@kitschpatrol/tldraw-cli 4.6.28 → 4.6.30
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 +118 -152
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/index.js +108 -148
- package/dist/lib/inline/get-image.d.ts +1 -1
- package/dist/lib/local-tldraw-server.d.ts +1 -1
- package/dist/lib/tldraw-controller.d.ts +9 -11
- package/dist/lib/tldraw-open.d.ts +3 -0
- package/dist/lib/tldraw-to-image.d.ts +4 -1
- package/dist/lib/validation.d.ts +3 -0
- package/dist/tldraw/assets/index-BkIYKf7d.css +1 -0
- package/dist/tldraw/assets/index-CLFDDK9V.js +423 -0
- package/dist/tldraw/index.html +2 -2
- package/dist/tldraw/translations/ar.json +91 -10
- package/dist/tldraw/translations/bn.json +376 -0
- package/dist/tldraw/translations/ca.json +91 -10
- package/dist/tldraw/translations/cs.json +65 -41
- package/dist/tldraw/translations/da.json +15 -36
- package/dist/tldraw/translations/de.json +80 -14
- package/dist/tldraw/translations/el.json +376 -0
- package/dist/tldraw/translations/es.json +87 -10
- package/dist/tldraw/translations/fa.json +13 -21
- package/dist/tldraw/translations/fi.json +84 -20
- package/dist/tldraw/translations/fr.json +25 -21
- package/dist/tldraw/translations/gl.json +45 -18
- package/dist/tldraw/translations/gu-in.json +376 -0
- package/dist/tldraw/translations/he.json +348 -58
- package/dist/tldraw/translations/hi-in.json +96 -10
- package/dist/tldraw/translations/hr.json +36 -18
- package/dist/tldraw/translations/hu.json +31 -20
- package/dist/tldraw/translations/id.json +117 -114
- package/dist/tldraw/translations/it.json +56 -10
- package/dist/tldraw/translations/ja.json +43 -18
- package/dist/tldraw/translations/km-kh.json +376 -0
- package/dist/tldraw/translations/kn.json +376 -0
- package/dist/tldraw/translations/ko-kr.json +3 -24
- package/dist/tldraw/translations/languages.json +56 -12
- package/dist/tldraw/translations/main.json +13 -34
- package/dist/tldraw/translations/ml.json +376 -0
- package/dist/tldraw/translations/mr.json +376 -0
- package/dist/tldraw/translations/ms.json +376 -0
- package/dist/tldraw/translations/ne.json +91 -10
- package/dist/tldraw/translations/nl.json +376 -0
- package/dist/tldraw/translations/no.json +334 -20
- package/dist/tldraw/translations/pa.json +376 -0
- package/dist/tldraw/translations/pl.json +36 -57
- package/dist/tldraw/translations/pt-br.json +279 -236
- package/dist/tldraw/translations/pt-pt.json +320 -30
- package/dist/tldraw/translations/ro.json +26 -21
- package/dist/tldraw/translations/ru.json +27 -26
- package/dist/tldraw/translations/sl.json +24 -21
- package/dist/tldraw/translations/so.json +14 -35
- package/dist/tldraw/translations/sv.json +330 -50
- package/dist/tldraw/translations/ta.json +376 -0
- package/dist/tldraw/translations/te.json +302 -38
- package/dist/tldraw/translations/th.json +95 -14
- package/dist/tldraw/translations/tl.json +376 -0
- package/dist/tldraw/translations/tr.json +44 -23
- package/dist/tldraw/translations/uk.json +25 -24
- package/dist/tldraw/translations/ur.json +376 -0
- package/dist/tldraw/translations/vi.json +101 -20
- package/dist/tldraw/translations/zh-cn.json +13 -23
- package/dist/tldraw/translations/zh-tw.json +53 -17
- package/license.txt +1 -1
- package/package.json +47 -37
- package/readme.md +36 -42
- package/dist/lib/tldraw-to-share-url.d.ts +0 -1
- package/dist/tldraw/assets/index-Cg19E2b-.js +0 -425
- package/dist/tldraw/assets/index-DZaxLi12.css +0 -1
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
var Z$=Object.defineProperty;var Q$=(n,e,t)=>e in n?Z$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var j=(n,e,t)=>Q$(n,typeof e!="symbol"?e+"":e,t);function J$(n,e){for(var t=0;t<e.length;t++){const r=e[t];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in n)){const o=Object.getOwnPropertyDescriptor(r,s);o&&Object.defineProperty(n,s,o.get?o:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(n,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 t(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=t(s);fetch(s.href,o)}})();var Or=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function bi(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var cS={exports:{}},Lu={},uS={exports:{}},et={};/**
|
|
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 j_;function e6(){if(j_)return et;j_=1;var n=Symbol.for("react.element"),e=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),o=Symbol.for("react.provider"),i=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),d=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),f=Symbol.iterator;function g(B){return B===null||typeof B!="object"?null:(B=f&&B[f]||B["@@iterator"],typeof B=="function"?B:null)}var y={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S=Object.assign,v={};function w(B,ne,he){this.props=B,this.context=ne,this.refs=v,this.updater=he||y}w.prototype.isReactComponent={},w.prototype.setState=function(B,ne){if(typeof B!="object"&&typeof B!="function"&&B!=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,B,ne,"setState")},w.prototype.forceUpdate=function(B){this.updater.enqueueForceUpdate(this,B,"forceUpdate")};function b(){}b.prototype=w.prototype;function P(B,ne,he){this.props=B,this.context=ne,this.refs=v,this.updater=he||y}var k=P.prototype=new b;k.constructor=P,S(k,w.prototype),k.isPureReactComponent=!0;var E=Array.isArray,M=Object.prototype.hasOwnProperty,A={current:null},R={key:!0,ref:!0,__self:!0,__source:!0};function D(B,ne,he){var Pe,ue={},Fe=null,Me=null;if(ne!=null)for(Pe in ne.ref!==void 0&&(Me=ne.ref),ne.key!==void 0&&(Fe=""+ne.key),ne)M.call(ne,Pe)&&!R.hasOwnProperty(Pe)&&(ue[Pe]=ne[Pe]);var xe=arguments.length-2;if(xe===1)ue.children=he;else if(1<xe){for(var Ie=Array(xe),ze=0;ze<xe;ze++)Ie[ze]=arguments[ze+2];ue.children=Ie}if(B&&B.defaultProps)for(Pe in xe=B.defaultProps,xe)ue[Pe]===void 0&&(ue[Pe]=xe[Pe]);return{$$typeof:n,type:B,key:Fe,ref:Me,props:ue,_owner:A.current}}function V(B,ne){return{$$typeof:n,type:B.type,key:ne,ref:B.ref,props:B.props,_owner:B._owner}}function L(B){return typeof B=="object"&&B!==null&&B.$$typeof===n}function U(B){var ne={"=":"=0",":":"=2"};return"$"+B.replace(/[=:]/g,function(he){return ne[he]})}var K=/\/+/g;function F(B,ne){return typeof B=="object"&&B!==null&&B.key!=null?U(""+B.key):ne.toString(36)}function $(B,ne,he,Pe,ue){var Fe=typeof B;(Fe==="undefined"||Fe==="boolean")&&(B=null);var Me=!1;if(B===null)Me=!0;else switch(Fe){case"string":case"number":Me=!0;break;case"object":switch(B.$$typeof){case n:case e:Me=!0}}if(Me)return Me=B,ue=ue(Me),B=Pe===""?"."+F(Me,0):Pe,E(ue)?(he="",B!=null&&(he=B.replace(K,"$&/")+"/"),$(ue,ne,he,"",function(ze){return ze})):ue!=null&&(L(ue)&&(ue=V(ue,he+(!ue.key||Me&&Me.key===ue.key?"":(""+ue.key).replace(K,"$&/")+"/")+B)),ne.push(ue)),1;if(Me=0,Pe=Pe===""?".":Pe+":",E(B))for(var xe=0;xe<B.length;xe++){Fe=B[xe];var Ie=Pe+F(Fe,xe);Me+=$(Fe,ne,he,Ie,ue)}else if(Ie=g(B),typeof Ie=="function")for(B=Ie.call(B),xe=0;!(Fe=B.next()).done;)Fe=Fe.value,Ie=Pe+F(Fe,xe++),Me+=$(Fe,ne,he,Ie,ue);else if(Fe==="object")throw ne=String(B),Error("Objects are not valid as a React child (found: "+(ne==="[object Object]"?"object with keys {"+Object.keys(B).join(", ")+"}":ne)+"). If you meant to render a collection of children, use an array instead.");return Me}function W(B,ne,he){if(B==null)return B;var Pe=[],ue=0;return $(B,Pe,"","",function(Fe){return ne.call(he,Fe,ue++)}),Pe}function Y(B){if(B._status===-1){var ne=B._result;ne=ne(),ne.then(function(he){(B._status===0||B._status===-1)&&(B._status=1,B._result=he)},function(he){(B._status===0||B._status===-1)&&(B._status=2,B._result=he)}),B._status===-1&&(B._status=0,B._result=ne)}if(B._status===1)return B._result.default;throw B._result}var Z={current:null},H={transition:null},Q={ReactCurrentDispatcher:Z,ReactCurrentBatchConfig:H,ReactCurrentOwner:A};function ae(){throw Error("act(...) is not supported in production builds of React.")}return et.Children={map:W,forEach:function(B,ne,he){W(B,function(){ne.apply(this,arguments)},he)},count:function(B){var ne=0;return W(B,function(){ne++}),ne},toArray:function(B){return W(B,function(ne){return ne})||[]},only:function(B){if(!L(B))throw Error("React.Children.only expected to receive a single React element child.");return B}},et.Component=w,et.Fragment=t,et.Profiler=s,et.PureComponent=P,et.StrictMode=r,et.Suspense=c,et.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Q,et.act=ae,et.cloneElement=function(B,ne,he){if(B==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+B+".");var Pe=S({},B.props),ue=B.key,Fe=B.ref,Me=B._owner;if(ne!=null){if(ne.ref!==void 0&&(Fe=ne.ref,Me=A.current),ne.key!==void 0&&(ue=""+ne.key),B.type&&B.type.defaultProps)var xe=B.type.defaultProps;for(Ie in ne)M.call(ne,Ie)&&!R.hasOwnProperty(Ie)&&(Pe[Ie]=ne[Ie]===void 0&&xe!==void 0?xe[Ie]:ne[Ie])}var Ie=arguments.length-2;if(Ie===1)Pe.children=he;else if(1<Ie){xe=Array(Ie);for(var ze=0;ze<Ie;ze++)xe[ze]=arguments[ze+2];Pe.children=xe}return{$$typeof:n,type:B.type,key:ue,ref:Fe,props:Pe,_owner:Me}},et.createContext=function(B){return B={$$typeof:i,_currentValue:B,_currentValue2:B,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},B.Provider={$$typeof:o,_context:B},B.Consumer=B},et.createElement=D,et.createFactory=function(B){var ne=D.bind(null,B);return ne.type=B,ne},et.createRef=function(){return{current:null}},et.forwardRef=function(B){return{$$typeof:a,render:B}},et.isValidElement=L,et.lazy=function(B){return{$$typeof:h,_payload:{_status:-1,_result:B},_init:Y}},et.memo=function(B,ne){return{$$typeof:d,type:B,compare:ne===void 0?null:ne}},et.startTransition=function(B){var ne=H.transition;H.transition={};try{B()}finally{H.transition=ne}},et.unstable_act=ae,et.useCallback=function(B,ne){return Z.current.useCallback(B,ne)},et.useContext=function(B){return Z.current.useContext(B)},et.useDebugValue=function(){},et.useDeferredValue=function(B){return Z.current.useDeferredValue(B)},et.useEffect=function(B,ne){return Z.current.useEffect(B,ne)},et.useId=function(){return Z.current.useId()},et.useImperativeHandle=function(B,ne,he){return Z.current.useImperativeHandle(B,ne,he)},et.useInsertionEffect=function(B,ne){return Z.current.useInsertionEffect(B,ne)},et.useLayoutEffect=function(B,ne){return Z.current.useLayoutEffect(B,ne)},et.useMemo=function(B,ne){return Z.current.useMemo(B,ne)},et.useReducer=function(B,ne,he){return Z.current.useReducer(B,ne,he)},et.useRef=function(B){return Z.current.useRef(B)},et.useState=function(B){return Z.current.useState(B)},et.useSyncExternalStore=function(B,ne,he){return Z.current.useSyncExternalStore(B,ne,he)},et.useTransition=function(){return Z.current.useTransition()},et.version="18.3.1",et}var R_;function G0(){return R_||(R_=1,uS.exports=e6()),uS.exports}/**
|
|
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 O_;function t6(){if(O_)return Lu;O_=1;var n=G0(),e=Symbol.for("react.element"),t=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function i(a,c,d){var h,f={},g=null,y=null;d!==void 0&&(g=""+d),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(y=c.ref);for(h in c)r.call(c,h)&&!o.hasOwnProperty(h)&&(f[h]=c[h]);if(a&&a.defaultProps)for(h in c=a.defaultProps,c)f[h]===void 0&&(f[h]=c[h]);return{$$typeof:e,type:a,key:g,ref:y,props:f,_owner:s.current}}return Lu.Fragment=t,Lu.jsx=i,Lu.jsxs=i,Lu}var D_;function n6(){return D_||(D_=1,cS.exports=t6()),cS.exports}var p=n6(),_=G0();const at=bi(_),r6=J$({__proto__:null,default:at},[_]);var gp={},dS={exports:{}},_r={},hS={exports:{}},pS={};/**
|
|
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
|
+
*/var L_;function s6(){return L_||(L_=1,function(n){function e(H,Q){var ae=H.length;H.push(Q);e:for(;0<ae;){var B=ae-1>>>1,ne=H[B];if(0<s(ne,Q))H[B]=Q,H[ae]=ne,ae=B;else break e}}function t(H){return H.length===0?null:H[0]}function r(H){if(H.length===0)return null;var Q=H[0],ae=H.pop();if(ae!==Q){H[0]=ae;e:for(var B=0,ne=H.length,he=ne>>>1;B<he;){var Pe=2*(B+1)-1,ue=H[Pe],Fe=Pe+1,Me=H[Fe];if(0>s(ue,ae))Fe<ne&&0>s(Me,ue)?(H[B]=Me,H[Fe]=ae,B=Fe):(H[B]=ue,H[Pe]=ae,B=Pe);else if(Fe<ne&&0>s(Me,ae))H[B]=Me,H[Fe]=ae,B=Fe;else break e}}return Q}function s(H,Q){var ae=H.sortIndex-Q.sortIndex;return ae!==0?ae:H.id-Q.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;n.unstable_now=function(){return o.now()}}else{var i=Date,a=i.now();n.unstable_now=function(){return i.now()-a}}var c=[],d=[],h=1,f=null,g=3,y=!1,S=!1,v=!1,w=typeof setTimeout=="function"?setTimeout:null,b=typeof clearTimeout=="function"?clearTimeout:null,P=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function k(H){for(var Q=t(d);Q!==null;){if(Q.callback===null)r(d);else if(Q.startTime<=H)r(d),Q.sortIndex=Q.expirationTime,e(c,Q);else break;Q=t(d)}}function E(H){if(v=!1,k(H),!S)if(t(c)!==null)S=!0,Y(M);else{var Q=t(d);Q!==null&&Z(E,Q.startTime-H)}}function M(H,Q){S=!1,v&&(v=!1,b(D),D=-1),y=!0;var ae=g;try{for(k(Q),f=t(c);f!==null&&(!(f.expirationTime>Q)||H&&!U());){var B=f.callback;if(typeof B=="function"){f.callback=null,g=f.priorityLevel;var ne=B(f.expirationTime<=Q);Q=n.unstable_now(),typeof ne=="function"?f.callback=ne:f===t(c)&&r(c),k(Q)}else r(c);f=t(c)}if(f!==null)var he=!0;else{var Pe=t(d);Pe!==null&&Z(E,Pe.startTime-Q),he=!1}return he}finally{f=null,g=ae,y=!1}}var A=!1,R=null,D=-1,V=5,L=-1;function U(){return!(n.unstable_now()-L<V)}function K(){if(R!==null){var H=n.unstable_now();L=H;var Q=!0;try{Q=R(!0,H)}finally{Q?F():(A=!1,R=null)}}else A=!1}var F;if(typeof P=="function")F=function(){P(K)};else if(typeof MessageChannel<"u"){var $=new MessageChannel,W=$.port2;$.port1.onmessage=K,F=function(){W.postMessage(null)}}else F=function(){w(K,0)};function Y(H){R=H,A||(A=!0,F())}function Z(H,Q){D=w(function(){H(n.unstable_now())},Q)}n.unstable_IdlePriority=5,n.unstable_ImmediatePriority=1,n.unstable_LowPriority=4,n.unstable_NormalPriority=3,n.unstable_Profiling=null,n.unstable_UserBlockingPriority=2,n.unstable_cancelCallback=function(H){H.callback=null},n.unstable_continueExecution=function(){S||y||(S=!0,Y(M))},n.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):V=0<H?Math.floor(1e3/H):5},n.unstable_getCurrentPriorityLevel=function(){return g},n.unstable_getFirstCallbackNode=function(){return t(c)},n.unstable_next=function(H){switch(g){case 1:case 2:case 3:var Q=3;break;default:Q=g}var ae=g;g=Q;try{return H()}finally{g=ae}},n.unstable_pauseExecution=function(){},n.unstable_requestPaint=function(){},n.unstable_runWithPriority=function(H,Q){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var ae=g;g=H;try{return Q()}finally{g=ae}},n.unstable_scheduleCallback=function(H,Q,ae){var B=n.unstable_now();switch(typeof ae=="object"&&ae!==null?(ae=ae.delay,ae=typeof ae=="number"&&0<ae?B+ae:B):ae=B,H){case 1:var ne=-1;break;case 2:ne=250;break;case 5:ne=1073741823;break;case 4:ne=1e4;break;default:ne=5e3}return ne=ae+ne,H={id:h++,callback:Q,priorityLevel:H,startTime:ae,expirationTime:ne,sortIndex:-1},ae>B?(H.sortIndex=ae,e(d,H),t(c)===null&&H===t(d)&&(v?(b(D),D=-1):v=!0,Z(E,ae-B))):(H.sortIndex=ne,e(c,H),S||y||(S=!0,Y(M))),H},n.unstable_shouldYield=U,n.unstable_wrapCallback=function(H){var Q=g;return function(){var ae=g;g=Q;try{return H.apply(this,arguments)}finally{g=ae}}}}(pS)),pS}var F_;function o6(){return F_||(F_=1,hS.exports=s6()),hS.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 N_;function i6(){if(N_)return _r;N_=1;var n=G0(),e=o6();function t(l){for(var u="https://reactjs.org/docs/error-decoder.html?invariant="+l,m=1;m<arguments.length;m++)u+="&args[]="+encodeURIComponent(arguments[m]);return"Minified React error #"+l+"; visit "+u+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var r=new Set,s={};function o(l,u){i(l,u),i(l+"Capture",u)}function i(l,u){for(s[l]=u,l=0;l<u.length;l++)r.add(u[l])}var a=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),c=Object.prototype.hasOwnProperty,d=/^[: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]*$/,h={},f={};function g(l){return c.call(f,l)?!0:c.call(h,l)?!1:d.test(l)?f[l]=!0:(h[l]=!0,!1)}function y(l,u,m,x){if(m!==null&&m.type===0)return!1;switch(typeof u){case"function":case"symbol":return!0;case"boolean":return x?!1:m!==null?!m.acceptsBooleans:(l=l.toLowerCase().slice(0,5),l!=="data-"&&l!=="aria-");default:return!1}}function S(l,u,m,x){if(u===null||typeof u>"u"||y(l,u,m,x))return!0;if(x)return!1;if(m!==null)switch(m.type){case 3:return!u;case 4:return u===!1;case 5:return isNaN(u);case 6:return isNaN(u)||1>u}return!1}function v(l,u,m,x,I,T,O){this.acceptsBooleans=u===2||u===3||u===4,this.attributeName=x,this.attributeNamespace=I,this.mustUseProperty=m,this.propertyName=l,this.type=u,this.sanitizeURL=T,this.removeEmptyString=O}var w={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(l){w[l]=new v(l,0,!1,l,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(l){var u=l[0];w[u]=new v(u,1,!1,l[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(l){w[l]=new v(l,2,!1,l.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(l){w[l]=new v(l,2,!1,l,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(l){w[l]=new v(l,3,!1,l.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(l){w[l]=new v(l,3,!0,l,null,!1,!1)}),["capture","download"].forEach(function(l){w[l]=new v(l,4,!1,l,null,!1,!1)}),["cols","rows","size","span"].forEach(function(l){w[l]=new v(l,6,!1,l,null,!1,!1)}),["rowSpan","start"].forEach(function(l){w[l]=new v(l,5,!1,l.toLowerCase(),null,!1,!1)});var b=/[\-:]([a-z])/g;function P(l){return l[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(l){var u=l.replace(b,P);w[u]=new v(u,1,!1,l,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(l){var u=l.replace(b,P);w[u]=new v(u,1,!1,l,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(l){var u=l.replace(b,P);w[u]=new v(u,1,!1,l,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(l){w[l]=new v(l,1,!1,l.toLowerCase(),null,!1,!1)}),w.xlinkHref=new v("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(l){w[l]=new v(l,1,!1,l.toLowerCase(),null,!0,!0)});function k(l,u,m,x){var I=w.hasOwnProperty(u)?w[u]:null;(I!==null?I.type!==0:x||!(2<u.length)||u[0]!=="o"&&u[0]!=="O"||u[1]!=="n"&&u[1]!=="N")&&(S(u,m,I,x)&&(m=null),x||I===null?g(u)&&(m===null?l.removeAttribute(u):l.setAttribute(u,""+m)):I.mustUseProperty?l[I.propertyName]=m===null?I.type===3?!1:"":m:(u=I.attributeName,x=I.attributeNamespace,m===null?l.removeAttribute(u):(I=I.type,m=I===3||I===4&&m===!0?"":""+m,x?l.setAttributeNS(x,u,m):l.setAttribute(u,m))))}var E=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,M=Symbol.for("react.element"),A=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),L=Symbol.for("react.provider"),U=Symbol.for("react.context"),K=Symbol.for("react.forward_ref"),F=Symbol.for("react.suspense"),$=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),Y=Symbol.for("react.lazy"),Z=Symbol.for("react.offscreen"),H=Symbol.iterator;function Q(l){return l===null||typeof l!="object"?null:(l=H&&l[H]||l["@@iterator"],typeof l=="function"?l:null)}var ae=Object.assign,B;function ne(l){if(B===void 0)try{throw Error()}catch(m){var u=m.stack.trim().match(/\n( *(at )?)/);B=u&&u[1]||""}return`
|
|
34
|
+
`+B+l}var he=!1;function Pe(l,u){if(!l||he)return"";he=!0;var m=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(u)if(u=function(){throw Error()},Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(oe){var x=oe}Reflect.construct(l,[],u)}else{try{u.call()}catch(oe){x=oe}l.call(u.prototype)}else{try{throw Error()}catch(oe){x=oe}l()}}catch(oe){if(oe&&x&&typeof oe.stack=="string"){for(var I=oe.stack.split(`
|
|
35
|
+
`),T=x.stack.split(`
|
|
36
|
+
`),O=I.length-1,z=T.length-1;1<=O&&0<=z&&I[O]!==T[z];)z--;for(;1<=O&&0<=z;O--,z--)if(I[O]!==T[z]){if(O!==1||z!==1)do if(O--,z--,0>z||I[O]!==T[z]){var G=`
|
|
37
|
+
`+I[O].replace(" at new "," at ");return l.displayName&&G.includes("<anonymous>")&&(G=G.replace("<anonymous>",l.displayName)),G}while(1<=O&&0<=z);break}}}finally{he=!1,Error.prepareStackTrace=m}return(l=l?l.displayName||l.name:"")?ne(l):""}function ue(l){switch(l.tag){case 5:return ne(l.type);case 16:return ne("Lazy");case 13:return ne("Suspense");case 19:return ne("SuspenseList");case 0:case 2:case 15:return l=Pe(l.type,!1),l;case 11:return l=Pe(l.type.render,!1),l;case 1:return l=Pe(l.type,!0),l;default:return""}}function Fe(l){if(l==null)return null;if(typeof l=="function")return l.displayName||l.name||null;if(typeof l=="string")return l;switch(l){case R:return"Fragment";case A:return"Portal";case V:return"Profiler";case D:return"StrictMode";case F:return"Suspense";case $:return"SuspenseList"}if(typeof l=="object")switch(l.$$typeof){case U:return(l.displayName||"Context")+".Consumer";case L:return(l._context.displayName||"Context")+".Provider";case K:var u=l.render;return l=l.displayName,l||(l=u.displayName||u.name||"",l=l!==""?"ForwardRef("+l+")":"ForwardRef"),l;case W:return u=l.displayName||null,u!==null?u:Fe(l.type)||"Memo";case Y:u=l._payload,l=l._init;try{return Fe(l(u))}catch{}}return null}function Me(l){var u=l.type;switch(l.tag){case 24:return"Cache";case 9:return(u.displayName||"Context")+".Consumer";case 10:return(u._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return l=u.render,l=l.displayName||l.name||"",u.displayName||(l!==""?"ForwardRef("+l+")":"ForwardRef");case 7:return"Fragment";case 5:return u;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Fe(u);case 8:return u===D?"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 u=="function")return u.displayName||u.name||null;if(typeof u=="string")return u}return null}function xe(l){switch(typeof l){case"boolean":case"number":case"string":case"undefined":return l;case"object":return l;default:return""}}function Ie(l){var u=l.type;return(l=l.nodeName)&&l.toLowerCase()==="input"&&(u==="checkbox"||u==="radio")}function ze(l){var u=Ie(l)?"checked":"value",m=Object.getOwnPropertyDescriptor(l.constructor.prototype,u),x=""+l[u];if(!l.hasOwnProperty(u)&&typeof m<"u"&&typeof m.get=="function"&&typeof m.set=="function"){var I=m.get,T=m.set;return Object.defineProperty(l,u,{configurable:!0,get:function(){return I.call(this)},set:function(O){x=""+O,T.call(this,O)}}),Object.defineProperty(l,u,{enumerable:m.enumerable}),{getValue:function(){return x},setValue:function(O){x=""+O},stopTracking:function(){l._valueTracker=null,delete l[u]}}}}function Ze(l){l._valueTracker||(l._valueTracker=ze(l))}function Xt(l){if(!l)return!1;var u=l._valueTracker;if(!u)return!0;var m=u.getValue(),x="";return l&&(x=Ie(l)?l.checked?"true":"false":l.value),l=x,l!==m?(u.setValue(l),!0):!1}function yt(l){if(l=l||(typeof document<"u"?document:void 0),typeof l>"u")return null;try{return l.activeElement||l.body}catch{return l.body}}function zt(l,u){var m=u.checked;return ae({},u,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:m??l._wrapperState.initialChecked})}function _t(l,u){var m=u.defaultValue==null?"":u.defaultValue,x=u.checked!=null?u.checked:u.defaultChecked;m=xe(u.value!=null?u.value:m),l._wrapperState={initialChecked:x,initialValue:m,controlled:u.type==="checkbox"||u.type==="radio"?u.checked!=null:u.value!=null}}function wt(l,u){u=u.checked,u!=null&&k(l,"checked",u,!1)}function hr(l,u){wt(l,u);var m=xe(u.value),x=u.type;if(m!=null)x==="number"?(m===0&&l.value===""||l.value!=m)&&(l.value=""+m):l.value!==""+m&&(l.value=""+m);else if(x==="submit"||x==="reset"){l.removeAttribute("value");return}u.hasOwnProperty("value")?fr(l,u.type,m):u.hasOwnProperty("defaultValue")&&fr(l,u.type,xe(u.defaultValue)),u.checked==null&&u.defaultChecked!=null&&(l.defaultChecked=!!u.defaultChecked)}function pr(l,u,m){if(u.hasOwnProperty("value")||u.hasOwnProperty("defaultValue")){var x=u.type;if(!(x!=="submit"&&x!=="reset"||u.value!==void 0&&u.value!==null))return;u=""+l._wrapperState.initialValue,m||u===l.value||(l.value=u),l.defaultValue=u}m=l.name,m!==""&&(l.name=""),l.defaultChecked=!!l._wrapperState.initialChecked,m!==""&&(l.name=m)}function fr(l,u,m){(u!=="number"||yt(l.ownerDocument)!==l)&&(m==null?l.defaultValue=""+l._wrapperState.initialValue:l.defaultValue!==""+m&&(l.defaultValue=""+m))}var gr=Array.isArray;function ls(l,u,m,x){if(l=l.options,u){u={};for(var I=0;I<m.length;I++)u["$"+m[I]]=!0;for(m=0;m<l.length;m++)I=u.hasOwnProperty("$"+l[m].value),l[m].selected!==I&&(l[m].selected=I),I&&x&&(l[m].defaultSelected=!0)}else{for(m=""+xe(m),u=null,I=0;I<l.length;I++){if(l[I].value===m){l[I].selected=!0,x&&(l[I].defaultSelected=!0);return}u!==null||l[I].disabled||(u=l[I])}u!==null&&(u.selected=!0)}}function Ta(l,u){if(u.dangerouslySetInnerHTML!=null)throw Error(t(91));return ae({},u,{value:void 0,defaultValue:void 0,children:""+l._wrapperState.initialValue})}function bl(l,u){var m=u.value;if(m==null){if(m=u.children,u=u.defaultValue,m!=null){if(u!=null)throw Error(t(92));if(gr(m)){if(1<m.length)throw Error(t(93));m=m[0]}u=m}u==null&&(u=""),m=u}l._wrapperState={initialValue:xe(m)}}function Pl(l,u){var m=xe(u.value),x=xe(u.defaultValue);m!=null&&(m=""+m,m!==l.value&&(l.value=m),u.defaultValue==null&&l.defaultValue!==m&&(l.defaultValue=m)),x!=null&&(l.defaultValue=""+x)}function Cl(l){var u=l.textContent;u===l._wrapperState.initialValue&&u!==""&&u!==null&&(l.value=u)}function _l(l){switch(l){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 oo(l,u){return l==null||l==="http://www.w3.org/1999/xhtml"?_l(u):l==="http://www.w3.org/2000/svg"&&u==="foreignObject"?"http://www.w3.org/1999/xhtml":l}var As,ka=function(l){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(u,m,x,I){MSApp.execUnsafeLocalFunction(function(){return l(u,m,x,I)})}:l}(function(l,u){if(l.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in l)l.innerHTML=u;else{for(As=As||document.createElement("div"),As.innerHTML="<svg>"+u.valueOf().toString()+"</svg>",u=As.firstChild;l.firstChild;)l.removeChild(l.firstChild);for(;u.firstChild;)l.appendChild(u.firstChild)}});function ie(l,u){if(u){var m=l.firstChild;if(m&&m===l.lastChild&&m.nodeType===3){m.nodeValue=u;return}}l.textContent=u}var ve={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},Ke=["Webkit","ms","Moz","O"];Object.keys(ve).forEach(function(l){Ke.forEach(function(u){u=u+l.charAt(0).toUpperCase()+l.substring(1),ve[u]=ve[l]})});function bt(l,u,m){return u==null||typeof u=="boolean"||u===""?"":m||typeof u!="number"||u===0||ve.hasOwnProperty(l)&&ve[l]?(""+u).trim():u+"px"}function cs(l,u){l=l.style;for(var m in u)if(u.hasOwnProperty(m)){var x=m.indexOf("--")===0,I=bt(m,u[m],x);m==="float"&&(m="cssFloat"),x?l.setProperty(m,I):l[m]=I}}var mr=ae({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 Wo(l,u){if(u){if(mr[l]&&(u.children!=null||u.dangerouslySetInnerHTML!=null))throw Error(t(137,l));if(u.dangerouslySetInnerHTML!=null){if(u.children!=null)throw Error(t(60));if(typeof u.dangerouslySetInnerHTML!="object"||!("__html"in u.dangerouslySetInnerHTML))throw Error(t(61))}if(u.style!=null&&typeof u.style!="object")throw Error(t(62))}}function Br(l,u){if(l.indexOf("-")===-1)return typeof u.is=="string";switch(l){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 Ur=null;function yr(l){return l=l.target||l.srcElement||window,l.correspondingUseElement&&(l=l.correspondingUseElement),l.nodeType===3?l.parentNode:l}var Hr=null,Sr=null,js=null;function Il(l){if(l=wu(l)){if(typeof Hr!="function")throw Error(t(280));var u=l.stateNode;u&&(u=Mh(u),Hr(l.stateNode,l.type,u))}}function ki(l){Sr?js?js.push(l):js=[l]:Sr=l}function El(){if(Sr){var l=Sr,u=js;if(js=Sr=null,Il(l),u)for(l=0;l<u.length;l++)Il(u[l])}}function Tl(l,u){return l(u)}function kl(){}var Go=!1;function dh(l,u,m){if(Go)return l(u,m);Go=!0;try{return Tl(l,u,m)}finally{Go=!1,(Sr!==null||js!==null)&&(kl(),El())}}function Ma(l,u){var m=l.stateNode;if(m===null)return null;var x=Mh(m);if(x===null)return null;m=x[u];e:switch(u){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(x=!x.disabled)||(l=l.type,x=!(l==="button"||l==="input"||l==="select"||l==="textarea")),l=!x;break e;default:l=!1}if(l)return null;if(m&&typeof m!="function")throw Error(t(231,u,typeof m));return m}var nu=!1;if(a)try{var Aa={};Object.defineProperty(Aa,"passive",{get:function(){nu=!0}}),window.addEventListener("test",Aa,Aa),window.removeEventListener("test",Aa,Aa)}catch{nu=!1}function Cm(l,u,m,x,I,T,O,z,G){var oe=Array.prototype.slice.call(arguments,3);try{u.apply(m,oe)}catch(fe){this.onError(fe)}}var Mi=!1,Ai=null,us=!1,ru=null,_m={onError:function(l){Mi=!0,Ai=l}};function Im(l,u,m,x,I,T,O,z,G){Mi=!1,Ai=null,Cm.apply(_m,arguments)}function Em(l,u,m,x,I,T,O,z,G){if(Im.apply(this,arguments),Mi){if(Mi){var oe=Ai;Mi=!1,Ai=null}else throw Error(t(198));us||(us=!0,ru=oe)}}function Vo(l){var u=l,m=l;if(l.alternate)for(;u.return;)u=u.return;else{l=u;do u=l,u.flags&4098&&(m=u.return),l=u.return;while(l)}return u.tag===3?m:null}function ds(l){if(l.tag===13){var u=l.memoizedState;if(u===null&&(l=l.alternate,l!==null&&(u=l.memoizedState)),u!==null)return u.dehydrated}return null}function hh(l){if(Vo(l)!==l)throw Error(t(188))}function Tm(l){var u=l.alternate;if(!u){if(u=Vo(l),u===null)throw Error(t(188));return u!==l?null:l}for(var m=l,x=u;;){var I=m.return;if(I===null)break;var T=I.alternate;if(T===null){if(x=I.return,x!==null){m=x;continue}break}if(I.child===T.child){for(T=I.child;T;){if(T===m)return hh(I),l;if(T===x)return hh(I),u;T=T.sibling}throw Error(t(188))}if(m.return!==x.return)m=I,x=T;else{for(var O=!1,z=I.child;z;){if(z===m){O=!0,m=I,x=T;break}if(z===x){O=!0,x=I,m=T;break}z=z.sibling}if(!O){for(z=T.child;z;){if(z===m){O=!0,m=T,x=I;break}if(z===x){O=!0,x=T,m=I;break}z=z.sibling}if(!O)throw Error(t(189))}}if(m.alternate!==x)throw Error(t(190))}if(m.tag!==3)throw Error(t(188));return m.stateNode.current===m?l:u}function ph(l){return l=Tm(l),l!==null?fh(l):null}function fh(l){if(l.tag===5||l.tag===6)return l;for(l=l.child;l!==null;){var u=fh(l);if(u!==null)return u;l=l.sibling}return null}var gh=e.unstable_scheduleCallback,io=e.unstable_cancelCallback,km=e.unstable_shouldYield,Mm=e.unstable_requestPaint,Kt=e.unstable_now,Am=e.unstable_getCurrentPriorityLevel,su=e.unstable_ImmediatePriority,ja=e.unstable_UserBlockingPriority,Ml=e.unstable_NormalPriority,jm=e.unstable_LowPriority,Rs=e.unstable_IdlePriority,Al=null,hs=null;function Rm(l){if(hs&&typeof hs.onCommitFiberRoot=="function")try{hs.onCommitFiberRoot(Al,l,void 0,(l.current.flags&128)===128)}catch{}}var Kr=Math.clz32?Math.clz32:jl,Om=Math.log,Dm=Math.LN2;function jl(l){return l>>>=0,l===0?32:31-(Om(l)/Dm|0)|0}var Rl=64,ao=4194304;function ji(l){switch(l&-l){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 l&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return l&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return l}}function Ra(l,u){var m=l.pendingLanes;if(m===0)return 0;var x=0,I=l.suspendedLanes,T=l.pingedLanes,O=m&268435455;if(O!==0){var z=O&~I;z!==0?x=ji(z):(T&=O,T!==0&&(x=ji(T)))}else O=m&~I,O!==0?x=ji(O):T!==0&&(x=ji(T));if(x===0)return 0;if(u!==0&&u!==x&&!(u&I)&&(I=x&-x,T=u&-u,I>=T||I===16&&(T&4194240)!==0))return u;if(x&4&&(x|=m&16),u=l.entangledLanes,u!==0)for(l=l.entanglements,u&=x;0<u;)m=31-Kr(u),I=1<<m,x|=l[m],u&=~I;return x}function Lm(l,u){switch(l){case 1:case 2:case 4:return u+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 u+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 Fm(l,u){for(var m=l.suspendedLanes,x=l.pingedLanes,I=l.expirationTimes,T=l.pendingLanes;0<T;){var O=31-Kr(T),z=1<<O,G=I[O];G===-1?(!(z&m)||z&x)&&(I[O]=Lm(z,u)):G<=u&&(l.expiredLanes|=z),T&=~z}}function ou(l){return l=l.pendingLanes&-1073741825,l!==0?l:l&1073741824?1073741824:0}function mh(){var l=Rl;return Rl<<=1,!(Rl&4194240)&&(Rl=64),l}function Ol(l){for(var u=[],m=0;31>m;m++)u.push(l);return u}function Oa(l,u,m){l.pendingLanes|=u,u!==536870912&&(l.suspendedLanes=0,l.pingedLanes=0),l=l.eventTimes,u=31-Kr(u),l[u]=m}function Nm(l,u){var m=l.pendingLanes&~u;l.pendingLanes=u,l.suspendedLanes=0,l.pingedLanes=0,l.expiredLanes&=u,l.mutableReadLanes&=u,l.entangledLanes&=u,u=l.entanglements;var x=l.eventTimes;for(l=l.expirationTimes;0<m;){var I=31-Kr(m),T=1<<I;u[I]=0,x[I]=-1,l[I]=-1,m&=~T}}function Dl(l,u){var m=l.entangledLanes|=u;for(l=l.entanglements;m;){var x=31-Kr(m),I=1<<x;I&u|l[x]&u&&(l[x]|=u),m&=~I}}var ct=0;function qo(l){return l&=-l,1<l?4<l?l&268435455?16:536870912:4:1}var yh,iu,Os,Sh,vh,au=!1,Ll=[],lo=null,Dn=null,Ds=null,Da=new Map,co=new Map,uo=[],lu="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 xh(l,u){switch(l){case"focusin":case"focusout":lo=null;break;case"dragenter":case"dragleave":Dn=null;break;case"mouseover":case"mouseout":Ds=null;break;case"pointerover":case"pointerout":Da.delete(u.pointerId);break;case"gotpointercapture":case"lostpointercapture":co.delete(u.pointerId)}}function Ri(l,u,m,x,I,T){return l===null||l.nativeEvent!==T?(l={blockedOn:u,domEventName:m,eventSystemFlags:x,nativeEvent:T,targetContainers:[I]},u!==null&&(u=wu(u),u!==null&&iu(u)),l):(l.eventSystemFlags|=x,u=l.targetContainers,I!==null&&u.indexOf(I)===-1&&u.push(I),l)}function wh(l,u,m,x,I){switch(u){case"focusin":return lo=Ri(lo,l,u,m,x,I),!0;case"dragenter":return Dn=Ri(Dn,l,u,m,x,I),!0;case"mouseover":return Ds=Ri(Ds,l,u,m,x,I),!0;case"pointerover":var T=I.pointerId;return Da.set(T,Ri(Da.get(T)||null,l,u,m,x,I)),!0;case"gotpointercapture":return T=I.pointerId,co.set(T,Ri(co.get(T)||null,l,u,m,x,I)),!0}return!1}function cu(l){var u=Na(l.target);if(u!==null){var m=Vo(u);if(m!==null){if(u=m.tag,u===13){if(u=ds(m),u!==null){l.blockedOn=u,vh(l.priority,function(){Os(m)});return}}else if(u===3&&m.stateNode.current.memoizedState.isDehydrated){l.blockedOn=m.tag===3?m.stateNode.containerInfo:null;return}}}l.blockedOn=null}function ho(l){if(l.blockedOn!==null)return!1;for(var u=l.targetContainers;0<u.length;){var m=kt(l.domEventName,l.eventSystemFlags,u[0],l.nativeEvent);if(m===null){m=l.nativeEvent;var x=new m.constructor(m.type,m);Ur=x,m.target.dispatchEvent(x),Ur=null}else return u=wu(m),u!==null&&iu(u),l.blockedOn=m,!1;u.shift()}return!0}function uu(l,u,m){ho(l)&&m.delete(u)}function $m(){au=!1,lo!==null&&ho(lo)&&(lo=null),Dn!==null&&ho(Dn)&&(Dn=null),Ds!==null&&ho(Ds)&&(Ds=null),Da.forEach(uu),co.forEach(uu)}function La(l,u){l.blockedOn===u&&(l.blockedOn=null,au||(au=!0,e.unstable_scheduleCallback(e.unstable_NormalPriority,$m)))}function Fa(l){function u(I){return La(I,l)}if(0<Ll.length){La(Ll[0],l);for(var m=1;m<Ll.length;m++){var x=Ll[m];x.blockedOn===l&&(x.blockedOn=null)}}for(lo!==null&&La(lo,l),Dn!==null&&La(Dn,l),Ds!==null&&La(Ds,l),Da.forEach(u),co.forEach(u),m=0;m<uo.length;m++)x=uo[m],x.blockedOn===l&&(x.blockedOn=null);for(;0<uo.length&&(m=uo[0],m.blockedOn===null);)cu(m),m.blockedOn===null&&uo.shift()}var N=E.ReactCurrentBatchConfig,X=!0;function de(l,u,m,x){var I=ct,T=N.transition;N.transition=null;try{ct=1,vt(l,u,m,x)}finally{ct=I,N.transition=T}}function Te(l,u,m,x){var I=ct,T=N.transition;N.transition=null;try{ct=4,vt(l,u,m,x)}finally{ct=I,N.transition=T}}function vt(l,u,m,x){if(X){var I=kt(l,u,m,x);if(I===null)Jm(l,u,x,qe,m),xh(l,x);else if(wh(I,l,u,m,x))x.stopPropagation();else if(xh(l,x),u&4&&-1<lu.indexOf(l)){for(;I!==null;){var T=wu(I);if(T!==null&&yh(T),T=kt(l,u,m,x),T===null&&Jm(l,u,x,qe,m),T===I)break;I=T}I!==null&&x.stopPropagation()}else Jm(l,u,x,null,m)}}var qe=null;function kt(l,u,m,x){if(qe=null,l=yr(x),l=Na(l),l!==null)if(u=Vo(l),u===null)l=null;else if(m=u.tag,m===13){if(l=ds(u),l!==null)return l;l=null}else if(m===3){if(u.stateNode.current.memoizedState.isDehydrated)return u.tag===3?u.stateNode.containerInfo:null;l=null}else u!==l&&(l=null);return qe=l,null}function en(l){switch(l){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(Am()){case su:return 1;case ja:return 4;case Ml:case jm:return 16;case Rs:return 536870912;default:return 16}default:return 16}}var Mt=null,It=null,gn=null;function vr(){if(gn)return gn;var l,u=It,m=u.length,x,I="value"in Mt?Mt.value:Mt.textContent,T=I.length;for(l=0;l<m&&u[l]===I[l];l++);var O=m-l;for(x=1;x<=O&&u[m-x]===I[T-x];x++);return gn=I.slice(l,1<x?1-x:void 0)}function tn(l){var u=l.keyCode;return"charCode"in l?(l=l.charCode,l===0&&u===13&&(l=13)):l=u,l===10&&(l=13),32<=l||l===13?l:0}function wn(){return!0}function Jn(){return!1}function Zt(l){function u(m,x,I,T,O){this._reactName=m,this._targetInst=I,this.type=x,this.nativeEvent=T,this.target=O,this.currentTarget=null;for(var z in l)l.hasOwnProperty(z)&&(m=l[z],this[z]=m?m(T):T[z]);return this.isDefaultPrevented=(T.defaultPrevented!=null?T.defaultPrevented:T.returnValue===!1)?wn:Jn,this.isPropagationStopped=Jn,this}return ae(u.prototype,{preventDefault:function(){this.defaultPrevented=!0;var m=this.nativeEvent;m&&(m.preventDefault?m.preventDefault():typeof m.returnValue!="unknown"&&(m.returnValue=!1),this.isDefaultPrevented=wn)},stopPropagation:function(){var m=this.nativeEvent;m&&(m.stopPropagation?m.stopPropagation():typeof m.cancelBubble!="unknown"&&(m.cancelBubble=!0),this.isPropagationStopped=wn)},persist:function(){},isPersistent:wn}),u}var Ln={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(l){return l.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Ls=Zt(Ln),Oi=ae({},Ln,{view:0,detail:0}),Fl=Zt(Oi),Di,zm,du,bh=ae({},Oi,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Um,button:0,buttons:0,relatedTarget:function(l){return l.relatedTarget===void 0?l.fromElement===l.srcElement?l.toElement:l.fromElement:l.relatedTarget},movementX:function(l){return"movementX"in l?l.movementX:(l!==du&&(du&&l.type==="mousemove"?(Di=l.screenX-du.screenX,zm=l.screenY-du.screenY):zm=Di=0,du=l),Di)},movementY:function(l){return"movementY"in l?l.movementY:zm}}),wP=Zt(bh),_4=ae({},bh,{dataTransfer:0}),I4=Zt(_4),E4=ae({},Oi,{relatedTarget:0}),Bm=Zt(E4),T4=ae({},Ln,{animationName:0,elapsedTime:0,pseudoElement:0}),k4=Zt(T4),M4=ae({},Ln,{clipboardData:function(l){return"clipboardData"in l?l.clipboardData:window.clipboardData}}),A4=Zt(M4),j4=ae({},Ln,{data:0}),bP=Zt(j4),R4={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},O4={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"},D4={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function L4(l){var u=this.nativeEvent;return u.getModifierState?u.getModifierState(l):(l=D4[l])?!!u[l]:!1}function Um(){return L4}var F4=ae({},Oi,{key:function(l){if(l.key){var u=R4[l.key]||l.key;if(u!=="Unidentified")return u}return l.type==="keypress"?(l=tn(l),l===13?"Enter":String.fromCharCode(l)):l.type==="keydown"||l.type==="keyup"?O4[l.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Um,charCode:function(l){return l.type==="keypress"?tn(l):0},keyCode:function(l){return l.type==="keydown"||l.type==="keyup"?l.keyCode:0},which:function(l){return l.type==="keypress"?tn(l):l.type==="keydown"||l.type==="keyup"?l.keyCode:0}}),N4=Zt(F4),$4=ae({},bh,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),PP=Zt($4),z4=ae({},Oi,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Um}),B4=Zt(z4),U4=ae({},Ln,{propertyName:0,elapsedTime:0,pseudoElement:0}),H4=Zt(U4),K4=ae({},bh,{deltaX:function(l){return"deltaX"in l?l.deltaX:"wheelDeltaX"in l?-l.wheelDeltaX:0},deltaY:function(l){return"deltaY"in l?l.deltaY:"wheelDeltaY"in l?-l.wheelDeltaY:"wheelDelta"in l?-l.wheelDelta:0},deltaZ:0,deltaMode:0}),W4=Zt(K4),G4=[9,13,27,32],Hm=a&&"CompositionEvent"in window,hu=null;a&&"documentMode"in document&&(hu=document.documentMode);var V4=a&&"TextEvent"in window&&!hu,CP=a&&(!Hm||hu&&8<hu&&11>=hu),_P=" ",IP=!1;function EP(l,u){switch(l){case"keyup":return G4.indexOf(u.keyCode)!==-1;case"keydown":return u.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function TP(l){return l=l.detail,typeof l=="object"&&"data"in l?l.data:null}var Nl=!1;function q4(l,u){switch(l){case"compositionend":return TP(u);case"keypress":return u.which!==32?null:(IP=!0,_P);case"textInput":return l=u.data,l===_P&&IP?null:l;default:return null}}function Y4(l,u){if(Nl)return l==="compositionend"||!Hm&&EP(l,u)?(l=vr(),gn=It=Mt=null,Nl=!1,l):null;switch(l){case"paste":return null;case"keypress":if(!(u.ctrlKey||u.altKey||u.metaKey)||u.ctrlKey&&u.altKey){if(u.char&&1<u.char.length)return u.char;if(u.which)return String.fromCharCode(u.which)}return null;case"compositionend":return CP&&u.locale!=="ko"?null:u.data;default:return null}}var X4={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 kP(l){var u=l&&l.nodeName&&l.nodeName.toLowerCase();return u==="input"?!!X4[l.type]:u==="textarea"}function MP(l,u,m,x){ki(x),u=Eh(u,"onChange"),0<u.length&&(m=new Ls("onChange","change",null,m,x),l.push({event:m,listeners:u}))}var pu=null,fu=null;function Z4(l){qP(l,0)}function Ph(l){var u=Hl(l);if(Xt(u))return l}function Q4(l,u){if(l==="change")return u}var AP=!1;if(a){var Km;if(a){var Wm="oninput"in document;if(!Wm){var jP=document.createElement("div");jP.setAttribute("oninput","return;"),Wm=typeof jP.oninput=="function"}Km=Wm}else Km=!1;AP=Km&&(!document.documentMode||9<document.documentMode)}function RP(){pu&&(pu.detachEvent("onpropertychange",OP),fu=pu=null)}function OP(l){if(l.propertyName==="value"&&Ph(fu)){var u=[];MP(u,fu,l,yr(l)),dh(Z4,u)}}function J4(l,u,m){l==="focusin"?(RP(),pu=u,fu=m,pu.attachEvent("onpropertychange",OP)):l==="focusout"&&RP()}function e$(l){if(l==="selectionchange"||l==="keyup"||l==="keydown")return Ph(fu)}function t$(l,u){if(l==="click")return Ph(u)}function n$(l,u){if(l==="input"||l==="change")return Ph(u)}function r$(l,u){return l===u&&(l!==0||1/l===1/u)||l!==l&&u!==u}var Fs=typeof Object.is=="function"?Object.is:r$;function gu(l,u){if(Fs(l,u))return!0;if(typeof l!="object"||l===null||typeof u!="object"||u===null)return!1;var m=Object.keys(l),x=Object.keys(u);if(m.length!==x.length)return!1;for(x=0;x<m.length;x++){var I=m[x];if(!c.call(u,I)||!Fs(l[I],u[I]))return!1}return!0}function DP(l){for(;l&&l.firstChild;)l=l.firstChild;return l}function LP(l,u){var m=DP(l);l=0;for(var x;m;){if(m.nodeType===3){if(x=l+m.textContent.length,l<=u&&x>=u)return{node:m,offset:u-l};l=x}e:{for(;m;){if(m.nextSibling){m=m.nextSibling;break e}m=m.parentNode}m=void 0}m=DP(m)}}function FP(l,u){return l&&u?l===u?!0:l&&l.nodeType===3?!1:u&&u.nodeType===3?FP(l,u.parentNode):"contains"in l?l.contains(u):l.compareDocumentPosition?!!(l.compareDocumentPosition(u)&16):!1:!1}function NP(){for(var l=window,u=yt();u instanceof l.HTMLIFrameElement;){try{var m=typeof u.contentWindow.location.href=="string"}catch{m=!1}if(m)l=u.contentWindow;else break;u=yt(l.document)}return u}function Gm(l){var u=l&&l.nodeName&&l.nodeName.toLowerCase();return u&&(u==="input"&&(l.type==="text"||l.type==="search"||l.type==="tel"||l.type==="url"||l.type==="password")||u==="textarea"||l.contentEditable==="true")}function s$(l){var u=NP(),m=l.focusedElem,x=l.selectionRange;if(u!==m&&m&&m.ownerDocument&&FP(m.ownerDocument.documentElement,m)){if(x!==null&&Gm(m)){if(u=x.start,l=x.end,l===void 0&&(l=u),"selectionStart"in m)m.selectionStart=u,m.selectionEnd=Math.min(l,m.value.length);else if(l=(u=m.ownerDocument||document)&&u.defaultView||window,l.getSelection){l=l.getSelection();var I=m.textContent.length,T=Math.min(x.start,I);x=x.end===void 0?T:Math.min(x.end,I),!l.extend&&T>x&&(I=x,x=T,T=I),I=LP(m,T);var O=LP(m,x);I&&O&&(l.rangeCount!==1||l.anchorNode!==I.node||l.anchorOffset!==I.offset||l.focusNode!==O.node||l.focusOffset!==O.offset)&&(u=u.createRange(),u.setStart(I.node,I.offset),l.removeAllRanges(),T>x?(l.addRange(u),l.extend(O.node,O.offset)):(u.setEnd(O.node,O.offset),l.addRange(u)))}}for(u=[],l=m;l=l.parentNode;)l.nodeType===1&&u.push({element:l,left:l.scrollLeft,top:l.scrollTop});for(typeof m.focus=="function"&&m.focus(),m=0;m<u.length;m++)l=u[m],l.element.scrollLeft=l.left,l.element.scrollTop=l.top}}var o$=a&&"documentMode"in document&&11>=document.documentMode,$l=null,Vm=null,mu=null,qm=!1;function $P(l,u,m){var x=m.window===m?m.document:m.nodeType===9?m:m.ownerDocument;qm||$l==null||$l!==yt(x)||(x=$l,"selectionStart"in x&&Gm(x)?x={start:x.selectionStart,end:x.selectionEnd}:(x=(x.ownerDocument&&x.ownerDocument.defaultView||window).getSelection(),x={anchorNode:x.anchorNode,anchorOffset:x.anchorOffset,focusNode:x.focusNode,focusOffset:x.focusOffset}),mu&&gu(mu,x)||(mu=x,x=Eh(Vm,"onSelect"),0<x.length&&(u=new Ls("onSelect","select",null,u,m),l.push({event:u,listeners:x}),u.target=$l)))}function Ch(l,u){var m={};return m[l.toLowerCase()]=u.toLowerCase(),m["Webkit"+l]="webkit"+u,m["Moz"+l]="moz"+u,m}var zl={animationend:Ch("Animation","AnimationEnd"),animationiteration:Ch("Animation","AnimationIteration"),animationstart:Ch("Animation","AnimationStart"),transitionend:Ch("Transition","TransitionEnd")},Ym={},zP={};a&&(zP=document.createElement("div").style,"AnimationEvent"in window||(delete zl.animationend.animation,delete zl.animationiteration.animation,delete zl.animationstart.animation),"TransitionEvent"in window||delete zl.transitionend.transition);function _h(l){if(Ym[l])return Ym[l];if(!zl[l])return l;var u=zl[l],m;for(m in u)if(u.hasOwnProperty(m)&&m in zP)return Ym[l]=u[m];return l}var BP=_h("animationend"),UP=_h("animationiteration"),HP=_h("animationstart"),KP=_h("transitionend"),WP=new Map,GP="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 Li(l,u){WP.set(l,u),o(u,[l])}for(var Xm=0;Xm<GP.length;Xm++){var Zm=GP[Xm],i$=Zm.toLowerCase(),a$=Zm[0].toUpperCase()+Zm.slice(1);Li(i$,"on"+a$)}Li(BP,"onAnimationEnd"),Li(UP,"onAnimationIteration"),Li(HP,"onAnimationStart"),Li("dblclick","onDoubleClick"),Li("focusin","onFocus"),Li("focusout","onBlur"),Li(KP,"onTransitionEnd"),i("onMouseEnter",["mouseout","mouseover"]),i("onMouseLeave",["mouseout","mouseover"]),i("onPointerEnter",["pointerout","pointerover"]),i("onPointerLeave",["pointerout","pointerover"]),o("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),o("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),o("onBeforeInput",["compositionend","keypress","textInput","paste"]),o("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),o("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),o("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var yu="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(" "),l$=new Set("cancel close invalid load scroll toggle".split(" ").concat(yu));function VP(l,u,m){var x=l.type||"unknown-event";l.currentTarget=m,Em(x,u,void 0,l),l.currentTarget=null}function qP(l,u){u=(u&4)!==0;for(var m=0;m<l.length;m++){var x=l[m],I=x.event;x=x.listeners;e:{var T=void 0;if(u)for(var O=x.length-1;0<=O;O--){var z=x[O],G=z.instance,oe=z.currentTarget;if(z=z.listener,G!==T&&I.isPropagationStopped())break e;VP(I,z,oe),T=G}else for(O=0;O<x.length;O++){if(z=x[O],G=z.instance,oe=z.currentTarget,z=z.listener,G!==T&&I.isPropagationStopped())break e;VP(I,z,oe),T=G}}}if(us)throw l=ru,us=!1,ru=null,l}function Dt(l,u){var m=u[oy];m===void 0&&(m=u[oy]=new Set);var x=l+"__bubble";m.has(x)||(YP(u,l,2,!1),m.add(x))}function Qm(l,u,m){var x=0;u&&(x|=4),YP(m,l,x,u)}var Ih="_reactListening"+Math.random().toString(36).slice(2);function Su(l){if(!l[Ih]){l[Ih]=!0,r.forEach(function(m){m!=="selectionchange"&&(l$.has(m)||Qm(m,!1,l),Qm(m,!0,l))});var u=l.nodeType===9?l:l.ownerDocument;u===null||u[Ih]||(u[Ih]=!0,Qm("selectionchange",!1,u))}}function YP(l,u,m,x){switch(en(u)){case 1:var I=de;break;case 4:I=Te;break;default:I=vt}m=I.bind(null,u,m,l),I=void 0,!nu||u!=="touchstart"&&u!=="touchmove"&&u!=="wheel"||(I=!0),x?I!==void 0?l.addEventListener(u,m,{capture:!0,passive:I}):l.addEventListener(u,m,!0):I!==void 0?l.addEventListener(u,m,{passive:I}):l.addEventListener(u,m,!1)}function Jm(l,u,m,x,I){var T=x;if(!(u&1)&&!(u&2)&&x!==null)e:for(;;){if(x===null)return;var O=x.tag;if(O===3||O===4){var z=x.stateNode.containerInfo;if(z===I||z.nodeType===8&&z.parentNode===I)break;if(O===4)for(O=x.return;O!==null;){var G=O.tag;if((G===3||G===4)&&(G=O.stateNode.containerInfo,G===I||G.nodeType===8&&G.parentNode===I))return;O=O.return}for(;z!==null;){if(O=Na(z),O===null)return;if(G=O.tag,G===5||G===6){x=T=O;continue e}z=z.parentNode}}x=x.return}dh(function(){var oe=T,fe=yr(m),ge=[];e:{var pe=WP.get(l);if(pe!==void 0){var Ee=Ls,je=l;switch(l){case"keypress":if(tn(m)===0)break e;case"keydown":case"keyup":Ee=N4;break;case"focusin":je="focus",Ee=Bm;break;case"focusout":je="blur",Ee=Bm;break;case"beforeblur":case"afterblur":Ee=Bm;break;case"click":if(m.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":Ee=wP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Ee=I4;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Ee=B4;break;case BP:case UP:case HP:Ee=k4;break;case KP:Ee=H4;break;case"scroll":Ee=Fl;break;case"wheel":Ee=W4;break;case"copy":case"cut":case"paste":Ee=A4;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Ee=PP}var Oe=(u&4)!==0,nn=!Oe&&l==="scroll",J=Oe?pe!==null?pe+"Capture":null:pe;Oe=[];for(var q=oe,re;q!==null;){re=q;var ye=re.stateNode;if(re.tag===5&&ye!==null&&(re=ye,J!==null&&(ye=Ma(q,J),ye!=null&&Oe.push(vu(q,ye,re)))),nn)break;q=q.return}0<Oe.length&&(pe=new Ee(pe,je,null,m,fe),ge.push({event:pe,listeners:Oe}))}}if(!(u&7)){e:{if(pe=l==="mouseover"||l==="pointerover",Ee=l==="mouseout"||l==="pointerout",pe&&m!==Ur&&(je=m.relatedTarget||m.fromElement)&&(Na(je)||je[Yo]))break e;if((Ee||pe)&&(pe=fe.window===fe?fe:(pe=fe.ownerDocument)?pe.defaultView||pe.parentWindow:window,Ee?(je=m.relatedTarget||m.toElement,Ee=oe,je=je?Na(je):null,je!==null&&(nn=Vo(je),je!==nn||je.tag!==5&&je.tag!==6)&&(je=null)):(Ee=null,je=oe),Ee!==je)){if(Oe=wP,ye="onMouseLeave",J="onMouseEnter",q="mouse",(l==="pointerout"||l==="pointerover")&&(Oe=PP,ye="onPointerLeave",J="onPointerEnter",q="pointer"),nn=Ee==null?pe:Hl(Ee),re=je==null?pe:Hl(je),pe=new Oe(ye,q+"leave",Ee,m,fe),pe.target=nn,pe.relatedTarget=re,ye=null,Na(fe)===oe&&(Oe=new Oe(J,q+"enter",je,m,fe),Oe.target=re,Oe.relatedTarget=nn,ye=Oe),nn=ye,Ee&&je)t:{for(Oe=Ee,J=je,q=0,re=Oe;re;re=Bl(re))q++;for(re=0,ye=J;ye;ye=Bl(ye))re++;for(;0<q-re;)Oe=Bl(Oe),q--;for(;0<re-q;)J=Bl(J),re--;for(;q--;){if(Oe===J||J!==null&&Oe===J.alternate)break t;Oe=Bl(Oe),J=Bl(J)}Oe=null}else Oe=null;Ee!==null&&XP(ge,pe,Ee,Oe,!1),je!==null&&nn!==null&&XP(ge,nn,je,Oe,!0)}}e:{if(pe=oe?Hl(oe):window,Ee=pe.nodeName&&pe.nodeName.toLowerCase(),Ee==="select"||Ee==="input"&&pe.type==="file")var De=Q4;else if(kP(pe))if(AP)De=n$;else{De=e$;var Be=J4}else(Ee=pe.nodeName)&&Ee.toLowerCase()==="input"&&(pe.type==="checkbox"||pe.type==="radio")&&(De=t$);if(De&&(De=De(l,oe))){MP(ge,De,m,fe);break e}Be&&Be(l,pe,oe),l==="focusout"&&(Be=pe._wrapperState)&&Be.controlled&&pe.type==="number"&&fr(pe,"number",pe.value)}switch(Be=oe?Hl(oe):window,l){case"focusin":(kP(Be)||Be.contentEditable==="true")&&($l=Be,Vm=oe,mu=null);break;case"focusout":mu=Vm=$l=null;break;case"mousedown":qm=!0;break;case"contextmenu":case"mouseup":case"dragend":qm=!1,$P(ge,m,fe);break;case"selectionchange":if(o$)break;case"keydown":case"keyup":$P(ge,m,fe)}var Ue;if(Hm)e:{switch(l){case"compositionstart":var Ve="onCompositionStart";break e;case"compositionend":Ve="onCompositionEnd";break e;case"compositionupdate":Ve="onCompositionUpdate";break e}Ve=void 0}else Nl?EP(l,m)&&(Ve="onCompositionEnd"):l==="keydown"&&m.keyCode===229&&(Ve="onCompositionStart");Ve&&(CP&&m.locale!=="ko"&&(Nl||Ve!=="onCompositionStart"?Ve==="onCompositionEnd"&&Nl&&(Ue=vr()):(Mt=fe,It="value"in Mt?Mt.value:Mt.textContent,Nl=!0)),Be=Eh(oe,Ve),0<Be.length&&(Ve=new bP(Ve,l,null,m,fe),ge.push({event:Ve,listeners:Be}),Ue?Ve.data=Ue:(Ue=TP(m),Ue!==null&&(Ve.data=Ue)))),(Ue=V4?q4(l,m):Y4(l,m))&&(oe=Eh(oe,"onBeforeInput"),0<oe.length&&(fe=new bP("onBeforeInput","beforeinput",null,m,fe),ge.push({event:fe,listeners:oe}),fe.data=Ue))}qP(ge,u)})}function vu(l,u,m){return{instance:l,listener:u,currentTarget:m}}function Eh(l,u){for(var m=u+"Capture",x=[];l!==null;){var I=l,T=I.stateNode;I.tag===5&&T!==null&&(I=T,T=Ma(l,m),T!=null&&x.unshift(vu(l,T,I)),T=Ma(l,u),T!=null&&x.push(vu(l,T,I))),l=l.return}return x}function Bl(l){if(l===null)return null;do l=l.return;while(l&&l.tag!==5);return l||null}function XP(l,u,m,x,I){for(var T=u._reactName,O=[];m!==null&&m!==x;){var z=m,G=z.alternate,oe=z.stateNode;if(G!==null&&G===x)break;z.tag===5&&oe!==null&&(z=oe,I?(G=Ma(m,T),G!=null&&O.unshift(vu(m,G,z))):I||(G=Ma(m,T),G!=null&&O.push(vu(m,G,z)))),m=m.return}O.length!==0&&l.push({event:u,listeners:O})}var c$=/\r\n?/g,u$=/\u0000|\uFFFD/g;function ZP(l){return(typeof l=="string"?l:""+l).replace(c$,`
|
|
38
|
+
`).replace(u$,"")}function Th(l,u,m){if(u=ZP(u),ZP(l)!==u&&m)throw Error(t(425))}function kh(){}var ey=null,ty=null;function ny(l,u){return l==="textarea"||l==="noscript"||typeof u.children=="string"||typeof u.children=="number"||typeof u.dangerouslySetInnerHTML=="object"&&u.dangerouslySetInnerHTML!==null&&u.dangerouslySetInnerHTML.__html!=null}var ry=typeof setTimeout=="function"?setTimeout:void 0,d$=typeof clearTimeout=="function"?clearTimeout:void 0,QP=typeof Promise=="function"?Promise:void 0,h$=typeof queueMicrotask=="function"?queueMicrotask:typeof QP<"u"?function(l){return QP.resolve(null).then(l).catch(p$)}:ry;function p$(l){setTimeout(function(){throw l})}function sy(l,u){var m=u,x=0;do{var I=m.nextSibling;if(l.removeChild(m),I&&I.nodeType===8)if(m=I.data,m==="/$"){if(x===0){l.removeChild(I),Fa(u);return}x--}else m!=="$"&&m!=="$?"&&m!=="$!"||x++;m=I}while(m);Fa(u)}function Fi(l){for(;l!=null;l=l.nextSibling){var u=l.nodeType;if(u===1||u===3)break;if(u===8){if(u=l.data,u==="$"||u==="$!"||u==="$?")break;if(u==="/$")return null}}return l}function JP(l){l=l.previousSibling;for(var u=0;l;){if(l.nodeType===8){var m=l.data;if(m==="$"||m==="$!"||m==="$?"){if(u===0)return l;u--}else m==="/$"&&u++}l=l.previousSibling}return null}var Ul=Math.random().toString(36).slice(2),po="__reactFiber$"+Ul,xu="__reactProps$"+Ul,Yo="__reactContainer$"+Ul,oy="__reactEvents$"+Ul,f$="__reactListeners$"+Ul,g$="__reactHandles$"+Ul;function Na(l){var u=l[po];if(u)return u;for(var m=l.parentNode;m;){if(u=m[Yo]||m[po]){if(m=u.alternate,u.child!==null||m!==null&&m.child!==null)for(l=JP(l);l!==null;){if(m=l[po])return m;l=JP(l)}return u}l=m,m=l.parentNode}return null}function wu(l){return l=l[po]||l[Yo],!l||l.tag!==5&&l.tag!==6&&l.tag!==13&&l.tag!==3?null:l}function Hl(l){if(l.tag===5||l.tag===6)return l.stateNode;throw Error(t(33))}function Mh(l){return l[xu]||null}var iy=[],Kl=-1;function Ni(l){return{current:l}}function Lt(l){0>Kl||(l.current=iy[Kl],iy[Kl]=null,Kl--)}function At(l,u){Kl++,iy[Kl]=l.current,l.current=u}var $i={},Fn=Ni($i),xr=Ni(!1),$a=$i;function Wl(l,u){var m=l.type.contextTypes;if(!m)return $i;var x=l.stateNode;if(x&&x.__reactInternalMemoizedUnmaskedChildContext===u)return x.__reactInternalMemoizedMaskedChildContext;var I={},T;for(T in m)I[T]=u[T];return x&&(l=l.stateNode,l.__reactInternalMemoizedUnmaskedChildContext=u,l.__reactInternalMemoizedMaskedChildContext=I),I}function wr(l){return l=l.childContextTypes,l!=null}function Ah(){Lt(xr),Lt(Fn)}function eC(l,u,m){if(Fn.current!==$i)throw Error(t(168));At(Fn,u),At(xr,m)}function tC(l,u,m){var x=l.stateNode;if(u=u.childContextTypes,typeof x.getChildContext!="function")return m;x=x.getChildContext();for(var I in x)if(!(I in u))throw Error(t(108,Me(l)||"Unknown",I));return ae({},m,x)}function jh(l){return l=(l=l.stateNode)&&l.__reactInternalMemoizedMergedChildContext||$i,$a=Fn.current,At(Fn,l),At(xr,xr.current),!0}function nC(l,u,m){var x=l.stateNode;if(!x)throw Error(t(169));m?(l=tC(l,u,$a),x.__reactInternalMemoizedMergedChildContext=l,Lt(xr),Lt(Fn),At(Fn,l)):Lt(xr),At(xr,m)}var Xo=null,Rh=!1,ay=!1;function rC(l){Xo===null?Xo=[l]:Xo.push(l)}function m$(l){Rh=!0,rC(l)}function zi(){if(!ay&&Xo!==null){ay=!0;var l=0,u=ct;try{var m=Xo;for(ct=1;l<m.length;l++){var x=m[l];do x=x(!0);while(x!==null)}Xo=null,Rh=!1}catch(I){throw Xo!==null&&(Xo=Xo.slice(l+1)),gh(su,zi),I}finally{ct=u,ay=!1}}return null}var Gl=[],Vl=0,Oh=null,Dh=0,ps=[],fs=0,za=null,Zo=1,Qo="";function Ba(l,u){Gl[Vl++]=Dh,Gl[Vl++]=Oh,Oh=l,Dh=u}function sC(l,u,m){ps[fs++]=Zo,ps[fs++]=Qo,ps[fs++]=za,za=l;var x=Zo;l=Qo;var I=32-Kr(x)-1;x&=~(1<<I),m+=1;var T=32-Kr(u)+I;if(30<T){var O=I-I%5;T=(x&(1<<O)-1).toString(32),x>>=O,I-=O,Zo=1<<32-Kr(u)+I|m<<I|x,Qo=T+l}else Zo=1<<T|m<<I|x,Qo=l}function ly(l){l.return!==null&&(Ba(l,1),sC(l,1,0))}function cy(l){for(;l===Oh;)Oh=Gl[--Vl],Gl[Vl]=null,Dh=Gl[--Vl],Gl[Vl]=null;for(;l===za;)za=ps[--fs],ps[fs]=null,Qo=ps[--fs],ps[fs]=null,Zo=ps[--fs],ps[fs]=null}var Wr=null,Gr=null,Bt=!1,Ns=null;function oC(l,u){var m=Ss(5,null,null,0);m.elementType="DELETED",m.stateNode=u,m.return=l,u=l.deletions,u===null?(l.deletions=[m],l.flags|=16):u.push(m)}function iC(l,u){switch(l.tag){case 5:var m=l.type;return u=u.nodeType!==1||m.toLowerCase()!==u.nodeName.toLowerCase()?null:u,u!==null?(l.stateNode=u,Wr=l,Gr=Fi(u.firstChild),!0):!1;case 6:return u=l.pendingProps===""||u.nodeType!==3?null:u,u!==null?(l.stateNode=u,Wr=l,Gr=null,!0):!1;case 13:return u=u.nodeType!==8?null:u,u!==null?(m=za!==null?{id:Zo,overflow:Qo}:null,l.memoizedState={dehydrated:u,treeContext:m,retryLane:1073741824},m=Ss(18,null,null,0),m.stateNode=u,m.return=l,l.child=m,Wr=l,Gr=null,!0):!1;default:return!1}}function uy(l){return(l.mode&1)!==0&&(l.flags&128)===0}function dy(l){if(Bt){var u=Gr;if(u){var m=u;if(!iC(l,u)){if(uy(l))throw Error(t(418));u=Fi(m.nextSibling);var x=Wr;u&&iC(l,u)?oC(x,m):(l.flags=l.flags&-4097|2,Bt=!1,Wr=l)}}else{if(uy(l))throw Error(t(418));l.flags=l.flags&-4097|2,Bt=!1,Wr=l}}}function aC(l){for(l=l.return;l!==null&&l.tag!==5&&l.tag!==3&&l.tag!==13;)l=l.return;Wr=l}function Lh(l){if(l!==Wr)return!1;if(!Bt)return aC(l),Bt=!0,!1;var u;if((u=l.tag!==3)&&!(u=l.tag!==5)&&(u=l.type,u=u!=="head"&&u!=="body"&&!ny(l.type,l.memoizedProps)),u&&(u=Gr)){if(uy(l))throw lC(),Error(t(418));for(;u;)oC(l,u),u=Fi(u.nextSibling)}if(aC(l),l.tag===13){if(l=l.memoizedState,l=l!==null?l.dehydrated:null,!l)throw Error(t(317));e:{for(l=l.nextSibling,u=0;l;){if(l.nodeType===8){var m=l.data;if(m==="/$"){if(u===0){Gr=Fi(l.nextSibling);break e}u--}else m!=="$"&&m!=="$!"&&m!=="$?"||u++}l=l.nextSibling}Gr=null}}else Gr=Wr?Fi(l.stateNode.nextSibling):null;return!0}function lC(){for(var l=Gr;l;)l=Fi(l.nextSibling)}function ql(){Gr=Wr=null,Bt=!1}function hy(l){Ns===null?Ns=[l]:Ns.push(l)}var y$=E.ReactCurrentBatchConfig;function bu(l,u,m){if(l=m.ref,l!==null&&typeof l!="function"&&typeof l!="object"){if(m._owner){if(m=m._owner,m){if(m.tag!==1)throw Error(t(309));var x=m.stateNode}if(!x)throw Error(t(147,l));var I=x,T=""+l;return u!==null&&u.ref!==null&&typeof u.ref=="function"&&u.ref._stringRef===T?u.ref:(u=function(O){var z=I.refs;O===null?delete z[T]:z[T]=O},u._stringRef=T,u)}if(typeof l!="string")throw Error(t(284));if(!m._owner)throw Error(t(290,l))}return l}function Fh(l,u){throw l=Object.prototype.toString.call(u),Error(t(31,l==="[object Object]"?"object with keys {"+Object.keys(u).join(", ")+"}":l))}function cC(l){var u=l._init;return u(l._payload)}function uC(l){function u(J,q){if(l){var re=J.deletions;re===null?(J.deletions=[q],J.flags|=16):re.push(q)}}function m(J,q){if(!l)return null;for(;q!==null;)u(J,q),q=q.sibling;return null}function x(J,q){for(J=new Map;q!==null;)q.key!==null?J.set(q.key,q):J.set(q.index,q),q=q.sibling;return J}function I(J,q){return J=qi(J,q),J.index=0,J.sibling=null,J}function T(J,q,re){return J.index=re,l?(re=J.alternate,re!==null?(re=re.index,re<q?(J.flags|=2,q):re):(J.flags|=2,q)):(J.flags|=1048576,q)}function O(J){return l&&J.alternate===null&&(J.flags|=2),J}function z(J,q,re,ye){return q===null||q.tag!==6?(q=rS(re,J.mode,ye),q.return=J,q):(q=I(q,re),q.return=J,q)}function G(J,q,re,ye){var De=re.type;return De===R?fe(J,q,re.props.children,ye,re.key):q!==null&&(q.elementType===De||typeof De=="object"&&De!==null&&De.$$typeof===Y&&cC(De)===q.type)?(ye=I(q,re.props),ye.ref=bu(J,q,re),ye.return=J,ye):(ye=ap(re.type,re.key,re.props,null,J.mode,ye),ye.ref=bu(J,q,re),ye.return=J,ye)}function oe(J,q,re,ye){return q===null||q.tag!==4||q.stateNode.containerInfo!==re.containerInfo||q.stateNode.implementation!==re.implementation?(q=sS(re,J.mode,ye),q.return=J,q):(q=I(q,re.children||[]),q.return=J,q)}function fe(J,q,re,ye,De){return q===null||q.tag!==7?(q=Ya(re,J.mode,ye,De),q.return=J,q):(q=I(q,re),q.return=J,q)}function ge(J,q,re){if(typeof q=="string"&&q!==""||typeof q=="number")return q=rS(""+q,J.mode,re),q.return=J,q;if(typeof q=="object"&&q!==null){switch(q.$$typeof){case M:return re=ap(q.type,q.key,q.props,null,J.mode,re),re.ref=bu(J,null,q),re.return=J,re;case A:return q=sS(q,J.mode,re),q.return=J,q;case Y:var ye=q._init;return ge(J,ye(q._payload),re)}if(gr(q)||Q(q))return q=Ya(q,J.mode,re,null),q.return=J,q;Fh(J,q)}return null}function pe(J,q,re,ye){var De=q!==null?q.key:null;if(typeof re=="string"&&re!==""||typeof re=="number")return De!==null?null:z(J,q,""+re,ye);if(typeof re=="object"&&re!==null){switch(re.$$typeof){case M:return re.key===De?G(J,q,re,ye):null;case A:return re.key===De?oe(J,q,re,ye):null;case Y:return De=re._init,pe(J,q,De(re._payload),ye)}if(gr(re)||Q(re))return De!==null?null:fe(J,q,re,ye,null);Fh(J,re)}return null}function Ee(J,q,re,ye,De){if(typeof ye=="string"&&ye!==""||typeof ye=="number")return J=J.get(re)||null,z(q,J,""+ye,De);if(typeof ye=="object"&&ye!==null){switch(ye.$$typeof){case M:return J=J.get(ye.key===null?re:ye.key)||null,G(q,J,ye,De);case A:return J=J.get(ye.key===null?re:ye.key)||null,oe(q,J,ye,De);case Y:var Be=ye._init;return Ee(J,q,re,Be(ye._payload),De)}if(gr(ye)||Q(ye))return J=J.get(re)||null,fe(q,J,ye,De,null);Fh(q,ye)}return null}function je(J,q,re,ye){for(var De=null,Be=null,Ue=q,Ve=q=0,Sn=null;Ue!==null&&Ve<re.length;Ve++){Ue.index>Ve?(Sn=Ue,Ue=null):Sn=Ue.sibling;var ft=pe(J,Ue,re[Ve],ye);if(ft===null){Ue===null&&(Ue=Sn);break}l&&Ue&&ft.alternate===null&&u(J,Ue),q=T(ft,q,Ve),Be===null?De=ft:Be.sibling=ft,Be=ft,Ue=Sn}if(Ve===re.length)return m(J,Ue),Bt&&Ba(J,Ve),De;if(Ue===null){for(;Ve<re.length;Ve++)Ue=ge(J,re[Ve],ye),Ue!==null&&(q=T(Ue,q,Ve),Be===null?De=Ue:Be.sibling=Ue,Be=Ue);return Bt&&Ba(J,Ve),De}for(Ue=x(J,Ue);Ve<re.length;Ve++)Sn=Ee(Ue,J,Ve,re[Ve],ye),Sn!==null&&(l&&Sn.alternate!==null&&Ue.delete(Sn.key===null?Ve:Sn.key),q=T(Sn,q,Ve),Be===null?De=Sn:Be.sibling=Sn,Be=Sn);return l&&Ue.forEach(function(Yi){return u(J,Yi)}),Bt&&Ba(J,Ve),De}function Oe(J,q,re,ye){var De=Q(re);if(typeof De!="function")throw Error(t(150));if(re=De.call(re),re==null)throw Error(t(151));for(var Be=De=null,Ue=q,Ve=q=0,Sn=null,ft=re.next();Ue!==null&&!ft.done;Ve++,ft=re.next()){Ue.index>Ve?(Sn=Ue,Ue=null):Sn=Ue.sibling;var Yi=pe(J,Ue,ft.value,ye);if(Yi===null){Ue===null&&(Ue=Sn);break}l&&Ue&&Yi.alternate===null&&u(J,Ue),q=T(Yi,q,Ve),Be===null?De=Yi:Be.sibling=Yi,Be=Yi,Ue=Sn}if(ft.done)return m(J,Ue),Bt&&Ba(J,Ve),De;if(Ue===null){for(;!ft.done;Ve++,ft=re.next())ft=ge(J,ft.value,ye),ft!==null&&(q=T(ft,q,Ve),Be===null?De=ft:Be.sibling=ft,Be=ft);return Bt&&Ba(J,Ve),De}for(Ue=x(J,Ue);!ft.done;Ve++,ft=re.next())ft=Ee(Ue,J,Ve,ft.value,ye),ft!==null&&(l&&ft.alternate!==null&&Ue.delete(ft.key===null?Ve:ft.key),q=T(ft,q,Ve),Be===null?De=ft:Be.sibling=ft,Be=ft);return l&&Ue.forEach(function(X$){return u(J,X$)}),Bt&&Ba(J,Ve),De}function nn(J,q,re,ye){if(typeof re=="object"&&re!==null&&re.type===R&&re.key===null&&(re=re.props.children),typeof re=="object"&&re!==null){switch(re.$$typeof){case M:e:{for(var De=re.key,Be=q;Be!==null;){if(Be.key===De){if(De=re.type,De===R){if(Be.tag===7){m(J,Be.sibling),q=I(Be,re.props.children),q.return=J,J=q;break e}}else if(Be.elementType===De||typeof De=="object"&&De!==null&&De.$$typeof===Y&&cC(De)===Be.type){m(J,Be.sibling),q=I(Be,re.props),q.ref=bu(J,Be,re),q.return=J,J=q;break e}m(J,Be);break}else u(J,Be);Be=Be.sibling}re.type===R?(q=Ya(re.props.children,J.mode,ye,re.key),q.return=J,J=q):(ye=ap(re.type,re.key,re.props,null,J.mode,ye),ye.ref=bu(J,q,re),ye.return=J,J=ye)}return O(J);case A:e:{for(Be=re.key;q!==null;){if(q.key===Be)if(q.tag===4&&q.stateNode.containerInfo===re.containerInfo&&q.stateNode.implementation===re.implementation){m(J,q.sibling),q=I(q,re.children||[]),q.return=J,J=q;break e}else{m(J,q);break}else u(J,q);q=q.sibling}q=sS(re,J.mode,ye),q.return=J,J=q}return O(J);case Y:return Be=re._init,nn(J,q,Be(re._payload),ye)}if(gr(re))return je(J,q,re,ye);if(Q(re))return Oe(J,q,re,ye);Fh(J,re)}return typeof re=="string"&&re!==""||typeof re=="number"?(re=""+re,q!==null&&q.tag===6?(m(J,q.sibling),q=I(q,re),q.return=J,J=q):(m(J,q),q=rS(re,J.mode,ye),q.return=J,J=q),O(J)):m(J,q)}return nn}var Yl=uC(!0),dC=uC(!1),Nh=Ni(null),$h=null,Xl=null,py=null;function fy(){py=Xl=$h=null}function gy(l){var u=Nh.current;Lt(Nh),l._currentValue=u}function my(l,u,m){for(;l!==null;){var x=l.alternate;if((l.childLanes&u)!==u?(l.childLanes|=u,x!==null&&(x.childLanes|=u)):x!==null&&(x.childLanes&u)!==u&&(x.childLanes|=u),l===m)break;l=l.return}}function Zl(l,u){$h=l,py=Xl=null,l=l.dependencies,l!==null&&l.firstContext!==null&&(l.lanes&u&&(br=!0),l.firstContext=null)}function gs(l){var u=l._currentValue;if(py!==l)if(l={context:l,memoizedValue:u,next:null},Xl===null){if($h===null)throw Error(t(308));Xl=l,$h.dependencies={lanes:0,firstContext:l}}else Xl=Xl.next=l;return u}var Ua=null;function yy(l){Ua===null?Ua=[l]:Ua.push(l)}function hC(l,u,m,x){var I=u.interleaved;return I===null?(m.next=m,yy(u)):(m.next=I.next,I.next=m),u.interleaved=m,Jo(l,x)}function Jo(l,u){l.lanes|=u;var m=l.alternate;for(m!==null&&(m.lanes|=u),m=l,l=l.return;l!==null;)l.childLanes|=u,m=l.alternate,m!==null&&(m.childLanes|=u),m=l,l=l.return;return m.tag===3?m.stateNode:null}var Bi=!1;function Sy(l){l.updateQueue={baseState:l.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function pC(l,u){l=l.updateQueue,u.updateQueue===l&&(u.updateQueue={baseState:l.baseState,firstBaseUpdate:l.firstBaseUpdate,lastBaseUpdate:l.lastBaseUpdate,shared:l.shared,effects:l.effects})}function ei(l,u){return{eventTime:l,lane:u,tag:0,payload:null,callback:null,next:null}}function Ui(l,u,m){var x=l.updateQueue;if(x===null)return null;if(x=x.shared,dt&2){var I=x.pending;return I===null?u.next=u:(u.next=I.next,I.next=u),x.pending=u,Jo(l,m)}return I=x.interleaved,I===null?(u.next=u,yy(x)):(u.next=I.next,I.next=u),x.interleaved=u,Jo(l,m)}function zh(l,u,m){if(u=u.updateQueue,u!==null&&(u=u.shared,(m&4194240)!==0)){var x=u.lanes;x&=l.pendingLanes,m|=x,u.lanes=m,Dl(l,m)}}function fC(l,u){var m=l.updateQueue,x=l.alternate;if(x!==null&&(x=x.updateQueue,m===x)){var I=null,T=null;if(m=m.firstBaseUpdate,m!==null){do{var O={eventTime:m.eventTime,lane:m.lane,tag:m.tag,payload:m.payload,callback:m.callback,next:null};T===null?I=T=O:T=T.next=O,m=m.next}while(m!==null);T===null?I=T=u:T=T.next=u}else I=T=u;m={baseState:x.baseState,firstBaseUpdate:I,lastBaseUpdate:T,shared:x.shared,effects:x.effects},l.updateQueue=m;return}l=m.lastBaseUpdate,l===null?m.firstBaseUpdate=u:l.next=u,m.lastBaseUpdate=u}function Bh(l,u,m,x){var I=l.updateQueue;Bi=!1;var T=I.firstBaseUpdate,O=I.lastBaseUpdate,z=I.shared.pending;if(z!==null){I.shared.pending=null;var G=z,oe=G.next;G.next=null,O===null?T=oe:O.next=oe,O=G;var fe=l.alternate;fe!==null&&(fe=fe.updateQueue,z=fe.lastBaseUpdate,z!==O&&(z===null?fe.firstBaseUpdate=oe:z.next=oe,fe.lastBaseUpdate=G))}if(T!==null){var ge=I.baseState;O=0,fe=oe=G=null,z=T;do{var pe=z.lane,Ee=z.eventTime;if((x&pe)===pe){fe!==null&&(fe=fe.next={eventTime:Ee,lane:0,tag:z.tag,payload:z.payload,callback:z.callback,next:null});e:{var je=l,Oe=z;switch(pe=u,Ee=m,Oe.tag){case 1:if(je=Oe.payload,typeof je=="function"){ge=je.call(Ee,ge,pe);break e}ge=je;break e;case 3:je.flags=je.flags&-65537|128;case 0:if(je=Oe.payload,pe=typeof je=="function"?je.call(Ee,ge,pe):je,pe==null)break e;ge=ae({},ge,pe);break e;case 2:Bi=!0}}z.callback!==null&&z.lane!==0&&(l.flags|=64,pe=I.effects,pe===null?I.effects=[z]:pe.push(z))}else Ee={eventTime:Ee,lane:pe,tag:z.tag,payload:z.payload,callback:z.callback,next:null},fe===null?(oe=fe=Ee,G=ge):fe=fe.next=Ee,O|=pe;if(z=z.next,z===null){if(z=I.shared.pending,z===null)break;pe=z,z=pe.next,pe.next=null,I.lastBaseUpdate=pe,I.shared.pending=null}}while(!0);if(fe===null&&(G=ge),I.baseState=G,I.firstBaseUpdate=oe,I.lastBaseUpdate=fe,u=I.shared.interleaved,u!==null){I=u;do O|=I.lane,I=I.next;while(I!==u)}else T===null&&(I.shared.lanes=0);Wa|=O,l.lanes=O,l.memoizedState=ge}}function gC(l,u,m){if(l=u.effects,u.effects=null,l!==null)for(u=0;u<l.length;u++){var x=l[u],I=x.callback;if(I!==null){if(x.callback=null,x=m,typeof I!="function")throw Error(t(191,I));I.call(x)}}}var Pu={},fo=Ni(Pu),Cu=Ni(Pu),_u=Ni(Pu);function Ha(l){if(l===Pu)throw Error(t(174));return l}function vy(l,u){switch(At(_u,u),At(Cu,l),At(fo,Pu),l=u.nodeType,l){case 9:case 11:u=(u=u.documentElement)?u.namespaceURI:oo(null,"");break;default:l=l===8?u.parentNode:u,u=l.namespaceURI||null,l=l.tagName,u=oo(u,l)}Lt(fo),At(fo,u)}function Ql(){Lt(fo),Lt(Cu),Lt(_u)}function mC(l){Ha(_u.current);var u=Ha(fo.current),m=oo(u,l.type);u!==m&&(At(Cu,l),At(fo,m))}function xy(l){Cu.current===l&&(Lt(fo),Lt(Cu))}var Wt=Ni(0);function Uh(l){for(var u=l;u!==null;){if(u.tag===13){var m=u.memoizedState;if(m!==null&&(m=m.dehydrated,m===null||m.data==="$?"||m.data==="$!"))return u}else if(u.tag===19&&u.memoizedProps.revealOrder!==void 0){if(u.flags&128)return u}else if(u.child!==null){u.child.return=u,u=u.child;continue}if(u===l)break;for(;u.sibling===null;){if(u.return===null||u.return===l)return null;u=u.return}u.sibling.return=u.return,u=u.sibling}return null}var wy=[];function by(){for(var l=0;l<wy.length;l++)wy[l]._workInProgressVersionPrimary=null;wy.length=0}var Hh=E.ReactCurrentDispatcher,Py=E.ReactCurrentBatchConfig,Ka=0,Gt=null,hn=null,mn=null,Kh=!1,Iu=!1,Eu=0,S$=0;function Nn(){throw Error(t(321))}function Cy(l,u){if(u===null)return!1;for(var m=0;m<u.length&&m<l.length;m++)if(!Fs(l[m],u[m]))return!1;return!0}function _y(l,u,m,x,I,T){if(Ka=T,Gt=u,u.memoizedState=null,u.updateQueue=null,u.lanes=0,Hh.current=l===null||l.memoizedState===null?b$:P$,l=m(x,I),Iu){T=0;do{if(Iu=!1,Eu=0,25<=T)throw Error(t(301));T+=1,mn=hn=null,u.updateQueue=null,Hh.current=C$,l=m(x,I)}while(Iu)}if(Hh.current=Vh,u=hn!==null&&hn.next!==null,Ka=0,mn=hn=Gt=null,Kh=!1,u)throw Error(t(300));return l}function Iy(){var l=Eu!==0;return Eu=0,l}function go(){var l={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return mn===null?Gt.memoizedState=mn=l:mn=mn.next=l,mn}function ms(){if(hn===null){var l=Gt.alternate;l=l!==null?l.memoizedState:null}else l=hn.next;var u=mn===null?Gt.memoizedState:mn.next;if(u!==null)mn=u,hn=l;else{if(l===null)throw Error(t(310));hn=l,l={memoizedState:hn.memoizedState,baseState:hn.baseState,baseQueue:hn.baseQueue,queue:hn.queue,next:null},mn===null?Gt.memoizedState=mn=l:mn=mn.next=l}return mn}function Tu(l,u){return typeof u=="function"?u(l):u}function Ey(l){var u=ms(),m=u.queue;if(m===null)throw Error(t(311));m.lastRenderedReducer=l;var x=hn,I=x.baseQueue,T=m.pending;if(T!==null){if(I!==null){var O=I.next;I.next=T.next,T.next=O}x.baseQueue=I=T,m.pending=null}if(I!==null){T=I.next,x=x.baseState;var z=O=null,G=null,oe=T;do{var fe=oe.lane;if((Ka&fe)===fe)G!==null&&(G=G.next={lane:0,action:oe.action,hasEagerState:oe.hasEagerState,eagerState:oe.eagerState,next:null}),x=oe.hasEagerState?oe.eagerState:l(x,oe.action);else{var ge={lane:fe,action:oe.action,hasEagerState:oe.hasEagerState,eagerState:oe.eagerState,next:null};G===null?(z=G=ge,O=x):G=G.next=ge,Gt.lanes|=fe,Wa|=fe}oe=oe.next}while(oe!==null&&oe!==T);G===null?O=x:G.next=z,Fs(x,u.memoizedState)||(br=!0),u.memoizedState=x,u.baseState=O,u.baseQueue=G,m.lastRenderedState=x}if(l=m.interleaved,l!==null){I=l;do T=I.lane,Gt.lanes|=T,Wa|=T,I=I.next;while(I!==l)}else I===null&&(m.lanes=0);return[u.memoizedState,m.dispatch]}function Ty(l){var u=ms(),m=u.queue;if(m===null)throw Error(t(311));m.lastRenderedReducer=l;var x=m.dispatch,I=m.pending,T=u.memoizedState;if(I!==null){m.pending=null;var O=I=I.next;do T=l(T,O.action),O=O.next;while(O!==I);Fs(T,u.memoizedState)||(br=!0),u.memoizedState=T,u.baseQueue===null&&(u.baseState=T),m.lastRenderedState=T}return[T,x]}function yC(){}function SC(l,u){var m=Gt,x=ms(),I=u(),T=!Fs(x.memoizedState,I);if(T&&(x.memoizedState=I,br=!0),x=x.queue,ky(wC.bind(null,m,x,l),[l]),x.getSnapshot!==u||T||mn!==null&&mn.memoizedState.tag&1){if(m.flags|=2048,ku(9,xC.bind(null,m,x,I,u),void 0,null),yn===null)throw Error(t(349));Ka&30||vC(m,u,I)}return I}function vC(l,u,m){l.flags|=16384,l={getSnapshot:u,value:m},u=Gt.updateQueue,u===null?(u={lastEffect:null,stores:null},Gt.updateQueue=u,u.stores=[l]):(m=u.stores,m===null?u.stores=[l]:m.push(l))}function xC(l,u,m,x){u.value=m,u.getSnapshot=x,bC(u)&&PC(l)}function wC(l,u,m){return m(function(){bC(u)&&PC(l)})}function bC(l){var u=l.getSnapshot;l=l.value;try{var m=u();return!Fs(l,m)}catch{return!0}}function PC(l){var u=Jo(l,1);u!==null&&Us(u,l,1,-1)}function CC(l){var u=go();return typeof l=="function"&&(l=l()),u.memoizedState=u.baseState=l,l={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Tu,lastRenderedState:l},u.queue=l,l=l.dispatch=w$.bind(null,Gt,l),[u.memoizedState,l]}function ku(l,u,m,x){return l={tag:l,create:u,destroy:m,deps:x,next:null},u=Gt.updateQueue,u===null?(u={lastEffect:null,stores:null},Gt.updateQueue=u,u.lastEffect=l.next=l):(m=u.lastEffect,m===null?u.lastEffect=l.next=l:(x=m.next,m.next=l,l.next=x,u.lastEffect=l)),l}function _C(){return ms().memoizedState}function Wh(l,u,m,x){var I=go();Gt.flags|=l,I.memoizedState=ku(1|u,m,void 0,x===void 0?null:x)}function Gh(l,u,m,x){var I=ms();x=x===void 0?null:x;var T=void 0;if(hn!==null){var O=hn.memoizedState;if(T=O.destroy,x!==null&&Cy(x,O.deps)){I.memoizedState=ku(u,m,T,x);return}}Gt.flags|=l,I.memoizedState=ku(1|u,m,T,x)}function IC(l,u){return Wh(8390656,8,l,u)}function ky(l,u){return Gh(2048,8,l,u)}function EC(l,u){return Gh(4,2,l,u)}function TC(l,u){return Gh(4,4,l,u)}function kC(l,u){if(typeof u=="function")return l=l(),u(l),function(){u(null)};if(u!=null)return l=l(),u.current=l,function(){u.current=null}}function MC(l,u,m){return m=m!=null?m.concat([l]):null,Gh(4,4,kC.bind(null,u,l),m)}function My(){}function AC(l,u){var m=ms();u=u===void 0?null:u;var x=m.memoizedState;return x!==null&&u!==null&&Cy(u,x[1])?x[0]:(m.memoizedState=[l,u],l)}function jC(l,u){var m=ms();u=u===void 0?null:u;var x=m.memoizedState;return x!==null&&u!==null&&Cy(u,x[1])?x[0]:(l=l(),m.memoizedState=[l,u],l)}function RC(l,u,m){return Ka&21?(Fs(m,u)||(m=mh(),Gt.lanes|=m,Wa|=m,l.baseState=!0),u):(l.baseState&&(l.baseState=!1,br=!0),l.memoizedState=m)}function v$(l,u){var m=ct;ct=m!==0&&4>m?m:4,l(!0);var x=Py.transition;Py.transition={};try{l(!1),u()}finally{ct=m,Py.transition=x}}function OC(){return ms().memoizedState}function x$(l,u,m){var x=Gi(l);if(m={lane:x,action:m,hasEagerState:!1,eagerState:null,next:null},DC(l))LC(u,m);else if(m=hC(l,u,m,x),m!==null){var I=tr();Us(m,l,x,I),FC(m,u,x)}}function w$(l,u,m){var x=Gi(l),I={lane:x,action:m,hasEagerState:!1,eagerState:null,next:null};if(DC(l))LC(u,I);else{var T=l.alternate;if(l.lanes===0&&(T===null||T.lanes===0)&&(T=u.lastRenderedReducer,T!==null))try{var O=u.lastRenderedState,z=T(O,m);if(I.hasEagerState=!0,I.eagerState=z,Fs(z,O)){var G=u.interleaved;G===null?(I.next=I,yy(u)):(I.next=G.next,G.next=I),u.interleaved=I;return}}catch{}finally{}m=hC(l,u,I,x),m!==null&&(I=tr(),Us(m,l,x,I),FC(m,u,x))}}function DC(l){var u=l.alternate;return l===Gt||u!==null&&u===Gt}function LC(l,u){Iu=Kh=!0;var m=l.pending;m===null?u.next=u:(u.next=m.next,m.next=u),l.pending=u}function FC(l,u,m){if(m&4194240){var x=u.lanes;x&=l.pendingLanes,m|=x,u.lanes=m,Dl(l,m)}}var Vh={readContext:gs,useCallback:Nn,useContext:Nn,useEffect:Nn,useImperativeHandle:Nn,useInsertionEffect:Nn,useLayoutEffect:Nn,useMemo:Nn,useReducer:Nn,useRef:Nn,useState:Nn,useDebugValue:Nn,useDeferredValue:Nn,useTransition:Nn,useMutableSource:Nn,useSyncExternalStore:Nn,useId:Nn,unstable_isNewReconciler:!1},b$={readContext:gs,useCallback:function(l,u){return go().memoizedState=[l,u===void 0?null:u],l},useContext:gs,useEffect:IC,useImperativeHandle:function(l,u,m){return m=m!=null?m.concat([l]):null,Wh(4194308,4,kC.bind(null,u,l),m)},useLayoutEffect:function(l,u){return Wh(4194308,4,l,u)},useInsertionEffect:function(l,u){return Wh(4,2,l,u)},useMemo:function(l,u){var m=go();return u=u===void 0?null:u,l=l(),m.memoizedState=[l,u],l},useReducer:function(l,u,m){var x=go();return u=m!==void 0?m(u):u,x.memoizedState=x.baseState=u,l={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:l,lastRenderedState:u},x.queue=l,l=l.dispatch=x$.bind(null,Gt,l),[x.memoizedState,l]},useRef:function(l){var u=go();return l={current:l},u.memoizedState=l},useState:CC,useDebugValue:My,useDeferredValue:function(l){return go().memoizedState=l},useTransition:function(){var l=CC(!1),u=l[0];return l=v$.bind(null,l[1]),go().memoizedState=l,[u,l]},useMutableSource:function(){},useSyncExternalStore:function(l,u,m){var x=Gt,I=go();if(Bt){if(m===void 0)throw Error(t(407));m=m()}else{if(m=u(),yn===null)throw Error(t(349));Ka&30||vC(x,u,m)}I.memoizedState=m;var T={value:m,getSnapshot:u};return I.queue=T,IC(wC.bind(null,x,T,l),[l]),x.flags|=2048,ku(9,xC.bind(null,x,T,m,u),void 0,null),m},useId:function(){var l=go(),u=yn.identifierPrefix;if(Bt){var m=Qo,x=Zo;m=(x&~(1<<32-Kr(x)-1)).toString(32)+m,u=":"+u+"R"+m,m=Eu++,0<m&&(u+="H"+m.toString(32)),u+=":"}else m=S$++,u=":"+u+"r"+m.toString(32)+":";return l.memoizedState=u},unstable_isNewReconciler:!1},P$={readContext:gs,useCallback:AC,useContext:gs,useEffect:ky,useImperativeHandle:MC,useInsertionEffect:EC,useLayoutEffect:TC,useMemo:jC,useReducer:Ey,useRef:_C,useState:function(){return Ey(Tu)},useDebugValue:My,useDeferredValue:function(l){var u=ms();return RC(u,hn.memoizedState,l)},useTransition:function(){var l=Ey(Tu)[0],u=ms().memoizedState;return[l,u]},useMutableSource:yC,useSyncExternalStore:SC,useId:OC,unstable_isNewReconciler:!1},C$={readContext:gs,useCallback:AC,useContext:gs,useEffect:ky,useImperativeHandle:MC,useInsertionEffect:EC,useLayoutEffect:TC,useMemo:jC,useReducer:Ty,useRef:_C,useState:function(){return Ty(Tu)},useDebugValue:My,useDeferredValue:function(l){var u=ms();return hn===null?u.memoizedState=l:RC(u,hn.memoizedState,l)},useTransition:function(){var l=Ty(Tu)[0],u=ms().memoizedState;return[l,u]},useMutableSource:yC,useSyncExternalStore:SC,useId:OC,unstable_isNewReconciler:!1};function $s(l,u){if(l&&l.defaultProps){u=ae({},u),l=l.defaultProps;for(var m in l)u[m]===void 0&&(u[m]=l[m]);return u}return u}function Ay(l,u,m,x){u=l.memoizedState,m=m(x,u),m=m==null?u:ae({},u,m),l.memoizedState=m,l.lanes===0&&(l.updateQueue.baseState=m)}var qh={isMounted:function(l){return(l=l._reactInternals)?Vo(l)===l:!1},enqueueSetState:function(l,u,m){l=l._reactInternals;var x=tr(),I=Gi(l),T=ei(x,I);T.payload=u,m!=null&&(T.callback=m),u=Ui(l,T,I),u!==null&&(Us(u,l,I,x),zh(u,l,I))},enqueueReplaceState:function(l,u,m){l=l._reactInternals;var x=tr(),I=Gi(l),T=ei(x,I);T.tag=1,T.payload=u,m!=null&&(T.callback=m),u=Ui(l,T,I),u!==null&&(Us(u,l,I,x),zh(u,l,I))},enqueueForceUpdate:function(l,u){l=l._reactInternals;var m=tr(),x=Gi(l),I=ei(m,x);I.tag=2,u!=null&&(I.callback=u),u=Ui(l,I,x),u!==null&&(Us(u,l,x,m),zh(u,l,x))}};function NC(l,u,m,x,I,T,O){return l=l.stateNode,typeof l.shouldComponentUpdate=="function"?l.shouldComponentUpdate(x,T,O):u.prototype&&u.prototype.isPureReactComponent?!gu(m,x)||!gu(I,T):!0}function $C(l,u,m){var x=!1,I=$i,T=u.contextType;return typeof T=="object"&&T!==null?T=gs(T):(I=wr(u)?$a:Fn.current,x=u.contextTypes,T=(x=x!=null)?Wl(l,I):$i),u=new u(m,T),l.memoizedState=u.state!==null&&u.state!==void 0?u.state:null,u.updater=qh,l.stateNode=u,u._reactInternals=l,x&&(l=l.stateNode,l.__reactInternalMemoizedUnmaskedChildContext=I,l.__reactInternalMemoizedMaskedChildContext=T),u}function zC(l,u,m,x){l=u.state,typeof u.componentWillReceiveProps=="function"&&u.componentWillReceiveProps(m,x),typeof u.UNSAFE_componentWillReceiveProps=="function"&&u.UNSAFE_componentWillReceiveProps(m,x),u.state!==l&&qh.enqueueReplaceState(u,u.state,null)}function jy(l,u,m,x){var I=l.stateNode;I.props=m,I.state=l.memoizedState,I.refs={},Sy(l);var T=u.contextType;typeof T=="object"&&T!==null?I.context=gs(T):(T=wr(u)?$a:Fn.current,I.context=Wl(l,T)),I.state=l.memoizedState,T=u.getDerivedStateFromProps,typeof T=="function"&&(Ay(l,u,T,m),I.state=l.memoizedState),typeof u.getDerivedStateFromProps=="function"||typeof I.getSnapshotBeforeUpdate=="function"||typeof I.UNSAFE_componentWillMount!="function"&&typeof I.componentWillMount!="function"||(u=I.state,typeof I.componentWillMount=="function"&&I.componentWillMount(),typeof I.UNSAFE_componentWillMount=="function"&&I.UNSAFE_componentWillMount(),u!==I.state&&qh.enqueueReplaceState(I,I.state,null),Bh(l,m,I,x),I.state=l.memoizedState),typeof I.componentDidMount=="function"&&(l.flags|=4194308)}function Jl(l,u){try{var m="",x=u;do m+=ue(x),x=x.return;while(x);var I=m}catch(T){I=`
|
|
39
|
+
Error generating stack: `+T.message+`
|
|
40
|
+
`+T.stack}return{value:l,source:u,stack:I,digest:null}}function Ry(l,u,m){return{value:l,source:null,stack:m??null,digest:u??null}}function Oy(l,u){try{console.error(u.value)}catch(m){setTimeout(function(){throw m})}}var _$=typeof WeakMap=="function"?WeakMap:Map;function BC(l,u,m){m=ei(-1,m),m.tag=3,m.payload={element:null};var x=u.value;return m.callback=function(){tp||(tp=!0,Yy=x),Oy(l,u)},m}function UC(l,u,m){m=ei(-1,m),m.tag=3;var x=l.type.getDerivedStateFromError;if(typeof x=="function"){var I=u.value;m.payload=function(){return x(I)},m.callback=function(){Oy(l,u)}}var T=l.stateNode;return T!==null&&typeof T.componentDidCatch=="function"&&(m.callback=function(){Oy(l,u),typeof x!="function"&&(Ki===null?Ki=new Set([this]):Ki.add(this));var O=u.stack;this.componentDidCatch(u.value,{componentStack:O!==null?O:""})}),m}function HC(l,u,m){var x=l.pingCache;if(x===null){x=l.pingCache=new _$;var I=new Set;x.set(u,I)}else I=x.get(u),I===void 0&&(I=new Set,x.set(u,I));I.has(m)||(I.add(m),l=$$.bind(null,l,u,m),u.then(l,l))}function KC(l){do{var u;if((u=l.tag===13)&&(u=l.memoizedState,u=u!==null?u.dehydrated!==null:!0),u)return l;l=l.return}while(l!==null);return null}function WC(l,u,m,x,I){return l.mode&1?(l.flags|=65536,l.lanes=I,l):(l===u?l.flags|=65536:(l.flags|=128,m.flags|=131072,m.flags&=-52805,m.tag===1&&(m.alternate===null?m.tag=17:(u=ei(-1,1),u.tag=2,Ui(m,u,1))),m.lanes|=1),l)}var I$=E.ReactCurrentOwner,br=!1;function er(l,u,m,x){u.child=l===null?dC(u,null,m,x):Yl(u,l.child,m,x)}function GC(l,u,m,x,I){m=m.render;var T=u.ref;return Zl(u,I),x=_y(l,u,m,x,T,I),m=Iy(),l!==null&&!br?(u.updateQueue=l.updateQueue,u.flags&=-2053,l.lanes&=~I,ti(l,u,I)):(Bt&&m&&ly(u),u.flags|=1,er(l,u,x,I),u.child)}function VC(l,u,m,x,I){if(l===null){var T=m.type;return typeof T=="function"&&!nS(T)&&T.defaultProps===void 0&&m.compare===null&&m.defaultProps===void 0?(u.tag=15,u.type=T,qC(l,u,T,x,I)):(l=ap(m.type,null,x,u,u.mode,I),l.ref=u.ref,l.return=u,u.child=l)}if(T=l.child,!(l.lanes&I)){var O=T.memoizedProps;if(m=m.compare,m=m!==null?m:gu,m(O,x)&&l.ref===u.ref)return ti(l,u,I)}return u.flags|=1,l=qi(T,x),l.ref=u.ref,l.return=u,u.child=l}function qC(l,u,m,x,I){if(l!==null){var T=l.memoizedProps;if(gu(T,x)&&l.ref===u.ref)if(br=!1,u.pendingProps=x=T,(l.lanes&I)!==0)l.flags&131072&&(br=!0);else return u.lanes=l.lanes,ti(l,u,I)}return Dy(l,u,m,x,I)}function YC(l,u,m){var x=u.pendingProps,I=x.children,T=l!==null?l.memoizedState:null;if(x.mode==="hidden")if(!(u.mode&1))u.memoizedState={baseLanes:0,cachePool:null,transitions:null},At(tc,Vr),Vr|=m;else{if(!(m&1073741824))return l=T!==null?T.baseLanes|m:m,u.lanes=u.childLanes=1073741824,u.memoizedState={baseLanes:l,cachePool:null,transitions:null},u.updateQueue=null,At(tc,Vr),Vr|=l,null;u.memoizedState={baseLanes:0,cachePool:null,transitions:null},x=T!==null?T.baseLanes:m,At(tc,Vr),Vr|=x}else T!==null?(x=T.baseLanes|m,u.memoizedState=null):x=m,At(tc,Vr),Vr|=x;return er(l,u,I,m),u.child}function XC(l,u){var m=u.ref;(l===null&&m!==null||l!==null&&l.ref!==m)&&(u.flags|=512,u.flags|=2097152)}function Dy(l,u,m,x,I){var T=wr(m)?$a:Fn.current;return T=Wl(u,T),Zl(u,I),m=_y(l,u,m,x,T,I),x=Iy(),l!==null&&!br?(u.updateQueue=l.updateQueue,u.flags&=-2053,l.lanes&=~I,ti(l,u,I)):(Bt&&x&&ly(u),u.flags|=1,er(l,u,m,I),u.child)}function ZC(l,u,m,x,I){if(wr(m)){var T=!0;jh(u)}else T=!1;if(Zl(u,I),u.stateNode===null)Xh(l,u),$C(u,m,x),jy(u,m,x,I),x=!0;else if(l===null){var O=u.stateNode,z=u.memoizedProps;O.props=z;var G=O.context,oe=m.contextType;typeof oe=="object"&&oe!==null?oe=gs(oe):(oe=wr(m)?$a:Fn.current,oe=Wl(u,oe));var fe=m.getDerivedStateFromProps,ge=typeof fe=="function"||typeof O.getSnapshotBeforeUpdate=="function";ge||typeof O.UNSAFE_componentWillReceiveProps!="function"&&typeof O.componentWillReceiveProps!="function"||(z!==x||G!==oe)&&zC(u,O,x,oe),Bi=!1;var pe=u.memoizedState;O.state=pe,Bh(u,x,O,I),G=u.memoizedState,z!==x||pe!==G||xr.current||Bi?(typeof fe=="function"&&(Ay(u,m,fe,x),G=u.memoizedState),(z=Bi||NC(u,m,z,x,pe,G,oe))?(ge||typeof O.UNSAFE_componentWillMount!="function"&&typeof O.componentWillMount!="function"||(typeof O.componentWillMount=="function"&&O.componentWillMount(),typeof O.UNSAFE_componentWillMount=="function"&&O.UNSAFE_componentWillMount()),typeof O.componentDidMount=="function"&&(u.flags|=4194308)):(typeof O.componentDidMount=="function"&&(u.flags|=4194308),u.memoizedProps=x,u.memoizedState=G),O.props=x,O.state=G,O.context=oe,x=z):(typeof O.componentDidMount=="function"&&(u.flags|=4194308),x=!1)}else{O=u.stateNode,pC(l,u),z=u.memoizedProps,oe=u.type===u.elementType?z:$s(u.type,z),O.props=oe,ge=u.pendingProps,pe=O.context,G=m.contextType,typeof G=="object"&&G!==null?G=gs(G):(G=wr(m)?$a:Fn.current,G=Wl(u,G));var Ee=m.getDerivedStateFromProps;(fe=typeof Ee=="function"||typeof O.getSnapshotBeforeUpdate=="function")||typeof O.UNSAFE_componentWillReceiveProps!="function"&&typeof O.componentWillReceiveProps!="function"||(z!==ge||pe!==G)&&zC(u,O,x,G),Bi=!1,pe=u.memoizedState,O.state=pe,Bh(u,x,O,I);var je=u.memoizedState;z!==ge||pe!==je||xr.current||Bi?(typeof Ee=="function"&&(Ay(u,m,Ee,x),je=u.memoizedState),(oe=Bi||NC(u,m,oe,x,pe,je,G)||!1)?(fe||typeof O.UNSAFE_componentWillUpdate!="function"&&typeof O.componentWillUpdate!="function"||(typeof O.componentWillUpdate=="function"&&O.componentWillUpdate(x,je,G),typeof O.UNSAFE_componentWillUpdate=="function"&&O.UNSAFE_componentWillUpdate(x,je,G)),typeof O.componentDidUpdate=="function"&&(u.flags|=4),typeof O.getSnapshotBeforeUpdate=="function"&&(u.flags|=1024)):(typeof O.componentDidUpdate!="function"||z===l.memoizedProps&&pe===l.memoizedState||(u.flags|=4),typeof O.getSnapshotBeforeUpdate!="function"||z===l.memoizedProps&&pe===l.memoizedState||(u.flags|=1024),u.memoizedProps=x,u.memoizedState=je),O.props=x,O.state=je,O.context=G,x=oe):(typeof O.componentDidUpdate!="function"||z===l.memoizedProps&&pe===l.memoizedState||(u.flags|=4),typeof O.getSnapshotBeforeUpdate!="function"||z===l.memoizedProps&&pe===l.memoizedState||(u.flags|=1024),x=!1)}return Ly(l,u,m,x,T,I)}function Ly(l,u,m,x,I,T){XC(l,u);var O=(u.flags&128)!==0;if(!x&&!O)return I&&nC(u,m,!1),ti(l,u,T);x=u.stateNode,I$.current=u;var z=O&&typeof m.getDerivedStateFromError!="function"?null:x.render();return u.flags|=1,l!==null&&O?(u.child=Yl(u,l.child,null,T),u.child=Yl(u,null,z,T)):er(l,u,z,T),u.memoizedState=x.state,I&&nC(u,m,!0),u.child}function QC(l){var u=l.stateNode;u.pendingContext?eC(l,u.pendingContext,u.pendingContext!==u.context):u.context&&eC(l,u.context,!1),vy(l,u.containerInfo)}function JC(l,u,m,x,I){return ql(),hy(I),u.flags|=256,er(l,u,m,x),u.child}var Fy={dehydrated:null,treeContext:null,retryLane:0};function Ny(l){return{baseLanes:l,cachePool:null,transitions:null}}function e_(l,u,m){var x=u.pendingProps,I=Wt.current,T=!1,O=(u.flags&128)!==0,z;if((z=O)||(z=l!==null&&l.memoizedState===null?!1:(I&2)!==0),z?(T=!0,u.flags&=-129):(l===null||l.memoizedState!==null)&&(I|=1),At(Wt,I&1),l===null)return dy(u),l=u.memoizedState,l!==null&&(l=l.dehydrated,l!==null)?(u.mode&1?l.data==="$!"?u.lanes=8:u.lanes=1073741824:u.lanes=1,null):(O=x.children,l=x.fallback,T?(x=u.mode,T=u.child,O={mode:"hidden",children:O},!(x&1)&&T!==null?(T.childLanes=0,T.pendingProps=O):T=lp(O,x,0,null),l=Ya(l,x,m,null),T.return=u,l.return=u,T.sibling=l,u.child=T,u.child.memoizedState=Ny(m),u.memoizedState=Fy,l):$y(u,O));if(I=l.memoizedState,I!==null&&(z=I.dehydrated,z!==null))return E$(l,u,O,x,z,I,m);if(T){T=x.fallback,O=u.mode,I=l.child,z=I.sibling;var G={mode:"hidden",children:x.children};return!(O&1)&&u.child!==I?(x=u.child,x.childLanes=0,x.pendingProps=G,u.deletions=null):(x=qi(I,G),x.subtreeFlags=I.subtreeFlags&14680064),z!==null?T=qi(z,T):(T=Ya(T,O,m,null),T.flags|=2),T.return=u,x.return=u,x.sibling=T,u.child=x,x=T,T=u.child,O=l.child.memoizedState,O=O===null?Ny(m):{baseLanes:O.baseLanes|m,cachePool:null,transitions:O.transitions},T.memoizedState=O,T.childLanes=l.childLanes&~m,u.memoizedState=Fy,x}return T=l.child,l=T.sibling,x=qi(T,{mode:"visible",children:x.children}),!(u.mode&1)&&(x.lanes=m),x.return=u,x.sibling=null,l!==null&&(m=u.deletions,m===null?(u.deletions=[l],u.flags|=16):m.push(l)),u.child=x,u.memoizedState=null,x}function $y(l,u){return u=lp({mode:"visible",children:u},l.mode,0,null),u.return=l,l.child=u}function Yh(l,u,m,x){return x!==null&&hy(x),Yl(u,l.child,null,m),l=$y(u,u.pendingProps.children),l.flags|=2,u.memoizedState=null,l}function E$(l,u,m,x,I,T,O){if(m)return u.flags&256?(u.flags&=-257,x=Ry(Error(t(422))),Yh(l,u,O,x)):u.memoizedState!==null?(u.child=l.child,u.flags|=128,null):(T=x.fallback,I=u.mode,x=lp({mode:"visible",children:x.children},I,0,null),T=Ya(T,I,O,null),T.flags|=2,x.return=u,T.return=u,x.sibling=T,u.child=x,u.mode&1&&Yl(u,l.child,null,O),u.child.memoizedState=Ny(O),u.memoizedState=Fy,T);if(!(u.mode&1))return Yh(l,u,O,null);if(I.data==="$!"){if(x=I.nextSibling&&I.nextSibling.dataset,x)var z=x.dgst;return x=z,T=Error(t(419)),x=Ry(T,x,void 0),Yh(l,u,O,x)}if(z=(O&l.childLanes)!==0,br||z){if(x=yn,x!==null){switch(O&-O){case 4:I=2;break;case 16:I=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:I=32;break;case 536870912:I=268435456;break;default:I=0}I=I&(x.suspendedLanes|O)?0:I,I!==0&&I!==T.retryLane&&(T.retryLane=I,Jo(l,I),Us(x,l,I,-1))}return tS(),x=Ry(Error(t(421))),Yh(l,u,O,x)}return I.data==="$?"?(u.flags|=128,u.child=l.child,u=z$.bind(null,l),I._reactRetry=u,null):(l=T.treeContext,Gr=Fi(I.nextSibling),Wr=u,Bt=!0,Ns=null,l!==null&&(ps[fs++]=Zo,ps[fs++]=Qo,ps[fs++]=za,Zo=l.id,Qo=l.overflow,za=u),u=$y(u,x.children),u.flags|=4096,u)}function t_(l,u,m){l.lanes|=u;var x=l.alternate;x!==null&&(x.lanes|=u),my(l.return,u,m)}function zy(l,u,m,x,I){var T=l.memoizedState;T===null?l.memoizedState={isBackwards:u,rendering:null,renderingStartTime:0,last:x,tail:m,tailMode:I}:(T.isBackwards=u,T.rendering=null,T.renderingStartTime=0,T.last=x,T.tail=m,T.tailMode=I)}function n_(l,u,m){var x=u.pendingProps,I=x.revealOrder,T=x.tail;if(er(l,u,x.children,m),x=Wt.current,x&2)x=x&1|2,u.flags|=128;else{if(l!==null&&l.flags&128)e:for(l=u.child;l!==null;){if(l.tag===13)l.memoizedState!==null&&t_(l,m,u);else if(l.tag===19)t_(l,m,u);else if(l.child!==null){l.child.return=l,l=l.child;continue}if(l===u)break e;for(;l.sibling===null;){if(l.return===null||l.return===u)break e;l=l.return}l.sibling.return=l.return,l=l.sibling}x&=1}if(At(Wt,x),!(u.mode&1))u.memoizedState=null;else switch(I){case"forwards":for(m=u.child,I=null;m!==null;)l=m.alternate,l!==null&&Uh(l)===null&&(I=m),m=m.sibling;m=I,m===null?(I=u.child,u.child=null):(I=m.sibling,m.sibling=null),zy(u,!1,I,m,T);break;case"backwards":for(m=null,I=u.child,u.child=null;I!==null;){if(l=I.alternate,l!==null&&Uh(l)===null){u.child=I;break}l=I.sibling,I.sibling=m,m=I,I=l}zy(u,!0,m,null,T);break;case"together":zy(u,!1,null,null,void 0);break;default:u.memoizedState=null}return u.child}function Xh(l,u){!(u.mode&1)&&l!==null&&(l.alternate=null,u.alternate=null,u.flags|=2)}function ti(l,u,m){if(l!==null&&(u.dependencies=l.dependencies),Wa|=u.lanes,!(m&u.childLanes))return null;if(l!==null&&u.child!==l.child)throw Error(t(153));if(u.child!==null){for(l=u.child,m=qi(l,l.pendingProps),u.child=m,m.return=u;l.sibling!==null;)l=l.sibling,m=m.sibling=qi(l,l.pendingProps),m.return=u;m.sibling=null}return u.child}function T$(l,u,m){switch(u.tag){case 3:QC(u),ql();break;case 5:mC(u);break;case 1:wr(u.type)&&jh(u);break;case 4:vy(u,u.stateNode.containerInfo);break;case 10:var x=u.type._context,I=u.memoizedProps.value;At(Nh,x._currentValue),x._currentValue=I;break;case 13:if(x=u.memoizedState,x!==null)return x.dehydrated!==null?(At(Wt,Wt.current&1),u.flags|=128,null):m&u.child.childLanes?e_(l,u,m):(At(Wt,Wt.current&1),l=ti(l,u,m),l!==null?l.sibling:null);At(Wt,Wt.current&1);break;case 19:if(x=(m&u.childLanes)!==0,l.flags&128){if(x)return n_(l,u,m);u.flags|=128}if(I=u.memoizedState,I!==null&&(I.rendering=null,I.tail=null,I.lastEffect=null),At(Wt,Wt.current),x)break;return null;case 22:case 23:return u.lanes=0,YC(l,u,m)}return ti(l,u,m)}var r_,By,s_,o_;r_=function(l,u){for(var m=u.child;m!==null;){if(m.tag===5||m.tag===6)l.appendChild(m.stateNode);else if(m.tag!==4&&m.child!==null){m.child.return=m,m=m.child;continue}if(m===u)break;for(;m.sibling===null;){if(m.return===null||m.return===u)return;m=m.return}m.sibling.return=m.return,m=m.sibling}},By=function(){},s_=function(l,u,m,x){var I=l.memoizedProps;if(I!==x){l=u.stateNode,Ha(fo.current);var T=null;switch(m){case"input":I=zt(l,I),x=zt(l,x),T=[];break;case"select":I=ae({},I,{value:void 0}),x=ae({},x,{value:void 0}),T=[];break;case"textarea":I=Ta(l,I),x=Ta(l,x),T=[];break;default:typeof I.onClick!="function"&&typeof x.onClick=="function"&&(l.onclick=kh)}Wo(m,x);var O;m=null;for(oe in I)if(!x.hasOwnProperty(oe)&&I.hasOwnProperty(oe)&&I[oe]!=null)if(oe==="style"){var z=I[oe];for(O in z)z.hasOwnProperty(O)&&(m||(m={}),m[O]="")}else oe!=="dangerouslySetInnerHTML"&&oe!=="children"&&oe!=="suppressContentEditableWarning"&&oe!=="suppressHydrationWarning"&&oe!=="autoFocus"&&(s.hasOwnProperty(oe)?T||(T=[]):(T=T||[]).push(oe,null));for(oe in x){var G=x[oe];if(z=I!=null?I[oe]:void 0,x.hasOwnProperty(oe)&&G!==z&&(G!=null||z!=null))if(oe==="style")if(z){for(O in z)!z.hasOwnProperty(O)||G&&G.hasOwnProperty(O)||(m||(m={}),m[O]="");for(O in G)G.hasOwnProperty(O)&&z[O]!==G[O]&&(m||(m={}),m[O]=G[O])}else m||(T||(T=[]),T.push(oe,m)),m=G;else oe==="dangerouslySetInnerHTML"?(G=G?G.__html:void 0,z=z?z.__html:void 0,G!=null&&z!==G&&(T=T||[]).push(oe,G)):oe==="children"?typeof G!="string"&&typeof G!="number"||(T=T||[]).push(oe,""+G):oe!=="suppressContentEditableWarning"&&oe!=="suppressHydrationWarning"&&(s.hasOwnProperty(oe)?(G!=null&&oe==="onScroll"&&Dt("scroll",l),T||z===G||(T=[])):(T=T||[]).push(oe,G))}m&&(T=T||[]).push("style",m);var oe=T;(u.updateQueue=oe)&&(u.flags|=4)}},o_=function(l,u,m,x){m!==x&&(u.flags|=4)};function Mu(l,u){if(!Bt)switch(l.tailMode){case"hidden":u=l.tail;for(var m=null;u!==null;)u.alternate!==null&&(m=u),u=u.sibling;m===null?l.tail=null:m.sibling=null;break;case"collapsed":m=l.tail;for(var x=null;m!==null;)m.alternate!==null&&(x=m),m=m.sibling;x===null?u||l.tail===null?l.tail=null:l.tail.sibling=null:x.sibling=null}}function $n(l){var u=l.alternate!==null&&l.alternate.child===l.child,m=0,x=0;if(u)for(var I=l.child;I!==null;)m|=I.lanes|I.childLanes,x|=I.subtreeFlags&14680064,x|=I.flags&14680064,I.return=l,I=I.sibling;else for(I=l.child;I!==null;)m|=I.lanes|I.childLanes,x|=I.subtreeFlags,x|=I.flags,I.return=l,I=I.sibling;return l.subtreeFlags|=x,l.childLanes=m,u}function k$(l,u,m){var x=u.pendingProps;switch(cy(u),u.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return $n(u),null;case 1:return wr(u.type)&&Ah(),$n(u),null;case 3:return x=u.stateNode,Ql(),Lt(xr),Lt(Fn),by(),x.pendingContext&&(x.context=x.pendingContext,x.pendingContext=null),(l===null||l.child===null)&&(Lh(u)?u.flags|=4:l===null||l.memoizedState.isDehydrated&&!(u.flags&256)||(u.flags|=1024,Ns!==null&&(Qy(Ns),Ns=null))),By(l,u),$n(u),null;case 5:xy(u);var I=Ha(_u.current);if(m=u.type,l!==null&&u.stateNode!=null)s_(l,u,m,x,I),l.ref!==u.ref&&(u.flags|=512,u.flags|=2097152);else{if(!x){if(u.stateNode===null)throw Error(t(166));return $n(u),null}if(l=Ha(fo.current),Lh(u)){x=u.stateNode,m=u.type;var T=u.memoizedProps;switch(x[po]=u,x[xu]=T,l=(u.mode&1)!==0,m){case"dialog":Dt("cancel",x),Dt("close",x);break;case"iframe":case"object":case"embed":Dt("load",x);break;case"video":case"audio":for(I=0;I<yu.length;I++)Dt(yu[I],x);break;case"source":Dt("error",x);break;case"img":case"image":case"link":Dt("error",x),Dt("load",x);break;case"details":Dt("toggle",x);break;case"input":_t(x,T),Dt("invalid",x);break;case"select":x._wrapperState={wasMultiple:!!T.multiple},Dt("invalid",x);break;case"textarea":bl(x,T),Dt("invalid",x)}Wo(m,T),I=null;for(var O in T)if(T.hasOwnProperty(O)){var z=T[O];O==="children"?typeof z=="string"?x.textContent!==z&&(T.suppressHydrationWarning!==!0&&Th(x.textContent,z,l),I=["children",z]):typeof z=="number"&&x.textContent!==""+z&&(T.suppressHydrationWarning!==!0&&Th(x.textContent,z,l),I=["children",""+z]):s.hasOwnProperty(O)&&z!=null&&O==="onScroll"&&Dt("scroll",x)}switch(m){case"input":Ze(x),pr(x,T,!0);break;case"textarea":Ze(x),Cl(x);break;case"select":case"option":break;default:typeof T.onClick=="function"&&(x.onclick=kh)}x=I,u.updateQueue=x,x!==null&&(u.flags|=4)}else{O=I.nodeType===9?I:I.ownerDocument,l==="http://www.w3.org/1999/xhtml"&&(l=_l(m)),l==="http://www.w3.org/1999/xhtml"?m==="script"?(l=O.createElement("div"),l.innerHTML="<script><\/script>",l=l.removeChild(l.firstChild)):typeof x.is=="string"?l=O.createElement(m,{is:x.is}):(l=O.createElement(m),m==="select"&&(O=l,x.multiple?O.multiple=!0:x.size&&(O.size=x.size))):l=O.createElementNS(l,m),l[po]=u,l[xu]=x,r_(l,u,!1,!1),u.stateNode=l;e:{switch(O=Br(m,x),m){case"dialog":Dt("cancel",l),Dt("close",l),I=x;break;case"iframe":case"object":case"embed":Dt("load",l),I=x;break;case"video":case"audio":for(I=0;I<yu.length;I++)Dt(yu[I],l);I=x;break;case"source":Dt("error",l),I=x;break;case"img":case"image":case"link":Dt("error",l),Dt("load",l),I=x;break;case"details":Dt("toggle",l),I=x;break;case"input":_t(l,x),I=zt(l,x),Dt("invalid",l);break;case"option":I=x;break;case"select":l._wrapperState={wasMultiple:!!x.multiple},I=ae({},x,{value:void 0}),Dt("invalid",l);break;case"textarea":bl(l,x),I=Ta(l,x),Dt("invalid",l);break;default:I=x}Wo(m,I),z=I;for(T in z)if(z.hasOwnProperty(T)){var G=z[T];T==="style"?cs(l,G):T==="dangerouslySetInnerHTML"?(G=G?G.__html:void 0,G!=null&&ka(l,G)):T==="children"?typeof G=="string"?(m!=="textarea"||G!=="")&&ie(l,G):typeof G=="number"&&ie(l,""+G):T!=="suppressContentEditableWarning"&&T!=="suppressHydrationWarning"&&T!=="autoFocus"&&(s.hasOwnProperty(T)?G!=null&&T==="onScroll"&&Dt("scroll",l):G!=null&&k(l,T,G,O))}switch(m){case"input":Ze(l),pr(l,x,!1);break;case"textarea":Ze(l),Cl(l);break;case"option":x.value!=null&&l.setAttribute("value",""+xe(x.value));break;case"select":l.multiple=!!x.multiple,T=x.value,T!=null?ls(l,!!x.multiple,T,!1):x.defaultValue!=null&&ls(l,!!x.multiple,x.defaultValue,!0);break;default:typeof I.onClick=="function"&&(l.onclick=kh)}switch(m){case"button":case"input":case"select":case"textarea":x=!!x.autoFocus;break e;case"img":x=!0;break e;default:x=!1}}x&&(u.flags|=4)}u.ref!==null&&(u.flags|=512,u.flags|=2097152)}return $n(u),null;case 6:if(l&&u.stateNode!=null)o_(l,u,l.memoizedProps,x);else{if(typeof x!="string"&&u.stateNode===null)throw Error(t(166));if(m=Ha(_u.current),Ha(fo.current),Lh(u)){if(x=u.stateNode,m=u.memoizedProps,x[po]=u,(T=x.nodeValue!==m)&&(l=Wr,l!==null))switch(l.tag){case 3:Th(x.nodeValue,m,(l.mode&1)!==0);break;case 5:l.memoizedProps.suppressHydrationWarning!==!0&&Th(x.nodeValue,m,(l.mode&1)!==0)}T&&(u.flags|=4)}else x=(m.nodeType===9?m:m.ownerDocument).createTextNode(x),x[po]=u,u.stateNode=x}return $n(u),null;case 13:if(Lt(Wt),x=u.memoizedState,l===null||l.memoizedState!==null&&l.memoizedState.dehydrated!==null){if(Bt&&Gr!==null&&u.mode&1&&!(u.flags&128))lC(),ql(),u.flags|=98560,T=!1;else if(T=Lh(u),x!==null&&x.dehydrated!==null){if(l===null){if(!T)throw Error(t(318));if(T=u.memoizedState,T=T!==null?T.dehydrated:null,!T)throw Error(t(317));T[po]=u}else ql(),!(u.flags&128)&&(u.memoizedState=null),u.flags|=4;$n(u),T=!1}else Ns!==null&&(Qy(Ns),Ns=null),T=!0;if(!T)return u.flags&65536?u:null}return u.flags&128?(u.lanes=m,u):(x=x!==null,x!==(l!==null&&l.memoizedState!==null)&&x&&(u.child.flags|=8192,u.mode&1&&(l===null||Wt.current&1?pn===0&&(pn=3):tS())),u.updateQueue!==null&&(u.flags|=4),$n(u),null);case 4:return Ql(),By(l,u),l===null&&Su(u.stateNode.containerInfo),$n(u),null;case 10:return gy(u.type._context),$n(u),null;case 17:return wr(u.type)&&Ah(),$n(u),null;case 19:if(Lt(Wt),T=u.memoizedState,T===null)return $n(u),null;if(x=(u.flags&128)!==0,O=T.rendering,O===null)if(x)Mu(T,!1);else{if(pn!==0||l!==null&&l.flags&128)for(l=u.child;l!==null;){if(O=Uh(l),O!==null){for(u.flags|=128,Mu(T,!1),x=O.updateQueue,x!==null&&(u.updateQueue=x,u.flags|=4),u.subtreeFlags=0,x=m,m=u.child;m!==null;)T=m,l=x,T.flags&=14680066,O=T.alternate,O===null?(T.childLanes=0,T.lanes=l,T.child=null,T.subtreeFlags=0,T.memoizedProps=null,T.memoizedState=null,T.updateQueue=null,T.dependencies=null,T.stateNode=null):(T.childLanes=O.childLanes,T.lanes=O.lanes,T.child=O.child,T.subtreeFlags=0,T.deletions=null,T.memoizedProps=O.memoizedProps,T.memoizedState=O.memoizedState,T.updateQueue=O.updateQueue,T.type=O.type,l=O.dependencies,T.dependencies=l===null?null:{lanes:l.lanes,firstContext:l.firstContext}),m=m.sibling;return At(Wt,Wt.current&1|2),u.child}l=l.sibling}T.tail!==null&&Kt()>nc&&(u.flags|=128,x=!0,Mu(T,!1),u.lanes=4194304)}else{if(!x)if(l=Uh(O),l!==null){if(u.flags|=128,x=!0,m=l.updateQueue,m!==null&&(u.updateQueue=m,u.flags|=4),Mu(T,!0),T.tail===null&&T.tailMode==="hidden"&&!O.alternate&&!Bt)return $n(u),null}else 2*Kt()-T.renderingStartTime>nc&&m!==1073741824&&(u.flags|=128,x=!0,Mu(T,!1),u.lanes=4194304);T.isBackwards?(O.sibling=u.child,u.child=O):(m=T.last,m!==null?m.sibling=O:u.child=O,T.last=O)}return T.tail!==null?(u=T.tail,T.rendering=u,T.tail=u.sibling,T.renderingStartTime=Kt(),u.sibling=null,m=Wt.current,At(Wt,x?m&1|2:m&1),u):($n(u),null);case 22:case 23:return eS(),x=u.memoizedState!==null,l!==null&&l.memoizedState!==null!==x&&(u.flags|=8192),x&&u.mode&1?Vr&1073741824&&($n(u),u.subtreeFlags&6&&(u.flags|=8192)):$n(u),null;case 24:return null;case 25:return null}throw Error(t(156,u.tag))}function M$(l,u){switch(cy(u),u.tag){case 1:return wr(u.type)&&Ah(),l=u.flags,l&65536?(u.flags=l&-65537|128,u):null;case 3:return Ql(),Lt(xr),Lt(Fn),by(),l=u.flags,l&65536&&!(l&128)?(u.flags=l&-65537|128,u):null;case 5:return xy(u),null;case 13:if(Lt(Wt),l=u.memoizedState,l!==null&&l.dehydrated!==null){if(u.alternate===null)throw Error(t(340));ql()}return l=u.flags,l&65536?(u.flags=l&-65537|128,u):null;case 19:return Lt(Wt),null;case 4:return Ql(),null;case 10:return gy(u.type._context),null;case 22:case 23:return eS(),null;case 24:return null;default:return null}}var Zh=!1,zn=!1,A$=typeof WeakSet=="function"?WeakSet:Set,ke=null;function ec(l,u){var m=l.ref;if(m!==null)if(typeof m=="function")try{m(null)}catch(x){Qt(l,u,x)}else m.current=null}function Uy(l,u,m){try{m()}catch(x){Qt(l,u,x)}}var i_=!1;function j$(l,u){if(ey=X,l=NP(),Gm(l)){if("selectionStart"in l)var m={start:l.selectionStart,end:l.selectionEnd};else e:{m=(m=l.ownerDocument)&&m.defaultView||window;var x=m.getSelection&&m.getSelection();if(x&&x.rangeCount!==0){m=x.anchorNode;var I=x.anchorOffset,T=x.focusNode;x=x.focusOffset;try{m.nodeType,T.nodeType}catch{m=null;break e}var O=0,z=-1,G=-1,oe=0,fe=0,ge=l,pe=null;t:for(;;){for(var Ee;ge!==m||I!==0&&ge.nodeType!==3||(z=O+I),ge!==T||x!==0&&ge.nodeType!==3||(G=O+x),ge.nodeType===3&&(O+=ge.nodeValue.length),(Ee=ge.firstChild)!==null;)pe=ge,ge=Ee;for(;;){if(ge===l)break t;if(pe===m&&++oe===I&&(z=O),pe===T&&++fe===x&&(G=O),(Ee=ge.nextSibling)!==null)break;ge=pe,pe=ge.parentNode}ge=Ee}m=z===-1||G===-1?null:{start:z,end:G}}else m=null}m=m||{start:0,end:0}}else m=null;for(ty={focusedElem:l,selectionRange:m},X=!1,ke=u;ke!==null;)if(u=ke,l=u.child,(u.subtreeFlags&1028)!==0&&l!==null)l.return=u,ke=l;else for(;ke!==null;){u=ke;try{var je=u.alternate;if(u.flags&1024)switch(u.tag){case 0:case 11:case 15:break;case 1:if(je!==null){var Oe=je.memoizedProps,nn=je.memoizedState,J=u.stateNode,q=J.getSnapshotBeforeUpdate(u.elementType===u.type?Oe:$s(u.type,Oe),nn);J.__reactInternalSnapshotBeforeUpdate=q}break;case 3:var re=u.stateNode.containerInfo;re.nodeType===1?re.textContent="":re.nodeType===9&&re.documentElement&&re.removeChild(re.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(t(163))}}catch(ye){Qt(u,u.return,ye)}if(l=u.sibling,l!==null){l.return=u.return,ke=l;break}ke=u.return}return je=i_,i_=!1,je}function Au(l,u,m){var x=u.updateQueue;if(x=x!==null?x.lastEffect:null,x!==null){var I=x=x.next;do{if((I.tag&l)===l){var T=I.destroy;I.destroy=void 0,T!==void 0&&Uy(u,m,T)}I=I.next}while(I!==x)}}function Qh(l,u){if(u=u.updateQueue,u=u!==null?u.lastEffect:null,u!==null){var m=u=u.next;do{if((m.tag&l)===l){var x=m.create;m.destroy=x()}m=m.next}while(m!==u)}}function Hy(l){var u=l.ref;if(u!==null){var m=l.stateNode;switch(l.tag){case 5:l=m;break;default:l=m}typeof u=="function"?u(l):u.current=l}}function a_(l){var u=l.alternate;u!==null&&(l.alternate=null,a_(u)),l.child=null,l.deletions=null,l.sibling=null,l.tag===5&&(u=l.stateNode,u!==null&&(delete u[po],delete u[xu],delete u[oy],delete u[f$],delete u[g$])),l.stateNode=null,l.return=null,l.dependencies=null,l.memoizedProps=null,l.memoizedState=null,l.pendingProps=null,l.stateNode=null,l.updateQueue=null}function l_(l){return l.tag===5||l.tag===3||l.tag===4}function c_(l){e:for(;;){for(;l.sibling===null;){if(l.return===null||l_(l.return))return null;l=l.return}for(l.sibling.return=l.return,l=l.sibling;l.tag!==5&&l.tag!==6&&l.tag!==18;){if(l.flags&2||l.child===null||l.tag===4)continue e;l.child.return=l,l=l.child}if(!(l.flags&2))return l.stateNode}}function Ky(l,u,m){var x=l.tag;if(x===5||x===6)l=l.stateNode,u?m.nodeType===8?m.parentNode.insertBefore(l,u):m.insertBefore(l,u):(m.nodeType===8?(u=m.parentNode,u.insertBefore(l,m)):(u=m,u.appendChild(l)),m=m._reactRootContainer,m!=null||u.onclick!==null||(u.onclick=kh));else if(x!==4&&(l=l.child,l!==null))for(Ky(l,u,m),l=l.sibling;l!==null;)Ky(l,u,m),l=l.sibling}function Wy(l,u,m){var x=l.tag;if(x===5||x===6)l=l.stateNode,u?m.insertBefore(l,u):m.appendChild(l);else if(x!==4&&(l=l.child,l!==null))for(Wy(l,u,m),l=l.sibling;l!==null;)Wy(l,u,m),l=l.sibling}var bn=null,zs=!1;function Hi(l,u,m){for(m=m.child;m!==null;)u_(l,u,m),m=m.sibling}function u_(l,u,m){if(hs&&typeof hs.onCommitFiberUnmount=="function")try{hs.onCommitFiberUnmount(Al,m)}catch{}switch(m.tag){case 5:zn||ec(m,u);case 6:var x=bn,I=zs;bn=null,Hi(l,u,m),bn=x,zs=I,bn!==null&&(zs?(l=bn,m=m.stateNode,l.nodeType===8?l.parentNode.removeChild(m):l.removeChild(m)):bn.removeChild(m.stateNode));break;case 18:bn!==null&&(zs?(l=bn,m=m.stateNode,l.nodeType===8?sy(l.parentNode,m):l.nodeType===1&&sy(l,m),Fa(l)):sy(bn,m.stateNode));break;case 4:x=bn,I=zs,bn=m.stateNode.containerInfo,zs=!0,Hi(l,u,m),bn=x,zs=I;break;case 0:case 11:case 14:case 15:if(!zn&&(x=m.updateQueue,x!==null&&(x=x.lastEffect,x!==null))){I=x=x.next;do{var T=I,O=T.destroy;T=T.tag,O!==void 0&&(T&2||T&4)&&Uy(m,u,O),I=I.next}while(I!==x)}Hi(l,u,m);break;case 1:if(!zn&&(ec(m,u),x=m.stateNode,typeof x.componentWillUnmount=="function"))try{x.props=m.memoizedProps,x.state=m.memoizedState,x.componentWillUnmount()}catch(z){Qt(m,u,z)}Hi(l,u,m);break;case 21:Hi(l,u,m);break;case 22:m.mode&1?(zn=(x=zn)||m.memoizedState!==null,Hi(l,u,m),zn=x):Hi(l,u,m);break;default:Hi(l,u,m)}}function d_(l){var u=l.updateQueue;if(u!==null){l.updateQueue=null;var m=l.stateNode;m===null&&(m=l.stateNode=new A$),u.forEach(function(x){var I=B$.bind(null,l,x);m.has(x)||(m.add(x),x.then(I,I))})}}function Bs(l,u){var m=u.deletions;if(m!==null)for(var x=0;x<m.length;x++){var I=m[x];try{var T=l,O=u,z=O;e:for(;z!==null;){switch(z.tag){case 5:bn=z.stateNode,zs=!1;break e;case 3:bn=z.stateNode.containerInfo,zs=!0;break e;case 4:bn=z.stateNode.containerInfo,zs=!0;break e}z=z.return}if(bn===null)throw Error(t(160));u_(T,O,I),bn=null,zs=!1;var G=I.alternate;G!==null&&(G.return=null),I.return=null}catch(oe){Qt(I,u,oe)}}if(u.subtreeFlags&12854)for(u=u.child;u!==null;)h_(u,l),u=u.sibling}function h_(l,u){var m=l.alternate,x=l.flags;switch(l.tag){case 0:case 11:case 14:case 15:if(Bs(u,l),mo(l),x&4){try{Au(3,l,l.return),Qh(3,l)}catch(Oe){Qt(l,l.return,Oe)}try{Au(5,l,l.return)}catch(Oe){Qt(l,l.return,Oe)}}break;case 1:Bs(u,l),mo(l),x&512&&m!==null&&ec(m,m.return);break;case 5:if(Bs(u,l),mo(l),x&512&&m!==null&&ec(m,m.return),l.flags&32){var I=l.stateNode;try{ie(I,"")}catch(Oe){Qt(l,l.return,Oe)}}if(x&4&&(I=l.stateNode,I!=null)){var T=l.memoizedProps,O=m!==null?m.memoizedProps:T,z=l.type,G=l.updateQueue;if(l.updateQueue=null,G!==null)try{z==="input"&&T.type==="radio"&&T.name!=null&&wt(I,T),Br(z,O);var oe=Br(z,T);for(O=0;O<G.length;O+=2){var fe=G[O],ge=G[O+1];fe==="style"?cs(I,ge):fe==="dangerouslySetInnerHTML"?ka(I,ge):fe==="children"?ie(I,ge):k(I,fe,ge,oe)}switch(z){case"input":hr(I,T);break;case"textarea":Pl(I,T);break;case"select":var pe=I._wrapperState.wasMultiple;I._wrapperState.wasMultiple=!!T.multiple;var Ee=T.value;Ee!=null?ls(I,!!T.multiple,Ee,!1):pe!==!!T.multiple&&(T.defaultValue!=null?ls(I,!!T.multiple,T.defaultValue,!0):ls(I,!!T.multiple,T.multiple?[]:"",!1))}I[xu]=T}catch(Oe){Qt(l,l.return,Oe)}}break;case 6:if(Bs(u,l),mo(l),x&4){if(l.stateNode===null)throw Error(t(162));I=l.stateNode,T=l.memoizedProps;try{I.nodeValue=T}catch(Oe){Qt(l,l.return,Oe)}}break;case 3:if(Bs(u,l),mo(l),x&4&&m!==null&&m.memoizedState.isDehydrated)try{Fa(u.containerInfo)}catch(Oe){Qt(l,l.return,Oe)}break;case 4:Bs(u,l),mo(l);break;case 13:Bs(u,l),mo(l),I=l.child,I.flags&8192&&(T=I.memoizedState!==null,I.stateNode.isHidden=T,!T||I.alternate!==null&&I.alternate.memoizedState!==null||(qy=Kt())),x&4&&d_(l);break;case 22:if(fe=m!==null&&m.memoizedState!==null,l.mode&1?(zn=(oe=zn)||fe,Bs(u,l),zn=oe):Bs(u,l),mo(l),x&8192){if(oe=l.memoizedState!==null,(l.stateNode.isHidden=oe)&&!fe&&l.mode&1)for(ke=l,fe=l.child;fe!==null;){for(ge=ke=fe;ke!==null;){switch(pe=ke,Ee=pe.child,pe.tag){case 0:case 11:case 14:case 15:Au(4,pe,pe.return);break;case 1:ec(pe,pe.return);var je=pe.stateNode;if(typeof je.componentWillUnmount=="function"){x=pe,m=pe.return;try{u=x,je.props=u.memoizedProps,je.state=u.memoizedState,je.componentWillUnmount()}catch(Oe){Qt(x,m,Oe)}}break;case 5:ec(pe,pe.return);break;case 22:if(pe.memoizedState!==null){g_(ge);continue}}Ee!==null?(Ee.return=pe,ke=Ee):g_(ge)}fe=fe.sibling}e:for(fe=null,ge=l;;){if(ge.tag===5){if(fe===null){fe=ge;try{I=ge.stateNode,oe?(T=I.style,typeof T.setProperty=="function"?T.setProperty("display","none","important"):T.display="none"):(z=ge.stateNode,G=ge.memoizedProps.style,O=G!=null&&G.hasOwnProperty("display")?G.display:null,z.style.display=bt("display",O))}catch(Oe){Qt(l,l.return,Oe)}}}else if(ge.tag===6){if(fe===null)try{ge.stateNode.nodeValue=oe?"":ge.memoizedProps}catch(Oe){Qt(l,l.return,Oe)}}else if((ge.tag!==22&&ge.tag!==23||ge.memoizedState===null||ge===l)&&ge.child!==null){ge.child.return=ge,ge=ge.child;continue}if(ge===l)break e;for(;ge.sibling===null;){if(ge.return===null||ge.return===l)break e;fe===ge&&(fe=null),ge=ge.return}fe===ge&&(fe=null),ge.sibling.return=ge.return,ge=ge.sibling}}break;case 19:Bs(u,l),mo(l),x&4&&d_(l);break;case 21:break;default:Bs(u,l),mo(l)}}function mo(l){var u=l.flags;if(u&2){try{e:{for(var m=l.return;m!==null;){if(l_(m)){var x=m;break e}m=m.return}throw Error(t(160))}switch(x.tag){case 5:var I=x.stateNode;x.flags&32&&(ie(I,""),x.flags&=-33);var T=c_(l);Wy(l,T,I);break;case 3:case 4:var O=x.stateNode.containerInfo,z=c_(l);Ky(l,z,O);break;default:throw Error(t(161))}}catch(G){Qt(l,l.return,G)}l.flags&=-3}u&4096&&(l.flags&=-4097)}function R$(l,u,m){ke=l,p_(l)}function p_(l,u,m){for(var x=(l.mode&1)!==0;ke!==null;){var I=ke,T=I.child;if(I.tag===22&&x){var O=I.memoizedState!==null||Zh;if(!O){var z=I.alternate,G=z!==null&&z.memoizedState!==null||zn;z=Zh;var oe=zn;if(Zh=O,(zn=G)&&!oe)for(ke=I;ke!==null;)O=ke,G=O.child,O.tag===22&&O.memoizedState!==null?m_(I):G!==null?(G.return=O,ke=G):m_(I);for(;T!==null;)ke=T,p_(T),T=T.sibling;ke=I,Zh=z,zn=oe}f_(l)}else I.subtreeFlags&8772&&T!==null?(T.return=I,ke=T):f_(l)}}function f_(l){for(;ke!==null;){var u=ke;if(u.flags&8772){var m=u.alternate;try{if(u.flags&8772)switch(u.tag){case 0:case 11:case 15:zn||Qh(5,u);break;case 1:var x=u.stateNode;if(u.flags&4&&!zn)if(m===null)x.componentDidMount();else{var I=u.elementType===u.type?m.memoizedProps:$s(u.type,m.memoizedProps);x.componentDidUpdate(I,m.memoizedState,x.__reactInternalSnapshotBeforeUpdate)}var T=u.updateQueue;T!==null&&gC(u,T,x);break;case 3:var O=u.updateQueue;if(O!==null){if(m=null,u.child!==null)switch(u.child.tag){case 5:m=u.child.stateNode;break;case 1:m=u.child.stateNode}gC(u,O,m)}break;case 5:var z=u.stateNode;if(m===null&&u.flags&4){m=z;var G=u.memoizedProps;switch(u.type){case"button":case"input":case"select":case"textarea":G.autoFocus&&m.focus();break;case"img":G.src&&(m.src=G.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(u.memoizedState===null){var oe=u.alternate;if(oe!==null){var fe=oe.memoizedState;if(fe!==null){var ge=fe.dehydrated;ge!==null&&Fa(ge)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(t(163))}zn||u.flags&512&&Hy(u)}catch(pe){Qt(u,u.return,pe)}}if(u===l){ke=null;break}if(m=u.sibling,m!==null){m.return=u.return,ke=m;break}ke=u.return}}function g_(l){for(;ke!==null;){var u=ke;if(u===l){ke=null;break}var m=u.sibling;if(m!==null){m.return=u.return,ke=m;break}ke=u.return}}function m_(l){for(;ke!==null;){var u=ke;try{switch(u.tag){case 0:case 11:case 15:var m=u.return;try{Qh(4,u)}catch(G){Qt(u,m,G)}break;case 1:var x=u.stateNode;if(typeof x.componentDidMount=="function"){var I=u.return;try{x.componentDidMount()}catch(G){Qt(u,I,G)}}var T=u.return;try{Hy(u)}catch(G){Qt(u,T,G)}break;case 5:var O=u.return;try{Hy(u)}catch(G){Qt(u,O,G)}}}catch(G){Qt(u,u.return,G)}if(u===l){ke=null;break}var z=u.sibling;if(z!==null){z.return=u.return,ke=z;break}ke=u.return}}var O$=Math.ceil,Jh=E.ReactCurrentDispatcher,Gy=E.ReactCurrentOwner,ys=E.ReactCurrentBatchConfig,dt=0,yn=null,cn=null,Pn=0,Vr=0,tc=Ni(0),pn=0,ju=null,Wa=0,ep=0,Vy=0,Ru=null,Pr=null,qy=0,nc=1/0,ni=null,tp=!1,Yy=null,Ki=null,np=!1,Wi=null,rp=0,Ou=0,Xy=null,sp=-1,op=0;function tr(){return dt&6?Kt():sp!==-1?sp:sp=Kt()}function Gi(l){return l.mode&1?dt&2&&Pn!==0?Pn&-Pn:y$.transition!==null?(op===0&&(op=mh()),op):(l=ct,l!==0||(l=window.event,l=l===void 0?16:en(l.type)),l):1}function Us(l,u,m,x){if(50<Ou)throw Ou=0,Xy=null,Error(t(185));Oa(l,m,x),(!(dt&2)||l!==yn)&&(l===yn&&(!(dt&2)&&(ep|=m),pn===4&&Vi(l,Pn)),Cr(l,x),m===1&&dt===0&&!(u.mode&1)&&(nc=Kt()+500,Rh&&zi()))}function Cr(l,u){var m=l.callbackNode;Fm(l,u);var x=Ra(l,l===yn?Pn:0);if(x===0)m!==null&&io(m),l.callbackNode=null,l.callbackPriority=0;else if(u=x&-x,l.callbackPriority!==u){if(m!=null&&io(m),u===1)l.tag===0?m$(S_.bind(null,l)):rC(S_.bind(null,l)),h$(function(){!(dt&6)&&zi()}),m=null;else{switch(qo(x)){case 1:m=su;break;case 4:m=ja;break;case 16:m=Ml;break;case 536870912:m=Rs;break;default:m=Ml}m=I_(m,y_.bind(null,l))}l.callbackPriority=u,l.callbackNode=m}}function y_(l,u){if(sp=-1,op=0,dt&6)throw Error(t(327));var m=l.callbackNode;if(rc()&&l.callbackNode!==m)return null;var x=Ra(l,l===yn?Pn:0);if(x===0)return null;if(x&30||x&l.expiredLanes||u)u=ip(l,x);else{u=x;var I=dt;dt|=2;var T=x_();(yn!==l||Pn!==u)&&(ni=null,nc=Kt()+500,Va(l,u));do try{F$();break}catch(z){v_(l,z)}while(!0);fy(),Jh.current=T,dt=I,cn!==null?u=0:(yn=null,Pn=0,u=pn)}if(u!==0){if(u===2&&(I=ou(l),I!==0&&(x=I,u=Zy(l,I))),u===1)throw m=ju,Va(l,0),Vi(l,x),Cr(l,Kt()),m;if(u===6)Vi(l,x);else{if(I=l.current.alternate,!(x&30)&&!D$(I)&&(u=ip(l,x),u===2&&(T=ou(l),T!==0&&(x=T,u=Zy(l,T))),u===1))throw m=ju,Va(l,0),Vi(l,x),Cr(l,Kt()),m;switch(l.finishedWork=I,l.finishedLanes=x,u){case 0:case 1:throw Error(t(345));case 2:qa(l,Pr,ni);break;case 3:if(Vi(l,x),(x&130023424)===x&&(u=qy+500-Kt(),10<u)){if(Ra(l,0)!==0)break;if(I=l.suspendedLanes,(I&x)!==x){tr(),l.pingedLanes|=l.suspendedLanes&I;break}l.timeoutHandle=ry(qa.bind(null,l,Pr,ni),u);break}qa(l,Pr,ni);break;case 4:if(Vi(l,x),(x&4194240)===x)break;for(u=l.eventTimes,I=-1;0<x;){var O=31-Kr(x);T=1<<O,O=u[O],O>I&&(I=O),x&=~T}if(x=I,x=Kt()-x,x=(120>x?120:480>x?480:1080>x?1080:1920>x?1920:3e3>x?3e3:4320>x?4320:1960*O$(x/1960))-x,10<x){l.timeoutHandle=ry(qa.bind(null,l,Pr,ni),x);break}qa(l,Pr,ni);break;case 5:qa(l,Pr,ni);break;default:throw Error(t(329))}}}return Cr(l,Kt()),l.callbackNode===m?y_.bind(null,l):null}function Zy(l,u){var m=Ru;return l.current.memoizedState.isDehydrated&&(Va(l,u).flags|=256),l=ip(l,u),l!==2&&(u=Pr,Pr=m,u!==null&&Qy(u)),l}function Qy(l){Pr===null?Pr=l:Pr.push.apply(Pr,l)}function D$(l){for(var u=l;;){if(u.flags&16384){var m=u.updateQueue;if(m!==null&&(m=m.stores,m!==null))for(var x=0;x<m.length;x++){var I=m[x],T=I.getSnapshot;I=I.value;try{if(!Fs(T(),I))return!1}catch{return!1}}}if(m=u.child,u.subtreeFlags&16384&&m!==null)m.return=u,u=m;else{if(u===l)break;for(;u.sibling===null;){if(u.return===null||u.return===l)return!0;u=u.return}u.sibling.return=u.return,u=u.sibling}}return!0}function Vi(l,u){for(u&=~Vy,u&=~ep,l.suspendedLanes|=u,l.pingedLanes&=~u,l=l.expirationTimes;0<u;){var m=31-Kr(u),x=1<<m;l[m]=-1,u&=~x}}function S_(l){if(dt&6)throw Error(t(327));rc();var u=Ra(l,0);if(!(u&1))return Cr(l,Kt()),null;var m=ip(l,u);if(l.tag!==0&&m===2){var x=ou(l);x!==0&&(u=x,m=Zy(l,x))}if(m===1)throw m=ju,Va(l,0),Vi(l,u),Cr(l,Kt()),m;if(m===6)throw Error(t(345));return l.finishedWork=l.current.alternate,l.finishedLanes=u,qa(l,Pr,ni),Cr(l,Kt()),null}function Jy(l,u){var m=dt;dt|=1;try{return l(u)}finally{dt=m,dt===0&&(nc=Kt()+500,Rh&&zi())}}function Ga(l){Wi!==null&&Wi.tag===0&&!(dt&6)&&rc();var u=dt;dt|=1;var m=ys.transition,x=ct;try{if(ys.transition=null,ct=1,l)return l()}finally{ct=x,ys.transition=m,dt=u,!(dt&6)&&zi()}}function eS(){Vr=tc.current,Lt(tc)}function Va(l,u){l.finishedWork=null,l.finishedLanes=0;var m=l.timeoutHandle;if(m!==-1&&(l.timeoutHandle=-1,d$(m)),cn!==null)for(m=cn.return;m!==null;){var x=m;switch(cy(x),x.tag){case 1:x=x.type.childContextTypes,x!=null&&Ah();break;case 3:Ql(),Lt(xr),Lt(Fn),by();break;case 5:xy(x);break;case 4:Ql();break;case 13:Lt(Wt);break;case 19:Lt(Wt);break;case 10:gy(x.type._context);break;case 22:case 23:eS()}m=m.return}if(yn=l,cn=l=qi(l.current,null),Pn=Vr=u,pn=0,ju=null,Vy=ep=Wa=0,Pr=Ru=null,Ua!==null){for(u=0;u<Ua.length;u++)if(m=Ua[u],x=m.interleaved,x!==null){m.interleaved=null;var I=x.next,T=m.pending;if(T!==null){var O=T.next;T.next=I,x.next=O}m.pending=x}Ua=null}return l}function v_(l,u){do{var m=cn;try{if(fy(),Hh.current=Vh,Kh){for(var x=Gt.memoizedState;x!==null;){var I=x.queue;I!==null&&(I.pending=null),x=x.next}Kh=!1}if(Ka=0,mn=hn=Gt=null,Iu=!1,Eu=0,Gy.current=null,m===null||m.return===null){pn=1,ju=u,cn=null;break}e:{var T=l,O=m.return,z=m,G=u;if(u=Pn,z.flags|=32768,G!==null&&typeof G=="object"&&typeof G.then=="function"){var oe=G,fe=z,ge=fe.tag;if(!(fe.mode&1)&&(ge===0||ge===11||ge===15)){var pe=fe.alternate;pe?(fe.updateQueue=pe.updateQueue,fe.memoizedState=pe.memoizedState,fe.lanes=pe.lanes):(fe.updateQueue=null,fe.memoizedState=null)}var Ee=KC(O);if(Ee!==null){Ee.flags&=-257,WC(Ee,O,z,T,u),Ee.mode&1&&HC(T,oe,u),u=Ee,G=oe;var je=u.updateQueue;if(je===null){var Oe=new Set;Oe.add(G),u.updateQueue=Oe}else je.add(G);break e}else{if(!(u&1)){HC(T,oe,u),tS();break e}G=Error(t(426))}}else if(Bt&&z.mode&1){var nn=KC(O);if(nn!==null){!(nn.flags&65536)&&(nn.flags|=256),WC(nn,O,z,T,u),hy(Jl(G,z));break e}}T=G=Jl(G,z),pn!==4&&(pn=2),Ru===null?Ru=[T]:Ru.push(T),T=O;do{switch(T.tag){case 3:T.flags|=65536,u&=-u,T.lanes|=u;var J=BC(T,G,u);fC(T,J);break e;case 1:z=G;var q=T.type,re=T.stateNode;if(!(T.flags&128)&&(typeof q.getDerivedStateFromError=="function"||re!==null&&typeof re.componentDidCatch=="function"&&(Ki===null||!Ki.has(re)))){T.flags|=65536,u&=-u,T.lanes|=u;var ye=UC(T,z,u);fC(T,ye);break e}}T=T.return}while(T!==null)}b_(m)}catch(De){u=De,cn===m&&m!==null&&(cn=m=m.return);continue}break}while(!0)}function x_(){var l=Jh.current;return Jh.current=Vh,l===null?Vh:l}function tS(){(pn===0||pn===3||pn===2)&&(pn=4),yn===null||!(Wa&268435455)&&!(ep&268435455)||Vi(yn,Pn)}function ip(l,u){var m=dt;dt|=2;var x=x_();(yn!==l||Pn!==u)&&(ni=null,Va(l,u));do try{L$();break}catch(I){v_(l,I)}while(!0);if(fy(),dt=m,Jh.current=x,cn!==null)throw Error(t(261));return yn=null,Pn=0,pn}function L$(){for(;cn!==null;)w_(cn)}function F$(){for(;cn!==null&&!km();)w_(cn)}function w_(l){var u=__(l.alternate,l,Vr);l.memoizedProps=l.pendingProps,u===null?b_(l):cn=u,Gy.current=null}function b_(l){var u=l;do{var m=u.alternate;if(l=u.return,u.flags&32768){if(m=M$(m,u),m!==null){m.flags&=32767,cn=m;return}if(l!==null)l.flags|=32768,l.subtreeFlags=0,l.deletions=null;else{pn=6,cn=null;return}}else if(m=k$(m,u,Vr),m!==null){cn=m;return}if(u=u.sibling,u!==null){cn=u;return}cn=u=l}while(u!==null);pn===0&&(pn=5)}function qa(l,u,m){var x=ct,I=ys.transition;try{ys.transition=null,ct=1,N$(l,u,m,x)}finally{ys.transition=I,ct=x}return null}function N$(l,u,m,x){do rc();while(Wi!==null);if(dt&6)throw Error(t(327));m=l.finishedWork;var I=l.finishedLanes;if(m===null)return null;if(l.finishedWork=null,l.finishedLanes=0,m===l.current)throw Error(t(177));l.callbackNode=null,l.callbackPriority=0;var T=m.lanes|m.childLanes;if(Nm(l,T),l===yn&&(cn=yn=null,Pn=0),!(m.subtreeFlags&2064)&&!(m.flags&2064)||np||(np=!0,I_(Ml,function(){return rc(),null})),T=(m.flags&15990)!==0,m.subtreeFlags&15990||T){T=ys.transition,ys.transition=null;var O=ct;ct=1;var z=dt;dt|=4,Gy.current=null,j$(l,m),h_(m,l),s$(ty),X=!!ey,ty=ey=null,l.current=m,R$(m),Mm(),dt=z,ct=O,ys.transition=T}else l.current=m;if(np&&(np=!1,Wi=l,rp=I),T=l.pendingLanes,T===0&&(Ki=null),Rm(m.stateNode),Cr(l,Kt()),u!==null)for(x=l.onRecoverableError,m=0;m<u.length;m++)I=u[m],x(I.value,{componentStack:I.stack,digest:I.digest});if(tp)throw tp=!1,l=Yy,Yy=null,l;return rp&1&&l.tag!==0&&rc(),T=l.pendingLanes,T&1?l===Xy?Ou++:(Ou=0,Xy=l):Ou=0,zi(),null}function rc(){if(Wi!==null){var l=qo(rp),u=ys.transition,m=ct;try{if(ys.transition=null,ct=16>l?16:l,Wi===null)var x=!1;else{if(l=Wi,Wi=null,rp=0,dt&6)throw Error(t(331));var I=dt;for(dt|=4,ke=l.current;ke!==null;){var T=ke,O=T.child;if(ke.flags&16){var z=T.deletions;if(z!==null){for(var G=0;G<z.length;G++){var oe=z[G];for(ke=oe;ke!==null;){var fe=ke;switch(fe.tag){case 0:case 11:case 15:Au(8,fe,T)}var ge=fe.child;if(ge!==null)ge.return=fe,ke=ge;else for(;ke!==null;){fe=ke;var pe=fe.sibling,Ee=fe.return;if(a_(fe),fe===oe){ke=null;break}if(pe!==null){pe.return=Ee,ke=pe;break}ke=Ee}}}var je=T.alternate;if(je!==null){var Oe=je.child;if(Oe!==null){je.child=null;do{var nn=Oe.sibling;Oe.sibling=null,Oe=nn}while(Oe!==null)}}ke=T}}if(T.subtreeFlags&2064&&O!==null)O.return=T,ke=O;else e:for(;ke!==null;){if(T=ke,T.flags&2048)switch(T.tag){case 0:case 11:case 15:Au(9,T,T.return)}var J=T.sibling;if(J!==null){J.return=T.return,ke=J;break e}ke=T.return}}var q=l.current;for(ke=q;ke!==null;){O=ke;var re=O.child;if(O.subtreeFlags&2064&&re!==null)re.return=O,ke=re;else e:for(O=q;ke!==null;){if(z=ke,z.flags&2048)try{switch(z.tag){case 0:case 11:case 15:Qh(9,z)}}catch(De){Qt(z,z.return,De)}if(z===O){ke=null;break e}var ye=z.sibling;if(ye!==null){ye.return=z.return,ke=ye;break e}ke=z.return}}if(dt=I,zi(),hs&&typeof hs.onPostCommitFiberRoot=="function")try{hs.onPostCommitFiberRoot(Al,l)}catch{}x=!0}return x}finally{ct=m,ys.transition=u}}return!1}function P_(l,u,m){u=Jl(m,u),u=BC(l,u,1),l=Ui(l,u,1),u=tr(),l!==null&&(Oa(l,1,u),Cr(l,u))}function Qt(l,u,m){if(l.tag===3)P_(l,l,m);else for(;u!==null;){if(u.tag===3){P_(u,l,m);break}else if(u.tag===1){var x=u.stateNode;if(typeof u.type.getDerivedStateFromError=="function"||typeof x.componentDidCatch=="function"&&(Ki===null||!Ki.has(x))){l=Jl(m,l),l=UC(u,l,1),u=Ui(u,l,1),l=tr(),u!==null&&(Oa(u,1,l),Cr(u,l));break}}u=u.return}}function $$(l,u,m){var x=l.pingCache;x!==null&&x.delete(u),u=tr(),l.pingedLanes|=l.suspendedLanes&m,yn===l&&(Pn&m)===m&&(pn===4||pn===3&&(Pn&130023424)===Pn&&500>Kt()-qy?Va(l,0):Vy|=m),Cr(l,u)}function C_(l,u){u===0&&(l.mode&1?(u=ao,ao<<=1,!(ao&130023424)&&(ao=4194304)):u=1);var m=tr();l=Jo(l,u),l!==null&&(Oa(l,u,m),Cr(l,m))}function z$(l){var u=l.memoizedState,m=0;u!==null&&(m=u.retryLane),C_(l,m)}function B$(l,u){var m=0;switch(l.tag){case 13:var x=l.stateNode,I=l.memoizedState;I!==null&&(m=I.retryLane);break;case 19:x=l.stateNode;break;default:throw Error(t(314))}x!==null&&x.delete(u),C_(l,m)}var __;__=function(l,u,m){if(l!==null)if(l.memoizedProps!==u.pendingProps||xr.current)br=!0;else{if(!(l.lanes&m)&&!(u.flags&128))return br=!1,T$(l,u,m);br=!!(l.flags&131072)}else br=!1,Bt&&u.flags&1048576&&sC(u,Dh,u.index);switch(u.lanes=0,u.tag){case 2:var x=u.type;Xh(l,u),l=u.pendingProps;var I=Wl(u,Fn.current);Zl(u,m),I=_y(null,u,x,l,I,m);var T=Iy();return u.flags|=1,typeof I=="object"&&I!==null&&typeof I.render=="function"&&I.$$typeof===void 0?(u.tag=1,u.memoizedState=null,u.updateQueue=null,wr(x)?(T=!0,jh(u)):T=!1,u.memoizedState=I.state!==null&&I.state!==void 0?I.state:null,Sy(u),I.updater=qh,u.stateNode=I,I._reactInternals=u,jy(u,x,l,m),u=Ly(null,u,x,!0,T,m)):(u.tag=0,Bt&&T&&ly(u),er(null,u,I,m),u=u.child),u;case 16:x=u.elementType;e:{switch(Xh(l,u),l=u.pendingProps,I=x._init,x=I(x._payload),u.type=x,I=u.tag=H$(x),l=$s(x,l),I){case 0:u=Dy(null,u,x,l,m);break e;case 1:u=ZC(null,u,x,l,m);break e;case 11:u=GC(null,u,x,l,m);break e;case 14:u=VC(null,u,x,$s(x.type,l),m);break e}throw Error(t(306,x,""))}return u;case 0:return x=u.type,I=u.pendingProps,I=u.elementType===x?I:$s(x,I),Dy(l,u,x,I,m);case 1:return x=u.type,I=u.pendingProps,I=u.elementType===x?I:$s(x,I),ZC(l,u,x,I,m);case 3:e:{if(QC(u),l===null)throw Error(t(387));x=u.pendingProps,T=u.memoizedState,I=T.element,pC(l,u),Bh(u,x,null,m);var O=u.memoizedState;if(x=O.element,T.isDehydrated)if(T={element:x,isDehydrated:!1,cache:O.cache,pendingSuspenseBoundaries:O.pendingSuspenseBoundaries,transitions:O.transitions},u.updateQueue.baseState=T,u.memoizedState=T,u.flags&256){I=Jl(Error(t(423)),u),u=JC(l,u,x,m,I);break e}else if(x!==I){I=Jl(Error(t(424)),u),u=JC(l,u,x,m,I);break e}else for(Gr=Fi(u.stateNode.containerInfo.firstChild),Wr=u,Bt=!0,Ns=null,m=dC(u,null,x,m),u.child=m;m;)m.flags=m.flags&-3|4096,m=m.sibling;else{if(ql(),x===I){u=ti(l,u,m);break e}er(l,u,x,m)}u=u.child}return u;case 5:return mC(u),l===null&&dy(u),x=u.type,I=u.pendingProps,T=l!==null?l.memoizedProps:null,O=I.children,ny(x,I)?O=null:T!==null&&ny(x,T)&&(u.flags|=32),XC(l,u),er(l,u,O,m),u.child;case 6:return l===null&&dy(u),null;case 13:return e_(l,u,m);case 4:return vy(u,u.stateNode.containerInfo),x=u.pendingProps,l===null?u.child=Yl(u,null,x,m):er(l,u,x,m),u.child;case 11:return x=u.type,I=u.pendingProps,I=u.elementType===x?I:$s(x,I),GC(l,u,x,I,m);case 7:return er(l,u,u.pendingProps,m),u.child;case 8:return er(l,u,u.pendingProps.children,m),u.child;case 12:return er(l,u,u.pendingProps.children,m),u.child;case 10:e:{if(x=u.type._context,I=u.pendingProps,T=u.memoizedProps,O=I.value,At(Nh,x._currentValue),x._currentValue=O,T!==null)if(Fs(T.value,O)){if(T.children===I.children&&!xr.current){u=ti(l,u,m);break e}}else for(T=u.child,T!==null&&(T.return=u);T!==null;){var z=T.dependencies;if(z!==null){O=T.child;for(var G=z.firstContext;G!==null;){if(G.context===x){if(T.tag===1){G=ei(-1,m&-m),G.tag=2;var oe=T.updateQueue;if(oe!==null){oe=oe.shared;var fe=oe.pending;fe===null?G.next=G:(G.next=fe.next,fe.next=G),oe.pending=G}}T.lanes|=m,G=T.alternate,G!==null&&(G.lanes|=m),my(T.return,m,u),z.lanes|=m;break}G=G.next}}else if(T.tag===10)O=T.type===u.type?null:T.child;else if(T.tag===18){if(O=T.return,O===null)throw Error(t(341));O.lanes|=m,z=O.alternate,z!==null&&(z.lanes|=m),my(O,m,u),O=T.sibling}else O=T.child;if(O!==null)O.return=T;else for(O=T;O!==null;){if(O===u){O=null;break}if(T=O.sibling,T!==null){T.return=O.return,O=T;break}O=O.return}T=O}er(l,u,I.children,m),u=u.child}return u;case 9:return I=u.type,x=u.pendingProps.children,Zl(u,m),I=gs(I),x=x(I),u.flags|=1,er(l,u,x,m),u.child;case 14:return x=u.type,I=$s(x,u.pendingProps),I=$s(x.type,I),VC(l,u,x,I,m);case 15:return qC(l,u,u.type,u.pendingProps,m);case 17:return x=u.type,I=u.pendingProps,I=u.elementType===x?I:$s(x,I),Xh(l,u),u.tag=1,wr(x)?(l=!0,jh(u)):l=!1,Zl(u,m),$C(u,x,I),jy(u,x,I,m),Ly(null,u,x,!0,l,m);case 19:return n_(l,u,m);case 22:return YC(l,u,m)}throw Error(t(156,u.tag))};function I_(l,u){return gh(l,u)}function U$(l,u,m,x){this.tag=l,this.key=m,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=u,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=x,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ss(l,u,m,x){return new U$(l,u,m,x)}function nS(l){return l=l.prototype,!(!l||!l.isReactComponent)}function H$(l){if(typeof l=="function")return nS(l)?1:0;if(l!=null){if(l=l.$$typeof,l===K)return 11;if(l===W)return 14}return 2}function qi(l,u){var m=l.alternate;return m===null?(m=Ss(l.tag,u,l.key,l.mode),m.elementType=l.elementType,m.type=l.type,m.stateNode=l.stateNode,m.alternate=l,l.alternate=m):(m.pendingProps=u,m.type=l.type,m.flags=0,m.subtreeFlags=0,m.deletions=null),m.flags=l.flags&14680064,m.childLanes=l.childLanes,m.lanes=l.lanes,m.child=l.child,m.memoizedProps=l.memoizedProps,m.memoizedState=l.memoizedState,m.updateQueue=l.updateQueue,u=l.dependencies,m.dependencies=u===null?null:{lanes:u.lanes,firstContext:u.firstContext},m.sibling=l.sibling,m.index=l.index,m.ref=l.ref,m}function ap(l,u,m,x,I,T){var O=2;if(x=l,typeof l=="function")nS(l)&&(O=1);else if(typeof l=="string")O=5;else e:switch(l){case R:return Ya(m.children,I,T,u);case D:O=8,I|=8;break;case V:return l=Ss(12,m,u,I|2),l.elementType=V,l.lanes=T,l;case F:return l=Ss(13,m,u,I),l.elementType=F,l.lanes=T,l;case $:return l=Ss(19,m,u,I),l.elementType=$,l.lanes=T,l;case Z:return lp(m,I,T,u);default:if(typeof l=="object"&&l!==null)switch(l.$$typeof){case L:O=10;break e;case U:O=9;break e;case K:O=11;break e;case W:O=14;break e;case Y:O=16,x=null;break e}throw Error(t(130,l==null?l:typeof l,""))}return u=Ss(O,m,u,I),u.elementType=l,u.type=x,u.lanes=T,u}function Ya(l,u,m,x){return l=Ss(7,l,x,u),l.lanes=m,l}function lp(l,u,m,x){return l=Ss(22,l,x,u),l.elementType=Z,l.lanes=m,l.stateNode={isHidden:!1},l}function rS(l,u,m){return l=Ss(6,l,null,u),l.lanes=m,l}function sS(l,u,m){return u=Ss(4,l.children!==null?l.children:[],l.key,u),u.lanes=m,u.stateNode={containerInfo:l.containerInfo,pendingChildren:null,implementation:l.implementation},u}function K$(l,u,m,x,I){this.tag=u,this.containerInfo=l,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Ol(0),this.expirationTimes=Ol(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ol(0),this.identifierPrefix=x,this.onRecoverableError=I,this.mutableSourceEagerHydrationData=null}function oS(l,u,m,x,I,T,O,z,G){return l=new K$(l,u,m,z,G),u===1?(u=1,T===!0&&(u|=8)):u=0,T=Ss(3,null,null,u),l.current=T,T.stateNode=l,T.memoizedState={element:x,isDehydrated:m,cache:null,transitions:null,pendingSuspenseBoundaries:null},Sy(T),l}function W$(l,u,m){var x=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:A,key:x==null?null:""+x,children:l,containerInfo:u,implementation:m}}function E_(l){if(!l)return $i;l=l._reactInternals;e:{if(Vo(l)!==l||l.tag!==1)throw Error(t(170));var u=l;do{switch(u.tag){case 3:u=u.stateNode.context;break e;case 1:if(wr(u.type)){u=u.stateNode.__reactInternalMemoizedMergedChildContext;break e}}u=u.return}while(u!==null);throw Error(t(171))}if(l.tag===1){var m=l.type;if(wr(m))return tC(l,m,u)}return u}function T_(l,u,m,x,I,T,O,z,G){return l=oS(m,x,!0,l,I,T,O,z,G),l.context=E_(null),m=l.current,x=tr(),I=Gi(m),T=ei(x,I),T.callback=u??null,Ui(m,T,I),l.current.lanes=I,Oa(l,I,x),Cr(l,x),l}function cp(l,u,m,x){var I=u.current,T=tr(),O=Gi(I);return m=E_(m),u.context===null?u.context=m:u.pendingContext=m,u=ei(T,O),u.payload={element:l},x=x===void 0?null:x,x!==null&&(u.callback=x),l=Ui(I,u,O),l!==null&&(Us(l,I,O,T),zh(l,I,O)),O}function up(l){if(l=l.current,!l.child)return null;switch(l.child.tag){case 5:return l.child.stateNode;default:return l.child.stateNode}}function k_(l,u){if(l=l.memoizedState,l!==null&&l.dehydrated!==null){var m=l.retryLane;l.retryLane=m!==0&&m<u?m:u}}function iS(l,u){k_(l,u),(l=l.alternate)&&k_(l,u)}function G$(){return null}var M_=typeof reportError=="function"?reportError:function(l){console.error(l)};function aS(l){this._internalRoot=l}dp.prototype.render=aS.prototype.render=function(l){var u=this._internalRoot;if(u===null)throw Error(t(409));cp(l,u,null,null)},dp.prototype.unmount=aS.prototype.unmount=function(){var l=this._internalRoot;if(l!==null){this._internalRoot=null;var u=l.containerInfo;Ga(function(){cp(null,l,null,null)}),u[Yo]=null}};function dp(l){this._internalRoot=l}dp.prototype.unstable_scheduleHydration=function(l){if(l){var u=Sh();l={blockedOn:null,target:l,priority:u};for(var m=0;m<uo.length&&u!==0&&u<uo[m].priority;m++);uo.splice(m,0,l),m===0&&cu(l)}};function lS(l){return!(!l||l.nodeType!==1&&l.nodeType!==9&&l.nodeType!==11)}function hp(l){return!(!l||l.nodeType!==1&&l.nodeType!==9&&l.nodeType!==11&&(l.nodeType!==8||l.nodeValue!==" react-mount-point-unstable "))}function A_(){}function V$(l,u,m,x,I){if(I){if(typeof x=="function"){var T=x;x=function(){var oe=up(O);T.call(oe)}}var O=T_(u,x,l,0,null,!1,!1,"",A_);return l._reactRootContainer=O,l[Yo]=O.current,Su(l.nodeType===8?l.parentNode:l),Ga(),O}for(;I=l.lastChild;)l.removeChild(I);if(typeof x=="function"){var z=x;x=function(){var oe=up(G);z.call(oe)}}var G=oS(l,0,!1,null,null,!1,!1,"",A_);return l._reactRootContainer=G,l[Yo]=G.current,Su(l.nodeType===8?l.parentNode:l),Ga(function(){cp(u,G,m,x)}),G}function pp(l,u,m,x,I){var T=m._reactRootContainer;if(T){var O=T;if(typeof I=="function"){var z=I;I=function(){var G=up(O);z.call(G)}}cp(u,O,l,I)}else O=V$(m,u,l,I,x);return up(O)}yh=function(l){switch(l.tag){case 3:var u=l.stateNode;if(u.current.memoizedState.isDehydrated){var m=ji(u.pendingLanes);m!==0&&(Dl(u,m|1),Cr(u,Kt()),!(dt&6)&&(nc=Kt()+500,zi()))}break;case 13:Ga(function(){var x=Jo(l,1);if(x!==null){var I=tr();Us(x,l,1,I)}}),iS(l,1)}},iu=function(l){if(l.tag===13){var u=Jo(l,134217728);if(u!==null){var m=tr();Us(u,l,134217728,m)}iS(l,134217728)}},Os=function(l){if(l.tag===13){var u=Gi(l),m=Jo(l,u);if(m!==null){var x=tr();Us(m,l,u,x)}iS(l,u)}},Sh=function(){return ct},vh=function(l,u){var m=ct;try{return ct=l,u()}finally{ct=m}},Hr=function(l,u,m){switch(u){case"input":if(hr(l,m),u=m.name,m.type==="radio"&&u!=null){for(m=l;m.parentNode;)m=m.parentNode;for(m=m.querySelectorAll("input[name="+JSON.stringify(""+u)+'][type="radio"]'),u=0;u<m.length;u++){var x=m[u];if(x!==l&&x.form===l.form){var I=Mh(x);if(!I)throw Error(t(90));Xt(x),hr(x,I)}}}break;case"textarea":Pl(l,m);break;case"select":u=m.value,u!=null&&ls(l,!!m.multiple,u,!1)}},Tl=Jy,kl=Ga;var q$={usingClientEntryPoint:!1,Events:[wu,Hl,Mh,ki,El,Jy]},Du={findFiberByHostInstance:Na,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},Y$={bundleType:Du.bundleType,version:Du.version,rendererPackageName:Du.rendererPackageName,rendererConfig:Du.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:E.ReactCurrentDispatcher,findHostInstanceByFiber:function(l){return l=ph(l),l===null?null:l.stateNode},findFiberByHostInstance:Du.findFiberByHostInstance||G$,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 fp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!fp.isDisabled&&fp.supportsFiber)try{Al=fp.inject(Y$),hs=fp}catch{}}return _r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=q$,_r.createPortal=function(l,u){var m=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!lS(u))throw Error(t(200));return W$(l,u,null,m)},_r.createRoot=function(l,u){if(!lS(l))throw Error(t(299));var m=!1,x="",I=M_;return u!=null&&(u.unstable_strictMode===!0&&(m=!0),u.identifierPrefix!==void 0&&(x=u.identifierPrefix),u.onRecoverableError!==void 0&&(I=u.onRecoverableError)),u=oS(l,1,!1,null,null,m,!1,x,I),l[Yo]=u.current,Su(l.nodeType===8?l.parentNode:l),new aS(u)},_r.findDOMNode=function(l){if(l==null)return null;if(l.nodeType===1)return l;var u=l._reactInternals;if(u===void 0)throw typeof l.render=="function"?Error(t(188)):(l=Object.keys(l).join(","),Error(t(268,l)));return l=ph(u),l=l===null?null:l.stateNode,l},_r.flushSync=function(l){return Ga(l)},_r.hydrate=function(l,u,m){if(!hp(u))throw Error(t(200));return pp(null,l,u,!0,m)},_r.hydrateRoot=function(l,u,m){if(!lS(l))throw Error(t(405));var x=m!=null&&m.hydratedSources||null,I=!1,T="",O=M_;if(m!=null&&(m.unstable_strictMode===!0&&(I=!0),m.identifierPrefix!==void 0&&(T=m.identifierPrefix),m.onRecoverableError!==void 0&&(O=m.onRecoverableError)),u=T_(u,null,l,1,m??null,I,!1,T,O),l[Yo]=u.current,Su(l),x)for(l=0;l<x.length;l++)m=x[l],I=m._getVersion,I=I(m._source),u.mutableSourceEagerHydrationData==null?u.mutableSourceEagerHydrationData=[m,I]:u.mutableSourceEagerHydrationData.push(m,I);return new dp(u)},_r.render=function(l,u,m){if(!hp(u))throw Error(t(200));return pp(null,l,u,!1,m)},_r.unmountComponentAtNode=function(l){if(!hp(l))throw Error(t(40));return l._reactRootContainer?(Ga(function(){pp(null,null,l,!1,function(){l._reactRootContainer=null,l[Yo]=null})}),!0):!1},_r.unstable_batchedUpdates=Jy,_r.unstable_renderSubtreeIntoContainer=function(l,u,m,x){if(!hp(m))throw Error(t(200));if(l==null||l._reactInternals===void 0)throw Error(t(38));return pp(l,u,m,!1,x)},_r.version="18.3.1-next-f1338f8080-20240426",_r}var $_;function Yk(){if($_)return dS.exports;$_=1;function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}return n(),dS.exports=i6(),dS.exports}var z_;function a6(){if(z_)return gp;z_=1;var n=Yk();return gp.createRoot=n.createRoot,gp.hydrateRoot=n.hydrateRoot,gp}var Xk=a6();const l6=bi(Xk);function we(n,e={}){const t=typeof n=="string"?n:n.src;if(typeof e=="function")return e(t);const{baseUrl:r=""}=e;return t.startsWith("data:")||t.match(/^https?:\/\//)?t:`${r.replace(/\/$/,"")}/${t.replace(/^\.?\//,"")}`}function c6(n){const e=we("./icons/icon/0_merged.svg",n);return{fonts:{monospace:we("./fonts/IBMPlexMono-Medium.woff2",n),sansSerif:we("./fonts/IBMPlexSans-Medium.woff2",n),serif:we("./fonts/IBMPlexSerif-Medium.woff2",n),draw:we("./fonts/Shantell_Sans-Tldrawish.woff2",n)},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:we("./translations/ar.json",n),bn:we("./translations/bn.json",n),ca:we("./translations/ca.json",n),cs:we("./translations/cs.json",n),da:we("./translations/da.json",n),de:we("./translations/de.json",n),el:we("./translations/el.json",n),en:we("./translations/en.json",n),es:we("./translations/es.json",n),fa:we("./translations/fa.json",n),fi:we("./translations/fi.json",n),fr:we("./translations/fr.json",n),gl:we("./translations/gl.json",n),"gu-in":we("./translations/gu-in.json",n),he:we("./translations/he.json",n),"hi-in":we("./translations/hi-in.json",n),hr:we("./translations/hr.json",n),hu:we("./translations/hu.json",n),id:we("./translations/id.json",n),it:we("./translations/it.json",n),ja:we("./translations/ja.json",n),"km-kh":we("./translations/km-kh.json",n),kn:we("./translations/kn.json",n),"ko-kr":we("./translations/ko-kr.json",n),ku:we("./translations/ku.json",n),languages:we("./translations/languages.json",n),main:we("./translations/main.json",n),ml:we("./translations/ml.json",n),mr:we("./translations/mr.json",n),ms:we("./translations/ms.json",n),my:we("./translations/my.json",n),ne:we("./translations/ne.json",n),nl:we("./translations/nl.json",n),no:we("./translations/no.json",n),pa:we("./translations/pa.json",n),pl:we("./translations/pl.json",n),"pt-br":we("./translations/pt-br.json",n),"pt-pt":we("./translations/pt-pt.json",n),ro:we("./translations/ro.json",n),ru:we("./translations/ru.json",n),sl:we("./translations/sl.json",n),so:we("./translations/so.json",n),sv:we("./translations/sv.json",n),ta:we("./translations/ta.json",n),te:we("./translations/te.json",n),th:we("./translations/th.json",n),tl:we("./translations/tl.json",n),tr:we("./translations/tr.json",n),uk:we("./translations/uk.json",n),ur:we("./translations/ur.json",n),vi:we("./translations/vi.json",n),"zh-cn":we("./translations/zh-cn.json",n),"zh-tw":we("./translations/zh-tw.json",n)},embedIcons:{codepen:we("./embed-icons/codepen.png",n),codesandbox:we("./embed-icons/codesandbox.png",n),desmos:we("./embed-icons/desmos.png",n),excalidraw:we("./embed-icons/excalidraw.png",n),felt:we("./embed-icons/felt.png",n),figma:we("./embed-icons/figma.png",n),github_gist:we("./embed-icons/github_gist.png",n),google_calendar:we("./embed-icons/google_calendar.png",n),google_maps:we("./embed-icons/google_maps.png",n),google_slides:we("./embed-icons/google_slides.png",n),observable:we("./embed-icons/observable.png",n),replit:we("./embed-icons/replit.png",n),scratch:we("./embed-icons/scratch.png",n),spotify:we("./embed-icons/spotify.png",n),tldraw:we("./embed-icons/tldraw.png",n),val_town:we("./embed-icons/val_town.png",n),vimeo:we("./embed-icons/vimeo.png",n),youtube:we("./embed-icons/youtube.png",n)}}}const fS="__TLDRAW_LIBRARY_VERSIONS__";function u6(){if(globalThis[fS])return globalThis[fS];const n={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,fS,{value:n,writable:!1,configurable:!1,enumerable:!1}),n}function ya(n,e,t){if(!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=u6();if(r.versions.push({name:n,version:e,modules:t}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,B_(r)},100)}catch{B_(r)}}function B_(n){if(!n.versions.length||n.didWarn)return;const e=n.versions.sort((a,c)=>U_(a.version,c.version)),t=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),gS(s,a.name,new Set).add(a.version);continue}a.version===t?r.add(a.name):(r.delete(a.name),gS(s,a.name,new Set).add(a.version))}if(s.size>0){const a=[`${ri("[tldraw]",["bold","bgRed","textWhite"])} ${ri("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 ${ri(`v${t}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,c=>` • ✅ ${ri(c,["bold"])}`),"","The following libraries are not on the latest version, or have multiple versions installed:",...Array.from(s,([c,d])=>{const h=Array.from(d).sort(U_).map(f=>ri(`v${f}`,f===t?["textGreen"]:["textRed"]));return` • ❌ ${ri(c,["bold"])} (${h.join(", ")})`})];console.log(a.join(`
|
|
41
|
+
`)),n.didWarn=!0;return}const o=new Map;for(const a of e)gS(o,a.name,{version:a.version,modules:[]}).modules.push(a.modules);const i=new Map;for(const[a,c]of o)c.modules.length>1&&i.set(a,c);if(i.size>0){const a=[`${ri("[tldraw]",["bold","bgRed","textWhite"])} ${ri("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,([c,d])=>{const h=d.modules.map((f,g)=>f==="esm"?` ${g+1}. ES Modules`:` ${g+1}. CommonJS`).join(`
|
|
42
|
+
`);return` • ❌ ${ri(c,["bold"])} v${d.version}:
|
|
43
|
+
${h}`}),"","You should configure your bundler to only import one version of each library."];console.log(a.join(`
|
|
44
|
+
`)),n.didWarn=!0;return}}function U_(n,e){const t=n.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/),r=e.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/);return!t||!r?n.localeCompare(e):t[1]!==r[1]?Number(t[1])-Number(r[1]):t[2]!==r[2]?Number(t[2])-Number(r[2]):t[3]!==r[3]?Number(t[3])-Number(r[3]):t[4]&&r[4]?t[4].localeCompare(r[4]):t[4]?1:r[4]?-1:0}const d6={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function ri(n,e=[]){return`\x1B[${e.map(t=>d6[t]).join(";")}m${n}\x1B[m`}function gS(n,e,t){return n.has(e)?n.get(e):(n.set(e,t),t)}var mS,H_;function h6(){if(H_)return mS;H_=1;var n="Expected a function",e=NaN,t="[object Symbol]",r=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,i=/^0o[0-7]+$/i,a=parseInt,c=typeof Or=="object"&&Or&&Or.Object===Object&&Or,d=typeof self=="object"&&self&&self.Object===Object&&self,h=c||d||Function("return this")(),f=Object.prototype,g=f.toString,y=Math.max,S=Math.min,v=function(){return h.Date.now()};function w(A,R,D){var V,L,U,K,F,$,W=0,Y=!1,Z=!1,H=!0;if(typeof A!="function")throw new TypeError(n);R=M(R)||0,P(D)&&(Y=!!D.leading,Z="maxWait"in D,U=Z?y(M(D.maxWait)||0,R):U,H="trailing"in D?!!D.trailing:H);function Q(xe){var Ie=V,ze=L;return V=L=void 0,W=xe,K=A.apply(ze,Ie),K}function ae(xe){return W=xe,F=setTimeout(he,R),Y?Q(xe):K}function B(xe){var Ie=xe-$,ze=xe-W,Ze=R-Ie;return Z?S(Ze,U-ze):Ze}function ne(xe){var Ie=xe-$,ze=xe-W;return $===void 0||Ie>=R||Ie<0||Z&&ze>=U}function he(){var xe=v();if(ne(xe))return Pe(xe);F=setTimeout(he,B(xe))}function Pe(xe){return F=void 0,H&&V?Q(xe):(V=L=void 0,K)}function ue(){F!==void 0&&clearTimeout(F),W=0,V=$=L=F=void 0}function Fe(){return F===void 0?K:Pe(v())}function Me(){var xe=v(),Ie=ne(xe);if(V=arguments,L=this,$=xe,Ie){if(F===void 0)return ae($);if(Z)return F=setTimeout(he,R),Q($)}return F===void 0&&(F=setTimeout(he,R)),K}return Me.cancel=ue,Me.flush=Fe,Me}function b(A,R,D){var V=!0,L=!0;if(typeof A!="function")throw new TypeError(n);return P(D)&&(V="leading"in D?!!D.leading:V,L="trailing"in D?!!D.trailing:L),w(A,R,{leading:V,maxWait:R,trailing:L})}function P(A){var R=typeof A;return!!A&&(R=="object"||R=="function")}function k(A){return!!A&&typeof A=="object"}function E(A){return typeof A=="symbol"||k(A)&&g.call(A)==t}function M(A){if(typeof A=="number")return A;if(E(A))return e;if(P(A)){var R=typeof A.valueOf=="function"?A.valueOf():A;A=P(R)?R+"":R}if(typeof A!="string")return A===0?A:+A;A=A.replace(r,"");var D=o.test(A);return D||i.test(A)?a(A.slice(2),D?2:8):s.test(A)?e:+A}return mS=b,mS}var p6=h6();const Zk=bi(p6);var yS,K_;function f6(){if(K_)return yS;K_=1;var n=200,e="__lodash_hash_undefined__",t=1/0,r="[object Function]",s="[object GeneratorFunction]",o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,a=typeof Or=="object"&&Or&&Or.Object===Object&&Or,c=typeof self=="object"&&self&&self.Object===Object&&self,d=a||c||Function("return this")();function h(ie,ve){var Ke=ie?ie.length:0;return!!Ke&&g(ie,ve,0)>-1}function f(ie,ve,Ke,bt){for(var cs=ie.length,mr=Ke+-1;++mr<cs;)if(ve(ie[mr],mr,ie))return mr;return-1}function g(ie,ve,Ke){if(ve!==ve)return f(ie,y,Ke);for(var bt=Ke-1,cs=ie.length;++bt<cs;)if(ie[bt]===ve)return bt;return-1}function y(ie){return ie!==ie}function S(ie,ve){return ie.has(ve)}function v(ie,ve){return ie==null?void 0:ie[ve]}function w(ie){var ve=!1;if(ie!=null&&typeof ie.toString!="function")try{ve=!!(ie+"")}catch{}return ve}function b(ie){var ve=-1,Ke=Array(ie.size);return ie.forEach(function(bt){Ke[++ve]=bt}),Ke}var P=Array.prototype,k=Function.prototype,E=Object.prototype,M=d["__core-js_shared__"],A=function(){var ie=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||"");return ie?"Symbol(src)_1."+ie:""}(),R=k.toString,D=E.hasOwnProperty,V=E.toString,L=RegExp("^"+R.call(D).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),U=P.splice,K=ls(d,"Map"),F=ls(d,"Set"),$=ls(Object,"create");function W(ie){var ve=-1,Ke=ie?ie.length:0;for(this.clear();++ve<Ke;){var bt=ie[ve];this.set(bt[0],bt[1])}}function Y(){this.__data__=$?$(null):{}}function Z(ie){return this.has(ie)&&delete this.__data__[ie]}function H(ie){var ve=this.__data__;if($){var Ke=ve[ie];return Ke===e?void 0:Ke}return D.call(ve,ie)?ve[ie]:void 0}function Q(ie){var ve=this.__data__;return $?ve[ie]!==void 0:D.call(ve,ie)}function ae(ie,ve){var Ke=this.__data__;return Ke[ie]=$&&ve===void 0?e:ve,this}W.prototype.clear=Y,W.prototype.delete=Z,W.prototype.get=H,W.prototype.has=Q,W.prototype.set=ae;function B(ie){var ve=-1,Ke=ie?ie.length:0;for(this.clear();++ve<Ke;){var bt=ie[ve];this.set(bt[0],bt[1])}}function ne(){this.__data__=[]}function he(ie){var ve=this.__data__,Ke=wt(ve,ie);if(Ke<0)return!1;var bt=ve.length-1;return Ke==bt?ve.pop():U.call(ve,Ke,1),!0}function Pe(ie){var ve=this.__data__,Ke=wt(ve,ie);return Ke<0?void 0:ve[Ke][1]}function ue(ie){return wt(this.__data__,ie)>-1}function Fe(ie,ve){var Ke=this.__data__,bt=wt(Ke,ie);return bt<0?Ke.push([ie,ve]):Ke[bt][1]=ve,this}B.prototype.clear=ne,B.prototype.delete=he,B.prototype.get=Pe,B.prototype.has=ue,B.prototype.set=Fe;function Me(ie){var ve=-1,Ke=ie?ie.length:0;for(this.clear();++ve<Ke;){var bt=ie[ve];this.set(bt[0],bt[1])}}function xe(){this.__data__={hash:new W,map:new(K||B),string:new W}}function Ie(ie){return gr(this,ie).delete(ie)}function ze(ie){return gr(this,ie).get(ie)}function Ze(ie){return gr(this,ie).has(ie)}function Xt(ie,ve){return gr(this,ie).set(ie,ve),this}Me.prototype.clear=xe,Me.prototype.delete=Ie,Me.prototype.get=ze,Me.prototype.has=Ze,Me.prototype.set=Xt;function yt(ie){var ve=-1,Ke=ie?ie.length:0;for(this.__data__=new Me;++ve<Ke;)this.add(ie[ve])}function zt(ie){return this.__data__.set(ie,e),this}function _t(ie){return this.__data__.has(ie)}yt.prototype.add=yt.prototype.push=zt,yt.prototype.has=_t;function wt(ie,ve){for(var Ke=ie.length;Ke--;)if(_l(ie[Ke][0],ve))return Ke;return-1}function hr(ie){if(!As(ie)||bl(ie))return!1;var ve=oo(ie)||w(ie)?L:i;return ve.test(Pl(ie))}function pr(ie,ve,Ke){var bt=-1,cs=h,mr=ie.length,Wo=!0,Br=[],Ur=Br;if(mr>=n){var yr=fr(ie);if(yr)return b(yr);Wo=!1,cs=S,Ur=new yt}else Ur=Br;e:for(;++bt<mr;){var Hr=ie[bt],Sr=Hr;if(Hr=Hr!==0?Hr:0,Wo&&Sr===Sr){for(var js=Ur.length;js--;)if(Ur[js]===Sr)continue e;Br.push(Hr)}else cs(Ur,Sr,Ke)||(Ur!==Br&&Ur.push(Sr),Br.push(Hr))}return Br}var fr=F&&1/b(new F([,-0]))[1]==t?function(ie){return new F(ie)}:ka;function gr(ie,ve){var Ke=ie.__data__;return Ta(ve)?Ke[typeof ve=="string"?"string":"hash"]:Ke.map}function ls(ie,ve){var Ke=v(ie,ve);return hr(Ke)?Ke:void 0}function Ta(ie){var ve=typeof ie;return ve=="string"||ve=="number"||ve=="symbol"||ve=="boolean"?ie!=="__proto__":ie===null}function bl(ie){return!!A&&A in ie}function Pl(ie){if(ie!=null){try{return R.call(ie)}catch{}try{return ie+""}catch{}}return""}function Cl(ie){return ie&&ie.length?pr(ie):[]}function _l(ie,ve){return ie===ve||ie!==ie&&ve!==ve}function oo(ie){var ve=As(ie)?V.call(ie):"";return ve==r||ve==s}function As(ie){var ve=typeof ie;return!!ie&&(ve=="object"||ve=="function")}function ka(){}return yS=Cl,yS}var g6=f6();const m6=bi(g6);function Qk(n){const e=(...t)=>{try{return n(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const vd=()=>{},rr={ok(n){return{ok:!0,value:n}},err(n){return{ok:!1,error:n}}};function un(n,e){const t=e&&n&&typeof n=="object"&&e in n?n[e]:n;throw new Error(`Unknown switch case ${t}`)}const mt=Qk((n,e)=>{if(!n)throw new Error(e||"Assertion Error")}),Ar=Qk((n,e)=>{if(n==null)throw new Error(e??"value must be defined");return n});function V0(){let n,e;const t=new Promise((r,s)=>{n=r,e=s});return Object.assign(t,{resolve:n,reject:e})}function jw(n){return new Promise(e=>setTimeout(e,n))}const Qu={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},y6=Qu.Good;class Jk{constructor(){j(this,"startTime",0);j(this,"name","");j(this,"frames",0);j(this,"started",!1);j(this,"frame",null);j(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,t=e===0?0:Math.floor(this.frames/e),r=t>55?Qu.Good:t>30?Qu.Mid:Qu.Poor,s=r===Qu.Mid?"black":"white",o=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${o} %c${t}%c fps`,`color: white; background: ${y6};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 q0(n,e){const t=[];e:for(const r of n){for(const s of t)if(e?e(r,s):r===s)continue e;t.push(r)}return t}function Ye(n){return n.filter(e=>e!=null)}function In(n){return n[n.length-1]}function S6(n,e){let t,r=1/0;for(const s of n){const o=e(s);o<r&&(t=s,r=o)}return t}function v6(n,e){let t,r=-1/0;for(const s of n){const o=e(s);o>r&&(t=s,r=o)}return t}function eM(n,e){if(n===e)return!0;if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!Object.is(n[t],e[t]))return!1;return!0}function Dr(...n){if(n.length===2){const[e,t]=n;t.addInitializer(function(){mt(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const s=e.bind(this),o=Reflect.defineProperty(this,t.name,{value:s,writable:!0,configurable:!0});mt(o,"Cannot bind a non-configurable class method.")})}else{const[e,t,r]=n;if(!r||typeof r.value!="function")throw new TypeError(`Only methods can be decorated with @bind. <${t}> is not a method!`);return{configurable:!0,get(){const s=r.value.bind(this);return Object.defineProperty(this,t,{value:s,configurable:!0,writable:!0}),s}}}}class Ao{constructor(){j(this,"items",new WeakMap)}get(e,t){return this.items.has(e)||this.items.set(e,t(e)),this.items.get(e)}}function Y0(n,e){let t;const r=(...s)=>(t||(t={},t.promise=new Promise((o,i)=>{t.resolve=o,t.reject=i})),clearTimeout(t.timeout),t.latestArgs=s,t.timeout=setTimeout(()=>{const o=t;t=void 0;try{o.resolve(n(...o.latestArgs))}catch(i){o.reject(i)}},e),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const W_=new WeakMap;function X0(n,e){if(typeof n!="object"||n===null)return;let t=W_.get(n);t||(t={tags:{},extras:{}},W_.set(n,t)),e.tags&&(t.tags={...t.tags,...e.tags}),e.extras&&(t.extras={...t.extras,...e.extras})}async function jo(n,e){return window.fetch(n,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const xd=(n,e)=>{const t=new window.Image(n,e);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Gs{static async dataUrlToArrayBuffer(e){return jo(e).then(function(t){return t.arrayBuffer()})}static async blobToDataUrl(e){return await new Promise((t,r)=>{if(e){const s=new FileReader;s.onload=()=>t(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((t,r)=>{if(e){const s=new FileReader;s.onload=()=>t(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsText(e)}})}static rewriteMimeType(e,t){return e.type===t?e:e instanceof File?new File([e],e.name,{type:t}):new Blob([e],{type:t})}}function Z0(n){let e=0;for(let t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e|=0;return e+""}function tM(n){const e=new DataView(n);let t=0;for(let r=0;r<e.byteLength;r++)t=(t<<5)-t+e.getUint8(r),t|=0;return t+""}/*!
|
|
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 G_=globalThis.crypto,x6="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",w6=128;let Za,mc;function b6(n){!Za||Za.length<n?(Za=new Uint8Array(n*w6),G_.getRandomValues(Za),mc=0):mc+n>Za.length&&(G_.getRandomValues(Za),mc=0),mc+=n}function P6(n=21){b6(n-=0);let e="";for(let t=mc-n;t<mc;t++)e+=x6[Za[t]&63];return e}let C6=P6;function xt(n){return C6(n)}/*!
|
|
54
|
+
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
55
|
+
* Copyright (c) Philip van Heemstra
|
|
56
|
+
*/function _6(n){const e=new Uint8Array(n);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,c,d=1024){if(!i)return-1;i=new RegExp(i,"g");const h=i.source.length,f=new TextDecoder,g=o.length;if(typeof c>"u"&&(c=g),a>=g||c<=0||a>=c)return-1;o=o.subarray(a,c);let y=-1,S=0,v=0,w="";e:for(;S<o.length;){const b=S+d,P=o.subarray(S,b),k=f.decode(P,{stream:!0}),E=w+k;let M,A=-1;for(;(M=i.exec(E))!==null;){A=M.index-w.length,y=v+A;break e}S=b,v+=k.length;const R=A>-1?A+h:k.length-h;w=k.slice(R)}return y>=0&&(y+=a>=0?a:g+a),y}const s=r(e,"IDAT",12);return s>=12?r(e,"acTL",8,s)>=8:!1}const I6=n=>new Uint8Array(n)[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 V_(n,e){let t=0;for(;n[e+t];)t+=n[e+t]+1;return t+1}function E6(n){return new TextDecoder("ascii").decode(n.slice(0,3))==="GIF"}function T6(n){const e=new Uint8Array(n);let t,r,s=0,o=0;if(!E6(n))return!1;for(t=e[10]&128,r=e[10]&7,s+=6,s+=7,s+=t?3*Math.pow(2,r+1):0;o<2&&s<e.length;)switch(e[s]){case 44:o+=1,t=e[s+9]&128,r=e[s+9]&7,s+=10,s+=t?3*Math.pow(2,r+1):0,s+=V_(e,s+1)+1;break;case 33:s+=2,s+=V_(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 Rw=[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"&&(Rw=new Int32Array(Rw));const k6=(n,e)=>{let t=-1;for(let r=0;r<n.length;r++)t=Rw[(t^n[r])&255]^t>>>8;return t^-1},q_=4,Y_=4;class bo{static isPng(e,t){return e.getUint8(t+0)===137&&e.getUint8(t+1)===80&&e.getUint8(t+2)===78&&e.getUint8(t+3)===71&&e.getUint8(t+4)===13&&e.getUint8(t+5)===10&&e.getUint8(t+6)===26&&e.getUint8(t+7)===10}static getChunkType(e,t){return[String.fromCharCode(e.getUint8(t)),String.fromCharCode(e.getUint8(t+1)),String.fromCharCode(e.getUint8(t+2)),String.fromCharCode(e.getUint8(t+3))].join("")}static readChunks(e,t=0){const r={};if(!bo.isPng(e,t))throw new Error("Not a PNG");for(t+=8;t<=e.buffer.byteLength;){const s=t,o=e.getInt32(t);t+=4;const i=bo.getChunkType(e,t);if(i==="IDAT"&&r[i]){t+=o+q_+Y_;continue}if(i==="IEND")break;r[i]={start:s,dataOffset:t+4,size:o},t+=o+q_+Y_}return r}static parsePhys(e,t){return{ppux:e.getUint32(t),ppuy:e.getUint32(t+4),unit:e.getUint8(t+4)}}static findChunk(e,t){return bo.readChunks(e)[t]}static setPhysChunk(e,t=1,r){let s=46,o=0;const i=bo.findChunk(e,"pHYs");i&&(s=i.start,o=i.size);const a=bo.findChunk(e,"IDAT");a&&(s=a.start,o=0);const c=new ArrayBuffer(21),d=new DataView(c);d.setUint32(0,9),d.setUint8(4,112),d.setUint8(5,72),d.setUint8(6,89),d.setUint8(7,115);const h=2835.5;d.setInt32(8,h*t),d.setInt32(12,h*t),d.setInt8(16,1);const f=new Uint8Array(c.slice(4,17));d.setInt32(17,k6(f));const g=e.buffer.slice(0,s),y=e.buffer.slice(s+o);return new Blob([g,c,y],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 M6(n){return!n||n.length<12?!1:n[8]===87&&n[9]===69&&n[10]===66&&n[11]===80}function A6(n){const e=new Uint8Array(n);return!M6(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const nM=Object.freeze(["image/svg+xml"]),rM=Object.freeze(["image/jpeg","image/png","image/webp"]),sM=Object.freeze(["image/gif","image/apng","image/avif"]),Fd=Object.freeze([...rM,...nM,...sM]),mg=Object.freeze(["video/mp4","video/webm","video/quicktime"]),j6=[...Fd,...mg].join(",");class Xr{static loadVideo(e){return new Promise((t,r)=>{const s=document.createElement("video");s.onloadeddata=()=>t(s),s.onerror=o=>{console.error(o),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=e})}static async getVideoFrameAsDataUrl(e,t=0){const r=V0();let s=!1;const o=()=>{if(!s)if(e.readyState>=e.HAVE_METADATA)s=!0,e.currentTime=t;else return;if(e.readyState>=e.HAVE_CURRENT_DATA){const a=document.createElement("canvas");a.width=e.videoWidth,a.height=e.videoHeight;const c=a.getContext("2d");if(!c)throw new Error("Could not get 2d context");c.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((t,r)=>{const s=xd();s.onload=()=>t(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 Xr.usingObjectURL(e,async t=>{const r=await Xr.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const t=await Xr.usingObjectURL(e,Xr.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(bo.isPng(r,0)){const s=bo.findChunk(r,"pHYs");if(s){const o=bo.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(t.naturalWidth/i),h:Math.round(t.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:t.naturalWidth,h:t.naturalHeight}}return{w:t.naturalWidth,h:t.naturalHeight}}static async isAnimated(e){return e.type==="image/gif"?T6(await e.arrayBuffer()):e.type==="image/avif"?I6(await e.arrayBuffer()):e.type==="image/webp"?A6(await e.arrayBuffer()):e.type==="image/apng"?_6(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return sM.includes(e||"")}static isStaticImageType(e){return rM.includes(e||"")}static isVectorImageType(e){return nM.includes(e||"")}static isImageType(e){return Fd.includes(e)}static async usingObjectURL(e,t){const r=URL.createObjectURL(e);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function ot(n,e,t){return n+(e-n)*t}function eo(n=""){let e=0,t=0,r=0,s=0;function o(){const i=e^e<<11;return e=t,t=r,r=s,s^=(s>>>19^i^i>>>8)>>>0,s/4294967296*2}for(let i=0;i<n.length+64;i++)e^=n.charCodeAt(i)|0,o();return o}function Ac(n,e,t,r=!1){const[s,o]=e,[i,a]=t,c=i+(n-s)/(o-s)*(a-i);return r?i<a?Math.max(Math.min(c,a),i):Math.max(Math.min(c,i),a):c}function Cs(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function Vn(n,e){if(Cs(n,e))return n[e]}function X_(n){return Object.keys(n)}function Vt(n){return Object.values(n)}function Lr(n){return Object.entries(n)}function Q0(n){return Object.fromEntries(n)}function cd(n,e){const t={};let r=!1;for(const[s,o]of Lr(n))e(s,o)?t[s]=o:r=!0;return r?t:n}function Nd(n,e){const t={};for(const[r,s]of Lr(n)){const o=e(r,s);t[r]=o}return t}function oM(n,e){if(n===e)return!0;const t=new Set(Object.keys(n)),r=new Set(Object.keys(e));if(t.size!==r.size)return!1;for(const s of t)if(!r.has(s)||!Object.is(n[s],e[s]))return!1;return!0}function R6(n){const e=O6(n.chars),t=D6(e,n.firstPositive,n.mostPositive,n.mostNegative),r=n.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=L6(r,e.length);return{chars:n.chars,byChar:e.byChar,byCode:e.byCode,length:e.length,first:e.byCode[0],last:e.byCode[e.length-1],firstPositive:t.firstPositive,mostPositive:t.mostPositive,firstNegative:t.firstNegative,mostNegative:t.mostNegative,jitterRange:r,paddingDict:s}}function O6(n){const e={},t={},r=n.length;for(let s=0;s<r;s++){const o=n[s];e[s]=o,t[o]=s}return{byCode:e,byChar:t,length:r}}function D6(n,e,t,r){const s=n.byChar[e],o=n.byChar[t],i=n.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:n.byCode[s],mostPositive:n.byCode[o],firstNegative:n.byCode[s-1],mostNegative:n.byCode[i]}}function L6(n,e){const t={};for(let r=0;r<100&&(t[r]=Math.pow(e,r),!(t[r]>n));r++);return t}var SS=null;function J0(){return SS||(SS=R6({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function sa(n,e,t){const r=t.byChar[n],s=t.byChar[e];return Math.abs(r-s)}function eb(n,e){const t=n[0];if(t>e.mostPositive||t<e.mostNegative)throw new Error("invalid firstChar on key");return t===e.mostPositive?sa(t,e.firstPositive,e)+1+Af(n.slice(1),"positive",e):t===e.mostNegative?sa(t,e.firstNegative,e)+1+Af(n.slice(1),"negative",e):t>=e.firstPositive?sa(t,e.firstPositive,e)+2:sa(t,e.firstNegative,e)+2}function Af(n,e,t){const r=n[0];if(r>t.mostPositive||r<t.mostNegative)throw new Error("invalid firstChar on key");return r===t.mostPositive&&e==="positive"?sa(r,t.mostNegative,t)+1+Af(n.slice(1),e,t):r===t.mostNegative&&e==="negative"?sa(r,t.mostPositive,t)+1+Af(n.slice(1),e,t):e==="positive"?sa(r,t.mostNegative,t)+2:sa(r,t.mostPositive,t)+2}function yg(n,e,t,r,s){const o=Math.max(n.length,e.length);return t==="start"?[n.padStart(o,r),e.padStart(o,r)]:[n.padEnd(o,r),e.padEnd(o,r)]}function F6(n,e,t){let[r,s]=yg(n,e,"end",t.first),o=Ow(r,s,t);o===1&&(r=r.padEnd(r.length+1,t.first),o=t.length);const i=lM(Math.floor(o/2),t);return tb(r,i,t)}function Ow(n,e,t){const[r,s]=yg(n,e,"end",t.first).sort(),o=iM(s,r,t);return N6(o,t)}function tb(n,e,t){const r=t.length,[s,o]=yg(n,e,"start",t.first),i=[];let a=0;for(let c=s.length-1;c>=0;c--){const d=t.byChar[s[c]],h=t.byChar[o[c]],f=d+h+a;a=Math.floor(f/r);const g=f%r;i.unshift(t.byCode[g])}return a>0&&i.unshift(t.byCode[a]),i.join("")}function iM(n,e,t){const r=t.length,[s,o]=yg(n,e,"start",t.first),i=[];let a=0;for(let c=s.length-1;c>=0;c--){let d=t.byChar[s[c]];const h=t.byChar[o[c]]+a;d<h?(a=1,d+=r):a=0;const f=d-h;i.unshift(t.byCode[f])}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]===t.byCode[0];)i.shift();return i.join("")}function aM(n,e){return tb(n,e.byCode[1],e)}function Dw(n,e){return iM(n,e.byCode[1],e)}function lM(n,e){if(n===0)return e.byCode[0];let t="";const r=e.length;for(;n>0;)t=e.byCode[n%r]+t,n=Math.floor(n/r);return t}function N6(n,e){let t=0;const r=n.length,s=e.length;for(let o=0;o<r;o++)t+=e.byChar[n[o]]*Math.pow(s,r-o-1);return t}function $6(n){return n.firstPositive+n.byCode[0]}function z6(n,e){return eb(n,e)===n.length}function Z_(n,e){jf(n,e)}function jf(n,e){const t=dM(n,e),r=eb(t,e);if(r>n.length)throw new Error("invalid order key length: "+n);return n.slice(0,r)}function cM(n,e){if(!z6(n,e))throw new Error("invalid integer length: "+n)}function uM(n,e){cM(n,e);const[t,r]=hM(n,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=aM(r,e);return t+i}const o=U6(t,e);return pM(o,"lower",e)}function B6(n,e){cM(n,e);const[t,r]=hM(n,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Dw(r,e);return t+i}const o=H6(t,e);return pM(o,"upper",e)}function dM(n,e){let t=0;if(n[0]===e.mostPositive)for(;n[t]===e.mostPositive;)t=t+1;if(n[0]===e.mostNegative)for(;n[t]===e.mostNegative;)t=t+1;return n.slice(0,t+1)}function hM(n,e){const t=dM(n,e),r=n.slice(t.length);return[t,r]}function U6(n,e){const t=n>=e.firstPositive,r=aM(n,e),s=n[n.length-1]===e.mostPositive,o=r[r.length-1]===e.mostPositive;return t&&o?r+e.mostNegative:!t&&s?n.slice(0,n.length-1):r}function H6(n,e){const t=n>=e.firstPositive,r=n[n.length-1]===e.mostNegative;if(t&&r){const s=n.slice(0,n.length-1);return Dw(s,e)}return!t&&r?n+e.mostPositive:Dw(n,e)}function pM(n,e,t){const r=eb(n,t),s=e==="upper"?t.byCode[t.length-1]:t.byCode[0];return n+s.repeat(r-n.length)}function fM(n,e){const t=lM(Math.floor(Math.random()*e.jitterRange),e);return tb(n,t,e)}function K6(n,e,t){const r=n.padEnd(n.length+e,t.first);return fM(r,t)}function W6(n,e,t){const r=jf(n,t),s=uM(r,t);let o=0;if(e!==null){const a=Ow(n,e,t);a<t.jitterRange+1&&(o=Math.max(o,Q_(a,t)))}const i=Ow(n,s,t);return i<t.jitterRange+1&&(o=Math.max(o,Q_(i,t))),o}function Q_(n,e){const t=e.jitterRange-n,r=Object.entries(e.paddingDict).find(([s,o])=>o>t);return r?parseInt(r[0]):0}function G6(n,e,t=J0()){if(n!==null&&Z_(n,t),e!==null&&Z_(e,t),n===null&&e===null)return $6(t);if(n===null){const r=jf(e,t);return B6(r,t)}if(e===null){const r=jf(n,t);return uM(r,t)}if(n>=e)throw new Error(n+" >= "+e);return F6(n,e,t)}function gM(n,e,t=J0()){const r=G6(n,e,t),s=W6(r,e,t);return s?K6(r,s,t):fM(r,t)}function mM(n,e,t,r=J0()){return V6(n,e,t,r,gM,mM)}function V6(n,e,t,r,s,o){if(t===0)return[];if(t===1)return[s(n,e,r)];if(e==null){let c=s(n,e,r);const d=[c];for(let h=0;h<t-1;h++)c=s(c,e,r),d.push(c);return d}if(n==null){let c=s(n,e,r);const d=[c];for(let h=0;h<t-1;h++)c=s(n,c,r),d.push(c);return d.reverse(),d}const i=Math.floor(t/2),a=s(n,e,r);return[...o(n,a,i,r),a,...o(a,e,t-i-1,r)]}const zc=mM,yM="a0";function q6(n){try{gM(n,null)}catch{throw new Error("invalid index: "+n)}}function jc(n,e,t){return zc(n??null,e??null,t)}function vS(n,e){return zc(n??null,null,e)}function wd(n,e){return zc(n??null,e??null,1)[0]}function Co(n=null){return zc(n,null,1)[0]}function Y6(n=null){return zc(null,n,1)[0]}function bd(n,e="a1"){return[e,...zc(e,null,n)]}function Wn(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function X6(n,e){return n.id>e.id?1:-1}function nb(n){try{return localStorage.getItem(n)}catch{return null}}function rb(n,e){try{localStorage.setItem(n,e)}catch{}}function Z6(){try{localStorage.clear()}catch{}}function SM(n){try{return sessionStorage.getItem(n)}catch{return null}}function sb(n,e){try{sessionStorage.setItem(n,e)}catch{}}function vM(n){try{sessionStorage.removeItem(n)}catch{}}function Q6(){try{sessionStorage.clear()}catch{}}const yc=[],J6=60,Jp=Math.ceil(1e3/J6);let Fu,xS=0,Lw=0;const ez=()=>{const n=yc.splice(0,yc.length);for(const e of n)e()};function xM(){if(Fu)return;const n=Date.now(),e=n-Lw;if(xS+e<Jp){Fu=requestAnimationFrame(()=>{Fu=void 0,xM()});return}Fu=requestAnimationFrame(()=>{Fu=void 0,Lw=n,xS=Math.min(xS+e-Jp,Jp*10),ez()})}let J_=!1;function wM(n){return yc.includes(n)||(yc.push(n),J_||(J_=!0,Lw=Date.now()-Jp-1),xM()),()=>{const e=yc.indexOf(n);e>-1&&yc.splice(e,1)}}class tz{constructor(){j(this,"timeouts",new Map);j(this,"intervals",new Map);j(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,t,r,...s){const o=window.setTimeout(t,r,s),i=this.timeouts.get(e)??[];return this.timeouts.set(e,[...i,o]),o}setInterval(e,t,r,...s){const o=window.setInterval(t,r,s),i=this.intervals.get(e)??[];return this.intervals.set(e,[...i,o]),o}requestAnimationFrame(e,t){const r=window.requestAnimationFrame(t),s=this.rafs.get(e)??[];return this.rafs.set(e,[...s,r]),r}dispose(e){var t,r,s;(t=this.timeouts.get(e))==null||t.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:(t,r,...s)=>this.setTimeout(e,t,r,s),setInterval:(t,r,...s)=>this.setInterval(e,t,r,s),requestAnimationFrame:t=>this.requestAnimationFrame(e,t),dispose:()=>this.dispose(e)}}}const Ge=(n,e)=>{try{return new URL(n,e)}catch{return}};function nz(n){return n!==void 0}function rz(){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]:[n=>n&&JSON.parse(JSON.stringify(n)),!1]}const bM=rz(),Nt=bM[0];bM[1];const sz=Object.getPrototypeOf(Nt({}));ya("@tldraw/utils","3.8.0-canary.3f23e0d4c913","esm");var eI={},Nu,tI;function or(){if(tI)return Nu;tI=1;var n=function(e){return e&&e.Math===Math&&e};return Nu=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Or=="object"&&Or)||n(typeof Nu=="object"&&Nu)||function(){return this}()||Function("return this")(),Nu}var wS={},bS,nI;function ir(){return nI||(nI=1,bS=function(n){try{return!!n()}catch{return!0}}),bS}var PS,rI;function Sa(){if(rI)return PS;rI=1;var n=ir();return PS=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),PS}var CS,sI;function Sg(){if(sI)return CS;sI=1;var n=ir();return CS=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),CS}var _S,oI;function Pi(){if(oI)return _S;oI=1;var n=Sg(),e=Function.prototype.call;return _S=n?e.bind(e):function(){return e.apply(e,arguments)},_S}var IS={},iI;function oz(){if(iI)return IS;iI=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return IS.f=t?function(s){var o=e(this,s);return!!o&&o.enumerable}:n,IS}var ES,aI;function PM(){return aI||(aI=1,ES=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),ES}var TS,lI;function xn(){if(lI)return TS;lI=1;var n=Sg(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return TS=n?r:function(s){return function(){return t.apply(s,arguments)}},TS}var kS,cI;function Bc(){if(cI)return kS;cI=1;var n=xn(),e=n({}.toString),t=n("".slice);return kS=function(r){return t(e(r),8,-1)},kS}var MS,uI;function iz(){if(uI)return MS;uI=1;var n=xn(),e=ir(),t=Bc(),r=Object,s=n("".split);return MS=e(function(){return!r("z").propertyIsEnumerable(0)})?function(o){return t(o)==="String"?s(o,""):r(o)}:r,MS}var AS,dI;function vg(){return dI||(dI=1,AS=function(n){return n==null}),AS}var jS,hI;function Uc(){if(hI)return jS;hI=1;var n=vg(),e=TypeError;return jS=function(t){if(n(t))throw new e("Can't call method on "+t);return t},jS}var RS,pI;function xg(){if(pI)return RS;pI=1;var n=iz(),e=Uc();return RS=function(t){return n(e(t))},RS}var OS,fI;function ar(){if(fI)return OS;fI=1;var n=typeof document=="object"&&document.all;return OS=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},OS}var DS,gI;function ml(){if(gI)return DS;gI=1;var n=ar();return DS=function(e){return typeof e=="object"?e!==null:n(e)},DS}var LS,mI;function wg(){if(mI)return LS;mI=1;var n=or(),e=ar(),t=function(r){return e(r)?r:void 0};return LS=function(r,s){return arguments.length<2?t(n[r]):n[r]&&n[r][s]},LS}var FS,yI;function CM(){if(yI)return FS;yI=1;var n=xn();return FS=n({}.isPrototypeOf),FS}var NS,SI;function az(){if(SI)return NS;SI=1;var n=or(),e=n.navigator,t=e&&e.userAgent;return NS=t?String(t):"",NS}var $S,vI;function lz(){if(vI)return $S;vI=1;var n=or(),e=az(),t=n.process,r=n.Deno,s=t&&t.versions||r&&r.version,o=s&&s.v8,i,a;return o&&(i=o.split("."),a=i[0]>0&&i[0]<4?1:+(i[0]+i[1])),!a&&e&&(i=e.match(/Edge\/(\d+)/),(!i||i[1]>=74)&&(i=e.match(/Chrome\/(\d+)/),i&&(a=+i[1]))),$S=a,$S}var zS,xI;function _M(){if(xI)return zS;xI=1;var n=lz(),e=ir(),t=or(),r=t.String;return zS=!!Object.getOwnPropertySymbols&&!e(function(){var s=Symbol("symbol detection");return!r(s)||!(Object(s)instanceof Symbol)||!Symbol.sham&&n&&n<41}),zS}var BS,wI;function IM(){if(wI)return BS;wI=1;var n=_M();return BS=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",BS}var US,bI;function EM(){if(bI)return US;bI=1;var n=wg(),e=ar(),t=CM(),r=IM(),s=Object;return US=r?function(o){return typeof o=="symbol"}:function(o){var i=n("Symbol");return e(i)&&t(i.prototype,s(o))},US}var HS,PI;function cz(){if(PI)return HS;PI=1;var n=String;return HS=function(e){try{return n(e)}catch{return"Object"}},HS}var KS,CI;function ob(){if(CI)return KS;CI=1;var n=ar(),e=cz(),t=TypeError;return KS=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},KS}var WS,_I;function ib(){if(_I)return WS;_I=1;var n=ob(),e=vg();return WS=function(t,r){var s=t[r];return e(s)?void 0:n(s)},WS}var GS,II;function uz(){if(II)return GS;II=1;var n=Pi(),e=ar(),t=ml(),r=TypeError;return GS=function(s,o){var i,a;if(o==="string"&&e(i=s.toString)&&!t(a=n(i,s))||e(i=s.valueOf)&&!t(a=n(i,s))||o!=="string"&&e(i=s.toString)&&!t(a=n(i,s)))return a;throw new r("Can't convert object to primitive value")},GS}var VS={exports:{}},qS,EI;function TM(){return EI||(EI=1,qS=!1),qS}var YS,TI;function ab(){if(TI)return YS;TI=1;var n=or(),e=Object.defineProperty;return YS=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},YS}var kI;function lb(){if(kI)return VS.exports;kI=1;var n=TM(),e=or(),t=ab(),r="__core-js_shared__",s=VS.exports=e[r]||t(r,{});return(s.versions||(s.versions=[])).push({version:"3.40.0",mode:n?"pure":"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"}),VS.exports}var XS,MI;function cb(){if(MI)return XS;MI=1;var n=lb();return XS=function(e,t){return n[e]||(n[e]=t||{})},XS}var ZS,AI;function $d(){if(AI)return ZS;AI=1;var n=Uc(),e=Object;return ZS=function(t){return e(n(t))},ZS}var QS,jI;function va(){if(jI)return QS;jI=1;var n=xn(),e=$d(),t=n({}.hasOwnProperty);return QS=Object.hasOwn||function(s,o){return t(e(s),o)},QS}var JS,RI;function kM(){if(RI)return JS;RI=1;var n=xn(),e=0,t=Math.random(),r=n(1 .toString);return JS=function(s){return"Symbol("+(s===void 0?"":s)+")_"+r(++e+t,36)},JS}var ev,OI;function Ci(){if(OI)return ev;OI=1;var n=or(),e=cb(),t=va(),r=kM(),s=_M(),o=IM(),i=n.Symbol,a=e("wks"),c=o?i.for||i:i&&i.withoutSetter||r;return ev=function(d){return t(a,d)||(a[d]=s&&t(i,d)?i[d]:c("Symbol."+d)),a[d]},ev}var tv,DI;function dz(){if(DI)return tv;DI=1;var n=Pi(),e=ml(),t=EM(),r=ib(),s=uz(),o=Ci(),i=TypeError,a=o("toPrimitive");return tv=function(c,d){if(!e(c)||t(c))return c;var h=r(c,a),f;if(h){if(d===void 0&&(d="default"),f=n(h,c,d),!e(f)||t(f))return f;throw new i("Can't convert object to primitive value")}return d===void 0&&(d="number"),s(c,d)},tv}var nv,LI;function MM(){if(LI)return nv;LI=1;var n=dz(),e=EM();return nv=function(t){var r=n(t,"string");return e(r)?r:r+""},nv}var rv,FI;function AM(){if(FI)return rv;FI=1;var n=or(),e=ml(),t=n.document,r=e(t)&&e(t.createElement);return rv=function(s){return r?t.createElement(s):{}},rv}var sv,NI;function jM(){if(NI)return sv;NI=1;var n=Sa(),e=ir(),t=AM();return sv=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),sv}var $I;function RM(){if($I)return wS;$I=1;var n=Sa(),e=Pi(),t=oz(),r=PM(),s=xg(),o=MM(),i=va(),a=jM(),c=Object.getOwnPropertyDescriptor;return wS.f=n?c:function(h,f){if(h=s(h),f=o(f),a)try{return c(h,f)}catch{}if(i(h,f))return r(!e(t.f,h,f),h[f])},wS}var ov={},iv,zI;function OM(){if(zI)return iv;zI=1;var n=Sa(),e=ir();return iv=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),iv}var av,BI;function yl(){if(BI)return av;BI=1;var n=ml(),e=String,t=TypeError;return av=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},av}var UI;function zd(){if(UI)return ov;UI=1;var n=Sa(),e=jM(),t=OM(),r=yl(),s=MM(),o=TypeError,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,c="enumerable",d="configurable",h="writable";return ov.f=n?t?function(g,y,S){if(r(g),y=s(y),r(S),typeof g=="function"&&y==="prototype"&&"value"in S&&h in S&&!S[h]){var v=a(g,y);v&&v[h]&&(g[y]=S.value,S={configurable:d in S?S[d]:v[d],enumerable:c in S?S[c]:v[c],writable:!1})}return i(g,y,S)}:i:function(g,y,S){if(r(g),y=s(y),r(S),e)try{return i(g,y,S)}catch{}if("get"in S||"set"in S)throw new o("Accessors not supported");return"value"in S&&(g[y]=S.value),g},ov}var lv,HI;function ub(){if(HI)return lv;HI=1;var n=Sa(),e=zd(),t=PM();return lv=n?function(r,s,o){return e.f(r,s,t(1,o))}:function(r,s,o){return r[s]=o,r},lv}var cv={exports:{}},uv,KI;function hz(){if(KI)return uv;KI=1;var n=Sa(),e=va(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,s=e(t,"name"),o=s&&(function(){}).name==="something",i=s&&(!n||n&&r(t,"name").configurable);return uv={EXISTS:s,PROPER:o,CONFIGURABLE:i},uv}var dv,WI;function DM(){if(WI)return dv;WI=1;var n=xn(),e=ar(),t=lb(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(s){return r(s)}),dv=t.inspectSource,dv}var hv,GI;function pz(){if(GI)return hv;GI=1;var n=or(),e=ar(),t=n.WeakMap;return hv=e(t)&&/native code/.test(String(t)),hv}var pv,VI;function LM(){if(VI)return pv;VI=1;var n=cb(),e=kM(),t=n("keys");return pv=function(r){return t[r]||(t[r]=e(r))},pv}var fv,qI;function db(){return qI||(qI=1,fv={}),fv}var gv,YI;function FM(){if(YI)return gv;YI=1;var n=pz(),e=or(),t=ml(),r=ub(),s=va(),o=lb(),i=LM(),a=db(),c="Object already initialized",d=e.TypeError,h=e.WeakMap,f,g,y,S=function(P){return y(P)?g(P):f(P,{})},v=function(P){return function(k){var E;if(!t(k)||(E=g(k)).type!==P)throw new d("Incompatible receiver, "+P+" required");return E}};if(n||o.state){var w=o.state||(o.state=new h);w.get=w.get,w.has=w.has,w.set=w.set,f=function(P,k){if(w.has(P))throw new d(c);return k.facade=P,w.set(P,k),k},g=function(P){return w.get(P)||{}},y=function(P){return w.has(P)}}else{var b=i("state");a[b]=!0,f=function(P,k){if(s(P,b))throw new d(c);return k.facade=P,r(P,b,k),k},g=function(P){return s(P,b)?P[b]:{}},y=function(P){return s(P,b)}}return gv={set:f,get:g,has:y,enforce:S,getterFor:v},gv}var XI;function fz(){if(XI)return cv.exports;XI=1;var n=xn(),e=ir(),t=ar(),r=va(),s=Sa(),o=hz().CONFIGURABLE,i=DM(),a=FM(),c=a.enforce,d=a.get,h=String,f=Object.defineProperty,g=n("".slice),y=n("".replace),S=n([].join),v=s&&!e(function(){return f(function(){},"length",{value:8}).length!==8}),w=String(String).split("String"),b=cv.exports=function(P,k,E){g(h(k),0,7)==="Symbol("&&(k="["+y(h(k),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),E&&E.getter&&(k="get "+k),E&&E.setter&&(k="set "+k),(!r(P,"name")||o&&P.name!==k)&&(s?f(P,"name",{value:k,configurable:!0}):P.name=k),v&&E&&r(E,"arity")&&P.length!==E.arity&&f(P,"length",{value:E.arity});try{E&&r(E,"constructor")&&E.constructor?s&&f(P,"prototype",{writable:!1}):P.prototype&&(P.prototype=void 0)}catch{}var M=c(P);return r(M,"source")||(M.source=S(w,typeof k=="string"?k:"")),P};return Function.prototype.toString=b(function(){return t(this)&&d(this).source||i(this)},"toString"),cv.exports}var mv,ZI;function NM(){if(ZI)return mv;ZI=1;var n=ar(),e=zd(),t=fz(),r=ab();return mv=function(s,o,i,a){a||(a={});var c=a.enumerable,d=a.name!==void 0?a.name:o;if(n(i)&&t(i,d,a),a.global)c?s[o]=i:r(o,i);else{try{a.unsafe?s[o]&&(c=!0):delete s[o]}catch{}c?s[o]=i:e.f(s,o,{value:i,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return s},mv}var yv={},Sv,QI;function gz(){if(QI)return Sv;QI=1;var n=Math.ceil,e=Math.floor;return Sv=Math.trunc||function(r){var s=+r;return(s>0?e:n)(s)},Sv}var vv,JI;function Sl(){if(JI)return vv;JI=1;var n=gz();return vv=function(e){var t=+e;return t!==t||t===0?0:n(t)},vv}var xv,eE;function mz(){if(eE)return xv;eE=1;var n=Sl(),e=Math.max,t=Math.min;return xv=function(r,s){var o=n(r);return o<0?e(o+s,0):t(o,s)},xv}var wv,tE;function $M(){if(tE)return wv;tE=1;var n=Sl(),e=Math.min;return wv=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},wv}var bv,nE;function Bd(){if(nE)return bv;nE=1;var n=$M();return bv=function(e){return n(e.length)},bv}var Pv,rE;function yz(){if(rE)return Pv;rE=1;var n=xg(),e=mz(),t=Bd(),r=function(s){return function(o,i,a){var c=n(o),d=t(c);if(d===0)return!s&&-1;var h=e(a,d),f;if(s&&i!==i){for(;d>h;)if(f=c[h++],f!==f)return!0}else for(;d>h;h++)if((s||h in c)&&c[h]===i)return s||h||0;return!s&&-1}};return Pv={includes:r(!0),indexOf:r(!1)},Pv}var Cv,sE;function zM(){if(sE)return Cv;sE=1;var n=xn(),e=va(),t=xg(),r=yz().indexOf,s=db(),o=n([].push);return Cv=function(i,a){var c=t(i),d=0,h=[],f;for(f in c)!e(s,f)&&e(c,f)&&o(h,f);for(;a.length>d;)e(c,f=a[d++])&&(~r(h,f)||o(h,f));return h},Cv}var _v,oE;function hb(){return oE||(oE=1,_v=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),_v}var iE;function Sz(){if(iE)return yv;iE=1;var n=zM(),e=hb(),t=e.concat("length","prototype");return yv.f=Object.getOwnPropertyNames||function(s){return n(s,t)},yv}var Iv={},aE;function vz(){return aE||(aE=1,Iv.f=Object.getOwnPropertySymbols),Iv}var Ev,lE;function xz(){if(lE)return Ev;lE=1;var n=wg(),e=xn(),t=Sz(),r=vz(),s=yl(),o=e([].concat);return Ev=n("Reflect","ownKeys")||function(a){var c=t.f(s(a)),d=r.f;return d?o(c,d(a)):c},Ev}var Tv,cE;function wz(){if(cE)return Tv;cE=1;var n=va(),e=xz(),t=RM(),r=zd();return Tv=function(s,o,i){for(var a=e(o),c=r.f,d=t.f,h=0;h<a.length;h++){var f=a[h];!n(s,f)&&!(i&&n(i,f))&&c(s,f,d(o,f))}},Tv}var kv,uE;function bz(){if(uE)return kv;uE=1;var n=ir(),e=ar(),t=/#|\.prototype\./,r=function(c,d){var h=o[s(c)];return h===a?!0:h===i?!1:e(d)?n(d):!!d},s=r.normalize=function(c){return String(c).replace(t,".").toLowerCase()},o=r.data={},i=r.NATIVE="N",a=r.POLYFILL="P";return kv=r,kv}var Mv,dE;function Hc(){if(dE)return Mv;dE=1;var n=or(),e=RM().f,t=ub(),r=NM(),s=ab(),o=wz(),i=bz();return Mv=function(a,c){var d=a.target,h=a.global,f=a.stat,g,y,S,v,w,b;if(h?y=n:f?y=n[d]||s(d,{}):y=n[d]&&n[d].prototype,y)for(S in c){if(w=c[S],a.dontCallGetSet?(b=e(y,S),v=b&&b.value):v=y[S],g=i(h?S:d+(f?".":"#")+S,a.forced),!g&&v!==void 0){if(typeof w==typeof v)continue;o(w,v)}(a.sham||v&&v.sham)&&t(w,"sham",!0),r(y,S,w,a)}},Mv}var Av={},jv,hE;function Pz(){if(hE)return jv;hE=1;var n=zM(),e=hb();return jv=Object.keys||function(r){return n(r,e)},jv}var pE;function Cz(){if(pE)return Av;pE=1;var n=Sa(),e=OM(),t=zd(),r=yl(),s=xg(),o=Pz();return Av.f=n&&!e?Object.defineProperties:function(a,c){r(a);for(var d=s(c),h=o(c),f=h.length,g=0,y;f>g;)t.f(a,y=h[g++],d[y]);return a},Av}var Rv,fE;function _z(){if(fE)return Rv;fE=1;var n=wg();return Rv=n("document","documentElement"),Rv}var Ov,gE;function BM(){if(gE)return Ov;gE=1;var n=yl(),e=Cz(),t=hb(),r=db(),s=_z(),o=AM(),i=LM(),a=">",c="<",d="prototype",h="script",f=i("IE_PROTO"),g=function(){},y=function(P){return c+h+a+P+c+"/"+h+a},S=function(P){P.write(y("")),P.close();var k=P.parentWindow.Object;return P=null,k},v=function(){var P=o("iframe"),k="java"+h+":",E;return P.style.display="none",s.appendChild(P),P.src=String(k),E=P.contentWindow.document,E.open(),E.write(y("document.F=Object")),E.close(),E.F},w,b=function(){try{w=new ActiveXObject("htmlfile")}catch{}b=typeof document<"u"?document.domain&&w?S(w):v():S(w);for(var P=t.length;P--;)delete b[d][t[P]];return b()};return r[f]=!0,Ov=Object.create||function(k,E){var M;return k!==null?(g[d]=n(k),M=new g,g[d]=null,M[f]=k):M=b(),E===void 0?M:e.f(M,E)},Ov}var Dv,mE;function pb(){if(mE)return Dv;mE=1;var n=Ci(),e=BM(),t=zd().f,r=n("unscopables"),s=Array.prototype;return s[r]===void 0&&t(s,r,{configurable:!0,value:e(null)}),Dv=function(o){s[r][o]=!0},Dv}var yE;function Iz(){if(yE)return eI;yE=1;var n=Hc(),e=$d(),t=Bd(),r=Sl(),s=pb();return n({target:"Array",proto:!0},{at:function(i){var a=e(this),c=t(a),d=r(i),h=d>=0?d:c+d;return h<0||h>=c?void 0:a[h]}}),s("at"),eI}var Lv,SE;function Ud(){if(SE)return Lv;SE=1;var n=or(),e=xn();return Lv=function(t,r){return e(n[t].prototype[r])},Lv}var Fv,vE;function Ez(){if(vE)return Fv;vE=1,Iz();var n=Ud();return Fv=n("Array","at"),Fv}var Nv,xE;function Tz(){if(xE)return Nv;xE=1;var n=Ez();return Nv=n,Nv}Tz();var wE={},$v,bE;function UM(){if(bE)return $v;bE=1;var n=Bc();return $v=Array.isArray||function(t){return n(t)==="Array"},$v}var zv,PE;function kz(){if(PE)return zv;PE=1;var n=TypeError,e=9007199254740991;return zv=function(t){if(t>e)throw n("Maximum allowed index exceeded");return t},zv}var Bv,CE;function Mz(){if(CE)return Bv;CE=1;var n=Bc(),e=xn();return Bv=function(t){if(n(t)==="Function")return e(t)},Bv}var Uv,_E;function Az(){if(_E)return Uv;_E=1;var n=Mz(),e=ob(),t=Sg(),r=n(n.bind);return Uv=function(s,o){return e(s),o===void 0?s:t?r(s,o):function(){return s.apply(o,arguments)}},Uv}var Hv,IE;function HM(){if(IE)return Hv;IE=1;var n=UM(),e=Bd(),t=kz(),r=Az(),s=function(o,i,a,c,d,h,f,g){for(var y=d,S=0,v=f?r(f,g):!1,w,b;S<c;)S in a&&(w=v?v(a[S],S,i):a[S],h>0&&n(w)?(b=e(w),y=s(o,i,w,b,y,h-1)-1):(t(y+1),o[y]=w),y++),S++;return y};return Hv=s,Hv}var Kv,EE;function jz(){if(EE)return Kv;EE=1;var n=Ci(),e=n("toStringTag"),t={};return t[e]="z",Kv=String(t)==="[object z]",Kv}var Wv,TE;function KM(){if(TE)return Wv;TE=1;var n=jz(),e=ar(),t=Bc(),r=Ci(),s=r("toStringTag"),o=Object,i=t(function(){return arguments}())==="Arguments",a=function(c,d){try{return c[d]}catch{}};return Wv=n?t:function(c){var d,h,f;return c===void 0?"Undefined":c===null?"Null":typeof(h=a(d=o(c),s))=="string"?h:i?t(d):(f=t(d))==="Object"&&e(d.callee)?"Arguments":f},Wv}var Gv,kE;function Rz(){if(kE)return Gv;kE=1;var n=xn(),e=ir(),t=ar(),r=KM(),s=wg(),o=DM(),i=function(){},a=s("Reflect","construct"),c=/^\s*(?:class|function)\b/,d=n(c.exec),h=!c.test(i),f=function(S){if(!t(S))return!1;try{return a(i,[],S),!0}catch{return!1}},g=function(S){if(!t(S))return!1;switch(r(S)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return h||!!d(c,o(S))}catch{return!0}};return g.sham=!0,Gv=!a||e(function(){var y;return f(f.call)||!f(Object)||!f(function(){y=!0})||y})?g:f,Gv}var Vv,ME;function Oz(){if(ME)return Vv;ME=1;var n=UM(),e=Rz(),t=ml(),r=Ci(),s=r("species"),o=Array;return Vv=function(i){var a;return n(i)&&(a=i.constructor,e(a)&&(a===o||n(a.prototype))?a=void 0:t(a)&&(a=a[s],a===null&&(a=void 0))),a===void 0?o:a},Vv}var qv,AE;function WM(){if(AE)return qv;AE=1;var n=Oz();return qv=function(e,t){return new(n(e))(t===0?0:t)},qv}var jE;function Dz(){if(jE)return wE;jE=1;var n=Hc(),e=HM(),t=ob(),r=$d(),s=Bd(),o=WM();return n({target:"Array",proto:!0},{flatMap:function(a){var c=r(this),d=s(c),h;return t(a),h=o(c,0),h.length=e(h,c,c,d,0,1,a,arguments.length>1?arguments[1]:void 0),h}}),wE}var RE={},OE;function Lz(){if(OE)return RE;OE=1;var n=pb();return n("flatMap"),RE}var Yv,DE;function Fz(){if(DE)return Yv;DE=1,Dz(),Lz();var n=Ud();return Yv=n("Array","flatMap"),Yv}var Xv,LE;function Nz(){if(LE)return Xv;LE=1;var n=Fz();return Xv=n,Xv}Nz();var FE={},NE;function $z(){if(NE)return FE;NE=1;var n=Hc(),e=HM(),t=$d(),r=Bd(),s=Sl(),o=WM();return n({target:"Array",proto:!0},{flat:function(){var a=arguments.length?arguments[0]:void 0,c=t(this),d=r(c),h=o(c,0);return h.length=e(h,c,c,d,0,a===void 0?1:s(a)),h}}),FE}var $E={},zE;function zz(){if(zE)return $E;zE=1;var n=pb();return n("flat"),$E}var Zv,BE;function Bz(){if(BE)return Zv;BE=1,$z(),zz();var n=Ud();return Zv=n("Array","flat"),Zv}var Qv,UE;function Uz(){if(UE)return Qv;UE=1;var n=Bz();return Qv=n,Qv}Uz();var HE={},Jv,KE;function Hd(){if(KE)return Jv;KE=1;var n=KM(),e=String;return Jv=function(t){if(n(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return e(t)},Jv}var WE;function Hz(){if(WE)return HE;WE=1;var n=Hc(),e=xn(),t=Uc(),r=Sl(),s=Hd(),o=ir(),i=e("".charAt),a=o(function(){return"𠮷".at(-2)!=="\uD842"});return n({target:"String",proto:!0,forced:a},{at:function(d){var h=s(t(this)),f=h.length,g=r(d),y=g>=0?g:f+g;return y<0||y>=f?void 0:i(h,y)}}),HE}var ex,GE;function Kz(){if(GE)return ex;GE=1,Hz();var n=Ud();return ex=n("String","at"),ex}var tx,VE;function Wz(){if(VE)return tx;VE=1;var n=Kz();return tx=n,tx}Wz();var qE={},nx,YE;function GM(){if(YE)return nx;YE=1;var n=yl();return nx=function(){var e=n(this),t="";return e.hasIndices&&(t+="d"),e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.unicodeSets&&(t+="v"),e.sticky&&(t+="y"),t},nx}var rx,XE;function Gz(){if(XE)return rx;XE=1;var n=ir(),e=or(),t=e.RegExp,r=n(function(){var i=t("a","y");return i.lastIndex=2,i.exec("abcd")!==null}),s=r||n(function(){return!t("a","y").sticky}),o=r||n(function(){var i=t("^r","gy");return i.lastIndex=2,i.exec("str")!==null});return rx={BROKEN_CARET:o,MISSED_STICKY:s,UNSUPPORTED_Y:r},rx}var sx,ZE;function Vz(){if(ZE)return sx;ZE=1;var n=ir(),e=or(),t=e.RegExp;return sx=n(function(){var r=t(".","s");return!(r.dotAll&&r.test(`
|
|
68
|
+
`)&&r.flags==="s")}),sx}var ox,QE;function qz(){if(QE)return ox;QE=1;var n=ir(),e=or(),t=e.RegExp;return ox=n(function(){var r=t("(?<a>b)","g");return r.exec("b").groups.a!=="b"||"b".replace(r,"$<a>c")!=="bc"}),ox}var ix,JE;function fb(){if(JE)return ix;JE=1;var n=Pi(),e=xn(),t=Hd(),r=GM(),s=Gz(),o=cb(),i=BM(),a=FM().get,c=Vz(),d=qz(),h=o("native-string-replace",String.prototype.replace),f=RegExp.prototype.exec,g=f,y=e("".charAt),S=e("".indexOf),v=e("".replace),w=e("".slice),b=function(){var M=/a/,A=/b*/g;return n(f,M,"a"),n(f,A,"a"),M.lastIndex!==0||A.lastIndex!==0}(),P=s.BROKEN_CARET,k=/()??/.exec("")[1]!==void 0,E=b||k||P||c||d;return E&&(g=function(A){var R=this,D=a(R),V=t(A),L=D.raw,U,K,F,$,W,Y,Z;if(L)return L.lastIndex=R.lastIndex,U=n(g,L,V),R.lastIndex=L.lastIndex,U;var H=D.groups,Q=P&&R.sticky,ae=n(r,R),B=R.source,ne=0,he=V;if(Q&&(ae=v(ae,"y",""),S(ae,"g")===-1&&(ae+="g"),he=w(V,R.lastIndex),R.lastIndex>0&&(!R.multiline||R.multiline&&y(V,R.lastIndex-1)!==`
|
|
69
|
+
`)&&(B="(?: "+B+")",he=" "+he,ne++),K=new RegExp("^(?:"+B+")",ae)),k&&(K=new RegExp("^"+B+"$(?!\\s)",ae)),b&&(F=R.lastIndex),$=n(f,Q?K:R,he),Q?$?($.input=w($.input,ne),$[0]=w($[0],ne),$.index=R.lastIndex,R.lastIndex+=$[0].length):R.lastIndex=0:b&&$&&(R.lastIndex=R.global?$.index+$[0].length:F),k&&$&&$.length>1&&n(h,$[0],K,function(){for(W=1;W<arguments.length-2;W++)arguments[W]===void 0&&($[W]=void 0)}),$&&H)for($.groups=Y=i(null),W=0;W<H.length;W++)Z=H[W],Y[Z[0]]=$[Z[1]];return $}),ix=g,ix}var e2;function VM(){if(e2)return qE;e2=1;var n=Hc(),e=fb();return n({target:"RegExp",proto:!0,forced:/./.exec!==e},{exec:e}),qE}var t2={},ax,n2;function Yz(){if(n2)return ax;n2=1;var n=Sg(),e=Function.prototype,t=e.apply,r=e.call;return ax=typeof Reflect=="object"&&Reflect.apply||(n?r.bind(t):function(){return r.apply(t,arguments)}),ax}var lx,r2;function Xz(){if(r2)return lx;r2=1,VM();var n=Pi(),e=NM(),t=fb(),r=ir(),s=Ci(),o=ub(),i=s("species"),a=RegExp.prototype;return lx=function(c,d,h,f){var g=s(c),y=!r(function(){var b={};return b[g]=function(){return 7},""[c](b)!==7}),S=y&&!r(function(){var b=!1,P=/a/;return c==="split"&&(P={},P.constructor={},P.constructor[i]=function(){return P},P.flags="",P[g]=/./[g]),P.exec=function(){return b=!0,null},P[g](""),!b});if(!y||!S||h){var v=/./[g],w=d(g,""[c],function(b,P,k,E,M){var A=P.exec;return A===t||A===a.exec?y&&!M?{done:!0,value:n(v,P,k,E)}:{done:!0,value:n(b,k,P,E)}:{done:!1}});e(String.prototype,c,w[0]),e(a,g,w[1])}f&&o(a[g],"sham",!0)},lx}var cx,s2;function Zz(){if(s2)return cx;s2=1;var n=xn(),e=Sl(),t=Hd(),r=Uc(),s=n("".charAt),o=n("".charCodeAt),i=n("".slice),a=function(c){return function(d,h){var f=t(r(d)),g=e(h),y=f.length,S,v;return g<0||g>=y?c?"":void 0:(S=o(f,g),S<55296||S>56319||g+1===y||(v=o(f,g+1))<56320||v>57343?c?s(f,g):S:c?i(f,g,g+2):(S-55296<<10)+(v-56320)+65536)}};return cx={codeAt:a(!1),charAt:a(!0)},cx}var ux,o2;function Qz(){if(o2)return ux;o2=1;var n=Zz().charAt;return ux=function(e,t,r){return t+(r?n(e,t).length:1)},ux}var dx,i2;function qM(){if(i2)return dx;i2=1;var n=xn(),e=$d(),t=Math.floor,r=n("".charAt),s=n("".replace),o=n("".slice),i=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,a=/\$([$&'`]|\d{1,2})/g;return dx=function(c,d,h,f,g,y){var S=h+c.length,v=f.length,w=a;return g!==void 0&&(g=e(g),w=i),s(y,w,function(b,P){var k;switch(r(P,0)){case"$":return"$";case"&":return c;case"`":return o(d,0,h);case"'":return o(d,S);case"<":k=g[o(P,1,-1)];break;default:var E=+P;if(E===0)return b;if(E>v){var M=t(E/10);return M===0?b:M<=v?f[M-1]===void 0?r(P,1):f[M-1]+r(P,1):b}k=f[E-1]}return k===void 0?"":k})},dx}var hx,a2;function Jz(){if(a2)return hx;a2=1;var n=Pi(),e=yl(),t=ar(),r=Bc(),s=fb(),o=TypeError;return hx=function(i,a){var c=i.exec;if(t(c)){var d=n(c,i,a);return d!==null&&e(d),d}if(r(i)==="RegExp")return n(s,i,a);throw new o("RegExp#exec called on incompatible receiver")},hx}var l2;function e8(){if(l2)return t2;l2=1;var n=Yz(),e=Pi(),t=xn(),r=Xz(),s=ir(),o=yl(),i=ar(),a=vg(),c=Sl(),d=$M(),h=Hd(),f=Uc(),g=Qz(),y=ib(),S=qM(),v=Jz(),w=Ci(),b=w("replace"),P=Math.max,k=Math.min,E=t([].concat),M=t([].push),A=t("".indexOf),R=t("".slice),D=function(K){return K===void 0?K:String(K)},V=function(){return"a".replace(/./,"$0")==="$0"}(),L=function(){return/./[b]?/./[b]("a","$0")==="":!1}(),U=!s(function(){var K=/./;return K.exec=function(){var F=[];return F.groups={a:"7"},F},"".replace(K,"$<a>")!=="7"});return r("replace",function(K,F,$){var W=L?"$":"$0";return[function(Z,H){var Q=f(this),ae=a(Z)?void 0:y(Z,b);return ae?e(ae,Z,Q,H):e(F,h(Q),Z,H)},function(Y,Z){var H=o(this),Q=h(Y);if(typeof Z=="string"&&A(Z,W)===-1&&A(Z,"$<")===-1){var ae=$(F,H,Q,Z);if(ae.done)return ae.value}var B=i(Z);B||(Z=h(Z));var ne=H.global,he;ne&&(he=H.unicode,H.lastIndex=0);for(var Pe=[],ue;ue=v(H,Q),!(ue===null||(M(Pe,ue),!ne));){var Fe=h(ue[0]);Fe===""&&(H.lastIndex=g(Q,d(H.lastIndex),he))}for(var Me="",xe=0,Ie=0;Ie<Pe.length;Ie++){ue=Pe[Ie];for(var ze=h(ue[0]),Ze=P(k(c(ue.index),Q.length),0),Xt=[],yt,zt=1;zt<ue.length;zt++)M(Xt,D(ue[zt]));var _t=ue.groups;if(B){var wt=E([ze],Xt,Ze,Q);_t!==void 0&&M(wt,_t),yt=h(n(Z,void 0,wt))}else yt=S(ze,Q,Ze,Xt,_t,Z);Ze>=xe&&(Me+=R(Q,xe,Ze)+yt,xe=Ze+ze.length)}return Me+R(Q,xe)}]},!U||!V||L),t2}var c2={},px,u2;function t8(){if(u2)return px;u2=1;var n=ml(),e=Bc(),t=Ci(),r=t("match");return px=function(s){var o;return n(s)&&((o=s[r])!==void 0?!!o:e(s)==="RegExp")},px}var fx,d2;function n8(){if(d2)return fx;d2=1;var n=Pi(),e=va(),t=CM(),r=GM(),s=RegExp.prototype;return fx=function(o){var i=o.flags;return i===void 0&&!("flags"in s)&&!e(o,"flags")&&t(s,o)?n(r,o):i},fx}var h2;function r8(){if(h2)return c2;h2=1;var n=Hc(),e=Pi(),t=xn(),r=Uc(),s=ar(),o=vg(),i=t8(),a=Hd(),c=ib(),d=n8(),h=qM(),f=Ci(),g=TM(),y=f("replace"),S=TypeError,v=t("".indexOf),w=t("".replace),b=t("".slice),P=Math.max;return n({target:"String",proto:!0},{replaceAll:function(E,M){var A=r(this),R,D,V,L,U,K,F,$,W,Y,Z=0,H="";if(!o(E)){if(R=i(E),R&&(D=a(r(d(E))),!~v(D,"g")))throw new S("`.replaceAll` does not allow non-global regexes");if(V=c(E,y),V)return e(V,E,A,M);if(g&&R)return w(a(A),E,M)}for(L=a(A),U=a(E),K=s(M),K||(M=a(M)),F=U.length,$=P(1,F),W=v(L,U);W!==-1;)Y=K?a(M(U,W,L)):h(U,L,W,[],void 0,M),H+=b(L,Z,W)+Y,Z=W+F,W=W+$>L.length?-1:v(L,U,W+$);return Z<L.length&&(H+=b(L,Z)),H}}),c2}var gx,p2;function s8(){if(p2)return gx;p2=1,VM(),e8(),r8();var n=Ud();return gx=n("String","replaceAll"),gx}var mx,f2;function o8(){if(f2)return mx;f2=1;var n=s8();return mx=n,mx}o8();function YM(n){return n&&typeof n=="object"&&"parents"in n}function XM(n){for(let e=0,t=n.parents.length;e<t;e++)if(n.parents[e].__unsafe__getWithoutCapture(!0),n.parents[e].lastChangedEpoch!==n.parentEpochs[e])return!0;return!1}function Rf(n,e){if(n.children.remove(e)&&n.children.isEmpty&&YM(n))for(let t=0,r=n.parents.length;t<r;t++)Rf(n.parents[t],n)}function gb(n,e){if(n.children.add(e)&&YM(n))for(let t=0,r=n.parents.length;t<r;t++)gb(n.parents[t],n)}function ZM(n,e){return n===e||Object.is(n,e)||!!(n&&e&&typeof n.equals=="function"&&n.equals(e))}function xa(n,e){const t=Symbol.for(`com.tldraw.state/${n}`),r=globalThis;return r[t]??(r[t]=e()),r[t]}const fi=xa("empty_array",()=>Object.freeze([])),g2=8;class Of{constructor(){j(this,"arraySize",0);j(this,"array",Array(g2));j(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<g2?(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 t=this.array.indexOf(e);return t===-1?!1:(this.array[t]=void 0,this.arraySize--,t!==this.arraySize&&(this.array[t]=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 t=0;t<this.arraySize;t++){const r=this.array[t];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 Qr=Symbol.for("com.tldraw.state/RESET_VALUE");class QM{constructor(e){j(this,"index",0);j(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,t,r){if(r!==void 0){if(r===Qr){this.clear();return}this.buffer[this.index]=[e,t,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){const{index:t,capacity:r,buffer:s}=this;for(let o=0;o<r;o++){const i=(t-1+r-o)%r,a=s[i];if(!a)return Qr;const[c,d]=a;if(o===0&&e>=d)return[];if(c<=e&&e<d){const h=o+1,f=new Array(h);for(let g=0;g<h;g++)f[g]=s[(i+g)%r][2];return f}}return Qr}}class i8{constructor(e,t){j(this,"offset",0);j(this,"maybeRemoved");this.below=e,this.child=t}}const Ut=xa("capture",()=>({stack:null}));function mp(n){const e=Ut.stack;Ut.stack=null;try{return n()}finally{Ut.stack=e}}function JM(n){Ut.stack=new i8(Ut.stack,n),n.parentSet.clear()}function eA(){const n=Ut.stack;if(Ut.stack=n.below,n.offset<n.child.parents.length){for(let e=n.offset;e<n.child.parents.length;e++){const t=n.child.parents[e];n.child.parentSet.has(t)||Rf(t,n.child)}n.child.parents.length=n.offset,n.child.parentEpochs.length=n.offset}if(n.maybeRemoved)for(let e=0;e<n.maybeRemoved.length;e++){const t=n.maybeRemoved[e];n.child.parentSet.has(t)||Rf(t,n.child)}}function Df(n){if(Ut.stack){if(Ut.stack.child.parentSet.has(n))return;if(Ut.stack.child.parentSet.add(n),Ut.stack.child.isActivelyListening&&gb(n,Ut.stack.child),Ut.stack.offset<Ut.stack.child.parents.length){const t=Ut.stack.child.parents[Ut.stack.offset];t!==n&&(Ut.stack.maybeRemoved?Ut.stack.maybeRemoved.push(t):Ut.stack.maybeRemoved=[t])}Ut.stack.child.parents[Ut.stack.offset]=n,Ut.stack.child.parentEpochs[Ut.stack.offset]=n.lastChangedEpoch,Ut.stack.offset++}}const oa=-1;class a8{constructor(e,t,r){j(this,"_isActivelyListening",!1);j(this,"lastTraversedEpoch",oa);j(this,"lastReactedEpoch",oa);j(this,"_scheduleCount",0);j(this,"parentSet",new Of);j(this,"parentEpochs",[]);j(this,"parents",[]);j(this,"_scheduleEffect");j(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=e,this.runEffect=t,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==kr()){if(this.parents.length&&!XM(this)){this.lastReactedEpoch=kr();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let e=0,t=this.parents.length;e<t;e++)gb(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,t=this.parents.length;e<t;e++)Rf(this.parents[e],this)}execute(){try{JM(this);const e=kr(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,t}finally{eA()}}}const Kc=xa("EffectScheduler",()=>a8);function To(n,e,t){const r=new Kc(n,e,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function l8(n,e,t){const r=new Kc(n,e,t);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 c8{constructor(e){j(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(gt.globalIsReacting)for(const e of this.initialAtomValues.keys())nA(e);else this.isRoot?tA(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,e)})}abort(){gt.globalEpoch++,this.initialAtomValues.forEach((e,t)=>{var r;t.set(e),(r=t.historyBuffer)==null||r.clear()}),this.commit()}}const gt=xa("transactions",()=>({globalEpoch:oa+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:oa+1}));function u8(){return gt.reactionEpoch}function kr(){return gt.globalEpoch}function d8(){return gt.globalIsReacting}function mb(n,e){e.lastTraversedEpoch!==gt.globalEpoch&&(e.lastTraversedEpoch=gt.globalEpoch,e instanceof Kc?n.add(e):e.children.visit(t=>mb(n,t)))}function tA(n){var t;if(gt.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=gt.currentTransaction;try{gt.currentTransaction=null,gt.globalIsReacting=!0,gt.reactionEpoch=gt.globalEpoch;const r=new Set;for(const o of n)o.children.visit(i=>mb(r,i));for(const o of r)o.maybeScheduleEffect();let s=0;for(;(t=gt.cleanupReactors)!=null&&t.size;){if(s++>1e3)throw new Error("Reaction update depth limit exceeded");const o=gt.cleanupReactors;gt.cleanupReactors=null;for(const i of o)i.maybeScheduleEffect()}}finally{gt.cleanupReactors=null,gt.globalIsReacting=!1,gt.currentTransaction=e}}function h8(n,e){gt.currentTransaction?gt.currentTransaction.initialAtomValues.has(n)||gt.currentTransaction.initialAtomValues.set(n,e):gt.globalIsReacting?nA(n):tA([n])}function nA(n){const e=gt.cleanupReactors??(gt.cleanupReactors=new Set);n.children.visit(t=>mb(e,t))}function p8(){gt.globalEpoch++}function f8(n){const e=new c8(gt.currentTransaction);gt.currentTransaction=e;try{let t,r=!1;try{t=n(()=>r=!0)}catch(s){throw e.abort(),s}return r?e.abort():e.commit(),t}finally{gt.currentTransaction=gt.currentTransaction.parent}}function ko(n){return gt.currentTransaction?n():f8(n)}class g8{constructor(e,t,r){j(this,"isEqual");j(this,"computeDiff");j(this,"lastChangedEpoch",kr());j(this,"children",new Of);j(this,"historyBuffer");this.name=e,this.current=t,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 Df(this),this.current}set(e,t){var s,o;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,e))??ZM(this.current,e))return this.current;p8(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,kr(),t??((o=this.computeDiff)==null?void 0:o.call(this,this.current,e,this.lastChangedEpoch,kr()))??Qr),this.lastChangedEpoch=kr();const r=this.current;return this.current=e,h8(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var t;return Df(this),e>=this.lastChangedEpoch?fi:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??Qr}}const m8=xa("Atom",()=>g8);function dn(n,e,t){return new m8(n,e,t)}let m2=!1;function y8(){m2||(m2=!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 Ju=Symbol.for("com.tldraw.state/UNINITIALIZED");function el(n){return n===Ju}const Fw=xa("WithDiff",()=>class{constructor(e,t){this.value=e,this.diff=t}});function ed(n,e){return new Fw(n,e)}class S8{constructor(e,t,r){j(this,"lastChangedEpoch",oa);j(this,"lastTraversedEpoch",oa);j(this,"lastCheckedEpoch",oa);j(this,"parentSet",new Of);j(this,"parents",[]);j(this,"parentEpochs",[]);j(this,"children",new Of);j(this,"historyBuffer");j(this,"state",Ju);j(this,"error",null);j(this,"computeDiff");j(this,"isEqual");this.name=e,this.derive=t,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 t=this.lastChangedEpoch===oa,r=kr();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&d8()&&this.lastTraversedEpoch<u8()||!XM(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 Fw?o.value:o,a=this.state===Ju;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const c=o instanceof Fw?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,kr(),c??((s=this.computeDiff)==null?void 0:s.call(this,this.state,i,this.lastCheckedEpoch,kr()))??Qr)}this.lastChangedEpoch=kr(),this.state=i}return this.error=null,this.lastCheckedEpoch=kr(),this.state}catch(o){if(this.state!==Ju&&(this.state=Ju,this.lastChangedEpoch=kr()),this.lastCheckedEpoch=kr(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!e)throw o;return this.state}finally{eA()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Df(this)}}getDiffSince(e){var t;return this.__unsafe__getWithoutCapture(!0),Df(this),e>=this.lastChangedEpoch?fi:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??Qr}}const bg=xa("Computed",()=>S8);function v8(n={},e,t,r){const s=r.value,o=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let i=this[o];return i||(i=new bg(t,s.bind(this),n),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[rA]=!0,r}function x8(n={},e,t,r){const s=r.get,o=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let i=this[o];return i||(i=new bg(t,s.bind(this),n),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function w8(n,e,t){mt(t.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(t.name)),s=function(){let o=this[r];return o||(o=new bg(String(t.name),e.bind(this),n),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()};return s[rA]=!0,s}function y2(n={},e){if(e.length===2){const[t,r]=e;return w8(n,t,r)}else{const[t,r,s]=e;return s.get?(y8(),x8(n,t,r,s)):v8(n,t,r,s)}}const rA="@@__isComputedMethod__@@";function le(){if(arguments.length===1){const n=arguments[0];return(...e)=>y2(n,e)}else return typeof arguments[0]=="string"?new bg(arguments[0],arguments[1],arguments[2]):y2(void 0,arguments)}const sA=1,b8=xa("apiVersion",()=>sA);if(b8!==sA)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");ya("@tldraw/state","3.8.0-canary.3f23e0d4c913","esm");function Pg(n,e,t=[]){const r=at.useRef(e);r.current=e;const[s,o,i]=at.useMemo(()=>{let a=null;const c=f=>(a=f,()=>{a=null}),d=new Kc(`useStateTracking(${n})`,()=>{var f;return(f=r.current)==null?void 0:f.call(r)},{scheduleEffect(){a==null||a()}});return[d,c,()=>d.scheduleCount]},[n,...t]);return at.useSyncExternalStore(o,i,i),at.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const S2={apply(n,e,t){return Pg(n.displayName??n.name??"tracked(???)",()=>n.apply(e,t))}},P8=Symbol.for("react.memo"),C8=Symbol.for("react.forward_ref");function jn(n){let e=null;const t=n.$$typeof;return t===P8&&(n=n.type,e=n.compare),t===C8?_.memo(_.forwardRef(new Proxy(n.render,S2))):_.memo(new Proxy(n,S2),e)}function yb(n,e,t){return _.useState(()=>{const r=typeof e=="function"?e():e;return dn(`useAtom(${n})`,r,t)})[0]}function _8(){const n=arguments[0],e=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return _.useMemo(()=>le(`useComputed(${n})`,e,t),r)}function aa(n,e,t=fi){_.useEffect(()=>{const r=new Kc(n,e);return r.attach(),r.execute(),()=>{r.detach()}},t)}function se(){const n=arguments,e=n.length===3?n[2]:[n[0]],t=n.length===3?n[0]:`useValue(${n[0].name})`,r=_.useRef(!0);r.current=!0;const s=_.useMemo(()=>n.length===1?n[0]:le(t,()=>{if(r.current)return n[1]();try{return n[1]()}catch{return{}}}),e);try{const{subscribe:o,getSnapshot:i}=_.useMemo(()=>({subscribe:a=>To(`useValue(${t})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return _.useSyncExternalStore(o,i,i)}finally{r.current=!1}}ya("@tldraw/state-react","3.8.0-canary.3f23e0d4c913","esm");const vn={linear:n=>n,easeInQuad:n=>n*n,easeOutQuad:n=>n*(2-n),easeInOutQuad:n=>n<.5?2*n*n:-1+(4-2*n)*n,easeInCubic:n=>n*n*n,easeOutCubic:n=>--n*n*n+1,easeInOutCubic:n=>n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1,easeInQuart:n=>n*n*n*n,easeOutQuart:n=>1- --n*n*n*n,easeInOutQuart:n=>n<.5?8*n*n*n*n:1-8*--n*n*n*n,easeInQuint:n=>n*n*n*n*n,easeOutQuint:n=>1+--n*n*n*n*n,easeInOutQuint:n=>n<.5?16*n*n*n*n*n:1+16*--n*n*n*n*n,easeInSine:n=>1-Math.cos(n*Math.PI/2),easeOutSine:n=>Math.sin(n*Math.PI/2),easeInOutSine:n=>-(Math.cos(Math.PI*n)-1)/2,easeInExpo:n=>n<=0?0:Math.pow(2,10*n-10),easeOutExpo:n=>n>=1?1:1-Math.pow(2,-10*n),easeInOutExpo:n=>n<=0?0:n>=1?1:n<.5?Math.pow(2,20*n-10)/2:(2-Math.pow(2,-20*n+10))/2};function ht(n){return`${ee(n.x)},${ee(n.y)} `}function jr(n,e){return`${ee((n.x+e.x)/2)},${ee((n.y+e.y)/2)} `}const pt=Math.PI,Rt=pt/2,St=pt*2,I8=Math.sin;function Cn(n,e,t){return Math.max(e,typeof t<"u"?Math.min(n,t):n)}function yp(n,e=1e10){return n?Math.round(n*e)/e:0}function la(n,e,t=1e-6){return Math.abs(n-e)<=t}function oA(n,e){const t=Math.pow(n-e,2)/Math.pow(n+e,2);return pt*(n+e)*(1+3*t/(10+Math.sqrt(4-3*t)))}function tl(n){return n=n%St,n<0?n=n+St:n===0&&(n=0),n}function Kd(n,e){return n=tl(n),e=tl(e),n>e&&(e+=St),e-n}function iA(n,e){return St-Kd(n,e)}function ef(n,e){const t=(e-n)%St;return 2*t%St-t}function Nw(n){return(St+n)%St}function Lf(n,e){const t=St/e;let r=Math.floor((Nw(n)+t/2)/t)*t%St;return r<pt&&(r+=St),r>pt&&(r-=St),r}function aA(n,e){return n===e||la(n%(Math.PI/2)-e%(Math.PI/2),0)}function E8(n){return n*pt/180}function T8(n){return n*180/pt}function sl(n,e,t){return new C(n.x,n.y).add(C.FromAngle(t,e))}function yx(n,e,t){const r=n/2,s=e/2,o=[];let i=1/0,a=-1/0,c=1/0,d=-1/0;for(let S=0;S<t;S++){const v=St/t,w=-Rt+S*v,b=r+r*Math.cos(w),P=s+s*Math.sin(w);b<i&&(i=b),P<c&&(c=P),b>a&&(a=b),P>d&&(d=P),o.push(new C(b,P))}const h=a-i,f=d-c,g=n-h,y=e-f;if(g!==0||y!==0)for(let S=0;S<o.length;S++){const v=o[S];v.x=(v.x-i)/h*n,v.y=(v.y-c)/f*e}return o}function $u(n,e,t,r){return n<r&&t<e}function Hs(n,e,t,r){const s=Math.max(n,t),o=Math.min(e,r);return s<=o?[s,o]:null}function v2(n,e,t){return(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y)}function Jr(n,e){let t=0,r,s;for(let o=0;o<e.length;o++){if(r=e[o],r.x===n.x&&r.y===n.y||(s=e[(o+1)%e.length],C.Dist(n,r)+C.Dist(n,s)===C.Dist(r,s)))return!0;r.y<=n.y?s.y>n.y&&v2(r,s,n)>0&&(t+=1):s.y<=n.y&&v2(r,s,n)<0&&(t-=1)}return t!==0}function ee(n){return Math.round(n*1e4)/1e4}function di(n){return Math.round(n*100)/100}const x2=n=>Math.abs(n)<Number.MAX_SAFE_INTEGER;function na(n,e,t){return t<0?Kd(n,e):iA(n,e)}function $w(n,e,t,r){let s;if(Math.abs(n)>pt){s=ef(e,r);const o=ef(r,t);return Math.abs(s)<Math.abs(o)?s/n:(n-o)/n}else{s=ef(e,r);const o=s/n;return Math.sign(s)!==Math.sign(n)?Math.abs(o)>.5?1:0:o}}function k8(n,e,t,r){const s=2*((e-n)%St)%St-(e-n)%St;return r?(St-Math.abs(s))*(t?1:-1):s}function Sb(n,e,t){const r=-2*(n.x*(e.y-t.y)-n.y*(e.x-t.x)+e.x*t.y-t.x*e.y),s=((n.x*n.x+n.y*n.y)*(t.y-e.y)+(e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y))/r,o=((n.x*n.x+n.y*n.y)*(e.x-t.x)+(e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x))/r;return!Number.isFinite(s)||!Number.isFinite(o)?null:new C(s,o)}function M8(n,e,t,r,s){if(t===null)return[C.From(n),C.From(e)];const o=[],i=C.Angle(t,n),a=C.Angle(t,e),c=Kd(i,a);for(let d=0;d<s;d++){const h=d/(s-1),f=i+c*h,g=sl(t,r,f);o.push(g)}return o}class C{constructor(e=0,t=0,r=1){this.x=e,this.y=t,this.z=r}get pressure(){return this.z}set(e=this.x,t=this.y,r=this.z){return this.x=e,this.y=t,this.z=r,this}setTo({x:e=0,y:t=0,z:r=1}){return this.x=e,this.y=t,this.z=r,this}rot(e){if(e===0)return this;const{x:t,y:r}=this,s=Math.sin(e),o=Math.cos(e);return this.x=t*o-r*s,this.y=t*s+r*o,this}rotWith(e,t){if(t===0)return this;const r=this.x-e.x,s=this.y-e.y,o=Math.sin(t),i=Math.cos(t);return this.x=e.x+(r*i-s*o),this.y=e.y+(r*o+s*i),this}clone(){const{x:e,y:t,z:r}=this;return new C(e,t,r)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,t){return this.x-=e,this.y-=t,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,t){return this.x+=e,this.y+=t,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,t){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),t!==void 0&&(this.x=Math.min(this.x,t),this.y=Math.min(this.y,t)),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,t){const r=C.Tan(e,this);return this.add(r.mul(t))}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 C.Dpr(this,e)}cpr(e){return C.Cpr(this,e)}len2(){return C.Len2(this)}len(){return C.Len(this)}pry(e){return C.Pry(this,e)}per(){const{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){return C.Uni(this)}tan(e){return C.Tan(this,e)}dist(e){return C.Dist(this,e)}distanceToLineSegment(e,t){return C.DistanceToLineSegment(e,t,this)}slope(e){return C.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 C.Angle(this,e)}toAngle(){return C.ToAngle(this)}lrp(e,t){return this.x=this.x+(e.x-this.x)*t,this.y=this.y+(e.y-this.y)*t,this}equals(e){return C.Equals(this,e)}equalsXY(e,t){return C.EqualsXY(this,e,t)}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 C.ToFixed(this)}toString(){return C.ToString(C.ToFixed(this))}toJson(){return C.ToJson(this)}toArray(){return C.ToArray(this)}static Add(e,t){return new C(e.x+t.x,e.y+t.y)}static AddXY(e,t,r){return new C(e.x+t,e.y+r)}static Sub(e,t){return new C(e.x-t.x,e.y-t.y)}static SubXY(e,t,r){return new C(e.x-t,e.y-r)}static AddScalar(e,t){return new C(e.x+t,e.y+t)}static SubScalar(e,t){return new C(e.x-t,e.y-t)}static Div(e,t){return new C(e.x/t,e.y/t)}static Mul(e,t){return new C(e.x*t,e.y*t)}static DivV(e,t){return new C(e.x/t.x,e.y/t.y)}static MulV(e,t){return new C(e.x*t.x,e.y*t.y)}static Neg(e){return new C(-e.x,-e.y)}static Per(e){return new C(e.y,-e.x)}static Abs(e){return new C(Math.abs(e.x),Math.abs(e.y))}static Dist(e,t){return((e.y-t.y)**2+(e.x-t.x)**2)**.5}static DistMin(e,t,r){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)<r**2}static Dist2(e,t){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)}static Dpr(e,t){return e.x*t.x+e.y*t.y}static Cross(e,t){return new C(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z)}static Cpr(e,t){return e.x*t.y-t.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,t){return C.Dpr(e,t)/C.Len(t)}static Uni(e){return C.Div(e,C.Len(e))}static Tan(e,t){return C.Uni(C.Sub(e,t))}static Min(e,t){return new C(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new C(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:r=1}){return new C(e,t,r)}static FromArray(e){return new C(e[0],e[1])}static Rot(e,t=0){const r=Math.sin(t),s=Math.cos(t);return new C(e.x*s-e.y*r,e.x*r+e.y*s)}static RotWith(e,t,r){const s=e.x-t.x,o=e.y-t.y,i=Math.sin(r),a=Math.cos(r);return new C(t.x+(s*a-o*i),t.y+(s*i+o*a))}static NearestPointOnLineThroughPoint(e,t,r){return C.Mul(t,C.Sub(r,e).pry(t)).add(e)}static NearestPointOnLineSegment(e,t,r,s=!0){if(C.Equals(e,r)||C.Equals(t,r))return C.From(r);const o=C.Tan(t,e),i=C.Add(e,C.Mul(o,C.Sub(r,e).pry(o)));if(s){if(i.x<Math.min(e.x,t.x))return C.Cast(e.x<t.x?e:t);if(i.x>Math.max(e.x,t.x))return C.Cast(e.x>t.x?e:t);if(i.y<Math.min(e.y,t.y))return C.Cast(e.y<t.y?e:t);if(i.y>Math.max(e.y,t.y))return C.Cast(e.y>t.y?e:t)}return i}static DistanceToLineThroughPoint(e,t,r){return C.Dist(r,C.NearestPointOnLineThroughPoint(e,t,r))}static DistanceToLineSegment(e,t,r,s=!0){return C.Dist(r,C.NearestPointOnLineSegment(e,t,r,s))}static Snap(e,t=1){return new C(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof C?e:C.From(e)}static Slope(e,t){return e.x===t.y?NaN:(e.y-t.y)/(e.x-t.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static Angle(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}static Lrp(e,t,r){return C.Sub(t,e).mul(r).add(e)}static Med(e,t){return new C((e.x+t.x)/2,(e.y+t.y)/2)}static Equals(e,t){return Math.abs(e.x-t.x)<1e-4&&Math.abs(e.y-t.y)<1e-4}static EqualsXY(e,t,r){return e.x===t&&e.y===r}static Clockwise(e,t,r){return(r.x-e.x)*(t.y-e.y)-(t.x-e.x)*(r.y-e.y)<0}static Rescale(e,t){const r=C.Len(e);return new C(t*e.x/r,t*e.y/r)}static ScaleWithOrigin(e,t,r){return C.Sub(e,r).mul(t).add(r)}static ToFixed(e){return new C(di(e.x),di(e.y))}static ToInt(e){return new C(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,t,r){return C.Add(e,C.Tan(t,e).mul(r))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let t=Math.atan2(e.y,e.x);return t<0&&(t+=Math.PI*2),t}static FromAngle(e,t=1){return new C(Math.cos(e)*t,Math.sin(e)*t)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){const{x:t,y:r,z:s}=e;return{x:t,y:r,z:s}}static Average(e){const t=e.length,r=new C(0,0);if(t===0)return r;for(let s=0;s<t;s++)r.add(e[s]);return r.div(t)}static Clamp(e,t,r){return r===void 0?new C(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new C(Math.min(Math.max(e.x,t),r),Math.min(Math.max(e.y,t),r))}static PointsBetween(e,t,r=6){const s=[];for(let o=0;o<r;o++){const i=vn.easeInQuad(o/(r-1)),a=C.Lrp(e,t,i);a.z=Math.min(1,.5+Math.abs(.5-A8(i))*.65),s.push(a)}return s}static SnapToGrid(e,t=8){return new C(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}const A8=n=>n<.5?2*n*n:-1+(4-2*n)*n;function lA(n,{initialBounds:e,scaleX:t,scaleY:r,newPoint:s,handle:o}){let i;switch(o){case"bottom_left":case"bottom_right":case"top_left":case"top_right":{i=Math.max(.01,Math.max(Math.abs(t),Math.abs(r)));break}case"left":case"right":{i=Math.max(.01,Math.abs(t));break}case"bottom":case"top":{i=Math.max(.01,Math.abs(r));break}default:throw un(o)}const a=new C(0,0);t<0&&(a.x=-(e.width*i)),r<0&&(a.y=-(e.height*i));const{x:c,y:d}=C.Add(s,a.rot(n.rotation));return{x:c,y:d,props:{scale:i*n.props.scale}}}const j8=(n,e)=>e.some(t=>n instanceof t);let w2,b2;function R8(){return w2||(w2=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function O8(){return b2||(b2=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const cA=new WeakMap,zw=new WeakMap,uA=new WeakMap,Sx=new WeakMap,vb=new WeakMap;function D8(n){const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("success",o),n.removeEventListener("error",i)},o=()=>{t(gi(n.result)),s()},i=()=>{r(n.error),s()};n.addEventListener("success",o),n.addEventListener("error",i)});return e.then(t=>{t instanceof IDBCursor&&cA.set(t,n)}).catch(()=>{}),vb.set(e,n),e}function L8(n){if(zw.has(n))return;const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("complete",o),n.removeEventListener("error",i),n.removeEventListener("abort",i)},o=()=>{t(),s()},i=()=>{r(n.error||new DOMException("AbortError","AbortError")),s()};n.addEventListener("complete",o),n.addEventListener("error",i),n.addEventListener("abort",i)});zw.set(n,e)}let Bw={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return zw.get(n);if(e==="objectStoreNames")return n.objectStoreNames||uA.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return gi(n[e])},set(n,e,t){return n[e]=t,!0},has(n,e){return n instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in n}};function F8(n){Bw=n(Bw)}function N8(n){return n===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){const r=n.call(vx(this),e,...t);return uA.set(r,e.sort?e.sort():[e]),gi(r)}:O8().includes(n)?function(...e){return n.apply(vx(this),e),gi(cA.get(this))}:function(...e){return gi(n.apply(vx(this),e))}}function $8(n){return typeof n=="function"?N8(n):(n instanceof IDBTransaction&&L8(n),j8(n,R8())?new Proxy(n,Bw):n)}function gi(n){if(n instanceof IDBRequest)return D8(n);if(Sx.has(n))return Sx.get(n);const e=$8(n);return e!==n&&(Sx.set(n,e),vb.set(e,n)),e}const vx=n=>vb.get(n);function dA(n,e,{blocked:t,upgrade:r,blocking:s,terminated:o}={}){const i=indexedDB.open(n,e),a=gi(i);return r&&i.addEventListener("upgradeneeded",c=>{r(gi(i.result),c.oldVersion,c.newVersion,gi(i.transaction),c)}),t&&i.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),a.then(c=>{o&&c.addEventListener("close",()=>o()),s&&c.addEventListener("versionchange",d=>s(d.oldVersion,d.newVersion,d))}).catch(()=>{}),a}function hA(n,{blocked:e}={}){const t=indexedDB.deleteDatabase(n);return e&&t.addEventListener("blocked",r=>e(r.oldVersion,r)),gi(t).then(()=>{})}const z8=["get","getKey","getAll","getAllKeys","count"],B8=["put","add","delete","clear"],xx=new Map;function P2(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(xx.get(e))return xx.get(e);const t=e.replace(/FromIndex$/,""),r=e!==t,s=B8.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(s||z8.includes(t)))return;const o=async function(i,...a){const c=this.transaction(i,s?"readwrite":"readonly");let d=c.store;return r&&(d=d.index(a.shift())),(await Promise.all([d[t](...a),s&&c.done]))[0]};return xx.set(e,o),o}F8(n=>({...n,get:(e,t,r)=>P2(e,t)||n.get(e,t,r),has:(e,t)=>!!P2(e,t)||n.has(e,t)}));const U8="TLDRAW_DOCUMENT_v2",H8="TLDRAW_ASSET_STORE_v1",pA="TLDRAW_DB_NAME_INDEX_v2",st={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function fA(n){const e=U8+n;return W8(e),await dA(e,4,{upgrade(t){t.objectStoreNames.contains(st.Records)||t.createObjectStore(st.Records),t.objectStoreNames.contains(st.Schema)||t.createObjectStore(st.Schema),t.objectStoreNames.contains(st.SessionState)||t.createObjectStore(st.SessionState),t.objectStoreNames.contains(st.Assets)||t.createObjectStore(st.Assets)}})}async function K8(n){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(g=>g.name):xb(),t=H8+n;if(!e.find(g=>g===t))return;const s=await dA(t,1,{upgrade(g){g.objectStoreNames.contains("assets")||g.createObjectStore("assets")}});if(!s.objectStoreNames.contains("assets"))return;const o=s.transaction(["assets"],"readonly"),i=o.objectStore("assets"),a=await i.getAllKeys(),c=await Promise.all(a.map(async g=>[g,await i.get(g)]));await o.done;const d=await fA(n),h=d.transaction([st.Assets],"readwrite"),f=h.objectStore(st.Assets);for(const[g,y]of c)f.put(y,g);await h.done,s.close(),d.close(),await hA(t)}const Sd=class Sd{constructor(e){j(this,"getDbPromise");j(this,"isClosed",!1);j(this,"pendingTransactionSet",new Set);Sd.connectedInstances.add(this),this.getDbPromise=(async()=>(await K8(e),await fA(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(vd)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),Sd.connectedInstances.delete(this))}tx(e,t,r){const s=(async()=>{mt(!this.isClosed,"db is closed");const i=(await this.getDb()).transaction(t,e),a=i.done.catch(c=>{if(!this.isClosed)throw c});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",[st.Records,st.Schema,st.SessionState],async t=>{var c,d;const r=t.objectStore(st.Records),s=t.objectStore(st.Schema),o=t.objectStore(st.SessionState);let i=e?(c=await o.get(e))==null?void 0:c.snapshot:null;return i||(i=(d=(await o.getAll()).sort((f,g)=>f.updatedAt-g.updatedAt).pop())==null?void 0:d.snapshot),{records:await r.getAll(),schema:await s.get(st.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:t,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[st.Records,st.Schema,st.SessionState],async o=>{const i=o.objectStore(st.Records),a=o.objectStore(st.Schema),c=o.objectStore(st.SessionState);for(const[d,h]of Object.entries(t.added))await i.put(h,d);for(const[d,h]of Object.values(t.updated))await i.put(h,h.id);for(const d of Object.keys(t.removed))await i.delete(d);a.put(e.serialize(),st.Schema),s&&r?c.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:t,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[st.Records,st.Schema,st.SessionState],async o=>{const i=o.objectStore(st.Records),a=o.objectStore(st.Schema),c=o.objectStore(st.SessionState);await i.clear();for(const[d,h]of Object.entries(t))await i.put(h,d);a.put(e.serialize(),st.Schema),s&&r?c.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",[st.SessionState],async e=>{const t=e.objectStore(st.SessionState),r=(await t.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 t.delete(o)})}async getAsset(e){return await this.tx("readonly",[st.Assets],async t=>await t.objectStore(st.Assets).get(e))}async storeAsset(e,t){await this.tx("readwrite",[st.Assets],async r=>{await r.objectStore(st.Assets).put(t,e)})}};j(Sd,"connectedInstances",new Set);let Ff=Sd;function xb(){const n=JSON.parse(nb(pA)||"[]")??[];return Array.isArray(n)?n:[]}function W8(n){const e=new Set(xb());e.add(n),rb(pA,JSON.stringify([...e]))}class tf{constructor(e){j(this,"nextValue");j(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,t=((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.size)??0;if(!(e===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(e,t){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(e),this.diff??(this.diff={}),t?(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 t=this.previousValue.has(e);if(t)return((o=(s=this.diff)==null?void 0:s.removed)==null?void 0:o.has(e))?this._add(e,t):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,t)}_remove(e,t){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(e),this.diff??(this.diff={}),t?((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 t=this.previousValue.has(e);if(!t)return((o=(s=this.diff)==null?void 0:s.added)==null?void 0:o.has(e))?this._remove(e,t):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(e)||this._remove(e,t)}}class Cg{constructor(e,t){j(this,"createDefaultProperties");j(this,"validator");j(this,"ephemeralKeys");j(this,"ephemeralKeySet");j(this,"scope");this.typeName=e,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:s=>s},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const r=new Set;if(t.ephemeralKeys)for(const[s,o]of Lr(t.ephemeralKeys))o&&r.add(s);this.ephemeralKeySet=r}create(e){const t={...this.createDefaultProperties(),id:this.createId()};for(const[r,s]of Object.entries(e))s!==void 0&&(t[r]=s);return t.typeName=this.typeName,t}clone(e){return{...Nt(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??xt())}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 t=0;t<this.typeName.length;t++)if(e[t]!==this.typeName[t])return!1;return e[this.typeName.length]===":"}withDefaultProperties(e){return new Cg(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,t){return t&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(t,e):this.validator.validate(e)}}function zo(n,e){return new Cg(n,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function Nf(){return{added:{},updated:{},removed:{}}}function Uw(n){const e={added:n.removed,removed:n.added,updated:{}};for(const[t,r]of Object.values(n.updated))e.updated[t.id]=[r,t];return e}function gA(n){return Object.keys(n.added).length===0&&Object.keys(n.updated).length===0&&Object.keys(n.removed).length===0}function wb(n){const e={added:{},removed:{},updated:{}};return ud(e,n),e}function ud(n,e){for(const t of e){for(const[r,s]of Lr(t.added))if(n.removed[r]){const o=n.removed[r];delete n.removed[r],o!==s&&(n.updated[r]=[o,s])}else n.added[r]=s;for(const[r,[s,o]]of Lr(t.updated)){if(n.added[r]){n.added[r]=o,delete n.updated[r],delete n.removed[r];continue}if(n.updated[r]){n.updated[r]=[n.updated[r][0],o],delete n.removed[r];continue}n.updated[r]=t.updated[r],delete n.removed[r]}for(const[r,s]of Lr(t.removed))n.added[r]?delete n.added[r]:n.updated[r]?(n.removed[r]=n.updated[r][0],delete n.updated[r]):n.removed[r]=s}}var td={exports:{}};td.exports;var C2;function G8(){return C2||(C2=1,function(n,e){var t=200,r="__lodash_hash_undefined__",s=1,o=2,i=9007199254740991,a="[object Arguments]",c="[object Array]",d="[object AsyncFunction]",h="[object Boolean]",f="[object Date]",g="[object Error]",y="[object Function]",S="[object GeneratorFunction]",v="[object Map]",w="[object Number]",b="[object Null]",P="[object Object]",k="[object Promise]",E="[object Proxy]",M="[object RegExp]",A="[object Set]",R="[object String]",D="[object Symbol]",V="[object Undefined]",L="[object WeakMap]",U="[object ArrayBuffer]",K="[object DataView]",F="[object Float32Array]",$="[object Float64Array]",W="[object Int8Array]",Y="[object Int16Array]",Z="[object Int32Array]",H="[object Uint8Array]",Q="[object Uint8ClampedArray]",ae="[object Uint16Array]",B="[object Uint32Array]",ne=/[\\^$.*+?()[\]{}|]/g,he=/^\[object .+?Constructor\]$/,Pe=/^(?:0|[1-9]\d*)$/,ue={};ue[F]=ue[$]=ue[W]=ue[Y]=ue[Z]=ue[H]=ue[Q]=ue[ae]=ue[B]=!0,ue[a]=ue[c]=ue[U]=ue[h]=ue[K]=ue[f]=ue[g]=ue[y]=ue[v]=ue[w]=ue[P]=ue[M]=ue[A]=ue[R]=ue[L]=!1;var Fe=typeof Or=="object"&&Or&&Or.Object===Object&&Or,Me=typeof self=="object"&&self&&self.Object===Object&&self,xe=Fe||Me||Function("return this")(),Ie=e&&!e.nodeType&&e,ze=Ie&&!0&&n&&!n.nodeType&&n,Ze=ze&&ze.exports===Ie,Xt=Ze&&Fe.process,yt=function(){try{return Xt&&Xt.binding&&Xt.binding("util")}catch{}}(),zt=yt&&yt.isTypedArray;function _t(N,X){for(var de=-1,Te=N==null?0:N.length,vt=0,qe=[];++de<Te;){var kt=N[de];X(kt,de,N)&&(qe[vt++]=kt)}return qe}function wt(N,X){for(var de=-1,Te=X.length,vt=N.length;++de<Te;)N[vt+de]=X[de];return N}function hr(N,X){for(var de=-1,Te=N==null?0:N.length;++de<Te;)if(X(N[de],de,N))return!0;return!1}function pr(N,X){for(var de=-1,Te=Array(N);++de<N;)Te[de]=X(de);return Te}function fr(N){return function(X){return N(X)}}function gr(N,X){return N.has(X)}function ls(N,X){return N==null?void 0:N[X]}function Ta(N){var X=-1,de=Array(N.size);return N.forEach(function(Te,vt){de[++X]=[vt,Te]}),de}function bl(N,X){return function(de){return N(X(de))}}function Pl(N){var X=-1,de=Array(N.size);return N.forEach(function(Te){de[++X]=Te}),de}var Cl=Array.prototype,_l=Function.prototype,oo=Object.prototype,As=xe["__core-js_shared__"],ka=_l.toString,ie=oo.hasOwnProperty,ve=function(){var N=/[^.]+$/.exec(As&&As.keys&&As.keys.IE_PROTO||"");return N?"Symbol(src)_1."+N:""}(),Ke=oo.toString,bt=RegExp("^"+ka.call(ie).replace(ne,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),cs=Ze?xe.Buffer:void 0,mr=xe.Symbol,Wo=xe.Uint8Array,Br=oo.propertyIsEnumerable,Ur=Cl.splice,yr=mr?mr.toStringTag:void 0,Hr=Object.getOwnPropertySymbols,Sr=cs?cs.isBuffer:void 0,js=bl(Object.keys,Object),Il=qo(xe,"DataView"),ki=qo(xe,"Map"),El=qo(xe,"Promise"),Tl=qo(xe,"Set"),kl=qo(xe,"WeakMap"),Go=qo(Object,"create"),dh=Dn(Il),Ma=Dn(ki),nu=Dn(El),Aa=Dn(Tl),Cm=Dn(kl),Mi=mr?mr.prototype:void 0,Ai=Mi?Mi.valueOf:void 0;function us(N){var X=-1,de=N==null?0:N.length;for(this.clear();++X<de;){var Te=N[X];this.set(Te[0],Te[1])}}function ru(){this.__data__=Go?Go(null):{},this.size=0}function _m(N){var X=this.has(N)&&delete this.__data__[N];return this.size-=X?1:0,X}function Im(N){var X=this.__data__;if(Go){var de=X[N];return de===r?void 0:de}return ie.call(X,N)?X[N]:void 0}function Em(N){var X=this.__data__;return Go?X[N]!==void 0:ie.call(X,N)}function Vo(N,X){var de=this.__data__;return this.size+=this.has(N)?0:1,de[N]=Go&&X===void 0?r:X,this}us.prototype.clear=ru,us.prototype.delete=_m,us.prototype.get=Im,us.prototype.has=Em,us.prototype.set=Vo;function ds(N){var X=-1,de=N==null?0:N.length;for(this.clear();++X<de;){var Te=N[X];this.set(Te[0],Te[1])}}function hh(){this.__data__=[],this.size=0}function Tm(N){var X=this.__data__,de=jl(X,N);if(de<0)return!1;var Te=X.length-1;return de==Te?X.pop():Ur.call(X,de,1),--this.size,!0}function ph(N){var X=this.__data__,de=jl(X,N);return de<0?void 0:X[de][1]}function fh(N){return jl(this.__data__,N)>-1}function gh(N,X){var de=this.__data__,Te=jl(de,N);return Te<0?(++this.size,de.push([N,X])):de[Te][1]=X,this}ds.prototype.clear=hh,ds.prototype.delete=Tm,ds.prototype.get=ph,ds.prototype.has=fh,ds.prototype.set=gh;function io(N){var X=-1,de=N==null?0:N.length;for(this.clear();++X<de;){var Te=N[X];this.set(Te[0],Te[1])}}function km(){this.size=0,this.__data__={hash:new us,map:new(ki||ds),string:new us}}function Mm(N){var X=ct(this,N).delete(N);return this.size-=X?1:0,X}function Kt(N){return ct(this,N).get(N)}function Am(N){return ct(this,N).has(N)}function su(N,X){var de=ct(this,N),Te=de.size;return de.set(N,X),this.size+=de.size==Te?0:1,this}io.prototype.clear=km,io.prototype.delete=Mm,io.prototype.get=Kt,io.prototype.has=Am,io.prototype.set=su;function ja(N){var X=-1,de=N==null?0:N.length;for(this.__data__=new io;++X<de;)this.add(N[X])}function Ml(N){return this.__data__.set(N,r),this}function jm(N){return this.__data__.has(N)}ja.prototype.add=ja.prototype.push=Ml,ja.prototype.has=jm;function Rs(N){var X=this.__data__=new ds(N);this.size=X.size}function Al(){this.__data__=new ds,this.size=0}function hs(N){var X=this.__data__,de=X.delete(N);return this.size=X.size,de}function Rm(N){return this.__data__.get(N)}function Kr(N){return this.__data__.has(N)}function Om(N,X){var de=this.__data__;if(de instanceof ds){var Te=de.__data__;if(!ki||Te.length<t-1)return Te.push([N,X]),this.size=++de.size,this;de=this.__data__=new io(Te)}return de.set(N,X),this.size=de.size,this}Rs.prototype.clear=Al,Rs.prototype.delete=hs,Rs.prototype.get=Rm,Rs.prototype.has=Kr,Rs.prototype.set=Om;function Dm(N,X){var de=co(N),Te=!de&&Da(N),vt=!de&&!Te&&lu(N),qe=!de&&!Te&&!vt&&uu(N),kt=de||Te||vt||qe,en=kt?pr(N.length,String):[],Mt=en.length;for(var It in N)ie.call(N,It)&&!(kt&&(It=="length"||vt&&(It=="offset"||It=="parent")||qe&&(It=="buffer"||It=="byteLength"||It=="byteOffset")||Sh(It,Mt)))&&en.push(It);return en}function jl(N,X){for(var de=N.length;de--;)if(Ds(N[de][0],X))return de;return-1}function Rl(N,X,de){var Te=X(N);return co(N)?Te:wt(Te,de(N))}function ao(N){return N==null?N===void 0?V:b:yr&&yr in Object(N)?yh(N):lo(N)}function ji(N){return ho(N)&&ao(N)==a}function Ra(N,X,de,Te,vt){return N===X?!0:N==null||X==null||!ho(N)&&!ho(X)?N!==N&&X!==X:Lm(N,X,de,Te,Ra,vt)}function Lm(N,X,de,Te,vt,qe){var kt=co(N),en=co(X),Mt=kt?c:Os(N),It=en?c:Os(X);Mt=Mt==a?P:Mt,It=It==a?P:It;var gn=Mt==P,vr=It==P,tn=Mt==It;if(tn&&lu(N)){if(!lu(X))return!1;kt=!0,gn=!1}if(tn&&!gn)return qe||(qe=new Rs),kt||uu(N)?Ol(N,X,de,Te,vt,qe):Oa(N,X,Mt,de,Te,vt,qe);if(!(de&s)){var wn=gn&&ie.call(N,"__wrapped__"),Jn=vr&&ie.call(X,"__wrapped__");if(wn||Jn){var Zt=wn?N.value():N,Ln=Jn?X.value():X;return qe||(qe=new Rs),vt(Zt,Ln,de,Te,qe)}}return tn?(qe||(qe=new Rs),Nm(N,X,de,Te,vt,qe)):!1}function Fm(N){if(!cu(N)||au(N))return!1;var X=Ri(N)?bt:he;return X.test(Dn(N))}function ou(N){return ho(N)&&wh(N.length)&&!!ue[ao(N)]}function mh(N){if(!Ll(N))return js(N);var X=[];for(var de in Object(N))ie.call(N,de)&&de!="constructor"&&X.push(de);return X}function Ol(N,X,de,Te,vt,qe){var kt=de&s,en=N.length,Mt=X.length;if(en!=Mt&&!(kt&&Mt>en))return!1;var It=qe.get(N);if(It&&qe.get(X))return It==X;var gn=-1,vr=!0,tn=de&o?new ja:void 0;for(qe.set(N,X),qe.set(X,N);++gn<en;){var wn=N[gn],Jn=X[gn];if(Te)var Zt=kt?Te(Jn,wn,gn,X,N,qe):Te(wn,Jn,gn,N,X,qe);if(Zt!==void 0){if(Zt)continue;vr=!1;break}if(tn){if(!hr(X,function(Ln,Ls){if(!gr(tn,Ls)&&(wn===Ln||vt(wn,Ln,de,Te,qe)))return tn.push(Ls)})){vr=!1;break}}else if(!(wn===Jn||vt(wn,Jn,de,Te,qe))){vr=!1;break}}return qe.delete(N),qe.delete(X),vr}function Oa(N,X,de,Te,vt,qe,kt){switch(de){case K:if(N.byteLength!=X.byteLength||N.byteOffset!=X.byteOffset)return!1;N=N.buffer,X=X.buffer;case U:return!(N.byteLength!=X.byteLength||!qe(new Wo(N),new Wo(X)));case h:case f:case w:return Ds(+N,+X);case g:return N.name==X.name&&N.message==X.message;case M:case R:return N==X+"";case v:var en=Ta;case A:var Mt=Te&s;if(en||(en=Pl),N.size!=X.size&&!Mt)return!1;var It=kt.get(N);if(It)return It==X;Te|=o,kt.set(N,X);var gn=Ol(en(N),en(X),Te,vt,qe,kt);return kt.delete(N),gn;case D:if(Ai)return Ai.call(N)==Ai.call(X)}return!1}function Nm(N,X,de,Te,vt,qe){var kt=de&s,en=Dl(N),Mt=en.length,It=Dl(X),gn=It.length;if(Mt!=gn&&!kt)return!1;for(var vr=Mt;vr--;){var tn=en[vr];if(!(kt?tn in X:ie.call(X,tn)))return!1}var wn=qe.get(N);if(wn&&qe.get(X))return wn==X;var Jn=!0;qe.set(N,X),qe.set(X,N);for(var Zt=kt;++vr<Mt;){tn=en[vr];var Ln=N[tn],Ls=X[tn];if(Te)var Oi=kt?Te(Ls,Ln,tn,X,N,qe):Te(Ln,Ls,tn,N,X,qe);if(!(Oi===void 0?Ln===Ls||vt(Ln,Ls,de,Te,qe):Oi)){Jn=!1;break}Zt||(Zt=tn=="constructor")}if(Jn&&!Zt){var Fl=N.constructor,Di=X.constructor;Fl!=Di&&"constructor"in N&&"constructor"in X&&!(typeof Fl=="function"&&Fl instanceof Fl&&typeof Di=="function"&&Di instanceof Di)&&(Jn=!1)}return qe.delete(N),qe.delete(X),Jn}function Dl(N){return Rl(N,$m,iu)}function ct(N,X){var de=N.__data__;return vh(X)?de[typeof X=="string"?"string":"hash"]:de.map}function qo(N,X){var de=ls(N,X);return Fm(de)?de:void 0}function yh(N){var X=ie.call(N,yr),de=N[yr];try{N[yr]=void 0;var Te=!0}catch{}var vt=Ke.call(N);return Te&&(X?N[yr]=de:delete N[yr]),vt}var iu=Hr?function(N){return N==null?[]:(N=Object(N),_t(Hr(N),function(X){return Br.call(N,X)}))}:La,Os=ao;(Il&&Os(new Il(new ArrayBuffer(1)))!=K||ki&&Os(new ki)!=v||El&&Os(El.resolve())!=k||Tl&&Os(new Tl)!=A||kl&&Os(new kl)!=L)&&(Os=function(N){var X=ao(N),de=X==P?N.constructor:void 0,Te=de?Dn(de):"";if(Te)switch(Te){case dh:return K;case Ma:return v;case nu:return k;case Aa:return A;case Cm:return L}return X});function Sh(N,X){return X=X??i,!!X&&(typeof N=="number"||Pe.test(N))&&N>-1&&N%1==0&&N<X}function vh(N){var X=typeof N;return X=="string"||X=="number"||X=="symbol"||X=="boolean"?N!=="__proto__":N===null}function au(N){return!!ve&&ve in N}function Ll(N){var X=N&&N.constructor,de=typeof X=="function"&&X.prototype||oo;return N===de}function lo(N){return Ke.call(N)}function Dn(N){if(N!=null){try{return ka.call(N)}catch{}try{return N+""}catch{}}return""}function Ds(N,X){return N===X||N!==N&&X!==X}var Da=ji(function(){return arguments}())?ji:function(N){return ho(N)&&ie.call(N,"callee")&&!Br.call(N,"callee")},co=Array.isArray;function uo(N){return N!=null&&wh(N.length)&&!Ri(N)}var lu=Sr||Fa;function xh(N,X){return Ra(N,X)}function Ri(N){if(!cu(N))return!1;var X=ao(N);return X==y||X==S||X==d||X==E}function wh(N){return typeof N=="number"&&N>-1&&N%1==0&&N<=i}function cu(N){var X=typeof N;return N!=null&&(X=="object"||X=="function")}function ho(N){return N!=null&&typeof N=="object"}var uu=zt?fr(zt):ou;function $m(N){return uo(N)?Dm(N):mh(N)}function La(){return[]}function Fa(){return!1}n.exports=xh}(td,td.exports)),td.exports}var V8=G8();const mA=bi(V8);function q8(n){if(n.length===0)return new Set;const e=n[0],t=n.slice(1),r=new Set;for(const s of e)t.every(o=>o.has(s))&&r.add(s);return r}function Y8(n,e){const t={};for(const r of e)n.has(r)||(t.added??(t.added=new Set),t.added.add(r));for(const r of n)e.has(r)||(t.removed??(t.removed=new Set),t.removed.add(r));return t.added||t.removed?t:void 0}function _2(n,e){for(const[t,r]of Object.entries(n)){const s=r,o=e[t];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 I2(n,e,t){const r=Object.fromEntries(Object.keys(t).map(s=>[s,new Set]));for(const[s,o]of Object.entries(t))if("eq"in o){const a=n.index(e,s).get().get(o.eq);if(a)for(const c of a)r[s].add(c)}else if("neq"in o){const i=n.index(e,s);for(const[a,c]of i.get())if(a!==o.neq)for(const d of c)r[s].add(d)}else if("gt"in o){const i=n.index(e,s);for(const[a,c]of i.get())if(a>o.gt)for(const d of c)r[s].add(d)}return q8(Object.values(r))}class X8{constructor(e,t){j(this,"indexCache",new Map);j(this,"historyCache",new Map);this.atoms=e,this.history=t}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const t=le("filterHistory:"+e,(r,s)=>{if(el(r))return this.history.get();const o=this.history.getDiffSince(s);if(o===Qr)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,c=0,d=0;for(const h of o){for(const f of Vt(h.added))if(f.typeName===e)if(i.removed[f.id]){const g=i.removed[f.id];delete i.removed[f.id],c--,g!==f&&(i.updated[f.id]=[g,f],d++)}else i.added[f.id]=f,a++;for(const[f,g]of Vt(h.updated))g.typeName===e&&(i.added[g.id]?i.added[g.id]=g:i.updated[g.id]?i.updated[g.id]=[i.updated[g.id][0],g]:(i.updated[g.id]=[f,g],d++));for(const f of Vt(h.removed))f.typeName===e&&(i.added[f.id]?(delete i.added[f.id],a--):i.updated[f.id]?(i.removed[f.id]=i.updated[f.id][0],delete i.updated[f.id],d--,c++):(i.removed[f.id]=f,c++))}return a||c||d?ed(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(e,t),t}index(e,t){const r=e+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const s=this.__uncached_createIndex(e,t);return this.indexCache.set(r,s),s}__uncached_createIndex(e,t){const r=this.filterHistory(e),s=()=>{r.get();const o=new Map;for(const i of Vt(this.atoms.get())){const a=i.get();if(a.typeName===e){const c=a[t];o.has(c)||o.set(c,new Set),o.get(c).add(a.id)}}return o};return le("index:"+e+":"+t,(o,i)=>{if(el(o))return s();const a=r.getDiffSince(i);if(a===Qr)return s();const c=new Map,d=(y,S)=>{let v=c.get(y);v||(v=new tf(o.get(y)??new Set)),v.add(S),c.set(y,v)},h=(y,S)=>{let v=c.get(y);v||(v=new tf(o.get(y)??new Set)),v.remove(S),c.set(y,v)};for(const y of a){for(const S of Vt(y.added))if(S.typeName===e){const v=S[t];d(v,S.id)}for(const[S,v]of Vt(y.updated))if(v.typeName===e){const w=S[t],b=v[t];w!==b&&(h(w,v.id),d(b,v.id))}for(const S of Vt(y.removed))if(S.typeName===e){const v=S[t];h(v,S.id)}}let f,g;for(const[y,S]of c){const v=S.get();v&&(f||(f=new Map(o)),g||(g=new Map),v.value.size===0?f.delete(y):f.set(y,v.value),g.set(y,v.diff))}return f&&g?ed(f,g):o},{historyLength:100})}record(e,t=()=>({}),r="record:"+e+(t?":"+t.toString():"")){const s=this.ids(e,t,r);return le(r,()=>{var o;for(const i of s.get())return(o=this.atoms.get()[i])==null?void 0:o.get()})}records(e,t=()=>({}),r="records:"+e+(t?":"+t.toString():"")){const s=this.ids(e,t,"ids:"+r);return le(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:eM})}ids(e,t=()=>({}),r="ids:"+e+(t?":"+t.toString():"")){const s=this.filterHistory(e),o=()=>{s.get();const c=t();return Object.keys(c).length===0?new Set(Vt(this.atoms.get()).flatMap(d=>{const h=d.get();return h.typeName===e?h.id:[]})):I2(this,e,c)},i=c=>{const d=o(),h=Y8(c,d);return h?ed(d,h):c},a=le("ids_query:"+r,t,{isEqual:mA});return le("query:"+r,(c,d)=>{const h=a.get();if(el(c))return o();if(d<a.lastChangedEpoch)return i(c);const f=s.getDiffSince(d);if(f===Qr)return i(c);const g=new tf(c);for(const S of f){for(const v of Vt(S.added))v.typeName===e&&_2(h,v)&&g.add(v.id);for(const[v,w]of Vt(S.updated))w.typeName===e&&(_2(h,w)?g.add(w.id):g.remove(w.id));for(const v of Vt(S.removed))v.typeName===e&&g.remove(v.id)}const y=g.get();return y?ed(y.value,y.diff):c},{historyLength:50})}exec(e,t){const r=I2(this,e,t);if(r.size===0)return fi;const s=this.atoms.get();return[...r].map(o=>s[o].get())}}class Z8{constructor(e){j(this,"_beforeCreateHandlers",{});j(this,"_afterCreateHandlers",{});j(this,"_beforeChangeHandlers",{});j(this,"_afterChangeHandlers",{});j(this,"_beforeDeleteHandlers",{});j(this,"_afterDeleteHandlers",{});j(this,"_operationCompleteHandlers",[]);j(this,"_isEnabled",!0);this.store=e}isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,t){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let s=e;for(const o of r)s=o(s,t);return s}return e}handleAfterCreate(e,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const s of r)s(e,t)}handleBeforeChange(e,t,r){if(!this._isEnabled)return t;const s=this._beforeChangeHandlers[t.typeName];if(s){let o=t;for(const i of s)o=i(e,o,r);return o}return t}handleAfterChange(e,t,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[t.typeName];if(s)for(const o of s)o(e,t,r)}handleBeforeDelete(e,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const s of r)if(s(e,t)===!1)return!1}return!0}handleAfterDelete(e,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const s of r)s(e,t)}handleOperationComplete(e){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(e)}register(e){const t=[];for(const[r,s]of Object.entries(e))s!=null&&s.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,s.beforeCreate)),s!=null&&s.afterCreate&&t.push(this.registerAfterCreateHandler(r,s.afterCreate)),s!=null&&s.beforeChange&&t.push(this.registerBeforeChangeHandler(r,s.beforeChange)),s!=null&&s.afterChange&&t.push(this.registerAfterChangeHandler(r,s.afterChange)),s!=null&&s.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,s.beforeDelete)),s!=null&&s.afterDelete&&t.push(this.registerAfterDeleteHandler(r,s.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(e,t){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(t),()=>Xa(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>Xa(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>Xa(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>Xa(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>Xa(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>Xa(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Xa(this._operationCompleteHandlers,e)}}function Xa(n,e){const t=n.indexOf(e);t>=0&&n.splice(t,1)}class bb{constructor(e){j(this,"id");j(this,"atoms",dn("store_atoms",{}));j(this,"history",dn("history",0,{historyLength:1e3}));j(this,"query",new X8(this.atoms,this.history));j(this,"listeners",new Set);j(this,"historyAccumulator",new J8);j(this,"historyReactor");j(this,"schema");j(this,"props");j(this,"scopedTypes");j(this,"sideEffects",new Z8(this));j(this,"isMergingRemoteChanges",!1);j(this,"_integrityChecker");j(this,"_isPossiblyCorrupted",!1);j(this,"pendingAfterEvents",null);j(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:s}=e;this.id=s??xt(),this.schema=r,this.props=e.props,t&&this.atoms.set(Q0(Lr(t).map(([o,i])=>[o,dn("atom:"+o,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=l8("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>this.cancelHistoryReactor=wM(o)}),this.scopedTypes={document:new Set(Vt(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(Vt(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(Vt(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:t,source:r}of e){let s=null,o=null,i=null;for(const{onHistory:a,filters:c}of this.listeners)if(!(c.source!=="all"&&c.source!==r))if(c.scope!=="all")if(c.scope==="document"){if(o??(o=this.filterChangesByScope(t,"document")),!o)continue;a({changes:o,source:r})}else if(c.scope==="session"){if(s??(s=this.filterChangesByScope(t,"session")),!s)continue;a({changes:s,source:r})}else{if(i??(i=this.filterChangesByScope(t,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,t){const r={added:cd(e.added,(s,o)=>this.scopedTypes[t].has(o.typeName)),updated:cd(e.updated,(s,o)=>this.scopedTypes[t].has(o[1].typeName)),removed:cd(e.removed,(s,o)=>this.scopedTypes[t].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(t=>this.schema.validateRecord(this,t,e,null))}put(e,t){this.atomic(()=>{const r={},s={},o=this.atoms.__unsafe__getWithoutCapture();let i=null,a,c=!1;const d=this.isMergingRemoteChanges?"remote":"user";for(let h=0,f=e.length;h<f;h++){a=e[h];const g=(i??o)[a.id];if(g){const y=g.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(y,a,d),this.schema.validateRecord(this,a,t??"updateRecord",y)===y)continue;g.set(a),c=!0;const v=g.__unsafe__getWithoutCapture();r[a.id]=[y,v],this.addDiffForAfterEvent(y,v)}else a=this.sideEffects.handleBeforeCreate(a,d),c=!0,a=this.schema.validateRecord(this,a,t??"createRecord",null),s[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...o}),i[a.id]=dn("atom:"+a.id,a)}i&&this.atoms.set(i),c&&this.updateHistory({added:s,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const t=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&&t.add(o)}let s;this.atoms.update(o=>{let i;for(const a of e){if(t.has(a)||!(a in o))continue;i||(i={...o}),s||(s={}),delete i[a];const c=o[a].get();s[a]=c,this.addDiffForAfterEvent(c,null)}return i??o}),s&&this.updateHistory({added:{},updated:{},removed:s})})}get(e){var t;return(t=this.atoms.get()[e])==null?void 0:t.get()}unsafeGetWithoutCapture(e){var t;return(t=this.atoms.__unsafe__getWithoutCapture()[e])==null?void 0:t.__unsafe__getWithoutCapture()}serialize(e="document"){const t={};for(const[r,s]of Lr(this.atoms.get())){const o=s.get();(e==="all"||this.scopedTypes[e].has(o.typeName))&&(t[r]=o)}return t}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 t=this.schema.migrateStoreSnapshot(e);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){const t=this.schema.migrateStoreSnapshot(e);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.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 Vt(this.atoms.get()).map(e=>e.get())}clear(){this.remove(X_(this.atoms.get()))}update(e,t){const r=this.atoms.get()[e];if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([t(r.__unsafe__getWithoutCapture())])}has(e){return!!this.atoms.get()[e]}listen(e,t){this._flushHistory();const r={onHistory:e,filters:{source:(t==null?void 0:t.source)??"all",scope:(t==null?void 0:t.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,ko(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const t=[],r=this.historyAccumulator.addInterceptor(s=>t.push(s.changes));try{return ko(e),wb(t)}finally{r()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=Vt(e.added);for(const[i,a]of Vt(e.updated)){const c=this.schema.getType(a.typeName);if(r&&c.ephemeralKeySet.size){const d=this.get(a.id);if(!d){s.push(a);continue}let h=null;for(const[f,g]of Object.entries(a))c.ephemeralKeySet.has(f)||Object.is(g,Vn(d,f))||(h||(h={...d}),h[f]=g);h&&s.push(h)}else s.push(a)}const o=X_(e.removed);s.length&&this.put(s),o.length&&this.remove(o)},t)}createComputedCache(e,t,r){const s=new Ao;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=r?le(i.name+":equals",()=>i.get(),{isEqual:r}):i;return le(e+":"+o,()=>t(a.get()))}).get()}}}createSelectedComputedCache(e,t,r){const s=new Ao;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=le(e+":"+o+":selector",()=>t(i.get()));return le(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,t){if(mt(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&mt(e.id===t.id),!e&&!t))return;const r=(e||t).id,s=this.pendingAfterEvents.get(r);s?s.after=t:this.pendingAfterEvents.set(r,{before:e,after:t})}flushAtomicCallbacks(){let e=0;const t=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,t):s&&!o?this.sideEffects.handleAfterDelete(s,t):!s&&o&&this.sideEffects.handleAfterCreate(o,t);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(t)}}}atomic(e,t=!0){return ko(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),e();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t??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(t=>e(t,this.isMergingRemoteChanges?"remote":"user"))}}function Q8(n){if(n.length===0)return[];const e=[];let t=[n[0]],r;for(let s=1,o=n.length;s<o;s++)r=n[s],t[0].source!==r.source&&(e.push(t),t=[]),t.push(r);return e.push(t),e.map(s=>({source:s[0].source,changes:wb(s.map(o=>o.changes))}))}class J8{constructor(){j(this,"_history",[]);j(this,"_interceptors",new Set)}addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const t of this._interceptors)t(e)}flush(){const e=Q8(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function e9(n,e,t){const r=new Ao;return{get(s,o){return r.get(s,()=>(s instanceof bb?s:s.store).createComputedCache(n,c=>e(s,c),t)).get(o)}}}function t9(n){const e=[];for(let t=n.length-1;t>=0;t--){const r=n[t];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 Cc({sequence:n,sequenceId:e,retroactive:t=!0}){const r={sequenceId:e,retroactive:t,sequence:t9(n)};return yA(r),r}function Nr(n,e){return Object.fromEntries(Lr(e).map(([t,r])=>[t,`${n}/${r}`]))}function os(n){const e=n.sequenceId;return Cc({sequenceId:e,retroactive:n.retroactive??!0,sequence:n.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>{var s,o;return r.typeName===n.recordType&&(((s=t.filter)==null?void 0:s.call(t,r))??!0)&&(((o=n.filter)==null?void 0:o.call(n,r))??!0)}}:t)})}function n9(n){const e=new Map(n.map(o=>[o.id,o])),t=new Set,r=[];function s(o){mt(!t.has(o.id),`Circular dependency in migrations: ${o.id}`),t.add(o.id);const{version:i,sequenceId:a}=$f(o.id),c=e.get(`${a}/${i-1}`);if(c&&s(c),o.dependsOn)for(const d of o.dependsOn){const h=e.get(d);h&&s(h)}e.delete(o.id),r.push(o)}for(const o of e.values())s(o);return r}function $f(n){const[e,t]=n.split("/");return{sequenceId:e,version:parseInt(t)}}function E2(n,e){e&&mt(n.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${n}'`),mt(n.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${n}'`)}function yA(n){if(mt(!n.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${n.sequenceId}`),mt(n.sequenceId.length,"sequenceId must be a non-empty string"),n.sequence.length===0)return;E2(n.sequence[0].id,n.sequenceId);let e=$f(n.sequence[0].id).version;mt(e===1,`Expected the first migrationId to be '${n.sequenceId}/1' but got '${n.sequence[0].id}'`);for(let t=1;t<n.sequence.length;t++){const r=n.sequence[t].id;E2(r,n.sequenceId);const s=$f(r).version;mt(s===e+1,`Migration id numbers must increase in increments of 1, expected ${n.sequenceId}/${e+1} but got '${n.sequence[t].id}'`),e=s}}var Ji=(n=>(n.IncompatibleSubtype="incompatible-subtype",n.UnknownType="unknown-type",n.TargetVersionTooNew="target-version-too-new",n.TargetVersionTooOld="target-version-too-old",n.MigrationError="migration-error",n.UnrecognizedSubtype="unrecognized-subtype",n))(Ji||{});function r9(n){if(n.schemaVersion>2||n.schemaVersion<1)return rr.err("Bad schema version");if(n.schemaVersion===2)return rr.ok(n);const e={schemaVersion:2,sequences:{"com.tldraw.store":n.storeVersion}};for(const[t,r]of Object.entries(n.recordVersions))if(e.sequences[`com.tldraw.${t}`]=r.version,"subTypeKey"in r)for(const[s,o]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${t}.${s}`]=o;return rr.ok(e)}class Pb{constructor(e,t){j(this,"migrations",{});j(this,"sortedMigrations");var s;this.types=e,this.options=t;for(const o of t.migrations??[])mt(!this.migrations[o.sequenceId],`Duplicate migration sequenceId ${o.sequenceId}`),yA(o),this.migrations[o.sequenceId]=o;const r=Object.values(this.migrations).flatMap(o=>o.sequence);this.sortedMigrations=n9(r);for(const o of this.sortedMigrations)if((s=o.dependsOn)!=null&&s.length)for(const i of o.dependsOn){const a=r.find(c=>c.id===i);mt(a,`Migration '${o.id}' depends on missing migration '${i}'`)}}static create(e,t){return new Pb(e,t??{})}validateRecord(e,t,r,s){try{const o=Vn(this.types,t.typeName);if(!o)throw new Error(`Missing definition for record type ${t.typeName}`);return o.validate(t,s??void 0)}catch(o){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:t,phase:r,recordBefore:s,error:o});throw o}}getMigrationsSince(e){const t=r9(e);if(!t.ok)return t;const r=t.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 rr.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 h of this.migrations[i].sequence)o.add(h.id);continue}const c=`${i}/${a}`,d=this.migrations[i].sequence.findIndex(h=>h.id===c);if(d===-1)return rr.err("Incompatible schema?");for(const h of this.migrations[i].sequence.slice(d+1))o.add(h.id)}return rr.ok(this.sortedMigrations.filter(({id:i})=>o.has(i)))}migratePersistedRecord(e,t,r="up"){const s=this.getMigrationsSince(t);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:Ji.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"?Ji.TargetVersionTooOld:Ji.TargetVersionTooNew};if(r==="down"){if(!o.every(i=>i.down))return{type:"error",reason:Ji.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 c=i[r](e);c&&(e=Nt(c))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Ji.MigrationError}}return{type:"success",value:e}}migrateStoreSnapshot(e){let{store:t}=e;const r=this.getMigrationsSince(e.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:Ji.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:t};t=Nt(t);try{for(const o of s)if(o.scope==="record")for(const[i,a]of Object.entries(t)){if(!(o.filter?o.filter(a):!0))continue;const d=o.up(a);d&&(t[i]=Nt(d))}else if(o.scope==="store"){const i=o.up(t);i&&(t=Nt(i))}else un(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Ji.MigrationError}}return{type:"success",value:t}}createIntegrityChecker(e){var t,r;return((r=(t=this.options).createIntegrityChecker)==null?void 0:r.call(t,e))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:t})=>[e,t.length?$f(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const t=Vn(this.types,e);return mt(t,"record type does not exists"),t}}ya("@tldraw/store","3.8.0-canary.3f23e0d4c913","esm");function s9(n){if(!n.length)return null;let e="";for(const t of n)typeof t=="number"?e+=`.${t}`:t.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${t.slice(1)}`:e+=t:e+=`.${t}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class lt extends Error{constructor(t,r=[]){const s=s9(r),o=t.split(`
|
|
83
|
+
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
84
|
+
`);super(r?`At ${s}: ${o}`:o);j(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Fr(n,e){try{return e()}catch(t){throw t instanceof lt?new lt(t.rawMessage,[n,...t.path]):new lt(t.toString(),[n])}}function ua(n){if(n===null)return"null";if(Array.isArray(n))return"an array";const e=typeof n;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:un(e)}}class lr{constructor(e,t){this.validationFn=e,this.validateUsingKnownGoodVersionFn=t}validate(e){return this.validationFn(e)}validateUsingKnownGoodVersion(e,t){return Object.is(e,t)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,t):this.validate(t)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return u9(this)}optional(){return vA(this)}refine(e){return new lr(t=>e(this.validate(t)),(t,r)=>{const s=this.validateUsingKnownGoodVersion(t,r);return Object.is(t,s)?t:e(s)})}check(e,t){return typeof e=="string"?this.refine(r=>(Fr(`(check ${e})`,()=>t(r)),r)):this.refine(r=>(e(r),r))}}class o9 extends lr{constructor(e){super(t=>{const r=T2.validate(t);for(let s=0;s<r.length;s++)Fr(s,()=>e.validate(r[s]));return r},(t,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=T2.validate(r);let o=t.length!==s.length;for(let i=0;i<s.length;i++){const a=s[i];if(i>=t.length){o=!0,Fr(i,()=>e.validate(a));continue}if(Object.is(t[i],a))continue;const c=Fr(i,()=>e.validateUsingKnownGoodVersion(t[i],a));Object.is(c,t[i])||(o=!0)}return o?r:t}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new lt("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new lt("Expected an array with length greater than 1")})}}class zf extends lr{constructor(e,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new lt(`Expected object, got ${ua(r)}`);for(const[s,o]of Object.entries(e))Fr(s,()=>{o.validate(Vn(r,s))});if(!t){for(const s of Object.keys(r))if(!Cs(e,s))throw new lt("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new lt(`Expected object, got ${ua(s)}`);let o=!1;for(const[i,a]of Object.entries(e)){const c=Vn(r,i),d=Vn(s,i);if(Object.is(c,d))continue;const h=Fr(i,()=>{const f=a;return f.validateUsingKnownGoodVersion?f.validateUsingKnownGoodVersion(c,d):f.validate(d)});Object.is(h,c)||(o=!0)}if(!t){for(const i of Object.keys(s))if(!Cs(e,i))throw new lt("Unexpected property",[i])}for(const i of Object.keys(r))if(!Cs(s,i)){o=!0;break}return o?s:r}),this.config=e,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new zf(this.config,!0)}extend(e){return new zf({...this.config,...e})}}class _g extends lr{constructor(e,t,r,s){super(o=>{this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(o);return i===void 0?this.unknownValueValidation(o,a):Fr(`(${e} = ${a})`,()=>i.validate(o))},(o,i)=>{this.expectObject(i),this.expectObject(o);const{matchingSchema:a,variant:c}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,c):Vn(o,e)!==Vn(i,e)?Fr(`(${e} = ${c})`,()=>a.validate(i)):Fr(`(${e} = ${c})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(o,i):a.validate(i))}),this.key=e,this.config=t,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(e){if(typeof e!="object"||e===null)throw new lt(`Expected an object, got ${ua(e)}`,[])}getMatchingSchemaAndVariant(e){const t=Vn(e,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new lt(`Expected a string for key "${this.key}", got ${ua(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new lt(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:Cs(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(e){return new _g(this.key,this.config,e,this.useNumberKeys)}}class i9 extends lr{constructor(e,t){super(r=>{if(typeof r!="object"||r===null)throw new lt(`Expected object, got ${ua(r)}`);for(const[s,o]of Object.entries(r))Fr(s,()=>{e.validate(s),t.validate(o)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new lt(`Expected object, got ${ua(s)}`);let o=!1;for(const[i,a]of Object.entries(s)){if(!Cs(r,i)){o=!0,Fr(i,()=>{e.validate(i),t.validate(a)});continue}const c=Vn(r,i),d=a;if(Object.is(c,d))continue;const h=Fr(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(c,d):t.validate(d));Object.is(h,c)||(o=!0)}for(const i of Object.keys(r))if(!Cs(s,i)){o=!0;break}return o?s:r}),this.keyValidator=e,this.valueValidator=t}}function Cb(n){return new lr(e=>{if(typeof e!==n)throw new lt(`Expected ${n}, got ${ua(e)}`);return e})}const a9=new lr(n=>n),Xe=Cb("string"),We=Cb("number").check(n=>{if(Number.isNaN(n))throw new lt("Expected a number, got NaN");if(!Number.isFinite(n))throw new lt(`Expected a finite number, got ${n}`)}),Bf=We.check(n=>{if(n<0)throw new lt(`Expected a positive number, got ${n}`)}),an=We.check(n=>{if(n<=0)throw new lt(`Expected a non-zero positive number, got ${n}`)}),SA=We.check(n=>{if(!Number.isInteger(n))throw new lt(`Expected an integer, got ${n}`)}),nf=SA.check(n=>{if(n<0)throw new lt(`Expected a positive integer, got ${n}`)}),l9=SA.check(n=>{if(n<=0)throw new lt(`Expected a non-zero positive integer, got ${n}`)}),tt=Cb("boolean");function Xn(n){return new lr(e=>{if(e!==n)throw new lt(`Expected ${n}, got ${JSON.stringify(e)}`);return n})}const T2=new lr(n=>{if(!Array.isArray(n))throw new lt(`Expected an array, got ${ua(n)}`);return n});function Tn(n){return new o9(n)}function rt(n){return new zf(n)}function Hw(n){return typeof n=="object"&&n!==null&&(Object.getPrototypeOf(n)===Object.prototype||Object.getPrototypeOf(n)===null||Object.getPrototypeOf(n)===sz)}function Kw(n){return n===null||typeof n=="number"||typeof n=="string"||typeof n=="boolean"?!0:Array.isArray(n)?n.every(Kw):Hw(n)?Object.values(n).every(Kw):!1}const kn=new lr(n=>{if(Kw(n))return n;throw new lt(`Expected json serializable value, got ${typeof n}`)},(n,e)=>{if(Array.isArray(n)&&Array.isArray(e)){let t=n.length!==e.length;for(let r=0;r<e.length;r++){if(r>=n.length){t=!0,kn.validate(e[r]);continue}const s=n[r],o=e[r];if(Object.is(s,o))continue;const i=kn.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(t=!0)}return t?e:n}else if(Hw(n)&&Hw(e)){let t=!1;for(const r of Object.keys(e)){if(!Cs(n,r)){t=!0,kn.validate(e[r]);continue}const s=n[r],o=e[r];if(Object.is(s,o))continue;const i=kn.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(t=!0)}for(const r of Object.keys(n))if(!Cs(e,r)){t=!0;break}return t?e:n}else return kn.validate(e)});function Uf(n,e){return new i9(n,e)}function _b(n,e){return new _g(n,e,(t,r)=>{throw new lt(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!1)}function c9(n,e){return new _g(n,e,(t,r)=>{throw new lt(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!0)}function Bo(n,e){return new lr(t=>Fr(n,()=>e.validate(t)),(t,r)=>Fr(n,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(t,r):e.validate(r)))}function Ig(n){return new lr(e=>{if(!n.has(e)){const t=Array.from(n,r=>JSON.stringify(r)).join(" or ");throw new lt(`Expected ${t}, got ${e}`)}return e})}function vA(n){return new lr(e=>{if(e!==void 0)return n.validate(e)},(e,t)=>{if(!(e===void 0&&t===void 0)&&t!==void 0)return n.validateUsingKnownGoodVersion&&e!==void 0?n.validateUsingKnownGoodVersion(e,t):n.validate(t)})}function u9(n){return new lr(e=>e===null?null:n.validate(e),(e,t)=>t===null?null:n.validateUsingKnownGoodVersion&&e!==null?n.validateUsingKnownGoodVersion(e,t):n.validate(t))}function Eg(...n){return Ig(new Set(n))}function Ib(n){try{return new URL(n)}catch{if(n.startsWith("/")||n.startsWith("./"))try{return new URL(n,"http://example.com")}catch{throw new lt(`Expected a valid url, got ${JSON.stringify(n)}`)}throw new lt(`Expected a valid url, got ${JSON.stringify(n)}`)}}const d9=new Set(["http:","https:","mailto:"]),ns=Xe.check(n=>{if(n==="")return;const e=Ib(n);if(!d9.has(e.protocol.toLowerCase()))throw new lt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)}),h9=new Set(["http:","https:","data:","asset:"]),ol=Xe.check(n=>{if(n==="")return;const e=Ib(n);if(!h9.has(e.protocol.toLowerCase()))throw new lt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});Xe.check(n=>{if(n==="")return;if(!Ib(n).protocol.toLowerCase().match(/^https?:$/))throw new lt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});const Eb=Xe.refine(n=>{try{return q6(n),n}catch{throw new lt(`Expected an index key, got ${JSON.stringify(n)}`)}});ya("@tldraw/validate","3.8.0-canary.3f23e0d4c913","esm");function es(n){return Xe.refine(e=>{if(!e.startsWith(`${n}:`))throw new Error(`${n} ID must start with "${n}:"`);return e})}const Tg=es("asset");function Tb(n,e){return rt({id:Tg,typeName:Xn("asset"),type:Xn(n),props:e,meta:kn})}const il=rt({x:We,y:We,z:We.optional()}),dd=rt({x:We,y:We,w:We,h:We}),xA=We.check(n=>{if(n<0||n>1)throw new lt("Opacity must be between 0 and 1")}),p9=Xe.refine(n=>{if(!n.startsWith("page:")&&!n.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return n}),vs=es("shape");function f9(n,e,t){return rt({id:vs,typeName:Xn("shape"),x:We,y:We,rotation:We,index:Eb,parentId:p9,type:Xn(n),isLocked:tt,opacity:xA,props:e?rt(e):kn,meta:t?rt(t):kn})}const g9=es("binding");function m9(n,e,t){return rt({id:g9,typeName:Xn("binding"),type:Xn(n),fromId:vs,toId:vs,props:e?rt(e):kn,meta:t?rt(t):kn})}Nr("com.tldraw.binding",{});os({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function nl(n){return`binding:${xt()}`}function y9(n){return zo("binding",{scope:"document",validator:Bo("binding",_b("type",Nd(n,(e,{props:t,meta:r})=>m9(e,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class Rn{constructor(e,t,r){this.id=e,this.defaultValue=t,this.type=r}static define(e,t){const{defaultValue:r,type:s=a9}=t;return new Rn(e,r,s)}static defineEnum(e,t){const{defaultValue:r,values:s}=t;return new S9(e,r,s)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,t):this.validate(t)}}class S9 extends Rn{constructor(e,t,r){super(e,t,Eg(...r)),this.values=r}}const Sp=Nr("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),v9=os({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:Sp.AddIsLocked,up:n=>{n.isLocked=!1},down:n=>{delete n.isLocked}},{id:Sp.HoistOpacity,up:n=>{n.opacity=Number(n.props.opacity??"1"),delete n.props.opacity},down:n=>{const e=n.opacity;delete n.opacity,n.props.opacity=e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}},{id:Sp.AddMeta,up:n=>{n.meta={}}},{id:Sp.AddWhite,up:n=>{},down:n=>{n.props.color==="white"&&(n.props.color="black")}}]});function Sc(n){return n?n.typeName==="shape":!1}function Mr(n){return n?n.startsWith("shape:"):!1}function Ct(n){return`shape:${n??xt()}`}function wA(n){const e=new Map;for(const[t,r]of Object.entries(n))if(r instanceof Rn){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,t)}return e}function to(n,e){return Nd(e,(t,r)=>`com.tldraw.shape.${n}/${r}`)}function x9(n){return zo("shape",{scope:"document",validator:Bo("shape",_b("type",Nd(n,(e,{props:t,meta:r})=>f9(e,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function k2(n,e){const t=[];for(const[r,{migrations:s}]of Object.entries(e)){const o=`com.tldraw.${n}.${r}`;s?"sequenceId"in s?(mt(o===s.sequenceId,`sequenceId mismatch for ${r} ${Cg} migrations. Expected '${o}', got '${s.sequenceId}'`),t.push(s)):"sequence"in s?t.push(Cc({sequenceId:o,retroactive:!1,sequence:s.sequence.map(i=>"id"in i?bA(n,r,i):i)})):t.push(Cc({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===n&&a.type===r,up:a=>{const c=s.migrators[i].up(a);if(c)return c},down:a=>{const c=s.migrators[i].down(a);if(c)return c}}))})):t.push(Cc({sequenceId:o,retroactive:!1,sequence:[]}))}return t}function bA(n,e,t){return{id:t.id,dependsOn:t.dependsOn,scope:"record",filter:r=>r.typeName===n&&r.type===e,up:r=>{const s=t.up(r.props);s&&(r.props=s)},down:typeof t.down=="function"?r=>{const s=t.down(r.props);s&&(r.props=s)}:void 0}}const PA=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Hf={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 _i(n){return n.isDarkMode?Hf.darkMode:Hf.lightMode}const rs=Rn.defineEnum("tldraw:color",{defaultValue:"black",values:PA}),kb=Rn.defineEnum("tldraw:labelColor",{defaultValue:"black",values:PA}),al=Rn.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),ll=Rn.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Ro=Rn.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),CA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Oo=Rn.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),_A=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Kf=Rn.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:_A}),Wf=Rn.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:_A}),IA={labelColor:kb,color:rs,fill:ll,dash:al,size:Oo,arrowheadStart:Kf,arrowheadEnd:Wf,font:Ro,start:il,end:il,bend:We,text:Xe,labelPosition:We,scale:an},pc=to("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function vp(n){return bA("shape","arrow",n)}const EA=Cc({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[vp({id:pc.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"}),vp({id:pc.AddIsPrecise,up:({start:n,end:e})=>{n.type==="binding"&&(n.isPrecise=!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:n,end:e})=>{n.type==="binding"&&(n.isPrecise||(n.normalizedAnchor={x:.5,y:.5}),delete n.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),vp({id:pc.AddLabelPosition,up:n=>{n.labelPosition=.5},down:n=>{delete n.labelPosition}}),{id:pc.ExtractBindings,scope:"store",up:n=>{const e=Object.values(n).filter(t=>t.typeName==="shape"&&t.type==="arrow");for(const t of e){const{start:r,end:s}=t.props;if(r.type==="binding"){const o=nl(),i={typeName:"binding",id:o,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};n[o]=i,t.props.start={x:0,y:0}}else delete t.props.start.type;if(s.type==="binding"){const o=nl(),i={typeName:"binding",id:o,type:"arrow",fromId:t.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};n[o]=i,t.props.end={x:0,y:0}}else delete t.props.end.type}}},vp({id:pc.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}})]}),TA={terminal:Eg("start","end"),normalizedAnchor:il,isExact:tt,isPrecise:tt},kA={sequence:[{dependsOn:[pc.ExtractBindings]}]},w9=Bo("camera",rt({typeName:Xn("camera"),id:es("camera"),x:We,y:We,z:We,meta:kn})),b9=Nr("com.tldraw.camera",{AddMeta:1}),P9=os({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:b9.AddMeta,up:n=>{n.meta={}}}]}),_o=zo("camera",{validator:w9,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),C9=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"]),MA=Ig(C9),_9=rt({type:MA,rotation:We}),I9=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),E9=Ig(I9),T9=new Set(["starting","paused","active","stopping"]),AA=rt({id:Xe,points:Tn(il),size:Bf,color:E9,opacity:We,state:Ig(T9),delay:We,shrink:We,taper:tt}),Pd=es("page"),k9=Bo("page",rt({typeName:Xn("page"),id:Pd,name:Xe,index:Eb,meta:kn})),M9=Nr("com.tldraw.page",{AddMeta:1}),A9=os({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:M9.AddMeta,up:n=>{n.meta={}}}]}),ss=zo("page",{validator:k9,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Er(n){return ss.isId(n)}const j9={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 jA(n){return n?cd(n,e=>j9[e]):null}es("instance");function R9(n){const e={};for(const[r,s]of n)e[r]=vA(s);const t=Bo("instance",rt({typeName:Xn("instance"),id:es("instance"),currentPageId:Pd,followingUserId:Xe.nullable(),brush:dd.nullable(),opacityForNextShape:xA,stylesForNextShape:rt(e),cursor:_9,scribbles:Tn(AA),isFocusMode:tt,isDebugMode:tt,isToolLocked:tt,exportBackground:tt,screenBounds:dd,insets:Tn(tt),zoomBrush:dd.nullable(),isPenMode:tt,isGridMode:tt,chatMessage:Xe,isChatting:tt,highlightedUserIds:Tn(Xe),isFocused:tt,devicePixelRatio:We,isCoarsePointer:tt,isHoveringCanvas:tt.nullable(),openMenus:Tn(Xe),isChangingStyle:tt,isReadonly:tt,meta:kn,duplicateProps:rt({shapeIds:Tn(es("shape")),offset:rt({x:We,y:We})}).nullable()}));return zo("instance",{validator:t,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 Ft=Nr("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}),O9=os({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:Ft.AddTransparentExportBgs,up:n=>({...n,exportBackground:!0})},{id:Ft.RemoveDialog,up:({dialog:n,...e})=>e},{id:Ft.AddToolLockMode,up:n=>({...n,isToolLocked:!1})},{id:Ft.RemoveExtraPropsForNextShape,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:Object.fromEntries(Object.entries(n).filter(([t])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(t)))})},{id:Ft.AddLabelColor,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:{...n,labelColor:"black"}})},{id:Ft.AddFollowingUserId,up:n=>({...n,followingUserId:null})},{id:Ft.RemoveAlignJustify,up:n=>{let e=n.propsForNextShape.align;return e==="justify"&&(e="start"),{...n,propsForNextShape:{...n.propsForNextShape,align:e}}}},{id:Ft.AddZoom,up:n=>({...n,zoomBrush:null})},{id:Ft.AddVerticalAlign,up:n=>({...n,propsForNextShape:{...n.propsForNextShape,verticalAlign:"middle"}})},{id:Ft.AddScribbleDelay,up:n=>n.scribble!==null?{...n,scribble:{...n.scribble,delay:0}}:{...n}},{id:Ft.RemoveUserId,up:({userId:n,...e})=>e},{id:Ft.AddIsPenModeAndIsGridMode,up:n=>({...n,isPenMode:!1,isGridMode:!1})},{id:Ft.HoistOpacity,up:({propsForNextShape:{opacity:n,...e},...t})=>({...t,opacityForNextShape:Number(n??"1"),propsForNextShape:e})},{id:Ft.AddChat,up:n=>({...n,chatMessage:"",isChatting:!1})},{id:Ft.AddHighlightedUserIds,up:n=>({...n,highlightedUserIds:[]})},{id:Ft.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:n,...e})=>({...e,stylesForNextShape:{}})},{id:Ft.AddMeta,up:n=>({...n,meta:{}})},{id:Ft.RemoveCursorColor,up:n=>{const{color:e,...t}=n.cursor;return{...n,cursor:t}}},{id:Ft.AddLonelyProperties,up:n=>({...n,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:Ft.ReadOnlyReadonly,up:({isReadOnly:n,...e})=>({...e,isReadonly:n})},{id:Ft.AddHoveringCanvas,up:n=>({...n,isHoveringCanvas:null})},{id:Ft.AddScribbles,up:({scribble:n,...e})=>({...e,scribbles:[]})},{id:Ft.AddInset,up:n=>({...n,insets:[!1,!1,!1,!1]}),down:({insets:n,...e})=>({...e})},{id:Ft.AddDuplicateProps,up:n=>({...n,duplicateProps:null}),down:({duplicateProps:n,...e})=>({...e})},{id:Ft.RemoveCanMoveCamera,up:({canMoveCamera:n,...e})=>({...e}),down:n=>({...n,canMoveCamera:!0})}]}),sr="instance:instance",D9=Bo("instance_page_state",rt({typeName:Xn("instance_page_state"),id:es("instance_page_state"),pageId:Pd,selectedShapeIds:Tn(vs),hintingShapeIds:Tn(vs),erasingShapeIds:Tn(vs),hoveredShapeId:vs.nullable(),editingShapeId:vs.nullable(),croppingShapeId:vs.nullable(),focusedGroupId:vs.nullable(),meta:kn})),zu=Nr("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),L9=os({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:zu.AddCroppingId,up(n){n.croppingShapeId=null}},{id:zu.RemoveInstanceIdAndCameraId,up(n){delete n.instanceId,delete n.cameraId}},{id:zu.AddMeta,up:n=>{n.meta={}}},{id:zu.RenameProperties,up:n=>{},down:n=>{}},{id:zu.RenamePropertiesAgain,up:n=>{n.selectedShapeIds=n.selectedIds,delete n.selectedIds,n.hintingShapeIds=n.hintingIds,delete n.hintingIds,n.erasingShapeIds=n.erasingIds,delete n.erasingIds,n.hoveredShapeId=n.hoveredId,delete n.hoveredId,n.editingShapeId=n.editingId,delete n.editingId,n.croppingShapeId=n.croppingShapeId??n.croppingId??null,delete n.croppingId,n.focusedGroupId=n.focusLayerId,delete n.focusLayerId},down:n=>{n.selectedIds=n.selectedShapeIds,delete n.selectedShapeIds,n.hintingIds=n.hintingShapeIds,delete n.hintingShapeIds,n.erasingIds=n.erasingShapeIds,delete n.erasingShapeIds,n.hoveredId=n.hoveredShapeId,delete n.hoveredShapeId,n.editingId=n.editingShapeId,delete n.editingShapeId,n.croppingId=n.croppingShapeId,delete n.croppingShapeId,n.focusLayerId=n.focusedGroupId,delete n.focusedGroupId}}]}),Vs=zo("instance_page_state",{validator:D9,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:{}})),F9=Bo("pointer",rt({typeName:Xn("pointer"),id:es("pointer"),x:We,y:We,lastActivityTimestamp:We,meta:kn})),N9=Nr("com.tldraw.pointer",{AddMeta:1}),$9=os({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:N9.AddMeta,up:n=>{n.meta={}}}]}),Mb=zo("pointer",{validator:F9,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Gf=Mb.createId("pointer"),z9=Bo("instance_presence",rt({typeName:Xn("instance_presence"),id:es("instance_presence"),userId:Xe,userName:Xe,lastActivityTimestamp:We.nullable(),followingUserId:Xe.nullable(),cursor:rt({x:We,y:We,type:MA,rotation:We}).nullable(),color:Xe,camera:rt({x:We,y:We,z:We}).nullable(),screenBounds:dd.nullable(),selectedShapeIds:Tn(es("shape")),currentPageId:es("page"),brush:dd.nullable(),scribbles:Tn(AA),chatMessage:Xe,meta:kn})),sc=Nr("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),B9=os({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:sc.AddScribbleDelay,up:n=>{n.scribble!==null&&(n.scribble.delay=0)}},{id:sc.RemoveInstanceId,up:n=>{delete n.instanceId}},{id:sc.AddChatMessage,up:n=>{n.chatMessage=""}},{id:sc.AddMeta,up:n=>{n.meta={}}},{id:sc.RenameSelectedShapeIds,up:n=>{}},{id:sc.NullableCameraCursor,up:n=>{},down:n=>{n.camera===null&&(n.camera={x:0,y:0,z:1}),n.lastActivityTimestamp===null&&(n.lastActivityTimestamp=0),n.cursor===null&&(n.cursor={type:"default",x:0,y:0,rotation:0}),n.screenBounds===null&&(n.screenBounds={x:0,y:0,w:1,h:1})}}]}),U9=zo("instance_presence",{validator:z9,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),H9=Bo("document",rt({typeName:Xn("document"),id:Xn("document:document"),gridSize:We,name:Xe,meta:kn})),M2=Nr("com.tldraw.document",{AddName:1,AddMeta:2}),K9=os({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:M2.AddName,up:n=>{n.name=""},down:n=>{delete n.name}},{id:M2.AddMeta,up:n=>{n.meta={}}}]}),Ab=zo("document",{validator:H9,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),Ww=Ab.createId("document");function W9(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function A2(n){n.typeName==="asset"&&("src"in n&&(n.src="<redacted>"),"src"in n.props&&(n.props.src="<redacted>"))}function G9({error:n,phase:e,record:t,recordBefore:r}){throw X0(n,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?A2(Nt(r)):void 0,recordAfter:A2(Nt(t))}}),n}function V9(){return[ss.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function q9(n){const e=n.query.ids("page"),t=n.query.records("instance_page_state"),r=()=>{if(!n.has(Ww))return n.put([Ab.create({id:Ww,name:n.props.defaultName})]),r();if(!n.has(Gf))return n.put([Mb.create({id:Gf})]),r();const s=e.get();if(s.size===0)return n.put(V9()),r();const o=()=>[...s].map(h=>n.get(h)).sort(W9)[0].id,i=n.get(sr);if(i){if(!s.has(i.currentPageId))return n.put([{...i,currentPageId:o()}]),r()}else return n.put([n.schema.types.instance.create({id:sr,currentPageId:o(),exportBackground:!0})]),r();const a=new Set,c=new Set;for(const h of s){const f=Vs.createId(h);n.get(f)||a.add(f);const y=_o.createId(h);n.has(y)||c.add(y)}a.size>0&&n.put([...a].map(h=>Vs.create({id:h,pageId:Vs.parseId(h)}))),c.size>0&&n.put([...c].map(h=>_o.create({id:h})));const d=t.get();for(const h of d){if(!s.has(h.pageId)){n.remove([h.id]);continue}if(h.croppingShapeId&&!n.has(h.croppingShapeId))return n.put([{...h,croppingShapeId:null}]),r();if(h.focusedGroupId&&!n.has(h.focusedGroupId))return n.put([{...h,focusedGroupId:null}]),r();if(h.hoveredShapeId&&!n.has(h.hoveredShapeId))return n.put([{...h,hoveredShapeId:null}]),r();const f=h.selectedShapeIds.filter(S=>n.has(S));if(f.length!==h.selectedShapeIds.length)return n.put([{...h,selectedShapeIds:f}]),r();const g=h.hintingShapeIds.filter(S=>n.has(S));if(g.length!==h.hintingShapeIds.length)return n.put([{...h,hintingShapeIds:g}]),r();const y=h.erasingShapeIds.filter(S=>n.has(S));if(y.length!==h.erasingShapeIds.length)return n.put([{...h,erasingShapeIds:y}]),r()}};return r}const Y9=Tb("bookmark",rt({title:Xe,description:Xe,image:Xe,favicon:Xe,src:ol.nullable()})),j2=Nr("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),X9=os({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:n=>n.type==="bookmark",sequence:[{id:j2.MakeUrlsValid,up:n=>{ol.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:j2.AddFavicon,up:n=>{ol.isValid(n.props.favicon)||(n.props.favicon="")},down:n=>{delete n.props.favicon}}]}),Z9=Tb("image",rt({w:We,h:We,name:Xe,isAnimated:tt,mimeType:Xe.nullable(),src:ol.nullable(),fileSize:an.optional()})),Bu=Nr("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),Q9=os({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:n=>n.type==="image",sequence:[{id:Bu.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:Bu.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:Bu.MakeUrlsValid,up:n=>{ol.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:Bu.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:Bu.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),J9=Tb("video",rt({w:We,h:We,name:Xe,isAnimated:tt,mimeType:Xe.nullable(),src:ol.nullable(),fileSize:We.optional()})),Uu=Nr("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),eB=os({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:n=>n.type==="video",sequence:[{id:Uu.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:Uu.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:Uu.MakeUrlsValid,up:n=>{ol.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:Uu.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:Uu.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),tB=Bo("asset",_b("type",{image:Z9,video:J9,bookmark:Y9})),nB=Nr("com.tldraw.asset",{AddMeta:1}),rB=os({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:nB.AddMeta,up:n=>{n.meta={}}}]}),da=zo("asset",{validator:tB,scope:"document"}).withDefaultProperties(()=>({meta:{}})),RA={w:an,h:an,assetId:Tg.nullable(),url:ns},R2=to("bookmark",{NullAssetId:1,MakeUrlsValid:2}),OA={sequence:[{id:R2.NullAssetId,up:n=>{n.assetId===void 0&&(n.assetId=null)},down:"retired"},{id:R2.MakeUrlsValid,up:n=>{ns.isValid(n.url)||(n.url="")},down:n=>{}}]},DA=rt({type:Eg("free","straight"),points:Tn(il)}),LA={color:rs,fill:ll,dash:al,size:Oo,segments:Tn(DA),isComplete:tt,isClosed:tt,isPen:tt,scale:an},O2=to("draw",{AddInPen:1,AddScale:2}),FA={sequence:[{id:O2.AddInPen,up:n=>{const{points:e}=n.segments[0];if(e.length===0){n.isPen=!1;return}let t=!(e[0].z===0||e[0].z===.5);e[1]&&(t=t&&!(e[1].z===0||e[1].z===.5)),n.isPen=t},down:"retired"},{id:O2.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},sB=/(^\/r\/[^/]+\/?$)/,oB=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(sB))return n}},{hostnames:["figma.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{hostnames:["google.*"],fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:n=>{const e=Ge(n),t=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s,o]=t;return`https://codepen.io/${s}/pen/${o}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:n=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s]=t;return`https://scratch.mit.edu/projects/${s}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n),t=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&t){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",t),e.href}}},{hostnames:["docs.google.*"],fromEmbedUrl:n=>{const e=Ge(n);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const t=Array.from(e.searchParams.keys());for(const r of t)e.searchParams.delete(r);return e.href}}},{hostnames:["gist.github.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return n.split("/").pop()?n:void 0}},{hostnames:["replit.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{hostnames:["open.spotify.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.hostname==="player.vimeo.com"){const t=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(t)return"https://vimeo.com/"+t[1]}}},{hostnames:["excalidraw.com"],fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.hash.match(/#room=/))return n}},{hostnames:["observablehq.com"],fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],NA={w:an,h:an,url:Xe},xp=to("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),$A={sequence:[{id:xp.GenOriginalUrlInEmbed,up:n=>{try{const e=n.url,t=new URL(e).host.replace("www.","");let r;for(const s of oB)if(s.hostnames.includes(t))try{r=s.fromEmbedUrl(e)}catch(o){console.warn(o)}n.tmpOldUrl=n.url,n.url=r??""}catch{n.url="",n.tmpOldUrl=n.url}},down:"retired"},{id:xp.RemoveDoesResize,up:n=>{delete n.doesResize},down:"retired"},{id:xp.RemoveTmpOldUrl,up:n=>{delete n.tmpOldUrl},down:"retired"},{id:xp.RemovePermissionOverrides,up:n=>{delete n.overridePermissions},down:"retired"}]},zA={w:an,h:an,name:Xe},BA={sequence:[]},Vf=Rn.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),qf=Rn.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),qs=Rn.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"]}),UA={geo:qs,labelColor:kb,color:rs,fill:ll,dash:al,size:Oo,font:Ro,align:Vf,verticalAlign:qf,url:ns,w:an,h:an,growY:Bf,text:Xe,scale:an},si=to("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),HA={sequence:[{id:si.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:si.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"},{id:si.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:si.AddCheckBox,up:n=>{},down:"retired"},{id:si.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:si.MigrateLegacyAlign,up:n=>{let e;switch(n.align){case"start":e="start-legacy";break;case"end":e="end-legacy";break;default:e="middle-legacy";break}n.align=e},down:"retired"},{id:si.AddCloud,up:n=>{},down:"retired"},{id:si.MakeUrlsValid,up:n=>{ns.isValid(n.url)||(n.url="")},down:n=>{}},{id:si.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},KA={},WA={sequence:[]},GA={color:rs,size:Oo,segments:Tn(DA),isComplete:tt,isPen:tt,scale:an},iB=to("highlight",{AddScale:1}),VA={sequence:[{id:iB.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},aB=rt({topLeft:il,bottomRight:il}),qA={w:an,h:an,playing:tt,url:ns,assetId:Tg.nullable(),crop:aB.nullable(),flipX:tt,flipY:tt},wp=to("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),YA={sequence:[{id:wp.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:wp.AddCropProp,up:n=>{n.crop=null},down:n=>{delete n.crop}},{id:wp.MakeUrlsValid,up:n=>{ns.isValid(n.url)||(n.url="")},down:n=>{}},{id:wp.AddFlipProps,up:n=>{n.flipX=!1,n.flipY=!1},down:n=>{delete n.flipX,delete n.flipY}}]},Yf=Rn.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),lB=rt({id:Xe,index:Eb,x:We,y:We}),XA={color:rs,dash:al,size:Oo,spline:Yf,points:Uf(Xe,lB),scale:an},Hu=to("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),ZA={sequence:[{id:Hu.AddSnapHandles,up:n=>{for(const e of Object.values(n.handles))e.canSnap=!0},down:"retired"},{id:Hu.RemoveExtraHandleProps,up:n=>{n.handles=Q0(Object.values(n.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:n=>{const e=Object.entries(n.handles).map(([t,r])=>({index:t,...r})).sort(Wn);n.handles=Object.fromEntries(e.map((t,r)=>{const s=r===0?"start":r===e.length-1?"end":`handle:${t.index}`;return[s,{id:s,type:"vertex",canBind:!1,canSnap:!0,index:t.index,x:t.x,y:t.y}]}))}},{id:Hu.HandlesToPoints,up:n=>{const e=Object.entries(n.handles).map(([t,{x:r,y:s}])=>({x:r,y:s,index:t})).sort(Wn);n.points=e.map(({x:t,y:r})=>({x:t,y:r})),delete n.handles},down:n=>{const e=bd(n.points.length);n.handles=Object.fromEntries(n.points.map((t,r)=>[e[r],{x:t.x,y:t.y}])),delete n.points}},{id:Hu.PointIndexIds,up:n=>{const e=bd(n.points.length);n.points=Object.fromEntries(n.points.map((t,r)=>{const s=e[r];return[s,{id:s,index:s,x:t.x,y:t.y}]}))},down:n=>{const e=Object.values(n.points).sort(Wn);n.points=e.map(({x:t,y:r})=>({x:t,y:r}))}},{id:Hu.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},QA={color:rs,labelColor:kb,size:Oo,font:Ro,fontSizeAdjustment:Bf,align:Vf,verticalAlign:qf,growY:Bf,url:ns,text:Xe,scale:an},Xi=to("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8}),JA={sequence:[{id:Xi.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:Xi.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:Xi.MigrateLegacyAlign,up:n=>{switch(n.align){case"start":n.align="start-legacy";return;case"end":n.align="end-legacy";return;default:n.align="middle-legacy";return}},down:"retired"},{id:Xi.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:Xi.MakeUrlsValid,up:n=>{ns.isValid(n.url)||(n.url="")},down:n=>{}},{id:Xi.AddFontSizeAdjustment,up:n=>{n.fontSizeAdjustment=0},down:n=>{delete n.fontSizeAdjustment}},{id:Xi.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:Xi.AddLabelColor,up:n=>{n.labelColor="black"},down:n=>{delete n.labelColor}}]},Gw=Rn.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),ej={color:rs,size:Oo,font:Ro,textAlign:Gw,w:an,text:Xe,scale:an,autoSize:tt},D2=to("text",{RemoveJustify:1,AddTextAlign:2}),tj={sequence:[{id:D2.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:D2.AddTextAlign,up:n=>{n.textAlign=n.align,delete n.align},down:n=>{n.align=n.textAlign,delete n.textAlign}}]},nj={w:an,h:an,time:We,playing:tt,url:ns,assetId:Tg.nullable()},L2=to("video",{AddUrlProp:1,MakeUrlsValid:2}),rj={sequence:[{id:L2.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:L2.MakeUrlsValid,up:n=>{ns.isValid(n.url)||(n.url="")},down:n=>{}}]},bp=Nr("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),cB=Cc({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:bp.RemoveCodeAndIconShapeTypes,scope:"store",up:n=>{for(const[e,t]of Lr(n))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete n[e]}},{id:bp.AddInstancePresenceType,scope:"store",up(n){}},{id:bp.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:n=>{for(const[e,t]of Lr(n))t.typeName.match(/^(user|user_presence)$/)&&delete n[e]}},{id:bp.RemoveUserDocument,scope:"store",up:n=>{for(const[e,t]of Lr(n))t.typeName.match("user_document")&&delete n[e]}}]}),uB={arrow:{migrations:EA,props:IA},bookmark:{migrations:OA,props:RA},draw:{migrations:FA,props:LA},embed:{migrations:$A,props:NA},frame:{migrations:BA,props:zA},geo:{migrations:HA,props:UA},group:{migrations:WA,props:KA},highlight:{migrations:VA,props:GA},image:{migrations:YA,props:qA},line:{migrations:ZA,props:XA},note:{migrations:JA,props:QA},text:{migrations:tj,props:ej},video:{migrations:rj,props:nj}},dB={arrow:{migrations:kA,props:TA}};function hB({shapes:n=uB,bindings:e=dB,migrations:t}={}){const r=new Map;for(const a of Vt(n))for(const c of wA(a.props??{}).keys()){if(r.has(c.id)&&r.get(c.id)!==c)throw new Error(`Multiple StyleProp instances with the same id: ${c.id}`);r.set(c.id,c)}const s=x9(n),o=y9(e),i=R9(r);return Pb.create({asset:da,binding:o,camera:_o,document:Ab,instance:i,instance_page_state:Vs,page:ss,instance_presence:U9,pointer:Mb,shape:s},{migrations:[cB,rB,P9,K9,O9,L9,A9,B9,$9,v9,X9,Q9,eB,...k2("shape",n),...k2("binding",e),...t??[]],onValidationFailure:G9,createIntegrityChecker:q9})}const Cd=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ms",label:"Bahasa Melayu"},{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:"tl",label:"Filipino"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"nl",label:"Nederlands"},{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:"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:"el",label:"Ελληνικά"},{locale:"ru",label:"Русский"},{locale:"uk",label:"Українська"},{locale:"he",label:"עברית"},{locale:"ur",label:"اردو"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ne",label:"नेपाली"},{locale:"mr",label:"मराठी"},{locale:"hi-in",label:"हिन्दी"},{locale:"bn",label:"বাংলা"},{locale:"pa",label:"ਪੰਜਾਬੀ"},{locale:"gu-in",label:"ગુજરાતી"},{locale:"ta",label:"தமிழ்"},{locale:"te",label:"తెలుగు"},{locale:"kn",label:"ಕನ್ನಡ"},{locale:"ml",label:"മലയാളം"},{locale:"th",label:"ภาษาไทย"},{locale:"km-kh",label:"ភាសាខ្មែរ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function pB(){const n=typeof window<"u"?window.navigator.languages??["en"]:["en"];return fB(n)}function fB(n){for(const e of n){const t=gB(e);if(t)return t}return"en"}const F2={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function gB(n){const e=Cd.find(s=>s.locale===n.toLowerCase());if(e)return e.locale;const[t,r]=n.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=Cd.find(o=>o.locale===t);if(s)return s.locale}return t in F2?F2[t]:null}ya("@tldraw/tlschema","3.8.0-canary.3f23e0d4c913","esm");var wx={exports:{}};/*!
|
|
85
|
+
Copyright (c) 2018 Jed Watson.
|
|
86
|
+
Licensed under the MIT License (MIT), see
|
|
87
|
+
http://jedwatson.github.io/classnames
|
|
88
|
+
*/var N2;function mB(){return N2||(N2=1,function(n){(function(){var e={}.hasOwnProperty;function t(){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 t.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}n.exports?(t.default=t,n.exports=t):window.classNames=t})()}(wx)),wx.exports}var yB=mB();const Le=bi(yB),sj="3.8.0-canary.3f23e0d4c913",$2={major:"2024-09-13T14:36:29.063Z",minor:"2025-02-07T19:49:49.149Z"},SB={error:null};class jb extends _.Component{constructor(){super(...arguments);j(this,"state",SB)}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,s;(s=(r=this.props).onError)==null||s.call(r,t)}render(){const{error:t}=this.state;if(t!==null){const{fallback:r}=this.props;return p.jsx(r,{error:t})}return this.props.children}}function _d({children:n,fallback:e,...t}){return e===null?n:p.jsx(jb,{fallback:e,...t,children:n})}function Rb(n,e){return kg(`${n}_${e}`)}function Wc(n){return kg(`${_.useId()}${n??""}`)}function Ys(n){const e=Ar(_.useContext(oj));return kg(`${e}_${n}`)}function kg(n){return n.replace(/:/g,"_")}const oj=_.createContext(null);function vB({children:n}){const e=Wc();return p.jsx(oj.Provider,{value:e,children:n})}const Ob=_.createContext(null);function te(){const n=at.useContext(Ob);if(!n)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return n}function wa(){return at.useContext(Ob)}function Db({editor:n,children:e}){return p.jsx(Ob.Provider,{value:n,children:p.jsx(vB,{children:e})})}function xB(){return p.jsx("div",{className:"tl-background"})}function Gc(n,e,t,r,s,o){_.useLayoutEffect(()=>{const i=n.current;if(!i||e===void 0)return;let a=`translate(${e}px, ${t}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 bx=({brush:n,color:e,opacity:t,className:r})=>{const s=_.useRef(null);Gc(s,n.x,n.y);const o=ee(Math.max(1,n.w)),i=ee(Math.max(1,n.h));return p.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?p.jsxs("g",{className:"tl-brush",opacity:t,children:[p.jsx("rect",{width:o,height:i,fill:e,opacity:.75}),p.jsx("rect",{width:o,height:i,fill:"none",stroke:e,opacity:.1})]}):p.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:o,height:i})})},Et={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1};typeof window<"u"&&"navigator"in window&&(Et.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Et.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Et.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Et.isFirefox=/firefox/i.test(navigator.userAgent),Et.isAndroid=/android/i.test(navigator.userAgent),Et.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1);const z2={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Px={duration:0,easing:vn.easeInOutCubic},B2={CAMERA_MOVE:-10},wB=["top","right","bottom","left"],U2=0,Lb=2,Pp=1,H2=5,bB=128;var Cx={};const PB={},ij=Ir("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),sn={logPreventDefaults:Ir("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Ir("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Ir("logElementRemoves",{defaults:{all:!1}}),debugSvg:Ir("debugSvg",{defaults:{all:!1}}),showFps:Ir("showFps",{defaults:{all:!1}}),measurePerformance:Ir("measurePerformance",{defaults:{all:!1}}),throwToBlob:Ir("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Ir("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Ir("debugCursors",{defaults:{all:!1}}),forceSrgb:Ir("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Ir("debugGeometry",{defaults:{all:!1}}),hideShapes:Ir("hideShapes",{defaults:{all:!1}}),editOnType:Ir("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const n=Element.prototype.removeChild;To("element removal logging",()=>{sn.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),n.call(this,e)}:Element.prototype.removeChild=n})}function Ir(n,{defaults:e,shouldStoreForSession:t=!0}){return CB({name:n,defaults:e,shouldStoreForSession:t})}function CB(n){const e=IB(n),t=n.shouldStoreForSession?_B(n.name):null,r=dn(`debug:${n.name}`,t??e);return typeof window<"u"&&(n.shouldStoreForSession&&To(`debug:${n.name}`,()=>{const s=r.get();s===e?vM(`tldraw_debug:${n.name}`):sb(`tldraw_debug:${n.name}`,JSON.stringify(s))}),Object.defineProperty(window,`tldraw${n.name.replace(/^[a-z]/,s=>s.toUpperCase())}`,{get(){return r.get()},set(s){r.set(s)},configurable:!0})),Object.assign(r,n)}function _B(n){try{return JSON.parse(SM(`tldraw_debug:${n}`)??"null")}catch{return null}}function _x(n){try{return n()}catch{return null}}function IB(n){switch(_x(()=>Cx.TLDRAW_ENV)??_x(()=>Cx.VERCEL_PUBLIC_TLDRAW_ENV)??_x(()=>Cx.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return n.defaults.production??n.defaults.all;case"preview":case"staging":return n.defaults.staging??n.defaults.all;default:return n.defaults.development??n.defaults.all}}function Xf(n){if(n instanceof HTMLElement)return n;if(n.parentElement)return Xf(n.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Je(n){n.preventDefault(),sn.logPreventDefaults.get()&&console.warn("preventDefault called on event:",n)}function Wd(n,e){if(n.setPointerCapture(e.pointerId),sn.logPointerCaptures.get()){const t=ij.get();t.set(n,(t.get(n)??0)+1),console.warn("setPointerCapture called on element:",n,e)}}function Gd(n,e){if(n.hasPointerCapture(e.pointerId)&&(n.releasePointerCapture(e.pointerId),sn.logPointerCaptures.get())){const t=ij.get();t.get(n)===1?t.delete(n):t.has(n)?t.set(n,t.get(n)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",n,e)}}const ln=n=>n.stopPropagation(),Bn=(n,e,t)=>{n&&n.style.setProperty(e,t)},EB=["input","select","button","textarea"];function aj(){const{activeElement:n}=document;return!!(n&&(n.getAttribute("contenteditable")||EB.indexOf(n.tagName.toLowerCase())>-1))}const Gn=n=>Et.isDarwin?n.metaKey:n.ctrlKey||n.metaKey;function Zr(n){return n.isKilled=!0,{point:{x:n.clientX,y:n.clientY,z:n.pressure},shiftKey:n.shiftKey,altKey:n.altKey,ctrlKey:n.metaKey||n.ctrlKey,metaKey:n.metaKey,accelKey:Gn(n),pointerId:n.pointerId,button:n.button,isPen:n.pointerType==="pen"}}function Fb(){const n=te();return _.useMemo(function(){let r,s;function o(v){if(!v.isKilled){if(v.button===Lb){n.dispatch({type:"pointer",target:"canvas",name:"right_click",...Zr(v)});return}v.button!==0&&v.button!==1&&v.button!==5||(Wd(v.currentTarget,v),n.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Zr(v)}))}}function i(v){v.isKilled||v.clientX===r&&v.clientY===s||(r=v.clientX,s=v.clientY,n.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Zr(v)}))}function a(v){v.isKilled||v.button!==0&&v.button!==1&&v.button!==2&&v.button!==5||(r=v.clientX,s=v.clientY,Gd(v.currentTarget,v),n.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Zr(v)}))}function c(v){if(v.isKilled||n.getInstanceState().isPenMode&&v.pointerType!=="pen")return;const w=v.pointerType==="mouse"||v.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:w?!0:null})}function d(v){if(v.isKilled||n.getInstanceState().isPenMode&&v.pointerType!=="pen")return;const w=v.pointerType==="mouse"||v.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:w?!1:null})}function h(v){v.isKilled=!0,Je(v)}function f(v){v.isKilled=!0,v.target instanceof HTMLElement&&v.target.tagName!=="A"&&v.target.tagName!=="TEXTAREA"&&!(n.getEditingShape()&&v.target.className.includes("tl-text-content"))&&Je(v)}function g(v){Je(v)}async function y(v){var b,P;if(Je(v),ln(v),!((P=(b=v.dataTransfer)==null?void 0:b.files)!=null&&P.length))return;const w=Array.from(v.dataTransfer.files);await n.putExternalContent({type:"files",files:w,point:n.screenToPage({x:v.clientX,y:v.clientY}),ignoreParent:!1})}function S(v){ln(v)}return{onPointerDown:o,onPointerMove:i,onPointerUp:a,onPointerEnter:c,onPointerLeave:d,onDragOver:g,onDrop:y,onTouchStart:h,onTouchEnd:f,onClick:S}},[n])}function TB(){const n=te();_.useEffect(()=>{let e=n.getInstanceState().isCoarsePointer;const t=i=>{const a=i.pointerType!=="mouse";e!==a&&(e=a,n.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",t,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),s=Et.isFirefox&&!Et.isAndroid&&!Et.isIos,o=()=>{const i=s?!1:r.matches;e===i&&(e=i,n.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",o),o()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",o)}},[n])}const lj=_.createContext(null);function cj({container:n,children:e}){return p.jsx(lj.Provider,{value:n,children:e})}function fn(){return Ar(_.useContext(lj),"useContainer used outside of <Tldraw />")}function kB(){const n=te(),e=fn(),t=se("isFocused",()=>n.getIsFocused(),[n]);_.useEffect(()=>{if(!e)return;function r(s){if(s.isSpecialRedispatchedEvent)return;Je(s),ln(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]),_.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=c=>{c.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)},n.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{r==null||r()}},[n]),_.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(n.isIn("zoom")||!n.getPath().endsWith(".idle"))&&!Cp(n)&&Je(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Je(a);return}break}case"Tab":{if(Cp(n))return;break}case",":return;case"Escape":{if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&Je(a),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),e.focus());return}default:if(Cp(n))return}const c={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:Gn(a)};n.dispatch(c)},s=a=>{if(a.isKilled||(a.isKilled=!0,Cp(n))||a.key===",")return;const c={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:Gn(a)};n.dispatch(c)};function o(a){var c,d;if(e.contains(a.target)){const h=a.touches[0].pageX,f=a.touches[0].radiusX||0;(h-f<10||h+f>n.getViewportScreenBounds().width-10)&&(((c=a.target)==null?void 0:c.tagName)==="BUTTON"&&((d=a.target)==null||d.click()),Je(a))}}const i=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Je(a)};return e.addEventListener("touchstart",o,{passive:!1}),e.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Je),document.addEventListener("gesturechange",Je),document.addEventListener("gestureend",Je),e.addEventListener("keydown",r),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Je),document.removeEventListener("gesturechange",Je),document.removeEventListener("gestureend",Je),e.removeEventListener("keydown",r),e.removeEventListener("keyup",s)}},[n,e,t])}function Cp(n){return n.menus.hasOpenMenus()||aj()}const MB=["textarea","input"];function AB(n){const e=te();_.useEffect(()=>{const t=n.current;if(!t)return;const r=s=>{var o;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:i}=s;if(MB.includes((o=i.tagName)==null?void 0:o.toLocaleLowerCase())||e.isIn("select.editing_shape"))return;Je(s)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[e,n])}function jB(n,e,t){return Math.max(e,Math.min(n,t))}const Mn={toVector(n,e){return n===void 0&&(n=e),Array.isArray(n)?n:[n,n]},add(n,e){return[n[0]+e[0],n[1]+e[1]]},sub(n,e){return[n[0]-e[0],n[1]-e[1]]},addTo(n,e){n[0]+=e[0],n[1]+=e[1]},subTo(n,e){n[0]-=e[0],n[1]-=e[1]}};function K2(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function W2(n,e,t,r=.15){return r===0?jB(n,e,t):n<e?-K2(e-n,t-e,r)+e:n>t?+K2(n-t,t-e,r)+t:n}function RB(n,[e,t],[r,s]){const[[o,i],[a,c]]=n;return[W2(e,o,i,r),W2(t,a,c,s)]}function OB(n,e){if(typeof n!="object"||n===null)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var r=t.call(n,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(n)}function DB(n){var e=OB(n,"string");return typeof e=="symbol"?e:String(e)}function Hn(n,e,t){return e=DB(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function G2(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(n,s).enumerable})),t.push.apply(t,r)}return t}function qt(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?G2(Object(t),!0).forEach(function(r){Hn(n,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):G2(Object(t)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))})}return n}const uj={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 V2(n){return n?n[0].toUpperCase()+n.slice(1):""}const LB=["enter","leave"];function FB(n=!1,e){return n&&!LB.includes(e)}function NB(n,e="",t=!1){const r=uj[n],s=r&&r[e]||e;return"on"+V2(n)+V2(s)+(FB(t,s)?"Capture":"")}const $B=["gotpointercapture","lostpointercapture"];function zB(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const r=$B.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function BB(n,e=""){const t=uj[n],r=t&&t[e]||e;return n+r}function dj(n){return"touches"in n}function UB(n){return dj(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function HB(n){return Array.from(n.touches).filter(e=>{var t,r;return e.target===n.currentTarget||((t=n.currentTarget)===null||t===void 0||(r=t.contains)===null||r===void 0?void 0:r.call(t,e.target))})}function Vw(n,e){try{const t=e.clientX-n.clientX,r=e.clientY-n.clientY,s=(e.clientX+n.clientX)/2,o=(e.clientY+n.clientY)/2,i=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function KB(n){return HB(n).map(e=>e.identifier)}function q2(n,e){const[t,r]=Array.from(n.touches).filter(s=>e.includes(s.identifier));return Vw(t,r)}const Y2=40,X2=800;function hj(n){let{deltaX:e,deltaY:t,deltaMode:r}=n;return r===1?(e*=Y2,t*=Y2):r===2&&(e*=X2,t*=X2),[e,t]}function WB(n){const e={};if("buttons"in n&&(e.buttons=n.buttons),"shiftKey"in n){const{shiftKey:t,altKey:r,metaKey:s,ctrlKey:o}=n;Object.assign(e,{shiftKey:t,altKey:r,metaKey:s,ctrlKey:o})}return e}function Zf(n,...e){return typeof n=="function"?n(...e):n}function GB(){}function VB(...n){return n.length===0?GB:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function Z2(n,e){return Object.assign({},e,n||{})}const qB=32;class pj{constructor(e,t,r){this.ctrl=e,this.args=t,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:t,ingKey:r,args:s}=this;t[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 t=this.state,r=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=r.from?Zf(r.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:r,shared:s}=this;t.args=this.args;let o=0;if(e&&(t.event=e,r.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,WB(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const A=t._delta.map(Math.abs);Mn.addTo(t._distance,A)}this.axisIntent&&this.axisIntent(e);const[i,a]=t._movement,[c,d]=r.threshold,{_step:h,values:f}=t;if(r.hasCustomTransform?(h[0]===!1&&(h[0]=Math.abs(i)>=c&&f[0]),h[1]===!1&&(h[1]=Math.abs(a)>=d&&f[1])):(h[0]===!1&&(h[0]=Math.abs(i)>=c&&Math.sign(i)*c),h[1]===!1&&(h[1]=Math.abs(a)>=d&&Math.sign(a)*d)),t.intentional=h[0]!==!1||h[1]!==!1,!t.intentional)return;const g=[0,0];if(r.hasCustomTransform){const[A,R]=f;g[0]=h[0]!==!1?A-h[0]:0,g[1]=h[1]!==!1?R-h[1]:0}else g[0]=h[0]!==!1?i-h[0]:0,g[1]=h[1]!==!1?a-h[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(g);const y=t.offset,S=t._active&&!t._blocked||t.active;S&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=s[this.ingKey]=t._active,e&&(t.first&&("bounds"in r&&(t._bounds=Zf(r.bounds,t)),this.setup&&this.setup()),t.movement=g,this.computeOffset()));const[v,w]=t.offset,[[b,P],[k,E]]=t._bounds;t.overflow=[v<b?-1:v>P?1:0,w<k?-1:w>E?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const M=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=RB(t._bounds,t.offset,M),t.delta=Mn.sub(t.offset,y),this.computeMovement(),S&&(!t.last||o>qB)){t.delta=Mn.sub(t.offset,y);const A=t.delta.map(Math.abs);Mn.addTo(t.distance,A),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&o>0&&(t.velocity=[A[0]/o,A[1]/o],t.timeDelta=o)}}emit(){const e=this.state,t=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const s=this.handler(qt(qt(qt({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function YB([n,e],t){const r=Math.abs(n),s=Math.abs(e);if(r>s&&r>t)return"x";if(s>r&&s>t)return"y"}class XB extends pj{constructor(...e){super(...e),Hn(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=Mn.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Mn.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,r=this.config;if(!t.axis&&e){const s=typeof r.axisThreshold=="object"?r.axisThreshold[UB(e)]:r.axisThreshold;t.axis=YB(t._movement,s)}t._blocked=(r.lockDirection||!!r.axis)&&!t.axis||!!r.axis&&r.axis!==t.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 ZB=n=>n,Q2=.15,fj={enabled(n=!0){return n},eventOptions(n,e,t){return qt(qt({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[Q2,Q2];case!1:return[0,0];default:return Mn.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return Mn.toVector(n)},transform(n,e,t){const r=n||t.shared.transform;return this.hasCustomTransform=!!r,r||ZB},threshold(n){return Mn.toVector(n,0)}},QB=0,Vd=qt(qt({},fj),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=QB){return n},bounds(n={}){if(typeof n=="function")return o=>Vd.bounds(n(o));if("current"in n)return()=>n.current;if(typeof HTMLElement=="function"&&n instanceof HTMLElement)return n;const{left:e=-1/0,right:t=1/0,top:r=-1/0,bottom:s=1/0}=n;return[[e,t],[r,s]]}}),qd=typeof window<"u"&&window.document&&window.document.createElement;function gj(){return qd&&"ontouchstart"in window}function JB(){return gj()||qd&&window.navigator.maxTouchPoints>1}function e7(){return qd&&"onpointerdown"in window}function t7(){return qd&&"exitPointerLock"in window.document}function n7(){try{return"constructor"in GestureEvent}catch{return!1}}const ws={isBrowser:qd,gesture:n7(),touch:gj(),touchscreen:JB(),pointer:e7(),pointerLock:t7()},r7=250,s7=180,o7=.5,i7=50,a7=250,l7=10,J2={mouse:0,touch:0,pen:8};qt(qt({},Vd),{},{device(n,e,{pointer:{touch:t=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&ws.pointerLock,ws.touch&&t?"touch":this.pointerLock?"mouse":ws.pointer&&!s?"pointer":ws.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?r7:void 0,!(!ws.touchscreen||t===!1))return n||(t!==void 0?"y":void 0)},pointerCapture(n,e,{pointer:{capture:t=!0,buttons:r=1,keys:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&t},threshold(n,e,{filterTaps:t=!1,tapsThreshold:r=3,axis:s=void 0}){const o=Mn.toVector(n,t?r:s?1:0);return this.filterTaps=t,this.tapsThreshold=r,o},swipe({velocity:n=o7,distance:e=i7,duration:t=a7}={}){return{velocity:this.transform(Mn.toVector(n)),distance:this.transform(Mn.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return s7;case!1:return 0;default:return n}},axisThreshold(n){return n?qt(qt({},J2),n):J2},keyboardDisplacement(n=l7){return n}});function mj(n){const[e,t]=n.overflow,[r,s]=n._delta,[o,i]=n._direction;(e<0&&r>0&&o<0||e>0&&r<0&&o>0)&&(n._movement[0]=n._movementBound[0]),(t<0&&s>0&&i<0||t>0&&s<0&&i>0)&&(n._movement[1]=n._movementBound[1])}const c7=30,u7=100;class d7 extends pj{constructor(...e){super(...e),Hn(this,"ingKey","pinching"),Hn(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:t,lastOffset:r}=this.state;e==="wheel"?this.state.offset=Mn.add(t,r):this.state.offset=[(1+t[0])*r[0],t[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:t}=this.state;this.state.movement=[e[0]/t[0],e[1]-t[1]]}axisIntent(){const e=this.state,[t,r]=e._movement;if(!e.axis){const s=Math.abs(t)*c7-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 t=this.state,r=this.ctrl.touchIds;if(t._active&&t._touchIds.every(o=>r.has(o))||r.size<2)return;this.start(e),t._touchIds=Array.from(r).slice(0,2);const s=q2(e,t._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 t=this.state,r=t._pointerEvents,s=this.ctrl.pointerIds;if(t._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(e.pointerId,e),t._pointerEvents.size<2))return;this.start(e);const o=Vw(...Array.from(r.values()));o&&this.pinchStart(e,o)}pinchStart(e,t){const r=this.state;r.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const t=q2(e,this.state._touchIds);t&&this.pinchMove(e,t)}pointerMove(e){const t=this.state._pointerEvents;if(t.has(e.pointerId)&&t.set(e.pointerId,e),!this.state._active)return;const r=Vw(...Array.from(t.values()));r&&this.pinchMove(e,r)}pinchMove(e,t){const r=this.state,s=r._values[1],o=t.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),this.computeValues([t.distance,t.angle-360*i]),r.origin=t.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(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const t=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}t._pointerEvents.has(e.pointerId)&&t._pointerEvents.delete(e.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const t=this.state;t._active||(this.start(e),this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY];const r=t._movement;t._movement=[e.scale-1,e.rotation],t._delta=Mn.sub(t._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const t=this.config.modifierKey;t&&(Array.isArray(t)?!t.find(r=>e[r]):!e[t])||(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=[-hj(e)[1]/u7*r.offset[0],0],Mn.addTo(r._movement,r._delta),mj(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 t=this.config.device;t&&(e(t,"start",this[t+"Start"].bind(this)),e(t,"change",this[t+"Move"].bind(this)),e(t,"end",this[t+"End"].bind(this)),e(t,"cancel",this[t+"End"].bind(this)),e("lostPointerCapture","",this[t+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const h7=qt(qt({},fj),{},{device(n,e,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!ws.touch&&ws.gesture)return"gesture";if(ws.touch&&r)return"touch";if(ws.touchscreen){if(ws.pointer)return"pointer";if(ws.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:r={}}){const s=i=>{const a=Z2(Zf(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=Z2(Zf(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(i)]},threshold(n,e,t){return this.lockDirection=t.axis==="lock",Mn.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});qt(qt({},Vd),{},{mouseOnly:(n=!0)=>n});class p7 extends XB{constructor(...e){super(...e),Hn(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 t=this.state;t._delta=hj(e),Mn.addTo(t._movement,t._delta),mj(t),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 f7=Vd;qt(qt({},Vd),{},{mouseOnly:(n=!0)=>n});const Nb=new Map,qw=new Map;function g7(n){Nb.set(n.key,n.engine),qw.set(n.key,n.resolver)}const m7={key:"pinch",engine:d7,resolver:h7},y7={key:"wheel",engine:p7,resolver:f7};function S7(n,e){if(n==null)return{};var t={},r=Object.keys(n),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(t[s]=n[s]);return t}function v7(n,e){if(n==null)return{};var t=S7(n,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(n);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(n,r)&&(t[r]=n[r])}return t}const x7={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=ws.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},w7=["target","eventOptions","window","enabled","transform"];function rf(n={},e){const t={};for(const[r,s]of Object.entries(e))switch(typeof s){case"function":t[r]=s.call(t,n[r],r,n);break;case"object":t[r]=rf(n[r],s);break;case"boolean":s&&(t[r]=n[r]);break}return t}function b7(n,e,t={}){const r=n,{target:s,eventOptions:o,window:i,enabled:a,transform:c}=r,d=v7(r,w7);if(t.shared=rf({target:s,eventOptions:o,window:i,enabled:a,transform:c},x7),e){const h=qw.get(e);t[e]=rf(qt({shared:t.shared},d),h)}else for(const h in d){const f=qw.get(h);f&&(t[h]=rf(qt({shared:t.shared},d[h]),f))}return t}class yj{constructor(e,t){Hn(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,r,s,o){const i=this._listeners,a=BB(t,r),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},d=qt(qt({},c),o);e.addEventListener(a,s,d);const h=()=>{e.removeEventListener(a,s,d),i.delete(h)};return i.add(h),h}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class P7{constructor(){Hn(this,"_timeouts",new Map)}add(e,t,r=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(t,r,...s))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class C7{constructor(e){Hn(this,"gestures",new Set),Hn(this,"_targetEventStore",new yj(this)),Hn(this,"gestureEventStores",{}),Hn(this,"gestureTimeoutStores",{}),Hn(this,"handlers",{}),Hn(this,"config",{}),Hn(this,"pointerIds",new Set),Hn(this,"touchIds",new Set),Hn(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),_7(this,e)}setEventIds(e){if(dj(e))return this.touchIds=new Set(KB(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,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=b7(e,t,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 t=this.config.shared,r={};let s;if(!(t.target&&(s=t.target(),!s))){if(t.enabled){for(const i of this.gestures){const a=this.config[i],c=eT(r,a.eventOptions,!!s);if(a.enabled){const d=Nb.get(i);new d(this,e,i).bind(c)}}const o=eT(r,t.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](qt(qt({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const o in r)r[o]=VB(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:c}=zB(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:c})}}}}function oc(n,e){n.gestures.add(e),n.gestureEventStores[e]=new yj(n,e),n.gestureTimeoutStores[e]=new P7}function _7(n,e){e.drag&&oc(n,"drag"),e.wheel&&oc(n,"wheel"),e.scroll&&oc(n,"scroll"),e.move&&oc(n,"move"),e.pinch&&oc(n,"pinch"),e.hover&&oc(n,"hover")}const eT=(n,e,t)=>(r,s,o,i={},a=!1)=>{var c,d;const h=(c=i.capture)!==null&&c!==void 0?c:e.capture,f=(d=i.passive)!==null&&d!==void 0?d:e.passive;let g=a?r:NB(r,s,h);t&&f&&(g+="Passive"),n[g]=n[g]||[],n[g].push(o)},I7=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function E7(n){const e={},t={},r=new Set;for(let s in n)I7.test(s)?(r.add(RegExp.lastMatch),t[s]=n[s]):e[s]=n[s];return[t,e,r]}function ic(n,e,t,r,s,o){if(!n.has(t)||!Nb.has(r))return;const i=t+"Start",a=t+"End",c=d=>{let h;return d.first&&i in e&&e[i](d),t in e&&(h=e[t](d)),d.last&&a in e&&e[a](d),h};s[r]=c,o[r]=o[r]||{}}function T7(n,e){const[t,r,s]=E7(n),o={};return ic(s,t,"onDrag","drag",o,e),ic(s,t,"onWheel","wheel",o,e),ic(s,t,"onScroll","scroll",o,e),ic(s,t,"onPinch","pinch",o,e),ic(s,t,"onMove","move",o,e),ic(s,t,"onHover","hover",o,e),{handlers:o,config:e,nativeHandlers:r}}function k7(n,e={},t,r){const s=at.useMemo(()=>new C7(n),[]);if(s.applyHandlers(n,r),s.applyConfig(e,t),at.useEffect(s.effect.bind(s)),at.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function M7(n){return n.forEach(g7),function(t,r){const{handlers:s,nativeHandlers:o,config:i}=T7(t,r||{});return k7(s,i,void 0,o)}}const tT=10,A7=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function Sj(n){let{deltaY:e,deltaX:t}=n,r=0;return n.ctrlKey||n.altKey||n.metaKey?r=(Math.abs(e)>tT?tT*Math.sign(e):e)/100:n.shiftKey&&!A7&&(t=e,e=0),{x:-t,y:-e,z:-r}}const j7=M7([y7,m7]);let ac;const R7=n=>ac===void 0?(ac=n,!1):n-ac>120&&n-ac<160?(ac=n,!0):(ac=n,!1);function O7(n){const e=te(),t=_.useMemo(()=>{let r="not sure";const s=({event:v})=>{if(!e.getInstanceState().isFocused||(r="not sure",R7(Date.now())))return;const w=e.getEditingShapeId();if(w){const k=e.getShape(w);if(k&&e.getShapeUtil(k).canScroll(k)){const M=e.getShapePageBounds(w);if(M!=null&&M.containsPoint(e.inputs.currentPagePoint))return}}Je(v),ln(v);const b=Sj(v);if(b.x===0&&b.y===0)return;const P={type:"wheel",name:"wheel",delta:b,point:new C(v.clientX,v.clientY),shiftKey:v.shiftKey,altKey:v.altKey,ctrlKey:v.metaKey||v.ctrlKey,metaKey:v.metaKey,accelKey:Gn(v)};e.dispatch(P)};let o=1,i=1,a=1,c=0;const d=new C,h=new C,f=v=>{const w=n.current;r="not sure";const{event:b,origin:P,da:k}=v;b instanceof WheelEvent||(b.target===w||w!=null&&w.contains(b.target))&&(h.x=P[0],h.y=P[1],d.x=P[0],d.y=P[1],o=k[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:P[0],y:P[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Gn(b)}))},g=v=>{if(v&&(r="zooming"),r==="zooming")return;const w=Math.abs(c-o),b=C.Dist(d,h);switch(r){case"not sure":{w>24?r="zooming":b>16&&(r="panning");break}case"panning":{w>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:f,onPinchEnd:v=>{const w=n.current,{event:b,origin:P,offset:k}=v;if(b instanceof WheelEvent||!(b.target===w||w!=null&&w.contains(b.target)))return;const E=k[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:P[0],y:P[1],z:E},delta:{x:P[0],y:P[1]},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Gn(b)})})},onPinch:v=>{const w=n.current,{event:b,origin:P,offset:k,da:E}=v;if(b instanceof WheelEvent||!(b.target===w||w!=null&&w.contains(b.target)))return;const M=v.type==="gesturechange"||v.type==="gestureend";c=E[0];const A=P[0]-h.x,R=P[1]-h.y;switch(h.x=P[0],h.y=P[1],g(M),r){case"zooming":{a=k[0],e.dispatch({type:"pinch",name:"pinch",point:{x:P[0],y:P[1],z:a},delta:{x:A,y:R},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Gn(b)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:P[0],y:P[1],z:i},delta:{x:A,y:R},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Gn(b)});break}}}}},[e,n]);j7(t,{target:n,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 Ix(n,e,t){const r=n.getShape(e),s=n.getShapeHandles(r);return{shape:r,handle:s.find(o=>o.id===t)}}function D7(n,e){const t=te();return _.useMemo(()=>{const r=c=>{if(c.isKilled)return;const d=Xf(c.currentTarget);Wd(d,c);const{shape:h,handle:f}=Ix(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:h,name:"pointer_down",...Zr(c)})};let s,o;return{onPointerDown:r,onPointerMove:c=>{if(c.isKilled||c.clientX===s&&c.clientY===o)return;s=c.clientX,o=c.clientY;const{shape:d,handle:h}=Ix(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:d,name:"pointer_move",...Zr(c)})},onPointerUp:c=>{if(c.isKilled)return;const d=Xf(c.currentTarget);Gd(d,c);const{shape:h,handle:f}=Ix(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:h,name:"pointer_up",...Zr(c)})}}},[t,n,e])}function L7(n){const e=te();_.useLayoutEffect(()=>{const t=Zk(()=>{n.current&&e.updateViewportScreenBounds(n.current)},200,{trailing:!0}),r=e.timers.setInterval(t,1e3);window.addEventListener("resize",t);const s=new ResizeObserver(a=>{a[0].contentRect&&t()}),o=n.current;let i=null;return o&&(s.observe(o),i=F7(o),i.addEventListener("scroll",t)),()=>{clearInterval(r),window.removeEventListener("resize",t),s.disconnect(),i==null||i.removeEventListener("scroll",t),t.cancel()}},[e,n])}/*!
|
|
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 F7=n=>{let e=n.parentElement;for(;e;){if(e===document.body)return document;const{overflowY:t}=window.getComputedStyle(e);if(e.scrollHeight>e.clientHeight&&(t==="auto"||t==="scroll"||t==="overlay"))return e;e=e.parentElement}return document};class Se{constructor(e=0,t=0,r=0,s=0){j(this,"x",0);j(this,"y",0);j(this,"w",0);j(this,"h",0);this.x=e,this.y=t,this.w=r,this.h=s}get point(){return new C(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 C(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 C(this.minX,this.minY),new C(this.maxX,this.minY),new C(this.maxX,this.maxY),new C(this.minX,this.maxY)]}get cornersAndCenter(){return[new C(this.minX,this.minY),new C(this.maxX,this.minY),new C(this.maxX,this.maxY),new C(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 C(this.w,this.h)}toFixed(){return this.x=yp(this.x),this.y=yp(this.y),this.w=yp(this.w),this.h=yp(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,t=0,r=0,s=0){return this.x=e,this.y=t,this.w=r,this.h=s,this}expand(e){const t=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=t,this.y=r,this.w=s-t,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:t,w:r,h:s}=this;return new Se(e,t,r,s)}translate(e){return this.x+=e.x,this.y+=e.y,this}snapToGrid(e){const t=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=t,this.minY=r,this.width=Math.max(1,s-t),this.height=Math.max(1,o-r)}collides(e){return Se.Collides(this,e)}contains(e){return Se.Contains(this,e)}includes(e){return Se.Includes(this,e)}containsPoint(e,t=0){return Se.ContainsPoint(this,e,t)}getHandlePoint(e){switch(e){case"top_left":return new C(this.minX,this.minY);case"top_right":return new C(this.maxX,this.minY);case"bottom_left":return new C(this.minX,this.maxY);case"bottom_right":return new C(this.maxX,this.maxY);case"top":return new C(this.midX,this.minY);case"right":return new C(this.maxX,this.midY);case"bottom":return new C(this.midX,this.maxY);case"left":return new C(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(e,t,r){const{minX:s,minY:o,maxX:i,maxY:a}=this;let{minX:c,minY:d,maxX:h,maxY:f}=this;switch(e){case"left":case"top_left":case"bottom_left":{c+=t;break}case"right":case"top_right":case"bottom_right":{h+=t;break}}switch(e){case"top":case"top_left":case"top_right":{d+=r;break}case"bottom":case"bottom_left":case"bottom_right":{f+=r;break}}const g=(h-c)/(i-s),y=(f-d)/(a-o),S=g<0,v=y<0;if(S){const w=h;h=c,c=w}if(v){const w=f;f=d,d=w}this.minX=c,this.minY=d,this.width=Math.abs(h-c),this.height=Math.abs(f-d)}union(e){const t=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=t,this.y=r,this.width=s-t,this.height=o-r,this}static From(e){return new Se(e.x,e.y,e.w,e.h)}static FromCenter(e,t){return new Se(e.x-t.x/2,e.y-t.y/2,t.x,t.y)}static FromPoints(e){if(e.length===0)return new Se;let t=1/0,r=1/0,s=-1/0,o=-1/0,i;for(let a=0,c=e.length;a<c;a++)i=e[a],t=Math.min(i.x,t),r=Math.min(i.y,r),s=Math.max(i.x,s),o=Math.max(i.y,o);return new Se(t,r,s-t,o-r)}static Expand(e,t){const r=Math.min(t.minX,e.minX),s=Math.min(t.minY,e.minY),o=Math.max(t.maxX,e.maxX),i=Math.max(t.maxY,e.maxY);return new Se(r,s,o-r,i-s)}static ExpandBy(e,t){return new Se(e.minX-t,e.minY-t,e.width+t*2,e.height+t*2)}static Collides(e,t){return!(e.maxX<t.minX||e.minX>t.maxX||e.maxY<t.minY||e.minY>t.maxY)}static Contains(e,t){return e.minX<t.minX&&e.minY<t.minY&&e.maxY>t.maxY&&e.maxX>t.maxX}static Includes(e,t){return Se.Collides(e,t)||Se.Contains(e,t)}static ContainsPoint(e,t,r=0){return!(t.x<e.minX-r||t.y<e.minY-r||t.x>e.maxX+r||t.y>e.maxY+r)}static Common(e){let t=1/0,r=1/0,s=-1/0,o=-1/0;for(let i=0;i<e.length;i++){const a=e[i];t=Math.min(t,a.minX),r=Math.min(r,a.minY),s=Math.max(s,a.maxX),o=Math.max(o,a.maxY)}return new Se(t,r,s-t,o-r)}static Sides(e,t=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,t,r,s,o=!1){const{minX:i,minY:a,maxX:c,maxY:d}=e;let{minX:h,minY:f,maxX:g,maxY:y}=e;switch(t){case"left":case"top_left":case"bottom_left":{h+=r;break}case"right":case"top_right":case"bottom_right":{g+=r;break}}switch(t){case"top":case"top_left":case"top_right":{f+=s;break}case"bottom":case"bottom_left":case"bottom_right":{y+=s;break}}const S=(g-h)/(c-i),v=(y-f)/(d-a),w=S<0,b=v<0;if(o){const k=(c-i)/(d-a),E=Math.abs(g-h),M=Math.abs(y-f),A=E*(v<0?1:-1)*(1/k),R=M*(S<0?1:-1)*k,D=k<E/M;switch(t){case"top_left":{D?f=y+A:h=g+R;break}case"top_right":{D?f=y+A:g=h-R;break}case"bottom_right":{D?y=f-A:g=h-R;break}case"bottom_left":{D?y=f-A:h=g+R;break}case"bottom":case"top":{const V=(h+g)/2,L=M*k;h=V-L/2,g=V+L/2;break}case"left":case"right":{const V=(f+y)/2,L=E/k;f=V-L/2,y=V+L/2;break}}}if(w){const k=g;g=h,h=k}if(b){const k=y;y=f,f=k}const P=new Se(h,f,Math.abs(g-h),Math.abs(y-f));return{box:P,scaleX:+(P.width/e.width*(S>0?1:-1)).toFixed(5),scaleY:+(P.height/e.height*(v>0?1:-1)).toFixed(5)}}equals(e){return Se.Equals(this,e)}static Equals(e,t){return t.x===e.x&&t.y===e.y&&t.w===e.w&&t.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 Se(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function N7(n){switch(n){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 n}}function $7(n){switch(n){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 n}}function z7(n){return n==="top_left"||n==="top_right"||n==="bottom_right"||n==="bottom_left"}class me{constructor(e,t,r,s,o,i){j(this,"a",1);j(this,"b",0);j(this,"c",0);j(this,"d",1);j(this,"e",0);j(this,"f",0);this.a=e,this.b=t,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 t=e,{a:r,b:s,c:o,d:i,e:a,f:c}=this;return this.a=r*t.a+o*t.b,this.c=r*t.c+o*t.d,this.e=r*t.e+o*t.f+a,this.b=s*t.a+i*t.b,this.d=s*t.c+i*t.d,this.f=s*t.e+i*t.f+c,this}rotate(e,t,r){return e===0?this:t===void 0?this.multiply(me.Rotate(e)):this.translate(t,r).multiply(me.Rotate(e)).translate(-t,-r)}translate(e,t){return this.multiply(me.Translate(e,t))}scale(e,t){return this.multiply(me.Scale(e,t))}invert(){const{a:e,b:t,c:r,d:s,e:o,f:i}=this,a=e*s-t*r;return this.a=s/a,this.b=t/-a,this.c=r/-a,this.d=e/a,this.e=(s*o-r*i)/-a,this.f=(t*o-e*i)/a,this}applyToPoint(e){return me.applyToPoint(this,e)}applyToPoints(e){return me.applyToPoints(this,e)}rotation(){return me.Rotation(this)}point(){return me.Point(this)}decomposed(){return me.Decompose(this)}toCssString(){return me.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return me.Decompose(this)}clone(){return new me(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new me(1,0,0,1,0,0)}static Translate(e,t){return new me(1,0,0,1,e,t)}static Rotate(e,t,r){if(e===0)return me.Identity();const s=Math.cos(e),o=Math.sin(e),i=new me(s,o,-o,s,0,0);return t===void 0?i:me.Compose(me.Translate(t,r),i,me.Translate(-t,-r))}static Scale(e,t,r,s){const o=new me(e,0,0,t,0,0);return r===void 0?o:me.Compose(me.Translate(r,s),o,me.Translate(-r,-s))}static Multiply(e,t){return{a:e.a*t.a+e.c*t.b,c:e.a*t.c+e.c*t.d,e:e.a*t.e+e.c*t.f+e.e,b:e.b*t.a+e.d*t.b,d:e.b*t.c+e.d*t.d,f:e.b*t.e+e.d*t.f+e.f}}static Inverse(e){const t=e.a*e.d-e.b*e.c;return{a:e.d/t,b:e.b/-t,c:e.c/-t,d:e.a/t,e:(e.d*e.e-e.c*e.f)/-t,f:(e.b*e.e-e.a*e.f)/t}}static Absolute(e){const t=e.a*e.d-e.b*e.c;return{a:e.d/t,b:e.b/-t,c:e.c/-t,d:e.a/t,e:(e.d*e.e-e.c*e.f)/t,f:(e.b*e.e-e.a*e.f)/-t}}static Compose(...e){const t=me.Identity();for(let r=0,s=e.length;r<s;r++)t.multiply(e[r]);return t}static Point(e){return new C(e.e,e.f)}static Rotation(e){let t;if(e.a!==0||e.c!==0){const r=(e.a*e.a+e.c*e.c)**.5;t=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;t=Rt+Math.acos(e.b/r)*(e.d>0?-1:1)}else t=0;return Nw(t)}static Decompose(e){let t,r,s;if(e.a!==0||e.c!==0){const o=(e.a*e.a+e.c*e.c)**.5;t=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;t=(e.a*e.d-e.b*e.c)/o,r=o,s=Rt+Math.acos(e.b/o)*(e.d>0?-1:1)}else t=0,r=0,s=0;return{x:e.e,y:e.f,scaleX:t,scaleY:r,rotation:Nw(s)}}static Smooth(e,t=1e10){return e.a=Math.round(e.a*t)/t,e.b=Math.round(e.b*t)/t,e.c=Math.round(e.c*t)/t,e.d=Math.round(e.d*t)/t,e.e=Math.round(e.e*t)/t,e.f=Math.round(e.f*t)/t,e}static toCssString(e){return`matrix(${ee(e.a)}, ${ee(e.b)}, ${ee(e.c)}, ${ee(e.d)}, ${ee(e.e)}, ${ee(e.f)})`}static applyToPoint(e,t){return new C(e.a*t.x+e.c*t.y+e.e,e.b*t.x+e.d*t.y+e.f,t.z)}static applyToXY(e,t,r){return[e.a*t+e.c*r+e.e,e.b*t+e.d*r+e.f]}static applyToPoints(e,t){return t.map(r=>new C(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,t){return new Se(e.e+t.minX,e.f+t.minY,t.width,t.height)}static From(e){return new me(e.a,e.b,e.c,e.d,e.e,e.f)}static Cast(e){return e instanceof me?e:me.From(e)}}class ba{constructor(e){j(this,"isFilled",!1);j(this,"isClosed",!0);j(this,"isLabel",!1);j(this,"debugColor");j(this,"ignore");j(this,"_vertices");j(this,"_bounds");j(this,"_area");j(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,t=0,r=!1){return this.isClosed&&(this.isFilled||r)&&Jr(e,this.vertices)?!0:C.Dist2(e,this.nearestPoint(e))<=t*t}distanceToPoint(e,t=!1){return e.dist(this.nearestPoint(e))*(this.isClosed&&(this.isFilled||t)&&Jr(e,this.vertices)?-1:1)}distanceToLineSegment(e,t){if(e.equals(t))return this.distanceToPoint(e);const{vertices:r}=this;let s,o=1/0,i,a,c;for(let d=0;d<r.length;d++)a=r[d],c=C.NearestPointOnLineSegment(e,t,a,!0),i=C.Dist2(a,c),i<o&&(o=i,s=c);if(!s)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Jr(s,this.vertices)?-o:o}hitTestLineSegment(e,t,r=0){return this.distanceToLineSegment(e,t)<=r}nearestPointOnLineSegment(e,t){const{vertices:r}=this;let s,o=1/0,i,a,c;for(let d=0;d<r.length;d++)a=r[d],c=C.NearestPointOnLineSegment(e,t,a,!0),i=C.Dist2(a,c),i<o&&(o=i,s=c);if(!s)throw Error("nearest point not found");return s}isPointInBounds(e,t=0){const{bounds:r}=this;return!(e.x<r.minX-t||e.y<r.minY-t||e.x>r.maxX+t||e.y>r.maxY+t)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return Se.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 t=0;for(let r=0,s=e.length;r<s;r++){const o=e[r],i=e[(r+1)%s];t+=o.x*i.y-i.x*o.y}return t/2}toSimpleSvgPath(){let e="";const{vertices:t}=this,r=t.length;if(r===0)return e;e+=`M${t[0].x},${t[0].y}`;for(let s=1;s<r;s++)e+=`L${t[s].x},${t[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 t,r=e[0],s=0;for(let o=1;o<e.length;o++)t=e[o],s+=C.Dist2(r,t),r=t;return Math.sqrt(s)}}class Is extends ba{constructor(t){super({...t,isClosed:!0,isFilled:!1});j(this,"children",[]);j(this,"ignoredChildren",[]);for(const r of t.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(t=>!t.isLabel).flatMap(t=>t.vertices)}nearestPoint(t){let r=1/0,s;const{children:o}=this;if(o.length===0)throw Error("no children");let i,a;for(const c of o)i=c.nearestPoint(t),a=C.Dist2(i,t),a<r&&(r=a,s=i);if(!s)throw Error("nearest point not found");return s}distanceToPoint(t,r=!1){return Math.min(...this.children.map((s,o)=>s.distanceToPoint(t,r||o>0)))}hitTestPoint(t,r,s){return!!this.children.filter(o=>!o.isLabel).find(o=>o.hitTestPoint(t,r,s))}hitTestLineSegment(t,r,s){return!!this.children.filter(o=>!o.isLabel).find(o=>o.hitTestLineSegment(t,r,s))}getArea(){return this.children[0].area}toSimpleSvgPath(){let t="";for(const s of this.children)t+=s.toSimpleSvgPath();const r=Se.FromPoints(this.vertices).corners;for(let s=0,o=r.length;s<o;s++){const i=r[s],a=r[(s-1+o)%o],c=i.dist(a),d=r[(s+1)%o],h=i.dist(d),f=i.clone().lrp(a,4/c),g=i,y=i.clone().lrp(d,4/h);t+=`M${f.x},${f.y} L${g.x},${g.y} L${y.x},${y.y} `}return t}getLength(){return this.children.reduce((t,r)=>r.isLabel?t:t+r.length,0)}getSvgPathData(){return this.children.map((t,r)=>t.isLabel?"":t.getSvgPathData(r===0)).join(" ")}}function B7(n=!0){const[e,t]=_.useState(0),r=te();_.useEffect(()=>{if(!n)return;const s=()=>t(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const U7=jn(function({showStroke:e=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const s=te();B7(r);const o=s.getZoomLevel(),i=s.getRenderingShapes(),{inputs:{currentPagePoint:a}}=s;return p.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(c=>{const d=s.getShape(c.id);if(d.type==="group")return null;const h=s.getShapeGeometry(d),f=s.getShapePageTransform(d),g=s.getPointInShapeSpace(d,a),y=h.nearestPoint(g),S=h.distanceToPoint(g,!0),v=Math.abs(S)*o,w=S<0,{vertices:b}=h;return p.jsxs("g",{transform:f.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&p.jsx("g",{stroke:h.debugColor??"red",opacity:"1",strokeWidth:2/o,fill:"none",children:p.jsx(vj,{geometry:h})}),t&&b.map((P,k)=>p.jsx("circle",{cx:P.x,cy:P.y,r:2/o,fill:`hsl(${Ac(k,[0,b.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/o},`v${k}`)),r&&v<150&&p.jsx("line",{x1:y.x,y1:y.y,x2:g.x,y2:g.y,opacity:1-v/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:2/o})]},c.id+"_outline")})})});function vj({geometry:n}){return n instanceof Is?p.jsx(p.Fragment,{children:[...n.children,...n.ignoredChildren].map((e,t)=>p.jsx(vj,{geometry:e},t))}):p.jsx("path",{d:n.toSimpleSvgPath()})}function xj(n){return m6(n)}function wj(){const n=te(),e=_8("userIds",()=>xj(n.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>{var s;return t.join(",")===((s=r.join)==null?void 0:s.call(r,","))}},[n]);return se(e)}function Mg(n){const e=te();return se(`latestPresence:${n}`,()=>e.getCollaborators().find(r=>r.userId===n),[e,n])??null}const H7=jn(function(){return wj().map(t=>p.jsx(K7,{collaboratorId:t},t))}),K7=jn(function({collaboratorId:e}){const t=te(),r=Mg(e),s=G7(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(s){case"inactive":{const{followingUserId:o,highlightedUserIds:i}=t.getInstanceState();if(!(o===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:o}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||o.includes(r.userId)))return null;break}}return p.jsx(W7,{latestPresence:r})}),W7=jn(function({latestPresence:e}){const t=te(),{CollaboratorBrush:r,CollaboratorScribble:s,CollaboratorCursor:o,CollaboratorHint:i,CollaboratorShapeIndicator:a}=$t(),c=t.getZoomLevel(),d=t.getViewportPageBounds(),{userId:h,chatMessage:f,brush:g,scribbles:y,selectedShapeIds:S,userName:v,cursor:w,color:b}=e;if(!w)return null;const P=!(w.x<d.minX-12/c||w.y<d.minY-16/c||w.x>d.maxX-12/c||w.y>d.maxY-16/c);return p.jsxs(p.Fragment,{children:[g&&r?p.jsx(r,{className:"tl-collaborator__brush",brush:g,color:b,opacity:.1},h+"_brush"):null,P&&o?p.jsx(o,{className:"tl-collaborator__cursor",point:w,color:b,zoom:c,name:v!=="New User"?v:null,chatMessage:f??""},h+"_cursor"):i?p.jsx(i,{className:"tl-collaborator__cursor-hint",point:w,color:b,zoom:c,viewport:d},h+"_cursor_hint"):null,s&&y.length?p.jsx(p.Fragment,{children:y.map(k=>p.jsx(s,{className:"tl-collaborator__scribble",scribble:k,color:b,zoom:c,opacity:k.color==="laser"?.5:.1},h+"_scribble_"+k.id))}):null,a&&S.filter(k=>!t.isShapeHidden(k)).map(k=>p.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:k,color:b,opacity:.5},h+"_"+k))]})});function nT(n,e){return e>n.options.collaboratorInactiveTimeoutMs?"inactive":e>n.options.collaboratorIdleTimeoutMs?"idle":"active"}function G7(n,e){const t=_.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,s]=_.useState(()=>nT(n,Date.now()-t.current));return _.useEffect(()=>{const o=n.timers.setInterval(()=>{s(nT(n,Date.now()-t.current))},n.options.collaboratorCheckIntervalMs);return()=>clearInterval(o)},[n]),e&&(t.current=e.lastActivityTimestamp??1/0),r}function V7(){const n=te(),e=se("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),[t,r]=_.useState(!1),s=e||t,o=Fb(),i=_.useRef({isDown:!1,isDragging:!1,start:new C}),a=_.useCallback(h=>{h.button===0&&(r(!0),i.current={isDown:!0,isDragging:!1,start:new C(h.clientX,h.clientY)}),n.menus.clearOpenMenus()},[n]),c=_.useCallback(h=>{var f,g,y;if(i.current.isDown){if(i.current.isDragging){(f=o.onPointerMove)==null||f.call(o,h);return}if(C.Dist2(i.current.start,new C(h.clientX,h.clientY))>n.options.dragDistanceSquared){i.current={...i.current,isDown:!0,isDragging:!0};const{x:S,y:v}=i.current.start;(g=o.onPointerDown)==null||g.call(o,{...h,clientX:S,clientY:v,button:0}),(y=o.onPointerMove)==null||y.call(o,h)}}},[o,n]),d=_.useCallback(h=>{var f;(f=o.onPointerUp)==null||f.call(o,h),r(!1),i.current={isDown:!1,isDragging:!1,start:new C(h.clientX,h.clientY)}},[o]);return s&&p.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...o,onPointerDown:a,onPointerMove:c,onPointerUp:d})}const bj=_.memo(function({id:e,shape:t,util:r,index:s,backgroundIndex:o,opacity:i}){const a=te(),{ShapeErrorFallback:c}=$t(),d=_.useRef(null),h=_.useRef(null),f=_.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});aa("set shape stuff",()=>{const S=a.getShape(e);if(!S)return;const v=f.current,w=a.getShapeClipPath(e)??"none";w!==v.clipPath&&(Bn(d.current,"clip-path",w),Bn(h.current,"clip-path",w),v.clipPath=w);const b=a.getShapePageTransform(e),P=me.toCssString(b),k=a.getShapeGeometry(S).bounds;P!==v.transform&&(Bn(d.current,"transform",P),Bn(h.current,"transform",P),v.transform=P);const E=Math.max(k.width,1),M=Math.max(k.height,1);(E!==v.width||M!==v.height)&&(Bn(d.current,"width",E+"px"),Bn(d.current,"height",M+"px"),Bn(h.current,"width",E+"px"),Bn(h.current,"height",M+"px"),v.width=E,v.height=M)},[a]),aa("set opacity and z-index",()=>{const S=d.current,v=h.current;Bn(S,"opacity",i),Bn(v,"opacity",i),Bn(S,"z-index",s),Bn(v,"z-index",o)},[i,s,o]),aa("set display",()=>{if(!a.getShape(e))return;const w=a.getCulledShapes().has(e);w!==f.current.isCulled&&(Bn(d.current,"display",w?"none":"block"),Bn(h.current,"display",w?"none":"block"),f.current.isCulled=w)},[a]);const g=_.useCallback(S=>a.annotateError(S,{origin:"shape",willCrashApp:!1}),[a]);if(!t)return null;const y="fill"in t.props&&t.props.fill!=="none";return p.jsxs(p.Fragment,{children:[r.backgroundComponent&&p.jsx("div",{ref:h,className:"tl-shape tl-shape-background","data-shape-type":t.type,"data-shape-id":t.id,draggable:!1,children:p.jsx(_d,{fallback:c,onError:g,children:p.jsx(Cj,{shape:t,util:r})})}),p.jsx("div",{ref:d,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":y,"data-shape-id":t.id,draggable:!1,children:p.jsx(_d,{fallback:c,onError:g,children:p.jsx(Pj,{shape:t,util:r})})})]})}),Pj=_.memo(function({shape:e,util:t}){return Pg("InnerShape:"+e.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(e.id)),[t,e.id])},(n,e)=>n.shape.props===e.shape.props&&n.shape.meta===e.shape.meta&&n.util===e.util),Cj=_.memo(function({shape:e,util:t}){return Pg("InnerShape:"+e.type,()=>{var r;return(r=t.backgroundComponent)==null?void 0:r.call(t,t.editor.store.unsafeGetWithoutCapture(e.id))},[t,e.id])},(n,e)=>n.shape.props===e.shape.props&&n.shape.meta===e.shape.meta&&n.util===e.util);function q7({className:n}){const e=te(),{Background:t,SvgDefs:r,ShapeIndicators:s}=$t(),o=_.useRef(null),i=_.useRef(null),a=_.useRef(null),c=fn();L7(o),kB(),TB(),O7(o),AB(o);const d=_.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});aa("position layers",function(){const{x:P,y:k,z:E}=e.getCamera();if(d.current.allowTextOutline&&Et.isSafari&&(c.style.setProperty("--tl-text-outline","none"),d.current.allowTextOutline=!1),d.current.allowTextOutline&&E<e.options.textShadowLod!==d.current.lodDisableTextOutline){const R=E<e.options.textShadowLod;c.style.setProperty("--tl-text-outline",R?"none":"var(--tl-text-outline-reference)"),d.current.lodDisableTextOutline=R}const M=E>=1?Ac(E,[1,8],[.125,.5],!0):Ac(E,[.1,1],[-2,.125],!0),A=`scale(${ee(E)}) translate(${ee(P+M)}px,${ee(k+M)}px)`;Bn(i.current,"transform",A),Bn(a.current,"transform",A)},[e,c]);const h=Fb(),f=se("shapeSvgDefs",()=>{const b=new Map;for(const P of Vt(e.shapeUtils)){if(!P)return;const k=P.getCanvasSvgDefs();for(const{key:E,component:M}of k)b.has(E)||b.set(E,p.jsx(M,{},E))}return[...b.values()]},[e]),g=se("debug_shapes",()=>sn.hideShapes.get(),[sn]),y=se("debug_svg",()=>sn.debugSvg.get(),[sn]),S=se("debug_geometry",()=>sn.debugGeometry.get(),[sn]),v=se("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),w=se("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return p.jsxs(p.Fragment,{children:[p.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":v,"data-isselectinganything":w,className:Le("tl-canvas",n),"data-testid":"canvas",...h,children:[p.jsx("svg",{className:"tl-svg-context",children:p.jsxs("defs",{children:[f,p.jsx(lU,{}),p.jsx(cU,{}),r&&p.jsx(r,{})]})}),t&&p.jsx("div",{className:"tl-background__wrapper",children:p.jsx(t,{})}),p.jsx(X7,{}),p.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[p.jsx(pU,{}),p.jsx(hU,{}),g?null:y?p.jsx(sU,{}):p.jsx(iU,{})]}),p.jsx("div",{className:"tl-overlays",children:p.jsxs("div",{ref:a,className:"tl-html-layer",children:[S?p.jsx(U7,{}):null,p.jsx(Q7,{}),p.jsx(Z7,{}),p.jsx(J7,{}),s&&p.jsx(s,{}),p.jsx(aU,{}),p.jsx(eU,{}),p.jsx(dU,{}),p.jsx(tU,{}),p.jsx(H7,{})]})}),p.jsx(fU,{})]}),p.jsx(V7,{}),p.jsx(Y7,{})]})}function Y7(){const{InFrontOfTheCanvas:n}=$t();return n?p.jsx(n,{}):null}function X7(){const n=te(),e=se("gridSize",()=>n.getDocumentSettings().gridSize,[n]),{x:t,y:r,z:s}=se("camera",()=>n.getCamera(),[n]),o=se("isGridMode",()=>n.getInstanceState().isGridMode,[n]),{Grid:i}=$t();return i&&o?p.jsx(i,{x:t,y:r,z:s,size:e}):null}function Z7(){const n=te(),e=se("scribbles",()=>n.getInstanceState().scribbles,[n]),t=se("zoomLevel",()=>n.getZoomLevel(),[n]),{Scribble:r}=$t();return r&&e.length?e.map(s=>p.jsx(r,{className:"tl-user-scribble",scribble:s,zoom:t},s.id)):null}function Q7(){const n=te(),e=se("brush",()=>n.getInstanceState().brush,[n]),{Brush:t}=$t();return t&&e?p.jsx(t,{className:"tl-user-brush",brush:e}):null}function J7(){const n=te(),e=se("zoomBrush",()=>n.getInstanceState().zoomBrush,[n]),{ZoomBrush:t}=$t();return t&&e?p.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function eU(){const n=te(),e=se("snapLines",()=>n.snaps.getIndicators(),[n]),t=se("zoomLevel",()=>n.getZoomLevel(),[n]),{SnapIndicator:r}=$t();return r&&e.length>0?e.map(s=>p.jsx(r,{className:"tl-user-snapline",line:s,zoom:t},s.id)):null}function tU(){const n=te(),e=se("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=n.getInstanceState();if(t||r)return!1;const s=n.getOnlySelectedShape();return!s||!n.getShapeHandles(s)?!1:s.id},[n]);return e?p.jsx(nU,{shapeId:e}):null}function nU({shapeId:n}){const e=te(),{Handles:t}=$t(),r=se("zoomLevel",()=>e.getZoomLevel(),[e]),s=se("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),o=se("handles transform",()=>e.getShapePageTransform(n),[e,n]),i=se("handles",()=>{const c=e.getShapeHandles(n);if(!c)return null;const d=(s?e.options.coarseHandleRadius:e.options.handleRadius)/r*2;return c.filter(h=>h.type!=="virtual"||!c.some(f=>f!==h&&f.type==="vertex"&&C.Dist(h,f)<d)).sort(h=>h.type==="vertex"?1:-1)},[e,r,s,n]),a=se("isHidden",()=>e.isShapeHidden(n),[e,n]);return!t||!i||!o||a?null:p.jsx(t,{children:p.jsx("g",{transform:me.toCssString(o),children:i.map(c=>p.jsx(rU,{shapeId:n,handle:c,zoom:r,isCoarse:s},c.id))})})}function rU({shapeId:n,handle:e,zoom:t,isCoarse:r}){const s=D7(n,e.id),{Handle:o}=$t();return o?p.jsx("g",{"aria-label":"handle",transform:`translate(${e.x}, ${e.y})`,...s,children:p.jsx(o,{shapeId:n,handle:e,zoom:t,isCoarse:r})}):null}function sU(){const n=te();return se("rendering shapes",()=>n.getRenderingShapes(),[n]).map(t=>p.jsxs(_.Fragment,{children:[p.jsx(bj,{...t}),p.jsx(uU,{id:t.id,mode:"iframe"})]},t.id+"_fragment"))}function oU(){const n=te(),e=_.useRef(new Set);return aa("reflow for culled shapes",()=>{const t=n.getCulledShapes();if(e.current.size===t.size&&[...t].every(s=>e.current.has(s)))return;e.current=t;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[n]),null}function iU(){const n=te(),e=se("rendering shapes",()=>n.getRenderingShapes(),[n]);return p.jsxs(p.Fragment,{children:[e.map(t=>p.jsx(bj,{...t},t.id+"_shape")),Et.isSafari&&p.jsx(oU,{})]})}function aU(){const n=te(),{ShapeIndicator:e}=$t(),t=se("hinting shape ids",()=>q0(n.getHintingShapeIds()),[n]);return!t.length||!e?null:t.map(r=>p.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function lU(){return p.jsxs("g",{id:Ys("cursor"),children:[p.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[p.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),p.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),p.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[p.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),p.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),p.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[p.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),p.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function cU(){const n=Ys("cursor_hint");return p.jsx("path",{id:n,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function uU({id:n,mode:e}){const t=te(),[r,s]=_.useState(null),o=se("is in root",()=>{const i=t.getShape(n);return(i==null?void 0:i.parentId)===t.getCurrentPageId()},[t,n]);return _.useEffect(()=>{if(!o)return;let i=null;const a=To("shape to svg",async()=>{const c=Math.random();i=c;const h=t.isShapeOfType(n,"frame")?0:10;let f=t.getShapePageBounds(n);if(!f)return;f=f.clone().expandBy(h);const g=await t.getSvgString([n],{padding:h});if(i!==c||!g)return;const y=`data:image/svg+xml;utf8,${encodeURIComponent(g.svg)}`;s({src:y,bounds:f})});return()=>{i=null,a()}},[t,n,o]),!o||!r?null:e==="iframe"?p.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"}}):p.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 dU(){const n=te(),e=se("selection rotation",()=>n.getSelectionRotation(),[n]),t=se("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionForeground:r}=$t();return!t||!r?null:p.jsx(r,{bounds:t,rotation:e})}function hU(){const n=te(),e=se("selection rotation",()=>n.getSelectionRotation(),[n]),t=se("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionBackground:r}=$t();return!t||!r?null:p.jsx(r,{bounds:t,rotation:e})}function pU(){const{OnTheCanvas:n}=$t();return n?p.jsx(n,{}):null}function fU(){const n=te(),e=se("camera state",()=>n.getCameraState(),[n]);return p.jsx("div",{className:Le("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function gU({className:n,zoom:e,point:t,color:r,viewport:s,opacity:o=1}){const i=_.useRef(null);Gc(i,Cn(t.x,s.minX+5/e,s.maxX-5/e),Cn(t.y,s.minY+5/e,s.maxY-5/e),1/e,C.Angle(s.center,t));const a=Ys("cursor_hint");return p.jsxs("svg",{ref:i,className:Le("tl-overlays__item",n),children:[p.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--color-background)"}),p.jsx("use",{href:`#${a}`,color:r,opacity:o})]})}const rT=_.memo(function({className:e,zoom:t,point:r,color:s,name:o,chatMessage:i}){const a=_.useRef(null);Gc(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t);const c=Ys("cursor");return r?p.jsxs("div",{ref:a,className:Le("tl-overlays__item",e),children:[p.jsx("svg",{className:"tl-cursor",children:p.jsx("use",{href:`#${c}`,color:s})}),i?p.jsxs(p.Fragment,{children:[o&&p.jsx("div",{className:"tl-nametag-title",style:{color:s},children:o}),p.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:s},children:i})]}):o&&p.jsx("div",{className:"tl-nametag",style:{backgroundColor:s},children:o})]}):null});function mU({x:n,y:e,z:t,size:r}){const s=Wc("grid"),o=te(),{gridSteps:i}=o.options;return p.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("defs",{children:i.map(({min:a,mid:c,step:d},h)=>{const f=d*r*t,g=.5+n*t,y=.5+e*t,S=g>0?g%f:f+g%f,v=y>0?y%f:f+y%f,w=t<c?Ac(t,[a,c],[0,1]):1;return p.jsx("pattern",{id:Rb(s,`${d}`),width:f,height:f,patternUnits:"userSpaceOnUse",children:p.jsx("circle",{className:"tl-grid-dot",cx:S,cy:v,r:1,opacity:w})},h)})}),i.map(({step:a},c)=>p.jsx("rect",{width:"100%",height:"100%",fill:`url(#${s}_${a})`},c))]})}function yU({handle:n,isCoarse:e,className:t,zoom:r}){const s=te(),o=(e?s.options.coarseHandleRadius:s.options.handleRadius)/r;if(n.type==="clone"){const a=3/r,c=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,d=wB.indexOf(n.id);return p.jsxs("g",{className:Le(`tl-handle tl-handle__${n.type}`,t),children:[p.jsx("circle",{className:"tl-handle__bg",r:o}),p.jsx("path",{className:"tl-handle__fg",d:c,transform:`rotate(${-90+90*d})`})]})}const i=(n.type==="create"&&e?3:4)/Math.max(r,.25);return p.jsxs("g",{className:Le(`tl-handle tl-handle__${n.type}`,t),children:[p.jsx("circle",{className:"tl-handle__bg",r:o}),p.jsx("circle",{className:"tl-handle__fg",r:i})]})}const SU=({children:n})=>p.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}),vU=()=>{const{Spinner:n}=$t();return p.jsx(t1,{children:n?p.jsx(n,{}):null})};function $b(n,e=!0){const t=n.length;if(t<2)return"";let r=n[0],s=n[1];if(t===2)return`M${ht(r)}L${ht(s)}`;let o="";for(let i=2,a=t-1;i<a;i++)r=n[i],s=n[i+1],o+=jr(r,s);return e?`M${jr(n[0],n[1])}Q${ht(n[1])}${jr(n[1],n[2])}T${o}${jr(n[t-1],n[0])}${jr(n[0],n[1])}Z`:`M${ht(n[0])}Q${ht(n[1])}${jr(n[1],n[2])}${n.length>3?"T":""}${o}L${ht(n[t-1])}`}function sT({scribble:n,zoom:e,color:t,opacity:r,className:s}){return n.points.length?p.jsx("svg",{className:s&&Le("tl-overlays__item",s),children:p.jsx("path",{className:"tl-scribble",d:$b(n.points,!1),stroke:t??`var(--color-${n.color})`,fill:"none",strokeWidth:8/e,opacity:r??n.opacity})}):null}function _j({bounds:n,rotation:e}){const t=_.useRef(null);return Gc(t,n.x,n.y,1,e),_.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=ee(Math.max(1,n.width))+"px",r.style.height=ee(Math.max(1,n.height))+"px")},[n.width,n.height]),p.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function xU({bounds:n,rotation:e}){const t=te(),r=_.useRef(null),s=se("only selected shape",()=>t.getOnlySelectedShape(),[t]),o=s?t.getShapeUtil(s).expandSelectionOutlinePx(s):0;return Gc(r,n==null?void 0:n.x,n==null?void 0:n.y,1,e,{x:-o,y:-o}),n=o instanceof Se?n.clone().expand(o).zeroFix():n.clone().expandBy(o).zeroFix(),p.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:p.jsx("rect",{className:Le("tl-selection__fg__outline"),width:ee(n.width),height:ee(n.height)})})}const wU=()=>p.jsx("div",{className:"tl-shape-error-boundary"}),bU=({shape:n,util:e})=>Pg("Indicator: "+n.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(n.id))),PU=({editor:n,id:e})=>{const t=se("shape for indicator",()=>n.store.get(e),[n,e]),{ShapeIndicatorErrorFallback:r}=$t();return!t||t.isLocked?null:p.jsx(_d,{fallback:r,onError:s=>n.annotateError(s,{origin:"react.shapeIndicator",willCrashApp:!1}),children:p.jsx(bU,{shape:t,util:n.getShapeUtil(t)},t.id)})},oT=_.memo(function({shapeId:e,className:t,color:r,hidden:s,opacity:o}){const i=te(),a=_.useRef(null);return aa("indicator transform",()=>{const c=a.current;if(!c)return;const d=i.getShapePageTransform(e);d&&c.style.setProperty("transform",d.toCssString())},[i,e]),_.useLayoutEffect(()=>{const c=a.current;c&&c.style.setProperty("display",s?"none":"block")},[s]),p.jsx("svg",{ref:a,className:Le("tl-overlays__item",t),children:p.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:o,children:p.jsx(PU,{editor:i,id:e})})})}),CU=()=>p.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),Ij=_.memo(function(){const e=te(),t=_.useRef(new Set),r=se("should display selected ids",()=>{const i=t.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 c=e.getSelectedShapeIds();for(const d of c)a.add(d);if(e.isInAny("select.idle","select.editing_shape")){const d=e.getInstanceState();if(d.isHoveringCanvas&&!d.isCoarsePointer){const h=e.getHoveredShapeId();h&&a.add(h)}}}if(i.size!==a.size)return t.current=a,a;for(const c of a)if(!i.has(c))return t.current=a,a;return i},[e]),s=se("rendering shapes",()=>e.getRenderingShapes(),[e]),{ShapeIndicator:o}=$t();return o?s.map(({id:i})=>p.jsx(o,{shapeId:i,hidden:!r.has(i)},i+"_indicator")):null});function _U({points:n,zoom:e}){const t=2.5/e,r=n.reduce((g,y)=>Math.min(g,y.x),1/0),s=n.reduce((g,y)=>Math.max(g,y.x),-1/0),o=n.reduce((g,y)=>Math.min(g,y.y),1/0),i=n.reduce((g,y)=>Math.max(g,y.y),-1/0),a=n.some(g=>g.x===r&&g.y===o);let c,d,h,f;return a?(c=r,d=o,h=s,f=i):(c=r,d=i,h=s,f=o),p.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[p.jsx("line",{x1:c,y1:d,x2:h,y2:f}),n.map((g,y)=>p.jsx("g",{transform:`translate(${g.x},${g.y})`,children:p.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},y))]})}function IU({gaps:n,direction:e,zoom:t}){const r=3.5/t;let s=[-1/0,1/0],o=null;const i=e==="horizontal";for(const c of n){if(o=Hs(s[0],s[1],i?c.startEdge[0].y:c.startEdge[0].x,i?c.startEdge[1].y:c.startEdge[1].x),o)s=o;else continue;if(o=Hs(s[0],s[1],i?c.endEdge[0].y:c.endEdge[0].x,i?c.endEdge[1].y:c.endEdge[1].x),o)s=o;else continue}if(s===null)return null;const a=(s[0]+s[1])/2;return p.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:n.map(({startEdge:c,endEdge:d},h)=>p.jsx(_.Fragment,{children:i?p.jsxs(p.Fragment,{children:[p.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),p.jsx("line",{x1:d[0].x,y1:a-2*r,x2:d[1].x,y2:a+2*r}),p.jsx("line",{x1:c[0].x,y1:a,x2:d[0].x,y2:a}),p.jsx("line",{x1:(c[0].x+d[0].x)/2,y1:a-r,x2:(c[0].x+d[0].x)/2,y2:a+r})]}):p.jsxs(p.Fragment,{children:[p.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),p.jsx("line",{x1:a-2*r,y1:d[0].y,x2:a+2*r,y2:d[1].y}),p.jsx("line",{x1:a,y1:c[0].y,x2:a,y2:d[0].y}),p.jsx("line",{x1:a-r,y1:(c[0].y+d[0].y)/2,x2:a+r,y2:(c[0].y+d[0].y)/2})]})},h))})}function EU({className:n,line:e,zoom:t}){return p.jsx("svg",{className:Le("tl-overlays__item",n),children:e.type==="points"?p.jsx(_U,{...e,zoom:t}):e.type==="gaps"?p.jsx(IU,{...e,zoom:t}):null})}function zb(){return p.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:p.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[p.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),p.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:p.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const TU=()=>null;function Ej(n,e){const t=_.useRef(n);return e(n,t.current)?t.current:(t.current=n,n)}const kU=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:eM(n,e));function ra(n){return Ej(n,kU)}const MU=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:oM(n,e));function Vc(n){return Ej(n,MU)}const Tj=_.createContext(null);function AU({overrides:n={},children:e}){const t=Vc(n),r=_.useMemo(()=>({Background:xB,SvgDefs:TU,Brush:bx,ZoomBrush:bx,CollaboratorBrush:bx,Cursor:rT,CollaboratorCursor:rT,CollaboratorHint:gU,CollaboratorShapeIndicator:oT,Grid:mU,Scribble:sT,SnapIndicator:EU,Handles:SU,Handle:yU,CollaboratorScribble:sT,ErrorFallback:Mj,ShapeErrorFallback:wU,ShapeIndicatorErrorFallback:CU,Spinner:zb,SelectionBackground:_j,SelectionForeground:xU,ShapeIndicators:Ij,ShapeIndicator:oT,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:q7,LoadingScreen:vU,...t}),[t]);return p.jsx(Tj.Provider,{value:r,children:e})}function $t(){const n=_.useContext(Tj);if(!n)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return n}const Ag={openWindow(n,e){window.open(n,e,"noopener noreferrer")},refreshPage(){window.location.reload()},async hardReset(){var n;return await((n=window.__tldraw__hardReset)==null?void 0:n.call(window))}};function kj(){Ag.hardReset()}function jU(){Ag.refreshPage()}const RU="https://github.com/tldraw/tldraw/issues/new",Mj=({error:n,editor:e})=>{const t=_.useRef(null),[r,s]=_.useState(!1),[o,i]=_.useState(!1),[a,c]=_.useState(!1);let d=null;try{d=$t().Canvas??null}catch{}const h=n instanceof Error?n.message:String(n),f=n instanceof Error?n.stack:null,g=se("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[y,S]=_.useState(null);_.useLayoutEffect(()=>{var M;g!==null&&S(g);let k=(M=t.current)==null?void 0:M.parentElement,E=!1;for(;k;){if(k.classList.contains("tl-theme__dark")||k.classList.contains("tl-theme__light")){E=!0;break}k=k.parentElement}if(E){S(null);return}typeof window<"u"&&"matchMedia"in window&&S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[g]),_.useEffect(()=>{if(o){const k=e==null?void 0:e.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(k)}},[o,e]);const v=()=>{const k=document.createElement("textarea");k.value=f??h,document.body.appendChild(k),k.select(),document.execCommand("copy"),k.remove(),i(!0)},w=()=>{jU()},b=async()=>{kj()},P=new URL(RU);return P.searchParams.set("title",h),P.searchParams.set("labels","bug"),P.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
93
|
+
|
|
94
|
+
\`\`\`js
|
|
95
|
+
${f??h}
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
My browser: ${navigator.userAgent}`),p.jsxs("div",{ref:t,className:Le("tl-container tl-error-boundary",y===null?"":y?"tl-theme__dark":"tl-theme__light"),children:[p.jsx("div",{className:"tl-error-boundary__overlay"}),e&&p.jsx(jb,{onError:vd,fallback:()=>null,children:p.jsx(Db,{editor:e,children:p.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:d?p.jsx(d,{}):null})})}),p.jsx("div",{className:Le("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?p.jsxs(p.Fragment,{children:[p.jsx("h2",{children:"Are you sure?"}),p.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),p.jsxs("div",{className:"tl-error-boundary__content__actions",children:[p.jsx("button",{onClick:()=>c(!1),children:"Cancel"}),p.jsx("button",{className:"tl-error-boundary__reset",onClick:b,children:"Reset data"})]})]}):p.jsxs(p.Fragment,{children:[p.jsx("h2",{children:"Something went wrong"}),p.jsx("p",{children:"Please refresh the page to continue."}),p.jsxs("p",{children:["If you keep seeing this screen, you can create a"," ",p.jsx("a",{href:P.toString(),children:"GitHub issue"})," or ask for help on"," ",p.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&&p.jsxs(p.Fragment,{children:["Message:",p.jsx("h4",{children:p.jsx("code",{children:h})}),"Stack trace:",p.jsxs("div",{className:"tl-error-boundary__content__error",children:[p.jsx("pre",{children:p.jsx("code",{children:f??h})}),p.jsx("button",{onClick:v,children:o?"Copied!":"Copy"})]})]}),p.jsxs("div",{className:"tl-error-boundary__content__actions",children:[p.jsx("button",{onClick:()=>s(!r),children:r?"Hide details":"Show details"}),p.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[p.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>c(!0),children:"Reset data"}),p.jsx("button",{className:"tl-error-boundary__refresh",onClick:w,children:"Refresh Page"})]})]})]})})]})},Aj="TLDRAW_USER_DATA_v3",jj=rt({id:Xe,name:Xe.nullable().optional(),color:Xe.nullable().optional(),locale:Xe.nullable().optional(),animationSpeed:We.nullable().optional(),edgeScrollSpeed:We.nullable().optional(),colorScheme:Eg("light","dark","system").optional(),isSnapMode:tt.nullable().optional(),isWrapMode:tt.nullable().optional(),isDynamicSizeMode:tt.nullable().optional(),isPasteAtCursorMode:tt.nullable().optional()}),ii={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},Bb=Math.max(...Object.values(ii));function OU(n){n.version<ii.AddAnimationSpeed&&(n.user.animationSpeed=1),n.version<ii.AddIsSnapMode&&(n.user.isSnapMode=!1),n.version<ii.MakeFieldsNullable,n.version<ii.AddEdgeScrollSpeed&&(n.user.edgeScrollSpeed=1),n.version<ii.AddExcalidrawSelectMode&&(n.user.isWrapMode=!1),n.version<ii.AllowSystemColorScheme&&(n.user.isDarkMode===!0?n.user.colorScheme="dark":n.user.isDarkMode===!1&&(n.user.colorScheme="light"),delete n.user.isDarkMode),n.version<ii.AddDynamicSizeMode&&(n.user.isDynamicSizeMode=!1),n.version<ii.AddPasteAtCursor&&(n.user.isPasteAtCursorMode=!1),n.version=Bb}const Yw=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function Rj(){return Yw[Math.floor(Math.random()*Yw.length)]}function DU(){var n,e;return typeof window<"u"&&"matchMedia"in window?((e=(n=window.matchMedia)==null?void 0:n.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:e.matches)??!1:!1}const vo=Object.freeze({name:"New User",locale:pB(),color:Rj(),edgeScrollSpeed:1,animationSpeed:DU()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"light"});function Ex(){return{id:xt(),color:Rj()}}function Oj(n){if(n===null||typeof n!="object"||!("version"in n)||!("user"in n)||typeof n.version!="number")return Ex();const e=Nt(n);OU(e);try{return jj.validate(e.user)}catch{return Ex()}}function LU(){const n=JSON.parse(nb(Aj)||"null")??null;return Oj(n)}const jg=dn("globalUserData",null);function FU(){rb(Aj,JSON.stringify({version:Bb,user:jg.get()}))}function Dj(n){jj.validate(n),jg.set(n),FU(),NU()}const _c=typeof BroadcastChannel<"u"?new BroadcastChannel("tldraw-user-sync"):null;_c==null||_c.addEventListener("message",n=>{const e=n.data;(e==null?void 0:e.type)===Fj&&(e==null?void 0:e.origin)!==Lj()&&jg.set(Oj(e.data))});let Tx=null;function Lj(){return Tx===null&&(Tx=xt()),Tx}const Fj="tldraw-user-preferences-change";function NU(){_c==null||_c.postMessage({type:Fj,origin:Lj(),data:{user:Nj(),version:Bb}})}function Nj(){let n=jg.get();return n||(n=LU(),Dj(n)),n}const $U=le("defaultLocalStorageUserPrefs",()=>Nj());function $j(n={}){return{userPreferences:n.userPreferences??$U,setUserPreferences:n.setUserPreferences??Dj}}var kx={exports:{}},iT;function zU(){return iT||(iT=1,function(n){var e=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function s(c,d,h){this.fn=c,this.context=d,this.once=h||!1}function o(c,d,h,f,g){if(typeof h!="function")throw new TypeError("The listener must be a function");var y=new s(h,f||c,g),S=t?t+d:d;return c._events[S]?c._events[S].fn?c._events[S]=[c._events[S],y]:c._events[S].push(y):(c._events[S]=y,c._eventsCount++),c}function i(c,d){--c._eventsCount===0?c._events=new r:delete c._events[d]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var d=[],h,f;if(this._eventsCount===0)return d;for(f in h=this._events)e.call(h,f)&&d.push(t?f.slice(1):f);return Object.getOwnPropertySymbols?d.concat(Object.getOwnPropertySymbols(h)):d},a.prototype.listeners=function(d){var h=t?t+d:d,f=this._events[h];if(!f)return[];if(f.fn)return[f.fn];for(var g=0,y=f.length,S=new Array(y);g<y;g++)S[g]=f[g].fn;return S},a.prototype.listenerCount=function(d){var h=t?t+d:d,f=this._events[h];return f?f.fn?1:f.length:0},a.prototype.emit=function(d,h,f,g,y,S){var v=t?t+d:d;if(!this._events[v])return!1;var w=this._events[v],b=arguments.length,P,k;if(w.fn){switch(w.once&&this.removeListener(d,w.fn,void 0,!0),b){case 1:return w.fn.call(w.context),!0;case 2:return w.fn.call(w.context,h),!0;case 3:return w.fn.call(w.context,h,f),!0;case 4:return w.fn.call(w.context,h,f,g),!0;case 5:return w.fn.call(w.context,h,f,g,y),!0;case 6:return w.fn.call(w.context,h,f,g,y,S),!0}for(k=1,P=new Array(b-1);k<b;k++)P[k-1]=arguments[k];w.fn.apply(w.context,P)}else{var E=w.length,M;for(k=0;k<E;k++)switch(w[k].once&&this.removeListener(d,w[k].fn,void 0,!0),b){case 1:w[k].fn.call(w[k].context);break;case 2:w[k].fn.call(w[k].context,h);break;case 3:w[k].fn.call(w[k].context,h,f);break;case 4:w[k].fn.call(w[k].context,h,f,g);break;default:if(!P)for(M=1,P=new Array(b-1);M<b;M++)P[M-1]=arguments[M];w[k].fn.apply(w[k].context,P)}}return!0},a.prototype.on=function(d,h,f){return o(this,d,h,f,!1)},a.prototype.once=function(d,h,f){return o(this,d,h,f,!0)},a.prototype.removeListener=function(d,h,f,g){var y=t?t+d:d;if(!this._events[y])return this;if(!h)return i(this,y),this;var S=this._events[y];if(S.fn)S.fn===h&&(!g||S.once)&&(!f||S.context===f)&&i(this,y);else{for(var v=0,w=[],b=S.length;v<b;v++)(S[v].fn!==h||g&&!S[v].once||f&&S[v].context!==f)&&w.push(S[v]);w.length?this._events[y]=w.length===1?w[0]:w:i(this,y)}return this},a.prototype.removeAllListeners=function(d){var h;return d?(h=t?t+d:d,this._events[h]&&i(this,h)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,n.exports=a}(kx)),kx.exports}var BU=zU();const UU=bi(BU),Ic="TLDRAW_TAB_ID_v2",mi=globalThis.window;function HU(){return mi?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(mi.navigator.platform)||Et.isDarwin&&"ontouchend"in document:!1}const Qf=mi?mi[Ic]??SM(Ic)??"TLDRAW_INSTANCE_STATE_V1_"+xt():"<error>";mi&&(mi[Ic]=Qf,HU()?sb(Ic,Qf):vM(Ic));mi==null||mi.addEventListener("beforeunload",()=>{sb(Ic,Qf)});const zj={Initial:0},Rg=Math.max(...Object.values(zj));function KU(n){n.version<zj.Initial,n.version=Rg}const Bj=rt({version:We,currentPageId:Pd.optional(),isFocusMode:tt.optional(),exportBackground:tt.optional(),isDebugMode:tt.optional(),isToolLocked:tt.optional(),isGridMode:tt.optional(),pageStates:Tn(rt({pageId:Pd,camera:rt({x:We,y:We,z:We}).optional(),selectedShapeIds:Tn(vs).optional(),focusedGroupId:vs.nullable().optional()})).optional()});function WU(n){if(!n||typeof n!="object")return console.warn("Invalid instance state"),null;if(!("version"in n)||typeof n.version!="number")return console.warn("No version in instance state"),null;n.version!==Rg&&(n=Nt(n),KU(n));try{return Bj.validate(n)}catch(e){return console.warn(e),null}}function Ub(n){const e=n.query.ids("page");return le("sessionStateSnapshot",()=>{const t=n.get(sr);if(!t)return null;const r=[...e.get()];return{version:Rg,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(s=>{const o=n.get(Vs.createId(s)),i=n.get(_o.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:mA})}function Xw(n,e,t){const r=WU(e);if(!r)return;const s=jA(n.get(sr)),o=t!=null&&t.forceOverwrite?r:s,i=t!=null&&t.forceOverwrite?s:r,a=n.schema.types.instance.create({id:sr,...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)});n.atomic(()=>{var c,d,h;for(const f of r.pageStates??[]){if(!n.has(f.pageId))continue;const g=_o.createId(f.pageId),y=Vs.createId(f.pageId),S=n.get(g),v=n.get(y);n.put([_o.create({id:g,x:((c=f.camera)==null?void 0:c.x)??(S==null?void 0:S.x),y:((d=f.camera)==null?void 0:d.y)??(S==null?void 0:S.y),z:((h=f.camera)==null?void 0:h.z)??(S==null?void 0:S.z)}),Vs.create({id:y,pageId:f.pageId,selectedShapeIds:f.selectedShapeIds??(v==null?void 0:v.selectedShapeIds),focusedGroupId:f.focusedGroupId??(v==null?void 0:v.focusedGroupId)})])}n.put([a]),n.ensureStoreIsUsable()})}function GU(n){var s;const e=[];for(const o of Object.values(n))(s=o.typeName)!=null&&s.match(/^(instance.*|pointer|camera)$/)&&e.push(o);const t=e.filter(o=>o.typeName==="instance"&&o.id!==sr)[0];if(!t)return null;const r={version:Rg,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:e.filter(o=>o.typeName==="instance_page_state"&&o.instanceId===t.id).map(o=>{const i=n[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(n,e,t){let r={};if("store"in e){const i=n.schema.migrateStoreSnapshot(e);if(i.type!=="success")throw new Error("Failed to migrate store snapshot: "+i.reason);r.document={schema:n.schema.serialize(),store:cd(i.value,(a,{typeName:c})=>n.scopedTypes.document.has(c))}}else r=e;const s=jA(n.get(sr)),o=Hj.get(n,Ub).get();n.atomic(()=>{r.document&&n.loadStoreSnapshot(r.document),s&&n.update(sr,i=>({...i,...s})),o&&Xw(n,o),r.session&&Xw(n,r.session,{forceOverwrite:t==null?void 0:t.forceOverwriteSessionState})})}const Hj=new Ao;function VU(n){const t=Hj.get(n,Ub).get();if(!t)throw new Error("Session state is not ready yet");return{document:n.getStoreSnapshot(),session:t}}function Kj(n){const e=[],t=new Set;for(const r of n){if(t.has(r.type))throw new Error(`Binding type "${r.type}" is defined more than once`);e.push(r),t.add(r.type)}return e}function ha({children:n,className:e="",...t}){return p.jsx("svg",{...t,className:Le("tl-svg-container",e),children:n})}function Hb(n,e,t,r){const s=n.x-t.x,o=n.y-t.y,i=r.x-t.x,a=r.y-t.y,c=e.x-n.x,d=e.y-n.y,h=i*o-a*s,f=c*o-d*s,g=a*c-i*d;if(h===0||f===0||g===0)return null;if(g!==0){const y=h/g,S=f/g;if(0<=y&&y<=1&&0<=S&&S<=1)return C.AddXY(n,y*c,y*d)}return null}function Yd(n,e,t,r){const s=(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y),o=2*((e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y)),i=t.x*t.x+t.y*t.y+n.x*n.x+n.y*n.y-2*(t.x*n.x+t.y*n.y)-r*r,a=o*o-4*s*i;if(a<0||a===0)return null;const c=Math.sqrt(a),d=(-o+c)/(2*s),h=(-o-c)/(2*s);if((d<0||d>1)&&(h<0||h>1))return null;const f=[];return 0<=d&&d<=1&&f.push(C.Lrp(n,e,d)),0<=h&&h<=1&&f.push(C.Lrp(n,e,h)),f.length===0?null:f}function qU(n,e,t){const r=[];let s;for(let o=0,i=t.length-1;o<i;o++)s=Hb(n,e,t[o],t[o+1]),s&&r.push(s);return r.length===0?null:r}function Kb(n,e,t){const r=[];let s;for(let o=1,i=t.length;o<i+1;o++)s=Hb(n,e,t[o-1],t[o%t.length]),s&&r.push(s);return r.length===0?null:r}function YU(n,e,t,r){let s=t.x-n.x,o=t.y-n.y;const i=Math.sqrt(s*s+o*o),a=(i*i-r*r+e*e)/(2*i),c=Math.sqrt(e*e-a*a);return s/=i,o/=i,[new C(n.x+s*a-o*c,n.y+o*a+s*c),new C(n.x+s*a+o*c,n.y+o*a-s*c)]}function Zw(n,e,t){const r=[];let s,o,i;for(let a=0,c=t.length;a<c;a++)s=t[a],o=t[(a+1)%t.length],i=Yd(s,o,n,e),i&&r.push(...i);return r.length===0?null:r}function aT(n,e,t){const r=[];let s,o,i;for(let a=1,c=t.length;a<c;a++)s=t[a-1],o=t[a],i=Yd(s,o,n,e),i&&r.push(...i);return r.length===0?null:r}function _p(n,e,t){return(t.y-n.y)*(e.x-n.x)>(e.y-n.y)*(t.x-n.x)}function Wb(n,e,t,r){return _p(n,t,r)!==_p(e,t,r)&&_p(n,e,t)!==_p(n,e,r)}function lT(n,e){const t=new Map;let r,s,o,i;for(let a=0,c=n.length;a<c;a++)if(r=n[a],Jr(r,e)){const d=Mx(r);t.has(d)||t.set(d,r)}for(let a=0,c=e.length;a<c;a++)if(r=e[a],Jr(r,n)){const d=Mx(r);t.has(d)||t.set(d,r)}for(let a=0,c=n.length;a<c;a++){r=n[a],s=n[(a+1)%n.length];for(let d=0,h=e.length;d<h;d++){o=e[d],i=e[(d+1)%e.length];const f=Hb(r,s,o,i);if(f!==null){const g=Mx(f);t.has(g)||t.set(g,f)}}}return t.size===0?null:XU([...t.values()])}function Mx(n){return`${n.x},${n.y}`}function XU(n){const e=C.Average(n);return n.sort((t,r)=>C.Angle(e,t)-C.Angle(e,r))}function Gb(n,e){let t,r,s,o;for(let i=0,a=n.length;i<a;i++){t=n[i],r=n[(i+1)%a];for(let c=0,d=e.length;c<d;c++)if(s=e[c],o=e[(c+1)%d],Wb(t,r,s,o))return!0}return!1}function ZU(n,e){let t,r,s,o;for(let i=0,a=n.length;i<a;i++){t=n[i],r=n[(i+1)%a];for(let c=1,d=e.length;c<d;c++)if(s=e[c-1],o=e[c],Wb(t,r,s,o))return!0}return!1}class hi extends ba{constructor(t){super({...t,isClosed:!1,isFilled:!1});j(this,"start");j(this,"end");j(this,"d");j(this,"u");j(this,"ul");const{start:r,end:s}=t;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(t){const{start:r,end:s,d:o,u:i,ul:a}=this;if(o.len()===0||a===0)return r;const c=C.Sub(t,r).dpr(i)/a,d=r.x+i.x*c;if(d<Math.min(r.x,s.x))return r.x<s.x?r:s;if(d>Math.max(r.x,s.x))return r.x>s.x?r:s;const h=r.y+i.y*c;return h<Math.min(r.y,s.y)?r.y<s.y?r:s:h>Math.max(r.y,s.y)?r.y>s.y?r:s:new C(d,h)}hitTestLineSegment(t,r,s=0){return Wb(t,r,this.start,this.end)||this.distanceToLineSegment(t,r)<=s}getSvgPathData(t=!0){const{start:r,end:s}=this;return`${t?`M${r.toFixed()}`:""} L${s.toFixed()}`}}class qc extends ba{constructor(t){super({isClosed:!1,isFilled:!1,...t});j(this,"points");j(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:t}=this;for(let r=0,s=t.length-1;r<s;r++){const o=t[r],i=t[r+1];this._segments.push(new hi({start:o,end:i}))}this.isClosed&&this._segments.push(new hi({start:t[t.length-1],end:t[0]}))}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){return this.points}nearestPoint(t){const{segments:r}=this;let s=this.points[0],o=1/0,i,a;for(let c=0;c<r.length;c++)i=r[c].nearestPoint(t),a=C.Dist2(i,t),a<o&&(s=i,o=a);if(!s)throw Error("nearest point not found");return s}hitTestLineSegment(t,r,s=0){const{segments:o}=this;for(let i=0,a=o.length;i<a;i++)if(o[i].hitTestLineSegment(t,r,s))return!0;return!1}getSvgPathData(){const{vertices:t}=this;return t.length<2?"":t.reduce((r,s,o)=>o===0?`M ${s.x} ${s.y}`:`${r} L ${s.x} ${s.y}`,"")}}class rn extends qc{constructor(e){super({...e}),this.isClosed=!0}}class Do extends rn{constructor(t){const{x:r=0,y:s=0,width:o,height:i}=t;super({...t,points:[new C(r,s),new C(r+o,s),new C(r+o,s+i),new C(r,s+i)]});j(this,"x");j(this,"y");j(this,"w");j(this,"h");this.x=r,this.y=s,this.w=o,this.h=i}getBounds(){return new Se(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:s,h:o}=this;return`M${t},${r} h${s} v${o} h-${s}z`}}class Xs{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,t){return!1}canDropShapes(e,t){return!1}expandSelectionOutlinePx(e){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(e){return{}}getHandleSnapGeometry(e){return{}}getText(e){}}j(Xs,"props"),j(Xs,"migrations"),j(Xs,"type");function Ws(n,e,t={}){const{closed:r=!1,snap:s=1,start:o="outset",end:i="outset",lengthRatio:a=2,style:c="dashed",forceSolid:d=!1}=t;let h=0,f=0,g=1,y=0,S=0;if(d)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(c){case"dashed":{g=1,h=Math.min(e*a,n/4);break}case"dotted":{g=100,h=e/g;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(o==="outset"?(n+=h/2,S+=h/2):o==="skip"&&(n-=h,S-=h),i==="outset"?n+=h/2:i==="skip"&&(n-=h)),f=Math.floor(n/h/(2*g)),f-=f%s,f<3&&c==="dashed"?n/e<4?(h=n,f=1,y=0):(h=n*(1/3),y=n*(1/3)):(h=n/f/(2*g),r?(S=h/2,y=(n-f*h)/f):y=(n-f*h)/Math.max(1,f-1)),{strokeDasharray:[h,y].join(" "),strokeDashoffset:S.toString()}}function cT({bounds:n,className:e}){const t=te(),r=se("zoom level",()=>t.getZoomLevel(),[t]);return p.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:n.sides.map((s,o)=>{const{strokeDasharray:i,strokeDashoffset:a}=Ws(s[0].dist(s[1]),1/r,{style:"dashed",lengthRatio:4});return p.jsx("line",{x1:s[0].x,y1:s[0].y,x2:s[1].x,y2:s[1].y,strokeDasharray:i,strokeDashoffset:a},o)})})}class sf extends Xs{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const t=this.editor.getSortedChildIdsForParent(e.id);return t.length===0?new Do({width:1,height:1,isFilled:!1}):new Is({children:t.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 rn({points:i,isFilled:!0}):new qc({points:i})})})}component(e){const t=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(!t&&(o||s))return null;const i=this.editor.getShapeGeometry(e).bounds;return p.jsx(ha,{children:p.jsx(cT,{className:"tl-group",bounds:i})})}indicator(e){const t=this.editor.getShapeGeometry(e).bounds;return p.jsx(cT,{className:"",bounds:t})}onChildrenChange(e){const t=this.editor.getSortedChildIdsForParent(e.id);if(t.length===0){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([e.id]);return}else if(t.length===1){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(t,e.parentId),this.editor.deleteShapes([e.id]);return}}}j(sf,"type","group"),j(sf,"props",KA),j(sf,"migrations",WA);const Wj=[sf],QU=new Set(Wj.map(n=>n.type));function Gj(n){const e=[...Wj],t=new Set;for(const r of n){if(QU.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(t.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);e.push(r),t.add(r.type)}return e}var Yc=Yk();const JU=bi(Yc);function Vj(n,e){const t=new Map;return async function(s){const o=t.get(s);if(o)return o;const i=(async()=>{try{const a=await jo(s,e);return mt(a.ok),await n(a)}catch(a){return console.error(a),null}})();return t.set(s,i),i}}const Og=Vj(async n=>await Gs.blobToDataUrl(await n.blob())),eH=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,tH=/@font-face\s*{([^}]+)}/gi,qj=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,nH=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function rH(n){return Array.from(n.matchAll(eH),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Yj(n,e){return Array.from(n.matchAll(tH),t=>{const r=t[1],s=Array.from(r.matchAll(qj),i=>{var c;const a=i[1]||i[2]||i[3];return{original:a,resolved:((c=Ge(a,e))==null?void 0:c.href)??null}}),o=new Set(Array.from(r.matchAll(nH),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:s,fontFamilies:o}})}function sH(n){const e=/\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi,t=/\s*,\s*/gi,r=new Set;for(;;){const s=e.exec(n);if(!s)break;const o=s[1]||s[2]||s[3];if(r.add(o.toLowerCase()),t.lastIndex=e.lastIndex,!t.exec(n))break;e.lastIndex=t.lastIndex}return r}function Xj(n){return!(n.startsWith("-")||n.startsWith("animation")||n.startsWith("transition")||n==="cursor"||n==="pointer-events"||n==="user-select"||n==="touch-action")}function oH(n,e){return{imports:rH(n),fontFaces:Yj(n,e)}}function iH(n){return Array.from(n.matchAll(qj),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const aH=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(n){return aH.has(n)}var lH=Object.create,Qj=Object.defineProperty,cH=Object.getOwnPropertyDescriptor,uH=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Jj=n=>{throw TypeError(n)},eR=(n,e,t)=>e in n?Qj(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,dH=n=>[,,,lH(null)],tR=["class","method","getter","setter","accessor","field","value","get","set"],nR=n=>n!==void 0&&typeof n!="function"?Jj("Function expected"):n,hH=(n,e,t,r,s)=>({kind:tR[n],name:e,metadata:r,addInitializer:o=>t._?Jj("Already initialized"):s.push(nR(o||null))}),pH=(n,e)=>eR(e,uH("metadata"),n[3]),fH=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},gH=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=tR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,cH(s,t)),b=r.length-1;b>=0;b--)c=hH(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,nR(i)&&(w[S]=i);return w&&Qj(s,t,w),s},Ip=(n,e,t)=>eR(n,typeof e!="symbol"?e+"":e,t),rR,Dg;rR=[Dr];class Vb{constructor(){fH(Dg,5,this),Ip(this,"fontFacesPromise",null),Ip(this,"foundFontNames",new Set),Ip(this,"fontFacesToEmbed",new Set),Ip(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){mt(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=mH()}onFontFamilyValue(e){mt(this.fontFacesPromise,"FontEmbedder not started");const t=sH(e);for(const r of t){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=Og(a.resolved))}}))}}async createCss(){await Promise.all(this.pendingPromises);let e="";for(const t of this.fontFacesToEmbed){let r=`@font-face {${t.fontFace}}`;for(const s of t.urls){if(!s.embedded)continue;const o=await s.embedded;o&&(r=r.replace(s.original,o))}e+=r}return e}}Dg=dH();gH(Dg,1,"onFontFamilyValue",rR,Vb);pH(Dg,Vb);async function mH(){var e;const n=[];for(const t of document.styleSheets){let r;try{r=t.cssRules}catch{}if(r){for(const s of t.cssRules)if(s instanceof CSSFontFaceRule)n.push(Yj(s.cssText,t.href??document.baseURI));else if(s instanceof CSSImportRule){const o=new URL(s.href,((e=s.parentStyleSheet)==null?void 0:e.href)??document.baseURI);n.push(Qw(o.href))}}else t.href&&n.push(Qw(t.href))}return Ye(await Promise.all(n)).flat()}const Qw=Vj(async n=>{const e=oH(await n.text(),n.url),t=await Promise.all(e.imports.map(({url:r})=>Qw(new URL(r,n.url).href)));return[...e.fontFaces,...Ye(t).flat()]});function sR(n){if(n.shadowRoot)return n.shadowRoot.childNodes;if(xH(n)){const e=n.assignedNodes();if(e!=null&&e.length)return e}return n.childNodes}function*Jw(n){for(const e of sR(n))yH(e)&&(yield e)}function Lg(n){var e;return((e=n.ownerDocument)==null?void 0:e.defaultView)??globalThis}function yH(n){return n instanceof Lg(n).Element}function SH(n){return n instanceof Lg(n).ShadowRoot}function vH(n){return"getRootNode"in n&&SH(n.getRootNode())}function xH(n){return vH(n)&&n instanceof Lg(n).HTMLSlotElement}function wH(n){return n.style}function qb(n,e){return Lg(n).getComputedStyle(n,e)}const rl={};class bH{constructor(e){j(this,"styles",new Map);j(this,"fonts",new Vb);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const t=Array.from(Jw(e));for(;t.length;){const r=t.pop();t.push(...Jw(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:t=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const s=t?IH(e.tagName.toLowerCase()):rl,o=r?((a=this.styles.get(e.parentElement))==null?void 0:a.self)??rl:rl,i={self:PH(e,{defaultStyles:s,parentStyles:o}),before:uT(e,"::before"),after:uT(e,"::after")};this.styles.set(e,i)}fetchResources(){const e=[];for(const t of this.styles.values())for(const r of Vt(t))if(r)for(const[s,o]of Object.entries(r)){if(!o)continue;s==="font-family"&&this.fonts.onFontFamilyValue(o);const i=iH(o);i.length!==0&&e.push(...i.map(async({url:a,original:c})=>{const d=await Og(a)??"data:";r[s]=o.replace(c,`url("${d}")`)}))}return Promise.all(e)}unwrapCustomElements(){const e=new Set,t=(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?t(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 sR(r))a instanceof Element?t(a,i):i.appendChild(a.cloneNode(!0))}};for(const r of this.styles.keys())t(r,null)}embedStyles(){let e="";for(const[t,r]of this.styles){if(r.after||r.before){const o=`pseudo-${xt()}`;t.classList.add(o),r.before&&(e+=`.${o}::before {${dT(r.before)}}
|
|
99
|
+
`),r.after&&(e+=`.${o}::after {${dT(r.after)}}
|
|
100
|
+
`)}const s=wH(t);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(){_H()}}function PH(n,{defaultStyles:e,parentStyles:t}){return n.computedStyleMap?oR(n.computedStyleMap(),{defaultStyles:e,parentStyles:t}):Yb(qb(n),{defaultStyles:e,parentStyles:t})}function uT(n,e){const t=qb(n,e),r=t.getPropertyValue("content");if(!(r===""||r==="none"))return Yb(t,{defaultStyles:rl,parentStyles:rl})}function oR(n,{defaultStyles:e,parentStyles:t}){const r={};for(const s of n.keys()){if(!Xj(s))continue;const o=n.get(s).toString();e[s]!==o&&(t[s]===o&&Zj(s)||(r[s]=o))}return r}function Yb(n,{defaultStyles:e,parentStyles:t}){const r={};for(const s of n){if(!Xj(s))continue;const o=n.getPropertyValue(s);e[s]!==o&&(t[s]===o&&Zj(s)||(r[s]=o))}return r}function dT(n){let e="";for(const[t,r]of Object.entries(n))e+=`${t}: ${r};`;return e}let Ec;const hT={};function CH(){if(!Ec){const n=document.createElement("iframe");n.style.display="none",document.body.appendChild(n);const e=Ar(n.contentDocument,"frame must have a document"),t=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");t.appendChild(r),e.body.appendChild(t),Ec={iframe:n,foreignObject:r,document:e}}return Ec}function _H(){Ec&&(document.body.removeChild(Ec.iframe),Ec=void 0)}const pT={defaultStyles:rl,parentStyles:rl};function IH(n){let e=hT[n];if(!e){const{foreignObject:t,document:r}=CH(),s=r.createElement(n);t.appendChild(s),e=s.computedStyleMap?oR(s.computedStyleMap(),pT):Yb(qb(s),pT),t.removeChild(s),hT[n]=e}return e}function EH(n,e){Array.from(n.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function fT(n,e){return n.replaceWith(e),e}async function hd(n,e){const t=document.createElement("img");e&&EH(e,t),t.setAttribute("src",n??"data:"),t.setAttribute("decoding","sync"),t.setAttribute("loading","eager");try{await t.decode()}catch{}return t}async function TH(n){try{const e=n.toDataURL();return await hd(e,n)}catch{return await hd(null,n)}}async function kH(n){try{const e=await Xr.getVideoFrameAsDataUrl(n);return hd(e,n)}catch(e){console.error("Could not get video frame",e)}if(n.poster){const e=await Og(n.poster);return hd(e,n)}return hd(null,n)}async function iR(n){if(n instanceof HTMLCanvasElement)return fT(n,await TH(n));if(n instanceof HTMLVideoElement)return fT(n,await kH(n));if(n instanceof HTMLImageElement){const e=n.currentSrc||n.src,t=await Og(e);n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}else n instanceof HTMLInputElement?n.setAttribute("value",n.value):n instanceof HTMLTextAreaElement&&(n.textContent=n.value);await Promise.all(Array.from(Jw(n),e=>iR(e)))}function Fg(n){const e=_.useRef();return _.useLayoutEffect(()=>{e.current=n}),_.useDebugValue(n),_.useCallback((...t)=>{const r=e.current;return mt(r,"fn does not exist"),r(...t)},[])}const Xb=_.createContext(null);function MH({context:n,editor:e,children:t}){const r=e.options.exportProvider;return p.jsx(Db,{editor:e,children:p.jsx(cj,{container:e.getContainer(),children:p.jsx(Xb.Provider,{value:n,children:p.jsx(r,{children:t})})})})}function Xd(){return _.useContext(Xb)}function AH(){const n=_.useContext(Xb),[e]=_.useState(V0);return _.useEffect(()=>(n==null||n.waitUntil(e),()=>{e.resolve()}),[e,n]),Fg(()=>{e.resolve()})}var jH=Object.create,aR=Object.defineProperty,RH=Object.getOwnPropertyDescriptor,OH=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),lR=n=>{throw TypeError(n)},cR=(n,e,t)=>e in n?aR(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,DH=n=>[,,,jH(null)],uR=["class","method","getter","setter","accessor","field","value","get","set"],dR=n=>n!==void 0&&typeof n!="function"?lR("Function expected"):n,LH=(n,e,t,r,s)=>({kind:uR[n],name:e,metadata:r,addInitializer:o=>t._?lR("Already initialized"):s.push(dR(o||null))}),FH=(n,e)=>cR(e,OH("metadata"),n[3]),NH=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},$H=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=uR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,RH(s,t)),b=r.length-1;b>=0;b--)c=LH(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,dR(i)&&(w[S]=i);return w&&aR(s,t,w),s},gT=(n,e,t)=>cR(n,typeof e!="symbol"?e+"":e,t),hR,Ng;hR=[Dr];class Zb{constructor(e){this.maxDelayTimeMs=e,NH(Ng,5,this),gT(this,"isResolved",!1),gT(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(t=>console.error("Error whilst waiting for export:",t)))}async resolvePromises(){let e=null;for(;this.promisesToWaitFor.length!==e;)e=this.promisesToWaitFor.length,await Promise.allSettled(this.promisesToWaitFor),await jw(0)}async resolve(){const e=jw(this.maxDelayTimeMs).then(()=>"timeout"),t=this.resolvePromises().then(()=>"resolved");await Promise.race([e,t])==="timeout"&&console.warn("[tldraw] Export delay timed out after ${this.maxDelayTimeMs}ms"),this.isResolved=!0}}Ng=DH();$H(Ng,1,"waitUntil",hR,Zb);FH(Ng,Zb);function zH(n,e,t={}){var b,P;if(!window.document)throw Error("No document");const{scale:r=1,background:s=n.getInstanceState().exportBackground,padding:o=n.options.defaultSvgPadding,preserveAspectRatio:i}=t,a=t.darkMode??n.user.getIsDarkMode(),c=n.getShapeAndDescendantIds(e),d=n.getUnorderedRenderingShapes(!1).filter(({id:k})=>c.has(k));let h=null;if(t.bounds)h=t.bounds;else for(const{id:k}of d){const E=n.getShapeMaskedPageBounds(k);E&&(h?h.union(E):h=E.clone())}if(!h)return;const f=e.length===1&&n.isShapeOfType(n.getShape(e[0]),"frame")?e[0]:null;f||h.expandBy(o);const g=h.width*r,y=h.height*r;try{(P=(b=document.body).focus)==null||P.call(b)}catch{}const S=new Zb(n.options.maxExportDelayMs),v=V0();return S.waitUntil(v),{jsx:p.jsx(BH,{editor:n,preserveAspectRatio:i,scale:r,pixelRatio:t.pixelRatio??null,bbox:h,background:s,singleFrameShapeId:f,isDarkMode:a,renderingShapes:d,onMount:v.resolve,waitUntil:S.waitUntil}),width:g,height:y,exportDelay:S}}function BH({editor:n,preserveAspectRatio:e,scale:t,pixelRatio:r,bbox:s,background:o,singleFrameShapeId:i,isDarkMode:a,renderingShapes:c,onMount:d,waitUntil:h}){const f=Wc(),g=_i({isDarkMode:a}),y=yb("export state",{defsById:{},shapeElements:null}),{defsById:S,shapeElements:v}=se(y),w=Fg(k=>{y.update(E=>{if(Cs(E.defsById,k.key))return E;const M=Promise.resolve(k.getElement());return h(M.then(A=>{y.update(R=>({...R,defsById:{...R.defsById,[k.key]:{pending:!1,element:A}}}))})),{...E,defsById:{...E.defsById,[k.key]:{pending:!0,element:M}}}})}),b=_.useMemo(()=>({isDarkMode:a,waitUntil:h,addExportDef:w,scale:t,pixelRatio:r,async resolveAssetUrl(k,E){const M=n.getAsset(k);return!M||M.type!=="image"&&M.type!=="video"?null:await n.resolveAssetUrl(k,{screenScale:t*(E/M.props.w),shouldResolveToOriginal:r===null,dpr:r??void 0})}}),[a,h,w,t,r,n]),P=_.useRef(!1);return _.useLayoutEffect(()=>{if(P.current)throw new Error("SvgExport should only render once - do not use with react strict mode");P.current=!0,(async()=>{const k={},E=c.map(async({id:A,opacity:R,index:D,backgroundIndex:V})=>{var F,$;if(A===i)return[];const L=n.getShape(A);if(n.isShapeOfType(L,"group"))return[];const U=[],K=n.getShapeUtil(L);if(K.toSvg||K.toBackgroundSvg){const[W,Y]=await Promise.all([(F=K.toSvg)==null?void 0:F.call(K,L,b),($=K.toBackgroundSvg)==null?void 0:$.call(K,L,b)]),Z=n.getShapePageTransform(L);let H=Z.toCssString(),Q=1;"scale"in L.props&&L.props.scale!==1&&(Q=L.props.scale,H=`${H} scale(${L.props.scale}, ${L.props.scale})`);const ae=n.getShapeMask(L.id),B=ae?me.From(me.Inverse(Z)).applyToPoints(ae):null,ne=Rb(f,L.id);B&&(k[ne]={pending:!1,element:p.jsx("clipPath",{id:ne,children:p.jsx("path",{d:`M${B.map(({x:he,y:Pe})=>`${he/Q},${Pe/Q}`).join("L")}Z`})})}),W&&U.push({zIndex:D,element:p.jsx("g",{transform:H,opacity:R,clipPath:ae?`url(#${ne})`:void 0,children:W},`fg_${L.id}`)}),Y&&U.push({zIndex:V,element:p.jsx("g",{transform:H,opacity:R,clipPath:ae?`url(#${ne})`:void 0,children:Y},`bg_${L.id}`)})}else U.push({zIndex:D,element:p.jsx(mT,{shape:L,util:K,component:Pj,className:"tl-shape",bbox:s,opacity:R},`fg_${L.id}`)}),K.backgroundComponent&&U.push({zIndex:V,element:p.jsx(mT,{shape:L,util:K,component:Cj,className:"tl-shape tl-shape-background",bbox:s,opacity:R},`bg_${L.id}`)});return U}),M=(await Promise.all(E)).flat();Yc.flushSync(()=>{y.update(A=>({...A,shapeElements:M.sort((R,D)=>R.zIndex-D.zIndex).map(({element:R})=>R),defsById:{...A.defsById,...k}}))})})()},[s,n,b,f,c,i,y]),_.useEffect(()=>{v!==null&&d()},[d,v]),p.jsx(MH,{editor:n,context:b,children:p.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:s.width*t,height:s.height*t,viewBox:`${s.minX} ${s.minY} ${s.width} ${s.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:o?i?g.solid:g.background:"transparent"},"data-color-mode":a?"dark":"light",className:`tl-container tl-theme__force-sRGB ${a?"tl-theme__dark":"tl-theme__light"}`,children:[p.jsx("defs",{children:Object.entries(S).map(([k,E])=>E.pending?null:p.jsx(_.Fragment,{children:E.element},k))}),v]})})}function mT({shape:n,util:e,className:t,component:r,bbox:s,opacity:o}){const i=te(),a=me.Translate(-s.minX,-s.minY).multiply(i.getShapePageTransform(n.id)),c=i.getShapeGeometry(n.id).bounds,d=Math.max(c.width,1),h=Math.max(c.height,1);return p.jsx(jb,{fallback:()=>null,children:p.jsx("foreignObject",{x:s.minX,y:s.minY,width:s.w,height:s.h,className:"tl-shape-foreign-object",children:p.jsx("div",{className:t,"data-shape-type":n.type,style:{clipPath:i.getShapeClipPath(n.id),transform:a.toCssString(),width:d,height:h,opacity:o},children:p.jsx(r,{shape:n,util:e})})})})}let UH=1;async function HH(n,e,t={}){const r=zH(n,e,t);if(!r)return;const s=n.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=Xk.createRoot(o,{identifierPrefix:`export_${UH++}_`});try{await Promise.resolve(),Yc.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=o.firstElementChild;return mt(a instanceof SVGSVGElement,"Expected an SVG element"),await KH(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),s.removeChild(o)},0)}}async function KH(n){const e=[...n.querySelectorAll("foreignObject.tl-shape-foreign-object > *")];if(!e.length)return;const t=new bH(n);try{t.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(o=>iR(o)));for(const o of e)t.readRootElementStyles(o);await t.fetchResources();const r=await t.getFontFaceCss();t.unwrapCustomElements();const s=t.embedStyles();if(r||s){const o=document.createElementNS("http://www.w3.org/2000/svg","style");o.textContent=`${r}
|
|
101
|
+
${s}`,n.prepend(o)}}finally{t.dispose()}}/*!
|
|
102
|
+
* canvas-size
|
|
103
|
+
* v2.0.0
|
|
104
|
+
* https://github.com/jhildenbiddle/canvas-size
|
|
105
|
+
* (c) 2015-2024 John Hildenbiddle <http://hildenbiddle.com>
|
|
106
|
+
* MIT license
|
|
107
|
+
*/function pd(n){const e=n.sizes.shift(),t=Math.max(Math.ceil(e[0]),1),r=Math.max(Math.ceil(e[1]),1),s=[t-1,r-1,1,1],o=performance.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope;let a,c;i?(a=new OffscreenCanvas(1,1),c=new OffscreenCanvas(t,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,c=document.createElement("canvas"),c.width=t,c.height=r);const d=a.getContext("2d"),h=c.getContext("2d");h&&(h.fillRect.apply(h,s),d.drawImage(c,t-1,r-1,1,1,0,0,1,1));const f=d&&d.getImageData(0,0,1,1).data[3]!==0,g=parseInt(performance.now()-o);return[a,c].forEach(y=>{y.height=0,y.width=0}),i?(postMessage({width:t,height:r,testTime:g,isTestPass:f}),!f&&n.sizes.length&&setTimeout(()=>{pd(n)},0)):f?n.onSuccess({width:t,height:r,testTime:g}):(n.onError({width:t,height:r,testTime:g}),n.sizes.length&&setTimeout(()=>{pd(n)},0)),f}const Ax={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]},vc={max:null,min:1,sizes:[],step:1024,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},Ku={};function jx(n){const e=n.width===n.height,t=n.height===1,r=n.width===1,s=[];if(!n.width||!n.height)n.sizes.forEach(o=>{const i=e||t?o:1,a=e||r?o:1;s.push([i,a])});else{const o=n.min||vc.min,i=n.step||vc.step;let a=Math.max(n.width,n.height);for(;a>=o;){const c=e||t?a:1,d=e||r?a:1;s.push([c,d]),a-=i}}return s}function Ep(n){const e=typeof window<"u",t=e&&"Promise"in window,r=e&&"HTMLCanvasElement"in window,s=e&&"OffscreenCanvas"in window,o=URL.createObjectURL(new Blob([])).slice(-36),i=performance.now(),{onError:a,onSuccess:c,...d}=n,h=()=>parseInt(performance.now()-i);let f=null;if(!r)return!1;if(n.useWorker&&s){const g=`
|
|
108
|
+
var canvasTest = ${pd.toString()};
|
|
109
|
+
onmessage = function(e) {
|
|
110
|
+
canvasTest(e.data);
|
|
111
|
+
};
|
|
112
|
+
`,y=new Blob([g],{type:"application/javascript"}),S=URL.createObjectURL(y);f=new Worker(S),URL.revokeObjectURL(S),f.onmessage=function(v){const{width:w,height:b,testTime:P,isTestPass:k}=v.data,E={width:w,height:b,testTime:P,totalTime:h()};k?(Ku[o].onSuccess(E),delete Ku[o]):Ku[o].onError(E)}}if(t)return new Promise(g=>{const y={...n,onError(S){let{width:v,height:w,testTime:b}=S;const P={width:v,height:w,testTime:b,totalTime:h()};let k;if(n.sizes.length===0)k=!0;else{const[[E,M]]=n.sizes.slice(-1);k=v===E&&w===M}a(P),k&&g({...P,success:!1})},onSuccess(S){let{width:v,height:w,testTime:b}=S;const P={width:v,height:w,testTime:b,totalTime:h()};c(P),g({...P,success:!0})}};if(f){const{onError:S,onSuccess:v}=y;Ku[o]={onError:S,onSuccess:v},f.postMessage(d)}else pd(y)});if(f)Ku[o]={onError:a,onSuccess:c},f.postMessage(d);else return pd(n)}const Rx={maxArea(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=jx({width:n.max,height:n.max,min:n.min,step:n.step,sizes:[...Ax.area]}),t={...vc,...n,sizes:e};return Ep(t)},maxHeight(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=jx({width:1,height:n.max,min:n.min,step:n.step,sizes:[...Ax.height]}),t={...vc,...n,sizes:e};return Ep(t)},maxWidth(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=jx({width:n.max,height:1,min:n.min,step:n.step,sizes:[...Ax.width]}),t={...vc,...n,sizes:e};return Ep(t)},test(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e={...vc,...n};return e.sizes=[...e.sizes],e.width&&e.height&&(e.sizes=[[e.width,e.height]]),Ep(e)}};let Ox=null;function WH(){return Ox||(Ox=GH()),Ox}async function GH(){const n=await Rx.maxWidth({usePromise:!0}),e=await Rx.maxHeight({usePromise:!0}),t=await Rx.maxArea({usePromise:!0});return{maxWidth:n.width,maxHeight:e.height,maxArea:t.width*t.height}}const yT=8192,VH=4096*4096;async function qH(n,e){if(n<=yT&&e<=yT&&n*e<=VH)return[n,e];const{maxWidth:t,maxHeight:r,maxArea:s}=await WH(),o=n/e;if(n>t&&(n=t,e=n/o),e>r&&(e=r,n=e*o),n*e>s){const i=Math.sqrt(s/(n*e));n*=i,e*=i}return[n,e]}async function YH(n,e){const{type:t,width:r,height:s,quality:o=1,pixelRatio:i=2}=e;let[a,c]=await qH(r*i,s*i);a=Math.floor(a),c=Math.floor(c);const d=a/r,h=await Gs.blobToDataUrl(new Blob([n],{type:"image/svg+xml"})),f=await new Promise(y=>{const S=xd();S.crossOrigin="anonymous",S.onload=async()=>{Et.isSafari&&await jw(250);const v=document.createElement("canvas"),w=v.getContext("2d");v.width=a,v.height=c,w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(S,0,0,a,c),URL.revokeObjectURL(h),y(v)},S.onerror=()=>{y(null)},S.src=h});if(!f)return null;const g=await new Promise(y=>f.toBlob(S=>{(!S||sn.throwToBlob.get())&&y(null),y(S)},"image/"+t,o));if(!g)return null;if(t==="png"){const y=new DataView(await g.arrayBuffer());return bo.setPhysChunk(y,d,{type:"image/"+t})}else return g}const Ks={menus:dn("open menus",[]),getOpenMenus(n){return n?this.menus.get().filter(e=>e.endsWith("-"+n)):this.menus.get()},addOpenMenu(n,e=""){const t=e?`${n}-${e}`:n,r=new Set(this.menus.get());r.has(t)||(r.add(t),this.menus.set([...r]))},deleteOpenMenu(n,e=""){const t=e?`${n}-${e}`:n,r=new Set(this.menus.get());r.has(t)&&(r.delete(t),this.menus.set([...r]))},clearOpenMenus(n){this.menus.set(n?this.menus.get().filter(e=>!e.endsWith("-"+n)):[])},_hiddenMenus:[],hideOpenMenus(n){if(this._hiddenMenus=[...this.getOpenMenus(n)],this._hiddenMenus.length!==0)for(const e of this._hiddenMenus)this.deleteOpenMenu(e,n)},showOpenMenus(n){if(this._hiddenMenus.length!==0){for(const e of this._hiddenMenus)this.addOpenMenu(e,n);this._hiddenMenus=[]}},isMenuOpen(n,e){return this.getOpenMenus(e).includes(n)},hasOpenMenus(n){return this.getOpenMenus(n).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(n){return{getOpenMenus:()=>this.getOpenMenus(n),addOpenMenu:e=>this.addOpenMenu(e,n),deleteOpenMenu:e=>this.deleteOpenMenu(e,n),clearOpenMenus:()=>this.clearOpenMenus(n),isMenuOpen:e=>this.isMenuOpen(e,n),hasOpenMenus:()=>this.hasOpenMenus(n),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}},e0=new tz,XH={maxShapesPerPage:4e3,maxFilesAtOnce:100,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,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:_.Fragment,enableToolbarKeyboardShortcuts:!0};function ST(n,e){if(!e)return!1;switch(n.type){case"mixed":return e.type==="mixed";case"shared":return e.type==="shared"&&n.value===e.value;default:throw un(n)}}class ZH{constructor(e){j(this,"map");this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){const t=this.get(e);if(t&&t.type!=="mixed")return t.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;const t=new Set;for(const[r,s]of this){if(!ST(s,e.get(r)))return!1;t.add(r)}for(const[r,s]of e)if(!t.has(r)&&!ST(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 t0 extends ZH{set(e,t){this.map.set(e,t)}applyValue(e,t){const r=this.get(e);if(!r){this.set(e,{type:"shared",value:t});return}switch(r.type){case"mixed":return;case"shared":r.value!==t&&this.set(e,{type:"mixed"});return;default:un(r,"type")}}}function QH(n,e,t){return jo(n).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:t})})}const JH="https://cdn.tldraw.com";function ia(){return`${JH}/${sj}`}function eK(n){switch(n.type){case"shapes":return`s${n.shapeIds.map(t=>Dx(t.slice(6))).join(".")}`;case"page":return"p"+Dx(ss.parseId(n.pageId));case"viewport":{const{bounds:e,pageId:t}=n;let r=`v${Math.round(e.x)}.${Math.round(e.y)}.${Math.round(e.w)}.${Math.round(e.h)}`;return t&&(r+="."+Dx(ss.parseId(t))),r}default:un(n)}}function tK(n){switch(n[0]){case"s":return{type:"shapes",shapeIds:n.slice(1).split(".").filter(Boolean).map(r=>Ct(decodeURIComponent(r)))};case"p":return{type:"page",pageId:ss.createId(decodeURIComponent(n.slice(1)))};case"v":{const[t,r,s,o,i]=n.slice(1).split(".");return{type:"viewport",bounds:new Se(Number(t),Number(r),Number(s),Number(o)),pageId:i?ss.createId(decodeURIComponent(i)):void 0}}default:throw Error("Invalid deep link string")}}function Dx(n){return encodeURIComponent(n).replace(/\./g,"%2E")}function nK(n,e){var s;let t=n;const r=new Set(e);for(;r.has(t);)t=(s=/^.*(\d+)$/.exec(t))!=null&&s[1]?t.replace(/(\d+)(?=\D?)$/,o=>(+o+1).toString()):`${t} 1`;return t}function Tp(n,e,t,r){if(t.length===0)return[];const s=new Map;for(const i of Ye(t.map(a=>n.getShape(a)))){const{parentId:a}=i;s.has(a)||s.set(a,{children:Ye(n.getSortedChildIdsForParent(a).map(c=>n.getShape(c))),moving:new Set}),s.get(a).moving.add(i)}const o=[];switch(e){case"toBack":{s.forEach(({moving:i,children:a})=>rK(i,a,o));break}case"toFront":{s.forEach(({moving:i,children:a})=>sK(i,a,o));break}case"forward":{s.forEach(({moving:i,children:a})=>oK(n,i,a,o,r));break}case"backward":{s.forEach(({moving:i,children:a})=>iK(n,i,a,o,r));break}}return o}function rK(n,e,t){const r=e.length;if(n.size===r)return;let s,o;for(let i=0;i<r;i++){const a=e[i];if(n.has(a))s=a.index,n.delete(a);else{o=a.index;break}}if(n.size!==0){const i=jc(s,o,n.size);t.push(...Array.from(n.values()).sort(Wn).map((a,c)=>({...a,index:i[c]})))}}function sK(n,e,t){const r=e.length;if(n.size===r)return;let s,o;for(let i=r-1;i>-1;i--){const a=e[i];if(n.has(a))o=a.index,n.delete(a);else{s=a.index;break}}if(n.size!==0){const i=jc(s,o,n.size);t.push(...Array.from(n.values()).sort(Wn).map((a,c)=>({...a,index:i[c]})))}}function vT(n,e){const t=n.getShapeGeometry(e),r=n.getShapePageTransform(e);return!t||!r?null:r.applyToPoints(t.vertices)}function pR(n,e){const t=Array.from(e).map(s=>{const o=vT(n,s);return o?{shape:s,vertices:o}:null}).filter(Boolean);return s=>{const o=vT(n,s);return o?t.some(i=>Gb(i.vertices,o)):!1}}function oK(n,e,t,r,s){var c;const o=pR(n,e),i=t.length;if(e.size===i)return;let a={name:"skipping"};for(let d=0;d<i;d++){const h=e.has(t[d]);switch(a.name){case"skipping":{if(!h)continue;a={name:"selecting",selectIndex:d};break}case"selecting":{if(h||!(s!=null&&s.considerAllShapes)&&!o(t[d]))continue;const{selectIndex:f}=a;jc(t[d].index,(c=t[d+1])==null?void 0:c.index,d-f).forEach((g,y)=>{const S=t[f+y];e.has(S)&&r.push({...S,index:g})}),a={name:"skipping"};break}}}}function iK(n,e,t,r,s){var c;const o=pR(n,e),i=t.length;if(e.size===i)return;let a={name:"skipping"};for(let d=i-1;d>-1;d--){const h=e.has(t[d]);switch(a.name){case"skipping":{if(!h)continue;a={name:"selecting",selectIndex:d};break}case"selecting":{if(h||!(s!=null&&s.considerAllShapes)&&!o(t[d]))continue;jc((c=t[d-1])==null?void 0:c.index,t[d].index,a.selectIndex-d).forEach((f,g)=>{const y=t[d+g+1];e.has(y)&&r.push({...y,index:f})}),a={name:"skipping"};break}}}}function fR({editor:n,ids:e}){const t=Ye(e.map(i=>n.getShape(i))),r=n.getShapesSharedRotation(e),s=n.getShapesRotatedPageBounds(e);if(!s)return null;const o=s.center.clone().rotWith(s.point,r);return{pageCenter:o,initialCursorAngle:o.angle(n.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:t.map(i=>({shape:i,initialPagePoint:n.getShapePageTransform(i.id).point()}))}}function of({delta:n,editor:e,snapshot:t,stage:r,centerOverride:s}){const{pageCenter:o,shapeSnapshots:i}=t;e.updateShapes(i.map(({shape:c,initialPagePoint:d})=>{const h=Mr(c.parentId)?e.getShapePageTransform(c.parentId):me.Identity(),f=C.RotWith(d,s??o,n),g=me.applyToPoint(me.Inverse(h),f),y=tl(c.rotation+n);return{id:c.id,type:c.type,x:g.x,y:g.y,rotation:y}}));const a=[];i.forEach(({shape:c})=>{var g,y,S;const d=e.getShape(c.id);if(!d)return;const h=e.getShapeUtil(c);if(r==="start"||r==="one-off"){const v=(g=h.onRotateStart)==null?void 0:g.call(h,c);v&&a.push(v)}const f=(y=h.onRotate)==null?void 0:y.call(h,c,d);if(f&&a.push(f),r==="end"||r==="one-off"){const v=(S=h.onRotateEnd)==null?void 0:S.call(h,c,d);v&&a.push(v)}}),a.length>0&&e.updateShapes(a)}const aK=n=>{const{store:e}=n,t=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:c,toId:d}=a,h=i.get(c);h?h.push(a):i.set(c,[a]);const f=i.get(d);f?f.push(a):i.set(d,[a])}return i}return le("arrowBindingsIndex",(o,i)=>{if(el(o))return s();const a=o,c=t.getDiffSince(i);if(c===Qr)return s();let d;function h(y){d??(d=new Map(a));const S=d.get(y.fromId),v=S==null?void 0:S.filter(P=>P.id!==y.id);v!=null&&v.length?d.set(y.fromId,v):d.delete(y.fromId);const w=d.get(y.toId),b=w==null?void 0:w.filter(P=>P.id!==y.id);b!=null&&b.length?d.set(y.toId,b):d.delete(y.toId)}function f(y){d??(d=new Map(a));let S=d.get(y);return S?S===a.get(y)&&(S=S.slice(0),d.set(y,S)):(S=[],d.set(y,S)),S}function g(y){f(y.fromId).push(y),f(y.toId).push(y)}for(const y of c){for(const S of Vt(y.added))g(S);for(const[S,v]of Vt(y.updated))h(S),g(v);for(const S of Vt(y.removed))h(S)}return d??a})};function lK(n,e,t){const r=n.getShapeMaskedPageBounds(e);return r===void 0?!0:!t.includes(r)}const cK=n=>{function e(t){const r=t.getCurrentPageShapeIds(),s=t.getViewportPageBounds(),o=new Set;return r.forEach(i=>{lK(t,i,s)&&o.add(i)}),o}return le("getCulledShapes",t=>{if(el(t))return e(n);const r=e(n);if(t.size!==r.size)return r;for(const s of t)if(!r.has(s))return r;return t})},uK=n=>{const e=n.query.ids("shape"),t=n.query.filterHistory("shape");function r(){const s={},o=e.get(),i=Array(o.size);return o.forEach(a=>i.push(n.get(a))),i.sort(Wn),i.forEach(a=>{s[a.parentId]||(s[a.parentId]=[]),s[a.parentId].push(a.id)}),s}return le("parentsToChildrenWithIndexes",(s,o)=>{if(el(s))return r();const i=t.getDiffSince(o);if(i===Qr)return r();if(i.length===0)return s;let a=null;const c=f=>{a||(a={...s}),a[f]?a[f]===s[f]&&(a[f]=[...a[f]]):a[f]=[]},d=new Set;let h;for(let f=0,g=i.length;f<g;f++){h=i[f];for(const y of Object.values(h.added))Sc(y)&&(c(y.parentId),a[y.parentId].push(y.id),d.add(a[y.parentId]));for(const[y,S]of Object.values(h.updated))if(Sc(S)&&Sc(y)){if(y.parentId!==S.parentId)c(y.parentId),c(S.parentId),a[y.parentId].splice(a[y.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),d.add(a[S.parentId]);else if(y.index!==S.index){c(S.parentId);const v=a[S.parentId].indexOf(S.id);a[S.parentId][v]=S.id,d.add(a[S.parentId])}}for(const y of Object.values(h.removed))Sc(y)&&(c(y.parentId),a[y.parentId].splice(a[y.parentId].indexOf(y.id),1))}for(const f of d){const g=Ye(f.map(y=>n.get(y)));g.sort(Wn),f.splice(0,f.length,...g.map(y=>y.id))}return a??s})},Lx=(n,e,t)=>{for(;!Er(t.parentId);){const r=n.get(t.parentId);if(!r)return!1;t=r}return t.parentId===e},dK=(n,e)=>{const t=n.query.ids("shape");let r=null;function s(){const o=e();return r=o,new Set([...t.get()].filter(i=>Lx(n,o,n.get(i))))}return le("_shapeIdsInCurrentPage",(o,i)=>{if(el(o))return s();const a=e();if(a!==r)return s();const c=n.history.getDiffSince(i);if(c===Qr)return s();const d=new tf(o);for(const f of c){for(const g of Object.values(f.added))Sc(g)&&Lx(n,a,g)&&d.add(g.id);for(const[g,y]of Object.values(f.updated))Sc(y)&&(Lx(n,a,y)?d.add(y.id):d.remove(y.id));for(const g of Object.keys(f.removed))Mr(g)&&d.remove(g)}const h=d.get();return h?ed(h.value,h.diff):o})};var hK=Object.create,gR=Object.defineProperty,pK=Object.getOwnPropertyDescriptor,fK=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),mR=n=>{throw TypeError(n)},yR=(n,e,t)=>e in n?gR(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,gK=n=>[,,,hK(null)],SR=["class","method","getter","setter","accessor","field","value","get","set"],vR=n=>n!==void 0&&typeof n!="function"?mR("Function expected"):n,mK=(n,e,t,r,s)=>({kind:SR[n],name:e,metadata:r,addInitializer:o=>t._?mR("Already initialized"):s.push(vR(o||null))}),yK=(n,e)=>yR(e,fK("metadata"),n[3]),SK=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},xR=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=SR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,pK(s,t)),b=r.length-1;b>=0;b--)c=mK(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,vR(i)&&(w[S]=i);return w&&gR(s,t,w),s},lc=(n,e,t)=>yR(n,typeof e!="symbol"?e+"":e,t),wR,bR,Zd;const vK=40;bR=[Dr],wR=[Dr];class $g{constructor(e){this.editor=e,SK(Zd,5,this),lc(this,"_clickId",""),lc(this,"_clickTimeout"),lc(this,"_clickScreenPoint"),lc(this,"_previousScreenPoint"),lc(this,"_clickState","idle"),lc(this,"lastPointerInfo",{})}_getClickTimeout(e,t=xt()){this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===e&&this._clickId===t){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=C.From(e.point),this._previousScreenPoint&&C.Dist2(this._previousScreenPoint,this._clickScreenPoint)>vK**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=C.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&&C.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"}}Zd=gK();xR(Zd,1,"_getClickTimeout",bR,$g);xR(Zd,1,"cancelDoubleClickTimeout",wR,$g);yK(Zd,$g);class xK{constructor(e){j(this,"_isEdgeScrolling",!1);j(this,"_edgeScrollDuration",-1);this.editor=e}updateEdgeScrolling(e){const{editor:t}=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>t.options.edgeScrollDelay){const s=t.options.edgeScrollEaseDuration>0?vn.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*s,y:r.y*s})}}getEdgeProximityFactors(e,t,r,s,o){const{editor:i}=this,a=i.options.edgeScrollDistance,c=r?i.options.coarsePointerWidth:0,d=e-c,h=e+c,f=s?0:a,g=o?t:t-a;return d<f?Math.min(1,(f-d)/a):h>g?-Math.min(1,(h-g)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=e,s=e.getViewportScreenBounds(),{isCoarsePointer:o,insets:[i,a,c,d]}=e.getInstanceState(),h=this.getEdgeProximityFactors(t,s.w,o,d,a),f=this.getEdgeProximityFactors(r,s.h,o,i,c);return{x:h,y:f}}moveCameraWhenCloseToEdge(e){const{editor:t}=this;if(!t.inputs.isDragging||t.inputs.isPanning||t.getCameraOptions().isLocked||e.x===0&&e.y===0)return;const r=t.getViewportScreenBounds(),s=r.w<1e3?.612:1,o=r.h<1e3?.612:1,i=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,c=a*e.x*s/i,d=a*e.y*o/i,{x:h,y:f,z:g}=t.getCamera();t.setCamera(new C(h+c,f+d,g))}}class wK{constructor(e,t){j(this,"disposeSideEffectListener");this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(s,o)=>{s.isFocused!==o.isFocused&&this.updateContainerClass()});const r=e.getInstanceState().isFocused;t!==r&&e.updateInstanceState({isFocused:!!t}),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 Wu(n){return PK}class bK{constructor(){j(this,"length",0);j(this,"head",null);j(this,"tail",this)}push(e){return new Qb(e,this)}toArray(){return fi}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const PK=new bK;class Qb{constructor(e,t){j(this,"length");this.head=e,this.tail=t,this.length=t.length+1}push(e){return new Qb(e,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let e=this;return{next(){if(e.length){const t=e.head;return e=e.tail,{value:t,done:!1}}else return{value:void 0,done:!0}}}}}class CK{constructor(e){j(this,"store");j(this,"dispose");j(this,"state","recording");j(this,"pendingDiff",new IK);j(this,"stacks",dn("HistoryManager.stacks",{undos:Wu(),redos:Wu()},{isEqual:(e,t)=>e.undos===t.undos&&e.redos===t.redos}));j(this,"annotateError");j(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??vd,this.dispose=this.store.addHistoryInterceptor((t,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(t.changes),this.stacks.update(({undos:s})=>({undos:s,redos:Wu()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:un(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;const e=this.pendingDiff.clear();this.stacks.update(({undos:t,redos:r})=>({undos:t.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,t){const r=this.state;r!=="paused"&&(t!=null&&t.history)&&(this.state=_K[t.history]);try{if(this._isInBatch)return ko(e),this;this._isInBatch=!0;try{ko(e)}catch(s){throw this.annotateError(s),s}finally{this._isInBatch=!1}return this}finally{this.state=r}}_undo({pushToRedoStack:e,toMark:t=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(),c=gA(a),d=Uw(a);e&&!c&&(i=i.push({type:"diff",diff:a}));let h=!1;if(c)for(;((s=o.head)==null?void 0:s.type)==="stop";){const f=o.head;if(o=o.tail,e&&(i=i.push(f)),f.id===t){h=!0;break}}if(!h)e:for(;o.head;){const f=o.head;switch(o=o.tail,e&&(i=i.push(f)),f.type){case"diff":ud(d,[Uw(f.diff)]);break;case"stop":if(!t)break e;if(f.id===t){h=!0;break e}break;default:un(f)}}if(!h&&t)return this;this.store.applyDiff(d,{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 t;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(;((t=s.head)==null?void 0:t.type)==="stop";)r=r.push(s.head),s=s.tail;const o=Nf();for(;s.head;){const i=s.head;if(r=r.push(i),s=s.tail,i.type==="diff")ud(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 t=this.stacks.get().undos;const r=[];for(;t.head&&!(t.head.type==="stop"&&t.head.id===e);)t.head.type==="diff"&&r.push(t.head.diff),t=t.tail;if(!t.head||((o=t.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=Nf();return ud(s,r.reverse()),this.stacks.update(({redos:i})=>({undos:t.push({type:"diff",diff:s}),redos:i})),this}_mark(e){ko(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:Wu(),redos:Wu()}),this.pendingDiff.clear()}getMarkIdMatching(e){let t=this.stacks.get().undos;for(;t.head;){if(t.head.type==="stop"&&t.head.id.includes(e))return t.head.id;t=t.tail}return null}debug(){const{undos:e,redos:t}=this.stacks.get();return{undos:e.toArray(),redos:t.toArray(),pendingDiff:this.pendingDiff.debug(),state:this.state}}}const _K={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class IK{constructor(){j(this,"diff",Nf());j(this,"isEmptyAtom",dn("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=Nf(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){ud(this.diff,[e]),this.isEmptyAtom.set(gA(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class EK{constructor(e){j(this,"scribbleItems",new Map);j(this,"state","paused");this.editor=e}addScribble(e,t=xt()){const r={id:t,scribble:{id:t,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(t,r),r}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}stop(e){const t=this.scribbleItems.get(e);if(!t)throw Error(`Scribble with id ${e} not found`);return t.delayRemaining=Math.min(t.delayRemaining,200),t.scribble.state="stopping",t}addPoint(e,t,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:t,y:r,z:s};return(!i||C.Dist(i,a)>=1)&&(o.next=a),o}tick(e){this.scribbleItems.size!==0&&this.editor.run(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:c,prev:d}=t;c&&c!==d&&(t.prev=c,t.scribble.points.push(c)),t.scribble.points.length>8&&(t.scribble.state="active");return}t.delayRemaining>0&&(t.delayRemaining=Math.max(0,t.delayRemaining-e)),t.timeoutMs+=e,t.timeoutMs>=16&&(t.timeoutMs=0);const{delayRemaining:r,timeoutMs:s,prev:o,next:i,scribble:a}=t;switch(a.state){case"active":{i&&i!==o?(t.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):s===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&s===0){if(a.points.length===1){this.scribbleItems.delete(t.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:t})=>({...t,points:[...t.points]})).slice(-5)})})}}var TK=Object.create,PR=Object.defineProperty,kK=Object.getOwnPropertyDescriptor,MK=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),CR=n=>{throw TypeError(n)},_R=(n,e,t)=>e in n?PR(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,AK=n=>[,,,TK(null)],IR=["class","method","getter","setter","accessor","field","value","get","set"],ER=n=>n!==void 0&&typeof n!="function"?CR("Function expected"):n,jK=(n,e,t,r,s)=>({kind:IR[n],name:e,metadata:r,addInitializer:o=>t._?CR("Already initialized"):s.push(ER(o||null))}),RK=(n,e)=>_R(e,MK("metadata"),n[3]),OK=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},zg=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=IR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,kK(s,t)),b=r.length-1;b>=0;b--)c=jK(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,ER(i)&&(w[S]=i);return w&&PR(s,t,w),s},DK=(n,e,t)=>_R(n,e+"",t),TR,kR,MR,AR,vl;const He=n=>Math.round(n*10**8)/10**8;function ai(n,e,t,r,s){const o=n.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&He(a.length)===He(t)&&Hs(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));if(o.length===0)return[];const i=new Set;return o.forEach(a=>{const c=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(c)){i.add(c);const d=ai(n,c,t,r,Hs(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));o.push(...d)}}),o}function LK(n){n.sort((e,t)=>t.gaps.length-e.gaps.length);for(let e=n.length-1;e>0;e--){const t=n[e];for(let r=e-1;r>=0;r--){const s=n[r];if(s.direction===t.direction&&t.gaps.every(o=>s.gaps.some(i=>He(o.startEdge[0].x)===He(i.startEdge[0].x)&&He(o.startEdge[0].y)===He(i.startEdge[0].y)&&He(o.startEdge[1].x)===He(i.startEdge[1].x)&&He(o.startEdge[1].y)===He(i.startEdge[1].y))&&s.gaps.some(i=>He(o.endEdge[0].x)===He(i.endEdge[0].x)&&He(o.endEdge[0].y)===He(i.endEdge[0].y)&&He(o.endEdge[1].x)===He(i.endEdge[1].x)&&He(o.endEdge[1].y)===He(i.endEdge[1].y)))){n.splice(e,1);break}}}}AR=[le],MR=[le],kR=[le],TR=[le];class Xc{constructor(e){this.manager=e,OK(vl,5,this),DK(this,"editor"),this.editor=e.editor}getSnapPointsCache(){const{editor:e}=this;return e.store.createComputedCache("snapPoints",t=>{const r=e.getShapePageTransform(t.id);if(!r)return;const o=e.getShapeUtil(t).getBoundsSnapGeometry(t).points??e.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!o))return o.map((i,a)=>{const{x:c,y:d}=me.applyToPoint(r,i);return{x:c,y:d,id:`${t.id}:${a}`}})})}getSnapPoints(e){return this.getSnapPointsCache().get(e)??[]}getSnappablePoints(){const e=this.getSnapPointsCache(),t=this.manager.getSnappableShapes(),r=[];for(const s of t){const o=e.get(s);o&&r.push(...o)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:Ar(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){const e=[],t=[];let r,s;const o=this.getSnappableGapNodes().sort((a,c)=>a.pageBounds.minX-c.pageBounds.minX);for(let a=0;a<o.length;a++){r=o[a];for(let c=a+1;c<o.length;c++)s=o[c],r.pageBounds.maxX<s.pageBounds.minX&&$u(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)&&e.push({startNode:r,endNode:s,startEdge:[new C(r.pageBounds.maxX,r.pageBounds.minY),new C(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new C(s.pageBounds.minX,s.pageBounds.minY),new C(s.pageBounds.minX,s.pageBounds.maxY)],length:s.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Hs(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)})}const i=o.sort((a,c)=>a.pageBounds.minY-c.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let c=a+1;c<i.length;c++)s=i[c],r.pageBounds.maxY<s.pageBounds.minY&&$u(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)&&t.push({startNode:r,endNode:s,startEdge:[new C(r.pageBounds.minX,r.pageBounds.maxY),new C(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new C(s.pageBounds.minX,s.pageBounds.minY),new C(s.pageBounds.maxX,s.pageBounds.minY)],length:s.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Hs(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)})}return{horizontal:e,vertical:t}}snapTranslateShapes({lockedAxis:e,initialSelectionPageBounds:t,initialSelectionSnapPoints:r,dragDelta:s}){var w,b;const o=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(s),c=r.map(({x:P,y:k},E)=>({id:"selection:"+E,x:P+s.x,y:k+s.y})),d=i,h=[],f=[],g=new C(o,o);this.collectPointSnaps({minOffset:g,nearestSnapsX:h,nearestSnapsY:f,otherNodeSnapPoints:d,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:h,nearestSnapsY:f,minOffset:g});const y=new C(e==="x"?0:((w=h[0])==null?void 0:w.nudge)??0,e==="y"?0:((b=f[0])==null?void 0:b.nudge)??0);g.x=0,g.y=0,h.length=0,f.length=0,c.forEach(P=>{P.x+=y.x,P.y+=y.y}),a.translate(y),this.collectPointSnaps({minOffset:g,nearestSnapsX:h,nearestSnapsY:f,otherNodeSnapPoints:d,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:h,nearestSnapsY:f,minOffset:g});const S=this.getPointSnapLines({nearestSnapsX:h,nearestSnapsY:f}),v=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:h,nearestSnapsY:f});return this.manager.setIndicators([...v,...S]),{nudge:y}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:t,handle:r,isAspectRatioLocked:s,isResizingFromCenter:o}){var R,D;const i=this.manager.getSnapThreshold(),{box:a,scaleX:c,scaleY:d}=Se.Resize(e,r,o?t.x*2:t.x,o?t.y*2:t.y,s);let h=r;c<0&&(h=$7(h)),d<0&&(h=N7(h)),o&&(a.center=e.center);const f=h==="top"||h==="bottom",g=h==="left"||h==="right",y=xT(h,a),S=this.getSnappablePoints(),v=[],w=[],b=new C(i,i);this.collectPointSnaps({minOffset:b,nearestSnapsX:v,nearestSnapsY:w,otherNodeSnapPoints:S,selectionSnapPoints:y});const P=new C(f?0:((R=v[0])==null?void 0:R.nudge)??0,g?0:((D=w[0])==null?void 0:D.nudge)??0);if(s&&z7(h)&&P.len()!==0){const V=v.length&&w.length?Math.abs(P.x)<Math.abs(P.y)?"x":"y":v.length?"x":"y",L=e.aspectRatio;V==="x"?(w.length=0,P.y=P.x/L,(h==="bottom_left"||h==="top_right")&&(P.y=-P.y)):(v.length=0,P.x=P.y*L,(h==="bottom_left"||h==="top_right")&&(P.x=-P.x))}const k=C.Add(t,P),{box:E}=Se.Resize(e,r,o?k.x*2:k.x,o?k.y*2:k.y,s);o&&(E.center=e.center);const M=xT("any",E);v.length=0,w.length=0,b.x=0,b.y=0,this.collectPointSnaps({minOffset:b,nearestSnapsX:v,nearestSnapsY:w,otherNodeSnapPoints:S,selectionSnapPoints:M});const A=this.getPointSnapLines({nearestSnapsX:v,nearestSnapsY:w});return this.manager.setIndicators([...A]),{nudge:P}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:s,nearestSnapsY:o}){for(const i of e)for(const a of t){const c=C.Sub(i,a),d=Math.abs(c.x),h=Math.abs(c.y);He(d)<=He(r.x)&&(He(d)<He(r.x)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=d),He(h)<=He(r.y)&&(He(h)<He(r.y)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=h)}}collectGapSnaps({selectionPageBounds:e,minOffset:t,nearestSnapsX:r,nearestSnapsY:s}){const{horizontal:o,vertical:i}=this.getVisibleGaps();for(const a of o){if(!$u(a.breadthIntersection[0],a.breadthIntersection[1],e.minY,e.maxY))continue;const d=a.startEdge[0].x+a.length/2-e.center.x;if(a.length>e.width&&He(Math.abs(d))<=He(t.x)){He(Math.abs(d))<He(t.x)&&(r.length=0),t.x=Math.abs(d);const b={type:"gap_center",gap:a,nudge:d},P=r.find(({type:E})=>E==="gap_center"),k=P&&Hs(a.breadthIntersection[0],a.breadthIntersection[1],P.gap.breadthIntersection[0],P.gap.breadthIntersection[1]);P&&P.gap.length>a.length&&k?r[r.indexOf(P)]=b:(!P||!k)&&r.push(b)}const f=a.startNode.pageBounds.minX-a.length,g=e.maxX,y=f-g;He(Math.abs(y))<=He(t.x)&&(He(Math.abs(y))<He(t.x)&&(r.length=0),t.x=Math.abs(y),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:y}));const S=a.endNode.pageBounds.maxX+a.length,v=e.minX,w=S-v;He(Math.abs(w))<=He(t.x)&&(He(Math.abs(w))<He(t.x)&&(r.length=0),t.x=Math.abs(w),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:w}))}for(const a of i){if(!$u(a.breadthIntersection[0],a.breadthIntersection[1],e.minX,e.maxX))continue;const d=a.startEdge[0].y+a.length/2-e.center.y;if(a.length>e.height&&He(Math.abs(d))<=He(t.y)){He(Math.abs(d))<He(t.y)&&(s.length=0),t.y=Math.abs(d);const b={type:"gap_center",gap:a,nudge:d},P=s.find(({type:E})=>E==="gap_center"),k=P&&$u(P.gap.breadthIntersection[0],P.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);P&&P.gap.length>a.length&&k?s[s.indexOf(P)]=b:(!P||!k)&&s.push(b);continue}const f=a.startNode.pageBounds.minY-a.length,g=e.maxY,y=f-g;He(Math.abs(y))<=He(t.y)&&(He(Math.abs(y))<He(t.y)&&(s.length=0),t.y=Math.abs(y),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:y}));const S=a.endNode.pageBounds.maxY+a.length,v=e.minY,w=S-v;He(Math.abs(w))<=He(t.y)&&(He(Math.abs(w))<He(t.y)&&(s.length=0),t.y=Math.abs(w),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:w}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:t}){const r={},s={};if(e.length>0){for(const o of e)if(o.type==="points"){const i=He(o.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(o.points)}}if(t.length>0){for(const o of t)if(o.type==="points"){const i=He(o.points.otherPoint.y);s[i]||(s[i]=[]),s[i].push(o.points)}}return Object.values(r).concat(Object.values(s)).map(o=>({id:xt(),type:"points",points:q0(o.map(i=>C.From(i.otherPoint)).concat(o.map(i=>C.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:t,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(t.length>0)for(const c of t){if(c.type==="points")continue;const{gap:{breadthIntersection:d,startEdge:h,startNode:f,endNode:g,length:y,endEdge:S}}=c;switch(c.type){case"gap_center":{const v=(y-e.width)/2,w=Hs(d[0],d[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:xt(),gaps:[...ai(o,f.id,v,"backward",w),{startEdge:h,endEdge:i.left},{startEdge:i.right,endEdge:S},...ai(o,g.id,v,"forward",w)]});break}case"gap_duplicate":{const v=Hs(d[0],d[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:xt(),gaps:c.protrusionDirection==="left"?[{startEdge:i.right,endEdge:h.map(w=>w.clone().addXY(-f.pageBounds.width,0))},{startEdge:h,endEdge:S},...ai(o,g.id,y,"forward",v)]:[...ai(o,f.id,y,"backward",v),{startEdge:h,endEdge:S},{startEdge:S.map(w=>w.clone().addXY(c.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const c of r){if(c.type==="points")continue;const{gap:{breadthIntersection:d,startEdge:h,startNode:f,endNode:g,length:y,endEdge:S}}=c;switch(c.type){case"gap_center":{const v=(y-e.height)/2,w=Hs(d[0],d[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:xt(),gaps:[...ai(s,f.id,v,"backward",w),{startEdge:h,endEdge:i.top},{startEdge:i.bottom,endEdge:S},...ai(s,c.gap.endNode.id,v,"forward",w)]});break}case"gap_duplicate":{const v=Hs(d[0],d[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:xt(),gaps:c.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:h.map(w=>w.clone().addXY(0,-f.pageBounds.height))},{startEdge:h,endEdge:S},...ai(s,g.id,y,"forward",v)]:[...ai(s,f.id,y,"backward",v),{startEdge:h,endEdge:S},{startEdge:S.map(w=>w.clone().addXY(0,g.pageBounds.height)),endEdge:i.top}]})}break}}return LK(a),a}}vl=AK();zg(vl,1,"getSnapPointsCache",AR,Xc);zg(vl,1,"getSnappablePoints",MR,Xc);zg(vl,1,"getSnappableGapNodes",kR,Xc);zg(vl,1,"getVisibleGaps",TR,Xc);RK(vl,Xc);function xT(n,e){const{minX:t,maxX:r,minY:s,maxY:o}=e,i=[];switch(n){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:t,y:s})}switch(n){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:s})}switch(n){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:o})}switch(n){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:t,y:o})}return i}var FK=Object.create,jR=Object.defineProperty,NK=Object.getOwnPropertyDescriptor,$K=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),RR=n=>{throw TypeError(n)},OR=(n,e,t)=>e in n?jR(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,zK=n=>[,,,FK(null)],DR=["class","method","getter","setter","accessor","field","value","get","set"],LR=n=>n!==void 0&&typeof n!="function"?RR("Function expected"):n,BK=(n,e,t,r,s)=>({kind:DR[n],name:e,metadata:r,addInitializer:o=>t._?RR("Already initialized"):s.push(LR(o||null))}),UK=(n,e)=>OR(e,$K("metadata"),n[3]),HK=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},KK=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=DR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,NK(s,t)),b=r.length-1;b>=0;b--)c=BK(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,LR(i)&&(w[S]=i);return w&&jR(s,t,w),s},WK=(n,e,t)=>OR(n,e+"",t),FR,Bg;const GK=()=>null,VK=()=>[];FR=[le];class Jb{constructor(e){this.manager=e,HK(Bg,5,this),WK(this,"editor"),this.editor=e.editor}getSnapGeometryCache(){const{editor:e}=this;return e.store.createComputedCache("handle snap geometry",t=>{const r=e.getShapeUtil(t).getHandleSnapGeometry(t),s=r.getSelfSnapOutline?r.getSelfSnapOutline.bind(r):GK,o=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):VK;return{outline:r.outline===void 0?e.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:s,getSelfSnapPoints:o}})}*iterateSnapPointsInPageSpace(e,t){var s,o;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapPoints(t);if(r&&r.length){const i=Ar(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 c=Ar(this.editor.getShapePageTransform(i));for(const d of a)yield c.applyToPoint(d)}}*iterateSnapOutlines(e,t){var s,o;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapOutline(t);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:t,handleInPageSpace:r}){const s=this.manager.getSnapThreshold();let o=s,i=null;for(const d of this.iterateSnapPointsInPageSpace(e,t))C.DistMin(r,d,o)&&(o=C.Dist(r,d),i=d);if(i)return i;let a=s,c=null;for(const{shapeId:d,outline:h}of this.iterateSnapOutlines(e,t)){const f=Ar(this.editor.getShapePageTransform(d)),g=this.editor.getPointInShapeSpace(d,r),y=h.nearestPoint(g),S=f.applyToPoint(y);C.DistMin(r,S,a)&&(a=C.Dist(r,S),c=S)}return c||null}snapHandle({currentShapeId:e,handle:t}){const s=Ar(this.editor.getShapePageTransform(e)).applyToPoint(t),o=this.getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:s});return o?(this.manager.setIndicators([{id:xt(),type:"points",points:[o]}]),{nudge:C.Sub(o,s)}):null}}Bg=zK();KK(Bg,1,"getSnapGeometryCache",FR,Jb);UK(Bg,Jb);var qK=Object.create,NR=Object.defineProperty,YK=Object.getOwnPropertyDescriptor,XK=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),$R=n=>{throw TypeError(n)},zR=(n,e,t)=>e in n?NR(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ZK=n=>[,,,qK(null)],BR=["class","method","getter","setter","accessor","field","value","get","set"],UR=n=>n!==void 0&&typeof n!="function"?$R("Function expected"):n,QK=(n,e,t,r,s)=>({kind:BR[n],name:e,metadata:r,addInitializer:o=>t._?$R("Already initialized"):s.push(UR(o||null))}),JK=(n,e)=>zR(e,XK("metadata"),n[3]),eW=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},e1=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=BR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,YK(s,t)),b=r.length-1;b>=0;b--)c=QK(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,UR(i)&&(w[S]=i);return w&&NR(s,t,w),s},Fx=(n,e,t)=>zR(n,typeof e!="symbol"?e+"":e,t),HR,KR,WR,Zc;WR=[le],KR=[le],HR=[le];class Qd{constructor(e){this.editor=e,eW(Zc,5,this),Fx(this,"shapeBounds"),Fx(this,"handles"),Fx(this,"_snapIndicators",dn("snapLines",void 0)),this.shapeBounds=new Xc(this),this.handles=new Jb(this)}getIndicators(){return this._snapIndicators.get()??fi}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,t=e.getViewportPageBounds(),r=e.getSelectedShapeIds(),s=new Set,o=i=>{if(Mr(i)){const c=e.getShape(i);c&&e.isShapeOfType(c,"frame")&&s.add(i)}const a=e.getSortedChildIdsForParent(i);for(const c of a){if(r.includes(c))continue;const d=e.getShape(c);if(!d||!e.getShapeUtil(d).canSnap(d))continue;const f=e.getShapePageBounds(c);if(f&&t.includes(f)){if(e.isShapeOfType(d,"group")){o(c);continue}s.add(c)}}};return o(this.getCurrentCommonAncestor()??e.getCurrentPageId()),s}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Zc=ZK();e1(Zc,1,"getSnapThreshold",WR,Qd);e1(Zc,1,"getSnappableShapes",KR,Qd);e1(Zc,1,"getCurrentCommonAncestor",HR,Qd);JK(Zc,Qd);const tW=/\r?\n|\r/g;function wT(n){return n.replace(tW,`
|
|
113
|
+
`).split(`
|
|
114
|
+
`).map(e=>e||" ").join(`
|
|
115
|
+
`)}const nW={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},rW=/\s/;class sW{constructor(e){j(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,t){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",t.fontFamily),r.style.setProperty("font-style",t.fontStyle),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("font-size",t.fontSize+"px"),r.style.setProperty("line-height",t.lineHeight*t.fontSize+"px"),r.style.setProperty("max-width",t.maxWidth===null?null:t.maxWidth+"px"),r.style.setProperty("min-width",t.minWidth===null?null:t.minWidth+"px"),r.style.setProperty("padding",t.padding),r.style.setProperty("overflow-wrap",t.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=wT(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:t=!1}={}){const r=[],s=e.getBoundingClientRect(),o=-s.left,i=-s.top,a=new Range,c=e.childNodes[0];let d=0,h=null,f=null,g=0,y=0,S=!1;for(const v of e.childNodes)if(v.nodeType===Node.TEXT_NODE)for(const w of v.textContent??""){a.setStart(c,d),a.setEnd(c,d+w.length);const b=a.getClientRects(),P=b[b.length-1],k=P.top+i,E=P.left+o,M=P.right+o,A=E<y,R=rW.test(w);if(R!==f||k!==g||!h){if(h){if(t&&k!==g){S=!0;break}r.push(h)}h={box:{x:E,y:k,w:P.width,h:P.height},text:w},y=E}else A&&(h.box.x=E),h.box.w=A?h.box.w+P.width:M-h.box.x,h.text+=w;w===`
|
|
116
|
+
`&&(y=0),f=R,g=k,d+=w.length}return h&&r.push(h),{spans:r,didTruncate:S}}measureTextSpans(e,t){if(e==="")return[];const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(r);const s=Math.ceil(t.width-t.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",`${t.fontSize}px`),r.style.setProperty("font-family",t.fontFamily),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("line-height",`${t.lineHeight*t.fontSize}px`),r.style.setProperty("text-align",nW[t.textAlign]),r.style.setProperty("font-style",t.fontStyle);const o=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";o&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=wT(e);r.textContent=i;const{spans:a,didTruncate:c}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:o});if(t.overflow==="truncate-ellipsis"&&c){r.textContent="…";const d=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${s-d}px`),r.textContent=i;const h=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,f=h[h.length-1];return h.push({text:"…",box:{x:Math.min(f.box.x+f.box.w,t.width-t.padding-d),y:f.box.y,w:d,h:f.box.h}}),h}return r.remove(),a}}var oW=Object.create,GR=Object.defineProperty,iW=Object.getOwnPropertyDescriptor,aW=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),VR=n=>{throw TypeError(n)},qR=(n,e,t)=>e in n?GR(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,lW=n=>[,,,oW(null)],YR=["class","method","getter","setter","accessor","field","value","get","set"],XR=n=>n!==void 0&&typeof n!="function"?VR("Function expected"):n,cW=(n,e,t,r,s)=>({kind:YR[n],name:e,metadata:r,addInitializer:o=>t._?VR("Already initialized"):s.push(XR(o||null))}),uW=(n,e)=>qR(e,aW("metadata"),n[3]),dW=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},ZR=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=YR[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,iW(s,t)),b=r.length-1;b>=0;b--)c=cW(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,XR(i)&&(w[S]=i);return w&&GR(s,t,w),s},kp=(n,e,t)=>qR(n,typeof e!="symbol"?e+"":e,t),QR,JR,Jd;const bT=wM;JR=[Dr],QR=[Dr];class Ug{constructor(e){this.editor=e,dW(Jd,5,this),kp(this,"cancelRaf"),kp(this,"isPaused",!0),kp(this,"now",0),kp(this,"prevPoint",new C),this.editor.disposables.add(this.dispose),this.start()}start(){var e;this.isPaused=!1,(e=this.cancelRaf)==null||e.call(this),this.cancelRaf=bT(this.tick),this.now=Date.now()}tick(){if(this.isPaused)return;const e=Date.now(),t=e-this.now;this.now=e,this.updatePointerVelocity(t),this.editor.emit("frame",t),this.editor.emit("tick",t),this.cancelRaf=bT(this.tick)}dispose(){var e;this.isPaused=!0,(e=this.cancelRaf)==null||e.call(this)}updatePointerVelocity(e){const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:s}}}=this;if(e===0)return;const o=C.Sub(r,t);this.prevPoint=r.clone();const i=o.len(),a=i?o.div(i):new C(0,0),c=s.clone().lrp(a.mul(i/e),.5);Math.abs(c.x)<.01&&(c.x=0),Math.abs(c.y)<.01&&(c.y=0),s.equals(c)||(this.editor.inputs.pointerVelocity=c)}}Jd=lW();ZR(Jd,1,"tick",JR,Ug);ZR(Jd,1,"dispose",QR,Ug);uW(Jd,Ug);var hW=Object.create,eO=Object.defineProperty,pW=Object.getOwnPropertyDescriptor,fW=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),tO=n=>{throw TypeError(n)},nO=(n,e,t)=>e in n?eO(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,gW=n=>[,,,hW(null)],rO=["class","method","getter","setter","accessor","field","value","get","set"],sO=n=>n!==void 0&&typeof n!="function"?tO("Function expected"):n,mW=(n,e,t,r,s)=>({kind:rO[n],name:e,metadata:r,addInitializer:o=>t._?tO("Already initialized"):s.push(sO(o||null))}),yW=(n,e)=>nO(e,fW("metadata"),n[3]),SW=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Ts=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=rO[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,pW(s,t)),b=r.length-1;b>=0;b--)c=mW(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,sO(i)&&(w[S]=i);return w&&eO(s,t,w),s},PT=(n,e,t)=>nO(n,typeof e!="symbol"?e+"":e,t),oO,iO,aO,lO,cO,uO,dO,hO,pO,fO,gO,mO,cr;mO=[le],gO=[le],fO=[le],pO=[le],hO=[le],dO=[le],uO=[le],cO=[le],lO=[le],aO=[le],iO=[le],oO=[le];class $r{constructor(e,t){if(this.user=e,this.inferDarkMode=t,SW(cr,5,this),PT(this,"systemColorScheme",dn("systemColorScheme","light")),PT(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??vo.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??vo.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??vo.name}getLocale(){return this.user.userPreferences.get().locale??vo.locale}getColor(){return this.user.userPreferences.get().color??vo.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??vo.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??vo.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??vo.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??vo.isPasteAtCursorMode}}cr=gW();Ts(cr,1,"getUserPreferences",mO,$r);Ts(cr,1,"getIsDarkMode",gO,$r);Ts(cr,1,"getEdgeScrollSpeed",fO,$r);Ts(cr,1,"getAnimationSpeed",pO,$r);Ts(cr,1,"getId",hO,$r);Ts(cr,1,"getName",dO,$r);Ts(cr,1,"getLocale",uO,$r);Ts(cr,1,"getColor",cO,$r);Ts(cr,1,"getIsSnapMode",lO,$r);Ts(cr,1,"getIsWrapMode",aO,$r);Ts(cr,1,"getIsDynamicResizeMode",iO,$r);Ts(cr,1,"getIsPasteAtCursorMode",oO,$r);yW(cr,$r);const vW={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"},xW=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class Re{constructor(e,t){j(this,"performanceTracker");j(this,"id");j(this,"type");j(this,"shapeType");j(this,"initial");j(this,"children");j(this,"isLockable");j(this,"parent");j(this,"_path");j(this,"_current");j(this,"_isActive");j(this,"_currentToolIdMask",dn("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=dn("toolIsActive"+this.id,!1),this._current=dn("toolState"+this.id,void 0),this._path=le("toolPath"+this.id,()=>{const a=this.getCurrent();return this.id+(a?`.${a.getPath()}`:"")}),this.parent=t??{},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 Jk}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}transition(e,t={}){var o;const r=e.split(".");let s=this;for(let i=0;i<r.length;i++){const a=r[i],c=s.getCurrent(),d=(o=s.children)==null?void 0:o[a];if(!d)throw Error(`${s.id} - no child state exists with the id ${a}.`);if((c==null?void 0:c.id)!==d.id&&(c==null||c.exit(t,a),s._current.set(d),d.enter(t,(c==null?void 0:c.id)||"initial"),!d.getIsActive()))break;s=d}return this}handleEvent(e){var s;const t=vW[e.name],r=this._current.__unsafe__getWithoutCapture();(s=this[t])==null||s.call(this,e),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(e)}enter(e,t){var r;if(sn.measurePerformance.get()&&xW.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,e,t),this.children&&this.initial&&this.getIsActive()){const s=this.children[this.initial];this._current.set(s),s.enter(e,t)}}exit(e,t){var r,s;sn.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,e,t),this.getIsActive()||(s=this.getCurrent())==null||s.exit(e,t)}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(e){this._currentToolIdMask.set(e)}}j(Re,"id"),j(Re,"initial"),j(Re,"children"),j(Re,"isLockable",!0);class n0 extends Re{static children(){return[]}onKeyDown(e){var t;switch(e.code){case"KeyZ":{if(!(e.shiftKey||e.ctrlKey)){const r=this.getCurrent();r&&((t=r.getCurrent())==null?void 0:t.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...e,onInteractionEnd:r.id})}break}}}}j(n0,"id","root"),j(n0,"initial","");var wW=Object.create,yO=Object.defineProperty,bW=Object.getOwnPropertyDescriptor,SO=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),vO=n=>{throw TypeError(n)},xO=(n,e,t)=>e in n?yO(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,PW=n=>[,,,wW((n==null?void 0:n[SO("metadata")])??null)],wO=["class","method","getter","setter","accessor","field","value","get","set"],bO=n=>n!==void 0&&typeof n!="function"?vO("Function expected"):n,CW=(n,e,t,r,s)=>({kind:wO[n],name:e,metadata:r,addInitializer:o=>t._?vO("Already initialized"):s.push(bO(o||null))}),_W=(n,e)=>xO(e,SO("metadata"),n[3]),IW=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},_e=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=wO[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,bW(s,t)),b=r.length-1;b>=0;b--)c=CW(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,bO(i)&&(w[S]=i);return w&&yO(s,t,w),s},$e=(n,e,t)=>xO(n,typeof e!="symbol"?e+"":e,t),PO,CO,_O,IO,EO,TO,kO,MO,AO,jO,RO,OO,DO,LO,FO,NO,$O,zO,BO,UO,HO,KO,WO,GO,VO,qO,YO,XO,ZO,QO,JO,eD,tD,nD,rD,sD,oD,iD,aD,lD,cD,uD,dD,hD,pD,fD,gD,mD,yD,SD,vD,xD,wD,bD,PD,CD,_D,ID,ED,TD,kD,MD,AD,jD,RD,OD,DD,LD,FD,ND,$D,zD,r0,Ce;class be extends(r0=UU,zD=[le],$D=[le],ND=[le],FD=[le],LD=[le],DD=[le],OD=[le],RD=[le],jD=[le],AD=[le],MD=[le],kD=[le],TD=[le],ED=[le],ID=[le],_D=[le],CD=[le],PD=[le],bD=[le],wD=[le],xD=[le],vD=[le],SD=[le],yD=[le],mD=[le],gD=[le],fD=[le],pD=[le],hD=[le],dD=[le],uD=[le],cD=[le],lD=[le],aD=[le],iD=[le],oD=[le],sD=[le],rD=[le],nD=[le],tD=[le],eD=[le],JO=[le],QO=[le],ZO=[le],XO=[le],YO=[le],qO=[le],VO=[le],GO=[le],WO=[le],KO=[le],HO=[le],UO=[le],BO=[le],zO=[le],$O=[le],NO=[le],FO=[le],LO=[le],DO=[le],OO=[le],RO=[le],jO=[le],AO=[le],MO=[le({isEqual:(e,t)=>e.equals(t)})],kO=[le],TO=[le],EO=[le],IO=[Dr],_O=[Dr],CO=[Dr],PO=[Dr],r0){constructor({store:e,user:t,shapeUtils:r,bindingUtils:s,tools:o,getContainer:i,cameraOptions:a,initialState:c,autoFocus:d,inferDarkMode:h,options:f,isShapeHidden:g}){var V;super(),IW(Ce,5,this),$e(this,"_isShapeHiddenPredicate"),$e(this,"options"),$e(this,"contextId",xt()),$e(this,"store"),$e(this,"root"),$e(this,"disposables",new Set),$e(this,"isDisposed",!1),$e(this,"_tickManager"),$e(this,"snaps"),$e(this,"timers",e0.forContext(this.contextId)),$e(this,"user"),$e(this,"textMeasure"),$e(this,"environment",Et),$e(this,"scribbles"),$e(this,"sideEffects"),$e(this,"edgeScrollManager"),$e(this,"focusManager"),$e(this,"getContainer"),$e(this,"shapeUtils"),$e(this,"styleProps"),$e(this,"bindingUtils"),$e(this,"history"),$e(this,"_shouldIgnoreShapeLock",!1),$e(this,"_crashingError",null),$e(this,"_isChangingStyleTimeout",-1),$e(this,"menus",Ks.forContext(this.contextId)),$e(this,"_cameraOptions",dn("camera options",z2)),$e(this,"_viewportAnimation",null),$e(this,"_willSetInitialBounds",!0),$e(this,"_isLockedOnFollowingUser",dn("isLockedOnFollowingUser",!1)),$e(this,"_cameraState",dn("camera state","idle")),$e(this,"_cameraStateTimeoutRemaining",0),$e(this,"_currentPageShapeIds"),$e(this,"_parentIdsToChildIds"),$e(this,"animatingShapes",new Map),$e(this,"externalAssetContentHandlers",{file:null,url:null}),$e(this,"temporaryAssetPreview",new Map),$e(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null}),$e(this,"inputs",{originPagePoint:new C,originScreenPoint:new C,previousPagePoint:new C,previousScreenPoint:new C,currentPagePoint:new C,currentScreenPoint:new C,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 C}),$e(this,"_clickManager",new $g(this)),$e(this,"_prevCursor","default"),$e(this,"_shiftKeyTimeout",-1),$e(this,"_altKeyTimeout",-1),$e(this,"_ctrlKeyTimeout",-1),$e(this,"_metaKeyTimeout",-1),$e(this,"_restoreToolId","select"),$e(this,"_pinchStart",1),$e(this,"_didPinch",!1),$e(this,"_selectedShapeIdsAtPointerDown",[]),$e(this,"_longPressTimeout",-1),$e(this,"capturedPointerId",null),$e(this,"performanceTracker"),$e(this,"performanceTrackerTimeout",-1),$e(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=g,this.options={...XH,...f},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new CK({store:e,annotateError:L=>{this.annotateError(L,{origin:"history.batch",willCrashApp:!0}),this.crash(L)}}),this.snaps=new Qd(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...z2,...a}),this.user=new $r(t??$j(),h??!1),this.disposables.add(()=>this.user.dispose()),this.getContainer=i,this.textMeasure=new sW(this),this._tickManager=new Ug(this);class y extends n0{}j(y,"initial",c??""),this.root=new y(this),this.root.children={};const S=Gj(r),v={},w={},b=new Map;for(const L of S){const U=new L(this);v[L.type]=U;const K=wA(L.props??{});w[L.type]=K;for(const F of K.keys())if(!b.has(F.id))b.set(F.id,F);else if(b.get(F.id)!==F)throw Error(`Multiple style props with id "${F.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=v,this.styleProps=w;const P=Kj(s),k={};for(const L of P){const U=new L(this);k[L.type]=U}this.bindingUtils=k;for(const L of[...o]){if(Cs(this.root.children,L.id))throw Error(`Can't override tool with id "${L.id}"`);this.root.children[L.id]=new L(this,this.root)}this.scribbles=new EK(this);const E=(L,U)=>{let K=null;const F=L.selectedShapeIds.filter(Y=>!U.has(Y));F.length!==L.selectedShapeIds.length&&(K||(K={...L}),K.selectedShapeIds=F);const $=L.erasingShapeIds.filter(Y=>!U.has(Y));$.length!==L.erasingShapeIds.length&&(K||(K={...L}),K.erasingShapeIds=$),L.hoveredShapeId&&U.has(L.hoveredShapeId)&&(K||(K={...L}),K.hoveredShapeId=null),L.editingShapeId&&U.has(L.editingShapeId)&&(K||(K={...L}),K.editingShapeId=null);const W=L.hintingShapeIds.filter(Y=>!U.has(Y));return W.length!==L.hintingShapeIds.length&&(K||(K={...L}),K.hintingShapeIds=W),L.focusedGroupId&&U.has(L.focusedGroupId)&&(K||(K={...L}),K.focusedGroupId=null),K};this.sideEffects=this.store.sideEffects;let M=new Map;const A=new Set,R=new Set;let D=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var L,U,K,F;A.clear();for(const $ of R){R.delete($);const W=this.getShape($);if(!W)continue;const Y=this.getShapeUtil(W),Z=(L=Y.onChildrenChange)==null?void 0:L.call(Y,W);Z!=null&&Z.length&&this.updateShapes(Z)}if(D.size){const $=D;D=new Set;for(const W of $){const Y=this.getBindingUtil(W);(U=Y.onOperationComplete)==null||U.call(Y)}}if(M.size){const $=M;M=new Map;for(const W of $.values())(F=(K=this.getBindingUtil(W.binding)).onAfterDelete)==null||F.call(K,W)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(L,U)=>{var K,F,$,W;for(const Y of this.getBindingsInvolvingShape(U))D.add(Y.type),Y.fromId===U.id&&((F=(K=this.getBindingUtil(Y)).onAfterChangeFromShape)==null||F.call(K,{binding:Y,shapeBefore:L,shapeAfter:U})),Y.toId===U.id&&((W=($=this.getBindingUtil(Y)).onAfterChangeToShape)==null||W.call($,{binding:Y,shapeBefore:L,shapeAfter:U}));if(L.parentId!==U.parentId){const Y=Z=>{var Q,ae,B,ne;const H=this.getShape(Z);if(H)for(const he of this.getBindingsInvolvingShape(H))D.add(he.type),he.fromId===H.id&&((ae=(Q=this.getBindingUtil(he)).onAfterChangeFromShape)==null||ae.call(Q,{binding:he,shapeBefore:H,shapeAfter:H})),he.toId===H.id&&((ne=(B=this.getBindingUtil(he)).onAfterChangeToShape)==null||ne.call(B,{binding:he,shapeBefore:H,shapeAfter:H}))};Y(U.id),this.visitDescendants(U.id,Y)}if(L.parentId!==U.parentId&&Er(U.parentId)){const Y=new Set([L.id]);this.visitDescendants(L.id,Z=>{Y.add(Z)});for(const Z of this.getPageStates()){if(Z.pageId===U.parentId)continue;const H=E(Z,Y);H&&this.store.put([H])}}L.parentId&&Mr(L.parentId)&&R.add(L.parentId),U.parentId!==L.parentId&&Mr(U.parentId)&&R.add(U.parentId)},beforeDelete:L=>{var $,W,Y,Z;if(A.has(L.id))return;L.parentId&&Mr(L.parentId)&&R.add(L.parentId),A.add(L.id);const U=[];for(const H of this.getBindingsInvolvingShape(L)){D.add(H.type),U.push(H.id);const Q=this.getBindingUtil(H);H.fromId===L.id?(($=Q.onBeforeIsolateToShape)==null||$.call(Q,{binding:H,removedShape:L}),(W=Q.onBeforeDeleteFromShape)==null||W.call(Q,{binding:H,shape:L})):((Y=Q.onBeforeIsolateFromShape)==null||Y.call(Q,{binding:H,removedShape:L}),(Z=Q.onBeforeDeleteToShape)==null||Z.call(Q,{binding:H,shape:L}))}U.length&&this.deleteBindings(U);const K=new Set([L.id]),F=Ye(this.getPageStates().map(H=>E(H,K)));F.length&&this.store.put(F)}},binding:{beforeCreate:L=>{var K,F;const U=(F=(K=this.getBindingUtil(L)).onBeforeCreate)==null?void 0:F.call(K,{binding:L});return U||L},afterCreate:L=>{var U,K;D.add(L.type),(K=(U=this.getBindingUtil(L)).onAfterCreate)==null||K.call(U,{binding:L})},beforeChange:(L,U)=>{var F,$;const K=($=(F=this.getBindingUtil(U)).onBeforeChange)==null?void 0:$.call(F,{bindingBefore:L,bindingAfter:U});return K||U},afterChange:(L,U)=>{var K,F;D.add(U.type),(F=(K=this.getBindingUtil(U)).onAfterChange)==null||F.call(K,{bindingBefore:L,bindingAfter:U})},beforeDelete:L=>{var U,K;(K=(U=this.getBindingUtil(L)).onBeforeDelete)==null||K.call(U,{binding:L})},afterDelete:L=>{var U,K;(K=(U=this.getBindingUtil(L)).onAfterDelete)==null||K.call(U,{binding:L}),D.add(L.type)}},page:{afterCreate:L=>{const U=_o.createId(L.id),K=Vs.createId(L.id);this.store.has(U)||this.store.put([_o.create({id:U})]),this.store.has(K)||this.store.put([Vs.create({id:K,pageId:L.id})])},afterDelete:(L,U)=>{var $,W;if((($=this.getInstanceState())==null?void 0:$.currentPageId)===L.id){const Y=(W=this.getPages().find(Z=>Z.id!==L.id))==null?void 0:W.id;Y?this.store.put([{...this.getInstanceState(),currentPageId:Y}]):U==="user"&&this.store.ensureStoreIsUsable()}const K=_o.createId(L.id),F=Vs.createId(L.id);this.store.remove([K,F])}},instance:{afterChange:(L,U,K)=>{var F;if(!this.store.has(U.currentPageId)){const $=this.store.has(L.currentPageId)?L.currentPageId:(F=this.getPages()[0])==null?void 0:F.id;$?this.store.update(U.id,W=>({...W,currentPageId:$})):K==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(L,U)=>{if((L==null?void 0:L.selectedShapeIds)!==(U==null?void 0:U.selectedShapeIds)){const K=U.selectedShapeIds.filter($=>{var Y,Z;let W=(Y=this.getShape($))==null?void 0:Y.parentId;for(;Mr(W);){if(U.selectedShapeIds.includes(W))return!1;W=(Z=this.getShape(W))==null?void 0:Z.parentId}return!0});let F=null;if(K.length>0){const $=this.findCommonAncestor(Ye(K.map(W=>this.getShape(W))),W=>this.isShapeOfType(W,"group"));$&&(F=$)}else U!=null&&U.focusedGroupId&&(F=U.focusedGroupId);(K.length!==U.selectedShapeIds.length||F!==U.focusedGroupId)&&this.store.put([{...U,selectedShapeIds:K,focusedGroupId:F??null}])}}}})),this._currentPageShapeIds=dK(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=uK(this.store),this.disposables.add(this.store.listen(L=>{this.emit("change",L)})),this.disposables.add(this.history.dispose),this.run(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})},{history:"ignore"}),c&&this.root.children[c]===void 0)throw Error(`No state found for initialState "${c}".`);if(this.root.enter(void 0,"initial"),this.edgeScrollManager=new xK(this),this.focusManager=new wK(this,d),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 Jk,(V=this.store.props.collaboration)!=null&&V.mode){const L=this.store.props.collaboration.mode;this.disposables.add(To("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:L.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 t=typeof e=="string"?e:e.type,r=Vn(this.shapeUtils,t);return mt(r,`No shape util found for type "${t}"`),r}hasShapeUtil(e){const t=typeof e=="string"?e:e.type;return Cs(this.shapeUtils,t)}getBindingUtil(e){const t=typeof e=="string"?e:e.type,r=Vn(this.bindingUtils,t);return mt(r,`No binding util found for type "${t}"`),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??xt()),this}markHistoryStoppingPoint(e){const t=`[${e??"stop"}]_${xt()}`;return this.history._mark(t),t}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,t){const r=this._shouldIgnoreShapeLock;this._shouldIgnoreShapeLock=(t==null?void 0:t.ignoreShapeLock)??r;try{this.history.batch(e,t)}finally{this._shouldIgnoreShapeLock=r}return this}batch(e,t){return this.run(e,t)}annotateError(e,{origin:t,willCrashApp:r,tags:s,extras:o}){const i=this.createErrorAnnotations(t,r);return X0(e,{tags:{...i.tags,...s},extras:{...i.extras,...o}}),r&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(e,t){try{const r=this.getEditingShapeId();return{tags:{origin:e,willCrashApp:t},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes().map(s=>{const{props:o,...i}=s,{text:a,richText:c,...d}=o;return{...i,props:d}}),selectionCount:this.getSelectedShapes().length,editingShape:r?this.getShape(r):void 0,inputs:this.inputs,pageState:this.getCurrentPageState(),instanceState:this.getInstanceState(),collaboratorCount:this.getCollaboratorsOnCurrentPage().length}}}catch{return{tags:{origin:e,willCrashApp:t},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 t=e.split(".").reverse();let r=this.root;for(;t.length>0;){const s=t.pop();if(!s)return!0;const o=r.getCurrent();if((o==null?void 0:o.id)===s){if(t.length===0)return!0;r=o;continue}else return!1}return!1}isInAny(...e){return e.some(t=>this.isIn(t))}setCurrentTool(e,t={}){return this.root.transition(e,t),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const e=this.getCurrentTool();return e?e.getCurrentToolIdMask()??e.id:""}getStateDescendant(e){var s;const t=e.split(".").reverse();let r=this.root;for(;t.length>0;){const o=t.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(Ww)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(sr)}updateInstanceState(e,t){return this._updateInstanceState(e,{history:"ignore",...t}),e.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),e.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},1e3))),this}_updateInstanceState(e,t){this.run(()=>{this.store.put([{...this.getInstanceState(),...e}])},t)}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 Vs.createId(this.getCurrentPageId())}updateCurrentPageState(e){return this._updateCurrentPageState(e),this}_updateCurrentPageState(e){this.store.update(e.id??this.getCurrentPageState().id,t=>({...t,...e}))}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:e}=this.getCurrentPageState();return Ye(e.map(t=>this.store.get(t)))}setSelectedShapes(e){return this.run(()=>{const t=e.map(o=>typeof o=="string"?o:o.id),{selectedShapeIds:r}=this.getCurrentPageState(),s=new Set(r);if(t.length===s.size&&t.every(o=>s.has(o)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:t}])},{history:"record-preserveRedoStack"})}isAncestorSelected(e){const t=typeof e=="string"?e:(e==null?void 0:e.id)??null,r=this.getShape(t);if(!r)return!1;const s=this.getSelectedShapeIds();return!!this.findShapeAncestor(r,o=>s.includes(o.id))}select(...e){const t=typeof e[0]=="string"?e:e.map(r=>r.id);return this.setSelectedShapes(t),this}deselect(...e){const t=typeof e[0]=="string"?e:e.map(s=>s.id),r=this.getSelectedShapeIds();return r.length>0&&t.length>0&&this.setSelectedShapes(r.filter(s=>!t.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 t=Ye(e.map(r=>this.getShapePageBounds(r)));return t.length===0?null:Se.Common(t)}getSelectionPageBounds(){return this.getShapesPageBounds(this.getSelectedShapeIds())}getShapesSharedRotation(e){let t=!1,r=0;for(let s=0,o=e.length;s<o;s++){const i=this.getShapePageTransform(e[s]);if(i)if(t){if(i.rotation()!==r)return 0}else t=!0,r=i.rotation()}return r}getSelectionRotation(){return this.getShapesSharedRotation(this.getSelectedShapeIds())}getShapesRotatedPageBounds(e){if(e.length===0)return;const t=this.getShapesSharedRotation(e);if(t===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=Se.FromPoints(e.flatMap(s=>{const o=this.getShapePageTransform(s);return o?o.applyToPoints(this.getShapeGeometry(s).bounds.corners):[]}).map(s=>s.rot(-t)));return r.point=r.point.rot(t),r}getSelectionRotatedPageBounds(){return this.getShapesRotatedPageBounds(this.getSelectedShapeIds())}getSelectionRotatedScreenBounds(){const e=this.getSelectionRotatedPageBounds();if(!e)return;const{x:t,y:r}=this.pageToScreen(e.point),s=this.getZoomLevel();return new Se(t,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 t=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(t!==null){const r=this.getShape(t);if(!r)throw Error(`Editor.setFocusedGroup: Shape with id ${t} does not exist`);if(!this.isShapeOfType(r,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${r.type}`)}return t===this.getFocusedGroupId()?this:this.run(()=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:t}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const e=this.getFocusedGroup();if(e){const t=this.findShapeAncestor(e,r=>this.isShapeOfType(r,"group"));this.setFocusedGroup((t==null?void 0:t.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 t=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(t!==this.getEditingShapeId()){if(t){const r=this.getShape(t);if(r&&this.getShapeUtil(r).canEdit(r))return this.run(()=>{this._updateCurrentPageState({editingShapeId:t})},{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 t=typeof e=="string"?e:(e==null?void 0:e.id)??null;return t===this.getHoveredShapeId()?this:(this.run(()=>{this.updateCurrentPageState({hoveredShapeId:t})},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const e=this.getHintingShapeIds();return Ye(e.map(t=>this.getShape(t)))}setHintingShapes(e){const t=typeof e[0]=="string"?e:e.map(r=>r.id);return this.run(()=>{this._updateCurrentPageState({hintingShapeIds:q0(t)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return Ye(e.map(t=>this.getShape(t)))}setErasingShapes(e){const t=typeof e[0]=="string"?e:e.map(s=>s.id);t.sort();const r=this.getErasingShapeIds();return this.run(()=>{if(t.length===r.length){for(let s=0;s<t.length;s++)if(t[s]!==r[s]){this._updateCurrentPageState({erasingShapeIds:t});break}}else this._updateCurrentPageState({erasingShapeIds:t})},{history:"ignore"}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(e){const t=typeof e=="string"?e:(e==null?void 0:e.id)??null;return t!==this.getCroppingShapeId()&&this.run(()=>{if(!t)this.updateCurrentPageState({croppingShapeId:null});else{const r=this.getShape(t),s=this.getShapeUtil(r);r&&s.canCrop(r)&&this.updateCurrentPageState({croppingShapeId:t})}},{history:"ignore"}),this}_unsafe_getCameraId(){return _o.createId(this.getCurrentPageId())}getCamera(){const e=this.store.get(this._unsafe_getCameraId());if(this._isLockedOnFollowingUser.get()){const t=this.getCameraForFollowing();if(t)return{...e,...t}}return e}getViewportPageBoundsForFollowing(){const e=this.getInstanceState().followingUserId;if(!e)return null;const t=this.getCollaborators().find(f=>f.userId===e);if(!t||!t.camera||!t.screenBounds)return null;const{w:r,h:s}=t.screenBounds,{x:o,y:i,z:a}=t.camera,c=new Se(-o,-i,r/a,s/a),d=this.getViewportScreenBounds().clone(),h=d.width/d.height;return d.width=c.width,d.height=d.width/h,d.height<c.height&&(d.height=c.height,d.width=d.height*h),d.center=c.center,d}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:t,zy:r}=_T(this,e);switch(e.constraints.initialZoom){case"fit-min":return Math.max(t,r);case"fit-max":return Math.min(t,r);case"fit-x":return t;case"fit-y":return r;case"fit-min-100":return Math.min(1,Math.max(t,r));case"fit-max-100":return Math.min(1,Math.min(t,r));case"fit-x-100":return Math.min(1,t);case"fit-y-100":return Math.min(1,r);default:throw un(e.constraints.initialZoom)}}getBaseZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.baseZoom==="default")return 1;const{zx:t,zy:r}=_T(this,e);switch(e.constraints.baseZoom){case"fit-min":return Math.max(t,r);case"fit-max":return Math.min(t,r);case"fit-x":return t;case"fit-y":return r;case"fit-min-100":return Math.min(1,Math.max(t,r));case"fit-max-100":return Math.min(1,Math.min(t,r));case"fit-x-100":return Math.min(1,t);case"fit-y-100":return Math.min(1,r);default:throw un(e.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(e){var r;const t=Nt({...this._cameraOptions.__unsafe__getWithoutCapture(),...e});return((r=t.zoomSteps)==null?void 0:r.length)<1&&(t.zoomSteps=[1]),this._cameraOptions.set(t),this.setCamera(this.getCamera()),this}getConstrainedCamera(e,t){const r=this.getCamera();let{x:s,y:o,z:i=r.z}=e;if(!(t!=null&&t.force)){const a=this.getCameraOptions(),c=a.zoomSteps[0],d=In(a.zoomSteps),h=this.getViewportScreenBounds();if(a.constraints){const{constraints:f}=a,g=Math.min(f.padding.y,h.w/2),y=Math.min(f.padding.x,h.h/2),S=Se.From(a.constraints.bounds),v=(h.w-y*2)/S.w,w=(h.h-g*2)/S.h,b=this.getBaseZoom(),P=d*b,k=c*b;if(t!=null&&t.reset&&(i=this.getInitialZoom()),i<k||i>P){const{x:K,y:F,z:$}=r,W=-K+h.w/$/2,Y=-F+h.h/$/2;i=Cn(i,k,P);const Z=-K+h.w/i/2,H=-F+h.h/i/2;s=K+Z-W,o=F+H-Y}const E=y/i-S.x,M=g/i-S.y,A=(h.w-y*2)/i-S.w,R=(h.h-g*2)/i-S.h,D=E+A*f.origin.x,V=M+R*f.origin.y,L=typeof f.behavior=="string"?f.behavior:f.behavior.x,U=typeof f.behavior=="string"?f.behavior:f.behavior.y;if(t!=null&&t.reset)s=D,o=V;else{switch(L){case"fixed":{s=D;break}case"contain":{i<v?s=D:s=Cn(s,E+A,E);break}case"inside":{i<v?s=Cn(s,E,(h.w-y)/i-S.w):s=Cn(s,E+A,E);break}case"outside":{s=Cn(s,y/i-S.w,(h.w-y)/i);break}case"free":break;default:throw un(L)}switch(U){case"fixed":{o=V;break}case"contain":{i<w?o=V:o=Cn(o,M+R,M);break}case"inside":{i<w?o=Cn(o,M,(h.h-g)/i-S.h):o=Cn(o,M+R,M);break}case"outside":{o=Cn(o,g/i-S.h,(h.h-g)/i);break}case"free":break;default:throw un(U)}}}else if(i>d||i<c){const{x:f,y:g,z:y}=r;i=Cn(i,c,d),s=f+(-f+h.w/i/2)-(-f+h.w/y/2),o=g+(-g+h.h/i/2)-(-g+h.h/y/2)}}return{x:s,y:o,z:i}}_setCamera(e,t){const r=this.getCamera(),{x:s,y:o,z:i}=this.getConstrainedCamera(e,t);return r.x===s&&r.y===o&&r.z===i?this:(ko(()=>{const a={...r,x:s,y:o,z:i};this.run(()=>{this.store.put([a])},{history:"ignore"});const{currentScreenPoint:c,currentPagePoint:d}=this.inputs,{screenBounds:h}=this.store.unsafeGetWithoutCapture(sr);if(c.x/i-s!==d.x||c.y/i-o!==d.y){const f={type:"pointer",target:"canvas",name:"pointer_move",point:C.AddXY(c,h.x,h.y),pointerId:B2.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,metaKey:this.inputs.metaKey,accelKey:Gn(this.inputs),button:0,isPen:this.getInstanceState().isPenMode??!1};t!=null&&t.immediate?this._flushEventForTick(f):this.dispatch(f)}this._tickCameraState()}),this)}setCamera(e,t){const{isLocked:r}=this._cameraOptions.__unsafe__getWithoutCapture();if(r&&!(t!=null&&t.force))return this;this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser();const s=C.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,t);if(t!=null&&t.animation){const{width:i,height:a}=this.getViewportScreenBounds();this._animateToViewport(new Se(-o.x,-o.y,i/o.z,a/o.z),t)}else this._setCamera(o,{...t,force:!0});return this}centerOnPoint(e,t){const{isLocked:r}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const{width:s,height:o}=this.getViewportPageBounds();return this.setCamera(new C(-(e.x-s/2),-(e.y-o/2),this.getCamera().z),t),this}zoomToFit(e){const t=[...this.getCurrentPageShapeIds()];if(t.length<=0)return this;const r=Se.Common(Ye(t.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(r,e),this}resetZoom(e=this.getViewportScreenCenter(),t){const{isLocked:r,constraints:s}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const o=this.getCamera(),{x:i,y:a,z:c}=o,{x:d,y:h}=e;let f=1;if(s){const g=this.getInitialZoom();c!==g&&(f=g)}return this.setCamera(new C(i+(d/f-d)-(d/c-d),a+(h/f-h)-(h/c-h),f),t),this}zoomIn(e=this.getViewportScreenCenter(),t){const{isLocked:r}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const{x:s,y:o,z:i}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const c=this.getBaseZoom();let d=In(a)*c;for(let h=1;h<a.length;h++){const f=a[h-1]*c,g=a[h]*c;if(!(g-i<=(g-f)/2)){d=g;break}}this.setCamera(new C(s+(e.x/d-e.x)-(e.x/i-e.x),o+(e.y/d-e.y)-(e.y/i-e.y),d),t)}return this}zoomOut(e=this.getViewportScreenCenter(),t){const{isLocked:r}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const{zoomSteps:s}=this.getCameraOptions();if(s!==null&&s.length>1){const o=this.getBaseZoom(),{x:i,y:a,z:c}=this.getCamera();let d=s[0]*o;for(let h=s.length-1;h>0;h--){const f=s[h-1]*o,g=s[h]*o;if(!(g-c>=(g-f)/2)){d=f;break}}this.setCamera(new C(i+(e.x/d-e.x)-(e.x/c-e.x),a+(e.y/d-e.y)-(e.y/c-e.y),d),t)}return this}zoomToSelection(e){const{isLocked:t}=this.getCameraOptions();if(t&&!(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,t){const r=this._cameraOptions.__unsafe__getWithoutCapture();if(r.isLocked&&!(t!=null&&t.force))return this;const s=this.getViewportScreenBounds(),o=(t==null?void 0:t.inset)??Math.min(bB,s.width*.28),i=this.getBaseZoom(),a=r.zoomSteps[0],c=In(r.zoomSteps);let d=Cn(Math.min((s.width-o)/e.w,(s.height-o)/e.h),a*i,c*i);return(t==null?void 0:t.targetZoom)!==void 0&&(d=Math.min(t.targetZoom,d)),this.setCamera(new C(-e.x+(s.width-e.w*d)/2/d,-e.y+(s.height-e.h*d)/2/d,d),t),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(e){if(!this._viewportAnimation)return;this._viewportAnimation.elapsed+=e;const{elapsed:t,easing:r,duration:s,start:o,end:i}=this._viewportAnimation;if(t>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new C(-i.x,-i.y,this.getViewportScreenBounds().width/i.width));return}const a=s-t,c=r(1-a/s),d=o.minX+(i.minX-o.minX)*c,h=o.minY+(i.minY-o.minY)*c,f=o.maxX+(i.maxX-o.maxX)*c;this._setCamera(new C(-d,-h,this.getViewportScreenBounds().width/(f-d)),{force:!0})}_animateToViewport(e,t={animation:Px}){const{animation:r,...s}=t;if(!r)return;const{duration:o=0,easing:i=vn.easeInOutCubic}=r,a=this.user.getAnimationSpeed(),c=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),o===0||a===0?this._setCamera(new C(-e.x,-e.y,this.getViewportScreenBounds().width/e.width),{...s}):(this._viewportAnimation={elapsed:0,duration:o/a,easing:i,start:c.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:t}=this.getCameraOptions();if(t&&!(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 c=Math.min(s,1);const d=()=>{this.off("tick",h),this.off("stop-camera-animation",d)};this.once("stop-camera-animation",d);const h=f=>{const{x:g,y,z:S}=this.getCamera(),v=C.Mul(i,c*f/S);c*=1-o,c<a?d():this._setCamera(new C(g+v.x,y+v.y,S))};return this.on("tick",h),this}zoomToUser(e,t={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),t&&t.animation&&!o&&(t.animation=void 0),this.centerOnPoint(s,t);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,e]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],c=a.indexOf(e);c<0||(a.splice(c,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(e,t=!1){if(e instanceof HTMLElement){const a=e.getBoundingClientRect();e=new Se(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,!la(document.body.scrollWidth,e.maxX,1),!la(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,c)=>a===i[c]))return this;if(s)this.updateInstanceState({screenBounds:e.toJson(),insets:r}),this.setCamera(this.getCamera());else if(t&&!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(C.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:e,y:t,w:r,h:s}=this.getInstanceState().screenBounds;return new Se(e,t,r,s)}getViewportScreenCenter(){const e=this.getViewportScreenBounds();return new C(e.midX-e.minX,e.midY-e.minY)}getViewportPageBounds(){const{w:e,h:t}=this.getViewportScreenBounds(),{x:r,y:s,z:o}=this.getCamera();return new Se(-r,-s,e/o,t/o)}screenToPage(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(sr),{x:r,y:s,z:o=1}=this.getCamera();return new C((e.x-t.x)/o-r,(e.y-t.y)/o-s,e.z??.5)}pageToScreen(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(sr),{x:r,y:s,z:o=1}=this.getCamera();return new C((e.x+r)*o+t.x,(e.y+s)*o+t.y,e.z??.5)}pageToViewport(e){const{x:t,y:r,z:s=1}=this.getCamera();return new C((e.x+t)*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=>v6(e.filter(o=>o.userId===r),o=>o.lastActivityTimestamp??0)):fi}getCollaboratorsOnCurrentPage(){const e=this.getCurrentPageId();return this.getCollaborators().filter(t=>t.currentPageId===e)}startFollowingUser(e){this.stopFollowingUser();const t=this._getCollaboratorsQuery().get().filter(o=>o.userId===e);if(!t.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"),t.some(o=>o.followingUserId===r))return this;const s=le("latestLeaderPresence",()=>this.getCollaborators().find(o=>o.userId===e));return ko(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const o=To("update current page",()=>{const c=s.get();if(!c){this.stopFollowingUser();return}c.currentPageId!==this.getCurrentPageId()&&this.getPage(c.currentPageId)&&this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:c.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 d=this.user.getAnimationSpeed();if(d===0){this._isLockedOnFollowingUser.set(!0);return}const h=this.getViewportPageBoundsForFollowing();if(!h){this.stopFollowingUser();return}const f=this.getViewportPageBounds(),g=Math.abs(h.minX-f.minX)+Math.abs(h.maxX-f.maxX),y=Math.abs(h.minY-f.minY)+Math.abs(h.maxY-f.maxY);if(g<this.options.followChaseViewportSnap&&y<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const S=Cn(d*.5,.1,.8),v=new Se(ot(f.minX,h.minX,S),ot(f.minY,h.minY,S),ot(f.width,h.width,S),ot(f.height,h.height,S)),w=new C(-v.x,-v.y,this.getViewportScreenBounds().width/v.width);this.stopCameraAnimation(),this._setCamera(w)};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 t=[];let r=this.options.maxShapesPerPage*2,s=this.options.maxShapesPerPage;const o=this.getErasingShapeIds(),i=(c,d,h)=>{const f=this.getShape(c);if(!f||this.isShapeHidden(f))return;d*=f.opacity;let g=!1;const y=this.getShapeUtil(f);e&&(g=!h&&o.includes(c),g&&(d*=.32)),t.push({id:c,shape:f,util:y,index:r,backgroundIndex:s,opacity:d}),r+=1,s+=1;const S=this.getSortedChildIdsForParent(c);if(!S.length)return;let v=null;y.providesBackgroundForChildren(f)&&(v=s,s=r,r+=this.options.maxShapesPerPage);for(const w of S)i(w,d,h||g);v!==null&&(s=v)},a=e?[this.getCurrentPage()]:this.getPages();for(const c of a)for(const d of this.getSortedChildIdsForParent(c.id))i(d,1,!1);return t}_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(X6)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return Array.from(this._getAllPagesQuery().get()).sort(Wn)}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 t=typeof e=="string"?e:e.id,r=this.store.query.exec("shape",{parentId:{eq:t}});return this.getShapeAndDescendantIds(r.map(s=>s.id))}setCurrentPage(e){const t=typeof e=="string"?e:e.id;return this.store.has(t)?(this.stopFollowingUser(),this.complete(),this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:t}]),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 t=this.getPages(),r=nK(e.name??"Page 1",t.map(i=>i.name));let s=e.index;(!s||t.some(i=>i.index===s))&&(s=Co(t[t.length-1].index));const o=ss.create({meta:{},...e,name:r,index:s});this.store.put([o])}),this}deletePage(e){const t=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(t);if(s){if(t===this.getCurrentPageId()){const o=r.findIndex(a=>a.id===t),i=r[o-1]??r[o+1];this.setCurrentPage(i.id)}this.store.remove([s.id])}}),this}duplicatePage(e,t=ss.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 d;const a=this.getPages(),c=wd(s.index,(d=a[a.indexOf(s)+1])==null?void 0:d.index);if(this.createPage({name:s.name+" Copy",id:t,index:c}),this.setCurrentPage(t),this.setCamera(o),i)return this.putContentOntoCurrentPage(i)}),this}renamePage(e,t){const r=typeof e=="string"?e:e.id;return this.getIsReadonly()?this:(this.updatePage({id:r,name:t}),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(t=>({...this.store.get(t.id),...t})))},{history:"ignore"}),this)}deleteAssets(e){if(this.getIsReadonly())return this;const t=typeof e[0]=="string"?e:e.map(r=>r.id);return t.length<=0?this:(this.run(()=>this.store.remove(t),{history:"ignore"}),this)}getAsset(e){return this.store.get(typeof e=="string"?e:e.id)}async resolveAssetUrl(e,t){if(!e)return null;const r=this.getAsset(e);if(!r)return null;const{screenScale:s=1,shouldResolveToOriginal:o=!1,dpr:i=this.getInstanceState().devicePixelRatio}=t,c=(h=>Math.pow(2,Math.ceil(Math.log2(h))))(s),d="connection"in navigator?navigator.connection.effectiveType:null;return await this.store.props.assets.resolve(r,{screenScale:s||1,steppedScreenScale:c,dpr:i,networkEffectiveType:d,shouldResolveToOriginal:o})}async uploadAsset(e,t,r){return await this.store.props.assets.upload(e,t,r)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",e=>this.getShapeUtil(e).getGeometry(e),(e,t)=>e.props===t.props)}getShapeGeometry(e){return this._getShapeGeometryCache().get(typeof e=="string"?e:e.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",e=>{var t,r;return(r=(t=this.getShapeUtil(e)).getHandles)==null?void 0:r.call(t,e)})}getShapeHandles(e){return this._getShapeHandlesCache().get(typeof e=="string"?e:e.id)}getShapeLocalTransform(e){const t=typeof e=="string"?e:e.id,r=this.getShape(t);if(!r)throw Error("Editor.getTransform: shape not found");return me.Identity().translate(r.x,r.y).rotate(r.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if(Er(e.parentId))return this.getShapeLocalTransform(e);const t=this._getShapePageTransformCache().get(e.parentId)??me.Identity();return me.Compose(t,this.getShapeLocalTransform(e))})}getShapeParentTransform(e){const t=typeof e=="string"?e:e.id,r=this.getShape(t);return!r||Er(r.parentId)?me.Identity():this._getShapePageTransformCache().get(r.parentId)??me.Identity()}getShapePageTransform(e){const t=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(t)??me.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",e=>{const t=this._getShapePageTransformCache().get(e.id);return t?Se.FromPoints(me.applyToPoints(t,this.getShapeGeometry(e).vertices)):new Se})}getShapePageBounds(e){return this._getShapePageBoundsCache().get(typeof e=="string"?e:e.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",e=>{const t=this._getShapeMaskCache().get(e.id);if(!t)return;if(t.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const r=this._getShapePageTransformCache().get(e.id);return r?`polygon(${me.applyToPoints(me.Inverse(r),t).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(Er(e.parentId))return;const t=this.getShapeAncestors(e.id).filter(s=>this.isShapeOfType(s,"frame"));return t.length===0?void 0:t.map(s=>this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)).reduce((s,o)=>{if(!(o&&s))return;const i=lT(s,o);return i?i.map(C.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 t=this._getShapePageBoundsCache().get(e.id);if(!t)return;const r=this._getShapeMaskCache().get(e.id);if(r){if(r.length===0)return;const{corners:s}=t;if(s.every((i,a)=>i&&C.Equals(i,r[a])))return t.clone();const o=lT(r,s);return o?Se.FromPoints(o):void 0}return t})}getShapeAncestors(e,t=[]){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return t;const o=s.parentId;if(Er(o))return t.reverse(),t;const i=this.store.get(o);return i?(t.push(i),this.getShapeAncestors(i,t)):t}findShapeAncestor(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return;const o=s.parentId;if(Er(o))return;const i=this.getShape(o);if(i)return t(i)?i:this.findShapeAncestor(i,t)}hasAncestor(e,t){const r=typeof e=="string"?e:e==null?void 0:e.id,s=r&&this.getShape(r);return s?s.parentId===t?!0:this.hasAncestor(this.getShapeParent(s),t):!1}findCommonAncestor(e,t){var c;if(e.length===0)return;const r=typeof e[0]=="string"?e:e.map(d=>d.id),s=Ye(r.map(d=>this.getShape(d)));if(s.length===1){const d=s[0].parentId;return Er(d)?void 0:t?(c=this.findShapeAncestor(s[0],t))==null?void 0:c.id:d}const[o,...i]=s;let a=this.getShapeParent(o);for(;a;){if(t&&!t(a)){a=this.getShapeParent(a);continue}if(i.every(d=>this.hasAncestor(d,a.id)))return a.id;a=this.getShapeParent(a)}}isShapeOrAncestorLocked(e){const t=typeof e=="string"?this.getShape(e):e;return t===void 0?!1:t.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(t))}_notVisibleShapes(){return cK(this)}getCulledShapes(){const e=this._notVisibleShapes().get(),t=this.getSelectedShapeIds(),r=this.getEditingShapeId(),s=new Set(e);return r&&s.delete(r),t.forEach(o=>{s.delete(o)}),s}getCurrentPageBounds(){let e;return this.getCurrentPageShapeIdsSorted().forEach(t=>{const r=this.getShapeMaskedPageBounds(t);r&&(e?e=e.expand(r):e=r.clone())}),e}getSelectedShapeAtPoint(e){const t=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(r=>r.type!=="group"&&t.includes(r.id)).reverse().find(r=>this.isPointInShape(r,e,{hitInside:!0,margin:0}))}getShapeAtPoint(e,t={}){const r=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:o,margin:i=0,hitLocked:a=!1,hitLabels:c=!1,hitInside:d=!1,hitFrameInside:h=!1}=t;let f=1/0,g=null,y=1/0,S=null;const v=(t.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(w=>{if(w.isLocked&&!a||this.isShapeHidden(w)||this.isShapeOfType(w,"group"))return!1;const b=this.getShapeMask(w);return b&&!Jr(e,b)?!1:o?o(w):!0});for(let w=v.length-1;w>=0;w--){const b=v[w],P=this.getShapeGeometry(b),k=P instanceof Is,E=this.getPointInShapeSpace(b,e);if(this.isShapeOfType(b,"frame")||(this.isShapeOfType(b,"arrow")||this.isShapeOfType(b,"geo")&&b.props.fill==="none")&&b.props.text.trim()){for(const A of P.children)if(A.isLabel&&A.isPointInBounds(E))return b}if(this.isShapeOfType(b,"frame")){const A=P.distanceToPoint(E,d);if(Math.abs(A)<=i)return S||b;if(P.hitTestPoint(E,0,!0))return S||g||(h?b:void 0);continue}let M;if(k){let A=1/0;for(const R of P.children){if(R.isLabel&&!c)continue;const D=R.distanceToPoint(E,d);D<A&&(A=D)}M=A}else i===0&&(P.bounds.w<1||P.bounds.h<1)||P.bounds.containsPoint(E,i)?M=P.distanceToPoint(E,d):M=1/0;if(P.isClosed){if(M<=i){if(P.isFilled||k&&P.children[0].isFilled)return S||b;if(this.getShapePageBounds(b).contains(s))continue;if(Math.abs(M)<i)Math.abs(M)<y&&(y=Math.abs(M),S=b);else if(!S){const{area:A}=P;A<f&&(f=A,g=b)}}}else if(M<this.options.hitTestMargin/r)return b}return S||g||void 0}getShapesAtPoint(e,t={}){return this.getCurrentPageShapes().filter(r=>!this.isShapeHidden(r)&&this.isPointInShape(r,e,t))}isPointInShape(e,t,r={}){const{hitInside:s=!1,margin:o=0}=r,i=typeof e=="string"?e:e.id,a=this.getShapeMask(i);return a&&!Jr(t,a)?!1:this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(e,t),o,s)}getPointInShapeSpace(e,t){const r=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(r).clone().invert().applyToPoint(t)}getPointInParentSpace(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return new C(0,0);if(Er(s.parentId))return C.From(t);const o=this.getShapePageTransform(s.parentId);return o?o.clone().invert().applyToPoint(t):C.From(t)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),e=>this.store.get(e))}getCurrentPageShapesSorted(){const e=[],t=this.getSortedChildIdsForParent(this.getCurrentPageId());for(let r=0,s=t.length;r<s;r++)BD(this,t[r],e);return e}getCurrentPageRenderingShapesSorted(){const e=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:t})=>!e.has(t)&&!this.isShapeHidden(t))}isShapeOfType(e,t){const r=typeof e=="string"?this.getShape(e):e;return r?r.type===t:!1}getShape(e){const t=typeof e=="string"?e:e.id;if(Mr(t))return this.store.get(t)}getShapeParent(e){const t=typeof e=="string"?e:e==null?void 0:e.id;if(!t)return;const r=this.getShape(t);if(!(r===void 0||!Mr(r.parentId)))return this.store.get(r.parentId)}getShapeNearestSibling(e,t){return t?t.parentId===e.parentId?t:this.findShapeAncestor(t,s=>s.parentId===e.parentId):void 0}isShapeInPage(e,t=this.getCurrentPageId()){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return!1;let o=!1;if(s.parentId===t)o=!0;else{let i=this.getShape(s.parentId);e:for(;i;){if(i.parentId===t){o=!0;break e}i=this.getShape(i.parentId)}}return o}getAncestorPageId(e){const t=typeof e=="string"?e:e==null?void 0:e.id,r=t&&this.getShape(t);if(r)return Er(r.parentId)?r.parentId:this.getAncestorPageId(this.getShape(r.parentId))}reparentShapes(e,t,r){const s=typeof e[0]=="string"?e:e.map(g=>g.id);if(s.length===0)return this;const o=[],i=Er(t)?me.Identity():this.getShapePageTransform(t),a=i.rotation();let c=[];const d=Ye(this.getSortedChildIdsForParent(t).map(g=>this.getShape(g)));if(r){const g=d.find(y=>y.index===r);if(g){const y=d[d.indexOf(g)+1];y?c=jc(r,y.index,s.length):c=vS(r,s.length)}else{const y=d.sort(Wn).find(S=>S.index>r);y?c=jc(r,y.index,s.length):c=vS(r,s.length)}}else{const g=d.length&&d[d.length-1];c=g?vS(g.index,s.length):bd(s.length)}const h=i.clone().invert(),f=Ye(s.map(g=>this.getShape(g)));return this.run(()=>{for(let g=0;g<f.length;g++){const y=f[g],S=this.getShapePageTransform(y);if(!S)continue;const v=S.point();if(!v)continue;const w=h.applyToPoint(v),b=S.rotation()-a;o.push({id:y.id,type:y.type,parentId:t,x:w.x,y:w.y,rotation:b,index:c[g]})}this.updateShapes(o)},{ignoreShapeLock:!0}),this}getHighestIndexForParent(e){const t=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[t];if(!r||r.length===0)return"a1";const s=this.getShape(r[r.length-1]);return Co(s.index)}getSortedChildIdsForParent(e){const t=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[t];return r||fi}visitDescendants(e,t){const r=typeof e=="string"?e:e.id,s=this.getSortedChildIdsForParent(r);for(const o of s)t(o)!==!1&&this.visitDescendants(o,t);return this}getShapeAndDescendantIds(e){const t=new Set;for(const r of e.map(s=>this.getShape(s)).sort(Wn))t.add(r.id),this.visitDescendants(r,s=>{t.add(s)});return t}getDroppingOverShape(e,t=[]){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,t)||t.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,t){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)&&((t==null?void 0:t(i))??!0))o=i;else if((a==null?void 0:a.id)===i.id)break;i=this.getShapeParent(i)}return o}_getBindingsIndexCache(){const e=aK(this);return this.store.createComputedCache("bindingsIndex",t=>e.get().get(t.id))}getBinding(e){return this.store.get(e)}getBindingsFromShape(e,t){const r=typeof e=="string"?e:e.id;return this.getBindingsInvolvingShape(r).filter(s=>s.fromId===r&&s.type===t)}getBindingsToShape(e,t){const r=typeof e=="string"?e:e.id;return this.getBindingsInvolvingShape(r).filter(s=>s.toId===r&&s.type===t)}getBindingsInvolvingShape(e,t){const r=typeof e=="string"?e:e.id,s=this._getBindingsIndexCache().get(r)??fi;return t?s.filter(o=>o.type===t):s}createBindings(e){const t=[];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(),c=this.store.schema.types.binding.create({...r,id:r.id??nl(),props:{...a,...r.props}});t.push(c)}return this.store.put(t),this}createBinding(e){return this.createBindings([e])}updateBindings(e){const t=[];for(const r of e){if(!r)continue;const s=this.getBinding(r.id);if(!s)continue;const o=yo(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})&&t.push(o)}return this.store.put(t),this}updateBinding(e){return this.updateBindings([e])}deleteBindings(e,{isolateShapes:t=!1}={}){const r=e.map(s=>typeof s=="string"?s:s.id);return t?this.store.atomic(()=>{var s,o;for(const i of r){const a=this.getBinding(i);if(!a)continue;const c=this.getBindingUtil(a);(s=c.onBeforeIsolateFromShape)==null||s.call(c,{binding:a,removedShape:this.getShape(a.toId)}),(o=c.onBeforeIsolateToShape)==null||o.call(c,{binding:a,removedShape:this.getShape(a.fromId)}),this.store.remove([i])}}):this.store.remove(r),this}deleteBinding(e,t){return this.deleteBindings([e],t)}canBindShapes({fromShape:e,toShape:t,binding:r}){const s=typeof e=="string"?e:e.type,o=typeof t=="string"?t:t.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,t,r){const s=typeof e[0]=="string"?e:e.map(i=>i.id);if(s.length<=0)return this;const o=fR({editor:this,ids:s});return o?(of({delta:t,snapshot:o,editor:this,stage:"one-off",centerOverride:r==null?void 0:r.center}),this):this}getChangesToTranslateShape(e,t){var o,i,a;let r=e;const s=this.getShapeUtil(e);return r=yo(r,((o=s.onTranslateStart)==null?void 0:o.call(s,r))??void 0),r=yo(r,{id:e.id,type:e.type,x:t.x,y:t.y}),r=yo(r,((i=s.onTranslate)==null?void 0:i.call(s,e,r))??void 0),r=yo(r,((a=s.onTranslateEnd)==null?void 0:a.call(s,e,r))??void 0),r}nudgeShapes(e,t){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=C.From(t),c=this.getShapeParentTransform(i);c&&a.rot(-c.rotation()),s.push(this.getChangesToTranslateShape(i,a.add(i)))}return this.updateShapes(s),this}duplicateShapes(e,t){return this.run(()=>{const r=typeof e[0]=="string"?e:e.map(g=>g.id);if(r.length<=0)return this;const s=new Set(r),o=this.getShapeAndDescendantIds(r),i=[...o].reverse(),a=new Map;for(const g of o)a.set(g,Ct());const{shapesToCreateWithOriginals:c,bindingsToCreate:d}=CT(this,o,g=>{const y=[];for(const v of g){const w=this.getBinding(v);if(!w)continue;const b=nl();y.push({...w,id:b,fromId:Ar(a.get(w.fromId)),toId:Ar(a.get(w.toId))})}const S=[];for(const v of i){const w=Ar(a.get(v)),b=this.getShape(v);if(!b)continue;let P=0,k=0;if(t&&s.has(v)){const E=this.getShapeParentTransform(b),M=new C(t.x,t.y).rot(-E.rotation());P=M.x,k=M.y}S.push({shape:{...b,id:w,x:b.x+P,y:b.y+k,index:"a1",parentId:a.get(b.parentId)??b.parentId},originalShape:b})}return{shapesToCreateWithOriginals:S,bindingsToCreate:y}});c.forEach(({shape:g,originalShape:y})=>{const S=y.parentId,v=this.getSortedChildIdsForParent(S),w=v.indexOf(y.id),b=v[w+1],P=b?this.getShape(b):void 0,k=wd(y.index,P==null?void 0:P.index);g.index=k});const h=c.map(({shape:g})=>g);if(h.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Mp(this);return}if(this.createShapes(h),this.createBindings(d),this.setSelectedShapes(Ye(r.map(g=>a.get(g)))),t!==void 0){const g=this.getSelectionPageBounds(),y=this.getViewportPageBounds();g&&!y.contains(g)&&this.centerOnPoint(g.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(e,t){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(t===s)return this;if(!this.store.has(t))return this;const o=this.getContentFromCurrentPage(r);if(!o)return this;if(this.getPageShapeIds(t).size+o.shapes.length>this.options.maxShapesPerPage)return Mp(this,t),this;const i=this.getCamera().z;return this.run(()=>{this.deleteShapes(r),this.setCurrentPage(t),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 t=typeof e[0]=="string"?e:e.map(i=>i.id);if(this.getIsReadonly()||t.length===0)return this;let r=!0,s=!0;const o=[];for(const i of t){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 t=typeof e[0]=="string"?e:e.map(s=>s.id),r=Tp(this,"toBack",t,{considerAllShapes:!0});return r&&this.updateShapes(r),this}sendBackward(e,t={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id),s=Tp(this,"backward",r,t);return s&&this.updateShapes(s),this}bringForward(e,t={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id),s=Tp(this,"forward",r,t);return s&&this.updateShapes(s),this}bringToFront(e){const t=typeof e[0]=="string"?e:e.map(s=>s.id),r=Tp(this,"toFront",t);return r&&this.updateShapes(r),this}flipShapes(e,t){const r=typeof e[0]=="string"?e:e.map(i=>i.id);if(this.getIsReadonly())return this;let s=Ye(r.map(i=>this.getShape(i)));if(!s.length)return this;s=Ye(s.map(i=>this.isShapeOfType(i,"group")?this.getSortedChildIdsForParent(i.id).map(a=>this.getShape(a)):i).flat());const o=Se.Common(Ye(s.map(i=>this.getShapePageBounds(i)))).center;return this.run(()=>{for(const i of s){const a=this.getShapeGeometry(i).bounds,c=this.getShapePageTransform(i.id);c&&this.resizeShape(i.id,{x:t==="horizontal"?-1:1,y:t==="vertical"?-1:1},{initialBounds:a,initialPageTransform:c,initialShape:i,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(i).isAspectRatioLocked(i),scaleOrigin:o,scaleAxisRotation:0})}}),this}stackShapes(e,t,r){const s=typeof e[0]=="string"?e:e.map(v=>v.id);if(this.getIsReadonly())return this;const o=s.map(v=>this.getShape(v)).filter(v=>v?this.getShapeUtil(v).canBeLaidOut(v):!1),i=o.length;if(r===0&&i<3||i<2)return this;const a=Object.fromEntries(o.map(v=>[v.id,this.getShapePageBounds(v)]));let c,d,h,f;t==="horizontal"?(c="x",d="minX",h="maxX",f="width"):(c="y",d="minY",h="maxY",f="height");let g;if(r===0){const v=[];o.sort((b,P)=>a[b.id][d]-a[P.id][d]);for(let b=0;b<i-1;b++){const P=o[b],k=o[b+1],E=a[P.id],A=a[k.id][d]-E[h],R=v.find(D=>D.gap===A);R?R.count++:v.push({gap:A,count:1})}let w=0;v.forEach(b=>{b.count>w&&(w=b.count,g=b.gap)}),w===1&&(g=Math.max(0,v.reduce((b,P)=>b+P.gap*P.count,0)/(i-1)))}else g=r;const y=[];let S=a[o[0].id][h];return o.forEach((v,w)=>{var M,A;if(w===0)return;const b={x:0,y:0};b[c]=S+g-a[v.id][c];const P=this.getShapeParent(v),k=P?C.Rot(b,-this.getShapePageTransform(P).decompose().rotation):b,E=(A=(M=this.getShapeUtil(v)).onTranslateStart)==null?void 0:A.call(M,v);y.push(E?{...E,[c]:v[c]+k[c]}:{id:v.id,type:v.type,[c]:v[c]+k[c]}),S+=a[v.id][f]+g}),this.updateShapes(y),this}packShapes(e,t){var A,R;const r=typeof e[0]=="string"?e:e.map(D=>D.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const s=r.map(D=>this.getShape(D)).filter(D=>D?this.getShapeUtil(D).canBeLaidOut(D):!1),o={},i={};let a,c,d=0;for(let D=0;D<s.length;D++)a=s[D],c=this.getShapePageBounds(a),o[a.id]=c,i[a.id]=c.clone(),d+=c.width*c.height;const h=Se.Common(Ye(Object.values(o))),f=h.width;s.sort((D,V)=>o[V.id].height-o[D.id].height);const g=Math.max(Math.ceil(Math.sqrt(d/.95)),f),y=[new Se(h.x,h.y,g,1/0)];let S=0,v=0,w,b;for(let D=0;D<s.length;D++){a=s[D],c=i[a.id];for(let V=y.length-1;V>=0;V--)if(w=y[V],!(c.width>w.width||c.height>w.height)){c.x=w.x,c.y=w.y,v=Math.max(v,c.maxY),S=Math.max(S,c.maxX),c.width===w.width&&c.height===w.height?(b=y.pop(),V<y.length&&(y[V]=b)):c.height===w.height?(w.x+=c.width+t,w.width-=c.width+t):c.width===w.width?(w.y+=c.height+t,w.height-=c.height+t):(y.push(new Se(w.x+(c.width+t),w.y,w.width-(c.width+t),c.height)),w.y+=c.height+t,w.height-=c.height+t);break}}const P=Se.Common(Object.values(i)),k=C.Sub(h.center,P.center);let E;const M=[];for(let D=0;D<s.length;D++){a=s[D],c=o[a.id],E=i[a.id];const V=C.Sub(E.point,c.point).add(k),L=this.getShapeParentTransform(a);L&&V.rot(-L.rotation());const U={id:a.id,type:a.type,x:a.x+V.x,y:a.y+V.y},K=(R=(A=this.getShapeUtil(a)).onTranslateStart)==null?void 0:R.call(A,{...a,...U});K?M.push({...U,...K}):M.push(U)}return M.length&&this.updateShapes(M),this}alignShapes(e,t){const r=typeof e[0]=="string"?e:e.map(c=>c.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const s=Ye(r.map(c=>this.getShape(c))),o=Object.fromEntries(s.map(c=>[c.id,this.getShapePageBounds(c)])),i=Se.Common(Ye(Object.values(o))),a=[];return s.forEach(c=>{const d=o[c.id];if(!d)return;const h={x:0,y:0};switch(t){case"top":{h.y=i.minY-d.minY;break}case"center-vertical":{h.y=i.midY-d.minY-d.height/2;break}case"bottom":{h.y=i.maxY-d.minY-d.height;break}case"left":{h.x=i.minX-d.minX;break}case"center-horizontal":{h.x=i.midX-d.minX-d.width/2;break}case"right":{h.x=i.maxX-d.minX-d.width;break}}const f=this.getShapeParent(c),g=f?C.Rot(h,-this.getShapePageTransform(f).decompose().rotation):h;a.push(this.getChangesToTranslateShape(c,C.Add(c,g)))}),this.updateShapes(a),this}distributeShapes(e,t){const r=typeof e[0]=="string"?e:e.map(P=>P.id);if(this.getIsReadonly())return this;if(r.length<3)return this;const s=r.length,o=Ye(r.map(P=>this.getShape(P))),i=Object.fromEntries(o.map(P=>[P.id,this.getShapePageBounds(P)]));let a,c,d,h,f;t==="horizontal"?(a="x",c="minX",d="maxX",h="midX",f="width"):(a="y",c="minY",d="maxY",h="midY",f="height");const g=[],y=o.sort((P,k)=>i[P.id][c]-i[k.id][c])[0],S=o.sort((P,k)=>i[k.id][d]-i[P.id][d])[0],v=i[y.id][h],w=(i[S.id][h]-v)/(s-1),b=v+w;return o.filter(P=>P!==y&&P!==S).sort((P,k)=>i[P.id][h]-i[k.id][h]).forEach((P,k)=>{const E={x:0,y:0};E[a]=b+w*k-i[P.id][f]/2-i[P.id][a];const M=this.getShapeParent(P),A=M?C.Rot(E,-this.getShapePageTransform(M).rotation()):E;g.push(this.getChangesToTranslateShape(P,C.Add(P,A)))}),this.updateShapes(g),this}stretchShapes(e,t){const r=typeof e[0]=="string"?e:e.map(c=>c.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const s=Ye(r.map(c=>this.getShape(c))),o=Object.fromEntries(r.map(c=>[c,this.getShapeGeometry(c).bounds])),i=Object.fromEntries(r.map(c=>[c,this.getShapePageBounds(c)])),a=Se.Common(Ye(Object.values(i)));switch(t){case"vertical":{this.run(()=>{for(const c of s){if(this.getShapePageTransform(c).rotation()%St)continue;const h=o[c.id],f=i[c.id],g=new C(0,a.minY-f.minY),y=this.getShapeParentTransform(c);y&&g.rot(-y.rotation());const{x:S,y:v}=C.Add(g,c);this.updateShapes([{id:c.id,type:c.type,x:S,y:v}]);const w=new C(1,a.height/f.height);this.resizeShape(c.id,w,{initialBounds:h,scaleOrigin:new C(f.center.x,a.minY),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}case"horizontal":{this.run(()=>{for(const c of s){const d=o[c.id],h=i[c.id];if(this.getShapePageTransform(c).rotation()%St)continue;const g=new C(a.minX-h.minX,0),y=this.getShapeParentTransform(c);y&&g.rot(-y.rotation());const{x:S,y:v}=C.Add(g,c);this.updateShapes([{id:c.id,type:c.type,x:S,y:v}]);const w=new C(a.width/h.width,1);this.resizeShape(c.id,w,{initialBounds:d,scaleOrigin:new C(a.minX,h.center.y),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}}return this}resizeShape(e,t,r={}){var S,v,w;const s=typeof e=="string"?e:e.id;if(this.getIsReadonly())return this;Number.isFinite(t.x)||(t=new C(1,t.y)),Number.isFinite(t.y)||(t=new C(t.x,1));const o=r.initialShape??this.getShape(s);if(!o)return this;const i=r.scaleOrigin??((S=this.getShapePageBounds(s))==null?void 0:S.center);if(!i)return this;const a=r.initialPageTransform?me.Cast(r.initialPageTransform):this.getShapePageTransform(s);if(!a)return this;const c=a.rotation();if(c==null)return this;const d=r.scaleAxisRotation??c,h=r.initialBounds??this.getShapeGeometry(s).bounds;if(!h)return this;const f=r.isAspectRatioLocked??this.getShapeUtil(o).isAspectRatioLocked(o);if(!aA(c,d))return this._resizeUnalignedShape(s,t,{...r,initialBounds:h,scaleOrigin:i,scaleAxisRotation:d,initialPageTransform:a,isAspectRatioLocked:f,initialShape:o});const g=this.getShapeUtil(o);f&&(Math.abs(t.x)>Math.abs(t.y)?t=new C(t.x,Math.sign(t.y)*Math.abs(t.x)):t=new C(Math.sign(t.x)*Math.abs(t.y),t.y));let y=!1;if(g.onResize&&g.canResize(o)){const b=this._scalePagePoint(me.applyToPoint(a,new C(0,0)),i,t,d),P=this.getPointInParentSpace(o.id,b),k=new C(t.x,t.y),E=la((c-d)%Math.PI,0);k.x=E?t.x:t.y,k.y=E?t.y:t.x;const M=me.applyToPoint(a,new C),{x:A,y:R}=this.getPointInParentSpace(o.id,M);let D=o;r.skipStartAndEndCallbacks||(D=yo(o,((v=g.onResizeStart)==null?void 0:v.call(g,o))??void 0));const V=g.onResize({...o,x:A,y:R},{newPoint:P,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:k.x,scaleY:k.y,initialBounds:h,initialShape:o});V&&(y=!0),D=yo(D,{id:s,type:o.type,x:P.x,y:P.y,...V}),r.skipStartAndEndCallbacks||(D=yo(D,((w=g.onResizeEnd)==null?void 0:w.call(g,o,D))??void 0)),this.updateShapes([D])}if(!y){const b=me.applyToPoint(a,h.center),P=this._scalePagePoint(b,i,t,d),k=this.getPointInParentSpace(o.id,b),E=this.getPointInParentSpace(o.id,P),M=C.Sub(E,k);this.updateShapes([{id:s,type:o.type,x:o.x+M.x,y:o.y+M.y}])}return this}_scalePagePoint(e,t,r,s){const o=C.RotWith(e,t,-s).sub(t),i=C.MulV(o,r);return C.Add(i,t).rotWith(t,s)}_resizeUnalignedShape(e,t,r){const{type:s}=r.initialShape,o=new C(t.x,t.y);if(Math.abs(t.x)>Math.abs(t.y)?o.x=Math.sign(t.x)*Math.abs(t.y):o.y=Math.sign(t.y)*Math.abs(t.x),this.resizeShape(e,o,{initialShape:r.initialShape,initialBounds:r.initialBounds,isAspectRatioLocked:r.isAspectRatioLocked}),Math.sign(t.x)*Math.sign(t.y)<0){let{rotation:w}=me.Decompose(r.initialPageTransform);w-=2*w,this.updateShapes([{id:e,type:s,rotation:w}])}const i=me.applyToPoint(r.initialPageTransform,r.initialBounds.center),a=this._scalePagePoint(i,r.scaleOrigin,t,r.scaleAxisRotation),c=this.getShapePageBounds(e),d=this.getShapePageTransform(e),h=c.center,f=d.point();if(!h||!f)return this;const g=C.Sub(a,h),y=C.Add(f,g),{x:S,y:v}=this.getPointInParentSpace(e,y);return this.updateShapes([{id:e,type:s,x:S,y:v}]),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 t=this.getCurrentPageShapeIds();if(e.length+t.size>this.options.maxShapesPerPage)return Mp(this),this;const s=this.getFocusedGroupId();return this.run(()=>{var h,f;const o=this.getCurrentPageShapesSorted(),i=e.map(g=>{if(g.id||(g={id:Ct(),...g}),!g.parentId||!(this.store.has(g.parentId)||e.some(y=>y.id===g.parentId))){let y=this.getFocusedGroupId();for(let v=o.length-1;v>=0;v--){const w=o[v];if(!this.isShapeHidden(w)&&this.getShapeUtil(w).canReceiveNewChildrenOfType(w,g.type)&&this.isPointInShape(w,{x:g.x??0,y:g.y??0},{margin:0,hitInside:!0})){y=w.id;break}}const S=g.parentId;if(y===g.id&&(y=s),y!==S&&(g={...g},g.parentId=y,Mr(y))){const v=this.getPointInShapeSpace(this.getShape(y),{x:g.x??0,y:g.y??0});g.x=v.x,g.y=v.y,g.rotation=-this.getShapePageTransform(y).rotation()+(g.rotation??0)}}return g}),a=new Map,c=[],{opacityForNextShape:d}=this.getInstanceState();for(const g of i){const y=this.getShapeUtil(g);let S=g.index;if(!S){const P=g.parentId??s;a.has(P)||a.set(P,this.getHighestIndexForParent(P)),S=a.get(P),a.set(P,Co(S))}const v=y.getDefaultProps();for(const[P,k]of this.styleProps[g.type])v[k]=this.getStyleForNextShape(P);let w=this.store.schema.types.shape.create({...g,index:S,opacity:g.opacity??d,parentId:g.parentId??s,props:"props"in g?{...v,...g.props}:v});if(w.index===void 0)throw Error("no index!");const b=(f=(h=this.getShapeUtil(w)).onBeforeCreate)==null?void 0:f.call(h,w);b&&(w=b),c.push(w)}c.forEach(g=>{g.meta={...this.getInitialMetaForShape(g),...g.meta}}),this.store.put(c)}),this}animateShape(e,t={animation:Px}){return this.animateShapes([e],t)}animateShapes(e,t={animation:Px}){if(!t.animation)return this;const{duration:r=500,easing:s=vn.linear}=t.animation,o=xt();let i=r,a;const c=[];let d,h;for(let g=0,y=e.length;g<y;g++){if(d=e[g],!d)continue;const S=this.getShape(d.id);S&&(h={start:Nt(S),end:yo(Nt(S),d)},c.push(h),this.animatingShapes.set(S.id,o))}const f=g=>{var w,b;if(i-=g,i<0){const{animatingShapes:P}=this,k=e.filter(E=>E&&P.get(E.id)===o);k.length&&this.updateShapes(k),this.off("tick",f);return}a=s(1-i/r);const{animatingShapes:y}=this,S=[];let v;for(let P=0,k=c.length;P<k;P++){const{start:E,end:M}=c[P];v=y.get(E.id),v===o&&S.push({...M,x:E.x+(M.x-E.x)*a,y:E.y+(M.y-E.y)*a,opacity:E.opacity+(M.opacity-E.opacity)*a,rotation:E.rotation+(M.rotation-E.rotation)*a,props:((b=(w=this.getShapeUtil(M)).getInterpolatedProps)==null?void 0:b.call(w,E,M,a))??M.props})}this._updateShapes(S)};return this.on("tick",f),this}groupShapes(e,t={}){var S;const{groupId:r=Ct(),select:s=!0}=t;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(v=>v.id);if(o.length<=1)return this;const i=Ye((this._shouldIgnoreShapeLock?o:this._getUnlockedShapeIds(o)).map(v=>this.getShape(v))),a=i.sort(Wn).map(v=>v.id),c=Se.Common(Ye(i.map(v=>this.getShapePageBounds(v)))),{x:d,y:h}=c.point,f=this.findCommonAncestor(i)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const g=i.filter(v=>v.parentId===f).sort(Wn),y=(S=g[g.length-1])==null?void 0:S.index;return this.run(()=>{this.createShapes([{id:r,type:"group",parentId:f,index:y,x:d,y:h,opacity:1,props:{}}]),this.reparentShapes(a,r),s&&this.select(r)}),this}ungroupShapes(e,t={}){if(this.getIsReadonly())return this;const{select:r=!0}=t,s=typeof e[0]=="string"?e:e.map(c=>c.id),o=Ye((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(c=>this.getShape(c)));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(c=>{this.isShapeOfType(c,"group")?a.push(c):i.add(c.id)}),a.length===0?this:(this.run(()=>{let c;for(let d=0,h=a.length;d<h;d++){c=a[d];const f=this.getSortedChildIdsForParent(c.id);for(let g=0,y=f.length;g<y;g++)i.add(f[g]);this.reparentShapes(f,c.parentId,c.index)}this.deleteShapes(a.map(d=>d.id)),r&&this.select(...i)}),this)}updateShape(e){return this.updateShapes([e]),this}updateShapes(e){const t=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),t.push(o)}}return this._updateShapes(t),this}_updateShapes(e){this.getIsReadonly()||this.run(()=>{var o,i;const t=[];let r,s;for(let a=0,c=e.length;a<c;a++){const d=e[a];d&&(r=this.getShape(d.id),r&&(s=yo(r,d),s!==r&&(s=((i=(o=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:i.call(o,r,s))??s,t.push(s))))}this.store.put(t)})}_getUnlockedShapeIds(e){return e.filter(t=>{var r;return!((r=this.getShape(t))!=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 t=typeof e[0]=="string"?e:e.map(o=>o.id),r=this._shouldIgnoreShapeLock?t:this._getUnlockedShapeIds(t);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,t){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]),t)}else for(const[r,s]of this.styleProps[e.type])t.applyValue(r,Vn(e.props,s))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),t=new t0;for(const r of e)this._extractSharedStyles(r,t);return t}getStyleForNextShape(e){const t=this.getInstanceState().stylesForNextShape[e.id];return t===void 0?e.defaultValue:t}getShapeStyleIfExists(e,t){const r=this.styleProps[e.type].get(t);if(r!==void 0)return Vn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),t=new t0;if(!e)return t;if(e.shapeType)for(const r of this.styleProps[e.shapeType].keys())t.applyValue(r,this.getStyleForNextShape(r));return t}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const e=[],t=s=>{const o=this.getShape(s);if(o)if(this.isShapeOfType(o,"group"))for(const i of this.getSortedChildIdsForParent(o.id))t(i);else e.push(o)};for(const s of this.getSelectedShapeIds())t(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,t){return this.updateInstanceState({opacityForNextShape:e},t),this}setOpacityForSelectedShapes(e){const t=this.getSelectedShapes();if(t.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 t)s(o);this.updateShapes(r.map(o=>({id:o.id,type:o.type,opacity:e})))}return this}setStyleForNextShapes(e,t,r){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[e.id]:t}},r),this}setStyleForSelectedShapes(e,t){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 c of a)o(this.getShape(c))}else{const a=this.getShapeUtil(i),c=this.styleProps[i.type].get(e);if(c){const d={id:i.id,type:i.type,props:{[c]:t}};s.push({util:a,originalShape:i,updatePartial:d})}}};for(const i of r)o(i);this.updateShapes(s.map(({updatePartial:i})=>i))}return this}registerExternalAssetHandler(e,t){return this.externalAssetContentHandlers[e]=t,this}createTemporaryAssetPreview(e,t){if(this.temporaryAssetPreview.has(e))return this.temporaryAssetPreview.get(e);const r=URL.createObjectURL(t);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 t,r;return await((r=(t=this.externalAssetContentHandlers)[e.type])==null?void 0:r.call(t,e))}hasExternalAssetHandler(e){return!!this.externalAssetContentHandlers[e]}registerExternalContentHandler(e,t){return this.externalContentHandlers[e]=t,this}async putExternalContent(e){var t,r;return(r=(t=this.externalContentHandlers)[e.type])==null?void 0:r.call(t,e)}getContentFromCurrentPage(e){const t=typeof e[0]=="string"?e:e.map(s=>s.id);if(!t||t.length===0)return;const r=this.getShapeAndDescendantIds(t);return CT(this,r,s=>{const o=[];for(const h of s){const f=this.getBinding(h);f&&o.push(f)}const i=[],a=[];for(const h of r){const f=this.getShape(h);if(!f)continue;if(!r.has(f.parentId)){const y=this.getShapePageTransform(f.id),S=y.point();a.push({...f,x:S.x,y:S.y,rotation:y.rotation(),parentId:this.getCurrentPageId()}),i.push(f.id)}else a.push(f)}const c=[],d=new Set;for(const h of a){if(!("assetId"in h.props))continue;const f=h.props.assetId;if(!f||d.has(f))continue;d.add(f);const g=this.getAsset(f);g&&c.push(g)}return{schema:this.store.schema.serialize(),shapes:a,rootShapeIds:i,bindings:o,assets:c}})}async resolveAssetsInContent(e){if(!e)return;const t=[];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),c=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await Gs.blobToDataUrl(await jo(c).then(d=>d.blob())),t.push(a)}else t.push(r)})),e.assets=t,e}putContentOntoCurrentPage(e,t={}){var L,U,K;if(this.getIsReadonly())return this;if(!e.schema)throw Error(`Could not put content:
|
|
117
|
+
content is missing a schema.`);const{select:r=!1,preserveIds:s=!1,preservePosition:o=!1}=t;let{point:i=void 0}=t;const a=this.getCurrentPageId(),{rootShapeIds:c}=e,d=[],h=[],f=[],g={store:{...Object.fromEntries(e.assets.map(F=>[F.id,F])),...Object.fromEntries(e.shapes.map(F=>[F.id,F])),...Object.fromEntries(((L=e.bindings)==null?void 0:L.map(F=>[F.id,F]))??[])},schema:e.schema},y=this.store.schema.migrateStoreSnapshot(g);if(y.type==="error")throw Error("Could not put content: could not migrate content");for(const F of Object.values(y.value))switch(F.typeName){case"asset":{d.push(F);break}case"shape":{h.push(F);break}case"binding":{f.push(F);break}}const S=new Map(s?h.map(F=>[F.id,F.id]):h.map(F=>[F.id,Ct()])),v=new Map(s?f.map(F=>[F.id,F.id]):f.map(F=>[F.id,nl()]));let w=this.getCurrentPageId(),b=1/0,P=[];for(const F of this.getSelectedShapes()){if(b===0)break;const $=this.isShapeOfType(F,"frame"),W=this.getShapeAncestors(F);$&&W.push(F);const Y=$?W.length+1:W.length;if(Y<b)b=Y,P=W,w=$?F.id:F.parentId;else if(Y===b){if(P.length!==W.length)throw Error(`Ancestors: ${P.length} !== ${W.length}`);if(P.length===0){w=a;break}else{w=a;for(let Z=0;Z<P.length&&W[Z]===P[Z];Z++)w=W[Z].id}}}let k=!1;if(!Er(w)){const F=this.getShape(w);if(F){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(F)))w=a;else if(c.length===1){const $=h.find(W=>W.id===c[0]);this.isShapeOfType(F,"frame")&&this.isShapeOfType($,"frame")&&$.props.w===(F==null?void 0:F.props.w)&&$.props.h===(F==null?void 0:F.props.h)&&(k=!0)}}else w=a}k||(k=S.has(w)),k&&(w=this.getShape(w).parentId);let E=this.getHighestIndexForParent(w);const M=[],A=h.map(F=>{const $=S.get(F.id),W={...F,id:$};return c.includes(F.id)&&(W.parentId=a,M.push(W)),S.has(W.parentId)?W.parentId=S.get(F.parentId):(c.push(W.id),W.index=E,E=Co(E)),W});if(A.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Mp(this),this;const R=f.map(F=>({...F,id:Ar(v.get(F.id)),fromId:Ar(S.get(F.fromId)),toId:Ar(S.get(F.toId))})),D=[],V=[];for(const F of d)this.store.has(F.id)||((F.type==="image"&&((U=F.props.src)!=null&&U.startsWith("data:image"))||F.type==="video"&&((K=F.props.src)!=null&&K.startsWith("data:video")))&&(V.push(Nt(F)),F.props.src=null),D.push(F));return Promise.allSettled(V.map(async F=>{const $=await QH(F.props.src,F.props.name,F.props.mimeType??"image/png"),W=await this.getAssetForExternalContent({type:"file",file:$,assetId:F.id});if(!W){this.deleteAssets([F.id]);return}this.updateAssets([{...W,id:F.id}])})),this.run(()=>{D.length>0&&this.createAssets(D),this.createShapes(A),this.createBindings(R),r&&this.select(...M.map(Z=>Z.id)),w!==a&&this.reparentShapes(M.map(Z=>Z.id),w);const F=A.map(Z=>this.getShape(Z.id)),$=Se.Common(F.map(Z=>this.getShapePageBounds(Z)));if(i===void 0)if(Er(w)){const Z=this.getViewportPageBounds();o||Z.includes(Se.From($))?i=$.center:i=Z.center}else{const Z=this.getShape(w);i=me.applyToPoint(this.getShapePageTransform(Z),this.getShapeGeometry(Z).bounds.center)}if(M.length===1){const Z=M[0];if(this.isShapeOfType(Z,"frame"))for(;this.getShapesAtPoint(i).some(H=>this.isShapeOfType(H,"frame")&&H.props.w===Z.props.w&&H.props.h===Z.props.h);)i.x+=$.w+16}const W=Se.Common(Ye(M.map(({id:Z})=>this.getShapePageBounds(Z)))).center,Y=C.Sub(i,W);this.updateShapes(M.map(({id:Z})=>{const H=this.getShape(Z),Q=this.getShapeParentTransform(Z).decompose().rotation,ae=C.Rot(Y,-Q);return{id:H.id,type:H.type,x:H.x+ae.x,y:H.y+ae.y}}))}),this}async getSvgElement(e,t={}){const r=e.length===0?this.getCurrentPageShapeIdsSorted():typeof e[0]=="string"?e:e.map(s=>s.id);if(r.length!==0)return HH(this,r,t)}async getSvgString(e,t={}){const r=await this.getSvgElement(e,t);return r?{svg:new XMLSerializer().serializeToString(r.svg),width:r.width,height:r.height}:void 0}async getSvg(e,t={}){const r=await this.getSvgElement(e,t);if(r)return r.svg}async toImage(e,t={}){const r={format:"png",scale:1,pixelRatio:t.format==="svg"?void 0:2,...t},s=await this.getSvgString(e,r);if(!s)throw new Error("Could not create SVG");switch(r.format){case"svg":return{blob:new Blob([s.svg],{type:"text/plain"}),width:s.width,height:s.height};case"jpeg":case"png":case"webp":{const o=await YH(s.svg,{type:r.format,quality:r.quality,pixelRatio:r.pixelRatio,width:s.width,height:s.height});if(!o)throw new Error("Could not construct image.");return{blob:o,width:s.width,height:s.height}}default:un(r.format)}}_updateInputsFromEvent(e){const{pointerVelocity:t,previousScreenPoint:r,previousPagePoint:s,currentScreenPoint:o,currentPagePoint:i}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(sr),{x:c,y:d,z:h}=mp(()=>this.getCamera()),f=e.point.x-a.x,g=e.point.y-a.y,y=e.point.z??.5;r.setTo(o),s.setTo(i),o.set(f,g);const S=f/h-c,v=g/h-d;isFinite(S)&&isFinite(v)&&i.set(S,v,y),this.inputs.isPen=e.type==="pointer"&&e.isPen,(e.name==="pointer_down"||this.inputs.isPinching)&&(t.set(0,0),this.inputs.originScreenPoint.setTo(o),this.inputs.originPagePoint.setTo(i)),this.run(()=>{var w;this.store.put([{id:Gf,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===B2.CAMERA_MOVE?((w=this.store.unsafeGetWithoutCapture(Gf))==null?void 0:w.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 VU(this.store)}loadSnapshot(e,t){return Uj(this.store,e,t),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 t=this.getPage(e.pageId);t&&this.setCurrentPage(t),this._zoomToFitPageContentAt100Percent();return}case"shapes":{const t=Ye(e.shapeIds.map(i=>this.getShape(i))),r={};for(const i of t){const a=this.getAncestorPageId(i);a&&(r[a]??(r[a]=[]),r[a].push(i))}const[s,o]=Object.entries(r).sort(([i,a],[c,d])=>d.length-a.length)[0]??["",[]];if(!s||!o.length)this._zoomToFitPageContentAt100Percent();else{this.setCurrentPage(s);const i=Se.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:un(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(tK(r))}catch(s){console.warn(s),this._zoomToFitPageContentAt100Percent()}return this}createDeepLink(e){const t=new URL((e==null?void 0:e.url)??window.location.href);return t.searchParams.set((e==null?void 0:e.param)??"d",eK((e==null?void 0:e.to)??{type:"viewport",pageId:this.options.maxPages===1?void 0:this.getCurrentPageId(),bounds:this.getViewportPageBounds()})),t}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 t=le("url with state",()=>{var c,d;const i=((c=e==null?void 0:e.getUrl)==null?void 0:c.call(e,this))??window.location.href;return this.createDeepLink({param:e==null?void 0:e.param,url:i,to:(d=e==null?void 0:e.getTarget)==null?void 0:d.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=Y0(i=>i(),(e==null?void 0:e.debounceMs)??500),o=To("update url on state change",()=>r(new URL(t.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:Gn(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:Gn(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:Gn(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:Gn(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 t=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const r of t)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;this.emit("before-event",e);const{inputs:t}=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,t.shiftKey=!0):!e.shiftKey&&t.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),e.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,t.altKey=!0):!e.altKey&&t.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),e.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,t.ctrlKey=!0):!e.ctrlKey&&t.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150)),e.metaKey?(clearTimeout(this._metaKeyTimeout),this._metaKeyTimeout=-1,t.metaKey=!0):!e.metaKey&&t.metaKey&&this._metaKeyTimeout===-1&&(this._metaKeyTimeout=this.timers.setTimeout(this._setMetaKeyTimeout,150));const{originPagePoint:s,currentPagePoint:o}=t;t.isPointing||(t.isDragging=!1);const i=this.store.unsafeGetWithoutCapture(sr),a=this.store.get(this._getCurrentPageStateId()),c=this._cameraOptions.__unsafe__getWithoutCapture();switch(r){case"pinch":{if(c.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(e),e.name){case"pinch_start":{if(t.isPinching)return;t.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=[...a.selectedShapeIds]),this._didPinch=!0,t.isPinching=!0,this.interrupt());return}case"pinch":{if(!t.isPinching)return;const{point:{z:d=1},delta:{x:h,y:f}}=e,{x:g,y}=C.SubXY(e.point,i.screenBounds.x,i.screenBounds.y);this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:S,y:v,z:w}=mp(()=>this.getCamera()),{panSpeed:b,zoomSpeed:P}=c;this._setCamera(new C(S+h*b/w-g/w+g/(d*P),v+f*b/w-y/w+y/(d*P),d*P),{immediate:!0});return}case"pinch_end":{if(!t.isPinching)return this;t.isPinching=!1;const{_selectedShapeIdsAtPointerDown:d}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,d.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(d)}));return}}}case"wheel":{if(c.isLocked)return;this._updateInputsFromEvent(e);const{panSpeed:d,zoomSpeed:h,wheelBehavior:f}=c;if(f!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:g,y,z:S}=mp(()=>this.getCamera()),{x:v,y:w,z:b=0}=e.delta;let P=f;switch(t.ctrlKey&&(P=f==="pan"?"zoom":"pan"),P){case"zoom":{const{x:k,y:E}=this.inputs.currentScreenPoint;let M=b;f==="zoom"&&(Math.abs(w)>10?M=10*Math.sign(w)/100:M=w/100);const A=S+(M??0)*h*S;this._setCamera(new C(g+(k/A-k)-(k/S-k),y+(E/A-E)-(E/S-E),A),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new C(g+v*d/S,y+w*d/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}break}case"pointer":{if(t.isPinching)return;this._updateInputsFromEvent(e);const{isPen:d}=e,{isPenMode:h}=i;switch(e.name){case"pointer_down":{if(h&&!d)return;if(this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{const f=this.getViewportScreenBounds();this.dispatch({...e,point:this.inputs.originScreenPoint.clone().addXY(f.x,f.y),name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),e.button===U2&&(this.capturedPointerId=e.pointerId),t.buttons.add(e.button),t.isPointing=!0,t.isDragging=!1,!h&&d&&this.updateInstanceState({isPenMode:!0}),e.button===H2?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===Pp&&(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(!d&&h)return;const{x:f,y:g,z:y}=mp(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:S,previousScreenPoint:v}=this.inputs,{panSpeed:w}=c,b=C.Sub(S,v);this.setCamera(new C(f+b.x*w/y,g+b.y*w/y,y),{immediate:!0}),this.maybeTrackPerformance("Panning");return}t.isPointing&&!t.isDragging&&C.Dist2(s,o)*this.getZoomLevel()>(i.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/y&&(t.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(t.isDragging=!1,t.isPointing=!1,clearTimeout(this._longPressTimeout),t.buttons.delete(e.button),i.isPenMode&&!d)return;if(this.capturedPointerId===e.pointerId&&(this.capturedPointerId=null,e.button=0),t.isPanning){t.keys.has("Space")||(t.isPanning=!1,t.isSpacebarPanning=!1);const f=this.inputs.pointerVelocity,g=Math.min(2,f.len());switch(e.button){case U2:{this.setCursor({type:"grab",rotation:0});break}case Pp:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}g>0&&this.slideCamera({speed:g,direction:f})}else e.button===H2&&(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(t.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 d;switch(e.code){case"ArrowUp":{d=new C(0,-1);break}case"ArrowRight":{d=new C(1,0);break}case"ArrowDown":{d=new C(0,1);break}case"ArrowLeft":{d=new C(-1,0);break}}if(d){const h=this.getViewportPageBounds(),f=h.clone().translate(d.mulV({x:h.w,y:h.h}));this._animateToViewport(f,{animation:{duration:320}})}}break}case"key_up":{t.keys.delete(e.code),e.code==="Space"&&(this.inputs.buttons.has(Pp)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===Pp?e.name="middle_click":e.button===Lb&&(e.name="right_click");const{isPenMode:d}=this.store.unsafeGetWithoutCapture(sr);if(e.isPen===d){const h=this._clickManager.handlePointerEvent(e);if(e.name!==h.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(h),this.emit("event",h);return}}}return this.root.handleEvent(e),this.emit("event",e),e.type==="pointer"&&e.name==="pointer_down"&&this.menus.clearOpenMenus(),this}maybeTrackPerformance(e){sn.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}Ce=PW(r0);_e(Ce,1,"getIsShapeHiddenCache",zD,be);_e(Ce,1,"getCanUndo",$D,be);_e(Ce,1,"getCanRedo",ND,be);_e(Ce,1,"getPath",FD,be);_e(Ce,1,"getCurrentTool",LD,be);_e(Ce,1,"getCurrentToolId",DD,be);_e(Ce,1,"getDocumentSettings",OD,be);_e(Ce,1,"getInstanceState",RD,be);_e(Ce,1,"getOpenMenus",jD,be);_e(Ce,1,"getIsMenuOpen",AD,be);_e(Ce,1,"getPageStates",MD,be);_e(Ce,1,"_getPageStatesQuery",kD,be);_e(Ce,1,"getCurrentPageState",TD,be);_e(Ce,1,"_getCurrentPageStateId",ED,be);_e(Ce,1,"getSelectedShapeIds",ID,be);_e(Ce,1,"getSelectedShapes",_D,be);_e(Ce,1,"getOnlySelectedShapeId",CD,be);_e(Ce,1,"getOnlySelectedShape",PD,be);_e(Ce,1,"getSelectionPageBounds",bD,be);_e(Ce,1,"getSelectionRotation",wD,be);_e(Ce,1,"getSelectionRotatedPageBounds",xD,be);_e(Ce,1,"getSelectionRotatedScreenBounds",vD,be);_e(Ce,1,"getFocusedGroupId",SD,be);_e(Ce,1,"getFocusedGroup",yD,be);_e(Ce,1,"getEditingShapeId",mD,be);_e(Ce,1,"getEditingShape",gD,be);_e(Ce,1,"getHoveredShapeId",fD,be);_e(Ce,1,"getHoveredShape",pD,be);_e(Ce,1,"getHintingShapeIds",hD,be);_e(Ce,1,"getHintingShape",dD,be);_e(Ce,1,"getErasingShapeIds",uD,be);_e(Ce,1,"getErasingShapes",cD,be);_e(Ce,1,"_unsafe_getCameraId",lD,be);_e(Ce,1,"getCamera",aD,be);_e(Ce,1,"getViewportPageBoundsForFollowing",iD,be);_e(Ce,1,"getCameraForFollowing",oD,be);_e(Ce,1,"getZoomLevel",sD,be);_e(Ce,1,"getViewportScreenBounds",rD,be);_e(Ce,1,"getViewportScreenCenter",nD,be);_e(Ce,1,"getViewportPageBounds",tD,be);_e(Ce,1,"_getCollaboratorsQuery",eD,be);_e(Ce,1,"getCollaborators",JO,be);_e(Ce,1,"getCollaboratorsOnCurrentPage",QO,be);_e(Ce,1,"getRenderingShapes",ZO,be);_e(Ce,1,"_getAllPagesQuery",XO,be);_e(Ce,1,"getPages",YO,be);_e(Ce,1,"getCurrentPageId",qO,be);_e(Ce,1,"getCurrentPageShapeIdsSorted",VO,be);_e(Ce,1,"_getAllAssetsQuery",GO,be);_e(Ce,1,"_getShapeGeometryCache",WO,be);_e(Ce,1,"_getShapeHandlesCache",KO,be);_e(Ce,1,"_getShapePageTransformCache",HO,be);_e(Ce,1,"_getShapePageBoundsCache",UO,be);_e(Ce,1,"_getShapeClipPathCache",BO,be);_e(Ce,1,"_getShapeMaskCache",zO,be);_e(Ce,1,"_getShapeMaskedPageBoundsCache",$O,be);_e(Ce,1,"_notVisibleShapes",NO,be);_e(Ce,1,"getCulledShapes",FO,be);_e(Ce,1,"getCurrentPageBounds",LO,be);_e(Ce,1,"getCurrentPageShapes",DO,be);_e(Ce,1,"getCurrentPageShapesSorted",OO,be);_e(Ce,1,"getCurrentPageRenderingShapesSorted",RO,be);_e(Ce,1,"_getBindingsIndexCache",jO,be);_e(Ce,1,"_getSelectionSharedStyles",AO,be);_e(Ce,1,"getSharedStyles",MO,be);_e(Ce,1,"getSharedOpacity",kO,be);_e(Ce,1,"getIsFocused",TO,be);_e(Ce,1,"getIsReadonly",EO,be);_e(Ce,1,"_setShiftKeyTimeout",IO,be);_e(Ce,1,"_setAltKeyTimeout",_O,be);_e(Ce,1,"_setCtrlKeyTimeout",CO,be);_e(Ce,1,"_setMetaKeyTimeout",PO,be);_W(Ce,be);function Mp(n,e=n.getCurrentPageId()){const t=n.getPage(e).name;n.emit("max-shapes",{name:t,pageId:e,count:n.options.maxShapesPerPage})}function yo(n,e){if(!e)return n;let t=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!==n[i]){if(t||(t={...n}),i==="props"||i==="meta"){t[i]={...n[i]};for(const[c,d]of Object.entries(a))t[i][c]=d;continue}t[i]=a}}return t||n}function BD(n,e,t){const r=n.getShape(e);if(!r)return;t.push(r);const s=n.getSortedChildIdsForParent(e);for(let o=0,i=s.length;o<i;o++)BD(n,s[o],t)}function CT(n,e,t){let r;if(n.run(()=>{const s=n.store.extractingChanges(()=>{const o=new Set,i=new Set;for(const a of e)if(n.getShape(a))for(const d of n.getBindingsInvolvingShape(a)){const h=e.has(d.fromId),f=e.has(d.toId);if(h&&f){o.add(d.id);continue}(!h||!f)&&i.add(d.id)}n.deleteBindings([...i],{isolateShapes:!0});try{r=rr.ok(t(o))}catch(a){r=rr.err(a)}});n.store.applyDiff(Uw(s))},{history:"ignore"}),r.ok)return r.value;throw r.error}function _T(n,e){if(!e.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=e.constraints,s=n.getViewportScreenBounds(),o=Se.From(e.constraints.bounds),i=(s.w-t*2)/o.w,a=(s.h-r*2)/o.h;return{zx:i,zy:a}}function eh(){const n=te(),e=Xd();return se("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??n.user.getIsDarkMode(),[e,n])}const IT="<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'/>",ET="<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'/>",Ap='<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 Zi(n,e,t,r,s,o=16,i=16){const a=(-t-e)*(pt/180),c=Math.sin(a),d=Math.cos(a),h=1*d-1*c,f=1*c+1*d;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='${h}' dy='${f}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${e+t} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+n.replaceAll('"',"'")+`</g></svg>") ${o} ${i}, pointer`}const EW=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],TW={none:()=>"none","ew-resize":(n,e,t)=>Zi(ET,n,0,e,t),"ns-resize":(n,e,t)=>Zi(ET,n,90,e,t),"nesw-resize":(n,e,t)=>Zi(IT,n,0,e,t),"nwse-resize":(n,e,t)=>Zi(IT,n,90,e,t),"nwse-rotate":(n,e,t)=>Zi(Ap,n,0,e,t),"nesw-rotate":(n,e,t)=>Zi(Ap,n,90,e,t),"senw-rotate":(n,e,t)=>Zi(Ap,n,180,e,t),"swne-rotate":(n,e,t)=>Zi(Ap,n,270,e,t)};function qr(n,e=0,t="black"){return TW[n](T8(e),!1,t)}function kW(){const n=te(),e=fn(),t=eh();aa("useCursor",()=>{const{type:r,rotation:s}=n.getInstanceState().cursor;if(EW.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",qr(r,s,t?"white":"black"))},[n,e,t])}function MW(){const n=te(),e=fn(),t=eh(),r=se(sn.forceSrgb);at.useEffect(()=>{t?(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")},[n,e,r,t])}function AW(){const[n,e]=_.useState(0);_.useEffect(()=>e(t=>t+1),[])}const jW=n=>n.props.src,RW={upload:async(n,e)=>({src:await Gs.blobToDataUrl(e)})};function OW(n){return"schema"in n&&n.schema?n.schema:hB({shapes:"shapeUtils"in n&&n.shapeUtils?TT(Gj(n.shapeUtils)):void 0,bindings:"bindingUtils"in n&&n.bindingUtils?TT(Kj(n.bindingUtils)):void 0,migrations:"migrations"in n?n.migrations:void 0})}function Id({initialData:n,defaultName:e="",id:t,assets:r=RW,onMount:s,collaboration:o,...i}={}){const a=OW(i),c=new bb({id:t,schema:a,initialData:n,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??jW},onMount:d=>{mt(d instanceof be),s==null||s(d)},collaboration:o}});if(i.snapshot){if(n)throw new Error("Cannot provide both initialData and snapshot");Uj(c,i.snapshot,{forceOverwriteSessionState:!0})}return c}function TT(n){return Object.fromEntries(n.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}function DW(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
|
|
118
|
+
|
|
119
|
+
Keep seeing this message?
|
|
120
|
+
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
|
|
121
|
+
• If your hard disk is full, try clearing up some space and then reload the page.`)}function LW(){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.
|
|
122
|
+
|
|
123
|
+
Keep seeing this message?
|
|
124
|
+
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const FW=350,NW=1e4,kT=Symbol("UPDATE_INSTANCE_STATE"),$W=n=>n;class zW{constructor(e){j(this,"onmessage")}postMessage(e){}close(){}}const BW=typeof BroadcastChannel>"u"?zW:BroadcastChannel;class UW{constructor(e,{persistenceKey:t,sessionId:r=Qf,onLoad:s,onLoadError:o},i=new BW(`tldraw-tab-sync-${t}`)){j(this,"disposables",new Set);j(this,"diffQueue",[]);j(this,"didDispose",!1);j(this,"shouldDoFullDBWrite",!0);j(this,"isReloading",!1);j(this,"persistenceKey");j(this,"sessionId");j(this,"serializedSchema");j(this,"isDebugging",!1);j(this,"documentTypes");j(this,"$sessionStateSnapshot");j(this,"db");j(this,"initTime",Date.now());j(this,"isPersisting",!1);j(this,"didLastWriteError",!1);j(this,"scheduledPersistTimeout",null);this.store=e,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.db=new Ff(t),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=Ub(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage($W({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(kT),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,t){this.debug("connecting");let r;try{r=await this.db.load({sessionId:this.sessionId})}catch(s){t(s),LW();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const s=Object.fromEntries(r.records.map(c=>[c.id,c])),o=r.sessionStateSnapshot??GU(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),t(new Error(`Failed to migrate store: ${i.reason}`));return}const a=Object.values(i.value).filter(c=>this.documentTypes.has(c.typeName));a.length>0&&this.store.mergeRemoteChanges(()=>{this.store.put(a,"initialize")}),o&&Xw(this.store,o,{forceOverwrite:!0})}this.channel.onmessage=({data:s})=>{var a,c;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){t(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(c=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||c.call(a);return}o.type==="diff"&&(this.debug("applying diff"),ko(()=>{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;t(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?NW:FW))}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(mt(!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 t=wb(e.filter(r=>r!==kT));await this.db.storeChanges({changes:t,schema:this.store.schema,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(t){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",t),DW(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function UD(n){const e=_.useRef(n),[t,r]=_.useState(n);t!==e.current&&r(e.current);const s=_.useCallback(o=>{typeof o=="function"?e.current=o(e.current):e.current=o,r(e.current)},[]);return[t,s]}function HW(n){const[e,t]=UD({status:"loading"});return n=Vc(n),_.useEffect(()=>{const{persistenceKey:r,sessionId:s,...o}=n;if(!r){t({status:"not-synced",store:Id(o)});return}t({status:"loading"});const i=new Ao,a={upload:async(f,g)=>(await h.db.storeAsset(f.id,g),{src:f.id}),resolve:async f=>f.props.src?f.props.src.startsWith("asset:")?await i.get(f,async()=>{const g=await h.db.getAsset(f.id);return g?URL.createObjectURL(g):null}):f.props.src:null,...o.assets},c=Id({...o,assets:a});let d=!1;const h=new UW(c,{sessionId:s,persistenceKey:r,onLoad(){d||t({store:c,status:"synced-local"})},onLoadError(f){d||t({status:"error",error:f})}});return()=>{d=!0,h.close()}},[n,t]),e}function KW(){const n=te(),e=fn();_.useEffect(()=>{const t=o=>e.style.setProperty("--tl-zoom",o.toString()),r=Y0(t,100),s=new Kc("useZoomCss",()=>{n.getCurrentPageShapeIds().size<300?t(n.getZoomLevel()):r(n.getZoomLevel())});return s.attach(),s.execute(),()=>{s.detach(),r.cancel()}},[n,e])}function s0(n){const e=new ArrayBuffer(n.length),t=new Uint8Array(e);for(let r=0,s=n.length;r<s;r++)t[r]=n.charCodeAt(r);return e}function WW(n){const e=atob(n),t=s0(e);return crypto.subtle.importKey("spki",new Uint8Array(t),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const GW=5,nd={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},VW=Math.max(...Object.values(nd)),rd={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},qW=Object.keys(rd).length,Nx="sales@tldraw.com",YW=`${ia()}/watermarks/watermark-track.svg`;class Hg{constructor(e,t,r){j(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");j(this,"isDevelopment");j(this,"isTest");j(this,"isCryptoAvailable");j(this,"state",dn("license state","pending"));j(this,"verbose",!0);this.isTest=!1,this.isDevelopment=this.getIsDevelopment(r),this.publicKey=t||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.getLicenseFromKey(e).then(s=>{const o=XW(s);!this.isDevelopment&&o&&jo(YW),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[t,r]=e.split("."),[s,o]=t.split("/");if(!s.startsWith("tldraw-"))throw new Error(`Unsupported prefix '${s}'`);const i=await WW(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(s0(atob(r))),new Uint8Array(s0(atob(o))))}catch(d){throw console.error(d),new Error("Could not perform signature validation")}if(!a)throw new Error("Invalid signature");let c;try{c=JSON.parse(atob(o))}catch{throw new Error("Could not parse object")}return c.length>qW&&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:c[rd.ID],hosts:c[rd.HOSTS],flags:c[rd.FLAGS],expiryDate:c[rd.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 t=e.replace(/[\u200B-\u200D\uFEFF]/g,"");t=t.replace(/\r?\n|\r/g,"");try{const r=await this.extractLicenseKey(t),s=new Date(r.expiryDate),o=this.isFlagEnabled(r.flags,nd.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,nd.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,nd.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,nd.WITH_WATERMARK)};return this.outputLicenseInfoIfNeeded(a),a}catch(r){return this.outputInvalidLicenseKey(r.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(e){const t=window.location.hostname.toLowerCase();return e.hosts.some(r=>{const s=r.toLowerCase().trim();if(s===t||`www.${s}`===t||s===`www.${t}`||r==="*")return!0;if(r.includes("*")){const o=new RegExp(r.replace(/\*/g,".*?"));return o.test(t)||o.test(`www.${t}`)}return!1})}getExpirationDateWithoutGracePeriod(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}getExpirationDateWithGracePeriod(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+GW+1)}isAnnualLicenseExpired(e){const t=this.getExpirationDateWithGracePeriod(e),r=new Date>=t;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 ${Nx} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const t=this.getExpirationDateWithGracePeriod(e),r={major:new Date($2.major),minor:new Date($2.minor)};return r.major>=t||r.minor>=t}isFlagEnabled(e,t){return(e&t)===t}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 ${Nx} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${Nx} if you would like to use tldraw on other domains.`]),e.license.flags>=VW*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 t of e)console.log(`%c${t}`,"color: white; background: crimson; padding: 2px; border-radius: 3px;");this.outputDelimiter()}}outputDelimiter(){console.log("%c-------------------------------------------------------------------","color: white; background: crimson; padding: 2px; border-radius: 3px;")}}j(Hg,"className","tl-watermark_SEE-LICENSE");function XW(n){if(!n.isLicenseParseable||!n.isDomainValid&&!n.isDevelopment)return!0;if(n.isPerpetualLicenseExpired||n.isAnnualLicenseExpired){if(n.isInternalLicense)throw new Error("License: Internal license expired.");return!0}return!1}const HD=_.createContext({}),ZW=()=>_.useContext(HD);function QW({licenseKey:n,children:e}){const[t]=_.useState(()=>new Hg(n));return p.jsx(HD.Provider,{value:t,children:e})}function Pa(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=fn();_.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;const o=n.current;if(o&&o.scrollHeight>o.clientHeight)return;Je(s);const i=e.querySelector(".tl-canvas");if(!i)return;const a=new WheelEvent("wheel",s);a.isSpecialRedispatchedEvent=!0,i.dispatchEvent(a)}const r=n.current;if(r)return r.addEventListener("wheel",t,{passive:!1}),()=>{r.removeEventListener("wheel",t)}},[e,n])}const JW='<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>',eG='<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 tG(n){return se("watermarkState",()=>n.state.get(),[n])}const nG=`data:image/svg+xml;utf8,${encodeURIComponent(JW)}`,rG=`data:image/svg+xml;utf8,${encodeURIComponent(eG)}`,sG=_.memo(function(){const e=ZW(),t=te(),r=se("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),s=tG(e);return["licensed-with-watermark","unlicensed"].includes(s)?p.jsxs(p.Fragment,{children:[p.jsx(iG,{}),p.jsx(oG,{src:r?rG:nG})]}):null}),oG=_.memo(function({src:e}){const t=te(),r=se("debug mode",()=>t.getInstanceState().isDebugMode,[t]),s=se("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),o=Fb(),i=_.useRef(null);Pa(i);const a=`url('${e}') center 100% / 100% no-repeat`,c="https://tldraw.dev";return p.jsx("div",{ref:i,className:Hg.className,"data-debug":r,"data-mobile":s,draggable:!1,...o,children:Et.isWebview?p.jsx("a",{draggable:!1,role:"button",onPointerDown:d=>{ln(d),Je(d)},onClick:()=>Ag.openWindow(c,"_blank"),style:{mask:a,WebkitMask:a}}):p.jsx("a",{href:c,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:d=>{ln(d)},style:{mask:a,WebkitMask:a}})})}),iG=_.memo(function(){const e=Hg.className,t=`/* ------------------- SEE LICENSE -------------------
|
|
125
|
+
The tldraw watermark is part of tldraw's license. It is shown for unlicensed
|
|
126
|
+
or "licensed-with-watermark" users. By using this library, you agree to
|
|
127
|
+
preserve the watermark's behavior, keeping it visible, unobscured, and
|
|
128
|
+
available to user-interaction.
|
|
129
|
+
|
|
130
|
+
To remove the watermark, please purchase a license at tldraw.dev.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
.${e} {
|
|
134
|
+
position: absolute;
|
|
135
|
+
bottom: var(--space-2);
|
|
136
|
+
right: var(--space-2);
|
|
137
|
+
width: 96px;
|
|
138
|
+
height: 32px;
|
|
139
|
+
display: flex;
|
|
140
|
+
align-items: center;
|
|
141
|
+
justify-content: center;
|
|
142
|
+
z-index: var(--layer-watermark) !important;
|
|
143
|
+
background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
|
|
144
|
+
opacity: 1;
|
|
145
|
+
border-radius: 5px;
|
|
146
|
+
pointer-events: all;
|
|
147
|
+
padding: 2px;
|
|
148
|
+
box-sizing: content-box;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.${e} > a {
|
|
152
|
+
position: absolute;
|
|
153
|
+
width: 96px;
|
|
154
|
+
height: 32px;
|
|
155
|
+
pointer-events: all;
|
|
156
|
+
cursor: inherit;
|
|
157
|
+
color: var(--color-text);
|
|
158
|
+
opacity: .38;
|
|
159
|
+
background-color: currentColor;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.${e}[data-debug='true'] {
|
|
163
|
+
bottom: 46px;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.${e}[data-mobile='true'] {
|
|
167
|
+
border-radius: 4px 0px 0px 4px;
|
|
168
|
+
right: -2px;
|
|
169
|
+
width: 8px;
|
|
170
|
+
height: 48px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.${e}[data-mobile='true'] > a {
|
|
174
|
+
width: 8px;
|
|
175
|
+
height: 32px;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@media (hover: hover) {
|
|
179
|
+
.${e} > a {
|
|
180
|
+
pointer-events: none;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.${e}:hover {
|
|
184
|
+
background-color: var(--color-background);
|
|
185
|
+
transition: background-color 0.2s ease-in-out;
|
|
186
|
+
transition-delay: 0.32s;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.${e}:hover > a {
|
|
190
|
+
animation: delayed_link 0.2s forwards ease-in-out;
|
|
191
|
+
animation-delay: 0.32s;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@keyframes delayed_link {
|
|
196
|
+
0% {
|
|
197
|
+
cursor: inherit;
|
|
198
|
+
opacity: .38;
|
|
199
|
+
pointer-events: none;
|
|
200
|
+
}
|
|
201
|
+
100% {
|
|
202
|
+
cursor: pointer;
|
|
203
|
+
opacity: 1;
|
|
204
|
+
pointer-events: all;
|
|
205
|
+
}
|
|
206
|
+
}`;return p.jsx("style",{children:t})}),aG=[],lG=[],cG=[],uG="tl-container",dG=_.memo(function({store:e,components:t,className:r,user:s,options:o,...i}){const[a,c]=_.useState(null),d=_.useMemo(()=>s??$j(),[s]),h=(t==null?void 0:t.ErrorFallback)===void 0?Mj:t==null?void 0:t.ErrorFallback,f={...i,shapeUtils:i.shapeUtils??aG,bindingUtils:i.bindingUtils??lG,tools:i.tools??cG,components:t,options:Vc(o)};return p.jsx("div",{ref:c,"data-tldraw":sj,draggable:!1,className:Le(`${uG} tl-theme__light`,r),onPointerDown:ln,tabIndex:-1,children:p.jsx(_d,{fallback:h,onError:g=>X0(g,{tags:{origin:"react.tldraw-before-app"}}),children:a&&p.jsx(QW,{licenseKey:i.licenseKey,children:p.jsx(cj,{container:a,children:p.jsx(AU,{overrides:t,children:e?e instanceof bb?p.jsx(WD,{...f,store:e,user:d}):p.jsx(KD,{...f,store:e,user:d}):p.jsx(hG,{...f,store:e,user:d})})})})})})});function hG(n){const{defaultName:e,snapshot:t,initialData:r,shapeUtils:s,bindingUtils:o,persistenceKey:i,sessionId:a,user:c,assets:d,migrations:h}=n,f=HW({shapeUtils:s,bindingUtils:o,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:t,assets:d,migrations:h});return p.jsx(KD,{...n,store:f,user:c})}const KD=_.memo(function({store:e,user:t,...r}){const s=fn();_.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,t]);const{LoadingScreen:o}=$t();switch(e.status){case"error":throw e.error;case"loading":return o?p.jsx(o,{}):null}return p.jsx(WD,{...r,store:e.store,user:t})}),$x=()=>document.location.search.includes("tldraw_preserve_focus");function WD({onMount:n,children:e,store:t,tools:r,shapeUtils:s,bindingUtils:o,user:i,initialState:a,autoFocus:c=!0,inferDarkMode:d,cameraOptions:h,options:f,licenseKey:g,deepLinks:y,isShapeHidden:S}){const{ErrorFallback:v}=$t(),w=fn(),[b,P]=UD(null),k=_.useRef(null),E=Vc(y===!0?{}:y),M=_.useRef({autoFocus:c&&!$x(),inferDarkMode:d,initialState:a,cameraOptions:h,deepLinks:E});_.useLayoutEffect(()=>{M.current={autoFocus:c&&!$x(),inferDarkMode:d,initialState:a,cameraOptions:h,deepLinks:E}},[c,d,a,h,E]),_.useLayoutEffect(()=>{const{autoFocus:D,inferDarkMode:V,initialState:L,cameraOptions:U,deepLinks:K}=M.current,F=new be({store:t,shapeUtils:s,bindingUtils:o,tools:r,getContainer:()=>w,user:i,initialState:L,autoFocus:D,inferDarkMode:V,cameraOptions:U,options:f,licenseKey:g,isShapeHidden:S});return F.updateViewportScreenBounds(k.current??w),K&&(K!=null&&K.getUrl?F.navigateToDeepLink({...K,url:K.getUrl(F)}):F.navigateToDeepLink(K)),P(F),()=>{F.dispose()}},[o,w,f,s,t,r,i,P,g,S]),_.useLayoutEffect(()=>{if(b&&E)return b.registerDeepLinkListener(E)},[b,E]),_.useLayoutEffect(()=>{b&&h&&b.setCameraOptions(h)},[b,h]);const A=_.useSyncExternalStore(_.useCallback(D=>b?(b.on("crash",D),()=>b.off("crash",D)):()=>{},[b]),()=>(b==null?void 0:b.getCrashingError())??null);_.useEffect(function(){if(!b)return;function V(){b&&b.focus()}function L(){b&&b.blur()}if(c&&$x())return b.getContainer().addEventListener("pointerdown",V),document.body.addEventListener("pointerdown",L),()=>{var U;(U=b.getContainer())==null||U.removeEventListener("pointerdown",V),document.body.removeEventListener("pointerdown",L)}},[b,c]);const{Canvas:R}=$t();return b?p.jsx(_d,{fallback:v,onError:D=>b.annotateError(D,{origin:"react.tldraw",willCrashApp:!0}),children:A?p.jsx(fG,{crashingError:A}):p.jsx(Db,{editor:b,children:p.jsxs(pG,{onMount:n,children:[e??(R?p.jsx(R,{},b.contextId):null),p.jsx(sG,{})]})})}):p.jsx("div",{className:"tl-canvas",ref:k})}function pG({children:n,onMount:e}){return KW(),kW(),MW(),AW(),VD(t=>{const r=t.store.props.onMount(t),s=e==null?void 0:e(t);return()=>{r==null||r(),s==null||s()}}),n}function fG({crashingError:n}){throw n}function t1({children:n}){return p.jsx("div",{className:"tl-loading",children:n})}function GD({children:n}){return p.jsx("div",{className:"tl-loading",children:n})}function VD(n){const e=te(),t=Fg(r=>{let s;return r.run(()=>{s=n==null?void 0:n(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});at.useLayoutEffect(()=>{if(e)return t==null?void 0:t(e)},[e,t])}function ca({children:n,className:e="",...t}){return p.jsx("div",{...t,className:Le("tl-html-container",e),children:n})}class af{constructor(e){this.editor=e}}j(af,"props"),j(af,"migrations"),j(af,"type");function Kg(n,e,t={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=e,{minWidth:a=1,maxWidth:c=1/0,minHeight:d=1,maxHeight:h=1/0}=t;let f=n.props.w*o,g=n.props.h*i;const y=new C(0,0);if(f>0){if(f<a){switch(s){case"top_left":case"left":case"bottom_left":{y.x=f-a;break}case"top":case"bottom":{y.x=(f-a)/2;break}default:y.x=0}f=a}}else if(y.x=f,f=-f,f<a){switch(s){case"top_left":case"left":case"bottom_left":{y.x=-f;break}default:y.x=-a}f=a}if(g>0){if(g<d){switch(s){case"top_left":case"top":case"top_right":{y.y=g-d;break}case"right":case"left":{y.y=(g-d)/2;break}default:y.y=0}g=d}}else if(y.y=g,g=-g,g<d){switch(s){case"top_left":case"top":case"top_right":{y.y=-g;break}default:y.y=-d}g=d}const{x:S,y:v}=y.rot(n.rotation).add(r);return{...n,x:S,y:v,props:{w:Math.min(c,f),h:Math.min(h,g)}}}class Qc extends Xs{getGeometry(e){return new Do({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return Kg(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,r){return{...t.props,w:ot(e.props.w,t.props.w,r),h:ot(e.props.h,t.props.h,r)}}}var hw;let gG=(hw=class extends Re{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},j(hw,"id","idle"),hw);var pw;let mG=(pw=class extends Re{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=this.parent.shapeType,s=Ct(),o=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),i=Zs(t,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?c=>{var d;return(d=a.onCreate)==null?void 0:d.call(a,c)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,t=this.parent.shapeType,r=Ct();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:t,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 C(o/2,i/2),c=this.editor.getShapeParentTransform(s);c&&a.rot(-c.rotation());let d=1;this.editor.user.getIsDynamicResizeMode()&&(d=1/this.editor.getZoomLevel(),o*=d,i*=d,a.mul(d));const h=Nt(s),f=Zs(new C(s.x-a.x,s.y-a.y),this.editor);h.x=f.x,h.y=f.y,h.props.w=o,h.props.h=i,"scale"in s.props&&(h.props.scale=d),this.editor.updateShape(h),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},j(pw,"id","pointing"),pw);function Zs(n,e){const t=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return t?n.clone().snapToGrid(r):n.clone()}class o0 extends Re{static children(){return[gG,mG]}}j(o0,"id","box"),j(o0,"initial","idle");function yG(n,e,t){const r=_.useRef(!1),s=_.useCallback(i=>{r.current=i,i?Ks.addOpenMenu(n):Ks.deleteOpenMenu(n),e==null||e(i)},[n,e]),o=se("is menu open",()=>Ks.getOpenMenus().includes(n),[n]);return _.useEffect(()=>(r.current&&(t==null||t("open-menu"),Ks.addOpenMenu(n)),()=>{r.current&&(Ks.deleteOpenMenu(n),Ks.getOpenMenus().forEach(i=>{i.startsWith(n)&&(t==null||t("close-menu"),Ks.deleteOpenMenu(i))}),r.current=!1)}),[n,t]),[o,s]}function Wg(n){const e=te();return se("isEditing",()=>e.getEditingShapeId()===n,[e,n])}function xo(n){const e=te();return _.useMemo(function(){const s=d=>{if(d.isKilled)return;if(d.button===Lb){e.dispatch({type:"pointer",target:"selection",handle:n,name:"right_click",...Zr(d)});return}if(d.button!==0)return;const h=Xf(d.currentTarget);function f(){h.removeEventListener("pointerup",f),Gd(h,d)}Wd(h,d),h.addEventListener("pointerup",f),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:n,...Zr(d)}),ln(d)};let o,i;function a(d){d.isKilled||d.button===0&&(d.clientX===o&&d.clientY===i||(o=d.clientX,i=d.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:n,...Zr(d)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:d=>{d.isKilled||d.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:n,...Zr(d)})}}},[e,n])}function SG(n){const[e,t]=_.useState(()=>({store:Id(n),opts:n}));if(!oM(e.opts,n)){const r={store:Id(n),opts:n};return t(r),r.store}return e.store}const vG=20,xG=8;function n1(n,e=vG){return Math.max(xG,Math.ceil(n/e))}class xc extends ba{constructor(t){super({...t,isFilled:!1,isClosed:!1});j(this,"_center");j(this,"radius");j(this,"start");j(this,"end");j(this,"largeArcFlag");j(this,"sweepFlag");j(this,"measure");j(this,"angleStart");j(this,"angleEnd");const{center:r,sweepFlag:s,largeArcFlag:o,start:i,end:a}=t;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=C.Angle(r,i),this.angleEnd=C.Angle(r,a),this.radius=C.Dist(r,i),this.measure=k8(this.angleStart,this.angleEnd,s,o),this.start=i,this.end=a,this.sweepFlag=s,this.largeArcFlag=o,this._center=r}nearestPoint(t){const{_center:r,measure:s,radius:o,angleEnd:i,angleStart:a,start:c,end:d}=this,h=$w(s,a,i,r.angle(t));if(h<=0)return c;if(h>=1)return d;const f=r.clone().add(t.clone().sub(r).uni().mul(o));let g,y=1/0,S;for(const v of[c,d,f])S=C.Dist2(t,v),S<y&&(g=v,y=S);if(!g)throw Error("nearest point not found");return g}hitTestLineSegment(t,r){const{_center:s,radius:o,measure:i,angleStart:a,angleEnd:c}=this,d=Yd(t,r,s,o);return d===null?!1:d.some(h=>{const f=$w(i,a,c,s.angle(h));return f>=0&&f<=1})}getVertices(){const{_center:t,measure:r,length:s,radius:o,angleStart:i}=this,a=[];for(let c=0,d=n1(Math.abs(s));c<d+1;c++){const h=c/d*r,f=i+h;a.push(sl(t,o,f))}return a}getSvgPathData(t=!0){const{start:r,end:s,radius:o,largeArcFlag:i,sweepFlag:a}=this;return`${t?`M${r.toFixed()}`:""} A${o} ${o} 0 ${i} ${a} ${s.toFixed()}`}getLength(){return this.measure*this.radius}}class r1 extends ba{constructor(t){super({isClosed:!0,...t});j(this,"_center");j(this,"radius");j(this,"x");j(this,"y");this.config=t;const{x:r=0,y:s=0,radius:o}=t;this.x=r,this.y=s,this._center=new C(o+r,o+s),this.radius=o}getBounds(){return new Se(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,s=St*r,o=[];for(let i=0,a=n1(s);i<a;i++){const c=i/a*St;o.push(sl(t,r,c))}return o}nearestPoint(t){const{_center:r,radius:s}=this;return r.equals(t)?C.AddXY(r,s,0):r.clone().add(t.clone().sub(r).uni().mul(s))}hitTestLineSegment(t,r,s=0){const{_center:o,radius:i}=this;return Yd(t,r,o,i+s)!==null}getSvgPathData(){const{_center:t,radius:r}=this;return`M${t.x+r},${t.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class Kn extends qc{constructor(t){const{start:r,cp1:s,cp2:o,end:i}=t;super({...t,points:[r,i]});j(this,"a");j(this,"b");j(this,"c");j(this,"d");this.a=r,this.b=s,this.c=o,this.d=i}getVertices(){const t=[],{a:r,b:s,c:o,d:i}=this;for(let a=0,c=10;a<=c;a++){const d=a/c;t.push(new C((1-d)*(1-d)*(1-d)*r.x+3*((1-d)*(1-d))*d*s.x+3*(1-d)*(d*d)*o.x+d*d*d*i.x,(1-d)*(1-d)*(1-d)*r.y+3*((1-d)*(1-d))*d*s.y+3*(1-d)*(d*d)*o.y+d*d*d*i.y))}return t}midPoint(){return Kn.GetAtT(this,.5)}nearestPoint(t){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(t),o=C.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}getSvgPathData(t=!0){const{a:r,b:s,c:o,d:i}=this;return`${t?`M ${r.toFixed()} `:""} C${s.toFixed()} ${o.toFixed()} ${i.toFixed()}`}static GetAtT(t,r){const{a:s,b:o,c:i,d:a}=t;return new C((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(t=32){let r,s=this.a,o=0;for(let i=1;i<=t;i++)r=Kn.GetAtT(this,i/t),o+=C.Dist(s,r),s=r;return o}}class wG extends ba{constructor(t){super({...t,isClosed:!1,isFilled:!1});j(this,"points");j(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:t}=this,r=t.length,s=r-2,o=1.25;for(let i=0;i<r-1;i++){const a=i===0?t[0]:t[i-1],c=t[i],d=t[i+1],h=i===s?d:t[i+2],f=c,g=i===0?a:new C(c.x+(d.x-a.x)/6*o,c.y+(d.y-a.y)/6*o),y=i===s?d:new C(d.x-(h.x-c.x)/6*o,d.y-(h.y-c.y)/6*o),S=d;this._segments.push(new Kn({start:f,cp1:g,cp2:y,end:S}))}}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){const t=this.segments.reduce((r,s)=>r.concat(s.vertices),[]);return t.push(this.points[this.points.length-1]),t}nearestPoint(t){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(t),o=C.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.segments.some(s=>s.hitTestLineSegment(t,r))}getSvgPathData(){let t=this.segments.reduce((r,s,o)=>r+s.getSvgPathData(o===0),"");return this.isClosed&&(t+="Z"),t}}class bG extends ba{constructor(t){super({...t,isClosed:!0});j(this,"w");j(this,"h");j(this,"_edges");this.config=t;const{width:r,height:s}=t;this.w=r,this.h=s}get edges(){if(!this._edges){const{vertices:t}=this;this._edges=[];for(let r=0,s=t.length;r<s;r++){const o=t[r],i=t[(r+1)%s];this._edges.push(new hi({start:o,end:i}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),s=t/2,o=r/2,i=Math.pow(s-o,2)/Math.pow(s+o,2),a=pt*(s+o)*(1+3*i/(10+Math.sqrt(4-3*i))),c=n1(a),d=St/c,h=Math.cos(d),f=Math.sin(d);let g=0,y=1,S=0,v=1;const w=Array(c);for(let b=0;b<c;b++)w[b]=new C(s+s*y,o+o*g),S=f*y+h*g,v=h*y-f*g,g=S,y=v;return w}nearestPoint(t){let r,s=1/0,o,i;for(const a of this.edges)i=a.nearestPoint(t),o=C.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.edges.some(s=>s.hitTestLineSegment(t,r))}getBounds(){return new Se(0,0,this.w,this.h)}getLength(){const{w:t,h:r}=this,s=t/2,o=r/2,i=Math.max(0,s),a=Math.max(0,o);return oA(i,a)}getSvgPathData(t=!1){const{w:r,h:s}=this,o=r/2,i=s/2,a=Math.max(0,o),c=Math.max(0,i);return`${t?`M${o-a},${i}`:""} a${a},${c},0,1,1,${a*2},0a${a},${c},0,1,1,-${a*2},0`}}class PG extends ba{constructor(t){super({...t,isClosed:!0});j(this,"w");j(this,"h");j(this,"a");j(this,"b");j(this,"c");j(this,"d");this.config=t;const{width:r,height:s}=t;if(this.w=r,this.h=s,s>r){const o=r/2;this.a=new xc({start:new C(0,o),end:new C(r,o),center:new C(r/2,o),sweepFlag:1,largeArcFlag:1}),this.b=new hi({start:new C(r,o),end:new C(r,s-o)}),this.c=new xc({start:new C(r,s-o),end:new C(0,s-o),center:new C(r/2,s-o),sweepFlag:1,largeArcFlag:1}),this.d=new hi({start:new C(0,s-o),end:new C(0,o)})}else{const o=s/2;this.a=new xc({start:new C(o,s),end:new C(o,0),center:new C(o,o),sweepFlag:1,largeArcFlag:1}),this.b=new hi({start:new C(o,0),end:new C(r-o,0)}),this.c=new xc({start:new C(r-o,0),end:new C(r-o,s),center:new C(r-o,o),sweepFlag:1,largeArcFlag:1}),this.d=new hi({start:new C(r-o,s),end:new C(o,s)})}}nearestPoint(t){let r,s=1/0,o,i;const{a,b:c,c:d,d:h}=this;for(const f of[a,c,d,h])i=f.nearestPoint(t),o=C.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){const{a:s,b:o,c:i,d:a}=this;return[s,o,i,a].some(c=>c.hitTestLineSegment(t,r))}getVertices(){const{a:t,b:r,c:s,d:o}=this;return[t,r,s,o].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new Se(0,0,this.w,this.h)}getLength(){const{h:t,w:r}=this;return t>r?(pt*(r/2)+(t-r))*2:(pt*(t/2)+(r-t))*2}getSvgPathData(){const{a:t,b:r,c:s,d:o}=this;return[t,r,s,o].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function CG({shouldReload:n=!0}={}){Q6();for(const e of Ff.connectedInstances)await e.close();await Promise.all(xb().map(e=>hA(e))),Z6(),n&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=CG);function _G(n,e="_blank"){Ag.openWindow(n,e)}ya("@tldraw/editor","3.8.0-canary.3f23e0d4c913","esm");function qD(){const[n,e]=_.useState(!1);return _.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const t=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{e(t.matches)};return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),n}const YD=()=>{},XD=_.createContext(null);function IG({onEvent:n,children:e}){return p.jsx(XD.Provider,{value:n??YD,children:e})}function On(){return _.useContext(XD)??YD}function Ae(n,e,{checkForDefaultPrevented:t=!0}={}){return function(s){if(n==null||n(s),t===!1||!s.defaultPrevented)return e==null?void 0:e(s)}}function EG(n,e){const t=_.createContext(e),r=o=>{const{children:i,...a}=o,c=_.useMemo(()=>a,Object.values(a));return p.jsx(t.Provider,{value:c,children:i})};r.displayName=n+"Provider";function s(o){const i=_.useContext(t);if(i)return i;if(e!==void 0)return e;throw new Error(`\`${o}\` must be used within \`${n}\``)}return[r,s]}function Uo(n,e=[]){let t=[];function r(o,i){const a=_.createContext(i),c=t.length;t=[...t,i];const d=f=>{var b;const{scope:g,children:y,...S}=f,v=((b=g==null?void 0:g[n])==null?void 0:b[c])||a,w=_.useMemo(()=>S,Object.values(S));return p.jsx(v.Provider,{value:w,children:y})};d.displayName=o+"Provider";function h(f,g){var v;const y=((v=g==null?void 0:g[n])==null?void 0:v[c])||a,S=_.useContext(y);if(S)return S;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${o}\``)}return[d,h]}const s=()=>{const o=t.map(i=>_.createContext(i));return function(a){const c=(a==null?void 0:a[n])||o;return _.useMemo(()=>({[`__scope${n}`]:{...a,[n]:c}}),[a,c])}};return s.scopeName=n,[r,TG(s,...e)]}function TG(...n){const e=n[0];if(n.length===1)return e;const t=()=>{const r=n.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const i=r.reduce((a,{useScope:c,scopeName:d})=>{const f=c(o)[`__scope${d}`];return{...a,...f}},{});return _.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return t.scopeName=e.scopeName,t}function MT(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function Gg(...n){return e=>{let t=!1;const r=n.map(s=>{const o=MT(s,e);return!t&&typeof o=="function"&&(t=!0),o});if(t)return()=>{for(let s=0;s<r.length;s++){const o=r[s];typeof o=="function"?o():MT(n[s],null)}}}}function Ot(...n){return _.useCallback(Gg(...n),n)}var cl=_.forwardRef((n,e)=>{const{children:t,...r}=n,s=_.Children.toArray(t),o=s.find(MG);if(o){const i=o.props.children,a=s.map(c=>c===o?_.Children.count(i)>1?_.Children.only(null):_.isValidElement(i)?i.props.children:null:c);return p.jsx(i0,{...r,ref:e,children:_.isValidElement(i)?_.cloneElement(i,void 0,a):null})}return p.jsx(i0,{...r,ref:e,children:t})});cl.displayName="Slot";var i0=_.forwardRef((n,e)=>{const{children:t,...r}=n;if(_.isValidElement(t)){const s=jG(t),o=AG(r,t.props);return t.type!==_.Fragment&&(o.ref=e?Gg(e,s):s),_.cloneElement(t,o)}return _.Children.count(t)>1?_.Children.only(null):null});i0.displayName="SlotClone";var kG=({children:n})=>p.jsx(p.Fragment,{children:n});function MG(n){return _.isValidElement(n)&&n.type===kG}function AG(n,e){const t={...e};for(const r in e){const s=n[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?t[r]=(...a)=>{o(...a),s(...a)}:s&&(t[r]=s):r==="style"?t[r]={...s,...o}:r==="className"&&(t[r]=[s,o].filter(Boolean).join(" "))}return{...n,...t}}function jG(n){var r,s;let e=(r=Object.getOwnPropertyDescriptor(n.props,"ref"))==null?void 0:r.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=(s=Object.getOwnPropertyDescriptor(n,"ref"))==null?void 0:s.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var RG=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],ut=RG.reduce((n,e)=>{const t=_.forwardRef((r,s)=>{const{asChild:o,...i}=r,a=o?cl:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),p.jsx(a,{...i,ref:s})});return t.displayName=`Primitive.${e}`,{...n,[e]:t}},{});function s1(n,e){n&&Yc.flushSync(()=>n.dispatchEvent(e))}function Vg(n){const e=n+"CollectionProvider",[t,r]=Uo(e),[s,o]=t(e,{collectionRef:{current:null},itemMap:new Map}),i=y=>{const{scope:S,children:v}=y,w=at.useRef(null),b=at.useRef(new Map).current;return p.jsx(s,{scope:S,itemMap:b,collectionRef:w,children:v})};i.displayName=e;const a=n+"CollectionSlot",c=at.forwardRef((y,S)=>{const{scope:v,children:w}=y,b=o(a,v),P=Ot(S,b.collectionRef);return p.jsx(cl,{ref:P,children:w})});c.displayName=a;const d=n+"CollectionItemSlot",h="data-radix-collection-item",f=at.forwardRef((y,S)=>{const{scope:v,children:w,...b}=y,P=at.useRef(null),k=Ot(S,P),E=o(d,v);return at.useEffect(()=>(E.itemMap.set(P,{ref:P,...b}),()=>void E.itemMap.delete(P))),p.jsx(cl,{[h]:"",ref:k,children:w})});f.displayName=d;function g(y){const S=o(n+"CollectionConsumer",y);return at.useCallback(()=>{const w=S.collectionRef.current;if(!w)return[];const b=Array.from(w.querySelectorAll(`[${h}]`));return Array.from(S.itemMap.values()).sort((E,M)=>b.indexOf(E.ref.current)-b.indexOf(M.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:i,Slot:c,ItemSlot:f},g,r]}var OG=_.createContext(void 0);function o1(n){const e=_.useContext(OG);return n||e||"ltr"}function An(n){const e=_.useRef(n);return _.useEffect(()=>{e.current=n}),_.useMemo(()=>(...t)=>{var r;return(r=e.current)==null?void 0:r.call(e,...t)},[])}function DG(n,e=globalThis==null?void 0:globalThis.document){const t=An(n);_.useEffect(()=>{const r=s=>{s.key==="Escape"&&t(s)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[t,e])}var LG="DismissableLayer",a0="dismissableLayer.update",FG="dismissableLayer.pointerDownOutside",NG="dismissableLayer.focusOutside",AT,ZD=_.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),th=_.forwardRef((n,e)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:i,onDismiss:a,...c}=n,d=_.useContext(ZD),[h,f]=_.useState(null),g=(h==null?void 0:h.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,y]=_.useState({}),S=Ot(e,R=>f(R)),v=Array.from(d.layers),[w]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),b=v.indexOf(w),P=h?v.indexOf(h):-1,k=d.layersWithOutsidePointerEventsDisabled.size>0,E=P>=b,M=zG(R=>{const D=R.target,V=[...d.branches].some(L=>L.contains(D));!E||V||(s==null||s(R),i==null||i(R),R.defaultPrevented||a==null||a())},g),A=BG(R=>{const D=R.target;[...d.branches].some(L=>L.contains(D))||(o==null||o(R),i==null||i(R),R.defaultPrevented||a==null||a())},g);return DG(R=>{P===d.layers.size-1&&(r==null||r(R),!R.defaultPrevented&&a&&(R.preventDefault(),a()))},g),_.useEffect(()=>{if(h)return t&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(AT=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(h)),d.layers.add(h),jT(),()=>{t&&d.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=AT)}},[h,g,t,d]),_.useEffect(()=>()=>{h&&(d.layers.delete(h),d.layersWithOutsidePointerEventsDisabled.delete(h),jT())},[h,d]),_.useEffect(()=>{const R=()=>y({});return document.addEventListener(a0,R),()=>document.removeEventListener(a0,R)},[]),p.jsx(ut.div,{...c,ref:S,style:{pointerEvents:k?E?"auto":"none":void 0,...n.style},onFocusCapture:Ae(n.onFocusCapture,A.onFocusCapture),onBlurCapture:Ae(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:Ae(n.onPointerDownCapture,M.onPointerDownCapture)})});th.displayName=LG;var $G="DismissableLayerBranch",QD=_.forwardRef((n,e)=>{const t=_.useContext(ZD),r=_.useRef(null),s=Ot(e,r);return _.useEffect(()=>{const o=r.current;if(o)return t.branches.add(o),()=>{t.branches.delete(o)}},[t.branches]),p.jsx(ut.div,{...n,ref:s})});QD.displayName=$G;function zG(n,e=globalThis==null?void 0:globalThis.document){const t=An(n),r=_.useRef(!1),s=_.useRef(()=>{});return _.useEffect(()=>{const o=a=>{if(a.target&&!r.current){let c=function(){JD(FG,t,d,{discrete:!0})};const d={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",s.current),s.current=c,e.addEventListener("click",s.current,{once:!0})):c()}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,t]),{onPointerDownCapture:()=>r.current=!0}}function BG(n,e=globalThis==null?void 0:globalThis.document){const t=An(n),r=_.useRef(!1);return _.useEffect(()=>{const s=o=>{o.target&&!r.current&&JD(NG,t,{originalEvent:o},{discrete:!1})};return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function jT(){const n=new CustomEvent(a0);document.dispatchEvent(n)}function JD(n,e,t,{discrete:r}){const s=t.originalEvent.target,o=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:t});e&&s.addEventListener(n,e,{once:!0}),r?s1(s,o):s.dispatchEvent(o)}var UG=th,HG=QD,zx=0;function i1(){_.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??RT()),document.body.insertAdjacentElement("beforeend",n[1]??RT()),zx++,()=>{zx===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),zx--}},[])}function RT(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var Bx="focusScope.autoFocusOnMount",Ux="focusScope.autoFocusOnUnmount",OT={bubbles:!1,cancelable:!0},KG="FocusScope",qg=_.forwardRef((n,e)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...i}=n,[a,c]=_.useState(null),d=An(s),h=An(o),f=_.useRef(null),g=Ot(e,v=>c(v)),y=_.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;_.useEffect(()=>{if(r){let v=function(k){if(y.paused||!a)return;const E=k.target;a.contains(E)?f.current=E:ea(f.current,{select:!0})},w=function(k){if(y.paused||!a)return;const E=k.relatedTarget;E!==null&&(a.contains(E)||ea(f.current,{select:!0}))},b=function(k){if(document.activeElement===document.body)for(const M of k)M.removedNodes.length>0&&ea(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",w);const P=new MutationObserver(b);return a&&P.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",w),P.disconnect()}}},[r,a,y.paused]),_.useEffect(()=>{if(a){LT.add(y);const v=document.activeElement;if(!a.contains(v)){const b=new CustomEvent(Bx,OT);a.addEventListener(Bx,d),a.dispatchEvent(b),b.defaultPrevented||(WG(XG(e3(a)),{select:!0}),document.activeElement===v&&ea(a))}return()=>{a.removeEventListener(Bx,d),setTimeout(()=>{const b=new CustomEvent(Ux,OT);a.addEventListener(Ux,h),a.dispatchEvent(b),b.defaultPrevented||ea(v??document.body,{select:!0}),a.removeEventListener(Ux,h),LT.remove(y)},0)}}},[a,d,h,y]);const S=_.useCallback(v=>{if(!t&&!r||y.paused)return;const w=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,b=document.activeElement;if(w&&b){const P=v.currentTarget,[k,E]=GG(P);k&&E?!v.shiftKey&&b===E?(v.preventDefault(),t&&ea(k,{select:!0})):v.shiftKey&&b===k&&(v.preventDefault(),t&&ea(E,{select:!0})):b===P&&v.preventDefault()}},[t,r,y.paused]);return p.jsx(ut.div,{tabIndex:-1,...i,ref:g,onKeyDown:S})});qg.displayName=KG;function WG(n,{select:e=!1}={}){const t=document.activeElement;for(const r of n)if(ea(r,{select:e}),document.activeElement!==t)return}function GG(n){const e=e3(n),t=DT(e,n),r=DT(e.reverse(),n);return[t,r]}function e3(n){const e=[],t=document.createTreeWalker(n,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(;t.nextNode();)e.push(t.currentNode);return e}function DT(n,e){for(const t of n)if(!VG(t,{upTo:e}))return t}function VG(n,{upTo:e}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(e!==void 0&&n===e)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function qG(n){return n instanceof HTMLInputElement&&"select"in n}function ea(n,{select:e=!1}={}){if(n&&n.focus){const t=document.activeElement;n.focus({preventScroll:!0}),n!==t&&qG(n)&&e&&n.select()}}var LT=YG();function YG(){let n=[];return{add(e){const t=n[0];e!==t&&(t==null||t.pause()),n=FT(n,e),n.unshift(e)},remove(e){var t;n=FT(n,e),(t=n[0])==null||t.resume()}}}function FT(n,e){const t=[...n],r=t.indexOf(e);return r!==-1&&t.splice(r,1),t}function XG(n){return n.filter(e=>e.tagName!=="A")}var pa=globalThis!=null&&globalThis.document?_.useLayoutEffect:()=>{},ZG=r6.useId||(()=>{}),QG=0;function yi(n){const[e,t]=_.useState(ZG());return pa(()=>{t(r=>r??String(QG++))},[n]),n||(e?`radix-${e}`:"")}const JG=["top","right","bottom","left"],fa=Math.min,Yr=Math.max,Jf=Math.round,jp=Math.floor,Mo=n=>({x:n,y:n}),eV={left:"right",right:"left",bottom:"top",top:"bottom"},tV={start:"end",end:"start"};function l0(n,e,t){return Yr(n,fa(e,t))}function vi(n,e){return typeof n=="function"?n(e):n}function xi(n){return n.split("-")[0]}function Jc(n){return n.split("-")[1]}function a1(n){return n==="x"?"y":"x"}function l1(n){return n==="y"?"height":"width"}function ga(n){return["top","bottom"].includes(xi(n))?"y":"x"}function c1(n){return a1(ga(n))}function nV(n,e,t){t===void 0&&(t=!1);const r=Jc(n),s=c1(n),o=l1(s);let i=s==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(i=eg(i)),[i,eg(i)]}function rV(n){const e=eg(n);return[c0(n),e,c0(e)]}function c0(n){return n.replace(/start|end/g,e=>tV[e])}function sV(n,e,t){const r=["left","right"],s=["right","left"],o=["top","bottom"],i=["bottom","top"];switch(n){case"top":case"bottom":return t?e?s:r:e?r:s;case"left":case"right":return e?o:i;default:return[]}}function oV(n,e,t,r){const s=Jc(n);let o=sV(xi(n),t==="start",r);return s&&(o=o.map(i=>i+"-"+s),e&&(o=o.concat(o.map(c0)))),o}function eg(n){return n.replace(/left|right|bottom|top/g,e=>eV[e])}function iV(n){return{top:0,right:0,bottom:0,left:0,...n}}function t3(n){return typeof n!="number"?iV(n):{top:n,right:n,bottom:n,left:n}}function tg(n){const{x:e,y:t,width:r,height:s}=n;return{width:r,height:s,top:t,left:e,right:e+r,bottom:t+s,x:e,y:t}}function NT(n,e,t){let{reference:r,floating:s}=n;const o=ga(e),i=c1(e),a=l1(i),c=xi(e),d=o==="y",h=r.x+r.width/2-s.width/2,f=r.y+r.height/2-s.height/2,g=r[a]/2-s[a]/2;let y;switch(c){case"top":y={x:h,y:r.y-s.height};break;case"bottom":y={x:h,y:r.y+r.height};break;case"right":y={x:r.x+r.width,y:f};break;case"left":y={x:r.x-s.width,y:f};break;default:y={x:r.x,y:r.y}}switch(Jc(e)){case"start":y[i]-=g*(t&&d?-1:1);break;case"end":y[i]+=g*(t&&d?-1:1);break}return y}const aV=async(n,e,t)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=t,a=o.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(e));let d=await i.getElementRects({reference:n,floating:e,strategy:s}),{x:h,y:f}=NT(d,r,c),g=r,y={},S=0;for(let v=0;v<a.length;v++){const{name:w,fn:b}=a[v],{x:P,y:k,data:E,reset:M}=await b({x:h,y:f,initialPlacement:r,placement:g,strategy:s,middlewareData:y,rects:d,platform:i,elements:{reference:n,floating:e}});h=P??h,f=k??f,y={...y,[w]:{...y[w],...E}},M&&S<=50&&(S++,typeof M=="object"&&(M.placement&&(g=M.placement),M.rects&&(d=M.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:s}):M.rects),{x:h,y:f}=NT(d,g,c)),v=-1)}return{x:h,y:f,placement:g,strategy:s,middlewareData:y}};async function Ed(n,e){var t;e===void 0&&(e={});const{x:r,y:s,platform:o,rects:i,elements:a,strategy:c}=n,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:g=!1,padding:y=0}=vi(e,n),S=t3(y),w=a[g?f==="floating"?"reference":"floating":f],b=tg(await o.getClippingRect({element:(t=await(o.isElement==null?void 0:o.isElement(w)))==null||t?w:w.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:d,rootBoundary:h,strategy:c})),P=f==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,k=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),E=await(o.isElement==null?void 0:o.isElement(k))?await(o.getScale==null?void 0:o.getScale(k))||{x:1,y:1}:{x:1,y:1},M=tg(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:P,offsetParent:k,strategy:c}):P);return{top:(b.top-M.top+S.top)/E.y,bottom:(M.bottom-b.bottom+S.bottom)/E.y,left:(b.left-M.left+S.left)/E.x,right:(M.right-b.right+S.right)/E.x}}const lV=n=>({name:"arrow",options:n,async fn(e){const{x:t,y:r,placement:s,rects:o,platform:i,elements:a,middlewareData:c}=e,{element:d,padding:h=0}=vi(n,e)||{};if(d==null)return{};const f=t3(h),g={x:t,y:r},y=c1(s),S=l1(y),v=await i.getDimensions(d),w=y==="y",b=w?"top":"left",P=w?"bottom":"right",k=w?"clientHeight":"clientWidth",E=o.reference[S]+o.reference[y]-g[y]-o.floating[S],M=g[y]-o.reference[y],A=await(i.getOffsetParent==null?void 0:i.getOffsetParent(d));let R=A?A[k]:0;(!R||!await(i.isElement==null?void 0:i.isElement(A)))&&(R=a.floating[k]||o.floating[S]);const D=E/2-M/2,V=R/2-v[S]/2-1,L=fa(f[b],V),U=fa(f[P],V),K=L,F=R-v[S]-U,$=R/2-v[S]/2+D,W=l0(K,$,F),Y=!c.arrow&&Jc(s)!=null&&$!==W&&o.reference[S]/2-($<K?L:U)-v[S]/2<0,Z=Y?$<K?$-K:$-F:0;return{[y]:g[y]+Z,data:{[y]:W,centerOffset:$-W-Z,...Y&&{alignmentOffset:Z}},reset:Y}}}),cV=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:a,platform:c,elements:d}=e,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:g,fallbackStrategy:y="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:v=!0,...w}=vi(n,e);if((t=o.arrow)!=null&&t.alignmentOffset)return{};const b=xi(s),P=ga(a),k=xi(a)===a,E=await(c.isRTL==null?void 0:c.isRTL(d.floating)),M=g||(k||!v?[eg(a)]:rV(a)),A=S!=="none";!g&&A&&M.push(...oV(a,v,S,E));const R=[a,...M],D=await Ed(e,w),V=[];let L=((r=o.flip)==null?void 0:r.overflows)||[];if(h&&V.push(D[b]),f){const $=nV(s,i,E);V.push(D[$[0]],D[$[1]])}if(L=[...L,{placement:s,overflows:V}],!V.every($=>$<=0)){var U,K;const $=(((U=o.flip)==null?void 0:U.index)||0)+1,W=R[$];if(W)return{data:{index:$,overflows:L},reset:{placement:W}};let Y=(K=L.filter(Z=>Z.overflows[0]<=0).sort((Z,H)=>Z.overflows[1]-H.overflows[1])[0])==null?void 0:K.placement;if(!Y)switch(y){case"bestFit":{var F;const Z=(F=L.filter(H=>{if(A){const Q=ga(H.placement);return Q===P||Q==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(Q=>Q>0).reduce((Q,ae)=>Q+ae,0)]).sort((H,Q)=>H[1]-Q[1])[0])==null?void 0:F[0];Z&&(Y=Z);break}case"initialPlacement":Y=a;break}if(s!==Y)return{reset:{placement:Y}}}return{}}}};function $T(n,e){return{top:n.top-e.height,right:n.right-e.width,bottom:n.bottom-e.height,left:n.left-e.width}}function zT(n){return JG.some(e=>n[e]>=0)}const uV=function(n){return n===void 0&&(n={}),{name:"hide",options:n,async fn(e){const{rects:t}=e,{strategy:r="referenceHidden",...s}=vi(n,e);switch(r){case"referenceHidden":{const o=await Ed(e,{...s,elementContext:"reference"}),i=$T(o,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:zT(i)}}}case"escaped":{const o=await Ed(e,{...s,altBoundary:!0}),i=$T(o,t.floating);return{data:{escapedOffsets:i,escaped:zT(i)}}}default:return{}}}}};async function dV(n,e){const{placement:t,platform:r,elements:s}=n,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=xi(t),a=Jc(t),c=ga(t)==="y",d=["left","top"].includes(i)?-1:1,h=o&&c?-1:1,f=vi(e,n);let{mainAxis:g,crossAxis:y,alignmentAxis:S}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof S=="number"&&(y=a==="end"?S*-1:S),c?{x:y*h,y:g*d}:{x:g*d,y:y*h}}const hV=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,r;const{x:s,y:o,placement:i,middlewareData:a}=e,c=await dV(e,n);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+c.x,y:o+c.y,data:{...c,placement:i}}}}},pV=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){const{x:t,y:r,placement:s}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:w=>{let{x:b,y:P}=w;return{x:b,y:P}}},...c}=vi(n,e),d={x:t,y:r},h=await Ed(e,c),f=ga(xi(s)),g=a1(f);let y=d[g],S=d[f];if(o){const w=g==="y"?"top":"left",b=g==="y"?"bottom":"right",P=y+h[w],k=y-h[b];y=l0(P,y,k)}if(i){const w=f==="y"?"top":"left",b=f==="y"?"bottom":"right",P=S+h[w],k=S-h[b];S=l0(P,S,k)}const v=a.fn({...e,[g]:y,[f]:S});return{...v,data:{x:v.x-t,y:v.y-r,enabled:{[g]:o,[f]:i}}}}}},fV=function(n){return n===void 0&&(n={}),{options:n,fn(e){const{x:t,y:r,placement:s,rects:o,middlewareData:i}=e,{offset:a=0,mainAxis:c=!0,crossAxis:d=!0}=vi(n,e),h={x:t,y:r},f=ga(s),g=a1(f);let y=h[g],S=h[f];const v=vi(a,e),w=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(c){const k=g==="y"?"height":"width",E=o.reference[g]-o.floating[k]+w.mainAxis,M=o.reference[g]+o.reference[k]-w.mainAxis;y<E?y=E:y>M&&(y=M)}if(d){var b,P;const k=g==="y"?"width":"height",E=["top","left"].includes(xi(s)),M=o.reference[f]-o.floating[k]+(E&&((b=i.offset)==null?void 0:b[f])||0)+(E?0:w.crossAxis),A=o.reference[f]+o.reference[k]+(E?0:((P=i.offset)==null?void 0:P[f])||0)-(E?w.crossAxis:0);S<M?S=M:S>A&&(S=A)}return{[g]:y,[f]:S}}}},gV=function(n){return n===void 0&&(n={}),{name:"size",options:n,async fn(e){var t,r;const{placement:s,rects:o,platform:i,elements:a}=e,{apply:c=()=>{},...d}=vi(n,e),h=await Ed(e,d),f=xi(s),g=Jc(s),y=ga(s)==="y",{width:S,height:v}=o.floating;let w,b;f==="top"||f==="bottom"?(w=f,b=g===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,w=g==="end"?"top":"bottom");const P=v-h.top-h.bottom,k=S-h.left-h.right,E=fa(v-h[w],P),M=fa(S-h[b],k),A=!e.middlewareData.shift;let R=E,D=M;if((t=e.middlewareData.shift)!=null&&t.enabled.x&&(D=k),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(R=P),A&&!g){const L=Yr(h.left,0),U=Yr(h.right,0),K=Yr(h.top,0),F=Yr(h.bottom,0);y?D=S-2*(L!==0||U!==0?L+U:Yr(h.left,h.right)):R=v-2*(K!==0||F!==0?K+F:Yr(h.top,h.bottom))}await c({...e,availableWidth:D,availableHeight:R});const V=await i.getDimensions(a.floating);return S!==V.width||v!==V.height?{reset:{rects:!0}}:{}}}};function Yg(){return typeof window<"u"}function eu(n){return n3(n)?(n.nodeName||"").toLowerCase():"#document"}function ts(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function Ho(n){var e;return(e=(n3(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function n3(n){return Yg()?n instanceof Node||n instanceof ts(n).Node:!1}function Qs(n){return Yg()?n instanceof Element||n instanceof ts(n).Element:!1}function Lo(n){return Yg()?n instanceof HTMLElement||n instanceof ts(n).HTMLElement:!1}function BT(n){return!Yg()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof ts(n).ShadowRoot}function nh(n){const{overflow:e,overflowX:t,overflowY:r,display:s}=Js(n);return/auto|scroll|overlay|hidden|clip/.test(e+r+t)&&!["inline","contents"].includes(s)}function mV(n){return["table","td","th"].includes(eu(n))}function Xg(n){return[":popover-open",":modal"].some(e=>{try{return n.matches(e)}catch{return!1}})}function u1(n){const e=d1(),t=Qs(n)?Js(n):n;return["transform","translate","scale","rotate","perspective"].some(r=>t[r]?t[r]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(r=>(t.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(t.contain||"").includes(r))}function yV(n){let e=ma(n);for(;Lo(e)&&!Rc(e);){if(u1(e))return e;if(Xg(e))return null;e=ma(e)}return null}function d1(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Rc(n){return["html","body","#document"].includes(eu(n))}function Js(n){return ts(n).getComputedStyle(n)}function Zg(n){return Qs(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function ma(n){if(eu(n)==="html")return n;const e=n.assignedSlot||n.parentNode||BT(n)&&n.host||Ho(n);return BT(e)?e.host:e}function r3(n){const e=ma(n);return Rc(e)?n.ownerDocument?n.ownerDocument.body:n.body:Lo(e)&&nh(e)?e:r3(e)}function Td(n,e,t){var r;e===void 0&&(e=[]),t===void 0&&(t=!0);const s=r3(n),o=s===((r=n.ownerDocument)==null?void 0:r.body),i=ts(s);if(o){const a=u0(i);return e.concat(i,i.visualViewport||[],nh(s)?s:[],a&&t?Td(a):[])}return e.concat(s,Td(s,[],t))}function u0(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function s3(n){const e=Js(n);let t=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Lo(n),o=s?n.offsetWidth:t,i=s?n.offsetHeight:r,a=Jf(t)!==o||Jf(r)!==i;return a&&(t=o,r=i),{width:t,height:r,$:a}}function h1(n){return Qs(n)?n:n.contextElement}function Tc(n){const e=h1(n);if(!Lo(e))return Mo(1);const t=e.getBoundingClientRect(),{width:r,height:s,$:o}=s3(e);let i=(o?Jf(t.width):t.width)/r,a=(o?Jf(t.height):t.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const SV=Mo(0);function o3(n){const e=ts(n);return!d1()||!e.visualViewport?SV:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function vV(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==ts(n)?!1:e}function ul(n,e,t,r){e===void 0&&(e=!1),t===void 0&&(t=!1);const s=n.getBoundingClientRect(),o=h1(n);let i=Mo(1);e&&(r?Qs(r)&&(i=Tc(r)):i=Tc(n));const a=vV(o,t,r)?o3(o):Mo(0);let c=(s.left+a.x)/i.x,d=(s.top+a.y)/i.y,h=s.width/i.x,f=s.height/i.y;if(o){const g=ts(o),y=r&&Qs(r)?ts(r):r;let S=g,v=u0(S);for(;v&&r&&y!==S;){const w=Tc(v),b=v.getBoundingClientRect(),P=Js(v),k=b.left+(v.clientLeft+parseFloat(P.paddingLeft))*w.x,E=b.top+(v.clientTop+parseFloat(P.paddingTop))*w.y;c*=w.x,d*=w.y,h*=w.x,f*=w.y,c+=k,d+=E,S=ts(v),v=u0(S)}}return tg({width:h,height:f,x:c,y:d})}function p1(n,e){const t=Zg(n).scrollLeft;return e?e.left+t:ul(Ho(n)).left+t}function i3(n,e,t){t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=r.left+e.scrollLeft-(t?0:p1(n,r)),o=r.top+e.scrollTop;return{x:s,y:o}}function xV(n){let{elements:e,rect:t,offsetParent:r,strategy:s}=n;const o=s==="fixed",i=Ho(r),a=e?Xg(e.floating):!1;if(r===i||a&&o)return t;let c={scrollLeft:0,scrollTop:0},d=Mo(1);const h=Mo(0),f=Lo(r);if((f||!f&&!o)&&((eu(r)!=="body"||nh(i))&&(c=Zg(r)),Lo(r))){const y=ul(r);d=Tc(r),h.x=y.x+r.clientLeft,h.y=y.y+r.clientTop}const g=i&&!f&&!o?i3(i,c,!0):Mo(0);return{width:t.width*d.x,height:t.height*d.y,x:t.x*d.x-c.scrollLeft*d.x+h.x+g.x,y:t.y*d.y-c.scrollTop*d.y+h.y+g.y}}function wV(n){return Array.from(n.getClientRects())}function bV(n){const e=Ho(n),t=Zg(n),r=n.ownerDocument.body,s=Yr(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=Yr(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+p1(n);const a=-t.scrollTop;return Js(r).direction==="rtl"&&(i+=Yr(e.clientWidth,r.clientWidth)-s),{width:s,height:o,x:i,y:a}}function PV(n,e){const t=ts(n),r=Ho(n),s=t.visualViewport;let o=r.clientWidth,i=r.clientHeight,a=0,c=0;if(s){o=s.width,i=s.height;const d=d1();(!d||d&&e==="fixed")&&(a=s.offsetLeft,c=s.offsetTop)}return{width:o,height:i,x:a,y:c}}function CV(n,e){const t=ul(n,!0,e==="fixed"),r=t.top+n.clientTop,s=t.left+n.clientLeft,o=Lo(n)?Tc(n):Mo(1),i=n.clientWidth*o.x,a=n.clientHeight*o.y,c=s*o.x,d=r*o.y;return{width:i,height:a,x:c,y:d}}function UT(n,e,t){let r;if(e==="viewport")r=PV(n,t);else if(e==="document")r=bV(Ho(n));else if(Qs(e))r=CV(e,t);else{const s=o3(n);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return tg(r)}function a3(n,e){const t=ma(n);return t===e||!Qs(t)||Rc(t)?!1:Js(t).position==="fixed"||a3(t,e)}function _V(n,e){const t=e.get(n);if(t)return t;let r=Td(n,[],!1).filter(a=>Qs(a)&&eu(a)!=="body"),s=null;const o=Js(n).position==="fixed";let i=o?ma(n):n;for(;Qs(i)&&!Rc(i);){const a=Js(i),c=u1(i);!c&&a.position==="fixed"&&(s=null),(o?!c&&!s:!c&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||nh(i)&&!c&&a3(n,i))?r=r.filter(h=>h!==i):s=a,i=ma(i)}return e.set(n,r),r}function IV(n){let{element:e,boundary:t,rootBoundary:r,strategy:s}=n;const i=[...t==="clippingAncestors"?Xg(e)?[]:_V(e,this._c):[].concat(t),r],a=i[0],c=i.reduce((d,h)=>{const f=UT(e,h,s);return d.top=Yr(f.top,d.top),d.right=fa(f.right,d.right),d.bottom=fa(f.bottom,d.bottom),d.left=Yr(f.left,d.left),d},UT(e,a,s));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function EV(n){const{width:e,height:t}=s3(n);return{width:e,height:t}}function TV(n,e,t){const r=Lo(e),s=Ho(e),o=t==="fixed",i=ul(n,!0,o,e);let a={scrollLeft:0,scrollTop:0};const c=Mo(0);if(r||!r&&!o)if((eu(e)!=="body"||nh(s))&&(a=Zg(e)),r){const g=ul(e,!0,o,e);c.x=g.x+e.clientLeft,c.y=g.y+e.clientTop}else s&&(c.x=p1(s));const d=s&&!r&&!o?i3(s,a):Mo(0),h=i.left+a.scrollLeft-c.x-d.x,f=i.top+a.scrollTop-c.y-d.y;return{x:h,y:f,width:i.width,height:i.height}}function Hx(n){return Js(n).position==="static"}function HT(n,e){if(!Lo(n)||Js(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return Ho(n)===t&&(t=t.ownerDocument.body),t}function l3(n,e){const t=ts(n);if(Xg(n))return t;if(!Lo(n)){let s=ma(n);for(;s&&!Rc(s);){if(Qs(s)&&!Hx(s))return s;s=ma(s)}return t}let r=HT(n,e);for(;r&&mV(r)&&Hx(r);)r=HT(r,e);return r&&Rc(r)&&Hx(r)&&!u1(r)?t:r||yV(n)||t}const kV=async function(n){const e=this.getOffsetParent||l3,t=this.getDimensions,r=await t(n.floating);return{reference:TV(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function MV(n){return Js(n).direction==="rtl"}const AV={convertOffsetParentRelativeRectToViewportRelativeRect:xV,getDocumentElement:Ho,getClippingRect:IV,getOffsetParent:l3,getElementRects:kV,getClientRects:wV,getDimensions:EV,getScale:Tc,isElement:Qs,isRTL:MV};function c3(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function jV(n,e){let t=null,r;const s=Ho(n);function o(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),o();const d=n.getBoundingClientRect(),{left:h,top:f,width:g,height:y}=d;if(a||e(),!g||!y)return;const S=jp(f),v=jp(s.clientWidth-(h+g)),w=jp(s.clientHeight-(f+y)),b=jp(h),k={rootMargin:-S+"px "+-v+"px "+-w+"px "+-b+"px",threshold:Yr(0,fa(1,c))||1};let E=!0;function M(A){const R=A[0].intersectionRatio;if(R!==c){if(!E)return i();R?i(!1,R):r=setTimeout(()=>{i(!1,1e-7)},1e3)}R===1&&!c3(d,n.getBoundingClientRect())&&i(),E=!1}try{t=new IntersectionObserver(M,{...k,root:s.ownerDocument})}catch{t=new IntersectionObserver(M,k)}t.observe(n)}return i(!0),o}function RV(n,e,t,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,d=h1(n),h=s||o?[...d?Td(d):[],...Td(e)]:[];h.forEach(b=>{s&&b.addEventListener("scroll",t,{passive:!0}),o&&b.addEventListener("resize",t)});const f=d&&a?jV(d,t):null;let g=-1,y=null;i&&(y=new ResizeObserver(b=>{let[P]=b;P&&P.target===d&&y&&(y.unobserve(e),cancelAnimationFrame(g),g=requestAnimationFrame(()=>{var k;(k=y)==null||k.observe(e)})),t()}),d&&!c&&y.observe(d),y.observe(e));let S,v=c?ul(n):null;c&&w();function w(){const b=ul(n);v&&!c3(v,b)&&t(),v=b,S=requestAnimationFrame(w)}return t(),()=>{var b;h.forEach(P=>{s&&P.removeEventListener("scroll",t),o&&P.removeEventListener("resize",t)}),f==null||f(),(b=y)==null||b.disconnect(),y=null,c&&cancelAnimationFrame(S)}}const OV=hV,DV=pV,LV=cV,FV=gV,NV=uV,KT=lV,$V=fV,zV=(n,e,t)=>{const r=new Map,s={platform:AV,...t},o={...s.platform,_c:r};return aV(n,e,{...s,platform:o})};var lf=typeof document<"u"?_.useLayoutEffect:_.useEffect;function ng(n,e){if(n===e)return!0;if(typeof n!=typeof e)return!1;if(typeof n=="function"&&n.toString()===e.toString())return!0;let t,r,s;if(n&&e&&typeof n=="object"){if(Array.isArray(n)){if(t=n.length,t!==e.length)return!1;for(r=t;r--!==0;)if(!ng(n[r],e[r]))return!1;return!0}if(s=Object.keys(n),t=s.length,t!==Object.keys(e).length)return!1;for(r=t;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=t;r--!==0;){const o=s[r];if(!(o==="_owner"&&n.$$typeof)&&!ng(n[o],e[o]))return!1}return!0}return n!==n&&e!==e}function u3(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function WT(n,e){const t=u3(n);return Math.round(e*t)/t}function Kx(n){const e=_.useRef(n);return lf(()=>{e.current=n}),e}function BV(n){n===void 0&&(n={});const{placement:e="bottom",strategy:t="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:a=!0,whileElementsMounted:c,open:d}=n,[h,f]=_.useState({x:0,y:0,strategy:t,placement:e,middlewareData:{},isPositioned:!1}),[g,y]=_.useState(r);ng(g,r)||y(r);const[S,v]=_.useState(null),[w,b]=_.useState(null),P=_.useCallback(H=>{H!==A.current&&(A.current=H,v(H))},[]),k=_.useCallback(H=>{H!==R.current&&(R.current=H,b(H))},[]),E=o||S,M=i||w,A=_.useRef(null),R=_.useRef(null),D=_.useRef(h),V=c!=null,L=Kx(c),U=Kx(s),K=Kx(d),F=_.useCallback(()=>{if(!A.current||!R.current)return;const H={placement:e,strategy:t,middleware:g};U.current&&(H.platform=U.current),zV(A.current,R.current,H).then(Q=>{const ae={...Q,isPositioned:K.current!==!1};$.current&&!ng(D.current,ae)&&(D.current=ae,Yc.flushSync(()=>{f(ae)}))})},[g,e,t,U,K]);lf(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,f(H=>({...H,isPositioned:!1})))},[d]);const $=_.useRef(!1);lf(()=>($.current=!0,()=>{$.current=!1}),[]),lf(()=>{if(E&&(A.current=E),M&&(R.current=M),E&&M){if(L.current)return L.current(E,M,F);F()}},[E,M,F,L,V]);const W=_.useMemo(()=>({reference:A,floating:R,setReference:P,setFloating:k}),[P,k]),Y=_.useMemo(()=>({reference:E,floating:M}),[E,M]),Z=_.useMemo(()=>{const H={position:t,left:0,top:0};if(!Y.floating)return H;const Q=WT(Y.floating,h.x),ae=WT(Y.floating,h.y);return a?{...H,transform:"translate("+Q+"px, "+ae+"px)",...u3(Y.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:Q,top:ae}},[t,a,Y.floating,h.x,h.y]);return _.useMemo(()=>({...h,update:F,refs:W,elements:Y,floatingStyles:Z}),[h,F,W,Y,Z])}const UV=n=>{function e(t){return{}.hasOwnProperty.call(t,"current")}return{name:"arrow",options:n,fn(t){const{element:r,padding:s}=typeof n=="function"?n(t):n;return r&&e(r)?r.current!=null?KT({element:r.current,padding:s}).fn(t):{}:r?KT({element:r,padding:s}).fn(t):{}}}},HV=(n,e)=>({...OV(n),options:[n,e]}),KV=(n,e)=>({...DV(n),options:[n,e]}),WV=(n,e)=>({...$V(n),options:[n,e]}),GV=(n,e)=>({...LV(n),options:[n,e]}),VV=(n,e)=>({...FV(n),options:[n,e]}),qV=(n,e)=>({...NV(n),options:[n,e]}),YV=(n,e)=>({...UV(n),options:[n,e]});var XV="Arrow",d3=_.forwardRef((n,e)=>{const{children:t,width:r=10,height:s=5,...o}=n;return p.jsx(ut.svg,{...o,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:n.asChild?t:p.jsx("polygon",{points:"0,0 30,0 15,10"})})});d3.displayName=XV;var ZV=d3;function h3(n){const[e,t]=_.useState(void 0);return pa(()=>{if(n){t({width:n.offsetWidth,height:n.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 c=o.borderBoxSize,d=Array.isArray(c)?c[0]:c;i=d.inlineSize,a=d.blockSize}else i=n.offsetWidth,a=n.offsetHeight;t({width:i,height:a})});return r.observe(n,{box:"border-box"}),()=>r.unobserve(n)}else t(void 0)},[n]),e}var f1="Popper",[p3,Qg]=Uo(f1),[QV,f3]=p3(f1),g3=n=>{const{__scopePopper:e,children:t}=n,[r,s]=_.useState(null);return p.jsx(QV,{scope:e,anchor:r,onAnchorChange:s,children:t})};g3.displayName=f1;var m3="PopperAnchor",y3=_.forwardRef((n,e)=>{const{__scopePopper:t,virtualRef:r,...s}=n,o=f3(m3,t),i=_.useRef(null),a=Ot(e,i);return _.useEffect(()=>{o.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:p.jsx(ut.div,{...s,ref:a})});y3.displayName=m3;var g1="PopperContent",[JV,eq]=p3(g1),S3=_.forwardRef((n,e)=>{var Me,xe,Ie,ze,Ze,Xt;const{__scopePopper:t,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:c=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:f="partial",hideWhenDetached:g=!1,updatePositionStrategy:y="optimized",onPlaced:S,...v}=n,w=f3(g1,t),[b,P]=_.useState(null),k=Ot(e,yt=>P(yt)),[E,M]=_.useState(null),A=h3(E),R=(A==null?void 0:A.width)??0,D=(A==null?void 0:A.height)??0,V=r+(o!=="center"?"-"+o:""),L=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},U=Array.isArray(d)?d:[d],K=U.length>0,F={padding:L,boundary:U.filter(nq),altBoundary:K},{refs:$,floatingStyles:W,placement:Y,isPositioned:Z,middlewareData:H}=BV({strategy:"fixed",placement:V,whileElementsMounted:(...yt)=>RV(...yt,{animationFrame:y==="always"}),elements:{reference:w.anchor},middleware:[HV({mainAxis:s+D,alignmentAxis:i}),c&&KV({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?WV():void 0,...F}),c&&GV({...F}),VV({...F,apply:({elements:yt,rects:zt,availableWidth:_t,availableHeight:wt})=>{const{width:hr,height:pr}=zt.reference,fr=yt.floating.style;fr.setProperty("--radix-popper-available-width",`${_t}px`),fr.setProperty("--radix-popper-available-height",`${wt}px`),fr.setProperty("--radix-popper-anchor-width",`${hr}px`),fr.setProperty("--radix-popper-anchor-height",`${pr}px`)}}),E&&YV({element:E,padding:a}),rq({arrowWidth:R,arrowHeight:D}),g&&qV({strategy:"referenceHidden",...F})]}),[Q,ae]=w3(Y),B=An(S);pa(()=>{Z&&(B==null||B())},[Z,B]);const ne=(Me=H.arrow)==null?void 0:Me.x,he=(xe=H.arrow)==null?void 0:xe.y,Pe=((Ie=H.arrow)==null?void 0:Ie.centerOffset)!==0,[ue,Fe]=_.useState();return pa(()=>{b&&Fe(window.getComputedStyle(b).zIndex)},[b]),p.jsx("div",{ref:$.setFloating,"data-radix-popper-content-wrapper":"",style:{...W,transform:Z?W.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ue,"--radix-popper-transform-origin":[(ze=H.transformOrigin)==null?void 0:ze.x,(Ze=H.transformOrigin)==null?void 0:Ze.y].join(" "),...((Xt=H.hide)==null?void 0:Xt.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:p.jsx(JV,{scope:t,placedSide:Q,onArrowChange:M,arrowX:ne,arrowY:he,shouldHideArrow:Pe,children:p.jsx(ut.div,{"data-side":Q,"data-align":ae,...v,ref:k,style:{...v.style,animation:Z?void 0:"none"}})})})});S3.displayName=g1;var v3="PopperArrow",tq={top:"bottom",right:"left",bottom:"top",left:"right"},x3=_.forwardRef(function(e,t){const{__scopePopper:r,...s}=e,o=eq(v3,r),i=tq[o.placedSide];return p.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:p.jsx(ZV,{...s,ref:t,style:{...s.style,display:"block"}})})});x3.displayName=v3;function nq(n){return n!==null}var rq=n=>({name:"transformOrigin",options:n,fn(e){var w,b,P;const{placement:t,rects:r,middlewareData:s}=e,i=((w=s.arrow)==null?void 0:w.centerOffset)!==0,a=i?0:n.arrowWidth,c=i?0:n.arrowHeight,[d,h]=w3(t),f={start:"0%",center:"50%",end:"100%"}[h],g=(((b=s.arrow)==null?void 0:b.x)??0)+a/2,y=(((P=s.arrow)==null?void 0:P.y)??0)+c/2;let S="",v="";return d==="bottom"?(S=i?f:`${g}px`,v=`${-c}px`):d==="top"?(S=i?f:`${g}px`,v=`${r.floating.height+c}px`):d==="right"?(S=`${-c}px`,v=i?f:`${y}px`):d==="left"&&(S=`${r.floating.width+c}px`,v=i?f:`${y}px`),{data:{x:S,y:v}}}});function w3(n){const[e,t="center"]=n.split("-");return[e,t]}var m1=g3,y1=y3,b3=S3,P3=x3,sq="Portal",rh=_.forwardRef((n,e)=>{var a;const{container:t,...r}=n,[s,o]=_.useState(!1);pa(()=>o(!0),[]);const i=t||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?JU.createPortal(p.jsx(ut.div,{...r,ref:e}),i):null});rh.displayName=sq;function oq(n,e){return _.useReducer((t,r)=>e[t][r]??t,n)}var no=n=>{const{present:e,children:t}=n,r=iq(e),s=typeof t=="function"?t({present:r.isPresent}):_.Children.only(t),o=Ot(r.ref,aq(s));return typeof t=="function"||r.isPresent?_.cloneElement(s,{ref:o}):null};no.displayName="Presence";function iq(n){const[e,t]=_.useState(),r=_.useRef({}),s=_.useRef(n),o=_.useRef("none"),i=n?"mounted":"unmounted",[a,c]=oq(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return _.useEffect(()=>{const d=Rp(r.current);o.current=a==="mounted"?d:"none"},[a]),pa(()=>{const d=r.current,h=s.current;if(h!==n){const g=o.current,y=Rp(d);n?c("MOUNT"):y==="none"||(d==null?void 0:d.display)==="none"?c("UNMOUNT"):c(h&&g!==y?"ANIMATION_OUT":"UNMOUNT"),s.current=n}},[n,c]),pa(()=>{if(e){let d;const h=e.ownerDocument.defaultView??window,f=y=>{const v=Rp(r.current).includes(y.animationName);if(y.target===e&&v&&(c("ANIMATION_END"),!s.current)){const w=e.style.animationFillMode;e.style.animationFillMode="forwards",d=h.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=w)})}},g=y=>{y.target===e&&(o.current=Rp(r.current))};return e.addEventListener("animationstart",g),e.addEventListener("animationcancel",f),e.addEventListener("animationend",f),()=>{h.clearTimeout(d),e.removeEventListener("animationstart",g),e.removeEventListener("animationcancel",f),e.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[e,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:_.useCallback(d=>{d&&(r.current=getComputedStyle(d)),t(d)},[])}}function Rp(n){return(n==null?void 0:n.animationName)||"none"}function aq(n){var r,s;let e=(r=Object.getOwnPropertyDescriptor(n.props,"ref"))==null?void 0:r.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=(s=Object.getOwnPropertyDescriptor(n,"ref"))==null?void 0:s.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}function Ca({prop:n,defaultProp:e,onChange:t=()=>{}}){const[r,s]=lq({defaultProp:e,onChange:t}),o=n!==void 0,i=o?n:r,a=An(t),c=_.useCallback(d=>{if(o){const f=typeof d=="function"?d(n):d;f!==n&&a(f)}else s(d)},[o,n,s,a]);return[i,c]}function lq({defaultProp:n,onChange:e}){const t=_.useState(n),[r]=t,s=_.useRef(r),o=An(e);return _.useEffect(()=>{s.current!==r&&(o(r),s.current=r)},[r,s,o]),t}var Wx="rovingFocusGroup.onEntryFocus",cq={bubbles:!1,cancelable:!0},Jg="RovingFocusGroup",[d0,C3,uq]=Vg(Jg),[dq,_3]=Uo(Jg,[uq]),[hq,pq]=dq(Jg),I3=_.forwardRef((n,e)=>p.jsx(d0.Provider,{scope:n.__scopeRovingFocusGroup,children:p.jsx(d0.Slot,{scope:n.__scopeRovingFocusGroup,children:p.jsx(fq,{...n,ref:e})})}));I3.displayName=Jg;var fq=_.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:s=!1,dir:o,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...f}=n,g=_.useRef(null),y=Ot(e,g),S=o1(o),[v=null,w]=Ca({prop:i,defaultProp:a,onChange:c}),[b,P]=_.useState(!1),k=An(d),E=C3(t),M=_.useRef(!1),[A,R]=_.useState(0);return _.useEffect(()=>{const D=g.current;if(D)return D.addEventListener(Wx,k),()=>D.removeEventListener(Wx,k)},[k]),p.jsx(hq,{scope:t,orientation:r,dir:S,loop:s,currentTabStopId:v,onItemFocus:_.useCallback(D=>w(D),[w]),onItemShiftTab:_.useCallback(()=>P(!0),[]),onFocusableItemAdd:_.useCallback(()=>R(D=>D+1),[]),onFocusableItemRemove:_.useCallback(()=>R(D=>D-1),[]),children:p.jsx(ut.div,{tabIndex:b||A===0?-1:0,"data-orientation":r,...f,ref:y,style:{outline:"none",...n.style},onMouseDown:Ae(n.onMouseDown,()=>{M.current=!0}),onFocus:Ae(n.onFocus,D=>{const V=!M.current;if(D.target===D.currentTarget&&V&&!b){const L=new CustomEvent(Wx,cq);if(D.currentTarget.dispatchEvent(L),!L.defaultPrevented){const U=E().filter(Y=>Y.focusable),K=U.find(Y=>Y.active),F=U.find(Y=>Y.id===v),W=[K,F,...U].filter(Boolean).map(Y=>Y.ref.current);k3(W,h)}}M.current=!1}),onBlur:Ae(n.onBlur,()=>P(!1))})})}),E3="RovingFocusGroupItem",T3=_.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:s=!1,tabStopId:o,...i}=n,a=yi(),c=o||a,d=pq(E3,t),h=d.currentTabStopId===c,f=C3(t),{onFocusableItemAdd:g,onFocusableItemRemove:y}=d;return _.useEffect(()=>{if(r)return g(),()=>y()},[r,g,y]),p.jsx(d0.ItemSlot,{scope:t,id:c,focusable:r,active:s,children:p.jsx(ut.span,{tabIndex:h?0:-1,"data-orientation":d.orientation,...i,ref:e,onMouseDown:Ae(n.onMouseDown,S=>{r?d.onItemFocus(c):S.preventDefault()}),onFocus:Ae(n.onFocus,()=>d.onItemFocus(c)),onKeyDown:Ae(n.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){d.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const v=yq(S,d.orientation,d.dir);if(v!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let b=f().filter(P=>P.focusable).map(P=>P.ref.current);if(v==="last")b.reverse();else if(v==="prev"||v==="next"){v==="prev"&&b.reverse();const P=b.indexOf(S.currentTarget);b=d.loop?Sq(b,P+1):b.slice(P+1)}setTimeout(()=>k3(b))}})})})});T3.displayName=E3;var gq={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function mq(n,e){return e!=="rtl"?n:n==="ArrowLeft"?"ArrowRight":n==="ArrowRight"?"ArrowLeft":n}function yq(n,e,t){const r=mq(n.key,t);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return gq[r]}function k3(n,e=!1){const t=document.activeElement;for(const r of n)if(r===t||(r.focus({preventScroll:e}),document.activeElement!==t))return}function Sq(n,e){return n.map((t,r)=>n[(e+r)%n.length])}var vq=I3,xq=T3,wq=function(n){if(typeof document>"u")return null;var e=Array.isArray(n)?n[0]:n;return e.ownerDocument.body},cc=new WeakMap,Op=new WeakMap,Dp={},Gx=0,M3=function(n){return n&&(n.host||M3(n.parentNode))},bq=function(n,e){return e.map(function(t){if(n.contains(t))return t;var r=M3(t);return r&&n.contains(r)?r:(console.error("aria-hidden",t,"in not contained inside",n,". Doing nothing"),null)}).filter(function(t){return!!t})},Pq=function(n,e,t,r){var s=bq(e,Array.isArray(n)?n:[n]);Dp[t]||(Dp[t]=new WeakMap);var o=Dp[t],i=[],a=new Set,c=new Set(s),d=function(f){!f||a.has(f)||(a.add(f),d(f.parentNode))};s.forEach(d);var h=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(g){if(a.has(g))h(g);else try{var y=g.getAttribute(r),S=y!==null&&y!=="false",v=(cc.get(g)||0)+1,w=(o.get(g)||0)+1;cc.set(g,v),o.set(g,w),i.push(g),v===1&&S&&Op.set(g,!0),w===1&&g.setAttribute(t,"true"),S||g.setAttribute(r,"true")}catch(b){console.error("aria-hidden: cannot operate on ",g,b)}})};return h(e),a.clear(),Gx++,function(){i.forEach(function(f){var g=cc.get(f)-1,y=o.get(f)-1;cc.set(f,g),o.set(f,y),g||(Op.has(f)||f.removeAttribute(r),Op.delete(f)),y||f.removeAttribute(t)}),Gx--,Gx||(cc=new WeakMap,cc=new WeakMap,Op=new WeakMap,Dp={})}},S1=function(n,e,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(n)?n:[n]),s=wq(n);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),Pq(r,s,t,"aria-hidden")):function(){return null}},Po=function(){return Po=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},Po.apply(this,arguments)};function A3(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(n);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(n,r[s])&&(t[r[s]]=n[r[s]]);return t}function Cq(n,e,t){if(t||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 n.concat(o||Array.prototype.slice.call(e))}var cf="right-scroll-bar-position",uf="width-before-scroll-bar",_q="with-scroll-bars-hidden",Iq="--removed-body-scroll-bar-size";function Vx(n,e){return typeof n=="function"?n(e):n&&(n.current=e),n}function Eq(n,e){var t=_.useState(function(){return{value:n,callback:e,facade:{get current(){return t.value},set current(r){var s=t.value;s!==r&&(t.value=r,t.callback(r,s))}}}})[0];return t.callback=e,t.facade}var Tq=typeof window<"u"?_.useLayoutEffect:_.useEffect,GT=new WeakMap;function kq(n,e){var t=Eq(null,function(r){return n.forEach(function(s){return Vx(s,r)})});return Tq(function(){var r=GT.get(t);if(r){var s=new Set(r),o=new Set(n),i=t.current;s.forEach(function(a){o.has(a)||Vx(a,null)}),o.forEach(function(a){s.has(a)||Vx(a,i)})}GT.set(t,n)},[n]),t}function Mq(n){return n}function Aq(n,e){e===void 0&&(e=Mq);var t=[],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 t.length?t[t.length-1]:n},useMedium:function(o){var i=e(o,r);return t.push(i),function(){t=t.filter(function(a){return a!==i})}},assignSyncMedium:function(o){for(r=!0;t.length;){var i=t;t=[],i.forEach(o)}t={push:function(a){return o(a)},filter:function(){return t}}},assignMedium:function(o){r=!0;var i=[];if(t.length){var a=t;t=[],a.forEach(o),i=t}var c=function(){var h=i;i=[],h.forEach(o)},d=function(){return Promise.resolve().then(c)};d(),t={push:function(h){i.push(h),d()},filter:function(h){return i=i.filter(h),t}}}};return s}function jq(n){n===void 0&&(n={});var e=Aq(null);return e.options=Po({async:!0,ssr:!1},n),e}var j3=function(n){var e=n.sideCar,t=A3(n,["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 _.createElement(r,Po({},t))};j3.isSideCarExport=!0;function Rq(n,e){return n.useMedium(e),j3}var R3=jq(),qx=function(){},em=_.forwardRef(function(n,e){var t=_.useRef(null),r=_.useState({onScrollCapture:qx,onWheelCapture:qx,onTouchMoveCapture:qx}),s=r[0],o=r[1],i=n.forwardProps,a=n.children,c=n.className,d=n.removeScrollBar,h=n.enabled,f=n.shards,g=n.sideCar,y=n.noIsolation,S=n.inert,v=n.allowPinchZoom,w=n.as,b=w===void 0?"div":w,P=n.gapMode,k=A3(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=g,M=kq([t,e]),A=Po(Po({},k),s);return _.createElement(_.Fragment,null,h&&_.createElement(E,{sideCar:R3,removeScrollBar:d,shards:f,noIsolation:y,inert:S,setCallbacks:o,allowPinchZoom:!!v,lockRef:t,gapMode:P}),i?_.cloneElement(_.Children.only(a),Po(Po({},A),{ref:M})):_.createElement(b,Po({},A,{className:c,ref:M}),a))});em.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};em.classNames={fullWidth:uf,zeroRight:cf};var Oq=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Dq(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var e=Oq();return e&&n.setAttribute("nonce",e),n}function Lq(n,e){n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}function Fq(n){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(n)}var Nq=function(){var n=0,e=null;return{add:function(t){n==0&&(e=Dq())&&(Lq(e,t),Fq(e)),n++},remove:function(){n--,!n&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},$q=function(){var n=Nq();return function(e,t){_.useEffect(function(){return n.add(e),function(){n.remove()}},[e&&t])}},O3=function(){var n=$q(),e=function(t){var r=t.styles,s=t.dynamic;return n(r,s),null};return e},zq={left:0,top:0,right:0,gap:0},Yx=function(n){return parseInt(n||"",10)||0},Bq=function(n){var e=window.getComputedStyle(document.body),t=e[n==="padding"?"paddingLeft":"marginLeft"],r=e[n==="padding"?"paddingTop":"marginTop"],s=e[n==="padding"?"paddingRight":"marginRight"];return[Yx(t),Yx(r),Yx(s)]},Uq=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return zq;var e=Bq(n),t=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-t+e[2]-e[0])}},Hq=O3(),kc="data-scroll-locked",Kq=function(n,e,t,r){var s=n.left,o=n.top,i=n.right,a=n.gap;return t===void 0&&(t="margin"),`
|
|
207
|
+
.`.concat(_q,` {
|
|
208
|
+
overflow: hidden `).concat(r,`;
|
|
209
|
+
padding-right: `).concat(a,"px ").concat(r,`;
|
|
210
|
+
}
|
|
211
|
+
body[`).concat(kc,`] {
|
|
212
|
+
overflow: hidden `).concat(r,`;
|
|
213
|
+
overscroll-behavior: contain;
|
|
214
|
+
`).concat([e&&"position: relative ".concat(r,";"),t==="margin"&&`
|
|
215
|
+
padding-left: `.concat(s,`px;
|
|
216
|
+
padding-top: `).concat(o,`px;
|
|
217
|
+
padding-right: `).concat(i,`px;
|
|
218
|
+
margin-left:0;
|
|
219
|
+
margin-top:0;
|
|
220
|
+
margin-right: `).concat(a,"px ").concat(r,`;
|
|
221
|
+
`),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.`).concat(cf,` {
|
|
225
|
+
right: `).concat(a,"px ").concat(r,`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.`).concat(uf,` {
|
|
229
|
+
margin-right: `).concat(a,"px ").concat(r,`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.`).concat(cf," .").concat(cf,` {
|
|
233
|
+
right: 0 `).concat(r,`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.`).concat(uf," .").concat(uf,` {
|
|
237
|
+
margin-right: 0 `).concat(r,`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
body[`).concat(kc,`] {
|
|
241
|
+
`).concat(Iq,": ").concat(a,`px;
|
|
242
|
+
}
|
|
243
|
+
`)},VT=function(){var n=parseInt(document.body.getAttribute(kc)||"0",10);return isFinite(n)?n:0},Wq=function(){_.useEffect(function(){return document.body.setAttribute(kc,(VT()+1).toString()),function(){var n=VT()-1;n<=0?document.body.removeAttribute(kc):document.body.setAttribute(kc,n.toString())}},[])},Gq=function(n){var e=n.noRelative,t=n.noImportant,r=n.gapMode,s=r===void 0?"margin":r;Wq();var o=_.useMemo(function(){return Uq(s)},[s]);return _.createElement(Hq,{styles:Kq(o,!e,s,t?"":"!important")})},h0=!1;if(typeof window<"u")try{var Lp=Object.defineProperty({},"passive",{get:function(){return h0=!0,!0}});window.addEventListener("test",Lp,Lp),window.removeEventListener("test",Lp,Lp)}catch{h0=!1}var uc=h0?{passive:!1}:!1,Vq=function(n){return n.tagName==="TEXTAREA"},D3=function(n,e){if(!(n instanceof Element))return!1;var t=window.getComputedStyle(n);return t[e]!=="hidden"&&!(t.overflowY===t.overflowX&&!Vq(n)&&t[e]==="visible")},qq=function(n){return D3(n,"overflowY")},Yq=function(n){return D3(n,"overflowX")},qT=function(n,e){var t=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=L3(n,r);if(s){var o=F3(n,r),i=o[1],a=o[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},Xq=function(n){var e=n.scrollTop,t=n.scrollHeight,r=n.clientHeight;return[e,t,r]},Zq=function(n){var e=n.scrollLeft,t=n.scrollWidth,r=n.clientWidth;return[e,t,r]},L3=function(n,e){return n==="v"?qq(e):Yq(e)},F3=function(n,e){return n==="v"?Xq(e):Zq(e)},Qq=function(n,e){return n==="h"&&e==="rtl"?-1:1},Jq=function(n,e,t,r,s){var o=Qq(n,window.getComputedStyle(e).direction),i=o*r,a=t.target,c=e.contains(a),d=!1,h=i>0,f=0,g=0;do{var y=F3(n,a),S=y[0],v=y[1],w=y[2],b=v-w-o*S;(S||b)&&L3(n,a)&&(f+=b,g+=S),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!c&&a!==document.body||c&&(e.contains(a)||e===a));return(h&&Math.abs(f)<1||!h&&Math.abs(g)<1)&&(d=!0),d},Fp=function(n){return"changedTouches"in n?[n.changedTouches[0].clientX,n.changedTouches[0].clientY]:[0,0]},YT=function(n){return[n.deltaX,n.deltaY]},XT=function(n){return n&&"current"in n?n.current:n},eY=function(n,e){return n[0]===e[0]&&n[1]===e[1]},tY=function(n){return`
|
|
244
|
+
.block-interactivity-`.concat(n,` {pointer-events: none;}
|
|
245
|
+
.allow-interactivity-`).concat(n,` {pointer-events: all;}
|
|
246
|
+
`)},nY=0,dc=[];function rY(n){var e=_.useRef([]),t=_.useRef([0,0]),r=_.useRef(),s=_.useState(nY++)[0],o=_.useState(O3)[0],i=_.useRef(n);_.useEffect(function(){i.current=n},[n]),_.useEffect(function(){if(n.inert){document.body.classList.add("block-interactivity-".concat(s));var v=Cq([n.lockRef.current],(n.shards||[]).map(XT),!0).filter(Boolean);return v.forEach(function(w){return w.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),v.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(s))})}}},[n.inert,n.lockRef.current,n.shards]);var a=_.useCallback(function(v,w){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!i.current.allowPinchZoom;var b=Fp(v),P=t.current,k="deltaX"in v?v.deltaX:P[0]-b[0],E="deltaY"in v?v.deltaY:P[1]-b[1],M,A=v.target,R=Math.abs(k)>Math.abs(E)?"h":"v";if("touches"in v&&R==="h"&&A.type==="range")return!1;var D=qT(R,A);if(!D)return!0;if(D?M=R:(M=R==="v"?"h":"v",D=qT(R,A)),!D)return!1;if(!r.current&&"changedTouches"in v&&(k||E)&&(r.current=M),!M)return!0;var V=r.current||M;return Jq(V,w,v,V==="h"?k:E)},[]),c=_.useCallback(function(v){var w=v;if(!(!dc.length||dc[dc.length-1]!==o)){var b="deltaY"in w?YT(w):Fp(w),P=e.current.filter(function(M){return M.name===w.type&&(M.target===w.target||w.target===M.shadowParent)&&eY(M.delta,b)})[0];if(P&&P.should){w.cancelable&&w.preventDefault();return}if(!P){var k=(i.current.shards||[]).map(XT).filter(Boolean).filter(function(M){return M.contains(w.target)}),E=k.length>0?a(w,k[0]):!i.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),d=_.useCallback(function(v,w,b,P){var k={name:v,delta:w,target:b,should:P,shadowParent:sY(b)};e.current.push(k),setTimeout(function(){e.current=e.current.filter(function(E){return E!==k})},1)},[]),h=_.useCallback(function(v){t.current=Fp(v),r.current=void 0},[]),f=_.useCallback(function(v){d(v.type,YT(v),v.target,a(v,n.lockRef.current))},[]),g=_.useCallback(function(v){d(v.type,Fp(v),v.target,a(v,n.lockRef.current))},[]);_.useEffect(function(){return dc.push(o),n.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:g}),document.addEventListener("wheel",c,uc),document.addEventListener("touchmove",c,uc),document.addEventListener("touchstart",h,uc),function(){dc=dc.filter(function(v){return v!==o}),document.removeEventListener("wheel",c,uc),document.removeEventListener("touchmove",c,uc),document.removeEventListener("touchstart",h,uc)}},[]);var y=n.removeScrollBar,S=n.inert;return _.createElement(_.Fragment,null,S?_.createElement(o,{styles:tY(s)}):null,y?_.createElement(Gq,{gapMode:n.gapMode}):null)}function sY(n){for(var e=null;n!==null;)n instanceof ShadowRoot&&(e=n.host,n=n.host),n=n.parentNode;return e}const oY=Rq(R3,rY);var tm=_.forwardRef(function(n,e){return _.createElement(em,Po({},n,{ref:e,sideCar:oY}))});tm.classNames=em.classNames;var p0=["Enter"," "],iY=["ArrowDown","PageUp","Home"],N3=["ArrowUp","PageDown","End"],aY=[...iY,...N3],lY={ltr:[...p0,"ArrowRight"],rtl:[...p0,"ArrowLeft"]},cY={ltr:["ArrowLeft"],rtl:["ArrowRight"]},sh="Menu",[kd,uY,dY]=Vg(sh),[xl,nm]=Uo(sh,[dY,Qg,_3]),oh=Qg(),$3=_3(),[z3,_a]=xl(sh),[hY,ih]=xl(sh),B3=n=>{const{__scopeMenu:e,open:t=!1,children:r,dir:s,onOpenChange:o,modal:i=!0}=n,a=oh(e),[c,d]=_.useState(null),h=_.useRef(!1),f=An(o),g=o1(s);return _.useEffect(()=>{const y=()=>{h.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>h.current=!1;return document.addEventListener("keydown",y,{capture:!0}),()=>{document.removeEventListener("keydown",y,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),p.jsx(m1,{...a,children:p.jsx(z3,{scope:e,open:t,onOpenChange:f,content:c,onContentChange:d,children:p.jsx(hY,{scope:e,onClose:_.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:g,modal:i,children:r})})})};B3.displayName=sh;var pY="MenuAnchor",v1=_.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=oh(t);return p.jsx(y1,{...s,...r,ref:e})});v1.displayName=pY;var x1="MenuPortal",[fY,U3]=xl(x1,{forceMount:void 0}),H3=n=>{const{__scopeMenu:e,forceMount:t,children:r,container:s}=n,o=_a(x1,e);return p.jsx(fY,{scope:e,forceMount:t,children:p.jsx(no,{present:t||o.open,children:p.jsx(rh,{asChild:!0,container:s,children:r})})})};H3.displayName=x1;var _s="MenuContent",[gY,w1]=xl(_s),K3=_.forwardRef((n,e)=>{const t=U3(_s,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,o=_a(_s,n.__scopeMenu),i=ih(_s,n.__scopeMenu);return p.jsx(kd.Provider,{scope:n.__scopeMenu,children:p.jsx(no,{present:r||o.open,children:p.jsx(kd.Slot,{scope:n.__scopeMenu,children:i.modal?p.jsx(mY,{...s,ref:e}):p.jsx(yY,{...s,ref:e})})})})}),mY=_.forwardRef((n,e)=>{const t=_a(_s,n.__scopeMenu),r=_.useRef(null),s=Ot(e,r);return _.useEffect(()=>{const o=r.current;if(o)return S1(o)},[]),p.jsx(b1,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:Ae(n.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),yY=_.forwardRef((n,e)=>{const t=_a(_s,n.__scopeMenu);return p.jsx(b1,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),b1=_.forwardRef((n,e)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:f,onInteractOutside:g,onDismiss:y,disableOutsideScroll:S,...v}=n,w=_a(_s,t),b=ih(_s,t),P=oh(t),k=$3(t),E=uY(t),[M,A]=_.useState(null),R=_.useRef(null),D=Ot(e,R,w.onContentChange),V=_.useRef(0),L=_.useRef(""),U=_.useRef(0),K=_.useRef(null),F=_.useRef("right"),$=_.useRef(0),W=S?tm:_.Fragment,Y=S?{as:cl,allowPinchZoom:!0}:void 0,Z=Q=>{var Me,xe;const ae=L.current+Q,B=E().filter(Ie=>!Ie.disabled),ne=document.activeElement,he=(Me=B.find(Ie=>Ie.ref.current===ne))==null?void 0:Me.textValue,Pe=B.map(Ie=>Ie.textValue),ue=kY(Pe,ae,he),Fe=(xe=B.find(Ie=>Ie.textValue===ue))==null?void 0:xe.ref.current;(function Ie(ze){L.current=ze,window.clearTimeout(V.current),ze!==""&&(V.current=window.setTimeout(()=>Ie(""),1e3))})(ae),Fe&&setTimeout(()=>Fe.focus())};_.useEffect(()=>()=>window.clearTimeout(V.current),[]),i1();const H=_.useCallback(Q=>{var B,ne;return F.current===((B=K.current)==null?void 0:B.side)&&AY(Q,(ne=K.current)==null?void 0:ne.area)},[]);return p.jsx(gY,{scope:t,searchRef:L,onItemEnter:_.useCallback(Q=>{H(Q)&&Q.preventDefault()},[H]),onItemLeave:_.useCallback(Q=>{var ae;H(Q)||((ae=R.current)==null||ae.focus(),A(null))},[H]),onTriggerLeave:_.useCallback(Q=>{H(Q)&&Q.preventDefault()},[H]),pointerGraceTimerRef:U,onPointerGraceIntentChange:_.useCallback(Q=>{K.current=Q},[]),children:p.jsx(W,{...Y,children:p.jsx(qg,{asChild:!0,trapped:s,onMountAutoFocus:Ae(o,Q=>{var ae;Q.preventDefault(),(ae=R.current)==null||ae.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:p.jsx(th,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:f,onInteractOutside:g,onDismiss:y,children:p.jsx(vq,{asChild:!0,...k,dir:b.dir,orientation:"vertical",loop:r,currentTabStopId:M,onCurrentTabStopIdChange:A,onEntryFocus:Ae(c,Q=>{b.isUsingKeyboardRef.current||Q.preventDefault()}),preventScrollOnEntryFocus:!0,children:p.jsx(b3,{role:"menu","aria-orientation":"vertical","data-state":aL(w.open),"data-radix-menu-content":"",dir:b.dir,...P,...v,ref:D,style:{outline:"none",...v.style},onKeyDown:Ae(v.onKeyDown,Q=>{const B=Q.target.closest("[data-radix-menu-content]")===Q.currentTarget,ne=Q.ctrlKey||Q.altKey||Q.metaKey,he=Q.key.length===1;B&&(Q.key==="Tab"&&Q.preventDefault(),!ne&&he&&Z(Q.key));const Pe=R.current;if(Q.target!==Pe||!aY.includes(Q.key))return;Q.preventDefault();const Fe=E().filter(Me=>!Me.disabled).map(Me=>Me.ref.current);N3.includes(Q.key)&&Fe.reverse(),EY(Fe)}),onBlur:Ae(n.onBlur,Q=>{Q.currentTarget.contains(Q.target)||(window.clearTimeout(V.current),L.current="")}),onPointerMove:Ae(n.onPointerMove,Md(Q=>{const ae=Q.target,B=$.current!==Q.clientX;if(Q.currentTarget.contains(ae)&&B){const ne=Q.clientX>$.current?"right":"left";F.current=ne,$.current=Q.clientX}}))})})})})})})});K3.displayName=_s;var SY="MenuGroup",P1=_.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return p.jsx(ut.div,{role:"group",...r,ref:e})});P1.displayName=SY;var vY="MenuLabel",W3=_.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return p.jsx(ut.div,{...r,ref:e})});W3.displayName=vY;var rg="MenuItem",ZT="menu.itemSelect",rm=_.forwardRef((n,e)=>{const{disabled:t=!1,onSelect:r,...s}=n,o=_.useRef(null),i=ih(rg,n.__scopeMenu),a=w1(rg,n.__scopeMenu),c=Ot(e,o),d=_.useRef(!1),h=()=>{const f=o.current;if(!t&&f){const g=new CustomEvent(ZT,{bubbles:!0,cancelable:!0});f.addEventListener(ZT,y=>r==null?void 0:r(y),{once:!0}),s1(f,g),g.defaultPrevented?d.current=!1:i.onClose()}};return p.jsx(G3,{...s,ref:c,disabled:t,onClick:Ae(n.onClick,h),onPointerDown:f=>{var g;(g=n.onPointerDown)==null||g.call(n,f),d.current=!0},onPointerUp:Ae(n.onPointerUp,f=>{var g;d.current||(g=f.currentTarget)==null||g.click()}),onKeyDown:Ae(n.onKeyDown,f=>{const g=a.searchRef.current!=="";t||g&&f.key===" "||p0.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});rm.displayName=rg;var G3=_.forwardRef((n,e)=>{const{__scopeMenu:t,disabled:r=!1,textValue:s,...o}=n,i=w1(rg,t),a=$3(t),c=_.useRef(null),d=Ot(e,c),[h,f]=_.useState(!1),[g,y]=_.useState("");return _.useEffect(()=>{const S=c.current;S&&y((S.textContent??"").trim())},[o.children]),p.jsx(kd.ItemSlot,{scope:t,disabled:r,textValue:s??g,children:p.jsx(xq,{asChild:!0,...a,focusable:!r,children:p.jsx(ut.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...o,ref:d,onPointerMove:Ae(n.onPointerMove,Md(S=>{r?i.onItemLeave(S):(i.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ae(n.onPointerLeave,Md(S=>i.onItemLeave(S))),onFocus:Ae(n.onFocus,()=>f(!0)),onBlur:Ae(n.onBlur,()=>f(!1))})})})}),xY="MenuCheckboxItem",V3=_.forwardRef((n,e)=>{const{checked:t=!1,onCheckedChange:r,...s}=n;return p.jsx(Q3,{scope:n.__scopeMenu,checked:t,children:p.jsx(rm,{role:"menuitemcheckbox","aria-checked":sg(t)?"mixed":t,...s,ref:e,"data-state":I1(t),onSelect:Ae(s.onSelect,()=>r==null?void 0:r(sg(t)?!0:!t),{checkForDefaultPrevented:!1})})})});V3.displayName=xY;var q3="MenuRadioGroup",[wY,bY]=xl(q3,{value:void 0,onValueChange:()=>{}}),Y3=_.forwardRef((n,e)=>{const{value:t,onValueChange:r,...s}=n,o=An(r);return p.jsx(wY,{scope:n.__scopeMenu,value:t,onValueChange:o,children:p.jsx(P1,{...s,ref:e})})});Y3.displayName=q3;var X3="MenuRadioItem",Z3=_.forwardRef((n,e)=>{const{value:t,...r}=n,s=bY(X3,n.__scopeMenu),o=t===s.value;return p.jsx(Q3,{scope:n.__scopeMenu,checked:o,children:p.jsx(rm,{role:"menuitemradio","aria-checked":o,...r,ref:e,"data-state":I1(o),onSelect:Ae(r.onSelect,()=>{var i;return(i=s.onValueChange)==null?void 0:i.call(s,t)},{checkForDefaultPrevented:!1})})})});Z3.displayName=X3;var C1="MenuItemIndicator",[Q3,PY]=xl(C1,{checked:!1}),J3=_.forwardRef((n,e)=>{const{__scopeMenu:t,forceMount:r,...s}=n,o=PY(C1,t);return p.jsx(no,{present:r||sg(o.checked)||o.checked===!0,children:p.jsx(ut.span,{...s,ref:e,"data-state":I1(o.checked)})})});J3.displayName=C1;var CY="MenuSeparator",eL=_.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return p.jsx(ut.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});eL.displayName=CY;var _Y="MenuArrow",tL=_.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=oh(t);return p.jsx(P3,{...s,...r,ref:e})});tL.displayName=_Y;var _1="MenuSub",[IY,nL]=xl(_1),rL=n=>{const{__scopeMenu:e,children:t,open:r=!1,onOpenChange:s}=n,o=_a(_1,e),i=oh(e),[a,c]=_.useState(null),[d,h]=_.useState(null),f=An(s);return _.useEffect(()=>(o.open===!1&&f(!1),()=>f(!1)),[o.open,f]),p.jsx(m1,{...i,children:p.jsx(z3,{scope:e,open:r,onOpenChange:f,content:d,onContentChange:h,children:p.jsx(IY,{scope:e,contentId:yi(),triggerId:yi(),trigger:a,onTriggerChange:c,children:t})})})};rL.displayName=_1;var sd="MenuSubTrigger",sL=_.forwardRef((n,e)=>{const t=_a(sd,n.__scopeMenu),r=ih(sd,n.__scopeMenu),s=nL(sd,n.__scopeMenu),o=w1(sd,n.__scopeMenu),i=_.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=o,d={__scopeMenu:n.__scopeMenu},h=_.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return _.useEffect(()=>h,[h]),_.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),p.jsx(v1,{asChild:!0,...d,children:p.jsx(G3,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":s.contentId,"data-state":aL(t.open),...n,ref:Gg(e,s.onTriggerChange),onClick:f=>{var g;(g=n.onClick)==null||g.call(n,f),!(n.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:Ae(n.onPointerMove,Md(f=>{o.onItemEnter(f),!f.defaultPrevented&&!n.disabled&&!t.open&&!i.current&&(o.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),h()},100))})),onPointerLeave:Ae(n.onPointerLeave,Md(f=>{var y,S;h();const g=(y=t.content)==null?void 0:y.getBoundingClientRect();if(g){const v=(S=t.content)==null?void 0:S.dataset.side,w=v==="right",b=w?-5:5,P=g[w?"left":"right"],k=g[w?"right":"left"];o.onPointerGraceIntentChange({area:[{x:f.clientX+b,y:f.clientY},{x:P,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:P,y:g.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>o.onPointerGraceIntentChange(null),300)}else{if(o.onTriggerLeave(f),f.defaultPrevented)return;o.onPointerGraceIntentChange(null)}})),onKeyDown:Ae(n.onKeyDown,f=>{var y;const g=o.searchRef.current!=="";n.disabled||g&&f.key===" "||lY[r.dir].includes(f.key)&&(t.onOpenChange(!0),(y=t.content)==null||y.focus(),f.preventDefault())})})})});sL.displayName=sd;var oL="MenuSubContent",iL=_.forwardRef((n,e)=>{const t=U3(_s,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,o=_a(_s,n.__scopeMenu),i=ih(_s,n.__scopeMenu),a=nL(oL,n.__scopeMenu),c=_.useRef(null),d=Ot(e,c);return p.jsx(kd.Provider,{scope:n.__scopeMenu,children:p.jsx(no,{present:r||o.open,children:p.jsx(kd.Slot,{scope:n.__scopeMenu,children:p.jsx(b1,{id:a.contentId,"aria-labelledby":a.triggerId,...s,ref:d,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:h=>{var f;i.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),h.preventDefault()},onCloseAutoFocus:h=>h.preventDefault(),onFocusOutside:Ae(n.onFocusOutside,h=>{h.target!==a.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Ae(n.onEscapeKeyDown,h=>{i.onClose(),h.preventDefault()}),onKeyDown:Ae(n.onKeyDown,h=>{var y;const f=h.currentTarget.contains(h.target),g=cY[i.dir].includes(h.key);f&&g&&(o.onOpenChange(!1),(y=a.trigger)==null||y.focus(),h.preventDefault())})})})})})});iL.displayName=oL;function aL(n){return n?"open":"closed"}function sg(n){return n==="indeterminate"}function I1(n){return sg(n)?"indeterminate":n?"checked":"unchecked"}function EY(n){const e=document.activeElement;for(const t of n)if(t===e||(t.focus(),document.activeElement!==e))return}function TY(n,e){return n.map((t,r)=>n[(e+r)%n.length])}function kY(n,e,t){const s=e.length>1&&Array.from(e).every(d=>d===e[0])?e[0]:e,o=t?n.indexOf(t):-1;let i=TY(n,Math.max(o,0));s.length===1&&(i=i.filter(d=>d!==t));const c=i.find(d=>d.toLowerCase().startsWith(s.toLowerCase()));return c!==t?c:void 0}function MY(n,e){const{x:t,y:r}=n;let s=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const a=e[o].x,c=e[o].y,d=e[i].x,h=e[i].y;c>r!=h>r&&t<(d-a)*(r-c)/(h-c)+a&&(s=!s)}return s}function AY(n,e){if(!e)return!1;const t={x:n.clientX,y:n.clientY};return MY(t,e)}function Md(n){return e=>e.pointerType==="mouse"?n(e):void 0}var lL=B3,cL=v1,uL=H3,dL=K3,hL=P1,pL=W3,fL=rm,gL=V3,mL=Y3,yL=Z3,SL=J3,vL=eL,xL=tL,wL=rL,bL=sL,PL=iL,E1="ContextMenu",[jY,hie]=Uo(E1,[nm]),Zn=nm(),[RY,CL]=jY(E1),_L=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,dir:s,modal:o=!0}=n,[i,a]=_.useState(!1),c=Zn(e),d=An(r),h=_.useCallback(f=>{a(f),d(f)},[d]);return p.jsx(RY,{scope:e,open:i,onOpenChange:h,modal:o,children:p.jsx(lL,{...c,dir:s,open:i,onOpenChange:h,modal:o,children:t})})};_L.displayName=E1;var IL="ContextMenuTrigger",EL=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,disabled:r=!1,...s}=n,o=CL(IL,t),i=Zn(t),a=_.useRef({x:0,y:0}),c=_.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),d=_.useRef(0),h=_.useCallback(()=>window.clearTimeout(d.current),[]),f=g=>{a.current={x:g.clientX,y:g.clientY},o.onOpenChange(!0)};return _.useEffect(()=>h,[h]),_.useEffect(()=>void(r&&h()),[r,h]),p.jsxs(p.Fragment,{children:[p.jsx(cL,{...i,virtualRef:c}),p.jsx(ut.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...s,ref:e,style:{WebkitTouchCallout:"none",...n.style},onContextMenu:r?n.onContextMenu:Ae(n.onContextMenu,g=>{h(),f(g),g.preventDefault()}),onPointerDown:r?n.onPointerDown:Ae(n.onPointerDown,Np(g=>{h(),d.current=window.setTimeout(()=>f(g),700)})),onPointerMove:r?n.onPointerMove:Ae(n.onPointerMove,Np(h)),onPointerCancel:r?n.onPointerCancel:Ae(n.onPointerCancel,Np(h)),onPointerUp:r?n.onPointerUp:Ae(n.onPointerUp,Np(h))})]})});EL.displayName=IL;var OY="ContextMenuPortal",T1=n=>{const{__scopeContextMenu:e,...t}=n,r=Zn(e);return p.jsx(uL,{...r,...t})};T1.displayName=OY;var TL="ContextMenuContent",kL=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=CL(TL,t),o=Zn(t),i=_.useRef(!1);return p.jsx(dL,{...o,...r,ref:e,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var c;(c=n.onCloseAutoFocus)==null||c.call(n,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var c;(c=n.onInteractOutside)==null||c.call(n,a),!a.defaultPrevented&&!s.modal&&(i.current=!0)},style:{...n.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)"}})});kL.displayName=TL;var DY="ContextMenuGroup",ML=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(hL,{...s,...r,ref:e})});ML.displayName=DY;var LY="ContextMenuLabel",FY=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(pL,{...s,...r,ref:e})});FY.displayName=LY;var NY="ContextMenuItem",AL=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(fL,{...s,...r,ref:e})});AL.displayName=NY;var $Y="ContextMenuCheckboxItem",jL=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(gL,{...s,...r,ref:e})});jL.displayName=$Y;var zY="ContextMenuRadioGroup",BY=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(mL,{...s,...r,ref:e})});BY.displayName=zY;var UY="ContextMenuRadioItem",HY=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(yL,{...s,...r,ref:e})});HY.displayName=UY;var KY="ContextMenuItemIndicator",WY=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(SL,{...s,...r,ref:e})});WY.displayName=KY;var GY="ContextMenuSeparator",VY=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(vL,{...s,...r,ref:e})});VY.displayName=GY;var qY="ContextMenuArrow",YY=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(xL,{...s,...r,ref:e})});YY.displayName=qY;var XY="ContextMenuSub",RL=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,open:s,defaultOpen:o}=n,i=Zn(e),[a,c]=Ca({prop:s,defaultProp:o,onChange:r});return p.jsx(wL,{...i,open:a,onOpenChange:c,children:t})};RL.displayName=XY;var ZY="ContextMenuSubTrigger",OL=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(bL,{...s,...r,ref:e})});OL.displayName=ZY;var QY="ContextMenuSubContent",DL=_.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Zn(t);return p.jsx(PL,{...s,...r,ref:e,style:{...n.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)"}})});DL.displayName=QY;function Np(n){return e=>e.pointerType!=="mouse"?n(e):void 0}var JY=_L,eX=EL,tX=T1,nX=kL,rX=jL,k1="DropdownMenu",[sX,pie]=Uo(k1,[nm]),Qn=nm(),[oX,LL]=sX(k1),FL=n=>{const{__scopeDropdownMenu:e,children:t,dir:r,open:s,defaultOpen:o,onOpenChange:i,modal:a=!0}=n,c=Qn(e),d=_.useRef(null),[h=!1,f]=Ca({prop:s,defaultProp:o,onChange:i});return p.jsx(oX,{scope:e,triggerId:yi(),triggerRef:d,contentId:yi(),open:h,onOpenChange:f,onOpenToggle:_.useCallback(()=>f(g=>!g),[f]),modal:a,children:p.jsx(lL,{...c,open:h,onOpenChange:f,dir:r,modal:a,children:t})})};FL.displayName=k1;var NL="DropdownMenuTrigger",$L=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...s}=n,o=LL(NL,t),i=Qn(t);return p.jsx(cL,{asChild:!0,...i,children:p.jsx(ut.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:Gg(e,o.triggerRef),onPointerDown:Ae(n.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(o.onOpenToggle(),o.open||a.preventDefault())}),onKeyDown:Ae(n.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&o.onOpenToggle(),a.key==="ArrowDown"&&o.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});$L.displayName=NL;var iX="DropdownMenuPortal",zL=n=>{const{__scopeDropdownMenu:e,...t}=n,r=Qn(e);return p.jsx(uL,{...r,...t})};zL.displayName=iX;var BL="DropdownMenuContent",UL=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=LL(BL,t),o=Qn(t),i=_.useRef(!1);return p.jsx(dL,{id:s.contentId,"aria-labelledby":s.triggerId,...o,...r,ref:e,onCloseAutoFocus:Ae(n.onCloseAutoFocus,a=>{var c;i.current||(c=s.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:Ae(n.onInteractOutside,a=>{const c=a.detail.originalEvent,d=c.button===0&&c.ctrlKey===!0,h=c.button===2||d;(!s.modal||h)&&(i.current=!0)}),style:{...n.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 aX="DropdownMenuGroup",HL=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(hL,{...s,...r,ref:e})});HL.displayName=aX;var lX="DropdownMenuLabel",cX=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(pL,{...s,...r,ref:e})});cX.displayName=lX;var uX="DropdownMenuItem",KL=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(fL,{...s,...r,ref:e})});KL.displayName=uX;var dX="DropdownMenuCheckboxItem",WL=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(gL,{...s,...r,ref:e})});WL.displayName=dX;var hX="DropdownMenuRadioGroup",pX=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(mL,{...s,...r,ref:e})});pX.displayName=hX;var fX="DropdownMenuRadioItem",gX=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(yL,{...s,...r,ref:e})});gX.displayName=fX;var mX="DropdownMenuItemIndicator",yX=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(SL,{...s,...r,ref:e})});yX.displayName=mX;var SX="DropdownMenuSeparator",vX=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(vL,{...s,...r,ref:e})});vX.displayName=SX;var xX="DropdownMenuArrow",wX=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(xL,{...s,...r,ref:e})});wX.displayName=xX;var bX=n=>{const{__scopeDropdownMenu:e,children:t,open:r,onOpenChange:s,defaultOpen:o}=n,i=Qn(e),[a=!1,c]=Ca({prop:r,defaultProp:o,onChange:s});return p.jsx(wL,{...i,open:a,onOpenChange:c,children:t})},PX="DropdownMenuSubTrigger",GL=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(bL,{...s,...r,ref:e})});GL.displayName=PX;var CX="DropdownMenuSubContent",VL=_.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Qn(t);return p.jsx(PL,{...s,...r,ref:e,style:{...n.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=CX;var M1=FL,A1=$L,sm=zL,j1=UL,_X=HL,IX=KL,EX=WL,TX=bX,kX=GL,MX=VL;function jt(n,e){var s;const t=new Set;for(const o of e){const i=n.getShape(o);if(!i)continue;n.getShapeUtil(i).onDragShapesOut&&t.add(i);const a=n.getShape(i.parentId);a&&n.getShapeUtil(a).onDragShapesOut&&t.add(a)}const r=new Map;for(const o of t){const i=qL(n,o);i.length&&r.set(o,i)}for(const[o,i]of r){const a=n.getShapeUtil(o),c=Ye(i.map(d=>n.getShape(d)));(s=a.onDragShapesOut)==null||s.call(a,o,c)}}function qL(n,e){const t=n.getSortedChildIdsForParent(e.id);if(t.length===0)return[];const r=n.getShapePageBounds(e);if(!r)return[];let s,o,i;const a=[];for(const c of t){const d=n.getShapePageBounds(c);if(!d)continue;if(!r.includes(d)){a.push(c);continue}s??(s=n.getShapeGeometry(e)),o??(o=n.getShapePageTransform(e)),i??(i=o.applyToPoints(s.vertices));const h=n.getShapePageTransform(c).clone().invert().applyToPoints(i),{vertices:f,isClosed:g}=n.getShapeGeometry(c);if(!f.some(y=>Jr(y,h))){if(g){if(Gb(h,f))continue}else if(ZU(h,f))continue;a.push(c)}}return a}function og(n,e,t=!1){n.select(e),n.setEditingShape(e),n.setCurrentTool("select.editing_shape",{target:"shape",shape:e}),t&&n.emit("select-all-text",{shapeId:e.id})}function AX(n,e){const t=Ye(e.map(s=>n.getShape(s)).filter(s=>s&&n.isShapeOfType(s,"frame")));if(!t.length)return;const r=[];n.run(()=>{t.map(s=>{const o=n.getSortedChildIdsForParent(s.id);o.length&&(n.reparentShapes(o,s.parentId,s.index),r.push(...o))}),n.setSelectedShapes(r),n.deleteShapes(e)})}const jX=50;function RX(n,e,t={}){const r=n.getShape(e);if(!r)return;const s=n.getSortedChildIdsForParent(r.id),o=Ye(s.map(y=>n.getShape(y)));if(!o.length)return;const i=Se.FromPoints(o.flatMap(y=>{const S=n.getShapeGeometry(y.id);return n.getShapeLocalTransform(y).applyToPoints(S.vertices)})),{padding:a=jX}=t,c=i.w+2*a,d=i.h+2*a,h=a-i.minX,f=a-i.minY;if(h===0&&f===0&&r.props.w===c&&r.props.h===d)return;const g=new C(h,f).rot(r.rotation);n.run(()=>{const y=s.map(S=>{const v=n.getShape(S);return{id:v.id,type:v.type,x:v.x+h,y:v.y+f}});y.push({id:r.id,type:r.type,x:r.x-g.x,y:r.y-g.y,props:{w:c,h:d}}),n.updateShapes(y)})}const YL=_.createContext(null);function OX({assetUrls:n,children:e}){return _.useEffect(()=>{for(const t of Object.values(n.icons)){const r=xd();r.src=t,r.decode()}for(const t of Object.values(n.embedIcons)){const r=xd();r.src=t,r.decode()}},[n]),p.jsx(YL.Provider,{value:n,children:e})}function R1(){const n=_.useContext(YL);if(!n)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return n}const f0={"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-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-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-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.files.amount-too-many":"Too many files","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.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.copy-link":"Copy editor link","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","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.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.","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","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.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…"},DX=new Set(["ar","fa","he","ur","ku"]),hc={locale:"en",label:"English",messages:f0,dir:"ltr"};async function LX(n,e){if(!(await jo(e.translations.en)).ok)return console.warn("No main translations found."),hc;if(n==="en")return hc;const r=Cd.find(i=>i.locale===n);if(!r)return console.warn(`No translation found for locale ${n}`),hc;const o=await(await jo(e.translations[r.locale])).json();if(!o)return console.warn(`No messages found for locale ${n}`),hc;for(const i in hc.messages)o[i];return{locale:n,label:r.label,dir:DX.has(r.locale)?"rtl":"ltr",messages:{...hc.messages,...o}}}const XL=_.createContext(null);function ZL(){const n=_.useContext(XL);if(!n)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return n}function FX({overrides:n,locale:e,children:t}){const r=R1(),[s,o]=_.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...f0,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:f0});return _.useEffect(()=>{let i=!1;async function a(){const c=await LX(e,r);c&&!i&&(n&&n[e]?o({...c,messages:{...c.messages,...n[e]}}):o(c))}return a(),()=>{i=!0}},[r,e,n]),p.jsx(XL.Provider,{value:s,children:t})}function it(){const n=ZL();return _.useCallback(function(t){return n.messages[t]??t},[n])}const Ne=_.forwardRef(function({children:e,type:t,...r},s){return p.jsx("button",{ref:s,type:"button",draggable:!1,...r,className:Le("tlui-button",`tlui-button__${t}`,r.className),children:e})});function on({children:n}){return p.jsx("span",{className:"tlui-button__label",children:n})}var O1="Dialog",[QL,fie]=Uo(O1),[NX,ro]=QL(O1),JL=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:s,onOpenChange:o,modal:i=!0}=n,a=_.useRef(null),c=_.useRef(null),[d=!1,h]=Ca({prop:r,defaultProp:s,onChange:o});return p.jsx(NX,{scope:e,triggerRef:a,contentRef:c,contentId:yi(),titleId:yi(),descriptionId:yi(),open:d,onOpenChange:h,onOpenToggle:_.useCallback(()=>h(f=>!f),[h]),modal:i,children:t})};JL.displayName=O1;var e5="DialogTrigger",$X=_.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ro(e5,t),o=Ot(e,s.triggerRef);return p.jsx(ut.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":F1(s.open),...r,ref:o,onClick:Ae(n.onClick,s.onOpenToggle)})});$X.displayName=e5;var D1="DialogPortal",[zX,t5]=QL(D1,{forceMount:void 0}),n5=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:s}=n,o=ro(D1,e);return p.jsx(zX,{scope:e,forceMount:t,children:_.Children.map(r,i=>p.jsx(no,{present:t||o.open,children:p.jsx(rh,{asChild:!0,container:s,children:i})}))})};n5.displayName=D1;var ig="DialogOverlay",r5=_.forwardRef((n,e)=>{const t=t5(ig,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,o=ro(ig,n.__scopeDialog);return o.modal?p.jsx(no,{present:r||o.open,children:p.jsx(BX,{...s,ref:e})}):null});r5.displayName=ig;var BX=_.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ro(ig,t);return p.jsx(tm,{as:cl,allowPinchZoom:!0,shards:[s.contentRef],children:p.jsx(ut.div,{"data-state":F1(s.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),dl="DialogContent",s5=_.forwardRef((n,e)=>{const t=t5(dl,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,o=ro(dl,n.__scopeDialog);return p.jsx(no,{present:r||o.open,children:o.modal?p.jsx(UX,{...s,ref:e}):p.jsx(HX,{...s,ref:e})})});s5.displayName=dl;var UX=_.forwardRef((n,e)=>{const t=ro(dl,n.__scopeDialog),r=_.useRef(null),s=Ot(e,t.contentRef,r);return _.useEffect(()=>{const o=r.current;if(o)return S1(o)},[]),p.jsx(o5,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ae(n.onCloseAutoFocus,o=>{var i;o.preventDefault(),(i=t.triggerRef.current)==null||i.focus()}),onPointerDownOutside:Ae(n.onPointerDownOutside,o=>{const i=o.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&o.preventDefault()}),onFocusOutside:Ae(n.onFocusOutside,o=>o.preventDefault())})}),HX=_.forwardRef((n,e)=>{const t=ro(dl,n.__scopeDialog),r=_.useRef(!1),s=_.useRef(!1);return p.jsx(o5,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=n.onCloseAutoFocus)==null||i.call(n,o),o.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var c,d;(c=n.onInteractOutside)==null||c.call(n,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((d=t.triggerRef.current)==null?void 0:d.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),o5=_.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,...i}=n,a=ro(dl,t),c=_.useRef(null),d=Ot(e,c);return i1(),p.jsxs(p.Fragment,{children:[p.jsx(qg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:p.jsx(th,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":F1(a.open),...i,ref:d,onDismiss:()=>a.onOpenChange(!1)})}),p.jsxs(p.Fragment,{children:[p.jsx(WX,{titleId:a.titleId}),p.jsx(VX,{contentRef:c,descriptionId:a.descriptionId})]})]})}),L1="DialogTitle",i5=_.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ro(L1,t);return p.jsx(ut.h2,{id:s.titleId,...r,ref:e})});i5.displayName=L1;var a5="DialogDescription",KX=_.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ro(a5,t);return p.jsx(ut.p,{id:s.descriptionId,...r,ref:e})});KX.displayName=a5;var l5="DialogClose",c5=_.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ro(l5,t);return p.jsx(ut.button,{type:"button",...r,ref:e,onClick:Ae(n.onClick,()=>s.onOpenChange(!1))})});c5.displayName=l5;function F1(n){return n?"open":"closed"}var u5="DialogTitleWarning",[gie,d5]=EG(u5,{contentName:dl,titleName:L1,docsSlug:"dialog"}),WX=({titleId:n})=>{const e=d5(u5),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
247
|
+
|
|
248
|
+
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
249
|
+
|
|
250
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return _.useEffect(()=>{n&&(document.getElementById(n)||console.error(t))},[t,n]),null},GX="DialogDescriptionWarning",VX=({contentRef:n,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${d5(GX).contentName}}.`;return _.useEffect(()=>{var o;const s=(o=n.current)==null?void 0:o.getAttribute("aria-describedby");e&&s&&(document.getElementById(e)||console.warn(r))},[r,n,e]),null},qX=JL,YX=n5,XX=r5,ZX=s5,QX=i5;const Fo=_.memo(function({small:e,invertIcon:t,icon:r,color:s,className:o,...i}){const a=R1(),c=a.icons[r]??a.icons["question-mark-circle"],d=_.useRef(null);return _.useLayoutEffect(()=>{c||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),d!=null&&d.current&&(d.current.style.webkitMask=`url(${c}) center 100% / 100% no-repeat`)},[d,c,r]),r==="none"?p.jsx("div",{className:Le("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},o)}):p.jsx("div",{...i,ref:d,className:Le("tlui-icon",{"tlui-icon__small":e},o),style:{color:s,mask:`url(${c}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})});function nt({icon:n,small:e,invertIcon:t}){return p.jsx(Fo,{className:"tlui-button__icon",icon:n,small:e,invertIcon:t})}function om({className:n,children:e}){return p.jsx("div",{className:Le("tlui-dialog__header",n),children:e})}function im({className:n,children:e,style:t}){return p.jsx(QX,{dir:"ltr",className:Le("tlui-dialog__header__title",n),style:t,children:e})}function am(){return p.jsx("div",{className:"tlui-dialog__header__close",children:p.jsx(c5,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:p.jsx(Ne,{type:"icon","aria-label":"Close",onTouchEnd:n=>n.target.click(),children:p.jsx(nt,{small:!0,icon:"cross-2"})})})})}function Ad({className:n,children:e,style:t}){return p.jsx("div",{className:Le("tlui-dialog__body",n),style:t,children:e})}function N1({className:n,children:e}){return p.jsx("div",{className:Le("tlui-dialog__footer",n),children:e})}const lm=_.forwardRef(function({className:e,label:t,icon:r,iconLeft:s,autoSelect:o=!1,autoFocus:i=!1,defaultValue:a,placeholder:c,onComplete:d,onValueChange:h,onCancel:f,onFocus:g,onBlur:y,shouldManuallyMaintainScrollPositionWhenFocused:S=!1,children:v,value:w,"data-testid":b},P){const k=wa(),E=_.useRef(null);_.useImperativeHandle(P,()=>E.current);const M=it(),A=_.useRef(a??""),R=_.useRef(a??""),[D,V]=_.useState(!1),L=_.useCallback($=>{V(!0);const W=$.currentTarget;R.current=W.value,k?k.timers.requestAnimationFrame(()=>{o&&W.select()}):e0.requestAnimationFrame("anon",()=>{o&&W.select()}),g==null||g()},[o,k,g]),U=_.useCallback($=>{const W=$.currentTarget.value;R.current=W,h==null||h(W)},[h]),K=_.useCallback($=>{switch($.key){case"Enter":{$.currentTarget.blur(),ln($),d==null||d($.currentTarget.value);break}case"Escape":{$.currentTarget.value=A.current,f==null||f($.currentTarget.value),$.currentTarget.blur(),ln($);break}}},[d,f]),F=_.useCallback($=>{V(!1);const W=$.currentTarget.value;y==null||y(W)},[y]);return _.useEffect(()=>{if(!Et.isIos)return;const $=window.visualViewport;if(D&&S&&$){const W=()=>{var Y;(Y=E.current)==null||Y.scrollIntoView({block:"center"})};return $.addEventListener("resize",W),$.addEventListener("scroll",W),k?k.timers.requestAnimationFrame(()=>{var Y;(Y=E.current)==null||Y.scrollIntoView({block:"center"})}):e0.requestAnimationFrame("anon",()=>{var Y;(Y=E.current)==null||Y.scrollIntoView({block:"center"})}),()=>{$.removeEventListener("resize",W),$.removeEventListener("scroll",W)}}},[D,k,S]),p.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[v,t&&p.jsx("label",{children:M(t)}),s&&p.jsx(Fo,{icon:s,className:"tlui-icon-left",small:!0}),p.jsx("input",{ref:E,className:Le("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:K,onChange:U,onFocus:L,onBlur:F,autoFocus:i,placeholder:c,value:w,"data-testid":b}),r&&p.jsx(Fo,{icon:r,small:!!t})]})});function QT(n){return ns.isValid(n)?{isValid:!0,hasProtocol:!0}:ns.isValid("https://"+n)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const JX=jn(function({onClose:e}){const r=te().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?p.jsx(eZ,{onClose:e,selectedShape:r}):null}),eZ=jn(function({onClose:e,selectedShape:t}){const r=te(),s=it(),o=_.useRef(null);_.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=o.current)==null?void 0:S.focus()})},[r]);const i=_.useRef(t.props.url),[a,c]=_.useState(()=>{const S=QT(t.props.url),v=S.isValid===!0?S.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:v,safe:v,valid:!0}}),d=_.useCallback(S=>{const v=S.replace(/https?:\/\/(https?:\/\/)/,(P,k)=>k),w=QT(v),b=w.isValid===!0?w.hasProtocol?v:"https://"+v:"https://";c({actual:v,safe:b,valid:w.isValid})},[]),h=_.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),e())},[r,e]),f=_.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(S&&"url"in S.props&&S.props.url!==a.safe&&r.updateShapes([{id:S.id,type:S.type,props:{url:a.safe}}]),e())},[r,e,a]),g=_.useCallback(()=>{e()},[e]);if(!t)return e(),null;const y=i.current&&!a.valid;return p.jsxs(p.Fragment,{children:[p.jsxs(om,{children:[p.jsx(im,{children:s("edit-link-dialog.title")}),p.jsx(am,{})]}),p.jsx(Ad,{children:p.jsxs("div",{className:"tlui-edit-link-dialog",children:[p.jsx(lm,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:d,onComplete:f,onCancel:g}),p.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),p.jsxs(N1,{className:"tlui-dialog__footer__actions",children:[p.jsx(Ne,{type:"normal",onClick:g,onTouchEnd:g,children:p.jsx(on,{children:s("edit-link-dialog.cancel")})}),y?p.jsx(Ne,{type:"danger",onTouchEnd:h,onClick:h,children:p.jsx(on,{children:s("edit-link-dialog.clear")})}):p.jsx(Ne,{type:"primary",disabled:!a.valid,onTouchEnd:f,onClick:f,children:p.jsx(on,{children:s("edit-link-dialog.save")})})]})]})});var tZ={};const JT=/(^\/r\/[^/]+\/?$)/,$1=[{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:n=>{const e=Ge(n);if(e&&e.pathname.match(JT))return n},fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(JT))return n}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:n=>{if(n.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!n.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${n}`},fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:n=>{if(n.includes("/maps/embed?"))return n;if(n.includes("/maps/")){const e=n.match(/@(.*?),(.*?),(.*?)z/);let t;if(e){const[,r,s,o]=e;t=`https://${new URL(n).host.replace("www.","")}/maps/embed/v1/view?key=${tZ.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${s}&zoom=${o}`}else t="";return t}},fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n),t=e&&e.pathname.match(/\/v\/(.+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Ge(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:n=>{const e=Ge(n),t=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Ge(n),t=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,t=n.match(e);if(t){const[r,s,o]=t;return`https://codepen.io/${s}/embed/${o}`}},fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s,o]=t;return`https://codepen.io/${s}/pen/${o}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:n=>{const e=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,t=n.match(e);if(t){const[r,s]=t;return`https://scratch.mit.edu/projects/embed/${s}`}},fromEmbedUrl:n=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s]=t;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:n=>{const e=Ge(n);if(!e)return;const t=e.hostname.replace(/^www./,"");if(t==="youtu.be")return`https://www.youtube.com/embed/${e.pathname.split("/").filter(Boolean)[0]}`;if((t==="youtube.com"||t==="m.youtube.com")&&e.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${e.searchParams.get("v")}`},fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n),t=e==null?void 0:e.searchParams.get("cid");if(e!=null&&e.pathname.match(/\/calendar\/u\/0/)&&t){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",t),e.href}},fromEmbedUrl:n=>{const e=Ge(n),t=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&t){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",t),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:n=>{const e=Ge(n);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/pub\/?$/))){e.pathname=e.pathname.replace(/\/pub$/,"/embed");const t=Array.from(e.searchParams.keys());for(const r of t)e.searchParams.delete(r);return e.href}},fromEmbedUrl:n=>{const e=Ge(n);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const t=Array.from(e.searchParams.keys());for(const r of t)e.searchParams.delete(r);return e.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return n.split("/").pop()?n:void 0},fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return n.split("/").pop()?n:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${n}?embed=true`},fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n);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:n=>{const e=Ge(n);if(e&&e.hostname==="player.vimeo.com"){const t=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(t)return"https://vimeo.com/"+t[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:n=>{const e=Ge(n);if(e&&e.hash.match(/#room=/))return n},fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.hash.match(/#room=/))return n}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:n=>{const e=Ge(n);if(e&&e.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}/embed${e.pathname}?cell=*`;if(e&&e.pathname.match(/^\/d\/([^/]+)\/?$/)){const t=e.pathname.replace(/^\/d/,"");return`${e.origin}/embed${t}?cell=*`}},fromEmbedUrl:n=>{const e=Ge(n);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:n=>{const e=Ge(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${n}?embed`},fromEmbedUrl:n=>{const e=Ge(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],nZ={"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},rZ=$1.map(n=>n.type);function sZ(n){return rZ.includes(n)}function oZ(n){return"icon"in n}function h5(){const n=te();if(n.hasShapeUtil("embed"))return n.getShapeUtil("embed")}function z1(){const n=h5();return e=>n?n.getEmbedDefinition(e):void 0}function iZ(){const n=h5();return n?n.getEmbedDefinitions():[]}const p5=jn(function({onClose:e}){const t=te(),r=it(),s=R1(),[o,i]=_.useState(null),[a,c]=_.useState(""),[d,h]=_.useState(null),[f,g]=_.useState(!1),y=_.useRef(-1),S=iZ(),v=z1();return p.jsxs(p.Fragment,{children:[p.jsxs(om,{children:[p.jsx(im,{children:o?`${r("embed-dialog.title")} — ${o.title}`:r("embed-dialog.title")}),p.jsx(am,{})]}),o?p.jsxs(p.Fragment,{children:[p.jsxs(Ad,{className:"tlui-embed-dialog__enter",children:[p.jsx(lm,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:w=>{c(w);const b=v(w);h(b&&b.definition.type===o.type?b:null),g(!1),clearTimeout(y.current),y.current=t.timers.setTimeout(()=>g(!b),320)}}),a===""?p.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[p.jsx("span",{children:r("embed-dialog.instruction")})," ",o.instructionLink&&p.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:o.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",p.jsx(Fo,{icon:"external-link",small:!0})]})]}):p.jsx("div",{className:"tlui-embed-dialog__warning",children:f?r("embed-dialog.invalid-url"):" "})]}),p.jsxs(N1,{className:"tlui-dialog__footer__actions",children:[p.jsx(Ne,{type:"normal",onClick:()=>{i(null),h(null),c("")},children:p.jsx(on,{children:r("embed-dialog.back")})}),p.jsx("div",{className:"tlui-embed__spacer"}),p.jsx(Ne,{type:"normal",onClick:e,children:p.jsx(on,{children:r("embed-dialog.cancel")})}),p.jsx(Ne,{type:"primary",disabled:!d,onClick:()=>{d&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:d.definition}),e())},children:p.jsx(on,{children:r("embed-dialog.create")})})]})]}):p.jsx(p.Fragment,{children:p.jsx(Ad,{className:"tlui-embed-dialog__list",children:S.map(w=>{const b=sZ(w.type)?s.embedIcons[w.type]:oZ(w)?w.icon:void 0;return p.jsxs(Ne,{type:"menu",onClick:()=>i(w),children:[p.jsx(on,{children:w.title}),b&&p.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${b})`}})]},w.type)})})})]})});async function aZ(n,e,t){const r=Ye(e.map(a=>{const c=n.getShape(a);if(!(!c||n.getShapeUtil(c.type).toSvg===void 0))return c}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||n.isShapeOfType(a,"image"))return}const s=[];if(t!==void 0){const a=r.map(c=>({shape:c,bounds:n.getShapeMaskedPageBounds(c).clone().expandBy(t)}));for(let c=0;c<a.length;c++){const d=a[c];if(c===0){s[0]={shapes:[d.shape],bounds:d.bounds};continue}let h=!1;for(const f of s)if(f.bounds.includes(d.bounds)){f.shapes.push(d.shape),f.bounds.expand(d.bounds),h=!0;break}h||s.push({shapes:[d.shape],bounds:d.bounds})}}else{const a=Se.Common(r.map(c=>n.getShapeMaskedPageBounds(c)));s.push({shapes:r,bounds:a})}const o=n.options.flattenImageBoundsPadding;for(const a of s){t!==void 0&&a.bounds.expandBy(-t);const c=await n.getSvgString(a.shapes,{padding:o});if(!(c!=null&&c.svg))continue;const d=await n.getAssetForExternalContent({type:"file",file:new File([c.svg],"asset.svg",{type:"image/svg+xml"})});d&&(a.asset=d)}const i=[];return ko(()=>{for(const a of s){const{asset:c,bounds:d,shapes:h}=a;if(!c)continue;const f=n.findCommonAncestor(h)??n.getCurrentPageId();if(!f)continue;let g="a1";for(const b of h)if(b.parentId===f){b.index>g&&(g=b.index);break}let y,S,v;if(Mr(f)){const b=n.getShape(f);if(!b)continue;const P=n.getPointInShapeSpace(b,{x:d.x,y:d.y});v=n.getShapePageTransform(f).rotation(),P.sub(new C(o,o).rot(-v)),y=P.x,S=P.y}else y=d.x-o,S=d.y-o,v=0;n.deleteShapes(h),n.createAssets([{...c,id:c.id}]);const w=Ct();n.createShape({id:w,type:"image",index:g,parentId:f,x:y,y:S,rotation:-v,props:{assetId:c.id,w:d.w+o*2,h:d.h+o*2}}),i.push(w)}}),i}function cm(){const n=wa();return(n==null?void 0:n.store.props.collaboration)!==void 0}function lZ(){const n=wa();return se("sync status",()=>{var e;return(e=n==null?void 0:n.store.props.collaboration)!=null&&e.status?n.store.props.collaboration.status.get():null},[n])}const Xx=[0,389,436,476,580,640,840,1023];var Jt=(n=>(n[n.ZERO=0]="ZERO",n[n.MOBILE_XXS=1]="MOBILE_XXS",n[n.MOBILE_XS=2]="MOBILE_XS",n[n.MOBILE_SM=3]="MOBILE_SM",n[n.MOBILE=4]="MOBILE",n[n.TABLET_SM=5]="TABLET_SM",n[n.TABLET=6]="TABLET",n[n.DESKTOP=7]="DESKTOP",n))(Jt||{});const f5=at.createContext(null);function cZ({forceMobile:n=!1,children:e}){const t=wa(),r=se("breakpoint",()=>{const{width:s}=(t==null?void 0:t.getViewportScreenBounds())??{width:window.innerWidth},o=n?Jt.MOBILE_SM:Xx.length-1;for(let i=0;i<o;i++)if(s>Xx[i]&&s<=Xx[i+1])return i;return o},[t]);return p.jsx(f5.Provider,{value:r,children:e})}function ur(){const n=_.useContext(f5);if(n===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return n}const g0=_.createContext(null);function uZ({context:n,children:e}){const t=_.useContext(g0),r=On(),s=yb("dialogs",[]),o=_.useMemo(()=>({dialogs:s,addDialog(i){const a=i.id??xt();return s.update(c=>[...c.filter(d=>d.id!==i.id),{...i,id:a}]),r("open-menu",{source:"dialog",id:a}),Ks.addOpenMenu(a,n),a},removeDialog(i){var c;const a=s.get().find(d=>d.id===i);return a&&((c=a.onClose)==null||c.call(a),r("close-menu",{source:"dialog",id:i}),Ks.deleteOpenMenu(i,n),s.update(d=>d.filter(h=>h!==a))),i},clearDialogs(){const i=s.get();i.length!==0&&(i.forEach(a=>{var c;(c=a.onClose)==null||c.call(a),r("close-menu",{source:"dialog",id:a.id}),Ks.deleteOpenMenu(a.id,n)}),s.set([]))}}),[r,s,n]);return t?p.jsx(p.Fragment,{children:e}):p.jsx(g0.Provider,{value:o,children:e})}function ah(){const n=_.useContext(g0);if(!n)throw new Error("useDialogs must be used within a DialogsProvider");return n}var dZ="VisuallyHidden",B1=_.forwardRef((n,e)=>p.jsx(ut.span,{...n,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",...n.style}}));B1.displayName=dZ;var U1="ToastProvider",[H1,hZ,pZ]=Vg("Toast"),[g5,mie]=Uo("Toast",[pZ]),[fZ,um]=g5(U1),m5=n=>{const{__scopeToast:e,label:t="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:o=50,children:i}=n,[a,c]=_.useState(null),[d,h]=_.useState(0),f=_.useRef(!1),g=_.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${U1}\`. Expected non-empty \`string\`.`),p.jsx(H1.Provider,{scope:e,children:p.jsx(fZ,{scope:e,label:t,duration:r,swipeDirection:s,swipeThreshold:o,toastCount:d,viewport:a,onViewportChange:c,onToastAdd:_.useCallback(()=>h(y=>y+1),[]),onToastRemove:_.useCallback(()=>h(y=>y-1),[]),isFocusedToastEscapeKeyDownRef:f,isClosePausedRef:g,children:i})})};m5.displayName=U1;var y5="ToastViewport",gZ=["F8"],m0="toast.viewportPause",y0="toast.viewportResume",S5=_.forwardRef((n,e)=>{const{__scopeToast:t,hotkey:r=gZ,label:s="Notifications ({hotkey})",...o}=n,i=um(y5,t),a=hZ(t),c=_.useRef(null),d=_.useRef(null),h=_.useRef(null),f=_.useRef(null),g=Ot(e,f,i.onViewportChange),y=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=i.toastCount>0;_.useEffect(()=>{const w=b=>{var k;r.length!==0&&r.every(E=>b[E]||b.code===E)&&((k=f.current)==null||k.focus())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[r]),_.useEffect(()=>{const w=c.current,b=f.current;if(S&&w&&b){const P=()=>{if(!i.isClosePausedRef.current){const A=new CustomEvent(m0);b.dispatchEvent(A),i.isClosePausedRef.current=!0}},k=()=>{if(i.isClosePausedRef.current){const A=new CustomEvent(y0);b.dispatchEvent(A),i.isClosePausedRef.current=!1}},E=A=>{!w.contains(A.relatedTarget)&&k()},M=()=>{w.contains(document.activeElement)||k()};return w.addEventListener("focusin",P),w.addEventListener("focusout",E),w.addEventListener("pointermove",P),w.addEventListener("pointerleave",M),window.addEventListener("blur",P),window.addEventListener("focus",k),()=>{w.removeEventListener("focusin",P),w.removeEventListener("focusout",E),w.removeEventListener("pointermove",P),w.removeEventListener("pointerleave",M),window.removeEventListener("blur",P),window.removeEventListener("focus",k)}}},[S,i.isClosePausedRef]);const v=_.useCallback(({tabbingDirection:w})=>{const P=a().map(k=>{const E=k.ref.current,M=[E,...TZ(E)];return w==="forwards"?M:M.reverse()});return(w==="forwards"?P.reverse():P).flat()},[a]);return _.useEffect(()=>{const w=f.current;if(w){const b=P=>{var M,A,R;const k=P.altKey||P.ctrlKey||P.metaKey;if(P.key==="Tab"&&!k){const D=document.activeElement,V=P.shiftKey;if(P.target===w&&V){(M=d.current)==null||M.focus();return}const K=v({tabbingDirection:V?"backwards":"forwards"}),F=K.findIndex($=>$===D);Zx(K.slice(F+1))?P.preventDefault():V?(A=d.current)==null||A.focus():(R=h.current)==null||R.focus()}};return w.addEventListener("keydown",b),()=>w.removeEventListener("keydown",b)}},[a,v]),p.jsxs(HG,{ref:c,role:"region","aria-label":s.replace("{hotkey}",y),tabIndex:-1,style:{pointerEvents:S?void 0:"none"},children:[S&&p.jsx(S0,{ref:d,onFocusFromOutsideViewport:()=>{const w=v({tabbingDirection:"forwards"});Zx(w)}}),p.jsx(H1.Slot,{scope:t,children:p.jsx(ut.ol,{tabIndex:-1,...o,ref:g})}),S&&p.jsx(S0,{ref:h,onFocusFromOutsideViewport:()=>{const w=v({tabbingDirection:"backwards"});Zx(w)}})]})});S5.displayName=y5;var v5="ToastFocusProxy",S0=_.forwardRef((n,e)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...s}=n,o=um(v5,t);return p.jsx(B1,{"aria-hidden":!0,tabIndex:0,...s,ref:e,style:{position:"fixed"},onFocus:i=>{var d;const a=i.relatedTarget;!((d=o.viewport)!=null&&d.contains(a))&&r()}})});S0.displayName=v5;var dm="Toast",mZ="toast.swipeStart",yZ="toast.swipeMove",SZ="toast.swipeCancel",vZ="toast.swipeEnd",x5=_.forwardRef((n,e)=>{const{forceMount:t,open:r,defaultOpen:s,onOpenChange:o,...i}=n,[a=!0,c]=Ca({prop:r,defaultProp:s,onChange:o});return p.jsx(no,{present:t||a,children:p.jsx(bZ,{open:a,...i,ref:e,onClose:()=>c(!1),onPause:An(n.onPause),onResume:An(n.onResume),onSwipeStart:Ae(n.onSwipeStart,d=>{d.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Ae(n.onSwipeMove,d=>{const{x:h,y:f}=d.detail.delta;d.currentTarget.setAttribute("data-swipe","move"),d.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${h}px`),d.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${f}px`)}),onSwipeCancel:Ae(n.onSwipeCancel,d=>{d.currentTarget.setAttribute("data-swipe","cancel"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),d.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:Ae(n.onSwipeEnd,d=>{const{x:h,y:f}=d.detail.delta;d.currentTarget.setAttribute("data-swipe","end"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),d.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),d.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${h}px`),d.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${f}px`),c(!1)})})})});x5.displayName=dm;var[xZ,wZ]=g5(dm,{onClose(){}}),bZ=_.forwardRef((n,e)=>{const{__scopeToast:t,type:r="foreground",duration:s,open:o,onClose:i,onEscapeKeyDown:a,onPause:c,onResume:d,onSwipeStart:h,onSwipeMove:f,onSwipeCancel:g,onSwipeEnd:y,...S}=n,v=um(dm,t),[w,b]=_.useState(null),P=Ot(e,$=>b($)),k=_.useRef(null),E=_.useRef(null),M=s||v.duration,A=_.useRef(0),R=_.useRef(M),D=_.useRef(0),{onToastAdd:V,onToastRemove:L}=v,U=An(()=>{var W;(w==null?void 0:w.contains(document.activeElement))&&((W=v.viewport)==null||W.focus()),i()}),K=_.useCallback($=>{!$||$===1/0||(window.clearTimeout(D.current),A.current=new Date().getTime(),D.current=window.setTimeout(U,$))},[U]);_.useEffect(()=>{const $=v.viewport;if($){const W=()=>{K(R.current),d==null||d()},Y=()=>{const Z=new Date().getTime()-A.current;R.current=R.current-Z,window.clearTimeout(D.current),c==null||c()};return $.addEventListener(m0,Y),$.addEventListener(y0,W),()=>{$.removeEventListener(m0,Y),$.removeEventListener(y0,W)}}},[v.viewport,M,c,d,K]),_.useEffect(()=>{o&&!v.isClosePausedRef.current&&K(M)},[o,M,v.isClosePausedRef,K]),_.useEffect(()=>(V(),()=>L()),[V,L]);const F=_.useMemo(()=>w?E5(w):null,[w]);return v.viewport?p.jsxs(p.Fragment,{children:[F&&p.jsx(PZ,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:F}),p.jsx(xZ,{scope:t,onClose:U,children:Yc.createPortal(p.jsx(H1.ItemSlot,{scope:t,children:p.jsx(UG,{asChild:!0,onEscapeKeyDown:Ae(a,()=>{v.isFocusedToastEscapeKeyDownRef.current||U(),v.isFocusedToastEscapeKeyDownRef.current=!1}),children:p.jsx(ut.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":v.swipeDirection,...S,ref:P,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:Ae(n.onKeyDown,$=>{$.key==="Escape"&&(a==null||a($.nativeEvent),$.nativeEvent.defaultPrevented||(v.isFocusedToastEscapeKeyDownRef.current=!0,U()))}),onPointerDown:Ae(n.onPointerDown,$=>{$.button===0&&(k.current={x:$.clientX,y:$.clientY})}),onPointerMove:Ae(n.onPointerMove,$=>{if(!k.current)return;const W=$.clientX-k.current.x,Y=$.clientY-k.current.y,Z=!!E.current,H=["left","right"].includes(v.swipeDirection),Q=["left","up"].includes(v.swipeDirection)?Math.min:Math.max,ae=H?Q(0,W):0,B=H?0:Q(0,Y),ne=$.pointerType==="touch"?10:2,he={x:ae,y:B},Pe={originalEvent:$,delta:he};Z?(E.current=he,$p(yZ,f,Pe,{discrete:!1})):ek(he,v.swipeDirection,ne)?(E.current=he,$p(mZ,h,Pe,{discrete:!1}),$.target.setPointerCapture($.pointerId)):(Math.abs(W)>ne||Math.abs(Y)>ne)&&(k.current=null)}),onPointerUp:Ae(n.onPointerUp,$=>{const W=E.current,Y=$.target;if(Y.hasPointerCapture($.pointerId)&&Y.releasePointerCapture($.pointerId),E.current=null,k.current=null,W){const Z=$.currentTarget,H={originalEvent:$,delta:W};ek(W,v.swipeDirection,v.swipeThreshold)?$p(vZ,y,H,{discrete:!0}):$p(SZ,g,H,{discrete:!0}),Z.addEventListener("click",Q=>Q.preventDefault(),{once:!0})}})})})}),v.viewport)})]}):null}),PZ=n=>{const{__scopeToast:e,children:t,...r}=n,s=um(dm,e),[o,i]=_.useState(!1),[a,c]=_.useState(!1);return IZ(()=>i(!0)),_.useEffect(()=>{const d=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(d)},[]),a?null:p.jsx(rh,{asChild:!0,children:p.jsx(B1,{...r,children:o&&p.jsxs(p.Fragment,{children:[s.label," ",t]})})})},CZ="ToastTitle",w5=_.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return p.jsx(ut.div,{...r,ref:e})});w5.displayName=CZ;var _Z="ToastDescription",b5=_.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return p.jsx(ut.div,{...r,ref:e})});b5.displayName=_Z;var P5="ToastAction",C5=_.forwardRef((n,e)=>{const{altText:t,...r}=n;return t.trim()?p.jsx(I5,{altText:t,asChild:!0,children:p.jsx(K1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${P5}\`. Expected non-empty \`string\`.`),null)});C5.displayName=P5;var _5="ToastClose",K1=_.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n,s=wZ(_5,t);return p.jsx(I5,{asChild:!0,children:p.jsx(ut.button,{type:"button",...r,ref:e,onClick:Ae(n.onClick,s.onClose)})})});K1.displayName=_5;var I5=_.forwardRef((n,e)=>{const{__scopeToast:t,altText:r,...s}=n;return p.jsx(ut.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function E5(n){const e=[];return Array.from(n.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),EZ(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(...E5(r))}}),e}function $p(n,e,t,{discrete:r}){const s=t.originalEvent.currentTarget,o=new CustomEvent(n,{bubbles:!0,cancelable:!0,detail:t});e&&s.addEventListener(n,e,{once:!0}),r?s1(s,o):s.dispatchEvent(o)}var ek=(n,e,t=0)=>{const r=Math.abs(n.x),s=Math.abs(n.y),o=r>s;return e==="left"||e==="right"?o&&r>t:!o&&s>t};function IZ(n=()=>{}){const e=An(n);pa(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[e])}function EZ(n){return n.nodeType===n.ELEMENT_NODE}function TZ(n){const e=[],t=document.createTreeWalker(n,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(;t.nextNode();)e.push(t.currentNode);return e}function Zx(n){const e=document.activeElement;return n.some(t=>t===e?!0:(t.focus(),document.activeElement!==e))}var kZ=x5,MZ=w5,AZ=b5,jZ=C5,tk=K1;const v0=_.createContext(null);function RZ({children:n}){const e=yb("toasts",[]),t=_.useContext(v0),r=_.useMemo(()=>({toasts:e,addToast(s){const o=s.id??xt();return e.update(i=>[...i.filter(a=>a.id!==s.id),{...s,id:o}]),o},removeToast(s){return e.update(o=>o.filter(i=>i.id!==s)),s},clearToasts(){e.set([])}}),[e]);return t?p.jsx(p.Fragment,{children:n}):p.jsx(m5,{children:p.jsx(v0.Provider,{value:r,children:n})})}function Ii(){const n=_.useContext(v0);if(!n)throw new Error("useToasts must be used within a ToastsProvider");return n}var Qx={exports:{}},nk;function OZ(){return nk||(nk=1,function(n){var e=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function i(c,d){if(!o[c]){o[c]={};for(var h=0;h<c.length;h++)o[c][c.charAt(h)]=h}return o[c][d]}var a={compressToBase64:function(c){if(c==null)return"";var d=a._compress(c,6,function(h){return r.charAt(h)});switch(d.length%4){default:case 0:return d;case 1:return d+"===";case 2:return d+"==";case 3:return d+"="}},decompressFromBase64:function(c){return c==null?"":c==""?null:a._decompress(c.length,32,function(d){return i(r,c.charAt(d))})},compressToUTF16:function(c){return c==null?"":a._compress(c,15,function(d){return t(d+32)})+" "},decompressFromUTF16:function(c){return c==null?"":c==""?null:a._decompress(c.length,16384,function(d){return c.charCodeAt(d)-32})},compressToUint8Array:function(c){for(var d=a.compress(c),h=new Uint8Array(d.length*2),f=0,g=d.length;f<g;f++){var y=d.charCodeAt(f);h[f*2]=y>>>8,h[f*2+1]=y%256}return h},decompressFromUint8Array:function(c){if(c==null)return a.decompress(c);for(var d=new Array(c.length/2),h=0,f=d.length;h<f;h++)d[h]=c[h*2]*256+c[h*2+1];var g=[];return d.forEach(function(y){g.push(t(y))}),a.decompress(g.join(""))},compressToEncodedURIComponent:function(c){return c==null?"":a._compress(c,6,function(d){return s.charAt(d)})},decompressFromEncodedURIComponent:function(c){return c==null?"":c==""?null:(c=c.replace(/ /g,"+"),a._decompress(c.length,32,function(d){return i(s,c.charAt(d))}))},compress:function(c){return a._compress(c,16,function(d){return t(d)})},_compress:function(c,d,h){if(c==null)return"";var f,g,y={},S={},v="",w="",b="",P=2,k=3,E=2,M=[],A=0,R=0,D;for(D=0;D<c.length;D+=1)if(v=c.charAt(D),Object.prototype.hasOwnProperty.call(y,v)||(y[v]=k++,S[v]=!0),w=b+v,Object.prototype.hasOwnProperty.call(y,w))b=w;else{if(Object.prototype.hasOwnProperty.call(S,b)){if(b.charCodeAt(0)<256){for(f=0;f<E;f++)A=A<<1,R==d-1?(R=0,M.push(h(A)),A=0):R++;for(g=b.charCodeAt(0),f=0;f<8;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1}else{for(g=1,f=0;f<E;f++)A=A<<1|g,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=0;for(g=b.charCodeAt(0),f=0;f<16;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1}P--,P==0&&(P=Math.pow(2,E),E++),delete S[b]}else for(g=y[b],f=0;f<E;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1;P--,P==0&&(P=Math.pow(2,E),E++),y[w]=k++,b=String(v)}if(b!==""){if(Object.prototype.hasOwnProperty.call(S,b)){if(b.charCodeAt(0)<256){for(f=0;f<E;f++)A=A<<1,R==d-1?(R=0,M.push(h(A)),A=0):R++;for(g=b.charCodeAt(0),f=0;f<8;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1}else{for(g=1,f=0;f<E;f++)A=A<<1|g,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=0;for(g=b.charCodeAt(0),f=0;f<16;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1}P--,P==0&&(P=Math.pow(2,E),E++),delete S[b]}else for(g=y[b],f=0;f<E;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1;P--,P==0&&(P=Math.pow(2,E),E++)}for(g=2,f=0;f<E;f++)A=A<<1|g&1,R==d-1?(R=0,M.push(h(A)),A=0):R++,g=g>>1;for(;;)if(A=A<<1,R==d-1){M.push(h(A));break}else R++;return M.join("")},decompress:function(c){return c==null?"":c==""?null:a._decompress(c.length,32768,function(d){return c.charCodeAt(d)})},_decompress:function(c,d,h){var f=[],g=4,y=4,S=3,v="",w=[],b,P,k,E,M,A,R,D={val:h(0),position:d,index:1};for(b=0;b<3;b+=1)f[b]=b;for(k=0,M=Math.pow(2,2),A=1;A!=M;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=d,D.val=h(D.index++)),k|=(E>0?1:0)*A,A<<=1;switch(k){case 0:for(k=0,M=Math.pow(2,8),A=1;A!=M;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=d,D.val=h(D.index++)),k|=(E>0?1:0)*A,A<<=1;R=t(k);break;case 1:for(k=0,M=Math.pow(2,16),A=1;A!=M;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=d,D.val=h(D.index++)),k|=(E>0?1:0)*A,A<<=1;R=t(k);break;case 2:return""}for(f[3]=R,P=R,w.push(R);;){if(D.index>c)return"";for(k=0,M=Math.pow(2,S),A=1;A!=M;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=d,D.val=h(D.index++)),k|=(E>0?1:0)*A,A<<=1;switch(R=k){case 0:for(k=0,M=Math.pow(2,8),A=1;A!=M;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=d,D.val=h(D.index++)),k|=(E>0?1:0)*A,A<<=1;f[y++]=t(k),R=y-1,g--;break;case 1:for(k=0,M=Math.pow(2,16),A=1;A!=M;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=d,D.val=h(D.index++)),k|=(E>0?1:0)*A,A<<=1;f[y++]=t(k),R=y-1,g--;break;case 2:return w.join("")}if(g==0&&(g=Math.pow(2,S),S++),f[R])v=f[R];else if(R===y)v=P+P.charAt(0);else return null;w.push(v),f[y++]=P+v.charAt(0),g--,P=v,g==0&&(g=Math.pow(2,S),S++)}}};return a}();n!=null?n.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})}(Qx)),Qx.exports}var DZ=OZ();const T5=bi(DZ),W1="web image/vnd.tldraw+png",LZ={"image/png":W1},FZ={[W1]:"image/png"};function NZ(n){return Vn(LZ,n)??null}function $Z(n){return Vn(FZ,n)??n}function zZ(n){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(n)}function BZ(n){const e=Object.entries(n);for(const[t,r]of e)r.catch(s=>console.error(s));return navigator.clipboard.write([new ClipboardItem(n)]).catch(t=>(console.error(t),Promise.all(e.map(async([r,s])=>[r,await s])).then(r=>{const s=Q0(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function UZ(n,e,t){var b,P,k;const{elements:r,files:s}=e,o={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:n.store.schema.serialize()},i=new Map,a=new Map,c=n.getCurrentPageId(),d=new Map,h=[],f=new Set;r.forEach(E=>{if(d.set(E.id,Ct()),E.boundElements!==null)for(const M of E.boundElements)M.type==="text"&&f.add(M.id)});let g=yM;for(const E of r){if(f.has(E.id))continue;const M=d.get(E.id),A={id:M,typeName:"shape",parentId:c,index:g,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:HZ(E.opacity),meta:{}};switch(E.angle!==0&&a.set(M,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(b=i.get(E.groupIds[0]))==null||b.push(M):i.set(E.groupIds[0],[M]):h.push(M),E.type){case"rectangle":case"ellipse":case"diamond":{let R="",D="middle";if(E.boundElements!==null){for(const L of E.boundElements)if(L.type==="text"){const U=r.find(K=>K.id===L.id);U&&(R=U.text,D=XZ[U.textAlign])}}const V=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;o.shapes.push({...A,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:zp[E.strokeWidth]??"draw",color:Gu[V]??"black",text:R,align:D,dash:Bp(E),fill:JZ(E)}});break}case"freedraw":{o.shapes.push({...A,type:"draw",props:{dash:Bp(E),size:zp[E.strokeWidth],color:Gu[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([R,D,V=.5])=>({x:R,y:D,z:V}))}]}});break}case"line":{if(E.points.slice().length<2)break;const D=bd(E.points.length);o.shapes.push({...A,type:"line",props:{dash:Bp(E),size:zp[E.strokeWidth],color:Gu[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([V,L],U)=>{const K=D[U];return[K,{id:K,index:K,x:V,y:L}]}))}}});break}case"arrow":{let R="";if(E.boundElements!==null){for(const K of E.boundElements)if(K.type==="text"){const F=r.find($=>$.id===K.id);F&&(R=F.text)}}const D=E.points[0],V=E.points[E.points.length-1],L=d.get((P=E.startBinding)==null?void 0:P.elementId),U=d.get((k=E.endBinding)==null?void 0:k.elementId);o.shapes.push({...A,type:"arrow",props:{text:R,bend:QZ(E,D,V),dash:Bp(E),size:zp[E.strokeWidth]??"m",color:Gu[E.strokeColor]??"black",start:{x:D[0],y:D[1]},end:{x:V[0],y:V[1]},arrowheadEnd:rk[E.endArrowhead]??"none",arrowheadStart:rk[E.startArrowhead]??"none"}}),L&&o.bindings.push({id:nl(),typeName:"binding",type:"arrow",fromId:M,toId:L,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),U&&o.bindings.push({id:nl(),typeName:"binding",type:"arrow",fromId:M,toId:U,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:R,scale:D}=WZ(E.fontSize);o.shapes.push({...A,type:"text",props:{size:R,scale:D,font:GZ[E.fontFamily]??"draw",color:Gu[E.strokeColor]??"black",text:E.text,textAlign:ZZ[E.textAlign]}});break}case"image":{const R=s[E.fileId];if(!R)break;const D=da.createId();o.assets.push({id:D,typeName:"asset",type:"image",props:{w:E.width,h:E.height,fileSize:R.size,name:E.id??"Untitled",isAnimated:!1,mimeType:R.mimeType,src:R.dataURL},meta:{}}),o.shapes.push({...A,type:"image",props:{w:E.width,h:E.height,assetId:D}})}}g=Co(g)}const y=t??(n.inputs.shiftKey?n.inputs.currentPagePoint:void 0);n.markHistoryStoppingPoint("paste"),n.putContentOntoCurrentPage(o,{point:y,select:!1,preserveIds:!0});for(const E of i.values())if(E.length>1){n.groupShapes(E);const M=n.getShape(E[0]);M!=null&&M.parentId&&Mr(M.parentId)&&h.push(M.parentId)}for(const[E,M]of a)n.select(E),n.rotateShapesBy([E],M);const S=Ye(h.map(E=>n.getShape(E))),v=Se.Common(S.map(E=>n.getShapePageBounds(E))),w=n.getViewportPageBounds().center;n.updateShapes(S.map(E=>{const M={x:(E.x??0)-(v.x+v.w/2),y:(E.y??0)-(v.y+v.h/2)};return{id:E.id,type:E.type,x:w.x+M.x,y:w.y+M.y}})),n.setSelectedShapes(h)}const HZ=n=>{const e=n/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},zp={1:"s",2:"m",3:"l",4:"xl"},KZ={16:"s",20:"m",28:"l",36:"xl"};function WZ(n){const e=KZ[n];return e?{size:e,scale:1}:n<16?{size:"s",scale:n/16}:n>36?{size:"xl",scale:n/36}:{size:"m",scale:1}}const GZ={1:"draw",2:"sans",3:"mono"},VZ={gray:["#f8f9fa","#e9ecef","#ced4da","#868e96","#343a40"],red:["#fff5f5","#ffc9c9","#ff8787","#fa5252","#e03131"],pink:["#fff0f6","#fcc2d7","#f783ac","#e64980","#c2255c"],grape:["#f8f0fc","#eebefa","#da77f2","#be4bdb","#9c36b5"],violet:["#f3f0ff","#d0bfff","#9775fa","#7950f2","#6741d9"],indigo:["#edf2ff","#bac8ff","#748ffc","#4c6ef5","#3b5bdb"],blue:["#e7f5ff","#a5d8ff","#4dabf7","#228be6","#1971c2"],cyan:["#e3fafc","#99e9f2","#3bc9db","#15aabf","#0c8599"],teal:["#e6fcf5","#96f2d7","#38d9a9","#12b886","#099268"],green:["#ebfbee","#b2f2bb","#69db7c","#40c057","#2f9e44"],lime:["#f4fce3","#d8f5a2","#a9e34b","#82c91e","#66a80f"],yellow:["#fff9db","#ffec99","#ffd43b","#fab005","#f08c00"],orange:["#fff4e6","#ffd8a8","#ffa94d","#fd7e14","#e8590c"]};function So(n,e,t){const r=[0,1,2,3,4].map(s=>VZ[n][s]);return Object.fromEntries(r.map((s,o)=>[s,o<3?e:t]))}const Gu={...So("gray","grey","black"),...So("red","light-red","red"),...So("pink","light-red","red"),...So("grape","light-violet","violet"),...So("blue","light-blue","blue"),...So("cyan","light-blue","blue"),...So("teal","light-green","green"),...So("green","light-green","green"),...So("yellow","yellow","orange"),...So("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},qZ={solid:"draw",dashed:"dashed",dotted:"dotted"},YZ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},XZ={left:"start",center:"middle",right:"end"},ZZ={left:"start",center:"middle",right:"end"},rk={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function QZ(n,e,t){let r=0;if(n.points.length>2){const s=new C(e[0],e[1]),o=new C(t[0],t[1]),i=new C(n.points[1][0],n.points[1][1]),a=C.Sub(o,s),c=C.Per(a),d=C.Med(o,s),h=C.Sub(d,c),f=C.Add(d,c),g=C.NearestPointOnLineSegment(h,f,i,!1);r=C.Dist(g,d),C.Clockwise(g,o,d)&&(r*=-1)}return r}const Bp=n=>{let e=qZ[n.strokeStyle]??"draw";return e==="draw"&&n.roughness===0&&(e="solid"),e},JZ=n=>n.backgroundColor==="transparent"?"none":YZ[n.fillStyle]??"solid";async function eQ(n,e,t,r){const s=e.map(o=>o instanceof File?o:new File([o],"tldrawFile",{type:o.type}));n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r})}function tQ(n,e,t){const r=n.getSelectionPageBounds();n.markHistoryStoppingPoint("paste"),n.putContentOntoCurrentPage(e,{point:t,select:!0});const s=n.getSelectionPageBounds();r&&s&&(r!=null&&r.collides(s))&&(n.updateInstanceState({isChangingStyle:!0}),n.timers.setTimeout(()=>{n.updateInstanceState({isChangingStyle:!1})},150))}async function x0(n,e,t,r){return n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"url",point:t,url:e,sources:r})}const nQ=[W1,"image/png","image/jpeg","image/webp","image/svg+xml"];function rQ(n){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=n.trim(),e.body.textContent||e.body.innerText||""}const sQ=n=>{try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},oQ=n=>{const e=n.split(/[\n\s]/);for(const t of e)try{const r=new URL(t);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return xj(e)},iQ=n=>/^<svg/.test(n),aQ=["input","select","textarea"];function Jx(n){const{activeElement:e}=document;return n.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||aQ.indexOf(e.tagName.toLowerCase())>-1)}const Up=(n,e,t,r)=>{const s=oQ(e);if(s)for(const o of s)x0(n,o,t);else sQ(e)?x0(n,e,t):iQ(e)?(n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"svg-text",text:e,point:t,sources:r})):(n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"text",text:e,point:t,sources:r}))},lQ=async(n,e,t)=>{if(n.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}}M5(n,r,t)},k5=async({editor:n,clipboardItems:e,point:t,fallbackFiles:r})=>{const s=[];for(const o of e){for(const i of nQ)if(o.types.includes(i)){const a=o.getType(i).then(c=>Gs.rewriteMimeType(c,$Z(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 Gs.blobToText(i)})()}),o.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{const i=await o.getType("text/uri-list");return await Gs.blobToText(i)})()}),o.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{const i=await o.getType("text/plain");return await Gs.blobToText(i)})()})}return r!=null&&r.length&&s.length===1&&s[0].type==="text"&&(s.pop(),s.push(...r.map(o=>({type:"file",source:Promise.resolve(o)})))),await M5(n,s,t)};async function M5(n,e,t){const r=e.filter(o=>(o.type==="file"||o.type==="blob")&&o.source!==null);if(r.length){if(r.length>n.options.maxFilesAtOnce)throw Error("Too many files");const o=Ye(await Promise.all(r.map(i=>i.source)));return await eQ(n,o,t)}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(c=>{var h;const d=(h=c.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:h[1];if(d)try{const f=T5.decompressFromBase64(d);if(f===null){i({type:"error",data:f,reason:"found tldraw data comment but could not parse base64"});return}else{const g=JSON.parse(f);if(g.type!=="application/tldraw"&&i({type:"error",data:g,reason:`found tldraw data comment but JSON was of a different type: ${g.type}`}),typeof g.data=="string"){i({type:"error",data:g,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:g.data});return}}catch{i({type:"error",data:d,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:c,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:c,subtype:"url"});return}try{const f=JSON.parse(c);if(f.type==="excalidraw/clipboard"){i({type:"excalidraw",data:f});return}else{i({type:"text",data:c,subtype:"json"});return}}catch{i({type:"text",data:c,subtype:"text"});return}}i({type:"error",data:c,reason:"unhandled case"})})})));for(const o of s)if(o.type==="tldraw"){tQ(n,o.data,t);return}for(const o of s)if(o.type==="excalidraw"){UZ(n,o.data,t);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(d=>d.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const d=a.firstElementChild.getAttribute("href");Up(n,d,t,s);return}if(!s.some(d=>d.type==="text"&&d.subtype!=="html")&&o.data.trim()){Up(n,rQ(o.data),t,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(d=>d.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="IFRAME"&&a.firstElementChild.hasAttribute("src")&&a.firstElementChild.getAttribute("src")!==""){const d=a.firstElementChild.getAttribute("src");Up(n,d,t,s);return}}}for(const o of s)if(o.type==="text"&&o.subtype==="url"){x0(n,o.data,t,s);return}for(const o of s)if(o.type==="text"&&o.subtype==="text"&&o.data.trim()){Up(n,o.data,t,s);return}}const ag=async n=>{var r;const e=await n.resolveAssetsInContent(n.getContentFromCurrentPage(n.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=T5.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const s=e.shapes.map(o=>n.getShapeUtil(o).getText(o)).filter(nz);if((r=navigator.clipboard)!=null&&r.write){const o=new Blob([`<div data-tldraw>${t}</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>${t}</div>`)}};function cQ(){const n=te(),e=On(),t=_.useCallback(async function(i){n.getSelectedShapeIds().length!==0&&(await ag(n),e("copy",{source:i}))},[n,e]),r=_.useCallback(async function(i){n.getSelectedShapeIds().length!==0&&(await ag(n),n.deleteShapes(n.getSelectedShapeIds()),e("cut",{source:i}))},[n,e]),s=_.useCallback(async function(i,a,c){n.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(k5({editor:n,clipboardItems:i,point:c}),e("paste",{source:"menu"})):navigator.clipboard.read().then(d=>{s(d,a,c)}))},[n,e]);return{copy:t,cut:r,paste:s}}function uQ(){const n=te(),e=On(),t=se("editor.isFocused",()=>n.getInstanceState().isFocused,[n]);_.useEffect(()=>{if(!t)return;const r=async c=>{n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||Jx(n)||(Je(c),await ag(n),e("copy",{source:"kbd"}))};async function s(c){n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||Jx(n)||(Je(c),await ag(n),n.deleteShapes(n.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let o=!1;const i=c=>{c.button===1&&(o=!0,n.timers.requestAnimationFrame(()=>{o=!1}))},a=c=>{var g,y;if(o){ln(c);return}if(n.getEditingShapeId()!==null||Jx(n))return;let d,h=!1;n.inputs.shiftKey&&(h=!0),n.user.getIsPasteAtCursorMode()&&(h=!h),h&&(d=n.inputs.currentPagePoint);const f=()=>{c.clipboardData&&lQ(n,c.clipboardData,d)};if((g=navigator.clipboard)!=null&&g.read){const S=Array.from(((y=c.clipboardData)==null?void 0:y.files)||[]);navigator.clipboard.read().then(v=>{Array.isArray(v)&&v[0]instanceof ClipboardItem&&k5({editor:n,clipboardItems:v,point:d,fallbackFiles:S})},()=>{f()})}else f();Je(c),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)}},[n,e,t])}const dQ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",svg:"text/plain"};function hQ(n,e,t={}){const r=e!=null&&e.length?e:[...n.getCurrentPageShapeIds()],s=t.format??"png";return{blobPromise:n.toImage(r,t).then(o=>o.blob),mimeType:dQ[s]}}function pQ(...n){const[e,t,r]=typeof n[2]=="string"?[n[0],n[1],{...n[3],format:n[2]}]:n;if(!navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(navigator.clipboard.write){const{blobPromise:s,mimeType:o}=hQ(e,t,r),i={[o]:s},a=NZ(o);return a&&zZ(a)&&(i[a]=s.then(c=>Gs.rewriteMimeType(c,a))),BZ(i)}switch(r.format){case"svg":return fQ(async()=>{const s=await e.getSvgString(t,r);if(!s)throw new Error("Failed to copy");return s.svg});case"png":throw new Error("Copy not supported");default:un(r.format)}}async function fQ(n){var e,t;await((t=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:t.call(e,await n()))}function gQ(){const n=te(),{addToast:e}=Ii(),t=it();return _.useCallback((r,s="svg")=>{pQ(n,r,{format:s}).catch(()=>{e({id:"copy-fail",severity:"warning",title:t("toast.error.copy-fail.title"),description:t("toast.error.copy-fail.desc")})})},[n,e,t])}async function mQ(...n){const[e,t,r]=typeof n[2]=="object"?n:[n[0],n[1],{...n[4],format:n[2]??"png",name:n[3]}];let s=r.name;if(!s&&(s=`shapes at ${sk()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?s=a.props.name||"frame":s=`${kg(a.id)} at ${sk()}`}s+=`.${r.format}`;const{blob:o}=await e.toImage(t,r),i=new File([o],s,{type:o.type});yQ(i)}function sk(){const n=new Date,e=String(n.getFullYear()).slice(2),t=String(n.getMonth()+1).padStart(2,"0"),r=String(n.getDate()).padStart(2,"0"),s=String(n.getHours()).padStart(2,"0"),o=String(n.getMinutes()).padStart(2,"0"),i=String(n.getSeconds()).padStart(2,"0");return`${e}-${t}-${r} ${s}.${o}.${i}`}function yQ(n){const e=document.createElement("a"),t=URL.createObjectURL(n);e.href=t,e.download=n.name,e.click(),URL.revokeObjectURL(t)}function SQ(){const n=te(),{addToast:e}=Ii(),t=it();return _.useCallback((r,s="png",o)=>{mQ(n,r,{format:s,name:o,scale:1}).catch(i=>{console.error(i.message),e({id:"export-fail",title:t("toast.error.export-fail.title"),description:t("toast.error.export-fail.desc"),severity:"error"})})},[n,e,t])}const A5=at.createContext([]);function vQ(){const n=te(),e=_.useRef(),t=ra(at.useContext(A5));return _.useEffect(()=>{const r=window.document.createElement("input");r.type="file",r.accept=(t==null?void 0:t.join(","))??j6,r.multiple=!0,e.current=r;async function s(o){const i=o.target.files;!i||i.length===0||(n.markHistoryStoppingPoint("insert media"),await n.putExternalContent({type:"files",files:Array.from(i),point:n.getViewportPageBounds().center,ignoreParent:!1}),r.value="")}return r.addEventListener("change",s),()=>{e.current=void 0,r.removeEventListener("change",s)}},[n,t]),_.useCallback(()=>{var r;(r=e.current)==null||r.click()},[e])}function xQ(){const n=te(),e=_.useRef(null),t=_.useRef(null);return _.useCallback(async function(){const s=document.createElement("div"),o=document.createElement("style"),i=(b,P)=>{b&&(b.innerHTML=""),P&&document.head.contains(P)&&document.head.removeChild(P),b&&document.body.contains(b)&&document.body.removeChild(b)};i(e.current,t.current),e.current=s,t.current=o;const a=`tl-print-surface-${xt()}`;s.className=a,o.innerHTML=`
|
|
251
|
+
.${a} {
|
|
252
|
+
display: none;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.${a} svg {
|
|
256
|
+
max-width: 100%;
|
|
257
|
+
height: 100%;
|
|
258
|
+
display: block;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@media print {
|
|
262
|
+
html, body {
|
|
263
|
+
min-height: 100%;
|
|
264
|
+
height: 100%;
|
|
265
|
+
margin: 0;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
body {
|
|
269
|
+
position: relative;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
body > * {
|
|
273
|
+
display: none;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.tldraw__editor {
|
|
277
|
+
display: none;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.${a} {
|
|
281
|
+
display: block !important;
|
|
282
|
+
background: white;
|
|
283
|
+
min-height: 100%;
|
|
284
|
+
height: 100%;
|
|
285
|
+
max-width: 100%;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.${a}__item {
|
|
289
|
+
padding: 10mm;
|
|
290
|
+
display: flex;
|
|
291
|
+
min-height: 100%;
|
|
292
|
+
flex-direction: column;
|
|
293
|
+
page-break-after: always;
|
|
294
|
+
position: relative;
|
|
295
|
+
overflow: hidden;
|
|
296
|
+
height: 100%;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.${a}__item__main {
|
|
300
|
+
flex: 1;
|
|
301
|
+
display: flex;
|
|
302
|
+
align-items: center;
|
|
303
|
+
justify-content: center;
|
|
304
|
+
max-height: 100%;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.${a}__item__header {
|
|
308
|
+
display: none;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.${a}__item__footer {
|
|
312
|
+
display: none;
|
|
313
|
+
text-align: right;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.${a}__item__footer__hide {
|
|
317
|
+
display: none;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
`;const c=()=>{document.head.appendChild(o),document.body.appendChild(s)},d=()=>{n.once("tick",()=>{i(s,o)})};window.addEventListener("beforeprint",c),window.addEventListener("afterprint",d);function h(b,P,k){try{s.innerHTML+=`<div class="${a}__item">
|
|
324
|
+
<div class="${a}__item__header">
|
|
325
|
+
${b.replace(/</g,"<").replace(/>/g,">")}
|
|
326
|
+
</div>
|
|
327
|
+
<div class="${a}__item__main">
|
|
328
|
+
${k}
|
|
329
|
+
</div>
|
|
330
|
+
<div class="${a}__item__footer ${a}__item__footer__${P?"":"hide"}">
|
|
331
|
+
${P??""}
|
|
332
|
+
</div>
|
|
333
|
+
</div>`}catch(E){console.error(E)}}function f(){Et.isChromeForIos?(c(),window.print()):Et.isSafari?(c(),document.execCommand("print",!1)):window.print()}const g=n.getSelectedShapeIds(),y=n.getCurrentPageId(),S=n.getPages(),w={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(n.getSelectedShapeIds().length>0){const b=await n.getSvgString(g,w);if(b){const P=S.find(k=>k.id===y);h(`tldraw — ${P==null?void 0:P.name}`,null,b.svg),f()}}else{const b=n.getCurrentPage(),P=await n.getSvgString(n.getSortedChildIdsForParent(b.id),w);P&&(h(`tldraw — ${b.name}`,null,P.svg),f())}window.removeEventListener("beforeprint",c),window.removeEventListener("afterprint",d)},[n])}function G1(){const{addToast:n,removeToast:e,clearToasts:t}=Ii(),{addDialog:r,clearDialogs:s,removeDialog:o}=ah(),i=it(),a=vQ(),c=xQ(),{cut:d,copy:h,paste:f}=cQ(),g=gQ(),y=SQ(),S=z1(),w=ur()<Jt.TABLET_SM;return _.useMemo(()=>({addToast:n,removeToast:e,clearToasts:t,addDialog:r,removeDialog:o,clearDialogs:s,msg:i,isMobile:w,insertMedia:a,printSelectionOrPages:c,cut:d,copy:h,paste:f,copyAs:g,exportAs:y,getEmbedDefinition:S}),[n,e,t,r,o,s,i,w,a,c,d,h,f,g,y,S])}function wQ(n,e){const t={};for(const r of n)if(r.translations)for(const[s,o]of Lr(r.translations)){let i=t[s];i||(i=t[s]={}),Object.assign(i,o)}return{actions:(r,s,o)=>{for(const i of n)i.actions&&(s=i.actions(r,s,o));return s},tools:(r,s,o)=>{for(const i of n)i.tools&&(s=i.tools(r,s,{...e,...o}));return s},translations:t}}function j5(n){return _.useMemo(()=>n,n)}function bQ(n){const e=j5(n==null?[]:Array.isArray(n)?n:[n]);return _.useMemo(()=>{const t={};for(const r of e)if(r.translations)for(const[s,o]of Lr(r.translations)){let i=t[s];i||(i=t[s]={}),Object.assign(i,o)}return t},[e])}function PQ(n){const e=G1(),t=j5(n==null?[]:Array.isArray(n)?n:[n]);return _.useMemo(()=>wQ(t,e),[t,e])}const R5=_.createContext(null);function CQ(n){return Object.fromEntries(n.map(e=>[e.id,e]))}function Hp(n,e){if(n.getSelectedShapes().length===0)return n.getDocumentSettings().name||e}function _Q({overrides:n,children:e}){const t=te(),r=cm(),s=G1(),o=On(),i=s.msg("document.default-name"),a=_.useMemo(()=>{function c(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function d(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const h=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(g){d()&&(c()||(o("edit-link",{source:g}),t.markHistoryStoppingPoint("edit-link"),s.addDialog({component:JX})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(g){o("insert-embed",{source:g}),s.addDialog({component:p5})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(g){o("insert-media",{source:g}),s.insertMedia()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(g){o("undo",{source:g}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(g){o("redo",{source:g}),t.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(g){let y=t.getSelectedShapeIds();y.length===0&&(y=Array.from(t.getCurrentPageShapeIds().values())),y.length!==0&&(o("export-as",{format:"svg",source:g}),s.exportAs(y,"svg",Hp(t,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(g){let y=t.getSelectedShapeIds();y.length===0&&(y=Array.from(t.getCurrentPageShapeIds().values())),y.length!==0&&(o("export-as",{format:"png",source:g}),s.exportAs(y,"png",Hp(t,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(g){let y=t.getSelectedShapeIds();y.length===0&&(y=Array.from(t.getCurrentPageShapeIds().values())),y.length!==0&&(o("export-all-as",{format:"svg",source:g}),s.exportAs(Array.from(t.getCurrentPageShapeIds()),"svg",Hp(t,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(g){const y=Array.from(t.getCurrentPageShapeIds().values());y.length!==0&&(o("export-all-as",{format:"png",source:g}),s.exportAs(y,"png",Hp(t,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(g){let y=t.getSelectedShapeIds();y.length===0&&(y=Array.from(t.getCurrentPageShapeIds().values())),y.length!==0&&(o("copy-as",{format:"svg",source:g}),s.copyAs(y,"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(g){let y=t.getSelectedShapeIds();y.length===0&&(y=Array.from(t.getCurrentPageShapeIds().values())),y.length!==0&&(o("copy-as",{format:"png",source:g}),s.copyAs(y,"png"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(g){if(!d()||c())return;o("toggle-auto-size",{source:g}),t.markHistoryStoppingPoint("toggling auto size");const y=t.getSelectedShapes().filter(S=>t.isShapeOfType(S,"text")&&S.props.autoSize===!1);t.updateShapes(y.map(S=>({id:S.id,type:S.type,props:{...S.props,w:8,autoSize:!0}}))),jt(t,y.map(S=>S.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(g){o("open-embed-link",{source:g});const y=t.getSelectedShapeIds(),S="No embed shapes selected";if(y.length!==1){console.error(S);return}const v=t.getShape(y[0]);if(!v||!t.isShapeOfType(v,"embed")){console.error(S);return}_G(v.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(g){var y,S;if(((y=t.root.getCurrent())==null?void 0:y.id)!=="zoom"&&(o("zoom-tool",{source:g}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const v=t.root.getCurrent();v&&((S=v.getCurrent())==null?void 0:S.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:v.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(g){d()&&(c()||t.run(()=>{o("convert-to-bookmark",{source:g});const y=t.getSelectedShapes(),S=[],v=[];for(const w of y){if(!w||!t.isShapeOfType(w,"embed")||!w.props.url)continue;const b=new C(w.x,w.y);b.rot(-w.rotation),b.add(new C(w.props.w/2-300/2,w.props.h/2-320/2)),b.rot(w.rotation);const P={id:Ct(),type:"bookmark",rotation:w.rotation,x:b.x,y:b.y,opacity:1,props:{url:w.props.url}};S.push(P),v.push(w.id)}t.markHistoryStoppingPoint("convert shapes to bookmark"),t.deleteShapes(v),t.createShapes(S)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(g){d()&&(c()||(o("convert-to-embed",{source:g}),t.run(()=>{const y=t.getSelectedShapeIds(),S=Ye(y.map(b=>t.getShape(b))),v=[],w=[];for(const b of S){if(!t.isShapeOfType(b,"bookmark"))continue;const{url:P}=b.props,k=s.getEmbedDefinition(P);if(!k||!k.definition)continue;const{width:E,height:M}=k.definition,A=new C(b.x,b.y);A.rot(-b.rotation),A.add(new C(b.props.w/2-E/2,b.props.h/2-M/2)),A.rot(b.rotation);const R={id:Ct(),type:"embed",x:A.x,y:A.y,rotation:b.rotation,props:{url:P,w:E,h:M}};v.push(R),w.push(b.id)}t.markHistoryStoppingPoint("convert shapes to embed"),t.deleteShapes(w),t.createShapes(v)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(g){if(!d()||c())return;o("duplicate-shapes",{source:g});const y=t.getInstanceState();let S,v;if(y.duplicateProps)S=y.duplicateProps.shapeIds,v=y.duplicateProps.offset;else{S=t.getSelectedShapeIds();const w=Se.Common(Ye(S.map(b=>t.getShapePageBounds(b))));v=t.getCameraOptions().isLocked?{x:t.options.adjacentShapeMargin,y:t.options.adjacentShapeMargin}:{x:w.width+t.options.adjacentShapeMargin,y:0}}t.markHistoryStoppingPoint("duplicate shapes"),t.duplicateShapes(S,v),y.duplicateProps&&t.updateInstanceState({duplicateProps:{...y.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(g){d()&&(c()||(o("ungroup-shapes",{source:g}),t.markHistoryStoppingPoint("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(g){if(!d()||c())return;o("group-shapes",{source:g});const y=t.getOnlySelectedShape();y&&t.isShapeOfType(y,"group")?(t.markHistoryStoppingPoint("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())):(t.markHistoryStoppingPoint("group"),t.groupShapes(t.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(g){if(!d())return;o("remove-frame",{source:g});const y=t.getSelectedShapes();y.length>0&&y.every(S=>t.isShapeOfType(S,"frame"))&&(t.markHistoryStoppingPoint("remove-frame"),AX(t,y.map(S=>S.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(g){if(!d())return;o("fit-frame-to-content",{source:g});const y=t.getOnlySelectedShape();y&&t.isShapeOfType(y,"frame")&&(t.markHistoryStoppingPoint("fit-frame-to-content"),RX(t,y.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(g){if(!d()||c())return;o("align-shapes",{operation:"left",source:g}),t.markHistoryStoppingPoint("align left");const y=t.getSelectedShapeIds();t.alignShapes(y,"left"),jt(t,y)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(g){if(!d()||c())return;o("align-shapes",{operation:"center-horizontal",source:g}),t.markHistoryStoppingPoint("align center horizontal");const y=t.getSelectedShapeIds();t.alignShapes(y,"center-horizontal"),jt(t,y)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(g){if(!d()||c())return;o("align-shapes",{operation:"right",source:g}),t.markHistoryStoppingPoint("align right");const y=t.getSelectedShapeIds();t.alignShapes(y,"right"),jt(t,y)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(g){if(!d()||c())return;o("align-shapes",{operation:"center-vertical",source:g}),t.markHistoryStoppingPoint("align center vertical");const y=t.getSelectedShapeIds();t.alignShapes(y,"center-vertical"),jt(t,y)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(g){if(!d()||c())return;o("align-shapes",{operation:"top",source:g}),t.markHistoryStoppingPoint("align top");const y=t.getSelectedShapeIds();t.alignShapes(y,"top"),jt(t,y)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(g){if(!d()||c())return;o("align-shapes",{operation:"bottom",source:g}),t.markHistoryStoppingPoint("align bottom");const y=t.getSelectedShapeIds();t.alignShapes(y,"bottom"),jt(t,y)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(g){if(!d()||c())return;o("distribute-shapes",{operation:"horizontal",source:g}),t.markHistoryStoppingPoint("distribute horizontal");const y=t.getSelectedShapeIds();t.distributeShapes(y,"horizontal"),jt(t,y)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(g){if(!d()||c())return;o("distribute-shapes",{operation:"vertical",source:g}),t.markHistoryStoppingPoint("distribute vertical");const y=t.getSelectedShapeIds();t.distributeShapes(y,"vertical"),jt(t,y)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(g){if(!d()||c())return;o("stretch-shapes",{operation:"horizontal",source:g}),t.markHistoryStoppingPoint("stretch horizontal");const y=t.getSelectedShapeIds();t.stretchShapes(y,"horizontal"),jt(t,y)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(g){if(!d()||c())return;o("stretch-shapes",{operation:"vertical",source:g}),t.markHistoryStoppingPoint("stretch vertical");const y=t.getSelectedShapeIds();t.stretchShapes(y,"vertical"),jt(t,y)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(g){if(!d()||c())return;o("flip-shapes",{operation:"horizontal",source:g}),t.markHistoryStoppingPoint("flip horizontal");const y=t.getSelectedShapeIds();t.flipShapes(y,"horizontal"),jt(t,y)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(g){if(!d()||c())return;o("flip-shapes",{operation:"vertical",source:g}),t.markHistoryStoppingPoint("flip vertical");const y=t.getSelectedShapeIds();t.flipShapes(y,"vertical"),jt(t,y)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(g){if(!d()||c())return;o("pack-shapes",{source:g}),t.markHistoryStoppingPoint("pack");const y=t.getSelectedShapeIds();t.packShapes(y,t.options.adjacentShapeMargin),jt(t,y)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(g){if(!d()||c())return;o("stack-shapes",{operation:"vertical",source:g}),t.markHistoryStoppingPoint("stack-vertical");const y=t.getSelectedShapeIds();t.stackShapes(y,"vertical",16),jt(t,y)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(g){if(!d()||c())return;o("stack-shapes",{operation:"horizontal",source:g}),t.markHistoryStoppingPoint("stack-horizontal");const y=t.getSelectedShapeIds();t.stackShapes(y,"horizontal",16),jt(t,y)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(g){d()&&(c()||(o("reorder-shapes",{operation:"toFront",source:g}),t.markHistoryStoppingPoint("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(g){d()&&(c()||(o("reorder-shapes",{operation:"forward",source:g}),t.markHistoryStoppingPoint("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(g){d()&&(c()||(o("reorder-shapes",{operation:"backward",source:g}),t.markHistoryStoppingPoint("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(g){d()&&(c()||(o("reorder-shapes",{operation:"toBack",source:g}),t.markHistoryStoppingPoint("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(g){d()&&(c()||(t.markHistoryStoppingPoint("cut"),s.cut(g)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(g){d()&&(c()||s.copy(g))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(g){var y;(y=navigator.clipboard)==null||y.read().then(S=>{s.paste(S,g,g==="context-menu"?t.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(g){t.run(()=>{c()||(o("select-all-shapes",{source:g}),t.markHistoryStoppingPoint("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(g){d()&&(c()||(o("select-none-shapes",{source:g}),t.markHistoryStoppingPoint("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(g){d()&&(c()||(o("delete-shapes",{source:g}),t.markHistoryStoppingPoint("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(g){if(!d()||c())return;o("rotate-cw",{source:g}),t.markHistoryStoppingPoint("rotate-cw");const y=t.getSelectionRotation()%(Rt/2),S=la(y,0)||la(y,Rt/2),v=t.getSelectedShapeIds();t.rotateShapesBy(v,Rt/2-(S?0:y)),jt(t,v)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(g){if(!d()||c())return;o("rotate-ccw",{source:g}),t.markHistoryStoppingPoint("rotate-ccw");const y=t.getSelectionRotation()%(Rt/2),S=la(y,0),v=t.getSelectedShapeIds();t.rotateShapesBy(v,S?-(Rt/2):-y),jt(t,v)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(g){o("zoom-in",{source:g}),t.zoomIn(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(g){o("zoom-out",{source:g}),t.zoomOut(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(g){o("reset-zoom",{source:g}),t.resetZoom(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(g){o("zoom-to-fit",{source:g}),t.zoomToFit({animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(g){d()&&(c()||(o("zoom-to-selection",{source:g}),t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(g){o("toggle-snap-mode",{source:g}),t.user.updateUserPreferences({isSnapMode:!t.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(g){const y=t.user.getIsDarkMode()?"light":"dark";o("color-scheme",{source:g,value:y}),t.user.updateUserPreferences({colorScheme:y})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(g){o("toggle-wrap-mode",{source:g}),t.user.updateUserPreferences({isWrapMode:!t.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(g){o("toggle-dynamic-size-mode",{source:g}),t.user.updateUserPreferences({isDynamicSizeMode:!t.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(g){o("toggle-paste-at-cursor",{source:g}),t.user.updateUserPreferences({isPasteAtCursorMode:!t.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(g){o("toggle-reduce-motion",{source:g}),t.user.updateUserPreferences({animationSpeed:t.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(g){o("toggle-edge-scrolling",{source:g}),t.user.updateUserPreferences({edgeScrollSpeed:t.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(g){o("toggle-transparent",{source:g}),t.updateInstanceState({exportBackground:!t.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(g){o("toggle-tool-lock",{source:g}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(g){o("unlock-all",{source:g});const y=[];for(const S of t.getCurrentPageShapes())S.isLocked&&y.push({id:S.id,type:S.type,isLocked:!1});y.length>0&&t.updateShapes(y)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(g){t.timers.requestAnimationFrame(()=>{t.run(()=>{o("toggle-focus-mode",{source:g}),s.clearDialogs(),s.clearToasts(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(g){o("toggle-grid-mode",{source:g}),t.updateInstanceState({isGridMode:!t.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(g){o("toggle-debug-mode",{source:g}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(g){o("print",{source:g}),s.printSelectionOrPages()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(g){o("exit-pen-mode",{source:g}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(g){o("stop-following",{source:g}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(g){o("zoom-to-content",{source:g});const y=t.getSelectionPageBounds()??t.getCurrentPageBounds();y&&t.zoomToBounds(y,{targetZoom:Math.min(1,t.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(g){t.markHistoryStoppingPoint("locking"),o("toggle-lock",{source:g}),t.toggleLock(t.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(g){const y=ss.createId(),S=t.getSelectedShapeIds();t.run(()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.createPage({name:s.msg("page-menu.new-page-initial-name"),id:y}),t.moveShapesToPage(S,y)}),o("move-to-new-page",{source:g})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(g){const y=rs;t.run(()=>{t.markHistoryStoppingPoint("change-color"),t.isIn("select")&&t.setStyleForSelectedShapes(y,"white"),t.setStyleForNextShapes(y,"white")}),o("set-style",{source:g,id:y.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(g){const y=ll;t.run(()=>{t.markHistoryStoppingPoint("change-fill"),t.isIn("select")&&t.setStyleForSelectedShapes(y,"fill"),t.setStyleForNextShapes(y,"fill")}),o("set-style",{source:g,id:y.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async g=>{const y=t.getSelectedShapeIds();if(y.length===0)return;t.markHistoryStoppingPoint("flattening to image"),o("flatten-to-image",{source:g});const S=await aZ(t,y,t.options.flattenImageBoundsExpand);S!=null&&S.length&&t.setSelectedShapes(S)}},{id:"select-geo-tool",kbd:"g",onSelect:async g=>{o("select-tool",{source:g,id:"geo-previous"}),t.setCurrentTool("geo")}}];r&&h.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(g){o("open-cursor-chat",{source:g}),!t.getInstanceState().isCoarsePointer&&t.timers.requestAnimationFrame(()=>{t.updateInstanceState({isChatting:!0})})}});const f=CQ(h);return n?n(t,f,s):f},[s,t,o,n,i,r]);return p.jsx(R5.Provider,{value:a,children:e})}function wl(){const n=_.useContext(R5);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function jd(n,e){return n?typeof n=="string"?n:e?n[e]??n.default:void 0:void 0}function is(){const n=wa();return se("isReadonlyMode",()=>!!(n!=null&&n.getIsReadonly()),[n])}const IQ=Et.isDarwin?"⌘":"Ctrl",EQ=Et.isDarwin?"⌥":"Alt";function O5(n){return n===","?[","]:n.split(",")[0].split("").map(e=>{const t=e.replace(/\$/g,IQ).replace(/\?/g,EQ).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function w0(n){return"— "+O5(n).join(" ")}function fd({children:n,visibleOnMobileLayout:e=!1}){const t=ur();return!e&&t<Jt.MOBILE?null:p.jsx("kbd",{className:"tlui-kbd",children:O5(n).map((r,s)=>p.jsx("span",{children:r},s))})}const D5=_.createContext(null);function hm(){const n=_.useContext(D5);if(!n)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return n}function Es({type:n,sourceId:e,children:t}){return p.jsx(D5.Provider,{value:{type:n,sourceId:e},children:t})}function pm({id:n,kbd:e,label:t,readonlyOk:r,onSelect:s,toggle:o=!1,disabled:i=!1,checked:a=!1}){const{type:c,sourceId:d}=hm(),h=is(),f=it();if(h&&!r)return null;const g=jd(t,c),y=g?f(g):void 0;switch(c){case"menu":return p.jsxs(EX,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:y,onSelect:S=>{s==null||s(d),Je(S)},disabled:i,checked:a,children:[p.jsx(Fo,{small:!0,icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),y&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:y}),e&&p.jsx(fd,{children:e})]});case"context-menu":return p.jsxs(rX,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:y,onSelect:S=>{s(d),Je(S)},disabled:i,checked:a,children:[p.jsx(Fo,{small:!0,icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),y&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:y}),e&&p.jsx(fd,{children:e})]},n);default:return null}}function Ei(n,e){const t=wa(),r=_.useCallback(i=>{i&&(t==null||t.complete()),e==null||e(i)},[t,e]),s=On(),o=_.useCallback(i=>{s(i,{source:"unknown",id:n})},[n,s]);return yG(t?`${n}-${t.contextId}`:n,r,o)}function hl({id:n,children:e,modal:t=!1,debugOpen:r=!1}){const[s,o]=Ei(n);return p.jsx(M1,{open:r||s,dir:"ltr",modal:t,onOpenChange:o,children:e})}function pl({children:n,...e}){return p.jsx(A1,{dir:"ltr",asChild:!0,onTouchEnd:t=>Je(t),...e,children:n})}function fl({className:n,side:e="bottom",align:t="start",sideOffset:r=8,alignOffset:s=8,children:o}){const i=fn();return p.jsx(sm,{container:i,children:p.jsx(j1,{className:Le("tlui-menu",n),side:e,sideOffset:r,align:t,alignOffset:s,collisionPadding:4,children:o})})}function TQ({id:n,children:e}){const[t,r]=Ei(n);return p.jsx(TX,{open:t,onOpenChange:r,children:e})}function kQ({id:n,label:e,title:t,disabled:r}){return p.jsx(kX,{dir:"ltr",asChild:!0,disabled:r,children:p.jsxs(Ne,{"data-testid":n,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[p.jsx(on,{children:e}),p.jsx(nt,{icon:"chevron-right",small:!0})]})})}function MQ({id:n,alignOffset:e=-1,sideOffset:t=-6,size:r="small",children:s}){const o=fn();return p.jsx(sm,{container:o,children:p.jsx(MX,{"data-testid":n,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:t,collisionPadding:4,"data-size":r,children:s})})}function AQ({children:n}){return p.jsx(_X,{dir:"ltr",className:"tlui-menu__group",children:n})}function Rd({noClose:n,children:e}){return p.jsx(IX,{dir:"ltr",asChild:!0,onClick:n?Je:void 0,children:e})}function Qe({id:n,label:e,children:t}){const{type:r,sourceId:s}=hm(),o=it(),i=jd(e,r),a=i?o(i):void 0;switch(r){case"panel":return p.jsx("div",{className:"tlui-menu__group","data-testid":`${s}-group.${n}`,children:t});case"menu":return p.jsx(AQ,{"data-testid":`${s}-group.${n}`,children:t});case"context-menu":return p.jsx(ML,{dir:"ltr",className:"tlui-menu__group","data-testid":`${s}-group.${n}`,children:t});case"keyboard-shortcuts":return p.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${s}-group.${n}`,children:[p.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),p.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function zr({id:n,disabled:e=!1,label:t,size:r="small",children:s}){const{type:o,sourceId:i}=hm(),a=fn(),c=it(),d=t?typeof t=="string"?t:t[o]??t.default:void 0,h=d?c(d):void 0;switch(o){case"menu":return p.jsxs(TQ,{id:`${i}-sub.${n}`,children:[p.jsx(kQ,{id:`${i}-sub.${n}-button`,disabled:e,label:h,title:h}),p.jsx(MQ,{id:`${i}-sub.${n}-content`,size:r,children:s})]});case"context-menu":return e?null:p.jsxs(jQ,{id:`${i}-sub.${n}`,children:[p.jsx(OL,{dir:"ltr",disabled:e,asChild:!0,children:p.jsxs(Ne,{"data-testid":`${i}-sub.${n}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[p.jsx(on,{children:h}),p.jsx(nt,{icon:"chevron-right",small:!0})]})}),p.jsx(T1,{container:a,children:p.jsx(DL,{"data-testid":`${i}-sub.${n}-content`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:s})})]});default:return s}}function jQ({id:n,children:e}){const[t,r]=Ei(n);return p.jsx(RL,{open:t,onOpenChange:r,children:e})}const RQ=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function OQ(){const n=te(),e=On(),t=se("colorScheme",()=>n.user.getUserPreferences().colorScheme??(n.user.getIsDarkMode()?"dark":"light"),[n]);return p.jsx(zr,{id:"help menu color-scheme",label:"menu.theme",children:p.jsx(Qe,{id:"theme",children:RQ.map(({colorScheme:r,label:s})=>p.jsx(pm,{id:`color-scheme-${r}`,label:s,checked:r===t,readonlyOk:!0,onSelect:()=>{n.user.updateUserPreferences({colorScheme:r}),e("color-scheme",{source:"menu",value:r})}},r))})})}const DQ=({id:n,component:e,onClose:t,preventBackgroundClose:r})=>{const{removeDialog:s}=ah(),o=_.useRef(!1),i=fn(),a=_.useCallback(c=>{if(!c){if(t)try{t()}catch(d){console.warn(d)}s(n)}},[n,t,s]);return p.jsx(qX,{onOpenChange:a,defaultOpen:!0,children:p.jsx(YX,{container:i,children:p.jsx(XX,{dir:"ltr",className:"tlui-dialog__overlay",onClick:c=>{o.current||!r&&c.target===c.currentTarget&&a(!1)},children:p.jsx(ZX,{dir:"ltr",className:"tlui-dialog__content","aria-describedby":void 0,onMouseDown:()=>o.current=!0,onMouseUp:()=>o.current=!1,onInteractOutside:c=>{o.current=!1,r&&c.preventDefault()},children:p.jsx(e,{onClose:()=>{o.current=!1,a(!1)}})})})})})},LQ=_.memo(function(){const{dialogs:e}=ah();return se("dialogs",()=>e.get(),[e]).map(r=>p.jsx(DQ,{...r},r.id))}),FQ=4e3,NQ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function $Q({toast:n}){const{removeToast:e}=Ii(),t=it(),r=i=>{i||e(n.id)},s=n.actions&&n.actions.length>0,o=n.icon||n.severity&&NQ[n.severity];return p.jsxs(kZ,{onOpenChange:r,className:"tlui-toast__container",duration:n.keepOpen?1/0:FQ,"data-severity":n.severity,children:[o&&p.jsx("div",{className:"tlui-toast__icon",children:p.jsx(Fo,{icon:o})}),p.jsxs("div",{className:"tlui-toast__main","data-title":!!n.title,"data-description":!!n.description,"data-actions":!!n.actions,children:[p.jsxs("div",{className:"tlui-toast__content",children:[n.title&&p.jsx(MZ,{className:"tlui-toast__title",children:n.title}),n.description&&p.jsx(AZ,{className:"tlui-toast__description",children:n.description})]}),n.actions&&p.jsxs("div",{className:"tlui-toast__actions",children:[n.actions.map((i,a)=>p.jsx(jZ,{altText:i.label,asChild:!0,onClick:i.onClick,children:p.jsx(Ne,{type:i.type,children:p.jsx(on,{children:i.label})})},a)),p.jsx(tk,{asChild:!0,children:p.jsx(Ne,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:p.jsx(on,{children:n.closeLabel??t("toast.close")})})})]})]}),!s&&p.jsx(tk,{asChild:!0,children:p.jsx(Ne,{type:"normal",className:"tlui-toast__close",children:p.jsx(on,{children:n.closeLabel??t("toast.close")})})})]})}const zQ=_.memo(function(){const{toasts:e}=Ii(),t=se("toasts",()=>e.get(),[]);return p.jsxs(p.Fragment,{children:[t.map(r=>p.jsx($Q,{toast:r},r.id)),p.jsx(S5,{className:"tlui-toast__viewport"})]})});function so({actionId:n="",...e}){const r=wl()[n];return r?p.jsx(pm,{...r,...e}):null}function ok(n){return p.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...n,children:p.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[p.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),p.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:p.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}function En({disabled:n=!1,spinner:e=!1,readonlyOk:t=!1,id:r,kbd:s,label:o,icon:i,onSelect:a,noClose:c,isSelected:d}){const{type:h,sourceId:f}=hm(),g=it(),[y,S]=_.useState(!1);if(is()&&!t)return null;const w=jd(o,h),b=s?w0(s):void 0,P=w?g(w):void 0,k=P&&b?`${P} ${b}`:P;switch(h){case"menu":return p.jsx(Rd,{children:p.jsxs(Ne,{type:"menu","data-testid":`${f}.${r}`,disabled:n,title:k,onClick:E=>{c&&Je(E),y?S(!1):a(f)},children:[p.jsx(on,{children:P}),s&&p.jsx(fd,{children:s})]})});case"context-menu":return n?null:p.jsxs(AL,{dir:"ltr",title:k,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${f}.${r}`,onSelect:E=>{c&&Je(E),y?S(!1):a(f)},children:[p.jsx("span",{className:"tlui-button__label",draggable:!1,children:P}),s&&p.jsx(fd,{children:s}),e&&p.jsx(ok,{})]});case"panel":return p.jsxs(Ne,{"data-testid":`${f}.${r}`,type:"menu",title:k,disabled:n,onClick:()=>a(f),children:[p.jsx(on,{children:P}),e?p.jsx(ok,{}):i&&p.jsx(nt,{icon:i})]});case"small-icons":case"icons":return p.jsx(Ne,{"data-testid":`${f}.${r}`,type:"icon",title:k,disabled:n,onClick:()=>a(f),children:p.jsx(nt,{icon:i,small:h==="small-icons"})});case"keyboard-shortcuts":return s?p.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${f}.${r}`,children:[p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:P}),p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:p.jsx(fd,{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 p.jsxs(Ne,{type:"low",onClick:()=>a(f),children:[p.jsx(nt,{icon:i}),p.jsx(on,{children:P})]});case"toolbar":return p.jsx(Ne,{type:"tool","data-testid":`tools.${r}`,"aria-label":w,"data-value":r,onClick:()=>a("toolbar"),title:k,disabled:n,onTouchStart:E=>{Je(E),a("toolbar")},role:"radio","aria-checked":d?"true":"false",children:p.jsx(nt,{icon:i})});case"toolbar-overflow":return p.jsx(Rd,{"aria-label":o,children:p.jsx(Ne,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:k,disabled:n,role:"radio","aria-checked":d?"true":"false","data-value":r,children:p.jsx(nt,{icon:i})})});default:throw un(h)}}function ce({actionId:n="",...e}){const r=wl()[n];return r?p.jsx(En,{...r,...e}):null}const L5=_.createContext(null);function BQ({overrides:n,children:e}){const t=te(),r=On(),s=G1(),o=_.useMemo(()=>{const i=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){if(t.isIn("select")){const d=t.root.getCurrent();d.exit({},d.id),d.enter({},d.id)}t.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){t.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){t.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){t.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...qs.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(d){t.run(()=>{t.setStyleForNextShapes(qs,c),t.setCurrentTool("geo"),r("select-tool",{source:d,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){t.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){t.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){t.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){t.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s.insertMedia(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){t.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){t.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(c){s.addDialog({component:p5}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){t.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];i.push();const a=Object.fromEntries(i.map(c=>[c.id,c]));return n?n(t,a,s):a},[n,t,r,s]);return p.jsx(L5.Provider,{value:o,children:e})}function V1(){const n=_.useContext(L5);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function Tr({toolId:n="",...e}){const r=V1()[n];return r?p.jsx(En,{...r,...e}):null}function UQ({children:n}){const e=te();return se("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])?p.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}):null}const{PI:HQ}=Math,Mc=HQ+1e-4;function F5(n,e={}){const{size:t=16,smoothing:r=.5}=e;if(n.length===0||t<=0)return{left:[],right:[]};const s=n[0],o=n[n.length-1],i=o.runningLength,a=Math.pow(t*r,2),c=[],d=[];let h=n[0].vector,f=n[0].point,g=f,y=f,S=g,v=!1,w;for(let b=0;b<n.length;b++){w=n[b];const{point:P,vector:k}=n[b],E=w.vector.dpr(h),M=(b<n.length-1?n[b+1]:n[b]).vector,A=b<n.length-1?M.dpr(w.vector):1,R=E<0&&!v,D=A!==null&&A<.2;if(R||D){if(A>-.62&&i-w.runningLength>w.radius){const L=h.clone().mul(w.radius);h.clone().cpr(M)<0?(y=C.Add(P,L),S=C.Sub(P,L)):(y=C.Sub(P,L),S=C.Add(P,L)),c.push(y),d.push(S)}else{const L=h.clone().mul(w.radius).per(),U=C.Sub(w.input,L);for(let K=1/13,F=0;F<1;F+=K)y=C.RotWith(U,w.input,Mc*F),c.push(y),S=C.RotWith(U,w.input,Mc+Mc*-F),d.push(S)}f=y,g=S,D&&(v=!0);continue}if(v=!1,w===s||w===o){const L=C.Per(k).mul(w.radius);c.push(C.Sub(P,L)),d.push(C.Add(P,L));continue}const V=C.Lrp(M,k,A).per().mul(w.radius);y=C.Sub(P,V),(b<=1||C.Dist2(f,y)>a)&&(c.push(y),f=y),S=C.Add(P,V),(b<=1||C.Dist2(g,S)>a)&&(d.push(S),g=S),h=k}return{left:c,right:d}}function q1(n,e={}){const{size:t=16,start:r={},end:s={},last:o=!1}=e,{cap:i=!0}=r,{cap:a=!0}=s;if(n.length===0||t<=0)return[];const c=n[0],d=n[n.length-1],h=d.runningLength,f=r.taper===!1?0:r.taper===!0?Math.max(t,h):r.taper,g=s.taper===!1?0:s.taper===!0?Math.max(t,h):s.taper,{left:y,right:S}=F5(n,e),v=c.point,w=n.length>1?n[n.length-1].point:C.AddXY(c.point,1,1);if(n.length===1&&(!(f||g)||o)){const E=C.Add(v,C.Sub(v,w).uni().per().mul(-c.radius)),M=[];for(let A=1/13,R=A;R<=1;R+=A)M.push(C.RotWith(E,v,Mc*2*R));return M}const b=[];if(!(f||g&&n.length===1))if(i)for(let E=1/8,M=E;M<=1;M+=E){const A=C.RotWith(S[0],v,Mc*M);b.push(A)}else{const E=C.Sub(y[0],S[0]),M=C.Mul(E,.5),A=C.Mul(E,.51);b.push(C.Sub(v,M),C.Sub(v,A),C.Add(v,A),C.Add(v,M))}const P=[],k=d.vector.clone().per().neg();if(g||f&&n.length===1)P.push(w);else if(a){const E=C.Add(w,C.Mul(k,d.radius));for(let M=1/29,A=M;A<1;A+=M)P.push(C.RotWith(E,w,Mc*3*A))}else P.push(C.Add(w,C.Mul(k,d.radius)),C.Add(w,C.Mul(k,d.radius*.99)),C.Sub(w,C.Mul(k,d.radius*.99)),C.Sub(w,C.Mul(k,d.radius)));return y.concat(P,S.reverse(),b)}const KQ=.025,WQ=.01;function No(n,e={}){var w;const{streamline:t=.5,size:r=16,simulatePressure:s=!1}=e;if(n.length===0)return[];const o=.15+(1-t)*.85;let i=n.map(C.From),a=0;if(!s){let b=i[0];for(;b&&!(b.z>=KQ);)i.shift(),b=i[0]}if(!s){let b=i[i.length-1];for(;b&&!(b.z>=WQ);)i.pop(),b=i[i.length-1]}if(i.length===0)return[{point:C.From(n[0]),input:C.From(n[0]),pressure:s?.5:.15,vector:new C(1,1),distance:0,runningLength:0,radius:1}];let c=i[1];for(;c&&!(C.Dist2(c,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,c.z),i.splice(1,1),c=i[1];const d=i.pop();for(c=i[i.length-1];c&&!(C.Dist2(c,d)>(r/3)**2);)i.pop(),c=i[i.length-1],a++;i.push(d);const h=e.last||!e.simulatePressure||i.length>1&&C.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&e.simulatePressure){const b=i[1];i=i.slice(0,-1);for(let P=1;P<5;P++){const k=C.Lrp(i[0],b,P/4);k.z=(i[0].z+(b.z-i[0].z))*P/4,i.push(k)}}const f=[{point:i[0],input:i[0],pressure:s?.5:i[0].z,vector:new C(1,1),distance:0,runningLength:0,radius:1}];let g=0,y=f[0],S,v;h&&t>0&&i.push(i[i.length-1].clone());for(let b=1,P=i.length;b<P;b++)S=!o||e.last&&b===P-1?i[b].clone():i[b].clone().lrp(y.point,1-o),!y.point.equals(S)&&(v=C.Dist(S,y.point),g+=v,!(b<4&&g<r)&&(y={input:i[b],point:S,pressure:s?.5:i[b].z,vector:C.Sub(y.point,S).uni(),distance:v,runningLength:g,radius:1},f.push(y)));if((w=f[1])!=null&&w.vector&&(f[0].vector=f[1].vector.clone()),g<1){const b=Math.max(.5,...f.map(P=>P.pressure));f.forEach(P=>P.pressure=b)}return f}const{min:Qi}=Math,ew=.275;function fm(n,e){const{size:t=16,thinning:r=.5,simulatePressure:s=!0,easing:o=w=>w,start:i={},end:a={}}=e,{easing:c=vn.easeOutQuad}=i,{easing:d=vn.easeOutCubic}=a,h=n[n.length-1].runningLength;let f,g=n[0].pressure,y;if(!s&&h<t){const w=n.reduce((b,P)=>Math.max(b,P.pressure),.5);return n.forEach(b=>{b.pressure=w,b.radius=t*o(.5-r*(.5-b.pressure))}),n}else{let w;for(let b=0,P=n.length;b<P&&(y=n[b],!(y.runningLength>t*5));b++){const k=Qi(1,y.distance/t);if(s){const E=Qi(1,1-k);w=Qi(1,g+(E-g)*(k*ew))}else w=Qi(1,g+(y.pressure-g)*.5);g=g+(w-g)*.5}for(let b=0;b<n.length;b++){if(y=n[b],r){let{pressure:P}=y;const k=Qi(1,y.distance/t);if(s){const E=Qi(1,1-k);P=Qi(1,g+(E-g)*(k*ew))}else P=Qi(1,g+(P-g)*(k*ew));y.radius=t*o(.5-r*(.5-P)),g=P}else y.radius=t/2;f===void 0&&(f=y.radius)}}const S=i.taper===!1?0:i.taper===!0?Math.max(t,h):i.taper,v=a.taper===!1?0:a.taper===!0?Math.max(t,h):a.taper;if(S||v)for(let w=0;w<n.length;w++){y=n[w];const{runningLength:b}=y,P=b<S?c(b/S):1,k=h-b<v?d((h-b)/v):1;y.radius=Math.max(.01,y.radius*Math.min(P,k))}return n}function GQ(n,e={}){return q1(fm(No(n,e),e),e)}function ik({scribble:n,zoom:e,color:t,opacity:r,className:s}){if(!n.points.length)return null;const o=GQ(n.points,{size:n.size/e,start:{taper:n.taper,easing:vn.linear},last:n.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(o.length<4){const a=n.size/e/2,{x:c,y:d}=n.points[n.points.length-1];i=`M ${c-a},${d} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=$b(o);return p.jsx("svg",{className:s&&Le("tl-overlays__item",s),children:p.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${n.color})`,opacity:r??n.opacity})})}const VQ=({bounds:n,rotation:e})=>{const t=te();return se("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?p.jsx(_j,{bounds:n,rotation:e}):null};function qQ({size:n,width:e,height:t,hideAlternateHandles:r}){const s=ee(n/3),o=s/2;return p.jsxs("svg",{className:"tl-overlays__item",children:[p.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
334
|
+
${ee(0-o)},${ee(n)}
|
|
335
|
+
${ee(0-o)},${ee(0-o)}
|
|
336
|
+
${ee(n)},${ee(0-o)}`,strokeWidth:s,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),p.jsx("line",{className:Le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(e/2-n),y1:ee(0-o),x2:ee(e/2+n),y2:ee(0-o),strokeWidth:s,"data-testid":"selection.crop.top","aria-label":"top handle"}),p.jsx("polyline",{className:Le("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
337
|
+
${ee(e-n)},${ee(0-o)}
|
|
338
|
+
${ee(e+o)},${ee(0-o)}
|
|
339
|
+
${ee(e+o)},${ee(n)}`,strokeWidth:s,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),p.jsx("line",{className:Le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(e+o),y1:ee(t/2-n),x2:ee(e+o),y2:ee(t/2+n),strokeWidth:s,"data-testid":"selection.crop.right","aria-label":"right handle"}),p.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
340
|
+
${ee(e+o)},${ee(t-n)}
|
|
341
|
+
${ee(e+o)},${ee(t+o)}
|
|
342
|
+
${ee(e-n)},${ee(t+o)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),p.jsx("line",{className:Le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(e/2-n),y1:ee(t+o),x2:ee(e/2+n),y2:ee(t+o),strokeWidth:s,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),p.jsx("polyline",{className:Le("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
343
|
+
${ee(0+n)},${ee(t+o)}
|
|
344
|
+
${ee(0-o)},${ee(t+o)}
|
|
345
|
+
${ee(0-o)},${ee(t-n)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),p.jsx("line",{className:Le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(0-o),y1:ee(t/2-n),x2:ee(0-o),y2:ee(t/2+n),strokeWidth:s,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const YQ=jn(function({bounds:e,rotation:t}){const r=te(),s=_.useRef(null),o=is(),i=xo("top"),a=xo("right"),c=xo("bottom"),d=xo("left"),h=xo("top_left"),f=xo("top_right"),g=xo("bottom_right"),y=xo("bottom_left"),S=r.getInstanceState().cursor.type==="default",v=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),b=w&&r.isShapeOrAncestorLocked(w),P=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0,k=P instanceof Se?e.clone().expand(P).zeroFix():e.clone().expandBy(P).zeroFix();if(Gc(s,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:k.x-e.x,y:k.y-e.y}),w&&r.isShapeHidden(w))return null;const E=r.getZoomLevel(),M=r.getInstanceState().isChangingStyle,A=k.width,R=k.height,D=8/E,V=A<D*2,L=R<D*2,U=A<D*4,K=R<D*4,F=A<D*5,$=R<D*5,W=v?1.75:1,Y=6/E*W,Z=(U?Y/2:Y)*(W*.75),H=(K?Y/2:Y)*(W*.75),Q=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!M;let ae=Q&&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")||Q&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&ae&&Et.isFirefox&&r.isShapeOfType(w,"embed")&&(ae=!1);const B=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!M&&!o,ne=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!M&&!o,he=!v&&!(V||L)&&(ne||B)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!b,Pe=v&&(!U||!K)&&(ne||B)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!b,ue=ne&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!B&&!b,Fe=V||L,Me=V&&L,xe=F||$,Ie=ue||B,ze=!he,Ze=!ne||!Pe,Xt=!ne||!Ie,yt=!ne||!Ie||Fe,zt=!ne||!Ie||Fe,_t=!ne||!Ie||Me&&!B;let wt=!0,hr=!0;if(B)wt=xe,hr=xe;else if(ue){wt=Fe||Me||v;const gr=v&&w&&w.type==="text";hr=wt&&!gr}const pr=Math.min(24/E,R-H*3),fr=ne&&v&&w&&r.isShapeOfType(w,"text")&&pr*E>=4;return p.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:p.jsxs("g",{ref:s,children:[ae&&p.jsx("rect",{className:"tl-selection__fg__outline",width:ee(A),height:ee(R)}),p.jsx(Kp,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:Y,corner:"top_left_rotate",cursor:S?qr("nwse-rotate",t):void 0,isHidden:ze}),p.jsx(Kp,{"data-testid":"selection.rotate.top-right",cx:A+Y*3,cy:0,targetSize:Y,corner:"top_right_rotate",cursor:S?qr("nesw-rotate",t):void 0,isHidden:ze}),p.jsx(Kp,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:R+Y*3,targetSize:Y,corner:"bottom_left_rotate",cursor:S?qr("swne-rotate",t):void 0,isHidden:ze}),p.jsx(Kp,{"data-testid":"selection.rotate.bottom-right",cx:A+Y*3,cy:R+Y*3,targetSize:Y,corner:"bottom_right_rotate",cursor:S?qr("senw-rotate",t):void 0,isHidden:ze}),p.jsx(ZQ,{"data-testid":"selection.rotate.mobile",cx:U?-Y*1.5:A/2,cy:U?R/2:-Y*1.5,size:D,isHidden:Ze}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":wt}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:ee(0-(K?H*2:H)),width:ee(A),height:ee(Math.max(1,H*2)),style:S?{cursor:qr("ns-resize",t)}:void 0,...i}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":hr}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:ee(A-(U?0:Z)),y:0,height:ee(R),width:ee(Math.max(1,Z*2)),style:S?{cursor:qr("ew-resize",t)}:void 0,...a}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":wt}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:ee(R-(K?0:H)),width:ee(A),height:ee(Math.max(1,H*2)),style:S?{cursor:qr("ns-resize",t)}:void 0,...c}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":hr}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:ee(0-(U?Z*2:Z)),y:0,height:ee(R),width:ee(Math.max(1,Z*2)),style:S?{cursor:qr("ew-resize",t)}:void 0,...d}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":Xt}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:ee(0-(U?Z*2:Z*1.5)),y:ee(0-(K?H*2:H*1.5)),width:ee(Z*3),height:ee(H*3),style:S?{cursor:qr("nwse-resize",t)}:void 0,...h}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":yt}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:ee(A-(U?0:Z*1.5)),y:ee(0-(K?H*2:H*1.5)),width:ee(Z*3),height:ee(H*3),style:S?{cursor:qr("nesw-resize",t)}:void 0,...f}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":_t}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:ee(A-(U?Z:Z*1.5)),y:ee(R-(K?H:H*1.5)),width:ee(Z*3),height:ee(H*3),style:S?{cursor:qr("nwse-resize",t)}:void 0,...g}),p.jsx("rect",{className:Le("tl-transparent",{"tl-hidden":zt}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:ee(0-(U?Z*3:Z*1.5)),y:ee(R-(K?0:H*1.5)),width:ee(Z*3),height:ee(H*3),style:S?{cursor:qr("nesw-resize",t)}:void 0,...y}),ue&&p.jsxs(p.Fragment,{children:[p.jsx("rect",{"data-testid":"selection.resize.top-left",className:Le("tl-corner-handle",{"tl-hidden":Xt}),"aria-label":"top_left handle",x:ee(0-D/2),y:ee(0-D/2),width:ee(D),height:ee(D)}),p.jsx("rect",{"data-testid":"selection.resize.top-right",className:Le("tl-corner-handle",{"tl-hidden":yt}),"aria-label":"top_right handle",x:ee(A-D/2),y:ee(0-D/2),width:ee(D),height:ee(D)}),p.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:Le("tl-corner-handle",{"tl-hidden":_t}),"aria-label":"bottom_right handle",x:ee(A-D/2),y:ee(R-D/2),width:ee(D),height:ee(D)}),p.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:Le("tl-corner-handle",{"tl-hidden":zt}),"aria-label":"bottom_left handle",x:ee(0-D/2),y:ee(R-D/2),width:ee(D),height:ee(D)})]}),fr&&p.jsxs(p.Fragment,{children:[p.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:ee(0-D/4),y:ee(R/2-pr/2),rx:D/4,width:ee(D/2),height:ee(pr)}),p.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:D/4,x:ee(A-D/4),y:ee(R/2-pr/2),width:ee(D/2),height:ee(pr)})]}),B&&p.jsx(qQ,{size:D,width:A,height:R,hideAlternateHandles:xe})]})})}),Kp=function({cx:e,cy:t,targetSize:r,corner:s,cursor:o,isHidden:i,"data-testid":a}){const c=xo(s);return p.jsx("rect",{className:Le("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${s} target`,pointerEvents:"all",x:ee(e-r*3),y:ee(t-r*3),width:ee(Math.max(1,r*3)),height:ee(Math.max(1,r*3)),cursor:o,...c})},XQ=Math.sqrt(Math.PI),ZQ=function({cx:e,cy:t,size:r,isHidden:s,"data-testid":o}){const i=xo("mobile_rotate"),a=te(),c=se("zoom level",()=>a.getZoomLevel(),[a]),d=Math.max(14*(1/c),20/Math.max(1,c));return p.jsxs("g",{children:[p.jsx("circle",{"data-testid":o,pointerEvents:"all",className:Le("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":s}),cx:e,cy:t,r:d,...i}),p.jsx("circle",{className:Le("tl-mobile-rotate__fg",{"tl-hidden":s}),cx:e,cy:t,r:r/XQ})]})};function QQ(){const n=te();return se("is in a valid select state",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle"),[n])?p.jsx(Ij,{}):null}function b0(n,e,t){const{arrowheadStart:r,arrowheadEnd:s}=e.props,o=wc(n,e,t),i=o.start.clone(),a=o.end.clone(),c=C.Med(i,a);if(C.Equals(i,a))return{bindings:t,isStraight:!0,start:{handle:i,point:i,arrowhead:e.props.arrowheadStart},end:{handle:a,point:a,arrowhead:e.props.arrowheadEnd},middle:c,isValid:!1,length:0};const d=C.Sub(a,i).uni(),h=lg(n,e,"start"),f=lg(n,e,"end"),g=n.getShapePageTransform(e);ak(a,o.start,g,f),ak(i,o.end,g,h);let y=0,S=0,v=0,w=0,b=gd*e.props.scale;const P=h&&f&&h.shape===f.shape,k=h&&f?Y1(n,h.shape.id,f.shape.id):"safe";k==="safe"&&h&&f&&!P&&!h.isExact&&!f.isExact&&(f.didIntersect&&!h.didIntersect?h.isClosed&&i.setTo(a.clone().add(d.clone().mul(gd*e.props.scale))):f.didIntersect||f.isClosed&&a.setTo(i.clone().sub(d.clone().mul(gd*e.props.scale))));const E=C.Sub(a,i),M=C.Len(E)?E.uni():C.From(E),A=!C.Equals(M,d);P||(k!=="start-contains-end"&&h&&r!=="none"&&!h.isExact&&(v=Eo[e.props.size]/2+("size"in h.shape.props?Eo[h.shape.props.size]/2:0),y=(cg+v)*e.props.scale,b+=v*e.props.scale),k!=="end-contains-start"&&f&&s!=="none"&&!f.isExact&&(w=Eo[e.props.size]/2+("size"in f.shape.props?Eo[f.shape.props.size]/2:0),S=(cg+w)*e.props.scale,b+=w*e.props.scale));const R=i.clone().add(M.clone().mul(y*(A?-1:1))),D=a.clone().sub(M.clone().mul(S*(A?-1:1)));C.DistMin(R,D,b)&&(y!==0&&S!==0?(y*=-1.5,S*=-1.5):y!==0?y*=-1:S!==0&&(S*=-1)),i.add(M.clone().mul(y*(A?-1:1))),a.sub(M.clone().mul(S*(A?-1:1))),A?(h&&f&&a.setTo(C.Add(i,M.clone().mul(-10*e.props.scale))),c.setTo(C.Med(o.start,o.end))):c.setTo(C.Med(i,a));const V=C.Dist(i,a);return{bindings:t,isStraight:!0,start:{handle:o.start,point:i,arrowhead:e.props.arrowheadStart},end:{handle:o.end,point:a,arrowhead:e.props.arrowheadEnd},middle:c,isValid:V>0,length:V}}function ak(n,e,t,r){if(r===void 0||r.isExact)return;const s=me.applyToPoint(t,e),o=me.applyToPoint(t,n),i=me.applyToPoint(me.Inverse(r.transform),s),a=me.applyToPoint(me.Inverse(r.transform),o),c=r.isClosed,h=(c?Kb:qU)(i,a,r.outline);let f;if(h!==null&&(f=h.sort((S,v)=>C.Dist2(S,i)-C.Dist2(v,i))[0]??(c?void 0:a)),f===void 0)return;const g=me.applyToPoint(r.transform,f),y=me.applyToPoint(me.Inverse(t),g);n.setTo(y),r.didIntersect=!0}function JQ(n,e,t){const{arrowheadEnd:r,arrowheadStart:s}=e.props,o=e.props.bend;if(Math.abs(o)>Math.abs(e.props.bend*(sJ*e.props.scale)))return b0(n,e,t);const i=wc(n,e,t),a=C.Med(i.start,i.end),c=C.Sub(i.end,i.start),d=C.Len(c)?c.uni():C.From(c),h=C.Add(a,d.per().mul(-o)),f=lg(n,e,"start"),g=lg(n,e,"end"),y=i.start.clone(),S=i.end.clone(),v=h.clone();if(C.Equals(y,S))return{bindings:t,isStraight:!0,start:{handle:y,point:y,arrowhead:e.props.arrowheadStart},end:{handle:S,point:S,arrowhead:e.props.arrowheadEnd},middle:v,isValid:!1,length:0};const w=e.props.bend<0,b=w?Kd:iA,P=lk(y,S,v),k=C.Angle(P.center,y),E=C.Angle(P.center,S),M=b(k,E);if(P.length===0||P.size===0||!x2(P.length)||!x2(P.size))return b0(n,e,t);const A=y.clone(),R=S.clone(),D=v.clone(),V=n.getShapePageTransform(e);let L=0,U=0,K=gd*e.props.scale;if(f&&!f.isExact){const ae=me.applyToPoint(V,A),B=me.applyToPoint(V,P.center),ne=me.applyToPoint(V,R),he=me.Inverse(f.transform),Pe=me.applyToPoint(he,ae),ue=me.applyToPoint(he,B),Fe=me.applyToPoint(he,ne),{isClosed:Me}=f,xe=Me?Zw:aT;let Ie,ze=xe(ue,P.radius,f.outline);if(ze){const Ze=ue.angle(Pe),Xt=ue.angle(Fe),yt=b(Ze,Xt);ze=ze.filter(_t=>b(Ze,ue.angle(_t))<=yt);const zt=yt*.25;ze.sort(Me?(_t,wt)=>Math.abs(b(Ze,ue.angle(_t))-zt)<Math.abs(b(Ze,ue.angle(wt))-zt)?-1:1:(_t,wt)=>b(Ze,ue.angle(_t))<b(Ze,ue.angle(wt))?-1:1),Ie=ze[0]??(Me?void 0:Pe)}else Ie=Me?void 0:Pe;if(Ie&&(A.setTo(n.getPointInShapeSpace(e,me.applyToPoint(f.transform,Ie))),f.didIntersect=!0,s!=="none")){const Ze=Eo[e.props.size]/2+("size"in f.shape.props?Eo[f.shape.props.size]/2:0);L=(cg+Ze)*e.props.scale,K+=Ze*e.props.scale}}if(g&&!g.isExact){const ae=me.applyToPoint(V,A),B=me.applyToPoint(V,R),ne=me.applyToPoint(V,P.center),he=me.Inverse(g.transform),Pe=me.applyToPoint(he,ae),ue=me.applyToPoint(he,ne),Fe=me.applyToPoint(he,B),Me=g.isClosed,xe=Me?Zw:aT;let Ie,ze=xe(ue,P.radius,g.outline);if(ze){const Ze=ue.angle(Pe),Xt=ue.angle(Fe),yt=b(Ze,Xt),zt=yt*.75;ze=ze.filter(_t=>b(Ze,ue.angle(_t))<=yt),ze.sort(Me?(_t,wt)=>Math.abs(b(Ze,ue.angle(_t))-zt)<Math.abs(b(Ze,ue.angle(wt))-zt)?-1:1:(_t,wt)=>b(Ze,ue.angle(_t))<b(Ze,ue.angle(wt))?-1:1),ze[0]?Ie=ze[0]:Ie=Me?void 0:Fe}else Ie=Me?void 0:Fe;if(Ie&&(R.setTo(n.getPointInShapeSpace(e,me.applyToPoint(g.transform,Ie))),g.didIntersect=!0,r!=="none")){const Ze=Eo[e.props.size]/2+("size"in g.shape.props?Eo[g.shape.props.size]/2:0);U=(cg+Ze)*e.props.scale,K+=Ze*e.props.scale}}let F=C.Angle(P.center,A),$=C.Angle(P.center,R),W=b(F,$),Y=W*P.radius;const Z=A.clone(),H=R.clone();if(L!==0&&Z.setTo(P.center).add(C.FromAngle(F+W*(L/Y*(w?1:-1))).mul(P.radius)),U!==0&&H.setTo(P.center).add(C.FromAngle($+W*(U/Y*(w?-1:1))).mul(P.radius)),C.DistMin(Z,H,K)&&(L!==0&&U!==0?(L*=-1.5,U*=-1.5):L!==0?L*=-2:U!==0&&(U*=-2)),L!==0&&A.setTo(P.center).add(C.FromAngle(F+W*(L/Y*(w?1:-1))).mul(P.radius)),U!==0&&R.setTo(P.center).add(C.FromAngle($+W*(U/Y*(w?-1:1))).mul(P.radius)),f&&g&&!f.isExact&&!g.isExact){F=C.Angle(P.center,A),$=C.Angle(P.center,R),W=b(F,$),Y=W*P.radius;const ae=Y1(n,f.shape.id,g.shape.id);ae==="double-bound"&&Y<30?(A.setTo(y),R.setTo(S),D.setTo(v)):ae==="safe"&&(f&&!f.didIntersect&&A.setTo(y),(g&&!g.didIntersect||b(k,F)>b(k,$))&&R.setTo(P.center).add(C.FromAngle(F+W*(Math.min(.9,gd*e.props.scale/Y)*(w?1:-1))).mul(P.radius)))}eJ(P.center,P.radius,A,R,D,M,w),A.equals(R)&&(A.setTo(D.clone().addXY(1,1)),R.setTo(D.clone().subXY(1,1))),y.setTo(A),S.setTo(R),v.setTo(D);const Q=lk(y,S,v);return{bindings:t,isStraight:!1,start:{point:y,handle:i.start,arrowhead:e.props.arrowheadStart},end:{point:S,handle:i.end,arrowhead:e.props.arrowheadEnd},middle:v,handleArc:P,bodyArc:Q,isValid:Q.length!==0&&isFinite(Q.center.x)&&isFinite(Q.center.y)}}function lk(n,e,t){const r=Sb(n,e,t)??C.Med(n,e),s=C.Dist(r,n),o=+C.Clockwise(n,t,e),i=((n.y-e.y)**2+(n.x-e.x)**2)**.5,a=((e.y-t.y)**2+(e.x-t.x)**2)**.5,c=((t.y-n.y)**2+(t.x-n.x)**2)**.5,d=Math.acos((a*a+c*c-i*i)/(2*a*c))*2,h=+(pt>d),f=(St-d)*(o?1:-1),g=f*s;return{center:r,radius:s,size:f,length:g,largeArcFlag:h,sweepFlag:o}}function eJ(n,e,t,r,s,o,i){const a=C.Angle(n,t),c=C.Angle(n,r);let d=Kd(a,c);if(i||(d=St-d),s.setTo(n).add(C.FromAngle(a+d*(.5*(i?1:-1))).mul(e)),d>o){s.rotWith(n,pt);const h=r.clone();r.setTo(t),t.setTo(h)}}const tJ=8;function nJ(n){return Math.abs(n.props.bend)<tJ*n.props.scale}function lg(n,e,t){const r=n.getBindingsFromShape(e,"arrow").find(c=>c.props.terminal===t);if(!r)return;const s=n.getShape(r.toId);if(!s)return;const o=n.getShapePageTransform(s),i=n.getShapeGeometry(s),a=i instanceof Is?i.children[0].vertices:i.vertices;return{shape:s,transform:o,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function ck(n,e,t,r){const s=n.getShape(t.toId);if(s){const{point:o,size:i}=n.getShapeGeometry(s).bounds,a=C.Add(o,C.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},i)),c=me.applyToPoint(n.getShapePageTransform(s),a);return me.applyToPoint(me.Inverse(e),c)}else return new C(0,0)}function Rr(n,e){const t=n.getBindingsFromShape(e,"arrow");return{start:t.find(r=>r.props.terminal==="start"),end:t.find(r=>r.props.terminal==="end")}}const rJ=e9("arrow info",(n,e)=>{const t=Rr(n,e);return nJ(e)?b0(n,e,t):JQ(n,e,t)});function Io(n,e){const t=typeof e=="string"?e:e.id;return rJ.get(n,t)}function wc(n,e,t){var a,c;const r=n.getShapePageTransform(e),s=Y1(n,(a=t.start)==null?void 0:a.toId,(c=t.end)==null?void 0:c.toId),o=t.start?ck(n,r,t.start,s==="double-bound"||s==="start-contains-end"):C.From(e.props.start),i=t.end?ck(n,r,t.end,s==="double-bound"||s==="end-contains-start"):C.From(e.props.end);return{start:o,end:i}}function Vu(n,e,t,r){const s=typeof e=="string"?e:e.id,o=typeof t=="string"?t:t.id,i=n.getBindingsFromShape(s,"arrow").filter(c=>c.props.terminal===r.terminal);i.length>1&&n.deleteBindings(i.slice(1));const a=i[0];a?n.updateBinding({...a,toId:o,props:r}):n.createBinding({type:"arrow",fromId:s,toId:o,props:r})}function df(n,e,t){const r=n.getBindingsFromShape(e,"arrow").filter(s=>s.props.terminal===t);n.deleteBindings(r)}const gd=10,cg=10,sJ=10,Eo={s:2,m:3.5,l:5,xl:10};function Y1(n,e,t){if(!e||!t)return"safe";if(e===t)return"double-bound";const r=n.getShapePageBounds(e),s=n.getShapePageBounds(t);if(r&&s){if(r.contains(s))return"start-contains-end";if(s.contains(r))return"end-contains-start"}return"safe"}class hf extends af{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const t=this.editor.getShape(e.fromId);t&&tw(this.editor,t)}onAfterChange({bindingAfter:e}){const t=this.editor.getShape(e.fromId);t&&tw(this.editor,t)}onAfterChangeFromShape({shapeAfter:e}){tw(this.editor,e)}onAfterChangeToShape({binding:e}){N5(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const t=this.editor.getShape(e.fromId);t&&ug({editor:this.editor,arrow:t,terminal:e.props.terminal})}}j(hf,"type","arrow"),j(hf,"props",TA),j(hf,"migrations",kA);function N5(n,e){var w;const t=n.getShape(e);if(!t)return;const r=Rr(n,t),{start:s,end:o}=r,i=s?n.getShape(s.toId):void 0,a=o?n.getShape(o.toId):void 0,c=n.getAncestorPageId(t);if(!c)return;let d;if(i&&a)d=n.findCommonAncestor([i,a])??c;else if(i||a){const b=(w=i||a)==null?void 0:w.parentId;b&&b===t.parentId?d=t.parentId:d=c}else return;d&&d!==t.parentId&&n.reparentShapes([e],d);const h=n.getShape(e);if(!h)throw Error("no reparented arrow");const f=n.getShapeNearestSibling(h,i),g=n.getShapeNearestSibling(h,a);let y;if(f&&g)y=f.index>g.index?f:g;else if(f&&!g)y=f;else if(g&&!f)y=g;else return;let S;const v=n.getSortedChildIdsForParent(y.parentId).map(b=>n.getShape(b)).filter(b=>b.index>y.index);if(v.length){const b=v.find(P=>P.type!=="arrow");if(h.index>y.index&&(!b||h.index<b.index))return;S=wd(y.index,v[0].index)}else S=Co(y.index);S!==h.index&&n.updateShapes([{id:e,type:"arrow",index:S}])}function tw(n,e){const t=Rr(n,e);for(const r of["start","end"]){const s=t[r];if(!s)continue;const o=n.getShape(s.toId),i=n.getAncestorPageId(e)===n.getAncestorPageId(o);(!o||!i)&&ug({editor:n,arrow:e,terminal:r,unbind:!0})}N5(n,e.id)}function ug({editor:n,arrow:e,terminal:t,unbind:r=!1,useHandle:s=!1}){const o=Io(n,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,c=t==="start"?i:a,d={id:e.id,type:"arrow",props:{[t]:{x:c.x,y:c.y},bend:e.props.bend}};if(!o.isStraight){const h=t==="start"?i:o.start.handle,f=t==="end"?a:o.end.handle,g=C.Med(h,f),y=C.Sub(h,f).per().uni().mul(o.handleArc.radius*2*Math.sign(e.props.bend)),S=Yd(o.handleArc.center,C.Add(g,y),o.handleArc.center,o.handleArc.radius);mt((S==null?void 0:S.length)===1);const v=C.Dist(g,S[0])*Math.sign(e.props.bend);la(v,d.props.bend)||(d.props.bend=v)}n.updateShape(d),r&&df(n,e,t)}const $5=[hf],Yn={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},qn={s:2,m:3.5,l:5,xl:10},Oc={s:18,m:24,l:36,xl:44},Si={s:18,m:22,l:26,xl:32},oJ={s:18,m:20,l:24,xl:28},wi={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},iJ=20,X1=4.25,xs=16;function aJ(n,e){const t=n.w/e.w,r=n.h/e.h;return t<=1&&r<=1?n:t>r?{w:n.w/t,h:n.h/t}:{w:n.w/r,h:n.h/r}}/*!
|
|
346
|
+
* MIT License
|
|
347
|
+
* Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
|
|
348
|
+
* Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
|
|
349
|
+
*/const bc=" ",nr=class nr{static insertTextFirefox(e,t){e.setRangeText(t,e.selectionStart||0,e.selectionEnd||0,"end"),e.dispatchEvent(new InputEvent("input",{data:t,inputType:"insertText",isComposing:!1}))}static insert(e,t){const r=e.ownerDocument,s=r.activeElement;s!==e&&e.focus(),r.execCommand("insertText",!1,t)||nr.insertTextFirefox(e,t),s===r.body?e.blur():s instanceof HTMLElement&&s!==e&&s.focus()}static set(e,t){e.select(),nr.insert(e,t)}static getSelection(e){const{selectionStart:t,selectionEnd:r}=e;return e.value.slice(t||void 0,r||void 0)}static wrapSelection(e,t,r){const{selectionStart:s,selectionEnd:o}=e,i=nr.getSelection(e);nr.insert(e,t+i+(r??t)),e.selectionStart=(s||0)+t.length,e.selectionEnd=(o||0)+t.length}static replace(e,t,r){let s=0;e.value.replace(t,(...o)=>{const i=s+o[o.length-2],a=o[0].length;e.selectionStart=i,e.selectionEnd=i+a;const c=typeof r=="string"?r:r(...o);return nr.insert(e,c),e.selectionStart=i,s+=c.length-a,c})}static findLineEnd(e,t){const r=e.lastIndexOf(`
|
|
350
|
+
`,t-1)+1;return e.charAt(r)!==" "?t:r+1}static indent(e){var a;const{selectionStart:t,selectionEnd:r,value:s}=e,o=s.slice(t,r),i=(a=/\n/g.exec(o))==null?void 0:a.length;if(i&&i>0){const c=s.lastIndexOf(`
|
|
351
|
+
`,t-1)+1,d=e.value.slice(c,r-1),h=d.replace(/^|\n/g,`$&${bc}`),f=h.length-d.length;e.setSelectionRange(c,r-1),nr.insert(e,h),e.setSelectionRange(t+1,r+f)}else nr.insert(e,bc)}static unindent(e){const{selectionStart:t,selectionEnd:r,value:s}=e,o=s.lastIndexOf(`
|
|
352
|
+
`,t-1)+1,i=nr.findLineEnd(s,r),a=e.value.slice(o,i),c=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),d=a.length-c.length;e.setSelectionRange(o,i),nr.insert(e,c);const h=/\t| {1,2}/.exec(s.slice(o,t)),f=h?h[0].length:0,g=t-f;e.setSelectionRange(t-f,Math.max(g,r-d))}static indentCE(e){var c;const t=window.getSelection(),r=e.innerText,s=Wp(e)??0,o=Wp(e)??0,i=r.slice(s,o),a=(c=/\n/g.exec(i))==null?void 0:c.length;if(a&&a>0){const d=r.lastIndexOf(`
|
|
353
|
+
`,s-1)+1,h=r.slice(d,o-1),g=h.replace(/^|\n/g,`$&${bc}`).length-h.length;t&&t.setBaseAndExtent(e,s+1,e,o+g)}else{const d=window.getSelection();e.innerText=r.slice(0,s)+bc+r.slice(s),d==null||d.setBaseAndExtent(e,s+1,e,s+2)}}static unindentCE(e){const t=window.getSelection(),r=e.innerText,s=Wp(e)??0,o=Wp(e)??0,i=r.lastIndexOf(`
|
|
354
|
+
`,s-1)+1,a=nr.findLineEnd(r,o),c=r.slice(i,a),d=c.replace(/(^|\n)(\t| {1,2})/g,"$1"),h=c.length-d.length;if(t){t.setBaseAndExtent(e,i,e,a);const f=/\t| {1,2}/.exec(r.slice(i,s)),g=f?f[0].length:0,y=s-g;t.setBaseAndExtent(e,s-g,e,Math.max(y,o-h))}}static normalizeText(e){return e.replace(nr.fixNewLines,`
|
|
355
|
+
`)}static normalizeTextForDom(e){return e.replace(nr.fixNewLines,`
|
|
356
|
+
`).split(`
|
|
357
|
+
`).map(t=>t||" ").join(`
|
|
358
|
+
`)}};j(nr,"fixNewLines",/\r?\n|\r/g);let Dc=nr;function Wp(n){if(typeof window.getSelection>"u")return;const e=window.getSelection();if(!e)return;let t=0;if(e.rangeCount!==0){const r=e.getRangeAt(0),s=r.cloneRange();s.selectNodeContents(n),s.setEnd(r.endContainer,r.endOffset),t=s.toString().length}return t}const lJ=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function z5(n){return lJ.test(n)}function cJ(n){return n.replace(/\t/g,bc)}function uJ(n){const e=n.split(`
|
|
359
|
+
`);for(;e[0]&&e[0].trim().length===0;)e.shift();let t=1/0;for(const r of e)if(r.trim().length>0){const s=r.length-r.trimStart().length;t=Math.min(t,s)}return e.map(r=>r.slice(t)).join(`
|
|
360
|
+
`)}const B5={"&":"&",""":'"',"'":"'",""":'"',"&":"&","'":"'","–":"–","—":"—","‘":"‘","’":"’","“":"“","”":"”","…":"…"},dJ=new RegExp(Object.keys(B5).join("|"),"g");function hJ(n){return n.replace(dJ,e=>B5[e])}function pJ(n){return n.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function fJ(n){return pJ(uJ(cJ(n)))}const gJ=5e3,U5=10*1024*1024;function mJ(n,e){n.registerExternalAssetHandler("file",async t=>yJ(n,t,e)),n.registerExternalAssetHandler("url",async t=>SJ(n,t,e)),n.registerExternalContentHandler("svg-text",async t=>vJ(n,t)),n.registerExternalContentHandler("embed",t=>xJ(n,t)),n.registerExternalContentHandler("files",async t=>wJ(n,t,e)),n.registerExternalContentHandler("text",async t=>bJ(n,t)),n.registerExternalContentHandler("url",async t=>PJ(n,t,e))}async function yJ(n,{file:e,assetId:t},{acceptedImageMimeTypes:r=Fd,acceptedVideoMimeTypes:s=mg,maxAssetSize:o=U5,maxImageDimension:i=gJ,toasts:a,msg:c}){const d=r.includes(e.type),h=s.includes(e.type);!d&&!h&&a.addToast({title:c("assets.files.type-not-allowed"),severity:"error"}),mt(d||h,`File type not allowed: ${e.type}`),e.size>o&&a.addToast({title:c("assets.files.size-too-big"),severity:"error"}),mt(e.size<=o,`File size too big: ${(e.size/1024).toFixed()}kb > ${(o/1024).toFixed()}kb`);const f=tM(await e.arrayBuffer());t=t??da.createId(f);const g=await H5(e,t,d,h);if(isFinite(i)){const S={w:g.props.w,h:g.props.h},v=aJ(S,{w:i,h:i});S!==v&&Xr.isStaticImageType(e.type)&&(g.props.w=v.w,g.props.h=v.h)}const y=await n.uploadAsset(g,e);return g.props.src=y.src,y.meta&&(g.meta={...g.meta,...y.meta}),da.create(g)}async function SJ(n,{url:e},{toasts:t,msg:r}){var o,i,a,c,d;let s;try{const f=await(await jo(e,{method:"GET",mode:"no-cors"})).text(),g=new DOMParser().parseFromString(f,"text/html");s={image:((o=g.head.querySelector('meta[property="og:image"]'))==null?void 0:o.getAttribute("content"))??"",favicon:((i=g.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:i.getAttribute("href"))??((a=g.head.querySelector('link[rel="icon"]'))==null?void 0:a.getAttribute("href"))??"",title:((c=g.head.querySelector('meta[property="og:title"]'))==null?void 0:c.getAttribute("content"))??e,description:((d=g.head.querySelector('meta[property="og:description"]'))==null?void 0:d.getAttribute("content"))??""},s.image.startsWith("http")||(s.image=new URL(s.image,e).href),s.favicon.startsWith("http")||(s.favicon=new URL(s.favicon,e).href)}catch(h){console.error(h),t.addToast({title:r("assets.url.failed"),severity:"error"}),s={image:"",favicon:"",title:"",description:""}}return{id:da.createId(Z0(e)),typeName:"asset",type:"bookmark",props:{src:e,description:s.description,image:s.image,favicon:s.favicon,title:s.title},meta:{}}}async function vJ(n,{point:e,text:t}){const r=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),s=new DOMParser().parseFromString(t,"image/svg+xml").querySelector("svg");if(!s)throw new Error("No <svg/> element present");let o=parseFloat(s.getAttribute("width")||"0"),i=parseFloat(s.getAttribute("height")||"0");if(!(o&&i)){document.body.appendChild(s);const c=s.getBoundingClientRect();document.body.removeChild(s),o=c.width,i=c.height}const a=await n.getAssetForExternalContent({type:"file",file:new File([t],"asset.svg",{type:"image/svg+xml"})});if(!a)throw Error("Could not create an asset");K5(n,[a],r)}function xJ(n,{point:e,url:t,embed:r}){const s=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),{width:o,height:i}=r,a=Ct(),c={id:a,type:"embed",x:s.x-(o||450)/2,y:s.y-(i||450)/2,props:{w:o,h:i,url:t}};n.createShapes([c]).select(a)}async function wJ(n,{point:e,files:t},{maxAssetSize:r=U5,acceptedImageMimeTypes:s=Fd,acceptedVideoMimeTypes:o=mg,toasts:i,msg:a}){if(t.length>n.options.maxFilesAtOnce){i.addToast({title:a("assets.files.amount-too-big"),severity:"error"});return}const c=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),d=new C(c.x,c.y),h=[];for(const g of t){if(g.size>r){i.addToast({title:a("assets.files.size-too-big"),severity:"error"}),console.warn(`File size too big: ${(g.size/1024).toFixed()}kb > ${(r/1024).toFixed()}kb`);continue}if(!g.type){i.addToast({title:a("assets.files.upload-failed"),severity:"error"}),console.error("No mime type");continue}if(![...s,...o].includes(g.type)){i.addToast({title:a("assets.files.type-not-allowed"),severity:"error"}),console.warn(`${g.name} not loaded - Mime type not allowed ${g.type}.`);continue}const S=s.includes(g.type),v=o.includes(g.type),w=tM(await g.arrayBuffer()),b=da.createId(w),P=await H5(g,b,S,v);let k;S&&(k=n.createTemporaryAssetPreview(b,g)),h.push({asset:P,file:g,temporaryAssetPreview:k})}const f=[];await Promise.allSettled(h.map(async g=>{try{const y=await n.getAssetForExternalContent({type:"file",file:g.file});if(!y)throw Error("Could not create an asset");const S={...y,id:g.asset.id};f.push(S),n.updateAssets([S])}catch(y){i.addToast({title:a("assets.files.upload-failed"),severity:"error"}),console.error(y);return}})),K5(n,f,d)}async function bJ(n,{point:e,text:t}){const r=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),s=n.getShapeUtil("text").getDefaultProps(),o=fJ(t),i=n.getOnlySelectedShape();if(i&&"text"in i.props){n.updateShapes([{id:i.id,type:i.type,props:{text:o}}]);return}let a,c,d,h="middle";const f=o.split(`
|
|
361
|
+
`).length>1,g=z5(o);f&&(h=f?g?"end":"start":"middle");const y=n.textMeasure.measureText(o,{...Yn,fontFamily:wi[s.font],fontSize:Oc[s.size],maxWidth:null}),S=Math.min(f?n.getViewportPageBounds().width*.9:920,Math.max(200,n.getViewportPageBounds().width*.9));if(y.w>S){const v=n.textMeasure.measureText(o,{...Yn,fontFamily:wi[s.font],fontSize:Oc[s.size],maxWidth:S});a=v.w,c=v.h,d=!1,h=g?"end":"start"}else a=y.w,c=y.h,d=!0;r.y-c/2<n.getViewportPageBounds().minY+40&&(r.y=n.getViewportPageBounds().minY+40+c/2),n.createShapes([{id:Ct(),type:"text",x:r.x-a/2,y:r.y-c/2,props:{text:o,textAlign:h,autoSize:d,w:a}}])}async function PJ(n,{point:e,url:t},{toasts:r,msg:s}){const o=n.getShapeUtil("embed"),i=o==null?void 0:o.getEmbedDefinition(t);if(i)return n.putExternalContent({type:"embed",url:i.url,point:e,embed:i.definition});const a=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),c=da.createId(Z0(t)),d=CJ(n,t,a);let h=n.getAsset(c),f=!1;if(!h){f=!0;try{const g=await n.getAssetForExternalContent({type:"url",url:t});if(!g)throw Error("Could not create an asset");h=g}catch{r.addToast({title:s("assets.url.failed"),severity:"error"});return}}n.run(()=>{f&&n.createAssets([h]),n.updateShapes([{id:d.id,type:d.type,props:{assetId:h.id}}])})}async function H5(n,e,t,r){let s=n.type;n.type==="video/quicktime"&&(s="video/mp4");const o=t?await Xr.getImageSize(n):await Xr.getVideoSize(n),i=await Xr.isAnimated(n)||r;return{id:e,type:t?"image":"video",typeName:"asset",props:{name:n.name,src:"",w:o.w,h:o.h,fileSize:n.size,mimeType:s,isAnimated:i},meta:{}}}async function K5(n,e,t){if(!e.length)return[];const r=C.From(t),s=[];for(let o=0;o<e.length;o++){const i=e[o];switch(i.type){case"image":{s.push({id:Ct(),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:Ct(),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 n.run(()=>{const o=e.filter(i=>!n.getAsset(i.id));o.length&&n.createAssets(o),n.createShapes(s).select(...s.map(i=>i.id)),W5(n,t)}),s.map(o=>o.id)}function W5(n,e){const t=n.getViewportPageBounds();let r=n.getSelectionPageBounds();if(r){const s=r.center.sub(e);n.updateShapes(n.getSelectedShapes().map(o=>{const i=n.getShapeParentTransform(o).decompose().rotation,a=C.Rot(s,-i);return{id:o.id,type:o.type,x:o.x-a.x,y:o.y-a.y}}))}if(r=n.getSelectionPageBounds(),r&&n.getInstanceState().isGridMode){const s=n.getDocumentSettings().gridSize,o=new C(r.minX,r.minY),i=o.clone().snapToGrid(s),a=C.Sub(o,i);n.updateShapes(n.getSelectedShapes().map(c=>{const d={x:c.x-a.x,y:c.y-a.y};return{id:c.id,type:c.type,x:d.x,y:d.y}}))}r=n.getSelectionPageBounds(),r&&!t.contains(r)&&n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})}function CJ(n,e,t){const r={id:Ct(),type:"bookmark",x:t.x-150,y:t.y-160,opacity:1,props:{assetId:null,url:e}};return n.run(()=>{n.createShapes([r]).select(r.id),W5(n,t)}),n.getShape(r.id)}var fw;let _J=(fw=class extends Re{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}onKeyUp(e){var t;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),(t=this.editor.root.getCurrent())==null||t.transition("editing_shape",{...e,target:"shape",shape:r}))}}},j(fw,"id","idle"),fw);var gw;let IJ=(gw=class extends Re{constructor(){super(...arguments);j(this,"shape");j(this,"markId","");j(this,"preciseTimeout",-1);j(this,"didTimeout",!1)}onEnter(){this.markId="",this.didTimeout=!1;const t=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});t?this.editor.setHintingShapes([t.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 f;const{originPagePoint:t}=this.editor.inputs,r=Ct();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`);const s=Zs(t,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"),c=this.shape,d=i.find(g=>g.id==="start"),h=(f=a.onHandleDrag)==null?void 0:f.call(a,o,{handle:{...d,x:0,y:0},isPrecise:!0,initial:c});h&&this.editor.updateShapes([h]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,o;const t=this.shape;if(!t)throw Error("expected shape");const r=this.editor.getShapeHandles(t);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=r.find(h=>h.id==="start"),d=(s=i.onHandleDrag)==null?void 0:s.call(i,t,{handle:{...c,x:0,y:0},isPrecise:this.didTimeout,initial:a});d&&this.editor.updateShapes([d])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),d=r.find(f=>f.id==="end"),h=(o=i.onHandleDrag)==null?void 0:o.call(i,this.editor.getShape(t),{handle:{...d,x:c.x,y:c.y},isPrecise:!1,initial:a});h&&this.editor.updateShapes([h])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},j(gw,"id","pointing"),gw);class P0 extends Re{constructor(){super(...arguments);j(this,"shapeType","arrow")}static children(){return[_J,IJ]}}j(P0,"id","arrow"),j(P0,"initial","idle");const EJ=n=>n*.65+I8(n*pt/2)*.35,TJ=n=>({size:n,thinning:.5,streamline:Ac(n,[9,16],[.64,.74],!0),smoothing:.62,easing:vn.easeOutSine,simulatePressure:!0}),kJ=n=>({size:1+n*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:EJ}),uk=n=>({size:n,thinning:0,streamline:Ac(n,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:vn.linear}),MJ=n=>({size:n,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:vn.linear});function Z1({strokeWidth:n,showAsComplete:e}){return{size:1+n,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:vn.easeOutSine,last:e}}function C0(n,e,t,r){const s=n.isComplete||t;return r?n.isPen?{...MJ(e),last:s}:{...uk(e),last:s}:n.dash==="draw"?n.isPen?{...kJ(e),last:s}:{...TJ(e),last:s}:{...uk(e),last:s}}function Lc(n){const e=[];for(const t of n)if(t.type==="free"||t.points.length<2)e.push(...t.points.map(C.Cast));else{const r=Math.max(4,Math.floor(C.Dist(t.points[0],t.points[1])/16));e.push(...C.PointsBetween(t.points[0],t.points[1],r))}return e}function AJ(n,e,t){return{draw:"none",solid:"none",dotted:`${t} ${e*2}`,dashed:`${e*2} ${e*2}`}[n.props.dash]}function gl(n,e=!1){const t=n.length;if(t<2)return"";let r=n[0].point,s=n[1].point;if(t===2)return`M${ht(r)}L${ht(s)}`;let o="";for(let i=2,a=t-1;i<a;i++)r=n[i].point,s=n[i+1].point,o+=jr(r,s);return e?`M${jr(n[0].point,n[1].point)}Q${ht(n[1].point)}${jr(n[1].point,n[2].point)}T${o}${jr(n[t-1].point,n[0].point)}${jr(n[0].point,n[1].point)}Z`:`M${ht(n[0].point)}Q${ht(n[1].point)}${jr(n[1].point,n[2].point)}${n.length>3?"T":""}${o}L${ht(n[t-1].point)}`}const G5=(n,e,t)=>{const r=[],s=[];n.forEach(d=>r.push(...d.points)),e.forEach(d=>s.push(...d.points));const o=Math.max(r.length,s.length),i=[],a=[];for(let d=0;d<o;d++)i.push(r[d]||r[r.length-1]),a.push(s[d]||s[s.length-1]);return[{type:"free",points:i.map((d,h)=>{let f=.5;return a[h].z!==void 0&&d.z!==void 0&&(f=ot(d.z,a[h].z,t)),{x:ot(d.x,a[h].x,t),y:ot(d.y,a[h].y,t),z:f}})}]};function jJ(){const[n,e]=_.useState(!1);return _.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)},[]),se(sn.forceSrgb)||!n?"srgb":"p3"}function ks(){return _i({isDarkMode:eh()})}const wo=class wo extends Xs{hideResizeHandles(e){return Gp(e)}hideRotateHandle(e){return Gp(e)}hideSelectionBoundsFg(e){return Gp(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const t=Qa(e);if(Gp(e))return new r1({x:-t/2,y:-t/2,radius:t/2,isFilled:!0});const{strokePoints:r,sw:s}=dk(e,t,!0),o=Z1({strokeWidth:s,showAsComplete:!0});return fm(r,o),new rn({points:q1(r,o),isFilled:!0})}component(e){const t=nw(this.editor,e),r=Qa(e);return p.jsx(ha,{children:p.jsx(Vp,{shape:e,forceSolid:t,strokeWidth:r,opacity:wo.options.overlayOpacity})})}backgroundComponent(e){const t=nw(this.editor,e),r=Qa(e);return p.jsx(ha,{children:p.jsx(Vp,{shape:e,forceSolid:t,strokeWidth:r,opacity:wo.options.underlayOpacity})})}indicator(e){const t=nw(this.editor,e),r=Qa(e),{strokePoints:s,sw:o}=dk(e,r,t),i=Lc(e.props.segments);let a;return s.length<2?a=OJ(i[0],o):a=gl(s,!1),p.jsx("path",{d:a})}toSvg(e){const t=Qa(e),r=t<1.5,s=1/e.props.scale;return p.jsx("g",{transform:`scale(${s})`,children:p.jsx(Vp,{forceSolid:r,strokeWidth:t,shape:e,opacity:wo.options.overlayOpacity})})}toBackgroundSvg(e){const t=Qa(e),r=t<1.5,s=1/e.props.scale;return p.jsx("g",{transform:`scale(${s})`,children:p.jsx(Vp,{forceSolid:r,strokeWidth:t,shape:e,opacity:wo.options.underlayOpacity})})}onResize(e,t){const{scaleX:r,scaleY:s}=t,o=[];for(const i of e.props.segments)o.push({...i,points:i.points.map(({x:a,y:c,z:d})=>({x:r*a,y:s*c,z:d}))});return{props:{segments:o}}}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,...t.props,segments:G5(e.props.segments,t.props.segments,r),scale:ot(e.props.scale,t.props.scale,r)}}};j(wo,"type","highlight"),j(wo,"props",GA),j(wo,"migrations",VA),j(wo,"options",{maxPointsPerShape:600,underlayOpacity:.82,overlayOpacity:.35});let dg=wo;function RJ(n){return`M ${n.x} ${n.y} m -${.1}, 0 a ${.1},${.1} 0 1,0 ${.1*2},0 a ${.1},${.1} 0 1,0 -${.1*2},0`}function OJ(n,e){const t=e/2;return`M ${n.x} ${n.y} m -${t}, 0 a ${t},${t} 0 1,0 ${t*2},0 a ${t},${t} 0 1,0 -${t*2},0`}function dk(n,e,t){var c;const r=Lc(n.props.segments),s=n.props.isComplete||((c=In(n.props.segments))==null?void 0:c.type)==="straight";let o=e;!t&&!n.props.isPen&&r.length===1&&(o+=eo(n.id)()*(e/6));const i=Z1({strokeWidth:o,showAsComplete:s});return{strokePoints:No(r,i),sw:o}}function Qa(n){return Oc[n.props.size]*1.12*n.props.scale}function Gp(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function Vp({strokeWidth:n,forceSolid:e,shape:t,opacity:r}){var g;const s=ks(),o=Lc(t.props.segments);let i=n;!e&&!t.props.isPen&&o.length===1&&(i+=eo(t.id)()*(i/6));const a=Z1({strokeWidth:i,showAsComplete:t.props.isComplete||((g=In(t.props.segments))==null?void 0:g.type)==="straight"}),c=No(o,a),d=c.length>1?gl(c,!1):RJ(t.props.segments[0].points[0]),h=jJ(),f=s[t.props.color].highlight[h];return p.jsx("path",{d,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:f,strokeWidth:i,opacity:r})}function nw(n,e){return se("forceSolid",()=>{const t=Qa(e),r=n.getZoomLevel();return t/r<1.5},[n])}function gm(n){return{key:`${Ro.id}:${n}`,async getElement(){const e=DJ(n);if(!e)return null;const{url:t,fontFaceRule:r}=e,s=await(await jo(t)).blob(),o=await Gs.blobToDataUrl(s),i=r.replace(t,o);return p.jsx("style",{children:i})}}}function DJ(n){const e=CA[n];for(const t of document.fonts)if(e.includes(t.family)&&"$$_url"in t&&typeof t.$$_url=="string"&&"$$_fontface"in t&&typeof t.$$_fontface=="string")return{url:t.$$_url,fontFaceRule:t.$$_fontface};return null}function Q1(n){return{key:`${Ro.id}:${n}`,async getElement(){return n!=="pattern"?null:p.jsx(LJ,{})}}}function LJ(){const n=eP(),e=Wc(),t=ks(),r=8/12;return p.jsxs(p.Fragment,{children:[p.jsxs("mask",{id:e,children:[p.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),p.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[p.jsx("line",{x1:r*1,y1:r*3,x2:r*3,y2:r*1}),p.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),p.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),p.jsx("pattern",{id:n(1,t.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:p.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:t.solid,mask:`url(#${e})`})})]})}function J1(){return{key:`${Ro.id}:pattern`,component:zJ}}const od=8,hk=(n,e,t)=>new Promise((r,s)=>{const o=od*e*n,i=document.createElement("canvas");i.width=o,i.height=o;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?Hf.darkMode.solid:Hf.lightMode.solid,a.fillRect(0,0,o,o),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*e*n;const c=8/12,d=h=>h*e*n;a.beginPath(),a.moveTo(d(c*1),d(c*3)),a.lineTo(d(c*3),d(c*1)),a.moveTo(d(c*5),d(c*7)),a.lineTo(d(c*7),d(c*5)),a.moveTo(d(c*9),d(c*11)),a.lineTo(d(c*11),d(c*9)),a.stroke(),i.toBlob(h=>{!h||sn.throwToBlob.get()?s():r(h)})}),pk=(n,e)=>{const t=document.createElement("canvas");t.width=n[0],t.height=n[1];const r=t.getContext("2d");return r?(e(r),t.toDataURL()):""};let rw=null;function FJ(){return rw||(rw={white:pk([1,1],n=>{n.fillStyle="#f8f9fa",n.fillRect(0,0,1,1)}),black:pk([1,1],n=>{n.fillStyle="#212529",n.fillRect(0,0,1,1)})}),rw}function V5(n){return Math.ceil(Math.log2(Math.max(1,n)))}function eP(){const n=Ys("hash_pattern");return _.useCallback((e,t)=>{const r=V5(e);return Rb(n,`${t}_${r}`)},[n])}function q5(n){const e=[],r=V5(n);for(let s=0;s<=r;s++)e.push(Math.pow(2,s));return e}function NJ(n){const e=FJ();return q5(n).flatMap(t=>[{zoom:t,url:e.white,theme:"light"},{zoom:t,url:e.black,theme:"dark"}])}function $J(){const n=te(),e=se("devicePixelRatio",()=>n.getInstanceState().devicePixelRatio,[n]),t=se("maxZoom",()=>Math.ceil(In(n.getCameraOptions().zoomSteps)),[n]),[r,s]=_.useState(!1),[o,i]=_.useState(()=>NJ(t)),a=eP();return _.useEffect(()=>{const d=Promise.all(q5(t).flatMap(f=>[hk(e,f,!1).then(g=>({zoom:f,theme:"light",url:URL.createObjectURL(g)})),hk(e,f,!0).then(g=>({zoom:f,theme:"dark",url:URL.createObjectURL(g)}))]));let h=!1;return d.then(f=>{h||(i(f),s(!0))}),()=>{h=!0,s(!1),d.then(f=>{for(const{url:g}of f)URL.revokeObjectURL(g)})}},[e,t]),{defs:p.jsx(p.Fragment,{children:o.map(d=>{const h=a(d.zoom,d.theme);return p.jsx("pattern",{id:h,width:od,height:od,patternUnits:"userSpaceOnUse",children:p.jsx("image",{href:d.url,width:od,height:od})},h)})}),isReady:r}}function zJ(){const n=te(),e=_.useRef(null),{defs:t,isReady:r}=$J();return _.useEffect(()=>{if(r&&Et.isSafari){const s=Y5(e.current);s&&n.timers.requestAnimationFrame(()=>{s.style.display="none",n.timers.requestAnimationFrame(()=>{s.style.display=""})})}},[n,r]),p.jsx("g",{ref:e,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function Y5(n){return n.classList.contains("tl-html-layer")?n:n.parentElement?Y5(n.parentElement):null}const Un=at.memo(function({theme:e,d:t,color:r,fill:s,scale:o}){switch(s){case"none":return null;case"solid":return p.jsx("path",{fill:e[r].semi,d:t});case"semi":return p.jsx("path",{fill:e.solid,d:t});case"fill":return p.jsx("path",{fill:e[r].fill,d:t});case"pattern":return p.jsx(BJ,{theme:e,color:r,fill:s,d:t,scale:o})}});function BJ({d:n,color:e,theme:t}){const r=te(),s=Xd(),o=se("zoomLevel",()=>r.getZoomLevel(),[r]),i=eP(),a=r.getZoomLevel()<=.18;return p.jsxs(p.Fragment,{children:[p.jsx("path",{fill:t[e].pattern,d:n}),p.jsx("path",{fill:s?`url(#${i(1,t.id)})`:a?t[e].semi:`url(#${i(o,t.id)})`,d:n})]})}function UJ(n,e={}){const{start:t={},end:r={}}=e,{cap:s=!0}=t,{cap:o=!0}=r;mt(!t.taper&&!r.taper,"cap taper not supported here"),mt(!t.easing&&!r.easing,"cap easing not supported here"),mt(s&&o,"cap must be true");const i=No(n,e);fm(i,e);const a=HJ(i);let c="";for(const d of a)c+=WJ(d,e);return c}function HJ(n){if(n.length<=2)return[n];const e=[];let t=[n[0]],r=C.Sub(n[1].point,n[0].point).uni(),s,o,i,a,c;for(let d=1,h=n.length;d<h-1;d++){if(i=n[d-1],a=n[d],c=n[d+1],s=C.Sub(c.point,a.point).uni(),o=C.Dpr(r,s),r=s,o<-.8){const f={...a,point:a.input};t.push(f),e.push(sw(t)),t=[f];continue}if(t.push(a),!(o>.7)&&(C.Dist2(i.point,a.point)+C.Dist2(a.point,c.point))/((i.radius+a.radius+c.radius)/3)**2<1.5){t.push(a),e.push(sw(t)),t=[a];continue}}return t.push(n[n.length-1]),e.push(sw(t)),e}function sw(n){const e=n[0];let t;for(;n.length>2&&(t=n[1],C.Dist2(e.point,t.point)<((e.radius+t.radius)/2*.5)**2);)n.splice(1,1);const r=n[n.length-1];let s;for(;n.length>2&&(s=n[n.length-2],C.Dist2(r.point,s.point)<((r.radius+s.radius)/2*.5)**2);)n.splice(n.length-2,1);return n.length>1&&(n[0]={...n[0],vector:C.Sub(n[0].point,n[1].point).uni()},n[n.length-1]={...n[n.length-1],vector:C.Sub(n[n.length-2].point,n[n.length-1].point).uni()}),n}function KJ(n,e,t){return"M "+n+" "+e+" m -"+t+", 0 a "+t+","+t+" 0 1,1 "+t*2+",0 a "+t+","+t+" 0 1,1 -"+t*2+",0"}function WJ(n,e={}){if(n.length===0)return"";if(n.length===1)return KJ(n[0].point.x,n[0].point.y,n[0].radius);const{left:t,right:r}=F5(n,e);r.reverse();let s=`M${ht(t[0])}T`;for(let o=1;o<t.length;o++)s+=jr(t[o-1],t[o]);{const o=n[n.length-1],i=o.radius,a=o.vector.clone().per().neg(),c=C.Add(o.point,C.Mul(a,i)),d=C.Add(o.point,C.Mul(a,-i));s+=`${ht(c)}A${ee(i)},${ee(i)} 0 0 1 ${ht(d)}T`}for(let o=1;o<r.length;o++)s+=jr(r[o-1],r[o]);{const o=n[0],i=o.radius,a=o.vector.clone().per(),c=C.Add(o.point,C.Mul(a,i)),d=C.Add(o.point,C.Mul(a,-i));s+=`${ht(c)}A${ee(i)},${ee(i)} 0 0 1 ${ht(d)}Z`}return s}class Pc extends Xs{hideResizeHandles(e){return ow(e)}hideRotateHandle(e){return ow(e)}hideSelectionBoundsFg(e){return ow(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(e){const t=Lc(e.props.segments),r=(qn[e.props.size]+1)*e.props.scale;if(e.props.segments.length===1){const o=Se.FromPoints(t);if(o.width<r*2&&o.height<r*2)return new r1({x:-r,y:-r,radius:r,isFilled:!0})}const s=No(t,C0(e.props,r,e.props.isPen,!0)).map(o=>o.point);return e.props.isClosed?new rn({points:s,isFilled:e.props.fill!=="none"}):new qc({points:s})}component(e){return p.jsx(ha,{children:p.jsx(fk,{shape:e})})}indicator(e){var d;const t=Lc(e.props.segments);let r=(qn[e.props.size]+1)*e.props.scale;!se("force solid",()=>{const h=this.editor.getZoomLevel();return h<.5&&h<1.5/r},[this.editor,r])&&!e.props.isPen&&e.props.dash==="draw"&&t.length===1&&(r+=eo(e.id)()*(r/6));const o=e.props.isComplete||((d=In(e.props.segments))==null?void 0:d.type)==="straight",i=C0(e.props,r,o,!0),a=No(t,i),c=a.length>1?gl(a,e.props.isClosed):X5(t[0],r);return p.jsx("path",{d:c})}toSvg(e,t){t.addExportDef(Q1(e.props.fill));const r=1/e.props.scale;return p.jsx("g",{transform:`scale(${r})`,children:p.jsx(fk,{shape:e,zoomOverride:1})})}getCanvasSvgDefs(){return[J1()]}onResize(e,t){const{scaleX:r,scaleY:s}=t,o=[];for(const i of e.props.segments)o.push({...i,points:i.points.map(({x:a,y:c,z:d})=>({x:di(r*a),y:di(s*c),z:d}))});return{props:{segments:o}}}expandSelectionOutlinePx(e){const t=e.props.dash==="draw"?1.6:1;return qn[e.props.size]*t/2*e.props.scale}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,segments:G5(e.props.segments,t.props.segments,r),scale:ot(e.props.scale,t.props.scale,r)}}}j(Pc,"type","draw"),j(Pc,"props",LA),j(Pc,"migrations",FA),j(Pc,"options",{maxPointsPerShape:600});function X5(n,e){const t=(e+1)*.5;return`M ${n.x} ${n.y} m -${t}, 0 a ${t},${t} 0 1,0 ${t*2},0 a ${t},${t} 0 1,0 -${t*2},0`}function ow(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function fk({shape:n,zoomOverride:e}){var y;const t=ks(),r=te(),s=Lc(n.props.segments),o=n.props.isComplete||((y=In(n.props.segments))==null?void 0:y.type)==="straight";let i=(qn[n.props.size]+1)*n.props.scale;const a=se("force solid",()=>{const S=e??r.getZoomLevel();return S<.5&&S<1.5/i},[r,i,e]),c=se("dot adjustment",()=>(e??r.getZoomLevel())<.2?0:.1,[r,e]);!a&&!n.props.isPen&&n.props.dash==="draw"&&s.length===1&&(i+=eo(n.id)()*(i/6));const d=C0(n.props,i,o,a);if(!a&&n.props.dash==="draw")return p.jsxs(p.Fragment,{children:[n.props.isClosed&&n.props.fill&&s.length>1?p.jsx(Un,{d:gl(No(s,d),n.props.isClosed),theme:t,color:n.props.color,fill:n.props.isClosed?n.props.fill:"none",scale:n.props.scale}):null,p.jsx("path",{d:UJ(s,d),strokeLinecap:"round",fill:t[n.props.color].solid})]});const h=No(s,d),f=h.length<2,g=f?X5(s[0],0):gl(h,n.props.isClosed);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{d:g,theme:t,color:n.props.color,fill:f||n.props.isClosed?n.props.fill:"none",scale:n.props.scale}),p.jsx("path",{d:g,strokeLinecap:"round",fill:f?t[n.props.color].solid:"none",stroke:t[n.props.color].solid,strokeWidth:i,strokeDasharray:f?"none":AJ(n,i,c),strokeDashoffset:"0"})]})}class tP extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"initialShape");j(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");j(this,"util",this.editor.getShapeUtil(this.shapeType));j(this,"maxPoints",500);j(this,"isPen",!1);j(this,"isPenOrStylus",!1);j(this,"segmentMode","free");j(this,"didJustShiftClickToExtendPreviousShapeLine",!1);j(this,"pagePointWhereCurrentSegmentChanged",{});j(this,"pagePointWhereNextSegmentChanged",null);j(this,"lastRecordedPoint",{});j(this,"mergeNextPoint",!1);j(this,"currentLineLength",0);j(this,"markId",null)}onEnter(t){this.markId=null,this.info=t,this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.startShape(),this.maxPoints=this.shapeType==="draw"?Pc.options.maxPointsPerShape:dg.options.maxPointsPerShape}onPointerMove(){const{inputs:t}=this.editor;if(this.isPen&&!t.isPen&&this.markId){this.editor.bailToMark(this.markId),this.startShape();return}this.isPenOrStylus?C.Dist(t.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=t.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape()}onKeyDown(t){if(t.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(t){if(t.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(t,r,s){if(!this.canClose())return!1;const o=qn[r],i=t[0].points[0],a=t[t.length-1],c=a.points[a.points.length-1];return i!==c&&this.currentLineLength>o*4*s&&C.DistMin(i,c,o*2*s)}startShape(){const{inputs:{originPagePoint:t,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=t.clone(),this.initialShape){const a=this.editor.getShape(this.initialShape.id);if(a&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const c=In(a.props.segments);if(!c)throw Error("Expected a previous segment!");const d=In(c.points);if(!d)throw Error("Expected a previous point!");const{x:h,y:f}=this.editor.getPointInShapeSpace(a,t).toFixed(),g={type:this.segmentMode,points:[{x:d.x,y:d.y,z:+o.toFixed(2)},{x:h,y:f,z:+o.toFixed(2)}]},y=me.applyToPoint(this.editor.getShapePageTransform(a.id),d);this.pagePointWhereCurrentSegmentChanged=y,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,g];this.currentLineLength<qn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const v={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(v.props.isClosed=this.getIsClosed(S,a.props.size,a.props.scale)),this.editor.updateShapes([v]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const i=Ct();this.editor.createShapes([{id:i,type:this.shapeType,x:t.x,y:t.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:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:s,props:{size:o,scale:i}}=t,a=this.editor.getShape(s);if(!a)return;const{segments:c}=a.props,{x:d,y:h,z:f}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),g=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,y={x:d,y:h,z:g};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:S}=this;if(S===null)throw Error("We should have a point where the segment changed");if(C.Dist2(S,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const w=In(c);if(!w)throw Error("Expected a previous segment!");const b=In(w.points);if(!b)throw Error("Expected a previous last point!");let P;const k=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(w.type==="straight"){this.currentLineLength+=C.Dist(b,k),P={type:"straight",points:[{...b},k]};const M=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=me.applyToPoint(M,b)}else P={type:"straight",points:[k,y]};const E={id:s,type:this.shapeType,props:{segments:[...c,P]}};this.canClose()&&(E.props.isClosed=this.getIsClosed(c,o,i)),this.editor.updateShapes([E])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:S}=this;if(S===null)throw Error("We should have a point where the segment changed");if(C.Dist2(S,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const w=c.slice(),b=w[w.length-1],P=In(b.points);if(!P)throw Error("No previous point!");const k={type:"free",points:[...C.PointsBetween(P,y,6).map(A=>({x:di(A.x),y:di(A.y),z:di(A.z)}))]},E=[...w,k];this.currentLineLength<qn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(E));const M={id:s,type:this.shapeType,props:{segments:E}};this.canClose()&&(M.props.isClosed=this.getIsClosed(E,o,i)),this.editor.updateShapes([M])}break}case"straight":{const S=c.slice(),v=S[S.length-1],{pagePointWhereCurrentSegmentChanged:w}=this,{ctrlKey:b,currentPagePoint:P}=this.editor.inputs;if(!w)throw Error("We should have a point where the segment changed");let k,E=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(E=!b,this.didJustShiftClickToExtendPreviousShapeLine=!1):E=!b;let M=this.editor.getPointInShapeSpace(a,P).toFixed().toJson(),A=!1,R;if((this.editor.user.getIsSnapMode()?!b:b)&&S.length>2){let L,U=8/this.editor.getZoomLevel();for(let K=0,F=c.length-2;K<F;K++){const $=c[K];if(!$)break;if($.type==="free")continue;const W=$.points[0],Y=In($.points);if(!(W&&Y))continue;const Z=C.NearestPointOnLineSegment(W,Y,M);if(C.DistMin(Z,M,U)){L=Z.toFixed().toJson(),U=C.Dist(Z,M),R=$;break}}L&&(A=!0,M=L)}if(A&&R){const L=this.editor.getShapePageTransform(a),U=R.points[0],K=In(R.points);if(!K)throw Error("Expected a last point!");const F=me.applyToPoint(L,U),$=me.applyToPoint(L,K),W=me.applyToPoint(L,M);this.editor.snaps.setIndicators([{id:xt(),type:"points",points:[F,W,$]}])}else{if(this.editor.snaps.clearIndicators(),E){const L=C.Angle(w,P),K=Lf(L,24)-L;k=C.RotWith(P,w,K)}else k=P;M=this.editor.getPointInShapeSpace(a,k).toFixed().toJson()}this.currentLineLength+=C.Dist(v.points[0],M),S[S.length-1]={...v,type:"straight",points:[v.points[0],M]};const V={id:s,type:this.shapeType,props:{segments:S}};this.canClose()&&(V.props.isClosed=this.getIsClosed(c,o,i)),this.editor.updateShapes([V]);break}case"free":{const S=c.slice(),v=S[S.length-1],w=[...v.points];if(w.length&&this.mergeNextPoint){const{z:P}=w[w.length-1];w[w.length-1]={x:y.x,y:y.y,z:P?Math.max(P,y.z):y.z}}else this.currentLineLength+=C.Dist(w[w.length-1],y),w.push(y);S[S.length-1]={...v,points:w},this.currentLineLength<qn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const b={id:s,type:this.shapeType,props:{segments:S}};if(this.canClose()&&(b.props.isClosed=this.getIsClosed(S,o,i)),this.editor.updateShapes([b]),w.length>this.maxPoints){this.editor.updateShapes([{id:s,type:this.shapeType,props:{isComplete:!0}}]);const P=Ct(),k=this.editor.getShape(s).props;this.editor.createShapes([{id:P,type:this.shapeType,x:di(r.currentPagePoint.x),y:di(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:k.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(f*1.25).toFixed():.5}]}]}}]),this.initialShape=Nt(this.editor.getShape(P)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(t){let r=0;for(const s of t)for(let o=0;o<s.points.length-1;o++){const i=s.points[o],a=s.points[o+1];r+=C.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:t}=this;t&&(this.editor.updateShapes([{id:t.id,type:t.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}j(tP,"id","drawing");var mw;let Z5=(mw=class extends Re{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},j(mw,"id","idle"),mw);class pf extends Re{constructor(){super(...arguments);j(this,"shapeType","draw")}static children(){return[Z5,tP]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}j(pf,"id","draw"),j(pf,"initial","idle"),j(pf,"isLockable",!1);class _0 extends o0{constructor(){super(...arguments);j(this,"shapeType","frame")}onCreate(t){if(!t)return;const r=this.editor.getShapePageBounds(t),s=[],o=this.editor.getShapeAncestors(t).map(i=>i.id);this.editor.getSortedChildIdsForParent(t.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===t.id||a.isLocked)return;const c=this.editor.getShapePageBounds(a);c&&r.contains(c)&&GJ(a,o,t)&&s.push(a.id)}),this.editor.reparentShapes(s,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")}}j(_0,"id","frame"),j(_0,"initial","idle");function GJ(n,e,t){return e.includes(n.id)?!1:n.parentId===t.parentId}var yw;let VJ=(yw=class extends Re{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onKeyUp(e){var t;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),(t=this.editor.root.getCurrent())==null||t.transition("editing_shape",{...e,target:"shape",shape:r}))}}onCancel(){this.editor.setCurrentTool("select")}},j(yw,"id","idle"),yw);var Sw;let qJ=(Sw=class extends Re{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=Ct(),s=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`),o=Zs(t,this.editor);this.editor.createShapes([{id:r,type:"geo",x:o.x,y:o.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(qs),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,t=Ct();this.editor.markHistoryStoppingPoint(`creating_geo:${t}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(qs),o=s==="star"?{w:200,h:190}:s==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:t,type:"geo",x:e.x,y:e.y,props:{geo:this.editor.getStyleForNextShape(qs),scale:r,...o}}]);const i=this.editor.getShape(t);if(!i)return;const{w:a,h:c}=i.props,d=new C(a/2,c/2).mul(r),h=this.editor.getShapeParentTransform(i);h&&d.rot(-h.rotation());const f=Zs(new C(i.x-d.x,i.y-d.y),this.editor);this.editor.select(t),this.editor.updateShape({id:i.id,type:"geo",x:f.x,y:f.y,props:{geo:this.editor.getStyleForNextShape(qs),w:a*r,h:c*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},j(Sw,"id","pointing"),Sw);class I0 extends Re{constructor(){super(...arguments);j(this,"shapeType","geo")}static children(){return[VJ,qJ]}}j(I0,"id","geo"),j(I0,"initial","idle");class ff extends Re{constructor(){super(...arguments);j(this,"shapeType","highlight")}static children(){return[Z5,tP]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}j(ff,"id","highlight"),j(ff,"initial","idle"),j(ff,"isLockable",!1);var vw;let YJ=(vw=class extends Re{constructor(){super(...arguments);j(this,"shapeId","")}onEnter(t){this.shapeId=t.shapeId,this.editor.setCursor({type:"cross",rotation:0})}onPointerDown(){this.parent.transition("pointing",{shapeId:this.shapeId})}onCancel(){this.editor.setCurrentTool("select")}},j(vw,"id","idle"),vw);const gk=2;var xw;let XJ=(xw=class extends Re{constructor(){super(...arguments);j(this,"shape",{});j(this,"markId")}onEnter(t){const{inputs:r}=this.editor,{currentPagePoint:s}=r;this.markId=void 0;const o=t.shapeId&&this.editor.getShape(t.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(S=>S.type==="vertex").sort(Wn),c=a[a.length-1],d=a[a.length-2],h=me.applyToPoint(this.editor.getShapeParentTransform(this.shape),new C(this.shape.x,this.shape.y)),f=C.Sub(s,h).addXY(.1,.1),g=Zs(f,this.editor),y=Nt(this.shape.props.points);if(C.DistMin(c,d,gk)||C.DistMin(g,c,gk))y[c.id]={id:c.id,index:c.index,x:g.x,y:g.y};else{const S=Co(c.index);y[S]={id:S,index:S,x:g.x,y:g.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:y}}])}else{const i=Ct();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i}`);const a=Zs(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 t=this.editor.getShapeHandles(this.shape);if(!t)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=In(t);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()}},j(xw,"id","pointing"),xw);class E0 extends Re{constructor(){super(...arguments);j(this,"shapeType","line")}static children(){return[YJ,XJ]}}j(E0,"id","line"),j(E0,"initial","idle");var ww;let ZJ=(ww=class extends Re{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},j(ww,"id","idle"),ww);const QJ=0,Pt=200,mm=new C(Pt/2,Pt/2),Q5=10,JJ=n=>[[["a1"],new C(Pt*.5,Pt*-.5-n.options.adjacentShapeMargin)],[["a2"],new C(Pt*1.5+n.options.adjacentShapeMargin,Pt*.5)],[["a3"],new C(Pt*.5,Pt*1.5+n.options.adjacentShapeMargin)],[["a4"],new C(Pt*-.5-n.options.adjacentShapeMargin,Pt*.5)]];function eee(n,e){if(e===1)return JJ(n);const t=Pt*e,r=n.options.adjacentShapeMargin*e;return[[["a1"],new C(t*.5,t*-.5-r)],[["a2"],new C(t*1.5+r,t*.5)],[["a3"],new C(t*.5,t*1.5+r)],[["a4"],new C(t*-.5-r,t*.5)]]}function J5(n,e,t,r,s,o){return Object.fromEntries(eee(n,o).map(([i,a],c)=>{const d=a.clone();return c===0&&s?d.y-=s:c===2&&r&&(d.y+=r),[i,d.rot(t).add(e)]}))}function eF(n,e,t,r){const s=new Set(n.getSelectedShapeIds()),o=(Pt+n.options.adjacentShapeMargin+r)**2,i=new Map,a=[];for(const h of n.getCurrentPageShapes()){if(!n.isShapeOfType(h,"note")||t!==h.props.scale||s.has(h.id))continue;const f=n.getShapePageTransform(h.id);e===f.rotation()&&(i.set(h,n.getShapePageBounds(h).center),a.push(...Object.values(J5(n,f.point(),e,h.props.growY,r,t))))}const c=a.length;let d;for(const[h,f]of i)for(let g=0;g<c;g++)d=a[g],d&&(C.Dist2(f,d)>o||n.isPointInShape(h,d)&&(a[g]=void 0));return Ye(a)}function tF(n,e,t,r,s=!1){let o;const i=n.getCurrentPageShapesSorted(),a=(Pt+n.options.adjacentShapeMargin**2)**e.props.scale;for(let c=i.length-1;c>=0;c--){const d=i[c];if(d.type==="note"&&d.id!==e.id){const h=n.getShapePageBounds(d);if(h&&C.Dist2(h.center,t)<a&&n.isPointInShape(d,t)){o=d;break}}}if(n.complete(),!o||s){n.markHistoryStoppingPoint("creating note shape");const c=Ct();n.createShape({id:c,type:"note",x:t.x,y:t.y,rotation:r,opacity:e.opacity,props:{...e.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const d=n.getShape(c);if(!d)return;const h=n.getPointInParentSpace(d,C.Sub(t,C.Rot(mm.clone().mul(d.props.scale),r)));n.updateShape({id:c,type:"note",x:h.x,y:h.y}),o=n.getShape(c)}return nee(n),o}const tee=16;function nee(n){const e=n.getSelectionPageBounds(),t=n.getViewportPageBounds();if(e&&!t.contains(e)){const r=e.clone().expandBy(tee/n.getZoomLevel()).expand(t),s=t.clone().translate({x:(r.center.x-t.center.x)*2,y:(r.center.y-t.center.y)*2});n.zoomToBounds(s,{animation:{duration:n.options.animationMediumMs},inset:0})}}var bw;let ree=(bw=class extends Re{constructor(){super(...arguments);j(this,"dragged",!1);j(this,"info",{});j(this,"markId","");j(this,"shape",{})}onEnter(){const{editor:t}=this,r=Ct();this.markId=t.markHistoryStoppingPoint(`creating_note:${r}`);const s=this.editor.inputs.originPagePoint.clone(),o=see(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);o&&s.sub(o),this.shape=oee(this.editor,r,s)}onPointerMove(t){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.translating",{...t,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)}},j(bw,"id","pointing"),bw);function see(n,e,t){let r=Q5/n.getZoomLevel(),s;for(const o of eF(n,0,t,0)){const i=C.Sub(e,o),a=i.len();a<r&&(r=a,s=i)}return s}function oee(n,e,t){n.createShape({id:e,type:"note",x:t.x,y:t.y,props:{scale:n.user.getIsDynamicResizeMode()?1/n.getZoomLevel():1}}).select(e);const r=n.getShape(e),s=n.getShapeGeometry(r).bounds,o=Zs(new C(r.x-s.width/2,r.y-s.height/2),n);return n.updateShapes([{id:e,type:"note",x:o.x,y:o.y}]),n.getShape(e)}class T0 extends Re{constructor(){super(...arguments);j(this,"shapeType","note")}static children(){return[ZJ,ree]}}j(T0,"id","note"),j(T0,"initial","idle");function iee(n){const e=n.getShapeAtPoint(n.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:n.options.hitTestMargin/n.getZoomLevel(),renderingOnly:!0});if(!e)return n.setHoveredShape(null);let t;const r=n.getOutermostSelectableShape(e);return r===e||r.id===n.getFocusedGroupId()||n.getSelectedShapeIds().includes(r.id)?t=e:t=r,n.setHoveredShape(t.id)}const pi=Zk(iee,32);var Pw;let aee=(Pw=class extends Re{onPointerMove(e){switch(e.target){case"shape":case"canvas":pi(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){pi.cancel()}onKeyDown(e){var t;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),(t=this.editor.root.getCurrent())==null||t.transition("editing_shape",{...e,target:"shape",shape:r}))}}onCancel(){this.editor.setCurrentTool("select")}},j(Pw,"id","idle"),Pw);var Cw;let lee=(Cw=class extends Re{constructor(){super(...arguments);j(this,"shape");j(this,"markId","");j(this,"enterTime",0)}onEnter(){this.enterTime=Date.now()}onExit(){this.editor.setHintingShapes([])}onPointerMove(t){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),d=Math.sqrt(r.getInstanceState().isCoarsePointer?r.options.coarseDragDistanceSquared:r.options.dragDistanceSquared)*6/r.getZoomLevel();if(a>d){const h=Ct();this.markId=r.markHistoryStoppingPoint(`creating_text:${h}`);const f=this.createTextShape(h,o,!1,a);if(!f){this.cancel();return}this.shape=r.getShape(f),r.select(h),r.setCurrentTool("select.resizing",{...t,target:"selection",handle:"right",isCreating:!0,creatingMarkId:this.markId,creationCursorOffset:{x:a,y:1},onInteractionEnd:"text",onCreate:()=>{r.setEditingShape(f.id)}})}}onPointerUp(){this.complete()}onComplete(){this.cancel()}onCancel(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.editor.markHistoryStoppingPoint("creating text shape");const t=Ct(),{originPagePoint:r}=this.editor.inputs;this.createTextShape(t,r,!0,20)&&(this.editor.select(t),this.editor.setEditingShape(t))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(t,r,s,o){this.editor.createShape({id:t,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(t);if(!i){this.cancel();return}const a=this.editor.getShapePageBounds(i),c=new C;if(s)switch(i.props.textAlign){case"start":{c.x=0;break}case"middle":{c.x=-a.width/2;break}case"end":{c.x=-a.width;break}}else c.x=0;if(c.y=-a.height/2,Mr(i.parentId)){const f=this.editor.getShapeParentTransform(i);c.rot(-f.rotation())}const d=i.x+c.x,h=i.y+c.y;if(this.editor.getInstanceState().isGridMode){const f=new C(d,h),g=Zs(f,this.editor),y=C.Sub(f,g);this.editor.updateShape({...i,x:d-y.x,y:h-y.y})}else this.editor.updateShape({...i,x:d,y:h});return i}},j(Cw,"id","pointing"),Cw);class k0 extends Re{constructor(){super(...arguments);j(this,"shapeType","text")}static children(){return[aee,lee]}}j(k0,"id","text"),j(k0,"initial","idle");const cee=[k0,pf,I0,T0,E0,_0,P0,ff];function uee(n){return n.replace(/\s/g," ")}function M0(n,e,t){const{padding:r=0}=t;if(e.length===0)return null;const s=Se.From(e[0].box);for(const{box:d}of e)s.union(d);const o=r+(t.offsetX??0),i=(t.offsetY??0)+t.fontSize/2+(t.verticalTextAlign==="start"?r:t.verticalTextAlign==="end"?t.height-r-s.height:(Math.ceil(t.height)-s.height)/2);let a=null;const c=[];for(const{text:d,box:h}of e)a!==null&&h.y>a&&c.push(p.jsx("tspan",{alignmentBaseline:"mathematical",x:o,y:h.y+i,children:`
|
|
362
|
+
`},c.length)),c.push(p.jsx("tspan",{alignmentBaseline:"mathematical",x:h.x+o,y:h.y+i,unicodeBidi:"plaintext",children:uee(d)},c.length)),a=h.y;return p.jsx("text",{fontSize:t.fontSize,fontFamily:t.fontFamily,fontStyle:t.fontStyle,fontWeight:t.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,children:c})}function dee(n,e,t,r){if((n==="start-legacy"||n==="end-legacy")&&t.length!==0){const s=Se.From(t[0].box);for(const{box:o}of t)s.union(o);if(n==="start-legacy")return(r-2*e-s.width)/2;if(n==="end-legacy")return-(r-2*e-s.width)/2}}function hee(n){return n==="start-legacy"||n==="middle-legacy"||n==="end-legacy"}function ym({fontSize:n,font:e,align:t,verticalAlign:r,text:s,labelColor:o,bounds:i,padding:a=16,stroke:c=!0}){const d=te(),h=ks(),f={fontSize:n,fontFamily:CA[e],textAlign:t,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Yn.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:o,stroke:void 0,strokeWidth:void 0},g=d.textMeasure.measureTextSpans(s,f),y=dee(t,a,g,i.width);y&&(f.offsetX=y),f.offsetX+=i.x,f.offsetY+=i.y;const S=M0(d,g,f);let v=null;return c&&(f.fill=h.background,f.stroke=h.background,f.strokeWidth=2,v=M0(d,g,f)),p.jsxs(p.Fragment,{children:[v,S]})}const pee=_.forwardRef(function({isEditing:e,text:t,handleFocus:r,handleChange:s,handleKeyDown:o,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:c},d){return p.jsx("textarea",{ref:d,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:t,onFocus:r,onChange:s,onKeyDown:o,onBlur:i,onTouchEnd:ln,onContextMenu:e?ln:void 0,onPointerDown:a,onDoubleClick:c,onDragStart:Je})});function fee(n,e,t){const r=te(),s=_.useRef(null),o=se("isEditing",()=>r.getEditingShapeId()===n,[r]),i=se("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);_.useEffect(()=>{function h(f){var g;f.shapeId===n&&((g=s.current)==null||g.select())}return r.on("select-all-text",h),()=>{r.off("select-all-text",h)}},[r,n,o]),_.useEffect(()=>{var h,f,g,y;o&&(document.activeElement!==s.current&&((h=s.current)==null||h.focus()),r.getInstanceState().isCoarsePointer&&((f=s.current)==null||f.select()),Et.isSafari&&((g=s.current)==null||g.blur(),(y=s.current)==null||y.focus()))},[r,o]);const a=_.useCallback(h=>{if(r.getEditingShapeId()===n)switch(h.key){case"Enter":{(h.ctrlKey||h.metaKey)&&r.complete();break}}},[r,n]),c=_.useCallback(h=>{if(r.getEditingShapeId()!==n)return;let f=Dc.normalizeText(h.currentTarget.value);const g=f.replace(/\t/g,bc);if(g!==f){const y=h.currentTarget.selectionStart;h.currentTarget.value=g,h.currentTarget.selectionStart=y+(g.length-f.length),h.currentTarget.selectionEnd=y+(g.length-f.length),f=g}r.updateShape({id:n,type:e,props:{text:f}})},[r,n,e]),d=_.useCallback(h=>{r.dispatch({...Zr(h),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(n)}),ln(h)},[r,n]);return{rInput:s,handleFocus:vd,handleBlur:vd,handleKeyDown:a,handleChange:c,handleInputPointerDown:d,handleDoubleClick:ln,isEmpty:t.trim().length===0,isEditing:o,isEditingAnything:i}}const Sm=at.memo(function({shapeId:e,type:t,text:r,labelColor:s,font:o,fontSize:i,lineHeight:a,align:c,verticalAlign:d,wrap:h,isSelected:f,padding:g=0,onKeyDown:y,classNamePrefix:S,style:v,textWidth:w,textHeight:b}){const{rInput:P,isEmpty:k,isEditing:E,isEditingAnything:M,...A}=fee(e,t,r),[R,D]=_.useState(r);_.useEffect(()=>{E||D(r)},[E,r]);const V=Dc.normalizeTextForDom(r),L=V.length>0,U=hee(c);if(!E&&!L)return null;const K=S||"tl-text";return p.jsx("div",{className:`${K}-label tl-text-wrapper`,"data-font":o,"data-align":c,"data-hastext":!k,"data-isediting":E,"data-iseditinganything":M,"data-textwrap":!!h,"data-isselected":f,style:{justifyContent:c==="middle"||U?"center":c,alignItems:d==="middle"?"center":d,padding:g,...v},children:p.jsxs("div",{className:`${K}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(w||0),color:s,width:w?Math.ceil(w):void 0,height:b?Math.ceil(b):void 0},children:[p.jsx("div",{className:`${K} tl-text tl-text-content`,dir:"auto",children:V.split(`
|
|
363
|
+
`).map((F,$)=>p.jsx("div",{dir:"auto",children:F},$))}),(M||f)&&p.jsx(pee,{ref:P,text:r,isEditing:E,...A,handleKeyDown:y??A.handleKeyDown},R)]})})}),gee=new Ao;function mee(n){return gee.get(n,()=>n.store.createComputedCache("arrowLabelSize",e=>{const t=Io(n,e);let r=0,s=0;const o=t.isStraight?new hi({start:C.From(t.start.point),end:C.From(t.end.point)}):new xc({center:C.Cast(t.handleArc.center),start:C.Cast(t.start.point),end:C.Cast(t.end.point),sweepFlag:t.bodyArc.sweepFlag,largeArcFlag:t.bodyArc.largeArcFlag});if(e.props.text.trim()){const i=o.bounds,a=A0(e),{w:c,h:d}=n.textMeasure.measureText(e.props.text,{...Yn,fontFamily:wi[e.props.font],fontSize:a,maxWidth:null});r=c,s=d;let h=!1;if(i.width>i.height?(r=Math.max(Math.min(c,64),Math.min(i.width-64,c)),h=!0):r>16*a&&(r=16*a,h=!0),h){const{w:f,h:g}=n.textMeasure.measureText(e.props.text,{...Yn,fontFamily:wi[e.props.font],fontSize:a,maxWidth:r});r=f,s=g}}return new C(r,s).addScalar(X1*2*e.props.scale)}))}function nP(n,e){return e.props.text.trim()===""?new C(0,0).addScalar(X1*2*e.props.scale):mee(n).get(e.id)??new C(0,0)}function nF(n){const e=qn[n.props.size];return(iJ+(e-qn.s)*2+(e===qn.xl?20:0))*n.props.scale}function yee(n,e,t){const r=nP(n,e),s=nF(e),o=C.Nudge(t.start.point,t.end.point,s),i=C.Nudge(t.end.point,t.start.point,s),a=Kb(o,i,Se.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[c,d]=a;C.Dist2(c,o)>C.Dist2(d,o)&&([d,c]=a);const h=o.add(C.Sub(t.middle,c)),f=i.add(C.Sub(t.middle,d)),g=C.Dist(t.start.point,h)/t.length,y=C.Dist(t.start.point,f)/t.length;return{start:g,end:y}}function See(n,e,t){const r=nP(n,e),s=nF(e),o=Math.sign(e.props.bend),i=s/t.handleArc.radius*o,a=C.Angle(t.bodyArc.center,t.start.point)-i,c=C.Angle(t.bodyArc.center,t.end.point)+i,d=sl(t.bodyArc.center,t.bodyArc.radius,a),h=sl(t.bodyArc.center,t.bodyArc.radius,c),f=[],g=yk(t.bodyArc.center,t.bodyArc.radius,a,c,o,Se.FromCenter(d,r).corners);f.push(new rn({points:Se.FromCenter(d,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const y=yk(t.bodyArc.center,t.bodyArc.radius,a,c,o,Se.FromCenter(h,r).corners);f.push(new rn({points:Se.FromCenter(h,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const R of[...g??[],...y??[],d,h])f.push(new r1({x:R.x-3,y:R.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const S=(g&&Sk(t.start.point,g))??t.middle,v=(y&&Sk(t.end.point,y))??t.middle,w=C.Angle(t.bodyArc.center,t.start.point),b=C.Angle(t.bodyArc.center,t.end.point),P=C.Angle(t.bodyArc.center,S),k=C.Angle(t.bodyArc.center,v);if(na(w,P,o)>na(w,k,o))return{start:.5,end:.5,dbg:f};const E=na(w,b,o),M=na(w,P,o)/E,A=na(w,k,o)/E;return{start:M,end:A,dbg:f}}function gf(n,e){let t;const r=[],s=Io(n,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=yee(n,e,s),c=mk(n,e,a,o);t=C.Lrp(s.start.point,s.end.point,c)}else{const a=See(n,e,s);a.dbg&&r.push(...a.dbg);const c=mk(n,e,a,o),d=vee(C.Angle(s.bodyArc.center,s.start.point),C.Angle(s.bodyArc.center,s.end.point),Math.sign(e.props.bend),c);t=sl(s.bodyArc.center,s.bodyArc.radius,d)}const i=nP(n,e);return{box:Se.FromCenter(t,i),debugGeom:r}}function mk(n,e,t,r){const{hasEndArrowhead:s,hasEndBinding:o,hasStartBinding:i,hasStartArrowhead:a}=r,c=iF(n,e);let d=Cn(e.props.labelPosition,a||i?t.start:0,s||o?t.end:1);const h=Math.min(.02,500/c*.02);return d=d>=.5-h&&d<=.5+h?.5:d,d}function yk(n,e,t,r,s,o){const i=Zw(n,e,o),a=na(t,r,s);return i==null?void 0:i.filter(c=>{const d=na(t,C.Angle(n,c),s);return d>=0&&d<=a})}function Sk(n,e){let t=null,r=-1/0;for(const s of e){const o=C.Dist2(n,s);o>r&&(t=s,r=o)}return t}function vee(n,e,t,r){const s=na(n,e,t);return n+s*r*t*-1}function A0(n){return oJ[n.props.size]*n.props.scale}function xee(n,e,t){const r=e==="end"?n.end.point:n.start.point,s=e==="end"?n.start.point:n.end.point,o=n.isStraight?C.Dist(s,r):Math.abs(n.bodyArc.length),i=Math.max(Math.min(o/5,t*3),t);let a;if(n.isStraight)a=C.Nudge(r,s,i);else{const c=YU(r,i,n.handleArc.center,n.handleArc.radius);a=e==="end"?n.handleArc.sweepFlag?c[0]:c[1]:n.handleArc.sweepFlag?c[1]:c[0]}return C.IsNaN(a)&&(a=n.start.point),{point:r,int:a}}function wee({point:n,int:e}){const t=C.RotWith(e,n,pt/6),r=C.RotWith(e,n,-pt/6);return`M ${t.x} ${t.y} L ${n.x} ${n.y} L ${r.x} ${r.y}`}function bee({point:n,int:e}){const t=C.RotWith(e,n,pt/6),r=C.RotWith(e,n,-pt/6);return`M ${t.x} ${t.y} L ${r.x} ${r.y} L ${n.x} ${n.y} Z`}function Pee({point:n,int:e}){const t=C.Sub(e,n).div(2),r=C.Add(n,C.Rot(t,Rt)),s=C.Sub(n,C.Rot(t,Rt));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${s.x} ${s.y} Z`}function Cee({point:n,int:e}){const t=C.Lrp(n,e,.45),r=C.Dist(t,n);return`M ${t.x-r},${t.y}
|
|
364
|
+
a ${r},${r} 0 1,0 ${r*2},0
|
|
365
|
+
a ${r},${r} 0 1,0 -${r*2},0 `}function _ee({point:n,int:e}){const t=C.Lrp(n,e,.75),r=C.RotWith(t,n,pt/4),s=C.RotWith(t,n,-pt/4),o=C.Lrp(r,s,.5);return o.add(C.Sub(o,n)),`M ${o.x} ${o.y} L ${s.x} ${s.y} ${n.x} ${n.y} L ${r.x} ${r.y} Z`}function Iee({int:n,point:e}){const t=C.Lrp(e,n,.85),r=C.Sub(t,e).div(2),s=C.Add(e,C.Rot(r,Rt)),o=C.Sub(e,C.Rot(r,Rt)),i=C.Add(t,C.Rot(r,Rt)),a=C.Sub(t,C.Rot(r,Rt));return`M ${s.x} ${s.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${o.x} ${o.y} Z`}function Eee({int:n,point:e}){const t=C.Sub(n,e).div(2),r=C.Add(e,C.Rot(t,Rt)),s=C.Sub(e,C.Rot(t,Rt));return`M ${r.x} ${r.y} L ${s.x} ${s.y}`}function hg(n,e,t){const r=e==="end"?n.end.arrowhead:n.start.arrowhead;if(r==="none")return;const s=xee(n,e,t);if(s){switch(r){case"bar":return Eee(s);case"square":return Iee(s);case"diamond":return _ee(s);case"dot":return Cee(s);case"inverted":return Pee(s);case"arrow":return wee(s);case"triangle":return bee(s)}return""}}function Tee(n){const{start:e,end:t,handleArc:{radius:r,largeArcFlag:s,sweepFlag:o}}=n;return`M${e.handle.x},${e.handle.y} A${r} ${r} 0 ${s} ${o} ${t.handle.x},${t.handle.y}`}function rF(n){const{start:e,end:t,bodyArc:{radius:r,largeArcFlag:s,sweepFlag:o}}=n;return`M${e.point.x},${e.point.y} A${r} ${r} 0 ${s} ${o} ${t.point.x},${t.point.y}`}function sF(n,e){return`M${n.x},${n.y}L${e.x},${e.y}`}function kee(n){return sF(n.start.handle,n.end.handle)}function oF(n){return sF(n.start.point,n.end.point)}class mf extends Xs{constructor(){super(...arguments);j(this,"_resizeInitialBindings",new Ao)}canEdit(){return!0}canBind({toShapeType:t}){return t!=="arrow"}canSnap(){return!1}hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsBg(){return!0}hideSelectionBoundsFg(){return!0}canBeLaidOut(t){const r=Rr(this.editor,t);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(t){const r=Io(this.editor,t),s=[],o=r.isStraight?new hi({start:C.From(r.start.point),end:C.From(r.end.point)}):new xc({center:C.Cast(r.handleArc.center),start:C.Cast(r.start.point),end:C.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(t.props.text.trim()){const a=gf(this.editor,t);s.push(...a.debugGeom),i=new Do({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Is({children:[...i?[o,i]:[o],...s]})}getHandles(t){const r=Io(this.editor,t);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(t){return t.props.text}onHandleDrag(t,{handle:r,isPrecise:s}){const o=r.id,i=Rr(this.editor,t);if(o==="middle"){const{start:A,end:R}=wc(this.editor,t,i),D=C.Sub(R,A),V=C.Per(D),L=C.Med(R,A),U=C.Sub(L,V),K=C.Add(L,V),F=C.NearestPointOnLineSegment(U,K,r,!1);let $=C.Dist(F,L);return C.Clockwise(F,R,L)&&($*=-1),{id:t.id,type:t.type,props:{bend:$}}}const a={id:t.id,type:"arrow",props:{}},c=i[o],h=i[o==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return df(this.editor,t,o),a.props[o]={x:r.x,y:r.y},a;const f=this.editor.getShapePageTransform(t.id).applyToPoint(r),g=this.editor.getShapeAtPoint(f,{hitInside:!0,hitFrameInside:!0,margin:0,filter:A=>!A.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:A,binding:"arrow"})});if(!g){df(this.editor,t,o);const A=Zs(new C(r.x,r.y),this.editor);return a.props[o]={x:A.x,y:A.y},a}const y=this.editor.getShapeGeometry(g),S=Se.ZeroFix(y.bounds),w=this.editor.getShapePageTransform(a.id).applyToPoint(r),b=this.editor.getPointInShapeSpace(g,w);let P=s;P||(!c||c&&g.id!==c.toId)&&(P=this.editor.inputs.pointerVelocity.len()<.5),s||(y.isClosed||(P=!0),h&&g.id===h.toId&&h.props.isPrecise&&(P=!0));const k={x:(b.x-S.minX)/S.width,y:(b.y-S.minY)/S.height};P&&C.Dist(b,S.center)<Math.max(4,Math.min(Math.min(S.width,S.height)*.15,16))/this.editor.getZoomLevel()&&(k.x=.5,k.y=.5);const E={terminal:o,normalizedAnchor:k,isPrecise:P,isExact:this.editor.inputs.altKey};Vu(this.editor,t,g.id,E),this.editor.setHintingShapes([g.id]);const M=Rr(this.editor,t);return M.start&&M.end&&M.start.toId===M.end.toId&&C.Equals(M.start.props.normalizedAnchor,M.end.props.normalizedAnchor)&&Vu(this.editor,t,M.end.toId,{...M.end.props,normalizedAnchor:{x:M.end.props.normalizedAnchor.x+.05,y:M.end.props.normalizedAnchor.y}}),a}onTranslateStart(t){const r=Rr(this.editor,t),s=wc(this.editor,t,r),o=this.editor.getShapePageTransform(t.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)))){xk.set(t,{pagePosition:o.applyToPoint(t),terminalBindings:Nd(s,(a,c)=>{const d=r[a];return d?{binding:d,shapePosition:c,pagePosition:o.applyToPoint(c)}:null})}),r.start&&(ug({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&ug({editor:this.editor,arrow:t,terminal:"end",useHandle:!0});for(const a of["start","end"]){const c=r[a];c&&this.editor.updateBinding({...c,props:{...c.props,isPrecise:!0}})}}}onTranslate(t,r){const s=xk.get(t);if(!s)return;const o=this.editor.getShapePageTransform(r.id),i=C.Sub(o.applyToPoint(r),s.pagePosition);for(const a of Object.values(s.terminalBindings)){if(!a)continue;const c=C.Add(a.pagePosition,C.Mul(i,.5)),d=this.editor.getShapeAtPoint(c,{hitInside:!0,hitFrameInside:!0,margin:0,filter:h=>!h.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:h,binding:"arrow"})});if((d==null?void 0:d.id)===a.binding.toId){const h=Se.ZeroFix(this.editor.getShapeGeometry(d).bounds),f=this.editor.getPointInShapeSpace(d,c),g={x:(f.x-h.minX)/h.width,y:(f.y-h.minY)/h.height};Vu(this.editor,r,d.id,{...a.binding.props,normalizedAnchor:g,isPrecise:!0})}else df(this.editor,r,a.binding.props.terminal)}}onResize(t,r){const{scaleX:s,scaleY:o}=r,i=this._resizeInitialBindings.get(t,()=>Rr(this.editor,t)),a=wc(this.editor,t,i),{start:c,end:d}=Nt(t.props);let{bend:h}=t.props;i.start||(c.x=a.start.x*s,c.y=a.start.y*o),i.end||(d.x=a.end.x*s,d.y=a.end.y*o);const f=Math.abs(s),g=Math.abs(o),y=i!=null&&i.start?C.From(i.start.props.normalizedAnchor):null,S=i!=null&&i.end?C.From(i.end.props.normalizedAnchor):null;return s<0&&o>=0?(h!==0&&(h*=-1,h*=Math.max(f,g)),y&&(y.x=1-y.x),S&&(S.x=1-S.x)):s>=0&&o<0?(h!==0&&(h*=-1,h*=Math.max(f,g)),y&&(y.y=1-y.y),S&&(S.y=1-S.y)):s>=0&&o>=0?h!==0&&(h*=Math.max(f,g)):s<0&&o<0&&(h!==0&&(h*=Math.max(f,g)),y&&(y.x=1-y.x,y.y=1-y.y),S&&(S.x=1-S.x,S.y=1-S.y)),i.start&&y&&Vu(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:y.toJson()}),i.end&&S&&Vu(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:S.toJson()}),{props:{start:c,end:d,bend:h}}}onDoubleClickHandle(t,r){switch(r.id){case"start":return{id:t.id,type:t.type,props:{...t.props,arrowheadStart:t.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:t.id,type:t.type,props:{...t.props,arrowheadEnd:t.props.arrowheadEnd==="none"?"arrow":"none"}}}}component(t){const r=ks(),s=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),i=Io(this.editor,t);if(!(i!=null&&i.isValid))return null;const a=gf(this.editor,t),c=t.id===this.editor.getOnlySelectedShapeId(),h=this.editor.getEditingShapeId()===t.id||t.props.text;return p.jsxs(p.Fragment,{children:[p.jsx(ha,{style:{minWidth:50,minHeight:50},children:p.jsx(vk,{shape:t,shouldDisplayHandles:o&&(s==null?void 0:s.id)===t.id})}),h&&p.jsx(Sm,{shapeId:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:A0(t),lineHeight:Yn.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w-X1*2*t.props.scale,isSelected:c,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(t){const r=Wg(t.id),s=Ys(t.id+"_clip"),o=Io(this.editor,t);if(!o)return null;const{start:i,end:a}=wc(this.editor,t,o==null?void 0:o.bindings),c=this.editor.getShapeGeometry(t),d=c.bounds,h=t.props.text.trim()?c.children[1]:null;if(C.Equals(i,a))return null;const f=qn[t.props.size]*t.props.scale,g=o.start.arrowhead&&hg(o,"start",f),y=o.end.arrowhead&&hg(o,"end",f),S=o.isStraight?oF(o):rF(o),v=g&&o.start.arrowhead!=="arrow"||y&&o.end.arrowhead!=="arrow"||!!h;if(r&&h)return p.jsx("rect",{x:ee(h.x),y:ee(h.y),width:h.w,height:h.h,rx:3.5*t.props.scale,ry:3.5*t.props.scale});const w=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),b=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return p.jsxs("g",{children:[v&&p.jsx("defs",{children:p.jsx(aF,{hasText:t.props.text.trim().length>0,bounds:d,labelBounds:h?h.getBounds():new Se(0,0,0,0),as:w&&g?g:"",ae:b&&y?y:""})}),p.jsxs("g",{style:{clipPath:v?`url(#${s})`:void 0,WebkitClipPath:v?`url(#${s})`:void 0},children:[v&&p.jsx("rect",{x:d.minX-100,y:d.minY-100,width:d.width+200,height:d.height+200,opacity:0}),p.jsx("path",{d:S})]}),g&&p.jsx("path",{d:g}),y&&p.jsx("path",{d:y}),h&&p.jsx("rect",{x:ee(h.x),y:ee(h.y),width:h.w,height:h.h,rx:3.5,ry:3.5})]})}onEditEnd(t){const{id:r,type:s,props:{text:o}}=t;o.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])}toSvg(t,r){r.addExportDef(Q1(t.props.fill)),t.props.text&&r.addExportDef(gm(t.props.font));const s=_i(r),o=1/t.props.scale;return p.jsxs("g",{transform:`scale(${o})`,children:[p.jsx(vk,{shape:t,shouldDisplayHandles:!1}),p.jsx(ym,{fontSize:A0(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:s[t.props.labelColor].solid,bounds:gf(this.editor,t).box.clone().expandBy(-4.25*t.props.scale),padding:0})]})}getCanvasSvgDefs(){return[J1(),{key:"arrow:dot",component:Mee},{key:"arrow:cross",component:Aee}]}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:ot(t.props.scale,r.props.scale,s),start:{x:ot(t.props.start.x,r.props.start.x,s),y:ot(t.props.start.y,r.props.start.y,s)},end:{x:ot(t.props.end.x,r.props.end.x,s),y:ot(t.props.end.y,r.props.end.y,s)},bend:ot(t.props.bend,r.props.bend,s),labelPosition:ot(t.props.labelPosition,r.props.labelPosition,s)}}}j(mf,"type","arrow"),j(mf,"props",IA),j(mf,"migrations",EA);function iF(n,e){const t=Io(n,e);return t.isStraight?C.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const vk=jn(function({shape:e,shouldDisplayHandles:t}){const r=te(),s=ks(),o=Io(r,e),i=Se.ZeroFix(r.getShapeGeometry(e).bounds),a=Rr(r,e),c=se("force solid",()=>r.getZoomLevel()<.2,[r]),d=Ys(e.id+"_clip"),h=Ys("arrowhead-dot"),f=Ys("arrowhead-cross");if(!(o!=null&&o.isValid))return null;const g=qn[e.props.size]*e.props.scale,y=o.start.arrowhead&&hg(o,"start",g),S=o.end.arrowhead&&hg(o,"end",g),v=o.isStraight?oF(o):rF(o);let w=null;if(t){const A=2/r.getZoomLevel(),{strokeDasharray:R,strokeDashoffset:D}=Ws(iF(r,e),A,{end:"skip",start:"skip",lengthRatio:2.5});w=a.start||a.end?p.jsx("path",{className:"tl-arrow-hint",d:o.isStraight?kee(o):Tee(o),strokeDasharray:R,strokeDashoffset:D,strokeWidth:A,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?`url(#${f})`:`url(#${h})`:"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?`url(#${f})`:`url(#${h})`:"",opacity:.16}):null}const{strokeDasharray:b,strokeDashoffset:P}=Ws(o.isStraight?o.length:Math.abs(o.bodyArc.length),g,{style:e.props.dash,forceSolid:c}),k=gf(r,e),E=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),M=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return p.jsxs(p.Fragment,{children:[p.jsx("defs",{children:p.jsx("clipPath",{id:d,children:p.jsx(aF,{hasText:e.props.text.trim().length>0,bounds:i,labelBounds:k.box,as:E&&y?y:"",ae:M&&S?S:""})})}),p.jsxs("g",{fill:"none",stroke:s[e.props.color].solid,strokeWidth:g,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[w,p.jsxs("g",{style:{clipPath:`url(#${d})`,WebkitClipPath:`url(#${d})`},children:[p.jsx("rect",{x:ee(i.minX-100),y:ee(i.minY-100),width:ee(i.width+200),height:ee(i.height+200),opacity:0}),p.jsx("path",{d:v,strokeDasharray:b,strokeDashoffset:P})]}),y&&E&&e.props.fill!=="none"&&p.jsx(Un,{theme:s,d:y,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),S&&M&&e.props.fill!=="none"&&p.jsx(Un,{theme:s,d:S,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),y&&p.jsx("path",{d:y}),S&&p.jsx("path",{d:S})]})]})});function aF({hasText:n,bounds:e,labelBounds:t,as:r,ae:s}){const o=`M${ee(e.minX-100)},${ee(e.minY-100)} h${e.width+200} v${e.height+200} h-${e.width+200} Z`,i=`M${ee(t.minX)},${ee(t.minY)} v${t.height} h${t.width} v-${t.height} Z`;return p.jsx("path",{d:`${o}${n?i:""}${r}${s}`})}const xk=new WeakMap;function Mee(){const n=Ys("arrowhead-dot");return p.jsx("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:p.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function Aee(){const n=Ys("arrowhead-cross");return p.jsxs("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[p.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),p.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const wk="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 Fc({url:n}){const e=te(),t=se("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return p.jsx("a",{className:Le("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t}),href:n,target:"_blank",rel:"noopener noreferrer",onPointerDown:ln,onPointerUp:ln,title:n,draggable:!1,children:p.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${wk}") center 100% / 100% no-repeat`,WebkitMask:`url("${wk}") center 100% / 100% no-repeat`}})})}const bk="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",jee=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function pg(n){return jee.map(t=>{const{offsetX:r,offsetY:s,blur:o,spread:i,color:a}=t,c=new C(r,s),{x:d,y:h}=c.rot(-n);return`${d}px ${h}px ${o}px ${i}px ${a}`}).join(", ")}const Ree=300,lF=320,Oee=46,Dee=101;class yf extends Qc{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:Ree,h:lF,assetId:null}}component(e){return p.jsx(Lee,{shape:e,util:this})}indicator(e){return p.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h),rx:"6",ry:"6"})}onBeforeCreate(e){return Pk(this.editor,e)}onBeforeUpdate(e,t){if(e.props.url!==t.props.url)if(ns.isValid(t.props.url))Nee(this.editor,t);else return{...t,props:{...t.props,url:e.props.url}};if(e.props.assetId!==t.props.assetId)return Pk(this.editor,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:ot(e.props.w,t.props.w,r),h:ot(e.props.h,t.props.h,r)}}}j(yf,"type","bookmark"),j(yf,"props",RA),j(yf,"migrations",OA);function Lee({shape:n,util:e}){const t=n.props.assetId?e.editor.getAsset(n.props.assetId):null,r=!!Xd()&&Et.isSafari,s=e.editor.getShapePageTransform(n).rotation(),o=Fee(n),[i,a]=_.useState(!0),c=()=>a(!1);return p.jsx(ca,{children:p.jsxs("div",{className:Le("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:pg(s),maxHeight:n.props.h},children:[(!t||t.props.image)&&p.jsxs("div",{className:"tl-bookmark__image_container",children:[t?p.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:t==null?void 0:t.props.image,alt:(t==null?void 0:t.props.title)||""}):p.jsx("div",{className:"tl-bookmark__placeholder"}),(t==null?void 0:t.props.image)&&p.jsx(Fc,{url:n.props.url})]}),p.jsxs("div",{className:"tl-bookmark__copy_container",children:[t!=null&&t.props.title?p.jsx("h2",{className:"tl-bookmark__heading",children:hJ(t.props.title)}):null,t!=null&&t.props.description&&(t!=null&&t.props.image)?p.jsx("p",{className:"tl-bookmark__description",children:t.props.description}):null,p.jsxs("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:ln,onPointerUp:ln,onClick:ln,children:[i&&(t!=null&&t.props.favicon)?p.jsx("img",{className:"tl-bookmark__favicon",src:t==null?void 0:t.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:c,alt:`favicon of ${o}`}):p.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${bk}") center 100% / 100% no-repeat`,WebkitMask:`url("${bk}") center 100% / 100% no-repeat`}}),p.jsx("span",{children:o})]})]})]})})}function Pk(n,e){const t=e.props.assetId?n.getAsset(e.props.assetId):null;let r=lF;return t&&(t.props.image||(t.props.title?r=Dee:r=Oee)),{...e,props:{...e.props,h:r}}}const Fee=n=>{try{return new URL(n.props.url).hostname.replace(/^www\./,"")}catch{return n.props.url}};function Nee(n,e){const{url:t}=e.props,r=da.createId(Z0(t));n.getAsset(r)?e.props.assetId!==r&&n.updateShapes([{id:e.id,type:e.type,props:{assetId:r}}]):(n.updateShapes([{id:e.id,type:e.type,props:{assetId:null}}]),$ee(n,e))}const $ee=Y0(async(n,e)=>{if(n.isDisposed)return;const{url:t}=e.props,r=await n.getAssetForExternalContent({type:"url",url:t});r&&n.run(()=>{n.createAssets([r]),n.updateShapes([{id:e.id,type:e.type,props:{assetId:r.id}}])})},500);function zee(n){if(typeof n!="string")throw new TypeError("Expected a string");return n.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Bee(n,e){const t=Ge(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(cF(s.hostnames,r)){const o=s.fromEmbedUrl(e);if(o)return{definition:s,url:o,embedUrl:e}}}const Uee=n=>n.split("*").map(e=>zee(e)).join(".+"),cF=(n,e)=>!!n.find(t=>{const r=new RegExp(Uee(t));return e.match(r)});function Hee(n,e){const t=Ge(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(cF(s.hostnames,r)){const o=s.toEmbedUrl(e);if(o)return{definition:s,embedUrl:o,url:e}}}function Kee(n,e){try{return Hee(n,e)??Bee(n,e)}catch{return}}const Wee=n=>Object.entries(n).filter(([e,t])=>t).map(([e])=>e).join(" "),ci=class ci extends Qc{static setEmbedDefinitions(e){ci.embedDefinitions=e}getEmbedDefinitions(){return ci.embedDefinitions}getEmbedDefinition(e){return Kee(ci.embedDefinitions,e)}getText(e){return e.props.url}hideSelectionBoundsFg(e){return!this.canResize(e)}canEdit(){return!0}canResize(e){var t,r;return!!((r=(t=this.getEmbedDefinition(e.props.url))==null?void 0:t.definition)!=null&&r.doesResize)}canEditInReadOnly(){return!0}getDefaultProps(){return{w:300,h:300,url:""}}isAspectRatioLocked(e){const t=this.getEmbedDefinition(e.props.url);return(t==null?void 0:t.definition.isAspectRatioLocked)??!1}onResize(e,t){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 Kg(e,t,{minWidth:o,minHeight:i})}component(e){const t=Xd(),{w:r,h:s,url:o}=e.props,i=Wg(e.id),a=this.getEmbedDefinition(o),c=se("is hovering",()=>{const{editingShapeId:y,hoveredShapeId:S}=this.editor.getCurrentPageState();if(y&&S!==y){const v=this.editor.getShape(y);if(v&&this.editor.isShapeOfType(v,"embed"))return!0}return!1},[]),d=this.editor.getShapePageTransform(e).rotation();if(t)return p.jsx(ca,{className:"tl-embed-container",id:e.id,children:p.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:pg(d),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 h=i||c;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 y=a.url.split("/").pop();if(!y)throw Error("No gist id!");return p.jsx(ca,{className:"tl-embed-container",id:e.id,children:p.jsx(Gee,{id:y,width:ee(r),height:ee(s),isInteractive:h,pageRotation:d})})}const g=Wee({...nZ,...(a==null?void 0:a.definition.overridePermissions)??{}});return p.jsx(ca,{className:"tl-embed-container",id:e.id,children:a!=null&&a.definition?p.jsx("iframe",{className:"tl-embed",sandbox:g,src:a.embedUrl,width:ee(r),height:ee(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:h?"auto":"none",zIndex:h?"":"-1",boxShadow:pg(d),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(e){const t=this.getEmbedDefinition(e.props.url);return p.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h),rx:(t==null?void 0:t.definition.overrideOutlineRadius)??8,ry:(t==null?void 0:t.definition.overrideOutlineRadius)??8})}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:ot(e.props.w,t.props.w,r),h:ot(e.props.h,t.props.h,r)}}};j(ci,"type","embed"),j(ci,"props",NA),j(ci,"migrations",$A),j(ci,"embedDefinitions",$1);let fg=ci;function Gee({id:n,isInteractive:e,width:t,height:r,style:s,pageRotation:o}){if(!n.match(/^[0-9a-f]+$/))throw Error("No gist id!");return p.jsx("iframe",{className:"tl-embed",draggable:!1,width:ee(t),height:ee(r),frameBorder:"0",scrolling:"no",referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:e?"all":"none",zIndex:e?"":"-1",boxShadow:pg(o)},srcDoc:`
|
|
366
|
+
<html>
|
|
367
|
+
<head>
|
|
368
|
+
<base target="_blank">
|
|
369
|
+
</head>
|
|
370
|
+
<body>
|
|
371
|
+
<script src=${`https://gist.github.com/${n}.js`}><\/script>
|
|
372
|
+
<style type="text/css">
|
|
373
|
+
* { margin: 0px; }
|
|
374
|
+
table { height: 100%; background-color: red; }
|
|
375
|
+
.gist { background-color: none; height: 100%; }
|
|
376
|
+
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
377
|
+
</style>
|
|
378
|
+
</body>
|
|
379
|
+
</html>`})}function j0(n,e){const s=((tl(n.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(s)}const Ck=new WeakMap;function _k(n,e,t){const r=rP(e.props.name,"Frame")+"";let s=Ck.get(e.props);if(!s){const o=n.textMeasure.measureTextSpans(r,t),i=o[0],a=In(o);s=a.box.w+a.box.x-i.box.x,Ck.set(e.props,s)}return new Se(0,-t.height,s,t.height)}function Ik(n,e){return{fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:n.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",fill:e,offsetY:-34,offsetX:2}}function uF(n,e,t){const r=t?"":"px",s=t?"":"deg";let o;switch(e){case 0:o="";break;case 3:o=`translate(${ee(n.props.w)}${r}, 0${r}) rotate(90${s})`;break;case 2:o=`translate(${ee(n.props.w)}${r}, ${ee(n.props.h)}${r}) rotate(180${s})`;break;case 1:o=`translate(0${r}, ${ee(n.props.h)}${r}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return o}const Vee=_.forwardRef(({id:n,name:e,isEditing:t},r)=>{const s=te(),o=_.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(ln(c),c.currentTarget.blur(),s.setEditingShape(null))},[s]),i=_.useCallback(c=>{const d=s.getShape(n);if(!d)return;const h=d.props.name,f=c.currentTarget.value.trim();h!==f&&s.updateShapes([{id:n,type:"frame",props:{name:f}}])},[n,s]),a=_.useCallback(c=>{const d=s.getShape(n);if(!d)return;const h=d.props.name,f=c.currentTarget.value;h!==f&&s.updateShapes([{id:n,type:"frame",props:{name:f}}])},[n,s]);return p.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[p.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:t?void 0:"none"},value:e,autoFocus:!0,onKeyDown:o,onBlur:i,onChange:a}),rP(e,"Frame")+""]})}),qee=_.memo(function({id:e,name:t,width:r,height:s}){const o=te(),{side:i,translation:a}=se("shape rotation",()=>{const h=o.getShape(e);if(!h)return{side:0,translation:"translate(0, 0)"};const f=j0(o,h);return{side:f,translation:uF(h,f,!1)}},[o,e]),c=_.useRef(null),d=Wg(e);return _.useEffect(()=>{const h=c.current;h&&d&&(h.focus(),h.select())},[c,d]),p.jsx("div",{className:"tl-frame-heading",style:{overflow:d?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(i===0||i===2?r:s)}px + var(--space-5))`,bottom:"100%",transform:`${a} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},children:p.jsx("div",{className:"tl-frame-heading-hit-area",children:p.jsx(Vee,{ref:c,id:e,name:t,isEditing:d})})})});function rP(n,e){return n.match(/^\s*$/)?e:n}class Sf extends Qc{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){const{editor:t}=this,r=t.getZoomLevel(),s=Ik(e,"black"),o=_k(t,e,s),i=j0(t,e);let a,c,d,h;const{w:f,h:g}=o,y=Math.min(f,e.props.w*r),S=Math.min(g,e.props.h*r);switch(i){case 0:{a=-8/r,c=(-g-4)/r,d=(y+16)/r,h=g/r;break}case 1:{a=(-g-4)/r,h=(S+16)/r,c=e.props.h-h+8/r,d=g/r;break}case 2:{a=e.props.w-(y+8)/r,c=e.props.h+4/r,d=(S+16)/r,h=g/r;break}case 3:{a=e.props.w+4/r,h=(S+16)/r,c=-8/r,d=g/r;break}}return new Is({children:[new Do({width:e.props.w,height:e.props.h,isFilled:!1}),new Do({x:a,y:c,width:d,height:h,isFilled:!0,isLabel:!0})]})}getText(e){return e.props.name}component(e){const t=ks(),r=se("is creating this shape",()=>{const s=this.editor.getStateDescendant("select.resizing");if(!s||!s.getIsActive())return!1;const o=s==null?void 0:s.info;return o?o.isCreating&&this.editor.getOnlySelectedShapeId()===e.id:!1},[e.id]);return p.jsxs(p.Fragment,{children:[p.jsx(ha,{children:p.jsx("rect",{className:Le("tl-frame__body",{"tl-frame__creating":r}),width:e.props.w,height:e.props.h,fill:t.solid,stroke:t.text})}),r?null:p.jsx(qee,{id:e.id,name:e.props.name,width:e.props.w,height:e.props.h})]})}toSvg(e,t){const r=_i({isDarkMode:t.isDarkMode}),s=j0(this.editor,e),o=uF(e,s,!0),i=Ik(e,r.text),a=rP(e.props.name,"Frame")+"",c=_k(this.editor,e,i),d=this.editor.textMeasure.measureTextSpans(a,i),h=M0(this.editor,d,i);return p.jsxs(p.Fragment,{children:[p.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),p.jsxs("g",{transform:o,children:[p.jsx("rect",{x:c.x-8,y:c.y-4,width:c.width+20,height:c.height,fill:r.background,rx:4,ry:4}),h]})]})}indicator(e){return p.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h),className:"tl-frame-indicator"})}canReceiveNewChildrenOfType(e,t){return!e.isLocked}providesBackgroundForChildren(){return!0}canDropShapes(e,t){return!e.isLocked}onDragShapesOver(e,t){t.every(r=>r.parentId===e.id)||this.editor.reparentShapes(t,e.id)}onDragShapesOut(e,t){const r=this.editor.getShape(e.parentId);r&&this.editor.isShapeOfType(r,"group")?this.editor.reparentShapes(t,r.id):this.editor.reparentShapes(t,this.editor.getCurrentPageId())}onResize(e,t){return Kg(e,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:ot(e.props.w,t.props.w,r),h:ot(e.props.h,t.props.h,r)}}}j(Sf,"type","frame"),j(Sf,"props",zA),j(Sf,"migrations",BA);function Ek(n,e){return n>e?(pt*(e/2)+(n-e))*2:(pt*(n/2)+(e-n))*2}function dF(n,e){return sP(n,e).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function Yee(n,e,t,r){const s=n/4,o=e/4,i=eo(r),a=t*.75,c=P=>P.addXY(i()*a,i()*a),d=new C(n/2,e),h=new C(0,o*1.2),f=new C(n/2,o*.9),g=new C(n,o*1.2),y=c(new C(n/2,e)),S=c(new C(0,o*1.2)),v=c(new C(n/2,o*.9)),w=c(new C(n,o*1.2));return[new Kn({start:d,cp1:new C(s*1.5,o*3),cp2:new C(0,o*2.5),end:h}),new Kn({start:h,cp1:new C(0,-o*.32),cp2:new C(s*1.85,-o*.32),end:f}),new Kn({start:f,cp1:new C(s*2.15,-o*.32),cp2:new C(n,-o*.32),end:g}),new Kn({start:g,cp1:new C(n,o*2.5),cp2:new C(s*2.5,o*3),end:y}),new Kn({start:y,cp1:new C(s*1.5,o*3),cp2:new C(0,o*2.5),end:S}),new Kn({start:S,cp1:new C(0,-o*.32),cp2:new C(s*1.85,-o*.32),end:v}),new Kn({start:v,cp1:new C(s*2.15,-o*.32),cp2:new C(n,-o*.32),end:w}),new Kn({start:w,cp1:new C(n,o*2.5),cp2:new C(s*2.5,o*3),end:d})].map((P,k)=>P.getSvgPathData(k===0)).join(" ")+" Z"}function sP(n,e){const t=n/4,r=e/4;return[new Kn({start:new C(n/2,e),cp1:new C(t*1.5,r*3),cp2:new C(0,r*2.5),end:new C(0,r*1.2)}),new Kn({start:new C(0,r*1.2),cp1:new C(0,-r*.32),cp2:new C(t*1.85,-r*.32),end:new C(n/2,r*.9)}),new Kn({start:new C(n/2,r*.9),cp1:new C(t*2.15,-r*.32),cp2:new C(n,-r*.32),end:new C(n,r*1.2)}),new Kn({start:new C(n,r*1.2),cp1:new C(n,r*2.5),cp2:new C(t*2.5,r*3),end:new C(n/2,e)})]}function Xee(n){return{size:1+n,thinning:.25,end:{taper:n},start:{taper:n},streamline:0,smoothing:1,simulatePressure:!1}}function Zee(n,e,t,r){const s=eo(n),o=e/2,i=t/2,a=oA(o,i),c=[],d=St*s(),h=St+Rt/2+Math.abs(s())*Rt,f=Math.max(16,a/10);for(let g=0;g<f;g++){const y=g/(f-1),S=d+y*h,v=Math.cos(S),w=Math.sin(S);c.push(new C(o*v+e*.5+.05*s(),i*w+t/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?vn.easeInOutSine(y):vn.easeInExpo(y)))/2)))}return No(c,Xee(r))}function Qee(n,e,t,r){return gl(Zee(n,e,t,r))}function R0(n){let e="M";const t=n.length;let r,s,o;for(let i=0,a=t;i<a;i+=3)r=n[i],s=n[i+1],o=n[i+2],e+=`${ht(r)}L${ht(s)}Q${ht(o)}`;return e+=`${ht(n[0])}`,e}function O0(n,e,t,r,s){const o=[],i=eo(n);let a=e[0],c;const d=e.length;for(let h=0,f=d*s;h<f;h++){c=C.AddXY(e[(h+1)%d],i()*t,i()*t);const g=C.Sub(c,a),y=C.Len(g),S=C.Div(g,y).mul(Math.min(y/4,r));o.push(C.Add(a,S),C.Add(c,S.neg()),c),a=c}return o}function Jee(n,e,t){const r=Math.min(n,e)/2,s=Math.max(n,e)-r*2,i=(Math.PI*(r*2)+2*s)/t,a=n>e?[{type:"straight",start:new C(r,0),delta:new C(1,0)},{type:"arc",center:new C(n-r,r),startAngle:-pt/2},{type:"straight",start:new C(n-r,e),delta:new C(-1,0)},{type:"arc",center:new C(r,r),startAngle:pt/2}]:[{type:"straight",start:new C(n,r),delta:new C(0,1)},{type:"arc",center:new C(r,e-r),startAngle:0},{type:"straight",start:new C(0,e-r),delta:new C(0,-1)},{type:"arc",center:new C(r,r),startAngle:pt}];let c=0;const d=[];for(let h=0;h<t;h++){const f=a[0];f.type==="straight"?d.push(C.Add(f.start,C.Mul(f.delta,c))):d.push(sl(f.center,r,f.startAngle+c/r)),c+=i;let g=f.type==="straight"?s:pt*r;for(;c>g;)c-=g,a.push(a.shift()),g=a[0].type==="straight"?s:pt*r}return d}const ete={s:50,m:70,l:100,xl:130},tte=.2;function vm(n,e,t,r,s){const o=eo(t),i=Ek(n,e),a=Math.max(Math.ceil(i/ete[r]),6,Math.ceil(i/Math.min(n,e))),c=i/a*tte,d=Math.max(n-c*2,1),h=Math.max(e-c*2,1),g=Ek(d,h)/a,y=(n-d)/2,S=(e-h)/2,v=Jee(d,h,a).map(E=>E.addXY(y,S)),w=n<20?0:c*.3,b=e<20?0:c*.3,P=v.slice(0);for(let E=0;E<Math.floor(a/2);E++)P[E]=C.AddXY(P[E],o()*w*s,o()*b*s),P[a-E-1]=C.AddXY(P[a-E-1],o()*w*s,o()*b*s);const k=[];for(let E=0;E<P.length;E++){const M=E===P.length-1?0:E+1,A=P[E],R=P[M],D=v[E],V=v[M],L=C.Dist(D,V),U=g-L,F=C.Dist(A,R)/L,$=(Math.max(y,S)+U)*F,W=C.Lrp(D,V,.5).add(C.Sub(V,D).uni().per().mul($));W.x<0?W.x=0:W.x>n&&(W.x=n),W.y<0?W.y=0:W.y>e&&(W.y=e);const Y=Sb(A,R,W),Z=C.Dist(Y||C.Average([A,R]),A);k.push({leftPoint:A,rightPoint:R,arcPoint:W,center:Y,radius:Z})}return k}function nte(n,e,t,r,s){const o=[],i=vm(n,e,t,r,s);for(const{center:a,radius:c,leftPoint:d,rightPoint:h}of i)o.push(...M8(d,h,a,c,10));return o}function D0(n,e,t,r,s){const o=vm(n,e,t,r,s);let i=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:a,rightPoint:c,radius:d,center:h}of o){if(h===null){i+=` L${c.toFixed()}`;continue}const f=C.Clockwise(a,c,h)?"0":"1";i+=` A${ee(d)},${ee(d)} 0 ${f},1 ${c.toFixed()}`}return i+=" Z",i}const rte={s:.5,m:.7,l:.9,xl:1.6};function ste(n,e,t,r,s){const o=eo(t),i=rte[r]*s,a=vm(n,e,t,r,s),h=a.reduce((S,v)=>S+C.Dist2(v.leftPoint,v.rightPoint),0)/a.length>(i*15)**2?S=>C.AddXY(S,o()*i*2,o()*i*2):S=>S;let f=`M${a[0].leftPoint.toFixed()}`,g=h(a[0].leftPoint),y=`M${g.toFixed()}`;for(const{leftPoint:S,center:v,rightPoint:w,radius:b,arcPoint:P}of a){if(v===null){f+=` L${w.toFixed()}`;const D=h(w);y+=` L${D.toFixed()}`,g=D;continue}const k=C.Clockwise(S,w,v)?"0":"1";f+=` A${ee(b)},${ee(b)} 0 ${k},1 ${w.toFixed()}`;const E=h(w),M=h(P),A=Sb(g,E,M);if(!A){y+=` L${E.toFixed()}`,g=E;continue}const R=Math.abs(C.Dist(A,g));y+=` A${ee(R)},${ee(R)} 0 ${k},1 ${E.toFixed()}`,g=E}return f+y+" Z"}function L0(n,e){switch(n.geo){case"x-box":return ote(n.w,n.h,e,n.dash);case"check-box":return ite(n.w,n.h);default:return}}function ote(n,e,t,r){const s=r==="draw"?.62:0;if(r==="dashed")return[[new C(0,0),new C(n/2,e/2)],[new C(n,e),new C(n/2,e/2)],[new C(0,e),new C(n/2,e/2)],[new C(n,0),new C(n/2,e/2)]];const o=a=>Math.max(0,Math.min(n,a)),i=a=>Math.max(0,Math.min(e,a));return[[new C(o(t*s),i(t*s)),new C(o(n-t*s),i(e-t*s))],[new C(o(t*s),i(e-t*s)),new C(o(n-t*s),i(t*s))]]}function ite(n,e){const t=Math.min(n,e)*.82,r=(n-t)/2,s=(e-t)/2,o=a=>Math.max(0,Math.min(n,a)),i=a=>Math.max(0,Math.min(e,a));return[[new C(o(r+t*.25),i(s+t*.52)),new C(o(r+t*.45),i(s+t*.82))],[new C(o(r+t*.45),i(s+t*.82)),new C(o(r+t*.82),i(s+t*.22))]]}function Tk({shape:n,shouldScale:e,forceSolid:t}){const r=e?n.props.scale:1,s=te(),o=ks(),{id:i,props:a}=n,{w:c,color:d,fill:h,dash:f,growY:g,size:y,scale:S}=a,v=qn[y]*r,w=a.h+g;switch(a.geo){case"cloud":if(f==="solid"){const b=D0(c,w,i,y,S);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:b,color:d,fill:h,scale:r}),p.jsx("path",{d:b,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}else if(f==="draw"){const b=ste(c,w,i,y,S);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:b,color:d,fill:h,scale:r}),p.jsx("path",{d:b,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}else{const b=D0(c,w,i,y,S),P=vm(c,w,i,y,S);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:b,color:d,fill:h,scale:r}),p.jsx("g",{strokeWidth:v,stroke:o[d].solid,fill:"none",pointerEvents:"all",children:P.map(({leftPoint:k,rightPoint:E,center:M,radius:A},R)=>{const D=M?A*tl(tl(C.Angle(M,E))-tl(C.Angle(M,k))):C.Dist(k,E),{strokeDasharray:V,strokeDashoffset:L}=Ws(D,v,{style:f,start:"outset",end:"outset",forceSolid:t});return p.jsx("path",{d:M?`M${k.x},${k.y}A${A},${A},0,0,1,${E.x},${E.y}`:`M${k.x},${k.y}L${E.x},${E.y}`,strokeDasharray:V,strokeDashoffset:L},R)})})]})}case"ellipse":{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),P=b.getSvgPathData(!0);if(f==="dashed"||f==="dotted"){const k=b.length,{strokeDasharray:E,strokeDashoffset:M}=Ws(k<64?k*2:k,v,{style:f,snap:4,closed:!0,forceSolid:t});return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:P,color:d,fill:h,scale:r}),p.jsx("path",{d:P,strokeWidth:v,fill:"none",stroke:o[d].solid,strokeDasharray:E,strokeDashoffset:M})]})}else{const E=(e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n)).getSvgPathData(!0);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:E,color:d,fill:h,scale:r}),p.jsx("path",{d:E,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}}case"oval":{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),P=b.getSvgPathData(!0);if(f==="dashed"||f==="dotted"){const k=b.getLength(),{strokeDasharray:E,strokeDashoffset:M}=Ws(k<64?k*2:k,v,{style:f,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:t});return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:P,color:d,fill:h,scale:r}),p.jsx("path",{d:P,strokeWidth:v,fill:"none",stroke:o[d].solid,strokeDasharray:E,strokeDashoffset:M})]})}else return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:P,color:d,fill:h,scale:r}),p.jsx("path",{d:P,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}case"heart":if(f==="dashed"||f==="dotted"||f==="solid"){const b=dF(c,w),P=sP(c,w);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:b,color:d,fill:h,scale:r}),P.map((k,E)=>{const{strokeDasharray:M,strokeDashoffset:A}=Ws(k.length,v,{style:f,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:t});return p.jsx("path",{d:k.getSvgPathData(),strokeWidth:v,fill:"none",stroke:o[d].solid,strokeDasharray:M,strokeDashoffset:A,pointerEvents:"all"},`curve_${E}`)})]})}else{const b=Yee(c,w,v,n.id);return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:b,color:d,fill:h,scale:r}),p.jsx("path",{d:b,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}default:{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),P=b instanceof Is?b.children[0].vertices:b.vertices,k=L0(n.props,v);if(f==="solid"){let E="M"+P[0]+"L"+P.slice(1)+"Z";if(k)for(const[M,A]of k)E+=`M${M.x},${M.y}L${A.x},${A.y}`;return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:E,color:d,fill:h,scale:r}),p.jsx("path",{d:E,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}else if(f==="dashed"||f==="dotted"){const E="M"+P[0]+"L"+P.slice(1)+"Z";return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:E,color:d,fill:h,scale:r}),p.jsxs("g",{strokeWidth:v,stroke:o[d].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(P.length)).map((M,A)=>{const R=C.ToFixed(P[A]),D=C.ToFixed(P[(A+1)%P.length]),V=C.Dist(R,D),{strokeDasharray:L,strokeDashoffset:U}=Ws(V,v,{style:f,start:"outset",end:"outset",forceSolid:t});return p.jsx("line",{x1:R.x,y1:R.y,x2:D.x,y2:D.y,strokeDasharray:L,strokeDashoffset:U},A)}),k&&k.map(([M,A],R)=>{const D=C.Dist(M,A),{strokeDasharray:V,strokeDashoffset:L}=Ws(D,v,{style:f,start:"skip",end:"skip",snap:f==="dotted"?4:void 0,forceSolid:t});return p.jsx("path",{d:`M${M.x},${M.y}L${A.x},${A.y}`,stroke:o[d].solid,strokeWidth:v,fill:"none",strokeDasharray:V,strokeDashoffset:L},`line_fg_${R}`)})]})]})}else if(f==="draw"){let E=R0(O0(i,P,v/3,v*2,2));if(k)for(const[A,R]of k)E+=`M${A.toFixed()}L${R.toFixed()}`;const M=R0(O0(i,P,0,v*2,1));return p.jsxs(p.Fragment,{children:[p.jsx(Un,{theme:o,d:M,color:d,fill:h,scale:r}),p.jsx("path",{d:E,stroke:o[d].solid,strokeWidth:v,fill:"none"})]})}}}}const kk=17*3;class vf extends Qc{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 t=Math.max(1,e.props.w),r=Math.max(1,e.props.h+e.props.growY),s=t/2,o=r/2,i=e.props.fill!=="none";let a;switch(e.props.geo){case"cloud":{a=new rn({points:nte(t,r,e.id,e.props.size,e.props.scale),isFilled:i});break}case"triangle":{a=new rn({points:[new C(s,0),new C(t,r),new C(0,r)],isFilled:i});break}case"diamond":{a=new rn({points:[new C(s,0),new C(t,o),new C(s,r),new C(0,o)],isFilled:i});break}case"pentagon":{a=new rn({points:yx(t,r,5),isFilled:i});break}case"hexagon":{a=new rn({points:yx(t,r,6),isFilled:i});break}case"octagon":{a=new rn({points:yx(t,r,8),isFilled:i});break}case"ellipse":{a=new bG({width:t,height:r,isFilled:i});break}case"oval":{a=new PG({width:t,height:r,isFilled:i});break}case"star":{const P=St/5/2,k=Math.floor(5/4)*2,E=5*2-k,M=0,A=Math.floor(5/2)*2,R=Math.cos(-Rt+k*P)*t/2,D=Math.cos(-Rt+E*P)*t/2,V=Math.sin(-Rt+M*P)*r/2,L=Math.sin(-Rt+A*P)*r/2,U=t-Math.abs(R-D),K=r-Math.abs(L-V),F=t/2+D-(t/2-R),$=r/2+V-(r/2-L),W=1,Y=(t-F)/2,Z=(r-$)/2,H=(t+U)/2,Q=(r+K)/2,ae=H*W/2,B=Q*W/2;a=new rn({points:Array.from(Array(5*2)).map((ne,he)=>{const Pe=-Rt+he*P;return new C(Y+(he%2?ae:H)*Math.cos(Pe),Z+(he%2?B:Q)*Math.sin(Pe))}),isFilled:i});break}case"rhombus":{const b=Math.min(t*.38,r*.38);a=new rn({points:[new C(b,0),new C(t,0),new C(t-b,r),new C(0,r)],isFilled:i});break}case"rhombus-2":{const b=Math.min(t*.38,r*.38);a=new rn({points:[new C(0,0),new C(t-b,0),new C(t,r),new C(b,r)],isFilled:i});break}case"trapezoid":{const b=Math.min(t*.38,r*.38);a=new rn({points:[new C(b,0),new C(t-b,0),new C(t,r),new C(0,r)],isFilled:i});break}case"arrow-right":{const b=Math.min(t,r)*.38,P=r*.16;a=new rn({points:[new C(0,P),new C(t-b,P),new C(t-b,0),new C(t,r/2),new C(t-b,r),new C(t-b,r-P),new C(0,r-P)],isFilled:i});break}case"arrow-left":{const b=Math.min(t,r)*.38,P=r*.16;a=new rn({points:[new C(b,0),new C(b,P),new C(t,P),new C(t,r-P),new C(b,r-P),new C(b,r),new C(0,r/2)],isFilled:i});break}case"arrow-up":{const b=t*.16,P=Math.min(t,r)*.38;a=new rn({points:[new C(t/2,0),new C(t,P),new C(t-b,P),new C(t-b,r),new C(b,r),new C(b,P),new C(0,P)],isFilled:i});break}case"arrow-down":{const b=t*.16,P=Math.min(t,r)*.38;a=new rn({points:[new C(b,0),new C(t-b,0),new C(t-b,r-P),new C(t,r-P),new C(t/2,r),new C(0,r-P),new C(b,r-P)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new Do({width:t,height:r,isFilled:i});break}case"heart":{const P=sP(t,r).reduce((k,E)=>(k.push(...E.vertices),k),[]);a=new rn({points:P,isFilled:i});break}default:un(e.props.geo)}const c=qp(this.editor,e),d=t/e.props.scale,h=r/e.props.scale,f=Math.min(100,d/2),g=Math.min(Si[e.props.size]*Yn.lineHeight+xs*2,h/2),y=Math.min(d,Math.max(c.w,Math.min(f,Math.max(1,d-8)))),S=Math.min(h,Math.max(c.h,Math.min(g,Math.max(1,h-8)))),v=L0(e.props,qn[e.props.size]*e.props.scale),w=v?v.map(b=>new qc({points:b})):[];return new Is({children:[a,new Do({x:e.props.align==="start"?0:e.props.align==="end"?(d-y)*e.props.scale:(d-y)/2*e.props.scale,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?(h-S)*e.props.scale:(h-S)/2*e.props.scale,width:y*e.props.scale,height:S*e.props.scale,isFilled:!0,isLabel:!0}),...w]})}getHandleSnapGeometry(e){const t=this.getGeometry(e),r=t.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(),t.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:r,points:[t.bounds.center]};default:un(e.props.geo)}}getText(e){return e.props.text}onEditEnd(e){const{id:t,type:r,props:{text:s}}=e;s.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:t,type:r,props:{text:s.trimEnd()}}])}component(e){const{id:t,type:r,props:s}=e,{fill:o,font:i,align:a,verticalAlign:c,size:d,text:h}=s,f=ks(),{editor:g}=this,y=se("isGeoOnlySelected",()=>e.id===g.getOnlySelectedShapeId(),[]),v=g.getEditingShapeId()!==null||e.props.text,w=se("force solid",()=>g.getZoomLevel()<.2,[g]);return p.jsxs(p.Fragment,{children:[p.jsx(ha,{children:p.jsx(Tk,{shape:e,shouldScale:!0,forceSolid:w})}),v&&p.jsx(ca,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+s.growY},children:p.jsx(Sm,{shapeId:t,type:r,font:i,fontSize:Si[d]*e.props.scale,lineHeight:Yn.lineHeight,padding:xs*e.props.scale,fill:o,align:a,verticalAlign:c,text:h,isSelected:y,labelColor:f[s.labelColor].solid,wrap:!0})}),e.props.url&&p.jsx(Fc,{url:e.props.url})]})}indicator(e){const{id:t,props:r}=e,{w:s,size:o}=r,i=r.h+r.growY,a=qn[o],c=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?p.jsx("path",{d:Qee(t,s,i,a)}):p.jsx("path",{d:c.getSvgPathData(!0)});case"heart":return p.jsx("path",{d:dF(s,i)});case"oval":return p.jsx("path",{d:c.getSvgPathData(!0)});case"cloud":return p.jsx("path",{d:D0(s,i,t,o,e.props.scale)});default:{const d=this.editor.getShapeGeometry(e),h=d instanceof Is?d.children[0].vertices:d.vertices;let f;if(r.dash==="draw"){const y=O0(t,h,0,a*2*e.props.scale,1);f=R0(y)}else f="M"+h[0]+"L"+h.slice(1)+"Z";const g=L0(e.props,a);if(g)for(const[y,S]of g)f+=`M${y.x},${y.y}L${S.x},${S.y}`;return p.jsx("path",{d:f})}}}toSvg(e,t){const r={...e,props:{...e.props,w:e.props.w/e.props.scale,h:e.props.h/e.props.scale}},s=r.props;t.addExportDef(Q1(s.fill));let o;if(s.text){t.addExportDef(gm(s.font));const i=_i(t),a=new Se(0,0,s.w,s.h+s.growY);o=p.jsx(ym,{fontSize:Si[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:i[s.labelColor].solid,bounds:a,padding:16})}return p.jsxs(p.Fragment,{children:[p.jsx(Tk,{shouldScale:!1,shape:r,forceSolid:!1}),o]})}getCanvasSvgDefs(){return[J1()]}onResize(e,{handle:t,newPoint:r,scaleX:s,scaleY:o,initialShape:i}){const a=i.props.w/i.props.scale,c=i.props.h/i.props.scale,d=i.props.growY/i.props.scale;let h=a*s,f=(c+d)*o,g=0,y=0;const S=kk;if(e.props.text.trim()){let E=Math.max(Math.abs(h),S),M=Math.max(Math.abs(f),S);E<S&&M===S&&(E=S),E===S&&M<S&&(M=S);const A=qp(this.editor,{...e,props:{...e.props,w:E*e.props.scale,h:M*e.props.scale}}),R=Math.max(Math.abs(h),A.w)*Math.sign(h),D=Math.max(Math.abs(f),A.h)*Math.sign(f);g=Math.abs(R)-Math.abs(h),y=Math.abs(D)-Math.abs(f),h=R,f=D}const v=h*e.props.scale,w=f*e.props.scale,b=new C(0,0);s<0&&(b.x+=v),(t==="left"||t==="top_left"||t==="bottom_left")&&(b.x+=s<0?g:-g),o<0&&(b.y+=w),(t==="top"||t==="top_left"||t==="top_right")&&(b.y+=o<0?y:-y);const{x:P,y:k}=b.rot(e.rotation).add(r);return{x:P,y:k,props:{w:Math.max(Math.abs(v),1),h:Math.max(Math.abs(w),1),growY:0}}}onBeforeCreate(e){if(!e.props.text)return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const t=e.props.h/e.props.scale,r=qp(this.editor,e).h;let s=null;if(r>t?s=r-t:e.props.growY&&(s=0),s!==null)return{...e,props:{...e.props,growY:s*e.props.scale}}}onBeforeUpdate(e,t){const r=e.props.text,s=t.props.text;if(r===s&&e.props.font===t.props.font&&e.props.size===t.props.size)return;if(r&&!s)return{...t,props:{...t.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,c=qp(this.editor,t);if(!r&&s&&s.length===1){let h=Math.max(o,c.w),f=Math.max(i,c.h);const g=kk;return o<g&&i<g&&(h=Math.max(h,g),f=Math.max(f,g),h=Math.max(h,f),f=Math.max(h,f)),{...t,props:{...t.props,w:h*t.props.scale,h:f*t.props.scale,growY:0}}}let d=null;if(c.h>i?d=c.h-i:a&&(d=0),d!==null){const h=t.props.w/t.props.scale;return{...t,props:{...t.props,growY:d*t.props.scale,w:Math.max(h,c.w)*t.props.scale}}}if(c.w>o)return{...t,props:{...t.props,w:c.w*t.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,t,r){return{...r>.5?t.props:e.props,w:ot(e.props.w,t.props.w,r),h:ot(e.props.h,t.props.h,r),scale:ot(e.props.scale,t.props.scale,r)}}}j(vf,"type","geo"),j(vf,"props",UA),j(vf,"migrations",HA);function qp(n,e){const{text:t,font:r,size:s,w:o}=e.props;if(!t)return{w:0,h:0};const i=n.textMeasure.measureText("w",{...Yn,fontFamily:wi[r],fontSize:Si[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},c=n.textMeasure.measureText(t,{...Yn,fontFamily:wi[r],fontSize:Si[s],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[s]),Math.ceil(o/e.props.scale-xs*2))});return{w:c.w+xs*2,h:c.h+xs*2}}function hF(){return p.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:[p.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),p.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),p.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}const Mk=8;function ate(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}function Od(n,e){if(!e)return{w:n.w,h:n.h};const t=n.w/(e.bottomRight.x-e.topLeft.x),r=n.h/(e.bottomRight.y-e.topLeft.y);return{w:t,h:r}}function lte(n,e,t={}){const{handle:r,change:s,crop:o}=e,{w:i,h:a}=e.uncroppedSize,{minWidth:c=Mk,minHeight:d=Mk}=t,h=Nt(o),f=new C(n.x,n.y),g=new C(0,0);let y=!1;switch(r){case"top":case"top_left":case"top_right":{if(a<d)break;y=!0,h.topLeft.y=h.topLeft.y+s.y/a,a*(h.bottomRight.y-h.topLeft.y)<d?(h.topLeft.y=h.bottomRight.y-d/a,g.y=(h.topLeft.y-o.topLeft.y)*a):h.topLeft.y<=0?(h.topLeft.y=0,g.y=(h.topLeft.y-o.topLeft.y)*a):g.y=s.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(a<d)break;y=!0,h.bottomRight.y=Math.min(1,h.bottomRight.y+s.y/a),a*(h.bottomRight.y-h.topLeft.y)<d&&(h.bottomRight.y=h.topLeft.y+d/a);break}}switch(r){case"left":case"top_left":case"bottom_left":{if(i<c)break;y=!0,h.topLeft.x=h.topLeft.x+s.x/i,i*(h.bottomRight.x-h.topLeft.x)<c?(h.topLeft.x=h.bottomRight.x-c/i,g.x=(h.topLeft.x-o.topLeft.x)*i):h.topLeft.x<=0?(h.topLeft.x=0,g.x=(h.topLeft.x-o.topLeft.x)*i):g.x=s.x;break}case"right":case"top_right":case"bottom_right":{if(i<c)break;y=!0,h.bottomRight.x=Math.min(1,h.bottomRight.x+s.x/i),i*(h.bottomRight.x-h.topLeft.x)<c&&(h.bottomRight.x=h.topLeft.x+c/i);break}}if(y)return f.add(g.rot(n.rotation)),{id:n.id,type:n.type,x:f.x,y:f.y,props:{w:(h.bottomRight.x-h.topLeft.x)*i,h:(h.bottomRight.y-h.topLeft.y)*a,crop:h}}}function pF({shapeId:n,assetId:e,width:t}){const r=te(),s=Xd(),o=AH(),[i,a]=_.useState(()=>({asset:e?r.getAsset(e)??null:null,url:null})),c=_.useRef(!1),d=_.useRef(null);return _.useEffect(()=>{if(!e)return;let h=!1,f;const g=To("update state",()=>{if(!s&&n&&r.getCulledShapes().has(n))return;const y=r.getAsset(e);if(!y)return;if(!y.props.src){const w=r.getTemporaryAssetPreview(y.id);if(w){d.current!==w&&(d.current=w,a(b=>({...b,isPlaceholder:!0,url:w})),o());return}}const S=s?s.scale*(t/y.props.w):r.getZoomLevel()*(t/y.props.w);function v(w,b){h||d.current!==b&&(c.current=!0,d.current=b,a({asset:w,url:b}),o())}if(c.current){let w=0;const b=()=>{w++,w>500/16&&(Ak(r,e,S,s,P=>v(y,P)),f==null||f())};f==null||f(),r.on("tick",b),f=()=>r.off("tick",b)}else Ak(r,e,S,s,w=>v(y,w))});return()=>{g(),f==null||f(),h=!0}},[r,e,s,o,n,t]),i}function Ak(n,e,t,r,s){n.resolveAssetUrl(e,{screenScale:t,shouldResolveToOriginal:r?r.pixelRatio===null:!1,dpr:(r==null?void 0:r.pixelRatio)??void 0}).then(o=>{s(o)})}async function cte(n){const t=await(await jo(n)).blob();return Gs.blobToDataUrl(t)}class xf extends Qc{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,t){let r=Kg(e,t);const{flipX:s,flipY:o}=t.initialShape.props,{scaleX:i,scaleY:a,mode:c}=t;if(r={...r,props:{...r.props,flipX:i<0!==s,flipY:a<0!==o}},!e.props.crop)return r;const d=c==="scale_shape"&&i===-1||c==="resize_bounds"&&s!==r.props.flipX,h=c==="scale_shape"&&a===-1||c==="resize_bounds"&&o!==r.props.flipY,{topLeft:f,bottomRight:g}=e.props.crop;return r.props.crop={topLeft:{x:d?1-g.x:f.x,y:h?1-g.y:f.y},bottomRight:{x:d?1-f.x:g.x,y:h?1-f.y:g.y}},r}component(e){return p.jsx(ute,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:p.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h)})}async toSvg(e,t){if(!e.props.assetId||!this.editor.getAsset(e.props.assetId))return null;const{w:s}=Od(e.props,e.props.crop);let o=await t.resolveAssetUrl(e.props.assetId,s);return o?((o.startsWith("blob:")||o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await cte(o)||""),p.jsx(hte,{shape:e,src:o})):null}onDoubleClickEdge(e){const t=e.props;if(!t||this.editor.getCroppingShapeId()!==e.id)return;const r=Nt(t.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},{w:s,h:o}=Od(e.props,r),i=new C(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,t,r){function s(o,i){var f,g,y,S;if(o.props.crop===null&&i.props.crop===null)return null;const a=((f=o.props.crop)==null?void 0:f.topLeft)||{x:0,y:0},c=((g=o.props.crop)==null?void 0:g.bottomRight)||{x:1,y:1},d=((y=i.props.crop)==null?void 0:y.topLeft)||{x:0,y:0},h=((S=i.props.crop)==null?void 0:S.bottomRight)||{x:1,y:1};return{topLeft:{x:ot(a.x,d.x,r),y:ot(a.y,d.y,r)},bottomRight:{x:ot(c.x,h.x,r),y:ot(c.y,h.y,r)}}}return{...r>.5?t.props:e.props,w:ot(e.props.w,t.props.w,r),h:ot(e.props.h,t.props.h,r),crop:s(e,t)}}}j(xf,"type","image"),j(xf,"props",qA),j(xf,"migrations",YA);const ute=_.memo(function({shape:e}){var P;const t=te(),{w:r}=Od(e.props,e.props.crop),{asset:s,url:o}=pF({shapeId:e.id,assetId:e.props.assetId,width:r}),i=qD(),[a,c]=_.useState(""),[d,h]=_.useState(null),f=dte(t,e);_.useEffect(()=>{if(o&&f){let k=!1;const E=xd();return E.onload=()=>{if(k)return;const M=document.createElement("canvas");M.width=E.width,M.height=E.height;const A=M.getContext("2d");A&&(A.drawImage(E,0,0),c(M.toDataURL()),h(o))},E.crossOrigin="anonymous",E.src=o,()=>{k=!0}}},[t,f,i,o]);const g=se("show crop preview",()=>e.id===t.getOnlySelectedShapeId()&&t.getCroppingShapeId()===e.id&&t.isIn("select.crop"),[t,e.id]),y=i&&(((P=s==null?void 0:s.props.mimeType)==null?void 0:P.includes("video"))||f),S=fF(e),v=o===d?null:o,w=y?a:d;if(!o&&!(s!=null&&s.props.src))return p.jsxs(ca,{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:[p.jsx("div",{className:Le("tl-image-container",s&&"tl-image-container-loading"),style:S,children:s?null:p.jsx(hF,{})}),"url"in e.props&&e.props.url&&p.jsx(Fc,{url:e.props.url})]});const b=f?"anonymous":void 0;return p.jsxs(p.Fragment,{children:[g&&w&&p.jsx("div",{style:S,children:p.jsx("img",{className:"tl-image",style:{...md(e),opacity:.1},crossOrigin:b,src:w,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),p.jsxs(ca,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[p.jsxs("div",{className:Le("tl-image-container"),style:S,children:[w&&p.jsx("img",{className:"tl-image",style:md(e),crossOrigin:b,src:w,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},w),v&&p.jsx("img",{className:"tl-image",style:md(e),crossOrigin:b,src:v,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>h(v)},v)]}),e.props.url&&p.jsx(Fc,{url:e.props.url})]})]})});function dte(n,e){const t=e.props.assetId?n.getAsset(e.props.assetId):void 0;return t?"mimeType"in t.props&&Xr.isAnimatedImageType(t==null?void 0:t.props.mimeType)||"isAnimated"in t.props&&t.props.isAnimated:!1}function fF(n){const e=n.props.crop,t=e==null?void 0:e.topLeft;if(!t)return{width:n.props.w,height:n.props.h};const{w:r,h:s}=Od(n.props,e),o=-t.x*r,i=-t.y*s;return{transform:`translate(${o}px, ${i}px)`,width:r,height:s}}function md(n,e){const{flipX:t,flipY:r}=n.props;if(!t&&!r)return;const s=`scale(${t?-1:1}, ${r?-1:1})`;return{transform:`${e?`translate(${t?e.width:0}px, ${r?e.height:0}px)`:""} ${s}`,transformOrigin:e?"0 0":"center center"}}function hte({shape:n,src:e}){const t=Wc(),r=fF(n),s=n.props.crop;if(r.transform&&s){const{transform:o,width:i,height:a}=r,c=(s.bottomRight.x-s.topLeft.x)*i,d=(s.bottomRight.y-s.topLeft.y)*a,h=[new C(0,0),new C(c,0),new C(c,d),new C(0,d)],f=md(n,{width:i,height:a});return p.jsxs(p.Fragment,{children:[p.jsx("defs",{children:p.jsx("clipPath",{id:t,children:p.jsx("polygon",{points:h.map(g=>`${g.x},${g.y}`).join(" ")})})}),p.jsx("g",{clipPath:`url(#${t})`,children:p.jsx("image",{href:e,width:i,height:a,style:f?{...f,transform:`${o} ${f.transform}`}:{transform:o}})})]})}else return p.jsx("image",{href:e,width:n.props.w,height:n.props.h,style:md(n,{width:n.props.w,height:n.props.h})})}function gF(n){return{size:n,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function mF(n,e,t){const r=e.vertices,s=gF(t);return No(r,s)}function pte(n,e,t){const r=gF(t);return q1(fm(mF(n,e,t),r),r)}function fte(n,e,t){const r=pte(n,e,t);return $b(r)}function gte(n,e,t){if(n.props.dash==="draw"){const r=mF(n,e,t);return gl(r)}return e.getSvgPathData()}function yF(n,e,t){let r=`M ${ht(e[0])}L`,s=`M ${ht(e[0])}L`;const o=t/3,i=t*2,a=eo(n);let c=e[0],d,h=e[0],f;const g=e.length;for(let y=0,S=g-1;y<S;y++){d=e[y+1],f=C.AddXY(e[y+1],a()*o,a()*o);const v=C.Sub(d,c),w=C.Len(v),b=C.Div(v,w).mul(Math.min(w/4,i)),P=C.Add(c,b),k=C.Add(d,b.neg()),E=C.Sub(f,h),M=C.Len(E),A=C.Div(E,M).mul(Math.min(M/4,i)),R=C.Add(h,A),D=C.Add(f,A.neg());y===S-1?(r+=`${ht(P)}L ${ht(d)}`,s+=`${ht(R)}L ${ht(f)}`):(r+=`${ht(P)}L ${ht(k)}Q ${ht(d)}`,s+=`${ht(R)}L ${ht(D)}Q ${ht(f)}`,c=d,h=f)}return[r,r+s]}const mte=new Ao;class wf extends Xs{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,t]=bd(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[e]:{id:e,index:e,x:0,y:0},[t]:{id:t,index:t,x:.1,y:.1}},scale:1}}getGeometry(e){return ad(e)}getHandles(e){return mte.get(e.props,()=>{const t=ad(e),r=id(e),s=r.map(o=>({...o,id:o.index,type:"vertex",canSnap:!0}));for(let o=0;o<r.length-1;o++){const i=wd(r[o].index,r[o+1].index),c=t.segments[o].midPoint();s.push({id:i,type:"create",index:i,x:c.x,y:c.y,canSnap:!0})}return s.sort(Wn)})}onResize(e,t){const{scaleX:r,scaleY:s}=t;return{props:{points:Nd(e.props.points,(o,{id:i,index:a,x:c,y:d})=>({id:i,index:a,x:c*r,y:d*s}))}}}onBeforeCreate(e){const{props:{points:t}}=e,r=Object.keys(t);if(r.length<2)return;const s=t[r[0]];if(r.every(i=>{const a=t[i];return a.x===s.x&&a.y===s.y})){const i=r[r.length-1];return t[i]={...t[i],x:t[i].x+.1,y:t[i].y+.1},e}}onHandleDrag(e,{handle:t}){if(t.type!=="vertex")return;const r=Zs(new C(t.x,t.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[t.id]:{id:t.id,index:t.index,x:r.x,y:r.y}}}}}component(e){return p.jsx(ha,{style:{minWidth:50,minHeight:50},children:p.jsx(jk,{shape:e})})}indicator(e){const t=Eo[e.props.size]*e.props.scale,r=ad(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]=yF(e.id,i,t);o=a}}else o=gte(e,r,t);return p.jsx("path",{d:o})}toSvg(e){return p.jsx(jk,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const t=id(e);return{points:t,getSelfSnapPoints:r=>{const s=this.getHandles(e).filter(o=>o.type==="vertex").findIndex(o=>o.id===r.id);return t.filter((o,i)=>Math.abs(i-s)>1).map(C.From)},getSelfSnapOutline:r=>{const s=this.getHandles(e).filter(i=>i.type==="vertex").findIndex(i=>i.id===r.id),o=ad(e).segments.filter((i,a)=>a!==s-1&&a!==s);return o.length?new Is({children:o}):null}}}getInterpolatedProps(e,t,r){const s=id(e),o=id(t),i=[],a=[];let c=yM;if(s.length>o.length)for(let d=0;d<s.length;d++)i[d]={...s[d]},o[d]===void 0?a[d]={...o[o.length-1],id:c}:a[d]={...o[d],id:c},c=Co(c);else if(o.length>s.length)for(let d=0;d<o.length;d++)a[d]={...o[d]},s[d]===void 0?i[d]={...s[s.length-1],id:c}:i[d]={...s[d],id:c},c=Co(c);else for(let d=0;d<o.length;d++)i[d]=s[d],a[d]=o[d];return{...r>.5?t.props:e.props,points:Object.fromEntries(i.map((d,h)=>{const f=a[h];return[d.id,{...d,x:ot(d.x,f.x,r),y:ot(d.y,f.y,r)}]})),scale:ot(e.props.scale,t.props.scale,r)}}}j(wf,"type","line"),j(wf,"props",XA),j(wf,"migrations",ZA);function id(n){return Object.values(n.props.points).sort(Wn)}function ad(n){const e=id(n).map(C.From);switch(n.props.spline){case"cubic":return new wG({points:e});case"line":return new qc({points:e})}}function jk({shape:n,shouldScale:e=!1,forceSolid:t=!1}){const r=ks(),s=ad(n),{dash:o,color:i,size:a}=n.props,c=1/n.props.scale,d=e?c:1,h=Eo[a]*n.props.scale;if(n.props.spline==="line"){if(o==="solid"){const f=s.points,g="M"+f[0]+"L"+f.slice(1);return p.jsx("path",{d:g,stroke:r[i].solid,strokeWidth:h,fill:"none",transform:`scale(${d})`})}if(o==="dashed"||o==="dotted")return p.jsx("g",{stroke:r[i].solid,strokeWidth:h,transform:`scale(${d})`,children:s.segments.map((f,g)=>{const{strokeDasharray:y,strokeDashoffset:S}=t?{strokeDasharray:"none",strokeDashoffset:"none"}:Ws(f.length,h,{style:o,start:g>0?"outset":"none",end:g<s.segments.length-1?"outset":"none"});return p.jsx("path",{strokeDasharray:y,strokeDashoffset:S,d:f.getSvgPathData(!0),fill:"none"},g)})});if(o==="draw"){const f=s.points,[g,y]=yF(n.id,f,h);return p.jsx("path",{d:y,stroke:r[i].solid,strokeWidth:h,fill:"none",transform:`scale(${d})`})}}if(n.props.spline==="cubic"){const f=s.getSvgPathData();if(o==="solid")return p.jsx("path",{strokeWidth:h,stroke:r[i].solid,fill:"none",d:f,transform:`scale(${d})`});if(o==="dashed"||o==="dotted")return p.jsx("g",{stroke:r[i].solid,strokeWidth:h,transform:`scale(${d})`,children:s.segments.map((g,y)=>{const{strokeDasharray:S,strokeDashoffset:v}=Ws(g.length,h,{style:o,start:y>0?"outset":"none",end:y<s.segments.length-1?"outset":"none",forceSolid:t});return p.jsx("path",{strokeDasharray:S,strokeDashoffset:v,d:g.getSvgPathData(),fill:"none"},y)})});if(o==="draw")return p.jsx("path",{d:fte(n,s,h),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${d})`})}}const ui=class ui extends Xs{canEdit(){return!0}hideResizeHandles(){const{resizeMode:e}=ui.options;switch(e){case"none":return!0;case"scale":return!1;default:throw un(e)}}isAspectRatioLocked(){return ui.options.resizeMode==="scale"}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:t,labelWidth:r}=SF(this.editor,e),{scale:s}=e.props,o=t*s,i=r*s,a=Pt*s,c=Yp(e);return new Is({children:[new Do({width:a,height:c,isFilled:!0}),new Do({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"?c-o:(c-o)/2,width:i,height:o,isFilled:!0,isLabel:!0})]})}getHandles(e){const{scale:t}=e.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const s=this.editor.getZoomLevel();if(s*t<.25)return[];const o=Yp(e),i=Pt*t,a=QJ/s*t;return s*t<.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}]}onResize(e,t){const{resizeMode:r}=ui.options;switch(r){case"none":return;case"scale":return lA(e,t);default:throw un(r)}}getText(e){return e.props.text}component(e){const{id:t,type:r,props:{labelColor:s,scale:o,color:i,font:a,size:c,align:d,text:h,verticalAlign:f,fontSizeAdjustment:g}}=e,y=vte(t),S=ks(),v=Pt*o,w=Yp(e),b=se("shape rotation",()=>{var M;return((M=this.editor.getShapePageTransform(t))==null?void 0:M.rotation())??0},[this.editor]),P=se("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),k=se("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),E=e.id===this.editor.getOnlySelectedShapeId();return p.jsxs(p.Fragment,{children:[p.jsx("div",{id:t,className:"tl-note__container",style:{width:v,height:w,backgroundColor:S[i].note.fill,borderBottom:P?k?`${2*o}px solid rgb(20, 20, 20)`:`${2*o}px solid rgb(144, 144, 144)`:"none",boxShadow:P?"none":xte(e.id,b,o)},children:p.jsx(Sm,{shapeId:t,type:r,font:a,fontSize:(g||Si[c])*o,lineHeight:Yn.lineHeight,align:d,verticalAlign:f,text:h,isNote:!0,isSelected:E,labelColor:s==="black"?S[i].note.text:S[s].fill,wrap:!0,padding:16*o,onKeyDown:y})}),"url"in e.props&&e.props.url&&p.jsx(Fc,{url:e.props.url})]})}indicator(e){const{scale:t}=e.props;return p.jsx("rect",{rx:t,width:ee(Pt*t),height:ee(Yp(e))})}toSvg(e,t){e.props.text&&t.addExportDef(gm(e.props.font));const r=_i({isDarkMode:t.isDarkMode}),s=wte(e);return p.jsxs(p.Fragment,{children:[p.jsx("rect",{x:5,y:5,rx:1,width:Pt-10,height:s.h,fill:"rgba(0,0,0,.1)"}),p.jsx("rect",{rx:1,width:Pt,height:s.h,fill:r[e.props.color].note.fill}),p.jsx(ym,{fontSize:e.props.fontSizeAdjustment||Si[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 Rk(this.editor,e)}onBeforeUpdate(e,t){if(!(e.props.text===t.props.text&&e.props.font===t.props.font&&e.props.size===t.props.size))return Rk(this.editor,t)}onEditEnd(e){const{id:t,type:r,props:{text:s}}=e;s.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:t,type:r,props:{text:s.trimEnd()}}])}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,scale:ot(e.props.scale,t.props.scale,r)}}};j(ui,"type","note"),j(ui,"props",QA),j(ui,"migrations",JA),j(ui,"options",{resizeMode:"none"});let F0=ui;function Rk(n,e){const{labelHeight:t,fontSizeAdjustment:r}=SF(n,e),s=Math.max(0,t-Pt);if(s!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:s,fontSizeAdjustment:r}}}function yte(n,e){const{text:t}=e.props;if(!t)return{labelHeight:Si[e.props.size]*Yn.lineHeight+xs*2,labelWidth:100,fontSizeAdjustment:0};const r=Si[e.props.size];let s=0,o=0,i=Pt,a=Pt;const c=1;do{s=Math.min(r,r-o);const d=n.textMeasure.measureText(t,{...Yn,fontFamily:wi[e.props.font],fontSize:s,maxWidth:Pt-xs*2-c,disableOverflowWrapBreaking:!0});if(i=d.h+xs*2,a=d.w+xs*2,s<=14){const h=n.textMeasure.measureText(t,{...Yn,fontFamily:wi[e.props.font],fontSize:s,maxWidth:Pt-xs*2-c});i=h.h+xs*2,a=h.w+xs*2;break}if(d.scrollWidth.toFixed(0)===d.w.toFixed(0))break}while(o++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:s}}const Ste=new Ao;function SF(n,e){return Ste.get(e,()=>yte(n,e))}function vte(n){const e=te(),t=ZL();return _.useCallback(r=>{const s=e.getShape(n);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(n),c=a.rotation(),d=!!(t.dir==="rtl"||z5(s.props.text)),h=(Pt+e.options.adjacentShapeMargin+(i&&!r.shiftKey?s.props.growY:0))*s.props.scale,f=new C(o?r.shiftKey!=d?-1:1:0,i?r.shiftKey?-1:1:0).mul(h).add(mm.clone().mul(s.props.scale)).rot(c).add(a.point()),g=tF(e,s,f,c);g&&(e.markHistoryStoppingPoint("editing adjacent shape"),og(e,g,!0))}},[n,e,t.dir])}function Yp(n){return(Pt+n.props.growY)*n.props.scale}function xte(n,e,t){const r=eo(n),s=Math.abs(r())+.5,o=Math.cos(e),i=5*t,a=4*t,c=6*t,d=7*t;return`0px ${i-s}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
380
|
+
0px ${(a+s*d)*Math.max(0,o)}px ${c+s*d}px -${a+s*c}px rgba(15, 23, 31, ${(.3+s*.1).toFixed(2)}),
|
|
381
|
+
0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+o)/2)).toFixed(2)})`}function wte(n){return new Se(0,0,Pt,Pt+n.props.growY)}const bte=new Ao;class bf extends Xs{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return bte.get(e.props,t=>Ok(this.editor,t))}getGeometry(e){const{scale:t}=e.props,{width:r,height:s}=this.getMinDimensions(e);return new Do({width:r*t,height:s*t,isFilled:!0,isLabel:!0})}getText(e){return e.props.text}canEdit(){return!0}isAspectRatioLocked(){return!0}component(e){const{id:t,props:{font:r,size:s,text:o,color:i,scale:a,textAlign:c}}=e,{width:d,height:h}=this.getMinDimensions(e),f=e.id===this.editor.getOnlySelectedShapeId(),g=ks(),y=Pte(t);return p.jsx(Sm,{shapeId:t,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Oc[s],lineHeight:Yn.lineHeight,align:c,verticalAlign:"middle",text:o,labelColor:g[i].solid,isSelected:f,textWidth:d,textHeight:h,style:{transform:`scale(${a})`,transformOrigin:"top left"},wrap:!0,onKeyDown:y})}indicator(e){const t=this.editor.getShapeGeometry(e).bounds,r=te();return e.props.autoSize&&r.getEditingShapeId()===e.id?null:p.jsx("rect",{width:ee(t.width),height:ee(t.height)})}toSvg(e,t){e.props.text&&t.addExportDef(gm(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=_i(t);return p.jsx(ym,{fontSize:Oc[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 Se(0,0,s,o),padding:0})}onResize(e,t){const{newPoint:r,initialBounds:s,initialShape:o,scaleX:i,handle:a}=t;if(t.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:e.id,type:e.type,...lA(e,t)};{const c=Math.max(1,Math.abs(s.width*i)),{x:d,y:h}=i<0?C.Sub(r,C.FromAngle(e.rotation).mul(c)):r;return{id:e.id,type:e.type,x:d,y:h,props:{w:c/o.props.scale,autoSize:!1}}}}onEditEnd(e){const{id:t,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:t,type:r,props:{text:s.trimEnd()}}])}onBeforeUpdate(e,t){if(!t.props.autoSize)return;const r=e.props.size!==t.props.size||e.props.textAlign!==t.props.textAlign||e.props.font!==t.props.font||e.props.scale!==1&&t.props.scale===1,s=e.props.text!==t.props.text;if(!r&&!s)return;const o=this.getMinDimensions(e),i=Ok(this.editor,t.props),a=o.width*e.props.scale,c=o.height*e.props.scale,d=i.width*t.props.scale,h=i.height*t.props.scale;let f;switch(t.props.textAlign){case"middle":{f=new C((d-a)/2,s?0:(h-c)/2);break}case"end":{f=new C(d-a,s?0:(h-c)/2);break}default:{if(s)break;f=new C(0,(h-c)/2);break}}if(f){f.rot(t.rotation);const{x:g,y}=t;return{...t,x:g-f.x,y:y-f.y,props:{...t.props,w:d}}}else return{...t,props:{...t.props,w:d}}}}j(bf,"type","text"),j(bf,"props",ej),j(bf,"migrations",tj);function Ok(n,e){const{font:t,text:r,autoSize:s,size:o,w:i}=e,a=s?16:Math.max(16,i),c=Oc[o],d=s?null:Math.floor(Math.max(a,i)),h=n.textMeasure.measureText(r,{...Yn,fontFamily:wi[t],fontSize:c,maxWidth:d});return s&&(h.w+=1),{width:Math.max(a,h.w),height:Math.max(c,h.h)}}function Pte(n){const e=te();return _.useCallback(t=>{if(e.getEditingShapeId()===n)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&e.complete();break}case"Tab":{Je(t),t.shiftKey?Dc.unindent(t.currentTarget):Dc.indent(t.currentTarget);break}}},[e,n])}class Pf extends Qc{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return p.jsx(Cte,{shape:e})}indicator(e){return p.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h)})}async toSvg(e,t){if(!e.props.assetId)return null;const r=await t.resolveAssetUrl(e.props.assetId,e.props.w);if(!r)return null;const s=await Xr.loadVideo(r),o=await Xr.getVideoFrameAsDataUrl(s,0);return o?p.jsx("image",{href:o,width:e.props.w,height:e.props.h}):null}}j(Pf,"type","video"),j(Pf,"props",nj),j(Pf,"migrations",rj);const Cte=_.memo(function({shape:e}){const t=te(),r=t.getShapeGeometry(e).bounds.w*t.getZoomLevel()>=110,s=Wg(e.id),o=qD(),{Spinner:i}=$t(),{asset:a,url:c}=pF({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),d=_.useRef(null),[h,f]=_.useState(!1),[g,y]=_.useState(!1);_.useEffect(()=>{const v=()=>y(document.fullscreenElement===d.current);return document.addEventListener("fullscreenchange",v),()=>document.removeEventListener("fullscreenchange",v)});const S=_.useCallback(v=>{v.currentTarget&&f(!0)},[]);return _.useEffect(()=>{const v=d.current;v&&s&&document.activeElement!==v&&v.focus()},[s,h]),_.useEffect(()=>{if(o){const v=d.current;if(!v)return;v.pause(),v.currentTime=0}},[d,o]),p.jsxs(p.Fragment,{children:[p.jsx(ca,{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:p.jsx("div",{className:"tl-counter-scaled",children:p.jsx("div",{className:"tl-video-container",children:a?i&&!a.props.src?p.jsx(i,{}):c?p.jsxs(p.Fragment,{children:[p.jsx("video",{ref:d,style:s?{pointerEvents:"all"}:h?void 0:{display:"none"},className:Le("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":g}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:s&&r,onLoadedData:S,hidden:!h,children:p.jsx("source",{src:c})}),!h&&i&&p.jsx(i,{})]}):null:p.jsx(hF,{})})})}),"url"in e.props&&e.props.url&&p.jsx(Fc,{url:e.props.url})]})}),vF=[bf,yf,Pc,vf,F0,wf,Sf,mf,dg,fg,xf,Pf];function _te(n){return n.sideEffects.register({instance_page_state:{afterChange:(e,t)=>{if(e.croppingShapeId!==t.croppingShapeId){const r=n.isIn("select.crop");!e.croppingShapeId&&t.croppingShapeId?r||n.setCurrentTool("select.crop.idle"):e.croppingShapeId&&!t.croppingShapeId&&r&&n.setCurrentTool("select.idle")}if(e.editingShapeId!==t.editingShapeId)if(!e.editingShapeId&&t.editingShapeId){if(!n.isIn("select.editing_shape")){const r=n.getEditingShape();r&&r.type==="text"&&n.isInAny("text.pointing","select.resizing")&&n.getInstanceState().isToolLocked?n.setCurrentTool("select.editing_shape",{isCreatingTextWhileToolLocked:!0}):n.setCurrentTool("select.editing_shape")}}else e.editingShapeId&&!t.editingShapeId&&n.isIn("select.editing_shape")&&n.setCurrentTool("select.idle")}}})}class xF extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"scribbleId","id");j(this,"markId","");j(this,"excludedShapeIds",new Set)}onEnter(t){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=t;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:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,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:t,excludedShapeIds:r}=this,s=t.getErasingShapeIds(),o=t.getZoomLevel(),i=t.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:c}}=t;this.pushPointToScribble();const d=new Set(s),h=this.editor.options.hitTestMargin/o;for(const f of i){if(t.isShapeOfType(f,"group"))continue;const g=t.getShapeMask(f.id);if(g&&!Jr(a,g))continue;const y=t.getShapeGeometry(f),S=t.getShapePageTransform(f);if(!y||!S)continue;const v=S.clone().invert(),w=v.applyToPoint(c),b=v.applyToPoint(a),{bounds:P}=y;P.minX-h>Math.max(w.x,b.x)||P.minY-h>Math.max(w.y,b.y)||P.maxX+h<Math.min(w.x,b.x)||P.maxY+h<Math.min(w.y,b.y)||y.hitTestLineSegment(w,b,h)&&d.add(t.getOutermostSelectableShape(f).id)}this.editor.setErasingShapes([...d].filter(f=>!r.has(f)))}complete(){const{editor:t}=this;t.deleteShapes(t.getCurrentPageState().erasingShapeIds),this.parent.transition("idle")}cancel(){const{editor:t}=this;t.bailToMark(this.markId),this.parent.transition("idle",this.info)}}j(xF,"id","erasing");var _w;let Ite=(_w=class extends Re{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},j(_w,"id","idle"),_w);var Iw;let Ete=(Iw=class extends Re{onEnter(){const e=this.editor.getZoomLevel(),t=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,s=new Set,o=s.size;for(let i=t.length,a=i-1;a>=0;a--){const c=t[a];if(!(this.editor.isShapeOrAncestorLocked(c)||this.editor.isShapeOfType(c,"group"))&&this.editor.isPointInShape(c,r,{hitInside:!1,margin:this.editor.options.hitTestMargin/e})){const d=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(d,"frame")&&s.size>o)break;s.add(d.id)}}this.editor.setErasingShapes([...s])}onLongPress(e){this.startErasing(e)}onExit(e,t){t!=="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")}},j(Iw,"id","pointing"),Iw);class Cf extends Re{static children(){return[Ite,Ete,xF]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}j(Cf,"id","eraser"),j(Cf,"initial","idle"),j(Cf,"isLockable",!1);class wF extends Re{constructor(){super(...arguments);j(this,"initialCamera",new C)}onEnter(){this.initialCamera=C.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:t,editor:r}=this,{currentScreenPoint:s,originScreenPoint:o}=r.inputs,i=C.Sub(s,o).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(t.clone().add(i))}complete(){const{editor:t}=this,{pointerVelocity:r}=t.inputs,s=Math.min(r.len(),2);s>.1&&this.editor.slideCamera({speed:s,direction:r}),this.parent.transition("idle")}}j(wF,"id","dragging");var Ew;let Tte=(Ew=class extends Re{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},j(Ew,"id","idle"),Ew);var Tw;let kte=(Tw=class extends Re{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")}},j(Tw,"id","pointing"),Tw);class _f extends Re{static children(){return[Tte,kte,wF]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomIn(t,{animation:{duration:220,easing:vn.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomOut(t,{animation:{duration:320,easing:vn.easeOutQuint}})}}onQuadrupleClick(e){if(e.phase==="settle"){const t=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:r}}=this.editor;t===1?this.editor.zoomToFit({animation:{duration:400,easing:vn.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:vn.easeOutQuint}})}}}j(_f,"id","hand"),j(_f,"initial","idle"),j(_f,"isLockable",!1);var kw;let Mte=(kw=class extends Re{onPointerDown(e){this.parent.transition("lasering",e)}},j(kw,"id","idle"),kw);class bF extends Re{constructor(){super(...arguments);j(this,"scribbleId","id")}onEnter(){const t=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:this.editor.options.laserDelayMs,shrink:.05,taper:!0});this.scribbleId=t.id,this.pushPointToScribble()}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.pushPointToScribble()}onPointerUp(){this.complete()}pushPointToScribble(){const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)}onCancel(){this.cancel()}onComplete(){this.complete()}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}j(bF,"id","lasering");class If extends Re{static children(){return[Mte,bF]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}j(If,"id","laser"),j(If,"initial","idle"),j(If,"isLockable",!1);class PF extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"initialSelectedShapeIds",[]);j(this,"excludedShapeIds",new Set);j(this,"isWrapMode",!1);j(this,"initialStartShape",null)}onEnter(t){const{altKey:r,currentPagePoint:s}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",t);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=t,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:t}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(t){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",t)}onKeyDown(t){this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:t,excludedShapeIds:r,isWrapMode:s}=this,{inputs:{originPagePoint:o,currentPagePoint:i,shiftKey:a,ctrlKey:c}}=t,d=new Set(a?this.initialSelectedShapeIds:[]),h=s?!c:c,f=Se.FromPoints([o,i]),{corners:g}=f;let y,S,v,w,b,P;const k=t.getCurrentPageRenderingShapesSorted(),E=t.getCurrentPageId();e:for(let R=0,D=k.length;R<D;R++){if(v=k[R],r.has(v.id)||d.has(v.id)||(w=t.getShapePageBounds(v),!w))continue e;if(f.contains(w)){this.handleHit(v,i,E,d,g);continue e}if(h||t.isShapeOfType(v,"frame"))continue e;if(f.collides(w)){if(b=t.getShapePageTransform(v),!b)continue e;P=b.clone().invert().applyToPoints(g);const V=t.getShapeGeometry(v);t:for(let L=0;L<4;L++)if(y=P[L],S=P[(L+1)%4],V.hitTestLineSegment(y,S,0)){this.handleHit(v,i,E,d,g);break t}}}const M=t.getInstanceState().brush;(!M||!f.equals(M))&&t.updateInstanceState({brush:{...f.toJson()}});const A=t.getSelectedShapeIds();(A.length!==d.size||A.some(R=>!d.has(R)))&&t.setSelectedShapes(Array.from(d))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(t,r,s,o,i){if(t.parentId===s){o.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),c=this.editor.getShapeMask(a.id);c&&!Gb(c,i)&&!Jr(r,c)||o.add(a.id)}}j(PF,"id","brushing");const Nc={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 CF extends Re{constructor(){super(...arguments);j(this,"info",{})}updateCursor(){const t=this.editor.getSelectedShapes(),r=Nc[this.info.handle];this.editor.setCursor({type:r,rotation:t.length===1?this.editor.getSelectionRotation():0})}onEnter(t){this.info=t,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")}}j(CF,"id","pointing_resize_handle");class oP extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"markId","");j(this,"snapshot",{})}onEnter(t){this.info=t,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=Nc[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){var g;const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t)return;const s=this.editor.getShapeUtil(t.type);if(!s)return;const o=this.editor.inputs.currentPagePoint.clone().sub(r),i=this.editor.inputs.originPagePoint.clone().sub(r),a=o.clone().sub(i).rot(-t.rotation),c=t.props.crop??ate(),d={w:1/(c.bottomRight.x-c.topLeft.x)*t.props.w,h:1/(c.bottomRight.y-c.topLeft.y)*t.props.h},f=(((g=s.onCrop)==null?void 0:g.bind(s))??lte)(t,{handle:this.info.handle,change:a,crop:c,uncroppedSize:d,initialShape:this.snapshot.shape});f&&(this.editor.updateShapes([{id:t.id,type:t.type,...f}]),this.updateCursor())}complete(){this.updateShapes(),jt(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 t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,s=this.editor.getOnlySelectedShape(),o=this.editor.getSelectionRotatedPageBounds(),i=C.RotWith(o.getHandlePoint(this.info.handle),o.point,t),a=C.Sub(r,i);return{shape:s,cursorHandleOffset:a}}}j(oP,"id","cropping");function _F(n,e=!1){const t=n.getZoomLevel(),{inputs:{currentPagePoint:r}}=n;return n.getShapeAtPoint(r,{hitInside:!1,hitLabels:e,margin:n.options.hitTestMargin/t,renderingOnly:!0})??n.getSelectedShapeAtPoint(r)}function IF(n,e,t){if(!e)throw Error("Needs to translate a cropped shape!");const{crop:r}=e.props;if(!r)return;const s=n.inputs.shiftKey?Math.abs(t.x)<Math.abs(t.y)?"x":"y":null;s==="x"?t.x=0:s==="y"&&(t.y=0),t.rot(-e.rotation);const{w:o,h:i}=Od(e.props,r),a=r.bottomRight.y-r.topLeft.y,c=r.bottomRight.x-r.topLeft.x,d=Nt(r);return d.topLeft.x=Math.min(1-c,Math.max(0,d.topLeft.x-t.x/o)),d.topLeft.y=Math.min(1-a,Math.max(0,d.topLeft.y-t.y/i)),d.bottomRight.x=d.topLeft.x+c,d.bottomRight.y=d.topLeft.y+a,{id:e.id,type:e.type,props:{crop:d}}}var Mw;let Ate=(Mw=class extends Re{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 t;if(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=_F(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(t=this.editor.getShapeUtil(e.shape))!=null&&t.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 t=this.editor.getCroppingShapeId();if(!t)return;const r=this.editor.getShape(t);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:t}}}=this,r=t.has("ShiftLeft"),s=new C(0,0);if(t.has("ArrowLeft")&&(s.x+=1),t.has("ArrowRight")&&(s.x-=1),t.has("ArrowUp")&&(s.y+=1),t.has("ArrowDown")&&(s.y-=1),s.equals(new C(0,0)))return;r&&s.mul(10);const o=this.editor.getShape(this.editor.getCroppingShapeId());if(!o)return;const i=IF(this.editor,o,s);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},j(Mw,"id","idle"),Mw);class EF extends Re{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)}}j(EF,"id","pointing_crop");class iP extends Re{constructor(){super(...arguments);j(this,"info",{})}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=Nc[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"))}}j(iP,"id","pointing_crop_handle");class TF extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"markId","");j(this,"snapshot",{})}onEnter(t){this.info=t,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(t){switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}}onKeyUp(t){switch(t.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 t=this.snapshot.shape;if(!t)return;const{originPagePoint:r,currentPagePoint:s}=this.editor.inputs,o=s.clone().sub(r),i=IF(this.editor,t,o);i&&this.editor.updateShapes([i])}}j(TF,"id","translating_crop");class N0 extends Re{constructor(){super(...arguments);j(this,"markId","");j(this,"didExit",!1)}static children(){return[Ate,TF,EF,iP,oP]}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))}}j(N0,"id","crop"),j(N0,"initial","idle");class kF extends Re{constructor(){super(...arguments);j(this,"shapeId","");j(this,"initialHandle",{});j(this,"initialAdjacentHandle",null);j(this,"initialPagePoint",{});j(this,"markId","");j(this,"initialPageTransform");j(this,"initialPageRotation");j(this,"info",{});j(this,"isPrecise",!1);j(this,"isPreciseId",null);j(this,"pointingId",null);j(this,"exactTimeout",-1)}onEnter(t){const{shape:r,isCreating:s,creatingMarkId:o,handle:i}=t;if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.shapeId=r.id,this.markId="",s)if(o)this.markId=o;else{const d=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);d&&(this.markId=d)}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 h=this.editor.getShapeHandles(r).find(f=>f.index===i.index);this.initialHandle=Nt(h)}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(Wn),c=a.findIndex(d=>d.id===t.handle.id);this.initialAdjacentHandle=null;for(let d=c+1;d<a.length;d++){const h=a[d];if(h.type==="vertex"&&h.id!=="middle"&&h.id!==t.handle.id){this.initialAdjacentHandle=h;break}}if(!this.initialAdjacentHandle)for(let d=a.length-1;d>=0;d--){const h=a[d];if(h.type==="vertex"&&h.id!=="middle"&&h.id!==t.handle.id){this.initialAdjacentHandle=h;break}}if(this.editor.isShapeOfType(r,"arrow")){const d=Rr(this.editor,r)[t.handle.id];this.isPrecise=!1,d?(this.editor.setHintingShapes([d.toId]),this.isPrecise=d.props.isPrecise,this.isPrecise?this.isPreciseId=d.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(),jt(this.editor,[this.shapeId]);const{onInteractionEnd:t}=this.info;if(this.editor.getInstanceState().isToolLocked&&t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:t}=this.info;if(t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var R;const{editor:t,shapeId:r,initialPagePoint:s}=this,{initialHandle:o,initialPageRotation:i,initialAdjacentHandle:a}=this,c=this.editor.getHintingShapeIds(),d=this.editor.user.getIsSnapMode(),{snaps:h,inputs:{currentPagePoint:f,shiftKey:g,ctrlKey:y,altKey:S,pointerVelocity:v}}=t,w=this.info.shape,b=t.getShape(r);if(!b)return;const P=t.getShapeUtil(b);let k=f.clone().sub(s).rot(-i).add(o);if(g&&a&&o.id!=="middle"){const D=C.Angle(a,k),L=Lf(D,24)-D;k=C.RotWith(k,a,L)}t.snaps.clearIndicators();let E={...o,x:k.x,y:k.y};if(o.canSnap&&(d?!y:y)){if(!t.getShapePageTransform(b.id))throw Error("Expected a page transform");const V=h.handles.snapHandle({currentShapeId:r,handle:E});V&&(V.nudge.rot(-t.getShapeParentTransform(b).rotation()),k.add(V.nudge),E={...o,x:k.x,y:k.y})}const M=(R=P.onHandleDrag)==null?void 0:R.call(P,b,{handle:E,isPrecise:this.isPrecise||S,initial:w}),A={id:b.id,type:b.type,...M};if(o.type==="vertex"&&this.editor.isShapeOfType(b,"arrow")){const D=Rr(t,b)[o.id];D?c[0]!==D.toId&&(t.setHintingShapes([D.toId]),this.pointingId=D.toId,this.isPrecise=v.len()<.5||S,this.isPreciseId=this.isPrecise?D.toId:null,this.resetExactTimeout()):c.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}M&&t.updateShapes([A])}}j(kF,"id","dragging_handle");function MF(n){return n.isLabel?[n]:n instanceof Is?n.children.filter(e=>e.isLabel):[]}class AF extends Re{constructor(){super(...arguments);j(this,"hitShapeForPointerUp",null);j(this,"info",{})}onEnter(t){const r=this.editor.getEditingShape();if(!r)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,this.info=t,t.isCreatingTextWhileToolLocked&&this.parent.setCurrentToolIdMask("text"),pi(this.editor),this.editor.select(r)}onExit(){var o;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null),pi.cancel();const r=this.editor.getShape(t),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(t){if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getIsReadonly()||this.hitShapeForPointerUp.isLocked)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",t),this.hitShapeForPointerUp=null;return}switch(t.target){case"shape":case"canvas":{pi(this.editor);return}}}onPointerDown(t){switch(this.hitShapeForPointerUp=null,t.target){case"shape":{const{shape:r}=t,s=this.editor.getEditingShape();if(!s)throw Error("Expected an editing shape!");const o=this.editor.getShapeUtil(r).getGeometry(r),i=MF(o),a=i.length===1?i[0]:void 0,c=this.editor.isShapeOfType(s,"text")&&s.props.text.trim()==="";if(a&&!c){const d=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(d,0)&&a.hitTestPoint(d)){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",t));else{this.parent.transition("pointing_shape",t);return}return}break}}this.parent.transition("idle",t),this.editor.root.handleEvent(t)}onPointerUp(t){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",t);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),pi(this.editor)}}onComplete(t){this.parent.transition("idle",t)}onCancel(t){this.parent.transition("idle",t)}}j(AF,"id","editing_shape");function Dk(n){const e=n.getOnlySelectedShape();return!!(e&&!n.isShapeOrAncestorLocked(e)&&n.getShapeUtil(e).canCrop(e))}function gg(n,e){const t=n.getSelectedShapeIds(),{currentPagePoint:r}=n.inputs,{shiftKey:s,altKey:o,accelKey:i}=e,a=s||i,c=n.getShapeAtPoint(r,{hitInside:!1,margin:n.options.hitTestMargin/n.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:d=>!d.isLocked});if(c){const d=n.getOutermostSelectableShape(c);if(a&&!o)n.cancelDoubleClick(),t.includes(d.id)?(n.markHistoryStoppingPoint("deselecting shape"),n.deselect(d)):(n.markHistoryStoppingPoint("shift selecting shape"),n.setSelectedShapes([...t,d.id]));else{let h;d===c||d.id===n.getFocusedGroupId()||t.includes(d.id)?h=c:h=d,h&&!t.includes(h.id)&&(n.markHistoryStoppingPoint("selecting shape"),n.select(h.id))}}else{if(a)return;{t.length>0&&(n.markHistoryStoppingPoint("selecting none"),n.selectNone());const d=n.getFocusedGroupId();if(Mr(d)){const h=n.getShape(d);n.isPointInShape(h,r,{margin:0,hitInside:!0})||n.setFocusedGroup(null)}}}}const jte=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Aw;let Rte=(Aw=class extends Re{onEnter(){this.parent.setCurrentToolIdMask(void 0),pi(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){pi.cancel()}onPointerMove(){pi(this.editor)}onPointerDown(e){const t=e.ctrlKey&&Dk(this.editor);switch(e.target){case"canvas":{const r=_F(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))&&Lk(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(t)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 t,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}),c=this.editor.getFocusedGroupId();if(a){if(this.editor.isShapeOfType(a,"group")){gg(this.editor,e);return}else{const d=this.editor.getShape(a.parentId);if(d&&this.editor.isShapeOfType(d,"group")&&!(c&&d.id===c)){gg(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 c=(t=a.onDoubleClickEdge)==null?void 0:t.call(a,i);if(c){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([c]),jt(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 c=(r=a.onDoubleClick)==null?void 0:r.call(a,i);if(c){this.editor.updateShapes([c]);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,c=this.editor.getShapeUtil(i),d=(o=c.onDoubleClickHandle)==null?void 0:o.call(c,i,a);d?this.editor.updateShapes([d]):this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}}}onRightClick(e){switch(e.target){case"canvas":{const t=this.editor.getHoveredShape(),r=t&&!this.editor.isShapeOfType(t,"group")?t: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))&&Lk(this.editor,i)){this.onRightClick({...e,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:t}=this.editor.getCurrentPageState(),{shape:r}=e,s=this.editor.getOutermostSelectableShape(r,o=>!t.includes(o.id));!t.includes(s.id)&&!this.editor.findShapeAncestor(s,o=>t.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(sn.editOnType.get()&&!jte.includes(e.key)&&!e.altKey&&!e.ctrlKey){const t=this.editor.getOnlySelectedShape();if(t&&this.editor.isShapeOfType(t,"note")&&this.shouldStartEditingShape(t)){this.startEditingShape(t,{...e,target:"shape",shape:t},!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 t=this.editor.getSelectedShapes();if(t.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(t.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}Dk(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,t,r){this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||(this.editor.markHistoryStoppingPoint("editing shape"),og(this.editor,e,r),this.parent.transition("editing_shape",t))}isOverArrowLabelTest(e){if(!e)return!1;const t=this.editor.getPointInShapeSpace(e,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(e,"arrow")){const r=this.editor.getShapeGeometry(e).children[1];if(r&&Jr(t,r.vertices))return!0}return!1}handleDoubleClickOnCanvas(e){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");const t=Ct(),{x:r,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:t,type:"text",x:r,y:s,props:{text:"",autoSize:!0}}]);const o=this.editor.getShape(t);if(!o)return;const i=this.editor.getShapeUtil(o);this.editor.getIsReadonly()&&!i.canEditInReadOnly(o)||(this.editor.setEditingShape(t),this.editor.select(t),this.parent.transition("editing_shape",e))}nudgeSelectedShapes(e=!1){const{editor:{inputs:{keys:t}}}=this,r=t.has("ShiftLeft"),s=new C(0,0);if(t.has("ArrowLeft")&&(s.x-=1),t.has("ArrowRight")&&(s.x+=1),t.has("ArrowUp")&&(s.y-=1),t.has("ArrowDown")&&(s.y+=1),s.equals(new C(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:o}=this.editor.getDocumentSettings(),i=this.editor.getInstanceState().isGridMode?r?o*Lte:o:r?Ote:Dte,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,s.mul(i)),jt(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},j(Aw,"id","idle"),Aw);const Ote=10,Dte=1,Lte=5;function Lk(n,e){const t=n.getSelectionRotatedPageBounds();if(!t)return!1;const r=n.getSelectionRotation();return r?Jr(e,t.corners.map(s=>C.RotWith(s,t.point,r))):t.containsPoint(e)}class jF extends Re{constructor(){super(...arguments);j(this,"shapeId","");j(this,"markId","");j(this,"wasAlreadySelected",!1);j(this,"didDrag",!1);j(this,"didCtrlOnEnter",!1);j(this,"info",{});j(this,"_labelDragOffset",new C(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(t){const{shape:r}=t;this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.shapeId=r.id,this.didDrag=!1,this.didCtrlOnEnter=t.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);if(this._labelDragOffset=C.Sub(o.center,a),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),t.shiftKey||t.accelKey){const d=this.editor.getSelectedShapeIds();this.editor.setSelectedShapes([...d,this.shapeId]);return}this.editor.setSelectedShapes([this.shapeId])}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){const{isDragging:t}=this.editor.inputs;if(!t)return;if(this.didCtrlOnEnter){this.parent.transition("brushing",this.info);return}const r=this.editor.getShape(this.shapeId);if(!r)return;const s=Io(this.editor,r),o=this.editor.getShapeGeometry(r),i=o.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),c=i.nearestPoint(C.Add(a,this._labelDragOffset));let d;if(s.isStraight){const h=C.Dist(s.start.point,s.end.point);d=1-C.Dist(s.end.point,c)/h}else{const{_center:h,measure:f,angleEnd:g,angleStart:y}=o.children[0];d=$w(f,y,g,h.angle(c))}isNaN(d)&&(d=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:d}})}onPointerUp(){const t=this.editor.getShape(this.shapeId);t&&(this.didDrag||!this.wasAlreadySelected?this.complete():this.editor.getIsReadonly()||(this.editor.setEditingShape(t.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")}}j(jF,"id","pointing_arrow_label");class RF extends Re{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){gg(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}j(RF,"id","pointing_canvas");class OF extends Re{constructor(){super(...arguments);j(this,"didCtrlOnEnter",!1);j(this,"info",{})}onEnter(t){this.info=t,this.didCtrlOnEnter=t.accelKey;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const s=Rr(this.editor,r)[t.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:t,handle:r}=this.info;if(this.editor.isShapeOfType(t,"note")){const{editor:s}=this,o=Fk(s,t,r,!1);if(o){og(s,o,!0);return}}this.parent.transition("idle",this.info)}onPointerMove(t){const{editor:r}=this;r.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",t):this.startDraggingHandle())}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){const{editor:t}=this;if(t.getIsReadonly())return;const{shape:r,handle:s}=this.info;if(t.isShapeOfType(r,"note")){const o=Fk(t,r,s,!0);if(o){const i=t.getPointInParentSpace(o,t.inputs.originPagePoint).sub(C.Rot(mm.clone().mul(r.props.scale),o.rotation));t.updateShape({...o,x:i.x,y:i.y}),t.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:t.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{og(t,o,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}j(OF,"id","pointing_handle");function Fk(n,e,t,r){const s=n.getShapePageTransform(e.id),o=s.point(),i=s.rotation(),c=J5(n,o,i,e.props.growY*e.props.scale,0,e.props.scale)[t.index];if(c)return tF(n,e,c,i,r)}class DF extends Re{constructor(){super(...arguments);j(this,"info",{})}updateCursor(){this.editor.setCursor({type:Nc[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(t){this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,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")}}j(DF,"id","pointing_rotate_handle");class LF extends Re{constructor(){super(...arguments);j(this,"info",{})}onEnter(t){this.info=t}onPointerUp(t){gg(this.editor,t),this.parent.transition("idle",t)}onPointerMove(t){this.editor.inputs.isDragging&&this.startTranslating(t)}onLongPress(t){this.startTranslating(t)}startTranslating(t){this.editor.getIsReadonly()||this.parent.transition("translating",t)}onDoubleClick(t){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,{...t,target:"shape",shape:this.editor.getShape(s)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}j(LF,"id","pointing_selection");class FF extends Re{constructor(){super(...arguments);j(this,"hitShape",{});j(this,"hitShapeForPointerUp",{});j(this,"isDoubleClick",!1);j(this,"didCtrlOnEnter",!1);j(this,"didSelectOnEnter",!1)}onEnter(t){const r=this.editor.getSelectedShapeIds(),s=this.editor.getSelectionRotatedPageBounds(),o=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i}}=this.editor,{shiftKey:a,altKey:c,accelKey:d}=t;this.hitShape=t.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=d;const h=this.editor.getOutermostSelectableShape(t.shape),f=this.editor.findShapeAncestor(h,g=>r.includes(g.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(t.shape).onClick||h.id===o||r.includes(h.id)||f||r.length>1&&(s!=null&&s.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=h;return}this.didSelectOnEnter=!0,a&&!c?(this.editor.cancelDoubleClick(),r.includes(h.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,h.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([h.id]))}onPointerUp(t){var h;const r=this.editor.getSelectedShapeIds(),s=this.editor.getFocusedGroupId(),o=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i}}=this.editor,a=t.shiftKey||t.accelKey,c=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/o,hitInside:!0,renderingOnly:!0})??this.hitShape,d=c?this.editor.getOutermostSelectableShape(c):this.hitShapeForPointerUp;if(d){const f=this.editor.getShapeUtil(d);if(f.onClick){const g=(h=f.onClick)==null?void 0:h.call(f,d);if(g){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([g]),this.parent.transition("idle",t);return}}if(d.id===s){r.length>0?(this.editor.markHistoryStoppingPoint("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",t);return}}if(!this.didSelectOnEnter){const f=this.editor.getOutermostSelectableShape(c,g=>!r.includes(g.id));if(r.includes(f.id))if(a)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(d);else if(r.includes(d.id)){if(r.length===1){const g=this.editor.getShapeUtil(d).getGeometry(d),y=MF(g),S=y.length===1?y[0]:void 0;if(S){const v=this.editor.getPointInShapeSpace(d,i);if(S.bounds.containsPoint(v,0)&&S.hitTestPoint(v)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(d.id);const w=this.editor.getShapeUtil(d);this.editor.getIsReadonly()&&!w.canEditInReadOnly(d)||(this.editor.setEditingShape(d.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:d.id}))});return}}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(d.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(d);else if(a){const g=this.editor.getShapeAncestors(f);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(y=>!g.find(S=>S.id===y)),f.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([f.id])}this.parent.transition("idle",t)}onDoubleClick(){this.isDoubleClick=!0}onPointerMove(t){this.editor.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",t):this.startTranslating(t))}onLongPress(t){this.startTranslating(t)}startTranslating(t){this.editor.getIsReadonly()||(this.editor.focus(),this.parent.transition("translating",t))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}j(FF,"id","pointing_shape");class NF extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"markId","");j(this,"didHoldCommand",!1);j(this,"creationCursorOffset",{x:0,y:0});j(this,"snapshot",{})}onEnter(t){const{isCreating:r=!1,creatingMarkId:s,creationCursorOffset:o={x:0,y:0}}=t;if(this.info=t,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(t.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:t}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)}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 t,r;if(jt(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(t=this.info).onCreate)==null||r.call(t,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:t}=this.snapshot,r=[];t.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:t}=this.snapshot,r=[];t.forEach(({shape:s})=>{var c;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(c=i.onResizeEnd)==null?void 0:c.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:o,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:c,selectionRotation:d,canShapesDeform:h}=this.snapshot;let f=r||!h;if(o.size===1){const D=[...o.values()][0];this.editor.isShapeOfType(D.shape,"text")&&(f=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:g}=this.editor.inputs,y=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),S=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!g){const{gridSize:D}=this.editor.getDocumentSettings();y.snapToGrid(D)}const v=this.info.handle,w=Nk(v,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!g:g)&&d%Rt===0){const{nudge:D}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:C.Sub(y,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:Nk(v,d),isAspectRatioLocked:f,isResizingFromCenter:t});y.add(D)}const P=C.RotWith(t?i.center:i.getHandlePoint(w),i.point,d),k=C.Sub(y,P).rot(-d),E=C.Sub(S,P).rot(-d),M=C.DivV(k,E);Number.isFinite(M.x)||(M.x=1),Number.isFinite(M.y)||(M.y=1);const A=v==="top"||v==="bottom",R=v==="left"||v==="right";f?R?M.y=Math.abs(M.x):A?M.x=Math.abs(M.y):Math.abs(M.x)>Math.abs(M.y)?M.y=Math.abs(M.x)*(M.y<0?-1:1):M.x=Math.abs(M.y)*(M.x<0?-1:1):(A&&(M.x=1),R&&(M.y=1)),this.info.isCreating||this.updateCursor({dragHandle:v,isFlippedX:M.x<0,isFlippedY:M.y<0,rotation:d});for(const D of o.keys()){const V=o.get(D);this.editor.resizeShape(D,M,{initialShape:V.shape,initialBounds:V.bounds,initialPageTransform:V.pageTransform,dragHandle:v,mode:c.length===1&&D===c[0]?"resize_bounds":"scale_shape",scaleOrigin:P,isAspectRatioLocked:f,scaleAxisRotation:d,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:D,children:V}of s){if(!V.length)continue;const L=o.get(D).shape,U=this.editor.getShape(D);if(!(L&&U))continue;const K=U.x-L.x,F=U.y-L.y,$=new C(K,F).rot(-L.rotation);if($.x!==0||$.y!==0)for(const W of V)this.editor.updateShape({id:W.id,type:W.type,x:W.x-$.x,y:W.y-$.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:D}of s)if(D.length)for(const V of D)this.editor.updateShape({id:V.id,type:V.type,x:V.x,y:V.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:s,rotation:o}){const i={...this.editor.getInstanceState().cursor};switch(t){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 t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:s}}=this.editor,o=this.editor.getSelectionRotatedPageBounds(),i=C.RotWith(o.getHandlePoint(this.info.handle),o.point,r),a=C.Sub(s,i),c=new Map,d=[];t.forEach(f=>{const g=this.editor.getShape(f);if(g){if(g.type==="frame"&&d.push({id:f,children:Ye(this.editor.getSortedChildIdsForParent(g).map(y=>this.editor.getShape(y)))}),c.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")&&t.length===1)return;this.editor.visitDescendants(g.id,y=>{const S=this.editor.getShape(y);if(S&&(c.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const h=![...c.values()].some(f=>!aA(f.pageRotation,r)||f.isAspectRatioLocked);return{shapeSnapshots:c,selectionBounds:o,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:h,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:d}}_createShapeSnapshot(t){const r=this.editor.getShapePageTransform(t),s=this.editor.getShapeUtil(t);return{shape:t,bounds:this.editor.getShapeGeometry(t).bounds,pageTransform:r,pageRotation:me.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(t)}}}j(NF,"id","resizing");const iw=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function Nk(n,e){e=e%St;const t=Math.round(e/(pt/4)),r=iw.indexOf(n);return iw[(r+t)%iw.length]}const $k=Math.PI/180;class $F extends Re{constructor(){super(...arguments);j(this,"snapshot",{});j(this,"info",{});j(this,"markId","")}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=fR({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});of({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:Nc[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 t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});of({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:Nc[this.info.handle],rotation:t+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(){of({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),jt(this.editor,this.snapshot.shapeSnapshots.map(t=>t.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)}_getRotationFromPointerPosition({snapToNearestDegree:t}){const r=this.editor.getSelectionRotation(),s=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:o,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialShapesRotation:c}=this.snapshot;if(!s)return c;const h=s.center.clone().rotWith(s.point,r).angle(i)-a;let f=c+h;if(o)f=Lf(f,24);else if(t&&(f=Math.round(f/$k)*$k,this.editor.getInstanceState().isCoarsePointer)){const g=Lf(f,4),y=ef(f,g);Math.abs(y)<E8(5)&&(f=g)}return f-c}}j($F,"id","rotating");class zF extends Re{constructor(){super(...arguments);j(this,"hits",new Set);j(this,"size",0);j(this,"scribbleId","id");j(this,"initialSelectedShapeIds",new Set);j(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 t=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=t.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:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)}updateScribbleSelection(t){const{editor:r}=this,s=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{shiftKey:o,originPagePoint:i,previousPagePoint:a,currentPagePoint:c}}=this.editor,{newlySelectedShapeIds:d,initialSelectedShapeIds:h}=this;t&&this.pushPointToScribble();const f=s;let g,y,S,v;const w=0;for(let k=0,E=f.length;k<E;k++){if(g=f[k],r.isShapeOfType(g,"group")||d.has(g.id)||r.isShapeOrAncestorLocked(g)||(y=r.getShapeGeometry(g),r.isShapeOfType(g,"frame")&&y.bounds.containsPoint(r.getPointInShapeSpace(g,i))))continue;const M=r.getShapePageTransform(g);if(!y||!M)continue;const A=M.clone().invert();S=A.applyToPoint(a),v=A.applyToPoint(c);const{bounds:R}=y;if(!(R.minX-w>Math.max(S.x,v.x)||R.minY-w>Math.max(S.y,v.y)||R.maxX+w<Math.min(S.x,v.x)||R.maxY+w<Math.min(S.y,v.y))&&y.hitTestLineSegment(S,v,w)){const D=this.editor.getOutermostSelectableShape(g),V=this.editor.getShapeMask(D.id);if(V&&Kb(a,c,V)!==null&&!Jr(c,V))continue;d.add(D.id)}}const b=r.getSelectedShapeIds(),P=new Set(o?[...d,...h]:[...d]);(b.length!==P.size||b.some(k=>!P.has(k)))&&this.editor.setSelectedShapes(Array.from(P))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}j(zF,"id","scribble_brushing");var Fte=Object.create,BF=Object.defineProperty,Nte=Object.getOwnPropertyDescriptor,$te=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),UF=n=>{throw TypeError(n)},HF=(n,e,t)=>e in n?BF(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,zte=n=>[,,,Fte(null)],KF=["class","method","getter","setter","accessor","field","value","get","set"],WF=n=>n!==void 0&&typeof n!="function"?UF("Function expected"):n,Bte=(n,e,t,r,s)=>({kind:KF[n],name:e,metadata:r,addInitializer:o=>t._?UF("Already initialized"):s.push(WF(o||null))}),Ute=(n,e)=>HF(e,$te("metadata"),n[3]),Hte=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Kte=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=KF[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,Nte(s,t)),b=r.length-1;b>=0;b--)c=Bte(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,WF(i)&&(w[S]=i);return w&&BF(s,t,w),s},aw=(n,e,t)=>HF(n,typeof e!="symbol"?e+"":e,t),GF,xm;const Wte=20,Gte=100;GF=[Dr];class aP{constructor(e){this.editor=e,Hte(xm,5,this),aw(this,"prevDroppingShapeId",null),aw(this,"droppingNodeTimer",null),aw(this,"first",!0),e.disposables.add(this.dispose)}updateDroppingNode(e,t){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,Wte,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Gte,t))}setDragTimer(e,t,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.run(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,e,r)}),this.droppingNodeTimer=null},t)}handleDrag(e,t,r){var c,d,h,f,g;t=Ye(t.map(y=>this.editor.getShape(y.id)));const s=((c=this.editor.getDroppingOverShape(e,t))==null?void 0:c.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(t);return}const{prevDroppingShapeId:o}=this,i=o&&this.editor.getShape(o),a=s&&this.editor.getShape(s);i&&((h=(d=this.editor.getShapeUtil(i)).onDragShapesOut)==null||h.call(d,i,t)),a&&((g=(f=this.editor.getShapeUtil(a)).onDragShapesOver)==null||g.call(f,a,t)),this.hintParents(t),r==null||r(),this.prevDroppingShapeId=s}hintParents(e){const t=new Map;for(const s of e){const o=this.editor.findShapeAncestor(s,i=>i.type!=="group");o&&(t.has(o.id)||t.set(o.id,[]),t.get(o.id).push(s.id))}const r=[];for(const[s,o]of t){const i=this.editor.getShape(s);i&&qL(this.editor,i).length<o.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,s;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),t){const o=this.editor.getShape(t);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()}}xm=zte();Kte(xm,1,"dispose",GF,aP);Ute(xm,aP);var Vte=Object.create,VF=Object.defineProperty,qte=Object.getOwnPropertyDescriptor,qF=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),YF=n=>{throw TypeError(n)},XF=(n,e,t)=>e in n?VF(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Yte=n=>[,,,Vte((n==null?void 0:n[qF("metadata")])??null)],ZF=["class","method","getter","setter","accessor","field","value","get","set"],QF=n=>n!==void 0&&typeof n!="function"?YF("Function expected"):n,Xte=(n,e,t,r,s)=>({kind:ZF[n],name:e,metadata:r,addInitializer:o=>t._?YF("Already initialized"):s.push(QF(o||null))}),Zte=(n,e)=>XF(e,qF("metadata"),n[3]),Qte=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Jte=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=ZF[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,qte(s,t)),b=r.length-1;b>=0;b--)c=Xte(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,QF(i)&&(w[S]=i);return w&&VF(s,t,w),s},ta=(n,e,t)=>XF(n,typeof e!="symbol"?e+"":e,t),JF,$0,wm;class bm extends($0=Re,JF=[Dr],$0){constructor(){super(...arguments),Qte(wm,5,this),ta(this,"info",{}),ta(this,"selectionSnapshot",{}),ta(this,"snapshot",{}),ta(this,"markId",""),ta(this,"isCloning",!1),ta(this,"isCreating",!1),ta(this,"dragAndDropManager",new aP(this.editor))}onCreate(e){}onEnter(e){var o;const{isCreating:t=!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=t,this.markId="",t)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=zk(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:t}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),t.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=zk(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),jt(this.editor,this.snapshot.movingShapes.map(t=>t.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,t=[];e.forEach(r=>{var i;const s=this.editor.getShapeUtil(r),o=(i=s.onTranslateStart)==null?void 0:i.call(s,r);o&&t.push(o)}),t.length>0&&this.editor.updateShapes(t),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:e}=this.snapshot;if(this.isCloning&&e.length>0){const r=C.Average(e.map(o=>this.editor.getShapePageTransform(o.id).point())),s=C.Sub(r,this.selectionSnapshot.averagePagePoint);C.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(o=>o.id),offset:{x:s.x,y:s.y}}})}const t=[];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&&t.push(i)}),t.length>0&&this.editor.updateShapes(t)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),ene({editor:this.editor,snapshot:e});const{movingShapes:t}=e,r=[];t.forEach(s=>{var c;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(c=i.onTranslate)==null?void 0:c.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateParentTransforms(){const{editor:e,snapshot:{shapeSnapshots:t}}=this;t.forEach(r=>{const s=e.getShape(r.shape.id);if(!s)return null;const o=Er(s.parentId)?null:me.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=o})}}wm=Yte($0);Jte(wm,1,"updateParentTransforms",JF,bm);Zte(wm,bm);ta(bm,"id","translating");function zk(n){var f;const e=[],t=[],r=n.getSelectedShapeIds(),s=Ye(r.map(g=>{const y=n.getShape(g);if(!y)return null;e.push(y);const S=n.getShapePageTransform(g),v=S.point(),w=S.rotation();t.push(v);const b=ss.isId(y.parentId)?null:me.Inverse(n.getShapePageTransform(y.parentId));return{shape:y,pagePoint:v,pageRotation:w,parentTransform:b}})),o=n.getOnlySelectedShape();let i=[];if(o)i=n.snaps.shapeBounds.getSnapPoints(o.id);else{const g=n.getSelectionPageBounds();g&&(i=g.cornersAndCenter.map((y,S)=>({id:"selection:"+S,x:y.x,y:y.y})))}let a,c;const{originPagePoint:d}=n.inputs,h=s.filter(g=>n.isShapeOfType(g.shape,"note")&&n.isPointInShape(g.shape,d));if(h.length!==0)if(h.length===1)c=h[0];else{const g=n.getCurrentPageShapesSorted();c=(f=h.map(y=>({snapshot:y,index:g.findIndex(S=>S.id===y.shape.id)})).sort((y,S)=>S.index-y.index)[0])==null?void 0:f.snapshot}return c&&(a=eF(n,c.pageRotation,c.shape.props.scale,c.shape.props.growY??0)),{averagePagePoint:C.Average(t),movingShapes:e,shapeSnapshots:s,initialPageBounds:n.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:c}}function ene({editor:n,snapshot:e}){const{inputs:t}=n,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:o,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:c}=e,d=n.getInstanceState().isGridMode,h=n.getDocumentSettings().gridSize,f=C.Sub(t.currentPagePoint,t.originPagePoint),g=n.inputs.shiftKey?Math.abs(f.x)<Math.abs(f.y)?"x":"y":null;g==="x"?f.x=0:g==="y"&&(f.y=0),n.snaps.clearIndicators();const y=n.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey;let S=!1;if(y&&n.inputs.pointerVelocity.len()<.5){const{nudge:P}=n.snaps.shapeBounds.snapTranslateShapes({dragDelta:f,initialSelectionPageBounds:o,lockedAxis:g,initialSelectionSnapPoints:i});f.add(P)}else if(r&&s){const{scale:P}=r.shape.props,k=r.pagePoint.clone().add(f).add(mm.clone().mul(P).rot(r.pageRotation));let E=Q5/n.getZoomLevel(),M=new C(0,0);for(const A of s){const R=C.Sub(k,A),D=R.len();D<E&&(S=!0,E=D,M=R)}f.sub(M)}const v=C.Add(c,f),w=n.snaps.getIndicators();d&&!t.ctrlKey&&!S&&w.length===0&&v.snapToGrid(h);const b=C.Sub(v,c);n.updateShapes(Ye(a.map(({shape:P,pagePoint:k,parentTransform:E})=>{const M=C.Add(k,b),A=E?me.applyToPoint(E,M):M;return{id:P.id,type:P.type,x:A.x,y:A.y}})))}class Ef extends Re{constructor(){super(...arguments);j(this,"reactor")}static children(){return[N0,oP,Rte,RF,FF,bm,PF,zF,iP,LF,CF,AF,NF,$F,DF,jF,OF,kF]}cleanUpDuplicateProps(){const t=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const s=new Set(r.duplicateProps.shapeIds);t.length===s.size&&t.every(o=>s.has(o))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=To("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(t){console.error(t)}})}onExit(){var t;(t=this.reactor)==null||t.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}j(Ef,"id","select"),j(Ef,"initial","idle"),j(Ef,"isLockable",!1);class eN extends Re{constructor(){super(...arguments);j(this,"info",{})}onEnter(t){this.info=t}onPointerDown(){this.parent.transition("pointing",this.info)}}j(eN,"id","idle");class tN extends Re{constructor(){super(...arguments);j(this,"info",{})}onEnter(t){this.info=t}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){const{currentScreenPoint:t}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(t,{animation:{duration:220}}):this.editor.zoomIn(t,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}j(tN,"id","pointing");class nN extends Re{constructor(){super(...arguments);j(this,"info",{});j(this,"zoomBrush",new Se)}onEnter(t){this.info=t,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){const{inputs:{originPagePoint:t,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Se.FromPoints([t,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:t}=this,r=8/this.editor.getZoomLevel();if(t.width<r&&t.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(t,{targetZoom:s,animation:{duration:220}})}this.parent.transition("idle",this.info)}}j(nN,"id","zoom_brushing");class Tf extends Re{constructor(){super(...arguments);j(this,"info",{})}static children(){return[eN,nN,tN]}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.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(t){this.updateCursor(),t.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})}}j(Tf,"id","zoom"),j(Tf,"initial","idle"),j(Tf,"isLockable",!1);const tne=[Cf,_f,If,Tf,Ef];function nne(){const n=te(),e=se("follow",()=>n.getInstanceState().followingUserId,[n]);return e?p.jsx(rne,{userId:e}):null}function rne({userId:n}){const e=Mg(n);return e?p.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let z0={fonts:{draw:`${ia()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${ia()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${ia()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${ia()}/fonts/IBMPlexMono-Medium.woff2`}};function rN(n){return _.useMemo(()=>n?{fonts:{...z0.fonts,...n==null?void 0:n.fonts}}:z0,[n])}const sne=["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 qu={...z0,icons:Object.fromEntries(sne.map(n=>[n,`${ia()}/icons/icon/0_merged.svg#${n}`])),translations:Object.fromEntries(Cd.map(n=>[n.locale,`${ia()}/translations/${n.locale}.json`])),embedIcons:Object.fromEntries($1.map(n=>[n.type,`${ia()}/embed-icons/${n.type}.png`]))};function one(n){return n?{fonts:Object.assign({...qu.fonts},{...n==null?void 0:n.fonts}),icons:Object.assign({...qu.icons},{...n==null?void 0:n.icons}),embedIcons:Object.assign({...qu.embedIcons},{...n==null?void 0:n.embedIcons}),translations:Object.assign({...qu.translations},{...n==null?void 0:n.translations})}:qu}var lP="Popover",[sN,Die]=Uo(lP,[Qg]),lh=Qg(),[ine,Ia]=sN(lP),oN=n=>{const{__scopePopover:e,children:t,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=n,a=lh(e),c=_.useRef(null),[d,h]=_.useState(!1),[f=!1,g]=Ca({prop:r,defaultProp:s,onChange:o});return p.jsx(m1,{...a,children:p.jsx(ine,{scope:e,contentId:yi(),triggerRef:c,open:f,onOpenChange:g,onOpenToggle:_.useCallback(()=>g(y=>!y),[g]),hasCustomAnchor:d,onCustomAnchorAdd:_.useCallback(()=>h(!0),[]),onCustomAnchorRemove:_.useCallback(()=>h(!1),[]),modal:i,children:t})})};oN.displayName=lP;var iN="PopoverAnchor",ane=_.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Ia(iN,t),o=lh(t),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=s;return _.useEffect(()=>(i(),()=>a()),[i,a]),p.jsx(y1,{...o,...r,ref:e})});ane.displayName=iN;var aN="PopoverTrigger",lN=_.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Ia(aN,t),o=lh(t),i=Ot(e,s.triggerRef),a=p.jsx(ut.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":pN(s.open),...r,ref:i,onClick:Ae(n.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:p.jsx(y1,{asChild:!0,...o,children:a})});lN.displayName=aN;var cP="PopoverPortal",[lne,cne]=sN(cP,{forceMount:void 0}),cN=n=>{const{__scopePopover:e,forceMount:t,children:r,container:s}=n,o=Ia(cP,e);return p.jsx(lne,{scope:e,forceMount:t,children:p.jsx(no,{present:t||o.open,children:p.jsx(rh,{asChild:!0,container:s,children:r})})})};cN.displayName=cP;var $c="PopoverContent",uN=_.forwardRef((n,e)=>{const t=cne($c,n.__scopePopover),{forceMount:r=t.forceMount,...s}=n,o=Ia($c,n.__scopePopover);return p.jsx(no,{present:r||o.open,children:o.modal?p.jsx(une,{...s,ref:e}):p.jsx(dne,{...s,ref:e})})});uN.displayName=$c;var une=_.forwardRef((n,e)=>{const t=Ia($c,n.__scopePopover),r=_.useRef(null),s=Ot(e,r),o=_.useRef(!1);return _.useEffect(()=>{const i=r.current;if(i)return S1(i)},[]),p.jsx(tm,{as:cl,allowPinchZoom:!0,children:p.jsx(dN,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ae(n.onCloseAutoFocus,i=>{var a;i.preventDefault(),o.current||(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Ae(n.onPointerDownOutside,i=>{const a=i.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,d=a.button===2||c;o.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:Ae(n.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),dne=_.forwardRef((n,e)=>{const t=Ia($c,n.__scopePopover),r=_.useRef(!1),s=_.useRef(!1);return p.jsx(dN,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=n.onCloseAutoFocus)==null||i.call(n,o),o.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var c,d;(c=n.onInteractOutside)==null||c.call(n,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((d=t.triggerRef.current)==null?void 0:d.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),dN=_.forwardRef((n,e)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:h,...f}=n,g=Ia($c,t),y=lh(t);return i1(),p.jsx(qg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:p.jsx(th,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:h,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:p.jsx(b3,{"data-state":pN(g.open),role:"dialog",id:g.contentId,...y,...f,ref:e,style:{...f.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)"}})})})}),hN="PopoverClose",hne=_.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Ia(hN,t);return p.jsx(ut.button,{type:"button",...r,ref:e,onClick:Ae(n.onClick,()=>s.onOpenChange(!1))})});hne.displayName=hN;var pne="PopoverArrow",fne=_.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=lh(t);return p.jsx(P3,{...s,...r,ref:e})});fne.displayName=pne;function pN(n){return n?"open":"closed"}var uP=oN,dP=lN,hP=cN,pP=uN;function fP({id:n,children:e,onOpenChange:t,open:r}){const[s,o]=Ei(n,t);return p.jsx(uP,{onOpenChange:o,open:r||s,children:p.jsx("div",{className:"tlui-popover",children:e})})}function gP({children:n}){return p.jsx(dP,{asChild:!0,dir:"ltr",children:n})}function mP({side:n,children:e,align:t="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:o=!1}){const i=fn();return p.jsx(hP,{container:i,children:p.jsx(pP,{className:"tlui-popover__content",side:n,sideOffset:r,align:t,alignOffset:s,dir:"ltr",onEscapeKeyDown:a=>o&&a.preventDefault(),children:e})})}function gne(n){return n.getSelectedShapeIds().map(r=>n.getShape(r)).filter(r=>{if(!r)return!1;if(n.isShapeOfType(r,"arrow")){const s=Rr(n,r);if(s.start||s.end)return!1}return!0})}const fN=()=>{const n=te();return se("threeStackableItems",()=>gne(n).length>2,[n])},Ti=()=>{const n=te();return se("isInSelectState",()=>n.isIn("select"),[n])},gN=()=>{const n=te();return se("allow group",()=>{const e=n.getSelectedShapes();if(e.length<2)return!1;for(const t of e)if(n.isShapeOfType(t,"arrow")){const r=Rr(n,t);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},[n])},mN=()=>{const n=te();return se("allowUngroup",()=>n.getSelectedShapeIds().some(e=>{var t;return((t=n.getShape(e))==null?void 0:t.type)==="group"}),[n])},mne=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function yN(n,e){const t=te();return se("selectedShapes",()=>t.getSelectedShapes().length>=n,[t,n,e])}function dr(n,e){const t=te();return se("selectedShapes",()=>{const r=t.getSelectedShapes().filter(s=>!t.isShapeOrAncestorLocked(s)).length;return n===void 0?r:r>=n},[t])}function yne(){const n=te();return se("showAutoSizeToggle",()=>{const e=n.getSelectedShapes();return e.length===1&&n.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[n])}function SN(){const n=te();return se("hasLinkShapeSelected",()=>{const e=n.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[n])}function Sne(){const n=te();return se("onlyFlippableShape",()=>{const e=n.getOnlySelectedShape();return e&&(n.isShapeOfType(e,"group")||n.isShapeOfType(e,"image")||n.isShapeOfType(e,"arrow")||n.isShapeOfType(e,"line")||n.isShapeOfType(e,"draw"))},[n])}function vN(){const n=te();return se("useCanRedo",()=>n.getCanRedo(),[n])}function xN(){const n=te();return se("useCanUndo",()=>n.getCanUndo(),[n])}function vne(){return p.jsxs(p.Fragment,{children:[p.jsx(xne,{}),p.jsx(wne,{}),p.jsx(bne,{}),p.jsx(Pne,{}),p.jsx(Cne,{}),p.jsx(Ene,{}),p.jsx(Tne,{}),p.jsx(kne,{})]})}function xne(){const n=dr(2),e=Ti(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"align-left",disabled:!t}),p.jsx(ce,{actionId:"align-center-horizontal",disabled:!t}),p.jsx(ce,{actionId:"align-right",disabled:!t}),p.jsx(ce,{actionId:"stretch-horizontal",disabled:!t}),p.jsx(ce,{actionId:"align-top",disabled:!t}),p.jsx(ce,{actionId:"align-center-vertical",disabled:!t}),p.jsx(ce,{actionId:"align-bottom",disabled:!t}),p.jsx(ce,{actionId:"stretch-vertical",disabled:!t})]})}function wne(){const n=dr(3),e=Ti(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"distribute-horizontal",disabled:!t}),p.jsx(ce,{actionId:"distribute-vertical",disabled:!t})]})}function bne(){const n=fN(),e=Ti(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"stack-horizontal",disabled:!t}),p.jsx(ce,{actionId:"stack-vertical",disabled:!t})]})}function Pne(){const n=dr(1),e=Ti(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"send-to-back",disabled:!t}),p.jsx(ce,{actionId:"send-backward",disabled:!t}),p.jsx(ce,{actionId:"bring-forward",disabled:!t}),p.jsx(ce,{actionId:"bring-to-front",disabled:!t})]})}function Cne(){return ur()<Jt.TABLET_SM?p.jsx(_ne,{}):p.jsx(Ine,{})}function _ne(){const n=te(),e=se("zoom is 1",()=>n.getZoomLevel()===1,[n]);return p.jsx(ce,{actionId:"zoom-to-100",disabled:e})}function Ine(){const n=dr(1),e=Ti(),t=n&&e;return p.jsx(ce,{actionId:"rotate-ccw",disabled:!t})}function Ene(){const n=dr(1),e=Ti(),t=n&&e;return p.jsx(ce,{actionId:"rotate-cw",disabled:!t})}function Tne(){const n=SN(),e=Ti(),t=n&&e;return p.jsx(ce,{actionId:"edit-link",disabled:!t})}function kne(){const n=gN(),e=mN();return n?p.jsx(Bk,{}):e?p.jsx(Mne,{}):p.jsx(Bk,{})}function Bk(){const n=dr(2),e=Ti(),t=n&&e;return p.jsx(ce,{actionId:"group",disabled:!t})}function Mne(){return p.jsx(ce,{actionId:"ungroup"})}const Ane=_.memo(function({children:e}){const t=it(),r=ur(),s=is(),o=_.useRef(null);Pa(o);const i=te(),a=se("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),c=e??p.jsx(vne,{});if(!(s&&!a))return p.jsxs(fP,{id:"actions-menu",children:[p.jsx(gP,{children:p.jsx(Ne,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:p.jsx(nt,{icon:"dots-vertical",small:!0})})}),p.jsx(mP,{side:r>=Jt.TABLET?"bottom":"top",sideOffset:6,children:p.jsx("div",{ref:o,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:p.jsx(Es,{type:"icons",sourceId:"actions-menu",children:c})})})]})});function wN(){return yne()?p.jsx(ce,{actionId:"toggle-auto-size"}):null}function bN(){return SN()?p.jsx(ce,{actionId:"edit-link"}):null}function jne(){return dr(1)?p.jsx(ce,{actionId:"duplicate"}):null}function PN(){const n=te();return se("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const r=n.getOnlySelectedShape();return!(r&&n.isShapeOfType(r,"image"))},[n])?p.jsx(ce,{actionId:"flatten-to-image"}):null}function CN(){return gN()?p.jsx(ce,{actionId:"group"}):null}function _N(){return mN()?p.jsx(ce,{actionId:"ungroup"}):null}function IN(){const n=te();return se("allow unframe",()=>{const t=n.getSelectedShapes();return t.length===0?!1:t.every(r=>n.isShapeOfType(r,"frame"))},[n])?p.jsx(ce,{actionId:"remove-frame"}):null}function EN(){const n=te();return se("allow fit frame to content",()=>{const t=n.getOnlySelectedShape();return t?n.isShapeOfType(t,"frame")&&n.getSortedChildIdsForParent(t).length>0:!1},[n])?p.jsx(ce,{actionId:"fit-frame-to-content"}):null}function TN(){const n=te();return se("selected shapes",()=>n.getSelectedShapes().length>0,[n])?p.jsx(ce,{actionId:"toggle-lock"}):null}function yP(){const n=te(),e=se("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return p.jsx(so,{actionId:"toggle-transparent",checked:e,toggle:!0})}function Rne(){const n=te(),e=se("any shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(ce,{actionId:"unlock-all",disabled:!e})}function kN(){const n=te(),e=se("zoomed to 100",()=>n.getZoomLevel()===1,[n]);return p.jsx(ce,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function MN(){const n=te(),e=se("has shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(ce,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function AN(){const n=te(),e=se("has shapes",()=>n.getSelectedShapeIds().length>0,[n]);return p.jsx(ce,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function jN(){return p.jsxs(Qe,{id:"clipboard",children:[p.jsx(Dne,{}),p.jsx(Lne,{}),p.jsx(Fne,{}),p.jsx(jne,{}),p.jsx(Nne,{})]})}function One(){var t;const n=te(),e=se("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsxs(zr,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[p.jsxs(Qe,{id:"copy-as-group",children:[p.jsx(ce,{actionId:"copy-as-svg"}),!!((t=window.navigator.clipboard)!=null&&t.write)&&p.jsx(ce,{actionId:"copy-as-png"})]}),p.jsx(Qe,{id:"copy-as-bg",children:p.jsx(yP,{})})]})}function Dne(){const n=dr(1);return p.jsx(ce,{actionId:"cut",disabled:!n})}function Lne(){const n=yN(1);return p.jsx(ce,{actionId:"copy",disabled:!n})}function Fne(){const n=mne;return p.jsx(ce,{actionId:"paste",disabled:!n})}function RN(){const n=te();return se("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n])?p.jsxs(Qe,{id:"conversions",children:[p.jsx(One,{}),p.jsxs(zr,{id:"export-as",label:"context-menu.export-as",size:"small",children:[p.jsxs(Qe,{id:"export-as-group",children:[p.jsx(ce,{actionId:"export-as-svg"}),p.jsx(ce,{actionId:"export-as-png"})]}),p.jsx(Qe,{id:"export-as-bg",children:p.jsx(yP,{})})]})]}):null}function ON(){const n=te(),e=se("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(ce,{actionId:"select-all",disabled:!e})}function Nne(){const n=dr(1);return p.jsx(ce,{actionId:"delete",disabled:!n})}function $ne(){const n=is();return!yN(1)||n?null:p.jsxs(zr,{id:"edit",label:"context-menu.edit",size:"small",children:[p.jsx(CN,{}),p.jsx(_N,{}),p.jsx(PN,{}),p.jsx(bN,{}),p.jsx(EN,{}),p.jsx(IN,{}),p.jsx(LN,{}),p.jsx(DN,{}),p.jsx(wN,{}),p.jsx(TN,{})]})}function zne(){const n=dr(2),e=Sne();return is()||!(n||e)?null:p.jsxs(zr,{id:"arrange",label:"context-menu.arrange",size:"small",children:[n&&p.jsxs(Qe,{id:"align",children:[p.jsx(ce,{actionId:"align-left"}),p.jsx(ce,{actionId:"align-center-horizontal"}),p.jsx(ce,{actionId:"align-right"}),p.jsx(ce,{actionId:"align-top"}),p.jsx(ce,{actionId:"align-center-vertical"}),p.jsx(ce,{actionId:"align-bottom"})]}),p.jsx(Bne,{}),n&&p.jsxs(Qe,{id:"stretch",children:[p.jsx(ce,{actionId:"stretch-horizontal"}),p.jsx(ce,{actionId:"stretch-vertical"})]}),(n||e)&&p.jsxs(Qe,{id:"flip",children:[p.jsx(ce,{actionId:"flip-horizontal"}),p.jsx(ce,{actionId:"flip-vertical"})]}),p.jsx(Une,{})]})}function Bne(){return dr(3)?p.jsxs(Qe,{id:"distribute",children:[p.jsx(ce,{actionId:"distribute-horizontal"}),p.jsx(ce,{actionId:"distribute-vertical"})]}):null}function Une(){const n=dr(2),e=fN();return n?p.jsxs(Qe,{id:"order",children:[p.jsx(ce,{actionId:"pack"}),e&&p.jsx(ce,{actionId:"stack-horizontal"}),e&&p.jsx(ce,{actionId:"stack-vertical"})]}):null}function Hne(){const n=is(),e=dr(1);return n||!e?null:p.jsx(zr,{id:"reorder",label:"context-menu.reorder",size:"small",children:p.jsxs(Qe,{id:"reorder",children:[p.jsx(ce,{actionId:"bring-to-front"}),p.jsx(ce,{actionId:"bring-forward"}),p.jsx(ce,{actionId:"send-backward"}),p.jsx(ce,{actionId:"send-to-back"})]})})}function Kne(){const n=te(),e=se("pages",()=>n.getPages(),[n]),t=se("current page id",()=>n.getCurrentPageId(),[n]),{addToast:r}=Ii(),s=On(),o=is();return!dr(1)||o?null:p.jsxs(zr,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[p.jsx(Qe,{id:"pages",children:e.map(a=>p.jsx(En,{id:a.id,disabled:t===a.id,label:a.name.length>30?`${a.name.slice(0,30)}…`:a.name,onSelect:()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.moveShapesToPage(n.getSelectedShapeIds(),a.id);const c=n.getPage(a.id);c&&r({title:"Changed Page",description:`Moved to ${c.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{n.markHistoryStoppingPoint("change-page"),n.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),p.jsx(Qe,{id:"new-page",children:p.jsx(ce,{actionId:"move-to-new-page"})})]})}function DN(){const n=te();return se("oneEmbedSelected",()=>{const t=n.getOnlySelectedShape();return t?!!(n.isShapeOfType(t,"embed")&&t.props.url&&!n.isShapeOrAncestorLocked(t)):!1},[n])?p.jsx(ce,{actionId:"convert-to-bookmark"}):null}function LN(){const n=te(),e=z1();return se("oneEmbeddableBookmarkSelected",()=>{const r=n.getOnlySelectedShape();return r?!!(n.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!n.isShapeOrAncestorLocked(r)):!1},[n])?p.jsx(ce,{actionId:"convert-to-embed"}):null}function Wne(){const n=te(),e=se("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return p.jsx(so,{actionId:"toggle-snap-mode",checked:e})}function Gne(){const n=te(),e=se("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return p.jsx(so,{actionId:"toggle-tool-lock",checked:e})}function Vne(){const n=te(),e=se("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return p.jsx(so,{actionId:"toggle-grid",checked:e})}function qne(){const n=te(),e=se("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return p.jsx(so,{actionId:"toggle-wrap-mode",checked:e})}function Yne(){const n=te(),e=se("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return p.jsx(so,{actionId:"toggle-focus-mode",checked:e})}function Xne(){const n=te(),e=se("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return p.jsx(so,{actionId:"toggle-edge-scrolling",checked:e===1})}function Zne(){const n=te(),e=se("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return p.jsx(so,{actionId:"toggle-reduce-motion",checked:e===0})}function Qne(){const n=te(),e=se("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return p.jsx(so,{actionId:"toggle-debug-mode",checked:e})}function Jne(){const n=te(),e=se("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return p.jsx(so,{actionId:"toggle-dynamic-size-mode",checked:e})}function ere(){const n=te(),e=se("paste at cursor",()=>n.user.getIsPasteAtCursorMode(),[n]);return p.jsx(so,{actionId:"toggle-paste-at-cursor",checked:e})}function tre(){const n=te();return se("show cursor chat",()=>n.getCurrentToolId()==="select"&&!n.getInstanceState().isCoarsePointer,[n])?p.jsx(ce,{actionId:"open-cursor-chat"}):null}function nre(){const n=te(),e=cm(),t=se("isSelectToolActive",()=>n.getCurrentToolId()==="select",[n]),r=se("isSinglePageMode",()=>n.options.maxPages<=1,[n]);return t?p.jsxs(p.Fragment,{children:[e&&p.jsx(tre,{}),p.jsxs(Qe,{id:"modify",children:[p.jsx($ne,{}),p.jsx(zne,{}),p.jsx(Hne,{}),!r&&p.jsx(Kne,{})]}),p.jsx(jN,{}),p.jsx(RN,{}),p.jsx(Qe,{id:"select-all",children:p.jsx(ON,{})})]}):null}const rre=_.memo(function({children:e,disabled:t=!1}){const r=te(),{Canvas:s}=$t(),o=_.useCallback(h=>{if(h){if(r.getInstanceState().isCoarsePointer){const f=r.getSelectedShapes(),{inputs:{currentPagePoint:g}}=r,y=r.getShapesAtPoint(g);if(!r.getSelectedShapes().length||!y.some(S=>f.includes(S))){const S=y.filter(v=>r.isShapeOrAncestorLocked(v));S.length&&r.select(...S.map(v=>v.id))}}}else{const f=r.getOnlySelectedShape();f&&r.isShapeOrAncestorLocked(f)&&r.setSelectedShapes([])}},[r]),i=fn(),[a,c]=Ei("context menu",o),d=e??p.jsx(nre,{});return p.jsxs(JY,{dir:"ltr",onOpenChange:c,modal:!1,children:[p.jsx(eX,{onContextMenu:void 0,dir:"ltr",disabled:t,children:s?p.jsx(s,{}):null}),a&&p.jsx(tX,{container:i,children:p.jsx(nX,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Je,children:p.jsx(Es,{type:"context-menu",sourceId:"context-menu",children:d})})})]})}),sre=2e3,ore=5e3,ire=jn(function(){const e=te(),{isChatting:t,chatMessage:r}=e.getInstanceState(),s=_.useRef(-1),[o,i]=_.useState("");return _.useEffect(()=>{if(!t&&r||t){const c=t?ore:sre;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},c)}return()=>{clearTimeout(s.current)}},[e,r,t]),t?p.jsx(lre,{value:o,setValue:i,chatMessage:r}):r.trim()?p.jsx(are,{chatMessage:r}):null});function FN(n){const e=te();_.useLayoutEffect(()=>{var i;if(!n.current)return;const{x:r,y:s}=e.inputs.currentScreenPoint;(i=n.current)==null||i.style.setProperty("transform",`translate(${r}px, ${s}px)`);function o(a){var h;const{minX:c,minY:d}=e.getViewportScreenBounds();(h=n.current)==null||h.style.setProperty("transform",`translate(${a.clientX-c}px, ${a.clientY-d}px)`)}return window.addEventListener("pointermove",o),()=>{window.removeEventListener("pointermove",o)}},[n,e])}const are=({chatMessage:n})=>{const e=te(),t=_.useRef(null);return FN(t),p.jsx("div",{ref:t,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:n})},lre=jn(function({chatMessage:e,value:t,setValue:r}){const s=te(),o=it(),i=_.useRef(null),a=e||o("cursor-chat.type-to-chat");FN(i),_.useLayoutEffect(()=>{const g=i.current;if(!g)return;const y=s.textMeasure.measureText(t||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});g.style.setProperty("width",y.w+"px")},[s,t,a]),_.useLayoutEffect(()=>{const g=s.timers.requestAnimationFrame(()=>{var y;(y=i.current)==null||y.focus()});return()=>{cancelAnimationFrame(g)}},[s]);const c=_.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),d=_.useCallback(g=>{const{value:y}=g.target;r(y.slice(0,64)),s.updateInstanceState({chatMessage:y})},[s,r]),h=_.useCallback(g=>{const y=i.current;if(!y)return;const{value:S}=y;switch(g.key){case"Enter":{if(Je(g),g.stopPropagation(),!S){c();return}r("");break}case"Escape":{Je(g),g.stopPropagation(),c();break}}},[c,r]),f=_.useCallback(g=>{g.stopPropagation()},[]);return p.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:c,onChange:d,onKeyDown:h,onPaste:f,value:t,placeholder:a,spellCheck:!1})});function B0({checked:n}){return p.jsx(Fo,{icon:n?"check":"none",className:"tlui-button__icon",small:!0})}function cre(){const n=te(),{addToast:e}=Ii(),{addDialog:t}=ah(),[r,s]=at.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(Qe,{id:"items",children:[p.jsx(En,{id:"add-toast",onSelect:()=>{e({id:xt(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:xt(),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:xt(),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:xt(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),p.jsx(En,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:o})=>p.jsx(hre,{displayDontShowAgain:!0,onCancel:()=>o(),onContinue:()=>o()}),onClose:()=>{}})}}),p.jsx(En,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>pre(n,100)}),p.jsx(En,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const o=n.getSelectedShapes(),i=o.length===0?n.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})(),p.jsx(En,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"}),p.jsx(En,{id:"hard-reset",onSelect:kj,label:"Hard reset"})]}),p.jsxs(Qe,{id:"flags",children:[p.jsx(ure,{}),p.jsx(dre,{})]})]})}function ure(){const n=Object.values(sn);return n.length?p.jsx(zr,{id:"debug flags",label:"Debug Flags",children:p.jsx(Qe,{id:"debug flags",children:n.map(e=>p.jsx(NN,{flag:e},e.name))})}):null}function dre(){const n=Object.values(PB);return n.length?p.jsx(zr,{id:"feature flags",label:"Feature Flags",children:p.jsx(Qe,{id:"feature flags",children:n.map(e=>p.jsx(NN,{flag:e},e.name))})}):null}function hre({title:n="title",body:e="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:o,onContinue:i}){const[a,c]=at.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(om,{children:[p.jsx(im,{children:n}),p.jsx(am,{})]}),p.jsx(Ad,{style:{maxWidth:350},children:e}),p.jsxs(N1,{className:"tlui-dialog__footer__actions",children:[s&&p.jsxs(Ne,{type:"normal",onClick:()=>c(!a),style:{marginRight:"auto"},children:[p.jsx(B0,{checked:a}),p.jsx(on,{children:"Don’t show again"})]}),p.jsx(Ne,{type:"normal",onClick:o,children:p.jsx(on,{children:t})}),p.jsx(Ne,{type:"primary",onClick:async()=>i(),children:p.jsx(on,{children:r})})]})]})}const NN=jn(function({flag:e,onChange:t}){const r=e.get();return p.jsx(pm,{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),t==null||t(!r)}})});let Uk=0;function pre(n,e){const t=Array(e),r=Math.floor(Math.sqrt(e));for(let s=0;s<e;s++)Uk++,t[s]={id:Ct("box"+Uk),type:"geo",x:s%r*132,y:Math.floor(s/r)*132};n.run(()=>{n.createShapes(t).setSelectedShapes(t.map(s=>s.id))})}function fre({children:n}){const e=n??p.jsx(cre,{});return p.jsxs(hl,{id:"debug",children:[p.jsx(pl,{children:p.jsx(Ne,{type:"icon",title:"Debug menu",children:p.jsx(nt,{icon:"dots-horizontal"})})}),p.jsx(fl,{side:"top",align:"end",alignOffset:0,children:p.jsx(Es,{type:"menu",sourceId:"debug-panel",children:e})})]})}const gre=_.memo(function(){const{DebugMenu:e}=Ea(),t=_.useRef(null);return Pa(t),p.jsxs("div",{ref:t,className:"tlui-debug-panel",children:[p.jsx(yre,{}),p.jsx(Sre,{}),e&&p.jsx(e,{})]})});function mre(n=!0){const[e,t]=_.useState(0),r=te();_.useEffect(()=>{if(!n)return;const s=()=>t(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const yre=jn(function(){mre();const e=te(),t=e.getPath(),r=e.getHoveredShape(),s=e.getOnlySelectedShape(),o=t==="select.idle"||!t.includes("select.")?r:s,i=o&&t.includes("select.")?` / ${o.type||""}${"geo"in o.props?" / "+o.props.geo:""} / [${C.ToInt(e.getPointInShapeSpace(o,e.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${C.ToInt(e.inputs.originPagePoint)}] → [${C.ToInt(e.inputs.currentPagePoint)}] = ${C.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return p.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function Sre(){const n=te(),e=se("show_fps",()=>sn.showFps.get(),[sn]),t=_.useRef(null);return _.useEffect(()=>{if(!e)return;const r=250;let s=0,o=-1,i=performance.now(),a=0,c=0,d=!1;function h(){if(c++,a=performance.now()-i,a>r){const f=Math.round(c*(r/a)*(1e3/r));f>s&&(s=f);const g=s*.75;(f<g&&!d||f>=g&&d)&&(d=!d),t.current.innerHTML=`FPS ${f.toString()}`,t.current.className="tlui-debug-panel__fps"+(d?" tlui-debug-panel__fps__slow":""),a-=r,c=0,i=performance.now()}o=n.timers.requestAnimationFrame(h)}return h(),()=>{cancelAnimationFrame(o)}},[e,n]),e?p.jsx("div",{ref:t}):null}const vre=_.memo(function(){const e=ur(),t=_.useRef(null);Pa(t);const{MainMenu:r,QuickActions:s,ActionsMenu:o,PageMenu:i}=Ea(),a=te(),c=se("isSinglePageMode",()=>a.options.maxPages<=1,[a]),d=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=Jt.TABLET;return!r&&!i&&!d?null:p.jsx("div",{ref:t,className:"tlui-menu-zone",children:p.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&p.jsx(r,{}),i&&!c&&p.jsx(i,{}),d?p.jsxs(p.Fragment,{children:[s&&p.jsx(s,{}),o&&p.jsx(o,{})]}):null]})})});function xre(){const n=te(),e=wl(),[t,r]=_.useState(!1),s=_.useRef(!1);return aa("toggle showback to content",()=>{const o=s.current,i=n.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===n.getCulledShapes().size),o!==a&&(r(a),s.current=a)},[n]),t?p.jsx(ce,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function wre(){const n=te();return se("is pen mode",()=>n.getInstanceState().isPenMode,[n])?p.jsx(ce,{actionId:"exit-pen-mode"}):null}function bre(){const n=te(),e=wl();return se("is following user",()=>!!n.getInstanceState().followingUserId,[n])?p.jsx(En,{...e["stop-following"]}):null}function Pre(){return p.jsxs(p.Fragment,{children:[p.jsx(wre,{}),p.jsx(xre,{}),p.jsx(bre,{})]})}function Cre({children:n}){const e=n??p.jsx(Pre,{});return p.jsx("div",{className:"tlui-helper-buttons",children:p.jsx(Es,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function _re(){const n=cm();return p.jsxs(p.Fragment,{children:[p.jsxs(Qe,{label:"shortcuts-dialog.tools",id:"tools",children:[p.jsx(ce,{actionId:"toggle-tool-lock"}),p.jsx(ce,{actionId:"insert-media"}),p.jsx(Tr,{toolId:"select"}),p.jsx(Tr,{toolId:"draw"}),p.jsx(Tr,{toolId:"eraser"}),p.jsx(Tr,{toolId:"hand"}),p.jsx(Tr,{toolId:"rectangle"}),p.jsx(Tr,{toolId:"ellipse"}),p.jsx(Tr,{toolId:"arrow"}),p.jsx(Tr,{toolId:"line"}),p.jsx(Tr,{toolId:"text"}),p.jsx(Tr,{toolId:"frame"}),p.jsx(Tr,{toolId:"note"}),p.jsx(Tr,{toolId:"laser"}),p.jsx(En,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),p.jsxs(Qe,{label:"shortcuts-dialog.preferences",id:"preferences",children:[p.jsx(ce,{actionId:"toggle-dark-mode"}),p.jsx(ce,{actionId:"toggle-focus-mode"}),p.jsx(ce,{actionId:"toggle-grid"})]}),p.jsxs(Qe,{label:"shortcuts-dialog.edit",id:"edit",children:[p.jsx(ce,{actionId:"undo"}),p.jsx(ce,{actionId:"redo"}),p.jsx(ce,{actionId:"cut"}),p.jsx(ce,{actionId:"copy"}),p.jsx(ce,{actionId:"paste"}),p.jsx(ce,{actionId:"select-all"}),p.jsx(ce,{actionId:"delete"}),p.jsx(ce,{actionId:"duplicate"})]}),p.jsxs(Qe,{label:"shortcuts-dialog.view",id:"view",children:[p.jsx(ce,{actionId:"zoom-in"}),p.jsx(ce,{actionId:"zoom-out"}),p.jsx(ce,{actionId:"zoom-to-100"}),p.jsx(ce,{actionId:"zoom-to-fit"}),p.jsx(ce,{actionId:"zoom-to-selection"})]}),p.jsxs(Qe,{label:"shortcuts-dialog.transform",id:"transform",children:[p.jsx(ce,{actionId:"bring-to-front"}),p.jsx(ce,{actionId:"bring-forward"}),p.jsx(ce,{actionId:"send-backward"}),p.jsx(ce,{actionId:"send-to-back"}),p.jsx(ce,{actionId:"group"}),p.jsx(ce,{actionId:"ungroup"}),p.jsx(ce,{actionId:"flip-horizontal"}),p.jsx(ce,{actionId:"flip-vertical"}),p.jsx(ce,{actionId:"align-top"}),p.jsx(ce,{actionId:"align-center-vertical"}),p.jsx(ce,{actionId:"align-bottom"}),p.jsx(ce,{actionId:"align-left"}),p.jsx(ce,{actionId:"align-center-horizontal"}),p.jsx(ce,{actionId:"align-right"})]}),n&&p.jsx(Qe,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:p.jsx(ce,{actionId:"open-cursor-chat"})})]})}const Ire=_.memo(function({children:e}){const t=it(),r=ur(),s=e??p.jsx(_re,{});return p.jsxs(p.Fragment,{children:[p.jsxs(om,{className:"tlui-shortcuts-dialog__header",children:[p.jsx(im,{children:t("shortcuts-dialog.title")}),p.jsx(am,{})]}),p.jsx(Ad,{className:Le("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=Jt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=Jt.TABLET}),children:p.jsx(Es,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),p.jsx("div",{className:"tlui-dialog__scrim"})]})});function $N(){const n=wa(),e=On(),t=se("locale",()=>n==null?void 0:n.user.getLocale(),[n]);return n?p.jsx(zr,{id:"help menu language",label:"menu.language",children:p.jsx(Qe,{id:"languages",children:Cd.map(({locale:r,label:s})=>p.jsx(pm,{id:`language-${r}`,title:r,label:s,checked:r===t,readonlyOk:!0,onSelect:()=>{n.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})}):null}function Ere(){return p.jsxs(p.Fragment,{children:[p.jsx($N,{}),p.jsx(zN,{})]})}function zN(){const{KeyboardShortcutsDialog:n}=Ea(),{addDialog:e}=ah(),t=_.useCallback(()=>{n&&e({component:n})},[e,n]);return n?p.jsx(En,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:t}):null}function Tre(){return p.jsxs(p.Fragment,{children:[p.jsxs(Qe,{id:"basic",children:[p.jsx(Mre,{}),p.jsx(Ore,{}),p.jsx(kre,{}),p.jsx(Dre,{})]}),p.jsx(Lre,{})]})}function kre(){return p.jsxs(zr,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[p.jsxs(Qe,{id:"export-all-as-group",children:[p.jsx(ce,{actionId:"export-all-as-svg"}),p.jsx(ce,{actionId:"export-all-as-png"})]}),p.jsx(Qe,{id:"export-all-as-bg",children:p.jsx(yP,{})})]})}function Mre(){return p.jsxs(zr,{id:"edit",label:"menu.edit",children:[p.jsx(Rre,{}),p.jsx(jN,{}),p.jsx(RN,{}),p.jsx(Are,{}),p.jsx(jre,{}),p.jsx(Qe,{id:"select-all",children:p.jsx(ON,{})})]})}function Are(){return p.jsxs(Qe,{id:"misc",children:[p.jsx(CN,{}),p.jsx(_N,{}),p.jsx(bN,{}),p.jsx(wN,{}),p.jsx(IN,{}),p.jsx(EN,{}),p.jsx(LN,{}),p.jsx(DN,{}),p.jsx(PN,{})]})}function jre(){return p.jsxs(Qe,{id:"lock",children:[p.jsx(TN,{}),p.jsx(Rne,{})]})}function Rre(){const n=xN(),e=vN();return p.jsxs(Qe,{id:"undo-redo",children:[p.jsx(ce,{actionId:"undo",disabled:!n}),p.jsx(ce,{actionId:"redo",disabled:!e})]})}function Ore(){return p.jsx(zr,{id:"view",label:"menu.view",children:p.jsxs(Qe,{id:"view-actions",children:[p.jsx(ce,{actionId:"zoom-in"}),p.jsx(ce,{actionId:"zoom-out"}),p.jsx(kN,{}),p.jsx(MN,{}),p.jsx(AN,{})]})})}function Dre(){return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"insert-embed"}),p.jsx(ce,{actionId:"insert-media"})]})}function Lre(){return p.jsxs(Qe,{id:"preferences",children:[p.jsxs(zr,{id:"preferences",label:"menu.preferences",children:[p.jsxs(Qe,{id:"preferences-actions",children:[p.jsx(Wne,{}),p.jsx(Gne,{}),p.jsx(Vne,{}),p.jsx(qne,{}),p.jsx(Yne,{}),p.jsx(Xne,{}),p.jsx(Zne,{}),p.jsx(Jne,{}),p.jsx(ere,{}),p.jsx(Qne,{})]}),p.jsx(Qe,{id:"color-scheme",children:p.jsx(OQ,{})})]}),p.jsx($N,{}),p.jsx(zN,{})]})}const Fre=_.memo(function({children:e}){const t=fn(),[r,s]=Ei("main menu"),o=it(),i=e??p.jsx(Tre,{});return p.jsxs(M1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[p.jsx(A1,{asChild:!0,dir:"ltr",children:p.jsx(Ne,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:p.jsx(nt,{icon:"menu",small:!0})})}),p.jsx(sm,{container:t,children:p.jsx(j1,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:p.jsx(Es,{type:"menu",sourceId:"main-menu",children:i})})})]})}),lw={};function Yu(n){if(lw[n])return lw[n];const t=document.createElement("canvas").getContext("2d");t.fillStyle=n,t.fillRect(0,0,1,1);const[r,s,o,i]=t.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,o/255,i/255]);return lw[n]=a,a}const kf=10,BN=4*6*kf+12+4*12;function fc(n,{center:e,radius:t,numArcSegments:r=20,startAngle:s=0,endAngle:o=St,offset:i=0}){const a=(o-s)/r;let c=i;for(let d=s;d<o;d+=a)n[c++]=e.x,n[c++]=e.y,n[c++]=e.x+Math.cos(d)*t,n[c++]=e.y+Math.sin(d)*t,n[c++]=e.x+Math.cos(d+a)*t,n[c++]=e.y+Math.sin(d+a)*t;return n}function gc(n,e,t,r,s,o){n[e++]=t,n[e++]=r,n[e++]=t,n[e++]=r+o,n[e++]=t+s,n[e++]=r,n[e++]=t+s,n[e++]=r,n[e++]=t,n[e++]=r+o,n[e++]=t+s,n[e++]=r+o}function Nre(n,e,t){const r=kf;t=Math.min(t,Math.min(e.w,e.h)/2);const s=Se.ExpandBy(e,-t);if(s.w<=0||s.h<=0)return fc(n,{center:e.center,radius:t,numArcSegments:kf*4}),kf*4*6;let o=0;return gc(n,o,s.minX,s.minY,s.w,s.h),o+=12,gc(n,o,s.minX,e.minY,s.w,t),o+=12,gc(n,o,s.maxX,s.minY,t,s.h),o+=12,gc(n,o,s.minX,s.maxY,s.w,t),o+=12,gc(n,o,e.minX,s.minY,t,s.h),o+=12,fc(n,{numArcSegments:r,offset:o,center:s.point,radius:t,startAngle:pt,endAngle:pt*1.5}),o+=r*6,fc(n,{numArcSegments:r,offset:o,center:C.Add(s.point,new C(s.w,0)),radius:t,startAngle:pt*1.5,endAngle:St}),o+=r*6,fc(n,{numArcSegments:r,offset:o,center:C.Add(s.point,s.size),radius:t,startAngle:0,endAngle:Rt}),o+=r*6,fc(n,{numArcSegments:r,offset:o,center:C.Add(s.point,new C(0,s.h)),radius:t,startAngle:Rt,endAngle:pt}),BN}function $re(n){if(!n)throw new Error("Canvas element not found");const e=n.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const t=`#version 300 es
|
|
382
|
+
precision mediump float;
|
|
383
|
+
|
|
384
|
+
in vec2 shapeVertexPosition;
|
|
385
|
+
|
|
386
|
+
uniform vec4 canvasPageBounds;
|
|
387
|
+
|
|
388
|
+
// taken (with thanks) from
|
|
389
|
+
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
|
|
390
|
+
void main() {
|
|
391
|
+
// convert the position from pixels to 0.0 to 1.0
|
|
392
|
+
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
|
|
393
|
+
|
|
394
|
+
// convert from 0->1 to 0->2
|
|
395
|
+
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
396
|
+
|
|
397
|
+
// convert from 0->2 to -1->+1 (clipspace)
|
|
398
|
+
vec2 clipSpace = zeroToTwo - 1.0;
|
|
399
|
+
|
|
400
|
+
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
401
|
+
}`,r=e.createShader(e.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(e.shaderSource(r,t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const s=`#version 300 es
|
|
402
|
+
precision mediump float;
|
|
403
|
+
|
|
404
|
+
uniform vec4 fillColor;
|
|
405
|
+
out vec4 outputColor;
|
|
406
|
+
|
|
407
|
+
void main() {
|
|
408
|
+
outputColor = fillColor;
|
|
409
|
+
}`,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 c=e.getUniformLocation(i,"canvasPageBounds"),d=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:Xp(e,1024),unselectedShapes:Xp(e,4096),viewport:Xp(e,BN),collaborators:Xp(e,1024),prepareTriangles(g,y){e.bindBuffer(e.ARRAY_BUFFER,g.buffer),e.bufferData(e.ARRAY_BUFFER,g.vertices,e.STATIC_DRAW,0,y),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(g){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,g/2),e.disable(e.BLEND)},drawTriangles(g){e.drawArrays(e.TRIANGLES,0,g/2)},setFillColor(g){e.uniform4fv(d,g)},setCanvasPageBounds(g){e.uniform4fv(c,g)}}}function Xp(n,e){const t=n.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(e)}}function Hk(n,e,t){let r=n.vertices.length;for(;r<e+t.length;)r*=2;if(r!=n.vertices.length){const s=new Float32Array(r);s.set(n.vertices),n.vertices=s}n.vertices.set(t,e)}var zre=Object.create,UN=Object.defineProperty,Bre=Object.getOwnPropertyDescriptor,Ure=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),HN=n=>{throw TypeError(n)},KN=(n,e,t)=>e in n?UN(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Hre=n=>[,,,zre(null)],WN=["class","method","getter","setter","accessor","field","value","get","set"],GN=n=>n!==void 0&&typeof n!="function"?HN("Function expected"):n,Kre=(n,e,t,r,s)=>({kind:WN[n],name:e,metadata:r,addInitializer:o=>t._?HN("Already initialized"):s.push(GN(o||null))}),Wre=(n,e)=>KN(e,Ure("metadata"),n[3]),Gre=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Ko=(n,e,t,r,s,o)=>{for(var i,a,c,d,h=e&7,f=!1,g=!1,y=2,S=WN[h+5],v=n[y]||(n[y]=[]),w=(s=s.prototype,Bre(s,t)),b=r.length-1;b>=0;b--)c=Kre(h,t,a={},n[3],v),c.static=f,c.private=g,d=c.access={has:P=>t in P},d.get=P=>P[t],i=(0,r[b])(w[S],c),a._=1,GN(i)&&(w[S]=i);return w&&UN(s,t,w),s},oi=(n,e,t)=>KN(n,typeof e!="symbol"?e+"":e,t),VN,qN,YN,XN,ZN,QN,JN,e4,t4,n4,as;n4=[Dr],t4=[le],e4=[le],JN=[le],QN=[le],ZN=[le],XN=[le],YN=[le],qN=[le],VN=[Dr];class Ms{constructor(e,t,r){this.editor=e,this.elem=t,this.container=r,Gre(as,5,this),oi(this,"disposables",[]),oi(this,"gl"),oi(this,"shapeGeometryCache"),oi(this,"colors"),oi(this,"id",xt()),oi(this,"canvasBoundingClientRect",dn("canvasBoundingClientRect",new Se)),oi(this,"originPagePoint",new C),oi(this,"originPageCenter",new C),oi(this,"isInViewport",!1),this.gl=$re(t),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",s=>{const o=e.getShapeMaskedPageBounds(s.id);if(!o)return null;const i=new Float32Array(12);return gc(i,0,o.x,o.y,o.w,o.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),To("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Yu(e.getPropertyValue("--color-text-3").trim()),selectFill:Yu(e.getPropertyValue("--color-selected").trim()),viewportFill:Yu(e.getPropertyValue("--color-muted-1").trim()),background:Yu(e.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const e=this.editor.getViewportPageBounds(),t=this.editor.getCurrentPageBounds();return t?Se.Expand(t,e):e}getContentScreenBounds(){const e=this.getContentPageBounds(),t=this.editor.pageToScreen(e.point),r=this.editor.pageToScreen(new C(e.maxX,e.maxY));return new Se(t.x,t.y,r.x-t.x,r.y-t.y)}_getCanvasBoundingRect(){const{x:e,y:t,width:r,height:s}=this.elem.getBoundingClientRect();return new Se(e,t,r,s)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const e=new ResizeObserver(()=>{const t=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(t)});return e.observe(this.elem),e.observe(this.container),()=>e.disconnect()}getCanvasSize(){const e=this.canvasBoundingClientRect.get(),t=this.getDpr();return new C(e.width*t,e.height*t)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const e=this.getCanvasScreenBounds(),t=this.getContentPageBounds(),r=e.width/e.height;let s=t.width,o=s/r;o<t.height&&(o=t.height,s=o*r);const i=new Se(0,0,s,o);return i.center=t.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:t,w:r,h:s}=this.getCanvasPageBounds();return new Float32Array([e,t,r,s])}getMinimapPagePoint(e,t){const r=this.getCanvasPageBounds(),s=this.getCanvasScreenBounds();let o=e-s.x,i=t-s.y;return o*=r.width/s.width,i*=r.height/s.height,o+=r.minX,i+=r.minY,new C(o,i,1)}minimapScreenPointToPagePoint(e,t,r=!1,s=!1){const{editor:o}=this,i=o.getViewportPageBounds();let{x:a,y:c}=this.getMinimapPagePoint(e,t);if(s){const d=this.editor.getCurrentPageBounds()??new Se,h=d.minX-i.width/2,f=d.maxX+i.width/2,g=d.minY-i.height/2,y=d.maxY+i.height/2,S=Math.max(0,h+i.width-a),v=Math.max(0,-(f-i.width-a)),w=Math.max(0,g+i.height-c),b=Math.max(0,-(y-i.height-c));a+=(S-v)/2,c+=(w-b)/2,a=Cn(a,h,f),c=Cn(c,g,y)}if(r){const{originPagePoint:d}=this,h=Math.abs(a-d.x),f=Math.abs(c-d.y);h>f?c=d.y:a=d.x}return new C(a,c)}render(){const e=this.gl.context,t=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=t.x,this.elem.height=t.y,e.viewport(0,0,t.x,t.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 c=0,d=a.length;c<d;c++){const h=a[c],f=this.shapeGeometryCache.get(h);if(!f)continue;const g=f.length;r.has(h)?(Hk(this.gl.selectedShapes,o,f),o+=g):(Hk(this.gl.unselectedShapes,i,f),i+=g)}this.drawShapes(this.gl.unselectedShapes,i,s.shapeFill),this.drawShapes(this.gl.selectedShapes,o,s.selectFill),this.drawViewport(),this.drawCollaborators()}drawShapes(e,t,r){this.gl.prepareTriangles(e,t),this.gl.setFillColor(r),this.gl.drawTriangles(t)}drawViewport(){const e=this.editor.getViewportPageBounds(),t=Nre(this.gl.viewport.vertices,e,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,t),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(t),Et.isSafari&&(this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t))}drawCollaborators(){const e=this.editor.getCollaboratorsOnCurrentPage();if(!e.length)return;const t=20,r=t*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:c}of e)c&&(fc(o,{center:C.From(c),radius:3*a,offset:i,numArcSegments:t}),i+=r);this.gl.prepareTriangles(this.gl.collaborators,s),i=0;for(const{color:c}of e)this.gl.setFillColor(Yu(c)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}as=Hre();Ko(as,1,"close",n4,Ms);Ko(as,1,"getDpr",t4,Ms);Ko(as,1,"getContentPageBounds",e4,Ms);Ko(as,1,"getContentScreenBounds",JN,Ms);Ko(as,1,"getCanvasSize",QN,Ms);Ko(as,1,"getCanvasClientPosition",ZN,Ms);Ko(as,1,"getCanvasPageBounds",XN,Ms);Ko(as,1,"getZoom",YN,Ms);Ko(as,1,"getCanvasPageBoundsArray",qN,Ms);Ko(as,1,"render",VN,Ms);Wre(as,Ms);function Vre(){const n=te(),e=fn(),t=_.useRef(null),r=_.useRef(!1),s=_.useRef();_.useEffect(()=>{try{const h=new Ms(n,t.current,e);return s.current=h,s.current.close}catch(h){n.annotateError(h,{origin:"minimap",willCrashApp:!1}),n.timers.setTimeout(()=>{throw h})}},[n,e]);const o=_.useCallback(h=>{if(!n.getCurrentPageShapeIds().size||!s.current)return;const f=s.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!1),g=s.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!0);s.current.originPagePoint.setTo(g),s.current.originPageCenter.setTo(n.getViewportPageBounds().center),n.centerOnPoint(f,{animation:{duration:n.options.animationMediumMs}})},[n]),i=_.useCallback(h=>{if(!s.current)return;const f=h.currentTarget;if(Wd(f,h),!n.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const g=s.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!1),y=n.getViewportPageBounds(),S=s.current.getContentPageBounds();if(new Se(S.x-y.width/2,S.y-y.height/2,S.width+y.width,S.height+y.height).containsPoint(g)&&!y.containsPoint(g)){s.current.isInViewport=y.containsPoint(g);const b=C.Sub(y.center,y.point),P=C.Add(g,b);s.current.originPagePoint.setTo(P),s.current.originPageCenter.setTo(g),n.centerOnPoint(g,{animation:{duration:n.options.animationMediumMs}})}else{const b=s.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!0);s.current.isInViewport=y.containsPoint(b),s.current.originPagePoint.setTo(b),s.current.originPageCenter.setTo(y.center)}function w(b){f&&Gd(f,b),r.current=!1,document.body.removeEventListener("pointerup",w)}document.body.addEventListener("pointerup",w)},[n]),a=_.useCallback(h=>{if(!s.current)return;const f=s.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,h.shiftKey,!0);if(r.current){if(s.current.isInViewport){const v=s.current.originPagePoint.clone().sub(s.current.originPageCenter);n.centerOnPoint(C.Sub(f,v));return}n.centerOnPoint(f)}const g=s.current.getMinimapPagePoint(h.clientX,h.clientY),y=n.pageToScreen(g),S={type:"pointer",target:"canvas",name:"pointer_move",...Zr(h),point:y,isPen:n.getInstanceState().isPenMode};n.dispatch(S)},[n]),c=_.useCallback(h=>{const f=Sj(h);n.dispatch({type:"wheel",name:"wheel",delta:f,point:new C(h.clientX,h.clientY),shiftKey:h.shiftKey,altKey:h.altKey,ctrlKey:h.metaKey||h.ctrlKey,metaKey:h.metaKey,accelKey:Gn(h)})},[n]),d=eh();return _.useEffect(()=>{n.timers.setTimeout(()=>{var h,f;(h=s.current)==null||h.updateColors(),(f=s.current)==null||f.render()})},[d,n]),p.jsx("div",{className:"tlui-minimap",children:p.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:o,onPointerMove:a,onPointerDown:i,onWheelCapture:c})})}function qre(n,e){const[t,r]=at.useState(e);at.useLayoutEffect(()=>{const o=nb(n);if(o)try{r(JSON.parse(o))}catch{console.error(`Could not restore value ${n} from local storage.`)}},[n]);const s=at.useCallback(o=>{r(i=>{const a=typeof o=="function"?o(i):o;return rb(n,JSON.stringify(a)),a})},[n]);return[t,s]}const Yre=_.memo(function(){const e=wl(),t=it(),r=ur(),s=_.useRef(null);Pa(s);const[o,i]=qre("minimap",!0),a=_.useCallback(()=>{i(h=>!h)},[i]),{ZoomMenu:c,Minimap:d}=Ea();return r<Jt.MOBILE?null:p.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[p.jsx("div",{className:"tlui-buttons__horizontal",children:c&&r<Jt.TABLET?p.jsx(c,{}):o?p.jsxs(p.Fragment,{children:[c&&p.jsx(c,{}),d&&p.jsx(Ne,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:p.jsx(nt,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):p.jsxs(p.Fragment,{children:[p.jsx(Ne,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(jd(e["zoom-out"].label))} ${w0(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:p.jsx(nt,{icon:"minus"})}),c&&p.jsx(c,{}),p.jsx(Ne,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(jd(e["zoom-in"].label))} ${w0(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:p.jsx(nt,{icon:"plus"})}),d&&p.jsx(Ne,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:p.jsx(nt,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),d&&r>=Jt.TABLET&&!o&&p.jsx(d,{})]})}),Xre=function({name:e,id:t,isCurrentPage:r,onCancel:s}){const o=te(),i=On(),a=_.useRef(null),c=_.useRef(null),d=_.useCallback(()=>{c.current=o.markHistoryStoppingPoint("rename page")},[o]),h=_.useCallback(g=>{o.renamePage(t,g||"New Page"),i("rename-page",{source:"page-menu"})},[o,t,i]),f=_.useCallback(()=>{c.current&&o.bailToMark(c.current),s()},[o,s]);return p.jsx(lm,{className:"tlui-page-menu__item__input",ref:g=>a.current=g,defaultValue:e,onValueChange:h,onCancel:f,onFocus:d,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},U0=(n,e,t,r,s)=>{let o;const i=n.getPages(),a=t>r?i[r-1]:i[r],c=t>r?i[r]:i[r+1];a&&!c?o=Co(a.index):!a&&c?o=Y6(i[0].index):o=wd(a.index,c.index),o!==i[t].index&&(n.markHistoryStoppingPoint("moving page"),n.updatePage({id:e,index:o}),s("move-page",{source:"page-menu"}))},Kk=jn(function({index:e,listSize:t,item:r,onRename:s}){const o=te(),i=it(),a=o.getPages(),c=On(),d=_.useCallback(()=>{o.markHistoryStoppingPoint("creating page");const y=ss.createId();o.duplicatePage(r.id,y),c("duplicate-page",{source:"page-menu"})},[o,r,c]),h=_.useCallback(()=>{U0(o,r.id,e,e-1,c)},[o,r,e,c]),f=_.useCallback(()=>{U0(o,r.id,e,e+1,c)},[o,r,e,c]),g=_.useCallback(()=>{o.markHistoryStoppingPoint("deleting page"),o.deletePage(r.id),c("delete-page",{source:"page-menu"})},[o,r,c]);return p.jsxs(hl,{id:`page item submenu ${e}`,children:[p.jsx(pl,{children:p.jsx(Ne,{type:"icon",title:i("page-menu.submenu.title"),children:p.jsx(nt,{icon:"dots-vertical",small:!0})})}),p.jsx(fl,{alignOffset:0,side:"right",sideOffset:-4,children:p.jsxs(Es,{type:"menu",sourceId:"page-menu",children:[p.jsxs(Qe,{id:"modify",children:[s&&p.jsx(En,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),p.jsx(En,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:d,disabled:a.length>=o.options.maxPages}),e>0&&p.jsx(En,{id:"move-up",onSelect:h,label:"page-menu.submenu.move-up"}),e<t-1&&p.jsx(En,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:f})]}),t>1&&p.jsx(Qe,{id:"delete",children:p.jsx(En,{id:"delete",onSelect:g,label:"page-menu.submenu.delete"})})]})})]})}),Zre=_.memo(function(){const e=te(),t=On(),r=it(),s=ur(),o=_.useCallback(()=>b(!1),[]),[i,a]=Ei("page-menu",o),c=36,d=_.useRef(null),h=se("pages",()=>e.getPages(),[e]),f=se("currentPage",()=>e.getCurrentPage(),[e]),g=se("currentPageId",()=>e.getCurrentPageId(),[e]),y=is(),S=se("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),v=se("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[w,b]=_.useState(!1),P=_.useCallback(()=>{y||b(F=>!F)},[y]),k=_.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[E,M]=_.useState(Object.fromEntries(h.map((F,$)=>[F.id,{y:$*c,offsetY:0,isSelected:!1}])));_.useLayoutEffect(()=>{M(Object.fromEntries(h.map((F,$)=>[F.id,{y:$*c,offsetY:0,isSelected:!1}])))},[c,h]),_.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const F=document.querySelector(`[data-testid="page-menu-item-${g}"]`);if(F){const $=d.current;if(!$)return;const W=F.offsetTop,Y=$.scrollTop;W<Y&&$.scrollTo({top:W});const Z=W+c,H=$.scrollTop+$.offsetHeight;Z>H&&$.scrollTo({top:Z-$.offsetHeight})}})},[c,g,i,e]);const A=_.useCallback(F=>{const{clientY:$,currentTarget:W}=F,{dataset:{id:Y,index:Z}}=W;if(!Y||!Z)return;const H=k.current;Wd(F.currentTarget,F),H.status="pointing",H.pointing={id:Y,index:+Z};const ae=E[Y].y;H.startY=$,H.startIndex=Math.max(0,Math.min(Math.round(ae/c),h.length-1))},[c,h.length,E]),R=_.useCallback(F=>{const $=k.current;if($.status==="pointing"){const{clientY:W}=F,Y=W-$.startY;Math.abs(Y)>5&&($.status="dragging")}if($.status==="dragging"){const{clientY:W}=F,Y=W-$.startY,Z=E[$.pointing.id],{startIndex:H,pointing:Q}=$,ae=Z.y+Y,B=Math.max(0,Math.min(Math.round(ae/c),h.length-1)),ne={...E};if(ne[Q.id]={y:Z.y,offsetY:Y,isSelected:!0},B!==$.dragIndex){$.dragIndex=B;for(let he=0;he<h.length;he++){const Pe=h[he];if(Pe.id===$.pointing.id)continue;let{y:ue}=ne[Pe.id];B===H?ue=he*c:B<H?B<=he&&he<H?ue=(he+1)*c:ue=he*c:B>H&&(B>=he&&he>H?ue=(he-1)*c:ue=he*c),ue!==ne[Pe.id].y&&(ne[Pe.id]={y:ue,offsetY:0,isSelected:!0})}}M(ne)}},[c,h,E]),D=_.useCallback(F=>{const $=k.current;if($.status==="dragging"){const{id:W,index:Y}=$.pointing;U0(e,W,Y,$.dragIndex,t)}Gd(F.currentTarget,F),$.status="idle"},[e,t]),V=_.useCallback(F=>{const $=k.current;F.key==="Escape"&&($.status==="dragging"&&M(Object.fromEntries(h.map((W,Y)=>[W.id,{y:Y*c,offsetY:0,isSelected:!1}]))),$.status="idle")},[c,h]),L=_.useCallback(()=>{y||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const F=ss.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:F}),e.setCurrentPage(F),b(!0)}),t("new-page",{source:"page-menu"}))},[e,r,y,t]),U=_.useCallback(F=>{e.setCurrentPage(F),t("change-page",{source:"page-menu"})},[e,t]),K=_.useCallback((F,$)=>{e.renamePage(F,$),t("rename-page",{source:"page-menu"})},[e,t]);return p.jsxs(fP,{id:"pages",onOpenChange:a,open:i,children:[p.jsx(gP,{"data-testid":"main.page-menu",children:p.jsxs(Ne,{type:"menu",title:f.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[p.jsx("div",{className:"tlui-page-menu__name",children:f.name}),p.jsx(nt,{icon:"chevron-down",small:!0})]})}),p.jsx(mP,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:w,children:p.jsxs("div",{className:"tlui-page-menu__wrapper",children:[p.jsxs("div",{className:"tlui-page-menu__header",children:[p.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!y&&p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsx(Ne,{type:"icon","data-testid":"page-menu.edit",title:r(w?"page-menu.edit-done":"page-menu.edit-start"),onClick:P,children:p.jsx(nt,{icon:w?"check":"edit"})}),p.jsx(Ne,{type:"icon","data-testid":"page-menu.create",title:r(S?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:S,onClick:L,children:p.jsx(nt,{icon:"plus"})})]})]}),p.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:c*h.length+4},ref:d,children:h.map((F,$)=>{const W=E[F.id]??{offsetY:0};return w?p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:F.id===f.id?888:$,transform:`translate(0px, ${W.y+W.offsetY}px)`},children:[p.jsx(Ne,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:A,onPointerUp:D,onPointerMove:R,onKeyDown:V,"data-id":F.id,"data-index":$,children:p.jsx(nt,{icon:"drag-handle-dots"})}),s<Jt.TABLET_SM&&v?p.jsxs(Ne,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const Y=window.prompt("Rename page",F.name);Y&&Y!==F.name&&K(F.id,Y)},onDoubleClick:P,children:[p.jsx(B0,{checked:F.id===f.id}),p.jsx(on,{children:F.name})]}):p.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:c},children:p.jsx(Xre,{id:F.id,name:F.name,isCurrentPage:F.id===f.id,onCancel:()=>{b(!1),e.menus.clearOpenMenus()}})}),!y&&p.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":w,children:p.jsx(Kk,{index:$,item:F,listSize:h.length})})]},F.id+"_editing"):p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[p.jsxs(Ne,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>U(F.id),onDoubleClick:P,title:r("page-menu.go-to-page"),children:[p.jsx(B0,{checked:F.id===f.id}),p.jsx(on,{children:F.name})]}),!y&&p.jsx("div",{className:"tlui-page_menu__item__submenu",children:p.jsx(Kk,{index:$,item:F,listSize:h.length,onRename:()=>{if(Et.isIos){const Y=window.prompt("Rename page",F.name);Y&&Y!==F.name&&K(F.id,Y)}else b(!0),g!==F.id&&U(F.id)}})})]},F.id)})})]})})]})});function Qre(){const n=te(),e=is(),t=se("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(e&&!t))return p.jsxs(p.Fragment,{children:[p.jsx(ese,{}),p.jsx(Jre,{})]})}function Jre(){const n=dr(1),e=Ti(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"delete",disabled:!t}),p.jsx(ce,{actionId:"duplicate",disabled:!t})]})}function ese(){const n=xN(),e=vN();return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"undo",disabled:!n}),p.jsx(ce,{actionId:"redo",disabled:!e})]})}const tse=_.memo(function({children:e}){const t=e??p.jsx(Qre,{});return p.jsx(Es,{type:"small-icons",sourceId:"quick-actions",children:t})});function nse({userId:n}){const e=Mg(n);return e?p.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:e.userName==="New User"?"":e.userName[0]??""},n):null}const rse=jn(function({userId:e}){const t=te(),r=it(),s=On(),o=Mg(e),i=_.useCallback(()=>{t.getInstanceState().followingUserId===e?(t.stopFollowingUser(),s("stop-following",{source:"people-menu"})):(t.startFollowingUser(e),s("start-following",{source:"people-menu"}))},[t,e,s]),a=(o==null?void 0:o.followingUserId)===t.user.getId(),c=t.getInstanceState().followingUserId===e;return o?p.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[p.jsxs(Ne,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>t.zoomToUser(e),onDoubleClick:i,children:[p.jsx(Fo,{icon:"color",color:o.color}),p.jsx("div",{className:"tlui-people-menu__name",children:o.userName??"New User"})]}),p.jsx(Ne,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":c?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,"data-active":c||a,children:p.jsx(nt,{icon:a?"leading":c?"following":"follow"})})]}):null});function sse({count:n}){return p.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(n)})}const ose=jn(function(){const e=te(),t=fn(),r=it(),s=On(),o=_.useRef(!1),[i,a]=_.useState(!1),c=_.useCallback(v=>{a(v)},[]),d=e.user.getColor(),h=_.useCallback(v=>{e.user.updateUserPreferences({color:v}),s("set-color",{source:"people-menu"})},[e,s]),{handleButtonClick:f,handleButtonPointerDown:g,handleButtonPointerEnter:y,handleButtonPointerUp:S}=at.useMemo(()=>{const v=()=>{o.current=!1,window.removeEventListener("pointerup",v)};return{handleButtonClick:E=>{const{id:M}=E.currentTarget.dataset;M&&d!==M&&h(M)},handleButtonPointerDown:E=>{const{id:M}=E.currentTarget.dataset;M&&(h(M),o.current=!0,window.addEventListener("pointerup",v))},handleButtonPointerEnter:E=>{if(!o.current)return;const{id:M}=E.currentTarget.dataset;M&&h(M)},handleButtonPointerUp:E=>{const{id:M}=E.currentTarget.dataset;M&&h(M)}}},[d,h]);return p.jsxs(uP,{onOpenChange:c,open:i,children:[p.jsx(dP,{dir:"ltr",asChild:!0,children:p.jsx(Ne,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:p.jsx(nt,{icon:"color"})})}),p.jsx(hP,{container:t,children:p.jsx(pP,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:p.jsx("div",{className:"tlui-buttons__grid",children:Yw.map(v=>p.jsx(Ne,{type:"icon","data-id":v,"data-testid":v,"aria-label":v,"data-state":d===v?"hinted":void 0,title:v,className:"tlui-button-grid__button",style:{color:v},onPointerEnter:y,onPointerDown:g,onPointerUp:S,onClick:f,children:p.jsx(nt,{icon:"color"})},v))})})})]})});function ise(){const n=te(),e=On(),t=se("userName",()=>n.user.getName(),[]),r=it(),s=_.useRef(t),o=_.useRef(t),[i,a]=_.useState(!1),c=_.useCallback(()=>{a(g=>!g)},[]),d=_.useCallback(g=>{o.current=g,n.user.updateUserPreferences({name:g})},[n]),h=_.useCallback(()=>{s.current!==o.current&&(e("change-user-name",{source:"people-menu"}),s.current=o.current)},[e]),f=_.useCallback(()=>{a(!1),n.user.updateUserPreferences({name:s.current}),n.menus.clearOpenMenus()},[n]);return p.jsxs("div",{className:"tlui-people-menu__user",children:[p.jsx(ose,{}),i?p.jsx(lm,{className:"tlui-people-menu__user__input",defaultValue:t,onValueChange:d,onComplete:c,onCancel:f,onBlur:h,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:t}),t==="New User"?p.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),p.jsx(Ne,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:c,children:p.jsx(nt,{icon:i?"check":"edit"})})]})}function ase({displayUserWhenAlone:n,children:e}){const t=it(),r=fn(),s=te(),o=wj(),i=se("user",()=>s.user.getColor(),[s]),a=se("user",()=>s.user.getName(),[s]),[c,d]=Ei("people menu");return p.jsxs(uP,{onOpenChange:d,open:c,children:[p.jsx(dP,{dir:"ltr",asChild:!0,children:p.jsxs("button",{className:"tlui-people-menu__avatars-button",title:t("people-menu.title"),children:[o.length>5&&p.jsx(sse,{count:o.length-5}),p.jsxs("div",{className:"tlui-people-menu__avatars",children:[o.slice(-5).map(h=>p.jsx(nse,{userId:h},h)),(n||o.length>0)&&p.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),p.jsx(hP,{container:r,children:p.jsx(pP,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:Je,children:p.jsxs("div",{className:"tlui-people-menu__wrapper",children:[p.jsx("div",{className:"tlui-people-menu__section",children:p.jsx(ise,{})}),o.length>0&&p.jsx("div",{className:"tlui-people-menu__section",children:o.map(h=>p.jsx(rse,{userId:h},h+"_presence"))}),e]})})})]})}function lse(){return p.jsx("div",{className:"tlui-share-zone",draggable:!1,children:p.jsx(ase,{displayUserWhenAlone:!0})})}const cse=Object.freeze([rs,al,ll,Oo]);function r4(n=cse){const e=te();return se("getRelevantStyles",()=>{var o;const t=new t0(e.getSharedStyles()),r=!!((o=e.root.getCurrent())!=null&&o.shapeType),s=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(t.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const i of n)t.applyValue(i,e.getStyleForNextShape(i));return r||s||t.size>0?t:null},[e])}const bs={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"}]},Ja=_.memo(function(e){const{uiType:t,items:r,title:s,style:o,value:i,onValueChange:a,onHistoryMark:c,theme:d}=e,h=it(),f=_.useRef(!1),g=_.useRef(null),{handleButtonClick:y,handleButtonPointerDown:S,handleButtonPointerEnter:v,handleButtonPointerUp:w}=_.useMemo(()=>{const b=()=>{f.current=!1,window.removeEventListener("pointerup",b);const A=g.current;A&&["TEXTAREA","INPUT"].includes(A.nodeName)&&A.focus(),g.current=null};return{handleButtonClick:A=>{const{id:R}=A.currentTarget.dataset;i.type==="shared"&&i.value===R||(c==null||c("point picker item"),a(o,R))},handleButtonPointerDown:A=>{const{id:R}=A.currentTarget.dataset;c==null||c("point picker item"),a(o,R),f.current=!0,g.current=document.activeElement,window.addEventListener("pointerup",b)},handleButtonPointerEnter:A=>{if(!f.current)return;const{id:R}=A.currentTarget.dataset;a(o,R)},handleButtonPointerUp:A=>{const{id:R}=A.currentTarget.dataset;i.type==="shared"&&i.value===R||a(o,R)}}},[i,c,a,o]);return p.jsx("div",{"data-testid":`style.${t}`,className:Le("tlui-buttons__grid"),children:r.map(b=>p.jsx(Ne,{type:"icon","data-id":b.value,"data-testid":`style.${t}.${b.value}`,"aria-label":b.value,"data-state":i.type==="shared"&&i.value===b.value?"hinted":void 0,title:s+" — "+h(`${t}-style.${b.value}`),className:Le("tlui-button-grid__button"),style:o===rs?{color:d[b.value].solid}:void 0,onPointerEnter:v,onPointerDown:S,onPointerUp:w,onClick:y,children:p.jsx(nt,{icon:b.icon})},b.value))})});function s4(n,[e,t]){return Math.min(t,Math.max(e,n))}function use(n){const e=_.useRef({value:n,previous:n});return _.useMemo(()=>(e.current.value!==n&&(e.current.previous=e.current.value,e.current.value=n),e.current.previous),[n])}var o4=["PageUp","PageDown"],i4=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],a4={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},tu="Slider",[H0,dse,hse]=Vg(tu),[l4,Lie]=Uo(tu,[hse]),[pse,Pm]=l4(tu),c4=_.forwardRef((n,e)=>{const{name:t,min:r=0,max:s=100,step:o=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:d=[r],value:h,onValueChange:f=()=>{},onValueCommit:g=()=>{},inverted:y=!1,form:S,...v}=n,w=_.useRef(new Set),b=_.useRef(0),k=i==="horizontal"?fse:gse,[E=[],M]=Ca({prop:h,defaultProp:d,onChange:U=>{var F;(F=[...w.current][b.current])==null||F.focus(),f(U)}}),A=_.useRef(E);function R(U){const K=xse(E,U);L(U,K)}function D(U){L(U,b.current)}function V(){const U=A.current[b.current];E[b.current]!==U&&g(E)}function L(U,K,{commit:F}={commit:!1}){const $=Cse(o),W=_se(Math.round((U-r)/o)*o+r,$),Y=s4(W,[r,s]);M((Z=[])=>{const H=Sse(Z,Y,K);if(Pse(H,c*o)){b.current=H.indexOf(Y);const Q=String(H)!==String(Z);return Q&&F&&g(H),Q?H:Z}else return Z})}return p.jsx(pse,{scope:n.__scopeSlider,name:t,disabled:a,min:r,max:s,valueIndexToChangeRef:b,thumbs:w.current,values:E,orientation:i,form:S,children:p.jsx(H0.Provider,{scope:n.__scopeSlider,children:p.jsx(H0.Slot,{scope:n.__scopeSlider,children:p.jsx(k,{"aria-disabled":a,"data-disabled":a?"":void 0,...v,ref:e,onPointerDown:Ae(v.onPointerDown,()=>{a||(A.current=E)}),min:r,max:s,inverted:y,onSlideStart:a?void 0:R,onSlideMove:a?void 0:D,onSlideEnd:a?void 0:V,onHomeKeyDown:()=>!a&&L(r,0,{commit:!0}),onEndKeyDown:()=>!a&&L(s,E.length-1,{commit:!0}),onStepKeyDown:({event:U,direction:K})=>{if(!a){const W=o4.includes(U.key)||U.shiftKey&&i4.includes(U.key)?10:1,Y=b.current,Z=E[Y],H=o*W*K;L(Z+H,Y,{commit:!0})}}})})})})});c4.displayName=tu;var[u4,d4]=l4(tu,{startEdge:"left",endEdge:"right",size:"width",direction:1}),fse=_.forwardRef((n,e)=>{const{min:t,max:r,dir:s,inverted:o,onSlideStart:i,onSlideMove:a,onSlideEnd:c,onStepKeyDown:d,...h}=n,[f,g]=_.useState(null),y=Ot(e,k=>g(k)),S=_.useRef(void 0),v=o1(s),w=v==="ltr",b=w&&!o||!w&&o;function P(k){const E=S.current||f.getBoundingClientRect(),M=[0,E.width],R=SP(M,b?[t,r]:[r,t]);return S.current=E,R(k-E.left)}return p.jsx(u4,{scope:n.__scopeSlider,startEdge:b?"left":"right",endEdge:b?"right":"left",direction:b?1:-1,size:"width",children:p.jsx(h4,{dir:v,"data-orientation":"horizontal",...h,ref:y,style:{...h.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:k=>{const E=P(k.clientX);i==null||i(E)},onSlideMove:k=>{const E=P(k.clientX);a==null||a(E)},onSlideEnd:()=>{S.current=void 0,c==null||c()},onStepKeyDown:k=>{const M=a4[b?"from-left":"from-right"].includes(k.key);d==null||d({event:k,direction:M?-1:1})}})})}),gse=_.forwardRef((n,e)=>{const{min:t,max:r,inverted:s,onSlideStart:o,onSlideMove:i,onSlideEnd:a,onStepKeyDown:c,...d}=n,h=_.useRef(null),f=Ot(e,h),g=_.useRef(void 0),y=!s;function S(v){const w=g.current||h.current.getBoundingClientRect(),b=[0,w.height],k=SP(b,y?[r,t]:[t,r]);return g.current=w,k(v-w.top)}return p.jsx(u4,{scope:n.__scopeSlider,startEdge:y?"bottom":"top",endEdge:y?"top":"bottom",size:"height",direction:y?1:-1,children:p.jsx(h4,{"data-orientation":"vertical",...d,ref:f,style:{...d.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:v=>{const w=S(v.clientY);o==null||o(w)},onSlideMove:v=>{const w=S(v.clientY);i==null||i(w)},onSlideEnd:()=>{g.current=void 0,a==null||a()},onStepKeyDown:v=>{const b=a4[y?"from-bottom":"from-top"].includes(v.key);c==null||c({event:v,direction:b?-1:1})}})})}),h4=_.forwardRef((n,e)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:s,onSlideEnd:o,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:c,...d}=n,h=Pm(tu,t);return p.jsx(ut.span,{...d,ref:e,onKeyDown:Ae(n.onKeyDown,f=>{f.key==="Home"?(i(f),f.preventDefault()):f.key==="End"?(a(f),f.preventDefault()):o4.concat(i4).includes(f.key)&&(c(f),f.preventDefault())}),onPointerDown:Ae(n.onPointerDown,f=>{const g=f.target;g.setPointerCapture(f.pointerId),f.preventDefault(),h.thumbs.has(g)?g.focus():r(f)}),onPointerMove:Ae(n.onPointerMove,f=>{f.target.hasPointerCapture(f.pointerId)&&s(f)}),onPointerUp:Ae(n.onPointerUp,f=>{const g=f.target;g.hasPointerCapture(f.pointerId)&&(g.releasePointerCapture(f.pointerId),o(f))})})}),p4="SliderTrack",f4=_.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=Pm(p4,t);return p.jsx(ut.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});f4.displayName=p4;var K0="SliderRange",g4=_.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=Pm(K0,t),o=d4(K0,t),i=_.useRef(null),a=Ot(e,i),c=s.values.length,d=s.values.map(g=>y4(g,s.min,s.max)),h=c>1?Math.min(...d):0,f=100-Math.max(...d);return p.jsx(ut.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...n.style,[o.startEdge]:h+"%",[o.endEdge]:f+"%"}})});g4.displayName=K0;var W0="SliderThumb",m4=_.forwardRef((n,e)=>{const t=dse(n.__scopeSlider),[r,s]=_.useState(null),o=Ot(e,a=>s(a)),i=_.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return p.jsx(mse,{...n,ref:o,index:i})}),mse=_.forwardRef((n,e)=>{const{__scopeSlider:t,index:r,name:s,...o}=n,i=Pm(W0,t),a=d4(W0,t),[c,d]=_.useState(null),h=Ot(e,P=>d(P)),f=c?i.form||!!c.closest("form"):!0,g=h3(c),y=i.values[r],S=y===void 0?0:y4(y,i.min,i.max),v=vse(r,i.values.length),w=g==null?void 0:g[a.size],b=w?wse(w,S,a.direction):0;return _.useEffect(()=>{if(c)return i.thumbs.add(c),()=>{i.thumbs.delete(c)}},[c,i.thumbs]),p.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${S}% + ${b}px)`},children:[p.jsx(H0.ItemSlot,{scope:n.__scopeSlider,children:p.jsx(ut.span,{role:"slider","aria-label":n["aria-label"]||v,"aria-valuemin":i.min,"aria-valuenow":y,"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:h,style:y===void 0?{display:"none"}:n.style,onFocus:Ae(n.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),f&&p.jsx(yse,{name:s??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:y},r)]})});m4.displayName=W0;var yse=n=>{const{value:e,...t}=n,r=_.useRef(null),s=use(e);return _.useEffect(()=>{const o=r.current,i=window.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(i,"value").set;if(s!==e&&c){const d=new Event("input",{bubbles:!0});c.call(o,e),o.dispatchEvent(d)}},[s,e]),p.jsx("input",{style:{display:"none"},...t,ref:r,defaultValue:e})};function Sse(n=[],e,t){const r=[...n];return r[t]=e,r.sort((s,o)=>s-o)}function y4(n,e,t){const o=100/(t-e)*(n-e);return s4(o,[0,100])}function vse(n,e){return e>2?`Value ${n+1} of ${e}`:e===2?["Minimum","Maximum"][n]:void 0}function xse(n,e){if(n.length===1)return 0;const t=n.map(s=>Math.abs(s-e)),r=Math.min(...t);return t.indexOf(r)}function wse(n,e,t){const r=n/2,o=SP([0,50],[0,r]);return(r-o(e)*t)*t}function bse(n){return n.slice(0,-1).map((e,t)=>n[t+1]-e)}function Pse(n,e){if(e>0){const t=bse(n);return Math.min(...t)>=e}return!0}function SP(n,e){return t=>{if(n[0]===n[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(n[1]-n[0]);return e[0]+r*(t-n[0])}}function Cse(n){return(String(n).split(".")[1]||"").length}function _se(n,e){const t=Math.pow(10,e);return Math.round(n*t)/t}var Ise=c4,Ese=f4,Tse=g4,kse=m4;const Mse=_.memo(function({onHistoryMark:e,title:t,steps:r,value:s,label:o,onValueChange:i,["data-testid"]:a}){const c=it(),d=_.useCallback(g=>{i(g[0])},[i]),h=_.useCallback(()=>{e("click slider")},[e]),f=_.useCallback(()=>{s&&i(s)},[s,i]);return p.jsx("div",{className:"tlui-slider__container",children:p.jsxs(Ise,{"data-testid":a,className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:h,onValueChange:d,onPointerUp:f,title:t+" — "+c(o),children:[p.jsx(Ese,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&p.jsx(Tse,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&p.jsx(kse,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Ase({label:n,uiTypeA:e,uiTypeB:t,labelA:r,labelB:s,itemsA:o,itemsB:i,styleA:a,styleB:c,valueA:d,valueB:h,onValueChange:f}){const g=it(),y=_.useMemo(()=>{var v;return((v=o.find(w=>d.type==="shared"&&d.value===w.value))==null?void 0:v.icon)??"mixed"},[o,d]),S=_.useMemo(()=>{var v;return((v=i.find(w=>h.type==="shared"&&h.value===w.value))==null?void 0:v.icon)??"mixed"},[i,h]);return d===void 0&&h===void 0?null:p.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[p.jsx("div",{title:g(n),className:"tlui-style-panel__double-select-picker-label",children:g(n)}),p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsxs(hl,{id:`style panel ${e} A`,children:[p.jsx(pl,{children:p.jsx(Ne,{type:"icon","data-testid":`style.${e}`,title:g(r)+" — "+(d===null||d.type==="mixed"?g("style-panel.mixed"):g(`${e}-style.${d.value}`)),children:p.jsx(nt,{icon:y,small:!0,invertIcon:!0})})}),p.jsx(fl,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:o.map((v,w)=>p.jsx(Rd,{"data-testid":`style.${e}.${v.value}`,children:p.jsx(Ne,{type:"icon",onClick:()=>f(a,v.value),title:`${g(r)} — ${g(`${e}-style.${v.value}`)}`,children:p.jsx(nt,{icon:v.icon,invertIcon:!0})},v.value)},w))})})]}),p.jsxs(hl,{id:`style panel ${t}`,children:[p.jsx(pl,{children:p.jsx(Ne,{type:"icon","data-testid":`style.${t}`,title:g(s)+" — "+(h===null||h.type==="mixed"?g("style-panel.mixed"):g(`${t}-style.${h.value}`)),children:p.jsx(nt,{icon:S,small:!0})})}),p.jsx(fl,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:i.map(v=>p.jsx(Rd,{children:p.jsx(Ne,{type:"icon",title:`${g(s)} — ${g(`${t}-style.${v.value}`)}`,"data-testid":`style.${t}.${v.value}`,onClick:()=>f(c,v.value),children:p.jsx(nt,{icon:v.icon})})},v.value))})})]})]})]})}const jse=_.memo(Ase);function Rse({id:n,label:e,uiType:t,stylePanelType:r,style:s,items:o,type:i,value:a,onValueChange:c}){const d=it(),h=te(),f=_.useMemo(()=>{var v;return(v=o.find(w=>a.type==="shared"&&w.value===a.value))==null?void 0:v.icon},[o,a]),g=d(`style-panel.${r}`),y=a.type==="mixed"?d("style-panel.mixed"):g+" — "+d(`${t}-style.${a.value}`),S=e?d(e):"";return p.jsxs(hl,{id:`style panel ${n}`,children:[p.jsx(pl,{children:p.jsxs(Ne,{type:i,"data-testid":`style.${t}`,title:y,children:[S&&p.jsx(on,{children:S}),p.jsx(nt,{icon:f??"mixed"})]})}),p.jsx(fl,{side:"left",align:"center",alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:o.map(v=>p.jsx(Rd,{children:p.jsx(Ne,{type:"icon","data-testid":`style.${t}.${v.value}`,title:g+" — "+d(`${t}-style.${v.value}`),onClick:()=>{h.markHistoryStoppingPoint("select style dropdown item"),c(s,v.value)},children:p.jsx(nt,{icon:v.icon})})},v.value))})})]})}const vP=_.memo(Rse);function Ose({styles:n}){const e=eh();if(!n)return null;const t=n.get(qs),r=n.get(Wf),s=n.get(Kf),o=n.get(Yf),i=n.get(Ro),a=t===void 0,c=r===void 0&&s===void 0,d=o===void 0,h=i===void 0,f=_i({isDarkMode:e});return p.jsxs(p.Fragment,{children:[p.jsx(Dse,{theme:f,styles:n}),!h&&p.jsx(Lse,{theme:f,styles:n}),!(a&&c&&d)&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[p.jsx(Fse,{styles:n}),p.jsx($se,{styles:n}),p.jsx(Nse,{styles:n})]})]})}function ch(){const n=te(),e=On();return at.useMemo(()=>function(r,s){n.run(()=>{n.isIn("select")&&n.setStyleForSelectedShapes(r,s),n.setStyleForNextShapes(r,s),n.updateInstanceState({isChangingStyle:!0})}),e("set-style",{source:"style-panel",id:r.id,value:s})},[n,e])}function Dse({styles:n,theme:e}){const t=it(),r=te(),s=_.useCallback(f=>r.markHistoryStoppingPoint(f),[r]),o=ch(),i=n.get(rs),a=n.get(ll),c=n.get(al),d=n.get(Oo),h=a!==void 0||c!==void 0||d!==void 0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[i===void 0?null:p.jsx(Ja,{title:t("style-panel.color"),uiType:"color",style:rs,items:bs.color,value:i,onValueChange:o,theme:e,onHistoryMark:s}),p.jsx(zse,{})]}),h&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:p.jsx(Ja,{title:t("style-panel.fill"),uiType:"fill",style:ll,items:bs.fill,value:a,onValueChange:o,theme:e,onHistoryMark:s}),c===void 0?null:p.jsx(Ja,{title:t("style-panel.dash"),uiType:"dash",style:al,items:bs.dash,value:c,onValueChange:o,theme:e,onHistoryMark:s}),d===void 0?null:p.jsx(Ja,{title:t("style-panel.size"),uiType:"size",style:Oo,items:bs.size,value:d,onValueChange:(f,g)=>{o(f,g);const y=r.getSelectedShapeIds();y.length>0&&jt(r,y)},theme:e,onHistoryMark:s})]})]})}function Lse({theme:n,styles:e}){const t=it(),r=ch(),s=te(),o=_.useCallback(h=>s.markHistoryStoppingPoint(h),[s]),i=e.get(Ro),a=e.get(Gw),c=e.get(Vf),d=e.get(qf);return i===void 0&&c===void 0?null:p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[i===void 0?null:p.jsx(Ja,{title:t("style-panel.font"),uiType:"font",style:Ro,items:bs.font,value:i,onValueChange:r,theme:n,onHistoryMark:o}),a===void 0?null:p.jsxs("div",{className:"tlui-style-panel__row",children:[p.jsx(Ja,{title:t("style-panel.align"),uiType:"align",style:Gw,items:bs.textAlign,value:a,onValueChange:r,theme:n,onHistoryMark:o}),p.jsx("div",{className:"tlui-style-panel__row__extra-button",children:p.jsx(Ne,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:p.jsx(nt,{icon:"vertical-align-middle"})})})]}),c===void 0?null:p.jsxs("div",{className:"tlui-style-panel__row",children:[p.jsx(Ja,{title:t("style-panel.label-align"),uiType:"align",style:Vf,items:bs.horizontalAlign,value:c,onValueChange:r,theme:n,onHistoryMark:o}),p.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d===void 0?p.jsx(Ne,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:p.jsx(nt,{icon:"vertical-align-middle"})}):p.jsx(vP,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:qf,items:bs.verticalAlign,value:d,onValueChange:r})})]})]})}function Fse({styles:n}){const e=ch(),t=n.get(qs);return t===void 0?null:p.jsx(vP,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:qs,items:bs.geo,value:t,onValueChange:e})}function Nse({styles:n}){const e=ch(),t=n.get(Yf);return t===void 0?null:p.jsx(vP,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:Yf,items:bs.spline,value:t,onValueChange:e})}function $se({styles:n}){const e=ch(),t=n.get(Wf),r=n.get(Kf);return!t||!r?null:p.jsx(jse,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Kf,itemsA:bs.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Wf,itemsB:bs.arrowheadEnd,valueB:t,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Xu=[.1,.25,.5,.75,1];function zse(){const n=te(),e=_.useCallback(a=>n.markHistoryStoppingPoint(a),[n]),t=se("opacity",()=>n.getSharedOpacity(),[n]),r=On(),s=it(),o=at.useCallback(a=>{const c=Xu[a];n.run(()=>{n.isIn("select")&&n.setOpacityForSelectedShapes(c),n.setOpacityForNextShapes(c),n.updateInstanceState({isChangingStyle:!0})}),r("set-style",{source:"style-panel",id:"opacity",value:a})},[n,r]);if(t===void 0)return null;const i=t.type==="mixed"?-1:Xu.indexOf(S6(Xu,a=>Math.abs(a-t.value)));return p.jsx(Mse,{"data-testid":"style.opacity",value:i>=0?i:Xu.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:o,steps:Xu.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const Bse=_.memo(function({isMobile:e,children:t}){const r=te(),s=_.useRef(null);Pa(s);const o=r4(),i=_.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=t??p.jsx(Ose,{styles:o});return p.jsx("div",{ref:s,className:Le("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:i,children:a})});function Use(){const n=te(),e=it(),t=r4(),r=t==null?void 0:t.get(rs),s=_i({isDarkMode:n.user.getIsDarkMode()}),o=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,i=se("disable style panel",()=>n.isInAny("hand","zoom","eraser","laser"),[n]),a=_.useCallback(d=>{d||n.updateInstanceState({isChangingStyle:!1})},[n]),{StylePanel:c}=Ea();return c?p.jsxs(fP,{id:"mobile style menu",onOpenChange:a,children:[p.jsx(gP,{children:p.jsx(Ne,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":o},title:e("style-panel.title"),disabled:i,children:p.jsx(nt,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),p.jsx(mP,{side:"top",align:"end",children:c&&p.jsx(c,{isMobile:!0})})]}):null}function Hse(){return p.jsxs(p.Fragment,{children:[p.jsx(Wse,{}),p.jsx(Gse,{}),p.jsx(Vse,{}),p.jsx(qse,{}),p.jsx(Yse,{}),p.jsx(Xse,{}),p.jsx(Zse,{}),p.jsx(Qse,{}),p.jsx(Jse,{}),p.jsx(eoe,{}),p.jsx(noe,{}),p.jsx(toe,{}),p.jsx(ooe,{}),p.jsx(loe,{}),p.jsx(roe,{}),p.jsx(aoe,{}),p.jsx(ioe,{}),p.jsx(soe,{}),p.jsx(coe,{}),p.jsx(uoe,{}),p.jsx(doe,{}),p.jsx(hoe,{}),p.jsx(poe,{}),p.jsx(foe,{}),p.jsx(goe,{}),p.jsx(moe,{}),p.jsx(Soe,{}),p.jsx(yoe,{})]})}function Kse(n){var r;const e=te(),t=(r=n.meta)==null?void 0:r.geo;return se("is tool selected",()=>{const s=e.getCurrentToolId(),o=e.getSharedStyles().getAsKnownValue(qs);return t?s==="geo"&&o===t:s===n.id},[e,n.id,t])}function Tt({tool:n}){const e=V1(),t=Kse(e[n]);return p.jsx(Tr,{toolId:n,isSelected:t})}function Wse(){return p.jsx(Tt,{tool:"select"})}function Gse(){return p.jsx(Tt,{tool:"hand"})}function Vse(){return p.jsx(Tt,{tool:"draw"})}function qse(){return p.jsx(Tt,{tool:"eraser"})}function Yse(){return p.jsx(Tt,{tool:"arrow"})}function Xse(){return p.jsx(Tt,{tool:"text"})}function Zse(){return p.jsx(Tt,{tool:"note"})}function Qse(){return p.jsx(Tr,{toolId:"asset"})}function Jse(){return p.jsx(Tt,{tool:"rectangle"})}function eoe(){return p.jsx(Tt,{tool:"ellipse"})}function toe(){return p.jsx(Tt,{tool:"diamond"})}function noe(){return p.jsx(Tt,{tool:"triangle"})}function roe(){return p.jsx(Tt,{tool:"rhombus"})}function soe(){return p.jsx(Tt,{tool:"heart"})}function ooe(){return p.jsx(Tt,{tool:"hexagon"})}function ioe(){return p.jsx(Tt,{tool:"cloud"})}function aoe(){return p.jsx(Tt,{tool:"star"})}function loe(){return p.jsx(Tt,{tool:"oval"})}function coe(){return p.jsx(Tt,{tool:"x-box"})}function uoe(){return p.jsx(Tt,{tool:"check-box"})}function doe(){return p.jsx(Tt,{tool:"arrow-left"})}function hoe(){return p.jsx(Tt,{tool:"arrow-up"})}function poe(){return p.jsx(Tt,{tool:"arrow-down"})}function foe(){return p.jsx(Tt,{tool:"arrow-right"})}function goe(){return p.jsx(Tt,{tool:"line"})}function moe(){return p.jsx(Tt,{tool:"highlight"})}function yoe(){return p.jsx(Tt,{tool:"frame"})}function Soe(){return p.jsx(Tt,{tool:"laser"})}const cw=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function uw(n,e,t,r){n.addEventListener?n.addEventListener(e,t,r):n.attachEvent&&n.attachEvent("on".concat(e),t)}function Zu(n,e,t,r){n.removeEventListener?n.removeEventListener(e,t,r):n.detachEvent&&n.detachEvent("on".concat(e),t)}function S4(n,e){const t=e.slice(0,e.length-1);for(let r=0;r<t.length;r++)t[r]=n[t[r].toLowerCase()];return t}function v4(n){typeof n!="string"&&(n=""),n=n.replace(/\s/g,"");const e=n.split(",");let t=e.lastIndexOf("");for(;t>=0;)e[t-1]+=",",e.splice(t,1),t=e.lastIndexOf("");return e}function voe(n,e){const t=n.length>=e.length?n:e,r=n.length>=e.length?e:n;let s=!0;for(let o=0;o<t.length;o++)r.indexOf(t[o])===-1&&(s=!1);return s}const Dd={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,"-":cw?173:189,"=":cw?61:187,";":cw?59:186,"'":222,"[":219,"]":221,"\\":220},$o={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Mf={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},_n={16:!1,18:!1,17:!1,91:!1},Yt={};for(let n=1;n<20;n++)Dd["f".concat(n)]=111+n;let Ht=[],yd=null,x4="all";const li=new Map,uh=n=>Dd[n.toLowerCase()]||$o[n.toLowerCase()]||n.toUpperCase().charCodeAt(0),xoe=n=>Object.keys(Dd).find(e=>Dd[e]===n),woe=n=>Object.keys($o).find(e=>$o[e]===n);function w4(n){x4=n||"all"}function Ld(){return x4||"all"}function boe(){return Ht.slice(0)}function Poe(){return Ht.map(n=>xoe(n)||woe(n)||String.fromCharCode(n))}function Coe(){const n=[];return Object.keys(Yt).forEach(e=>{Yt[e].forEach(t=>{let{key:r,scope:s,mods:o,shortcut:i}=t;n.push({scope:s,shortcut:i,mods:o,keys:r.split("+").map(a=>uh(a))})})}),n}function _oe(n){const e=n.target||n.srcElement,{tagName:t}=e;let r=!0;const s=t==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(s||t==="TEXTAREA"||t==="SELECT")&&!e.readOnly)&&(r=!1),r}function Ioe(n){return typeof n=="string"&&(n=uh(n)),Ht.indexOf(n)!==-1}function Eoe(n,e){let t,r;n||(n=Ld());for(const s in Yt)if(Object.prototype.hasOwnProperty.call(Yt,s))for(t=Yt[s],r=0;r<t.length;)t[r].scope===n?t.splice(r,1).forEach(i=>{let{element:a}=i;return xP(a)}):r++;Ld()===n&&w4(e||"all")}function Toe(n){let e=n.keyCode||n.which||n.charCode;const t=Ht.indexOf(e);if(t>=0&&Ht.splice(t,1),n.key&&n.key.toLowerCase()==="meta"&&Ht.splice(0,Ht.length),(e===93||e===224)&&(e=91),e in _n){_n[e]=!1;for(const r in $o)$o[r]===e&&(Ps[r]=!1)}}function b4(n){if(typeof n>"u")Object.keys(Yt).forEach(s=>{Array.isArray(Yt[s])&&Yt[s].forEach(o=>Zp(o)),delete Yt[s]}),xP(null);else if(Array.isArray(n))n.forEach(s=>{s.key&&Zp(s)});else if(typeof n=="object")n.key&&Zp(n);else if(typeof n=="string"){for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;r<e;r++)t[r-1]=arguments[r];let[s,o]=t;typeof s=="function"&&(o=s,s=""),Zp({key:n,scope:s,method:o,splitKey:"+"})}}const Zp=n=>{let{key:e,scope:t,method:r,splitKey:s="+"}=n;v4(e).forEach(i=>{const a=i.split(s),c=a.length,d=a[c-1],h=d==="*"?"*":uh(d);if(!Yt[h])return;t||(t=Ld());const f=c>1?S4($o,a):[],g=[];Yt[h]=Yt[h].filter(y=>{const v=(r?y.method===r:!0)&&y.scope===t&&voe(y.mods,f);return v&&g.push(y.element),!v}),g.forEach(y=>xP(y))})};function Wk(n,e,t,r){if(e.element!==r)return;let s;if(e.scope===t||e.scope==="all"){s=e.mods.length>0;for(const o in _n)Object.prototype.hasOwnProperty.call(_n,o)&&(!_n[o]&&e.mods.indexOf(+o)>-1||_n[o]&&e.mods.indexOf(+o)===-1)&&(s=!1);(e.mods.length===0&&!_n[16]&&!_n[18]&&!_n[17]&&!_n[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(Ht),e.method(n,e)===!1&&(n.preventDefault?n.preventDefault():n.returnValue=!1,n.stopPropagation&&n.stopPropagation(),n.cancelBubble&&(n.cancelBubble=!0)))}}function Gk(n,e){const t=Yt["*"];let r=n.keyCode||n.which||n.charCode;if(!Ps.filter.call(this,n))return;if((r===93||r===224)&&(r=91),Ht.indexOf(r)===-1&&r!==229&&Ht.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const c=Mf[a];n[a]&&Ht.indexOf(c)===-1?Ht.push(c):!n[a]&&Ht.indexOf(c)>-1?Ht.splice(Ht.indexOf(c),1):a==="metaKey"&&n[a]&&(Ht=Ht.filter(d=>d in Mf||d===r))}),r in _n){_n[r]=!0;for(const a in $o)$o[a]===r&&(Ps[a]=!0);if(!t)return}for(const a in _n)Object.prototype.hasOwnProperty.call(_n,a)&&(_n[a]=n[Mf[a]]);n.getModifierState&&!(n.altKey&&!n.ctrlKey)&&n.getModifierState("AltGraph")&&(Ht.indexOf(17)===-1&&Ht.push(17),Ht.indexOf(18)===-1&&Ht.push(18),_n[17]=!0,_n[18]=!0);const s=Ld();if(t)for(let a=0;a<t.length;a++)t[a].scope===s&&(n.type==="keydown"&&t[a].keydown||n.type==="keyup"&&t[a].keyup)&&Wk(n,t[a],s,e);if(!(r in Yt))return;const o=Yt[r],i=o.length;for(let a=0;a<i;a++)if((n.type==="keydown"&&o[a].keydown||n.type==="keyup"&&o[a].keyup)&&o[a].key){const c=o[a],{splitKey:d}=c,h=c.key.split(d),f=[];for(let g=0;g<h.length;g++)f.push(uh(h[g]));f.sort().join("")===Ht.sort().join("")&&Wk(n,c,s,e)}}function Ps(n,e,t){Ht=[];const r=v4(n);let s=[],o="all",i=document,a=0,c=!1,d=!0,h="+",f=!1,g=!1;for(t===void 0&&typeof e=="function"&&(t=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(o=e.scope),e.element&&(i=e.element),e.keyup&&(c=e.keyup),e.keydown!==void 0&&(d=e.keydown),e.capture!==void 0&&(f=e.capture),typeof e.splitKey=="string"&&(h=e.splitKey),e.single===!0&&(g=!0)),typeof e=="string"&&(o=e),g&&b4(n,o);a<r.length;a++)n=r[a].split(h),s=[],n.length>1&&(s=S4($o,n)),n=n[n.length-1],n=n==="*"?"*":uh(n),n in Yt||(Yt[n]=[]),Yt[n].push({keyup:c,keydown:d,scope:o,mods:s,shortcut:r[a],method:t,key:r[a],splitKey:h,element:i});if(typeof i<"u"&&window){if(!li.has(i)){const y=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return Gk(v,i)},S=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;Gk(v,i),Toe(v)};li.set(i,{keydownListener:y,keyupListenr:S,capture:f}),uw(i,"keydown",y,f),uw(i,"keyup",S,f)}if(!yd){const y=()=>{Ht=[]};yd={listener:y,capture:f},uw(window,"focus",y,f)}}}function koe(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(Yt).forEach(t=>{Yt[t].filter(s=>s.scope===e&&s.shortcut===n).forEach(s=>{s&&s.method&&s.method()})})}function xP(n){const e=Object.values(Yt).flat();if(e.findIndex(r=>{let{element:s}=r;return s===n})<0){const{keydownListener:r,keyupListenr:s,capture:o}=li.get(n)||{};r&&s&&(Zu(n,"keyup",s,o),Zu(n,"keydown",r,o),li.delete(n))}if((e.length<=0||li.size<=0)&&(Object.keys(li).forEach(s=>{const{keydownListener:o,keyupListenr:i,capture:a}=li.get(s)||{};o&&i&&(Zu(s,"keyup",i,a),Zu(s,"keydown",o,a),li.delete(s))}),li.clear(),Object.keys(Yt).forEach(s=>delete Yt[s]),yd)){const{listener:s,capture:o}=yd;Zu(window,"focus",s,o),yd=null}}const dw={getPressedKeyString:Poe,setScope:w4,getScope:Ld,deleteScope:Eoe,getPressedKeyCodes:boe,getAllKeyCodes:Coe,isPressed:Ioe,filter:_oe,trigger:koe,unbind:b4,keyMap:Dd,modifier:$o,modifierMap:Mf};for(const n in dw)Object.prototype.hasOwnProperty.call(dw,n)&&(Ps[n]=dw[n]);if(typeof window<"u"){const n=window.hotkeys;Ps.noConflict=e=>(e&&window.hotkeys===Ps&&(window.hotkeys=n),Ps),window.hotkeys=Ps}const Vk=["copy","cut","paste","asset"];function Moe(){const n=te(),e=is(),t=wl(),r=V1(),s=se("is focused",()=>n.getInstanceState().isFocused,[n]);_.useEffect(()=>{if(!s)return;const o=new Array,i=(c,d)=>{Ps(c,{element:document.body},d),o.push(()=>{Ps.unbind(c,d)})},a=(c,d)=>{Ps(c,{element:document.body,keyup:!0,keydown:!1},d),o.push(()=>{Ps.unbind(c,d)})};for(const c of Object.values(t))c.kbd&&(e&&!c.readonlyOk||Vk.includes(c.id)||i(qk(c.kbd),d=>{ld(n)||(Je(d),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&n.getIsReadonly()||Vk.includes(c.id)||i(qk(c.kbd),d=>{ld(n)||(Je(d),c.onSelect("kbd"))});return i(",",c=>{if(ld(n)||n.inputs.keys.has("Comma"))return;Je(c),n.focus(),n.inputs.keys.add("Comma");const{x:d,y:h,z:f}=n.inputs.currentPagePoint,g=n.pageToScreen({x:d,y:h}),y={type:"pointer",name:"pointer_down",point:{x:g.x,y:g.y,z:f},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,metaKey:c.metaKey,accelKey:Gn(c),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(y)}),a(",",c=>{if(ld(n)||!n.inputs.keys.has("Comma"))return;n.inputs.keys.delete("Comma");const{x:d,y:h,z:f}=n.inputs.currentScreenPoint,g={type:"pointer",name:"pointer_up",point:{x:d,y:h,z:f},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,metaKey:c.metaKey,accelKey:Gn(c),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(g)}),()=>{o.forEach(c=>c())}},[t,r,e,n,s])}function qk(n){return Aoe(n).map(e=>{let t="";const r=e.split("");return r.length===1?t=r[0]:r[0]==="!"?t=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?t=`alt+shift+${r[2]}`:t=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?t=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?t=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:t=`cmd+${r[1]},ctrl+${r[1]}`:t=e,t}).join(",")}function Aoe(n){typeof n!="string"&&(n=""),n=n.replace(/\s/g,"");const e=n.split(",");let t=e.lastIndexOf("");for(;t>=0;)e[t-1]+=",",e.splice(t,1),t=e.lastIndexOf("");return e}function ld(n){return n.menus.hasAnyOpenMenus()||n.getEditingShapeId()!==null||n.getCrashingError()}const joe=_.createContext(!1),Roe={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,0:9};function Ooe({children:n}){const e=te(),t=Wc(),r=ur(),s=it(),o=_.useRef([]),i=Math.min(8,5+r),[a,c]=_.useState(0),d=_.useRef(null),[h,f]=_.useState(null),g=_.useMemo(()=>{const S=h?`:not([data-value="${h}"])`:"";return`
|
|
410
|
+
#${t}_main > *:nth-child(n + ${i+(h?1:2)})${S} {
|
|
411
|
+
display: none;
|
|
412
|
+
}
|
|
413
|
+
#${t}_more > *:nth-child(-n + ${i}) {
|
|
414
|
+
display: none;
|
|
415
|
+
}
|
|
416
|
+
`},[h,t,i]),y=Fg(()=>{var b;if(!d.current)return;const S=Array.from(d.current.children);c(S.length),S.findIndex(P=>P.getAttribute("data-value")===h)<=i&&f(null);const w=Array.from(d.current.children).findIndex(P=>P.getAttribute("aria-checked")==="true");w!==-1&&(w>=i&&f(S[w].getAttribute("data-value")),o.current=Array.from(((b=d.current)==null?void 0:b.children)??[]).filter(P=>!(P instanceof HTMLElement)||P.tagName.toLowerCase()!=="button"?!1:!!(P.offsetWidth||P.offsetHeight)))});return _.useLayoutEffect(()=>{y()}),_.useLayoutEffect(()=>{if(!d.current)return;const S=new MutationObserver(y);return S.observe(d.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{S.disconnect()}},[y]),_.useEffect(()=>{if(!e.options.enableToolbarKeyboardShortcuts)return;function S(v){var b;if(ld(e)||aj()||v.ctrlKey||v.metaKey||v.altKey||v.shiftKey)return;const w=Roe[v.key];typeof w=="number"&&(Je(v),(b=o.current[w])==null||b.click())}return document.addEventListener("keydown",S),()=>{document.removeEventListener("keydown",S)}},[e]),p.jsxs(p.Fragment,{children:[p.jsx("style",{children:g}),p.jsxs("div",{className:Le("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<Jt.TABLET_SM}),role:"radiogroup",children:[p.jsx("div",{id:`${t}_main`,ref:d,className:"tlui-toolbar__tools__list",children:p.jsx(Es,{type:"toolbar",sourceId:"toolbar",children:n})}),a>i+1&&p.jsx(joe.Provider,{value:!0,children:p.jsxs(hl,{id:"toolbar overflow",modal:!1,children:[p.jsx(pl,{children:p.jsx(Ne,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:p.jsx(nt,{icon:"chevron-up"})})}),p.jsx(fl,{side:"top",align:"center",children:p.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:p.jsx(Es,{type:"toolbar-overflow",sourceId:"toolbar",children:n})})})]})})]})]})}function Doe({activeToolId:n}){const e=te(),t=ur(),r=it(),s=se("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),o=se("current tool",()=>e.getCurrentTool(),[e]);return!n||!o.isLockable?null:p.jsx(Ne,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:Le("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<Jt.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:p.jsx(nt,{icon:s?"lock":"unlock",small:!0})})}const Loe=_.memo(function({children:e}){const t=te(),r=ur(),s=is(),o=se("current tool id",()=>t.getCurrentToolId(),[t]),i=_.useRef(null);Pa(i);const{ActionsMenu:a,QuickActions:c}=Ea(),d=t.options.actionShortcutsLocation==="menu"?!1:t.options.actionShortcutsLocation==="toolbar"?!0:r<Jt.TABLET;return p.jsx("div",{ref:i,className:"tlui-toolbar",children:p.jsxs("div",{className:"tlui-toolbar__inner",children:[p.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&p.jsxs("div",{className:"tlui-toolbar__extras",children:[d&&p.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[c&&p.jsx(c,{}),a&&p.jsx(a,{})]}),p.jsx(Doe,{activeToolId:o})]}),p.jsx(Ooe,{children:e??p.jsx(Hse,{})})]}),r<Jt.TABLET_SM&&!s&&p.jsx("div",{className:"tlui-toolbar__tools",children:p.jsx(Use,{})})]})})});function Foe(){const n=it();return p.jsxs("div",{className:Le("tlui-offline-indicator"),children:[n("status.offline"),p.jsx(Fo,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function Noe({maxWidth:n=420,ignoreRightWidth:e=0,stylePanelWidth:t=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:o}){const i=_.useRef(null),a=ur(),c=_.useCallback(()=>{const d=i.current;if(!d)return;const h=d.parentElement.parentElement,f=h.querySelector(".tlui-layout__top__left"),g=h.querySelector(".tlui-layout__top__right"),y=h.offsetWidth,S=f.offsetWidth,v=g.offsetWidth,w=d.offsetWidth-e;let b=(y-w)/2;y%2!==0&&(b-=.5);const P=S+r,k=d.offsetLeft,E=Math.min(y-v-S-2*r,n),M=Math.max(b,P)-k;g.offsetWidth>t&&a<=6?d.style.setProperty("max-width",E-s+"px"):d.style.setProperty("max-width",E+"px"),d.style.setProperty("transform",`translate(${M}px, 0px)`)},[a,e,r,n,s,t]);return _.useLayoutEffect(()=>{const d=i.current;if(!d)return;const h=d.parentElement.parentElement,f=h.querySelector(".tlui-layout__top__left"),g=h.querySelector(".tlui-layout__top__right"),y=new ResizeObserver(c);return y.observe(f),y.observe(g),y.observe(h),y.observe(d),c(),()=>{y.disconnect()}},[c]),_.useLayoutEffect(()=>{c()}),p.jsx("div",{ref:i,className:"tlui-top-panel__container",children:o})}function $oe(){const n=lZ()==="offline";return p.jsx(Noe,{children:n&&p.jsx(Foe,{})})}function zoe(){return p.jsxs(p.Fragment,{children:[p.jsx(ce,{actionId:"zoom-in",noClose:!0}),p.jsx(ce,{actionId:"zoom-out",noClose:!0}),p.jsx(kN,{}),p.jsx(MN,{}),p.jsx(AN,{})]})}const Boe=_.memo(function({children:e}){const t=fn(),[r,s]=Ei("zoom menu"),o=e??p.jsx(zoe,{});return p.jsxs(M1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[p.jsx(A1,{asChild:!0,dir:"ltr",children:p.jsx(Uoe,{})}),p.jsx(sm,{container:t,children:p.jsx(j1,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:p.jsx(Es,{type:"menu",sourceId:"zoom-menu",children:o})})})]})}),Uoe=_.forwardRef(function(e,t){const r=te(),s=ur(),o=se("zoom",()=>r.getZoomLevel(),[r]),i=it(),a=_.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return p.jsx(Ne,{ref:t,...e,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<Jt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:s<Jt.MOBILE?null:p.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(o*100),"%"]})})}),P4=_.createContext(null);function Hoe({overrides:n={},children:e}){const t=Vc(n),r=cm();return p.jsx(P4.Provider,{value:_.useMemo(()=>({ContextMenu:rre,ActionsMenu:Ane,HelpMenu:null,ZoomMenu:Boe,MainMenu:Fre,Minimap:Vre,StylePanel:Bse,PageMenu:Zre,NavigationPanel:Yre,Toolbar:Loe,KeyboardShortcutsDialog:Ire,QuickActions:tse,HelperButtons:Cre,DebugPanel:gre,DebugMenu:fre,MenuPanel:vre,SharePanel:r?lse:null,CursorChatBubble:r?ire:null,TopPanel:r?$oe:null,Dialogs:LQ,Toasts:zQ,...t}),[t,r]),children:e})}function Ea(){const n=_.useContext(P4);if(!n)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return n}const Koe=jn(function({overrides:e,components:t,assetUrls:r,onUiEvent:s,forceMobile:o,mediaMimeTypes:i,children:a}){const c=wa();return p.jsx(A5.Provider,{value:i,children:p.jsx(OX,{assetUrls:one(r),children:p.jsx(FX,{overrides:bQ(e),locale:(c==null?void 0:c.user.getLocale())??vo.locale,children:p.jsx(IG,{onEvent:s,children:p.jsx(RZ,{children:p.jsx(uZ,{context:"tla",children:p.jsx(cZ,{forceMobile:o,children:p.jsx(Hoe,{overrides:t,children:c?p.jsx(Woe,{overrides:e,children:a}):a})})})})})})})})});function Woe({overrides:n,children:e}){const t=PQ(n);return p.jsx(_Q,{overrides:t.actions,children:p.jsx(BQ,{overrides:t.tools,children:e})})}function Goe(){const n=te(),{addToast:e}=Ii();_.useEffect(()=>{function t({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 n.addListener("max-shapes",t),()=>{n.removeListener("max-shapes",t)}},[n,e])}const Voe=at.memo(function({renderDebugMenuItems:e,children:t,hideUi:r,components:s,...o}){return p.jsx(Koe,{...o,components:s,children:p.jsx(qoe,{hideUi:r,renderDebugMenuItems:e,children:t})})}),qoe=at.memo(function({children:e,hideUi:t,...r}){return p.jsxs(p.Fragment,{children:[e,t?null:p.jsx(Yoe,{...r})]})}),Yoe=at.memo(function(){const e=te(),t=it(),r=ur(),s=is(),o=se("focus",()=>e.getInstanceState().isFocusMode,[e]),i=se("debug",()=>e.getInstanceState().isDebugMode,[e]),{SharePanel:a,TopPanel:c,MenuPanel:d,StylePanel:h,Toolbar:f,HelpMenu:g,NavigationPanel:y,HelperButtons:S,DebugPanel:v,CursorChatBubble:w,Toasts:b,Dialogs:P}=Ea();Moe(),uQ(),Goe();const{"toggle-focus-mode":k}=wl();return p.jsxs("div",{className:Le("tlui-layout",{"tlui-layout__mobile":r<Jt.TABLET_SM}),"data-breakpoint":r,children:[o?p.jsx("div",{className:"tlui-layout__top",children:p.jsx(Ne,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>k.onSelect("menu"),children:p.jsx(nt,{icon:"dot"})})}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"tlui-layout__top",children:[p.jsxs("div",{className:"tlui-layout__top__left",children:[d&&p.jsx(d,{}),S&&p.jsx(S,{})]}),p.jsx("div",{className:"tlui-layout__top__center",children:c&&p.jsx(c,{})}),p.jsxs("div",{className:"tlui-layout__top__right",children:[a&&p.jsx(a,{}),h&&r>=Jt.TABLET_SM&&!s&&p.jsx(h,{})]})]}),p.jsxs("div",{className:"tlui-layout__bottom",children:[p.jsxs("div",{className:"tlui-layout__bottom__main",children:[y&&p.jsx(y,{}),f&&p.jsx(f,{}),g&&p.jsx(g,{})]}),i&&v&&p.jsx(v,{})]})]}),b&&p.jsx(b,{}),P&&p.jsx(P,{}),p.jsx(nne,{}),w&&p.jsx(w,{})]})});async function Xoe(n,e){const{url:t,style:r="normal",weight:s="500",display:o,featureSettings:i,stretch:a,unicodeRange:c,variant:d,format:h}=e,f={style:r,weight:s,display:o,featureSettings:i,stretch:a,unicodeRange:c,variant:d},g=new FontFace(n,`url(${t})`,f);return await g.load(),document.fonts.add(g),g.$$_url=t,g.$$_fontface=`
|
|
417
|
+
@font-face {
|
|
418
|
+
font-family: ${g.family};
|
|
419
|
+
font-stretch: ${g.stretch};
|
|
420
|
+
font-weight: ${g.weight};
|
|
421
|
+
font-style: ${g.style};
|
|
422
|
+
src: url("${t}") format("${h}")
|
|
423
|
+
}`,g}const Qp=(n,e)=>{const[t,r]=_.useState(2);return _.useEffect(()=>{let s=!1;return r(2),Xoe(n,e).then(()=>{s||r(0)}).catch(o=>{s||(console.error(o),r(1))}),()=>{s=!0}},[n,e]),t};function Zoe(n){return{draw:{url:n.fonts.draw,format:n.fonts.draw.split(".").pop()},serif:{url:n.fonts.serif,format:n.fonts.serif.split(".").pop()},sansSerif:{url:n.fonts.sansSerif,format:n.fonts.sansSerif.split(".").pop()},monospace:{url:n.fonts.monospace,format:n.fonts.monospace.split(".").pop()}}}function C4(n){const e=_.useMemo(()=>Zoe(n),[n]),t=[Qp("tldraw_draw",e.draw),Qp("tldraw_serif",e.serif),Qp("tldraw_sans",e.sansSerif),Qp("tldraw_mono",e.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Qoe(n){const{children:e,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:o,onMount:i,components:a={},shapeUtils:c=[],bindingUtils:d=[],tools:h=[],embeds:f,...g}=n,y=Vc(a),S=_.useMemo(()=>({Scribble:ik,ShapeIndicators:QQ,CollaboratorScribble:ik,SelectionForeground:YQ,SelectionBackground:VQ,Handles:UQ,...y}),[y]),v=ra(c),w=_.useMemo(()=>[...vF,...v],[v]),b=ra(d),P=_.useMemo(()=>[...$5,...b],[b]),k=ra(h),E=_.useMemo(()=>[...tne,...cee,...k],[k]),M=ra(s??Fd),A=ra(o??mg),R=_.useMemo(()=>[...M,...A],[M,A]),D=rN(g.assetUrls),{done:V,error:L}=C4(D);return L?p.jsx(GD,{children:"Could not load assets. Please refresh the page."}):V?(w.find(K=>K.type==="embed")&&f&&fg.setEmbedDefinitions(f),p.jsx(dG,{initialState:"select",...g,components:S,shapeUtils:w,bindingUtils:P,tools:E,children:p.jsxs(Voe,{...g,components:S,mediaMimeTypes:R,children:[p.jsx(Joe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:M,acceptedVideoMimeTypes:A,onMount:i}),e]})})):p.jsx(t1,{children:p.jsx(zb,{})})}function Joe({maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,onMount:s}){const o=te(),i=Ii(),a=it();VD(()=>{const h=[];return h.push(_te(o)),mJ(o,{maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,toasts:i,msg:a}),h.push(o.store.props.onMount(o)),h.push(s==null?void 0:s(o)),()=>{h.forEach(f=>f==null?void 0:f())}});const{Canvas:c}=$t(),{ContextMenu:d}=Ea();return d?p.jsx(d,{}):c?p.jsx(c,{}):null}_.memo(function(e){const[t,r]=_.useState(null),[s,o]=_.useState(null),i=ra(e.shapeUtils??[]),a=_.useMemo(()=>[...vF,...i],[i]),c=ra(e.bindingUtils??[]),d=_.useMemo(()=>[...$5,...c],[c]),h=SG({snapshot:e.snapshot,shapeUtils:a}),f=rN(e.assetUrls),{done:g,error:y}=C4(f),{pageId:S,bounds:v,scale:w,pixelRatio:b,background:P,padding:k,darkMode:E,preserveAspectRatio:M,format:A="svg",licenseKey:R}=e;return _.useLayoutEffect(()=>{if(!s||!h||!g)return;let D=!1;const V=document.createElement("div");s.appendChild(V),s.classList.add("tl-container","tl-theme__light");const L=new be({store:h,shapeUtils:a,bindingUtils:d,tools:[],getContainer:()=>V,licenseKey:R});S&&L.setCurrentPage(S);const U=L.getCurrentPageShapeIds();async function K(){const F=await L.toImage([...U],{bounds:v,scale:w,background:P,padding:k,darkMode:E,preserveAspectRatio:M,format:A});if(!F||D)return;const $=URL.createObjectURL(F.blob);r($),L.dispose()}return K(),()=>{D=!0}},[A,s,h,a,d,S,v,w,P,k,E,M,g,y,R,b]),_.useEffect(()=>()=>{t&&URL.revokeObjectURL(t)},[t]),y?p.jsx(GD,{children:"Could not load assets."}):g?p.jsx("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:t&&p.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):p.jsx(t1,{children:p.jsx(zb,{})})});_.memo(function({children:e}){const t=it(),r=ur(),s=_.useRef(null);Pa(s);const o=e??p.jsx(Ere,{});return r<Jt.MOBILE?null:p.jsx("div",{ref:s,className:"tlui-help-menu",children:p.jsxs(hl,{id:"help menu",children:[p.jsx(pl,{children:p.jsx(Ne,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:p.jsx(nt,{icon:"question-mark",small:!0})})}),p.jsx(fl,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:p.jsx(Es,{type:"menu",sourceId:"help-menu",children:o})})]})})});const eie=1,tie=rt({schemaVersion:Xn(1),storeVersion:nf,recordVersions:Uf(Xe,rt({version:nf,subTypeVersions:Uf(Xe,nf).optional(),subTypeKey:Xe.optional()}))}),nie=rt({schemaVersion:Xn(2),sequences:Uf(Xe,nf)}),rie=rt({tldrawFileFormatVersion:l9,schema:c9("schemaVersion",{1:tie,2:nie}),records:Tn(rt({id:Xe,typeName:Xe}).allowUnknownProperties())});function sie(n){var e;try{return!!((e=n.document)!=null&&e.version)}catch{return!1}}function oie({json:n,schema:e}){let t;try{t=rie.validate(JSON.parse(n))}catch(o){try{if(t=JSON.parse(n),sie(t))return rr.err({type:"v1File",data:t})}catch{}return rr.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>eie)return rr.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r,s;try{const o=iie(t.records);s=Object.fromEntries(o.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:s,schema:t.schema})}catch(o){return rr.err({type:"invalidRecords",cause:o})}if(r.type==="error")return rr.err({type:"migrationFailed",reason:r.reason});try{return rr.ok(Id({snapshot:{store:s,schema:t.schema},schema:e}))}catch(o){return rr.err({type:"invalidRecords",cause:o})}}function iie(n){const e=new Set;for(const t of n)t.typeName==="shape"&&"assetId"in t.props&&t.props.assetId&&e.add(t.props.assetId);return n.filter(t=>t.typeName!=="asset"||e.has(t.id))}ya("tldraw","3.8.0-canary.3f23e0d4c913","esm");function aie(){const[n,e]=_.useState();function t(r){globalThis.editor=r,n===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=oie({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.menus.clearOpenMenus())}return p.jsx("div",{style:{inset:0,position:"fixed"},children:p.jsx(Qoe,{assetUrls:c6(),onMount:t,store:n})})}l6.createRoot(document.querySelector("#root")).render(p.jsx(at.StrictMode,{children:p.jsx(aie,{})}));
|