@kitschpatrol/tldraw-cli 4.6.33 → 4.6.34

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.
Files changed (38) hide show
  1. package/bin/cli.js +785 -234
  2. package/dist/.DS_Store +0 -0
  3. package/dist/lib/index.js +784 -233
  4. package/dist/tldraw/assets/index-BK7ffB3e.css +1 -0
  5. package/dist/tldraw/assets/index-CCEXN6Jj.js +522 -0
  6. package/dist/tldraw/fonts/IBMPlexMono-Bold.woff2 +0 -0
  7. package/dist/tldraw/fonts/IBMPlexMono-BoldItalic.woff2 +0 -0
  8. package/dist/tldraw/fonts/IBMPlexMono-Medium.woff2 +0 -0
  9. package/dist/tldraw/fonts/IBMPlexMono-MediumItalic.woff2 +0 -0
  10. package/dist/tldraw/fonts/IBMPlexSans-Bold.woff2 +0 -0
  11. package/dist/tldraw/fonts/IBMPlexSans-BoldItalic.woff2 +0 -0
  12. package/dist/tldraw/fonts/IBMPlexSans-Medium.woff2 +0 -0
  13. package/dist/tldraw/fonts/IBMPlexSans-MediumItalic.woff2 +0 -0
  14. package/dist/tldraw/fonts/IBMPlexSerif-Bold.woff2 +0 -0
  15. package/dist/tldraw/fonts/IBMPlexSerif-BoldItalic.woff2 +0 -0
  16. package/dist/tldraw/fonts/IBMPlexSerif-Medium.woff2 +0 -0
  17. package/dist/tldraw/fonts/IBMPlexSerif-MediumItalic.woff2 +0 -0
  18. package/dist/tldraw/fonts/Shantell_Sans-Informal_Bold.woff2 +0 -0
  19. package/dist/tldraw/fonts/Shantell_Sans-Informal_Bold_Italic.woff2 +0 -0
  20. package/dist/tldraw/fonts/Shantell_Sans-Informal_Regular.woff2 +0 -0
  21. package/dist/tldraw/fonts/Shantell_Sans-Informal_Regular_Italic.woff2 +0 -0
  22. package/dist/tldraw/icons/icon/0_merged.svg +1 -1
  23. package/dist/tldraw/icons/icon/bold.svg +1 -0
  24. package/dist/tldraw/icons/icon/bulletList.svg +1 -0
  25. package/dist/tldraw/icons/icon/code.svg +1 -0
  26. package/dist/tldraw/icons/icon/heading.svg +1 -0
  27. package/dist/tldraw/icons/icon/highlight.svg +1 -0
  28. package/dist/tldraw/icons/icon/icon-names.json +9 -0
  29. package/dist/tldraw/icons/icon/italic.svg +1 -0
  30. package/dist/tldraw/icons/icon/list.svg +1 -0
  31. package/dist/tldraw/icons/icon/strike.svg +1 -0
  32. package/dist/tldraw/icons/icon/underline.svg +1 -0
  33. package/dist/tldraw/index.html +2 -2
  34. package/dist/tldraw/translations/main.json +10 -0
  35. package/package.json +13 -12
  36. package/dist/tldraw/assets/index-BkIYKf7d.css +0 -1
  37. package/dist/tldraw/assets/index-DipIZPz9.js +0 -419
  38. package/dist/tldraw/fonts/Shantell_Sans-Tldrawish.woff2 +0 -0
@@ -0,0 +1,522 @@
1
+ var rV=Object.defineProperty;var sV=(n,e,t)=>e in n?rV(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var O=(n,e,t)=>sV(n,typeof e!="symbol"?e+"":e,t);function iV(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 i=Object.getOwnPropertyDescriptor(r,s);i&&Object.defineProperty(n,s,i.get?i:{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 i of s)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function t(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=t(s);fetch(s.href,i)}})();var Ss=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ja(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var vw={exports:{}},Gh={},xw={exports:{}},pt={};/**
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 VM;function oV(){if(VM)return pt;VM=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"),i=Symbol.for("react.provider"),o=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),c=Symbol.for("react.memo"),d=Symbol.for("react.lazy"),f=Symbol.iterator;function p(H){return H===null||typeof H!="object"?null:(H=f&&H[f]||H["@@iterator"],typeof H=="function"?H:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},y=Object.assign,v={};function x(H,ne,ge){this.props=H,this.context=ne,this.refs=v,this.updater=ge||m}x.prototype.isReactComponent={},x.prototype.setState=function(H,ne){if(typeof H!="object"&&typeof H!="function"&&H!=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,H,ne,"setState")},x.prototype.forceUpdate=function(H){this.updater.enqueueForceUpdate(this,H,"forceUpdate")};function b(){}b.prototype=x.prototype;function C(H,ne,ge){this.props=H,this.context=ne,this.refs=v,this.updater=ge||m}var I=C.prototype=new b;I.constructor=C,y(I,x.prototype),I.isPureReactComponent=!0;var _=Array.isArray,T=Object.prototype.hasOwnProperty,A={current:null},R={key:!0,ref:!0,__self:!0,__source:!0};function j(H,ne,ge){var Pe,ce={},Be=null,Re=null;if(ne!=null)for(Pe in ne.ref!==void 0&&(Re=ne.ref),ne.key!==void 0&&(Be=""+ne.key),ne)T.call(ne,Pe)&&!R.hasOwnProperty(Pe)&&(ce[Pe]=ne[Pe]);var Ce=arguments.length-2;if(Ce===1)ce.children=ge;else if(1<Ce){for(var _e=Array(Ce),Ve=0;Ve<Ce;Ve++)_e[Ve]=arguments[Ve+2];ce.children=_e}if(H&&H.defaultProps)for(Pe in Ce=H.defaultProps,Ce)ce[Pe]===void 0&&(ce[Pe]=Ce[Pe]);return{$$typeof:n,type:H,key:Be,ref:Re,props:ce,_owner:A.current}}function K(H,ne){return{$$typeof:n,type:H.type,key:ne,ref:H.ref,props:H.props,_owner:H._owner}}function U(H){return typeof H=="object"&&H!==null&&H.$$typeof===n}function J(H){var ne={"=":"=0",":":"=2"};return"$"+H.replace(/[=:]/g,function(ge){return ne[ge]})}var z=/\/+/g;function N(H,ne){return typeof H=="object"&&H!==null&&H.key!=null?J(""+H.key):ne.toString(36)}function L(H,ne,ge,Pe,ce){var Be=typeof H;(Be==="undefined"||Be==="boolean")&&(H=null);var Re=!1;if(H===null)Re=!0;else switch(Be){case"string":case"number":Re=!0;break;case"object":switch(H.$$typeof){case n:case e:Re=!0}}if(Re)return Re=H,ce=ce(Re),H=Pe===""?"."+N(Re,0):Pe,_(ce)?(ge="",H!=null&&(ge=H.replace(z,"$&/")+"/"),L(ce,ne,ge,"",function(Ve){return Ve})):ce!=null&&(U(ce)&&(ce=K(ce,ge+(!ce.key||Re&&Re.key===ce.key?"":(""+ce.key).replace(z,"$&/")+"/")+H)),ne.push(ce)),1;if(Re=0,Pe=Pe===""?".":Pe+":",_(H))for(var Ce=0;Ce<H.length;Ce++){Be=H[Ce];var _e=Pe+N(Be,Ce);Re+=L(Be,ne,ge,_e,ce)}else if(_e=p(H),typeof _e=="function")for(H=_e.call(H),Ce=0;!(Be=H.next()).done;)Be=Be.value,_e=Pe+N(Be,Ce++),Re+=L(Be,ne,ge,_e,ce);else if(Be==="object")throw ne=String(H),Error("Objects are not valid as a React child (found: "+(ne==="[object Object]"?"object with keys {"+Object.keys(H).join(", ")+"}":ne)+"). If you meant to render a collection of children, use an array instead.");return Re}function V(H,ne,ge){if(H==null)return H;var Pe=[],ce=0;return L(H,Pe,"","",function(Be){return ne.call(ge,Be,ce++)}),Pe}function X(H){if(H._status===-1){var ne=H._result;ne=ne(),ne.then(function(ge){(H._status===0||H._status===-1)&&(H._status=1,H._result=ge)},function(ge){(H._status===0||H._status===-1)&&(H._status=2,H._result=ge)}),H._status===-1&&(H._status=0,H._result=ne)}if(H._status===1)return H._result.default;throw H._result}var W={current:null},$={transition:null},G={ReactCurrentDispatcher:W,ReactCurrentBatchConfig:$,ReactCurrentOwner:A};function re(){throw Error("act(...) is not supported in production builds of React.")}return pt.Children={map:V,forEach:function(H,ne,ge){V(H,function(){ne.apply(this,arguments)},ge)},count:function(H){var ne=0;return V(H,function(){ne++}),ne},toArray:function(H){return V(H,function(ne){return ne})||[]},only:function(H){if(!U(H))throw Error("React.Children.only expected to receive a single React element child.");return H}},pt.Component=x,pt.Fragment=t,pt.Profiler=s,pt.PureComponent=C,pt.StrictMode=r,pt.Suspense=l,pt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=G,pt.act=re,pt.cloneElement=function(H,ne,ge){if(H==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+H+".");var Pe=y({},H.props),ce=H.key,Be=H.ref,Re=H._owner;if(ne!=null){if(ne.ref!==void 0&&(Be=ne.ref,Re=A.current),ne.key!==void 0&&(ce=""+ne.key),H.type&&H.type.defaultProps)var Ce=H.type.defaultProps;for(_e in ne)T.call(ne,_e)&&!R.hasOwnProperty(_e)&&(Pe[_e]=ne[_e]===void 0&&Ce!==void 0?Ce[_e]:ne[_e])}var _e=arguments.length-2;if(_e===1)Pe.children=ge;else if(1<_e){Ce=Array(_e);for(var Ve=0;Ve<_e;Ve++)Ce[Ve]=arguments[Ve+2];Pe.children=Ce}return{$$typeof:n,type:H.type,key:ce,ref:Be,props:Pe,_owner:Re}},pt.createContext=function(H){return H={$$typeof:o,_currentValue:H,_currentValue2:H,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},H.Provider={$$typeof:i,_context:H},H.Consumer=H},pt.createElement=j,pt.createFactory=function(H){var ne=j.bind(null,H);return ne.type=H,ne},pt.createRef=function(){return{current:null}},pt.forwardRef=function(H){return{$$typeof:a,render:H}},pt.isValidElement=U,pt.lazy=function(H){return{$$typeof:d,_payload:{_status:-1,_result:H},_init:X}},pt.memo=function(H,ne){return{$$typeof:c,type:H,compare:ne===void 0?null:ne}},pt.startTransition=function(H){var ne=$.transition;$.transition={};try{H()}finally{$.transition=ne}},pt.unstable_act=re,pt.useCallback=function(H,ne){return W.current.useCallback(H,ne)},pt.useContext=function(H){return W.current.useContext(H)},pt.useDebugValue=function(){},pt.useDeferredValue=function(H){return W.current.useDeferredValue(H)},pt.useEffect=function(H,ne){return W.current.useEffect(H,ne)},pt.useId=function(){return W.current.useId()},pt.useImperativeHandle=function(H,ne,ge){return W.current.useImperativeHandle(H,ne,ge)},pt.useInsertionEffect=function(H,ne){return W.current.useInsertionEffect(H,ne)},pt.useLayoutEffect=function(H,ne){return W.current.useLayoutEffect(H,ne)},pt.useMemo=function(H,ne){return W.current.useMemo(H,ne)},pt.useReducer=function(H,ne,ge){return W.current.useReducer(H,ne,ge)},pt.useRef=function(H){return W.current.useRef(H)},pt.useState=function(H){return W.current.useState(H)},pt.useSyncExternalStore=function(H,ne,ge){return W.current.useSyncExternalStore(H,ne,ge)},pt.useTransition=function(){return W.current.useTransition()},pt.version="18.3.1",pt}var qM;function hk(){return qM||(qM=1,xw.exports=oV()),xw.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 GM;function aV(){if(GM)return Gh;GM=1;var n=hk(),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,i={key:!0,ref:!0,__self:!0,__source:!0};function o(a,l,c){var d,f={},p=null,m=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(m=l.ref);for(d in l)r.call(l,d)&&!i.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:e,type:a,key:p,ref:m,props:f,_owner:s.current}}return Gh.Fragment=t,Gh.jsx=o,Gh.jsxs=o,Gh}var YM;function lV(){return YM||(YM=1,vw.exports=aV()),vw.exports}var g=lV(),P=hk();const He=ja(P),cV=iV({__proto__:null,default:He},[P]);var im={},ww={exports:{}},cs={},bw={exports:{}},Cw={};/**
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 XM;function uV(){return XM||(XM=1,function(n){function e($,G){var re=$.length;$.push(G);e:for(;0<re;){var H=re-1>>>1,ne=$[H];if(0<s(ne,G))$[H]=G,$[re]=ne,re=H;else break e}}function t($){return $.length===0?null:$[0]}function r($){if($.length===0)return null;var G=$[0],re=$.pop();if(re!==G){$[0]=re;e:for(var H=0,ne=$.length,ge=ne>>>1;H<ge;){var Pe=2*(H+1)-1,ce=$[Pe],Be=Pe+1,Re=$[Be];if(0>s(ce,re))Be<ne&&0>s(Re,ce)?($[H]=Re,$[Be]=re,H=Be):($[H]=ce,$[Pe]=re,H=Pe);else if(Be<ne&&0>s(Re,re))$[H]=Re,$[Be]=re,H=Be;else break e}}return G}function s($,G){var re=$.sortIndex-G.sortIndex;return re!==0?re:$.id-G.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;n.unstable_now=function(){return i.now()}}else{var o=Date,a=o.now();n.unstable_now=function(){return o.now()-a}}var l=[],c=[],d=1,f=null,p=3,m=!1,y=!1,v=!1,x=typeof setTimeout=="function"?setTimeout:null,b=typeof clearTimeout=="function"?clearTimeout:null,C=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function I($){for(var G=t(c);G!==null;){if(G.callback===null)r(c);else if(G.startTime<=$)r(c),G.sortIndex=G.expirationTime,e(l,G);else break;G=t(c)}}function _($){if(v=!1,I($),!y)if(t(l)!==null)y=!0,X(T);else{var G=t(c);G!==null&&W(_,G.startTime-$)}}function T($,G){y=!1,v&&(v=!1,b(j),j=-1),m=!0;var re=p;try{for(I(G),f=t(l);f!==null&&(!(f.expirationTime>G)||$&&!J());){var H=f.callback;if(typeof H=="function"){f.callback=null,p=f.priorityLevel;var ne=H(f.expirationTime<=G);G=n.unstable_now(),typeof ne=="function"?f.callback=ne:f===t(l)&&r(l),I(G)}else r(l);f=t(l)}if(f!==null)var ge=!0;else{var Pe=t(c);Pe!==null&&W(_,Pe.startTime-G),ge=!1}return ge}finally{f=null,p=re,m=!1}}var A=!1,R=null,j=-1,K=5,U=-1;function J(){return!(n.unstable_now()-U<K)}function z(){if(R!==null){var $=n.unstable_now();U=$;var G=!0;try{G=R(!0,$)}finally{G?N():(A=!1,R=null)}}else A=!1}var N;if(typeof C=="function")N=function(){C(z)};else if(typeof MessageChannel<"u"){var L=new MessageChannel,V=L.port2;L.port1.onmessage=z,N=function(){V.postMessage(null)}}else N=function(){x(z,0)};function X($){R=$,A||(A=!0,N())}function W($,G){j=x(function(){$(n.unstable_now())},G)}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($){$.callback=null},n.unstable_continueExecution=function(){y||m||(y=!0,X(T))},n.unstable_forceFrameRate=function($){0>$||125<$?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):K=0<$?Math.floor(1e3/$):5},n.unstable_getCurrentPriorityLevel=function(){return p},n.unstable_getFirstCallbackNode=function(){return t(l)},n.unstable_next=function($){switch(p){case 1:case 2:case 3:var G=3;break;default:G=p}var re=p;p=G;try{return $()}finally{p=re}},n.unstable_pauseExecution=function(){},n.unstable_requestPaint=function(){},n.unstable_runWithPriority=function($,G){switch($){case 1:case 2:case 3:case 4:case 5:break;default:$=3}var re=p;p=$;try{return G()}finally{p=re}},n.unstable_scheduleCallback=function($,G,re){var H=n.unstable_now();switch(typeof re=="object"&&re!==null?(re=re.delay,re=typeof re=="number"&&0<re?H+re:H):re=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=re+ne,$={id:d++,callback:G,priorityLevel:$,startTime:re,expirationTime:ne,sortIndex:-1},re>H?($.sortIndex=re,e(c,$),t(l)===null&&$===t(c)&&(v?(b(j),j=-1):v=!0,W(_,re-H))):($.sortIndex=ne,e(l,$),y||m||(y=!0,X(T))),$},n.unstable_shouldYield=J,n.unstable_wrapCallback=function($){var G=p;return function(){var re=p;p=G;try{return $.apply(this,arguments)}finally{p=re}}}}(Cw)),Cw}var ZM;function dV(){return ZM||(ZM=1,bw.exports=uV()),bw.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 JM;function hV(){if(JM)return cs;JM=1;var n=hk(),e=dV();function t(u){for(var h="https://reactjs.org/docs/error-decoder.html?invariant="+u,S=1;S<arguments.length;S++)h+="&args[]="+encodeURIComponent(arguments[S]);return"Minified React error #"+u+"; visit "+h+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var r=new Set,s={};function i(u,h){o(u,h),o(u+"Capture",h)}function o(u,h){for(s[u]=h,u=0;u<h.length;u++)r.add(h[u])}var a=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),l=Object.prototype.hasOwnProperty,c=/^[: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]*$/,d={},f={};function p(u){return l.call(f,u)?!0:l.call(d,u)?!1:c.test(u)?f[u]=!0:(d[u]=!0,!1)}function m(u,h,S,w){if(S!==null&&S.type===0)return!1;switch(typeof h){case"function":case"symbol":return!0;case"boolean":return w?!1:S!==null?!S.acceptsBooleans:(u=u.toLowerCase().slice(0,5),u!=="data-"&&u!=="aria-");default:return!1}}function y(u,h,S,w){if(h===null||typeof h>"u"||m(u,h,S,w))return!0;if(w)return!1;if(S!==null)switch(S.type){case 3:return!h;case 4:return h===!1;case 5:return isNaN(h);case 6:return isNaN(h)||1>h}return!1}function v(u,h,S,w,k,M,D){this.acceptsBooleans=h===2||h===3||h===4,this.attributeName=w,this.attributeNamespace=k,this.mustUseProperty=S,this.propertyName=u,this.type=h,this.sanitizeURL=M,this.removeEmptyString=D}var x={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(u){x[u]=new v(u,0,!1,u,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(u){var h=u[0];x[h]=new v(h,1,!1,u[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(u){x[u]=new v(u,2,!1,u.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(u){x[u]=new v(u,2,!1,u,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(u){x[u]=new v(u,3,!1,u.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(u){x[u]=new v(u,3,!0,u,null,!1,!1)}),["capture","download"].forEach(function(u){x[u]=new v(u,4,!1,u,null,!1,!1)}),["cols","rows","size","span"].forEach(function(u){x[u]=new v(u,6,!1,u,null,!1,!1)}),["rowSpan","start"].forEach(function(u){x[u]=new v(u,5,!1,u.toLowerCase(),null,!1,!1)});var b=/[\-:]([a-z])/g;function C(u){return u[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(u){var h=u.replace(b,C);x[h]=new v(h,1,!1,u,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(u){var h=u.replace(b,C);x[h]=new v(h,1,!1,u,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(u){var h=u.replace(b,C);x[h]=new v(h,1,!1,u,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(u){x[u]=new v(u,1,!1,u.toLowerCase(),null,!1,!1)}),x.xlinkHref=new v("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(u){x[u]=new v(u,1,!1,u.toLowerCase(),null,!0,!0)});function I(u,h,S,w){var k=x.hasOwnProperty(h)?x[h]:null;(k!==null?k.type!==0:w||!(2<h.length)||h[0]!=="o"&&h[0]!=="O"||h[1]!=="n"&&h[1]!=="N")&&(y(h,S,k,w)&&(S=null),w||k===null?p(h)&&(S===null?u.removeAttribute(h):u.setAttribute(h,""+S)):k.mustUseProperty?u[k.propertyName]=S===null?k.type===3?!1:"":S:(h=k.attributeName,w=k.attributeNamespace,S===null?u.removeAttribute(h):(k=k.type,S=k===3||k===4&&S===!0?"":""+S,w?u.setAttributeNS(w,h,S):u.setAttribute(h,S))))}var _=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,T=Symbol.for("react.element"),A=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),j=Symbol.for("react.strict_mode"),K=Symbol.for("react.profiler"),U=Symbol.for("react.provider"),J=Symbol.for("react.context"),z=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),V=Symbol.for("react.memo"),X=Symbol.for("react.lazy"),W=Symbol.for("react.offscreen"),$=Symbol.iterator;function G(u){return u===null||typeof u!="object"?null:(u=$&&u[$]||u["@@iterator"],typeof u=="function"?u:null)}var re=Object.assign,H;function ne(u){if(H===void 0)try{throw Error()}catch(S){var h=S.stack.trim().match(/\n( *(at )?)/);H=h&&h[1]||""}return`
34
+ `+H+u}var ge=!1;function Pe(u,h){if(!u||ge)return"";ge=!0;var S=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(h)if(h=function(){throw Error()},Object.defineProperty(h.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(h,[])}catch(oe){var w=oe}Reflect.construct(u,[],h)}else{try{h.call()}catch(oe){w=oe}u.call(h.prototype)}else{try{throw Error()}catch(oe){w=oe}u()}}catch(oe){if(oe&&w&&typeof oe.stack=="string"){for(var k=oe.stack.split(`
35
+ `),M=w.stack.split(`
36
+ `),D=k.length-1,B=M.length-1;1<=D&&0<=B&&k[D]!==M[B];)B--;for(;1<=D&&0<=B;D--,B--)if(k[D]!==M[B]){if(D!==1||B!==1)do if(D--,B--,0>B||k[D]!==M[B]){var q=`
37
+ `+k[D].replace(" at new "," at ");return u.displayName&&q.includes("<anonymous>")&&(q=q.replace("<anonymous>",u.displayName)),q}while(1<=D&&0<=B);break}}}finally{ge=!1,Error.prepareStackTrace=S}return(u=u?u.displayName||u.name:"")?ne(u):""}function ce(u){switch(u.tag){case 5:return ne(u.type);case 16:return ne("Lazy");case 13:return ne("Suspense");case 19:return ne("SuspenseList");case 0:case 2:case 15:return u=Pe(u.type,!1),u;case 11:return u=Pe(u.type.render,!1),u;case 1:return u=Pe(u.type,!0),u;default:return""}}function Be(u){if(u==null)return null;if(typeof u=="function")return u.displayName||u.name||null;if(typeof u=="string")return u;switch(u){case R:return"Fragment";case A:return"Portal";case K:return"Profiler";case j:return"StrictMode";case N:return"Suspense";case L:return"SuspenseList"}if(typeof u=="object")switch(u.$$typeof){case J:return(u.displayName||"Context")+".Consumer";case U:return(u._context.displayName||"Context")+".Provider";case z:var h=u.render;return u=u.displayName,u||(u=h.displayName||h.name||"",u=u!==""?"ForwardRef("+u+")":"ForwardRef"),u;case V:return h=u.displayName||null,h!==null?h:Be(u.type)||"Memo";case X:h=u._payload,u=u._init;try{return Be(u(h))}catch{}}return null}function Re(u){var h=u.type;switch(u.tag){case 24:return"Cache";case 9:return(h.displayName||"Context")+".Consumer";case 10:return(h._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return u=h.render,u=u.displayName||u.name||"",h.displayName||(u!==""?"ForwardRef("+u+")":"ForwardRef");case 7:return"Fragment";case 5:return h;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Be(h);case 8:return h===j?"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 h=="function")return h.displayName||h.name||null;if(typeof h=="string")return h}return null}function Ce(u){switch(typeof u){case"boolean":case"number":case"string":case"undefined":return u;case"object":return u;default:return""}}function _e(u){var h=u.type;return(u=u.nodeName)&&u.toLowerCase()==="input"&&(h==="checkbox"||h==="radio")}function Ve(u){var h=_e(u)?"checked":"value",S=Object.getOwnPropertyDescriptor(u.constructor.prototype,h),w=""+u[h];if(!u.hasOwnProperty(h)&&typeof S<"u"&&typeof S.get=="function"&&typeof S.set=="function"){var k=S.get,M=S.set;return Object.defineProperty(u,h,{configurable:!0,get:function(){return k.call(this)},set:function(D){w=""+D,M.call(this,D)}}),Object.defineProperty(u,h,{enumerable:S.enumerable}),{getValue:function(){return w},setValue:function(D){w=""+D},stopTracking:function(){u._valueTracker=null,delete u[h]}}}}function it(u){u._valueTracker||(u._valueTracker=Ve(u))}function cn(u){if(!u)return!1;var h=u._valueTracker;if(!h)return!0;var S=h.getValue(),w="";return u&&(w=_e(u)?u.checked?"true":"false":u.value),u=w,u!==S?(h.setValue(u),!0):!1}function It(u){if(u=u||(typeof document<"u"?document:void 0),typeof u>"u")return null;try{return u.activeElement||u.body}catch{return u.body}}function Jt(u,h){var S=h.checked;return re({},h,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:S??u._wrapperState.initialChecked})}function jt(u,h){var S=h.defaultValue==null?"":h.defaultValue,w=h.checked!=null?h.checked:h.defaultChecked;S=Ce(h.value!=null?h.value:S),u._wrapperState={initialChecked:w,initialValue:S,controlled:h.type==="checkbox"||h.type==="radio"?h.checked!=null:h.value!=null}}function Mt(u,h){h=h.checked,h!=null&&I(u,"checked",h,!1)}function Yr(u,h){Mt(u,h);var S=Ce(h.value),w=h.type;if(S!=null)w==="number"?(S===0&&u.value===""||u.value!=S)&&(u.value=""+S):u.value!==""+S&&(u.value=""+S);else if(w==="submit"||w==="reset"){u.removeAttribute("value");return}h.hasOwnProperty("value")?Zr(u,h.type,S):h.hasOwnProperty("defaultValue")&&Zr(u,h.type,Ce(h.defaultValue)),h.checked==null&&h.defaultChecked!=null&&(u.defaultChecked=!!h.defaultChecked)}function Xr(u,h,S){if(h.hasOwnProperty("value")||h.hasOwnProperty("defaultValue")){var w=h.type;if(!(w!=="submit"&&w!=="reset"||h.value!==void 0&&h.value!==null))return;h=""+u._wrapperState.initialValue,S||h===u.value||(u.value=h),u.defaultValue=h}S=u.name,S!==""&&(u.name=""),u.defaultChecked=!!u._wrapperState.initialChecked,S!==""&&(u.name=S)}function Zr(u,h,S){(h!=="number"||It(u.ownerDocument)!==u)&&(S==null?u.defaultValue=""+u._wrapperState.initialValue:u.defaultValue!==""+S&&(u.defaultValue=""+S))}var Jr=Array.isArray;function Zs(u,h,S,w){if(u=u.options,h){h={};for(var k=0;k<S.length;k++)h["$"+S[k]]=!0;for(S=0;S<u.length;S++)k=h.hasOwnProperty("$"+u[S].value),u[S].selected!==k&&(u[S].selected=k),k&&w&&(u[S].defaultSelected=!0)}else{for(S=""+Ce(S),h=null,k=0;k<u.length;k++){if(u[k].value===S){u[k].selected=!0,w&&(u[k].defaultSelected=!0);return}h!==null||u[k].disabled||(h=u[k])}h!==null&&(h.selected=!0)}}function rc(u,h){if(h.dangerouslySetInnerHTML!=null)throw Error(t(91));return re({},h,{value:void 0,defaultValue:void 0,children:""+u._wrapperState.initialValue})}function Su(u,h){var S=h.value;if(S==null){if(S=h.children,h=h.defaultValue,S!=null){if(h!=null)throw Error(t(92));if(Jr(S)){if(1<S.length)throw Error(t(93));S=S[0]}h=S}h==null&&(h=""),S=h}u._wrapperState={initialValue:Ce(S)}}function vu(u,h){var S=Ce(h.value),w=Ce(h.defaultValue);S!=null&&(S=""+S,S!==u.value&&(u.value=S),h.defaultValue==null&&u.defaultValue!==S&&(u.defaultValue=S)),w!=null&&(u.defaultValue=""+w)}function xu(u){var h=u.textContent;h===u._wrapperState.initialValue&&h!==""&&h!==null&&(u.value=h)}function wu(u){switch(u){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 ao(u,h){return u==null||u==="http://www.w3.org/1999/xhtml"?wu(h):u==="http://www.w3.org/2000/svg"&&h==="foreignObject"?"http://www.w3.org/1999/xhtml":u}var Ii,sc=function(u){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(h,S,w,k){MSApp.execUnsafeLocalFunction(function(){return u(h,S,w,k)})}:u}(function(u,h){if(u.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in u)u.innerHTML=h;else{for(Ii=Ii||document.createElement("div"),Ii.innerHTML="<svg>"+h.valueOf().toString()+"</svg>",h=Ii.firstChild;u.firstChild;)u.removeChild(u.firstChild);for(;h.firstChild;)u.appendChild(h.firstChild)}});function ae(u,h){if(h){var S=u.firstChild;if(S&&S===u.lastChild&&S.nodeType===3){S.nodeValue=h;return}}u.textContent=h}var be={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},Xe=["Webkit","ms","Moz","O"];Object.keys(be).forEach(function(u){Xe.forEach(function(h){h=h+u.charAt(0).toUpperCase()+u.substring(1),be[h]=be[u]})});function At(u,h,S){return h==null||typeof h=="boolean"||h===""?"":S||typeof h!="number"||h===0||be.hasOwnProperty(u)&&be[u]?(""+h).trim():h+"px"}function Js(u,h){u=u.style;for(var S in h)if(h.hasOwnProperty(S)){var w=S.indexOf("--")===0,k=At(S,h[S],w);S==="float"&&(S="cssFloat"),w?u.setProperty(S,k):u[S]=k}}var Qr=re({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 Yo(u,h){if(h){if(Qr[u]&&(h.children!=null||h.dangerouslySetInnerHTML!=null))throw Error(t(137,u));if(h.dangerouslySetInnerHTML!=null){if(h.children!=null)throw Error(t(60));if(typeof h.dangerouslySetInnerHTML!="object"||!("__html"in h.dangerouslySetInnerHTML))throw Error(t(61))}if(h.style!=null&&typeof h.style!="object")throw Error(t(62))}}function Is(u,h){if(u.indexOf("-")===-1)return typeof h.is=="string";switch(u){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 _s=null;function es(u){return u=u.target||u.srcElement||window,u.correspondingUseElement&&(u=u.correspondingUseElement),u.nodeType===3?u.parentNode:u}var Ts=null,ts=null,_i=null;function bu(u){if(u=Rh(u)){if(typeof Ts!="function")throw Error(t(280));var h=u.stateNode;h&&(h=xg(h),Ts(u.stateNode,u.type,h))}}function Ka(u){ts?_i?_i.push(u):_i=[u]:ts=u}function Cu(){if(ts){var u=ts,h=_i;if(_i=ts=null,bu(u),h)for(u=0;u<h.length;u++)bu(h[u])}}function Pu(u,h){return u(h)}function Eu(){}var Xo=!1;function tg(u,h,S){if(Xo)return u(h,S);Xo=!0;try{return Pu(u,h,S)}finally{Xo=!1,(ts!==null||_i!==null)&&(Eu(),Cu())}}function ic(u,h){var S=u.stateNode;if(S===null)return null;var w=xg(S);if(w===null)return null;S=w[h];e:switch(h){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(w=!w.disabled)||(u=u.type,w=!(u==="button"||u==="input"||u==="select"||u==="textarea")),u=!w;break e;default:u=!1}if(u)return null;if(S&&typeof S!="function")throw Error(t(231,h,typeof S));return S}var ph=!1;if(a)try{var oc={};Object.defineProperty(oc,"passive",{get:function(){ph=!0}}),window.addEventListener("test",oc,oc),window.removeEventListener("test",oc,oc)}catch{ph=!1}function D0(u,h,S,w,k,M,D,B,q){var oe=Array.prototype.slice.call(arguments,3);try{h.apply(S,oe)}catch(fe){this.onError(fe)}}var Wa=!1,Va=null,Qs=!1,gh=null,j0={onError:function(u){Wa=!0,Va=u}};function N0(u,h,S,w,k,M,D,B,q){Wa=!1,Va=null,D0.apply(j0,arguments)}function L0(u,h,S,w,k,M,D,B,q){if(N0.apply(this,arguments),Wa){if(Wa){var oe=Va;Wa=!1,Va=null}else throw Error(t(198));Qs||(Qs=!0,gh=oe)}}function Zo(u){var h=u,S=u;if(u.alternate)for(;h.return;)h=h.return;else{u=h;do h=u,(h.flags&4098)!==0&&(S=h.return),u=h.return;while(u)}return h.tag===3?S:null}function ei(u){if(u.tag===13){var h=u.memoizedState;if(h===null&&(u=u.alternate,u!==null&&(h=u.memoizedState)),h!==null)return h.dehydrated}return null}function ng(u){if(Zo(u)!==u)throw Error(t(188))}function F0(u){var h=u.alternate;if(!h){if(h=Zo(u),h===null)throw Error(t(188));return h!==u?null:u}for(var S=u,w=h;;){var k=S.return;if(k===null)break;var M=k.alternate;if(M===null){if(w=k.return,w!==null){S=w;continue}break}if(k.child===M.child){for(M=k.child;M;){if(M===S)return ng(k),u;if(M===w)return ng(k),h;M=M.sibling}throw Error(t(188))}if(S.return!==w.return)S=k,w=M;else{for(var D=!1,B=k.child;B;){if(B===S){D=!0,S=k,w=M;break}if(B===w){D=!0,w=k,S=M;break}B=B.sibling}if(!D){for(B=M.child;B;){if(B===S){D=!0,S=M,w=k;break}if(B===w){D=!0,w=M,S=k;break}B=B.sibling}if(!D)throw Error(t(189))}}if(S.alternate!==w)throw Error(t(190))}if(S.tag!==3)throw Error(t(188));return S.stateNode.current===S?u:h}function rg(u){return u=F0(u),u!==null?sg(u):null}function sg(u){if(u.tag===5||u.tag===6)return u;for(u=u.child;u!==null;){var h=sg(u);if(h!==null)return h;u=u.sibling}return null}var ig=e.unstable_scheduleCallback,lo=e.unstable_cancelCallback,z0=e.unstable_shouldYield,$0=e.unstable_requestPaint,nn=e.unstable_now,B0=e.unstable_getCurrentPriorityLevel,mh=e.unstable_ImmediatePriority,ac=e.unstable_UserBlockingPriority,ku=e.unstable_NormalPriority,U0=e.unstable_LowPriority,Ti=e.unstable_IdlePriority,Iu=null,ti=null;function H0(u){if(ti&&typeof ti.onCommitFiberRoot=="function")try{ti.onCommitFiberRoot(Iu,u,void 0,(u.current.flags&128)===128)}catch{}}var Ms=Math.clz32?Math.clz32:_u,K0=Math.log,W0=Math.LN2;function _u(u){return u>>>=0,u===0?32:31-(K0(u)/W0|0)|0}var Tu=64,co=4194304;function qa(u){switch(u&-u){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 u&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return u&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return u}}function lc(u,h){var S=u.pendingLanes;if(S===0)return 0;var w=0,k=u.suspendedLanes,M=u.pingedLanes,D=S&268435455;if(D!==0){var B=D&~k;B!==0?w=qa(B):(M&=D,M!==0&&(w=qa(M)))}else D=S&~k,D!==0?w=qa(D):M!==0&&(w=qa(M));if(w===0)return 0;if(h!==0&&h!==w&&(h&k)===0&&(k=w&-w,M=h&-h,k>=M||k===16&&(M&4194240)!==0))return h;if((w&4)!==0&&(w|=S&16),h=u.entangledLanes,h!==0)for(u=u.entanglements,h&=w;0<h;)S=31-Ms(h),k=1<<S,w|=u[S],h&=~k;return w}function V0(u,h){switch(u){case 1:case 2:case 4:return h+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 h+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 q0(u,h){for(var S=u.suspendedLanes,w=u.pingedLanes,k=u.expirationTimes,M=u.pendingLanes;0<M;){var D=31-Ms(M),B=1<<D,q=k[D];q===-1?((B&S)===0||(B&w)!==0)&&(k[D]=V0(B,h)):q<=h&&(u.expiredLanes|=B),M&=~B}}function yh(u){return u=u.pendingLanes&-1073741825,u!==0?u:u&1073741824?1073741824:0}function og(){var u=Tu;return Tu<<=1,(Tu&4194240)===0&&(Tu=64),u}function Mu(u){for(var h=[],S=0;31>S;S++)h.push(u);return h}function cc(u,h,S){u.pendingLanes|=h,h!==536870912&&(u.suspendedLanes=0,u.pingedLanes=0),u=u.eventTimes,h=31-Ms(h),u[h]=S}function G0(u,h){var S=u.pendingLanes&~h;u.pendingLanes=h,u.suspendedLanes=0,u.pingedLanes=0,u.expiredLanes&=h,u.mutableReadLanes&=h,u.entangledLanes&=h,h=u.entanglements;var w=u.eventTimes;for(u=u.expirationTimes;0<S;){var k=31-Ms(S),M=1<<k;h[k]=0,w[k]=-1,u[k]=-1,S&=~M}}function Au(u,h){var S=u.entangledLanes|=h;for(u=u.entanglements;S;){var w=31-Ms(S),k=1<<w;k&h|u[w]&h&&(u[w]|=h),S&=~k}}var vt=0;function Jo(u){return u&=-u,1<u?4<u?(u&268435455)!==0?16:536870912:4:1}var ag,Sh,Mi,lg,cg,vh=!1,Ou=[],uo=null,ur=null,Ai=null,uc=new Map,ho=new Map,fo=[],xh="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 ug(u,h){switch(u){case"focusin":case"focusout":uo=null;break;case"dragenter":case"dragleave":ur=null;break;case"mouseover":case"mouseout":Ai=null;break;case"pointerover":case"pointerout":uc.delete(h.pointerId);break;case"gotpointercapture":case"lostpointercapture":ho.delete(h.pointerId)}}function Ga(u,h,S,w,k,M){return u===null||u.nativeEvent!==M?(u={blockedOn:h,domEventName:S,eventSystemFlags:w,nativeEvent:M,targetContainers:[k]},h!==null&&(h=Rh(h),h!==null&&Sh(h)),u):(u.eventSystemFlags|=w,h=u.targetContainers,k!==null&&h.indexOf(k)===-1&&h.push(k),u)}function dg(u,h,S,w,k){switch(h){case"focusin":return uo=Ga(uo,u,h,S,w,k),!0;case"dragenter":return ur=Ga(ur,u,h,S,w,k),!0;case"mouseover":return Ai=Ga(Ai,u,h,S,w,k),!0;case"pointerover":var M=k.pointerId;return uc.set(M,Ga(uc.get(M)||null,u,h,S,w,k)),!0;case"gotpointercapture":return M=k.pointerId,ho.set(M,Ga(ho.get(M)||null,u,h,S,w,k)),!0}return!1}function wh(u){var h=fc(u.target);if(h!==null){var S=Zo(h);if(S!==null){if(h=S.tag,h===13){if(h=ei(S),h!==null){u.blockedOn=h,cg(u.priority,function(){Mi(S)});return}}else if(h===3&&S.stateNode.current.memoizedState.isDehydrated){u.blockedOn=S.tag===3?S.stateNode.containerInfo:null;return}}}u.blockedOn=null}function po(u){if(u.blockedOn!==null)return!1;for(var h=u.targetContainers;0<h.length;){var S=zt(u.domEventName,u.eventSystemFlags,h[0],u.nativeEvent);if(S===null){S=u.nativeEvent;var w=new S.constructor(S.type,S);_s=w,S.target.dispatchEvent(w),_s=null}else return h=Rh(S),h!==null&&Sh(h),u.blockedOn=S,!1;h.shift()}return!0}function bh(u,h,S){po(u)&&S.delete(h)}function Y0(){vh=!1,uo!==null&&po(uo)&&(uo=null),ur!==null&&po(ur)&&(ur=null),Ai!==null&&po(Ai)&&(Ai=null),uc.forEach(bh),ho.forEach(bh)}function dc(u,h){u.blockedOn===h&&(u.blockedOn=null,vh||(vh=!0,e.unstable_scheduleCallback(e.unstable_NormalPriority,Y0)))}function hc(u){function h(k){return dc(k,u)}if(0<Ou.length){dc(Ou[0],u);for(var S=1;S<Ou.length;S++){var w=Ou[S];w.blockedOn===u&&(w.blockedOn=null)}}for(uo!==null&&dc(uo,u),ur!==null&&dc(ur,u),Ai!==null&&dc(Ai,u),uc.forEach(h),ho.forEach(h),S=0;S<fo.length;S++)w=fo[S],w.blockedOn===u&&(w.blockedOn=null);for(;0<fo.length&&(S=fo[0],S.blockedOn===null);)wh(S),S.blockedOn===null&&fo.shift()}var F=_.ReactCurrentBatchConfig,Z=!0;function de(u,h,S,w){var k=vt,M=F.transition;F.transition=null;try{vt=1,Tt(u,h,S,w)}finally{vt=k,F.transition=M}}function Ae(u,h,S,w){var k=vt,M=F.transition;F.transition=null;try{vt=4,Tt(u,h,S,w)}finally{vt=k,F.transition=M}}function Tt(u,h,S,w){if(Z){var k=zt(u,h,S,w);if(k===null)cx(u,h,w,et,S),ug(u,w);else if(dg(k,u,h,S,w))w.stopPropagation();else if(ug(u,w),h&4&&-1<xh.indexOf(u)){for(;k!==null;){var M=Rh(k);if(M!==null&&ag(M),M=zt(u,h,S,w),M===null&&cx(u,h,w,et,S),M===k)break;k=M}k!==null&&w.stopPropagation()}else cx(u,h,w,null,S)}}var et=null;function zt(u,h,S,w){if(et=null,u=es(w),u=fc(u),u!==null)if(h=Zo(u),h===null)u=null;else if(S=h.tag,S===13){if(u=ei(h),u!==null)return u;u=null}else if(S===3){if(h.stateNode.current.memoizedState.isDehydrated)return h.tag===3?h.stateNode.containerInfo:null;u=null}else h!==u&&(u=null);return et=u,null}function mn(u){switch(u){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(B0()){case mh:return 1;case ac:return 4;case ku:case U0:return 16;case Ti:return 536870912;default:return 16}default:return 16}}var $t=null,Nt=null,Dn=null;function ns(){if(Dn)return Dn;var u,h=Nt,S=h.length,w,k="value"in $t?$t.value:$t.textContent,M=k.length;for(u=0;u<S&&h[u]===k[u];u++);var D=S-u;for(w=1;w<=D&&h[S-w]===k[M-w];w++);return Dn=k.slice(u,1<w?1-w:void 0)}function yn(u){var h=u.keyCode;return"charCode"in u?(u=u.charCode,u===0&&h===13&&(u=13)):u=h,u===10&&(u=13),32<=u||u===13?u:0}function qn(){return!0}function Or(){return!1}function un(u){function h(S,w,k,M,D){this._reactName=S,this._targetInst=k,this.type=w,this.nativeEvent=M,this.target=D,this.currentTarget=null;for(var B in u)u.hasOwnProperty(B)&&(S=u[B],this[B]=S?S(M):M[B]);return this.isDefaultPrevented=(M.defaultPrevented!=null?M.defaultPrevented:M.returnValue===!1)?qn:Or,this.isPropagationStopped=Or,this}return re(h.prototype,{preventDefault:function(){this.defaultPrevented=!0;var S=this.nativeEvent;S&&(S.preventDefault?S.preventDefault():typeof S.returnValue!="unknown"&&(S.returnValue=!1),this.isDefaultPrevented=qn)},stopPropagation:function(){var S=this.nativeEvent;S&&(S.stopPropagation?S.stopPropagation():typeof S.cancelBubble!="unknown"&&(S.cancelBubble=!0),this.isPropagationStopped=qn)},persist:function(){},isPersistent:qn}),h}var dr={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(u){return u.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Oi=un(dr),Ya=re({},dr,{view:0,detail:0}),Ru=un(Ya),Xa,X0,Ch,hg=re({},Ya,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:J0,button:0,buttons:0,relatedTarget:function(u){return u.relatedTarget===void 0?u.fromElement===u.srcElement?u.toElement:u.fromElement:u.relatedTarget},movementX:function(u){return"movementX"in u?u.movementX:(u!==Ch&&(Ch&&u.type==="mousemove"?(Xa=u.screenX-Ch.screenX,X0=u.screenY-Ch.screenY):X0=Xa=0,Ch=u),Xa)},movementY:function(u){return"movementY"in u?u.movementY:X0}}),jT=un(hg),AK=re({},hg,{dataTransfer:0}),OK=un(AK),RK=re({},Ya,{relatedTarget:0}),Z0=un(RK),DK=re({},dr,{animationName:0,elapsedTime:0,pseudoElement:0}),jK=un(DK),NK=re({},dr,{clipboardData:function(u){return"clipboardData"in u?u.clipboardData:window.clipboardData}}),LK=un(NK),FK=re({},dr,{data:0}),NT=un(FK),zK={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},$K={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"},BK={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function UK(u){var h=this.nativeEvent;return h.getModifierState?h.getModifierState(u):(u=BK[u])?!!h[u]:!1}function J0(){return UK}var HK=re({},Ya,{key:function(u){if(u.key){var h=zK[u.key]||u.key;if(h!=="Unidentified")return h}return u.type==="keypress"?(u=yn(u),u===13?"Enter":String.fromCharCode(u)):u.type==="keydown"||u.type==="keyup"?$K[u.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:J0,charCode:function(u){return u.type==="keypress"?yn(u):0},keyCode:function(u){return u.type==="keydown"||u.type==="keyup"?u.keyCode:0},which:function(u){return u.type==="keypress"?yn(u):u.type==="keydown"||u.type==="keyup"?u.keyCode:0}}),KK=un(HK),WK=re({},hg,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),LT=un(WK),VK=re({},Ya,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:J0}),qK=un(VK),GK=re({},dr,{propertyName:0,elapsedTime:0,pseudoElement:0}),YK=un(GK),XK=re({},hg,{deltaX:function(u){return"deltaX"in u?u.deltaX:"wheelDeltaX"in u?-u.wheelDeltaX:0},deltaY:function(u){return"deltaY"in u?u.deltaY:"wheelDeltaY"in u?-u.wheelDeltaY:"wheelDelta"in u?-u.wheelDelta:0},deltaZ:0,deltaMode:0}),ZK=un(XK),JK=[9,13,27,32],Q0=a&&"CompositionEvent"in window,Ph=null;a&&"documentMode"in document&&(Ph=document.documentMode);var QK=a&&"TextEvent"in window&&!Ph,FT=a&&(!Q0||Ph&&8<Ph&&11>=Ph),zT=" ",$T=!1;function BT(u,h){switch(u){case"keyup":return JK.indexOf(h.keyCode)!==-1;case"keydown":return h.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function UT(u){return u=u.detail,typeof u=="object"&&"data"in u?u.data:null}var Du=!1;function eW(u,h){switch(u){case"compositionend":return UT(h);case"keypress":return h.which!==32?null:($T=!0,zT);case"textInput":return u=h.data,u===zT&&$T?null:u;default:return null}}function tW(u,h){if(Du)return u==="compositionend"||!Q0&&BT(u,h)?(u=ns(),Dn=Nt=$t=null,Du=!1,u):null;switch(u){case"paste":return null;case"keypress":if(!(h.ctrlKey||h.altKey||h.metaKey)||h.ctrlKey&&h.altKey){if(h.char&&1<h.char.length)return h.char;if(h.which)return String.fromCharCode(h.which)}return null;case"compositionend":return FT&&h.locale!=="ko"?null:h.data;default:return null}}var nW={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 HT(u){var h=u&&u.nodeName&&u.nodeName.toLowerCase();return h==="input"?!!nW[u.type]:h==="textarea"}function KT(u,h,S,w){Ka(w),h=yg(h,"onChange"),0<h.length&&(S=new Oi("onChange","change",null,S,w),u.push({event:S,listeners:h}))}var Eh=null,kh=null;function rW(u){l2(u,0)}function fg(u){var h=zu(u);if(cn(h))return u}function sW(u,h){if(u==="change")return h}var WT=!1;if(a){var ex;if(a){var tx="oninput"in document;if(!tx){var VT=document.createElement("div");VT.setAttribute("oninput","return;"),tx=typeof VT.oninput=="function"}ex=tx}else ex=!1;WT=ex&&(!document.documentMode||9<document.documentMode)}function qT(){Eh&&(Eh.detachEvent("onpropertychange",GT),kh=Eh=null)}function GT(u){if(u.propertyName==="value"&&fg(kh)){var h=[];KT(h,kh,u,es(u)),tg(rW,h)}}function iW(u,h,S){u==="focusin"?(qT(),Eh=h,kh=S,Eh.attachEvent("onpropertychange",GT)):u==="focusout"&&qT()}function oW(u){if(u==="selectionchange"||u==="keyup"||u==="keydown")return fg(kh)}function aW(u,h){if(u==="click")return fg(h)}function lW(u,h){if(u==="input"||u==="change")return fg(h)}function cW(u,h){return u===h&&(u!==0||1/u===1/h)||u!==u&&h!==h}var Ri=typeof Object.is=="function"?Object.is:cW;function Ih(u,h){if(Ri(u,h))return!0;if(typeof u!="object"||u===null||typeof h!="object"||h===null)return!1;var S=Object.keys(u),w=Object.keys(h);if(S.length!==w.length)return!1;for(w=0;w<S.length;w++){var k=S[w];if(!l.call(h,k)||!Ri(u[k],h[k]))return!1}return!0}function YT(u){for(;u&&u.firstChild;)u=u.firstChild;return u}function XT(u,h){var S=YT(u);u=0;for(var w;S;){if(S.nodeType===3){if(w=u+S.textContent.length,u<=h&&w>=h)return{node:S,offset:h-u};u=w}e:{for(;S;){if(S.nextSibling){S=S.nextSibling;break e}S=S.parentNode}S=void 0}S=YT(S)}}function ZT(u,h){return u&&h?u===h?!0:u&&u.nodeType===3?!1:h&&h.nodeType===3?ZT(u,h.parentNode):"contains"in u?u.contains(h):u.compareDocumentPosition?!!(u.compareDocumentPosition(h)&16):!1:!1}function JT(){for(var u=window,h=It();h instanceof u.HTMLIFrameElement;){try{var S=typeof h.contentWindow.location.href=="string"}catch{S=!1}if(S)u=h.contentWindow;else break;h=It(u.document)}return h}function nx(u){var h=u&&u.nodeName&&u.nodeName.toLowerCase();return h&&(h==="input"&&(u.type==="text"||u.type==="search"||u.type==="tel"||u.type==="url"||u.type==="password")||h==="textarea"||u.contentEditable==="true")}function uW(u){var h=JT(),S=u.focusedElem,w=u.selectionRange;if(h!==S&&S&&S.ownerDocument&&ZT(S.ownerDocument.documentElement,S)){if(w!==null&&nx(S)){if(h=w.start,u=w.end,u===void 0&&(u=h),"selectionStart"in S)S.selectionStart=h,S.selectionEnd=Math.min(u,S.value.length);else if(u=(h=S.ownerDocument||document)&&h.defaultView||window,u.getSelection){u=u.getSelection();var k=S.textContent.length,M=Math.min(w.start,k);w=w.end===void 0?M:Math.min(w.end,k),!u.extend&&M>w&&(k=w,w=M,M=k),k=XT(S,M);var D=XT(S,w);k&&D&&(u.rangeCount!==1||u.anchorNode!==k.node||u.anchorOffset!==k.offset||u.focusNode!==D.node||u.focusOffset!==D.offset)&&(h=h.createRange(),h.setStart(k.node,k.offset),u.removeAllRanges(),M>w?(u.addRange(h),u.extend(D.node,D.offset)):(h.setEnd(D.node,D.offset),u.addRange(h)))}}for(h=[],u=S;u=u.parentNode;)u.nodeType===1&&h.push({element:u,left:u.scrollLeft,top:u.scrollTop});for(typeof S.focus=="function"&&S.focus(),S=0;S<h.length;S++)u=h[S],u.element.scrollLeft=u.left,u.element.scrollTop=u.top}}var dW=a&&"documentMode"in document&&11>=document.documentMode,ju=null,rx=null,_h=null,sx=!1;function QT(u,h,S){var w=S.window===S?S.document:S.nodeType===9?S:S.ownerDocument;sx||ju==null||ju!==It(w)||(w=ju,"selectionStart"in w&&nx(w)?w={start:w.selectionStart,end:w.selectionEnd}:(w=(w.ownerDocument&&w.ownerDocument.defaultView||window).getSelection(),w={anchorNode:w.anchorNode,anchorOffset:w.anchorOffset,focusNode:w.focusNode,focusOffset:w.focusOffset}),_h&&Ih(_h,w)||(_h=w,w=yg(rx,"onSelect"),0<w.length&&(h=new Oi("onSelect","select",null,h,S),u.push({event:h,listeners:w}),h.target=ju)))}function pg(u,h){var S={};return S[u.toLowerCase()]=h.toLowerCase(),S["Webkit"+u]="webkit"+h,S["Moz"+u]="moz"+h,S}var Nu={animationend:pg("Animation","AnimationEnd"),animationiteration:pg("Animation","AnimationIteration"),animationstart:pg("Animation","AnimationStart"),transitionend:pg("Transition","TransitionEnd")},ix={},e2={};a&&(e2=document.createElement("div").style,"AnimationEvent"in window||(delete Nu.animationend.animation,delete Nu.animationiteration.animation,delete Nu.animationstart.animation),"TransitionEvent"in window||delete Nu.transitionend.transition);function gg(u){if(ix[u])return ix[u];if(!Nu[u])return u;var h=Nu[u],S;for(S in h)if(h.hasOwnProperty(S)&&S in e2)return ix[u]=h[S];return u}var t2=gg("animationend"),n2=gg("animationiteration"),r2=gg("animationstart"),s2=gg("transitionend"),i2=new Map,o2="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 Za(u,h){i2.set(u,h),i(h,[u])}for(var ox=0;ox<o2.length;ox++){var ax=o2[ox],hW=ax.toLowerCase(),fW=ax[0].toUpperCase()+ax.slice(1);Za(hW,"on"+fW)}Za(t2,"onAnimationEnd"),Za(n2,"onAnimationIteration"),Za(r2,"onAnimationStart"),Za("dblclick","onDoubleClick"),Za("focusin","onFocus"),Za("focusout","onBlur"),Za(s2,"onTransitionEnd"),o("onMouseEnter",["mouseout","mouseover"]),o("onMouseLeave",["mouseout","mouseover"]),o("onPointerEnter",["pointerout","pointerover"]),o("onPointerLeave",["pointerout","pointerover"]),i("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),i("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),i("onBeforeInput",["compositionend","keypress","textInput","paste"]),i("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),i("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),i("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Th="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(" "),pW=new Set("cancel close invalid load scroll toggle".split(" ").concat(Th));function a2(u,h,S){var w=u.type||"unknown-event";u.currentTarget=S,L0(w,h,void 0,u),u.currentTarget=null}function l2(u,h){h=(h&4)!==0;for(var S=0;S<u.length;S++){var w=u[S],k=w.event;w=w.listeners;e:{var M=void 0;if(h)for(var D=w.length-1;0<=D;D--){var B=w[D],q=B.instance,oe=B.currentTarget;if(B=B.listener,q!==M&&k.isPropagationStopped())break e;a2(k,B,oe),M=q}else for(D=0;D<w.length;D++){if(B=w[D],q=B.instance,oe=B.currentTarget,B=B.listener,q!==M&&k.isPropagationStopped())break e;a2(k,B,oe),M=q}}}if(Qs)throw u=gh,Qs=!1,gh=null,u}function Wt(u,h){var S=h[gx];S===void 0&&(S=h[gx]=new Set);var w=u+"__bubble";S.has(w)||(c2(h,u,2,!1),S.add(w))}function lx(u,h,S){var w=0;h&&(w|=4),c2(S,u,w,h)}var mg="_reactListening"+Math.random().toString(36).slice(2);function Mh(u){if(!u[mg]){u[mg]=!0,r.forEach(function(S){S!=="selectionchange"&&(pW.has(S)||lx(S,!1,u),lx(S,!0,u))});var h=u.nodeType===9?u:u.ownerDocument;h===null||h[mg]||(h[mg]=!0,lx("selectionchange",!1,h))}}function c2(u,h,S,w){switch(mn(h)){case 1:var k=de;break;case 4:k=Ae;break;default:k=Tt}S=k.bind(null,h,S,u),k=void 0,!ph||h!=="touchstart"&&h!=="touchmove"&&h!=="wheel"||(k=!0),w?k!==void 0?u.addEventListener(h,S,{capture:!0,passive:k}):u.addEventListener(h,S,!0):k!==void 0?u.addEventListener(h,S,{passive:k}):u.addEventListener(h,S,!1)}function cx(u,h,S,w,k){var M=w;if((h&1)===0&&(h&2)===0&&w!==null)e:for(;;){if(w===null)return;var D=w.tag;if(D===3||D===4){var B=w.stateNode.containerInfo;if(B===k||B.nodeType===8&&B.parentNode===k)break;if(D===4)for(D=w.return;D!==null;){var q=D.tag;if((q===3||q===4)&&(q=D.stateNode.containerInfo,q===k||q.nodeType===8&&q.parentNode===k))return;D=D.return}for(;B!==null;){if(D=fc(B),D===null)return;if(q=D.tag,q===5||q===6){w=M=D;continue e}B=B.parentNode}}w=w.return}tg(function(){var oe=M,fe=es(S),me=[];e:{var he=i2.get(u);if(he!==void 0){var Me=Oi,je=u;switch(u){case"keypress":if(yn(S)===0)break e;case"keydown":case"keyup":Me=KK;break;case"focusin":je="focus",Me=Z0;break;case"focusout":je="blur",Me=Z0;break;case"beforeblur":case"afterblur":Me=Z0;break;case"click":if(S.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":Me=jT;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Me=OK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Me=qK;break;case t2:case n2:case r2:Me=jK;break;case s2:Me=YK;break;case"scroll":Me=Ru;break;case"wheel":Me=ZK;break;case"copy":case"cut":case"paste":Me=LK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Me=LT}var Fe=(h&4)!==0,Sn=!Fe&&u==="scroll",Q=Fe?he!==null?he+"Capture":null:he;Fe=[];for(var Y=oe,se;Y!==null;){se=Y;var xe=se.stateNode;if(se.tag===5&&xe!==null&&(se=xe,Q!==null&&(xe=ic(Y,Q),xe!=null&&Fe.push(Ah(Y,xe,se)))),Sn)break;Y=Y.return}0<Fe.length&&(he=new Me(he,je,null,S,fe),me.push({event:he,listeners:Fe}))}}if((h&7)===0){e:{if(he=u==="mouseover"||u==="pointerover",Me=u==="mouseout"||u==="pointerout",he&&S!==_s&&(je=S.relatedTarget||S.fromElement)&&(fc(je)||je[Qo]))break e;if((Me||he)&&(he=fe.window===fe?fe:(he=fe.ownerDocument)?he.defaultView||he.parentWindow:window,Me?(je=S.relatedTarget||S.toElement,Me=oe,je=je?fc(je):null,je!==null&&(Sn=Zo(je),je!==Sn||je.tag!==5&&je.tag!==6)&&(je=null)):(Me=null,je=oe),Me!==je)){if(Fe=jT,xe="onMouseLeave",Q="onMouseEnter",Y="mouse",(u==="pointerout"||u==="pointerover")&&(Fe=LT,xe="onPointerLeave",Q="onPointerEnter",Y="pointer"),Sn=Me==null?he:zu(Me),se=je==null?he:zu(je),he=new Fe(xe,Y+"leave",Me,S,fe),he.target=Sn,he.relatedTarget=se,xe=null,fc(fe)===oe&&(Fe=new Fe(Q,Y+"enter",je,S,fe),Fe.target=se,Fe.relatedTarget=Sn,xe=Fe),Sn=xe,Me&&je)t:{for(Fe=Me,Q=je,Y=0,se=Fe;se;se=Lu(se))Y++;for(se=0,xe=Q;xe;xe=Lu(xe))se++;for(;0<Y-se;)Fe=Lu(Fe),Y--;for(;0<se-Y;)Q=Lu(Q),se--;for(;Y--;){if(Fe===Q||Q!==null&&Fe===Q.alternate)break t;Fe=Lu(Fe),Q=Lu(Q)}Fe=null}else Fe=null;Me!==null&&u2(me,he,Me,Fe,!1),je!==null&&Sn!==null&&u2(me,Sn,je,Fe,!0)}}e:{if(he=oe?zu(oe):window,Me=he.nodeName&&he.nodeName.toLowerCase(),Me==="select"||Me==="input"&&he.type==="file")var $e=sW;else if(HT(he))if(WT)$e=lW;else{$e=oW;var qe=iW}else(Me=he.nodeName)&&Me.toLowerCase()==="input"&&(he.type==="checkbox"||he.type==="radio")&&($e=aW);if($e&&($e=$e(u,oe))){KT(me,$e,S,fe);break e}qe&&qe(u,he,oe),u==="focusout"&&(qe=he._wrapperState)&&qe.controlled&&he.type==="number"&&Zr(he,"number",he.value)}switch(qe=oe?zu(oe):window,u){case"focusin":(HT(qe)||qe.contentEditable==="true")&&(ju=qe,rx=oe,_h=null);break;case"focusout":_h=rx=ju=null;break;case"mousedown":sx=!0;break;case"contextmenu":case"mouseup":case"dragend":sx=!1,QT(me,S,fe);break;case"selectionchange":if(dW)break;case"keydown":case"keyup":QT(me,S,fe)}var Ge;if(Q0)e:{switch(u){case"compositionstart":var Qe="onCompositionStart";break e;case"compositionend":Qe="onCompositionEnd";break e;case"compositionupdate":Qe="onCompositionUpdate";break e}Qe=void 0}else Du?BT(u,S)&&(Qe="onCompositionEnd"):u==="keydown"&&S.keyCode===229&&(Qe="onCompositionStart");Qe&&(FT&&S.locale!=="ko"&&(Du||Qe!=="onCompositionStart"?Qe==="onCompositionEnd"&&Du&&(Ge=ns()):($t=fe,Nt="value"in $t?$t.value:$t.textContent,Du=!0)),qe=yg(oe,Qe),0<qe.length&&(Qe=new NT(Qe,u,null,S,fe),me.push({event:Qe,listeners:qe}),Ge?Qe.data=Ge:(Ge=UT(S),Ge!==null&&(Qe.data=Ge)))),(Ge=QK?eW(u,S):tW(u,S))&&(oe=yg(oe,"onBeforeInput"),0<oe.length&&(fe=new NT("onBeforeInput","beforeinput",null,S,fe),me.push({event:fe,listeners:oe}),fe.data=Ge))}l2(me,h)})}function Ah(u,h,S){return{instance:u,listener:h,currentTarget:S}}function yg(u,h){for(var S=h+"Capture",w=[];u!==null;){var k=u,M=k.stateNode;k.tag===5&&M!==null&&(k=M,M=ic(u,S),M!=null&&w.unshift(Ah(u,M,k)),M=ic(u,h),M!=null&&w.push(Ah(u,M,k))),u=u.return}return w}function Lu(u){if(u===null)return null;do u=u.return;while(u&&u.tag!==5);return u||null}function u2(u,h,S,w,k){for(var M=h._reactName,D=[];S!==null&&S!==w;){var B=S,q=B.alternate,oe=B.stateNode;if(q!==null&&q===w)break;B.tag===5&&oe!==null&&(B=oe,k?(q=ic(S,M),q!=null&&D.unshift(Ah(S,q,B))):k||(q=ic(S,M),q!=null&&D.push(Ah(S,q,B)))),S=S.return}D.length!==0&&u.push({event:h,listeners:D})}var gW=/\r\n?/g,mW=/\u0000|\uFFFD/g;function d2(u){return(typeof u=="string"?u:""+u).replace(gW,`
38
+ `).replace(mW,"")}function Sg(u,h,S){if(h=d2(h),d2(u)!==h&&S)throw Error(t(425))}function vg(){}var ux=null,dx=null;function hx(u,h){return u==="textarea"||u==="noscript"||typeof h.children=="string"||typeof h.children=="number"||typeof h.dangerouslySetInnerHTML=="object"&&h.dangerouslySetInnerHTML!==null&&h.dangerouslySetInnerHTML.__html!=null}var fx=typeof setTimeout=="function"?setTimeout:void 0,yW=typeof clearTimeout=="function"?clearTimeout:void 0,h2=typeof Promise=="function"?Promise:void 0,SW=typeof queueMicrotask=="function"?queueMicrotask:typeof h2<"u"?function(u){return h2.resolve(null).then(u).catch(vW)}:fx;function vW(u){setTimeout(function(){throw u})}function px(u,h){var S=h,w=0;do{var k=S.nextSibling;if(u.removeChild(S),k&&k.nodeType===8)if(S=k.data,S==="/$"){if(w===0){u.removeChild(k),hc(h);return}w--}else S!=="$"&&S!=="$?"&&S!=="$!"||w++;S=k}while(S);hc(h)}function Ja(u){for(;u!=null;u=u.nextSibling){var h=u.nodeType;if(h===1||h===3)break;if(h===8){if(h=u.data,h==="$"||h==="$!"||h==="$?")break;if(h==="/$")return null}}return u}function f2(u){u=u.previousSibling;for(var h=0;u;){if(u.nodeType===8){var S=u.data;if(S==="$"||S==="$!"||S==="$?"){if(h===0)return u;h--}else S==="/$"&&h++}u=u.previousSibling}return null}var Fu=Math.random().toString(36).slice(2),go="__reactFiber$"+Fu,Oh="__reactProps$"+Fu,Qo="__reactContainer$"+Fu,gx="__reactEvents$"+Fu,xW="__reactListeners$"+Fu,wW="__reactHandles$"+Fu;function fc(u){var h=u[go];if(h)return h;for(var S=u.parentNode;S;){if(h=S[Qo]||S[go]){if(S=h.alternate,h.child!==null||S!==null&&S.child!==null)for(u=f2(u);u!==null;){if(S=u[go])return S;u=f2(u)}return h}u=S,S=u.parentNode}return null}function Rh(u){return u=u[go]||u[Qo],!u||u.tag!==5&&u.tag!==6&&u.tag!==13&&u.tag!==3?null:u}function zu(u){if(u.tag===5||u.tag===6)return u.stateNode;throw Error(t(33))}function xg(u){return u[Oh]||null}var mx=[],$u=-1;function Qa(u){return{current:u}}function Vt(u){0>$u||(u.current=mx[$u],mx[$u]=null,$u--)}function Bt(u,h){$u++,mx[$u]=u.current,u.current=h}var el={},hr=Qa(el),rs=Qa(!1),pc=el;function Bu(u,h){var S=u.type.contextTypes;if(!S)return el;var w=u.stateNode;if(w&&w.__reactInternalMemoizedUnmaskedChildContext===h)return w.__reactInternalMemoizedMaskedChildContext;var k={},M;for(M in S)k[M]=h[M];return w&&(u=u.stateNode,u.__reactInternalMemoizedUnmaskedChildContext=h,u.__reactInternalMemoizedMaskedChildContext=k),k}function ss(u){return u=u.childContextTypes,u!=null}function wg(){Vt(rs),Vt(hr)}function p2(u,h,S){if(hr.current!==el)throw Error(t(168));Bt(hr,h),Bt(rs,S)}function g2(u,h,S){var w=u.stateNode;if(h=h.childContextTypes,typeof w.getChildContext!="function")return S;w=w.getChildContext();for(var k in w)if(!(k in h))throw Error(t(108,Re(u)||"Unknown",k));return re({},S,w)}function bg(u){return u=(u=u.stateNode)&&u.__reactInternalMemoizedMergedChildContext||el,pc=hr.current,Bt(hr,u),Bt(rs,rs.current),!0}function m2(u,h,S){var w=u.stateNode;if(!w)throw Error(t(169));S?(u=g2(u,h,pc),w.__reactInternalMemoizedMergedChildContext=u,Vt(rs),Vt(hr),Bt(hr,u)):Vt(rs),Bt(rs,S)}var ea=null,Cg=!1,yx=!1;function y2(u){ea===null?ea=[u]:ea.push(u)}function bW(u){Cg=!0,y2(u)}function tl(){if(!yx&&ea!==null){yx=!0;var u=0,h=vt;try{var S=ea;for(vt=1;u<S.length;u++){var w=S[u];do w=w(!0);while(w!==null)}ea=null,Cg=!1}catch(k){throw ea!==null&&(ea=ea.slice(u+1)),ig(mh,tl),k}finally{vt=h,yx=!1}}return null}var Uu=[],Hu=0,Pg=null,Eg=0,ni=[],ri=0,gc=null,ta=1,na="";function mc(u,h){Uu[Hu++]=Eg,Uu[Hu++]=Pg,Pg=u,Eg=h}function S2(u,h,S){ni[ri++]=ta,ni[ri++]=na,ni[ri++]=gc,gc=u;var w=ta;u=na;var k=32-Ms(w)-1;w&=~(1<<k),S+=1;var M=32-Ms(h)+k;if(30<M){var D=k-k%5;M=(w&(1<<D)-1).toString(32),w>>=D,k-=D,ta=1<<32-Ms(h)+k|S<<k|w,na=M+u}else ta=1<<M|S<<k|w,na=u}function Sx(u){u.return!==null&&(mc(u,1),S2(u,1,0))}function vx(u){for(;u===Pg;)Pg=Uu[--Hu],Uu[Hu]=null,Eg=Uu[--Hu],Uu[Hu]=null;for(;u===gc;)gc=ni[--ri],ni[ri]=null,na=ni[--ri],ni[ri]=null,ta=ni[--ri],ni[ri]=null}var As=null,Os=null,Qt=!1,Di=null;function v2(u,h){var S=ai(5,null,null,0);S.elementType="DELETED",S.stateNode=h,S.return=u,h=u.deletions,h===null?(u.deletions=[S],u.flags|=16):h.push(S)}function x2(u,h){switch(u.tag){case 5:var S=u.type;return h=h.nodeType!==1||S.toLowerCase()!==h.nodeName.toLowerCase()?null:h,h!==null?(u.stateNode=h,As=u,Os=Ja(h.firstChild),!0):!1;case 6:return h=u.pendingProps===""||h.nodeType!==3?null:h,h!==null?(u.stateNode=h,As=u,Os=null,!0):!1;case 13:return h=h.nodeType!==8?null:h,h!==null?(S=gc!==null?{id:ta,overflow:na}:null,u.memoizedState={dehydrated:h,treeContext:S,retryLane:1073741824},S=ai(18,null,null,0),S.stateNode=h,S.return=u,u.child=S,As=u,Os=null,!0):!1;default:return!1}}function xx(u){return(u.mode&1)!==0&&(u.flags&128)===0}function wx(u){if(Qt){var h=Os;if(h){var S=h;if(!x2(u,h)){if(xx(u))throw Error(t(418));h=Ja(S.nextSibling);var w=As;h&&x2(u,h)?v2(w,S):(u.flags=u.flags&-4097|2,Qt=!1,As=u)}}else{if(xx(u))throw Error(t(418));u.flags=u.flags&-4097|2,Qt=!1,As=u}}}function w2(u){for(u=u.return;u!==null&&u.tag!==5&&u.tag!==3&&u.tag!==13;)u=u.return;As=u}function kg(u){if(u!==As)return!1;if(!Qt)return w2(u),Qt=!0,!1;var h;if((h=u.tag!==3)&&!(h=u.tag!==5)&&(h=u.type,h=h!=="head"&&h!=="body"&&!hx(u.type,u.memoizedProps)),h&&(h=Os)){if(xx(u))throw b2(),Error(t(418));for(;h;)v2(u,h),h=Ja(h.nextSibling)}if(w2(u),u.tag===13){if(u=u.memoizedState,u=u!==null?u.dehydrated:null,!u)throw Error(t(317));e:{for(u=u.nextSibling,h=0;u;){if(u.nodeType===8){var S=u.data;if(S==="/$"){if(h===0){Os=Ja(u.nextSibling);break e}h--}else S!=="$"&&S!=="$!"&&S!=="$?"||h++}u=u.nextSibling}Os=null}}else Os=As?Ja(u.stateNode.nextSibling):null;return!0}function b2(){for(var u=Os;u;)u=Ja(u.nextSibling)}function Ku(){Os=As=null,Qt=!1}function bx(u){Di===null?Di=[u]:Di.push(u)}var CW=_.ReactCurrentBatchConfig;function Dh(u,h,S){if(u=S.ref,u!==null&&typeof u!="function"&&typeof u!="object"){if(S._owner){if(S=S._owner,S){if(S.tag!==1)throw Error(t(309));var w=S.stateNode}if(!w)throw Error(t(147,u));var k=w,M=""+u;return h!==null&&h.ref!==null&&typeof h.ref=="function"&&h.ref._stringRef===M?h.ref:(h=function(D){var B=k.refs;D===null?delete B[M]:B[M]=D},h._stringRef=M,h)}if(typeof u!="string")throw Error(t(284));if(!S._owner)throw Error(t(290,u))}return u}function Ig(u,h){throw u=Object.prototype.toString.call(h),Error(t(31,u==="[object Object]"?"object with keys {"+Object.keys(h).join(", ")+"}":u))}function C2(u){var h=u._init;return h(u._payload)}function P2(u){function h(Q,Y){if(u){var se=Q.deletions;se===null?(Q.deletions=[Y],Q.flags|=16):se.push(Y)}}function S(Q,Y){if(!u)return null;for(;Y!==null;)h(Q,Y),Y=Y.sibling;return null}function w(Q,Y){for(Q=new Map;Y!==null;)Y.key!==null?Q.set(Y.key,Y):Q.set(Y.index,Y),Y=Y.sibling;return Q}function k(Q,Y){return Q=cl(Q,Y),Q.index=0,Q.sibling=null,Q}function M(Q,Y,se){return Q.index=se,u?(se=Q.alternate,se!==null?(se=se.index,se<Y?(Q.flags|=2,Y):se):(Q.flags|=2,Y)):(Q.flags|=1048576,Y)}function D(Q){return u&&Q.alternate===null&&(Q.flags|=2),Q}function B(Q,Y,se,xe){return Y===null||Y.tag!==6?(Y=fw(se,Q.mode,xe),Y.return=Q,Y):(Y=k(Y,se),Y.return=Q,Y)}function q(Q,Y,se,xe){var $e=se.type;return $e===R?fe(Q,Y,se.props.children,xe,se.key):Y!==null&&(Y.elementType===$e||typeof $e=="object"&&$e!==null&&$e.$$typeof===X&&C2($e)===Y.type)?(xe=k(Y,se.props),xe.ref=Dh(Q,Y,se),xe.return=Q,xe):(xe=Zg(se.type,se.key,se.props,null,Q.mode,xe),xe.ref=Dh(Q,Y,se),xe.return=Q,xe)}function oe(Q,Y,se,xe){return Y===null||Y.tag!==4||Y.stateNode.containerInfo!==se.containerInfo||Y.stateNode.implementation!==se.implementation?(Y=pw(se,Q.mode,xe),Y.return=Q,Y):(Y=k(Y,se.children||[]),Y.return=Q,Y)}function fe(Q,Y,se,xe,$e){return Y===null||Y.tag!==7?(Y=Pc(se,Q.mode,xe,$e),Y.return=Q,Y):(Y=k(Y,se),Y.return=Q,Y)}function me(Q,Y,se){if(typeof Y=="string"&&Y!==""||typeof Y=="number")return Y=fw(""+Y,Q.mode,se),Y.return=Q,Y;if(typeof Y=="object"&&Y!==null){switch(Y.$$typeof){case T:return se=Zg(Y.type,Y.key,Y.props,null,Q.mode,se),se.ref=Dh(Q,null,Y),se.return=Q,se;case A:return Y=pw(Y,Q.mode,se),Y.return=Q,Y;case X:var xe=Y._init;return me(Q,xe(Y._payload),se)}if(Jr(Y)||G(Y))return Y=Pc(Y,Q.mode,se,null),Y.return=Q,Y;Ig(Q,Y)}return null}function he(Q,Y,se,xe){var $e=Y!==null?Y.key:null;if(typeof se=="string"&&se!==""||typeof se=="number")return $e!==null?null:B(Q,Y,""+se,xe);if(typeof se=="object"&&se!==null){switch(se.$$typeof){case T:return se.key===$e?q(Q,Y,se,xe):null;case A:return se.key===$e?oe(Q,Y,se,xe):null;case X:return $e=se._init,he(Q,Y,$e(se._payload),xe)}if(Jr(se)||G(se))return $e!==null?null:fe(Q,Y,se,xe,null);Ig(Q,se)}return null}function Me(Q,Y,se,xe,$e){if(typeof xe=="string"&&xe!==""||typeof xe=="number")return Q=Q.get(se)||null,B(Y,Q,""+xe,$e);if(typeof xe=="object"&&xe!==null){switch(xe.$$typeof){case T:return Q=Q.get(xe.key===null?se:xe.key)||null,q(Y,Q,xe,$e);case A:return Q=Q.get(xe.key===null?se:xe.key)||null,oe(Y,Q,xe,$e);case X:var qe=xe._init;return Me(Q,Y,se,qe(xe._payload),$e)}if(Jr(xe)||G(xe))return Q=Q.get(se)||null,fe(Y,Q,xe,$e,null);Ig(Y,xe)}return null}function je(Q,Y,se,xe){for(var $e=null,qe=null,Ge=Y,Qe=Y=0,Ln=null;Ge!==null&&Qe<se.length;Qe++){Ge.index>Qe?(Ln=Ge,Ge=null):Ln=Ge.sibling;var Et=he(Q,Ge,se[Qe],xe);if(Et===null){Ge===null&&(Ge=Ln);break}u&&Ge&&Et.alternate===null&&h(Q,Ge),Y=M(Et,Y,Qe),qe===null?$e=Et:qe.sibling=Et,qe=Et,Ge=Ln}if(Qe===se.length)return S(Q,Ge),Qt&&mc(Q,Qe),$e;if(Ge===null){for(;Qe<se.length;Qe++)Ge=me(Q,se[Qe],xe),Ge!==null&&(Y=M(Ge,Y,Qe),qe===null?$e=Ge:qe.sibling=Ge,qe=Ge);return Qt&&mc(Q,Qe),$e}for(Ge=w(Q,Ge);Qe<se.length;Qe++)Ln=Me(Ge,Q,Qe,se[Qe],xe),Ln!==null&&(u&&Ln.alternate!==null&&Ge.delete(Ln.key===null?Qe:Ln.key),Y=M(Ln,Y,Qe),qe===null?$e=Ln:qe.sibling=Ln,qe=Ln);return u&&Ge.forEach(function(ul){return h(Q,ul)}),Qt&&mc(Q,Qe),$e}function Fe(Q,Y,se,xe){var $e=G(se);if(typeof $e!="function")throw Error(t(150));if(se=$e.call(se),se==null)throw Error(t(151));for(var qe=$e=null,Ge=Y,Qe=Y=0,Ln=null,Et=se.next();Ge!==null&&!Et.done;Qe++,Et=se.next()){Ge.index>Qe?(Ln=Ge,Ge=null):Ln=Ge.sibling;var ul=he(Q,Ge,Et.value,xe);if(ul===null){Ge===null&&(Ge=Ln);break}u&&Ge&&ul.alternate===null&&h(Q,Ge),Y=M(ul,Y,Qe),qe===null?$e=ul:qe.sibling=ul,qe=ul,Ge=Ln}if(Et.done)return S(Q,Ge),Qt&&mc(Q,Qe),$e;if(Ge===null){for(;!Et.done;Qe++,Et=se.next())Et=me(Q,Et.value,xe),Et!==null&&(Y=M(Et,Y,Qe),qe===null?$e=Et:qe.sibling=Et,qe=Et);return Qt&&mc(Q,Qe),$e}for(Ge=w(Q,Ge);!Et.done;Qe++,Et=se.next())Et=Me(Ge,Q,Qe,Et.value,xe),Et!==null&&(u&&Et.alternate!==null&&Ge.delete(Et.key===null?Qe:Et.key),Y=M(Et,Y,Qe),qe===null?$e=Et:qe.sibling=Et,qe=Et);return u&&Ge.forEach(function(nV){return h(Q,nV)}),Qt&&mc(Q,Qe),$e}function Sn(Q,Y,se,xe){if(typeof se=="object"&&se!==null&&se.type===R&&se.key===null&&(se=se.props.children),typeof se=="object"&&se!==null){switch(se.$$typeof){case T:e:{for(var $e=se.key,qe=Y;qe!==null;){if(qe.key===$e){if($e=se.type,$e===R){if(qe.tag===7){S(Q,qe.sibling),Y=k(qe,se.props.children),Y.return=Q,Q=Y;break e}}else if(qe.elementType===$e||typeof $e=="object"&&$e!==null&&$e.$$typeof===X&&C2($e)===qe.type){S(Q,qe.sibling),Y=k(qe,se.props),Y.ref=Dh(Q,qe,se),Y.return=Q,Q=Y;break e}S(Q,qe);break}else h(Q,qe);qe=qe.sibling}se.type===R?(Y=Pc(se.props.children,Q.mode,xe,se.key),Y.return=Q,Q=Y):(xe=Zg(se.type,se.key,se.props,null,Q.mode,xe),xe.ref=Dh(Q,Y,se),xe.return=Q,Q=xe)}return D(Q);case A:e:{for(qe=se.key;Y!==null;){if(Y.key===qe)if(Y.tag===4&&Y.stateNode.containerInfo===se.containerInfo&&Y.stateNode.implementation===se.implementation){S(Q,Y.sibling),Y=k(Y,se.children||[]),Y.return=Q,Q=Y;break e}else{S(Q,Y);break}else h(Q,Y);Y=Y.sibling}Y=pw(se,Q.mode,xe),Y.return=Q,Q=Y}return D(Q);case X:return qe=se._init,Sn(Q,Y,qe(se._payload),xe)}if(Jr(se))return je(Q,Y,se,xe);if(G(se))return Fe(Q,Y,se,xe);Ig(Q,se)}return typeof se=="string"&&se!==""||typeof se=="number"?(se=""+se,Y!==null&&Y.tag===6?(S(Q,Y.sibling),Y=k(Y,se),Y.return=Q,Q=Y):(S(Q,Y),Y=fw(se,Q.mode,xe),Y.return=Q,Q=Y),D(Q)):S(Q,Y)}return Sn}var Wu=P2(!0),E2=P2(!1),_g=Qa(null),Tg=null,Vu=null,Cx=null;function Px(){Cx=Vu=Tg=null}function Ex(u){var h=_g.current;Vt(_g),u._currentValue=h}function kx(u,h,S){for(;u!==null;){var w=u.alternate;if((u.childLanes&h)!==h?(u.childLanes|=h,w!==null&&(w.childLanes|=h)):w!==null&&(w.childLanes&h)!==h&&(w.childLanes|=h),u===S)break;u=u.return}}function qu(u,h){Tg=u,Cx=Vu=null,u=u.dependencies,u!==null&&u.firstContext!==null&&((u.lanes&h)!==0&&(is=!0),u.firstContext=null)}function si(u){var h=u._currentValue;if(Cx!==u)if(u={context:u,memoizedValue:h,next:null},Vu===null){if(Tg===null)throw Error(t(308));Vu=u,Tg.dependencies={lanes:0,firstContext:u}}else Vu=Vu.next=u;return h}var yc=null;function Ix(u){yc===null?yc=[u]:yc.push(u)}function k2(u,h,S,w){var k=h.interleaved;return k===null?(S.next=S,Ix(h)):(S.next=k.next,k.next=S),h.interleaved=S,ra(u,w)}function ra(u,h){u.lanes|=h;var S=u.alternate;for(S!==null&&(S.lanes|=h),S=u,u=u.return;u!==null;)u.childLanes|=h,S=u.alternate,S!==null&&(S.childLanes|=h),S=u,u=u.return;return S.tag===3?S.stateNode:null}var nl=!1;function _x(u){u.updateQueue={baseState:u.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function I2(u,h){u=u.updateQueue,h.updateQueue===u&&(h.updateQueue={baseState:u.baseState,firstBaseUpdate:u.firstBaseUpdate,lastBaseUpdate:u.lastBaseUpdate,shared:u.shared,effects:u.effects})}function sa(u,h){return{eventTime:u,lane:h,tag:0,payload:null,callback:null,next:null}}function rl(u,h,S){var w=u.updateQueue;if(w===null)return null;if(w=w.shared,(bt&2)!==0){var k=w.pending;return k===null?h.next=h:(h.next=k.next,k.next=h),w.pending=h,ra(u,S)}return k=w.interleaved,k===null?(h.next=h,Ix(w)):(h.next=k.next,k.next=h),w.interleaved=h,ra(u,S)}function Mg(u,h,S){if(h=h.updateQueue,h!==null&&(h=h.shared,(S&4194240)!==0)){var w=h.lanes;w&=u.pendingLanes,S|=w,h.lanes=S,Au(u,S)}}function _2(u,h){var S=u.updateQueue,w=u.alternate;if(w!==null&&(w=w.updateQueue,S===w)){var k=null,M=null;if(S=S.firstBaseUpdate,S!==null){do{var D={eventTime:S.eventTime,lane:S.lane,tag:S.tag,payload:S.payload,callback:S.callback,next:null};M===null?k=M=D:M=M.next=D,S=S.next}while(S!==null);M===null?k=M=h:M=M.next=h}else k=M=h;S={baseState:w.baseState,firstBaseUpdate:k,lastBaseUpdate:M,shared:w.shared,effects:w.effects},u.updateQueue=S;return}u=S.lastBaseUpdate,u===null?S.firstBaseUpdate=h:u.next=h,S.lastBaseUpdate=h}function Ag(u,h,S,w){var k=u.updateQueue;nl=!1;var M=k.firstBaseUpdate,D=k.lastBaseUpdate,B=k.shared.pending;if(B!==null){k.shared.pending=null;var q=B,oe=q.next;q.next=null,D===null?M=oe:D.next=oe,D=q;var fe=u.alternate;fe!==null&&(fe=fe.updateQueue,B=fe.lastBaseUpdate,B!==D&&(B===null?fe.firstBaseUpdate=oe:B.next=oe,fe.lastBaseUpdate=q))}if(M!==null){var me=k.baseState;D=0,fe=oe=q=null,B=M;do{var he=B.lane,Me=B.eventTime;if((w&he)===he){fe!==null&&(fe=fe.next={eventTime:Me,lane:0,tag:B.tag,payload:B.payload,callback:B.callback,next:null});e:{var je=u,Fe=B;switch(he=h,Me=S,Fe.tag){case 1:if(je=Fe.payload,typeof je=="function"){me=je.call(Me,me,he);break e}me=je;break e;case 3:je.flags=je.flags&-65537|128;case 0:if(je=Fe.payload,he=typeof je=="function"?je.call(Me,me,he):je,he==null)break e;me=re({},me,he);break e;case 2:nl=!0}}B.callback!==null&&B.lane!==0&&(u.flags|=64,he=k.effects,he===null?k.effects=[B]:he.push(B))}else Me={eventTime:Me,lane:he,tag:B.tag,payload:B.payload,callback:B.callback,next:null},fe===null?(oe=fe=Me,q=me):fe=fe.next=Me,D|=he;if(B=B.next,B===null){if(B=k.shared.pending,B===null)break;he=B,B=he.next,he.next=null,k.lastBaseUpdate=he,k.shared.pending=null}}while(!0);if(fe===null&&(q=me),k.baseState=q,k.firstBaseUpdate=oe,k.lastBaseUpdate=fe,h=k.shared.interleaved,h!==null){k=h;do D|=k.lane,k=k.next;while(k!==h)}else M===null&&(k.shared.lanes=0);xc|=D,u.lanes=D,u.memoizedState=me}}function T2(u,h,S){if(u=h.effects,h.effects=null,u!==null)for(h=0;h<u.length;h++){var w=u[h],k=w.callback;if(k!==null){if(w.callback=null,w=S,typeof k!="function")throw Error(t(191,k));k.call(w)}}}var jh={},mo=Qa(jh),Nh=Qa(jh),Lh=Qa(jh);function Sc(u){if(u===jh)throw Error(t(174));return u}function Tx(u,h){switch(Bt(Lh,h),Bt(Nh,u),Bt(mo,jh),u=h.nodeType,u){case 9:case 11:h=(h=h.documentElement)?h.namespaceURI:ao(null,"");break;default:u=u===8?h.parentNode:h,h=u.namespaceURI||null,u=u.tagName,h=ao(h,u)}Vt(mo),Bt(mo,h)}function Gu(){Vt(mo),Vt(Nh),Vt(Lh)}function M2(u){Sc(Lh.current);var h=Sc(mo.current),S=ao(h,u.type);h!==S&&(Bt(Nh,u),Bt(mo,S))}function Mx(u){Nh.current===u&&(Vt(mo),Vt(Nh))}var rn=Qa(0);function Og(u){for(var h=u;h!==null;){if(h.tag===13){var S=h.memoizedState;if(S!==null&&(S=S.dehydrated,S===null||S.data==="$?"||S.data==="$!"))return h}else if(h.tag===19&&h.memoizedProps.revealOrder!==void 0){if((h.flags&128)!==0)return h}else if(h.child!==null){h.child.return=h,h=h.child;continue}if(h===u)break;for(;h.sibling===null;){if(h.return===null||h.return===u)return null;h=h.return}h.sibling.return=h.return,h=h.sibling}return null}var Ax=[];function Ox(){for(var u=0;u<Ax.length;u++)Ax[u]._workInProgressVersionPrimary=null;Ax.length=0}var Rg=_.ReactCurrentDispatcher,Rx=_.ReactCurrentBatchConfig,vc=0,sn=null,_n=null,jn=null,Dg=!1,Fh=!1,zh=0,PW=0;function fr(){throw Error(t(321))}function Dx(u,h){if(h===null)return!1;for(var S=0;S<h.length&&S<u.length;S++)if(!Ri(u[S],h[S]))return!1;return!0}function jx(u,h,S,w,k,M){if(vc=M,sn=h,h.memoizedState=null,h.updateQueue=null,h.lanes=0,Rg.current=u===null||u.memoizedState===null?_W:TW,u=S(w,k),Fh){M=0;do{if(Fh=!1,zh=0,25<=M)throw Error(t(301));M+=1,jn=_n=null,h.updateQueue=null,Rg.current=MW,u=S(w,k)}while(Fh)}if(Rg.current=Lg,h=_n!==null&&_n.next!==null,vc=0,jn=_n=sn=null,Dg=!1,h)throw Error(t(300));return u}function Nx(){var u=zh!==0;return zh=0,u}function yo(){var u={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jn===null?sn.memoizedState=jn=u:jn=jn.next=u,jn}function ii(){if(_n===null){var u=sn.alternate;u=u!==null?u.memoizedState:null}else u=_n.next;var h=jn===null?sn.memoizedState:jn.next;if(h!==null)jn=h,_n=u;else{if(u===null)throw Error(t(310));_n=u,u={memoizedState:_n.memoizedState,baseState:_n.baseState,baseQueue:_n.baseQueue,queue:_n.queue,next:null},jn===null?sn.memoizedState=jn=u:jn=jn.next=u}return jn}function $h(u,h){return typeof h=="function"?h(u):h}function Lx(u){var h=ii(),S=h.queue;if(S===null)throw Error(t(311));S.lastRenderedReducer=u;var w=_n,k=w.baseQueue,M=S.pending;if(M!==null){if(k!==null){var D=k.next;k.next=M.next,M.next=D}w.baseQueue=k=M,S.pending=null}if(k!==null){M=k.next,w=w.baseState;var B=D=null,q=null,oe=M;do{var fe=oe.lane;if((vc&fe)===fe)q!==null&&(q=q.next={lane:0,action:oe.action,hasEagerState:oe.hasEagerState,eagerState:oe.eagerState,next:null}),w=oe.hasEagerState?oe.eagerState:u(w,oe.action);else{var me={lane:fe,action:oe.action,hasEagerState:oe.hasEagerState,eagerState:oe.eagerState,next:null};q===null?(B=q=me,D=w):q=q.next=me,sn.lanes|=fe,xc|=fe}oe=oe.next}while(oe!==null&&oe!==M);q===null?D=w:q.next=B,Ri(w,h.memoizedState)||(is=!0),h.memoizedState=w,h.baseState=D,h.baseQueue=q,S.lastRenderedState=w}if(u=S.interleaved,u!==null){k=u;do M=k.lane,sn.lanes|=M,xc|=M,k=k.next;while(k!==u)}else k===null&&(S.lanes=0);return[h.memoizedState,S.dispatch]}function Fx(u){var h=ii(),S=h.queue;if(S===null)throw Error(t(311));S.lastRenderedReducer=u;var w=S.dispatch,k=S.pending,M=h.memoizedState;if(k!==null){S.pending=null;var D=k=k.next;do M=u(M,D.action),D=D.next;while(D!==k);Ri(M,h.memoizedState)||(is=!0),h.memoizedState=M,h.baseQueue===null&&(h.baseState=M),S.lastRenderedState=M}return[M,w]}function A2(){}function O2(u,h){var S=sn,w=ii(),k=h(),M=!Ri(w.memoizedState,k);if(M&&(w.memoizedState=k,is=!0),w=w.queue,zx(j2.bind(null,S,w,u),[u]),w.getSnapshot!==h||M||jn!==null&&jn.memoizedState.tag&1){if(S.flags|=2048,Bh(9,D2.bind(null,S,w,k,h),void 0,null),Nn===null)throw Error(t(349));(vc&30)!==0||R2(S,h,k)}return k}function R2(u,h,S){u.flags|=16384,u={getSnapshot:h,value:S},h=sn.updateQueue,h===null?(h={lastEffect:null,stores:null},sn.updateQueue=h,h.stores=[u]):(S=h.stores,S===null?h.stores=[u]:S.push(u))}function D2(u,h,S,w){h.value=S,h.getSnapshot=w,N2(h)&&L2(u)}function j2(u,h,S){return S(function(){N2(h)&&L2(u)})}function N2(u){var h=u.getSnapshot;u=u.value;try{var S=h();return!Ri(u,S)}catch{return!0}}function L2(u){var h=ra(u,1);h!==null&&Fi(h,u,1,-1)}function F2(u){var h=yo();return typeof u=="function"&&(u=u()),h.memoizedState=h.baseState=u,u={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:$h,lastRenderedState:u},h.queue=u,u=u.dispatch=IW.bind(null,sn,u),[h.memoizedState,u]}function Bh(u,h,S,w){return u={tag:u,create:h,destroy:S,deps:w,next:null},h=sn.updateQueue,h===null?(h={lastEffect:null,stores:null},sn.updateQueue=h,h.lastEffect=u.next=u):(S=h.lastEffect,S===null?h.lastEffect=u.next=u:(w=S.next,S.next=u,u.next=w,h.lastEffect=u)),u}function z2(){return ii().memoizedState}function jg(u,h,S,w){var k=yo();sn.flags|=u,k.memoizedState=Bh(1|h,S,void 0,w===void 0?null:w)}function Ng(u,h,S,w){var k=ii();w=w===void 0?null:w;var M=void 0;if(_n!==null){var D=_n.memoizedState;if(M=D.destroy,w!==null&&Dx(w,D.deps)){k.memoizedState=Bh(h,S,M,w);return}}sn.flags|=u,k.memoizedState=Bh(1|h,S,M,w)}function $2(u,h){return jg(8390656,8,u,h)}function zx(u,h){return Ng(2048,8,u,h)}function B2(u,h){return Ng(4,2,u,h)}function U2(u,h){return Ng(4,4,u,h)}function H2(u,h){if(typeof h=="function")return u=u(),h(u),function(){h(null)};if(h!=null)return u=u(),h.current=u,function(){h.current=null}}function K2(u,h,S){return S=S!=null?S.concat([u]):null,Ng(4,4,H2.bind(null,h,u),S)}function $x(){}function W2(u,h){var S=ii();h=h===void 0?null:h;var w=S.memoizedState;return w!==null&&h!==null&&Dx(h,w[1])?w[0]:(S.memoizedState=[u,h],u)}function V2(u,h){var S=ii();h=h===void 0?null:h;var w=S.memoizedState;return w!==null&&h!==null&&Dx(h,w[1])?w[0]:(u=u(),S.memoizedState=[u,h],u)}function q2(u,h,S){return(vc&21)===0?(u.baseState&&(u.baseState=!1,is=!0),u.memoizedState=S):(Ri(S,h)||(S=og(),sn.lanes|=S,xc|=S,u.baseState=!0),h)}function EW(u,h){var S=vt;vt=S!==0&&4>S?S:4,u(!0);var w=Rx.transition;Rx.transition={};try{u(!1),h()}finally{vt=S,Rx.transition=w}}function G2(){return ii().memoizedState}function kW(u,h,S){var w=al(u);if(S={lane:w,action:S,hasEagerState:!1,eagerState:null,next:null},Y2(u))X2(h,S);else if(S=k2(u,h,S,w),S!==null){var k=Dr();Fi(S,u,w,k),Z2(S,h,w)}}function IW(u,h,S){var w=al(u),k={lane:w,action:S,hasEagerState:!1,eagerState:null,next:null};if(Y2(u))X2(h,k);else{var M=u.alternate;if(u.lanes===0&&(M===null||M.lanes===0)&&(M=h.lastRenderedReducer,M!==null))try{var D=h.lastRenderedState,B=M(D,S);if(k.hasEagerState=!0,k.eagerState=B,Ri(B,D)){var q=h.interleaved;q===null?(k.next=k,Ix(h)):(k.next=q.next,q.next=k),h.interleaved=k;return}}catch{}finally{}S=k2(u,h,k,w),S!==null&&(k=Dr(),Fi(S,u,w,k),Z2(S,h,w))}}function Y2(u){var h=u.alternate;return u===sn||h!==null&&h===sn}function X2(u,h){Fh=Dg=!0;var S=u.pending;S===null?h.next=h:(h.next=S.next,S.next=h),u.pending=h}function Z2(u,h,S){if((S&4194240)!==0){var w=h.lanes;w&=u.pendingLanes,S|=w,h.lanes=S,Au(u,S)}}var Lg={readContext:si,useCallback:fr,useContext:fr,useEffect:fr,useImperativeHandle:fr,useInsertionEffect:fr,useLayoutEffect:fr,useMemo:fr,useReducer:fr,useRef:fr,useState:fr,useDebugValue:fr,useDeferredValue:fr,useTransition:fr,useMutableSource:fr,useSyncExternalStore:fr,useId:fr,unstable_isNewReconciler:!1},_W={readContext:si,useCallback:function(u,h){return yo().memoizedState=[u,h===void 0?null:h],u},useContext:si,useEffect:$2,useImperativeHandle:function(u,h,S){return S=S!=null?S.concat([u]):null,jg(4194308,4,H2.bind(null,h,u),S)},useLayoutEffect:function(u,h){return jg(4194308,4,u,h)},useInsertionEffect:function(u,h){return jg(4,2,u,h)},useMemo:function(u,h){var S=yo();return h=h===void 0?null:h,u=u(),S.memoizedState=[u,h],u},useReducer:function(u,h,S){var w=yo();return h=S!==void 0?S(h):h,w.memoizedState=w.baseState=h,u={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:u,lastRenderedState:h},w.queue=u,u=u.dispatch=kW.bind(null,sn,u),[w.memoizedState,u]},useRef:function(u){var h=yo();return u={current:u},h.memoizedState=u},useState:F2,useDebugValue:$x,useDeferredValue:function(u){return yo().memoizedState=u},useTransition:function(){var u=F2(!1),h=u[0];return u=EW.bind(null,u[1]),yo().memoizedState=u,[h,u]},useMutableSource:function(){},useSyncExternalStore:function(u,h,S){var w=sn,k=yo();if(Qt){if(S===void 0)throw Error(t(407));S=S()}else{if(S=h(),Nn===null)throw Error(t(349));(vc&30)!==0||R2(w,h,S)}k.memoizedState=S;var M={value:S,getSnapshot:h};return k.queue=M,$2(j2.bind(null,w,M,u),[u]),w.flags|=2048,Bh(9,D2.bind(null,w,M,S,h),void 0,null),S},useId:function(){var u=yo(),h=Nn.identifierPrefix;if(Qt){var S=na,w=ta;S=(w&~(1<<32-Ms(w)-1)).toString(32)+S,h=":"+h+"R"+S,S=zh++,0<S&&(h+="H"+S.toString(32)),h+=":"}else S=PW++,h=":"+h+"r"+S.toString(32)+":";return u.memoizedState=h},unstable_isNewReconciler:!1},TW={readContext:si,useCallback:W2,useContext:si,useEffect:zx,useImperativeHandle:K2,useInsertionEffect:B2,useLayoutEffect:U2,useMemo:V2,useReducer:Lx,useRef:z2,useState:function(){return Lx($h)},useDebugValue:$x,useDeferredValue:function(u){var h=ii();return q2(h,_n.memoizedState,u)},useTransition:function(){var u=Lx($h)[0],h=ii().memoizedState;return[u,h]},useMutableSource:A2,useSyncExternalStore:O2,useId:G2,unstable_isNewReconciler:!1},MW={readContext:si,useCallback:W2,useContext:si,useEffect:zx,useImperativeHandle:K2,useInsertionEffect:B2,useLayoutEffect:U2,useMemo:V2,useReducer:Fx,useRef:z2,useState:function(){return Fx($h)},useDebugValue:$x,useDeferredValue:function(u){var h=ii();return _n===null?h.memoizedState=u:q2(h,_n.memoizedState,u)},useTransition:function(){var u=Fx($h)[0],h=ii().memoizedState;return[u,h]},useMutableSource:A2,useSyncExternalStore:O2,useId:G2,unstable_isNewReconciler:!1};function ji(u,h){if(u&&u.defaultProps){h=re({},h),u=u.defaultProps;for(var S in u)h[S]===void 0&&(h[S]=u[S]);return h}return h}function Bx(u,h,S,w){h=u.memoizedState,S=S(w,h),S=S==null?h:re({},h,S),u.memoizedState=S,u.lanes===0&&(u.updateQueue.baseState=S)}var Fg={isMounted:function(u){return(u=u._reactInternals)?Zo(u)===u:!1},enqueueSetState:function(u,h,S){u=u._reactInternals;var w=Dr(),k=al(u),M=sa(w,k);M.payload=h,S!=null&&(M.callback=S),h=rl(u,M,k),h!==null&&(Fi(h,u,k,w),Mg(h,u,k))},enqueueReplaceState:function(u,h,S){u=u._reactInternals;var w=Dr(),k=al(u),M=sa(w,k);M.tag=1,M.payload=h,S!=null&&(M.callback=S),h=rl(u,M,k),h!==null&&(Fi(h,u,k,w),Mg(h,u,k))},enqueueForceUpdate:function(u,h){u=u._reactInternals;var S=Dr(),w=al(u),k=sa(S,w);k.tag=2,h!=null&&(k.callback=h),h=rl(u,k,w),h!==null&&(Fi(h,u,w,S),Mg(h,u,w))}};function J2(u,h,S,w,k,M,D){return u=u.stateNode,typeof u.shouldComponentUpdate=="function"?u.shouldComponentUpdate(w,M,D):h.prototype&&h.prototype.isPureReactComponent?!Ih(S,w)||!Ih(k,M):!0}function Q2(u,h,S){var w=!1,k=el,M=h.contextType;return typeof M=="object"&&M!==null?M=si(M):(k=ss(h)?pc:hr.current,w=h.contextTypes,M=(w=w!=null)?Bu(u,k):el),h=new h(S,M),u.memoizedState=h.state!==null&&h.state!==void 0?h.state:null,h.updater=Fg,u.stateNode=h,h._reactInternals=u,w&&(u=u.stateNode,u.__reactInternalMemoizedUnmaskedChildContext=k,u.__reactInternalMemoizedMaskedChildContext=M),h}function eM(u,h,S,w){u=h.state,typeof h.componentWillReceiveProps=="function"&&h.componentWillReceiveProps(S,w),typeof h.UNSAFE_componentWillReceiveProps=="function"&&h.UNSAFE_componentWillReceiveProps(S,w),h.state!==u&&Fg.enqueueReplaceState(h,h.state,null)}function Ux(u,h,S,w){var k=u.stateNode;k.props=S,k.state=u.memoizedState,k.refs={},_x(u);var M=h.contextType;typeof M=="object"&&M!==null?k.context=si(M):(M=ss(h)?pc:hr.current,k.context=Bu(u,M)),k.state=u.memoizedState,M=h.getDerivedStateFromProps,typeof M=="function"&&(Bx(u,h,M,S),k.state=u.memoizedState),typeof h.getDerivedStateFromProps=="function"||typeof k.getSnapshotBeforeUpdate=="function"||typeof k.UNSAFE_componentWillMount!="function"&&typeof k.componentWillMount!="function"||(h=k.state,typeof k.componentWillMount=="function"&&k.componentWillMount(),typeof k.UNSAFE_componentWillMount=="function"&&k.UNSAFE_componentWillMount(),h!==k.state&&Fg.enqueueReplaceState(k,k.state,null),Ag(u,S,k,w),k.state=u.memoizedState),typeof k.componentDidMount=="function"&&(u.flags|=4194308)}function Yu(u,h){try{var S="",w=h;do S+=ce(w),w=w.return;while(w);var k=S}catch(M){k=`
39
+ Error generating stack: `+M.message+`
40
+ `+M.stack}return{value:u,source:h,stack:k,digest:null}}function Hx(u,h,S){return{value:u,source:null,stack:S??null,digest:h??null}}function Kx(u,h){try{console.error(h.value)}catch(S){setTimeout(function(){throw S})}}var AW=typeof WeakMap=="function"?WeakMap:Map;function tM(u,h,S){S=sa(-1,S),S.tag=3,S.payload={element:null};var w=h.value;return S.callback=function(){Wg||(Wg=!0,iw=w),Kx(u,h)},S}function nM(u,h,S){S=sa(-1,S),S.tag=3;var w=u.type.getDerivedStateFromError;if(typeof w=="function"){var k=h.value;S.payload=function(){return w(k)},S.callback=function(){Kx(u,h)}}var M=u.stateNode;return M!==null&&typeof M.componentDidCatch=="function"&&(S.callback=function(){Kx(u,h),typeof w!="function"&&(il===null?il=new Set([this]):il.add(this));var D=h.stack;this.componentDidCatch(h.value,{componentStack:D!==null?D:""})}),S}function rM(u,h,S){var w=u.pingCache;if(w===null){w=u.pingCache=new AW;var k=new Set;w.set(h,k)}else k=w.get(h),k===void 0&&(k=new Set,w.set(h,k));k.has(S)||(k.add(S),u=WW.bind(null,u,h,S),h.then(u,u))}function sM(u){do{var h;if((h=u.tag===13)&&(h=u.memoizedState,h=h!==null?h.dehydrated!==null:!0),h)return u;u=u.return}while(u!==null);return null}function iM(u,h,S,w,k){return(u.mode&1)===0?(u===h?u.flags|=65536:(u.flags|=128,S.flags|=131072,S.flags&=-52805,S.tag===1&&(S.alternate===null?S.tag=17:(h=sa(-1,1),h.tag=2,rl(S,h,1))),S.lanes|=1),u):(u.flags|=65536,u.lanes=k,u)}var OW=_.ReactCurrentOwner,is=!1;function Rr(u,h,S,w){h.child=u===null?E2(h,null,S,w):Wu(h,u.child,S,w)}function oM(u,h,S,w,k){S=S.render;var M=h.ref;return qu(h,k),w=jx(u,h,S,w,M,k),S=Nx(),u!==null&&!is?(h.updateQueue=u.updateQueue,h.flags&=-2053,u.lanes&=~k,ia(u,h,k)):(Qt&&S&&Sx(h),h.flags|=1,Rr(u,h,w,k),h.child)}function aM(u,h,S,w,k){if(u===null){var M=S.type;return typeof M=="function"&&!hw(M)&&M.defaultProps===void 0&&S.compare===null&&S.defaultProps===void 0?(h.tag=15,h.type=M,lM(u,h,M,w,k)):(u=Zg(S.type,null,w,h,h.mode,k),u.ref=h.ref,u.return=h,h.child=u)}if(M=u.child,(u.lanes&k)===0){var D=M.memoizedProps;if(S=S.compare,S=S!==null?S:Ih,S(D,w)&&u.ref===h.ref)return ia(u,h,k)}return h.flags|=1,u=cl(M,w),u.ref=h.ref,u.return=h,h.child=u}function lM(u,h,S,w,k){if(u!==null){var M=u.memoizedProps;if(Ih(M,w)&&u.ref===h.ref)if(is=!1,h.pendingProps=w=M,(u.lanes&k)!==0)(u.flags&131072)!==0&&(is=!0);else return h.lanes=u.lanes,ia(u,h,k)}return Wx(u,h,S,w,k)}function cM(u,h,S){var w=h.pendingProps,k=w.children,M=u!==null?u.memoizedState:null;if(w.mode==="hidden")if((h.mode&1)===0)h.memoizedState={baseLanes:0,cachePool:null,transitions:null},Bt(Zu,Rs),Rs|=S;else{if((S&1073741824)===0)return u=M!==null?M.baseLanes|S:S,h.lanes=h.childLanes=1073741824,h.memoizedState={baseLanes:u,cachePool:null,transitions:null},h.updateQueue=null,Bt(Zu,Rs),Rs|=u,null;h.memoizedState={baseLanes:0,cachePool:null,transitions:null},w=M!==null?M.baseLanes:S,Bt(Zu,Rs),Rs|=w}else M!==null?(w=M.baseLanes|S,h.memoizedState=null):w=S,Bt(Zu,Rs),Rs|=w;return Rr(u,h,k,S),h.child}function uM(u,h){var S=h.ref;(u===null&&S!==null||u!==null&&u.ref!==S)&&(h.flags|=512,h.flags|=2097152)}function Wx(u,h,S,w,k){var M=ss(S)?pc:hr.current;return M=Bu(h,M),qu(h,k),S=jx(u,h,S,w,M,k),w=Nx(),u!==null&&!is?(h.updateQueue=u.updateQueue,h.flags&=-2053,u.lanes&=~k,ia(u,h,k)):(Qt&&w&&Sx(h),h.flags|=1,Rr(u,h,S,k),h.child)}function dM(u,h,S,w,k){if(ss(S)){var M=!0;bg(h)}else M=!1;if(qu(h,k),h.stateNode===null)$g(u,h),Q2(h,S,w),Ux(h,S,w,k),w=!0;else if(u===null){var D=h.stateNode,B=h.memoizedProps;D.props=B;var q=D.context,oe=S.contextType;typeof oe=="object"&&oe!==null?oe=si(oe):(oe=ss(S)?pc:hr.current,oe=Bu(h,oe));var fe=S.getDerivedStateFromProps,me=typeof fe=="function"||typeof D.getSnapshotBeforeUpdate=="function";me||typeof D.UNSAFE_componentWillReceiveProps!="function"&&typeof D.componentWillReceiveProps!="function"||(B!==w||q!==oe)&&eM(h,D,w,oe),nl=!1;var he=h.memoizedState;D.state=he,Ag(h,w,D,k),q=h.memoizedState,B!==w||he!==q||rs.current||nl?(typeof fe=="function"&&(Bx(h,S,fe,w),q=h.memoizedState),(B=nl||J2(h,S,B,w,he,q,oe))?(me||typeof D.UNSAFE_componentWillMount!="function"&&typeof D.componentWillMount!="function"||(typeof D.componentWillMount=="function"&&D.componentWillMount(),typeof D.UNSAFE_componentWillMount=="function"&&D.UNSAFE_componentWillMount()),typeof D.componentDidMount=="function"&&(h.flags|=4194308)):(typeof D.componentDidMount=="function"&&(h.flags|=4194308),h.memoizedProps=w,h.memoizedState=q),D.props=w,D.state=q,D.context=oe,w=B):(typeof D.componentDidMount=="function"&&(h.flags|=4194308),w=!1)}else{D=h.stateNode,I2(u,h),B=h.memoizedProps,oe=h.type===h.elementType?B:ji(h.type,B),D.props=oe,me=h.pendingProps,he=D.context,q=S.contextType,typeof q=="object"&&q!==null?q=si(q):(q=ss(S)?pc:hr.current,q=Bu(h,q));var Me=S.getDerivedStateFromProps;(fe=typeof Me=="function"||typeof D.getSnapshotBeforeUpdate=="function")||typeof D.UNSAFE_componentWillReceiveProps!="function"&&typeof D.componentWillReceiveProps!="function"||(B!==me||he!==q)&&eM(h,D,w,q),nl=!1,he=h.memoizedState,D.state=he,Ag(h,w,D,k);var je=h.memoizedState;B!==me||he!==je||rs.current||nl?(typeof Me=="function"&&(Bx(h,S,Me,w),je=h.memoizedState),(oe=nl||J2(h,S,oe,w,he,je,q)||!1)?(fe||typeof D.UNSAFE_componentWillUpdate!="function"&&typeof D.componentWillUpdate!="function"||(typeof D.componentWillUpdate=="function"&&D.componentWillUpdate(w,je,q),typeof D.UNSAFE_componentWillUpdate=="function"&&D.UNSAFE_componentWillUpdate(w,je,q)),typeof D.componentDidUpdate=="function"&&(h.flags|=4),typeof D.getSnapshotBeforeUpdate=="function"&&(h.flags|=1024)):(typeof D.componentDidUpdate!="function"||B===u.memoizedProps&&he===u.memoizedState||(h.flags|=4),typeof D.getSnapshotBeforeUpdate!="function"||B===u.memoizedProps&&he===u.memoizedState||(h.flags|=1024),h.memoizedProps=w,h.memoizedState=je),D.props=w,D.state=je,D.context=q,w=oe):(typeof D.componentDidUpdate!="function"||B===u.memoizedProps&&he===u.memoizedState||(h.flags|=4),typeof D.getSnapshotBeforeUpdate!="function"||B===u.memoizedProps&&he===u.memoizedState||(h.flags|=1024),w=!1)}return Vx(u,h,S,w,M,k)}function Vx(u,h,S,w,k,M){uM(u,h);var D=(h.flags&128)!==0;if(!w&&!D)return k&&m2(h,S,!1),ia(u,h,M);w=h.stateNode,OW.current=h;var B=D&&typeof S.getDerivedStateFromError!="function"?null:w.render();return h.flags|=1,u!==null&&D?(h.child=Wu(h,u.child,null,M),h.child=Wu(h,null,B,M)):Rr(u,h,B,M),h.memoizedState=w.state,k&&m2(h,S,!0),h.child}function hM(u){var h=u.stateNode;h.pendingContext?p2(u,h.pendingContext,h.pendingContext!==h.context):h.context&&p2(u,h.context,!1),Tx(u,h.containerInfo)}function fM(u,h,S,w,k){return Ku(),bx(k),h.flags|=256,Rr(u,h,S,w),h.child}var qx={dehydrated:null,treeContext:null,retryLane:0};function Gx(u){return{baseLanes:u,cachePool:null,transitions:null}}function pM(u,h,S){var w=h.pendingProps,k=rn.current,M=!1,D=(h.flags&128)!==0,B;if((B=D)||(B=u!==null&&u.memoizedState===null?!1:(k&2)!==0),B?(M=!0,h.flags&=-129):(u===null||u.memoizedState!==null)&&(k|=1),Bt(rn,k&1),u===null)return wx(h),u=h.memoizedState,u!==null&&(u=u.dehydrated,u!==null)?((h.mode&1)===0?h.lanes=1:u.data==="$!"?h.lanes=8:h.lanes=1073741824,null):(D=w.children,u=w.fallback,M?(w=h.mode,M=h.child,D={mode:"hidden",children:D},(w&1)===0&&M!==null?(M.childLanes=0,M.pendingProps=D):M=Jg(D,w,0,null),u=Pc(u,w,S,null),M.return=h,u.return=h,M.sibling=u,h.child=M,h.child.memoizedState=Gx(S),h.memoizedState=qx,u):Yx(h,D));if(k=u.memoizedState,k!==null&&(B=k.dehydrated,B!==null))return RW(u,h,D,w,B,k,S);if(M){M=w.fallback,D=h.mode,k=u.child,B=k.sibling;var q={mode:"hidden",children:w.children};return(D&1)===0&&h.child!==k?(w=h.child,w.childLanes=0,w.pendingProps=q,h.deletions=null):(w=cl(k,q),w.subtreeFlags=k.subtreeFlags&14680064),B!==null?M=cl(B,M):(M=Pc(M,D,S,null),M.flags|=2),M.return=h,w.return=h,w.sibling=M,h.child=w,w=M,M=h.child,D=u.child.memoizedState,D=D===null?Gx(S):{baseLanes:D.baseLanes|S,cachePool:null,transitions:D.transitions},M.memoizedState=D,M.childLanes=u.childLanes&~S,h.memoizedState=qx,w}return M=u.child,u=M.sibling,w=cl(M,{mode:"visible",children:w.children}),(h.mode&1)===0&&(w.lanes=S),w.return=h,w.sibling=null,u!==null&&(S=h.deletions,S===null?(h.deletions=[u],h.flags|=16):S.push(u)),h.child=w,h.memoizedState=null,w}function Yx(u,h){return h=Jg({mode:"visible",children:h},u.mode,0,null),h.return=u,u.child=h}function zg(u,h,S,w){return w!==null&&bx(w),Wu(h,u.child,null,S),u=Yx(h,h.pendingProps.children),u.flags|=2,h.memoizedState=null,u}function RW(u,h,S,w,k,M,D){if(S)return h.flags&256?(h.flags&=-257,w=Hx(Error(t(422))),zg(u,h,D,w)):h.memoizedState!==null?(h.child=u.child,h.flags|=128,null):(M=w.fallback,k=h.mode,w=Jg({mode:"visible",children:w.children},k,0,null),M=Pc(M,k,D,null),M.flags|=2,w.return=h,M.return=h,w.sibling=M,h.child=w,(h.mode&1)!==0&&Wu(h,u.child,null,D),h.child.memoizedState=Gx(D),h.memoizedState=qx,M);if((h.mode&1)===0)return zg(u,h,D,null);if(k.data==="$!"){if(w=k.nextSibling&&k.nextSibling.dataset,w)var B=w.dgst;return w=B,M=Error(t(419)),w=Hx(M,w,void 0),zg(u,h,D,w)}if(B=(D&u.childLanes)!==0,is||B){if(w=Nn,w!==null){switch(D&-D){case 4:k=2;break;case 16:k=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:k=32;break;case 536870912:k=268435456;break;default:k=0}k=(k&(w.suspendedLanes|D))!==0?0:k,k!==0&&k!==M.retryLane&&(M.retryLane=k,ra(u,k),Fi(w,u,k,-1))}return dw(),w=Hx(Error(t(421))),zg(u,h,D,w)}return k.data==="$?"?(h.flags|=128,h.child=u.child,h=VW.bind(null,u),k._reactRetry=h,null):(u=M.treeContext,Os=Ja(k.nextSibling),As=h,Qt=!0,Di=null,u!==null&&(ni[ri++]=ta,ni[ri++]=na,ni[ri++]=gc,ta=u.id,na=u.overflow,gc=h),h=Yx(h,w.children),h.flags|=4096,h)}function gM(u,h,S){u.lanes|=h;var w=u.alternate;w!==null&&(w.lanes|=h),kx(u.return,h,S)}function Xx(u,h,S,w,k){var M=u.memoizedState;M===null?u.memoizedState={isBackwards:h,rendering:null,renderingStartTime:0,last:w,tail:S,tailMode:k}:(M.isBackwards=h,M.rendering=null,M.renderingStartTime=0,M.last=w,M.tail=S,M.tailMode=k)}function mM(u,h,S){var w=h.pendingProps,k=w.revealOrder,M=w.tail;if(Rr(u,h,w.children,S),w=rn.current,(w&2)!==0)w=w&1|2,h.flags|=128;else{if(u!==null&&(u.flags&128)!==0)e:for(u=h.child;u!==null;){if(u.tag===13)u.memoizedState!==null&&gM(u,S,h);else if(u.tag===19)gM(u,S,h);else if(u.child!==null){u.child.return=u,u=u.child;continue}if(u===h)break e;for(;u.sibling===null;){if(u.return===null||u.return===h)break e;u=u.return}u.sibling.return=u.return,u=u.sibling}w&=1}if(Bt(rn,w),(h.mode&1)===0)h.memoizedState=null;else switch(k){case"forwards":for(S=h.child,k=null;S!==null;)u=S.alternate,u!==null&&Og(u)===null&&(k=S),S=S.sibling;S=k,S===null?(k=h.child,h.child=null):(k=S.sibling,S.sibling=null),Xx(h,!1,k,S,M);break;case"backwards":for(S=null,k=h.child,h.child=null;k!==null;){if(u=k.alternate,u!==null&&Og(u)===null){h.child=k;break}u=k.sibling,k.sibling=S,S=k,k=u}Xx(h,!0,S,null,M);break;case"together":Xx(h,!1,null,null,void 0);break;default:h.memoizedState=null}return h.child}function $g(u,h){(h.mode&1)===0&&u!==null&&(u.alternate=null,h.alternate=null,h.flags|=2)}function ia(u,h,S){if(u!==null&&(h.dependencies=u.dependencies),xc|=h.lanes,(S&h.childLanes)===0)return null;if(u!==null&&h.child!==u.child)throw Error(t(153));if(h.child!==null){for(u=h.child,S=cl(u,u.pendingProps),h.child=S,S.return=h;u.sibling!==null;)u=u.sibling,S=S.sibling=cl(u,u.pendingProps),S.return=h;S.sibling=null}return h.child}function DW(u,h,S){switch(h.tag){case 3:hM(h),Ku();break;case 5:M2(h);break;case 1:ss(h.type)&&bg(h);break;case 4:Tx(h,h.stateNode.containerInfo);break;case 10:var w=h.type._context,k=h.memoizedProps.value;Bt(_g,w._currentValue),w._currentValue=k;break;case 13:if(w=h.memoizedState,w!==null)return w.dehydrated!==null?(Bt(rn,rn.current&1),h.flags|=128,null):(S&h.child.childLanes)!==0?pM(u,h,S):(Bt(rn,rn.current&1),u=ia(u,h,S),u!==null?u.sibling:null);Bt(rn,rn.current&1);break;case 19:if(w=(S&h.childLanes)!==0,(u.flags&128)!==0){if(w)return mM(u,h,S);h.flags|=128}if(k=h.memoizedState,k!==null&&(k.rendering=null,k.tail=null,k.lastEffect=null),Bt(rn,rn.current),w)break;return null;case 22:case 23:return h.lanes=0,cM(u,h,S)}return ia(u,h,S)}var yM,Zx,SM,vM;yM=function(u,h){for(var S=h.child;S!==null;){if(S.tag===5||S.tag===6)u.appendChild(S.stateNode);else if(S.tag!==4&&S.child!==null){S.child.return=S,S=S.child;continue}if(S===h)break;for(;S.sibling===null;){if(S.return===null||S.return===h)return;S=S.return}S.sibling.return=S.return,S=S.sibling}},Zx=function(){},SM=function(u,h,S,w){var k=u.memoizedProps;if(k!==w){u=h.stateNode,Sc(mo.current);var M=null;switch(S){case"input":k=Jt(u,k),w=Jt(u,w),M=[];break;case"select":k=re({},k,{value:void 0}),w=re({},w,{value:void 0}),M=[];break;case"textarea":k=rc(u,k),w=rc(u,w),M=[];break;default:typeof k.onClick!="function"&&typeof w.onClick=="function"&&(u.onclick=vg)}Yo(S,w);var D;S=null;for(oe in k)if(!w.hasOwnProperty(oe)&&k.hasOwnProperty(oe)&&k[oe]!=null)if(oe==="style"){var B=k[oe];for(D in B)B.hasOwnProperty(D)&&(S||(S={}),S[D]="")}else oe!=="dangerouslySetInnerHTML"&&oe!=="children"&&oe!=="suppressContentEditableWarning"&&oe!=="suppressHydrationWarning"&&oe!=="autoFocus"&&(s.hasOwnProperty(oe)?M||(M=[]):(M=M||[]).push(oe,null));for(oe in w){var q=w[oe];if(B=k!=null?k[oe]:void 0,w.hasOwnProperty(oe)&&q!==B&&(q!=null||B!=null))if(oe==="style")if(B){for(D in B)!B.hasOwnProperty(D)||q&&q.hasOwnProperty(D)||(S||(S={}),S[D]="");for(D in q)q.hasOwnProperty(D)&&B[D]!==q[D]&&(S||(S={}),S[D]=q[D])}else S||(M||(M=[]),M.push(oe,S)),S=q;else oe==="dangerouslySetInnerHTML"?(q=q?q.__html:void 0,B=B?B.__html:void 0,q!=null&&B!==q&&(M=M||[]).push(oe,q)):oe==="children"?typeof q!="string"&&typeof q!="number"||(M=M||[]).push(oe,""+q):oe!=="suppressContentEditableWarning"&&oe!=="suppressHydrationWarning"&&(s.hasOwnProperty(oe)?(q!=null&&oe==="onScroll"&&Wt("scroll",u),M||B===q||(M=[])):(M=M||[]).push(oe,q))}S&&(M=M||[]).push("style",S);var oe=M;(h.updateQueue=oe)&&(h.flags|=4)}},vM=function(u,h,S,w){S!==w&&(h.flags|=4)};function Uh(u,h){if(!Qt)switch(u.tailMode){case"hidden":h=u.tail;for(var S=null;h!==null;)h.alternate!==null&&(S=h),h=h.sibling;S===null?u.tail=null:S.sibling=null;break;case"collapsed":S=u.tail;for(var w=null;S!==null;)S.alternate!==null&&(w=S),S=S.sibling;w===null?h||u.tail===null?u.tail=null:u.tail.sibling=null:w.sibling=null}}function pr(u){var h=u.alternate!==null&&u.alternate.child===u.child,S=0,w=0;if(h)for(var k=u.child;k!==null;)S|=k.lanes|k.childLanes,w|=k.subtreeFlags&14680064,w|=k.flags&14680064,k.return=u,k=k.sibling;else for(k=u.child;k!==null;)S|=k.lanes|k.childLanes,w|=k.subtreeFlags,w|=k.flags,k.return=u,k=k.sibling;return u.subtreeFlags|=w,u.childLanes=S,h}function jW(u,h,S){var w=h.pendingProps;switch(vx(h),h.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return pr(h),null;case 1:return ss(h.type)&&wg(),pr(h),null;case 3:return w=h.stateNode,Gu(),Vt(rs),Vt(hr),Ox(),w.pendingContext&&(w.context=w.pendingContext,w.pendingContext=null),(u===null||u.child===null)&&(kg(h)?h.flags|=4:u===null||u.memoizedState.isDehydrated&&(h.flags&256)===0||(h.flags|=1024,Di!==null&&(lw(Di),Di=null))),Zx(u,h),pr(h),null;case 5:Mx(h);var k=Sc(Lh.current);if(S=h.type,u!==null&&h.stateNode!=null)SM(u,h,S,w,k),u.ref!==h.ref&&(h.flags|=512,h.flags|=2097152);else{if(!w){if(h.stateNode===null)throw Error(t(166));return pr(h),null}if(u=Sc(mo.current),kg(h)){w=h.stateNode,S=h.type;var M=h.memoizedProps;switch(w[go]=h,w[Oh]=M,u=(h.mode&1)!==0,S){case"dialog":Wt("cancel",w),Wt("close",w);break;case"iframe":case"object":case"embed":Wt("load",w);break;case"video":case"audio":for(k=0;k<Th.length;k++)Wt(Th[k],w);break;case"source":Wt("error",w);break;case"img":case"image":case"link":Wt("error",w),Wt("load",w);break;case"details":Wt("toggle",w);break;case"input":jt(w,M),Wt("invalid",w);break;case"select":w._wrapperState={wasMultiple:!!M.multiple},Wt("invalid",w);break;case"textarea":Su(w,M),Wt("invalid",w)}Yo(S,M),k=null;for(var D in M)if(M.hasOwnProperty(D)){var B=M[D];D==="children"?typeof B=="string"?w.textContent!==B&&(M.suppressHydrationWarning!==!0&&Sg(w.textContent,B,u),k=["children",B]):typeof B=="number"&&w.textContent!==""+B&&(M.suppressHydrationWarning!==!0&&Sg(w.textContent,B,u),k=["children",""+B]):s.hasOwnProperty(D)&&B!=null&&D==="onScroll"&&Wt("scroll",w)}switch(S){case"input":it(w),Xr(w,M,!0);break;case"textarea":it(w),xu(w);break;case"select":case"option":break;default:typeof M.onClick=="function"&&(w.onclick=vg)}w=k,h.updateQueue=w,w!==null&&(h.flags|=4)}else{D=k.nodeType===9?k:k.ownerDocument,u==="http://www.w3.org/1999/xhtml"&&(u=wu(S)),u==="http://www.w3.org/1999/xhtml"?S==="script"?(u=D.createElement("div"),u.innerHTML="<script><\/script>",u=u.removeChild(u.firstChild)):typeof w.is=="string"?u=D.createElement(S,{is:w.is}):(u=D.createElement(S),S==="select"&&(D=u,w.multiple?D.multiple=!0:w.size&&(D.size=w.size))):u=D.createElementNS(u,S),u[go]=h,u[Oh]=w,yM(u,h,!1,!1),h.stateNode=u;e:{switch(D=Is(S,w),S){case"dialog":Wt("cancel",u),Wt("close",u),k=w;break;case"iframe":case"object":case"embed":Wt("load",u),k=w;break;case"video":case"audio":for(k=0;k<Th.length;k++)Wt(Th[k],u);k=w;break;case"source":Wt("error",u),k=w;break;case"img":case"image":case"link":Wt("error",u),Wt("load",u),k=w;break;case"details":Wt("toggle",u),k=w;break;case"input":jt(u,w),k=Jt(u,w),Wt("invalid",u);break;case"option":k=w;break;case"select":u._wrapperState={wasMultiple:!!w.multiple},k=re({},w,{value:void 0}),Wt("invalid",u);break;case"textarea":Su(u,w),k=rc(u,w),Wt("invalid",u);break;default:k=w}Yo(S,k),B=k;for(M in B)if(B.hasOwnProperty(M)){var q=B[M];M==="style"?Js(u,q):M==="dangerouslySetInnerHTML"?(q=q?q.__html:void 0,q!=null&&sc(u,q)):M==="children"?typeof q=="string"?(S!=="textarea"||q!=="")&&ae(u,q):typeof q=="number"&&ae(u,""+q):M!=="suppressContentEditableWarning"&&M!=="suppressHydrationWarning"&&M!=="autoFocus"&&(s.hasOwnProperty(M)?q!=null&&M==="onScroll"&&Wt("scroll",u):q!=null&&I(u,M,q,D))}switch(S){case"input":it(u),Xr(u,w,!1);break;case"textarea":it(u),xu(u);break;case"option":w.value!=null&&u.setAttribute("value",""+Ce(w.value));break;case"select":u.multiple=!!w.multiple,M=w.value,M!=null?Zs(u,!!w.multiple,M,!1):w.defaultValue!=null&&Zs(u,!!w.multiple,w.defaultValue,!0);break;default:typeof k.onClick=="function"&&(u.onclick=vg)}switch(S){case"button":case"input":case"select":case"textarea":w=!!w.autoFocus;break e;case"img":w=!0;break e;default:w=!1}}w&&(h.flags|=4)}h.ref!==null&&(h.flags|=512,h.flags|=2097152)}return pr(h),null;case 6:if(u&&h.stateNode!=null)vM(u,h,u.memoizedProps,w);else{if(typeof w!="string"&&h.stateNode===null)throw Error(t(166));if(S=Sc(Lh.current),Sc(mo.current),kg(h)){if(w=h.stateNode,S=h.memoizedProps,w[go]=h,(M=w.nodeValue!==S)&&(u=As,u!==null))switch(u.tag){case 3:Sg(w.nodeValue,S,(u.mode&1)!==0);break;case 5:u.memoizedProps.suppressHydrationWarning!==!0&&Sg(w.nodeValue,S,(u.mode&1)!==0)}M&&(h.flags|=4)}else w=(S.nodeType===9?S:S.ownerDocument).createTextNode(w),w[go]=h,h.stateNode=w}return pr(h),null;case 13:if(Vt(rn),w=h.memoizedState,u===null||u.memoizedState!==null&&u.memoizedState.dehydrated!==null){if(Qt&&Os!==null&&(h.mode&1)!==0&&(h.flags&128)===0)b2(),Ku(),h.flags|=98560,M=!1;else if(M=kg(h),w!==null&&w.dehydrated!==null){if(u===null){if(!M)throw Error(t(318));if(M=h.memoizedState,M=M!==null?M.dehydrated:null,!M)throw Error(t(317));M[go]=h}else Ku(),(h.flags&128)===0&&(h.memoizedState=null),h.flags|=4;pr(h),M=!1}else Di!==null&&(lw(Di),Di=null),M=!0;if(!M)return h.flags&65536?h:null}return(h.flags&128)!==0?(h.lanes=S,h):(w=w!==null,w!==(u!==null&&u.memoizedState!==null)&&w&&(h.child.flags|=8192,(h.mode&1)!==0&&(u===null||(rn.current&1)!==0?Tn===0&&(Tn=3):dw())),h.updateQueue!==null&&(h.flags|=4),pr(h),null);case 4:return Gu(),Zx(u,h),u===null&&Mh(h.stateNode.containerInfo),pr(h),null;case 10:return Ex(h.type._context),pr(h),null;case 17:return ss(h.type)&&wg(),pr(h),null;case 19:if(Vt(rn),M=h.memoizedState,M===null)return pr(h),null;if(w=(h.flags&128)!==0,D=M.rendering,D===null)if(w)Uh(M,!1);else{if(Tn!==0||u!==null&&(u.flags&128)!==0)for(u=h.child;u!==null;){if(D=Og(u),D!==null){for(h.flags|=128,Uh(M,!1),w=D.updateQueue,w!==null&&(h.updateQueue=w,h.flags|=4),h.subtreeFlags=0,w=S,S=h.child;S!==null;)M=S,u=w,M.flags&=14680066,D=M.alternate,D===null?(M.childLanes=0,M.lanes=u,M.child=null,M.subtreeFlags=0,M.memoizedProps=null,M.memoizedState=null,M.updateQueue=null,M.dependencies=null,M.stateNode=null):(M.childLanes=D.childLanes,M.lanes=D.lanes,M.child=D.child,M.subtreeFlags=0,M.deletions=null,M.memoizedProps=D.memoizedProps,M.memoizedState=D.memoizedState,M.updateQueue=D.updateQueue,M.type=D.type,u=D.dependencies,M.dependencies=u===null?null:{lanes:u.lanes,firstContext:u.firstContext}),S=S.sibling;return Bt(rn,rn.current&1|2),h.child}u=u.sibling}M.tail!==null&&nn()>Ju&&(h.flags|=128,w=!0,Uh(M,!1),h.lanes=4194304)}else{if(!w)if(u=Og(D),u!==null){if(h.flags|=128,w=!0,S=u.updateQueue,S!==null&&(h.updateQueue=S,h.flags|=4),Uh(M,!0),M.tail===null&&M.tailMode==="hidden"&&!D.alternate&&!Qt)return pr(h),null}else 2*nn()-M.renderingStartTime>Ju&&S!==1073741824&&(h.flags|=128,w=!0,Uh(M,!1),h.lanes=4194304);M.isBackwards?(D.sibling=h.child,h.child=D):(S=M.last,S!==null?S.sibling=D:h.child=D,M.last=D)}return M.tail!==null?(h=M.tail,M.rendering=h,M.tail=h.sibling,M.renderingStartTime=nn(),h.sibling=null,S=rn.current,Bt(rn,w?S&1|2:S&1),h):(pr(h),null);case 22:case 23:return uw(),w=h.memoizedState!==null,u!==null&&u.memoizedState!==null!==w&&(h.flags|=8192),w&&(h.mode&1)!==0?(Rs&1073741824)!==0&&(pr(h),h.subtreeFlags&6&&(h.flags|=8192)):pr(h),null;case 24:return null;case 25:return null}throw Error(t(156,h.tag))}function NW(u,h){switch(vx(h),h.tag){case 1:return ss(h.type)&&wg(),u=h.flags,u&65536?(h.flags=u&-65537|128,h):null;case 3:return Gu(),Vt(rs),Vt(hr),Ox(),u=h.flags,(u&65536)!==0&&(u&128)===0?(h.flags=u&-65537|128,h):null;case 5:return Mx(h),null;case 13:if(Vt(rn),u=h.memoizedState,u!==null&&u.dehydrated!==null){if(h.alternate===null)throw Error(t(340));Ku()}return u=h.flags,u&65536?(h.flags=u&-65537|128,h):null;case 19:return Vt(rn),null;case 4:return Gu(),null;case 10:return Ex(h.type._context),null;case 22:case 23:return uw(),null;case 24:return null;default:return null}}var Bg=!1,gr=!1,LW=typeof WeakSet=="function"?WeakSet:Set,Oe=null;function Xu(u,h){var S=u.ref;if(S!==null)if(typeof S=="function")try{S(null)}catch(w){dn(u,h,w)}else S.current=null}function Jx(u,h,S){try{S()}catch(w){dn(u,h,w)}}var xM=!1;function FW(u,h){if(ux=Z,u=JT(),nx(u)){if("selectionStart"in u)var S={start:u.selectionStart,end:u.selectionEnd};else e:{S=(S=u.ownerDocument)&&S.defaultView||window;var w=S.getSelection&&S.getSelection();if(w&&w.rangeCount!==0){S=w.anchorNode;var k=w.anchorOffset,M=w.focusNode;w=w.focusOffset;try{S.nodeType,M.nodeType}catch{S=null;break e}var D=0,B=-1,q=-1,oe=0,fe=0,me=u,he=null;t:for(;;){for(var Me;me!==S||k!==0&&me.nodeType!==3||(B=D+k),me!==M||w!==0&&me.nodeType!==3||(q=D+w),me.nodeType===3&&(D+=me.nodeValue.length),(Me=me.firstChild)!==null;)he=me,me=Me;for(;;){if(me===u)break t;if(he===S&&++oe===k&&(B=D),he===M&&++fe===w&&(q=D),(Me=me.nextSibling)!==null)break;me=he,he=me.parentNode}me=Me}S=B===-1||q===-1?null:{start:B,end:q}}else S=null}S=S||{start:0,end:0}}else S=null;for(dx={focusedElem:u,selectionRange:S},Z=!1,Oe=h;Oe!==null;)if(h=Oe,u=h.child,(h.subtreeFlags&1028)!==0&&u!==null)u.return=h,Oe=u;else for(;Oe!==null;){h=Oe;try{var je=h.alternate;if((h.flags&1024)!==0)switch(h.tag){case 0:case 11:case 15:break;case 1:if(je!==null){var Fe=je.memoizedProps,Sn=je.memoizedState,Q=h.stateNode,Y=Q.getSnapshotBeforeUpdate(h.elementType===h.type?Fe:ji(h.type,Fe),Sn);Q.__reactInternalSnapshotBeforeUpdate=Y}break;case 3:var se=h.stateNode.containerInfo;se.nodeType===1?se.textContent="":se.nodeType===9&&se.documentElement&&se.removeChild(se.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(t(163))}}catch(xe){dn(h,h.return,xe)}if(u=h.sibling,u!==null){u.return=h.return,Oe=u;break}Oe=h.return}return je=xM,xM=!1,je}function Hh(u,h,S){var w=h.updateQueue;if(w=w!==null?w.lastEffect:null,w!==null){var k=w=w.next;do{if((k.tag&u)===u){var M=k.destroy;k.destroy=void 0,M!==void 0&&Jx(h,S,M)}k=k.next}while(k!==w)}}function Ug(u,h){if(h=h.updateQueue,h=h!==null?h.lastEffect:null,h!==null){var S=h=h.next;do{if((S.tag&u)===u){var w=S.create;S.destroy=w()}S=S.next}while(S!==h)}}function Qx(u){var h=u.ref;if(h!==null){var S=u.stateNode;switch(u.tag){case 5:u=S;break;default:u=S}typeof h=="function"?h(u):h.current=u}}function wM(u){var h=u.alternate;h!==null&&(u.alternate=null,wM(h)),u.child=null,u.deletions=null,u.sibling=null,u.tag===5&&(h=u.stateNode,h!==null&&(delete h[go],delete h[Oh],delete h[gx],delete h[xW],delete h[wW])),u.stateNode=null,u.return=null,u.dependencies=null,u.memoizedProps=null,u.memoizedState=null,u.pendingProps=null,u.stateNode=null,u.updateQueue=null}function bM(u){return u.tag===5||u.tag===3||u.tag===4}function CM(u){e:for(;;){for(;u.sibling===null;){if(u.return===null||bM(u.return))return null;u=u.return}for(u.sibling.return=u.return,u=u.sibling;u.tag!==5&&u.tag!==6&&u.tag!==18;){if(u.flags&2||u.child===null||u.tag===4)continue e;u.child.return=u,u=u.child}if(!(u.flags&2))return u.stateNode}}function ew(u,h,S){var w=u.tag;if(w===5||w===6)u=u.stateNode,h?S.nodeType===8?S.parentNode.insertBefore(u,h):S.insertBefore(u,h):(S.nodeType===8?(h=S.parentNode,h.insertBefore(u,S)):(h=S,h.appendChild(u)),S=S._reactRootContainer,S!=null||h.onclick!==null||(h.onclick=vg));else if(w!==4&&(u=u.child,u!==null))for(ew(u,h,S),u=u.sibling;u!==null;)ew(u,h,S),u=u.sibling}function tw(u,h,S){var w=u.tag;if(w===5||w===6)u=u.stateNode,h?S.insertBefore(u,h):S.appendChild(u);else if(w!==4&&(u=u.child,u!==null))for(tw(u,h,S),u=u.sibling;u!==null;)tw(u,h,S),u=u.sibling}var Gn=null,Ni=!1;function sl(u,h,S){for(S=S.child;S!==null;)PM(u,h,S),S=S.sibling}function PM(u,h,S){if(ti&&typeof ti.onCommitFiberUnmount=="function")try{ti.onCommitFiberUnmount(Iu,S)}catch{}switch(S.tag){case 5:gr||Xu(S,h);case 6:var w=Gn,k=Ni;Gn=null,sl(u,h,S),Gn=w,Ni=k,Gn!==null&&(Ni?(u=Gn,S=S.stateNode,u.nodeType===8?u.parentNode.removeChild(S):u.removeChild(S)):Gn.removeChild(S.stateNode));break;case 18:Gn!==null&&(Ni?(u=Gn,S=S.stateNode,u.nodeType===8?px(u.parentNode,S):u.nodeType===1&&px(u,S),hc(u)):px(Gn,S.stateNode));break;case 4:w=Gn,k=Ni,Gn=S.stateNode.containerInfo,Ni=!0,sl(u,h,S),Gn=w,Ni=k;break;case 0:case 11:case 14:case 15:if(!gr&&(w=S.updateQueue,w!==null&&(w=w.lastEffect,w!==null))){k=w=w.next;do{var M=k,D=M.destroy;M=M.tag,D!==void 0&&((M&2)!==0||(M&4)!==0)&&Jx(S,h,D),k=k.next}while(k!==w)}sl(u,h,S);break;case 1:if(!gr&&(Xu(S,h),w=S.stateNode,typeof w.componentWillUnmount=="function"))try{w.props=S.memoizedProps,w.state=S.memoizedState,w.componentWillUnmount()}catch(B){dn(S,h,B)}sl(u,h,S);break;case 21:sl(u,h,S);break;case 22:S.mode&1?(gr=(w=gr)||S.memoizedState!==null,sl(u,h,S),gr=w):sl(u,h,S);break;default:sl(u,h,S)}}function EM(u){var h=u.updateQueue;if(h!==null){u.updateQueue=null;var S=u.stateNode;S===null&&(S=u.stateNode=new LW),h.forEach(function(w){var k=qW.bind(null,u,w);S.has(w)||(S.add(w),w.then(k,k))})}}function Li(u,h){var S=h.deletions;if(S!==null)for(var w=0;w<S.length;w++){var k=S[w];try{var M=u,D=h,B=D;e:for(;B!==null;){switch(B.tag){case 5:Gn=B.stateNode,Ni=!1;break e;case 3:Gn=B.stateNode.containerInfo,Ni=!0;break e;case 4:Gn=B.stateNode.containerInfo,Ni=!0;break e}B=B.return}if(Gn===null)throw Error(t(160));PM(M,D,k),Gn=null,Ni=!1;var q=k.alternate;q!==null&&(q.return=null),k.return=null}catch(oe){dn(k,h,oe)}}if(h.subtreeFlags&12854)for(h=h.child;h!==null;)kM(h,u),h=h.sibling}function kM(u,h){var S=u.alternate,w=u.flags;switch(u.tag){case 0:case 11:case 14:case 15:if(Li(h,u),So(u),w&4){try{Hh(3,u,u.return),Ug(3,u)}catch(Fe){dn(u,u.return,Fe)}try{Hh(5,u,u.return)}catch(Fe){dn(u,u.return,Fe)}}break;case 1:Li(h,u),So(u),w&512&&S!==null&&Xu(S,S.return);break;case 5:if(Li(h,u),So(u),w&512&&S!==null&&Xu(S,S.return),u.flags&32){var k=u.stateNode;try{ae(k,"")}catch(Fe){dn(u,u.return,Fe)}}if(w&4&&(k=u.stateNode,k!=null)){var M=u.memoizedProps,D=S!==null?S.memoizedProps:M,B=u.type,q=u.updateQueue;if(u.updateQueue=null,q!==null)try{B==="input"&&M.type==="radio"&&M.name!=null&&Mt(k,M),Is(B,D);var oe=Is(B,M);for(D=0;D<q.length;D+=2){var fe=q[D],me=q[D+1];fe==="style"?Js(k,me):fe==="dangerouslySetInnerHTML"?sc(k,me):fe==="children"?ae(k,me):I(k,fe,me,oe)}switch(B){case"input":Yr(k,M);break;case"textarea":vu(k,M);break;case"select":var he=k._wrapperState.wasMultiple;k._wrapperState.wasMultiple=!!M.multiple;var Me=M.value;Me!=null?Zs(k,!!M.multiple,Me,!1):he!==!!M.multiple&&(M.defaultValue!=null?Zs(k,!!M.multiple,M.defaultValue,!0):Zs(k,!!M.multiple,M.multiple?[]:"",!1))}k[Oh]=M}catch(Fe){dn(u,u.return,Fe)}}break;case 6:if(Li(h,u),So(u),w&4){if(u.stateNode===null)throw Error(t(162));k=u.stateNode,M=u.memoizedProps;try{k.nodeValue=M}catch(Fe){dn(u,u.return,Fe)}}break;case 3:if(Li(h,u),So(u),w&4&&S!==null&&S.memoizedState.isDehydrated)try{hc(h.containerInfo)}catch(Fe){dn(u,u.return,Fe)}break;case 4:Li(h,u),So(u);break;case 13:Li(h,u),So(u),k=u.child,k.flags&8192&&(M=k.memoizedState!==null,k.stateNode.isHidden=M,!M||k.alternate!==null&&k.alternate.memoizedState!==null||(sw=nn())),w&4&&EM(u);break;case 22:if(fe=S!==null&&S.memoizedState!==null,u.mode&1?(gr=(oe=gr)||fe,Li(h,u),gr=oe):Li(h,u),So(u),w&8192){if(oe=u.memoizedState!==null,(u.stateNode.isHidden=oe)&&!fe&&(u.mode&1)!==0)for(Oe=u,fe=u.child;fe!==null;){for(me=Oe=fe;Oe!==null;){switch(he=Oe,Me=he.child,he.tag){case 0:case 11:case 14:case 15:Hh(4,he,he.return);break;case 1:Xu(he,he.return);var je=he.stateNode;if(typeof je.componentWillUnmount=="function"){w=he,S=he.return;try{h=w,je.props=h.memoizedProps,je.state=h.memoizedState,je.componentWillUnmount()}catch(Fe){dn(w,S,Fe)}}break;case 5:Xu(he,he.return);break;case 22:if(he.memoizedState!==null){TM(me);continue}}Me!==null?(Me.return=he,Oe=Me):TM(me)}fe=fe.sibling}e:for(fe=null,me=u;;){if(me.tag===5){if(fe===null){fe=me;try{k=me.stateNode,oe?(M=k.style,typeof M.setProperty=="function"?M.setProperty("display","none","important"):M.display="none"):(B=me.stateNode,q=me.memoizedProps.style,D=q!=null&&q.hasOwnProperty("display")?q.display:null,B.style.display=At("display",D))}catch(Fe){dn(u,u.return,Fe)}}}else if(me.tag===6){if(fe===null)try{me.stateNode.nodeValue=oe?"":me.memoizedProps}catch(Fe){dn(u,u.return,Fe)}}else if((me.tag!==22&&me.tag!==23||me.memoizedState===null||me===u)&&me.child!==null){me.child.return=me,me=me.child;continue}if(me===u)break e;for(;me.sibling===null;){if(me.return===null||me.return===u)break e;fe===me&&(fe=null),me=me.return}fe===me&&(fe=null),me.sibling.return=me.return,me=me.sibling}}break;case 19:Li(h,u),So(u),w&4&&EM(u);break;case 21:break;default:Li(h,u),So(u)}}function So(u){var h=u.flags;if(h&2){try{e:{for(var S=u.return;S!==null;){if(bM(S)){var w=S;break e}S=S.return}throw Error(t(160))}switch(w.tag){case 5:var k=w.stateNode;w.flags&32&&(ae(k,""),w.flags&=-33);var M=CM(u);tw(u,M,k);break;case 3:case 4:var D=w.stateNode.containerInfo,B=CM(u);ew(u,B,D);break;default:throw Error(t(161))}}catch(q){dn(u,u.return,q)}u.flags&=-3}h&4096&&(u.flags&=-4097)}function zW(u,h,S){Oe=u,IM(u)}function IM(u,h,S){for(var w=(u.mode&1)!==0;Oe!==null;){var k=Oe,M=k.child;if(k.tag===22&&w){var D=k.memoizedState!==null||Bg;if(!D){var B=k.alternate,q=B!==null&&B.memoizedState!==null||gr;B=Bg;var oe=gr;if(Bg=D,(gr=q)&&!oe)for(Oe=k;Oe!==null;)D=Oe,q=D.child,D.tag===22&&D.memoizedState!==null?MM(k):q!==null?(q.return=D,Oe=q):MM(k);for(;M!==null;)Oe=M,IM(M),M=M.sibling;Oe=k,Bg=B,gr=oe}_M(u)}else(k.subtreeFlags&8772)!==0&&M!==null?(M.return=k,Oe=M):_M(u)}}function _M(u){for(;Oe!==null;){var h=Oe;if((h.flags&8772)!==0){var S=h.alternate;try{if((h.flags&8772)!==0)switch(h.tag){case 0:case 11:case 15:gr||Ug(5,h);break;case 1:var w=h.stateNode;if(h.flags&4&&!gr)if(S===null)w.componentDidMount();else{var k=h.elementType===h.type?S.memoizedProps:ji(h.type,S.memoizedProps);w.componentDidUpdate(k,S.memoizedState,w.__reactInternalSnapshotBeforeUpdate)}var M=h.updateQueue;M!==null&&T2(h,M,w);break;case 3:var D=h.updateQueue;if(D!==null){if(S=null,h.child!==null)switch(h.child.tag){case 5:S=h.child.stateNode;break;case 1:S=h.child.stateNode}T2(h,D,S)}break;case 5:var B=h.stateNode;if(S===null&&h.flags&4){S=B;var q=h.memoizedProps;switch(h.type){case"button":case"input":case"select":case"textarea":q.autoFocus&&S.focus();break;case"img":q.src&&(S.src=q.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(h.memoizedState===null){var oe=h.alternate;if(oe!==null){var fe=oe.memoizedState;if(fe!==null){var me=fe.dehydrated;me!==null&&hc(me)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(t(163))}gr||h.flags&512&&Qx(h)}catch(he){dn(h,h.return,he)}}if(h===u){Oe=null;break}if(S=h.sibling,S!==null){S.return=h.return,Oe=S;break}Oe=h.return}}function TM(u){for(;Oe!==null;){var h=Oe;if(h===u){Oe=null;break}var S=h.sibling;if(S!==null){S.return=h.return,Oe=S;break}Oe=h.return}}function MM(u){for(;Oe!==null;){var h=Oe;try{switch(h.tag){case 0:case 11:case 15:var S=h.return;try{Ug(4,h)}catch(q){dn(h,S,q)}break;case 1:var w=h.stateNode;if(typeof w.componentDidMount=="function"){var k=h.return;try{w.componentDidMount()}catch(q){dn(h,k,q)}}var M=h.return;try{Qx(h)}catch(q){dn(h,M,q)}break;case 5:var D=h.return;try{Qx(h)}catch(q){dn(h,D,q)}}}catch(q){dn(h,h.return,q)}if(h===u){Oe=null;break}var B=h.sibling;if(B!==null){B.return=h.return,Oe=B;break}Oe=h.return}}var $W=Math.ceil,Hg=_.ReactCurrentDispatcher,nw=_.ReactCurrentOwner,oi=_.ReactCurrentBatchConfig,bt=0,Nn=null,Cn=null,Yn=0,Rs=0,Zu=Qa(0),Tn=0,Kh=null,xc=0,Kg=0,rw=0,Wh=null,as=null,sw=0,Ju=1/0,oa=null,Wg=!1,iw=null,il=null,Vg=!1,ol=null,qg=0,Vh=0,ow=null,Gg=-1,Yg=0;function Dr(){return(bt&6)!==0?nn():Gg!==-1?Gg:Gg=nn()}function al(u){return(u.mode&1)===0?1:(bt&2)!==0&&Yn!==0?Yn&-Yn:CW.transition!==null?(Yg===0&&(Yg=og()),Yg):(u=vt,u!==0||(u=window.event,u=u===void 0?16:mn(u.type)),u)}function Fi(u,h,S,w){if(50<Vh)throw Vh=0,ow=null,Error(t(185));cc(u,S,w),((bt&2)===0||u!==Nn)&&(u===Nn&&((bt&2)===0&&(Kg|=S),Tn===4&&ll(u,Yn)),ls(u,w),S===1&&bt===0&&(h.mode&1)===0&&(Ju=nn()+500,Cg&&tl()))}function ls(u,h){var S=u.callbackNode;q0(u,h);var w=lc(u,u===Nn?Yn:0);if(w===0)S!==null&&lo(S),u.callbackNode=null,u.callbackPriority=0;else if(h=w&-w,u.callbackPriority!==h){if(S!=null&&lo(S),h===1)u.tag===0?bW(OM.bind(null,u)):y2(OM.bind(null,u)),SW(function(){(bt&6)===0&&tl()}),S=null;else{switch(Jo(w)){case 1:S=mh;break;case 4:S=ac;break;case 16:S=ku;break;case 536870912:S=Ti;break;default:S=ku}S=$M(S,AM.bind(null,u))}u.callbackPriority=h,u.callbackNode=S}}function AM(u,h){if(Gg=-1,Yg=0,(bt&6)!==0)throw Error(t(327));var S=u.callbackNode;if(Qu()&&u.callbackNode!==S)return null;var w=lc(u,u===Nn?Yn:0);if(w===0)return null;if((w&30)!==0||(w&u.expiredLanes)!==0||h)h=Xg(u,w);else{h=w;var k=bt;bt|=2;var M=DM();(Nn!==u||Yn!==h)&&(oa=null,Ju=nn()+500,bc(u,h));do try{HW();break}catch(B){RM(u,B)}while(!0);Px(),Hg.current=M,bt=k,Cn!==null?h=0:(Nn=null,Yn=0,h=Tn)}if(h!==0){if(h===2&&(k=yh(u),k!==0&&(w=k,h=aw(u,k))),h===1)throw S=Kh,bc(u,0),ll(u,w),ls(u,nn()),S;if(h===6)ll(u,w);else{if(k=u.current.alternate,(w&30)===0&&!BW(k)&&(h=Xg(u,w),h===2&&(M=yh(u),M!==0&&(w=M,h=aw(u,M))),h===1))throw S=Kh,bc(u,0),ll(u,w),ls(u,nn()),S;switch(u.finishedWork=k,u.finishedLanes=w,h){case 0:case 1:throw Error(t(345));case 2:Cc(u,as,oa);break;case 3:if(ll(u,w),(w&130023424)===w&&(h=sw+500-nn(),10<h)){if(lc(u,0)!==0)break;if(k=u.suspendedLanes,(k&w)!==w){Dr(),u.pingedLanes|=u.suspendedLanes&k;break}u.timeoutHandle=fx(Cc.bind(null,u,as,oa),h);break}Cc(u,as,oa);break;case 4:if(ll(u,w),(w&4194240)===w)break;for(h=u.eventTimes,k=-1;0<w;){var D=31-Ms(w);M=1<<D,D=h[D],D>k&&(k=D),w&=~M}if(w=k,w=nn()-w,w=(120>w?120:480>w?480:1080>w?1080:1920>w?1920:3e3>w?3e3:4320>w?4320:1960*$W(w/1960))-w,10<w){u.timeoutHandle=fx(Cc.bind(null,u,as,oa),w);break}Cc(u,as,oa);break;case 5:Cc(u,as,oa);break;default:throw Error(t(329))}}}return ls(u,nn()),u.callbackNode===S?AM.bind(null,u):null}function aw(u,h){var S=Wh;return u.current.memoizedState.isDehydrated&&(bc(u,h).flags|=256),u=Xg(u,h),u!==2&&(h=as,as=S,h!==null&&lw(h)),u}function lw(u){as===null?as=u:as.push.apply(as,u)}function BW(u){for(var h=u;;){if(h.flags&16384){var S=h.updateQueue;if(S!==null&&(S=S.stores,S!==null))for(var w=0;w<S.length;w++){var k=S[w],M=k.getSnapshot;k=k.value;try{if(!Ri(M(),k))return!1}catch{return!1}}}if(S=h.child,h.subtreeFlags&16384&&S!==null)S.return=h,h=S;else{if(h===u)break;for(;h.sibling===null;){if(h.return===null||h.return===u)return!0;h=h.return}h.sibling.return=h.return,h=h.sibling}}return!0}function ll(u,h){for(h&=~rw,h&=~Kg,u.suspendedLanes|=h,u.pingedLanes&=~h,u=u.expirationTimes;0<h;){var S=31-Ms(h),w=1<<S;u[S]=-1,h&=~w}}function OM(u){if((bt&6)!==0)throw Error(t(327));Qu();var h=lc(u,0);if((h&1)===0)return ls(u,nn()),null;var S=Xg(u,h);if(u.tag!==0&&S===2){var w=yh(u);w!==0&&(h=w,S=aw(u,w))}if(S===1)throw S=Kh,bc(u,0),ll(u,h),ls(u,nn()),S;if(S===6)throw Error(t(345));return u.finishedWork=u.current.alternate,u.finishedLanes=h,Cc(u,as,oa),ls(u,nn()),null}function cw(u,h){var S=bt;bt|=1;try{return u(h)}finally{bt=S,bt===0&&(Ju=nn()+500,Cg&&tl())}}function wc(u){ol!==null&&ol.tag===0&&(bt&6)===0&&Qu();var h=bt;bt|=1;var S=oi.transition,w=vt;try{if(oi.transition=null,vt=1,u)return u()}finally{vt=w,oi.transition=S,bt=h,(bt&6)===0&&tl()}}function uw(){Rs=Zu.current,Vt(Zu)}function bc(u,h){u.finishedWork=null,u.finishedLanes=0;var S=u.timeoutHandle;if(S!==-1&&(u.timeoutHandle=-1,yW(S)),Cn!==null)for(S=Cn.return;S!==null;){var w=S;switch(vx(w),w.tag){case 1:w=w.type.childContextTypes,w!=null&&wg();break;case 3:Gu(),Vt(rs),Vt(hr),Ox();break;case 5:Mx(w);break;case 4:Gu();break;case 13:Vt(rn);break;case 19:Vt(rn);break;case 10:Ex(w.type._context);break;case 22:case 23:uw()}S=S.return}if(Nn=u,Cn=u=cl(u.current,null),Yn=Rs=h,Tn=0,Kh=null,rw=Kg=xc=0,as=Wh=null,yc!==null){for(h=0;h<yc.length;h++)if(S=yc[h],w=S.interleaved,w!==null){S.interleaved=null;var k=w.next,M=S.pending;if(M!==null){var D=M.next;M.next=k,w.next=D}S.pending=w}yc=null}return u}function RM(u,h){do{var S=Cn;try{if(Px(),Rg.current=Lg,Dg){for(var w=sn.memoizedState;w!==null;){var k=w.queue;k!==null&&(k.pending=null),w=w.next}Dg=!1}if(vc=0,jn=_n=sn=null,Fh=!1,zh=0,nw.current=null,S===null||S.return===null){Tn=1,Kh=h,Cn=null;break}e:{var M=u,D=S.return,B=S,q=h;if(h=Yn,B.flags|=32768,q!==null&&typeof q=="object"&&typeof q.then=="function"){var oe=q,fe=B,me=fe.tag;if((fe.mode&1)===0&&(me===0||me===11||me===15)){var he=fe.alternate;he?(fe.updateQueue=he.updateQueue,fe.memoizedState=he.memoizedState,fe.lanes=he.lanes):(fe.updateQueue=null,fe.memoizedState=null)}var Me=sM(D);if(Me!==null){Me.flags&=-257,iM(Me,D,B,M,h),Me.mode&1&&rM(M,oe,h),h=Me,q=oe;var je=h.updateQueue;if(je===null){var Fe=new Set;Fe.add(q),h.updateQueue=Fe}else je.add(q);break e}else{if((h&1)===0){rM(M,oe,h),dw();break e}q=Error(t(426))}}else if(Qt&&B.mode&1){var Sn=sM(D);if(Sn!==null){(Sn.flags&65536)===0&&(Sn.flags|=256),iM(Sn,D,B,M,h),bx(Yu(q,B));break e}}M=q=Yu(q,B),Tn!==4&&(Tn=2),Wh===null?Wh=[M]:Wh.push(M),M=D;do{switch(M.tag){case 3:M.flags|=65536,h&=-h,M.lanes|=h;var Q=tM(M,q,h);_2(M,Q);break e;case 1:B=q;var Y=M.type,se=M.stateNode;if((M.flags&128)===0&&(typeof Y.getDerivedStateFromError=="function"||se!==null&&typeof se.componentDidCatch=="function"&&(il===null||!il.has(se)))){M.flags|=65536,h&=-h,M.lanes|=h;var xe=nM(M,B,h);_2(M,xe);break e}}M=M.return}while(M!==null)}NM(S)}catch($e){h=$e,Cn===S&&S!==null&&(Cn=S=S.return);continue}break}while(!0)}function DM(){var u=Hg.current;return Hg.current=Lg,u===null?Lg:u}function dw(){(Tn===0||Tn===3||Tn===2)&&(Tn=4),Nn===null||(xc&268435455)===0&&(Kg&268435455)===0||ll(Nn,Yn)}function Xg(u,h){var S=bt;bt|=2;var w=DM();(Nn!==u||Yn!==h)&&(oa=null,bc(u,h));do try{UW();break}catch(k){RM(u,k)}while(!0);if(Px(),bt=S,Hg.current=w,Cn!==null)throw Error(t(261));return Nn=null,Yn=0,Tn}function UW(){for(;Cn!==null;)jM(Cn)}function HW(){for(;Cn!==null&&!z0();)jM(Cn)}function jM(u){var h=zM(u.alternate,u,Rs);u.memoizedProps=u.pendingProps,h===null?NM(u):Cn=h,nw.current=null}function NM(u){var h=u;do{var S=h.alternate;if(u=h.return,(h.flags&32768)===0){if(S=jW(S,h,Rs),S!==null){Cn=S;return}}else{if(S=NW(S,h),S!==null){S.flags&=32767,Cn=S;return}if(u!==null)u.flags|=32768,u.subtreeFlags=0,u.deletions=null;else{Tn=6,Cn=null;return}}if(h=h.sibling,h!==null){Cn=h;return}Cn=h=u}while(h!==null);Tn===0&&(Tn=5)}function Cc(u,h,S){var w=vt,k=oi.transition;try{oi.transition=null,vt=1,KW(u,h,S,w)}finally{oi.transition=k,vt=w}return null}function KW(u,h,S,w){do Qu();while(ol!==null);if((bt&6)!==0)throw Error(t(327));S=u.finishedWork;var k=u.finishedLanes;if(S===null)return null;if(u.finishedWork=null,u.finishedLanes=0,S===u.current)throw Error(t(177));u.callbackNode=null,u.callbackPriority=0;var M=S.lanes|S.childLanes;if(G0(u,M),u===Nn&&(Cn=Nn=null,Yn=0),(S.subtreeFlags&2064)===0&&(S.flags&2064)===0||Vg||(Vg=!0,$M(ku,function(){return Qu(),null})),M=(S.flags&15990)!==0,(S.subtreeFlags&15990)!==0||M){M=oi.transition,oi.transition=null;var D=vt;vt=1;var B=bt;bt|=4,nw.current=null,FW(u,S),kM(S,u),uW(dx),Z=!!ux,dx=ux=null,u.current=S,zW(S),$0(),bt=B,vt=D,oi.transition=M}else u.current=S;if(Vg&&(Vg=!1,ol=u,qg=k),M=u.pendingLanes,M===0&&(il=null),H0(S.stateNode),ls(u,nn()),h!==null)for(w=u.onRecoverableError,S=0;S<h.length;S++)k=h[S],w(k.value,{componentStack:k.stack,digest:k.digest});if(Wg)throw Wg=!1,u=iw,iw=null,u;return(qg&1)!==0&&u.tag!==0&&Qu(),M=u.pendingLanes,(M&1)!==0?u===ow?Vh++:(Vh=0,ow=u):Vh=0,tl(),null}function Qu(){if(ol!==null){var u=Jo(qg),h=oi.transition,S=vt;try{if(oi.transition=null,vt=16>u?16:u,ol===null)var w=!1;else{if(u=ol,ol=null,qg=0,(bt&6)!==0)throw Error(t(331));var k=bt;for(bt|=4,Oe=u.current;Oe!==null;){var M=Oe,D=M.child;if((Oe.flags&16)!==0){var B=M.deletions;if(B!==null){for(var q=0;q<B.length;q++){var oe=B[q];for(Oe=oe;Oe!==null;){var fe=Oe;switch(fe.tag){case 0:case 11:case 15:Hh(8,fe,M)}var me=fe.child;if(me!==null)me.return=fe,Oe=me;else for(;Oe!==null;){fe=Oe;var he=fe.sibling,Me=fe.return;if(wM(fe),fe===oe){Oe=null;break}if(he!==null){he.return=Me,Oe=he;break}Oe=Me}}}var je=M.alternate;if(je!==null){var Fe=je.child;if(Fe!==null){je.child=null;do{var Sn=Fe.sibling;Fe.sibling=null,Fe=Sn}while(Fe!==null)}}Oe=M}}if((M.subtreeFlags&2064)!==0&&D!==null)D.return=M,Oe=D;else e:for(;Oe!==null;){if(M=Oe,(M.flags&2048)!==0)switch(M.tag){case 0:case 11:case 15:Hh(9,M,M.return)}var Q=M.sibling;if(Q!==null){Q.return=M.return,Oe=Q;break e}Oe=M.return}}var Y=u.current;for(Oe=Y;Oe!==null;){D=Oe;var se=D.child;if((D.subtreeFlags&2064)!==0&&se!==null)se.return=D,Oe=se;else e:for(D=Y;Oe!==null;){if(B=Oe,(B.flags&2048)!==0)try{switch(B.tag){case 0:case 11:case 15:Ug(9,B)}}catch($e){dn(B,B.return,$e)}if(B===D){Oe=null;break e}var xe=B.sibling;if(xe!==null){xe.return=B.return,Oe=xe;break e}Oe=B.return}}if(bt=k,tl(),ti&&typeof ti.onPostCommitFiberRoot=="function")try{ti.onPostCommitFiberRoot(Iu,u)}catch{}w=!0}return w}finally{vt=S,oi.transition=h}}return!1}function LM(u,h,S){h=Yu(S,h),h=tM(u,h,1),u=rl(u,h,1),h=Dr(),u!==null&&(cc(u,1,h),ls(u,h))}function dn(u,h,S){if(u.tag===3)LM(u,u,S);else for(;h!==null;){if(h.tag===3){LM(h,u,S);break}else if(h.tag===1){var w=h.stateNode;if(typeof h.type.getDerivedStateFromError=="function"||typeof w.componentDidCatch=="function"&&(il===null||!il.has(w))){u=Yu(S,u),u=nM(h,u,1),h=rl(h,u,1),u=Dr(),h!==null&&(cc(h,1,u),ls(h,u));break}}h=h.return}}function WW(u,h,S){var w=u.pingCache;w!==null&&w.delete(h),h=Dr(),u.pingedLanes|=u.suspendedLanes&S,Nn===u&&(Yn&S)===S&&(Tn===4||Tn===3&&(Yn&130023424)===Yn&&500>nn()-sw?bc(u,0):rw|=S),ls(u,h)}function FM(u,h){h===0&&((u.mode&1)===0?h=1:(h=co,co<<=1,(co&130023424)===0&&(co=4194304)));var S=Dr();u=ra(u,h),u!==null&&(cc(u,h,S),ls(u,S))}function VW(u){var h=u.memoizedState,S=0;h!==null&&(S=h.retryLane),FM(u,S)}function qW(u,h){var S=0;switch(u.tag){case 13:var w=u.stateNode,k=u.memoizedState;k!==null&&(S=k.retryLane);break;case 19:w=u.stateNode;break;default:throw Error(t(314))}w!==null&&w.delete(h),FM(u,S)}var zM;zM=function(u,h,S){if(u!==null)if(u.memoizedProps!==h.pendingProps||rs.current)is=!0;else{if((u.lanes&S)===0&&(h.flags&128)===0)return is=!1,DW(u,h,S);is=(u.flags&131072)!==0}else is=!1,Qt&&(h.flags&1048576)!==0&&S2(h,Eg,h.index);switch(h.lanes=0,h.tag){case 2:var w=h.type;$g(u,h),u=h.pendingProps;var k=Bu(h,hr.current);qu(h,S),k=jx(null,h,w,u,k,S);var M=Nx();return h.flags|=1,typeof k=="object"&&k!==null&&typeof k.render=="function"&&k.$$typeof===void 0?(h.tag=1,h.memoizedState=null,h.updateQueue=null,ss(w)?(M=!0,bg(h)):M=!1,h.memoizedState=k.state!==null&&k.state!==void 0?k.state:null,_x(h),k.updater=Fg,h.stateNode=k,k._reactInternals=h,Ux(h,w,u,S),h=Vx(null,h,w,!0,M,S)):(h.tag=0,Qt&&M&&Sx(h),Rr(null,h,k,S),h=h.child),h;case 16:w=h.elementType;e:{switch($g(u,h),u=h.pendingProps,k=w._init,w=k(w._payload),h.type=w,k=h.tag=YW(w),u=ji(w,u),k){case 0:h=Wx(null,h,w,u,S);break e;case 1:h=dM(null,h,w,u,S);break e;case 11:h=oM(null,h,w,u,S);break e;case 14:h=aM(null,h,w,ji(w.type,u),S);break e}throw Error(t(306,w,""))}return h;case 0:return w=h.type,k=h.pendingProps,k=h.elementType===w?k:ji(w,k),Wx(u,h,w,k,S);case 1:return w=h.type,k=h.pendingProps,k=h.elementType===w?k:ji(w,k),dM(u,h,w,k,S);case 3:e:{if(hM(h),u===null)throw Error(t(387));w=h.pendingProps,M=h.memoizedState,k=M.element,I2(u,h),Ag(h,w,null,S);var D=h.memoizedState;if(w=D.element,M.isDehydrated)if(M={element:w,isDehydrated:!1,cache:D.cache,pendingSuspenseBoundaries:D.pendingSuspenseBoundaries,transitions:D.transitions},h.updateQueue.baseState=M,h.memoizedState=M,h.flags&256){k=Yu(Error(t(423)),h),h=fM(u,h,w,S,k);break e}else if(w!==k){k=Yu(Error(t(424)),h),h=fM(u,h,w,S,k);break e}else for(Os=Ja(h.stateNode.containerInfo.firstChild),As=h,Qt=!0,Di=null,S=E2(h,null,w,S),h.child=S;S;)S.flags=S.flags&-3|4096,S=S.sibling;else{if(Ku(),w===k){h=ia(u,h,S);break e}Rr(u,h,w,S)}h=h.child}return h;case 5:return M2(h),u===null&&wx(h),w=h.type,k=h.pendingProps,M=u!==null?u.memoizedProps:null,D=k.children,hx(w,k)?D=null:M!==null&&hx(w,M)&&(h.flags|=32),uM(u,h),Rr(u,h,D,S),h.child;case 6:return u===null&&wx(h),null;case 13:return pM(u,h,S);case 4:return Tx(h,h.stateNode.containerInfo),w=h.pendingProps,u===null?h.child=Wu(h,null,w,S):Rr(u,h,w,S),h.child;case 11:return w=h.type,k=h.pendingProps,k=h.elementType===w?k:ji(w,k),oM(u,h,w,k,S);case 7:return Rr(u,h,h.pendingProps,S),h.child;case 8:return Rr(u,h,h.pendingProps.children,S),h.child;case 12:return Rr(u,h,h.pendingProps.children,S),h.child;case 10:e:{if(w=h.type._context,k=h.pendingProps,M=h.memoizedProps,D=k.value,Bt(_g,w._currentValue),w._currentValue=D,M!==null)if(Ri(M.value,D)){if(M.children===k.children&&!rs.current){h=ia(u,h,S);break e}}else for(M=h.child,M!==null&&(M.return=h);M!==null;){var B=M.dependencies;if(B!==null){D=M.child;for(var q=B.firstContext;q!==null;){if(q.context===w){if(M.tag===1){q=sa(-1,S&-S),q.tag=2;var oe=M.updateQueue;if(oe!==null){oe=oe.shared;var fe=oe.pending;fe===null?q.next=q:(q.next=fe.next,fe.next=q),oe.pending=q}}M.lanes|=S,q=M.alternate,q!==null&&(q.lanes|=S),kx(M.return,S,h),B.lanes|=S;break}q=q.next}}else if(M.tag===10)D=M.type===h.type?null:M.child;else if(M.tag===18){if(D=M.return,D===null)throw Error(t(341));D.lanes|=S,B=D.alternate,B!==null&&(B.lanes|=S),kx(D,S,h),D=M.sibling}else D=M.child;if(D!==null)D.return=M;else for(D=M;D!==null;){if(D===h){D=null;break}if(M=D.sibling,M!==null){M.return=D.return,D=M;break}D=D.return}M=D}Rr(u,h,k.children,S),h=h.child}return h;case 9:return k=h.type,w=h.pendingProps.children,qu(h,S),k=si(k),w=w(k),h.flags|=1,Rr(u,h,w,S),h.child;case 14:return w=h.type,k=ji(w,h.pendingProps),k=ji(w.type,k),aM(u,h,w,k,S);case 15:return lM(u,h,h.type,h.pendingProps,S);case 17:return w=h.type,k=h.pendingProps,k=h.elementType===w?k:ji(w,k),$g(u,h),h.tag=1,ss(w)?(u=!0,bg(h)):u=!1,qu(h,S),Q2(h,w,k),Ux(h,w,k,S),Vx(null,h,w,!0,u,S);case 19:return mM(u,h,S);case 22:return cM(u,h,S)}throw Error(t(156,h.tag))};function $M(u,h){return ig(u,h)}function GW(u,h,S,w){this.tag=u,this.key=S,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=h,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=w,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ai(u,h,S,w){return new GW(u,h,S,w)}function hw(u){return u=u.prototype,!(!u||!u.isReactComponent)}function YW(u){if(typeof u=="function")return hw(u)?1:0;if(u!=null){if(u=u.$$typeof,u===z)return 11;if(u===V)return 14}return 2}function cl(u,h){var S=u.alternate;return S===null?(S=ai(u.tag,h,u.key,u.mode),S.elementType=u.elementType,S.type=u.type,S.stateNode=u.stateNode,S.alternate=u,u.alternate=S):(S.pendingProps=h,S.type=u.type,S.flags=0,S.subtreeFlags=0,S.deletions=null),S.flags=u.flags&14680064,S.childLanes=u.childLanes,S.lanes=u.lanes,S.child=u.child,S.memoizedProps=u.memoizedProps,S.memoizedState=u.memoizedState,S.updateQueue=u.updateQueue,h=u.dependencies,S.dependencies=h===null?null:{lanes:h.lanes,firstContext:h.firstContext},S.sibling=u.sibling,S.index=u.index,S.ref=u.ref,S}function Zg(u,h,S,w,k,M){var D=2;if(w=u,typeof u=="function")hw(u)&&(D=1);else if(typeof u=="string")D=5;else e:switch(u){case R:return Pc(S.children,k,M,h);case j:D=8,k|=8;break;case K:return u=ai(12,S,h,k|2),u.elementType=K,u.lanes=M,u;case N:return u=ai(13,S,h,k),u.elementType=N,u.lanes=M,u;case L:return u=ai(19,S,h,k),u.elementType=L,u.lanes=M,u;case W:return Jg(S,k,M,h);default:if(typeof u=="object"&&u!==null)switch(u.$$typeof){case U:D=10;break e;case J:D=9;break e;case z:D=11;break e;case V:D=14;break e;case X:D=16,w=null;break e}throw Error(t(130,u==null?u:typeof u,""))}return h=ai(D,S,h,k),h.elementType=u,h.type=w,h.lanes=M,h}function Pc(u,h,S,w){return u=ai(7,u,w,h),u.lanes=S,u}function Jg(u,h,S,w){return u=ai(22,u,w,h),u.elementType=W,u.lanes=S,u.stateNode={isHidden:!1},u}function fw(u,h,S){return u=ai(6,u,null,h),u.lanes=S,u}function pw(u,h,S){return h=ai(4,u.children!==null?u.children:[],u.key,h),h.lanes=S,h.stateNode={containerInfo:u.containerInfo,pendingChildren:null,implementation:u.implementation},h}function XW(u,h,S,w,k){this.tag=h,this.containerInfo=u,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Mu(0),this.expirationTimes=Mu(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Mu(0),this.identifierPrefix=w,this.onRecoverableError=k,this.mutableSourceEagerHydrationData=null}function gw(u,h,S,w,k,M,D,B,q){return u=new XW(u,h,S,B,q),h===1?(h=1,M===!0&&(h|=8)):h=0,M=ai(3,null,null,h),u.current=M,M.stateNode=u,M.memoizedState={element:w,isDehydrated:S,cache:null,transitions:null,pendingSuspenseBoundaries:null},_x(M),u}function ZW(u,h,S){var w=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:A,key:w==null?null:""+w,children:u,containerInfo:h,implementation:S}}function BM(u){if(!u)return el;u=u._reactInternals;e:{if(Zo(u)!==u||u.tag!==1)throw Error(t(170));var h=u;do{switch(h.tag){case 3:h=h.stateNode.context;break e;case 1:if(ss(h.type)){h=h.stateNode.__reactInternalMemoizedMergedChildContext;break e}}h=h.return}while(h!==null);throw Error(t(171))}if(u.tag===1){var S=u.type;if(ss(S))return g2(u,S,h)}return h}function UM(u,h,S,w,k,M,D,B,q){return u=gw(S,w,!0,u,k,M,D,B,q),u.context=BM(null),S=u.current,w=Dr(),k=al(S),M=sa(w,k),M.callback=h??null,rl(S,M,k),u.current.lanes=k,cc(u,k,w),ls(u,w),u}function Qg(u,h,S,w){var k=h.current,M=Dr(),D=al(k);return S=BM(S),h.context===null?h.context=S:h.pendingContext=S,h=sa(M,D),h.payload={element:u},w=w===void 0?null:w,w!==null&&(h.callback=w),u=rl(k,h,D),u!==null&&(Fi(u,k,D,M),Mg(u,k,D)),D}function em(u){if(u=u.current,!u.child)return null;switch(u.child.tag){case 5:return u.child.stateNode;default:return u.child.stateNode}}function HM(u,h){if(u=u.memoizedState,u!==null&&u.dehydrated!==null){var S=u.retryLane;u.retryLane=S!==0&&S<h?S:h}}function mw(u,h){HM(u,h),(u=u.alternate)&&HM(u,h)}function JW(){return null}var KM=typeof reportError=="function"?reportError:function(u){console.error(u)};function yw(u){this._internalRoot=u}tm.prototype.render=yw.prototype.render=function(u){var h=this._internalRoot;if(h===null)throw Error(t(409));Qg(u,h,null,null)},tm.prototype.unmount=yw.prototype.unmount=function(){var u=this._internalRoot;if(u!==null){this._internalRoot=null;var h=u.containerInfo;wc(function(){Qg(null,u,null,null)}),h[Qo]=null}};function tm(u){this._internalRoot=u}tm.prototype.unstable_scheduleHydration=function(u){if(u){var h=lg();u={blockedOn:null,target:u,priority:h};for(var S=0;S<fo.length&&h!==0&&h<fo[S].priority;S++);fo.splice(S,0,u),S===0&&wh(u)}};function Sw(u){return!(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11)}function nm(u){return!(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11&&(u.nodeType!==8||u.nodeValue!==" react-mount-point-unstable "))}function WM(){}function QW(u,h,S,w,k){if(k){if(typeof w=="function"){var M=w;w=function(){var oe=em(D);M.call(oe)}}var D=UM(h,w,u,0,null,!1,!1,"",WM);return u._reactRootContainer=D,u[Qo]=D.current,Mh(u.nodeType===8?u.parentNode:u),wc(),D}for(;k=u.lastChild;)u.removeChild(k);if(typeof w=="function"){var B=w;w=function(){var oe=em(q);B.call(oe)}}var q=gw(u,0,!1,null,null,!1,!1,"",WM);return u._reactRootContainer=q,u[Qo]=q.current,Mh(u.nodeType===8?u.parentNode:u),wc(function(){Qg(h,q,S,w)}),q}function rm(u,h,S,w,k){var M=S._reactRootContainer;if(M){var D=M;if(typeof k=="function"){var B=k;k=function(){var q=em(D);B.call(q)}}Qg(h,D,u,k)}else D=QW(S,h,u,k,w);return em(D)}ag=function(u){switch(u.tag){case 3:var h=u.stateNode;if(h.current.memoizedState.isDehydrated){var S=qa(h.pendingLanes);S!==0&&(Au(h,S|1),ls(h,nn()),(bt&6)===0&&(Ju=nn()+500,tl()))}break;case 13:wc(function(){var w=ra(u,1);if(w!==null){var k=Dr();Fi(w,u,1,k)}}),mw(u,1)}},Sh=function(u){if(u.tag===13){var h=ra(u,134217728);if(h!==null){var S=Dr();Fi(h,u,134217728,S)}mw(u,134217728)}},Mi=function(u){if(u.tag===13){var h=al(u),S=ra(u,h);if(S!==null){var w=Dr();Fi(S,u,h,w)}mw(u,h)}},lg=function(){return vt},cg=function(u,h){var S=vt;try{return vt=u,h()}finally{vt=S}},Ts=function(u,h,S){switch(h){case"input":if(Yr(u,S),h=S.name,S.type==="radio"&&h!=null){for(S=u;S.parentNode;)S=S.parentNode;for(S=S.querySelectorAll("input[name="+JSON.stringify(""+h)+'][type="radio"]'),h=0;h<S.length;h++){var w=S[h];if(w!==u&&w.form===u.form){var k=xg(w);if(!k)throw Error(t(90));cn(w),Yr(w,k)}}}break;case"textarea":vu(u,S);break;case"select":h=S.value,h!=null&&Zs(u,!!S.multiple,h,!1)}},Pu=cw,Eu=wc;var eV={usingClientEntryPoint:!1,Events:[Rh,zu,xg,Ka,Cu,cw]},qh={findFiberByHostInstance:fc,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},tV={bundleType:qh.bundleType,version:qh.version,rendererPackageName:qh.rendererPackageName,rendererConfig:qh.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:_.ReactCurrentDispatcher,findHostInstanceByFiber:function(u){return u=rg(u),u===null?null:u.stateNode},findFiberByHostInstance:qh.findFiberByHostInstance||JW,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 sm=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!sm.isDisabled&&sm.supportsFiber)try{Iu=sm.inject(tV),ti=sm}catch{}}return cs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=eV,cs.createPortal=function(u,h){var S=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Sw(h))throw Error(t(200));return ZW(u,h,null,S)},cs.createRoot=function(u,h){if(!Sw(u))throw Error(t(299));var S=!1,w="",k=KM;return h!=null&&(h.unstable_strictMode===!0&&(S=!0),h.identifierPrefix!==void 0&&(w=h.identifierPrefix),h.onRecoverableError!==void 0&&(k=h.onRecoverableError)),h=gw(u,1,!1,null,null,S,!1,w,k),u[Qo]=h.current,Mh(u.nodeType===8?u.parentNode:u),new yw(h)},cs.findDOMNode=function(u){if(u==null)return null;if(u.nodeType===1)return u;var h=u._reactInternals;if(h===void 0)throw typeof u.render=="function"?Error(t(188)):(u=Object.keys(u).join(","),Error(t(268,u)));return u=rg(h),u=u===null?null:u.stateNode,u},cs.flushSync=function(u){return wc(u)},cs.hydrate=function(u,h,S){if(!nm(h))throw Error(t(200));return rm(null,u,h,!0,S)},cs.hydrateRoot=function(u,h,S){if(!Sw(u))throw Error(t(405));var w=S!=null&&S.hydratedSources||null,k=!1,M="",D=KM;if(S!=null&&(S.unstable_strictMode===!0&&(k=!0),S.identifierPrefix!==void 0&&(M=S.identifierPrefix),S.onRecoverableError!==void 0&&(D=S.onRecoverableError)),h=UM(h,null,u,1,S??null,k,!1,M,D),u[Qo]=h.current,Mh(u),w)for(u=0;u<w.length;u++)S=w[u],k=S._getVersion,k=k(S._source),h.mutableSourceEagerHydrationData==null?h.mutableSourceEagerHydrationData=[S,k]:h.mutableSourceEagerHydrationData.push(S,k);return new tm(h)},cs.render=function(u,h,S){if(!nm(h))throw Error(t(200));return rm(null,u,h,!1,S)},cs.unmountComponentAtNode=function(u){if(!nm(u))throw Error(t(40));return u._reactRootContainer?(wc(function(){rm(null,null,u,!1,function(){u._reactRootContainer=null,u[Qo]=null})}),!0):!1},cs.unstable_batchedUpdates=cw,cs.unstable_renderSubtreeIntoContainer=function(u,h,S,w){if(!nm(S))throw Error(t(200));if(u==null||u._reactInternals===void 0)throw Error(t(38));return rm(u,h,S,!1,w)},cs.version="18.3.1-next-f1338f8080-20240426",cs}var QM;function HL(){if(QM)return ww.exports;QM=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(),ww.exports=hV(),ww.exports}var eA;function fV(){if(eA)return im;eA=1;var n=HL();return im.createRoot=n.createRoot,im.hydrateRoot=n.hydrateRoot,im}var KL=fV();const pV=ja(KL);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 gV(n){const e=we("./icons/icon/0_merged.svg",n);return{fonts:{tldraw_mono_bold:we("./fonts/IBMPlexMono-Bold.woff2",n),tldraw_mono_italic_bold:we("./fonts/IBMPlexMono-BoldItalic.woff2",n),tldraw_mono:we("./fonts/IBMPlexMono-Medium.woff2",n),tldraw_mono_italic:we("./fonts/IBMPlexMono-MediumItalic.woff2",n),tldraw_sans_bold:we("./fonts/IBMPlexSans-Bold.woff2",n),tldraw_sans_italic_bold:we("./fonts/IBMPlexSans-BoldItalic.woff2",n),tldraw_sans:we("./fonts/IBMPlexSans-Medium.woff2",n),tldraw_sans_italic:we("./fonts/IBMPlexSans-MediumItalic.woff2",n),tldraw_serif_bold:we("./fonts/IBMPlexSerif-Bold.woff2",n),tldraw_serif_italic_bold:we("./fonts/IBMPlexSerif-BoldItalic.woff2",n),tldraw_serif:we("./fonts/IBMPlexSerif-Medium.woff2",n),tldraw_serif_italic:we("./fonts/IBMPlexSerif-MediumItalic.woff2",n),tldraw_draw_bold:we("./fonts/Shantell_Sans-Informal_Bold.woff2",n),tldraw_draw_italic_bold:we("./fonts/Shantell_Sans-Informal_Bold_Italic.woff2",n),tldraw_draw:we("./fonts/Shantell_Sans-Informal_Regular.woff2",n),tldraw_draw_italic:we("./fonts/Shantell_Sans-Informal_Regular_Italic.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",bold:e+"#bold","bring-forward":e+"#bring-forward","bring-to-front":e+"#bring-to-front",broken:e+"#broken",bulletList:e+"#bulletList","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",code:e+"#code",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",heading:e+"#heading",highlight:e+"#highlight","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",italic:e+"#italic",leading:e+"#leading",link:e+"#link",list:e+"#list",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",strike:e+"#strike","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",underline:e+"#underline",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 Pw="__TLDRAW_LIBRARY_VERSIONS__";function mV(){if(globalThis[Pw])return globalThis[Pw];const n={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,Pw,{value:n,writable:!1,configurable:!1,enumerable:!1}),n}function Wl(n,e,t){if(!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=mV();if(r.versions.push({name:n,version:e,modules:t}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,tA(r)},100)}catch{tA(r)}}function tA(n){if(!n.versions.length||n.didWarn)return;const e=n.versions.sort((a,l)=>nA(a.version,l.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),Ew(s,a.name,new Set).add(a.version);continue}a.version===t?r.add(a.name):(r.delete(a.name),Ew(s,a.name,new Set).add(a.version))}if(s.size>0){const a=[`${aa("[tldraw]",["bold","bgRed","textWhite"])} ${aa("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 ${aa(`v${t}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${aa(l,["bold"])}`),"","The following libraries are not on the latest version, or have multiple versions installed:",...Array.from(s,([l,c])=>{const d=Array.from(c).sort(nA).map(f=>aa(`v${f}`,f===t?["textGreen"]:["textRed"]));return` • ❌ ${aa(l,["bold"])} (${d.join(", ")})`})];console.log(a.join(`
41
+ `)),n.didWarn=!0;return}const i=new Map;for(const a of e)Ew(i,a.name,{version:a.version,modules:[]}).modules.push(a.modules);const o=new Map;for(const[a,l]of i)l.modules.length>1&&o.set(a,l);if(o.size>0){const a=[`${aa("[tldraw]",["bold","bgRed","textWhite"])} ${aa("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(o,([l,c])=>{const d=c.modules.map((f,p)=>f==="esm"?` ${p+1}. ES Modules`:` ${p+1}. CommonJS`).join(`
42
+ `);return` • ❌ ${aa(l,["bold"])} v${c.version}:
43
+ ${d}`}),"","You should configure your bundler to only import one version of each library."];console.log(a.join(`
44
+ `)),n.didWarn=!0;return}}function nA(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 yV={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function aa(n,e=[]){return`\x1B[${e.map(t=>yV[t]).join(";")}m${n}\x1B[m`}function Ew(n,e,t){return n.has(e)?n.get(e):(n.set(e,t),t)}var kw,rA;function SV(){if(rA)return kw;rA=1;var n="Expected a function",e=NaN,t="[object Symbol]",r=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,o=/^0o[0-7]+$/i,a=parseInt,l=typeof Ss=="object"&&Ss&&Ss.Object===Object&&Ss,c=typeof self=="object"&&self&&self.Object===Object&&self,d=l||c||Function("return this")(),f=Object.prototype,p=f.toString,m=Math.max,y=Math.min,v=function(){return d.Date.now()};function x(A,R,j){var K,U,J,z,N,L,V=0,X=!1,W=!1,$=!0;if(typeof A!="function")throw new TypeError(n);R=T(R)||0,C(j)&&(X=!!j.leading,W="maxWait"in j,J=W?m(T(j.maxWait)||0,R):J,$="trailing"in j?!!j.trailing:$);function G(Ce){var _e=K,Ve=U;return K=U=void 0,V=Ce,z=A.apply(Ve,_e),z}function re(Ce){return V=Ce,N=setTimeout(ge,R),X?G(Ce):z}function H(Ce){var _e=Ce-L,Ve=Ce-V,it=R-_e;return W?y(it,J-Ve):it}function ne(Ce){var _e=Ce-L,Ve=Ce-V;return L===void 0||_e>=R||_e<0||W&&Ve>=J}function ge(){var Ce=v();if(ne(Ce))return Pe(Ce);N=setTimeout(ge,H(Ce))}function Pe(Ce){return N=void 0,$&&K?G(Ce):(K=U=void 0,z)}function ce(){N!==void 0&&clearTimeout(N),V=0,K=L=U=N=void 0}function Be(){return N===void 0?z:Pe(v())}function Re(){var Ce=v(),_e=ne(Ce);if(K=arguments,U=this,L=Ce,_e){if(N===void 0)return re(L);if(W)return N=setTimeout(ge,R),G(L)}return N===void 0&&(N=setTimeout(ge,R)),z}return Re.cancel=ce,Re.flush=Be,Re}function b(A,R,j){var K=!0,U=!0;if(typeof A!="function")throw new TypeError(n);return C(j)&&(K="leading"in j?!!j.leading:K,U="trailing"in j?!!j.trailing:U),x(A,R,{leading:K,maxWait:R,trailing:U})}function C(A){var R=typeof A;return!!A&&(R=="object"||R=="function")}function I(A){return!!A&&typeof A=="object"}function _(A){return typeof A=="symbol"||I(A)&&p.call(A)==t}function T(A){if(typeof A=="number")return A;if(_(A))return e;if(C(A)){var R=typeof A.valueOf=="function"?A.valueOf():A;A=C(R)?R+"":R}if(typeof A!="string")return A===0?A:+A;A=A.replace(r,"");var j=i.test(A);return j||o.test(A)?a(A.slice(2),j?2:8):s.test(A)?e:+A}return kw=b,kw}var vV=SV();const WL=ja(vV);var Iw,sA;function xV(){if(sA)return Iw;sA=1;var n=200,e="__lodash_hash_undefined__",t=1/0,r="[object Function]",s="[object GeneratorFunction]",i=/[\\^$.*+?()[\]{}|]/g,o=/^\[object .+?Constructor\]$/,a=typeof Ss=="object"&&Ss&&Ss.Object===Object&&Ss,l=typeof self=="object"&&self&&self.Object===Object&&self,c=a||l||Function("return this")();function d(ae,be){var Xe=ae?ae.length:0;return!!Xe&&p(ae,be,0)>-1}function f(ae,be,Xe,At){for(var Js=ae.length,Qr=Xe+-1;++Qr<Js;)if(be(ae[Qr],Qr,ae))return Qr;return-1}function p(ae,be,Xe){if(be!==be)return f(ae,m,Xe);for(var At=Xe-1,Js=ae.length;++At<Js;)if(ae[At]===be)return At;return-1}function m(ae){return ae!==ae}function y(ae,be){return ae.has(be)}function v(ae,be){return ae==null?void 0:ae[be]}function x(ae){var be=!1;if(ae!=null&&typeof ae.toString!="function")try{be=!!(ae+"")}catch{}return be}function b(ae){var be=-1,Xe=Array(ae.size);return ae.forEach(function(At){Xe[++be]=At}),Xe}var C=Array.prototype,I=Function.prototype,_=Object.prototype,T=c["__core-js_shared__"],A=function(){var ae=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||"");return ae?"Symbol(src)_1."+ae:""}(),R=I.toString,j=_.hasOwnProperty,K=_.toString,U=RegExp("^"+R.call(j).replace(i,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J=C.splice,z=Zs(c,"Map"),N=Zs(c,"Set"),L=Zs(Object,"create");function V(ae){var be=-1,Xe=ae?ae.length:0;for(this.clear();++be<Xe;){var At=ae[be];this.set(At[0],At[1])}}function X(){this.__data__=L?L(null):{}}function W(ae){return this.has(ae)&&delete this.__data__[ae]}function $(ae){var be=this.__data__;if(L){var Xe=be[ae];return Xe===e?void 0:Xe}return j.call(be,ae)?be[ae]:void 0}function G(ae){var be=this.__data__;return L?be[ae]!==void 0:j.call(be,ae)}function re(ae,be){var Xe=this.__data__;return Xe[ae]=L&&be===void 0?e:be,this}V.prototype.clear=X,V.prototype.delete=W,V.prototype.get=$,V.prototype.has=G,V.prototype.set=re;function H(ae){var be=-1,Xe=ae?ae.length:0;for(this.clear();++be<Xe;){var At=ae[be];this.set(At[0],At[1])}}function ne(){this.__data__=[]}function ge(ae){var be=this.__data__,Xe=Mt(be,ae);if(Xe<0)return!1;var At=be.length-1;return Xe==At?be.pop():J.call(be,Xe,1),!0}function Pe(ae){var be=this.__data__,Xe=Mt(be,ae);return Xe<0?void 0:be[Xe][1]}function ce(ae){return Mt(this.__data__,ae)>-1}function Be(ae,be){var Xe=this.__data__,At=Mt(Xe,ae);return At<0?Xe.push([ae,be]):Xe[At][1]=be,this}H.prototype.clear=ne,H.prototype.delete=ge,H.prototype.get=Pe,H.prototype.has=ce,H.prototype.set=Be;function Re(ae){var be=-1,Xe=ae?ae.length:0;for(this.clear();++be<Xe;){var At=ae[be];this.set(At[0],At[1])}}function Ce(){this.__data__={hash:new V,map:new(z||H),string:new V}}function _e(ae){return Jr(this,ae).delete(ae)}function Ve(ae){return Jr(this,ae).get(ae)}function it(ae){return Jr(this,ae).has(ae)}function cn(ae,be){return Jr(this,ae).set(ae,be),this}Re.prototype.clear=Ce,Re.prototype.delete=_e,Re.prototype.get=Ve,Re.prototype.has=it,Re.prototype.set=cn;function It(ae){var be=-1,Xe=ae?ae.length:0;for(this.__data__=new Re;++be<Xe;)this.add(ae[be])}function Jt(ae){return this.__data__.set(ae,e),this}function jt(ae){return this.__data__.has(ae)}It.prototype.add=It.prototype.push=Jt,It.prototype.has=jt;function Mt(ae,be){for(var Xe=ae.length;Xe--;)if(wu(ae[Xe][0],be))return Xe;return-1}function Yr(ae){if(!Ii(ae)||Su(ae))return!1;var be=ao(ae)||x(ae)?U:o;return be.test(vu(ae))}function Xr(ae,be,Xe){var At=-1,Js=d,Qr=ae.length,Yo=!0,Is=[],_s=Is;if(Qr>=n){var es=Zr(ae);if(es)return b(es);Yo=!1,Js=y,_s=new It}else _s=Is;e:for(;++At<Qr;){var Ts=ae[At],ts=Ts;if(Ts=Ts!==0?Ts:0,Yo&&ts===ts){for(var _i=_s.length;_i--;)if(_s[_i]===ts)continue e;Is.push(Ts)}else Js(_s,ts,Xe)||(_s!==Is&&_s.push(ts),Is.push(Ts))}return Is}var Zr=N&&1/b(new N([,-0]))[1]==t?function(ae){return new N(ae)}:sc;function Jr(ae,be){var Xe=ae.__data__;return rc(be)?Xe[typeof be=="string"?"string":"hash"]:Xe.map}function Zs(ae,be){var Xe=v(ae,be);return Yr(Xe)?Xe:void 0}function rc(ae){var be=typeof ae;return be=="string"||be=="number"||be=="symbol"||be=="boolean"?ae!=="__proto__":ae===null}function Su(ae){return!!A&&A in ae}function vu(ae){if(ae!=null){try{return R.call(ae)}catch{}try{return ae+""}catch{}}return""}function xu(ae){return ae&&ae.length?Xr(ae):[]}function wu(ae,be){return ae===be||ae!==ae&&be!==be}function ao(ae){var be=Ii(ae)?K.call(ae):"";return be==r||be==s}function Ii(ae){var be=typeof ae;return!!ae&&(be=="object"||be=="function")}function sc(){}return Iw=xu,Iw}var wV=xV();const bV=ja(wV);function VL(n){const e=(...t)=>{try{return n(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Vf=()=>{},jr={ok(n){return{ok:!0,value:n}},err(n){return{ok:!1,error:n}}};function En(n,e){const t=e&&n&&typeof n=="object"&&e in n?n[e]:n;throw new Error(`Unknown switch case ${t}`)}const nt=VL((n,e)=>{if(!n)throw new Error(e||"Assertion Error")}),Nr=VL((n,e)=>{if(n==null)throw new Error(e??"value must be defined");return n});function fk(){let n,e;const t=new Promise((r,s)=>{n=r,e=s});return Object.assign(t,{resolve:n,reject:e})}function wP(n){return new Promise(e=>setTimeout(e,n))}const hf={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},CV=hf.Good;class qL{constructor(){O(this,"startTime",0);O(this,"name","");O(this,"frames",0);O(this,"started",!1);O(this,"frame",null);O(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?hf.Good:t>30?hf.Mid:hf.Poor,s=r===hf.Mid?"black":"white",i=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${i} %c${t}%c fps`,`color: white; background: ${CV};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 pk(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 st(n){return n.filter(e=>e!=null)}function Jn(n){return n[n.length-1]}function PV(n,e){let t,r=1/0;for(const s of n){const i=e(s);i<r&&(t=s,r=i)}return t}function EV(n,e){let t,r=-1/0;for(const s of n){const i=e(s);i>r&&(t=s,r=i)}return t}function jy(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 _w(n,e,t){const r=new Set(e.map(i=>i[n])),s=[];for(const i of t)r.has(i[n])||s.push(i);for(const i of e)s.push(i);return s}/*!
45
+ * MIT License: https://github.com/NoHomey/bind-decorator/blob/master/License
46
+ * Copyright (c) 2016 Ivo Stratev
47
+ */function vs(...n){if(n.length===2){const[e,t]=n;t.addInitializer(function(){nt(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const s=e.bind(this),i=Reflect.defineProperty(this,t.name,{value:s,writable:!0,configurable:!0});nt(i,"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 Na{constructor(){O(this,"items",new WeakMap)}get(e,t){return this.items.has(e)||this.items.set(e,t(e)),this.items.get(e)}}function cv(n,e){let t;const r=(...s)=>(t||(t={},t.promise=new Promise((i,o)=>{t.resolve=i,t.reject=o})),clearTimeout(t.timeout),t.latestArgs=s,t.timeout=setTimeout(()=>{const i=t;t=void 0;try{i.resolve(n(...i.latestArgs))}catch(o){i.reject(o)}},e),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const iA=new WeakMap;function gk(n,e){if(typeof n!="object"||n===null)return;let t=iA.get(n);t||(t={tags:{},extras:{}},iA.set(n,t)),e.tags&&(t.tags={...t.tags,...e.tags}),e.extras&&(t.extras={...t.extras,...e.extras})}async function Vi(n,e){return window.fetch(n,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const qf=(n,e)=>{const t=new window.Image(n,e);return t.referrerPolicy="strict-origin-when-cross-origin",t};class zr{static async dataUrlToArrayBuffer(e){return Vi(e).then(function(t){return t.arrayBuffer()})}static async urlToArrayBuffer(e){return await(await Vi(e)).arrayBuffer()}static async urlToBlob(e){return await(await Vi(e)).blob()}static async urlToDataUrl(e){if(e.startsWith("data:"))return e;const t=await zr.urlToBlob(e);return await zr.blobToDataUrl(t)}static async blobToDataUrl(e){return await new Promise((t,r)=>{if(e){const s=new FileReader;s.onload=()=>t(s.result),s.onerror=i=>r(i),s.onabort=i=>r(i),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=i=>r(i),s.onabort=i=>r(i),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 mk(n){let e=0;for(let t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e|=0;return e+""}function GL(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+""}/*!
48
+ * MIT License: https://github.com/ai/nanoid/blob/main/LICENSE
49
+ * Modified code originally from <https://github.com/ai/nanoid>
50
+ * Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
51
+ *
52
+ * `nanoid` is currently only distributed as an ES module. Some tools (jest, playwright) don't
53
+ * properly support ESM-only code yet, and tldraw itself is distributed as both an ES module and a
54
+ * CommonJS module. By including nanoid here, we can make sure it works well in every environment
55
+ * where tldraw is used. We can also remove some unused features like custom alphabets.
56
+ */const oA=globalThis.crypto,kV="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",IV=128;let Ic,yd;function _V(n){!Ic||Ic.length<n?(Ic=new Uint8Array(n*IV),oA.getRandomValues(Ic),yd=0):yd+n>Ic.length&&(oA.getRandomValues(Ic),yd=0),yd+=n}function TV(n=21){_V(n-=0);let e="";for(let t=yd-n;t<yd;t++)e+=kV[Ic[t]&63];return e}let MV=TV;function _t(n){return MV(n)}/*!
57
+ * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
58
+ * Copyright (c) Philip van Heemstra
59
+ */function AV(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(i,o,a,l,c=1024){if(!o)return-1;o=new RegExp(o,"g");const d=o.source.length,f=new TextDecoder,p=i.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;i=i.subarray(a,l);let m=-1,y=0,v=0,x="";e:for(;y<i.length;){const b=y+c,C=i.subarray(y,b),I=f.decode(C,{stream:!0}),_=x+I;let T,A=-1;for(;(T=o.exec(_))!==null;){A=T.index-x.length,m=v+A;break e}y=b,v+=I.length;const R=A>-1?A+d:I.length-d;x=I.slice(R)}return m>=0&&(m+=a>=0?a:p+a),m}const s=r(e,"IDAT",12);return s>=12?r(e,"acTL",8,s)>=8:!1}const OV=n=>new Uint8Array(n)[3]===44;/*!
60
+ * MIT License
61
+ * Modified code originally from <https://github.com/qzb/is-animated>
62
+ * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
63
+ */function aA(n,e){let t=0;for(;n[e+t];)t+=n[e+t]+1;return t+1}function RV(n){return new TextDecoder("ascii").decode(n.slice(0,3))==="GIF"}function DV(n){const e=new Uint8Array(n);let t,r,s=0,i=0;if(!RV(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;i<2&&s<e.length;)switch(e[s]){case 44:i+=1,t=e[s+9]&128,r=e[s+9]&7,s+=10,s+=t?3*Math.pow(2,r+1):0,s+=aA(e,s+1)+1;break;case 33:s+=2,s+=aA(e,s);break;case 59:s=e.length;break;default:s=e.length;break}return i>1}/*!
64
+ * MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
65
+ * Copyright: 2014 Alex Gorbatchev
66
+ * Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
67
+ */let bP=[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"&&(bP=new Int32Array(bP));const jV=(n,e)=>{let t=-1;for(let r=0;r<n.length;r++)t=bP[(t^n[r])&255]^t>>>8;return t^-1},lA=4,cA=4;class Io{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(!Io.isPng(e,t))throw new Error("Not a PNG");for(t+=8;t<=e.buffer.byteLength;){const s=t,i=e.getInt32(t);t+=4;const o=Io.getChunkType(e,t);if(o==="IDAT"&&r[o]){t+=i+lA+cA;continue}if(o==="IEND")break;r[o]={start:s,dataOffset:t+4,size:i},t+=i+lA+cA}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 Io.readChunks(e)[t]}static setPhysChunk(e,t=1,r){let s=46,i=0;const o=Io.findChunk(e,"pHYs");o&&(s=o.start,i=o.size);const a=Io.findChunk(e,"IDAT");a&&(s=a.start,i=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const d=2835.5;c.setInt32(8,d*t),c.setInt32(12,d*t),c.setInt8(16,1);const f=new Uint8Array(l.slice(4,17));c.setInt32(17,jV(f));const p=e.buffer.slice(0,s),m=e.buffer.slice(s+i);return new Blob([p,l,m],r)}}/*!
68
+ * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
69
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
70
+ */function NV(n){return!n||n.length<12?!1:n[8]===87&&n[9]===69&&n[10]===66&&n[11]===80}function LV(n){const e=new Uint8Array(n);return!NV(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const YL=Object.freeze(["image/svg+xml"]),XL=Object.freeze(["image/jpeg","image/png","image/webp"]),ZL=Object.freeze(["image/gif","image/apng","image/avif"]),wp=Object.freeze([...XL,...YL,...ZL]),uv=Object.freeze(["video/mp4","video/webm","video/quicktime"]),FV=[...wp,...uv].join(",");class Ls{static loadVideo(e){return new Promise((t,r)=>{const s=document.createElement("video");s.onloadeddata=()=>t(s),s.onerror=i=>{console.error(i),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=e})}static async getVideoFrameAsDataUrl(e,t=0){const r=fk();let s=!1;const i=()=>{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 l=a.getContext("2d");if(!l)throw new Error("Could not get 2d context");l.drawImage(e,0,0),r.resolve(a.toDataURL())}},o=a=>{console.error(a),r.reject(new Error("Could not get video frame"))};e.addEventListener("loadedmetadata",i),e.addEventListener("loadeddata",i),e.addEventListener("canplay",i),e.addEventListener("seeked",i),e.addEventListener("error",o),e.addEventListener("stalled",o),i();try{return await r}finally{e.removeEventListener("loadedmetadata",i),e.removeEventListener("loadeddata",i),e.removeEventListener("canplay",i),e.removeEventListener("seeked",i),e.removeEventListener("error",o),e.removeEventListener("stalled",o)}}static loadImage(e){return new Promise((t,r)=>{const s=qf();s.onload=()=>t(s),s.onerror=i=>{console.error(i),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 Ls.usingObjectURL(e,async t=>{const r=await Ls.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const t=await Ls.usingObjectURL(e,Ls.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(Io.isPng(r,0)){const s=Io.findChunk(r,"pHYs");if(s){const i=Io.parsePhys(r,s.dataOffset);if(i.unit===0&&i.ppux===i.ppuy){const a=Math.max(i.ppux/2834.645669291339,1);return{w:Math.round(t.naturalWidth/a),h:Math.round(t.naturalHeight/a)}}}}}}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"?DV(await e.arrayBuffer()):e.type==="image/avif"?OV(await e.arrayBuffer()):e.type==="image/webp"?LV(await e.arrayBuffer()):e.type==="image/apng"?AV(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return ZL.includes(e||"")}static isStaticImageType(e){return XL.includes(e||"")}static isVectorImageType(e){return YL.includes(e||"")}static isImageType(e){return wp.includes(e)}static async usingObjectURL(e,t){const r=URL.createObjectURL(e);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function yt(n,e,t){return n+(e-n)*t}function to(n=""){let e=0,t=0,r=0,s=0;function i(){const o=e^e<<11;return e=t,t=r,r=s,s^=(s>>>19^o^o>>>8)>>>0,s/4294967296*2}for(let o=0;o<n.length+64;o++)e^=n.charCodeAt(o)|0,i();return i}function Dd(n,e,t,r=!1){const[s,i]=e,[o,a]=t,l=o+(n-s)/(i-s)*(a-o);return r?o<a?Math.max(Math.min(l,a),o):Math.max(Math.min(l,o),a):l}function yi(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function On(n,e){if(yi(n,e))return n[e]}function zV(n){return Object.keys(n)}function fn(n){return Object.values(n)}function xs(n){return Object.entries(n)}function JL(n){return Object.fromEntries(n)}function If(n,e){const t={};let r=!1;for(const[s,i]of xs(n))e(s,i)?t[s]=i:r=!0;return r?t:n}function Jd(n,e){const t={};for(const[r,s]of xs(n)){const i=e(r,s);t[r]=i}return t}function QL(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 $V(n){const e=BV(n.chars),t=UV(e,n.firstPositive,n.mostPositive,n.mostNegative),r=n.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=HV(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 BV(n){const e={},t={},r=n.length;for(let s=0;s<r;s++){const i=n[s];e[s]=i,t[i]=s}return{byCode:e,byChar:t,length:r}}function UV(n,e,t,r){const s=n.byChar[e],i=n.byChar[t],o=n.byChar[r];if(s===void 0||i===void 0||o===void 0)throw new Error("invalid charSet");if(i-s<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(s-o<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:n.byCode[s],mostPositive:n.byCode[i],firstNegative:n.byCode[s-1],mostNegative:n.byCode[o]}}function HV(n,e){const t={};for(let r=0;r<100&&(t[r]=Math.pow(e,r),!(t[r]>n));r++);return t}var Tw=null;function yk(){return Tw||(Tw=$V({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function kl(n,e,t){const r=t.byChar[n],s=t.byChar[e];return Math.abs(r-s)}function Sk(n,e){const t=n[0];if(t>e.mostPositive||t<e.mostNegative)throw new Error("invalid firstChar on key");return t===e.mostPositive?kl(t,e.firstPositive,e)+1+Ny(n.slice(1),"positive",e):t===e.mostNegative?kl(t,e.firstNegative,e)+1+Ny(n.slice(1),"negative",e):t>=e.firstPositive?kl(t,e.firstPositive,e)+2:kl(t,e.firstNegative,e)+2}function Ny(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"?kl(r,t.mostNegative,t)+1+Ny(n.slice(1),e,t):r===t.mostNegative&&e==="negative"?kl(r,t.mostPositive,t)+1+Ny(n.slice(1),e,t):e==="positive"?kl(r,t.mostNegative,t)+2:kl(r,t.mostPositive,t)+2}function dv(n,e,t,r,s){const i=Math.max(n.length,e.length);return t==="start"?[n.padStart(i,r),e.padStart(i,r)]:[n.padEnd(i,r),e.padEnd(i,r)]}function KV(n,e,t){let[r,s]=dv(n,e,"end",t.first),i=CP(r,s,t);i===1&&(r=r.padEnd(r.length+1,t.first),i=t.length);const o=n3(Math.floor(i/2),t);return vk(r,o,t)}function CP(n,e,t){const[r,s]=dv(n,e,"end",t.first).sort(),i=e3(s,r,t);return WV(i,t)}function vk(n,e,t){const r=t.length,[s,i]=dv(n,e,"start",t.first),o=[];let a=0;for(let l=s.length-1;l>=0;l--){const c=t.byChar[s[l]],d=t.byChar[i[l]],f=c+d+a;a=Math.floor(f/r);const p=f%r;o.unshift(t.byCode[p])}return a>0&&o.unshift(t.byCode[a]),o.join("")}function e3(n,e,t){const r=t.length,[s,i]=dv(n,e,"start",t.first),o=[];let a=0;for(let l=s.length-1;l>=0;l--){let c=t.byChar[s[l]];const d=t.byChar[i[l]]+a;c<d?(a=1,c+=r):a=0;const f=c-d;o.unshift(t.byCode[f])}if(a>0)throw new Error("Subtraction result is negative. Ensure a is greater than or equal to b.");for(;o.length>1&&o[0]===t.byCode[0];)o.shift();return o.join("")}function t3(n,e){return vk(n,e.byCode[1],e)}function PP(n,e){return e3(n,e.byCode[1],e)}function n3(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 WV(n,e){let t=0;const r=n.length,s=e.length;for(let i=0;i<r;i++)t+=e.byChar[n[i]]*Math.pow(s,r-i-1);return t}function VV(n){return n.firstPositive+n.byCode[0]}function qV(n,e){return Sk(n,e)===n.length}function uA(n,e){Ly(n,e)}function Ly(n,e){const t=i3(n,e),r=Sk(t,e);if(r>n.length)throw new Error("invalid order key length: "+n);return n.slice(0,r)}function r3(n,e){if(!qV(n,e))throw new Error("invalid integer length: "+n)}function s3(n,e){r3(n,e);const[t,r]=o3(n,e);if(r.split("").some(o=>o!==e.byCode[e.length-1])){const o=t3(r,e);return t+o}const i=YV(t,e);return a3(i,"lower",e)}function GV(n,e){r3(n,e);const[t,r]=o3(n,e);if(r.split("").some(o=>o!==e.byCode[0])){const o=PP(r,e);return t+o}const i=XV(t,e);return a3(i,"upper",e)}function i3(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 o3(n,e){const t=i3(n,e),r=n.slice(t.length);return[t,r]}function YV(n,e){const t=n>=e.firstPositive,r=t3(n,e),s=n[n.length-1]===e.mostPositive,i=r[r.length-1]===e.mostPositive;return t&&i?r+e.mostNegative:!t&&s?n.slice(0,n.length-1):r}function XV(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 PP(s,e)}return!t&&r?n+e.mostPositive:PP(n,e)}function a3(n,e,t){const r=Sk(n,t),s=e==="upper"?t.byCode[t.length-1]:t.byCode[0];return n+s.repeat(r-n.length)}function l3(n,e){const t=n3(Math.floor(Math.random()*e.jitterRange),e);return vk(n,t,e)}function ZV(n,e,t){const r=n.padEnd(n.length+e,t.first);return l3(r,t)}function JV(n,e,t){const r=Ly(n,t),s=s3(r,t);let i=0;if(e!==null){const a=CP(n,e,t);a<t.jitterRange+1&&(i=Math.max(i,dA(a,t)))}const o=CP(n,s,t);return o<t.jitterRange+1&&(i=Math.max(i,dA(o,t))),i}function dA(n,e){const t=e.jitterRange-n,r=Object.entries(e.paddingDict).find(([s,i])=>i>t);return r?parseInt(r[0]):0}function QV(n,e,t=yk()){if(n!==null&&uA(n,t),e!==null&&uA(e,t),n===null&&e===null)return VV(t);if(n===null){const r=Ly(e,t);return GV(r,t)}if(e===null){const r=Ly(n,t);return s3(r,t)}if(n>=e)throw new Error(n+" >= "+e);return KV(n,e,t)}function c3(n,e,t=yk()){const r=QV(n,e,t),s=JV(r,e,t);return s?ZV(r,s,t):l3(r,t)}function u3(n,e,t,r=yk()){return eq(n,e,t,r,c3,u3)}function eq(n,e,t,r,s,i){if(t===0)return[];if(t===1)return[s(n,e,r)];if(e==null){let l=s(n,e,r);const c=[l];for(let d=0;d<t-1;d++)l=s(l,e,r),c.push(l);return c}if(n==null){let l=s(n,e,r);const c=[l];for(let d=0;d<t-1;d++)l=s(n,l,r),c.push(l);return c.reverse(),c}const o=Math.floor(t/2),a=s(n,e,r);return[...i(n,a,o,r),a,...i(a,e,t-o-1,r)]}const Qd=u3,d3="a0";function tq(n){try{c3(n,null)}catch{throw new Error("invalid index: "+n)}}function jd(n,e,t){return Qd(n??null,e??null,t)}function Mw(n,e){return Qd(n??null,null,e)}function Gf(n,e){return Qd(n??null,e??null,1)[0]}function To(n=null){return Qd(n,null,1)[0]}function nq(n=null){return Qd(null,n,1)[0]}function Yf(n,e="a1"){return[e,...Qd(e,null,n)]}function Qn(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function rq(n,e){return n.id>e.id?1:-1}function xk(n){try{return localStorage.getItem(n)}catch{return null}}function wk(n,e){try{localStorage.setItem(n,e)}catch{}}function sq(){try{localStorage.clear()}catch{}}function h3(n){try{return sessionStorage.getItem(n)}catch{return null}}function bk(n,e){try{sessionStorage.setItem(n,e)}catch{}}function f3(n){try{sessionStorage.removeItem(n)}catch{}}function iq(){try{sessionStorage.clear()}catch{}}const Sd=[],oq=60,Ym=Math.ceil(1e3/oq);let Yh,Aw=0,EP=0;const aq=()=>{const n=Sd.splice(0,Sd.length);for(const e of n)e()};function p3(){if(Yh)return;const n=Date.now(),e=n-EP;if(Aw+e<Ym){Yh=requestAnimationFrame(()=>{Yh=void 0,p3()});return}Yh=requestAnimationFrame(()=>{Yh=void 0,EP=n,Aw=Math.min(Aw+e-Ym,Ym*10),aq()})}let hA=!1;function g3(n){return Sd.includes(n)||(Sd.push(n),hA||(hA=!0,EP=Date.now()-Ym-1),p3()),()=>{const e=Sd.indexOf(n);e>-1&&Sd.splice(e,1)}}class lq{constructor(){O(this,"timeouts",new Map);O(this,"intervals",new Map);O(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 i=window.setTimeout(t,r,s),o=this.timeouts.get(e)??[];return this.timeouts.set(e,[...o,i]),i}setInterval(e,t,r,...s){const i=window.setInterval(t,r,s),o=this.intervals.get(e)??[];return this.intervals.set(e,[...o,i]),i}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(i=>clearTimeout(i)),(r=this.intervals.get(e))==null||r.forEach(i=>clearInterval(i)),(s=this.rafs.get(e))==null||s.forEach(i=>cancelAnimationFrame(i)),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 Je=(n,e)=>{try{return new URL(n,e)}catch{return}};function cq(n){return n!==void 0}function uq(){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 m3=uq(),Yt=m3[0];m3[1];const dq=Object.getPrototypeOf(Yt({}));Wl("@tldraw/utils","3.10.3","esm");var fA={},Xh,pA;function Hr(){if(pA)return Xh;pA=1;var n=function(e){return e&&e.Math===Math&&e};return Xh=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Ss=="object"&&Ss)||n(typeof Xh=="object"&&Xh)||function(){return this}()||Function("return this")(),Xh}var Ow={},Rw,gA;function Kr(){return gA||(gA=1,Rw=function(n){try{return!!n()}catch{return!0}}),Rw}var Dw,mA;function Vl(){if(mA)return Dw;mA=1;var n=Kr();return Dw=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Dw}var jw,yA;function hv(){if(yA)return jw;yA=1;var n=Kr();return jw=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),jw}var Nw,SA;function La(){if(SA)return Nw;SA=1;var n=hv(),e=Function.prototype.call;return Nw=n?e.bind(e):function(){return e.apply(e,arguments)},Nw}var Lw={},vA;function hq(){if(vA)return Lw;vA=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return Lw.f=t?function(s){var i=e(this,s);return!!i&&i.enumerable}:n,Lw}var Fw,xA;function y3(){return xA||(xA=1,Fw=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),Fw}var zw,wA;function Wn(){if(wA)return zw;wA=1;var n=hv(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return zw=n?r:function(s){return function(){return t.apply(s,arguments)}},zw}var $w,bA;function eh(){if(bA)return $w;bA=1;var n=Wn(),e=n({}.toString),t=n("".slice);return $w=function(r){return t(e(r),8,-1)},$w}var Bw,CA;function fq(){if(CA)return Bw;CA=1;var n=Wn(),e=Kr(),t=eh(),r=Object,s=n("".split);return Bw=e(function(){return!r("z").propertyIsEnumerable(0)})?function(i){return t(i)==="String"?s(i,""):r(i)}:r,Bw}var Uw,PA;function fv(){return PA||(PA=1,Uw=function(n){return n==null}),Uw}var Hw,EA;function th(){if(EA)return Hw;EA=1;var n=fv(),e=TypeError;return Hw=function(t){if(n(t))throw new e("Can't call method on "+t);return t},Hw}var Kw,kA;function pv(){if(kA)return Kw;kA=1;var n=fq(),e=th();return Kw=function(t){return n(e(t))},Kw}var Ww,IA;function Wr(){if(IA)return Ww;IA=1;var n=typeof document=="object"&&document.all;return Ww=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},Ww}var Vw,_A;function lu(){if(_A)return Vw;_A=1;var n=Wr();return Vw=function(e){return typeof e=="object"?e!==null:n(e)},Vw}var qw,TA;function gv(){if(TA)return qw;TA=1;var n=Hr(),e=Wr(),t=function(r){return e(r)?r:void 0};return qw=function(r,s){return arguments.length<2?t(n[r]):n[r]&&n[r][s]},qw}var Gw,MA;function S3(){if(MA)return Gw;MA=1;var n=Wn();return Gw=n({}.isPrototypeOf),Gw}var Yw,AA;function pq(){if(AA)return Yw;AA=1;var n=Hr(),e=n.navigator,t=e&&e.userAgent;return Yw=t?String(t):"",Yw}var Xw,OA;function gq(){if(OA)return Xw;OA=1;var n=Hr(),e=pq(),t=n.process,r=n.Deno,s=t&&t.versions||r&&r.version,i=s&&s.v8,o,a;return i&&(o=i.split("."),a=o[0]>0&&o[0]<4?1:+(o[0]+o[1])),!a&&e&&(o=e.match(/Edge\/(\d+)/),(!o||o[1]>=74)&&(o=e.match(/Chrome\/(\d+)/),o&&(a=+o[1]))),Xw=a,Xw}var Zw,RA;function v3(){if(RA)return Zw;RA=1;var n=gq(),e=Kr(),t=Hr(),r=t.String;return Zw=!!Object.getOwnPropertySymbols&&!e(function(){var s=Symbol("symbol detection");return!r(s)||!(Object(s)instanceof Symbol)||!Symbol.sham&&n&&n<41}),Zw}var Jw,DA;function x3(){if(DA)return Jw;DA=1;var n=v3();return Jw=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Jw}var Qw,jA;function w3(){if(jA)return Qw;jA=1;var n=gv(),e=Wr(),t=S3(),r=x3(),s=Object;return Qw=r?function(i){return typeof i=="symbol"}:function(i){var o=n("Symbol");return e(o)&&t(o.prototype,s(i))},Qw}var eb,NA;function mq(){if(NA)return eb;NA=1;var n=String;return eb=function(e){try{return n(e)}catch{return"Object"}},eb}var tb,LA;function Ck(){if(LA)return tb;LA=1;var n=Wr(),e=mq(),t=TypeError;return tb=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},tb}var nb,FA;function Pk(){if(FA)return nb;FA=1;var n=Ck(),e=fv();return nb=function(t,r){var s=t[r];return e(s)?void 0:n(s)},nb}var rb,zA;function yq(){if(zA)return rb;zA=1;var n=La(),e=Wr(),t=lu(),r=TypeError;return rb=function(s,i){var o,a;if(i==="string"&&e(o=s.toString)&&!t(a=n(o,s))||e(o=s.valueOf)&&!t(a=n(o,s))||i!=="string"&&e(o=s.toString)&&!t(a=n(o,s)))return a;throw new r("Can't convert object to primitive value")},rb}var sb={exports:{}},ib,$A;function b3(){return $A||($A=1,ib=!1),ib}var ob,BA;function Ek(){if(BA)return ob;BA=1;var n=Hr(),e=Object.defineProperty;return ob=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},ob}var UA;function kk(){if(UA)return sb.exports;UA=1;var n=b3(),e=Hr(),t=Ek(),r="__core-js_shared__",s=sb.exports=e[r]||t(r,{});return(s.versions||(s.versions=[])).push({version:"3.41.0",mode:n?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.41.0/LICENSE",source:"https://github.com/zloirock/core-js"}),sb.exports}var ab,HA;function Ik(){if(HA)return ab;HA=1;var n=kk();return ab=function(e,t){return n[e]||(n[e]=t||{})},ab}var lb,KA;function bp(){if(KA)return lb;KA=1;var n=th(),e=Object;return lb=function(t){return e(n(t))},lb}var cb,WA;function ql(){if(WA)return cb;WA=1;var n=Wn(),e=bp(),t=n({}.hasOwnProperty);return cb=Object.hasOwn||function(s,i){return t(e(s),i)},cb}var ub,VA;function C3(){if(VA)return ub;VA=1;var n=Wn(),e=0,t=Math.random(),r=n(1 .toString);return ub=function(s){return"Symbol("+(s===void 0?"":s)+")_"+r(++e+t,36)},ub}var db,qA;function Fa(){if(qA)return db;qA=1;var n=Hr(),e=Ik(),t=ql(),r=C3(),s=v3(),i=x3(),o=n.Symbol,a=e("wks"),l=i?o.for||o:o&&o.withoutSetter||r;return db=function(c){return t(a,c)||(a[c]=s&&t(o,c)?o[c]:l("Symbol."+c)),a[c]},db}var hb,GA;function Sq(){if(GA)return hb;GA=1;var n=La(),e=lu(),t=w3(),r=Pk(),s=yq(),i=Fa(),o=TypeError,a=i("toPrimitive");return hb=function(l,c){if(!e(l)||t(l))return l;var d=r(l,a),f;if(d){if(c===void 0&&(c="default"),f=n(d,l,c),!e(f)||t(f))return f;throw new o("Can't convert object to primitive value")}return c===void 0&&(c="number"),s(l,c)},hb}var fb,YA;function P3(){if(YA)return fb;YA=1;var n=Sq(),e=w3();return fb=function(t){var r=n(t,"string");return e(r)?r:r+""},fb}var pb,XA;function E3(){if(XA)return pb;XA=1;var n=Hr(),e=lu(),t=n.document,r=e(t)&&e(t.createElement);return pb=function(s){return r?t.createElement(s):{}},pb}var gb,ZA;function k3(){if(ZA)return gb;ZA=1;var n=Vl(),e=Kr(),t=E3();return gb=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),gb}var JA;function I3(){if(JA)return Ow;JA=1;var n=Vl(),e=La(),t=hq(),r=y3(),s=pv(),i=P3(),o=ql(),a=k3(),l=Object.getOwnPropertyDescriptor;return Ow.f=n?l:function(d,f){if(d=s(d),f=i(f),a)try{return l(d,f)}catch{}if(o(d,f))return r(!e(t.f,d,f),d[f])},Ow}var mb={},yb,QA;function _3(){if(QA)return yb;QA=1;var n=Vl(),e=Kr();return yb=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),yb}var Sb,eO;function cu(){if(eO)return Sb;eO=1;var n=lu(),e=String,t=TypeError;return Sb=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},Sb}var tO;function Cp(){if(tO)return mb;tO=1;var n=Vl(),e=k3(),t=_3(),r=cu(),s=P3(),i=TypeError,o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,l="enumerable",c="configurable",d="writable";return mb.f=n?t?function(p,m,y){if(r(p),m=s(m),r(y),typeof p=="function"&&m==="prototype"&&"value"in y&&d in y&&!y[d]){var v=a(p,m);v&&v[d]&&(p[m]=y.value,y={configurable:c in y?y[c]:v[c],enumerable:l in y?y[l]:v[l],writable:!1})}return o(p,m,y)}:o:function(p,m,y){if(r(p),m=s(m),r(y),e)try{return o(p,m,y)}catch{}if("get"in y||"set"in y)throw new i("Accessors not supported");return"value"in y&&(p[m]=y.value),p},mb}var vb,nO;function _k(){if(nO)return vb;nO=1;var n=Vl(),e=Cp(),t=y3();return vb=n?function(r,s,i){return e.f(r,s,t(1,i))}:function(r,s,i){return r[s]=i,r},vb}var xb={exports:{}},wb,rO;function vq(){if(rO)return wb;rO=1;var n=Vl(),e=ql(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,s=e(t,"name"),i=s&&(function(){}).name==="something",o=s&&(!n||n&&r(t,"name").configurable);return wb={EXISTS:s,PROPER:i,CONFIGURABLE:o},wb}var bb,sO;function T3(){if(sO)return bb;sO=1;var n=Wn(),e=Wr(),t=kk(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(s){return r(s)}),bb=t.inspectSource,bb}var Cb,iO;function xq(){if(iO)return Cb;iO=1;var n=Hr(),e=Wr(),t=n.WeakMap;return Cb=e(t)&&/native code/.test(String(t)),Cb}var Pb,oO;function M3(){if(oO)return Pb;oO=1;var n=Ik(),e=C3(),t=n("keys");return Pb=function(r){return t[r]||(t[r]=e(r))},Pb}var Eb,aO;function Tk(){return aO||(aO=1,Eb={}),Eb}var kb,lO;function A3(){if(lO)return kb;lO=1;var n=xq(),e=Hr(),t=lu(),r=_k(),s=ql(),i=kk(),o=M3(),a=Tk(),l="Object already initialized",c=e.TypeError,d=e.WeakMap,f,p,m,y=function(C){return m(C)?p(C):f(C,{})},v=function(C){return function(I){var _;if(!t(I)||(_=p(I)).type!==C)throw new c("Incompatible receiver, "+C+" required");return _}};if(n||i.state){var x=i.state||(i.state=new d);x.get=x.get,x.has=x.has,x.set=x.set,f=function(C,I){if(x.has(C))throw new c(l);return I.facade=C,x.set(C,I),I},p=function(C){return x.get(C)||{}},m=function(C){return x.has(C)}}else{var b=o("state");a[b]=!0,f=function(C,I){if(s(C,b))throw new c(l);return I.facade=C,r(C,b,I),I},p=function(C){return s(C,b)?C[b]:{}},m=function(C){return s(C,b)}}return kb={set:f,get:p,has:m,enforce:y,getterFor:v},kb}var cO;function wq(){if(cO)return xb.exports;cO=1;var n=Wn(),e=Kr(),t=Wr(),r=ql(),s=Vl(),i=vq().CONFIGURABLE,o=T3(),a=A3(),l=a.enforce,c=a.get,d=String,f=Object.defineProperty,p=n("".slice),m=n("".replace),y=n([].join),v=s&&!e(function(){return f(function(){},"length",{value:8}).length!==8}),x=String(String).split("String"),b=xb.exports=function(C,I,_){p(d(I),0,7)==="Symbol("&&(I="["+m(d(I),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),_&&_.getter&&(I="get "+I),_&&_.setter&&(I="set "+I),(!r(C,"name")||i&&C.name!==I)&&(s?f(C,"name",{value:I,configurable:!0}):C.name=I),v&&_&&r(_,"arity")&&C.length!==_.arity&&f(C,"length",{value:_.arity});try{_&&r(_,"constructor")&&_.constructor?s&&f(C,"prototype",{writable:!1}):C.prototype&&(C.prototype=void 0)}catch{}var T=l(C);return r(T,"source")||(T.source=y(x,typeof I=="string"?I:"")),C};return Function.prototype.toString=b(function(){return t(this)&&c(this).source||o(this)},"toString"),xb.exports}var Ib,uO;function O3(){if(uO)return Ib;uO=1;var n=Wr(),e=Cp(),t=wq(),r=Ek();return Ib=function(s,i,o,a){a||(a={});var l=a.enumerable,c=a.name!==void 0?a.name:i;if(n(o)&&t(o,c,a),a.global)l?s[i]=o:r(i,o);else{try{a.unsafe?s[i]&&(l=!0):delete s[i]}catch{}l?s[i]=o:e.f(s,i,{value:o,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return s},Ib}var _b={},Tb,dO;function bq(){if(dO)return Tb;dO=1;var n=Math.ceil,e=Math.floor;return Tb=Math.trunc||function(r){var s=+r;return(s>0?e:n)(s)},Tb}var Mb,hO;function uu(){if(hO)return Mb;hO=1;var n=bq();return Mb=function(e){var t=+e;return t!==t||t===0?0:n(t)},Mb}var Ab,fO;function Cq(){if(fO)return Ab;fO=1;var n=uu(),e=Math.max,t=Math.min;return Ab=function(r,s){var i=n(r);return i<0?e(i+s,0):t(i,s)},Ab}var Ob,pO;function R3(){if(pO)return Ob;pO=1;var n=uu(),e=Math.min;return Ob=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},Ob}var Rb,gO;function Pp(){if(gO)return Rb;gO=1;var n=R3();return Rb=function(e){return n(e.length)},Rb}var Db,mO;function Pq(){if(mO)return Db;mO=1;var n=pv(),e=Cq(),t=Pp(),r=function(s){return function(i,o,a){var l=n(i),c=t(l);if(c===0)return!s&&-1;var d=e(a,c),f;if(s&&o!==o){for(;c>d;)if(f=l[d++],f!==f)return!0}else for(;c>d;d++)if((s||d in l)&&l[d]===o)return s||d||0;return!s&&-1}};return Db={includes:r(!0),indexOf:r(!1)},Db}var jb,yO;function D3(){if(yO)return jb;yO=1;var n=Wn(),e=ql(),t=pv(),r=Pq().indexOf,s=Tk(),i=n([].push);return jb=function(o,a){var l=t(o),c=0,d=[],f;for(f in l)!e(s,f)&&e(l,f)&&i(d,f);for(;a.length>c;)e(l,f=a[c++])&&(~r(d,f)||i(d,f));return d},jb}var Nb,SO;function Mk(){return SO||(SO=1,Nb=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),Nb}var vO;function Eq(){if(vO)return _b;vO=1;var n=D3(),e=Mk(),t=e.concat("length","prototype");return _b.f=Object.getOwnPropertyNames||function(s){return n(s,t)},_b}var Lb={},xO;function kq(){return xO||(xO=1,Lb.f=Object.getOwnPropertySymbols),Lb}var Fb,wO;function Iq(){if(wO)return Fb;wO=1;var n=gv(),e=Wn(),t=Eq(),r=kq(),s=cu(),i=e([].concat);return Fb=n("Reflect","ownKeys")||function(a){var l=t.f(s(a)),c=r.f;return c?i(l,c(a)):l},Fb}var zb,bO;function _q(){if(bO)return zb;bO=1;var n=ql(),e=Iq(),t=I3(),r=Cp();return zb=function(s,i,o){for(var a=e(i),l=r.f,c=t.f,d=0;d<a.length;d++){var f=a[d];!n(s,f)&&!(o&&n(o,f))&&l(s,f,c(i,f))}},zb}var $b,CO;function Tq(){if(CO)return $b;CO=1;var n=Kr(),e=Wr(),t=/#|\.prototype\./,r=function(l,c){var d=i[s(l)];return d===a?!0:d===o?!1:e(c)?n(c):!!c},s=r.normalize=function(l){return String(l).replace(t,".").toLowerCase()},i=r.data={},o=r.NATIVE="N",a=r.POLYFILL="P";return $b=r,$b}var Bb,PO;function nh(){if(PO)return Bb;PO=1;var n=Hr(),e=I3().f,t=_k(),r=O3(),s=Ek(),i=_q(),o=Tq();return Bb=function(a,l){var c=a.target,d=a.global,f=a.stat,p,m,y,v,x,b;if(d?m=n:f?m=n[c]||s(c,{}):m=n[c]&&n[c].prototype,m)for(y in l){if(x=l[y],a.dontCallGetSet?(b=e(m,y),v=b&&b.value):v=m[y],p=o(d?y:c+(f?".":"#")+y,a.forced),!p&&v!==void 0){if(typeof x==typeof v)continue;i(x,v)}(a.sham||v&&v.sham)&&t(x,"sham",!0),r(m,y,x,a)}},Bb}var Ub={},Hb,EO;function Mq(){if(EO)return Hb;EO=1;var n=D3(),e=Mk();return Hb=Object.keys||function(r){return n(r,e)},Hb}var kO;function Aq(){if(kO)return Ub;kO=1;var n=Vl(),e=_3(),t=Cp(),r=cu(),s=pv(),i=Mq();return Ub.f=n&&!e?Object.defineProperties:function(a,l){r(a);for(var c=s(l),d=i(l),f=d.length,p=0,m;f>p;)t.f(a,m=d[p++],c[m]);return a},Ub}var Kb,IO;function Oq(){if(IO)return Kb;IO=1;var n=gv();return Kb=n("document","documentElement"),Kb}var Wb,_O;function j3(){if(_O)return Wb;_O=1;var n=cu(),e=Aq(),t=Mk(),r=Tk(),s=Oq(),i=E3(),o=M3(),a=">",l="<",c="prototype",d="script",f=o("IE_PROTO"),p=function(){},m=function(C){return l+d+a+C+l+"/"+d+a},y=function(C){C.write(m("")),C.close();var I=C.parentWindow.Object;return C=null,I},v=function(){var C=i("iframe"),I="java"+d+":",_;return C.style.display="none",s.appendChild(C),C.src=String(I),_=C.contentWindow.document,_.open(),_.write(m("document.F=Object")),_.close(),_.F},x,b=function(){try{x=new ActiveXObject("htmlfile")}catch{}b=typeof document<"u"?document.domain&&x?y(x):v():y(x);for(var C=t.length;C--;)delete b[c][t[C]];return b()};return r[f]=!0,Wb=Object.create||function(I,_){var T;return I!==null?(p[c]=n(I),T=new p,p[c]=null,T[f]=I):T=b(),_===void 0?T:e.f(T,_)},Wb}var Vb,TO;function Ak(){if(TO)return Vb;TO=1;var n=Fa(),e=j3(),t=Cp().f,r=n("unscopables"),s=Array.prototype;return s[r]===void 0&&t(s,r,{configurable:!0,value:e(null)}),Vb=function(i){s[r][i]=!0},Vb}var MO;function Rq(){if(MO)return fA;MO=1;var n=nh(),e=bp(),t=Pp(),r=uu(),s=Ak();return n({target:"Array",proto:!0},{at:function(o){var a=e(this),l=t(a),c=r(o),d=c>=0?c:l+c;return d<0||d>=l?void 0:a[d]}}),s("at"),fA}var qb,AO;function Ep(){if(AO)return qb;AO=1;var n=Hr(),e=Wn();return qb=function(t,r){return e(n[t].prototype[r])},qb}var Gb,OO;function Dq(){if(OO)return Gb;OO=1,Rq();var n=Ep();return Gb=n("Array","at"),Gb}var Yb,RO;function jq(){if(RO)return Yb;RO=1;var n=Dq();return Yb=n,Yb}jq();var DO={},Xb,jO;function N3(){if(jO)return Xb;jO=1;var n=eh();return Xb=Array.isArray||function(t){return n(t)==="Array"},Xb}var Zb,NO;function Nq(){if(NO)return Zb;NO=1;var n=TypeError,e=9007199254740991;return Zb=function(t){if(t>e)throw n("Maximum allowed index exceeded");return t},Zb}var Jb,LO;function Lq(){if(LO)return Jb;LO=1;var n=eh(),e=Wn();return Jb=function(t){if(n(t)==="Function")return e(t)},Jb}var Qb,FO;function Fq(){if(FO)return Qb;FO=1;var n=Lq(),e=Ck(),t=hv(),r=n(n.bind);return Qb=function(s,i){return e(s),i===void 0?s:t?r(s,i):function(){return s.apply(i,arguments)}},Qb}var e1,zO;function L3(){if(zO)return e1;zO=1;var n=N3(),e=Pp(),t=Nq(),r=Fq(),s=function(i,o,a,l,c,d,f,p){for(var m=c,y=0,v=f?r(f,p):!1,x,b;y<l;)y in a&&(x=v?v(a[y],y,o):a[y],d>0&&n(x)?(b=e(x),m=s(i,o,x,b,m,d-1)-1):(t(m+1),i[m]=x),m++),y++;return m};return e1=s,e1}var t1,$O;function zq(){if($O)return t1;$O=1;var n=Fa(),e=n("toStringTag"),t={};return t[e]="z",t1=String(t)==="[object z]",t1}var n1,BO;function F3(){if(BO)return n1;BO=1;var n=zq(),e=Wr(),t=eh(),r=Fa(),s=r("toStringTag"),i=Object,o=t(function(){return arguments}())==="Arguments",a=function(l,c){try{return l[c]}catch{}};return n1=n?t:function(l){var c,d,f;return l===void 0?"Undefined":l===null?"Null":typeof(d=a(c=i(l),s))=="string"?d:o?t(c):(f=t(c))==="Object"&&e(c.callee)?"Arguments":f},n1}var r1,UO;function $q(){if(UO)return r1;UO=1;var n=Wn(),e=Kr(),t=Wr(),r=F3(),s=gv(),i=T3(),o=function(){},a=s("Reflect","construct"),l=/^\s*(?:class|function)\b/,c=n(l.exec),d=!l.test(o),f=function(y){if(!t(y))return!1;try{return a(o,[],y),!0}catch{return!1}},p=function(y){if(!t(y))return!1;switch(r(y)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return d||!!c(l,i(y))}catch{return!0}};return p.sham=!0,r1=!a||e(function(){var m;return f(f.call)||!f(Object)||!f(function(){m=!0})||m})?p:f,r1}var s1,HO;function Bq(){if(HO)return s1;HO=1;var n=N3(),e=$q(),t=lu(),r=Fa(),s=r("species"),i=Array;return s1=function(o){var a;return n(o)&&(a=o.constructor,e(a)&&(a===i||n(a.prototype))?a=void 0:t(a)&&(a=a[s],a===null&&(a=void 0))),a===void 0?i:a},s1}var i1,KO;function z3(){if(KO)return i1;KO=1;var n=Bq();return i1=function(e,t){return new(n(e))(t===0?0:t)},i1}var WO;function Uq(){if(WO)return DO;WO=1;var n=nh(),e=L3(),t=Ck(),r=bp(),s=Pp(),i=z3();return n({target:"Array",proto:!0},{flatMap:function(a){var l=r(this),c=s(l),d;return t(a),d=i(l,0),d.length=e(d,l,l,c,0,1,a,arguments.length>1?arguments[1]:void 0),d}}),DO}var VO={},qO;function Hq(){if(qO)return VO;qO=1;var n=Ak();return n("flatMap"),VO}var o1,GO;function Kq(){if(GO)return o1;GO=1,Uq(),Hq();var n=Ep();return o1=n("Array","flatMap"),o1}var a1,YO;function Wq(){if(YO)return a1;YO=1;var n=Kq();return a1=n,a1}Wq();var XO={},ZO;function Vq(){if(ZO)return XO;ZO=1;var n=nh(),e=L3(),t=bp(),r=Pp(),s=uu(),i=z3();return n({target:"Array",proto:!0},{flat:function(){var a=arguments.length?arguments[0]:void 0,l=t(this),c=r(l),d=i(l,0);return d.length=e(d,l,l,c,0,a===void 0?1:s(a)),d}}),XO}var JO={},QO;function qq(){if(QO)return JO;QO=1;var n=Ak();return n("flat"),JO}var l1,eR;function Gq(){if(eR)return l1;eR=1,Vq(),qq();var n=Ep();return l1=n("Array","flat"),l1}var c1,tR;function Yq(){if(tR)return c1;tR=1;var n=Gq();return c1=n,c1}Yq();var nR={},u1,rR;function kp(){if(rR)return u1;rR=1;var n=F3(),e=String;return u1=function(t){if(n(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return e(t)},u1}var sR;function Xq(){if(sR)return nR;sR=1;var n=nh(),e=Wn(),t=th(),r=uu(),s=kp(),i=Kr(),o=e("".charAt),a=i(function(){return"𠮷".at(-2)!=="\uD842"});return n({target:"String",proto:!0,forced:a},{at:function(c){var d=s(t(this)),f=d.length,p=r(c),m=p>=0?p:f+p;return m<0||m>=f?void 0:o(d,m)}}),nR}var d1,iR;function Zq(){if(iR)return d1;iR=1,Xq();var n=Ep();return d1=n("String","at"),d1}var h1,oR;function Jq(){if(oR)return h1;oR=1;var n=Zq();return h1=n,h1}Jq();var aR={},f1,lR;function $3(){if(lR)return f1;lR=1;var n=cu();return f1=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},f1}var p1,cR;function Qq(){if(cR)return p1;cR=1;var n=Kr(),e=Hr(),t=e.RegExp,r=n(function(){var o=t("a","y");return o.lastIndex=2,o.exec("abcd")!==null}),s=r||n(function(){return!t("a","y").sticky}),i=r||n(function(){var o=t("^r","gy");return o.lastIndex=2,o.exec("str")!==null});return p1={BROKEN_CARET:i,MISSED_STICKY:s,UNSUPPORTED_Y:r},p1}var g1,uR;function eG(){if(uR)return g1;uR=1;var n=Kr(),e=Hr(),t=e.RegExp;return g1=n(function(){var r=t(".","s");return!(r.dotAll&&r.test(`
71
+ `)&&r.flags==="s")}),g1}var m1,dR;function tG(){if(dR)return m1;dR=1;var n=Kr(),e=Hr(),t=e.RegExp;return m1=n(function(){var r=t("(?<a>b)","g");return r.exec("b").groups.a!=="b"||"b".replace(r,"$<a>c")!=="bc"}),m1}var y1,hR;function Ok(){if(hR)return y1;hR=1;var n=La(),e=Wn(),t=kp(),r=$3(),s=Qq(),i=Ik(),o=j3(),a=A3().get,l=eG(),c=tG(),d=i("native-string-replace",String.prototype.replace),f=RegExp.prototype.exec,p=f,m=e("".charAt),y=e("".indexOf),v=e("".replace),x=e("".slice),b=function(){var T=/a/,A=/b*/g;return n(f,T,"a"),n(f,A,"a"),T.lastIndex!==0||A.lastIndex!==0}(),C=s.BROKEN_CARET,I=/()??/.exec("")[1]!==void 0,_=b||I||C||l||c;return _&&(p=function(A){var R=this,j=a(R),K=t(A),U=j.raw,J,z,N,L,V,X,W;if(U)return U.lastIndex=R.lastIndex,J=n(p,U,K),R.lastIndex=U.lastIndex,J;var $=j.groups,G=C&&R.sticky,re=n(r,R),H=R.source,ne=0,ge=K;if(G&&(re=v(re,"y",""),y(re,"g")===-1&&(re+="g"),ge=x(K,R.lastIndex),R.lastIndex>0&&(!R.multiline||R.multiline&&m(K,R.lastIndex-1)!==`
72
+ `)&&(H="(?: "+H+")",ge=" "+ge,ne++),z=new RegExp("^(?:"+H+")",re)),I&&(z=new RegExp("^"+H+"$(?!\\s)",re)),b&&(N=R.lastIndex),L=n(f,G?z:R,ge),G?L?(L.input=x(L.input,ne),L[0]=x(L[0],ne),L.index=R.lastIndex,R.lastIndex+=L[0].length):R.lastIndex=0:b&&L&&(R.lastIndex=R.global?L.index+L[0].length:N),I&&L&&L.length>1&&n(d,L[0],z,function(){for(V=1;V<arguments.length-2;V++)arguments[V]===void 0&&(L[V]=void 0)}),L&&$)for(L.groups=X=o(null),V=0;V<$.length;V++)W=$[V],X[W[0]]=L[W[1]];return L}),y1=p,y1}var fR;function B3(){if(fR)return aR;fR=1;var n=nh(),e=Ok();return n({target:"RegExp",proto:!0,forced:/./.exec!==e},{exec:e}),aR}var pR={},S1,gR;function nG(){if(gR)return S1;gR=1;var n=hv(),e=Function.prototype,t=e.apply,r=e.call;return S1=typeof Reflect=="object"&&Reflect.apply||(n?r.bind(t):function(){return r.apply(t,arguments)}),S1}var v1,mR;function rG(){if(mR)return v1;mR=1,B3();var n=La(),e=O3(),t=Ok(),r=Kr(),s=Fa(),i=_k(),o=s("species"),a=RegExp.prototype;return v1=function(l,c,d,f){var p=s(l),m=!r(function(){var b={};return b[p]=function(){return 7},""[l](b)!==7}),y=m&&!r(function(){var b=!1,C=/a/;return l==="split"&&(C={},C.constructor={},C.constructor[o]=function(){return C},C.flags="",C[p]=/./[p]),C.exec=function(){return b=!0,null},C[p](""),!b});if(!m||!y||d){var v=/./[p],x=c(p,""[l],function(b,C,I,_,T){var A=C.exec;return A===t||A===a.exec?m&&!T?{done:!0,value:n(v,C,I,_)}:{done:!0,value:n(b,I,C,_)}:{done:!1}});e(String.prototype,l,x[0]),e(a,p,x[1])}f&&i(a[p],"sham",!0)},v1}var x1,yR;function sG(){if(yR)return x1;yR=1;var n=Wn(),e=uu(),t=kp(),r=th(),s=n("".charAt),i=n("".charCodeAt),o=n("".slice),a=function(l){return function(c,d){var f=t(r(c)),p=e(d),m=f.length,y,v;return p<0||p>=m?l?"":void 0:(y=i(f,p),y<55296||y>56319||p+1===m||(v=i(f,p+1))<56320||v>57343?l?s(f,p):y:l?o(f,p,p+2):(y-55296<<10)+(v-56320)+65536)}};return x1={codeAt:a(!1),charAt:a(!0)},x1}var w1,SR;function iG(){if(SR)return w1;SR=1;var n=sG().charAt;return w1=function(e,t,r){return t+(r?n(e,t).length:1)},w1}var b1,vR;function U3(){if(vR)return b1;vR=1;var n=Wn(),e=bp(),t=Math.floor,r=n("".charAt),s=n("".replace),i=n("".slice),o=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,a=/\$([$&'`]|\d{1,2})/g;return b1=function(l,c,d,f,p,m){var y=d+l.length,v=f.length,x=a;return p!==void 0&&(p=e(p),x=o),s(m,x,function(b,C){var I;switch(r(C,0)){case"$":return"$";case"&":return l;case"`":return i(c,0,d);case"'":return i(c,y);case"<":I=p[i(C,1,-1)];break;default:var _=+C;if(_===0)return b;if(_>v){var T=t(_/10);return T===0?b:T<=v?f[T-1]===void 0?r(C,1):f[T-1]+r(C,1):b}I=f[_-1]}return I===void 0?"":I})},b1}var C1,xR;function oG(){if(xR)return C1;xR=1;var n=La(),e=cu(),t=Wr(),r=eh(),s=Ok(),i=TypeError;return C1=function(o,a){var l=o.exec;if(t(l)){var c=n(l,o,a);return c!==null&&e(c),c}if(r(o)==="RegExp")return n(s,o,a);throw new i("RegExp#exec called on incompatible receiver")},C1}var wR;function aG(){if(wR)return pR;wR=1;var n=nG(),e=La(),t=Wn(),r=rG(),s=Kr(),i=cu(),o=Wr(),a=fv(),l=uu(),c=R3(),d=kp(),f=th(),p=iG(),m=Pk(),y=U3(),v=oG(),x=Fa(),b=x("replace"),C=Math.max,I=Math.min,_=t([].concat),T=t([].push),A=t("".indexOf),R=t("".slice),j=function(z){return z===void 0?z:String(z)},K=function(){return"a".replace(/./,"$0")==="$0"}(),U=function(){return/./[b]?/./[b]("a","$0")==="":!1}(),J=!s(function(){var z=/./;return z.exec=function(){var N=[];return N.groups={a:"7"},N},"".replace(z,"$<a>")!=="7"});return r("replace",function(z,N,L){var V=U?"$":"$0";return[function(W,$){var G=f(this),re=a(W)?void 0:m(W,b);return re?e(re,W,G,$):e(N,d(G),W,$)},function(X,W){var $=i(this),G=d(X);if(typeof W=="string"&&A(W,V)===-1&&A(W,"$<")===-1){var re=L(N,$,G,W);if(re.done)return re.value}var H=o(W);H||(W=d(W));var ne=$.global,ge;ne&&(ge=$.unicode,$.lastIndex=0);for(var Pe=[],ce;ce=v($,G),!(ce===null||(T(Pe,ce),!ne));){var Be=d(ce[0]);Be===""&&($.lastIndex=p(G,c($.lastIndex),ge))}for(var Re="",Ce=0,_e=0;_e<Pe.length;_e++){ce=Pe[_e];for(var Ve=d(ce[0]),it=C(I(l(ce.index),G.length),0),cn=[],It,Jt=1;Jt<ce.length;Jt++)T(cn,j(ce[Jt]));var jt=ce.groups;if(H){var Mt=_([Ve],cn,it,G);jt!==void 0&&T(Mt,jt),It=d(n(W,void 0,Mt))}else It=y(Ve,G,it,cn,jt,W);it>=Ce&&(Re+=R(G,Ce,it)+It,Ce=it+Ve.length)}return Re+R(G,Ce)}]},!J||!K||U),pR}var bR={},P1,CR;function lG(){if(CR)return P1;CR=1;var n=lu(),e=eh(),t=Fa(),r=t("match");return P1=function(s){var i;return n(s)&&((i=s[r])!==void 0?!!i:e(s)==="RegExp")},P1}var E1,PR;function cG(){if(PR)return E1;PR=1;var n=La(),e=ql(),t=S3(),r=$3(),s=RegExp.prototype;return E1=function(i){var o=i.flags;return o===void 0&&!("flags"in s)&&!e(i,"flags")&&t(s,i)?n(r,i):o},E1}var ER;function uG(){if(ER)return bR;ER=1;var n=nh(),e=La(),t=Wn(),r=th(),s=Wr(),i=fv(),o=lG(),a=kp(),l=Pk(),c=cG(),d=U3(),f=Fa(),p=b3(),m=f("replace"),y=TypeError,v=t("".indexOf),x=t("".replace),b=t("".slice),C=Math.max;return n({target:"String",proto:!0},{replaceAll:function(_,T){var A=r(this),R,j,K,U,J,z,N,L,V,X,W=0,$="";if(!i(_)){if(R=o(_),R&&(j=a(r(c(_))),!~v(j,"g")))throw new y("`.replaceAll` does not allow non-global regexes");if(K=l(_,m),K)return e(K,_,A,T);if(p&&R)return x(a(A),_,T)}for(U=a(A),J=a(_),z=s(T),z||(T=a(T)),N=J.length,L=C(1,N),V=v(U,J);V!==-1;)X=z?a(T(J,V,U)):d(J,U,V,[],void 0,T),$+=b(U,W,V)+X,W=V+N,V=V+L>U.length?-1:v(U,J,V+L);return W<U.length&&($+=b(U,W)),$}}),bR}var k1,kR;function dG(){if(kR)return k1;kR=1,B3(),aG(),uG();var n=Ep();return k1=n("String","replaceAll"),k1}var I1,IR;function hG(){if(IR)return I1;IR=1;var n=dG();return I1=n,I1}hG();function H3(n){return n&&typeof n=="object"&&"parents"in n}function K3(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 Fy(n,e){if(n.children.remove(e)&&n.children.isEmpty&&H3(n))for(let t=0,r=n.parents.length;t<r;t++)Fy(n.parents[t],n)}function Rk(n,e){if(n.children.add(e)&&H3(n))for(let t=0,r=n.parents.length;t<r;t++)Rk(n.parents[t],n)}function W3(n,e){return n===e||Object.is(n,e)||!!(n&&e&&typeof n.equals=="function"&&n.equals(e))}function Gl(n,e){const t=Symbol.for(`com.tldraw.state/${n}`),r=globalThis;return r[t]??(r[t]=e()),r[t]}const Si=Gl("empty_array",()=>Object.freeze([])),_R=8;class zy{constructor(){O(this,"arraySize",0);O(this,"array",Array(_R));O(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<_R?(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")}*[Symbol.iterator](){if(this.array)for(let e=0;e<this.arraySize;e++){const t=this.array[e];typeof t<"u"&&(yield t)}else if(this.set)yield*this.set;else 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 zs=Symbol.for("com.tldraw.state/RESET_VALUE");class V3{constructor(e){O(this,"index",0);O(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,t,r){if(r!==void 0){if(r===zs){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 i=0;i<r;i++){const o=(t-1+r-i)%r,a=s[o];if(!a)return zs;const[l,c]=a;if(i===0&&e>=c)return[];if(l<=e&&e<c){const d=i+1,f=new Array(d);for(let p=0;p<d;p++)f[p]=s[(o+p)%r][2];return f}}return zs}}class fG{constructor(e,t){O(this,"offset",0);O(this,"maybeRemoved");this.below=e,this.child=t}}const en=Gl("capture",()=>({stack:null}));function om(n){const e=en.stack;en.stack=null;try{return n()}finally{en.stack=e}}function q3(n){en.stack=new fG(en.stack,n),n.parentSet.clear()}function G3(){const n=en.stack;if(en.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)||Fy(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)||Fy(t,n.child)}}function $y(n){if(en.stack){if(en.stack.child.parentSet.has(n))return;if(en.stack.child.parentSet.add(n),en.stack.child.isActivelyListening&&Rk(n,en.stack.child),en.stack.offset<en.stack.child.parents.length){const t=en.stack.child.parents[en.stack.offset];t!==n&&(en.stack.maybeRemoved?en.stack.maybeRemoved.push(t):en.stack.maybeRemoved=[t])}en.stack.child.parents[en.stack.offset]=n,en.stack.child.parentEpochs[en.stack.offset]=n.lastChangedEpoch,en.stack.offset++}}const Il=-1;class pG{constructor(e,t,r){O(this,"_isActivelyListening",!1);O(this,"lastTraversedEpoch",Il);O(this,"lastReactedEpoch",Il);O(this,"_scheduleCount",0);O(this,"parentSet",new zy);O(this,"parentEpochs",[]);O(this,"parents",[]);O(this,"_scheduleEffect");O(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!==fs()){if(this.parents.length&&!K3(this)){this.lastReactedEpoch=fs();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++)Rk(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,t=this.parents.length;e<t;e++)Fy(this.parents[e],this)}execute(){try{q3(this);const e=fs(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,t}finally{G3()}}}const du=Gl("EffectScheduler",()=>pG);function qi(n,e,t){const r=new du(n,e,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function gG(n,e,t){const r=new du(n,e,t);return{scheduler:r,start:s=>{const i=(s==null?void 0:s.force)??!1;r.attach(),i?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}let mG=class{constructor(e){O(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(kt.globalIsReacting)for(const e of this.initialAtomValues.keys())X3(e);else this.isRoot?Y3(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,e)})}abort(){kt.globalEpoch++,this.initialAtomValues.forEach((e,t)=>{var r;t.set(e),(r=t.historyBuffer)==null||r.clear()}),this.commit()}};const kt=Gl("transactions",()=>({globalEpoch:Il+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Il+1}));function yG(){return kt.reactionEpoch}function fs(){return kt.globalEpoch}function SG(){return kt.globalIsReacting}function Dk(n,e){e.lastTraversedEpoch!==kt.globalEpoch&&(e.lastTraversedEpoch=kt.globalEpoch,e instanceof du?n.add(e):e.children.visit(t=>Dk(n,t)))}function Y3(n){var t;if(kt.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=kt.currentTransaction;try{kt.currentTransaction=null,kt.globalIsReacting=!0,kt.reactionEpoch=kt.globalEpoch;const r=new Set;for(const i of n)i.children.visit(o=>Dk(r,o));for(const i of r)i.maybeScheduleEffect();let s=0;for(;(t=kt.cleanupReactors)!=null&&t.size;){if(s++>1e3)throw new Error("Reaction update depth limit exceeded");const i=kt.cleanupReactors;kt.cleanupReactors=null;for(const o of i)o.maybeScheduleEffect()}}finally{kt.cleanupReactors=null,kt.globalIsReacting=!1,kt.currentTransaction=e}}function vG(n,e){kt.currentTransaction?kt.currentTransaction.initialAtomValues.has(n)||kt.currentTransaction.initialAtomValues.set(n,e):kt.globalIsReacting?X3(n):Y3([n])}function X3(n){const e=kt.cleanupReactors??(kt.cleanupReactors=new Set);n.children.visit(t=>Dk(e,t))}function xG(){kt.globalEpoch++}function wG(n){const e=new mG(kt.currentTransaction);kt.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{kt.currentTransaction=kt.currentTransaction.parent}}function ws(n){return kt.currentTransaction?n():wG(n)}class bG{constructor(e,t,r){O(this,"isEqual");O(this,"computeDiff");O(this,"lastChangedEpoch",fs());O(this,"children",new zy);O(this,"historyBuffer");this.name=e,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new V3(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return $y(this),this.current}set(e,t){var s,i;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,e))??W3(this.current,e))return this.current;xG(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,fs(),t??((i=this.computeDiff)==null?void 0:i.call(this,this.current,e,this.lastChangedEpoch,fs()))??zs),this.lastChangedEpoch=fs();const r=this.current;return this.current=e,vG(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var t;return $y(this),e>=this.lastChangedEpoch?Si:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??zs}}const CG=Gl("Atom",()=>bG);function on(n,e,t){return new CG(n,e,t)}let TR=!1;function PG(){TR||(TR=!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.
73
+
74
+ // Before
75
+ @computed
76
+ get foo() {
77
+ return 'foo'
78
+ }
79
+
80
+ // After
81
+ @computed
82
+ getFoo() {
83
+ return 'foo'
84
+ }
85
+ `))}const Sr=Symbol.for("com.tldraw.state/UNINITIALIZED");function Lc(n){return n===Sr}const kP=Gl("WithDiff",()=>class{constructor(e,t){this.value=e,this.diff=t}});function ff(n,e){return new kP(n,e)}class EG{constructor(e,t,r){O(this,"lastChangedEpoch",Il);O(this,"lastTraversedEpoch",Il);O(this,"lastCheckedEpoch",Il);O(this,"parentSet",new zy);O(this,"parents",[]);O(this,"parentEpochs",[]);O(this,"children",new zy);O(this,"historyBuffer");O(this,"state",Sr);O(this,"error",null);O(this,"computeDiff");O(this,"isEqual");this.name=e,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new V3(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??W3}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var s;const t=this.lastChangedEpoch===Il,r=fs();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&SG()&&this.lastTraversedEpoch<yG()||!K3(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{q3(this);const i=this.derive(this.state,this.lastCheckedEpoch),o=i instanceof kP?i.value:i,a=this.state===Sr;if(a||!this.isEqual(o,this.state)){if(this.historyBuffer&&!a){const l=i instanceof kP?i.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,fs(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,o,this.lastCheckedEpoch,fs()))??zs)}this.lastChangedEpoch=fs(),this.state=o}return this.error=null,this.lastCheckedEpoch=fs(),this.state}catch(i){if(this.state!==Sr&&(this.state=Sr,this.lastChangedEpoch=fs()),this.lastCheckedEpoch=fs(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:i},!e)throw i;return this.state}finally{G3()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{$y(this)}}getDiffSince(e){var t;return this.__unsafe__getWithoutCapture(!0),$y(this),e>=this.lastChangedEpoch?Si:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??zs}}const mv=Gl("Computed",()=>EG);function kG(n={},e,t,r){const s=r.value,i=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let o=this[i];return o||(o=new mv(t,s.bind(this),n),Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()},r.value[Z3]=!0,r}function IG(n={},e,t,r){const s=r.get,i=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let o=this[i];return o||(o=new mv(t,s.bind(this),n),Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()},r}function _G(n,e,t){nt(t.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(t.name)),s=function(){let i=this[r];return i||(i=new mv(String(t.name),e.bind(this),n),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()};return s[Z3]=!0,s}function MR(n={},e){if(e.length===2){const[t,r]=e;return _G(n,t,r)}else{const[t,r,s]=e;return s.get?(PG(),IG(n,t,r,s)):kG(n,t,r,s)}}const Z3="@@__isComputedMethod__@@";function le(){if(arguments.length===1){const n=arguments[0];return(...e)=>MR(n,e)}else return typeof arguments[0]=="string"?new mv(arguments[0],arguments[1],arguments[2]):MR(void 0,arguments)}const J3=1,TG=Gl("apiVersion",()=>J3);if(TG!==J3)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");Wl("@tldraw/state","3.10.3","esm");function yv(n,e,t=[]){const r=He.useRef(e);r.current=e;const[s,i,o]=He.useMemo(()=>{let a=null;const l=f=>(a=f,()=>{a=null}),c=new du(`useStateTracking(${n})`,()=>{var f;return(f=r.current)==null?void 0:f.call(r)},{scheduleEffect(){a==null||a()}});return[c,l,()=>c.scheduleCount]},[n,...t]);return He.useSyncExternalStore(i,o,o),He.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const AR={apply(n,e,t){return yv(n.displayName??n.name??"tracked(???)",()=>n.apply(e,t))}},MG=Symbol.for("react.memo"),AG=Symbol.for("react.forward_ref");function Vn(n){let e=null;const t=n.$$typeof;return t===MG&&(n=n.type,e=n.compare),t===AG?P.memo(P.forwardRef(new Proxy(n.render,AR))):P.memo(new Proxy(n,AR),e)}function Sv(n,e,t){return P.useState(()=>{const r=typeof e=="function"?e():e;return on(`useAtom(${n})`,r,t)})[0]}function OG(){const n=arguments[0],e=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return P.useMemo(()=>le(`useComputed(${n})`,e,t),r)}function Ca(n,e,t=Si){P.useEffect(()=>{const r=new du(n,e);return r.attach(),r.execute(),()=>{r.detach()}},t)}function jk(n,e,t=[]){const r=P.useRef(-1),s=P.useMemo(()=>new du(n,e,{scheduleEffect:i=>{const o=requestAnimationFrame(i);return r.current=o,o}}),t);P.useEffect(()=>(s.attach(),s.execute(),()=>{s.detach(),cancelAnimationFrame(r.current)}),[s])}function ie(){const n=arguments,e=n.length===3?n[2]:[n[0]],t=n.length===3?n[0]:`useValue(${n[0].name})`,r=P.useRef(!0);r.current=!0;const s=P.useMemo(()=>n.length===1?n[0]:le(t,()=>{if(r.current)return n[1]();try{return n[1]()}catch{return{}}}),e);try{const{subscribe:i,getSnapshot:o}=P.useMemo(()=>({subscribe:a=>qi(`useValue(${t})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return P.useSyncExternalStore(i,o,o)}finally{r.current=!1}}Wl("@tldraw/state-react","3.10.3","esm");const $n={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 Ct(n){return`${ee(n.x)},${ee(n.y)} `}function gs(n,e){return`${ee((n.x+e.x)/2)},${ee((n.y+e.y)/2)} `}const xt=Math.PI,Ht=xt/2,Rt=xt*2,RG=Math.sin;function Mn(n,e,t){return Math.max(e,typeof t<"u"?Math.min(n,t):n)}function am(n,e=1e10){return n?Math.round(n*e)/e:0}function Al(n,e,t=1e-6){return Math.abs(n-e)<=t}function Q3(n,e){const t=Math.pow(n-e,2)/Math.pow(n+e,2);return xt*(n+e)*(1+3*t/(10+Math.sqrt(4-3*t)))}function Fc(n){return n=n%Rt,n<0?n=n+Rt:n===0&&(n=0),n}function Ip(n,e){return n=Fc(n),e=Fc(e),n>e&&(e+=Rt),e-n}function eF(n,e){return Rt-Ip(n,e)}function Xm(n,e){const t=(e-n)%Rt;return 2*t%Rt-t}function IP(n){return(Rt+n)%Rt}function By(n,e){const t=Rt/e;let r=Math.floor((IP(n)+t/2)/t)*t%Rt;return r<xt&&(r+=Rt),r>xt&&(r-=Rt),r}function tF(n,e){return n===e||Al(n%(Math.PI/2)-e%(Math.PI/2),0)}function DG(n){return n*xt/180}function jG(n){return n*180/xt}function Wc(n,e,t){return new E(n.x,n.y).add(E.FromAngle(t,e))}function _1(n,e,t){const r=n/2,s=e/2,i=[];let o=1/0,a=-1/0,l=1/0,c=-1/0;for(let y=0;y<t;y++){const v=Rt/t,x=-Ht+y*v,b=r+r*Math.cos(x),C=s+s*Math.sin(x);b<o&&(o=b),C<l&&(l=C),b>a&&(a=b),C>c&&(c=C),i.push(new E(b,C))}const d=a-o,f=c-l,p=n-d,m=e-f;if(p!==0||m!==0)for(let y=0;y<i.length;y++){const v=i[y];v.x=(v.x-o)/d*n,v.y=(v.y-l)/f*e}return i}function Zh(n,e,t,r){return n<r&&t<e}function zi(n,e,t,r){const s=Math.max(n,t),i=Math.min(e,r);return s<=i?[s,i]:null}function OR(n,e,t){return(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y)}function $s(n,e){let t=0,r,s;for(let i=0;i<e.length;i++){if(r=e[i],r.x===n.x&&r.y===n.y||(s=e[(i+1)%e.length],E.Dist(n,r)+E.Dist(n,s)===E.Dist(r,s)))return!0;r.y<=n.y?s.y>n.y&&OR(r,s,n)>0&&(t+=1):s.y<=n.y&&OR(r,s,n)<0&&(t-=1)}return t!==0}function ee(n){return Math.round(n*1e4)/1e4}function va(n){return Math.round(n*100)/100}const RR=n=>Math.abs(n)<Number.MAX_SAFE_INTEGER;function bl(n,e,t){return t<0?Ip(n,e):eF(n,e)}function _P(n,e,t,r){let s;if(Math.abs(n)>xt){s=Xm(e,r);const i=Xm(r,t);return Math.abs(s)<Math.abs(i)?s/n:(n-i)/n}else{s=Xm(e,r);const i=s/n;return Math.sign(s)!==Math.sign(n)?Math.abs(i)>.5?1:0:i}}function NG(n,e,t,r){const s=2*((e-n)%Rt)%Rt-(e-n)%Rt;return r?(Rt-Math.abs(s))*(t?1:-1):s}function Nk(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,i=((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(i)?null:new E(s,i)}function LG(n,e,t,r,s){if(t===null)return[E.From(n),E.From(e)];const i=[],o=E.Angle(t,n),a=E.Angle(t,e),l=Ip(o,a);for(let c=0;c<s;c++){const d=c/(s-1),f=o+l*d,p=Wc(t,r,f);i.push(p)}return i}class E{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),i=Math.cos(e);return this.x=t*i-r*s,this.y=t*s+r*i,this}rotWith(e,t){if(t===0)return this;const r=this.x-e.x,s=this.y-e.y,i=Math.sin(t),o=Math.cos(t);return this.x=e.x+(r*o-s*i),this.y=e.y+(r*i+s*o),this}clone(){const{x:e,y:t,z:r}=this;return new E(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=E.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 E.Dpr(this,e)}cpr(e){return E.Cpr(this,e)}len2(){return E.Len2(this)}len(){return E.Len(this)}pry(e){return E.Pry(this,e)}per(){const{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){return E.Uni(this)}tan(e){return E.Tan(this,e)}dist(e){return E.Dist(this,e)}distanceToLineSegment(e,t){return E.DistanceToLineSegment(e,t,this)}slope(e){return E.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 E.Angle(this,e)}toAngle(){return E.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 E.Equals(this,e)}equalsXY(e,t){return E.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 E.ToFixed(this)}toString(){return E.ToString(E.ToFixed(this))}toJson(){return E.ToJson(this)}toArray(){return E.ToArray(this)}static Add(e,t){return new E(e.x+t.x,e.y+t.y)}static AddXY(e,t,r){return new E(e.x+t,e.y+r)}static Sub(e,t){return new E(e.x-t.x,e.y-t.y)}static SubXY(e,t,r){return new E(e.x-t,e.y-r)}static AddScalar(e,t){return new E(e.x+t,e.y+t)}static SubScalar(e,t){return new E(e.x-t,e.y-t)}static Div(e,t){return new E(e.x/t,e.y/t)}static Mul(e,t){return new E(e.x*t,e.y*t)}static DivV(e,t){return new E(e.x/t.x,e.y/t.y)}static MulV(e,t){return new E(e.x*t.x,e.y*t.y)}static Neg(e){return new E(-e.x,-e.y)}static Per(e){return new E(e.y,-e.x)}static Abs(e){return new E(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 E(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 E.Dpr(e,t)/E.Len(t)}static Uni(e){return E.Div(e,E.Len(e))}static Tan(e,t){return E.Uni(E.Sub(e,t))}static Min(e,t){return new E(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new E(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:r=1}){return new E(e,t,r)}static FromArray(e){return new E(e[0],e[1])}static Rot(e,t=0){const r=Math.sin(t),s=Math.cos(t);return new E(e.x*s-e.y*r,e.x*r+e.y*s)}static RotWith(e,t,r){const s=e.x-t.x,i=e.y-t.y,o=Math.sin(r),a=Math.cos(r);return new E(t.x+(s*a-i*o),t.y+(s*o+i*a))}static NearestPointOnLineThroughPoint(e,t,r){return E.Mul(t,E.Sub(r,e).pry(t)).add(e)}static NearestPointOnLineSegment(e,t,r,s=!0){if(E.Equals(e,r)||E.Equals(t,r))return E.From(r);const i=E.Tan(t,e),o=E.Add(e,E.Mul(i,E.Sub(r,e).pry(i)));if(s){if(o.x<Math.min(e.x,t.x))return E.Cast(e.x<t.x?e:t);if(o.x>Math.max(e.x,t.x))return E.Cast(e.x>t.x?e:t);if(o.y<Math.min(e.y,t.y))return E.Cast(e.y<t.y?e:t);if(o.y>Math.max(e.y,t.y))return E.Cast(e.y>t.y?e:t)}return o}static DistanceToLineThroughPoint(e,t,r){return E.Dist(r,E.NearestPointOnLineThroughPoint(e,t,r))}static DistanceToLineSegment(e,t,r,s=!0){return E.Dist(r,E.NearestPointOnLineSegment(e,t,r,s))}static Snap(e,t=1){return new E(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof E?e:E.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 E.Sub(t,e).mul(r).add(e)}static Med(e,t){return new E((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=E.Len(e);return new E(t*e.x/r,t*e.y/r)}static ScaleWithOrigin(e,t,r){return E.Sub(e,r).mul(t).add(r)}static ToFixed(e){return new E(va(e.x),va(e.y))}static ToInt(e){return new E(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 E.Add(e,E.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 E(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 E(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 E(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new E(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 i=0;i<r;i++){const o=$n.easeInQuad(i/(r-1)),a=E.Lrp(e,t,o);a.z=Math.min(1,.5+Math.abs(.5-FG(o))*.65),s.push(a)}return s}static SnapToGrid(e,t=8){return new E(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}const FG=n=>n<.5?2*n*n:-1+(4-2*n)*n;function nF(n,{initialBounds:e,scaleX:t,scaleY:r,newPoint:s,handle:i}){let o;switch(i){case"bottom_left":case"bottom_right":case"top_left":case"top_right":{o=Math.max(.01,Math.max(Math.abs(t),Math.abs(r)));break}case"left":case"right":{o=Math.max(.01,Math.abs(t));break}case"bottom":case"top":{o=Math.max(.01,Math.abs(r));break}default:throw En(i)}const a=new E(0,0);t<0&&(a.x=-(e.width*o)),r<0&&(a.y=-(e.height*o));const{x:l,y:c}=E.Add(s,a.rot(n.rotation));return{x:l,y:c,props:{scale:o*n.props.scale}}}function Xn(n){this.content=n}Xn.prototype={constructor:Xn,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var r=t&&t!=n?this.remove(t):this,s=r.find(n),i=r.content.slice();return s==-1?i.push(t||n,e):(i[s+1]=e,t&&(i[s]=t)),new Xn(i)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Xn(t)},addToStart:function(n,e){return new Xn([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Xn(t)},addBefore:function(n,e,t){var r=this.remove(e),s=r.content.slice(),i=r.find(n);return s.splice(i==-1?s.length:i,0,e,t),new Xn(s)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Xn.from(n),n.size?new Xn(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Xn.from(n),n.size?new Xn(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Xn.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};Xn.from=function(n){if(n instanceof Xn)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Xn(e)};function rF(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let s=n.child(r),i=e.child(r);if(s==i){t+=s.nodeSize;continue}if(!s.sameMarkup(i))return t;if(s.isText&&s.text!=i.text){for(let o=0;s.text[o]==i.text[o];o++)t++;return t}if(s.content.size||i.content.size){let o=rF(s.content,i.content,t+1);if(o!=null)return o}t+=s.nodeSize}}function sF(n,e,t,r){for(let s=n.childCount,i=e.childCount;;){if(s==0||i==0)return s==i?null:{a:t,b:r};let o=n.child(--s),a=e.child(--i),l=o.nodeSize;if(o==a){t-=l,r-=l;continue}if(!o.sameMarkup(a))return{a:t,b:r};if(o.isText&&o.text!=a.text){let c=0,d=Math.min(o.text.length,a.text.length);for(;c<d&&o.text[o.text.length-c-1]==a.text[a.text.length-c-1];)c++,t--,r--;return{a:t,b:r}}if(o.content.size||a.content.size){let c=sF(o.content,a.content,t-1,r-1);if(c)return c}t-=l,r-=l}}class pe{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,s=0,i){for(let o=0,a=0;a<t;o++){let l=this.content[o],c=a+l.nodeSize;if(c>e&&r(l,s+a,i||null,o)!==!1&&l.content.size){let d=a+1;l.nodesBetween(Math.max(0,e-d),Math.min(l.content.size,t-d),r,s+d)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,s){let i="",o=!0;return this.nodesBetween(e,t,(a,l)=>{let c=a.isText?a.text.slice(Math.max(e,l)-l,t-l):a.isLeaf?s?typeof s=="function"?s(a):s:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&c||a.isTextblock)&&r&&(o?o=!1:i+=r),i+=c},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,s=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(r)&&(s[s.length-1]=t.withText(t.text+r.text),i=1);i<e.content.length;i++)s.push(e.content[i]);return new pe(s,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],s=0;if(t>e)for(let i=0,o=0;o<t;i++){let a=this.content[i],l=o+a.nodeSize;l>e&&((o<e||l>t)&&(a.isText?a=a.cut(Math.max(0,e-o),Math.min(a.text.length,t-o)):a=a.cut(Math.max(0,e-o-1),Math.min(a.content.size,t-o-1))),r.push(a),s+=a.nodeSize),o=l}return new pe(r,s)}cutByIndex(e,t){return e==t?pe.empty:e==0&&t==this.content.length?this:new pe(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let s=this.content.slice(),i=this.size+t.nodeSize-r.nodeSize;return s[e]=t,new pe(s,i)}addToStart(e){return new pe([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new pe(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let s=this.content[t];e(s,r,t),r+=s.nodeSize}}findDiffStart(e,t=0){return rF(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return sF(this,e,t,r)}findIndex(e,t=-1){if(e==0)return lm(0,e);if(e==this.size)return lm(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,s=0;;r++){let i=this.child(r),o=s+i.nodeSize;if(o>=e)return o==e||t>0?lm(r+1,o):lm(r,s);s=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return pe.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new pe(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return pe.empty;let t,r=0;for(let s=0;s<e.length;s++){let i=e[s];r+=i.nodeSize,s&&i.isText&&e[s-1].sameMarkup(i)?(t||(t=e.slice(0,s)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new pe(t||e,r)}static from(e){if(!e)return pe.empty;if(e instanceof pe)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new pe([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}pe.empty=new pe([],0);const T1={index:0,offset:0};function lm(n,e){return T1.index=n,T1.offset=e,T1}function Uy(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!Uy(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!Uy(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}let Lt=class TP{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let s=0;s<e.length;s++){let i=e[s];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,s));else{if(i.type.excludes(this.type))return e;!r&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,s)),t.push(this),r=!0),t&&t.push(i)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Uy(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[t.type];if(!r)throw new RangeError(`There is no mark type ${t.type} in this schema`);let s=r.create(t.attrs);return r.checkAttrs(s.attrs),s}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(t[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return TP.none;if(e instanceof TP)return[e];let t=e.slice();return t.sort((r,s)=>r.type.rank-s.type.rank),t}};Lt.none=[];class Hy extends Error{}class Te{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=oF(this.content,e+this.openStart,t);return r&&new Te(r,this.openStart,this.openEnd)}removeBetween(e,t){return new Te(iF(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return Te.empty;let r=t.openStart||0,s=t.openEnd||0;if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Te(pe.fromJSON(e,t.content),r,s)}static maxOpen(e,t=!0){let r=0,s=0;for(let i=e.firstChild;i&&!i.isLeaf&&(t||!i.type.spec.isolating);i=i.firstChild)r++;for(let i=e.lastChild;i&&!i.isLeaf&&(t||!i.type.spec.isolating);i=i.lastChild)s++;return new Te(e,r,s)}}Te.empty=new Te(pe.empty,0,0);function iF(n,e,t){let{index:r,offset:s}=n.findIndex(e),i=n.maybeChild(r),{index:o,offset:a}=n.findIndex(t);if(s==e||i.isText){if(a!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,i.copy(iF(i.content,e-s-1,t-s-1)))}function oF(n,e,t,r){let{index:s,offset:i}=n.findIndex(e),o=n.maybeChild(s);if(i==e||o.isText)return n.cut(0,e).append(t).append(n.cut(e));let a=oF(o.content,e-i-1,t);return a&&n.replaceChild(s,o.copy(a))}function zG(n,e,t){if(t.openStart>n.depth)throw new Hy("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Hy("Inconsistent open depths");return aF(n,e,t,0)}function aF(n,e,t,r){let s=n.index(r),i=n.node(r);if(s==e.index(r)&&r<n.depth-t.openStart){let o=aF(n,e,t,r+1);return i.copy(i.content.replaceChild(s,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let o=n.parent,a=o.content;return $c(o,a.cut(0,n.parentOffset).append(t.content).append(a.cut(e.parentOffset)))}else{let{start:o,end:a}=$G(t,n);return $c(i,cF(n,o,a,e,r))}else return $c(i,Ky(n,e,r))}function lF(n,e){if(!e.type.compatibleContent(n.type))throw new Hy("Cannot join "+e.type.name+" onto "+n.type.name)}function MP(n,e,t){let r=n.node(t);return lF(r,e.node(t)),r}function zc(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function _f(n,e,t,r){let s=(e||n).node(t),i=0,o=e?e.index(t):s.childCount;n&&(i=n.index(t),n.depth>t?i++:n.textOffset&&(zc(n.nodeAfter,r),i++));for(let a=i;a<o;a++)zc(s.child(a),r);e&&e.depth==t&&e.textOffset&&zc(e.nodeBefore,r)}function $c(n,e){return n.type.checkContent(e),n.copy(e)}function cF(n,e,t,r,s){let i=n.depth>s&&MP(n,e,s+1),o=r.depth>s&&MP(t,r,s+1),a=[];return _f(null,n,s,a),i&&o&&e.index(s)==t.index(s)?(lF(i,o),zc($c(i,cF(n,e,t,r,s+1)),a)):(i&&zc($c(i,Ky(n,e,s+1)),a),_f(e,t,s,a),o&&zc($c(o,Ky(t,r,s+1)),a)),_f(r,null,s,a),new pe(a)}function Ky(n,e,t){let r=[];if(_f(null,n,t,r),n.depth>t){let s=MP(n,e,t+1);zc($c(s,Ky(n,e,t+1)),r)}return _f(e,null,t,r),new pe(r)}function $G(n,e){let t=e.depth-n.openStart,s=e.node(t).copy(n.content);for(let i=t-1;i>=0;i--)s=e.node(i).copy(pe.from(s));return{start:s.resolveNoCache(n.openStart+t),end:s.resolveNoCache(s.content.size-n.openEnd-t)}}class Xf{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],s=e.child(t);return r?e.child(t).cut(r):s}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],s=t==0?0:this.path[t*3-1]+1;for(let i=0;i<e;i++)s+=r.child(i).nodeSize;return s}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return Lt.none;if(this.textOffset)return e.child(t).marks;let r=e.maybeChild(t-1),s=e.maybeChild(t);if(!r){let a=r;r=s,s=a}let i=r.marks;for(var o=0;o<i.length;o++)i[o].type.spec.inclusive===!1&&(!s||!i[o].isInSet(s.marks))&&(i=i[o--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let r=t.marks,s=e.parent.maybeChild(e.index());for(var i=0;i<r.length;i++)r[i].type.spec.inclusive===!1&&(!s||!r[i].isInSet(s.marks))&&(r=r[i--].removeFromSet(r));return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Wy(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],s=0,i=t;for(let o=e;;){let{index:a,offset:l}=o.content.findIndex(i),c=i-l;if(r.push(o,a,s+l),!c||(o=o.child(a),o.isText))break;i=c-1,s+=l+1}return new Xf(t,r,i)}static resolveCached(e,t){let r=DR.get(e);if(r)for(let i=0;i<r.elts.length;i++){let o=r.elts[i];if(o.pos==t)return o}else DR.set(e,r=new BG);let s=r.elts[r.i]=Xf.resolve(e,t);return r.i=(r.i+1)%UG,s}}class BG{constructor(){this.elts=[],this.i=0}}const UG=12,DR=new WeakMap;class Wy{constructor(e,t,r){this.$from=e,this.$to=t,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const HG=Object.create(null);let Gi=class AP{constructor(e,t,r,s=Lt.none){this.type=e,this.attrs=t,this.marks=s,this.content=r||pe.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,r,s=0){this.content.nodesBetween(e,t,r,s,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,r,s){return this.content.textBetween(e,t,r,s)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,r){return this.type==e&&Uy(this.attrs,t||e.defaultAttrs||HG)&&Lt.sameSet(this.marks,r||Lt.none)}copy(e=null){return e==this.content?this:new AP(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new AP(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,r=!1){if(e==t)return Te.empty;let s=this.resolve(e),i=this.resolve(t),o=r?0:s.sharedDepth(t),a=s.start(o),c=s.node(o).content.cut(s.pos-a,i.pos-a);return new Te(c,s.depth-o,i.depth-o)}replace(e,t,r){return zG(this.resolve(e),this.resolve(t),r)}nodeAt(e){for(let t=this;;){let{index:r,offset:s}=t.content.findIndex(e);if(t=t.maybeChild(r),!t)return null;if(s==e||t.isText)return t;e-=s+1}}childAfter(e){let{index:t,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(t),index:t,offset:r};let s=this.content.child(t-1);return{node:s,index:t-1,offset:r-s.nodeSize}}resolve(e){return Xf.resolveCached(this,e)}resolveNoCache(e){return Xf.resolve(this,e)}rangeHasMark(e,t,r){let s=!1;return t>e&&this.nodesBetween(e,t,i=>(r.isInSet(i.marks)&&(s=!0),!s)),s}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),uF(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=pe.empty,s=0,i=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,s,i),a=o&&o.matchFragment(this.content,t);if(!a||!a.validEnd)return!1;for(let l=s;l<i;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,t,r,s){if(s&&!this.type.allowsMarks(s))return!1;let i=this.contentMatchAt(e).matchType(r),o=i&&i.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=Lt.none;for(let t=0;t<this.marks.length;t++){let r=this.marks[t];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!Lt.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let s=pe.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,s,r);return i.type.checkAttrs(i.attrs),i}};Gi.prototype.text=void 0;class Vy extends Gi{constructor(e,t,r,s){if(super(e,t,null,s),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):uF(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Vy(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Vy(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function uF(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Vc{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new KG(e,t);if(r.next==null)return Vc.empty;let s=dF(r);r.next&&r.err("Unexpected trailing text");let i=ZG(XG(s));return JG(i,r),i}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,r=e.childCount){let s=this;for(let i=t;s&&i<r;i++)s=s.matchType(e.child(i).type);return s}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let r=0;r<e.next.length;r++)if(this.next[t].type==e.next[r].type)return!0;return!1}fillBefore(e,t=!1,r=0){let s=[this];function i(o,a){let l=o.matchFragment(e,r);if(l&&(!t||l.validEnd))return pe.from(a.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:d,next:f}=o.next[c];if(!(d.isText||d.hasRequiredAttrs())&&s.indexOf(f)==-1){s.push(f);let p=i(f,a.concat(d));if(p)return p}}return null}return i(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let s=r.shift(),i=s.match;if(i.matchType(e)){let o=[];for(let a=s;a.type;a=a.via)o.push(a.type);return o.reverse()}for(let o=0;o<i.next.length;o++){let{type:a,next:l}=i.next[o];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!s.type||l.validEnd)&&(r.push({match:a.contentMatch,type:a,via:s}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let s=0;s<r.next.length;s++)e.indexOf(r.next[s].next)==-1&&t(r.next[s].next)}return t(this),e.map((r,s)=>{let i=s+(r.validEnd?"*":" ")+" ";for(let o=0;o<r.next.length;o++)i+=(o?", ":"")+r.next[o].type.name+"->"+e.indexOf(r.next[o].next);return i}).join(`
86
+ `)}}Vc.empty=new Vc(!0);class KG{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function dF(n){let e=[];do e.push(WG(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function WG(n){let e=[];do e.push(VG(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function VG(n){let e=YG(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=qG(n,e);else break;return e}function jR(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function qG(n,e){let t=jR(n),r=t;return n.eat(",")&&(n.next!="}"?r=jR(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function GG(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let s=[];for(let i in t){let o=t[i];o.isInGroup(e)&&s.push(o)}return s.length==0&&n.err("No node type or group '"+e+"' found"),s}function YG(n){if(n.eat("(")){let e=dF(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=GG(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function XG(n){let e=[[]];return s(i(n,0),t()),e;function t(){return e.push([])-1}function r(o,a,l){let c={term:l,to:a};return e[o].push(c),c}function s(o,a){o.forEach(l=>l.to=a)}function i(o,a){if(o.type=="choice")return o.exprs.reduce((l,c)=>l.concat(i(c,a)),[]);if(o.type=="seq")for(let l=0;;l++){let c=i(o.exprs[l],a);if(l==o.exprs.length-1)return c;s(c,a=t())}else if(o.type=="star"){let l=t();return r(a,l),s(i(o.expr,l),l),[r(l)]}else if(o.type=="plus"){let l=t();return s(i(o.expr,a),l),s(i(o.expr,l),l),[r(l)]}else{if(o.type=="opt")return[r(a)].concat(i(o.expr,a));if(o.type=="range"){let l=a;for(let c=0;c<o.min;c++){let d=t();s(i(o.expr,l),d),l=d}if(o.max==-1)s(i(o.expr,l),l);else for(let c=o.min;c<o.max;c++){let d=t();r(l,d),s(i(o.expr,l),d),l=d}return[r(l)]}else{if(o.type=="name")return[r(a,void 0,o.value)];throw new Error("Unknown expr type")}}}}function hF(n,e){return e-n}function NR(n,e){let t=[];return r(e),t.sort(hF);function r(s){let i=n[s];if(i.length==1&&!i[0].term)return r(i[0].to);t.push(s);for(let o=0;o<i.length;o++){let{term:a,to:l}=i[o];!a&&t.indexOf(l)==-1&&r(l)}}}function ZG(n){let e=Object.create(null);return t(NR(n,0));function t(r){let s=[];r.forEach(o=>{n[o].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let d=0;d<s.length;d++)s[d][0]==a&&(c=s[d][1]);NR(n,l).forEach(d=>{c||s.push([a,c=[]]),c.indexOf(d)==-1&&c.push(d)})})});let i=e[r.join(",")]=new Vc(r.indexOf(n.length-1)>-1);for(let o=0;o<s.length;o++){let a=s[o][1].sort(hF);i.next.push({type:s[o][0],next:e[a.join(",")]||t(a)})}return i}}function JG(n,e){for(let t=0,r=[n];t<r.length;t++){let s=r[t],i=!s.validEnd,o=[];for(let a=0;a<s.next.length;a++){let{type:l,next:c}=s.next[a];o.push(l.name),i&&!(l.isText||l.hasRequiredAttrs())&&(i=!1),r.indexOf(c)==-1&&r.push(c)}i&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function fF(n){let e=Object.create(null);for(let t in n){let r=n[t];if(!r.hasDefault)return null;e[t]=r.default}return e}function pF(n,e){let t=Object.create(null);for(let r in n){let s=e&&e[r];if(s===void 0){let i=n[r];if(i.hasDefault)s=i.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=s}return t}function gF(n,e,t,r){for(let s in e)if(!(s in n))throw new RangeError(`Unsupported attribute ${s} for ${t} of type ${s}`);for(let s in n){let i=n[s];i.validate&&i.validate(e[s])}}function mF(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new eY(n,r,e[r]);return t}let LR=class yF{constructor(e,t,r){this.name=e,this.schema=t,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=mF(e,r.attrs),this.defaultAttrs=fF(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Vc.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:pF(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Gi(this,this.computeAttrs(e),pe.from(t),Lt.setFrom(r))}createChecked(e=null,t,r){return t=pe.from(t),this.checkContent(t),new Gi(this,this.computeAttrs(e),t,Lt.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=pe.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let s=this.contentMatch.matchFragment(t),i=s&&s.fillBefore(pe.empty,!0);return i?new Gi(this,e,t.append(i),Lt.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){gF(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?t&&t.push(e[r]):t||(t=e.slice(0,r));return t?t.length?t:Lt.none:e}static compile(e,t){let r=Object.create(null);e.forEach((i,o)=>r[i]=new yF(i,t,o));let s=t.spec.topNode||"doc";if(!r[s])throw new RangeError("Schema is missing its top node type ('"+s+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let i in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function QG(n,e,t){let r=t.split("|");return s=>{let i=s===null?"null":typeof s;if(r.indexOf(i)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${i}`)}}class eY{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?QG(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class vv{constructor(e,t,r,s){this.name=e,this.rank=t,this.schema=r,this.spec=s,this.attrs=mF(e,s.attrs),this.excluded=null;let i=fF(this.attrs);this.instance=i?new Lt(this,i):null}create(e=null){return!e&&this.instance?this.instance:new Lt(this,pF(this.attrs,e))}static compile(e,t){let r=Object.create(null),s=0;return e.forEach((i,o)=>r[i]=new vv(i,s++,t,o)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){gF(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class SF{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let s in e)t[s]=e[s];t.nodes=Xn.from(e.nodes),t.marks=Xn.from(e.marks||{}),this.nodes=LR.compile(this.spec.nodes,this),this.marks=vv.compile(this.spec.marks,this);let r=Object.create(null);for(let s in this.nodes){if(s in this.marks)throw new RangeError(s+" can not be both a node and a mark");let i=this.nodes[s],o=i.spec.content||"",a=i.spec.marks;if(i.contentMatch=r[o]||(r[o]=Vc.parse(o,this.nodes)),i.inlineContent=i.contentMatch.inlineContent,i.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!i.isInline||!i.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=i}i.markSet=a=="_"?null:a?FR(this,a.split(" ")):a==""||!i.inlineContent?[]:null}for(let s in this.marks){let i=this.marks[s],o=i.spec.excludes;i.excluded=o==null?[i]:o==""?[]:FR(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,s){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof LR){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,s)}text(e,t){let r=this.nodes.text;return new Vy(r,r.defaultAttrs,e,Lt.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Gi.fromJSON(this,e)}markFromJSON(e){return Lt.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function FR(n,e){let t=[];for(let r=0;r<e.length;r++){let s=e[r],i=n.marks[s],o=i;if(i)t.push(i);else for(let a in n.marks){let l=n.marks[a];(s=="_"||l.spec.group&&l.spec.group.split(" ").indexOf(s)>-1)&&t.push(o=l)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function tY(n){return n.tag!=null}function nY(n){return n.style!=null}let Cd=class OP{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(s=>{if(tY(s))this.tags.push(s);else if(nY(s)){let i=/[^=]*/.exec(s.style)[0];r.indexOf(i)<0&&r.push(i),this.styles.push(s)}}),this.normalizeLists=!this.tags.some(s=>{if(!/^(ul|ol)\b/.test(s.tag)||!s.node)return!1;let i=e.nodes[s.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new $R(this,t,!1);return r.addAll(e,Lt.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new $R(this,t,!0);return r.addAll(e,Lt.none,t.from,t.to),Te.maxOpen(r.finish())}matchTag(e,t,r){for(let s=r?this.tags.indexOf(r)+1:0;s<this.tags.length;s++){let i=this.tags[s];if(iY(e,i.tag)&&(i.namespace===void 0||e.namespaceURI==i.namespace)&&(!i.context||t.matchesContext(i.context))){if(i.getAttrs){let o=i.getAttrs(e);if(o===!1)continue;i.attrs=o||void 0}return i}}}matchStyle(e,t,r,s){for(let i=s?this.styles.indexOf(s)+1:0;i<this.styles.length;i++){let o=this.styles[i],a=o.style;if(!(a.indexOf(e)!=0||o.context&&!r.matchesContext(o.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}static schemaRules(e){let t=[];function r(s){let i=s.priority==null?50:s.priority,o=0;for(;o<t.length;o++){let a=t[o];if((a.priority==null?50:a.priority)<i)break}t.splice(o,0,s)}for(let s in e.marks){let i=e.marks[s].spec.parseDOM;i&&i.forEach(o=>{r(o=BR(o)),o.mark||o.ignore||o.clearMark||(o.mark=s)})}for(let s in e.nodes){let i=e.nodes[s].spec.parseDOM;i&&i.forEach(o=>{r(o=BR(o)),o.node||o.ignore||o.mark||(o.node=s)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new OP(e,OP.schemaRules(e)))}};const vF={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},rY={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xF={ol:!0,ul:!0},Zf=1,RP=2,Zm=4;function zR(n,e,t){return e!=null?(e?Zf:0)|(e==="full"?RP:0):n&&n.whitespace=="pre"?Zf|RP:t&-5}class cm{constructor(e,t,r,s,i,o){this.type=e,this.attrs=t,this.marks=r,this.solid=s,this.options=o,this.content=[],this.activeMarks=Lt.none,this.match=i||(o&Zm?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(pe.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,s;return(s=r.findWrapping(e.type))?(this.match=r,s):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Zf)){let r=this.content[this.content.length-1],s;if(r&&r.isText&&(s=/[ \t\r\n\u000c]+$/.exec(r.text))){let i=r;r.text.length==s[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-s[0].length))}}let t=pe.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(pe.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!vF.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class $R{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let s=t.topNode,i,o=zR(null,t.preserveWhitespace,0)|(r?Zm:0);s?i=new cm(s.type,s.attrs,Lt.none,!0,t.topMatch||s.type.contentMatch,o):r?i=new cm(null,null,Lt.none,!0,null,o):i=new cm(e.schema.topNodeType,null,Lt.none,!0,null,o),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,s=this.top,i=s.options&RP?"full":this.localPreserveWS||(s.options&Zf)>0;if(i==="full"||s.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i)i!=="full"?r=r.replace(/\r?\n|\r/g," "):r=r.replace(/\r\n?/g,`
87
+ `);else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=s.content[s.content.length-1],a=e.previousSibling;(!o||a&&a.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let s=this.localPreserveWS,i=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),a;xF.hasOwnProperty(o)&&this.parser.normalizeLists&&sY(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:rY.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let c,d=this.needsBlock;if(vF.hasOwnProperty(o))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),c=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let f=l&&l.skip?t:this.readStyles(e,t);f&&this.addAll(e,f),c&&this.sync(i),this.needsBlock=d}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,l,c,l.consuming===!1?a:void 0)}this.localPreserveWS=s}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
88
+ `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let s=0;s<this.parser.matchedStyles.length;s++){let i=this.parser.matchedStyles[s],o=r.getPropertyValue(i);if(o)for(let a=void 0;;){let l=this.parser.matchStyle(i,o,this,a);if(!l)break;if(l.ignore)return null;if(l.clearMark?t=t.filter(c=>!l.clearMark(c)):t=t.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return t}addElementByRule(e,t,r,s){let i,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let l=this.enter(o,t.attrs||null,r,t.preserveWhitespace);l&&(i=!0,r=l)}else{let l=this.parser.schema.marks[t.mark];r=r.concat(l.create(t.attrs))}let a=this.top;if(o&&o.isLeaf)this.findInside(e);else if(s)this.addElement(e,r,s);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r));else{let l=e;typeof t.contentElement=="string"?l=e.querySelector(t.contentElement):typeof t.contentElement=="function"?l=t.contentElement(e):t.contentElement&&(l=t.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}i&&this.sync(a)&&this.open--}addAll(e,t,r,s){let i=r||0;for(let o=r?e.childNodes[r]:e.firstChild,a=s==null?null:e.childNodes[s];o!=a;o=o.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(o,t);this.findAtPoint(e,i)}findPlace(e,t){let r,s;for(let i=this.open;i>=0;i--){let o=this.nodes[i],a=o.findWrapping(e);if(a&&(!r||r.length>a.length)&&(r=a,s=o,!a.length)||o.solid)break}if(!r)return null;this.sync(s);for(let i=0;i<r.length;i++)t=this.enterInner(r[i],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let i=Lt.none;for(let o of r.concat(e.marks))(s.type?s.type.allowsMarkType(o.type):UR(o.type,e.type))&&(i=o.addToSet(i));return s.content.push(e.mark(i)),!0}return!1}enter(e,t,r,s){let i=this.findPlace(e.create(t),r);return i&&(i=this.enterInner(e,t,r,!0,s)),i}enterInner(e,t,r,s=!1,i){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let a=zR(e,i,o.options);o.options&Zm&&o.content.length==0&&(a|=Zm);let l=Lt.none;return r=r.filter(c=>(o.type?o.type.allowsMarkType(c.type):UR(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new cm(e,t,l,s,null,a)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=Zf)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let s=r.length-1;s>=0;s--)e+=r[s].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==t&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,r){if(e!=t&&this.find)for(let s=0;s<this.find.length;s++)this.find[s].pos==null&&e.nodeType==1&&e.contains(this.find[s].node)&&t.compareDocumentPosition(this.find[s].node)&(r?2:4)&&(this.find[s].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,s=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),i=-(r?r.depth+1:0)+(s?0:1),o=(a,l)=>{for(;a>=0;a--){let c=t[a];if(c==""){if(a==t.length-1||a==0)continue;for(;l>=i;l--)if(o(a-1,l))return!0;return!1}else{let d=l>0||l==0&&s?this.nodes[l].type:r&&l>=i?r.node(l-i).type:null;if(!d||d.name!=c&&!d.isInGroup(c))return!1;l--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function sY(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&xF.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function iY(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function BR(n){let e={};for(let t in n)e[t]=n[t];return e}function UR(n,e){let t=e.schema.nodes;for(let r in t){let s=t[r];if(!s.allowsMarkType(n))continue;let i=[],o=a=>{i.push(a);for(let l=0;l<a.edgeCount;l++){let{type:c,next:d}=a.edge(l);if(c==e||i.indexOf(d)<0&&o(d))return!0}};if(o(s.contentMatch))return!0}}class hu{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},r){r||(r=M1(t).createDocumentFragment());let s=r,i=[];return e.forEach(o=>{if(i.length||o.marks.length){let a=0,l=0;for(;a<i.length&&l<o.marks.length;){let c=o.marks[l];if(!this.marks[c.type.name]){l++;continue}if(!c.eq(i[a][0])||c.type.spec.spanning===!1)break;a++,l++}for(;a<i.length;)s=i.pop()[1];for(;l<o.marks.length;){let c=o.marks[l++],d=this.serializeMark(c,o.isInline,t);d&&(i.push([c,s]),s.appendChild(d.dom),s=d.contentDOM||d.dom)}}s.appendChild(this.serializeNodeInner(o,t))}),r}serializeNodeInner(e,t){let{dom:r,contentDOM:s}=Jm(M1(t),this.nodes[e.type.name](e),null,e.attrs);if(s){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,s)}return r}serializeNode(e,t={}){let r=this.serializeNodeInner(e,t);for(let s=e.marks.length-1;s>=0;s--){let i=this.serializeMark(e.marks[s],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(r),r=i.dom)}return r}serializeMark(e,t,r={}){let s=this.marks[e.type.name];return s&&Jm(M1(r),s(e,t),null,e.attrs)}static renderSpec(e,t,r=null,s){return Jm(e,t,r,s)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new hu(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=HR(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return HR(e.marks)}}function HR(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function M1(n){return n.document||window.document}const KR=new WeakMap;function oY(n){let e=KR.get(n);return e===void 0&&KR.set(n,e=aY(n)),e}function aY(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let s=0;s<r.length;s++)t(r[s]);else for(let s in r)t(r[s])}return t(n),e}function Jm(n,e,t,r){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let s=e[0],i;if(typeof s!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(i=oY(r))&&i.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=s.indexOf(" ");o>0&&(t=s.slice(0,o),s=s.slice(o+1));let a,l=t?n.createElementNS(t,s):n.createElement(s),c=e[1],d=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){d=2;for(let f in c)if(c[f]!=null){let p=f.indexOf(" ");p>0?l.setAttributeNS(f.slice(0,p),f.slice(p+1),c[f]):l.setAttribute(f,c[f])}}for(let f=d;f<e.length;f++){let p=e[f];if(p===0){if(f<e.length-1||f>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:m,contentDOM:y}=Jm(n,p,t,r);if(l.appendChild(m),y){if(a)throw new RangeError("Multiple content holes");a=y}}}return{dom:l,contentDOM:a}}const wF=65535,bF=Math.pow(2,16);function lY(n,e){return n+e*bF}function WR(n){return n&wF}function cY(n){return(n-(n&wF))/bF}const CF=1,PF=2,Qm=4,EF=8;class DP{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&EF)>0}get deletedBefore(){return(this.delInfo&(CF|Qm))>0}get deletedAfter(){return(this.delInfo&(PF|Qm))>0}get deletedAcross(){return(this.delInfo&Qm)>0}}class Ns{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ns.empty)return Ns.empty}recover(e){let t=0,r=WR(e);if(!this.inverted)for(let s=0;s<r;s++)t+=this.ranges[s*3+2]-this.ranges[s*3+1];return this.ranges[r*3]+t+cY(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let s=0,i=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?s:0);if(l>e)break;let c=this.ranges[a+i],d=this.ranges[a+o],f=l+c;if(e<=f){let p=c?e==l?-1:e==f?1:t:t,m=l+s+(p<0?0:d);if(r)return m;let y=e==(t<0?l:f)?null:lY(a/3,e-l),v=e==l?PF:e==f?CF:Qm;return(t<0?e!=l:e!=f)&&(v|=EF),new DP(m,v,y)}s+=d-c}return r?e+s:new DP(e+s,0,null)}touches(e,t){let r=0,s=WR(t),i=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?r:0);if(l>e)break;let c=this.ranges[a+i],d=l+c;if(e<=d&&a==s*3)return!0;r+=this.ranges[a+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let s=0,i=0;s<this.ranges.length;s+=3){let o=this.ranges[s],a=o-(this.inverted?i:0),l=o+(this.inverted?0:i),c=this.ranges[s+t],d=this.ranges[s+r];e(a,a+c,l,l+d),i+=d-c}}invert(){return new Ns(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ns.empty:new Ns(e<0?[0,-e,0]:[0,0,e])}}Ns.empty=new Ns([]);class Jf{constructor(e,t,r=0,s=e?e.length:0){this.mirror=t,this.from=r,this.to=s,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new Jf(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,r=this._maps.length;t<e._maps.length;t++){let s=e.getMirror(t);this.appendMap(e._maps[t],s!=null&&s<t?r+s:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,r=this._maps.length+e._maps.length;t>=0;t--){let s=e.getMirror(t);this.appendMap(e._maps[t].invert(),s!=null&&s>t?r-s-1:void 0)}}invert(){let e=new Jf;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;r<this.to;r++)e=this._maps[r].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,r){let s=0;for(let i=this.from;i<this.to;i++){let o=this._maps[i],a=o.mapResult(e,t);if(a.recover!=null){let l=this.getMirror(i);if(l!=null&&l>i&&l<this.to){i=l,e=this._maps[l].recover(a.recover);continue}}s|=a.delInfo,e=a.pos}return r?e:new DP(e,s,null)}}const A1=Object.create(null);class Ir{getMap(){return Ns.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=A1[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in A1)throw new RangeError("Duplicate use of step JSON ID "+e);return A1[e]=t,t.prototype.jsonID=e,t}}class kn{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new kn(e,null)}static fail(e){return new kn(null,e)}static fromReplace(e,t,r,s){try{return kn.ok(e.replace(t,r,s))}catch(i){if(i instanceof Hy)return kn.fail(i.message);throw i}}}function Lk(n,e,t){let r=[];for(let s=0;s<n.childCount;s++){let i=n.child(s);i.content.size&&(i=i.copy(Lk(i.content,e,i))),i.isInline&&(i=e(i,t,s)),r.push(i)}return pe.fromArray(r)}class _l extends Ir{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),s=r.node(r.sharedDepth(this.to)),i=new Te(Lk(t.content,(o,a)=>!o.isAtom||!a.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),s),t.openStart,t.openEnd);return kn.fromReplace(e,this.from,this.to,i)}invert(){return new Mo(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new _l(t.pos,r.pos,this.mark)}merge(e){return e instanceof _l&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _l(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new _l(t.from,t.to,e.markFromJSON(t.mark))}}Ir.jsonID("addMark",_l);class Mo extends Ir{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new Te(Lk(t.content,s=>s.mark(this.mark.removeFromSet(s.marks)),e),t.openStart,t.openEnd);return kn.fromReplace(e,this.from,this.to,r)}invert(){return new _l(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Mo(t.pos,r.pos,this.mark)}merge(e){return e instanceof Mo&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Mo(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Mo(t.from,t.to,e.markFromJSON(t.mark))}}Ir.jsonID("removeMark",Mo);class Tl extends Ir{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return kn.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return kn.fromReplace(e,this.pos,this.pos+1,new Te(pe.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let s=0;s<t.marks.length;s++)if(!t.marks[s].isInSet(r))return new Tl(this.pos,t.marks[s]);return new Tl(this.pos,this.mark)}}return new Nd(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Tl(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Tl(t.pos,e.markFromJSON(t.mark))}}Ir.jsonID("addNodeMark",Tl);class Nd extends Ir{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return kn.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return kn.fromReplace(e,this.pos,this.pos+1,new Te(pe.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Tl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Nd(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Nd(t.pos,e.markFromJSON(t.mark))}}Ir.jsonID("removeNodeMark",Nd);class Fn extends Ir{constructor(e,t,r,s=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=s}apply(e){return this.structure&&jP(e,this.from,this.to)?kn.fail("Structure replace would overwrite content"):kn.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ns([this.from,this.to-this.from,this.slice.size])}invert(e){return new Fn(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deletedAcross&&r.deletedAcross?null:new Fn(t.pos,Math.max(t.pos,r.pos),this.slice)}merge(e){if(!(e instanceof Fn)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?Te.empty:new Te(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Fn(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?Te.empty:new Te(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Fn(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Fn(t.from,t.to,Te.fromJSON(e,t.slice),!!t.structure)}}Ir.jsonID("replace",Fn);class Bn extends Ir{constructor(e,t,r,s,i,o,a=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=s,this.slice=i,this.insert=o,this.structure=a}apply(e){if(this.structure&&(jP(e,this.from,this.gapFrom)||jP(e,this.gapTo,this.to)))return kn.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return kn.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?kn.fromReplace(e,this.from,this.to,r):kn.fail("Content does not fit in gap")}getMap(){return new Ns([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Bn(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),s=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||s<t.pos||i>r.pos?null:new Bn(t.pos,r.pos,s,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Bn(t.from,t.to,t.gapFrom,t.gapTo,Te.fromJSON(e,t.slice),t.insert,!!t.structure)}}Ir.jsonID("replaceAround",Bn);function jP(n,e,t){let r=n.resolve(e),s=t-e,i=r.depth;for(;s>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,s--;if(s>0){let o=r.node(i).maybeChild(r.indexAfter(i));for(;s>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,s--}}return!1}function uY(n,e,t,r){let s=[],i=[],o,a;n.doc.nodesBetween(e,t,(l,c,d)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&d.type.allowsMarkType(r.type)){let p=Math.max(c,e),m=Math.min(c+l.nodeSize,t),y=r.addToSet(f);for(let v=0;v<f.length;v++)f[v].isInSet(y)||(o&&o.to==p&&o.mark.eq(f[v])?o.to=m:s.push(o=new Mo(p,m,f[v])));a&&a.to==p?a.to=m:i.push(a=new _l(p,m,r))}}),s.forEach(l=>n.step(l)),i.forEach(l=>n.step(l))}function dY(n,e,t,r){let s=[],i=0;n.doc.nodesBetween(e,t,(o,a)=>{if(!o.isInline)return;i++;let l=null;if(r instanceof vv){let c=o.marks,d;for(;d=r.isInSet(c);)(l||(l=[])).push(d),c=d.removeFromSet(c)}else r?r.isInSet(o.marks)&&(l=[r]):l=o.marks;if(l&&l.length){let c=Math.min(a+o.nodeSize,t);for(let d=0;d<l.length;d++){let f=l[d],p;for(let m=0;m<s.length;m++){let y=s[m];y.step==i-1&&f.eq(s[m].style)&&(p=y)}p?(p.to=c,p.step=i):s.push({style:f,from:Math.max(a,e),to:c,step:i})}}}),s.forEach(o=>n.step(new Mo(o.from,o.to,o.style)))}function Fk(n,e,t,r=t.contentMatch,s=!0){let i=n.doc.nodeAt(e),o=[],a=e+1;for(let l=0;l<i.childCount;l++){let c=i.child(l),d=a+c.nodeSize,f=r.matchType(c.type);if(!f)o.push(new Fn(a,d,Te.empty));else{r=f;for(let p=0;p<c.marks.length;p++)t.allowsMarkType(c.marks[p].type)||n.step(new Mo(a,d,c.marks[p]));if(s&&c.isText&&t.whitespace!="pre"){let p,m=/\r?\n|\r/g,y;for(;p=m.exec(c.text);)y||(y=new Te(pe.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new Fn(a+p.index,a+p.index+p[0].length,y))}}a=d}if(!r.validEnd){let l=r.fillBefore(pe.empty,!0);n.replace(a,a,new Te(l,0,0))}for(let l=o.length-1;l>=0;l--)n.step(o[l])}function hY(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function rh(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let s=n.$from.node(r),i=n.$from.index(r),o=n.$to.indexAfter(r);if(r<n.depth&&s.canReplace(i,o,t))return r;if(r==0||s.type.spec.isolating||!hY(s,i,o))break}return null}function fY(n,e,t){let{$from:r,$to:s,depth:i}=e,o=r.before(i+1),a=s.after(i+1),l=o,c=a,d=pe.empty,f=0;for(let y=i,v=!1;y>t;y--)v||r.index(y)>0?(v=!0,d=pe.from(r.node(y).copy(d)),f++):l--;let p=pe.empty,m=0;for(let y=i,v=!1;y>t;y--)v||s.after(y+1)<s.end(y)?(v=!0,p=pe.from(s.node(y).copy(p)),m++):c++;n.step(new Bn(l,c,o,a,new Te(d.append(p),f,m),d.size-f,!0))}function zk(n,e,t=null,r=n){let s=pY(n,e),i=s&&gY(r,e);return i?s.map(VR).concat({type:e,attrs:t}).concat(i.map(VR)):null}function VR(n){return{type:n,attrs:null}}function pY(n,e){let{parent:t,startIndex:r,endIndex:s}=n,i=t.contentMatchAt(r).findWrapping(e);if(!i)return null;let o=i.length?i[0]:e;return t.canReplaceWith(r,s,o)?i:null}function gY(n,e){let{parent:t,startIndex:r,endIndex:s}=n,i=t.child(r),o=e.contentMatch.findWrapping(i.type);if(!o)return null;let l=(o.length?o[o.length-1]:e).contentMatch;for(let c=r;l&&c<s;c++)l=l.matchType(t.child(c).type);return!l||!l.validEnd?null:o}function mY(n,e,t){let r=pe.empty;for(let o=t.length-1;o>=0;o--){if(r.size){let a=t[o].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=pe.from(t[o].type.create(t[o].attrs,r))}let s=e.start,i=e.end;n.step(new Bn(s,i,s,i,new Te(r,0,0),t.length,!0))}function yY(n,e,t,r,s){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=n.steps.length;n.doc.nodesBetween(e,t,(o,a)=>{let l=typeof s=="function"?s(o):s;if(o.isTextblock&&!o.hasMarkup(r,l)&&SY(n.doc,n.mapping.slice(i).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let m=r.whitespace=="pre",y=!!r.contentMatch.matchType(r.schema.linebreakReplacement);m&&!y?c=!1:!m&&y&&(c=!0)}c===!1&&IF(n,o,a,i),Fk(n,n.mapping.slice(i).map(a,1),r,void 0,c===null);let d=n.mapping.slice(i),f=d.map(a,1),p=d.map(a+o.nodeSize,1);return n.step(new Bn(f,p,f+1,p-1,new Te(pe.from(r.create(l,null,o.marks)),0,0),1,!0)),c===!0&&kF(n,o,a,i),!1}})}function kF(n,e,t,r){e.forEach((s,i)=>{if(s.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(s.text);){let l=n.mapping.slice(r).map(t+1+i+o.index);n.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function IF(n,e,t,r){e.forEach((s,i)=>{if(s.type==s.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+i);n.replaceWith(o,o+1,e.type.schema.text(`
89
+ `))}})}function SY(n,e,t){let r=n.resolve(e),s=r.index();return r.parent.canReplaceWith(s,s+1,t)}function vY(n,e,t,r,s){let i=n.doc.nodeAt(e);if(!i)throw new RangeError("No node at given position");t||(t=i.type);let o=t.create(r,null,s||i.marks);if(i.isLeaf)return n.replaceWith(e,e+i.nodeSize,o);if(!t.validContent(i.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Bn(e,e+i.nodeSize,e+1,e+i.nodeSize-1,new Te(pe.from(o),0,0),1,!0))}function Pa(n,e,t=1,r){let s=n.resolve(e),i=s.depth-t,o=r&&r[r.length-1]||s.parent;if(i<0||s.parent.type.spec.isolating||!s.parent.canReplace(s.index(),s.parent.childCount)||!o.type.validContent(s.parent.content.cutByIndex(s.index(),s.parent.childCount)))return!1;for(let c=s.depth-1,d=t-2;c>i;c--,d--){let f=s.node(c),p=s.index(c);if(f.type.spec.isolating)return!1;let m=f.content.cutByIndex(p,f.childCount),y=r&&r[d+1];y&&(m=m.replaceChild(0,y.type.create(y.attrs)));let v=r&&r[d]||f;if(!f.canReplace(p+1,f.childCount)||!v.type.validContent(m))return!1}let a=s.indexAfter(i),l=r&&r[0];return s.node(i).canReplaceWith(a,a,l?l.type:s.node(i+1).type)}function xY(n,e,t=1,r){let s=n.doc.resolve(e),i=pe.empty,o=pe.empty;for(let a=s.depth,l=s.depth-t,c=t-1;a>l;a--,c--){i=pe.from(s.node(a).copy(i));let d=r&&r[c];o=pe.from(d?d.type.create(d.attrs,o):s.node(a).copy(o))}n.step(new Fn(e,e,new Te(i.append(o),t,t),!0))}function Yl(n,e){let t=n.resolve(e),r=t.index();return _F(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function wY(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let s=0;s<e.childCount;s++){let i=e.child(s),o=i.type==r?n.type.schema.nodes.text:i.type;if(t=t.matchType(o),!t||!n.type.allowsMarks(i.marks))return!1}return t.validEnd}function _F(n,e){return!!(n&&e&&!n.isLeaf&&wY(n,e))}function xv(n,e,t=-1){let r=n.resolve(e);for(let s=r.depth;;s--){let i,o,a=r.index(s);if(s==r.depth?(i=r.nodeBefore,o=r.nodeAfter):t>0?(i=r.node(s+1),a++,o=r.node(s).maybeChild(a)):(i=r.node(s).maybeChild(a-1),o=r.node(s+1)),i&&!i.isTextblock&&_F(i,o)&&r.node(s).canReplace(a,a+1))return e;if(s==0)break;e=t<0?r.before(s):r.after(s)}}function bY(n,e,t){let r=null,{linebreakReplacement:s}=n.doc.type.schema,i=n.doc.resolve(e-t),o=i.node().type;if(s&&o.inlineContent){let d=o.whitespace=="pre",f=!!o.contentMatch.matchType(s);d&&!f?r=!1:!d&&f&&(r=!0)}let a=n.steps.length;if(r===!1){let d=n.doc.resolve(e+t);IF(n,d.node(),d.before(),a)}o.inlineContent&&Fk(n,e+t-1,o,i.node().contentMatchAt(i.index()),r==null);let l=n.mapping.slice(a),c=l.map(e-t);if(n.step(new Fn(c,l.map(e+t,-1),Te.empty,!0)),r===!0){let d=n.doc.resolve(c);kF(n,d.node(),d.before(),n.steps.length)}return n}function CY(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let s=r.depth-1;s>=0;s--){let i=r.index(s);if(r.node(s).canReplaceWith(i,i,t))return r.before(s+1);if(i>0)return null}if(r.parentOffset==r.parent.content.size)for(let s=r.depth-1;s>=0;s--){let i=r.indexAfter(s);if(r.node(s).canReplaceWith(i,i,t))return r.after(s+1);if(i<r.node(s).childCount)return null}return null}function TF(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let s=t.content;for(let i=0;i<t.openStart;i++)s=s.firstChild.content;for(let i=1;i<=(t.openStart==0&&t.size?2:1);i++)for(let o=r.depth;o>=0;o--){let a=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,l=r.index(o)+(a>0?1:0),c=r.node(o),d=!1;if(i==1)d=c.canReplace(l,l,s);else{let f=c.contentMatchAt(l).findWrapping(s.firstChild.type);d=f&&c.canReplaceWith(l,l,f[0])}if(d)return a==0?r.pos:a<0?r.before(o+1):r.after(o+1)}return null}function wv(n,e,t=e,r=Te.empty){if(e==t&&!r.size)return null;let s=n.resolve(e),i=n.resolve(t);return MF(s,i,r)?new Fn(e,t,r):new PY(s,i,r).fit()}function MF(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class PY{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=pe.empty;for(let s=0;s<=e.depth;s++){let i=e.node(s);this.frontier.push({type:i.type,match:i.contentMatchAt(e.indexAfter(s))})}for(let s=e.depth;s>0;s--)this.placed=pe.from(e.node(s).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,s=this.close(e<0?this.$to:r.doc.resolve(e));if(!s)return null;let i=this.placed,o=r.depth,a=s.depth;for(;o&&a&&i.childCount==1;)i=i.firstChild.content,o--,a--;let l=new Te(i,o,a);return e>-1?new Bn(r.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||r.pos!=this.$to.pos?new Fn(r.pos,s.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,s=this.unplaced.openEnd;r<e;r++){let i=t.firstChild;if(t.childCount>1&&(s=0),i.type.spec.isolating&&s<=r){e=r;break}t=i.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let s,i=null;r?(i=O1(this.unplaced.content,r-1).firstChild,s=i.content):s=this.unplaced.content;let o=s.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],d,f=null;if(t==1&&(o?c.matchType(o.type)||(f=c.fillBefore(pe.from(o),!1)):i&&l.compatibleContent(i.type)))return{sliceDepth:r,frontierDepth:a,parent:i,inject:f};if(t==2&&o&&(d=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:a,parent:i,wrap:d};if(i&&c.matchType(i.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,s=O1(e,t);return!s.childCount||s.firstChild.isLeaf?!1:(this.unplaced=new Te(e,t+1,Math.max(r,s.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,s=O1(e,t);if(s.childCount<=1&&t>0){let i=e.size-t<=t+s.size;this.unplaced=new Te(pf(e,t-1,1),t-1,i?t-1:r)}else this.unplaced=new Te(pf(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:s,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let v=0;v<i.length;v++)this.openFrontierNode(i[v]);let o=this.unplaced,a=r?r.content:o.content,l=o.openStart-e,c=0,d=[],{match:f,type:p}=this.frontier[t];if(s){for(let v=0;v<s.childCount;v++)d.push(s.child(v));f=f.matchFragment(s)}let m=a.size+e-(o.content.size-o.openEnd);for(;c<a.childCount;){let v=a.child(c),x=f.matchType(v.type);if(!x)break;c++,(c>1||l==0||v.content.size)&&(f=x,d.push(AF(v.mark(p.allowedMarks(v.marks)),c==1?l:0,c==a.childCount?m:-1)))}let y=c==a.childCount;y||(m=-1),this.placed=gf(this.placed,t,pe.from(d)),this.frontier[t].match=f,y&&m<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let v=0,x=a;v<m;v++){let b=x.lastChild;this.frontier.push({type:b.type,match:b.contentMatchAt(b.childCount)}),x=b.content}this.unplaced=y?e==0?Te.empty:new Te(pf(o.content,e-1,1),e-1,m<0?o.openEnd:e-1):new Te(pf(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!R1(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:r}=this.$to,s=this.$to.after(r);for(;r>1&&s==this.$to.end(--r);)++s;return s}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:s}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=R1(e,t,s,r,i);if(o){for(let a=t-1;a>=0;a--){let{match:l,type:c}=this.frontier[a],d=R1(e,a,c,l,!0);if(!d||d.childCount)continue e}return{depth:t,fit:o,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=gf(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let s=e.node(r),i=s.type.contentMatch.fillBefore(s.content,!0,e.index(r));this.openFrontierNode(s.type,s.attrs,i)}return e}openFrontierNode(e,t=null,r){let s=this.frontier[this.depth];s.match=s.match.matchType(e),this.placed=gf(this.placed,this.depth,pe.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(pe.empty,!0);t.childCount&&(this.placed=gf(this.placed,this.frontier.length,t))}}function pf(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(pf(n.firstChild.content,e-1,t)))}function gf(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(gf(n.lastChild.content,e-1,t)))}function O1(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function AF(n,e,t){if(e<=0)return n;let r=n.content;return e>1&&(r=r.replaceChild(0,AF(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(pe.empty,!0)))),n.copy(r)}function R1(n,e,t,r,s){let i=n.node(e),o=s?n.indexAfter(e):n.index(e);if(o==i.childCount&&!t.compatibleContent(i.type))return null;let a=r.fillBefore(i.content,!0,o);return a&&!EY(t,i.content,o)?a:null}function EY(n,e,t){for(let r=t;r<e.childCount;r++)if(!n.allowsMarks(e.child(r).marks))return!0;return!1}function kY(n){return n.spec.defining||n.spec.definingForContent}function IY(n,e,t,r){if(!r.size)return n.deleteRange(e,t);let s=n.doc.resolve(e),i=n.doc.resolve(t);if(MF(s,i,r))return n.step(new Fn(e,t,r));let o=RF(s,n.doc.resolve(t));o[o.length-1]==0&&o.pop();let a=-(s.depth+1);o.unshift(a);for(let p=s.depth,m=s.pos-1;p>0;p--,m--){let y=s.node(p).type.spec;if(y.defining||y.definingAsContext||y.isolating)break;o.indexOf(p)>-1?a=p:s.before(p)==m&&o.splice(1,0,-p)}let l=o.indexOf(a),c=[],d=r.openStart;for(let p=r.content,m=0;;m++){let y=p.firstChild;if(c.push(y),m==r.openStart)break;p=y.content}for(let p=d-1;p>=0;p--){let m=c[p],y=kY(m.type);if(y&&!m.sameMarkup(s.node(Math.abs(a)-1)))d=p;else if(y||!m.type.isTextblock)break}for(let p=r.openStart;p>=0;p--){let m=(p+d+1)%(r.openStart+1),y=c[m];if(y)for(let v=0;v<o.length;v++){let x=o[(v+l)%o.length],b=!0;x<0&&(b=!1,x=-x);let C=s.node(x-1),I=s.index(x-1);if(C.canReplaceWith(I,I,y.type,y.marks))return n.replace(s.before(x),b?i.after(x):t,new Te(OF(r.content,0,r.openStart,m),m,r.openEnd))}}let f=n.steps.length;for(let p=o.length-1;p>=0&&(n.replace(e,t,r),!(n.steps.length>f));p--){let m=o[p];m<0||(e=s.before(m),t=i.after(m))}}function OF(n,e,t,r,s){if(e<t){let i=n.firstChild;n=n.replaceChild(0,i.copy(OF(i.content,e+1,t,r,i)))}if(e>r){let i=s.contentMatchAt(0),o=i.fillBefore(n).append(n);n=o.append(i.matchFragment(o).fillBefore(pe.empty,!0))}return n}function _Y(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let s=CY(n.doc,e,r.type);s!=null&&(e=t=s)}n.replaceRange(e,t,new Te(pe.from(r),0,0))}function TY(n,e,t){let r=n.doc.resolve(e),s=n.doc.resolve(t),i=RF(r,s);for(let o=0;o<i.length;o++){let a=i[o],l=o==i.length-1;if(l&&a==0||r.node(a).type.contentMatch.validEnd)return n.delete(r.start(a),s.end(a));if(a>0&&(l||r.node(a-1).canReplace(r.index(a-1),s.indexAfter(a-1))))return n.delete(r.before(a),s.after(a))}for(let o=1;o<=r.depth&&o<=s.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&s.end(o)-t!=s.depth-o&&r.start(o-1)==s.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),s.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function RF(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let s=r;s>=0;s--){let i=n.start(s);if(i<n.pos-(n.depth-s)||e.end(s)>e.pos+(e.depth-s)||n.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(i==e.start(s)||s==n.depth&&s==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==i-1)&&t.push(s)}return t}class Pd extends Ir{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return kn.fail("No node at attribute step's position");let r=Object.create(null);for(let i in t.attrs)r[i]=t.attrs[i];r[this.attr]=this.value;let s=t.type.create(r,null,t.marks);return kn.fromReplace(e,this.pos,this.pos+1,new Te(pe.from(s),0,t.isLeaf?0:1))}getMap(){return Ns.empty}invert(e){return new Pd(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Pd(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Pd(t.pos,t.attr,t.value)}}Ir.jsonID("attr",Pd);class Qf extends Ir{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let s in e.attrs)t[s]=e.attrs[s];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return kn.ok(r)}getMap(){return Ns.empty}invert(e){return new Qf(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Qf(t.attr,t.value)}}Ir.jsonID("docAttr",Qf);let Ld=class extends Error{};Ld=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Ld.prototype=Object.create(Error.prototype);Ld.prototype.constructor=Ld;Ld.prototype.name="TransformError";class DF{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Jf}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Ld(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=Te.empty){let s=wv(this.doc,e,t,r);return s&&this.step(s),this}replaceWith(e,t,r){return this.replace(e,t,new Te(pe.from(r),0,0))}delete(e,t){return this.replace(e,t,Te.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return IY(this,e,t,r),this}replaceRangeWith(e,t,r){return _Y(this,e,t,r),this}deleteRange(e,t){return TY(this,e,t),this}lift(e,t){return fY(this,e,t),this}join(e,t=1){return bY(this,e,t),this}wrap(e,t){return mY(this,e,t),this}setBlockType(e,t=e,r,s=null){return yY(this,e,t,r,s),this}setNodeMarkup(e,t,r=null,s){return vY(this,e,t,r,s),this}setNodeAttribute(e,t,r){return this.step(new Pd(e,t,r)),this}setDocAttribute(e,t){return this.step(new Qf(e,t)),this}addNodeMark(e,t){return this.step(new Tl(e,t)),this}removeNodeMark(e,t){if(!(t instanceof Lt)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Nd(e,t)),this}split(e,t=1,r){return xY(this,e,t,r),this}addMark(e,t,r){return uY(this,e,t,r),this}removeMark(e,t,r){return dY(this,e,t,r),this}clearIncompatible(e,t,r){return Fk(this,e,t,r),this}}const D1=Object.create(null);class at{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new MY(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=Te.empty){let r=t.content.lastChild,s=null;for(let a=0;a<t.openEnd;a++)s=r,r=r.lastChild;let i=e.steps.length,o=this.ranges;for(let a=0;a<o.length;a++){let{$from:l,$to:c}=o[a],d=e.mapping.slice(i);e.replaceRange(d.map(l.pos),d.map(c.pos),a?Te.empty:t),a==0&&YR(e,i,(r?r.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,s=this.ranges;for(let i=0;i<s.length;i++){let{$from:o,$to:a}=s[i],l=e.mapping.slice(r),c=l.map(o.pos),d=l.map(a.pos);i?e.deleteRange(c,d):(e.replaceRangeWith(c,d,t),YR(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let s=e.parent.inlineContent?new rt(e):dd(e.node(0),e.parent,e.pos,e.index(),t,r);if(s)return s;for(let i=e.depth-1;i>=0;i--){let o=t<0?dd(e.node(0),e.node(i),e.before(i+1),e.index(i),t,r):dd(e.node(0),e.node(i),e.after(i+1),e.index(i)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Bs(e.node(0))}static atStart(e){return dd(e,e,0,0,1)||new Bs(e)}static atEnd(e){return dd(e,e,e.content.size,e.childCount,-1)||new Bs(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=D1[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in D1)throw new RangeError("Duplicate use of selection JSON ID "+e);return D1[e]=t,t.prototype.jsonID=e,t}getBookmark(){return rt.between(this.$anchor,this.$head).getBookmark()}}at.prototype.visible=!0;class MY{constructor(e,t){this.$from=e,this.$to=t}}let qR=!1;function GR(n){!qR&&!n.parent.inlineContent&&(qR=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class rt extends at{constructor(e,t=e){GR(e),GR(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return at.near(r);let s=e.resolve(t.map(this.anchor));return new rt(s.parent.inlineContent?s:r,r)}replace(e,t=Te.empty){if(super.replace(e,t),t==Te.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof rt&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new bv(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new rt(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let s=e.resolve(t);return new this(s,r==t?s:e.resolve(r))}static between(e,t,r){let s=e.pos-t.pos;if((!r||s)&&(r=s>=0?1:-1),!t.parent.inlineContent){let i=at.findFrom(t,r,!0)||at.findFrom(t,-r,!0);if(i)t=i.$head;else return at.near(t,r)}return e.parent.inlineContent||(s==0?e=t:(e=(at.findFrom(e,-r,!0)||at.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=s<0&&(e=t))),new rt(e,t)}}at.jsonID("text",rt);class bv{constructor(e,t){this.anchor=e,this.head=t}map(e){return new bv(e.map(this.anchor),e.map(this.head))}resolve(e){return rt.between(e.resolve(this.anchor),e.resolve(this.head))}}class We extends at{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:s}=t.mapResult(this.anchor),i=e.resolve(s);return r?at.near(i):new We(i)}content(){return new Te(pe.from(this.node),0,0)}eq(e){return e instanceof We&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new $k(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new We(e.resolve(t.anchor))}static create(e,t){return new We(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}We.prototype.visible=!1;at.jsonID("node",We);class $k{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new bv(r,r):new $k(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&We.isSelectable(r)?new We(t):at.near(t)}}class Bs extends at{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Te.empty){if(t==Te.empty){e.delete(0,e.doc.content.size);let r=at.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Bs(e)}map(e){return new Bs(e)}eq(e){return e instanceof Bs}getBookmark(){return AY}}at.jsonID("all",Bs);const AY={map(){return this},resolve(n){return new Bs(n)}};function dd(n,e,t,r,s,i=!1){if(e.inlineContent)return rt.create(n,t);for(let o=r-(s>0?0:1);s>0?o<e.childCount:o>=0;o+=s){let a=e.child(o);if(a.isAtom){if(!i&&We.isSelectable(a))return We.create(n,t-(s<0?a.nodeSize:0))}else{let l=dd(n,a,t+s,s<0?a.childCount:0,s,i);if(l)return l}t+=a.nodeSize*s}return null}function YR(n,e,t){let r=n.steps.length-1;if(r<e)return;let s=n.steps[r];if(!(s instanceof Fn||s instanceof Bn))return;let i=n.mapping.maps[r],o;i.forEach((a,l,c,d)=>{o==null&&(o=d)}),n.setSelection(at.near(n.doc.resolve(o),t))}const XR=1,ZR=2,JR=4;class OY extends DF{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|XR)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&XR)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=ZR,this}ensureMarks(e){return Lt.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&ZR)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||Lt.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let s=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(s.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let i=this.storedMarks;if(!i){let o=this.doc.resolve(t);i=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,s.text(e,i)),this.selection.empty||this.setSelection(at.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=JR,this}get scrolledIntoView(){return(this.updated&JR)>0}}function QR(n,e){return!e||!n?n:n.bind(e)}class mf{constructor(e,t,r){this.name=e,this.init=QR(t.init,r),this.apply=QR(t.apply,r)}}const RY=[new mf("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new mf("selection",{init(n,e){return n.selection||at.atStart(e.doc)},apply(n){return n.selection}}),new mf("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new mf("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class j1{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=RY.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new mf(r.key,r.spec.state,r))})}}class vd{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=t){let s=this.config.plugins[r];if(s.spec.filterTransaction&&!s.spec.filterTransaction.call(s,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],r=this.applyInner(e),s=null;for(;;){let i=!1;for(let o=0;o<this.config.plugins.length;o++){let a=this.config.plugins[o];if(a.spec.appendTransaction){let l=s?s[o].n:0,c=s?s[o].state:this,d=l<t.length&&a.spec.appendTransaction.call(a,l?t.slice(l):t,c,r);if(d&&r.filterTransaction(d,o)){if(d.setMeta("appendedTransaction",e),!s){s=[];for(let f=0;f<this.config.plugins.length;f++)s.push(f<o?{state:r,n:t.length}:{state:this,n:0})}t.push(d),r=r.applyInner(d),i=!0}s&&(s[o]={state:r,n:t.length})}}if(!i)return{state:r,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new vd(this.config),r=this.config.fields;for(let s=0;s<r.length;s++){let i=r[s];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new OY(this)}static create(e){let t=new j1(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new vd(t);for(let s=0;s<t.fields.length;s++)r[t.fields[s].name]=t.fields[s].init(e,r);return r}reconfigure(e){let t=new j1(this.schema,e.plugins),r=t.fields,s=new vd(t);for(let i=0;i<r.length;i++){let o=r[i].name;s[o]=this.hasOwnProperty(o)?this[o]:r[i].init(e,s)}return s}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(r=>r.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=e[r],i=s.spec.state;i&&i.toJSON&&(t[r]=i.toJSON.call(s,this[s.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let s=new j1(e.schema,e.plugins),i=new vd(s);return s.fields.forEach(o=>{if(o.name=="doc")i.doc=Gi.fromJSON(e.schema,t.doc);else if(o.name=="selection")i.selection=at.fromJSON(i.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let l=r[a],c=l.spec.state;if(l.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,a)){i[o.name]=c.fromJSON.call(l,e,t[a],i);return}}i[o.name]=o.init(e,i)}}),i}}function jF(n,e,t){for(let r in n){let s=n[r];s instanceof Function?s=s.bind(e):r=="handleDOMEvents"&&(s=jF(s,e,{})),t[r]=s}return t}class lr{constructor(e){this.spec=e,this.props={},e.props&&jF(e.props,this,this.props),this.key=e.key?e.key.key:NF("plugin")}getState(e){return e[this.key]}}const N1=Object.create(null);function NF(n){return n in N1?n+"$"+ ++N1[n]:(N1[n]=0,n+"$")}class qs{constructor(e="key"){this.key=NF(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const er=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Fd=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let NP=null;const ma=function(n,e,t){let r=NP||(NP=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},DY=function(){NP=null},qc=function(n,e,t,r){return t&&(eD(n,e,t,r,-1)||eD(n,e,t,r,1))},jY=/^(img|br|input|textarea|hr)$/i;function eD(n,e,t,r,s){for(;;){if(n==t&&e==r)return!0;if(e==(s<0?0:fi(n))){let i=n.parentNode;if(!i||i.nodeType!=1||_p(n)||jY.test(n.nodeName)||n.contentEditable=="false")return!1;e=er(n)+(s<0?0:1),n=i}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.contentEditable=="false")return!1;e=s<0?fi(n):0}else return!1}}function fi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function NY(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=fi(n)}else if(n.parentNode&&!_p(n))e=er(n),n=n.parentNode;else return null}}function LY(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!_p(n))e=er(n)+1,n=n.parentNode;else return null}}function FY(n,e,t){for(let r=e==0,s=e==fi(n);r||s;){if(n==t)return!0;let i=er(n);if(n=n.parentNode,!n)return!1;r=r&&i==0,s=s&&i==fi(n)}}function _p(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const Cv=function(n){return n.focusNode&&qc(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Tc(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function zY(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function $Y(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(fi(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(fi(r.startContainer),r.startOffset)}}}const jo=typeof navigator<"u"?navigator:null,tD=typeof document<"u"?document:null,Xl=jo&&jo.userAgent||"",LP=/Edge\/(\d+)/.exec(Xl),LF=/MSIE \d/.exec(Xl),FP=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Xl),bs=!!(LF||FP||LP),Ol=LF?document.documentMode:FP?+FP[1]:LP?+LP[1]:0,Zi=!bs&&/gecko\/(\d+)/i.test(Xl);Zi&&+(/Firefox\/(\d+)/.exec(Xl)||[0,0])[1];const zP=!bs&&/Chrome\/(\d+)/.exec(Xl),Pr=!!zP,FF=zP?+zP[1]:0,$r=!bs&&!!jo&&/Apple Computer/.test(jo.vendor),zd=$r&&(/Mobile\/\w+/.test(Xl)||!!jo&&jo.maxTouchPoints>2),ui=zd||(jo?/Mac/.test(jo.platform):!1),BY=jo?/Win/.test(jo.platform):!1,xa=/Android \d/.test(Xl),Tp=!!tD&&"webkitFontSmoothing"in tD.documentElement.style,UY=Tp?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function HY(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function la(n,e){return typeof n=="number"?n:n[e]}function KY(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function nD(n,e,t){let r=n.someProp("scrollThreshold")||0,s=n.someProp("scrollMargin")||5,i=n.dom.ownerDocument;for(let o=t||n.dom;o;){if(o.nodeType!=1){o=Fd(o);continue}let a=o,l=a==i.body,c=l?HY(i):KY(a),d=0,f=0;if(e.top<c.top+la(r,"top")?f=-(c.top-e.top+la(s,"top")):e.bottom>c.bottom-la(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+la(s,"top")-c.top:e.bottom-c.bottom+la(s,"bottom")),e.left<c.left+la(r,"left")?d=-(c.left-e.left+la(s,"left")):e.right>c.right-la(r,"right")&&(d=e.right-c.right+la(s,"right")),d||f)if(l)i.defaultView.scrollBy(d,f);else{let m=a.scrollLeft,y=a.scrollTop;f&&(a.scrollTop+=f),d&&(a.scrollLeft+=d);let v=a.scrollLeft-m,x=a.scrollTop-y;e={left:e.left-v,top:e.top-x,right:e.right-v,bottom:e.bottom-x}}let p=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(p))break;o=p=="absolute"?o.offsetParent:Fd(o)}}function WY(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,s;for(let i=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let a=n.root.elementFromPoint(i,o);if(!a||a==n.dom||!n.dom.contains(a))continue;let l=a.getBoundingClientRect();if(l.top>=t-20){r=a,s=l.top;break}}return{refDOM:r,refTop:s,stack:zF(n.dom)}}function zF(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Fd(r));return e}function VY({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;$F(t,r==0?0:r-e)}function $F(n,e){for(let t=0;t<n.length;t++){let{dom:r,top:s,left:i}=n[t];r.scrollTop!=s+e&&(r.scrollTop=s+e),r.scrollLeft!=i&&(r.scrollLeft=i)}}let ed=null;function qY(n){if(n.setActive)return n.setActive();if(ed)return n.focus(ed);let e=zF(n);n.focus(ed==null?{get preventScroll(){return ed={preventScroll:!0},!0}}:void 0),ed||(ed=!1,$F(e,0))}function BF(n,e){let t,r=2e8,s,i=0,o=e.top,a=e.top,l,c;for(let d=n.firstChild,f=0;d;d=d.nextSibling,f++){let p;if(d.nodeType==1)p=d.getClientRects();else if(d.nodeType==3)p=ma(d).getClientRects();else continue;for(let m=0;m<p.length;m++){let y=p[m];if(y.top<=o&&y.bottom>=a){o=Math.max(y.bottom,o),a=Math.min(y.top,a);let v=y.left>e.left?y.left-e.left:y.right<e.left?e.left-y.right:0;if(v<r){t=d,r=v,s=v&&t.nodeType==3?{left:y.right<e.left?y.right:y.left,top:e.top}:e,d.nodeType==1&&v&&(i=f+(e.left>=(y.left+y.right)/2?1:0));continue}}else y.top>e.top&&!l&&y.left<=e.left&&y.right>=e.left&&(l=d,c={left:Math.max(y.left,Math.min(y.right,e.left)),top:y.top});!t&&(e.left>=y.right&&e.top>=y.top||e.left>=y.left&&e.top>=y.bottom)&&(i=f+1)}}return!t&&l&&(t=l,s=c,r=0),t&&t.nodeType==3?GY(t,s):!t||r&&t.nodeType==1?{node:n,offset:i}:BF(t,s)}function GY(n,e){let t=n.nodeValue.length,r=document.createRange();for(let s=0;s<t;s++){r.setEnd(n,s+1),r.setStart(n,s);let i=gl(r,1);if(i.top!=i.bottom&&Bk(e,i))return{node:n,offset:s+(e.left>=(i.left+i.right)/2?1:0)}}return{node:n,offset:0}}function Bk(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function YY(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function XY(n,e,t){let{node:r,offset:s}=BF(e,t),i=-1;if(r.nodeType==1&&!r.firstChild){let o=r.getBoundingClientRect();i=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,s,i)}function ZY(n,e,t,r){let s=-1;for(let i=e,o=!1;i!=n.dom;){let a=n.docView.nearestDesc(i,!0),l;if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)&&((l=a.dom.getBoundingClientRect()).width||l.height)&&(a.node.isBlock&&a.parent&&(!o&&l.left>r.left||l.top>r.top?s=a.posBefore:(!o&&l.right<r.left||l.bottom<r.top)&&(s=a.posAfter),o=!0),!a.contentDOM&&s<0&&!a.node.isText))return(a.node.isBlock?r.top<(l.top+l.bottom)/2:r.left<(l.left+l.right)/2)?a.posBefore:a.posAfter;i=a.dom.parentNode}return s>-1?s:n.docView.posFromDOM(e,t,-1)}function UF(n,e,t){let r=n.childNodes.length;if(r&&t.top<t.bottom)for(let s=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-t.top)/(t.bottom-t.top))-2)),i=s;;){let o=n.childNodes[i];if(o.nodeType==1){let a=o.getClientRects();for(let l=0;l<a.length;l++){let c=a[l];if(Bk(e,c))return UF(o,e,c)}}if((i=(i+1)%r)==s)break}return n}function JY(n,e){let t=n.dom.ownerDocument,r,s=0,i=$Y(t,e.left,e.top);i&&({node:r,offset:s}=i);let o=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),a;if(!o||!n.dom.contains(o.nodeType!=1?o.parentNode:o)){let c=n.dom.getBoundingClientRect();if(!Bk(e,c)||(o=UF(n.dom,e,c),!o))return null}if($r)for(let c=o;r&&c;c=Fd(c))c.draggable&&(r=void 0);if(o=YY(o,e),r){if(Zi&&r.nodeType==1&&(s=Math.min(s,r.childNodes.length),s<r.childNodes.length)){let d=r.childNodes[s],f;d.nodeName=="IMG"&&(f=d.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&s++}let c;Tp&&s&&r.nodeType==1&&(c=r.childNodes[s-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&s--,r==n.dom&&s==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=n.state.doc.content.size:(s==0||r.nodeType!=1||r.childNodes[s-1].nodeName!="BR")&&(a=ZY(n,r,s,e))}a==null&&(a=XY(n,o,e));let l=n.docView.nearestDesc(o,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function rD(n){return n.top<n.bottom||n.left<n.right}function gl(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(rD(r))return r}return Array.prototype.find.call(t,rD)||n.getBoundingClientRect()}const QY=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function HF(n,e,t){let{node:r,offset:s,atom:i}=n.docView.domFromPos(e,t<0?-1:1),o=Tp||Zi;if(r.nodeType==3)if(o&&(QY.test(r.nodeValue)||(t<0?!s:s==r.nodeValue.length))){let l=gl(ma(r,s,s),t);if(Zi&&s&&/\s/.test(r.nodeValue[s-1])&&s<r.nodeValue.length){let c=gl(ma(r,s-1,s-1),-1);if(c.top==l.top){let d=gl(ma(r,s,s+1),-1);if(d.top!=l.top)return Jh(d,d.left<c.left)}}return l}else{let l=s,c=s,d=t<0?1:-1;return t<0&&!s?(c++,d=-1):t>=0&&s==r.nodeValue.length?(l--,d=1):t<0?l--:c++,Jh(gl(ma(r,l,c),d),d<0)}if(!n.state.doc.resolve(e-(i||0)).parent.inlineContent){if(i==null&&s&&(t<0||s==fi(r))){let l=r.childNodes[s-1];if(l.nodeType==1)return L1(l.getBoundingClientRect(),!1)}if(i==null&&s<fi(r)){let l=r.childNodes[s];if(l.nodeType==1)return L1(l.getBoundingClientRect(),!0)}return L1(r.getBoundingClientRect(),t>=0)}if(i==null&&s&&(t<0||s==fi(r))){let l=r.childNodes[s-1],c=l.nodeType==3?ma(l,fi(l)-(o?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return Jh(gl(c,1),!1)}if(i==null&&s<fi(r)){let l=r.childNodes[s];for(;l.pmViewDesc&&l.pmViewDesc.ignoreForCoords;)l=l.nextSibling;let c=l?l.nodeType==3?ma(l,0,o?0:1):l.nodeType==1?l:null:null;if(c)return Jh(gl(c,-1),!0)}return Jh(gl(r.nodeType==3?ma(r):r,-t),t>=0)}function Jh(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function L1(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function KF(n,e,t){let r=n.state,s=n.root.activeElement;r!=e&&n.updateState(e),s!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),s!=n.dom&&s&&s.focus()}}function eX(n,e,t){let r=e.selection,s=t=="up"?r.$from:r.$to;return KF(n,e,()=>{let{node:i}=n.docView.domFromPos(s.pos,t=="up"?-1:1);for(;;){let a=n.docView.nearestDesc(i,!0);if(!a)break;if(a.node.isBlock){i=a.contentDOM||a.dom;break}i=a.dom.parentNode}let o=HF(n,s.pos,1);for(let a=i.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=ma(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;c<l.length;c++){let d=l[c];if(d.bottom>d.top+1&&(t=="up"?o.top-d.top>(d.bottom-o.top)*2:d.bottom-o.bottom>(o.bottom-d.top)*2))return!1}}return!0})}const tX=/[\u0590-\u08ac]/;function nX(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let s=r.parentOffset,i=!s,o=s==r.parent.content.size,a=n.domSelection();return a?!tX.test(r.parent.textContent)||!a.modify?t=="left"||t=="backward"?i:o:KF(n,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:d,anchorOffset:f}=n.domSelectionRange(),p=a.caretBidiLevel;a.modify("move",t,"character");let m=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:y,focusOffset:v}=n.domSelectionRange(),x=y&&!m.contains(y.nodeType==1?y:y.parentNode)||l==y&&c==v;try{a.collapse(d,f),l&&(l!=d||c!=f)&&a.extend&&a.extend(l,c)}catch{}return p!=null&&(a.caretBidiLevel=p),x}):r.pos==r.start()||r.pos==r.end()}let sD=null,iD=null,oD=!1;function rX(n,e,t){return sD==e&&iD==t?oD:(sD=e,iD=t,oD=t=="up"||t=="down"?eX(n,e,t):nX(n,e,t))}const vi=0,aD=1,Ac=2,No=3;class Mp{constructor(e,t,r,s){this.parent=e,this.children=t,this.dom=r,this.contentDOM=s,this.dirty=vi,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,r=this.posAtStart;;t++){let s=this.children[t];if(s==e)return r;r+=s.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,r){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(r<0){let i,o;if(e==this.contentDOM)i=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;i=e.previousSibling}for(;i&&!((o=i.pmViewDesc)&&o.parent==this);)i=i.previousSibling;return i?this.posBeforeChild(o)+o.size:this.posAtStart}else{let i,o;if(e==this.contentDOM)i=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;i=e.nextSibling}for(;i&&!((o=i.pmViewDesc)&&o.parent==this);)i=i.nextSibling;return i?this.posBeforeChild(o):this.posAtEnd}let s;if(e==this.dom&&this.contentDOM)s=t>er(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let i=e;;i=i.parentNode){if(i==this.dom){s=!1;break}if(i.previousSibling)break}if(s==null&&t==e.childNodes.length)for(let i=e;;i=i.parentNode){if(i==this.dom){s=!0;break}if(i.nextSibling)break}}return s??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,s=e;s;s=s.parentNode){let i=this.getDesc(s),o;if(i&&(!t||i.node))if(r&&(o=i.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return i}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let s=e;s;s=s.parentNode){let i=this.getDesc(s);if(i)return i.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;t<this.children.length;t++){let s=this.children[t],i=r+s.size;if(r==e&&i!=r){for(;!s.border&&s.children.length;)for(let o=0;o<s.children.length;o++){let a=s.children[o];if(a.size){s=a;break}}return s}if(e<i)return s.descAt(e-r-s.border);r=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,s=0;for(let i=0;r<this.children.length;r++){let o=this.children[r],a=i+o.size;if(a>e||o instanceof VF){s=e-i;break}i=a}if(s)return this.children[r].domFromPos(s-this.children[r].border,t);for(let i;r&&!(i=this.children[r-1]).size&&i instanceof WF&&i.side>=0;r--);if(t<=0){let i,o=!0;for(;i=r?this.children[r-1]:null,!(!i||i.dom.parentNode==this.contentDOM);r--,o=!1);return i&&t&&o&&!i.border&&!i.domAtom?i.domFromPos(i.size,t):{node:this.contentDOM,offset:i?er(i.dom)+1:0}}else{let i,o=!0;for(;i=r<this.children.length?this.children[r]:null,!(!i||i.dom.parentNode==this.contentDOM);r++,o=!1);return i&&o&&!i.border&&!i.domAtom?i.domFromPos(0,t):{node:this.contentDOM,offset:i?er(i.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,i=-1;for(let o=r,a=0;;a++){let l=this.children[a],c=o+l.size;if(s==-1&&e<=c){let d=o+l.border;if(e>=d&&t<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,t,d);e=o;for(let f=a;f>0;f--){let p=this.children[f-1];if(p.size&&p.dom.parentNode==this.contentDOM&&!p.emptyChildAt(1)){s=er(p.dom)+1;break}e-=p.size}s==-1&&(s=0)}if(s>-1&&(c>t||a==this.children.length-1)){t=c;for(let d=a+1;d<this.children.length;d++){let f=this.children[d];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){i=er(f.dom);break}t+=f.size}i==-1&&(i=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:s,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:r}=this.domFromPos(e,0);if(t.nodeType!=1||r==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[r]}setSelection(e,t,r,s=!1){let i=Math.min(e,t),o=Math.max(e,t);for(let m=0,y=0;m<this.children.length;m++){let v=this.children[m],x=y+v.size;if(i>y&&o<x)return v.setSelection(e-y-v.border,t-y-v.border,r,s);y=x}let a=this.domFromPos(e,e?-1:1),l=t==e?a:this.domFromPos(t,t?-1:1),c=r.root.getSelection(),d=r.domSelectionRange(),f=!1;if((Zi||$r)&&e==t){let{node:m,offset:y}=a;if(m.nodeType==3){if(f=!!(y&&m.nodeValue[y-1]==`
90
+ `),f&&y==m.nodeValue.length)for(let v=m,x;v;v=v.parentNode){if(x=v.nextSibling){x.nodeName=="BR"&&(a=l={node:x.parentNode,offset:er(x)+1});break}let b=v.pmViewDesc;if(b&&b.node&&b.node.isBlock)break}}else{let v=m.childNodes[y-1];f=v&&(v.nodeName=="BR"||v.contentEditable=="false")}}if(Zi&&d.focusNode&&d.focusNode!=l.node&&d.focusNode.nodeType==1){let m=d.focusNode.childNodes[d.focusOffset];m&&m.contentEditable=="false"&&(s=!0)}if(!(s||f&&$r)&&qc(a.node,a.offset,d.anchorNode,d.anchorOffset)&&qc(l.node,l.offset,d.focusNode,d.focusOffset))return;let p=!1;if((c.extend||e==t)&&!f){c.collapse(a.node,a.offset);try{e!=t&&c.extend(l.node,l.offset),p=!0}catch{}}if(!p){if(e>t){let y=a;a=l,l=y}let m=document.createRange();m.setEnd(l.node,l.offset),m.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(m)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,s=0;s<this.children.length;s++){let i=this.children[s],o=r+i.size;if(r==o?e<=o&&t>=r:e<o&&t>r){let a=r+i.border,l=o-i.border;if(e>=a&&t<=l){this.dirty=e==r||t==o?Ac:aD,e==a&&t==l&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=No:i.markDirty(e-a,t-a);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?Ac:No}r=o}this.dirty=Ac}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Ac:aD;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class WF extends Mp{constructor(e,t,r,s){let i,o=t.type.toDOM;if(typeof o=="function"&&(o=o(r,()=>{if(!i)return s;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){if(o.nodeType!=1){let a=document.createElement("span");a.appendChild(o),o=a}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==vi&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class sX extends Mp{constructor(e,t,r,s){super(e,[],t,null),this.textDOM=r,this.text=s}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Gc extends Mp{constructor(e,t,r,s,i){super(e,[],r,s),this.mark=t,this.spec=i}static create(e,t,r,s){let i=s.nodeViews[t.type.name],o=i&&i(t,s,r);return(!o||!o.dom)&&(o=hu.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Gc(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&No||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=No&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=vi){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=vi}}slice(e,t,r){let s=Gc.create(this.parent,this.mark,!0,r),i=this.children,o=this.size;t<o&&(i=BP(i,t,o,r)),e>0&&(i=BP(i,0,e,r));for(let a=0;a<i.length;a++)i[a].parent=s;return s.children=i,s}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Rl extends Mp{constructor(e,t,r,s,i,o,a,l,c){super(e,[],i,o),this.node=t,this.outerDeco=r,this.innerDeco=s,this.nodeDOM=a}static create(e,t,r,s,i,o){let a=i.nodeViews[t.type.name],l,c=a&&a(t,i,()=>{if(!l)return o;if(l.parent)return l.parent.posBeforeChild(l)},r,s),d=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!d)d=document.createTextNode(t.text);else if(d.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else d||({dom:d,contentDOM:f}=hu.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&d.nodeName!="BR"&&(d.hasAttribute("contenteditable")||(d.contentEditable="false"),t.type.spec.draggable&&(d.draggable=!0));let p=d;return d=YF(d,r,t),c?l=new iX(e,t,r,s,d,f||null,p,c,i,o+1):t.isText?new Pv(e,t,r,s,d,p,i):new Rl(e,t,r,s,d,f||null,p,i,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>pe.empty)}return e}matchesNode(e,t,r){return this.dirty==vi&&e.eq(this.node)&&qy(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,s=t,i=e.composing?this.localCompositionInfo(e,t):null,o=i&&i.pos>-1?i:null,a=i&&i.pos<0,l=new aX(this,o&&o.node,e);uX(this.node,this.innerDeco,(c,d,f)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!f&&l.syncToMarks(d==this.node.childCount?Lt.none:this.node.child(d).marks,r,e),l.placeWidget(c,e,s)},(c,d,f,p)=>{l.syncToMarks(c.marks,r,e);let m;l.findNodeMatch(c,d,f,p)||a&&e.state.selection.from>s&&e.state.selection.to<s+c.nodeSize&&(m=l.findIndexWithChild(i.node))>-1&&l.updateNodeAt(c,d,f,m,e)||l.updateNextNode(c,d,f,e,p,s)||l.addNode(c,d,f,e,s),s+=c.nodeSize}),l.syncToMarks([],r,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==Ac)&&(o&&this.protectLocalComposition(e,o),qF(this.contentDOM,this.children,e),zd&&dX(this.dom))}localCompositionInfo(e,t){let{from:r,to:s}=e.state.selection;if(!(e.state.selection instanceof rt)||r<t||s>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let o=i.nodeValue,a=hX(this.node.content,o,r-t,s-t);return a<0?null:{node:i,pos:a,text:o}}else return{node:i,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:s}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let o=new sX(this,i,t,s);e.input.compositionNodes.push(o),this.children=BP(this.children,r,r+s.length,e,o)}update(e,t,r,s){return this.dirty==No||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,s),!0)}updateInner(e,t,r,s){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=vi}updateOuterDeco(e){if(qy(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=GF(this.dom,this.nodeDOM,$P(this.outerDeco,this.node,t),$P(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function lD(n,e,t,r,s){YF(r,e,n);let i=new Rl(void 0,n,e,t,r,r,r,s,0);return i.contentDOM&&i.updateChildren(s,0),i}class Pv extends Rl{constructor(e,t,r,s,i,o,a){super(e,t,r,s,i,null,o,a,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,s){return this.dirty==No||this.dirty!=vi&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=vi||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,s.trackWrites==this.nodeDOM&&(s.trackWrites=null)),this.node=e,this.dirty=vi,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let s=this.node.cut(e,t),i=document.createTextNode(s.text);return new Pv(this.parent,s,this.outerDeco,this.innerDeco,i,i,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=No)}get domAtom(){return!1}isText(e){return this.node.text==e}}class VF extends Mp{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==vi&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class iX extends Rl{constructor(e,t,r,s,i,o,a,l,c,d){super(e,t,r,s,i,o,a,c,d),this.spec=l}update(e,t,r,s){if(this.dirty==No)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,r);return i&&this.updateInner(e,t,r,s),i}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,s){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,r,s)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function qF(n,e,t){let r=n.firstChild,s=!1;for(let i=0;i<e.length;i++){let o=e[i],a=o.dom;if(a.parentNode==n){for(;a!=r;)r=cD(r),s=!0;r=r.nextSibling}else s=!0,n.insertBefore(a,r);if(o instanceof Gc){let l=r?r.previousSibling:n.lastChild;qF(o.contentDOM,o.children,t),r=l?l.nextSibling:n.firstChild}}for(;r;)r=cD(r),s=!0;s&&t.trackWrites==n&&(t.trackWrites=null)}const Tf=function(n){n&&(this.nodeName=n)};Tf.prototype=Object.create(null);const Oc=[new Tf];function $P(n,e,t){if(n.length==0)return Oc;let r=t?Oc[0]:new Tf,s=[r];for(let i=0;i<n.length;i++){let o=n[i].type.attrs;if(o){o.nodeName&&s.push(r=new Tf(o.nodeName));for(let a in o){let l=o[a];l!=null&&(t&&s.length==1&&s.push(r=new Tf(e.isInline?"span":"div")),a=="class"?r.class=(r.class?r.class+" ":"")+l:a=="style"?r.style=(r.style?r.style+";":"")+l:a!="nodeName"&&(r[a]=l))}}}return s}function GF(n,e,t,r){if(t==Oc&&r==Oc)return e;let s=e;for(let i=0;i<r.length;i++){let o=r[i],a=t[i];if(i){let l;a&&a.nodeName==o.nodeName&&s!=n&&(l=s.parentNode)&&l.nodeName.toLowerCase()==o.nodeName||(l=document.createElement(o.nodeName),l.pmIsDeco=!0,l.appendChild(s),a=Oc[0]),s=l}oX(s,a||Oc[0],o)}return s}function oX(n,e,t){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in t)&&n.removeAttribute(r);for(let r in t)r!="class"&&r!="style"&&r!="nodeName"&&t[r]!=e[r]&&n.setAttribute(r,t[r]);if(e.class!=t.class){let r=e.class?e.class.split(" ").filter(Boolean):[],s=t.class?t.class.split(" ").filter(Boolean):[];for(let i=0;i<r.length;i++)s.indexOf(r[i])==-1&&n.classList.remove(r[i]);for(let i=0;i<s.length;i++)r.indexOf(s[i])==-1&&n.classList.add(s[i]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,s;for(;s=r.exec(e.style);)n.style.removeProperty(s[1])}t.style&&(n.style.cssText+=t.style)}}function YF(n,e,t){return GF(n,n,Oc,$P(e,t,n.nodeType!=1))}function qy(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function cD(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class aX{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=lX(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let r=e;r<t;r++)this.top.children[r].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,r){let s=0,i=this.stack.length>>1,o=Math.min(i,e.length);for(;s<o&&(s==i-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<i;)this.destroyRest(),this.top.dirty=vi,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let a=-1;for(let l=this.index;l<Math.min(this.index+3,this.top.children.length);l++){let c=this.top.children[l];if(c.matchesMark(e[i])&&!this.isLocked(c.dom)){a=l;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let l=Gc.create(this.top,e[i],t,r);this.top.children.splice(this.index,0,l),this.top=l,this.changed=!0}this.index=0,i++}}findNodeMatch(e,t,r,s){let i=-1,o;if(s>=this.preMatch.index&&(o=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))i=this.top.children.indexOf(o,this.index);else for(let a=this.index,l=Math.min(this.top.children.length,a+5);a<l;a++){let c=this.top.children[a];if(c.matchesNode(e,t,r)&&!this.preMatch.matched.has(c)){i=a;break}}return i<0?!1:(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,r,s,i){let o=this.top.children[s];return o.dirty==No&&o.dom==o.contentDOM&&(o.dirty=Ac),o.update(e,t,r,i)?(this.destroyBetween(this.index,s),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let r=e.pmViewDesc;if(r){for(let s=this.index;s<this.top.children.length;s++)if(this.top.children[s]==r)return s}return-1}e=t}}updateNextNode(e,t,r,s,i,o){for(let a=this.index;a<this.top.children.length;a++){let l=this.top.children[a];if(l instanceof Rl){let c=this.preMatch.matched.get(l);if(c!=null&&c!=i)return!1;let d=l.dom,f,p=this.isLocked(d)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&l.dirty!=No&&qy(t,l.outerDeco));if(!p&&l.update(e,t,r,s))return this.destroyBetween(this.index,a),l.dom!=d&&(this.changed=!0),this.index++,!0;if(!p&&(f=this.recreateWrapper(l,e,t,r,s,o)))return this.destroyBetween(this.index,a),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Ac,f.updateChildren(s,o+1),f.dirty=vi),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,r,s,i,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!qy(r,e.outerDeco)||!s.eq(e.innerDeco))return null;let a=Rl.create(this.top,t,r,s,i,o);if(a.contentDOM){a.children=e.children,e.children=[];for(let l of a.children)l.parent=a}return e.destroy(),a}addNode(e,t,r,s,i){let o=Rl.create(this.top,e,t,r,s,i);o.contentDOM&&o.updateChildren(s,i+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,r){let s=this.index<this.top.children.length?this.top.children[this.index]:null;if(s&&s.matchesWidget(e)&&(e==s.widget||!s.widget.type.toDOM.parentNode))this.index++;else{let i=new WF(this.top,e,t,r);this.top.children.splice(this.index++,0,i),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Gc;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Pv)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&(($r||Pr)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let r=document.createElement(e);e=="IMG"&&(r.className="ProseMirror-separator",r.alt=""),e=="BR"&&(r.className="ProseMirror-trailingBreak");let s=new VF(this.top,[],r,null);t!=this.top?t.children.push(s):t.children.splice(this.index++,0,s),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function lX(n,e){let t=e,r=t.children.length,s=n.childCount,i=new Map,o=[];e:for(;s>0;){let a;for(;;)if(r){let c=t.children[r-1];if(c instanceof Gc)t=c,r=c.children.length;else{a=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let l=a.node;if(l){if(l!=n.child(s-1))break;--s,i.set(a,s),o.push(a)}}return{index:s,matched:i,matches:o.reverse()}}function cX(n,e){return n.type.side-e.type.side}function uX(n,e,t,r){let s=e.locals(n),i=0;if(s.length==0){for(let c=0;c<n.childCount;c++){let d=n.child(c);r(d,s,e.forChild(i,d),c),i+=d.nodeSize}return}let o=0,a=[],l=null;for(let c=0;;){let d,f;for(;o<s.length&&s[o].to==i;){let x=s[o++];x.widget&&(d?(f||(f=[d])).push(x):d=x)}if(d)if(f){f.sort(cX);for(let x=0;x<f.length;x++)t(f[x],c,!!l)}else t(d,c,!!l);let p,m;if(l)m=-1,p=l,l=null;else if(c<n.childCount)m=c,p=n.child(c++);else break;for(let x=0;x<a.length;x++)a[x].to<=i&&a.splice(x--,1);for(;o<s.length&&s[o].from<=i&&s[o].to>i;)a.push(s[o++]);let y=i+p.nodeSize;if(p.isText){let x=y;o<s.length&&s[o].from<x&&(x=s[o].from);for(let b=0;b<a.length;b++)a[b].to<x&&(x=a[b].to);x<y&&(l=p.cut(x-i),p=p.cut(0,x-i),y=x,m=-1)}else for(;o<s.length&&s[o].to<y;)o++;let v=p.isInline&&!p.isLeaf?a.filter(x=>!x.inline):a.slice();r(p,v,e.forChild(i,p),m),i=y}}function dX(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function hX(n,e,t,r){for(let s=0,i=0;s<n.childCount&&i<=r;){let o=n.child(s++),a=i;if(i+=o.nodeSize,!o.isText)continue;let l=o.text;for(;s<n.childCount;){let c=n.child(s++);if(i+=c.nodeSize,!c.isText)break;l+=c.text}if(i>=t){if(i>=r&&l.slice(r-e.length-a,r-a)==e)return r-e.length;let c=a<r?l.lastIndexOf(e,r-a-1):-1;if(c>=0&&c+e.length+a>=t)return a+c;if(t==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}function BP(n,e,t,r,s){let i=[];for(let o=0,a=0;o<n.length;o++){let l=n[o],c=a,d=a+=l.size;c>=t||d<=e?i.push(l):(c<e&&i.push(l.slice(0,e-c,r)),s&&(i.push(s),s=void 0),d>t&&i.push(l.slice(t-c,l.size,r)))}return i}function Uk(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let s=n.docView.nearestDesc(t.focusNode),i=s&&s.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let a=r.resolve(o),l,c;if(Cv(t)){for(l=o;s&&!s.node;)s=s.parent;let f=s.node;if(s&&f.isAtom&&We.isSelectable(f)&&s.parent&&!(f.isInline&&FY(t.focusNode,t.focusOffset,s.dom))){let p=s.posBefore;c=new We(o==p?a:r.resolve(p))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,p=o;for(let m=0;m<t.rangeCount;m++){let y=t.getRangeAt(m);f=Math.min(f,n.docView.posFromDOM(y.startContainer,y.startOffset,1)),p=Math.max(p,n.docView.posFromDOM(y.endContainer,y.endOffset,-1))}if(f<0)return null;[l,o]=p==n.state.selection.anchor?[p,f]:[f,p],a=r.resolve(o)}else l=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!c){let f=e=="pointer"||n.state.selection.head<a.pos&&!i?1:-1;c=Hk(n,d,a,f)}return c}function XF(n){return n.editable?n.hasFocus():JF(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function Ea(n,e=!1){let t=n.state.selection;if(ZF(n,t),!!XF(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Pr){let r=n.domSelectionRange(),s=n.domObserver.currentSelection;if(r.anchorNode&&s.anchorNode&&qc(r.anchorNode,r.anchorOffset,s.anchorNode,s.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)pX(n);else{let{anchor:r,head:s}=t,i,o;uD&&!(t instanceof rt)&&(t.$from.parent.inlineContent||(i=dD(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=dD(n,t.to))),n.docView.setSelection(r,s,n,e),uD&&(i&&hD(i),o&&hD(o)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&fX(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const uD=$r||Pr&&FF<63;function dD(n,e){let{node:t,offset:r}=n.docView.domFromPos(e,0),s=r<t.childNodes.length?t.childNodes[r]:null,i=r?t.childNodes[r-1]:null;if($r&&s&&s.contentEditable=="false")return F1(s);if((!s||s.contentEditable=="false")&&(!i||i.contentEditable=="false")){if(s)return F1(s);if(i)return F1(i)}}function F1(n){return n.contentEditable="true",$r&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function hD(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function fX(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),r=t.anchorNode,s=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=r||t.anchorOffset!=s)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!XF(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function pX(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,s=r.nodeName=="IMG";s?t.setStart(r.parentNode,er(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!s&&!n.state.selection.visible&&bs&&Ol<=11&&(r.disabled=!0,r.disabled=!1)}function ZF(n,e){if(e instanceof We){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(fD(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else fD(n)}function fD(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Hk(n,e,t,r){return n.someProp("createSelectionBetween",s=>s(n,e,t))||rt.between(e,t,r)}function pD(n){return n.editable&&!n.hasFocus()?!1:JF(n)}function JF(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function gX(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return qc(e.node,e.offset,t.anchorNode,t.anchorOffset)}function UP(n,e){let{$anchor:t,$head:r}=n.selection,s=e>0?t.max(r):t.min(r),i=s.parent.inlineContent?s.depth?n.doc.resolve(e>0?s.after():s.before()):null:s;return i&&at.findFrom(i,e)}function vl(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function gD(n,e,t){let r=n.state.selection;if(r instanceof rt)if(t.indexOf("s")>-1){let{$head:s}=r,i=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let o=n.state.doc.resolve(s.pos+i.nodeSize*(e<0?-1:1));return vl(n,new rt(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let s=UP(n.state,e);return s&&s instanceof We?vl(n,s):!1}else if(!(ui&&t.indexOf("m")>-1)){let s=r.$head,i=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter,o;if(!i||i.isText)return!1;let a=e<0?s.pos-i.nodeSize:s.pos;return i.isAtom||(o=n.docView.descAt(a))&&!o.contentDOM?We.isSelectable(i)?vl(n,new We(e<0?n.state.doc.resolve(s.pos-i.nodeSize):s)):Tp?vl(n,new rt(n.state.doc.resolve(e<0?a:a+i.nodeSize))):!1:!1}}else return!1;else{if(r instanceof We&&r.node.isInline)return vl(n,new rt(e>0?r.$to:r.$from));{let s=UP(n.state,e);return s?vl(n,s):!1}}}function Gy(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Mf(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function td(n,e){return e<0?mX(n):yX(n)}function mX(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let s,i,o=!1;for(Zi&&t.nodeType==1&&r<Gy(t)&&Mf(t.childNodes[r],-1)&&(o=!0);;)if(r>0){if(t.nodeType!=1)break;{let a=t.childNodes[r-1];if(Mf(a,-1))s=t,i=--r;else if(a.nodeType==3)t=a,r=t.nodeValue.length;else break}}else{if(QF(t))break;{let a=t.previousSibling;for(;a&&Mf(a,-1);)s=t.parentNode,i=er(a),a=a.previousSibling;if(a)t=a,r=Gy(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?HP(n,t,r):s&&HP(n,s,i)}function yX(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let s=Gy(t),i,o;for(;;)if(r<s){if(t.nodeType!=1)break;let a=t.childNodes[r];if(Mf(a,1))i=t,o=++r;else break}else{if(QF(t))break;{let a=t.nextSibling;for(;a&&Mf(a,1);)i=a.parentNode,o=er(a)+1,a=a.nextSibling;if(a)t=a,r=0,s=Gy(t);else{if(t=t.parentNode,t==n.dom)break;r=s=0}}}i&&HP(n,i,o)}function QF(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function SX(n,e){for(;n&&e==n.childNodes.length&&!_p(n);)e=er(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function vX(n,e){for(;n&&!e&&!_p(n);)e=er(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function HP(n,e,t){if(e.nodeType!=3){let i,o;(o=SX(e,t))?(e=o,t=0):(i=vX(e,t))&&(e=i,t=i.nodeValue.length)}let r=n.domSelection();if(!r)return;if(Cv(r)){let i=document.createRange();i.setEnd(e,t),i.setStart(e,t),r.removeAllRanges(),r.addRange(i)}else r.extend&&r.extend(e,t);n.domObserver.setCurSelection();let{state:s}=n;setTimeout(()=>{n.state==s&&Ea(n)},50)}function mD(n,e){let t=n.state.doc.resolve(e);if(!(Pr||BY)&&t.parent.inlineContent){let s=n.coordsAtPos(e);if(e>t.start()){let i=n.coordsAtPos(e-1),o=(i.top+i.bottom)/2;if(o>s.top&&o<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<t.end()){let i=n.coordsAtPos(e+1),o=(i.top+i.bottom)/2;if(o>s.top&&o<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function yD(n,e,t){let r=n.state.selection;if(r instanceof rt&&!r.empty||t.indexOf("s")>-1||ui&&t.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=UP(n.state,e);if(o&&o instanceof We)return vl(n,o)}if(!s.parent.inlineContent){let o=e<0?s:i,a=r instanceof Bs?at.near(o,e):at.findFrom(o,e);return a?vl(n,a):!1}return!1}function SD(n,e){if(!(n.state.selection instanceof rt))return!0;let{$head:t,$anchor:r,empty:s}=n.state.selection;if(!t.sameParent(r))return!0;if(!s)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let i=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(i&&!i.isText){let o=n.state.tr;return e<0?o.delete(t.pos-i.nodeSize,t.pos):o.delete(t.pos,t.pos+i.nodeSize),n.dispatch(o),!0}return!1}function vD(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function xX(n){if(!$r||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;vD(n,r,"true"),setTimeout(()=>vD(n,r,"false"),20)}return!1}function wX(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function bX(n,e){let t=e.keyCode,r=wX(e);if(t==8||ui&&t==72&&r=="c")return SD(n,-1)||td(n,-1);if(t==46&&!e.shiftKey||ui&&t==68&&r=="c")return SD(n,1)||td(n,1);if(t==13||t==27)return!0;if(t==37||ui&&t==66&&r=="c"){let s=t==37?mD(n,n.state.selection.from)=="ltr"?-1:1:-1;return gD(n,s,r)||td(n,s)}else if(t==39||ui&&t==70&&r=="c"){let s=t==39?mD(n,n.state.selection.from)=="ltr"?1:-1:1;return gD(n,s,r)||td(n,s)}else{if(t==38||ui&&t==80&&r=="c")return yD(n,-1,r)||td(n,-1);if(t==40||ui&&t==78&&r=="c")return xX(n)||yD(n,1,r)||td(n,1);if(r==(ui?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Kk(n,e){n.someProp("transformCopied",m=>{e=m(e,n)});let t=[],{content:r,openStart:s,openEnd:i}=e;for(;s>1&&i>1&&r.childCount==1&&r.firstChild.childCount==1;){s--,i--;let m=r.firstChild;t.push(m.type.name,m.attrs!=m.type.defaultAttrs?m.attrs:null),r=m.content}let o=n.someProp("clipboardSerializer")||hu.fromSchema(n.state.schema),a=i5(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,f=0;for(;c&&c.nodeType==1&&(d=s5[c.nodeName.toLowerCase()]);){for(let m=d.length-1;m>=0;m--){let y=a.createElement(d[m]);for(;l.firstChild;)y.appendChild(l.firstChild);l.appendChild(y),f++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${s} ${i}${f?` -${f}`:""} ${JSON.stringify(t)}`);let p=n.someProp("clipboardTextSerializer",m=>m(e,n))||e.content.textBetween(0,e.content.size,`
91
+
92
+ `);return{dom:l,text:p,slice:e}}function e5(n,e,t,r,s){let i=s.parent.type.spec.code,o,a;if(!t&&!e)return null;let l=e&&(r||i||!t);if(l){if(n.someProp("transformPastedText",p=>{e=p(e,i||r,n)}),i)return e?new Te(pe.from(n.state.schema.text(e.replace(/\r\n?/g,`
93
+ `))),0,0):Te.empty;let f=n.someProp("clipboardTextParser",p=>p(e,s,r,n));if(f)a=f;else{let p=s.marks(),{schema:m}=n.state,y=hu.fromSchema(m);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(v=>{let x=o.appendChild(document.createElement("p"));v&&x.appendChild(y.serializeNode(m.text(v,p)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=kX(t),Tp&&IX(o);let c=o&&o.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let f=+d[3];f>0;f--){let p=o.firstChild;for(;p&&p.nodeType!=1;)p=p.nextSibling;if(!p)break;o=p}if(a||(a=(n.someProp("clipboardParser")||n.someProp("domParser")||Cd.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(l||d),context:s,ruleFromNode(p){return p.nodeName=="BR"&&!p.nextSibling&&p.parentNode&&!CX.test(p.parentNode.nodeName)?{ignore:!0}:null}})),d)a=_X(xD(a,+d[1],+d[2]),d[4]);else if(a=Te.maxOpen(PX(a.content,s),!0),a.openStart||a.openEnd){let f=0,p=0;for(let m=a.content.firstChild;f<a.openStart&&!m.type.spec.isolating;f++,m=m.firstChild);for(let m=a.content.lastChild;p<a.openEnd&&!m.type.spec.isolating;p++,m=m.lastChild);a=xD(a,f,p)}return n.someProp("transformPasted",f=>{a=f(a,n)}),a}const CX=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function PX(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let s=e.node(t).contentMatchAt(e.index(t)),i,o=[];if(n.forEach(a=>{if(!o)return;let l=s.findWrapping(a.type),c;if(!l)return o=null;if(c=o.length&&i.length&&n5(l,i,a,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=r5(o[o.length-1],i.length));let d=t5(a,l);o.push(d),s=s.matchType(d.type),i=l}}),o)return pe.from(o)}return n}function t5(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,pe.from(n));return n}function n5(n,e,t,r,s){if(s<n.length&&s<e.length&&n[s]==e[s]){let i=n5(n,e,t,r.lastChild,s+1);if(i)return r.copy(r.content.replaceChild(r.childCount-1,i));if(r.contentMatchAt(r.childCount).matchType(s==n.length-1?t.type:n[s+1]))return r.copy(r.content.append(pe.from(t5(t,n,s+1))))}}function r5(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,r5(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(pe.empty,!0);return n.copy(t.append(r))}function KP(n,e,t,r,s,i){let o=e<0?n.firstChild:n.lastChild,a=o.content;return n.childCount>1&&(i=0),s<r-1&&(a=KP(a,e,t,r,s+1,i)),s>=t&&(a=e<0?o.contentMatchAt(0).fillBefore(a,i<=s).append(a):a.append(o.contentMatchAt(o.childCount).fillBefore(pe.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(a))}function xD(n,e,t){return e<n.openStart&&(n=new Te(KP(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new Te(KP(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const s5={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let wD=null;function i5(){return wD||(wD=document.implementation.createHTMLDocument("title"))}let z1=null;function EX(n){let e=window.trustedTypes;return e?(z1||(z1=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),z1.createHTML(n)):n}function kX(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=i5().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),s;if((s=r&&s5[r[1].toLowerCase()])&&(n=s.map(i=>"<"+i+">").join("")+n+s.map(i=>"</"+i+">").reverse().join("")),t.innerHTML=EX(n),s)for(let i=0;i<s.length;i++)t=t.querySelector(s[i])||t;return t}function IX(n){let e=n.querySelectorAll(Pr?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let r=e[t];r.childNodes.length==1&&r.textContent==" "&&r.parentNode&&r.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),r)}}function _X(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return n}let{content:s,openStart:i,openEnd:o}=n;for(let a=r.length-2;a>=0;a-=2){let l=t.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;s=pe.from(l.create(r[a+1],s)),i++,o++}return new Te(s,i,o)}const Br={},Ur={},TX={touchstart:!0,touchmove:!0};class MX{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function AX(n){for(let e in Br){let t=Br[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{RX(n,r)&&!Wk(n,r)&&(n.editable||!(r.type in Ur))&&t(n,r)},TX[e]?{passive:!0}:void 0)}$r&&n.dom.addEventListener("input",()=>null),WP(n)}function Ml(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function OX(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function WP(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Wk(n,r))})}function Wk(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function RX(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function DX(n,e){!Wk(n,e)&&Br[e.type]&&(n.editable||!(e.type in Ur))&&Br[e.type](n,e)}Ur.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!a5(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(xa&&Pr&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),zd&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",s=>s(n,Tc(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||bX(n,t)?t.preventDefault():Ml(n,"key")};Ur.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Ur.keypress=(n,e)=>{let t=e;if(a5(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ui&&t.metaKey)return;if(n.someProp("handleKeyPress",s=>s(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof rt)||!r.$from.sameParent(r.$to)){let s=String.fromCharCode(t.charCode);!/[\r\n]/.test(s)&&!n.someProp("handleTextInput",i=>i(n,r.$from.pos,r.$to.pos,s))&&n.dispatch(n.state.tr.insertText(s).scrollIntoView()),t.preventDefault()}};function Ev(n){return{left:n.clientX,top:n.clientY}}function jX(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Vk(n,e,t,r,s){if(r==-1)return!1;let i=n.state.doc.resolve(r);for(let o=i.depth+1;o>0;o--)if(n.someProp(e,a=>o>i.depth?a(n,t,i.nodeAfter,i.before(o),s,!0):a(n,t,i.node(o),i.before(o),s,!1)))return!0;return!1}function Ed(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function NX(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&We.isSelectable(r)?(Ed(n,new We(t)),!0):!1}function LX(n,e){if(e==-1)return!1;let t=n.state.selection,r,s;t instanceof We&&(r=t.node);let i=n.state.doc.resolve(e);for(let o=i.depth+1;o>0;o--){let a=o>i.depth?i.nodeAfter:i.node(o);if(We.isSelectable(a)){r&&t.$from.depth>0&&o>=t.$from.depth&&i.before(t.$from.depth+1)==t.$from.pos?s=i.before(t.$from.depth):s=i.before(o);break}}return s!=null?(Ed(n,We.create(n.state.doc,s)),!0):!1}function FX(n,e,t,r,s){return Vk(n,"handleClickOn",e,t,r)||n.someProp("handleClick",i=>i(n,e,r))||(s?LX(n,t):NX(n,t))}function zX(n,e,t,r){return Vk(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",s=>s(n,e,r))}function $X(n,e,t,r){return Vk(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",s=>s(n,e,r))||BX(n,t,r)}function BX(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Ed(n,rt.create(r,0,r.content.size)),!0):!1;let s=r.resolve(e);for(let i=s.depth+1;i>0;i--){let o=i>s.depth?s.nodeAfter:s.node(i),a=s.before(i);if(o.inlineContent)Ed(n,rt.create(r,a+1,a+1+o.content.size));else if(We.isSelectable(o))Ed(n,We.create(r,a));else continue;return!0}}function qk(n){return Yy(n)}const o5=ui?"metaKey":"ctrlKey";Br.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=qk(n),s=Date.now(),i="singleClick";s-n.input.lastClick.time<500&&jX(t,n.input.lastClick)&&!t[o5]&&(n.input.lastClick.type=="singleClick"?i="doubleClick":n.input.lastClick.type=="doubleClick"&&(i="tripleClick")),n.input.lastClick={time:s,x:t.clientX,y:t.clientY,type:i};let o=n.posAtCoords(Ev(t));o&&(i=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new UX(n,o,t,!!r)):(i=="doubleClick"?zX:$X)(n,o.pos,o.inside,t)?t.preventDefault():Ml(n,"pointer"))};class UX{constructor(e,t,r,s){this.view=e,this.pos=t,this.event=r,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[o5],this.allowDefault=r.shiftKey;let i,o;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),o=t.inside;else{let d=e.state.doc.resolve(t.pos);i=d.parent,o=d.depth?d.before():0}const a=s?null:r.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.dom.nodeType==1?l.dom:null;let{selection:c}=e.state;(r.button==0&&i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof We&&c.from<=o&&c.to>o)&&(this.mightDrag={node:i,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Zi&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Ml(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>Ea(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Ev(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ml(this.view,"pointer"):FX(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||$r&&this.mightDrag&&!this.mightDrag.node.isAtom||Pr&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Ed(this.view,at.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Ml(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ml(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Br.touchstart=n=>{n.input.lastTouch=Date.now(),qk(n),Ml(n,"pointer")};Br.touchmove=n=>{n.input.lastTouch=Date.now(),Ml(n,"pointer")};Br.contextmenu=n=>qk(n);function a5(n,e){return n.composing?!0:$r&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const HX=xa?5e3:-1;Ur.compositionstart=Ur.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof rt&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),Yy(n,!0),n.markCursor=null;else if(Yy(n,!e.selection.empty),Zi&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let s=r.focusNode,i=r.focusOffset;s&&s.nodeType==1&&i!=0;){let o=i<0?s.lastChild:s.childNodes[i-1];if(!o)break;if(o.nodeType==3){let a=n.domSelection();a&&a.collapse(o,o.nodeValue.length);break}else s=o,i=-1}}n.input.composing=!0}l5(n,HX)};Ur.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,l5(n,20))};function l5(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Yy(n),e))}function c5(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=WX());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function KX(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=NY(e.focusNode,e.focusOffset),r=LY(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let s=r.pmViewDesc,i=n.domObserver.lastChangedTextNode;if(t==i||r==i)return i;if(!s||!s.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function WX(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Yy(n,e=!1){if(!(xa&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),c5(n),e||n.docView&&n.docView.dirty){let t=Uk(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function VX(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),s=document.createRange();s.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(s),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const ep=bs&&Ol<15||zd&&UY<604;Br.copy=Ur.cut=(n,e)=>{let t=e,r=n.state.selection,s=t.type=="cut";if(r.empty)return;let i=ep?null:t.clipboardData,o=r.content(),{dom:a,text:l}=Kk(n,o);i?(t.preventDefault(),i.clearData(),i.setData("text/html",a.innerHTML),i.setData("text/plain",l)):VX(n,a),s&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function qX(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function GX(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let s=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?tp(n,r.value,null,s,e):tp(n,r.textContent,r.innerHTML,s,e)},50)}function tp(n,e,t,r,s){let i=e5(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",l=>l(n,s,i||Te.empty)))return!0;if(!i)return!1;let o=qX(i),a=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(i);return n.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function u5(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Ur.paste=(n,e)=>{let t=e;if(n.composing&&!xa)return;let r=ep?null:t.clipboardData,s=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&tp(n,u5(r),r.getData("text/html"),s,t)?t.preventDefault():GX(n,t)};let d5=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}};const h5=ui?"altKey":"ctrlKey";Br.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let s=n.state.selection,i=s.empty?null:n.posAtCoords(Ev(t)),o;if(!(i&&i.pos>=s.from&&i.pos<=(s instanceof We?s.to-1:s.to))){if(r&&r.mightDrag)o=We.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=We.create(n.state.doc,f.posBefore))}}let a=(o||n.state.selection).content(),{dom:l,text:c,slice:d}=Kk(n,a);(!t.dataTransfer.files.length||!Pr||FF>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ep?"Text":"text/html",l.innerHTML),t.dataTransfer.effectAllowed="copyMove",ep||t.dataTransfer.setData("text/plain",c),n.dragging=new d5(d,!t[h5],o)};Br.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Ur.dragover=Ur.dragenter=(n,e)=>e.preventDefault();Ur.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let s=n.posAtCoords(Ev(t));if(!s)return;let i=n.state.doc.resolve(s.pos),o=r&&r.slice;o?n.someProp("transformPasted",y=>{o=y(o,n)}):o=e5(n,u5(t.dataTransfer),ep?null:t.dataTransfer.getData("text/html"),!1,i);let a=!!(r&&!t[h5]);if(n.someProp("handleDrop",y=>y(n,t,o||Te.empty,a))){t.preventDefault();return}if(!o)return;t.preventDefault();let l=o?TF(n.state.doc,i.pos,o):i.pos;l==null&&(l=i.pos);let c=n.state.tr;if(a){let{node:y}=r;y?y.replace(c):c.deleteSelection()}let d=c.mapping.map(l),f=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,p=c.doc;if(f?c.replaceRangeWith(d,d,o.content.firstChild):c.replaceRange(d,d,o),c.doc.eq(p))return;let m=c.doc.resolve(d);if(f&&We.isSelectable(o.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new We(m));else{let y=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach((v,x,b,C)=>y=C),c.setSelection(Hk(n,m,c.doc.resolve(y)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};Br.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&Ea(n)},20))};Br.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Br.beforeinput=(n,e)=>{if(Pr&&xa&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",i=>i(n,Tc(8,"Backspace")))))return;let{$cursor:s}=n.state.selection;s&&s.pos>0&&n.dispatch(n.state.tr.delete(s.pos-1,s.pos).scrollIntoView())},50)}};for(let n in Ur)Br[n]=Ur[n];function np(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class Xy{constructor(e,t){this.toDOM=e,this.spec=t||Bc,this.side=this.spec.side||0}map(e,t,r,s){let{pos:i,deleted:o}=e.mapResult(t.from+s,this.side<0?-1:1);return o?null:new pi(i-r,i-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Xy&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&np(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Dl{constructor(e,t){this.attrs=e,this.spec=t||Bc}map(e,t,r,s){let i=e.map(t.from+s,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+s,this.spec.inclusiveEnd?1:-1)-r;return i>=o?null:new pi(i,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Dl&&np(this.attrs,e.attrs)&&np(this.spec,e.spec)}static is(e){return e.type instanceof Dl}destroy(){}}class Gk{constructor(e,t){this.attrs=e,this.spec=t||Bc}map(e,t,r,s){let i=e.mapResult(t.from+s,1);if(i.deleted)return null;let o=e.mapResult(t.to+s,-1);return o.deleted||o.pos<=i.pos?null:new pi(i.pos-r,o.pos-r,this)}valid(e,t){let{index:r,offset:s}=e.content.findIndex(t.from),i;return s==t.from&&!(i=e.child(r)).isText&&s+i.nodeSize==t.to}eq(e){return this==e||e instanceof Gk&&np(this.attrs,e.attrs)&&np(this.spec,e.spec)}destroy(){}}class pi{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new pi(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,r){return this.type.map(e,this,t,r)}static widget(e,t,r){return new pi(e,e,new Xy(t,r))}static inline(e,t,r,s){return new pi(e,t,new Dl(r,s))}static node(e,t,r,s){return new pi(e,t,new Gk(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Dl}get widget(){return this.type instanceof Xy}}const hd=[],Bc={};class An{constructor(e,t){this.local=e.length?e:hd,this.children=t.length?t:hd}static create(e,t){return t.length?Zy(t,e,0,Bc):vr}find(e,t,r){let s=[];return this.findInner(e??0,t??1e9,s,0,r),s}findInner(e,t,r,s,i){for(let o=0;o<this.local.length;o++){let a=this.local[o];a.from<=t&&a.to>=e&&(!i||i(a.spec))&&r.push(a.copy(a.from+s,a.to+s))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let a=this.children[o]+1;this.children[o+2].findInner(e-a,t-a,r,s+a,i)}}map(e,t,r){return this==vr||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Bc)}mapInner(e,t,r,s,i){let o;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,r,s);l&&l.type.valid(t,l)?(o||(o=[])).push(l):i.onRemove&&i.onRemove(this.local[a].spec)}return this.children.length?YX(this.children,o||[],e,t,r,s,i):o?new An(o.sort(Uc),hd):vr}add(e,t){return t.length?this==vr?An.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let s,i=0;e.forEach((a,l)=>{let c=l+r,d;if(d=p5(t,a,c)){for(s||(s=this.children.slice());i<s.length&&s[i]<l;)i+=3;s[i]==l?s[i+2]=s[i+2].addInner(a,d,c+1):s.splice(i,0,l,l+a.nodeSize,Zy(d,a,c+1,Bc)),i+=3}});let o=f5(i?g5(t):t,-r);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a])||o.splice(a--,1);return new An(o.length?this.local.concat(o).sort(Uc):this.local,s||this.children)}remove(e){return e.length==0||this==vr?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,s=this.local;for(let i=0;i<r.length;i+=3){let o,a=r[i]+t,l=r[i+1]+t;for(let d=0,f;d<e.length;d++)(f=e[d])&&f.from>a&&f.to<l&&(e[d]=null,(o||(o=[])).push(f));if(!o)continue;r==this.children&&(r=this.children.slice());let c=r[i+2].removeInner(o,a+1);c!=vr?r[i+2]=c:(r.splice(i,3),i-=3)}if(s.length){for(let i=0,o;i<e.length;i++)if(o=e[i])for(let a=0;a<s.length;a++)s[a].eq(o,t)&&(s==this.local&&(s=this.local.slice()),s.splice(a--,1))}return r==this.children&&s==this.local?this:s.length||r.length?new An(s,r):vr}forChild(e,t){if(this==vr)return this;if(t.isLeaf)return An.empty;let r,s;for(let a=0;a<this.children.length;a+=3)if(this.children[a]>=e){this.children[a]==e&&(r=this.children[a+2]);break}let i=e+1,o=i+t.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<o&&l.to>i&&l.type instanceof Dl){let c=Math.max(i,l.from)-i,d=Math.min(o,l.to)-i;c<d&&(s||(s=[])).push(l.copy(c,d))}}if(s){let a=new An(s.sort(Uc),hd);return r?new Cl([a,r]):a}return r||vr}eq(e){if(this==e)return!0;if(!(e instanceof An)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return Yk(this.localsInner(e))}localsInner(e){if(this==vr)return hd;if(e.inlineContent||!this.local.some(Dl.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Dl||t.push(this.local[r]);return t}forEachSet(e){e(this)}}An.empty=new An([],[]);An.removeOverlap=Yk;const vr=An.empty;class Cl{constructor(e){this.members=e}map(e,t){const r=this.members.map(s=>s.map(e,t,Bc));return Cl.from(r)}forChild(e,t){if(t.isLeaf)return An.empty;let r=[];for(let s=0;s<this.members.length;s++){let i=this.members[s].forChild(e,t);i!=vr&&(i instanceof Cl?r=r.concat(i.members):r.push(i))}return Cl.from(r)}eq(e){if(!(e instanceof Cl)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,r=!0;for(let s=0;s<this.members.length;s++){let i=this.members[s].localsInner(e);if(i.length)if(!t)t=i;else{r&&(t=t.slice(),r=!1);for(let o=0;o<i.length;o++)t.push(i[o])}}return t?Yk(r?t:t.sort(Uc)):hd}static from(e){switch(e.length){case 0:return vr;case 1:return e[0];default:return new Cl(e.every(t=>t instanceof An)?e:e.reduce((t,r)=>t.concat(r instanceof An?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function YX(n,e,t,r,s,i,o){let a=n.slice();for(let c=0,d=i;c<t.maps.length;c++){let f=0;t.maps[c].forEach((p,m,y,v)=>{let x=v-y-(m-p);for(let b=0;b<a.length;b+=3){let C=a[b+1];if(C<0||p>C+d-f)continue;let I=a[b]+d-f;m>=I?a[b+1]=p<=I?-2:-1:p>=d&&x&&(a[b]+=x,a[b+1]+=x)}f+=x}),d=t.maps[c].map(d,-1)}let l=!1;for(let c=0;c<a.length;c+=3)if(a[c+1]<0){if(a[c+1]==-2){l=!0,a[c+1]=-1;continue}let d=t.map(n[c]+i),f=d-s;if(f<0||f>=r.content.size){l=!0;continue}let p=t.map(n[c+1]+i,-1),m=p-s,{index:y,offset:v}=r.content.findIndex(f),x=r.maybeChild(y);if(x&&v==f&&v+x.nodeSize==m){let b=a[c+2].mapInner(t,x,d+1,n[c]+i+1,o);b!=vr?(a[c]=f,a[c+1]=m,a[c+2]=b):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=XX(a,n,e,t,s,i,o),d=Zy(c,r,0,o);e=d.local;for(let f=0;f<a.length;f+=3)a[f+1]<0&&(a.splice(f,3),f-=3);for(let f=0,p=0;f<d.children.length;f+=3){let m=d.children[f];for(;p<a.length&&a[p]<m;)p+=3;a.splice(p,0,d.children[f],d.children[f+1],d.children[f+2])}}return new An(e.sort(Uc),a)}function f5(n,e){if(!e||!n.length)return n;let t=[];for(let r=0;r<n.length;r++){let s=n[r];t.push(new pi(s.from+e,s.to+e,s.type))}return t}function XX(n,e,t,r,s,i,o){function a(l,c){for(let d=0;d<l.local.length;d++){let f=l.local[d].map(r,s,c);f?t.push(f):o.onRemove&&o.onRemove(l.local[d].spec)}for(let d=0;d<l.children.length;d+=3)a(l.children[d+2],l.children[d]+c+1)}for(let l=0;l<n.length;l+=3)n[l+1]==-1&&a(n[l+2],e[l]+i+1);return t}function p5(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,s=null;for(let i=0,o;i<n.length;i++)(o=n[i])&&o.from>t&&o.to<r&&((s||(s=[])).push(o),n[i]=null);return s}function g5(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Zy(n,e,t,r){let s=[],i=!1;e.forEach((a,l)=>{let c=p5(n,a,l+t);if(c){i=!0;let d=Zy(c,a,t+l+1,r);d!=vr&&s.push(l,l+a.nodeSize,d)}});let o=f5(i?g5(n):n,-t).sort(Uc);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a])||(r.onRemove&&r.onRemove(o[a].spec),o.splice(a--,1));return o.length||s.length?new An(o,s):vr}function Uc(n,e){return n.from-e.from||n.to-e.to}function Yk(n){let e=n;for(let t=0;t<e.length-1;t++){let r=e[t];if(r.from!=r.to)for(let s=t+1;s<e.length;s++){let i=e[s];if(i.from==r.from){i.to!=r.to&&(e==n&&(e=n.slice()),e[s]=i.copy(i.from,r.to),bD(e,s+1,i.copy(r.to,i.to)));continue}else{i.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,i.from),bD(e,s,r.copy(i.from,r.to)));break}}}return e}function bD(n,e,t){for(;e<n.length&&Uc(t,n[e])>0;)e++;n.splice(e,0,t)}function $1(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=vr&&e.push(r)}),n.cursorWrapper&&e.push(An.create(n.state.doc,[n.cursorWrapper.deco])),Cl.from(e)}const ZX={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},JX=bs&&Ol<=11;class QX{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class eZ{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new QX,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let s=0;s<r.length;s++)this.queue.push(r[s]);bs&&Ol<=11&&r.some(s=>s.type=="childList"&&s.removedNodes.length||s.type=="characterData"&&s.oldValue.length>s.target.nodeValue.length)?this.flushSoon():this.flush()}),JX&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,ZX)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(pD(this.view)){if(this.suppressingSelectionUpdates)return Ea(this.view);if(bs&&Ol<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&qc(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let i=e.focusNode;i;i=Fd(i))t.add(i);for(let i=e.anchorNode;i;i=Fd(i))if(t.has(i)){r=i;break}let s=r&&this.view.docView.nearestDesc(r);if(s&&s.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&pD(e)&&!this.ignoreSelectionChange(r),i=-1,o=-1,a=!1,l=[];if(e.editable)for(let d=0;d<t.length;d++){let f=this.registerMutation(t[d],l);f&&(i=i<0?f.from:Math.min(f.from,i),o=o<0?f.to:Math.max(f.to,o),f.typeOver&&(a=!0))}if(Zi&&l.length){let d=l.filter(f=>f.nodeName=="BR");if(d.length==2){let[f,p]=d;f.parentNode&&f.parentNode.parentNode==p.parentNode?p.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let p of d){let m=p.parentNode;m&&m.nodeName=="LI"&&(!f||rZ(e,f)!=m)&&p.remove()}}}let c=null;i<0&&s&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Cv(r)&&(c=Uk(e))&&c.eq(at.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Ea(e),this.currentSelection.set(r),e.scrollToSelection()):(i>-1||s)&&(i>-1&&(e.docView.markDirty(i,o),tZ(e)),this.handleDOMChange(i,o,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Ea(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let d=0;d<e.addedNodes.length;d++){let f=e.addedNodes[d];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let s=e.previousSibling,i=e.nextSibling;if(bs&&Ol<=11&&e.addedNodes.length)for(let d=0;d<e.addedNodes.length;d++){let{previousSibling:f,nextSibling:p}=e.addedNodes[d];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(s=f),(!p||Array.prototype.indexOf.call(e.addedNodes,p)<0)&&(i=p)}let o=s&&s.parentNode==e.target?er(s)+1:0,a=r.localPosFromDOM(e.target,o,-1),l=i&&i.parentNode==e.target?er(i):e.target.childNodes.length,c=r.localPosFromDOM(e.target,l,1);return{from:a,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let CD=new WeakMap,PD=!1;function tZ(n){if(!CD.has(n)&&(CD.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Zi,PD)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),PD=!0}}function ED(n,e){let t=e.startContainer,r=e.startOffset,s=e.endContainer,i=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return qc(o.node,o.offset,s,i)&&([t,r,s,i]=[s,i,t,r]),{anchorNode:t,anchorOffset:r,focusNode:s,focusOffset:i}}function nZ(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return ED(n,s)}let t;function r(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",r,!0),t?ED(n,t):null}function rZ(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let r=n.docView.nearestDesc(t,!0);if(r&&r.node.isBlock)return t}return null}function sZ(n,e,t){let{node:r,fromOffset:s,toOffset:i,from:o,to:a}=n.docView.parseRange(e,t),l=n.domSelectionRange(),c,d=l.anchorNode;if(d&&n.dom.contains(d.nodeType==1?d:d.parentNode)&&(c=[{node:d,offset:l.anchorOffset}],Cv(l)||c.push({node:l.focusNode,offset:l.focusOffset})),Pr&&n.input.lastKeyCode===8)for(let x=i;x>s;x--){let b=r.childNodes[x-1],C=b.pmViewDesc;if(b.nodeName=="BR"&&!C){i=x;break}if(!C||C.size)break}let f=n.state.doc,p=n.someProp("domParser")||Cd.fromSchema(n.state.schema),m=f.resolve(o),y=null,v=p.parse(r,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:s,to:i,preserveWhitespace:m.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:iZ,context:m});if(c&&c[0].pos!=null){let x=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=x),y={anchor:x+o,head:b+o}}return{doc:v,sel:y,from:o,to:a}}function iZ(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if($r&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||$r&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const oZ=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function aZ(n,e,t,r,s){let i=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let K=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,U=Uk(n,K);if(U&&!n.state.selection.eq(U)){if(Pr&&xa&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",z=>z(n,Tc(13,"Enter"))))return;let J=n.state.tr.setSelection(U);K=="pointer"?J.setMeta("pointer",!0):K=="key"&&J.scrollIntoView(),i&&J.setMeta("composition",i),n.dispatch(J)}return}let o=n.state.doc.resolve(e),a=o.sharedDepth(t);e=o.before(a+1),t=n.state.doc.resolve(t).after(a+1);let l=n.state.selection,c=sZ(n,e,t),d=n.state.doc,f=d.slice(c.from,c.to),p,m;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(p=n.state.selection.to,m="end"):(p=n.state.selection.from,m="start"),n.input.lastKeyCode=null;let y=uZ(f.content,c.doc.content,c.from,p,m);if(y&&n.input.domChangeCount++,(zd&&n.input.lastIOSEnter>Date.now()-225||xa)&&s.some(K=>K.nodeType==1&&!oZ.test(K.nodeName))&&(!y||y.endA>=y.endB)&&n.someProp("handleKeyDown",K=>K(n,Tc(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!y)if(r&&l instanceof rt&&!l.empty&&l.$head.sameParent(l.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))y={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let K=kD(n,n.state.doc,c.sel);if(K&&!K.eq(n.state.selection)){let U=n.state.tr.setSelection(K);i&&U.setMeta("composition",i),n.dispatch(U)}}return}n.state.selection.from<n.state.selection.to&&y.start==y.endB&&n.state.selection instanceof rt&&(y.start>n.state.selection.from&&y.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?y.start=n.state.selection.from:y.endA<n.state.selection.to&&y.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(y.endB+=n.state.selection.to-y.endA,y.endA=n.state.selection.to)),bs&&Ol<=11&&y.endB==y.start+1&&y.endA==y.start&&y.start>c.from&&c.doc.textBetween(y.start-c.from-1,y.start-c.from+1)=="  "&&(y.start--,y.endA--,y.endB--);let v=c.doc.resolveNoCache(y.start-c.from),x=c.doc.resolveNoCache(y.endB-c.from),b=d.resolve(y.start),C=v.sameParent(x)&&v.parent.inlineContent&&b.end()>=y.endA,I;if((zd&&n.input.lastIOSEnter>Date.now()-225&&(!C||s.some(K=>K.nodeName=="DIV"||K.nodeName=="P"))||!C&&v.pos<c.doc.content.size&&!v.sameParent(x)&&(I=at.findFrom(c.doc.resolve(v.pos+1),1,!0))&&I.head==x.pos)&&n.someProp("handleKeyDown",K=>K(n,Tc(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>y.start&&cZ(d,y.start,y.endA,v,x)&&n.someProp("handleKeyDown",K=>K(n,Tc(8,"Backspace")))){xa&&Pr&&n.domObserver.suppressSelectionUpdates();return}Pr&&y.endB==y.start&&(n.input.lastChromeDelete=Date.now()),xa&&!C&&v.start()!=x.start()&&x.parentOffset==0&&v.depth==x.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==y.endA&&(y.endB-=2,x=c.doc.resolveNoCache(y.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(K){return K(n,Tc(13,"Enter"))})},20));let _=y.start,T=y.endA,A,R,j;if(C){if(v.pos==x.pos)bs&&Ol<=11&&v.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>Ea(n),20)),A=n.state.tr.delete(_,T),R=d.resolve(y.start).marksAcross(d.resolve(y.endA));else if(y.endA==y.endB&&(j=lZ(v.parent.content.cut(v.parentOffset,x.parentOffset),b.parent.content.cut(b.parentOffset,y.endA-b.start()))))A=n.state.tr,j.type=="add"?A.addMark(_,T,j.mark):A.removeMark(_,T,j.mark);else if(v.parent.child(v.index()).isText&&v.index()==x.index()-(x.textOffset?0:1)){let K=v.parent.textBetween(v.parentOffset,x.parentOffset);if(n.someProp("handleTextInput",U=>U(n,_,T,K)))return;A=n.state.tr.insertText(K,_,T)}}if(A||(A=n.state.tr.replace(_,T,c.doc.slice(y.start-c.from,y.endB-c.from))),c.sel){let K=kD(n,A.doc,c.sel);K&&!(Pr&&n.composing&&K.empty&&(y.start!=y.endB||n.input.lastChromeDelete<Date.now()-100)&&(K.head==_||K.head==A.mapping.map(T)-1)||bs&&K.empty&&K.head==_)&&A.setSelection(K)}R&&A.ensureMarks(R),i&&A.setMeta("composition",i),n.dispatch(A.scrollIntoView())}function kD(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Hk(n,e.resolve(t.anchor),e.resolve(t.head))}function lZ(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,s=t,i=r,o,a,l;for(let d=0;d<r.length;d++)s=r[d].removeFromSet(s);for(let d=0;d<t.length;d++)i=t[d].removeFromSet(i);if(s.length==1&&i.length==0)a=s[0],o="add",l=d=>d.mark(a.addToSet(d.marks));else if(s.length==0&&i.length==1)a=i[0],o="remove",l=d=>d.mark(a.removeFromSet(d.marks));else return null;let c=[];for(let d=0;d<e.childCount;d++)c.push(l(e.child(d)));if(pe.from(c).eq(n))return{mark:a,type:o}}function cZ(n,e,t,r,s){if(t-e<=s.pos-r.pos||B1(r,!0,!1)<s.pos)return!1;let i=n.resolve(e);if(!r.parent.isTextblock){let a=i.nodeAfter;return a!=null&&t==e+a.nodeSize}if(i.parentOffset<i.parent.content.size||!i.parent.isTextblock)return!1;let o=n.resolve(B1(i,!0,!0));return!o.parent.isTextblock||o.pos>t||B1(o,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function B1(n,e,t){let r=n.depth,s=e?n.end():n.pos;for(;r>0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,s++,e=!1;if(t){let i=n.node(r).maybeChild(n.indexAfter(r));for(;i&&!i.isLeaf;)i=i.firstChild,s++}return s}function uZ(n,e,t,r,s){let i=n.findDiffStart(e,t);if(i==null)return null;let{a:o,b:a}=n.findDiffEnd(e,t+n.size,t+e.size);if(s=="end"){let l=Math.max(0,i-Math.min(o,a));r-=o+l-i}if(o<i&&n.size<e.size){let l=r<=i&&r>=o?i-r:0;i-=l,i&&i<e.size&&ID(e.textBetween(i-1,i+1))&&(i+=l?1:-1),a=i+(a-o),o=i}else if(a<i){let l=r<=i&&r>=a?i-r:0;i-=l,i&&i<n.size&&ID(n.textBetween(i-1,i+1))&&(i+=l?1:-1),o=i+(o-a),a=i}return{start:i,endA:o,endB:a}}function ID(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class dZ{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new MX,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(OD),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=MD(this),TD(this),this.nodeViews=AD(this),this.docView=lD(this.state.doc,_D(this),$1(this),this.dom,this),this.domObserver=new eZ(this,(r,s,i,o)=>aZ(this,r,s,i,o)),this.domObserver.start(),AX(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&WP(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(OD),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let s=this.state,i=!1,o=!1;e.storedMarks&&this.composing&&(c5(this),o=!0),this.state=e;let a=s.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let m=AD(this);fZ(m,this.nodeViews)&&(this.nodeViews=m,i=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&WP(this),this.editable=MD(this),TD(this);let l=$1(this),c=_D(this),d=s.plugins!=e.plugins&&!s.doc.eq(e.doc)?"reset":e.scrollToSelection>s.scrollToSelection?"to selection":"preserve",f=i||!this.docView.matchesNode(e.doc,c,l);(f||!e.selection.eq(s.selection))&&(o=!0);let p=d=="preserve"&&o&&this.dom.style.overflowAnchor==null&&WY(this);if(o){this.domObserver.stop();let m=f&&(bs||Pr)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&hZ(s.selection,e.selection);if(f){let y=Pr?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=KX(this)),(i||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=lD(e.doc,c,l,this.dom,this)),y&&!this.trackWrites&&(m=!0)}m||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&gX(this))?Ea(this,m):(ZF(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),!((r=this.dragging)===null||r===void 0)&&r.node&&!s.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,s),d=="reset"?this.dom.scrollTop=0:d=="to selection"?this.scrollToSelection():p&&VY(p)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof We){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&nD(this,t.getBoundingClientRect(),e)}else nD(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let r=this.directPlugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let r=this.state.plugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let r=this.pluginViews[t];r.update&&r.update(this,e)}}updateDraggedNode(e,t){let r=e.node,s=-1;if(this.state.doc.nodeAt(r.from)==r.node)s=r.from;else{let i=r.from+(this.state.doc.content.size-t.doc.content.size);(i>0&&this.state.doc.nodeAt(i))==r.node&&(s=i)}this.dragging=new d5(e.slice,e.move,s<0?void 0:We.create(this.state.doc,s))}someProp(e,t){let r=this._props&&this._props[e],s;if(r!=null&&(s=t?t(r):r))return s;for(let o=0;o<this.directPlugins.length;o++){let a=this.directPlugins[o].props[e];if(a!=null&&(s=t?t(a):a))return s}let i=this.state.plugins;if(i)for(let o=0;o<i.length;o++){let a=i[o].props[e];if(a!=null&&(s=t?t(a):a))return s}}hasFocus(){if(bs){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&qY(this.dom),Ea(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return JY(this,e)}coordsAtPos(e,t=1){return HF(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let s=this.docView.posFromDOM(e,t,r);if(s==null)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(e,t){return rX(this,t||this.state,e)}pasteHTML(e,t){return tp(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return tp(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Kk(this,e)}destroy(){this.docView&&(OX(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],$1(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,DY())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return DX(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?$r&&this.root.nodeType===11&&zY(this.dom.ownerDocument)==this.dom&&nZ(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function _D(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[pi.node(0,n.state.doc.content.size,e)]}function TD(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:pi.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function MD(n){return!n.someProp("editable",e=>e(n.state)===!1)}function hZ(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function AD(n){let e=Object.create(null);function t(r){for(let s in r)Object.prototype.hasOwnProperty.call(e,s)||(e[s]=r[s])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function fZ(n,e){let t=0,r=0;for(let s in n){if(n[s]!=e[s])return!0;t++}for(let s in e)r++;return t!=r}function OD(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Nl={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Jy={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},pZ=typeof navigator<"u"&&/Mac/.test(navigator.platform),gZ=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var tr=0;tr<10;tr++)Nl[48+tr]=Nl[96+tr]=String(tr);for(var tr=1;tr<=24;tr++)Nl[tr+111]="F"+tr;for(var tr=65;tr<=90;tr++)Nl[tr]=String.fromCharCode(tr+32),Jy[tr]=String.fromCharCode(tr);for(var U1 in Nl)Jy.hasOwnProperty(U1)||(Jy[U1]=Nl[U1]);function mZ(n){var e=pZ&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||gZ&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Jy:Nl)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const yZ=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function SZ(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,s,i,o;for(let a=0;a<e.length-1;a++){let l=e[a];if(/^(cmd|meta|m)$/i.test(l))o=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))s=!0;else if(/^s(hift)?$/i.test(l))i=!0;else if(/^mod$/i.test(l))yZ?o=!0:s=!0;else throw new Error("Unrecognized modifier name: "+l)}return r&&(t="Alt-"+t),s&&(t="Ctrl-"+t),o&&(t="Meta-"+t),i&&(t="Shift-"+t),t}function vZ(n){let e=Object.create(null);for(let t in n)e[SZ(t)]=n[t];return e}function H1(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function xZ(n){return new lr({props:{handleKeyDown:m5(n)}})}function m5(n){let e=vZ(n);return function(t,r){let s=mZ(r),i,o=e[H1(s,r)];if(o&&o(t.state,t.dispatch,t))return!0;if(s.length==1&&s!=" "){if(r.shiftKey){let a=e[H1(s,r,!1)];if(a&&a(t.state,t.dispatch,t))return!0}if((r.shiftKey||r.altKey||r.metaKey||s.charCodeAt(0)>127)&&(i=Nl[r.keyCode])&&i!=s){let a=e[H1(i,r)];if(a&&a(t.state,t.dispatch,t))return!0}}return!1}}const Xk=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function y5(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const S5=(n,e,t)=>{let r=y5(n,t);if(!r)return!1;let s=Zk(r);if(!s){let o=r.blockRange(),a=o&&rh(o);return a==null?!1:(e&&e(n.tr.lift(o,a).scrollIntoView()),!0)}let i=s.nodeBefore;if(I5(n,s,e,-1))return!0;if(r.parent.content.size==0&&($d(i,"end")||We.isSelectable(i)))for(let o=r.depth;;o--){let a=wv(n.doc,r.before(o),r.after(o),Te.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=n.tr.step(a);l.setSelection($d(i,"end")?at.findFrom(l.doc.resolve(l.mapping.map(s.pos,-1)),-1):We.create(l.doc,s.pos-i.nodeSize)),e(l.scrollIntoView())}return!0}if(o==1||r.node(o-1).childCount>1)break}return i.isAtom&&s.depth==r.depth-1?(e&&e(n.tr.delete(s.pos-i.nodeSize,s.pos).scrollIntoView()),!0):!1},wZ=(n,e,t)=>{let r=y5(n,t);if(!r)return!1;let s=Zk(r);return s?v5(n,s,e):!1},bZ=(n,e,t)=>{let r=w5(n,t);if(!r)return!1;let s=Jk(r);return s?v5(n,s,e):!1};function v5(n,e,t){let r=e.nodeBefore,s=r,i=e.pos-1;for(;!s.isTextblock;i--){if(s.type.spec.isolating)return!1;let d=s.lastChild;if(!d)return!1;s=d}let o=e.nodeAfter,a=o,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let d=a.firstChild;if(!d)return!1;a=d}let c=wv(n.doc,i,l,Te.empty);if(!c||c.from!=i||c instanceof Fn&&c.slice.size>=l-i)return!1;if(t){let d=n.tr.step(c);d.setSelection(rt.create(d.doc,i)),t(d.scrollIntoView())}return!0}function $d(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}const x5=(n,e,t)=>{let{$head:r,empty:s}=n.selection,i=r;if(!s)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;i=Zk(r)}let o=i&&i.nodeBefore;return!o||!We.isSelectable(o)?!1:(e&&e(n.tr.setSelection(We.create(n.doc,i.pos-o.nodeSize)).scrollIntoView()),!0)};function Zk(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function w5(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const b5=(n,e,t)=>{let r=w5(n,t);if(!r)return!1;let s=Jk(r);if(!s)return!1;let i=s.nodeAfter;if(I5(n,s,e,1))return!0;if(r.parent.content.size==0&&($d(i,"start")||We.isSelectable(i))){let o=wv(n.doc,r.before(),r.after(),Te.empty);if(o&&o.slice.size<o.to-o.from){if(e){let a=n.tr.step(o);a.setSelection($d(i,"start")?at.findFrom(a.doc.resolve(a.mapping.map(s.pos)),1):We.create(a.doc,a.mapping.map(s.pos))),e(a.scrollIntoView())}return!0}}return i.isAtom&&s.depth==r.depth-1?(e&&e(n.tr.delete(s.pos,s.pos+i.nodeSize).scrollIntoView()),!0):!1},C5=(n,e,t)=>{let{$head:r,empty:s}=n.selection,i=r;if(!s)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset<r.parent.content.size)return!1;i=Jk(r)}let o=i&&i.nodeAfter;return!o||!We.isSelectable(o)?!1:(e&&e(n.tr.setSelection(We.create(n.doc,i.pos)).scrollIntoView()),!0)};function Jk(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const CZ=(n,e)=>{let t=n.selection,r=t instanceof We,s;if(r){if(t.node.isTextblock||!Yl(n.doc,t.from))return!1;s=t.from}else if(s=xv(n.doc,t.from,-1),s==null)return!1;if(e){let i=n.tr.join(s);r&&i.setSelection(We.create(i.doc,s-n.doc.resolve(s).nodeBefore.nodeSize)),e(i.scrollIntoView())}return!0},PZ=(n,e)=>{let t=n.selection,r;if(t instanceof We){if(t.node.isTextblock||!Yl(n.doc,t.to))return!1;r=t.to}else if(r=xv(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},EZ=(n,e)=>{let{$from:t,$to:r}=n.selection,s=t.blockRange(r),i=s&&rh(s);return i==null?!1:(e&&e(n.tr.lift(s,i).scrollIntoView()),!0)},P5=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
94
+ `).scrollIntoView()),!0)};function Qk(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const kZ=(n,e)=>{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let s=t.node(-1),i=t.indexAfter(-1),o=Qk(s.contentMatchAt(i));if(!o||!s.canReplaceWith(i,i,o))return!1;if(e){let a=t.after(),l=n.tr.replaceWith(a,a,o.createAndFill());l.setSelection(at.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},E5=(n,e)=>{let t=n.selection,{$from:r,$to:s}=t;if(t instanceof Bs||r.parent.inlineContent||s.parent.inlineContent)return!1;let i=Qk(s.parent.contentMatchAt(s.indexAfter()));if(!i||!i.isTextblock)return!1;if(e){let o=(!r.parentOffset&&s.index()<s.parent.childCount?r:s).pos,a=n.tr.insert(o,i.createAndFill());a.setSelection(rt.create(a.doc,o+1)),e(a.scrollIntoView())}return!0},k5=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let i=t.before();if(Pa(n.doc,i))return e&&e(n.tr.split(i).scrollIntoView()),!0}let r=t.blockRange(),s=r&&rh(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)};function IZ(n){return(e,t)=>{let{$from:r,$to:s}=e.selection;if(e.selection instanceof We&&e.selection.node.isBlock)return!r.parentOffset||!Pa(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let i=[],o,a,l=!1,c=!1;for(let m=r.depth;;m--)if(r.node(m).isBlock){l=r.end(m)==r.pos+(r.depth-m),c=r.start(m)==r.pos-(r.depth-m),a=Qk(r.node(m-1).contentMatchAt(r.indexAfter(m-1))),i.unshift(l&&a?{type:a}:null),o=m;break}else{if(m==1)return!1;i.unshift(null)}let d=e.tr;(e.selection instanceof rt||e.selection instanceof Bs)&&d.deleteSelection();let f=d.mapping.map(r.pos),p=Pa(d.doc,f,i.length,i);if(p||(i[0]=a?{type:a}:null,p=Pa(d.doc,f,i.length,i)),d.split(f,i.length,i),!l&&c&&r.node(o).type!=a){let m=d.mapping.map(r.before(o)),y=d.doc.resolve(m);a&&r.node(o-1).canReplaceWith(y.index(),y.index()+1,a)&&d.setNodeMarkup(d.mapping.map(r.before(o)),a)}return t&&t(d.scrollIntoView()),!0}}const _Z=IZ(),TZ=(n,e)=>{let{$from:t,to:r}=n.selection,s,i=t.sharedDepth(r);return i==0?!1:(s=t.before(i),e&&e(n.tr.setSelection(We.create(n.doc,s))),!0)};function MZ(n,e,t){let r=e.nodeBefore,s=e.nodeAfter,i=e.index();return!r||!s||!r.type.compatibleContent(s.type)?!1:!r.content.size&&e.parent.canReplace(i-1,i)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(i,i+1)||!(s.isTextblock||Yl(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function I5(n,e,t,r){let s=e.nodeBefore,i=e.nodeAfter,o,a,l=s.type.spec.isolating||i.type.spec.isolating;if(!l&&MZ(n,e,t))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(a=s.contentMatchAt(s.childCount)).findWrapping(i.type))&&a.matchType(o[0]||i.type).validEnd){if(t){let m=e.pos+i.nodeSize,y=pe.empty;for(let b=o.length-1;b>=0;b--)y=pe.from(o[b].create(null,y));y=pe.from(s.copy(y));let v=n.tr.step(new Bn(e.pos-1,m,e.pos,m,new Te(y,1,0),o.length,!0)),x=v.doc.resolve(m+2*o.length);x.nodeAfter&&x.nodeAfter.type==s.type&&Yl(v.doc,x.pos)&&v.join(x.pos),t(v.scrollIntoView())}return!0}let d=i.type.spec.isolating||r>0&&l?null:at.findFrom(e,1),f=d&&d.$from.blockRange(d.$to),p=f&&rh(f);if(p!=null&&p>=e.depth)return t&&t(n.tr.lift(f,p).scrollIntoView()),!0;if(c&&$d(i,"start",!0)&&$d(s,"end")){let m=s,y=[];for(;y.push(m),!m.isTextblock;)m=m.lastChild;let v=i,x=1;for(;!v.isTextblock;v=v.firstChild)x++;if(m.canReplace(m.childCount,m.childCount,v.content)){if(t){let b=pe.empty;for(let I=y.length-1;I>=0;I--)b=pe.from(y[I].copy(b));let C=n.tr.step(new Bn(e.pos-y.length,e.pos+i.nodeSize,e.pos+x,e.pos+i.nodeSize-x,new Te(b,y.length,0),0,!0));t(C.scrollIntoView())}return!0}}return!1}function _5(n){return function(e,t){let r=e.selection,s=n<0?r.$from:r.$to,i=s.depth;for(;s.node(i).isInline;){if(!i)return!1;i--}return s.node(i).isTextblock?(t&&t(e.tr.setSelection(rt.create(e.doc,n<0?s.start(i):s.end(i)))),!0):!1}}const AZ=_5(-1),OZ=_5(1);function RZ(n,e=null){return function(t,r){let{$from:s,$to:i}=t.selection,o=s.blockRange(i),a=o&&zk(o,n,e);return a?(r&&r(t.tr.wrap(o,a).scrollIntoView()),!0):!1}}function RD(n,e=null){return function(t,r){let s=!1;for(let i=0;i<t.selection.ranges.length&&!s;i++){let{$from:{pos:o},$to:{pos:a}}=t.selection.ranges[i];t.doc.nodesBetween(o,a,(l,c)=>{if(s)return!1;if(!(!l.isTextblock||l.hasMarkup(n,e)))if(l.type==n)s=!0;else{let d=t.doc.resolve(c),f=d.index();s=d.parent.canReplaceWith(f,f+1,n)}})}if(!s)return!1;if(r){let i=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:a},$to:{pos:l}}=t.selection.ranges[o];i.setBlockType(a,l,n,e)}r(i.scrollIntoView())}return!0}}function eI(...n){return function(e,t,r){for(let s=0;s<n.length;s++)if(n[s](e,t,r))return!0;return!1}}eI(Xk,S5,x5);eI(Xk,b5,C5);eI(P5,E5,k5,_Z);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function DZ(n,e=null){return function(t,r){let{$from:s,$to:i}=t.selection,o=s.blockRange(i);if(!o)return!1;let a=r?t.tr:null;return jZ(a,o,n,e)?(r&&r(a.scrollIntoView()),!0):!1}}function jZ(n,e,t,r=null){let s=!1,i=e,o=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let l=o.resolve(e.start-2);i=new Wy(l,l,e.depth),e.endIndex<e.parent.childCount&&(e=new Wy(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),s=!0}let a=zk(i,t,r,e);return a?(n&&NZ(n,e,a,s,t),!0):!1}function NZ(n,e,t,r,s){let i=pe.empty;for(let d=t.length-1;d>=0;d--)i=pe.from(t[d].type.create(t[d].attrs,i));n.step(new Bn(e.start-(r?2:0),e.end,e.start,e.end,new Te(i,0,0),t.length,!0));let o=0;for(let d=0;d<t.length;d++)t[d].type==s&&(o=d+1);let a=t.length-o,l=e.start+t.length-(r?2:0),c=e.parent;for(let d=e.startIndex,f=e.endIndex,p=!0;d<f;d++,p=!1)!p&&Pa(n.doc,l,a)&&(n.split(l,a),l+=2*a),l+=c.child(d).nodeSize;return n}function LZ(n){return function(e,t){let{$from:r,$to:s}=e.selection,i=r.blockRange(s,o=>o.childCount>0&&o.firstChild.type==n);return i?t?r.node(i.depth-1).type==n?FZ(e,t,n,i):zZ(e,t,i):!0:!1}}function FZ(n,e,t,r){let s=n.tr,i=r.end,o=r.$to.end(r.depth);i<o&&(s.step(new Bn(i-1,o,i,o,new Te(pe.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new Wy(s.doc.resolve(r.$from.pos),s.doc.resolve(o),r.depth));const a=rh(r);if(a==null)return!1;s.lift(r,a);let l=s.doc.resolve(s.mapping.map(i,-1)-1);return Yl(s.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&s.join(l.pos),e(s.scrollIntoView()),!0}function zZ(n,e,t){let r=n.tr,s=t.parent;for(let m=t.end,y=t.endIndex-1,v=t.startIndex;y>v;y--)m-=s.child(y).nodeSize,r.delete(m-1,m+1);let i=r.doc.resolve(t.start),o=i.nodeAfter;if(r.mapping.map(t.end)!=t.start+i.nodeAfter.nodeSize)return!1;let a=t.startIndex==0,l=t.endIndex==s.childCount,c=i.node(-1),d=i.index(-1);if(!c.canReplace(d+(a?0:1),d+1,o.content.append(l?pe.empty:pe.from(s))))return!1;let f=i.pos,p=f+o.nodeSize;return r.step(new Bn(f-(a?1:0),p+(l?1:0),f+1,p-1,new Te((a?pe.empty:pe.from(s.copy(pe.empty))).append(l?pe.empty:pe.from(s.copy(pe.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function $Z(n){return function(e,t){let{$from:r,$to:s}=e.selection,i=r.blockRange(s,c=>c.childCount>0&&c.firstChild.type==n);if(!i)return!1;let o=i.startIndex;if(o==0)return!1;let a=i.parent,l=a.child(o-1);if(l.type!=n)return!1;if(t){let c=l.lastChild&&l.lastChild.type==a.type,d=pe.from(c?n.create():null),f=new Te(pe.from(n.create(null,pe.from(a.type.create(null,d)))),c?3:1,0),p=i.start,m=i.end;t(e.tr.step(new Bn(p-(c?3:1),m,p,m,f,1,!0)).scrollIntoView())}return!0}}function kv(n){const{state:e,transaction:t}=n;let{selection:r}=t,{doc:s}=t,{storedMarks:i}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return i},get selection(){return r},get doc(){return s},get tr(){return r=t.selection,s=t.doc,i=t.storedMarks,t}}}class Iv{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:r}=this,{view:s}=t,{tr:i}=r,o=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([a,l])=>[a,(...d)=>{const f=l(...d)(o);return!i.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(i),f}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:r,editor:s,state:i}=this,{view:o}=s,a=[],l=!!e,c=e||i.tr,d=()=>(!l&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),a.every(p=>p===!0)),f={...Object.fromEntries(Object.entries(r).map(([p,m])=>[p,(...v)=>{const x=this.buildProps(c,t),b=m(...v)(x);return a.push(b),f}])),run:d};return f}createCan(e){const{rawCommands:t,state:r}=this,s=!1,i=e||r.tr,o=this.buildProps(i,s);return{...Object.fromEntries(Object.entries(t).map(([l,c])=>[l,(...d)=>c(...d)({...o,dispatch:void 0})])),chain:()=>this.createChain(i,s)}}buildProps(e,t=!0){const{rawCommands:r,editor:s,state:i}=this,{view:o}=s,a={tr:e,editor:s,view:o,state:kv({state:i,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([l,c])=>[l,(...d)=>c(...d)(a)]))}};return a}}let BZ=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const r=this.callbacks[e];return r&&r.forEach(s=>s.apply(this,t)),this}off(e,t){const r=this.callbacks[e];return r&&(t?this.callbacks[e]=r.filter(s=>s!==t):delete this.callbacks[e]),this}once(e,t){const r=(...s)=>{this.off(e,r),t.apply(this,s)};return this.on(e,r)}removeAllListeners(){this.callbacks={}}};function Le(n,e,t){return n.config[e]===void 0&&n.parent?Le(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?Le(n.parent,e,t):null}):n.config[e]}function _v(n){const e=n.filter(s=>s.type==="extension"),t=n.filter(s=>s.type==="node"),r=n.filter(s=>s.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:r}}function T5(n){const e=[],{nodeExtensions:t,markExtensions:r}=_v(n),s=[...t,...r],i={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return n.forEach(o=>{const a={name:o.name,options:o.options,storage:o.storage,extensions:s},l=Le(o,"addGlobalAttributes",a);if(!l)return;l().forEach(d=>{d.types.forEach(f=>{Object.entries(d.attributes).forEach(([p,m])=>{e.push({type:f,name:p,attribute:{...i,...m}})})})})}),s.forEach(o=>{const a={name:o.name,options:o.options,storage:o.storage},l=Le(o,"addAttributes",a);if(!l)return;const c=l();Object.entries(c).forEach(([d,f])=>{const p={...i,...f};typeof(p==null?void 0:p.default)=="function"&&(p.default=p.default()),p!=null&&p.isRequired&&(p==null?void 0:p.default)===void 0&&delete p.default,e.push({type:o.name,name:d,attribute:p})})}),e}function Hn(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}function Kn(...n){return n.filter(e=>!!e).reduce((e,t)=>{const r={...e};return Object.entries(t).forEach(([s,i])=>{if(!r[s]){r[s]=i;return}if(s==="class"){const a=i?String(i).split(" "):[],l=r[s]?r[s].split(" "):[],c=a.filter(d=>!l.includes(d));r[s]=[...l,...c].join(" ")}else if(s==="style"){const a=i?i.split(";").map(d=>d.trim()).filter(Boolean):[],l=r[s]?r[s].split(";").map(d=>d.trim()).filter(Boolean):[],c=new Map;l.forEach(d=>{const[f,p]=d.split(":").map(m=>m.trim());c.set(f,p)}),a.forEach(d=>{const[f,p]=d.split(":").map(m=>m.trim());c.set(f,p)}),r[s]=Array.from(c.entries()).map(([d,f])=>`${d}: ${f}`).join("; ")}else r[s]=i}),r},{})}function VP(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,r)=>Kn(t,r),{})}function M5(n){return typeof n=="function"}function dt(n,e=void 0,...t){return M5(n)?e?n.bind(e)(...t):n(...t):n}function UZ(n={}){return Object.keys(n).length===0&&n.constructor===Object}function HZ(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function DD(n,e){return"style"in n?n:{...n,getAttrs:t=>{const r=n.getAttrs?n.getAttrs(t):n.attrs;if(r===!1)return!1;const s=e.reduce((i,o)=>{const a=o.attribute.parseHTML?o.attribute.parseHTML(t):HZ(t.getAttribute(o.name));return a==null?i:{...i,[o.name]:a}},{});return{...r,...s}}}}function jD(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&UZ(t)?!1:t!=null))}function A5(n,e){var t;const r=T5(n),{nodeExtensions:s,markExtensions:i}=_v(n),o=(t=s.find(c=>Le(c,"topNode")))===null||t===void 0?void 0:t.name,a=Object.fromEntries(s.map(c=>{const d=r.filter(b=>b.type===c.name),f={name:c.name,options:c.options,storage:c.storage,editor:e},p=n.reduce((b,C)=>{const I=Le(C,"extendNodeSchema",f);return{...b,...I?I(c):{}}},{}),m=jD({...p,content:dt(Le(c,"content",f)),marks:dt(Le(c,"marks",f)),group:dt(Le(c,"group",f)),inline:dt(Le(c,"inline",f)),atom:dt(Le(c,"atom",f)),selectable:dt(Le(c,"selectable",f)),draggable:dt(Le(c,"draggable",f)),code:dt(Le(c,"code",f)),whitespace:dt(Le(c,"whitespace",f)),linebreakReplacement:dt(Le(c,"linebreakReplacement",f)),defining:dt(Le(c,"defining",f)),isolating:dt(Le(c,"isolating",f)),attrs:Object.fromEntries(d.map(b=>{var C;return[b.name,{default:(C=b==null?void 0:b.attribute)===null||C===void 0?void 0:C.default}]}))}),y=dt(Le(c,"parseHTML",f));y&&(m.parseDOM=y.map(b=>DD(b,d)));const v=Le(c,"renderHTML",f);v&&(m.toDOM=b=>v({node:b,HTMLAttributes:VP(b,d)}));const x=Le(c,"renderText",f);return x&&(m.toText=x),[c.name,m]})),l=Object.fromEntries(i.map(c=>{const d=r.filter(x=>x.type===c.name),f={name:c.name,options:c.options,storage:c.storage,editor:e},p=n.reduce((x,b)=>{const C=Le(b,"extendMarkSchema",f);return{...x,...C?C(c):{}}},{}),m=jD({...p,inclusive:dt(Le(c,"inclusive",f)),excludes:dt(Le(c,"excludes",f)),group:dt(Le(c,"group",f)),spanning:dt(Le(c,"spanning",f)),code:dt(Le(c,"code",f)),attrs:Object.fromEntries(d.map(x=>{var b;return[x.name,{default:(b=x==null?void 0:x.attribute)===null||b===void 0?void 0:b.default}]}))}),y=dt(Le(c,"parseHTML",f));y&&(m.parseDOM=y.map(x=>DD(x,d)));const v=Le(c,"renderHTML",f);return v&&(m.toDOM=x=>v({mark:x,HTMLAttributes:VP(x,d)})),[c.name,m]}));return new SF({topNode:o,nodes:a,marks:l})}function K1(n,e){return e.nodes[n]||e.marks[n]||null}function ND(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Tv(n,e){const t=hu.fromSchema(e).serializeFragment(n),s=document.implementation.createHTMLDocument().createElement("div");return s.appendChild(t),s.innerHTML}const KZ=(n,e=500)=>{let t="";const r=n.parentOffset;return n.parent.nodesBetween(Math.max(0,r-e),r,(s,i,o,a)=>{var l,c;const d=((c=(l=s.type.spec).toText)===null||c===void 0?void 0:c.call(l,{node:s,pos:i,parent:o,index:a}))||s.textContent||"%leaf%";t+=s.isAtom&&!s.isText?d:d.slice(0,Math.max(0,r-i))}),t};function tI(n){return Object.prototype.toString.call(n)==="[object RegExp]"}class Mv{constructor(e){this.find=e.find,this.handler=e.handler}}const WZ=(n,e)=>{if(tI(e))return e.exec(n);const t=e(n);if(!t)return null;const r=[t.text];return r.index=t.index,r.input=n,r.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(t.replaceWith)),r};function um(n){var e;const{editor:t,from:r,to:s,text:i,rules:o,plugin:a}=n,{view:l}=t;if(l.composing)return!1;const c=l.state.doc.resolve(r);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(p=>p.type.spec.code))return!1;let d=!1;const f=KZ(c)+i;return o.forEach(p=>{if(d)return;const m=WZ(f,p.find);if(!m)return;const y=l.state.tr,v=kv({state:l.state,transaction:y}),x={from:r-(m[0].length-i.length),to:s},{commands:b,chain:C,can:I}=new Iv({editor:t,state:v});p.handler({state:v,range:x,match:m,commands:b,chain:C,can:I})===null||!y.steps.length||(y.setMeta(a,{transform:y,from:r,to:s,text:i}),l.dispatch(y),d=!0)}),d}function VZ(n){const{editor:e,rules:t}=n,r=new lr({state:{init(){return null},apply(s,i,o){const a=s.getMeta(r);if(a)return a;const l=s.getMeta("applyInputRules");return!!l&&setTimeout(()=>{let{text:d}=l;typeof d=="string"?d=d:d=Tv(pe.from(d),o.schema);const{from:f}=l,p=f+d.length;um({editor:e,from:f,to:p,text:d,rules:t,plugin:r})}),s.selectionSet||s.docChanged?null:i}},props:{handleTextInput(s,i,o,a){return um({editor:e,from:i,to:o,text:a,rules:t,plugin:r})},handleDOMEvents:{compositionend:s=>(setTimeout(()=>{const{$cursor:i}=s.state.selection;i&&um({editor:e,from:i.pos,to:i.pos,text:"",rules:t,plugin:r})}),!1)},handleKeyDown(s,i){if(i.key!=="Enter")return!1;const{$cursor:o}=s.state.selection;return o?um({editor:e,from:o.pos,to:o.pos,text:`
95
+ `,rules:t,plugin:r}):!1}},isInputRules:!0});return r}function qZ(n){return Object.prototype.toString.call(n).slice(8,-1)}function dm(n){return qZ(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Av(n,e){const t={...n};return dm(n)&&dm(e)&&Object.keys(e).forEach(r=>{dm(e[r])&&dm(n[r])?t[r]=Av(n[r],e[r]):t[r]=e[r]}),t}class Lo{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=dt(Le(this,"addOptions",{name:this.name}))),this.storage=dt(Le(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Lo(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>Av(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new Lo(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=dt(Le(t,"addOptions",{name:t.name})),t.storage=dt(Le(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:r}=e.state,s=e.state.selection.$from;if(s.pos===s.end()){const o=s.marks();if(!!!o.find(c=>(c==null?void 0:c.type.name)===t.name))return!1;const l=o.find(c=>(c==null?void 0:c.type.name)===t.name);return l&&r.removeStoredMark(l),r.insertText(" ",s.pos),e.view.dispatch(r),!0}return!1}}function GZ(n){return typeof n=="number"}class YZ{constructor(e){this.find=e.find,this.handler=e.handler}}const XZ=(n,e,t)=>{if(tI(e))return[...n.matchAll(e)];const r=e(n,t);return r?r.map(s=>{const i=[s.text];return i.index=s.index,i.input=n,i.data=s.data,s.replaceWith&&(s.text.includes(s.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),i.push(s.replaceWith)),i}):[]};function ZZ(n){const{editor:e,state:t,from:r,to:s,rule:i,pasteEvent:o,dropEvent:a}=n,{commands:l,chain:c,can:d}=new Iv({editor:e,state:t}),f=[];return t.doc.nodesBetween(r,s,(m,y)=>{if(!m.isTextblock||m.type.spec.code)return;const v=Math.max(r,y),x=Math.min(s,y+m.content.size),b=m.textBetween(v-y,x-y,void 0,"");XZ(b,i.find,o).forEach(I=>{if(I.index===void 0)return;const _=v+I.index+1,T=_+I[0].length,A={from:t.tr.mapping.map(_),to:t.tr.mapping.map(T)},R=i.handler({state:t,range:A,match:I,commands:l,chain:c,can:d,pasteEvent:o,dropEvent:a});f.push(R)})}),f.every(m=>m!==null)}let hm=null;const JZ=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)===null||e===void 0||e.setData("text/html",n),t};function QZ(n){const{editor:e,rules:t}=n;let r=null,s=!1,i=!1,o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,a;try{a=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{a=null}const l=({state:d,from:f,to:p,rule:m,pasteEvt:y})=>{const v=d.tr,x=kv({state:d,transaction:v});if(!(!ZZ({editor:e,state:x,from:Math.max(f-1,0),to:p.b-1,rule:m,pasteEvent:y,dropEvent:a})||!v.steps.length)){try{a=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{a=null}return o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,v}};return t.map(d=>new lr({view(f){const p=y=>{var v;r=!((v=f.dom.parentElement)===null||v===void 0)&&v.contains(y.target)?f.dom.parentElement:null,r&&(hm=e)},m=()=>{hm&&(hm=null)};return window.addEventListener("dragstart",p),window.addEventListener("dragend",m),{destroy(){window.removeEventListener("dragstart",p),window.removeEventListener("dragend",m)}}},props:{handleDOMEvents:{drop:(f,p)=>{if(i=r===f.dom.parentElement,a=p,!i){const m=hm;m&&setTimeout(()=>{const y=m.state.selection;y&&m.commands.deleteRange({from:y.from,to:y.to})},10)}return!1},paste:(f,p)=>{var m;const y=(m=p.clipboardData)===null||m===void 0?void 0:m.getData("text/html");return o=p,s=!!(y!=null&&y.includes("data-pm-slice")),!1}}},appendTransaction:(f,p,m)=>{const y=f[0],v=y.getMeta("uiEvent")==="paste"&&!s,x=y.getMeta("uiEvent")==="drop"&&!i,b=y.getMeta("applyPasteRules"),C=!!b;if(!v&&!x&&!C)return;if(C){let{text:T}=b;typeof T=="string"?T=T:T=Tv(pe.from(T),m.schema);const{from:A}=b,R=A+T.length,j=JZ(T);return l({rule:d,state:m,from:A,to:{b:R},pasteEvt:j})}const I=p.doc.content.findDiffStart(m.doc.content),_=p.doc.content.findDiffEnd(m.doc.content);if(!(!GZ(I)||!_||I===_.b))return l({rule:d,state:m,from:I,to:_,pasteEvt:o})}}))}function eJ(n){const e=n.filter((t,r)=>n.indexOf(t)!==r);return Array.from(new Set(e))}class Rc{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=Rc.resolve(e),this.schema=A5(this.extensions,t),this.setupExtensions()}static resolve(e){const t=Rc.sort(Rc.flatten(e)),r=eJ(t.map(s=>s.name));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(s=>`'${s}'`).join(", ")}]. This can lead to issues.`),t}static flatten(e){return e.map(t=>{const r={name:t.name,options:t.options,storage:t.storage},s=Le(t,"addExtensions",r);return s?[t,...this.flatten(s())]:t}).flat(10)}static sort(e){return e.sort((r,s)=>{const i=Le(r,"priority")||100,o=Le(s,"priority")||100;return i>o?-1:i<o?1:0})}get commands(){return this.extensions.reduce((e,t)=>{const r={name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:K1(t.name,this.schema)},s=Le(t,"addCommands",r);return s?{...e,...s()}:e},{})}get plugins(){const{editor:e}=this,t=Rc.sort([...this.extensions].reverse()),r=[],s=[],i=t.map(o=>{const a={name:o.name,options:o.options,storage:o.storage,editor:e,type:K1(o.name,this.schema)},l=[],c=Le(o,"addKeyboardShortcuts",a);let d={};if(o.type==="mark"&&Le(o,"exitable",a)&&(d.ArrowRight=()=>Lo.handleExit({editor:e,mark:o})),c){const v=Object.fromEntries(Object.entries(c()).map(([x,b])=>[x,()=>b({editor:e})]));d={...d,...v}}const f=xZ(d);l.push(f);const p=Le(o,"addInputRules",a);ND(o,e.options.enableInputRules)&&p&&r.push(...p());const m=Le(o,"addPasteRules",a);ND(o,e.options.enablePasteRules)&&m&&s.push(...m());const y=Le(o,"addProseMirrorPlugins",a);if(y){const v=y();l.push(...v)}return l}).flat();return[VZ({editor:e,rules:r}),...QZ({editor:e,rules:s}),...i]}get attributes(){return T5(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=_v(this.extensions);return Object.fromEntries(t.filter(r=>!!Le(r,"addNodeView")).map(r=>{const s=this.attributes.filter(l=>l.type===r.name),i={name:r.name,options:r.options,storage:r.storage,editor:e,type:Hn(r.name,this.schema)},o=Le(r,"addNodeView",i);if(!o)return[];const a=(l,c,d,f,p)=>{const m=VP(l,s);return o()({node:l,view:c,getPos:d,decorations:f,innerDecorations:p,editor:e,extension:r,HTMLAttributes:m})};return[r.name,a]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const r={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:K1(e.name,this.schema)};e.type==="mark"&&(!((t=dt(Le(e,"keepOnSplit",r)))!==null&&t!==void 0)||t)&&this.splittableMarks.push(e.name);const s=Le(e,"onBeforeCreate",r),i=Le(e,"onCreate",r),o=Le(e,"onUpdate",r),a=Le(e,"onSelectionUpdate",r),l=Le(e,"onTransaction",r),c=Le(e,"onFocus",r),d=Le(e,"onBlur",r),f=Le(e,"onDestroy",r);s&&this.editor.on("beforeCreate",s),i&&this.editor.on("create",i),o&&this.editor.on("update",o),a&&this.editor.on("selectionUpdate",a),l&&this.editor.on("transaction",l),c&&this.editor.on("focus",c),d&&this.editor.on("blur",d),f&&this.editor.on("destroy",f)})}}class or{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=dt(Le(this,"addOptions",{name:this.name}))),this.storage=dt(Le(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new or(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>Av(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new or({...this.config,...e});return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=dt(Le(t,"addOptions",{name:t.name})),t.storage=dt(Le(t,"addStorage",{name:t.name,options:t.options})),t}}function O5(n,e,t){const{from:r,to:s}=e,{blockSeparator:i=`
96
+
97
+ `,textSerializers:o={}}=t||{};let a="";return n.nodesBetween(r,s,(l,c,d,f)=>{var p;l.isBlock&&c>r&&(a+=i);const m=o==null?void 0:o[l.type.name];if(m)return d&&(a+=m({node:l,pos:c,parent:d,index:f,range:e})),!1;l.isText&&(a+=(p=l==null?void 0:l.text)===null||p===void 0?void 0:p.slice(Math.max(r,c)-c,s-c))}),a}function nI(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const tJ=or.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new lr({key:new qs("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:r,selection:s}=e,{ranges:i}=s,o=Math.min(...i.map(d=>d.$from.pos)),a=Math.max(...i.map(d=>d.$to.pos)),l=nI(t);return O5(r,{from:o,to:a},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),nJ=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),rJ=(n=!1)=>({commands:e})=>e.setContent("",n),sJ=()=>({state:n,tr:e,dispatch:t})=>{const{selection:r}=e,{ranges:s}=r;return t&&s.forEach(({$from:i,$to:o})=>{n.doc.nodesBetween(i.pos,o.pos,(a,l)=>{if(a.type.isText)return;const{doc:c,mapping:d}=e,f=c.resolve(d.map(l)),p=c.resolve(d.map(l+a.nodeSize)),m=f.blockRange(p);if(!m)return;const y=rh(m);if(a.type.isTextblock){const{defaultType:v}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(m.start,v)}(y||y===0)&&e.lift(m,y)})}),!0},iJ=n=>e=>n(e),oJ=()=>({state:n,dispatch:e})=>E5(n,e),aJ=(n,e)=>({editor:t,tr:r})=>{const{state:s}=t,i=s.doc.slice(n.from,n.to);r.deleteRange(n.from,n.to);const o=r.mapping.map(e);return r.insert(o,i.content),r.setSelection(new rt(r.doc.resolve(o-1))),!0},lJ=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,r=t.$anchor.node();if(r.content.size>0)return!1;const s=n.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===r.type){if(e){const a=s.before(i),l=s.after(i);n.delete(a,l).scrollIntoView()}return!0}return!1},cJ=n=>({tr:e,state:t,dispatch:r})=>{const s=Hn(n,t.schema),i=e.selection.$anchor;for(let o=i.depth;o>0;o-=1)if(i.node(o).type===s){if(r){const l=i.before(o),c=i.after(o);e.delete(l,c).scrollIntoView()}return!0}return!1},uJ=n=>({tr:e,dispatch:t})=>{const{from:r,to:s}=n;return t&&e.delete(r,s),!0},dJ=()=>({state:n,dispatch:e})=>Xk(n,e),hJ=()=>({commands:n})=>n.keyboardShortcut("Enter"),fJ=()=>({state:n,dispatch:e})=>kZ(n,e);function Qy(n,e,t={strict:!0}){const r=Object.keys(e);return r.length?r.every(s=>t.strict?e[s]===n[s]:tI(e[s])?e[s].test(n[s]):e[s]===n[s]):!0}function R5(n,e,t={}){return n.find(r=>r.type===e&&Qy(Object.fromEntries(Object.keys(t).map(s=>[s,r.attrs[s]])),t))}function LD(n,e,t={}){return!!R5(n,e,t)}function Ov(n,e,t){var r;if(!n||!e)return;let s=n.parent.childAfter(n.parentOffset);if((!s.node||!s.node.marks.some(d=>d.type===e))&&(s=n.parent.childBefore(n.parentOffset)),!s.node||!s.node.marks.some(d=>d.type===e)||(t=t||((r=s.node.marks[0])===null||r===void 0?void 0:r.attrs),!R5([...s.node.marks],e,t)))return;let o=s.index,a=n.start()+s.offset,l=o+1,c=a+s.node.nodeSize;for(;o>0&&LD([...n.parent.child(o-1).marks],e,t);)o-=1,a-=n.parent.child(o).nodeSize;for(;l<n.parent.childCount&&LD([...n.parent.child(l).marks],e,t);)c+=n.parent.child(l).nodeSize,l+=1;return{from:a,to:c}}function Zl(n,e){if(typeof n=="string"){if(!e.marks[n])throw Error(`There is no mark type named '${n}'. Maybe you forgot to add the extension?`);return e.marks[n]}return n}const pJ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{const i=Zl(n,r.schema),{doc:o,selection:a}=t,{$from:l,from:c,to:d}=a;if(s){const f=Ov(l,i,e);if(f&&f.from<=c&&f.to>=d){const p=rt.create(o,f.from,f.to);t.setSelection(p)}}return!0},gJ=n=>e=>{const t=typeof n=="function"?n(e):n;for(let r=0;r<t.length;r+=1)if(t[r](e))return!0;return!1};function D5(n){return n instanceof rt}function Dc(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function j5(n,e=null){if(!e)return null;const t=at.atStart(n),r=at.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return r;const s=t.from,i=r.to;return e==="all"?rt.create(n,Dc(0,s,i),Dc(n.content.size,s,i)):rt.create(n,Dc(e,s,i),Dc(e,s,i))}function mJ(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function rI(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const yJ=(n=null,e={})=>({editor:t,view:r,tr:s,dispatch:i})=>{e={scrollIntoView:!0,...e};const o=()=>{(rI()||mJ())&&r.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};if(r.hasFocus()&&n===null||n===!1)return!0;if(i&&n===null&&!D5(t.state.selection))return o(),!0;const a=j5(s.doc,n)||t.state.selection,l=t.state.selection.eq(a);return i&&(l||s.setSelection(a),l&&s.storedMarks&&s.setStoredMarks(s.storedMarks),o()),!0},SJ=(n,e)=>t=>n.every((r,s)=>e(r,{...t,index:s})),vJ=(n,e)=>({tr:t,commands:r})=>r.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),N5=n=>{const e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){const r=e[t];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?n.removeChild(r):r.nodeType===1&&N5(r)}return n};function yf(n){const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return N5(t)}function eS(n,e,t){if(n instanceof Gi||n instanceof pe)return n;t={slice:!0,parseOptions:{},...t};const r=typeof n=="object"&&n!==null,s=typeof n=="string";if(r)try{if(Array.isArray(n)&&n.length>0)return pe.fromArray(n.map(a=>e.nodeFromJSON(a)));const o=e.nodeFromJSON(n);return t.errorOnInvalidContent&&o.check(),o}catch(i){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:i});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",i),eS("",e,t)}if(s){if(t.errorOnInvalidContent){let o=!1,a="";const l=new SF({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(o=!0,a=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?Cd.fromSchema(l).parseSlice(yf(n),t.parseOptions):Cd.fromSchema(l).parse(yf(n),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${a}`)})}const i=Cd.fromSchema(e);return t.slice?i.parseSlice(yf(n),t.parseOptions).content:i.parse(yf(n),t.parseOptions)}return eS("",e,t)}function xJ(n,e,t){const r=n.steps.length-1;if(r<e)return;const s=n.steps[r];if(!(s instanceof Fn||s instanceof Bn))return;const i=n.mapping.maps[r];let o=0;i.forEach((a,l,c,d)=>{o===0&&(o=d)}),n.setSelection(at.near(n.doc.resolve(o),t))}const wJ=n=>!("type"in n),bJ=(n,e,t)=>({tr:r,dispatch:s,editor:i})=>{var o;if(s){t={parseOptions:i.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let a;try{a=eS(e,i.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions},errorOnInvalidContent:(o=t.errorOnInvalidContent)!==null&&o!==void 0?o:i.options.enableContentCheck})}catch(y){return i.emit("contentError",{editor:i,error:y,disableCollaboration:()=>{i.storage.collaboration&&(i.storage.collaboration.isDisabled=!0)}}),!1}let{from:l,to:c}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},d=!0,f=!0;if((wJ(a)?a:[a]).forEach(y=>{y.check(),d=d?y.isText&&y.marks.length===0:!1,f=f?y.isBlock:!1}),l===c&&f){const{parent:y}=r.doc.resolve(l);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(l-=1,c+=1)}let m;if(d){if(Array.isArray(e))m=e.map(y=>y.text||"").join("");else if(e instanceof pe){let y="";e.forEach(v=>{v.text&&(y+=v.text)}),m=y}else typeof e=="object"&&e&&e.text?m=e.text:m=e;r.insertText(m,l,c)}else m=a,r.replaceWith(l,c,m);t.updateSelection&&xJ(r,r.steps.length-1,-1),t.applyInputRules&&r.setMeta("applyInputRules",{from:l,text:m}),t.applyPasteRules&&r.setMeta("applyPasteRules",{from:l,text:m})}return!0},CJ=()=>({state:n,dispatch:e})=>CZ(n,e),PJ=()=>({state:n,dispatch:e})=>PZ(n,e),EJ=()=>({state:n,dispatch:e})=>S5(n,e),kJ=()=>({state:n,dispatch:e})=>b5(n,e),IJ=()=>({state:n,dispatch:e,tr:t})=>{try{const r=xv(n.doc,n.selection.$from.pos,-1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},_J=()=>({state:n,dispatch:e,tr:t})=>{try{const r=xv(n.doc,n.selection.$from.pos,1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},TJ=()=>({state:n,dispatch:e})=>wZ(n,e),MJ=()=>({state:n,dispatch:e})=>bZ(n,e);function L5(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function AJ(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let r,s,i,o;for(let a=0;a<e.length-1;a+=1){const l=e[a];if(/^(cmd|meta|m)$/i.test(l))o=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))s=!0;else if(/^s(hift)?$/i.test(l))i=!0;else if(/^mod$/i.test(l))rI()||L5()?o=!0:s=!0;else throw new Error(`Unrecognized modifier name: ${l}`)}return r&&(t=`Alt-${t}`),s&&(t=`Ctrl-${t}`),o&&(t=`Meta-${t}`),i&&(t=`Shift-${t}`),t}const OJ=n=>({editor:e,view:t,tr:r,dispatch:s})=>{const i=AJ(n).split(/-(?!$)/),o=i.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),a=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:i.includes("Alt"),ctrlKey:i.includes("Ctrl"),metaKey:i.includes("Meta"),shiftKey:i.includes("Shift"),bubbles:!0,cancelable:!0}),l=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,a))});return l==null||l.steps.forEach(c=>{const d=c.map(r.mapping);d&&s&&r.maybeStep(d)}),!0};function rp(n,e,t={}){const{from:r,to:s,empty:i}=n.selection,o=e?Hn(e,n.schema):null,a=[];n.doc.nodesBetween(r,s,(f,p)=>{if(f.isText)return;const m=Math.max(r,p),y=Math.min(s,p+f.nodeSize);a.push({node:f,from:m,to:y})});const l=s-r,c=a.filter(f=>o?o.name===f.node.type.name:!0).filter(f=>Qy(f.node.attrs,t,{strict:!1}));return i?!!c.length:c.reduce((f,p)=>f+p.to-p.from,0)>=l}const RJ=(n,e={})=>({state:t,dispatch:r})=>{const s=Hn(n,t.schema);return rp(t,s,e)?EZ(t,r):!1},DJ=()=>({state:n,dispatch:e})=>k5(n,e),jJ=n=>({state:e,dispatch:t})=>{const r=Hn(n,e.schema);return LZ(r)(e,t)},NJ=()=>({state:n,dispatch:e})=>P5(n,e);function Rv(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function FD(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((r,s)=>(t.includes(s)||(r[s]=n[s]),r),{})}const LJ=(n,e)=>({tr:t,state:r,dispatch:s})=>{let i=null,o=null;const a=Rv(typeof n=="string"?n:n.name,r.schema);return a?(a==="node"&&(i=Hn(n,r.schema)),a==="mark"&&(o=Zl(n,r.schema)),s&&t.selection.ranges.forEach(l=>{r.doc.nodesBetween(l.$from.pos,l.$to.pos,(c,d)=>{i&&i===c.type&&t.setNodeMarkup(d,void 0,FD(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(f=>{o===f.type&&t.addMark(d,d+c.nodeSize,o.create(FD(f.attrs,e)))})})}),!0):!1},FJ=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),zJ=()=>({tr:n,dispatch:e})=>{if(e){const t=new Bs(n.doc);n.setSelection(t)}return!0},$J=()=>({state:n,dispatch:e})=>x5(n,e),BJ=()=>({state:n,dispatch:e})=>C5(n,e),UJ=()=>({state:n,dispatch:e})=>TZ(n,e),HJ=()=>({state:n,dispatch:e})=>OZ(n,e),KJ=()=>({state:n,dispatch:e})=>AZ(n,e);function qP(n,e,t={},r={}){return eS(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:r.errorOnInvalidContent})}const WJ=(n,e=!1,t={},r={})=>({editor:s,tr:i,dispatch:o,commands:a})=>{var l,c;const{doc:d}=i;if(t.preserveWhitespace!=="full"){const f=qP(n,s.schema,t,{errorOnInvalidContent:(l=r.errorOnInvalidContent)!==null&&l!==void 0?l:s.options.enableContentCheck});return o&&i.replaceWith(0,d.content.size,f).setMeta("preventUpdate",!e),!0}return o&&i.setMeta("preventUpdate",!e),a.insertContentAt({from:0,to:d.content.size},n,{parseOptions:t,errorOnInvalidContent:(c=r.errorOnInvalidContent)!==null&&c!==void 0?c:s.options.enableContentCheck})};function F5(n,e){const t=Zl(e,n.schema),{from:r,to:s,empty:i}=n.selection,o=[];i?(n.storedMarks&&o.push(...n.storedMarks),o.push(...n.selection.$head.marks())):n.doc.nodesBetween(r,s,l=>{o.push(...l.marks)});const a=o.find(l=>l.type.name===t.name);return a?{...a.attrs}:{}}function VJ(n,e){const t=new DF(n);return e.forEach(r=>{r.steps.forEach(s=>{t.step(s)})}),t}function qJ(n){for(let e=0;e<n.edgeCount;e+=1){const{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function GJ(n,e,t){const r=[];return n.nodesBetween(e.from,e.to,(s,i)=>{t(s)&&r.push({node:s,pos:i})}),r}function YJ(n,e){for(let t=n.depth;t>0;t-=1){const r=n.node(t);if(e(r))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:r}}}function sI(n){return e=>YJ(e.$from,n)}function Dv(n,e){const t=Rc.resolve(n);return A5(t,e)}function XJ(n,e){const t=Dv(e),r=Gi.fromJSON(t,n);return Tv(r.content,t)}function ZJ(n,e){const t=Dv(e),r=yf(n);return Cd.fromSchema(t).parse(r).toJSON()}function z5(n,e){const t={from:0,to:n.content.size};return O5(n,t,e)}function JJ(n,e,t){const{blockSeparator:r=`
98
+
99
+ `,textSerializers:s={}}=t||{},i=Dv(e),o=Gi.fromJSON(i,n);return z5(o,{blockSeparator:r,textSerializers:{...nI(i),...s}})}function QJ(n,e){const t=Hn(e,n.schema),{from:r,to:s}=n.selection,i=[];n.doc.nodesBetween(r,s,a=>{i.push(a)});const o=i.reverse().find(a=>a.type.name===t.name);return o?{...o.attrs}:{}}function $5(n,e){const t=Rv(typeof e=="string"?e:e.name,n.schema);return t==="node"?QJ(n,e):t==="mark"?F5(n,e):{}}function eQ(n,e=JSON.stringify){const t={};return n.filter(r=>{const s=e(r);return Object.prototype.hasOwnProperty.call(t,s)?!1:t[s]=!0})}function tQ(n){const e=eQ(n);return e.length===1?e:e.filter((t,r)=>!e.filter((i,o)=>o!==r).some(i=>t.oldRange.from>=i.oldRange.from&&t.oldRange.to<=i.oldRange.to&&t.newRange.from>=i.newRange.from&&t.newRange.to<=i.newRange.to))}function nQ(n){const{mapping:e,steps:t}=n,r=[];return e.maps.forEach((s,i)=>{const o=[];if(s.ranges.length)s.forEach((a,l)=>{o.push({from:a,to:l})});else{const{from:a,to:l}=t[i];if(a===void 0||l===void 0)return;o.push({from:a,to:l})}o.forEach(({from:a,to:l})=>{const c=e.slice(i).map(a,-1),d=e.slice(i).map(l),f=e.invert().map(c,-1),p=e.invert().map(d);r.push({oldRange:{from:f,to:p},newRange:{from:c,to:d}})})}),tQ(r)}function iI(n,e,t){const r=[];return n===e?t.resolve(n).marks().forEach(s=>{const i=t.resolve(n),o=Ov(i,s.type);o&&r.push({mark:s,...o})}):t.nodesBetween(n,e,(s,i)=>{!s||(s==null?void 0:s.nodeSize)===void 0||r.push(...s.marks.map(o=>({from:i,to:i+s.nodeSize,mark:o})))}),r}function ey(n,e,t){return Object.fromEntries(Object.entries(t).filter(([r])=>{const s=n.find(i=>i.type===e&&i.name===r);return s?s.attribute.keepOnSplit:!1}))}function GP(n,e,t={}){const{empty:r,ranges:s}=n.selection,i=e?Zl(e,n.schema):null;if(r)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>i?i.name===f.type.name:!0).find(f=>Qy(f.attrs,t,{strict:!1}));let o=0;const a=[];if(s.forEach(({$from:f,$to:p})=>{const m=f.pos,y=p.pos;n.doc.nodesBetween(m,y,(v,x)=>{if(!v.isText&&!v.marks.length)return;const b=Math.max(m,x),C=Math.min(y,x+v.nodeSize),I=C-b;o+=I,a.push(...v.marks.map(_=>({mark:_,from:b,to:C})))})}),o===0)return!1;const l=a.filter(f=>i?i.name===f.mark.type.name:!0).filter(f=>Qy(f.mark.attrs,t,{strict:!1})).reduce((f,p)=>f+p.to-p.from,0),c=a.filter(f=>i?f.mark.type!==i&&f.mark.type.excludes(i):!0).reduce((f,p)=>f+p.to-p.from,0);return(l>0?l+c:l)>=o}function rQ(n,e,t={}){if(!e)return rp(n,null,t)||GP(n,null,t);const r=Rv(e,n.schema);return r==="node"?rp(n,e,t):r==="mark"?GP(n,e,t):!1}function zD(n,e){const{nodeExtensions:t}=_v(e),r=t.find(o=>o.name===n);if(!r)return!1;const s={name:r.name,options:r.options,storage:r.storage},i=dt(Le(r,"group",s));return typeof i!="string"?!1:i.split(" ").includes("list")}function oI(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var r;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((r=n.text)!==null&&r!==void 0?r:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let s=!0;return n.content.forEach(i=>{s!==!1&&(oI(i,{ignoreWhitespace:t,checkChildren:e})||(s=!1))}),s}return!1}function sQ(n){return n instanceof We}function iQ(n,e,t){var r;const{selection:s}=e;let i=null;if(D5(s)&&(i=s.$cursor),i){const a=(r=n.storedMarks)!==null&&r!==void 0?r:i.marks();return!!t.isInSet(a)||!a.some(l=>l.type.excludes(t))}const{ranges:o}=s;return o.some(({$from:a,$to:l})=>{let c=a.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(a.pos,l.pos,(d,f,p)=>{if(c)return!1;if(d.isInline){const m=!p||p.type.allowsMarkType(t),y=!!t.isInSet(d.marks)||!d.marks.some(v=>v.type.excludes(t));c=m&&y}return!c}),c})}const oQ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{const{selection:i}=t,{empty:o,ranges:a}=i,l=Zl(n,r.schema);if(s)if(o){const c=F5(r,l);t.addStoredMark(l.create({...c,...e}))}else a.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(p,m)=>{const y=Math.max(m,d),v=Math.min(m+p.nodeSize,f);p.marks.find(b=>b.type===l)?p.marks.forEach(b=>{l===b.type&&t.addMark(y,v,l.create({...b.attrs,...e}))}):t.addMark(y,v,l.create(e))})});return iQ(r,t,l)},aQ=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),lQ=(n,e={})=>({state:t,dispatch:r,chain:s})=>{const i=Hn(n,t.schema);let o;return t.selection.$anchor.sameParent(t.selection.$head)&&(o=t.selection.$anchor.parent.attrs),i.isTextblock?s().command(({commands:a})=>RD(i,{...o,...e})(t)?!0:a.clearNodes()).command(({state:a})=>RD(i,{...o,...e})(a,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},cQ=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,s=Dc(n,0,r.content.size),i=We.create(r,s);e.setSelection(i)}return!0},uQ=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,{from:s,to:i}=typeof n=="number"?{from:n,to:n}:n,o=rt.atStart(r).from,a=rt.atEnd(r).to,l=Dc(s,o,a),c=Dc(i,o,a),d=rt.create(r,l,c);e.setSelection(d)}return!0},dQ=n=>({state:e,dispatch:t})=>{const r=Hn(n,e.schema);return $Z(r)(e,t)};function $D(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const r=t.filter(s=>e==null?void 0:e.includes(s.type.name));n.tr.ensureMarks(r)}}const hQ=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:r,editor:s})=>{const{selection:i,doc:o}=e,{$from:a,$to:l}=i,c=s.extensionManager.attributes,d=ey(c,a.node().type.name,a.node().attrs);if(i instanceof We&&i.node.isBlock)return!a.parentOffset||!Pa(o,a.pos)?!1:(r&&(n&&$D(t,s.extensionManager.splittableMarks),e.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;const f=l.parentOffset===l.parent.content.size,p=a.depth===0?void 0:qJ(a.node(-1).contentMatchAt(a.indexAfter(-1)));let m=f&&p?[{type:p,attrs:d}]:void 0,y=Pa(e.doc,e.mapping.map(a.pos),1,m);if(!m&&!y&&Pa(e.doc,e.mapping.map(a.pos),1,p?[{type:p}]:void 0)&&(y=!0,m=p?[{type:p,attrs:d}]:void 0),r){if(y&&(i instanceof rt&&e.deleteSelection(),e.split(e.mapping.map(a.pos),1,m),p&&!f&&!a.parentOffset&&a.parent.type!==p)){const v=e.mapping.map(a.before()),x=e.doc.resolve(v);a.node(-1).canReplaceWith(x.index(),x.index()+1,p)&&e.setNodeMarkup(e.mapping.map(a.before()),p)}n&&$D(t,s.extensionManager.splittableMarks),e.scrollIntoView()}return y},fQ=(n,e={})=>({tr:t,state:r,dispatch:s,editor:i})=>{var o;const a=Hn(n,r.schema),{$from:l,$to:c}=r.selection,d=r.selection.node;if(d&&d.isBlock||l.depth<2||!l.sameParent(c))return!1;const f=l.node(-1);if(f.type!==a)return!1;const p=i.extensionManager.attributes;if(l.parent.content.size===0&&l.node(-1).childCount===l.indexAfter(-1)){if(l.depth===2||l.node(-3).type!==a||l.index(-2)!==l.node(-2).childCount-1)return!1;if(s){let b=pe.empty;const C=l.index(-1)?1:l.index(-2)?2:3;for(let j=l.depth-C;j>=l.depth-3;j-=1)b=pe.from(l.node(j).copy(b));const I=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,_={...ey(p,l.node().type.name,l.node().attrs),...e},T=((o=a.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(_))||void 0;b=b.append(pe.from(a.createAndFill(null,T)||void 0));const A=l.before(l.depth-(C-1));t.replace(A,l.after(-I),new Te(b,4-C,0));let R=-1;t.doc.nodesBetween(A,t.doc.content.size,(j,K)=>{if(R>-1)return!1;j.isTextblock&&j.content.size===0&&(R=K+1)}),R>-1&&t.setSelection(rt.near(t.doc.resolve(R))),t.scrollIntoView()}return!0}const m=c.pos===l.end()?f.contentMatchAt(0).defaultType:null,y={...ey(p,f.type.name,f.attrs),...e},v={...ey(p,l.node().type.name,l.node().attrs),...e};t.delete(l.pos,c.pos);const x=m?[{type:a,attrs:y},{type:m,attrs:v}]:[{type:a,attrs:y}];if(!Pa(t.doc,l.pos,2))return!1;if(s){const{selection:b,storedMarks:C}=r,{splittableMarks:I}=i.extensionManager,_=C||b.$to.parentOffset&&b.$from.marks();if(t.split(l.pos,2,x).scrollIntoView(),!_||!s)return!0;const T=_.filter(A=>I.includes(A.type.name));t.ensureMarks(T)}return!0},W1=(n,e)=>{const t=sI(o=>o.type===e)(n.selection);if(!t)return!0;const r=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(r===void 0)return!0;const s=n.doc.nodeAt(r);return t.node.type===(s==null?void 0:s.type)&&Yl(n.doc,t.pos)&&n.join(t.pos),!0},V1=(n,e)=>{const t=sI(o=>o.type===e)(n.selection);if(!t)return!0;const r=n.doc.resolve(t.start).after(t.depth);if(r===void 0)return!0;const s=n.doc.nodeAt(r);return t.node.type===(s==null?void 0:s.type)&&Yl(n.doc,r)&&n.join(r),!0},pQ=(n,e,t,r={})=>({editor:s,tr:i,state:o,dispatch:a,chain:l,commands:c,can:d})=>{const{extensions:f,splittableMarks:p}=s.extensionManager,m=Hn(n,o.schema),y=Hn(e,o.schema),{selection:v,storedMarks:x}=o,{$from:b,$to:C}=v,I=b.blockRange(C),_=x||v.$to.parentOffset&&v.$from.marks();if(!I)return!1;const T=sI(A=>zD(A.type.name,f))(v);if(I.depth>=1&&T&&I.depth-T.depth<=1){if(T.node.type===m)return c.liftListItem(y);if(zD(T.node.type.name,f)&&m.validContent(T.node.content)&&a)return l().command(()=>(i.setNodeMarkup(T.pos,m),!0)).command(()=>W1(i,m)).command(()=>V1(i,m)).run()}return!t||!_||!a?l().command(()=>d().wrapInList(m,r)?!0:c.clearNodes()).wrapInList(m,r).command(()=>W1(i,m)).command(()=>V1(i,m)).run():l().command(()=>{const A=d().wrapInList(m,r),R=_.filter(j=>p.includes(j.type.name));return i.ensureMarks(R),A?!0:c.clearNodes()}).wrapInList(m,r).command(()=>W1(i,m)).command(()=>V1(i,m)).run()},gQ=(n,e={},t={})=>({state:r,commands:s})=>{const{extendEmptyMarkRange:i=!1}=t,o=Zl(n,r.schema);return GP(r,o,e)?s.unsetMark(o,{extendEmptyMarkRange:i}):s.setMark(o,e)},mQ=(n,e,t={})=>({state:r,commands:s})=>{const i=Hn(n,r.schema),o=Hn(e,r.schema),a=rp(r,i,t);let l;return r.selection.$anchor.sameParent(r.selection.$head)&&(l=r.selection.$anchor.parent.attrs),a?s.setNode(o,l):s.setNode(i,{...l,...t})},yQ=(n,e={})=>({state:t,commands:r})=>{const s=Hn(n,t.schema);return rp(t,s,e)?r.lift(s):r.wrapIn(s,e)},SQ=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let r=0;r<t.length;r+=1){const s=t[r];let i;if(s.spec.isInputRules&&(i=s.getState(n))){if(e){const o=n.tr,a=i.transform;for(let l=a.steps.length-1;l>=0;l-=1)o.step(a.steps[l].invert(a.docs[l]));if(i.text){const l=o.doc.resolve(i.from).marks();o.replaceWith(i.from,i.to,n.schema.text(i.text,l))}else o.delete(i.from,i.to)}return!0}}return!1},vQ=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:r,ranges:s}=t;return r||e&&s.forEach(i=>{n.removeMark(i.$from.pos,i.$to.pos)}),!0},xQ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{var i;const{extendEmptyMarkRange:o=!1}=e,{selection:a}=t,l=Zl(n,r.schema),{$from:c,empty:d,ranges:f}=a;if(!s)return!0;if(d&&o){let{from:p,to:m}=a;const y=(i=c.marks().find(x=>x.type===l))===null||i===void 0?void 0:i.attrs,v=Ov(c,l,y);v&&(p=v.from,m=v.to),t.removeMark(p,m,l)}else f.forEach(p=>{t.removeMark(p.$from.pos,p.$to.pos,l)});return t.removeStoredMark(l),!0},wQ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{let i=null,o=null;const a=Rv(typeof n=="string"?n:n.name,r.schema);return a?(a==="node"&&(i=Hn(n,r.schema)),a==="mark"&&(o=Zl(n,r.schema)),s&&t.selection.ranges.forEach(l=>{const c=l.$from.pos,d=l.$to.pos;let f,p,m,y;t.selection.empty?r.doc.nodesBetween(c,d,(v,x)=>{i&&i===v.type&&(m=Math.max(x,c),y=Math.min(x+v.nodeSize,d),f=x,p=v)}):r.doc.nodesBetween(c,d,(v,x)=>{x<c&&i&&i===v.type&&(m=Math.max(x,c),y=Math.min(x+v.nodeSize,d),f=x,p=v),x>=c&&x<=d&&(i&&i===v.type&&t.setNodeMarkup(x,void 0,{...v.attrs,...e}),o&&v.marks.length&&v.marks.forEach(b=>{if(o===b.type){const C=Math.max(x,c),I=Math.min(x+v.nodeSize,d);t.addMark(C,I,o.create({...b.attrs,...e}))}}))}),p&&(f!==void 0&&t.setNodeMarkup(f,void 0,{...p.attrs,...e}),o&&p.marks.length&&p.marks.forEach(v=>{o===v.type&&t.addMark(m,y,o.create({...v.attrs,...e}))}))}),!0):!1},bQ=(n,e={})=>({state:t,dispatch:r})=>{const s=Hn(n,t.schema);return RZ(s,e)(t,r)},CQ=(n,e={})=>({state:t,dispatch:r})=>{const s=Hn(n,t.schema);return DZ(s,e)(t,r)};var PQ=Object.freeze({__proto__:null,blur:nJ,clearContent:rJ,clearNodes:sJ,command:iJ,createParagraphNear:oJ,cut:aJ,deleteCurrentNode:lJ,deleteNode:cJ,deleteRange:uJ,deleteSelection:dJ,enter:hJ,exitCode:fJ,extendMarkRange:pJ,first:gJ,focus:yJ,forEach:SJ,insertContent:vJ,insertContentAt:bJ,joinBackward:EJ,joinDown:PJ,joinForward:kJ,joinItemBackward:IJ,joinItemForward:_J,joinTextblockBackward:TJ,joinTextblockForward:MJ,joinUp:CJ,keyboardShortcut:OJ,lift:RJ,liftEmptyBlock:DJ,liftListItem:jJ,newlineInCode:NJ,resetAttributes:LJ,scrollIntoView:FJ,selectAll:zJ,selectNodeBackward:$J,selectNodeForward:BJ,selectParentNode:UJ,selectTextblockEnd:HJ,selectTextblockStart:KJ,setContent:WJ,setMark:oQ,setMeta:aQ,setNode:lQ,setNodeSelection:cQ,setTextSelection:uQ,sinkListItem:dQ,splitBlock:hQ,splitListItem:fQ,toggleList:pQ,toggleMark:gQ,toggleNode:mQ,toggleWrap:yQ,undoInputRule:SQ,unsetAllMarks:vQ,unsetMark:xQ,updateAttributes:wQ,wrapIn:bQ,wrapInList:CQ});const EQ=or.create({name:"commands",addCommands(){return{...PQ}}}),kQ=or.create({name:"drop",addProseMirrorPlugins(){return[new lr({key:new qs("tiptapDrop"),props:{handleDrop:(n,e,t,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:r})}}})]}}),IQ=or.create({name:"editable",addProseMirrorPlugins(){return[new lr({key:new qs("editable"),props:{editable:()=>this.editor.options.editable}})]}}),_Q=or.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new lr({key:new qs("focusEvents"),props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const r=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,t)=>{n.isFocused=!1;const r=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),TQ=or.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:a})=>{const{selection:l,doc:c}=a,{empty:d,$anchor:f}=l,{pos:p,parent:m}=f,y=f.parent.isTextblock&&p>0?a.doc.resolve(p-1):f,v=y.parent.type.spec.isolating,x=f.pos-f.parentOffset,b=v&&y.parent.childCount===1?x===f.pos:at.atStart(c).from===p;return!d||!m.type.isTextblock||m.textContent.length||!b||b&&f.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},s={...r},i={...r,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return rI()||L5()?i:s},addProseMirrorPlugins(){return[new lr({key:new qs("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(v=>v.getMeta("composition")))return;const r=n.some(v=>v.docChanged)&&!e.doc.eq(t.doc),s=n.some(v=>v.getMeta("preventClearDocument"));if(!r||s)return;const{empty:i,from:o,to:a}=e.selection,l=at.atStart(e.doc).from,c=at.atEnd(e.doc).to;if(i||!(o===l&&a===c)||!oI(t.doc))return;const p=t.tr,m=kv({state:t,transaction:p}),{commands:y}=new Iv({editor:this.editor,state:m});if(y.clearNodes(),!!p.steps.length)return p}})]}}),MQ=or.create({name:"paste",addProseMirrorPlugins(){return[new lr({key:new qs("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),AQ=or.create({name:"tabindex",addProseMirrorPlugins(){return[new lr({key:new qs("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class Mc{get name(){return this.node.type.name}constructor(e,t,r=!1,s=null){this.currentNode=null,this.actualDepth=null,this.isBlock=r,this.resolvedPos=e,this.editor=t,this.currentNode=s}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!==null&&e!==void 0?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,r=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,r=this.to-1}this.editor.commands.insertContentAt({from:t,to:r},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new Mc(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new Mc(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new Mc(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,r)=>{const s=t.isBlock&&!t.isTextblock,i=t.isAtom&&!t.isText,o=this.pos+r+(i?0:1),a=this.resolvedPos.doc.resolve(o);if(!s&&a.depth<=this.depth)return;const l=new Mc(a,this.editor,s,s?t:null);s&&(l.actualDepth=this.depth+1),e.push(new Mc(a,this.editor,s,s?t:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let r=null,s=this.parent;for(;s&&!r;){if(s.node.type.name===e)if(Object.keys(t).length>0){const i=s.node.attrs,o=Object.keys(t);for(let a=0;a<o.length;a+=1){const l=o[a];if(i[l]!==t[l])break}}else r=s;s=s.parent}return r}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},r=!1){let s=[];if(!this.children||this.children.length===0)return s;const i=Object.keys(t);return this.children.forEach(o=>{r&&s.length>0||(o.node.type.name===e&&i.every(l=>t[l]===o.node.attrs[l])&&s.push(o),!(r&&s.length>0)&&(s=s.concat(o.querySelectorAll(e,t,r))))}),s}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}}const OQ=`.ProseMirror {
100
+ position: relative;
101
+ }
102
+
103
+ .ProseMirror {
104
+ word-wrap: break-word;
105
+ white-space: pre-wrap;
106
+ white-space: break-spaces;
107
+ -webkit-font-variant-ligatures: none;
108
+ font-variant-ligatures: none;
109
+ font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
110
+ }
111
+
112
+ .ProseMirror [contenteditable="false"] {
113
+ white-space: normal;
114
+ }
115
+
116
+ .ProseMirror [contenteditable="false"] [contenteditable="true"] {
117
+ white-space: pre-wrap;
118
+ }
119
+
120
+ .ProseMirror pre {
121
+ white-space: pre-wrap;
122
+ }
123
+
124
+ img.ProseMirror-separator {
125
+ display: inline !important;
126
+ border: none !important;
127
+ margin: 0 !important;
128
+ width: 0 !important;
129
+ height: 0 !important;
130
+ }
131
+
132
+ .ProseMirror-gapcursor {
133
+ display: none;
134
+ pointer-events: none;
135
+ position: absolute;
136
+ margin: 0;
137
+ }
138
+
139
+ .ProseMirror-gapcursor:after {
140
+ content: "";
141
+ display: block;
142
+ position: absolute;
143
+ top: -2px;
144
+ width: 20px;
145
+ border-top: 1px solid black;
146
+ animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
147
+ }
148
+
149
+ @keyframes ProseMirror-cursor-blink {
150
+ to {
151
+ visibility: hidden;
152
+ }
153
+ }
154
+
155
+ .ProseMirror-hideselection *::selection {
156
+ background: transparent;
157
+ }
158
+
159
+ .ProseMirror-hideselection *::-moz-selection {
160
+ background: transparent;
161
+ }
162
+
163
+ .ProseMirror-hideselection * {
164
+ caret-color: transparent;
165
+ }
166
+
167
+ .ProseMirror-focused .ProseMirror-gapcursor {
168
+ display: block;
169
+ }
170
+
171
+ .tippy-box[data-animation=fade][data-state=hidden] {
172
+ opacity: 0
173
+ }`;function RQ(n,e,t){const r=document.querySelector("style[data-tiptap-style]");if(r!==null)return r;const s=document.createElement("style");return e&&s.setAttribute("nonce",e),s.setAttribute("data-tiptap-style",""),s.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(s),s}let DQ=class extends BZ{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:t})=>{throw t},onPaste:()=>null,onDrop:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("contentError",this.options.onContentError),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:t,slice:r,moved:s})=>this.options.onDrop(t,r,s)),this.on("paste",({event:t,slice:r})=>this.options.onPaste(t,r)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=RQ(OQ,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.view||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const r=M5(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],s=this.state.reconfigure({plugins:r});return this.view.updateState(s),s}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let r=t;if([].concat(e).forEach(i=>{const o=typeof i=="string"?`${i}$`:i.key;r=t.filter(a=>!a.key.startsWith(o))}),t.length===r.length)return;const s=this.state.reconfigure({plugins:r});return this.view.updateState(s),s}createExtensionManager(){var e,t;const s=[...this.options.enableCoreExtensions?[IQ,tJ.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||t===void 0?void 0:t.blockSeparator}),EQ,_Q,TQ,AQ,kQ,MQ].filter(i=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[i.name]!==!1:!0):[],...this.options.extensions].filter(i=>["extension","node","mark"].includes(i==null?void 0:i.type));this.extensionManager=new Rc(s,this)}createCommandManager(){this.commandManager=new Iv({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=qP(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(o){if(!(o instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(o.message))throw o;this.emit("contentError",{editor:this,error:o,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(a=>a.name!=="collaboration"),this.createExtensionManager()}}),t=qP(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const r=j5(t,this.options.autofocus);this.view=new dZ(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...(e=this.options.editorProps)===null||e===void 0?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:vd.create({doc:t,selection:r||void 0})});const s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.createNodeViews(),this.prependClass();const i=this.view.dom;i.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(o=>{var a;return(a=this.capturedTransaction)===null||a===void 0?void 0:a.step(o)});return}const t=this.state.apply(e),r=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),r&&this.emit("selectionUpdate",{editor:this,transaction:e});const s=e.getMeta("focus"),i=e.getMeta("blur");s&&this.emit("focus",{editor:this,event:s.event,transaction:e}),i&&this.emit("blur",{editor:this,event:i.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return $5(this.state,e)}isActive(e,t){const r=typeof e=="string"?e:null,s=typeof e=="string"?t:e;return rQ(this.state,r,s)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Tv(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
174
+
175
+ `,textSerializers:r={}}=e||{};return z5(this.state.doc,{blockSeparator:t,textSerializers:{...nI(this.schema),...r}})}get isEmpty(){return oI(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelector(e,t))||null}$nodes(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new Mc(t,this)}get $doc(){return this.$pos(0)}};function Yc(n){return new Mv({find:n.find,handler:({state:e,range:t,match:r})=>{const s=dt(n.getAttributes,void 0,r);if(s===!1||s===null)return null;const{tr:i}=e,o=r[r.length-1],a=r[0];if(o){const l=a.search(/\S/),c=t.from+a.indexOf(o),d=c+o.length;if(iI(t.from,t.to,e.doc).filter(m=>m.mark.type.excluded.find(v=>v===n.type&&v!==m.mark.type)).filter(m=>m.to>c).length)return null;d<t.to&&i.delete(d,t.to),c>t.from&&i.delete(t.from+l,c);const p=t.from+l+o.length;i.addMark(t.from+l,p,n.type.create(s||{})),i.removeStoredMark(n.type)}}})}function jQ(n){return new Mv({find:n.find,handler:({state:e,range:t,match:r})=>{const s=dt(n.getAttributes,void 0,r)||{},{tr:i}=e,o=t.from;let a=t.to;const l=n.type.create(s);if(r[1]){const c=r[0].lastIndexOf(r[1]);let d=o+c;d>a?d=a:a=d+r[1].length;const f=r[0][r[0].length-1];i.insertText(f,o+r[0].length-1),i.replaceWith(d,a,l)}else if(r[0]){const c=n.type.isInline?o:o-1;i.insert(c,n.type.create(s)).delete(i.mapping.map(o),i.mapping.map(a))}i.scrollIntoView()}})}function YP(n){return new Mv({find:n.find,handler:({state:e,range:t,match:r})=>{const s=e.doc.resolve(t.from),i=dt(n.getAttributes,void 0,r)||{};if(!s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),n.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,n.type,i)}})}function sp(n){return new Mv({find:n.find,handler:({state:e,range:t,match:r,chain:s})=>{const i=dt(n.getAttributes,void 0,r)||{},o=e.tr.delete(t.from,t.to),l=o.doc.resolve(t.from).blockRange(),c=l&&zk(l,n.type,i);if(!c)return null;if(o.wrap(l,c),n.keepMarks&&n.editor){const{selection:f,storedMarks:p}=e,{splittableMarks:m}=n.editor.extensionManager,y=p||f.$to.parentOffset&&f.$from.marks();if(y){const v=y.filter(x=>m.includes(x.type.name));o.ensureMarks(v)}}if(n.keepAttributes){const f=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";s().updateAttributes(f,i).run()}const d=o.doc.resolve(t.from-1).nodeBefore;d&&d.type===n.type&&Yl(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,d))&&o.join(t.from-1)}})}let no=class XP{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=dt(Le(this,"addOptions",{name:this.name}))),this.storage=dt(Le(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new XP(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>Av(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new XP(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=dt(Le(t,"addOptions",{name:t.name})),t.storage=dt(Le(t,"addStorage",{name:t.name,options:t.options})),t}};function Ll(n){return new YZ({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:s})=>{const i=dt(n.getAttributes,void 0,r,s);if(i===!1||i===null)return null;const{tr:o}=e,a=r[r.length-1],l=r[0];let c=t.to;if(a){const d=l.search(/\S/),f=t.from+l.indexOf(a),p=f+a.length;if(iI(t.from,t.to,e.doc).filter(y=>y.mark.type.excluded.find(x=>x===n.type&&x!==y.mark.type)).filter(y=>y.to>f).length)return null;p<t.to&&o.delete(p,t.to),f>t.from&&o.delete(t.from+d,f),c=t.from+d+a.length,o.addMark(t.from+d,c,n.type.create(i||{})),o.removeStoredMark(n.type)}}})}function aI(n,e,t){const{tipTapConfig:r,addFontsFromNode:s}=n.getTextOptions();nt(r,"textOptions.tipTapConfig must be set to use rich text"),nt(s,"textOptions.addFontsFromNode must be set to use rich text");const i=Dv(r.extensions??[]),o=Gi.fromJSON(i,e),a=new Set;function l(d){a.add(d)}function c(d,f){f=s(d,f,l);for(const p of d.children)c(p,f)}return c(o,t),Array.from(a)}const NQ=(n,e)=>e.some(t=>n instanceof t);let BD,UD;function LQ(){return BD||(BD=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function FQ(){return UD||(UD=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const B5=new WeakMap,ZP=new WeakMap,U5=new WeakMap,q1=new WeakMap,lI=new WeakMap;function zQ(n){const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("success",i),n.removeEventListener("error",o)},i=()=>{t(ka(n.result)),s()},o=()=>{r(n.error),s()};n.addEventListener("success",i),n.addEventListener("error",o)});return e.then(t=>{t instanceof IDBCursor&&B5.set(t,n)}).catch(()=>{}),lI.set(e,n),e}function $Q(n){if(ZP.has(n))return;const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("complete",i),n.removeEventListener("error",o),n.removeEventListener("abort",o)},i=()=>{t(),s()},o=()=>{r(n.error||new DOMException("AbortError","AbortError")),s()};n.addEventListener("complete",i),n.addEventListener("error",o),n.addEventListener("abort",o)});ZP.set(n,e)}let JP={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return ZP.get(n);if(e==="objectStoreNames")return n.objectStoreNames||U5.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return ka(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 BQ(n){JP=n(JP)}function UQ(n){return n===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){const r=n.call(G1(this),e,...t);return U5.set(r,e.sort?e.sort():[e]),ka(r)}:FQ().includes(n)?function(...e){return n.apply(G1(this),e),ka(B5.get(this))}:function(...e){return ka(n.apply(G1(this),e))}}function HQ(n){return typeof n=="function"?UQ(n):(n instanceof IDBTransaction&&$Q(n),NQ(n,LQ())?new Proxy(n,JP):n)}function ka(n){if(n instanceof IDBRequest)return zQ(n);if(q1.has(n))return q1.get(n);const e=HQ(n);return e!==n&&(q1.set(n,e),lI.set(e,n)),e}const G1=n=>lI.get(n);function H5(n,e,{blocked:t,upgrade:r,blocking:s,terminated:i}={}){const o=indexedDB.open(n,e),a=ka(o);return r&&o.addEventListener("upgradeneeded",l=>{r(ka(o.result),l.oldVersion,l.newVersion,ka(o.transaction),l)}),t&&o.addEventListener("blocked",l=>t(l.oldVersion,l.newVersion,l)),a.then(l=>{i&&l.addEventListener("close",()=>i()),s&&l.addEventListener("versionchange",c=>s(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function K5(n,{blocked:e}={}){const t=indexedDB.deleteDatabase(n);return e&&t.addEventListener("blocked",r=>e(r.oldVersion,r)),ka(t).then(()=>{})}const KQ=["get","getKey","getAll","getAllKeys","count"],WQ=["put","add","delete","clear"],Y1=new Map;function HD(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(Y1.get(e))return Y1.get(e);const t=e.replace(/FromIndex$/,""),r=e!==t,s=WQ.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(s||KQ.includes(t)))return;const i=async function(o,...a){const l=this.transaction(o,s?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[t](...a),s&&l.done]))[0]};return Y1.set(e,i),i}BQ(n=>({...n,get:(e,t,r)=>HD(e,t)||n.get(e,t,r),has:(e,t)=>!!HD(e,t)||n.has(e,t)}));const VQ="TLDRAW_DOCUMENT_v2",qQ="TLDRAW_ASSET_STORE_v1",W5="TLDRAW_DB_NAME_INDEX_v2",mt={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function V5(n){const e=VQ+n;return YQ(e),await H5(e,4,{upgrade(t){t.objectStoreNames.contains(mt.Records)||t.createObjectStore(mt.Records),t.objectStoreNames.contains(mt.Schema)||t.createObjectStore(mt.Schema),t.objectStoreNames.contains(mt.SessionState)||t.createObjectStore(mt.SessionState),t.objectStoreNames.contains(mt.Assets)||t.createObjectStore(mt.Assets)}})}async function GQ(n){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):cI(),t=qQ+n;if(!e.find(p=>p===t))return;const s=await H5(t,1,{upgrade(p){p.objectStoreNames.contains("assets")||p.createObjectStore("assets")}});if(!s.objectStoreNames.contains("assets"))return;const i=s.transaction(["assets"],"readonly"),o=i.objectStore("assets"),a=await o.getAllKeys(),l=await Promise.all(a.map(async p=>[p,await o.get(p)]));await i.done;const c=await V5(n),d=c.transaction([mt.Assets],"readwrite"),f=d.objectStore(mt.Assets);for(const[p,m]of l)f.put(m,p);await d.done,s.close(),c.close(),await K5(t)}const Kf=class Kf{constructor(e){O(this,"getDbPromise");O(this,"isClosed",!1);O(this,"pendingTransactionSet",new Set);Kf.connectedInstances.add(this),this.getDbPromise=(async()=>(await GQ(e),await V5(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Vf)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),Kf.connectedInstances.delete(this))}tx(e,t,r){const s=(async()=>{nt(!this.isClosed,"db is closed");const o=(await this.getDb()).transaction(t,e),a=o.done.catch(l=>{if(!this.isClosed)throw l});try{return await r(o)}finally{this.isClosed?o.abort():await a}})();return this.pendingTransactionSet.add(s),s.finally(()=>this.pendingTransactionSet.delete(s)),s}async load({sessionId:e}={}){return await this.tx("readonly",[mt.Records,mt.Schema,mt.SessionState],async t=>{var l,c;const r=t.objectStore(mt.Records),s=t.objectStore(mt.Schema),i=t.objectStore(mt.SessionState);let o=e?(l=await i.get(e))==null?void 0:l.snapshot:null;return o||(o=(c=(await i.getAll()).sort((f,p)=>f.updatedAt-p.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(mt.Schema),sessionStateSnapshot:o}})}async storeChanges({schema:e,changes:t,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[mt.Records,mt.Schema,mt.SessionState],async i=>{const o=i.objectStore(mt.Records),a=i.objectStore(mt.Schema),l=i.objectStore(mt.SessionState);for(const[c,d]of Object.entries(t.added))await o.put(d,c);for(const[c,d]of Object.values(t.updated))await o.put(d,d.id);for(const c of Object.keys(t.removed))await o.delete(c);a.put(e.serialize(),mt.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:t,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[mt.Records,mt.Schema,mt.SessionState],async i=>{const o=i.objectStore(mt.Records),a=i.objectStore(mt.Schema),l=i.objectStore(mt.SessionState);await o.clear();for(const[c,d]of Object.entries(t))await o.put(d,c);a.put(e.serialize(),mt.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[mt.SessionState],async e=>{const t=e.objectStore(mt.SessionState),r=(await t.getAll()).sort((i,o)=>i.updatedAt-o.updatedAt);if(r.length<10){await e.done;return}const s=r.slice(0,r.length-10);for(const{id:i}of s)await t.delete(i)})}async getAsset(e){return await this.tx("readonly",[mt.Assets],async t=>await t.objectStore(mt.Assets).get(e))}async storeAsset(e,t){await this.tx("readwrite",[mt.Assets],async r=>{await r.objectStore(mt.Assets).put(t,e)})}};O(Kf,"connectedInstances",new Set);let tS=Kf;function cI(){const n=JSON.parse(xk(W5)||"[]")??[];return Array.isArray(n)?n:[]}function YQ(n){const e=new Set(cI());e.add(n),wk(W5,JSON.stringify([...e]))}function uI(n){return n>>>1&1073741824|n&3221225471}const XQ=Object.prototype.valueOf;function Xc(n){if(n==null)return KD(n);if(typeof n.hashCode=="function")return uI(n.hashCode(n));const e=tee(n);if(e==null)return KD(e);switch(typeof e){case"boolean":return e?1108378657:1108378656;case"number":return ZQ(e);case"string":return e.length>nee?JQ(e):QP(e);case"object":case"function":return eee(e);case"symbol":return QQ(e);default:if(typeof e.toString=="function")return QP(e.toString());throw new Error("Value type "+typeof e+" cannot be hashed.")}}function KD(n){return n===null?1108378658:1108378659}function ZQ(n){if(n!==n||n===1/0)return 0;let e=n|0;for(e!==n&&(e^=n*4294967295);n>4294967295;)n/=4294967295,e^=n;return uI(e)}function JQ(n){let e=J1[n];return e===void 0&&(e=QP(n),Z1===ree&&(Z1=0,J1={}),Z1++,J1[n]=e),e}function QP(n){let e=0;for(let t=0;t<n.length;t++)e=31*e+n.charCodeAt(t)|0;return uI(e)}function QQ(n){let e=VD[n];return e!==void 0||(e=q5(),VD[n]=e),e}function eee(n){let e=WD.get(n);return e!==void 0||(e=q5(),WD.set(n,e)),e}function tee(n){return n.valueOf!==XQ&&typeof n.valueOf=="function"?n.valueOf(n):n}function q5(){const n=++X1;return X1&1073741824&&(X1=0),n}const WD=new WeakMap,VD=Object.create(null);let X1=0;const nee=16,ree=255;let Z1=0,J1={};const Bd=5,Ap=1<<Bd,Ud=Ap-1,Ma={};function qD(){return{value:!1}}function Hi(n){n&&(n.value=!0)}function dI(n,e){e=e||0;const t=Math.max(0,n.length-e),r=new Array(t);for(let s=0;s<t;s++)r[s]=n[s+e];return r}const Hd=Object.is;class G5{}class hI{constructor(e){O(this,"_root");O(this,"size");O(this,"__ownerID");O(this,"__hash");O(this,"__altered");return e==null?kd():e instanceof hI?e:kd().withMutations(t=>{for(const[r,s]of e)t.set(r,s)})}get(e,t){return this._root?this._root.get(0,void 0,e,t):t}set(e,t){return XD(this,e,t)}delete(e){return XD(this,e,Ma)}deleteAll(e){return this.withMutations(t=>{for(const r of e)t.delete(r)})}__ensureOwner(e){return e===this.__ownerID?this:e?gI(this.size,this._root,e,this.__hash):this.size===0?kd():(this.__ownerID=e,this.__altered=!1,this)}withMutations(e){const t=this.asMutable();return e(t),t.wasAltered()?t.__ensureOwner(this.__ownerID):this}wasAltered(){return this.__altered}asMutable(){return this.__ownerID?this:this.__ensureOwner(new G5)}[Symbol.iterator](){return this.entries()[Symbol.iterator]()}entries(){return new Q1(this,see,!1)}keys(){return new Q1(this,Y5,!1)}values(){return new Q1(this,X5,!1)}}class fI{constructor(e,t){this.ownerID=e,this.entries=t}get(e,t,r,s){const i=this.entries;for(let o=0,a=i.length;o<a;o++)if(Hd(r,i[o][0]))return i[o][1];return s}update(e,t,r,s,i,o,a){const l=i===Ma,c=this.entries;let d=0;const f=c.length;for(;d<f&&!Hd(s,c[d][0]);d++);const p=d<f;if(p?c[d][1]===i:l)return this;if(Hi(a),(l||!p)&&Hi(o),l&&c.length===1)return;if(!p&&!l&&c.length>=hee)return aee(e,c,s,i);const m=e&&e===this.ownerID,y=m?c:dI(c);return p?l?d===f-1?y.pop():y[d]=y.pop():y[d]=[s,i]:y.push([s,i]),m?(this.entries=y,this):new fI(e,y)}}class jv{constructor(e,t,r){this.ownerID=e,this.bitmap=t,this.nodes=r}get(e,t,r,s){t===void 0&&(t=Xc(r));const i=1<<((e===0?t:t>>>e)&Ud),o=this.bitmap;return(o&i)===0?s:this.nodes[JD(o&i-1)].get(e+Bd,t,r,s)}update(e,t,r,s,i,o,a){r===void 0&&(r=Xc(s));const l=(t===0?r:r>>>t)&Ud,c=1<<l,d=this.bitmap,f=(d&c)!==0;if(!f&&i===Ma)return this;const p=JD(d&c-1),m=this.nodes,y=f?m[p]:void 0,v=mI(y,e,t+Bd,r,s,i,o,a);if(v===y)return this;if(!f&&v&&m.length>=fee)return cee(e,m,d,l,v);if(f&&!v&&m.length===2&&ZD(m[p^1]))return m[p^1];if(f&&v&&m.length===1&&ZD(v))return v;const x=e&&e===this.ownerID,b=f?v?d:d^c:d|c,C=f?v?Z5(m,p,v,x):dee(m,p,x):uee(m,p,v,x);return x?(this.bitmap=b,this.nodes=C,this):new jv(e,b,C)}}class pI{constructor(e,t,r){this.ownerID=e,this.count=t,this.nodes=r}get(e,t,r,s){t===void 0&&(t=Xc(r));const i=(e===0?t:t>>>e)&Ud,o=this.nodes[i];return o?o.get(e+Bd,t,r,s):s}update(e,t,r,s,i,o,a){r===void 0&&(r=Xc(s));const l=(t===0?r:r>>>t)&Ud,c=i===Ma,d=this.nodes,f=d[l];if(c&&!f)return this;const p=mI(f,e,t+Bd,r,s,i,o,a);if(p===f)return this;let m=this.count;if(!f)m++;else if(!p&&(m--,m<pee))return lee(e,d,m,l);const y=e&&e===this.ownerID,v=Z5(d,l,p,y);return y?(this.count=m,this.nodes=v,this):new pI(e,m,v)}}class Nv{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entries=r}get(e,t,r,s){const i=this.entries;for(let o=0,a=i.length;o<a;o++)if(Hd(r,i[o][0]))return i[o][1];return s}update(e,t,r,s,i,o,a){r===void 0&&(r=Xc(s));const l=i===Ma;if(r!==this.keyHash)return l?this:(Hi(a),Hi(o),yI(this,e,t,r,[s,i]));const c=this.entries;let d=0;const f=c.length;for(;d<f&&!Hd(s,c[d][0]);d++);const p=d<f;if(p?c[d][1]===i:l)return this;if(Hi(a),(l||!p)&&Hi(o),l&&f===2)return new fu(e,this.keyHash,c[d^1]);const m=e&&e===this.ownerID,y=m?c:dI(c);return p?l?d===f-1?y.pop():y[d]=y.pop():y[d]=[s,i]:y.push([s,i]),m?(this.entries=y,this):new Nv(e,this.keyHash,y)}}class fu{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entry=r}get(e,t,r,s){return Hd(r,this.entry[0])?this.entry[1]:s}update(e,t,r,s,i,o,a){const l=i===Ma,c=Hd(s,this.entry[0]);if(c?i===this.entry[1]:l)return this;if(Hi(a),l){Hi(o);return}return c?e&&e===this.ownerID?(this.entry[1]=i,this):new fu(e,this.keyHash,[s,i]):(Hi(o),yI(this,e,t,Xc(s),[s,i]))}}class Q1{constructor(e,t,r){O(this,"_stack");this._type=t,this._reverse=r,this._stack=e._root&&GD(e._root)}[Symbol.iterator](){return this}next(){const e=this._type;let t=this._stack;for(;t;){const r=t.node,s=t.index++;let i;if(r.entry){if(s===0)return eC(e,r.entry)}else if("entries"in r&&r.entries){if(i=r.entries.length-1,s<=i)return eC(e,r.entries[this._reverse?i-s:s])}else if(i=r.nodes.length-1,s<=i){const o=r.nodes[this._reverse?i-s:s];if(o){if(o.entry)return eC(e,o.entry);t=this._stack=GD(o,t)}continue}t=this._stack=this._stack.__prev}return oee()}}function eC(n,e){return iee(n,e[0],e[1])}function GD(n,e){return{node:n,index:0,__prev:e}}const Y5=0,X5=1,see=2;function iee(n,e,t,r){const s=n===Y5?e:n===X5?t:[e,t];return r?r.value=s:r={value:s,done:!1},r}function oee(){return{value:void 0,done:!0}}function gI(n,e,t,r){const s=Object.create(hI.prototype);return s.size=n,s._root=e,s.__ownerID=t,s.__hash=r,s.__altered=!1,s}let YD;function kd(){return YD||(YD=gI(0))}function XD(n,e,t){let r,s;if(n._root){const i=qD(),o=qD();if(r=mI(n._root,n.__ownerID,0,void 0,e,t,i,o),!o.value)return n;s=n.size+(i.value?t===Ma?-1:1:0)}else{if(t===Ma)return n;s=1,r=new fI(n.__ownerID,[[e,t]])}return n.__ownerID?(n.size=s,n._root=r,n.__hash=void 0,n.__altered=!0,n):r?gI(s,r):kd()}function mI(n,e,t,r,s,i,o,a){return n?n.update(e,t,r,s,i,o,a):i===Ma?n:(Hi(a),Hi(o),new fu(e,r,[s,i]))}function ZD(n){return n.constructor===fu||n.constructor===Nv}function yI(n,e,t,r,s){if(n.keyHash===r)return new Nv(e,r,[n.entry,s]);const i=(t===0?n.keyHash:n.keyHash>>>t)&Ud,o=(t===0?r:r>>>t)&Ud;let a;const l=i===o?[yI(n,e,t+Bd,r,s)]:(a=new fu(e,r,s),i<o?[n,a]:[a,n]);return new jv(e,1<<i|1<<o,l)}function aee(n,e,t,r){n||(n=new G5);let s=new fu(n,Xc(t),[t,r]);for(let i=0;i<e.length;i++){const o=e[i];s=s.update(n,0,void 0,o[0],o[1])}return s}function lee(n,e,t,r){let s=0,i=0;const o=new Array(t);for(let a=0,l=1,c=e.length;a<c;a++,l<<=1){const d=e[a];d!==void 0&&a!==r&&(s|=l,o[i++]=d)}return new jv(n,s,o)}function cee(n,e,t,r,s){let i=0;const o=new Array(Ap);for(let a=0;t!==0;a++,t>>>=1)o[a]=t&1?e[i++]:void 0;return o[r]=s,new pI(n,i+1,o)}function JD(n){return n-=n>>1&1431655765,n=(n&858993459)+(n>>2&858993459),n=n+(n>>4)&252645135,n+=n>>8,n+=n>>16,n&127}function Z5(n,e,t,r){const s=r?n:dI(n);return s[e]=t,s}function uee(n,e,t,r){const s=n.length+1;if(r&&e+1===s)return n[e]=t,n;const i=new Array(s);let o=0;for(let a=0;a<s;a++)a===e?(i[a]=t,o=-1):i[a]=n[a+o];return i}function dee(n,e,t){const r=n.length-1;if(t&&e===r)return n.pop(),n;const s=new Array(r);let i=0;for(let o=0;o<r;o++)o===e&&(i=1),s[o]=n[o+i];return s}const hee=Ap/4,fee=Ap/2,pee=Ap/4;var BL,UL;class eE{constructor(e,t){O(this,"atoms");O(this,BL,"AtomMap");this.name=e;let r=kd();t&&(r=r.withMutations(s=>{for(const[i,o]of t)s.set(i,on(`${e}:${String(i)}`,o))})),this.atoms=on(`${e}:atoms`,r)}getAtom(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t){this.atoms.get();return}return t}get(e){var r;const t=(r=this.getAtom(e))==null?void 0:r.get();return nt(t!==Sr),t}__unsafe__getWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t)return;const r=t.__unsafe__getWithoutCapture();return nt(r!==Sr),r}has(e){const t=this.getAtom(e);return t?t.get()!==Sr:!1}__unsafe__hasWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(nt(t.__unsafe__getWithoutCapture()!==Sr),!0):!1}set(e,t){const r=this.atoms.__unsafe__getWithoutCapture().get(e);return r?r.set(t):this.atoms.update(s=>s.set(e,on(`${this.name}:${String(e)}`,t))),this}update(e,t){const r=this.atoms.__unsafe__getWithoutCapture().get(e);if(!r)throw new Error(`AtomMap: key ${e} not found`);const s=r.__unsafe__getWithoutCapture();nt(s!==Sr),r.set(t(s))}delete(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(ws(()=>{t.set(Sr),this.atoms.update(r=>r.delete(e))}),!0):!1}deleteMany(e){return ws(()=>{const t=[],r=this.atoms.get().withMutations(s=>{for(const i of e){const o=s.get(i);if(!o)continue;const a=o.get();nt(a!==Sr),t.push([i,a]),s.delete(i),o.set(Sr)}});return t.length&&this.atoms.set(r),t})}clear(){return ws(()=>{for(const e of this.atoms.__unsafe__getWithoutCapture().values())e.set(Sr);this.atoms.set(kd())})}*entries(){for(const[e,t]of this.atoms.get()){const r=t.get();nt(r!==Sr),yield[e,r]}}*keys(){for(const e of this.atoms.get().keys())yield e}*values(){for(const e of this.atoms.get().values()){const t=e.get();nt(t!==Sr),yield t}}get size(){return this.atoms.get().size}forEach(e,t){for(const[r,s]of this.entries())e.call(t,s,r,this)}[(UL=Symbol.iterator,BL=Symbol.toStringTag,UL)](){return this.entries()}}class ty{constructor(e){O(this,"nextValue");O(this,"diff");this.previousValue=e}get(){var r,s,i,o;const e=((s=(r=this.diff)==null?void 0:r.removed)==null?void 0:s.size)??0,t=((o=(i=this.diff)==null?void 0:i.added)==null?void 0:o.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,i,o;const t=this.previousValue.has(e);if(t)return((i=(s=this.diff)==null?void 0:s.removed)==null?void 0:i.has(e))?this._add(e,t):void 0;(o=this.nextValue)!=null&&o.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,i,o,a;const t=this.previousValue.has(e);if(!t)return((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.has(e))?this._remove(e,t):void 0;(a=(o=this.diff)==null?void 0:o.removed)!=null&&a.has(e)||this._remove(e,t)}}class Lv{constructor(e,t){O(this,"createDefaultProperties");O(this,"validator");O(this,"ephemeralKeys");O(this,"ephemeralKeySet");O(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,i]of xs(t.ephemeralKeys))i&&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{...Yt(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??_t())}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 Lv(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 Ko(n,e){return new Lv(n,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function nS(){return{added:{},updated:{},removed:{}}}function tE(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 J5(n){return Object.keys(n.added).length===0&&Object.keys(n.updated).length===0&&Object.keys(n.removed).length===0}function SI(n){const e={added:{},removed:{},updated:{}};return Af(e,n),e}function Af(n,e){for(const t of e){for(const[r,s]of xs(t.added))if(n.removed[r]){const i=n.removed[r];delete n.removed[r],i!==s&&(n.updated[r]=[i,s])}else n.added[r]=s;for(const[r,[s,i]]of xs(t.updated)){if(n.added[r]){n.added[r]=i,delete n.updated[r],delete n.removed[r];continue}if(n.updated[r]){n.updated[r]=[n.updated[r][0],i],delete n.removed[r];continue}n.updated[r]=t.updated[r],delete n.removed[r]}for(const[r,s]of xs(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 Sf={exports:{}};Sf.exports;var QD;function gee(){return QD||(QD=1,function(n,e){var t=200,r="__lodash_hash_undefined__",s=1,i=2,o=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",d="[object Boolean]",f="[object Date]",p="[object Error]",m="[object Function]",y="[object GeneratorFunction]",v="[object Map]",x="[object Number]",b="[object Null]",C="[object Object]",I="[object Promise]",_="[object Proxy]",T="[object RegExp]",A="[object Set]",R="[object String]",j="[object Symbol]",K="[object Undefined]",U="[object WeakMap]",J="[object ArrayBuffer]",z="[object DataView]",N="[object Float32Array]",L="[object Float64Array]",V="[object Int8Array]",X="[object Int16Array]",W="[object Int32Array]",$="[object Uint8Array]",G="[object Uint8ClampedArray]",re="[object Uint16Array]",H="[object Uint32Array]",ne=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Pe=/^(?:0|[1-9]\d*)$/,ce={};ce[N]=ce[L]=ce[V]=ce[X]=ce[W]=ce[$]=ce[G]=ce[re]=ce[H]=!0,ce[a]=ce[l]=ce[J]=ce[d]=ce[z]=ce[f]=ce[p]=ce[m]=ce[v]=ce[x]=ce[C]=ce[T]=ce[A]=ce[R]=ce[U]=!1;var Be=typeof Ss=="object"&&Ss&&Ss.Object===Object&&Ss,Re=typeof self=="object"&&self&&self.Object===Object&&self,Ce=Be||Re||Function("return this")(),_e=e&&!e.nodeType&&e,Ve=_e&&!0&&n&&!n.nodeType&&n,it=Ve&&Ve.exports===_e,cn=it&&Be.process,It=function(){try{return cn&&cn.binding&&cn.binding("util")}catch{}}(),Jt=It&&It.isTypedArray;function jt(F,Z){for(var de=-1,Ae=F==null?0:F.length,Tt=0,et=[];++de<Ae;){var zt=F[de];Z(zt,de,F)&&(et[Tt++]=zt)}return et}function Mt(F,Z){for(var de=-1,Ae=Z.length,Tt=F.length;++de<Ae;)F[Tt+de]=Z[de];return F}function Yr(F,Z){for(var de=-1,Ae=F==null?0:F.length;++de<Ae;)if(Z(F[de],de,F))return!0;return!1}function Xr(F,Z){for(var de=-1,Ae=Array(F);++de<F;)Ae[de]=Z(de);return Ae}function Zr(F){return function(Z){return F(Z)}}function Jr(F,Z){return F.has(Z)}function Zs(F,Z){return F==null?void 0:F[Z]}function rc(F){var Z=-1,de=Array(F.size);return F.forEach(function(Ae,Tt){de[++Z]=[Tt,Ae]}),de}function Su(F,Z){return function(de){return F(Z(de))}}function vu(F){var Z=-1,de=Array(F.size);return F.forEach(function(Ae){de[++Z]=Ae}),de}var xu=Array.prototype,wu=Function.prototype,ao=Object.prototype,Ii=Ce["__core-js_shared__"],sc=wu.toString,ae=ao.hasOwnProperty,be=function(){var F=/[^.]+$/.exec(Ii&&Ii.keys&&Ii.keys.IE_PROTO||"");return F?"Symbol(src)_1."+F:""}(),Xe=ao.toString,At=RegExp("^"+sc.call(ae).replace(ne,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Js=it?Ce.Buffer:void 0,Qr=Ce.Symbol,Yo=Ce.Uint8Array,Is=ao.propertyIsEnumerable,_s=xu.splice,es=Qr?Qr.toStringTag:void 0,Ts=Object.getOwnPropertySymbols,ts=Js?Js.isBuffer:void 0,_i=Su(Object.keys,Object),bu=Jo(Ce,"DataView"),Ka=Jo(Ce,"Map"),Cu=Jo(Ce,"Promise"),Pu=Jo(Ce,"Set"),Eu=Jo(Ce,"WeakMap"),Xo=Jo(Object,"create"),tg=ur(bu),ic=ur(Ka),ph=ur(Cu),oc=ur(Pu),D0=ur(Eu),Wa=Qr?Qr.prototype:void 0,Va=Wa?Wa.valueOf:void 0;function Qs(F){var Z=-1,de=F==null?0:F.length;for(this.clear();++Z<de;){var Ae=F[Z];this.set(Ae[0],Ae[1])}}function gh(){this.__data__=Xo?Xo(null):{},this.size=0}function j0(F){var Z=this.has(F)&&delete this.__data__[F];return this.size-=Z?1:0,Z}function N0(F){var Z=this.__data__;if(Xo){var de=Z[F];return de===r?void 0:de}return ae.call(Z,F)?Z[F]:void 0}function L0(F){var Z=this.__data__;return Xo?Z[F]!==void 0:ae.call(Z,F)}function Zo(F,Z){var de=this.__data__;return this.size+=this.has(F)?0:1,de[F]=Xo&&Z===void 0?r:Z,this}Qs.prototype.clear=gh,Qs.prototype.delete=j0,Qs.prototype.get=N0,Qs.prototype.has=L0,Qs.prototype.set=Zo;function ei(F){var Z=-1,de=F==null?0:F.length;for(this.clear();++Z<de;){var Ae=F[Z];this.set(Ae[0],Ae[1])}}function ng(){this.__data__=[],this.size=0}function F0(F){var Z=this.__data__,de=_u(Z,F);if(de<0)return!1;var Ae=Z.length-1;return de==Ae?Z.pop():_s.call(Z,de,1),--this.size,!0}function rg(F){var Z=this.__data__,de=_u(Z,F);return de<0?void 0:Z[de][1]}function sg(F){return _u(this.__data__,F)>-1}function ig(F,Z){var de=this.__data__,Ae=_u(de,F);return Ae<0?(++this.size,de.push([F,Z])):de[Ae][1]=Z,this}ei.prototype.clear=ng,ei.prototype.delete=F0,ei.prototype.get=rg,ei.prototype.has=sg,ei.prototype.set=ig;function lo(F){var Z=-1,de=F==null?0:F.length;for(this.clear();++Z<de;){var Ae=F[Z];this.set(Ae[0],Ae[1])}}function z0(){this.size=0,this.__data__={hash:new Qs,map:new(Ka||ei),string:new Qs}}function $0(F){var Z=vt(this,F).delete(F);return this.size-=Z?1:0,Z}function nn(F){return vt(this,F).get(F)}function B0(F){return vt(this,F).has(F)}function mh(F,Z){var de=vt(this,F),Ae=de.size;return de.set(F,Z),this.size+=de.size==Ae?0:1,this}lo.prototype.clear=z0,lo.prototype.delete=$0,lo.prototype.get=nn,lo.prototype.has=B0,lo.prototype.set=mh;function ac(F){var Z=-1,de=F==null?0:F.length;for(this.__data__=new lo;++Z<de;)this.add(F[Z])}function ku(F){return this.__data__.set(F,r),this}function U0(F){return this.__data__.has(F)}ac.prototype.add=ac.prototype.push=ku,ac.prototype.has=U0;function Ti(F){var Z=this.__data__=new ei(F);this.size=Z.size}function Iu(){this.__data__=new ei,this.size=0}function ti(F){var Z=this.__data__,de=Z.delete(F);return this.size=Z.size,de}function H0(F){return this.__data__.get(F)}function Ms(F){return this.__data__.has(F)}function K0(F,Z){var de=this.__data__;if(de instanceof ei){var Ae=de.__data__;if(!Ka||Ae.length<t-1)return Ae.push([F,Z]),this.size=++de.size,this;de=this.__data__=new lo(Ae)}return de.set(F,Z),this.size=de.size,this}Ti.prototype.clear=Iu,Ti.prototype.delete=ti,Ti.prototype.get=H0,Ti.prototype.has=Ms,Ti.prototype.set=K0;function W0(F,Z){var de=ho(F),Ae=!de&&uc(F),Tt=!de&&!Ae&&xh(F),et=!de&&!Ae&&!Tt&&bh(F),zt=de||Ae||Tt||et,mn=zt?Xr(F.length,String):[],$t=mn.length;for(var Nt in F)ae.call(F,Nt)&&!(zt&&(Nt=="length"||Tt&&(Nt=="offset"||Nt=="parent")||et&&(Nt=="buffer"||Nt=="byteLength"||Nt=="byteOffset")||lg(Nt,$t)))&&mn.push(Nt);return mn}function _u(F,Z){for(var de=F.length;de--;)if(Ai(F[de][0],Z))return de;return-1}function Tu(F,Z,de){var Ae=Z(F);return ho(F)?Ae:Mt(Ae,de(F))}function co(F){return F==null?F===void 0?K:b:es&&es in Object(F)?ag(F):uo(F)}function qa(F){return po(F)&&co(F)==a}function lc(F,Z,de,Ae,Tt){return F===Z?!0:F==null||Z==null||!po(F)&&!po(Z)?F!==F&&Z!==Z:V0(F,Z,de,Ae,lc,Tt)}function V0(F,Z,de,Ae,Tt,et){var zt=ho(F),mn=ho(Z),$t=zt?l:Mi(F),Nt=mn?l:Mi(Z);$t=$t==a?C:$t,Nt=Nt==a?C:Nt;var Dn=$t==C,ns=Nt==C,yn=$t==Nt;if(yn&&xh(F)){if(!xh(Z))return!1;zt=!0,Dn=!1}if(yn&&!Dn)return et||(et=new Ti),zt||bh(F)?Mu(F,Z,de,Ae,Tt,et):cc(F,Z,$t,de,Ae,Tt,et);if(!(de&s)){var qn=Dn&&ae.call(F,"__wrapped__"),Or=ns&&ae.call(Z,"__wrapped__");if(qn||Or){var un=qn?F.value():F,dr=Or?Z.value():Z;return et||(et=new Ti),Tt(un,dr,de,Ae,et)}}return yn?(et||(et=new Ti),G0(F,Z,de,Ae,Tt,et)):!1}function q0(F){if(!wh(F)||vh(F))return!1;var Z=Ga(F)?At:ge;return Z.test(ur(F))}function yh(F){return po(F)&&dg(F.length)&&!!ce[co(F)]}function og(F){if(!Ou(F))return _i(F);var Z=[];for(var de in Object(F))ae.call(F,de)&&de!="constructor"&&Z.push(de);return Z}function Mu(F,Z,de,Ae,Tt,et){var zt=de&s,mn=F.length,$t=Z.length;if(mn!=$t&&!(zt&&$t>mn))return!1;var Nt=et.get(F);if(Nt&&et.get(Z))return Nt==Z;var Dn=-1,ns=!0,yn=de&i?new ac:void 0;for(et.set(F,Z),et.set(Z,F);++Dn<mn;){var qn=F[Dn],Or=Z[Dn];if(Ae)var un=zt?Ae(Or,qn,Dn,Z,F,et):Ae(qn,Or,Dn,F,Z,et);if(un!==void 0){if(un)continue;ns=!1;break}if(yn){if(!Yr(Z,function(dr,Oi){if(!Jr(yn,Oi)&&(qn===dr||Tt(qn,dr,de,Ae,et)))return yn.push(Oi)})){ns=!1;break}}else if(!(qn===Or||Tt(qn,Or,de,Ae,et))){ns=!1;break}}return et.delete(F),et.delete(Z),ns}function cc(F,Z,de,Ae,Tt,et,zt){switch(de){case z:if(F.byteLength!=Z.byteLength||F.byteOffset!=Z.byteOffset)return!1;F=F.buffer,Z=Z.buffer;case J:return!(F.byteLength!=Z.byteLength||!et(new Yo(F),new Yo(Z)));case d:case f:case x:return Ai(+F,+Z);case p:return F.name==Z.name&&F.message==Z.message;case T:case R:return F==Z+"";case v:var mn=rc;case A:var $t=Ae&s;if(mn||(mn=vu),F.size!=Z.size&&!$t)return!1;var Nt=zt.get(F);if(Nt)return Nt==Z;Ae|=i,zt.set(F,Z);var Dn=Mu(mn(F),mn(Z),Ae,Tt,et,zt);return zt.delete(F),Dn;case j:if(Va)return Va.call(F)==Va.call(Z)}return!1}function G0(F,Z,de,Ae,Tt,et){var zt=de&s,mn=Au(F),$t=mn.length,Nt=Au(Z),Dn=Nt.length;if($t!=Dn&&!zt)return!1;for(var ns=$t;ns--;){var yn=mn[ns];if(!(zt?yn in Z:ae.call(Z,yn)))return!1}var qn=et.get(F);if(qn&&et.get(Z))return qn==Z;var Or=!0;et.set(F,Z),et.set(Z,F);for(var un=zt;++ns<$t;){yn=mn[ns];var dr=F[yn],Oi=Z[yn];if(Ae)var Ya=zt?Ae(Oi,dr,yn,Z,F,et):Ae(dr,Oi,yn,F,Z,et);if(!(Ya===void 0?dr===Oi||Tt(dr,Oi,de,Ae,et):Ya)){Or=!1;break}un||(un=yn=="constructor")}if(Or&&!un){var Ru=F.constructor,Xa=Z.constructor;Ru!=Xa&&"constructor"in F&&"constructor"in Z&&!(typeof Ru=="function"&&Ru instanceof Ru&&typeof Xa=="function"&&Xa instanceof Xa)&&(Or=!1)}return et.delete(F),et.delete(Z),Or}function Au(F){return Tu(F,Y0,Sh)}function vt(F,Z){var de=F.__data__;return cg(Z)?de[typeof Z=="string"?"string":"hash"]:de.map}function Jo(F,Z){var de=Zs(F,Z);return q0(de)?de:void 0}function ag(F){var Z=ae.call(F,es),de=F[es];try{F[es]=void 0;var Ae=!0}catch{}var Tt=Xe.call(F);return Ae&&(Z?F[es]=de:delete F[es]),Tt}var Sh=Ts?function(F){return F==null?[]:(F=Object(F),jt(Ts(F),function(Z){return Is.call(F,Z)}))}:dc,Mi=co;(bu&&Mi(new bu(new ArrayBuffer(1)))!=z||Ka&&Mi(new Ka)!=v||Cu&&Mi(Cu.resolve())!=I||Pu&&Mi(new Pu)!=A||Eu&&Mi(new Eu)!=U)&&(Mi=function(F){var Z=co(F),de=Z==C?F.constructor:void 0,Ae=de?ur(de):"";if(Ae)switch(Ae){case tg:return z;case ic:return v;case ph:return I;case oc:return A;case D0:return U}return Z});function lg(F,Z){return Z=Z??o,!!Z&&(typeof F=="number"||Pe.test(F))&&F>-1&&F%1==0&&F<Z}function cg(F){var Z=typeof F;return Z=="string"||Z=="number"||Z=="symbol"||Z=="boolean"?F!=="__proto__":F===null}function vh(F){return!!be&&be in F}function Ou(F){var Z=F&&F.constructor,de=typeof Z=="function"&&Z.prototype||ao;return F===de}function uo(F){return Xe.call(F)}function ur(F){if(F!=null){try{return sc.call(F)}catch{}try{return F+""}catch{}}return""}function Ai(F,Z){return F===Z||F!==F&&Z!==Z}var uc=qa(function(){return arguments}())?qa:function(F){return po(F)&&ae.call(F,"callee")&&!Is.call(F,"callee")},ho=Array.isArray;function fo(F){return F!=null&&dg(F.length)&&!Ga(F)}var xh=ts||hc;function ug(F,Z){return lc(F,Z)}function Ga(F){if(!wh(F))return!1;var Z=co(F);return Z==m||Z==y||Z==c||Z==_}function dg(F){return typeof F=="number"&&F>-1&&F%1==0&&F<=o}function wh(F){var Z=typeof F;return F!=null&&(Z=="object"||Z=="function")}function po(F){return F!=null&&typeof F=="object"}var bh=Jt?Zr(Jt):yh;function Y0(F){return fo(F)?W0(F):og(F)}function dc(){return[]}function hc(){return!1}n.exports=ug}(Sf,Sf.exports)),Sf.exports}var mee=gee();const Op=ja(mee);function yee(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(i=>i.has(s))&&r.add(s);return r}function See(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 ej(n,e){for(const[t,r]of Object.entries(n)){const s=r,i=e[t];if("eq"in s&&i!==s.eq||"neq"in s&&i===s.neq||"gt"in s&&(typeof i!="number"||i<=s.gt))return!1}return!0}function tj(n,e,t){const r=Object.fromEntries(Object.keys(t).map(s=>[s,new Set]));for(const[s,i]of Object.entries(t))if("eq"in i){const a=n.index(e,s).get().get(i.eq);if(a)for(const l of a)r[s].add(l)}else if("neq"in i){const o=n.index(e,s);for(const[a,l]of o.get())if(a!==i.neq)for(const c of l)r[s].add(c)}else if("gt"in i){const o=n.index(e,s);for(const[a,l]of o.get())if(a>i.gt)for(const c of l)r[s].add(c)}return yee(Object.values(r))}class vee{constructor(e,t){O(this,"indexCache",new Map);O(this,"historyCache",new Map);this.recordMap=e,this.history=t}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const t=le("filterHistory:"+e,(r,s)=>{if(Lc(r))return this.history.get();const i=this.history.getDiffSince(s);if(i===zs)return this.history.get();const o={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const d of i){for(const f of fn(d.added))if(f.typeName===e)if(o.removed[f.id]){const p=o.removed[f.id];delete o.removed[f.id],l--,p!==f&&(o.updated[f.id]=[p,f],c++)}else o.added[f.id]=f,a++;for(const[f,p]of fn(d.updated))p.typeName===e&&(o.added[p.id]?o.added[p.id]=p:o.updated[p.id]?o.updated[p.id]=[o.updated[p.id][0],p]:(o.updated[p.id]=[f,p],c++));for(const f of fn(d.removed))f.typeName===e&&(o.added[f.id]?(delete o.added[f.id],a--):o.updated[f.id]?(o.removed[f.id]=o.updated[f.id][0],delete o.updated[f.id],c--,l++):(o.removed[f.id]=f,l++))}return a||l||c?ff(this.history.get(),o):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 i=new Map;for(const o of this.recordMap.values())if(o.typeName===e){const a=o[t];i.has(a)||i.set(a,new Set),i.get(a).add(o.id)}return i};return le("index:"+e+":"+t,(i,o)=>{if(Lc(i))return s();const a=r.getDiffSince(o);if(a===zs)return s();const l=new Map,c=(m,y)=>{let v=l.get(m);v||(v=new ty(i.get(m)??new Set)),v.add(y),l.set(m,v)},d=(m,y)=>{let v=l.get(m);v||(v=new ty(i.get(m)??new Set)),v.remove(y),l.set(m,v)};for(const m of a){for(const y of fn(m.added))if(y.typeName===e){const v=y[t];c(v,y.id)}for(const[y,v]of fn(m.updated))if(v.typeName===e){const x=y[t],b=v[t];x!==b&&(d(x,v.id),c(b,v.id))}for(const y of fn(m.removed))if(y.typeName===e){const v=y[t];d(v,y.id)}}let f,p;for(const[m,y]of l){const v=y.get();v&&(f||(f=new Map(i)),p||(p=new Map),v.value.size===0?f.delete(m):f.set(m,v.value),p.set(m,v.diff))}return f&&p?ff(f,p):i},{historyLength:100})}record(e,t=()=>({}),r="record:"+e+(t?":"+t.toString():"")){const s=this.ids(e,t,r);return le(r,()=>{for(const i of s.get())return this.recordMap.get(i)})}records(e,t=()=>({}),r="records:"+e+(t?":"+t.toString():"")){const s=this.ids(e,t,"ids:"+r);return le(r,()=>Array.from(s.get(),i=>this.recordMap.get(i)),{isEqual:jy})}ids(e,t=()=>({}),r="ids:"+e+(t?":"+t.toString():"")){const s=this.filterHistory(e),i=()=>{s.get();const l=t();if(Object.keys(l).length===0){const c=new Set;for(const d of this.recordMap.values())d.typeName===e&&c.add(d.id);return c}return tj(this,e,l)},o=l=>{const c=i(),d=See(l,c);return d?ff(c,d):l},a=le("ids_query:"+r,t,{isEqual:Op});return le("query:"+r,(l,c)=>{const d=a.get();if(Lc(l))return i();if(c<a.lastChangedEpoch)return o(l);const f=s.getDiffSince(c);if(f===zs)return o(l);const p=new ty(l);for(const y of f){for(const v of fn(y.added))v.typeName===e&&ej(d,v)&&p.add(v.id);for(const[v,x]of fn(y.updated))x.typeName===e&&(ej(d,x)?p.add(x.id):p.remove(x.id));for(const v of fn(y.removed))v.typeName===e&&p.remove(v.id)}const m=p.get();return m?ff(m.value,m.diff):l},{historyLength:50})}exec(e,t){const r=tj(this,e,t);return r.size===0?Si:Array.from(r,s=>this.recordMap.get(s))}}class xee{constructor(e){O(this,"_beforeCreateHandlers",{});O(this,"_afterCreateHandlers",{});O(this,"_beforeChangeHandlers",{});O(this,"_afterChangeHandlers",{});O(this,"_beforeDeleteHandlers",{});O(this,"_afterDeleteHandlers",{});O(this,"_operationCompleteHandlers",[]);O(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 i of r)s=i(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 i=t;for(const o of s)i=o(e,i,r);return i}return t}handleAfterChange(e,t,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[t.typeName];if(s)for(const i of s)i(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),()=>Ec(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>Ec(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>Ec(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>Ec(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>Ec(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>Ec(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Ec(this._operationCompleteHandlers,e)}}function Ec(n,e){const t=n.indexOf(e);t>=0&&n.splice(t,1)}class vI{constructor(e){O(this,"id");O(this,"records");O(this,"history",on("history",0,{historyLength:1e3}));O(this,"query");O(this,"listeners",new Set);O(this,"historyAccumulator",new bee);O(this,"historyReactor");O(this,"schema");O(this,"props");O(this,"scopedTypes");O(this,"sideEffects",new xee(this));O(this,"isMergingRemoteChanges",!1);O(this,"_integrityChecker");O(this,"_isPossiblyCorrupted",!1);O(this,"pendingAfterEvents",null);O(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:s}=e;this.id=s??_t(),this.schema=r,this.props=e.props,t?this.records=new eE("store",xs(t).map(([i,o])=>[i,this.schema.validateRecord(this,o,"initialize",null)])):this.records=new eE("store"),this.query=new vee(this.records,this.history),this.historyReactor=gG("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:i=>this.cancelHistoryReactor=g3(i)}),this.scopedTypes={document:new Set(fn(this.schema.types).filter(i=>i.scope==="document").map(i=>i.typeName)),session:new Set(fn(this.schema.types).filter(i=>i.scope==="session").map(i=>i.typeName)),presence:new Set(fn(this.schema.types).filter(i=>i.scope==="presence").map(i=>i.typeName))}}cancelHistoryReactor(){}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:t,source:r}of e){let s=null,i=null,o=null;for(const{onHistory:a,filters:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(i??(i=this.filterChangesByScope(t,"document")),!i)continue;a({changes:i,source:r})}else if(l.scope==="session"){if(s??(s=this.filterChangesByScope(t,"session")),!s)continue;a({changes:s,source:r})}else{if(o??(o=this.filterChangesByScope(t,"presence")),!o)continue;a({changes:o,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,t){const r={added:If(e.added,(s,i)=>this.scopedTypes[t].has(i.typeName)),updated:If(e.updated,(s,i)=>this.scopedTypes[t].has(i[1].typeName)),removed:If(e.removed,(s,i)=>this.scopedTypes[t].has(i.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={};let i,o=!1;const a=this.isMergingRemoteChanges?"remote":"user";for(let l=0,c=e.length;l<c;l++){i=e[l];const d=this.records.__unsafe__getWithoutCapture(i.id);if(d){if(i=this.sideEffects.handleBeforeChange(d,i,a),this.schema.validateRecord(this,i,t??"updateRecord",d)===d)continue;i=i,this.records.set(i.id,i),o=!0,r[i.id]=[d,i],this.addDiffForAfterEvent(d,i)}else i=this.sideEffects.handleBeforeCreate(i,a),o=!0,i=this.schema.validateRecord(this,i,t??"createRecord",null),i=i,s[i.id]=i,this.addDiffForAfterEvent(null,i),this.records.set(i.id,i)}o&&this.updateHistory({added:s,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const t=new Set(e),r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of e){const a=this.records.__unsafe__getWithoutCapture(o);a&&this.sideEffects.handleBeforeDelete(a,r)===!1&&t.delete(o)}const s=this.records.deleteMany(t);if(s.length===0)return;const i={};for(const[o,a]of s)i[o]=a,this.addDiffForAfterEvent(a,null);this.updateHistory({added:{},updated:{},removed:i})})}get(e){return this.records.get(e)}unsafeGetWithoutCapture(e){return this.records.__unsafe__getWithoutCapture(e)}serialize(e="document"){const t={};for(const[r,s]of this.records)(e==="all"||this.scopedTypes[e].has(s.typeName))&&(t[r]=s);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 Array.from(this.records.values())}clear(){this.remove(Array.from(this.records.keys()))}update(e,t){const r=this.unsafeGetWithoutCapture(e);if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([t(r)])}has(e){return this.records.has(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,ws(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const t=[],r=this.historyAccumulator.addInterceptor(s=>t.push(s.changes));try{return ws(e),SI(t)}finally{r()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=fn(e.added);for(const[o,a]of fn(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){s.push(a);continue}let d=null;for(const[f,p]of Object.entries(a))l.ephemeralKeySet.has(f)||Object.is(p,On(c,f))||(d||(d={...c}),d[f]=p);d&&s.push(d)}else s.push(a)}const i=zV(e.removed);s.length&&this.put(s),i.length&&this.remove(i)},t)}createCache(e){const t=new Na;return{get:r=>{const s=this.records.getAtom(r);if(s)return t.get(s,()=>e(r,s)).get()}}}createComputedCache(e,t,r){return this.createCache((s,i)=>{const o=r!=null&&r.areRecordsEqual?le(on.name+":equals",()=>i.get(),{isEqual:r.areRecordsEqual}):i;return le(e+":"+s,()=>t(o.get()),{isEqual:r==null?void 0:r.areResultsEqual})})}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(nt(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&nt(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:i}of r.values())s&&i?this.sideEffects.handleAfterChange(s,i,t):s&&!i?this.sideEffects.handleAfterDelete(s,t):!s&&i&&this.sideEffects.handleAfterCreate(i,t);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(t)}}}atomic(e,t=!0){return ws(()=>{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 wee(n){if(n.length===0)return[];const e=[];let t=[n[0]],r;for(let s=1,i=n.length;s<i;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:SI(s.map(i=>i.changes))}))}class bee{constructor(){O(this,"_history",[]);O(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=wee(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function xI(n,e,t){const r=new Na;return{get(s,i){return r.get(s,()=>(s instanceof vI?s:s.store).createComputedCache(n,l=>e(s,l),t)).get(i)}}}function Cee(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,i=e[0];i&&(e[0]={...i,dependsOn:s.concat(i.dependsOn??[])})}}return e}function Id({sequence:n,sequenceId:e,retroactive:t=!0}){const r={sequenceId:e,retroactive:t,sequence:Cee(n)};return Q5(r),r}function Ps(n,e){return Object.fromEntries(xs(e).map(([t,r])=>[t,`${n}/${r}`]))}function Gs(n){const e=n.sequenceId;return Id({sequenceId:e,retroactive:n.retroactive??!0,sequence:n.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>{var s,i;return r.typeName===n.recordType&&(((s=t.filter)==null?void 0:s.call(t,r))??!0)&&(((i=n.filter)==null?void 0:i.call(n,r))??!0)}}:t)})}function Pee(n){const e=new Map(n.map(i=>[i.id,i])),t=new Set,r=[];function s(i){nt(!t.has(i.id),`Circular dependency in migrations: ${i.id}`),t.add(i.id);const{version:o,sequenceId:a}=rS(i.id),l=e.get(`${a}/${o-1}`);if(l&&s(l),i.dependsOn)for(const c of i.dependsOn){const d=e.get(c);d&&s(d)}e.delete(i.id),r.push(i)}for(const i of e.values())s(i);return r}function rS(n){const[e,t]=n.split("/");return{sequenceId:e,version:parseInt(t)}}function nj(n,e){e&&nt(n.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${n}'`),nt(n.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${n}'`)}function Q5(n){if(nt(!n.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${n.sequenceId}`),nt(n.sequenceId.length,"sequenceId must be a non-empty string"),n.sequence.length===0)return;nj(n.sequence[0].id,n.sequenceId);let e=rS(n.sequence[0].id).version;nt(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;nj(r,n.sequenceId);const s=rS(r).version;nt(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 ml=(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))(ml||{});function Eee(n){if(n.schemaVersion>2||n.schemaVersion<1)return jr.err("Bad schema version");if(n.schemaVersion===2)return jr.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,i]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${t}.${s}`]=i;return jr.ok(e)}class wI{constructor(e,t){O(this,"migrations",{});O(this,"sortedMigrations");var s;this.types=e,this.options=t;for(const i of t.migrations??[])nt(!this.migrations[i.sequenceId],`Duplicate migration sequenceId ${i.sequenceId}`),Q5(i),this.migrations[i.sequenceId]=i;const r=Object.values(this.migrations).flatMap(i=>i.sequence);this.sortedMigrations=Pee(r);for(const i of this.sortedMigrations)if((s=i.dependsOn)!=null&&s.length)for(const o of i.dependsOn){const a=r.find(l=>l.id===o);nt(a,`Migration '${i.id}' depends on missing migration '${o}'`)}}static create(e,t){return new wI(e,t??{})}validateRecord(e,t,r,s){try{const i=On(this.types,t.typeName);if(!i)throw new Error(`Missing definition for record type ${t.typeName}`);return i.validate(t,s??void 0)}catch(i){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:t,phase:r,recordBefore:s,error:i});throw i}}getMigrationsSince(e){const t=Eee(e);if(!t.ok)return t;const r=t.value,s=new Set(Object.keys(r.sequences).filter(o=>this.migrations[o]));for(const o in this.migrations)r.sequences[o]===void 0&&this.migrations[o].retroactive&&s.add(o);if(s.size===0)return jr.ok([]);const i=new Set;for(const o of s){const a=r.sequences[o];if(typeof a!="number"&&this.migrations[o].retroactive||a===0){for(const d of this.migrations[o].sequence)i.add(d.id);continue}const l=`${o}/${a}`,c=this.migrations[o].sequence.findIndex(d=>d.id===l);if(c===-1)return jr.err("Incompatible schema?");for(const d of this.migrations[o].sequence.slice(c+1))i.add(d.id)}return jr.ok(this.sortedMigrations.filter(({id:o})=>i.has(o)))}migratePersistedRecord(e,t,r="up"){const s=this.getMigrationsSince(t);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:ml.MigrationError};let i=s.value;if(i.length===0)return{type:"success",value:e};if(i.some(o=>o.scope==="store"))return{type:"error",reason:r==="down"?ml.TargetVersionTooOld:ml.TargetVersionTooNew};if(r==="down"){if(!i.every(o=>o.down))return{type:"error",reason:ml.TargetVersionTooOld};i=i.slice().reverse()}e=Yt(e);try{for(const o of i){if(o.scope==="store")throw new Error;if(!(o.filter?o.filter(e):!0))continue;const l=o[r](e);l&&(e=Yt(l))}}catch(o){return console.error("Error migrating record",o),{type:"error",reason:ml.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:ml.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:t};t=Yt(t);try{for(const i of s)if(i.scope==="record")for(const[o,a]of Object.entries(t)){if(!(i.filter?i.filter(a):!0))continue;const c=i.up(a);c&&(t[o]=Yt(c))}else if(i.scope==="store"){const o=i.up(t);o&&(t=Yt(o))}else En(i)}catch(i){return console.error("Error migrating store",i),{type:"error",reason:ml.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?rS(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=On(this.types,e);return nt(t,"record type does not exists"),t}}Wl("@tldraw/store","3.10.3","esm");function kee(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 St extends Error{constructor(t,r=[]){const s=kee(r),i=t.split(`
176
+ `).map((o,a)=>a===0?o:` ${o}`).join(`
177
+ `);super(r?`At ${s}: ${i}`:i);O(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Cs(n,e){try{return e()}catch(t){throw t instanceof St?new St(t.rawMessage,[n,...t.path]):new St(t.toString(),[n])}}function Fl(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:En(e)}}class _r{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 Ree(this)}optional(){return t4(this)}refine(e){return new _r(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=>(Cs(`(check ${e})`,()=>t(r)),r)):this.refine(r=>(e(r),r))}}class Iee extends _r{constructor(e){super(t=>{const r=rj.validate(t);for(let s=0;s<r.length;s++)Cs(s,()=>e.validate(r[s]));return r},(t,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=rj.validate(r);let i=t.length!==s.length;for(let o=0;o<s.length;o++){const a=s[o];if(o>=t.length){i=!0,Cs(o,()=>e.validate(a));continue}if(Object.is(t[o],a))continue;const l=Cs(o,()=>e.validateUsingKnownGoodVersion(t[o],a));Object.is(l,t[o])||(i=!0)}return i?r:t}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new St("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new St("Expected an array with length greater than 1")})}}class sS extends _r{constructor(e,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new St(`Expected object, got ${Fl(r)}`);for(const[s,i]of Object.entries(e))Cs(s,()=>{i.validate(On(r,s))});if(!t){for(const s of Object.keys(r))if(!yi(e,s))throw new St("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new St(`Expected object, got ${Fl(s)}`);let i=!1;for(const[o,a]of Object.entries(e)){const l=On(r,o),c=On(s,o);if(Object.is(l,c))continue;const d=Cs(o,()=>{const f=a;return f.validateUsingKnownGoodVersion?f.validateUsingKnownGoodVersion(l,c):f.validate(c)});Object.is(d,l)||(i=!0)}if(!t){for(const o of Object.keys(s))if(!yi(e,o))throw new St("Unexpected property",[o])}for(const o of Object.keys(r))if(!yi(s,o)){i=!0;break}return i?s:r}),this.config=e,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new sS(this.config,!0)}extend(e){return new sS({...this.config,...e})}}class Fv extends _r{constructor(e,t,r,s){super(i=>{this.expectObject(i);const{matchingSchema:o,variant:a}=this.getMatchingSchemaAndVariant(i);return o===void 0?this.unknownValueValidation(i,a):Cs(`(${e} = ${a})`,()=>o.validate(i))},(i,o)=>{this.expectObject(o),this.expectObject(i);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(o);return a===void 0?this.unknownValueValidation(o,l):On(i,e)!==On(o,e)?Cs(`(${e} = ${l})`,()=>a.validate(o)):Cs(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(i,o):a.validate(o))}),this.key=e,this.config=t,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(e){if(typeof e!="object"||e===null)throw new St(`Expected an object, got ${Fl(e)}`,[])}getMatchingSchemaAndVariant(e){const t=On(e,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new St(`Expected a string for key "${this.key}", got ${Fl(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new St(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:yi(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(e){return new Fv(this.key,this.config,e,this.useNumberKeys)}}class _ee extends _r{constructor(e,t){super(r=>{if(typeof r!="object"||r===null)throw new St(`Expected object, got ${Fl(r)}`);for(const[s,i]of Object.entries(r))Cs(s,()=>{e.validate(s),t.validate(i)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new St(`Expected object, got ${Fl(s)}`);let i=!1;for(const[o,a]of Object.entries(s)){if(!yi(r,o)){i=!0,Cs(o,()=>{e.validate(o),t.validate(a)});continue}const l=On(r,o),c=a;if(Object.is(l,c))continue;const d=Cs(o,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,c):t.validate(c));Object.is(d,l)||(i=!0)}for(const o of Object.keys(r))if(!yi(s,o)){i=!0;break}return i?s:r}),this.keyValidator=e,this.valueValidator=t}}function bI(n){return new _r(e=>{if(typeof e!==n)throw new St(`Expected ${n}, got ${Fl(e)}`);return e})}const Tee=new _r(n=>n),Mee=new _r(n=>n),ot=bI("string"),Ze=bI("number").check(n=>{if(Number.isNaN(n))throw new St("Expected a number, got NaN");if(!Number.isFinite(n))throw new St(`Expected a finite number, got ${n}`)}),iS=Ze.check(n=>{if(n<0)throw new St(`Expected a positive number, got ${n}`)}),bn=Ze.check(n=>{if(n<=0)throw new St(`Expected a non-zero positive number, got ${n}`)}),e4=Ze.check(n=>{if(!Number.isInteger(n))throw new St(`Expected an integer, got ${n}`)}),ny=e4.check(n=>{if(n<0)throw new St(`Expected a positive integer, got ${n}`)}),Aee=e4.check(n=>{if(n<=0)throw new St(`Expected a non-zero positive integer, got ${n}`)}),gt=bI("boolean");function kr(n){return new _r(e=>{if(e!==n)throw new St(`Expected ${n}, got ${JSON.stringify(e)}`);return n})}const rj=new _r(n=>{if(!Array.isArray(n))throw new St(`Expected an array, got ${Fl(n)}`);return n});function zn(n){return new Iee(n)}function ht(n){return new sS(n)}function nE(n){return typeof n=="object"&&n!==null&&(Object.getPrototypeOf(n)===Object.prototype||Object.getPrototypeOf(n)===null||Object.getPrototypeOf(n)===dq)}function rE(n){return n===null||typeof n=="number"||typeof n=="string"||typeof n=="boolean"?!0:Array.isArray(n)?n.every(rE):nE(n)?Object.values(n).every(rE):!1}const rr=new _r(n=>{if(rE(n))return n;throw new St(`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,rr.validate(e[r]);continue}const s=n[r],i=e[r];if(Object.is(s,i))continue;const o=rr.validateUsingKnownGoodVersion(s,i);Object.is(o,s)||(t=!0)}return t?e:n}else if(nE(n)&&nE(e)){let t=!1;for(const r of Object.keys(e)){if(!yi(n,r)){t=!0,rr.validate(e[r]);continue}const s=n[r],i=e[r];if(Object.is(s,i))continue;const o=rr.validateUsingKnownGoodVersion(s,i);Object.is(o,s)||(t=!0)}for(const r of Object.keys(n))if(!yi(e,r)){t=!0;break}return t?e:n}else return rr.validate(e)});function oS(n,e){return new _ee(n,e)}function CI(n,e){return new Fv(n,e,(t,r)=>{throw new St(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!1)}function Oee(n,e){return new Fv(n,e,(t,r)=>{throw new St(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!0)}function Wo(n,e){return new _r(t=>Cs(n,()=>e.validate(t)),(t,r)=>Cs(n,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(t,r):e.validate(r)))}function zv(n){return new _r(e=>{if(!n.has(e)){const t=Array.from(n,r=>JSON.stringify(r)).join(" or ");throw new St(`Expected ${t}, got ${e}`)}return e})}function t4(n){return new _r(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 Ree(n){return new _r(e=>e===null?null:n.validate(e),(e,t)=>t===null?null:n.validateUsingKnownGoodVersion&&e!==null?n.validateUsingKnownGoodVersion(e,t):n.validate(t))}function $v(...n){return zv(new Set(n))}function PI(n){try{return new URL(n)}catch{if(n.startsWith("/")||n.startsWith("./"))try{return new URL(n,"http://example.com")}catch{throw new St(`Expected a valid url, got ${JSON.stringify(n)}`)}throw new St(`Expected a valid url, got ${JSON.stringify(n)}`)}}const Dee=new Set(["http:","https:","mailto:"]),Ks=ot.check(n=>{if(n==="")return;const e=PI(n);if(!Dee.has(e.protocol.toLowerCase()))throw new St(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)}),jee=new Set(["http:","https:","data:","asset:"]),Zc=ot.check(n=>{if(n==="")return;const e=PI(n);if(!jee.has(e.protocol.toLowerCase()))throw new St(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});ot.check(n=>{if(n==="")return;if(!PI(n).protocol.toLowerCase().match(/^https?:$/))throw new St(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});const EI=ot.refine(n=>{try{return tq(n),n}catch{throw new St(`Expected an index key, got ${JSON.stringify(n)}`)}});Wl("@tldraw/validate","3.10.3","esm");function Us(n){return ot.refine(e=>{if(!e.startsWith(`${n}:`))throw new Error(`${n} ID must start with "${n}:"`);return e})}const Bv=Us("asset");function kI(n,e){return ht({id:Bv,typeName:kr("asset"),type:kr(n),props:e,meta:rr})}const Jc=ht({x:Ze,y:Ze,z:Ze.optional()}),Of=ht({x:Ze,y:Ze,w:Ze,h:Ze}),n4=Ze.check(n=>{if(n<0||n>1)throw new St("Opacity must be between 0 and 1")}),Nee=ot.refine(n=>{if(!n.startsWith("page:")&&!n.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return n}),di=Us("shape");function Lee(n,e,t){return ht({id:di,typeName:kr("shape"),x:Ze,y:Ze,rotation:Ze,index:EI,parentId:Nee,type:kr(n),isLocked:gt,opacity:n4,props:e?ht(e):rr,meta:t?ht(t):rr})}const Fee=Us("binding");function zee(n,e,t){return ht({id:Fee,typeName:kr("binding"),type:kr(n),fromId:di,toId:di,props:e?ht(e):rr,meta:t?ht(t):rr})}Ps("com.tldraw.binding",{});Gs({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Hc(n){return`binding:${_t()}`}function $ee(n){return Ko("binding",{scope:"document",validator:Wo("binding",CI("type",Jd(n,(e,{props:t,meta:r})=>zee(e,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class cr{constructor(e,t,r){this.id=e,this.defaultValue=t,this.type=r}static define(e,t){const{defaultValue:r,type:s=Mee}=t;return new cr(e,r,s)}static defineEnum(e,t){const{defaultValue:r,values:s}=t;return new Bee(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 Bee extends cr{constructor(e,t,r){super(e,t,$v(...r)),this.values=r}}const fm=Ps("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),Uee=Gs({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:fm.AddIsLocked,up:n=>{n.isLocked=!1},down:n=>{delete n.isLocked}},{id:fm.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:fm.AddMeta,up:n=>{n.meta={}}},{id:fm.AddWhite,up:n=>{},down:n=>{n.props.color==="white"&&(n.props.color="black")}}]});function xd(n){return n?n.typeName==="shape":!1}function ps(n){return n?n.startsWith("shape:"):!1}function Dt(n){return`shape:${n??_t()}`}function r4(n){const e=new Map;for(const[t,r]of Object.entries(n))if(r instanceof cr){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 ro(n,e){return Jd(e,(t,r)=>`com.tldraw.shape.${n}/${r}`)}function Hee(n){return Ko("shape",{scope:"document",validator:Wo("shape",CI("type",Jd(n,(e,{props:t,meta:r})=>Lee(e,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function sj(n,e){const t=[];for(const[r,{migrations:s}]of Object.entries(e)){const i=`com.tldraw.${n}.${r}`;s?"sequenceId"in s?(nt(i===s.sequenceId,`sequenceId mismatch for ${r} ${Lv} migrations. Expected '${i}', got '${s.sequenceId}'`),t.push(s)):"sequence"in s?t.push(Id({sequenceId:i,retroactive:!1,sequence:s.sequence.map(o=>"id"in o?s4(n,r,o):o)})):t.push(Id({sequenceId:i,retroactive:!1,sequence:Object.keys(s.migrators).map(o=>Number(o)).sort((o,a)=>o-a).map(o=>({id:`${i}/${o}`,scope:"record",filter:a=>a.typeName===n&&a.type===r,up:a=>{const l=s.migrators[o].up(a);if(l)return l},down:a=>{const l=s.migrators[o].down(a);if(l)return l}}))})):t.push(Id({sequenceId:i,retroactive:!1,sequence:[]}))}return t}function s4(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 i4=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],aS={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.8205 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.6225 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 za(n){return n.isDarkMode?aS.darkMode:aS.lightMode}const Ws=cr.defineEnum("tldraw:color",{defaultValue:"black",values:i4}),II=cr.defineEnum("tldraw:labelColor",{defaultValue:"black",values:i4}),Qc=cr.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),eu=cr.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Aa=cr.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),o4={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Fo=cr.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),a4=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],lS=cr.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:a4}),cS=cr.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:a4}),l4={labelColor:II,color:Ws,fill:eu,dash:Qc,size:Fo,arrowheadStart:lS,arrowheadEnd:cS,font:Aa,start:Jc,end:Jc,bend:Ze,text:ot,labelPosition:Ze,scale:bn},fd=ro("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function pm(n){return s4("shape","arrow",n)}const c4=Id({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[pm({id:fd.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"}),pm({id:fd.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)}}),pm({id:fd.AddLabelPosition,up:n=>{n.labelPosition=.5},down:n=>{delete n.labelPosition}}),{id:fd.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 i=Hc(),o={typeName:"binding",id:i,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};n[i]=o,t.props.start={x:0,y:0}}else delete t.props.start.type;if(s.type==="binding"){const i=Hc(),o={typeName:"binding",id:i,type:"arrow",fromId:t.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};n[i]=o,t.props.end={x:0,y:0}}else delete t.props.end.type}}},pm({id:fd.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}})]}),u4={terminal:$v("start","end"),normalizedAnchor:Jc,isExact:gt,isPrecise:gt},d4={sequence:[{dependsOn:[fd.ExtractBindings]}]},Kee=Wo("camera",ht({typeName:kr("camera"),id:Us("camera"),x:Ze,y:Ze,z:Ze,meta:rr})),Wee=Ps("com.tldraw.camera",{AddMeta:1}),Vee=Gs({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:Wee.AddMeta,up:n=>{n.meta={}}}]}),Ao=Ko("camera",{validator:Kee,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),qee=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"]),h4=zv(qee),Gee=ht({type:h4,rotation:Ze}),Yee=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),Xee=zv(Yee),Zee=new Set(["starting","paused","active","stopping"]),f4=ht({id:ot,points:zn(Jc),size:iS,color:Xee,opacity:Ze,state:zv(Zee),delay:Ze,shrink:Ze,taper:gt}),ip=Us("page"),Jee=Wo("page",ht({typeName:kr("page"),id:ip,name:ot,index:EI,meta:rr})),Qee=Ps("com.tldraw.page",{AddMeta:1}),ete=Gs({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:Qee.AddMeta,up:n=>{n.meta={}}}]}),Vs=Ko("page",{validator:Jee,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function ds(n){return Vs.isId(n)}const tte={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 p4(n){return n?If(n,e=>tte[e]):null}Us("instance");function nte(n){const e={};for(const[r,s]of n)e[r]=t4(s);const t=Wo("instance",ht({typeName:kr("instance"),id:Us("instance"),currentPageId:ip,followingUserId:ot.nullable(),brush:Of.nullable(),opacityForNextShape:n4,stylesForNextShape:ht(e),cursor:Gee,scribbles:zn(f4),isFocusMode:gt,isDebugMode:gt,isToolLocked:gt,exportBackground:gt,screenBounds:Of,insets:zn(gt),zoomBrush:Of.nullable(),isPenMode:gt,isGridMode:gt,chatMessage:ot,isChatting:gt,highlightedUserIds:zn(ot),isFocused:gt,devicePixelRatio:Ze,isCoarsePointer:gt,isHoveringCanvas:gt.nullable(),openMenus:zn(ot),isChangingStyle:gt,isReadonly:gt,meta:rr,duplicateProps:ht({shapeIds:zn(Us("shape")),offset:ht({x:Ze,y:Ze})}).nullable()}));return Ko("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 qt=Ps("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}),rte=Gs({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:qt.AddTransparentExportBgs,up:n=>({...n,exportBackground:!0})},{id:qt.RemoveDialog,up:({dialog:n,...e})=>e},{id:qt.AddToolLockMode,up:n=>({...n,isToolLocked:!1})},{id:qt.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:qt.AddLabelColor,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:{...n,labelColor:"black"}})},{id:qt.AddFollowingUserId,up:n=>({...n,followingUserId:null})},{id:qt.RemoveAlignJustify,up:n=>{let e=n.propsForNextShape.align;return e==="justify"&&(e="start"),{...n,propsForNextShape:{...n.propsForNextShape,align:e}}}},{id:qt.AddZoom,up:n=>({...n,zoomBrush:null})},{id:qt.AddVerticalAlign,up:n=>({...n,propsForNextShape:{...n.propsForNextShape,verticalAlign:"middle"}})},{id:qt.AddScribbleDelay,up:n=>n.scribble!==null?{...n,scribble:{...n.scribble,delay:0}}:{...n}},{id:qt.RemoveUserId,up:({userId:n,...e})=>e},{id:qt.AddIsPenModeAndIsGridMode,up:n=>({...n,isPenMode:!1,isGridMode:!1})},{id:qt.HoistOpacity,up:({propsForNextShape:{opacity:n,...e},...t})=>({...t,opacityForNextShape:Number(n??"1"),propsForNextShape:e})},{id:qt.AddChat,up:n=>({...n,chatMessage:"",isChatting:!1})},{id:qt.AddHighlightedUserIds,up:n=>({...n,highlightedUserIds:[]})},{id:qt.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:n,...e})=>({...e,stylesForNextShape:{}})},{id:qt.AddMeta,up:n=>({...n,meta:{}})},{id:qt.RemoveCursorColor,up:n=>{const{color:e,...t}=n.cursor;return{...n,cursor:t}}},{id:qt.AddLonelyProperties,up:n=>({...n,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:qt.ReadOnlyReadonly,up:({isReadOnly:n,...e})=>({...e,isReadonly:n})},{id:qt.AddHoveringCanvas,up:n=>({...n,isHoveringCanvas:null})},{id:qt.AddScribbles,up:({scribble:n,...e})=>({...e,scribbles:[]})},{id:qt.AddInset,up:n=>({...n,insets:[!1,!1,!1,!1]}),down:({insets:n,...e})=>({...e})},{id:qt.AddDuplicateProps,up:n=>({...n,duplicateProps:null}),down:({duplicateProps:n,...e})=>({...e})},{id:qt.RemoveCanMoveCamera,up:({canMoveCamera:n,...e})=>({...e}),down:n=>({...n,canMoveCamera:!0})}]}),Lr="instance:instance",ste=Wo("instance_page_state",ht({typeName:kr("instance_page_state"),id:Us("instance_page_state"),pageId:ip,selectedShapeIds:zn(di),hintingShapeIds:zn(di),erasingShapeIds:zn(di),hoveredShapeId:di.nullable(),editingShapeId:di.nullable(),croppingShapeId:di.nullable(),focusedGroupId:di.nullable(),meta:rr})),Qh=Ps("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),ite=Gs({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Qh.AddCroppingId,up(n){n.croppingShapeId=null}},{id:Qh.RemoveInstanceIdAndCameraId,up(n){delete n.instanceId,delete n.cameraId}},{id:Qh.AddMeta,up:n=>{n.meta={}}},{id:Qh.RenameProperties,up:n=>{},down:n=>{}},{id:Qh.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}}]}),Ki=Ko("instance_page_state",{validator:ste,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:{}})),ote=Wo("pointer",ht({typeName:kr("pointer"),id:Us("pointer"),x:Ze,y:Ze,lastActivityTimestamp:Ze,meta:rr})),ate=Ps("com.tldraw.pointer",{AddMeta:1}),lte=Gs({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:ate.AddMeta,up:n=>{n.meta={}}}]}),_I=Ko("pointer",{validator:ote,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),uS=_I.createId("pointer"),cte=Wo("instance_presence",ht({typeName:kr("instance_presence"),id:Us("instance_presence"),userId:ot,userName:ot,lastActivityTimestamp:Ze.nullable(),followingUserId:ot.nullable(),cursor:ht({x:Ze,y:Ze,type:h4,rotation:Ze}).nullable(),color:ot,camera:ht({x:Ze,y:Ze,z:Ze}).nullable(),screenBounds:Of.nullable(),selectedShapeIds:zn(Us("shape")),currentPageId:Us("page"),brush:Of.nullable(),scribbles:zn(f4),chatMessage:ot,meta:rr})),nd=Ps("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),ute=Gs({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:nd.AddScribbleDelay,up:n=>{n.scribble!==null&&(n.scribble.delay=0)}},{id:nd.RemoveInstanceId,up:n=>{delete n.instanceId}},{id:nd.AddChatMessage,up:n=>{n.chatMessage=""}},{id:nd.AddMeta,up:n=>{n.meta={}}},{id:nd.RenameSelectedShapeIds,up:n=>{}},{id:nd.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})}}]}),dte=Ko("instance_presence",{validator:cte,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),hte=Wo("document",ht({typeName:kr("document"),id:kr("document:document"),gridSize:Ze,name:ot,meta:rr})),ij=Ps("com.tldraw.document",{AddName:1,AddMeta:2}),fte=Gs({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:ij.AddName,up:n=>{n.name=""},down:n=>{delete n.name}},{id:ij.AddMeta,up:n=>{n.meta={}}}]}),TI=Ko("document",{validator:hte,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),sE=TI.createId("document");function pte(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function oj(n){n.typeName==="asset"&&("src"in n&&(n.src="<redacted>"),"src"in n.props&&(n.props.src="<redacted>"))}function gte({error:n,phase:e,record:t,recordBefore:r}){throw gk(n,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?oj(Yt(r)):void 0,recordAfter:oj(Yt(t))}}),n}function mte(){return[Vs.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function yte(n){const e=n.query.ids("page"),t=n.query.records("instance_page_state"),r=()=>{if(!n.has(sE))return n.put([TI.create({id:sE,name:n.props.defaultName})]),r();if(!n.has(uS))return n.put([_I.create({id:uS})]),r();const s=e.get();if(s.size===0)return n.put(mte()),r();const i=()=>[...s].map(d=>n.get(d)).sort(pte)[0].id,o=n.get(Lr);if(o){if(!s.has(o.currentPageId))return n.put([{...o,currentPageId:i()}]),r()}else return n.put([n.schema.types.instance.create({id:Lr,currentPageId:i(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const d of s){const f=Ki.createId(d);n.get(f)||a.add(f);const m=Ao.createId(d);n.has(m)||l.add(m)}a.size>0&&n.put([...a].map(d=>Ki.create({id:d,pageId:Ki.parseId(d)}))),l.size>0&&n.put([...l].map(d=>Ao.create({id:d})));const c=t.get();for(const d of c){if(!s.has(d.pageId)){n.remove([d.id]);continue}if(d.croppingShapeId&&!n.has(d.croppingShapeId))return n.put([{...d,croppingShapeId:null}]),r();if(d.focusedGroupId&&!n.has(d.focusedGroupId))return n.put([{...d,focusedGroupId:null}]),r();if(d.hoveredShapeId&&!n.has(d.hoveredShapeId))return n.put([{...d,hoveredShapeId:null}]),r();const f=d.selectedShapeIds.filter(y=>n.has(y));if(f.length!==d.selectedShapeIds.length)return n.put([{...d,selectedShapeIds:f}]),r();const p=d.hintingShapeIds.filter(y=>n.has(y));if(p.length!==d.hintingShapeIds.length)return n.put([{...d,hintingShapeIds:p}]),r();const m=d.erasingShapeIds.filter(y=>n.has(y));if(m.length!==d.erasingShapeIds.length)return n.put([{...d,erasingShapeIds:m}]),r()}};return r}const Ste=kI("bookmark",ht({title:ot,description:ot,image:ot,favicon:ot,src:Zc.nullable()})),aj=Ps("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),vte=Gs({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:n=>n.type==="bookmark",sequence:[{id:aj.MakeUrlsValid,up:n=>{Zc.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:aj.AddFavicon,up:n=>{Zc.isValid(n.props.favicon)||(n.props.favicon="")},down:n=>{delete n.props.favicon}}]}),xte=kI("image",ht({w:Ze,h:Ze,name:ot,isAnimated:gt,mimeType:ot.nullable(),src:Zc.nullable(),fileSize:bn.optional()})),ef=Ps("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),wte=Gs({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:n=>n.type==="image",sequence:[{id:ef.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:ef.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:ef.MakeUrlsValid,up:n=>{Zc.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:ef.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:ef.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),bte=kI("video",ht({w:Ze,h:Ze,name:ot,isAnimated:gt,mimeType:ot.nullable(),src:Zc.nullable(),fileSize:Ze.optional()})),tf=Ps("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),Cte=Gs({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:n=>n.type==="video",sequence:[{id:tf.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:tf.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:tf.MakeUrlsValid,up:n=>{Zc.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:tf.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:tf.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),Pte=Wo("asset",CI("type",{image:xte,video:bte,bookmark:Ste})),Ete=Ps("com.tldraw.asset",{AddMeta:1}),kte=Gs({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:Ete.AddMeta,up:n=>{n.meta={}}}]}),zl=Ko("asset",{validator:Pte,scope:"document"}).withDefaultProperties(()=>({meta:{}})),g4={w:bn,h:bn,assetId:Bv.nullable(),url:Ks},lj=ro("bookmark",{NullAssetId:1,MakeUrlsValid:2}),m4={sequence:[{id:lj.NullAssetId,up:n=>{n.assetId===void 0&&(n.assetId=null)},down:"retired"},{id:lj.MakeUrlsValid,up:n=>{Ks.isValid(n.url)||(n.url="")},down:n=>{}}]},y4=ht({type:$v("free","straight"),points:zn(Jc)}),S4={color:Ws,fill:eu,dash:Qc,size:Fo,segments:zn(y4),isComplete:gt,isClosed:gt,isPen:gt,scale:bn},cj=ro("draw",{AddInPen:1,AddScale:2}),v4={sequence:[{id:cj.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:cj.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},Ite=/(^\/r\/[^/]+\/?$)/,_te=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:n=>{const e=Je(n);if(e&&e.pathname.match(Ite))return n}},{hostnames:["figma.com"],fromEmbedUrl:n=>{const e=Je(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{hostnames:["google.*"],fromEmbedUrl:n=>{const e=Je(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,i]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${i},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:n=>{const e=Je(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:n=>{const e=Je(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,i]=t;return`https://codepen.io/${s}/pen/${i}`}}},{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=Je(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=Je(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=Je(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=Je(n);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return n.split("/").pop()?n:void 0}},{hostnames:["replit.com"],fromEmbedUrl:n=>{const e=Je(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:n=>{const e=Je(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=Je(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=Je(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=Je(n);if(e&&e.hash.match(/#room=/))return n}},{hostnames:["observablehq.com"],fromEmbedUrl:n=>{const e=Je(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=Je(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],x4={w:bn,h:bn,url:ot},gm=ro("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),w4={sequence:[{id:gm.GenOriginalUrlInEmbed,up:n=>{try{const e=n.url,t=new URL(e).host.replace("www.","");let r;for(const s of _te)if(s.hostnames.includes(t))try{r=s.fromEmbedUrl(e)}catch(i){console.warn(i)}n.tmpOldUrl=n.url,n.url=r??""}catch{n.url="",n.tmpOldUrl=n.url}},down:"retired"},{id:gm.RemoveDoesResize,up:n=>{delete n.doesResize},down:"retired"},{id:gm.RemoveTmpOldUrl,up:n=>{delete n.tmpOldUrl},down:"retired"},{id:gm.RemovePermissionOverrides,up:n=>{delete n.overridePermissions},down:"retired"}]},b4={w:bn,h:bn,name:ot},C4={sequence:[]},MI=ht({type:ot,content:zn(Tee)});function wi(n){return{type:"doc",content:n.split(`
178
+ `).map(r=>r?{type:"paragraph",content:[{type:"text",text:r}]}:{type:"paragraph"})}}const dS=cr.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),hS=cr.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Wi=cr.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"]}),P4={geo:Wi,labelColor:II,color:Ws,fill:eu,dash:Qc,size:Fo,font:Aa,align:dS,verticalAlign:hS,url:Ks,w:bn,h:bn,growY:iS,richText:MI,scale:bn},vo=ro("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9,AddRichText:10}),E4={sequence:[{id:vo.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:vo.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"},{id:vo.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:vo.AddCheckBox,up:n=>{},down:"retired"},{id:vo.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:vo.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:vo.AddCloud,up:n=>{},down:"retired"},{id:vo.MakeUrlsValid,up:n=>{Ks.isValid(n.url)||(n.url="")},down:n=>{}},{id:vo.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:vo.AddRichText,up:n=>{n.richText=wi(n.text),delete n.text}}]},k4={},I4={sequence:[]},_4={color:Ws,size:Fo,segments:zn(y4),isComplete:gt,isPen:gt,scale:bn},Tte=ro("highlight",{AddScale:1}),T4={sequence:[{id:Tte.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},Mte=ht({topLeft:Jc,bottomRight:Jc}),M4={w:bn,h:bn,playing:gt,url:Ks,assetId:Bv.nullable(),crop:Mte.nullable(),flipX:gt,flipY:gt},mm=ro("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),A4={sequence:[{id:mm.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:mm.AddCropProp,up:n=>{n.crop=null},down:n=>{delete n.crop}},{id:mm.MakeUrlsValid,up:n=>{Ks.isValid(n.url)||(n.url="")},down:n=>{}},{id:mm.AddFlipProps,up:n=>{n.flipX=!1,n.flipY=!1},down:n=>{delete n.flipX,delete n.flipY}}]},fS=cr.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),Ate=ht({id:ot,index:EI,x:Ze,y:Ze}),O4={color:Ws,dash:Qc,size:Fo,spline:fS,points:oS(ot,Ate),scale:bn},nf=ro("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),R4={sequence:[{id:nf.AddSnapHandles,up:n=>{for(const e of Object.values(n.handles))e.canSnap=!0},down:"retired"},{id:nf.RemoveExtraHandleProps,up:n=>{n.handles=JL(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(Qn);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:nf.HandlesToPoints,up:n=>{const e=Object.entries(n.handles).map(([t,{x:r,y:s}])=>({x:r,y:s,index:t})).sort(Qn);n.points=e.map(({x:t,y:r})=>({x:t,y:r})),delete n.handles},down:n=>{const e=Yf(n.points.length);n.handles=Object.fromEntries(n.points.map((t,r)=>[e[r],{x:t.x,y:t.y}])),delete n.points}},{id:nf.PointIndexIds,up:n=>{const e=Yf(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(Qn);n.points=e.map(({x:t,y:r})=>({x:t,y:r}))}},{id:nf.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},D4={color:Ws,labelColor:II,size:Fo,font:Aa,fontSizeAdjustment:iS,align:dS,verticalAlign:hS,growY:iS,url:Ks,richText:MI,scale:bn},ca=ro("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8,AddRichText:9}),j4={sequence:[{id:ca.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:ca.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:ca.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:ca.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:ca.MakeUrlsValid,up:n=>{Ks.isValid(n.url)||(n.url="")},down:n=>{}},{id:ca.AddFontSizeAdjustment,up:n=>{n.fontSizeAdjustment=0},down:n=>{delete n.fontSizeAdjustment}},{id:ca.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:ca.AddLabelColor,up:n=>{n.labelColor="black"},down:n=>{delete n.labelColor}},{id:ca.AddRichText,up:n=>{n.richText=wi(n.text),delete n.text}}]},iE=cr.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),N4={color:Ws,size:Fo,font:Aa,textAlign:iE,w:bn,richText:MI,scale:bn,autoSize:gt},tC=ro("text",{RemoveJustify:1,AddTextAlign:2,AddRichText:3}),L4={sequence:[{id:tC.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:tC.AddTextAlign,up:n=>{n.textAlign=n.align,delete n.align},down:n=>{n.align=n.textAlign,delete n.textAlign}},{id:tC.AddRichText,up:n=>{n.richText=wi(n.text),delete n.text}}]},F4={w:bn,h:bn,time:Ze,playing:gt,url:Ks,assetId:Bv.nullable()},uj=ro("video",{AddUrlProp:1,MakeUrlsValid:2}),z4={sequence:[{id:uj.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:uj.MakeUrlsValid,up:n=>{Ks.isValid(n.url)||(n.url="")},down:n=>{}}]},ym=Ps("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),Ote=Id({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:ym.RemoveCodeAndIconShapeTypes,scope:"store",up:n=>{for(const[e,t]of xs(n))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete n[e]}},{id:ym.AddInstancePresenceType,scope:"store",up(n){}},{id:ym.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:n=>{for(const[e,t]of xs(n))t.typeName.match(/^(user|user_presence)$/)&&delete n[e]}},{id:ym.RemoveUserDocument,scope:"store",up:n=>{for(const[e,t]of xs(n))t.typeName.match("user_document")&&delete n[e]}}]}),Rte={arrow:{migrations:c4,props:l4},bookmark:{migrations:m4,props:g4},draw:{migrations:v4,props:S4},embed:{migrations:w4,props:x4},frame:{migrations:C4,props:b4},geo:{migrations:E4,props:P4},group:{migrations:I4,props:k4},highlight:{migrations:T4,props:_4},image:{migrations:A4,props:M4},line:{migrations:R4,props:O4},note:{migrations:j4,props:D4},text:{migrations:L4,props:N4},video:{migrations:z4,props:F4}},Dte={arrow:{migrations:d4,props:u4}};function jte({shapes:n=Rte,bindings:e=Dte,migrations:t}={}){const r=new Map;for(const a of fn(n))for(const l of r4(a.props??{}).keys()){if(r.has(l.id)&&r.get(l.id)!==l)throw new Error(`Multiple StyleProp instances with the same id: ${l.id}`);r.set(l.id,l)}const s=Hee(n),i=$ee(e),o=nte(r);return wI.create({asset:zl,binding:i,camera:Ao,document:TI,instance:o,instance_page_state:Ki,page:Vs,instance_presence:dte,pointer:_I,shape:s},{migrations:[Ote,kte,Vee,fte,rte,ite,ete,ute,lte,Uee,vte,wte,Cte,...sj("shape",n),...sj("binding",e),...t??[]],onValidationFailure:gte,createIntegrityChecker:yte})}const op=[{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 Nte(){const n=typeof window<"u"?window.navigator.languages??["en"]:["en"];return Lte(n)}function Lte(n){for(const e of n){const t=Fte(e);if(t)return t}return"en"}const dj={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function Fte(n){const e=op.find(s=>s.locale===n.toLowerCase());if(e)return e.locale;const[t,r]=n.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=op.find(i=>i.locale===t);if(s)return s.locale}return t in dj?dj[t]:null}Wl("@tldraw/tlschema","3.10.3","esm");var nC={exports:{}};/*!
179
+ Copyright (c) 2018 Jed Watson.
180
+ Licensed under the MIT License (MIT), see
181
+ http://jedwatson.github.io/classnames
182
+ */var hj;function zte(){return hj||(hj=1,function(n){(function(){var e={}.hasOwnProperty;function t(){for(var i="",o=0;o<arguments.length;o++){var a=arguments[o];a&&(i=s(i,r(a)))}return i}function r(i){if(typeof i=="string"||typeof i=="number")return i;if(typeof i!="object")return"";if(Array.isArray(i))return t.apply(null,i);if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]"))return i.toString();var o="";for(var a in i)e.call(i,a)&&i[a]&&(o=s(o,a));return o}function s(i,o){return o?i?i+" "+o:i+o:i}n.exports?(t.default=t,n.exports=t):window.classNames=t})()}(nC)),nC.exports}var $te=zte();const ze=ja($te),$4="3.10.3",fj={major:"2024-09-13T14:36:29.063Z",minor:"2025-03-11T14:20:29.409Z"},Bte={error:null};class AI extends P.Component{constructor(){super(...arguments);O(this,"state",Bte)}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 g.jsx(r,{error:t})}return this.props.children}}function ap({children:n,fallback:e,...t}){return e===null?n:g.jsx(AI,{fallback:e,...t,children:n})}function OI(n,e){return Uv(`${n}_${e}`)}function pu(n){return Uv(`${P.useId()}${n??""}`)}function Yi(n){const e=Nr(P.useContext(B4));return Uv(`${e}_${n}`)}function Uv(n){return n.replace(/:/g,"_")}const B4=P.createContext(null);function Ute({children:n}){const e=pu();return g.jsx(B4.Provider,{value:e,children:n})}const RI=P.createContext(null);function te(){const n=He.useContext(RI);if(!n)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return n}function Tr(){return He.useContext(RI)}function DI({editor:n,children:e}){return g.jsx(RI.Provider,{value:n,children:g.jsx(Ute,{children:e})})}function Hte(){return g.jsx("div",{className:"tl-background"})}function sh(n,e,t,r,s,i){P.useLayoutEffect(()=>{const o=n.current;if(!o||e===void 0)return;let a=`translate(${e}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),s!==void 0&&(a+=` rotate(${s}rad)`),i&&(a+=` translate(${i.x}px, ${i.y}px)`),o.style.transform=a})}const rC=({brush:n,color:e,opacity:t,className:r})=>{const s=P.useRef(null);sh(s,n.x,n.y);const i=ee(Math.max(1,n.w)),o=ee(Math.max(1,n.h));return g.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?g.jsxs("g",{className:"tl-brush",opacity:t,children:[g.jsx("rect",{width:i,height:o,fill:e,opacity:.75}),g.jsx("rect",{width:i,height:o,fill:"none",stroke:e,opacity:.1})]}):g.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:i,height:o})})},Pt={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1,hasCanvasSupport:!1};typeof window<"u"&&"navigator"in window&&(Pt.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Pt.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Pt.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Pt.isFirefox=/firefox/i.test(navigator.userAgent),Pt.isAndroid=/android/i.test(navigator.userAgent),Pt.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Pt.hasCanvasSupport=typeof window<"u"&&"Promise"in window&&"HTMLCanvasElement"in window);const pj={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},sC={duration:0,easing:$n.easeInOutCubic},gj={CAMERA_MOVE:-10},Kte=["top","right","bottom","left"],mj=0,jI=2,Sm=1,yj=5,Wte=128;var iC={};const Vte={},U4=us("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),xn={logPreventDefaults:us("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:us("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:us("logElementRemoves",{defaults:{all:!1}}),debugSvg:us("debugSvg",{defaults:{all:!1}}),showFps:us("showFps",{defaults:{all:!1}}),measurePerformance:us("measurePerformance",{defaults:{all:!1}}),throwToBlob:us("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:us("reconnectOnPing",{defaults:{all:!1}}),debugCursors:us("debugCursors",{defaults:{all:!1}}),forceSrgb:us("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:us("debugGeometry",{defaults:{all:!1}}),hideShapes:us("hideShapes",{defaults:{all:!1}}),editOnType:us("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const n=Element.prototype.removeChild;qi("element removal logging",()=>{xn.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),n.call(this,e)}:Element.prototype.removeChild=n})}function us(n,{defaults:e,shouldStoreForSession:t=!0}){return qte({name:n,defaults:e,shouldStoreForSession:t})}function qte(n){const e=Yte(n),t=n.shouldStoreForSession?Gte(n.name):null,r=on(`debug:${n.name}`,t??e);return typeof window<"u"&&(n.shouldStoreForSession&&qi(`debug:${n.name}`,()=>{const s=r.get();s===e?f3(`tldraw_debug:${n.name}`):bk(`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 Gte(n){try{return JSON.parse(h3(`tldraw_debug:${n}`)??"null")}catch{return null}}function oC(n){try{return n()}catch{return null}}function Yte(n){switch(oC(()=>iC.TLDRAW_ENV)??oC(()=>iC.VERCEL_PUBLIC_TLDRAW_ENV)??oC(()=>iC.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 pS(n){if(n instanceof HTMLElement)return n;if(n.parentElement)return pS(n.parentElement);throw Error("Could not find a parent element of an HTML type!")}function tt(n){n.preventDefault(),xn.logPreventDefaults.get()&&console.warn("preventDefault called on event:",n)}function Rp(n,e){if(n.setPointerCapture(e.pointerId),xn.logPointerCaptures.get()){const t=U4.get();t.set(n,(t.get(n)??0)+1),console.warn("setPointerCapture called on element:",n,e)}}function Dp(n,e){if(n.hasPointerCapture(e.pointerId)&&(n.releasePointerCapture(e.pointerId),xn.logPointerCaptures.get())){const t=U4.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 Xt=n=>n.stopPropagation(),mr=(n,e,t)=>{n&&n.style.setProperty(e,t)},Xte=["input","select","button","textarea"];function H4(){const{activeElement:n}=document;return!!(n&&(n.isContentEditable||Xte.indexOf(n.tagName.toLowerCase())>-1))}const Cr=n=>Pt.isDarwin?n.metaKey:n.ctrlKey||n.metaKey;function Fs(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:Cr(n),pointerId:n.pointerId,button:n.button,isPen:n.pointerType==="pen"}}function NI(){const n=te();return P.useMemo(function(){let r,s;function i(v){if(!v.isKilled){if(v.button===jI){n.dispatch({type:"pointer",target:"canvas",name:"right_click",...Fs(v)});return}v.button!==0&&v.button!==1&&v.button!==5||(Rp(v.currentTarget,v),n.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Fs(v)}))}}function o(v){v.isKilled||v.clientX===r&&v.clientY===s||(r=v.clientX,s=v.clientY,n.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Fs(v)}))}function a(v){v.isKilled||v.button!==0&&v.button!==1&&v.button!==2&&v.button!==5||(r=v.clientX,s=v.clientY,Dp(v.currentTarget,v),n.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Fs(v)}))}function l(v){if(v.isKilled||n.getInstanceState().isPenMode&&v.pointerType!=="pen")return;const x=v.pointerType==="mouse"||v.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:x?!0:null})}function c(v){if(v.isKilled||n.getInstanceState().isPenMode&&v.pointerType!=="pen")return;const x=v.pointerType==="mouse"||v.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:x?!1:null})}function d(v){v.isKilled=!0,tt(v)}function f(v){v.isKilled=!0,v.target instanceof HTMLElement&&v.target.tagName!=="A"&&v.target.tagName!=="TEXTAREA"&&v.target.isContentEditable&&!(n.getEditingShape()&&v.target.className.includes("tl-text-content"))&&tt(v)}function p(v){tt(v)}async function m(v){var b,C;if(tt(v),Xt(v),(C=(b=v.dataTransfer)==null?void 0:b.files)!=null&&C.length){const I=Array.from(v.dataTransfer.files);await n.putExternalContent({type:"files",files:I,point:n.screenToPage({x:v.clientX,y:v.clientY}),ignoreParent:!1});return}const x=v.dataTransfer.getData("url");if(x){await n.putExternalContent({type:"url",url:x,point:n.screenToPage({x:v.clientX,y:v.clientY})});return}}function y(v){Xt(v)}return{onPointerDown:i,onPointerMove:o,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:m,onTouchStart:d,onTouchEnd:f,onClick:y}},[n])}function Zte(){const n=te();P.useEffect(()=>{let e=n.getInstanceState().isCoarsePointer;const t=o=>{const a=o.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=Pt.isFirefox&&!Pt.isAndroid&&!Pt.isIos,i=()=>{const o=s?!1:r.matches;e===o&&(e=o,n.updateInstanceState({isCoarsePointer:o}))};return r&&(r.addEventListener("change",i),i()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",i)}},[n])}const K4=P.createContext(null);function W4({container:n,children:e}){return g.jsx(K4.Provider,{value:n,children:e})}function In(){return Nr(P.useContext(K4),"useContainer used outside of <Tldraw />")}function Jte(){const n=te(),e=In(),t=ie("isFocused",()=>n.getIsFocused(),[n]);P.useEffect(()=>{if(!e)return;function r(s){if(s.isSpecialRedispatchedEvent)return;tt(s),Xt(s);const i=e.querySelector(".tl-canvas");if(!i)return;const o=new DragEvent(s.type,s);o.isSpecialRedispatchedEvent=!0,i.dispatchEvent(o)}return e.addEventListener("dragover",r),e.addEventListener("drop",r),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",r)}},[e]),P.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let r=null;const s=()=>{r!=null&&r();const i=`(resolution: ${window.devicePixelRatio}dppx)`,o=matchMedia(i),a=l=>{l.type==="change"&&s()};o.addEventListener?o.addEventListener("change",s):o.addListener&&o.addListener(a),r=()=>{o.removeEventListener?o.removeEventListener("change",s):o.removeListener&&o.removeListener(a)},n.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{r==null||r()}},[n]),P.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(n.isIn("zoom")||!n.getPath().endsWith(".idle"))&&!vm(n)&&tt(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){tt(a);return}break}case"Tab":{if(vm(n))return;break}case",":return;case"Escape":{if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&tt(a),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),e.focus());return}default:if(vm(n))return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,metaKey:a.metaKey,accelKey:Cr(a)};n.dispatch(l)},s=a=>{if(a.isKilled||(a.isKilled=!0,vm(n))||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,metaKey:a.metaKey,accelKey:Cr(a)};n.dispatch(l)};function i(a){var l,c;if(e.contains(a.target)){const d=a.touches[0].pageX,f=a.touches[0].radiusX||0;(d-f<10||d+f>n.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),tt(a))}}const o=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&tt(a)};return e.addEventListener("touchstart",i,{passive:!1}),e.addEventListener("wheel",o,{passive:!1}),document.addEventListener("gesturestart",tt),document.addEventListener("gesturechange",tt),document.addEventListener("gestureend",tt),e.addEventListener("keydown",r),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",i),e.removeEventListener("wheel",o),document.removeEventListener("gesturestart",tt),document.removeEventListener("gesturechange",tt),document.removeEventListener("gestureend",tt),e.removeEventListener("keydown",r),e.removeEventListener("keyup",s)}},[n,e,t])}function vm(n){return n.menus.hasOpenMenus()||H4()}const Qte=["textarea","input"];function ene(n){const e=te();P.useEffect(()=>{const t=n.current;if(!t)return;const r=s=>{var i;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:o}=s;if(Qte.includes((i=o.tagName)==null?void 0:i.toLocaleLowerCase())||o.isContentEditable||e.isIn("select.editing_shape"))return;tt(s)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[e,n])}function tne(n,e,t){return Math.max(e,Math.min(n,t))}const sr={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 Sj(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function vj(n,e,t,r=.15){return r===0?tne(n,e,t):n<e?-Sj(e-n,t-e,r)+e:n>t?+Sj(n-t,t-e,r)+t:n}function nne(n,[e,t],[r,s]){const[[i,o],[a,l]]=n;return[vj(e,i,o,r),vj(t,a,l,s)]}function rne(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 sne(n){var e=rne(n,"string");return typeof e=="symbol"?e:String(e)}function xr(n,e,t){return e=sne(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function xj(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 an(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?xj(Object(t),!0).forEach(function(r){xr(n,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):xj(Object(t)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))})}return n}const V4={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 wj(n){return n?n[0].toUpperCase()+n.slice(1):""}const ine=["enter","leave"];function one(n=!1,e){return n&&!ine.includes(e)}function ane(n,e="",t=!1){const r=V4[n],s=r&&r[e]||e;return"on"+wj(n)+wj(s)+(one(t,s)?"Capture":"")}const lne=["gotpointercapture","lostpointercapture"];function cne(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const r=lne.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function une(n,e=""){const t=V4[n],r=t&&t[e]||e;return n+r}function q4(n){return"touches"in n}function dne(n){return q4(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function hne(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 oE(n,e){try{const t=e.clientX-n.clientX,r=e.clientY-n.clientY,s=(e.clientX+n.clientX)/2,i=(e.clientY+n.clientY)/2,o=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:o,origin:[s,i]}}catch{}return null}function fne(n){return hne(n).map(e=>e.identifier)}function bj(n,e){const[t,r]=Array.from(n.touches).filter(s=>e.includes(s.identifier));return oE(t,r)}const Cj=40,Pj=800;function G4(n){let{deltaX:e,deltaY:t,deltaMode:r}=n;return r===1?(e*=Cj,t*=Cj):r===2&&(e*=Pj,t*=Pj),[e,t]}function pne(n){const e={};if("buttons"in n&&(e.buttons=n.buttons),"shiftKey"in n){const{shiftKey:t,altKey:r,metaKey:s,ctrlKey:i}=n;Object.assign(e,{shiftKey:t,altKey:r,metaKey:s,ctrlKey:i})}return e}function gS(n,...e){return typeof n=="function"?n(...e):n}function gne(){}function mne(...n){return n.length===0?gne:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function Ej(n,e){return Object.assign({},e,n||{})}const yne=32;class Y4{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?gS(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 i=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,pne(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,i=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const A=t._delta.map(Math.abs);sr.addTo(t._distance,A)}this.axisIntent&&this.axisIntent(e);const[o,a]=t._movement,[l,c]=r.threshold,{_step:d,values:f}=t;if(r.hasCustomTransform?(d[0]===!1&&(d[0]=Math.abs(o)>=l&&f[0]),d[1]===!1&&(d[1]=Math.abs(a)>=c&&f[1])):(d[0]===!1&&(d[0]=Math.abs(o)>=l&&Math.sign(o)*l),d[1]===!1&&(d[1]=Math.abs(a)>=c&&Math.sign(a)*c)),t.intentional=d[0]!==!1||d[1]!==!1,!t.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[A,R]=f;p[0]=d[0]!==!1?A-d[0]:0,p[1]=d[1]!==!1?R-d[1]:0}else p[0]=d[0]!==!1?o-d[0]:0,p[1]=d[1]!==!1?a-d[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(p);const m=t.offset,y=t._active&&!t._blocked||t.active;y&&(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=gS(r.bounds,t)),this.setup&&this.setup()),t.movement=p,this.computeOffset()));const[v,x]=t.offset,[[b,C],[I,_]]=t._bounds;t.overflow=[v<b?-1:v>C?1:0,x<I?-1:x>_?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 T=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=nne(t._bounds,t.offset,T),t.delta=sr.sub(t.offset,m),this.computeMovement(),y&&(!t.last||i>yne)){t.delta=sr.sub(t.offset,m);const A=t.delta.map(Math.abs);sr.addTo(t.distance,A),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&i>0&&(t.velocity=[A[0]/i,A[1]/i],t.timeDelta=i)}}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(an(an(an({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function Sne([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 vne extends Y4{constructor(...e){super(...e),xr(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=sr.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=sr.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[dne(e)]:r.axisThreshold;t.axis=Sne(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 xne=n=>n,kj=.15,X4={enabled(n=!0){return n},eventOptions(n,e,t){return an(an({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[kj,kj];case!1:return[0,0];default:return sr.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return sr.toVector(n)},transform(n,e,t){const r=n||t.shared.transform;return this.hasCustomTransform=!!r,r||xne},threshold(n){return sr.toVector(n,0)}},wne=0,jp=an(an({},X4),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=wne){return n},bounds(n={}){if(typeof n=="function")return i=>jp.bounds(n(i));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]]}}),Np=typeof window<"u"&&window.document&&window.document.createElement;function Z4(){return Np&&"ontouchstart"in window}function bne(){return Z4()||Np&&window.navigator.maxTouchPoints>1}function Cne(){return Np&&"onpointerdown"in window}function Pne(){return Np&&"exitPointerLock"in window.document}function Ene(){try{return"constructor"in GestureEvent}catch{return!1}}const hi={isBrowser:Np,gesture:Ene(),touch:Z4(),touchscreen:bne(),pointer:Cne(),pointerLock:Pne()},kne=250,Ine=180,_ne=.5,Tne=50,Mne=250,Ane=10,Ij={mouse:0,touch:0,pen:8};an(an({},jp),{},{device(n,e,{pointer:{touch:t=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&hi.pointerLock,hi.touch&&t?"touch":this.pointerLock?"mouse":hi.pointer&&!s?"pointer":hi.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?kne:void 0,!(!hi.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 i=sr.toVector(n,t?r:s?1:0);return this.filterTaps=t,this.tapsThreshold=r,i},swipe({velocity:n=_ne,distance:e=Tne,duration:t=Mne}={}){return{velocity:this.transform(sr.toVector(n)),distance:this.transform(sr.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return Ine;case!1:return 0;default:return n}},axisThreshold(n){return n?an(an({},Ij),n):Ij},keyboardDisplacement(n=Ane){return n}});function J4(n){const[e,t]=n.overflow,[r,s]=n._delta,[i,o]=n._direction;(e<0&&r>0&&i<0||e>0&&r<0&&i>0)&&(n._movement[0]=n._movementBound[0]),(t<0&&s>0&&o<0||t>0&&s<0&&o>0)&&(n._movement[1]=n._movementBound[1])}const One=30,Rne=100;class Dne extends Y4{constructor(...e){super(...e),xr(this,"ingKey","pinching"),xr(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=sr.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)*One-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(i=>r.has(i))||r.size<2)return;this.start(e),t._touchIds=Array.from(r).slice(0,2);const s=bj(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(o=>s.has(o))||(r.size<2&&r.set(e.pointerId,e),t._pointerEvents.size<2))return;this.start(e);const i=oE(...Array.from(r.values()));i&&this.pinchStart(e,i)}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=bj(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=oE(...Array.from(t.values()));r&&this.pinchMove(e,r)}pinchMove(e,t){const r=this.state,s=r._values[1],i=t.angle-s;let o=0;Math.abs(i)>270&&(o+=Math.sign(i)),this.computeValues([t.distance,t.angle-360*o]),r.origin=t.origin,r.turns=o,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=sr.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=[-G4(e)[1]/Rne*r.offset[0],0],sr.addTo(r._movement,r._delta),J4(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 jne=an(an({},X4),{},{device(n,e,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!hi.touch&&hi.gesture)return"gesture";if(hi.touch&&r)return"touch";if(hi.touchscreen){if(hi.pointer)return"pointer";if(hi.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:r={}}){const s=o=>{const a=Ej(gS(t,o),{min:-1/0,max:1/0});return[a.min,a.max]},i=o=>{const a=Ej(gS(r,o),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[s(),i()]:o=>[s(o),i(o)]},threshold(n,e,t){return this.lockDirection=t.axis==="lock",sr.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});an(an({},jp),{},{mouseOnly:(n=!0)=>n});class Nne extends vne{constructor(...e){super(...e),xr(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=G4(e),sr.addTo(t._movement,t._delta),J4(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 Lne=jp;an(an({},jp),{},{mouseOnly:(n=!0)=>n});const LI=new Map,aE=new Map;function Fne(n){LI.set(n.key,n.engine),aE.set(n.key,n.resolver)}const zne={key:"pinch",engine:Dne,resolver:jne},$ne={key:"wheel",engine:Nne,resolver:Lne};function Bne(n,e){if(n==null)return{};var t={},r=Object.keys(n),s,i;for(i=0;i<r.length;i++)s=r[i],!(e.indexOf(s)>=0)&&(t[s]=n[s]);return t}function Une(n,e){if(n==null)return{};var t=Bne(n,e),r,s;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);for(s=0;s<i.length;s++)r=i[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(n,r)&&(t[r]=n[r])}return t}const Hne={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=hi.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},Kne=["target","eventOptions","window","enabled","transform"];function ry(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]=ry(n[r],s);break;case"boolean":s&&(t[r]=n[r]);break}return t}function Wne(n,e,t={}){const r=n,{target:s,eventOptions:i,window:o,enabled:a,transform:l}=r,c=Une(r,Kne);if(t.shared=ry({target:s,eventOptions:i,window:o,enabled:a,transform:l},Hne),e){const d=aE.get(e);t[e]=ry(an({shared:t.shared},c),d)}else for(const d in c){const f=aE.get(d);f&&(t[d]=ry(an({shared:t.shared},c[d]),f))}return t}class Q4{constructor(e,t){xr(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,r,s,i){const o=this._listeners,a=une(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=an(an({},l),i);e.addEventListener(a,s,c);const d=()=>{e.removeEventListener(a,s,c),o.delete(d)};return o.add(d),d}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Vne{constructor(){xr(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 qne{constructor(e){xr(this,"gestures",new Set),xr(this,"_targetEventStore",new Q4(this)),xr(this,"gestureEventStores",{}),xr(this,"gestureTimeoutStores",{}),xr(this,"handlers",{}),xr(this,"config",{}),xr(this,"pointerIds",new Set),xr(this,"touchIds",new Set),xr(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Gne(this,e)}setEventIds(e){if(q4(e))return this.touchIds=new Set(fne(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=Wne(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 o of this.gestures){const a=this.config[o],l=_j(r,a.eventOptions,!!s);if(a.enabled){const c=LI.get(o);new c(this,e,o).bind(l)}}const i=_j(r,t.eventOptions,!!s);for(const o in this.nativeHandlers)i(o,"",a=>this.nativeHandlers[o](an(an({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const i in r)r[i]=mne(...r[i]);if(!s)return r;for(const i in r){const{device:o,capture:a,passive:l}=cne(i);this._targetEventStore.add(s,o,"",r[i],{capture:a,passive:l})}}}}function rd(n,e){n.gestures.add(e),n.gestureEventStores[e]=new Q4(n,e),n.gestureTimeoutStores[e]=new Vne}function Gne(n,e){e.drag&&rd(n,"drag"),e.wheel&&rd(n,"wheel"),e.scroll&&rd(n,"scroll"),e.move&&rd(n,"move"),e.pinch&&rd(n,"pinch"),e.hover&&rd(n,"hover")}const _j=(n,e,t)=>(r,s,i,o={},a=!1)=>{var l,c;const d=(l=o.capture)!==null&&l!==void 0?l:e.capture,f=(c=o.passive)!==null&&c!==void 0?c:e.passive;let p=a?r:ane(r,s,d);t&&f&&(p+="Passive"),n[p]=n[p]||[],n[p].push(i)},Yne=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Xne(n){const e={},t={},r=new Set;for(let s in n)Yne.test(s)?(r.add(RegExp.lastMatch),t[s]=n[s]):e[s]=n[s];return[t,e,r]}function sd(n,e,t,r,s,i){if(!n.has(t)||!LI.has(r))return;const o=t+"Start",a=t+"End",l=c=>{let d;return c.first&&o in e&&e[o](c),t in e&&(d=e[t](c)),c.last&&a in e&&e[a](c),d};s[r]=l,i[r]=i[r]||{}}function Zne(n,e){const[t,r,s]=Xne(n),i={};return sd(s,t,"onDrag","drag",i,e),sd(s,t,"onWheel","wheel",i,e),sd(s,t,"onScroll","scroll",i,e),sd(s,t,"onPinch","pinch",i,e),sd(s,t,"onMove","move",i,e),sd(s,t,"onHover","hover",i,e),{handlers:i,config:e,nativeHandlers:r}}function Jne(n,e={},t,r){const s=He.useMemo(()=>new qne(n),[]);if(s.applyHandlers(n,r),s.applyConfig(e,t),He.useEffect(s.effect.bind(s)),He.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Qne(n){return n.forEach(Fne),function(t,r){const{handlers:s,nativeHandlers:i,config:o}=Zne(t,r||{});return Jne(s,o,void 0,i)}}const Tj=10,ere=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function ez(n){let{deltaY:e,deltaX:t}=n,r=0;return n.ctrlKey||n.altKey||n.metaKey?r=(Math.abs(e)>Tj?Tj*Math.sign(e):e)/100:n.shiftKey&&!ere&&(t=e,e=0),{x:-t,y:-e,z:-r}}const tre=Qne([$ne,zne]);let id;const nre=n=>id===void 0?(id=n,!1):n-id>120&&n-id<160?(id=n,!0):(id=n,!1);function rre(n){const e=te(),t=P.useMemo(()=>{let r="not sure";const s=({event:v})=>{if(!e.getInstanceState().isFocused||(r="not sure",nre(Date.now())))return;const x=e.getEditingShapeId();if(x){const I=e.getShape(x);if(I&&e.getShapeUtil(I).canScroll(I)){const T=e.getShapePageBounds(x);if(T!=null&&T.containsPoint(e.inputs.currentPagePoint))return}}tt(v),Xt(v);const b=ez(v);if(b.x===0&&b.y===0)return;const C={type:"wheel",name:"wheel",delta:b,point:new E(v.clientX,v.clientY),shiftKey:v.shiftKey,altKey:v.altKey,ctrlKey:v.metaKey||v.ctrlKey,metaKey:v.metaKey,accelKey:Cr(v)};e.dispatch(C)};let i=1,o=1,a=1,l=0;const c=new E,d=new E,f=v=>{const x=n.current;r="not sure";const{event:b,origin:C,da:I}=v;b instanceof WheelEvent||(b.target===x||x!=null&&x.contains(b.target))&&(d.x=C[0],d.y=C[1],c.x=C[0],c.y=C[1],i=I[0],o=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:C[0],y:C[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Cr(b)}))},p=v=>{if(v&&(r="zooming"),r==="zooming")return;const x=Math.abs(l-i),b=E.Dist(c,d);switch(r){case"not sure":{x>24?r="zooming":b>16&&(r="panning");break}case"panning":{x>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:f,onPinchEnd:v=>{const x=n.current,{event:b,origin:C,offset:I}=v;if(b instanceof WheelEvent||!(b.target===x||x!=null&&x.contains(b.target)))return;const _=I[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:C[0],y:C[1],z:_},delta:{x:C[0],y:C[1]},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Cr(b)})})},onPinch:v=>{const x=n.current,{event:b,origin:C,offset:I,da:_}=v;if(b instanceof WheelEvent||!(b.target===x||x!=null&&x.contains(b.target)))return;const T=v.type==="gesturechange"||v.type==="gestureend";l=_[0];const A=C[0]-d.x,R=C[1]-d.y;switch(d.x=C[0],d.y=C[1],p(T),r){case"zooming":{a=I[0],e.dispatch({type:"pinch",name:"pinch",point:{x:C[0],y:C[1],z:a},delta:{x:A,y:R},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Cr(b)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:C[0],y:C[1],z:o},delta:{x:A,y:R},shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:Cr(b)});break}}}}},[e,n]);tre(t,{target:n,eventOptions:{passive:!1},pinch:{from:()=>[e.getZoomLevel(),0],scaleBounds:()=>{const r=e.getBaseZoom(),s=e.getCameraOptions().zoomSteps,i=s[0]*r,o=s[s.length-1]*r;return{from:e.getZoomLevel(),max:o,min:i}}}})}function aC(n,e,t){const r=n.getShape(e),s=n.getShapeHandles(r);return{shape:r,handle:s.find(i=>i.id===t)}}function sre(n,e){const t=te();return P.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=pS(l.currentTarget);Rp(c,l);const{shape:d,handle:f}=aC(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:d,name:"pointer_down",...Fs(l)})};let s,i;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===s&&l.clientY===i)return;s=l.clientX,i=l.clientY;const{shape:c,handle:d}=aC(t,n,e);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:c,name:"pointer_move",...Fs(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=pS(l.currentTarget);Dp(c,l);const{shape:d,handle:f}=aC(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:d,name:"pointer_up",...Fs(l)})}}},[t,n,e])}function ire(n){const e=te();P.useLayoutEffect(()=>{const t=WL(()=>{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()}),i=n.current;let o=null;return i&&(s.observe(i),o=ore(i),o.addEventListener("scroll",t)),()=>{clearInterval(r),window.removeEventListener("resize",t),s.disconnect(),o==null||o.removeEventListener("scroll",t),t.cancel()}},[e,n])}/*!
183
+ * Author: excalidraw
184
+ * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
185
+ * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
186
+ */const ore=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 ye{constructor(e=0,t=0,r=0,s=0){O(this,"x",0);O(this,"y",0);O(this,"w",0);O(this,"h",0);this.x=e,this.y=t,this.w=r,this.h=s}get point(){return new E(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 E(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 E(this.minX,this.minY),new E(this.maxX,this.minY),new E(this.maxX,this.maxY),new E(this.minX,this.maxY)]}get cornersAndCenter(){return[new E(this.minX,this.minY),new E(this.maxX,this.minY),new E(this.maxX,this.maxY),new E(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 E(this.w,this.h)}toFixed(){return this.x=am(this.x),this.y=am(this.y),this.w=am(this.w),this.h=am(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),i=Math.max(this.maxY,e.maxY);return this.x=t,this.y=r,this.w=s-t,this.h=i-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 ye(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,i=Math.round(this.maxY/e)*e;this.minX=t,this.minY=r,this.width=Math.max(1,s-t),this.height=Math.max(1,i-r)}collides(e){return ye.Collides(this,e)}contains(e){return ye.Contains(this,e)}includes(e){return ye.Includes(this,e)}containsPoint(e,t=0){return ye.ContainsPoint(this,e,t)}getHandlePoint(e){switch(e){case"top_left":return new E(this.minX,this.minY);case"top_right":return new E(this.maxX,this.minY);case"bottom_left":return new E(this.minX,this.maxY);case"bottom_right":return new E(this.maxX,this.maxY);case"top":return new E(this.midX,this.minY);case"right":return new E(this.maxX,this.midY);case"bottom":return new E(this.midX,this.maxY);case"left":return new E(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:i,maxX:o,maxY:a}=this;let{minX:l,minY:c,maxX:d,maxY:f}=this;switch(e){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{d+=t;break}}switch(e){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{f+=r;break}}const p=(d-l)/(o-s),m=(f-c)/(a-i),y=p<0,v=m<0;if(y){const x=d;d=l,l=x}if(v){const x=f;f=c,c=x}this.minX=l,this.minY=c,this.width=Math.abs(d-l),this.height=Math.abs(f-c)}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),i=Math.max(this.maxY,e.h+e.y);return this.x=t,this.y=r,this.width=s-t,this.height=i-r,this}static From(e){return new ye(e.x,e.y,e.w,e.h)}static FromCenter(e,t){return new ye(e.x-t.x/2,e.y-t.y/2,t.x,t.y)}static FromPoints(e){if(e.length===0)return new ye;let t=1/0,r=1/0,s=-1/0,i=-1/0,o;for(let a=0,l=e.length;a<l;a++)o=e[a],t=Math.min(o.x,t),r=Math.min(o.y,r),s=Math.max(o.x,s),i=Math.max(o.y,i);return new ye(t,r,s-t,i-r)}static Expand(e,t){const r=Math.min(t.minX,e.minX),s=Math.min(t.minY,e.minY),i=Math.max(t.maxX,e.maxX),o=Math.max(t.maxY,e.maxY);return new ye(r,s,i-r,o-s)}static ExpandBy(e,t){return new ye(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 ye.Collides(e,t)||ye.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,i=-1/0;for(let o=0;o<e.length;o++){const a=e[o];t=Math.min(t,a.minX),r=Math.min(r,a.minY),s=Math.max(s,a.maxX),i=Math.max(i,a.maxY)}return new ye(t,r,s-t,i-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,i=!1){const{minX:o,minY:a,maxX:l,maxY:c}=e;let{minX:d,minY:f,maxX:p,maxY:m}=e;switch(t){case"left":case"top_left":case"bottom_left":{d+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(t){case"top":case"top_left":case"top_right":{f+=s;break}case"bottom":case"bottom_left":case"bottom_right":{m+=s;break}}const y=(p-d)/(l-o),v=(m-f)/(c-a),x=y<0,b=v<0;if(i){const I=(l-o)/(c-a),_=Math.abs(p-d),T=Math.abs(m-f),A=_*(v<0?1:-1)*(1/I),R=T*(y<0?1:-1)*I,j=I<_/T;switch(t){case"top_left":{j?f=m+A:d=p+R;break}case"top_right":{j?f=m+A:p=d-R;break}case"bottom_right":{j?m=f-A:p=d-R;break}case"bottom_left":{j?m=f-A:d=p+R;break}case"bottom":case"top":{const K=(d+p)/2,U=T*I;d=K-U/2,p=K+U/2;break}case"left":case"right":{const K=(f+m)/2,U=_/I;f=K-U/2,m=K+U/2;break}}}if(x){const I=p;p=d,d=I}if(b){const I=m;m=f,f=I}const C=new ye(d,f,Math.abs(p-d),Math.abs(m-f));return{box:C,scaleX:+(C.width/e.width*(y>0?1:-1)).toFixed(5),scaleY:+(C.height/e.height*(v>0?1:-1)).toFixed(5)}}equals(e){return ye.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 ye(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function are(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 lre(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 cre(n){return n==="top_left"||n==="top_right"||n==="bottom_right"||n==="bottom_left"}class ve{constructor(e,t,r,s,i,o){O(this,"a",1);O(this,"b",0);O(this,"c",0);O(this,"d",1);O(this,"e",0);O(this,"f",0);this.a=e,this.b=t,this.c=r,this.d=s,this.e=i,this.f=o}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:i,d:o,e:a,f:l}=this;return this.a=r*t.a+i*t.b,this.c=r*t.c+i*t.d,this.e=r*t.e+i*t.f+a,this.b=s*t.a+o*t.b,this.d=s*t.c+o*t.d,this.f=s*t.e+o*t.f+l,this}rotate(e,t,r){return e===0?this:t===void 0?this.multiply(ve.Rotate(e)):this.translate(t,r).multiply(ve.Rotate(e)).translate(-t,-r)}translate(e,t){return this.multiply(ve.Translate(e,t))}scale(e,t){return this.multiply(ve.Scale(e,t))}invert(){const{a:e,b:t,c:r,d:s,e:i,f:o}=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*i-r*o)/-a,this.f=(t*i-e*o)/a,this}applyToPoint(e){return ve.applyToPoint(this,e)}applyToPoints(e){return ve.applyToPoints(this,e)}rotation(){return ve.Rotation(this)}point(){return ve.Point(this)}decomposed(){return ve.Decompose(this)}toCssString(){return ve.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return ve.Decompose(this)}clone(){return new ve(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new ve(1,0,0,1,0,0)}static Translate(e,t){return new ve(1,0,0,1,e,t)}static Rotate(e,t,r){if(e===0)return ve.Identity();const s=Math.cos(e),i=Math.sin(e),o=new ve(s,i,-i,s,0,0);return t===void 0?o:ve.Compose(ve.Translate(t,r),o,ve.Translate(-t,-r))}static Scale(e,t,r,s){const i=new ve(e,0,0,t,0,0);return r===void 0?i:ve.Compose(ve.Translate(r,s),i,ve.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=ve.Identity();for(let r=0,s=e.length;r<s;r++)t.multiply(e[r]);return t}static Point(e){return new E(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=Ht+Math.acos(e.b/r)*(e.d>0?-1:1)}else t=0;return IP(t)}static Decompose(e){let t,r,s;if(e.a!==0||e.c!==0){const i=(e.a*e.a+e.c*e.c)**.5;t=i,r=(e.a*e.d-e.b*e.c)/i,s=Math.acos(e.a/i)*(e.c>0?-1:1)}else if(e.b!==0||e.d!==0){const i=(e.b*e.b+e.d*e.d)**.5;t=(e.a*e.d-e.b*e.c)/i,r=i,s=Ht+Math.acos(e.b/i)*(e.d>0?-1:1)}else t=0,r=0,s=0;return{x:e.e,y:e.f,scaleX:t,scaleY:r,rotation:IP(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 E(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 E(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 ye(e.e+t.minX,e.f+t.minY,t.width,t.height)}static From(e){return new ve(e.a,e.b,e.c,e.d,e.e,e.f)}static Cast(e){return e instanceof ve?e:ve.From(e)}}class Jl{constructor(e){O(this,"isFilled",!1);O(this,"isClosed",!0);O(this,"isLabel",!1);O(this,"debugColor");O(this,"ignore");O(this,"_vertices");O(this,"_bounds");O(this,"_area");O(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)&&$s(e,this.vertices)?!0:E.Dist2(e,this.nearestPoint(e))<=t*t}distanceToPoint(e,t=!1){return e.dist(this.nearestPoint(e))*(this.isClosed&&(this.isFilled||t)&&$s(e,this.vertices)?-1:1)}distanceToLineSegment(e,t){if(e.equals(t))return this.distanceToPoint(e);const{vertices:r}=this;let s,i=1/0,o,a,l;for(let c=0;c<r.length;c++)a=r[c],l=E.NearestPointOnLineSegment(e,t,a,!0),o=E.Dist2(a,l),o<i&&(i=o,s=l);if(!s)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&$s(s,this.vertices)?-i:i}hitTestLineSegment(e,t,r=0){return this.distanceToLineSegment(e,t)<=r}nearestPointOnLineSegment(e,t){const{vertices:r}=this;let s,i=1/0,o,a,l;for(let c=0;c<r.length;c++)a=r[c],l=E.NearestPointOnLineSegment(e,t,a,!0),o=E.Dist2(a,l),o<i&&(i=o,s=l);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 ye.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 i=e[r],o=e[(r+1)%s];t+=i.x*o.y-o.x*i.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 i=1;i<e.length;i++)t=e[i],s+=E.Dist2(r,t),r=t;return Math.sqrt(s)}}class bi extends Jl{constructor(t){super({...t,isClosed:!0,isFilled:!1});O(this,"children",[]);O(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:i}=this;if(i.length===0)throw Error("no children");let o,a;for(const l of i)o=l.nearestPoint(t),a=E.Dist2(o,t),a<r&&(r=a,s=o);if(!s)throw Error("nearest point not found");return s}distanceToPoint(t,r=!1){return Math.min(...this.children.map((s,i)=>s.distanceToPoint(t,r||i>0)))}hitTestPoint(t,r,s){return!!this.children.filter(i=>!i.isLabel).find(i=>i.hitTestPoint(t,r,s))}hitTestLineSegment(t,r,s){return!!this.children.filter(i=>!i.isLabel).find(i=>i.hitTestLineSegment(t,r,s))}getArea(){return this.children[0].area}toSimpleSvgPath(){let t="";for(const s of this.children)t+=s.toSimpleSvgPath();const r=ye.FromPoints(this.vertices).corners;for(let s=0,i=r.length;s<i;s++){const o=r[s],a=r[(s-1+i)%i],l=o.dist(a),c=r[(s+1)%i],d=o.dist(c),f=o.clone().lrp(a,4/l),p=o,m=o.clone().lrp(c,4/d);t+=`M${f.x},${f.y} L${p.x},${p.y} L${m.x},${m.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 ure(n=!0){const[e,t]=P.useState(0),r=te();P.useEffect(()=>{if(!n)return;const s=()=>t(i=>i+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const dre=Vn(function({showStroke:e=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const s=te();ure(r);const i=s.getZoomLevel(),o=s.getRenderingShapes(),{inputs:{currentPagePoint:a}}=s;return g.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:o.map(l=>{const c=s.getShape(l.id);if(c.type==="group")return null;const d=s.getShapeGeometry(c),f=s.getShapePageTransform(c),p=s.getPointInShapeSpace(c,a),m=d.nearestPoint(p),y=d.distanceToPoint(p,!0),v=Math.abs(y)*i,x=y<0,{vertices:b}=d;return g.jsxs("g",{transform:f.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&g.jsx("g",{stroke:d.debugColor??"red",opacity:"1",strokeWidth:2/i,fill:"none",children:g.jsx(tz,{geometry:d})}),t&&b.map((C,I)=>g.jsx("circle",{cx:C.x,cy:C.y,r:2/i,fill:`hsl(${Dd(I,[0,b.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/i},`v${I}`)),r&&v<150&&g.jsx("line",{x1:m.x,y1:m.y,x2:p.x,y2:p.y,opacity:1-v/150,stroke:x?"goldenrod":"dodgerblue",strokeWidth:2/i})]},l.id+"_outline")})})});function tz({geometry:n}){return n instanceof bi?g.jsx(g.Fragment,{children:[...n.children,...n.ignoredChildren].map((e,t)=>g.jsx(tz,{geometry:e},t))}):g.jsx("path",{d:n.toSimpleSvgPath()})}function nz(n){return bV(n)}function rz(){const n=te(),e=OG("userIds",()=>nz(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 ie(e)}function Hv(n){const e=te();return ie(`latestPresence:${n}`,()=>e.getCollaborators().find(r=>r.userId===n),[e,n])??null}const hre=Vn(function(){return rz().map(t=>g.jsx(fre,{collaboratorId:t},t))}),fre=Vn(function({collaboratorId:e}){const t=te(),r=Hv(e),s=gre(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(s){case"inactive":{const{followingUserId:i,highlightedUserIds:o}=t.getInstanceState();if(!(i===r.userId||o.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:i}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||i.includes(r.userId)))return null;break}}return g.jsx(pre,{latestPresence:r})}),pre=Vn(function({latestPresence:e}){const t=te(),{CollaboratorBrush:r,CollaboratorScribble:s,CollaboratorCursor:i,CollaboratorHint:o,CollaboratorShapeIndicator:a}=Zt(),l=t.getZoomLevel(),c=t.getViewportPageBounds(),{userId:d,chatMessage:f,brush:p,scribbles:m,selectedShapeIds:y,userName:v,cursor:x,color:b}=e;if(!x)return null;const C=!(x.x<c.minX-12/l||x.y<c.minY-16/l||x.x>c.maxX-12/l||x.y>c.maxY-16/l);return g.jsxs(g.Fragment,{children:[p&&r?g.jsx(r,{className:"tl-collaborator__brush",userId:d,brush:p,color:b,opacity:.1},d+"_brush"):null,C&&i?g.jsx(i,{className:"tl-collaborator__cursor",userId:d,point:x,color:b,zoom:l,name:v!=="New User"?v:null,chatMessage:f??""},d+"_cursor"):o?g.jsx(o,{className:"tl-collaborator__cursor-hint",userId:d,point:x,color:b,zoom:l,viewport:c},d+"_cursor_hint"):null,s&&m.length?g.jsx(g.Fragment,{children:m.map(I=>g.jsx(s,{className:"tl-collaborator__scribble",userId:d,scribble:I,color:b,zoom:l,opacity:I.color==="laser"?.5:.1},d+"_scribble_"+I.id))}):null,a&&y.filter(I=>!t.isShapeHidden(I)).map(I=>g.jsx(a,{className:"tl-collaborator__shape-indicator",userId:d,shapeId:I,color:b,opacity:.5},d+"_"+I))]})});function Mj(n,e){return e>n.options.collaboratorInactiveTimeoutMs?"inactive":e>n.options.collaboratorIdleTimeoutMs?"idle":"active"}function gre(n,e){const t=P.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,s]=P.useState(()=>Mj(n,Date.now()-t.current));return P.useEffect(()=>{const i=n.timers.setInterval(()=>{s(Mj(n,Date.now()-t.current))},n.options.collaboratorCheckIntervalMs);return()=>clearInterval(i)},[n]),e&&(t.current=e.lastActivityTimestamp??1/0),r}function mre(){const n=te(),e=ie("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),[t,r]=P.useState(!1),s=e||t,i=NI(),o=P.useRef({isDown:!1,isDragging:!1,start:new E}),a=P.useCallback(d=>{d.button===0&&(r(!0),o.current={isDown:!0,isDragging:!1,start:new E(d.clientX,d.clientY)}),n.menus.clearOpenMenus()},[n]),l=P.useCallback(d=>{var f,p,m;if(o.current.isDown){if(o.current.isDragging){(f=i.onPointerMove)==null||f.call(i,d);return}if(E.Dist2(o.current.start,new E(d.clientX,d.clientY))>n.options.dragDistanceSquared){o.current={...o.current,isDown:!0,isDragging:!0};const{x:y,y:v}=o.current.start;(p=i.onPointerDown)==null||p.call(i,{...d,clientX:y,clientY:v,button:0}),(m=i.onPointerMove)==null||m.call(i,d)}}},[i,n]),c=P.useCallback(d=>{var f;(f=i.onPointerUp)==null||f.call(i,d),r(!1),o.current={isDown:!1,isDragging:!1,start:new E(d.clientX,d.clientY)}},[i]);return s&&g.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...i,onPointerDown:a,onPointerMove:l,onPointerUp:c})}const sz=P.memo(function({id:e,shape:t,util:r,index:s,backgroundIndex:i,opacity:o}){const a=te(),{ShapeErrorFallback:l}=Zt(),c=P.useRef(null),d=P.useRef(null);P.useEffect(()=>qi("load fonts",()=>{const y=a.fonts.getShapeFontFaces(t);a.fonts.requestFonts(y)}),[a,t]);const f=P.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Ca("set shape stuff",()=>{const y=a.getShape(e);if(!y)return;const v=f.current,x=a.getShapeClipPath(e)??"none";x!==v.clipPath&&(mr(c.current,"clip-path",x),mr(d.current,"clip-path",x),v.clipPath=x);const b=a.getShapePageTransform(e),C=ve.toCssString(b),I=a.getShapeGeometry(y).bounds;C!==v.transform&&(mr(c.current,"transform",C),mr(d.current,"transform",C),v.transform=C);const _=Math.max(I.width,1),T=Math.max(I.height,1);(_!==v.width||T!==v.height)&&(mr(c.current,"width",_+"px"),mr(c.current,"height",T+"px"),mr(d.current,"width",_+"px"),mr(d.current,"height",T+"px"),v.width=_,v.height=T)},[a]),Ca("set opacity and z-index",()=>{const y=c.current,v=d.current;mr(y,"opacity",o),mr(v,"opacity",o),mr(y,"z-index",s),mr(v,"z-index",i)},[o,s,i]),Ca("set display",()=>{if(!a.getShape(e))return;const x=a.getCulledShapes().has(e);x!==f.current.isCulled&&(mr(c.current,"display",x?"none":"block"),mr(d.current,"display",x?"none":"block"),f.current.isCulled=x)},[a]);const p=P.useCallback(y=>a.annotateError(y,{origin:"shape",willCrashApp:!1}),[a]);if(!t)return null;const m="fill"in t.props&&t.props.fill!=="none";return g.jsxs(g.Fragment,{children:[r.backgroundComponent&&g.jsx("div",{ref:d,className:"tl-shape tl-shape-background","data-shape-type":t.type,"data-shape-id":t.id,draggable:!1,children:g.jsx(ap,{fallback:l,onError:p,children:g.jsx(oz,{shape:t,util:r})})}),g.jsx("div",{ref:c,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":m,"data-shape-id":t.id,draggable:!1,children:g.jsx(ap,{fallback:l,onError:p,children:g.jsx(iz,{shape:t,util:r})})})]})}),iz=P.memo(function({shape:e,util:t}){return yv("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),oz=P.memo(function({shape:e,util:t}){return yv("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 yre({className:n}){const e=te(),{Background:t,SvgDefs:r,ShapeIndicators:s}=Zt(),i=P.useRef(null),o=P.useRef(null),a=P.useRef(null),l=In();ire(i),Jte(),Zte(),rre(i),ene(i);const c=P.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Ca("position layers",function(){const{x:C,y:I,z:_}=e.getCamera();if(c.current.allowTextOutline&&Pt.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&_<e.options.textShadowLod!==c.current.lodDisableTextOutline){const R=_<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",R?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=R}const T=_>=1?Dd(_,[1,8],[.125,.5],!0):Dd(_,[.1,1],[-2,.125],!0),A=`scale(${ee(_)}) translate(${ee(C+T)}px,${ee(I+T)}px)`;mr(o.current,"transform",A),mr(a.current,"transform",A)},[e,l]);const d=NI(),f=ie("shapeSvgDefs",()=>{const b=new Map;for(const C of fn(e.shapeUtils)){if(!C)return;const I=C.getCanvasSvgDefs();for(const{key:_,component:T}of I)b.has(_)||b.set(_,g.jsx(T,{},_))}return[...b.values()]},[e]),p=ie("debug_shapes",()=>xn.hideShapes.get(),[xn]),m=ie("debug_svg",()=>xn.debugSvg.get(),[xn]),y=ie("debug_geometry",()=>xn.debugGeometry.get(),[xn]),v=ie("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),x=ie("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return g.jsxs(g.Fragment,{children:[g.jsxs("div",{ref:i,draggable:!1,"data-iseditinganything":v,"data-isselectinganything":x,className:ze("tl-canvas",n),"data-testid":"canvas",...d,children:[g.jsx("svg",{className:"tl-svg-context",children:g.jsxs("defs",{children:[f,g.jsx(Are,{}),g.jsx(Ore,{}),r&&g.jsx(r,{})]})}),t&&g.jsx("div",{className:"tl-background__wrapper",children:g.jsx(t,{})}),g.jsx(vre,{}),g.jsxs("div",{ref:o,className:"tl-html-layer tl-shapes",draggable:!1,children:[g.jsx(Nre,{}),g.jsx(jre,{}),p?null:m?g.jsx(Ire,{}):g.jsx(Tre,{})]}),g.jsx("div",{className:"tl-overlays",children:g.jsxs("div",{ref:a,className:"tl-html-layer",children:[y?g.jsx(dre,{}):null,g.jsx(wre,{}),g.jsx(xre,{}),g.jsx(bre,{}),s&&g.jsx(s,{}),g.jsx(Mre,{}),g.jsx(Cre,{}),g.jsx(Dre,{}),g.jsx(Pre,{}),g.jsx(hre,{})]})}),g.jsx(Lre,{})]}),g.jsx(mre,{}),g.jsx(Sre,{})]})}function Sre(){const{InFrontOfTheCanvas:n}=Zt();return n?g.jsx(n,{}):null}function vre(){const n=te(),e=ie("gridSize",()=>n.getDocumentSettings().gridSize,[n]),{x:t,y:r,z:s}=ie("camera",()=>n.getCamera(),[n]),i=ie("isGridMode",()=>n.getInstanceState().isGridMode,[n]),{Grid:o}=Zt();return o&&i?g.jsx(o,{x:t,y:r,z:s,size:e}):null}function xre(){const n=te(),e=ie("scribbles",()=>n.getInstanceState().scribbles,[n]),t=ie("zoomLevel",()=>n.getZoomLevel(),[n]),{Scribble:r}=Zt();return r&&e.length?e.map(s=>g.jsx(r,{className:"tl-user-scribble",scribble:s,zoom:t},s.id)):null}function wre(){const n=te(),e=ie("brush",()=>n.getInstanceState().brush,[n]),{Brush:t}=Zt();return t&&e?g.jsx(t,{className:"tl-user-brush",brush:e}):null}function bre(){const n=te(),e=ie("zoomBrush",()=>n.getInstanceState().zoomBrush,[n]),{ZoomBrush:t}=Zt();return t&&e?g.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function Cre(){const n=te(),e=ie("snapLines",()=>n.snaps.getIndicators(),[n]),t=ie("zoomLevel",()=>n.getZoomLevel(),[n]),{SnapIndicator:r}=Zt();return r&&e.length>0?e.map(s=>g.jsx(r,{className:"tl-user-snapline",line:s,zoom:t},s.id)):null}function Pre(){const n=te(),e=ie("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?g.jsx(Ere,{shapeId:e}):null}function Ere({shapeId:n}){const e=te(),{Handles:t}=Zt(),r=ie("zoomLevel",()=>e.getZoomLevel(),[e]),s=ie("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),i=ie("handles transform",()=>e.getShapePageTransform(n),[e,n]),o=ie("handles",()=>{const l=e.getShapeHandles(n);if(!l)return null;const c=(s?e.options.coarseHandleRadius:e.options.handleRadius)/r*2;return l.filter(d=>d.type!=="virtual"||!l.some(f=>f!==d&&f.type==="vertex"&&E.Dist(d,f)<c)).sort(d=>d.type==="vertex"?1:-1)},[e,r,s,n]),a=ie("isHidden",()=>e.isShapeHidden(n),[e,n]);return!t||!o||!i||a?null:g.jsx(t,{children:g.jsx("g",{transform:ve.toCssString(i),children:o.map(l=>g.jsx(kre,{shapeId:n,handle:l,zoom:r,isCoarse:s},l.id))})})}function kre({shapeId:n,handle:e,zoom:t,isCoarse:r}){const s=sre(n,e.id),{Handle:i}=Zt();return i?g.jsx("g",{"aria-label":"handle",transform:`translate(${e.x}, ${e.y})`,...s,children:g.jsx(i,{shapeId:n,handle:e,zoom:t,isCoarse:r})}):null}function Ire(){const n=te();return ie("rendering shapes",()=>n.getRenderingShapes(),[n]).map(t=>g.jsxs(P.Fragment,{children:[g.jsx(sz,{...t}),g.jsx(Rre,{id:t.id,mode:"iframe"})]},t.id+"_fragment"))}function _re(){const n=te(),e=P.useRef(new Set);return Ca("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 Tre(){const n=te(),e=ie("rendering shapes",()=>n.getRenderingShapes(),[n]);return g.jsxs(g.Fragment,{children:[e.map(t=>g.jsx(sz,{...t},t.id+"_shape")),Pt.isSafari&&g.jsx(_re,{})]})}function Mre(){const n=te(),{ShapeIndicator:e}=Zt(),t=ie("hinting shape ids",()=>pk(n.getHintingShapeIds()),[n]);return!t.length||!e?null:t.map(r=>g.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function Are(){return g.jsxs("g",{id:Yi("cursor"),children:[g.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[g.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),g.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),g.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[g.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),g.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),g.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[g.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),g.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function Ore(){const n=Yi("cursor_hint");return g.jsx("path",{id:n,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function Rre({id:n,mode:e}){const t=te(),[r,s]=P.useState(null),i=ie("is in root",()=>{const o=t.getShape(n);return(o==null?void 0:o.parentId)===t.getCurrentPageId()},[t,n]);return P.useEffect(()=>{if(!i)return;let o=null;const a=qi("shape to svg",async()=>{const l=Math.random();o=l;const d=t.isShapeOfType(n,"frame")?0:10;let f=t.getShapePageBounds(n);if(!f)return;f=f.clone().expandBy(d);const p=await t.getSvgString([n],{padding:d});if(o!==l||!p)return;const m=`data:image/svg+xml;utf8,${encodeURIComponent(p.svg)}`;s({src:m,bounds:f})});return()=>{o=null,a()}},[t,n,i]),!i||!r?null:e==="iframe"?g.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"}}):g.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 Dre(){const n=te(),e=ie("selection rotation",()=>n.getSelectionRotation(),[n]),t=ie("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionForeground:r}=Zt();return!t||!r?null:g.jsx(r,{bounds:t,rotation:e})}function jre(){const n=te(),e=ie("selection rotation",()=>n.getSelectionRotation(),[n]),t=ie("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionBackground:r}=Zt();return!t||!r?null:g.jsx(r,{bounds:t,rotation:e})}function Nre(){const{OnTheCanvas:n}=Zt();return n?g.jsx(n,{}):null}function Lre(){const n=te(),e=ie("camera state",()=>n.getCameraState(),[n]);return g.jsx("div",{className:ze("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function Fre({className:n,zoom:e,point:t,color:r,viewport:s,opacity:i=1}){const o=P.useRef(null);sh(o,Mn(t.x,s.minX+5/e,s.maxX-5/e),Mn(t.y,s.minY+5/e,s.maxY-5/e),1/e,E.Angle(s.center,t));const a=Yi("cursor_hint");return g.jsxs("svg",{ref:o,className:ze("tl-overlays__item",n),children:[g.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--color-background)"}),g.jsx("use",{href:`#${a}`,color:r,opacity:i})]})}const Aj=P.memo(function({className:e,zoom:t,point:r,color:s,name:i,chatMessage:o}){const a=P.useRef(null);sh(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t);const l=Yi("cursor");return r?g.jsxs("div",{ref:a,className:ze("tl-overlays__item",e),children:[g.jsx("svg",{className:"tl-cursor",children:g.jsx("use",{href:`#${l}`,color:s})}),o?g.jsxs(g.Fragment,{children:[i&&g.jsx("div",{className:"tl-nametag-title",style:{color:s},children:i}),g.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:s},children:o})]}):i&&g.jsx("div",{className:"tl-nametag",style:{backgroundColor:s},children:i})]}):null});function zre({x:n,y:e,z:t,size:r}){const s=pu("grid"),i=te(),{gridSteps:o}=i.options;return g.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[g.jsx("defs",{children:o.map(({min:a,mid:l,step:c},d)=>{const f=c*r*t,p=.5+n*t,m=.5+e*t,y=p>0?p%f:f+p%f,v=m>0?m%f:f+m%f,x=t<l?Dd(t,[a,l],[0,1]):1;return g.jsx("pattern",{id:OI(s,`${c}`),width:f,height:f,patternUnits:"userSpaceOnUse",children:g.jsx("circle",{className:"tl-grid-dot",cx:y,cy:v,r:1,opacity:x})},d)})}),o.map(({step:a},l)=>g.jsx("rect",{width:"100%",height:"100%",fill:`url(#${s}_${a})`},l))]})}function $re({handle:n,isCoarse:e,className:t,zoom:r}){const s=te(),i=(e?s.options.coarseHandleRadius:s.options.handleRadius)/r;if(n.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,c=Kte.indexOf(n.id);return g.jsxs("g",{className:ze(`tl-handle tl-handle__${n.type}`,t),children:[g.jsx("circle",{className:"tl-handle__bg",r:i}),g.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*c})`})]})}const o=(n.type==="create"&&e?3:4)/Math.max(r,.25);return g.jsxs("g",{className:ze(`tl-handle tl-handle__${n.type}`,t),children:[g.jsx("circle",{className:"tl-handle__bg",r:i}),g.jsx("circle",{className:"tl-handle__fg",r:o})]})}const Bre=({children:n})=>g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}),Ure=()=>{const{Spinner:n}=Zt();return g.jsx($ae,{children:n?g.jsx(n,{}):null})};function FI(n,e=!0){const t=n.length;if(t<2)return"";let r=n[0],s=n[1];if(t===2)return`M${Ct(r)}L${Ct(s)}`;let i="";for(let o=2,a=t-1;o<a;o++)r=n[o],s=n[o+1],i+=gs(r,s);return e?`M${gs(n[0],n[1])}Q${Ct(n[1])}${gs(n[1],n[2])}T${i}${gs(n[t-1],n[0])}${gs(n[0],n[1])}Z`:`M${Ct(n[0])}Q${Ct(n[1])}${gs(n[1],n[2])}${n.length>3?"T":""}${i}L${Ct(n[t-1])}`}function Oj({scribble:n,zoom:e,color:t,opacity:r,className:s}){return n.points.length?g.jsx("svg",{className:s&&ze("tl-overlays__item",s),children:g.jsx("path",{className:"tl-scribble",d:FI(n.points,!1),stroke:t??`var(--color-${n.color})`,fill:"none",strokeWidth:8/e,opacity:r??n.opacity})}):null}function az({bounds:n,rotation:e}){const t=P.useRef(null);return sh(t,n.x,n.y,1,e),P.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]),g.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function Hre({bounds:n,rotation:e}){const t=te(),r=P.useRef(null),s=ie("only selected shape",()=>t.getOnlySelectedShape(),[t]),i=s?t.getShapeUtil(s).expandSelectionOutlinePx(s):0;return sh(r,n==null?void 0:n.x,n==null?void 0:n.y,1,e,{x:-i,y:-i}),n=i instanceof ye?n.clone().expand(i).zeroFix():n.clone().expandBy(i).zeroFix(),g.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:g.jsx("rect",{className:ze("tl-selection__fg__outline"),width:ee(n.width),height:ee(n.height)})})}const Kre=()=>g.jsx("div",{className:"tl-shape-error-boundary"}),Wre=({shape:n,util:e})=>yv("Indicator: "+n.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(n.id))),Vre=({editor:n,id:e})=>{const t=ie("shape for indicator",()=>n.store.get(e),[n,e]),{ShapeIndicatorErrorFallback:r}=Zt();return!t||t.isLocked?null:g.jsx(ap,{fallback:r,onError:s=>n.annotateError(s,{origin:"react.shapeIndicator",willCrashApp:!1}),children:g.jsx(Wre,{shape:t,util:n.getShapeUtil(t)},t.id)})},Rj=P.memo(function({shapeId:e,className:t,color:r,hidden:s,opacity:i}){const o=te(),a=P.useRef(null);return Ca("indicator transform",()=>{const l=a.current;if(!l)return;const c=o.getShapePageTransform(e);c&&l.style.setProperty("transform",c.toCssString())},[o,e]),P.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",s?"none":"block")},[s]),g.jsx("svg",{ref:a,className:ze("tl-overlays__item",t),children:g.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:i,children:g.jsx(Vre,{editor:o,id:e})})})}),qre=()=>g.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),lz=P.memo(function(){const e=te(),t=P.useRef(new Set),r=ie("should display selected ids",()=>{const o=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 l=e.getSelectedShapeIds();for(const c of l)a.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const d=e.getHoveredShapeId();d&&a.add(d)}}}if(o.size!==a.size)return t.current=a,a;for(const l of a)if(!o.has(l))return t.current=a,a;return o},[e]),s=ie("rendering shapes",()=>e.getRenderingShapes(),[e]),{ShapeIndicator:i}=Zt();return i?s.map(({id:o})=>g.jsx(i,{shapeId:o,hidden:!r.has(o)},o+"_indicator")):null});function Gre({points:n,zoom:e}){const t=2.5/e,r=n.reduce((p,m)=>Math.min(p,m.x),1/0),s=n.reduce((p,m)=>Math.max(p,m.x),-1/0),i=n.reduce((p,m)=>Math.min(p,m.y),1/0),o=n.reduce((p,m)=>Math.max(p,m.y),-1/0),a=n.some(p=>p.x===r&&p.y===i);let l,c,d,f;return a?(l=r,c=i,d=s,f=o):(l=r,c=o,d=s,f=i),g.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[g.jsx("line",{x1:l,y1:c,x2:d,y2:f}),n.map((p,m)=>g.jsx("g",{transform:`translate(${p.x},${p.y})`,children:g.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},m))]})}function Yre({gaps:n,direction:e,zoom:t}){const r=3.5/t;let s=[-1/0,1/0],i=null;const o=e==="horizontal";for(const l of n){if(i=zi(s[0],s[1],o?l.startEdge[0].y:l.startEdge[0].x,o?l.startEdge[1].y:l.startEdge[1].x),i)s=i;else continue;if(i=zi(s[0],s[1],o?l.endEdge[0].y:l.endEdge[0].x,o?l.endEdge[1].y:l.endEdge[1].x),i)s=i;else continue}if(s===null)return null;const a=(s[0]+s[1])/2;return g.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:n.map(({startEdge:l,endEdge:c},d)=>g.jsx(P.Fragment,{children:o?g.jsxs(g.Fragment,{children:[g.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),g.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),g.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),g.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):g.jsxs(g.Fragment,{children:[g.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),g.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),g.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),g.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},d))})}function Xre({className:n,line:e,zoom:t}){return g.jsx("svg",{className:ze("tl-overlays__item",n),children:e.type==="points"?g.jsx(Gre,{...e,zoom:t}):e.type==="gaps"?g.jsx(Yre,{...e,zoom:t}):null})}function Zre(){return g.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:g.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[g.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),g.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:g.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const Jre=()=>null;function cz(n,e){const t=P.useRef(n);return e(n,t.current)?t.current:(t.current=n,n)}const Qre=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:jy(n,e));function Pl(n){return cz(n,Qre)}const ese=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:QL(n,e));function ih(n){return cz(n,ese)}const uz=P.createContext(null);function tse({overrides:n={},children:e}){const t=ih(n),r=P.useMemo(()=>({Background:Hte,SvgDefs:Jre,Brush:rC,ZoomBrush:rC,CollaboratorBrush:rC,Cursor:Aj,CollaboratorCursor:Aj,CollaboratorHint:Fre,CollaboratorShapeIndicator:Rj,Grid:zre,Scribble:Oj,SnapIndicator:Xre,Handles:Bre,Handle:$re,CollaboratorScribble:Oj,ErrorFallback:hz,ShapeErrorFallback:Kre,ShapeIndicatorErrorFallback:qre,Spinner:Zre,SelectionBackground:az,SelectionForeground:Hre,ShapeIndicators:lz,ShapeIndicator:Rj,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:yre,LoadingScreen:Ure,...t}),[t]);return g.jsx(uz.Provider,{value:r,children:e})}function Zt(){const n=P.useContext(uz);if(!n)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return n}const Kv={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 dz(){Kv.hardReset()}function nse(){Kv.refreshPage()}const rse="https://github.com/tldraw/tldraw/issues/new",hz=({error:n,editor:e})=>{const t=P.useRef(null),[r,s]=P.useState(!1),[i,o]=P.useState(!1),[a,l]=P.useState(!1);let c=null;try{c=Zt().Canvas??null}catch{}const d=n instanceof Error?n.message:String(n),f=n instanceof Error?n.stack:null,p=ie("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[m,y]=P.useState(null);P.useLayoutEffect(()=>{var T;p!==null&&y(p);let I=(T=t.current)==null?void 0:T.parentElement,_=!1;for(;I;){if(I.classList.contains("tl-theme__dark")||I.classList.contains("tl-theme__light")){_=!0;break}I=I.parentElement}if(_){y(null);return}typeof window<"u"&&"matchMedia"in window&&y(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),P.useEffect(()=>{if(i){const I=e==null?void 0:e.timers.setTimeout(()=>{o(!1)},2e3);return()=>clearTimeout(I)}},[i,e]);const v=()=>{const I=document.createElement("textarea");I.value=f??d,document.body.appendChild(I),I.select(),document.execCommand("copy"),I.remove(),o(!0)},x=()=>{nse()},b=async()=>{dz()},C=new URL(rse);return C.searchParams.set("title",d),C.searchParams.set("labels","bug"),C.searchParams.set("body",`Hey, I ran into an error while using tldraw:
187
+
188
+ \`\`\`js
189
+ ${f??d}
190
+ \`\`\`
191
+
192
+ My browser: ${navigator.userAgent}`),g.jsxs("div",{ref:t,className:ze("tl-container tl-error-boundary",m===null?"":m?"tl-theme__dark":"tl-theme__light"),children:[g.jsx("div",{className:"tl-error-boundary__overlay"}),e&&g.jsx(AI,{onError:Vf,fallback:()=>null,children:g.jsx(DI,{editor:e,children:g.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?g.jsx(c,{}):null})})}),g.jsx("div",{className:ze("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?g.jsxs(g.Fragment,{children:[g.jsx("h2",{children:"Are you sure?"}),g.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),g.jsxs("div",{className:"tl-error-boundary__content__actions",children:[g.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),g.jsx("button",{className:"tl-error-boundary__reset",onClick:b,children:"Reset data"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("h2",{children:"Something went wrong"}),g.jsx("p",{children:"Please refresh the page to continue."}),g.jsxs("p",{children:["If you keep seeing this screen, you can create a"," ",g.jsx("a",{href:C.toString(),children:"GitHub issue"})," or ask for help on"," ",g.jsx("a",{href:"https://discord.tldraw.com/?utm_source=sdk&utm_medium=organic&utm_campaign=error-screen",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&&g.jsxs(g.Fragment,{children:["Message:",g.jsx("h4",{children:g.jsx("code",{children:d})}),"Stack trace:",g.jsxs("div",{className:"tl-error-boundary__content__error",children:[g.jsx("pre",{children:g.jsx("code",{children:f??d})}),g.jsx("button",{onClick:v,children:i?"Copied!":"Copy"})]})]}),g.jsxs("div",{className:"tl-error-boundary__content__actions",children:[g.jsx("button",{onClick:()=>s(!r),children:r?"Hide details":"Show details"}),g.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[g.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),g.jsx("button",{className:"tl-error-boundary__refresh",onClick:x,children:"Refresh Page"})]})]})]})})]})},fz="TLDRAW_USER_DATA_v3",pz=ht({id:ot,name:ot.nullable().optional(),color:ot.nullable().optional(),locale:ot.nullable().optional(),animationSpeed:Ze.nullable().optional(),edgeScrollSpeed:Ze.nullable().optional(),colorScheme:$v("light","dark","system").optional(),isSnapMode:gt.nullable().optional(),isWrapMode:gt.nullable().optional(),isDynamicSizeMode:gt.nullable().optional(),isPasteAtCursorMode:gt.nullable().optional()}),fa={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},zI=Math.max(...Object.values(fa));function sse(n){n.version<fa.AddAnimationSpeed&&(n.user.animationSpeed=1),n.version<fa.AddIsSnapMode&&(n.user.isSnapMode=!1),n.version<fa.MakeFieldsNullable,n.version<fa.AddEdgeScrollSpeed&&(n.user.edgeScrollSpeed=1),n.version<fa.AddExcalidrawSelectMode&&(n.user.isWrapMode=!1),n.version<fa.AllowSystemColorScheme&&(n.user.isDarkMode===!0?n.user.colorScheme="dark":n.user.isDarkMode===!1&&(n.user.colorScheme="light"),delete n.user.isDarkMode),n.version<fa.AddDynamicSizeMode&&(n.user.isDynamicSizeMode=!1),n.version<fa.AddPasteAtCursor&&(n.user.isPasteAtCursorMode=!1),n.version=zI}const lE=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function gz(){return lE[Math.floor(Math.random()*lE.length)]}function ise(){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 bo=Object.freeze({name:"New User",locale:Nte(),color:gz(),edgeScrollSpeed:1,animationSpeed:ise()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"light"});function lC(){return{id:_t(),color:gz()}}function mz(n){if(n===null||typeof n!="object"||!("version"in n)||!("user"in n)||typeof n.version!="number")return lC();const e=Yt(n);sse(e);try{return pz.validate(e.user)}catch{return lC()}}function ose(){const n=JSON.parse(xk(fz)||"null")??null;return mz(n)}const Wv=on("globalUserData",null);function ase(){wk(fz,JSON.stringify({version:zI,user:Wv.get()}))}function yz(n){pz.validate(n),Wv.set(n),ase(),lse()}const _d=typeof BroadcastChannel<"u"?new BroadcastChannel("tldraw-user-sync"):null;_d==null||_d.addEventListener("message",n=>{const e=n.data;(e==null?void 0:e.type)===vz&&(e==null?void 0:e.origin)!==Sz()&&Wv.set(mz(e.data))});let cC=null;function Sz(){return cC===null&&(cC=_t()),cC}const vz="tldraw-user-preferences-change";function lse(){_d==null||_d.postMessage({type:vz,origin:Sz(),data:{user:xz(),version:zI}})}function xz(){let n=Wv.get();return n||(n=ose(),yz(n)),n}const cse=le("defaultLocalStorageUserPrefs",()=>xz());function wz(n={}){return{userPreferences:n.userPreferences??cse,setUserPreferences:n.setUserPreferences??yz}}var uC={exports:{}},Dj;function use(){return Dj||(Dj=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(l,c,d){this.fn=l,this.context=c,this.once=d||!1}function i(l,c,d,f,p){if(typeof d!="function")throw new TypeError("The listener must be a function");var m=new s(d,f||l,p),y=t?t+c:c;return l._events[y]?l._events[y].fn?l._events[y]=[l._events[y],m]:l._events[y].push(m):(l._events[y]=m,l._eventsCount++),l}function o(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],d,f;if(this._eventsCount===0)return c;for(f in d=this._events)e.call(d,f)&&c.push(t?f.slice(1):f);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(d)):c},a.prototype.listeners=function(c){var d=t?t+c:c,f=this._events[d];if(!f)return[];if(f.fn)return[f.fn];for(var p=0,m=f.length,y=new Array(m);p<m;p++)y[p]=f[p].fn;return y},a.prototype.listenerCount=function(c){var d=t?t+c:c,f=this._events[d];return f?f.fn?1:f.length:0},a.prototype.emit=function(c,d,f,p,m,y){var v=t?t+c:c;if(!this._events[v])return!1;var x=this._events[v],b=arguments.length,C,I;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),b){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,d),!0;case 3:return x.fn.call(x.context,d,f),!0;case 4:return x.fn.call(x.context,d,f,p),!0;case 5:return x.fn.call(x.context,d,f,p,m),!0;case 6:return x.fn.call(x.context,d,f,p,m,y),!0}for(I=1,C=new Array(b-1);I<b;I++)C[I-1]=arguments[I];x.fn.apply(x.context,C)}else{var _=x.length,T;for(I=0;I<_;I++)switch(x[I].once&&this.removeListener(c,x[I].fn,void 0,!0),b){case 1:x[I].fn.call(x[I].context);break;case 2:x[I].fn.call(x[I].context,d);break;case 3:x[I].fn.call(x[I].context,d,f);break;case 4:x[I].fn.call(x[I].context,d,f,p);break;default:if(!C)for(T=1,C=new Array(b-1);T<b;T++)C[T-1]=arguments[T];x[I].fn.apply(x[I].context,C)}}return!0},a.prototype.on=function(c,d,f){return i(this,c,d,f,!1)},a.prototype.once=function(c,d,f){return i(this,c,d,f,!0)},a.prototype.removeListener=function(c,d,f,p){var m=t?t+c:c;if(!this._events[m])return this;if(!d)return o(this,m),this;var y=this._events[m];if(y.fn)y.fn===d&&(!p||y.once)&&(!f||y.context===f)&&o(this,m);else{for(var v=0,x=[],b=y.length;v<b;v++)(y[v].fn!==d||p&&!y[v].once||f&&y[v].context!==f)&&x.push(y[v]);x.length?this._events[m]=x.length===1?x[0]:x:o(this,m)}return this},a.prototype.removeAllListeners=function(c){var d;return c?(d=t?t+c:c,this._events[d]&&o(this,d)):(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}(uC)),uC.exports}var dse=use();const hse=ja(dse),Td="TLDRAW_TAB_ID_v2",Ia=globalThis.window;function fse(){return Ia?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(Ia.navigator.platform)||Pt.isDarwin&&"ontouchend"in document:!1}const mS=Ia?Ia[Td]??h3(Td)??"TLDRAW_INSTANCE_STATE_V1_"+_t():"<error>";Ia&&(Ia[Td]=mS,fse()?bk(Td,mS):f3(Td));Ia==null||Ia.addEventListener("beforeunload",()=>{bk(Td,mS)});const bz={Initial:0},Vv=Math.max(...Object.values(bz));function pse(n){n.version<bz.Initial,n.version=Vv}const Cz=ht({version:Ze,currentPageId:ip.optional(),isFocusMode:gt.optional(),exportBackground:gt.optional(),isDebugMode:gt.optional(),isToolLocked:gt.optional(),isGridMode:gt.optional(),pageStates:zn(ht({pageId:ip,camera:ht({x:Ze,y:Ze,z:Ze}).optional(),selectedShapeIds:zn(di).optional(),focusedGroupId:di.nullable().optional()})).optional()});function gse(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!==Vv&&(n=Yt(n),pse(n));try{return Cz.validate(n)}catch(e){return console.warn(e),null}}function $I(n){const e=n.query.ids("page");return le("sessionStateSnapshot",()=>{const t=n.get(Lr);if(!t)return null;const r=[...e.get()];return{version:Vv,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(s=>{const i=n.get(Ki.createId(s)),o=n.get(Ao.createId(s));return{pageId:s,camera:{x:(o==null?void 0:o.x)??0,y:(o==null?void 0:o.y)??0,z:(o==null?void 0:o.z)??1},selectedShapeIds:(i==null?void 0:i.selectedShapeIds)??[],focusedGroupId:(i==null?void 0:i.focusedGroupId)??null}})}},{isEqual:Op})}function cE(n,e,t){const r=gse(e);if(!r)return;const s=p4(n.get(Lr)),i=t!=null&&t.forceOverwrite?r:s,o=t!=null&&t.forceOverwrite?s:r,a=n.schema.types.instance.create({id:Lr,...s,currentPageId:r.currentPageId,isDebugMode:(i==null?void 0:i.isDebugMode)??(o==null?void 0:o.isDebugMode),isFocusMode:(i==null?void 0:i.isFocusMode)??(o==null?void 0:o.isFocusMode),isToolLocked:(i==null?void 0:i.isToolLocked)??(o==null?void 0:o.isToolLocked),isGridMode:(i==null?void 0:i.isGridMode)??(o==null?void 0:o.isGridMode),exportBackground:(i==null?void 0:i.exportBackground)??(o==null?void 0:o.exportBackground)});n.atomic(()=>{var l,c,d;for(const f of r.pageStates??[]){if(!n.has(f.pageId))continue;const p=Ao.createId(f.pageId),m=Ki.createId(f.pageId),y=n.get(p),v=n.get(m);n.put([Ao.create({id:p,x:((l=f.camera)==null?void 0:l.x)??(y==null?void 0:y.x),y:((c=f.camera)==null?void 0:c.y)??(y==null?void 0:y.y),z:((d=f.camera)==null?void 0:d.z)??(y==null?void 0:y.z)}),Ki.create({id:m,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 mse(n){var s;const e=[];for(const i of Object.values(n))(s=i.typeName)!=null&&s.match(/^(instance.*|pointer|camera)$/)&&e.push(i);const t=e.filter(i=>i.typeName==="instance"&&i.id!==Lr)[0];if(!t)return null;const r={version:Vv,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:e.filter(i=>i.typeName==="instance_page_state"&&i.instanceId===t.id).map(i=>{const o=n[i.cameraId]??{x:0,y:0,z:1};return{pageId:i.pageId,camera:{x:o.x,y:o.y,z:o.z},selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId}})};try{return Cz.validate(r),r}catch{return null}}function Pz(n,e,t){let r={};if("store"in e){const o=n.schema.migrateStoreSnapshot(e);if(o.type!=="success")throw new Error("Failed to migrate store snapshot: "+o.reason);r.document={schema:n.schema.serialize(),store:If(o.value,(a,{typeName:l})=>n.scopedTypes.document.has(l))}}else r=e;const s=p4(n.get(Lr)),i=Ez.get(n,$I).get();n.atomic(()=>{r.document&&n.loadStoreSnapshot(r.document),s&&n.update(Lr,o=>({...o,...s})),i&&cE(n,i),r.session&&cE(n,r.session,{forceOverwrite:t==null?void 0:t.forceOverwriteSessionState})})}const Ez=new Na;function yse(n){const t=Ez.get(n,$I).get();if(!t)throw new Error("Session state is not ready yet");return{document:n.getStoreSnapshot(),session:t}}function kz(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 $l({children:n,className:e="",...t}){return g.jsx("svg",{...t,className:ze("tl-svg-container",e),children:n})}function BI(n,e,t,r){const s=n.x-t.x,i=n.y-t.y,o=r.x-t.x,a=r.y-t.y,l=e.x-n.x,c=e.y-n.y,d=o*i-a*s,f=l*i-c*s,p=a*l-o*c;if(d===0||f===0||p===0)return null;if(p!==0){const m=d/p,y=f/p;if(0<=m&&m<=1&&0<=y&&y<=1)return E.AddXY(n,m*l,m*c)}return null}function Lp(n,e,t,r){const s=(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y),i=2*((e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y)),o=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=i*i-4*s*o;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-i+l)/(2*s),d=(-i-l)/(2*s);if((c<0||c>1)&&(d<0||d>1))return null;const f=[];return 0<=c&&c<=1&&f.push(E.Lrp(n,e,c)),0<=d&&d<=1&&f.push(E.Lrp(n,e,d)),f.length===0?null:f}function Sse(n,e,t){const r=[];let s;for(let i=0,o=t.length-1;i<o;i++)s=BI(n,e,t[i],t[i+1]),s&&r.push(s);return r.length===0?null:r}function UI(n,e,t){const r=[];let s;for(let i=1,o=t.length;i<o+1;i++)s=BI(n,e,t[i-1],t[i%t.length]),s&&r.push(s);return r.length===0?null:r}function vse(n,e,t,r){let s=t.x-n.x,i=t.y-n.y;const o=Math.sqrt(s*s+i*i),a=(o*o-r*r+e*e)/(2*o),l=Math.sqrt(e*e-a*a);return s/=o,i/=o,[new E(n.x+s*a-i*l,n.y+i*a+s*l),new E(n.x+s*a+i*l,n.y+i*a-s*l)]}function uE(n,e,t){const r=[];let s,i,o;for(let a=0,l=t.length;a<l;a++)s=t[a],i=t[(a+1)%t.length],o=Lp(s,i,n,e),o&&r.push(...o);return r.length===0?null:r}function jj(n,e,t){const r=[];let s,i,o;for(let a=1,l=t.length;a<l;a++)s=t[a-1],i=t[a],o=Lp(s,i,n,e),o&&r.push(...o);return r.length===0?null:r}function xm(n,e,t){return(t.y-n.y)*(e.x-n.x)>(e.y-n.y)*(t.x-n.x)}function HI(n,e,t,r){return xm(n,t,r)!==xm(e,t,r)&&xm(n,e,t)!==xm(n,e,r)}function Nj(n,e){const t=new Map;let r,s,i,o;for(let a=0,l=n.length;a<l;a++)if(r=n[a],$s(r,e)){const c=dC(r);t.has(c)||t.set(c,r)}for(let a=0,l=e.length;a<l;a++)if(r=e[a],$s(r,n)){const c=dC(r);t.has(c)||t.set(c,r)}for(let a=0,l=n.length;a<l;a++){r=n[a],s=n[(a+1)%n.length];for(let c=0,d=e.length;c<d;c++){i=e[c],o=e[(c+1)%e.length];const f=BI(r,s,i,o);if(f!==null){const p=dC(f);t.has(p)||t.set(p,f)}}}return t.size===0?null:xse([...t.values()])}function dC(n){return`${n.x},${n.y}`}function xse(n){const e=E.Average(n);return n.sort((t,r)=>E.Angle(e,t)-E.Angle(e,r))}function KI(n,e){let t,r,s,i;for(let o=0,a=n.length;o<a;o++){t=n[o],r=n[(o+1)%a];for(let l=0,c=e.length;l<c;l++)if(s=e[l],i=e[(l+1)%c],HI(t,r,s,i))return!0}return!1}function wse(n,e){let t,r,s,i;for(let o=0,a=n.length;o<a;o++){t=n[o],r=n[(o+1)%a];for(let l=1,c=e.length;l<c;l++)if(s=e[l-1],i=e[l],HI(t,r,s,i))return!0}return!1}class wa extends Jl{constructor(t){super({...t,isClosed:!1,isFilled:!1});O(this,"start");O(this,"end");O(this,"d");O(this,"u");O(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:i,u:o,ul:a}=this;if(i.len()===0||a===0)return r;const l=E.Sub(t,r).dpr(o)/a,c=r.x+o.x*l;if(c<Math.min(r.x,s.x))return r.x<s.x?r:s;if(c>Math.max(r.x,s.x))return r.x>s.x?r:s;const d=r.y+o.y*l;return d<Math.min(r.y,s.y)?r.y<s.y?r:s:d>Math.max(r.y,s.y)?r.y>s.y?r:s:new E(c,d)}hitTestLineSegment(t,r,s=0){return HI(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 oh extends Jl{constructor(t){super({isClosed:!1,isFilled:!1,...t});O(this,"points");O(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 i=t[r],o=t[r+1];this._segments.push(new wa({start:i,end:o}))}this.isClosed&&this._segments.push(new wa({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],i=1/0,o,a;for(let l=0;l<r.length;l++)o=r[l].nearestPoint(t),a=E.Dist2(o,t),a<i&&(s=o,i=a);if(!s)throw Error("nearest point not found");return s}hitTestLineSegment(t,r,s=0){const{segments:i}=this;for(let o=0,a=i.length;o<a;o++)if(i[o].hitTestLineSegment(t,r,s))return!0;return!1}getSvgPathData(){const{vertices:t}=this;return t.length<2?"":t.reduce((r,s,i)=>i===0?`M ${s.x} ${s.y}`:`${r} L ${s.x} ${s.y}`,"")}}class vn extends oh{constructor(e){super({...e}),this.isClosed=!0}}class zo extends vn{constructor(t){const{x:r=0,y:s=0,width:i,height:o}=t;super({...t,points:[new E(r,s),new E(r+i,s),new E(r+i,s+o),new E(r,s+o)]});O(this,"x");O(this,"y");O(this,"w");O(this,"h");this.x=r,this.y=s,this.w=i,this.h=o}getBounds(){return new ye(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:s,h:i}=this;return`M${t},${r} h${s} v${i} h-${s}z`}}class Xi{constructor(e){O(this,"options",{});this.editor=e}static configure(e){return class extends this{constructor(){super(...arguments);O(this,"options",{...this.options,...e})}}}getFontFaces(e){return Si}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,t){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){}}O(Xi,"props"),O(Xi,"migrations"),O(Xi,"type");function Bi(n,e,t={}){const{closed:r=!1,snap:s=1,start:i="outset",end:o="outset",lengthRatio:a=2,style:l="dashed",forceSolid:c=!1}=t;let d=0,f=0,p=1,m=0,y=0;if(c)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(l){case"dashed":{p=1,d=Math.min(e*a,n/4);break}case"dotted":{p=100,d=e/p;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(i==="outset"?(n+=d/2,y+=d/2):i==="skip"&&(n-=d,y-=d),o==="outset"?n+=d/2:o==="skip"&&(n-=d)),f=Math.floor(n/d/(2*p)),f-=f%s,f<3&&l==="dashed"?n/e<4?(d=n,f=1,m=0):(d=n*(1/3),m=n*(1/3)):(d=n/f/(2*p),r?(y=d/2,m=(n-f*d)/f):m=(n-f*d)/Math.max(1,f-1)),{strokeDasharray:[d,m].join(" "),strokeDashoffset:y.toString()}}function Lj({bounds:n,className:e}){const t=te(),r=ie("zoom level",()=>t.getZoomLevel(),[t]);return g.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:n.sides.map((s,i)=>{const{strokeDasharray:o,strokeDashoffset:a}=Bi(s[0].dist(s[1]),1/r,{style:"dashed",lengthRatio:4});return g.jsx("line",{x1:s[0].x,y1:s[0].y,x2:s[1].x,y2:s[1].y,strokeDasharray:o,strokeDashoffset:a},i)})})}class sy extends Xi{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const t=this.editor.getSortedChildIdsForParent(e.id);return t.length===0?new zo({width:1,height:1,isFilled:!1}):new bi({children:t.map(r=>{const s=this.editor.getShape(r),i=this.editor.getShapeGeometry(r),o=this.editor.getShapeLocalTransform(s).applyToPoints(i.vertices);return i.isClosed?new vn({points:o,isFilled:!0}):new oh({points:o})})})}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")),i=this.editor.getCurrentPageState().focusedGroupId!==e.id;if(!t&&(i||s))return null;const o=this.editor.getShapeGeometry(e).bounds;return g.jsx($l,{children:g.jsx(Lj,{className:"tl-group",bounds:o})})}indicator(e){const t=this.editor.getShapeGeometry(e).bounds;return g.jsx(Lj,{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}}}O(sy,"type","group"),O(sy,"props",k4),O(sy,"migrations",I4);const Iz=[sy],bse=new Set(Iz.map(n=>n.type));function _z(n){const e=[...Iz],t=new Set;for(const r of n){if(bse.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 ah=HL();const Tz=ja(ah);function Mz(n,e){const t=new Map;return async function(s){const i=t.get(s);if(i)return i;const o=(async()=>{try{const a=await Vi(s,e);return nt(a.ok),await n(a)}catch(a){return console.error(a),null}})();return t.set(s,o),o}}const qv=Mz(async n=>await zr.blobToDataUrl(await n.blob())),Cse=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,Pse=/@font-face\s*{([^}]+)}/gi,Az=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,Ese=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function kse(n){return Array.from(n.matchAll(Cse),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Oz(n,e){return Array.from(n.matchAll(Pse),t=>{const r=t[1],s=Array.from(r.matchAll(Az),o=>{var l;const a=o[1]||o[2]||o[3];return{original:a,resolved:((l=Je(a,e))==null?void 0:l.href)??null}}),i=new Set(Array.from(r.matchAll(Ese),o=>(o[1]||o[2]||o[3]).toLowerCase()));return{fontFace:r,urls:s,fontFamilies:i}})}function Ise(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 i=s[1]||s[2]||s[3];if(r.add(i.toLowerCase()),t.lastIndex=e.lastIndex,!t.exec(n))break;e.lastIndex=t.lastIndex}return r}function Rz(n){return!(n.startsWith("-")||n.startsWith("animation")||n.startsWith("transition")||n==="cursor"||n==="pointer-events"||n==="user-select"||n==="touch-action")}function _se(n,e){return{imports:kse(n),fontFaces:Oz(n,e)}}function Tse(n){return Array.from(n.matchAll(Az),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const Mse=new Set(["border-block-end-color","border-block-start-color","border-bottom-color","border-inline-end-color","border-inline-start-color","border-left-color","border-right-color","border-top-color","caret-color","column-rule-color","outline-color","text-decoration","text-decoration-color","text-emphasis-color"]);function Dz(n,e,t){if(Mse.has(e))return t==="currentColor"||t===n||e==="text-decoration"&&t===`none solid ${n}`}const Ase=new Set(["border-collapse","border-spacing","caption-side","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","overflow-wrap","quotes","stroke-linecap","stroke-linejoin","tab-size","text-align","text-align-last","text-indent","text-justify","text-shadow","text-transform","visibility","white-space","white-space-collapse","widows","word-break","word-spacing","word-wrap"]);function jz(n){return Ase.has(n)}var Ose=Object.create,Nz=Object.defineProperty,Rse=Object.getOwnPropertyDescriptor,Dse=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Lz=n=>{throw TypeError(n)},Fz=(n,e,t)=>e in n?Nz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,jse=n=>[,,,Ose(null)],zz=["class","method","getter","setter","accessor","field","value","get","set"],$z=n=>n!==void 0&&typeof n!="function"?Lz("Function expected"):n,Nse=(n,e,t,r,s)=>({kind:zz[n],name:e,metadata:r,addInitializer:i=>t._?Lz("Already initialized"):s.push($z(i||null))}),Lse=(n,e)=>Fz(e,Dse("metadata"),n[3]),Fse=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},zse=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=zz[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Rse(s,t)),b=r.length-1;b>=0;b--)l=Nse(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,$z(o)&&(x[y]=o);return x&&Nz(s,t,x),s},wm=(n,e,t)=>Fz(n,typeof e!="symbol"?e+"":e,t),Bz,Gv;const Uz="tldraw-svg-export";Bz=[vs];class WI{constructor(){Fse(Gv,5,this),wm(this,"fontFacesPromise",null),wm(this,"foundFontNames",new Set),wm(this,"fontFacesToEmbed",new Set),wm(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){nt(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=$se()}onFontFamilyValue(e){nt(this.fontFacesPromise,"FontEmbedder not started");const t=Ise(e);for(const r of t){if(this.foundFontNames.has(r))return;this.foundFontNames.add(r),this.pendingPromises.push(this.fontFacesPromise.then(s=>{const i=s.filter(o=>o.fontFamilies.has(r));for(const o of i)if(!this.fontFacesToEmbed.has(o)){this.fontFacesToEmbed.add(o);for(const a of o.urls)!a.resolved||a.embedded||(a.embedded=qv(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 i=await s.embedded;i&&(r=r.replace(s.original,i))}e+=r}return e}}Gv=jse();zse(Gv,1,"onFontFamilyValue",Bz,WI);Lse(Gv,WI);async function $se(){var t;const n=[],e=Array.from(document.styleSheets).filter(r=>{var s;return!((s=r.ownerNode)!=null&&s.closest(`.${Uz}`))});for(const r of e){let s;try{s=r.cssRules}catch{}if(s){for(const i of r.cssRules)if(i instanceof CSSFontFaceRule)n.push(Oz(i.cssText,r.href??document.baseURI));else if(i instanceof CSSImportRule){const o=new URL(i.href,((t=i.parentStyleSheet)==null?void 0:t.href)??document.baseURI);n.push(dE(o.href))}}else r.href&&n.push(dE(r.href))}return st(await Promise.all(n)).flat()}const dE=Mz(async n=>{const e=_se(await n.text(),n.url),t=await Promise.all(e.imports.map(({url:r})=>dE(new URL(r,n.url).href)));return[...e.fontFaces,...st(t).flat()]});function Hz(n){if(n.shadowRoot)return n.shadowRoot.childNodes;if(Kse(n)){const e=n.assignedNodes();if(e!=null&&e.length)return e}return n.childNodes}function*hE(n){for(const e of Hz(n))Bse(e)&&(yield e)}function Yv(n){var e;return((e=n.ownerDocument)==null?void 0:e.defaultView)??globalThis}function Bse(n){return n instanceof Yv(n).Element}function Use(n){return n instanceof Yv(n).ShadowRoot}function Hse(n){return"getRootNode"in n&&Use(n.getRootNode())}function Kse(n){return Hse(n)&&n instanceof Yv(n).HTMLSlotElement}function Wse(n){return n.style}function VI(n,e){return Yv(n).getComputedStyle(n,e)}const Kd={};class Vse{constructor(e){O(this,"styles",new Map);O(this,"fonts",new WI);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const t=Array.from(hE(e));for(;t.length;){const r=t.pop();t.push(...hE(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:t=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const s=t?Xse(e.tagName.toLowerCase()):Kd,i=Object.assign({},Kd);if(r){let l=e.parentElement;for(;l;){const c=(a=this.styles.get(l))==null?void 0:a.self;for(const d in c)i[d]||(i[d]=c[d]);l=l.parentElement}}const o={self:qse(e,{defaultStyles:s,parentStyles:i}),before:Fj(e,"::before"),after:Fj(e,"::after")};this.styles.set(e,o)}fetchResources(){const e=[];for(const t of this.styles.values())for(const r of fn(t))if(r)for(const[s,i]of Object.entries(r)){if(!i)continue;s==="font-family"&&this.fonts.onFontFamilyValue(i);const o=Tse(i);o.length!==0&&e.push(...o.map(async({url:a,original:l})=>{const c=await qv(a)??"data:";r[s]=i.replace(l,`url("${c}")`)}))}return Promise.all(e)}unwrapCustomElements(){const e=new Set,t=(r,s)=>{if(e.has(r))return;e.add(r);const i=r.shadowRoot;if(i){const o=document.createElement("div");this.styles.set(o,this.styles.get(r)),o.setAttribute("data-tl-custom-element",r.tagName),(s??r.parentElement).appendChild(o);for(const a of i.childNodes)a instanceof Element?t(a,o):o.appendChild(a.cloneNode(!0));r.remove()}else if(s){if(r.tagName.toLowerCase()==="style")return;const o=r.cloneNode(!1);this.styles.set(o,this.styles.get(r)),s.appendChild(o);for(const a of Hz(r))a instanceof Element?t(a,o):o.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 i=`pseudo-${_t()}`;t.classList.add(i),r.before&&(e+=`.${i}::before {${zj(r.before)}}
193
+ `),r.after&&(e+=`.${i}::after {${zj(r.after)}}
194
+ `)}const s=Wse(t);for(const[i,o]of Object.entries(r.self))o&&s.setProperty(i,o);s.fontKerning==="auto"&&(s.fontKerning="normal")}return e}async getFontFaceCss(){return await this.fonts.createCss()}dispose(){Yse()}}function qse(n,{defaultStyles:e,parentStyles:t}){return n.computedStyleMap?Kz(n.computedStyleMap(),{defaultStyles:e,parentStyles:t}):qI(VI(n),{defaultStyles:e,parentStyles:t})}function Fj(n,e){const t=VI(n,e),r=t.getPropertyValue("content");if(!(r===""||r==="none"))return qI(t,{defaultStyles:Kd,parentStyles:Kd})}function Kz(n,{defaultStyles:e,parentStyles:t}){var s;const r={};for(const i of n.keys()){if(!Rz(i))continue;const o=n.get(i).toString();e[i]!==o&&(t[i]===o&&jz(i)||Dz(((s=n.get("color"))==null?void 0:s.toString())||"",i,o)||(r[i]=o))}return r}function qI(n,{defaultStyles:e,parentStyles:t}){const r={};for(const s in n){if(!Rz(s))continue;const i=n.getPropertyValue(s);e[s]!==i&&(t[s]===i&&jz(s)||Dz(n.color,s,i)||(r[s]=i))}return r}function zj(n){let e="";for(const[t,r]of Object.entries(n))e+=`${t}: ${r};`;return e}let Md;const $j={};function Gse(){if(!Md){const n=document.createElement("iframe");n.style.display="none",document.body.appendChild(n);const e=Nr(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),Md={iframe:n,foreignObject:r,document:e}}return Md}function Yse(){Md&&(document.body.removeChild(Md.iframe),Md=void 0)}const Bj={defaultStyles:Kd,parentStyles:Kd};function Xse(n){let e=$j[n];if(!e){const{foreignObject:t,document:r}=Gse(),s=r.createElement(n);t.appendChild(s),e=s.computedStyleMap?Kz(s.computedStyleMap(),Bj):qI(VI(s),Bj),t.removeChild(s),$j[n]=e}return e}function Zse(n,e){Array.from(n.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function Uj(n,e){return n.replaceWith(e),e}async function Rf(n,e){const t=document.createElement("img");e&&Zse(e,t),t.setAttribute("src",n??"data:"),t.setAttribute("decoding","sync"),t.setAttribute("loading","eager");try{await t.decode()}catch{}return t}async function Jse(n){try{const e=n.toDataURL();return await Rf(e,n)}catch{return await Rf(null,n)}}async function Qse(n){try{const e=await Ls.getVideoFrameAsDataUrl(n);return Rf(e,n)}catch(e){console.error("Could not get video frame",e)}if(n.poster){const e=await qv(n.poster);return Rf(e,n)}return Rf(null,n)}async function Wz(n){if(n instanceof HTMLCanvasElement)return Uj(n,await Jse(n));if(n instanceof HTMLVideoElement)return Uj(n,await Qse(n));if(n instanceof HTMLImageElement){const e=n.currentSrc||n.src,t=await qv(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(hE(n),e=>Wz(e)))}function Xv(n){const e=P.useRef();return P.useLayoutEffect(()=>{e.current=n}),P.useDebugValue(n),P.useCallback((...t)=>{const r=e.current;return nt(r,"fn does not exist"),r(...t)},[])}const GI=P.createContext(null);function eie({context:n,editor:e,children:t}){const r=e.options.exportProvider;return g.jsx(DI,{editor:e,children:g.jsx(W4,{container:e.getContainer(),children:g.jsx(GI.Provider,{value:n,children:g.jsx(r,{children:t})})})})}function Fp(){return P.useContext(GI)}function tie(){const n=P.useContext(GI),[e]=P.useState(fk);return P.useEffect(()=>(n==null||n.waitUntil(e),()=>{e.resolve()}),[e,n]),Xv(()=>{e.resolve()})}var nie=Object.create,Vz=Object.defineProperty,rie=Object.getOwnPropertyDescriptor,sie=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),qz=n=>{throw TypeError(n)},Gz=(n,e,t)=>e in n?Vz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,iie=n=>[,,,nie(null)],Yz=["class","method","getter","setter","accessor","field","value","get","set"],Xz=n=>n!==void 0&&typeof n!="function"?qz("Function expected"):n,oie=(n,e,t,r,s)=>({kind:Yz[n],name:e,metadata:r,addInitializer:i=>t._?qz("Already initialized"):s.push(Xz(i||null))}),aie=(n,e)=>Gz(e,sie("metadata"),n[3]),lie=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},cie=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=Yz[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,rie(s,t)),b=r.length-1;b>=0;b--)l=oie(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,Xz(o)&&(x[y]=o);return x&&Vz(s,t,x),s},Hj=(n,e,t)=>Gz(n,typeof e!="symbol"?e+"":e,t),Zz,Zv;Zz=[vs];class YI{constructor(e){this.maxDelayTimeMs=e,lie(Zv,5,this),Hj(this,"isResolved",!1),Hj(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 while waiting for export:",t)))}async resolvePromises(){let e=null;for(;this.promisesToWaitFor.length!==e;)e=this.promisesToWaitFor.length,await Promise.allSettled(this.promisesToWaitFor),await wP(0)}async resolve(){const e=wP(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}}Zv=iie();cie(Zv,1,"waitUntil",Zz,YI);aie(Zv,YI);function uie(n,e,t={}){var b,C;if(!window.document)throw Error("No document");const{scale:r=1,background:s=n.getInstanceState().exportBackground,padding:i=n.options.defaultSvgPadding,preserveAspectRatio:o}=t,a=t.darkMode??n.user.getIsDarkMode(),l=n.getShapeAndDescendantIds(e),c=n.getUnorderedRenderingShapes(!1).filter(({id:I})=>l.has(I));let d=null;if(t.bounds)d=t.bounds;else for(const{id:I}of c){const _=n.getShapeMaskedPageBounds(I);_&&(d?d.union(_):d=_.clone())}if(!d)return;const f=e.length===1&&n.isShapeOfType(n.getShape(e[0]),"frame")?e[0]:null;f||d.expandBy(i);const p=d.width*r,m=d.height*r;try{(C=(b=document.body).focus)==null||C.call(b)}catch{}const y=new YI(n.options.maxExportDelayMs),v=fk();return y.waitUntil(v),{jsx:g.jsx(die,{editor:n,preserveAspectRatio:o,scale:r,pixelRatio:t.pixelRatio??null,bbox:d,background:s,singleFrameShapeId:f,isDarkMode:a,renderingShapes:c,onMount:v.resolve,waitUntil:y.waitUntil}),width:p,height:m,exportDelay:y}}function die({editor:n,preserveAspectRatio:e,scale:t,pixelRatio:r,bbox:s,background:i,singleFrameShapeId:o,isDarkMode:a,renderingShapes:l,onMount:c,waitUntil:d}){const f=pu(),p=za({isDarkMode:a}),m=Sv("export state",{defsById:{},shapeElements:null}),{defsById:y,shapeElements:v}=ie(m),x=Xv(I=>{m.update(_=>{if(yi(_.defsById,I.key))return _;const T=Promise.resolve(I.getElement());return d(T.then(A=>{m.update(R=>({...R,defsById:{...R.defsById,[I.key]:{pending:!1,element:A}}}))})),{..._,defsById:{..._.defsById,[I.key]:{pending:!0,element:T}}}})}),b=P.useMemo(()=>({isDarkMode:a,waitUntil:d,addExportDef:x,scale:t,pixelRatio:r,async resolveAssetUrl(I,_){const T=n.getAsset(I);return!T||T.type!=="image"&&T.type!=="video"?null:await n.resolveAssetUrl(I,{screenScale:t*(_/T.props.w),shouldResolveToOriginal:r===null,dpr:r??void 0})}}),[a,d,x,t,r,n]),C=P.useRef(!1);return P.useLayoutEffect(()=>{if(C.current)throw new Error("SvgExport should only render once - do not use with react strict mode");C.current=!0,(async()=>{const I={},_=l.map(async({id:A,opacity:R,index:j,backgroundIndex:K})=>{var N,L;if(A===o)return[];const U=n.getShape(A);if(n.isShapeOfType(U,"group"))return[];const J=[],z=n.getShapeUtil(U);if(z.toSvg||z.toBackgroundSvg){const[V,X]=await Promise.all([(N=z.toSvg)==null?void 0:N.call(z,U,b),(L=z.toBackgroundSvg)==null?void 0:L.call(z,U,b)]),W=n.getShapePageTransform(U);let $=W.toCssString(),G=1;"scale"in U.props&&U.props.scale!==1&&(G=U.props.scale,$=`${$} scale(${U.props.scale}, ${U.props.scale})`);const re=n.getShapeMask(U.id),H=re?ve.From(ve.Inverse(W)).applyToPoints(re):null,ne=OI(f,U.id);H&&(I[ne]={pending:!1,element:g.jsx("clipPath",{id:ne,children:g.jsx("path",{d:`M${H.map(({x:ge,y:Pe})=>`${ge/G},${Pe/G}`).join("L")}Z`})})}),V&&J.push({zIndex:j,element:g.jsx("g",{transform:$,opacity:R,clipPath:re?`url(#${ne})`:void 0,children:V},`fg_${U.id}`)}),X&&J.push({zIndex:K,element:g.jsx("g",{transform:$,opacity:R,clipPath:re?`url(#${ne})`:void 0,children:X},`bg_${U.id}`)})}else J.push({zIndex:j,element:g.jsx(Kj,{shape:U,util:z,component:iz,className:"tl-shape",bbox:s,opacity:R},`fg_${U.id}`)}),z.backgroundComponent&&J.push({zIndex:K,element:g.jsx(Kj,{shape:U,util:z,component:oz,className:"tl-shape tl-shape-background",bbox:s,opacity:R},`bg_${U.id}`)});return J}),T=(await Promise.all(_)).flat();ah.flushSync(()=>{m.update(A=>({...A,shapeElements:T.sort((R,j)=>R.zIndex-j.zIndex).map(({element:R})=>R),defsById:{...A.defsById,...I}}))})})()},[s,n,b,f,l,o,m]),P.useEffect(()=>{const I=new Set;for(const{id:_}of l)for(const T of n.fonts.getShapeFontFaces(_))I.add(T);for(const _ of I)x({key:_t(),getElement:async()=>{const T=await n.fonts.toEmbeddedCssDeclaration(_);return g.jsx("style",{children:T})}})},[n,l,x]),P.useEffect(()=>{v!==null&&c()},[c,v]),g.jsx(eie,{editor:n,context:b,children:g.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:i?o?p.solid:p.background:"transparent"},"data-color-mode":a?"dark":"light",className:`tl-container tl-theme__force-sRGB ${a?"tl-theme__dark":"tl-theme__light"}`,children:[g.jsx("defs",{children:Object.entries(y).map(([I,_])=>_.pending?null:g.jsx(P.Fragment,{children:_.element},I))}),v]})})}function Kj({shape:n,util:e,className:t,component:r,bbox:s,opacity:i}){const o=te(),a=ve.Translate(-s.minX,-s.minY).multiply(o.getShapePageTransform(n.id)),l=o.getShapeGeometry(n.id).bounds,c=Math.max(l.width,1),d=Math.max(l.height,1);return g.jsx(AI,{fallback:()=>null,children:g.jsx("foreignObject",{x:s.minX,y:s.minY,width:s.w,height:s.h,className:"tl-shape-foreign-object tl-export-embed-styles",children:g.jsx("div",{className:t,"data-shape-type":n.type,style:{clipPath:o.getShapeClipPath(n.id),transform:a.toCssString(),width:c,height:d,opacity:i},children:g.jsx(r,{shape:n,util:e})})})})}let hie=1;async function fie(n,e,t={}){const r=uie(n,e,t);if(!r)return;const s=n.getContainer(),i=document.createElement("div");i.className=Uz,i.inert=!0,i.tabIndex=-1,Object.assign(i.style,{position:"absolute",top:"0px",left:"0px",width:r.width+"px",height:r.height+"px",pointerEvents:"none",opacity:0}),s.appendChild(i);const o=KL.createRoot(i,{identifierPrefix:`export_${hie++}_`});try{await Promise.resolve(),ah.flushSync(()=>{o.render(r.jsx)}),await r.exportDelay.resolve();const a=i.firstElementChild;return nt(a instanceof SVGSVGElement,"Expected an SVG element"),await pie(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{o.unmount(),s.removeChild(i)},0)}}async function pie(n){const e=[...n.querySelectorAll("foreignObject.tl-export-embed-styles > *")];if(!e.length)return;const t=new Vse(n);try{t.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(i=>Wz(i)));for(const i of e)t.readRootElementStyles(i);await t.fetchResources();const r=await t.getFontFaceCss();t.unwrapCustomElements();const s=t.embedStyles();if(r||s){const i=document.createElementNS("http://www.w3.org/2000/svg","style");i.textContent=`${r}
195
+ ${s}`,n.prepend(i)}}finally{t.dispose()}}let hC=null;function gie(){return hC||(hC={maxWidth:fC("width"),maxHeight:fC("height"),maxArea:fC("area")}),hC}/*!
196
+ * Extracted from https://github.com/jhildenbiddle/canvas-size
197
+ * MIT License: https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE
198
+ * Copyright (c) John Hildenbiddle
199
+ */const Wj=8192,mie=4096*4096,yie={area:[16384,14188,11402,11180,10836,8192,4096],height:[8388607,65535,32767,16384,8192,4096],width:[4194303,65535,32767,16384,8192,4096]};function fC(n){const e=document.createElement("canvas");e.width=1,e.height=1;const t=e.getContext("2d");for(const r of yie[n]){const s=n==="height"?1:r,i=n==="width"?1:r,o=document.createElement("canvas");o.width=s,o.height=i,o.getContext("2d").fillRect(s-1,i-1,1,1),t.drawImage(o,s-1,i-1,1,1,0,0,1,1);const l=t.getImageData(0,0,1,1).data[3]!==0;if(o.width=0,o.height=0,l)return e.width=0,e.height=0,n==="area"?r*r:r}throw e.width=0,e.height=0,Error("Failed to determine maximum canvas dimension")}function Sie(n,e){if(n<=Wj&&e<=Wj&&n*e<=mie)return[n,e];const{maxWidth:t,maxHeight:r,maxArea:s}=gie(),i=n/e;if(n>t&&(n=t,e=n/i),e>r&&(e=r,n=e*i),n*e>s){const o=Math.sqrt(s/(n*e));n*=o,e*=o}return[n,e]}async function vie(n,e){const{type:t,width:r,height:s,quality:i=1,pixelRatio:o=2}=e;let[a,l]=Sie(r*o,s*o);a=Math.floor(a),l=Math.floor(l);const c=a/r,d=await zr.blobToDataUrl(new Blob([n],{type:"image/svg+xml"})),f=await new Promise(m=>{const y=qf();y.crossOrigin="anonymous",y.onload=async()=>{Pt.isSafari&&await wP(250);const v=document.createElement("canvas"),x=v.getContext("2d");v.width=a,v.height=l,x.imageSmoothingEnabled=!0,x.imageSmoothingQuality="high",x.drawImage(y,0,0,a,l),URL.revokeObjectURL(d),m(v)},y.onerror=()=>{m(null)},y.src=d});if(!f)return null;const p=await new Promise(m=>f.toBlob(y=>{(!y||xn.throwToBlob.get())&&m(null),m(y)},"image/"+t,i));if(!p)return null;if(t==="png"){const m=new DataView(await p.arrayBuffer());return Io.setPhysChunk(m,c,{type:"image/"+t})}else return p}const $i={menus:on("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()}}},yS=new lq,xie={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:P.Fragment,enableToolbarKeyboardShortcuts:!0,maxFontsToLoadBeforeRender:1/0};function Vj(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 En(n)}}class wie{constructor(e){O(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(!Vj(s,e.get(r)))return!1;t.add(r)}for(const[r,s]of e)if(!t.has(r)&&!Vj(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 fE extends wie{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:En(r,"type")}}}function bie(n,e,t){return Vi(n).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:t})})}const Cie="https://cdn.tldraw.com";function Pn(){return`${Cie}/${$4}`}function Pie(n){switch(n.type){case"shapes":return`s${n.shapeIds.map(t=>pC(t.slice(6))).join(".")}`;case"page":return"p"+pC(Vs.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+="."+pC(Vs.parseId(t))),r}default:En(n)}}function Eie(n){switch(n[0]){case"s":return{type:"shapes",shapeIds:n.slice(1).split(".").filter(Boolean).map(r=>Dt(decodeURIComponent(r)))};case"p":return{type:"page",pageId:Vs.createId(decodeURIComponent(n.slice(1)))};case"v":{const[t,r,s,i,o]=n.slice(1).split(".");return{type:"viewport",bounds:new ye(Number(t),Number(r),Number(s),Number(i)),pageId:o?Vs.createId(decodeURIComponent(o)):void 0}}default:throw Error("Invalid deep link string")}}function pC(n){return encodeURIComponent(n).replace(/\./g,"%2E")}function kie(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?)$/,i=>(+i+1).toString()):`${t} 1`;return t}function bm(n,e,t,r){if(t.length===0)return[];const s=new Map;for(const o of st(t.map(a=>n.getShape(a)))){const{parentId:a}=o;s.has(a)||s.set(a,{children:st(n.getSortedChildIdsForParent(a).map(l=>n.getShape(l))),moving:new Set}),s.get(a).moving.add(o)}const i=[];switch(e){case"toBack":{s.forEach(({moving:o,children:a})=>Iie(o,a,i));break}case"toFront":{s.forEach(({moving:o,children:a})=>_ie(o,a,i));break}case"forward":{s.forEach(({moving:o,children:a})=>Tie(n,o,a,i,r));break}case"backward":{s.forEach(({moving:o,children:a})=>Mie(n,o,a,i,r));break}}return i}function Iie(n,e,t){const r=e.length;if(n.size===r)return;let s,i;for(let o=0;o<r;o++){const a=e[o];if(n.has(a))s=a.index,n.delete(a);else{i=a.index;break}}if(n.size!==0){const o=jd(s,i,n.size);t.push(...Array.from(n.values()).sort(Qn).map((a,l)=>({...a,index:o[l]})))}}function _ie(n,e,t){const r=e.length;if(n.size===r)return;let s,i;for(let o=r-1;o>-1;o--){const a=e[o];if(n.has(a))i=a.index,n.delete(a);else{s=a.index;break}}if(n.size!==0){const o=jd(s,i,n.size);t.push(...Array.from(n.values()).sort(Qn).map((a,l)=>({...a,index:o[l]})))}}function qj(n,e){const t=n.getShapeGeometry(e),r=n.getShapePageTransform(e);return!t||!r?null:r.applyToPoints(t.vertices)}function Jz(n,e){const t=Array.from(e).map(s=>{const i=qj(n,s);return i?{shape:s,vertices:i}:null}).filter(Boolean);return s=>{const i=qj(n,s);return i?t.some(o=>KI(o.vertices,i)):!1}}function Tie(n,e,t,r,s){var l;const i=Jz(n,e),o=t.length;if(e.size===o)return;let a={name:"skipping"};for(let c=0;c<o;c++){const d=e.has(t[c]);switch(a.name){case"skipping":{if(!d)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(d||!(s!=null&&s.considerAllShapes)&&!i(t[c]))continue;const{selectIndex:f}=a;jd(t[c].index,(l=t[c+1])==null?void 0:l.index,c-f).forEach((p,m)=>{const y=t[f+m];e.has(y)&&r.push({...y,index:p})}),a={name:"skipping"};break}}}}function Mie(n,e,t,r,s){var l;const i=Jz(n,e),o=t.length;if(e.size===o)return;let a={name:"skipping"};for(let c=o-1;c>-1;c--){const d=e.has(t[c]);switch(a.name){case"skipping":{if(!d)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(d||!(s!=null&&s.considerAllShapes)&&!i(t[c]))continue;jd((l=t[c-1])==null?void 0:l.index,t[c].index,a.selectIndex-c).forEach((f,p)=>{const m=t[c+p+1];e.has(m)&&r.push({...m,index:f})}),a={name:"skipping"};break}}}}function Qz({editor:n,ids:e}){const t=st(e.map(o=>n.getShape(o))),r=n.getShapesSharedRotation(e),s=n.getShapesRotatedPageBounds(e);if(!s)return null;const i=s.center.clone().rotWith(s.point,r);return{pageCenter:i,initialCursorAngle:i.angle(n.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:t.map(o=>({shape:o,initialPagePoint:n.getShapePageTransform(o.id).point()}))}}function iy({delta:n,editor:e,snapshot:t,stage:r,centerOverride:s}){const{pageCenter:i,shapeSnapshots:o}=t;e.updateShapes(o.map(({shape:l,initialPagePoint:c})=>{const d=ps(l.parentId)?e.getShapePageTransform(l.parentId):ve.Identity(),f=E.RotWith(c,s??i,n),p=ve.applyToPoint(ve.Inverse(d),f),m=Fc(l.rotation+n);return{id:l.id,type:l.type,x:p.x,y:p.y,rotation:m}}));const a=[];o.forEach(({shape:l})=>{var p,m,y;const c=e.getShape(l.id);if(!c)return;const d=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const v=(p=d.onRotateStart)==null?void 0:p.call(d,l);v&&a.push(v)}const f=(m=d.onRotate)==null?void 0:m.call(d,l,c);if(f&&a.push(f),r==="end"||r==="one-off"){const v=(y=d.onRotateEnd)==null?void 0:y.call(d,l,c);v&&a.push(v)}}),a.length>0&&e.updateShapes(a)}const Aie=n=>{const{store:e}=n,t=e.query.filterHistory("binding"),r=e.query.records("binding");function s(){const i=r.get(),o=new Map;for(const a of i){const{fromId:l,toId:c}=a,d=o.get(l);d?d.push(a):o.set(l,[a]);const f=o.get(c);f?f.push(a):o.set(c,[a])}return o}return le("arrowBindingsIndex",(i,o)=>{if(Lc(i))return s();const a=i,l=t.getDiffSince(o);if(l===zs)return s();let c;function d(m){c??(c=new Map(a));const y=c.get(m.fromId),v=y==null?void 0:y.filter(C=>C.id!==m.id);v!=null&&v.length?c.set(m.fromId,v):c.delete(m.fromId);const x=c.get(m.toId),b=x==null?void 0:x.filter(C=>C.id!==m.id);b!=null&&b.length?c.set(m.toId,b):c.delete(m.toId)}function f(m){c??(c=new Map(a));let y=c.get(m);return y?y===a.get(m)&&(y=y.slice(0),c.set(m,y)):(y=[],c.set(m,y)),y}function p(m){f(m.fromId).push(m),f(m.toId).push(m)}for(const m of l){for(const y of fn(m.added))p(y);for(const[y,v]of fn(m.updated))d(y),p(v);for(const y of fn(m.removed))d(y)}return c??a})};function Oie(n,e,t){const r=n.getShapeMaskedPageBounds(e);return r===void 0?!0:!t.includes(r)}const Rie=n=>{function e(t){const r=t.getCurrentPageShapeIds(),s=t.getViewportPageBounds(),i=new Set;return r.forEach(o=>{Oie(t,o,s)&&i.add(o)}),i}return le("getCulledShapes",t=>{if(Lc(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})},Die=n=>{const e=n.query.ids("shape"),t=n.query.filterHistory("shape");function r(){const s={},i=e.get(),o=Array(i.size);return i.forEach(a=>o.push(n.get(a))),o.sort(Qn),o.forEach(a=>{s[a.parentId]||(s[a.parentId]=[]),s[a.parentId].push(a.id)}),s}return le("parentsToChildrenWithIndexes",(s,i)=>{if(Lc(s))return r();const o=t.getDiffSince(i);if(o===zs)return r();if(o.length===0)return s;let a=null;const l=f=>{a||(a={...s}),a[f]?a[f]===s[f]&&(a[f]=[...a[f]]):a[f]=[]},c=new Set;let d;for(let f=0,p=o.length;f<p;f++){d=o[f];for(const m of Object.values(d.added))xd(m)&&(l(m.parentId),a[m.parentId].push(m.id),c.add(a[m.parentId]));for(const[m,y]of Object.values(d.updated))if(xd(y)&&xd(m)){if(m.parentId!==y.parentId)l(m.parentId),l(y.parentId),a[m.parentId].splice(a[m.parentId].indexOf(y.id),1),a[y.parentId].push(y.id),c.add(a[y.parentId]);else if(m.index!==y.index){l(y.parentId);const v=a[y.parentId].indexOf(y.id);a[y.parentId][v]=y.id,c.add(a[y.parentId])}}for(const m of Object.values(d.removed))xd(m)&&(l(m.parentId),a[m.parentId].splice(a[m.parentId].indexOf(m.id),1))}for(const f of c){const p=st(f.map(m=>n.get(m)));p.sort(Qn),f.splice(0,f.length,...p.map(m=>m.id))}return a??s})},gC=(n,e,t)=>{for(;!ds(t.parentId);){const r=n.get(t.parentId);if(!r)return!1;t=r}return t.parentId===e},jie=(n,e)=>{const t=n.query.ids("shape");let r=null;function s(){const i=e();return r=i,new Set([...t.get()].filter(o=>gC(n,i,n.get(o))))}return le("_shapeIdsInCurrentPage",(i,o)=>{if(Lc(i))return s();const a=e();if(a!==r)return s();const l=n.history.getDiffSince(o);if(l===zs)return s();const c=new ty(i);for(const f of l){for(const p of Object.values(f.added))xd(p)&&gC(n,a,p)&&c.add(p.id);for(const[p,m]of Object.values(f.updated))xd(m)&&(gC(n,a,m)?c.add(m.id):c.remove(m.id));for(const p of Object.keys(f.removed))ps(p)&&c.remove(p)}const d=c.get();return d?ff(d.value,d.diff):i})};var Nie=Object.create,e$=Object.defineProperty,Lie=Object.getOwnPropertyDescriptor,Fie=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),t$=n=>{throw TypeError(n)},n$=(n,e,t)=>e in n?e$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,zie=n=>[,,,Nie(null)],r$=["class","method","getter","setter","accessor","field","value","get","set"],s$=n=>n!==void 0&&typeof n!="function"?t$("Function expected"):n,$ie=(n,e,t,r,s)=>({kind:r$[n],name:e,metadata:r,addInitializer:i=>t._?t$("Already initialized"):s.push(s$(i||null))}),Bie=(n,e)=>n$(e,Fie("metadata"),n[3]),Uie=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},i$=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=r$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Lie(s,t)),b=r.length-1;b>=0;b--)l=$ie(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,s$(o)&&(x[y]=o);return x&&e$(s,t,x),s},od=(n,e,t)=>n$(n,typeof e!="symbol"?e+"":e,t),o$,a$,zp;const Hie=40;a$=[vs],o$=[vs];class Jv{constructor(e){this.editor=e,Uie(zp,5,this),od(this,"_clickId",""),od(this,"_clickTimeout"),od(this,"_clickScreenPoint"),od(this,"_previousScreenPoint"),od(this,"_clickState","idle"),od(this,"lastPointerInfo",{})}_getClickTimeout(e,t=_t()){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=E.From(e.point),this._previousScreenPoint&&E.Dist2(this._previousScreenPoint,this._clickScreenPoint)>Hie**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=E.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&&E.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"}}zp=zie();i$(zp,1,"_getClickTimeout",a$,Jv);i$(zp,1,"cancelDoubleClickTimeout",o$,Jv);Bie(zp,Jv);class Kie{constructor(e){O(this,"_isEdgeScrolling",!1);O(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?$n.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,i){const{editor:o}=this,a=o.options.edgeScrollDistance,l=r?o.options.coarsePointerWidth:0,c=e-l,d=e+l,f=s?0:a,p=i?t:t-a;return c<f?Math.min(1,(f-c)/a):d>p?-Math.min(1,(d-p)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=e,s=e.getViewportScreenBounds(),{isCoarsePointer:i,insets:[o,a,l,c]}=e.getInstanceState(),d=this.getEdgeProximityFactors(t,s.w,i,c,a),f=this.getEdgeProximityFactors(r,s.h,i,o,l);return{x:d,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,i=r.h<1e3?.612:1,o=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,l=a*e.x*s/o,c=a*e.y*i/o,{x:d,y:f,z:p}=t.getCamera();t.setCamera(new E(d+l,f+c,p))}}class Wie{constructor(e,t){O(this,"disposeSideEffectListener");this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(s,i)=>{s.isFocused!==i.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)}}class Vie{constructor(e,t){O(this,"shapeFontFacesCache");O(this,"shapeFontLoadStateCache");O(this,"fontStates",new eE("font states"));O(this,"fontsToLoad",new Set);this.editor=e,this.assetUrls=t,this.shapeFontFacesCache=e.store.createComputedCache("shape font faces",r=>this.editor.getShapeUtil(r).getFontFaces(r),{areResultsEqual:jy}),this.shapeFontLoadStateCache=e.store.createCache(r=>{const s=le("font faces",()=>this.getShapeFontFaces(r));return le("font load state",()=>s.get().map(o=>this.getFontState(o)),{isEqual:jy})})}getShapeFontFaces(e){const t=typeof e=="string"?e:e.id;return this.shapeFontFacesCache.get(t)??Si}trackFontsForShape(e){const t=typeof e=="string"?e:e.id;this.shapeFontLoadStateCache.get(t)}async loadRequiredFontsForCurrentPage(e=1/0){const t=new Set;for(const s of this.editor.getCurrentPageShapeIds())for(const i of this.getShapeFontFaces(this.editor.getShape(s)))t.add(i);if(t.size>e)return;const r=Array.from(t,s=>this.ensureFontIsLoaded(s));await Promise.all(r)}getFontState(e){return this.fontStates.get(e)??null}ensureFontIsLoaded(e){const t=this.getFontState(e);if(t)return t.loadingPromise;const r=this.findOrCreateFontFace(e),s={state:"loading",instance:r,loadingPromise:r.load().then(()=>{document.fonts.add(r),this.fontStates.update(e,i=>({...i,state:"ready"}))}).catch(i=>{console.error(i),this.fontStates.update(e,o=>({...o,state:"error"}))})};return this.fontStates.set(e,s),s.loadingPromise}requestFonts(e){this.fontsToLoad.size||queueMicrotask(()=>{if(this.editor.isDisposed)return;const t=this.fontsToLoad;this.fontsToLoad=new Set,ws(()=>{for(const r of t)this.ensureFontIsLoaded(r)})});for(const t of e)this.fontsToLoad.add(t)}findOrCreateFontFace(e){var s;for(const i of document.fonts)if(i.family===e.family&&xs(Gj).every(([o,a])=>i[o]===(e[o]??a)))return i;const t=((s=this.assetUrls)==null?void 0:s[e.src.url])??e.src.url,r=new FontFace(e.family,`url(${JSON.stringify(t)})`,{...Jd(Gj,i=>e[i]),display:"swap"});return document.fonts.add(r),r}async toEmbeddedCssDeclaration(e){var i;const t=((i=this.assetUrls)==null?void 0:i[e.src.url])??e.src.url,r=await zr.urlToDataUrl(t),s=st([`url("${r}")`,e.src.format?`format(${e.src.format})`:null,e.src.tech?`tech(${e.src.tech})`:null]).join(" ");return st(["@font-face {",` font-family: "${e.family}";`,e.ascentOverride?` ascent-override: ${e.ascentOverride};`:null,e.descentOverride?` descent-override: ${e.descentOverride};`:null,e.stretch?` font-stretch: ${e.stretch};`:null,e.style?` font-style: ${e.style};`:null,e.weight?` font-weight: ${e.weight};`:null,e.featureSettings?` font-feature-settings: ${e.featureSettings};`:null,e.lineGapOverride?` line-gap-override: ${e.lineGapOverride};`:null,e.unicodeRange?` unicode-range: ${e.unicodeRange};`:null,` src: ${s};`,"}"]).join(`
200
+ `)}}const Gj={style:"normal",weight:"normal",stretch:"normal",unicodeRange:"U+0-10FFFF",featureSettings:"normal",ascentOverride:"normal",descentOverride:"normal",lineGapOverride:"normal"};function rf(n){return Gie}class qie{constructor(){O(this,"length",0);O(this,"head",null);O(this,"tail",this)}push(e){return new XI(e,this)}toArray(){return Si}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const Gie=new qie;class XI{constructor(e,t){O(this,"length");this.head=e,this.tail=t,this.length=t.length+1}push(e){return new XI(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 Yie{constructor(e){O(this,"store");O(this,"dispose");O(this,"state","recording");O(this,"pendingDiff",new Zie);O(this,"stacks",on("HistoryManager.stacks",{undos:rf(),redos:rf()},{isEqual:(e,t)=>e.undos===t.undos&&e.redos===t.redos}));O(this,"annotateError");O(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??Vf,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:rf()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:En(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=Xie[t.history]);try{if(this._isInBatch)return ws(e),this;this._isInBatch=!0;try{ws(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:i,redos:o}=this.stacks.get();const a=this.pendingDiff.clear(),l=J5(a),c=tE(a);e&&!l&&(o=o.push({type:"diff",diff:a}));let d=!1;if(l)for(;((s=i.head)==null?void 0:s.type)==="stop";){const f=i.head;if(i=i.tail,e&&(o=o.push(f)),f.id===t){d=!0;break}}if(!d)e:for(;i.head;){const f=i.head;switch(i=i.tail,e&&(o=o.push(f)),f.type){case"diff":Af(c,[tE(f.diff)]);break;case"stop":if(!t)break e;if(f.id===t){d=!0;break e}break;default:En(f)}}if(!d&&t)return this;this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:i,redos:o})}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 i=nS();for(;s.head;){const o=s.head;if(r=r.push(o),s=s.tail,o.type==="diff")Af(i,[o.diff]);else break}this.store.applyDiff(i,{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 i;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||((i=t.head)==null?void 0:i.id)!==e)return console.error("Could not find mark to squash to: ",e),this;if(r.length===0)return this;const s=nS();return Af(s,r.reverse()),this.stacks.update(({redos:o})=>({undos:t.push({type:"diff",diff:s}),redos:o})),this}_mark(e){ws(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:rf(),redos:rf()}),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 Xie={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class Zie{constructor(){O(this,"diff",nS());O(this,"isEmptyAtom",on("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=nS(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){Af(this.diff,[e]),this.isEmptyAtom.set(J5(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class Jie{constructor(e){O(this,"scribbleItems",new Map);O(this,"state","paused");this.editor=e}addScribble(e,t=_t()){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 i=this.scribbleItems.get(e);if(!i)throw Error(`Scribble with id ${e} not found`);const{prev:o}=i,a={x:t,y:r,z:s};return(!o||E.Dist(o,a)>=1)&&(i.next=a),i}tick(e){this.scribbleItems.size!==0&&this.editor.run(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:l,prev:c}=t;l&&l!==c&&(t.prev=l,t.scribble.points.push(l)),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:i,next:o,scribble:a}=t;switch(a.state){case"active":{o&&o!==i?(t.prev=o,a.points.push(o),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 Qie=Object.create,l$=Object.defineProperty,eoe=Object.getOwnPropertyDescriptor,toe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),c$=n=>{throw TypeError(n)},u$=(n,e,t)=>e in n?l$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,noe=n=>[,,,Qie(null)],d$=["class","method","getter","setter","accessor","field","value","get","set"],h$=n=>n!==void 0&&typeof n!="function"?c$("Function expected"):n,roe=(n,e,t,r,s)=>({kind:d$[n],name:e,metadata:r,addInitializer:i=>t._?c$("Already initialized"):s.push(h$(i||null))}),soe=(n,e)=>u$(e,toe("metadata"),n[3]),ioe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},Qv=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=d$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,eoe(s,t)),b=r.length-1;b>=0;b--)l=roe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,h$(o)&&(x[y]=o);return x&&l$(s,t,x),s},ooe=(n,e,t)=>u$(n,e+"",t),f$,p$,g$,m$,gu;const Ye=n=>Math.round(n*10**8)/10**8;function pa(n,e,t,r,s){const i=n.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&Ye(a.length)===Ye(t)&&zi(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));if(i.length===0)return[];const o=new Set;return i.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!o.has(l)){o.add(l);const c=pa(n,l,t,r,zi(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));i.push(...c)}}),i}function aoe(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(i=>s.gaps.some(o=>Ye(i.startEdge[0].x)===Ye(o.startEdge[0].x)&&Ye(i.startEdge[0].y)===Ye(o.startEdge[0].y)&&Ye(i.startEdge[1].x)===Ye(o.startEdge[1].x)&&Ye(i.startEdge[1].y)===Ye(o.startEdge[1].y))&&s.gaps.some(o=>Ye(i.endEdge[0].x)===Ye(o.endEdge[0].x)&&Ye(i.endEdge[0].y)===Ye(o.endEdge[0].y)&&Ye(i.endEdge[1].x)===Ye(o.endEdge[1].x)&&Ye(i.endEdge[1].y)===Ye(o.endEdge[1].y)))){n.splice(e,1);break}}}}m$=[le],g$=[le],p$=[le],f$=[le];class lh{constructor(e){this.manager=e,ioe(gu,5,this),ooe(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 i=e.getShapeUtil(t).getBoundsSnapGeometry(t).points??e.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!i))return i.map((o,a)=>{const{x:l,y:c}=ve.applyToPoint(r,o);return{x:l,y:c,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 i=e.get(s);i&&r.push(...i)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:Nr(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){const e=[],t=[];let r,s;const i=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)s=i[l],r.pageBounds.maxX<s.pageBounds.minX&&Zh(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)&&e.push({startNode:r,endNode:s,startEdge:[new E(r.pageBounds.maxX,r.pageBounds.minY),new E(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new E(s.pageBounds.minX,s.pageBounds.minY),new E(s.pageBounds.minX,s.pageBounds.maxY)],length:s.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:zi(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)})}const o=i.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<o.length;a++){r=o[a];for(let l=a+1;l<o.length;l++)s=o[l],r.pageBounds.maxY<s.pageBounds.minY&&Zh(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)&&t.push({startNode:r,endNode:s,startEdge:[new E(r.pageBounds.minX,r.pageBounds.maxY),new E(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new E(s.pageBounds.minX,s.pageBounds.minY),new E(s.pageBounds.maxX,s.pageBounds.minY)],length:s.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:zi(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 x,b;const i=this.manager.getSnapThreshold(),o=this.getSnappablePoints(),a=t.clone().translate(s),l=r.map(({x:C,y:I},_)=>({id:"selection:"+_,x:C+s.x,y:I+s.y})),c=o,d=[],f=[],p=new E(i,i);this.collectPointSnaps({minOffset:p,nearestSnapsX:d,nearestSnapsY:f,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:f,minOffset:p});const m=new E(e==="x"?0:((x=d[0])==null?void 0:x.nudge)??0,e==="y"?0:((b=f[0])==null?void 0:b.nudge)??0);p.x=0,p.y=0,d.length=0,f.length=0,l.forEach(C=>{C.x+=m.x,C.y+=m.y}),a.translate(m),this.collectPointSnaps({minOffset:p,nearestSnapsX:d,nearestSnapsY:f,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:f,minOffset:p});const y=this.getPointSnapLines({nearestSnapsX:d,nearestSnapsY:f}),v=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:f});return this.manager.setIndicators([...v,...y]),{nudge:m}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:t,handle:r,isAspectRatioLocked:s,isResizingFromCenter:i}){var R,j;const o=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=ye.Resize(e,r,i?t.x*2:t.x,i?t.y*2:t.y,s);let d=r;l<0&&(d=lre(d)),c<0&&(d=are(d)),i&&(a.center=e.center);const f=d==="top"||d==="bottom",p=d==="left"||d==="right",m=Yj(d,a),y=this.getSnappablePoints(),v=[],x=[],b=new E(o,o);this.collectPointSnaps({minOffset:b,nearestSnapsX:v,nearestSnapsY:x,otherNodeSnapPoints:y,selectionSnapPoints:m});const C=new E(f?0:((R=v[0])==null?void 0:R.nudge)??0,p?0:((j=x[0])==null?void 0:j.nudge)??0);if(s&&cre(d)&&C.len()!==0){const K=v.length&&x.length?Math.abs(C.x)<Math.abs(C.y)?"x":"y":v.length?"x":"y",U=e.aspectRatio;K==="x"?(x.length=0,C.y=C.x/U,(d==="bottom_left"||d==="top_right")&&(C.y=-C.y)):(v.length=0,C.x=C.y*U,(d==="bottom_left"||d==="top_right")&&(C.x=-C.x))}const I=E.Add(t,C),{box:_}=ye.Resize(e,r,i?I.x*2:I.x,i?I.y*2:I.y,s);i&&(_.center=e.center);const T=Yj("any",_);v.length=0,x.length=0,b.x=0,b.y=0,this.collectPointSnaps({minOffset:b,nearestSnapsX:v,nearestSnapsY:x,otherNodeSnapPoints:y,selectionSnapPoints:T});const A=this.getPointSnapLines({nearestSnapsX:v,nearestSnapsY:x});return this.manager.setIndicators([...A]),{nudge:C}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:s,nearestSnapsY:i}){for(const o of e)for(const a of t){const l=E.Sub(o,a),c=Math.abs(l.x),d=Math.abs(l.y);Ye(c)<=Ye(r.x)&&(Ye(c)<Ye(r.x)&&(s.length=0),s.push({type:"points",points:{thisPoint:o,otherPoint:a},nudge:a.x-o.x}),r.x=c),Ye(d)<=Ye(r.y)&&(Ye(d)<Ye(r.y)&&(i.length=0),i.push({type:"points",points:{thisPoint:o,otherPoint:a},nudge:a.y-o.y}),r.y=d)}}collectGapSnaps({selectionPageBounds:e,minOffset:t,nearestSnapsX:r,nearestSnapsY:s}){const{horizontal:i,vertical:o}=this.getVisibleGaps();for(const a of i){if(!Zh(a.breadthIntersection[0],a.breadthIntersection[1],e.minY,e.maxY))continue;const c=a.startEdge[0].x+a.length/2-e.center.x;if(a.length>e.width&&Ye(Math.abs(c))<=Ye(t.x)){Ye(Math.abs(c))<Ye(t.x)&&(r.length=0),t.x=Math.abs(c);const b={type:"gap_center",gap:a,nudge:c},C=r.find(({type:_})=>_==="gap_center"),I=C&&zi(a.breadthIntersection[0],a.breadthIntersection[1],C.gap.breadthIntersection[0],C.gap.breadthIntersection[1]);C&&C.gap.length>a.length&&I?r[r.indexOf(C)]=b:(!C||!I)&&r.push(b)}const f=a.startNode.pageBounds.minX-a.length,p=e.maxX,m=f-p;Ye(Math.abs(m))<=Ye(t.x)&&(Ye(Math.abs(m))<Ye(t.x)&&(r.length=0),t.x=Math.abs(m),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:m}));const y=a.endNode.pageBounds.maxX+a.length,v=e.minX,x=y-v;Ye(Math.abs(x))<=Ye(t.x)&&(Ye(Math.abs(x))<Ye(t.x)&&(r.length=0),t.x=Math.abs(x),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:x}))}for(const a of o){if(!Zh(a.breadthIntersection[0],a.breadthIntersection[1],e.minX,e.maxX))continue;const c=a.startEdge[0].y+a.length/2-e.center.y;if(a.length>e.height&&Ye(Math.abs(c))<=Ye(t.y)){Ye(Math.abs(c))<Ye(t.y)&&(s.length=0),t.y=Math.abs(c);const b={type:"gap_center",gap:a,nudge:c},C=s.find(({type:_})=>_==="gap_center"),I=C&&Zh(C.gap.breadthIntersection[0],C.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);C&&C.gap.length>a.length&&I?s[s.indexOf(C)]=b:(!C||!I)&&s.push(b);continue}const f=a.startNode.pageBounds.minY-a.length,p=e.maxY,m=f-p;Ye(Math.abs(m))<=Ye(t.y)&&(Ye(Math.abs(m))<Ye(t.y)&&(s.length=0),t.y=Math.abs(m),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:m}));const y=a.endNode.pageBounds.maxY+a.length,v=e.minY,x=y-v;Ye(Math.abs(x))<=Ye(t.y)&&(Ye(Math.abs(x))<Ye(t.y)&&(s.length=0),t.y=Math.abs(x),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:x}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:t}){const r={},s={};if(e.length>0){for(const i of e)if(i.type==="points"){const o=Ye(i.points.otherPoint.x);r[o]||(r[o]=[]),r[o].push(i.points)}}if(t.length>0){for(const i of t)if(i.type==="points"){const o=Ye(i.points.otherPoint.y);s[o]||(s[o]=[]),s[o].push(i.points)}}return Object.values(r).concat(Object.values(s)).map(i=>({id:_t(),type:"points",points:pk(i.map(o=>E.From(o.otherPoint)).concat(i.map(o=>E.From(o.thisPoint))),(o,a)=>o.equals(a))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:s,horizontal:i}=this.getVisibleGaps(),o={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 l of t){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:d,startNode:f,endNode:p,length:m,endEdge:y}}=l;switch(l.type){case"gap_center":{const v=(m-e.width)/2,x=zi(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:_t(),gaps:[...pa(i,f.id,v,"backward",x),{startEdge:d,endEdge:o.left},{startEdge:o.right,endEdge:y},...pa(i,p.id,v,"forward",x)]});break}case"gap_duplicate":{const v=zi(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:_t(),gaps:l.protrusionDirection==="left"?[{startEdge:o.right,endEdge:d.map(x=>x.clone().addXY(-f.pageBounds.width,0))},{startEdge:d,endEdge:y},...pa(i,p.id,m,"forward",v)]:[...pa(i,f.id,m,"backward",v),{startEdge:d,endEdge:y},{startEdge:y.map(x=>x.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:o.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:d,startNode:f,endNode:p,length:m,endEdge:y}}=l;switch(l.type){case"gap_center":{const v=(m-e.height)/2,x=zi(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:_t(),gaps:[...pa(s,f.id,v,"backward",x),{startEdge:d,endEdge:o.top},{startEdge:o.bottom,endEdge:y},...pa(s,l.gap.endNode.id,v,"forward",x)]});break}case"gap_duplicate":{const v=zi(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:_t(),gaps:l.protrusionDirection==="top"?[{startEdge:o.bottom,endEdge:d.map(x=>x.clone().addXY(0,-f.pageBounds.height))},{startEdge:d,endEdge:y},...pa(s,p.id,m,"forward",v)]:[...pa(s,f.id,m,"backward",v),{startEdge:d,endEdge:y},{startEdge:y.map(x=>x.clone().addXY(0,p.pageBounds.height)),endEdge:o.top}]})}break}}return aoe(a),a}}gu=noe();Qv(gu,1,"getSnapPointsCache",m$,lh);Qv(gu,1,"getSnappablePoints",g$,lh);Qv(gu,1,"getSnappableGapNodes",p$,lh);Qv(gu,1,"getVisibleGaps",f$,lh);soe(gu,lh);function Yj(n,e){const{minX:t,maxX:r,minY:s,maxY:i}=e,o=[];switch(n){case"top":case"left":case"top_left":case"any":o.push({id:"top_left",handle:"top_left",x:t,y:s})}switch(n){case"top":case"right":case"top_right":case"any":o.push({id:"top_right",handle:"top_right",x:r,y:s})}switch(n){case"bottom":case"right":case"bottom_right":case"any":o.push({id:"bottom_right",handle:"bottom_right",x:r,y:i})}switch(n){case"bottom":case"left":case"bottom_left":case"any":o.push({id:"bottom_left",handle:"bottom_left",x:t,y:i})}return o}var loe=Object.create,y$=Object.defineProperty,coe=Object.getOwnPropertyDescriptor,uoe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),S$=n=>{throw TypeError(n)},v$=(n,e,t)=>e in n?y$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,doe=n=>[,,,loe(null)],x$=["class","method","getter","setter","accessor","field","value","get","set"],w$=n=>n!==void 0&&typeof n!="function"?S$("Function expected"):n,hoe=(n,e,t,r,s)=>({kind:x$[n],name:e,metadata:r,addInitializer:i=>t._?S$("Already initialized"):s.push(w$(i||null))}),foe=(n,e)=>v$(e,uoe("metadata"),n[3]),poe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},goe=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=x$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,coe(s,t)),b=r.length-1;b>=0;b--)l=hoe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,w$(o)&&(x[y]=o);return x&&y$(s,t,x),s},moe=(n,e,t)=>v$(n,e+"",t),b$,e0;const yoe=()=>null,Soe=()=>[];b$=[le];class ZI{constructor(e){this.manager=e,poe(e0,5,this),moe(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):yoe,i=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):Soe;return{outline:r.outline===void 0?e.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:s,getSelfSnapPoints:i}})}*iterateSnapPointsInPageSpace(e,t){var s,i;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapPoints(t);if(r&&r.length){const o=Nr(this.editor.getShapePageTransform(e));for(const a of r)yield o.applyToPoint(a)}for(const o of this.manager.getSnappableShapes()){if(o===e)continue;const a=(i=this.getSnapGeometryCache().get(o))==null?void 0:i.points;if(!a||!a.length)continue;const l=Nr(this.editor.getShapePageTransform(o));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(e,t){var s,i;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapOutline(t);r&&(yield{shapeId:e,outline:r});for(const o of this.manager.getSnappableShapes()){if(o===e)continue;const a=(i=this.getSnapGeometryCache().get(o))==null?void 0:i.outline;a&&(yield{shapeId:o,outline:a})}}getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:r}){const s=this.manager.getSnapThreshold();let i=s,o=null;for(const c of this.iterateSnapPointsInPageSpace(e,t))E.DistMin(r,c,i)&&(i=E.Dist(r,c),o=c);if(o)return o;let a=s,l=null;for(const{shapeId:c,outline:d}of this.iterateSnapOutlines(e,t)){const f=Nr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),m=d.nearestPoint(p),y=f.applyToPoint(m);E.DistMin(r,y,a)&&(a=E.Dist(r,y),l=y)}return l||null}snapHandle({currentShapeId:e,handle:t}){const s=Nr(this.editor.getShapePageTransform(e)).applyToPoint(t),i=this.getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:s});return i?(this.manager.setIndicators([{id:_t(),type:"points",points:[i]}]),{nudge:E.Sub(i,s)}):null}}e0=doe();goe(e0,1,"getSnapGeometryCache",b$,ZI);foe(e0,ZI);var voe=Object.create,C$=Object.defineProperty,xoe=Object.getOwnPropertyDescriptor,woe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),P$=n=>{throw TypeError(n)},E$=(n,e,t)=>e in n?C$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,boe=n=>[,,,voe(null)],k$=["class","method","getter","setter","accessor","field","value","get","set"],I$=n=>n!==void 0&&typeof n!="function"?P$("Function expected"):n,Coe=(n,e,t,r,s)=>({kind:k$[n],name:e,metadata:r,addInitializer:i=>t._?P$("Already initialized"):s.push(I$(i||null))}),Poe=(n,e)=>E$(e,woe("metadata"),n[3]),Eoe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},JI=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=k$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,xoe(s,t)),b=r.length-1;b>=0;b--)l=Coe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,I$(o)&&(x[y]=o);return x&&C$(s,t,x),s},mC=(n,e,t)=>E$(n,typeof e!="symbol"?e+"":e,t),_$,T$,M$,ch;M$=[le],T$=[le],_$=[le];class $p{constructor(e){this.editor=e,Eoe(ch,5,this),mC(this,"shapeBounds"),mC(this,"handles"),mC(this,"_snapIndicators",on("snapLines",void 0)),this.shapeBounds=new lh(this),this.handles=new ZI(this)}getIndicators(){return this._snapIndicators.get()??Si}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,i=o=>{if(ps(o)){const l=e.getShape(o);l&&e.isShapeOfType(l,"frame")&&s.add(o)}const a=e.getSortedChildIdsForParent(o);for(const l of a){if(r.includes(l))continue;const c=e.getShape(l);if(!c||!e.getShapeUtil(c).canSnap(c))continue;const f=e.getShapePageBounds(l);if(f&&t.includes(f)){if(e.isShapeOfType(c,"group")){i(l);continue}s.add(l)}}};return i(this.getCurrentCommonAncestor()??e.getCurrentPageId()),s}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}ch=boe();JI(ch,1,"getSnapThreshold",M$,$p);JI(ch,1,"getSnappableShapes",T$,$p);JI(ch,1,"getCurrentCommonAncestor",_$,$p);Poe(ch,$p);const koe=/\r?\n|\r/g;function Xj(n){return n.replace(koe,`
201
+ `).split(`
202
+ `).map(e=>e||" ").join(`
203
+ `)}const Ioe={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},_oe=/\s/;class Toe{constructor(e){O(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=document.createElement("div");return r.textContent=Xj(e),this.measureHtml(r.innerHTML,t)}measureHtml(e,t){const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(r),r.innerHTML=e,this.baseElem.insertAdjacentElement("afterend",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");const s=r.scrollWidth,i=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:i.width,h:i.height,scrollWidth:s}}measureElementTextNodeSpans(e,{shouldTruncateToFirstLine:t=!1}={}){const r=[],s=e.getBoundingClientRect(),i=-s.left,o=-s.top,a=new Range,l=e.childNodes[0];let c=0,d=null,f=null,p=0,m=0,y=!1;for(const v of e.childNodes)if(v.nodeType===Node.TEXT_NODE)for(const x of v.textContent??""){a.setStart(l,c),a.setEnd(l,c+x.length);const b=a.getClientRects(),C=b[b.length-1],I=C.top+o,_=C.left+i,T=C.right+i,A=_<m,R=_oe.test(x);if(R!==f||I!==p||!d){if(d){if(t&&I!==p){y=!0;break}r.push(d)}d={box:{x:_,y:I,w:C.width,h:C.height},text:x},m=_}else A&&(d.box.x=_),d.box.w=A?d.box.w+C.width:T-d.box.x,d.text+=x;x===`
204
+ `&&(m=0),f=R,p=I,c+=x.length}return d&&r.push(d),{spans:r,didTruncate:y}}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",Ioe[t.textAlign]),r.style.setProperty("font-style",t.fontStyle);const i=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";i&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const o=Xj(e);r.textContent=o;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:i});if(t.overflow==="truncate-ellipsis"&&l){r.textContent="…";const c=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${s-c}px`),r.textContent=o;const d=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,f=d[d.length-1];return d.push({text:"…",box:{x:Math.min(f.box.x+f.box.w,t.width-t.padding-c),y:f.box.y,w:c,h:f.box.h}}),d}return r.remove(),a}}var Moe=Object.create,A$=Object.defineProperty,Aoe=Object.getOwnPropertyDescriptor,Ooe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),O$=n=>{throw TypeError(n)},R$=(n,e,t)=>e in n?A$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Roe=n=>[,,,Moe(null)],D$=["class","method","getter","setter","accessor","field","value","get","set"],j$=n=>n!==void 0&&typeof n!="function"?O$("Function expected"):n,Doe=(n,e,t,r,s)=>({kind:D$[n],name:e,metadata:r,addInitializer:i=>t._?O$("Already initialized"):s.push(j$(i||null))}),joe=(n,e)=>R$(e,Ooe("metadata"),n[3]),Noe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},N$=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=D$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Aoe(s,t)),b=r.length-1;b>=0;b--)l=Doe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,j$(o)&&(x[y]=o);return x&&A$(s,t,x),s},Cm=(n,e,t)=>R$(n,typeof e!="symbol"?e+"":e,t),L$,F$,Bp;const Zj=g3;F$=[vs],L$=[vs];class t0{constructor(e){this.editor=e,Noe(Bp,5,this),Cm(this,"cancelRaf"),Cm(this,"isPaused",!0),Cm(this,"now",0),Cm(this,"prevPoint",new E),this.editor.disposables.add(this.dispose),this.start()}start(){var e;this.isPaused=!1,(e=this.cancelRaf)==null||e.call(this),this.cancelRaf=Zj(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=Zj(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 i=E.Sub(r,t);this.prevPoint=r.clone();const o=i.len(),a=o?i.div(o):new E(0,0),l=s.clone().lrp(a.mul(o/e),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),s.equals(l)||(this.editor.inputs.pointerVelocity=l)}}Bp=Roe();N$(Bp,1,"tick",F$,t0);N$(Bp,1,"dispose",L$,t0);joe(Bp,t0);var Loe=Object.create,z$=Object.defineProperty,Foe=Object.getOwnPropertyDescriptor,zoe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),$$=n=>{throw TypeError(n)},B$=(n,e,t)=>e in n?z$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,$oe=n=>[,,,Loe(null)],U$=["class","method","getter","setter","accessor","field","value","get","set"],H$=n=>n!==void 0&&typeof n!="function"?$$("Function expected"):n,Boe=(n,e,t,r,s)=>({kind:U$[n],name:e,metadata:r,addInitializer:i=>t._?$$("Already initialized"):s.push(H$(i||null))}),Uoe=(n,e)=>B$(e,zoe("metadata"),n[3]),Hoe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},Pi=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=U$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Foe(s,t)),b=r.length-1;b>=0;b--)l=Boe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,H$(o)&&(x[y]=o);return x&&z$(s,t,x),s},Jj=(n,e,t)=>B$(n,typeof e!="symbol"?e+"":e,t),K$,W$,V$,q$,G$,Y$,X$,Z$,J$,Q$,eB,tB,Vr;tB=[le],eB=[le],Q$=[le],J$=[le],Z$=[le],X$=[le],Y$=[le],G$=[le],q$=[le],V$=[le],W$=[le],K$=[le];class Es{constructor(e,t){if(this.user=e,this.inferDarkMode=t,Hoe(Vr,5,this),Jj(this,"systemColorScheme",on("systemColorScheme","light")),Jj(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=i=>{i.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??bo.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??bo.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??bo.name}getLocale(){return this.user.userPreferences.get().locale??bo.locale}getColor(){return this.user.userPreferences.get().color??bo.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??bo.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??bo.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??bo.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??bo.isPasteAtCursorMode}}Vr=$oe();Pi(Vr,1,"getUserPreferences",tB,Es);Pi(Vr,1,"getIsDarkMode",eB,Es);Pi(Vr,1,"getEdgeScrollSpeed",Q$,Es);Pi(Vr,1,"getAnimationSpeed",J$,Es);Pi(Vr,1,"getId",Z$,Es);Pi(Vr,1,"getName",X$,Es);Pi(Vr,1,"getLocale",Y$,Es);Pi(Vr,1,"getColor",G$,Es);Pi(Vr,1,"getIsSnapMode",q$,Es);Pi(Vr,1,"getIsWrapMode",V$,Es);Pi(Vr,1,"getIsDynamicResizeMode",W$,Es);Pi(Vr,1,"getIsPasteAtCursorMode",K$,Es);Uoe(Vr,Es);const Koe={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"},Woe=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class Ne{constructor(e,t){O(this,"performanceTracker");O(this,"id");O(this,"type");O(this,"shapeType");O(this,"initial");O(this,"children");O(this,"isLockable");O(this,"parent");O(this,"_path");O(this,"_current");O(this,"_isActive");O(this,"_currentToolIdMask",on("curent tool id mask",void 0));this.editor=e;const{id:r,children:s,initial:i,isLockable:o}=this.constructor;this.id=r,this._isActive=on("toolIsActive"+this.id,!1),this._current=on("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&&i?(this.type="branch",this.initial=i,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&&i&&(this.initial=i,this.children=Object.fromEntries(s().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial]))),this.isLockable=o,this.performanceTracker=new qL}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}transition(e,t={}){var i;const r=e.split(".");let s=this;for(let o=0;o<r.length;o++){const a=r[o],l=s.getCurrent(),c=(i=s.children)==null?void 0:i[a];if(!c)throw Error(`${s.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(t,a),s._current.set(c),c.enter(t,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;s=c}return this}handleEvent(e){var s;const t=Koe[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(xn.measurePerformance.get()&&Woe.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;xn.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)}}O(Ne,"id"),O(Ne,"initial"),O(Ne,"children"),O(Ne,"isLockable",!0);class pE extends Ne{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}}}}O(pE,"id","root"),O(pE,"initial","");var Voe=Object.create,nB=Object.defineProperty,qoe=Object.getOwnPropertyDescriptor,rB=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),sB=n=>{throw TypeError(n)},iB=(n,e,t)=>e in n?nB(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Goe=n=>[,,,Voe((n==null?void 0:n[rB("metadata")])??null)],oB=["class","method","getter","setter","accessor","field","value","get","set"],aB=n=>n!==void 0&&typeof n!="function"?sB("Function expected"):n,Yoe=(n,e,t,r,s)=>({kind:oB[n],name:e,metadata:r,addInitializer:i=>t._?sB("Already initialized"):s.push(aB(i||null))}),Xoe=(n,e)=>iB(e,rB("metadata"),n[3]),Zoe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},Ie=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=oB[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,qoe(s,t)),b=r.length-1;b>=0;b--)l=Yoe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,aB(o)&&(x[y]=o);return x&&nB(s,t,x),s},Ue=(n,e,t)=>iB(n,typeof e!="symbol"?e+"":e,t),lB,cB,uB,dB,hB,fB,pB,gB,mB,yB,SB,vB,xB,wB,bB,CB,PB,EB,kB,IB,_B,TB,MB,AB,OB,RB,DB,jB,NB,LB,FB,zB,$B,BB,UB,HB,KB,WB,VB,qB,GB,YB,XB,ZB,JB,QB,e6,t6,n6,r6,s6,i6,o6,a6,l6,c6,u6,d6,h6,f6,p6,g6,m6,y6,S6,v6,x6,w6,b6,C6,P6,E6,gE,ke;class Ee extends(gE=hse,E6=[le],P6=[le],C6=[le],b6=[le],w6=[le],x6=[le],v6=[le],S6=[le],y6=[le],m6=[le],g6=[le],p6=[le],f6=[le],h6=[le],d6=[le],u6=[le],c6=[le],l6=[le],a6=[le],o6=[le],i6=[le],s6=[le],r6=[le],n6=[le],t6=[le],e6=[le],QB=[le],JB=[le],ZB=[le],XB=[le],YB=[le],GB=[le],qB=[le],VB=[le],WB=[le],KB=[le],HB=[le],UB=[le],BB=[le],$B=[le],zB=[le],FB=[le],LB=[le],NB=[le],jB=[le],DB=[le],RB=[le],OB=[le],AB=[le],MB=[le],TB=[le],_B=[le],IB=[le],kB=[le],EB=[le],PB=[le],CB=[le],bB=[le],wB=[le],xB=[le],vB=[le],SB=[le],yB=[le],mB=[le],gB=[le({isEqual:(e,t)=>e.equals(t)})],pB=[le],fB=[le],hB=[le],dB=[vs],uB=[vs],cB=[vs],lB=[vs],gE){constructor({store:e,user:t,shapeUtils:r,bindingUtils:s,tools:i,getContainer:o,cameraOptions:a,textOptions:l,initialState:c,autoFocus:d,inferDarkMode:f,options:p,isShapeHidden:m,fontAssetUrls:y}){var J;super(),Zoe(ke,5,this),Ue(this,"id",_t()),Ue(this,"_isShapeHiddenPredicate"),Ue(this,"options"),Ue(this,"contextId",_t()),Ue(this,"store"),Ue(this,"root"),Ue(this,"disposables",new Set),Ue(this,"isDisposed",!1),Ue(this,"_tickManager"),Ue(this,"snaps"),Ue(this,"timers",yS.forContext(this.contextId)),Ue(this,"user"),Ue(this,"textMeasure"),Ue(this,"fonts"),Ue(this,"environment",Pt),Ue(this,"scribbles"),Ue(this,"sideEffects"),Ue(this,"edgeScrollManager"),Ue(this,"focusManager"),Ue(this,"getContainer"),Ue(this,"shapeUtils"),Ue(this,"styleProps"),Ue(this,"bindingUtils"),Ue(this,"history"),Ue(this,"_shouldIgnoreShapeLock",!1),Ue(this,"_crashingError",null),Ue(this,"_isChangingStyleTimeout",-1),Ue(this,"menus",$i.forContext(this.contextId)),Ue(this,"_currentRichTextEditor",on("rich text editor",null)),Ue(this,"_textOptions"),Ue(this,"_cameraOptions",on("camera options",pj)),Ue(this,"_viewportAnimation",null),Ue(this,"_willSetInitialBounds",!0),Ue(this,"_isLockedOnFollowingUser",on("isLockedOnFollowingUser",!1)),Ue(this,"_cameraState",on("camera state","idle")),Ue(this,"_cameraStateTimeoutRemaining",0),Ue(this,"_currentPageShapeIds"),Ue(this,"_shapeGeometryCaches",{}),Ue(this,"_parentIdsToChildIds"),Ue(this,"animatingShapes",new Map),Ue(this,"externalAssetContentHandlers",{file:null,url:null}),Ue(this,"temporaryAssetPreview",new Map),Ue(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null,tldraw:null,excalidraw:null}),Ue(this,"inputs",{originPagePoint:new E,originScreenPoint:new E,previousPagePoint:new E,previousScreenPoint:new E,currentPagePoint:new E,currentScreenPoint:new E,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 E}),Ue(this,"_clickManager",new Jv(this)),Ue(this,"_prevCursor","default"),Ue(this,"_shiftKeyTimeout",-1),Ue(this,"_altKeyTimeout",-1),Ue(this,"_ctrlKeyTimeout",-1),Ue(this,"_metaKeyTimeout",-1),Ue(this,"_restoreToolId","select"),Ue(this,"_pinchStart",1),Ue(this,"_didPinch",!1),Ue(this,"_selectedShapeIdsAtPointerDown",[]),Ue(this,"_longPressTimeout",-1),Ue(this,"capturedPointerId",null),Ue(this,"performanceTracker"),Ue(this,"performanceTrackerTimeout",-1),Ue(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=m,this.options={...xie,...p},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new Yie({store:e,annotateError:z=>{this.annotateError(z,{origin:"history.batch",willCrashApp:!0}),this.crash(z)}}),this.snaps=new $p(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...pj,...a}),this._textOptions=on("text options",l??null),this.user=new Es(t??wz(),f??!1),this.disposables.add(()=>this.user.dispose()),this.getContainer=o,this.textMeasure=new Toe(this),this.fonts=new Vie(this,y),this._tickManager=new t0(this);class v extends pE{}O(v,"initial",c??""),this.root=new v(this),this.root.children={};const x=_z(r),b={},C={},I=new Map;for(const z of x){const N=new z(this);b[z.type]=N;const L=r4(z.props??{});C[z.type]=L;for(const V of L.keys())if(!I.has(V.id))I.set(V.id,V);else if(I.get(V.id)!==V)throw Error(`Multiple style props with id "${V.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=b,this.styleProps=C;const _=kz(s),T={};for(const z of _){const N=new z(this);T[z.type]=N}this.bindingUtils=T;for(const z of[...i]){if(yi(this.root.children,z.id))throw Error(`Can't override tool with id "${z.id}"`);this.root.children[z.id]=new z(this,this.root)}this.scribbles=new Jie(this);const A=(z,N)=>{let L=null;const V=z.selectedShapeIds.filter($=>!N.has($));V.length!==z.selectedShapeIds.length&&(L||(L={...z}),L.selectedShapeIds=V);const X=z.erasingShapeIds.filter($=>!N.has($));X.length!==z.erasingShapeIds.length&&(L||(L={...z}),L.erasingShapeIds=X),z.hoveredShapeId&&N.has(z.hoveredShapeId)&&(L||(L={...z}),L.hoveredShapeId=null),z.editingShapeId&&N.has(z.editingShapeId)&&(L||(L={...z}),L.editingShapeId=null);const W=z.hintingShapeIds.filter($=>!N.has($));return W.length!==z.hintingShapeIds.length&&(L||(L={...z}),L.hintingShapeIds=W),z.focusedGroupId&&N.has(z.focusedGroupId)&&(L||(L={...z}),L.focusedGroupId=null),L};this.sideEffects=this.store.sideEffects;let R=new Map;const j=new Set,K=new Set;let U=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var z,N,L,V;j.clear();for(const X of K){K.delete(X);const W=this.getShape(X);if(!W)continue;const $=this.getShapeUtil(W),G=(z=$.onChildrenChange)==null?void 0:z.call($,W);G!=null&&G.length&&this.updateShapes(G)}if(U.size){const X=U;U=new Set;for(const W of X){const $=this.getBindingUtil(W);(N=$.onOperationComplete)==null||N.call($)}}if(R.size){const X=R;R=new Map;for(const W of X.values())(V=(L=this.getBindingUtil(W.binding)).onAfterDelete)==null||V.call(L,W)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(z,N)=>{var L,V,X,W;for(const $ of this.getBindingsInvolvingShape(N))U.add($.type),$.fromId===N.id&&((V=(L=this.getBindingUtil($)).onAfterChangeFromShape)==null||V.call(L,{binding:$,shapeBefore:z,shapeAfter:N})),$.toId===N.id&&((W=(X=this.getBindingUtil($)).onAfterChangeToShape)==null||W.call(X,{binding:$,shapeBefore:z,shapeAfter:N}));if(z.parentId!==N.parentId){const $=G=>{var H,ne,ge,Pe;const re=this.getShape(G);if(re)for(const ce of this.getBindingsInvolvingShape(re))U.add(ce.type),ce.fromId===re.id&&((ne=(H=this.getBindingUtil(ce)).onAfterChangeFromShape)==null||ne.call(H,{binding:ce,shapeBefore:re,shapeAfter:re})),ce.toId===re.id&&((Pe=(ge=this.getBindingUtil(ce)).onAfterChangeToShape)==null||Pe.call(ge,{binding:ce,shapeBefore:re,shapeAfter:re}))};$(N.id),this.visitDescendants(N.id,$)}if(z.parentId!==N.parentId&&ds(N.parentId)){const $=new Set([z.id]);this.visitDescendants(z.id,G=>{$.add(G)});for(const G of this.getPageStates()){if(G.pageId===N.parentId)continue;const re=A(G,$);re&&this.store.put([re])}}z.parentId&&ps(z.parentId)&&K.add(z.parentId),N.parentId!==z.parentId&&ps(N.parentId)&&K.add(N.parentId)},beforeDelete:z=>{var X,W,$,G;if(j.has(z.id))return;z.parentId&&ps(z.parentId)&&K.add(z.parentId),j.add(z.id);const N=[];for(const re of this.getBindingsInvolvingShape(z)){U.add(re.type),N.push(re.id);const H=this.getBindingUtil(re);re.fromId===z.id?((X=H.onBeforeIsolateToShape)==null||X.call(H,{binding:re,removedShape:z}),(W=H.onBeforeDeleteFromShape)==null||W.call(H,{binding:re,shape:z})):(($=H.onBeforeIsolateFromShape)==null||$.call(H,{binding:re,removedShape:z}),(G=H.onBeforeDeleteToShape)==null||G.call(H,{binding:re,shape:z}))}N.length&&this.deleteBindings(N);const L=new Set([z.id]),V=st(this.getPageStates().map(re=>A(re,L)));V.length&&this.store.put(V)}},binding:{beforeCreate:z=>{var L,V;const N=(V=(L=this.getBindingUtil(z)).onBeforeCreate)==null?void 0:V.call(L,{binding:z});return N||z},afterCreate:z=>{var N,L;U.add(z.type),(L=(N=this.getBindingUtil(z)).onAfterCreate)==null||L.call(N,{binding:z})},beforeChange:(z,N)=>{var V,X;const L=(X=(V=this.getBindingUtil(N)).onBeforeChange)==null?void 0:X.call(V,{bindingBefore:z,bindingAfter:N});return L||N},afterChange:(z,N)=>{var L,V;U.add(N.type),(V=(L=this.getBindingUtil(N)).onAfterChange)==null||V.call(L,{bindingBefore:z,bindingAfter:N})},beforeDelete:z=>{var N,L;(L=(N=this.getBindingUtil(z)).onBeforeDelete)==null||L.call(N,{binding:z})},afterDelete:z=>{var N,L;(L=(N=this.getBindingUtil(z)).onAfterDelete)==null||L.call(N,{binding:z}),U.add(z.type)}},page:{afterCreate:z=>{const N=Ao.createId(z.id),L=Ki.createId(z.id);this.store.has(N)||this.store.put([Ao.create({id:N})]),this.store.has(L)||this.store.put([Ki.create({id:L,pageId:z.id})])},afterDelete:(z,N)=>{var X,W;if(((X=this.getInstanceState())==null?void 0:X.currentPageId)===z.id){const $=(W=this.getPages().find(G=>G.id!==z.id))==null?void 0:W.id;$?this.store.put([{...this.getInstanceState(),currentPageId:$}]):N==="user"&&this.store.ensureStoreIsUsable()}const L=Ao.createId(z.id),V=Ki.createId(z.id);this.store.remove([L,V])}},instance:{afterChange:(z,N,L)=>{var V;if(!this.store.has(N.currentPageId)){const X=this.store.has(z.currentPageId)?z.currentPageId:(V=this.getPages()[0])==null?void 0:V.id;X?this.store.update(N.id,W=>({...W,currentPageId:X})):L==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(z,N)=>{if((z==null?void 0:z.selectedShapeIds)!==(N==null?void 0:N.selectedShapeIds)){const L=N.selectedShapeIds.filter(X=>{var $,G;let W=($=this.getShape(X))==null?void 0:$.parentId;for(;ps(W);){if(N.selectedShapeIds.includes(W))return!1;W=(G=this.getShape(W))==null?void 0:G.parentId}return!0});let V=null;if(L.length>0){const X=this.findCommonAncestor(st(L.map(W=>this.getShape(W))),W=>this.isShapeOfType(W,"group"));X&&(V=X)}else N!=null&&N.focusedGroupId&&(V=N.focusedGroupId);(L.length!==N.selectedShapeIds.length||V!==N.focusedGroupId)&&this.store.put([{...N,selectedShapeIds:L,focusedGroupId:V??null}])}}}})),this._currentPageShapeIds=jie(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=Die(this.store),this.disposables.add(this.store.listen(z=>{this.emit("change",z)})),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 Kie(this),this.focusManager=new Wie(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 qL,(J=this.store.props.collaboration)!=null&&J.mode){const z=this.store.props.collaboration.mode;this.disposables.add(qi("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:z.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=On(this.shapeUtils,t);return nt(r,`No shape util found for type "${t}"`),r}hasShapeUtil(e){const t=typeof e=="string"?e:e.type;return yi(this.shapeUtils,t)}getBindingUtil(e){const t=typeof e=="string"?e:e.type,r=On(this.bindingUtils,t);return nt(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??_t()),this}markHistoryStoppingPoint(e){const t=`[${e??"stop"}]_${_t()}`;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:i}){const o=this.createErrorAnnotations(t,r);return gk(e,{tags:{...o.tags,...s},extras:{...o.extras,...i}}),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:i,...o}=s,{text:a,richText:l,...c}=i;return{...o,props:c}}),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 i=r.getCurrent();if((i==null?void 0:i.id)===s){if(t.length===0)return!0;r=i;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 i=t.pop();if(!i)return r;const o=(s=r.children)==null?void 0:s[i];if(!o)return;r=o}return r}getDocumentSettings(){return this.store.get(sE)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(Lr)}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 Ki.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 st(e.map(t=>this.store.get(t)))}setSelectedShapes(e){return this.run(()=>{const t=e.map(i=>typeof i=="string"?i:i.id),{selectedShapeIds:r}=this.getCurrentPageState(),s=new Set(r);if(t.length===s.size&&t.every(i=>s.has(i)))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,i=>s.includes(i.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=st(e.map(r=>this.getShapePageBounds(r)));return t.length===0?null:ye.Common(t)}getSelectionPageBounds(){return this.getShapesPageBounds(this.getSelectedShapeIds())}getShapesSharedRotation(e){let t=!1,r=0;for(let s=0,i=e.length;s<i;s++){const o=this.getShapePageTransform(e[s]);if(o)if(t){if(o.rotation()!==r)return 0}else t=!0,r=o.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(),i=this.getShapePageTransform(e[0]);return s.point=i.applyToPoint(s.point),s}const r=ye.FromPoints(e.flatMap(s=>{const i=this.getShapePageTransform(s);return i?i.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 ye(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(this.setRichTextEditor(null),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}),this._currentRichTextEditor.set(null)},{history:"ignore"})}return this}getRichTextEditor(){return this._currentRichTextEditor.get()}setRichTextEditor(e){const t=this._currentRichTextEditor.__unsafe__getWithoutCapture();return t!==e&&(t==null||t.destroy()),this._currentRichTextEditor.set(e),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 st(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:pk(t)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return st(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}getTextOptions(){return Nr(this._textOptions.get(),"Cannot use text without setting textOptions")}_unsafe_getCameraId(){return Ao.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:i,y:o,z:a}=t.camera,l=new ye(-i,-o,r/a,s/a),c=this.getViewportScreenBounds().clone(),d=c.width/c.height;return c.width=l.width,c.height=c.width/d,c.height<l.height&&(c.height=l.height,c.width=c.height*d),c.center=l.center,c}getCameraForFollowing(){const e=this.getViewportPageBoundsForFollowing();return e?{x:-e.x,y:-e.y,z:this.getViewportScreenBounds().w/e.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.initialZoom==="default")return 1;const{zx:t,zy:r}=eN(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 En(e.constraints.initialZoom)}}getBaseZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.baseZoom==="default")return 1;const{zx:t,zy:r}=eN(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 En(e.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(e){var r;const t=Yt({...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:i,z:o=r.z}=e;if(!(t!=null&&t.force)){const a=this.getCameraOptions(),l=a.zoomSteps[0],c=Jn(a.zoomSteps),d=this.getViewportScreenBounds();if(a.constraints){const{constraints:f}=a,p=Math.min(f.padding.y,d.w/2),m=Math.min(f.padding.x,d.h/2),y=ye.From(a.constraints.bounds),v=(d.w-m*2)/y.w,x=(d.h-p*2)/y.h,b=this.getBaseZoom(),C=c*b,I=l*b;if(t!=null&&t.reset&&(o=this.getInitialZoom()),o<I||o>C){const{x:z,y:N,z:L}=r,V=-z+d.w/L/2,X=-N+d.h/L/2;o=Mn(o,I,C);const W=-z+d.w/o/2,$=-N+d.h/o/2;s=z+W-V,i=N+$-X}const _=m/o-y.x,T=p/o-y.y,A=(d.w-m*2)/o-y.w,R=(d.h-p*2)/o-y.h,j=_+A*f.origin.x,K=T+R*f.origin.y,U=typeof f.behavior=="string"?f.behavior:f.behavior.x,J=typeof f.behavior=="string"?f.behavior:f.behavior.y;if(t!=null&&t.reset)s=j,i=K;else{switch(U){case"fixed":{s=j;break}case"contain":{o<v?s=j:s=Mn(s,_+A,_);break}case"inside":{o<v?s=Mn(s,_,(d.w-m)/o-y.w):s=Mn(s,_+A,_);break}case"outside":{s=Mn(s,m/o-y.w,(d.w-m)/o);break}case"free":break;default:throw En(U)}switch(J){case"fixed":{i=K;break}case"contain":{o<x?i=K:i=Mn(i,T+R,T);break}case"inside":{o<x?i=Mn(i,T,(d.h-p)/o-y.h):i=Mn(i,T+R,T);break}case"outside":{i=Mn(i,p/o-y.h,(d.h-p)/o);break}case"free":break;default:throw En(J)}}}else if(o>c||o<l){const{x:f,y:p,z:m}=r;o=Mn(o,l,c),s=f+(-f+d.w/o/2)-(-f+d.w/m/2),i=p+(-p+d.h/o/2)-(-p+d.h/m/2)}}return{x:s,y:i,z:o}}_setCamera(e,t){const r=this.getCamera(),{x:s,y:i,z:o}=this.getConstrainedCamera(e,t);return r.x===s&&r.y===i&&r.z===o?this:(ws(()=>{const a={...r,x:s,y:i,z:o};this.run(()=>{this.store.put([a])},{history:"ignore"});const{currentScreenPoint:l,currentPagePoint:c}=this.inputs,{screenBounds:d}=this.store.unsafeGetWithoutCapture(Lr);if(l.x/o-s!==c.x||l.y/o-i!==c.y){const f={type:"pointer",target:"canvas",name:"pointer_move",point:E.AddXY(l,d.x,d.y),pointerId:gj.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,metaKey:this.inputs.metaKey,accelKey:Cr(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=E.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 i=this.getConstrainedCamera(s,t);if(t!=null&&t.animation){const{width:o,height:a}=this.getViewportScreenBounds();this._animateToViewport(new ye(-i.x,-i.y,o/i.z,a/i.z),t)}else this._setCamera(i,{...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:i}=this.getViewportPageBounds();return this.setCamera(new E(-(e.x-s/2),-(e.y-i/2),this.getCamera().z),t),this}zoomToFit(e){const t=[...this.getCurrentPageShapeIds()];if(t.length<=0)return this;const r=ye.Common(st(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 i=this.getCamera(),{x:o,y:a,z:l}=i,{x:c,y:d}=e;let f=1;if(s){const p=this.getInitialZoom();l!==p&&(f=p)}return this.setCamera(new E(o+(c/f-c)-(c/l-c),a+(d/f-d)-(d/l-d),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:i,z:o}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const l=this.getBaseZoom();let c=Jn(a)*l;for(let d=1;d<a.length;d++){const f=a[d-1]*l,p=a[d]*l;if(!(p-o<=(p-f)/2)){c=p;break}}this.setCamera(new E(s+(e.x/c-e.x)-(e.x/o-e.x),i+(e.y/c-e.y)-(e.y/o-e.y),c),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 i=this.getBaseZoom(),{x:o,y:a,z:l}=this.getCamera();let c=s[0]*i;for(let d=s.length-1;d>0;d--){const f=s[d-1]*i,p=s[d]*i;if(!(p-l>=(p-f)/2)){c=f;break}}this.setCamera(new E(o+(e.x/c-e.x)-(e.x/l-e.x),a+(e.y/c-e.y)-(e.y/l-e.y),c),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(),i=(t==null?void 0:t.inset)??Math.min(Wte,s.width*.28),o=this.getBaseZoom(),a=r.zoomSteps[0],l=Jn(r.zoomSteps);let c=Mn(Math.min((s.width-i)/e.w,(s.height-i)/e.h),a*o,l*o);return(t==null?void 0:t.targetZoom)!==void 0&&(c=Math.min(t.targetZoom,c)),this.setCamera(new E(-e.x+(s.width-e.w*c)/2/c,-e.y+(s.height-e.h*c)/2/c,c),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:i,end:o}=this._viewportAnimation;if(t>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new E(-o.x,-o.y,this.getViewportScreenBounds().width/o.width));return}const a=s-t,l=r(1-a/s),c=i.minX+(o.minX-i.minX)*l,d=i.minY+(o.minY-i.minY)*l,f=i.maxX+(o.maxX-i.maxX)*l;this._setCamera(new E(-c,-d,this.getViewportScreenBounds().width/(f-c)),{force:!0})}_animateToViewport(e,t={animation:sC}){const{animation:r,...s}=t;if(!r)return;const{duration:i=0,easing:o=$n.easeInOutCubic}=r,a=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||a===0?this._setCamera(new E(-e.x,-e.y,this.getViewportScreenBounds().width/e.width),{...s}):(this._viewportAnimation={elapsed:0,duration:i/a,easing:o,start:l.clone(),end:e.clone()},this.once("stop-camera-animation",()=>{this.off("tick",this._animateViewport),this._viewportAnimation=null}),this.on("tick",this._animateViewport),this)}slideCamera(e={}){const{isLocked:t}=this.getCameraOptions();if(t&&!(e!=null&&e.force))return this;if(this.user.getAnimationSpeed()===0)return this;this.stopCameraAnimation();const{speed:s,friction:i=this.options.cameraSlideFriction,direction:o,speedThreshold:a=.01}=e;let l=Math.min(s,1);const c=()=>{this.off("tick",d),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const d=f=>{const{x:p,y:m,z:y}=this.getCamera(),v=E.Mul(o,l*f/y);l*=1-i,l<a?c():this._setCamera(new E(p+v.x,m+v.y,y))};return this.on("tick",d),this}zoomToUser(e,t={animation:{duration:500}}){const r=this.getCollaborators().find(i=>i.userId===e);if(!r)return this;const s=r.cursor;return s?(this.run(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const i=r.currentPageId===this.getCurrentPageId();i||this.setCurrentPage(r.currentPageId),t&&t.animation&&!i&&(t.animation=void 0),this.centerOnPoint(s,t);const{highlightedUserIds:o}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...o,e]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],l=a.indexOf(e);l<0||(a.splice(l,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(e,t=!1){if(e instanceof HTMLElement){const a=e.getBoundingClientRect();e=new ye(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,!Al(document.body.scrollWidth,e.maxX,1),!Al(document.body.scrollHeight,e.maxY,1),e.minX!==0],{_willSetInitialBounds:s}=this;this._willSetInitialBounds=!1;const{screenBounds:i,insets:o}=this.getInstanceState();if(e.equals(i)&&r.every((a,l)=>a===o[l]))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(E.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:e,y:t,w:r,h:s}=this.getInstanceState().screenBounds;return new ye(e,t,r,s)}getViewportScreenCenter(){const e=this.getViewportScreenBounds();return new E(e.midX-e.minX,e.midY-e.minY)}getViewportPageBounds(){const{w:e,h:t}=this.getViewportScreenBounds(),{x:r,y:s,z:i}=this.getCamera();return new ye(-r,-s,e/i,t/i)}screenToPage(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(Lr),{x:r,y:s,z:i=1}=this.getCamera();return new E((e.x-t.x)/i-r,(e.y-t.y)/i-s,e.z??.5)}pageToScreen(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(Lr),{x:r,y:s,z:i=1}=this.getCamera();return new E((e.x+r)*i+t.x,(e.y+s)*i+t.y,e.z??.5)}pageToViewport(e){const{x:t,y:r,z:s=1}=this.getCamera();return new E((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=>EV(e.filter(i=>i.userId===r),i=>i.lastActivityTimestamp??0)):Si}getCollaboratorsOnCurrentPage(){const e=this.getCurrentPageId();return this.getCollaborators().filter(t=>t.currentPageId===e)}startFollowingUser(e){this.stopFollowingUser();const t=this._getCollaboratorsQuery().get().filter(i=>i.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(i=>i.followingUserId===r))return this;const s=le("latestLeaderPresence",()=>this.getCollaborators().find(i=>i.userId===e));return ws(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const i=qi("update current page",()=>{const l=s.get();if(!l){this.stopFollowingUser();return}l.currentPageId!==this.getCurrentPageId()&&this.getPage(l.currentPageId)&&this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:l.currentPageId}]),this._isLockedOnFollowingUser.set(!0)},{history:"ignore"})}),o=()=>{i(),this._isLockedOnFollowingUser.set(!1),this.off("frame",a),this.off("stop-following",o)},a=()=>{if(!s.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const c=this.user.getAnimationSpeed();if(c===0){this._isLockedOnFollowingUser.set(!0);return}const d=this.getViewportPageBoundsForFollowing();if(!d){this.stopFollowingUser();return}const f=this.getViewportPageBounds(),p=Math.abs(d.minX-f.minX)+Math.abs(d.maxX-f.maxX),m=Math.abs(d.minY-f.minY)+Math.abs(d.maxY-f.maxY);if(p<this.options.followChaseViewportSnap&&m<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const y=Mn(c*.5,.1,.8),v=new ye(yt(f.minX,d.minX,y),yt(f.minY,d.minY,y),yt(f.width,d.width,y),yt(f.height,d.height,y)),x=new E(-v.x,-v.y,this.getViewportScreenBounds().width/v.width);this.stopCameraAnimation(),this._setCamera(x)};this.once("stop-following",o),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 i=this.getErasingShapeIds(),o=(l,c,d)=>{const f=this.getShape(l);if(!f||this.isShapeHidden(f))return;c*=f.opacity;let p=!1;const m=this.getShapeUtil(f);e&&(p=!d&&i.includes(l),p&&(c*=.32)),t.push({id:l,shape:f,util:m,index:r,backgroundIndex:s,opacity:c}),r+=1,s+=1;const y=this.getSortedChildIdsForParent(l);if(!y.length)return;let v=null;m.providesBackgroundForChildren(f)&&(v=s,s=r,r+=this.options.maxShapesPerPage);for(const x of y)o(x,c,d||p);v!==null&&(s=v)},a=e?[this.getCurrentPage()]:this.getPages();for(const l of a)for(const c of this.getSortedChildIdsForParent(l.id))o(c,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(rq)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return Array.from(this._getAllPagesQuery().get()).sort(Qn)}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=kie(e.name??"Page 1",t.map(o=>o.name));let s=e.index;(!s||t.some(o=>o.index===s))&&(s=To(t[t.length-1].index));const i=Vs.create({meta:{},...e,name:r,index:s});this.store.put([i])}),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 i=r.findIndex(a=>a.id===t),o=r[i-1]??r[i+1];this.setCurrentPage(o.id)}this.store.remove([s.id])}}),this}duplicatePage(e,t=Vs.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 i={...this.getCamera()},o=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.run(()=>{var c;const a=this.getPages(),l=Gf(s.index,(c=a[a.indexOf(s)+1])==null?void 0:c.index);if(this.createPage({name:s.name+" Copy",id:t,index:l}),this.setCurrentPage(t),this.setCamera(i),o)return this.putContentOntoCurrentPage(o)}),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:i=!1,dpr:o=this.getInstanceState().devicePixelRatio}=t,l=(d=>Math.pow(2,Math.ceil(Math.log2(d))))(s),c="connection"in navigator?navigator.connection.effectiveType:null;return await this.store.props.assets.resolve(r,{screenScale:s||1,steppedScreenScale:l,dpr:o,networkEffectiveType:c,shouldResolveToOriginal:i})}async uploadAsset(e,t,r){return await this.store.props.assets.upload(e,t,r)}getShapeGeometry(e,t){const r=(t==null?void 0:t.context)??"none";return this._shapeGeometryCaches[r]||(this._shapeGeometryCaches[r]=this.store.createComputedCache("bounds",s=>(this.fonts.trackFontsForShape(s),this.getShapeUtil(s).getGeometry(s,t)),{areRecordsEqual:(s,i)=>s.props===i.props})),this._shapeGeometryCaches[r].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 ve.Identity().translate(r.x,r.y).rotate(r.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if(ds(e.parentId))return this.getShapeLocalTransform(e);const t=this._getShapePageTransformCache().get(e.parentId)??ve.Identity();return ve.Compose(t,this.getShapeLocalTransform(e))})}getShapeParentTransform(e){const t=typeof e=="string"?e:e.id,r=this.getShape(t);return!r||ds(r.parentId)?ve.Identity():this._getShapePageTransformCache().get(r.parentId)??ve.Identity()}getShapePageTransform(e){const t=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(t)??ve.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",e=>{const t=this._getShapePageTransformCache().get(e.id);return t?ye.FromPoints(ve.applyToPoints(t,this.getShapeGeometry(e).vertices)):new ye})}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(${ve.applyToPoints(ve.Inverse(r),t).map(i=>`${i.x}px ${i.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(ds(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,i)=>{if(!(i&&s))return;const o=Nj(s,i);return o?o.map(E.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((o,a)=>o&&E.Equals(o,r[a])))return t.clone();const i=Nj(r,s);return i?ye.FromPoints(i):void 0}return t})}getShapeAncestors(e,t=[]){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return t;const i=s.parentId;if(ds(i))return t.reverse(),t;const o=this.store.get(i);return o?(t.push(o),this.getShapeAncestors(o,t)):t}findShapeAncestor(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return;const i=s.parentId;if(ds(i))return;const o=this.getShape(i);if(o)return t(o)?o:this.findShapeAncestor(o,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 l;if(e.length===0)return;const r=typeof e[0]=="string"?e:e.map(c=>c.id),s=st(r.map(c=>this.getShape(c)));if(s.length===1){const c=s[0].parentId;return ds(c)?void 0:t?(l=this.findShapeAncestor(s[0],t))==null?void 0:l.id:c}const[i,...o]=s;let a=this.getShapeParent(i);for(;a;){if(t&&!t(a)){a=this.getShapeParent(a);continue}if(o.every(c=>this.hasAncestor(c,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 Rie(this)}getCulledShapes(){const e=this._notVisibleShapes().get(),t=this.getSelectedShapeIds(),r=this.getEditingShapeId(),s=new Set(e);return r&&s.delete(r),t.forEach(i=>{s.delete(i)}),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={}){var x;const r=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:i,margin:o=0,hitLocked:a=!1,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:d=!1}=t;let f=1/0,p=null,m=1/0,y=null;const v=(t.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(b=>{if(b.isLocked&&!a||this.isShapeHidden(b)||this.isShapeOfType(b,"group"))return!1;const C=this.getShapeMask(b);return C&&!$s(e,C)?!1:i?i(b):!0});for(let b=v.length-1;b>=0;b--){const C=v[b],I=this.getShapeGeometry(C),_=I instanceof bi,T=this.getPointInShapeSpace(C,e);if(this.isShapeOfType(C,"frame")||this.isShapeOfType(C,"arrow")&&C.props.text.trim()||(this.isShapeOfType(C,"note")||this.isShapeOfType(C,"geo")&&C.props.fill==="none")&&((x=this.getShapeUtil(C).getText(C))!=null&&x.trim())){for(const R of I.children)if(R.isLabel&&R.isPointInBounds(T))return C}if(this.isShapeOfType(C,"frame")){const R=I.distanceToPoint(T,c);if(Math.abs(R)<=o)return y||C;if(I.hitTestPoint(T,0,!0))return y||p||(d?C:void 0);continue}let A;if(_){let R=1/0;for(const j of I.children){if(j.isLabel&&!l)continue;const K=j.distanceToPoint(T,c);K<R&&(R=K)}A=R}else o===0&&(I.bounds.w<1||I.bounds.h<1)||I.bounds.containsPoint(T,o)?A=I.distanceToPoint(T,c):A=1/0;if(I.isClosed){if(A<=o){if(I.isFilled||_&&I.children[0].isFilled)return y||C;if(this.getShapePageBounds(C).contains(s))continue;if(Math.abs(A)<o)Math.abs(A)<m&&(m=Math.abs(A),y=C);else if(!y){const{area:R}=I;R<f&&(f=R,p=C)}}}else if(A<this.options.hitTestMargin/r)return C}return y||p||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:i=0}=r,o=typeof e=="string"?e:e.id,a=this.getShapeMask(o);return a&&!$s(t,a)?!1:this.getShapeGeometry(o).hitTestPoint(this.getPointInShapeSpace(e,t),i,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 E(0,0);if(ds(s.parentId))return E.From(t);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(t):E.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++)k6(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(ps(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||!ps(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 i=!1;if(s.parentId===t)i=!0;else{let o=this.getShape(s.parentId);e:for(;o;){if(o.parentId===t){i=!0;break e}o=this.getShape(o.parentId)}}return i}getAncestorPageId(e){const t=typeof e=="string"?e:e==null?void 0:e.id,r=t&&this.getShape(t);if(r)return ds(r.parentId)?r.parentId:this.getAncestorPageId(this.getShape(r.parentId))}reparentShapes(e,t,r){const s=typeof e[0]=="string"?e:e.map(p=>p.id);if(s.length===0)return this;const i=[],o=ds(t)?ve.Identity():this.getShapePageTransform(t),a=o.rotation();let l=[];const c=st(this.getSortedChildIdsForParent(t).map(p=>this.getShape(p)));if(r){const p=c.find(m=>m.index===r);if(p){const m=c[c.indexOf(p)+1];m?l=jd(r,m.index,s.length):l=Mw(r,s.length)}else{const m=c.sort(Qn).find(y=>y.index>r);m?l=jd(r,m.index,s.length):l=Mw(r,s.length)}}else{const p=c.length&&c[c.length-1];l=p?Mw(p.index,s.length):Yf(s.length)}const d=o.clone().invert(),f=st(s.map(p=>this.getShape(p))).sort(Qn);return this.run(()=>{for(let p=0;p<f.length;p++){const m=f[p],y=this.getShapePageTransform(m);if(!y)continue;const v=y.point();if(!v)continue;const x=d.applyToPoint(v),b=y.rotation()-a;i.push({id:m.id,type:m.type,parentId:t,x:x.x,y:x.y,rotation:b,index:l[p]})}this.updateShapes(i)},{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 To(s.index)}getSortedChildIdsForParent(e){const t=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[t];return r||Si}visitDescendants(e,t){const r=typeof e=="string"?e:e.id,s=this.getSortedChildIdsForParent(r);for(const i of s)t(i)!==!1&&this.visitDescendants(i,t);return this}getShapeAndDescendantIds(e){const t=new Set;for(const r of e.map(s=>this.getShape(s)).sort(Qn))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 i=r[s];if(this.isShapeHidden(i)||this.getSelectedShapeIds().includes(i.id)||!this.getShapeUtil(i).canDropShapes(i,t)||t.find(a=>a.id===i.id||this.hasAncestor(i,a.id)))continue;const o=this.getShapeMaskedPageBounds(i.id);if(o&&o.containsPoint(e)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,e),0,!0))return i}}getOutermostSelectableShape(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);let i=s,o=s;const a=this.getFocusedGroup();for(;o;){if(this.isShapeOfType(o,"group")&&(a==null?void 0:a.id)!==o.id&&!this.hasAncestor(a,o.id)&&((t==null?void 0:t(o))??!0))i=o;else if((a==null?void 0:a.id)===o.id)break;o=this.getShapeParent(o)}return i}_getBindingsIndexCache(){const e=Aie(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)??Si;return t?s.filter(i=>i.type===t):s}createBindings(e){const t=[];for(const r of e){const s=this.getShape(r.fromId),i=this.getShape(r.toId);if(!s||!i||!this.canBindShapes({fromShape:s,toShape:i,binding:r}))continue;const a=this.getBindingUtil(r.type).getDefaultProps(),l=this.store.schema.types.binding.create({...r,id:r.id??Hc(),props:{...a,...r.props}});t.push(l)}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 i=xo(s,r);if(i===s)continue;const o=this.getShape(i.fromId),a=this.getShape(i.toId);!o||!a||this.canBindShapes({fromShape:o,toShape:a,binding:i})&&t.push(i)}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,i;for(const o of r){const a=this.getBinding(o);if(!a)continue;const l=this.getBindingUtil(a);(s=l.onBeforeIsolateFromShape)==null||s.call(l,{binding:a,removedShape:this.getShape(a.toId)}),(i=l.onBeforeIsolateToShape)==null||i.call(l,{binding:a,removedShape:this.getShape(a.fromId)}),this.store.remove([o])}}):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,i=typeof t=="string"?t:t.type,o=typeof r=="string"?r:r.type,a={fromShapeType:s,toShapeType:i,bindingType:o};return s===i?this.getShapeUtil(s).canBind(a):this.getShapeUtil(s).canBind(a)&&this.getShapeUtil(i).canBind(a)}rotateShapesBy(e,t,r){const s=typeof e[0]=="string"?e:e.map(o=>o.id);if(s.length<=0)return this;const i=Qz({editor:this,ids:s});return i?(iy({delta:t,snapshot:i,editor:this,stage:"one-off",centerOverride:r==null?void 0:r.center}),this):this}getChangesToTranslateShape(e,t){var l,c,d;let r=e;const s=this.getShapeUtil(e),i=(l=s.onTranslateStart)==null?void 0:l.call(s,r);i&&(r=xo(r,i)),r=xo(r,{id:e.id,type:e.type,x:t.x,y:t.y});const o=(c=s.onTranslate)==null?void 0:c.call(s,e,r);o&&(r=xo(r,o));const a=(d=s.onTranslateEnd)==null?void 0:d.call(s,e,r);return a&&(r=xo(r,a)),r}nudgeShapes(e,t){const r=typeof e[0]=="string"?e:e.map(i=>i.id);if(r.length<=0)return this;const s=[];for(const i of r){const o=this.getShape(i),a=E.From(t),l=this.getShapeParentTransform(o);l&&a.rot(-l.rotation()),s.push(this.getChangesToTranslateShape(o,a.add(o)))}return this.updateShapes(s),this}duplicateShapes(e,t){return this.run(()=>{const r=typeof e[0]=="string"?e:e.map(p=>p.id);if(r.length<=0)return this;const s=new Set(r),i=this.getShapeAndDescendantIds(r),o=[...i].reverse(),a=new Map;for(const p of i)a.set(p,Dt());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=Qj(this,i,p=>{const m=[];for(const v of p){const x=this.getBinding(v);if(!x)continue;const b=Hc();m.push({...x,id:b,fromId:Nr(a.get(x.fromId)),toId:Nr(a.get(x.toId))})}const y=[];for(const v of o){const x=Nr(a.get(v)),b=this.getShape(v);if(!b)continue;let C=0,I=0;if(t&&s.has(v)){const _=this.getShapeParentTransform(b),T=new E(t.x,t.y).rot(-_.rotation());C=T.x,I=T.y}y.push({shape:{...b,id:x,x:b.x+C,y:b.y+I,index:"a1",parentId:a.get(b.parentId)??b.parentId},originalShape:b})}return{shapesToCreateWithOriginals:y,bindingsToCreate:m}});l.forEach(({shape:p,originalShape:m})=>{const y=m.parentId,v=this.getSortedChildIdsForParent(y),x=v.indexOf(m.id),b=v[x+1],C=b?this.getShape(b):void 0,I=Gf(m.index,C==null?void 0:C.index);p.index=I});const d=l.map(({shape:p})=>p);if(d.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Pm(this);return}if(this.createShapes(d),this.createBindings(c),this.setSelectedShapes(st(r.map(p=>a.get(p)))),t!==void 0){const p=this.getSelectionPageBounds(),m=this.getViewportPageBounds();p&&!m.contains(p)&&this.centerOnPoint(p.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 i=this.getContentFromCurrentPage(r);if(!i)return this;if(this.getPageShapeIds(t).size+i.shapes.length>this.options.maxShapesPerPage)return Pm(this,t),this;const o=this.getCamera().z;return this.run(()=>{this.deleteShapes(r),this.setCurrentPage(t),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(i,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:o}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(e){const t=typeof e[0]=="string"?e:e.map(o=>o.id);if(this.getIsReadonly()||t.length===0)return this;let r=!0,s=!0;const i=[];for(const o of t){const a=this.getShape(o);a&&(i.push(a),a.isLocked?s=!1:r=!1)}return this.run(()=>{s?(this.updateShapes(i.map(o=>({id:o.id,type:o.type,isLocked:!0}))),this.setSelectedShapes([])):r?this.updateShapes(i.map(o=>({id:o.id,type:o.type,isLocked:!1}))):this.updateShapes(i.map(o=>({id:o.id,type:o.type,isLocked:!0})))}),this}sendToBack(e){const t=typeof e[0]=="string"?e:e.map(s=>s.id),r=bm(this,"toBack",t,{considerAllShapes:!0});return r&&this.updateShapes(r),this}sendBackward(e,t={}){const r=typeof e[0]=="string"?e:e.map(i=>i.id),s=bm(this,"backward",r,t);return s&&this.updateShapes(s),this}bringForward(e,t={}){const r=typeof e[0]=="string"?e:e.map(i=>i.id),s=bm(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=bm(this,"toFront",t);return r&&this.updateShapes(r),this}collectShapesViaArrowBindings(e){const{initialShapes:t,resultShapes:r,resultBounds:s,bindings:i,visited:o}=e;for(const a of i)for(const l of[a.fromId,a.toId])if(!o.has(l)){const c=t.find(d=>d.id===l);if(c&&!o.has(c.id)){o.add(c.id);const d=this.getShapePageBounds(c);if(!d)continue;r.push(c),s.push(d),this.collectShapesViaArrowBindings({...e,bindings:this.getBindingsInvolvingShape(c,"arrow")})}}}flipShapes(e,t){if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(l=>l.id),s=st(r.map(l=>this.getShape(l)));for(const l of s)if(this.isShapeOfType(l,"group")){const c=st(this.getSortedChildIdsForParent(l.id).map(d=>this.getShape(d)));s.push(...c)}const i=[],o=[];for(const l of s){const c=this.getShapeUtil(l);if(!c.canBeLaidOut(l,{type:"flip",shapes:s}))continue;const d=this.getShapePageBounds(l),f=this.getShapeGeometry(l).bounds,p=this.getShapePageTransform(l.id);d&&f&&p&&(i.push({shape:l,localBounds:f,pageTransform:p,isAspectRatioLocked:c.isAspectRatioLocked(l)}),o.push(d))}if(!i.length)return this;const a=ye.Common(o).center;return this.run(()=>{for(const{shape:l,localBounds:c,pageTransform:d,isAspectRatioLocked:f}of i)this.resizeShape(l.id,{x:t==="horizontal"?-1:1,y:t==="vertical"?-1:1},{initialBounds:c,initialPageTransform:d,initialShape:l,isAspectRatioLocked:f,mode:"scale_shape",scaleOrigin:a,scaleAxisRotation:0})}),this}stackShapes(e,t,r){var x,b;const s=typeof e[0]=="string"?e:e.map(C=>C.id);if(this.getIsReadonly())return this;const i=st(s.map(C=>this.getShape(C))),o=[],a=new Set;for(const C of i){if(a.has(C.id))continue;a.add(C.id);const I=this.getShapePageBounds(C);if(!I||!((b=(x=this.getShapeUtil(C)).canBeLaidOut)!=null&&b.call(x,C,{type:"stack",shapes:i})))continue;const _=[C],T=[I];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(C.id,"arrow"),initialShapes:i,resultShapes:_,resultBounds:T,visited:a});const A=ye.Common(T);A&&o.push({shapes:_,pageBounds:A})}const l=o.length;if(r===0&&l<3||l<2)return this;let c,d,f,p;t==="horizontal"?(c="x",d="minX",f="maxX",p="width"):(c="y",d="minY",f="maxY",p="height");let m=0;if(r===0){const C={};o.sort((_,T)=>_.pageBounds[d]-T.pageBounds[d]);for(let _=0;_<l-1;_++){const T=o[_],R=o[_+1].pageBounds[d]-T.pageBounds[f];C[R]||(C[R]=0),C[R]++}let I=1;for(const[_,T]of Object.entries(C))T>I&&(I=T,m=parseFloat(_));if(I===1){let _=0;for(const[T,A]of Object.entries(C))m+=parseFloat(T)*A,_+=A;m/=_}}else m=r;const y=[];let v=o[0].pageBounds[f];for(let C=1;C<o.length;C++){const{shapes:I,pageBounds:_}=o[C],T=new E;T[c]=v+m-_[c];for(const A of I){const R=T.clone(),j=this.getShapeParent(A);if(j){const K=this.getShapePageTransform(j);K&&R.rot(-K.rotation())}R.add(A),y.push(this.getChangesToTranslateShape(A,R))}v+=_[p]+m}return this.updateShapes(y),this}packShapes(e,t){var _,T;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(A=>A.id),s=st(r.map(A=>this.getShape(A))),i=[],o=[],a=new Set;for(const A of s){if(a.has(A.id))continue;a.add(A.id);const R=this.getShapePageBounds(A);if(!R||!((T=(_=this.getShapeUtil(A)).canBeLaidOut)!=null&&T.call(_,A,{type:"pack",shapes:s})))continue;const j=[A],K=[R];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(A.id,"arrow"),initialShapes:s,resultShapes:j,resultBounds:K,visited:a});const U=ye.Common(K);U&&(i.push({shapes:j,pageBounds:U,nextPageBounds:U.clone()}),o.push(U))}if(i.length<2)return this;let l=0;for(const{pageBounds:A}of i)l+=A.width*A.height;const c=ye.Common(o),d=c.width;i.sort((A,R)=>A.pageBounds.width-R.pageBounds.width).sort((A,R)=>A.pageBounds.height-R.pageBounds.height);const f=Math.max(Math.ceil(Math.sqrt(l/.95)),d),p=[new ye(c.x,c.y,f,1/0)];let m=0,y=0,v,x;for(const{nextPageBounds:A}of i)for(let R=p.length-1;R>=0;R--)if(v=p[R],!(A.width>v.width||A.height>v.height)){A.x=v.x,A.y=v.y,y=Math.max(y,A.maxY),m=Math.max(m,A.maxX),A.width===v.width&&A.height===v.height?(x=p.pop(),R<p.length&&(p[R]=x)):A.height===v.height?(v.x+=A.width+t,v.width-=A.width+t):A.width===v.width?(v.y+=A.height+t,v.height-=A.height+t):(p.push(new ye(v.x+(A.width+t),v.y,v.width-(A.width+t),A.height)),v.y+=A.height+t,v.height-=A.height+t);break}const b=ye.Common(i.map(A=>A.nextPageBounds)),C=E.Sub(c.center,b.center),I=[];for(const{shapes:A,pageBounds:R,nextPageBounds:j}of i){const K=E.Sub(j.point,R.point).add(C);for(const U of A){const J=K.clone();if(this.getShapeParent(U)){const N=this.getShapeParentTransform(U);N&&J.rot(-N.rotation())}J.add(U),I.push(this.getChangesToTranslateShape(U,J))}}return I.length&&this.updateShapes(I),this}alignShapes(e,t){var d,f;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(p=>p.id),s=st(r.map(p=>this.getShape(p))),i=[],o=[],a=new Set;for(const p of s){if(a.has(p.id))continue;a.add(p.id);const m=this.getShapePageBounds(p);if(!m||!((f=(d=this.getShapeUtil(p)).canBeLaidOut)!=null&&f.call(d,p,{type:"align",shapes:s})))continue;const y=[p],v=[m];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(p.id,"arrow"),initialShapes:s,resultShapes:y,resultBounds:v,visited:a});const x=ye.Common(v);x&&(i.push({shapes:y,pageBounds:x}),o.push(x))}if(i.length<2)return this;const l=ye.Common(o),c=[];return i.forEach(({shapes:p,pageBounds:m})=>{const y=new E;switch(t){case"top":{y.y=l.minY-m.minY;break}case"center-vertical":{y.y=l.midY-m.minY-m.height/2;break}case"bottom":{y.y=l.maxY-m.minY-m.height;break}case"left":{y.x=l.minX-m.minX;break}case"center-horizontal":{y.x=l.midX-m.minX-m.width/2;break}case"right":{y.x=l.maxX-m.minX-m.width;break}}for(const v of p){const x=y.clone(),b=this.getShapeParent(v);if(b){const C=this.getShapePageTransform(b);C&&x.rot(-C.rotation())}x.add(v),c.push(this.getChangesToTranslateShape(v,x))}}),this.updateShapes(c),this}distributeShapes(e,t){var I,_;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(T=>T.id),s=st(r.map(T=>this.getShape(T))),i=[],o=new Set;for(const T of s){if(o.has(T.id))continue;o.add(T.id);const A=this.getShapePageBounds(T);if(!A||!((_=(I=this.getShapeUtil(T)).canBeLaidOut)!=null&&_.call(I,T,{type:"distribute",shapes:s})))continue;const R=[T],j=[A];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(T.id,"arrow"),initialShapes:s,resultShapes:R,resultBounds:j,visited:o});const K=ye.Common(j);K&&i.push({shapes:R,pageBounds:K})}if(i.length<3)return this;let a,l,c,d;t==="horizontal"?(a="x",l="minX",c="maxX",d="width"):(a="y",l="minY",c="maxY",d="height");const f=[],p=i.sort((T,A)=>T.pageBounds[l]-A.pageBounds[l])[0],m=i.sort((T,A)=>A.pageBounds[c]-T.pageBounds[c])[0];if(p===m){const T=new Set(p.shapes.map(A=>A.id));return this.distributeShapes(r.filter(A=>!T.has(A)),t)}const y=i.filter(T=>T!==p&&T!==m).sort((T,A)=>T.pageBounds[l]===A.pageBounds[l]?T.shapes[0].id<A.shapes[0].id?-1:1:T.pageBounds[l]-A.pageBounds[l]),v=p.pageBounds[c],x=m.pageBounds[l]-v,b=y.reduce((T,A)=>T+A.pageBounds[d],0),C=(x-b)/(y.length+1);for(let T=v+C,A=0;A<y.length;A++){const{shapes:R,pageBounds:j}=y[A],K=new E;K[a]=T-j[a],T+j[d]>m.pageBounds[c]-1&&(K[a]=m.pageBounds[c]-j[c]-1);for(const U of R){const J=K.clone(),z=this.getShapeParent(U);if(z){const N=this.getShapePageTransform(z);N&&J.rot(-N.rotation())}J.add(U),f.push(this.getChangesToTranslateShape(U,J))}T+=j[d]+C}return this.updateShapes(f),this}stretchShapes(e,t){var p,m;const r=typeof e[0]=="string"?e:e.map(y=>y.id);if(this.getIsReadonly())return this;const s=st(r.map(y=>this.getShape(y))).filter(y=>{var v;return((v=this.getShapePageTransform(y))==null?void 0:v.rotation())%(xt/2)===0}),i=[],o=[],a=new Set;for(const y of s){if(a.has(y.id))continue;a.add(y.id);const v=this.getShapePageBounds(y);if(!v)continue;const x=[y],b=[v];if(!((m=(p=this.getShapeUtil(y)).canBeLaidOut)!=null&&m.call(p,y,{type:"stretch",shapes:s})))continue;this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(y.id,"arrow"),initialShapes:s,resultShapes:x,resultBounds:b,visited:a});const C=ye.Common(b);C&&(i.push({shapes:x,pageBounds:C}),o.push(C))}if(i.length<2)return this;const l=ye.Common(o);let c,d,f;return t==="horizontal"?(c="x",d="minX",f="width"):(c="y",d="minY",f="height"),this.run(()=>{i.forEach(({shapes:y,pageBounds:v})=>{const x=new E;x[c]=l[d]-v[d];const b=v.center.clone();b[c]=l[d];const C=new E(1,1);C[c]=l[f]/v[f];for(const I of y){const _=x.clone(),T=this.getShapeParentTransform(I);T&&x.rot(-T.rotation()),_.add(I);const A=this.getChangesToTranslateShape(I,_);this.updateShape(A),this.resizeShape(I.id,C,{initialBounds:this.getShapeGeometry(I).bounds,scaleOrigin:b,isAspectRatioLocked:this.getShapeUtil(I).isAspectRatioLocked(I),scaleAxisRotation:0})}})}),this}resizeShape(e,t,r={}){var y,v,x;const s=typeof e=="string"?e:e.id;if(this.getIsReadonly())return this;Number.isFinite(t.x)||(t=new E(1,t.y)),Number.isFinite(t.y)||(t=new E(t.x,1));const i=r.initialShape??this.getShape(s);if(!i)return this;const o=r.scaleOrigin??((y=this.getShapePageBounds(s))==null?void 0:y.center);if(!o)return this;const a=r.initialPageTransform?ve.Cast(r.initialPageTransform):this.getShapePageTransform(s);if(!a)return this;const l=a.rotation();if(l==null)return this;const c=r.scaleAxisRotation??l,d=r.initialBounds??this.getShapeGeometry(s).bounds;if(!d)return this;const f=r.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!tF(l,c))return this._resizeUnalignedShape(s,t,{...r,initialBounds:d,scaleOrigin:o,scaleAxisRotation:c,initialPageTransform:a,isAspectRatioLocked:f,initialShape:i});const p=this.getShapeUtil(i);f&&(Math.abs(t.x)>Math.abs(t.y)?t=new E(t.x,Math.sign(t.y)*Math.abs(t.x)):t=new E(Math.sign(t.x)*Math.abs(t.y),t.y));let m=!1;if(p.onResize&&p.canResize(i)){const b=this._scalePagePoint(ve.applyToPoint(a,new E(0,0)),o,t,c),C=this.getPointInParentSpace(i.id,b),I=new E(t.x,t.y),_=Al((l-c)%Math.PI,0);I.x=_?t.x:t.y,I.y=_?t.y:t.x;const T=ve.applyToPoint(a,new E),{x:A,y:R}=this.getPointInParentSpace(i.id,T);let j=i;r.skipStartAndEndCallbacks||(j=xo(i,((v=p.onResizeStart)==null?void 0:v.call(p,i))??void 0));const K=p.onResize({...i,x:A,y:R},{newPoint:C,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:I.x,scaleY:I.y,initialBounds:d,initialShape:i});K&&(m=!0),j=xo(j,{id:s,type:i.type,x:C.x,y:C.y,...K}),r.skipStartAndEndCallbacks||(j=xo(j,((x=p.onResizeEnd)==null?void 0:x.call(p,i,j))??void 0)),this.updateShapes([j])}if(!m){const b=ve.applyToPoint(a,d.center),C=this._scalePagePoint(b,o,t,c),I=this.getPointInParentSpace(i.id,b),_=this.getPointInParentSpace(i.id,C),T=E.Sub(_,I);this.updateShapes([{id:s,type:i.type,x:i.x+T.x,y:i.y+T.y}])}return this}_scalePagePoint(e,t,r,s){const i=E.RotWith(e,t,-s).sub(t),o=E.MulV(i,r);return E.Add(o,t).rotWith(t,s)}_resizeUnalignedShape(e,t,r){const{type:s}=r.initialShape,i=new E(t.x,t.y);if(Math.abs(t.x)>Math.abs(t.y)?i.x=Math.sign(t.x)*Math.abs(t.y):i.y=Math.sign(t.y)*Math.abs(t.x),this.resizeShape(e,i,{initialShape:r.initialShape,initialBounds:r.initialBounds,isAspectRatioLocked:r.isAspectRatioLocked}),Math.sign(t.x)*Math.sign(t.y)<0){let{rotation:x}=ve.Decompose(r.initialPageTransform);x-=2*x,this.updateShapes([{id:e,type:s,rotation:x}])}const o=ve.applyToPoint(r.initialPageTransform,r.initialBounds.center),a=this._scalePagePoint(o,r.scaleOrigin,t,r.scaleAxisRotation),l=this.getShapePageBounds(e),c=this.getShapePageTransform(e),d=l.center,f=c.point();if(!d||!f)return this;const p=E.Sub(a,d),m=E.Add(f,p),{x:y,y:v}=this.getPointInParentSpace(e,m);return this.updateShapes([{id:e,type:s,x:y,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 Pm(this),this;const s=this.getFocusedGroupId();return this.run(()=>{var d,f;const i=this.getCurrentPageShapesSorted(),o=e.map(p=>{if(p.id||(p={id:Dt(),...p}),!p.parentId||!(this.store.has(p.parentId)||e.some(m=>m.id===p.parentId))){let m=this.getFocusedGroupId();for(let v=i.length-1;v>=0;v--){const x=i[v];if(!this.isShapeHidden(x)&&this.getShapeUtil(x).canReceiveNewChildrenOfType(x,p.type)&&this.isPointInShape(x,{x:p.x??0,y:p.y??0},{margin:0,hitInside:!0})){m=x.id;break}}const y=p.parentId;if(m===p.id&&(m=s),m!==y&&(p={...p},p.parentId=m,ps(m))){const v=this.getPointInShapeSpace(this.getShape(m),{x:p.x??0,y:p.y??0});p.x=v.x,p.y=v.y,p.rotation=-this.getShapePageTransform(m).rotation()+(p.rotation??0)}}return p}),a=new Map,l=[],{opacityForNextShape:c}=this.getInstanceState();for(const p of o){const m=this.getShapeUtil(p);let y=p.index;if(!y){const C=p.parentId??s;a.has(C)||a.set(C,this.getHighestIndexForParent(C)),y=a.get(C),a.set(C,To(y))}const v=m.getDefaultProps();for(const[C,I]of this.styleProps[p.type])v[I]=this.getStyleForNextShape(C);let x=this.store.schema.types.shape.create({...p,index:y,opacity:p.opacity??c,parentId:p.parentId??s,props:"props"in p?{...v,...p.props}:v});if(x.index===void 0)throw Error("no index!");const b=(f=(d=this.getShapeUtil(x)).onBeforeCreate)==null?void 0:f.call(d,x);b&&(x=b),l.push(x)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)}),this}animateShape(e,t={animation:sC}){return this.animateShapes([e],t)}animateShapes(e,t={animation:sC}){if(!t.animation)return this;const{duration:r=500,easing:s=$n.linear}=t.animation,i=_t();let o=r,a;const l=[];let c,d;for(let p=0,m=e.length;p<m;p++){if(c=e[p],!c)continue;const y=this.getShape(c.id);y&&(d={start:Yt(y),end:xo(Yt(y),c)},l.push(d),this.animatingShapes.set(y.id,i))}const f=p=>{var x,b;if(o-=p,o<0){const{animatingShapes:C}=this,I=e.filter(_=>_&&C.get(_.id)===i);I.length&&this.updateShapes(I),this.off("tick",f);return}a=s(1-o/r);const{animatingShapes:m}=this,y=[];let v;for(let C=0,I=l.length;C<I;C++){const{start:_,end:T}=l[C];v=m.get(_.id),v===i&&y.push({...T,x:_.x+(T.x-_.x)*a,y:_.y+(T.y-_.y)*a,opacity:_.opacity+(T.opacity-_.opacity)*a,rotation:_.rotation+(T.rotation-_.rotation)*a,props:((b=(x=this.getShapeUtil(T)).getInterpolatedProps)==null?void 0:b.call(x,_,T,a))??T.props})}this._updateShapes(y)};return this.on("tick",f),this}groupShapes(e,t={}){var y;const{groupId:r=Dt(),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 i=typeof e[0]=="string"?e:e.map(v=>v.id);if(i.length<=1)return this;const o=st((this._shouldIgnoreShapeLock?i:this._getUnlockedShapeIds(i)).map(v=>this.getShape(v))),a=o.sort(Qn).map(v=>v.id),l=ye.Common(st(o.map(v=>this.getShapePageBounds(v)))),{x:c,y:d}=l.point,f=this.findCommonAncestor(o)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const p=o.filter(v=>v.parentId===f).sort(Qn),m=(y=p[p.length-1])==null?void 0:y.index;return this.run(()=>{this.createShapes([{id:r,type:"group",parentId:f,index:m,x:c,y:d,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(l=>l.id),i=st((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(l=>this.getShape(l)));if(i.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const o=new Set,a=[];return i.forEach(l=>{this.isShapeOfType(l,"group")?a.push(l):o.add(l.id)}),a.length===0?this:(this.run(()=>{let l;for(let c=0,d=a.length;c<d;c++){l=a[c];const f=this.getSortedChildIdsForParent(l.id);for(let p=0,m=f.length;p<m;p++)o.add(f[p]);this.reparentShapes(f,l.parentId,l.index)}this.deleteShapes(a.map(c=>c.id)),r&&this.select(...o)}),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 i=e[r];if(!i)continue;const o=this.getShape(i.id);if(o){if(!this._shouldIgnoreShapeLock){if(o.isLocked){if(!(Object.hasOwn(i,"isLocked")&&!i.isLocked))continue}else if(this.isShapeOrAncestorLocked(o))continue}this.animatingShapes.delete(i.id),t.push(i)}}return this._updateShapes(t),this}_updateShapes(e){this.getIsReadonly()||this.run(()=>{var i,o;const t=[];let r,s;for(let a=0,l=e.length;a<l;a++){const c=e[a];c&&(r=this.getShape(c.id),r&&(s=xo(r,c),s!==r&&(s=((o=(i=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:o.call(i,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(i=>i.id),r=this._shouldIgnoreShapeLock?t:this._getUnlockedShapeIds(t);if(r.length===0)return this;const s=new Set(r);for(const i of r)this.visitDescendants(i,o=>{s.add(o)});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,i=r.length;s<i;s++)this._extractSharedStyles(this.getShape(r[s]),t)}else for(const[r,s]of this.styleProps[e.type])t.applyValue(r,On(e.props,s))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),t=new fE;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 On(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),t=new fE;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 i=this.getShape(s);if(i)if(this.isShapeOfType(i,"group"))for(const o of this.getSortedChildIdsForParent(i.id))t(o);else e.push(i)};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=i=>{if(this.isShapeOfType(i,"group")){const o=this.getSortedChildIdsForParent(i);for(const a of o)s(this.getShape(a))}else r.push(i)};for(const i of t)s(i);this.updateShapes(r.map(i=>({id:i.id,type:i.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=[],i=o=>{if(this.isShapeOfType(o,"group")){const a=this.getSortedChildIdsForParent(o.id);for(const l of a)i(this.getShape(l))}else{const a=this.getShapeUtil(o),l=this.styleProps[o.type].get(e);if(l){const c={id:o.id,type:o.type,props:{[l]:t}};s.push({util:a,originalShape:o,updatePartial:c})}}};for(const o of r)i(o);this.updateShapes(s.map(({updatePartial:o})=>o))}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 Qj(this,r,s=>{const i=[];for(const d of s){const f=this.getBinding(d);f&&i.push(f)}const o=[],a=[];for(const d of r){const f=this.getShape(d);if(!f)continue;if(!r.has(f.parentId)){const m=this.getShapePageTransform(f.id),y=m.point();a.push({...f,x:y.x,y:y.y,rotation:m.rotation(),parentId:this.getCurrentPageId()}),o.push(f.id)}else a.push(f)}const l=[],c=new Set;for(const d of a){if(!("assetId"in d.props))continue;const f=d.props.assetId;if(!f||c.has(f))continue;c.add(f);const p=this.getAsset(f);p&&l.push(p)}return{schema:this.store.schema.serialize(),shapes:a,rootShapeIds:o,bindings:i,assets:l}})}async resolveAssetsInContent(e){if(!e)return;const t=[];return await Promise.allSettled(e.assets.map(async r=>{var s,i,o;if((r.type==="image"||r.type==="video")&&!((s=r.props.src)!=null&&s.startsWith("data:image"))&&!((i=r.props.src)!=null&&i.startsWith("data:video"))&&!((o=r.props.src)!=null&&o.startsWith("http"))){const a=Yt(r),l=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await zr.blobToDataUrl(await Vi(l).then(c=>c.blob())),t.push(a)}else t.push(r)})),e.assets=t,e}putContentOntoCurrentPage(e,t={}){var U,J,z;if(this.getIsReadonly())return this;if(!e.schema)throw Error(`Could not put content:
205
+ content is missing a schema.`);const{select:r=!1,preserveIds:s=!1,preservePosition:i=!1}=t;let{point:o=void 0}=t;const a=this.getCurrentPageId(),{rootShapeIds:l}=e,c=[],d=[],f=[],p={store:{...Object.fromEntries(e.assets.map(N=>[N.id,N])),...Object.fromEntries(e.shapes.map(N=>[N.id,N])),...Object.fromEntries(((U=e.bindings)==null?void 0:U.map(N=>[N.id,N]))??[])},schema:e.schema},m=this.store.schema.migrateStoreSnapshot(p);if(m.type==="error")throw Error("Could not put content: could not migrate content");for(const N of Object.values(m.value))switch(N.typeName){case"asset":{c.push(N);break}case"shape":{d.push(N);break}case"binding":{f.push(N);break}}const y=new Map(s?d.map(N=>[N.id,N.id]):d.map(N=>[N.id,Dt()])),v=new Map(s?f.map(N=>[N.id,N.id]):f.map(N=>[N.id,Hc()]));let x=this.getCurrentPageId(),b=1/0,C=[];for(const N of this.getSelectedShapes()){if(b===0)break;const L=this.isShapeOfType(N,"frame"),V=this.getShapeAncestors(N);L&&V.push(N);const X=L?V.length+1:V.length;if(X<b)b=X,C=V,x=L?N.id:N.parentId;else if(X===b){if(C.length!==V.length)throw Error(`Ancestors: ${C.length} !== ${V.length}`);if(C.length===0){x=a;break}else{x=a;for(let W=0;W<C.length&&V[W]===C[W];W++)x=V[W].id}}}let I=!1;if(!ds(x)){const N=this.getShape(x);if(N){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(N)))x=a;else if(l.length===1){const L=d.find(V=>V.id===l[0]);this.isShapeOfType(N,"frame")&&this.isShapeOfType(L,"frame")&&L.props.w===(N==null?void 0:N.props.w)&&L.props.h===(N==null?void 0:N.props.h)&&(I=!0)}}else x=a}I||(I=y.has(x)),I&&(x=this.getShape(x).parentId);let _=this.getHighestIndexForParent(x);const T=[],A=d.map(N=>{const L=y.get(N.id),V={...N,id:L};return l.includes(N.id)&&(V.parentId=a,T.push(V)),y.has(V.parentId)?V.parentId=y.get(N.parentId):(l.push(V.id),V.index=_,_=To(_)),V});if(A.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Pm(this),this;const R=f.map(N=>({...N,id:Nr(v.get(N.id)),fromId:Nr(y.get(N.fromId)),toId:Nr(y.get(N.toId))})),j=[],K=[];for(const N of c)this.store.has(N.id)||((N.type==="image"&&((J=N.props.src)!=null&&J.startsWith("data:image"))||N.type==="video"&&((z=N.props.src)!=null&&z.startsWith("data:video")))&&(K.push(Yt(N)),N.props.src=null),j.push(N));return Promise.allSettled(K.map(async N=>{const L=await bie(N.props.src,N.props.name,N.props.mimeType??"image/png"),V=await this.getAssetForExternalContent({type:"file",file:L,assetId:N.id});if(!V){this.deleteAssets([N.id]);return}this.updateAssets([{...V,id:N.id}])})),this.run(()=>{j.length>0&&this.createAssets(j),this.createShapes(A),this.createBindings(R),r&&this.select(...T.map(W=>W.id)),x!==a&&this.reparentShapes(T.map(W=>W.id),x);const N=A.map(W=>this.getShape(W.id)),L=ye.Common(N.map(W=>this.getShapePageBounds(W)));if(o===void 0)if(ds(x)){const W=this.getViewportPageBounds();i||W.includes(ye.From(L))?o=L.center:o=W.center}else{const W=this.getShape(x);o=ve.applyToPoint(this.getShapePageTransform(W),this.getShapeGeometry(W).bounds.center)}if(T.length===1){const W=T[0];if(this.isShapeOfType(W,"frame"))for(;this.getShapesAtPoint(o).some($=>this.isShapeOfType($,"frame")&&$.props.w===W.props.w&&$.props.h===W.props.h);)o.x+=L.w+16}const V=ye.Common(st(T.map(({id:W})=>this.getShapePageBounds(W)))).center,X=E.Sub(o,V);this.updateShapes(T.map(({id:W})=>{const $=this.getShape(W),G=this.getShapeParentTransform(W).decompose().rotation,re=E.Rot(X,-G);return{id:$.id,type:$.type,x:$.x+re.x,y:$.y+re.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 fie(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:"image/svg+xml"}),width:s.width,height:s.height};case"jpeg":case"png":case"webp":{const i=await vie(s.svg,{type:r.format,quality:r.quality,pixelRatio:r.pixelRatio,width:s.width,height:s.height});if(!i)throw new Error("Could not construct image.");return{blob:i,width:s.width,height:s.height}}default:En(r.format)}}_updateInputsFromEvent(e){const{pointerVelocity:t,previousScreenPoint:r,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:o}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(Lr),{x:l,y:c,z:d}=om(()=>this.getCamera()),f=e.point.x-a.x,p=e.point.y-a.y,m=e.point.z??.5;r.setTo(i),s.setTo(o),i.set(f,p);const y=f/d-l,v=p/d-c;isFinite(y)&&isFinite(v)&&o.set(y,v,m),this.inputs.isPen=e.type==="pointer"&&e.isPen,(e.name==="pointer_down"||this.inputs.isPinching)&&(t.set(0,0),this.inputs.originScreenPoint.setTo(i),this.inputs.originPagePoint.setTo(o)),this.run(()=>{var x;this.store.put([{id:uS,typeName:"pointer",x:o.x,y:o.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===gj.CAMERA_MOVE?((x=this.store.unsafeGetWithoutCapture(uS))==null?void 0:x.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 yse(this.store)}loadSnapshot(e,t){return Pz(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=st(e.shapeIds.map(o=>this.getShape(o))),r={};for(const o of t){const a=this.getAncestorPageId(o);a&&(r[a]??(r[a]=[]),r[a].push(o))}const[s,i]=Object.entries(r).sort(([o,a],[l,c])=>c.length-a.length)[0]??["",[]];if(!s||!i.length)this._zoomToFitPageContentAt100Percent();else{this.setCurrentPage(s);const o=ye.Common(i.map(a=>this.getShapePageBounds(a)));this.zoomToBounds(o,{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:En(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(Eie(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",Pie((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 l,c;const o=((l=e==null?void 0:e.getUrl)==null?void 0:l.call(e,this))??window.location.href;return this.createDeepLink({param:e==null?void 0:e.param,url:o,to:(c=e==null?void 0:e.getTarget)==null?void 0:c.call(e,this)}).toString()}),r=(e==null?void 0:e.onChange)??(()=>{var a;const o=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,o.toString())}),s=cv(o=>o(),(e==null?void 0:e.debounceMs)??500),i=qi("update url on state change",()=>r(new URL(t.get()),this),{scheduleEffect:s});return()=>{i(),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:Cr(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:Cr(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:Cr(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:Cr(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:i}=t;t.isPointing||(t.isDragging=!1);const o=this.store.unsafeGetWithoutCapture(Lr),a=this.store.get(this._getCurrentPageStateId()),l=this._cameraOptions.__unsafe__getWithoutCapture();switch(r){case"pinch":{if(l.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(e),e.name){case"pinch_start":{if(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:c=1},delta:{x:d,y:f}}=e,{x:p,y:m}=E.SubXY(e.point,o.screenBounds.x,o.screenBounds.y);this.stopCameraAnimation(),o.followingUserId&&this.stopFollowingUser();const{x:y,y:v,z:x}=om(()=>this.getCamera()),{panSpeed:b,zoomSpeed:C}=l;this._setCamera(new E(y+d*b/x-p/x+p/(c*C),v+f*b/x-m/x+m/(c*C),c*C),{immediate:!0});return}case"pinch_end":{if(!t.isPinching)return this;t.isPinching=!1;const{_selectedShapeIdsAtPointerDown:c}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,c.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(c)}));return}}}case"wheel":{if(l.isLocked)return;this._updateInputsFromEvent(e);const{panSpeed:c,zoomSpeed:d,wheelBehavior:f}=l;if(f!=="none"){this.stopCameraAnimation(),o.followingUserId&&this.stopFollowingUser();const{x:p,y:m,z:y}=om(()=>this.getCamera()),{x:v,y:x,z:b=0}=e.delta;let C=f;switch(t.ctrlKey&&(C=f==="pan"?"zoom":"pan"),C){case"zoom":{const{x:I,y:_}=this.inputs.currentScreenPoint;let T=b;f==="zoom"&&(Math.abs(x)>10?T=10*Math.sign(x)/100:T=x/100);const A=y+(T??0)*d*y;this._setCamera(new E(p+(I/A-I)-(I/y-I),m+(_/A-_)-(_/y-_),A),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new E(p+v*c/y,m+x*c/y,y),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}break}case"pointer":{if(t.isPinching)return;this._updateInputsFromEvent(e);const{isPen:c}=e,{isPenMode:d}=o;switch(e.name){case"pointer_down":{if(d&&!c)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===mj&&(this.capturedPointerId=e.pointerId),t.buttons.add(e.button),t.isPointing=!0,t.isDragging=!1,!d&&c&&this.updateInstanceState({isPenMode:!0}),e.button===yj?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===Sm&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!c&&d)return;const{x:f,y:p,z:m}=om(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:y,previousScreenPoint:v}=this.inputs,{panSpeed:x}=l,b=E.Sub(y,v);this.setCamera(new E(f+b.x*x/m,p+b.y*x/m,m),{immediate:!0}),this.maybeTrackPerformance("Panning");return}t.isPointing&&!t.isDragging&&E.Dist2(s,i)*this.getZoomLevel()>(o.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/m&&(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),o.isPenMode&&!c)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,p=Math.min(2,f.len());switch(e.button){case mj:{this.setCursor({type:"grab",rotation:0});break}case Sm:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}p>0&&this.slideCamera({speed:p,direction:f})}else e.button===yj&&(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=o.cursor.type),this.inputs.isPanning=!0,this.inputs.isSpacebarPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0})),this.inputs.isSpacebarPanning){let c;switch(e.code){case"ArrowUp":{c=new E(0,-1);break}case"ArrowRight":{c=new E(1,0);break}case"ArrowDown":{c=new E(0,1);break}case"ArrowLeft":{c=new E(-1,0);break}}if(c){const d=this.getViewportPageBounds(),f=d.clone().translate(c.mulV({x:d.w,y:d.h}));this._animateToViewport(f,{animation:{duration:320}})}}break}case"key_up":{t.keys.delete(e.code),e.code==="Space"&&(this.inputs.buttons.has(Sm)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===Sm?e.name="middle_click":e.button===jI&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(Lr);if(e.isPen===c){const d=this._clickManager.handlePointerEvent(e);if(e.name!==d.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(d),this.emit("event",d);return}}}return this.root.handleEvent(e),this.emit("event",e),e.type==="pointer"&&e.name==="pointer_down"&&this.menus.clearOpenMenus(),this}maybeTrackPerformance(e){xn.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}ke=Goe(gE);Ie(ke,1,"getIsShapeHiddenCache",E6,Ee);Ie(ke,1,"getCanUndo",P6,Ee);Ie(ke,1,"getCanRedo",C6,Ee);Ie(ke,1,"getPath",b6,Ee);Ie(ke,1,"getCurrentTool",w6,Ee);Ie(ke,1,"getCurrentToolId",x6,Ee);Ie(ke,1,"getDocumentSettings",v6,Ee);Ie(ke,1,"getInstanceState",S6,Ee);Ie(ke,1,"getOpenMenus",y6,Ee);Ie(ke,1,"getIsMenuOpen",m6,Ee);Ie(ke,1,"getPageStates",g6,Ee);Ie(ke,1,"_getPageStatesQuery",p6,Ee);Ie(ke,1,"getCurrentPageState",f6,Ee);Ie(ke,1,"_getCurrentPageStateId",h6,Ee);Ie(ke,1,"getSelectedShapeIds",d6,Ee);Ie(ke,1,"getSelectedShapes",u6,Ee);Ie(ke,1,"getOnlySelectedShapeId",c6,Ee);Ie(ke,1,"getOnlySelectedShape",l6,Ee);Ie(ke,1,"getSelectionPageBounds",a6,Ee);Ie(ke,1,"getSelectionRotation",o6,Ee);Ie(ke,1,"getSelectionRotatedPageBounds",i6,Ee);Ie(ke,1,"getSelectionRotatedScreenBounds",s6,Ee);Ie(ke,1,"getFocusedGroupId",r6,Ee);Ie(ke,1,"getFocusedGroup",n6,Ee);Ie(ke,1,"getEditingShapeId",t6,Ee);Ie(ke,1,"getEditingShape",e6,Ee);Ie(ke,1,"getRichTextEditor",QB,Ee);Ie(ke,1,"getHoveredShapeId",JB,Ee);Ie(ke,1,"getHoveredShape",ZB,Ee);Ie(ke,1,"getHintingShapeIds",XB,Ee);Ie(ke,1,"getHintingShape",YB,Ee);Ie(ke,1,"getErasingShapeIds",GB,Ee);Ie(ke,1,"getErasingShapes",qB,Ee);Ie(ke,1,"_unsafe_getCameraId",VB,Ee);Ie(ke,1,"getCamera",WB,Ee);Ie(ke,1,"getViewportPageBoundsForFollowing",KB,Ee);Ie(ke,1,"getCameraForFollowing",HB,Ee);Ie(ke,1,"getZoomLevel",UB,Ee);Ie(ke,1,"getViewportScreenBounds",BB,Ee);Ie(ke,1,"getViewportScreenCenter",$B,Ee);Ie(ke,1,"getViewportPageBounds",zB,Ee);Ie(ke,1,"_getCollaboratorsQuery",FB,Ee);Ie(ke,1,"getCollaborators",LB,Ee);Ie(ke,1,"getCollaboratorsOnCurrentPage",NB,Ee);Ie(ke,1,"getRenderingShapes",jB,Ee);Ie(ke,1,"_getAllPagesQuery",DB,Ee);Ie(ke,1,"getPages",RB,Ee);Ie(ke,1,"getCurrentPageId",OB,Ee);Ie(ke,1,"getCurrentPageShapeIdsSorted",AB,Ee);Ie(ke,1,"_getAllAssetsQuery",MB,Ee);Ie(ke,1,"_getShapeHandlesCache",TB,Ee);Ie(ke,1,"_getShapePageTransformCache",_B,Ee);Ie(ke,1,"_getShapePageBoundsCache",IB,Ee);Ie(ke,1,"_getShapeClipPathCache",kB,Ee);Ie(ke,1,"_getShapeMaskCache",EB,Ee);Ie(ke,1,"_getShapeMaskedPageBoundsCache",PB,Ee);Ie(ke,1,"_notVisibleShapes",CB,Ee);Ie(ke,1,"getCulledShapes",bB,Ee);Ie(ke,1,"getCurrentPageBounds",wB,Ee);Ie(ke,1,"getCurrentPageShapes",xB,Ee);Ie(ke,1,"getCurrentPageShapesSorted",vB,Ee);Ie(ke,1,"getCurrentPageRenderingShapesSorted",SB,Ee);Ie(ke,1,"_getBindingsIndexCache",yB,Ee);Ie(ke,1,"_getSelectionSharedStyles",mB,Ee);Ie(ke,1,"getSharedStyles",gB,Ee);Ie(ke,1,"getSharedOpacity",pB,Ee);Ie(ke,1,"getIsFocused",fB,Ee);Ie(ke,1,"getIsReadonly",hB,Ee);Ie(ke,1,"_setShiftKeyTimeout",dB,Ee);Ie(ke,1,"_setAltKeyTimeout",uB,Ee);Ie(ke,1,"_setCtrlKeyTimeout",cB,Ee);Ie(ke,1,"_setMetaKeyTimeout",lB,Ee);Xoe(ke,Ee);function Pm(n,e=n.getCurrentPageId()){const t=n.getPage(e).name;n.emit("max-shapes",{name:t,pageId:e,count:n.options.maxShapesPerPage})}function xo(n,e){if(!e)return n;let t=null;const r=Object.entries(e);for(let s=0,i=r.length;s<i;s++){const[o,a]=r[s];if(a!==void 0&&!(o==="id"||o==="type"||o==="typeName")&&a!==n[o]){if(t||(t={...n}),o==="props"||o==="meta"){t[o]={...n[o]};for(const[l,c]of Object.entries(a))t[o][l]=c;continue}t[o]=a}}return t||n}function k6(n,e,t){const r=n.getShape(e);if(!r)return;t.push(r);const s=n.getSortedChildIdsForParent(e);for(let i=0,o=s.length;i<o;i++)k6(n,s[i],t)}function Qj(n,e,t){let r;if(n.run(()=>{const s=n.store.extractingChanges(()=>{const i=new Set,o=new Set;for(const a of e)if(n.getShape(a))for(const c of n.getBindingsInvolvingShape(a)){const d=e.has(c.fromId),f=e.has(c.toId);if(d&&f){i.add(c.id);continue}(!d||!f)&&o.add(c.id)}n.deleteBindings([...o],{isolateShapes:!0});try{r=jr.ok(t(i))}catch(a){r=jr.err(a)}});n.store.applyDiff(tE(s),{runCallbacks:!1})},{history:"ignore"}),r.ok)return r.value;throw r.error}function eN(n,e){if(!e.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=e.constraints,s=n.getViewportScreenBounds(),i=ye.From(e.constraints.bounds),o=(s.w-t*2)/i.w,a=(s.h-r*2)/i.h;return{zx:o,zy:a}}function Up(){const n=te(),e=Fp();return ie("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??n.user.getIsDarkMode(),[e,n])}const tN="<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'/>",nN="<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'/>",Em='<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 dl(n,e,t,r,s,i=16,o=16){const a=(-t-e)*(xt/180),l=Math.sin(a),c=Math.cos(a),d=1*c-1*l,f=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${s};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${d}' 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>") ${i} ${o}, pointer`}const Joe=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],Qoe={none:()=>"none","ew-resize":(n,e,t)=>dl(nN,n,0,e,t),"ns-resize":(n,e,t)=>dl(nN,n,90,e,t),"nesw-resize":(n,e,t)=>dl(tN,n,0,e,t),"nwse-resize":(n,e,t)=>dl(tN,n,90,e,t),"nwse-rotate":(n,e,t)=>dl(Em,n,0,e,t),"nesw-rotate":(n,e,t)=>dl(Em,n,90,e,t),"senw-rotate":(n,e,t)=>dl(Em,n,180,e,t),"swne-rotate":(n,e,t)=>dl(Em,n,270,e,t)};function Ds(n,e=0,t="black"){return Qoe[n](jG(e),!1,t)}function eae(){const n=te(),e=In(),t=Up();Ca("useCursor",()=>{const{type:r,rotation:s}=n.getInstanceState().cursor;if(Joe.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",Ds(r,s,t?"white":"black"))},[n,e,t])}function tae(){const n=te(),e=In(),t=Up(),r=ie(xn.forceSrgb);He.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 nae(){const[n,e]=P.useState(0);P.useEffect(()=>e(t=>t+1),[])}const rae=n=>n.props.src,sae={upload:async(n,e)=>({src:await zr.blobToDataUrl(e)})};function iae(n){return"schema"in n&&n.schema?n.schema:jte({shapes:"shapeUtils"in n&&n.shapeUtils?rN(_z(n.shapeUtils)):void 0,bindings:"bindingUtils"in n&&n.bindingUtils?rN(kz(n.bindingUtils)):void 0,migrations:"migrations"in n?n.migrations:void 0})}function lp({initialData:n,defaultName:e="",id:t,assets:r=sae,onMount:s,collaboration:i,...o}={}){const a=iae(o),l=new vI({id:t,schema:a,initialData:n,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??rae},onMount:c=>{nt(c instanceof Ee),s==null||s(c)},collaboration:i}});if(o.snapshot){if(n)throw new Error("Cannot provide both initialData and snapshot");Pz(l,o.snapshot,{forceOverwriteSessionState:!0})}return l}function rN(n){return Object.fromEntries(n.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}function oae(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
206
+
207
+ Keep seeing this message?
208
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
209
+ • If your hard disk is full, try clearing up some space and then reload the page.`)}function aae(){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.
210
+
211
+ Keep seeing this message?
212
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const lae=350,cae=1e4,sN=Symbol("UPDATE_INSTANCE_STATE"),uae=n=>n;class dae{constructor(e){O(this,"onmessage")}postMessage(e){}close(){}}const hae=typeof BroadcastChannel>"u"?dae:BroadcastChannel;class fae{constructor(e,{persistenceKey:t,sessionId:r=mS,onLoad:s,onLoadError:i},o=new hae(`tldraw-tab-sync-${t}`)){O(this,"disposables",new Set);O(this,"diffQueue",[]);O(this,"didDispose",!1);O(this,"shouldDoFullDBWrite",!0);O(this,"isReloading",!1);O(this,"persistenceKey");O(this,"sessionId");O(this,"serializedSchema");O(this,"isDebugging",!1);O(this,"documentTypes");O(this,"$sessionStateSnapshot");O(this,"db");O(this,"initTime",Date.now());O(this,"isPersisting",!1);O(this,"didLastWriteError",!1);O(this,"scheduledPersistTimeout",null);this.store=e,this.channel=o,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.db=new tS(t),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=$I(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(uae({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(sN),this.schedulePersist()},{scope:"session"})),this.connect(s,i),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),aae();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const s=Object.fromEntries(r.records.map(l=>[l.id,l])),i=r.sessionStateSnapshot??mse(s),o=this.store.schema.migrateStoreSnapshot({store:s,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(o.type==="error"){console.error("failed to migrate store",o),t(new Error(`Failed to migrate store: ${o.reason}`));return}const a=Object.values(o.value).filter(l=>this.documentTypes.has(l.typeName));a.length>0&&this.store.mergeRemoteChanges(()=>{this.store.put(a,"initialize")}),i&&cE(this.store,i,{forceOverwrite:!0})}this.channel.onmessage=({data:s})=>{var a,l;this.debug("got message",s);const i=s,o=this.store.schema.getMigrationsSince(i.schema);if(o.ok){if(o.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,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}i.type==="diff"&&(this.debug("applying diff"),ws(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(i.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?cae:lae))}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(nt(!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=SI(e.filter(r=>r!==sN));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),oae(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function I6(n){const e=P.useRef(n),[t,r]=P.useState(n);t!==e.current&&r(e.current);const s=P.useCallback(i=>{typeof i=="function"?e.current=i(e.current):e.current=i,r(e.current)},[]);return[t,s]}function pae(n){const[e,t]=I6({status:"loading"});return n=ih(n),P.useEffect(()=>{const{persistenceKey:r,sessionId:s,...i}=n;if(!r){t({status:"not-synced",store:lp(i)});return}t({status:"loading"});const o=new Na,a={upload:async(f,p)=>(await d.db.storeAsset(f.id,p),{src:f.id}),resolve:async f=>f.props.src?f.props.src.startsWith("asset:")?await o.get(f,async()=>{const p=await d.db.getAsset(f.id);return p?URL.createObjectURL(p):null}):f.props.src:null,...i.assets},l=lp({...i,assets:a});let c=!1;const d=new fae(l,{sessionId:s,persistenceKey:r,onLoad(){c||t({store:l,status:"synced-local"})},onLoadError(f){c||t({status:"error",error:f})}});return()=>{c=!0,d.close()}},[n,t]),e}function gae(){const n=te(),e=In();P.useEffect(()=>{const t=i=>e.style.setProperty("--tl-zoom",i.toString()),r=cv(t,100),s=new du("useZoomCss",()=>{n.getCurrentPageShapeIds().size<300?t(n.getZoomLevel()):r(n.getZoomLevel())});return s.attach(),s.execute(),()=>{s.detach(),r.cancel()}},[n,e])}function mE(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 mae(n){const e=atob(n),t=mE(e);return crypto.subtle.importKey("spki",new Uint8Array(t),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const yae=5,vf={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},Sae=Math.max(...Object.values(vf)),xf={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},vae=Object.keys(xf).length,yC="sales@tldraw.com",xae=`${Pn()}/watermarks/watermark-track.svg`;class n0{constructor(e,t,r){O(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");O(this,"isDevelopment");O(this,"isTest");O(this,"isCryptoAvailable");O(this,"state",on("license state","pending"));O(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 i=wae(s);!this.isDevelopment&&i&&Vi(xae),i?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:"||window.location.hostname==="localhost"}async extractLicenseKey(e){const[t,r]=e.split("."),[s,i]=t.split("/");if(!s.startsWith("tldraw-"))throw new Error(`Unsupported prefix '${s}'`);const o=await mae(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,new Uint8Array(mE(atob(r))),new Uint8Array(mE(atob(i))))}catch(c){throw console.error(c),new Error("Could not perform signature validation")}if(!a)throw new Error("Invalid signature");let l;try{l=JSON.parse(atob(i))}catch{throw new Error("Could not parse object")}return l.length>vae&&this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]),{id:l[xf.ID],hosts:l[xf.HOSTS],flags:l[xf.FLAGS],expiryDate:l[xf.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),i=this.isFlagEnabled(r.flags,vf.ANNUAL_LICENSE),o=this.isFlagEnabled(r.flags,vf.PERPETUAL_LICENSE),a={license:r,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(r),expiryDate:s,isAnnualLicense:i,isAnnualLicenseExpired:i&&this.isAnnualLicenseExpired(s),isPerpetualLicense:o,isPerpetualLicenseExpired:o&&this.isPerpetualLicenseExpired(s),isInternalLicense:this.isFlagEnabled(r.flags,vf.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,vf.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 i=new RegExp(r.replace(/\*/g,".*?"));return i.test(t)||i.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()+yae+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 ${yC} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const t=this.getExpirationDateWithGracePeriod(e),r={major:new Date(fj.major),minor:new Date(fj.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 ${yC} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${yC} if you would like to use tldraw on other domains.`]),e.license.flags>=Sae*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;")}}O(n0,"className","tl-watermark_SEE-LICENSE");function wae(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 _6=P.createContext({}),bae=()=>P.useContext(_6);function Cae({licenseKey:n,children:e}){const[t]=P.useState(()=>new n0(n));return g.jsx(_6.Provider,{value:t,children:e})}function $a(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=In();P.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;const i=n.current;if(i&&i.scrollHeight>i.clientHeight)return;tt(s);const o=e.querySelector(".tl-canvas");if(!o)return;const a=new WheelEvent("wheel",s);a.isSpecialRedispatchedEvent=!0,o.dispatchEvent(a)}const r=n.current;if(r)return r.addEventListener("wheel",t,{passive:!1}),()=>{r.removeEventListener("wheel",t)}},[e,n])}const Pae='<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>',Eae='<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 kae(n){return ie("watermarkState",()=>n.state.get(),[n])}const Iae=`data:image/svg+xml;utf8,${encodeURIComponent(Pae)}`,_ae=`data:image/svg+xml;utf8,${encodeURIComponent(Eae)}`,Tae=P.memo(function(){const e=bae(),t=te(),r=ie("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),s=kae(e);return["licensed-with-watermark","unlicensed"].includes(s)?g.jsxs(g.Fragment,{children:[g.jsx(Aae,{}),g.jsx(Mae,{src:r?_ae:Iae})]}):null}),Mae=P.memo(function({src:e}){const t=te(),r=ie("debug mode",()=>t.getInstanceState().isDebugMode,[t]),s=ie("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),i=NI(),o=P.useRef(null);$a(o);const a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark";return g.jsx("div",{ref:o,className:n0.className,"data-debug":r,"data-mobile":s,draggable:!1,...i,children:Pt.isWebview?g.jsx("a",{draggable:!1,role:"button",onPointerDown:c=>{Xt(c),tt(c)},onClick:()=>Kv.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}}):g.jsx("a",{href:l,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:c=>{Xt(c)},style:{mask:a,WebkitMask:a}})})}),Aae=P.memo(function(){const e=n0.className,t=`/* ------------------- SEE LICENSE -------------------
213
+ The tldraw watermark is part of tldraw's license. It is shown for unlicensed
214
+ or "licensed-with-watermark" users. By using this library, you agree to
215
+ preserve the watermark's behavior, keeping it visible, unobscured, and
216
+ available to user-interaction.
217
+
218
+ To remove the watermark, please purchase a license at tldraw.dev.
219
+ */
220
+
221
+ .${e} {
222
+ position: absolute;
223
+ bottom: var(--space-2);
224
+ right: var(--space-2);
225
+ width: 96px;
226
+ height: 32px;
227
+ display: flex;
228
+ align-items: center;
229
+ justify-content: center;
230
+ z-index: var(--layer-watermark) !important;
231
+ background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
232
+ opacity: 1;
233
+ border-radius: 5px;
234
+ pointer-events: all;
235
+ padding: 2px;
236
+ box-sizing: content-box;
237
+ }
238
+
239
+ .${e} > a {
240
+ position: absolute;
241
+ width: 96px;
242
+ height: 32px;
243
+ pointer-events: all;
244
+ cursor: inherit;
245
+ color: var(--color-text);
246
+ opacity: .38;
247
+ background-color: currentColor;
248
+ }
249
+
250
+ .${e}[data-debug='true'] {
251
+ bottom: 46px;
252
+ }
253
+
254
+ .${e}[data-mobile='true'] {
255
+ border-radius: 4px 0px 0px 4px;
256
+ right: -2px;
257
+ width: 8px;
258
+ height: 48px;
259
+ }
260
+
261
+ .${e}[data-mobile='true'] > a {
262
+ width: 8px;
263
+ height: 32px;
264
+ }
265
+
266
+ @media (hover: hover) {
267
+ .${e} > a {
268
+ pointer-events: none;
269
+ }
270
+
271
+ .${e}:hover {
272
+ background-color: var(--color-background);
273
+ transition: background-color 0.2s ease-in-out;
274
+ transition-delay: 0.32s;
275
+ }
276
+
277
+ .${e}:hover > a {
278
+ animation: delayed_link 0.2s forwards ease-in-out;
279
+ animation-delay: 0.32s;
280
+ }
281
+ }
282
+
283
+ @keyframes delayed_link {
284
+ 0% {
285
+ cursor: inherit;
286
+ opacity: .38;
287
+ pointer-events: none;
288
+ }
289
+ 100% {
290
+ cursor: pointer;
291
+ opacity: 1;
292
+ pointer-events: all;
293
+ }
294
+ }`;return g.jsx("style",{children:t})}),Oae=[],Rae=[],Dae=[],jae="tl-container",Nae=P.memo(function({store:e,components:t,className:r,user:s,options:i,...o}){const[a,l]=P.useState(null),c=P.useMemo(()=>s??wz(),[s]),d=(t==null?void 0:t.ErrorFallback)===void 0?hz:t==null?void 0:t.ErrorFallback,f={...o,shapeUtils:o.shapeUtils??Oae,bindingUtils:o.bindingUtils??Rae,tools:o.tools??Dae,components:t,options:ih(i)};return g.jsx("div",{ref:l,"data-tldraw":$4,draggable:!1,className:ze(`${jae} tl-theme__light`,r),onPointerDown:Xt,tabIndex:-1,children:g.jsx(ap,{fallback:d,onError:p=>gk(p,{tags:{origin:"react.tldraw-before-app"}}),children:a&&g.jsx(Cae,{licenseKey:o.licenseKey,children:g.jsx(W4,{container:a,children:g.jsx(tse,{overrides:t,children:e?e instanceof vI?g.jsx(M6,{...f,store:e,user:c}):g.jsx(T6,{...f,store:e,user:c}):g.jsx(Lae,{...f,store:e,user:c})})})})})})});function Lae(n){const{defaultName:e,snapshot:t,initialData:r,shapeUtils:s,bindingUtils:i,persistenceKey:o,sessionId:a,user:l,assets:c,migrations:d}=n,f=pae({shapeUtils:s,bindingUtils:i,initialData:r,persistenceKey:o,sessionId:a,defaultName:e,snapshot:t,assets:c,migrations:d});return g.jsx(T6,{...n,store:f,user:l})}const T6=P.memo(function({store:e,user:t,...r}){const s=In();P.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,t]);const{LoadingScreen:i}=Zt();switch(e.status){case"error":throw e.error;case"loading":return i?g.jsx(i,{}):null}return g.jsx(M6,{...r,store:e.store,user:t})}),SC=()=>document.location.search.includes("tldraw_preserve_focus");function M6({onMount:n,children:e,store:t,tools:r,shapeUtils:s,bindingUtils:i,user:o,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:d,textOptions:f,options:p,licenseKey:m,deepLinks:y,isShapeHidden:v,assetUrls:x}){const{ErrorFallback:b}=Zt(),C=In(),[I,_]=I6(null),T=P.useRef(null),A=ih(y===!0?{}:y),R=P.useRef({autoFocus:l&&!SC(),inferDarkMode:c,initialState:a,cameraOptions:d,deepLinks:A});P.useLayoutEffect(()=>{R.current={autoFocus:l&&!SC(),inferDarkMode:c,initialState:a,cameraOptions:d,deepLinks:A}},[l,c,a,d,A]),P.useLayoutEffect(()=>{const{autoFocus:L,inferDarkMode:V,initialState:X,cameraOptions:W,deepLinks:$}=R.current,G=new Ee({store:t,shapeUtils:s,bindingUtils:i,tools:r,getContainer:()=>C,user:o,initialState:X,autoFocus:L,inferDarkMode:V,cameraOptions:W,textOptions:f,options:p,licenseKey:m,isShapeHidden:v,fontAssetUrls:x==null?void 0:x.fonts});return G.updateViewportScreenBounds(T.current??C),$&&($!=null&&$.getUrl?G.navigateToDeepLink({...$,url:$.getUrl(G)}):G.navigateToDeepLink($)),_(G),()=>{G.dispose()}},[i,C,p,s,t,r,o,_,m,v,f,x]),P.useLayoutEffect(()=>{if(I&&A)return I.registerDeepLinkListener(A)},[I,A]),P.useLayoutEffect(()=>{I&&d&&I.setCameraOptions(d)},[I,d]);const j=P.useSyncExternalStore(P.useCallback(L=>I?(I.on("crash",L),()=>I.off("crash",L)):()=>{},[I]),()=>(I==null?void 0:I.getCrashingError())??null);P.useEffect(function(){if(!I)return;function V(){I&&I.focus()}function X(){I&&I.blur()}if(l&&SC())return I.getContainer().addEventListener("pointerdown",V),document.body.addEventListener("pointerdown",X),()=>{var W;(W=I.getContainer())==null||W.removeEventListener("pointerdown",V),document.body.removeEventListener("pointerdown",X)}},[I,l]);const[K,U]=P.useState(null);let J=K;I!==(J==null?void 0:J.editor)&&(J=null),P.useEffect(()=>{if(!I)return;let L=!1;return U({editor:I,isLoaded:!1}),I.fonts.loadRequiredFontsForCurrentPage(I.options.maxFontsToLoadBeforeRender).finally(()=>{L||U({editor:I,isLoaded:!0})}),()=>{L=!0}},[I]);const{Canvas:z,LoadingScreen:N}=Zt();return!I||!(J!=null&&J.isLoaded)?g.jsxs(g.Fragment,{children:[N&&g.jsx(N,{}),g.jsx("div",{className:"tl-canvas",ref:T})]}):g.jsx(ap,{fallback:b,onError:L=>I.annotateError(L,{origin:"react.tldraw",willCrashApp:!0}),children:j?g.jsx(zae,{crashingError:j}):g.jsx(DI,{editor:I,children:g.jsxs(Fae,{onMount:n,children:[e??(z?g.jsx(z,{},I.contextId):null),g.jsx(Tae,{})]})})})}function Fae({children:n,onMount:e}){return gae(),eae(),tae(),nae(),A6(t=>{const r=t.store.props.onMount(t),s=e==null?void 0:e(t);return()=>{r==null||r(),s==null||s()}}),n}function zae({crashingError:n}){throw n}function $ae({children:n}){return g.jsx("div",{className:"tl-loading",children:n})}function A6(n){const e=te(),t=Xv(r=>{let s;return r.run(()=>{s=n==null?void 0:n(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});He.useLayoutEffect(()=>{if(e)return t==null?void 0:t(e)},[e,t])}function jl({children:n,className:e="",...t}){return g.jsx("div",{...t,className:ze("tl-html-container",e),children:n})}class oy{constructor(e){this.editor=e}}O(oy,"props"),O(oy,"migrations"),O(oy,"type");function r0(n,e,t={}){const{newPoint:r,handle:s,scaleX:i,scaleY:o}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:d=1/0}=t;let f=n.props.w*i,p=n.props.h*o;const m=new E(0,0);if(f>0){if(f<a){switch(s){case"top_left":case"left":case"bottom_left":{m.x=f-a;break}case"top":case"bottom":{m.x=(f-a)/2;break}default:m.x=0}f=a}}else if(m.x=f,f=-f,f<a){switch(s){case"top_left":case"left":case"bottom_left":{m.x=-f;break}default:m.x=-a}f=a}if(p>0){if(p<c){switch(s){case"top_left":case"top":case"top_right":{m.y=p-c;break}case"right":case"left":{m.y=(p-c)/2;break}default:m.y=0}p=c}}else if(m.y=p,p=-p,p<c){switch(s){case"top_left":case"top":case"top_right":{m.y=-p;break}default:m.y=-c}p=c}const{x:y,y:v}=m.rot(n.rotation).add(r);return{...n,x:y,y:v,props:{w:Math.min(l,f),h:Math.min(d,p)}}}class uh extends Xi{getGeometry(e){return new zo({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return r0(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,r){return{...t.props,w:yt(e.props.w,t.props.w,r),h:yt(e.props.h,t.props.h,r)}}}var tP;let Bae=(tP=class extends Ne{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},O(tP,"id","idle"),tP);var nP;let Uae=(nP=class extends Ne{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=this.parent.shapeType,s=Dt(),i=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),o=Ji(t,this.editor);this.editor.createShapes([{id:s,type:r,x:o.x,y:o.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:i,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?l=>{var c;return(c=a.onCreate)==null?void 0:c.call(a,l)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,t=this.parent.shapeType,r=Dt();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:i,h:o}=s.props;const a=new E(i/2,o/2),l=this.editor.getShapeParentTransform(s);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),i*=c,o*=c,a.mul(c));const d=Yt(s),f=Ji(new E(s.x-a.x,s.y-a.y),this.editor);d.x=f.x,d.y=f.y,d.props.w=i,d.props.h=o,"scale"in s.props&&(d.props.scale=c),this.editor.updateShape(d),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},O(nP,"id","pointing"),nP);function Ji(n,e){const t=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return t?n.clone().snapToGrid(r):n.clone()}class yE extends Ne{static children(){return[Bae,Uae]}}O(yE,"id","box"),O(yE,"initial","idle");function Hae(n,e,t){const r=P.useRef(!1),s=P.useCallback(o=>{r.current=o,o?$i.addOpenMenu(n):$i.deleteOpenMenu(n),e==null||e(o)},[n,e]),i=ie("is menu open",()=>$i.getOpenMenus().includes(n),[n]);return P.useEffect(()=>(r.current&&(t==null||t("open-menu"),$i.addOpenMenu(n)),()=>{r.current&&($i.deleteOpenMenu(n),$i.getOpenMenus().forEach(o=>{o.startsWith(n)&&(t==null||t("close-menu"),$i.deleteOpenMenu(o))}),r.current=!1)}),[n,t]),[i,s]}function s0(n){const e=te();return ie("isEditing",()=>e.getEditingShapeId()===n,[e,n])}function Kae(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=In();P.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;tt(s);const i=e.querySelector(".tl-canvas");if(!i)return;const o=new PointerEvent(s.type,s);o.isSpecialRedispatchedEvent=!0,i.dispatchEvent(o)}const r=n.current;if(r)return r.addEventListener("mouseover",t,{passive:!1}),()=>{r.removeEventListener("mouseover",t)}},[e,n])}function Co(n){const e=te();return P.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===jI){e.dispatch({type:"pointer",target:"selection",handle:n,name:"right_click",...Fs(c)});return}if(c.button!==0)return;const d=pS(c.currentTarget);function f(){d.removeEventListener("pointerup",f),Dp(d,c)}Rp(d,c),d.addEventListener("pointerup",f),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:n,...Fs(c)}),Xt(c)};let i,o;function a(c){c.isKilled||c.button===0&&(c.clientX===i&&c.clientY===o||(i=c.clientX,o=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:n,...Fs(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:n,...Fs(c)})}}},[e,n])}function Wae(n){const[e,t]=P.useState(()=>({store:lp(n),opts:n}));if(!QL(e.opts,n)){const r={store:lp(n),opts:n};return t(r),r.store}return e.store}const Vae=20,qae=8;function QI(n,e=Vae){return Math.max(qae,Math.ceil(n/e))}class wd extends Jl{constructor(t){super({...t,isFilled:!1,isClosed:!1});O(this,"_center");O(this,"radius");O(this,"start");O(this,"end");O(this,"largeArcFlag");O(this,"sweepFlag");O(this,"measure");O(this,"angleStart");O(this,"angleEnd");const{center:r,sweepFlag:s,largeArcFlag:i,start:o,end:a}=t;if(o.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=E.Angle(r,o),this.angleEnd=E.Angle(r,a),this.radius=E.Dist(r,o),this.measure=NG(this.angleStart,this.angleEnd,s,i),this.start=o,this.end=a,this.sweepFlag=s,this.largeArcFlag=i,this._center=r}nearestPoint(t){const{_center:r,measure:s,radius:i,angleEnd:o,angleStart:a,start:l,end:c}=this,d=_P(s,a,o,r.angle(t));if(d<=0)return l;if(d>=1)return c;const f=r.clone().add(t.clone().sub(r).uni().mul(i));let p,m=1/0,y;for(const v of[l,c,f])y=E.Dist2(t,v),y<m&&(p=v,m=y);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(t,r){const{_center:s,radius:i,measure:o,angleStart:a,angleEnd:l}=this,c=Lp(t,r,s,i);return c===null?!1:c.some(d=>{const f=_P(o,a,l,s.angle(d));return f>=0&&f<=1})}getVertices(){const{_center:t,measure:r,length:s,radius:i,angleStart:o}=this,a=[];for(let l=0,c=QI(Math.abs(s));l<c+1;l++){const d=l/c*r,f=o+d;a.push(Wc(t,i,f))}return a}getSvgPathData(t=!0){const{start:r,end:s,radius:i,largeArcFlag:o,sweepFlag:a}=this;return`${t?`M${r.toFixed()}`:""} A${i} ${i} 0 ${o} ${a} ${s.toFixed()}`}getLength(){return this.measure*this.radius}}class e_ extends Jl{constructor(t){super({isClosed:!0,...t});O(this,"_center");O(this,"radius");O(this,"x");O(this,"y");this.config=t;const{x:r=0,y:s=0,radius:i}=t;this.x=r,this.y=s,this._center=new E(i+r,i+s),this.radius=i}getBounds(){return new ye(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,s=Rt*r,i=[];for(let o=0,a=QI(s);o<a;o++){const l=o/a*Rt;i.push(Wc(t,r,l))}return i}nearestPoint(t){const{_center:r,radius:s}=this;return r.equals(t)?E.AddXY(r,s,0):r.clone().add(t.clone().sub(r).uni().mul(s))}hitTestLineSegment(t,r,s=0){const{_center:i,radius:o}=this;return Lp(t,r,i,o+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 wr extends oh{constructor(t){const{start:r,cp1:s,cp2:i,end:o}=t;super({...t,points:[r,o]});O(this,"a");O(this,"b");O(this,"c");O(this,"d");this.a=r,this.b=s,this.c=i,this.d=o}getVertices(){const t=[],{a:r,b:s,c:i,d:o}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;t.push(new E((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*s.x+3*(1-c)*(c*c)*i.x+c*c*c*o.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*s.y+3*(1-c)*(c*c)*i.y+c*c*c*o.y))}return t}midPoint(){return wr.GetAtT(this,.5)}nearestPoint(t){let r,s=1/0,i,o;for(const a of this.segments)o=a.nearestPoint(t),i=E.Dist2(o,t),i<s&&(r=o,s=i);if(!r)throw Error("nearest point not found");return r}getSvgPathData(t=!0){const{a:r,b:s,c:i,d:o}=this;return`${t?`M ${r.toFixed()} `:""} C${s.toFixed()} ${i.toFixed()} ${o.toFixed()}`}static GetAtT(t,r){const{a:s,b:i,c:o,d:a}=t;return new E((1-r)*(1-r)*(1-r)*s.x+3*((1-r)*(1-r))*r*i.x+3*(1-r)*(r*r)*o.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*s.y+3*((1-r)*(1-r))*r*i.y+3*(1-r)*(r*r)*o.y+r*r*r*a.y)}getLength(t=32){let r,s=this.a,i=0;for(let o=1;o<=t;o++)r=wr.GetAtT(this,o/t),i+=E.Dist(s,r),s=r;return i}}class Gae extends Jl{constructor(t){super({...t,isClosed:!1,isFilled:!1});O(this,"points");O(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,i=1.25;for(let o=0;o<r-1;o++){const a=o===0?t[0]:t[o-1],l=t[o],c=t[o+1],d=o===s?c:t[o+2],f=l,p=o===0?a:new E(l.x+(c.x-a.x)/6*i,l.y+(c.y-a.y)/6*i),m=o===s?c:new E(c.x-(d.x-l.x)/6*i,c.y-(d.y-l.y)/6*i),y=c;this._segments.push(new wr({start:f,cp1:p,cp2:m,end:y}))}}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,i,o;for(const a of this.segments)o=a.nearestPoint(t),i=E.Dist2(o,t),i<s&&(r=o,s=i);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,i)=>r+s.getSvgPathData(i===0),"");return this.isClosed&&(t+="Z"),t}}class Yae extends Jl{constructor(t){super({...t,isClosed:!0});O(this,"w");O(this,"h");O(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 i=t[r],o=t[(r+1)%s];this._edges.push(new wa({start:i,end:o}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),s=t/2,i=r/2,o=Math.pow(s-i,2)/Math.pow(s+i,2),a=xt*(s+i)*(1+3*o/(10+Math.sqrt(4-3*o))),l=QI(a),c=Rt/l,d=Math.cos(c),f=Math.sin(c);let p=0,m=1,y=0,v=1;const x=Array(l);for(let b=0;b<l;b++)x[b]=new E(s+s*m,i+i*p),y=f*m+d*p,v=d*m-f*p,p=y,m=v;return x}nearestPoint(t){let r,s=1/0,i,o;for(const a of this.edges)o=a.nearestPoint(t),i=E.Dist2(o,t),i<s&&(r=o,s=i);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 ye(0,0,this.w,this.h)}getLength(){const{w:t,h:r}=this,s=t/2,i=r/2,o=Math.max(0,s),a=Math.max(0,i);return Q3(o,a)}getSvgPathData(t=!1){const{w:r,h:s}=this,i=r/2,o=s/2,a=Math.max(0,i),l=Math.max(0,o);return`${t?`M${i-a},${o}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class Xae extends Jl{constructor(t){super({...t,isClosed:!0});O(this,"w");O(this,"h");O(this,"a");O(this,"b");O(this,"c");O(this,"d");this.config=t;const{width:r,height:s}=t;if(this.w=r,this.h=s,s>r){const i=r/2;this.a=new wd({start:new E(0,i),end:new E(r,i),center:new E(r/2,i),sweepFlag:1,largeArcFlag:1}),this.b=new wa({start:new E(r,i),end:new E(r,s-i)}),this.c=new wd({start:new E(r,s-i),end:new E(0,s-i),center:new E(r/2,s-i),sweepFlag:1,largeArcFlag:1}),this.d=new wa({start:new E(0,s-i),end:new E(0,i)})}else{const i=s/2;this.a=new wd({start:new E(i,s),end:new E(i,0),center:new E(i,i),sweepFlag:1,largeArcFlag:1}),this.b=new wa({start:new E(i,0),end:new E(r-i,0)}),this.c=new wd({start:new E(r-i,0),end:new E(r-i,s),center:new E(r-i,i),sweepFlag:1,largeArcFlag:1}),this.d=new wa({start:new E(r-i,s),end:new E(i,s)})}}nearestPoint(t){let r,s=1/0,i,o;const{a,b:l,c,d}=this;for(const f of[a,l,c,d])o=f.nearestPoint(t),i=E.Dist2(o,t),i<s&&(r=o,s=i);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){const{a:s,b:i,c:o,d:a}=this;return[s,i,o,a].some(l=>l.hitTestLineSegment(t,r))}getVertices(){const{a:t,b:r,c:s,d:i}=this;return[t,r,s,i].reduce((o,a)=>(o.push(...a.vertices),o),[])}getBounds(){return new ye(0,0,this.w,this.h)}getLength(){const{h:t,w:r}=this;return t>r?(xt*(r/2)+(t-r))*2:(xt*(t/2)+(r-t))*2}getSvgPathData(){const{a:t,b:r,c:s,d:i}=this;return[t,r,s,i].map((o,a)=>o.getSvgPathData(a===0)).join(" ")+" Z"}}async function Zae({shouldReload:n=!0}={}){iq();for(const e of tS.connectedInstances)await e.close();await Promise.all(cI().map(e=>K5(e))),sq(),n&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Zae);function Jae(n,e="_blank"){Kv.openWindow(n,e)}Wl("@tldraw/editor","3.10.3","esm");function O6(){const[n,e]=P.useState(!1);return P.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 R6=()=>{},D6=P.createContext(null);function Qae({onEvent:n,children:e}){return g.jsx(D6.Provider,{value:n??R6,children:e})}function Rn(){return P.useContext(D6)??R6}function De(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 ele(n,e){const t=P.createContext(e),r=i=>{const{children:o,...a}=i,l=P.useMemo(()=>a,Object.values(a));return g.jsx(t.Provider,{value:l,children:o})};r.displayName=n+"Provider";function s(i){const o=P.useContext(t);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${i}\` must be used within \`${n}\``)}return[r,s]}function Vo(n,e=[]){let t=[];function r(i,o){const a=P.createContext(o),l=t.length;t=[...t,o];const c=f=>{var b;const{scope:p,children:m,...y}=f,v=((b=p==null?void 0:p[n])==null?void 0:b[l])||a,x=P.useMemo(()=>y,Object.values(y));return g.jsx(v.Provider,{value:x,children:m})};c.displayName=i+"Provider";function d(f,p){var v;const m=((v=p==null?void 0:p[n])==null?void 0:v[l])||a,y=P.useContext(m);if(y)return y;if(o!==void 0)return o;throw new Error(`\`${f}\` must be used within \`${i}\``)}return[c,d]}const s=()=>{const i=t.map(o=>P.createContext(o));return function(a){const l=(a==null?void 0:a[n])||i;return P.useMemo(()=>({[`__scope${n}`]:{...a,[n]:l}}),[a,l])}};return s.scopeName=n,[r,tle(s,...e)]}function tle(...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(i){const o=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(i)[`__scope${c}`];return{...a,...f}},{});return P.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return t.scopeName=e.scopeName,t}function iN(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function i0(...n){return e=>{let t=!1;const r=n.map(s=>{const i=iN(s,e);return!t&&typeof i=="function"&&(t=!0),i});if(t)return()=>{for(let s=0;s<r.length;s++){const i=r[s];typeof i=="function"?i():iN(n[s],null)}}}}function Kt(...n){return P.useCallback(i0(...n),n)}var tu=P.forwardRef((n,e)=>{const{children:t,...r}=n,s=P.Children.toArray(t),i=s.find(rle);if(i){const o=i.props.children,a=s.map(l=>l===i?P.Children.count(o)>1?P.Children.only(null):P.isValidElement(o)?o.props.children:null:l);return g.jsx(SE,{...r,ref:e,children:P.isValidElement(o)?P.cloneElement(o,void 0,a):null})}return g.jsx(SE,{...r,ref:e,children:t})});tu.displayName="Slot";var SE=P.forwardRef((n,e)=>{const{children:t,...r}=n;if(P.isValidElement(t)){const s=ile(t),i=sle(r,t.props);return t.type!==P.Fragment&&(i.ref=e?i0(e,s):s),P.cloneElement(t,i)}return P.Children.count(t)>1?P.Children.only(null):null});SE.displayName="SlotClone";var nle=({children:n})=>g.jsx(g.Fragment,{children:n});function rle(n){return P.isValidElement(n)&&n.type===nle}function sle(n,e){const t={...e};for(const r in e){const s=n[r],i=e[r];/^on[A-Z]/.test(r)?s&&i?t[r]=(...a)=>{i(...a),s(...a)}:s&&(t[r]=s):r==="style"?t[r]={...s,...i}:r==="className"&&(t[r]=[s,i].filter(Boolean).join(" "))}return{...n,...t}}function ile(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 ole=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],wt=ole.reduce((n,e)=>{const t=P.forwardRef((r,s)=>{const{asChild:i,...o}=r,a=i?tu:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),g.jsx(a,{...o,ref:s})});return t.displayName=`Primitive.${e}`,{...n,[e]:t}},{});function t_(n,e){n&&ah.flushSync(()=>n.dispatchEvent(e))}function o0(n){const e=n+"CollectionProvider",[t,r]=Vo(e),[s,i]=t(e,{collectionRef:{current:null},itemMap:new Map}),o=m=>{const{scope:y,children:v}=m,x=He.useRef(null),b=He.useRef(new Map).current;return g.jsx(s,{scope:y,itemMap:b,collectionRef:x,children:v})};o.displayName=e;const a=n+"CollectionSlot",l=He.forwardRef((m,y)=>{const{scope:v,children:x}=m,b=i(a,v),C=Kt(y,b.collectionRef);return g.jsx(tu,{ref:C,children:x})});l.displayName=a;const c=n+"CollectionItemSlot",d="data-radix-collection-item",f=He.forwardRef((m,y)=>{const{scope:v,children:x,...b}=m,C=He.useRef(null),I=Kt(y,C),_=i(c,v);return He.useEffect(()=>(_.itemMap.set(C,{ref:C,...b}),()=>void _.itemMap.delete(C))),g.jsx(tu,{[d]:"",ref:I,children:x})});f.displayName=c;function p(m){const y=i(n+"CollectionConsumer",m);return He.useCallback(()=>{const x=y.collectionRef.current;if(!x)return[];const b=Array.from(x.querySelectorAll(`[${d}]`));return Array.from(y.itemMap.values()).sort((_,T)=>b.indexOf(_.ref.current)-b.indexOf(T.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:o,Slot:l,ItemSlot:f},p,r]}var ale=P.createContext(void 0);function n_(n){const e=P.useContext(ale);return n||e||"ltr"}function ar(n){const e=P.useRef(n);return P.useEffect(()=>{e.current=n}),P.useMemo(()=>(...t)=>{var r;return(r=e.current)==null?void 0:r.call(e,...t)},[])}function lle(n,e=globalThis==null?void 0:globalThis.document){const t=ar(n);P.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 cle="DismissableLayer",vE="dismissableLayer.update",ule="dismissableLayer.pointerDownOutside",dle="dismissableLayer.focusOutside",oN,j6=P.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Hp=P.forwardRef((n,e)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:o,onDismiss:a,...l}=n,c=P.useContext(j6),[d,f]=P.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=P.useState({}),y=Kt(e,R=>f(R)),v=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),b=v.indexOf(x),C=d?v.indexOf(d):-1,I=c.layersWithOutsidePointerEventsDisabled.size>0,_=C>=b,T=fle(R=>{const j=R.target,K=[...c.branches].some(U=>U.contains(j));!_||K||(s==null||s(R),o==null||o(R),R.defaultPrevented||a==null||a())},p),A=ple(R=>{const j=R.target;[...c.branches].some(U=>U.contains(j))||(i==null||i(R),o==null||o(R),R.defaultPrevented||a==null||a())},p);return lle(R=>{C===c.layers.size-1&&(r==null||r(R),!R.defaultPrevented&&a&&(R.preventDefault(),a()))},p),P.useEffect(()=>{if(d)return t&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(oN=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),aN(),()=>{t&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=oN)}},[d,p,t,c]),P.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),aN())},[d,c]),P.useEffect(()=>{const R=()=>m({});return document.addEventListener(vE,R),()=>document.removeEventListener(vE,R)},[]),g.jsx(wt.div,{...l,ref:y,style:{pointerEvents:I?_?"auto":"none":void 0,...n.style},onFocusCapture:De(n.onFocusCapture,A.onFocusCapture),onBlurCapture:De(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:De(n.onPointerDownCapture,T.onPointerDownCapture)})});Hp.displayName=cle;var hle="DismissableLayerBranch",N6=P.forwardRef((n,e)=>{const t=P.useContext(j6),r=P.useRef(null),s=Kt(e,r);return P.useEffect(()=>{const i=r.current;if(i)return t.branches.add(i),()=>{t.branches.delete(i)}},[t.branches]),g.jsx(wt.div,{...n,ref:s})});N6.displayName=hle;function fle(n,e=globalThis==null?void 0:globalThis.document){const t=ar(n),r=P.useRef(!1),s=P.useRef(()=>{});return P.useEffect(()=>{const i=a=>{if(a.target&&!r.current){let l=function(){L6(ule,t,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",s.current),s.current=l,e.addEventListener("click",s.current,{once:!0})):l()}else e.removeEventListener("click",s.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",i),e.removeEventListener("click",s.current)}},[e,t]),{onPointerDownCapture:()=>r.current=!0}}function ple(n,e=globalThis==null?void 0:globalThis.document){const t=ar(n),r=P.useRef(!1);return P.useEffect(()=>{const s=i=>{i.target&&!r.current&&L6(dle,t,{originalEvent:i},{discrete:!1})};return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function aN(){const n=new CustomEvent(vE);document.dispatchEvent(n)}function L6(n,e,t,{discrete:r}){const s=t.originalEvent.target,i=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:t});e&&s.addEventListener(n,e,{once:!0}),r?t_(s,i):s.dispatchEvent(i)}var gle=Hp,mle=N6,vC=0;function r_(){P.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??lN()),document.body.insertAdjacentElement("beforeend",n[1]??lN()),vC++,()=>{vC===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),vC--}},[])}function lN(){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 xC="focusScope.autoFocusOnMount",wC="focusScope.autoFocusOnUnmount",cN={bubbles:!1,cancelable:!0},yle="FocusScope",a0=P.forwardRef((n,e)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:i,...o}=n,[a,l]=P.useState(null),c=ar(s),d=ar(i),f=P.useRef(null),p=Kt(e,v=>l(v)),m=P.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;P.useEffect(()=>{if(r){let v=function(I){if(m.paused||!a)return;const _=I.target;a.contains(_)?f.current=_:yl(f.current,{select:!0})},x=function(I){if(m.paused||!a)return;const _=I.relatedTarget;_!==null&&(a.contains(_)||yl(f.current,{select:!0}))},b=function(I){if(document.activeElement===document.body)for(const T of I)T.removedNodes.length>0&&yl(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",x);const C=new MutationObserver(b);return a&&C.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",x),C.disconnect()}}},[r,a,m.paused]),P.useEffect(()=>{if(a){dN.add(m);const v=document.activeElement;if(!a.contains(v)){const b=new CustomEvent(xC,cN);a.addEventListener(xC,c),a.dispatchEvent(b),b.defaultPrevented||(Sle(Cle(F6(a)),{select:!0}),document.activeElement===v&&yl(a))}return()=>{a.removeEventListener(xC,c),setTimeout(()=>{const b=new CustomEvent(wC,cN);a.addEventListener(wC,d),a.dispatchEvent(b),b.defaultPrevented||yl(v??document.body,{select:!0}),a.removeEventListener(wC,d),dN.remove(m)},0)}}},[a,c,d,m]);const y=P.useCallback(v=>{if(!t&&!r||m.paused)return;const x=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,b=document.activeElement;if(x&&b){const C=v.currentTarget,[I,_]=vle(C);I&&_?!v.shiftKey&&b===_?(v.preventDefault(),t&&yl(I,{select:!0})):v.shiftKey&&b===I&&(v.preventDefault(),t&&yl(_,{select:!0})):b===C&&v.preventDefault()}},[t,r,m.paused]);return g.jsx(wt.div,{tabIndex:-1,...o,ref:p,onKeyDown:y})});a0.displayName=yle;function Sle(n,{select:e=!1}={}){const t=document.activeElement;for(const r of n)if(yl(r,{select:e}),document.activeElement!==t)return}function vle(n){const e=F6(n),t=uN(e,n),r=uN(e.reverse(),n);return[t,r]}function F6(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 uN(n,e){for(const t of n)if(!xle(t,{upTo:e}))return t}function xle(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 wle(n){return n instanceof HTMLInputElement&&"select"in n}function yl(n,{select:e=!1}={}){if(n&&n.focus){const t=document.activeElement;n.focus({preventScroll:!0}),n!==t&&wle(n)&&e&&n.select()}}var dN=ble();function ble(){let n=[];return{add(e){const t=n[0];e!==t&&(t==null||t.pause()),n=hN(n,e),n.unshift(e)},remove(e){var t;n=hN(n,e),(t=n[0])==null||t.resume()}}}function hN(n,e){const t=[...n],r=t.indexOf(e);return r!==-1&&t.splice(r,1),t}function Cle(n){return n.filter(e=>e.tagName!=="A")}var Bl=globalThis!=null&&globalThis.document?P.useLayoutEffect:()=>{},Ple=cV.useId||(()=>{}),Ele=0;function _a(n){const[e,t]=P.useState(Ple());return Bl(()=>{t(r=>r??String(Ele++))},[n]),n||(e?`radix-${e}`:"")}const kle=["top","right","bottom","left"],Ul=Math.min,js=Math.max,SS=Math.round,km=Math.floor,Do=n=>({x:n,y:n}),Ile={left:"right",right:"left",bottom:"top",top:"bottom"},_le={start:"end",end:"start"};function xE(n,e,t){return js(n,Ul(e,t))}function Oa(n,e){return typeof n=="function"?n(e):n}function Ra(n){return n.split("-")[0]}function dh(n){return n.split("-")[1]}function s_(n){return n==="x"?"y":"x"}function i_(n){return n==="y"?"height":"width"}function Hl(n){return["top","bottom"].includes(Ra(n))?"y":"x"}function o_(n){return s_(Hl(n))}function Tle(n,e,t){t===void 0&&(t=!1);const r=dh(n),s=o_(n),i=i_(s);let o=s==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(o=vS(o)),[o,vS(o)]}function Mle(n){const e=vS(n);return[wE(n),e,wE(e)]}function wE(n){return n.replace(/start|end/g,e=>_le[e])}function Ale(n,e,t){const r=["left","right"],s=["right","left"],i=["top","bottom"],o=["bottom","top"];switch(n){case"top":case"bottom":return t?e?s:r:e?r:s;case"left":case"right":return e?i:o;default:return[]}}function Ole(n,e,t,r){const s=dh(n);let i=Ale(Ra(n),t==="start",r);return s&&(i=i.map(o=>o+"-"+s),e&&(i=i.concat(i.map(wE)))),i}function vS(n){return n.replace(/left|right|bottom|top/g,e=>Ile[e])}function Rle(n){return{top:0,right:0,bottom:0,left:0,...n}}function z6(n){return typeof n!="number"?Rle(n):{top:n,right:n,bottom:n,left:n}}function xS(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 fN(n,e,t){let{reference:r,floating:s}=n;const i=Hl(e),o=o_(e),a=i_(o),l=Ra(e),c=i==="y",d=r.x+r.width/2-s.width/2,f=r.y+r.height/2-s.height/2,p=r[a]/2-s[a]/2;let m;switch(l){case"top":m={x:d,y:r.y-s.height};break;case"bottom":m={x:d,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:f};break;case"left":m={x:r.x-s.width,y:f};break;default:m={x:r.x,y:r.y}}switch(dh(e)){case"start":m[o]-=p*(t&&c?-1:1);break;case"end":m[o]+=p*(t&&c?-1:1);break}return m}const Dle=async(n,e,t)=>{const{placement:r="bottom",strategy:s="absolute",middleware:i=[],platform:o}=t,a=i.filter(Boolean),l=await(o.isRTL==null?void 0:o.isRTL(e));let c=await o.getElementRects({reference:n,floating:e,strategy:s}),{x:d,y:f}=fN(c,r,l),p=r,m={},y=0;for(let v=0;v<a.length;v++){const{name:x,fn:b}=a[v],{x:C,y:I,data:_,reset:T}=await b({x:d,y:f,initialPlacement:r,placement:p,strategy:s,middlewareData:m,rects:c,platform:o,elements:{reference:n,floating:e}});d=C??d,f=I??f,m={...m,[x]:{...m[x],..._}},T&&y<=50&&(y++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(c=T.rects===!0?await o.getElementRects({reference:n,floating:e,strategy:s}):T.rects),{x:d,y:f}=fN(c,p,l)),v=-1)}return{x:d,y:f,placement:p,strategy:s,middlewareData:m}};async function cp(n,e){var t;e===void 0&&(e={});const{x:r,y:s,platform:i,rects:o,elements:a,strategy:l}=n,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:p=!1,padding:m=0}=Oa(e,n),y=z6(m),x=a[p?f==="floating"?"reference":"floating":f],b=xS(await i.getClippingRect({element:(t=await(i.isElement==null?void 0:i.isElement(x)))==null||t?x:x.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),C=f==="floating"?{x:r,y:s,width:o.floating.width,height:o.floating.height}:o.reference,I=await(i.getOffsetParent==null?void 0:i.getOffsetParent(a.floating)),_=await(i.isElement==null?void 0:i.isElement(I))?await(i.getScale==null?void 0:i.getScale(I))||{x:1,y:1}:{x:1,y:1},T=xS(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:C,offsetParent:I,strategy:l}):C);return{top:(b.top-T.top+y.top)/_.y,bottom:(T.bottom-b.bottom+y.bottom)/_.y,left:(b.left-T.left+y.left)/_.x,right:(T.right-b.right+y.right)/_.x}}const jle=n=>({name:"arrow",options:n,async fn(e){const{x:t,y:r,placement:s,rects:i,platform:o,elements:a,middlewareData:l}=e,{element:c,padding:d=0}=Oa(n,e)||{};if(c==null)return{};const f=z6(d),p={x:t,y:r},m=o_(s),y=i_(m),v=await o.getDimensions(c),x=m==="y",b=x?"top":"left",C=x?"bottom":"right",I=x?"clientHeight":"clientWidth",_=i.reference[y]+i.reference[m]-p[m]-i.floating[y],T=p[m]-i.reference[m],A=await(o.getOffsetParent==null?void 0:o.getOffsetParent(c));let R=A?A[I]:0;(!R||!await(o.isElement==null?void 0:o.isElement(A)))&&(R=a.floating[I]||i.floating[y]);const j=_/2-T/2,K=R/2-v[y]/2-1,U=Ul(f[b],K),J=Ul(f[C],K),z=U,N=R-v[y]-J,L=R/2-v[y]/2+j,V=xE(z,L,N),X=!l.arrow&&dh(s)!=null&&L!==V&&i.reference[y]/2-(L<z?U:J)-v[y]/2<0,W=X?L<z?L-z:L-N:0;return{[m]:p[m]+W,data:{[m]:V,centerOffset:L-V-W,...X&&{alignmentOffset:W}},reset:X}}}),Nle=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,r;const{placement:s,middlewareData:i,rects:o,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:v=!0,...x}=Oa(n,e);if((t=i.arrow)!=null&&t.alignmentOffset)return{};const b=Ra(s),C=Hl(a),I=Ra(a)===a,_=await(l.isRTL==null?void 0:l.isRTL(c.floating)),T=p||(I||!v?[vS(a)]:Mle(a)),A=y!=="none";!p&&A&&T.push(...Ole(a,v,y,_));const R=[a,...T],j=await cp(e,x),K=[];let U=((r=i.flip)==null?void 0:r.overflows)||[];if(d&&K.push(j[b]),f){const L=Tle(s,o,_);K.push(j[L[0]],j[L[1]])}if(U=[...U,{placement:s,overflows:K}],!K.every(L=>L<=0)){var J,z;const L=(((J=i.flip)==null?void 0:J.index)||0)+1,V=R[L];if(V)return{data:{index:L,overflows:U},reset:{placement:V}};let X=(z=U.filter(W=>W.overflows[0]<=0).sort((W,$)=>W.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!X)switch(m){case"bestFit":{var N;const W=(N=U.filter($=>{if(A){const G=Hl($.placement);return G===C||G==="y"}return!0}).map($=>[$.placement,$.overflows.filter(G=>G>0).reduce((G,re)=>G+re,0)]).sort(($,G)=>$[1]-G[1])[0])==null?void 0:N[0];W&&(X=W);break}case"initialPlacement":X=a;break}if(s!==X)return{reset:{placement:X}}}return{}}}};function pN(n,e){return{top:n.top-e.height,right:n.right-e.width,bottom:n.bottom-e.height,left:n.left-e.width}}function gN(n){return kle.some(e=>n[e]>=0)}const Lle=function(n){return n===void 0&&(n={}),{name:"hide",options:n,async fn(e){const{rects:t}=e,{strategy:r="referenceHidden",...s}=Oa(n,e);switch(r){case"referenceHidden":{const i=await cp(e,{...s,elementContext:"reference"}),o=pN(i,t.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:gN(o)}}}case"escaped":{const i=await cp(e,{...s,altBoundary:!0}),o=pN(i,t.floating);return{data:{escapedOffsets:o,escaped:gN(o)}}}default:return{}}}}};async function Fle(n,e){const{placement:t,platform:r,elements:s}=n,i=await(r.isRTL==null?void 0:r.isRTL(s.floating)),o=Ra(t),a=dh(t),l=Hl(t)==="y",c=["left","top"].includes(o)?-1:1,d=i&&l?-1:1,f=Oa(e,n);let{mainAxis:p,crossAxis:m,alignmentAxis:y}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof y=="number"&&(m=a==="end"?y*-1:y),l?{x:m*d,y:p*c}:{x:p*c,y:m*d}}const zle=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,r;const{x:s,y:i,placement:o,middlewareData:a}=e,l=await Fle(e,n);return o===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:i+l.y,data:{...l,placement:o}}}}},$le=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){const{x:t,y:r,placement:s}=e,{mainAxis:i=!0,crossAxis:o=!1,limiter:a={fn:x=>{let{x:b,y:C}=x;return{x:b,y:C}}},...l}=Oa(n,e),c={x:t,y:r},d=await cp(e,l),f=Hl(Ra(s)),p=s_(f);let m=c[p],y=c[f];if(i){const x=p==="y"?"top":"left",b=p==="y"?"bottom":"right",C=m+d[x],I=m-d[b];m=xE(C,m,I)}if(o){const x=f==="y"?"top":"left",b=f==="y"?"bottom":"right",C=y+d[x],I=y-d[b];y=xE(C,y,I)}const v=a.fn({...e,[p]:m,[f]:y});return{...v,data:{x:v.x-t,y:v.y-r,enabled:{[p]:i,[f]:o}}}}}},Ble=function(n){return n===void 0&&(n={}),{options:n,fn(e){const{x:t,y:r,placement:s,rects:i,middlewareData:o}=e,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Oa(n,e),d={x:t,y:r},f=Hl(s),p=s_(f);let m=d[p],y=d[f];const v=Oa(a,e),x=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const I=p==="y"?"height":"width",_=i.reference[p]-i.floating[I]+x.mainAxis,T=i.reference[p]+i.reference[I]-x.mainAxis;m<_?m=_:m>T&&(m=T)}if(c){var b,C;const I=p==="y"?"width":"height",_=["top","left"].includes(Ra(s)),T=i.reference[f]-i.floating[I]+(_&&((b=o.offset)==null?void 0:b[f])||0)+(_?0:x.crossAxis),A=i.reference[f]+i.reference[I]+(_?0:((C=o.offset)==null?void 0:C[f])||0)-(_?x.crossAxis:0);y<T?y=T:y>A&&(y=A)}return{[p]:m,[f]:y}}}},Ule=function(n){return n===void 0&&(n={}),{name:"size",options:n,async fn(e){var t,r;const{placement:s,rects:i,platform:o,elements:a}=e,{apply:l=()=>{},...c}=Oa(n,e),d=await cp(e,c),f=Ra(s),p=dh(s),m=Hl(s)==="y",{width:y,height:v}=i.floating;let x,b;f==="top"||f==="bottom"?(x=f,b=p===(await(o.isRTL==null?void 0:o.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,x=p==="end"?"top":"bottom");const C=v-d.top-d.bottom,I=y-d.left-d.right,_=Ul(v-d[x],C),T=Ul(y-d[b],I),A=!e.middlewareData.shift;let R=_,j=T;if((t=e.middlewareData.shift)!=null&&t.enabled.x&&(j=I),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(R=C),A&&!p){const U=js(d.left,0),J=js(d.right,0),z=js(d.top,0),N=js(d.bottom,0);m?j=y-2*(U!==0||J!==0?U+J:js(d.left,d.right)):R=v-2*(z!==0||N!==0?z+N:js(d.top,d.bottom))}await l({...e,availableWidth:j,availableHeight:R});const K=await o.getDimensions(a.floating);return y!==K.width||v!==K.height?{reset:{rects:!0}}:{}}}};function l0(){return typeof window<"u"}function hh(n){return $6(n)?(n.nodeName||"").toLowerCase():"#document"}function Hs(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function qo(n){var e;return(e=($6(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function $6(n){return l0()?n instanceof Node||n instanceof Hs(n).Node:!1}function Qi(n){return l0()?n instanceof Element||n instanceof Hs(n).Element:!1}function $o(n){return l0()?n instanceof HTMLElement||n instanceof Hs(n).HTMLElement:!1}function mN(n){return!l0()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Hs(n).ShadowRoot}function Kp(n){const{overflow:e,overflowX:t,overflowY:r,display:s}=eo(n);return/auto|scroll|overlay|hidden|clip/.test(e+r+t)&&!["inline","contents"].includes(s)}function Hle(n){return["table","td","th"].includes(hh(n))}function c0(n){return[":popover-open",":modal"].some(e=>{try{return n.matches(e)}catch{return!1}})}function a_(n){const e=l_(),t=Qi(n)?eo(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 Kle(n){let e=Kl(n);for(;$o(e)&&!Wd(e);){if(a_(e))return e;if(c0(e))return null;e=Kl(e)}return null}function l_(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Wd(n){return["html","body","#document"].includes(hh(n))}function eo(n){return Hs(n).getComputedStyle(n)}function u0(n){return Qi(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function Kl(n){if(hh(n)==="html")return n;const e=n.assignedSlot||n.parentNode||mN(n)&&n.host||qo(n);return mN(e)?e.host:e}function B6(n){const e=Kl(n);return Wd(e)?n.ownerDocument?n.ownerDocument.body:n.body:$o(e)&&Kp(e)?e:B6(e)}function up(n,e,t){var r;e===void 0&&(e=[]),t===void 0&&(t=!0);const s=B6(n),i=s===((r=n.ownerDocument)==null?void 0:r.body),o=Hs(s);if(i){const a=bE(o);return e.concat(o,o.visualViewport||[],Kp(s)?s:[],a&&t?up(a):[])}return e.concat(s,up(s,[],t))}function bE(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function U6(n){const e=eo(n);let t=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=$o(n),i=s?n.offsetWidth:t,o=s?n.offsetHeight:r,a=SS(t)!==i||SS(r)!==o;return a&&(t=i,r=o),{width:t,height:r,$:a}}function c_(n){return Qi(n)?n:n.contextElement}function Ad(n){const e=c_(n);if(!$o(e))return Do(1);const t=e.getBoundingClientRect(),{width:r,height:s,$:i}=U6(e);let o=(i?SS(t.width):t.width)/r,a=(i?SS(t.height):t.height)/s;return(!o||!Number.isFinite(o))&&(o=1),(!a||!Number.isFinite(a))&&(a=1),{x:o,y:a}}const Wle=Do(0);function H6(n){const e=Hs(n);return!l_()||!e.visualViewport?Wle:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Vle(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Hs(n)?!1:e}function nu(n,e,t,r){e===void 0&&(e=!1),t===void 0&&(t=!1);const s=n.getBoundingClientRect(),i=c_(n);let o=Do(1);e&&(r?Qi(r)&&(o=Ad(r)):o=Ad(n));const a=Vle(i,t,r)?H6(i):Do(0);let l=(s.left+a.x)/o.x,c=(s.top+a.y)/o.y,d=s.width/o.x,f=s.height/o.y;if(i){const p=Hs(i),m=r&&Qi(r)?Hs(r):r;let y=p,v=bE(y);for(;v&&r&&m!==y;){const x=Ad(v),b=v.getBoundingClientRect(),C=eo(v),I=b.left+(v.clientLeft+parseFloat(C.paddingLeft))*x.x,_=b.top+(v.clientTop+parseFloat(C.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,f*=x.y,l+=I,c+=_,y=Hs(v),v=bE(y)}}return xS({width:d,height:f,x:l,y:c})}function u_(n,e){const t=u0(n).scrollLeft;return e?e.left+t:nu(qo(n)).left+t}function K6(n,e,t){t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=r.left+e.scrollLeft-(t?0:u_(n,r)),i=r.top+e.scrollTop;return{x:s,y:i}}function qle(n){let{elements:e,rect:t,offsetParent:r,strategy:s}=n;const i=s==="fixed",o=qo(r),a=e?c0(e.floating):!1;if(r===o||a&&i)return t;let l={scrollLeft:0,scrollTop:0},c=Do(1);const d=Do(0),f=$o(r);if((f||!f&&!i)&&((hh(r)!=="body"||Kp(o))&&(l=u0(r)),$o(r))){const m=nu(r);c=Ad(r),d.x=m.x+r.clientLeft,d.y=m.y+r.clientTop}const p=o&&!f&&!i?K6(o,l,!0):Do(0);return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-l.scrollLeft*c.x+d.x+p.x,y:t.y*c.y-l.scrollTop*c.y+d.y+p.y}}function Gle(n){return Array.from(n.getClientRects())}function Yle(n){const e=qo(n),t=u0(n),r=n.ownerDocument.body,s=js(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),i=js(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let o=-t.scrollLeft+u_(n);const a=-t.scrollTop;return eo(r).direction==="rtl"&&(o+=js(e.clientWidth,r.clientWidth)-s),{width:s,height:i,x:o,y:a}}function Xle(n,e){const t=Hs(n),r=qo(n),s=t.visualViewport;let i=r.clientWidth,o=r.clientHeight,a=0,l=0;if(s){i=s.width,o=s.height;const c=l_();(!c||c&&e==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:i,height:o,x:a,y:l}}function Zle(n,e){const t=nu(n,!0,e==="fixed"),r=t.top+n.clientTop,s=t.left+n.clientLeft,i=$o(n)?Ad(n):Do(1),o=n.clientWidth*i.x,a=n.clientHeight*i.y,l=s*i.x,c=r*i.y;return{width:o,height:a,x:l,y:c}}function yN(n,e,t){let r;if(e==="viewport")r=Xle(n,t);else if(e==="document")r=Yle(qo(n));else if(Qi(e))r=Zle(e,t);else{const s=H6(n);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return xS(r)}function W6(n,e){const t=Kl(n);return t===e||!Qi(t)||Wd(t)?!1:eo(t).position==="fixed"||W6(t,e)}function Jle(n,e){const t=e.get(n);if(t)return t;let r=up(n,[],!1).filter(a=>Qi(a)&&hh(a)!=="body"),s=null;const i=eo(n).position==="fixed";let o=i?Kl(n):n;for(;Qi(o)&&!Wd(o);){const a=eo(o),l=a_(o);!l&&a.position==="fixed"&&(s=null),(i?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||Kp(o)&&!l&&W6(n,o))?r=r.filter(d=>d!==o):s=a,o=Kl(o)}return e.set(n,r),r}function Qle(n){let{element:e,boundary:t,rootBoundary:r,strategy:s}=n;const o=[...t==="clippingAncestors"?c0(e)?[]:Jle(e,this._c):[].concat(t),r],a=o[0],l=o.reduce((c,d)=>{const f=yN(e,d,s);return c.top=js(f.top,c.top),c.right=Ul(f.right,c.right),c.bottom=Ul(f.bottom,c.bottom),c.left=js(f.left,c.left),c},yN(e,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function ece(n){const{width:e,height:t}=U6(n);return{width:e,height:t}}function tce(n,e,t){const r=$o(e),s=qo(e),i=t==="fixed",o=nu(n,!0,i,e);let a={scrollLeft:0,scrollTop:0};const l=Do(0);if(r||!r&&!i)if((hh(e)!=="body"||Kp(s))&&(a=u0(e)),r){const p=nu(e,!0,i,e);l.x=p.x+e.clientLeft,l.y=p.y+e.clientTop}else s&&(l.x=u_(s));const c=s&&!r&&!i?K6(s,a):Do(0),d=o.left+a.scrollLeft-l.x-c.x,f=o.top+a.scrollTop-l.y-c.y;return{x:d,y:f,width:o.width,height:o.height}}function bC(n){return eo(n).position==="static"}function SN(n,e){if(!$o(n)||eo(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return qo(n)===t&&(t=t.ownerDocument.body),t}function V6(n,e){const t=Hs(n);if(c0(n))return t;if(!$o(n)){let s=Kl(n);for(;s&&!Wd(s);){if(Qi(s)&&!bC(s))return s;s=Kl(s)}return t}let r=SN(n,e);for(;r&&Hle(r)&&bC(r);)r=SN(r,e);return r&&Wd(r)&&bC(r)&&!a_(r)?t:r||Kle(n)||t}const nce=async function(n){const e=this.getOffsetParent||V6,t=this.getDimensions,r=await t(n.floating);return{reference:tce(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function rce(n){return eo(n).direction==="rtl"}const sce={convertOffsetParentRelativeRectToViewportRelativeRect:qle,getDocumentElement:qo,getClippingRect:Qle,getOffsetParent:V6,getElementRects:nce,getClientRects:Gle,getDimensions:ece,getScale:Ad,isElement:Qi,isRTL:rce};function q6(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function ice(n,e){let t=null,r;const s=qo(n);function i(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function o(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),i();const c=n.getBoundingClientRect(),{left:d,top:f,width:p,height:m}=c;if(a||e(),!p||!m)return;const y=km(f),v=km(s.clientWidth-(d+p)),x=km(s.clientHeight-(f+m)),b=km(d),I={rootMargin:-y+"px "+-v+"px "+-x+"px "+-b+"px",threshold:js(0,Ul(1,l))||1};let _=!0;function T(A){const R=A[0].intersectionRatio;if(R!==l){if(!_)return o();R?o(!1,R):r=setTimeout(()=>{o(!1,1e-7)},1e3)}R===1&&!q6(c,n.getBoundingClientRect())&&o(),_=!1}try{t=new IntersectionObserver(T,{...I,root:s.ownerDocument})}catch{t=new IntersectionObserver(T,I)}t.observe(n)}return o(!0),i}function oce(n,e,t,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:i=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=c_(n),d=s||i?[...c?up(c):[],...up(e)]:[];d.forEach(b=>{s&&b.addEventListener("scroll",t,{passive:!0}),i&&b.addEventListener("resize",t)});const f=c&&a?ice(c,t):null;let p=-1,m=null;o&&(m=new ResizeObserver(b=>{let[C]=b;C&&C.target===c&&m&&(m.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var I;(I=m)==null||I.observe(e)})),t()}),c&&!l&&m.observe(c),m.observe(e));let y,v=l?nu(n):null;l&&x();function x(){const b=nu(n);v&&!q6(v,b)&&t(),v=b,y=requestAnimationFrame(x)}return t(),()=>{var b;d.forEach(C=>{s&&C.removeEventListener("scroll",t),i&&C.removeEventListener("resize",t)}),f==null||f(),(b=m)==null||b.disconnect(),m=null,l&&cancelAnimationFrame(y)}}const ace=zle,lce=$le,cce=Nle,uce=Ule,dce=Lle,vN=jle,hce=Ble,fce=(n,e,t)=>{const r=new Map,s={platform:sce,...t},i={...s.platform,_c:r};return Dle(n,e,{...s,platform:i})};var ay=typeof document<"u"?P.useLayoutEffect:P.useEffect;function wS(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(!wS(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 i=s[r];if(!(i==="_owner"&&n.$$typeof)&&!wS(n[i],e[i]))return!1}return!0}return n!==n&&e!==e}function G6(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function xN(n,e){const t=G6(n);return Math.round(e*t)/t}function CC(n){const e=P.useRef(n);return ay(()=>{e.current=n}),e}function pce(n){n===void 0&&(n={});const{placement:e="bottom",strategy:t="absolute",middleware:r=[],platform:s,elements:{reference:i,floating:o}={},transform:a=!0,whileElementsMounted:l,open:c}=n,[d,f]=P.useState({x:0,y:0,strategy:t,placement:e,middlewareData:{},isPositioned:!1}),[p,m]=P.useState(r);wS(p,r)||m(r);const[y,v]=P.useState(null),[x,b]=P.useState(null),C=P.useCallback($=>{$!==A.current&&(A.current=$,v($))},[]),I=P.useCallback($=>{$!==R.current&&(R.current=$,b($))},[]),_=i||y,T=o||x,A=P.useRef(null),R=P.useRef(null),j=P.useRef(d),K=l!=null,U=CC(l),J=CC(s),z=CC(c),N=P.useCallback(()=>{if(!A.current||!R.current)return;const $={placement:e,strategy:t,middleware:p};J.current&&($.platform=J.current),fce(A.current,R.current,$).then(G=>{const re={...G,isPositioned:z.current!==!1};L.current&&!wS(j.current,re)&&(j.current=re,ah.flushSync(()=>{f(re)}))})},[p,e,t,J,z]);ay(()=>{c===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const L=P.useRef(!1);ay(()=>(L.current=!0,()=>{L.current=!1}),[]),ay(()=>{if(_&&(A.current=_),T&&(R.current=T),_&&T){if(U.current)return U.current(_,T,N);N()}},[_,T,N,U,K]);const V=P.useMemo(()=>({reference:A,floating:R,setReference:C,setFloating:I}),[C,I]),X=P.useMemo(()=>({reference:_,floating:T}),[_,T]),W=P.useMemo(()=>{const $={position:t,left:0,top:0};if(!X.floating)return $;const G=xN(X.floating,d.x),re=xN(X.floating,d.y);return a?{...$,transform:"translate("+G+"px, "+re+"px)",...G6(X.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:G,top:re}},[t,a,X.floating,d.x,d.y]);return P.useMemo(()=>({...d,update:N,refs:V,elements:X,floatingStyles:W}),[d,N,V,X,W])}const gce=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?vN({element:r.current,padding:s}).fn(t):{}:r?vN({element:r,padding:s}).fn(t):{}}}},mce=(n,e)=>({...ace(n),options:[n,e]}),yce=(n,e)=>({...lce(n),options:[n,e]}),Sce=(n,e)=>({...hce(n),options:[n,e]}),vce=(n,e)=>({...cce(n),options:[n,e]}),xce=(n,e)=>({...uce(n),options:[n,e]}),wce=(n,e)=>({...dce(n),options:[n,e]}),bce=(n,e)=>({...gce(n),options:[n,e]});var Cce="Arrow",Y6=P.forwardRef((n,e)=>{const{children:t,width:r=10,height:s=5,...i}=n;return g.jsx(wt.svg,{...i,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:n.asChild?t:g.jsx("polygon",{points:"0,0 30,0 15,10"})})});Y6.displayName=Cce;var Pce=Y6;function X6(n){const[e,t]=P.useState(void 0);return Bl(()=>{if(n){t({width:n.offsetWidth,height:n.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const i=s[0];let o,a;if("borderBoxSize"in i){const l=i.borderBoxSize,c=Array.isArray(l)?l[0]:l;o=c.inlineSize,a=c.blockSize}else o=n.offsetWidth,a=n.offsetHeight;t({width:o,height:a})});return r.observe(n,{box:"border-box"}),()=>r.unobserve(n)}else t(void 0)},[n]),e}var d_="Popper",[Z6,d0]=Vo(d_),[Ece,J6]=Z6(d_),Q6=n=>{const{__scopePopper:e,children:t}=n,[r,s]=P.useState(null);return g.jsx(Ece,{scope:e,anchor:r,onAnchorChange:s,children:t})};Q6.displayName=d_;var e8="PopperAnchor",t8=P.forwardRef((n,e)=>{const{__scopePopper:t,virtualRef:r,...s}=n,i=J6(e8,t),o=P.useRef(null),a=Kt(e,o);return P.useEffect(()=>{i.onAnchorChange((r==null?void 0:r.current)||o.current)}),r?null:g.jsx(wt.div,{...s,ref:a})});t8.displayName=e8;var h_="PopperContent",[kce,Ice]=Z6(h_),n8=P.forwardRef((n,e)=>{var Re,Ce,_e,Ve,it,cn;const{__scopePopper:t,side:r="bottom",sideOffset:s=0,align:i="center",alignOffset:o=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:p=!1,updatePositionStrategy:m="optimized",onPlaced:y,...v}=n,x=J6(h_,t),[b,C]=P.useState(null),I=Kt(e,It=>C(It)),[_,T]=P.useState(null),A=X6(_),R=(A==null?void 0:A.width)??0,j=(A==null?void 0:A.height)??0,K=r+(i!=="center"?"-"+i:""),U=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},J=Array.isArray(c)?c:[c],z=J.length>0,N={padding:U,boundary:J.filter(Tce),altBoundary:z},{refs:L,floatingStyles:V,placement:X,isPositioned:W,middlewareData:$}=pce({strategy:"fixed",placement:K,whileElementsMounted:(...It)=>oce(...It,{animationFrame:m==="always"}),elements:{reference:x.anchor},middleware:[mce({mainAxis:s+j,alignmentAxis:o}),l&&yce({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Sce():void 0,...N}),l&&vce({...N}),xce({...N,apply:({elements:It,rects:Jt,availableWidth:jt,availableHeight:Mt})=>{const{width:Yr,height:Xr}=Jt.reference,Zr=It.floating.style;Zr.setProperty("--radix-popper-available-width",`${jt}px`),Zr.setProperty("--radix-popper-available-height",`${Mt}px`),Zr.setProperty("--radix-popper-anchor-width",`${Yr}px`),Zr.setProperty("--radix-popper-anchor-height",`${Xr}px`)}}),_&&bce({element:_,padding:a}),Mce({arrowWidth:R,arrowHeight:j}),p&&wce({strategy:"referenceHidden",...N})]}),[G,re]=i8(X),H=ar(y);Bl(()=>{W&&(H==null||H())},[W,H]);const ne=(Re=$.arrow)==null?void 0:Re.x,ge=(Ce=$.arrow)==null?void 0:Ce.y,Pe=((_e=$.arrow)==null?void 0:_e.centerOffset)!==0,[ce,Be]=P.useState();return Bl(()=>{b&&Be(window.getComputedStyle(b).zIndex)},[b]),g.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...V,transform:W?V.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ce,"--radix-popper-transform-origin":[(Ve=$.transformOrigin)==null?void 0:Ve.x,(it=$.transformOrigin)==null?void 0:it.y].join(" "),...((cn=$.hide)==null?void 0:cn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:g.jsx(kce,{scope:t,placedSide:G,onArrowChange:T,arrowX:ne,arrowY:ge,shouldHideArrow:Pe,children:g.jsx(wt.div,{"data-side":G,"data-align":re,...v,ref:I,style:{...v.style,animation:W?void 0:"none"}})})})});n8.displayName=h_;var r8="PopperArrow",_ce={top:"bottom",right:"left",bottom:"top",left:"right"},s8=P.forwardRef(function(e,t){const{__scopePopper:r,...s}=e,i=Ice(r8,r),o=_ce[i.placedSide];return g.jsx("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[o]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:g.jsx(Pce,{...s,ref:t,style:{...s.style,display:"block"}})})});s8.displayName=r8;function Tce(n){return n!==null}var Mce=n=>({name:"transformOrigin",options:n,fn(e){var x,b,C;const{placement:t,rects:r,middlewareData:s}=e,o=((x=s.arrow)==null?void 0:x.centerOffset)!==0,a=o?0:n.arrowWidth,l=o?0:n.arrowHeight,[c,d]=i8(t),f={start:"0%",center:"50%",end:"100%"}[d],p=(((b=s.arrow)==null?void 0:b.x)??0)+a/2,m=(((C=s.arrow)==null?void 0:C.y)??0)+l/2;let y="",v="";return c==="bottom"?(y=o?f:`${p}px`,v=`${-l}px`):c==="top"?(y=o?f:`${p}px`,v=`${r.floating.height+l}px`):c==="right"?(y=`${-l}px`,v=o?f:`${m}px`):c==="left"&&(y=`${r.floating.width+l}px`,v=o?f:`${m}px`),{data:{x:y,y:v}}}});function i8(n){const[e,t="center"]=n.split("-");return[e,t]}var f_=Q6,p_=t8,o8=n8,a8=s8,Ace="Portal",Wp=P.forwardRef((n,e)=>{var a;const{container:t,...r}=n,[s,i]=P.useState(!1);Bl(()=>i(!0),[]);const o=t||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return o?Tz.createPortal(g.jsx(wt.div,{...r,ref:e}),o):null});Wp.displayName=Ace;function Oce(n,e){return P.useReducer((t,r)=>e[t][r]??t,n)}var so=n=>{const{present:e,children:t}=n,r=Rce(e),s=typeof t=="function"?t({present:r.isPresent}):P.Children.only(t),i=Kt(r.ref,Dce(s));return typeof t=="function"||r.isPresent?P.cloneElement(s,{ref:i}):null};so.displayName="Presence";function Rce(n){const[e,t]=P.useState(),r=P.useRef({}),s=P.useRef(n),i=P.useRef("none"),o=n?"mounted":"unmounted",[a,l]=Oce(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return P.useEffect(()=>{const c=Im(r.current);i.current=a==="mounted"?c:"none"},[a]),Bl(()=>{const c=r.current,d=s.current;if(d!==n){const p=i.current,m=Im(c);n?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==m?"ANIMATION_OUT":"UNMOUNT"),s.current=n}},[n,l]),Bl(()=>{if(e){let c;const d=e.ownerDocument.defaultView??window,f=m=>{const v=Im(r.current).includes(m.animationName);if(m.target===e&&v&&(l("ANIMATION_END"),!s.current)){const x=e.style.animationFillMode;e.style.animationFillMode="forwards",c=d.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=x)})}},p=m=>{m.target===e&&(i.current=Im(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",f),e.addEventListener("animationend",f),()=>{d.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",f),e.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:P.useCallback(c=>{c&&(r.current=getComputedStyle(c)),t(c)},[])}}function Im(n){return(n==null?void 0:n.animationName)||"none"}function Dce(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 Ql({prop:n,defaultProp:e,onChange:t=()=>{}}){const[r,s]=jce({defaultProp:e,onChange:t}),i=n!==void 0,o=i?n:r,a=ar(t),l=P.useCallback(c=>{if(i){const f=typeof c=="function"?c(n):c;f!==n&&a(f)}else s(c)},[i,n,s,a]);return[o,l]}function jce({defaultProp:n,onChange:e}){const t=P.useState(n),[r]=t,s=P.useRef(r),i=ar(e);return P.useEffect(()=>{s.current!==r&&(i(r),s.current=r)},[r,s,i]),t}var PC="rovingFocusGroup.onEntryFocus",Nce={bubbles:!1,cancelable:!0},h0="RovingFocusGroup",[CE,l8,Lce]=o0(h0),[Fce,c8]=Vo(h0,[Lce]),[zce,$ce]=Fce(h0),u8=P.forwardRef((n,e)=>g.jsx(CE.Provider,{scope:n.__scopeRovingFocusGroup,children:g.jsx(CE.Slot,{scope:n.__scopeRovingFocusGroup,children:g.jsx(Bce,{...n,ref:e})})}));u8.displayName=h0;var Bce=P.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:s=!1,dir:i,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...f}=n,p=P.useRef(null),m=Kt(e,p),y=n_(i),[v=null,x]=Ql({prop:o,defaultProp:a,onChange:l}),[b,C]=P.useState(!1),I=ar(c),_=l8(t),T=P.useRef(!1),[A,R]=P.useState(0);return P.useEffect(()=>{const j=p.current;if(j)return j.addEventListener(PC,I),()=>j.removeEventListener(PC,I)},[I]),g.jsx(zce,{scope:t,orientation:r,dir:y,loop:s,currentTabStopId:v,onItemFocus:P.useCallback(j=>x(j),[x]),onItemShiftTab:P.useCallback(()=>C(!0),[]),onFocusableItemAdd:P.useCallback(()=>R(j=>j+1),[]),onFocusableItemRemove:P.useCallback(()=>R(j=>j-1),[]),children:g.jsx(wt.div,{tabIndex:b||A===0?-1:0,"data-orientation":r,...f,ref:m,style:{outline:"none",...n.style},onMouseDown:De(n.onMouseDown,()=>{T.current=!0}),onFocus:De(n.onFocus,j=>{const K=!T.current;if(j.target===j.currentTarget&&K&&!b){const U=new CustomEvent(PC,Nce);if(j.currentTarget.dispatchEvent(U),!U.defaultPrevented){const J=_().filter(X=>X.focusable),z=J.find(X=>X.active),N=J.find(X=>X.id===v),V=[z,N,...J].filter(Boolean).map(X=>X.ref.current);f8(V,d)}}T.current=!1}),onBlur:De(n.onBlur,()=>C(!1))})})}),d8="RovingFocusGroupItem",h8=P.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:s=!1,tabStopId:i,...o}=n,a=_a(),l=i||a,c=$ce(d8,t),d=c.currentTabStopId===l,f=l8(t),{onFocusableItemAdd:p,onFocusableItemRemove:m}=c;return P.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),g.jsx(CE.ItemSlot,{scope:t,id:l,focusable:r,active:s,children:g.jsx(wt.span,{tabIndex:d?0:-1,"data-orientation":c.orientation,...o,ref:e,onMouseDown:De(n.onMouseDown,y=>{r?c.onItemFocus(l):y.preventDefault()}),onFocus:De(n.onFocus,()=>c.onItemFocus(l)),onKeyDown:De(n.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){c.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const v=Kce(y,c.orientation,c.dir);if(v!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let b=f().filter(C=>C.focusable).map(C=>C.ref.current);if(v==="last")b.reverse();else if(v==="prev"||v==="next"){v==="prev"&&b.reverse();const C=b.indexOf(y.currentTarget);b=c.loop?Wce(b,C+1):b.slice(C+1)}setTimeout(()=>f8(b))}})})})});h8.displayName=d8;var Uce={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Hce(n,e){return e!=="rtl"?n:n==="ArrowLeft"?"ArrowRight":n==="ArrowRight"?"ArrowLeft":n}function Kce(n,e,t){const r=Hce(n.key,t);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Uce[r]}function f8(n,e=!1){const t=document.activeElement;for(const r of n)if(r===t||(r.focus({preventScroll:e}),document.activeElement!==t))return}function Wce(n,e){return n.map((t,r)=>n[(e+r)%n.length])}var Vce=u8,qce=h8,Gce=function(n){if(typeof document>"u")return null;var e=Array.isArray(n)?n[0]:n;return e.ownerDocument.body},ad=new WeakMap,_m=new WeakMap,Tm={},EC=0,p8=function(n){return n&&(n.host||p8(n.parentNode))},Yce=function(n,e){return e.map(function(t){if(n.contains(t))return t;var r=p8(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})},Xce=function(n,e,t,r){var s=Yce(e,Array.isArray(n)?n:[n]);Tm[t]||(Tm[t]=new WeakMap);var i=Tm[t],o=[],a=new Set,l=new Set(s),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};s.forEach(c);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(p){if(a.has(p))d(p);else try{var m=p.getAttribute(r),y=m!==null&&m!=="false",v=(ad.get(p)||0)+1,x=(i.get(p)||0)+1;ad.set(p,v),i.set(p,x),o.push(p),v===1&&y&&_m.set(p,!0),x===1&&p.setAttribute(t,"true"),y||p.setAttribute(r,"true")}catch(b){console.error("aria-hidden: cannot operate on ",p,b)}})};return d(e),a.clear(),EC++,function(){o.forEach(function(f){var p=ad.get(f)-1,m=i.get(f)-1;ad.set(f,p),i.set(f,m),p||(_m.has(f)||f.removeAttribute(r),_m.delete(f)),m||f.removeAttribute(t)}),EC--,EC||(ad=new WeakMap,ad=new WeakMap,_m=new WeakMap,Tm={})}},g_=function(n,e,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(n)?n:[n]),s=Gce(n);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),Xce(r,s,t,"aria-hidden")):function(){return null}},_o=function(){return _o=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},_o.apply(this,arguments)};function g8(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 Zce(n,e,t){if(t||arguments.length===2)for(var r=0,s=e.length,i;r<s;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return n.concat(i||Array.prototype.slice.call(e))}var ly="right-scroll-bar-position",cy="width-before-scroll-bar",Jce="with-scroll-bars-hidden",Qce="--removed-body-scroll-bar-size";function kC(n,e){return typeof n=="function"?n(e):n&&(n.current=e),n}function eue(n,e){var t=P.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 tue=typeof window<"u"?P.useLayoutEffect:P.useEffect,wN=new WeakMap;function nue(n,e){var t=eue(null,function(r){return n.forEach(function(s){return kC(s,r)})});return tue(function(){var r=wN.get(t);if(r){var s=new Set(r),i=new Set(n),o=t.current;s.forEach(function(a){i.has(a)||kC(a,null)}),i.forEach(function(a){s.has(a)||kC(a,o)})}wN.set(t,n)},[n]),t}function rue(n){return n}function sue(n,e){e===void 0&&(e=rue);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(i){var o=e(i,r);return t.push(o),function(){t=t.filter(function(a){return a!==o})}},assignSyncMedium:function(i){for(r=!0;t.length;){var o=t;t=[],o.forEach(i)}t={push:function(a){return i(a)},filter:function(){return t}}},assignMedium:function(i){r=!0;var o=[];if(t.length){var a=t;t=[],a.forEach(i),o=t}var l=function(){var d=o;o=[],d.forEach(i)},c=function(){return Promise.resolve().then(l)};c(),t={push:function(d){o.push(d),c()},filter:function(d){return o=o.filter(d),t}}}};return s}function iue(n){n===void 0&&(n={});var e=sue(null);return e.options=_o({async:!0,ssr:!1},n),e}var m8=function(n){var e=n.sideCar,t=g8(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 P.createElement(r,_o({},t))};m8.isSideCarExport=!0;function oue(n,e){return n.useMedium(e),m8}var y8=iue(),IC=function(){},f0=P.forwardRef(function(n,e){var t=P.useRef(null),r=P.useState({onScrollCapture:IC,onWheelCapture:IC,onTouchMoveCapture:IC}),s=r[0],i=r[1],o=n.forwardProps,a=n.children,l=n.className,c=n.removeScrollBar,d=n.enabled,f=n.shards,p=n.sideCar,m=n.noIsolation,y=n.inert,v=n.allowPinchZoom,x=n.as,b=x===void 0?"div":x,C=n.gapMode,I=g8(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),_=p,T=nue([t,e]),A=_o(_o({},I),s);return P.createElement(P.Fragment,null,d&&P.createElement(_,{sideCar:y8,removeScrollBar:c,shards:f,noIsolation:m,inert:y,setCallbacks:i,allowPinchZoom:!!v,lockRef:t,gapMode:C}),o?P.cloneElement(P.Children.only(a),_o(_o({},A),{ref:T})):P.createElement(b,_o({},A,{className:l,ref:T}),a))});f0.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};f0.classNames={fullWidth:cy,zeroRight:ly};var aue=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function lue(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var e=aue();return e&&n.setAttribute("nonce",e),n}function cue(n,e){n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}function uue(n){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(n)}var due=function(){var n=0,e=null;return{add:function(t){n==0&&(e=lue())&&(cue(e,t),uue(e)),n++},remove:function(){n--,!n&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},hue=function(){var n=due();return function(e,t){P.useEffect(function(){return n.add(e),function(){n.remove()}},[e&&t])}},S8=function(){var n=hue(),e=function(t){var r=t.styles,s=t.dynamic;return n(r,s),null};return e},fue={left:0,top:0,right:0,gap:0},_C=function(n){return parseInt(n||"",10)||0},pue=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[_C(t),_C(r),_C(s)]},gue=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return fue;var e=pue(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])}},mue=S8(),Od="data-scroll-locked",yue=function(n,e,t,r){var s=n.left,i=n.top,o=n.right,a=n.gap;return t===void 0&&(t="margin"),`
295
+ .`.concat(Jce,` {
296
+ overflow: hidden `).concat(r,`;
297
+ padding-right: `).concat(a,"px ").concat(r,`;
298
+ }
299
+ body[`).concat(Od,`] {
300
+ overflow: hidden `).concat(r,`;
301
+ overscroll-behavior: contain;
302
+ `).concat([e&&"position: relative ".concat(r,";"),t==="margin"&&`
303
+ padding-left: `.concat(s,`px;
304
+ padding-top: `).concat(i,`px;
305
+ padding-right: `).concat(o,`px;
306
+ margin-left:0;
307
+ margin-top:0;
308
+ margin-right: `).concat(a,"px ").concat(r,`;
309
+ `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
310
+ }
311
+
312
+ .`).concat(ly,` {
313
+ right: `).concat(a,"px ").concat(r,`;
314
+ }
315
+
316
+ .`).concat(cy,` {
317
+ margin-right: `).concat(a,"px ").concat(r,`;
318
+ }
319
+
320
+ .`).concat(ly," .").concat(ly,` {
321
+ right: 0 `).concat(r,`;
322
+ }
323
+
324
+ .`).concat(cy," .").concat(cy,` {
325
+ margin-right: 0 `).concat(r,`;
326
+ }
327
+
328
+ body[`).concat(Od,`] {
329
+ `).concat(Qce,": ").concat(a,`px;
330
+ }
331
+ `)},bN=function(){var n=parseInt(document.body.getAttribute(Od)||"0",10);return isFinite(n)?n:0},Sue=function(){P.useEffect(function(){return document.body.setAttribute(Od,(bN()+1).toString()),function(){var n=bN()-1;n<=0?document.body.removeAttribute(Od):document.body.setAttribute(Od,n.toString())}},[])},vue=function(n){var e=n.noRelative,t=n.noImportant,r=n.gapMode,s=r===void 0?"margin":r;Sue();var i=P.useMemo(function(){return gue(s)},[s]);return P.createElement(mue,{styles:yue(i,!e,s,t?"":"!important")})},PE=!1;if(typeof window<"u")try{var Mm=Object.defineProperty({},"passive",{get:function(){return PE=!0,!0}});window.addEventListener("test",Mm,Mm),window.removeEventListener("test",Mm,Mm)}catch{PE=!1}var ld=PE?{passive:!1}:!1,xue=function(n){return n.tagName==="TEXTAREA"},v8=function(n,e){if(!(n instanceof Element))return!1;var t=window.getComputedStyle(n);return t[e]!=="hidden"&&!(t.overflowY===t.overflowX&&!xue(n)&&t[e]==="visible")},wue=function(n){return v8(n,"overflowY")},bue=function(n){return v8(n,"overflowX")},CN=function(n,e){var t=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=x8(n,r);if(s){var i=w8(n,r),o=i[1],a=i[2];if(o>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},Cue=function(n){var e=n.scrollTop,t=n.scrollHeight,r=n.clientHeight;return[e,t,r]},Pue=function(n){var e=n.scrollLeft,t=n.scrollWidth,r=n.clientWidth;return[e,t,r]},x8=function(n,e){return n==="v"?wue(e):bue(e)},w8=function(n,e){return n==="v"?Cue(e):Pue(e)},Eue=function(n,e){return n==="h"&&e==="rtl"?-1:1},kue=function(n,e,t,r,s){var i=Eue(n,window.getComputedStyle(e).direction),o=i*r,a=t.target,l=e.contains(a),c=!1,d=o>0,f=0,p=0;do{var m=w8(n,a),y=m[0],v=m[1],x=m[2],b=v-x-i*y;(y||b)&&x8(n,a)&&(f+=b,p+=y),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(e.contains(a)||e===a));return(d&&Math.abs(f)<1||!d&&Math.abs(p)<1)&&(c=!0),c},Am=function(n){return"changedTouches"in n?[n.changedTouches[0].clientX,n.changedTouches[0].clientY]:[0,0]},PN=function(n){return[n.deltaX,n.deltaY]},EN=function(n){return n&&"current"in n?n.current:n},Iue=function(n,e){return n[0]===e[0]&&n[1]===e[1]},_ue=function(n){return`
332
+ .block-interactivity-`.concat(n,` {pointer-events: none;}
333
+ .allow-interactivity-`).concat(n,` {pointer-events: all;}
334
+ `)},Tue=0,cd=[];function Mue(n){var e=P.useRef([]),t=P.useRef([0,0]),r=P.useRef(),s=P.useState(Tue++)[0],i=P.useState(S8)[0],o=P.useRef(n);P.useEffect(function(){o.current=n},[n]),P.useEffect(function(){if(n.inert){document.body.classList.add("block-interactivity-".concat(s));var v=Zce([n.lockRef.current],(n.shards||[]).map(EN),!0).filter(Boolean);return v.forEach(function(x){return x.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),v.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(s))})}}},[n.inert,n.lockRef.current,n.shards]);var a=P.useCallback(function(v,x){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!o.current.allowPinchZoom;var b=Am(v),C=t.current,I="deltaX"in v?v.deltaX:C[0]-b[0],_="deltaY"in v?v.deltaY:C[1]-b[1],T,A=v.target,R=Math.abs(I)>Math.abs(_)?"h":"v";if("touches"in v&&R==="h"&&A.type==="range")return!1;var j=CN(R,A);if(!j)return!0;if(j?T=R:(T=R==="v"?"h":"v",j=CN(R,A)),!j)return!1;if(!r.current&&"changedTouches"in v&&(I||_)&&(r.current=T),!T)return!0;var K=r.current||T;return kue(K,x,v,K==="h"?I:_)},[]),l=P.useCallback(function(v){var x=v;if(!(!cd.length||cd[cd.length-1]!==i)){var b="deltaY"in x?PN(x):Am(x),C=e.current.filter(function(T){return T.name===x.type&&(T.target===x.target||x.target===T.shadowParent)&&Iue(T.delta,b)})[0];if(C&&C.should){x.cancelable&&x.preventDefault();return}if(!C){var I=(o.current.shards||[]).map(EN).filter(Boolean).filter(function(T){return T.contains(x.target)}),_=I.length>0?a(x,I[0]):!o.current.noIsolation;_&&x.cancelable&&x.preventDefault()}}},[]),c=P.useCallback(function(v,x,b,C){var I={name:v,delta:x,target:b,should:C,shadowParent:Aue(b)};e.current.push(I),setTimeout(function(){e.current=e.current.filter(function(_){return _!==I})},1)},[]),d=P.useCallback(function(v){t.current=Am(v),r.current=void 0},[]),f=P.useCallback(function(v){c(v.type,PN(v),v.target,a(v,n.lockRef.current))},[]),p=P.useCallback(function(v){c(v.type,Am(v),v.target,a(v,n.lockRef.current))},[]);P.useEffect(function(){return cd.push(i),n.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener("wheel",l,ld),document.addEventListener("touchmove",l,ld),document.addEventListener("touchstart",d,ld),function(){cd=cd.filter(function(v){return v!==i}),document.removeEventListener("wheel",l,ld),document.removeEventListener("touchmove",l,ld),document.removeEventListener("touchstart",d,ld)}},[]);var m=n.removeScrollBar,y=n.inert;return P.createElement(P.Fragment,null,y?P.createElement(i,{styles:_ue(s)}):null,m?P.createElement(vue,{gapMode:n.gapMode}):null)}function Aue(n){for(var e=null;n!==null;)n instanceof ShadowRoot&&(e=n.host,n=n.host),n=n.parentNode;return e}const Oue=oue(y8,Mue);var p0=P.forwardRef(function(n,e){return P.createElement(f0,_o({},n,{ref:e,sideCar:Oue}))});p0.classNames=f0.classNames;var EE=["Enter"," "],Rue=["ArrowDown","PageUp","Home"],b8=["ArrowUp","PageDown","End"],Due=[...Rue,...b8],jue={ltr:[...EE,"ArrowRight"],rtl:[...EE,"ArrowLeft"]},Nue={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Vp="Menu",[dp,Lue,Fue]=o0(Vp),[mu,g0]=Vo(Vp,[Fue,d0,c8]),qp=d0(),C8=c8(),[P8,ec]=mu(Vp),[zue,Gp]=mu(Vp),E8=n=>{const{__scopeMenu:e,open:t=!1,children:r,dir:s,onOpenChange:i,modal:o=!0}=n,a=qp(e),[l,c]=P.useState(null),d=P.useRef(!1),f=ar(i),p=n_(s);return P.useEffect(()=>{const m=()=>{d.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>d.current=!1;return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),g.jsx(f_,{...a,children:g.jsx(P8,{scope:e,open:t,onOpenChange:f,content:l,onContentChange:c,children:g.jsx(zue,{scope:e,onClose:P.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:p,modal:o,children:r})})})};E8.displayName=Vp;var $ue="MenuAnchor",m_=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=qp(t);return g.jsx(p_,{...s,...r,ref:e})});m_.displayName=$ue;var y_="MenuPortal",[Bue,k8]=mu(y_,{forceMount:void 0}),I8=n=>{const{__scopeMenu:e,forceMount:t,children:r,container:s}=n,i=ec(y_,e);return g.jsx(Bue,{scope:e,forceMount:t,children:g.jsx(so,{present:t||i.open,children:g.jsx(Wp,{asChild:!0,container:s,children:r})})})};I8.displayName=y_;var xi="MenuContent",[Uue,S_]=mu(xi),_8=P.forwardRef((n,e)=>{const t=k8(xi,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,i=ec(xi,n.__scopeMenu),o=Gp(xi,n.__scopeMenu);return g.jsx(dp.Provider,{scope:n.__scopeMenu,children:g.jsx(so,{present:r||i.open,children:g.jsx(dp.Slot,{scope:n.__scopeMenu,children:o.modal?g.jsx(Hue,{...s,ref:e}):g.jsx(Kue,{...s,ref:e})})})})}),Hue=P.forwardRef((n,e)=>{const t=ec(xi,n.__scopeMenu),r=P.useRef(null),s=Kt(e,r);return P.useEffect(()=>{const i=r.current;if(i)return g_(i)},[]),g.jsx(v_,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:De(n.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),Kue=P.forwardRef((n,e)=>{const t=ec(xi,n.__scopeMenu);return g.jsx(v_,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),v_=P.forwardRef((n,e)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:s,onOpenAutoFocus:i,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:m,disableOutsideScroll:y,...v}=n,x=ec(xi,t),b=Gp(xi,t),C=qp(t),I=C8(t),_=Lue(t),[T,A]=P.useState(null),R=P.useRef(null),j=Kt(e,R,x.onContentChange),K=P.useRef(0),U=P.useRef(""),J=P.useRef(0),z=P.useRef(null),N=P.useRef("right"),L=P.useRef(0),V=y?p0:P.Fragment,X=y?{as:tu,allowPinchZoom:!0}:void 0,W=G=>{var Re,Ce;const re=U.current+G,H=_().filter(_e=>!_e.disabled),ne=document.activeElement,ge=(Re=H.find(_e=>_e.ref.current===ne))==null?void 0:Re.textValue,Pe=H.map(_e=>_e.textValue),ce=nde(Pe,re,ge),Be=(Ce=H.find(_e=>_e.textValue===ce))==null?void 0:Ce.ref.current;(function _e(Ve){U.current=Ve,window.clearTimeout(K.current),Ve!==""&&(K.current=window.setTimeout(()=>_e(""),1e3))})(re),Be&&setTimeout(()=>Be.focus())};P.useEffect(()=>()=>window.clearTimeout(K.current),[]),r_();const $=P.useCallback(G=>{var H,ne;return N.current===((H=z.current)==null?void 0:H.side)&&sde(G,(ne=z.current)==null?void 0:ne.area)},[]);return g.jsx(Uue,{scope:t,searchRef:U,onItemEnter:P.useCallback(G=>{$(G)&&G.preventDefault()},[$]),onItemLeave:P.useCallback(G=>{var re;$(G)||((re=R.current)==null||re.focus(),A(null))},[$]),onTriggerLeave:P.useCallback(G=>{$(G)&&G.preventDefault()},[$]),pointerGraceTimerRef:J,onPointerGraceIntentChange:P.useCallback(G=>{z.current=G},[]),children:g.jsx(V,{...X,children:g.jsx(a0,{asChild:!0,trapped:s,onMountAutoFocus:De(i,G=>{var re;G.preventDefault(),(re=R.current)==null||re.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:g.jsx(Hp,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:m,children:g.jsx(Vce,{asChild:!0,...I,dir:b.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:A,onEntryFocus:De(l,G=>{b.isUsingKeyboardRef.current||G.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(o8,{role:"menu","aria-orientation":"vertical","data-state":W8(x.open),"data-radix-menu-content":"",dir:b.dir,...C,...v,ref:j,style:{outline:"none",...v.style},onKeyDown:De(v.onKeyDown,G=>{const H=G.target.closest("[data-radix-menu-content]")===G.currentTarget,ne=G.ctrlKey||G.altKey||G.metaKey,ge=G.key.length===1;H&&(G.key==="Tab"&&G.preventDefault(),!ne&&ge&&W(G.key));const Pe=R.current;if(G.target!==Pe||!Due.includes(G.key))return;G.preventDefault();const Be=_().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);b8.includes(G.key)&&Be.reverse(),ede(Be)}),onBlur:De(n.onBlur,G=>{G.currentTarget.contains(G.target)||(window.clearTimeout(K.current),U.current="")}),onPointerMove:De(n.onPointerMove,hp(G=>{const re=G.target,H=L.current!==G.clientX;if(G.currentTarget.contains(re)&&H){const ne=G.clientX>L.current?"right":"left";N.current=ne,L.current=G.clientX}}))})})})})})})});_8.displayName=xi;var Wue="MenuGroup",x_=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return g.jsx(wt.div,{role:"group",...r,ref:e})});x_.displayName=Wue;var Vue="MenuLabel",T8=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return g.jsx(wt.div,{...r,ref:e})});T8.displayName=Vue;var bS="MenuItem",kN="menu.itemSelect",m0=P.forwardRef((n,e)=>{const{disabled:t=!1,onSelect:r,...s}=n,i=P.useRef(null),o=Gp(bS,n.__scopeMenu),a=S_(bS,n.__scopeMenu),l=Kt(e,i),c=P.useRef(!1),d=()=>{const f=i.current;if(!t&&f){const p=new CustomEvent(kN,{bubbles:!0,cancelable:!0});f.addEventListener(kN,m=>r==null?void 0:r(m),{once:!0}),t_(f,p),p.defaultPrevented?c.current=!1:o.onClose()}};return g.jsx(M8,{...s,ref:l,disabled:t,onClick:De(n.onClick,d),onPointerDown:f=>{var p;(p=n.onPointerDown)==null||p.call(n,f),c.current=!0},onPointerUp:De(n.onPointerUp,f=>{var p;c.current||(p=f.currentTarget)==null||p.click()}),onKeyDown:De(n.onKeyDown,f=>{const p=a.searchRef.current!=="";t||p&&f.key===" "||EE.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});m0.displayName=bS;var M8=P.forwardRef((n,e)=>{const{__scopeMenu:t,disabled:r=!1,textValue:s,...i}=n,o=S_(bS,t),a=C8(t),l=P.useRef(null),c=Kt(e,l),[d,f]=P.useState(!1),[p,m]=P.useState("");return P.useEffect(()=>{const y=l.current;y&&m((y.textContent??"").trim())},[i.children]),g.jsx(dp.ItemSlot,{scope:t,disabled:r,textValue:s??p,children:g.jsx(qce,{asChild:!0,...a,focusable:!r,children:g.jsx(wt.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...i,ref:c,onPointerMove:De(n.onPointerMove,hp(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:De(n.onPointerLeave,hp(y=>o.onItemLeave(y))),onFocus:De(n.onFocus,()=>f(!0)),onBlur:De(n.onBlur,()=>f(!1))})})})}),que="MenuCheckboxItem",A8=P.forwardRef((n,e)=>{const{checked:t=!1,onCheckedChange:r,...s}=n;return g.jsx(N8,{scope:n.__scopeMenu,checked:t,children:g.jsx(m0,{role:"menuitemcheckbox","aria-checked":CS(t)?"mixed":t,...s,ref:e,"data-state":C_(t),onSelect:De(s.onSelect,()=>r==null?void 0:r(CS(t)?!0:!t),{checkForDefaultPrevented:!1})})})});A8.displayName=que;var O8="MenuRadioGroup",[Gue,Yue]=mu(O8,{value:void 0,onValueChange:()=>{}}),R8=P.forwardRef((n,e)=>{const{value:t,onValueChange:r,...s}=n,i=ar(r);return g.jsx(Gue,{scope:n.__scopeMenu,value:t,onValueChange:i,children:g.jsx(x_,{...s,ref:e})})});R8.displayName=O8;var D8="MenuRadioItem",j8=P.forwardRef((n,e)=>{const{value:t,...r}=n,s=Yue(D8,n.__scopeMenu),i=t===s.value;return g.jsx(N8,{scope:n.__scopeMenu,checked:i,children:g.jsx(m0,{role:"menuitemradio","aria-checked":i,...r,ref:e,"data-state":C_(i),onSelect:De(r.onSelect,()=>{var o;return(o=s.onValueChange)==null?void 0:o.call(s,t)},{checkForDefaultPrevented:!1})})})});j8.displayName=D8;var w_="MenuItemIndicator",[N8,Xue]=mu(w_,{checked:!1}),L8=P.forwardRef((n,e)=>{const{__scopeMenu:t,forceMount:r,...s}=n,i=Xue(w_,t);return g.jsx(so,{present:r||CS(i.checked)||i.checked===!0,children:g.jsx(wt.span,{...s,ref:e,"data-state":C_(i.checked)})})});L8.displayName=w_;var Zue="MenuSeparator",F8=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return g.jsx(wt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});F8.displayName=Zue;var Jue="MenuArrow",z8=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=qp(t);return g.jsx(a8,{...s,...r,ref:e})});z8.displayName=Jue;var b_="MenuSub",[Que,$8]=mu(b_),B8=n=>{const{__scopeMenu:e,children:t,open:r=!1,onOpenChange:s}=n,i=ec(b_,e),o=qp(e),[a,l]=P.useState(null),[c,d]=P.useState(null),f=ar(s);return P.useEffect(()=>(i.open===!1&&f(!1),()=>f(!1)),[i.open,f]),g.jsx(f_,{...o,children:g.jsx(P8,{scope:e,open:r,onOpenChange:f,content:c,onContentChange:d,children:g.jsx(Que,{scope:e,contentId:_a(),triggerId:_a(),trigger:a,onTriggerChange:l,children:t})})})};B8.displayName=b_;var wf="MenuSubTrigger",U8=P.forwardRef((n,e)=>{const t=ec(wf,n.__scopeMenu),r=Gp(wf,n.__scopeMenu),s=$8(wf,n.__scopeMenu),i=S_(wf,n.__scopeMenu),o=P.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=i,c={__scopeMenu:n.__scopeMenu},d=P.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return P.useEffect(()=>d,[d]),P.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),g.jsx(m_,{asChild:!0,...c,children:g.jsx(M8,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":s.contentId,"data-state":W8(t.open),...n,ref:i0(e,s.onTriggerChange),onClick:f=>{var p;(p=n.onClick)==null||p.call(n,f),!(n.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:De(n.onPointerMove,hp(f=>{i.onItemEnter(f),!f.defaultPrevented&&!n.disabled&&!t.open&&!o.current&&(i.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{t.onOpenChange(!0),d()},100))})),onPointerLeave:De(n.onPointerLeave,hp(f=>{var m,y;d();const p=(m=t.content)==null?void 0:m.getBoundingClientRect();if(p){const v=(y=t.content)==null?void 0:y.dataset.side,x=v==="right",b=x?-5:5,C=p[x?"left":"right"],I=p[x?"right":"left"];i.onPointerGraceIntentChange({area:[{x:f.clientX+b,y:f.clientY},{x:C,y:p.top},{x:I,y:p.top},{x:I,y:p.bottom},{x:C,y:p.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>i.onPointerGraceIntentChange(null),300)}else{if(i.onTriggerLeave(f),f.defaultPrevented)return;i.onPointerGraceIntentChange(null)}})),onKeyDown:De(n.onKeyDown,f=>{var m;const p=i.searchRef.current!=="";n.disabled||p&&f.key===" "||jue[r.dir].includes(f.key)&&(t.onOpenChange(!0),(m=t.content)==null||m.focus(),f.preventDefault())})})})});U8.displayName=wf;var H8="MenuSubContent",K8=P.forwardRef((n,e)=>{const t=k8(xi,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,i=ec(xi,n.__scopeMenu),o=Gp(xi,n.__scopeMenu),a=$8(H8,n.__scopeMenu),l=P.useRef(null),c=Kt(e,l);return g.jsx(dp.Provider,{scope:n.__scopeMenu,children:g.jsx(so,{present:r||i.open,children:g.jsx(dp.Slot,{scope:n.__scopeMenu,children:g.jsx(v_,{id:a.contentId,"aria-labelledby":a.triggerId,...s,ref:c,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;o.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:De(n.onFocusOutside,d=>{d.target!==a.trigger&&i.onOpenChange(!1)}),onEscapeKeyDown:De(n.onEscapeKeyDown,d=>{o.onClose(),d.preventDefault()}),onKeyDown:De(n.onKeyDown,d=>{var m;const f=d.currentTarget.contains(d.target),p=Nue[o.dir].includes(d.key);f&&p&&(i.onOpenChange(!1),(m=a.trigger)==null||m.focus(),d.preventDefault())})})})})})});K8.displayName=H8;function W8(n){return n?"open":"closed"}function CS(n){return n==="indeterminate"}function C_(n){return CS(n)?"indeterminate":n?"checked":"unchecked"}function ede(n){const e=document.activeElement;for(const t of n)if(t===e||(t.focus(),document.activeElement!==e))return}function tde(n,e){return n.map((t,r)=>n[(e+r)%n.length])}function nde(n,e,t){const s=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,i=t?n.indexOf(t):-1;let o=tde(n,Math.max(i,0));s.length===1&&(o=o.filter(c=>c!==t));const l=o.find(c=>c.toLowerCase().startsWith(s.toLowerCase()));return l!==t?l:void 0}function rde(n,e){const{x:t,y:r}=n;let s=!1;for(let i=0,o=e.length-1;i<e.length;o=i++){const a=e[i].x,l=e[i].y,c=e[o].x,d=e[o].y;l>r!=d>r&&t<(c-a)*(r-l)/(d-l)+a&&(s=!s)}return s}function sde(n,e){if(!e)return!1;const t={x:n.clientX,y:n.clientY};return rde(t,e)}function hp(n){return e=>e.pointerType==="mouse"?n(e):void 0}var V8=E8,q8=m_,G8=I8,Y8=_8,X8=x_,Z8=T8,J8=m0,Q8=A8,eU=R8,tU=j8,nU=L8,rU=F8,sU=z8,iU=B8,oU=U8,aU=K8,P_="ContextMenu",[ide,i1e]=Vo(P_,[g0]),Mr=g0(),[ode,lU]=ide(P_),cU=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,dir:s,modal:i=!0}=n,[o,a]=P.useState(!1),l=Mr(e),c=ar(r),d=P.useCallback(f=>{a(f),c(f)},[c]);return g.jsx(ode,{scope:e,open:o,onOpenChange:d,modal:i,children:g.jsx(V8,{...l,dir:s,open:o,onOpenChange:d,modal:i,children:t})})};cU.displayName=P_;var uU="ContextMenuTrigger",dU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,disabled:r=!1,...s}=n,i=lU(uU,t),o=Mr(t),a=P.useRef({x:0,y:0}),l=P.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=P.useRef(0),d=P.useCallback(()=>window.clearTimeout(c.current),[]),f=p=>{a.current={x:p.clientX,y:p.clientY},i.onOpenChange(!0)};return P.useEffect(()=>d,[d]),P.useEffect(()=>void(r&&d()),[r,d]),g.jsxs(g.Fragment,{children:[g.jsx(q8,{...o,virtualRef:l}),g.jsx(wt.span,{"data-state":i.open?"open":"closed","data-disabled":r?"":void 0,...s,ref:e,style:{WebkitTouchCallout:"none",...n.style},onContextMenu:r?n.onContextMenu:De(n.onContextMenu,p=>{d(),f(p),p.preventDefault()}),onPointerDown:r?n.onPointerDown:De(n.onPointerDown,Om(p=>{d(),c.current=window.setTimeout(()=>f(p),700)})),onPointerMove:r?n.onPointerMove:De(n.onPointerMove,Om(d)),onPointerCancel:r?n.onPointerCancel:De(n.onPointerCancel,Om(d)),onPointerUp:r?n.onPointerUp:De(n.onPointerUp,Om(d))})]})});dU.displayName=uU;var ade="ContextMenuPortal",E_=n=>{const{__scopeContextMenu:e,...t}=n,r=Mr(e);return g.jsx(G8,{...r,...t})};E_.displayName=ade;var hU="ContextMenuContent",fU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=lU(hU,t),i=Mr(t),o=P.useRef(!1);return g.jsx(Y8,{...i,...r,ref:e,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=n.onCloseAutoFocus)==null||l.call(n,a),!a.defaultPrevented&&o.current&&a.preventDefault(),o.current=!1},onInteractOutside:a=>{var l;(l=n.onInteractOutside)==null||l.call(n,a),!a.defaultPrevented&&!s.modal&&(o.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)"}})});fU.displayName=hU;var lde="ContextMenuGroup",pU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(X8,{...s,...r,ref:e})});pU.displayName=lde;var cde="ContextMenuLabel",ude=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(Z8,{...s,...r,ref:e})});ude.displayName=cde;var dde="ContextMenuItem",gU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(J8,{...s,...r,ref:e})});gU.displayName=dde;var hde="ContextMenuCheckboxItem",mU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(Q8,{...s,...r,ref:e})});mU.displayName=hde;var fde="ContextMenuRadioGroup",pde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(eU,{...s,...r,ref:e})});pde.displayName=fde;var gde="ContextMenuRadioItem",mde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(tU,{...s,...r,ref:e})});mde.displayName=gde;var yde="ContextMenuItemIndicator",Sde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(nU,{...s,...r,ref:e})});Sde.displayName=yde;var vde="ContextMenuSeparator",xde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(rU,{...s,...r,ref:e})});xde.displayName=vde;var wde="ContextMenuArrow",bde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(sU,{...s,...r,ref:e})});bde.displayName=wde;var Cde="ContextMenuSub",yU=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,open:s,defaultOpen:i}=n,o=Mr(e),[a,l]=Ql({prop:s,defaultProp:i,onChange:r});return g.jsx(iU,{...o,open:a,onOpenChange:l,children:t})};yU.displayName=Cde;var Pde="ContextMenuSubTrigger",SU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(oU,{...s,...r,ref:e})});SU.displayName=Pde;var Ede="ContextMenuSubContent",vU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Mr(t);return g.jsx(aU,{...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)"}})});vU.displayName=Ede;function Om(n){return e=>e.pointerType!=="mouse"?n(e):void 0}var kde=cU,Ide=dU,_de=E_,Tde=fU,Mde=mU,k_="DropdownMenu",[Ade,o1e]=Vo(k_,[g0]),Ar=g0(),[Ode,xU]=Ade(k_),wU=n=>{const{__scopeDropdownMenu:e,children:t,dir:r,open:s,defaultOpen:i,onOpenChange:o,modal:a=!0}=n,l=Ar(e),c=P.useRef(null),[d=!1,f]=Ql({prop:s,defaultProp:i,onChange:o});return g.jsx(Ode,{scope:e,triggerId:_a(),triggerRef:c,contentId:_a(),open:d,onOpenChange:f,onOpenToggle:P.useCallback(()=>f(p=>!p),[f]),modal:a,children:g.jsx(V8,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:t})})};wU.displayName=k_;var bU="DropdownMenuTrigger",CU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...s}=n,i=xU(bU,t),o=Ar(t);return g.jsx(q8,{asChild:!0,...o,children:g.jsx(wt.button,{type:"button",id:i.triggerId,"aria-haspopup":"menu","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":i.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...s,ref:i0(e,i.triggerRef),onPointerDown:De(n.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(i.onOpenToggle(),i.open||a.preventDefault())}),onKeyDown:De(n.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&i.onOpenToggle(),a.key==="ArrowDown"&&i.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});CU.displayName=bU;var Rde="DropdownMenuPortal",PU=n=>{const{__scopeDropdownMenu:e,...t}=n,r=Ar(e);return g.jsx(G8,{...r,...t})};PU.displayName=Rde;var EU="DropdownMenuContent",kU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=xU(EU,t),i=Ar(t),o=P.useRef(!1);return g.jsx(Y8,{id:s.contentId,"aria-labelledby":s.triggerId,...i,...r,ref:e,onCloseAutoFocus:De(n.onCloseAutoFocus,a=>{var l;o.current||(l=s.triggerRef.current)==null||l.focus(),o.current=!1,a.preventDefault()}),onInteractOutside:De(n.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!s.modal||d)&&(o.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)"}})});kU.displayName=EU;var Dde="DropdownMenuGroup",IU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(X8,{...s,...r,ref:e})});IU.displayName=Dde;var jde="DropdownMenuLabel",Nde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(Z8,{...s,...r,ref:e})});Nde.displayName=jde;var Lde="DropdownMenuItem",_U=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(J8,{...s,...r,ref:e})});_U.displayName=Lde;var Fde="DropdownMenuCheckboxItem",TU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(Q8,{...s,...r,ref:e})});TU.displayName=Fde;var zde="DropdownMenuRadioGroup",$de=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(eU,{...s,...r,ref:e})});$de.displayName=zde;var Bde="DropdownMenuRadioItem",Ude=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(tU,{...s,...r,ref:e})});Ude.displayName=Bde;var Hde="DropdownMenuItemIndicator",Kde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(nU,{...s,...r,ref:e})});Kde.displayName=Hde;var Wde="DropdownMenuSeparator",Vde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(rU,{...s,...r,ref:e})});Vde.displayName=Wde;var qde="DropdownMenuArrow",Gde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(sU,{...s,...r,ref:e})});Gde.displayName=qde;var Yde=n=>{const{__scopeDropdownMenu:e,children:t,open:r,onOpenChange:s,defaultOpen:i}=n,o=Ar(e),[a=!1,l]=Ql({prop:r,defaultProp:i,onChange:s});return g.jsx(iU,{...o,open:a,onOpenChange:l,children:t})},Xde="DropdownMenuSubTrigger",MU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(oU,{...s,...r,ref:e})});MU.displayName=Xde;var Zde="DropdownMenuSubContent",AU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Ar(t);return g.jsx(aU,{...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)"}})});AU.displayName=Zde;var I_=wU,__=CU,y0=PU,T_=kU,Jde=IU,Qde=_U,ehe=TU,the=Yde,nhe=MU,rhe=AU;function Ut(n,e){var s;const t=new Set;for(const i of e){const o=n.getShape(i);if(!o)continue;n.getShapeUtil(o).onDragShapesOut&&t.add(o);const a=n.getShape(o.parentId);a&&n.getShapeUtil(a).onDragShapesOut&&t.add(a)}const r=new Map;for(const i of t){const o=OU(n,i);o.length&&r.set(i,o)}for(const[i,o]of r){const a=n.getShapeUtil(i),l=st(o.map(c=>n.getShape(c)));(s=a.onDragShapesOut)==null||s.call(a,i,l)}}function OU(n,e){const t=n.getSortedChildIdsForParent(e.id);if(t.length===0)return[];const r=n.getShapePageBounds(e);if(!r)return[];let s,i,o;const a=[];for(const l of t){const c=n.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}s??(s=n.getShapeGeometry(e)),i??(i=n.getShapePageTransform(e)),o??(o=i.applyToPoints(s.vertices));const d=n.getShapePageTransform(l).clone().invert().applyToPoints(o),{vertices:f,isClosed:p}=n.getShapeGeometry(l);if(!f.some(m=>$s(m,d))){if(p){if(KI(d,f))continue}else if(wse(d,f))continue;a.push(l)}}return a}function PS(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 she(n,e){const t=st(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 i=n.getSortedChildIdsForParent(s.id);i.length&&(n.reparentShapes(i,s.parentId,s.index),r.push(...i))}),n.setSelectedShapes(r),n.deleteShapes(e)})}const ihe=50;function ohe(n,e,t={}){const r=n.getShape(e);if(!r)return;const s=n.getSortedChildIdsForParent(r.id),i=st(s.map(m=>n.getShape(m)));if(!i.length)return;const o=ye.FromPoints(i.flatMap(m=>{const y=n.getShapeGeometry(m.id);return n.getShapeLocalTransform(m).applyToPoints(y.vertices)})),{padding:a=ihe}=t,l=o.w+2*a,c=o.h+2*a,d=a-o.minX,f=a-o.minY;if(d===0&&f===0&&r.props.w===l&&r.props.h===c)return;const p=new E(d,f).rot(r.rotation);n.run(()=>{const m=s.map(y=>{const v=n.getShape(y);return{id:v.id,type:v.type,x:v.x+d,y:v.y+f}});m.push({id:r.id,type:r.type,x:r.x-p.x,y:r.y-p.y,props:{w:l,h:c}}),n.updateShapes(m)})}const RU=P.createContext(null);function ahe({assetUrls:n,children:e}){return P.useEffect(()=>{for(const t of Object.values(n.icons)){const r=qf();r.src=t,r.decode()}for(const t of Object.values(n.embedIcons)){const r=qf();r.src=t,r.decode()}},[n]),g.jsx(RU.Provider,{value:n,children:e})}function M_(){const n=P.useContext(RU);if(!n)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return n}const kE={"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","tool.rich-text-bold":"Bold","tool.rich-text-italic":"Italic","tool.rich-text-code":"Code","tool.rich-text-highlight":"Highlight","tool.rich-text-strikethrough":"Strikethrough","tool.rich-text-link":"Link","tool.rich-text-link-visit":"Visit link","tool.rich-text-link-remove":"Remove link","tool.rich-text-header":"Header","tool.rich-text-bulletList":"Bulleted list","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…"},lhe=new Set(["ar","fa","he","ur","ku"]),ud={locale:"en",label:"English",messages:kE,dir:"ltr"};async function che(n,e){if(!(await Vi(e.translations.en)).ok)return console.warn("No main translations found."),ud;if(n==="en")return ud;const r=op.find(o=>o.locale===n);if(!r)return console.warn(`No translation found for locale ${n}`),ud;const i=await(await Vi(e.translations[r.locale])).json();if(!i)return console.warn(`No messages found for locale ${n}`),ud;for(const o in ud.messages)i[o];return{locale:n,label:r.label,dir:lhe.has(r.locale)?"rtl":"ltr",messages:{...ud.messages,...i}}}const DU=P.createContext(null);function jU(){const n=P.useContext(DU);if(!n)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return n}function uhe({overrides:n,locale:e,children:t}){const r=M_(),[s,i]=P.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...kE,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:kE});return P.useEffect(()=>{let o=!1;async function a(){const l=await che(e,r);l&&!o&&(n&&n[e]?i({...l,messages:{...l.messages,...n[e]}}):i(l))}return a(),()=>{o=!0}},[r,e,n]),g.jsx(DU.Provider,{value:s,children:t})}function ft(){const n=jU();return P.useCallback(function(t){return n.messages[t]??t},[n])}const Ke=P.forwardRef(function({children:e,type:t,isActive:r,...s},i){return g.jsx("button",{ref:i,type:"button",draggable:!1,"data-isactive":r,...s,className:ze("tlui-button",`tlui-button__${t}`,s.className),children:e})});function wn({children:n}){return g.jsx("span",{className:"tlui-button__label",children:n})}var A_="Dialog",[NU,a1e]=Vo(A_),[dhe,io]=NU(A_),LU=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:s,onOpenChange:i,modal:o=!0}=n,a=P.useRef(null),l=P.useRef(null),[c=!1,d]=Ql({prop:r,defaultProp:s,onChange:i});return g.jsx(dhe,{scope:e,triggerRef:a,contentRef:l,contentId:_a(),titleId:_a(),descriptionId:_a(),open:c,onOpenChange:d,onOpenToggle:P.useCallback(()=>d(f=>!f),[d]),modal:o,children:t})};LU.displayName=A_;var FU="DialogTrigger",hhe=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=io(FU,t),i=Kt(e,s.triggerRef);return g.jsx(wt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":D_(s.open),...r,ref:i,onClick:De(n.onClick,s.onOpenToggle)})});hhe.displayName=FU;var O_="DialogPortal",[fhe,zU]=NU(O_,{forceMount:void 0}),$U=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:s}=n,i=io(O_,e);return g.jsx(fhe,{scope:e,forceMount:t,children:P.Children.map(r,o=>g.jsx(so,{present:t||i.open,children:g.jsx(Wp,{asChild:!0,container:s,children:o})}))})};$U.displayName=O_;var ES="DialogOverlay",BU=P.forwardRef((n,e)=>{const t=zU(ES,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,i=io(ES,n.__scopeDialog);return i.modal?g.jsx(so,{present:r||i.open,children:g.jsx(phe,{...s,ref:e})}):null});BU.displayName=ES;var phe=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=io(ES,t);return g.jsx(p0,{as:tu,allowPinchZoom:!0,shards:[s.contentRef],children:g.jsx(wt.div,{"data-state":D_(s.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),ru="DialogContent",UU=P.forwardRef((n,e)=>{const t=zU(ru,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,i=io(ru,n.__scopeDialog);return g.jsx(so,{present:r||i.open,children:i.modal?g.jsx(ghe,{...s,ref:e}):g.jsx(mhe,{...s,ref:e})})});UU.displayName=ru;var ghe=P.forwardRef((n,e)=>{const t=io(ru,n.__scopeDialog),r=P.useRef(null),s=Kt(e,t.contentRef,r);return P.useEffect(()=>{const i=r.current;if(i)return g_(i)},[]),g.jsx(HU,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:De(n.onCloseAutoFocus,i=>{var o;i.preventDefault(),(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:De(n.onPointerDownOutside,i=>{const o=i.detail.originalEvent,a=o.button===0&&o.ctrlKey===!0;(o.button===2||a)&&i.preventDefault()}),onFocusOutside:De(n.onFocusOutside,i=>i.preventDefault())})}),mhe=P.forwardRef((n,e)=>{const t=io(ru,n.__scopeDialog),r=P.useRef(!1),s=P.useRef(!1);return g.jsx(HU,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var o,a;(o=n.onCloseAutoFocus)==null||o.call(n,i),i.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),i.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:i=>{var l,c;(l=n.onInteractOutside)==null||l.call(n,i),i.defaultPrevented||(r.current=!0,i.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const o=i.target;((c=t.triggerRef.current)==null?void 0:c.contains(o))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&s.current&&i.preventDefault()}})}),HU=P.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:i,...o}=n,a=io(ru,t),l=P.useRef(null),c=Kt(e,l);return r_(),g.jsxs(g.Fragment,{children:[g.jsx(a0,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:i,children:g.jsx(Hp,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":D_(a.open),...o,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),g.jsxs(g.Fragment,{children:[g.jsx(She,{titleId:a.titleId}),g.jsx(xhe,{contentRef:l,descriptionId:a.descriptionId})]})]})}),R_="DialogTitle",KU=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=io(R_,t);return g.jsx(wt.h2,{id:s.titleId,...r,ref:e})});KU.displayName=R_;var WU="DialogDescription",yhe=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=io(WU,t);return g.jsx(wt.p,{id:s.descriptionId,...r,ref:e})});yhe.displayName=WU;var VU="DialogClose",qU=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=io(VU,t);return g.jsx(wt.button,{type:"button",...r,ref:e,onClick:De(n.onClick,()=>s.onOpenChange(!1))})});qU.displayName=VU;function D_(n){return n?"open":"closed"}var GU="DialogTitleWarning",[l1e,YU]=ele(GU,{contentName:ru,titleName:R_,docsSlug:"dialog"}),She=({titleId:n})=>{const e=YU(GU),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
335
+
336
+ If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
337
+
338
+ For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return P.useEffect(()=>{n&&(document.getElementById(n)||console.error(t))},[t,n]),null},vhe="DialogDescriptionWarning",xhe=({contentRef:n,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${YU(vhe).contentName}}.`;return P.useEffect(()=>{var i;const s=(i=n.current)==null?void 0:i.getAttribute("aria-describedby");e&&s&&(document.getElementById(e)||console.warn(r))},[r,n,e]),null},whe=LU,bhe=$U,Che=BU,Phe=UU,Ehe=KU;const Bo=P.memo(function({small:e,invertIcon:t,icon:r,color:s,className:i,...o}){const a=M_(),l=a.icons[r]??a.icons["question-mark-circle"],c=P.useRef(null);return P.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?g.jsx("div",{className:ze("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},i)}):g.jsx("div",{...o,ref:c,className:ze("tlui-icon",{"tlui-icon__small":e},i),style:{color:s,mask:`url(${l}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})});function ct({icon:n,small:e,invertIcon:t}){return g.jsx(Bo,{className:"tlui-button__icon",icon:n,small:e,invertIcon:t})}function S0({className:n,children:e}){return g.jsx("div",{className:ze("tlui-dialog__header",n),children:e})}function v0({className:n,children:e,style:t}){return g.jsx(Ehe,{dir:"ltr",className:ze("tlui-dialog__header__title",n),style:t,children:e})}function x0(){return g.jsx("div",{className:"tlui-dialog__header__close",children:g.jsx(qU,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:g.jsx(Ke,{type:"icon","aria-label":"Close",onTouchEnd:n=>n.target.click(),children:g.jsx(ct,{small:!0,icon:"cross-2"})})})})}function fp({className:n,children:e,style:t}){return g.jsx("div",{className:ze("tlui-dialog__body",n),style:t,children:e})}function j_({className:n,children:e}){return g.jsx("div",{className:ze("tlui-dialog__footer",n),children:e})}const Yp=P.forwardRef(function({className:e,label:t,icon:r,iconLeft:s,autoSelect:i=!1,autoFocus:o=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:d,onCancel:f,onFocus:p,onBlur:m,shouldManuallyMaintainScrollPositionWhenFocused:y=!1,children:v,value:x,"data-testid":b},C){const I=Tr(),_=P.useRef(null);P.useImperativeHandle(C,()=>_.current);const T=ft(),A=P.useRef(a??""),R=P.useRef(a??""),j=P.useRef(!1),[K,U]=P.useState(!1),J=P.useCallback(W=>{U(!0);const $=W.currentTarget;R.current=$.value,I?I.timers.requestAnimationFrame(()=>{i&&$.select()}):yS.requestAnimationFrame("anon",()=>{i&&$.select()}),p==null||p()},[i,I,p]),z=P.useCallback(W=>{const $=W.currentTarget.value;R.current=$,d==null||d($)},[d]),N=P.useCallback(W=>{switch(W.key){case"Enter":{if(j.current)return;W.currentTarget.blur(),Xt(W),c==null||c(W.currentTarget.value);break}case"Escape":{W.currentTarget.value=A.current,f==null||f(W.currentTarget.value),W.currentTarget.blur(),Xt(W);break}}},[c,f]),L=P.useCallback(W=>{U(!1);const $=W.currentTarget.value;m==null||m($)},[m]),V=P.useCallback(()=>j.current=!0,[]),X=P.useCallback(()=>j.current=!1,[]);return P.useEffect(()=>{if(!Pt.isIos)return;const W=window.visualViewport;if(K&&y&&W){const $=()=>{var G;(G=_.current)==null||G.scrollIntoView({block:"center"})};return W.addEventListener("resize",$),W.addEventListener("scroll",$),I?I.timers.requestAnimationFrame(()=>{var G;(G=_.current)==null||G.scrollIntoView({block:"center"})}):yS.requestAnimationFrame("anon",()=>{var G;(G=_.current)==null||G.scrollIntoView({block:"center"})}),()=>{W.removeEventListener("resize",$),W.removeEventListener("scroll",$)}}},[K,I,y]),g.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[v,t&&g.jsx("label",{children:T(t)}),s&&g.jsx(Bo,{icon:s,className:"tlui-icon-left",small:!0}),g.jsx("input",{ref:_,className:ze("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:N,onChange:z,onFocus:J,onBlur:L,onCompositionStart:V,onCompositionEnd:X,autoFocus:o,placeholder:l,value:x,"data-testid":b}),r&&g.jsx(Bo,{icon:r,small:!!t})]})});function IN(n){return Ks.isValid(n)?{isValid:!0,hasProtocol:!0}:Ks.isValid("https://"+n)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const khe=Vn(function({onClose:e}){const r=te().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?g.jsx(Ihe,{onClose:e,selectedShape:r}):null}),Ihe=Vn(function({onClose:e,selectedShape:t}){const r=te(),s=ft(),i=P.useRef(null);P.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var y;return(y=i.current)==null?void 0:y.focus()})},[r]);const o=P.useRef(t.props.url),[a,l]=P.useState(()=>{const y=IN(t.props.url),v=y.isValid===!0?y.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:v,safe:v,valid:!0}}),c=P.useCallback(y=>{const v=y.replace(/https?:\/\/(https?:\/\/)/,(C,I)=>I),x=IN(v),b=x.isValid===!0?x.hasProtocol?v:"https://"+v:"https://";l({actual:v,safe:b,valid:x.isValid})},[]),d=P.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),e())},[r,e]),f=P.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),e())},[r,e,a]),p=P.useCallback(()=>{e()},[e]);if(!t)return e(),null;const m=o.current&&!a.valid;return g.jsxs(g.Fragment,{children:[g.jsxs(S0,{children:[g.jsx(v0,{children:s("edit-link-dialog.title")}),g.jsx(x0,{})]}),g.jsx(fp,{children:g.jsxs("div",{className:"tlui-edit-link-dialog",children:[g.jsx(Yp,{ref:i,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:f,onCancel:p}),g.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),g.jsxs(j_,{className:"tlui-dialog__footer__actions",children:[g.jsx(Ke,{type:"normal",onClick:p,onTouchEnd:p,children:g.jsx(wn,{children:s("edit-link-dialog.cancel")})}),m?g.jsx(Ke,{type:"danger",onTouchEnd:d,onClick:d,children:g.jsx(wn,{children:s("edit-link-dialog.clear")})}):g.jsx(Ke,{type:"primary",disabled:!a.valid,onTouchEnd:f,onClick:f,children:g.jsx(wn,{children:s("edit-link-dialog.save")})})]})]})});var _he={};const _N=/(^\/r\/[^/]+\/?$)/,N_=[{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=Je(n);if(e&&e.pathname.match(_N))return n},fromEmbedUrl:n=>{const e=Je(n);if(e&&e.pathname.match(_N))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=Je(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,i]=e;t=`https://${new URL(n).host.replace("www.","")}/maps/embed/v1/view?key=${_he.NEXT_PUBLIC_GC_API_KEY}&center=${r},${s}&zoom=${i}`}else t="";return t}},fromEmbedUrl:n=>{const e=Je(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,i]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${i},${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=Je(n),t=e&&e.pathname.match(/\/v\/(.+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Je(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=Je(n),t=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Je(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,i]=t;return`https://codepen.io/${s}/embed/${i}`}},fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s,i]=t;return`https://codepen.io/${s}/pen/${i}`}}},{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=Je(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=Je(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=Je(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=Je(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=Je(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=Je(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=Je(n);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return n.split("/").pop()?n:void 0},fromEmbedUrl:n=>{const e=Je(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=Je(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${n}?embed=true`},fromEmbedUrl:n=>{const e=Je(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=Je(n);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Je(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=Je(n);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Je(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=Je(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=Je(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=Je(n);if(e&&e.hash.match(/#room=/))return n},fromEmbedUrl:n=>{const e=Je(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=Je(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=Je(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=Je(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${n}?embed`},fromEmbedUrl:n=>{const e=Je(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],The={"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},Mhe=N_.map(n=>n.type);function Ahe(n){return Mhe.includes(n)}function Ohe(n){return"icon"in n}function XU(){const n=Tr();if(n&&n.hasShapeUtil("embed"))return n.getShapeUtil("embed")}function L_(){const n=XU();return e=>n?n.getEmbedDefinition(e):void 0}function Rhe(){const n=XU();return n?n.getEmbedDefinitions():[]}const ZU=Vn(function({onClose:e}){const t=te(),r=ft(),s=M_(),[i,o]=P.useState(null),[a,l]=P.useState(""),[c,d]=P.useState(null),[f,p]=P.useState(!1),m=P.useRef(-1),y=Rhe(),v=L_();return g.jsxs(g.Fragment,{children:[g.jsxs(S0,{children:[g.jsx(v0,{children:i?`${r("embed-dialog.title")} — ${i.title}`:r("embed-dialog.title")}),g.jsx(x0,{})]}),i?g.jsxs(g.Fragment,{children:[g.jsxs(fp,{className:"tlui-embed-dialog__enter",children:[g.jsx(Yp,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:x=>{l(x);const b=v(x);d(b&&b.definition.type===i.type?b:null),p(!1),clearTimeout(m.current),m.current=t.timers.setTimeout(()=>p(!b),320)}}),a===""?g.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[g.jsx("span",{children:r("embed-dialog.instruction")})," ",i.instructionLink&&g.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:i.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",g.jsx(Bo,{icon:"external-link",small:!0})]})]}):g.jsx("div",{className:"tlui-embed-dialog__warning",children:f?r("embed-dialog.invalid-url"):" "})]}),g.jsxs(j_,{className:"tlui-dialog__footer__actions",children:[g.jsx(Ke,{type:"normal",onClick:()=>{o(null),d(null),l("")},children:g.jsx(wn,{children:r("embed-dialog.back")})}),g.jsx("div",{className:"tlui-embed__spacer"}),g.jsx(Ke,{type:"normal",onClick:e,children:g.jsx(wn,{children:r("embed-dialog.cancel")})}),g.jsx(Ke,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:c.definition}),e())},children:g.jsx(wn,{children:r("embed-dialog.create")})})]})]}):g.jsx(g.Fragment,{children:g.jsx(fp,{className:"tlui-embed-dialog__list",children:y.map(x=>{const b=Ahe(x.type)?s.embedIcons[x.type]:Ohe(x)?x.icon:void 0;return g.jsxs(Ke,{type:"menu",onClick:()=>o(x),children:[g.jsx(wn,{children:x.title}),b&&g.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${b})`}})]},x.type)})})})]})});async function Dhe(n,e,t){const r=st(e.map(a=>{const l=n.getShape(a);if(!(!l||n.getShapeUtil(l.type).toSvg===void 0))return l}));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(l=>({shape:l,bounds:n.getShapeMaskedPageBounds(l).clone().expandBy(t)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){s[0]={shapes:[c.shape],bounds:c.bounds};continue}let d=!1;for(const f of s)if(f.bounds.includes(c.bounds)){f.shapes.push(c.shape),f.bounds.expand(c.bounds),d=!0;break}d||s.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=ye.Common(r.map(l=>n.getShapeMaskedPageBounds(l)));s.push({shapes:r,bounds:a})}const i=n.options.flattenImageBoundsPadding;for(const a of s){t!==void 0&&a.bounds.expandBy(-t);const l=await n.getSvgString(a.shapes,{padding:i});if(!(l!=null&&l.svg))continue;const c=await n.getAssetForExternalContent({type:"file",file:new File([l.svg],"asset.svg",{type:"image/svg+xml"})});c&&(a.asset=c)}const o=[];return ws(()=>{for(const a of s){const{asset:l,bounds:c,shapes:d}=a;if(!l)continue;const f=n.findCommonAncestor(d)??n.getCurrentPageId();if(!f)continue;let p="a1";for(const b of d)if(b.parentId===f){b.index>p&&(p=b.index);break}let m,y,v;if(ps(f)){const b=n.getShape(f);if(!b)continue;const C=n.getPointInShapeSpace(b,{x:c.x,y:c.y});v=n.getShapePageTransform(f).rotation(),C.sub(new E(i,i).rot(-v)),m=C.x,y=C.y}else m=c.x-i,y=c.y-i,v=0;n.deleteShapes(d),n.createAssets([{...l,id:l.id}]);const x=Dt();n.createShape({id:x,type:"image",index:p,parentId:f,x:m,y,rotation:-v,props:{assetId:l.id,w:c.w+i*2,h:c.h+i*2}}),o.push(x)}}),o}function w0(){const n=Tr();return(n==null?void 0:n.store.props.collaboration)!==void 0}function jhe(){const n=Tr();return ie("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 TC=[0,389,436,476,580,640,840,1023];var gn=(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))(gn||{});const JU=He.createContext(null);function Nhe({forceMobile:n=!1,children:e}){const t=Tr(),r=ie("breakpoint",()=>{const{width:s}=(t==null?void 0:t.getViewportScreenBounds())??{width:window.innerWidth},i=n?gn.MOBILE_SM:TC.length-1;for(let o=0;o<i;o++)if(s>TC[o]&&s<=TC[o+1])return o;return i},[t]);return g.jsx(JU.Provider,{value:r,children:e})}function qr(){const n=P.useContext(JU);if(n===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return n}const IE=P.createContext(null);function Lhe({context:n,children:e}){const t=P.useContext(IE),r=Rn(),s=Sv("dialogs",[]),i=P.useMemo(()=>({dialogs:s,addDialog(o){const a=o.id??_t();return s.update(l=>[...l.filter(c=>c.id!==o.id),{...o,id:a}]),r("open-menu",{source:"dialog",id:a}),$i.addOpenMenu(a,n),a},removeDialog(o){var l;const a=s.get().find(c=>c.id===o);return a&&((l=a.onClose)==null||l.call(a),r("close-menu",{source:"dialog",id:o}),$i.deleteOpenMenu(o,n),s.update(c=>c.filter(d=>d!==a))),o},clearDialogs(){const o=s.get();o.length!==0&&(o.forEach(a=>{var l;(l=a.onClose)==null||l.call(a),r("close-menu",{source:"dialog",id:a.id}),$i.deleteOpenMenu(a.id,n)}),s.set([]))}}),[r,s,n]);return t?g.jsx(g.Fragment,{children:e}):g.jsx(IE.Provider,{value:i,children:e})}function Xp(){const n=P.useContext(IE);if(!n)throw new Error("useDialogs must be used within a DialogsProvider");return n}var Fhe="VisuallyHidden",F_=P.forwardRef((n,e)=>g.jsx(wt.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}}));F_.displayName=Fhe;var z_="ToastProvider",[$_,zhe,$he]=o0("Toast"),[QU,c1e]=Vo("Toast",[$he]),[Bhe,b0]=QU(z_),e9=n=>{const{__scopeToast:e,label:t="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:i=50,children:o}=n,[a,l]=P.useState(null),[c,d]=P.useState(0),f=P.useRef(!1),p=P.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${z_}\`. Expected non-empty \`string\`.`),g.jsx($_.Provider,{scope:e,children:g.jsx(Bhe,{scope:e,label:t,duration:r,swipeDirection:s,swipeThreshold:i,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:P.useCallback(()=>d(m=>m+1),[]),onToastRemove:P.useCallback(()=>d(m=>m-1),[]),isFocusedToastEscapeKeyDownRef:f,isClosePausedRef:p,children:o})})};e9.displayName=z_;var t9="ToastViewport",Uhe=["F8"],_E="toast.viewportPause",TE="toast.viewportResume",n9=P.forwardRef((n,e)=>{const{__scopeToast:t,hotkey:r=Uhe,label:s="Notifications ({hotkey})",...i}=n,o=b0(t9,t),a=zhe(t),l=P.useRef(null),c=P.useRef(null),d=P.useRef(null),f=P.useRef(null),p=Kt(e,f,o.onViewportChange),m=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=o.toastCount>0;P.useEffect(()=>{const x=b=>{var I;r.length!==0&&r.every(_=>b[_]||b.code===_)&&((I=f.current)==null||I.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),P.useEffect(()=>{const x=l.current,b=f.current;if(y&&x&&b){const C=()=>{if(!o.isClosePausedRef.current){const A=new CustomEvent(_E);b.dispatchEvent(A),o.isClosePausedRef.current=!0}},I=()=>{if(o.isClosePausedRef.current){const A=new CustomEvent(TE);b.dispatchEvent(A),o.isClosePausedRef.current=!1}},_=A=>{!x.contains(A.relatedTarget)&&I()},T=()=>{x.contains(document.activeElement)||I()};return x.addEventListener("focusin",C),x.addEventListener("focusout",_),x.addEventListener("pointermove",C),x.addEventListener("pointerleave",T),window.addEventListener("blur",C),window.addEventListener("focus",I),()=>{x.removeEventListener("focusin",C),x.removeEventListener("focusout",_),x.removeEventListener("pointermove",C),x.removeEventListener("pointerleave",T),window.removeEventListener("blur",C),window.removeEventListener("focus",I)}}},[y,o.isClosePausedRef]);const v=P.useCallback(({tabbingDirection:x})=>{const C=a().map(I=>{const _=I.ref.current,T=[_,...tfe(_)];return x==="forwards"?T:T.reverse()});return(x==="forwards"?C.reverse():C).flat()},[a]);return P.useEffect(()=>{const x=f.current;if(x){const b=C=>{var T,A,R;const I=C.altKey||C.ctrlKey||C.metaKey;if(C.key==="Tab"&&!I){const j=document.activeElement,K=C.shiftKey;if(C.target===x&&K){(T=c.current)==null||T.focus();return}const z=v({tabbingDirection:K?"backwards":"forwards"}),N=z.findIndex(L=>L===j);MC(z.slice(N+1))?C.preventDefault():K?(A=c.current)==null||A.focus():(R=d.current)==null||R.focus()}};return x.addEventListener("keydown",b),()=>x.removeEventListener("keydown",b)}},[a,v]),g.jsxs(mle,{ref:l,role:"region","aria-label":s.replace("{hotkey}",m),tabIndex:-1,style:{pointerEvents:y?void 0:"none"},children:[y&&g.jsx(ME,{ref:c,onFocusFromOutsideViewport:()=>{const x=v({tabbingDirection:"forwards"});MC(x)}}),g.jsx($_.Slot,{scope:t,children:g.jsx(wt.ol,{tabIndex:-1,...i,ref:p})}),y&&g.jsx(ME,{ref:d,onFocusFromOutsideViewport:()=>{const x=v({tabbingDirection:"backwards"});MC(x)}})]})});n9.displayName=t9;var r9="ToastFocusProxy",ME=P.forwardRef((n,e)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...s}=n,i=b0(r9,t);return g.jsx(F_,{"aria-hidden":!0,tabIndex:0,...s,ref:e,style:{position:"fixed"},onFocus:o=>{var c;const a=o.relatedTarget;!((c=i.viewport)!=null&&c.contains(a))&&r()}})});ME.displayName=r9;var C0="Toast",Hhe="toast.swipeStart",Khe="toast.swipeMove",Whe="toast.swipeCancel",Vhe="toast.swipeEnd",s9=P.forwardRef((n,e)=>{const{forceMount:t,open:r,defaultOpen:s,onOpenChange:i,...o}=n,[a=!0,l]=Ql({prop:r,defaultProp:s,onChange:i});return g.jsx(so,{present:t||a,children:g.jsx(Yhe,{open:a,...o,ref:e,onClose:()=>l(!1),onPause:ar(n.onPause),onResume:ar(n.onResume),onSwipeStart:De(n.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:De(n.onSwipeMove,c=>{const{x:d,y:f}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${f}px`)}),onSwipeCancel:De(n.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:De(n.onSwipeEnd,c=>{const{x:d,y:f}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${f}px`),l(!1)})})})});s9.displayName=C0;var[qhe,Ghe]=QU(C0,{onClose(){}}),Yhe=P.forwardRef((n,e)=>{const{__scopeToast:t,type:r="foreground",duration:s,open:i,onClose:o,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:d,onSwipeMove:f,onSwipeCancel:p,onSwipeEnd:m,...y}=n,v=b0(C0,t),[x,b]=P.useState(null),C=Kt(e,L=>b(L)),I=P.useRef(null),_=P.useRef(null),T=s||v.duration,A=P.useRef(0),R=P.useRef(T),j=P.useRef(0),{onToastAdd:K,onToastRemove:U}=v,J=ar(()=>{var V;(x==null?void 0:x.contains(document.activeElement))&&((V=v.viewport)==null||V.focus()),o()}),z=P.useCallback(L=>{!L||L===1/0||(window.clearTimeout(j.current),A.current=new Date().getTime(),j.current=window.setTimeout(J,L))},[J]);P.useEffect(()=>{const L=v.viewport;if(L){const V=()=>{z(R.current),c==null||c()},X=()=>{const W=new Date().getTime()-A.current;R.current=R.current-W,window.clearTimeout(j.current),l==null||l()};return L.addEventListener(_E,X),L.addEventListener(TE,V),()=>{L.removeEventListener(_E,X),L.removeEventListener(TE,V)}}},[v.viewport,T,l,c,z]),P.useEffect(()=>{i&&!v.isClosePausedRef.current&&z(T)},[i,T,v.isClosePausedRef,z]),P.useEffect(()=>(K(),()=>U()),[K,U]);const N=P.useMemo(()=>x?d9(x):null,[x]);return v.viewport?g.jsxs(g.Fragment,{children:[N&&g.jsx(Xhe,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:N}),g.jsx(qhe,{scope:t,onClose:J,children:ah.createPortal(g.jsx($_.ItemSlot,{scope:t,children:g.jsx(gle,{asChild:!0,onEscapeKeyDown:De(a,()=>{v.isFocusedToastEscapeKeyDownRef.current||J(),v.isFocusedToastEscapeKeyDownRef.current=!1}),children:g.jsx(wt.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":i?"open":"closed","data-swipe-direction":v.swipeDirection,...y,ref:C,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:De(n.onKeyDown,L=>{L.key==="Escape"&&(a==null||a(L.nativeEvent),L.nativeEvent.defaultPrevented||(v.isFocusedToastEscapeKeyDownRef.current=!0,J()))}),onPointerDown:De(n.onPointerDown,L=>{L.button===0&&(I.current={x:L.clientX,y:L.clientY})}),onPointerMove:De(n.onPointerMove,L=>{if(!I.current)return;const V=L.clientX-I.current.x,X=L.clientY-I.current.y,W=!!_.current,$=["left","right"].includes(v.swipeDirection),G=["left","up"].includes(v.swipeDirection)?Math.min:Math.max,re=$?G(0,V):0,H=$?0:G(0,X),ne=L.pointerType==="touch"?10:2,ge={x:re,y:H},Pe={originalEvent:L,delta:ge};W?(_.current=ge,Rm(Khe,f,Pe,{discrete:!1})):TN(ge,v.swipeDirection,ne)?(_.current=ge,Rm(Hhe,d,Pe,{discrete:!1}),L.target.setPointerCapture(L.pointerId)):(Math.abs(V)>ne||Math.abs(X)>ne)&&(I.current=null)}),onPointerUp:De(n.onPointerUp,L=>{const V=_.current,X=L.target;if(X.hasPointerCapture(L.pointerId)&&X.releasePointerCapture(L.pointerId),_.current=null,I.current=null,V){const W=L.currentTarget,$={originalEvent:L,delta:V};TN(V,v.swipeDirection,v.swipeThreshold)?Rm(Vhe,m,$,{discrete:!0}):Rm(Whe,p,$,{discrete:!0}),W.addEventListener("click",G=>G.preventDefault(),{once:!0})}})})})}),v.viewport)})]}):null}),Xhe=n=>{const{__scopeToast:e,children:t,...r}=n,s=b0(C0,e),[i,o]=P.useState(!1),[a,l]=P.useState(!1);return Qhe(()=>o(!0)),P.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:g.jsx(Wp,{asChild:!0,children:g.jsx(F_,{...r,children:i&&g.jsxs(g.Fragment,{children:[s.label," ",t]})})})},Zhe="ToastTitle",i9=P.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return g.jsx(wt.div,{...r,ref:e})});i9.displayName=Zhe;var Jhe="ToastDescription",o9=P.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return g.jsx(wt.div,{...r,ref:e})});o9.displayName=Jhe;var a9="ToastAction",l9=P.forwardRef((n,e)=>{const{altText:t,...r}=n;return t.trim()?g.jsx(u9,{altText:t,asChild:!0,children:g.jsx(B_,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${a9}\`. Expected non-empty \`string\`.`),null)});l9.displayName=a9;var c9="ToastClose",B_=P.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n,s=Ghe(c9,t);return g.jsx(u9,{asChild:!0,children:g.jsx(wt.button,{type:"button",...r,ref:e,onClick:De(n.onClick,s.onClose)})})});B_.displayName=c9;var u9=P.forwardRef((n,e)=>{const{__scopeToast:t,altText:r,...s}=n;return g.jsx(wt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function d9(n){const e=[];return Array.from(n.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),efe(r)){const s=r.ariaHidden||r.hidden||r.style.display==="none",i=r.dataset.radixToastAnnounceExclude==="";if(!s)if(i){const o=r.dataset.radixToastAnnounceAlt;o&&e.push(o)}else e.push(...d9(r))}}),e}function Rm(n,e,t,{discrete:r}){const s=t.originalEvent.currentTarget,i=new CustomEvent(n,{bubbles:!0,cancelable:!0,detail:t});e&&s.addEventListener(n,e,{once:!0}),r?t_(s,i):s.dispatchEvent(i)}var TN=(n,e,t=0)=>{const r=Math.abs(n.x),s=Math.abs(n.y),i=r>s;return e==="left"||e==="right"?i&&r>t:!i&&s>t};function Qhe(n=()=>{}){const e=ar(n);Bl(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[e])}function efe(n){return n.nodeType===n.ELEMENT_NODE}function tfe(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 MC(n){const e=document.activeElement;return n.some(t=>t===e?!0:(t.focus(),document.activeElement!==e))}var nfe=s9,rfe=i9,sfe=o9,ife=l9,MN=B_;const AE=P.createContext(null);function ofe({children:n}){const e=Sv("toasts",[]),t=P.useContext(AE),r=P.useMemo(()=>({toasts:e,addToast(s){const i=s.id??_t();return e.update(o=>[...o.filter(a=>a.id!==s.id),{...s,id:i}]),i},removeToast(s){return e.update(i=>i.filter(o=>o.id!==s)),s},clearToasts(){e.set([])}}),[e]);return t?g.jsx(g.Fragment,{children:n}):g.jsx(e9,{children:g.jsx(AE.Provider,{value:r,children:n})})}function Ba(){const n=P.useContext(AE);if(!n)throw new Error("useToasts must be used within a ToastsProvider");return n}var AC={exports:{}},AN;function afe(){return AN||(AN=1,function(n){var e=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",i={};function o(l,c){if(!i[l]){i[l]={};for(var d=0;d<l.length;d++)i[l][l.charAt(d)]=d}return i[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(d){return r.charAt(d)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return o(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),d=new Uint8Array(c.length*2),f=0,p=c.length;f<p;f++){var m=c.charCodeAt(f);d[f*2]=m>>>8,d[f*2+1]=m%256}return d},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),d=0,f=c.length;d<f;d++)c[d]=l[d*2]*256+l[d*2+1];var p=[];return c.forEach(function(m){p.push(t(m))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return s.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return o(s,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,d){if(l==null)return"";var f,p,m={},y={},v="",x="",b="",C=2,I=3,_=2,T=[],A=0,R=0,j;for(j=0;j<l.length;j+=1)if(v=l.charAt(j),Object.prototype.hasOwnProperty.call(m,v)||(m[v]=I++,y[v]=!0),x=b+v,Object.prototype.hasOwnProperty.call(m,x))b=x;else{if(Object.prototype.hasOwnProperty.call(y,b)){if(b.charCodeAt(0)<256){for(f=0;f<_;f++)A=A<<1,R==c-1?(R=0,T.push(d(A)),A=0):R++;for(p=b.charCodeAt(0),f=0;f<8;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1}else{for(p=1,f=0;f<_;f++)A=A<<1|p,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=0;for(p=b.charCodeAt(0),f=0;f<16;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1}C--,C==0&&(C=Math.pow(2,_),_++),delete y[b]}else for(p=m[b],f=0;f<_;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1;C--,C==0&&(C=Math.pow(2,_),_++),m[x]=I++,b=String(v)}if(b!==""){if(Object.prototype.hasOwnProperty.call(y,b)){if(b.charCodeAt(0)<256){for(f=0;f<_;f++)A=A<<1,R==c-1?(R=0,T.push(d(A)),A=0):R++;for(p=b.charCodeAt(0),f=0;f<8;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1}else{for(p=1,f=0;f<_;f++)A=A<<1|p,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=0;for(p=b.charCodeAt(0),f=0;f<16;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1}C--,C==0&&(C=Math.pow(2,_),_++),delete y[b]}else for(p=m[b],f=0;f<_;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1;C--,C==0&&(C=Math.pow(2,_),_++)}for(p=2,f=0;f<_;f++)A=A<<1|p&1,R==c-1?(R=0,T.push(d(A)),A=0):R++,p=p>>1;for(;;)if(A=A<<1,R==c-1){T.push(d(A));break}else R++;return T.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,d){var f=[],p=4,m=4,y=3,v="",x=[],b,C,I,_,T,A,R,j={val:d(0),position:c,index:1};for(b=0;b<3;b+=1)f[b]=b;for(I=0,T=Math.pow(2,2),A=1;A!=T;)_=j.val&j.position,j.position>>=1,j.position==0&&(j.position=c,j.val=d(j.index++)),I|=(_>0?1:0)*A,A<<=1;switch(I){case 0:for(I=0,T=Math.pow(2,8),A=1;A!=T;)_=j.val&j.position,j.position>>=1,j.position==0&&(j.position=c,j.val=d(j.index++)),I|=(_>0?1:0)*A,A<<=1;R=t(I);break;case 1:for(I=0,T=Math.pow(2,16),A=1;A!=T;)_=j.val&j.position,j.position>>=1,j.position==0&&(j.position=c,j.val=d(j.index++)),I|=(_>0?1:0)*A,A<<=1;R=t(I);break;case 2:return""}for(f[3]=R,C=R,x.push(R);;){if(j.index>l)return"";for(I=0,T=Math.pow(2,y),A=1;A!=T;)_=j.val&j.position,j.position>>=1,j.position==0&&(j.position=c,j.val=d(j.index++)),I|=(_>0?1:0)*A,A<<=1;switch(R=I){case 0:for(I=0,T=Math.pow(2,8),A=1;A!=T;)_=j.val&j.position,j.position>>=1,j.position==0&&(j.position=c,j.val=d(j.index++)),I|=(_>0?1:0)*A,A<<=1;f[m++]=t(I),R=m-1,p--;break;case 1:for(I=0,T=Math.pow(2,16),A=1;A!=T;)_=j.val&j.position,j.position>>=1,j.position==0&&(j.position=c,j.val=d(j.index++)),I|=(_>0?1:0)*A,A<<=1;f[m++]=t(I),R=m-1,p--;break;case 2:return x.join("")}if(p==0&&(p=Math.pow(2,y),y++),f[R])v=f[R];else if(R===m)v=C+C.charAt(0);else return null;x.push(v),f[m++]=C+v.charAt(0),p--,C=v,p==0&&(p=Math.pow(2,y),y++)}}};return a}();n!=null?n.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})}(AC)),AC.exports}var lfe=afe();const h9=ja(lfe),U_="web image/vnd.tldraw+png",cfe={png:U_},ufe={[U_]:"image/png"};function dfe(n){return On(cfe,n)??null}function hfe(n){return On(ufe,n)??n}function ffe(n){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(n)}function pfe(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=JL(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function gfe(n,e,t,r){const s=e.map(i=>i instanceof File?i:new File([i],"tldrawFile",{type:i.type}));n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r})}async function OE(n,e,t,r){return n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"url",point:t,url:e,sources:r})}const mfe=[U_,"image/png","image/jpeg","image/webp","image/svg+xml"];function ON(n){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=n.trim(),e.body.textContent||e.body.innerText||""}const yfe=n=>{try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Sfe=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 nz(e)},vfe=n=>/^<svg/.test(n),xfe=["input","select","textarea"];function OC(n){const{activeElement:e}=document;return n.menus.hasAnyOpenMenus()||e&&(e.isContentEditable||xfe.indexOf(e.tagName.toLowerCase())>-1)}const Dm=(n,e,t,r)=>{const s=Sfe(e);if(s)for(const i of s)OE(n,i,t);else yfe(e)?OE(n,e,t):vfe(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}))},wfe=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(i=>i(s.getAsFile()))});break}case"string":{s.type==="text/html"?r.push({type:"html",source:new Promise(i=>s.getAsString(i))}):s.type==="text/plain"?r.push({type:"text",source:new Promise(i=>s.getAsString(i))}):r.push({type:s.type,source:new Promise(i=>s.getAsString(i))});break}}p9(n,r,t)},f9=async({editor:n,clipboardItems:e,point:t,fallbackFiles:r})=>{const s=[];for(const i of e){for(const o of mfe)if(i.types.includes(o)){const a=i.getType(o).then(l=>zr.rewriteMimeType(l,hfe(o)));s.push({type:"blob",source:a});break}i.types.includes("text/html")&&s.push({type:"html",source:(async()=>{const o=await i.getType("text/html");return await zr.blobToText(o)})()}),i.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{const o=await i.getType("text/uri-list");return await zr.blobToText(o)})()}),i.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{const o=await i.getType("text/plain");return await zr.blobToText(o)})()})}return r!=null&&r.length&&s.length===1&&s[0].type==="text"?(s.pop(),s.push(...r.map(i=>({type:"file",source:Promise.resolve(i)})))):r!=null&&r.length&&s.length===0&&s.push(...r.map(i=>({type:"file",source:Promise.resolve(i)}))),await p9(n,s,t)};async function p9(n,e,t){const r=e.filter(i=>(i.type==="file"||i.type==="blob")&&i.source!==null);if(r.length){if(r.length>n.options.maxFilesAtOnce)throw Error("Too many files");const i=st(await Promise.all(r.map(o=>o.source)));return await gfe(n,i,t)}const s=await Promise.all(e.filter(i=>i.type!=="file").map(i=>new Promise(o=>{const a=i;if(a.type==="file"){o({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var d;const c=(d=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:d[1];if(c)try{const f=h9.decompressFromBase64(c);if(f===null){o({type:"error",data:f,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(f);if(p.type!=="application/tldraw"&&o({type:"error",data:p,reason:`found tldraw data comment but JSON was of a different type: ${p.type}`}),typeof p.data=="string"){o({type:"error",data:p,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}o({type:"tldraw",data:p.data});return}}catch{o({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){o({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){o({type:"text",data:l,subtype:"url"});return}try{const f=JSON.parse(l);if(f.type==="excalidraw/clipboard"){o({type:"excalidraw",data:f});return}else{o({type:"text",data:l,subtype:"json"});return}}catch{o({type:"text",data:l,subtype:"text"});return}}o({type:"error",data:l,reason:"unhandled case"})})})));for(const i of s)if(i.type==="tldraw"){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"tldraw",content:i.data,point:t});return}for(const i of s)if(i.type==="excalidraw"){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"excalidraw",content:i.data,point:t});return}for(const i of s){if(i.type==="text"&&i.subtype==="html"){const a=new DOMParser().parseFromString(i.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");Dm(n,c,t,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&i.data.trim()){Dm(n,ON(i.data),t,s);return}if(s.some(c=>c.type==="text"&&c.subtype!=="html")){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"text",text:ON(i.data),html:i.data,point:t,sources:s});return}}if(i.type==="text"&&i.subtype==="text"&&i.data.startsWith("<iframe ")){const a=new DOMParser().parseFromString(i.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="IFRAME"&&a.firstElementChild.hasAttribute("src")&&a.firstElementChild.getAttribute("src")!==""){const c=a.firstElementChild.getAttribute("src");Dm(n,c,t,s);return}}}for(const i of s)if(i.type==="text"&&i.subtype==="url"){OE(n,i.data,t,s);return}for(const i of s)if(i.type==="text"&&i.subtype==="text"&&i.data.trim()){Dm(n,i.data,t,s);return}}const kS=async n=>{var r;const e=await n.resolveAssetsInContent(n.getContentFromCurrentPage(n.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=h9.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const s=e.shapes.map(i=>n.getShapeUtil(i).getText(i)).filter(cq);if((r=navigator.clipboard)!=null&&r.write){const i=new Blob([`<div data-tldraw>${t}</div>`],{type:"text/html"});let o=s.join(" ");o===""&&(o=" "),navigator.clipboard.write([new ClipboardItem({"text/html":i,"text/plain":new Blob([o],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${t}</div>`)}};function bfe(){const n=Tr(),e=Rn(),t=P.useCallback(async function(o){nt(n,"editor is required for copy"),n.getSelectedShapeIds().length!==0&&(await kS(n),e("copy",{source:o}))},[n,e]),r=P.useCallback(async function(o){n&&n.getSelectedShapeIds().length!==0&&(await kS(n),n.deleteShapes(n.getSelectedShapeIds()),e("cut",{source:o}))},[n,e]),s=P.useCallback(async function(o,a,l){n&&n.getEditingShapeId()===null&&(Array.isArray(o)&&o[0]instanceof ClipboardItem?(f9({editor:n,clipboardItems:o,point:l}),e("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{s(c,a,l)}))},[n,e]);return{copy:t,cut:r,paste:s}}function Cfe(){const n=te(),e=Rn(),t=ie("editor.isFocused",()=>n.getInstanceState().isFocused,[n]);P.useEffect(()=>{if(!t)return;const r=async l=>{n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||OC(n)||(tt(l),await kS(n),e("copy",{source:"kbd"}))};async function s(l){n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||OC(n)||(tt(l),await kS(n),n.deleteShapes(n.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let i=!1;const o=l=>{l.button===1&&(i=!0,n.timers.requestAnimationFrame(()=>{i=!1}))},a=l=>{var p,m;if(i){Xt(l);return}if(n.getEditingShapeId()!==null||OC(n))return;let c,d=!1;n.inputs.shiftKey&&(d=!0),n.user.getIsPasteAtCursorMode()&&(d=!d),d&&(c=n.inputs.currentPagePoint);const f=()=>{l.clipboardData&&wfe(n,l.clipboardData,c)};if((p=navigator.clipboard)!=null&&p.read){const y=Array.from(((m=l.clipboardData)==null?void 0:m.files)||[]);navigator.clipboard.read().then(v=>{Array.isArray(v)&&v[0]instanceof ClipboardItem&&f9({editor:n,clipboardItems:v,point:c,fallbackFiles:y})},()=>{f()})}else f();tt(l),e("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",s),document.addEventListener("paste",a),document.addEventListener("pointerup",o),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",s),document.removeEventListener("paste",a),document.removeEventListener("pointerup",o)}},[n,e,t])}const RN={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",svg:"text/plain"};function Pfe(n,e,t={}){const r=e!=null&&e.length?e:[...n.getCurrentPageShapeIds()],s=t.format??"png";return{blobPromise:n.toImage(r,t).then(i=>zr.rewriteMimeType(i.blob,RN[s])),mimeType:RN[s]}}function Efe(...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:i}=Pfe(e,t,r),o={[i]:s},a=dfe(r.format);return a&&ffe(a)&&(o[a]=s.then(l=>zr.rewriteMimeType(l,a))),pfe(o)}switch(r.format){case"svg":return kfe(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:En(r.format)}}async function kfe(n){var e,t;await((t=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:t.call(e,await n()))}function Ife(){const n=Tr(),{addToast:e}=Ba(),t=ft();return P.useCallback((r,s="svg")=>{nt(n,"useCopyAs: editor is required"),Efe(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 _fe(...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 ${DN()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?s=a.props.name||"frame":s=`${Uv(a.id)} at ${DN()}`}s+=`.${r.format}`;const{blob:i}=await e.toImage(t,r),o=new File([i],s,{type:i.type});Tfe(o)}function DN(){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"),i=String(n.getMinutes()).padStart(2,"0"),o=String(n.getSeconds()).padStart(2,"0");return`${e}-${t}-${r} ${s}.${i}.${o}`}function Tfe(n){const e=document.createElement("a"),t=URL.createObjectURL(n);e.href=t,e.download=n.name,e.click(),URL.revokeObjectURL(t)}function Mfe(){const n=Tr(),{addToast:e}=Ba(),t=ft();return P.useCallback((r,s="png",i)=>{nt(n,"useExportAs: editor is required"),_fe(n,r,{format:s,name:i,scale:1}).catch(o=>{console.error(o.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 g9=He.createContext([]);function Afe(){const n=Tr(),e=P.useRef(),t=Pl(He.useContext(g9));return P.useEffect(()=>{const r=n;if(!r)return;const s=window.document.createElement("input");s.type="file",s.accept=(t==null?void 0:t.join(","))??FV,s.multiple=!0,e.current=s;async function i(o){const a=o.target.files;!a||a.length===0||(r.markHistoryStoppingPoint("insert media"),await r.putExternalContent({type:"files",files:Array.from(a),point:r.getViewportPageBounds().center,ignoreParent:!1}),s.value="")}return s.addEventListener("change",i),()=>{e.current=void 0,s.removeEventListener("change",i)}},[n,t]),P.useCallback(()=>{var r;(r=e.current)==null||r.click()},[e])}function Ofe(){const n=Tr(),e=P.useRef(null),t=P.useRef(null);return P.useCallback(async function(){nt(n,"usePrint: editor is required");const s=document.createElement("div"),i=document.createElement("style"),o=(b,C)=>{b&&(b.innerHTML=""),C&&document.head.contains(C)&&document.head.removeChild(C),b&&document.body.contains(b)&&document.body.removeChild(b)};o(e.current,t.current),e.current=s,t.current=i;const a=`tl-print-surface-${_t()}`;s.className=a,i.innerHTML=`
339
+ .${a} {
340
+ display: none;
341
+ }
342
+
343
+ .${a} svg {
344
+ max-width: 100%;
345
+ height: 100%;
346
+ display: block;
347
+ }
348
+
349
+ @media print {
350
+ html, body {
351
+ min-height: 100%;
352
+ height: 100%;
353
+ margin: 0;
354
+ }
355
+
356
+ body {
357
+ position: relative;
358
+ }
359
+
360
+ body > * {
361
+ display: none;
362
+ }
363
+
364
+ .tldraw__editor {
365
+ display: none;
366
+ }
367
+
368
+ .${a} {
369
+ display: block !important;
370
+ background: white;
371
+ min-height: 100%;
372
+ height: 100%;
373
+ max-width: 100%;
374
+ }
375
+
376
+ .${a}__item {
377
+ padding: 10mm;
378
+ display: flex;
379
+ min-height: 100%;
380
+ flex-direction: column;
381
+ page-break-after: always;
382
+ position: relative;
383
+ overflow: hidden;
384
+ height: 100%;
385
+ }
386
+
387
+ .${a}__item__main {
388
+ flex: 1;
389
+ display: flex;
390
+ align-items: center;
391
+ justify-content: center;
392
+ max-height: 100%;
393
+ }
394
+
395
+ .${a}__item__header {
396
+ display: none;
397
+ }
398
+
399
+ .${a}__item__footer {
400
+ display: none;
401
+ text-align: right;
402
+ }
403
+
404
+ .${a}__item__footer__hide {
405
+ display: none;
406
+ }
407
+
408
+
409
+ }
410
+
411
+ `;const l=()=>{document.head.appendChild(i),document.body.appendChild(s)},c=()=>{n.once("tick",()=>{o(s,i)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function d(b,C,I){try{s.innerHTML+=`<div class="${a}__item">
412
+ <div class="${a}__item__header">
413
+ ${b.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
414
+ </div>
415
+ <div class="${a}__item__main">
416
+ ${I}
417
+ </div>
418
+ <div class="${a}__item__footer ${a}__item__footer__${C?"":"hide"}">
419
+ ${C??""}
420
+ </div>
421
+ </div>`}catch(_){console.error(_)}}function f(){Pt.isChromeForIos?(l(),window.print()):Pt.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=n.getSelectedShapeIds(),m=n.getCurrentPageId(),y=n.getPages(),x={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(n.getSelectedShapeIds().length>0){const b=await n.getSvgString(p,x);if(b){const C=y.find(I=>I.id===m);d(`tldraw — ${C==null?void 0:C.name}`,null,b.svg),f()}}else{const b=n.getCurrentPage(),C=await n.getSvgString(n.getSortedChildIdsForParent(b.id),x);C&&(d(`tldraw — ${b.name}`,null,C.svg),f())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[n])}function H_(){const{addToast:n,removeToast:e,clearToasts:t}=Ba(),{addDialog:r,clearDialogs:s,removeDialog:i}=Xp(),o=ft(),a=Afe(),l=Ofe(),{cut:c,copy:d,paste:f}=bfe(),p=Ife(),m=Mfe(),y=L_(),x=qr()<gn.TABLET_SM;return P.useMemo(()=>({addToast:n,removeToast:e,clearToasts:t,addDialog:r,removeDialog:i,clearDialogs:s,msg:o,isMobile:x,insertMedia:a,printSelectionOrPages:l,cut:c,copy:d,paste:f,copyAs:p,exportAs:m,getEmbedDefinition:y}),[n,e,t,r,i,s,o,x,a,l,c,d,f,p,m,y])}function Rfe(n,e){const t={};for(const r of n)if(r.translations)for(const[s,i]of xs(r.translations)){let o=t[s];o||(o=t[s]={}),Object.assign(o,i)}return{actions:(r,s,i)=>{for(const o of n)o.actions&&(s=o.actions(r,s,i));return s},tools:(r,s,i)=>{for(const o of n)o.tools&&(s=o.tools(r,s,{...e,...i}));return s},translations:t}}function m9(n){return P.useMemo(()=>n,n)}function Dfe(n){const e=m9(n==null?[]:Array.isArray(n)?n:[n]);return P.useMemo(()=>{const t={};for(const r of e)if(r.translations)for(const[s,i]of xs(r.translations)){let o=t[s];o||(o=t[s]={}),Object.assign(o,i)}return t},[e])}function jfe(n){const e=H_(),t=m9(n==null?[]:Array.isArray(n)?n:[n]);return P.useMemo(()=>Rfe(t,e),[t,e])}const y9=P.createContext(null);function Nfe(n){return Object.fromEntries(n.map(e=>[e.id,e]))}function jm(n,e){if(n.getSelectedShapes().length===0)return n.getDocumentSettings().name||e}function Lfe({overrides:n,children:e}){const t=Tr(),r=w0(),s=H_(),i=Rn(),o=s.msg("document.default-name"),a=P.useMemo(()=>{const l=t;if(!l)return{};function c(){return l.isIn("select")||(l.complete(),l.setCurrentTool("select")),!1}function d(){return l.isIn("select")&&l.getSelectedShapeIds().length>0}const f=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(m){d()&&(c()||(i("edit-link",{source:m}),l.markHistoryStoppingPoint("edit-link"),s.addDialog({component:khe})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(m){i("insert-embed",{source:m}),s.addDialog({component:ZU})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(m){i("insert-media",{source:m}),s.insertMedia()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(m){i("undo",{source:m}),l.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(m){i("redo",{source:m}),l.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(m){let y=l.getSelectedShapeIds();y.length===0&&(y=Array.from(l.getCurrentPageShapeIds().values())),y.length!==0&&(i("export-as",{format:"svg",source:m}),s.exportAs(y,"svg",jm(l,o)))}},{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(m){let y=l.getSelectedShapeIds();y.length===0&&(y=Array.from(l.getCurrentPageShapeIds().values())),y.length!==0&&(i("export-as",{format:"png",source:m}),s.exportAs(y,"png",jm(l,o)))}},{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(m){let y=l.getSelectedShapeIds();y.length===0&&(y=Array.from(l.getCurrentPageShapeIds().values())),y.length!==0&&(i("export-all-as",{format:"svg",source:m}),s.exportAs(Array.from(l.getCurrentPageShapeIds()),"svg",jm(l,o)))}},{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(m){const y=Array.from(l.getCurrentPageShapeIds().values());y.length!==0&&(i("export-all-as",{format:"png",source:m}),s.exportAs(y,"png",jm(l,o)))}},{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(m){let y=l.getSelectedShapeIds();y.length===0&&(y=Array.from(l.getCurrentPageShapeIds().values())),y.length!==0&&(i("copy-as",{format:"svg",source:m}),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(m){let y=l.getSelectedShapeIds();y.length===0&&(y=Array.from(l.getCurrentPageShapeIds().values())),y.length!==0&&(i("copy-as",{format:"png",source:m}),s.copyAs(y,"png"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(m){d()&&(c()||(i("toggle-auto-size",{source:m}),l.markHistoryStoppingPoint("toggling auto size"),l.run(()=>{const y=l.getSelectedShapes().filter(v=>l.isShapeOfType(v,"text")&&v.props.autoSize===!1);l.updateShapes(y.map(v=>({id:v.id,type:v.type,props:{...v.props,w:8,autoSize:!0}}))),Ut(l,y.map(v=>v.id))})))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(m){i("open-embed-link",{source:m});const y=l.getSelectedShapeIds(),v="No embed shapes selected";if(y.length!==1){console.error(v);return}const x=l.getShape(y[0]);if(!x||!l.isShapeOfType(x,"embed")){console.error(v);return}Jae(x.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(m){var y,v;if(((y=l.root.getCurrent())==null?void 0:y.id)!=="zoom"&&(i("zoom-tool",{source:m}),!(l.inputs.shiftKey||l.inputs.ctrlKey))){const x=l.root.getCurrent();x&&((v=x.getCurrent())==null?void 0:v.id)==="idle"&&l.setCurrentTool("zoom",{onInteractionEnd:x.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(m){d()&&(c()||l.run(()=>{i("convert-to-bookmark",{source:m});const y=l.getSelectedShapes(),v=[],x=[];for(const b of y){if(!b||!l.isShapeOfType(b,"embed")||!b.props.url)continue;const C=new E(b.x,b.y);C.rot(-b.rotation),C.add(new E(b.props.w/2-300/2,b.props.h/2-320/2)),C.rot(b.rotation);const I={id:Dt(),type:"bookmark",rotation:b.rotation,x:C.x,y:C.y,opacity:1,props:{url:b.props.url}};v.push(I),x.push(b.id)}l.markHistoryStoppingPoint("convert shapes to bookmark"),l.deleteShapes(x),l.createShapes(v)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(m){d()&&(c()||(i("convert-to-embed",{source:m}),l.run(()=>{const y=l.getSelectedShapeIds(),v=st(y.map(C=>l.getShape(C))),x=[],b=[];for(const C of v){if(!l.isShapeOfType(C,"bookmark"))continue;const{url:I}=C.props,_=s.getEmbedDefinition(I);if(!_||!_.definition)continue;const{width:T,height:A}=_.definition,R=new E(C.x,C.y);R.rot(-C.rotation),R.add(new E(C.props.w/2-T/2,C.props.h/2-A/2)),R.rot(C.rotation);const j={id:Dt(),type:"embed",x:R.x,y:R.y,rotation:C.rotation,props:{url:I,w:T,h:A}};x.push(j),b.push(C.id)}l.markHistoryStoppingPoint("convert shapes to embed"),l.deleteShapes(b),l.createShapes(x)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(m){if(!d()||c())return;i("duplicate-shapes",{source:m});const y=l.getInstanceState();let v,x;if(y.duplicateProps)v=y.duplicateProps.shapeIds,x=y.duplicateProps.offset;else{v=l.getSelectedShapeIds();const b=ye.Common(st(v.map(C=>l.getShapePageBounds(C))));x=l.getCameraOptions().isLocked?{x:l.options.adjacentShapeMargin,y:l.options.adjacentShapeMargin}:{x:b.width+l.options.adjacentShapeMargin,y:0}}l.markHistoryStoppingPoint("duplicate shapes"),l.duplicateShapes(v,x),y.duplicateProps&&l.updateInstanceState({duplicateProps:{...y.duplicateProps,shapeIds:l.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(m){d()&&(c()||(i("ungroup-shapes",{source:m}),l.markHistoryStoppingPoint("ungroup"),l.ungroupShapes(l.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(m){if(!d()||c())return;i("group-shapes",{source:m});const y=l.getOnlySelectedShape();y&&l.isShapeOfType(y,"group")?(l.markHistoryStoppingPoint("ungroup"),l.ungroupShapes(l.getSelectedShapeIds())):(l.markHistoryStoppingPoint("group"),l.groupShapes(l.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(m){if(!d())return;i("remove-frame",{source:m});const y=l.getSelectedShapes();y.length>0&&y.every(v=>l.isShapeOfType(v,"frame"))&&(l.markHistoryStoppingPoint("remove-frame"),she(l,y.map(v=>v.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(m){if(!d())return;i("fit-frame-to-content",{source:m});const y=l.getOnlySelectedShape();y&&l.isShapeOfType(y,"frame")&&(l.markHistoryStoppingPoint("fit-frame-to-content"),ohe(l,y.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(m){d()&&(c()||(i("align-shapes",{operation:"left",source:m}),l.markHistoryStoppingPoint("align left"),l.run(()=>{const y=l.getSelectedShapeIds();l.alignShapes(y,"left"),Ut(l,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(m){d()&&(c()||(i("align-shapes",{operation:"center-horizontal",source:m}),l.markHistoryStoppingPoint("align center horizontal"),l.run(()=>{const y=l.getSelectedShapeIds();l.alignShapes(y,"center-horizontal"),Ut(l,y)})))}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(m){d()&&(c()||(i("align-shapes",{operation:"right",source:m}),l.markHistoryStoppingPoint("align right"),l.run(()=>{const y=l.getSelectedShapeIds();l.alignShapes(y,"right"),Ut(l,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(m){d()&&(c()||(i("align-shapes",{operation:"center-vertical",source:m}),l.markHistoryStoppingPoint("align center vertical"),l.run(()=>{const y=l.getSelectedShapeIds();l.alignShapes(y,"center-vertical"),Ut(l,y)})))}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(m){d()&&(c()||(i("align-shapes",{operation:"top",source:m}),l.markHistoryStoppingPoint("align top"),l.run(()=>{const y=l.getSelectedShapeIds();l.alignShapes(y,"top"),Ut(l,y)})))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(m){d()&&(c()||(i("align-shapes",{operation:"bottom",source:m}),l.markHistoryStoppingPoint("align bottom"),l.run(()=>{const y=l.getSelectedShapeIds();l.alignShapes(y,"bottom"),Ut(l,y)})))}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(m){d()&&(c()||(i("distribute-shapes",{operation:"horizontal",source:m}),l.markHistoryStoppingPoint("distribute horizontal"),l.run(()=>{const y=l.getSelectedShapeIds();l.distributeShapes(y,"horizontal"),Ut(l,y)})))}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(m){d()&&(c()||(i("distribute-shapes",{operation:"vertical",source:m}),l.markHistoryStoppingPoint("distribute vertical"),l.run(()=>{const y=l.getSelectedShapeIds();l.distributeShapes(y,"vertical"),Ut(l,y)})))}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(m){d()&&(c()||(i("stretch-shapes",{operation:"horizontal",source:m}),l.markHistoryStoppingPoint("stretch horizontal"),l.run(()=>{const y=l.getSelectedShapeIds();l.stretchShapes(y,"horizontal"),Ut(l,y)})))}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(m){d()&&(c()||(i("stretch-shapes",{operation:"vertical",source:m}),l.markHistoryStoppingPoint("stretch vertical"),l.run(()=>{const y=l.getSelectedShapeIds();l.stretchShapes(y,"vertical"),Ut(l,y)})))}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(m){d()&&(c()||(i("flip-shapes",{operation:"horizontal",source:m}),l.markHistoryStoppingPoint("flip horizontal"),l.run(()=>{const y=l.getSelectedShapeIds();l.flipShapes(y,"horizontal"),Ut(l,y)})))}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(m){d()&&(c()||(i("flip-shapes",{operation:"vertical",source:m}),l.markHistoryStoppingPoint("flip vertical"),l.run(()=>{const y=l.getSelectedShapeIds();l.flipShapes(y,"vertical"),Ut(l,y)})))}},{id:"pack",label:"action.pack",icon:"pack",onSelect(m){d()&&(c()||(i("pack-shapes",{source:m}),l.markHistoryStoppingPoint("pack"),l.run(()=>{const y=l.getSelectedShapeIds();l.packShapes(y,l.options.adjacentShapeMargin),Ut(l,y)})))}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(m){d()&&(c()||(i("stack-shapes",{operation:"vertical",source:m}),l.markHistoryStoppingPoint("stack-vertical"),l.run(()=>{const y=l.getSelectedShapeIds();l.stackShapes(y,"vertical",16),Ut(l,y)})))}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(m){d()&&(c()||(i("stack-shapes",{operation:"horizontal",source:m}),l.markHistoryStoppingPoint("stack-horizontal"),l.run(()=>{const y=l.getSelectedShapeIds();l.stackShapes(y,"horizontal",16),Ut(l,y)})))}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(m){d()&&(c()||(i("reorder-shapes",{operation:"toFront",source:m}),l.markHistoryStoppingPoint("bring to front"),l.bringToFront(l.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(m){d()&&(c()||(i("reorder-shapes",{operation:"forward",source:m}),l.markHistoryStoppingPoint("bring forward"),l.bringForward(l.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(m){d()&&(c()||(i("reorder-shapes",{operation:"backward",source:m}),l.markHistoryStoppingPoint("send backward"),l.sendBackward(l.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(m){d()&&(c()||(i("reorder-shapes",{operation:"toBack",source:m}),l.markHistoryStoppingPoint("send to back"),l.sendToBack(l.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(m){d()&&(c()||(l.markHistoryStoppingPoint("cut"),s.cut(m)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(m){d()&&(c()||s.copy(m))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(m){var y;(y=navigator.clipboard)==null||y.read().then(v=>{s.paste(v,m,m==="context-menu"?l.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(m){l.run(()=>{c()||(i("select-all-shapes",{source:m}),l.markHistoryStoppingPoint("select all kbd"),l.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(m){d()&&(c()||(i("select-none-shapes",{source:m}),l.markHistoryStoppingPoint("select none"),l.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(m){d()&&(c()||(i("delete-shapes",{source:m}),l.markHistoryStoppingPoint("delete"),l.deleteShapes(l.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(m){d()&&(c()||(i("rotate-cw",{source:m}),l.markHistoryStoppingPoint("rotate-cw"),l.run(()=>{const y=l.getSelectionRotation()%(Ht/2),v=Al(y,0)||Al(y,Ht/2),x=l.getSelectedShapeIds();l.rotateShapesBy(x,Ht/2-(v?0:y)),Ut(l,x)})))}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(m){d()&&(c()||(i("rotate-ccw",{source:m}),l.markHistoryStoppingPoint("rotate-ccw"),l.run(()=>{const y=l.getSelectionRotation()%(Ht/2),v=Al(y,0),x=l.getSelectedShapeIds();l.rotateShapesBy(x,v?-(Ht/2):-y),Ut(l,x)})))}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(m){i("zoom-in",{source:m}),l.zoomIn(void 0,{animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(m){i("zoom-out",{source:m}),l.zoomOut(void 0,{animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(m){i("reset-zoom",{source:m}),l.resetZoom(void 0,{animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(m){i("zoom-to-fit",{source:m}),l.zoomToFit({animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(m){d()&&(c()||(i("zoom-to-selection",{source:m}),l.zoomToSelection({animation:{duration:l.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(m){i("toggle-snap-mode",{source:m}),l.user.updateUserPreferences({isSnapMode:!l.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(m){const y=l.user.getIsDarkMode()?"light":"dark";i("color-scheme",{source:m,value:y}),l.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(m){i("toggle-wrap-mode",{source:m}),l.user.updateUserPreferences({isWrapMode:!l.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(m){i("toggle-dynamic-size-mode",{source:m}),l.user.updateUserPreferences({isDynamicSizeMode:!l.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(m){i("toggle-paste-at-cursor",{source:m}),l.user.updateUserPreferences({isPasteAtCursorMode:!l.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(m){i("toggle-reduce-motion",{source:m}),l.user.updateUserPreferences({animationSpeed:l.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(m){i("toggle-edge-scrolling",{source:m}),l.user.updateUserPreferences({edgeScrollSpeed:l.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(m){i("toggle-transparent",{source:m}),l.updateInstanceState({exportBackground:!l.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(m){i("toggle-tool-lock",{source:m}),l.updateInstanceState({isToolLocked:!l.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(m){i("unlock-all",{source:m});const y=[];for(const v of l.getCurrentPageShapes())v.isLocked&&y.push({id:v.id,type:v.type,isLocked:!1});y.length>0&&l.updateShapes(y)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(m){l.timers.requestAnimationFrame(()=>{l.run(()=>{i("toggle-focus-mode",{source:m}),s.clearDialogs(),s.clearToasts(),l.updateInstanceState({isFocusMode:!l.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(m){i("toggle-grid-mode",{source:m}),l.updateInstanceState({isGridMode:!l.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(m){i("toggle-debug-mode",{source:m}),l.updateInstanceState({isDebugMode:!l.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(m){i("print",{source:m}),s.printSelectionOrPages()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(m){i("exit-pen-mode",{source:m}),l.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(m){i("stop-following",{source:m}),l.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(m){i("zoom-to-content",{source:m});const y=l.getSelectionPageBounds()??l.getCurrentPageBounds();y&&l.zoomToBounds(y,{targetZoom:Math.min(1,l.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(m){l.markHistoryStoppingPoint("locking"),i("toggle-lock",{source:m}),l.toggleLock(l.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(m){const y=Vs.createId(),v=l.getSelectedShapeIds();l.run(()=>{l.markHistoryStoppingPoint("move_shapes_to_page"),l.createPage({name:s.msg("page-menu.new-page-initial-name"),id:y}),l.moveShapesToPage(v,y)}),i("move-to-new-page",{source:m})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(m){const y=Ws;l.run(()=>{l.markHistoryStoppingPoint("change-color"),l.isIn("select")&&l.setStyleForSelectedShapes(y,"white"),l.setStyleForNextShapes(y,"white")}),i("set-style",{source:m,id:y.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(m){const y=eu;l.run(()=>{l.markHistoryStoppingPoint("change-fill"),l.isIn("select")&&l.setStyleForSelectedShapes(y,"fill"),l.setStyleForNextShapes(y,"fill")}),i("set-style",{source:m,id:y.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async m=>{const y=l.getSelectedShapeIds();if(y.length===0)return;l.markHistoryStoppingPoint("flattening to image"),i("flatten-to-image",{source:m});const v=await Dhe(l,y,l.options.flattenImageBoundsExpand);v!=null&&v.length&&l.setSelectedShapes(v)}},{id:"select-geo-tool",kbd:"g",onSelect:async m=>{i("select-tool",{source:m,id:"geo-previous"}),l.setCurrentTool("geo")}}];r&&f.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(m){i("open-cursor-chat",{source:m}),!l.getInstanceState().isCoarsePointer&&l.timers.requestAnimationFrame(()=>{l.updateInstanceState({isChatting:!0})})}});const p=Nfe(f);return n?n(l,p,s):p},[s,t,i,n,o,r]);return g.jsx(y9.Provider,{value:a,children:e})}function yu(){const n=P.useContext(y9);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function pp(n,e){return n?typeof n=="string"?n:e?n[e]??n.default:void 0:void 0}function Ys(){const n=Tr();return ie("isReadonlyMode",()=>!!(n!=null&&n.getIsReadonly()),[n])}const Ffe=Pt.isDarwin?"⌘":"Ctrl",zfe=Pt.isDarwin?"⌥":"Alt";function S9(n){return n===","?[","]:n.split(",")[0].split("").map(e=>{const t=e.replace(/\$/g,Ffe).replace(/\?/g,zfe).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function RE(n){return"— "+S9(n).join(" ")}function Df({children:n,visibleOnMobileLayout:e=!1}){const t=qr();return!e&&t<gn.MOBILE?null:g.jsx("kbd",{className:"tlui-kbd",children:S9(n).map((r,s)=>g.jsx("span",{children:r},s))})}const v9=P.createContext(null);function P0(){const n=P.useContext(v9);if(!n)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return n}function Ci({type:n,sourceId:e,children:t}){return g.jsx(v9.Provider,{value:{type:n,sourceId:e},children:t})}function E0({id:n,kbd:e,label:t,readonlyOk:r,onSelect:s,toggle:i=!1,disabled:o=!1,checked:a=!1}){const{type:l,sourceId:c}=P0(),d=Ys(),f=ft();if(d&&!r)return null;const p=pp(t,l),m=p?f(p):void 0;switch(l){case"menu":return g.jsxs(ehe,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:m,onSelect:y=>{s==null||s(c),tt(y)},disabled:o,checked:a,children:[g.jsx(Bo,{small:!0,icon:i?a?"toggle-on":"toggle-off":a?"check":"none"}),m&&g.jsx("span",{className:"tlui-button__label",draggable:!1,children:m}),e&&g.jsx(Df,{children:e})]});case"context-menu":return g.jsxs(Mde,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:m,onSelect:y=>{s(c),tt(y)},disabled:o,checked:a,children:[g.jsx(Bo,{small:!0,icon:i?a?"toggle-on":"toggle-off":a?"check":"none"}),m&&g.jsx("span",{className:"tlui-button__label",draggable:!1,children:m}),e&&g.jsx(Df,{children:e})]},n);default:return null}}function Ua(n,e){const t=Tr(),r=P.useCallback(o=>{o&&(t==null||t.complete()),e==null||e(o)},[t,e]),s=Rn(),i=P.useCallback(o=>{s(o,{source:"unknown",id:n})},[n,s]);return Hae(t?`${n}-${t.contextId}`:n,r,i)}function su({id:n,children:e,modal:t=!1,debugOpen:r=!1}){const[s,i]=Ua(n);return g.jsx(I_,{open:r||s,dir:"ltr",modal:t,onOpenChange:i,children:e})}function iu({children:n,...e}){return g.jsx(__,{dir:"ltr",asChild:!0,onTouchEnd:t=>tt(t),...e,children:n})}function ou({className:n,side:e="bottom",align:t="start",sideOffset:r=8,alignOffset:s=8,children:i}){const o=In();return g.jsx(y0,{container:o,children:g.jsx(T_,{className:ze("tlui-menu",n),side:e,sideOffset:r,align:t,alignOffset:s,collisionPadding:4,children:i})})}function $fe({id:n,children:e}){const[t,r]=Ua(n);return g.jsx(the,{open:t,onOpenChange:r,children:e})}function Bfe({id:n,label:e,title:t,disabled:r}){return g.jsx(nhe,{dir:"ltr",asChild:!0,disabled:r,children:g.jsxs(Ke,{"data-testid":n,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[g.jsx(wn,{children:e}),g.jsx(ct,{icon:"chevron-right",small:!0})]})})}function Ufe({id:n,alignOffset:e=-1,sideOffset:t=-6,size:r="small",children:s}){const i=In();return g.jsx(y0,{container:i,children:g.jsx(rhe,{"data-testid":n,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:t,collisionPadding:4,"data-size":r,children:s})})}function Hfe({children:n}){return g.jsx(Jde,{dir:"ltr",className:"tlui-menu__group",children:n})}function gp({noClose:n,children:e}){return g.jsx(Qde,{dir:"ltr",asChild:!0,onClick:n?tt:void 0,children:e})}function lt({id:n,label:e,children:t}){const{type:r,sourceId:s}=P0(),i=ft(),o=pp(e,r),a=o?i(o):void 0;switch(r){case"panel":return g.jsx("div",{className:"tlui-menu__group","data-testid":`${s}-group.${n}`,children:t});case"menu":return g.jsx(Hfe,{"data-testid":`${s}-group.${n}`,children:t});case"context-menu":return g.jsx(pU,{dir:"ltr",className:"tlui-menu__group","data-testid":`${s}-group.${n}`,children:t});case"keyboard-shortcuts":return g.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${s}-group.${n}`,children:[g.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),g.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function ks({id:n,disabled:e=!1,label:t,size:r="small",children:s}){const{type:i,sourceId:o}=P0(),a=In(),l=ft(),c=t?typeof t=="string"?t:t[i]??t.default:void 0,d=c?l(c):void 0;switch(i){case"menu":return g.jsxs($fe,{id:`${o}-sub.${n}`,children:[g.jsx(Bfe,{id:`${o}-sub.${n}-button`,disabled:e,label:d,title:d}),g.jsx(Ufe,{id:`${o}-sub.${n}-content`,size:r,children:s})]});case"context-menu":return e?null:g.jsxs(Kfe,{id:`${o}-sub.${n}`,children:[g.jsx(SU,{dir:"ltr",disabled:e,asChild:!0,children:g.jsxs(Ke,{"data-testid":`${o}-sub.${n}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[g.jsx(wn,{children:d}),g.jsx(ct,{icon:"chevron-right",small:!0})]})}),g.jsx(E_,{container:a,children:g.jsx(vU,{"data-testid":`${o}-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 Kfe({id:n,children:e}){const[t,r]=Ua(n);return g.jsx(yU,{open:t,onOpenChange:r,children:e})}const Wfe=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Vfe(){const n=te(),e=Rn(),t=ie("colorScheme",()=>n.user.getUserPreferences().colorScheme??(n.user.getIsDarkMode()?"dark":"light"),[n]);return g.jsx(ks,{id:"help menu color-scheme",label:"menu.theme",children:g.jsx(lt,{id:"theme",children:Wfe.map(({colorScheme:r,label:s})=>g.jsx(E0,{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 qfe=({id:n,component:e,onClose:t,preventBackgroundClose:r})=>{const{removeDialog:s}=Xp(),i=P.useRef(!1),o=In(),a=P.useCallback(l=>{if(!l){if(t)try{t()}catch(c){console.warn(c)}s(n)}},[n,t,s]);return g.jsx(whe,{onOpenChange:a,defaultOpen:!0,children:g.jsx(bhe,{container:o,children:g.jsx(Che,{dir:"ltr",className:"tlui-dialog__overlay",onClick:l=>{i.current||!r&&l.target===l.currentTarget&&a(!1)},children:g.jsx(Phe,{dir:"ltr",className:"tlui-dialog__content","aria-describedby":void 0,onMouseDown:()=>i.current=!0,onMouseUp:()=>i.current=!1,onInteractOutside:l=>{i.current=!1,r&&l.preventDefault()},children:g.jsx(e,{onClose:()=>{i.current=!1,a(!1)}})})})})})},Gfe=P.memo(function(){const{dialogs:e}=Xp();return ie("dialogs",()=>e.get(),[e]).map(r=>g.jsx(qfe,{...r},r.id))}),Yfe=4e3,Xfe={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Zfe({toast:n}){const{removeToast:e}=Ba(),t=ft(),r=o=>{o||e(n.id)},s=n.actions&&n.actions.length>0,i=n.icon||n.severity&&Xfe[n.severity];return g.jsxs(nfe,{onOpenChange:r,className:"tlui-toast__container",duration:n.keepOpen?1/0:Yfe,"data-severity":n.severity,children:[i&&g.jsx("div",{className:"tlui-toast__icon",children:g.jsx(Bo,{icon:i})}),g.jsxs("div",{className:"tlui-toast__main","data-title":!!n.title,"data-description":!!n.description,"data-actions":!!n.actions,children:[g.jsxs("div",{className:"tlui-toast__content",children:[n.title&&g.jsx(rfe,{className:"tlui-toast__title",children:n.title}),n.description&&g.jsx(sfe,{className:"tlui-toast__description",children:n.description})]}),n.actions&&g.jsxs("div",{className:"tlui-toast__actions",children:[n.actions.map((o,a)=>g.jsx(ife,{altText:o.label,asChild:!0,onClick:o.onClick,children:g.jsx(Ke,{type:o.type,children:g.jsx(wn,{children:o.label})})},a)),g.jsx(MN,{asChild:!0,children:g.jsx(Ke,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:g.jsx(wn,{children:n.closeLabel??t("toast.close")})})})]})]}),!s&&g.jsx(MN,{asChild:!0,children:g.jsx(Ke,{type:"normal",className:"tlui-toast__close",children:g.jsx(wn,{children:n.closeLabel??t("toast.close")})})})]})}const Jfe=P.memo(function(){const{toasts:e}=Ba(),t=ie("toasts",()=>e.get(),[]);return g.jsxs(g.Fragment,{children:[t.map(r=>g.jsx(Zfe,{toast:r},r.id)),g.jsx(n9,{className:"tlui-toast__viewport"})]})});function oo({actionId:n="",...e}){const r=yu()[n];return r?g.jsx(E0,{...r,...e}):null}function jN(n){return g.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...n,children:g.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[g.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),g.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:g.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}function nr({disabled:n=!1,spinner:e=!1,readonlyOk:t=!1,id:r,kbd:s,label:i,icon:o,onSelect:a,noClose:l,isSelected:c}){const{type:d,sourceId:f}=P0(),p=ft(),[m,y]=P.useState(!1);if(Ys()&&!t)return null;const x=pp(i,d),b=s?RE(s):void 0,C=x?p(x):void 0,I=C&&b?`${C} ${b}`:C;switch(d){case"menu":return g.jsx(gp,{children:g.jsxs(Ke,{type:"menu","data-testid":`${f}.${r}`,disabled:n,title:I,onClick:_=>{l&&tt(_),m?y(!1):a(f)},children:[g.jsx(wn,{children:C}),s&&g.jsx(Df,{children:s})]})});case"context-menu":return n?null:g.jsxs(gU,{dir:"ltr",title:I,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${f}.${r}`,onSelect:_=>{l&&tt(_),m?y(!1):a(f)},children:[g.jsx("span",{className:"tlui-button__label",draggable:!1,children:C}),s&&g.jsx(Df,{children:s}),e&&g.jsx(jN,{})]});case"panel":return g.jsxs(Ke,{"data-testid":`${f}.${r}`,type:"menu",title:I,disabled:n,onClick:()=>a(f),children:[g.jsx(wn,{children:C}),e?g.jsx(jN,{}):o&&g.jsx(ct,{icon:o})]});case"small-icons":case"icons":return g.jsx(Ke,{"data-testid":`${f}.${r}`,type:"icon",title:I,disabled:n,onClick:()=>a(f),children:g.jsx(ct,{icon:o,small:d==="small-icons"})});case"keyboard-shortcuts":return s?g.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${f}.${r}`,children:[g.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:C}),g.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:g.jsx(Df,{visibleOnMobileLayout:!0,children:s})})]}):(console.warn(`Menu item '${i}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return g.jsxs(Ke,{type:"low",onClick:()=>a(f),children:[g.jsx(ct,{icon:o}),g.jsx(wn,{children:C})]});case"toolbar":return g.jsx(Ke,{type:"tool","data-testid":`tools.${r}`,"aria-label":x,"data-value":r,onClick:()=>a("toolbar"),title:I,disabled:n,onTouchStart:_=>{tt(_),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:g.jsx(ct,{icon:o})});case"toolbar-overflow":return g.jsx(gp,{"aria-label":i,children:g.jsx(Ke,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:I,disabled:n,role:"radio","aria-checked":c?"true":"false","data-value":r,children:g.jsx(ct,{icon:o})})});default:throw En(d)}}function ue({actionId:n="",...e}){const r=yu()[n];return r?g.jsx(nr,{...r,...e}):null}const x9=P.createContext(null);function Qfe({overrides:n,children:e}){const t=Tr(),r=Rn(),s=H_(),i=P.useMemo(()=>{if(!t)return{};const o=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(l){if(t.isIn("select")){const c=t.root.getCurrent();c.exit({},c.id),c.enter({},c.id)}t.setCurrentTool("select"),r("select-tool",{source:l,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(l){t.setCurrentTool("hand"),r("select-tool",{source:l,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(l){t.setCurrentTool("eraser"),r("select-tool",{source:l,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(l){t.setCurrentTool("draw"),r("select-tool",{source:l,id:"draw"})}},...[...Wi.values].map(l=>({id:l,label:`tool.${l}`,meta:{geo:l},kbd:l==="rectangle"?"r":l==="ellipse"?"o":void 0,icon:"geo-"+l,onSelect(c){t.run(()=>{t.setStyleForNextShapes(Wi,l),t.setCurrentTool("geo"),r("select-tool",{source:c,id:`geo-${l}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(l){t.setCurrentTool("arrow"),r("select-tool",{source:l,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(l){t.setCurrentTool("line"),r("select-tool",{source:l,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(l){t.setCurrentTool("frame"),r("select-tool",{source:l,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(l){t.setCurrentTool("text"),r("select-tool",{source:l,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(l){s.insertMedia(),r("select-tool",{source:l,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(l){t.setCurrentTool("note"),r("select-tool",{source:l,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(l){t.setCurrentTool("laser"),r("select-tool",{source:l,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(l){s.addDialog({component:ZU}),r("select-tool",{source:l,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(l){t.setCurrentTool("highlight"),r("select-tool",{source:l,id:"highlight"})}}];o.push();const a=Object.fromEntries(o.map(l=>[l.id,l]));return n?n(t,a,s):a},[n,t,r,s]);return g.jsx(x9.Provider,{value:i,children:e})}function K_(){const n=P.useContext(x9);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function hs({toolId:n="",...e}){const r=K_()[n];return r?g.jsx(nr,{...r,...e}):null}function epe({children:n}){const e=te();return ie("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])?g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}):null}const{PI:tpe}=Math,Rd=tpe+1e-4;function w9(n,e={}){const{size:t=16,smoothing:r=.5}=e;if(n.length===0||t<=0)return{left:[],right:[]};const s=n[0],i=n[n.length-1],o=i.runningLength,a=Math.pow(t*r,2),l=[],c=[];let d=n[0].vector,f=n[0].point,p=f,m=f,y=p,v=!1,x;for(let b=0;b<n.length;b++){x=n[b];const{point:C,vector:I}=n[b],_=x.vector.dpr(d),T=(b<n.length-1?n[b+1]:n[b]).vector,A=b<n.length-1?T.dpr(x.vector):1,R=_<0&&!v,j=A!==null&&A<.2;if(R||j){if(A>-.62&&o-x.runningLength>x.radius){const U=d.clone().mul(x.radius);d.clone().cpr(T)<0?(m=E.Add(C,U),y=E.Sub(C,U)):(m=E.Sub(C,U),y=E.Add(C,U)),l.push(m),c.push(y)}else{const U=d.clone().mul(x.radius).per(),J=E.Sub(x.input,U);for(let z=1/13,N=0;N<1;N+=z)m=E.RotWith(J,x.input,Rd*N),l.push(m),y=E.RotWith(J,x.input,Rd+Rd*-N),c.push(y)}f=m,p=y,j&&(v=!0);continue}if(v=!1,x===s||x===i){const U=E.Per(I).mul(x.radius);l.push(E.Sub(C,U)),c.push(E.Add(C,U));continue}const K=E.Lrp(T,I,A).per().mul(x.radius);m=E.Sub(C,K),(b<=1||E.Dist2(f,m)>a)&&(l.push(m),f=m),y=E.Add(C,K),(b<=1||E.Dist2(p,y)>a)&&(c.push(y),p=y),d=I}return{left:l,right:c}}function W_(n,e={}){const{size:t=16,start:r={},end:s={},last:i=!1}=e,{cap:o=!0}=r,{cap:a=!0}=s;if(n.length===0||t<=0)return[];const l=n[0],c=n[n.length-1],d=c.runningLength,f=r.taper===!1?0:r.taper===!0?Math.max(t,d):r.taper,p=s.taper===!1?0:s.taper===!0?Math.max(t,d):s.taper,{left:m,right:y}=w9(n,e),v=l.point,x=n.length>1?n[n.length-1].point:E.AddXY(l.point,1,1);if(n.length===1&&(!(f||p)||i)){const _=E.Add(v,E.Sub(v,x).uni().per().mul(-l.radius)),T=[];for(let A=1/13,R=A;R<=1;R+=A)T.push(E.RotWith(_,v,Rd*2*R));return T}const b=[];if(!(f||p&&n.length===1))if(o)for(let _=1/8,T=_;T<=1;T+=_){const A=E.RotWith(y[0],v,Rd*T);b.push(A)}else{const _=E.Sub(m[0],y[0]),T=E.Mul(_,.5),A=E.Mul(_,.51);b.push(E.Sub(v,T),E.Sub(v,A),E.Add(v,A),E.Add(v,T))}const C=[],I=c.vector.clone().per().neg();if(p||f&&n.length===1)C.push(x);else if(a){const _=E.Add(x,E.Mul(I,c.radius));for(let T=1/29,A=T;A<1;A+=T)C.push(E.RotWith(_,x,Rd*3*A))}else C.push(E.Add(x,E.Mul(I,c.radius)),E.Add(x,E.Mul(I,c.radius*.99)),E.Sub(x,E.Mul(I,c.radius*.99)),E.Sub(x,E.Mul(I,c.radius)));return m.concat(C,y.reverse(),b)}const npe=.025,rpe=.01;function Uo(n,e={}){var x;const{streamline:t=.5,size:r=16,simulatePressure:s=!1}=e;if(n.length===0)return[];const i=.15+(1-t)*.85;let o=n.map(E.From),a=0;if(!s){let b=o[0];for(;b&&!(b.z>=npe);)o.shift(),b=o[0]}if(!s){let b=o[o.length-1];for(;b&&!(b.z>=rpe);)o.pop(),b=o[o.length-1]}if(o.length===0)return[{point:E.From(n[0]),input:E.From(n[0]),pressure:s?.5:.15,vector:new E(1,1),distance:0,runningLength:0,radius:1}];let l=o[1];for(;l&&!(E.Dist2(l,o[0])>(r/3)**2);)o[0].z=Math.max(o[0].z,l.z),o.splice(1,1),l=o[1];const c=o.pop();for(l=o[o.length-1];l&&!(E.Dist2(l,c)>(r/3)**2);)o.pop(),l=o[o.length-1],a++;o.push(c);const d=e.last||!e.simulatePressure||o.length>1&&E.Dist2(o[o.length-1],o[o.length-2])<r**2||a>0;if(o.length===2&&e.simulatePressure){const b=o[1];o=o.slice(0,-1);for(let C=1;C<5;C++){const I=E.Lrp(o[0],b,C/4);I.z=(o[0].z+(b.z-o[0].z))*C/4,o.push(I)}}const f=[{point:o[0],input:o[0],pressure:s?.5:o[0].z,vector:new E(1,1),distance:0,runningLength:0,radius:1}];let p=0,m=f[0],y,v;d&&t>0&&o.push(o[o.length-1].clone());for(let b=1,C=o.length;b<C;b++)y=!i||e.last&&b===C-1?o[b].clone():o[b].clone().lrp(m.point,1-i),!m.point.equals(y)&&(v=E.Dist(y,m.point),p+=v,!(b<4&&p<r)&&(m={input:o[b],point:y,pressure:s?.5:o[b].z,vector:E.Sub(m.point,y).uni(),distance:v,runningLength:p,radius:1},f.push(m)));if((x=f[1])!=null&&x.vector&&(f[0].vector=f[1].vector.clone()),p<1){const b=Math.max(.5,...f.map(C=>C.pressure));f.forEach(C=>C.pressure=b)}return f}const{min:hl}=Math,RC=.275;function k0(n,e){const{size:t=16,thinning:r=.5,simulatePressure:s=!0,easing:i=x=>x,start:o={},end:a={}}=e,{easing:l=$n.easeOutQuad}=o,{easing:c=$n.easeOutCubic}=a,d=n[n.length-1].runningLength;let f,p=n[0].pressure,m;if(!s&&d<t){const x=n.reduce((b,C)=>Math.max(b,C.pressure),.5);return n.forEach(b=>{b.pressure=x,b.radius=t*i(.5-r*(.5-b.pressure))}),n}else{let x;for(let b=0,C=n.length;b<C&&(m=n[b],!(m.runningLength>t*5));b++){const I=hl(1,m.distance/t);if(s){const _=hl(1,1-I);x=hl(1,p+(_-p)*(I*RC))}else x=hl(1,p+(m.pressure-p)*.5);p=p+(x-p)*.5}for(let b=0;b<n.length;b++){if(m=n[b],r){let{pressure:C}=m;const I=hl(1,m.distance/t);if(s){const _=hl(1,1-I);C=hl(1,p+(_-p)*(I*RC))}else C=hl(1,p+(C-p)*(I*RC));m.radius=t*i(.5-r*(.5-C)),p=C}else m.radius=t/2;f===void 0&&(f=m.radius)}}const y=o.taper===!1?0:o.taper===!0?Math.max(t,d):o.taper,v=a.taper===!1?0:a.taper===!0?Math.max(t,d):a.taper;if(y||v)for(let x=0;x<n.length;x++){m=n[x];const{runningLength:b}=m,C=b<y?l(b/y):1,I=d-b<v?c((d-b)/v):1;m.radius=Math.max(.01,m.radius*Math.min(C,I))}return n}function spe(n,e={}){return W_(k0(Uo(n,e),e),e)}function NN({scribble:n,zoom:e,color:t,opacity:r,className:s}){if(!n.points.length)return null;const i=spe(n.points,{size:n.size/e,start:{taper:n.taper,easing:$n.linear},last:n.state==="stopping",simulatePressure:!1,streamline:.32});let o;if(i.length<4){const a=n.size/e/2,{x:l,y:c}=n.points[n.points.length-1];o=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else o=FI(i);return g.jsx("svg",{className:s&&ze("tl-overlays__item",s),children:g.jsx("path",{className:"tl-scribble",d:o,fill:t??`var(--color-${n.color})`,opacity:r??n.opacity})})}const ipe=({bounds:n,rotation:e})=>{const t=te();return ie("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?g.jsx(az,{bounds:n,rotation:e}):null};function ope({size:n,width:e,height:t,hideAlternateHandles:r}){const s=ee(n/3),i=s/2;return g.jsxs("svg",{className:"tl-overlays__item",children:[g.jsx("polyline",{className:"tl-corner-crop-handle",points:`
422
+ ${ee(0-i)},${ee(n)}
423
+ ${ee(0-i)},${ee(0-i)}
424
+ ${ee(n)},${ee(0-i)}`,strokeWidth:s,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),g.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(e/2-n),y1:ee(0-i),x2:ee(e/2+n),y2:ee(0-i),strokeWidth:s,"data-testid":"selection.crop.top","aria-label":"top handle"}),g.jsx("polyline",{className:ze("tl-corner-crop-handle",{"tl-hidden":r}),points:`
425
+ ${ee(e-n)},${ee(0-i)}
426
+ ${ee(e+i)},${ee(0-i)}
427
+ ${ee(e+i)},${ee(n)}`,strokeWidth:s,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),g.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(e+i),y1:ee(t/2-n),x2:ee(e+i),y2:ee(t/2+n),strokeWidth:s,"data-testid":"selection.crop.right","aria-label":"right handle"}),g.jsx("polyline",{className:"tl-corner-crop-handle",points:`
428
+ ${ee(e+i)},${ee(t-n)}
429
+ ${ee(e+i)},${ee(t+i)}
430
+ ${ee(e-n)},${ee(t+i)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),g.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(e/2-n),y1:ee(t+i),x2:ee(e/2+n),y2:ee(t+i),strokeWidth:s,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),g.jsx("polyline",{className:ze("tl-corner-crop-handle",{"tl-hidden":r}),points:`
431
+ ${ee(0+n)},${ee(t+i)}
432
+ ${ee(0-i)},${ee(t+i)}
433
+ ${ee(0-i)},${ee(t-n)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),g.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:ee(0-i),y1:ee(t/2-n),x2:ee(0-i),y2:ee(t/2+n),strokeWidth:s,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const ape=Vn(function({bounds:e,rotation:t}){const r=te(),s=P.useRef(null),i=Ys(),o=Co("top"),a=Co("right"),l=Co("bottom"),c=Co("left"),d=Co("top_left"),f=Co("top_right"),p=Co("bottom_right"),m=Co("bottom_left"),y=r.getInstanceState().cursor.type==="default",v=r.getInstanceState().isCoarsePointer,x=r.getOnlySelectedShape(),b=x&&r.isShapeOrAncestorLocked(x),C=x?r.getShapeUtil(x).expandSelectionOutlinePx(x):0,I=C instanceof ye?e.clone().expand(C).zeroFix():e.clone().expandBy(C).zeroFix();if(sh(s,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:I.x-e.x,y:I.y-e.y}),x&&r.isShapeHidden(x))return null;const _=r.getZoomLevel(),T=r.getInstanceState().isChangingStyle,A=I.width,R=I.height,j=8/_,K=A<j*2,U=R<j*2,J=A<j*4,z=R<j*4,N=A<j*5,L=R<j*5,V=v?1.75:1,X=6/_*V,W=(J?X/2:X)*(V*.75),$=(z?X/2:X)*(V*.75),G=(x?!r.getShapeUtil(x).hideSelectionBoundsFg(x):!0)&&!T;let re=G&&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")||G&&r.isIn("select.resizing")&&x&&r.isShapeOfType(x,"text");x&&re&&Pt.isFirefox&&r.isShapeOfType(x,"embed")&&(re=!1);const H=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!T&&!i,ne=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!T&&!i,ge=!v&&!(K||U)&&(ne||H)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!b,Pe=v&&(!J||!z)&&(ne||H)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!b,ce=ne&&(x?r.getShapeUtil(x).canResize(x)&&!r.getShapeUtil(x).hideResizeHandles(x):!0)&&!H&&!b,Be=K||U,Re=K&&U,Ce=N||L,_e=ce||H,Ve=!ge,it=!ne||!Pe,cn=!ne||!_e,It=!ne||!_e||Be,Jt=!ne||!_e||Be,jt=!ne||!_e||Re&&!H;let Mt=!0,Yr=!0;if(H)Mt=Ce,Yr=Ce;else if(ce){Mt=Be||Re||v;const Jr=v&&x&&x.type==="text";Yr=Mt&&!Jr}const Xr=Math.min(24/_,R-$*3),Zr=ne&&v&&x&&r.isShapeOfType(x,"text")&&Xr*_>=4;return g.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:g.jsxs("g",{ref:s,children:[re&&g.jsx("rect",{className:"tl-selection__fg__outline",width:ee(A),height:ee(R)}),g.jsx(Nm,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:X,corner:"top_left_rotate",cursor:y?Ds("nwse-rotate",t):void 0,isHidden:Ve}),g.jsx(Nm,{"data-testid":"selection.rotate.top-right",cx:A+X*3,cy:0,targetSize:X,corner:"top_right_rotate",cursor:y?Ds("nesw-rotate",t):void 0,isHidden:Ve}),g.jsx(Nm,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:R+X*3,targetSize:X,corner:"bottom_left_rotate",cursor:y?Ds("swne-rotate",t):void 0,isHidden:Ve}),g.jsx(Nm,{"data-testid":"selection.rotate.bottom-right",cx:A+X*3,cy:R+X*3,targetSize:X,corner:"bottom_right_rotate",cursor:y?Ds("senw-rotate",t):void 0,isHidden:Ve}),g.jsx(cpe,{"data-testid":"selection.rotate.mobile",cx:J?-X*1.5:A/2,cy:J?R/2:-X*1.5,size:j,isHidden:it}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Mt}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:ee(0-(z?$*2:$)),width:ee(A),height:ee(Math.max(1,$*2)),style:y?{cursor:Ds("ns-resize",t)}:void 0,...o}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Yr}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:ee(A-(J?0:W)),y:0,height:ee(R),width:ee(Math.max(1,W*2)),style:y?{cursor:Ds("ew-resize",t)}:void 0,...a}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Mt}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:ee(R-(z?0:$)),width:ee(A),height:ee(Math.max(1,$*2)),style:y?{cursor:Ds("ns-resize",t)}:void 0,...l}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Yr}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:ee(0-(J?W*2:W)),y:0,height:ee(R),width:ee(Math.max(1,W*2)),style:y?{cursor:Ds("ew-resize",t)}:void 0,...c}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":cn}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:ee(0-(J?W*2:W*1.5)),y:ee(0-(z?$*2:$*1.5)),width:ee(W*3),height:ee($*3),style:y?{cursor:Ds("nwse-resize",t)}:void 0,...d}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":It}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:ee(A-(J?0:W*1.5)),y:ee(0-(z?$*2:$*1.5)),width:ee(W*3),height:ee($*3),style:y?{cursor:Ds("nesw-resize",t)}:void 0,...f}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":jt}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:ee(A-(J?W:W*1.5)),y:ee(R-(z?$:$*1.5)),width:ee(W*3),height:ee($*3),style:y?{cursor:Ds("nwse-resize",t)}:void 0,...p}),g.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Jt}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:ee(0-(J?W*3:W*1.5)),y:ee(R-(z?0:$*1.5)),width:ee(W*3),height:ee($*3),style:y?{cursor:Ds("nesw-resize",t)}:void 0,...m}),ce&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.resize.top-left",className:ze("tl-corner-handle",{"tl-hidden":cn}),"aria-label":"top_left handle",x:ee(0-j/2),y:ee(0-j/2),width:ee(j),height:ee(j)}),g.jsx("rect",{"data-testid":"selection.resize.top-right",className:ze("tl-corner-handle",{"tl-hidden":It}),"aria-label":"top_right handle",x:ee(A-j/2),y:ee(0-j/2),width:ee(j),height:ee(j)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ze("tl-corner-handle",{"tl-hidden":jt}),"aria-label":"bottom_right handle",x:ee(A-j/2),y:ee(R-j/2),width:ee(j),height:ee(j)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ze("tl-corner-handle",{"tl-hidden":Jt}),"aria-label":"bottom_left handle",x:ee(0-j/2),y:ee(R-j/2),width:ee(j),height:ee(j)})]}),Zr&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:ee(0-j/4),y:ee(R/2-Xr/2),rx:j/4,width:ee(j/2),height:ee(Xr)}),g.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:j/4,x:ee(A-j/4),y:ee(R/2-Xr/2),width:ee(j/2),height:ee(Xr)})]}),H&&g.jsx(ope,{size:j,width:A,height:R,hideAlternateHandles:Ce})]})})}),Nm=function({cx:e,cy:t,targetSize:r,corner:s,cursor:i,isHidden:o,"data-testid":a}){const l=Co(s);return g.jsx("rect",{className:ze("tl-transparent","tl-rotate-corner",{"tl-hidden":o}),"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:i,...l})},lpe=Math.sqrt(Math.PI),cpe=function({cx:e,cy:t,size:r,isHidden:s,"data-testid":i}){const o=Co("mobile_rotate"),a=te(),l=ie("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return g.jsxs("g",{children:[g.jsx("circle",{"data-testid":i,pointerEvents:"all",className:ze("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":s}),cx:e,cy:t,r:c,...o}),g.jsx("circle",{className:ze("tl-mobile-rotate__fg",{"tl-hidden":s}),cx:e,cy:t,r:r/lpe})]})};function upe(){const n=te();return ie("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])?g.jsx(lz,{}):null}function DE(n,e,t){const{arrowheadStart:r,arrowheadEnd:s}=e.props,i=bd(n,e,t),o=i.start.clone(),a=i.end.clone(),l=E.Med(o,a);if(E.Equals(o,a))return{bindings:t,isStraight:!0,start:{handle:o,point:o,arrowhead:e.props.arrowheadStart},end:{handle:a,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:!1,length:0};const c=E.Sub(a,o).uni(),d=IS(n,e,"start"),f=IS(n,e,"end"),p=n.getShapePageTransform(e);LN(a,i.start,p,f),LN(o,i.end,p,d);let m=0,y=0,v=0,x=0,b=jf*e.props.scale;const C=d&&f&&d.shape===f.shape,I=d&&f?V_(n,d.shape.id,f.shape.id):"safe";I==="safe"&&d&&f&&!C&&!d.isExact&&!f.isExact&&(f.didIntersect&&!d.didIntersect?d.isClosed&&o.setTo(a.clone().add(c.clone().mul(jf*e.props.scale))):f.didIntersect||f.isClosed&&a.setTo(o.clone().sub(c.clone().mul(jf*e.props.scale))));const _=E.Sub(a,o),T=E.Len(_)?_.uni():E.From(_),A=!E.Equals(T,c);C||(I!=="start-contains-end"&&d&&r!=="none"&&!d.isExact&&(v=Ro[e.props.size]/2+("size"in d.shape.props?Ro[d.shape.props.size]/2:0),m=(_S+v)*e.props.scale,b+=v*e.props.scale),I!=="end-contains-start"&&f&&s!=="none"&&!f.isExact&&(x=Ro[e.props.size]/2+("size"in f.shape.props?Ro[f.shape.props.size]/2:0),y=(_S+x)*e.props.scale,b+=x*e.props.scale));const R=o.clone().add(T.clone().mul(m*(A?-1:1))),j=a.clone().sub(T.clone().mul(y*(A?-1:1)));E.DistMin(R,j,b)&&(m!==0&&y!==0?(m*=-1.5,y*=-1.5):m!==0?m*=-1:y!==0&&(y*=-1)),o.add(T.clone().mul(m*(A?-1:1))),a.sub(T.clone().mul(y*(A?-1:1))),A?(d&&f&&a.setTo(E.Add(o,T.clone().mul(-10*e.props.scale))),l.setTo(E.Med(i.start,i.end))):l.setTo(E.Med(o,a));const K=E.Dist(o,a);return{bindings:t,isStraight:!0,start:{handle:i.start,point:o,arrowhead:e.props.arrowheadStart},end:{handle:i.end,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:K>0,length:K}}function LN(n,e,t,r){if(r===void 0||r.isExact)return;const s=ve.applyToPoint(t,e),i=ve.applyToPoint(t,n),o=ve.applyToPoint(ve.Inverse(r.transform),s),a=ve.applyToPoint(ve.Inverse(r.transform),i),l=r.isClosed,d=(l?UI:Sse)(o,a,r.outline);let f;if(d!==null&&(f=d.sort((y,v)=>E.Dist2(y,o)-E.Dist2(v,o))[0]??(l?void 0:a)),f===void 0)return;const p=ve.applyToPoint(r.transform,f),m=ve.applyToPoint(ve.Inverse(t),p);n.setTo(m),r.didIntersect=!0}function dpe(n,e,t){const{arrowheadEnd:r,arrowheadStart:s}=e.props,i=e.props.bend;if(Math.abs(i)>Math.abs(e.props.bend*(mpe*e.props.scale)))return DE(n,e,t);const o=bd(n,e,t),a=E.Med(o.start,o.end),l=E.Sub(o.end,o.start),c=E.Len(l)?l.uni():E.From(l),d=E.Add(a,c.per().mul(-i)),f=IS(n,e,"start"),p=IS(n,e,"end"),m=o.start.clone(),y=o.end.clone(),v=d.clone();if(E.Equals(m,y))return{bindings:t,isStraight:!0,start:{handle:m,point:m,arrowhead:e.props.arrowheadStart},end:{handle:y,point:y,arrowhead:e.props.arrowheadEnd},middle:v,isValid:!1,length:0};const x=e.props.bend<0,b=x?Ip:eF,C=FN(m,y,v),I=E.Angle(C.center,m),_=E.Angle(C.center,y),T=b(I,_);if(C.length===0||C.size===0||!RR(C.length)||!RR(C.size))return DE(n,e,t);const A=m.clone(),R=y.clone(),j=v.clone(),K=n.getShapePageTransform(e);let U=0,J=0,z=jf*e.props.scale;if(f&&!f.isExact){const re=ve.applyToPoint(K,A),H=ve.applyToPoint(K,C.center),ne=ve.applyToPoint(K,R),ge=ve.Inverse(f.transform),Pe=ve.applyToPoint(ge,re),ce=ve.applyToPoint(ge,H),Be=ve.applyToPoint(ge,ne),{isClosed:Re}=f,Ce=Re?uE:jj;let _e,Ve=Ce(ce,C.radius,f.outline);if(Ve){const it=ce.angle(Pe),cn=ce.angle(Be),It=b(it,cn);Ve=Ve.filter(jt=>b(it,ce.angle(jt))<=It);const Jt=It*.25;Ve.sort(Re?(jt,Mt)=>Math.abs(b(it,ce.angle(jt))-Jt)<Math.abs(b(it,ce.angle(Mt))-Jt)?-1:1:(jt,Mt)=>b(it,ce.angle(jt))<b(it,ce.angle(Mt))?-1:1),_e=Ve[0]??(Re?void 0:Pe)}else _e=Re?void 0:Pe;if(_e&&(A.setTo(n.getPointInShapeSpace(e,ve.applyToPoint(f.transform,_e))),f.didIntersect=!0,s!=="none")){const it=Ro[e.props.size]/2+("size"in f.shape.props?Ro[f.shape.props.size]/2:0);U=(_S+it)*e.props.scale,z+=it*e.props.scale}}if(p&&!p.isExact){const re=ve.applyToPoint(K,A),H=ve.applyToPoint(K,R),ne=ve.applyToPoint(K,C.center),ge=ve.Inverse(p.transform),Pe=ve.applyToPoint(ge,re),ce=ve.applyToPoint(ge,ne),Be=ve.applyToPoint(ge,H),Re=p.isClosed,Ce=Re?uE:jj;let _e,Ve=Ce(ce,C.radius,p.outline);if(Ve){const it=ce.angle(Pe),cn=ce.angle(Be),It=b(it,cn),Jt=It*.75;Ve=Ve.filter(jt=>b(it,ce.angle(jt))<=It),Ve.sort(Re?(jt,Mt)=>Math.abs(b(it,ce.angle(jt))-Jt)<Math.abs(b(it,ce.angle(Mt))-Jt)?-1:1:(jt,Mt)=>b(it,ce.angle(jt))<b(it,ce.angle(Mt))?-1:1),Ve[0]?_e=Ve[0]:_e=Re?void 0:Be}else _e=Re?void 0:Be;if(_e&&(R.setTo(n.getPointInShapeSpace(e,ve.applyToPoint(p.transform,_e))),p.didIntersect=!0,r!=="none")){const it=Ro[e.props.size]/2+("size"in p.shape.props?Ro[p.shape.props.size]/2:0);J=(_S+it)*e.props.scale,z+=it*e.props.scale}}let N=E.Angle(C.center,A),L=E.Angle(C.center,R),V=b(N,L),X=V*C.radius;const W=A.clone(),$=R.clone();if(U!==0&&W.setTo(C.center).add(E.FromAngle(N+V*(U/X*(x?1:-1))).mul(C.radius)),J!==0&&$.setTo(C.center).add(E.FromAngle(L+V*(J/X*(x?-1:1))).mul(C.radius)),E.DistMin(W,$,z)&&(U!==0&&J!==0?(U*=-1.5,J*=-1.5):U!==0?U*=-2:J!==0&&(J*=-2)),U!==0&&A.setTo(C.center).add(E.FromAngle(N+V*(U/X*(x?1:-1))).mul(C.radius)),J!==0&&R.setTo(C.center).add(E.FromAngle(L+V*(J/X*(x?-1:1))).mul(C.radius)),f&&p&&!f.isExact&&!p.isExact){N=E.Angle(C.center,A),L=E.Angle(C.center,R),V=b(N,L),X=V*C.radius;const re=V_(n,f.shape.id,p.shape.id);re==="double-bound"&&X<30?(A.setTo(m),R.setTo(y),j.setTo(v)):re==="safe"&&(f&&!f.didIntersect&&A.setTo(m),(p&&!p.didIntersect||b(I,N)>b(I,L))&&R.setTo(C.center).add(E.FromAngle(N+V*(Math.min(.9,jf*e.props.scale/X)*(x?1:-1))).mul(C.radius)))}hpe(C.center,C.radius,A,R,j,T,x),A.equals(R)&&(A.setTo(j.clone().addXY(1,1)),R.setTo(j.clone().subXY(1,1))),m.setTo(A),y.setTo(R),v.setTo(j);const G=FN(m,y,v);return{bindings:t,isStraight:!1,start:{point:m,handle:o.start,arrowhead:e.props.arrowheadStart},end:{point:y,handle:o.end,arrowhead:e.props.arrowheadEnd},middle:v,handleArc:C,bodyArc:G,isValid:G.length!==0&&isFinite(G.center.x)&&isFinite(G.center.y)}}function FN(n,e,t){const r=Nk(n,e,t)??E.Med(n,e),s=E.Dist(r,n),i=+E.Clockwise(n,t,e),o=((n.y-e.y)**2+(n.x-e.x)**2)**.5,a=((e.y-t.y)**2+(e.x-t.x)**2)**.5,l=((t.y-n.y)**2+(t.x-n.x)**2)**.5,c=Math.acos((a*a+l*l-o*o)/(2*a*l))*2,d=+(xt>c),f=(Rt-c)*(i?1:-1),p=f*s;return{center:r,radius:s,size:f,length:p,largeArcFlag:d,sweepFlag:i}}function hpe(n,e,t,r,s,i,o){const a=E.Angle(n,t),l=E.Angle(n,r);let c=Ip(a,l);if(o||(c=Rt-c),s.setTo(n).add(E.FromAngle(a+c*(.5*(o?1:-1))).mul(e)),c>i){s.rotWith(n,xt);const d=r.clone();r.setTo(t),t.setTo(d)}}const fpe=8;function ppe(n){return Math.abs(n.props.bend)<fpe*n.props.scale}function IS(n,e,t){const r=n.getBindingsFromShape(e,"arrow").find(l=>l.props.terminal===t);if(!r)return;const s=n.getShape(r.toId);if(!s)return;const i=n.getShapePageTransform(s),o=n.getShapeGeometry(s,t==="start"?{context:"@tldraw/arrow-start"}:void 0),a=o instanceof bi?o.children[0].vertices:o.vertices;return{shape:s,transform:i,isClosed:o.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function zN(n,e,t,r){const s=n.getShape(t.toId);if(s){const{point:i,size:o}=n.getShapeGeometry(s).bounds,a=E.Add(i,E.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},o)),l=ve.applyToPoint(n.getShapePageTransform(s),a);return ve.applyToPoint(ve.Inverse(e),l)}else return new E(0,0)}function ys(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 gpe=xI("arrow info",(n,e)=>{const t=ys(n,e);return ppe(e)?DE(n,e,t):dpe(n,e,t)});function Oo(n,e){const t=typeof e=="string"?e:e.id;return gpe.get(n,t)}function bd(n,e,t){var a,l;const r=n.getShapePageTransform(e),s=V_(n,(a=t.start)==null?void 0:a.toId,(l=t.end)==null?void 0:l.toId),i=t.start?zN(n,r,t.start,s==="double-bound"||s==="start-contains-end"):E.From(e.props.start),o=t.end?zN(n,r,t.end,s==="double-bound"||s==="end-contains-start"):E.From(e.props.end);return{start:i,end:o}}function sf(n,e,t,r){const s=typeof e=="string"?e:e.id,i=typeof t=="string"?t:t.id,o=n.getBindingsFromShape(s,"arrow").filter(l=>l.props.terminal===r.terminal);o.length>1&&n.deleteBindings(o.slice(1));const a=o[0];a?n.updateBinding({...a,toId:i,props:r}):n.createBinding({type:"arrow",fromId:s,toId:i,props:r})}function uy(n,e,t){const r=n.getBindingsFromShape(e,"arrow").filter(s=>s.props.terminal===t);n.deleteBindings(r)}const jf=10,_S=10,mpe=10,Ro={s:2,m:3.5,l:5,xl:10};function V_(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 dy extends oy{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const t=this.editor.getShape(e.fromId);t&&DC(this.editor,t)}onAfterChange({bindingAfter:e}){const t=this.editor.getShape(e.fromId);t&&DC(this.editor,t)}onAfterChangeFromShape({shapeAfter:e}){DC(this.editor,e)}onAfterChangeToShape({binding:e}){b9(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const t=this.editor.getShape(e.fromId);t&&TS({editor:this.editor,arrow:t,terminal:e.props.terminal})}}O(dy,"type","arrow"),O(dy,"props",u4),O(dy,"migrations",d4);function b9(n,e){var x;const t=n.getShape(e);if(!t)return;const r=ys(n,t),{start:s,end:i}=r,o=s?n.getShape(s.toId):void 0,a=i?n.getShape(i.toId):void 0,l=n.getAncestorPageId(t);if(!l)return;let c;if(o&&a)c=n.findCommonAncestor([o,a])??l;else if(o||a){const b=(x=o||a)==null?void 0:x.parentId;b&&b===t.parentId?c=t.parentId:c=l}else return;c&&c!==t.parentId&&n.reparentShapes([e],c);const d=n.getShape(e);if(!d)throw Error("no reparented arrow");const f=n.getShapeNearestSibling(d,o),p=n.getShapeNearestSibling(d,a);let m;if(f&&p)m=f.index>p.index?f:p;else if(f&&!p)m=f;else if(p&&!f)m=p;else return;let y;const v=n.getSortedChildIdsForParent(m.parentId).map(b=>n.getShape(b)).filter(b=>b.index>m.index);if(v.length){const b=v.find(C=>C.type!=="arrow");if(d.index>m.index&&(!b||d.index<b.index))return;y=Gf(m.index,v[0].index)}else y=To(m.index);y!==d.index&&n.updateShapes([{id:e,type:"arrow",index:y}])}function DC(n,e){const t=ys(n,e);for(const r of["start","end"]){const s=t[r];if(!s)continue;const i=n.getShape(s.toId),o=n.getAncestorPageId(e)===n.getAncestorPageId(i);(!i||!o)&&TS({editor:n,arrow:e,terminal:r,unbind:!0})}b9(n,e.id)}function TS({editor:n,arrow:e,terminal:t,unbind:r=!1,useHandle:s=!1}){const i=Oo(n,e);if(!i)throw new Error("expected arrow info");const o=s?i.start.handle:i.start.point,a=s?i.end.handle:i.end.point,l=t==="start"?o:a,c={id:e.id,type:"arrow",props:{[t]:{x:l.x,y:l.y},bend:e.props.bend}};if(!i.isStraight){const d=t==="start"?o:i.start.handle,f=t==="end"?a:i.end.handle,p=E.Med(d,f),m=E.Sub(d,f).per().uni().mul(i.handleArc.radius*2*Math.sign(e.props.bend)),y=Lp(i.handleArc.center,E.Add(p,m),i.handleArc.center,i.handleArc.radius);nt((y==null?void 0:y.length)===1);const v=E.Dist(p,y[0])*Math.sign(e.props.bend);Al(v,c.props.bend)||(c.props.bend=v)}n.updateShape(c),r&&uy(n,e,t)}const C9=[dy],ir={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},Er={s:2,m:3.5,l:5,xl:10},Vd={s:18,m:24,l:36,xl:44},Ta={s:18,m:22,l:26,xl:32},ype={s:18,m:20,l:24,xl:28},Da={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},Spe=20,q_=4.25,Fr=16;function vpe(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}}async function xpe(n,e,t){var b,C,I;const{elements:r,files:s}=e,i={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:n.store.schema.serialize()},o=new Map,a=new Map,l=n.getCurrentPageId(),c=new Map,d=[],f=new Set;r.forEach(_=>{if(c.set(_.id,Dt()),_.boundElements!==null)for(const T of _.boundElements)T.type==="text"&&f.add(T.id)});let p=d3;for(const _ of r){if(f.has(_.id))continue;const T=c.get(_.id),A={id:T,typeName:"shape",parentId:l,index:p,x:_.x,y:_.y,rotation:0,isLocked:_.locked,opacity:wpe(_.opacity),meta:{}};switch(_.angle!==0&&a.set(T,_.angle),_.groupIds&&_.groupIds.length>0?o.has(_.groupIds[0])?(b=o.get(_.groupIds[0]))==null||b.push(T):o.set(_.groupIds[0],[T]):d.push(T),_.type){case"rectangle":case"ellipse":case"diamond":{let R="",j="middle";if(_.boundElements!==null){for(const U of _.boundElements)if(U.type==="text"){const J=r.find(z=>z.id===U.id);J&&(R=J.text,j=_pe[J.textAlign])}}const K=_.backgroundColor==="transparent"?_.strokeColor:_.backgroundColor;i.shapes.push({...A,type:"geo",props:{geo:_.type,url:_.link??"",w:_.width,h:_.height,size:Lm[_.strokeWidth]??"draw",color:of[K]??"black",richText:wi(R),align:j,dash:Fm(_),fill:Ape(_)}});break}case"freedraw":{i.shapes.push({...A,type:"draw",props:{dash:Fm(_),size:Lm[_.strokeWidth],color:of[_.strokeColor]??"black",segments:[{type:"free",points:_.points.map(([R,j,K=.5])=>({x:R,y:j,z:K}))}]}});break}case"line":{if(_.points.slice().length<2)break;const j=Yf(_.points.length);i.shapes.push({...A,type:"line",props:{dash:Fm(_),size:Lm[_.strokeWidth],color:of[_.strokeColor]??"black",spline:_.roundness?"cubic":"line",points:{...Object.fromEntries(_.points.map(([K,U],J)=>{const z=j[J];return[z,{id:z,index:z,x:K,y:U}]}))}}});break}case"arrow":{let R="";if(_.boundElements!==null){for(const z of _.boundElements)if(z.type==="text"){const N=r.find(L=>L.id===z.id);N&&(R=N.text)}}const j=_.points[0],K=_.points[_.points.length-1],U=c.get((C=_.startBinding)==null?void 0:C.elementId),J=c.get((I=_.endBinding)==null?void 0:I.elementId);i.shapes.push({...A,type:"arrow",props:{text:R,bend:Mpe(_,j,K),dash:Fm(_),size:Lm[_.strokeWidth]??"m",color:of[_.strokeColor]??"black",start:{x:j[0],y:j[1]},end:{x:K[0],y:K[1]},arrowheadEnd:$N[_.endArrowhead]??"none",arrowheadStart:$N[_.startArrowhead]??"none"}}),U&&i.bindings.push({id:Hc(),typeName:"binding",type:"arrow",fromId:T,toId:U,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),J&&i.bindings.push({id:Hc(),typeName:"binding",type:"arrow",fromId:T,toId:J,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:R,scale:j}=Cpe(_.fontSize);i.shapes.push({...A,type:"text",props:{size:R,scale:j,font:Ppe[_.fontFamily]??"draw",color:of[_.strokeColor]??"black",richText:wi(_.text),textAlign:Tpe[_.textAlign]}});break}case"image":{const R=s[_.fileId];if(!R)break;const j=zl.createId();i.assets.push({id:j,typeName:"asset",type:"image",props:{w:_.width,h:_.height,fileSize:R.size,name:_.id??"Untitled",isAnimated:!1,mimeType:R.mimeType,src:R.dataURL},meta:{}}),i.shapes.push({...A,type:"image",props:{w:_.width,h:_.height,assetId:j}})}}p=To(p)}const m=t??(n.inputs.shiftKey?n.inputs.currentPagePoint:void 0);n.putContentOntoCurrentPage(i,{point:m,select:!1,preserveIds:!0});for(const _ of o.values())if(_.length>1){n.groupShapes(_);const T=n.getShape(_[0]);T!=null&&T.parentId&&ps(T.parentId)&&d.push(T.parentId)}for(const[_,T]of a)n.select(_),n.rotateShapesBy([_],T);const y=st(d.map(_=>n.getShape(_))),v=ye.Common(y.map(_=>n.getShapePageBounds(_))),x=n.getViewportPageBounds().center;n.updateShapes(y.map(_=>{const T={x:(_.x??0)-(v.x+v.w/2),y:(_.y??0)-(v.y+v.h/2)};return{id:_.id,type:_.type,x:x.x+T.x,y:x.y+T.y}})),n.setSelectedShapes(d)}const wpe=n=>{const e=n/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Lm={1:"s",2:"m",3:"l",4:"xl"},bpe={16:"s",20:"m",28:"l",36:"xl"};function Cpe(n){const e=bpe[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 Ppe={1:"draw",2:"sans",3:"mono"},Epe={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 wo(n,e,t){const r=[0,1,2,3,4].map(s=>Epe[n][s]);return Object.fromEntries(r.map((s,i)=>[s,i<3?e:t]))}const of={...wo("gray","grey","black"),...wo("red","light-red","red"),...wo("pink","light-red","red"),...wo("grape","light-violet","violet"),...wo("blue","light-blue","blue"),...wo("cyan","light-blue","blue"),...wo("teal","light-green","green"),...wo("green","light-green","green"),...wo("yellow","yellow","orange"),...wo("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},kpe={solid:"draw",dashed:"dashed",dotted:"dotted"},Ipe={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},_pe={left:"start",center:"middle",right:"end"},Tpe={left:"start",center:"middle",right:"end"},$N={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Mpe(n,e,t){let r=0;if(n.points.length>2){const s=new E(e[0],e[1]),i=new E(t[0],t[1]),o=new E(n.points[1][0],n.points[1][1]),a=E.Sub(i,s),l=E.Per(a),c=E.Med(i,s),d=E.Sub(c,l),f=E.Add(c,l),p=E.NearestPointOnLineSegment(d,f,o,!1);r=E.Dist(p,c),E.Clockwise(p,i,c)&&(r*=-1)}return r}const Fm=n=>{let e=kpe[n.strokeStyle]??"draw";return e==="draw"&&n.roughness===0&&(e="solid"),e},Ape=n=>n.backgroundColor==="transparent"?"none":Ipe[n.fillStyle]??"solid",Ope=/(^|[^`])`([^`]+)`(?!`)/,Rpe=/(^|[^`])`([^`]+)`(?!`)/g,P9=Lo.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setCode:()=>({commands:n})=>n.setMark(this.name),toggleCode:()=>({commands:n})=>n.toggleMark(this.name),unsetCode:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[Yc({find:Ope,type:this.type})]},addPasteRules(){return[Ll({find:Rpe,type:this.type})]}}),Dpe=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,jpe=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,E9=Lo.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:n=>n.getAttribute("data-color")||n.style.backgroundColor,renderHTML:n=>n.color?{"data-color":n.color,style:`background-color: ${n.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:n}){return["mark",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setHighlight:n=>({commands:e})=>e.setMark(this.name,n),toggleHighlight:n=>({commands:e})=>e.toggleMark(this.name,n),unsetHighlight:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Yc({find:Dpe,type:this.type})]},addPasteRules(){return[Ll({find:jpe,type:this.type})]}}),Npe="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2ntley5rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6logistics9properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3ncaster6d0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2psy3ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",Lpe="ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2",qd=(n,e)=>{for(const t in e)n[t]=e[t];return n},jE="numeric",NE="ascii",LE="alpha",Nf="asciinumeric",bf="alphanumeric",FE="domain",k9="emoji",Fpe="scheme",zpe="slashscheme",jC="whitespace";function $pe(n,e){return n in e||(e[n]=[]),e[n]}function jc(n,e,t){e[jE]&&(e[Nf]=!0,e[bf]=!0),e[NE]&&(e[Nf]=!0,e[LE]=!0),e[Nf]&&(e[bf]=!0),e[LE]&&(e[bf]=!0),e[bf]&&(e[FE]=!0),e[k9]&&(e[FE]=!0);for(const r in e){const s=$pe(r,t);s.indexOf(n)<0&&s.push(n)}}function Bpe(n,e){const t={};for(const r in e)e[r].indexOf(n)>=0&&(t[r]=!0);return t}function ms(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}ms.groups={};ms.prototype={accepts(){return!!this.t},go(n){const e=this,t=e.j[n];if(t)return t;for(let r=0;r<e.jr.length;r++){const s=e.jr[r][0],i=e.jr[r][1];if(i&&s.test(n))return i}return e.jd},has(n,e=!1){return e?n in this.j:!!this.go(n)},ta(n,e,t,r){for(let s=0;s<n.length;s++)this.tt(n[s],e,t,r)},tr(n,e,t,r){r=r||ms.groups;let s;return e&&e.j?s=e:(s=new ms(e),t&&r&&jc(e,t,r)),this.jr.push([n,s]),s},ts(n,e,t,r){let s=this;const i=n.length;if(!i)return s;for(let o=0;o<i-1;o++)s=s.tt(n[o]);return s.tt(n[i-1],e,t,r)},tt(n,e,t,r){r=r||ms.groups;const s=this;if(e&&e.j)return s.j[n]=e,e;const i=e;let o,a=s.go(n);if(a?(o=new ms,qd(o.j,a.j),o.jr.push.apply(o.jr,a.jr),o.jd=a.jd,o.t=a.t):o=new ms,i){if(r)if(o.t&&typeof o.t=="string"){const l=qd(Bpe(o.t,r),t);jc(i,l,r)}else t&&jc(i,t,r);o.t=i}return s.j[n]=o,o}};const ut=(n,e,t,r,s)=>n.ta(e,t,r,s),hn=(n,e,t,r,s)=>n.tr(e,t,r,s),BN=(n,e,t,r,s)=>n.ts(e,t,r,s),Se=(n,e,t,r,s)=>n.tt(e,t,r,s),ga="WORD",zE="UWORD",I9="ASCIINUMERICAL",_9="ALPHANUMERICAL",mp="LOCALHOST",$E="TLD",BE="UTLD",hy="SCHEME",pd="SLASH_SCHEME",G_="NUM",UE="WS",Y_="NL",Lf="OPENBRACE",Ff="CLOSEBRACE",MS="OPENBRACKET",AS="CLOSEBRACKET",OS="OPENPAREN",RS="CLOSEPAREN",DS="OPENANGLEBRACKET",jS="CLOSEANGLEBRACKET",NS="FULLWIDTHLEFTPAREN",LS="FULLWIDTHRIGHTPAREN",FS="LEFTCORNERBRACKET",zS="RIGHTCORNERBRACKET",$S="LEFTWHITECORNERBRACKET",BS="RIGHTWHITECORNERBRACKET",US="FULLWIDTHLESSTHAN",HS="FULLWIDTHGREATERTHAN",KS="AMPERSAND",X_="APOSTROPHE",WS="ASTERISK",xl="AT",VS="BACKSLASH",qS="BACKTICK",GS="CARET",El="COLON",Z_="COMMA",YS="DOLLAR",Po="DOT",XS="EQUALS",J_="EXCLAMATION",ci="HYPHEN",zf="PERCENT",ZS="PIPE",JS="PLUS",QS="POUND",$f="QUERY",Q_="QUOTE",T9="FULLWIDTHMIDDLEDOT",eT="SEMI",Eo="SLASH",Bf="TILDE",ev="UNDERSCORE",M9="EMOJI",tv="SYM";var A9=Object.freeze({__proto__:null,WORD:ga,UWORD:zE,ASCIINUMERICAL:I9,ALPHANUMERICAL:_9,LOCALHOST:mp,TLD:$E,UTLD:BE,SCHEME:hy,SLASH_SCHEME:pd,NUM:G_,WS:UE,NL:Y_,OPENBRACE:Lf,CLOSEBRACE:Ff,OPENBRACKET:MS,CLOSEBRACKET:AS,OPENPAREN:OS,CLOSEPAREN:RS,OPENANGLEBRACKET:DS,CLOSEANGLEBRACKET:jS,FULLWIDTHLEFTPAREN:NS,FULLWIDTHRIGHTPAREN:LS,LEFTCORNERBRACKET:FS,RIGHTCORNERBRACKET:zS,LEFTWHITECORNERBRACKET:$S,RIGHTWHITECORNERBRACKET:BS,FULLWIDTHLESSTHAN:US,FULLWIDTHGREATERTHAN:HS,AMPERSAND:KS,APOSTROPHE:X_,ASTERISK:WS,AT:xl,BACKSLASH:VS,BACKTICK:qS,CARET:GS,COLON:El,COMMA:Z_,DOLLAR:YS,DOT:Po,EQUALS:XS,EXCLAMATION:J_,HYPHEN:ci,PERCENT:zf,PIPE:ZS,PLUS:JS,POUND:QS,QUERY:$f,QUOTE:Q_,FULLWIDTHMIDDLEDOT:T9,SEMI:eT,SLASH:Eo,TILDE:Bf,UNDERSCORE:ev,EMOJI:M9,SYM:tv});const ua=/[a-z]/,af=new RegExp("\\p{L}","u"),NC=new RegExp("\\p{Emoji}","u"),da=/\d/,LC=/\s/,UN="\r",FC=`
434
+ `,Upe="️",Hpe="‍",zC="";let zm=null,$m=null;function Kpe(n=[]){const e={};ms.groups=e;const t=new ms;zm==null&&(zm=HN(Npe)),$m==null&&($m=HN(Lpe)),Se(t,"'",X_),Se(t,"{",Lf),Se(t,"}",Ff),Se(t,"[",MS),Se(t,"]",AS),Se(t,"(",OS),Se(t,")",RS),Se(t,"<",DS),Se(t,">",jS),Se(t,"(",NS),Se(t,")",LS),Se(t,"「",FS),Se(t,"」",zS),Se(t,"『",$S),Se(t,"』",BS),Se(t,"<",US),Se(t,">",HS),Se(t,"&",KS),Se(t,"*",WS),Se(t,"@",xl),Se(t,"`",qS),Se(t,"^",GS),Se(t,":",El),Se(t,",",Z_),Se(t,"$",YS),Se(t,".",Po),Se(t,"=",XS),Se(t,"!",J_),Se(t,"-",ci),Se(t,"%",zf),Se(t,"|",ZS),Se(t,"+",JS),Se(t,"#",QS),Se(t,"?",$f),Se(t,'"',Q_),Se(t,"/",Eo),Se(t,";",eT),Se(t,"~",Bf),Se(t,"_",ev),Se(t,"\\",VS),Se(t,"・",T9);const r=hn(t,da,G_,{[jE]:!0});hn(r,da,r);const s=hn(r,ua,I9,{[Nf]:!0}),i=hn(r,af,_9,{[bf]:!0}),o=hn(t,ua,ga,{[NE]:!0});hn(o,da,s),hn(o,ua,o),hn(s,da,s),hn(s,ua,s);const a=hn(t,af,zE,{[LE]:!0});hn(a,ua),hn(a,da,i),hn(a,af,a),hn(i,da,i),hn(i,ua),hn(i,af,i);const l=Se(t,FC,Y_,{[jC]:!0}),c=Se(t,UN,UE,{[jC]:!0}),d=hn(t,LC,UE,{[jC]:!0});Se(t,zC,d),Se(c,FC,l),Se(c,zC,d),hn(c,LC,d),Se(d,UN),Se(d,FC),hn(d,LC,d),Se(d,zC,d);const f=hn(t,NC,M9,{[k9]:!0});Se(f,"#"),hn(f,NC,f),Se(f,Upe,f);const p=Se(f,Hpe);Se(p,"#"),hn(p,NC,f);const m=[[ua,o],[da,s]],y=[[ua,null],[af,a],[da,i]];for(let v=0;v<zm.length;v++)fl(t,zm[v],$E,ga,m);for(let v=0;v<$m.length;v++)fl(t,$m[v],BE,zE,y);jc($E,{tld:!0,ascii:!0},e),jc(BE,{utld:!0,alpha:!0},e),fl(t,"file",hy,ga,m),fl(t,"mailto",hy,ga,m),fl(t,"http",pd,ga,m),fl(t,"https",pd,ga,m),fl(t,"ftp",pd,ga,m),fl(t,"ftps",pd,ga,m),jc(hy,{scheme:!0,ascii:!0},e),jc(pd,{slashscheme:!0,ascii:!0},e),n=n.sort((v,x)=>v[0]>x[0]?1:-1);for(let v=0;v<n.length;v++){const x=n[v][0],C=n[v][1]?{[Fpe]:!0}:{[zpe]:!0};x.indexOf("-")>=0?C[FE]=!0:ua.test(x)?da.test(x)?C[Nf]=!0:C[NE]=!0:C[jE]=!0,BN(t,x,x,C)}return BN(t,"localhost",mp,{ascii:!0}),t.jd=new ms(tv),{start:t,tokens:qd({groups:e},A9)}}function O9(n,e){const t=Wpe(e.replace(/[A-Z]/g,a=>a.toLowerCase())),r=t.length,s=[];let i=0,o=0;for(;o<r;){let a=n,l=null,c=0,d=null,f=-1,p=-1;for(;o<r&&(l=a.go(t[o]));)a=l,a.accepts()?(f=0,p=0,d=a):f>=0&&(f+=t[o].length,p++),c+=t[o].length,i+=t[o].length,o++;i-=f,o-=p,c-=f,s.push({t:d.t,v:e.slice(i-c,i),s:i-c,e:i})}return s}function Wpe(n){const e=[],t=n.length;let r=0;for(;r<t;){let s=n.charCodeAt(r),i,o=s<55296||s>56319||r+1===t||(i=n.charCodeAt(r+1))<56320||i>57343?n[r]:n.slice(r,r+2);e.push(o),r+=o.length}return e}function fl(n,e,t,r,s){let i;const o=e.length;for(let a=0;a<o-1;a++){const l=e[a];n.j[l]?i=n.j[l]:(i=new ms(r),i.jr=s.slice(),n.j[l]=i),n=i}return i=new ms(t),i.jr=s.slice(),n.j[e[o-1]]=i,i}function HN(n){const e=[],t=[];let r=0,s="0123456789";for(;r<n.length;){let i=0;for(;s.indexOf(n[r+i])>=0;)i++;if(i>0){e.push(t.join(""));for(let o=parseInt(n.substring(r,r+i),10);o>0;o--)t.pop();r+=i}else t.push(n[r]),r++}return e}const yp={defaultProtocol:"http",events:null,format:KN,formatHref:KN,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function tT(n,e=null){let t=qd({},yp);n&&(t=qd(t,n instanceof tT?n.o:n));const r=t.ignoreTags,s=[];for(let i=0;i<r.length;i++)s.push(r[i].toUpperCase());this.o=t,e&&(this.defaultRender=e),this.ignoreTags=s}tT.prototype={o:yp,ignoreTags:[],defaultRender(n){return n},check(n){return this.get("validate",n.toString(),n)},get(n,e,t){const r=e!=null;let s=this.o[n];return s&&(typeof s=="object"?(s=t.t in s?s[t.t]:yp[n],typeof s=="function"&&r&&(s=s(e,t))):typeof s=="function"&&r&&(s=s(e,t.t,t)),s)},getObj(n,e,t){let r=this.o[n];return typeof r=="function"&&e!=null&&(r=r(e,t.t,t)),r},render(n){const e=n.render(this);return(this.get("render",null,n)||this.defaultRender)(e,n.t,n)}};function KN(n){return n}function R9(n,e){this.t="token",this.v=n,this.tk=e}R9.prototype={isLink:!1,toString(){return this.v},toHref(n){return this.toString()},toFormattedString(n){const e=this.toString(),t=n.get("truncate",e,this),r=n.get("format",e,this);return t&&r.length>t?r.substring(0,t)+"…":r},toFormattedHref(n){return n.get("formatHref",this.toHref(n.get("defaultProtocol")),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(n=yp.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(n),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(n){return{type:this.t,value:this.toFormattedString(n),isLink:this.isLink,href:this.toFormattedHref(n),start:this.startIndex(),end:this.endIndex()}},validate(n){return n.get("validate",this.toString(),this)},render(n){const e=this,t=this.toHref(n.get("defaultProtocol")),r=n.get("formatHref",t,this),s=n.get("tagName",t,e),i=this.toFormattedString(n),o={},a=n.get("className",t,e),l=n.get("target",t,e),c=n.get("rel",t,e),d=n.getObj("attributes",t,e),f=n.getObj("events",t,e);return o.href=r,a&&(o.class=a),l&&(o.target=l),c&&(o.rel=c),d&&qd(o,d),{tagName:s,attributes:o,content:i,eventListeners:f}}};function I0(n,e){class t extends R9{constructor(s,i){super(s,i),this.t=n}}for(const r in e)t.prototype[r]=e[r];return t.t=n,t}const WN=I0("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),VN=I0("text"),Vpe=I0("nl"),Bm=I0("url",{isLink:!0,toHref(n=yp.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==mp&&n[1].t===El}}),li=n=>new ms(n);function qpe({groups:n}){const e=n.domain.concat([KS,WS,xl,VS,qS,GS,YS,XS,ci,G_,zf,ZS,JS,QS,Eo,tv,Bf,ev]),t=[El,Z_,Po,J_,zf,$f,Q_,eT,DS,jS,Lf,Ff,AS,MS,OS,RS,NS,LS,FS,zS,$S,BS,US,HS],r=[KS,X_,WS,VS,qS,GS,YS,XS,ci,Lf,Ff,zf,ZS,JS,QS,$f,Eo,tv,Bf,ev],s=li(),i=Se(s,Bf);ut(i,r,i),ut(i,n.domain,i);const o=li(),a=li(),l=li();ut(s,n.domain,o),ut(s,n.scheme,a),ut(s,n.slashscheme,l),ut(o,r,i),ut(o,n.domain,o);const c=Se(o,xl);Se(i,xl,c),Se(a,xl,c),Se(l,xl,c);const d=Se(i,Po);ut(d,r,i),ut(d,n.domain,i);const f=li();ut(c,n.domain,f),ut(f,n.domain,f);const p=Se(f,Po);ut(p,n.domain,f);const m=li(WN);ut(p,n.tld,m),ut(p,n.utld,m),Se(c,mp,m);const y=Se(f,ci);Se(y,ci,y),ut(y,n.domain,f),ut(m,n.domain,f),Se(m,Po,p),Se(m,ci,y);const v=Se(m,El);ut(v,n.numeric,WN);const x=Se(o,ci),b=Se(o,Po);Se(x,ci,x),ut(x,n.domain,o),ut(b,r,i),ut(b,n.domain,o);const C=li(Bm);ut(b,n.tld,C),ut(b,n.utld,C),ut(C,n.domain,o),ut(C,r,i),Se(C,Po,b),Se(C,ci,x),Se(C,xl,c);const I=Se(C,El),_=li(Bm);ut(I,n.numeric,_);const T=li(Bm),A=li();ut(T,e,T),ut(T,t,A),ut(A,e,T),ut(A,t,A),Se(C,Eo,T),Se(_,Eo,T);const R=Se(a,El),j=Se(l,El),K=Se(j,Eo),U=Se(K,Eo);ut(a,n.domain,o),Se(a,Po,b),Se(a,ci,x),ut(l,n.domain,o),Se(l,Po,b),Se(l,ci,x),ut(R,n.domain,T),Se(R,Eo,T),Se(R,$f,T),ut(U,n.domain,T),ut(U,e,T),Se(U,Eo,T);const J=[[Lf,Ff],[MS,AS],[OS,RS],[DS,jS],[NS,LS],[FS,zS],[$S,BS],[US,HS]];for(let z=0;z<J.length;z++){const[N,L]=J[z],V=Se(T,N);Se(A,N,V),Se(V,L,T);const X=li(Bm);ut(V,e,X);const W=li();ut(V,t),ut(X,e,X),ut(X,t,W),ut(W,e,X),ut(W,t,W),Se(X,L,T),Se(W,L,T)}return Se(s,mp,C),Se(s,Y_,Vpe),{start:s,tokens:A9}}function Gpe(n,e,t){let r=t.length,s=0,i=[],o=[];for(;s<r;){let a=n,l=null,c=null,d=0,f=null,p=-1;for(;s<r&&!(l=a.go(t[s].t));)o.push(t[s++]);for(;s<r&&(c=l||a.go(t[s].t));)l=null,a=c,a.accepts()?(p=0,f=a):p>=0&&p++,s++,d++;if(p<0)s-=d,s<r&&(o.push(t[s]),s++);else{o.length>0&&(i.push($C(VN,e,o)),o=[]),s-=p,d-=p;const m=f.t,y=t.slice(s-d,s);i.push($C(m,e,y))}}return o.length>0&&i.push($C(VN,e,o)),i}function $C(n,e,t){const r=t[0].s,s=t[t.length-1].e,i=e.slice(r,s);return new n(i,t)}const Ype=typeof console<"u"&&console&&console.warn||(()=>{}),Xpe="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",Gt={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function Zpe(){return ms.groups={},Gt.scanner=null,Gt.parser=null,Gt.tokenQueue=[],Gt.pluginQueue=[],Gt.customSchemes=[],Gt.initialized=!1,Gt}function qN(n,e=!1){if(Gt.initialized&&Ype(`linkifyjs: already initialized - will not register custom scheme "${n}" ${Xpe}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(n))throw new Error(`linkifyjs: incorrect scheme format.
435
+ 1. Must only contain digits, lowercase ASCII letters or "-"
436
+ 2. Cannot start or end with "-"
437
+ 3. "-" cannot repeat`);Gt.customSchemes.push([n,e])}function Jpe(){Gt.scanner=Kpe(Gt.customSchemes);for(let n=0;n<Gt.tokenQueue.length;n++)Gt.tokenQueue[n][1]({scanner:Gt.scanner});Gt.parser=qpe(Gt.scanner.tokens);for(let n=0;n<Gt.pluginQueue.length;n++)Gt.pluginQueue[n][1]({scanner:Gt.scanner,parser:Gt.parser});return Gt.initialized=!0,Gt}function nT(n){return Gt.initialized||Jpe(),Gpe(Gt.parser.start,n,O9(Gt.scanner.start,n))}nT.scan=O9;function D9(n,e=null,t=null){if(e&&typeof e=="object"){if(t)throw Error(`linkifyjs: Invalid link type ${e}; must be a string`);t=e,e=null}const r=new tT(t),s=nT(n),i=[];for(let o=0;o<s.length;o++){const a=s[o];a.isLink&&(!e||a.t===e)&&r.check(a)&&i.push(a.toFormattedObject(r))}return i}function Qpe(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function ege(n){return new lr({key:new qs("autolink"),appendTransaction:(e,t,r)=>{const s=e.some(c=>c.docChanged)&&!t.doc.eq(r.doc),i=e.some(c=>c.getMeta("preventAutolink"));if(!s||i)return;const{tr:o}=r,a=VJ(t.doc,[...e]);if(nQ(a).forEach(({newRange:c})=>{const d=GJ(r.doc,c,m=>m.isTextblock);let f,p;if(d.length>1?(f=d[0],p=r.doc.textBetween(f.pos,f.pos+f.node.nodeSize,void 0," ")):d.length&&r.doc.textBetween(c.from,c.to," "," ").endsWith(" ")&&(f=d[0],p=r.doc.textBetween(f.pos,c.to,void 0," ")),f&&p){const m=p.split(" ").filter(b=>b!=="");if(m.length<=0)return!1;const y=m[m.length-1],v=f.pos+p.lastIndexOf(y);if(!y)return!1;const x=nT(y).map(b=>b.toObject(n.defaultProtocol));if(!Qpe(x))return!1;x.filter(b=>b.isLink).map(b=>({...b,from:v+b.start+1,to:v+b.end+1})).filter(b=>r.schema.marks.code?!r.doc.rangeHasMark(b.from,b.to,r.schema.marks.code):!0).filter(b=>n.validate(b.value)).filter(b=>n.shouldAutoLink(b.value)).forEach(b=>{iI(b.from,b.to,r.doc).some(C=>C.mark.type===n.type)||o.addMark(b.from,b.to,n.type.create({href:b.href}))})}}),!!o.steps.length)return o}})}function tge(n){return new lr({key:new qs("handleClickLink"),props:{handleClick:(e,t,r)=>{var s,i;if(r.button!==0||!e.editable)return!1;let o=r.target;const a=[];for(;o.nodeName!=="DIV";)a.push(o),o=o.parentNode;if(!a.find(p=>p.nodeName==="A"))return!1;const l=$5(e.state,n.type.name),c=r.target,d=(s=c==null?void 0:c.href)!==null&&s!==void 0?s:l.href,f=(i=c==null?void 0:c.target)!==null&&i!==void 0?i:l.target;return c&&d?(window.open(d,f),!0):!1}}})}function nge(n){return new lr({key:new qs("handlePasteLink"),props:{handlePaste:(e,t,r)=>{const{state:s}=e,{selection:i}=s,{empty:o}=i;if(o)return!1;let a="";r.content.forEach(c=>{a+=c.textContent});const l=D9(a,{defaultProtocol:n.defaultProtocol}).find(c=>c.isLink&&c.value===a);return!a||!l?!1:n.editor.commands.setMark(n.type,{href:l.href})}}})}const rge=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;function kc(n,e){const t=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(r=>{const s=typeof r=="string"?r:r.scheme;s&&t.push(s)}),!n||n.replace(rge,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}const sge=Lo.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(n=>{if(typeof n=="string"){qN(n);return}qN(n.scheme,n.optionalSlashes)})},onDestroy(){Zpe()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(n,e)=>!!kc(n,e.protocols),validate:n=>!!n,shouldAutoLink:n=>!!n}},addAttributes(){return{href:{default:null,parseHTML(n){return n.getAttribute("href")}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class}}},parseHTML(){return[{tag:"a[href]",getAttrs:n=>{const e=n.getAttribute("href");return!e||!this.options.isAllowedUri(e,{defaultValidate:t=>!!kc(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:n}){return this.options.isAllowedUri(n.href,{defaultValidate:e=>!!kc(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",Kn(this.options.HTMLAttributes,n),0]:["a",Kn(this.options.HTMLAttributes,{...n,href:""}),0]},addCommands(){return{setLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:r=>!!kc(r,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().setMark(this.name,n).setMeta("preventAutolink",!0).run():!1},toggleLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:r=>!!kc(r,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().toggleMark(this.name,n,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run():!1},unsetLink:()=>({chain:n})=>n().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[Ll({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:r}=this.options,s=D9(n).filter(i=>i.isLink&&this.options.isAllowedUri(i.value,{defaultValidate:o=>!!kc(o,t),protocols:t,defaultProtocol:r}));s.length&&s.forEach(i=>e.push({text:i.value,data:{href:i.href},index:i.start}))}return e},type:this.type,getAttributes:n=>{var e;return{href:(e=n.data)===null||e===void 0?void 0:e.href}}})]},addProseMirrorPlugins(){const n=[],{protocols:e,defaultProtocol:t}=this.options;return this.options.autolink&&n.push(ege({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:r=>this.options.isAllowedUri(r,{defaultValidate:s=>!!kc(s,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),this.options.openOnClick===!0&&n.push(tge({type:this.type})),this.options.linkOnPaste&&n.push(nge({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type})),n}}),ige=/^\s*>\s$/,oge=no.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return["blockquote",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setBlockquote:()=>({commands:n})=>n.wrapIn(this.name),toggleBlockquote:()=>({commands:n})=>n.toggleWrap(this.name),unsetBlockquote:()=>({commands:n})=>n.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[sp({find:ige,type:this.type})]}}),age=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,lge=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,cge=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,uge=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,dge=Lo.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name===this.name},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return["strong",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Yc({find:age,type:this.type}),Yc({find:cge,type:this.type})]},addPasteRules(){return[Ll({find:lge,type:this.type}),Ll({find:uge,type:this.type})]}}),hge="listItem",GN="textStyle",YN=/^\s*([-+*])\s$/,fge=no.create({name:"bulletList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:"ul"}]},renderHTML({HTMLAttributes:n}){return["ul",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleBulletList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(hge,this.editor.getAttributes(GN)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=sp({find:YN,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=sp({find:YN,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(GN),editor:this.editor})),[n]}}),pge=/^```([a-z]+)?[\s\n]$/,gge=/^~~~([a-z]+)?[\s\n]$/,mge=no.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:n=>{var e;const{languageClassPrefix:t}=this.options,i=[...((e=n.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(o=>o.startsWith(t)).map(o=>o.replace(t,""))[0];return i||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:n,HTMLAttributes:e}){return["pre",Kn(this.options.HTMLAttributes,e),["code",{class:n.attrs.language?this.options.languageClassPrefix+n.attrs.language:null},0]]},addCommands(){return{setCodeBlock:n=>({commands:e})=>e.setNode(this.name,n),toggleCodeBlock:n=>({commands:e})=>e.toggleNode(this.name,"paragraph",n)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:n,$anchor:e}=this.editor.state.selection,t=e.pos===1;return!n||e.parent.type.name!==this.name?!1:t||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:n})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=n,{selection:t}=e,{$from:r,empty:s}=t;if(!s||r.parent.type!==this.type)return!1;const i=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(`
438
+
439
+ `);return!i||!o?!1:n.chain().command(({tr:a})=>(a.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:n})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=n,{selection:t,doc:r}=e,{$from:s,empty:i}=t;if(!i||s.parent.type!==this.type||!(s.parentOffset===s.parent.nodeSize-2))return!1;const a=s.after();return a===void 0?!1:r.nodeAt(a)?n.commands.command(({tr:c})=>(c.setSelection(at.near(r.resolve(a))),!0)):n.commands.exitCode()}}},addInputRules(){return[YP({find:pge,type:this.type,getAttributes:n=>({language:n[1]})}),YP({find:gge,type:this.type,getAttributes:n=>({language:n[1]})})]},addProseMirrorPlugins(){return[new lr({key:new qs("codeBlockVSCodeHandler"),props:{handlePaste:(n,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const t=e.clipboardData.getData("text/plain"),r=e.clipboardData.getData("vscode-editor-data"),s=r?JSON.parse(r):void 0,i=s==null?void 0:s.mode;if(!t||!i)return!1;const{tr:o,schema:a}=n.state,l=a.text(t.replace(/\r\n?/g,`
440
+ `));return o.replaceSelectionWith(this.type.create({language:i},l)),o.selection.$from.parent.type!==this.type&&o.setSelection(rt.near(o.doc.resolve(Math.max(0,o.selection.from-2)))),o.setMeta("paste",!0),n.dispatch(o),!0}}})]}}),yge=no.create({name:"doc",topNode:!0,content:"block+"});function Sge(n={}){return new lr({view(e){return new vge(e,n)}})}class vge{constructor(e,t){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=t.width)!==null&&r!==void 0?r:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(s=>{let i=o=>{this[s](o)};return e.dom.addEventListener(s,i),{name:s,handler:i}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,r;if(t){let a=e.nodeBefore,l=e.nodeAfter;if(a||l){let c=this.editorView.nodeDOM(this.cursorPos-(a?a.nodeSize:0));if(c){let d=c.getBoundingClientRect(),f=a?d.bottom:d.top;a&&l&&(f=(f+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),r={left:d.left,right:d.right,top:f-this.width/2,bottom:f+this.width/2}}}}if(!r){let a=this.editorView.coordsAtPos(this.cursorPos);r={left:a.left-this.width/2,right:a.left+this.width/2,top:a.top,bottom:a.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let i,o;if(!s||s==document.body&&getComputedStyle(s).position=="static")i=-pageXOffset,o=-pageYOffset;else{let a=s.getBoundingClientRect();i=a.left-s.scrollLeft,o=a.top-s.scrollTop}this.element.style.left=r.left-i+"px",this.element.style.top=r.top-o+"px",this.element.style.width=r.right-r.left+"px",this.element.style.height=r.bottom-r.top+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),s=r&&r.type.spec.disableDropCursor,i=typeof s=="function"?s(this.editorView,t,e):s;if(t&&!i){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let a=TF(this.editorView.state.doc,o,this.editorView.dragging.slice);a!=null&&(o=a)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){(e.target==this.editorView.dom||!this.editorView.dom.contains(e.relatedTarget))&&this.setCursor(null)}}const xge=or.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[Sge(this.options)]}});class pn extends at{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return pn.valid(r)?new pn(r):at.near(r)}content(){return Te.empty}eq(e){return e instanceof pn&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new pn(e.resolve(t.pos))}getBookmark(){return new rT(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!wge(e)||!bge(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let s=t.contentMatchAt(e.index()).defaultType;return s&&s.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&pn.valid(e))return e;let s=e.pos,i=null;for(let o=e.depth;;o--){let a=e.node(o);if(t>0?e.indexAfter(o)<a.childCount:e.index(o)>0){i=a.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;s+=t;let l=e.doc.resolve(s);if(pn.valid(l))return l}for(;;){let o=t>0?i.firstChild:i.lastChild;if(!o){if(i.isAtom&&!i.isText&&!We.isSelectable(i)){e=e.doc.resolve(s+i.nodeSize*t),r=!1;continue e}break}i=o,s+=t;let a=e.doc.resolve(s);if(pn.valid(a))return a}return null}}}pn.prototype.visible=!1;pn.findFrom=pn.findGapCursorFrom;at.jsonID("gapcursor",pn);class rT{constructor(e){this.pos=e}map(e){return new rT(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return pn.valid(t)?new pn(t):at.near(t)}}function wge(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let s=r.child(t-1);;s=s.lastChild){if(s.childCount==0&&!s.inlineContent||s.isAtom||s.type.spec.isolating)return!0;if(s.inlineContent)return!1}}return!0}function bge(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let s=r.child(t);;s=s.firstChild){if(s.childCount==0&&!s.inlineContent||s.isAtom||s.type.spec.isolating)return!0;if(s.inlineContent)return!1}}return!0}function Cge(){return new lr({props:{decorations:Ige,createSelectionBetween(n,e,t){return e.pos==t.pos&&pn.valid(t)?new pn(t):null},handleClick:Ege,handleKeyDown:Pge,handleDOMEvents:{beforeinput:kge}}})}const Pge=m5({ArrowLeft:Um("horiz",-1),ArrowRight:Um("horiz",1),ArrowUp:Um("vert",-1),ArrowDown:Um("vert",1)});function Um(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,s,i){let o=r.selection,a=e>0?o.$to:o.$from,l=o.empty;if(o instanceof rt){if(!i.endOfTextblock(t)||a.depth==0)return!1;l=!1,a=r.doc.resolve(e>0?a.after():a.before())}let c=pn.findGapCursorFrom(a,e,l);return c?(s&&s(r.tr.setSelection(new pn(c))),!0):!1}}function Ege(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!pn.valid(r))return!1;let s=n.posAtCoords({left:t.clientX,top:t.clientY});return s&&s.inside>-1&&We.isSelectable(n.state.doc.nodeAt(s.inside))?!1:(n.dispatch(n.state.tr.setSelection(new pn(r))),!0)}function kge(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof pn))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let s=pe.empty;for(let o=r.length-1;o>=0;o--)s=pe.from(r[o].createAndFill(null,s));let i=n.state.tr.replace(t.pos,t.pos,new Te(s,0,0));return i.setSelection(rt.near(i.doc.resolve(t.pos+1))),n.dispatch(i),!1}function Ige(n){if(!(n.selection instanceof pn))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",An.create(n.doc,[pi.widget(n.selection.head,e,{key:"gapcursor"})])}const _ge=or.create({name:"gapCursor",addProseMirrorPlugins(){return[Cge()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=dt(Le(n,"allowGapCursor",t)))!==null&&e!==void 0?e:null}}}),Tge=no.create({name:"hardBreak",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:n}){return["br",Kn(this.options.HTMLAttributes,n)]},renderText(){return`
441
+ `},addCommands(){return{setHardBreak:()=>({commands:n,chain:e,state:t,editor:r})=>n.first([()=>n.exitCode(),()=>n.command(()=>{const{selection:s,storedMarks:i}=t;if(s.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:a}=r.extensionManager,l=i||s.$to.parentOffset&&s.$from.marks();return e().insertContent({type:this.name}).command(({tr:c,dispatch:d})=>{if(d&&l&&o){const f=l.filter(p=>a.includes(p.type.name));c.ensureMarks(f)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),Mge=no.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(n=>({tag:`h${n}`,attrs:{level:n}}))},renderHTML({node:n,HTMLAttributes:e}){return[`h${this.options.levels.includes(n.attrs.level)?n.attrs.level:this.options.levels[0]}`,Kn(this.options.HTMLAttributes,e),0]},addCommands(){return{setHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.setNode(this.name,n):!1,toggleHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.toggleNode(this.name,"paragraph",n):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((n,e)=>({...n,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(n=>YP({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${n}})\\s$`),type:this.type,getAttributes:{level:n}}))}});var nv=200,Un=function(){};Un.prototype.append=function(e){return e.length?(e=Un.from(e),!this.length&&e||e.length<nv&&this.leafAppend(e)||this.length<nv&&e.leafPrepend(this)||this.appendInner(e)):this};Un.prototype.prepend=function(e){return e.length?Un.from(e).append(this):this};Un.prototype.appendInner=function(e){return new Age(this,e)};Un.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?Un.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};Un.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};Un.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};Un.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var s=[];return this.forEach(function(i,o){return s.push(e(i,o))},t,r),s};Un.from=function(e){return e instanceof Un?e:e&&e.length?new j9(e):Un.empty};var j9=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(s,i){return s==0&&i==this.length?this:new e(this.values.slice(s,i))},e.prototype.getInner=function(s){return this.values[s]},e.prototype.forEachInner=function(s,i,o,a){for(var l=i;l<o;l++)if(s(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(s,i,o,a){for(var l=i-1;l>=o;l--)if(s(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(s){if(this.length+s.length<=nv)return new e(this.values.concat(s.flatten()))},e.prototype.leafPrepend=function(s){if(this.length+s.length<=nv)return new e(s.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(Un);Un.empty=new j9([]);var Age=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,s,i,o){var a=this.left.length;if(s<a&&this.left.forEachInner(r,s,Math.min(i,a),o)===!1||i>a&&this.right.forEachInner(r,Math.max(s-a,0),Math.min(this.length,i)-a,o+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,i,o){var a=this.left.length;if(s>a&&this.right.forEachInvertedInner(r,s-a,Math.max(i,a)-a,o+a)===!1||i<a&&this.left.forEachInvertedInner(r,Math.min(s,a),i,o)===!1)return!1},e.prototype.sliceInner=function(r,s){if(r==0&&s==this.length)return this;var i=this.left.length;return s<=i?this.left.slice(r,s):r>=i?this.right.slice(r-i,s-i):this.left.slice(r,i).append(this.right.slice(0,s-i))},e.prototype.leafAppend=function(r){var s=this.right.leafAppend(r);if(s)return new e(this.left,s)},e.prototype.leafPrepend=function(r){var s=this.left.leafPrepend(r);if(s)return new e(s,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(Un);const Oge=500;class Ui{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let s,i;t&&(s=this.remapping(r,this.items.length),i=s.maps.length);let o=e.tr,a,l,c=[],d=[];return this.items.forEach((f,p)=>{if(!f.step){s||(s=this.remapping(r,p+1),i=s.maps.length),i--,d.push(f);return}if(s){d.push(new ko(f.map));let m=f.step.map(s.slice(i)),y;m&&o.maybeStep(m).doc&&(y=o.mapping.maps[o.mapping.maps.length-1],c.push(new ko(y,void 0,void 0,c.length+d.length))),i--,y&&s.appendMap(y,i)}else o.maybeStep(f.step);if(f.selection)return a=s?f.selection.map(s.slice(i)):f.selection,l=new Ui(this.items.slice(0,r).append(d.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:o,selection:a}}addTransform(e,t,r,s){let i=[],o=this.eventCount,a=this.items,l=!s&&a.length?a.get(a.length-1):null;for(let d=0;d<e.steps.length;d++){let f=e.steps[d].invert(e.docs[d]),p=new ko(e.mapping.maps[d],f,t),m;(m=l&&l.merge(p))&&(p=m,d?i.pop():a=a.slice(0,a.length-1)),i.push(p),t&&(o++,t=void 0),s||(l=p)}let c=o-r.depth;return c>Dge&&(a=Rge(a,c),o-=c),new Ui(a.append(i),o)}remapping(e,t){let r=new Jf;return this.items.forEach((s,i)=>{let o=s.mirrorOffset!=null&&i-s.mirrorOffset>=e?r.maps.length-s.mirrorOffset:void 0;r.appendMap(s.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new Ui(this.items.append(e.map(t=>new ko(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],s=Math.max(0,this.items.length-t),i=e.mapping,o=e.steps.length,a=this.eventCount;this.items.forEach(p=>{p.selection&&a--},s);let l=t;this.items.forEach(p=>{let m=i.getMirror(--l);if(m==null)return;o=Math.min(o,m);let y=i.maps[m];if(p.step){let v=e.steps[m].invert(e.docs[m]),x=p.selection&&p.selection.map(i.slice(l+1,m));x&&a++,r.push(new ko(y,v,x))}else r.push(new ko(y))},s);let c=[];for(let p=t;p<o;p++)c.push(new ko(i.maps[p]));let d=this.items.slice(0,s).append(c).append(r),f=new Ui(d,a);return f.emptyItemCount()>Oge&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,s=[],i=0;return this.items.forEach((o,a)=>{if(a>=e)s.push(o),o.selection&&i++;else if(o.step){let l=o.step.map(t.slice(r)),c=l&&l.getMap();if(r--,c&&t.appendMap(c,r),l){let d=o.selection&&o.selection.map(t.slice(r));d&&i++;let f=new ko(c.invert(),l,d),p,m=s.length-1;(p=s.length&&s[m].merge(f))?s[m]=p:s.push(f)}}else o.map&&r--},this.items.length,0),new Ui(Un.from(s.reverse()),i)}}Ui.empty=new Ui(Un.empty,0);function Rge(n,e){let t;return n.forEach((r,s)=>{if(r.selection&&e--==0)return t=s,!1}),n.slice(t)}class ko{constructor(e,t,r,s){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=s}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ko(t.getMap().invert(),t,this.selection)}}}class wl{constructor(e,t,r,s,i){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=s,this.prevComposition=i}}const Dge=20;function jge(n,e,t,r){let s=t.getMeta(Kc),i;if(s)return s.historyState;t.getMeta(Fge)&&(n=new wl(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(Kc))return o.getMeta(Kc).redo?new wl(n.done.addTransform(t,void 0,r,fy(e)),n.undone,XN(t.mapping.maps),n.prevTime,n.prevComposition):new wl(n.done,n.undone.addTransform(t,void 0,r,fy(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let a=t.getMeta("composition"),l=n.prevTime==0||!o&&n.prevComposition!=a&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Nge(t,n.prevRanges)),c=o?BC(n.prevRanges,t.mapping):XN(t.mapping.maps);return new wl(n.done.addTransform(t,l?e.selection.getBookmark():void 0,r,fy(e)),Ui.empty,c,t.time,a??n.prevComposition)}else return(i=t.getMeta("rebased"))?new wl(n.done.rebased(t,i),n.undone.rebased(t,i),BC(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new wl(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),BC(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Nge(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,s)=>{for(let i=0;i<e.length;i+=2)r<=e[i+1]&&s>=e[i]&&(t=!0)}),t}function XN(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,s,i,o)=>e.push(i,o));return e}function BC(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let s=e.map(n[r],1),i=e.map(n[r+1],-1);s<=i&&t.push(s,i)}return t}function Lge(n,e,t){let r=fy(e),s=Kc.get(e).spec.config,i=(t?n.undone:n.done).popEvent(e,r);if(!i)return null;let o=i.selection.resolve(i.transform.doc),a=(t?n.done:n.undone).addTransform(i.transform,e.selection.getBookmark(),s,r),l=new wl(t?a:i.remaining,t?i.remaining:a,null,0,-1);return i.transform.setSelection(o).setMeta(Kc,{redo:t,historyState:l})}let UC=!1,ZN=null;function fy(n){let e=n.plugins;if(ZN!=e){UC=!1,ZN=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){UC=!0;break}}return UC}const Kc=new qs("history"),Fge=new qs("closeHistory");function zge(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new lr({key:Kc,state:{init(){return new wl(Ui.empty,Ui.empty,null,0,-1)},apply(e,t,r){return jge(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,s=r=="historyUndo"?L9:r=="historyRedo"?F9:null;return s?(t.preventDefault(),s(e.state,e.dispatch)):!1}}}})}function N9(n,e){return(t,r)=>{let s=Kc.getState(t);if(!s||(n?s.undone:s.done).eventCount==0)return!1;if(r){let i=Lge(s,t,n);i&&r(e?i.scrollIntoView():i)}return!0}}const L9=N9(!1,!0),F9=N9(!0,!0),$ge=or.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>L9(n,e),redo:()=>({state:n,dispatch:e})=>F9(n,e)}},addProseMirrorPlugins(){return[zge(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Bge=no.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{}}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:n}){return["hr",Kn(this.options.HTMLAttributes,n)]},addCommands(){return{setHorizontalRule:()=>({chain:n,state:e})=>{const{selection:t}=e,{$from:r,$to:s}=t,i=n();return r.parentOffset===0?i.insertContentAt({from:Math.max(r.pos-1,0),to:s.pos},{type:this.name}):sQ(t)?i.insertContentAt(s.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({tr:o,dispatch:a})=>{var l;if(a){const{$to:c}=o.selection,d=c.end();if(c.nodeAfter)c.nodeAfter.isTextblock?o.setSelection(rt.create(o.doc,c.pos+1)):c.nodeAfter.isBlock?o.setSelection(We.create(o.doc,c.pos)):o.setSelection(rt.create(o.doc,c.pos));else{const f=(l=c.parent.type.contentMatch.defaultType)===null||l===void 0?void 0:l.create();f&&(o.insert(d,f),o.setSelection(rt.create(o.doc,d+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[jQ({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),Uge=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Hge=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Kge=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Wge=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Vge=Lo.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:n=>n.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Yc({find:Uge,type:this.type}),Yc({find:Kge,type:this.type})]},addPasteRules(){return[Ll({find:Hge,type:this.type}),Ll({find:Wge,type:this.type})]}}),qge=no.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",Kn(this.options.HTMLAttributes,n),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),Gge="listItem",JN="textStyle",QN=/^(\d+)\.\s$/,Yge=no.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:n=>n.hasAttribute("start")?parseInt(n.getAttribute("start")||"",10):1},type:{default:void 0,parseHTML:n=>n.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:n}){const{start:e,...t}=n;return e===1?["ol",Kn(this.options.HTMLAttributes,t),0]:["ol",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleOrderedList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Gge,this.editor.getAttributes(JN)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let n=sp({find:QN,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(n=sp({find:QN,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(JN)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[n]}}),Xge=no.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Zge=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Jge=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Qge=Lo.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["s",Kn(this.options.HTMLAttributes,n),0]},addCommands(){return{setStrike:()=>({commands:n})=>n.setMark(this.name),toggleStrike:()=>({commands:n})=>n.toggleMark(this.name),unsetStrike:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Yc({find:Zge,type:this.type})]},addPasteRules(){return[Ll({find:Jge,type:this.type})]}}),eme=no.create({name:"text",group:"inline"}),tme=or.create({name:"starterKit",addExtensions(){var n,e,t,r,s,i,o,a,l,c,d,f,p,m,y,v,x,b;const C=[];return this.options.bold!==!1&&C.push(dge.configure((n=this.options)===null||n===void 0?void 0:n.bold)),this.options.blockquote!==!1&&C.push(oge.configure((e=this.options)===null||e===void 0?void 0:e.blockquote)),this.options.bulletList!==!1&&C.push(fge.configure((t=this.options)===null||t===void 0?void 0:t.bulletList)),this.options.code!==!1&&C.push(P9.configure((r=this.options)===null||r===void 0?void 0:r.code)),this.options.codeBlock!==!1&&C.push(mge.configure((s=this.options)===null||s===void 0?void 0:s.codeBlock)),this.options.document!==!1&&C.push(yge.configure((i=this.options)===null||i===void 0?void 0:i.document)),this.options.dropcursor!==!1&&C.push(xge.configure((o=this.options)===null||o===void 0?void 0:o.dropcursor)),this.options.gapcursor!==!1&&C.push(_ge.configure((a=this.options)===null||a===void 0?void 0:a.gapcursor)),this.options.hardBreak!==!1&&C.push(Tge.configure((l=this.options)===null||l===void 0?void 0:l.hardBreak)),this.options.heading!==!1&&C.push(Mge.configure((c=this.options)===null||c===void 0?void 0:c.heading)),this.options.history!==!1&&C.push($ge.configure((d=this.options)===null||d===void 0?void 0:d.history)),this.options.horizontalRule!==!1&&C.push(Bge.configure((f=this.options)===null||f===void 0?void 0:f.horizontalRule)),this.options.italic!==!1&&C.push(Vge.configure((p=this.options)===null||p===void 0?void 0:p.italic)),this.options.listItem!==!1&&C.push(qge.configure((m=this.options)===null||m===void 0?void 0:m.listItem)),this.options.orderedList!==!1&&C.push(Yge.configure((y=this.options)===null||y===void 0?void 0:y.orderedList)),this.options.paragraph!==!1&&C.push(Xge.configure((v=this.options)===null||v===void 0?void 0:v.paragraph)),this.options.strike!==!1&&C.push(Qge.configure((x=this.options)===null||x===void 0?void 0:x.strike)),this.options.text!==!1&&C.push(eme.configure((b=this.options)===null||b===void 0?void 0:b.text)),C}}),sT={tldraw_draw:{normal:{normal:{family:"tldraw_draw",src:{url:"tldraw_draw",format:"woff2"},weight:"normal"},bold:{family:"tldraw_draw",src:{url:"tldraw_draw_bold",format:"woff2"},weight:"bold"}},italic:{normal:{family:"tldraw_draw",src:{url:"tldraw_draw_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_draw",src:{url:"tldraw_draw_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}},tldraw_sans:{normal:{normal:{family:"tldraw_sans",src:{url:"tldraw_sans",format:"woff2"},weight:"normal",style:"normal"},bold:{family:"tldraw_sans",src:{url:"tldraw_sans_bold",format:"woff2"},weight:"bold",style:"normal"}},italic:{normal:{family:"tldraw_sans",src:{url:"tldraw_sans_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_sans",src:{url:"tldraw_sans_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}},tldraw_serif:{normal:{normal:{family:"tldraw_serif",src:{url:"tldraw_serif",format:"woff2"},weight:"normal",style:"normal"},bold:{family:"tldraw_serif",src:{url:"tldraw_serif_bold",format:"woff2"},weight:"bold",style:"normal"}},italic:{normal:{family:"tldraw_serif",src:{url:"tldraw_serif_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_serif",src:{url:"tldraw_serif_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}},tldraw_mono:{normal:{normal:{family:"tldraw_mono",src:{url:"tldraw_mono",format:"woff2"},weight:"normal",style:"normal"},bold:{family:"tldraw_mono",src:{url:"tldraw_mono_bold",format:"woff2"},weight:"bold",style:"normal"}},italic:{normal:{family:"tldraw_mono",src:{url:"tldraw_mono_italic",format:"woff2"},weight:"normal",style:"italic"},bold:{family:"tldraw_mono",src:{url:"tldraw_mono_italic_bold",format:"woff2"},weight:"bold",style:"italic"}}}},nme=fn(sT).flatMap(n=>fn(n).flatMap(e=>Object.values(e))),rme=or.create({name:"textDirection",addGlobalAttributes(){return[{types:["heading","paragraph"],attributes:{dir:{default:"auto",parseHTML:n=>{const e=n.getAttribute("dir");return e&&["ltr","rtl","auto"].includes(e)?e:"auto"},renderHTML:n=>({dir:n.dir})}}}]}});var sme=rme;const ime=or.create({name:"keyboardShiftEnterHandler",addKeyboardShortcuts(){return{"Shift-Enter":({editor:n})=>n.commands.enter()}}});P9.config.excludes=void 0;E9.config.priority=1100;const Zp=[tme.configure({blockquote:!1,codeBlock:!1,horizontalRule:!1}),sge.configure({openOnClick:!1,autolink:!0}),E9,ime,sme];function iT(n,e){var s;const t=((s=n.getTextOptions().tipTapConfig)==null?void 0:s.extensions)??Zp;return XJ(e,t).replaceAll('<p dir="auto"></p>',"<p><br /></p>")??""}function rv(n,e){return`<div class="tl-rich-text">${iT(n,e)}</div>`}function br(n,e){var r;const t=((r=n.getTextOptions().tipTapConfig)==null?void 0:r.extensions)??Zp;return JJ(e,t,{blockSeparator:`
442
+ `})}function ome(n,e){var r;const t=((r=n.getTextOptions().tipTapConfig)==null?void 0:r.extensions)??Zp;return ZJ(e,t)}function z9(n,e,t){for(const o of n.marks)o.type.name==="bold"&&e.weight!=="bold"&&(e={...e,weight:"bold"}),o.type.name==="italic"&&e.style!=="italic"&&(e={...e,style:"italic"}),o.type.name==="code"&&e.family!=="tldraw_mono"&&(e={...e,family:"tldraw_mono"});const r=On(sT,e.family);if(!r)return e;const s=On(r,e.style);if(!s)return e;const i=On(s,e.weight);return i&&t(i),e}const ame=" ",Wf=class Wf{static normalizeText(e){return e.replace(Wf.fixNewLines,`
443
+ `)}static normalizeTextForDom(e){return e.replace(Wf.fixNewLines,`
444
+ `).split(`
445
+ `).map(t=>t||" ").join(`
446
+ `)}};O(Wf,"fixNewLines",/\r?\n|\r/g);let sv=Wf;const lme=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function $9(n){return lme.test(n)}function cme(n){return n.replace(/\t/g,ame)}function ume(n){const e=n.split(`
447
+ `);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(`
448
+ `)}const B9={"&amp;":"&","&quot;":'"',"&apos;":"'","&#34;":'"',"&#38;":"&","&#39;":"'","&#8211;":"–","&#8212;":"—","&#8216;":"‘","&#8217;":"’","&#8220;":"“","&#8221;":"”","&#8230;":"…"},dme=new RegExp(Object.keys(B9).join("|"),"g");function hme(n){return n.replace(dme,e=>B9[e])}function fme(n){return n.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function pme(n){return fme(ume(cme(n)))}const U9=5e3,H9=10*1024*1024;function gme(n,e){n.registerExternalAssetHandler("file",async t=>mme(n,t,e)),n.registerExternalAssetHandler("url",async t=>yme(n,t,e)),n.registerExternalContentHandler("svg-text",async t=>Sme(n,t)),n.registerExternalContentHandler("embed",t=>vme(n,t)),n.registerExternalContentHandler("files",async t=>xme(n,t,e)),n.registerExternalContentHandler("text",async t=>wme(n,t)),n.registerExternalContentHandler("url",async t=>bme(n,t,e)),n.registerExternalContentHandler("tldraw",async t=>Cme(n,t)),n.registerExternalContentHandler("excalidraw",async t=>Pme(n,t))}async function mme(n,{file:e,assetId:t},{acceptedImageMimeTypes:r=wp,acceptedVideoMimeTypes:s=uv,maxAssetSize:i=H9,maxImageDimension:o=U9,toasts:a,msg:l}){const c=r.includes(e.type),d=s.includes(e.type);!c&&!d&&a.addToast({title:l("assets.files.type-not-allowed"),severity:"error"}),nt(c||d,`File type not allowed: ${e.type}`),e.size>i&&a.addToast({title:l("assets.files.size-too-big"),severity:"error"}),nt(e.size<=i,`File size too big: ${(e.size/1024).toFixed()}kb > ${(i/1024).toFixed()}kb`);const f=GL(await e.arrayBuffer());t=t??zl.createId(f);const p=await K9(e,t,c,d,o),m=await n.uploadAsset(p,e);return p.props.src=m.src,m.meta&&(p.meta={...p.meta,...m.meta}),zl.create(p)}async function yme(n,{url:e},{toasts:t,msg:r}){var i,o,a,l,c;let s;try{const f=await(await Vi(e,{method:"GET",mode:"no-cors"})).text(),p=new DOMParser().parseFromString(f,"text/html");s={image:((i=p.head.querySelector('meta[property="og:image"]'))==null?void 0:i.getAttribute("content"))??"",favicon:((o=p.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:o.getAttribute("href"))??((a=p.head.querySelector('link[rel="icon"]'))==null?void 0:a.getAttribute("href"))??"",title:((l=p.head.querySelector('meta[property="og:title"]'))==null?void 0:l.getAttribute("content"))??e,description:((c=p.head.querySelector('meta[property="og:description"]'))==null?void 0:c.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(d){console.error(d),t.addToast({title:r("assets.url.failed"),severity:"error"}),s={image:"",favicon:"",title:"",description:""}}return{id:zl.createId(mk(e)),typeName:"asset",type:"bookmark",props:{src:e,description:s.description,image:s.image,favicon:s.favicon,title:s.title},meta:{}}}async function Sme(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 i=parseFloat(s.getAttribute("width")||"0"),o=parseFloat(s.getAttribute("height")||"0");if(!(i&&o)){document.body.appendChild(s);const l=s.getBoundingClientRect();document.body.removeChild(s),i=l.width,o=l.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");W9(n,[a],r)}function vme(n,{point:e,url:t,embed:r}){const s=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),{width:i,height:o}=r,a=Dt(),l={id:a,type:"embed",x:s.x-(i||450)/2,y:s.y-(o||450)/2,props:{w:i,h:o,url:t}};n.createShapes([l]).select(a)}async function xme(n,{point:e,files:t},{maxAssetSize:r=H9,maxImageDimension:s=U9,acceptedImageMimeTypes:i=wp,acceptedVideoMimeTypes:o=uv,toasts:a,msg:l}){if(t.length>n.options.maxFilesAtOnce){a.addToast({title:l("assets.files.amount-too-big"),severity:"error"});return}const c=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),d=new E(c.x,c.y),f=[],p=[];for(const m of t){if(m.size>r){a.addToast({title:l("assets.files.size-too-big"),severity:"error"}),console.warn(`File size too big: ${(m.size/1024).toFixed()}kb > ${(r/1024).toFixed()}kb`);continue}if(!m.type){a.addToast({title:l("assets.files.upload-failed"),severity:"error"}),console.error("No mime type");continue}if(![...i,...o].includes(m.type)){a.addToast({title:l("assets.files.type-not-allowed"),severity:"error"}),console.warn(`${m.name} not loaded - Mime type not allowed ${m.type}.`);continue}const v=i.includes(m.type),x=o.includes(m.type),b=GL(await m.arrayBuffer()),C=zl.createId(b),I=await K9(m,C,v,x,s);let _;v&&(_=n.createTemporaryAssetPreview(C,m)),f.push(I),p.push({asset:I,file:m,temporaryAssetPreview:_})}Promise.allSettled(p.map(async m=>{try{const y=await n.getAssetForExternalContent({type:"file",file:m.file});if(!y)throw Error("Could not create an asset");n.updateAssets([{...y,id:m.asset.id}])}catch(y){a.addToast({title:l("assets.files.upload-failed"),severity:"error"}),console.error(y),n.deleteAssets([m.asset.id]);return}})),W9(n,f,d)}async function wme(n,{point:e,text:t,html:r}){const s=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),i=n.getShapeUtil("text").getDefaultProps(),o=pme(t),a=r?ome(n,r):wi(o);let l,c,d,f="middle";const p=r??o.replace(/\n/g,"<br>"),m=r?a.content.length>1:o.split(`
449
+ `).length>1,y=$9(o);m&&(f=m?y?"end":"start":"middle");const v=n.textMeasure.measureHtml(p,{...ir,fontFamily:Da[i.font],fontSize:Vd[i.size],maxWidth:null}),x=Math.min(m?n.getViewportPageBounds().width*.9:920,Math.max(200,n.getViewportPageBounds().width*.9));if(v.w>x){const b=n.textMeasure.measureHtml(p,{...ir,fontFamily:Da[i.font],fontSize:Vd[i.size],maxWidth:x});l=b.w,c=b.h,d=!1,f=y?"end":"start"}else l=v.w,c=v.h,d=!0;s.y-c/2<n.getViewportPageBounds().minY+40&&(s.y=n.getViewportPageBounds().minY+40+c/2),n.createShapes([{id:Dt(),type:"text",x:s.x-l/2,y:s.y-c/2,props:{richText:a,textAlign:f,autoSize:d,w:l}}])}async function bme(n,{point:e,url:t},{toasts:r,msg:s}){const i=n.getShapeUtil("embed"),o=i==null?void 0:i.getEmbedDefinition(t);if(o)return n.putExternalContent({type:"embed",url:o.url,point:e,embed:o.definition});const a=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),l=zl.createId(mk(t)),c=Eme(n,t,a);let d=n.getAsset(l),f=!1;if(!d){f=!0;try{const p=await n.getAssetForExternalContent({type:"url",url:t});if(!p)throw Error("Could not create an asset");d=p}catch{r.addToast({title:s("assets.url.failed"),severity:"error"});return}}n.run(()=>{f&&n.createAssets([d]),n.updateShapes([{id:c.id,type:c.type,props:{assetId:d.id}}])})}async function Cme(n,{point:e,content:t}){n.run(()=>{const r=n.getSelectionPageBounds();n.markHistoryStoppingPoint("paste"),n.putContentOntoCurrentPage(t,{point:e,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 Pme(n,{point:e,content:t}){n.run(()=>{xpe(n,t,e)})}async function K9(n,e,t,r,s){let i=n.type;n.type==="video/quicktime"&&(i="video/mp4");const o=t?await Ls.getImageSize(n):await Ls.getVideoSize(n),a=await Ls.isAnimated(n)||r,l={id:e,type:t?"image":"video",typeName:"asset",props:{name:n.name,src:"",w:o.w,h:o.h,fileSize:n.size,mimeType:i,isAnimated:a},meta:{}};if(s&&isFinite(s)){const c={w:l.props.w,h:l.props.h},d=vpe(c,{w:s,h:s});c!==d&&Ls.isStaticImageType(n.type)&&(l.props.w=d.w,l.props.h=d.h)}return l}async function W9(n,e,t){if(!e.length)return[];const r=E.From(t),s=[];for(let i=0;i<e.length;i++){const o=e[i];switch(o.type){case"image":{s.push({id:Dt(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:o.id,w:o.props.w,h:o.props.h}}),r.x+=o.props.w;break}case"video":s.push({id:Dt(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:o.id,w:o.props.w,h:o.props.h}}),r.x+=o.props.w}}return n.run(()=>{const i=e.filter(o=>!n.getAsset(o.id));i.length&&n.createAssets(i),n.createShapes(s).select(...s.map(o=>o.id)),V9(n,t)}),s.map(i=>i.id)}function V9(n,e){const t=n.getViewportPageBounds();let r=n.getSelectionPageBounds();if(r){const s=r.center.sub(e);n.updateShapes(n.getSelectedShapes().map(i=>{const o=n.getShapeParentTransform(i).decompose().rotation,a=E.Rot(s,-o);return{id:i.id,type:i.type,x:i.x-a.x,y:i.y-a.y}}))}if(r=n.getSelectionPageBounds(),r&&n.getInstanceState().isGridMode){const s=n.getDocumentSettings().gridSize,i=new E(r.minX,r.minY),o=i.clone().snapToGrid(s),a=E.Sub(i,o);n.updateShapes(n.getSelectedShapes().map(l=>{const c={x:l.x-a.x,y:l.y-a.y};return{id:l.id,type:l.type,x:c.x,y:c.y}}))}r=n.getSelectionPageBounds(),r&&!t.contains(r)&&n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})}function Eme(n,e,t){const r={id:Dt(),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),V9(n,t)}),n.getShape(r.id)}var rP;let kme=(rP=class extends Ne{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}))}}},O(rP,"id","idle"),rP);var sP;let Ime=(sP=class extends Ne{constructor(){super(...arguments);O(this,"shape");O(this,"markId","");O(this,"preciseTimeout",-1);O(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=Dt();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`);const s=Ji(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 i=this.editor.getShape(r);if(!i)throw Error("expected shape");const o=this.editor.getShapeHandles(i);if(!o)throw Error("expected handles for arrow");const a=this.editor.getShapeUtil("arrow"),l=this.shape,c=o.find(p=>p.id==="start"),d=(f=a.onHandleDrag)==null?void 0:f.call(a,i,{handle:{...c,x:0,y:0},isPrecise:!0,initial:l});d&&this.editor.updateShapes([d]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,i;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 o=this.editor.getShapeUtil("arrow"),a=this.shape,l=r.find(d=>d.id==="start"),c=(s=o.onHandleDrag)==null?void 0:s.call(o,t,{handle:{...l,x:0,y:0},isPrecise:this.didTimeout,initial:a});c&&this.editor.updateShapes([c])}{const o=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),c=r.find(f=>f.id==="end"),d=(i=o.onHandleDrag)==null?void 0:i.call(o,this.editor.getShape(t),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});d&&this.editor.updateShapes([d])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},O(sP,"id","pointing"),sP);class HE extends Ne{constructor(){super(...arguments);O(this,"shapeType","arrow")}static children(){return[kme,Ime]}}O(HE,"id","arrow"),O(HE,"initial","idle");class oT extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"initialShape");O(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");O(this,"util",this.editor.getShapeUtil(this.shapeType));O(this,"isPen",!1);O(this,"isPenOrStylus",!1);O(this,"segmentMode","free");O(this,"didJustShiftClickToExtendPreviousShapeLine",!1);O(this,"pagePointWhereCurrentSegmentChanged",{});O(this,"pagePointWhereNextSegmentChanged",null);O(this,"lastRecordedPoint",{});O(this,"mergeNextPoint",!1);O(this,"currentLineLength",0);O(this,"markId",null)}onEnter(t){this.markId=null,this.info=t,this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.startShape()}onPointerMove(){const{inputs:t}=this.editor;if(this.isPen&&!t.isPen&&this.markId){this.editor.bailToMark(this.markId),this.startShape();return}this.isPenOrStylus?E.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 i=Er[r],o=t[0].points[0],a=t[t.length-1],l=a.points[a.points.length-1];return o!==l&&this.currentLineLength>i*4*s&&E.DistMin(o,l,i*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 i=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 l=Jn(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=Jn(l.points);if(!c)throw Error("Expected a previous point!");const{x:d,y:f}=this.editor.getPointInShapeSpace(a,t).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+i.toFixed(2)},{x:d,y:f,z:+i.toFixed(2)}]},m=ve.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=m,this.pagePointWhereNextSegmentChanged=null;const y=[...a.props.segments,p];this.currentLineLength<Er[a.props.size]*4&&(this.currentLineLength=this.getLineLength(y));const v={id:a.id,type:this.shapeType,props:{segments:y}};this.canClose()&&(v.props.isClosed=this.getIsClosed(y,a.props.size,a.props.scale)),this.editor.updateShapes([v]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const o=Dt();this.editor.createShapes([{id:o,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:+i.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(o)}updateDrawingShape(){const{initialShape:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:s,props:{size:i,scale:o}}=t,a=this.editor.getShape(s);if(!a)return;const{segments:l}=a.props,{x:c,y:d,z:f}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),p=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,m={x:c,y:d,z:p};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:y}=this;if(y===null)throw Error("We should have a point where the segment changed");if(E.Dist2(y,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const x=Jn(l);if(!x)throw Error("Expected a previous segment!");const b=Jn(x.points);if(!b)throw Error("Expected a previous last point!");let C;const I=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(x.type==="straight"){this.currentLineLength+=E.Dist(b,I),C={type:"straight",points:[{...b},I]};const T=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=ve.applyToPoint(T,b)}else C={type:"straight",points:[I,m]};const _={id:s,type:this.shapeType,props:{segments:[...l,C]}};this.canClose()&&(_.props.isClosed=this.getIsClosed(l,i,o)),this.editor.updateShapes([_])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:y}=this;if(y===null)throw Error("We should have a point where the segment changed");if(E.Dist2(y,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const x=l.slice(),b=x[x.length-1],C=Jn(b.points);if(!C)throw Error("No previous point!");const I={type:"free",points:[...E.PointsBetween(C,m,6).map(A=>({x:va(A.x),y:va(A.y),z:va(A.z)}))]},_=[...x,I];this.currentLineLength<Er[a.props.size]*4&&(this.currentLineLength=this.getLineLength(_));const T={id:s,type:this.shapeType,props:{segments:_}};this.canClose()&&(T.props.isClosed=this.getIsClosed(_,i,o)),this.editor.updateShapes([T])}break}case"straight":{const y=l.slice(),v=y[y.length-1],{pagePointWhereCurrentSegmentChanged:x}=this,{ctrlKey:b,currentPagePoint:C}=this.editor.inputs;if(!x)throw Error("We should have a point where the segment changed");let I,_=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(_=!b,this.didJustShiftClickToExtendPreviousShapeLine=!1):_=!b;let T=this.editor.getPointInShapeSpace(a,C).toFixed().toJson(),A=!1,R;if((this.editor.user.getIsSnapMode()?!b:b)&&y.length>2){let U,J=8/this.editor.getZoomLevel();for(let z=0,N=l.length-2;z<N;z++){const L=l[z];if(!L)break;if(L.type==="free")continue;const V=L.points[0],X=Jn(L.points);if(!(V&&X))continue;const W=E.NearestPointOnLineSegment(V,X,T);if(E.DistMin(W,T,J)){U=W.toFixed().toJson(),J=E.Dist(W,T),R=L;break}}U&&(A=!0,T=U)}if(A&&R){const U=this.editor.getShapePageTransform(a),J=R.points[0],z=Jn(R.points);if(!z)throw Error("Expected a last point!");const N=ve.applyToPoint(U,J),L=ve.applyToPoint(U,z),V=ve.applyToPoint(U,T);this.editor.snaps.setIndicators([{id:_t(),type:"points",points:[N,V,L]}])}else{if(this.editor.snaps.clearIndicators(),_){const U=E.Angle(x,C),z=By(U,24)-U;I=E.RotWith(C,x,z)}else I=C;T=this.editor.getPointInShapeSpace(a,I).toFixed().toJson()}this.currentLineLength+=E.Dist(v.points[0],T),y[y.length-1]={...v,type:"straight",points:[v.points[0],T]};const K={id:s,type:this.shapeType,props:{segments:y}};this.canClose()&&(K.props.isClosed=this.getIsClosed(l,i,o)),this.editor.updateShapes([K]);break}case"free":{const y=l.slice(),v=y[y.length-1],x=[...v.points];if(x.length&&this.mergeNextPoint){const{z:C}=x[x.length-1];x[x.length-1]={x:m.x,y:m.y,z:C?Math.max(C,m.z):m.z}}else this.currentLineLength+=E.Dist(x[x.length-1],m),x.push(m);y[y.length-1]={...v,points:x},this.currentLineLength<Er[a.props.size]*4&&(this.currentLineLength=this.getLineLength(y));const b={id:s,type:this.shapeType,props:{segments:y}};if(this.canClose()&&(b.props.isClosed=this.getIsClosed(y,i,o)),this.editor.updateShapes([b]),x.length>this.util.options.maxPointsPerShape){this.editor.updateShapes([{id:s,type:this.shapeType,props:{isComplete:!0}}]);const C=Dt(),I=this.editor.getShape(s).props;this.editor.createShapes([{id:C,type:this.shapeType,x:va(r.currentPagePoint.x),y:va(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:I.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(f*1.25).toFixed():.5}]}]}}]),this.initialShape=Yt(this.editor.getShape(C)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(t){let r=0;for(const s of t)for(let i=0;i<s.points.length-1;i++){const o=s.points[i],a=s.points[i+1];r+=E.Dist2(a,o)}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)}}O(oT,"id","drawing");var iP;let q9=(iP=class extends Ne{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},O(iP,"id","idle"),iP);class py extends Ne{constructor(){super(...arguments);O(this,"shapeType","draw")}static children(){return[q9,oT]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}O(py,"id","draw"),O(py,"initial","idle"),O(py,"isLockable",!1);class KE extends yE{constructor(){super(...arguments);O(this,"shapeType","frame")}onCreate(t){if(!t)return;const r=this.editor.getShapePageBounds(t),s=[],i=this.editor.getShapeAncestors(t).map(o=>o.id);this.editor.getSortedChildIdsForParent(t.parentId).map(o=>{const a=this.editor.getShape(o);if(!a||a.id===t.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&_me(a,i,t)&&s.push(a.id)}),this.editor.reparentShapes(s,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")}}O(KE,"id","frame"),O(KE,"initial","idle");function _me(n,e,t){return e.includes(n.id)?!1:n.parentId===t.parentId}var oP;let Tme=(oP=class extends Ne{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")}},O(oP,"id","idle"),oP);var aP;let Mme=(aP=class extends Ne{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=Dt(),s=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`),i=Ji(t,this.editor);this.editor.createShapes([{id:r,type:"geo",x:i.x,y:i.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(Wi),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=Dt();this.editor.markHistoryStoppingPoint(`creating_geo:${t}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(Wi),i=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(Wi),scale:r,...i}}]);const o=this.editor.getShape(t);if(!o)return;const{w:a,h:l}=o.props,c=new E(a/2,l/2).mul(r),d=this.editor.getShapeParentTransform(o);d&&c.rot(-d.rotation());const f=Ji(new E(o.x-c.x,o.y-c.y),this.editor);this.editor.select(t),this.editor.updateShape({id:o.id,type:"geo",x:f.x,y:f.y,props:{geo:this.editor.getStyleForNextShape(Wi),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},O(aP,"id","pointing"),aP);class WE extends Ne{constructor(){super(...arguments);O(this,"shapeType","geo")}static children(){return[Tme,Mme]}}O(WE,"id","geo"),O(WE,"initial","idle");class gy extends Ne{constructor(){super(...arguments);O(this,"shapeType","highlight")}static children(){return[q9,oT]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}O(gy,"id","highlight"),O(gy,"initial","idle"),O(gy,"isLockable",!1);var lP;let Ame=(lP=class extends Ne{constructor(){super(...arguments);O(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")}},O(lP,"id","idle"),lP);const eL=2;var cP;let Ome=(cP=class extends Ne{constructor(){super(...arguments);O(this,"shape",{});O(this,"markId")}onEnter(t){const{inputs:r}=this.editor,{currentPagePoint:s}=r;this.markId=void 0;const i=t.shapeId&&this.editor.getShape(t.shapeId);if(i&&r.shiftKey){this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i.id}`),this.shape=i;const o=this.editor.getShapeHandles(this.shape);if(!o)return;const a=o.filter(y=>y.type==="vertex").sort(Qn),l=a[a.length-1],c=a[a.length-2],d=ve.applyToPoint(this.editor.getShapeParentTransform(this.shape),new E(this.shape.x,this.shape.y)),f=E.Sub(s,d).addXY(.1,.1),p=Ji(f,this.editor),m=Yt(this.shape.props.points);if(E.DistMin(l,c,eL)||E.DistMin(p,l,eL))m[l.id]={id:l.id,index:l.index,x:p.x,y:p.y};else{const y=To(l.index);m[y]={id:y,index:y,x:p.x,y:p.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:m}}])}else{const o=Dt();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${o}`);const a=Ji(s,this.editor);this.editor.createShapes([{id:o,type:"line",x:a.x,y:a.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(o),this.shape=this.editor.getShape(o)}}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=Jn(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()}},O(cP,"id","pointing"),cP);class VE extends Ne{constructor(){super(...arguments);O(this,"shapeType","line")}static children(){return[Ame,Ome]}}O(VE,"id","line"),O(VE,"initial","idle");var uP;let Rme=(uP=class extends Ne{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},O(uP,"id","idle"),uP);const Dme=0,Ot=200,_0=new E(Ot/2,Ot/2),G9=10,jme=n=>[[["a1"],new E(Ot*.5,Ot*-.5-n.options.adjacentShapeMargin)],[["a2"],new E(Ot*1.5+n.options.adjacentShapeMargin,Ot*.5)],[["a3"],new E(Ot*.5,Ot*1.5+n.options.adjacentShapeMargin)],[["a4"],new E(Ot*-.5-n.options.adjacentShapeMargin,Ot*.5)]];function Nme(n,e){if(e===1)return jme(n);const t=Ot*e,r=n.options.adjacentShapeMargin*e;return[[["a1"],new E(t*.5,t*-.5-r)],[["a2"],new E(t*1.5+r,t*.5)],[["a3"],new E(t*.5,t*1.5+r)],[["a4"],new E(t*-.5-r,t*.5)]]}function Y9(n,e,t,r,s,i){return Object.fromEntries(Nme(n,i).map(([o,a],l)=>{const c=a.clone();return l===0&&s?c.y-=s:l===2&&r&&(c.y+=r),[o,c.rot(t).add(e)]}))}function X9(n,e,t,r){const s=new Set(n.getSelectedShapeIds()),i=(Ot+n.options.adjacentShapeMargin+r)**2,o=new Map,a=[];for(const d of n.getCurrentPageShapes()){if(!n.isShapeOfType(d,"note")||t!==d.props.scale||s.has(d.id))continue;const f=n.getShapePageTransform(d.id);e===f.rotation()&&(o.set(d,n.getShapePageBounds(d).center),a.push(...Object.values(Y9(n,f.point(),e,d.props.growY,r,t))))}const l=a.length;let c;for(const[d,f]of o)for(let p=0;p<l;p++)c=a[p],c&&(E.Dist2(f,c)>i||n.isPointInShape(d,c)&&(a[p]=void 0));return st(a)}function Z9(n,e,t,r,s=!1){let i;const o=n.getCurrentPageShapesSorted(),a=(Ot+n.options.adjacentShapeMargin**2)**e.props.scale;for(let l=o.length-1;l>=0;l--){const c=o[l];if(c.type==="note"&&c.id!==e.id){const d=n.getShapePageBounds(c);if(d&&E.Dist2(d.center,t)<a&&n.isPointInShape(c,t)){i=c;break}}}if(n.complete(),!i||s){n.markHistoryStoppingPoint("creating note shape");const l=Dt();n.createShape({id:l,type:"note",x:t.x,y:t.y,rotation:r,opacity:e.opacity,props:{...e.props,richText:wi(""),growY:0,fontSizeAdjustment:0,url:""}});const c=n.getShape(l);if(!c)return;const d=n.getPointInParentSpace(c,E.Sub(t,E.Rot(_0.clone().mul(c.props.scale),r)));n.updateShape({id:l,type:"note",x:d.x,y:d.y}),i=n.getShape(l)}return Fme(n),i}const Lme=16;function Fme(n){const e=n.getSelectionPageBounds(),t=n.getViewportPageBounds();if(e&&!t.contains(e)){const r=e.clone().expandBy(Lme/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 dP;let zme=(dP=class extends Ne{constructor(){super(...arguments);O(this,"dragged",!1);O(this,"info",{});O(this,"markId","");O(this,"shape",{})}onEnter(){const{editor:t}=this,r=Dt();this.markId=t.markHistoryStoppingPoint(`creating_note:${r}`);const s=this.editor.inputs.originPagePoint.clone(),i=$me(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);i&&s.sub(i),this.shape=Bme(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)}},O(dP,"id","pointing"),dP);function $me(n,e,t){let r=G9/n.getZoomLevel(),s;for(const i of X9(n,0,t,0)){const o=E.Sub(e,i),a=o.len();a<r&&(r=a,s=o)}return s}function Bme(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,i=Ji(new E(r.x-s.width/2,r.y-s.height/2),n);return n.updateShapes([{id:e,type:"note",x:i.x,y:i.y}]),n.getShape(e)}class qE extends Ne{constructor(){super(...arguments);O(this,"shapeType","note")}static children(){return[Rme,zme]}}O(qE,"id","note"),O(qE,"initial","idle");function Ume(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 ba=WL(Ume,32);var hP;let Hme=(hP=class extends Ne{onPointerMove(e){switch(e.target){case"shape":case"canvas":ba(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){ba.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")}},O(hP,"id","idle"),hP);var fP;let Kme=(fP=class extends Ne{constructor(){super(...arguments);O(this,"shape");O(this,"markId","");O(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:i,currentPagePoint:o}=r.inputs,a=Math.abs(i.x-o.x),c=Math.sqrt(r.getInstanceState().isCoarsePointer?r.options.coarseDragDistanceSquared:r.options.dragDistanceSquared)*6/r.getZoomLevel();if(a>c){const d=Dt();this.markId=r.markHistoryStoppingPoint(`creating_text:${d}`);const f=this.createTextShape(d,i,!1,a);if(!f){this.cancel();return}this.shape=r.getShape(f),r.select(d),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=Dt(),{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,i){this.editor.createShape({id:t,type:"text",x:r.x,y:r.y,props:{richText:wi(""),autoSize:s,w:i,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(t);if(!o){this.cancel();return}const a=this.editor.getShapePageBounds(o),l=new E;if(s)switch(o.props.textAlign){case"start":{l.x=0;break}case"middle":{l.x=-a.width/2;break}case"end":{l.x=-a.width;break}}else l.x=0;if(l.y=-a.height/2,ps(o.parentId)){const f=this.editor.getShapeParentTransform(o);l.rot(-f.rotation())}const c=o.x+l.x,d=o.y+l.y;if(this.editor.getInstanceState().isGridMode){const f=new E(c,d),p=Ji(f,this.editor),m=E.Sub(f,p);this.editor.updateShape({...o,x:c-m.x,y:d-m.y})}else this.editor.updateShape({...o,x:c,y:d});return o}},O(fP,"id","pointing"),fP);class GE extends Ne{constructor(){super(...arguments);O(this,"shapeType","text")}static children(){return[Hme,Kme]}}O(GE,"id","text"),O(GE,"initial","idle");const Wme=[GE,py,WE,qE,VE,KE,HE,gy],Vme=He.forwardRef(function({isEditing:e,text:t,handleFocus:r,handleChange:s,handleKeyDown:i,handleBlur:o,handleInputPointerDown:a,handleDoubleClick:l},c){const d=f=>{s({plaintext:f.target.value})};return g.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,disabled:!e,readOnly:!e,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:t,onFocus:r,onChange:d,onKeyDown:f=>i(f.nativeEvent),onBlur:o,onTouchEnd:Xt,onContextMenu:e?Xt:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:tt})});function qme(n,e,t,r){if((n==="start-legacy"||n==="end-legacy")&&t.length!==0){const s=ye.From(t[0].box);for(const{box:i}of t)s.union(i);if(n==="start-legacy")return(r-2*e-s.width)/2;if(n==="end-legacy")return-(r-2*e-s.width)/2}}function J9(n){return n==="start-legacy"||n==="middle-legacy"||n==="end-legacy"}function Gme(n,e,t){const r=Q9(n),s=r.isEditing,i=te(),o=P.useRef(null),a=(t||"").trim().length===0;P.useEffect(()=>{function d(f){var p,m;f.shapeId===n&&((m=(p=o.current)==null?void 0:p.select)==null||m.call(p))}return i.on("select-all-text",d),()=>{i.off("select-all-text",d)}},[i,n,s]),P.useEffect(()=>{var d,f,p,m;s&&(document.activeElement!==o.current&&((d=o.current)==null||d.focus()),i.getInstanceState().isCoarsePointer&&((f=o.current)==null||f.select()),Pt.isSafari&&((p=o.current)==null||p.blur(),(m=o.current)==null||m.focus()))},[i,s]);const l=P.useCallback(d=>{if(i.getEditingShapeId()===n)switch(d.key){case"Enter":{(d.ctrlKey||d.metaKey)&&i.complete();break}}},[i,n]),c=P.useCallback(({plaintext:d})=>{if(i.getEditingShapeId()!==n)return;const f=sv.normalizeText(d||"");i.updateShape({id:n,type:e,props:{text:f}})},[i,n,e]);return{rInput:o,handleKeyDown:l,handleChange:c,isEmpty:a,...r}}function Q9(n){const e=te(),t=ie("isEditing",()=>e.getEditingShapeId()===n,[e]),r=ie("isEditingAnything",()=>!!e.getEditingShapeId(),[e]),s=P.useCallback(i=>{e.dispatch({...Fs(i),type:"pointer",name:"pointer_down",target:"shape",shape:e.getShape(n)}),Xt(i)},[e,n]);return{handleFocus:Vf,handleBlur:Vf,handleInputPointerDown:s,handleDoubleClick:Xt,isEditing:t,isEditingAnything:r}}const Yme=He.memo(function({shapeId:e,type:t,text:r,labelColor:s,font:i,fontSize:o,lineHeight:a,align:l,verticalAlign:c,wrap:d,isSelected:f,padding:p=0,onKeyDown:m,classNamePrefix:y,style:v,textWidth:x,textHeight:b}){const{rInput:C,isEmpty:I,isEditing:_,isEditingAnything:T,...A}=Gme(e,t,r),R=sv.normalizeTextForDom(r||""),j=R.length>0,K=J9(l);if(!_&&!j)return null;const U=y||"tl-text";return g.jsx("div",{className:`${U}-label tl-text-wrapper tl-plain-text-wrapper`,"data-font":i,"data-align":l,"data-hastext":!I,"data-isediting":_,"data-iseditinganything":T,"data-textwrap":!!d,"data-isselected":f,style:{justifyContent:l==="middle"||K?"center":l,alignItems:c==="middle"?"center":c,padding:p,...v},children:g.jsxs("div",{className:`${U}-label__inner tl-text-content__wrapper`,style:{fontSize:o,lineHeight:Math.floor(o*a)+"px",minHeight:Math.floor(o*a)+"px",minWidth:Math.ceil(x||0),color:s,width:x?Math.ceil(x):void 0,height:b?Math.ceil(b):void 0},children:[g.jsx("div",{className:`${U} tl-text tl-text-content`,dir:"auto",children:R.split(`
450
+ `).map((J,z)=>g.jsx("div",{dir:"auto",children:J},z))}),(T||f)&&g.jsx(Vme,{ref:C,text:r,isEditing:_,shapeId:e,...A,handleKeyDown:m??A.handleKeyDown})]})})});function Ei(){return za({isDarkMode:Up()})}function aT(n){return{key:`${Aa.id}:${n}`,async getElement(){return n!=="pattern"?null:g.jsx(Xme,{})}}}function Xme(){const n=cT(),e=pu(),t=Ei(),r=8/12;return g.jsxs(g.Fragment,{children:[g.jsxs("mask",{id:e,children:[g.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),g.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[g.jsx("line",{x1:r*1,y1:r*3,x2:r*3,y2:r*1}),g.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),g.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),g.jsx("pattern",{id:n(1,t.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:g.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:t.solid,mask:`url(#${e})`})})]})}function lT(){return{key:`${Aa.id}:pattern`,component:eye}}const Cf=8,tL=(n,e,t)=>new Promise((r,s)=>{const i=Cf*e*n,o=document.createElement("canvas");o.width=i,o.height=i;const a=o.getContext("2d");if(!a)return;a.fillStyle=t?aS.darkMode.solid:aS.lightMode.solid,a.fillRect(0,0,i,i),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*e*n;const l=8/12,c=d=>d*e*n;a.beginPath(),a.moveTo(c(l*1),c(l*3)),a.lineTo(c(l*3),c(l*1)),a.moveTo(c(l*5),c(l*7)),a.lineTo(c(l*7),c(l*5)),a.moveTo(c(l*9),c(l*11)),a.lineTo(c(l*11),c(l*9)),a.stroke(),o.toBlob(d=>{!d||xn.throwToBlob.get()?s():r(d)})}),nL=(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 HC=null;function Zme(){return HC||(HC={white:nL([1,1],n=>{n.fillStyle="#f8f9fa",n.fillRect(0,0,1,1)}),black:nL([1,1],n=>{n.fillStyle="#212529",n.fillRect(0,0,1,1)})}),HC}function e7(n){return Math.ceil(Math.log2(Math.max(1,n)))}function cT(){const n=Yi("hash_pattern");return P.useCallback((e,t)=>{const r=e7(e);return OI(n,`${t}_${r}`)},[n])}function t7(n){const e=[],r=e7(n);for(let s=0;s<=r;s++)e.push(Math.pow(2,s));return e}function Jme(n){const e=Zme();return t7(n).flatMap(t=>[{zoom:t,url:e.white,theme:"light"},{zoom:t,url:e.black,theme:"dark"}])}function Qme(){const n=te(),e=ie("devicePixelRatio",()=>n.getInstanceState().devicePixelRatio,[n]),t=ie("maxZoom",()=>Math.ceil(Jn(n.getCameraOptions().zoomSteps)),[n]),[r,s]=P.useState(!1),[i,o]=P.useState(()=>Jme(t)),a=cT();return P.useEffect(()=>{const c=Promise.all(t7(t).flatMap(f=>[tL(e,f,!1).then(p=>({zoom:f,theme:"light",url:URL.createObjectURL(p)})),tL(e,f,!0).then(p=>({zoom:f,theme:"dark",url:URL.createObjectURL(p)}))]));let d=!1;return c.then(f=>{d||(o(f),s(!0))}),()=>{d=!0,s(!1),c.then(f=>{for(const{url:p}of f)URL.revokeObjectURL(p)})}},[e,t]),{defs:g.jsx(g.Fragment,{children:i.map(c=>{const d=a(c.zoom,c.theme);return g.jsx("pattern",{id:d,width:Cf,height:Cf,patternUnits:"userSpaceOnUse",children:g.jsx("image",{href:c.url,width:Cf,height:Cf})},d)})}),isReady:r}}function eye(){const n=te(),e=P.useRef(null),{defs:t,isReady:r}=Qme();return P.useEffect(()=>{if(r&&Pt.isSafari){const s=n7(e.current);s&&n.timers.requestAnimationFrame(()=>{s.style.display="none",n.timers.requestAnimationFrame(()=>{s.style.display=""})})}},[n,r]),g.jsx("g",{ref:e,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function n7(n){return n.classList.contains("tl-html-layer")?n:n.parentElement?n7(n.parentElement):null}const yr=He.memo(function({theme:e,d:t,color:r,fill:s,scale:i}){switch(s){case"none":return null;case"solid":return g.jsx("path",{fill:e[r].semi,d:t});case"semi":return g.jsx("path",{fill:e.solid,d:t});case"fill":return g.jsx("path",{fill:e[r].fill,d:t});case"pattern":return g.jsx(tye,{theme:e,color:r,fill:s,d:t,scale:i})}});function tye({d:n,color:e,theme:t}){const r=te(),s=Fp(),i=ie("zoomLevel",()=>r.getZoomLevel(),[r]),o=cT(),a=r.getZoomLevel()<=.18;return g.jsxs(g.Fragment,{children:[g.jsx("path",{fill:t[e].pattern,d:n}),g.jsx("path",{fill:s?`url(#${o(1,t.id)})`:a?t[e].semi:`url(#${o(i,t.id)})`,d:n})]})}function nye(n){return n.replace(/\s/g," ")}function YE(n,e,t){const{padding:r=0}=t;if(e.length===0)return null;const s=ye.From(e[0].box);for(const{box:c}of e)s.union(c);const i=r+(t.offsetX??0),o=(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 l=[];for(const{text:c,box:d}of e)a!==null&&d.y>a&&l.push(g.jsx("tspan",{alignmentBaseline:"mathematical",x:i,y:d.y+o,children:`
451
+ `},l.length)),l.push(g.jsx("tspan",{alignmentBaseline:"mathematical",x:d.x+i,y:d.y+o,unicodeBidi:"plaintext",children:nye(c)},l.length)),a=d.y;return g.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:l})}function rye({fontSize:n,font:e,align:t,verticalAlign:r,text:s,labelColor:i,bounds:o,padding:a=16,stroke:l=!0}){const c=te(),d=Ei(),f={fontSize:n,fontFamily:o4[e],textAlign:t,verticalTextAlign:r,width:Math.ceil(o.width),height:Math.ceil(o.height),padding:a,lineHeight:ir.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:i,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(s,f),m=qme(t,a,p,o.width);m&&(f.offsetX=m),f.offsetX+=o.x,f.offsetY+=o.y;const y=YE(c,p,f);let v=null;return l&&(f.fill=d.background,f.stroke=d.background,f.strokeWidth=2,v=YE(c,p,f)),g.jsxs(g.Fragment,{children:[v,y]})}const sye=xI("arrow label size",(n,e)=>{n.fonts.trackFontsForShape(e);const t=Oo(n,e);let r=0,s=0;const i=t.isStraight?new wa({start:E.From(t.start.point),end:E.From(t.end.point)}):new wd({center:E.Cast(t.handleArc.center),start:E.Cast(t.start.point),end:E.Cast(t.end.point),sweepFlag:t.bodyArc.sweepFlag,largeArcFlag:t.bodyArc.largeArcFlag});if(e.props.text.trim()){const o=i.bounds,a=XE(e),{w:l,h:c}=n.textMeasure.measureText(e.props.text,{...ir,fontFamily:Da[e.props.font],fontSize:a,maxWidth:null});r=l,s=c;let d=!1;if(o.width>o.height?(r=Math.max(Math.min(l,64),Math.min(o.width-64,l)),d=!0):r>16*a&&(r=16*a,d=!0),d){const{w:f,h:p}=n.textMeasure.measureText(e.props.text,{...ir,fontFamily:Da[e.props.font],fontSize:a,maxWidth:r});r=f,s=p}}return new E(r,s).addScalar(q_*2*e.props.scale)},{areRecordsEqual:(n,e)=>n.props===e.props});function uT(n,e){return e.props.text.trim()===""?new E(0,0).addScalar(q_*2*e.props.scale):sye.get(n,e.id)??new E(0,0)}function r7(n){const e=Er[n.props.size];return(Spe+(e-Er.s)*2+(e===Er.xl?20:0))*n.props.scale}function iye(n,e,t){const r=uT(n,e),s=r7(e),i=E.Nudge(t.start.point,t.end.point,s),o=E.Nudge(t.end.point,t.start.point,s),a=UI(i,o,ye.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;E.Dist2(l,i)>E.Dist2(c,i)&&([c,l]=a);const d=i.add(E.Sub(t.middle,l)),f=o.add(E.Sub(t.middle,c)),p=E.Dist(t.start.point,d)/t.length,m=E.Dist(t.start.point,f)/t.length;return{start:p,end:m}}function oye(n,e,t){const r=uT(n,e),s=r7(e),i=Math.sign(e.props.bend),o=s/t.handleArc.radius*i,a=E.Angle(t.bodyArc.center,t.start.point)-o,l=E.Angle(t.bodyArc.center,t.end.point)+o,c=Wc(t.bodyArc.center,t.bodyArc.radius,a),d=Wc(t.bodyArc.center,t.bodyArc.radius,l),f=[],p=sL(t.bodyArc.center,t.bodyArc.radius,a,l,i,ye.FromCenter(c,r).corners);f.push(new vn({points:ye.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const m=sL(t.bodyArc.center,t.bodyArc.radius,a,l,i,ye.FromCenter(d,r).corners);f.push(new vn({points:ye.FromCenter(d,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const R of[...p??[],...m??[],c,d])f.push(new e_({x:R.x-3,y:R.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const y=(p&&iL(t.start.point,p))??t.middle,v=(m&&iL(t.end.point,m))??t.middle,x=E.Angle(t.bodyArc.center,t.start.point),b=E.Angle(t.bodyArc.center,t.end.point),C=E.Angle(t.bodyArc.center,y),I=E.Angle(t.bodyArc.center,v);if(bl(x,C,i)>bl(x,I,i))return{start:.5,end:.5,dbg:f};const _=bl(x,b,i),T=bl(x,C,i)/_,A=bl(x,I,i)/_;return{start:T,end:A,dbg:f}}function my(n,e){let t;const r=[],s=Oo(n,e),i={hasStartBinding:!!s.bindings.start,hasEndBinding:!!s.bindings.end,hasStartArrowhead:s.start.arrowhead!=="none",hasEndArrowhead:s.end.arrowhead!=="none"};if(s.isStraight){const a=iye(n,e,s),l=rL(n,e,a,i);t=E.Lrp(s.start.point,s.end.point,l)}else{const a=oye(n,e,s);a.dbg&&r.push(...a.dbg);const l=rL(n,e,a,i),c=aye(E.Angle(s.bodyArc.center,s.start.point),E.Angle(s.bodyArc.center,s.end.point),Math.sign(e.props.bend),l);t=Wc(s.bodyArc.center,s.bodyArc.radius,c)}const o=uT(n,e);return{box:ye.FromCenter(t,o),debugGeom:r}}function rL(n,e,t,r){const{hasEndArrowhead:s,hasEndBinding:i,hasStartBinding:o,hasStartArrowhead:a}=r,l=a7(n,e);let c=Mn(e.props.labelPosition,a||o?t.start:0,s||i?t.end:1);const d=Math.min(.02,500/l*.02);return c=c>=.5-d&&c<=.5+d?.5:c,c}function sL(n,e,t,r,s,i){const o=uE(n,e,i),a=bl(t,r,s);return o==null?void 0:o.filter(l=>{const c=bl(t,E.Angle(n,l),s);return c>=0&&c<=a})}function iL(n,e){let t=null,r=-1/0;for(const s of e){const i=E.Dist2(n,s);i>r&&(t=s,r=i)}return t}function aye(n,e,t,r){const s=bl(n,e,t);return n+s*r*t*-1}function XE(n){return ype[n.props.size]*n.props.scale}function lye(n,e,t){const r=e==="end"?n.end.point:n.start.point,s=e==="end"?n.start.point:n.end.point,i=n.isStraight?E.Dist(s,r):Math.abs(n.bodyArc.length),o=Math.max(Math.min(i/5,t*3),t);let a;if(n.isStraight)a=E.Nudge(r,s,o);else{const l=vse(r,o,n.handleArc.center,n.handleArc.radius);a=e==="end"?n.handleArc.sweepFlag?l[0]:l[1]:n.handleArc.sweepFlag?l[1]:l[0]}return E.IsNaN(a)&&(a=n.start.point),{point:r,int:a}}function cye({point:n,int:e}){const t=E.RotWith(e,n,xt/6),r=E.RotWith(e,n,-xt/6);return`M ${t.x} ${t.y} L ${n.x} ${n.y} L ${r.x} ${r.y}`}function uye({point:n,int:e}){const t=E.RotWith(e,n,xt/6),r=E.RotWith(e,n,-xt/6);return`M ${t.x} ${t.y} L ${r.x} ${r.y} L ${n.x} ${n.y} Z`}function dye({point:n,int:e}){const t=E.Sub(e,n).div(2),r=E.Add(n,E.Rot(t,Ht)),s=E.Sub(n,E.Rot(t,Ht));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${s.x} ${s.y} Z`}function hye({point:n,int:e}){const t=E.Lrp(n,e,.45),r=E.Dist(t,n);return`M ${t.x-r},${t.y}
452
+ a ${r},${r} 0 1,0 ${r*2},0
453
+ a ${r},${r} 0 1,0 -${r*2},0 `}function fye({point:n,int:e}){const t=E.Lrp(n,e,.75),r=E.RotWith(t,n,xt/4),s=E.RotWith(t,n,-xt/4),i=E.Lrp(r,s,.5);return i.add(E.Sub(i,n)),`M ${i.x} ${i.y} L ${s.x} ${s.y} ${n.x} ${n.y} L ${r.x} ${r.y} Z`}function pye({int:n,point:e}){const t=E.Lrp(e,n,.85),r=E.Sub(t,e).div(2),s=E.Add(e,E.Rot(r,Ht)),i=E.Sub(e,E.Rot(r,Ht)),o=E.Add(t,E.Rot(r,Ht)),a=E.Sub(t,E.Rot(r,Ht));return`M ${s.x} ${s.y} L ${o.x} ${o.y} L ${a.x} ${a.y} L ${i.x} ${i.y} Z`}function gye({int:n,point:e}){const t=E.Sub(n,e).div(2),r=E.Add(e,E.Rot(t,Ht)),s=E.Sub(e,E.Rot(t,Ht));return`M ${r.x} ${r.y} L ${s.x} ${s.y}`}function iv(n,e,t){const r=e==="end"?n.end.arrowhead:n.start.arrowhead;if(r==="none")return;const s=lye(n,e,t);if(s){switch(r){case"bar":return gye(s);case"square":return pye(s);case"diamond":return fye(s);case"dot":return hye(s);case"inverted":return dye(s);case"arrow":return cye(s);case"triangle":return uye(s)}return""}}function mye(n){const{start:e,end:t,handleArc:{radius:r,largeArcFlag:s,sweepFlag:i}}=n;return`M${e.handle.x},${e.handle.y} A${r} ${r} 0 ${s} ${i} ${t.handle.x},${t.handle.y}`}function s7(n){const{start:e,end:t,bodyArc:{radius:r,largeArcFlag:s,sweepFlag:i}}=n;return`M${e.point.x},${e.point.y} A${r} ${r} 0 ${s} ${i} ${t.point.x},${t.point.y}`}function i7(n,e){return`M${n.x},${n.y}L${e.x},${e.y}`}function yye(n){return i7(n.start.handle,n.end.handle)}function o7(n){return i7(n.start.point,n.end.point)}class yy extends Xi{constructor(){super(...arguments);O(this,"_resizeInitialBindings",new Na)}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,r){if(r.type==="flip"){const s=ys(this.editor,t),{start:i,end:o}=s,{shapes:a=[]}=r;if(i&&!a.find(l=>l.id===i.toId)||o&&!a.find(l=>l.id===o.toId))return!1}return!0}getFontFaces(t){return t.props.text?[sT[`tldraw_${t.props.font}`].normal.normal]:Si}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=Oo(this.editor,t),s=[],i=r.isStraight?new wa({start:E.From(r.start.point),end:E.From(r.end.point)}):new wd({center:E.Cast(r.handleArc.center),start:E.Cast(r.start.point),end:E.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let o;if(t.props.text.trim()){const a=my(this.editor,t);s.push(...a.debugGeom),o=new zo({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new bi({children:[...o?[i,o]:[i],...s]})}getHandles(t){const r=Oo(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 i=r.id,o=ys(this.editor,t);if(i==="middle"){const{start:A,end:R}=bd(this.editor,t,o),j=E.Sub(R,A),K=E.Per(j),U=E.Med(R,A),J=E.Sub(U,K),z=E.Add(U,K),N=E.NearestPointOnLineSegment(J,z,r,!1);let L=E.Dist(N,U);return E.Clockwise(N,R,U)&&(L*=-1),{id:t.id,type:t.type,props:{bend:L}}}const a={id:t.id,type:"arrow",props:{}},l=o[i],d=o[i==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return uy(this.editor,t,i),a.props[i]={x:r.x,y:r.y},a;const f=this.editor.getShapePageTransform(t.id).applyToPoint(r),p=this.editor.getShapeAtPoint(f,{hitInside:!0,hitFrameInside:!0,margin:0,filter:A=>!A.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:A,binding:"arrow"})});if(!p){uy(this.editor,t,i);const A=Ji(new E(r.x,r.y),this.editor);return a.props[i]={x:A.x,y:A.y},a}const m=this.editor.getShapeGeometry(p),y=ye.ZeroFix(m.bounds),x=this.editor.getShapePageTransform(a.id).applyToPoint(r),b=this.editor.getPointInShapeSpace(p,x);let C=s;C||(!l||l&&p.id!==l.toId)&&(C=this.editor.inputs.pointerVelocity.len()<.5),s||(m.isClosed||(C=!0),d&&p.id===d.toId&&d.props.isPrecise&&(C=!0));const I={x:(b.x-y.minX)/y.width,y:(b.y-y.minY)/y.height};C&&E.Dist(b,y.center)<Math.max(4,Math.min(Math.min(y.width,y.height)*.15,16))/this.editor.getZoomLevel()&&(I.x=.5,I.y=.5);const _={terminal:i,normalizedAnchor:I,isPrecise:C,isExact:this.editor.inputs.altKey};sf(this.editor,t,p.id,_),this.editor.setHintingShapes([p.id]);const T=ys(this.editor,t);return T.start&&T.end&&T.start.toId===T.end.toId&&E.Equals(T.start.props.normalizedAnchor,T.end.props.normalizedAnchor)&&sf(this.editor,t,T.end.toId,{...T.end.props,normalizedAnchor:{x:T.end.props.normalizedAnchor.x+.05,y:T.end.props.normalizedAnchor.y}}),a}onTranslateStart(t){const r=ys(this.editor,t),s=bd(this.editor,t,r),i=this.editor.getShapePageTransform(t.id),o=this.editor.getSelectedShapeIds();if(!(r.start&&(o.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(o.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){aL.set(t,{pagePosition:i.applyToPoint(t),terminalBindings:Jd(s,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:i.applyToPoint(l)}:null})}),r.start&&(TS({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&TS({editor:this.editor,arrow:t,terminal:"end",useHandle:!0});for(const a of["start","end"]){const l=r[a];l&&this.editor.updateBinding({...l,props:{...l.props,isPrecise:!0}})}}}onTranslate(t,r){const s=aL.get(t);if(!s)return;const i=this.editor.getShapePageTransform(r.id),o=E.Sub(i.applyToPoint(r),s.pagePosition);for(const a of Object.values(s.terminalBindings)){if(!a)continue;const l=E.Add(a.pagePosition,E.Mul(o,.5)),c=this.editor.getShapeAtPoint(l,{hitInside:!0,hitFrameInside:!0,margin:0,filter:d=>!d.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:d,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const d=ye.ZeroFix(this.editor.getShapeGeometry(c).bounds),f=this.editor.getPointInShapeSpace(c,l),p={x:(f.x-d.minX)/d.width,y:(f.y-d.minY)/d.height};sf(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else uy(this.editor,r,a.binding.props.terminal)}}onResize(t,r){const{scaleX:s,scaleY:i}=r,o=this._resizeInitialBindings.get(t,()=>ys(this.editor,t)),a=bd(this.editor,t,o),{start:l,end:c}=Yt(t.props);let{bend:d}=t.props;o.start||(l.x=a.start.x*s,l.y=a.start.y*i),o.end||(c.x=a.end.x*s,c.y=a.end.y*i);const f=Math.abs(s),p=Math.abs(i),m=o!=null&&o.start?E.From(o.start.props.normalizedAnchor):null,y=o!=null&&o.end?E.From(o.end.props.normalizedAnchor):null;return s<0&&i>=0?(d!==0&&(d*=-1,d*=Math.max(f,p)),m&&(m.x=1-m.x),y&&(y.x=1-y.x)):s>=0&&i<0?(d!==0&&(d*=-1,d*=Math.max(f,p)),m&&(m.y=1-m.y),y&&(y.y=1-y.y)):s>=0&&i>=0?d!==0&&(d*=Math.max(f,p)):s<0&&i<0&&(d!==0&&(d*=Math.max(f,p)),m&&(m.x=1-m.x,m.y=1-m.y),y&&(y.x=1-y.x,y.y=1-y.y)),o.start&&m&&sf(this.editor,t,o.start.toId,{...o.start.props,normalizedAnchor:m.toJson()}),o.end&&y&&sf(this.editor,t,o.end.toId,{...o.end.props,normalizedAnchor:y.toJson()}),{props:{start:l,end:c,bend:d}}}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=Ei(),s=this.editor.getOnlySelectedShape(),i=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),o=Oo(this.editor,t);if(!(o!=null&&o.isValid))return null;const a=my(this.editor,t),l=t.id===this.editor.getOnlySelectedShapeId(),d=this.editor.getEditingShapeId()===t.id||t.props.text;return g.jsxs(g.Fragment,{children:[g.jsx($l,{style:{minWidth:50,minHeight:50},children:g.jsx(oL,{shape:t,shouldDisplayHandles:i&&(s==null?void 0:s.id)===t.id})}),d&&g.jsx(Yme,{shapeId:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:XE(t),lineHeight:ir.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w-q_*2*t.props.scale,isSelected:l,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(t){const r=s0(t.id),s=Yi(t.id+"_clip"),i=Oo(this.editor,t);if(!i)return null;const{start:o,end:a}=bd(this.editor,t,i==null?void 0:i.bindings),l=this.editor.getShapeGeometry(t),c=l.bounds,d=t.props.text.trim()?l.children[1]:null;if(E.Equals(o,a))return null;const f=Er[t.props.size]*t.props.scale,p=i.start.arrowhead&&iv(i,"start",f),m=i.end.arrowhead&&iv(i,"end",f),y=i.isStraight?o7(i):s7(i),v=p&&i.start.arrowhead!=="arrow"||m&&i.end.arrowhead!=="arrow"||!!d;if(r&&d)return g.jsx("rect",{x:ee(d.x),y:ee(d.y),width:d.w,height:d.h,rx:3.5*t.props.scale,ry:3.5*t.props.scale});const x=!(i.start.arrowhead==="none"||i.start.arrowhead==="arrow"),b=!(i.end.arrowhead==="none"||i.end.arrowhead==="arrow");return g.jsxs("g",{children:[v&&g.jsx("defs",{children:g.jsx(l7,{hasText:t.props.text.trim().length>0,bounds:c,labelBounds:d?d.getBounds():new ye(0,0,0,0),as:x&&p?p:"",ae:b&&m?m:""})}),g.jsxs("g",{style:{clipPath:v?`url(#${s})`:void 0,WebkitClipPath:v?`url(#${s})`:void 0},children:[v&&g.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),g.jsx("path",{d:y})]}),p&&g.jsx("path",{d:p}),m&&g.jsx("path",{d:m}),d&&g.jsx("rect",{x:ee(d.x),y:ee(d.y),width:d.w,height:d.h,rx:3.5,ry:3.5})]})}onEditEnd(t){const{id:r,type:s,props:{text:i}}=t;i.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:i.trimEnd()}}])}toSvg(t,r){r.addExportDef(aT(t.props.fill));const s=za(r),i=1/t.props.scale;return g.jsxs("g",{transform:`scale(${i})`,children:[g.jsx(oL,{shape:t,shouldDisplayHandles:!1}),g.jsx(rye,{fontSize:XE(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:s[t.props.labelColor].solid,bounds:my(this.editor,t).box.clone().expandBy(-4.25*t.props.scale),padding:0})]})}getCanvasSvgDefs(){return[lT(),{key:"arrow:dot",component:Sye},{key:"arrow:cross",component:vye}]}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:yt(t.props.scale,r.props.scale,s),start:{x:yt(t.props.start.x,r.props.start.x,s),y:yt(t.props.start.y,r.props.start.y,s)},end:{x:yt(t.props.end.x,r.props.end.x,s),y:yt(t.props.end.y,r.props.end.y,s)},bend:yt(t.props.bend,r.props.bend,s),labelPosition:yt(t.props.labelPosition,r.props.labelPosition,s)}}}O(yy,"type","arrow"),O(yy,"props",l4),O(yy,"migrations",c4);function a7(n,e){const t=Oo(n,e);return t.isStraight?E.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const oL=Vn(function({shape:e,shouldDisplayHandles:t}){const r=te(),s=Ei(),i=Oo(r,e),o=ye.ZeroFix(r.getShapeGeometry(e).bounds),a=ys(r,e),l=ie("force solid",()=>r.getZoomLevel()<.2,[r]),c=Yi(e.id+"_clip"),d=Yi("arrowhead-dot"),f=Yi("arrowhead-cross");if(!(i!=null&&i.isValid))return null;const p=Er[e.props.size]*e.props.scale,m=i.start.arrowhead&&iv(i,"start",p),y=i.end.arrowhead&&iv(i,"end",p),v=i.isStraight?o7(i):s7(i);let x=null;if(t){const A=2/r.getZoomLevel(),{strokeDasharray:R,strokeDashoffset:j}=Bi(a7(r,e),A,{end:"skip",start:"skip",lengthRatio:2.5});x=a.start||a.end?g.jsx("path",{className:"tl-arrow-hint",d:i.isStraight?yye(i):mye(i),strokeDasharray:R,strokeDashoffset:j,strokeWidth:A,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?`url(#${f})`:`url(#${d})`:"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?`url(#${f})`:`url(#${d})`:"",opacity:.16}):null}const{strokeDasharray:b,strokeDashoffset:C}=Bi(i.isStraight?i.length:Math.abs(i.bodyArc.length),p,{style:e.props.dash,forceSolid:l}),I=my(r,e),_=!(i.start.arrowhead==="none"||i.start.arrowhead==="arrow"),T=!(i.end.arrowhead==="none"||i.end.arrowhead==="arrow");return g.jsxs(g.Fragment,{children:[g.jsx("defs",{children:g.jsx("clipPath",{id:c,children:g.jsx(l7,{hasText:e.props.text.trim().length>0,bounds:o,labelBounds:I.box,as:_&&m?m:"",ae:T&&y?y:""})})}),g.jsxs("g",{fill:"none",stroke:s[e.props.color].solid,strokeWidth:p,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[x,g.jsxs("g",{style:{clipPath:`url(#${c})`,WebkitClipPath:`url(#${c})`},children:[g.jsx("rect",{x:ee(o.minX-100),y:ee(o.minY-100),width:ee(o.width+200),height:ee(o.height+200),opacity:0}),g.jsx("path",{d:v,strokeDasharray:b,strokeDashoffset:C})]}),m&&_&&e.props.fill!=="none"&&g.jsx(yr,{theme:s,d:m,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),y&&T&&e.props.fill!=="none"&&g.jsx(yr,{theme:s,d:y,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),m&&g.jsx("path",{d:m}),y&&g.jsx("path",{d:y})]})]})});function l7({hasText:n,bounds:e,labelBounds:t,as:r,ae:s}){const i=`M${ee(e.minX-100)},${ee(e.minY-100)} h${e.width+200} v${e.height+200} h-${e.width+200} Z`,o=`M${ee(t.minX)},${ee(t.minY)} v${t.height} h${t.width} v-${t.height} Z`;return g.jsx("path",{d:`${i}${n?o:""}${r}${s}`})}const aL=new WeakMap;function Sye(){const n=Yi("arrowhead-dot");return g.jsx("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:g.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function vye(){const n=Yi("arrowhead-cross");return g.jsxs("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[g.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),g.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const lL="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 Gd({url:n}){const e=te(),t=ie("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return g.jsx("a",{className:ze("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t}),href:n,target:"_blank",rel:"noopener noreferrer",onPointerDown:Xt,onPointerUp:Xt,title:n,draggable:!1,children:g.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${lL}") center 100% / 100% no-repeat`,WebkitMask:`url("${lL}") center 100% / 100% no-repeat`}})})}const cL="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",xye=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function ov(n){return xye.map(t=>{const{offsetX:r,offsetY:s,blur:i,spread:o,color:a}=t,l=new E(r,s),{x:c,y:d}=l.rot(-n);return`${c}px ${d}px ${i}px ${o}px ${a}`}).join(", ")}const wye=300,c7=320,bye=46,Cye=101;class Sy extends uh{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:wye,h:c7,assetId:null}}component(e){return g.jsx(Pye,{shape:e,util:this})}indicator(e){return g.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h),rx:"6",ry:"6"})}onBeforeCreate(e){return uL(this.editor,e)}onBeforeUpdate(e,t){if(e.props.url!==t.props.url)if(Ks.isValid(t.props.url))kye(this.editor,t);else return{...t,props:{...t.props,url:e.props.url}};if(e.props.assetId!==t.props.assetId)return uL(this.editor,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:yt(e.props.w,t.props.w,r),h:yt(e.props.h,t.props.h,r)}}}O(Sy,"type","bookmark"),O(Sy,"props",g4),O(Sy,"migrations",m4);function Pye({shape:n,util:e}){const t=n.props.assetId?e.editor.getAsset(n.props.assetId):null,r=!!Fp()&&Pt.isSafari,s=e.editor.getShapePageTransform(n).rotation(),i=Eye(n),[o,a]=P.useState(!0),l=()=>a(!1);return g.jsx(jl,{children:g.jsxs("div",{className:ze("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:ov(s),maxHeight:n.props.h},children:[(!t||t.props.image)&&g.jsxs("div",{className:"tl-bookmark__image_container",children:[t?g.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)||""}):g.jsx("div",{className:"tl-bookmark__placeholder"}),(t==null?void 0:t.props.image)&&g.jsx(Gd,{url:n.props.url})]}),g.jsxs("div",{className:"tl-bookmark__copy_container",children:[t!=null&&t.props.title?g.jsx("h2",{className:"tl-bookmark__heading",children:hme(t.props.title)}):null,t!=null&&t.props.description&&(t!=null&&t.props.image)?g.jsx("p",{className:"tl-bookmark__description",children:t.props.description}):null,g.jsxs("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Xt,onPointerUp:Xt,onClick:Xt,children:[o&&(t!=null&&t.props.favicon)?g.jsx("img",{className:"tl-bookmark__favicon",src:t==null?void 0:t.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:l,alt:`favicon of ${i}`}):g.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${cL}") center 100% / 100% no-repeat`,WebkitMask:`url("${cL}") center 100% / 100% no-repeat`}}),g.jsx("span",{children:i})]})]})]})})}function uL(n,e){const t=e.props.assetId?n.getAsset(e.props.assetId):null;let r=c7;return t&&(t.props.image||(t.props.title?r=Cye:r=bye)),{...e,props:{...e.props,h:r}}}const Eye=n=>{try{return new URL(n.props.url).hostname.replace(/^www\./,"")}catch{return n.props.url}};function kye(n,e){const{url:t}=e.props,r=zl.createId(mk(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}}]),Iye(n,e))}const Iye=cv(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 au(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${Ct(r)}L${Ct(s)}`;let i="";for(let o=2,a=t-1;o<a;o++)r=n[o].point,s=n[o+1].point,i+=gs(r,s);return e?`M${gs(n[0].point,n[1].point)}Q${Ct(n[1].point)}${gs(n[1].point,n[2].point)}T${i}${gs(n[t-1].point,n[0].point)}${gs(n[0].point,n[1].point)}Z`:`M${Ct(n[0].point)}Q${Ct(n[1].point)}${gs(n[1].point,n[2].point)}${n.length>3?"T":""}${i}L${Ct(n[t-1].point)}`}function _ye(n,e={}){const{start:t={},end:r={}}=e,{cap:s=!0}=t,{cap:i=!0}=r;nt(!t.taper&&!r.taper,"cap taper not supported here"),nt(!t.easing&&!r.easing,"cap easing not supported here"),nt(s&&i,"cap must be true");const o=Uo(n,e);k0(o,e);const a=Tye(o);let l="";for(const c of a)l+=Aye(c,e);return l}function Tye(n){if(n.length<=2)return[n];const e=[];let t=[n[0]],r=E.Sub(n[1].point,n[0].point).uni(),s,i,o,a,l;for(let c=1,d=n.length;c<d-1;c++){if(o=n[c-1],a=n[c],l=n[c+1],s=E.Sub(l.point,a.point).uni(),i=E.Dpr(r,s),r=s,i<-.8){const f={...a,point:a.input};t.push(f),e.push(KC(t)),t=[f];continue}if(t.push(a),!(i>.7)&&(E.Dist2(o.point,a.point)+E.Dist2(a.point,l.point))/((o.radius+a.radius+l.radius)/3)**2<1.5){t.push(a),e.push(KC(t)),t=[a];continue}}return t.push(n[n.length-1]),e.push(KC(t)),e}function KC(n){const e=n[0];let t;for(;n.length>2&&(t=n[1],E.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],E.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:E.Sub(n[0].point,n[1].point).uni()},n[n.length-1]={...n[n.length-1],vector:E.Sub(n[n.length-2].point,n[n.length-1].point).uni()}),n}function Mye(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 Aye(n,e={}){if(n.length===0)return"";if(n.length===1)return Mye(n[0].point.x,n[0].point.y,n[0].radius);const{left:t,right:r}=w9(n,e);r.reverse();let s=`M${Ct(t[0])}T`;for(let i=1;i<t.length;i++)s+=gs(t[i-1],t[i]);{const i=n[n.length-1],o=i.radius,a=i.vector.clone().per().neg(),l=E.Add(i.point,E.Mul(a,o)),c=E.Add(i.point,E.Mul(a,-o));s+=`${Ct(l)}A${ee(o)},${ee(o)} 0 0 1 ${Ct(c)}T`}for(let i=1;i<r.length;i++)s+=gs(r[i-1],r[i]);{const i=n[0],o=i.radius,a=i.vector.clone().per(),l=E.Add(i.point,E.Mul(a,o)),c=E.Add(i.point,E.Mul(a,-o));s+=`${Ct(l)}A${ee(o)},${ee(o)} 0 0 1 ${Ct(c)}Z`}return s}const u7=(n,e,t)=>{const r=[],s=[];n.forEach(c=>r.push(...c.points)),e.forEach(c=>s.push(...c.points));const i=Math.max(r.length,s.length),o=[],a=[];for(let c=0;c<i;c++)o.push(r[c]||r[r.length-1]),a.push(s[c]||s[s.length-1]);return[{type:"free",points:o.map((c,d)=>{let f=.5;return a[d].z!==void 0&&c.z!==void 0&&(f=yt(c.z,a[d].z,t)),{x:yt(c.x,a[d].x,t),y:yt(c.y,a[d].y,t),z:f}})}]},Oye=n=>n*.65+RG(n*xt/2)*.35,Rye=n=>({size:n,thinning:.5,streamline:Dd(n,[9,16],[.64,.74],!0),smoothing:.62,easing:$n.easeOutSine,simulatePressure:!0}),Dye=n=>({size:1+n*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Oye}),dL=n=>({size:n,thinning:0,streamline:Dd(n,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:$n.linear}),jye=n=>({size:n,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:$n.linear});function dT({strokeWidth:n,showAsComplete:e}){return{size:1+n,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:$n.easeOutSine,last:e}}function ZE(n,e,t,r){const s=n.isComplete||t;return r?n.isPen?{...jye(e),last:s}:{...dL(e),last:s}:n.dash==="draw"?n.isPen?{...Dye(e),last:s}:{...Rye(e),last:s}:{...dL(e),last:s}}function Yd(n){const e=[];for(const t of n)if(t.type==="free"||t.points.length<2)e.push(...t.points.map(E.Cast));else{const r=Math.max(4,Math.floor(E.Dist(t.points[0],t.points[1])/16));e.push(...E.PointsBetween(t.points[0],t.points[1],r))}return e}function Nye(n,e,t){return{draw:"none",solid:"none",dotted:`${t} ${e*2}`,dashed:`${e*2} ${e*2}`}[n.props.dash]}class vy extends Xi{constructor(){super(...arguments);O(this,"options",{maxPointsPerShape:600})}hideResizeHandles(t){return WC(t)}hideRotateHandle(t){return WC(t)}hideSelectionBoundsFg(t){return WC(t)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(t){const r=Yd(t.props.segments),s=(Er[t.props.size]+1)*t.props.scale;if(t.props.segments.length===1){const o=ye.FromPoints(r);if(o.width<s*2&&o.height<s*2)return new e_({x:-s,y:-s,radius:s,isFilled:!0})}const i=Uo(r,ZE(t.props,s,t.props.isPen,!0)).map(o=>o.point);return t.props.isClosed?new vn({points:i,isFilled:t.props.fill!=="none"}):new oh({points:i})}component(t){return g.jsx($l,{children:g.jsx(hL,{shape:t})})}indicator(t){var d;const r=Yd(t.props.segments);let s=(Er[t.props.size]+1)*t.props.scale;!ie("force solid",()=>{const f=this.editor.getZoomLevel();return f<.5&&f<1.5/s},[this.editor,s])&&!t.props.isPen&&t.props.dash==="draw"&&r.length===1&&(s+=to(t.id)()*(s/6));const o=t.props.isComplete||((d=Jn(t.props.segments))==null?void 0:d.type)==="straight",a=ZE(t.props,s,o,!0),l=Uo(r,a),c=l.length>1?au(l,t.props.isClosed):d7(r[0],s);return g.jsx("path",{d:c})}toSvg(t,r){r.addExportDef(aT(t.props.fill));const s=1/t.props.scale;return g.jsx("g",{transform:`scale(${s})`,children:g.jsx(hL,{shape:t,zoomOverride:1})})}getCanvasSvgDefs(){return[lT()]}onResize(t,r){const{scaleX:s,scaleY:i}=r,o=[];for(const a of t.props.segments)o.push({...a,points:a.points.map(({x:l,y:c,z:d})=>({x:va(s*l),y:va(i*c),z:d}))});return{props:{segments:o}}}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return Er[t.props.size]*r/2*t.props.scale}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,segments:u7(t.props.segments,r.props.segments,s),scale:yt(t.props.scale,r.props.scale,s)}}}O(vy,"type","draw"),O(vy,"props",S4),O(vy,"migrations",v4);function d7(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 WC(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function hL({shape:n,zoomOverride:e}){var m;const t=Ei(),r=te(),s=Yd(n.props.segments),i=n.props.isComplete||((m=Jn(n.props.segments))==null?void 0:m.type)==="straight";let o=(Er[n.props.size]+1)*n.props.scale;const a=ie("force solid",()=>{const y=e??r.getZoomLevel();return y<.5&&y<1.5/o},[r,o,e]),l=ie("dot adjustment",()=>(e??r.getZoomLevel())<.2?0:.1,[r,e]);!a&&!n.props.isPen&&n.props.dash==="draw"&&s.length===1&&(o+=to(n.id)()*(o/6));const c=ZE(n.props,o,i,a);if(!a&&n.props.dash==="draw")return g.jsxs(g.Fragment,{children:[n.props.isClosed&&n.props.fill&&s.length>1?g.jsx(yr,{d:au(Uo(s,c),n.props.isClosed),theme:t,color:n.props.color,fill:n.props.isClosed?n.props.fill:"none",scale:n.props.scale}):null,g.jsx("path",{d:_ye(s,c),strokeLinecap:"round",fill:t[n.props.color].solid})]});const d=Uo(s,c),f=d.length<2,p=f?d7(s[0],0):au(d,n.props.isClosed);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{d:p,theme:t,color:n.props.color,fill:f||n.props.isClosed?n.props.fill:"none",scale:n.props.scale}),g.jsx("path",{d:p,strokeLinecap:"round",fill:f?t[n.props.color].solid:"none",stroke:t[n.props.color].solid,strokeWidth:o,strokeDasharray:f?"none":Nye(n,o,l),strokeDashoffset:"0"})]})}function Lye(n){if(typeof n!="string")throw new TypeError("Expected a string");return n.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Fye(n,e){const t=Je(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(h7(s.hostnames,r)){const i=s.fromEmbedUrl(e);if(i)return{definition:s,url:i,embedUrl:e}}}const zye=n=>n.split("*").map(e=>Lye(e)).join(".+"),h7=(n,e)=>!!n.find(t=>{const r=new RegExp(zye(t));return e.match(r)});function $ye(n,e){const t=Je(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(h7(s.hostnames,r)){const i=s.toEmbedUrl(e);if(i)return{definition:s,embedUrl:i,url:e}}}function Bye(n,e){try{return $ye(n,e)??Fye(n,e)}catch{return}}const Uye=n=>Object.entries(n).filter(([e,t])=>t).map(([e])=>e).join(" "),Sa=class Sa extends uh{static setEmbedDefinitions(e){Sa.embedDefinitions=e}getEmbedDefinitions(){return Sa.embedDefinitions}getEmbedDefinition(e){return Bye(Sa.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 i=(s==null?void 0:s.definition.minWidth)??200,o=(s==null?void 0:s.definition.minHeight)??200;if(r){const a=e.props.w/e.props.h;a>1?i*=a:o/=a}return r0(e,t,{minWidth:i,minHeight:o})}component(e){const t=Fp(),{w:r,h:s,url:i}=e.props,o=s0(e.id),a=this.getEmbedDefinition(i),l=ie("is hovering",()=>{const{editingShapeId:m,hoveredShapeId:y}=this.editor.getCurrentPageState();if(m&&y!==m){const v=this.editor.getShape(m);if(v&&this.editor.isShapeOfType(v,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(e).rotation();if(t)return g.jsx(jl,{className:"tl-embed-container",id:e.id,children:g.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:ov(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:(a==null?void 0:a.definition.backgroundColor)??"var(--color-background)",width:r,height:s}})});const d=o||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const m=a.url.split("/").pop();if(!m)throw Error("No gist id!");return g.jsx(jl,{className:"tl-embed-container",id:e.id,children:g.jsx(Hye,{id:m,width:ee(r),height:ee(s),isInteractive:d,pageRotation:c})})}const p=Uye({...The,...(a==null?void 0:a.definition.overridePermissions)??{}});return g.jsx(jl,{className:"tl-embed-container",id:e.id,children:a!=null&&a.definition?g.jsx("iframe",{className:"tl-embed",sandbox:p,src:a.embedUrl,width:ee(r),height:ee(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:d?"auto":"none",zIndex:d?"":"-1",boxShadow:ov(c),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 g.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:yt(e.props.w,t.props.w,r),h:yt(e.props.h,t.props.h,r)}}};O(Sa,"type","embed"),O(Sa,"props",x4),O(Sa,"migrations",w4),O(Sa,"embedDefinitions",N_);let av=Sa;function Hye({id:n,isInteractive:e,width:t,height:r,style:s,pageRotation:i}){if(!n.match(/^[0-9a-f]+$/))throw Error("No gist id!");return g.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:ov(i)},srcDoc:`
454
+ <html>
455
+ <head>
456
+ <base target="_blank">
457
+ </head>
458
+ <body>
459
+ <script src=${`https://gist.github.com/${n}.js`}><\/script>
460
+ <style type="text/css">
461
+ * { margin: 0px; }
462
+ table { height: 100%; background-color: red; }
463
+ .gist { background-color: none; height: 100%; }
464
+ .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
465
+ </style>
466
+ </body>
467
+ </html>`})}function JE(n,e){const s=((Fc(n.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(s)}const fL=new WeakMap;function pL(n,e,t){let r=fL.get(e.props);if(!r){const s=hT(e.props.name,"Frame")+"​",i=n.textMeasure.measureTextSpans(s,t),o=i[0],a=Jn(i);r=a.box.w+a.box.x-o.box.x,fL.set(e.props,r)}return new ye(0,-t.height,r,t.height)}function gL(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 f7(n,e,t){const r=t?"":"px",s=t?"":"deg";let i;switch(e){case 0:i="";break;case 3:i=`translate(${ee(n.props.w)}${r}, 0${r}) rotate(90${s})`;break;case 2:i=`translate(${ee(n.props.w)}${r}, ${ee(n.props.h)}${r}) rotate(180${s})`;break;case 1:i=`translate(0${r}, ${ee(n.props.h)}${r}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return i}const Kye=P.forwardRef(({id:n,name:e,isEditing:t},r)=>{const s=te(),i=P.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Xt(l),l.currentTarget.blur(),s.setEditingShape(null))},[s]),o=P.useCallback(l=>{const c=s.getShape(n);if(!c)return;const d=c.props.name,f=l.currentTarget.value.trim();d!==f&&s.updateShapes([{id:n,type:"frame",props:{name:f}}])},[n,s]),a=P.useCallback(l=>{const c=s.getShape(n);if(!c)return;const d=c.props.name,f=l.currentTarget.value;d!==f&&s.updateShapes([{id:n,type:"frame",props:{name:f}}])},[n,s]);return g.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[g.jsx("input",{className:"tl-frame-name-input",ref:r,disabled:!t,readOnly:!t,style:{display:t?void 0:"none"},value:e,autoFocus:!0,onKeyDown:i,onBlur:o,onChange:a}),hT(e,"Frame")+"​"]})}),Wye=P.memo(function({id:e,name:t,width:r,height:s}){const i=te(),{side:o,translation:a}=ie("shape rotation",()=>{const d=i.getShape(e);if(!d)return{side:0,translation:"translate(0, 0)"};const f=JE(i,d);return{side:f,translation:f7(d,f,!1)}},[i,e]),l=P.useRef(null),c=s0(e);return P.useEffect(()=>{const d=l.current;d&&c&&(d.focus(),d.select())},[l,c]),g.jsx("div",{className:"tl-frame-heading",style:{overflow:c?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(o===0||o===2?r:s)}px + var(--space-5))`,bottom:"100%",transform:`${a} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},children:g.jsx("div",{className:"tl-frame-heading-hit-area",children:g.jsx(Kye,{ref:l,id:e,name:t,isEditing:c})})})});function hT(n,e){return n.match(/^\s*$/)?e:n}class xy extends uh{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){const{editor:t}=this,r=t.getZoomLevel(),s=gL(e,"black"),i=pL(t,e,s),o=JE(t,e);let a,l,c,d;const{w:f,h:p}=i,m=Math.min(f,e.props.w*r),y=Math.min(p,e.props.h*r);switch(o){case 0:{a=-8/r,l=(-p-4)/r,c=(m+16)/r,d=p/r;break}case 1:{a=(-p-4)/r,d=(y+16)/r,l=e.props.h-d+8/r,c=p/r;break}case 2:{a=e.props.w-(m+8)/r,l=e.props.h+4/r,c=(y+16)/r,d=p/r;break}case 3:{a=e.props.w+4/r,d=(y+16)/r,l=-8/r,c=p/r;break}}return new bi({children:[new zo({width:e.props.w,height:e.props.h,isFilled:!1}),new zo({x:a,y:l,width:c,height:d,isFilled:!0,isLabel:!0})]})}getText(e){return e.props.name}component(e){const t=Ei(),r=ie("is creating this shape",()=>{const s=this.editor.getStateDescendant("select.resizing");if(!s||!s.getIsActive())return!1;const i=s==null?void 0:s.info;return i?i.isCreating&&this.editor.getOnlySelectedShapeId()===e.id:!1},[e.id]);return g.jsxs(g.Fragment,{children:[g.jsx($l,{children:g.jsx("rect",{className:ze("tl-frame__body",{"tl-frame__creating":r}),width:e.props.w,height:e.props.h,fill:t.solid,stroke:t.text})}),r?null:g.jsx(Wye,{id:e.id,name:e.props.name,width:e.props.w,height:e.props.h})]})}toSvg(e,t){const r=za({isDarkMode:t.isDarkMode}),s=JE(this.editor,e),i=f7(e,s,!0),o=gL(e,r.text),a=hT(e.props.name,"Frame")+"​",l=pL(this.editor,e,o),c=this.editor.textMeasure.measureTextSpans(a,o),d=YE(this.editor,c,o);return g.jsxs(g.Fragment,{children:[g.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),g.jsxs("g",{transform:i,children:[g.jsx("rect",{x:l.x-8,y:l.y-4,width:l.width+20,height:l.height,fill:r.background,rx:4,ry:4}),d]})]})}indicator(e){return g.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 r0(e,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:yt(e.props.w,t.props.w,r),h:yt(e.props.h,t.props.h,r)}}}O(xy,"type","frame"),O(xy,"props",b4),O(xy,"migrations",C4);function Vye(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var p7={exports:{}},VC={};/**
468
+ * @license React
469
+ * use-sync-external-store-shim.production.min.js
470
+ *
471
+ * Copyright (c) Facebook, Inc. and its affiliates.
472
+ *
473
+ * This source code is licensed under the MIT license found in the
474
+ * LICENSE file in the root directory of this source tree.
475
+ */var mL;function qye(){if(mL)return VC;mL=1;var n=He;function e(f,p){return f===p&&(f!==0||1/f===1/p)||f!==f&&p!==p}var t=typeof Object.is=="function"?Object.is:e,r=n.useState,s=n.useEffect,i=n.useLayoutEffect,o=n.useDebugValue;function a(f,p){var m=p(),y=r({inst:{value:m,getSnapshot:p}}),v=y[0].inst,x=y[1];return i(function(){v.value=m,v.getSnapshot=p,l(v)&&x({inst:v})},[f,m,p]),s(function(){return l(v)&&x({inst:v}),f(function(){l(v)&&x({inst:v})})},[f]),o(m),m}function l(f){var p=f.getSnapshot;f=f.value;try{var m=p();return!t(f,m)}catch{return!0}}function c(f,p){return p()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?c:a;return VC.useSyncExternalStore=n.useSyncExternalStore!==void 0?n.useSyncExternalStore:d,VC}p7.exports=qye();var fT=p7.exports;const Gye=(...n)=>e=>{n.forEach(t=>{typeof t=="function"?t(e):t&&(t.current=e)})},Yye=({contentComponent:n})=>{const e=fT.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getServerSnapshot);return He.createElement(He.Fragment,null,Object.values(e))};function Xye(){const n=new Set;let e={};return{subscribe(t){return n.add(t),()=>{n.delete(t)}},getSnapshot(){return e},getServerSnapshot(){return e},setRenderer(t,r){e={...e,[t]:Tz.createPortal(r.reactElement,r.element,t)},n.forEach(s=>s())},removeRenderer(t){const r={...e};delete r[t],e=r,n.forEach(s=>s())}}}class Zye extends He.Component{constructor(e){var t;super(e),this.editorContentRef=He.createRef(),this.initialized=!1,this.state={hasContentComponentInitialized:!!(!((t=e.editor)===null||t===void 0)&&t.contentComponent)}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){const e=this.props.editor;if(e&&!e.isDestroyed&&e.options.element){if(e.contentComponent)return;const t=this.editorContentRef.current;t.append(...e.options.element.childNodes),e.setOptions({element:t}),e.contentComponent=Xye(),this.state.hasContentComponentInitialized||(this.unsubscribeToContentComponent=e.contentComponent.subscribe(()=>{this.setState(r=>r.hasContentComponentInitialized?r:{hasContentComponentInitialized:!0}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent()})),e.createNodeViews(),this.initialized=!0}}componentWillUnmount(){const e=this.props.editor;if(!e||(this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent(),e.contentComponent=null,!e.options.element.firstChild))return;const t=document.createElement("div");t.append(...e.options.element.childNodes),e.setOptions({element:t})}render(){const{editor:e,innerRef:t,...r}=this.props;return He.createElement(He.Fragment,null,He.createElement("div",{ref:Gye(t,this.editorContentRef),...r}),(e==null?void 0:e.contentComponent)&&He.createElement(Yye,{contentComponent:e.contentComponent}))}}const Jye=P.forwardRef((n,e)=>{const t=He.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[n.editor]);return He.createElement(Zye,{key:t,innerRef:e,...n})}),Qye=He.memo(Jye);var eSe=function n(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){if(e.constructor!==t.constructor)return!1;var r,s,i;if(Array.isArray(e)){if(r=e.length,r!=t.length)return!1;for(s=r;s--!==0;)if(!n(e[s],t[s]))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(s of e.entries())if(!t.has(s[0]))return!1;for(s of e.entries())if(!n(s[1],t.get(s[0])))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(s of e.entries())if(!t.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(r=e.length,r!=t.length)return!1;for(s=r;s--!==0;)if(e[s]!==t[s])return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if(i=Object.keys(e),r=i.length,r!==Object.keys(t).length)return!1;for(s=r;s--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[s]))return!1;for(s=r;s--!==0;){var o=i[s];if(!(o==="_owner"&&e.$$typeof)&&!n(e[o],t[o]))return!1}return!0}return e!==e&&t!==t},tSe=Vye(eSe),g7={exports:{}},qC={};/**
476
+ * @license React
477
+ * use-sync-external-store-shim/with-selector.production.min.js
478
+ *
479
+ * Copyright (c) Facebook, Inc. and its affiliates.
480
+ *
481
+ * This source code is licensed under the MIT license found in the
482
+ * LICENSE file in the root directory of this source tree.
483
+ */var yL;function nSe(){if(yL)return qC;yL=1;var n=He,e=fT;function t(c,d){return c===d&&(c!==0||1/c===1/d)||c!==c&&d!==d}var r=typeof Object.is=="function"?Object.is:t,s=e.useSyncExternalStore,i=n.useRef,o=n.useEffect,a=n.useMemo,l=n.useDebugValue;return qC.useSyncExternalStoreWithSelector=function(c,d,f,p,m){var y=i(null);if(y.current===null){var v={hasValue:!1,value:null};y.current=v}else v=y.current;y=a(function(){function b(A){if(!C){if(C=!0,I=A,A=p(A),m!==void 0&&v.hasValue){var R=v.value;if(m(R,A))return _=R}return _=A}if(R=_,r(I,A))return R;var j=p(A);return m!==void 0&&m(R,j)?R:(I=A,_=j)}var C=!1,I,_,T=f===void 0?null:f;return[function(){return b(d())},T===null?void 0:function(){return b(T())}]},[d,f,p,m]);var x=s(c,y[0],y[1]);return o(function(){v.hasValue=!0,v.value=x},[x]),l(x),x},qC}g7.exports=nSe();var rSe=g7.exports;const sSe=typeof window<"u"?P.useLayoutEffect:P.useEffect;class iSe{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){const t=()=>{this.transactionNumber+=1,this.subscribers.forEach(s=>s())},r=this.editor;return r.on("transaction",t),()=>{r.off("transaction",t)}}}}function oSe(n){var e;const[t]=P.useState(()=>new iSe(n.editor)),r=rSe.useSyncExternalStoreWithSelector(t.subscribe,t.getSnapshot,t.getServerSnapshot,n.selector,(e=n.equalityFn)!==null&&e!==void 0?e:tSe);return sSe(()=>t.watch(n.editor),[n.editor,t]),P.useDebugValue(r),r}const aSe=!1,QE=typeof window>"u",lSe=QE||!!(typeof window<"u"&&window.next);class pT{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId="",this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(t=>t())}getInitialEditor(){return this.options.current.immediatelyRender===void 0?QE||lSe?null:this.createEditor():(this.options.current.immediatelyRender,this.options.current.immediatelyRender?this.createEditor():null)}createEditor(){const e={...this.options.current,onBeforeCreate:(...r)=>{var s,i;return(i=(s=this.options.current).onBeforeCreate)===null||i===void 0?void 0:i.call(s,...r)},onBlur:(...r)=>{var s,i;return(i=(s=this.options.current).onBlur)===null||i===void 0?void 0:i.call(s,...r)},onCreate:(...r)=>{var s,i;return(i=(s=this.options.current).onCreate)===null||i===void 0?void 0:i.call(s,...r)},onDestroy:(...r)=>{var s,i;return(i=(s=this.options.current).onDestroy)===null||i===void 0?void 0:i.call(s,...r)},onFocus:(...r)=>{var s,i;return(i=(s=this.options.current).onFocus)===null||i===void 0?void 0:i.call(s,...r)},onSelectionUpdate:(...r)=>{var s,i;return(i=(s=this.options.current).onSelectionUpdate)===null||i===void 0?void 0:i.call(s,...r)},onTransaction:(...r)=>{var s,i;return(i=(s=this.options.current).onTransaction)===null||i===void 0?void 0:i.call(s,...r)},onUpdate:(...r)=>{var s,i;return(i=(s=this.options.current).onUpdate)===null||i===void 0?void 0:i.call(s,...r)},onContentError:(...r)=>{var s,i;return(i=(s=this.options.current).onContentError)===null||i===void 0?void 0:i.call(s,...r)},onDrop:(...r)=>{var s,i;return(i=(s=this.options.current).onDrop)===null||i===void 0?void 0:i.call(s,...r)},onPaste:(...r)=>{var s,i;return(i=(s=this.options.current).onPaste)===null||i===void 0?void 0:i.call(s,...r)}};return new DQ(e)}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,t){return Object.keys(e).every(r=>["onCreate","onBeforeCreate","onDestroy","onUpdate","onTransaction","onFocus","onBlur","onSelectionUpdate","onContentError","onDrop","onPaste"].includes(r)?!0:r==="extensions"&&e.extensions&&t.extensions?e.extensions.length!==t.extensions.length?!1:e.extensions.every((s,i)=>{var o;return s===((o=t.extensions)===null||o===void 0?void 0:o[i])}):e[r]===t[r])}onRender(e){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&e.length===0?pT.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(e),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((r,s)=>r===e[s]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){const e=this.instanceId,t=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){t&&t.setOptions(this.options.current);return}t&&!t.isDestroyed&&(t.destroy(),this.instanceId===e&&this.setEditor(null))},1)}}function cSe(n={},e=[]){const t=P.useRef(n);t.current=n;const[r]=P.useState(()=>new pT(t)),s=fT.useSyncExternalStore(r.subscribe,r.getEditor,r.getServerSnapshot);return P.useDebugValue(s),P.useEffect(r.onRender(e)),oSe({editor:s,selector:({transactionNumber:i})=>n.shouldRerenderOnTransaction===!1?null:n.immediatelyRender&&i===0?0:i+1}),s}const m7=P.createContext({editor:null}),uSe=m7.Consumer;function dSe({children:n,slotAfter:e,slotBefore:t,editorContainerProps:r={},...s}){const i=cSe(s);return i?He.createElement(m7.Provider,{value:{editor:i}},t,He.createElement(uSe,null,({editor:o})=>He.createElement(Qye,{editor:o,...r})),n,e):null}const hSe=P.createContext({onDragStart:void 0}),fSe=()=>P.useContext(hSe);He.forwardRef((n,e)=>{const{onDragStart:t}=fSe(),r=n.as||"div";return He.createElement(r,{...n,ref:e,"data-node-view-wrapper":"",onDragStart:t,style:{whiteSpace:"normal",...n.style}})});const pSe=He.forwardRef(function({shapeId:e,isEditing:t,richText:r,handleFocus:s,handleChange:i,handleBlur:o,handleKeyDown:a,handleDoubleClick:l},c){const d=te(),f=pu("tip-tap-editor"),p=d.getTextOptions().tipTapConfig,m=P.useRef({selectAll:!1,caretPosition:null,time:Date.now()}),y=P.useRef(null),v=P.useCallback(_=>{var j;if(d.getEditingShapeId()!==e)return;const T=_.editor;d.setRichTextEditor(T),y.current=T;const{selectAll:A,caretPosition:R}=m.current;if(A){T.chain().focus().selectAll().run();return}if(R){const K=(j=T.view.posAtCoords({left:R.x,top:R.y}))==null?void 0:j.pos;K?T.chain().focus().setTextSelection(K).run():T.chain().focus().selectAll().run();return}d.timers.setTimeout(()=>T.commands.focus("end"),100)},[d,e]);P.useLayoutEffect(()=>{function _(A){A.shapeId===d.getEditingShapeId()&&(m.current={...m.current,selectAll:!0})}function T(A){A.shapeId===d.getEditingShapeId()&&(m.current={...m.current,caretPosition:A.point})}return d.on("select-all-text",_),d.on("place-caret",T),()=>{d.off("select-all-text",_),d.off("place-caret",T)}},[d,t]);const x=P.useCallback(_=>{i({richText:_.editor.state.doc.toJSON()})},[i]),b=P.useCallback((_,T)=>{T.key==="Tab"&&gSe(d,_,T),a(T)},[d,a]);if(!t||!p)return null;const{editorProps:C,...I}=p;return g.jsx("div",{id:f,ref:c,tabIndex:-1,"data-testid":"rich-text-area",className:"tl-rich-text tl-text tl-text-input",onContextMenu:t?Xt:void 0,onPointerDownCapture:Xt,onTouchEnd:Xt,onDragStart:tt,children:g.jsx("div",{className:"tl-rich-text",children:g.jsx(dSe,{autofocus:!0,editable:t,onUpdate:x,onFocus:s,onBlur:o,onCreate:v,immediatelyRender:!0,shouldRerenderOnTransaction:!1,editorProps:{handleKeyDown:b,handleDoubleClick:(_,T,A)=>l(A),...C},coreExtensionOptions:{clipboardTextSerializer:{blockSeparator:`
484
+ `}},...I,content:r})})})});function gSe(n,e,t){t.preventDefault();const r=n.getRichTextEditor();if(r!=null&&r.isActive("bulletList")||r!=null&&r.isActive("orderedList"))return;const{state:s,dispatch:i}=e,{$from:o,$to:a}=s.selection,l=t.shiftKey;let c=s.tr,d=a.end();for(;d>=o.start();){const p=s.doc.resolve(d).blockRange();if(!p)break;const m=p.start,y=p.end,v=s.doc.textBetween(m,y,`
485
+ `);let x=!1;s.doc.nodesBetween(m,y,b=>{if(b.type.name==="bulletList"||b.type.name==="orderedList")return x=!0,!1}),x||(l?v.startsWith(" ")&&(c=c.delete(m+1,m+2)):c=c.insertText(" ",m+1)),d=m-1}const f=s.selection.map(c.doc,c.mapping);c.setSelection(f),c.docChanged&&i(c)}function mSe(n,e,t){const r=Q9(n),s=r.isEditing,i=te(),o=P.useRef(null),a=t?br(i,t).length===0:!0;P.useEffect(()=>{var f;if(!s)return;const d=(f=o.current)==null?void 0:f.querySelector("[contenteditable]");d&&document.activeElement!==o.current&&d.focus()},[i,s]);const l=P.useCallback(d=>{if(i.getEditingShapeId()===n)switch(d.key){case"Enter":{(d.ctrlKey||d.metaKey)&&i.complete();break}}},[i,n]),c=P.useCallback(({richText:d})=>{i.getEditingShapeId()===n&&i.updateShape({id:n,type:e,props:{richText:d}})},[i,n,e]);return{rInput:o,handleKeyDown:l,handleChange:c,isEmpty:a,...r}}const gT=He.memo(function({shapeId:e,type:t,richText:r,labelColor:s,font:i,fontSize:o,lineHeight:a,align:l,verticalAlign:c,wrap:d,isSelected:f,padding:p=0,onKeyDown:m,classNamePrefix:y,style:v,textWidth:x,textHeight:b}){const C=te(),I=He.useRef(!1),{rInput:_,isEmpty:T,isEditing:A,isEditingAnything:R,...j}=mSe(e,t,r),K=P.useMemo(()=>{if(r)return iT(C,r)},[C,r]),U=ie("isSelectToolActive",()=>C.getCurrentToolId()==="select",[C]);jk("isDragging",()=>{C.getInstanceState(),I.current=C.inputs.isDragging},[C]);const J=J9(l),z=V=>{var X;if(V.target instanceof HTMLElement&&(V.target.tagName==="A"||V.target.closest("a"))){if(tt(V),!U)return;const W=((X=V.target.closest("a"))==null?void 0:X.getAttribute("href"))??"",$=G=>{G.name==="pointer_up"&&(I.current||window.open(W,"_blank","noopener, noreferrer"),C.off("event",$))};C.on("event",$)}},N=r?br(C,r).length>0:!1;if(!A&&!N)return null;const L=y||"tl-text";return g.jsx("div",{className:`${L}-label tl-text-wrapper tl-rich-text-wrapper`,"data-font":i,"data-align":l,"data-hastext":!T,"data-isediting":A,"data-iseditinganything":R,"data-textwrap":!!d,"data-isselected":f,style:{justifyContent:l==="middle"||J?"center":l,alignItems:c==="middle"?"center":c,padding:p,...v},children:g.jsxs("div",{className:`${L}-label__inner tl-text-content__wrapper`,style:{fontSize:o,lineHeight:Math.floor(o*a)+"px",minHeight:Math.floor(o*a)+"px",minWidth:Math.ceil(x||0),color:s,width:x?Math.ceil(x):void 0,height:b?Math.ceil(b):void 0},children:[g.jsx("div",{className:`${L} tl-text tl-text-content`,dir:"auto",children:r&&g.jsx("div",{className:"tl-rich-text","data-is-select-tool-active":U,dangerouslySetInnerHTML:{__html:K||""},onPointerDown:z,"data-iseditinganything":R})}),(R||f)&&g.jsx(pSe,{ref:_,richText:r,isEditing:A,shapeId:e,...j,handleKeyDown:m??j.handleKeyDown})]})})});function mT({bounds:n,richText:e,fontSize:t,font:r,align:s,verticalAlign:i,wrap:o,labelColor:a,padding:l}){const c=te(),d=iT(c,e),f=s==="middle"?"center":s==="start"?"start":"end",p=s==="middle"?"center":s==="start"?"flex-start":"flex-end",m=i==="middle"?"center":i==="start"?"flex-start":"flex-end",y={display:"flex",fontFamily:o4[r],height:"100%",justifyContent:p,alignItems:m,padding:`${l}px`},v={fontSize:`${t}px`,wrap:o?"wrap":"nowrap",color:a,lineHeight:ir.lineHeight,textAlign:f,width:"100%",wordWrap:"break-word",overflowWrap:"break-word",whiteSpace:"pre-wrap"};return g.jsx("foreignObject",{x:n.minX,y:n.minY,width:n.w,height:n.h,className:"tl-export-embed-styles tl-rich-text tl-rich-text-svg",children:g.jsx("div",{style:y,children:g.jsx("div",{dangerouslySetInnerHTML:{__html:d},style:v})})})}function SL(n,e){return n>e?(xt*(e/2)+(n-e))*2:(xt*(n/2)+(e-n))*2}function y7(n,e){return yT(n,e).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function ySe(n,e,t,r){const s=n/4,i=e/4,o=to(r),a=t*.75,l=C=>C.addXY(o()*a,o()*a),c=new E(n/2,e),d=new E(0,i*1.2),f=new E(n/2,i*.9),p=new E(n,i*1.2),m=l(new E(n/2,e)),y=l(new E(0,i*1.2)),v=l(new E(n/2,i*.9)),x=l(new E(n,i*1.2));return[new wr({start:c,cp1:new E(s*1.5,i*3),cp2:new E(0,i*2.5),end:d}),new wr({start:d,cp1:new E(0,-i*.32),cp2:new E(s*1.85,-i*.32),end:f}),new wr({start:f,cp1:new E(s*2.15,-i*.32),cp2:new E(n,-i*.32),end:p}),new wr({start:p,cp1:new E(n,i*2.5),cp2:new E(s*2.5,i*3),end:m}),new wr({start:m,cp1:new E(s*1.5,i*3),cp2:new E(0,i*2.5),end:y}),new wr({start:y,cp1:new E(0,-i*.32),cp2:new E(s*1.85,-i*.32),end:v}),new wr({start:v,cp1:new E(s*2.15,-i*.32),cp2:new E(n,-i*.32),end:x}),new wr({start:x,cp1:new E(n,i*2.5),cp2:new E(s*2.5,i*3),end:c})].map((C,I)=>C.getSvgPathData(I===0)).join(" ")+" Z"}function yT(n,e){const t=n/4,r=e/4;return[new wr({start:new E(n/2,e),cp1:new E(t*1.5,r*3),cp2:new E(0,r*2.5),end:new E(0,r*1.2)}),new wr({start:new E(0,r*1.2),cp1:new E(0,-r*.32),cp2:new E(t*1.85,-r*.32),end:new E(n/2,r*.9)}),new wr({start:new E(n/2,r*.9),cp1:new E(t*2.15,-r*.32),cp2:new E(n,-r*.32),end:new E(n,r*1.2)}),new wr({start:new E(n,r*1.2),cp1:new E(n,r*2.5),cp2:new E(t*2.5,r*3),end:new E(n/2,e)})]}function SSe(n){return{size:1+n,thinning:.25,end:{taper:n},start:{taper:n},streamline:0,smoothing:1,simulatePressure:!1}}function vSe(n,e,t,r){const s=to(n),i=e/2,o=t/2,a=Q3(i,o),l=[],c=Rt*s(),d=Rt+Ht/2+Math.abs(s())*Ht,f=Math.max(16,a/10);for(let p=0;p<f;p++){const m=p/(f-1),y=c+m*d,v=Math.cos(y),x=Math.sin(y);l.push(new E(i*v+e*.5+.05*s(),o*x+t/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?$n.easeInOutSine(m):$n.easeInExpo(m)))/2)))}return Uo(l,SSe(r))}function xSe(n,e,t,r){return au(vSe(n,e,t,r))}function ek(n){let e="M";const t=n.length;let r,s,i;for(let o=0,a=t;o<a;o+=3)r=n[o],s=n[o+1],i=n[o+2],e+=`${Ct(r)}L${Ct(s)}Q${Ct(i)}`;return e+=`${Ct(n[0])}`,e}function tk(n,e,t,r,s){const i=[],o=to(n);let a=e[0],l;const c=e.length;for(let d=0,f=c*s;d<f;d++){l=E.AddXY(e[(d+1)%c],o()*t,o()*t);const p=E.Sub(l,a),m=E.Len(p),y=E.Div(p,m).mul(Math.min(m/4,r));i.push(E.Add(a,y),E.Add(l,y.neg()),l),a=l}return i}function wSe(n,e,t){const r=Math.min(n,e)/2,s=Math.max(n,e)-r*2,o=(Math.PI*(r*2)+2*s)/t,a=n>e?[{type:"straight",start:new E(r,0),delta:new E(1,0)},{type:"arc",center:new E(n-r,r),startAngle:-xt/2},{type:"straight",start:new E(n-r,e),delta:new E(-1,0)},{type:"arc",center:new E(r,r),startAngle:xt/2}]:[{type:"straight",start:new E(n,r),delta:new E(0,1)},{type:"arc",center:new E(r,e-r),startAngle:0},{type:"straight",start:new E(0,e-r),delta:new E(0,-1)},{type:"arc",center:new E(r,r),startAngle:xt}];let l=0;const c=[];for(let d=0;d<t;d++){const f=a[0];f.type==="straight"?c.push(E.Add(f.start,E.Mul(f.delta,l))):c.push(Wc(f.center,r,f.startAngle+l/r)),l+=o;let p=f.type==="straight"?s:xt*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?s:xt*r}return c}const bSe={s:50,m:70,l:100,xl:130},CSe=.2;function T0(n,e,t,r,s){const i=to(t),o=SL(n,e),a=Math.max(Math.ceil(o/bSe[r]),6,Math.ceil(o/Math.min(n,e))),l=o/a*CSe,c=Math.max(n-l*2,1),d=Math.max(e-l*2,1),p=SL(c,d)/a,m=(n-c)/2,y=(e-d)/2,v=wSe(c,d,a).map(_=>_.addXY(m,y)),x=n<20?0:l*.3,b=e<20?0:l*.3,C=v.slice(0);for(let _=0;_<Math.floor(a/2);_++)C[_]=E.AddXY(C[_],i()*x*s,i()*b*s),C[a-_-1]=E.AddXY(C[a-_-1],i()*x*s,i()*b*s);const I=[];for(let _=0;_<C.length;_++){const T=_===C.length-1?0:_+1,A=C[_],R=C[T],j=v[_],K=v[T],U=E.Dist(j,K),J=p-U,N=E.Dist(A,R)/U,L=(Math.max(m,y)+J)*N,V=E.Lrp(j,K,.5).add(E.Sub(K,j).uni().per().mul(L));V.x<0?V.x=0:V.x>n&&(V.x=n),V.y<0?V.y=0:V.y>e&&(V.y=e);const X=Nk(A,R,V),W=E.Dist(X||E.Average([A,R]),A);I.push({leftPoint:A,rightPoint:R,arcPoint:V,center:X,radius:W})}return I}function PSe(n,e,t,r,s){const i=[],o=T0(n,e,t,r,s);for(const{center:a,radius:l,leftPoint:c,rightPoint:d}of o)i.push(...LG(c,d,a,l,10));return i}function nk(n,e,t,r,s){const i=T0(n,e,t,r,s);let o=`M${i[0].leftPoint.toFixed()}`;for(const{leftPoint:a,rightPoint:l,radius:c,center:d}of i){if(d===null){o+=` L${l.toFixed()}`;continue}const f=E.Clockwise(a,l,d)?"0":"1";o+=` A${ee(c)},${ee(c)} 0 ${f},1 ${l.toFixed()}`}return o+=" Z",o}const ESe={s:.5,m:.7,l:.9,xl:1.6};function kSe(n,e,t,r,s){const i=to(t),o=ESe[r]*s,a=T0(n,e,t,r,s),d=a.reduce((y,v)=>y+E.Dist2(v.leftPoint,v.rightPoint),0)/a.length>(o*15)**2?y=>E.AddXY(y,i()*o*2,i()*o*2):y=>y;let f=`M${a[0].leftPoint.toFixed()}`,p=d(a[0].leftPoint),m=`M${p.toFixed()}`;for(const{leftPoint:y,center:v,rightPoint:x,radius:b,arcPoint:C}of a){if(v===null){f+=` L${x.toFixed()}`;const j=d(x);m+=` L${j.toFixed()}`,p=j;continue}const I=E.Clockwise(y,x,v)?"0":"1";f+=` A${ee(b)},${ee(b)} 0 ${I},1 ${x.toFixed()}`;const _=d(x),T=d(C),A=Nk(p,_,T);if(!A){m+=` L${_.toFixed()}`,p=_;continue}const R=Math.abs(E.Dist(A,p));m+=` A${ee(R)},${ee(R)} 0 ${I},1 ${_.toFixed()}`,p=_}return f+m+" Z"}function rk(n,e){switch(n.geo){case"x-box":return ISe(n.w,n.h,e,n.dash);case"check-box":return _Se(n.w,n.h);default:return}}function ISe(n,e,t,r){const s=r==="draw"?.62:0;if(r==="dashed")return[[new E(0,0),new E(n/2,e/2)],[new E(n,e),new E(n/2,e/2)],[new E(0,e),new E(n/2,e/2)],[new E(n,0),new E(n/2,e/2)]];const i=a=>Math.max(0,Math.min(n,a)),o=a=>Math.max(0,Math.min(e,a));return[[new E(i(t*s),o(t*s)),new E(i(n-t*s),o(e-t*s))],[new E(i(t*s),o(e-t*s)),new E(i(n-t*s),o(t*s))]]}function _Se(n,e){const t=Math.min(n,e)*.82,r=(n-t)/2,s=(e-t)/2,i=a=>Math.max(0,Math.min(n,a)),o=a=>Math.max(0,Math.min(e,a));return[[new E(i(r+t*.25),o(s+t*.52)),new E(i(r+t*.45),o(s+t*.82))],[new E(i(r+t*.45),o(s+t*.82)),new E(i(r+t*.82),o(s+t*.22))]]}function vL({shape:n,shouldScale:e,forceSolid:t}){const r=e?n.props.scale:1,s=te(),i=Ei(),{id:o,props:a}=n,{w:l,color:c,fill:d,dash:f,growY:p,size:m,scale:y}=a,v=Er[m]*r,x=a.h+p;switch(a.geo){case"cloud":if(f==="solid"){const b=nk(l,x,o,m,y);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:b,color:c,fill:d,scale:r}),g.jsx("path",{d:b,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}else if(f==="draw"){const b=kSe(l,x,o,m,y);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:b,color:c,fill:d,scale:r}),g.jsx("path",{d:b,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}else{const b=nk(l,x,o,m,y),C=T0(l,x,o,m,y);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:b,color:c,fill:d,scale:r}),g.jsx("g",{strokeWidth:v,stroke:i[c].solid,fill:"none",pointerEvents:"all",children:C.map(({leftPoint:I,rightPoint:_,center:T,radius:A},R)=>{const j=T?A*Fc(Fc(E.Angle(T,_))-Fc(E.Angle(T,I))):E.Dist(I,_),{strokeDasharray:K,strokeDashoffset:U}=Bi(j,v,{style:f,start:"outset",end:"outset",forceSolid:t});return g.jsx("path",{d:T?`M${I.x},${I.y}A${A},${A},0,0,1,${_.x},${_.y}`:`M${I.x},${I.y}L${_.x},${_.y}`,strokeDasharray:K,strokeDashoffset:U},R)})})]})}case"ellipse":{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=b.getSvgPathData(!0);if(f==="dashed"||f==="dotted"){const I=b.length,{strokeDasharray:_,strokeDashoffset:T}=Bi(I<64?I*2:I,v,{style:f,snap:4,closed:!0,forceSolid:t});return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:C,color:c,fill:d,scale:r}),g.jsx("path",{d:C,strokeWidth:v,fill:"none",stroke:i[c].solid,strokeDasharray:_,strokeDashoffset:T})]})}else{const _=(e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n)).getSvgPathData(!0);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:_,color:c,fill:d,scale:r}),g.jsx("path",{d:_,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}}case"oval":{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=b.getSvgPathData(!0);if(f==="dashed"||f==="dotted"){const I=b.getLength(),{strokeDasharray:_,strokeDashoffset:T}=Bi(I<64?I*2:I,v,{style:f,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:t});return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:C,color:c,fill:d,scale:r}),g.jsx("path",{d:C,strokeWidth:v,fill:"none",stroke:i[c].solid,strokeDasharray:_,strokeDashoffset:T})]})}else return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:C,color:c,fill:d,scale:r}),g.jsx("path",{d:C,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}case"heart":if(f==="dashed"||f==="dotted"||f==="solid"){const b=y7(l,x),C=yT(l,x);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:b,color:c,fill:d,scale:r}),C.map((I,_)=>{const{strokeDasharray:T,strokeDashoffset:A}=Bi(I.length,v,{style:f,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:t});return g.jsx("path",{d:I.getSvgPathData(),strokeWidth:v,fill:"none",stroke:i[c].solid,strokeDasharray:T,strokeDashoffset:A,pointerEvents:"all"},`curve_${_}`)})]})}else{const b=ySe(l,x,v,n.id);return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:b,color:c,fill:d,scale:r}),g.jsx("path",{d:b,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}default:{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=b instanceof bi?b.children[0].vertices:b.vertices,I=rk(n.props,v);if(f==="solid"){let _="M"+C[0]+"L"+C.slice(1)+"Z";if(I)for(const[T,A]of I)_+=`M${T.x},${T.y}L${A.x},${A.y}`;return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:_,color:c,fill:d,scale:r}),g.jsx("path",{d:_,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}else if(f==="dashed"||f==="dotted"){const _="M"+C[0]+"L"+C.slice(1)+"Z";return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:_,color:c,fill:d,scale:r}),g.jsxs("g",{strokeWidth:v,stroke:i[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(C.length)).map((T,A)=>{const R=E.ToFixed(C[A]),j=E.ToFixed(C[(A+1)%C.length]),K=E.Dist(R,j),{strokeDasharray:U,strokeDashoffset:J}=Bi(K,v,{style:f,start:"outset",end:"outset",forceSolid:t});return g.jsx("line",{x1:R.x,y1:R.y,x2:j.x,y2:j.y,strokeDasharray:U,strokeDashoffset:J},A)}),I&&I.map(([T,A],R)=>{const j=E.Dist(T,A),{strokeDasharray:K,strokeDashoffset:U}=Bi(j,v,{style:f,start:"skip",end:"skip",snap:f==="dotted"?4:void 0,forceSolid:t});return g.jsx("path",{d:`M${T.x},${T.y}L${A.x},${A.y}`,stroke:i[c].solid,strokeWidth:v,fill:"none",strokeDasharray:K,strokeDashoffset:U},`line_fg_${R}`)})]})]})}else if(f==="draw"){let _=ek(tk(o,C,v/3,v*2,2));if(I)for(const[A,R]of I)_+=`M${A.toFixed()}L${R.toFixed()}`;const T=ek(tk(o,C,0,v*2,1));return g.jsxs(g.Fragment,{children:[g.jsx(yr,{theme:i,d:T,color:c,fill:d,scale:r}),g.jsx("path",{d:_,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}}}}const xL=17*3;class wy extends uh{canEdit(){return!0}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",align:"middle",verticalAlign:"middle",growY:0,url:"",scale:1,richText:wi("")}}getGeometry(e){const t=Math.max(1,e.props.w),r=Math.max(1,e.props.h+e.props.growY),s=t/2,i=r/2,o=e.props.fill!=="none";let a;switch(e.props.geo){case"cloud":{a=new vn({points:PSe(t,r,e.id,e.props.size,e.props.scale),isFilled:o});break}case"triangle":{a=new vn({points:[new E(s,0),new E(t,r),new E(0,r)],isFilled:o});break}case"diamond":{a=new vn({points:[new E(s,0),new E(t,i),new E(s,r),new E(0,i)],isFilled:o});break}case"pentagon":{a=new vn({points:_1(t,r,5),isFilled:o});break}case"hexagon":{a=new vn({points:_1(t,r,6),isFilled:o});break}case"octagon":{a=new vn({points:_1(t,r,8),isFilled:o});break}case"ellipse":{a=new Yae({width:t,height:r,isFilled:o});break}case"oval":{a=new Xae({width:t,height:r,isFilled:o});break}case"star":{const C=Rt/5/2,I=Math.floor(5/4)*2,_=5*2-I,T=0,A=Math.floor(5/2)*2,R=Math.cos(-Ht+I*C)*t/2,j=Math.cos(-Ht+_*C)*t/2,K=Math.sin(-Ht+T*C)*r/2,U=Math.sin(-Ht+A*C)*r/2,J=t-Math.abs(R-j),z=r-Math.abs(U-K),N=t/2+j-(t/2-R),L=r/2+K-(r/2-U),V=1,X=(t-N)/2,W=(r-L)/2,$=(t+J)/2,G=(r+z)/2,re=$*V/2,H=G*V/2;a=new vn({points:Array.from(Array(5*2)).map((ne,ge)=>{const Pe=-Ht+ge*C;return new E(X+(ge%2?re:$)*Math.cos(Pe),W+(ge%2?H:G)*Math.sin(Pe))}),isFilled:o});break}case"rhombus":{const b=Math.min(t*.38,r*.38);a=new vn({points:[new E(b,0),new E(t,0),new E(t-b,r),new E(0,r)],isFilled:o});break}case"rhombus-2":{const b=Math.min(t*.38,r*.38);a=new vn({points:[new E(0,0),new E(t-b,0),new E(t,r),new E(b,r)],isFilled:o});break}case"trapezoid":{const b=Math.min(t*.38,r*.38);a=new vn({points:[new E(b,0),new E(t-b,0),new E(t,r),new E(0,r)],isFilled:o});break}case"arrow-right":{const b=Math.min(t,r)*.38,C=r*.16;a=new vn({points:[new E(0,C),new E(t-b,C),new E(t-b,0),new E(t,r/2),new E(t-b,r),new E(t-b,r-C),new E(0,r-C)],isFilled:o});break}case"arrow-left":{const b=Math.min(t,r)*.38,C=r*.16;a=new vn({points:[new E(b,0),new E(b,C),new E(t,C),new E(t,r-C),new E(b,r-C),new E(b,r),new E(0,r/2)],isFilled:o});break}case"arrow-up":{const b=t*.16,C=Math.min(t,r)*.38;a=new vn({points:[new E(t/2,0),new E(t,C),new E(t-b,C),new E(t-b,r),new E(b,r),new E(b,C),new E(0,C)],isFilled:o});break}case"arrow-down":{const b=t*.16,C=Math.min(t,r)*.38;a=new vn({points:[new E(b,0),new E(t-b,0),new E(t-b,r-C),new E(t,r-C),new E(t/2,r),new E(0,r-C),new E(b,r-C)],isFilled:o});break}case"check-box":case"x-box":case"rectangle":{a=new zo({width:t,height:r,isFilled:o});break}case"heart":{const C=yT(t,r).reduce((I,_)=>(I.push(..._.vertices),I),[]);a=new vn({points:C,isFilled:o});break}default:En(e.props.geo)}const l=Hm(this.editor,e),c=t/e.props.scale,d=r/e.props.scale,f=Math.min(100,c/2),p=Math.min(Ta[e.props.size]*ir.lineHeight+Fr*2,d/2),m=Math.min(c,Math.max(l.w,Math.min(f,Math.max(1,c-8)))),y=Math.min(d,Math.max(l.h,Math.min(p,Math.max(1,d-8)))),v=rk(e.props,Er[e.props.size]*e.props.scale),x=v?v.map(b=>new oh({points:b})):[];return new bi({children:[a,new zo({x:e.props.align==="start"?0:e.props.align==="end"?(c-m)*e.props.scale:(c-m)/2*e.props.scale,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?(d-y)*e.props.scale:(d-y)/2*e.props.scale,width:m*e.props.scale,height:y*e.props.scale,isFilled:!0,isLabel:!0}),...x]})}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:En(e.props.geo)}}getText(e){return br(this.editor,e.props.richText)}getFontFaces(e){return aI(this.editor,e.props.richText,{family:`tldraw_${e.props.font}`,weight:"normal",style:"normal"})}component(e){const{id:t,type:r,props:s}=e,{fill:i,font:o,align:a,verticalAlign:l,size:c,richText:d}=s,f=Ei(),{editor:p}=this,m=ie("isGeoOnlySelected",()=>e.id===p.getOnlySelectedShapeId(),[]),y=p.getEditingShapeId()!==null,v=br(this.editor,e.props.richText),x=y||!!v.length,b=ie("force solid",()=>p.getZoomLevel()<.2,[p]);return g.jsxs(g.Fragment,{children:[g.jsx($l,{children:g.jsx(vL,{shape:e,shouldScale:!0,forceSolid:b})}),x&&g.jsx(jl,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+s.growY},children:g.jsx(gT,{shapeId:t,type:r,font:o,fontSize:Ta[c]*e.props.scale,lineHeight:ir.lineHeight,padding:Fr*e.props.scale,fill:i,align:a,verticalAlign:l,richText:d,isSelected:m,labelColor:f[s.labelColor].solid,wrap:!0})}),e.props.url&&g.jsx(Gd,{url:e.props.url})]})}indicator(e){const{id:t,props:r}=e,{w:s,size:i}=r,o=r.h+r.growY,a=Er[i],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?g.jsx("path",{d:xSe(t,s,o,a)}):g.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return g.jsx("path",{d:y7(s,o)});case"oval":return g.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return g.jsx("path",{d:nk(s,o,t,i,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),d=c instanceof bi?c.children[0].vertices:c.vertices;let f;if(r.dash==="draw"){const m=tk(t,d,0,a*2*e.props.scale,1);f=ek(m)}else f="M"+d[0]+"L"+d.slice(1)+"Z";const p=rk(e.props,a);if(p)for(const[m,y]of p)f+=`M${m.x},${m.y}L${y.x},${y.y}`;return g.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(aT(s.fill));let i;if(br(this.editor,s.richText)){const o=za(t),a=new ye(0,0,s.w,s.h+s.growY);i=g.jsx(mT,{fontSize:Ta[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,richText:s.richText,labelColor:o[s.labelColor].solid,bounds:a,padding:Fr*e.props.scale})}return g.jsxs(g.Fragment,{children:[g.jsx(vL,{shouldScale:!1,shape:r,forceSolid:!1}),i]})}getCanvasSvgDefs(){return[lT()]}onResize(e,{handle:t,newPoint:r,scaleX:s,scaleY:i,initialShape:o}){const a=o.props.w/o.props.scale,l=o.props.h/o.props.scale,c=o.props.growY/o.props.scale;let d=a*s,f=(l+c)*i,p=0,m=0;const y=xL;if(br(this.editor,e.props.richText)){let _=Math.max(Math.abs(d),y),T=Math.max(Math.abs(f),y);_<y&&T===y&&(_=y),_===y&&T<y&&(T=y);const A=Hm(this.editor,{...e,props:{...e.props,w:_*e.props.scale,h:T*e.props.scale}}),R=Math.max(Math.abs(d),A.w)*Math.sign(d),j=Math.max(Math.abs(f),A.h)*Math.sign(f);p=Math.abs(R)-Math.abs(d),m=Math.abs(j)-Math.abs(f),d=R,f=j}const v=d*e.props.scale,x=f*e.props.scale,b=new E(0,0);s<0&&(b.x+=v),(t==="left"||t==="top_left"||t==="bottom_left")&&(b.x+=s<0?p:-p),i<0&&(b.y+=x),(t==="top"||t==="top_left"||t==="top_right")&&(b.y+=i<0?m:-m);const{x:C,y:I}=b.rot(e.rotation).add(r);return{x:C,y:I,props:{w:Math.max(Math.abs(v),1),h:Math.max(Math.abs(x),1),growY:0}}}onBeforeCreate(e){if(!br(this.editor,e.props.richText))return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const t=e.props.h/e.props.scale,r=Hm(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){if(Op(e.props.richText,t.props.richText)&&e.props.font===t.props.font&&e.props.size===t.props.size)return;const r=br(this.editor,e.props.richText),s=br(this.editor,t.props.richText);if(r&&!s)return{...t,props:{...t.props,growY:0}};const i=e.props.w/e.props.scale,o=e.props.h/e.props.scale,a=e.props.growY/e.props.scale,l=Hm(this.editor,t);if(!r&&s&&s.length===1){let d=Math.max(i,l.w),f=Math.max(o,l.h);const p=xL;return i<p&&o<p&&(d=Math.max(d,p),f=Math.max(f,p),d=Math.max(d,f),f=Math.max(d,f)),{...t,props:{...t.props,w:d*t.props.scale,h:f*t.props.scale,growY:0}}}let c=null;if(l.h>o?c=l.h-o:a&&(c=0),c!==null){const d=t.props.w/t.props.scale;return{...t,props:{...t.props,growY:c*t.props.scale,w:Math.max(d,l.w)*t.props.scale}}}if(l.w>i)return{...t,props:{...t.props,w:l.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:yt(e.props.w,t.props.w,r),h:yt(e.props.h,t.props.h,r),scale:yt(e.props.scale,t.props.scale,r)}}}O(wy,"type","geo"),O(wy,"props",P4),O(wy,"migrations",E4);function Hm(n,e){const{richText:t,font:r,size:s,w:i}=e.props;if(!t||!br(n,t))return{w:0,h:0};const o=n.textMeasure.measureText("w",{...ir,fontFamily:Da[r],fontSize:Ta[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=rv(n,t),c=n.textMeasure.measureHtml(l,{...ir,fontFamily:Da[r],fontSize:Ta[s],minWidth:o.w,maxWidth:Math.max(0,Math.ceil(o.w+a[s]),Math.ceil(i/e.props.scale-Fr*2))});return{w:c.w+Fr*2,h:c.h+Fr*2}}function TSe(){const[n,e]=P.useState(!1);return P.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),s=matchMedia("(color-gamut: p3)");e(r&&s.matches);const i=()=>e(r&&s.matches);return s.addEventListener("change",i),()=>s.removeEventListener("change",i)},[]),ie(xn.forceSrgb)||!n?"srgb":"p3"}class by extends Xi{constructor(){super(...arguments);O(this,"options",{maxPointsPerShape:600,underlayOpacity:.82,overlayOpacity:.35})}hideResizeHandles(t){return Km(t)}hideRotateHandle(t){return Km(t)}hideSelectionBoundsFg(t){return Km(t)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=_c(t);if(Km(t))return new e_({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:s,sw:i}=wL(t,r,!0),o=dT({strokeWidth:i,showAsComplete:!0});return k0(s,o),new vn({points:W_(s,o),isFilled:!0})}component(t){const r=GC(this.editor,t),s=_c(t);return g.jsx($l,{children:g.jsx(Wm,{shape:t,forceSolid:r,strokeWidth:s,opacity:this.options.overlayOpacity})})}backgroundComponent(t){const r=GC(this.editor,t),s=_c(t);return g.jsx($l,{children:g.jsx(Wm,{shape:t,forceSolid:r,strokeWidth:s,opacity:this.options.underlayOpacity})})}indicator(t){const r=GC(this.editor,t),s=_c(t),{strokePoints:i,sw:o}=wL(t,s,r),a=Yd(t.props.segments);let l;return i.length<2?l=ASe(a[0],o):l=au(i,!1),g.jsx("path",{d:l})}toSvg(t){const r=_c(t),s=r<1.5,i=1/t.props.scale;return g.jsx("g",{transform:`scale(${i})`,children:g.jsx(Wm,{forceSolid:s,strokeWidth:r,shape:t,opacity:this.options.overlayOpacity})})}toBackgroundSvg(t){const r=_c(t),s=r<1.5,i=1/t.props.scale;return g.jsx("g",{transform:`scale(${i})`,children:g.jsx(Wm,{forceSolid:s,strokeWidth:r,shape:t,opacity:this.options.underlayOpacity})})}onResize(t,r){const{scaleX:s,scaleY:i}=r,o=[];for(const a of t.props.segments)o.push({...a,points:a.points.map(({x:l,y:c,z:d})=>({x:s*l,y:i*c,z:d}))});return{props:{segments:o}}}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,...r.props,segments:u7(t.props.segments,r.props.segments,s),scale:yt(t.props.scale,r.props.scale,s)}}}O(by,"type","highlight"),O(by,"props",_4),O(by,"migrations",T4);function MSe(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 ASe(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 wL(n,e,t){var l;const r=Yd(n.props.segments),s=n.props.isComplete||((l=Jn(n.props.segments))==null?void 0:l.type)==="straight";let i=e;!t&&!n.props.isPen&&r.length===1&&(i+=to(n.id)()*(e/6));const o=dT({strokeWidth:i,showAsComplete:s});return{strokePoints:Uo(r,o),sw:i}}function _c(n){return Vd[n.props.size]*1.12*n.props.scale}function Km(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function Wm({strokeWidth:n,forceSolid:e,shape:t,opacity:r}){var p;const s=Ei(),i=Yd(t.props.segments);let o=n;!e&&!t.props.isPen&&i.length===1&&(o+=to(t.id)()*(o/6));const a=dT({strokeWidth:o,showAsComplete:t.props.isComplete||((p=Jn(t.props.segments))==null?void 0:p.type)==="straight"}),l=Uo(i,a),c=l.length>1?au(l,!1):MSe(t.props.segments[0].points[0]),d=TSe(),f=s[t.props.color].highlight[d];return g.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:f,strokeWidth:o,opacity:r})}function GC(n,e){return ie("forceSolid",()=>{const t=_c(e),r=n.getZoomLevel();return t/r<1.5},[n])}function S7(){return g.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:[g.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),g.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),g.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}const bL=8;function OSe(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}function Sp(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 RSe(n,e,t={}){const{handle:r,change:s,crop:i}=e,{w:o,h:a}=e.uncroppedSize,{minWidth:l=bL,minHeight:c=bL}=t,d=Yt(i),f=new E(n.x,n.y),p=new E(0,0);let m=!1;switch(r){case"top":case"top_left":case"top_right":{if(a<c)break;m=!0,d.topLeft.y=d.topLeft.y+s.y/a,a*(d.bottomRight.y-d.topLeft.y)<c?(d.topLeft.y=d.bottomRight.y-c/a,p.y=(d.topLeft.y-i.topLeft.y)*a):d.topLeft.y<=0?(d.topLeft.y=0,p.y=(d.topLeft.y-i.topLeft.y)*a):p.y=s.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(a<c)break;m=!0,d.bottomRight.y=Math.min(1,d.bottomRight.y+s.y/a),a*(d.bottomRight.y-d.topLeft.y)<c&&(d.bottomRight.y=d.topLeft.y+c/a);break}}switch(r){case"left":case"top_left":case"bottom_left":{if(o<l)break;m=!0,d.topLeft.x=d.topLeft.x+s.x/o,o*(d.bottomRight.x-d.topLeft.x)<l?(d.topLeft.x=d.bottomRight.x-l/o,p.x=(d.topLeft.x-i.topLeft.x)*o):d.topLeft.x<=0?(d.topLeft.x=0,p.x=(d.topLeft.x-i.topLeft.x)*o):p.x=s.x;break}case"right":case"top_right":case"bottom_right":{if(o<l)break;m=!0,d.bottomRight.x=Math.min(1,d.bottomRight.x+s.x/o),o*(d.bottomRight.x-d.topLeft.x)<l&&(d.bottomRight.x=d.topLeft.x+l/o);break}}if(m)return f.add(p.rot(n.rotation)),{id:n.id,type:n.type,x:f.x,y:f.y,props:{w:(d.bottomRight.x-d.topLeft.x)*o,h:(d.bottomRight.y-d.topLeft.y)*a,crop:d}}}function v7({shapeId:n,assetId:e,width:t}){const r=te(),s=Fp(),i=tie(),[o,a]=P.useState(()=>({asset:e?r.getAsset(e)??null:null,url:null})),l=P.useRef(!1),c=P.useRef(null);return P.useEffect(()=>{if(!e)return;let d=!1,f;const p=qi("update state",()=>{if(!s&&n&&r.getCulledShapes().has(n))return;const m=r.getAsset(e);if(!m){a(x=>({...x,asset:null,url:null}));return}if(!m.props.src){const x=r.getTemporaryAssetPreview(m.id);if(x){c.current!==x&&(c.current=x,a(b=>({...b,isPlaceholder:!0,url:x})),i());return}}const y=s?s.scale*(t/m.props.w):r.getZoomLevel()*(t/m.props.w);function v(x,b){d||c.current!==b&&(l.current=!0,c.current=b,a({asset:x,url:b}),i())}if(l.current){let x=0;const b=()=>{x++,x>500/16&&(CL(r,e,y,s,C=>v(m,C)),f==null||f())};f==null||f(),r.on("tick",b),f=()=>r.off("tick",b)}else CL(r,e,y,s,x=>v(m,x))});return()=>{p(),f==null||f(),d=!0}},[r,e,s,i,n,t]),o}function CL(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(i=>{s(i)})}async function DSe(n){const t=await(await Vi(n)).blob();return zr.blobToDataUrl(t)}const jSe=new Na;class Cy extends uh{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=r0(e,t);const{flipX:s,flipY:i}=t.initialShape.props,{scaleX:o,scaleY:a,mode:l}=t;if(r={...r,props:{...r.props,flipX:o<0!==s,flipY:a<0!==i}},!e.props.crop)return r;const c=l==="scale_shape"&&o===-1||l==="resize_bounds"&&s!==r.props.flipX,d=l==="scale_shape"&&a===-1||l==="resize_bounds"&&i!==r.props.flipY,{topLeft:f,bottomRight:p}=e.props.crop;return r.props.crop={topLeft:{x:c?1-p.x:f.x,y:d?1-p.y:f.y},bottomRight:{x:c?1-f.x:p.x,y:d?1-f.y:p.y}},r}component(e){return g.jsx(NSe,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:g.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h)})}async toSvg(e,t){if(!e.props.assetId)return null;const r=this.editor.getAsset(e.props.assetId);if(!r)return null;const{w:s}=Sp(e.props,e.props.crop),i=await jSe.get(r,async()=>{let o=await t.resolveAssetUrl(r.id,s);if(!o)return null;if((o.startsWith("blob:")||o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await DSe(o)||""),x7(this.editor,r.id)){const{promise:a}=b7(o);o=await a}return o});return i?g.jsx(LSe,{shape:e,src:i}):null}onDoubleClickEdge(e){const t=e.props;if(!t||this.editor.getCroppingShapeId()!==e.id)return;const r=Yt(t.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},{w:s,h:i}=Sp(e.props,r),o=new E(r.topLeft.x*s,r.topLeft.y*i).rot(e.rotation),a={id:e.id,type:e.type,x:e.x-o.x,y:e.y-o.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([a])}getInterpolatedProps(e,t,r){function s(i,o){var f,p,m,y;if(i.props.crop===null&&o.props.crop===null)return null;const a=((f=i.props.crop)==null?void 0:f.topLeft)||{x:0,y:0},l=((p=i.props.crop)==null?void 0:p.bottomRight)||{x:1,y:1},c=((m=o.props.crop)==null?void 0:m.topLeft)||{x:0,y:0},d=((y=o.props.crop)==null?void 0:y.bottomRight)||{x:1,y:1};return{topLeft:{x:yt(a.x,c.x,r),y:yt(a.y,c.y,r)},bottomRight:{x:yt(l.x,d.x,r),y:yt(l.y,d.y,r)}}}return{...r>.5?t.props:e.props,w:yt(e.props.w,t.props.w,r),h:yt(e.props.h,t.props.h,r),crop:s(e,t)}}}O(Cy,"type","image"),O(Cy,"props",M4),O(Cy,"migrations",A4);const NSe=P.memo(function({shape:e}){var C;const t=te(),{w:r}=Sp(e.props,e.props.crop),{asset:s,url:i}=v7({shapeId:e.id,assetId:e.props.assetId,width:r}),o=O6(),[a,l]=P.useState(""),[c,d]=P.useState(null),f=s&&x7(t,s.id);P.useEffect(()=>{if(i&&f){const{promise:I,cancel:_}=b7(i);return I.then(T=>{l(T),d(i)}),()=>{_()}}},[t,f,o,i]);const p=ie("show crop preview",()=>e.id===t.getOnlySelectedShapeId()&&t.getCroppingShapeId()===e.id&&t.isIn("select.crop"),[t,e.id]),m=o&&(((C=s==null?void 0:s.props.mimeType)==null?void 0:C.includes("video"))||f),y=w7(e),v=i===c?null:i,x=m?a:c;if(!i&&!(s!=null&&s.props.src))return g.jsxs(jl,{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:[g.jsx("div",{className:ze("tl-image-container",s&&"tl-image-container-loading"),style:y,children:s?null:g.jsx(S7,{})}),"url"in e.props&&e.props.url&&g.jsx(Gd,{url:e.props.url})]});const b=f?"anonymous":void 0;return g.jsxs(g.Fragment,{children:[p&&x&&g.jsx("div",{style:y,children:g.jsx("img",{className:"tl-image",style:{...Uf(e),opacity:.1},crossOrigin:b,src:x,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),g.jsxs(jl,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[g.jsxs("div",{className:ze("tl-image-container"),style:y,children:[x&&g.jsx("img",{className:"tl-image",style:Uf(e),crossOrigin:b,src:x,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},x),v&&g.jsx("img",{className:"tl-image",style:Uf(e),crossOrigin:b,src:v,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>d(v)},v)]}),e.props.url&&g.jsx(Gd,{url:e.props.url})]})]})});function x7(n,e){const t=e?n.getAsset(e):void 0;return t?"mimeType"in t.props&&Ls.isAnimatedImageType(t==null?void 0:t.props.mimeType)||"isAnimated"in t.props&&t.props.isAnimated:!1}function w7(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}=Sp(n.props,e),i=-t.x*r,o=-t.y*s;return{transform:`translate(${i}px, ${o}px)`,width:r,height:s}}function Uf(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 LSe({shape:n,src:e}){const t=pu(),r=w7(n),s=n.props.crop;if(r.transform&&s){const{transform:i,width:o,height:a}=r,l=(s.bottomRight.x-s.topLeft.x)*o,c=(s.bottomRight.y-s.topLeft.y)*a,d=[new E(0,0),new E(l,0),new E(l,c),new E(0,c)],f=Uf(n,{width:o,height:a});return g.jsxs(g.Fragment,{children:[g.jsx("defs",{children:g.jsx("clipPath",{id:t,children:g.jsx("polygon",{points:d.map(p=>`${p.x},${p.y}`).join(" ")})})}),g.jsx("g",{clipPath:`url(#${t})`,children:g.jsx("image",{href:e,width:o,height:a,style:f?{...f,transform:`${i} ${f.transform}`}:{transform:i}})})]})}else return g.jsx("image",{href:e,width:n.props.w,height:n.props.h,style:Uf(n,{width:n.props.w,height:n.props.h})})}function b7(n){let e=!1;return{promise:new Promise(r=>{const s=qf();s.onload=()=>{if(e)return;const i=document.createElement("canvas");i.width=s.width,i.height=s.height;const o=i.getContext("2d");o&&(o.drawImage(s,0,0),r(i.toDataURL()))},s.crossOrigin="anonymous",s.src=n}),cancel:()=>e=!0}}function C7(n){return{size:n,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function P7(n,e,t){const r=e.vertices,s=C7(t);return Uo(r,s)}function FSe(n,e,t){const r=C7(t);return W_(k0(P7(n,e,t),r),r)}function zSe(n,e,t){const r=FSe(n,e,t);return FI(r)}function $Se(n,e,t){if(n.props.dash==="draw"){const r=P7(n,e,t);return au(r)}return e.getSvgPathData()}function E7(n,e,t){let r=`M ${Ct(e[0])}L`,s=`M ${Ct(e[0])}L`;const i=t/3,o=t*2,a=to(n);let l=e[0],c,d=e[0],f;const p=e.length;for(let m=0,y=p-1;m<y;m++){c=e[m+1],f=E.AddXY(e[m+1],a()*i,a()*i);const v=E.Sub(c,l),x=E.Len(v),b=E.Div(v,x).mul(Math.min(x/4,o)),C=E.Add(l,b),I=E.Add(c,b.neg()),_=E.Sub(f,d),T=E.Len(_),A=E.Div(_,T).mul(Math.min(T/4,o)),R=E.Add(d,A),j=E.Add(f,A.neg());m===y-1?(r+=`${Ct(C)}L ${Ct(c)}`,s+=`${Ct(R)}L ${Ct(f)}`):(r+=`${Ct(C)}L ${Ct(I)}Q ${Ct(c)}`,s+=`${Ct(R)}L ${Ct(j)}Q ${Ct(f)}`,l=c,d=f)}return[r,r+s]}const BSe=new Na;class Py extends Xi{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,t]=Yf(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 Ef(e)}getHandles(e){return BSe.get(e.props,()=>{const t=Ef(e),r=Pf(e),s=r.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<r.length-1;i++){const o=Gf(r[i].index,r[i+1].index),l=t.segments[i].midPoint();s.push({id:o,type:"create",index:o,x:l.x,y:l.y,canSnap:!0})}return s.sort(Qn)})}onResize(e,t){const{scaleX:r,scaleY:s}=t;return{props:{points:Jd(e.props.points,(i,{id:o,index:a,x:l,y:c})=>({id:o,index:a,x:l*r,y:c*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(o=>{const a=t[o];return a.x===s.x&&a.y===s.y})){const o=r[r.length-1];return t[o]={...t[o],x:t[o].x+.1,y:t[o].y+.1},e}}onHandleDrag(e,{handle:t}){if(t.type!=="vertex")return;const r=Ji(new E(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 g.jsx($l,{style:{minWidth:50,minHeight:50},children:g.jsx(PL,{shape:e})})}indicator(e){const t=Ro[e.props.size]*e.props.scale,r=Ef(e),{dash:s}=e.props;let i;if(e.props.spline==="line"){const o=r.points;if(s==="solid"||s==="dotted"||s==="dashed")i="M"+o[0]+"L"+o.slice(1);else{const[a]=E7(e.id,o,t);i=a}}else i=$Se(e,r,t);return g.jsx("path",{d:i})}toSvg(e){return g.jsx(PL,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const t=Pf(e);return{points:t,getSelfSnapPoints:r=>{const s=this.getHandles(e).filter(i=>i.type==="vertex").findIndex(i=>i.id===r.id);return t.filter((i,o)=>Math.abs(o-s)>1).map(E.From)},getSelfSnapOutline:r=>{const s=this.getHandles(e).filter(o=>o.type==="vertex").findIndex(o=>o.id===r.id),i=Ef(e).segments.filter((o,a)=>a!==s-1&&a!==s);return i.length?new bi({children:i}):null}}}getInterpolatedProps(e,t,r){const s=Pf(e),i=Pf(t),o=[],a=[];let l=d3;if(s.length>i.length)for(let c=0;c<s.length;c++)o[c]={...s[c]},i[c]===void 0?a[c]={...i[i.length-1],id:l}:a[c]={...i[c],id:l},l=To(l);else if(i.length>s.length)for(let c=0;c<i.length;c++)a[c]={...i[c]},s[c]===void 0?o[c]={...s[s.length-1],id:l}:o[c]={...s[c],id:l},l=To(l);else for(let c=0;c<i.length;c++)o[c]=s[c],a[c]=i[c];return{...r>.5?t.props:e.props,points:Object.fromEntries(o.map((c,d)=>{const f=a[d];return[c.id,{...c,x:yt(c.x,f.x,r),y:yt(c.y,f.y,r)}]})),scale:yt(e.props.scale,t.props.scale,r)}}}O(Py,"type","line"),O(Py,"props",O4),O(Py,"migrations",R4);function Pf(n){return Object.values(n.props.points).sort(Qn)}function Ef(n){const e=Pf(n).map(E.From);switch(n.props.spline){case"cubic":return new Gae({points:e});case"line":return new oh({points:e})}}function PL({shape:n,shouldScale:e=!1,forceSolid:t=!1}){const r=Ei(),s=Ef(n),{dash:i,color:o,size:a}=n.props,l=1/n.props.scale,c=e?l:1,d=Ro[a]*n.props.scale;if(n.props.spline==="line"){if(i==="solid"){const f=s.points,p="M"+f[0]+"L"+f.slice(1);return g.jsx("path",{d:p,stroke:r[o].solid,strokeWidth:d,fill:"none",transform:`scale(${c})`})}if(i==="dashed"||i==="dotted")return g.jsx("g",{stroke:r[o].solid,strokeWidth:d,transform:`scale(${c})`,children:s.segments.map((f,p)=>{const{strokeDasharray:m,strokeDashoffset:y}=t?{strokeDasharray:"none",strokeDashoffset:"none"}:Bi(f.length,d,{style:i,start:p>0?"outset":"none",end:p<s.segments.length-1?"outset":"none"});return g.jsx("path",{strokeDasharray:m,strokeDashoffset:y,d:f.getSvgPathData(!0),fill:"none"},p)})});if(i==="draw"){const f=s.points,[p,m]=E7(n.id,f,d);return g.jsx("path",{d:m,stroke:r[o].solid,strokeWidth:d,fill:"none",transform:`scale(${c})`})}}if(n.props.spline==="cubic"){const f=s.getSvgPathData();if(i==="solid")return g.jsx("path",{strokeWidth:d,stroke:r[o].solid,fill:"none",d:f,transform:`scale(${c})`});if(i==="dashed"||i==="dotted")return g.jsx("g",{stroke:r[o].solid,strokeWidth:d,transform:`scale(${c})`,children:s.segments.map((p,m)=>{const{strokeDasharray:y,strokeDashoffset:v}=Bi(p.length,d,{style:i,start:m>0?"outset":"none",end:m<s.segments.length-1?"outset":"none",forceSolid:t});return g.jsx("path",{strokeDasharray:y,strokeDashoffset:v,d:p.getSvgPathData(),fill:"none"},m)})});if(i==="draw")return g.jsx("path",{d:zSe(n,s,d),strokeWidth:1,stroke:r[o].solid,fill:r[o].solid,transform:`scale(${c})`})}}class Ey extends Xi{constructor(){super(...arguments);O(this,"options",{resizeMode:"none"})}canEdit(){return!0}hideResizeHandles(){const{resizeMode:t}=this.options;switch(t){case"none":return!0;case"scale":return!1;default:throw En(t)}}isAspectRatioLocked(){return this.options.resizeMode==="scale"}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",richText:wi(""),size:"m",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(t){const{labelHeight:r,labelWidth:s}=k7(this.editor,t),{scale:i}=t.props,o=r*i,a=s*i,l=Ot*i,c=Vm(t);return new bi({children:[new zo({width:l,height:c,isFilled:!0}),new zo({x:t.props.align==="start"?0:t.props.align==="end"?l-a:(l-a)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?c-o:(c-o)/2,width:a,height:o,isFilled:!0,isLabel:!0})]})}getHandles(t){const{scale:r}=t.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const i=this.editor.getZoomLevel();if(i*r<.25)return[];const o=Vm(t),a=Ot*r,l=Dme/i*r;return i*r<.5?[{id:"bottom",index:"a3",type:"clone",x:a/2,y:o+l}]:[{id:"top",index:"a1",type:"clone",x:a/2,y:-l},{id:"right",index:"a2",type:"clone",x:a+l,y:o/2},{id:"bottom",index:"a3",type:"clone",x:a/2,y:o+l},{id:"left",index:"a4",type:"clone",x:-l,y:o/2}]}onResize(t,r){const{resizeMode:s}=this.options;switch(s){case"none":return;case"scale":return nF(t,r);default:throw En(s)}}getText(t){return br(this.editor,t.props.richText)}getFontFaces(t){return aI(this.editor,t.props.richText,{family:`tldraw_${t.props.font}`,weight:"normal",style:"normal"})}component(t){const{id:r,type:s,props:{labelColor:i,scale:o,color:a,font:l,size:c,align:d,richText:f,verticalAlign:p,fontSizeAdjustment:m}}=t,y=KSe(r),v=Ei(),x=Ot*o,b=Vm(t),C=ie("shape rotation",()=>{var A;return((A=this.editor.getShapePageTransform(r))==null?void 0:A.rotation())??0},[this.editor]),I=ie("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),_=ie("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),T=t.id===this.editor.getOnlySelectedShapeId();return g.jsxs(g.Fragment,{children:[g.jsx("div",{id:r,className:"tl-note__container",style:{width:x,height:b,backgroundColor:v[a].note.fill,borderBottom:I?_?`${2*o}px solid rgb(20, 20, 20)`:`${2*o}px solid rgb(144, 144, 144)`:"none",boxShadow:I?"none":WSe(t.id,C,o)},children:g.jsx(gT,{shapeId:r,type:s,font:l,fontSize:(m||Ta[c])*o,lineHeight:ir.lineHeight,align:d,verticalAlign:p,richText:f,isSelected:T,labelColor:i==="black"?v[a].note.text:v[i].fill,wrap:!0,padding:Fr*o,onKeyDown:y})}),"url"in t.props&&t.props.url&&g.jsx(Gd,{url:t.props.url})]})}indicator(t){const{scale:r}=t.props;return g.jsx("rect",{rx:r,width:ee(Ot*r),height:ee(Vm(t))})}toSvg(t,r){const s=za({isDarkMode:r.isDarkMode}),i=VSe(t),o=g.jsx(mT,{fontSize:t.props.fontSizeAdjustment||Ta[t.props.size],font:t.props.font,align:t.props.align,verticalAlign:t.props.verticalAlign,richText:t.props.richText,labelColor:s[t.props.color].note.text,bounds:i,padding:Fr*t.props.scale});return g.jsxs(g.Fragment,{children:[g.jsx("rect",{x:5,y:5,rx:1,width:Ot-10,height:i.h,fill:"rgba(0,0,0,.1)"}),g.jsx("rect",{rx:1,width:Ot,height:i.h,fill:s[t.props.color].note.fill}),o]})}onBeforeCreate(t){return EL(this.editor,t)}onBeforeUpdate(t,r){if(!(Op(t.props.richText,r.props.richText)&&t.props.font===r.props.font&&t.props.size===r.props.size))return EL(this.editor,r)}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:yt(t.props.scale,r.props.scale,s)}}}O(Ey,"type","note"),O(Ey,"props",D4),O(Ey,"migrations",j4);function EL(n,e){const{labelHeight:t,fontSizeAdjustment:r}=k7(n,e),s=Math.max(0,t-Ot);if(s!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:s,fontSizeAdjustment:r}}}function USe(n,e){const{richText:t}=e.props;if(!br(n,t))return{labelHeight:Ta[e.props.size]*ir.lineHeight+Fr*2,labelWidth:100,fontSizeAdjustment:0};const r=Ta[e.props.size];let s=0,i=0,o=Ot,a=Ot;const l=1;do{s=Math.min(r,r-i);const c=rv(n,t),d=n.textMeasure.measureHtml(c,{...ir,fontFamily:Da[e.props.font],fontSize:s,maxWidth:Ot-Fr*2-l,disableOverflowWrapBreaking:!0});if(o=d.h+Fr*2,a=d.w+Fr*2,s<=14){const f=rv(n,t),p=n.textMeasure.measureHtml(f,{...ir,fontFamily:Da[e.props.font],fontSize:s,maxWidth:Ot-Fr*2-l});o=p.h+Fr*2,a=p.w+Fr*2;break}if(d.scrollWidth.toFixed(0)===d.w.toFixed(0))break}while(i++<50);return{labelHeight:o,labelWidth:a,fontSizeAdjustment:s}}const HSe=new Na;function k7(n,e){return HSe.get(e,()=>USe(n,e))}function KSe(n){const e=te(),t=jU();return P.useCallback(r=>{const s=e.getShape(n);if(!s)return;const i=r.key==="Tab",o=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(i||o){r.preventDefault();const a=e.getShapePageTransform(n),l=a.rotation(),c=!!(t.dir==="rtl"||$9(br(e,s.props.richText))),d=(Ot+e.options.adjacentShapeMargin+(o&&!r.shiftKey?s.props.growY:0))*s.props.scale,f=new E(i?r.shiftKey!=c?-1:1:0,o?r.shiftKey?-1:1:0).mul(d).add(_0.clone().mul(s.props.scale)).rot(l).add(a.point()),p=Z9(e,s,f,l);p&&(e.markHistoryStoppingPoint("editing adjacent shape"),PS(e,p,!0))}},[n,e,t.dir])}function Vm(n){return(Ot+n.props.growY)*n.props.scale}function WSe(n,e,t){const r=to(n),s=Math.abs(r())+.5,i=Math.cos(e),o=5*t,a=4*t,l=6*t,c=7*t;return`0px ${o-s}px ${o}px -${o}px rgba(15, 23, 31, .6),
486
+ 0px ${(a+s*c)*Math.max(0,i)}px ${l+s*c}px -${a+s*l}px rgba(15, 23, 31, ${(.3+s*.1).toFixed(2)}),
487
+ 0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+i)/2)).toFixed(2)})`}function VSe(n){return new ye(0,0,Ot,Ot+n.props.growY)}const qSe=xI("text size",(n,e)=>(n.fonts.trackFontsForShape(e),I7(n,e.props)),{areRecordsEqual:(n,e)=>n.props===e.props});class ky extends Xi{constructor(){super(...arguments);O(this,"options",{extraArrowHorizontalPadding:10})}getDefaultProps(){return{color:"black",size:"m",w:8,font:"draw",textAlign:"start",autoSize:!0,scale:1,richText:wi("")}}getMinDimensions(t){return qSe.get(this.editor,t.id)}getGeometry(t,r){const{scale:s}=t.props,{width:i,height:o}=this.getMinDimensions(t),a=(r==null?void 0:r.context)??"none";return new zo({x:(a==="@tldraw/arrow-start"?-this.options.extraArrowHorizontalPadding:0)*s,width:(i+(a==="@tldraw/arrow-start"?this.options.extraArrowHorizontalPadding*2:0))*s,height:o*s,isFilled:!0,isLabel:!0})}getFontFaces(t){return aI(this.editor,t.props.richText,{family:`tldraw_${t.props.font}`,weight:"normal",style:"normal"})}getText(t){return br(this.editor,t.props.richText)}canEdit(){return!0}isAspectRatioLocked(){return!0}component(t){const{id:r,props:{font:s,size:i,richText:o,color:a,scale:l,textAlign:c}}=t,{width:d,height:f}=this.getMinDimensions(t),p=t.id===this.editor.getOnlySelectedShapeId(),m=Ei(),y=GSe(r);return g.jsx(gT,{shapeId:r,classNamePrefix:"tl-text-shape",type:"text",font:s,fontSize:Vd[i],lineHeight:ir.lineHeight,align:c,verticalAlign:"middle",richText:o,labelColor:m[a].solid,isSelected:p,textWidth:d,textHeight:f,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0,onKeyDown:y})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,s=te();return t.props.autoSize&&s.getEditingShapeId()===t.id?null:g.jsx("rect",{width:ee(r.width),height:ee(r.height)})}toSvg(t,r){const s=this.editor.getShapeGeometry(t).bounds,i=s.width/(t.props.scale??1),o=s.height/(t.props.scale??1),a=za(r),l=new ye(0,0,i,o);return g.jsx(mT,{fontSize:Vd[t.props.size],font:t.props.font,align:t.props.textAlign,verticalAlign:"middle",richText:t.props.richText,labelColor:a[t.props.color].solid,bounds:l,padding:0})}onResize(t,r){const{newPoint:s,initialBounds:i,initialShape:o,scaleX:a,handle:l}=r;if(r.mode==="scale_shape"||l!=="right"&&l!=="left")return{id:t.id,type:t.type,...nF(t,r)};{const c=Math.max(1,Math.abs(i.width*a)),{x:d,y:f}=a<0?E.Sub(s,E.FromAngle(t.rotation).mul(c)):s;return{id:t.id,type:t.type,x:d,y:f,props:{w:c/o.props.scale,autoSize:!1}}}}onEditEnd(t){br(this.editor,t.props.richText).trimEnd().length===0&&this.editor.deleteShapes([t.id])}onBeforeUpdate(t,r){if(!r.props.autoSize)return;const s=t.props.size!==r.props.size||t.props.textAlign!==r.props.textAlign||t.props.font!==r.props.font||t.props.scale!==1&&r.props.scale===1,i=!Op(t.props.richText,r.props.richText);if(!s&&!i)return;const o=this.getMinDimensions(t),a=I7(this.editor,r.props),l=o.width*t.props.scale,c=o.height*t.props.scale,d=a.width*r.props.scale,f=a.height*r.props.scale;let p;switch(r.props.textAlign){case"middle":{p=new E((d-l)/2,i?0:(f-c)/2);break}case"end":{p=new E(d-l,i?0:(f-c)/2);break}default:{if(i)break;p=new E(0,(f-c)/2);break}}if(p){p.rot(r.rotation);const{x:m,y}=r;return{...r,x:m-p.x,y:y-p.y,props:{...r.props,w:d}}}else return{...r,props:{...r.props,w:d}}}}O(ky,"type","text"),O(ky,"props",N4),O(ky,"migrations",L4);function I7(n,e){const{font:t,richText:r,autoSize:s,size:i,w:o}=e,a=s?16:Math.max(16,o),l=Vd[i],c=s?null:Math.floor(Math.max(a,o)),d=rv(n,r),f=n.textMeasure.measureHtml(d,{...ir,fontFamily:Da[t],fontSize:l,maxWidth:c});return s&&(f.w+=1),{width:Math.max(a,f.w),height:Math.max(l,f.h)}}function GSe(n){const e=te();return P.useCallback(t=>{if(e.getEditingShapeId()===n)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&e.complete();break}}},[e,n])}const YSe=new Na;class Iy extends uh{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return g.jsx(XSe,{shape:e})}indicator(e){return g.jsx("rect",{width:ee(e.props.w),height:ee(e.props.h)})}async toSvg(e,t){if(!e.props.assetId)return null;const r=this.editor.getAsset(e.props.assetId);if(!r)return null;const s=await YSe.get(r,async()=>{const i=await t.resolveAssetUrl(r.id,e.props.w);if(!i)return null;const o=await Ls.loadVideo(i);return await Ls.getVideoFrameAsDataUrl(o,0)});return s?g.jsx("image",{href:s,width:e.props.w,height:e.props.h}):null}}O(Iy,"type","video"),O(Iy,"props",F4),O(Iy,"migrations",z4);const XSe=P.memo(function({shape:e}){const t=te(),r=t.getShapeGeometry(e).bounds.w*t.getZoomLevel()>=110,s=s0(e.id),i=O6(),{Spinner:o}=Zt(),{asset:a,url:l}=v7({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),c=P.useRef(null),[d,f]=P.useState(!1),[p,m]=P.useState(!1);P.useEffect(()=>{const v=()=>m(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",v),()=>document.removeEventListener("fullscreenchange",v)});const y=P.useCallback(v=>{v.currentTarget&&f(!0)},[]);return P.useEffect(()=>{const v=c.current;v&&s&&document.activeElement!==v&&v.focus()},[s,d]),P.useEffect(()=>{if(i){const v=c.current;if(!v)return;v.pause(),v.currentTime=0}},[c,i]),g.jsxs(g.Fragment,{children:[g.jsx(jl,{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:g.jsx("div",{className:"tl-counter-scaled",children:g.jsx("div",{className:"tl-video-container",children:a?o&&!a.props.src?g.jsx(o,{}):l?g.jsxs(g.Fragment,{children:[g.jsx("video",{ref:c,style:s?{pointerEvents:"all"}:d?void 0:{display:"none"},className:ze("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":p}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:s&&r,onLoadedData:y,hidden:!d,children:g.jsx("source",{src:l})}),!d&&o&&g.jsx(o,{})]}):null:g.jsx(S7,{})})})}),"url"in e.props&&e.props.url&&g.jsx(Gd,{url:e.props.url})]})}),_7=[ky,Sy,vy,wy,Ey,Py,xy,yy,by,av,Cy,Iy];function ZSe(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 T7 extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"scribbleId","id");O(this,"markId","");O(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(i=>{if(this.editor.isShapeOrAncestorLocked(i))return!0;if(this.editor.isShapeOfType(i,"group")||this.editor.isShapeOfType(i,"frame")){const o=this.editor.getPointInShapeSpace(i,r);return this.editor.getShapeGeometry(i).bounds.containsPoint(o)}return!1}).map(i=>i.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(),i=t.getZoomLevel(),o=t.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=t;this.pushPointToScribble();const c=new Set(s),d=this.editor.options.hitTestMargin/i;for(const f of o){if(t.isShapeOfType(f,"group"))continue;const p=t.getShapeMask(f.id);if(p&&!$s(a,p))continue;const m=t.getShapeGeometry(f),y=t.getShapePageTransform(f);if(!m||!y)continue;const v=y.clone().invert(),x=v.applyToPoint(l),b=v.applyToPoint(a),{bounds:C}=m;C.minX-d>Math.max(x.x,b.x)||C.minY-d>Math.max(x.y,b.y)||C.maxX+d<Math.min(x.x,b.x)||C.maxY+d<Math.min(x.y,b.y)||m.hitTestLineSegment(x,b,d)&&c.add(t.getOutermostSelectableShape(f).id)}this.editor.setErasingShapes([...c].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)}}O(T7,"id","erasing");var pP;let JSe=(pP=class extends Ne{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},O(pP,"id","idle"),pP);var gP;let QSe=(gP=class extends Ne{onEnter(){const e=this.editor.getZoomLevel(),t=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,s=new Set,i=s.size;for(let o=t.length,a=o-1;a>=0;a--){const l=t[a];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,r,{hitInside:!1,margin:this.editor.options.hitTestMargin/e})){const c=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(c,"frame")&&s.size>i)break;s.add(c.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")}},O(gP,"id","pointing"),gP);class _y extends Ne{static children(){return[JSe,QSe,T7]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}O(_y,"id","eraser"),O(_y,"initial","idle"),O(_y,"isLockable",!1);class M7 extends Ne{constructor(){super(...arguments);O(this,"initialCamera",new E)}onEnter(){this.initialCamera=E.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:i}=r.inputs,o=E.Sub(s,i).div(r.getZoomLevel());o.len2()!==0&&r.setCamera(t.clone().add(o))}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")}}O(M7,"id","dragging");var mP;let eve=(mP=class extends Ne{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},O(mP,"id","idle"),mP);var yP;let tve=(yP=class extends Ne{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")}},O(yP,"id","pointing"),yP);class Ty extends Ne{static children(){return[eve,tve,M7]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomIn(t,{animation:{duration:220,easing:$n.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomOut(t,{animation:{duration:320,easing:$n.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:$n.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:$n.easeOutQuint}})}}}O(Ty,"id","hand"),O(Ty,"initial","idle"),O(Ty,"isLockable",!1);var SP;let nve=(SP=class extends Ne{onPointerDown(e){this.parent.transition("lasering",e)}},O(SP,"id","idle"),SP);class A7 extends Ne{constructor(){super(...arguments);O(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")}}O(A7,"id","lasering");class My extends Ne{static children(){return[nve,A7]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}O(My,"id","laser"),O(My,"initial","idle"),O(My,"isLockable",!1);class O7 extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"initialSelectedShapeIds",[]);O(this,"excludedShapeIds",new Set);O(this,"isWrapMode",!1);O(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(i=>this.editor.isShapeOfType(i,"group")||this.editor.isShapeOrAncestorLocked(i)).map(i=>i.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:i,currentPagePoint:o,shiftKey:a,ctrlKey:l}}=t,c=new Set(a?this.initialSelectedShapeIds:[]),d=s?!l:l,f=ye.FromPoints([i,o]),{corners:p}=f;let m,y,v,x,b,C;const I=t.getCurrentPageRenderingShapesSorted(),_=t.getCurrentPageId();e:for(let R=0,j=I.length;R<j;R++){if(v=I[R],r.has(v.id)||c.has(v.id)||(x=t.getShapePageBounds(v),!x))continue e;if(f.contains(x)){this.handleHit(v,o,_,c,p);continue e}if(d||t.isShapeOfType(v,"frame"))continue e;if(f.collides(x)){if(b=t.getShapePageTransform(v),!b)continue e;C=b.clone().invert().applyToPoints(p);const K=t.getShapeGeometry(v);t:for(let U=0;U<4;U++)if(m=C[U],y=C[(U+1)%4],K.hitTestLineSegment(m,y,0)){this.handleHit(v,o,_,c,p);break t}}}const T=t.getInstanceState().brush;(!T||!f.equals(T))&&t.updateInstanceState({brush:{...f.toJson()}});const A=t.getSelectedShapeIds();(A.length!==c.size||A.some(R=>!c.has(R)))&&t.setSelectedShapes(Array.from(c))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(t,r,s,i,o){if(t.parentId===s){i.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),l=this.editor.getShapeMask(a.id);l&&!KI(l,o)&&!$s(r,l)||i.add(a.id)}}O(O7,"id","brushing");const Xd={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 R7 extends Ne{constructor(){super(...arguments);O(this,"info",{})}updateCursor(){const t=this.editor.getSelectedShapes(),r=Xd[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")}}O(R7,"id","pointing_resize_handle");class ST extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"markId","");O(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=Xd[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){var p;const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t)return;const s=this.editor.getShapeUtil(t.type);if(!s)return;const i=this.editor.inputs.currentPagePoint.clone().sub(r),o=this.editor.inputs.originPagePoint.clone().sub(r),a=i.clone().sub(o).rot(-t.rotation),l=t.props.crop??OSe(),c={w:1/(l.bottomRight.x-l.topLeft.x)*t.props.w,h:1/(l.bottomRight.y-l.topLeft.y)*t.props.h},f=(((p=s.onCrop)==null?void 0:p.bind(s))??RSe)(t,{handle:this.info.handle,change:a,crop:l,uncroppedSize:c,initialShape:this.snapshot.shape});f&&(this.editor.updateShapes([{id:t.id,type:t.type,...f}]),this.updateCursor())}complete(){this.updateShapes(),Ut(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(),i=this.editor.getSelectionRotatedPageBounds(),o=E.RotWith(i.getHandlePoint(this.info.handle),i.point,t),a=E.Sub(r,o);return{shape:s,cursorHandleOffset:a}}}O(ST,"id","cropping");function vT(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 D7(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:i,h:o}=Sp(e.props,r),a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=Yt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-t.x/i)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-t.y/o)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:e.id,type:e.type,props:{crop:c}}}var vP;let rve=(vP=class extends Ne{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=vT(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 i;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"){(i=s.onDoubleClickEdge)==null||i.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 E(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 E(0,0)))return;r&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const o=D7(this.editor,i,s);o&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([o]))}},O(vP,"id","idle"),vP);class j7 extends Ne{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)}}O(j7,"id","pointing_crop");class xT extends Ne{constructor(){super(...arguments);O(this,"info",{})}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=Xd[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"))}}O(xT,"id","pointing_crop_handle");class N7 extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"markId","");O(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,i=s.clone().sub(r),o=D7(this.editor,t,i);o&&this.editor.updateShapes([o])}}O(N7,"id","translating_crop");class sk extends Ne{constructor(){super(...arguments);O(this,"markId","");O(this,"didExit",!1)}static children(){return[rve,N7,j7,xT,ST]}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))}}O(sk,"id","crop"),O(sk,"initial","idle");class L7 extends Ne{constructor(){super(...arguments);O(this,"shapeId","");O(this,"initialHandle",{});O(this,"initialAdjacentHandle",null);O(this,"initialPagePoint",{});O(this,"markId","");O(this,"initialPageTransform");O(this,"initialPageRotation");O(this,"info",{});O(this,"isPrecise",!1);O(this,"isPreciseId",null);O(this,"pointingId",null);O(this,"exactTimeout",-1)}onEnter(t){const{shape:r,isCreating:s,creatingMarkId:i,handle:o}=t;if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.shapeId=r.id,this.markId="",s)if(i)this.markId=i;else{const c=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);c&&(this.markId=c)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");if(this.initialHandle=Yt(o),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[o.index]:{id:o.index,index:o.index,x:o.x,y:o.y}}}});const d=this.editor.getShapeHandles(r).find(f=>f.index===o.index);this.initialHandle=Yt(d)}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(Qn),l=a.findIndex(c=>c.id===t.handle.id);this.initialAdjacentHandle=null;for(let c=l+1;c<a.length;c++){const d=a[c];if(d.type==="vertex"&&d.id!=="middle"&&d.id!==t.handle.id){this.initialAdjacentHandle=d;break}}if(!this.initialAdjacentHandle)for(let c=a.length-1;c>=0;c--){const d=a[c];if(d.type==="vertex"&&d.id!=="middle"&&d.id!==t.handle.id){this.initialAdjacentHandle=d;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=ys(this.editor,r)[t.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),Ut(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:i,initialPageRotation:o,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:d,inputs:{currentPagePoint:f,shiftKey:p,ctrlKey:m,altKey:y,pointerVelocity:v}}=t,x=this.info.shape,b=t.getShape(r);if(!b)return;const C=t.getShapeUtil(b);let I=f.clone().sub(s).rot(-o).add(i);if(p&&a&&i.id!=="middle"){const j=E.Angle(a,I),U=By(j,24)-j;I=E.RotWith(I,a,U)}t.snaps.clearIndicators();let _={...i,x:I.x,y:I.y};if(i.canSnap&&(c?!m:m)){if(!t.getShapePageTransform(b.id))throw Error("Expected a page transform");const K=d.handles.snapHandle({currentShapeId:r,handle:_});K&&(K.nudge.rot(-t.getShapeParentTransform(b).rotation()),I.add(K.nudge),_={...i,x:I.x,y:I.y})}const T=(R=C.onHandleDrag)==null?void 0:R.call(C,b,{handle:_,isPrecise:this.isPrecise||y,initial:x}),A={id:b.id,type:b.type,...T};if(i.type==="vertex"&&this.editor.isShapeOfType(b,"arrow")){const j=ys(t,b)[i.id];j?l[0]!==j.toId&&(t.setHintingShapes([j.toId]),this.pointingId=j.toId,this.isPrecise=v.len()<.5||y,this.isPreciseId=this.isPrecise?j.toId:null,this.resetExactTimeout()):l.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}T&&t.updateShapes([A])}}O(L7,"id","dragging_handle");function F7(n){return n.isLabel?[n]:n instanceof bi?n.children.filter(e=>e.isLabel):[]}class z7 extends Ne{constructor(){super(...arguments);O(this,"hitShapeForPointerUp",null);O(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"),ba(this.editor),this.editor.select(r)}onExit(){var i;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null),ba.cancel();const r=this.editor.getShape(t),s=this.editor.getShapeUtil(r);(i=s.onEditEnd)==null||i.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":{ba(this.editor);return}}}onPointerDown(t){switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=vT(this.editor,!0);if(r){this.onPointerDown({...t,shape:r,target:"shape"});return}break}case"shape":{const{shape:r}=t,s=this.editor.getEditingShape();if(!s)throw Error("Expected an editing shape!");const i=this.editor.getShapeUtil(r).getGeometry(r),o=F7(i),a=o.length===1?o[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&br(this.editor,s.props.richText).trim()==="";if(a&&!l){const c=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(c,0)&&a.hitTestPoint(c)){if(r.id===s.id)return;this.hitShapeForPointerUp=r,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===s.id)this.editor.isShapeOfType(r,"frame")&&(this.editor.setEditingShape(null),this.parent.transition("idle",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)return;if(this.editor.getIsReadonly()&&!s.canEditInReadOnly(r)){this.parent.transition("pointing_shape",t);return}this.editor.select(r.id);const i=this.editor.getEditingShape(),o=i&&i.id!==r.id;this.editor.setEditingShape(r.id);const a=Pt.isIos||Pt.isAndroid;!a||!o?this.editor.emit("place-caret",{shapeId:r.id,point:t.point}):a&&o&&this.editor.emit("select-all-text",{shapeId:r.id}),ba(this.editor)}onComplete(t){this.parent.transition("idle",t)}onCancel(t){this.parent.transition("idle",t)}}O(z7,"id","editing_shape");function kL(n){const e=n.getOnlySelectedShape();return!!(e&&!n.isShapeOrAncestorLocked(e)&&n.getShapeUtil(e).canCrop(e))}function lv(n,e){const t=n.getSelectedShapeIds(),{currentPagePoint:r}=n.inputs,{shiftKey:s,altKey:i,accelKey:o}=e,a=s||o,l=n.getShapeAtPoint(r,{hitInside:!1,margin:n.options.hitTestMargin/n.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:c=>!c.isLocked});if(l){const c=n.getOutermostSelectableShape(l);if(a&&!i)n.cancelDoubleClick(),t.includes(c.id)?(n.markHistoryStoppingPoint("deselecting shape"),n.deselect(c)):(n.markHistoryStoppingPoint("shift selecting shape"),n.setSelectedShapes([...t,c.id]));else{let d;c===l||c.id===n.getFocusedGroupId()||t.includes(c.id)?d=l:d=c,d&&!t.includes(d.id)&&(n.markHistoryStoppingPoint("selecting shape"),n.select(d.id))}}else{if(a)return;{t.length>0&&(n.markHistoryStoppingPoint("selecting none"),n.selectNone());const c=n.getFocusedGroupId();if(ps(c)){const d=n.getShape(c);n.isPointInShape(d,r,{margin:0,hitInside:!0})||n.setFocusedGroup(null)}}}}const sve=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var xP;let ive=(xP=class extends Ne{onEnter(){this.parent.setCurrentToolIdMask(void 0),ba(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){ba.cancel()}onPointerMove(){ba(this.editor)}onPointerDown(e){const t=e.ctrlKey&&kL(this.editor);switch(e.target){case"canvas":{const r=vT(this.editor);if(r&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:o}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&IL(this.editor,o)){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,i;if(!(this.editor.inputs.shiftKey||e.phase!=="up")&&!(e.ctrlKey||e.shiftKey))switch(e.target){case"canvas":{const o=this.editor.getHoveredShape(),a=o&&!this.editor.isShapeOfType(o,"group")?o:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(a){if(this.editor.isShapeOfType(a,"group")){lv(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){lv(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 o=this.editor.getOnlySelectedShape();if(o){const a=this.editor.getShapeUtil(o);if(!this.canInteractWithShapeInReadOnly(o))return;if(e.handle==="right"||e.handle==="left"||e.handle==="top"||e.handle==="bottom"){const l=(t=a.onDoubleClickEdge)==null?void 0:t.call(a,o);if(l){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([l]),Ut(this.editor,[o.id]);return}}if(a.canCrop(o)&&!this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("crop",e);return}this.shouldStartEditingShape(o)&&this.startEditingShape(o,e,!0)}break}case"shape":{const{shape:o}=e,a=this.editor.getShapeUtil(o);if(o.type!=="video"&&o.type!=="embed"&&this.editor.getIsReadonly())break;if(a.onDoubleClick){const l=(r=a.onDoubleClick)==null?void 0:r.call(a,o);if(l){this.editor.updateShapes([l]);return}}if(a.canCrop(o)&&!this.editor.isShapeOrAncestorLocked(o)){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(o)?this.startEditingShape(o,e,!0):this.handleDoubleClickOnCanvas(e);break}case"handle":{if(this.editor.getIsReadonly())break;const{shape:o,handle:a}=e,l=this.editor.getShapeUtil(o),c=(i=l.onDoubleClickHandle)==null?void 0:i.call(l,o,a);c?this.editor.updateShapes([c]):this.shouldStartEditingShape(o)&&this.startEditingShape(o,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(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:o}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&IL(this.editor,o)){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,i=>!t.includes(i.id));!t.includes(s.id)&&!this.editor.findShapeAncestor(s,i=>t.includes(i.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(xn.editOnType.get()&&!sve.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}kL(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"),PS(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&&$s(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=Dt(),{x:r,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:t,type:"text",x:r,y:s,props:{richText:wi(""),autoSize:!0}}]);const i=this.editor.getShape(t);if(!i)return;const o=this.editor.getShapeUtil(i);this.editor.getIsReadonly()&&!o.canEditInReadOnly(i)||(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 E(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 E(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),o=this.editor.getInstanceState().isGridMode?r?i*lve:i:r?ove:ave,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,s.mul(o)),Ut(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},O(xP,"id","idle"),xP);const ove=10,ave=1,lve=5;function IL(n,e){const t=n.getSelectionRotatedPageBounds();if(!t)return!1;const r=n.getSelectionRotation();return r?$s(e,t.corners.map(s=>E.RotWith(s,t.point,r))):t.containsPoint(e)}class $7 extends Ne{constructor(){super(...arguments);O(this,"shapeId","");O(this,"markId","");O(this,"wasAlreadySelected",!1);O(this,"didDrag",!1);O(this,"didCtrlOnEnter",!1);O(this,"info",{});O(this,"_labelDragOffset",new E(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 i=this.editor.getShapeGeometry(r).children[1];if(!i)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:o}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,o);if(this._labelDragOffset=E.Sub(i.center,a),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),t.shiftKey||t.accelKey){const c=this.editor.getSelectedShapeIds();this.editor.setSelectedShapes([...c,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=Oo(this.editor,r),i=this.editor.getShapeGeometry(r),o=i.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=o.nearestPoint(E.Add(a,this._labelDragOffset));let c;if(s.isStraight){const d=E.Dist(s.start.point,s.end.point);c=1-E.Dist(s.end.point,l)/d}else{const{_center:d,measure:f,angleEnd:p,angleStart:m}=i.children[0];c=_P(f,m,p,d.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})}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")}}O($7,"id","pointing_arrow_label");class B7 extends Ne{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){lv(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}O(B7,"id","pointing_canvas");class U7 extends Ne{constructor(){super(...arguments);O(this,"didCtrlOnEnter",!1);O(this,"info",{})}onEnter(t){this.info=t,this.didCtrlOnEnter=t.accelKey;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const s=ys(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,i=_L(s,t,r,!1);if(i){PS(s,i,!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 i=_L(t,r,s,!0);if(i){const o=t.getPointInParentSpace(i,t.inputs.originPagePoint).sub(E.Rot(_0.clone().mul(r.props.scale),i.rotation));t.updateShape({...i,x:o.x,y:o.y}),t.setHoveredShape(i.id).select(i.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:t.getShape(i),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{PS(t,i,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}O(U7,"id","pointing_handle");function _L(n,e,t,r){const s=n.getShapePageTransform(e.id),i=s.point(),o=s.rotation(),l=Y9(n,i,o,e.props.growY*e.props.scale,0,e.props.scale)[t.index];if(l)return Z9(n,e,l,o,r)}class H7 extends Ne{constructor(){super(...arguments);O(this,"info",{})}updateCursor(){this.editor.setCursor({type:Xd[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")}}O(H7,"id","pointing_rotate_handle");class K7 extends Ne{constructor(){super(...arguments);O(this,"info",{})}onEnter(t){this.info=t}onPointerUp(t){lv(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 i,o;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"),(o=(i=this.parent).onDoubleClick)==null||o.call(i,{...t,target:"shape",shape:this.editor.getShape(s)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}O(K7,"id","pointing_selection");class W7 extends Ne{constructor(){super(...arguments);O(this,"hitShape",{});O(this,"hitShapeForPointerUp",{});O(this,"isDoubleClick",!1);O(this,"didCtrlOnEnter",!1);O(this,"didSelectOnEnter",!1)}onEnter(t){const r=this.editor.getSelectedShapeIds(),s=this.editor.getSelectionRotatedPageBounds(),i=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:o}}=this.editor,{shiftKey:a,altKey:l,accelKey:c}=t;this.hitShape=t.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=c;const d=this.editor.getOutermostSelectableShape(t.shape),f=this.editor.findShapeAncestor(d,p=>r.includes(p.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(t.shape).onClick||d.id===i||r.includes(d.id)||f||r.length>1&&(s!=null&&s.containsPoint(o))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=d;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(d.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,d.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([d.id]))}onPointerUp(t){var d;const r=this.editor.getSelectedShapeIds(),s=this.editor.getFocusedGroupId(),i=this.editor.getZoomLevel(),{inputs:{currentPagePoint:o}}=this.editor,a=t.shiftKey||t.accelKey,l=this.editor.getShapeAtPoint(o,{margin:this.editor.options.hitTestMargin/i,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const f=this.editor.getShapeUtil(c);if(f.onClick){const p=(d=f.onClick)==null?void 0:d.call(f,c);if(p){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",t);return}}if(c.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(l,p=>!r.includes(p.id));if(r.includes(f.id))if(a)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),m=F7(p),y=m.length===1?m[0]:void 0;if(y){const v=this.editor.getPointInShapeSpace(c,o);if(y.bounds.containsPoint(v,0)&&y.hitTestPoint(v)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(c.id);const x=this.editor.getShapeUtil(c);this.editor.getIsReadonly()&&!x.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick?this.editor.emit("select-all-text",{shapeId:c.id}):this.editor.emit("place-caret",{shapeId:c.id,point:t.point}))});return}}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c);else if(a){const p=this.editor.getShapeAncestors(f);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(m=>!p.find(y=>y.id===m)),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")}}O(W7,"id","pointing_shape");class V7 extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"markId","");O(this,"didHoldCommand",!1);O(this,"creationCursorOffset",{x:0,y:0});O(this,"snapshot",{})}onEnter(t){const{isCreating:r=!1,creatingMarkId:s,creationCursorOffset:i={x:0,y:0}}=t;this.info=t,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.creationCursorOffset=i;try{this.snapshot=this._createSnapshot()}catch(o){console.error(o),this.cancel();return}if(this.markId="",r)if(s)this.markId=s;else{const o=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);o&&(this.markId=o)}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(Ut(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 i=this.editor.getShapeUtil(s),o=(a=i.onResizeStart)==null?void 0:a.call(i,s);o&&r.push(o)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:s})=>{var l;const i=this.editor.getShape(s.id),o=this.editor.getShapeUtil(s),a=(l=o.onResizeEnd)==null?void 0:l.call(o,s,i);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:i,selectionBounds:o,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:d}=this.snapshot;let f=r||!d;if(i.size===1){const j=[...i.values()][0];this.editor.isShapeOfType(j.shape,"text")&&(f=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,m=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),y=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:j}=this.editor.getDocumentSettings();m.snapToGrid(j)}const v=this.info.handle,x=TL(v,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ht===0){const{nudge:j}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:E.Sub(m,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:TL(v,c),isAspectRatioLocked:f,isResizingFromCenter:t});m.add(j)}const C=E.RotWith(t?o.center:o.getHandlePoint(x),o.point,c),I=E.Sub(m,C).rot(-c),_=E.Sub(y,C).rot(-c),T=E.DivV(I,_);Number.isFinite(T.x)||(T.x=1),Number.isFinite(T.y)||(T.y=1);const A=v==="top"||v==="bottom",R=v==="left"||v==="right";f?R?T.y=Math.abs(T.x):A?T.x=Math.abs(T.y):Math.abs(T.x)>Math.abs(T.y)?T.y=Math.abs(T.x)*(T.y<0?-1:1):T.x=Math.abs(T.y)*(T.x<0?-1:1):(A&&(T.x=1),R&&(T.y=1)),this.info.isCreating||this.updateCursor({dragHandle:v,isFlippedX:T.x<0,isFlippedY:T.y<0,rotation:c});for(const j of i.keys()){const K=i.get(j);this.editor.resizeShape(j,T,{initialShape:K.shape,initialBounds:K.bounds,initialPageTransform:K.pageTransform,dragHandle:v,mode:l.length===1&&j===l[0]?"resize_bounds":"scale_shape",scaleOrigin:C,isAspectRatioLocked:f,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:j,children:K}of s){if(!K.length)continue;const U=i.get(j).shape,J=this.editor.getShape(j);if(!(U&&J))continue;const z=J.x-U.x,N=J.y-U.y,L=new E(z,N).rot(-U.rotation);if(L.x!==0||L.y!==0)for(const V of K)this.editor.updateShape({id:V.id,type:V.type,x:V.x-L.x,y:V.y-L.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:j}of s)if(j.length)for(const K of j)this.editor.updateShape({id:K.id,type:K.type,x:K.x,y:K.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:s,rotation:i}){const o={...this.editor.getInstanceState().cursor};switch(t){case"top_left":case"bottom_right":{o.type="nwse-resize",r!==s&&(o.type="nesw-resize");break}case"top_right":case"bottom_left":{o.type="nesw-resize",r!==s&&(o.type="nwse-resize");break}}o.rotation=i,this.editor.setCursor(o)}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,i=this.editor.getSelectionRotatedPageBounds();if(!i)throw Error("Resizing but nothing is selected");const o=E.RotWith(i.getHandlePoint(this.info.handle),i.point,r),a=E.Sub(s,o),l=new Map,c=[];t.forEach(f=>{const p=this.editor.getShape(f);if(p){if(p.type==="frame"&&c.push({id:f,children:st(this.editor.getSortedChildIdsForParent(p).map(m=>this.editor.getShape(m)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&t.length===1)return;this.editor.visitDescendants(p.id,m=>{const y=this.editor.getShape(m);if(y&&(l.set(y.id,this._createShapeSnapshot(y)),this.editor.isShapeOfType(y,"frame")))return!1})}});const d=![...l.values()].some(f=>!tF(f.pageRotation,r)||f.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:i,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:d,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}}_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:ve.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(t)}}}O(V7,"id","resizing");const YC=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function TL(n,e){e=e%Rt;const t=Math.round(e/(xt/4)),r=YC.indexOf(n);return YC[(r+t)%YC.length]}const ML=Math.PI/180;class q7 extends Ne{constructor(){super(...arguments);O(this,"snapshot",{});O(this,"info",{});O(this,"markId","")}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=Qz({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});iy({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:Xd[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});iy({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:Xd[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(){iy({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ut(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:i,currentPagePoint:o}}=this.editor,{initialCursorAngle:a,initialShapesRotation:l}=this.snapshot;if(!s)return l;const d=s.center.clone().rotWith(s.point,r).angle(o)-a;let f=l+d;if(i)f=By(f,24);else if(t&&(f=Math.round(f/ML)*ML,this.editor.getInstanceState().isCoarsePointer)){const p=By(f,4),m=Xm(f,p);Math.abs(m)<DG(5)&&(f=p)}return f-l}}O(q7,"id","rotating");class G7 extends Ne{constructor(){super(...arguments);O(this,"hits",new Set);O(this,"size",0);O(this,"scribbleId","id");O(this,"initialSelectedShapeIds",new Set);O(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:i,originPagePoint:o,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:d}=this;t&&this.pushPointToScribble();const f=s;let p,m,y,v;const x=0;for(let I=0,_=f.length;I<_;I++){if(p=f[I],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(m=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&m.bounds.containsPoint(r.getPointInShapeSpace(p,o))))continue;const T=r.getShapePageTransform(p);if(!m||!T)continue;const A=T.clone().invert();y=A.applyToPoint(a),v=A.applyToPoint(l);const{bounds:R}=m;if(!(R.minX-x>Math.max(y.x,v.x)||R.minY-x>Math.max(y.y,v.y)||R.maxX+x<Math.min(y.x,v.x)||R.maxY+x<Math.min(y.y,v.y))&&m.hitTestLineSegment(y,v,x)){const j=this.editor.getOutermostSelectableShape(p),K=this.editor.getShapeMask(j.id);if(K&&UI(a,l,K)!==null&&!$s(l,K))continue;c.add(j.id)}}const b=r.getSelectedShapeIds(),C=new Set(i?[...c,...d]:[...c]);(b.length!==C.size||b.some(I=>!C.has(I)))&&this.editor.setSelectedShapes(Array.from(C))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}O(G7,"id","scribble_brushing");var cve=Object.create,Y7=Object.defineProperty,uve=Object.getOwnPropertyDescriptor,dve=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),X7=n=>{throw TypeError(n)},Z7=(n,e,t)=>e in n?Y7(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,hve=n=>[,,,cve(null)],J7=["class","method","getter","setter","accessor","field","value","get","set"],Q7=n=>n!==void 0&&typeof n!="function"?X7("Function expected"):n,fve=(n,e,t,r,s)=>({kind:J7[n],name:e,metadata:r,addInitializer:i=>t._?X7("Already initialized"):s.push(Q7(i||null))}),pve=(n,e)=>Z7(e,dve("metadata"),n[3]),gve=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},mve=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=J7[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,uve(s,t)),b=r.length-1;b>=0;b--)l=fve(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,Q7(o)&&(x[y]=o);return x&&Y7(s,t,x),s},XC=(n,e,t)=>Z7(n,typeof e!="symbol"?e+"":e,t),eH,M0;const yve=20,Sve=100;eH=[vs];class wT{constructor(e){this.editor=e,gve(M0,5,this),XC(this,"prevDroppingShapeId",null),XC(this,"droppingNodeTimer",null),XC(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,i=>i.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,yve,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Sve,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 l,c,d,f,p;t=st(t.map(m=>this.editor.getShape(m.id)));const s=((l=this.editor.getDroppingOverShape(e,t))==null?void 0:l.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(t);return}const{prevDroppingShapeId:i}=this,o=i&&this.editor.getShape(i),a=s&&this.editor.getShape(s);o&&((d=(c=this.editor.getShapeUtil(o)).onDragShapesOut)==null||d.call(c,o,t)),a&&((p=(f=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.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 i=this.editor.findShapeAncestor(s,o=>o.type!=="group");i&&(t.has(i.id)||t.set(i.id,[]),t.get(i.id).push(s.id))}const r=[];for(const[s,i]of t){const o=this.editor.getShape(s);o&&OU(this.editor,o).length<i.length&&r.push(o.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,s;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),t){const i=this.editor.getShape(t);if(!i)return;(s=(r=this.editor.getShapeUtil(i)).onDropShapesOver)==null||s.call(r,i,e)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}dispose(){this.clear()}}M0=hve();mve(M0,1,"dispose",eH,wT);pve(M0,wT);var vve=Object.create,tH=Object.defineProperty,xve=Object.getOwnPropertyDescriptor,nH=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),rH=n=>{throw TypeError(n)},sH=(n,e,t)=>e in n?tH(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,wve=n=>[,,,vve((n==null?void 0:n[nH("metadata")])??null)],iH=["class","method","getter","setter","accessor","field","value","get","set"],oH=n=>n!==void 0&&typeof n!="function"?rH("Function expected"):n,bve=(n,e,t,r,s)=>({kind:iH[n],name:e,metadata:r,addInitializer:i=>t._?rH("Already initialized"):s.push(oH(i||null))}),Cve=(n,e)=>sH(e,nH("metadata"),n[3]),Pve=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},Eve=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=iH[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,xve(s,t)),b=r.length-1;b>=0;b--)l=bve(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,oH(o)&&(x[y]=o);return x&&tH(s,t,x),s},Sl=(n,e,t)=>sH(n,typeof e!="symbol"?e+"":e,t),aH,ik,A0;class O0 extends(ik=Ne,aH=[vs],ik){constructor(){super(...arguments),Pve(A0,5,this),Sl(this,"info",{}),Sl(this,"selectionSnapshot",{}),Sl(this,"snapshot",{}),Sl(this,"markId",""),Sl(this,"isCloning",!1),Sl(this,"isCreating",!1),Sl(this,"dragAndDropManager",new wT(this.editor))}onCreate(e){}onEnter(e){var i;const{isCreating:t=!1,creatingMarkId:r,onCreate:s=()=>{}}=e;if(!((i=this.editor.getSelectedShapeIds())!=null&&i.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 o=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);o&&(this.markId=o)}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=AL(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=AL(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),Ut(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 o;const s=this.editor.getShapeUtil(r),i=(o=s.onTranslateStart)==null?void 0:o.call(s,r);i&&t.push(i)}),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=E.Average(e.map(i=>this.editor.getShapePageTransform(i.id).point())),s=E.Sub(r,this.selectionSnapshot.averagePagePoint);E.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(i=>i.id),offset:{x:s.x,y:s.y}}})}const t=[];e.forEach(r=>{var a;const s=this.editor.getShape(r.id),i=this.editor.getShapeUtil(r),o=(a=i.onTranslateEnd)==null?void 0:a.call(i,r,s);o&&t.push(o)}),t.length>0&&this.editor.updateShapes(t)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),kve({editor:this.editor,snapshot:e});const{movingShapes:t}=e,r=[];t.forEach(s=>{var l;const i=this.editor.getShape(s.id),o=this.editor.getShapeUtil(s),a=(l=o.onTranslate)==null?void 0:l.call(o,s,i);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 i=ds(s.parentId)?null:ve.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=i})}}A0=wve(ik);Eve(A0,1,"updateParentTransforms",aH,O0);Cve(A0,O0);Sl(O0,"id","translating");function AL(n){var f;const e=[],t=[],r=n.getSelectedShapeIds(),s=st(r.map(p=>{const m=n.getShape(p);if(!m)return null;e.push(m);const y=n.getShapePageTransform(p),v=y.point(),x=y.rotation();t.push(v);const b=Vs.isId(m.parentId)?null:ve.Inverse(n.getShapePageTransform(m.parentId));return{shape:m,pagePoint:v,pageRotation:x,parentTransform:b}})),i=n.getOnlySelectedShape();let o=[];if(i)o=n.snaps.shapeBounds.getSnapPoints(i.id);else{const p=n.getSelectionPageBounds();p&&(o=p.cornersAndCenter.map((m,y)=>({id:"selection:"+y,x:m.x,y:m.y})))}let a,l;const{originPagePoint:c}=n.inputs,d=s.filter(p=>n.isShapeOfType(p.shape,"note")&&n.isPointInShape(p.shape,c));if(d.length!==0)if(d.length===1)l=d[0];else{const p=n.getCurrentPageShapesSorted();l=(f=d.map(m=>({snapshot:m,index:p.findIndex(y=>y.id===m.shape.id)})).sort((m,y)=>y.index-m.index)[0])==null?void 0:f.snapshot}return l&&(a=X9(n,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:E.Average(t),movingShapes:e,shapeSnapshots:s,initialPageBounds:n.getSelectionPageBounds(),initialSnapPoints:o,noteAdjacentPositions:a,noteSnapshot:l}}function kve({editor:n,snapshot:e}){const{inputs:t}=n,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:i,initialSnapPoints:o,shapeSnapshots:a,averagePagePoint:l}=e,c=n.getInstanceState().isGridMode,d=n.getDocumentSettings().gridSize,f=E.Sub(t.currentPagePoint,t.originPagePoint),p=n.inputs.shiftKey?Math.abs(f.x)<Math.abs(f.y)?"x":"y":null;p==="x"?f.x=0:p==="y"&&(f.y=0),n.snaps.clearIndicators();const m=n.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey;let y=!1;if(m&&n.inputs.pointerVelocity.len()<.5){const{nudge:C}=n.snaps.shapeBounds.snapTranslateShapes({dragDelta:f,initialSelectionPageBounds:i,lockedAxis:p,initialSelectionSnapPoints:o});f.add(C)}else if(r&&s){const{scale:C}=r.shape.props,I=r.pagePoint.clone().add(f).add(_0.clone().mul(C).rot(r.pageRotation));let _=G9/n.getZoomLevel(),T=new E(0,0);for(const A of s){const R=E.Sub(I,A),j=R.len();j<_&&(y=!0,_=j,T=R)}f.sub(T)}const v=E.Add(l,f),x=n.snaps.getIndicators();c&&!t.ctrlKey&&!y&&x.length===0&&v.snapToGrid(d);const b=E.Sub(v,l);n.updateShapes(st(a.map(({shape:C,pagePoint:I,parentTransform:_})=>{const T=E.Add(I,b),A=_?ve.applyToPoint(_,T):T;return{id:C.id,type:C.type,x:A.x,y:A.y}})))}class Ay extends Ne{constructor(){super(...arguments);O(this,"reactor")}static children(){return[sk,ST,ive,B7,W7,O0,O7,G7,xT,K7,R7,z7,V7,q7,H7,$7,U7,L7]}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(i=>s.has(i))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=qi("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)}}O(Ay,"id","select"),O(Ay,"initial","idle"),O(Ay,"isLockable",!1);class lH extends Ne{constructor(){super(...arguments);O(this,"info",{})}onEnter(t){this.info=t}onPointerDown(){this.parent.transition("pointing",this.info)}}O(lH,"id","idle");class cH extends Ne{constructor(){super(...arguments);O(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)}}O(cH,"id","pointing");class uH extends Ne{constructor(){super(...arguments);O(this,"info",{});O(this,"zoomBrush",new ye)}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(ye.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)}}O(uH,"id","zoom_brushing");class Oy extends Ne{constructor(){super(...arguments);O(this,"info",{})}static children(){return[lH,uH,cH]}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})}}O(Oy,"id","zoom"),O(Oy,"initial","idle"),O(Oy,"isLockable",!1);const Ive=[_y,Ty,My,Oy,Ay];function _ve(){const n=te(),e=ie("follow",()=>n.getInstanceState().followingUserId,[n]);return e?g.jsx(Tve,{userId:e}):null}function Tve({userId:n}){const e=Hv(n);return e?g.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let ok={fonts:{tldraw_mono:`${Pn()}/fonts/IBMPlexMono-Medium.woff2`,tldraw_mono_italic:`${Pn()}/fonts/IBMPlexMono-MediumItalic.woff2`,tldraw_mono_bold:`${Pn()}/fonts/IBMPlexMono-Bold.woff2`,tldraw_mono_italic_bold:`${Pn()}/fonts/IBMPlexMono-BoldItalic.woff2`,tldraw_serif:`${Pn()}/fonts/IBMPlexSerif-Medium.woff2`,tldraw_serif_italic:`${Pn()}/fonts/IBMPlexSerif-MediumItalic.woff2`,tldraw_serif_bold:`${Pn()}/fonts/IBMPlexSerif-Bold.woff2`,tldraw_serif_italic_bold:`${Pn()}/fonts/IBMPlexSerif-BoldItalic.woff2`,tldraw_sans:`${Pn()}/fonts/IBMPlexSans-Medium.woff2`,tldraw_sans_italic:`${Pn()}/fonts/IBMPlexSans-MediumItalic.woff2`,tldraw_sans_bold:`${Pn()}/fonts/IBMPlexSans-Bold.woff2`,tldraw_sans_italic_bold:`${Pn()}/fonts/IBMPlexSans-BoldItalic.woff2`,tldraw_draw:`${Pn()}/fonts/Shantell_Sans-Informal_Regular.woff2`,tldraw_draw_italic:`${Pn()}/fonts/Shantell_Sans-Informal_Regular_Italic.woff2`,tldraw_draw_bold:`${Pn()}/fonts/Shantell_Sans-Informal_Bold.woff2`,tldraw_draw_italic_bold:`${Pn()}/fonts/Shantell_Sans-Informal_Bold_Italic.woff2`}};function Mve(n){return P.useMemo(()=>n?{fonts:{...ok.fonts,...n==null?void 0:n.fonts}}:ok,[n])}const Ave=["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","bold","bring-forward","bring-to-front","broken","bulletList","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","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","heading","highlight","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","italic","leading","link","list","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","strike","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","underline","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let lf={...ok,icons:Object.fromEntries(Ave.map(n=>[n,`${Pn()}/icons/icon/0_merged.svg#${n}`])),translations:Object.fromEntries(op.map(n=>[n.locale,`${Pn()}/translations/${n.locale}.json`])),embedIcons:Object.fromEntries(N_.map(n=>[n.type,`${Pn()}/embed-icons/${n.type}.png`]))};function Ove(n){return n?{fonts:Object.assign({...lf.fonts},{...n==null?void 0:n.fonts}),icons:Object.assign({...lf.icons},{...n==null?void 0:n.icons}),embedIcons:Object.assign({...lf.embedIcons},{...n==null?void 0:n.embedIcons}),translations:Object.assign({...lf.translations},{...n==null?void 0:n.translations})}:lf}var bT="Popover",[dH,_1e]=Vo(bT,[d0]),Jp=d0(),[Rve,tc]=dH(bT),hH=n=>{const{__scopePopover:e,children:t,open:r,defaultOpen:s,onOpenChange:i,modal:o=!1}=n,a=Jp(e),l=P.useRef(null),[c,d]=P.useState(!1),[f=!1,p]=Ql({prop:r,defaultProp:s,onChange:i});return g.jsx(f_,{...a,children:g.jsx(Rve,{scope:e,contentId:_a(),triggerRef:l,open:f,onOpenChange:p,onOpenToggle:P.useCallback(()=>p(m=>!m),[p]),hasCustomAnchor:c,onCustomAnchorAdd:P.useCallback(()=>d(!0),[]),onCustomAnchorRemove:P.useCallback(()=>d(!1),[]),modal:o,children:t})})};hH.displayName=bT;var fH="PopoverAnchor",Dve=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=tc(fH,t),i=Jp(t),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=s;return P.useEffect(()=>(o(),()=>a()),[o,a]),g.jsx(p_,{...i,...r,ref:e})});Dve.displayName=fH;var pH="PopoverTrigger",gH=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=tc(pH,t),i=Jp(t),o=Kt(e,s.triggerRef),a=g.jsx(wt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":xH(s.open),...r,ref:o,onClick:De(n.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:g.jsx(p_,{asChild:!0,...i,children:a})});gH.displayName=pH;var CT="PopoverPortal",[jve,Nve]=dH(CT,{forceMount:void 0}),mH=n=>{const{__scopePopover:e,forceMount:t,children:r,container:s}=n,i=tc(CT,e);return g.jsx(jve,{scope:e,forceMount:t,children:g.jsx(so,{present:t||i.open,children:g.jsx(Wp,{asChild:!0,container:s,children:r})})})};mH.displayName=CT;var Zd="PopoverContent",yH=P.forwardRef((n,e)=>{const t=Nve(Zd,n.__scopePopover),{forceMount:r=t.forceMount,...s}=n,i=tc(Zd,n.__scopePopover);return g.jsx(so,{present:r||i.open,children:i.modal?g.jsx(Lve,{...s,ref:e}):g.jsx(Fve,{...s,ref:e})})});yH.displayName=Zd;var Lve=P.forwardRef((n,e)=>{const t=tc(Zd,n.__scopePopover),r=P.useRef(null),s=Kt(e,r),i=P.useRef(!1);return P.useEffect(()=>{const o=r.current;if(o)return g_(o)},[]),g.jsx(p0,{as:tu,allowPinchZoom:!0,children:g.jsx(SH,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:De(n.onCloseAutoFocus,o=>{var a;o.preventDefault(),i.current||(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:De(n.onPointerDownOutside,o=>{const a=o.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;i.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:De(n.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Fve=P.forwardRef((n,e)=>{const t=tc(Zd,n.__scopePopover),r=P.useRef(!1),s=P.useRef(!1);return g.jsx(SH,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var o,a;(o=n.onCloseAutoFocus)==null||o.call(n,i),i.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),i.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:i=>{var l,c;(l=n.onInteractOutside)==null||l.call(n,i),i.defaultPrevented||(r.current=!0,i.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const o=i.target;((c=t.triggerRef.current)==null?void 0:c.contains(o))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&s.current&&i.preventDefault()}})}),SH=P.forwardRef((n,e)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:d,...f}=n,p=tc(Zd,t),m=Jp(t);return r_(),g.jsx(a0,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:i,children:g.jsx(Hp,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:d,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:g.jsx(o8,{"data-state":xH(p.open),role:"dialog",id:p.contentId,...m,...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)"}})})})}),vH="PopoverClose",zve=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=tc(vH,t);return g.jsx(wt.button,{type:"button",...r,ref:e,onClick:De(n.onClick,()=>s.onOpenChange(!1))})});zve.displayName=vH;var $ve="PopoverArrow",Bve=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Jp(t);return g.jsx(a8,{...s,...r,ref:e})});Bve.displayName=$ve;function xH(n){return n?"open":"closed"}var PT=hH,ET=gH,kT=mH,IT=yH;function _T({id:n,children:e,onOpenChange:t,open:r}){const[s,i]=Ua(n,t);return g.jsx(PT,{onOpenChange:i,open:r||s,children:g.jsx("div",{className:"tlui-popover",children:e})})}function TT({children:n}){return g.jsx(ET,{asChild:!0,dir:"ltr",children:n})}function MT({side:n,children:e,align:t="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:i=!1}){const o=In();return g.jsx(kT,{container:o,children:g.jsx(IT,{className:"tlui-popover__content",side:n,sideOffset:r,align:t,alignOffset:s,dir:"ltr",onEscapeKeyDown:a=>i&&a.preventDefault(),children:e})})}function Uve(n){return n.getSelectedShapeIds().map(r=>n.getShape(r)).filter(r=>{if(!r)return!1;if(n.isShapeOfType(r,"arrow")){const s=ys(n,r);if(s.start||s.end)return!1}return!0})}const wH=()=>{const n=te();return ie("threeStackableItems",()=>Uve(n).length>2,[n])},Ha=()=>{const n=te();return ie("isInSelectState",()=>n.isIn("select"),[n])},bH=()=>{const n=te();return ie("allow group",()=>{const e=n.getSelectedShapes();if(e.length<2)return!1;for(const t of e)if(n.isShapeOfType(t,"arrow")){const r=ys(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])},CH=()=>{const n=te();return ie("allowUngroup",()=>n.getSelectedShapeIds().some(e=>{var t;return((t=n.getShape(e))==null?void 0:t.type)==="group"}),[n])},Hve=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function PH(n,e){const t=te();return ie("selectedShapes",()=>t.getSelectedShapes().length>=n,[t,n,e])}function Gr(n,e){const t=te();return ie("selectedShapes",()=>{const r=t.getSelectedShapes().filter(s=>!t.isShapeOrAncestorLocked(s)).length;return n===void 0?r:r>=n},[t])}function Kve(){const n=te();return ie("showAutoSizeToggle",()=>{const e=n.getSelectedShapes();return e.length===1&&n.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[n])}function EH(){const n=te();return ie("hasLinkShapeSelected",()=>{const e=n.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[n])}function Wve(){const n=te();return ie("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 kH(){const n=te();return ie("useCanRedo",()=>n.getCanRedo(),[n])}function IH(){const n=te();return ie("useCanUndo",()=>n.getCanUndo(),[n])}function Vve(){return g.jsxs(g.Fragment,{children:[g.jsx(qve,{}),g.jsx(Gve,{}),g.jsx(Yve,{}),g.jsx(Xve,{}),g.jsx(Zve,{}),g.jsx(e0e,{}),g.jsx(t0e,{}),g.jsx(n0e,{})]})}function qve(){const n=Gr(2),e=Ha(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"align-left",disabled:!t}),g.jsx(ue,{actionId:"align-center-horizontal",disabled:!t}),g.jsx(ue,{actionId:"align-right",disabled:!t}),g.jsx(ue,{actionId:"stretch-horizontal",disabled:!t}),g.jsx(ue,{actionId:"align-top",disabled:!t}),g.jsx(ue,{actionId:"align-center-vertical",disabled:!t}),g.jsx(ue,{actionId:"align-bottom",disabled:!t}),g.jsx(ue,{actionId:"stretch-vertical",disabled:!t})]})}function Gve(){const n=Gr(3),e=Ha(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"distribute-horizontal",disabled:!t}),g.jsx(ue,{actionId:"distribute-vertical",disabled:!t})]})}function Yve(){const n=wH(),e=Ha(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"stack-horizontal",disabled:!t}),g.jsx(ue,{actionId:"stack-vertical",disabled:!t})]})}function Xve(){const n=Gr(1),e=Ha(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"send-to-back",disabled:!t}),g.jsx(ue,{actionId:"send-backward",disabled:!t}),g.jsx(ue,{actionId:"bring-forward",disabled:!t}),g.jsx(ue,{actionId:"bring-to-front",disabled:!t})]})}function Zve(){return qr()<gn.TABLET_SM?g.jsx(Jve,{}):g.jsx(Qve,{})}function Jve(){const n=te(),e=ie("zoom is 1",()=>n.getZoomLevel()===1,[n]);return g.jsx(ue,{actionId:"zoom-to-100",disabled:e})}function Qve(){const n=Gr(1),e=Ha(),t=n&&e;return g.jsx(ue,{actionId:"rotate-ccw",disabled:!t})}function e0e(){const n=Gr(1),e=Ha(),t=n&&e;return g.jsx(ue,{actionId:"rotate-cw",disabled:!t})}function t0e(){const n=EH(),e=Ha(),t=n&&e;return g.jsx(ue,{actionId:"edit-link",disabled:!t})}function n0e(){const n=bH(),e=CH();return n?g.jsx(OL,{}):e?g.jsx(r0e,{}):g.jsx(OL,{})}function OL(){const n=Gr(2),e=Ha(),t=n&&e;return g.jsx(ue,{actionId:"group",disabled:!t})}function r0e(){return g.jsx(ue,{actionId:"ungroup"})}const s0e=P.memo(function({children:e}){const t=ft(),r=qr(),s=Ys(),i=P.useRef(null);$a(i);const o=te(),a=ie("should display quick actions when in readonly",()=>o.isInAny("hand","zoom"),[o]),l=e??g.jsx(Vve,{});if(!(s&&!a))return g.jsxs(_T,{id:"actions-menu",children:[g.jsx(TT,{children:g.jsx(Ke,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:g.jsx(ct,{icon:"dots-vertical",small:!0})})}),g.jsx(MT,{side:r>=gn.TABLET?"bottom":"top",sideOffset:6,children:g.jsx("div",{ref:i,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:g.jsx(Ci,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function _H(){return Kve()?g.jsx(ue,{actionId:"toggle-auto-size"}):null}function TH(){return EH()?g.jsx(ue,{actionId:"edit-link"}):null}function i0e(){return Gr(1)?g.jsx(ue,{actionId:"duplicate"}):null}function MH(){const n=te();return ie("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const r=n.getOnlySelectedShape();return!(r&&n.isShapeOfType(r,"image"))},[n])?g.jsx(ue,{actionId:"flatten-to-image"}):null}function AH(){return bH()?g.jsx(ue,{actionId:"group"}):null}function OH(){return CH()?g.jsx(ue,{actionId:"ungroup"}):null}function RH(){const n=te();return ie("allow unframe",()=>{const t=n.getSelectedShapes();return t.length===0?!1:t.every(r=>n.isShapeOfType(r,"frame"))},[n])?g.jsx(ue,{actionId:"remove-frame"}):null}function DH(){const n=te();return ie("allow fit frame to content",()=>{const t=n.getOnlySelectedShape();return t?n.isShapeOfType(t,"frame")&&n.getSortedChildIdsForParent(t).length>0:!1},[n])?g.jsx(ue,{actionId:"fit-frame-to-content"}):null}function jH(){const n=te();return ie("selected shapes",()=>n.getSelectedShapes().length>0,[n])?g.jsx(ue,{actionId:"toggle-lock"}):null}function AT(){const n=te(),e=ie("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return g.jsx(oo,{actionId:"toggle-transparent",checked:e,toggle:!0})}function o0e(){const n=te(),e=ie("any shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsx(ue,{actionId:"unlock-all",disabled:!e})}function NH(){const n=te(),e=ie("zoomed to 100",()=>n.getZoomLevel()===1,[n]);return g.jsx(ue,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function LH(){const n=te(),e=ie("has shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsx(ue,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function FH(){const n=te(),e=ie("has shapes",()=>n.getSelectedShapeIds().length>0,[n]);return g.jsx(ue,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function zH(){return g.jsxs(lt,{id:"clipboard",children:[g.jsx(l0e,{}),g.jsx(c0e,{}),g.jsx(u0e,{}),g.jsx(i0e,{}),g.jsx(d0e,{})]})}function a0e(){var t;const n=te(),e=ie("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsxs(ks,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[g.jsxs(lt,{id:"copy-as-group",children:[g.jsx(ue,{actionId:"copy-as-svg"}),!!((t=window.navigator.clipboard)!=null&&t.write)&&g.jsx(ue,{actionId:"copy-as-png"})]}),g.jsx(lt,{id:"copy-as-bg",children:g.jsx(AT,{})})]})}function l0e(){const n=Gr(1);return g.jsx(ue,{actionId:"cut",disabled:!n})}function c0e(){const n=PH(1);return g.jsx(ue,{actionId:"copy",disabled:!n})}function u0e(){const n=Hve;return g.jsx(ue,{actionId:"paste",disabled:!n})}function $H(){const n=te();return ie("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n])?g.jsxs(lt,{id:"conversions",children:[g.jsx(a0e,{}),g.jsxs(ks,{id:"export-as",label:"context-menu.export-as",size:"small",children:[g.jsxs(lt,{id:"export-as-group",children:[g.jsx(ue,{actionId:"export-as-svg"}),g.jsx(ue,{actionId:"export-as-png"})]}),g.jsx(lt,{id:"export-as-bg",children:g.jsx(AT,{})})]})]}):null}function BH(){const n=te(),e=ie("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsx(ue,{actionId:"select-all",disabled:!e})}function d0e(){const n=Gr(1);return g.jsx(ue,{actionId:"delete",disabled:!n})}function h0e(){const n=Ys();return!PH(1)||n?null:g.jsxs(ks,{id:"edit",label:"context-menu.edit",size:"small",children:[g.jsx(AH,{}),g.jsx(OH,{}),g.jsx(MH,{}),g.jsx(TH,{}),g.jsx(DH,{}),g.jsx(RH,{}),g.jsx(HH,{}),g.jsx(UH,{}),g.jsx(_H,{}),g.jsx(jH,{})]})}function f0e(){const n=Gr(2),e=Wve();return Ys()||!(n||e)?null:g.jsxs(ks,{id:"arrange",label:"context-menu.arrange",size:"small",children:[n&&g.jsxs(lt,{id:"align",children:[g.jsx(ue,{actionId:"align-left"}),g.jsx(ue,{actionId:"align-center-horizontal"}),g.jsx(ue,{actionId:"align-right"}),g.jsx(ue,{actionId:"align-top"}),g.jsx(ue,{actionId:"align-center-vertical"}),g.jsx(ue,{actionId:"align-bottom"})]}),g.jsx(p0e,{}),n&&g.jsxs(lt,{id:"stretch",children:[g.jsx(ue,{actionId:"stretch-horizontal"}),g.jsx(ue,{actionId:"stretch-vertical"})]}),(n||e)&&g.jsxs(lt,{id:"flip",children:[g.jsx(ue,{actionId:"flip-horizontal"}),g.jsx(ue,{actionId:"flip-vertical"})]}),g.jsx(g0e,{})]})}function p0e(){return Gr(3)?g.jsxs(lt,{id:"distribute",children:[g.jsx(ue,{actionId:"distribute-horizontal"}),g.jsx(ue,{actionId:"distribute-vertical"})]}):null}function g0e(){const n=Gr(2),e=wH();return n?g.jsxs(lt,{id:"order",children:[g.jsx(ue,{actionId:"pack"}),e&&g.jsx(ue,{actionId:"stack-horizontal"}),e&&g.jsx(ue,{actionId:"stack-vertical"})]}):null}function m0e(){const n=Ys(),e=Gr(1);return n||!e?null:g.jsx(ks,{id:"reorder",label:"context-menu.reorder",size:"small",children:g.jsxs(lt,{id:"reorder",children:[g.jsx(ue,{actionId:"bring-to-front"}),g.jsx(ue,{actionId:"bring-forward"}),g.jsx(ue,{actionId:"send-backward"}),g.jsx(ue,{actionId:"send-to-back"})]})})}function y0e(){const n=te(),e=ie("pages",()=>n.getPages(),[n]),t=ie("current page id",()=>n.getCurrentPageId(),[n]),{addToast:r}=Ba(),s=Rn(),i=Ys();return!Gr(1)||i?null:g.jsxs(ks,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[g.jsx(lt,{id:"pages",children:e.map(a=>g.jsx(nr,{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 l=n.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{n.markHistoryStoppingPoint("change-page"),n.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),g.jsx(lt,{id:"new-page",children:g.jsx(ue,{actionId:"move-to-new-page"})})]})}function UH(){const n=te();return ie("oneEmbedSelected",()=>{const t=n.getOnlySelectedShape();return t?!!(n.isShapeOfType(t,"embed")&&t.props.url&&!n.isShapeOrAncestorLocked(t)):!1},[n])?g.jsx(ue,{actionId:"convert-to-bookmark"}):null}function HH(){const n=te(),e=L_();return ie("oneEmbeddableBookmarkSelected",()=>{const r=n.getOnlySelectedShape();return r?!!(n.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!n.isShapeOrAncestorLocked(r)):!1},[n])?g.jsx(ue,{actionId:"convert-to-embed"}):null}function S0e(){const n=te(),e=ie("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return g.jsx(oo,{actionId:"toggle-snap-mode",checked:e})}function v0e(){const n=te(),e=ie("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return g.jsx(oo,{actionId:"toggle-tool-lock",checked:e})}function x0e(){const n=te(),e=ie("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return g.jsx(oo,{actionId:"toggle-grid",checked:e})}function w0e(){const n=te(),e=ie("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return g.jsx(oo,{actionId:"toggle-wrap-mode",checked:e})}function b0e(){const n=te(),e=ie("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return g.jsx(oo,{actionId:"toggle-focus-mode",checked:e})}function C0e(){const n=te(),e=ie("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return g.jsx(oo,{actionId:"toggle-edge-scrolling",checked:e===1})}function P0e(){const n=te(),e=ie("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return g.jsx(oo,{actionId:"toggle-reduce-motion",checked:e===0})}function E0e(){const n=te(),e=ie("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return g.jsx(oo,{actionId:"toggle-debug-mode",checked:e})}function k0e(){const n=te(),e=ie("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return g.jsx(oo,{actionId:"toggle-dynamic-size-mode",checked:e})}function I0e(){const n=te(),e=ie("paste at cursor",()=>n.user.getIsPasteAtCursorMode(),[n]);return g.jsx(oo,{actionId:"toggle-paste-at-cursor",checked:e})}function _0e(){const n=te();return ie("show cursor chat",()=>n.getCurrentToolId()==="select"&&!n.getInstanceState().isCoarsePointer,[n])?g.jsx(ue,{actionId:"open-cursor-chat"}):null}function T0e(){const n=te(),e=w0(),t=ie("isSelectToolActive",()=>n.getCurrentToolId()==="select",[n]),r=ie("isSinglePageMode",()=>n.options.maxPages<=1,[n]);return t?g.jsxs(g.Fragment,{children:[e&&g.jsx(_0e,{}),g.jsxs(lt,{id:"modify",children:[g.jsx(h0e,{}),g.jsx(f0e,{}),g.jsx(m0e,{}),!r&&g.jsx(y0e,{})]}),g.jsx(zH,{}),g.jsx($H,{}),g.jsx(lt,{id:"select-all",children:g.jsx(BH,{})})]}):null}const M0e=P.memo(function({children:e,disabled:t=!1}){const r=te(),{Canvas:s}=Zt(),i=P.useCallback(d=>{if(d){if(r.getInstanceState().isCoarsePointer){const f=r.getSelectedShapes(),{inputs:{currentPagePoint:p}}=r,m=r.getShapesAtPoint(p);if(!r.getSelectedShapes().length||!m.some(y=>f.includes(y))){const y=m.filter(v=>r.isShapeOrAncestorLocked(v));y.length&&r.select(...y.map(v=>v.id))}}}else{const f=r.getOnlySelectedShape();f&&r.isShapeOrAncestorLocked(f)&&r.setSelectedShapes([])}},[r]),o=In(),[a,l]=Ua("context menu",i),c=e??g.jsx(T0e,{});return g.jsxs(kde,{dir:"ltr",onOpenChange:l,modal:!1,children:[g.jsx(Ide,{onContextMenu:void 0,dir:"ltr",disabled:t,children:s?g.jsx(s,{}):null}),a&&g.jsx(_de,{container:o,children:g.jsx(Tde,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:tt,children:g.jsx(Ci,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),A0e=2e3,O0e=5e3,R0e=Vn(function(){const e=te(),{isChatting:t,chatMessage:r}=e.getInstanceState(),s=P.useRef(-1),[i,o]=P.useState("");return P.useEffect(()=>{if(!t&&r||t){const l=t?O0e:A0e;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),o(""),e.focus()},l)}return()=>{clearTimeout(s.current)}},[e,r,t]),t?g.jsx(j0e,{value:i,setValue:o,chatMessage:r}):r.trim()?g.jsx(D0e,{chatMessage:r}):null});function KH(n){const e=te();P.useLayoutEffect(()=>{var o;if(!n.current)return;const{x:r,y:s}=e.inputs.currentScreenPoint;(o=n.current)==null||o.style.setProperty("transform",`translate(${r}px, ${s}px)`);function i(a){var d;const{minX:l,minY:c}=e.getViewportScreenBounds();(d=n.current)==null||d.style.setProperty("transform",`translate(${a.clientX-l}px, ${a.clientY-c}px)`)}return window.addEventListener("pointermove",i),()=>{window.removeEventListener("pointermove",i)}},[n,e])}const D0e=({chatMessage:n})=>{const e=te(),t=P.useRef(null);return KH(t),g.jsx("div",{ref:t,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:n})},j0e=Vn(function({chatMessage:e,value:t,setValue:r}){const s=te(),i=ft(),o=P.useRef(null),a=e||i("cursor-chat.type-to-chat");KH(o),P.useLayoutEffect(()=>{const p=o.current;if(!p)return;const m=s.textMeasure.measureText(t||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});p.style.setProperty("width",m.w+"px")},[s,t,a]),P.useLayoutEffect(()=>{const p=s.timers.requestAnimationFrame(()=>{var m;(m=o.current)==null||m.focus()});return()=>{cancelAnimationFrame(p)}},[s]);const l=P.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=P.useCallback(p=>{const{value:m}=p.target;r(m.slice(0,64)),s.updateInstanceState({chatMessage:m})},[s,r]),d=P.useCallback(p=>{const m=o.current;if(!m)return;const{value:y}=m;switch(p.key){case"Enter":{if(tt(p),p.stopPropagation(),!y){l();return}r("");break}case"Escape":{tt(p),p.stopPropagation(),l();break}}},[l,r]),f=P.useCallback(p=>{p.stopPropagation()},[]);return g.jsx("input",{ref:o,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:l,onChange:c,onKeyDown:d,onPaste:f,value:t,placeholder:a,spellCheck:!1})});function ak({checked:n}){return g.jsx(Bo,{icon:n?"check":"none",className:"tlui-button__icon",small:!0})}function N0e(){const n=te(),{addToast:e}=Ba(),{addDialog:t}=Xp(),[r,s]=He.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(lt,{id:"items",children:[g.jsx(nr,{id:"add-toast",onSelect:()=>{e({id:_t(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:_t(),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:_t(),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:_t(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),g.jsx(nr,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:i})=>g.jsx(z0e,{displayDontShowAgain:!0,onCancel:()=>i(),onContinue:()=>i()}),onClose:()=>{}})}}),g.jsx(nr,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>$0e(n,100)}),g.jsx(nr,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const i=n.getSelectedShapes(),o=i.length===0?n.getRenderingShapes():i;window.alert(`Shapes ${o.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),g.jsx(nr,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"}),g.jsx(nr,{id:"hard-reset",onSelect:dz,label:"Hard reset"})]}),g.jsxs(lt,{id:"flags",children:[g.jsx(L0e,{}),g.jsx(F0e,{})]})]})}function L0e(){const n=Object.values(xn);return n.length?g.jsx(ks,{id:"debug flags",label:"Debug Flags",children:g.jsx(lt,{id:"debug flags",children:n.map(e=>g.jsx(WH,{flag:e},e.name))})}):null}function F0e(){const n=Object.values(Vte);return n.length?g.jsx(ks,{id:"feature flags",label:"Feature Flags",children:g.jsx(lt,{id:"feature flags",children:n.map(e=>g.jsx(WH,{flag:e},e.name))})}):null}function z0e({title:n="title",body:e="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:i,onContinue:o}){const[a,l]=He.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(S0,{children:[g.jsx(v0,{children:n}),g.jsx(x0,{})]}),g.jsx(fp,{style:{maxWidth:350},children:e}),g.jsxs(j_,{className:"tlui-dialog__footer__actions",children:[s&&g.jsxs(Ke,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[g.jsx(ak,{checked:a}),g.jsx(wn,{children:"Don’t show again"})]}),g.jsx(Ke,{type:"normal",onClick:i,children:g.jsx(wn,{children:t})}),g.jsx(Ke,{type:"primary",onClick:async()=>o(),children:g.jsx(wn,{children:r})})]})]})}const WH=Vn(function({flag:e,onChange:t}){const r=e.get();return g.jsx(E0,{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 RL=0;function $0e(n,e){const t=Array(e),r=Math.floor(Math.sqrt(e));for(let s=0;s<e;s++)RL++,t[s]={id:Dt("box"+RL),type:"geo",x:s%r*132,y:Math.floor(s/r)*132};n.run(()=>{n.createShapes(t).setSelectedShapes(t.map(s=>s.id))})}function B0e({children:n}){const e=n??g.jsx(N0e,{});return g.jsxs(su,{id:"debug",children:[g.jsx(iu,{children:g.jsx(Ke,{type:"icon",title:"Debug menu",children:g.jsx(ct,{icon:"dots-horizontal"})})}),g.jsx(ou,{side:"top",align:"end",alignOffset:0,children:g.jsx(Ci,{type:"menu",sourceId:"debug-panel",children:e})})]})}const U0e=P.memo(function(){const{DebugMenu:e}=nc(),t=P.useRef(null);return $a(t),g.jsxs("div",{ref:t,className:"tlui-debug-panel",children:[g.jsx(K0e,{}),g.jsx(W0e,{}),e&&g.jsx(e,{})]})});function H0e(n=!0){const[e,t]=P.useState(0),r=te();P.useEffect(()=>{if(!n)return;const s=()=>t(i=>i+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const K0e=Vn(function(){H0e();const e=te(),t=e.getPath(),r=e.getHoveredShape(),s=e.getOnlySelectedShape(),i=t==="select.idle"||!t.includes("select.")?r:s,o=i&&t.includes("select.")?` / ${i.type||""}${"geo"in i.props?" / "+i.props.geo:""} / [${E.ToInt(e.getPointInShapeSpace(i,e.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${E.ToInt(e.inputs.originPagePoint)}] → [${E.ToInt(e.inputs.currentPagePoint)}] = ${E.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return g.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${o}${a}`})});function W0e(){const n=te(),e=ie("show_fps",()=>xn.showFps.get(),[xn]),t=P.useRef(null);return P.useEffect(()=>{if(!e)return;const r=250;let s=0,i=-1,o=performance.now(),a=0,l=0,c=!1;function d(){if(l++,a=performance.now()-o,a>r){const f=Math.round(l*(r/a)*(1e3/r));f>s&&(s=f);const p=s*.75;(f<p&&!c||f>=p&&c)&&(c=!c),t.current.innerHTML=`FPS ${f.toString()}`,t.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,o=performance.now()}i=n.timers.requestAnimationFrame(d)}return d(),()=>{cancelAnimationFrame(i)}},[e,n]),e?g.jsx("div",{ref:t}):null}const V0e=P.memo(function(){const e=qr(),t=P.useRef(null);$a(t);const{MainMenu:r,QuickActions:s,ActionsMenu:i,PageMenu:o}=nc(),a=te(),l=ie("isSinglePageMode",()=>a.options.maxPages<=1,[a]),c=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=gn.TABLET;return!r&&!o&&!c?null:g.jsx("div",{ref:t,className:"tlui-menu-zone",children:g.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&g.jsx(r,{}),o&&!l&&g.jsx(o,{}),c?g.jsxs(g.Fragment,{children:[s&&g.jsx(s,{}),i&&g.jsx(i,{})]}):null]})})});function q0e(){const n=te(),e=yu(),[t,r]=P.useState(!1),s=P.useRef(!1);return Ca("toggle showback to content",()=>{const i=s.current,o=n.getCurrentPageShapeIds();let a=!1;o.size&&(a=o.size===n.getCulledShapes().size),i!==a&&(r(a),s.current=a)},[n]),t?g.jsx(ue,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function G0e(){const n=te();return ie("is pen mode",()=>n.getInstanceState().isPenMode,[n])?g.jsx(ue,{actionId:"exit-pen-mode"}):null}function Y0e(){const n=te(),e=yu();return ie("is following user",()=>!!n.getInstanceState().followingUserId,[n])?g.jsx(nr,{...e["stop-following"]}):null}function X0e(){return g.jsxs(g.Fragment,{children:[g.jsx(G0e,{}),g.jsx(q0e,{}),g.jsx(Y0e,{})]})}function Z0e({children:n}){const e=n??g.jsx(X0e,{});return g.jsx("div",{className:"tlui-helper-buttons",children:g.jsx(Ci,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function J0e(){const n=w0();return g.jsxs(g.Fragment,{children:[g.jsxs(lt,{label:"shortcuts-dialog.tools",id:"tools",children:[g.jsx(ue,{actionId:"toggle-tool-lock"}),g.jsx(ue,{actionId:"insert-media"}),g.jsx(hs,{toolId:"select"}),g.jsx(hs,{toolId:"draw"}),g.jsx(hs,{toolId:"eraser"}),g.jsx(hs,{toolId:"hand"}),g.jsx(hs,{toolId:"rectangle"}),g.jsx(hs,{toolId:"ellipse"}),g.jsx(hs,{toolId:"arrow"}),g.jsx(hs,{toolId:"line"}),g.jsx(hs,{toolId:"text"}),g.jsx(hs,{toolId:"frame"}),g.jsx(hs,{toolId:"note"}),g.jsx(hs,{toolId:"laser"}),g.jsx(nr,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),g.jsxs(lt,{label:"shortcuts-dialog.preferences",id:"preferences",children:[g.jsx(ue,{actionId:"toggle-dark-mode"}),g.jsx(ue,{actionId:"toggle-focus-mode"}),g.jsx(ue,{actionId:"toggle-grid"})]}),g.jsxs(lt,{label:"shortcuts-dialog.edit",id:"edit",children:[g.jsx(ue,{actionId:"undo"}),g.jsx(ue,{actionId:"redo"}),g.jsx(ue,{actionId:"cut"}),g.jsx(ue,{actionId:"copy"}),g.jsx(ue,{actionId:"paste"}),g.jsx(ue,{actionId:"select-all"}),g.jsx(ue,{actionId:"delete"}),g.jsx(ue,{actionId:"duplicate"})]}),g.jsxs(lt,{label:"shortcuts-dialog.view",id:"view",children:[g.jsx(ue,{actionId:"zoom-in"}),g.jsx(ue,{actionId:"zoom-out"}),g.jsx(ue,{actionId:"zoom-to-100"}),g.jsx(ue,{actionId:"zoom-to-fit"}),g.jsx(ue,{actionId:"zoom-to-selection"})]}),g.jsxs(lt,{label:"shortcuts-dialog.transform",id:"transform",children:[g.jsx(ue,{actionId:"bring-to-front"}),g.jsx(ue,{actionId:"bring-forward"}),g.jsx(ue,{actionId:"send-backward"}),g.jsx(ue,{actionId:"send-to-back"}),g.jsx(ue,{actionId:"group"}),g.jsx(ue,{actionId:"ungroup"}),g.jsx(ue,{actionId:"flip-horizontal"}),g.jsx(ue,{actionId:"flip-vertical"}),g.jsx(ue,{actionId:"align-top"}),g.jsx(ue,{actionId:"align-center-vertical"}),g.jsx(ue,{actionId:"align-bottom"}),g.jsx(ue,{actionId:"align-left"}),g.jsx(ue,{actionId:"align-center-horizontal"}),g.jsx(ue,{actionId:"align-right"})]}),n&&g.jsx(lt,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:g.jsx(ue,{actionId:"open-cursor-chat"})})]})}const Q0e=P.memo(function({children:e}){const t=ft(),r=qr(),s=e??g.jsx(J0e,{});return g.jsxs(g.Fragment,{children:[g.jsxs(S0,{className:"tlui-shortcuts-dialog__header",children:[g.jsx(v0,{children:t("shortcuts-dialog.title")}),g.jsx(x0,{})]}),g.jsx(fp,{className:ze("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=gn.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=gn.TABLET}),children:g.jsx(Ci,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),g.jsx("div",{className:"tlui-dialog__scrim"})]})});function VH(){const n=Tr(),e=Rn(),t=ie("locale",()=>n==null?void 0:n.user.getLocale(),[n]);return n?g.jsx(ks,{id:"help menu language",label:"menu.language",children:g.jsx(lt,{id:"languages",children:op.map(({locale:r,label:s})=>g.jsx(E0,{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 exe(){return g.jsxs(g.Fragment,{children:[g.jsx(VH,{}),g.jsx(qH,{})]})}function qH(){const{KeyboardShortcutsDialog:n}=nc(),{addDialog:e}=Xp(),t=P.useCallback(()=>{n&&e({component:n})},[e,n]);return n?g.jsx(nr,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:t}):null}function txe(){return g.jsxs(g.Fragment,{children:[g.jsxs(lt,{id:"basic",children:[g.jsx(rxe,{}),g.jsx(axe,{}),g.jsx(nxe,{}),g.jsx(lxe,{})]}),g.jsx(cxe,{})]})}function nxe(){return g.jsxs(ks,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[g.jsxs(lt,{id:"export-all-as-group",children:[g.jsx(ue,{actionId:"export-all-as-svg"}),g.jsx(ue,{actionId:"export-all-as-png"})]}),g.jsx(lt,{id:"export-all-as-bg",children:g.jsx(AT,{})})]})}function rxe(){return g.jsxs(ks,{id:"edit",label:"menu.edit",children:[g.jsx(oxe,{}),g.jsx(zH,{}),g.jsx($H,{}),g.jsx(sxe,{}),g.jsx(ixe,{}),g.jsx(lt,{id:"select-all",children:g.jsx(BH,{})})]})}function sxe(){return g.jsxs(lt,{id:"misc",children:[g.jsx(AH,{}),g.jsx(OH,{}),g.jsx(TH,{}),g.jsx(_H,{}),g.jsx(RH,{}),g.jsx(DH,{}),g.jsx(HH,{}),g.jsx(UH,{}),g.jsx(MH,{})]})}function ixe(){return g.jsxs(lt,{id:"lock",children:[g.jsx(jH,{}),g.jsx(o0e,{})]})}function oxe(){const n=IH(),e=kH();return g.jsxs(lt,{id:"undo-redo",children:[g.jsx(ue,{actionId:"undo",disabled:!n}),g.jsx(ue,{actionId:"redo",disabled:!e})]})}function axe(){return g.jsx(ks,{id:"view",label:"menu.view",children:g.jsxs(lt,{id:"view-actions",children:[g.jsx(ue,{actionId:"zoom-in"}),g.jsx(ue,{actionId:"zoom-out"}),g.jsx(NH,{}),g.jsx(LH,{}),g.jsx(FH,{})]})})}function lxe(){return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"insert-embed"}),g.jsx(ue,{actionId:"insert-media"})]})}function cxe(){return g.jsxs(lt,{id:"preferences",children:[g.jsxs(ks,{id:"preferences",label:"menu.preferences",children:[g.jsxs(lt,{id:"preferences-actions",children:[g.jsx(S0e,{}),g.jsx(v0e,{}),g.jsx(x0e,{}),g.jsx(w0e,{}),g.jsx(b0e,{}),g.jsx(C0e,{}),g.jsx(P0e,{}),g.jsx(k0e,{}),g.jsx(I0e,{}),g.jsx(E0e,{})]}),g.jsx(lt,{id:"color-scheme",children:g.jsx(Vfe,{})})]}),g.jsx(VH,{}),g.jsx(qH,{})]})}const uxe=P.memo(function({children:e}){const t=In(),[r,s]=Ua("main menu"),i=ft(),o=e??g.jsx(txe,{});return g.jsxs(I_,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[g.jsx(__,{asChild:!0,dir:"ltr",children:g.jsx(Ke,{type:"icon","data-testid":"main-menu.button",title:i("menu.title"),children:g.jsx(ct,{icon:"menu",small:!0})})}),g.jsx(y0,{container:t,children:g.jsx(T_,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:g.jsx(Ci,{type:"menu",sourceId:"main-menu",children:o})})})]})}),ZC={};function cf(n){if(ZC[n])return ZC[n];const t=document.createElement("canvas").getContext("2d");t.fillStyle=n,t.fillRect(0,0,1,1);const[r,s,i,o]=t.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,i/255,o/255]);return ZC[n]=a,a}const Ry=10,GH=4*6*Ry+12+4*12;function gd(n,{center:e,radius:t,numArcSegments:r=20,startAngle:s=0,endAngle:i=Rt,offset:o=0}){const a=(i-s)/r;let l=o;for(let c=s;c<i;c+=a)n[l++]=e.x,n[l++]=e.y,n[l++]=e.x+Math.cos(c)*t,n[l++]=e.y+Math.sin(c)*t,n[l++]=e.x+Math.cos(c+a)*t,n[l++]=e.y+Math.sin(c+a)*t;return n}function md(n,e,t,r,s,i){n[e++]=t,n[e++]=r,n[e++]=t,n[e++]=r+i,n[e++]=t+s,n[e++]=r,n[e++]=t+s,n[e++]=r,n[e++]=t,n[e++]=r+i,n[e++]=t+s,n[e++]=r+i}function dxe(n,e,t){const r=Ry;t=Math.min(t,Math.min(e.w,e.h)/2);const s=ye.ExpandBy(e,-t);if(s.w<=0||s.h<=0)return gd(n,{center:e.center,radius:t,numArcSegments:Ry*4}),Ry*4*6;let i=0;return md(n,i,s.minX,s.minY,s.w,s.h),i+=12,md(n,i,s.minX,e.minY,s.w,t),i+=12,md(n,i,s.maxX,s.minY,t,s.h),i+=12,md(n,i,s.minX,s.maxY,s.w,t),i+=12,md(n,i,e.minX,s.minY,t,s.h),i+=12,gd(n,{numArcSegments:r,offset:i,center:s.point,radius:t,startAngle:xt,endAngle:xt*1.5}),i+=r*6,gd(n,{numArcSegments:r,offset:i,center:E.Add(s.point,new E(s.w,0)),radius:t,startAngle:xt*1.5,endAngle:Rt}),i+=r*6,gd(n,{numArcSegments:r,offset:i,center:E.Add(s.point,s.size),radius:t,startAngle:0,endAngle:Ht}),i+=r*6,gd(n,{numArcSegments:r,offset:i,center:E.Add(s.point,new E(0,s.h)),radius:t,startAngle:Ht,endAngle:xt}),GH}function hxe(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
488
+ precision mediump float;
489
+
490
+ in vec2 shapeVertexPosition;
491
+
492
+ uniform vec4 canvasPageBounds;
493
+
494
+ // taken (with thanks) from
495
+ // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
496
+ void main() {
497
+ // convert the position from pixels to 0.0 to 1.0
498
+ vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
499
+
500
+ // convert from 0->1 to 0->2
501
+ vec2 zeroToTwo = zeroToOne * 2.0;
502
+
503
+ // convert from 0->2 to -1->+1 (clipspace)
504
+ vec2 clipSpace = zeroToTwo - 1.0;
505
+
506
+ gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
507
+ }`,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
508
+ precision mediump float;
509
+
510
+ uniform vec4 fillColor;
511
+ out vec4 outputColor;
512
+
513
+ void main() {
514
+ outputColor = fillColor;
515
+ }`,i=e.createShader(e.FRAGMENT_SHADER);if(!i)throw new Error("Failed to create fragment shader");if(e.shaderSource(i,s),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const o=e.createProgram();if(!o)throw new Error("Failed to create program");if(e.attachShader(o,r),e.attachShader(o,i),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(o);const a=e.getAttribLocation(o,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(o,"canvasPageBounds"),c=e.getUniformLocation(o,"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:qm(e,1024),unselectedShapes:qm(e,4096),viewport:qm(e,GH),collaborators:qm(e,1024),prepareTriangles(p,m){e.bindBuffer(e.ARRAY_BUFFER,p.buffer),e.bufferData(e.ARRAY_BUFFER,p.vertices,e.STATIC_DRAW,0,m),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(p){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,p/2),e.disable(e.BLEND)},drawTriangles(p){e.drawArrays(e.TRIANGLES,0,p/2)},setFillColor(p){e.uniform4fv(c,p)},setCanvasPageBounds(p){e.uniform4fv(l,p)}}}function qm(n,e){const t=n.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(e)}}function DL(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 fxe=Object.create,YH=Object.defineProperty,pxe=Object.getOwnPropertyDescriptor,gxe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),XH=n=>{throw TypeError(n)},ZH=(n,e,t)=>e in n?YH(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,mxe=n=>[,,,fxe(null)],JH=["class","method","getter","setter","accessor","field","value","get","set"],QH=n=>n!==void 0&&typeof n!="function"?XH("Function expected"):n,yxe=(n,e,t,r,s)=>({kind:JH[n],name:e,metadata:r,addInitializer:i=>t._?XH("Already initialized"):s.push(QH(i||null))}),Sxe=(n,e)=>ZH(e,gxe("metadata"),n[3]),vxe=(n,e,t,r)=>{for(var s=0,i=n[e>>1],o=i&&i.length;s<o;s++)i[s].call(t);return r},Go=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,p=!1,m=2,y=JH[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,pxe(s,t)),b=r.length-1;b>=0;b--)l=yxe(d,t,a={},n[3],v),l.static=f,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,QH(o)&&(x[y]=o);return x&&YH(s,t,x),s},ha=(n,e,t)=>ZH(n,typeof e!="symbol"?e+"":e,t),eK,tK,nK,rK,sK,iK,oK,aK,lK,cK,Xs;cK=[vs],lK=[le],aK=[le],oK=[le],iK=[le],sK=[le],rK=[le],nK=[le],tK=[le],eK=[vs];class ki{constructor(e,t,r){this.editor=e,this.elem=t,this.container=r,vxe(Xs,5,this),ha(this,"disposables",[]),ha(this,"gl"),ha(this,"shapeGeometryCache"),ha(this,"colors"),ha(this,"id",_t()),ha(this,"canvasBoundingClientRect",on("canvasBoundingClientRect",new ye)),ha(this,"originPagePoint",new E),ha(this,"originPageCenter",new E),ha(this,"isInViewport",!1),this.gl=hxe(t),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",s=>{const i=e.getShapeMaskedPageBounds(s.id);if(!i)return null;const o=new Float32Array(12);return md(o,0,i.x,i.y,i.w,i.h),o}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),qi("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:cf(e.getPropertyValue("--color-text-3").trim()),selectFill:cf(e.getPropertyValue("--color-selected").trim()),viewportFill:cf(e.getPropertyValue("--color-muted-1").trim()),background:cf(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?ye.Expand(t,e):e}getContentScreenBounds(){const e=this.getContentPageBounds(),t=this.editor.pageToScreen(e.point),r=this.editor.pageToScreen(new E(e.maxX,e.maxY));return new ye(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 ye(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 E(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,i=s/r;i<t.height&&(i=t.height,s=i*r);const o=new ye(0,0,s,i);return o.center=t.center,o}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 i=e-s.x,o=t-s.y;return i*=r.width/s.width,o*=r.height/s.height,i+=r.minX,o+=r.minY,new E(i,o,1)}minimapScreenPointToPagePoint(e,t,r=!1,s=!1){const{editor:i}=this,o=i.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,t);if(s){const c=this.editor.getCurrentPageBounds()??new ye,d=c.minX-o.width/2,f=c.maxX+o.width/2,p=c.minY-o.height/2,m=c.maxY+o.height/2,y=Math.max(0,d+o.width-a),v=Math.max(0,-(f-o.width-a)),x=Math.max(0,p+o.height-l),b=Math.max(0,-(m-o.height-l));a+=(y-v)/2,l+=(x-b)/2,a=Mn(a,d,f),l=Mn(l,p,m)}if(r){const{originPagePoint:c}=this,d=Math.abs(a-c.x),f=Math.abs(l-c.y);d>f?l=c.y:a=c.x}return new E(a,l)}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 i=0,o=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const d=a[l],f=this.shapeGeometryCache.get(d);if(!f)continue;const p=f.length;r.has(d)?(DL(this.gl.selectedShapes,i,f),i+=p):(DL(this.gl.unselectedShapes,o,f),o+=p)}this.drawShapes(this.gl.unselectedShapes,o,s.shapeFill),this.drawShapes(this.gl.selectedShapes,i,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=dxe(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),Pt.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 i=this.gl.collaborators.vertices;let o=0;const a=this.getZoom();for(const{cursor:l}of e)l&&(gd(i,{center:E.From(l),radius:3*a,offset:o,numArcSegments:t}),o+=r);this.gl.prepareTriangles(this.gl.collaborators,s),o=0;for(const{color:l}of e)this.gl.setFillColor(cf(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,o/2,r/2),o+=r}}Xs=mxe();Go(Xs,1,"close",cK,ki);Go(Xs,1,"getDpr",lK,ki);Go(Xs,1,"getContentPageBounds",aK,ki);Go(Xs,1,"getContentScreenBounds",oK,ki);Go(Xs,1,"getCanvasSize",iK,ki);Go(Xs,1,"getCanvasClientPosition",sK,ki);Go(Xs,1,"getCanvasPageBounds",rK,ki);Go(Xs,1,"getZoom",nK,ki);Go(Xs,1,"getCanvasPageBoundsArray",tK,ki);Go(Xs,1,"render",eK,ki);Sxe(Xs,ki);function xxe(){const n=te(),e=In(),t=P.useRef(null),r=P.useRef(!1),s=P.useRef();P.useEffect(()=>{try{const d=new ki(n,t.current,e);return s.current=d,s.current.close}catch(d){n.annotateError(d,{origin:"minimap",willCrashApp:!1}),n.timers.setTimeout(()=>{throw d})}},[n,e]);const i=P.useCallback(d=>{if(!n.getCurrentPageShapeIds().size||!s.current)return;const f=s.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),p=s.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);s.current.originPagePoint.setTo(p),s.current.originPageCenter.setTo(n.getViewportPageBounds().center),n.centerOnPoint(f,{animation:{duration:n.options.animationMediumMs}})},[n]),o=P.useCallback(d=>{if(!s.current)return;const f=d.currentTarget;if(Rp(f,d),!n.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const p=s.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),m=n.getViewportPageBounds(),y=s.current.getContentPageBounds();if(new ye(y.x-m.width/2,y.y-m.height/2,y.width+m.width,y.height+m.height).containsPoint(p)&&!m.containsPoint(p)){s.current.isInViewport=m.containsPoint(p);const b=E.Sub(m.center,m.point),C=E.Add(p,b);s.current.originPagePoint.setTo(C),s.current.originPageCenter.setTo(p),n.centerOnPoint(p,{animation:{duration:n.options.animationMediumMs}})}else{const b=s.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);s.current.isInViewport=m.containsPoint(b),s.current.originPagePoint.setTo(b),s.current.originPageCenter.setTo(m.center)}function x(b){f&&Dp(f,b),r.current=!1,document.body.removeEventListener("pointerup",x)}document.body.addEventListener("pointerup",x)},[n]),a=P.useCallback(d=>{if(!s.current)return;const f=s.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,d.shiftKey,!0);if(r.current){if(s.current.isInViewport){const v=s.current.originPagePoint.clone().sub(s.current.originPageCenter);n.centerOnPoint(E.Sub(f,v));return}n.centerOnPoint(f)}const p=s.current.getMinimapPagePoint(d.clientX,d.clientY),m=n.pageToScreen(p),y={type:"pointer",target:"canvas",name:"pointer_move",...Fs(d),point:m,isPen:n.getInstanceState().isPenMode};n.dispatch(y)},[n]),l=P.useCallback(d=>{const f=ez(d);n.dispatch({type:"wheel",name:"wheel",delta:f,point:new E(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey,metaKey:d.metaKey,accelKey:Cr(d)})},[n]),c=Up();return P.useEffect(()=>{n.timers.setTimeout(()=>{var d,f;(d=s.current)==null||d.updateColors(),(f=s.current)==null||f.render()})},[c,n]),g.jsx("div",{className:"tlui-minimap",children:g.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:i,onPointerMove:a,onPointerDown:o,onWheelCapture:l})})}function wxe(n,e){const[t,r]=He.useState(e);He.useLayoutEffect(()=>{const i=xk(n);if(i)try{r(JSON.parse(i))}catch{console.error(`Could not restore value ${n} from local storage.`)}},[n]);const s=He.useCallback(i=>{r(o=>{const a=typeof i=="function"?i(o):i;return wk(n,JSON.stringify(a)),a})},[n]);return[t,s]}const bxe=P.memo(function(){const e=yu(),t=ft(),r=qr(),s=P.useRef(null);$a(s);const[i,o]=wxe("minimap",!0),a=P.useCallback(()=>{o(d=>!d)},[o]),{ZoomMenu:l,Minimap:c}=nc();return r<gn.MOBILE?null:g.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[g.jsx("div",{className:"tlui-buttons__horizontal",children:l&&r<gn.TABLET?g.jsx(l,{}):i?g.jsxs(g.Fragment,{children:[l&&g.jsx(l,{}),c&&g.jsx(Ke,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:g.jsx(ct,{icon:i?"chevrons-ne":"chevrons-sw"})})]}):g.jsxs(g.Fragment,{children:[g.jsx(Ke,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(pp(e["zoom-out"].label))} ${RE(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:g.jsx(ct,{icon:"minus"})}),l&&g.jsx(l,{}),g.jsx(Ke,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(pp(e["zoom-in"].label))} ${RE(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:g.jsx(ct,{icon:"plus"})}),c&&g.jsx(Ke,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:g.jsx(ct,{icon:i?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=gn.TABLET&&!i&&g.jsx(c,{})]})}),Cxe=function({name:e,id:t,isCurrentPage:r,onCancel:s}){const i=te(),o=Rn(),a=P.useRef(null),l=P.useRef(null),c=P.useCallback(()=>{l.current=i.markHistoryStoppingPoint("rename page")},[i]),d=P.useCallback(p=>{i.renamePage(t,p||"New Page"),o("rename-page",{source:"page-menu"})},[i,t,o]),f=P.useCallback(()=>{l.current&&i.bailToMark(l.current),s()},[i,s]);return g.jsx(Yp,{className:"tlui-page-menu__item__input",ref:p=>a.current=p,defaultValue:e,onValueChange:d,onCancel:f,onFocus:c,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},lk=(n,e,t,r,s)=>{let i;const o=n.getPages(),a=t>r?o[r-1]:o[r],l=t>r?o[r]:o[r+1];a&&!l?i=To(a.index):!a&&l?i=nq(o[0].index):i=Gf(a.index,l.index),i!==o[t].index&&(n.markHistoryStoppingPoint("moving page"),n.updatePage({id:e,index:i}),s("move-page",{source:"page-menu"}))},jL=Vn(function({index:e,listSize:t,item:r,onRename:s}){const i=te(),o=ft(),a=i.getPages(),l=Rn(),c=P.useCallback(()=>{i.markHistoryStoppingPoint("creating page");const m=Vs.createId();i.duplicatePage(r.id,m),l("duplicate-page",{source:"page-menu"})},[i,r,l]),d=P.useCallback(()=>{lk(i,r.id,e,e-1,l)},[i,r,e,l]),f=P.useCallback(()=>{lk(i,r.id,e,e+1,l)},[i,r,e,l]),p=P.useCallback(()=>{i.markHistoryStoppingPoint("deleting page"),i.deletePage(r.id),l("delete-page",{source:"page-menu"})},[i,r,l]);return g.jsxs(su,{id:`page item submenu ${e}`,children:[g.jsx(iu,{children:g.jsx(Ke,{type:"icon",title:o("page-menu.submenu.title"),children:g.jsx(ct,{icon:"dots-vertical",small:!0})})}),g.jsx(ou,{alignOffset:0,side:"right",sideOffset:-4,children:g.jsxs(Ci,{type:"menu",sourceId:"page-menu",children:[g.jsxs(lt,{id:"modify",children:[s&&g.jsx(nr,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),g.jsx(nr,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=i.options.maxPages}),e>0&&g.jsx(nr,{id:"move-up",onSelect:d,label:"page-menu.submenu.move-up"}),e<t-1&&g.jsx(nr,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:f})]}),t>1&&g.jsx(lt,{id:"delete",children:g.jsx(nr,{id:"delete",onSelect:p,label:"page-menu.submenu.delete"})})]})})]})}),Pxe=P.memo(function(){const e=te(),t=Rn(),r=ft(),s=qr(),i=P.useCallback(()=>b(!1),[]),[o,a]=Ua("page-menu",i),l=36,c=P.useRef(null),d=ie("pages",()=>e.getPages(),[e]),f=ie("currentPage",()=>e.getCurrentPage(),[e]),p=ie("currentPageId",()=>e.getCurrentPageId(),[e]),m=Ys(),y=ie("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),v=ie("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[x,b]=P.useState(!1),C=P.useCallback(()=>{m||b(N=>!N)},[m]),I=P.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[_,T]=P.useState(Object.fromEntries(d.map((N,L)=>[N.id,{y:L*l,offsetY:0,isSelected:!1}])));P.useLayoutEffect(()=>{T(Object.fromEntries(d.map((N,L)=>[N.id,{y:L*l,offsetY:0,isSelected:!1}])))},[l,d]),P.useEffect(()=>{o&&e.timers.requestAnimationFrame(()=>{const N=document.querySelector(`[data-testid="page-menu-item-${p}"]`);if(N){const L=c.current;if(!L)return;const V=N.offsetTop,X=L.scrollTop;V<X&&L.scrollTo({top:V});const W=V+l,$=L.scrollTop+L.offsetHeight;W>$&&L.scrollTo({top:W-L.offsetHeight})}})},[l,p,o,e]);const A=P.useCallback(N=>{const{clientY:L,currentTarget:V}=N,{dataset:{id:X,index:W}}=V;if(!X||!W)return;const $=I.current;Rp(N.currentTarget,N),$.status="pointing",$.pointing={id:X,index:+W};const re=_[X].y;$.startY=L,$.startIndex=Math.max(0,Math.min(Math.round(re/l),d.length-1))},[l,d.length,_]),R=P.useCallback(N=>{const L=I.current;if(L.status==="pointing"){const{clientY:V}=N,X=V-L.startY;Math.abs(X)>5&&(L.status="dragging")}if(L.status==="dragging"){const{clientY:V}=N,X=V-L.startY,W=_[L.pointing.id],{startIndex:$,pointing:G}=L,re=W.y+X,H=Math.max(0,Math.min(Math.round(re/l),d.length-1)),ne={..._};if(ne[G.id]={y:W.y,offsetY:X,isSelected:!0},H!==L.dragIndex){L.dragIndex=H;for(let ge=0;ge<d.length;ge++){const Pe=d[ge];if(Pe.id===L.pointing.id)continue;let{y:ce}=ne[Pe.id];H===$?ce=ge*l:H<$?H<=ge&&ge<$?ce=(ge+1)*l:ce=ge*l:H>$&&(H>=ge&&ge>$?ce=(ge-1)*l:ce=ge*l),ce!==ne[Pe.id].y&&(ne[Pe.id]={y:ce,offsetY:0,isSelected:!0})}}T(ne)}},[l,d,_]),j=P.useCallback(N=>{const L=I.current;if(L.status==="dragging"){const{id:V,index:X}=L.pointing;lk(e,V,X,L.dragIndex,t)}Dp(N.currentTarget,N),L.status="idle"},[e,t]),K=P.useCallback(N=>{const L=I.current;N.key==="Escape"&&(L.status==="dragging"&&T(Object.fromEntries(d.map((V,X)=>[V.id,{y:X*l,offsetY:0,isSelected:!1}]))),L.status="idle")},[l,d]),U=P.useCallback(()=>{m||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const N=Vs.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:N}),e.setCurrentPage(N),b(!0)}),t("new-page",{source:"page-menu"}))},[e,r,m,t]),J=P.useCallback(N=>{e.setCurrentPage(N),t("change-page",{source:"page-menu"})},[e,t]),z=P.useCallback((N,L)=>{e.renamePage(N,L),t("rename-page",{source:"page-menu"})},[e,t]);return g.jsxs(_T,{id:"pages",onOpenChange:a,open:o,children:[g.jsx(TT,{"data-testid":"main.page-menu",children:g.jsxs(Ke,{type:"menu",title:f.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[g.jsx("div",{className:"tlui-page-menu__name",children:f.name}),g.jsx(ct,{icon:"chevron-down",small:!0})]})}),g.jsx(MT,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:x,children:g.jsxs("div",{className:"tlui-page-menu__wrapper",children:[g.jsxs("div",{className:"tlui-page-menu__header",children:[g.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!m&&g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsx(Ke,{type:"icon","data-testid":"page-menu.edit",title:r(x?"page-menu.edit-done":"page-menu.edit-start"),onClick:C,children:g.jsx(ct,{icon:x?"check":"edit"})}),g.jsx(Ke,{type:"icon","data-testid":"page-menu.create",title:r(y?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:y,onClick:U,children:g.jsx(ct,{icon:"plus"})})]})]}),g.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*d.length+4},ref:c,children:d.map((N,L)=>{const V=_[N.id]??{offsetY:0};return x?g.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:N.id===f.id?888:L,transform:`translate(0px, ${V.y+V.offsetY}px)`},children:[g.jsx(Ke,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:A,onPointerUp:j,onPointerMove:R,onKeyDown:K,"data-id":N.id,"data-index":L,children:g.jsx(ct,{icon:"drag-handle-dots"})}),s<gn.TABLET_SM&&v?g.jsxs(Ke,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const X=window.prompt("Rename page",N.name);X&&X!==N.name&&z(N.id,X)},onDoubleClick:C,children:[g.jsx(ak,{checked:N.id===f.id}),g.jsx(wn,{children:N.name})]}):g.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:g.jsx(Cxe,{id:N.id,name:N.name,isCurrentPage:N.id===f.id,onCancel:()=>{b(!1),e.menus.clearOpenMenus()}})}),!m&&g.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":x,children:g.jsx(jL,{index:L,item:N,listSize:d.length})})]},N.id+"_editing"):g.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[g.jsxs(Ke,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>J(N.id),onDoubleClick:C,title:r("page-menu.go-to-page"),children:[g.jsx(ak,{checked:N.id===f.id}),g.jsx(wn,{children:N.name})]}),!m&&g.jsx("div",{className:"tlui-page_menu__item__submenu",children:g.jsx(jL,{index:L,item:N,listSize:d.length,onRename:()=>{if(Pt.isIos){const X=window.prompt("Rename page",N.name);X&&X!==N.name&&z(N.id,X)}else b(!0),p!==N.id&&J(N.id)}})})]},N.id)})})]})})]})});function Exe(){const n=te(),e=Ys(),t=ie("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(e&&!t))return g.jsxs(g.Fragment,{children:[g.jsx(Ixe,{}),g.jsx(kxe,{})]})}function kxe(){const n=Gr(1),e=Ha(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"delete",disabled:!t}),g.jsx(ue,{actionId:"duplicate",disabled:!t})]})}function Ixe(){const n=IH(),e=kH();return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"undo",disabled:!n}),g.jsx(ue,{actionId:"redo",disabled:!e})]})}const _xe=P.memo(function({children:e}){const t=e??g.jsx(Exe,{});return g.jsx(Ci,{type:"small-icons",sourceId:"quick-actions",children:t})});function Txe({userId:n}){const e=Hv(n);return e?g.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:e.userName==="New User"?"":e.userName[0]??""},n):null}const Mxe=Vn(function({userId:e}){const t=te(),r=ft(),s=Rn(),i=Hv(e),o=P.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=(i==null?void 0:i.followingUserId)===t.user.getId(),l=t.getInstanceState().followingUserId===e;return i?g.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[g.jsxs(Ke,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>t.zoomToUser(e),onDoubleClick:o,children:[g.jsx(Bo,{icon:"color",color:i.color}),g.jsx("div",{className:"tlui-people-menu__name",children:i.userName??"New User"})]}),g.jsx(Ke,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:o,disabled:a,"data-active":l||a,children:g.jsx(ct,{icon:a?"leading":l?"following":"follow"})})]}):null});function Axe({count:n}){return g.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(n)})}const Oxe=Vn(function(){const e=te(),t=In(),r=ft(),s=Rn(),i=P.useRef(!1),[o,a]=P.useState(!1),l=P.useCallback(v=>{a(v)},[]),c=e.user.getColor(),d=P.useCallback(v=>{e.user.updateUserPreferences({color:v}),s("set-color",{source:"people-menu"})},[e,s]),{handleButtonClick:f,handleButtonPointerDown:p,handleButtonPointerEnter:m,handleButtonPointerUp:y}=He.useMemo(()=>{const v=()=>{i.current=!1,window.removeEventListener("pointerup",v)};return{handleButtonClick:_=>{const{id:T}=_.currentTarget.dataset;T&&c!==T&&d(T)},handleButtonPointerDown:_=>{const{id:T}=_.currentTarget.dataset;T&&(d(T),i.current=!0,window.addEventListener("pointerup",v))},handleButtonPointerEnter:_=>{if(!i.current)return;const{id:T}=_.currentTarget.dataset;T&&d(T)},handleButtonPointerUp:_=>{const{id:T}=_.currentTarget.dataset;T&&d(T)}}},[c,d]);return g.jsxs(PT,{onOpenChange:l,open:o,children:[g.jsx(ET,{dir:"ltr",asChild:!0,children:g.jsx(Ke,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:g.jsx(ct,{icon:"color"})})}),g.jsx(kT,{container:t,children:g.jsx(IT,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:g.jsx("div",{className:"tlui-buttons__grid",children:lE.map(v=>g.jsx(Ke,{type:"icon","data-id":v,"data-testid":v,"aria-label":v,"data-state":c===v?"hinted":void 0,title:v,className:"tlui-button-grid__button",style:{color:v},onPointerEnter:m,onPointerDown:p,onPointerUp:y,onClick:f,children:g.jsx(ct,{icon:"color"})},v))})})})]})});function Rxe(){const n=te(),e=Rn(),t=ie("userName",()=>n.user.getName(),[]),r=ft(),s=P.useRef(t),i=P.useRef(t),[o,a]=P.useState(!1),l=P.useCallback(()=>{a(p=>!p)},[]),c=P.useCallback(p=>{i.current=p,n.user.updateUserPreferences({name:p})},[n]),d=P.useCallback(()=>{s.current!==i.current&&(e("change-user-name",{source:"people-menu"}),s.current=i.current)},[e]),f=P.useCallback(()=>{a(!1),n.user.updateUserPreferences({name:s.current}),n.menus.clearOpenMenus()},[n]);return g.jsxs("div",{className:"tlui-people-menu__user",children:[g.jsx(Oxe,{}),o?g.jsx(Yp,{className:"tlui-people-menu__user__input",defaultValue:t,onValueChange:c,onComplete:l,onCancel:f,onBlur:d,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{o||a(!0)},children:t}),t==="New User"?g.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),g.jsx(Ke,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:g.jsx(ct,{icon:o?"check":"edit"})})]})}function Dxe({displayUserWhenAlone:n,children:e}){const t=ft(),r=In(),s=te(),i=rz(),o=ie("user",()=>s.user.getColor(),[s]),a=ie("user",()=>s.user.getName(),[s]),[l,c]=Ua("people menu");return g.jsxs(PT,{onOpenChange:c,open:l,children:[g.jsx(ET,{dir:"ltr",asChild:!0,children:g.jsxs("button",{className:"tlui-people-menu__avatars-button",title:t("people-menu.title"),children:[i.length>5&&g.jsx(Axe,{count:i.length-5}),g.jsxs("div",{className:"tlui-people-menu__avatars",children:[i.slice(-5).map(d=>g.jsx(Txe,{userId:d},d)),(n||i.length>0)&&g.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:o},children:a==="New User"?"":a[0]??""})]})]})}),g.jsx(kT,{container:r,children:g.jsx(IT,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:tt,children:g.jsxs("div",{className:"tlui-people-menu__wrapper",children:[g.jsx("div",{className:"tlui-people-menu__section",children:g.jsx(Rxe,{})}),i.length>0&&g.jsx("div",{className:"tlui-people-menu__section",children:i.map(d=>g.jsx(Mxe,{userId:d},d+"_presence"))}),e]})})})]})}function jxe(){return g.jsx("div",{className:"tlui-share-zone",draggable:!1,children:g.jsx(Dxe,{displayUserWhenAlone:!0})})}const Nxe=Object.freeze([Ws,Qc,eu,Fo]);function uK(n=Nxe){const e=te();return ie("getRelevantStyles",()=>{var i;const t=new fE(e.getSharedStyles()),r=!!((i=e.root.getCurrent())!=null&&i.shapeType),s=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(t.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const o of n)t.applyValue(o,e.getStyleForNextShape(o));return r||s||t.size>0?t:null},[e])}const gi={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"}]},Nc=P.memo(function(e){const{uiType:t,items:r,title:s,style:i,value:o,onValueChange:a,onHistoryMark:l,theme:c}=e,d=ft(),f=P.useRef(!1),p=P.useRef(null),{handleButtonClick:m,handleButtonPointerDown:y,handleButtonPointerEnter:v,handleButtonPointerUp:x}=P.useMemo(()=>{const b=()=>{f.current=!1,window.removeEventListener("pointerup",b);const A=p.current;A&&(["TEXTAREA","INPUT"].includes(A.nodeName)||A.isContentEditable)&&A.focus(),p.current=null};return{handleButtonClick:A=>{const{id:R}=A.currentTarget.dataset;o.type==="shared"&&o.value===R||(l==null||l("point picker item"),a(i,R))},handleButtonPointerDown:A=>{const{id:R}=A.currentTarget.dataset;l==null||l("point picker item"),a(i,R),f.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",b)},handleButtonPointerEnter:A=>{if(!f.current)return;const{id:R}=A.currentTarget.dataset;a(i,R)},handleButtonPointerUp:A=>{const{id:R}=A.currentTarget.dataset;o.type==="shared"&&o.value===R||a(i,R)}}},[o,l,a,i]);return g.jsx("div",{"data-testid":`style.${t}`,className:ze("tlui-buttons__grid"),children:r.map(b=>g.jsx(Ke,{type:"icon","data-id":b.value,"data-testid":`style.${t}.${b.value}`,"aria-label":b.value,"data-state":o.type==="shared"&&o.value===b.value?"hinted":void 0,title:s+" — "+d(`${t}-style.${b.value}`),className:ze("tlui-button-grid__button"),style:i===Ws?{color:c[b.value].solid}:void 0,onPointerEnter:v,onPointerDown:y,onPointerUp:x,onClick:m,children:g.jsx(ct,{icon:b.icon})},b.value))})});function dK(n,[e,t]){return Math.min(t,Math.max(e,n))}function Lxe(n){const e=P.useRef({value:n,previous:n});return P.useMemo(()=>(e.current.value!==n&&(e.current.previous=e.current.value,e.current.value=n),e.current.previous),[n])}var hK=["PageUp","PageDown"],fK=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],pK={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},fh="Slider",[ck,Fxe,zxe]=o0(fh),[gK,T1e]=Vo(fh,[zxe]),[$xe,R0]=gK(fh),mK=P.forwardRef((n,e)=>{const{name:t,min:r=0,max:s=100,step:i=1,orientation:o="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:d,onValueChange:f=()=>{},onValueCommit:p=()=>{},inverted:m=!1,form:y,...v}=n,x=P.useRef(new Set),b=P.useRef(0),I=o==="horizontal"?Bxe:Uxe,[_=[],T]=Ql({prop:d,defaultProp:c,onChange:J=>{var N;(N=[...x.current][b.current])==null||N.focus(),f(J)}}),A=P.useRef(_);function R(J){const z=qxe(_,J);U(J,z)}function j(J){U(J,b.current)}function K(){const J=A.current[b.current];_[b.current]!==J&&p(_)}function U(J,z,{commit:N}={commit:!1}){const L=Zxe(i),V=Jxe(Math.round((J-r)/i)*i+r,L),X=dK(V,[r,s]);T((W=[])=>{const $=Wxe(W,X,z);if(Xxe($,l*i)){b.current=$.indexOf(X);const G=String($)!==String(W);return G&&N&&p($),G?$:W}else return W})}return g.jsx($xe,{scope:n.__scopeSlider,name:t,disabled:a,min:r,max:s,valueIndexToChangeRef:b,thumbs:x.current,values:_,orientation:o,form:y,children:g.jsx(ck.Provider,{scope:n.__scopeSlider,children:g.jsx(ck.Slot,{scope:n.__scopeSlider,children:g.jsx(I,{"aria-disabled":a,"data-disabled":a?"":void 0,...v,ref:e,onPointerDown:De(v.onPointerDown,()=>{a||(A.current=_)}),min:r,max:s,inverted:m,onSlideStart:a?void 0:R,onSlideMove:a?void 0:j,onSlideEnd:a?void 0:K,onHomeKeyDown:()=>!a&&U(r,0,{commit:!0}),onEndKeyDown:()=>!a&&U(s,_.length-1,{commit:!0}),onStepKeyDown:({event:J,direction:z})=>{if(!a){const V=hK.includes(J.key)||J.shiftKey&&fK.includes(J.key)?10:1,X=b.current,W=_[X],$=i*V*z;U(W+$,X,{commit:!0})}}})})})})});mK.displayName=fh;var[yK,SK]=gK(fh,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Bxe=P.forwardRef((n,e)=>{const{min:t,max:r,dir:s,inverted:i,onSlideStart:o,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...d}=n,[f,p]=P.useState(null),m=Kt(e,I=>p(I)),y=P.useRef(void 0),v=n_(s),x=v==="ltr",b=x&&!i||!x&&i;function C(I){const _=y.current||f.getBoundingClientRect(),T=[0,_.width],R=OT(T,b?[t,r]:[r,t]);return y.current=_,R(I-_.left)}return g.jsx(yK,{scope:n.__scopeSlider,startEdge:b?"left":"right",endEdge:b?"right":"left",direction:b?1:-1,size:"width",children:g.jsx(vK,{dir:v,"data-orientation":"horizontal",...d,ref:m,style:{...d.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:I=>{const _=C(I.clientX);o==null||o(_)},onSlideMove:I=>{const _=C(I.clientX);a==null||a(_)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:I=>{const T=pK[b?"from-left":"from-right"].includes(I.key);c==null||c({event:I,direction:T?-1:1})}})})}),Uxe=P.forwardRef((n,e)=>{const{min:t,max:r,inverted:s,onSlideStart:i,onSlideMove:o,onSlideEnd:a,onStepKeyDown:l,...c}=n,d=P.useRef(null),f=Kt(e,d),p=P.useRef(void 0),m=!s;function y(v){const x=p.current||d.current.getBoundingClientRect(),b=[0,x.height],I=OT(b,m?[r,t]:[t,r]);return p.current=x,I(v-x.top)}return g.jsx(yK,{scope:n.__scopeSlider,startEdge:m?"bottom":"top",endEdge:m?"top":"bottom",size:"height",direction:m?1:-1,children:g.jsx(vK,{"data-orientation":"vertical",...c,ref:f,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:v=>{const x=y(v.clientY);i==null||i(x)},onSlideMove:v=>{const x=y(v.clientY);o==null||o(x)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:v=>{const b=pK[m?"from-bottom":"from-top"].includes(v.key);l==null||l({event:v,direction:b?-1:1})}})})}),vK=P.forwardRef((n,e)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:s,onSlideEnd:i,onHomeKeyDown:o,onEndKeyDown:a,onStepKeyDown:l,...c}=n,d=R0(fh,t);return g.jsx(wt.span,{...c,ref:e,onKeyDown:De(n.onKeyDown,f=>{f.key==="Home"?(o(f),f.preventDefault()):f.key==="End"?(a(f),f.preventDefault()):hK.concat(fK).includes(f.key)&&(l(f),f.preventDefault())}),onPointerDown:De(n.onPointerDown,f=>{const p=f.target;p.setPointerCapture(f.pointerId),f.preventDefault(),d.thumbs.has(p)?p.focus():r(f)}),onPointerMove:De(n.onPointerMove,f=>{f.target.hasPointerCapture(f.pointerId)&&s(f)}),onPointerUp:De(n.onPointerUp,f=>{const p=f.target;p.hasPointerCapture(f.pointerId)&&(p.releasePointerCapture(f.pointerId),i(f))})})}),xK="SliderTrack",wK=P.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=R0(xK,t);return g.jsx(wt.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});wK.displayName=xK;var uk="SliderRange",bK=P.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=R0(uk,t),i=SK(uk,t),o=P.useRef(null),a=Kt(e,o),l=s.values.length,c=s.values.map(p=>PK(p,s.min,s.max)),d=l>1?Math.min(...c):0,f=100-Math.max(...c);return g.jsx(wt.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...n.style,[i.startEdge]:d+"%",[i.endEdge]:f+"%"}})});bK.displayName=uk;var dk="SliderThumb",CK=P.forwardRef((n,e)=>{const t=Fxe(n.__scopeSlider),[r,s]=P.useState(null),i=Kt(e,a=>s(a)),o=P.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return g.jsx(Hxe,{...n,ref:i,index:o})}),Hxe=P.forwardRef((n,e)=>{const{__scopeSlider:t,index:r,name:s,...i}=n,o=R0(dk,t),a=SK(dk,t),[l,c]=P.useState(null),d=Kt(e,C=>c(C)),f=l?o.form||!!l.closest("form"):!0,p=X6(l),m=o.values[r],y=m===void 0?0:PK(m,o.min,o.max),v=Vxe(r,o.values.length),x=p==null?void 0:p[a.size],b=x?Gxe(x,y,a.direction):0;return P.useEffect(()=>{if(l)return o.thumbs.add(l),()=>{o.thumbs.delete(l)}},[l,o.thumbs]),g.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${y}% + ${b}px)`},children:[g.jsx(ck.ItemSlot,{scope:n.__scopeSlider,children:g.jsx(wt.span,{role:"slider","aria-label":n["aria-label"]||v,"aria-valuemin":o.min,"aria-valuenow":m,"aria-valuemax":o.max,"aria-orientation":o.orientation,"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,tabIndex:o.disabled?void 0:0,...i,ref:d,style:m===void 0?{display:"none"}:n.style,onFocus:De(n.onFocus,()=>{o.valueIndexToChangeRef.current=r})})}),f&&g.jsx(Kxe,{name:s??(o.name?o.name+(o.values.length>1?"[]":""):void 0),form:o.form,value:m},r)]})});CK.displayName=dk;var Kxe=n=>{const{value:e,...t}=n,r=P.useRef(null),s=Lxe(e);return P.useEffect(()=>{const i=r.current,o=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(o,"value").set;if(s!==e&&l){const c=new Event("input",{bubbles:!0});l.call(i,e),i.dispatchEvent(c)}},[s,e]),g.jsx("input",{style:{display:"none"},...t,ref:r,defaultValue:e})};function Wxe(n=[],e,t){const r=[...n];return r[t]=e,r.sort((s,i)=>s-i)}function PK(n,e,t){const i=100/(t-e)*(n-e);return dK(i,[0,100])}function Vxe(n,e){return e>2?`Value ${n+1} of ${e}`:e===2?["Minimum","Maximum"][n]:void 0}function qxe(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 Gxe(n,e,t){const r=n/2,i=OT([0,50],[0,r]);return(r-i(e)*t)*t}function Yxe(n){return n.slice(0,-1).map((e,t)=>n[t+1]-e)}function Xxe(n,e){if(e>0){const t=Yxe(n);return Math.min(...t)>=e}return!0}function OT(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 Zxe(n){return(String(n).split(".")[1]||"").length}function Jxe(n,e){const t=Math.pow(10,e);return Math.round(n*t)/t}var Qxe=mK,ewe=wK,twe=bK,nwe=CK;const rwe=P.memo(function({onHistoryMark:e,title:t,steps:r,value:s,label:i,onValueChange:o,["data-testid"]:a}){const l=ft(),c=P.useCallback(p=>{o(p[0])},[o]),d=P.useCallback(()=>{e("click slider")},[e]),f=P.useCallback(()=>{s&&o(s)},[s,o]);return g.jsx("div",{className:"tlui-slider__container",children:g.jsxs(Qxe,{"data-testid":a,className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:d,onValueChange:c,onPointerUp:f,title:t+" — "+l(i),children:[g.jsx(ewe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&g.jsx(twe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&g.jsx(nwe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function swe({label:n,uiTypeA:e,uiTypeB:t,labelA:r,labelB:s,itemsA:i,itemsB:o,styleA:a,styleB:l,valueA:c,valueB:d,onValueChange:f}){const p=ft(),m=P.useMemo(()=>{var v;return((v=i.find(x=>c.type==="shared"&&c.value===x.value))==null?void 0:v.icon)??"mixed"},[i,c]),y=P.useMemo(()=>{var v;return((v=o.find(x=>d.type==="shared"&&d.value===x.value))==null?void 0:v.icon)??"mixed"},[o,d]);return c===void 0&&d===void 0?null:g.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[g.jsx("div",{title:p(n),className:"tlui-style-panel__double-select-picker-label",children:p(n)}),g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsxs(su,{id:`style panel ${e} A`,children:[g.jsx(iu,{children:g.jsx(Ke,{type:"icon","data-testid":`style.${e}`,title:p(r)+" — "+(c===null||c.type==="mixed"?p("style-panel.mixed"):p(`${e}-style.${c.value}`)),children:g.jsx(ct,{icon:m,small:!0,invertIcon:!0})})}),g.jsx(ou,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:g.jsx("div",{className:"tlui-buttons__grid",children:i.map((v,x)=>g.jsx(gp,{"data-testid":`style.${e}.${v.value}`,children:g.jsx(Ke,{type:"icon",onClick:()=>f(a,v.value),title:`${p(r)} — ${p(`${e}-style.${v.value}`)}`,children:g.jsx(ct,{icon:v.icon,invertIcon:!0})},v.value)},x))})})]}),g.jsxs(su,{id:`style panel ${t}`,children:[g.jsx(iu,{children:g.jsx(Ke,{type:"icon","data-testid":`style.${t}`,title:p(s)+" — "+(d===null||d.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${d.value}`)),children:g.jsx(ct,{icon:y,small:!0})})}),g.jsx(ou,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:g.jsx("div",{className:"tlui-buttons__grid",children:o.map(v=>g.jsx(gp,{children:g.jsx(Ke,{type:"icon",title:`${p(s)} — ${p(`${t}-style.${v.value}`)}`,"data-testid":`style.${t}.${v.value}`,onClick:()=>f(l,v.value),children:g.jsx(ct,{icon:v.icon})})},v.value))})})]})]})]})}const iwe=P.memo(swe);function owe({id:n,label:e,uiType:t,stylePanelType:r,style:s,items:i,type:o,value:a,onValueChange:l}){const c=ft(),d=te(),f=P.useMemo(()=>{var v;return(v=i.find(x=>a.type==="shared"&&x.value===a.value))==null?void 0:v.icon},[i,a]),p=c(`style-panel.${r}`),m=a.type==="mixed"?c("style-panel.mixed"):p+" — "+c(`${t}-style.${a.value}`),y=e?c(e):"";return g.jsxs(su,{id:`style panel ${n}`,children:[g.jsx(iu,{children:g.jsxs(Ke,{type:o,"data-testid":`style.${t}`,title:m,children:[y&&g.jsx(wn,{children:y}),g.jsx(ct,{icon:f??"mixed"})]})}),g.jsx(ou,{side:"left",align:"center",alignOffset:0,children:g.jsx("div",{className:"tlui-buttons__grid",children:i.map(v=>g.jsx(gp,{children:g.jsx(Ke,{type:"icon","data-testid":`style.${t}.${v.value}`,title:p+" — "+c(`${t}-style.${v.value}`),onClick:()=>{d.markHistoryStoppingPoint("select style dropdown item"),l(s,v.value)},children:g.jsx(ct,{icon:v.icon})})},v.value))})})]})}const RT=P.memo(owe);function awe({styles:n}){const e=Up();if(!n)return null;const t=n.get(Wi),r=n.get(cS),s=n.get(lS),i=n.get(fS),o=n.get(Aa),a=t===void 0,l=r===void 0&&s===void 0,c=i===void 0,d=o===void 0,f=za({isDarkMode:e});return g.jsxs(g.Fragment,{children:[g.jsx(lwe,{theme:f,styles:n}),!d&&g.jsx(cwe,{theme:f,styles:n}),!(a&&l&&c)&&g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[g.jsx(uwe,{styles:n}),g.jsx(hwe,{styles:n}),g.jsx(dwe,{styles:n})]})]})}function Qp(){const n=te(),e=Rn();return He.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 lwe({styles:n,theme:e}){const t=ft(),r=te(),s=P.useCallback(f=>r.markHistoryStoppingPoint(f),[r]),i=Qp(),o=n.get(Ws),a=n.get(eu),l=n.get(Qc),c=n.get(Fo),d=a!==void 0||l!==void 0||c!==void 0;return g.jsxs(g.Fragment,{children:[g.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[o===void 0?null:g.jsx(Nc,{title:t("style-panel.color"),uiType:"color",style:Ws,items:gi.color,value:o,onValueChange:i,theme:e,onHistoryMark:s}),g.jsx(fwe,{})]}),d&&g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:g.jsx(Nc,{title:t("style-panel.fill"),uiType:"fill",style:eu,items:gi.fill,value:a,onValueChange:i,theme:e,onHistoryMark:s}),l===void 0?null:g.jsx(Nc,{title:t("style-panel.dash"),uiType:"dash",style:Qc,items:gi.dash,value:l,onValueChange:i,theme:e,onHistoryMark:s}),c===void 0?null:g.jsx(Nc,{title:t("style-panel.size"),uiType:"size",style:Fo,items:gi.size,value:c,onValueChange:(f,p)=>{i(f,p);const m=r.getSelectedShapeIds();m.length>0&&Ut(r,m)},theme:e,onHistoryMark:s})]})]})}function cwe({theme:n,styles:e}){const t=ft(),r=Qp(),s=te(),i=P.useCallback(d=>s.markHistoryStoppingPoint(d),[s]),o=e.get(Aa),a=e.get(iE),l=e.get(dS),c=e.get(hS);return o===void 0&&l===void 0?null:g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:g.jsx(Nc,{title:t("style-panel.font"),uiType:"font",style:Aa,items:gi.font,value:o,onValueChange:r,theme:n,onHistoryMark:i}),a===void 0?null:g.jsxs("div",{className:"tlui-style-panel__row",children:[g.jsx(Nc,{title:t("style-panel.align"),uiType:"align",style:iE,items:gi.textAlign,value:a,onValueChange:r,theme:n,onHistoryMark:i}),g.jsx("div",{className:"tlui-style-panel__row__extra-button",children:g.jsx(Ke,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:g.jsx(ct,{icon:"vertical-align-middle"})})})]}),l===void 0?null:g.jsxs("div",{className:"tlui-style-panel__row",children:[g.jsx(Nc,{title:t("style-panel.label-align"),uiType:"align",style:dS,items:gi.horizontalAlign,value:l,onValueChange:r,theme:n,onHistoryMark:i}),g.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?g.jsx(Ke,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:g.jsx(ct,{icon:"vertical-align-middle"})}):g.jsx(RT,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:hS,items:gi.verticalAlign,value:c,onValueChange:r})})]})]})}function uwe({styles:n}){const e=Qp(),t=n.get(Wi);return t===void 0?null:g.jsx(RT,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:Wi,items:gi.geo,value:t,onValueChange:e})}function dwe({styles:n}){const e=Qp(),t=n.get(fS);return t===void 0?null:g.jsx(RT,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:fS,items:gi.spline,value:t,onValueChange:e})}function hwe({styles:n}){const e=Qp(),t=n.get(cS),r=n.get(lS);return!t||!r?null:g.jsx(iwe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:lS,itemsA:gi.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:cS,itemsB:gi.arrowheadEnd,valueB:t,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const uf=[.1,.25,.5,.75,1];function fwe(){const n=te(),e=P.useCallback(a=>n.markHistoryStoppingPoint(a),[n]),t=ie("opacity",()=>n.getSharedOpacity(),[n]),r=Rn(),s=ft(),i=He.useCallback(a=>{const l=uf[a];n.run(()=>{n.isIn("select")&&n.setOpacityForSelectedShapes(l),n.setOpacityForNextShapes(l),n.updateInstanceState({isChangingStyle:!0})}),r("set-style",{source:"style-panel",id:"opacity",value:a})},[n,r]);if(t===void 0)return null;const o=t.type==="mixed"?-1:uf.indexOf(PV(uf,a=>Math.abs(a-t.value)));return g.jsx(rwe,{"data-testid":"style.opacity",value:o>=0?o:uf.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:i,steps:uf.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const pwe=P.memo(function({isMobile:e,children:t}){const r=te(),s=P.useRef(null);$a(s);const i=uK(),o=P.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=t??g.jsx(awe,{styles:i});return g.jsx("div",{ref:s,className:ze("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:o,children:a})}),gwe=He.forwardRef(function({children:e,className:t},r){return $a(r),Kae(r),g.jsx("div",{ref:r,"data-testid":"contextual-toolbar",className:ze("tlui-contextual-toolbar",t),onPointerDown:Xt,children:g.jsx("div",{className:"tlui-menu tlui-buttons__horizontal",role:"radiogroup",children:e})})});function mwe({textEditor:n,onEditLinkStart:e}){const t=Rn(),r=ft(),s="rich-text-menu",[i,o]=P.useState(0);return P.useEffect(function(){function c(){o(d=>d+1)}n.on("update",c),n.on("selectionUpdate",c)},[n]),P.useMemo(()=>{function l(c,d){t("rich-text",{operation:c,source:s}),n.chain().focus()[d]().run()}return[{name:"bold",onSelect(){l("bold","toggleBold")}},{name:"italic",onSelect(){l("bold","toggleItalic")}},{name:"code",onSelect(){l("bold","toggleCode")}},e?{name:"link",onSelect(){e()}}:void 0,{name:"bulletList",onSelect(){l("bulletList","toggleBulletList")}},{name:"highlight",onSelect(){l("bulletList","toggleHighlight")}}].filter(Boolean)},[n,t,e]).map(({name:l,attrs:c,onSelect:d})=>g.jsx(Ke,{title:r(`tool.rich-text-${l}`),"data-testid":`rich-text.${l}`,type:"icon",isActive:n.isActive(l,c),onPointerDown:tt,onClick:d,children:g.jsx(ct,{small:!0,icon:l})},l))}function ywe({textEditor:n,value:e,onComplete:t}){const r=te(),[s,i]=P.useState(e),o=ft(),a=P.useRef(null),l=Rn(),c="rich-text-menu",d=s.startsWith("http")?s:`https://${s}`,f=x=>i(x),p=x=>{l("rich-text",{operation:"link-edit",source:c}),!x.startsWith("http://")&&!x.startsWith("https://")&&(x=`https://${x}`),n.commands.setLink({href:x}),r.getInstanceState().isCoarsePointer?n.commands.blur():n.commands.focus(),t()},m=()=>{l("rich-text",{operation:"link-visit",source:c}),window.open(d,"_blank","noopener, noreferrer"),t()},y=()=>{l("rich-text",{operation:"link-remove",source:c}),n.chain().unsetLink().focus().run(),t()},v=()=>t();return P.useEffect(()=>{var x;s||(x=a.current)==null||x.focus()},[s]),P.useEffect(()=>{i(e)},[e]),g.jsxs(g.Fragment,{children:[g.jsx(Yp,{ref:a,"data-testid":"rich-text.link-input",className:"tlui-rich-text__toolbar-link-input",value:s,onValueChange:f,onComplete:p,onCancel:v,placeholder:"example.com"}),g.jsx(Ke,{className:"tlui-rich-text__toolbar-link-visit",title:o("tool.rich-text-link-visit"),type:"icon",onPointerDown:tt,onClick:m,disabled:!s,children:g.jsx(ct,{small:!0,icon:"external-link"})}),g.jsx(Ke,{className:"tlui-rich-text__toolbar-link-remove",title:o("tool.rich-text-link-remove"),"data-testid":"rich-text.link-remove",type:"icon",onPointerDown:tt,onClick:y,children:g.jsx(ct,{small:!0,icon:"trash"})})]})}const Swe=150,vwe=16,xwe=16,wwe=8,pl=16,bwe=16**2,Cwe=!0,Pwe=Vn(function({children:e}){const t=te(),r=ie("textEditor",()=>t.getRichTextEditor(),[t]);return t.getInstanceState().isCoarsePointer||!r?null:g.jsx(Ewe,{textEditor:r,children:e})});function Ewe({textEditor:n,children:e}){const t=te(),r=P.useRef(null),{isVisible:s,isInteractive:i,hide:o,show:a,position:l,move:c}=Twe(),{isEditingLink:d,onEditLinkStart:f,onEditLinkComplete:p}=Iwe(n),m=Sv("force toolbar position update",0);P.useEffect(function(){function _(){m.update(T=>T+1)}return yS.requestAnimationFrame("first forced update",_),n.on("selectionUpdate",_),()=>{n.off("selectionUpdate",_)}},[n,m]),jk("shape change",function(){t.getEditingShape(),m.update(_=>_+1)},[t]);const y=P.useRef(!1),[v,x]=P.useState(!1);Ca("toolbar position",function(){const _=r.current;if(!_)return;t.getCamera(),m.get();const T=kwe(t,_);if(!T){y.current&&(y.current=!1,x(!1));return}t.getCameraState()==="moving"?r.current.style.setProperty("transform",`translate(${T.x}px, ${T.y}px)`):c(T.x,T.y),y.current||(y.current=!0,x(!0))},[t,n,m]);const b=ie("camera state",()=>t.getCameraState(),[t]),C=Mwe(n);return P.useEffect(()=>{if(b==="moving"&&Cwe){o(!0);return}if(C||!v){o();return}a()},[v,b,C,a,o]),P.useLayoutEffect(()=>{const I=r.current;I&&(I.dataset.visible=`${s}`)},[s,l]),P.useLayoutEffect(()=>{const I=r.current;I&&I.style.setProperty("transform",`translate(${l.x}px, ${l.y}px)`)},[l]),P.useLayoutEffect(()=>{const I=r.current;I&&(I.dataset.interactive=`${i}`)},[i]),g.jsx(gwe,{ref:r,className:"tlui-rich-text__toolbar","data-interactive":!1,"data-visible":!1,children:e||(d?g.jsx(ywe,{textEditor:n,value:n.isActive("link")?n.getAttributes("link").href:"",onComplete:p}):g.jsx(mwe,{textEditor:n,onEditLinkStart:f}))})}function NL(n){return new ye(n.x,n.y,n.width,n.height)}function kwe(n,e){const t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return;const r=[];for(let f=0;f<t.rangeCount;f++){const p=t.getRangeAt(f);r.push(NL(p.getBoundingClientRect()))}const s=ye.Common(r),i=n.getViewportScreenBounds();if(s.x-=i.x,s.y-=i.y,s.midY<pl||s.midY>i.h-pl||s.midX<pl||s.midX>i.w-pl)return;const o=NL(e.getBoundingClientRect());if(!o.width||!o.height)return;const{scrollLeft:a,scrollTop:l}=n.getContainer();let c=s.midX-o.w/2,d=s.y-o.h-wwe;return c=Mn(c,pl,i.w-o.w-pl),d=Mn(d,pl,i.h-o.h-pl),c+=a,d+=l,c=Math.round(c),d=Math.round(d),{x:c,y:d}}function Iwe(n){const[e,t]=P.useState(!1);P.useEffect(()=>{if(!n){t(!1);return}const o=()=>{const a=n.isActive("link");t(a)};return n.view.dom.addEventListener("click",o),()=>{n.view.dom.removeEventListener("click",o)}},[n,e]),P.useEffect(()=>{if(n&&n.isActive("link"))try{const{from:o,to:a}=Ov(n.state.doc.resolve(n.state.selection.from),n.schema.marks.link);n.state.selection.empty&&n.commands.setTextSelection({from:o,to:a})}catch{}},[n,e]);const r=P.useCallback(()=>{t(!0)},[]),s=P.useCallback(()=>{t(!1)},[]),i=P.useCallback(()=>{if(t(!1),!n)return;const o=n.state.selection.from;n.commands.setTextSelection({from:o,to:o})},[n]);return{isEditingLink:e,onEditLinkStart:r,onEditLinkComplete:i,onEditLinkCancel:s}}function _we(n,e){return E.Sub(e,n).y**2>=bwe}function Twe(){const n=te(),e=P.useRef({name:"hidden"}),[t,r]=P.useState(!1),[s,i]=P.useState(!1),[o,a]=P.useState({x:-1e3,y:-1e3}),l=P.useRef(new E(-1e3,-1e3)),c=P.useRef(new E(-1e3,-1e3)),d=P.useRef(-1),f=P.useRef(-1),p=P.useCallback((v,x)=>{c.current.x=v,c.current.y=x,!(e.current.name==="hidden"||e.current.name==="showing")&&(clearTimeout(f.current),f.current=n.timers.setTimeout(()=>{if(e.current.name==="shown"&&_we(c.current,l.current)){const{x:b,y:C}=c.current;l.current=new E(b,C),a({x:b,y:C})}},Swe))},[n]),m=P.useCallback((v=!1)=>{switch(e.current.name){case"showing":{clearTimeout(d.current),e.current={name:"hidden"};break}case"shown":{e.current={name:"hiding"},r(!1),v?(e.current={name:"hidden"},i(!1)):d.current=n.timers.setTimeout(()=>{e.current={name:"hidden"},i(!1)},vwe);break}}},[n]),y=P.useCallback(()=>{switch(e.current.name){case"hidden":{e.current={name:"showing"},d.current=n.timers.setTimeout(()=>{const{x:v,y:x}=c.current;l.current=new E(v,x),a({x:v,y:x}),e.current={name:"shown"},i(!0),r(!0)},xwe);break}case"hiding":{clearTimeout(d.current),e.current={name:"shown"},r(!0),p(c.current.x,c.current.y);break}}},[n,p]);return{isVisible:s,isInteractive:t,show:y,hide:m,move:p,position:o}}function Mwe(n){const[e,t]=P.useState(!1);return P.useEffect(()=>{if(!n)return;const r=cv(({isPointing:l})=>{t(l)},16),s=()=>r({isPointing:!0}),i=()=>r({isPointing:!1}),o=["touchstart","pointerdown","mousedown"],a=["touchend","pointerup","mouseup"];return o.forEach(l=>{n.view.dom.addEventListener(l,s)}),a.forEach(l=>{document.body.addEventListener(l,i)}),()=>{o.forEach(l=>{n.view.dom.removeEventListener(l,s)}),a.forEach(l=>{document.body.removeEventListener(l,i)})}},[n]),e}function Awe(){const n=te(),e=ft(),t=uK(),r=t==null?void 0:t.get(Ws),s=za({isDarkMode:n.user.getIsDarkMode()}),i=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,o=ie("disable style panel",()=>n.isInAny("hand","zoom","eraser","laser"),[n]),a=P.useCallback(c=>{c||n.updateInstanceState({isChangingStyle:!1})},[n]),{StylePanel:l}=nc();return l?g.jsxs(_T,{id:"mobile style menu",onOpenChange:a,children:[g.jsx(TT,{children:g.jsx(Ke,{type:"tool","data-testid":"mobile-styles.button",style:{color:o?"var(--color-muted-1)":i},title:e("style-panel.title"),disabled:o,children:g.jsx(ct,{icon:o?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),g.jsx(MT,{side:"top",align:"end",children:l&&g.jsx(l,{isMobile:!0})})]}):null}function Owe(){return g.jsxs(g.Fragment,{children:[g.jsx(Dwe,{}),g.jsx(jwe,{}),g.jsx(Nwe,{}),g.jsx(Lwe,{}),g.jsx(Fwe,{}),g.jsx(zwe,{}),g.jsx($we,{}),g.jsx(Bwe,{}),g.jsx(Uwe,{}),g.jsx(Hwe,{}),g.jsx(Wwe,{}),g.jsx(Kwe,{}),g.jsx(Gwe,{}),g.jsx(Zwe,{}),g.jsx(Vwe,{}),g.jsx(Xwe,{}),g.jsx(Ywe,{}),g.jsx(qwe,{}),g.jsx(Jwe,{}),g.jsx(Qwe,{}),g.jsx(ebe,{}),g.jsx(tbe,{}),g.jsx(nbe,{}),g.jsx(rbe,{}),g.jsx(sbe,{}),g.jsx(ibe,{}),g.jsx(abe,{}),g.jsx(obe,{})]})}function Rwe(n){var r;const e=te(),t=(r=n.meta)==null?void 0:r.geo;return ie("is tool selected",()=>{const s=e.getCurrentToolId(),i=e.getSharedStyles().getAsKnownValue(Wi);return t?s==="geo"&&i===t:s===n.id},[e,n.id,t])}function Ft({tool:n}){const e=K_(),t=Rwe(e[n]);return g.jsx(hs,{toolId:n,isSelected:t})}function Dwe(){return g.jsx(Ft,{tool:"select"})}function jwe(){return g.jsx(Ft,{tool:"hand"})}function Nwe(){return g.jsx(Ft,{tool:"draw"})}function Lwe(){return g.jsx(Ft,{tool:"eraser"})}function Fwe(){return g.jsx(Ft,{tool:"arrow"})}function zwe(){return g.jsx(Ft,{tool:"text"})}function $we(){return g.jsx(Ft,{tool:"note"})}function Bwe(){return g.jsx(hs,{toolId:"asset"})}function Uwe(){return g.jsx(Ft,{tool:"rectangle"})}function Hwe(){return g.jsx(Ft,{tool:"ellipse"})}function Kwe(){return g.jsx(Ft,{tool:"diamond"})}function Wwe(){return g.jsx(Ft,{tool:"triangle"})}function Vwe(){return g.jsx(Ft,{tool:"rhombus"})}function qwe(){return g.jsx(Ft,{tool:"heart"})}function Gwe(){return g.jsx(Ft,{tool:"hexagon"})}function Ywe(){return g.jsx(Ft,{tool:"cloud"})}function Xwe(){return g.jsx(Ft,{tool:"star"})}function Zwe(){return g.jsx(Ft,{tool:"oval"})}function Jwe(){return g.jsx(Ft,{tool:"x-box"})}function Qwe(){return g.jsx(Ft,{tool:"check-box"})}function ebe(){return g.jsx(Ft,{tool:"arrow-left"})}function tbe(){return g.jsx(Ft,{tool:"arrow-up"})}function nbe(){return g.jsx(Ft,{tool:"arrow-down"})}function rbe(){return g.jsx(Ft,{tool:"arrow-right"})}function sbe(){return g.jsx(Ft,{tool:"line"})}function ibe(){return g.jsx(Ft,{tool:"highlight"})}function obe(){return g.jsx(Ft,{tool:"frame"})}function abe(){return g.jsx(Ft,{tool:"laser"})}const JC=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function QC(n,e,t,r){n.addEventListener?n.addEventListener(e,t,r):n.attachEvent&&n.attachEvent("on".concat(e),t)}function df(n,e,t,r){n.removeEventListener?n.removeEventListener(e,t,r):n.detachEvent&&n.detachEvent("on".concat(e),t)}function EK(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 kK(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 lbe(n,e){const t=n.length>=e.length?n:e,r=n.length>=e.length?e:n;let s=!0;for(let i=0;i<t.length;i++)r.indexOf(t[i])===-1&&(s=!1);return s}const vp={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,"-":JC?173:189,"=":JC?61:187,";":JC?59:186,"'":222,"[":219,"]":221,"\\":220},Ho={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Dy={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Zn={16:!1,18:!1,17:!1,91:!1},ln={};for(let n=1;n<20;n++)vp["f".concat(n)]=111+n;let tn=[],Hf=null,IK="all";const ya=new Map,eg=n=>vp[n.toLowerCase()]||Ho[n.toLowerCase()]||n.toUpperCase().charCodeAt(0),cbe=n=>Object.keys(vp).find(e=>vp[e]===n),ube=n=>Object.keys(Ho).find(e=>Ho[e]===n);function _K(n){IK=n||"all"}function xp(){return IK||"all"}function dbe(){return tn.slice(0)}function hbe(){return tn.map(n=>cbe(n)||ube(n)||String.fromCharCode(n))}function fbe(){const n=[];return Object.keys(ln).forEach(e=>{ln[e].forEach(t=>{let{key:r,scope:s,mods:i,shortcut:o}=t;n.push({scope:s,shortcut:o,mods:i,keys:r.split("+").map(a=>eg(a))})})}),n}function pbe(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 gbe(n){return typeof n=="string"&&(n=eg(n)),tn.indexOf(n)!==-1}function mbe(n,e){let t,r;n||(n=xp());for(const s in ln)if(Object.prototype.hasOwnProperty.call(ln,s))for(t=ln[s],r=0;r<t.length;)t[r].scope===n?t.splice(r,1).forEach(o=>{let{element:a}=o;return DT(a)}):r++;xp()===n&&_K(e||"all")}function ybe(n){let e=n.keyCode||n.which||n.charCode;const t=tn.indexOf(e);if(t>=0&&tn.splice(t,1),n.key&&n.key.toLowerCase()==="meta"&&tn.splice(0,tn.length),(e===93||e===224)&&(e=91),e in Zn){Zn[e]=!1;for(const r in Ho)Ho[r]===e&&(mi[r]=!1)}}function TK(n){if(typeof n>"u")Object.keys(ln).forEach(s=>{Array.isArray(ln[s])&&ln[s].forEach(i=>Gm(i)),delete ln[s]}),DT(null);else if(Array.isArray(n))n.forEach(s=>{s.key&&Gm(s)});else if(typeof n=="object")n.key&&Gm(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,i]=t;typeof s=="function"&&(i=s,s=""),Gm({key:n,scope:s,method:i,splitKey:"+"})}}const Gm=n=>{let{key:e,scope:t,method:r,splitKey:s="+"}=n;kK(e).forEach(o=>{const a=o.split(s),l=a.length,c=a[l-1],d=c==="*"?"*":eg(c);if(!ln[d])return;t||(t=xp());const f=l>1?EK(Ho,a):[],p=[];ln[d]=ln[d].filter(m=>{const v=(r?m.method===r:!0)&&m.scope===t&&lbe(m.mods,f);return v&&p.push(m.element),!v}),p.forEach(m=>DT(m))})};function LL(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 i in Zn)Object.prototype.hasOwnProperty.call(Zn,i)&&(!Zn[i]&&e.mods.indexOf(+i)>-1||Zn[i]&&e.mods.indexOf(+i)===-1)&&(s=!1);(e.mods.length===0&&!Zn[16]&&!Zn[18]&&!Zn[17]&&!Zn[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(tn),e.method(n,e)===!1&&(n.preventDefault?n.preventDefault():n.returnValue=!1,n.stopPropagation&&n.stopPropagation(),n.cancelBubble&&(n.cancelBubble=!0)))}}function FL(n,e){const t=ln["*"];let r=n.keyCode||n.which||n.charCode;if(!mi.filter.call(this,n))return;if((r===93||r===224)&&(r=91),tn.indexOf(r)===-1&&r!==229&&tn.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=Dy[a];n[a]&&tn.indexOf(l)===-1?tn.push(l):!n[a]&&tn.indexOf(l)>-1?tn.splice(tn.indexOf(l),1):a==="metaKey"&&n[a]&&(tn=tn.filter(c=>c in Dy||c===r))}),r in Zn){Zn[r]=!0;for(const a in Ho)Ho[a]===r&&(mi[a]=!0);if(!t)return}for(const a in Zn)Object.prototype.hasOwnProperty.call(Zn,a)&&(Zn[a]=n[Dy[a]]);n.getModifierState&&!(n.altKey&&!n.ctrlKey)&&n.getModifierState("AltGraph")&&(tn.indexOf(17)===-1&&tn.push(17),tn.indexOf(18)===-1&&tn.push(18),Zn[17]=!0,Zn[18]=!0);const s=xp();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)&&LL(n,t[a],s,e);if(!(r in ln))return;const i=ln[r],o=i.length;for(let a=0;a<o;a++)if((n.type==="keydown"&&i[a].keydown||n.type==="keyup"&&i[a].keyup)&&i[a].key){const l=i[a],{splitKey:c}=l,d=l.key.split(c),f=[];for(let p=0;p<d.length;p++)f.push(eg(d[p]));f.sort().join("")===tn.sort().join("")&&LL(n,l,s,e)}}function mi(n,e,t){tn=[];const r=kK(n);let s=[],i="all",o=document,a=0,l=!1,c=!0,d="+",f=!1,p=!1;for(t===void 0&&typeof e=="function"&&(t=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(i=e.scope),e.element&&(o=e.element),e.keyup&&(l=e.keyup),e.keydown!==void 0&&(c=e.keydown),e.capture!==void 0&&(f=e.capture),typeof e.splitKey=="string"&&(d=e.splitKey),e.single===!0&&(p=!0)),typeof e=="string"&&(i=e),p&&TK(n,i);a<r.length;a++)n=r[a].split(d),s=[],n.length>1&&(s=EK(Ho,n)),n=n[n.length-1],n=n==="*"?"*":eg(n),n in ln||(ln[n]=[]),ln[n].push({keyup:l,keydown:c,scope:i,mods:s,shortcut:r[a],method:t,key:r[a],splitKey:d,element:o});if(typeof o<"u"&&window){if(!ya.has(o)){const m=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return FL(v,o)},y=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;FL(v,o),ybe(v)};ya.set(o,{keydownListener:m,keyupListenr:y,capture:f}),QC(o,"keydown",m,f),QC(o,"keyup",y,f)}if(!Hf){const m=()=>{tn=[]};Hf={listener:m,capture:f},QC(window,"focus",m,f)}}}function Sbe(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ln).forEach(t=>{ln[t].filter(s=>s.scope===e&&s.shortcut===n).forEach(s=>{s&&s.method&&s.method()})})}function DT(n){const e=Object.values(ln).flat();if(e.findIndex(r=>{let{element:s}=r;return s===n})<0){const{keydownListener:r,keyupListenr:s,capture:i}=ya.get(n)||{};r&&s&&(df(n,"keyup",s,i),df(n,"keydown",r,i),ya.delete(n))}if((e.length<=0||ya.size<=0)&&(Object.keys(ya).forEach(s=>{const{keydownListener:i,keyupListenr:o,capture:a}=ya.get(s)||{};i&&o&&(df(s,"keyup",o,a),df(s,"keydown",i,a),ya.delete(s))}),ya.clear(),Object.keys(ln).forEach(s=>delete ln[s]),Hf)){const{listener:s,capture:i}=Hf;df(window,"focus",s,i),Hf=null}}const eP={getPressedKeyString:hbe,setScope:_K,getScope:xp,deleteScope:mbe,getPressedKeyCodes:dbe,getAllKeyCodes:fbe,isPressed:gbe,filter:pbe,trigger:Sbe,unbind:TK,keyMap:vp,modifier:Ho,modifierMap:Dy};for(const n in eP)Object.prototype.hasOwnProperty.call(eP,n)&&(mi[n]=eP[n]);if(typeof window<"u"){const n=window.hotkeys;mi.noConflict=e=>(e&&window.hotkeys===mi&&(window.hotkeys=n),mi),window.hotkeys=mi}const zL=["copy","cut","paste","asset"];function vbe(){const n=te(),e=Ys(),t=yu(),r=K_(),s=ie("is focused",()=>n.getInstanceState().isFocused,[n]);P.useEffect(()=>{if(!s)return;const i=new Array,o=(l,c)=>{mi(l,{element:document.body},c),i.push(()=>{mi.unbind(l,c)})},a=(l,c)=>{mi(l,{element:document.body,keyup:!0,keydown:!1},c),i.push(()=>{mi.unbind(l,c)})};for(const l of Object.values(t))l.kbd&&(e&&!l.readonlyOk||zL.includes(l.id)||o($L(l.kbd),c=>{kf(n)||(tt(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&n.getIsReadonly()||zL.includes(l.id)||o($L(l.kbd),c=>{kf(n)||(tt(c),l.onSelect("kbd"))});return o(",",l=>{if(kf(n)||n.inputs.keys.has("Comma"))return;tt(l),n.focus(),n.inputs.keys.add("Comma");const{x:c,y:d,z:f}=n.inputs.currentPagePoint,p=n.pageToScreen({x:c,y:d}),m={type:"pointer",name:"pointer_down",point:{x:p.x,y:p.y,z:f},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:Cr(l),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(m)}),a(",",l=>{if(kf(n)||!n.inputs.keys.has("Comma"))return;n.inputs.keys.delete("Comma");const{x:c,y:d,z:f}=n.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:d,z:f},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:Cr(l),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(p)}),()=>{i.forEach(l=>l())}},[t,r,e,n,s])}function $L(n){return xbe(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 xbe(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 kf(n){return n.menus.hasAnyOpenMenus()||n.getEditingShapeId()!==null||n.getCrashingError()}const wbe=P.createContext(!1),bbe={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,0:9};function Cbe({children:n}){const e=te(),t=pu(),r=qr(),s=ft(),i=P.useRef([]),o=Math.min(8,5+r),[a,l]=P.useState(0),c=P.useRef(null),[d,f]=P.useState(null),p=P.useMemo(()=>{const y=d?`:not([data-value="${d}"])`:"";return`
516
+ #${t}_main > *:nth-child(n + ${o+(d?1:2)})${y} {
517
+ display: none;
518
+ }
519
+ #${t}_more > *:nth-child(-n + ${o}) {
520
+ display: none;
521
+ }
522
+ `},[d,t,o]),m=Xv(()=>{var b;if(!c.current)return;const y=Array.from(c.current.children);l(y.length),y.findIndex(C=>C.getAttribute("data-value")===d)<=o&&f(null);const x=Array.from(c.current.children).findIndex(C=>C.getAttribute("aria-checked")==="true");x!==-1&&(x>=o&&f(y[x].getAttribute("data-value")),i.current=Array.from(((b=c.current)==null?void 0:b.children)??[]).filter(C=>!(C instanceof HTMLElement)||C.tagName.toLowerCase()!=="button"?!1:!!(C.offsetWidth||C.offsetHeight)))});return P.useLayoutEffect(()=>{m()}),P.useLayoutEffect(()=>{if(!c.current)return;const y=new MutationObserver(m);return y.observe(c.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{y.disconnect()}},[m]),P.useEffect(()=>{if(!e.options.enableToolbarKeyboardShortcuts)return;function y(v){var b;if(kf(e)||H4()||v.ctrlKey||v.metaKey||v.altKey||v.shiftKey)return;const x=bbe[v.key];typeof x=="number"&&(tt(v),(b=i.current[x])==null||b.click())}return document.addEventListener("keydown",y),()=>{document.removeEventListener("keydown",y)}},[e]),g.jsxs(g.Fragment,{children:[g.jsx("style",{children:p}),g.jsxs("div",{className:ze("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<gn.TABLET_SM}),role:"radiogroup",children:[g.jsx("div",{id:`${t}_main`,ref:c,className:"tlui-toolbar__tools__list",children:g.jsx(Ci,{type:"toolbar",sourceId:"toolbar",children:n})}),a>o+1&&g.jsx(wbe.Provider,{value:!0,children:g.jsxs(su,{id:"toolbar overflow",modal:!1,children:[g.jsx(iu,{children:g.jsx(Ke,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:g.jsx(ct,{icon:"chevron-up"})})}),g.jsx(ou,{side:"top",align:"center",children:g.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:g.jsx(Ci,{type:"toolbar-overflow",sourceId:"toolbar",children:n})})})]})})]})]})}function Pbe({activeToolId:n}){const e=te(),t=qr(),r=ft(),s=ie("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),i=ie("current tool",()=>e.getCurrentTool(),[e]);return!n||!i.isLockable?null:g.jsx(Ke,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ze("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<gn.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:g.jsx(ct,{icon:s?"lock":"unlock",small:!0})})}const Ebe=P.memo(function({children:e}){const t=te(),r=qr(),s=Ys(),i=ie("current tool id",()=>t.getCurrentToolId(),[t]),o=P.useRef(null);$a(o);const{ActionsMenu:a,QuickActions:l}=nc(),c=t.options.actionShortcutsLocation==="menu"?!1:t.options.actionShortcutsLocation==="toolbar"?!0:r<gn.TABLET;return g.jsx("div",{ref:o,className:"tlui-toolbar",children:g.jsxs("div",{className:"tlui-toolbar__inner",children:[g.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&g.jsxs("div",{className:"tlui-toolbar__extras",children:[c&&g.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[l&&g.jsx(l,{}),a&&g.jsx(a,{})]}),g.jsx(Pbe,{activeToolId:i})]}),g.jsx(Cbe,{children:e??g.jsx(Owe,{})})]}),r<gn.TABLET_SM&&!s&&g.jsx("div",{className:"tlui-toolbar__tools",children:g.jsx(Awe,{})})]})})});function kbe(){const n=ft();return g.jsxs("div",{className:ze("tlui-offline-indicator"),children:[n("status.offline"),g.jsx(Bo,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function Ibe({maxWidth:n=420,ignoreRightWidth:e=0,stylePanelWidth:t=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:i}){const o=P.useRef(null),a=qr(),l=P.useCallback(()=>{const c=o.current;if(!c)return;const d=c.parentElement.parentElement,f=d.querySelector(".tlui-layout__top__left"),p=d.querySelector(".tlui-layout__top__right"),m=d.offsetWidth,y=f.offsetWidth,v=p.offsetWidth,x=c.offsetWidth-e;let b=(m-x)/2;m%2!==0&&(b-=.5);const C=y+r,I=c.offsetLeft,_=Math.min(m-v-y-2*r,n),T=Math.max(b,C)-I;p.offsetWidth>t&&a<=6?c.style.setProperty("max-width",_-s+"px"):c.style.setProperty("max-width",_+"px"),c.style.setProperty("transform",`translate(${T}px, 0px)`)},[a,e,r,n,s,t]);return P.useLayoutEffect(()=>{const c=o.current;if(!c)return;const d=c.parentElement.parentElement,f=d.querySelector(".tlui-layout__top__left"),p=d.querySelector(".tlui-layout__top__right"),m=new ResizeObserver(l);return m.observe(f),m.observe(p),m.observe(d),m.observe(c),l(),()=>{m.disconnect()}},[l]),P.useLayoutEffect(()=>{l()}),g.jsx("div",{ref:o,className:"tlui-top-panel__container",children:i})}function _be(){const n=jhe()==="offline";return g.jsx(Ibe,{children:n&&g.jsx(kbe,{})})}function Tbe(){return g.jsxs(g.Fragment,{children:[g.jsx(ue,{actionId:"zoom-in",noClose:!0}),g.jsx(ue,{actionId:"zoom-out",noClose:!0}),g.jsx(NH,{}),g.jsx(LH,{}),g.jsx(FH,{})]})}const Mbe=P.memo(function({children:e}){const t=In(),[r,s]=Ua("zoom menu"),i=e??g.jsx(Tbe,{});return g.jsxs(I_,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[g.jsx(__,{asChild:!0,dir:"ltr",children:g.jsx(Abe,{})}),g.jsx(y0,{container:t,children:g.jsx(T_,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:g.jsx(Ci,{type:"menu",sourceId:"zoom-menu",children:i})})})]})}),Abe=P.forwardRef(function(e,t){const r=te(),s=qr(),i=ie("zoom",()=>r.getZoomLevel(),[r]),o=ft(),a=P.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return g.jsx(Ke,{ref:t,...e,type:"icon",title:`${o("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<gn.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:s<gn.MOBILE?null:g.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(i*100),"%"]})})}),MK=P.createContext(null);function Obe({overrides:n={},children:e}){const t=ih(n),r=w0();return g.jsx(MK.Provider,{value:P.useMemo(()=>({ContextMenu:M0e,ActionsMenu:s0e,HelpMenu:null,ZoomMenu:Mbe,MainMenu:uxe,Minimap:xxe,StylePanel:pwe,PageMenu:Pxe,NavigationPanel:bxe,Toolbar:Ebe,RichTextToolbar:Pwe,KeyboardShortcutsDialog:Q0e,QuickActions:_xe,HelperButtons:Z0e,DebugPanel:U0e,DebugMenu:B0e,MenuPanel:V0e,SharePanel:r?jxe:null,CursorChatBubble:r?R0e:null,TopPanel:r?_be:null,Dialogs:Gfe,Toasts:Jfe,...t}),[t,r]),children:e})}function nc(){const n=P.useContext(MK);if(!n)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return n}const Rbe=Vn(function({overrides:e,components:t,assetUrls:r,onUiEvent:s,forceMobile:i,mediaMimeTypes:o,children:a}){const l=Tr();return g.jsx(g9.Provider,{value:o,children:g.jsx(ahe,{assetUrls:Ove(r),children:g.jsx(uhe,{overrides:Dfe(e),locale:(l==null?void 0:l.user.getLocale())??bo.locale,children:g.jsx(Qae,{onEvent:s,children:g.jsx(ofe,{children:g.jsx(Lhe,{context:"tla",children:g.jsx(Nhe,{forceMobile:i,children:g.jsx(Obe,{overrides:t,children:g.jsx(Dbe,{overrides:e,children:a})})})})})})})})})});function Dbe({overrides:n,children:e}){const t=jfe(n);return g.jsx(Lfe,{overrides:t.actions,children:g.jsx(Qfe,{overrides:t.tools,children:e})})}function jbe(){const n=te(),{addToast:e}=Ba();P.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 Nbe=He.memo(function({renderDebugMenuItems:e,children:t,hideUi:r,components:s,...i}){return g.jsx(Rbe,{...i,components:s,children:g.jsx(Lbe,{hideUi:r,renderDebugMenuItems:e,children:t})})}),Lbe=He.memo(function({children:e,hideUi:t,...r}){return g.jsxs(g.Fragment,{children:[e,t?null:g.jsx(Fbe,{...r})]})}),Fbe=He.memo(function(){const e=te(),t=ft(),r=qr(),s=Ys(),i=ie("focus",()=>e.getInstanceState().isFocusMode,[e]),o=ie("debug",()=>e.getInstanceState().isDebugMode,[e]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:d,Toolbar:f,HelpMenu:p,NavigationPanel:m,HelperButtons:y,DebugPanel:v,CursorChatBubble:x,RichTextToolbar:b,Toasts:C,Dialogs:I}=nc();vbe(),Cfe(),jbe();const _=P.useRef(!1),T=P.useRef(-1),[A,R]=P.useState(!1);jk("update hide toolbar while delayed",()=>{if(!(Pt.isIos||Pt.isAndroid))return;if(e.getEditingShapeId()===null){_.current&&(_.current=!1,clearTimeout(T.current),Pt.isAndroid?T.current=e.timers.setTimeout(()=>{R(!1)},150):R(!1));return}_.current||(_.current=!0,clearTimeout(T.current),R(!0))},[]);const{"toggle-focus-mode":j}=yu();return g.jsxs("div",{className:ze("tlui-layout",{"tlui-layout__mobile":r<gn.TABLET_SM}),"data-iseditinganything":A,"data-breakpoint":r,children:[i?g.jsx("div",{className:"tlui-layout__top",children:g.jsx(Ke,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>j.onSelect("menu"),children:g.jsx(ct,{icon:"dot"})})}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"tlui-layout__top",children:[g.jsxs("div",{className:"tlui-layout__top__left",children:[c&&g.jsx(c,{}),y&&g.jsx(y,{})]}),g.jsx("div",{className:"tlui-layout__top__center",children:l&&g.jsx(l,{})}),g.jsxs("div",{className:"tlui-layout__top__right",children:[a&&g.jsx(a,{}),d&&r>=gn.TABLET_SM&&!s&&g.jsx(d,{})]})]}),g.jsxs("div",{className:"tlui-layout__bottom",children:[g.jsxs("div",{className:"tlui-layout__bottom__main",children:[m&&g.jsx(m,{}),f&&g.jsx(f,{}),p&&g.jsx(p,{})]}),o&&v&&g.jsx(v,{})]})]}),b&&g.jsx(b,{}),C&&g.jsx(C,{}),I&&g.jsx(I,{}),g.jsx(_ve,{}),x&&g.jsx(x,{})]})}),zbe=[...Ive,...Wme];function $be(n){const{children:e,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:i,onMount:o,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:d=[],embeds:f,textOptions:p,...m}=n,y=ih(a),v=P.useMemo(()=>({Scribble:NN,ShapeIndicators:upe,CollaboratorScribble:NN,SelectionForeground:ape,SelectionBackground:ipe,Handles:epe,...y}),[y]),x=Pl(l),b=P.useMemo(()=>_w("type",x,_7),[x]),C=Pl(c),I=P.useMemo(()=>_w("type",C,C9),[C]),_=Pl(d),T=P.useMemo(()=>_w("id",zbe,_),[_]),A=Pl(s??wp),R=Pl(i??uv),j=P.useMemo(()=>({addFontsFromNode:z9,...p,tipTapConfig:{extensions:Zp,...p==null?void 0:p.tipTapConfig}}),[p]),K=P.useMemo(()=>[...A,...R],[A,R]),U=Mve(m.assetUrls);return b.find(z=>z.type==="embed")&&f&&av.setEmbedDefinitions(f),g.jsx(Nae,{initialState:"select",...m,components:v,shapeUtils:b,bindingUtils:I,tools:T,textOptions:j,assetUrls:U,children:g.jsxs(Nbe,{...m,components:v,mediaMimeTypes:K,children:[g.jsx(Bbe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:A,acceptedVideoMimeTypes:R,onMount:o}),e]})})}function Bbe({maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,onMount:s}){const i=te(),o=Ba(),a=ft();A6(()=>{const d=[];return d.push(ZSe(i)),i.fonts.requestFonts(nme),gme(i,{maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,toasts:o,msg:a}),d.push(i.store.props.onMount(i)),d.push(s==null?void 0:s(i)),()=>{d.forEach(f=>f==null?void 0:f())}});const{Canvas:l}=Zt(),{ContextMenu:c}=nc();return c?g.jsx(c,{}):l?g.jsx(l,{}):null}const Ube={tipTapConfig:{extensions:Zp},addFontsFromNode:z9};P.memo(function(e){const[t,r]=P.useState(null),[s,i]=P.useState(null),o=Pl(e.shapeUtils??[]),a=P.useMemo(()=>[..._7,...o],[o]),l=Pl(e.bindingUtils??[]),c=P.useMemo(()=>[...C9,...l],[l]),d=Wae({snapshot:e.snapshot,shapeUtils:a}),{pageId:f,bounds:p,scale:m,pixelRatio:y,background:v,padding:x,darkMode:b,preserveAspectRatio:C,format:I="svg",licenseKey:_,assetUrls:T,textOptions:A=Ube}=e;return P.useLayoutEffect(()=>{if(!s||!d)return;let R=!1;const j=document.createElement("div");s.appendChild(j),s.classList.add("tl-container","tl-theme__light");const K=new Ee({store:d,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>j,licenseKey:_,fontAssetUrls:T==null?void 0:T.fonts,textOptions:A});f&&K.setCurrentPage(f);const U=K.getCurrentPageShapeIds();async function J(){const z=await K.toImage([...U],{bounds:p,scale:m,background:v,padding:x,darkMode:b,preserveAspectRatio:C,format:I});if(!z||R)return;const N=URL.createObjectURL(z.blob);r(N),K.dispose()}return J(),()=>{R=!0}},[I,s,d,a,c,f,p,m,v,x,b,C,_,y,T,A]),P.useEffect(()=>()=>{t&&URL.revokeObjectURL(t)},[t]),g.jsx("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:t&&g.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})})});P.memo(function({children:e}){const t=ft(),r=qr(),s=P.useRef(null);$a(s);const i=e??g.jsx(exe,{});return r<gn.MOBILE?null:g.jsx("div",{ref:s,className:"tlui-help-menu",children:g.jsxs(su,{id:"help menu",children:[g.jsx(iu,{children:g.jsx(Ke,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:g.jsx(ct,{icon:"question-mark",small:!0})})}),g.jsx(ou,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:g.jsx(Ci,{type:"menu",sourceId:"help-menu",children:i})})]})})});const Hbe=1,Kbe=ht({schemaVersion:kr(1),storeVersion:ny,recordVersions:oS(ot,ht({version:ny,subTypeVersions:oS(ot,ny).optional(),subTypeKey:ot.optional()}))}),Wbe=ht({schemaVersion:kr(2),sequences:oS(ot,ny)}),Vbe=ht({tldrawFileFormatVersion:Aee,schema:Oee("schemaVersion",{1:Kbe,2:Wbe}),records:zn(ht({id:ot,typeName:ot}).allowUnknownProperties())});function qbe(n){var e;try{return!!((e=n.document)!=null&&e.version)}catch{return!1}}function Gbe({json:n,schema:e}){let t;try{t=Vbe.validate(JSON.parse(n))}catch(i){try{if(t=JSON.parse(n),qbe(t))return jr.err({type:"v1File",data:t})}catch{}return jr.err({type:"notATldrawFile",cause:i})}if(t.tldrawFileFormatVersion>Hbe)return jr.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r,s;try{const i=Ybe(t.records);s=Object.fromEntries(i.map(o=>[o.id,o])),r=e.migrateStoreSnapshot({store:s,schema:t.schema})}catch(i){return jr.err({type:"invalidRecords",cause:i})}if(r.type==="error")return jr.err({type:"migrationFailed",reason:r.reason});try{return jr.ok(lp({snapshot:{store:s,schema:t.schema},schema:e}))}catch(i){return jr.err({type:"invalidRecords",cause:i})}}function Ybe(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))}Wl("tldraw","3.10.3","esm");function Xbe(){const[n,e]=P.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 i=Gbe({json:s,schema:r.store.schema});i.ok?(console.log("Loaded tldr file from local endpoint"),e(i.value)):console.error(`Couldn't parse tldr file: ${String(i.error.type)}`)}).catch(s=>{console.error("Couldn't fetch data:",s)}):(r.zoomToFit(),r.menus.clearOpenMenus())}return g.jsx("div",{style:{inset:0,position:"fixed"},children:g.jsx($be,{assetUrls:gV(),onMount:t,store:n})})}pV.createRoot(document.querySelector("#root")).render(g.jsx(He.StrictMode,{children:g.jsx(Xbe,{})}));