@kitschpatrol/tldraw-cli 4.6.34 → 4.6.36

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 (62) hide show
  1. package/bin/cli.js +5 -5
  2. package/dist/lib/index.js +3 -3
  3. package/dist/lib/inline/get-image.d.ts +1 -1
  4. package/dist/lib/inline/get-tldr.d.ts +1 -1
  5. package/dist/lib/inline/set-tldr.d.ts +1 -1
  6. package/dist/lib/tldraw-open.d.ts +1 -1
  7. package/dist/tldraw/assets/index-CVVHYKYT.css +1 -0
  8. package/dist/tldraw/assets/index-Dr4aLNdU.js +518 -0
  9. package/dist/tldraw/index.html +2 -2
  10. package/dist/tldraw/translations/ar.json +1 -1
  11. package/dist/tldraw/translations/bn.json +1 -1
  12. package/dist/tldraw/translations/ca.json +1 -1
  13. package/dist/tldraw/translations/cs.json +1 -1
  14. package/dist/tldraw/translations/da.json +14 -14
  15. package/dist/tldraw/translations/de.json +2 -2
  16. package/dist/tldraw/translations/el.json +1 -1
  17. package/dist/tldraw/translations/es.json +1 -1
  18. package/dist/tldraw/translations/fa.json +1 -1
  19. package/dist/tldraw/translations/fi.json +12 -12
  20. package/dist/tldraw/translations/fr.json +4 -3
  21. package/dist/tldraw/translations/gl.json +2 -2
  22. package/dist/tldraw/translations/gu-in.json +1 -1
  23. package/dist/tldraw/translations/he.json +6 -5
  24. package/dist/tldraw/translations/hi-in.json +1 -1
  25. package/dist/tldraw/translations/hr.json +1 -1
  26. package/dist/tldraw/translations/hu.json +1 -1
  27. package/dist/tldraw/translations/id.json +1 -1
  28. package/dist/tldraw/translations/it.json +5 -5
  29. package/dist/tldraw/translations/km-kh.json +12 -12
  30. package/dist/tldraw/translations/kn.json +1 -1
  31. package/dist/tldraw/translations/ko-kr.json +13 -2
  32. package/dist/tldraw/translations/main.json +2 -0
  33. package/dist/tldraw/translations/ml.json +1 -1
  34. package/dist/tldraw/translations/mr.json +1 -1
  35. package/dist/tldraw/translations/ms.json +1 -1
  36. package/dist/tldraw/translations/ne.json +1 -1
  37. package/dist/tldraw/translations/nl.json +21 -8
  38. package/dist/tldraw/translations/no.json +3 -3
  39. package/dist/tldraw/translations/pa.json +1 -1
  40. package/dist/tldraw/translations/pl.json +6 -6
  41. package/dist/tldraw/translations/pt-br.json +1 -1
  42. package/dist/tldraw/translations/pt-pt.json +1 -1
  43. package/dist/tldraw/translations/ro.json +13 -13
  44. package/dist/tldraw/translations/ru.json +1 -1
  45. package/dist/tldraw/translations/sl.json +1 -1
  46. package/dist/tldraw/translations/so.json +13 -13
  47. package/dist/tldraw/translations/sv.json +1 -1
  48. package/dist/tldraw/translations/ta.json +1 -1
  49. package/dist/tldraw/translations/te.json +1 -1
  50. package/dist/tldraw/translations/th.json +1 -1
  51. package/dist/tldraw/translations/tl.json +1 -1
  52. package/dist/tldraw/translations/tr.json +8 -8
  53. package/dist/tldraw/translations/uk.json +1 -1
  54. package/dist/tldraw/translations/ur.json +1 -1
  55. package/dist/tldraw/translations/vi.json +16 -16
  56. package/dist/tldraw/translations/zh-cn.json +1 -1
  57. package/dist/tldraw/translations/zh-tw.json +1 -1
  58. package/package.json +12 -12
  59. package/readme.md +5 -15
  60. package/dist/.DS_Store +0 -0
  61. package/dist/tldraw/assets/index-BK7ffB3e.css +0 -1
  62. package/dist/tldraw/assets/index-CCEXN6Jj.js +0 -522
@@ -0,0 +1,518 @@
1
+ var qW=Object.defineProperty;var GW=(n,e,t)=>e in n?qW(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var R=(n,e,t)=>GW(n,typeof e!="symbol"?e+"":e,t);function YW(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 ws=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $a(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var bw={exports:{}},Qh={},Cw={exports:{}},mt={};/**
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 HM;function XW(){if(HM)return mt;HM=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 g(K){return K===null||typeof K!="object"?null:(K=f&&K[f]||K["@@iterator"],typeof K=="function"?K:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},y=Object.assign,v={};function x(K,ne,ge){this.props=K,this.context=ne,this.refs=v,this.updater=ge||m}x.prototype.isReactComponent={},x.prototype.setState=function(K,ne){if(typeof K!="object"&&typeof K!="function"&&K!=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,K,ne,"setState")},x.prototype.forceUpdate=function(K){this.updater.enqueueForceUpdate(this,K,"forceUpdate")};function b(){}b.prototype=x.prototype;function C(K,ne,ge){this.props=K,this.context=ne,this.refs=v,this.updater=ge||m}var E=C.prototype=new b;E.constructor=C,y(E,x.prototype),E.isPureReactComponent=!0;var _=Array.isArray,M=Object.prototype.hasOwnProperty,A={current:null},O={key:!0,ref:!0,__self:!0,__source:!0};function D(K,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)M.call(ne,Pe)&&!O.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),We=0;We<Ce;We++)_e[We]=arguments[We+2];ce.children=_e}if(K&&K.defaultProps)for(Pe in Ce=K.defaultProps,Ce)ce[Pe]===void 0&&(ce[Pe]=Ce[Pe]);return{$$typeof:n,type:K,key:Be,ref:Re,props:ce,_owner:A.current}}function B(K,ne){return{$$typeof:n,type:K.type,key:ne,ref:K.ref,props:K.props,_owner:K._owner}}function U(K){return typeof K=="object"&&K!==null&&K.$$typeof===n}function G(K){var ne={"=":"=0",":":"=2"};return"$"+K.replace(/[=:]/g,function(ge){return ne[ge]})}var z=/\/+/g;function N(K,ne){return typeof K=="object"&&K!==null&&K.key!=null?G(""+K.key):ne.toString(36)}function L(K,ne,ge,Pe,ce){var Be=typeof K;(Be==="undefined"||Be==="boolean")&&(K=null);var Re=!1;if(K===null)Re=!0;else switch(Be){case"string":case"number":Re=!0;break;case"object":switch(K.$$typeof){case n:case e:Re=!0}}if(Re)return Re=K,ce=ce(Re),K=Pe===""?"."+N(Re,0):Pe,_(ce)?(ge="",K!=null&&(ge=K.replace(z,"$&/")+"/"),L(ce,ne,ge,"",function(We){return We})):ce!=null&&(U(ce)&&(ce=B(ce,ge+(!ce.key||Re&&Re.key===ce.key?"":(""+ce.key).replace(z,"$&/")+"/")+K)),ne.push(ce)),1;if(Re=0,Pe=Pe===""?".":Pe+":",_(K))for(var Ce=0;Ce<K.length;Ce++){Be=K[Ce];var _e=Pe+N(Be,Ce);Re+=L(Be,ne,ge,_e,ce)}else if(_e=g(K),typeof _e=="function")for(K=_e.call(K),Ce=0;!(Be=K.next()).done;)Be=Be.value,_e=Pe+N(Be,Ce++),Re+=L(Be,ne,ge,_e,ce);else if(Be==="object")throw ne=String(K),Error("Objects are not valid as a React child (found: "+(ne==="[object Object]"?"object with keys {"+Object.keys(K).join(", ")+"}":ne)+"). If you meant to render a collection of children, use an array instead.");return Re}function V(K,ne,ge){if(K==null)return K;var Pe=[],ce=0;return L(K,Pe,"","",function(Be){return ne.call(ge,Be,ce++)}),Pe}function Z(K){if(K._status===-1){var ne=K._result;ne=ne(),ne.then(function(ge){(K._status===0||K._status===-1)&&(K._status=1,K._result=ge)},function(ge){(K._status===0||K._status===-1)&&(K._status=2,K._result=ge)}),K._status===-1&&(K._status=0,K._result=ne)}if(K._status===1)return K._result.default;throw K._result}var W={current:null},$={transition:null},Y={ReactCurrentDispatcher:W,ReactCurrentBatchConfig:$,ReactCurrentOwner:A};function re(){throw Error("act(...) is not supported in production builds of React.")}return mt.Children={map:V,forEach:function(K,ne,ge){V(K,function(){ne.apply(this,arguments)},ge)},count:function(K){var ne=0;return V(K,function(){ne++}),ne},toArray:function(K){return V(K,function(ne){return ne})||[]},only:function(K){if(!U(K))throw Error("React.Children.only expected to receive a single React element child.");return K}},mt.Component=x,mt.Fragment=t,mt.Profiler=s,mt.PureComponent=C,mt.StrictMode=r,mt.Suspense=l,mt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Y,mt.act=re,mt.cloneElement=function(K,ne,ge){if(K==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+K+".");var Pe=y({},K.props),ce=K.key,Be=K.ref,Re=K._owner;if(ne!=null){if(ne.ref!==void 0&&(Be=ne.ref,Re=A.current),ne.key!==void 0&&(ce=""+ne.key),K.type&&K.type.defaultProps)var Ce=K.type.defaultProps;for(_e in ne)M.call(ne,_e)&&!O.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 We=0;We<_e;We++)Ce[We]=arguments[We+2];Pe.children=Ce}return{$$typeof:n,type:K.type,key:ce,ref:Be,props:Pe,_owner:Re}},mt.createContext=function(K){return K={$$typeof:o,_currentValue:K,_currentValue2:K,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},K.Provider={$$typeof:i,_context:K},K.Consumer=K},mt.createElement=D,mt.createFactory=function(K){var ne=D.bind(null,K);return ne.type=K,ne},mt.createRef=function(){return{current:null}},mt.forwardRef=function(K){return{$$typeof:a,render:K}},mt.isValidElement=U,mt.lazy=function(K){return{$$typeof:d,_payload:{_status:-1,_result:K},_init:Z}},mt.memo=function(K,ne){return{$$typeof:c,type:K,compare:ne===void 0?null:ne}},mt.startTransition=function(K){var ne=$.transition;$.transition={};try{K()}finally{$.transition=ne}},mt.unstable_act=re,mt.useCallback=function(K,ne){return W.current.useCallback(K,ne)},mt.useContext=function(K){return W.current.useContext(K)},mt.useDebugValue=function(){},mt.useDeferredValue=function(K){return W.current.useDeferredValue(K)},mt.useEffect=function(K,ne){return W.current.useEffect(K,ne)},mt.useId=function(){return W.current.useId()},mt.useImperativeHandle=function(K,ne,ge){return W.current.useImperativeHandle(K,ne,ge)},mt.useInsertionEffect=function(K,ne){return W.current.useInsertionEffect(K,ne)},mt.useLayoutEffect=function(K,ne){return W.current.useLayoutEffect(K,ne)},mt.useMemo=function(K,ne){return W.current.useMemo(K,ne)},mt.useReducer=function(K,ne,ge){return W.current.useReducer(K,ne,ge)},mt.useRef=function(K){return W.current.useRef(K)},mt.useState=function(K){return W.current.useState(K)},mt.useSyncExternalStore=function(K,ne,ge){return W.current.useSyncExternalStore(K,ne,ge)},mt.useTransition=function(){return W.current.useTransition()},mt.version="18.3.1",mt}var KM;function dI(){return KM||(KM=1,Cw.exports=XW()),Cw.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 WM;function ZW(){if(WM)return Qh;WM=1;var n=dI(),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={},g=null,m=null;c!==void 0&&(g=""+c),l.key!==void 0&&(g=""+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:g,ref:m,props:f,_owner:s.current}}return Qh.Fragment=t,Qh.jsx=o,Qh.jsxs=o,Qh}var VM;function JW(){return VM||(VM=1,bw.exports=ZW()),bw.exports}var p=JW(),P=dI();const ot=$a(P),QW=YW({__proto__:null,default:ot},[P]);var cm={},Pw={exports:{}},hs={},kw={exports:{}},Iw={};/**
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 qM;function eV(){return qM||(qM=1,function(n){function e($,Y){var re=$.length;$.push(Y);e:for(;0<re;){var K=re-1>>>1,ne=$[K];if(0<s(ne,Y))$[K]=Y,$[re]=ne,re=K;else break e}}function t($){return $.length===0?null:$[0]}function r($){if($.length===0)return null;var Y=$[0],re=$.pop();if(re!==Y){$[0]=re;e:for(var K=0,ne=$.length,ge=ne>>>1;K<ge;){var Pe=2*(K+1)-1,ce=$[Pe],Be=Pe+1,Re=$[Be];if(0>s(ce,re))Be<ne&&0>s(Re,ce)?($[K]=Re,$[Be]=re,K=Be):($[K]=ce,$[Pe]=re,K=Pe);else if(Be<ne&&0>s(Re,re))$[K]=Re,$[Be]=re,K=Be;else break e}}return Y}function s($,Y){var re=$.sortIndex-Y.sortIndex;return re!==0?re:$.id-Y.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,g=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 E($){for(var Y=t(c);Y!==null;){if(Y.callback===null)r(c);else if(Y.startTime<=$)r(c),Y.sortIndex=Y.expirationTime,e(l,Y);else break;Y=t(c)}}function _($){if(v=!1,E($),!y)if(t(l)!==null)y=!0,Z(M);else{var Y=t(c);Y!==null&&W(_,Y.startTime-$)}}function M($,Y){y=!1,v&&(v=!1,b(D),D=-1),m=!0;var re=g;try{for(E(Y),f=t(l);f!==null&&(!(f.expirationTime>Y)||$&&!G());){var K=f.callback;if(typeof K=="function"){f.callback=null,g=f.priorityLevel;var ne=K(f.expirationTime<=Y);Y=n.unstable_now(),typeof ne=="function"?f.callback=ne:f===t(l)&&r(l),E(Y)}else r(l);f=t(l)}if(f!==null)var ge=!0;else{var Pe=t(c);Pe!==null&&W(_,Pe.startTime-Y),ge=!1}return ge}finally{f=null,g=re,m=!1}}var A=!1,O=null,D=-1,B=5,U=-1;function G(){return!(n.unstable_now()-U<B)}function z(){if(O!==null){var $=n.unstable_now();U=$;var Y=!0;try{Y=O(!0,$)}finally{Y?N():(A=!1,O=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 Z($){O=$,A||(A=!0,N())}function W($,Y){D=x(function(){$(n.unstable_now())},Y)}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,Z(M))},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"):B=0<$?Math.floor(1e3/$):5},n.unstable_getCurrentPriorityLevel=function(){return g},n.unstable_getFirstCallbackNode=function(){return t(l)},n.unstable_next=function($){switch(g){case 1:case 2:case 3:var Y=3;break;default:Y=g}var re=g;g=Y;try{return $()}finally{g=re}},n.unstable_pauseExecution=function(){},n.unstable_requestPaint=function(){},n.unstable_runWithPriority=function($,Y){switch($){case 1:case 2:case 3:case 4:case 5:break;default:$=3}var re=g;g=$;try{return Y()}finally{g=re}},n.unstable_scheduleCallback=function($,Y,re){var K=n.unstable_now();switch(typeof re=="object"&&re!==null?(re=re.delay,re=typeof re=="number"&&0<re?K+re:K):re=K,$){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:Y,priorityLevel:$,startTime:re,expirationTime:ne,sortIndex:-1},re>K?($.sortIndex=re,e(c,$),t(l)===null&&$===t(c)&&(v?(b(D),D=-1):v=!0,W(_,re-K))):($.sortIndex=ne,e(l,$),y||m||(y=!0,Z(M))),$},n.unstable_shouldYield=G,n.unstable_wrapCallback=function($){var Y=g;return function(){var re=g;g=Y;try{return $.apply(this,arguments)}finally{g=re}}}}(Iw)),Iw}var GM;function tV(){return GM||(GM=1,kw.exports=eV()),kw.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 YM;function nV(){if(YM)return hs;YM=1;var n=dI(),e=tV();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 g(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,I,T,j){this.acceptsBooleans=h===2||h===3||h===4,this.attributeName=w,this.attributeNamespace=I,this.mustUseProperty=S,this.propertyName=u,this.type=h,this.sanitizeURL=T,this.removeEmptyString=j}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 E(u,h,S,w){var I=x.hasOwnProperty(h)?x[h]:null;(I!==null?I.type!==0:w||!(2<h.length)||h[0]!=="o"&&h[0]!=="O"||h[1]!=="n"&&h[1]!=="N")&&(y(h,S,I,w)&&(S=null),w||I===null?g(h)&&(S===null?u.removeAttribute(h):u.setAttribute(h,""+S)):I.mustUseProperty?u[I.propertyName]=S===null?I.type===3?!1:"":S:(h=I.attributeName,w=I.attributeNamespace,S===null?u.removeAttribute(h):(I=I.type,S=I===3||I===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,M=Symbol.for("react.element"),A=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),U=Symbol.for("react.provider"),G=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"),Z=Symbol.for("react.lazy"),W=Symbol.for("react.offscreen"),$=Symbol.iterator;function Y(u){return u===null||typeof u!="object"?null:(u=$&&u[$]||u["@@iterator"],typeof u=="function"?u:null)}var re=Object.assign,K;function ne(u){if(K===void 0)try{throw Error()}catch(S){var h=S.stack.trim().match(/\n( *(at )?)/);K=h&&h[1]||""}return`
34
+ `+K+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 I=oe.stack.split(`
35
+ `),T=w.stack.split(`
36
+ `),j=I.length-1,H=T.length-1;1<=j&&0<=H&&I[j]!==T[H];)H--;for(;1<=j&&0<=H;j--,H--)if(I[j]!==T[H]){if(j!==1||H!==1)do if(j--,H--,0>H||I[j]!==T[H]){var q=`
37
+ `+I[j].replace(" at new "," at ");return u.displayName&&q.includes("<anonymous>")&&(q=q.replace("<anonymous>",u.displayName)),q}while(1<=j&&0<=H);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 O:return"Fragment";case A:return"Portal";case B:return"Profiler";case D:return"StrictMode";case N:return"Suspense";case L:return"SuspenseList"}if(typeof u=="object")switch(u.$$typeof){case G: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 Z: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===D?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof 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 We(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 I=S.get,T=S.set;return Object.defineProperty(u,h,{configurable:!0,get:function(){return I.call(this)},set:function(j){w=""+j,T.call(this,j)}}),Object.defineProperty(u,h,{enumerable:S.enumerable}),{getValue:function(){return w},setValue:function(j){w=""+j},stopTracking:function(){u._valueTracker=null,delete u[h]}}}}function st(u){u._valueTracker||(u._valueTracker=We(u))}function hn(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 _t(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 Qt(u,h){var S=h.checked;return re({},h,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:S??u._wrapperState.initialChecked})}function Nt(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 At(u,h){h=h.checked,h!=null&&E(u,"checked",h,!1)}function Jr(u,h){At(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")?es(u,h.type,S):h.hasOwnProperty("defaultValue")&&es(u,h.type,Ce(h.defaultValue)),h.checked==null&&h.defaultChecked!=null&&(u.defaultChecked=!!h.defaultChecked)}function Qr(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 es(u,h,S){(h!=="number"||_t(u.ownerDocument)!==u)&&(S==null?u.defaultValue=""+u._wrapperState.initialValue:u.defaultValue!==""+S&&(u.defaultValue=""+S))}var ts=Array.isArray;function ti(u,h,S,w){if(u=u.options,h){h={};for(var I=0;I<S.length;I++)h["$"+S[I]]=!0;for(S=0;S<u.length;S++)I=h.hasOwnProperty("$"+u[S].value),u[S].selected!==I&&(u[S].selected=I),I&&w&&(u[S].defaultSelected=!0)}else{for(S=""+Ce(S),h=null,I=0;I<u.length;I++){if(u[I].value===S){u[I].selected=!0,w&&(u[I].defaultSelected=!0);return}h!==null||u[I].disabled||(h=u[I])}h!==null&&(h.selected=!0)}}function ac(u,h){if(h.dangerouslySetInnerHTML!=null)throw Error(t(91));return re({},h,{value:void 0,defaultValue:void 0,children:""+u._wrapperState.initialValue})}function bu(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(ts(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 Cu(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 Pu(u){var h=u.textContent;h===u._wrapperState.initialValue&&h!==""&&h!==null&&(u.value=h)}function ku(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 co(u,h){return u==null||u==="http://www.w3.org/1999/xhtml"?ku(h):u==="http://www.w3.org/2000/svg"&&h==="foreignObject"?"http://www.w3.org/1999/xhtml":u}var Mi,lc=function(u){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(h,S,w,I){MSApp.execUnsafeLocalFunction(function(){return u(h,S,w,I)})}:u}(function(u,h){if(u.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in u)u.innerHTML=h;else{for(Mi=Mi||document.createElement("div"),Mi.innerHTML="<svg>"+h.valueOf().toString()+"</svg>",h=Mi.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},Ye=["Webkit","ms","Moz","O"];Object.keys(be).forEach(function(u){Ye.forEach(function(h){h=h+u.charAt(0).toUpperCase()+u.substring(1),be[h]=be[u]})});function Ot(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 ni(u,h){u=u.style;for(var S in h)if(h.hasOwnProperty(S)){var w=S.indexOf("--")===0,I=Ot(S,h[S],w);S==="float"&&(S="cssFloat"),w?u.setProperty(S,I):u[S]=I}}var ns=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 Qo(u,h){if(h){if(ns[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 As(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 Os=null;function rs(u){return u=u.target||u.srcElement||window,u.correspondingUseElement&&(u=u.correspondingUseElement),u.nodeType===3?u.parentNode:u}var Rs=null,ss=null,Ai=null;function Iu(u){if(u=Fh(u)){if(typeof Rs!="function")throw Error(t(280));var h=u.stateNode;h&&(h=Pg(h),Rs(u.stateNode,u.type,h))}}function Ga(u){ss?Ai?Ai.push(u):Ai=[u]:ss=u}function Eu(){if(ss){var u=ss,h=Ai;if(Ai=ss=null,Iu(u),h)for(u=0;u<h.length;u++)Iu(h[u])}}function _u(u,h){return u(h)}function Tu(){}var ea=!1;function ig(u,h,S){if(ea)return u(h,S);ea=!0;try{return _u(u,h,S)}finally{ea=!1,(ss!==null||Ai!==null)&&(Tu(),Eu())}}function cc(u,h){var S=u.stateNode;if(S===null)return null;var w=Pg(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 vh=!1;if(a)try{var uc={};Object.defineProperty(uc,"passive",{get:function(){vh=!0}}),window.addEventListener("test",uc,uc),window.removeEventListener("test",uc,uc)}catch{vh=!1}function Lv(u,h,S,w,I,T,j,H,q){var oe=Array.prototype.slice.call(arguments,3);try{h.apply(S,oe)}catch(fe){this.onError(fe)}}var Ya=!1,Xa=null,ri=!1,xh=null,Fv={onError:function(u){Ya=!0,Xa=u}};function zv(u,h,S,w,I,T,j,H,q){Ya=!1,Xa=null,Lv.apply(Fv,arguments)}function $v(u,h,S,w,I,T,j,H,q){if(zv.apply(this,arguments),Ya){if(Ya){var oe=Xa;Ya=!1,Xa=null}else throw Error(t(198));ri||(ri=!0,xh=oe)}}function ta(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 si(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 og(u){if(ta(u)!==u)throw Error(t(188))}function Bv(u){var h=u.alternate;if(!h){if(h=ta(u),h===null)throw Error(t(188));return h!==u?null:u}for(var S=u,w=h;;){var I=S.return;if(I===null)break;var T=I.alternate;if(T===null){if(w=I.return,w!==null){S=w;continue}break}if(I.child===T.child){for(T=I.child;T;){if(T===S)return og(I),u;if(T===w)return og(I),h;T=T.sibling}throw Error(t(188))}if(S.return!==w.return)S=I,w=T;else{for(var j=!1,H=I.child;H;){if(H===S){j=!0,S=I,w=T;break}if(H===w){j=!0,w=I,S=T;break}H=H.sibling}if(!j){for(H=T.child;H;){if(H===S){j=!0,S=T,w=I;break}if(H===w){j=!0,w=T,S=I;break}H=H.sibling}if(!j)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 ag(u){return u=Bv(u),u!==null?lg(u):null}function lg(u){if(u.tag===5||u.tag===6)return u;for(u=u.child;u!==null;){var h=lg(u);if(h!==null)return h;u=u.sibling}return null}var cg=e.unstable_scheduleCallback,uo=e.unstable_cancelCallback,Uv=e.unstable_shouldYield,Hv=e.unstable_requestPaint,rn=e.unstable_now,Kv=e.unstable_getCurrentPriorityLevel,wh=e.unstable_ImmediatePriority,dc=e.unstable_UserBlockingPriority,Mu=e.unstable_NormalPriority,Wv=e.unstable_LowPriority,Oi=e.unstable_IdlePriority,Au=null,ii=null;function Vv(u){if(ii&&typeof ii.onCommitFiberRoot=="function")try{ii.onCommitFiberRoot(Au,u,void 0,(u.current.flags&128)===128)}catch{}}var Ds=Math.clz32?Math.clz32:Ou,qv=Math.log,Gv=Math.LN2;function Ou(u){return u>>>=0,u===0?32:31-(qv(u)/Gv|0)|0}var Ru=64,ho=4194304;function Za(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 hc(u,h){var S=u.pendingLanes;if(S===0)return 0;var w=0,I=u.suspendedLanes,T=u.pingedLanes,j=S&268435455;if(j!==0){var H=j&~I;H!==0?w=Za(H):(T&=j,T!==0&&(w=Za(T)))}else j=S&~I,j!==0?w=Za(j):T!==0&&(w=Za(T));if(w===0)return 0;if(h!==0&&h!==w&&(h&I)===0&&(I=w&-w,T=h&-h,I>=T||I===16&&(T&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-Ds(h),I=1<<S,w|=u[S],h&=~I;return w}function Yv(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 Xv(u,h){for(var S=u.suspendedLanes,w=u.pingedLanes,I=u.expirationTimes,T=u.pendingLanes;0<T;){var j=31-Ds(T),H=1<<j,q=I[j];q===-1?((H&S)===0||(H&w)!==0)&&(I[j]=Yv(H,h)):q<=h&&(u.expiredLanes|=H),T&=~H}}function bh(u){return u=u.pendingLanes&-1073741825,u!==0?u:u&1073741824?1073741824:0}function ug(){var u=Ru;return Ru<<=1,(Ru&4194240)===0&&(Ru=64),u}function Du(u){for(var h=[],S=0;31>S;S++)h.push(u);return h}function fc(u,h,S){u.pendingLanes|=h,h!==536870912&&(u.suspendedLanes=0,u.pingedLanes=0),u=u.eventTimes,h=31-Ds(h),u[h]=S}function Zv(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 I=31-Ds(S),T=1<<I;h[I]=0,w[I]=-1,u[I]=-1,S&=~T}}function ju(u,h){var S=u.entangledLanes|=h;for(u=u.entanglements;S;){var w=31-Ds(S),I=1<<w;I&h|u[w]&h&&(u[w]|=h),S&=~I}}var xt=0;function na(u){return u&=-u,1<u?4<u?(u&268435455)!==0?16:536870912:4:1}var dg,Ch,Ri,hg,fg,Ph=!1,Nu=[],fo=null,hr=null,Di=null,pc=new Map,po=new Map,go=[],kh="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 pg(u,h){switch(u){case"focusin":case"focusout":fo=null;break;case"dragenter":case"dragleave":hr=null;break;case"mouseover":case"mouseout":Di=null;break;case"pointerover":case"pointerout":pc.delete(h.pointerId);break;case"gotpointercapture":case"lostpointercapture":po.delete(h.pointerId)}}function Ja(u,h,S,w,I,T){return u===null||u.nativeEvent!==T?(u={blockedOn:h,domEventName:S,eventSystemFlags:w,nativeEvent:T,targetContainers:[I]},h!==null&&(h=Fh(h),h!==null&&Ch(h)),u):(u.eventSystemFlags|=w,h=u.targetContainers,I!==null&&h.indexOf(I)===-1&&h.push(I),u)}function gg(u,h,S,w,I){switch(h){case"focusin":return fo=Ja(fo,u,h,S,w,I),!0;case"dragenter":return hr=Ja(hr,u,h,S,w,I),!0;case"mouseover":return Di=Ja(Di,u,h,S,w,I),!0;case"pointerover":var T=I.pointerId;return pc.set(T,Ja(pc.get(T)||null,u,h,S,w,I)),!0;case"gotpointercapture":return T=I.pointerId,po.set(T,Ja(po.get(T)||null,u,h,S,w,I)),!0}return!1}function Ih(u){var h=yc(u.target);if(h!==null){var S=ta(h);if(S!==null){if(h=S.tag,h===13){if(h=si(S),h!==null){u.blockedOn=h,fg(u.priority,function(){Ri(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 mo(u){if(u.blockedOn!==null)return!1;for(var h=u.targetContainers;0<h.length;){var S=$t(u.domEventName,u.eventSystemFlags,h[0],u.nativeEvent);if(S===null){S=u.nativeEvent;var w=new S.constructor(S.type,S);Os=w,S.target.dispatchEvent(w),Os=null}else return h=Fh(S),h!==null&&Ch(h),u.blockedOn=S,!1;h.shift()}return!0}function Eh(u,h,S){mo(u)&&S.delete(h)}function Jv(){Ph=!1,fo!==null&&mo(fo)&&(fo=null),hr!==null&&mo(hr)&&(hr=null),Di!==null&&mo(Di)&&(Di=null),pc.forEach(Eh),po.forEach(Eh)}function gc(u,h){u.blockedOn===h&&(u.blockedOn=null,Ph||(Ph=!0,e.unstable_scheduleCallback(e.unstable_NormalPriority,Jv)))}function mc(u){function h(I){return gc(I,u)}if(0<Nu.length){gc(Nu[0],u);for(var S=1;S<Nu.length;S++){var w=Nu[S];w.blockedOn===u&&(w.blockedOn=null)}}for(fo!==null&&gc(fo,u),hr!==null&&gc(hr,u),Di!==null&&gc(Di,u),pc.forEach(h),po.forEach(h),S=0;S<go.length;S++)w=go[S],w.blockedOn===u&&(w.blockedOn=null);for(;0<go.length&&(S=go[0],S.blockedOn===null);)Ih(S),S.blockedOn===null&&go.shift()}var F=_.ReactCurrentBatchConfig,J=!0;function de(u,h,S,w){var I=xt,T=F.transition;F.transition=null;try{xt=1,Mt(u,h,S,w)}finally{xt=I,F.transition=T}}function Ae(u,h,S,w){var I=xt,T=F.transition;F.transition=null;try{xt=4,Mt(u,h,S,w)}finally{xt=I,F.transition=T}}function Mt(u,h,S,w){if(J){var I=$t(u,h,S,w);if(I===null)hx(u,h,w,Qe,S),pg(u,w);else if(gg(I,u,h,S,w))w.stopPropagation();else if(pg(u,w),h&4&&-1<kh.indexOf(u)){for(;I!==null;){var T=Fh(I);if(T!==null&&dg(T),T=$t(u,h,S,w),T===null&&hx(u,h,w,Qe,S),T===I)break;I=T}I!==null&&w.stopPropagation()}else hx(u,h,w,null,S)}}var Qe=null;function $t(u,h,S,w){if(Qe=null,u=rs(w),u=yc(u),u!==null)if(h=ta(u),h===null)u=null;else if(S=h.tag,S===13){if(u=si(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 Qe=u,null}function Sn(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(Kv()){case wh:return 1;case dc:return 4;case Mu:case Wv:return 16;case Oi:return 536870912;default:return 16}default:return 16}}var Bt=null,Lt=null,Nn=null;function is(){if(Nn)return Nn;var u,h=Lt,S=h.length,w,I="value"in Bt?Bt.value:Bt.textContent,T=I.length;for(u=0;u<S&&h[u]===I[u];u++);var j=S-u;for(w=1;w<=j&&h[S-w]===I[T-w];w++);return Nn=I.slice(u,1<w?1-w:void 0)}function vn(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 Yn(){return!0}function Dr(){return!1}function fn(u){function h(S,w,I,T,j){this._reactName=S,this._targetInst=I,this.type=w,this.nativeEvent=T,this.target=j,this.currentTarget=null;for(var H in u)u.hasOwnProperty(H)&&(S=u[H],this[H]=S?S(T):T[H]);return this.isDefaultPrevented=(T.defaultPrevented!=null?T.defaultPrevented:T.returnValue===!1)?Yn:Dr,this.isPropagationStopped=Dr,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=Yn)},stopPropagation:function(){var S=this.nativeEvent;S&&(S.stopPropagation?S.stopPropagation():typeof S.cancelBubble!="unknown"&&(S.cancelBubble=!0),this.isPropagationStopped=Yn)},persist:function(){},isPersistent:Yn}),h}var fr={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(u){return u.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},ji=fn(fr),Qa=re({},fr,{view:0,detail:0}),Lu=fn(Qa),el,Qv,_h,mg=re({},Qa,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:tx,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!==_h&&(_h&&u.type==="mousemove"?(el=u.screenX-_h.screenX,Qv=u.screenY-_h.screenY):Qv=el=0,_h=u),el)},movementY:function(u){return"movementY"in u?u.movementY:Qv}}),OT=fn(mg),wK=re({},mg,{dataTransfer:0}),bK=fn(wK),CK=re({},Qa,{relatedTarget:0}),ex=fn(CK),PK=re({},fr,{animationName:0,elapsedTime:0,pseudoElement:0}),kK=fn(PK),IK=re({},fr,{clipboardData:function(u){return"clipboardData"in u?u.clipboardData:window.clipboardData}}),EK=fn(IK),_K=re({},fr,{data:0}),RT=fn(_K),TK={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},MK={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"},AK={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function OK(u){var h=this.nativeEvent;return h.getModifierState?h.getModifierState(u):(u=AK[u])?!!h[u]:!1}function tx(){return OK}var RK=re({},Qa,{key:function(u){if(u.key){var h=TK[u.key]||u.key;if(h!=="Unidentified")return h}return u.type==="keypress"?(u=vn(u),u===13?"Enter":String.fromCharCode(u)):u.type==="keydown"||u.type==="keyup"?MK[u.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:tx,charCode:function(u){return u.type==="keypress"?vn(u):0},keyCode:function(u){return u.type==="keydown"||u.type==="keyup"?u.keyCode:0},which:function(u){return u.type==="keypress"?vn(u):u.type==="keydown"||u.type==="keyup"?u.keyCode:0}}),DK=fn(RK),jK=re({},mg,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),DT=fn(jK),NK=re({},Qa,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:tx}),LK=fn(NK),FK=re({},fr,{propertyName:0,elapsedTime:0,pseudoElement:0}),zK=fn(FK),$K=re({},mg,{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}),BK=fn($K),UK=[9,13,27,32],nx=a&&"CompositionEvent"in window,Th=null;a&&"documentMode"in document&&(Th=document.documentMode);var HK=a&&"TextEvent"in window&&!Th,jT=a&&(!nx||Th&&8<Th&&11>=Th),NT=" ",LT=!1;function FT(u,h){switch(u){case"keyup":return UK.indexOf(h.keyCode)!==-1;case"keydown":return h.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function zT(u){return u=u.detail,typeof u=="object"&&"data"in u?u.data:null}var Fu=!1;function KK(u,h){switch(u){case"compositionend":return zT(h);case"keypress":return h.which!==32?null:(LT=!0,NT);case"textInput":return u=h.data,u===NT&&LT?null:u;default:return null}}function WK(u,h){if(Fu)return u==="compositionend"||!nx&&FT(u,h)?(u=is(),Nn=Lt=Bt=null,Fu=!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 jT&&h.locale!=="ko"?null:h.data;default:return null}}var VK={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 $T(u){var h=u&&u.nodeName&&u.nodeName.toLowerCase();return h==="input"?!!VK[u.type]:h==="textarea"}function BT(u,h,S,w){Ga(w),h=wg(h,"onChange"),0<h.length&&(S=new ji("onChange","change",null,S,w),u.push({event:S,listeners:h}))}var Mh=null,Ah=null;function qK(u){i2(u,0)}function yg(u){var h=Hu(u);if(hn(h))return u}function GK(u,h){if(u==="change")return h}var UT=!1;if(a){var rx;if(a){var sx="oninput"in document;if(!sx){var HT=document.createElement("div");HT.setAttribute("oninput","return;"),sx=typeof HT.oninput=="function"}rx=sx}else rx=!1;UT=rx&&(!document.documentMode||9<document.documentMode)}function KT(){Mh&&(Mh.detachEvent("onpropertychange",WT),Ah=Mh=null)}function WT(u){if(u.propertyName==="value"&&yg(Ah)){var h=[];BT(h,Ah,u,rs(u)),ig(qK,h)}}function YK(u,h,S){u==="focusin"?(KT(),Mh=h,Ah=S,Mh.attachEvent("onpropertychange",WT)):u==="focusout"&&KT()}function XK(u){if(u==="selectionchange"||u==="keyup"||u==="keydown")return yg(Ah)}function ZK(u,h){if(u==="click")return yg(h)}function JK(u,h){if(u==="input"||u==="change")return yg(h)}function QK(u,h){return u===h&&(u!==0||1/u===1/h)||u!==u&&h!==h}var Ni=typeof Object.is=="function"?Object.is:QK;function Oh(u,h){if(Ni(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 I=S[w];if(!l.call(h,I)||!Ni(u[I],h[I]))return!1}return!0}function VT(u){for(;u&&u.firstChild;)u=u.firstChild;return u}function qT(u,h){var S=VT(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=VT(S)}}function GT(u,h){return u&&h?u===h?!0:u&&u.nodeType===3?!1:h&&h.nodeType===3?GT(u,h.parentNode):"contains"in u?u.contains(h):u.compareDocumentPosition?!!(u.compareDocumentPosition(h)&16):!1:!1}function YT(){for(var u=window,h=_t();h instanceof u.HTMLIFrameElement;){try{var S=typeof h.contentWindow.location.href=="string"}catch{S=!1}if(S)u=h.contentWindow;else break;h=_t(u.document)}return h}function ix(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 eW(u){var h=YT(),S=u.focusedElem,w=u.selectionRange;if(h!==S&&S&&S.ownerDocument&&GT(S.ownerDocument.documentElement,S)){if(w!==null&&ix(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 I=S.textContent.length,T=Math.min(w.start,I);w=w.end===void 0?T:Math.min(w.end,I),!u.extend&&T>w&&(I=w,w=T,T=I),I=qT(S,T);var j=qT(S,w);I&&j&&(u.rangeCount!==1||u.anchorNode!==I.node||u.anchorOffset!==I.offset||u.focusNode!==j.node||u.focusOffset!==j.offset)&&(h=h.createRange(),h.setStart(I.node,I.offset),u.removeAllRanges(),T>w?(u.addRange(h),u.extend(j.node,j.offset)):(h.setEnd(j.node,j.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 tW=a&&"documentMode"in document&&11>=document.documentMode,zu=null,ox=null,Rh=null,ax=!1;function XT(u,h,S){var w=S.window===S?S.document:S.nodeType===9?S:S.ownerDocument;ax||zu==null||zu!==_t(w)||(w=zu,"selectionStart"in w&&ix(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}),Rh&&Oh(Rh,w)||(Rh=w,w=wg(ox,"onSelect"),0<w.length&&(h=new ji("onSelect","select",null,h,S),u.push({event:h,listeners:w}),h.target=zu)))}function Sg(u,h){var S={};return S[u.toLowerCase()]=h.toLowerCase(),S["Webkit"+u]="webkit"+h,S["Moz"+u]="moz"+h,S}var $u={animationend:Sg("Animation","AnimationEnd"),animationiteration:Sg("Animation","AnimationIteration"),animationstart:Sg("Animation","AnimationStart"),transitionend:Sg("Transition","TransitionEnd")},lx={},ZT={};a&&(ZT=document.createElement("div").style,"AnimationEvent"in window||(delete $u.animationend.animation,delete $u.animationiteration.animation,delete $u.animationstart.animation),"TransitionEvent"in window||delete $u.transitionend.transition);function vg(u){if(lx[u])return lx[u];if(!$u[u])return u;var h=$u[u],S;for(S in h)if(h.hasOwnProperty(S)&&S in ZT)return lx[u]=h[S];return u}var JT=vg("animationend"),QT=vg("animationiteration"),e2=vg("animationstart"),t2=vg("transitionend"),n2=new Map,r2="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 tl(u,h){n2.set(u,h),i(h,[u])}for(var cx=0;cx<r2.length;cx++){var ux=r2[cx],nW=ux.toLowerCase(),rW=ux[0].toUpperCase()+ux.slice(1);tl(nW,"on"+rW)}tl(JT,"onAnimationEnd"),tl(QT,"onAnimationIteration"),tl(e2,"onAnimationStart"),tl("dblclick","onDoubleClick"),tl("focusin","onFocus"),tl("focusout","onBlur"),tl(t2,"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 Dh="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(" "),sW=new Set("cancel close invalid load scroll toggle".split(" ").concat(Dh));function s2(u,h,S){var w=u.type||"unknown-event";u.currentTarget=S,$v(w,h,void 0,u),u.currentTarget=null}function i2(u,h){h=(h&4)!==0;for(var S=0;S<u.length;S++){var w=u[S],I=w.event;w=w.listeners;e:{var T=void 0;if(h)for(var j=w.length-1;0<=j;j--){var H=w[j],q=H.instance,oe=H.currentTarget;if(H=H.listener,q!==T&&I.isPropagationStopped())break e;s2(I,H,oe),T=q}else for(j=0;j<w.length;j++){if(H=w[j],q=H.instance,oe=H.currentTarget,H=H.listener,q!==T&&I.isPropagationStopped())break e;s2(I,H,oe),T=q}}}if(ri)throw u=xh,ri=!1,xh=null,u}function Vt(u,h){var S=h[Sx];S===void 0&&(S=h[Sx]=new Set);var w=u+"__bubble";S.has(w)||(o2(h,u,2,!1),S.add(w))}function dx(u,h,S){var w=0;h&&(w|=4),o2(S,u,w,h)}var xg="_reactListening"+Math.random().toString(36).slice(2);function jh(u){if(!u[xg]){u[xg]=!0,r.forEach(function(S){S!=="selectionchange"&&(sW.has(S)||dx(S,!1,u),dx(S,!0,u))});var h=u.nodeType===9?u:u.ownerDocument;h===null||h[xg]||(h[xg]=!0,dx("selectionchange",!1,h))}}function o2(u,h,S,w){switch(Sn(h)){case 1:var I=de;break;case 4:I=Ae;break;default:I=Mt}S=I.bind(null,h,S,u),I=void 0,!vh||h!=="touchstart"&&h!=="touchmove"&&h!=="wheel"||(I=!0),w?I!==void 0?u.addEventListener(h,S,{capture:!0,passive:I}):u.addEventListener(h,S,!0):I!==void 0?u.addEventListener(h,S,{passive:I}):u.addEventListener(h,S,!1)}function hx(u,h,S,w,I){var T=w;if((h&1)===0&&(h&2)===0&&w!==null)e:for(;;){if(w===null)return;var j=w.tag;if(j===3||j===4){var H=w.stateNode.containerInfo;if(H===I||H.nodeType===8&&H.parentNode===I)break;if(j===4)for(j=w.return;j!==null;){var q=j.tag;if((q===3||q===4)&&(q=j.stateNode.containerInfo,q===I||q.nodeType===8&&q.parentNode===I))return;j=j.return}for(;H!==null;){if(j=yc(H),j===null)return;if(q=j.tag,q===5||q===6){w=T=j;continue e}H=H.parentNode}}w=w.return}ig(function(){var oe=T,fe=rs(S),me=[];e:{var he=n2.get(u);if(he!==void 0){var Me=ji,je=u;switch(u){case"keypress":if(vn(S)===0)break e;case"keydown":case"keyup":Me=DK;break;case"focusin":je="focus",Me=ex;break;case"focusout":je="blur",Me=ex;break;case"beforeblur":case"afterblur":Me=ex;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=OT;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Me=bK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Me=LK;break;case JT:case QT:case e2:Me=kK;break;case t2:Me=zK;break;case"scroll":Me=Lu;break;case"wheel":Me=BK;break;case"copy":case"cut":case"paste":Me=EK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Me=DT}var Fe=(h&4)!==0,xn=!Fe&&u==="scroll",ee=Fe?he!==null?he+"Capture":null:he;Fe=[];for(var X=oe,se;X!==null;){se=X;var xe=se.stateNode;if(se.tag===5&&xe!==null&&(se=xe,ee!==null&&(xe=cc(X,ee),xe!=null&&Fe.push(Nh(X,xe,se)))),xn)break;X=X.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!==Os&&(je=S.relatedTarget||S.fromElement)&&(yc(je)||je[ra]))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?yc(je):null,je!==null&&(xn=ta(je),je!==xn||je.tag!==5&&je.tag!==6)&&(je=null)):(Me=null,je=oe),Me!==je)){if(Fe=OT,xe="onMouseLeave",ee="onMouseEnter",X="mouse",(u==="pointerout"||u==="pointerover")&&(Fe=DT,xe="onPointerLeave",ee="onPointerEnter",X="pointer"),xn=Me==null?he:Hu(Me),se=je==null?he:Hu(je),he=new Fe(xe,X+"leave",Me,S,fe),he.target=xn,he.relatedTarget=se,xe=null,yc(fe)===oe&&(Fe=new Fe(ee,X+"enter",je,S,fe),Fe.target=se,Fe.relatedTarget=xn,xe=Fe),xn=xe,Me&&je)t:{for(Fe=Me,ee=je,X=0,se=Fe;se;se=Bu(se))X++;for(se=0,xe=ee;xe;xe=Bu(xe))se++;for(;0<X-se;)Fe=Bu(Fe),X--;for(;0<se-X;)ee=Bu(ee),se--;for(;X--;){if(Fe===ee||ee!==null&&Fe===ee.alternate)break t;Fe=Bu(Fe),ee=Bu(ee)}Fe=null}else Fe=null;Me!==null&&a2(me,he,Me,Fe,!1),je!==null&&xn!==null&&a2(me,xn,je,Fe,!0)}}e:{if(he=oe?Hu(oe):window,Me=he.nodeName&&he.nodeName.toLowerCase(),Me==="select"||Me==="input"&&he.type==="file")var $e=GK;else if($T(he))if(UT)$e=JK;else{$e=XK;var Ve=YK}else(Me=he.nodeName)&&Me.toLowerCase()==="input"&&(he.type==="checkbox"||he.type==="radio")&&($e=ZK);if($e&&($e=$e(u,oe))){BT(me,$e,S,fe);break e}Ve&&Ve(u,he,oe),u==="focusout"&&(Ve=he._wrapperState)&&Ve.controlled&&he.type==="number"&&es(he,"number",he.value)}switch(Ve=oe?Hu(oe):window,u){case"focusin":($T(Ve)||Ve.contentEditable==="true")&&(zu=Ve,ox=oe,Rh=null);break;case"focusout":Rh=ox=zu=null;break;case"mousedown":ax=!0;break;case"contextmenu":case"mouseup":case"dragend":ax=!1,XT(me,S,fe);break;case"selectionchange":if(tW)break;case"keydown":case"keyup":XT(me,S,fe)}var qe;if(nx)e:{switch(u){case"compositionstart":var Je="onCompositionStart";break e;case"compositionend":Je="onCompositionEnd";break e;case"compositionupdate":Je="onCompositionUpdate";break e}Je=void 0}else Fu?FT(u,S)&&(Je="onCompositionEnd"):u==="keydown"&&S.keyCode===229&&(Je="onCompositionStart");Je&&(jT&&S.locale!=="ko"&&(Fu||Je!=="onCompositionStart"?Je==="onCompositionEnd"&&Fu&&(qe=is()):(Bt=fe,Lt="value"in Bt?Bt.value:Bt.textContent,Fu=!0)),Ve=wg(oe,Je),0<Ve.length&&(Je=new RT(Je,u,null,S,fe),me.push({event:Je,listeners:Ve}),qe?Je.data=qe:(qe=zT(S),qe!==null&&(Je.data=qe)))),(qe=HK?KK(u,S):WK(u,S))&&(oe=wg(oe,"onBeforeInput"),0<oe.length&&(fe=new RT("onBeforeInput","beforeinput",null,S,fe),me.push({event:fe,listeners:oe}),fe.data=qe))}i2(me,h)})}function Nh(u,h,S){return{instance:u,listener:h,currentTarget:S}}function wg(u,h){for(var S=h+"Capture",w=[];u!==null;){var I=u,T=I.stateNode;I.tag===5&&T!==null&&(I=T,T=cc(u,S),T!=null&&w.unshift(Nh(u,T,I)),T=cc(u,h),T!=null&&w.push(Nh(u,T,I))),u=u.return}return w}function Bu(u){if(u===null)return null;do u=u.return;while(u&&u.tag!==5);return u||null}function a2(u,h,S,w,I){for(var T=h._reactName,j=[];S!==null&&S!==w;){var H=S,q=H.alternate,oe=H.stateNode;if(q!==null&&q===w)break;H.tag===5&&oe!==null&&(H=oe,I?(q=cc(S,T),q!=null&&j.unshift(Nh(S,q,H))):I||(q=cc(S,T),q!=null&&j.push(Nh(S,q,H)))),S=S.return}j.length!==0&&u.push({event:h,listeners:j})}var iW=/\r\n?/g,oW=/\u0000|\uFFFD/g;function l2(u){return(typeof u=="string"?u:""+u).replace(iW,`
38
+ `).replace(oW,"")}function bg(u,h,S){if(h=l2(h),l2(u)!==h&&S)throw Error(t(425))}function Cg(){}var fx=null,px=null;function gx(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 mx=typeof setTimeout=="function"?setTimeout:void 0,aW=typeof clearTimeout=="function"?clearTimeout:void 0,c2=typeof Promise=="function"?Promise:void 0,lW=typeof queueMicrotask=="function"?queueMicrotask:typeof c2<"u"?function(u){return c2.resolve(null).then(u).catch(cW)}:mx;function cW(u){setTimeout(function(){throw u})}function yx(u,h){var S=h,w=0;do{var I=S.nextSibling;if(u.removeChild(S),I&&I.nodeType===8)if(S=I.data,S==="/$"){if(w===0){u.removeChild(I),mc(h);return}w--}else S!=="$"&&S!=="$?"&&S!=="$!"||w++;S=I}while(S);mc(h)}function nl(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 u2(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 Uu=Math.random().toString(36).slice(2),yo="__reactFiber$"+Uu,Lh="__reactProps$"+Uu,ra="__reactContainer$"+Uu,Sx="__reactEvents$"+Uu,uW="__reactListeners$"+Uu,dW="__reactHandles$"+Uu;function yc(u){var h=u[yo];if(h)return h;for(var S=u.parentNode;S;){if(h=S[ra]||S[yo]){if(S=h.alternate,h.child!==null||S!==null&&S.child!==null)for(u=u2(u);u!==null;){if(S=u[yo])return S;u=u2(u)}return h}u=S,S=u.parentNode}return null}function Fh(u){return u=u[yo]||u[ra],!u||u.tag!==5&&u.tag!==6&&u.tag!==13&&u.tag!==3?null:u}function Hu(u){if(u.tag===5||u.tag===6)return u.stateNode;throw Error(t(33))}function Pg(u){return u[Lh]||null}var vx=[],Ku=-1;function rl(u){return{current:u}}function qt(u){0>Ku||(u.current=vx[Ku],vx[Ku]=null,Ku--)}function Ut(u,h){Ku++,vx[Ku]=u.current,u.current=h}var sl={},pr=rl(sl),as=rl(!1),Sc=sl;function Wu(u,h){var S=u.type.contextTypes;if(!S)return sl;var w=u.stateNode;if(w&&w.__reactInternalMemoizedUnmaskedChildContext===h)return w.__reactInternalMemoizedMaskedChildContext;var I={},T;for(T in S)I[T]=h[T];return w&&(u=u.stateNode,u.__reactInternalMemoizedUnmaskedChildContext=h,u.__reactInternalMemoizedMaskedChildContext=I),I}function ls(u){return u=u.childContextTypes,u!=null}function kg(){qt(as),qt(pr)}function d2(u,h,S){if(pr.current!==sl)throw Error(t(168));Ut(pr,h),Ut(as,S)}function h2(u,h,S){var w=u.stateNode;if(h=h.childContextTypes,typeof w.getChildContext!="function")return S;w=w.getChildContext();for(var I in w)if(!(I in h))throw Error(t(108,Re(u)||"Unknown",I));return re({},S,w)}function Ig(u){return u=(u=u.stateNode)&&u.__reactInternalMemoizedMergedChildContext||sl,Sc=pr.current,Ut(pr,u),Ut(as,as.current),!0}function f2(u,h,S){var w=u.stateNode;if(!w)throw Error(t(169));S?(u=h2(u,h,Sc),w.__reactInternalMemoizedMergedChildContext=u,qt(as),qt(pr),Ut(pr,u)):qt(as),Ut(as,S)}var sa=null,Eg=!1,xx=!1;function p2(u){sa===null?sa=[u]:sa.push(u)}function hW(u){Eg=!0,p2(u)}function il(){if(!xx&&sa!==null){xx=!0;var u=0,h=xt;try{var S=sa;for(xt=1;u<S.length;u++){var w=S[u];do w=w(!0);while(w!==null)}sa=null,Eg=!1}catch(I){throw sa!==null&&(sa=sa.slice(u+1)),cg(wh,il),I}finally{xt=h,xx=!1}}return null}var Vu=[],qu=0,_g=null,Tg=0,oi=[],ai=0,vc=null,ia=1,oa="";function xc(u,h){Vu[qu++]=Tg,Vu[qu++]=_g,_g=u,Tg=h}function g2(u,h,S){oi[ai++]=ia,oi[ai++]=oa,oi[ai++]=vc,vc=u;var w=ia;u=oa;var I=32-Ds(w)-1;w&=~(1<<I),S+=1;var T=32-Ds(h)+I;if(30<T){var j=I-I%5;T=(w&(1<<j)-1).toString(32),w>>=j,I-=j,ia=1<<32-Ds(h)+I|S<<I|w,oa=T+u}else ia=1<<T|S<<I|w,oa=u}function wx(u){u.return!==null&&(xc(u,1),g2(u,1,0))}function bx(u){for(;u===_g;)_g=Vu[--qu],Vu[qu]=null,Tg=Vu[--qu],Vu[qu]=null;for(;u===vc;)vc=oi[--ai],oi[ai]=null,oa=oi[--ai],oi[ai]=null,ia=oi[--ai],oi[ai]=null}var js=null,Ns=null,en=!1,Li=null;function m2(u,h){var S=di(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 y2(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,js=u,Ns=nl(h.firstChild),!0):!1;case 6:return h=u.pendingProps===""||h.nodeType!==3?null:h,h!==null?(u.stateNode=h,js=u,Ns=null,!0):!1;case 13:return h=h.nodeType!==8?null:h,h!==null?(S=vc!==null?{id:ia,overflow:oa}:null,u.memoizedState={dehydrated:h,treeContext:S,retryLane:1073741824},S=di(18,null,null,0),S.stateNode=h,S.return=u,u.child=S,js=u,Ns=null,!0):!1;default:return!1}}function Cx(u){return(u.mode&1)!==0&&(u.flags&128)===0}function Px(u){if(en){var h=Ns;if(h){var S=h;if(!y2(u,h)){if(Cx(u))throw Error(t(418));h=nl(S.nextSibling);var w=js;h&&y2(u,h)?m2(w,S):(u.flags=u.flags&-4097|2,en=!1,js=u)}}else{if(Cx(u))throw Error(t(418));u.flags=u.flags&-4097|2,en=!1,js=u}}}function S2(u){for(u=u.return;u!==null&&u.tag!==5&&u.tag!==3&&u.tag!==13;)u=u.return;js=u}function Mg(u){if(u!==js)return!1;if(!en)return S2(u),en=!0,!1;var h;if((h=u.tag!==3)&&!(h=u.tag!==5)&&(h=u.type,h=h!=="head"&&h!=="body"&&!gx(u.type,u.memoizedProps)),h&&(h=Ns)){if(Cx(u))throw v2(),Error(t(418));for(;h;)m2(u,h),h=nl(h.nextSibling)}if(S2(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){Ns=nl(u.nextSibling);break e}h--}else S!=="$"&&S!=="$!"&&S!=="$?"||h++}u=u.nextSibling}Ns=null}}else Ns=js?nl(u.stateNode.nextSibling):null;return!0}function v2(){for(var u=Ns;u;)u=nl(u.nextSibling)}function Gu(){Ns=js=null,en=!1}function kx(u){Li===null?Li=[u]:Li.push(u)}var fW=_.ReactCurrentBatchConfig;function zh(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 I=w,T=""+u;return h!==null&&h.ref!==null&&typeof h.ref=="function"&&h.ref._stringRef===T?h.ref:(h=function(j){var H=I.refs;j===null?delete H[T]:H[T]=j},h._stringRef=T,h)}if(typeof u!="string")throw Error(t(284));if(!S._owner)throw Error(t(290,u))}return u}function Ag(u,h){throw u=Object.prototype.toString.call(h),Error(t(31,u==="[object Object]"?"object with keys {"+Object.keys(h).join(", ")+"}":u))}function x2(u){var h=u._init;return h(u._payload)}function w2(u){function h(ee,X){if(u){var se=ee.deletions;se===null?(ee.deletions=[X],ee.flags|=16):se.push(X)}}function S(ee,X){if(!u)return null;for(;X!==null;)h(ee,X),X=X.sibling;return null}function w(ee,X){for(ee=new Map;X!==null;)X.key!==null?ee.set(X.key,X):ee.set(X.index,X),X=X.sibling;return ee}function I(ee,X){return ee=fl(ee,X),ee.index=0,ee.sibling=null,ee}function T(ee,X,se){return ee.index=se,u?(se=ee.alternate,se!==null?(se=se.index,se<X?(ee.flags|=2,X):se):(ee.flags|=2,X)):(ee.flags|=1048576,X)}function j(ee){return u&&ee.alternate===null&&(ee.flags|=2),ee}function H(ee,X,se,xe){return X===null||X.tag!==6?(X=mw(se,ee.mode,xe),X.return=ee,X):(X=I(X,se),X.return=ee,X)}function q(ee,X,se,xe){var $e=se.type;return $e===O?fe(ee,X,se.props.children,xe,se.key):X!==null&&(X.elementType===$e||typeof $e=="object"&&$e!==null&&$e.$$typeof===Z&&x2($e)===X.type)?(xe=I(X,se.props),xe.ref=zh(ee,X,se),xe.return=ee,xe):(xe=tm(se.type,se.key,se.props,null,ee.mode,xe),xe.ref=zh(ee,X,se),xe.return=ee,xe)}function oe(ee,X,se,xe){return X===null||X.tag!==4||X.stateNode.containerInfo!==se.containerInfo||X.stateNode.implementation!==se.implementation?(X=yw(se,ee.mode,xe),X.return=ee,X):(X=I(X,se.children||[]),X.return=ee,X)}function fe(ee,X,se,xe,$e){return X===null||X.tag!==7?(X=_c(se,ee.mode,xe,$e),X.return=ee,X):(X=I(X,se),X.return=ee,X)}function me(ee,X,se){if(typeof X=="string"&&X!==""||typeof X=="number")return X=mw(""+X,ee.mode,se),X.return=ee,X;if(typeof X=="object"&&X!==null){switch(X.$$typeof){case M:return se=tm(X.type,X.key,X.props,null,ee.mode,se),se.ref=zh(ee,null,X),se.return=ee,se;case A:return X=yw(X,ee.mode,se),X.return=ee,X;case Z:var xe=X._init;return me(ee,xe(X._payload),se)}if(ts(X)||Y(X))return X=_c(X,ee.mode,se,null),X.return=ee,X;Ag(ee,X)}return null}function he(ee,X,se,xe){var $e=X!==null?X.key:null;if(typeof se=="string"&&se!==""||typeof se=="number")return $e!==null?null:H(ee,X,""+se,xe);if(typeof se=="object"&&se!==null){switch(se.$$typeof){case M:return se.key===$e?q(ee,X,se,xe):null;case A:return se.key===$e?oe(ee,X,se,xe):null;case Z:return $e=se._init,he(ee,X,$e(se._payload),xe)}if(ts(se)||Y(se))return $e!==null?null:fe(ee,X,se,xe,null);Ag(ee,se)}return null}function Me(ee,X,se,xe,$e){if(typeof xe=="string"&&xe!==""||typeof xe=="number")return ee=ee.get(se)||null,H(X,ee,""+xe,$e);if(typeof xe=="object"&&xe!==null){switch(xe.$$typeof){case M:return ee=ee.get(xe.key===null?se:xe.key)||null,q(X,ee,xe,$e);case A:return ee=ee.get(xe.key===null?se:xe.key)||null,oe(X,ee,xe,$e);case Z:var Ve=xe._init;return Me(ee,X,se,Ve(xe._payload),$e)}if(ts(xe)||Y(xe))return ee=ee.get(se)||null,fe(X,ee,xe,$e,null);Ag(X,xe)}return null}function je(ee,X,se,xe){for(var $e=null,Ve=null,qe=X,Je=X=0,zn=null;qe!==null&&Je<se.length;Je++){qe.index>Je?(zn=qe,qe=null):zn=qe.sibling;var It=he(ee,qe,se[Je],xe);if(It===null){qe===null&&(qe=zn);break}u&&qe&&It.alternate===null&&h(ee,qe),X=T(It,X,Je),Ve===null?$e=It:Ve.sibling=It,Ve=It,qe=zn}if(Je===se.length)return S(ee,qe),en&&xc(ee,Je),$e;if(qe===null){for(;Je<se.length;Je++)qe=me(ee,se[Je],xe),qe!==null&&(X=T(qe,X,Je),Ve===null?$e=qe:Ve.sibling=qe,Ve=qe);return en&&xc(ee,Je),$e}for(qe=w(ee,qe);Je<se.length;Je++)zn=Me(qe,ee,Je,se[Je],xe),zn!==null&&(u&&zn.alternate!==null&&qe.delete(zn.key===null?Je:zn.key),X=T(zn,X,Je),Ve===null?$e=zn:Ve.sibling=zn,Ve=zn);return u&&qe.forEach(function(pl){return h(ee,pl)}),en&&xc(ee,Je),$e}function Fe(ee,X,se,xe){var $e=Y(se);if(typeof $e!="function")throw Error(t(150));if(se=$e.call(se),se==null)throw Error(t(151));for(var Ve=$e=null,qe=X,Je=X=0,zn=null,It=se.next();qe!==null&&!It.done;Je++,It=se.next()){qe.index>Je?(zn=qe,qe=null):zn=qe.sibling;var pl=he(ee,qe,It.value,xe);if(pl===null){qe===null&&(qe=zn);break}u&&qe&&pl.alternate===null&&h(ee,qe),X=T(pl,X,Je),Ve===null?$e=pl:Ve.sibling=pl,Ve=pl,qe=zn}if(It.done)return S(ee,qe),en&&xc(ee,Je),$e;if(qe===null){for(;!It.done;Je++,It=se.next())It=me(ee,It.value,xe),It!==null&&(X=T(It,X,Je),Ve===null?$e=It:Ve.sibling=It,Ve=It);return en&&xc(ee,Je),$e}for(qe=w(ee,qe);!It.done;Je++,It=se.next())It=Me(qe,ee,Je,It.value,xe),It!==null&&(u&&It.alternate!==null&&qe.delete(It.key===null?Je:It.key),X=T(It,X,Je),Ve===null?$e=It:Ve.sibling=It,Ve=It);return u&&qe.forEach(function(VW){return h(ee,VW)}),en&&xc(ee,Je),$e}function xn(ee,X,se,xe){if(typeof se=="object"&&se!==null&&se.type===O&&se.key===null&&(se=se.props.children),typeof se=="object"&&se!==null){switch(se.$$typeof){case M:e:{for(var $e=se.key,Ve=X;Ve!==null;){if(Ve.key===$e){if($e=se.type,$e===O){if(Ve.tag===7){S(ee,Ve.sibling),X=I(Ve,se.props.children),X.return=ee,ee=X;break e}}else if(Ve.elementType===$e||typeof $e=="object"&&$e!==null&&$e.$$typeof===Z&&x2($e)===Ve.type){S(ee,Ve.sibling),X=I(Ve,se.props),X.ref=zh(ee,Ve,se),X.return=ee,ee=X;break e}S(ee,Ve);break}else h(ee,Ve);Ve=Ve.sibling}se.type===O?(X=_c(se.props.children,ee.mode,xe,se.key),X.return=ee,ee=X):(xe=tm(se.type,se.key,se.props,null,ee.mode,xe),xe.ref=zh(ee,X,se),xe.return=ee,ee=xe)}return j(ee);case A:e:{for(Ve=se.key;X!==null;){if(X.key===Ve)if(X.tag===4&&X.stateNode.containerInfo===se.containerInfo&&X.stateNode.implementation===se.implementation){S(ee,X.sibling),X=I(X,se.children||[]),X.return=ee,ee=X;break e}else{S(ee,X);break}else h(ee,X);X=X.sibling}X=yw(se,ee.mode,xe),X.return=ee,ee=X}return j(ee);case Z:return Ve=se._init,xn(ee,X,Ve(se._payload),xe)}if(ts(se))return je(ee,X,se,xe);if(Y(se))return Fe(ee,X,se,xe);Ag(ee,se)}return typeof se=="string"&&se!==""||typeof se=="number"?(se=""+se,X!==null&&X.tag===6?(S(ee,X.sibling),X=I(X,se),X.return=ee,ee=X):(S(ee,X),X=mw(se,ee.mode,xe),X.return=ee,ee=X),j(ee)):S(ee,X)}return xn}var Yu=w2(!0),b2=w2(!1),Og=rl(null),Rg=null,Xu=null,Ix=null;function Ex(){Ix=Xu=Rg=null}function _x(u){var h=Og.current;qt(Og),u._currentValue=h}function Tx(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 Zu(u,h){Rg=u,Ix=Xu=null,u=u.dependencies,u!==null&&u.firstContext!==null&&((u.lanes&h)!==0&&(cs=!0),u.firstContext=null)}function li(u){var h=u._currentValue;if(Ix!==u)if(u={context:u,memoizedValue:h,next:null},Xu===null){if(Rg===null)throw Error(t(308));Xu=u,Rg.dependencies={lanes:0,firstContext:u}}else Xu=Xu.next=u;return h}var wc=null;function Mx(u){wc===null?wc=[u]:wc.push(u)}function C2(u,h,S,w){var I=h.interleaved;return I===null?(S.next=S,Mx(h)):(S.next=I.next,I.next=S),h.interleaved=S,aa(u,w)}function aa(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 ol=!1;function Ax(u){u.updateQueue={baseState:u.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function P2(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 la(u,h){return{eventTime:u,lane:h,tag:0,payload:null,callback:null,next:null}}function al(u,h,S){var w=u.updateQueue;if(w===null)return null;if(w=w.shared,(Ct&2)!==0){var I=w.pending;return I===null?h.next=h:(h.next=I.next,I.next=h),w.pending=h,aa(u,S)}return I=w.interleaved,I===null?(h.next=h,Mx(w)):(h.next=I.next,I.next=h),w.interleaved=h,aa(u,S)}function Dg(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,ju(u,S)}}function k2(u,h){var S=u.updateQueue,w=u.alternate;if(w!==null&&(w=w.updateQueue,S===w)){var I=null,T=null;if(S=S.firstBaseUpdate,S!==null){do{var j={eventTime:S.eventTime,lane:S.lane,tag:S.tag,payload:S.payload,callback:S.callback,next:null};T===null?I=T=j:T=T.next=j,S=S.next}while(S!==null);T===null?I=T=h:T=T.next=h}else I=T=h;S={baseState:w.baseState,firstBaseUpdate:I,lastBaseUpdate:T,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 jg(u,h,S,w){var I=u.updateQueue;ol=!1;var T=I.firstBaseUpdate,j=I.lastBaseUpdate,H=I.shared.pending;if(H!==null){I.shared.pending=null;var q=H,oe=q.next;q.next=null,j===null?T=oe:j.next=oe,j=q;var fe=u.alternate;fe!==null&&(fe=fe.updateQueue,H=fe.lastBaseUpdate,H!==j&&(H===null?fe.firstBaseUpdate=oe:H.next=oe,fe.lastBaseUpdate=q))}if(T!==null){var me=I.baseState;j=0,fe=oe=q=null,H=T;do{var he=H.lane,Me=H.eventTime;if((w&he)===he){fe!==null&&(fe=fe.next={eventTime:Me,lane:0,tag:H.tag,payload:H.payload,callback:H.callback,next:null});e:{var je=u,Fe=H;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:ol=!0}}H.callback!==null&&H.lane!==0&&(u.flags|=64,he=I.effects,he===null?I.effects=[H]:he.push(H))}else Me={eventTime:Me,lane:he,tag:H.tag,payload:H.payload,callback:H.callback,next:null},fe===null?(oe=fe=Me,q=me):fe=fe.next=Me,j|=he;if(H=H.next,H===null){if(H=I.shared.pending,H===null)break;he=H,H=he.next,he.next=null,I.lastBaseUpdate=he,I.shared.pending=null}}while(!0);if(fe===null&&(q=me),I.baseState=q,I.firstBaseUpdate=oe,I.lastBaseUpdate=fe,h=I.shared.interleaved,h!==null){I=h;do j|=I.lane,I=I.next;while(I!==h)}else T===null&&(I.shared.lanes=0);Pc|=j,u.lanes=j,u.memoizedState=me}}function I2(u,h,S){if(u=h.effects,h.effects=null,u!==null)for(h=0;h<u.length;h++){var w=u[h],I=w.callback;if(I!==null){if(w.callback=null,w=S,typeof I!="function")throw Error(t(191,I));I.call(w)}}}var $h={},So=rl($h),Bh=rl($h),Uh=rl($h);function bc(u){if(u===$h)throw Error(t(174));return u}function Ox(u,h){switch(Ut(Uh,h),Ut(Bh,u),Ut(So,$h),u=h.nodeType,u){case 9:case 11:h=(h=h.documentElement)?h.namespaceURI:co(null,"");break;default:u=u===8?h.parentNode:h,h=u.namespaceURI||null,u=u.tagName,h=co(h,u)}qt(So),Ut(So,h)}function Ju(){qt(So),qt(Bh),qt(Uh)}function E2(u){bc(Uh.current);var h=bc(So.current),S=co(h,u.type);h!==S&&(Ut(Bh,u),Ut(So,S))}function Rx(u){Bh.current===u&&(qt(So),qt(Bh))}var sn=rl(0);function Ng(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 Dx=[];function jx(){for(var u=0;u<Dx.length;u++)Dx[u]._workInProgressVersionPrimary=null;Dx.length=0}var Lg=_.ReactCurrentDispatcher,Nx=_.ReactCurrentBatchConfig,Cc=0,on=null,An=null,Ln=null,Fg=!1,Hh=!1,Kh=0,pW=0;function gr(){throw Error(t(321))}function Lx(u,h){if(h===null)return!1;for(var S=0;S<h.length&&S<u.length;S++)if(!Ni(u[S],h[S]))return!1;return!0}function Fx(u,h,S,w,I,T){if(Cc=T,on=h,h.memoizedState=null,h.updateQueue=null,h.lanes=0,Lg.current=u===null||u.memoizedState===null?SW:vW,u=S(w,I),Hh){T=0;do{if(Hh=!1,Kh=0,25<=T)throw Error(t(301));T+=1,Ln=An=null,h.updateQueue=null,Lg.current=xW,u=S(w,I)}while(Hh)}if(Lg.current=Bg,h=An!==null&&An.next!==null,Cc=0,Ln=An=on=null,Fg=!1,h)throw Error(t(300));return u}function zx(){var u=Kh!==0;return Kh=0,u}function vo(){var u={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Ln===null?on.memoizedState=Ln=u:Ln=Ln.next=u,Ln}function ci(){if(An===null){var u=on.alternate;u=u!==null?u.memoizedState:null}else u=An.next;var h=Ln===null?on.memoizedState:Ln.next;if(h!==null)Ln=h,An=u;else{if(u===null)throw Error(t(310));An=u,u={memoizedState:An.memoizedState,baseState:An.baseState,baseQueue:An.baseQueue,queue:An.queue,next:null},Ln===null?on.memoizedState=Ln=u:Ln=Ln.next=u}return Ln}function Wh(u,h){return typeof h=="function"?h(u):h}function $x(u){var h=ci(),S=h.queue;if(S===null)throw Error(t(311));S.lastRenderedReducer=u;var w=An,I=w.baseQueue,T=S.pending;if(T!==null){if(I!==null){var j=I.next;I.next=T.next,T.next=j}w.baseQueue=I=T,S.pending=null}if(I!==null){T=I.next,w=w.baseState;var H=j=null,q=null,oe=T;do{var fe=oe.lane;if((Cc&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?(H=q=me,j=w):q=q.next=me,on.lanes|=fe,Pc|=fe}oe=oe.next}while(oe!==null&&oe!==T);q===null?j=w:q.next=H,Ni(w,h.memoizedState)||(cs=!0),h.memoizedState=w,h.baseState=j,h.baseQueue=q,S.lastRenderedState=w}if(u=S.interleaved,u!==null){I=u;do T=I.lane,on.lanes|=T,Pc|=T,I=I.next;while(I!==u)}else I===null&&(S.lanes=0);return[h.memoizedState,S.dispatch]}function Bx(u){var h=ci(),S=h.queue;if(S===null)throw Error(t(311));S.lastRenderedReducer=u;var w=S.dispatch,I=S.pending,T=h.memoizedState;if(I!==null){S.pending=null;var j=I=I.next;do T=u(T,j.action),j=j.next;while(j!==I);Ni(T,h.memoizedState)||(cs=!0),h.memoizedState=T,h.baseQueue===null&&(h.baseState=T),S.lastRenderedState=T}return[T,w]}function _2(){}function T2(u,h){var S=on,w=ci(),I=h(),T=!Ni(w.memoizedState,I);if(T&&(w.memoizedState=I,cs=!0),w=w.queue,Ux(O2.bind(null,S,w,u),[u]),w.getSnapshot!==h||T||Ln!==null&&Ln.memoizedState.tag&1){if(S.flags|=2048,Vh(9,A2.bind(null,S,w,I,h),void 0,null),Fn===null)throw Error(t(349));(Cc&30)!==0||M2(S,h,I)}return I}function M2(u,h,S){u.flags|=16384,u={getSnapshot:h,value:S},h=on.updateQueue,h===null?(h={lastEffect:null,stores:null},on.updateQueue=h,h.stores=[u]):(S=h.stores,S===null?h.stores=[u]:S.push(u))}function A2(u,h,S,w){h.value=S,h.getSnapshot=w,R2(h)&&D2(u)}function O2(u,h,S){return S(function(){R2(h)&&D2(u)})}function R2(u){var h=u.getSnapshot;u=u.value;try{var S=h();return!Ni(u,S)}catch{return!0}}function D2(u){var h=aa(u,1);h!==null&&Bi(h,u,1,-1)}function j2(u){var h=vo();return typeof u=="function"&&(u=u()),h.memoizedState=h.baseState=u,u={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Wh,lastRenderedState:u},h.queue=u,u=u.dispatch=yW.bind(null,on,u),[h.memoizedState,u]}function Vh(u,h,S,w){return u={tag:u,create:h,destroy:S,deps:w,next:null},h=on.updateQueue,h===null?(h={lastEffect:null,stores:null},on.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 N2(){return ci().memoizedState}function zg(u,h,S,w){var I=vo();on.flags|=u,I.memoizedState=Vh(1|h,S,void 0,w===void 0?null:w)}function $g(u,h,S,w){var I=ci();w=w===void 0?null:w;var T=void 0;if(An!==null){var j=An.memoizedState;if(T=j.destroy,w!==null&&Lx(w,j.deps)){I.memoizedState=Vh(h,S,T,w);return}}on.flags|=u,I.memoizedState=Vh(1|h,S,T,w)}function L2(u,h){return zg(8390656,8,u,h)}function Ux(u,h){return $g(2048,8,u,h)}function F2(u,h){return $g(4,2,u,h)}function z2(u,h){return $g(4,4,u,h)}function $2(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 B2(u,h,S){return S=S!=null?S.concat([u]):null,$g(4,4,$2.bind(null,h,u),S)}function Hx(){}function U2(u,h){var S=ci();h=h===void 0?null:h;var w=S.memoizedState;return w!==null&&h!==null&&Lx(h,w[1])?w[0]:(S.memoizedState=[u,h],u)}function H2(u,h){var S=ci();h=h===void 0?null:h;var w=S.memoizedState;return w!==null&&h!==null&&Lx(h,w[1])?w[0]:(u=u(),S.memoizedState=[u,h],u)}function K2(u,h,S){return(Cc&21)===0?(u.baseState&&(u.baseState=!1,cs=!0),u.memoizedState=S):(Ni(S,h)||(S=ug(),on.lanes|=S,Pc|=S,u.baseState=!0),h)}function gW(u,h){var S=xt;xt=S!==0&&4>S?S:4,u(!0);var w=Nx.transition;Nx.transition={};try{u(!1),h()}finally{xt=S,Nx.transition=w}}function W2(){return ci().memoizedState}function mW(u,h,S){var w=dl(u);if(S={lane:w,action:S,hasEagerState:!1,eagerState:null,next:null},V2(u))q2(h,S);else if(S=C2(u,h,S,w),S!==null){var I=Nr();Bi(S,u,w,I),G2(S,h,w)}}function yW(u,h,S){var w=dl(u),I={lane:w,action:S,hasEagerState:!1,eagerState:null,next:null};if(V2(u))q2(h,I);else{var T=u.alternate;if(u.lanes===0&&(T===null||T.lanes===0)&&(T=h.lastRenderedReducer,T!==null))try{var j=h.lastRenderedState,H=T(j,S);if(I.hasEagerState=!0,I.eagerState=H,Ni(H,j)){var q=h.interleaved;q===null?(I.next=I,Mx(h)):(I.next=q.next,q.next=I),h.interleaved=I;return}}catch{}finally{}S=C2(u,h,I,w),S!==null&&(I=Nr(),Bi(S,u,w,I),G2(S,h,w))}}function V2(u){var h=u.alternate;return u===on||h!==null&&h===on}function q2(u,h){Hh=Fg=!0;var S=u.pending;S===null?h.next=h:(h.next=S.next,S.next=h),u.pending=h}function G2(u,h,S){if((S&4194240)!==0){var w=h.lanes;w&=u.pendingLanes,S|=w,h.lanes=S,ju(u,S)}}var Bg={readContext:li,useCallback:gr,useContext:gr,useEffect:gr,useImperativeHandle:gr,useInsertionEffect:gr,useLayoutEffect:gr,useMemo:gr,useReducer:gr,useRef:gr,useState:gr,useDebugValue:gr,useDeferredValue:gr,useTransition:gr,useMutableSource:gr,useSyncExternalStore:gr,useId:gr,unstable_isNewReconciler:!1},SW={readContext:li,useCallback:function(u,h){return vo().memoizedState=[u,h===void 0?null:h],u},useContext:li,useEffect:L2,useImperativeHandle:function(u,h,S){return S=S!=null?S.concat([u]):null,zg(4194308,4,$2.bind(null,h,u),S)},useLayoutEffect:function(u,h){return zg(4194308,4,u,h)},useInsertionEffect:function(u,h){return zg(4,2,u,h)},useMemo:function(u,h){var S=vo();return h=h===void 0?null:h,u=u(),S.memoizedState=[u,h],u},useReducer:function(u,h,S){var w=vo();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=mW.bind(null,on,u),[w.memoizedState,u]},useRef:function(u){var h=vo();return u={current:u},h.memoizedState=u},useState:j2,useDebugValue:Hx,useDeferredValue:function(u){return vo().memoizedState=u},useTransition:function(){var u=j2(!1),h=u[0];return u=gW.bind(null,u[1]),vo().memoizedState=u,[h,u]},useMutableSource:function(){},useSyncExternalStore:function(u,h,S){var w=on,I=vo();if(en){if(S===void 0)throw Error(t(407));S=S()}else{if(S=h(),Fn===null)throw Error(t(349));(Cc&30)!==0||M2(w,h,S)}I.memoizedState=S;var T={value:S,getSnapshot:h};return I.queue=T,L2(O2.bind(null,w,T,u),[u]),w.flags|=2048,Vh(9,A2.bind(null,w,T,S,h),void 0,null),S},useId:function(){var u=vo(),h=Fn.identifierPrefix;if(en){var S=oa,w=ia;S=(w&~(1<<32-Ds(w)-1)).toString(32)+S,h=":"+h+"R"+S,S=Kh++,0<S&&(h+="H"+S.toString(32)),h+=":"}else S=pW++,h=":"+h+"r"+S.toString(32)+":";return u.memoizedState=h},unstable_isNewReconciler:!1},vW={readContext:li,useCallback:U2,useContext:li,useEffect:Ux,useImperativeHandle:B2,useInsertionEffect:F2,useLayoutEffect:z2,useMemo:H2,useReducer:$x,useRef:N2,useState:function(){return $x(Wh)},useDebugValue:Hx,useDeferredValue:function(u){var h=ci();return K2(h,An.memoizedState,u)},useTransition:function(){var u=$x(Wh)[0],h=ci().memoizedState;return[u,h]},useMutableSource:_2,useSyncExternalStore:T2,useId:W2,unstable_isNewReconciler:!1},xW={readContext:li,useCallback:U2,useContext:li,useEffect:Ux,useImperativeHandle:B2,useInsertionEffect:F2,useLayoutEffect:z2,useMemo:H2,useReducer:Bx,useRef:N2,useState:function(){return Bx(Wh)},useDebugValue:Hx,useDeferredValue:function(u){var h=ci();return An===null?h.memoizedState=u:K2(h,An.memoizedState,u)},useTransition:function(){var u=Bx(Wh)[0],h=ci().memoizedState;return[u,h]},useMutableSource:_2,useSyncExternalStore:T2,useId:W2,unstable_isNewReconciler:!1};function Fi(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 Kx(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 Ug={isMounted:function(u){return(u=u._reactInternals)?ta(u)===u:!1},enqueueSetState:function(u,h,S){u=u._reactInternals;var w=Nr(),I=dl(u),T=la(w,I);T.payload=h,S!=null&&(T.callback=S),h=al(u,T,I),h!==null&&(Bi(h,u,I,w),Dg(h,u,I))},enqueueReplaceState:function(u,h,S){u=u._reactInternals;var w=Nr(),I=dl(u),T=la(w,I);T.tag=1,T.payload=h,S!=null&&(T.callback=S),h=al(u,T,I),h!==null&&(Bi(h,u,I,w),Dg(h,u,I))},enqueueForceUpdate:function(u,h){u=u._reactInternals;var S=Nr(),w=dl(u),I=la(S,w);I.tag=2,h!=null&&(I.callback=h),h=al(u,I,w),h!==null&&(Bi(h,u,w,S),Dg(h,u,w))}};function Y2(u,h,S,w,I,T,j){return u=u.stateNode,typeof u.shouldComponentUpdate=="function"?u.shouldComponentUpdate(w,T,j):h.prototype&&h.prototype.isPureReactComponent?!Oh(S,w)||!Oh(I,T):!0}function X2(u,h,S){var w=!1,I=sl,T=h.contextType;return typeof T=="object"&&T!==null?T=li(T):(I=ls(h)?Sc:pr.current,w=h.contextTypes,T=(w=w!=null)?Wu(u,I):sl),h=new h(S,T),u.memoizedState=h.state!==null&&h.state!==void 0?h.state:null,h.updater=Ug,u.stateNode=h,h._reactInternals=u,w&&(u=u.stateNode,u.__reactInternalMemoizedUnmaskedChildContext=I,u.__reactInternalMemoizedMaskedChildContext=T),h}function Z2(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&&Ug.enqueueReplaceState(h,h.state,null)}function Wx(u,h,S,w){var I=u.stateNode;I.props=S,I.state=u.memoizedState,I.refs={},Ax(u);var T=h.contextType;typeof T=="object"&&T!==null?I.context=li(T):(T=ls(h)?Sc:pr.current,I.context=Wu(u,T)),I.state=u.memoizedState,T=h.getDerivedStateFromProps,typeof T=="function"&&(Kx(u,h,T,S),I.state=u.memoizedState),typeof h.getDerivedStateFromProps=="function"||typeof I.getSnapshotBeforeUpdate=="function"||typeof I.UNSAFE_componentWillMount!="function"&&typeof I.componentWillMount!="function"||(h=I.state,typeof I.componentWillMount=="function"&&I.componentWillMount(),typeof I.UNSAFE_componentWillMount=="function"&&I.UNSAFE_componentWillMount(),h!==I.state&&Ug.enqueueReplaceState(I,I.state,null),jg(u,S,I,w),I.state=u.memoizedState),typeof I.componentDidMount=="function"&&(u.flags|=4194308)}function Qu(u,h){try{var S="",w=h;do S+=ce(w),w=w.return;while(w);var I=S}catch(T){I=`
39
+ Error generating stack: `+T.message+`
40
+ `+T.stack}return{value:u,source:h,stack:I,digest:null}}function Vx(u,h,S){return{value:u,source:null,stack:S??null,digest:h??null}}function qx(u,h){try{console.error(h.value)}catch(S){setTimeout(function(){throw S})}}var wW=typeof WeakMap=="function"?WeakMap:Map;function J2(u,h,S){S=la(-1,S),S.tag=3,S.payload={element:null};var w=h.value;return S.callback=function(){Yg||(Yg=!0,lw=w),qx(u,h)},S}function Q2(u,h,S){S=la(-1,S),S.tag=3;var w=u.type.getDerivedStateFromError;if(typeof w=="function"){var I=h.value;S.payload=function(){return w(I)},S.callback=function(){qx(u,h)}}var T=u.stateNode;return T!==null&&typeof T.componentDidCatch=="function"&&(S.callback=function(){qx(u,h),typeof w!="function"&&(cl===null?cl=new Set([this]):cl.add(this));var j=h.stack;this.componentDidCatch(h.value,{componentStack:j!==null?j:""})}),S}function eM(u,h,S){var w=u.pingCache;if(w===null){w=u.pingCache=new wW;var I=new Set;w.set(h,I)}else I=w.get(h),I===void 0&&(I=new Set,w.set(h,I));I.has(S)||(I.add(S),u=jW.bind(null,u,h,S),h.then(u,u))}function tM(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 nM(u,h,S,w,I){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=la(-1,1),h.tag=2,al(S,h,1))),S.lanes|=1),u):(u.flags|=65536,u.lanes=I,u)}var bW=_.ReactCurrentOwner,cs=!1;function jr(u,h,S,w){h.child=u===null?b2(h,null,S,w):Yu(h,u.child,S,w)}function rM(u,h,S,w,I){S=S.render;var T=h.ref;return Zu(h,I),w=Fx(u,h,S,w,T,I),S=zx(),u!==null&&!cs?(h.updateQueue=u.updateQueue,h.flags&=-2053,u.lanes&=~I,ca(u,h,I)):(en&&S&&wx(h),h.flags|=1,jr(u,h,w,I),h.child)}function sM(u,h,S,w,I){if(u===null){var T=S.type;return typeof T=="function"&&!gw(T)&&T.defaultProps===void 0&&S.compare===null&&S.defaultProps===void 0?(h.tag=15,h.type=T,iM(u,h,T,w,I)):(u=tm(S.type,null,w,h,h.mode,I),u.ref=h.ref,u.return=h,h.child=u)}if(T=u.child,(u.lanes&I)===0){var j=T.memoizedProps;if(S=S.compare,S=S!==null?S:Oh,S(j,w)&&u.ref===h.ref)return ca(u,h,I)}return h.flags|=1,u=fl(T,w),u.ref=h.ref,u.return=h,h.child=u}function iM(u,h,S,w,I){if(u!==null){var T=u.memoizedProps;if(Oh(T,w)&&u.ref===h.ref)if(cs=!1,h.pendingProps=w=T,(u.lanes&I)!==0)(u.flags&131072)!==0&&(cs=!0);else return h.lanes=u.lanes,ca(u,h,I)}return Gx(u,h,S,w,I)}function oM(u,h,S){var w=h.pendingProps,I=w.children,T=u!==null?u.memoizedState:null;if(w.mode==="hidden")if((h.mode&1)===0)h.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ut(td,Ls),Ls|=S;else{if((S&1073741824)===0)return u=T!==null?T.baseLanes|S:S,h.lanes=h.childLanes=1073741824,h.memoizedState={baseLanes:u,cachePool:null,transitions:null},h.updateQueue=null,Ut(td,Ls),Ls|=u,null;h.memoizedState={baseLanes:0,cachePool:null,transitions:null},w=T!==null?T.baseLanes:S,Ut(td,Ls),Ls|=w}else T!==null?(w=T.baseLanes|S,h.memoizedState=null):w=S,Ut(td,Ls),Ls|=w;return jr(u,h,I,S),h.child}function aM(u,h){var S=h.ref;(u===null&&S!==null||u!==null&&u.ref!==S)&&(h.flags|=512,h.flags|=2097152)}function Gx(u,h,S,w,I){var T=ls(S)?Sc:pr.current;return T=Wu(h,T),Zu(h,I),S=Fx(u,h,S,w,T,I),w=zx(),u!==null&&!cs?(h.updateQueue=u.updateQueue,h.flags&=-2053,u.lanes&=~I,ca(u,h,I)):(en&&w&&wx(h),h.flags|=1,jr(u,h,S,I),h.child)}function lM(u,h,S,w,I){if(ls(S)){var T=!0;Ig(h)}else T=!1;if(Zu(h,I),h.stateNode===null)Kg(u,h),X2(h,S,w),Wx(h,S,w,I),w=!0;else if(u===null){var j=h.stateNode,H=h.memoizedProps;j.props=H;var q=j.context,oe=S.contextType;typeof oe=="object"&&oe!==null?oe=li(oe):(oe=ls(S)?Sc:pr.current,oe=Wu(h,oe));var fe=S.getDerivedStateFromProps,me=typeof fe=="function"||typeof j.getSnapshotBeforeUpdate=="function";me||typeof j.UNSAFE_componentWillReceiveProps!="function"&&typeof j.componentWillReceiveProps!="function"||(H!==w||q!==oe)&&Z2(h,j,w,oe),ol=!1;var he=h.memoizedState;j.state=he,jg(h,w,j,I),q=h.memoizedState,H!==w||he!==q||as.current||ol?(typeof fe=="function"&&(Kx(h,S,fe,w),q=h.memoizedState),(H=ol||Y2(h,S,H,w,he,q,oe))?(me||typeof j.UNSAFE_componentWillMount!="function"&&typeof j.componentWillMount!="function"||(typeof j.componentWillMount=="function"&&j.componentWillMount(),typeof j.UNSAFE_componentWillMount=="function"&&j.UNSAFE_componentWillMount()),typeof j.componentDidMount=="function"&&(h.flags|=4194308)):(typeof j.componentDidMount=="function"&&(h.flags|=4194308),h.memoizedProps=w,h.memoizedState=q),j.props=w,j.state=q,j.context=oe,w=H):(typeof j.componentDidMount=="function"&&(h.flags|=4194308),w=!1)}else{j=h.stateNode,P2(u,h),H=h.memoizedProps,oe=h.type===h.elementType?H:Fi(h.type,H),j.props=oe,me=h.pendingProps,he=j.context,q=S.contextType,typeof q=="object"&&q!==null?q=li(q):(q=ls(S)?Sc:pr.current,q=Wu(h,q));var Me=S.getDerivedStateFromProps;(fe=typeof Me=="function"||typeof j.getSnapshotBeforeUpdate=="function")||typeof j.UNSAFE_componentWillReceiveProps!="function"&&typeof j.componentWillReceiveProps!="function"||(H!==me||he!==q)&&Z2(h,j,w,q),ol=!1,he=h.memoizedState,j.state=he,jg(h,w,j,I);var je=h.memoizedState;H!==me||he!==je||as.current||ol?(typeof Me=="function"&&(Kx(h,S,Me,w),je=h.memoizedState),(oe=ol||Y2(h,S,oe,w,he,je,q)||!1)?(fe||typeof j.UNSAFE_componentWillUpdate!="function"&&typeof j.componentWillUpdate!="function"||(typeof j.componentWillUpdate=="function"&&j.componentWillUpdate(w,je,q),typeof j.UNSAFE_componentWillUpdate=="function"&&j.UNSAFE_componentWillUpdate(w,je,q)),typeof j.componentDidUpdate=="function"&&(h.flags|=4),typeof j.getSnapshotBeforeUpdate=="function"&&(h.flags|=1024)):(typeof j.componentDidUpdate!="function"||H===u.memoizedProps&&he===u.memoizedState||(h.flags|=4),typeof j.getSnapshotBeforeUpdate!="function"||H===u.memoizedProps&&he===u.memoizedState||(h.flags|=1024),h.memoizedProps=w,h.memoizedState=je),j.props=w,j.state=je,j.context=q,w=oe):(typeof j.componentDidUpdate!="function"||H===u.memoizedProps&&he===u.memoizedState||(h.flags|=4),typeof j.getSnapshotBeforeUpdate!="function"||H===u.memoizedProps&&he===u.memoizedState||(h.flags|=1024),w=!1)}return Yx(u,h,S,w,T,I)}function Yx(u,h,S,w,I,T){aM(u,h);var j=(h.flags&128)!==0;if(!w&&!j)return I&&f2(h,S,!1),ca(u,h,T);w=h.stateNode,bW.current=h;var H=j&&typeof S.getDerivedStateFromError!="function"?null:w.render();return h.flags|=1,u!==null&&j?(h.child=Yu(h,u.child,null,T),h.child=Yu(h,null,H,T)):jr(u,h,H,T),h.memoizedState=w.state,I&&f2(h,S,!0),h.child}function cM(u){var h=u.stateNode;h.pendingContext?d2(u,h.pendingContext,h.pendingContext!==h.context):h.context&&d2(u,h.context,!1),Ox(u,h.containerInfo)}function uM(u,h,S,w,I){return Gu(),kx(I),h.flags|=256,jr(u,h,S,w),h.child}var Xx={dehydrated:null,treeContext:null,retryLane:0};function Zx(u){return{baseLanes:u,cachePool:null,transitions:null}}function dM(u,h,S){var w=h.pendingProps,I=sn.current,T=!1,j=(h.flags&128)!==0,H;if((H=j)||(H=u!==null&&u.memoizedState===null?!1:(I&2)!==0),H?(T=!0,h.flags&=-129):(u===null||u.memoizedState!==null)&&(I|=1),Ut(sn,I&1),u===null)return Px(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):(j=w.children,u=w.fallback,T?(w=h.mode,T=h.child,j={mode:"hidden",children:j},(w&1)===0&&T!==null?(T.childLanes=0,T.pendingProps=j):T=nm(j,w,0,null),u=_c(u,w,S,null),T.return=h,u.return=h,T.sibling=u,h.child=T,h.child.memoizedState=Zx(S),h.memoizedState=Xx,u):Jx(h,j));if(I=u.memoizedState,I!==null&&(H=I.dehydrated,H!==null))return CW(u,h,j,w,H,I,S);if(T){T=w.fallback,j=h.mode,I=u.child,H=I.sibling;var q={mode:"hidden",children:w.children};return(j&1)===0&&h.child!==I?(w=h.child,w.childLanes=0,w.pendingProps=q,h.deletions=null):(w=fl(I,q),w.subtreeFlags=I.subtreeFlags&14680064),H!==null?T=fl(H,T):(T=_c(T,j,S,null),T.flags|=2),T.return=h,w.return=h,w.sibling=T,h.child=w,w=T,T=h.child,j=u.child.memoizedState,j=j===null?Zx(S):{baseLanes:j.baseLanes|S,cachePool:null,transitions:j.transitions},T.memoizedState=j,T.childLanes=u.childLanes&~S,h.memoizedState=Xx,w}return T=u.child,u=T.sibling,w=fl(T,{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 Jx(u,h){return h=nm({mode:"visible",children:h},u.mode,0,null),h.return=u,u.child=h}function Hg(u,h,S,w){return w!==null&&kx(w),Yu(h,u.child,null,S),u=Jx(h,h.pendingProps.children),u.flags|=2,h.memoizedState=null,u}function CW(u,h,S,w,I,T,j){if(S)return h.flags&256?(h.flags&=-257,w=Vx(Error(t(422))),Hg(u,h,j,w)):h.memoizedState!==null?(h.child=u.child,h.flags|=128,null):(T=w.fallback,I=h.mode,w=nm({mode:"visible",children:w.children},I,0,null),T=_c(T,I,j,null),T.flags|=2,w.return=h,T.return=h,w.sibling=T,h.child=w,(h.mode&1)!==0&&Yu(h,u.child,null,j),h.child.memoizedState=Zx(j),h.memoizedState=Xx,T);if((h.mode&1)===0)return Hg(u,h,j,null);if(I.data==="$!"){if(w=I.nextSibling&&I.nextSibling.dataset,w)var H=w.dgst;return w=H,T=Error(t(419)),w=Vx(T,w,void 0),Hg(u,h,j,w)}if(H=(j&u.childLanes)!==0,cs||H){if(w=Fn,w!==null){switch(j&-j){case 4:I=2;break;case 16:I=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:I=32;break;case 536870912:I=268435456;break;default:I=0}I=(I&(w.suspendedLanes|j))!==0?0:I,I!==0&&I!==T.retryLane&&(T.retryLane=I,aa(u,I),Bi(w,u,I,-1))}return pw(),w=Vx(Error(t(421))),Hg(u,h,j,w)}return I.data==="$?"?(h.flags|=128,h.child=u.child,h=NW.bind(null,u),I._reactRetry=h,null):(u=T.treeContext,Ns=nl(I.nextSibling),js=h,en=!0,Li=null,u!==null&&(oi[ai++]=ia,oi[ai++]=oa,oi[ai++]=vc,ia=u.id,oa=u.overflow,vc=h),h=Jx(h,w.children),h.flags|=4096,h)}function hM(u,h,S){u.lanes|=h;var w=u.alternate;w!==null&&(w.lanes|=h),Tx(u.return,h,S)}function Qx(u,h,S,w,I){var T=u.memoizedState;T===null?u.memoizedState={isBackwards:h,rendering:null,renderingStartTime:0,last:w,tail:S,tailMode:I}:(T.isBackwards=h,T.rendering=null,T.renderingStartTime=0,T.last=w,T.tail=S,T.tailMode=I)}function fM(u,h,S){var w=h.pendingProps,I=w.revealOrder,T=w.tail;if(jr(u,h,w.children,S),w=sn.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&&hM(u,S,h);else if(u.tag===19)hM(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(Ut(sn,w),(h.mode&1)===0)h.memoizedState=null;else switch(I){case"forwards":for(S=h.child,I=null;S!==null;)u=S.alternate,u!==null&&Ng(u)===null&&(I=S),S=S.sibling;S=I,S===null?(I=h.child,h.child=null):(I=S.sibling,S.sibling=null),Qx(h,!1,I,S,T);break;case"backwards":for(S=null,I=h.child,h.child=null;I!==null;){if(u=I.alternate,u!==null&&Ng(u)===null){h.child=I;break}u=I.sibling,I.sibling=S,S=I,I=u}Qx(h,!0,S,null,T);break;case"together":Qx(h,!1,null,null,void 0);break;default:h.memoizedState=null}return h.child}function Kg(u,h){(h.mode&1)===0&&u!==null&&(u.alternate=null,h.alternate=null,h.flags|=2)}function ca(u,h,S){if(u!==null&&(h.dependencies=u.dependencies),Pc|=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=fl(u,u.pendingProps),h.child=S,S.return=h;u.sibling!==null;)u=u.sibling,S=S.sibling=fl(u,u.pendingProps),S.return=h;S.sibling=null}return h.child}function PW(u,h,S){switch(h.tag){case 3:cM(h),Gu();break;case 5:E2(h);break;case 1:ls(h.type)&&Ig(h);break;case 4:Ox(h,h.stateNode.containerInfo);break;case 10:var w=h.type._context,I=h.memoizedProps.value;Ut(Og,w._currentValue),w._currentValue=I;break;case 13:if(w=h.memoizedState,w!==null)return w.dehydrated!==null?(Ut(sn,sn.current&1),h.flags|=128,null):(S&h.child.childLanes)!==0?dM(u,h,S):(Ut(sn,sn.current&1),u=ca(u,h,S),u!==null?u.sibling:null);Ut(sn,sn.current&1);break;case 19:if(w=(S&h.childLanes)!==0,(u.flags&128)!==0){if(w)return fM(u,h,S);h.flags|=128}if(I=h.memoizedState,I!==null&&(I.rendering=null,I.tail=null,I.lastEffect=null),Ut(sn,sn.current),w)break;return null;case 22:case 23:return h.lanes=0,oM(u,h,S)}return ca(u,h,S)}var pM,ew,gM,mM;pM=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}},ew=function(){},gM=function(u,h,S,w){var I=u.memoizedProps;if(I!==w){u=h.stateNode,bc(So.current);var T=null;switch(S){case"input":I=Qt(u,I),w=Qt(u,w),T=[];break;case"select":I=re({},I,{value:void 0}),w=re({},w,{value:void 0}),T=[];break;case"textarea":I=ac(u,I),w=ac(u,w),T=[];break;default:typeof I.onClick!="function"&&typeof w.onClick=="function"&&(u.onclick=Cg)}Qo(S,w);var j;S=null;for(oe in I)if(!w.hasOwnProperty(oe)&&I.hasOwnProperty(oe)&&I[oe]!=null)if(oe==="style"){var H=I[oe];for(j in H)H.hasOwnProperty(j)&&(S||(S={}),S[j]="")}else oe!=="dangerouslySetInnerHTML"&&oe!=="children"&&oe!=="suppressContentEditableWarning"&&oe!=="suppressHydrationWarning"&&oe!=="autoFocus"&&(s.hasOwnProperty(oe)?T||(T=[]):(T=T||[]).push(oe,null));for(oe in w){var q=w[oe];if(H=I!=null?I[oe]:void 0,w.hasOwnProperty(oe)&&q!==H&&(q!=null||H!=null))if(oe==="style")if(H){for(j in H)!H.hasOwnProperty(j)||q&&q.hasOwnProperty(j)||(S||(S={}),S[j]="");for(j in q)q.hasOwnProperty(j)&&H[j]!==q[j]&&(S||(S={}),S[j]=q[j])}else S||(T||(T=[]),T.push(oe,S)),S=q;else oe==="dangerouslySetInnerHTML"?(q=q?q.__html:void 0,H=H?H.__html:void 0,q!=null&&H!==q&&(T=T||[]).push(oe,q)):oe==="children"?typeof q!="string"&&typeof q!="number"||(T=T||[]).push(oe,""+q):oe!=="suppressContentEditableWarning"&&oe!=="suppressHydrationWarning"&&(s.hasOwnProperty(oe)?(q!=null&&oe==="onScroll"&&Vt("scroll",u),T||H===q||(T=[])):(T=T||[]).push(oe,q))}S&&(T=T||[]).push("style",S);var oe=T;(h.updateQueue=oe)&&(h.flags|=4)}},mM=function(u,h,S,w){S!==w&&(h.flags|=4)};function qh(u,h){if(!en)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 mr(u){var h=u.alternate!==null&&u.alternate.child===u.child,S=0,w=0;if(h)for(var I=u.child;I!==null;)S|=I.lanes|I.childLanes,w|=I.subtreeFlags&14680064,w|=I.flags&14680064,I.return=u,I=I.sibling;else for(I=u.child;I!==null;)S|=I.lanes|I.childLanes,w|=I.subtreeFlags,w|=I.flags,I.return=u,I=I.sibling;return u.subtreeFlags|=w,u.childLanes=S,h}function kW(u,h,S){var w=h.pendingProps;switch(bx(h),h.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return mr(h),null;case 1:return ls(h.type)&&kg(),mr(h),null;case 3:return w=h.stateNode,Ju(),qt(as),qt(pr),jx(),w.pendingContext&&(w.context=w.pendingContext,w.pendingContext=null),(u===null||u.child===null)&&(Mg(h)?h.flags|=4:u===null||u.memoizedState.isDehydrated&&(h.flags&256)===0||(h.flags|=1024,Li!==null&&(dw(Li),Li=null))),ew(u,h),mr(h),null;case 5:Rx(h);var I=bc(Uh.current);if(S=h.type,u!==null&&h.stateNode!=null)gM(u,h,S,w,I),u.ref!==h.ref&&(h.flags|=512,h.flags|=2097152);else{if(!w){if(h.stateNode===null)throw Error(t(166));return mr(h),null}if(u=bc(So.current),Mg(h)){w=h.stateNode,S=h.type;var T=h.memoizedProps;switch(w[yo]=h,w[Lh]=T,u=(h.mode&1)!==0,S){case"dialog":Vt("cancel",w),Vt("close",w);break;case"iframe":case"object":case"embed":Vt("load",w);break;case"video":case"audio":for(I=0;I<Dh.length;I++)Vt(Dh[I],w);break;case"source":Vt("error",w);break;case"img":case"image":case"link":Vt("error",w),Vt("load",w);break;case"details":Vt("toggle",w);break;case"input":Nt(w,T),Vt("invalid",w);break;case"select":w._wrapperState={wasMultiple:!!T.multiple},Vt("invalid",w);break;case"textarea":bu(w,T),Vt("invalid",w)}Qo(S,T),I=null;for(var j in T)if(T.hasOwnProperty(j)){var H=T[j];j==="children"?typeof H=="string"?w.textContent!==H&&(T.suppressHydrationWarning!==!0&&bg(w.textContent,H,u),I=["children",H]):typeof H=="number"&&w.textContent!==""+H&&(T.suppressHydrationWarning!==!0&&bg(w.textContent,H,u),I=["children",""+H]):s.hasOwnProperty(j)&&H!=null&&j==="onScroll"&&Vt("scroll",w)}switch(S){case"input":st(w),Qr(w,T,!0);break;case"textarea":st(w),Pu(w);break;case"select":case"option":break;default:typeof T.onClick=="function"&&(w.onclick=Cg)}w=I,h.updateQueue=w,w!==null&&(h.flags|=4)}else{j=I.nodeType===9?I:I.ownerDocument,u==="http://www.w3.org/1999/xhtml"&&(u=ku(S)),u==="http://www.w3.org/1999/xhtml"?S==="script"?(u=j.createElement("div"),u.innerHTML="<script><\/script>",u=u.removeChild(u.firstChild)):typeof w.is=="string"?u=j.createElement(S,{is:w.is}):(u=j.createElement(S),S==="select"&&(j=u,w.multiple?j.multiple=!0:w.size&&(j.size=w.size))):u=j.createElementNS(u,S),u[yo]=h,u[Lh]=w,pM(u,h,!1,!1),h.stateNode=u;e:{switch(j=As(S,w),S){case"dialog":Vt("cancel",u),Vt("close",u),I=w;break;case"iframe":case"object":case"embed":Vt("load",u),I=w;break;case"video":case"audio":for(I=0;I<Dh.length;I++)Vt(Dh[I],u);I=w;break;case"source":Vt("error",u),I=w;break;case"img":case"image":case"link":Vt("error",u),Vt("load",u),I=w;break;case"details":Vt("toggle",u),I=w;break;case"input":Nt(u,w),I=Qt(u,w),Vt("invalid",u);break;case"option":I=w;break;case"select":u._wrapperState={wasMultiple:!!w.multiple},I=re({},w,{value:void 0}),Vt("invalid",u);break;case"textarea":bu(u,w),I=ac(u,w),Vt("invalid",u);break;default:I=w}Qo(S,I),H=I;for(T in H)if(H.hasOwnProperty(T)){var q=H[T];T==="style"?ni(u,q):T==="dangerouslySetInnerHTML"?(q=q?q.__html:void 0,q!=null&&lc(u,q)):T==="children"?typeof q=="string"?(S!=="textarea"||q!=="")&&ae(u,q):typeof q=="number"&&ae(u,""+q):T!=="suppressContentEditableWarning"&&T!=="suppressHydrationWarning"&&T!=="autoFocus"&&(s.hasOwnProperty(T)?q!=null&&T==="onScroll"&&Vt("scroll",u):q!=null&&E(u,T,q,j))}switch(S){case"input":st(u),Qr(u,w,!1);break;case"textarea":st(u),Pu(u);break;case"option":w.value!=null&&u.setAttribute("value",""+Ce(w.value));break;case"select":u.multiple=!!w.multiple,T=w.value,T!=null?ti(u,!!w.multiple,T,!1):w.defaultValue!=null&&ti(u,!!w.multiple,w.defaultValue,!0);break;default:typeof I.onClick=="function"&&(u.onclick=Cg)}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 mr(h),null;case 6:if(u&&h.stateNode!=null)mM(u,h,u.memoizedProps,w);else{if(typeof w!="string"&&h.stateNode===null)throw Error(t(166));if(S=bc(Uh.current),bc(So.current),Mg(h)){if(w=h.stateNode,S=h.memoizedProps,w[yo]=h,(T=w.nodeValue!==S)&&(u=js,u!==null))switch(u.tag){case 3:bg(w.nodeValue,S,(u.mode&1)!==0);break;case 5:u.memoizedProps.suppressHydrationWarning!==!0&&bg(w.nodeValue,S,(u.mode&1)!==0)}T&&(h.flags|=4)}else w=(S.nodeType===9?S:S.ownerDocument).createTextNode(w),w[yo]=h,h.stateNode=w}return mr(h),null;case 13:if(qt(sn),w=h.memoizedState,u===null||u.memoizedState!==null&&u.memoizedState.dehydrated!==null){if(en&&Ns!==null&&(h.mode&1)!==0&&(h.flags&128)===0)v2(),Gu(),h.flags|=98560,T=!1;else if(T=Mg(h),w!==null&&w.dehydrated!==null){if(u===null){if(!T)throw Error(t(318));if(T=h.memoizedState,T=T!==null?T.dehydrated:null,!T)throw Error(t(317));T[yo]=h}else Gu(),(h.flags&128)===0&&(h.memoizedState=null),h.flags|=4;mr(h),T=!1}else Li!==null&&(dw(Li),Li=null),T=!0;if(!T)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||(sn.current&1)!==0?On===0&&(On=3):pw())),h.updateQueue!==null&&(h.flags|=4),mr(h),null);case 4:return Ju(),ew(u,h),u===null&&jh(h.stateNode.containerInfo),mr(h),null;case 10:return _x(h.type._context),mr(h),null;case 17:return ls(h.type)&&kg(),mr(h),null;case 19:if(qt(sn),T=h.memoizedState,T===null)return mr(h),null;if(w=(h.flags&128)!==0,j=T.rendering,j===null)if(w)qh(T,!1);else{if(On!==0||u!==null&&(u.flags&128)!==0)for(u=h.child;u!==null;){if(j=Ng(u),j!==null){for(h.flags|=128,qh(T,!1),w=j.updateQueue,w!==null&&(h.updateQueue=w,h.flags|=4),h.subtreeFlags=0,w=S,S=h.child;S!==null;)T=S,u=w,T.flags&=14680066,j=T.alternate,j===null?(T.childLanes=0,T.lanes=u,T.child=null,T.subtreeFlags=0,T.memoizedProps=null,T.memoizedState=null,T.updateQueue=null,T.dependencies=null,T.stateNode=null):(T.childLanes=j.childLanes,T.lanes=j.lanes,T.child=j.child,T.subtreeFlags=0,T.deletions=null,T.memoizedProps=j.memoizedProps,T.memoizedState=j.memoizedState,T.updateQueue=j.updateQueue,T.type=j.type,u=j.dependencies,T.dependencies=u===null?null:{lanes:u.lanes,firstContext:u.firstContext}),S=S.sibling;return Ut(sn,sn.current&1|2),h.child}u=u.sibling}T.tail!==null&&rn()>nd&&(h.flags|=128,w=!0,qh(T,!1),h.lanes=4194304)}else{if(!w)if(u=Ng(j),u!==null){if(h.flags|=128,w=!0,S=u.updateQueue,S!==null&&(h.updateQueue=S,h.flags|=4),qh(T,!0),T.tail===null&&T.tailMode==="hidden"&&!j.alternate&&!en)return mr(h),null}else 2*rn()-T.renderingStartTime>nd&&S!==1073741824&&(h.flags|=128,w=!0,qh(T,!1),h.lanes=4194304);T.isBackwards?(j.sibling=h.child,h.child=j):(S=T.last,S!==null?S.sibling=j:h.child=j,T.last=j)}return T.tail!==null?(h=T.tail,T.rendering=h,T.tail=h.sibling,T.renderingStartTime=rn(),h.sibling=null,S=sn.current,Ut(sn,w?S&1|2:S&1),h):(mr(h),null);case 22:case 23:return fw(),w=h.memoizedState!==null,u!==null&&u.memoizedState!==null!==w&&(h.flags|=8192),w&&(h.mode&1)!==0?(Ls&1073741824)!==0&&(mr(h),h.subtreeFlags&6&&(h.flags|=8192)):mr(h),null;case 24:return null;case 25:return null}throw Error(t(156,h.tag))}function IW(u,h){switch(bx(h),h.tag){case 1:return ls(h.type)&&kg(),u=h.flags,u&65536?(h.flags=u&-65537|128,h):null;case 3:return Ju(),qt(as),qt(pr),jx(),u=h.flags,(u&65536)!==0&&(u&128)===0?(h.flags=u&-65537|128,h):null;case 5:return Rx(h),null;case 13:if(qt(sn),u=h.memoizedState,u!==null&&u.dehydrated!==null){if(h.alternate===null)throw Error(t(340));Gu()}return u=h.flags,u&65536?(h.flags=u&-65537|128,h):null;case 19:return qt(sn),null;case 4:return Ju(),null;case 10:return _x(h.type._context),null;case 22:case 23:return fw(),null;case 24:return null;default:return null}}var Wg=!1,yr=!1,EW=typeof WeakSet=="function"?WeakSet:Set,Oe=null;function ed(u,h){var S=u.ref;if(S!==null)if(typeof S=="function")try{S(null)}catch(w){pn(u,h,w)}else S.current=null}function tw(u,h,S){try{S()}catch(w){pn(u,h,w)}}var yM=!1;function _W(u,h){if(fx=J,u=YT(),ix(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 I=w.anchorOffset,T=w.focusNode;w=w.focusOffset;try{S.nodeType,T.nodeType}catch{S=null;break e}var j=0,H=-1,q=-1,oe=0,fe=0,me=u,he=null;t:for(;;){for(var Me;me!==S||I!==0&&me.nodeType!==3||(H=j+I),me!==T||w!==0&&me.nodeType!==3||(q=j+w),me.nodeType===3&&(j+=me.nodeValue.length),(Me=me.firstChild)!==null;)he=me,me=Me;for(;;){if(me===u)break t;if(he===S&&++oe===I&&(H=j),he===T&&++fe===w&&(q=j),(Me=me.nextSibling)!==null)break;me=he,he=me.parentNode}me=Me}S=H===-1||q===-1?null:{start:H,end:q}}else S=null}S=S||{start:0,end:0}}else S=null;for(px={focusedElem:u,selectionRange:S},J=!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,xn=je.memoizedState,ee=h.stateNode,X=ee.getSnapshotBeforeUpdate(h.elementType===h.type?Fe:Fi(h.type,Fe),xn);ee.__reactInternalSnapshotBeforeUpdate=X}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){pn(h,h.return,xe)}if(u=h.sibling,u!==null){u.return=h.return,Oe=u;break}Oe=h.return}return je=yM,yM=!1,je}function Gh(u,h,S){var w=h.updateQueue;if(w=w!==null?w.lastEffect:null,w!==null){var I=w=w.next;do{if((I.tag&u)===u){var T=I.destroy;I.destroy=void 0,T!==void 0&&tw(h,S,T)}I=I.next}while(I!==w)}}function Vg(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 nw(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 SM(u){var h=u.alternate;h!==null&&(u.alternate=null,SM(h)),u.child=null,u.deletions=null,u.sibling=null,u.tag===5&&(h=u.stateNode,h!==null&&(delete h[yo],delete h[Lh],delete h[Sx],delete h[uW],delete h[dW])),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 vM(u){return u.tag===5||u.tag===3||u.tag===4}function xM(u){e:for(;;){for(;u.sibling===null;){if(u.return===null||vM(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 rw(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=Cg));else if(w!==4&&(u=u.child,u!==null))for(rw(u,h,S),u=u.sibling;u!==null;)rw(u,h,S),u=u.sibling}function sw(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(sw(u,h,S),u=u.sibling;u!==null;)sw(u,h,S),u=u.sibling}var Xn=null,zi=!1;function ll(u,h,S){for(S=S.child;S!==null;)wM(u,h,S),S=S.sibling}function wM(u,h,S){if(ii&&typeof ii.onCommitFiberUnmount=="function")try{ii.onCommitFiberUnmount(Au,S)}catch{}switch(S.tag){case 5:yr||ed(S,h);case 6:var w=Xn,I=zi;Xn=null,ll(u,h,S),Xn=w,zi=I,Xn!==null&&(zi?(u=Xn,S=S.stateNode,u.nodeType===8?u.parentNode.removeChild(S):u.removeChild(S)):Xn.removeChild(S.stateNode));break;case 18:Xn!==null&&(zi?(u=Xn,S=S.stateNode,u.nodeType===8?yx(u.parentNode,S):u.nodeType===1&&yx(u,S),mc(u)):yx(Xn,S.stateNode));break;case 4:w=Xn,I=zi,Xn=S.stateNode.containerInfo,zi=!0,ll(u,h,S),Xn=w,zi=I;break;case 0:case 11:case 14:case 15:if(!yr&&(w=S.updateQueue,w!==null&&(w=w.lastEffect,w!==null))){I=w=w.next;do{var T=I,j=T.destroy;T=T.tag,j!==void 0&&((T&2)!==0||(T&4)!==0)&&tw(S,h,j),I=I.next}while(I!==w)}ll(u,h,S);break;case 1:if(!yr&&(ed(S,h),w=S.stateNode,typeof w.componentWillUnmount=="function"))try{w.props=S.memoizedProps,w.state=S.memoizedState,w.componentWillUnmount()}catch(H){pn(S,h,H)}ll(u,h,S);break;case 21:ll(u,h,S);break;case 22:S.mode&1?(yr=(w=yr)||S.memoizedState!==null,ll(u,h,S),yr=w):ll(u,h,S);break;default:ll(u,h,S)}}function bM(u){var h=u.updateQueue;if(h!==null){u.updateQueue=null;var S=u.stateNode;S===null&&(S=u.stateNode=new EW),h.forEach(function(w){var I=LW.bind(null,u,w);S.has(w)||(S.add(w),w.then(I,I))})}}function $i(u,h){var S=h.deletions;if(S!==null)for(var w=0;w<S.length;w++){var I=S[w];try{var T=u,j=h,H=j;e:for(;H!==null;){switch(H.tag){case 5:Xn=H.stateNode,zi=!1;break e;case 3:Xn=H.stateNode.containerInfo,zi=!0;break e;case 4:Xn=H.stateNode.containerInfo,zi=!0;break e}H=H.return}if(Xn===null)throw Error(t(160));wM(T,j,I),Xn=null,zi=!1;var q=I.alternate;q!==null&&(q.return=null),I.return=null}catch(oe){pn(I,h,oe)}}if(h.subtreeFlags&12854)for(h=h.child;h!==null;)CM(h,u),h=h.sibling}function CM(u,h){var S=u.alternate,w=u.flags;switch(u.tag){case 0:case 11:case 14:case 15:if($i(h,u),xo(u),w&4){try{Gh(3,u,u.return),Vg(3,u)}catch(Fe){pn(u,u.return,Fe)}try{Gh(5,u,u.return)}catch(Fe){pn(u,u.return,Fe)}}break;case 1:$i(h,u),xo(u),w&512&&S!==null&&ed(S,S.return);break;case 5:if($i(h,u),xo(u),w&512&&S!==null&&ed(S,S.return),u.flags&32){var I=u.stateNode;try{ae(I,"")}catch(Fe){pn(u,u.return,Fe)}}if(w&4&&(I=u.stateNode,I!=null)){var T=u.memoizedProps,j=S!==null?S.memoizedProps:T,H=u.type,q=u.updateQueue;if(u.updateQueue=null,q!==null)try{H==="input"&&T.type==="radio"&&T.name!=null&&At(I,T),As(H,j);var oe=As(H,T);for(j=0;j<q.length;j+=2){var fe=q[j],me=q[j+1];fe==="style"?ni(I,me):fe==="dangerouslySetInnerHTML"?lc(I,me):fe==="children"?ae(I,me):E(I,fe,me,oe)}switch(H){case"input":Jr(I,T);break;case"textarea":Cu(I,T);break;case"select":var he=I._wrapperState.wasMultiple;I._wrapperState.wasMultiple=!!T.multiple;var Me=T.value;Me!=null?ti(I,!!T.multiple,Me,!1):he!==!!T.multiple&&(T.defaultValue!=null?ti(I,!!T.multiple,T.defaultValue,!0):ti(I,!!T.multiple,T.multiple?[]:"",!1))}I[Lh]=T}catch(Fe){pn(u,u.return,Fe)}}break;case 6:if($i(h,u),xo(u),w&4){if(u.stateNode===null)throw Error(t(162));I=u.stateNode,T=u.memoizedProps;try{I.nodeValue=T}catch(Fe){pn(u,u.return,Fe)}}break;case 3:if($i(h,u),xo(u),w&4&&S!==null&&S.memoizedState.isDehydrated)try{mc(h.containerInfo)}catch(Fe){pn(u,u.return,Fe)}break;case 4:$i(h,u),xo(u);break;case 13:$i(h,u),xo(u),I=u.child,I.flags&8192&&(T=I.memoizedState!==null,I.stateNode.isHidden=T,!T||I.alternate!==null&&I.alternate.memoizedState!==null||(aw=rn())),w&4&&bM(u);break;case 22:if(fe=S!==null&&S.memoizedState!==null,u.mode&1?(yr=(oe=yr)||fe,$i(h,u),yr=oe):$i(h,u),xo(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:Gh(4,he,he.return);break;case 1:ed(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){pn(w,S,Fe)}}break;case 5:ed(he,he.return);break;case 22:if(he.memoizedState!==null){IM(me);continue}}Me!==null?(Me.return=he,Oe=Me):IM(me)}fe=fe.sibling}e:for(fe=null,me=u;;){if(me.tag===5){if(fe===null){fe=me;try{I=me.stateNode,oe?(T=I.style,typeof T.setProperty=="function"?T.setProperty("display","none","important"):T.display="none"):(H=me.stateNode,q=me.memoizedProps.style,j=q!=null&&q.hasOwnProperty("display")?q.display:null,H.style.display=Ot("display",j))}catch(Fe){pn(u,u.return,Fe)}}}else if(me.tag===6){if(fe===null)try{me.stateNode.nodeValue=oe?"":me.memoizedProps}catch(Fe){pn(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:$i(h,u),xo(u),w&4&&bM(u);break;case 21:break;default:$i(h,u),xo(u)}}function xo(u){var h=u.flags;if(h&2){try{e:{for(var S=u.return;S!==null;){if(vM(S)){var w=S;break e}S=S.return}throw Error(t(160))}switch(w.tag){case 5:var I=w.stateNode;w.flags&32&&(ae(I,""),w.flags&=-33);var T=xM(u);sw(u,T,I);break;case 3:case 4:var j=w.stateNode.containerInfo,H=xM(u);rw(u,H,j);break;default:throw Error(t(161))}}catch(q){pn(u,u.return,q)}u.flags&=-3}h&4096&&(u.flags&=-4097)}function TW(u,h,S){Oe=u,PM(u)}function PM(u,h,S){for(var w=(u.mode&1)!==0;Oe!==null;){var I=Oe,T=I.child;if(I.tag===22&&w){var j=I.memoizedState!==null||Wg;if(!j){var H=I.alternate,q=H!==null&&H.memoizedState!==null||yr;H=Wg;var oe=yr;if(Wg=j,(yr=q)&&!oe)for(Oe=I;Oe!==null;)j=Oe,q=j.child,j.tag===22&&j.memoizedState!==null?EM(I):q!==null?(q.return=j,Oe=q):EM(I);for(;T!==null;)Oe=T,PM(T),T=T.sibling;Oe=I,Wg=H,yr=oe}kM(u)}else(I.subtreeFlags&8772)!==0&&T!==null?(T.return=I,Oe=T):kM(u)}}function kM(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:yr||Vg(5,h);break;case 1:var w=h.stateNode;if(h.flags&4&&!yr)if(S===null)w.componentDidMount();else{var I=h.elementType===h.type?S.memoizedProps:Fi(h.type,S.memoizedProps);w.componentDidUpdate(I,S.memoizedState,w.__reactInternalSnapshotBeforeUpdate)}var T=h.updateQueue;T!==null&&I2(h,T,w);break;case 3:var j=h.updateQueue;if(j!==null){if(S=null,h.child!==null)switch(h.child.tag){case 5:S=h.child.stateNode;break;case 1:S=h.child.stateNode}I2(h,j,S)}break;case 5:var H=h.stateNode;if(S===null&&h.flags&4){S=H;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&&mc(me)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(t(163))}yr||h.flags&512&&nw(h)}catch(he){pn(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 IM(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 EM(u){for(;Oe!==null;){var h=Oe;try{switch(h.tag){case 0:case 11:case 15:var S=h.return;try{Vg(4,h)}catch(q){pn(h,S,q)}break;case 1:var w=h.stateNode;if(typeof w.componentDidMount=="function"){var I=h.return;try{w.componentDidMount()}catch(q){pn(h,I,q)}}var T=h.return;try{nw(h)}catch(q){pn(h,T,q)}break;case 5:var j=h.return;try{nw(h)}catch(q){pn(h,j,q)}}}catch(q){pn(h,h.return,q)}if(h===u){Oe=null;break}var H=h.sibling;if(H!==null){H.return=h.return,Oe=H;break}Oe=h.return}}var MW=Math.ceil,qg=_.ReactCurrentDispatcher,iw=_.ReactCurrentOwner,ui=_.ReactCurrentBatchConfig,Ct=0,Fn=null,In=null,Zn=0,Ls=0,td=rl(0),On=0,Yh=null,Pc=0,Gg=0,ow=0,Xh=null,us=null,aw=0,nd=1/0,ua=null,Yg=!1,lw=null,cl=null,Xg=!1,ul=null,Zg=0,Zh=0,cw=null,Jg=-1,Qg=0;function Nr(){return(Ct&6)!==0?rn():Jg!==-1?Jg:Jg=rn()}function dl(u){return(u.mode&1)===0?1:(Ct&2)!==0&&Zn!==0?Zn&-Zn:fW.transition!==null?(Qg===0&&(Qg=ug()),Qg):(u=xt,u!==0||(u=window.event,u=u===void 0?16:Sn(u.type)),u)}function Bi(u,h,S,w){if(50<Zh)throw Zh=0,cw=null,Error(t(185));fc(u,S,w),((Ct&2)===0||u!==Fn)&&(u===Fn&&((Ct&2)===0&&(Gg|=S),On===4&&hl(u,Zn)),ds(u,w),S===1&&Ct===0&&(h.mode&1)===0&&(nd=rn()+500,Eg&&il()))}function ds(u,h){var S=u.callbackNode;Xv(u,h);var w=hc(u,u===Fn?Zn:0);if(w===0)S!==null&&uo(S),u.callbackNode=null,u.callbackPriority=0;else if(h=w&-w,u.callbackPriority!==h){if(S!=null&&uo(S),h===1)u.tag===0?hW(TM.bind(null,u)):p2(TM.bind(null,u)),lW(function(){(Ct&6)===0&&il()}),S=null;else{switch(na(w)){case 1:S=wh;break;case 4:S=dc;break;case 16:S=Mu;break;case 536870912:S=Oi;break;default:S=Mu}S=LM(S,_M.bind(null,u))}u.callbackPriority=h,u.callbackNode=S}}function _M(u,h){if(Jg=-1,Qg=0,(Ct&6)!==0)throw Error(t(327));var S=u.callbackNode;if(rd()&&u.callbackNode!==S)return null;var w=hc(u,u===Fn?Zn:0);if(w===0)return null;if((w&30)!==0||(w&u.expiredLanes)!==0||h)h=em(u,w);else{h=w;var I=Ct;Ct|=2;var T=AM();(Fn!==u||Zn!==h)&&(ua=null,nd=rn()+500,Ic(u,h));do try{RW();break}catch(H){MM(u,H)}while(!0);Ex(),qg.current=T,Ct=I,In!==null?h=0:(Fn=null,Zn=0,h=On)}if(h!==0){if(h===2&&(I=bh(u),I!==0&&(w=I,h=uw(u,I))),h===1)throw S=Yh,Ic(u,0),hl(u,w),ds(u,rn()),S;if(h===6)hl(u,w);else{if(I=u.current.alternate,(w&30)===0&&!AW(I)&&(h=em(u,w),h===2&&(T=bh(u),T!==0&&(w=T,h=uw(u,T))),h===1))throw S=Yh,Ic(u,0),hl(u,w),ds(u,rn()),S;switch(u.finishedWork=I,u.finishedLanes=w,h){case 0:case 1:throw Error(t(345));case 2:Ec(u,us,ua);break;case 3:if(hl(u,w),(w&130023424)===w&&(h=aw+500-rn(),10<h)){if(hc(u,0)!==0)break;if(I=u.suspendedLanes,(I&w)!==w){Nr(),u.pingedLanes|=u.suspendedLanes&I;break}u.timeoutHandle=mx(Ec.bind(null,u,us,ua),h);break}Ec(u,us,ua);break;case 4:if(hl(u,w),(w&4194240)===w)break;for(h=u.eventTimes,I=-1;0<w;){var j=31-Ds(w);T=1<<j,j=h[j],j>I&&(I=j),w&=~T}if(w=I,w=rn()-w,w=(120>w?120:480>w?480:1080>w?1080:1920>w?1920:3e3>w?3e3:4320>w?4320:1960*MW(w/1960))-w,10<w){u.timeoutHandle=mx(Ec.bind(null,u,us,ua),w);break}Ec(u,us,ua);break;case 5:Ec(u,us,ua);break;default:throw Error(t(329))}}}return ds(u,rn()),u.callbackNode===S?_M.bind(null,u):null}function uw(u,h){var S=Xh;return u.current.memoizedState.isDehydrated&&(Ic(u,h).flags|=256),u=em(u,h),u!==2&&(h=us,us=S,h!==null&&dw(h)),u}function dw(u){us===null?us=u:us.push.apply(us,u)}function AW(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 I=S[w],T=I.getSnapshot;I=I.value;try{if(!Ni(T(),I))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 hl(u,h){for(h&=~ow,h&=~Gg,u.suspendedLanes|=h,u.pingedLanes&=~h,u=u.expirationTimes;0<h;){var S=31-Ds(h),w=1<<S;u[S]=-1,h&=~w}}function TM(u){if((Ct&6)!==0)throw Error(t(327));rd();var h=hc(u,0);if((h&1)===0)return ds(u,rn()),null;var S=em(u,h);if(u.tag!==0&&S===2){var w=bh(u);w!==0&&(h=w,S=uw(u,w))}if(S===1)throw S=Yh,Ic(u,0),hl(u,h),ds(u,rn()),S;if(S===6)throw Error(t(345));return u.finishedWork=u.current.alternate,u.finishedLanes=h,Ec(u,us,ua),ds(u,rn()),null}function hw(u,h){var S=Ct;Ct|=1;try{return u(h)}finally{Ct=S,Ct===0&&(nd=rn()+500,Eg&&il())}}function kc(u){ul!==null&&ul.tag===0&&(Ct&6)===0&&rd();var h=Ct;Ct|=1;var S=ui.transition,w=xt;try{if(ui.transition=null,xt=1,u)return u()}finally{xt=w,ui.transition=S,Ct=h,(Ct&6)===0&&il()}}function fw(){Ls=td.current,qt(td)}function Ic(u,h){u.finishedWork=null,u.finishedLanes=0;var S=u.timeoutHandle;if(S!==-1&&(u.timeoutHandle=-1,aW(S)),In!==null)for(S=In.return;S!==null;){var w=S;switch(bx(w),w.tag){case 1:w=w.type.childContextTypes,w!=null&&kg();break;case 3:Ju(),qt(as),qt(pr),jx();break;case 5:Rx(w);break;case 4:Ju();break;case 13:qt(sn);break;case 19:qt(sn);break;case 10:_x(w.type._context);break;case 22:case 23:fw()}S=S.return}if(Fn=u,In=u=fl(u.current,null),Zn=Ls=h,On=0,Yh=null,ow=Gg=Pc=0,us=Xh=null,wc!==null){for(h=0;h<wc.length;h++)if(S=wc[h],w=S.interleaved,w!==null){S.interleaved=null;var I=w.next,T=S.pending;if(T!==null){var j=T.next;T.next=I,w.next=j}S.pending=w}wc=null}return u}function MM(u,h){do{var S=In;try{if(Ex(),Lg.current=Bg,Fg){for(var w=on.memoizedState;w!==null;){var I=w.queue;I!==null&&(I.pending=null),w=w.next}Fg=!1}if(Cc=0,Ln=An=on=null,Hh=!1,Kh=0,iw.current=null,S===null||S.return===null){On=1,Yh=h,In=null;break}e:{var T=u,j=S.return,H=S,q=h;if(h=Zn,H.flags|=32768,q!==null&&typeof q=="object"&&typeof q.then=="function"){var oe=q,fe=H,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=tM(j);if(Me!==null){Me.flags&=-257,nM(Me,j,H,T,h),Me.mode&1&&eM(T,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){eM(T,oe,h),pw();break e}q=Error(t(426))}}else if(en&&H.mode&1){var xn=tM(j);if(xn!==null){(xn.flags&65536)===0&&(xn.flags|=256),nM(xn,j,H,T,h),kx(Qu(q,H));break e}}T=q=Qu(q,H),On!==4&&(On=2),Xh===null?Xh=[T]:Xh.push(T),T=j;do{switch(T.tag){case 3:T.flags|=65536,h&=-h,T.lanes|=h;var ee=J2(T,q,h);k2(T,ee);break e;case 1:H=q;var X=T.type,se=T.stateNode;if((T.flags&128)===0&&(typeof X.getDerivedStateFromError=="function"||se!==null&&typeof se.componentDidCatch=="function"&&(cl===null||!cl.has(se)))){T.flags|=65536,h&=-h,T.lanes|=h;var xe=Q2(T,H,h);k2(T,xe);break e}}T=T.return}while(T!==null)}RM(S)}catch($e){h=$e,In===S&&S!==null&&(In=S=S.return);continue}break}while(!0)}function AM(){var u=qg.current;return qg.current=Bg,u===null?Bg:u}function pw(){(On===0||On===3||On===2)&&(On=4),Fn===null||(Pc&268435455)===0&&(Gg&268435455)===0||hl(Fn,Zn)}function em(u,h){var S=Ct;Ct|=2;var w=AM();(Fn!==u||Zn!==h)&&(ua=null,Ic(u,h));do try{OW();break}catch(I){MM(u,I)}while(!0);if(Ex(),Ct=S,qg.current=w,In!==null)throw Error(t(261));return Fn=null,Zn=0,On}function OW(){for(;In!==null;)OM(In)}function RW(){for(;In!==null&&!Uv();)OM(In)}function OM(u){var h=NM(u.alternate,u,Ls);u.memoizedProps=u.pendingProps,h===null?RM(u):In=h,iw.current=null}function RM(u){var h=u;do{var S=h.alternate;if(u=h.return,(h.flags&32768)===0){if(S=kW(S,h,Ls),S!==null){In=S;return}}else{if(S=IW(S,h),S!==null){S.flags&=32767,In=S;return}if(u!==null)u.flags|=32768,u.subtreeFlags=0,u.deletions=null;else{On=6,In=null;return}}if(h=h.sibling,h!==null){In=h;return}In=h=u}while(h!==null);On===0&&(On=5)}function Ec(u,h,S){var w=xt,I=ui.transition;try{ui.transition=null,xt=1,DW(u,h,S,w)}finally{ui.transition=I,xt=w}return null}function DW(u,h,S,w){do rd();while(ul!==null);if((Ct&6)!==0)throw Error(t(327));S=u.finishedWork;var I=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 T=S.lanes|S.childLanes;if(Zv(u,T),u===Fn&&(In=Fn=null,Zn=0),(S.subtreeFlags&2064)===0&&(S.flags&2064)===0||Xg||(Xg=!0,LM(Mu,function(){return rd(),null})),T=(S.flags&15990)!==0,(S.subtreeFlags&15990)!==0||T){T=ui.transition,ui.transition=null;var j=xt;xt=1;var H=Ct;Ct|=4,iw.current=null,_W(u,S),CM(S,u),eW(px),J=!!fx,px=fx=null,u.current=S,TW(S),Hv(),Ct=H,xt=j,ui.transition=T}else u.current=S;if(Xg&&(Xg=!1,ul=u,Zg=I),T=u.pendingLanes,T===0&&(cl=null),Vv(S.stateNode),ds(u,rn()),h!==null)for(w=u.onRecoverableError,S=0;S<h.length;S++)I=h[S],w(I.value,{componentStack:I.stack,digest:I.digest});if(Yg)throw Yg=!1,u=lw,lw=null,u;return(Zg&1)!==0&&u.tag!==0&&rd(),T=u.pendingLanes,(T&1)!==0?u===cw?Zh++:(Zh=0,cw=u):Zh=0,il(),null}function rd(){if(ul!==null){var u=na(Zg),h=ui.transition,S=xt;try{if(ui.transition=null,xt=16>u?16:u,ul===null)var w=!1;else{if(u=ul,ul=null,Zg=0,(Ct&6)!==0)throw Error(t(331));var I=Ct;for(Ct|=4,Oe=u.current;Oe!==null;){var T=Oe,j=T.child;if((Oe.flags&16)!==0){var H=T.deletions;if(H!==null){for(var q=0;q<H.length;q++){var oe=H[q];for(Oe=oe;Oe!==null;){var fe=Oe;switch(fe.tag){case 0:case 11:case 15:Gh(8,fe,T)}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(SM(fe),fe===oe){Oe=null;break}if(he!==null){he.return=Me,Oe=he;break}Oe=Me}}}var je=T.alternate;if(je!==null){var Fe=je.child;if(Fe!==null){je.child=null;do{var xn=Fe.sibling;Fe.sibling=null,Fe=xn}while(Fe!==null)}}Oe=T}}if((T.subtreeFlags&2064)!==0&&j!==null)j.return=T,Oe=j;else e:for(;Oe!==null;){if(T=Oe,(T.flags&2048)!==0)switch(T.tag){case 0:case 11:case 15:Gh(9,T,T.return)}var ee=T.sibling;if(ee!==null){ee.return=T.return,Oe=ee;break e}Oe=T.return}}var X=u.current;for(Oe=X;Oe!==null;){j=Oe;var se=j.child;if((j.subtreeFlags&2064)!==0&&se!==null)se.return=j,Oe=se;else e:for(j=X;Oe!==null;){if(H=Oe,(H.flags&2048)!==0)try{switch(H.tag){case 0:case 11:case 15:Vg(9,H)}}catch($e){pn(H,H.return,$e)}if(H===j){Oe=null;break e}var xe=H.sibling;if(xe!==null){xe.return=H.return,Oe=xe;break e}Oe=H.return}}if(Ct=I,il(),ii&&typeof ii.onPostCommitFiberRoot=="function")try{ii.onPostCommitFiberRoot(Au,u)}catch{}w=!0}return w}finally{xt=S,ui.transition=h}}return!1}function DM(u,h,S){h=Qu(S,h),h=J2(u,h,1),u=al(u,h,1),h=Nr(),u!==null&&(fc(u,1,h),ds(u,h))}function pn(u,h,S){if(u.tag===3)DM(u,u,S);else for(;h!==null;){if(h.tag===3){DM(h,u,S);break}else if(h.tag===1){var w=h.stateNode;if(typeof h.type.getDerivedStateFromError=="function"||typeof w.componentDidCatch=="function"&&(cl===null||!cl.has(w))){u=Qu(S,u),u=Q2(h,u,1),h=al(h,u,1),u=Nr(),h!==null&&(fc(h,1,u),ds(h,u));break}}h=h.return}}function jW(u,h,S){var w=u.pingCache;w!==null&&w.delete(h),h=Nr(),u.pingedLanes|=u.suspendedLanes&S,Fn===u&&(Zn&S)===S&&(On===4||On===3&&(Zn&130023424)===Zn&&500>rn()-aw?Ic(u,0):ow|=S),ds(u,h)}function jM(u,h){h===0&&((u.mode&1)===0?h=1:(h=ho,ho<<=1,(ho&130023424)===0&&(ho=4194304)));var S=Nr();u=aa(u,h),u!==null&&(fc(u,h,S),ds(u,S))}function NW(u){var h=u.memoizedState,S=0;h!==null&&(S=h.retryLane),jM(u,S)}function LW(u,h){var S=0;switch(u.tag){case 13:var w=u.stateNode,I=u.memoizedState;I!==null&&(S=I.retryLane);break;case 19:w=u.stateNode;break;default:throw Error(t(314))}w!==null&&w.delete(h),jM(u,S)}var NM;NM=function(u,h,S){if(u!==null)if(u.memoizedProps!==h.pendingProps||as.current)cs=!0;else{if((u.lanes&S)===0&&(h.flags&128)===0)return cs=!1,PW(u,h,S);cs=(u.flags&131072)!==0}else cs=!1,en&&(h.flags&1048576)!==0&&g2(h,Tg,h.index);switch(h.lanes=0,h.tag){case 2:var w=h.type;Kg(u,h),u=h.pendingProps;var I=Wu(h,pr.current);Zu(h,S),I=Fx(null,h,w,u,I,S);var T=zx();return h.flags|=1,typeof I=="object"&&I!==null&&typeof I.render=="function"&&I.$$typeof===void 0?(h.tag=1,h.memoizedState=null,h.updateQueue=null,ls(w)?(T=!0,Ig(h)):T=!1,h.memoizedState=I.state!==null&&I.state!==void 0?I.state:null,Ax(h),I.updater=Ug,h.stateNode=I,I._reactInternals=h,Wx(h,w,u,S),h=Yx(null,h,w,!0,T,S)):(h.tag=0,en&&T&&wx(h),jr(null,h,I,S),h=h.child),h;case 16:w=h.elementType;e:{switch(Kg(u,h),u=h.pendingProps,I=w._init,w=I(w._payload),h.type=w,I=h.tag=zW(w),u=Fi(w,u),I){case 0:h=Gx(null,h,w,u,S);break e;case 1:h=lM(null,h,w,u,S);break e;case 11:h=rM(null,h,w,u,S);break e;case 14:h=sM(null,h,w,Fi(w.type,u),S);break e}throw Error(t(306,w,""))}return h;case 0:return w=h.type,I=h.pendingProps,I=h.elementType===w?I:Fi(w,I),Gx(u,h,w,I,S);case 1:return w=h.type,I=h.pendingProps,I=h.elementType===w?I:Fi(w,I),lM(u,h,w,I,S);case 3:e:{if(cM(h),u===null)throw Error(t(387));w=h.pendingProps,T=h.memoizedState,I=T.element,P2(u,h),jg(h,w,null,S);var j=h.memoizedState;if(w=j.element,T.isDehydrated)if(T={element:w,isDehydrated:!1,cache:j.cache,pendingSuspenseBoundaries:j.pendingSuspenseBoundaries,transitions:j.transitions},h.updateQueue.baseState=T,h.memoizedState=T,h.flags&256){I=Qu(Error(t(423)),h),h=uM(u,h,w,S,I);break e}else if(w!==I){I=Qu(Error(t(424)),h),h=uM(u,h,w,S,I);break e}else for(Ns=nl(h.stateNode.containerInfo.firstChild),js=h,en=!0,Li=null,S=b2(h,null,w,S),h.child=S;S;)S.flags=S.flags&-3|4096,S=S.sibling;else{if(Gu(),w===I){h=ca(u,h,S);break e}jr(u,h,w,S)}h=h.child}return h;case 5:return E2(h),u===null&&Px(h),w=h.type,I=h.pendingProps,T=u!==null?u.memoizedProps:null,j=I.children,gx(w,I)?j=null:T!==null&&gx(w,T)&&(h.flags|=32),aM(u,h),jr(u,h,j,S),h.child;case 6:return u===null&&Px(h),null;case 13:return dM(u,h,S);case 4:return Ox(h,h.stateNode.containerInfo),w=h.pendingProps,u===null?h.child=Yu(h,null,w,S):jr(u,h,w,S),h.child;case 11:return w=h.type,I=h.pendingProps,I=h.elementType===w?I:Fi(w,I),rM(u,h,w,I,S);case 7:return jr(u,h,h.pendingProps,S),h.child;case 8:return jr(u,h,h.pendingProps.children,S),h.child;case 12:return jr(u,h,h.pendingProps.children,S),h.child;case 10:e:{if(w=h.type._context,I=h.pendingProps,T=h.memoizedProps,j=I.value,Ut(Og,w._currentValue),w._currentValue=j,T!==null)if(Ni(T.value,j)){if(T.children===I.children&&!as.current){h=ca(u,h,S);break e}}else for(T=h.child,T!==null&&(T.return=h);T!==null;){var H=T.dependencies;if(H!==null){j=T.child;for(var q=H.firstContext;q!==null;){if(q.context===w){if(T.tag===1){q=la(-1,S&-S),q.tag=2;var oe=T.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}}T.lanes|=S,q=T.alternate,q!==null&&(q.lanes|=S),Tx(T.return,S,h),H.lanes|=S;break}q=q.next}}else if(T.tag===10)j=T.type===h.type?null:T.child;else if(T.tag===18){if(j=T.return,j===null)throw Error(t(341));j.lanes|=S,H=j.alternate,H!==null&&(H.lanes|=S),Tx(j,S,h),j=T.sibling}else j=T.child;if(j!==null)j.return=T;else for(j=T;j!==null;){if(j===h){j=null;break}if(T=j.sibling,T!==null){T.return=j.return,j=T;break}j=j.return}T=j}jr(u,h,I.children,S),h=h.child}return h;case 9:return I=h.type,w=h.pendingProps.children,Zu(h,S),I=li(I),w=w(I),h.flags|=1,jr(u,h,w,S),h.child;case 14:return w=h.type,I=Fi(w,h.pendingProps),I=Fi(w.type,I),sM(u,h,w,I,S);case 15:return iM(u,h,h.type,h.pendingProps,S);case 17:return w=h.type,I=h.pendingProps,I=h.elementType===w?I:Fi(w,I),Kg(u,h),h.tag=1,ls(w)?(u=!0,Ig(h)):u=!1,Zu(h,S),X2(h,w,I),Wx(h,w,I,S),Yx(null,h,w,!0,u,S);case 19:return fM(u,h,S);case 22:return oM(u,h,S)}throw Error(t(156,h.tag))};function LM(u,h){return cg(u,h)}function FW(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 di(u,h,S,w){return new FW(u,h,S,w)}function gw(u){return u=u.prototype,!(!u||!u.isReactComponent)}function zW(u){if(typeof u=="function")return gw(u)?1:0;if(u!=null){if(u=u.$$typeof,u===z)return 11;if(u===V)return 14}return 2}function fl(u,h){var S=u.alternate;return S===null?(S=di(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 tm(u,h,S,w,I,T){var j=2;if(w=u,typeof u=="function")gw(u)&&(j=1);else if(typeof u=="string")j=5;else e:switch(u){case O:return _c(S.children,I,T,h);case D:j=8,I|=8;break;case B:return u=di(12,S,h,I|2),u.elementType=B,u.lanes=T,u;case N:return u=di(13,S,h,I),u.elementType=N,u.lanes=T,u;case L:return u=di(19,S,h,I),u.elementType=L,u.lanes=T,u;case W:return nm(S,I,T,h);default:if(typeof u=="object"&&u!==null)switch(u.$$typeof){case U:j=10;break e;case G:j=9;break e;case z:j=11;break e;case V:j=14;break e;case Z:j=16,w=null;break e}throw Error(t(130,u==null?u:typeof u,""))}return h=di(j,S,h,I),h.elementType=u,h.type=w,h.lanes=T,h}function _c(u,h,S,w){return u=di(7,u,w,h),u.lanes=S,u}function nm(u,h,S,w){return u=di(22,u,w,h),u.elementType=W,u.lanes=S,u.stateNode={isHidden:!1},u}function mw(u,h,S){return u=di(6,u,null,h),u.lanes=S,u}function yw(u,h,S){return h=di(4,u.children!==null?u.children:[],u.key,h),h.lanes=S,h.stateNode={containerInfo:u.containerInfo,pendingChildren:null,implementation:u.implementation},h}function $W(u,h,S,w,I){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=Du(0),this.expirationTimes=Du(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Du(0),this.identifierPrefix=w,this.onRecoverableError=I,this.mutableSourceEagerHydrationData=null}function Sw(u,h,S,w,I,T,j,H,q){return u=new $W(u,h,S,H,q),h===1?(h=1,T===!0&&(h|=8)):h=0,T=di(3,null,null,h),u.current=T,T.stateNode=u,T.memoizedState={element:w,isDehydrated:S,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ax(T),u}function BW(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 FM(u){if(!u)return sl;u=u._reactInternals;e:{if(ta(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(ls(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(ls(S))return h2(u,S,h)}return h}function zM(u,h,S,w,I,T,j,H,q){return u=Sw(S,w,!0,u,I,T,j,H,q),u.context=FM(null),S=u.current,w=Nr(),I=dl(S),T=la(w,I),T.callback=h??null,al(S,T,I),u.current.lanes=I,fc(u,I,w),ds(u,w),u}function rm(u,h,S,w){var I=h.current,T=Nr(),j=dl(I);return S=FM(S),h.context===null?h.context=S:h.pendingContext=S,h=la(T,j),h.payload={element:u},w=w===void 0?null:w,w!==null&&(h.callback=w),u=al(I,h,j),u!==null&&(Bi(u,I,j,T),Dg(u,I,j)),j}function sm(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 $M(u,h){if(u=u.memoizedState,u!==null&&u.dehydrated!==null){var S=u.retryLane;u.retryLane=S!==0&&S<h?S:h}}function vw(u,h){$M(u,h),(u=u.alternate)&&$M(u,h)}function UW(){return null}var BM=typeof reportError=="function"?reportError:function(u){console.error(u)};function xw(u){this._internalRoot=u}im.prototype.render=xw.prototype.render=function(u){var h=this._internalRoot;if(h===null)throw Error(t(409));rm(u,h,null,null)},im.prototype.unmount=xw.prototype.unmount=function(){var u=this._internalRoot;if(u!==null){this._internalRoot=null;var h=u.containerInfo;kc(function(){rm(null,u,null,null)}),h[ra]=null}};function im(u){this._internalRoot=u}im.prototype.unstable_scheduleHydration=function(u){if(u){var h=hg();u={blockedOn:null,target:u,priority:h};for(var S=0;S<go.length&&h!==0&&h<go[S].priority;S++);go.splice(S,0,u),S===0&&Ih(u)}};function ww(u){return!(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11)}function om(u){return!(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11&&(u.nodeType!==8||u.nodeValue!==" react-mount-point-unstable "))}function UM(){}function HW(u,h,S,w,I){if(I){if(typeof w=="function"){var T=w;w=function(){var oe=sm(j);T.call(oe)}}var j=zM(h,w,u,0,null,!1,!1,"",UM);return u._reactRootContainer=j,u[ra]=j.current,jh(u.nodeType===8?u.parentNode:u),kc(),j}for(;I=u.lastChild;)u.removeChild(I);if(typeof w=="function"){var H=w;w=function(){var oe=sm(q);H.call(oe)}}var q=Sw(u,0,!1,null,null,!1,!1,"",UM);return u._reactRootContainer=q,u[ra]=q.current,jh(u.nodeType===8?u.parentNode:u),kc(function(){rm(h,q,S,w)}),q}function am(u,h,S,w,I){var T=S._reactRootContainer;if(T){var j=T;if(typeof I=="function"){var H=I;I=function(){var q=sm(j);H.call(q)}}rm(h,j,u,I)}else j=HW(S,h,u,I,w);return sm(j)}dg=function(u){switch(u.tag){case 3:var h=u.stateNode;if(h.current.memoizedState.isDehydrated){var S=Za(h.pendingLanes);S!==0&&(ju(h,S|1),ds(h,rn()),(Ct&6)===0&&(nd=rn()+500,il()))}break;case 13:kc(function(){var w=aa(u,1);if(w!==null){var I=Nr();Bi(w,u,1,I)}}),vw(u,1)}},Ch=function(u){if(u.tag===13){var h=aa(u,134217728);if(h!==null){var S=Nr();Bi(h,u,134217728,S)}vw(u,134217728)}},Ri=function(u){if(u.tag===13){var h=dl(u),S=aa(u,h);if(S!==null){var w=Nr();Bi(S,u,h,w)}vw(u,h)}},hg=function(){return xt},fg=function(u,h){var S=xt;try{return xt=u,h()}finally{xt=S}},Rs=function(u,h,S){switch(h){case"input":if(Jr(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 I=Pg(w);if(!I)throw Error(t(90));hn(w),Jr(w,I)}}}break;case"textarea":Cu(u,S);break;case"select":h=S.value,h!=null&&ti(u,!!S.multiple,h,!1)}},_u=hw,Tu=kc;var KW={usingClientEntryPoint:!1,Events:[Fh,Hu,Pg,Ga,Eu,hw]},Jh={findFiberByHostInstance:yc,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},WW={bundleType:Jh.bundleType,version:Jh.version,rendererPackageName:Jh.rendererPackageName,rendererConfig:Jh.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=ag(u),u===null?null:u.stateNode},findFiberByHostInstance:Jh.findFiberByHostInstance||UW,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 lm=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!lm.isDisabled&&lm.supportsFiber)try{Au=lm.inject(WW),ii=lm}catch{}}return hs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=KW,hs.createPortal=function(u,h){var S=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!ww(h))throw Error(t(200));return BW(u,h,null,S)},hs.createRoot=function(u,h){if(!ww(u))throw Error(t(299));var S=!1,w="",I=BM;return h!=null&&(h.unstable_strictMode===!0&&(S=!0),h.identifierPrefix!==void 0&&(w=h.identifierPrefix),h.onRecoverableError!==void 0&&(I=h.onRecoverableError)),h=Sw(u,1,!1,null,null,S,!1,w,I),u[ra]=h.current,jh(u.nodeType===8?u.parentNode:u),new xw(h)},hs.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=ag(h),u=u===null?null:u.stateNode,u},hs.flushSync=function(u){return kc(u)},hs.hydrate=function(u,h,S){if(!om(h))throw Error(t(200));return am(null,u,h,!0,S)},hs.hydrateRoot=function(u,h,S){if(!ww(u))throw Error(t(405));var w=S!=null&&S.hydratedSources||null,I=!1,T="",j=BM;if(S!=null&&(S.unstable_strictMode===!0&&(I=!0),S.identifierPrefix!==void 0&&(T=S.identifierPrefix),S.onRecoverableError!==void 0&&(j=S.onRecoverableError)),h=zM(h,null,u,1,S??null,I,!1,T,j),u[ra]=h.current,jh(u),w)for(u=0;u<w.length;u++)S=w[u],I=S._getVersion,I=I(S._source),h.mutableSourceEagerHydrationData==null?h.mutableSourceEagerHydrationData=[S,I]:h.mutableSourceEagerHydrationData.push(S,I);return new im(h)},hs.render=function(u,h,S){if(!om(h))throw Error(t(200));return am(null,u,h,!1,S)},hs.unmountComponentAtNode=function(u){if(!om(u))throw Error(t(40));return u._reactRootContainer?(kc(function(){am(null,null,u,!1,function(){u._reactRootContainer=null,u[ra]=null})}),!0):!1},hs.unstable_batchedUpdates=hw,hs.unstable_renderSubtreeIntoContainer=function(u,h,S,w){if(!om(S))throw Error(t(200));if(u==null||u._reactInternals===void 0)throw Error(t(38));return am(u,h,S,!1,w)},hs.version="18.3.1-next-f1338f8080-20240426",hs}var XM;function FL(){if(XM)return Pw.exports;XM=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(),Pw.exports=nV(),Pw.exports}var ZM;function rV(){if(ZM)return cm;ZM=1;var n=FL();return cm.createRoot=n.createRoot,cm.hydrateRoot=n.hydrateRoot,cm}var zL=rV();const sV=$a(zL);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 iV(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 Ew="__TLDRAW_LIBRARY_VERSIONS__";function oV(){if(globalThis[Ew])return globalThis[Ew];const n={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,Ew,{value:n,writable:!1,configurable:!1,enumerable:!1}),n}function Yl(n,e,t){if(!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=oV();if(r.versions.push({name:n,version:e,modules:t}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,JM(r)},100)}catch{JM(r)}}function JM(n){if(!n.versions.length||n.didWarn)return;const e=n.versions.sort((a,l)=>QM(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),_w(s,a.name,new Set).add(a.version);continue}a.version===t?r.add(a.name):(r.delete(a.name),_w(s,a.name,new Set).add(a.version))}if(s.size>0){const a=[`${da("[tldraw]",["bold","bgRed","textWhite"])} ${da("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 ${da(`v${t}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${da(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(QM).map(f=>da(`v${f}`,f===t?["textGreen"]:["textRed"]));return` • ❌ ${da(l,["bold"])} (${d.join(", ")})`})];console.log(a.join(`
41
+ `)),n.didWarn=!0;return}const i=new Map;for(const a of e)_w(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=[`${da("[tldraw]",["bold","bgRed","textWhite"])} ${da("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,g)=>f==="esm"?` ${g+1}. ES Modules`:` ${g+1}. CommonJS`).join(`
42
+ `);return` • ❌ ${da(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 QM(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 aV={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function da(n,e=[]){return`\x1B[${e.map(t=>aV[t]).join(";")}m${n}\x1B[m`}function _w(n,e,t){return n.has(e)?n.get(e):(n.set(e,t),t)}var Tw,eA;function lV(){if(eA)return Tw;eA=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 ws=="object"&&ws&&ws.Object===Object&&ws,c=typeof self=="object"&&self&&self.Object===Object&&self,d=l||c||Function("return this")(),f=Object.prototype,g=f.toString,m=Math.max,y=Math.min,v=function(){return d.Date.now()};function x(A,O,D){var B,U,G,z,N,L,V=0,Z=!1,W=!1,$=!0;if(typeof A!="function")throw new TypeError(n);O=M(O)||0,C(D)&&(Z=!!D.leading,W="maxWait"in D,G=W?m(M(D.maxWait)||0,O):G,$="trailing"in D?!!D.trailing:$);function Y(Ce){var _e=B,We=U;return B=U=void 0,V=Ce,z=A.apply(We,_e),z}function re(Ce){return V=Ce,N=setTimeout(ge,O),Z?Y(Ce):z}function K(Ce){var _e=Ce-L,We=Ce-V,st=O-_e;return W?y(st,G-We):st}function ne(Ce){var _e=Ce-L,We=Ce-V;return L===void 0||_e>=O||_e<0||W&&We>=G}function ge(){var Ce=v();if(ne(Ce))return Pe(Ce);N=setTimeout(ge,K(Ce))}function Pe(Ce){return N=void 0,$&&B?Y(Ce):(B=U=void 0,z)}function ce(){N!==void 0&&clearTimeout(N),V=0,B=L=U=N=void 0}function Be(){return N===void 0?z:Pe(v())}function Re(){var Ce=v(),_e=ne(Ce);if(B=arguments,U=this,L=Ce,_e){if(N===void 0)return re(L);if(W)return N=setTimeout(ge,O),Y(L)}return N===void 0&&(N=setTimeout(ge,O)),z}return Re.cancel=ce,Re.flush=Be,Re}function b(A,O,D){var B=!0,U=!0;if(typeof A!="function")throw new TypeError(n);return C(D)&&(B="leading"in D?!!D.leading:B,U="trailing"in D?!!D.trailing:U),x(A,O,{leading:B,maxWait:O,trailing:U})}function C(A){var O=typeof A;return!!A&&(O=="object"||O=="function")}function E(A){return!!A&&typeof A=="object"}function _(A){return typeof A=="symbol"||E(A)&&g.call(A)==t}function M(A){if(typeof A=="number")return A;if(_(A))return e;if(C(A)){var O=typeof A.valueOf=="function"?A.valueOf():A;A=C(O)?O+"":O}if(typeof A!="string")return A===0?A:+A;A=A.replace(r,"");var D=i.test(A);return D||o.test(A)?a(A.slice(2),D?2:8):s.test(A)?e:+A}return Tw=b,Tw}var cV=lV();const $L=$a(cV);var Mw,tA;function uV(){if(tA)return Mw;tA=1;var n=200,e="__lodash_hash_undefined__",t=1/0,r="[object Function]",s="[object GeneratorFunction]",i=/[\\^$.*+?()[\]{}|]/g,o=/^\[object .+?Constructor\]$/,a=typeof ws=="object"&&ws&&ws.Object===Object&&ws,l=typeof self=="object"&&self&&self.Object===Object&&self,c=a||l||Function("return this")();function d(ae,be){var Ye=ae?ae.length:0;return!!Ye&&g(ae,be,0)>-1}function f(ae,be,Ye,Ot){for(var ni=ae.length,ns=Ye+-1;++ns<ni;)if(be(ae[ns],ns,ae))return ns;return-1}function g(ae,be,Ye){if(be!==be)return f(ae,m,Ye);for(var Ot=Ye-1,ni=ae.length;++Ot<ni;)if(ae[Ot]===be)return Ot;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,Ye=Array(ae.size);return ae.forEach(function(Ot){Ye[++be]=Ot}),Ye}var C=Array.prototype,E=Function.prototype,_=Object.prototype,M=c["__core-js_shared__"],A=function(){var ae=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||"");return ae?"Symbol(src)_1."+ae:""}(),O=E.toString,D=_.hasOwnProperty,B=_.toString,U=RegExp("^"+O.call(D).replace(i,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),G=C.splice,z=ti(c,"Map"),N=ti(c,"Set"),L=ti(Object,"create");function V(ae){var be=-1,Ye=ae?ae.length:0;for(this.clear();++be<Ye;){var Ot=ae[be];this.set(Ot[0],Ot[1])}}function Z(){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 Ye=be[ae];return Ye===e?void 0:Ye}return D.call(be,ae)?be[ae]:void 0}function Y(ae){var be=this.__data__;return L?be[ae]!==void 0:D.call(be,ae)}function re(ae,be){var Ye=this.__data__;return Ye[ae]=L&&be===void 0?e:be,this}V.prototype.clear=Z,V.prototype.delete=W,V.prototype.get=$,V.prototype.has=Y,V.prototype.set=re;function K(ae){var be=-1,Ye=ae?ae.length:0;for(this.clear();++be<Ye;){var Ot=ae[be];this.set(Ot[0],Ot[1])}}function ne(){this.__data__=[]}function ge(ae){var be=this.__data__,Ye=At(be,ae);if(Ye<0)return!1;var Ot=be.length-1;return Ye==Ot?be.pop():G.call(be,Ye,1),!0}function Pe(ae){var be=this.__data__,Ye=At(be,ae);return Ye<0?void 0:be[Ye][1]}function ce(ae){return At(this.__data__,ae)>-1}function Be(ae,be){var Ye=this.__data__,Ot=At(Ye,ae);return Ot<0?Ye.push([ae,be]):Ye[Ot][1]=be,this}K.prototype.clear=ne,K.prototype.delete=ge,K.prototype.get=Pe,K.prototype.has=ce,K.prototype.set=Be;function Re(ae){var be=-1,Ye=ae?ae.length:0;for(this.clear();++be<Ye;){var Ot=ae[be];this.set(Ot[0],Ot[1])}}function Ce(){this.__data__={hash:new V,map:new(z||K),string:new V}}function _e(ae){return ts(this,ae).delete(ae)}function We(ae){return ts(this,ae).get(ae)}function st(ae){return ts(this,ae).has(ae)}function hn(ae,be){return ts(this,ae).set(ae,be),this}Re.prototype.clear=Ce,Re.prototype.delete=_e,Re.prototype.get=We,Re.prototype.has=st,Re.prototype.set=hn;function _t(ae){var be=-1,Ye=ae?ae.length:0;for(this.__data__=new Re;++be<Ye;)this.add(ae[be])}function Qt(ae){return this.__data__.set(ae,e),this}function Nt(ae){return this.__data__.has(ae)}_t.prototype.add=_t.prototype.push=Qt,_t.prototype.has=Nt;function At(ae,be){for(var Ye=ae.length;Ye--;)if(ku(ae[Ye][0],be))return Ye;return-1}function Jr(ae){if(!Mi(ae)||bu(ae))return!1;var be=co(ae)||x(ae)?U:o;return be.test(Cu(ae))}function Qr(ae,be,Ye){var Ot=-1,ni=d,ns=ae.length,Qo=!0,As=[],Os=As;if(ns>=n){var rs=es(ae);if(rs)return b(rs);Qo=!1,ni=y,Os=new _t}else Os=As;e:for(;++Ot<ns;){var Rs=ae[Ot],ss=Rs;if(Rs=Rs!==0?Rs:0,Qo&&ss===ss){for(var Ai=Os.length;Ai--;)if(Os[Ai]===ss)continue e;As.push(Rs)}else ni(Os,ss,Ye)||(Os!==As&&Os.push(ss),As.push(Rs))}return As}var es=N&&1/b(new N([,-0]))[1]==t?function(ae){return new N(ae)}:lc;function ts(ae,be){var Ye=ae.__data__;return ac(be)?Ye[typeof be=="string"?"string":"hash"]:Ye.map}function ti(ae,be){var Ye=v(ae,be);return Jr(Ye)?Ye:void 0}function ac(ae){var be=typeof ae;return be=="string"||be=="number"||be=="symbol"||be=="boolean"?ae!=="__proto__":ae===null}function bu(ae){return!!A&&A in ae}function Cu(ae){if(ae!=null){try{return O.call(ae)}catch{}try{return ae+""}catch{}}return""}function Pu(ae){return ae&&ae.length?Qr(ae):[]}function ku(ae,be){return ae===be||ae!==ae&&be!==be}function co(ae){var be=Mi(ae)?B.call(ae):"";return be==r||be==s}function Mi(ae){var be=typeof ae;return!!ae&&(be=="object"||be=="function")}function lc(){}return Mw=Pu,Mw}var dV=uV();const hV=$a(dV);function BL(n){const e=(...t)=>{try{return n(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Zf=()=>{},Lr={ok(n){return{ok:!0,value:n}},err(n){return{ok:!1,error:n}}};function _n(n,e){const t=e&&n&&typeof n=="object"&&e in n?n[e]:n;throw new Error(`Unknown switch case ${t}`)}const tt=BL((n,e)=>{if(!n)throw new Error(e||"Assertion Error")}),Fr=BL((n,e)=>{if(n==null)throw new Error(e??"value must be defined");return n});function hI(){let n,e;const t=new Promise((r,s)=>{n=r,e=s});return Object.assign(t,{resolve:n,reject:e})}function bP(n){return new Promise(e=>setTimeout(e,n))}const yf={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},fV=yf.Good;class UL{constructor(){R(this,"startTime",0);R(this,"name","");R(this,"frames",0);R(this,"started",!1);R(this,"frame",null);R(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?yf.Good:t>30?yf.Mid:yf.Poor,s=r===yf.Mid?"black":"white",i=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${i} %c${t}%c fps`,`color: white; background: ${fV};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 fI(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 rt(n){return n.filter(e=>e!=null)}function er(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 gV(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 zy(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 Aw(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 bs(...n){if(n.length===2){const[e,t]=n;t.addInitializer(function(){tt(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});tt(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 qo{constructor(){R(this,"items",new WeakMap)}get(e,t){return this.items.has(e)||this.items.set(e,t(e)),this.items.get(e)}}function f0(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 nA=new WeakMap;function pI(n,e){if(typeof n!="object"||n===null)return;let t=nA.get(n);t||(t={tags:{},extras:{}},nA.set(n,t)),e.tags&&(t.tags={...t.tags,...e.tags}),e.extras&&(t.extras={...t.extras,...e.extras})}async function Gi(n,e){return window.fetch(n,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Jf=(n,e)=>{const t=new window.Image(n,e);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Ur{static async dataUrlToArrayBuffer(e){return Gi(e).then(function(t){return t.arrayBuffer()})}static async urlToArrayBuffer(e){return await(await Gi(e)).arrayBuffer()}static async urlToBlob(e){return await(await Gi(e)).blob()}static async urlToDataUrl(e){if(e.startsWith("data:"))return e;const t=await Ur.urlToBlob(e);return await Ur.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 gI(n){let e=0;for(let t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e|=0;return e+""}function HL(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 rA=globalThis.crypto,mV="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",yV=128;let Ac,wd;function SV(n){!Ac||Ac.length<n?(Ac=new Uint8Array(n*yV),rA.getRandomValues(Ac),wd=0):wd+n>Ac.length&&(rA.getRandomValues(Ac),wd=0),wd+=n}function vV(n=21){SV(n-=0);let e="";for(let t=wd-n;t<wd;t++)e+=mV[Ac[t]&63];return e}let xV=vV;function Tt(n){return xV(n)}/*!
57
+ * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
58
+ * Copyright (c) Philip van Heemstra
59
+ */function wV(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,g=i.length;if(typeof l>"u"&&(l=g),a>=g||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),E=f.decode(C,{stream:!0}),_=x+E;let M,A=-1;for(;(M=o.exec(_))!==null;){A=M.index-x.length,m=v+A;break e}y=b,v+=E.length;const O=A>-1?A+d:E.length-d;x=E.slice(O)}return m>=0&&(m+=a>=0?a:g+a),m}const s=r(e,"IDAT",12);return s>=12?r(e,"acTL",8,s)>=8:!1}const bV=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 sA(n,e){let t=0;for(;n[e+t];)t+=n[e+t]+1;return t+1}function CV(n){return new TextDecoder("ascii").decode(n.slice(0,3))==="GIF"}function PV(n){const e=new Uint8Array(n);let t,r,s=0,i=0;if(!CV(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+=sA(e,s+1)+1;break;case 33:s+=2,s+=sA(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 CP=[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"&&(CP=new Int32Array(CP));const kV=(n,e)=>{let t=-1;for(let r=0;r<n.length;r++)t=CP[(t^n[r])&255]^t>>>8;return t^-1},iA=4,oA=4;class Mo{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(!Mo.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=Mo.getChunkType(e,t);if(o==="IDAT"&&r[o]){t+=i+iA+oA;continue}if(o==="IEND")break;r[o]={start:s,dataOffset:t+4,size:i},t+=i+iA+oA}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 Mo.readChunks(e)[t]}static setPhysChunk(e,t=1,r){let s=46,i=0;const o=Mo.findChunk(e,"pHYs");o&&(s=o.start,i=o.size);const a=Mo.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,kV(f));const g=e.buffer.slice(0,s),m=e.buffer.slice(s+i);return new Blob([g,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 IV(n){return!n||n.length<12?!1:n[8]===87&&n[9]===69&&n[10]===66&&n[11]===80}function EV(n){const e=new Uint8Array(n);return!IV(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const KL=Object.freeze(["image/svg+xml"]),WL=Object.freeze(["image/jpeg","image/png","image/webp"]),VL=Object.freeze(["image/gif","image/apng","image/avif"]),kp=Object.freeze([...WL,...KL,...VL]),p0=Object.freeze(["video/mp4","video/webm","video/quicktime"]),_V=[...kp,...p0].join(",");class Us{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=hI();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=Jf();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 Us.usingObjectURL(e,async t=>{const r=await Us.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const t=await Us.usingObjectURL(e,Us.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(Mo.isPng(r,0)){const s=Mo.findChunk(r,"pHYs");if(s){const i=Mo.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"?PV(await e.arrayBuffer()):e.type==="image/avif"?bV(await e.arrayBuffer()):e.type==="image/webp"?EV(await e.arrayBuffer()):e.type==="image/apng"?wV(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return VL.includes(e||"")}static isStaticImageType(e){return WL.includes(e||"")}static isVectorImageType(e){return KL.includes(e||"")}static isImageType(e){return kp.includes(e)}static async usingObjectURL(e,t){const r=URL.createObjectURL(e);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function St(n,e,t){return n+(e-n)*t}function ro(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 Fd(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 wi(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function Cn(n,e){if(wi(n,e))return n[e]}function TV(n){return Object.keys(n)}function mn(n){return Object.values(n)}function Cs(n){return Object.entries(n)}function qL(n){return Object.fromEntries(n)}function Of(n,e){const t={};let r=!1;for(const[s,i]of Cs(n))e(s,i)?t[s]=i:r=!0;return r?t:n}function rh(n,e){const t={};for(const[r,s]of Cs(n)){const i=e(r,s);t[r]=i}return t}function GL(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 MV(n){const e=AV(n.chars),t=OV(e,n.firstPositive,n.mostPositive,n.mostNegative),r=n.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=RV(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 AV(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 OV(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 RV(n,e){const t={};for(let r=0;r<100&&(t[r]=Math.pow(e,r),!(t[r]>n));r++);return t}var Ow=null;function mI(){return Ow||(Ow=MV({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Ml(n,e,t){const r=t.byChar[n],s=t.byChar[e];return Math.abs(r-s)}function yI(n,e){const t=n[0];if(t>e.mostPositive||t<e.mostNegative)throw new Error("invalid firstChar on key");return t===e.mostPositive?Ml(t,e.firstPositive,e)+1+$y(n.slice(1),"positive",e):t===e.mostNegative?Ml(t,e.firstNegative,e)+1+$y(n.slice(1),"negative",e):t>=e.firstPositive?Ml(t,e.firstPositive,e)+2:Ml(t,e.firstNegative,e)+2}function $y(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"?Ml(r,t.mostNegative,t)+1+$y(n.slice(1),e,t):r===t.mostNegative&&e==="negative"?Ml(r,t.mostPositive,t)+1+$y(n.slice(1),e,t):e==="positive"?Ml(r,t.mostNegative,t)+2:Ml(r,t.mostPositive,t)+2}function g0(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 DV(n,e,t){let[r,s]=g0(n,e,"end",t.first),i=PP(r,s,t);i===1&&(r=r.padEnd(r.length+1,t.first),i=t.length);const o=ZL(Math.floor(i/2),t);return SI(r,o,t)}function PP(n,e,t){const[r,s]=g0(n,e,"end",t.first).sort(),i=YL(s,r,t);return jV(i,t)}function SI(n,e,t){const r=t.length,[s,i]=g0(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 g=f%r;o.unshift(t.byCode[g])}return a>0&&o.unshift(t.byCode[a]),o.join("")}function YL(n,e,t){const r=t.length,[s,i]=g0(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 XL(n,e){return SI(n,e.byCode[1],e)}function kP(n,e){return YL(n,e.byCode[1],e)}function ZL(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 jV(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 NV(n){return n.firstPositive+n.byCode[0]}function LV(n,e){return yI(n,e)===n.length}function aA(n,e){By(n,e)}function By(n,e){const t=e3(n,e),r=yI(t,e);if(r>n.length)throw new Error("invalid order key length: "+n);return n.slice(0,r)}function JL(n,e){if(!LV(n,e))throw new Error("invalid integer length: "+n)}function QL(n,e){JL(n,e);const[t,r]=t3(n,e);if(r.split("").some(o=>o!==e.byCode[e.length-1])){const o=XL(r,e);return t+o}const i=zV(t,e);return n3(i,"lower",e)}function FV(n,e){JL(n,e);const[t,r]=t3(n,e);if(r.split("").some(o=>o!==e.byCode[0])){const o=kP(r,e);return t+o}const i=$V(t,e);return n3(i,"upper",e)}function e3(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 t3(n,e){const t=e3(n,e),r=n.slice(t.length);return[t,r]}function zV(n,e){const t=n>=e.firstPositive,r=XL(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 $V(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 kP(s,e)}return!t&&r?n+e.mostPositive:kP(n,e)}function n3(n,e,t){const r=yI(n,t),s=e==="upper"?t.byCode[t.length-1]:t.byCode[0];return n+s.repeat(r-n.length)}function r3(n,e){const t=ZL(Math.floor(Math.random()*e.jitterRange),e);return SI(n,t,e)}function BV(n,e,t){const r=n.padEnd(n.length+e,t.first);return r3(r,t)}function UV(n,e,t){const r=By(n,t),s=QL(r,t);let i=0;if(e!==null){const a=PP(n,e,t);a<t.jitterRange+1&&(i=Math.max(i,lA(a,t)))}const o=PP(n,s,t);return o<t.jitterRange+1&&(i=Math.max(i,lA(o,t))),i}function lA(n,e){const t=e.jitterRange-n,r=Object.entries(e.paddingDict).find(([s,i])=>i>t);return r?parseInt(r[0]):0}function HV(n,e,t=mI()){if(n!==null&&aA(n,t),e!==null&&aA(e,t),n===null&&e===null)return NV(t);if(n===null){const r=By(e,t);return FV(r,t)}if(e===null){const r=By(n,t);return QL(r,t)}if(n>=e)throw new Error(n+" >= "+e);return DV(n,e,t)}function s3(n,e,t=mI()){const r=HV(n,e,t),s=UV(r,e,t);return s?BV(r,s,t):r3(r,t)}function i3(n,e,t,r=mI()){return KV(n,e,t,r,s3,i3)}function KV(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 sh=i3,o3="a0";function WV(n){try{s3(n,null)}catch{throw new Error("invalid index: "+n)}}function zd(n,e,t){return sh(n??null,e??null,t)}function Rw(n,e){return sh(n??null,null,e)}function Qf(n,e){return sh(n??null,e??null,1)[0]}function Oo(n=null){return sh(n,null,1)[0]}function VV(n=null){return sh(null,n,1)[0]}function ep(n,e="a1"){return[e,...sh(e,null,n)]}function tr(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function qV(n,e){return n.id>e.id?1:-1}function vI(n){try{return localStorage.getItem(n)}catch{return null}}function xI(n,e){try{localStorage.setItem(n,e)}catch{}}function GV(){try{localStorage.clear()}catch{}}function a3(n){try{return sessionStorage.getItem(n)}catch{return null}}function wI(n,e){try{sessionStorage.setItem(n,e)}catch{}}function l3(n){try{sessionStorage.removeItem(n)}catch{}}function YV(){try{sessionStorage.clear()}catch{}}const bd=[],XV=60,Qm=Math.ceil(1e3/XV);let ef,Dw=0,IP=0;const ZV=()=>{const n=bd.splice(0,bd.length);for(const e of n)e()};function c3(){if(ef)return;const n=Date.now(),e=n-IP;if(Dw+e<Qm){ef=requestAnimationFrame(()=>{ef=void 0,c3()});return}ef=requestAnimationFrame(()=>{ef=void 0,IP=n,Dw=Math.min(Dw+e-Qm,Qm*10),ZV()})}let cA=!1;function u3(n){return bd.includes(n)||(bd.push(n),cA||(cA=!0,IP=Date.now()-Qm-1),c3()),()=>{const e=bd.indexOf(n);e>-1&&bd.splice(e,1)}}class JV{constructor(){R(this,"timeouts",new Map);R(this,"intervals",new Map);R(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 Ze=(n,e)=>{try{return new URL(n,e)}catch{return}};function QV(n){return n!==void 0}function eq(){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 d3=eq(),Xt=d3[0];d3[1];const tq=Object.getPrototypeOf(Xt({}));Yl("@tldraw/utils","3.11.1","esm");var uA={},tf,dA;function qr(){if(dA)return tf;dA=1;var n=function(e){return e&&e.Math===Math&&e};return tf=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof ws=="object"&&ws)||n(typeof tf=="object"&&tf)||function(){return this}()||Function("return this")(),tf}var jw={},Nw,hA;function Gr(){return hA||(hA=1,Nw=function(n){try{return!!n()}catch{return!0}}),Nw}var Lw,fA;function Xl(){if(fA)return Lw;fA=1;var n=Gr();return Lw=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Lw}var Fw,pA;function m0(){if(pA)return Fw;pA=1;var n=Gr();return Fw=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),Fw}var zw,gA;function Ba(){if(gA)return zw;gA=1;var n=m0(),e=Function.prototype.call;return zw=n?e.bind(e):function(){return e.apply(e,arguments)},zw}var $w={},mA;function nq(){if(mA)return $w;mA=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return $w.f=t?function(s){var i=e(this,s);return!!i&&i.enumerable}:n,$w}var Bw,yA;function h3(){return yA||(yA=1,Bw=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),Bw}var Uw,SA;function qn(){if(SA)return Uw;SA=1;var n=m0(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return Uw=n?r:function(s){return function(){return t.apply(s,arguments)}},Uw}var Hw,vA;function ih(){if(vA)return Hw;vA=1;var n=qn(),e=n({}.toString),t=n("".slice);return Hw=function(r){return t(e(r),8,-1)},Hw}var Kw,xA;function rq(){if(xA)return Kw;xA=1;var n=qn(),e=Gr(),t=ih(),r=Object,s=n("".split);return Kw=e(function(){return!r("z").propertyIsEnumerable(0)})?function(i){return t(i)==="String"?s(i,""):r(i)}:r,Kw}var Ww,wA;function y0(){return wA||(wA=1,Ww=function(n){return n==null}),Ww}var Vw,bA;function oh(){if(bA)return Vw;bA=1;var n=y0(),e=TypeError;return Vw=function(t){if(n(t))throw new e("Can't call method on "+t);return t},Vw}var qw,CA;function S0(){if(CA)return qw;CA=1;var n=rq(),e=oh();return qw=function(t){return n(e(t))},qw}var Gw,PA;function Yr(){if(PA)return Gw;PA=1;var n=typeof document=="object"&&document.all;return Gw=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},Gw}var Yw,kA;function hu(){if(kA)return Yw;kA=1;var n=Yr();return Yw=function(e){return typeof e=="object"?e!==null:n(e)},Yw}var Xw,IA;function v0(){if(IA)return Xw;IA=1;var n=qr(),e=Yr(),t=function(r){return e(r)?r:void 0};return Xw=function(r,s){return arguments.length<2?t(n[r]):n[r]&&n[r][s]},Xw}var Zw,EA;function f3(){if(EA)return Zw;EA=1;var n=qn();return Zw=n({}.isPrototypeOf),Zw}var Jw,_A;function sq(){if(_A)return Jw;_A=1;var n=qr(),e=n.navigator,t=e&&e.userAgent;return Jw=t?String(t):"",Jw}var Qw,TA;function iq(){if(TA)return Qw;TA=1;var n=qr(),e=sq(),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]))),Qw=a,Qw}var eb,MA;function p3(){if(MA)return eb;MA=1;var n=iq(),e=Gr(),t=qr(),r=t.String;return eb=!!Object.getOwnPropertySymbols&&!e(function(){var s=Symbol("symbol detection");return!r(s)||!(Object(s)instanceof Symbol)||!Symbol.sham&&n&&n<41}),eb}var tb,AA;function g3(){if(AA)return tb;AA=1;var n=p3();return tb=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",tb}var nb,OA;function m3(){if(OA)return nb;OA=1;var n=v0(),e=Yr(),t=f3(),r=g3(),s=Object;return nb=r?function(i){return typeof i=="symbol"}:function(i){var o=n("Symbol");return e(o)&&t(o.prototype,s(i))},nb}var rb,RA;function oq(){if(RA)return rb;RA=1;var n=String;return rb=function(e){try{return n(e)}catch{return"Object"}},rb}var sb,DA;function bI(){if(DA)return sb;DA=1;var n=Yr(),e=oq(),t=TypeError;return sb=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},sb}var ib,jA;function CI(){if(jA)return ib;jA=1;var n=bI(),e=y0();return ib=function(t,r){var s=t[r];return e(s)?void 0:n(s)},ib}var ob,NA;function aq(){if(NA)return ob;NA=1;var n=Ba(),e=Yr(),t=hu(),r=TypeError;return ob=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")},ob}var ab={exports:{}},lb,LA;function y3(){return LA||(LA=1,lb=!1),lb}var cb,FA;function PI(){if(FA)return cb;FA=1;var n=qr(),e=Object.defineProperty;return cb=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},cb}var zA;function kI(){if(zA)return ab.exports;zA=1;var n=y3(),e=qr(),t=PI(),r="__core-js_shared__",s=ab.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"}),ab.exports}var ub,$A;function II(){if($A)return ub;$A=1;var n=kI();return ub=function(e,t){return n[e]||(n[e]=t||{})},ub}var db,BA;function Ip(){if(BA)return db;BA=1;var n=oh(),e=Object;return db=function(t){return e(n(t))},db}var hb,UA;function Zl(){if(UA)return hb;UA=1;var n=qn(),e=Ip(),t=n({}.hasOwnProperty);return hb=Object.hasOwn||function(s,i){return t(e(s),i)},hb}var fb,HA;function S3(){if(HA)return fb;HA=1;var n=qn(),e=0,t=Math.random(),r=n(1 .toString);return fb=function(s){return"Symbol("+(s===void 0?"":s)+")_"+r(++e+t,36)},fb}var pb,KA;function Ua(){if(KA)return pb;KA=1;var n=qr(),e=II(),t=Zl(),r=S3(),s=p3(),i=g3(),o=n.Symbol,a=e("wks"),l=i?o.for||o:o&&o.withoutSetter||r;return pb=function(c){return t(a,c)||(a[c]=s&&t(o,c)?o[c]:l("Symbol."+c)),a[c]},pb}var gb,WA;function lq(){if(WA)return gb;WA=1;var n=Ba(),e=hu(),t=m3(),r=CI(),s=aq(),i=Ua(),o=TypeError,a=i("toPrimitive");return gb=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)},gb}var mb,VA;function v3(){if(VA)return mb;VA=1;var n=lq(),e=m3();return mb=function(t){var r=n(t,"string");return e(r)?r:r+""},mb}var yb,qA;function x3(){if(qA)return yb;qA=1;var n=qr(),e=hu(),t=n.document,r=e(t)&&e(t.createElement);return yb=function(s){return r?t.createElement(s):{}},yb}var Sb,GA;function w3(){if(GA)return Sb;GA=1;var n=Xl(),e=Gr(),t=x3();return Sb=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),Sb}var YA;function b3(){if(YA)return jw;YA=1;var n=Xl(),e=Ba(),t=nq(),r=h3(),s=S0(),i=v3(),o=Zl(),a=w3(),l=Object.getOwnPropertyDescriptor;return jw.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])},jw}var vb={},xb,XA;function C3(){if(XA)return xb;XA=1;var n=Xl(),e=Gr();return xb=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),xb}var wb,ZA;function fu(){if(ZA)return wb;ZA=1;var n=hu(),e=String,t=TypeError;return wb=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},wb}var JA;function Ep(){if(JA)return vb;JA=1;var n=Xl(),e=w3(),t=C3(),r=fu(),s=v3(),i=TypeError,o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,l="enumerable",c="configurable",d="writable";return vb.f=n?t?function(g,m,y){if(r(g),m=s(m),r(y),typeof g=="function"&&m==="prototype"&&"value"in y&&d in y&&!y[d]){var v=a(g,m);v&&v[d]&&(g[m]=y.value,y={configurable:c in y?y[c]:v[c],enumerable:l in y?y[l]:v[l],writable:!1})}return o(g,m,y)}:o:function(g,m,y){if(r(g),m=s(m),r(y),e)try{return o(g,m,y)}catch{}if("get"in y||"set"in y)throw new i("Accessors not supported");return"value"in y&&(g[m]=y.value),g},vb}var bb,QA;function EI(){if(QA)return bb;QA=1;var n=Xl(),e=Ep(),t=h3();return bb=n?function(r,s,i){return e.f(r,s,t(1,i))}:function(r,s,i){return r[s]=i,r},bb}var Cb={exports:{}},Pb,eO;function cq(){if(eO)return Pb;eO=1;var n=Xl(),e=Zl(),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 Pb={EXISTS:s,PROPER:i,CONFIGURABLE:o},Pb}var kb,tO;function P3(){if(tO)return kb;tO=1;var n=qn(),e=Yr(),t=kI(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(s){return r(s)}),kb=t.inspectSource,kb}var Ib,nO;function uq(){if(nO)return Ib;nO=1;var n=qr(),e=Yr(),t=n.WeakMap;return Ib=e(t)&&/native code/.test(String(t)),Ib}var Eb,rO;function k3(){if(rO)return Eb;rO=1;var n=II(),e=S3(),t=n("keys");return Eb=function(r){return t[r]||(t[r]=e(r))},Eb}var _b,sO;function _I(){return sO||(sO=1,_b={}),_b}var Tb,iO;function I3(){if(iO)return Tb;iO=1;var n=uq(),e=qr(),t=hu(),r=EI(),s=Zl(),i=kI(),o=k3(),a=_I(),l="Object already initialized",c=e.TypeError,d=e.WeakMap,f,g,m,y=function(C){return m(C)?g(C):f(C,{})},v=function(C){return function(E){var _;if(!t(E)||(_=g(E)).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,E){if(x.has(C))throw new c(l);return E.facade=C,x.set(C,E),E},g=function(C){return x.get(C)||{}},m=function(C){return x.has(C)}}else{var b=o("state");a[b]=!0,f=function(C,E){if(s(C,b))throw new c(l);return E.facade=C,r(C,b,E),E},g=function(C){return s(C,b)?C[b]:{}},m=function(C){return s(C,b)}}return Tb={set:f,get:g,has:m,enforce:y,getterFor:v},Tb}var oO;function dq(){if(oO)return Cb.exports;oO=1;var n=qn(),e=Gr(),t=Yr(),r=Zl(),s=Xl(),i=cq().CONFIGURABLE,o=P3(),a=I3(),l=a.enforce,c=a.get,d=String,f=Object.defineProperty,g=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=Cb.exports=function(C,E,_){g(d(E),0,7)==="Symbol("&&(E="["+m(d(E),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),_&&_.getter&&(E="get "+E),_&&_.setter&&(E="set "+E),(!r(C,"name")||i&&C.name!==E)&&(s?f(C,"name",{value:E,configurable:!0}):C.name=E),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 M=l(C);return r(M,"source")||(M.source=y(x,typeof E=="string"?E:"")),C};return Function.prototype.toString=b(function(){return t(this)&&c(this).source||o(this)},"toString"),Cb.exports}var Mb,aO;function E3(){if(aO)return Mb;aO=1;var n=Yr(),e=Ep(),t=dq(),r=PI();return Mb=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},Mb}var Ab={},Ob,lO;function hq(){if(lO)return Ob;lO=1;var n=Math.ceil,e=Math.floor;return Ob=Math.trunc||function(r){var s=+r;return(s>0?e:n)(s)},Ob}var Rb,cO;function pu(){if(cO)return Rb;cO=1;var n=hq();return Rb=function(e){var t=+e;return t!==t||t===0?0:n(t)},Rb}var Db,uO;function fq(){if(uO)return Db;uO=1;var n=pu(),e=Math.max,t=Math.min;return Db=function(r,s){var i=n(r);return i<0?e(i+s,0):t(i,s)},Db}var jb,dO;function _3(){if(dO)return jb;dO=1;var n=pu(),e=Math.min;return jb=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},jb}var Nb,hO;function _p(){if(hO)return Nb;hO=1;var n=_3();return Nb=function(e){return n(e.length)},Nb}var Lb,fO;function pq(){if(fO)return Lb;fO=1;var n=S0(),e=fq(),t=_p(),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 Lb={includes:r(!0),indexOf:r(!1)},Lb}var Fb,pO;function T3(){if(pO)return Fb;pO=1;var n=qn(),e=Zl(),t=S0(),r=pq().indexOf,s=_I(),i=n([].push);return Fb=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},Fb}var zb,gO;function TI(){return gO||(gO=1,zb=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),zb}var mO;function gq(){if(mO)return Ab;mO=1;var n=T3(),e=TI(),t=e.concat("length","prototype");return Ab.f=Object.getOwnPropertyNames||function(s){return n(s,t)},Ab}var $b={},yO;function mq(){return yO||(yO=1,$b.f=Object.getOwnPropertySymbols),$b}var Bb,SO;function yq(){if(SO)return Bb;SO=1;var n=v0(),e=qn(),t=gq(),r=mq(),s=fu(),i=e([].concat);return Bb=n("Reflect","ownKeys")||function(a){var l=t.f(s(a)),c=r.f;return c?i(l,c(a)):l},Bb}var Ub,vO;function Sq(){if(vO)return Ub;vO=1;var n=Zl(),e=yq(),t=b3(),r=Ep();return Ub=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))}},Ub}var Hb,xO;function vq(){if(xO)return Hb;xO=1;var n=Gr(),e=Yr(),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 Hb=r,Hb}var Kb,wO;function ah(){if(wO)return Kb;wO=1;var n=qr(),e=b3().f,t=EI(),r=E3(),s=PI(),i=Sq(),o=vq();return Kb=function(a,l){var c=a.target,d=a.global,f=a.stat,g,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],g=o(d?y:c+(f?".":"#")+y,a.forced),!g&&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)}},Kb}var Wb={},Vb,bO;function xq(){if(bO)return Vb;bO=1;var n=T3(),e=TI();return Vb=Object.keys||function(r){return n(r,e)},Vb}var CO;function wq(){if(CO)return Wb;CO=1;var n=Xl(),e=C3(),t=Ep(),r=fu(),s=S0(),i=xq();return Wb.f=n&&!e?Object.defineProperties:function(a,l){r(a);for(var c=s(l),d=i(l),f=d.length,g=0,m;f>g;)t.f(a,m=d[g++],c[m]);return a},Wb}var qb,PO;function bq(){if(PO)return qb;PO=1;var n=v0();return qb=n("document","documentElement"),qb}var Gb,kO;function M3(){if(kO)return Gb;kO=1;var n=fu(),e=wq(),t=TI(),r=_I(),s=bq(),i=x3(),o=k3(),a=">",l="<",c="prototype",d="script",f=o("IE_PROTO"),g=function(){},m=function(C){return l+d+a+C+l+"/"+d+a},y=function(C){C.write(m("")),C.close();var E=C.parentWindow.Object;return C=null,E},v=function(){var C=i("iframe"),E="java"+d+":",_;return C.style.display="none",s.appendChild(C),C.src=String(E),_=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,Gb=Object.create||function(E,_){var M;return E!==null?(g[c]=n(E),M=new g,g[c]=null,M[f]=E):M=b(),_===void 0?M:e.f(M,_)},Gb}var Yb,IO;function MI(){if(IO)return Yb;IO=1;var n=Ua(),e=M3(),t=Ep().f,r=n("unscopables"),s=Array.prototype;return s[r]===void 0&&t(s,r,{configurable:!0,value:e(null)}),Yb=function(i){s[r][i]=!0},Yb}var EO;function Cq(){if(EO)return uA;EO=1;var n=ah(),e=Ip(),t=_p(),r=pu(),s=MI();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"),uA}var Xb,_O;function Tp(){if(_O)return Xb;_O=1;var n=qr(),e=qn();return Xb=function(t,r){return e(n[t].prototype[r])},Xb}var Zb,TO;function Pq(){if(TO)return Zb;TO=1,Cq();var n=Tp();return Zb=n("Array","at"),Zb}var Jb,MO;function kq(){if(MO)return Jb;MO=1;var n=Pq();return Jb=n,Jb}kq();var AO={},Qb,OO;function A3(){if(OO)return Qb;OO=1;var n=ih();return Qb=Array.isArray||function(t){return n(t)==="Array"},Qb}var e1,RO;function Iq(){if(RO)return e1;RO=1;var n=TypeError,e=9007199254740991;return e1=function(t){if(t>e)throw n("Maximum allowed index exceeded");return t},e1}var t1,DO;function Eq(){if(DO)return t1;DO=1;var n=ih(),e=qn();return t1=function(t){if(n(t)==="Function")return e(t)},t1}var n1,jO;function _q(){if(jO)return n1;jO=1;var n=Eq(),e=bI(),t=m0(),r=n(n.bind);return n1=function(s,i){return e(s),i===void 0?s:t?r(s,i):function(){return s.apply(i,arguments)}},n1}var r1,NO;function O3(){if(NO)return r1;NO=1;var n=A3(),e=_p(),t=Iq(),r=_q(),s=function(i,o,a,l,c,d,f,g){for(var m=c,y=0,v=f?r(f,g):!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 r1=s,r1}var s1,LO;function Tq(){if(LO)return s1;LO=1;var n=Ua(),e=n("toStringTag"),t={};return t[e]="z",s1=String(t)==="[object z]",s1}var i1,FO;function R3(){if(FO)return i1;FO=1;var n=Tq(),e=Yr(),t=ih(),r=Ua(),s=r("toStringTag"),i=Object,o=t(function(){return arguments}())==="Arguments",a=function(l,c){try{return l[c]}catch{}};return i1=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},i1}var o1,zO;function Mq(){if(zO)return o1;zO=1;var n=qn(),e=Gr(),t=Yr(),r=R3(),s=v0(),i=P3(),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}},g=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 g.sham=!0,o1=!a||e(function(){var m;return f(f.call)||!f(Object)||!f(function(){m=!0})||m})?g:f,o1}var a1,$O;function Aq(){if($O)return a1;$O=1;var n=A3(),e=Mq(),t=hu(),r=Ua(),s=r("species"),i=Array;return a1=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},a1}var l1,BO;function D3(){if(BO)return l1;BO=1;var n=Aq();return l1=function(e,t){return new(n(e))(t===0?0:t)},l1}var UO;function Oq(){if(UO)return AO;UO=1;var n=ah(),e=O3(),t=bI(),r=Ip(),s=_p(),i=D3();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}}),AO}var HO={},KO;function Rq(){if(KO)return HO;KO=1;var n=MI();return n("flatMap"),HO}var c1,WO;function Dq(){if(WO)return c1;WO=1,Oq(),Rq();var n=Tp();return c1=n("Array","flatMap"),c1}var u1,VO;function jq(){if(VO)return u1;VO=1;var n=Dq();return u1=n,u1}jq();var qO={},GO;function Nq(){if(GO)return qO;GO=1;var n=ah(),e=O3(),t=Ip(),r=_p(),s=pu(),i=D3();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}}),qO}var YO={},XO;function Lq(){if(XO)return YO;XO=1;var n=MI();return n("flat"),YO}var d1,ZO;function Fq(){if(ZO)return d1;ZO=1,Nq(),Lq();var n=Tp();return d1=n("Array","flat"),d1}var h1,JO;function zq(){if(JO)return h1;JO=1;var n=Fq();return h1=n,h1}zq();var QO={},f1,eR;function Mp(){if(eR)return f1;eR=1;var n=R3(),e=String;return f1=function(t){if(n(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return e(t)},f1}var tR;function $q(){if(tR)return QO;tR=1;var n=ah(),e=qn(),t=oh(),r=pu(),s=Mp(),i=Gr(),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,g=r(c),m=g>=0?g:f+g;return m<0||m>=f?void 0:o(d,m)}}),QO}var p1,nR;function Bq(){if(nR)return p1;nR=1,$q();var n=Tp();return p1=n("String","at"),p1}var g1,rR;function Uq(){if(rR)return g1;rR=1;var n=Bq();return g1=n,g1}Uq();var sR={},m1,iR;function j3(){if(iR)return m1;iR=1;var n=fu();return m1=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},m1}var y1,oR;function Hq(){if(oR)return y1;oR=1;var n=Gr(),e=qr(),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 y1={BROKEN_CARET:i,MISSED_STICKY:s,UNSUPPORTED_Y:r},y1}var S1,aR;function Kq(){if(aR)return S1;aR=1;var n=Gr(),e=qr(),t=e.RegExp;return S1=n(function(){var r=t(".","s");return!(r.dotAll&&r.test(`
71
+ `)&&r.flags==="s")}),S1}var v1,lR;function Wq(){if(lR)return v1;lR=1;var n=Gr(),e=qr(),t=e.RegExp;return v1=n(function(){var r=t("(?<a>b)","g");return r.exec("b").groups.a!=="b"||"b".replace(r,"$<a>c")!=="bc"}),v1}var x1,cR;function AI(){if(cR)return x1;cR=1;var n=Ba(),e=qn(),t=Mp(),r=j3(),s=Hq(),i=II(),o=M3(),a=I3().get,l=Kq(),c=Wq(),d=i("native-string-replace",String.prototype.replace),f=RegExp.prototype.exec,g=f,m=e("".charAt),y=e("".indexOf),v=e("".replace),x=e("".slice),b=function(){var M=/a/,A=/b*/g;return n(f,M,"a"),n(f,A,"a"),M.lastIndex!==0||A.lastIndex!==0}(),C=s.BROKEN_CARET,E=/()??/.exec("")[1]!==void 0,_=b||E||C||l||c;return _&&(g=function(A){var O=this,D=a(O),B=t(A),U=D.raw,G,z,N,L,V,Z,W;if(U)return U.lastIndex=O.lastIndex,G=n(g,U,B),O.lastIndex=U.lastIndex,G;var $=D.groups,Y=C&&O.sticky,re=n(r,O),K=O.source,ne=0,ge=B;if(Y&&(re=v(re,"y",""),y(re,"g")===-1&&(re+="g"),ge=x(B,O.lastIndex),O.lastIndex>0&&(!O.multiline||O.multiline&&m(B,O.lastIndex-1)!==`
72
+ `)&&(K="(?: "+K+")",ge=" "+ge,ne++),z=new RegExp("^(?:"+K+")",re)),E&&(z=new RegExp("^"+K+"$(?!\\s)",re)),b&&(N=O.lastIndex),L=n(f,Y?z:O,ge),Y?L?(L.input=x(L.input,ne),L[0]=x(L[0],ne),L.index=O.lastIndex,O.lastIndex+=L[0].length):O.lastIndex=0:b&&L&&(O.lastIndex=O.global?L.index+L[0].length:N),E&&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=Z=o(null),V=0;V<$.length;V++)W=$[V],Z[W[0]]=L[W[1]];return L}),x1=g,x1}var uR;function N3(){if(uR)return sR;uR=1;var n=ah(),e=AI();return n({target:"RegExp",proto:!0,forced:/./.exec!==e},{exec:e}),sR}var dR={},w1,hR;function Vq(){if(hR)return w1;hR=1;var n=m0(),e=Function.prototype,t=e.apply,r=e.call;return w1=typeof Reflect=="object"&&Reflect.apply||(n?r.bind(t):function(){return r.apply(t,arguments)}),w1}var b1,fR;function qq(){if(fR)return b1;fR=1,N3();var n=Ba(),e=E3(),t=AI(),r=Gr(),s=Ua(),i=EI(),o=s("species"),a=RegExp.prototype;return b1=function(l,c,d,f){var g=s(l),m=!r(function(){var b={};return b[g]=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[g]=/./[g]),C.exec=function(){return b=!0,null},C[g](""),!b});if(!m||!y||d){var v=/./[g],x=c(g,""[l],function(b,C,E,_,M){var A=C.exec;return A===t||A===a.exec?m&&!M?{done:!0,value:n(v,C,E,_)}:{done:!0,value:n(b,E,C,_)}:{done:!1}});e(String.prototype,l,x[0]),e(a,g,x[1])}f&&i(a[g],"sham",!0)},b1}var C1,pR;function Gq(){if(pR)return C1;pR=1;var n=qn(),e=pu(),t=Mp(),r=oh(),s=n("".charAt),i=n("".charCodeAt),o=n("".slice),a=function(l){return function(c,d){var f=t(r(c)),g=e(d),m=f.length,y,v;return g<0||g>=m?l?"":void 0:(y=i(f,g),y<55296||y>56319||g+1===m||(v=i(f,g+1))<56320||v>57343?l?s(f,g):y:l?o(f,g,g+2):(y-55296<<10)+(v-56320)+65536)}};return C1={codeAt:a(!1),charAt:a(!0)},C1}var P1,gR;function Yq(){if(gR)return P1;gR=1;var n=Gq().charAt;return P1=function(e,t,r){return t+(r?n(e,t).length:1)},P1}var k1,mR;function L3(){if(mR)return k1;mR=1;var n=qn(),e=Ip(),t=Math.floor,r=n("".charAt),s=n("".replace),i=n("".slice),o=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,a=/\$([$&'`]|\d{1,2})/g;return k1=function(l,c,d,f,g,m){var y=d+l.length,v=f.length,x=a;return g!==void 0&&(g=e(g),x=o),s(m,x,function(b,C){var E;switch(r(C,0)){case"$":return"$";case"&":return l;case"`":return i(c,0,d);case"'":return i(c,y);case"<":E=g[i(C,1,-1)];break;default:var _=+C;if(_===0)return b;if(_>v){var M=t(_/10);return M===0?b:M<=v?f[M-1]===void 0?r(C,1):f[M-1]+r(C,1):b}E=f[_-1]}return E===void 0?"":E})},k1}var I1,yR;function Xq(){if(yR)return I1;yR=1;var n=Ba(),e=fu(),t=Yr(),r=ih(),s=AI(),i=TypeError;return I1=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")},I1}var SR;function Zq(){if(SR)return dR;SR=1;var n=Vq(),e=Ba(),t=qn(),r=qq(),s=Gr(),i=fu(),o=Yr(),a=y0(),l=pu(),c=_3(),d=Mp(),f=oh(),g=Yq(),m=CI(),y=L3(),v=Xq(),x=Ua(),b=x("replace"),C=Math.max,E=Math.min,_=t([].concat),M=t([].push),A=t("".indexOf),O=t("".slice),D=function(z){return z===void 0?z:String(z)},B=function(){return"a".replace(/./,"$0")==="$0"}(),U=function(){return/./[b]?/./[b]("a","$0")==="":!1}(),G=!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 Y=f(this),re=a(W)?void 0:m(W,b);return re?e(re,W,Y,$):e(N,d(Y),W,$)},function(Z,W){var $=i(this),Y=d(Z);if(typeof W=="string"&&A(W,V)===-1&&A(W,"$<")===-1){var re=L(N,$,Y,W);if(re.done)return re.value}var K=o(W);K||(W=d(W));var ne=$.global,ge;ne&&(ge=$.unicode,$.lastIndex=0);for(var Pe=[],ce;ce=v($,Y),!(ce===null||(M(Pe,ce),!ne));){var Be=d(ce[0]);Be===""&&($.lastIndex=g(Y,c($.lastIndex),ge))}for(var Re="",Ce=0,_e=0;_e<Pe.length;_e++){ce=Pe[_e];for(var We=d(ce[0]),st=C(E(l(ce.index),Y.length),0),hn=[],_t,Qt=1;Qt<ce.length;Qt++)M(hn,D(ce[Qt]));var Nt=ce.groups;if(K){var At=_([We],hn,st,Y);Nt!==void 0&&M(At,Nt),_t=d(n(W,void 0,At))}else _t=y(We,Y,st,hn,Nt,W);st>=Ce&&(Re+=O(Y,Ce,st)+_t,Ce=st+We.length)}return Re+O(Y,Ce)}]},!G||!B||U),dR}var vR={},E1,xR;function Jq(){if(xR)return E1;xR=1;var n=hu(),e=ih(),t=Ua(),r=t("match");return E1=function(s){var i;return n(s)&&((i=s[r])!==void 0?!!i:e(s)==="RegExp")},E1}var _1,wR;function Qq(){if(wR)return _1;wR=1;var n=Ba(),e=Zl(),t=f3(),r=j3(),s=RegExp.prototype;return _1=function(i){var o=i.flags;return o===void 0&&!("flags"in s)&&!e(i,"flags")&&t(s,i)?n(r,i):o},_1}var bR;function eG(){if(bR)return vR;bR=1;var n=ah(),e=Ba(),t=qn(),r=oh(),s=Yr(),i=y0(),o=Jq(),a=Mp(),l=CI(),c=Qq(),d=L3(),f=Ua(),g=y3(),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(_,M){var A=r(this),O,D,B,U,G,z,N,L,V,Z,W=0,$="";if(!i(_)){if(O=o(_),O&&(D=a(r(c(_))),!~v(D,"g")))throw new y("`.replaceAll` does not allow non-global regexes");if(B=l(_,m),B)return e(B,_,A,M);if(g&&O)return x(a(A),_,M)}for(U=a(A),G=a(_),z=s(M),z||(M=a(M)),N=G.length,L=C(1,N),V=v(U,G);V!==-1;)Z=z?a(M(G,V,U)):d(G,U,V,[],void 0,M),$+=b(U,W,V)+Z,W=V+N,V=V+L>U.length?-1:v(U,G,V+L);return W<U.length&&($+=b(U,W)),$}}),vR}var T1,CR;function tG(){if(CR)return T1;CR=1,N3(),Zq(),eG();var n=Tp();return T1=n("String","replaceAll"),T1}var M1,PR;function nG(){if(PR)return M1;PR=1;var n=tG();return M1=n,M1}nG();function F3(n){return n&&typeof n=="object"&&"parents"in n}function z3(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 Uy(n,e){if(n.children.remove(e)&&n.children.isEmpty&&F3(n))for(let t=0,r=n.parents.length;t<r;t++)Uy(n.parents[t],n)}function OI(n,e){if(n.children.add(e)&&F3(n))for(let t=0,r=n.parents.length;t<r;t++)OI(n.parents[t],n)}function $3(n,e){return n===e||Object.is(n,e)||!!(n&&e&&typeof n.equals=="function"&&n.equals(e))}function Jl(n,e){const t=Symbol.for(`com.tldraw.state/${n}`),r=globalThis;return r[t]??(r[t]=e()),r[t]}const bi=Jl("empty_array",()=>Object.freeze([])),kR=8;class Hy{constructor(){R(this,"arraySize",0);R(this,"array",Array(kR));R(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<kR?(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 Ks=Symbol.for("com.tldraw.state/RESET_VALUE");class B3{constructor(e){R(this,"index",0);R(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,t,r){if(r!==void 0){if(r===Ks){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 Ks;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 g=0;g<d;g++)f[g]=s[(o+g)%r][2];return f}}return Ks}}class rG{constructor(e,t){R(this,"offset",0);R(this,"maybeRemoved");this.below=e,this.child=t}}const tn=Jl("capture",()=>({stack:null}));function um(n){const e=tn.stack;tn.stack=null;try{return n()}finally{tn.stack=e}}function U3(n){tn.stack=new rG(tn.stack,n),n.parentSet.clear()}function H3(){const n=tn.stack;if(tn.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)||Uy(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)||Uy(t,n.child)}}function Ky(n){if(tn.stack){if(tn.stack.child.parentSet.has(n))return;if(tn.stack.child.parentSet.add(n),tn.stack.child.isActivelyListening&&OI(n,tn.stack.child),tn.stack.offset<tn.stack.child.parents.length){const t=tn.stack.child.parents[tn.stack.offset];t!==n&&(tn.stack.maybeRemoved?tn.stack.maybeRemoved.push(t):tn.stack.maybeRemoved=[t])}tn.stack.child.parents[tn.stack.offset]=n,tn.stack.child.parentEpochs[tn.stack.offset]=n.lastChangedEpoch,tn.stack.offset++}}const Al=-1;class sG{constructor(e,t,r){R(this,"_isActivelyListening",!1);R(this,"lastTraversedEpoch",Al);R(this,"lastReactedEpoch",Al);R(this,"_scheduleCount",0);R(this,"parentSet",new Hy);R(this,"parentEpochs",[]);R(this,"parents",[]);R(this,"_scheduleEffect");R(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!==ms()){if(this.parents.length&&!z3(this)){this.lastReactedEpoch=ms();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++)OI(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,t=this.parents.length;e<t;e++)Uy(this.parents[e],this)}execute(){try{U3(this);const e=ms(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,t}finally{H3()}}}const gu=Jl("EffectScheduler",()=>sG);function Yi(n,e,t){const r=new gu(n,e,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function iG(n,e,t){const r=new gu(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 oG=class{constructor(e){R(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(Et.globalIsReacting)for(const e of this.initialAtomValues.keys())W3(e);else this.isRoot?K3(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,e)})}abort(){Et.globalEpoch++,this.initialAtomValues.forEach((e,t)=>{var r;t.set(e),(r=t.historyBuffer)==null||r.clear()}),this.commit()}};const Et=Jl("transactions",()=>({globalEpoch:Al+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Al+1}));function aG(){return Et.reactionEpoch}function ms(){return Et.globalEpoch}function lG(){return Et.globalIsReacting}function RI(n,e){e.lastTraversedEpoch!==Et.globalEpoch&&(e.lastTraversedEpoch=Et.globalEpoch,e instanceof gu?n.add(e):e.children.visit(t=>RI(n,t)))}function K3(n){var t;if(Et.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=Et.currentTransaction;try{Et.currentTransaction=null,Et.globalIsReacting=!0,Et.reactionEpoch=Et.globalEpoch;const r=new Set;for(const i of n)i.children.visit(o=>RI(r,o));for(const i of r)i.maybeScheduleEffect();let s=0;for(;(t=Et.cleanupReactors)!=null&&t.size;){if(s++>1e3)throw new Error("Reaction update depth limit exceeded");const i=Et.cleanupReactors;Et.cleanupReactors=null;for(const o of i)o.maybeScheduleEffect()}}finally{Et.cleanupReactors=null,Et.globalIsReacting=!1,Et.currentTransaction=e}}function cG(n,e){Et.currentTransaction?Et.currentTransaction.initialAtomValues.has(n)||Et.currentTransaction.initialAtomValues.set(n,e):Et.globalIsReacting?W3(n):K3([n])}function W3(n){const e=Et.cleanupReactors??(Et.cleanupReactors=new Set);n.children.visit(t=>RI(e,t))}function uG(){Et.globalEpoch++}function dG(n){const e=new oG(Et.currentTransaction);Et.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{Et.currentTransaction=Et.currentTransaction.parent}}function Ps(n){return Et.currentTransaction?n():dG(n)}class hG{constructor(e,t,r){R(this,"isEqual");R(this,"computeDiff");R(this,"lastChangedEpoch",ms());R(this,"children",new Hy);R(this,"historyBuffer");this.name=e,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new B3(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return Ky(this),this.current}set(e,t){var s,i;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,e))??$3(this.current,e))return this.current;uG(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,ms(),t??((i=this.computeDiff)==null?void 0:i.call(this,this.current,e,this.lastChangedEpoch,ms()))??Ks),this.lastChangedEpoch=ms();const r=this.current;return this.current=e,cG(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var t;return Ky(this),e>=this.lastChangedEpoch?bi:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??Ks}}const fG=Jl("Atom",()=>hG);function ln(n,e,t){return new fG(n,e,t)}let IR=!1;function pG(){IR||(IR=!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 xr=Symbol.for("com.tldraw.state/UNINITIALIZED");function Bc(n){return n===xr}const EP=Jl("WithDiff",()=>class{constructor(e,t){this.value=e,this.diff=t}});function Sf(n,e){return new EP(n,e)}class gG{constructor(e,t,r){R(this,"lastChangedEpoch",Al);R(this,"lastTraversedEpoch",Al);R(this,"lastCheckedEpoch",Al);R(this,"parentSet",new Hy);R(this,"parents",[]);R(this,"parentEpochs",[]);R(this,"children",new Hy);R(this,"historyBuffer");R(this,"state",xr);R(this,"error",null);R(this,"computeDiff");R(this,"isEqual");this.name=e,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new B3(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??$3}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var s;const t=this.lastChangedEpoch===Al,r=ms();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&lG()&&this.lastTraversedEpoch<aG()||!z3(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{U3(this);const i=this.derive(this.state,this.lastCheckedEpoch),o=i instanceof EP?i.value:i,a=this.state===xr;if(a||!this.isEqual(o,this.state)){if(this.historyBuffer&&!a){const l=i instanceof EP?i.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,ms(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,o,this.lastCheckedEpoch,ms()))??Ks)}this.lastChangedEpoch=ms(),this.state=o}return this.error=null,this.lastCheckedEpoch=ms(),this.state}catch(i){if(this.state!==xr&&(this.state=xr,this.lastChangedEpoch=ms()),this.lastCheckedEpoch=ms(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:i},!e)throw i;return this.state}finally{H3()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Ky(this)}}getDiffSince(e){var t;return this.__unsafe__getWithoutCapture(!0),Ky(this),e>=this.lastChangedEpoch?bi:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??Ks}}const x0=Jl("Computed",()=>gG);function mG(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 x0(t,s.bind(this),n),Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()},r.value[V3]=!0,r}function yG(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 x0(t,s.bind(this),n),Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()},r}function SG(n,e,t){tt(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 x0(String(t.name),e.bind(this),n),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()};return s[V3]=!0,s}function ER(n={},e){if(e.length===2){const[t,r]=e;return SG(n,t,r)}else{const[t,r,s]=e;return s.get?(pG(),yG(n,t,r,s)):mG(n,t,r,s)}}const V3="@@__isComputedMethod__@@";function le(){if(arguments.length===1){const n=arguments[0];return(...e)=>ER(n,e)}else return typeof arguments[0]=="string"?new x0(arguments[0],arguments[1],arguments[2]):ER(void 0,arguments)}const q3=1,vG=Jl("apiVersion",()=>q3);if(vG!==q3)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");Yl("@tldraw/state","3.11.1","esm");function w0(n,e,t=[]){const r=ot.useRef(e);r.current=e;const[s,i,o]=ot.useMemo(()=>{let a=null;const l=f=>(a=f,()=>{a=null}),c=new gu(`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 ot.useSyncExternalStore(i,o,o),ot.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const _R={apply(n,e,t){return w0(n.displayName??n.name??"tracked(???)",()=>n.apply(e,t))}},xG=Symbol.for("react.memo"),wG=Symbol.for("react.forward_ref");function Gn(n){let e=null;const t=n.$$typeof;return t===xG&&(n=n.type,e=n.compare),t===wG?P.memo(P.forwardRef(new Proxy(n.render,_R))):P.memo(new Proxy(n,_R),e)}function b0(n,e,t){return P.useState(()=>{const r=typeof e=="function"?e():e;return ln(`useAtom(${n})`,r,t)})[0]}function bG(){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 _a(n,e,t=bi){P.useEffect(()=>{const r=new gu(n,e);return r.attach(),r.execute(),()=>{r.detach()}},t)}function DI(n,e,t=[]){const r=P.useRef(-1),s=P.useMemo(()=>new gu(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=>Yi(`useValue(${t})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return P.useSyncExternalStore(i,o,o)}finally{r.current=!1}}Yl("@tldraw/state-react","3.11.1","esm");const Un={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 Pt(n){return`${te(n.x)},${te(n.y)} `}function Ss(n,e){return`${te((n.x+e.x)/2)},${te((n.y+e.y)/2)} `}const wt=Math.PI,Kt=wt/2,Dt=wt*2,CG=Math.sin;function Rn(n,e,t){return Math.max(e,typeof t<"u"?Math.min(n,t):n)}function dm(n,e=1e10){return n?Math.round(n*e)/e:0}function jl(n,e,t=1e-6){return Math.abs(n-e)<=t}function G3(n,e){const t=Math.pow(n-e,2)/Math.pow(n+e,2);return wt*(n+e)*(1+3*t/(10+Math.sqrt(4-3*t)))}function Uc(n){return n=n%Dt,n<0?n=n+Dt:n===0&&(n=0),n}function Ap(n,e){return n=Uc(n),e=Uc(e),n>e&&(e+=Dt),e-n}function Y3(n,e){return Dt-Ap(n,e)}function ey(n,e){const t=(e-n)%Dt;return 2*t%Dt-t}function _P(n){return(Dt+n)%Dt}function Wy(n,e){const t=Dt/e;let r=Math.floor((_P(n)+t/2)/t)*t%Dt;return r<wt&&(r+=Dt),r>wt&&(r-=Dt),r}function X3(n,e){return n===e||jl(n%(Math.PI/2)-e%(Math.PI/2),0)}function PG(n){return n*wt/180}function kG(n){return n*180/wt}function Yc(n,e,t){return new k(n.x,n.y).add(k.FromAngle(t,e))}function A1(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=Dt/t,x=-Kt+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 k(b,C))}const d=a-o,f=c-l,g=n-d,m=e-f;if(g!==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 nf(n,e,t,r){return n<r&&t<e}function Ui(n,e,t,r){const s=Math.max(n,t),i=Math.min(e,r);return s<=i?[s,i]:null}function TR(n,e,t){return(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y)}function Ws(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],k.Dist(n,r)+k.Dist(n,s)===k.Dist(r,s)))return!0;r.y<=n.y?s.y>n.y&&TR(r,s,n)>0&&(t+=1):s.y<=n.y&&TR(r,s,n)<0&&(t-=1)}return t!==0}function te(n){return Math.round(n*1e4)/1e4}function Ca(n){return Math.round(n*100)/100}const MR=n=>Math.abs(n)<Number.MAX_SAFE_INTEGER;function Il(n,e,t){return t<0?Ap(n,e):Y3(n,e)}function TP(n,e,t,r){let s;if(Math.abs(n)>wt){s=ey(e,r);const i=ey(r,t);return Math.abs(s)<Math.abs(i)?s/n:(n-i)/n}else{s=ey(e,r);const i=s/n;return Math.sign(s)!==Math.sign(n)?Math.abs(i)>.5?1:0:i}}function IG(n,e,t,r){const s=2*((e-n)%Dt)%Dt-(e-n)%Dt;return r?(Dt-Math.abs(s))*(t?1:-1):s}function jI(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 k(s,i)}function EG(n,e,t,r,s){if(t===null)return[k.From(n),k.From(e)];const i=[],o=k.Angle(t,n),a=k.Angle(t,e),l=Ap(o,a);for(let c=0;c<s;c++){const d=c/(s-1),f=o+l*d,g=Yc(t,r,f);i.push(g)}return i}class k{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 k(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=k.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 k.Dpr(this,e)}cpr(e){return k.Cpr(this,e)}len2(){return k.Len2(this)}len(){return k.Len(this)}pry(e){return k.Pry(this,e)}per(){const{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){return k.Uni(this)}tan(e){return k.Tan(this,e)}dist(e){return k.Dist(this,e)}distanceToLineSegment(e,t){return k.DistanceToLineSegment(e,t,this)}slope(e){return k.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 k.Angle(this,e)}toAngle(){return k.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 k.Equals(this,e)}equalsXY(e,t){return k.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 k.ToFixed(this)}toString(){return k.ToString(k.ToFixed(this))}toJson(){return k.ToJson(this)}toArray(){return k.ToArray(this)}static Add(e,t){return new k(e.x+t.x,e.y+t.y)}static AddXY(e,t,r){return new k(e.x+t,e.y+r)}static Sub(e,t){return new k(e.x-t.x,e.y-t.y)}static SubXY(e,t,r){return new k(e.x-t,e.y-r)}static AddScalar(e,t){return new k(e.x+t,e.y+t)}static SubScalar(e,t){return new k(e.x-t,e.y-t)}static Div(e,t){return new k(e.x/t,e.y/t)}static Mul(e,t){return new k(e.x*t,e.y*t)}static DivV(e,t){return new k(e.x/t.x,e.y/t.y)}static MulV(e,t){return new k(e.x*t.x,e.y*t.y)}static Neg(e){return new k(-e.x,-e.y)}static Per(e){return new k(e.y,-e.x)}static Abs(e){return new k(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 k(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 k.Dpr(e,t)/k.Len(t)}static Uni(e){return k.Div(e,k.Len(e))}static Tan(e,t){return k.Uni(k.Sub(e,t))}static Min(e,t){return new k(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new k(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:r=1}){return new k(e,t,r)}static FromArray(e){return new k(e[0],e[1])}static Rot(e,t=0){const r=Math.sin(t),s=Math.cos(t);return new k(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 k(t.x+(s*a-i*o),t.y+(s*o+i*a))}static NearestPointOnLineThroughPoint(e,t,r){return k.Mul(t,k.Sub(r,e).pry(t)).add(e)}static NearestPointOnLineSegment(e,t,r,s=!0){if(k.Equals(e,r)||k.Equals(t,r))return k.From(r);const i=k.Tan(t,e),o=k.Add(e,k.Mul(i,k.Sub(r,e).pry(i)));if(s){if(o.x<Math.min(e.x,t.x))return k.Cast(e.x<t.x?e:t);if(o.x>Math.max(e.x,t.x))return k.Cast(e.x>t.x?e:t);if(o.y<Math.min(e.y,t.y))return k.Cast(e.y<t.y?e:t);if(o.y>Math.max(e.y,t.y))return k.Cast(e.y>t.y?e:t)}return o}static DistanceToLineThroughPoint(e,t,r){return k.Dist(r,k.NearestPointOnLineThroughPoint(e,t,r))}static DistanceToLineSegment(e,t,r,s=!0){return k.Dist(r,k.NearestPointOnLineSegment(e,t,r,s))}static Snap(e,t=1){return new k(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof k?e:k.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 k.Sub(t,e).mul(r).add(e)}static Med(e,t){return new k((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=k.Len(e);return new k(t*e.x/r,t*e.y/r)}static ScaleWithOrigin(e,t,r){return k.Sub(e,r).mul(t).add(r)}static ToFixed(e){return new k(Ca(e.x),Ca(e.y))}static ToInt(e){return new k(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 k.Add(e,k.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 k(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 k(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 k(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new k(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=Un.easeInQuad(i/(r-1)),a=k.Lrp(e,t,o);a.z=Math.min(1,.5+Math.abs(.5-_G(o))*.65),s.push(a)}return s}static SnapToGrid(e,t=8){return new k(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}const _G=n=>n<.5?2*n*n:-1+(4-2*n)*n;function Z3(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 _n(i)}const a=new k(0,0);t<0&&(a.x=-(e.width*o)),r<0&&(a.y=-(e.height*o));const{x:l,y:c}=k.Add(s,a.rot(n.rotation));return{x:l,y:c,props:{scale:o*n.props.scale}}}function Jn(n){this.content=n}Jn.prototype={constructor:Jn,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 Jn(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 Jn(t)},addToStart:function(n,e){return new Jn([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Jn(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 Jn(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=Jn.from(n),n.size?new Jn(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Jn.from(n),n.size?new Jn(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Jn.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}};Jn.from=function(n){if(n instanceof Jn)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Jn(e)};function J3(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=J3(s.content,i.content,t+1);if(o!=null)return o}t+=s.nodeSize}}function Q3(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=Q3(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 J3(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return Q3(this,e,t,r)}findIndex(e,t=-1){if(e==0)return hm(0,e);if(e==this.size)return hm(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?hm(r+1,o):hm(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 O1={index:0,offset:0};function hm(n,e){return O1.index=n,O1.offset=e,O1}function Vy(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(!Vy(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!Vy(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}let Ft=class MP{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&&Vy(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 MP.none;if(e instanceof MP)return[e];let t=e.slice();return t.sort((r,s)=>r.type.rank-s.type.rank),t}};Ft.none=[];class qy 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=tF(this.content,e+this.openStart,t);return r&&new Te(r,this.openStart,this.openEnd)}removeBetween(e,t){return new Te(eF(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 eF(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(eF(i.content,e-s-1,t-s-1)))}function tF(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=tF(o.content,e-i-1,t);return a&&n.replaceChild(s,o.copy(a))}function TG(n,e,t){if(t.openStart>n.depth)throw new qy("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new qy("Inconsistent open depths");return nF(n,e,t,0)}function nF(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=nF(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 Kc(o,a.cut(0,n.parentOffset).append(t.content).append(a.cut(e.parentOffset)))}else{let{start:o,end:a}=MG(t,n);return Kc(i,sF(n,o,a,e,r))}else return Kc(i,Gy(n,e,r))}function rF(n,e){if(!e.type.compatibleContent(n.type))throw new qy("Cannot join "+e.type.name+" onto "+n.type.name)}function AP(n,e,t){let r=n.node(t);return rF(r,e.node(t)),r}function Hc(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 Rf(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&&(Hc(n.nodeAfter,r),i++));for(let a=i;a<o;a++)Hc(s.child(a),r);e&&e.depth==t&&e.textOffset&&Hc(e.nodeBefore,r)}function Kc(n,e){return n.type.checkContent(e),n.copy(e)}function sF(n,e,t,r,s){let i=n.depth>s&&AP(n,e,s+1),o=r.depth>s&&AP(t,r,s+1),a=[];return Rf(null,n,s,a),i&&o&&e.index(s)==t.index(s)?(rF(i,o),Hc(Kc(i,sF(n,e,t,r,s+1)),a)):(i&&Hc(Kc(i,Gy(n,e,s+1)),a),Rf(e,t,s,a),o&&Hc(Kc(o,Gy(t,r,s+1)),a)),Rf(r,null,s,a),new pe(a)}function Gy(n,e,t){let r=[];if(Rf(null,n,t,r),n.depth>t){let s=AP(n,e,t+1);Hc(Kc(s,Gy(n,e,t+1)),r)}return Rf(e,null,t,r),new pe(r)}function MG(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 tp{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 Ft.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 Yy(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 tp(t,r,i)}static resolveCached(e,t){let r=AR.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 AR.set(e,r=new AG);let s=r.elts[r.i]=tp.resolve(e,t);return r.i=(r.i+1)%OG,s}}class AG{constructor(){this.elts=[],this.i=0}}const OG=12,AR=new WeakMap;class Yy{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 RG=Object.create(null);let Xi=class OP{constructor(e,t,r,s=Ft.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&&Vy(this.attrs,t||e.defaultAttrs||RG)&&Ft.sameSet(this.marks,r||Ft.none)}copy(e=null){return e==this.content?this:new OP(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new OP(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 TG(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 tp.resolveCached(this,e)}resolveNoCache(e){return tp.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()+")"),iF(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=Ft.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(!Ft.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}};Xi.prototype.text=void 0;class Xy extends Xi{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):iF(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 Xy(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Xy(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 iF(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Xc{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new DG(e,t);if(r.next==null)return Xc.empty;let s=oF(r);r.next&&r.err("Unexpected trailing text");let i=BG($G(s));return UG(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 g=i(f,a.concat(d));if(g)return g}}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
+ `)}}Xc.empty=new Xc(!0);class DG{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 oF(n){let e=[];do e.push(jG(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function jG(n){let e=[];do e.push(NG(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function NG(n){let e=zG(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=LG(n,e);else break;return e}function OR(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function LG(n,e){let t=OR(n),r=t;return n.eat(",")&&(n.next!="}"?r=OR(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function FG(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 zG(n){if(n.eat("(")){let e=oF(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=FG(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 $G(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 aF(n,e){return e-n}function RR(n,e){let t=[];return r(e),t.sort(aF);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 BG(n){let e=Object.create(null);return t(RR(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]);RR(n,l).forEach(d=>{c||s.push([a,c=[]]),c.indexOf(d)==-1&&c.push(d)})})});let i=e[r.join(",")]=new Xc(r.indexOf(n.length-1)>-1);for(let o=0;o<s.length;o++){let a=s[o][1].sort(aF);i.next.push({type:s[o][0],next:e[a.join(",")]||t(a)})}return i}}function UG(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 lF(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 cF(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 uF(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 dF(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new KG(n,r,e[r]);return t}let DR=class hF{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=dF(e,r.attrs),this.defaultAttrs=lF(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==Xc.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:cF(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Xi(this,this.computeAttrs(e),pe.from(t),Ft.setFrom(r))}createChecked(e=null,t,r){return t=pe.from(t),this.checkContent(t),new Xi(this,this.computeAttrs(e),t,Ft.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 Xi(this,e,t.append(i),Ft.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){uF(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:Ft.none:e}static compile(e,t){let r=Object.create(null);e.forEach((i,o)=>r[i]=new hF(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 HG(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 KG{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?HG(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class C0{constructor(e,t,r,s){this.name=e,this.rank=t,this.schema=r,this.spec=s,this.attrs=dF(e,s.attrs),this.excluded=null;let i=lF(this.attrs);this.instance=i?new Ft(this,i):null}create(e=null){return!e&&this.instance?this.instance:new Ft(this,cF(this.attrs,e))}static compile(e,t){let r=Object.create(null),s=0;return e.forEach((i,o)=>r[i]=new C0(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){uF(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class fF{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=Jn.from(e.nodes),t.marks=Jn.from(e.marks||{}),this.nodes=DR.compile(this.spec.nodes,this),this.marks=C0.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]=Xc.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?jR(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==""?[]:jR(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 DR){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 Xy(r,r.defaultAttrs,e,Ft.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Xi.fromJSON(this,e)}markFromJSON(e){return Ft.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function jR(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 WG(n){return n.tag!=null}function VG(n){return n.style!=null}let Ed=class RP{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(s=>{if(WG(s))this.tags.push(s);else if(VG(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 LR(this,t,!1);return r.addAll(e,Ft.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new LR(this,t,!0);return r.addAll(e,Ft.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(YG(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=FR(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=FR(o)),o.node||o.ignore||o.mark||(o.node=s)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new RP(e,RP.schemaRules(e)))}};const pF={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},qG={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},gF={ol:!0,ul:!0},np=1,DP=2,ty=4;function NR(n,e,t){return e!=null?(e?np:0)|(e==="full"?DP:0):n&&n.whitespace=="pre"?np|DP:t&-5}class fm{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=Ft.none,this.match=i||(o&ty?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&np)){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&&!pF.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class LR{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=NR(null,t.preserveWhitespace,0)|(r?ty:0);s?i=new fm(s.type,s.attrs,Ft.none,!0,t.topMatch||s.type.contentMatch,o):r?i=new fm(null,null,Ft.none,!0,null,o):i=new fm(e.schema.topNodeType,null,Ft.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&DP?"full":this.localPreserveWS||(s.options&np)>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;gF.hasOwnProperty(o)&&this.parser.normalizeLists&&GG(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:qG.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(pF.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=Ft.none;for(let o of r.concat(e.marks))(s.type?s.type.allowsMarkType(o.type):zR(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=NR(e,i,o.options);o.options&ty&&o.content.length==0&&(a|=ty);let l=Ft.none;return r=r.filter(c=>(o.type?o.type.allowsMarkType(c.type):zR(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new fm(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|=np)}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 GG(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&gF.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function YG(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function FR(n){let e={};for(let t in n)e[t]=n[t];return e}function zR(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 mu{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},r){r||(r=R1(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}=ny(R1(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&&ny(R1(r),s(e,t),null,e.attrs)}static renderSpec(e,t,r=null,s){return ny(e,t,r,s)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new mu(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=$R(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return $R(e.marks)}}function $R(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function R1(n){return n.document||window.document}const BR=new WeakMap;function XG(n){let e=BR.get(n);return e===void 0&&BR.set(n,e=ZG(n)),e}function ZG(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 ny(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=XG(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 g=f.indexOf(" ");g>0?l.setAttributeNS(f.slice(0,g),f.slice(g+1),c[f]):l.setAttribute(f,c[f])}}for(let f=d;f<e.length;f++){let g=e[f];if(g===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}=ny(n,g,t,r);if(l.appendChild(m),y){if(a)throw new RangeError("Multiple content holes");a=y}}}return{dom:l,contentDOM:a}}const mF=65535,yF=Math.pow(2,16);function JG(n,e){return n+e*yF}function UR(n){return n&mF}function QG(n){return(n-(n&mF))/yF}const SF=1,vF=2,ry=4,xF=8;class jP{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&xF)>0}get deletedBefore(){return(this.delInfo&(SF|ry))>0}get deletedAfter(){return(this.delInfo&(vF|ry))>0}get deletedAcross(){return(this.delInfo&ry)>0}}class Bs{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Bs.empty)return Bs.empty}recover(e){let t=0,r=UR(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+QG(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 g=c?e==l?-1:e==f?1:t:t,m=l+s+(g<0?0:d);if(r)return m;let y=e==(t<0?l:f)?null:JG(a/3,e-l),v=e==l?vF:e==f?SF:ry;return(t<0?e!=l:e!=f)&&(v|=xF),new jP(m,v,y)}s+=d-c}return r?e+s:new jP(e+s,0,null)}touches(e,t){let r=0,s=UR(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 Bs(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Bs.empty:new Bs(e<0?[0,-e,0]:[0,0,e])}}Bs.empty=new Bs([]);class rp{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 rp(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 rp;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 jP(e,s,null)}}const D1=Object.create(null);class _r{getMap(){return Bs.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=D1[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 D1)throw new RangeError("Duplicate use of step JSON ID "+e);return D1[e]=t,t.prototype.jsonID=e,t}}class Tn{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new Tn(e,null)}static fail(e){return new Tn(null,e)}static fromReplace(e,t,r,s){try{return Tn.ok(e.replace(t,r,s))}catch(i){if(i instanceof qy)return Tn.fail(i.message);throw i}}}function NI(n,e,t){let r=[];for(let s=0;s<n.childCount;s++){let i=n.child(s);i.content.size&&(i=i.copy(NI(i.content,e,i))),i.isInline&&(i=e(i,t,s)),r.push(i)}return pe.fromArray(r)}class Ol extends _r{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(NI(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 Tn.fromReplace(e,this.from,this.to,i)}invert(){return new Ro(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 Ol(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ol&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ol(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 Ol(t.from,t.to,e.markFromJSON(t.mark))}}_r.jsonID("addMark",Ol);class Ro extends _r{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(NI(t.content,s=>s.mark(this.mark.removeFromSet(s.marks)),e),t.openStart,t.openEnd);return Tn.fromReplace(e,this.from,this.to,r)}invert(){return new Ol(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 Ro(t.pos,r.pos,this.mark)}merge(e){return e instanceof Ro&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ro(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 Ro(t.from,t.to,e.markFromJSON(t.mark))}}_r.jsonID("removeMark",Ro);class Rl extends _r{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tn.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Tn.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 Rl(this.pos,t.marks[s]);return new Rl(this.pos,this.mark)}}return new $d(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Rl(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 Rl(t.pos,e.markFromJSON(t.mark))}}_r.jsonID("addNodeMark",Rl);class $d extends _r{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tn.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Tn.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 Rl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new $d(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 $d(t.pos,e.markFromJSON(t.mark))}}_r.jsonID("removeNodeMark",$d);class $n extends _r{constructor(e,t,r,s=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=s}apply(e){return this.structure&&NP(e,this.from,this.to)?Tn.fail("Structure replace would overwrite content"):Tn.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Bs([this.from,this.to-this.from,this.slice.size])}invert(e){return new $n(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 $n(t.pos,Math.max(t.pos,r.pos),this.slice)}merge(e){if(!(e instanceof $n)||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 $n(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 $n(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 $n(t.from,t.to,Te.fromJSON(e,t.slice),!!t.structure)}}_r.jsonID("replace",$n);class Hn extends _r{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&&(NP(e,this.from,this.gapFrom)||NP(e,this.gapTo,this.to)))return Tn.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Tn.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?Tn.fromReplace(e,this.from,this.to,r):Tn.fail("Content does not fit in gap")}getMap(){return new Bs([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 Hn(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 Hn(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 Hn(t.from,t.to,t.gapFrom,t.gapTo,Te.fromJSON(e,t.slice),t.insert,!!t.structure)}}_r.jsonID("replaceAround",Hn);function NP(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 eY(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 g=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==g&&o.mark.eq(f[v])?o.to=m:s.push(o=new Ro(g,m,f[v])));a&&a.to==g?a.to=m:i.push(a=new Ol(g,m,r))}}),s.forEach(l=>n.step(l)),i.forEach(l=>n.step(l))}function tY(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 C0){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],g;for(let m=0;m<s.length;m++){let y=s[m];y.step==i-1&&f.eq(s[m].style)&&(g=y)}g?(g.to=c,g.step=i):s.push({style:f,from:Math.max(a,e),to:c,step:i})}}}),s.forEach(o=>n.step(new Ro(o.from,o.to,o.style)))}function LI(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 $n(a,d,Te.empty));else{r=f;for(let g=0;g<c.marks.length;g++)t.allowsMarkType(c.marks[g].type)||n.step(new Ro(a,d,c.marks[g]));if(s&&c.isText&&t.whitespace!="pre"){let g,m=/\r?\n|\r/g,y;for(;g=m.exec(c.text);)y||(y=new Te(pe.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new $n(a+g.index,a+g.index+g[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 nY(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function lh(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||!nY(s,i,o))break}return null}function rY(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 g=pe.empty,m=0;for(let y=i,v=!1;y>t;y--)v||s.after(y+1)<s.end(y)?(v=!0,g=pe.from(s.node(y).copy(g)),m++):c++;n.step(new Hn(l,c,o,a,new Te(d.append(g),f,m),d.size-f,!0))}function FI(n,e,t=null,r=n){let s=sY(n,e),i=s&&iY(r,e);return i?s.map(HR).concat({type:e,attrs:t}).concat(i.map(HR)):null}function HR(n){return{type:n,attrs:null}}function sY(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 iY(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 oY(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 Hn(s,i,s,i,new Te(r,0,0),t.length,!0))}function aY(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)&&lY(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&&bF(n,o,a,i),LI(n,n.mapping.slice(i).map(a,1),r,void 0,c===null);let d=n.mapping.slice(i),f=d.map(a,1),g=d.map(a+o.nodeSize,1);return n.step(new Hn(f,g,f+1,g-1,new Te(pe.from(r.create(l,null,o.marks)),0,0),1,!0)),c===!0&&wF(n,o,a,i),!1}})}function wF(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 bF(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 lY(n,e,t){let r=n.resolve(e),s=r.index();return r.parent.canReplaceWith(s,s+1,t)}function cY(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 Hn(e,e+i.nodeSize,e+1,e+i.nodeSize-1,new Te(pe.from(o),0,0),1,!0))}function Ta(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),g=s.index(c);if(f.type.spec.isolating)return!1;let m=f.content.cutByIndex(g,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(g+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 uY(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 $n(e,e,new Te(i.append(o),t,t),!0))}function Ql(n,e){let t=n.resolve(e),r=t.index();return CF(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function dY(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 CF(n,e){return!!(n&&e&&!n.isLeaf&&dY(n,e))}function P0(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&&CF(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 hY(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);bF(n,d.node(),d.before(),a)}o.inlineContent&&LI(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 $n(c,l.map(e+t,-1),Te.empty,!0)),r===!0){let d=n.doc.resolve(c);wF(n,d.node(),d.before(),n.steps.length)}return n}function fY(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 PF(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 k0(n,e,t=e,r=Te.empty){if(e==t&&!r.size)return null;let s=n.resolve(e),i=n.resolve(t);return kF(s,i,r)?new $n(e,t,r):new pY(s,i,r).fit()}function kF(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 Hn(r.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||r.pos!=this.$to.pos?new $n(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=j1(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=j1(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=j1(e,t);if(s.childCount<=1&&t>0){let i=e.size-t<=t+s.size;this.unplaced=new Te(vf(e,t-1,1),t-1,i?t-1:r)}else this.unplaced=new Te(vf(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:g}=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(IF(v.mark(g.allowedMarks(v.marks)),c==1?l:0,c==a.childCount?m:-1)))}let y=c==a.childCount;y||(m=-1),this.placed=xf(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(vf(o.content,e-1,1),e-1,m<0?o.openEnd:e-1):new Te(vf(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||!N1(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=N1(e,t,s,r,i);if(o){for(let a=t-1;a>=0;a--){let{match:l,type:c}=this.frontier[a],d=N1(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=xf(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=xf(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=xf(this.placed,this.frontier.length,t))}}function vf(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(vf(n.firstChild.content,e-1,t)))}function xf(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(xf(n.lastChild.content,e-1,t)))}function j1(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function IF(n,e,t){if(e<=0)return n;let r=n.content;return e>1&&(r=r.replaceChild(0,IF(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 N1(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&&!gY(t,i.content,o)?a:null}function gY(n,e,t){for(let r=t;r<e.childCount;r++)if(!n.allowsMarks(e.child(r).marks))return!0;return!1}function mY(n){return n.spec.defining||n.spec.definingForContent}function yY(n,e,t,r){if(!r.size)return n.deleteRange(e,t);let s=n.doc.resolve(e),i=n.doc.resolve(t);if(kF(s,i,r))return n.step(new $n(e,t,r));let o=_F(s,n.doc.resolve(t));o[o.length-1]==0&&o.pop();let a=-(s.depth+1);o.unshift(a);for(let g=s.depth,m=s.pos-1;g>0;g--,m--){let y=s.node(g).type.spec;if(y.defining||y.definingAsContext||y.isolating)break;o.indexOf(g)>-1?a=g:s.before(g)==m&&o.splice(1,0,-g)}let l=o.indexOf(a),c=[],d=r.openStart;for(let g=r.content,m=0;;m++){let y=g.firstChild;if(c.push(y),m==r.openStart)break;g=y.content}for(let g=d-1;g>=0;g--){let m=c[g],y=mY(m.type);if(y&&!m.sameMarkup(s.node(Math.abs(a)-1)))d=g;else if(y||!m.type.isTextblock)break}for(let g=r.openStart;g>=0;g--){let m=(g+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),E=s.index(x-1);if(C.canReplaceWith(E,E,y.type,y.marks))return n.replace(s.before(x),b?i.after(x):t,new Te(EF(r.content,0,r.openStart,m),m,r.openEnd))}}let f=n.steps.length;for(let g=o.length-1;g>=0&&(n.replace(e,t,r),!(n.steps.length>f));g--){let m=o[g];m<0||(e=s.before(m),t=i.after(m))}}function EF(n,e,t,r,s){if(e<t){let i=n.firstChild;n=n.replaceChild(0,i.copy(EF(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 SY(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let s=fY(n.doc,e,r.type);s!=null&&(e=t=s)}n.replaceRange(e,t,new Te(pe.from(r),0,0))}function vY(n,e,t){let r=n.doc.resolve(e),s=n.doc.resolve(t),i=_F(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 _F(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 _d extends _r{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 Tn.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 Tn.fromReplace(e,this.pos,this.pos+1,new Te(pe.from(s),0,t.isLeaf?0:1))}getMap(){return Bs.empty}invert(e){return new _d(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 _d(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 _d(t.pos,t.attr,t.value)}}_r.jsonID("attr",_d);class sp extends _r{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 Tn.ok(r)}getMap(){return Bs.empty}invert(e){return new sp(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 sp(t.attr,t.value)}}_r.jsonID("docAttr",sp);let Bd=class extends Error{};Bd=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Bd.prototype=Object.create(Error.prototype);Bd.prototype.constructor=Bd;Bd.prototype.name="TransformError";class TF{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new rp}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Bd(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=k0(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 yY(this,e,t,r),this}replaceRangeWith(e,t,r){return SY(this,e,t,r),this}deleteRange(e,t){return vY(this,e,t),this}lift(e,t){return rY(this,e,t),this}join(e,t=1){return hY(this,e,t),this}wrap(e,t){return oY(this,e,t),this}setBlockType(e,t=e,r,s=null){return aY(this,e,t,r,s),this}setNodeMarkup(e,t,r=null,s){return cY(this,e,t,r,s),this}setNodeAttribute(e,t,r){return this.step(new _d(e,t,r)),this}setDocAttribute(e,t){return this.step(new sp(e,t)),this}addNodeMark(e,t){return this.step(new Rl(e,t)),this}removeNodeMark(e,t){if(!(t instanceof Ft)){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 $d(e,t)),this}split(e,t=1,r){return uY(this,e,t,r),this}addMark(e,t,r){return eY(this,e,t,r),this}removeMark(e,t,r){return tY(this,e,t,r),this}clearIncompatible(e,t,r){return LI(this,e,t,r),this}}const L1=Object.create(null);class at{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new xY(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&&VR(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),VR(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let s=e.parent.inlineContent?new nt(e):gd(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?gd(e.node(0),e.node(i),e.before(i+1),e.index(i),t,r):gd(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 Vs(e.node(0))}static atStart(e){return gd(e,e,0,0,1)||new Vs(e)}static atEnd(e){return gd(e,e,e.content.size,e.childCount,-1)||new Vs(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=L1[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 L1)throw new RangeError("Duplicate use of selection JSON ID "+e);return L1[e]=t,t.prototype.jsonID=e,t}getBookmark(){return nt.between(this.$anchor,this.$head).getBookmark()}}at.prototype.visible=!0;class xY{constructor(e,t){this.$from=e,this.$to=t}}let KR=!1;function WR(n){!KR&&!n.parent.inlineContent&&(KR=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class nt extends at{constructor(e,t=e){WR(e),WR(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 nt(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 nt&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new I0(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 nt(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 nt(e,t)}}at.jsonID("text",nt);class I0{constructor(e,t){this.anchor=e,this.head=t}map(e){return new I0(e.map(this.anchor),e.map(this.head))}resolve(e){return nt.between(e.resolve(this.anchor),e.resolve(this.head))}}class Ke 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 Ke(i)}content(){return new Te(pe.from(this.node),0,0)}eq(e){return e instanceof Ke&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new zI(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ke(e.resolve(t.anchor))}static create(e,t){return new Ke(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Ke.prototype.visible=!1;at.jsonID("node",Ke);class zI{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new I0(r,r):new zI(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&Ke.isSelectable(r)?new Ke(t):at.near(t)}}class Vs 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 Vs(e)}map(e){return new Vs(e)}eq(e){return e instanceof Vs}getBookmark(){return wY}}at.jsonID("all",Vs);const wY={map(){return this},resolve(n){return new Vs(n)}};function gd(n,e,t,r,s,i=!1){if(e.inlineContent)return nt.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&&Ke.isSelectable(a))return Ke.create(n,t-(s<0?a.nodeSize:0))}else{let l=gd(n,a,t+s,s<0?a.childCount:0,s,i);if(l)return l}t+=a.nodeSize*s}return null}function VR(n,e,t){let r=n.steps.length-1;if(r<e)return;let s=n.steps[r];if(!(s instanceof $n||s instanceof Hn))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 qR=1,GR=2,YR=4;class bY extends TF{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|qR)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&qR)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=GR,this}ensureMarks(e){return Ft.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&GR)>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)||Ft.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|=YR,this}get scrolledIntoView(){return(this.updated&YR)>0}}function XR(n,e){return!e||!n?n:n.bind(e)}class wf{constructor(e,t,r){this.name=e,this.init=XR(t.init,r),this.apply=XR(t.apply,r)}}const CY=[new wf("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new wf("selection",{init(n,e){return n.selection||at.atStart(e.doc)},apply(n){return n.selection}}),new wf("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new wf("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class F1{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=CY.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 wf(r.key,r.spec.state,r))})}}class Cd{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 Cd(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 bY(this)}static create(e){let t=new F1(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new Cd(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 F1(this.schema,e.plugins),r=t.fields,s=new Cd(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 F1(e.schema,e.plugins),i=new Cd(s);return s.fields.forEach(o=>{if(o.name=="doc")i.doc=Xi.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 MF(n,e,t){for(let r in n){let s=n[r];s instanceof Function?s=s.bind(e):r=="handleDOMEvents"&&(s=MF(s,e,{})),t[r]=s}return t}class ur{constructor(e){this.spec=e,this.props={},e.props&&MF(e.props,this,this.props),this.key=e.key?e.key.key:AF("plugin")}getState(e){return e[this.key]}}const z1=Object.create(null);function AF(n){return n in z1?n+"$"+ ++z1[n]:(z1[n]=0,n+"$")}class Zs{constructor(e="key"){this.key=AF(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const nr=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Ud=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let LP=null;const xa=function(n,e,t){let r=LP||(LP=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},PY=function(){LP=null},Zc=function(n,e,t,r){return t&&(ZR(n,e,t,r,-1)||ZR(n,e,t,r,1))},kY=/^(img|br|input|textarea|hr)$/i;function ZR(n,e,t,r,s){for(;;){if(n==t&&e==r)return!0;if(e==(s<0?0:yi(n))){let i=n.parentNode;if(!i||i.nodeType!=1||Op(n)||kY.test(n.nodeName)||n.contentEditable=="false")return!1;e=nr(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?yi(n):0}else return!1}}function yi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function IY(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=yi(n)}else if(n.parentNode&&!Op(n))e=nr(n),n=n.parentNode;else return null}}function EY(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&&!Op(n))e=nr(n)+1,n=n.parentNode;else return null}}function _Y(n,e,t){for(let r=e==0,s=e==yi(n);r||s;){if(n==t)return!0;let i=nr(n);if(n=n.parentNode,!n)return!1;r=r&&i==0,s=s&&i==yi(n)}}function Op(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 E0=function(n){return n.focusNode&&Zc(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Rc(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function TY(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function MY(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(yi(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(yi(r.startContainer),r.startOffset)}}}const Fo=typeof navigator<"u"?navigator:null,JR=typeof document<"u"?document:null,ec=Fo&&Fo.userAgent||"",FP=/Edge\/(\d+)/.exec(ec),OF=/MSIE \d/.exec(ec),zP=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ec),ks=!!(OF||zP||FP),Nl=OF?document.documentMode:zP?+zP[1]:FP?+FP[1]:0,Qi=!ks&&/gecko\/(\d+)/i.test(ec);Qi&&+(/Firefox\/(\d+)/.exec(ec)||[0,0])[1];const $P=!ks&&/Chrome\/(\d+)/.exec(ec),kr=!!$P,RF=$P?+$P[1]:0,Hr=!ks&&!!Fo&&/Apple Computer/.test(Fo.vendor),Hd=Hr&&(/Mobile\/\w+/.test(ec)||!!Fo&&Fo.maxTouchPoints>2),pi=Hd||(Fo?/Mac/.test(Fo.platform):!1),AY=Fo?/Win/.test(Fo.platform):!1,ka=/Android \d/.test(ec),Rp=!!JR&&"webkitFontSmoothing"in JR.documentElement.style,OY=Rp?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function RY(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 ha(n,e){return typeof n=="number"?n:n[e]}function DY(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 QR(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=Ud(o);continue}let a=o,l=a==i.body,c=l?RY(i):DY(a),d=0,f=0;if(e.top<c.top+ha(r,"top")?f=-(c.top-e.top+ha(s,"top")):e.bottom>c.bottom-ha(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+ha(s,"top")-c.top:e.bottom-c.bottom+ha(s,"bottom")),e.left<c.left+ha(r,"left")?d=-(c.left-e.left+ha(s,"left")):e.right>c.right-ha(r,"right")&&(d=e.right-c.right+ha(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 g=l?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(g))break;o=g=="absolute"?o.offsetParent:Ud(o)}}function jY(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:DF(n.dom)}}function DF(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Ud(r));return e}function NY({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;jF(t,r==0?0:r-e)}function jF(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 sd=null;function LY(n){if(n.setActive)return n.setActive();if(sd)return n.focus(sd);let e=DF(n);n.focus(sd==null?{get preventScroll(){return sd={preventScroll:!0},!0}}:void 0),sd||(sd=!1,jF(e,0))}function NF(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 g;if(d.nodeType==1)g=d.getClientRects();else if(d.nodeType==3)g=xa(d).getClientRects();else continue;for(let m=0;m<g.length;m++){let y=g[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?FY(t,s):!t||r&&t.nodeType==1?{node:n,offset:i}:NF(t,s)}function FY(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=vl(r,1);if(i.top!=i.bottom&&$I(e,i))return{node:n,offset:s+(e.left>=(i.left+i.right)/2?1:0)}}return{node:n,offset:0}}function $I(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function zY(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function $Y(n,e,t){let{node:r,offset:s}=NF(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 BY(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 LF(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($I(e,c))return LF(o,e,c)}}if((i=(i+1)%r)==s)break}return n}function UY(n,e){let t=n.dom.ownerDocument,r,s=0,i=MY(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(!$I(e,c)||(o=LF(n.dom,e,c),!o))return null}if(Hr)for(let c=o;r&&c;c=Ud(c))c.draggable&&(r=void 0);if(o=zY(o,e),r){if(Qi&&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;Rp&&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=BY(n,r,s,e))}a==null&&(a=$Y(n,o,e));let l=n.docView.nearestDesc(o,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function eD(n){return n.top<n.bottom||n.left<n.right}function vl(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(eD(r))return r}return Array.prototype.find.call(t,eD)||n.getBoundingClientRect()}const HY=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function FF(n,e,t){let{node:r,offset:s,atom:i}=n.docView.domFromPos(e,t<0?-1:1),o=Rp||Qi;if(r.nodeType==3)if(o&&(HY.test(r.nodeValue)||(t<0?!s:s==r.nodeValue.length))){let l=vl(xa(r,s,s),t);if(Qi&&s&&/\s/.test(r.nodeValue[s-1])&&s<r.nodeValue.length){let c=vl(xa(r,s-1,s-1),-1);if(c.top==l.top){let d=vl(xa(r,s,s+1),-1);if(d.top!=l.top)return rf(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++,rf(vl(xa(r,l,c),d),d<0)}if(!n.state.doc.resolve(e-(i||0)).parent.inlineContent){if(i==null&&s&&(t<0||s==yi(r))){let l=r.childNodes[s-1];if(l.nodeType==1)return $1(l.getBoundingClientRect(),!1)}if(i==null&&s<yi(r)){let l=r.childNodes[s];if(l.nodeType==1)return $1(l.getBoundingClientRect(),!0)}return $1(r.getBoundingClientRect(),t>=0)}if(i==null&&s&&(t<0||s==yi(r))){let l=r.childNodes[s-1],c=l.nodeType==3?xa(l,yi(l)-(o?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return rf(vl(c,1),!1)}if(i==null&&s<yi(r)){let l=r.childNodes[s];for(;l.pmViewDesc&&l.pmViewDesc.ignoreForCoords;)l=l.nextSibling;let c=l?l.nodeType==3?xa(l,0,o?0:1):l.nodeType==1?l:null:null;if(c)return rf(vl(c,-1),!0)}return rf(vl(r.nodeType==3?xa(r):r,-t),t>=0)}function rf(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 $1(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 zF(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 KY(n,e,t){let r=e.selection,s=t=="up"?r.$from:r.$to;return zF(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=FF(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=xa(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 WY=/[\u0590-\u08ac]/;function VY(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?!WY.test(r.parent.textContent)||!a.modify?t=="left"||t=="backward"?i:o:zF(n,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:d,anchorOffset:f}=n.domSelectionRange(),g=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 g!=null&&(a.caretBidiLevel=g),x}):r.pos==r.start()||r.pos==r.end()}let tD=null,nD=null,rD=!1;function qY(n,e,t){return tD==e&&nD==t?rD:(tD=e,nD=t,rD=t=="up"||t=="down"?KY(n,e,t):VY(n,e,t))}const Ci=0,sD=1,jc=2,zo=3;class Dp{constructor(e,t,r,s){this.parent=e,this.children=t,this.dom=r,this.contentDOM=s,this.dirty=Ci,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>nr(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 BF){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 $F&&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?nr(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?nr(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 g=this.children[f-1];if(g.size&&g.dom.parentNode==this.contentDOM&&!g.emptyChildAt(1)){s=nr(g.dom)+1;break}e-=g.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=nr(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((Qi||Hr)&&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:nr(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(Qi&&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&&Hr)&&Zc(a.node,a.offset,d.anchorNode,d.anchorOffset)&&Zc(l.node,l.offset,d.focusNode,d.focusOffset))return;let g=!1;if((c.extend||e==t)&&!f){c.collapse(a.node,a.offset);try{e!=t&&c.extend(l.node,l.offset),g=!0}catch{}}if(!g){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?jc:sD,e==a&&t==l&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=zo:i.markDirty(e-a,t-a);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?jc:zo}r=o}this.dirty=jc}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?jc:sD;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class $F extends Dp{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==Ci&&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 GY extends Dp{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 Jc extends Dp{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=mu.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Jc(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&zo||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=zo&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ci){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=Ci}}slice(e,t,r){let s=Jc.create(this.parent,this.mark,!0,r),i=this.children,o=this.size;t<o&&(i=UP(i,t,o,r)),e>0&&(i=UP(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 Ll extends Dp{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}=mu.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 g=d;return d=KF(d,r,t),c?l=new YY(e,t,r,s,d,f||null,g,c,i,o+1):t.isText?new _0(e,t,r,s,d,g,i):new Ll(e,t,r,s,d,f||null,g,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==Ci&&e.eq(this.node)&&Zy(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 ZY(this,o&&o.node,e);eX(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?Ft.none:this.node.child(d).marks,r,e),l.placeWidget(c,e,s)},(c,d,f,g)=>{l.syncToMarks(c.marks,r,e);let m;l.findNodeMatch(c,d,f,g)||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,g,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==jc)&&(o&&this.protectLocalComposition(e,o),UF(this.contentDOM,this.children,e),Hd&&tX(this.dom))}localCompositionInfo(e,t){let{from:r,to:s}=e.state.selection;if(!(e.state.selection instanceof nt)||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=nX(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 GY(this,i,t,s);e.input.compositionNodes.push(o),this.children=UP(this.children,r,r+s.length,e,o)}update(e,t,r,s){return this.dirty==zo||!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=Ci}updateOuterDeco(e){if(Zy(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=HF(this.dom,this.nodeDOM,BP(this.outerDeco,this.node,t),BP(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 iD(n,e,t,r,s){KF(r,e,n);let i=new Ll(void 0,n,e,t,r,r,r,s,0);return i.contentDOM&&i.updateChildren(s,0),i}class _0 extends Ll{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==zo||this.dirty!=Ci&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ci||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=Ci,!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 _0(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=zo)}get domAtom(){return!1}isText(e){return this.node.text==e}}class BF extends Dp{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ci&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class YY extends Ll{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==zo)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 UF(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=oD(r),s=!0;r=r.nextSibling}else s=!0,n.insertBefore(a,r);if(o instanceof Jc){let l=r?r.previousSibling:n.lastChild;UF(o.contentDOM,o.children,t),r=l?l.nextSibling:n.firstChild}}for(;r;)r=oD(r),s=!0;s&&t.trackWrites==n&&(t.trackWrites=null)}const Df=function(n){n&&(this.nodeName=n)};Df.prototype=Object.create(null);const Nc=[new Df];function BP(n,e,t){if(n.length==0)return Nc;let r=t?Nc[0]:new Df,s=[r];for(let i=0;i<n.length;i++){let o=n[i].type.attrs;if(o){o.nodeName&&s.push(r=new Df(o.nodeName));for(let a in o){let l=o[a];l!=null&&(t&&s.length==1&&s.push(r=new Df(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 HF(n,e,t,r){if(t==Nc&&r==Nc)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=Nc[0]),s=l}XY(s,a||Nc[0],o)}return s}function XY(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 KF(n,e,t){return HF(n,n,Nc,BP(e,t,n.nodeType!=1))}function Zy(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 oD(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class ZY{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=JY(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=Ci,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=Jc.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==zo&&o.dom==o.contentDOM&&(o.dirty=jc),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 Ll){let c=this.preMatch.matched.get(l);if(c!=null&&c!=i)return!1;let d=l.dom,f,g=this.isLocked(d)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&l.dirty!=zo&&Zy(t,l.outerDeco));if(!g&&l.update(e,t,r,s))return this.destroyBetween(this.index,a),l.dom!=d&&(this.changed=!0),this.index++,!0;if(!g&&(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=jc,f.updateChildren(s,o+1),f.dirty=Ci),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)||!Zy(r,e.outerDeco)||!s.eq(e.innerDeco))return null;let a=Ll.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=Ll.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 $F(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 Jc;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof _0)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Hr||kr)&&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 BF(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 JY(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 Jc)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 QY(n,e){return n.type.side-e.type.side}function eX(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(QY);for(let x=0;x<f.length;x++)t(f[x],c,!!l)}else t(d,c,!!l);let g,m;if(l)m=-1,g=l,l=null;else if(c<n.childCount)m=c,g=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+g.nodeSize;if(g.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=g.cut(x-i),g=g.cut(0,x-i),y=x,m=-1)}else for(;o<s.length&&s[o].to<y;)o++;let v=g.isInline&&!g.isLeaf?a.filter(x=>!x.inline):a.slice();r(g,v,e.forChild(i,g),m),i=y}}function tX(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 nX(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 UP(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 BI(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(E0(t)){for(l=o;s&&!s.node;)s=s.parent;let f=s.node;if(s&&f.isAtom&&Ke.isSelectable(f)&&s.parent&&!(f.isInline&&_Y(t.focusNode,t.focusOffset,s.dom))){let g=s.posBefore;c=new Ke(o==g?a:r.resolve(g))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,g=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)),g=Math.max(g,n.docView.posFromDOM(y.endContainer,y.endOffset,-1))}if(f<0)return null;[l,o]=g==n.state.selection.anchor?[g,f]:[f,g],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=UI(n,d,a,f)}return c}function WF(n){return n.editable?n.hasFocus():qF(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function Ma(n,e=!1){let t=n.state.selection;if(VF(n,t),!!WF(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&kr){let r=n.domSelectionRange(),s=n.domObserver.currentSelection;if(r.anchorNode&&s.anchorNode&&Zc(r.anchorNode,r.anchorOffset,s.anchorNode,s.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)sX(n);else{let{anchor:r,head:s}=t,i,o;aD&&!(t instanceof nt)&&(t.$from.parent.inlineContent||(i=lD(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=lD(n,t.to))),n.docView.setSelection(r,s,n,e),aD&&(i&&cD(i),o&&cD(o)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&rX(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const aD=Hr||kr&&RF<63;function lD(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(Hr&&s&&s.contentEditable=="false")return B1(s);if((!s||s.contentEditable=="false")&&(!i||i.contentEditable=="false")){if(s)return B1(s);if(i)return B1(i)}}function B1(n){return n.contentEditable="true",Hr&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function cD(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function rX(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(()=>{(!WF(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function sX(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,nr(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!s&&!n.state.selection.visible&&ks&&Nl<=11&&(r.disabled=!0,r.disabled=!1)}function VF(n,e){if(e instanceof Ke){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(uD(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else uD(n)}function uD(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function UI(n,e,t,r){return n.someProp("createSelectionBetween",s=>s(n,e,t))||nt.between(e,t,r)}function dD(n){return n.editable&&!n.hasFocus()?!1:qF(n)}function qF(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 iX(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Zc(e.node,e.offset,t.anchorNode,t.anchorOffset)}function HP(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 Cl(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function hD(n,e,t){let r=n.state.selection;if(r instanceof nt)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 Cl(n,new nt(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let s=HP(n.state,e);return s&&s instanceof Ke?Cl(n,s):!1}else if(!(pi&&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?Ke.isSelectable(i)?Cl(n,new Ke(e<0?n.state.doc.resolve(s.pos-i.nodeSize):s)):Rp?Cl(n,new nt(n.state.doc.resolve(e<0?a:a+i.nodeSize))):!1:!1}}else return!1;else{if(r instanceof Ke&&r.node.isInline)return Cl(n,new nt(e>0?r.$to:r.$from));{let s=HP(n.state,e);return s?Cl(n,s):!1}}}function Jy(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function jf(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function id(n,e){return e<0?oX(n):aX(n)}function oX(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let s,i,o=!1;for(Qi&&t.nodeType==1&&r<Jy(t)&&jf(t.childNodes[r],-1)&&(o=!0);;)if(r>0){if(t.nodeType!=1)break;{let a=t.childNodes[r-1];if(jf(a,-1))s=t,i=--r;else if(a.nodeType==3)t=a,r=t.nodeValue.length;else break}}else{if(GF(t))break;{let a=t.previousSibling;for(;a&&jf(a,-1);)s=t.parentNode,i=nr(a),a=a.previousSibling;if(a)t=a,r=Jy(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?KP(n,t,r):s&&KP(n,s,i)}function aX(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let s=Jy(t),i,o;for(;;)if(r<s){if(t.nodeType!=1)break;let a=t.childNodes[r];if(jf(a,1))i=t,o=++r;else break}else{if(GF(t))break;{let a=t.nextSibling;for(;a&&jf(a,1);)i=a.parentNode,o=nr(a)+1,a=a.nextSibling;if(a)t=a,r=0,s=Jy(t);else{if(t=t.parentNode,t==n.dom)break;r=s=0}}}i&&KP(n,i,o)}function GF(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function lX(n,e){for(;n&&e==n.childNodes.length&&!Op(n);)e=nr(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 cX(n,e){for(;n&&!e&&!Op(n);)e=nr(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 KP(n,e,t){if(e.nodeType!=3){let i,o;(o=lX(e,t))?(e=o,t=0):(i=cX(e,t))&&(e=i,t=i.nodeValue.length)}let r=n.domSelection();if(!r)return;if(E0(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&&Ma(n)},50)}function fD(n,e){let t=n.state.doc.resolve(e);if(!(kr||AY)&&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 pD(n,e,t){let r=n.state.selection;if(r instanceof nt&&!r.empty||t.indexOf("s")>-1||pi&&t.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=HP(n.state,e);if(o&&o instanceof Ke)return Cl(n,o)}if(!s.parent.inlineContent){let o=e<0?s:i,a=r instanceof Vs?at.near(o,e):at.findFrom(o,e);return a?Cl(n,a):!1}return!1}function gD(n,e){if(!(n.state.selection instanceof nt))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 mD(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function uX(n){if(!Hr||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;mD(n,r,"true"),setTimeout(()=>mD(n,r,"false"),20)}return!1}function dX(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function hX(n,e){let t=e.keyCode,r=dX(e);if(t==8||pi&&t==72&&r=="c")return gD(n,-1)||id(n,-1);if(t==46&&!e.shiftKey||pi&&t==68&&r=="c")return gD(n,1)||id(n,1);if(t==13||t==27)return!0;if(t==37||pi&&t==66&&r=="c"){let s=t==37?fD(n,n.state.selection.from)=="ltr"?-1:1:-1;return hD(n,s,r)||id(n,s)}else if(t==39||pi&&t==70&&r=="c"){let s=t==39?fD(n,n.state.selection.from)=="ltr"?1:-1:1;return hD(n,s,r)||id(n,s)}else{if(t==38||pi&&t==80&&r=="c")return pD(n,-1,r)||id(n,-1);if(t==40||pi&&t==78&&r=="c")return uX(n)||pD(n,1,r)||id(n,1);if(r==(pi?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function HI(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")||mu.fromSchema(n.state.schema),a=e5(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,f=0;for(;c&&c.nodeType==1&&(d=QF[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 g=n.someProp("clipboardTextSerializer",m=>m(e,n))||e.content.textBetween(0,e.content.size,`
91
+
92
+ `);return{dom:l,text:g,slice:e}}function YF(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",g=>{e=g(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",g=>g(e,s,r,n));if(f)a=f;else{let g=s.marks(),{schema:m}=n.state,y=mu.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,g)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=mX(t),Rp&&yX(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 g=o.firstChild;for(;g&&g.nodeType!=1;)g=g.nextSibling;if(!g)break;o=g}if(a||(a=(n.someProp("clipboardParser")||n.someProp("domParser")||Ed.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(l||d),context:s,ruleFromNode(g){return g.nodeName=="BR"&&!g.nextSibling&&g.parentNode&&!fX.test(g.parentNode.nodeName)?{ignore:!0}:null}})),d)a=SX(yD(a,+d[1],+d[2]),d[4]);else if(a=Te.maxOpen(pX(a.content,s),!0),a.openStart||a.openEnd){let f=0,g=0;for(let m=a.content.firstChild;f<a.openStart&&!m.type.spec.isolating;f++,m=m.firstChild);for(let m=a.content.lastChild;g<a.openEnd&&!m.type.spec.isolating;g++,m=m.lastChild);a=yD(a,f,g)}return n.someProp("transformPasted",f=>{a=f(a,n)}),a}const fX=/^(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&&ZF(l,i,a,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=JF(o[o.length-1],i.length));let d=XF(a,l);o.push(d),s=s.matchType(d.type),i=l}}),o)return pe.from(o)}return n}function XF(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,pe.from(n));return n}function ZF(n,e,t,r,s){if(s<n.length&&s<e.length&&n[s]==e[s]){let i=ZF(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(XF(t,n,s+1))))}}function JF(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,JF(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(pe.empty,!0);return n.copy(t.append(r))}function WP(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=WP(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 yD(n,e,t){return e<n.openStart&&(n=new Te(WP(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new Te(WP(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const QF={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 SD=null;function e5(){return SD||(SD=document.implementation.createHTMLDocument("title"))}let U1=null;function gX(n){let e=window.trustedTypes;return e?(U1||(U1=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),U1.createHTML(n)):n}function mX(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=e5().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),s;if((s=r&&QF[r[1].toLowerCase()])&&(n=s.map(i=>"<"+i+">").join("")+n+s.map(i=>"</"+i+">").reverse().join("")),t.innerHTML=gX(n),s)for(let i=0;i<s.length;i++)t=t.querySelector(s[i])||t;return t}function yX(n){let e=n.querySelectorAll(kr?"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 SX(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 Kr={},Wr={},vX={touchstart:!0,touchmove:!0};class xX{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 wX(n){for(let e in Kr){let t=Kr[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{CX(n,r)&&!KI(n,r)&&(n.editable||!(r.type in Wr))&&t(n,r)},vX[e]?{passive:!0}:void 0)}Hr&&n.dom.addEventListener("input",()=>null),VP(n)}function Dl(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function bX(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 VP(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>KI(n,r))})}function KI(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function CX(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 PX(n,e){!KI(n,e)&&Kr[e.type]&&(n.editable||!(e.type in Wr))&&Kr[e.type](n,e)}Wr.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!n5(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(ka&&kr&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Hd&&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,Rc(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||hX(n,t)?t.preventDefault():Dl(n,"key")};Wr.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};Wr.keypress=(n,e)=>{let t=e;if(n5(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||pi&&t.metaKey)return;if(n.someProp("handleKeyPress",s=>s(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof nt)||!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 T0(n){return{left:n.clientX,top:n.clientY}}function kX(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function WI(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 Td(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 IX(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&Ke.isSelectable(r)?(Td(n,new Ke(t)),!0):!1}function EX(n,e){if(e==-1)return!1;let t=n.state.selection,r,s;t instanceof Ke&&(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(Ke.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?(Td(n,Ke.create(n.state.doc,s)),!0):!1}function _X(n,e,t,r,s){return WI(n,"handleClickOn",e,t,r)||n.someProp("handleClick",i=>i(n,e,r))||(s?EX(n,t):IX(n,t))}function TX(n,e,t,r){return WI(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",s=>s(n,e,r))}function MX(n,e,t,r){return WI(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",s=>s(n,e,r))||AX(n,t,r)}function AX(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Td(n,nt.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)Td(n,nt.create(r,a+1,a+1+o.content.size));else if(Ke.isSelectable(o))Td(n,Ke.create(r,a));else continue;return!0}}function VI(n){return Qy(n)}const t5=pi?"metaKey":"ctrlKey";Kr.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=VI(n),s=Date.now(),i="singleClick";s-n.input.lastClick.time<500&&kX(t,n.input.lastClick)&&!t[t5]&&(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(T0(t));o&&(i=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new OX(n,o,t,!!r)):(i=="doubleClick"?TX:MX)(n,o.pos,o.inside,t)?t.preventDefault():Dl(n,"pointer"))};class OX{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[t5],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 Ke&&c.from<=o&&c.to>o)&&(this.mightDrag={node:i,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Qi&&!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)),Dl(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(()=>Ma(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(T0(e))),this.updateAllowDefault(e),this.allowDefault||!t?Dl(this.view,"pointer"):_X(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Hr&&this.mightDrag&&!this.mightDrag.node.isAtom||kr&&!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)?(Td(this.view,at.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Dl(this.view,"pointer")}move(e){this.updateAllowDefault(e),Dl(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)}}Kr.touchstart=n=>{n.input.lastTouch=Date.now(),VI(n),Dl(n,"pointer")};Kr.touchmove=n=>{n.input.lastTouch=Date.now(),Dl(n,"pointer")};Kr.contextmenu=n=>VI(n);function n5(n,e){return n.composing?!0:Hr&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const RX=ka?5e3:-1;Wr.compositionstart=Wr.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof nt&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),Qy(n,!0),n.markCursor=null;else if(Qy(n,!e.selection.empty),Qi&&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}r5(n,RX)};Wr.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++,r5(n,20))};function r5(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Qy(n),e))}function s5(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=jX());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function DX(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=IY(e.focusNode,e.focusOffset),r=EY(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 jX(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Qy(n,e=!1){if(!(ka&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),s5(n),e||n.docView&&n.docView.dirty){let t=BI(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 NX(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 ip=ks&&Nl<15||Hd&&OY<604;Kr.copy=Wr.cut=(n,e)=>{let t=e,r=n.state.selection,s=t.type=="cut";if(r.empty)return;let i=ip?null:t.clipboardData,o=r.content(),{dom:a,text:l}=HI(n,o);i?(t.preventDefault(),i.clearData(),i.setData("text/html",a.innerHTML),i.setData("text/plain",l)):NX(n,a),s&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function LX(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function FX(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?op(n,r.value,null,s,e):op(n,r.textContent,r.innerHTML,s,e)},50)}function op(n,e,t,r,s){let i=YF(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=LX(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 i5(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," "):""}Wr.paste=(n,e)=>{let t=e;if(n.composing&&!ka)return;let r=ip?null:t.clipboardData,s=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&op(n,i5(r),r.getData("text/html"),s,t)?t.preventDefault():FX(n,t)};let o5=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}};const zX=pi?"altKey":"ctrlKey";function a5(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[zX]}Kr.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(T0(t)),o;if(!(i&&i.pos>=s.from&&i.pos<=(s instanceof Ke?s.to-1:s.to))){if(r&&r.mightDrag)o=Ke.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=Ke.create(n.state.doc,f.posBefore))}}let a=(o||n.state.selection).content(),{dom:l,text:c,slice:d}=HI(n,a);(!t.dataTransfer.files.length||!kr||RF>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ip?"Text":"text/html",l.innerHTML),t.dataTransfer.effectAllowed="copyMove",ip||t.dataTransfer.setData("text/plain",c),n.dragging=new o5(d,a5(n,t),o)};Kr.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};Wr.dragover=Wr.dragenter=(n,e)=>e.preventDefault();Wr.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let s=n.posAtCoords(T0(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=YF(n,i5(t.dataTransfer),ip?null:t.dataTransfer.getData("text/html"),!1,i);let a=!!(r&&a5(n,t));if(n.someProp("handleDrop",y=>y(n,t,o||Te.empty,a))){t.preventDefault();return}if(!o)return;t.preventDefault();let l=o?PF(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,g=c.doc;if(f?c.replaceRangeWith(d,d,o.content.firstChild):c.replaceRange(d,d,o),c.doc.eq(g))return;let m=c.doc.resolve(d);if(f&&Ke.isSelectable(o.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new Ke(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(UI(n,m,c.doc.resolve(y)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};Kr.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())&&Ma(n)},20))};Kr.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)};Kr.beforeinput=(n,e)=>{if(kr&&ka&&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,Rc(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 Wr)Kr[n]=Wr[n];function ap(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 eS{constructor(e,t){this.toDOM=e,this.spec=t||Wc,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 Si(i-r,i-r,this)}valid(){return!0}eq(e){return this==e||e instanceof eS&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ap(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Fl{constructor(e,t){this.attrs=e,this.spec=t||Wc}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 Si(i,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Fl&&ap(this.attrs,e.attrs)&&ap(this.spec,e.spec)}static is(e){return e.type instanceof Fl}destroy(){}}class qI{constructor(e,t){this.attrs=e,this.spec=t||Wc}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 Si(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 qI&&ap(this.attrs,e.attrs)&&ap(this.spec,e.spec)}destroy(){}}class Si{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new Si(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 Si(e,e,new eS(t,r))}static inline(e,t,r,s){return new Si(e,t,new Fl(r,s))}static node(e,t,r,s){return new Si(e,t,new qI(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Fl}get widget(){return this.type instanceof eS}}const md=[],Wc={};class Dn{constructor(e,t){this.local=e.length?e:md,this.children=t.length?t:md}static create(e,t){return t.length?tS(t,e,0,Wc):wr}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==wr||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Wc)}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?$X(this.children,o||[],e,t,r,s,i):o?new Dn(o.sort(Vc),md):wr}add(e,t){return t.length?this==wr?Dn.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=c5(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,tS(d,a,c+1,Wc)),i+=3}});let o=l5(i?u5(t):t,-r);for(let a=0;a<o.length;a++)o[a].type.valid(e,o[a])||o.splice(a--,1);return new Dn(o.length?this.local.concat(o).sort(Vc):this.local,s||this.children)}remove(e){return e.length==0||this==wr?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!=wr?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 Dn(s,r):wr}forChild(e,t){if(this==wr)return this;if(t.isLeaf)return Dn.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 Fl){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 Dn(s.sort(Vc),md);return r?new El([a,r]):a}return r||wr}eq(e){if(this==e)return!0;if(!(e instanceof Dn)||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 GI(this.localsInner(e))}localsInner(e){if(this==wr)return md;if(e.inlineContent||!this.local.some(Fl.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Fl||t.push(this.local[r]);return t}forEachSet(e){e(this)}}Dn.empty=new Dn([],[]);Dn.removeOverlap=GI;const wr=Dn.empty;class El{constructor(e){this.members=e}map(e,t){const r=this.members.map(s=>s.map(e,t,Wc));return El.from(r)}forChild(e,t){if(t.isLeaf)return Dn.empty;let r=[];for(let s=0;s<this.members.length;s++){let i=this.members[s].forChild(e,t);i!=wr&&(i instanceof El?r=r.concat(i.members):r.push(i))}return El.from(r)}eq(e){if(!(e instanceof El)||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?GI(r?t:t.sort(Vc)):md}static from(e){switch(e.length){case 0:return wr;case 1:return e[0];default:return new El(e.every(t=>t instanceof Dn)?e:e.reduce((t,r)=>t.concat(r instanceof Dn?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function $X(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((g,m,y,v)=>{let x=v-y-(m-g);for(let b=0;b<a.length;b+=3){let C=a[b+1];if(C<0||g>C+d-f)continue;let E=a[b]+d-f;m>=E?a[b+1]=g<=E?-2:-1:g>=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 g=t.map(n[c+1]+i,-1),m=g-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!=wr?(a[c]=f,a[c+1]=m,a[c+2]=b):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=BX(a,n,e,t,s,i,o),d=tS(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,g=0;f<d.children.length;f+=3){let m=d.children[f];for(;g<a.length&&a[g]<m;)g+=3;a.splice(g,0,d.children[f],d.children[f+1],d.children[f+2])}}return new Dn(e.sort(Vc),a)}function l5(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 Si(s.from+e,s.to+e,s.type))}return t}function BX(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 c5(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 u5(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function tS(n,e,t,r){let s=[],i=!1;e.forEach((a,l)=>{let c=c5(n,a,l+t);if(c){i=!0;let d=tS(c,a,t+l+1,r);d!=wr&&s.push(l,l+a.nodeSize,d)}});let o=l5(i?u5(n):n,-t).sort(Vc);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 Dn(o,s):wr}function Vc(n,e){return n.from-e.from||n.to-e.to}function GI(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),vD(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),vD(e,s,r.copy(i.from,r.to)));break}}}return e}function vD(n,e,t){for(;e<n.length&&Vc(t,n[e])>0;)e++;n.splice(e,0,t)}function H1(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=wr&&e.push(r)}),n.cursorWrapper&&e.push(Dn.create(n.state.doc,[n.cursorWrapper.deco])),El.from(e)}const UX={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},HX=ks&&Nl<=11;class KX{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 WX{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new KX,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]);ks&&Nl<=11&&r.some(s=>s.type=="childList"&&s.removedNodes.length||s.type=="characterData"&&s.oldValue.length>s.target.nodeValue.length)?this.flushSoon():this.flush()}),HX&&(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,UX)),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(dD(this.view)){if(this.suppressingSelectionUpdates)return Ma(this.view);if(ks&&Nl<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Zc(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=Ud(i))t.add(i);for(let i=e.anchorNode;i;i=Ud(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)&&dD(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(Qi&&l.length){let d=l.filter(f=>f.nodeName=="BR");if(d.length==2){let[f,g]=d;f.parentNode&&f.parentNode.parentNode==g.parentNode?g.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let g of d){let m=g.parentNode;m&&m.nodeName=="LI"&&(!f||GX(e,f)!=m)&&g.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&&E0(r)&&(c=BI(e))&&c.eq(at.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Ma(e),this.currentSelection.set(r),e.scrollToSelection()):(i>-1||s)&&(i>-1&&(e.docView.markDirty(i,o),VX(e)),this.handleDOMChange(i,o,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Ma(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(ks&&Nl<=11&&e.addedNodes.length)for(let d=0;d<e.addedNodes.length;d++){let{previousSibling:f,nextSibling:g}=e.addedNodes[d];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(s=f),(!g||Array.prototype.indexOf.call(e.addedNodes,g)<0)&&(i=g)}let o=s&&s.parentNode==e.target?nr(s)+1:0,a=r.localPosFromDOM(e.target,o,-1),l=i&&i.parentNode==e.target?nr(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 xD=new WeakMap,wD=!1;function VX(n){if(!xD.has(n)&&(xD.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Qi,wD)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."),wD=!0}}function bD(n,e){let t=e.startContainer,r=e.startOffset,s=e.endContainer,i=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return Zc(o.node,o.offset,s,i)&&([t,r,s,i]=[s,i,t,r]),{anchorNode:t,anchorOffset:r,focusNode:s,focusOffset:i}}function qX(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return bD(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?bD(n,t):null}function GX(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 YX(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}],E0(l)||c.push({node:l.focusNode,offset:l.focusOffset})),kr&&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,g=n.someProp("domParser")||Ed.fromSchema(n.state.schema),m=f.resolve(o),y=null,v=g.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:XX,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 XX(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(Hr&&/^(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||Hr&&/^(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 ZX=/^(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 JX(n,e,t,r,s){let i=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let B=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,U=BI(n,B);if(U&&!n.state.selection.eq(U)){if(kr&&ka&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",z=>z(n,Rc(13,"Enter"))))return;let G=n.state.tr.setSelection(U);B=="pointer"?G.setMeta("pointer",!0):B=="key"&&G.scrollIntoView(),i&&G.setMeta("composition",i),n.dispatch(G)}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=YX(n,e,t),d=n.state.doc,f=d.slice(c.from,c.to),g,m;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(g=n.state.selection.to,m="end"):(g=n.state.selection.from,m="start"),n.input.lastKeyCode=null;let y=tZ(f.content,c.doc.content,c.from,g,m);if(y&&n.input.domChangeCount++,(Hd&&n.input.lastIOSEnter>Date.now()-225||ka)&&s.some(B=>B.nodeType==1&&!ZX.test(B.nodeName))&&(!y||y.endA>=y.endB)&&n.someProp("handleKeyDown",B=>B(n,Rc(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!y)if(r&&l instanceof nt&&!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 B=CD(n,n.state.doc,c.sel);if(B&&!B.eq(n.state.selection)){let U=n.state.tr.setSelection(B);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 nt&&(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)),ks&&Nl<=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,E;if((Hd&&n.input.lastIOSEnter>Date.now()-225&&(!C||s.some(B=>B.nodeName=="DIV"||B.nodeName=="P"))||!C&&v.pos<c.doc.content.size&&(!v.sameParent(x)||!v.parent.inlineContent)&&(E=at.findFrom(c.doc.resolve(v.pos+1),1,!0))&&E.head>v.pos)&&n.someProp("handleKeyDown",B=>B(n,Rc(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>y.start&&eZ(d,y.start,y.endA,v,x)&&n.someProp("handleKeyDown",B=>B(n,Rc(8,"Backspace")))){ka&&kr&&n.domObserver.suppressSelectionUpdates();return}kr&&y.endB==y.start&&(n.input.lastChromeDelete=Date.now()),ka&&!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(B){return B(n,Rc(13,"Enter"))})},20));let _=y.start,M=y.endA,A,O,D;if(C){if(v.pos==x.pos)ks&&Nl<=11&&v.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>Ma(n),20)),A=n.state.tr.delete(_,M),O=d.resolve(y.start).marksAcross(d.resolve(y.endA));else if(y.endA==y.endB&&(D=QX(v.parent.content.cut(v.parentOffset,x.parentOffset),b.parent.content.cut(b.parentOffset,y.endA-b.start()))))A=n.state.tr,D.type=="add"?A.addMark(_,M,D.mark):A.removeMark(_,M,D.mark);else if(v.parent.child(v.index()).isText&&v.index()==x.index()-(x.textOffset?0:1)){let B=v.parent.textBetween(v.parentOffset,x.parentOffset);if(n.someProp("handleTextInput",U=>U(n,_,M,B)))return;A=n.state.tr.insertText(B,_,M)}}if(A||(A=n.state.tr.replace(_,M,c.doc.slice(y.start-c.from,y.endB-c.from))),c.sel){let B=CD(n,A.doc,c.sel);B&&!(kr&&n.composing&&B.empty&&(y.start!=y.endB||n.input.lastChromeDelete<Date.now()-100)&&(B.head==_||B.head==A.mapping.map(M)-1)||ks&&B.empty&&B.head==_)&&A.setSelection(B)}O&&A.ensureMarks(O),i&&A.setMeta("composition",i),n.dispatch(A.scrollIntoView())}function CD(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:UI(n,e.resolve(t.anchor),e.resolve(t.head))}function QX(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 eZ(n,e,t,r,s){if(t-e<=s.pos-r.pos||K1(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(K1(i,!0,!0));return!o.parent.isTextblock||o.pos>t||K1(o,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function K1(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 tZ(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&&PD(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&&PD(n.textBetween(i-1,i+1))&&(i+=l?1:-1),o=i+(o-a),a=i}return{start:i,endA:o,endB:a}}function PD(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 nZ{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 xX,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(TD),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=ED(this),ID(this),this.nodeViews=_D(this),this.docView=iD(this.state.doc,kD(this),H1(this),this.dom,this),this.domObserver=new WX(this,(r,s,i,o)=>JX(this,r,s,i,o)),this.domObserver.start(),wX(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&&VP(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(TD),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&&(s5(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=_D(this);sZ(m,this.nodeViews)&&(this.nodeViews=m,i=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&VP(this),this.editable=ED(this),ID(this);let l=H1(this),c=kD(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 g=d=="preserve"&&o&&this.dom.style.overflowAnchor==null&&jY(this);if(o){this.domObserver.stop();let m=f&&(ks||kr)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&rZ(s.selection,e.selection);if(f){let y=kr?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=DX(this)),(i||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=iD(e.doc,c,l,this.dom,this)),y&&!this.trackWrites&&(m=!0)}m||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&iX(this))?Ma(this,m):(VF(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():g&&NY(g)}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 Ke){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&QR(this,t.getBoundingClientRect(),e)}else QR(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 o5(e.slice,e.move,s<0?void 0:Ke.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(ks){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&&LY(this.dom),Ma(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 UY(this,e)}coordsAtPos(e,t=1){return FF(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 qY(this,t||this.state,e)}pasteHTML(e,t){return op(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return op(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return HI(this,e)}destroy(){this.docView&&(bX(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],H1(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,PY())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return PX(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?Hr&&this.root.nodeType===11&&TY(this.dom.ownerDocument)==this.dom&&qX(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function kD(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"),[Si.node(0,n.state.doc.content.size,e)]}function ID(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:Si.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function ED(n){return!n.someProp("editable",e=>e(n.state)===!1)}function rZ(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 _D(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 sZ(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 TD(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 $l={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:"'"},nS={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},iZ=typeof navigator<"u"&&/Mac/.test(navigator.platform),oZ=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var rr=0;rr<10;rr++)$l[48+rr]=$l[96+rr]=String(rr);for(var rr=1;rr<=24;rr++)$l[rr+111]="F"+rr;for(var rr=65;rr<=90;rr++)$l[rr]=String.fromCharCode(rr+32),nS[rr]=String.fromCharCode(rr);for(var W1 in $l)nS.hasOwnProperty(W1)||(nS[W1]=$l[W1]);function aZ(n){var e=iZ&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||oZ&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?nS:$l)[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 lZ=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function cZ(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))lZ?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 uZ(n){let e=Object.create(null);for(let t in n)e[cZ(t)]=n[t];return e}function V1(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 dZ(n){return new ur({props:{handleKeyDown:d5(n)}})}function d5(n){let e=uZ(n);return function(t,r){let s=aZ(r),i,o=e[V1(s,r)];if(o&&o(t.state,t.dispatch,t))return!0;if(s.length==1&&s!=" "){if(r.shiftKey){let a=e[V1(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=$l[r.keyCode])&&i!=s){let a=e[V1(i,r)];if(a&&a(t.state,t.dispatch,t))return!0}}return!1}}const YI=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function h5(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const f5=(n,e,t)=>{let r=h5(n,t);if(!r)return!1;let s=XI(r);if(!s){let o=r.blockRange(),a=o&&lh(o);return a==null?!1:(e&&e(n.tr.lift(o,a).scrollIntoView()),!0)}let i=s.nodeBefore;if(b5(n,s,e,-1))return!0;if(r.parent.content.size==0&&(Kd(i,"end")||Ke.isSelectable(i)))for(let o=r.depth;;o--){let a=k0(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(Kd(i,"end")?at.findFrom(l.doc.resolve(l.mapping.map(s.pos,-1)),-1):Ke.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},hZ=(n,e,t)=>{let r=h5(n,t);if(!r)return!1;let s=XI(r);return s?p5(n,s,e):!1},fZ=(n,e,t)=>{let r=m5(n,t);if(!r)return!1;let s=ZI(r);return s?p5(n,s,e):!1};function p5(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=k0(n.doc,i,l,Te.empty);if(!c||c.from!=i||c instanceof $n&&c.slice.size>=l-i)return!1;if(t){let d=n.tr.step(c);d.setSelection(nt.create(d.doc,i)),t(d.scrollIntoView())}return!0}function Kd(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 g5=(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=XI(r)}let o=i&&i.nodeBefore;return!o||!Ke.isSelectable(o)?!1:(e&&e(n.tr.setSelection(Ke.create(n.doc,i.pos-o.nodeSize)).scrollIntoView()),!0)};function XI(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 m5(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const y5=(n,e,t)=>{let r=m5(n,t);if(!r)return!1;let s=ZI(r);if(!s)return!1;let i=s.nodeAfter;if(b5(n,s,e,1))return!0;if(r.parent.content.size==0&&(Kd(i,"start")||Ke.isSelectable(i))){let o=k0(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(Kd(i,"start")?at.findFrom(a.doc.resolve(a.mapping.map(s.pos)),1):Ke.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},S5=(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=ZI(r)}let o=i&&i.nodeAfter;return!o||!Ke.isSelectable(o)?!1:(e&&e(n.tr.setSelection(Ke.create(n.doc,i.pos)).scrollIntoView()),!0)};function ZI(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 pZ=(n,e)=>{let t=n.selection,r=t instanceof Ke,s;if(r){if(t.node.isTextblock||!Ql(n.doc,t.from))return!1;s=t.from}else if(s=P0(n.doc,t.from,-1),s==null)return!1;if(e){let i=n.tr.join(s);r&&i.setSelection(Ke.create(i.doc,s-n.doc.resolve(s).nodeBefore.nodeSize)),e(i.scrollIntoView())}return!0},gZ=(n,e)=>{let t=n.selection,r;if(t instanceof Ke){if(t.node.isTextblock||!Ql(n.doc,t.to))return!1;r=t.to}else if(r=P0(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},mZ=(n,e)=>{let{$from:t,$to:r}=n.selection,s=t.blockRange(r),i=s&&lh(s);return i==null?!1:(e&&e(n.tr.lift(s,i).scrollIntoView()),!0)},v5=(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 JI(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 yZ=(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=JI(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},x5=(n,e)=>{let t=n.selection,{$from:r,$to:s}=t;if(t instanceof Vs||r.parent.inlineContent||s.parent.inlineContent)return!1;let i=JI(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(nt.create(a.doc,o+1)),e(a.scrollIntoView())}return!0},w5=(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(Ta(n.doc,i))return e&&e(n.tr.split(i).scrollIntoView()),!0}let r=t.blockRange(),s=r&&lh(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)};function SZ(n){return(e,t)=>{let{$from:r,$to:s}=e.selection;if(e.selection instanceof Ke&&e.selection.node.isBlock)return!r.parentOffset||!Ta(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=JI(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 nt||e.selection instanceof Vs)&&d.deleteSelection();let f=d.mapping.map(r.pos),g=Ta(d.doc,f,i.length,i);if(g||(i[0]=a?{type:a}:null,g=Ta(d.doc,f,i.length,i)),!g)return!1;if(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 vZ=SZ(),xZ=(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(Ke.create(n.doc,s))),!0)};function wZ(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||Ql(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function b5(n,e,t,r){let s=e.nodeBefore,i=e.nodeAfter,o,a,l=s.type.spec.isolating||i.type.spec.isolating;if(!l&&wZ(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 Hn(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&&Ql(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),g=f&&lh(f);if(g!=null&&g>=e.depth)return t&&t(n.tr.lift(f,g).scrollIntoView()),!0;if(c&&Kd(i,"start",!0)&&Kd(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 E=y.length-1;E>=0;E--)b=pe.from(y[E].copy(b));let C=n.tr.step(new Hn(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 C5(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(nt.create(e.doc,n<0?s.start(i):s.end(i)))),!0):!1}}const bZ=C5(-1),CZ=C5(1);function PZ(n,e=null){return function(t,r){let{$from:s,$to:i}=t.selection,o=s.blockRange(i),a=o&&FI(o,n,e);return a?(r&&r(t.tr.wrap(o,a).scrollIntoView()),!0):!1}}function MD(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 QI(...n){return function(e,t,r){for(let s=0;s<n.length;s++)if(n[s](e,t,r))return!0;return!1}}QI(YI,f5,g5);QI(YI,y5,S5);QI(v5,x5,w5,vZ);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function kZ(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 IZ(a,o,n,e)?(r&&r(a.scrollIntoView()),!0):!1}}function IZ(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 Yy(l,l,e.depth),e.endIndex<e.parent.childCount&&(e=new Yy(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),s=!0}let a=FI(i,t,r,e);return a?(n&&EZ(n,e,a,s,t),!0):!1}function EZ(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 Hn(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,g=!0;d<f;d++,g=!1)!g&&Ta(n.doc,l,a)&&(n.split(l,a),l+=2*a),l+=c.child(d).nodeSize;return n}function _Z(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?TZ(e,t,n,i):MZ(e,t,i):!0:!1}}function TZ(n,e,t,r){let s=n.tr,i=r.end,o=r.$to.end(r.depth);i<o&&(s.step(new Hn(i-1,o,i,o,new Te(pe.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new Yy(s.doc.resolve(r.$from.pos),s.doc.resolve(o),r.depth));const a=lh(r);if(a==null)return!1;s.lift(r,a);let l=s.doc.resolve(s.mapping.map(i,-1)-1);return Ql(s.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&s.join(l.pos),e(s.scrollIntoView()),!0}function MZ(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,g=f+o.nodeSize;return r.step(new Hn(f-(a?1:0),g+(l?1:0),f+1,g-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 AZ(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),g=i.start,m=i.end;t(e.tr.step(new Hn(g-(c?3:1),m,g,m,f,1,!0)).scrollIntoView())}return!0}}function M0(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 A0{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(g=>g===!0)),f={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...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:M0({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 OZ=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 O0(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 P5(n){const e=[],{nodeExtensions:t,markExtensions:r}=O0(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(([g,m])=>{e.push({type:f,name:g,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 g={...i,...f};typeof(g==null?void 0:g.default)=="function"&&(g.default=g.default()),g!=null&&g.isRequired&&(g==null?void 0:g.default)===void 0&&delete g.default,e.push({type:o.name,name:d,attribute:g})})}),e}function Wn(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 Vn(...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,g]=d.split(":").map(m=>m.trim());c.set(f,g)}),a.forEach(d=>{const[f,g]=d.split(":").map(m=>m.trim());c.set(f,g)}),r[s]=Array.from(c.entries()).map(([d,f])=>`${d}: ${f}`).join("; ")}else r[s]=i}),r},{})}function qP(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)=>Vn(t,r),{})}function k5(n){return typeof n=="function"}function ft(n,e=void 0,...t){return k5(n)?e?n.bind(e)(...t):n(...t):n}function RZ(n={}){return Object.keys(n).length===0&&n.constructor===Object}function DZ(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function AD(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):DZ(t.getAttribute(o.name));return a==null?i:{...i,[o.name]:a}},{});return{...r,...s}}}}function OD(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&RZ(t)?!1:t!=null))}function I5(n,e){var t;const r=P5(n),{nodeExtensions:s,markExtensions:i}=O0(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},g=n.reduce((b,C)=>{const E=Le(C,"extendNodeSchema",f);return{...b,...E?E(c):{}}},{}),m=OD({...g,content:ft(Le(c,"content",f)),marks:ft(Le(c,"marks",f)),group:ft(Le(c,"group",f)),inline:ft(Le(c,"inline",f)),atom:ft(Le(c,"atom",f)),selectable:ft(Le(c,"selectable",f)),draggable:ft(Le(c,"draggable",f)),code:ft(Le(c,"code",f)),whitespace:ft(Le(c,"whitespace",f)),linebreakReplacement:ft(Le(c,"linebreakReplacement",f)),defining:ft(Le(c,"defining",f)),isolating:ft(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=ft(Le(c,"parseHTML",f));y&&(m.parseDOM=y.map(b=>AD(b,d)));const v=Le(c,"renderHTML",f);v&&(m.toDOM=b=>v({node:b,HTMLAttributes:qP(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},g=n.reduce((x,b)=>{const C=Le(b,"extendMarkSchema",f);return{...x,...C?C(c):{}}},{}),m=OD({...g,inclusive:ft(Le(c,"inclusive",f)),excludes:ft(Le(c,"excludes",f)),group:ft(Le(c,"group",f)),spanning:ft(Le(c,"spanning",f)),code:ft(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=ft(Le(c,"parseHTML",f));y&&(m.parseDOM=y.map(x=>AD(x,d)));const v=Le(c,"renderHTML",f);return v&&(m.toDOM=x=>v({mark:x,HTMLAttributes:qP(x,d)})),[c.name,m]}));return new fF({topNode:o,nodes:a,marks:l})}function q1(n,e){return e.nodes[n]||e.marks[n]||null}function RD(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function R0(n,e){const t=mu.fromSchema(e).serializeFragment(n),s=document.implementation.createHTMLDocument().createElement("div");return s.appendChild(t),s.innerHTML}const jZ=(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 eE(n){return Object.prototype.toString.call(n)==="[object RegExp]"}class D0{constructor(e){this.find=e.find,this.handler=e.handler}}const NZ=(n,e)=>{if(eE(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 pm(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(g=>g.type.spec.code))return!1;let d=!1;const f=jZ(c)+i;return o.forEach(g=>{if(d)return;const m=NZ(f,g.find);if(!m)return;const y=l.state.tr,v=M0({state:l.state,transaction:y}),x={from:r-(m[0].length-i.length),to:s},{commands:b,chain:C,can:E}=new A0({editor:t,state:v});g.handler({state:v,range:x,match:m,commands:b,chain:C,can:E})===null||!y.steps.length||(y.setMeta(a,{transform:y,from:r,to:s,text:i}),l.dispatch(y),d=!0)}),d}function LZ(n){const{editor:e,rules:t}=n,r=new ur({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=R0(pe.from(d),o.schema);const{from:f}=l,g=f+d.length;pm({editor:e,from:f,to:g,text:d,rules:t,plugin:r})}),s.selectionSet||s.docChanged?null:i}},props:{handleTextInput(s,i,o,a){return pm({editor:e,from:i,to:o,text:a,rules:t,plugin:r})},handleDOMEvents:{compositionend:s=>(setTimeout(()=>{const{$cursor:i}=s.state.selection;i&&pm({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?pm({editor:e,from:o.pos,to:o.pos,text:`
95
+ `,rules:t,plugin:r}):!1}},isInputRules:!0});return r}function FZ(n){return Object.prototype.toString.call(n).slice(8,-1)}function gm(n){return FZ(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function j0(n,e){const t={...n};return gm(n)&&gm(e)&&Object.keys(e).forEach(r=>{gm(e[r])&&gm(n[r])?t[r]=j0(n[r],e[r]):t[r]=e[r]}),t}class $o{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=ft(Le(this,"addOptions",{name:this.name}))),this.storage=ft(Le(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new $o(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>j0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new $o(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=ft(Le(t,"addOptions",{name:t.name})),t.storage=ft(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 zZ(n){return typeof n=="number"}class $Z{constructor(e){this.find=e.find,this.handler=e.handler}}const BZ=(n,e,t)=>{if(eE(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 UZ(n){const{editor:e,state:t,from:r,to:s,rule:i,pasteEvent:o,dropEvent:a}=n,{commands:l,chain:c,can:d}=new A0({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,"");BZ(b,i.find,o).forEach(E=>{if(E.index===void 0)return;const _=v+E.index+1,M=_+E[0].length,A={from:t.tr.mapping.map(_),to:t.tr.mapping.map(M)},O=i.handler({state:t,range:A,match:E,commands:l,chain:c,can:d,pasteEvent:o,dropEvent:a});f.push(O)})}),f.every(m=>m!==null)}let mm=null;const HZ=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 KZ(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:g,rule:m,pasteEvt:y})=>{const v=d.tr,x=M0({state:d,transaction:v});if(!(!UZ({editor:e,state:x,from:Math.max(f-1,0),to:g.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 ur({view(f){const g=y=>{var v;r=!((v=f.dom.parentElement)===null||v===void 0)&&v.contains(y.target)?f.dom.parentElement:null,r&&(mm=e)},m=()=>{mm&&(mm=null)};return window.addEventListener("dragstart",g),window.addEventListener("dragend",m),{destroy(){window.removeEventListener("dragstart",g),window.removeEventListener("dragend",m)}}},props:{handleDOMEvents:{drop:(f,g)=>{if(i=r===f.dom.parentElement,a=g,!i){const m=mm;m&&setTimeout(()=>{const y=m.state.selection;y&&m.commands.deleteRange({from:y.from,to:y.to})},10)}return!1},paste:(f,g)=>{var m;const y=(m=g.clipboardData)===null||m===void 0?void 0:m.getData("text/html");return o=g,s=!!(y!=null&&y.includes("data-pm-slice")),!1}}},appendTransaction:(f,g,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:M}=b;typeof M=="string"?M=M:M=R0(pe.from(M),m.schema);const{from:A}=b,O=A+M.length,D=HZ(M);return l({rule:d,state:m,from:A,to:{b:O},pasteEvt:D})}const E=g.doc.content.findDiffStart(m.doc.content),_=g.doc.content.findDiffEnd(m.doc.content);if(!(!zZ(E)||!_||E===_.b))return l({rule:d,state:m,from:E,to:_,pasteEvt:o})}}))}function WZ(n){const e=n.filter((t,r)=>n.indexOf(t)!==r);return Array.from(new Set(e))}class Lc{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=Lc.resolve(e),this.schema=I5(this.extensions,t),this.setupExtensions()}static resolve(e){const t=Lc.sort(Lc.flatten(e)),r=WZ(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:q1(t.name,this.schema)},s=Le(t,"addCommands",r);return s?{...e,...s()}:e},{})}get plugins(){const{editor:e}=this,t=Lc.sort([...this.extensions].reverse()),r=[],s=[],i=t.map(o=>{const a={name:o.name,options:o.options,storage:o.storage,editor:e,type:q1(o.name,this.schema)},l=[],c=Le(o,"addKeyboardShortcuts",a);let d={};if(o.type==="mark"&&Le(o,"exitable",a)&&(d.ArrowRight=()=>$o.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=dZ(d);l.push(f);const g=Le(o,"addInputRules",a);RD(o,e.options.enableInputRules)&&g&&r.push(...g());const m=Le(o,"addPasteRules",a);RD(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[LZ({editor:e,rules:r}),...KZ({editor:e,rules:s}),...i]}get attributes(){return P5(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=O0(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:Wn(r.name,this.schema)},o=Le(r,"addNodeView",i);if(!o)return[];const a=(l,c,d,f,g)=>{const m=qP(l,s);return o()({node:l,view:c,getPos:d,decorations:f,innerDecorations:g,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:q1(e.name,this.schema)};e.type==="mark"&&(!((t=ft(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 lr{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=ft(Le(this,"addOptions",{name:this.name}))),this.storage=ft(Le(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new lr(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>j0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new lr({...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=ft(Le(t,"addOptions",{name:t.name})),t.storage=ft(Le(t,"addStorage",{name:t.name,options:t.options})),t}}function E5(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 g;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+=(g=l==null?void 0:l.text)===null||g===void 0?void 0:g.slice(Math.max(r,c)-c,s-c))}),a}function tE(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const VZ=lr.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new ur({key:new Zs("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=tE(t);return E5(r,{from:o,to:a},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),qZ=()=>({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),GZ=(n=!1)=>({commands:e})=>e.setContent("",n),YZ=()=>({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)),g=c.resolve(d.map(l+a.nodeSize)),m=f.blockRange(g);if(!m)return;const y=lh(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},XZ=n=>e=>n(e),ZZ=()=>({state:n,dispatch:e})=>x5(n,e),JZ=(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 nt(r.doc.resolve(o-1))),!0},QZ=()=>({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},eJ=n=>({tr:e,state:t,dispatch:r})=>{const s=Wn(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},tJ=n=>({tr:e,dispatch:t})=>{const{from:r,to:s}=n;return t&&e.delete(r,s),!0},nJ=()=>({state:n,dispatch:e})=>YI(n,e),rJ=()=>({commands:n})=>n.keyboardShortcut("Enter"),sJ=()=>({state:n,dispatch:e})=>yZ(n,e);function rS(n,e,t={strict:!0}){const r=Object.keys(e);return r.length?r.every(s=>t.strict?e[s]===n[s]:eE(e[s])?e[s].test(n[s]):e[s]===n[s]):!0}function _5(n,e,t={}){return n.find(r=>r.type===e&&rS(Object.fromEntries(Object.keys(t).map(s=>[s,r.attrs[s]])),t))}function DD(n,e,t={}){return!!_5(n,e,t)}function N0(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),!_5([...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&&DD([...n.parent.child(o-1).marks],e,t);)o-=1,a-=n.parent.child(o).nodeSize;for(;l<n.parent.childCount&&DD([...n.parent.child(l).marks],e,t);)c+=n.parent.child(l).nodeSize,l+=1;return{from:a,to:c}}function tc(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 iJ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{const i=tc(n,r.schema),{doc:o,selection:a}=t,{$from:l,from:c,to:d}=a;if(s){const f=N0(l,i,e);if(f&&f.from<=c&&f.to>=d){const g=nt.create(o,f.from,f.to);t.setSelection(g)}}return!0},oJ=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 T5(n){return n instanceof nt}function Fc(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function M5(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"?nt.create(n,Fc(0,s,i),Fc(n.content.size,s,i)):nt.create(n,Fc(e,s,i),Fc(e,s,i))}function aJ(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function nE(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const lJ=(n=null,e={})=>({editor:t,view:r,tr:s,dispatch:i})=>{e={scrollIntoView:!0,...e};const o=()=>{(nE()||aJ())&&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&&!T5(t.state.selection))return o(),!0;const a=M5(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},cJ=(n,e)=>t=>n.every((r,s)=>e(r,{...t,index:s})),uJ=(n,e)=>({tr:t,commands:r})=>r.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),A5=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&&A5(r)}return n};function bf(n){const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return A5(t)}function sS(n,e,t){if(n instanceof Xi||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),sS("",e,t)}if(s){if(t.errorOnInvalidContent){let o=!1,a="";const l=new fF({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?Ed.fromSchema(l).parseSlice(bf(n),t.parseOptions):Ed.fromSchema(l).parse(bf(n),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${a}`)})}const i=Ed.fromSchema(e);return t.slice?i.parseSlice(bf(n),t.parseOptions).content:i.parse(bf(n),t.parseOptions)}return sS("",e,t)}function dJ(n,e,t){const r=n.steps.length-1;if(r<e)return;const s=n.steps[r];if(!(s instanceof $n||s instanceof Hn))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 hJ=n=>!("type"in n),fJ=(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=sS(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((hJ(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&&dJ(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},pJ=()=>({state:n,dispatch:e})=>pZ(n,e),gJ=()=>({state:n,dispatch:e})=>gZ(n,e),mJ=()=>({state:n,dispatch:e})=>f5(n,e),yJ=()=>({state:n,dispatch:e})=>y5(n,e),SJ=()=>({state:n,dispatch:e,tr:t})=>{try{const r=P0(n.doc,n.selection.$from.pos,-1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},vJ=()=>({state:n,dispatch:e,tr:t})=>{try{const r=P0(n.doc,n.selection.$from.pos,1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},xJ=()=>({state:n,dispatch:e})=>hZ(n,e),wJ=()=>({state:n,dispatch:e})=>fZ(n,e);function O5(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function bJ(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))nE()||O5()?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 CJ=n=>({editor:e,view:t,tr:r,dispatch:s})=>{const i=bJ(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 lp(n,e,t={}){const{from:r,to:s,empty:i}=n.selection,o=e?Wn(e,n.schema):null,a=[];n.doc.nodesBetween(r,s,(f,g)=>{if(f.isText)return;const m=Math.max(r,g),y=Math.min(s,g+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=>rS(f.node.attrs,t,{strict:!1}));return i?!!c.length:c.reduce((f,g)=>f+g.to-g.from,0)>=l}const PJ=(n,e={})=>({state:t,dispatch:r})=>{const s=Wn(n,t.schema);return lp(t,s,e)?mZ(t,r):!1},kJ=()=>({state:n,dispatch:e})=>w5(n,e),IJ=n=>({state:e,dispatch:t})=>{const r=Wn(n,e.schema);return _Z(r)(e,t)},EJ=()=>({state:n,dispatch:e})=>v5(n,e);function L0(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function jD(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 _J=(n,e)=>({tr:t,state:r,dispatch:s})=>{let i=null,o=null;const a=L0(typeof n=="string"?n:n.name,r.schema);return a?(a==="node"&&(i=Wn(n,r.schema)),a==="mark"&&(o=tc(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,jD(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(f=>{o===f.type&&t.addMark(d,d+c.nodeSize,o.create(jD(f.attrs,e)))})})}),!0):!1},TJ=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),MJ=()=>({tr:n,dispatch:e})=>{if(e){const t=new Vs(n.doc);n.setSelection(t)}return!0},AJ=()=>({state:n,dispatch:e})=>g5(n,e),OJ=()=>({state:n,dispatch:e})=>S5(n,e),RJ=()=>({state:n,dispatch:e})=>xZ(n,e),DJ=()=>({state:n,dispatch:e})=>CZ(n,e),jJ=()=>({state:n,dispatch:e})=>bZ(n,e);function GP(n,e,t={},r={}){return sS(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:r.errorOnInvalidContent})}const NJ=(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=GP(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 R5(n,e){const t=tc(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 LJ(n,e){const t=new TF(n);return e.forEach(r=>{r.steps.forEach(s=>{t.step(s)})}),t}function FJ(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 zJ(n,e,t){const r=[];return n.nodesBetween(e.from,e.to,(s,i)=>{t(s)&&r.push({node:s,pos:i})}),r}function $J(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 rE(n){return e=>$J(e.$from,n)}function F0(n,e){const t=Lc.resolve(n);return I5(t,e)}function BJ(n,e){const t=F0(e),r=Xi.fromJSON(t,n);return R0(r.content,t)}function UJ(n,e){const t=F0(e),r=bf(n);return Ed.fromSchema(t).parse(r).toJSON()}function D5(n,e){const t={from:0,to:n.content.size};return E5(n,t,e)}function HJ(n,e,t){const{blockSeparator:r=`
98
+
99
+ `,textSerializers:s={}}=t||{},i=F0(e),o=Xi.fromJSON(i,n);return D5(o,{blockSeparator:r,textSerializers:{...tE(i),...s}})}function KJ(n,e){const t=Wn(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 j5(n,e){const t=L0(typeof e=="string"?e:e.name,n.schema);return t==="node"?KJ(n,e):t==="mark"?R5(n,e):{}}function WJ(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 VJ(n){const e=WJ(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 qJ(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),g=e.invert().map(d);r.push({oldRange:{from:f,to:g},newRange:{from:c,to:d}})})}),VJ(r)}function sE(n,e,t){const r=[];return n===e?t.resolve(n).marks().forEach(s=>{const i=t.resolve(n),o=N0(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 sy(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 YP(n,e,t={}){const{empty:r,ranges:s}=n.selection,i=e?tc(e,n.schema):null;if(r)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>i?i.name===f.type.name:!0).find(f=>rS(f.attrs,t,{strict:!1}));let o=0;const a=[];if(s.forEach(({$from:f,$to:g})=>{const m=f.pos,y=g.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),E=C-b;o+=E,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=>rS(f.mark.attrs,t,{strict:!1})).reduce((f,g)=>f+g.to-g.from,0),c=a.filter(f=>i?f.mark.type!==i&&f.mark.type.excludes(i):!0).reduce((f,g)=>f+g.to-g.from,0);return(l>0?l+c:l)>=o}function GJ(n,e,t={}){if(!e)return lp(n,null,t)||YP(n,null,t);const r=L0(e,n.schema);return r==="node"?lp(n,e,t):r==="mark"?YP(n,e,t):!1}function ND(n,e){const{nodeExtensions:t}=O0(e),r=t.find(o=>o.name===n);if(!r)return!1;const s={name:r.name,options:r.options,storage:r.storage},i=ft(Le(r,"group",s));return typeof i!="string"?!1:i.split(" ").includes("list")}function iE(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&&(iE(i,{ignoreWhitespace:t,checkChildren:e})||(s=!1))}),s}return!1}function YJ(n){return n instanceof Ke}function XJ(n,e,t){var r;const{selection:s}=e;let i=null;if(T5(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,g)=>{if(c)return!1;if(d.isInline){const m=!g||g.type.allowsMarkType(t),y=!!t.isInSet(d.marks)||!d.marks.some(v=>v.type.excludes(t));c=m&&y}return!c}),c})}const ZJ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{const{selection:i}=t,{empty:o,ranges:a}=i,l=tc(n,r.schema);if(s)if(o){const c=R5(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,(g,m)=>{const y=Math.max(m,d),v=Math.min(m+g.nodeSize,f);g.marks.find(b=>b.type===l)?g.marks.forEach(b=>{l===b.type&&t.addMark(y,v,l.create({...b.attrs,...e}))}):t.addMark(y,v,l.create(e))})});return XJ(r,t,l)},JJ=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),QJ=(n,e={})=>({state:t,dispatch:r,chain:s})=>{const i=Wn(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})=>MD(i,{...o,...e})(t)?!0:a.clearNodes()).command(({state:a})=>MD(i,{...o,...e})(a,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},eQ=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,s=Fc(n,0,r.content.size),i=Ke.create(r,s);e.setSelection(i)}return!0},tQ=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,{from:s,to:i}=typeof n=="number"?{from:n,to:n}:n,o=nt.atStart(r).from,a=nt.atEnd(r).to,l=Fc(s,o,a),c=Fc(i,o,a),d=nt.create(r,l,c);e.setSelection(d)}return!0},nQ=n=>({state:e,dispatch:t})=>{const r=Wn(n,e.schema);return AZ(r)(e,t)};function LD(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 rQ=({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=sy(c,a.node().type.name,a.node().attrs);if(i instanceof Ke&&i.node.isBlock)return!a.parentOffset||!Ta(o,a.pos)?!1:(r&&(n&&LD(t,s.extensionManager.splittableMarks),e.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;const f=l.parentOffset===l.parent.content.size,g=a.depth===0?void 0:FJ(a.node(-1).contentMatchAt(a.indexAfter(-1)));let m=f&&g?[{type:g,attrs:d}]:void 0,y=Ta(e.doc,e.mapping.map(a.pos),1,m);if(!m&&!y&&Ta(e.doc,e.mapping.map(a.pos),1,g?[{type:g}]:void 0)&&(y=!0,m=g?[{type:g,attrs:d}]:void 0),r){if(y&&(i instanceof nt&&e.deleteSelection(),e.split(e.mapping.map(a.pos),1,m),g&&!f&&!a.parentOffset&&a.parent.type!==g)){const v=e.mapping.map(a.before()),x=e.doc.resolve(v);a.node(-1).canReplaceWith(x.index(),x.index()+1,g)&&e.setNodeMarkup(e.mapping.map(a.before()),g)}n&&LD(t,s.extensionManager.splittableMarks),e.scrollIntoView()}return y},sQ=(n,e={})=>({tr:t,state:r,dispatch:s,editor:i})=>{var o;const a=Wn(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 g=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 D=l.depth-C;D>=l.depth-3;D-=1)b=pe.from(l.node(D).copy(b));const E=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,_={...sy(g,l.node().type.name,l.node().attrs),...e},M=((o=a.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(_))||void 0;b=b.append(pe.from(a.createAndFill(null,M)||void 0));const A=l.before(l.depth-(C-1));t.replace(A,l.after(-E),new Te(b,4-C,0));let O=-1;t.doc.nodesBetween(A,t.doc.content.size,(D,B)=>{if(O>-1)return!1;D.isTextblock&&D.content.size===0&&(O=B+1)}),O>-1&&t.setSelection(nt.near(t.doc.resolve(O))),t.scrollIntoView()}return!0}const m=c.pos===l.end()?f.contentMatchAt(0).defaultType:null,y={...sy(g,f.type.name,f.attrs),...e},v={...sy(g,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(!Ta(t.doc,l.pos,2))return!1;if(s){const{selection:b,storedMarks:C}=r,{splittableMarks:E}=i.extensionManager,_=C||b.$to.parentOffset&&b.$from.marks();if(t.split(l.pos,2,x).scrollIntoView(),!_||!s)return!0;const M=_.filter(A=>E.includes(A.type.name));t.ensureMarks(M)}return!0},G1=(n,e)=>{const t=rE(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)&&Ql(n.doc,t.pos)&&n.join(t.pos),!0},Y1=(n,e)=>{const t=rE(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)&&Ql(n.doc,r)&&n.join(r),!0},iQ=(n,e,t,r={})=>({editor:s,tr:i,state:o,dispatch:a,chain:l,commands:c,can:d})=>{const{extensions:f,splittableMarks:g}=s.extensionManager,m=Wn(n,o.schema),y=Wn(e,o.schema),{selection:v,storedMarks:x}=o,{$from:b,$to:C}=v,E=b.blockRange(C),_=x||v.$to.parentOffset&&v.$from.marks();if(!E)return!1;const M=rE(A=>ND(A.type.name,f))(v);if(E.depth>=1&&M&&E.depth-M.depth<=1){if(M.node.type===m)return c.liftListItem(y);if(ND(M.node.type.name,f)&&m.validContent(M.node.content)&&a)return l().command(()=>(i.setNodeMarkup(M.pos,m),!0)).command(()=>G1(i,m)).command(()=>Y1(i,m)).run()}return!t||!_||!a?l().command(()=>d().wrapInList(m,r)?!0:c.clearNodes()).wrapInList(m,r).command(()=>G1(i,m)).command(()=>Y1(i,m)).run():l().command(()=>{const A=d().wrapInList(m,r),O=_.filter(D=>g.includes(D.type.name));return i.ensureMarks(O),A?!0:c.clearNodes()}).wrapInList(m,r).command(()=>G1(i,m)).command(()=>Y1(i,m)).run()},oQ=(n,e={},t={})=>({state:r,commands:s})=>{const{extendEmptyMarkRange:i=!1}=t,o=tc(n,r.schema);return YP(r,o,e)?s.unsetMark(o,{extendEmptyMarkRange:i}):s.setMark(o,e)},aQ=(n,e,t={})=>({state:r,commands:s})=>{const i=Wn(n,r.schema),o=Wn(e,r.schema),a=lp(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})},lQ=(n,e={})=>({state:t,commands:r})=>{const s=Wn(n,t.schema);return lp(t,s,e)?r.lift(s):r.wrapIn(s,e)},cQ=()=>({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},uQ=()=>({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},dQ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{var i;const{extendEmptyMarkRange:o=!1}=e,{selection:a}=t,l=tc(n,r.schema),{$from:c,empty:d,ranges:f}=a;if(!s)return!0;if(d&&o){let{from:g,to:m}=a;const y=(i=c.marks().find(x=>x.type===l))===null||i===void 0?void 0:i.attrs,v=N0(c,l,y);v&&(g=v.from,m=v.to),t.removeMark(g,m,l)}else f.forEach(g=>{t.removeMark(g.$from.pos,g.$to.pos,l)});return t.removeStoredMark(l),!0},hQ=(n,e={})=>({tr:t,state:r,dispatch:s})=>{let i=null,o=null;const a=L0(typeof n=="string"?n:n.name,r.schema);return a?(a==="node"&&(i=Wn(n,r.schema)),a==="mark"&&(o=tc(n,r.schema)),s&&t.selection.ranges.forEach(l=>{const c=l.$from.pos,d=l.$to.pos;let f,g,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,g=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,g=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),E=Math.min(x+v.nodeSize,d);t.addMark(C,E,o.create({...b.attrs,...e}))}}))}),g&&(f!==void 0&&t.setNodeMarkup(f,void 0,{...g.attrs,...e}),o&&g.marks.length&&g.marks.forEach(v=>{o===v.type&&t.addMark(m,y,o.create({...v.attrs,...e}))}))}),!0):!1},fQ=(n,e={})=>({state:t,dispatch:r})=>{const s=Wn(n,t.schema);return PZ(s,e)(t,r)},pQ=(n,e={})=>({state:t,dispatch:r})=>{const s=Wn(n,t.schema);return kZ(s,e)(t,r)};var gQ=Object.freeze({__proto__:null,blur:qZ,clearContent:GZ,clearNodes:YZ,command:XZ,createParagraphNear:ZZ,cut:JZ,deleteCurrentNode:QZ,deleteNode:eJ,deleteRange:tJ,deleteSelection:nJ,enter:rJ,exitCode:sJ,extendMarkRange:iJ,first:oJ,focus:lJ,forEach:cJ,insertContent:uJ,insertContentAt:fJ,joinBackward:mJ,joinDown:gJ,joinForward:yJ,joinItemBackward:SJ,joinItemForward:vJ,joinTextblockBackward:xJ,joinTextblockForward:wJ,joinUp:pJ,keyboardShortcut:CJ,lift:PJ,liftEmptyBlock:kJ,liftListItem:IJ,newlineInCode:EJ,resetAttributes:_J,scrollIntoView:TJ,selectAll:MJ,selectNodeBackward:AJ,selectNodeForward:OJ,selectParentNode:RJ,selectTextblockEnd:DJ,selectTextblockStart:jJ,setContent:NJ,setMark:ZJ,setMeta:JJ,setNode:QJ,setNodeSelection:eQ,setTextSelection:tQ,sinkListItem:nQ,splitBlock:rQ,splitListItem:sQ,toggleList:iQ,toggleMark:oQ,toggleNode:aQ,toggleWrap:lQ,undoInputRule:cQ,unsetAllMarks:uQ,unsetMark:dQ,updateAttributes:hQ,wrapIn:fQ,wrapInList:pQ});const mQ=lr.create({name:"commands",addCommands(){return{...gQ}}}),yQ=lr.create({name:"drop",addProseMirrorPlugins(){return[new ur({key:new Zs("tiptapDrop"),props:{handleDrop:(n,e,t,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:r})}}})]}}),SQ=lr.create({name:"editable",addProseMirrorPlugins(){return[new ur({key:new Zs("editable"),props:{editable:()=>this.editor.options.editable}})]}}),vQ=new Zs("focusEvents"),xQ=lr.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new ur({key:vQ,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}}}})]}}),wQ=lr.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:g,parent:m}=f,y=f.parent.isTextblock&&g>0?a.doc.resolve(g-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===g;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 nE()||O5()?i:s},addProseMirrorPlugins(){return[new ur({key:new Zs("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)||!iE(t.doc))return;const g=t.tr,m=M0({state:t,transaction:g}),{commands:y}=new A0({editor:this.editor,state:m});if(y.clearNodes(),!!g.steps.length)return g}})]}}),bQ=lr.create({name:"paste",addProseMirrorPlugins(){return[new ur({key:new Zs("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),CQ=lr.create({name:"tabindex",addProseMirrorPlugins(){return[new ur({key:new Zs("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class Dc{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 Dc(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 Dc(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 Dc(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 Dc(a,this.editor,s,s?t:null);s&&(l.actualDepth=this.depth+1),e.push(new Dc(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 PQ=`.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 kQ(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 IQ=class extends OZ{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=kQ(PQ,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=k5(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?[SQ,VZ.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||t===void 0?void 0:t.blockSeparator}),mQ,xQ,wQ,CQ,yQ,bQ].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 Lc(s,this)}createCommandManager(){this.commandManager=new A0({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=GP(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=GP(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const r=M5(t,this.options.autofocus);this.view=new nZ(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:Cd.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 j5(this.state,e)}isActive(e,t){const r=typeof e=="string"?e:null,s=typeof e=="string"?t:e;return GJ(this.state,r,s)}getJSON(){return this.state.doc.toJSON()}getHTML(){return R0(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
174
+
175
+ `,textSerializers:r={}}=e||{};return D5(this.state.doc,{blockSeparator:t,textSerializers:{...tE(this.schema),...r}})}get isEmpty(){return iE(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 Dc(t,this)}get $doc(){return this.$pos(0)}};function Qc(n){return new D0({find:n.find,handler:({state:e,range:t,match:r})=>{const s=ft(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(sE(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 g=t.from+l+o.length;i.addMark(t.from+l,g,n.type.create(s||{})),i.removeStoredMark(n.type)}}})}function EQ(n){return new D0({find:n.find,handler:({state:e,range:t,match:r})=>{const s=ft(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 XP(n){return new D0({find:n.find,handler:({state:e,range:t,match:r})=>{const s=e.doc.resolve(t.from),i=ft(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 cp(n){return new D0({find:n.find,handler:({state:e,range:t,match:r,chain:s})=>{const i=ft(n.getAttributes,void 0,r)||{},o=e.tr.delete(t.from,t.to),l=o.doc.resolve(t.from).blockRange(),c=l&&FI(l,n.type,i);if(!c)return null;if(o.wrap(l,c),n.keepMarks&&n.editor){const{selection:f,storedMarks:g}=e,{splittableMarks:m}=n.editor.extensionManager,y=g||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&&Ql(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,d))&&o.join(t.from-1)}})}let so=class ZP{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=ft(Le(this,"addOptions",{name:this.name}))),this.storage=ft(Le(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new ZP(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>j0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new ZP(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=ft(Le(t,"addOptions",{name:t.name})),t.storage=ft(Le(t,"addStorage",{name:t.name,options:t.options})),t}};function Bl(n){return new $Z({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:s})=>{const i=ft(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),g=f+a.length;if(sE(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;g<t.to&&o.delete(g,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 oE(n,e,t){const{tipTapConfig:r,addFontsFromNode:s}=n.getTextOptions();tt(r,"textOptions.tipTapConfig must be set to use rich text"),tt(s,"textOptions.addFontsFromNode must be set to use rich text");const i=F0(r.extensions??[]),o=Xi.fromJSON(i,e),a=new Set;function l(d){a.add(d)}function c(d,f){f=s(d,f,l);for(const g of d.children)c(g,f)}return c(o,t),Array.from(a)}const _Q=(n,e)=>e.some(t=>n instanceof t);let FD,zD;function TQ(){return FD||(FD=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function MQ(){return zD||(zD=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const N5=new WeakMap,JP=new WeakMap,L5=new WeakMap,X1=new WeakMap,aE=new WeakMap;function AQ(n){const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("success",i),n.removeEventListener("error",o)},i=()=>{t(Aa(n.result)),s()},o=()=>{r(n.error),s()};n.addEventListener("success",i),n.addEventListener("error",o)});return e.then(t=>{t instanceof IDBCursor&&N5.set(t,n)}).catch(()=>{}),aE.set(e,n),e}function OQ(n){if(JP.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)});JP.set(n,e)}let QP={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return JP.get(n);if(e==="objectStoreNames")return n.objectStoreNames||L5.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Aa(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 RQ(n){QP=n(QP)}function DQ(n){return n===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){const r=n.call(Z1(this),e,...t);return L5.set(r,e.sort?e.sort():[e]),Aa(r)}:MQ().includes(n)?function(...e){return n.apply(Z1(this),e),Aa(N5.get(this))}:function(...e){return Aa(n.apply(Z1(this),e))}}function jQ(n){return typeof n=="function"?DQ(n):(n instanceof IDBTransaction&&OQ(n),_Q(n,TQ())?new Proxy(n,QP):n)}function Aa(n){if(n instanceof IDBRequest)return AQ(n);if(X1.has(n))return X1.get(n);const e=jQ(n);return e!==n&&(X1.set(n,e),aE.set(e,n)),e}const Z1=n=>aE.get(n);function F5(n,e,{blocked:t,upgrade:r,blocking:s,terminated:i}={}){const o=indexedDB.open(n,e),a=Aa(o);return r&&o.addEventListener("upgradeneeded",l=>{r(Aa(o.result),l.oldVersion,l.newVersion,Aa(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 z5(n,{blocked:e}={}){const t=indexedDB.deleteDatabase(n);return e&&t.addEventListener("blocked",r=>e(r.oldVersion,r)),Aa(t).then(()=>{})}const NQ=["get","getKey","getAll","getAllKeys","count"],LQ=["put","add","delete","clear"],J1=new Map;function $D(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(J1.get(e))return J1.get(e);const t=e.replace(/FromIndex$/,""),r=e!==t,s=LQ.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(s||NQ.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 J1.set(e,i),i}RQ(n=>({...n,get:(e,t,r)=>$D(e,t)||n.get(e,t,r),has:(e,t)=>!!$D(e,t)||n.has(e,t)}));const FQ="TLDRAW_DOCUMENT_v2",zQ="TLDRAW_ASSET_STORE_v1",$5="TLDRAW_DB_NAME_INDEX_v2",ht={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function B5(n){const e=FQ+n;return BQ(e),await F5(e,4,{upgrade(t){t.objectStoreNames.contains(ht.Records)||t.createObjectStore(ht.Records),t.objectStoreNames.contains(ht.Schema)||t.createObjectStore(ht.Schema),t.objectStoreNames.contains(ht.SessionState)||t.createObjectStore(ht.SessionState),t.objectStoreNames.contains(ht.Assets)||t.createObjectStore(ht.Assets)}})}async function $Q(n){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(g=>g.name):lE(),t=zQ+n;if(!e.find(g=>g===t))return;const s=await F5(t,1,{upgrade(g){g.objectStoreNames.contains("assets")||g.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 g=>[g,await o.get(g)]));await i.done;const c=await B5(n),d=c.transaction([ht.Assets],"readwrite"),f=d.objectStore(ht.Assets);for(const[g,m]of l)f.put(m,g);await d.done,s.close(),c.close(),await z5(t)}const Yf=class Yf{constructor(e){R(this,"getDbPromise");R(this,"isClosed",!1);R(this,"pendingTransactionSet",new Set);Yf.connectedInstances.add(this),this.getDbPromise=(async()=>(await $Q(e),await B5(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Zf)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),Yf.connectedInstances.delete(this))}tx(e,t,r){const s=(async()=>{tt(!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",[ht.Records,ht.Schema,ht.SessionState],async t=>{var l,c;const r=t.objectStore(ht.Records),s=t.objectStore(ht.Schema),i=t.objectStore(ht.SessionState);let o=e?(l=await i.get(e))==null?void 0:l.snapshot:null;return o||(o=(c=(await i.getAll()).sort((f,g)=>f.updatedAt-g.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(ht.Schema),sessionStateSnapshot:o}})}async storeChanges({schema:e,changes:t,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[ht.Records,ht.Schema,ht.SessionState],async i=>{const o=i.objectStore(ht.Records),a=i.objectStore(ht.Schema),l=i.objectStore(ht.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(),ht.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",[ht.Records,ht.Schema,ht.SessionState],async i=>{const o=i.objectStore(ht.Records),a=i.objectStore(ht.Schema),l=i.objectStore(ht.SessionState);await o.clear();for(const[c,d]of Object.entries(t))await o.put(d,c);a.put(e.serialize(),ht.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",[ht.SessionState],async e=>{const t=e.objectStore(ht.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",[ht.Assets],async t=>await t.objectStore(ht.Assets).get(e))}async storeAsset(e,t){await this.tx("readwrite",[ht.Assets],async r=>{await r.objectStore(ht.Assets).put(t,e)})}async removeAssets(e){await this.tx("readwrite",[ht.Assets],async t=>{const r=t.objectStore(ht.Assets);for(const s of e)await r.delete(s)})}};R(Yf,"connectedInstances",new Set);let iS=Yf;function lE(){const n=JSON.parse(vI($5)||"[]")??[];return Array.isArray(n)?n:[]}function BQ(n){const e=new Set(lE());e.add(n),xI($5,JSON.stringify([...e]))}/*!
176
+ * This file was lovingly and delicately extracted from Immutable.js
177
+ * MIT License: https://github.com/immutable-js/immutable-js/blob/main/LICENSE
178
+ * Copyright (c) 2014-present, Lee Byron and other contributors.
179
+ */function cE(n){return n>>>1&1073741824|n&3221225471}const UQ=Object.prototype.valueOf;function eu(n){if(n==null)return BD(n);if(typeof n.hashCode=="function")return cE(n.hashCode(n));const e=qQ(n);if(e==null)return BD(e);switch(typeof e){case"boolean":return e?1108378657:1108378656;case"number":return HQ(e);case"string":return e.length>GQ?KQ(e):ek(e);case"object":case"function":return VQ(e);case"symbol":return WQ(e);default:if(typeof e.toString=="function")return ek(e.toString());throw new Error("Value type "+typeof e+" cannot be hashed.")}}function BD(n){return n===null?1108378658:1108378659}function HQ(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 cE(e)}function KQ(n){let e=tC[n];return e===void 0&&(e=ek(n),eC===YQ&&(eC=0,tC={}),eC++,tC[n]=e),e}function ek(n){let e=0;for(let t=0;t<n.length;t++)e=31*e+n.charCodeAt(t)|0;return cE(e)}function WQ(n){let e=HD[n];return e!==void 0||(e=U5(),HD[n]=e),e}function VQ(n){let e=UD.get(n);return e!==void 0||(e=U5(),UD.set(n,e)),e}function qQ(n){return n.valueOf!==UQ&&typeof n.valueOf=="function"?n.valueOf(n):n}function U5(){const n=++Q1;return Q1&1073741824&&(Q1=0),n}const UD=new WeakMap,HD=Object.create(null);let Q1=0;const GQ=16,YQ=255;let eC=0,tC={};const Wd=5,jp=1<<Wd,Vd=jp-1,ja={};function KD(){return{value:!1}}function Wi(n){n&&(n.value=!0)}function uE(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 qd=Object.is;class H5{}class dE{constructor(e){R(this,"_root");R(this,"size");R(this,"__ownerID");R(this,"__hash");R(this,"__altered");return e==null?Md():e instanceof dE?e:Md().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 qD(this,e,t)}delete(e){return qD(this,e,ja)}deleteAll(e){return this.withMutations(t=>{for(const r of e)t.delete(r)})}__ensureOwner(e){return e===this.__ownerID?this:e?pE(this.size,this._root,e,this.__hash):this.size===0?Md():(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 H5)}[Symbol.iterator](){return this.entries()[Symbol.iterator]()}entries(){return new nC(this,XQ,!1)}keys(){return new nC(this,K5,!1)}values(){return new nC(this,W5,!1)}}class hE{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(qd(r,i[o][0]))return i[o][1];return s}update(e,t,r,s,i,o,a){const l=i===ja,c=this.entries;let d=0;const f=c.length;for(;d<f&&!qd(s,c[d][0]);d++);const g=d<f;if(g?c[d][1]===i:l)return this;if(Wi(a),(l||!g)&&Wi(o),l&&c.length===1)return;if(!g&&!l&&c.length>=see)return QQ(e,c,s,i);const m=e&&e===this.ownerID,y=m?c:uE(c);return g?l?d===f-1?y.pop():y[d]=y.pop():y[d]=[s,i]:y.push([s,i]),m?(this.entries=y,this):new hE(e,y)}}class z0{constructor(e,t,r){this.ownerID=e,this.bitmap=t,this.nodes=r}get(e,t,r,s){t===void 0&&(t=eu(r));const i=1<<((e===0?t:t>>>e)&Vd),o=this.bitmap;return(o&i)===0?s:this.nodes[YD(o&i-1)].get(e+Wd,t,r,s)}update(e,t,r,s,i,o,a){r===void 0&&(r=eu(s));const l=(t===0?r:r>>>t)&Vd,c=1<<l,d=this.bitmap,f=(d&c)!==0;if(!f&&i===ja)return this;const g=YD(d&c-1),m=this.nodes,y=f?m[g]:void 0,v=gE(y,e,t+Wd,r,s,i,o,a);if(v===y)return this;if(!f&&v&&m.length>=iee)return tee(e,m,d,l,v);if(f&&!v&&m.length===2&&GD(m[g^1]))return m[g^1];if(f&&v&&m.length===1&&GD(v))return v;const x=e&&e===this.ownerID,b=f?v?d:d^c:d|c,C=f?v?V5(m,g,v,x):ree(m,g,x):nee(m,g,v,x);return x?(this.bitmap=b,this.nodes=C,this):new z0(e,b,C)}}class fE{constructor(e,t,r){this.ownerID=e,this.count=t,this.nodes=r}get(e,t,r,s){t===void 0&&(t=eu(r));const i=(e===0?t:t>>>e)&Vd,o=this.nodes[i];return o?o.get(e+Wd,t,r,s):s}update(e,t,r,s,i,o,a){r===void 0&&(r=eu(s));const l=(t===0?r:r>>>t)&Vd,c=i===ja,d=this.nodes,f=d[l];if(c&&!f)return this;const g=gE(f,e,t+Wd,r,s,i,o,a);if(g===f)return this;let m=this.count;if(!f)m++;else if(!g&&(m--,m<oee))return eee(e,d,m,l);const y=e&&e===this.ownerID,v=V5(d,l,g,y);return y?(this.count=m,this.nodes=v,this):new fE(e,m,v)}}class $0{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(qd(r,i[o][0]))return i[o][1];return s}update(e,t,r,s,i,o,a){r===void 0&&(r=eu(s));const l=i===ja;if(r!==this.keyHash)return l?this:(Wi(a),Wi(o),mE(this,e,t,r,[s,i]));const c=this.entries;let d=0;const f=c.length;for(;d<f&&!qd(s,c[d][0]);d++);const g=d<f;if(g?c[d][1]===i:l)return this;if(Wi(a),(l||!g)&&Wi(o),l&&f===2)return new yu(e,this.keyHash,c[d^1]);const m=e&&e===this.ownerID,y=m?c:uE(c);return g?l?d===f-1?y.pop():y[d]=y.pop():y[d]=[s,i]:y.push([s,i]),m?(this.entries=y,this):new $0(e,this.keyHash,y)}}class yu{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entry=r}get(e,t,r,s){return qd(r,this.entry[0])?this.entry[1]:s}update(e,t,r,s,i,o,a){const l=i===ja,c=qd(s,this.entry[0]);if(c?i===this.entry[1]:l)return this;if(Wi(a),l){Wi(o);return}return c?e&&e===this.ownerID?(this.entry[1]=i,this):new yu(e,this.keyHash,[s,i]):(Wi(o),mE(this,e,t,eu(s),[s,i]))}}class nC{constructor(e,t,r){R(this,"_stack");this._type=t,this._reverse=r,this._stack=e._root&&WD(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 rC(e,r.entry)}else if("entries"in r&&r.entries){if(i=r.entries.length-1,s<=i)return rC(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 rC(e,o.entry);t=this._stack=WD(o,t)}continue}t=this._stack=this._stack.__prev}return JQ()}}function rC(n,e){return ZQ(n,e[0],e[1])}function WD(n,e){return{node:n,index:0,__prev:e}}const K5=0,W5=1,XQ=2;function ZQ(n,e,t,r){const s=n===K5?e:n===W5?t:[e,t];return r?r.value=s:r={value:s,done:!1},r}function JQ(){return{value:void 0,done:!0}}function pE(n,e,t,r){const s=Object.create(dE.prototype);return s.size=n,s._root=e,s.__ownerID=t,s.__hash=r,s.__altered=!1,s}let VD;function Md(){return VD||(VD=pE(0))}function qD(n,e,t){let r,s;if(n._root){const i=KD(),o=KD();if(r=gE(n._root,n.__ownerID,0,void 0,e,t,i,o),!o.value)return n;s=n.size+(i.value?t===ja?-1:1:0)}else{if(t===ja)return n;s=1,r=new hE(n.__ownerID,[[e,t]])}return n.__ownerID?(n.size=s,n._root=r,n.__hash=void 0,n.__altered=!0,n):r?pE(s,r):Md()}function gE(n,e,t,r,s,i,o,a){return n?n.update(e,t,r,s,i,o,a):i===ja?n:(Wi(a),Wi(o),new yu(e,r,[s,i]))}function GD(n){return n.constructor===yu||n.constructor===$0}function mE(n,e,t,r,s){if(n.keyHash===r)return new $0(e,r,[n.entry,s]);const i=(t===0?n.keyHash:n.keyHash>>>t)&Vd,o=(t===0?r:r>>>t)&Vd;let a;const l=i===o?[mE(n,e,t+Wd,r,s)]:(a=new yu(e,r,s),i<o?[n,a]:[a,n]);return new z0(e,1<<i|1<<o,l)}function QQ(n,e,t,r){n||(n=new H5);let s=new yu(n,eu(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 eee(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 z0(n,s,o)}function tee(n,e,t,r,s){let i=0;const o=new Array(jp);for(let a=0;t!==0;a++,t>>>=1)o[a]=t&1?e[i++]:void 0;return o[r]=s,new fE(n,i+1,o)}function YD(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 V5(n,e,t,r){const s=r?n:uE(n);return s[e]=t,s}function nee(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 ree(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 see=jp/4,iee=jp/2,oee=jp/4;var NL,LL;class tk{constructor(e,t){R(this,"atoms");R(this,NL,"AtomMap");this.name=e;let r=Md();t&&(r=r.withMutations(s=>{for(const[i,o]of t)s.set(i,ln(`${e}:${String(i)}`,o))})),this.atoms=ln(`${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 tt(t!==xr),t}__unsafe__getWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t)return;const r=t.__unsafe__getWithoutCapture();return tt(r!==xr),r}has(e){const t=this.getAtom(e);return t?t.get()!==xr:!1}__unsafe__hasWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(tt(t.__unsafe__getWithoutCapture()!==xr),!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,ln(`${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();tt(s!==xr),r.set(t(s))}delete(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(Ps(()=>{t.set(xr),this.atoms.update(r=>r.delete(e))}),!0):!1}deleteMany(e){return Ps(()=>{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();tt(a!==xr),t.push([i,a]),s.delete(i),o.set(xr)}});return t.length&&this.atoms.set(r),t})}clear(){return Ps(()=>{for(const e of this.atoms.__unsafe__getWithoutCapture().values())e.set(xr);this.atoms.set(Md())})}*entries(){for(const[e,t]of this.atoms.get()){const r=t.get();tt(r!==xr),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();tt(t!==xr),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)}[(LL=Symbol.iterator,NL=Symbol.toStringTag,LL)](){return this.entries()}}class iy{constructor(e){R(this,"nextValue");R(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 B0{constructor(e,t){R(this,"createDefaultProperties");R(this,"validator");R(this,"ephemeralKeys");R(this,"ephemeralKeySet");R(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 Cs(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{...Xt(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??Tt())}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 B0(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 Go(n,e){return new B0(n,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function oS(){return{added:{},updated:{},removed:{}}}function nk(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 q5(n){return Object.keys(n.added).length===0&&Object.keys(n.updated).length===0&&Object.keys(n.removed).length===0}function yE(n){const e={added:{},removed:{},updated:{}};return Nf(e,n),e}function Nf(n,e){for(const t of e){for(const[r,s]of Cs(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 Cs(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 Cs(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 Cf={exports:{}};Cf.exports;var XD;function aee(){return XD||(XD=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]",g="[object Error]",m="[object Function]",y="[object GeneratorFunction]",v="[object Map]",x="[object Number]",b="[object Null]",C="[object Object]",E="[object Promise]",_="[object Proxy]",M="[object RegExp]",A="[object Set]",O="[object String]",D="[object Symbol]",B="[object Undefined]",U="[object WeakMap]",G="[object ArrayBuffer]",z="[object DataView]",N="[object Float32Array]",L="[object Float64Array]",V="[object Int8Array]",Z="[object Int16Array]",W="[object Int32Array]",$="[object Uint8Array]",Y="[object Uint8ClampedArray]",re="[object Uint16Array]",K="[object Uint32Array]",ne=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Pe=/^(?:0|[1-9]\d*)$/,ce={};ce[N]=ce[L]=ce[V]=ce[Z]=ce[W]=ce[$]=ce[Y]=ce[re]=ce[K]=!0,ce[a]=ce[l]=ce[G]=ce[d]=ce[z]=ce[f]=ce[g]=ce[m]=ce[v]=ce[x]=ce[C]=ce[M]=ce[A]=ce[O]=ce[U]=!1;var Be=typeof ws=="object"&&ws&&ws.Object===Object&&ws,Re=typeof self=="object"&&self&&self.Object===Object&&self,Ce=Be||Re||Function("return this")(),_e=e&&!e.nodeType&&e,We=_e&&!0&&n&&!n.nodeType&&n,st=We&&We.exports===_e,hn=st&&Be.process,_t=function(){try{return hn&&hn.binding&&hn.binding("util")}catch{}}(),Qt=_t&&_t.isTypedArray;function Nt(F,J){for(var de=-1,Ae=F==null?0:F.length,Mt=0,Qe=[];++de<Ae;){var $t=F[de];J($t,de,F)&&(Qe[Mt++]=$t)}return Qe}function At(F,J){for(var de=-1,Ae=J.length,Mt=F.length;++de<Ae;)F[Mt+de]=J[de];return F}function Jr(F,J){for(var de=-1,Ae=F==null?0:F.length;++de<Ae;)if(J(F[de],de,F))return!0;return!1}function Qr(F,J){for(var de=-1,Ae=Array(F);++de<F;)Ae[de]=J(de);return Ae}function es(F){return function(J){return F(J)}}function ts(F,J){return F.has(J)}function ti(F,J){return F==null?void 0:F[J]}function ac(F){var J=-1,de=Array(F.size);return F.forEach(function(Ae,Mt){de[++J]=[Mt,Ae]}),de}function bu(F,J){return function(de){return F(J(de))}}function Cu(F){var J=-1,de=Array(F.size);return F.forEach(function(Ae){de[++J]=Ae}),de}var Pu=Array.prototype,ku=Function.prototype,co=Object.prototype,Mi=Ce["__core-js_shared__"],lc=ku.toString,ae=co.hasOwnProperty,be=function(){var F=/[^.]+$/.exec(Mi&&Mi.keys&&Mi.keys.IE_PROTO||"");return F?"Symbol(src)_1."+F:""}(),Ye=co.toString,Ot=RegExp("^"+lc.call(ae).replace(ne,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ni=st?Ce.Buffer:void 0,ns=Ce.Symbol,Qo=Ce.Uint8Array,As=co.propertyIsEnumerable,Os=Pu.splice,rs=ns?ns.toStringTag:void 0,Rs=Object.getOwnPropertySymbols,ss=ni?ni.isBuffer:void 0,Ai=bu(Object.keys,Object),Iu=na(Ce,"DataView"),Ga=na(Ce,"Map"),Eu=na(Ce,"Promise"),_u=na(Ce,"Set"),Tu=na(Ce,"WeakMap"),ea=na(Object,"create"),ig=hr(Iu),cc=hr(Ga),vh=hr(Eu),uc=hr(_u),Lv=hr(Tu),Ya=ns?ns.prototype:void 0,Xa=Ya?Ya.valueOf:void 0;function ri(F){var J=-1,de=F==null?0:F.length;for(this.clear();++J<de;){var Ae=F[J];this.set(Ae[0],Ae[1])}}function xh(){this.__data__=ea?ea(null):{},this.size=0}function Fv(F){var J=this.has(F)&&delete this.__data__[F];return this.size-=J?1:0,J}function zv(F){var J=this.__data__;if(ea){var de=J[F];return de===r?void 0:de}return ae.call(J,F)?J[F]:void 0}function $v(F){var J=this.__data__;return ea?J[F]!==void 0:ae.call(J,F)}function ta(F,J){var de=this.__data__;return this.size+=this.has(F)?0:1,de[F]=ea&&J===void 0?r:J,this}ri.prototype.clear=xh,ri.prototype.delete=Fv,ri.prototype.get=zv,ri.prototype.has=$v,ri.prototype.set=ta;function si(F){var J=-1,de=F==null?0:F.length;for(this.clear();++J<de;){var Ae=F[J];this.set(Ae[0],Ae[1])}}function og(){this.__data__=[],this.size=0}function Bv(F){var J=this.__data__,de=Ou(J,F);if(de<0)return!1;var Ae=J.length-1;return de==Ae?J.pop():Os.call(J,de,1),--this.size,!0}function ag(F){var J=this.__data__,de=Ou(J,F);return de<0?void 0:J[de][1]}function lg(F){return Ou(this.__data__,F)>-1}function cg(F,J){var de=this.__data__,Ae=Ou(de,F);return Ae<0?(++this.size,de.push([F,J])):de[Ae][1]=J,this}si.prototype.clear=og,si.prototype.delete=Bv,si.prototype.get=ag,si.prototype.has=lg,si.prototype.set=cg;function uo(F){var J=-1,de=F==null?0:F.length;for(this.clear();++J<de;){var Ae=F[J];this.set(Ae[0],Ae[1])}}function Uv(){this.size=0,this.__data__={hash:new ri,map:new(Ga||si),string:new ri}}function Hv(F){var J=xt(this,F).delete(F);return this.size-=J?1:0,J}function rn(F){return xt(this,F).get(F)}function Kv(F){return xt(this,F).has(F)}function wh(F,J){var de=xt(this,F),Ae=de.size;return de.set(F,J),this.size+=de.size==Ae?0:1,this}uo.prototype.clear=Uv,uo.prototype.delete=Hv,uo.prototype.get=rn,uo.prototype.has=Kv,uo.prototype.set=wh;function dc(F){var J=-1,de=F==null?0:F.length;for(this.__data__=new uo;++J<de;)this.add(F[J])}function Mu(F){return this.__data__.set(F,r),this}function Wv(F){return this.__data__.has(F)}dc.prototype.add=dc.prototype.push=Mu,dc.prototype.has=Wv;function Oi(F){var J=this.__data__=new si(F);this.size=J.size}function Au(){this.__data__=new si,this.size=0}function ii(F){var J=this.__data__,de=J.delete(F);return this.size=J.size,de}function Vv(F){return this.__data__.get(F)}function Ds(F){return this.__data__.has(F)}function qv(F,J){var de=this.__data__;if(de instanceof si){var Ae=de.__data__;if(!Ga||Ae.length<t-1)return Ae.push([F,J]),this.size=++de.size,this;de=this.__data__=new uo(Ae)}return de.set(F,J),this.size=de.size,this}Oi.prototype.clear=Au,Oi.prototype.delete=ii,Oi.prototype.get=Vv,Oi.prototype.has=Ds,Oi.prototype.set=qv;function Gv(F,J){var de=po(F),Ae=!de&&pc(F),Mt=!de&&!Ae&&kh(F),Qe=!de&&!Ae&&!Mt&&Eh(F),$t=de||Ae||Mt||Qe,Sn=$t?Qr(F.length,String):[],Bt=Sn.length;for(var Lt in F)ae.call(F,Lt)&&!($t&&(Lt=="length"||Mt&&(Lt=="offset"||Lt=="parent")||Qe&&(Lt=="buffer"||Lt=="byteLength"||Lt=="byteOffset")||hg(Lt,Bt)))&&Sn.push(Lt);return Sn}function Ou(F,J){for(var de=F.length;de--;)if(Di(F[de][0],J))return de;return-1}function Ru(F,J,de){var Ae=J(F);return po(F)?Ae:At(Ae,de(F))}function ho(F){return F==null?F===void 0?B:b:rs&&rs in Object(F)?dg(F):fo(F)}function Za(F){return mo(F)&&ho(F)==a}function hc(F,J,de,Ae,Mt){return F===J?!0:F==null||J==null||!mo(F)&&!mo(J)?F!==F&&J!==J:Yv(F,J,de,Ae,hc,Mt)}function Yv(F,J,de,Ae,Mt,Qe){var $t=po(F),Sn=po(J),Bt=$t?l:Ri(F),Lt=Sn?l:Ri(J);Bt=Bt==a?C:Bt,Lt=Lt==a?C:Lt;var Nn=Bt==C,is=Lt==C,vn=Bt==Lt;if(vn&&kh(F)){if(!kh(J))return!1;$t=!0,Nn=!1}if(vn&&!Nn)return Qe||(Qe=new Oi),$t||Eh(F)?Du(F,J,de,Ae,Mt,Qe):fc(F,J,Bt,de,Ae,Mt,Qe);if(!(de&s)){var Yn=Nn&&ae.call(F,"__wrapped__"),Dr=is&&ae.call(J,"__wrapped__");if(Yn||Dr){var fn=Yn?F.value():F,fr=Dr?J.value():J;return Qe||(Qe=new Oi),Mt(fn,fr,de,Ae,Qe)}}return vn?(Qe||(Qe=new Oi),Zv(F,J,de,Ae,Mt,Qe)):!1}function Xv(F){if(!Ih(F)||Ph(F))return!1;var J=Ja(F)?Ot:ge;return J.test(hr(F))}function bh(F){return mo(F)&&gg(F.length)&&!!ce[ho(F)]}function ug(F){if(!Nu(F))return Ai(F);var J=[];for(var de in Object(F))ae.call(F,de)&&de!="constructor"&&J.push(de);return J}function Du(F,J,de,Ae,Mt,Qe){var $t=de&s,Sn=F.length,Bt=J.length;if(Sn!=Bt&&!($t&&Bt>Sn))return!1;var Lt=Qe.get(F);if(Lt&&Qe.get(J))return Lt==J;var Nn=-1,is=!0,vn=de&i?new dc:void 0;for(Qe.set(F,J),Qe.set(J,F);++Nn<Sn;){var Yn=F[Nn],Dr=J[Nn];if(Ae)var fn=$t?Ae(Dr,Yn,Nn,J,F,Qe):Ae(Yn,Dr,Nn,F,J,Qe);if(fn!==void 0){if(fn)continue;is=!1;break}if(vn){if(!Jr(J,function(fr,ji){if(!ts(vn,ji)&&(Yn===fr||Mt(Yn,fr,de,Ae,Qe)))return vn.push(ji)})){is=!1;break}}else if(!(Yn===Dr||Mt(Yn,Dr,de,Ae,Qe))){is=!1;break}}return Qe.delete(F),Qe.delete(J),is}function fc(F,J,de,Ae,Mt,Qe,$t){switch(de){case z:if(F.byteLength!=J.byteLength||F.byteOffset!=J.byteOffset)return!1;F=F.buffer,J=J.buffer;case G:return!(F.byteLength!=J.byteLength||!Qe(new Qo(F),new Qo(J)));case d:case f:case x:return Di(+F,+J);case g:return F.name==J.name&&F.message==J.message;case M:case O:return F==J+"";case v:var Sn=ac;case A:var Bt=Ae&s;if(Sn||(Sn=Cu),F.size!=J.size&&!Bt)return!1;var Lt=$t.get(F);if(Lt)return Lt==J;Ae|=i,$t.set(F,J);var Nn=Du(Sn(F),Sn(J),Ae,Mt,Qe,$t);return $t.delete(F),Nn;case D:if(Xa)return Xa.call(F)==Xa.call(J)}return!1}function Zv(F,J,de,Ae,Mt,Qe){var $t=de&s,Sn=ju(F),Bt=Sn.length,Lt=ju(J),Nn=Lt.length;if(Bt!=Nn&&!$t)return!1;for(var is=Bt;is--;){var vn=Sn[is];if(!($t?vn in J:ae.call(J,vn)))return!1}var Yn=Qe.get(F);if(Yn&&Qe.get(J))return Yn==J;var Dr=!0;Qe.set(F,J),Qe.set(J,F);for(var fn=$t;++is<Bt;){vn=Sn[is];var fr=F[vn],ji=J[vn];if(Ae)var Qa=$t?Ae(ji,fr,vn,J,F,Qe):Ae(fr,ji,vn,F,J,Qe);if(!(Qa===void 0?fr===ji||Mt(fr,ji,de,Ae,Qe):Qa)){Dr=!1;break}fn||(fn=vn=="constructor")}if(Dr&&!fn){var Lu=F.constructor,el=J.constructor;Lu!=el&&"constructor"in F&&"constructor"in J&&!(typeof Lu=="function"&&Lu instanceof Lu&&typeof el=="function"&&el instanceof el)&&(Dr=!1)}return Qe.delete(F),Qe.delete(J),Dr}function ju(F){return Ru(F,Jv,Ch)}function xt(F,J){var de=F.__data__;return fg(J)?de[typeof J=="string"?"string":"hash"]:de.map}function na(F,J){var de=ti(F,J);return Xv(de)?de:void 0}function dg(F){var J=ae.call(F,rs),de=F[rs];try{F[rs]=void 0;var Ae=!0}catch{}var Mt=Ye.call(F);return Ae&&(J?F[rs]=de:delete F[rs]),Mt}var Ch=Rs?function(F){return F==null?[]:(F=Object(F),Nt(Rs(F),function(J){return As.call(F,J)}))}:gc,Ri=ho;(Iu&&Ri(new Iu(new ArrayBuffer(1)))!=z||Ga&&Ri(new Ga)!=v||Eu&&Ri(Eu.resolve())!=E||_u&&Ri(new _u)!=A||Tu&&Ri(new Tu)!=U)&&(Ri=function(F){var J=ho(F),de=J==C?F.constructor:void 0,Ae=de?hr(de):"";if(Ae)switch(Ae){case ig:return z;case cc:return v;case vh:return E;case uc:return A;case Lv:return U}return J});function hg(F,J){return J=J??o,!!J&&(typeof F=="number"||Pe.test(F))&&F>-1&&F%1==0&&F<J}function fg(F){var J=typeof F;return J=="string"||J=="number"||J=="symbol"||J=="boolean"?F!=="__proto__":F===null}function Ph(F){return!!be&&be in F}function Nu(F){var J=F&&F.constructor,de=typeof J=="function"&&J.prototype||co;return F===de}function fo(F){return Ye.call(F)}function hr(F){if(F!=null){try{return lc.call(F)}catch{}try{return F+""}catch{}}return""}function Di(F,J){return F===J||F!==F&&J!==J}var pc=Za(function(){return arguments}())?Za:function(F){return mo(F)&&ae.call(F,"callee")&&!As.call(F,"callee")},po=Array.isArray;function go(F){return F!=null&&gg(F.length)&&!Ja(F)}var kh=ss||mc;function pg(F,J){return hc(F,J)}function Ja(F){if(!Ih(F))return!1;var J=ho(F);return J==m||J==y||J==c||J==_}function gg(F){return typeof F=="number"&&F>-1&&F%1==0&&F<=o}function Ih(F){var J=typeof F;return F!=null&&(J=="object"||J=="function")}function mo(F){return F!=null&&typeof F=="object"}var Eh=Qt?es(Qt):bh;function Jv(F){return go(F)?Gv(F):ug(F)}function gc(){return[]}function mc(){return!1}n.exports=pg}(Cf,Cf.exports)),Cf.exports}var lee=aee();const Np=$a(lee);function cee(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 uee(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 ZD(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 JD(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 cee(Object.values(r))}class dee{constructor(e,t){R(this,"indexCache",new Map);R(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(Bc(r))return this.history.get();const i=this.history.getDiffSince(s);if(i===Ks)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 mn(d.added))if(f.typeName===e)if(o.removed[f.id]){const g=o.removed[f.id];delete o.removed[f.id],l--,g!==f&&(o.updated[f.id]=[g,f],c++)}else o.added[f.id]=f,a++;for(const[f,g]of mn(d.updated))g.typeName===e&&(o.added[g.id]?o.added[g.id]=g:o.updated[g.id]?o.updated[g.id]=[o.updated[g.id][0],g]:(o.updated[g.id]=[f,g],c++));for(const f of mn(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?Sf(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(Bc(i))return s();const a=r.getDiffSince(o);if(a===Ks)return s();const l=new Map,c=(m,y)=>{let v=l.get(m);v||(v=new iy(i.get(m)??new Set)),v.add(y),l.set(m,v)},d=(m,y)=>{let v=l.get(m);v||(v=new iy(i.get(m)??new Set)),v.remove(y),l.set(m,v)};for(const m of a){for(const y of mn(m.added))if(y.typeName===e){const v=y[t];c(v,y.id)}for(const[y,v]of mn(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 mn(m.removed))if(y.typeName===e){const v=y[t];d(v,y.id)}}let f,g;for(const[m,y]of l){const v=y.get();v&&(f||(f=new Map(i)),g||(g=new Map),v.value.size===0?f.delete(m):f.set(m,v.value),g.set(m,v.diff))}return f&&g?Sf(f,g):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:zy})}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 JD(this,e,l)},o=l=>{const c=i(),d=uee(l,c);return d?Sf(c,d):l},a=le("ids_query:"+r,t,{isEqual:Np});return le("query:"+r,(l,c)=>{const d=a.get();if(Bc(l))return i();if(c<a.lastChangedEpoch)return o(l);const f=s.getDiffSince(c);if(f===Ks)return o(l);const g=new iy(l);for(const y of f){for(const v of mn(y.added))v.typeName===e&&ZD(d,v)&&g.add(v.id);for(const[v,x]of mn(y.updated))x.typeName===e&&(ZD(d,x)?g.add(x.id):g.remove(x.id));for(const v of mn(y.removed))v.typeName===e&&g.remove(v.id)}const m=g.get();return m?Sf(m.value,m.diff):l},{historyLength:50})}exec(e,t){const r=JD(this,e,t);return r.size===0?bi:Array.from(r,s=>this.recordMap.get(s))}}class hee{constructor(e){R(this,"_beforeCreateHandlers",{});R(this,"_afterCreateHandlers",{});R(this,"_beforeChangeHandlers",{});R(this,"_afterChangeHandlers",{});R(this,"_beforeDeleteHandlers",{});R(this,"_afterDeleteHandlers",{});R(this,"_operationCompleteHandlers",[]);R(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),()=>Tc(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>Tc(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>Tc(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>Tc(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>Tc(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>Tc(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Tc(this._operationCompleteHandlers,e)}}function Tc(n,e){const t=n.indexOf(e);t>=0&&n.splice(t,1)}class SE{constructor(e){R(this,"id");R(this,"records");R(this,"history",ln("history",0,{historyLength:1e3}));R(this,"query");R(this,"listeners",new Set);R(this,"historyAccumulator",new pee);R(this,"historyReactor");R(this,"schema");R(this,"props");R(this,"scopedTypes");R(this,"sideEffects",new hee(this));R(this,"isMergingRemoteChanges",!1);R(this,"_integrityChecker");R(this,"_isPossiblyCorrupted",!1);R(this,"pendingAfterEvents",null);R(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:s}=e;this.id=s??Tt(),this.schema=r,this.props=e.props,t?this.records=new tk("store",Cs(t).map(([i,o])=>[i,this.schema.validateRecord(this,o,"initialize",null)])):this.records=new tk("store"),this.query=new dee(this.records,this.history),this.historyReactor=iG("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:i=>this.cancelHistoryReactor=u3(i)}),this.scopedTypes={document:new Set(mn(this.schema.types).filter(i=>i.scope==="document").map(i=>i.typeName)),session:new Set(mn(this.schema.types).filter(i=>i.scope==="session").map(i=>i.typeName)),presence:new Set(mn(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:Of(e.added,(s,i)=>this.scopedTypes[t].has(i.typeName)),updated:Of(e.updated,(s,i)=>this.scopedTypes[t].has(i[1].typeName)),removed:Of(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,Ps(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const t=[],r=this.historyAccumulator.addInterceptor(s=>t.push(s.changes));try{return Ps(e),yE(t)}finally{r()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=mn(e.added);for(const[o,a]of mn(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,g]of Object.entries(a))l.ephemeralKeySet.has(f)||Object.is(g,Cn(c,f))||(d||(d={...c}),d[f]=g);d&&s.push(d)}else s.push(a)}const i=TV(e.removed);s.length&&this.put(s),i.length&&this.remove(i)},t)}createCache(e){const t=new qo;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(ln.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(tt(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&tt(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 Ps(()=>{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 fee(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:yE(s.map(i=>i.changes))}))}class pee{constructor(){R(this,"_history",[]);R(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=fee(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function vE(n,e,t){const r=new qo;return{get(s,i){return r.get(s,()=>(s instanceof SE?s:s.store).createComputedCache(n,l=>e(s,l),t)).get(i)}}}function gee(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 Ad({sequence:n,sequenceId:e,retroactive:t=!0}){const r={sequenceId:e,retroactive:t,sequence:gee(n)};return G5(r),r}function _s(n,e){return Object.fromEntries(Cs(e).map(([t,r])=>[t,`${n}/${r}`]))}function Js(n){const e=n.sequenceId;return Ad({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 mee(n){const e=new Map(n.map(i=>[i.id,i])),t=new Set,r=[];function s(i){tt(!t.has(i.id),`Circular dependency in migrations: ${i.id}`),t.add(i.id);const{version:o,sequenceId:a}=aS(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 aS(n){const[e,t]=n.split("/");return{sequenceId:e,version:parseInt(t)}}function QD(n,e){e&&tt(n.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${n}'`),tt(n.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${n}'`)}function G5(n){if(tt(!n.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${n.sequenceId}`),tt(n.sequenceId.length,"sequenceId must be a non-empty string"),n.sequence.length===0)return;QD(n.sequence[0].id,n.sequenceId);let e=aS(n.sequence[0].id).version;tt(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;QD(r,n.sequenceId);const s=aS(r).version;tt(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 xl=(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))(xl||{});function yee(n){if(n.schemaVersion>2||n.schemaVersion<1)return Lr.err("Bad schema version");if(n.schemaVersion===2)return Lr.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 Lr.ok(e)}class xE{constructor(e,t){R(this,"migrations",{});R(this,"sortedMigrations");var s;this.types=e,this.options=t;for(const i of t.migrations??[])tt(!this.migrations[i.sequenceId],`Duplicate migration sequenceId ${i.sequenceId}`),G5(i),this.migrations[i.sequenceId]=i;const r=Object.values(this.migrations).flatMap(i=>i.sequence);this.sortedMigrations=mee(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);tt(a,`Migration '${i.id}' depends on missing migration '${o}'`)}}static create(e,t){return new xE(e,t??{})}validateRecord(e,t,r,s){try{const i=Cn(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=yee(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 Lr.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 Lr.err("Incompatible schema?");for(const d of this.migrations[o].sequence.slice(c+1))i.add(d.id)}return Lr.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:xl.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"?xl.TargetVersionTooOld:xl.TargetVersionTooNew};if(r==="down"){if(!i.every(o=>o.down))return{type:"error",reason:xl.TargetVersionTooOld};i=i.slice().reverse()}e=Xt(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=Xt(l))}}catch(o){return console.error("Error migrating record",o),{type:"error",reason:xl.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:xl.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:t};t=Xt(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]=Xt(c))}else if(i.scope==="store"){const o=i.up(t);o&&(t=Xt(o))}else _n(i)}catch(i){return console.error("Error migrating store",i),{type:"error",reason:xl.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?aS(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=Cn(this.types,e);return tt(t,"record type does not exists"),t}}Yl("@tldraw/store","3.11.1","esm");function See(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 vt extends Error{constructor(t,r=[]){const s=See(r),i=t.split(`
180
+ `).map((o,a)=>a===0?o:` ${o}`).join(`
181
+ `);super(r?`At ${s}: ${i}`:i);R(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Is(n,e){try{return e()}catch(t){throw t instanceof vt?new vt(t.rawMessage,[n,...t.path]):new vt(t.toString(),[n])}}function Ul(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:_n(e)}}class Tr{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 kee(this)}optional(){return X5(this)}refine(e){return new Tr(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=>(Is(`(check ${e})`,()=>t(r)),r)):this.refine(r=>(e(r),r))}}class vee extends Tr{constructor(e){super(t=>{const r=ej.validate(t);for(let s=0;s<r.length;s++)Is(s,()=>e.validate(r[s]));return r},(t,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=ej.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,Is(o,()=>e.validate(a));continue}if(Object.is(t[o],a))continue;const l=Is(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 vt("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new vt("Expected an array with length greater than 1")})}}class lS extends Tr{constructor(e,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new vt(`Expected object, got ${Ul(r)}`);for(const[s,i]of Object.entries(e))Is(s,()=>{i.validate(Cn(r,s))});if(!t){for(const s of Object.keys(r))if(!wi(e,s))throw new vt("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new vt(`Expected object, got ${Ul(s)}`);let i=!1;for(const[o,a]of Object.entries(e)){const l=Cn(r,o),c=Cn(s,o);if(Object.is(l,c))continue;const d=Is(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(!wi(e,o))throw new vt("Unexpected property",[o])}for(const o of Object.keys(r))if(!wi(s,o)){i=!0;break}return i?s:r}),this.config=e,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new lS(this.config,!0)}extend(e){return new lS({...this.config,...e})}}class U0 extends Tr{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):Is(`(${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):Cn(i,e)!==Cn(o,e)?Is(`(${e} = ${l})`,()=>a.validate(o)):Is(`(${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 vt(`Expected an object, got ${Ul(e)}`,[])}getMatchingSchemaAndVariant(e){const t=Cn(e,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new vt(`Expected a string for key "${this.key}", got ${Ul(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new vt(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:wi(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(e){return new U0(this.key,this.config,e,this.useNumberKeys)}}class xee extends Tr{constructor(e,t){super(r=>{if(typeof r!="object"||r===null)throw new vt(`Expected object, got ${Ul(r)}`);for(const[s,i]of Object.entries(r))Is(s,()=>{e.validate(s),t.validate(i)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new vt(`Expected object, got ${Ul(s)}`);let i=!1;for(const[o,a]of Object.entries(s)){if(!wi(r,o)){i=!0,Is(o,()=>{e.validate(o),t.validate(a)});continue}const l=Cn(r,o),c=a;if(Object.is(l,c))continue;const d=Is(o,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,c):t.validate(c));Object.is(d,l)||(i=!0)}for(const o of Object.keys(r))if(!wi(s,o)){i=!0;break}return i?s:r}),this.keyValidator=e,this.valueValidator=t}}function wE(n){return new Tr(e=>{if(typeof e!==n)throw new vt(`Expected ${n}, got ${Ul(e)}`);return e})}const wee=new Tr(n=>n),bee=new Tr(n=>n),it=wE("string"),Xe=wE("number").check(n=>{if(Number.isNaN(n))throw new vt("Expected a number, got NaN");if(!Number.isFinite(n))throw new vt(`Expected a finite number, got ${n}`)}),cS=Xe.check(n=>{if(n<0)throw new vt(`Expected a positive number, got ${n}`)}),kn=Xe.check(n=>{if(n<=0)throw new vt(`Expected a non-zero positive number, got ${n}`)}),Y5=Xe.check(n=>{if(!Number.isInteger(n))throw new vt(`Expected an integer, got ${n}`)}),oy=Y5.check(n=>{if(n<0)throw new vt(`Expected a positive integer, got ${n}`)}),Cee=Y5.check(n=>{if(n<=0)throw new vt(`Expected a non-zero positive integer, got ${n}`)}),yt=wE("boolean");function Er(n){return new Tr(e=>{if(e!==n)throw new vt(`Expected ${n}, got ${JSON.stringify(e)}`);return n})}const ej=new Tr(n=>{if(!Array.isArray(n))throw new vt(`Expected an array, got ${Ul(n)}`);return n});function Bn(n){return new vee(n)}function pt(n){return new lS(n)}function rk(n){return typeof n=="object"&&n!==null&&(Object.getPrototypeOf(n)===Object.prototype||Object.getPrototypeOf(n)===null||Object.getPrototypeOf(n)===tq)}function sk(n){return n===null||typeof n=="number"||typeof n=="string"||typeof n=="boolean"?!0:Array.isArray(n)?n.every(sk):rk(n)?Object.values(n).every(sk):!1}const ir=new Tr(n=>{if(sk(n))return n;throw new vt(`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,ir.validate(e[r]);continue}const s=n[r],i=e[r];if(Object.is(s,i))continue;const o=ir.validateUsingKnownGoodVersion(s,i);Object.is(o,s)||(t=!0)}return t?e:n}else if(rk(n)&&rk(e)){let t=!1;for(const r of Object.keys(e)){if(!wi(n,r)){t=!0,ir.validate(e[r]);continue}const s=n[r],i=e[r];if(Object.is(s,i))continue;const o=ir.validateUsingKnownGoodVersion(s,i);Object.is(o,s)||(t=!0)}for(const r of Object.keys(n))if(!wi(e,r)){t=!0;break}return t?e:n}else return ir.validate(e)});function uS(n,e){return new xee(n,e)}function bE(n,e){return new U0(n,e,(t,r)=>{throw new vt(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!1)}function Pee(n,e){return new U0(n,e,(t,r)=>{throw new vt(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!0)}function Yo(n,e){return new Tr(t=>Is(n,()=>e.validate(t)),(t,r)=>Is(n,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(t,r):e.validate(r)))}function H0(n){return new Tr(e=>{if(!n.has(e)){const t=Array.from(n,r=>JSON.stringify(r)).join(" or ");throw new vt(`Expected ${t}, got ${e}`)}return e})}function X5(n){return new Tr(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 kee(n){return new Tr(e=>e===null?null:n.validate(e),(e,t)=>t===null?null:n.validateUsingKnownGoodVersion&&e!==null?n.validateUsingKnownGoodVersion(e,t):n.validate(t))}function K0(...n){return H0(new Set(n))}function CE(n){try{return new URL(n)}catch{if(n.startsWith("/")||n.startsWith("./"))try{return new URL(n,"http://example.com")}catch{throw new vt(`Expected a valid url, got ${JSON.stringify(n)}`)}throw new vt(`Expected a valid url, got ${JSON.stringify(n)}`)}}const Iee=new Set(["http:","https:","mailto:"]),Ys=it.check(n=>{if(n==="")return;const e=CE(n);if(!Iee.has(e.protocol.toLowerCase()))throw new vt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)}),Eee=new Set(["http:","https:","data:","asset:"]),tu=it.check(n=>{if(n==="")return;const e=CE(n);if(!Eee.has(e.protocol.toLowerCase()))throw new vt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});it.check(n=>{if(n==="")return;if(!CE(n).protocol.toLowerCase().match(/^https?:$/))throw new vt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});const PE=it.refine(n=>{try{return WV(n),n}catch{throw new vt(`Expected an index key, got ${JSON.stringify(n)}`)}});Yl("@tldraw/validate","3.11.1","esm");function qs(n){return it.refine(e=>{if(!e.startsWith(`${n}:`))throw new Error(`${n} ID must start with "${n}:"`);return e})}const W0=qs("asset");function kE(n,e){return pt({id:W0,typeName:Er("asset"),type:Er(n),props:e,meta:ir})}const nu=pt({x:Xe,y:Xe,z:Xe.optional()}),Lf=pt({x:Xe,y:Xe,w:Xe,h:Xe}),Z5=Xe.check(n=>{if(n<0||n>1)throw new vt("Opacity must be between 0 and 1")}),_ee=it.refine(n=>{if(!n.startsWith("page:")&&!n.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return n}),gi=qs("shape");function Tee(n,e,t){return pt({id:gi,typeName:Er("shape"),x:Xe,y:Xe,rotation:Xe,index:PE,parentId:_ee,type:Er(n),isLocked:yt,opacity:Z5,props:e?pt(e):ir,meta:t?pt(t):ir})}const Mee=qs("binding");function Aee(n,e,t){return pt({id:Mee,typeName:Er("binding"),type:Er(n),fromId:gi,toId:gi,props:e?pt(e):ir,meta:t?pt(t):ir})}_s("com.tldraw.binding",{});Js({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function qc(n){return`binding:${Tt()}`}function Oee(n){return Go("binding",{scope:"document",validator:Yo("binding",bE("type",rh(n,(e,{props:t,meta:r})=>Aee(e,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class dr{constructor(e,t,r){this.id=e,this.defaultValue=t,this.type=r}static define(e,t){const{defaultValue:r,type:s=bee}=t;return new dr(e,r,s)}static defineEnum(e,t){const{defaultValue:r,values:s}=t;return new Ree(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 Ree extends dr{constructor(e,t,r){super(e,t,K0(...r)),this.values=r}}const ym=_s("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),Dee=Js({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:ym.AddIsLocked,up:n=>{n.isLocked=!1},down:n=>{delete n.isLocked}},{id:ym.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:ym.AddMeta,up:n=>{n.meta={}}},{id:ym.AddWhite,up:n=>{},down:n=>{n.props.color==="white"&&(n.props.color="black")}}]});function Pd(n){return n?n.typeName==="shape":!1}function ys(n){return n?n.startsWith("shape:"):!1}function jt(n){return`shape:${n??Tt()}`}function J5(n){const e=new Map;for(const[t,r]of Object.entries(n))if(r instanceof dr){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 io(n,e){return rh(e,(t,r)=>`com.tldraw.shape.${n}/${r}`)}function jee(n){return Go("shape",{scope:"document",validator:Yo("shape",bE("type",rh(n,(e,{props:t,meta:r})=>Tee(e,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function tj(n,e){const t=[];for(const[r,{migrations:s}]of Object.entries(e)){const i=`com.tldraw.${n}.${r}`;s?"sequenceId"in s?(tt(i===s.sequenceId,`sequenceId mismatch for ${r} ${B0} migrations. Expected '${i}', got '${s.sequenceId}'`),t.push(s)):"sequence"in s?t.push(Ad({sequenceId:i,retroactive:!1,sequence:s.sequence.map(o=>"id"in o?Q5(n,r,o):o)})):t.push(Ad({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(Ad({sequenceId:i,retroactive:!1,sequence:[]}))}return t}function Q5(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 e4=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],dS={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 Ha(n){return n.isDarkMode?dS.darkMode:dS.lightMode}const Xs=dr.defineEnum("tldraw:color",{defaultValue:"black",values:e4}),IE=dr.defineEnum("tldraw:labelColor",{defaultValue:"black",values:e4}),ru=dr.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),su=dr.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Na=dr.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),t4={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Bo=dr.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),n4=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],hS=dr.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:n4}),fS=dr.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:n4}),r4={labelColor:IE,color:Xs,fill:su,dash:ru,size:Bo,arrowheadStart:hS,arrowheadEnd:fS,font:Na,start:nu,end:nu,bend:Xe,text:it,labelPosition:Xe,scale:kn},yd=io("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function Sm(n){return Q5("shape","arrow",n)}const s4=Ad({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[Sm({id:yd.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"}),Sm({id:yd.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)}}),Sm({id:yd.AddLabelPosition,up:n=>{n.labelPosition=.5},down:n=>{delete n.labelPosition}}),{id:yd.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=qc(),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=qc(),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}}},Sm({id:yd.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}})]}),i4={terminal:K0("start","end"),normalizedAnchor:nu,isExact:yt,isPrecise:yt},o4={sequence:[{dependsOn:[yd.ExtractBindings]}]},Nee=Yo("camera",pt({typeName:Er("camera"),id:qs("camera"),x:Xe,y:Xe,z:Xe,meta:ir})),Lee=_s("com.tldraw.camera",{AddMeta:1}),Fee=Js({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:Lee.AddMeta,up:n=>{n.meta={}}}]}),Do=Go("camera",{validator:Nee,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),zee=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"]),a4=H0(zee),$ee=pt({type:a4,rotation:Xe}),Bee=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),Uee=H0(Bee),Hee=new Set(["starting","paused","active","stopping"]),l4=pt({id:it,points:Bn(nu),size:cS,color:Uee,opacity:Xe,state:H0(Hee),delay:Xe,shrink:Xe,taper:yt}),up=qs("page"),Kee=Yo("page",pt({typeName:Er("page"),id:up,name:it,index:PE,meta:ir})),Wee=_s("com.tldraw.page",{AddMeta:1}),Vee=Js({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:Wee.AddMeta,up:n=>{n.meta={}}}]}),Es=Go("page",{validator:Kee,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function ps(n){return Es.isId(n)}const qee={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 c4(n){return n?Of(n,e=>qee[e]):null}qs("instance");function Gee(n){const e={};for(const[r,s]of n)e[r]=X5(s);const t=Yo("instance",pt({typeName:Er("instance"),id:qs("instance"),currentPageId:up,followingUserId:it.nullable(),brush:Lf.nullable(),opacityForNextShape:Z5,stylesForNextShape:pt(e),cursor:$ee,scribbles:Bn(l4),isFocusMode:yt,isDebugMode:yt,isToolLocked:yt,exportBackground:yt,screenBounds:Lf,insets:Bn(yt),zoomBrush:Lf.nullable(),isPenMode:yt,isGridMode:yt,chatMessage:it,isChatting:yt,highlightedUserIds:Bn(it),isFocused:yt,devicePixelRatio:Xe,isCoarsePointer:yt,isHoveringCanvas:yt.nullable(),openMenus:Bn(it),isChangingStyle:yt,isReadonly:yt,meta:ir,duplicateProps:pt({shapeIds:Bn(qs("shape")),offset:pt({x:Xe,y:Xe})}).nullable()}));return Go("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 Gt=_s("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}),Yee=Js({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:Gt.AddTransparentExportBgs,up:n=>({...n,exportBackground:!0})},{id:Gt.RemoveDialog,up:({dialog:n,...e})=>e},{id:Gt.AddToolLockMode,up:n=>({...n,isToolLocked:!1})},{id:Gt.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:Gt.AddLabelColor,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:{...n,labelColor:"black"}})},{id:Gt.AddFollowingUserId,up:n=>({...n,followingUserId:null})},{id:Gt.RemoveAlignJustify,up:n=>{let e=n.propsForNextShape.align;return e==="justify"&&(e="start"),{...n,propsForNextShape:{...n.propsForNextShape,align:e}}}},{id:Gt.AddZoom,up:n=>({...n,zoomBrush:null})},{id:Gt.AddVerticalAlign,up:n=>({...n,propsForNextShape:{...n.propsForNextShape,verticalAlign:"middle"}})},{id:Gt.AddScribbleDelay,up:n=>n.scribble!==null?{...n,scribble:{...n.scribble,delay:0}}:{...n}},{id:Gt.RemoveUserId,up:({userId:n,...e})=>e},{id:Gt.AddIsPenModeAndIsGridMode,up:n=>({...n,isPenMode:!1,isGridMode:!1})},{id:Gt.HoistOpacity,up:({propsForNextShape:{opacity:n,...e},...t})=>({...t,opacityForNextShape:Number(n??"1"),propsForNextShape:e})},{id:Gt.AddChat,up:n=>({...n,chatMessage:"",isChatting:!1})},{id:Gt.AddHighlightedUserIds,up:n=>({...n,highlightedUserIds:[]})},{id:Gt.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:n,...e})=>({...e,stylesForNextShape:{}})},{id:Gt.AddMeta,up:n=>({...n,meta:{}})},{id:Gt.RemoveCursorColor,up:n=>{const{color:e,...t}=n.cursor;return{...n,cursor:t}}},{id:Gt.AddLonelyProperties,up:n=>({...n,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:Gt.ReadOnlyReadonly,up:({isReadOnly:n,...e})=>({...e,isReadonly:n})},{id:Gt.AddHoveringCanvas,up:n=>({...n,isHoveringCanvas:null})},{id:Gt.AddScribbles,up:({scribble:n,...e})=>({...e,scribbles:[]})},{id:Gt.AddInset,up:n=>({...n,insets:[!1,!1,!1,!1]}),down:({insets:n,...e})=>({...e})},{id:Gt.AddDuplicateProps,up:n=>({...n,duplicateProps:null}),down:({duplicateProps:n,...e})=>({...e})},{id:Gt.RemoveCanMoveCamera,up:({canMoveCamera:n,...e})=>({...e}),down:n=>({...n,canMoveCamera:!0})}]}),zr="instance:instance",Xee=Yo("instance_page_state",pt({typeName:Er("instance_page_state"),id:qs("instance_page_state"),pageId:up,selectedShapeIds:Bn(gi),hintingShapeIds:Bn(gi),erasingShapeIds:Bn(gi),hoveredShapeId:gi.nullable(),editingShapeId:gi.nullable(),croppingShapeId:gi.nullable(),focusedGroupId:gi.nullable(),meta:ir})),sf=_s("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),Zee=Js({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:sf.AddCroppingId,up(n){n.croppingShapeId=null}},{id:sf.RemoveInstanceIdAndCameraId,up(n){delete n.instanceId,delete n.cameraId}},{id:sf.AddMeta,up:n=>{n.meta={}}},{id:sf.RenameProperties,up:n=>{},down:n=>{}},{id:sf.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}}]}),Vi=Go("instance_page_state",{validator:Xee,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:{}})),Jee=Yo("pointer",pt({typeName:Er("pointer"),id:qs("pointer"),x:Xe,y:Xe,lastActivityTimestamp:Xe,meta:ir})),Qee=_s("com.tldraw.pointer",{AddMeta:1}),ete=Js({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:Qee.AddMeta,up:n=>{n.meta={}}}]}),EE=Go("pointer",{validator:Jee,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),pS=EE.createId("pointer"),tte=Yo("instance_presence",pt({typeName:Er("instance_presence"),id:qs("instance_presence"),userId:it,userName:it,lastActivityTimestamp:Xe.nullable(),followingUserId:it.nullable(),cursor:pt({x:Xe,y:Xe,type:a4,rotation:Xe}).nullable(),color:it,camera:pt({x:Xe,y:Xe,z:Xe}).nullable(),screenBounds:Lf.nullable(),selectedShapeIds:Bn(qs("shape")),currentPageId:qs("page"),brush:Lf.nullable(),scribbles:Bn(l4),chatMessage:it,meta:ir})),od=_s("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),nte=Js({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:od.AddScribbleDelay,up:n=>{n.scribble!==null&&(n.scribble.delay=0)}},{id:od.RemoveInstanceId,up:n=>{delete n.instanceId}},{id:od.AddChatMessage,up:n=>{n.chatMessage=""}},{id:od.AddMeta,up:n=>{n.meta={}}},{id:od.RenameSelectedShapeIds,up:n=>{}},{id:od.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})}}]}),rte=Go("instance_presence",{validator:tte,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),ste=Yo("document",pt({typeName:Er("document"),id:Er("document:document"),gridSize:Xe,name:it,meta:ir})),nj=_s("com.tldraw.document",{AddName:1,AddMeta:2}),ite=Js({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:nj.AddName,up:n=>{n.name=""},down:n=>{delete n.name}},{id:nj.AddMeta,up:n=>{n.meta={}}}]}),_E=Go("document",{validator:ste,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),ik=_E.createId("document");function ote(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function rj(n){n.typeName==="asset"&&("src"in n&&(n.src="<redacted>"),"src"in n.props&&(n.props.src="<redacted>"))}function ate({error:n,phase:e,record:t,recordBefore:r}){throw pI(n,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?rj(Xt(r)):void 0,recordAfter:rj(Xt(t))}}),n}function lte(){return[Es.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function cte(n){const e=n.query.ids("page"),t=n.query.records("instance_page_state"),r=()=>{if(!n.has(ik))return n.put([_E.create({id:ik,name:n.props.defaultName})]),r();if(!n.has(pS))return n.put([EE.create({id:pS})]),r();const s=e.get();if(s.size===0)return n.put(lte()),r();const i=()=>[...s].map(d=>n.get(d)).sort(ote)[0].id,o=n.get(zr);if(o){if(!s.has(o.currentPageId))return n.put([{...o,currentPageId:i()}]),r()}else return n.put([n.schema.types.instance.create({id:zr,currentPageId:i(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const d of s){const f=Vi.createId(d);n.get(f)||a.add(f);const m=Do.createId(d);n.has(m)||l.add(m)}a.size>0&&n.put([...a].map(d=>Vi.create({id:d,pageId:Vi.parseId(d)}))),l.size>0&&n.put([...l].map(d=>Do.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 g=d.hintingShapeIds.filter(y=>n.has(y));if(g.length!==d.hintingShapeIds.length)return n.put([{...d,hintingShapeIds:g}]),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 ute=kE("bookmark",pt({title:it,description:it,image:it,favicon:it,src:tu.nullable()})),sj=_s("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),dte=Js({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:n=>n.type==="bookmark",sequence:[{id:sj.MakeUrlsValid,up:n=>{tu.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:sj.AddFavicon,up:n=>{tu.isValid(n.props.favicon)||(n.props.favicon="")},down:n=>{delete n.props.favicon}}]}),hte=kE("image",pt({w:Xe,h:Xe,name:it,isAnimated:yt,mimeType:it.nullable(),src:tu.nullable(),fileSize:kn.optional()})),of=_s("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),fte=Js({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:n=>n.type==="image",sequence:[{id:of.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:of.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:of.MakeUrlsValid,up:n=>{tu.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:of.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:of.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),pte=kE("video",pt({w:Xe,h:Xe,name:it,isAnimated:yt,mimeType:it.nullable(),src:tu.nullable(),fileSize:Xe.optional()})),af=_s("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),gte=Js({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:n=>n.type==="video",sequence:[{id:af.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:af.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:af.MakeUrlsValid,up:n=>{tu.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:af.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:af.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),mte=Yo("asset",bE("type",{image:hte,video:pte,bookmark:ute})),yte=_s("com.tldraw.asset",{AddMeta:1}),Ste=Js({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:yte.AddMeta,up:n=>{n.meta={}}}]}),Hl=Go("asset",{validator:mte,scope:"document"}).withDefaultProperties(()=>({meta:{}})),u4={w:kn,h:kn,assetId:W0.nullable(),url:Ys},ij=io("bookmark",{NullAssetId:1,MakeUrlsValid:2}),d4={sequence:[{id:ij.NullAssetId,up:n=>{n.assetId===void 0&&(n.assetId=null)},down:"retired"},{id:ij.MakeUrlsValid,up:n=>{Ys.isValid(n.url)||(n.url="")},down:n=>{}}]},h4=pt({type:K0("free","straight"),points:Bn(nu)}),f4={color:Xs,fill:su,dash:ru,size:Bo,segments:Bn(h4),isComplete:yt,isClosed:yt,isPen:yt,scale:kn},oj=io("draw",{AddInPen:1,AddScale:2}),p4={sequence:[{id:oj.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:oj.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},vte=/(^\/r\/[^/]+\/?$)/,xte=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:n=>{const e=Ze(n);if(e&&e.pathname.match(vte))return n}},{hostnames:["figma.com"],fromEmbedUrl:n=>{const e=Ze(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{hostnames:["google.*"],fromEmbedUrl:n=>{const e=Ze(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=Ze(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:n=>{const e=Ze(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=Ze(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=Ze(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=Ze(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=Ze(n);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return n.split("/").pop()?n:void 0}},{hostnames:["replit.com"],fromEmbedUrl:n=>{const e=Ze(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:n=>{const e=Ze(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=Ze(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=Ze(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=Ze(n);if(e&&e.hash.match(/#room=/))return n}},{hostnames:["observablehq.com"],fromEmbedUrl:n=>{const e=Ze(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=Ze(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],g4={w:kn,h:kn,url:it},vm=io("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),m4={sequence:[{id:vm.GenOriginalUrlInEmbed,up:n=>{try{const e=n.url,t=new URL(e).host.replace("www.","");let r;for(const s of xte)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:vm.RemoveDoesResize,up:n=>{delete n.doesResize},down:"retired"},{id:vm.RemoveTmpOldUrl,up:n=>{delete n.tmpOldUrl},down:"retired"},{id:vm.RemovePermissionOverrides,up:n=>{delete n.overridePermissions},down:"retired"}]},y4={w:kn,h:kn,name:it},S4={sequence:[]},TE=pt({type:it,content:Bn(wee)});function ki(n){return{type:"doc",content:n.split(`
182
+ `).map(r=>r?{type:"paragraph",content:[{type:"text",text:r}]}:{type:"paragraph"})}}const gS=dr.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),mS=dr.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),qi=dr.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"]}),v4={geo:qi,labelColor:IE,color:Xs,fill:su,dash:ru,size:Bo,font:Na,align:gS,verticalAlign:mS,url:Ys,w:kn,h:kn,growY:cS,richText:TE,scale:kn},wo=io("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9,AddRichText:10}),x4={sequence:[{id:wo.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:wo.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"},{id:wo.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:wo.AddCheckBox,up:n=>{},down:"retired"},{id:wo.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:wo.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:wo.AddCloud,up:n=>{},down:"retired"},{id:wo.MakeUrlsValid,up:n=>{Ys.isValid(n.url)||(n.url="")},down:n=>{}},{id:wo.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:wo.AddRichText,up:n=>{n.richText=ki(n.text),delete n.text}}]},w4={},b4={sequence:[]},C4={color:Xs,size:Bo,segments:Bn(h4),isComplete:yt,isPen:yt,scale:kn},wte=io("highlight",{AddScale:1}),P4={sequence:[{id:wte.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},bte=pt({topLeft:nu,bottomRight:nu}),k4={w:kn,h:kn,playing:yt,url:Ys,assetId:W0.nullable(),crop:bte.nullable(),flipX:yt,flipY:yt},xm=io("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),I4={sequence:[{id:xm.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:xm.AddCropProp,up:n=>{n.crop=null},down:n=>{delete n.crop}},{id:xm.MakeUrlsValid,up:n=>{Ys.isValid(n.url)||(n.url="")},down:n=>{}},{id:xm.AddFlipProps,up:n=>{n.flipX=!1,n.flipY=!1},down:n=>{delete n.flipX,delete n.flipY}}]},yS=dr.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),Cte=pt({id:it,index:PE,x:Xe,y:Xe}),E4={color:Xs,dash:ru,size:Bo,spline:yS,points:uS(it,Cte),scale:kn},lf=io("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),_4={sequence:[{id:lf.AddSnapHandles,up:n=>{for(const e of Object.values(n.handles))e.canSnap=!0},down:"retired"},{id:lf.RemoveExtraHandleProps,up:n=>{n.handles=qL(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(tr);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:lf.HandlesToPoints,up:n=>{const e=Object.entries(n.handles).map(([t,{x:r,y:s}])=>({x:r,y:s,index:t})).sort(tr);n.points=e.map(({x:t,y:r})=>({x:t,y:r})),delete n.handles},down:n=>{const e=ep(n.points.length);n.handles=Object.fromEntries(n.points.map((t,r)=>[e[r],{x:t.x,y:t.y}])),delete n.points}},{id:lf.PointIndexIds,up:n=>{const e=ep(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(tr);n.points=e.map(({x:t,y:r})=>({x:t,y:r}))}},{id:lf.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},T4={color:Xs,labelColor:IE,size:Bo,font:Na,fontSizeAdjustment:cS,align:gS,verticalAlign:mS,growY:cS,url:Ys,richText:TE,scale:kn},fa=io("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8,AddRichText:9}),M4={sequence:[{id:fa.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:fa.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:fa.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:fa.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:fa.MakeUrlsValid,up:n=>{Ys.isValid(n.url)||(n.url="")},down:n=>{}},{id:fa.AddFontSizeAdjustment,up:n=>{n.fontSizeAdjustment=0},down:n=>{delete n.fontSizeAdjustment}},{id:fa.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:fa.AddLabelColor,up:n=>{n.labelColor="black"},down:n=>{delete n.labelColor}},{id:fa.AddRichText,up:n=>{n.richText=ki(n.text),delete n.text}}]},ok=dr.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),A4={color:Xs,size:Bo,font:Na,textAlign:ok,w:kn,richText:TE,scale:kn,autoSize:yt},sC=io("text",{RemoveJustify:1,AddTextAlign:2,AddRichText:3}),O4={sequence:[{id:sC.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:sC.AddTextAlign,up:n=>{n.textAlign=n.align,delete n.align},down:n=>{n.align=n.textAlign,delete n.textAlign}},{id:sC.AddRichText,up:n=>{n.richText=ki(n.text),delete n.text}}]},R4={w:kn,h:kn,time:Xe,playing:yt,url:Ys,assetId:W0.nullable()},aj=io("video",{AddUrlProp:1,MakeUrlsValid:2}),D4={sequence:[{id:aj.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:aj.MakeUrlsValid,up:n=>{Ys.isValid(n.url)||(n.url="")},down:n=>{}}]},wm=_s("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),Pte=Ad({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:wm.RemoveCodeAndIconShapeTypes,scope:"store",up:n=>{for(const[e,t]of Cs(n))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete n[e]}},{id:wm.AddInstancePresenceType,scope:"store",up(n){}},{id:wm.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:n=>{for(const[e,t]of Cs(n))t.typeName.match(/^(user|user_presence)$/)&&delete n[e]}},{id:wm.RemoveUserDocument,scope:"store",up:n=>{for(const[e,t]of Cs(n))t.typeName.match("user_document")&&delete n[e]}}]}),kte={arrow:{migrations:s4,props:r4},bookmark:{migrations:d4,props:u4},draw:{migrations:p4,props:f4},embed:{migrations:m4,props:g4},frame:{migrations:S4,props:y4},geo:{migrations:x4,props:v4},group:{migrations:b4,props:w4},highlight:{migrations:P4,props:C4},image:{migrations:I4,props:k4},line:{migrations:_4,props:E4},note:{migrations:M4,props:T4},text:{migrations:O4,props:A4},video:{migrations:D4,props:R4}},Ite={arrow:{migrations:o4,props:i4}};function Ete({shapes:n=kte,bindings:e=Ite,migrations:t}={}){const r=new Map;for(const a of mn(n))for(const l of J5(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=jee(n),i=Oee(e),o=Gee(r);return xE.create({asset:Hl,binding:i,camera:Do,document:_E,instance:o,instance_page_state:Vi,page:Es,instance_presence:rte,pointer:EE,shape:s},{migrations:[Pte,Ste,Fee,ite,Yee,Zee,Vee,nte,ete,Dee,dte,fte,gte,...tj("shape",n),...tj("binding",e),...t??[]],onValidationFailure:ate,createIntegrityChecker:cte})}const dp=[{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 _te(){const n=typeof window<"u"?window.navigator.languages??["en"]:["en"];return Tte(n)}function Tte(n){for(const e of n){const t=Mte(e);if(t)return t}return"en"}const lj={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function Mte(n){const e=dp.find(s=>s.locale===n.toLowerCase());if(e)return e.locale;const[t,r]=n.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=dp.find(i=>i.locale===t);if(s)return s.locale}return t in lj?lj[t]:null}Yl("@tldraw/tlschema","3.11.1","esm");var iC={exports:{}};/*!
183
+ Copyright (c) 2018 Jed Watson.
184
+ Licensed under the MIT License (MIT), see
185
+ http://jedwatson.github.io/classnames
186
+ */var cj;function Ate(){return cj||(cj=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})()}(iC)),iC.exports}var Ote=Ate();const ze=$a(Ote),j4="3.11.1",uj={major:"2024-09-13T14:36:29.063Z",minor:"2025-03-20T14:45:59.625Z"},Rte={error:null};class ME extends P.Component{constructor(){super(...arguments);R(this,"state",Rte)}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,s;(s=(r=this.props).onError)==null||s.call(r,t)}render(){const{error:t}=this.state;if(t!==null){const{fallback:r}=this.props;return p.jsx(r,{error:t})}return this.props.children}}function hp({children:n,fallback:e,...t}){return e===null?n:p.jsx(ME,{fallback:e,...t,children:n})}function AE(n,e){return V0(`${n}_${e}`)}function Su(n){return V0(`${P.useId()}${n??""}`)}function Zi(n){const e=Fr(P.useContext(N4));return V0(`${e}_${n}`)}function V0(n){return n.replace(/:/g,"_")}const N4=P.createContext(null);function Dte({children:n}){const e=Su();return p.jsx(N4.Provider,{value:e,children:n})}const OE=P.createContext(null);function Q(){const n=ot.useContext(OE);if(!n)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return n}function Mr(){return ot.useContext(OE)}function RE({editor:n,children:e}){return p.jsx(OE.Provider,{value:n,children:p.jsx(Dte,{children:e})})}function jte(){return p.jsx("div",{className:"tl-background"})}function ch(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 oC=({brush:n,color:e,opacity:t,className:r})=>{const s=P.useRef(null);ch(s,n.x,n.y);const i=te(Math.max(1,n.w)),o=te(Math.max(1,n.h));return p.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?p.jsxs("g",{className:"tl-brush",opacity:t,children:[p.jsx("rect",{width:i,height:o,fill:e,opacity:.75}),p.jsx("rect",{width:i,height:o,fill:"none",stroke:e,opacity:.1})]}):p.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:i,height:o})})},kt={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1,hasCanvasSupport:!1};typeof window<"u"&&"navigator"in window&&(kt.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),kt.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),kt.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),kt.isFirefox=/firefox/i.test(navigator.userAgent),kt.isAndroid=/android/i.test(navigator.userAgent),kt.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,kt.hasCanvasSupport=typeof window<"u"&&"Promise"in window&&"HTMLCanvasElement"in window);const dj={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.05,.1,.25,.5,1,2,4,8]},aC={duration:0,easing:Un.easeInOutCubic},hj={CAMERA_MOVE:-10},Nte=["top","right","bottom","left"],fj=0,DE=2,bm=1,pj=5,Lte=128;var lC={};const Fte={},L4=fs("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),bn={logPreventDefaults:fs("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:fs("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:fs("logElementRemoves",{defaults:{all:!1}}),debugSvg:fs("debugSvg",{defaults:{all:!1}}),showFps:fs("showFps",{defaults:{all:!1}}),measurePerformance:fs("measurePerformance",{defaults:{all:!1}}),throwToBlob:fs("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:fs("reconnectOnPing",{defaults:{all:!1}}),debugCursors:fs("debugCursors",{defaults:{all:!1}}),forceSrgb:fs("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:fs("debugGeometry",{defaults:{all:!1}}),hideShapes:fs("hideShapes",{defaults:{all:!1}}),editOnType:fs("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const n=Element.prototype.removeChild;Yi("element removal logging",()=>{bn.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),n.call(this,e)}:Element.prototype.removeChild=n})}function fs(n,{defaults:e,shouldStoreForSession:t=!0}){return zte({name:n,defaults:e,shouldStoreForSession:t})}function zte(n){const e=Bte(n),t=n.shouldStoreForSession?$te(n.name):null,r=ln(`debug:${n.name}`,t??e);return typeof window<"u"&&(n.shouldStoreForSession&&Yi(`debug:${n.name}`,()=>{const s=r.get();s===e?l3(`tldraw_debug:${n.name}`):wI(`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 $te(n){try{return JSON.parse(a3(`tldraw_debug:${n}`)??"null")}catch{return null}}function cC(n){try{return n()}catch{return null}}function Bte(n){switch(cC(()=>lC.TLDRAW_ENV)??cC(()=>lC.VERCEL_PUBLIC_TLDRAW_ENV)??cC(()=>lC.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 SS(n){if(n instanceof HTMLElement)return n;if(n.parentElement)return SS(n.parentElement);throw Error("Could not find a parent element of an HTML type!")}function et(n){n.preventDefault(),bn.logPreventDefaults.get()&&console.warn("preventDefault called on event:",n)}function Lp(n,e){if(n.setPointerCapture(e.pointerId),bn.logPointerCaptures.get()){const t=L4.get();t.set(n,(t.get(n)??0)+1),console.warn("setPointerCapture called on element:",n,e)}}function Fp(n,e){if(n.hasPointerCapture(e.pointerId)&&(n.releasePointerCapture(e.pointerId),bn.logPointerCaptures.get())){const t=L4.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 Zt=n=>n.stopPropagation(),Sr=(n,e,t)=>{n&&n.style.setProperty(e,t)},Ute=["input","select","button","textarea"];function F4(){const{activeElement:n}=document;return!!(n&&(n.isContentEditable||Ute.indexOf(n.tagName.toLowerCase())>-1))}const Pr=n=>kt.isDarwin?n.metaKey:n.ctrlKey||n.metaKey;function Hs(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:Pr(n),pointerId:n.pointerId,button:n.button,isPen:n.pointerType==="pen"}}function jE(){const n=Q();return P.useMemo(function(){let r,s;function i(v){if(!v.isKilled){if(v.button===DE){n.dispatch({type:"pointer",target:"canvas",name:"right_click",...Hs(v)});return}v.button!==0&&v.button!==1&&v.button!==5||(Lp(v.currentTarget,v),n.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Hs(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",...Hs(v)}))}function a(v){v.isKilled||v.button!==0&&v.button!==1&&v.button!==2&&v.button!==5||(r=v.clientX,s=v.clientY,Fp(v.currentTarget,v),n.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Hs(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,et(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"))&&et(v)}function g(v){et(v)}async function m(v){var b,C;if(et(v),Zt(v),(C=(b=v.dataTransfer)==null?void 0:b.files)!=null&&C.length){const E=Array.from(v.dataTransfer.files);await n.putExternalContent({type:"files",files:E,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){Zt(v)}return{onPointerDown:i,onPointerMove:o,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:g,onDrop:m,onTouchStart:d,onTouchEnd:f,onClick:y}},[n])}function Hte(){const n=Q();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=kt.isFirefox&&!kt.isAndroid&&!kt.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 z4=P.createContext(null);function $4({container:n,children:e}){return p.jsx(z4.Provider,{value:n,children:e})}function Mn(){return Fr(P.useContext(z4),"useContainer used outside of <Tldraw />")}function Kte(){const n=Q(),e=Mn(),t=ie("isFocused",()=>n.getIsFocused(),[n]);P.useEffect(()=>{if(!e)return;function r(s){if(s.isSpecialRedispatchedEvent)return;et(s),Zt(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"))&&!Cm(n)&&et(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){et(a);return}break}case"Tab":{if(Cm(n))return;break}case",":return;case"Escape":{if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&et(a),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),e.focus());return}default:if(Cm(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:Pr(a)};n.dispatch(l)},s=a=>{if(a.isKilled||(a.isKilled=!0,Cm(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:Pr(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()),et(a))}}const o=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&et(a)};return e.addEventListener("touchstart",i,{passive:!1}),e.addEventListener("wheel",o,{passive:!1}),document.addEventListener("gesturestart",et),document.addEventListener("gesturechange",et),document.addEventListener("gestureend",et),e.addEventListener("keydown",r),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",i),e.removeEventListener("wheel",o),document.removeEventListener("gesturestart",et),document.removeEventListener("gesturechange",et),document.removeEventListener("gestureend",et),e.removeEventListener("keydown",r),e.removeEventListener("keyup",s)}},[n,e,t])}function Cm(n){return n.menus.hasOpenMenus()||F4()}const Wte=["textarea","input"];function Vte(n){const e=Q();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(Wte.includes((i=o.tagName)==null?void 0:i.toLocaleLowerCase())||o.isContentEditable||e.isIn("select.editing_shape"))return;et(s)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[e,n])}function qte(n,e,t){return Math.max(e,Math.min(n,t))}const or={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 gj(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function mj(n,e,t,r=.15){return r===0?qte(n,e,t):n<e?-gj(e-n,t-e,r)+e:n>t?+gj(n-t,t-e,r)+t:n}function Gte(n,[e,t],[r,s]){const[[i,o],[a,l]]=n;return[mj(e,i,o,r),mj(t,a,l,s)]}function Yte(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 Xte(n){var e=Yte(n,"string");return typeof e=="symbol"?e:String(e)}function br(n,e,t){return e=Xte(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function yj(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 cn(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?yj(Object(t),!0).forEach(function(r){br(n,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):yj(Object(t)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))})}return n}const B4={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 Sj(n){return n?n[0].toUpperCase()+n.slice(1):""}const Zte=["enter","leave"];function Jte(n=!1,e){return n&&!Zte.includes(e)}function Qte(n,e="",t=!1){const r=B4[n],s=r&&r[e]||e;return"on"+Sj(n)+Sj(s)+(Jte(t,s)?"Capture":"")}const ene=["gotpointercapture","lostpointercapture"];function tne(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const r=ene.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function nne(n,e=""){const t=B4[n],r=t&&t[e]||e;return n+r}function U4(n){return"touches"in n}function rne(n){return U4(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function sne(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 ak(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 ine(n){return sne(n).map(e=>e.identifier)}function vj(n,e){const[t,r]=Array.from(n.touches).filter(s=>e.includes(s.identifier));return ak(t,r)}const xj=40,wj=800;function H4(n){let{deltaX:e,deltaY:t,deltaMode:r}=n;return r===1?(e*=xj,t*=xj):r===2&&(e*=wj,t*=wj),[e,t]}function one(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 vS(n,...e){return typeof n=="function"?n(...e):n}function ane(){}function lne(...n){return n.length===0?ane:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function bj(n,e){return Object.assign({},e,n||{})}const cne=32;class K4{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?vS(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,one(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);or.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 g=[0,0];if(r.hasCustomTransform){const[A,O]=f;g[0]=d[0]!==!1?A-d[0]:0,g[1]=d[1]!==!1?O-d[1]:0}else g[0]=d[0]!==!1?o-d[0]:0,g[1]=d[1]!==!1?a-d[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(g);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=vS(r.bounds,t)),this.setup&&this.setup()),t.movement=g,this.computeOffset()));const[v,x]=t.offset,[[b,C],[E,_]]=t._bounds;t.overflow=[v<b?-1:v>C?1:0,x<E?-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 M=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=Gte(t._bounds,t.offset,M),t.delta=or.sub(t.offset,m),this.computeMovement(),y&&(!t.last||i>cne)){t.delta=or.sub(t.offset,m);const A=t.delta.map(Math.abs);or.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(cn(cn(cn({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function une([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 dne extends K4{constructor(...e){super(...e),br(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=or.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=or.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[rne(e)]:r.axisThreshold;t.axis=une(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 hne=n=>n,Cj=.15,W4={enabled(n=!0){return n},eventOptions(n,e,t){return cn(cn({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[Cj,Cj];case!1:return[0,0];default:return or.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return or.toVector(n)},transform(n,e,t){const r=n||t.shared.transform;return this.hasCustomTransform=!!r,r||hne},threshold(n){return or.toVector(n,0)}},fne=0,zp=cn(cn({},W4),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=fne){return n},bounds(n={}){if(typeof n=="function")return i=>zp.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]]}}),$p=typeof window<"u"&&window.document&&window.document.createElement;function V4(){return $p&&"ontouchstart"in window}function pne(){return V4()||$p&&window.navigator.maxTouchPoints>1}function gne(){return $p&&"onpointerdown"in window}function mne(){return $p&&"exitPointerLock"in window.document}function yne(){try{return"constructor"in GestureEvent}catch{return!1}}const mi={isBrowser:$p,gesture:yne(),touch:V4(),touchscreen:pne(),pointer:gne(),pointerLock:mne()},Sne=250,vne=180,xne=.5,wne=50,bne=250,Cne=10,Pj={mouse:0,touch:0,pen:8};cn(cn({},zp),{},{device(n,e,{pointer:{touch:t=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&mi.pointerLock,mi.touch&&t?"touch":this.pointerLock?"mouse":mi.pointer&&!s?"pointer":mi.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?Sne:void 0,!(!mi.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=or.toVector(n,t?r:s?1:0);return this.filterTaps=t,this.tapsThreshold=r,i},swipe({velocity:n=xne,distance:e=wne,duration:t=bne}={}){return{velocity:this.transform(or.toVector(n)),distance:this.transform(or.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return vne;case!1:return 0;default:return n}},axisThreshold(n){return n?cn(cn({},Pj),n):Pj},keyboardDisplacement(n=Cne){return n}});function q4(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 Pne=30,kne=100;class Ine extends K4{constructor(...e){super(...e),br(this,"ingKey","pinching"),br(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=or.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)*Pne-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=vj(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=ak(...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=vj(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=ak(...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=or.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=[-H4(e)[1]/kne*r.offset[0],0],or.addTo(r._movement,r._delta),q4(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 Ene=cn(cn({},W4),{},{device(n,e,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!mi.touch&&mi.gesture)return"gesture";if(mi.touch&&r)return"touch";if(mi.touchscreen){if(mi.pointer)return"pointer";if(mi.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:r={}}){const s=o=>{const a=bj(vS(t,o),{min:-1/0,max:1/0});return[a.min,a.max]},i=o=>{const a=bj(vS(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",or.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});cn(cn({},zp),{},{mouseOnly:(n=!0)=>n});class _ne extends dne{constructor(...e){super(...e),br(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=H4(e),or.addTo(t._movement,t._delta),q4(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 Tne=zp;cn(cn({},zp),{},{mouseOnly:(n=!0)=>n});const NE=new Map,lk=new Map;function Mne(n){NE.set(n.key,n.engine),lk.set(n.key,n.resolver)}const Ane={key:"pinch",engine:Ine,resolver:Ene},One={key:"wheel",engine:_ne,resolver:Tne};function Rne(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 Dne(n,e){if(n==null)return{};var t=Rne(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 jne={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=mi.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},Nne=["target","eventOptions","window","enabled","transform"];function ay(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]=ay(n[r],s);break;case"boolean":s&&(t[r]=n[r]);break}return t}function Lne(n,e,t={}){const r=n,{target:s,eventOptions:i,window:o,enabled:a,transform:l}=r,c=Dne(r,Nne);if(t.shared=ay({target:s,eventOptions:i,window:o,enabled:a,transform:l},jne),e){const d=lk.get(e);t[e]=ay(cn({shared:t.shared},c),d)}else for(const d in c){const f=lk.get(d);f&&(t[d]=ay(cn({shared:t.shared},c[d]),f))}return t}class G4{constructor(e,t){br(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,r,s,i){const o=this._listeners,a=nne(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=cn(cn({},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 Fne{constructor(){br(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 zne{constructor(e){br(this,"gestures",new Set),br(this,"_targetEventStore",new G4(this)),br(this,"gestureEventStores",{}),br(this,"gestureTimeoutStores",{}),br(this,"handlers",{}),br(this,"config",{}),br(this,"pointerIds",new Set),br(this,"touchIds",new Set),br(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),$ne(this,e)}setEventIds(e){if(U4(e))return this.touchIds=new Set(ine(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=Lne(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=kj(r,a.eventOptions,!!s);if(a.enabled){const c=NE.get(o);new c(this,e,o).bind(l)}}const i=kj(r,t.eventOptions,!!s);for(const o in this.nativeHandlers)i(o,"",a=>this.nativeHandlers[o](cn(cn({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const i in r)r[i]=lne(...r[i]);if(!s)return r;for(const i in r){const{device:o,capture:a,passive:l}=tne(i);this._targetEventStore.add(s,o,"",r[i],{capture:a,passive:l})}}}}function ad(n,e){n.gestures.add(e),n.gestureEventStores[e]=new G4(n,e),n.gestureTimeoutStores[e]=new Fne}function $ne(n,e){e.drag&&ad(n,"drag"),e.wheel&&ad(n,"wheel"),e.scroll&&ad(n,"scroll"),e.move&&ad(n,"move"),e.pinch&&ad(n,"pinch"),e.hover&&ad(n,"hover")}const kj=(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 g=a?r:Qte(r,s,d);t&&f&&(g+="Passive"),n[g]=n[g]||[],n[g].push(i)},Bne=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Une(n){const e={},t={},r=new Set;for(let s in n)Bne.test(s)?(r.add(RegExp.lastMatch),t[s]=n[s]):e[s]=n[s];return[t,e,r]}function ld(n,e,t,r,s,i){if(!n.has(t)||!NE.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 Hne(n,e){const[t,r,s]=Une(n),i={};return ld(s,t,"onDrag","drag",i,e),ld(s,t,"onWheel","wheel",i,e),ld(s,t,"onScroll","scroll",i,e),ld(s,t,"onPinch","pinch",i,e),ld(s,t,"onMove","move",i,e),ld(s,t,"onHover","hover",i,e),{handlers:i,config:e,nativeHandlers:r}}function Kne(n,e={},t,r){const s=ot.useMemo(()=>new zne(n),[]);if(s.applyHandlers(n,r),s.applyConfig(e,t),ot.useEffect(s.effect.bind(s)),ot.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Wne(n){return n.forEach(Mne),function(t,r){const{handlers:s,nativeHandlers:i,config:o}=Hne(t,r||{});return Kne(s,o,void 0,i)}}const Ij=10,Vne=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function Y4(n){let{deltaY:e,deltaX:t}=n,r=0;return n.ctrlKey||n.altKey||n.metaKey?r=(Math.abs(e)>Ij?Ij*Math.sign(e):e)/100:n.shiftKey&&!Vne&&(t=e,e=0),{x:-t,y:-e,z:-r}}const qne=Wne([One,Ane]);let cd;const Gne=n=>cd===void 0?(cd=n,!1):n-cd>120&&n-cd<160?(cd=n,!0):(cd=n,!1);function Yne(n){const e=Q(),t=P.useMemo(()=>{let r="not sure";const s=({event:y})=>{if(!e.getInstanceState().isFocused||(r="not sure",Gne(Date.now())))return;const v=e.getEditingShapeId();if(v){const C=e.getShape(v);if(C&&e.getShapeUtil(C).canScroll(C)){const _=e.getShapePageBounds(v);if(_!=null&&_.containsPoint(e.inputs.currentPagePoint))return}}et(y),Zt(y);const x=Y4(y);if(x.x===0&&x.y===0)return;const b={type:"wheel",name:"wheel",delta:x,point:new k(y.clientX,y.clientY),shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:Pr(y)};e.dispatch(b)};let i=1,o=1,a=0;const l=new k,c=new k,d=y=>{const v=n.current;r="not sure";const{event:x,origin:b,da:C}=y;x instanceof WheelEvent||(x.target===v||v!=null&&v.contains(x.target))&&(c.x=b[0],c.y=b[1],l.x=b[0],l.y=b[1],i=C[0],o=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:b[0],y:b[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:x.shiftKey,altKey:x.altKey,ctrlKey:x.metaKey||x.ctrlKey,metaKey:x.metaKey,accelKey:Pr(x)}))},f=y=>{if(y&&(r="zooming"),r==="zooming")return;const v=Math.abs(a-i),x=k.Dist(l,c);switch(r){case"not sure":{v>24?r="zooming":x>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:d,onPinchEnd:y=>{const v=n.current,{event:x,origin:b,offset:C}=y;if(x instanceof WheelEvent||!(x.target===v||v!=null&&v.contains(x.target)))return;const E=C[0]**e.getCameraOptions().zoomSpeed;r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:b[0],y:b[1],z:E},delta:{x:b[0],y:b[1]},shiftKey:x.shiftKey,altKey:x.altKey,ctrlKey:x.metaKey||x.ctrlKey,metaKey:x.metaKey,accelKey:Pr(x)})})},onPinch:y=>{const v=n.current,{event:x,origin:b,offset:C,da:E}=y;if(x instanceof WheelEvent||!(x.target===v||v!=null&&v.contains(x.target)))return;const _=y.type==="gesturechange"||y.type==="gestureend";a=E[0];const M=b[0]-c.x,A=b[1]-c.y;switch(c.x=b[0],c.y=b[1],f(_),r){case"zooming":{const O=C[0]**e.getCameraOptions().zoomSpeed;e.dispatch({type:"pinch",name:"pinch",point:{x:b[0],y:b[1],z:O},delta:{x:M,y:A},shiftKey:x.shiftKey,altKey:x.altKey,ctrlKey:x.metaKey||x.ctrlKey,metaKey:x.metaKey,accelKey:Pr(x)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:b[0],y:b[1],z:o},delta:{x:M,y:A},shiftKey:x.shiftKey,altKey:x.altKey,ctrlKey:x.metaKey||x.ctrlKey,metaKey:x.metaKey,accelKey:Pr(x)});break}}}}},[e,n]);qne(t,{target:n,eventOptions:{passive:!1},pinch:{from:()=>{const{zoomSpeed:r}=e.getCameraOptions();return[e.getZoomLevel()**(1/r),0]},scaleBounds:()=>{const r=e.getBaseZoom(),{zoomSteps:s,zoomSpeed:i}=e.getCameraOptions(),o=s[0]*r;return{max:(s[s.length-1]*r)**(1/i),min:o**(1/i)}}}})}function uC(n,e,t){const r=n.getShape(e),s=n.getShapeHandles(r);return{shape:r,handle:s.find(i=>i.id===t)}}function Xne(n,e){const t=Q();return P.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=SS(l.currentTarget);Lp(c,l);const{shape:d,handle:f}=uC(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:d,name:"pointer_down",...Hs(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}=uC(t,n,e);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:c,name:"pointer_move",...Hs(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=SS(l.currentTarget);Fp(c,l);const{shape:d,handle:f}=uC(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:d,name:"pointer_up",...Hs(l)})}}},[t,n,e])}function Zne(n){const e=Q();P.useLayoutEffect(()=>{const t=$L(()=>{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=Jne(i),o.addEventListener("scroll",t)),()=>{clearInterval(r),window.removeEventListener("resize",t),s.disconnect(),o==null||o.removeEventListener("scroll",t),t.cancel()}},[e,n])}/*!
187
+ * Author: excalidraw
188
+ * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
189
+ * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
190
+ */const Jne=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){R(this,"x",0);R(this,"y",0);R(this,"w",0);R(this,"h",0);this.x=e,this.y=t,this.w=r,this.h=s}get point(){return new k(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 k(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 k(this.minX,this.minY),new k(this.maxX,this.minY),new k(this.maxX,this.maxY),new k(this.minX,this.maxY)]}get cornersAndCenter(){return[new k(this.minX,this.minY),new k(this.maxX,this.minY),new k(this.maxX,this.maxY),new k(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 k(this.w,this.h)}toFixed(){return this.x=dm(this.x),this.y=dm(this.y),this.w=dm(this.w),this.h=dm(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 k(this.minX,this.minY);case"top_right":return new k(this.maxX,this.minY);case"bottom_left":return new k(this.minX,this.maxY);case"bottom_right":return new k(this.maxX,this.maxY);case"top":return new k(this.midX,this.minY);case"right":return new k(this.maxX,this.midY);case"bottom":return new k(this.midX,this.maxY);case"left":return new k(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 g=(d-l)/(o-s),m=(f-c)/(a-i),y=g<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:g,maxY:m}=e;switch(t){case"left":case"top_left":case"bottom_left":{d+=r;break}case"right":case"top_right":case"bottom_right":{g+=r;break}}switch(t){case"top":case"top_left":case"top_right":{f+=s;break}case"bottom":case"bottom_left":case"bottom_right":{m+=s;break}}const y=(g-d)/(l-o),v=(m-f)/(c-a),x=y<0,b=v<0;if(i){const E=(l-o)/(c-a),_=Math.abs(g-d),M=Math.abs(m-f),A=_*(v<0?1:-1)*(1/E),O=M*(y<0?1:-1)*E,D=E<_/M;switch(t){case"top_left":{D?f=m+A:d=g+O;break}case"top_right":{D?f=m+A:g=d-O;break}case"bottom_right":{D?m=f-A:g=d-O;break}case"bottom_left":{D?m=f-A:d=g+O;break}case"bottom":case"top":{const B=(d+g)/2,U=M*E;d=B-U/2,g=B+U/2;break}case"left":case"right":{const B=(f+m)/2,U=_/E;f=B-U/2,m=B+U/2;break}}}if(x){const E=g;g=d,d=E}if(b){const E=m;m=f,f=E}const C=new ye(d,f,Math.abs(g-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 Qne(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 ere(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 tre(n){return n==="top_left"||n==="top_right"||n==="bottom_right"||n==="bottom_left"}class ve{constructor(e,t,r,s,i,o){R(this,"a",1);R(this,"b",0);R(this,"c",0);R(this,"d",1);R(this,"e",0);R(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 k(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=Kt+Math.acos(e.b/r)*(e.d>0?-1:1)}else t=0;return _P(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=Kt+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:_P(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(${te(e.a)}, ${te(e.b)}, ${te(e.c)}, ${te(e.d)}, ${te(e.e)}, ${te(e.f)})`}static applyToPoint(e,t){return new k(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 k(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 nc{constructor(e){R(this,"isFilled",!1);R(this,"isClosed",!0);R(this,"isLabel",!1);R(this,"debugColor");R(this,"ignore");R(this,"_vertices");R(this,"_bounds");R(this,"_area");R(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)&&Ws(e,this.vertices)?!0:k.Dist2(e,this.nearestPoint(e))<=t*t}distanceToPoint(e,t=!1){return e.dist(this.nearestPoint(e))*(this.isClosed&&(this.isFilled||t)&&Ws(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=k.NearestPointOnLineSegment(e,t,a,!0),o=k.Dist2(a,l),o<i&&(i=o,s=l);if(!s)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Ws(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=k.NearestPointOnLineSegment(e,t,a,!0),o=k.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+=k.Dist2(r,t),r=t;return Math.sqrt(s)}}class Ii extends nc{constructor(t){super({...t,isClosed:!0,isFilled:!1});R(this,"children",[]);R(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=k.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),g=o,m=o.clone().lrp(c,4/d);t+=`M${f.x},${f.y} L${g.x},${g.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 nre(n=!0){const[e,t]=P.useState(0),r=Q();P.useEffect(()=>{if(!n)return;const s=()=>t(i=>i+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const rre=Gn(function({showStroke:e=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const s=Q();nre(r);const i=s.getZoomLevel(),o=s.getRenderingShapes(),{inputs:{currentPagePoint:a}}=s;return p.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),g=s.getPointInShapeSpace(c,a),m=d.nearestPoint(g),y=d.distanceToPoint(g,!0),v=Math.abs(y)*i,x=y<0,{vertices:b}=d;return p.jsxs("g",{transform:f.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&p.jsx("g",{stroke:d.debugColor??"red",opacity:"1",strokeWidth:2/i,fill:"none",children:p.jsx(X4,{geometry:d})}),t&&b.map((C,E)=>p.jsx("circle",{cx:C.x,cy:C.y,r:2/i,fill:`hsl(${Fd(E,[0,b.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/i},`v${E}`)),r&&v<150&&p.jsx("line",{x1:m.x,y1:m.y,x2:g.x,y2:g.y,opacity:1-v/150,stroke:x?"goldenrod":"dodgerblue",strokeWidth:2/i})]},l.id+"_outline")})})});function X4({geometry:n}){return n instanceof Ii?p.jsx(p.Fragment,{children:[...n.children,...n.ignoredChildren].map((e,t)=>p.jsx(X4,{geometry:e},t))}):p.jsx("path",{d:n.toSimpleSvgPath()})}function Z4(n){return hV(n)}function J4(){const n=Q(),e=bG("userIds",()=>Z4(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 q0(n){const e=Q();return ie(`latestPresence:${n}`,()=>e.getCollaborators().find(r=>r.userId===n),[e,n])??null}const sre=Gn(function(){return J4().map(t=>p.jsx(ire,{collaboratorId:t},t))}),ire=Gn(function({collaboratorId:e}){const t=Q(),r=q0(e),s=are(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 p.jsx(ore,{latestPresence:r})}),ore=Gn(function({latestPresence:e}){const t=Q(),{CollaboratorBrush:r,CollaboratorScribble:s,CollaboratorCursor:i,CollaboratorHint:o,CollaboratorShapeIndicator:a}=Jt(),l=t.getZoomLevel(),c=t.getViewportPageBounds(),{userId:d,chatMessage:f,brush:g,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 p.jsxs(p.Fragment,{children:[g&&r?p.jsx(r,{className:"tl-collaborator__brush",userId:d,brush:g,color:b,opacity:.1},d+"_brush"):null,C&&i?p.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?p.jsx(o,{className:"tl-collaborator__cursor-hint",userId:d,point:x,color:b,zoom:l,viewport:c},d+"_cursor_hint"):null,s&&m.length?p.jsx(p.Fragment,{children:m.map(E=>p.jsx(s,{className:"tl-collaborator__scribble",userId:d,scribble:E,color:b,zoom:l,opacity:E.color==="laser"?.5:.1},d+"_scribble_"+E.id))}):null,a&&y.filter(E=>!t.isShapeHidden(E)).map(E=>p.jsx(a,{className:"tl-collaborator__shape-indicator",userId:d,shapeId:E,color:b,opacity:.5},d+"_"+E))]})});function Ej(n,e){return e>n.options.collaboratorInactiveTimeoutMs?"inactive":e>n.options.collaboratorIdleTimeoutMs?"idle":"active"}function are(n,e){const t=P.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,s]=P.useState(()=>Ej(n,Date.now()-t.current));return P.useEffect(()=>{const i=n.timers.setInterval(()=>{s(Ej(n,Date.now()-t.current))},n.options.collaboratorCheckIntervalMs);return()=>clearInterval(i)},[n]),e&&(t.current=e.lastActivityTimestamp??1/0),r}function lre(){const n=Q(),e=ie("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),[t,r]=P.useState(!1),s=e||t,i=jE(),o=P.useRef({isDown:!1,isDragging:!1,start:new k}),a=P.useCallback(d=>{d.button===0&&(r(!0),o.current={isDown:!0,isDragging:!1,start:new k(d.clientX,d.clientY)}),n.menus.clearOpenMenus()},[n]),l=P.useCallback(d=>{var f,g,m;if(o.current.isDown){if(o.current.isDragging){(f=i.onPointerMove)==null||f.call(i,d);return}if(k.Dist2(o.current.start,new k(d.clientX,d.clientY))>n.options.dragDistanceSquared){o.current={...o.current,isDown:!0,isDragging:!0};const{x:y,y:v}=o.current.start;(g=i.onPointerDown)==null||g.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 k(d.clientX,d.clientY)}},[i]);return s&&p.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...i,onPointerDown:a,onPointerMove:l,onPointerUp:c})}const Q4=P.memo(function({id:e,shape:t,util:r,index:s,backgroundIndex:i,opacity:o}){const a=Q(),{ShapeErrorFallback:l}=Jt(),c=P.useRef(null),d=P.useRef(null);P.useEffect(()=>Yi("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});_a("set shape stuff",()=>{const y=a.getShape(e);if(!y)return;const v=f.current,x=a.getShapeClipPath(e)??"none";x!==v.clipPath&&(Sr(c.current,"clip-path",x),Sr(d.current,"clip-path",x),v.clipPath=x);const b=a.getShapePageTransform(e),C=ve.toCssString(b),E=a.getShapeGeometry(y).bounds;C!==v.transform&&(Sr(c.current,"transform",C),Sr(d.current,"transform",C),v.transform=C);const _=Math.max(E.width,1),M=Math.max(E.height,1);(_!==v.width||M!==v.height)&&(Sr(c.current,"width",_+"px"),Sr(c.current,"height",M+"px"),Sr(d.current,"width",_+"px"),Sr(d.current,"height",M+"px"),v.width=_,v.height=M)},[a]),_a("set opacity and z-index",()=>{const y=c.current,v=d.current;Sr(y,"opacity",o),Sr(v,"opacity",o),Sr(y,"z-index",s),Sr(v,"z-index",i)},[o,s,i]),_a("set display",()=>{if(!a.getShape(e))return;const x=a.getCulledShapes().has(e);x!==f.current.isCulled&&(Sr(c.current,"display",x?"none":"block"),Sr(d.current,"display",x?"none":"block"),f.current.isCulled=x)},[a]);const g=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 p.jsxs(p.Fragment,{children:[r.backgroundComponent&&p.jsx("div",{ref:d,className:"tl-shape tl-shape-background","data-shape-type":t.type,"data-shape-id":t.id,draggable:!1,children:p.jsx(hp,{fallback:l,onError:g,children:p.jsx(tz,{shape:t,util:r})})}),p.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:p.jsx(hp,{fallback:l,onError:g,children:p.jsx(ez,{shape:t,util:r})})})]})}),ez=P.memo(function({shape:e,util:t}){return w0("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),tz=P.memo(function({shape:e,util:t}){return w0("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 cre({className:n}){const e=Q(),{Background:t,SvgDefs:r,ShapeIndicators:s}=Jt(),i=P.useRef(null),o=P.useRef(null),a=P.useRef(null),l=Mn();Zne(i),Kte(),Hte(),Yne(i),Vte(i);const c=P.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});_a("position layers",function(){const{x:C,y:E,z:_}=e.getCamera();if(c.current.allowTextOutline&&kt.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&_<e.options.textShadowLod!==c.current.lodDisableTextOutline){const O=_<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",O?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=O}const M=_>=1?Fd(_,[1,8],[.125,.5],!0):Fd(_,[.1,1],[-2,.125],!0),A=`scale(${te(_)}) translate(${te(C+M)}px,${te(E+M)}px)`;Sr(o.current,"transform",A),Sr(a.current,"transform",A)},[e,l]);const d=jE(),f=ie("shapeSvgDefs",()=>{const b=new Map;for(const C of mn(e.shapeUtils)){if(!C)return;const E=C.getCanvasSvgDefs();for(const{key:_,component:M}of E)b.has(_)||b.set(_,p.jsx(M,{},_))}return[...b.values()]},[e]),g=ie("debug_shapes",()=>bn.hideShapes.get(),[bn]),m=ie("debug_svg",()=>bn.debugSvg.get(),[bn]),y=ie("debug_geometry",()=>bn.debugGeometry.get(),[bn]),v=ie("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),x=ie("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return p.jsxs(p.Fragment,{children:[p.jsxs("div",{ref:i,draggable:!1,"data-iseditinganything":v,"data-isselectinganything":x,className:ze("tl-canvas",n),"data-testid":"canvas",...d,children:[p.jsx("svg",{className:"tl-svg-context",children:p.jsxs("defs",{children:[f,p.jsx(Cre,{}),p.jsx(Pre,{}),r&&p.jsx(r,{})]})}),t&&p.jsx("div",{className:"tl-background__wrapper",children:p.jsx(t,{})}),p.jsx(dre,{}),p.jsxs("div",{ref:o,className:"tl-html-layer tl-shapes",draggable:!1,children:[p.jsx(_re,{}),p.jsx(Ere,{}),g?null:m?p.jsx(vre,{}):p.jsx(wre,{})]}),p.jsx("div",{className:"tl-overlays",children:p.jsxs("div",{ref:a,className:"tl-html-layer",children:[y?p.jsx(rre,{}):null,p.jsx(fre,{}),p.jsx(hre,{}),p.jsx(pre,{}),s&&p.jsx(s,{}),p.jsx(bre,{}),p.jsx(gre,{}),p.jsx(Ire,{}),p.jsx(mre,{}),p.jsx(sre,{})]})}),p.jsx(Tre,{})]}),p.jsx(lre,{}),p.jsx(ure,{})]})}function ure(){const{InFrontOfTheCanvas:n}=Jt();return n?p.jsx(n,{}):null}function dre(){const n=Q(),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}=Jt();return o&&i?p.jsx(o,{x:t,y:r,z:s,size:e}):null}function hre(){const n=Q(),e=ie("scribbles",()=>n.getInstanceState().scribbles,[n]),t=ie("zoomLevel",()=>n.getZoomLevel(),[n]),{Scribble:r}=Jt();return r&&e.length?e.map(s=>p.jsx(r,{className:"tl-user-scribble",scribble:s,zoom:t},s.id)):null}function fre(){const n=Q(),e=ie("brush",()=>n.getInstanceState().brush,[n]),{Brush:t}=Jt();return t&&e?p.jsx(t,{className:"tl-user-brush",brush:e}):null}function pre(){const n=Q(),e=ie("zoomBrush",()=>n.getInstanceState().zoomBrush,[n]),{ZoomBrush:t}=Jt();return t&&e?p.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function gre(){const n=Q(),e=ie("snapLines",()=>n.snaps.getIndicators(),[n]),t=ie("zoomLevel",()=>n.getZoomLevel(),[n]),{SnapIndicator:r}=Jt();return r&&e.length>0?e.map(s=>p.jsx(r,{className:"tl-user-snapline",line:s,zoom:t},s.id)):null}function mre(){const n=Q(),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?p.jsx(yre,{shapeId:e}):null}function yre({shapeId:n}){const e=Q(),{Handles:t}=Jt(),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"&&k.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:p.jsx(t,{children:p.jsx("g",{transform:ve.toCssString(i),children:o.map(l=>p.jsx(Sre,{shapeId:n,handle:l,zoom:r,isCoarse:s},l.id))})})}function Sre({shapeId:n,handle:e,zoom:t,isCoarse:r}){const s=Xne(n,e.id),{Handle:i}=Jt();return i?p.jsx("g",{"aria-label":"handle",transform:`translate(${e.x}, ${e.y})`,...s,children:p.jsx(i,{shapeId:n,handle:e,zoom:t,isCoarse:r})}):null}function vre(){const n=Q();return ie("rendering shapes",()=>n.getRenderingShapes(),[n]).map(t=>p.jsxs(P.Fragment,{children:[p.jsx(Q4,{...t}),p.jsx(kre,{id:t.id,mode:"iframe"})]},t.id+"_fragment"))}function xre(){const n=Q(),e=P.useRef(new Set);return _a("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 wre(){const n=Q(),e=ie("rendering shapes",()=>n.getRenderingShapes(),[n]);return p.jsxs(p.Fragment,{children:[e.map(t=>p.jsx(Q4,{...t},t.id+"_shape")),kt.isSafari&&p.jsx(xre,{})]})}function bre(){const n=Q(),{ShapeIndicator:e}=Jt(),t=ie("hinting shape ids",()=>fI(n.getHintingShapeIds()),[n]);return!t.length||!e?null:t.map(r=>p.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function Cre(){return p.jsxs("g",{id:Zi("cursor"),children:[p.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[p.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),p.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),p.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[p.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),p.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),p.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[p.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),p.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function Pre(){const n=Zi("cursor_hint");return p.jsx("path",{id:n,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function kre({id:n,mode:e}){const t=Q(),[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=Yi("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 g=await t.getSvgString([n],{padding:d});if(o!==l||!g)return;const m=`data:image/svg+xml;utf8,${encodeURIComponent(g.svg)}`;s({src:m,bounds:f})});return()=>{o=null,a()}},[t,n,i]),!i||!r?null:e==="iframe"?p.jsx("iframe",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,border:"none",transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}}):p.jsx("img",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function Ire(){const n=Q(),e=ie("selection rotation",()=>n.getSelectionRotation(),[n]),t=ie("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionForeground:r}=Jt();return!t||!r?null:p.jsx(r,{bounds:t,rotation:e})}function Ere(){const n=Q(),e=ie("selection rotation",()=>n.getSelectionRotation(),[n]),t=ie("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionBackground:r}=Jt();return!t||!r?null:p.jsx(r,{bounds:t,rotation:e})}function _re(){const{OnTheCanvas:n}=Jt();return n?p.jsx(n,{}):null}function Tre(){const n=Q(),e=ie("camera state",()=>n.getCameraState(),[n]);return p.jsx("div",{className:ze("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function Mre({className:n,zoom:e,point:t,color:r,viewport:s,opacity:i=1}){const o=P.useRef(null);ch(o,Rn(t.x,s.minX+5/e,s.maxX-5/e),Rn(t.y,s.minY+5/e,s.maxY-5/e),1/e,k.Angle(s.center,t));const a=Zi("cursor_hint");return p.jsxs("svg",{ref:o,className:ze("tl-overlays__item",n),children:[p.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--color-background)"}),p.jsx("use",{href:`#${a}`,color:r,opacity:i})]})}const _j=P.memo(function({className:e,zoom:t,point:r,color:s,name:i,chatMessage:o}){const a=P.useRef(null);ch(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t);const l=Zi("cursor");return r?p.jsxs("div",{ref:a,className:ze("tl-overlays__item",e),children:[p.jsx("svg",{className:"tl-cursor",children:p.jsx("use",{href:`#${l}`,color:s})}),o?p.jsxs(p.Fragment,{children:[i&&p.jsx("div",{className:"tl-nametag-title",style:{color:s},children:i}),p.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:s},children:o})]}):i&&p.jsx("div",{className:"tl-nametag",style:{backgroundColor:s},children:i})]}):null});function Are({x:n,y:e,z:t,size:r}){const s=Su("grid"),i=Q(),{gridSteps:o}=i.options;return p.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("defs",{children:o.map(({min:a,mid:l,step:c},d)=>{const f=c*r*t,g=.5+n*t,m=.5+e*t,y=g>0?g%f:f+g%f,v=m>0?m%f:f+m%f,x=t<l?Fd(t,[a,l],[0,1]):1;return p.jsx("pattern",{id:AE(s,`${c}`),width:f,height:f,patternUnits:"userSpaceOnUse",children:p.jsx("circle",{className:"tl-grid-dot",cx:y,cy:v,r:1,opacity:x})},d)})}),o.map(({step:a},l)=>p.jsx("rect",{width:"100%",height:"100%",fill:`url(#${s}_${a})`},l))]})}function Ore({handle:n,isCoarse:e,className:t,zoom:r}){const s=Q(),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=Nte.indexOf(n.id);return p.jsxs("g",{className:ze(`tl-handle tl-handle__${n.type}`,t),children:[p.jsx("circle",{className:"tl-handle__bg",r:i}),p.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 p.jsxs("g",{className:ze(`tl-handle tl-handle__${n.type}`,t),children:[p.jsx("circle",{className:"tl-handle__bg",r:i}),p.jsx("circle",{className:"tl-handle__fg",r:o})]})}const Rre=({children:n})=>p.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}),Dre=()=>{const{Spinner:n}=Jt();return p.jsx(Aae,{children:n?p.jsx(n,{}):null})};function LE(n,e=!0){const t=n.length;if(t<2)return"";let r=n[0],s=n[1];if(t===2)return`M${Pt(r)}L${Pt(s)}`;let i="";for(let o=2,a=t-1;o<a;o++)r=n[o],s=n[o+1],i+=Ss(r,s);return e?`M${Ss(n[0],n[1])}Q${Pt(n[1])}${Ss(n[1],n[2])}T${i}${Ss(n[t-1],n[0])}${Ss(n[0],n[1])}Z`:`M${Pt(n[0])}Q${Pt(n[1])}${Ss(n[1],n[2])}${n.length>3?"T":""}${i}L${Pt(n[t-1])}`}function Tj({scribble:n,zoom:e,color:t,opacity:r,className:s}){return n.points.length?p.jsx("svg",{className:s&&ze("tl-overlays__item",s),children:p.jsx("path",{className:"tl-scribble",d:LE(n.points,!1),stroke:t??`var(--color-${n.color})`,fill:"none",strokeWidth:8/e,opacity:r??n.opacity})}):null}function nz({bounds:n,rotation:e}){const t=P.useRef(null);return ch(t,n.x,n.y,1,e),P.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=te(Math.max(1,n.width))+"px",r.style.height=te(Math.max(1,n.height))+"px")},[n.width,n.height]),p.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function jre({bounds:n,rotation:e}){const t=Q(),r=P.useRef(null),s=ie("only selected shape",()=>t.getOnlySelectedShape(),[t]),i=s?t.getShapeUtil(s).expandSelectionOutlinePx(s):0;return ch(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(),p.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:p.jsx("rect",{className:ze("tl-selection__fg__outline"),width:te(n.width),height:te(n.height)})})}const Nre=()=>p.jsx("div",{className:"tl-shape-error-boundary"}),Lre=P.memo(({shape:n,util:e})=>w0("Indicator: "+n.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(n.id)))),Fre=P.memo(({editor:n,id:e})=>{const t=ie("shape for indicator",()=>n.store.get(e),[n,e]),{ShapeIndicatorErrorFallback:r}=Jt();return!t||t.isLocked?null:p.jsx(hp,{fallback:r,onError:s=>n.annotateError(s,{origin:"react.shapeIndicator",willCrashApp:!1}),children:p.jsx(Lre,{shape:t,util:n.getShapeUtil(t)},t.id)})}),Mj=P.memo(function({shapeId:e,className:t,color:r,hidden:s,opacity:i}){const o=Q(),a=P.useRef(null);return _a("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]),p.jsx("svg",{ref:a,className:ze("tl-overlays__item",t),children:p.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:i,children:p.jsx(Fre,{editor:o,id:e})})})}),zre=()=>p.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),rz=P.memo(function({hideAll:e,showAll:t}){const r=Q();if(e&&t)throw Error("You cannot set both hideAll and showAll props to true, cmon now");const s=P.useRef(new Set),i=ie("should display selected ids",()=>{const l=s.current,c=new Set,d=r.getInstanceState(),f=d.isChangingStyle,g=r.isInAny("select.idle","select.editing_shape"),m=r.isInAny("select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","select.pointing_handle");if(f||!(g||m))return s.current=c,c;for(const y of r.getSelectedShapeIds())c.add(y);if(g&&d.isHoveringCanvas&&!d.isCoarsePointer){const y=r.getHoveredShapeId();y&&c.add(y)}if(l.size!==c.size)return s.current=c,c;for(const y of c)if(!l.has(y))return s.current=c,c;return l},[r]),o=ie("rendering shapes",()=>r.getRenderingShapes(),[r]),{ShapeIndicator:a}=Jt();return a?o.map(({id:l})=>p.jsx(a,{shapeId:l,hidden:!t&&(e||!i.has(l))},l+"_indicator")):null});function $re({points:n,zoom:e}){const t=2.5/e,r=n.reduce((g,m)=>Math.min(g,m.x),1/0),s=n.reduce((g,m)=>Math.max(g,m.x),-1/0),i=n.reduce((g,m)=>Math.min(g,m.y),1/0),o=n.reduce((g,m)=>Math.max(g,m.y),-1/0),a=n.some(g=>g.x===r&&g.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),p.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[p.jsx("line",{x1:l,y1:c,x2:d,y2:f}),n.map((g,m)=>p.jsx("g",{transform:`translate(${g.x},${g.y})`,children:p.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},m))]})}function Bre({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=Ui(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=Ui(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 p.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:n.map(({startEdge:l,endEdge:c},d)=>p.jsx(P.Fragment,{children:o?p.jsxs(p.Fragment,{children:[p.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),p.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),p.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),p.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):p.jsxs(p.Fragment,{children:[p.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),p.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),p.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),p.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 Ure({className:n,line:e,zoom:t}){return p.jsx("svg",{className:ze("tl-overlays__item",n),children:e.type==="points"?p.jsx($re,{...e,zoom:t}):e.type==="gaps"?p.jsx(Bre,{...e,zoom:t}):null})}function Hre(){return p.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:p.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[p.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),p.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:p.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const Kre=()=>null;function sz(n,e){const t=P.useRef(n);return e(n,t.current)?t.current:(t.current=n,n)}const Wre=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:zy(n,e));function _l(n){return sz(n,Wre)}const Vre=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:GL(n,e));function uh(n){return sz(n,Vre)}const iz=P.createContext(null);function qre({overrides:n={},children:e}){const t=uh(n),r=P.useMemo(()=>({Background:jte,SvgDefs:Kre,Brush:oC,ZoomBrush:oC,CollaboratorBrush:oC,Cursor:_j,CollaboratorCursor:_j,CollaboratorHint:Mre,CollaboratorShapeIndicator:Mj,Grid:Are,Scribble:Tj,SnapIndicator:Ure,Handles:Rre,Handle:Ore,CollaboratorScribble:Tj,ErrorFallback:az,ShapeErrorFallback:Nre,ShapeIndicatorErrorFallback:zre,Spinner:Hre,SelectionBackground:nz,SelectionForeground:jre,ShapeIndicators:rz,ShapeIndicator:Mj,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:cre,LoadingScreen:Dre,...t}),[t]);return p.jsx(iz.Provider,{value:r,children:e})}function Jt(){const n=P.useContext(iz);if(!n)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return n}const G0={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 oz(){G0.hardReset()}function Gre(){G0.refreshPage()}const Yre="https://github.com/tldraw/tldraw/issues/new",az=({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=Jt().Canvas??null}catch{}const d=n instanceof Error?n.message:String(n),f=n instanceof Error?n.stack:null,g=ie("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[m,y]=P.useState(null);P.useLayoutEffect(()=>{var M;g!==null&&y(g);let E=(M=t.current)==null?void 0:M.parentElement,_=!1;for(;E;){if(E.classList.contains("tl-theme__dark")||E.classList.contains("tl-theme__light")){_=!0;break}E=E.parentElement}if(_){y(null);return}typeof window<"u"&&"matchMedia"in window&&y(window.matchMedia("(prefers-color-scheme: dark)").matches)},[g]),P.useEffect(()=>{if(i){const E=e==null?void 0:e.timers.setTimeout(()=>{o(!1)},2e3);return()=>clearTimeout(E)}},[i,e]);const v=()=>{const E=document.createElement("textarea");E.value=f??d,document.body.appendChild(E),E.select(),document.execCommand("copy"),E.remove(),o(!0)},x=()=>{Gre()},b=async()=>{oz()},C=new URL(Yre);return C.searchParams.set("title",d),C.searchParams.set("labels","bug"),C.searchParams.set("body",`Hey, I ran into an error while using tldraw:
191
+
192
+ \`\`\`js
193
+ ${f??d}
194
+ \`\`\`
195
+
196
+ My browser: ${navigator.userAgent}`),p.jsxs("div",{ref:t,className:ze("tl-container tl-error-boundary",m===null?"":m?"tl-theme__dark":"tl-theme__light"),children:[p.jsx("div",{className:"tl-error-boundary__overlay"}),e&&p.jsx(ME,{onError:Zf,fallback:()=>null,children:p.jsx(RE,{editor:e,children:p.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?p.jsx(c,{}):null})})}),p.jsx("div",{className:ze("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?p.jsxs(p.Fragment,{children:[p.jsx("h2",{children:"Are you sure?"}),p.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),p.jsxs("div",{className:"tl-error-boundary__content__actions",children:[p.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),p.jsx("button",{className:"tl-error-boundary__reset",onClick:b,children:"Reset data"})]})]}):p.jsxs(p.Fragment,{children:[p.jsx("h2",{children:"Something went wrong"}),p.jsx("p",{children:"Please refresh the page to continue."}),p.jsxs("p",{children:["If you keep seeing this screen, you can create a"," ",p.jsx("a",{href:C.toString(),children:"GitHub issue"})," or ask for help on"," ",p.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&&p.jsxs(p.Fragment,{children:["Message:",p.jsx("h4",{children:p.jsx("code",{children:d})}),"Stack trace:",p.jsxs("div",{className:"tl-error-boundary__content__error",children:[p.jsx("pre",{children:p.jsx("code",{children:f??d})}),p.jsx("button",{onClick:v,children:i?"Copied!":"Copy"})]})]}),p.jsxs("div",{className:"tl-error-boundary__content__actions",children:[p.jsx("button",{onClick:()=>s(!r),children:r?"Hide details":"Show details"}),p.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[p.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),p.jsx("button",{className:"tl-error-boundary__refresh",onClick:x,children:"Refresh Page"})]})]})]})})]})},lz="TLDRAW_USER_DATA_v3",cz=pt({id:it,name:it.nullable().optional(),color:it.nullable().optional(),locale:it.nullable().optional(),animationSpeed:Xe.nullable().optional(),edgeScrollSpeed:Xe.nullable().optional(),colorScheme:K0("light","dark","system").optional(),isSnapMode:yt.nullable().optional(),isWrapMode:yt.nullable().optional(),isDynamicSizeMode:yt.nullable().optional(),isPasteAtCursorMode:yt.nullable().optional()}),ya={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},FE=Math.max(...Object.values(ya));function Xre(n){n.version<ya.AddAnimationSpeed&&(n.user.animationSpeed=1),n.version<ya.AddIsSnapMode&&(n.user.isSnapMode=!1),n.version<ya.MakeFieldsNullable,n.version<ya.AddEdgeScrollSpeed&&(n.user.edgeScrollSpeed=1),n.version<ya.AddExcalidrawSelectMode&&(n.user.isWrapMode=!1),n.version<ya.AllowSystemColorScheme&&(n.user.isDarkMode===!0?n.user.colorScheme="dark":n.user.isDarkMode===!1&&(n.user.colorScheme="light"),delete n.user.isDarkMode),n.version<ya.AddDynamicSizeMode&&(n.user.isDynamicSizeMode=!1),n.version<ya.AddPasteAtCursor&&(n.user.isPasteAtCursorMode=!1),n.version=FE}const ck=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function uz(){return ck[Math.floor(Math.random()*ck.length)]}function Zre(){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 Po=Object.freeze({name:"",locale:_te(),color:uz(),edgeScrollSpeed:1,animationSpeed:Zre()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"light"});function dC(){return{id:Tt(),color:uz()}}function dz(n){if(n===null||typeof n!="object"||!("version"in n)||!("user"in n)||typeof n.version!="number")return dC();const e=Xt(n);Xre(e);try{return cz.validate(e.user)}catch{return dC()}}function Jre(){const n=JSON.parse(vI(lz)||"null")??null;return dz(n)}const Y0=ln("globalUserData",null);function Qre(){xI(lz,JSON.stringify({version:FE,user:Y0.get()}))}function hz(n){cz.validate(n),Y0.set(n),Qre(),ese()}const Od=typeof BroadcastChannel<"u"?new BroadcastChannel("tldraw-user-sync"):null;Od==null||Od.addEventListener("message",n=>{const e=n.data;(e==null?void 0:e.type)===pz&&(e==null?void 0:e.origin)!==fz()&&Y0.set(dz(e.data))});let hC=null;function fz(){return hC===null&&(hC=Tt()),hC}const pz="tldraw-user-preferences-change";function ese(){Od==null||Od.postMessage({type:pz,origin:fz(),data:{user:gz(),version:FE}})}function gz(){let n=Y0.get();return n||(n=Jre(),hz(n)),n}const tse=le("defaultLocalStorageUserPrefs",()=>gz());function mz(n={}){return{userPreferences:n.userPreferences??tse,setUserPreferences:n.setUserPreferences??hz}}var fC={exports:{}},Aj;function nse(){return Aj||(Aj=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,g){if(typeof d!="function")throw new TypeError("The listener must be a function");var m=new s(d,f||l,g),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 g=0,m=f.length,y=new Array(m);g<m;g++)y[g]=f[g].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,g,m,y){var v=t?t+c:c;if(!this._events[v])return!1;var x=this._events[v],b=arguments.length,C,E;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,g),!0;case 5:return x.fn.call(x.context,d,f,g,m),!0;case 6:return x.fn.call(x.context,d,f,g,m,y),!0}for(E=1,C=new Array(b-1);E<b;E++)C[E-1]=arguments[E];x.fn.apply(x.context,C)}else{var _=x.length,M;for(E=0;E<_;E++)switch(x[E].once&&this.removeListener(c,x[E].fn,void 0,!0),b){case 1:x[E].fn.call(x[E].context);break;case 2:x[E].fn.call(x[E].context,d);break;case 3:x[E].fn.call(x[E].context,d,f);break;case 4:x[E].fn.call(x[E].context,d,f,g);break;default:if(!C)for(M=1,C=new Array(b-1);M<b;M++)C[M-1]=arguments[M];x[E].fn.apply(x[E].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,g){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&&(!g||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||g&&!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}(fC)),fC.exports}var rse=nse();const sse=$a(rse),Rd="TLDRAW_TAB_ID_v2",Oa=globalThis.window;function ise(){return Oa?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(Oa.navigator.platform)||kt.isDarwin&&"ontouchend"in document:!1}const xS=Oa?Oa[Rd]??a3(Rd)??"TLDRAW_INSTANCE_STATE_V1_"+Tt():"<error>";Oa&&(Oa[Rd]=xS,ise()?wI(Rd,xS):l3(Rd));Oa==null||Oa.addEventListener("beforeunload",()=>{wI(Rd,xS)});const yz={Initial:0},X0=Math.max(...Object.values(yz));function ose(n){n.version<yz.Initial,n.version=X0}const Sz=pt({version:Xe,currentPageId:up.optional(),isFocusMode:yt.optional(),exportBackground:yt.optional(),isDebugMode:yt.optional(),isToolLocked:yt.optional(),isGridMode:yt.optional(),pageStates:Bn(pt({pageId:up,camera:pt({x:Xe,y:Xe,z:Xe}).optional(),selectedShapeIds:Bn(gi).optional(),focusedGroupId:gi.nullable().optional()})).optional()});function ase(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!==X0&&(n=Xt(n),ose(n));try{return Sz.validate(n)}catch(e){return console.warn(e),null}}function zE(n){const e=n.query.ids("page");return le("sessionStateSnapshot",()=>{const t=n.get(zr);if(!t)return null;const r=[...e.get()];return{version:X0,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(Vi.createId(s)),o=n.get(Do.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:Np})}function uk(n,e,t){const r=ase(e);if(!r)return;const s=c4(n.get(zr)),i=t!=null&&t.forceOverwrite?r:s,o=t!=null&&t.forceOverwrite?s:r,a=n.schema.types.instance.create({id:zr,...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 g=Do.createId(f.pageId),m=Vi.createId(f.pageId),y=n.get(g),v=n.get(m);n.put([Do.create({id:g,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)}),Vi.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 lse(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!==zr)[0];if(!t)return null;const r={version:X0,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 Sz.validate(r),r}catch{return null}}function vz(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:Of(o.value,(a,{typeName:l})=>n.scopedTypes.document.has(l))}}else r=e;const s=c4(n.get(zr)),i=xz.get(n,zE).get();n.atomic(()=>{r.document&&n.loadStoreSnapshot(r.document),s&&n.update(zr,o=>({...o,...s})),i&&uk(n,i),r.session&&uk(n,r.session,{forceOverwrite:t==null?void 0:t.forceOverwriteSessionState})})}const xz=new qo;function cse(n){const t=xz.get(n,zE).get();if(!t)throw new Error("Session state is not ready yet");return{document:n.getStoreSnapshot(),session:t}}function wz(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 Kl({children:n,className:e="",...t}){return p.jsx("svg",{...t,className:ze("tl-svg-container",e),children:n})}function $E(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,g=a*l-o*c;if(d===0||f===0||g===0)return null;if(g!==0){const m=d/g,y=f/g;if(0<=m&&m<=1&&0<=y&&y<=1)return k.AddXY(n,m*l,m*c)}return null}function Bp(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(k.Lrp(n,e,c)),0<=d&&d<=1&&f.push(k.Lrp(n,e,d)),f.length===0?null:f}function use(n,e,t){const r=[];let s;for(let i=0,o=t.length-1;i<o;i++)s=$E(n,e,t[i],t[i+1]),s&&r.push(s);return r.length===0?null:r}function BE(n,e,t){const r=[];let s;for(let i=1,o=t.length;i<o+1;i++)s=$E(n,e,t[i-1],t[i%t.length]),s&&r.push(s);return r.length===0?null:r}function dse(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 k(n.x+s*a-i*l,n.y+i*a+s*l),new k(n.x+s*a+i*l,n.y+i*a-s*l)]}function dk(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=Bp(s,i,n,e),o&&r.push(...o);return r.length===0?null:r}function Oj(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=Bp(s,i,n,e),o&&r.push(...o);return r.length===0?null:r}function Pm(n,e,t){return(t.y-n.y)*(e.x-n.x)>(e.y-n.y)*(t.x-n.x)}function UE(n,e,t,r){return Pm(n,t,r)!==Pm(e,t,r)&&Pm(n,e,t)!==Pm(n,e,r)}function Rj(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],Ws(r,e)){const c=pC(r);t.has(c)||t.set(c,r)}for(let a=0,l=e.length;a<l;a++)if(r=e[a],Ws(r,n)){const c=pC(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=$E(r,s,i,o);if(f!==null){const g=pC(f);t.has(g)||t.set(g,f)}}}return t.size===0?null:hse([...t.values()])}function pC(n){return`${n.x},${n.y}`}function hse(n){const e=k.Average(n);return n.sort((t,r)=>k.Angle(e,t)-k.Angle(e,r))}function HE(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],UE(t,r,s,i))return!0}return!1}function fse(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],UE(t,r,s,i))return!0}return!1}class Ia extends nc{constructor(t){super({...t,isClosed:!1,isFilled:!1});R(this,"start");R(this,"end");R(this,"d");R(this,"u");R(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=k.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 k(c,d)}hitTestLineSegment(t,r,s=0){return UE(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 dh extends nc{constructor(t){super({isClosed:!1,isFilled:!1,...t});R(this,"points");R(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 Ia({start:i,end:o}))}this.isClosed&&this._segments.push(new Ia({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=k.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 wn extends dh{constructor(e){super({...e}),this.isClosed=!0}}class Uo extends wn{constructor(t){const{x:r=0,y:s=0,width:i,height:o}=t;super({...t,points:[new k(r,s),new k(r+i,s),new k(r+i,s+o),new k(r,s+o)]});R(this,"x");R(this,"y");R(this,"w");R(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 Ji{constructor(e){R(this,"options",{});this.editor=e}static configure(e){return class extends this{constructor(){super(...arguments);R(this,"options",{...this.options,...e})}}}getFontFaces(e){return bi}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){}}R(Ji,"props"),R(Ji,"migrations"),R(Ji,"type");function Hi(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,g=1,m=0,y=0;if(c)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(l){case"dashed":{g=1,d=Math.min(e*a,n/4);break}case"dotted":{g=100,d=e/g;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*g)),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*g),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 Dj({bounds:n,className:e}){const t=Q(),r=ie("zoom level",()=>t.getZoomLevel(),[t]);return p.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:n.sides.map((s,i)=>{const{strokeDasharray:o,strokeDashoffset:a}=Hi(s[0].dist(s[1]),1/r,{style:"dashed",lengthRatio:4});return p.jsx("line",{x1:s[0].x,y1:s[0].y,x2:s[1].x,y2:s[1].y,strokeDasharray:o,strokeDashoffset:a},i)})})}class ly extends Ji{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const t=this.editor.getSortedChildIdsForParent(e.id);return t.length===0?new Uo({width:1,height:1,isFilled:!1}):new Ii({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 wn({points:o,isFilled:!0}):new dh({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 p.jsx(Kl,{children:p.jsx(Dj,{className:"tl-group",bounds:o})})}indicator(e){const t=this.editor.getShapeGeometry(e).bounds;return p.jsx(Dj,{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}}}R(ly,"type","group"),R(ly,"props",w4),R(ly,"migrations",b4);const bz=[ly],pse=new Set(bz.map(n=>n.type));function Cz(n){const e=[...bz],t=new Set;for(const r of n){if(pse.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 hh=FL();const gse=$a(hh);function Pz(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 Gi(s,e);return tt(a.ok),await n(a)}catch(a){return console.error(a),null}})();return t.set(s,o),o}}const Z0=Pz(async n=>await Ur.blobToDataUrl(await n.blob())),mse=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,yse=/@font-face\s*{([^}]+)}/gi,kz=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,Sse=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function vse(n){return Array.from(n.matchAll(mse),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Iz(n,e){return Array.from(n.matchAll(yse),t=>{const r=t[1],s=Array.from(r.matchAll(kz),o=>{var l;const a=o[1]||o[2]||o[3];return{original:a,resolved:((l=Ze(a,e))==null?void 0:l.href)??null}}),i=new Set(Array.from(r.matchAll(Sse),o=>(o[1]||o[2]||o[3]).toLowerCase()));return{fontFace:r,urls:s,fontFamilies:i}})}function xse(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 Ez(n){return!(n.startsWith("-")||n.startsWith("animation")||n.startsWith("transition")||n==="cursor"||n==="pointer-events"||n==="user-select"||n==="touch-action")}function wse(n,e){return{imports:vse(n),fontFaces:Iz(n,e)}}function bse(n){return Array.from(n.matchAll(kz),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}var Cse=Object.create,_z=Object.defineProperty,Pse=Object.getOwnPropertyDescriptor,kse=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Tz=n=>{throw TypeError(n)},Mz=(n,e,t)=>e in n?_z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Ise=n=>[,,,Cse(null)],Az=["class","method","getter","setter","accessor","field","value","get","set"],Oz=n=>n!==void 0&&typeof n!="function"?Tz("Function expected"):n,Ese=(n,e,t,r,s)=>({kind:Az[n],name:e,metadata:r,addInitializer:i=>t._?Tz("Already initialized"):s.push(Oz(i||null))}),_se=(n,e)=>Mz(e,kse("metadata"),n[3]),Tse=(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},Mse=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=Az[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Pse(s,t)),b=r.length-1;b>=0;b--)l=Ese(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,Oz(o)&&(x[y]=o);return x&&_z(s,t,x),s},km=(n,e,t)=>Mz(n,typeof e!="symbol"?e+"":e,t),Rz,J0;const Dz="tldraw-svg-export";Rz=[bs];class KE{constructor(){Tse(J0,5,this),km(this,"fontFacesPromise",null),km(this,"foundFontNames",new Set),km(this,"fontFacesToEmbed",new Set),km(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){tt(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=Ase()}onFontFamilyValue(e){tt(this.fontFacesPromise,"FontEmbedder not started");const t=xse(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=Z0(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}}J0=Ise();Mse(J0,1,"onFontFamilyValue",Rz,KE);_se(J0,KE);async function Ase(){var t;const n=[],e=Array.from(document.styleSheets).filter(r=>{var s;return!((s=r.ownerNode)!=null&&s.closest(`.${Dz}`))});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(Iz(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(hk(o.href))}}else r.href&&n.push(hk(r.href))}return rt(await Promise.all(n)).flat()}const hk=Pz(async n=>{const e=wse(await n.text(),n.url),t=await Promise.all(e.imports.map(({url:r})=>hk(new URL(r,n.url).href)));return[...e.fontFaces,...rt(t).flat()]}),Fs=(n,e,{currentColor:t})=>n==="currentColor"||n===t,dt=(n,e,{parentStyles:t})=>t[e]===n,an=n=>(e,t,{getStyle:r})=>{const s=r(`border-${n}-width`),i=r(`border-${n}-style`);return s==="0px"||i==="none"},jz={"border-block-end-color":Fs,"border-block-start-color":Fs,"border-bottom-color":Fs,"border-inline-end-color":Fs,"border-inline-start-color":Fs,"border-left-color":Fs,"border-right-color":Fs,"border-top-color":Fs,"caret-color":Fs,"column-rule-color":Fs,"outline-color":Fs,"text-decoration":(n,e,{currentColor:t})=>n==="none solid currentColor"||n==="none solid "+t,"text-decoration-color":Fs,"text-emphasis-color":Fs,"border-collapse":dt,"border-spacing":dt,"caption-side":dt,cursor:dt,direction:dt,"empty-cells":dt,"font-family":dt,"font-size":dt,"font-style":dt,"font-variant":dt,"font-weight":dt,"font-size-adjust":dt,"font-stretch":dt,font:dt,"letter-spacing":dt,"line-height":dt,"list-style-image":dt,"list-style-position":dt,"list-style-type":dt,"list-style":dt,orphans:dt,"overflow-wrap":dt,quotes:dt,"stroke-linecap":dt,"stroke-linejoin":dt,"tab-size":dt,"text-align":dt,"text-align-last":dt,"text-indent":dt,"text-justify":dt,"text-shadow":dt,"text-transform":dt,visibility:dt,"white-space":dt,"white-space-collapse":dt,widows:dt,"word-break":dt,"word-spacing":dt,"word-wrap":dt,"border-top":an("top"),"border-right":an("right"),"border-bottom":an("bottom"),"border-left":an("left"),"border-block-end":an("block-end"),"border-block-start":an("block-start"),"border-inline-end":an("inline-end"),"border-inline-start":an("inline-start"),"border-top-style":an("top"),"border-right-style":an("right"),"border-bottom-style":an("bottom"),"border-left-style":an("left"),"border-block-end-style":an("block-end"),"border-block-start-style":an("block-start"),"border-inline-end-style":an("inline-end"),"border-inline-start-style":an("inline-start"),"border-top-width":an("top"),"border-right-width":an("right"),"border-bottom-width":an("bottom"),"border-left-width":an("left"),"border-block-end-width":an("block-end"),"border-block-start-width":an("block-start"),"border-inline-end-width":an("inline-end")};function Nz(n){if(n.shadowRoot)return n.shadowRoot.childNodes;if(jse(n)){const e=n.assignedNodes();if(e!=null&&e.length)return e}return n.childNodes}function*fk(n){for(const e of Nz(n))Ose(e)&&(yield e)}function Q0(n){var e;return((e=n.ownerDocument)==null?void 0:e.defaultView)??globalThis}function Ose(n){return n instanceof Q0(n).Element}function Rse(n){return n instanceof Q0(n).ShadowRoot}function Dse(n){return"getRootNode"in n&&Rse(n.getRootNode())}function jse(n){return Dse(n)&&n instanceof Q0(n).HTMLSlotElement}function Nse(n){return n.style}function WE(n,e){return Q0(n).getComputedStyle(n,e)}const Gd={};class Lse{constructor(e){R(this,"styles",new Map);R(this,"fonts",new KE);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const t=Array.from(fk(e));for(;t.length;){const r=t.pop();t.push(...fk(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:t=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const s=t?Bse(e.tagName.toLowerCase()):Gd,i=Object.assign({},Gd);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:Fse(e,{defaultStyles:s,parentStyles:i}),before:jj(e,"::before"),after:jj(e,"::after")};this.styles.set(e,o)}fetchResources(){const e=[];for(const t of this.styles.values())for(const r of mn(t))if(r)for(const[s,i]of Object.entries(r)){if(!i)continue;s==="font-family"&&this.fonts.onFontFamilyValue(i);const o=bse(i);o.length!==0&&e.push(...o.map(async({url:a,original:l})=>{const c=await Z0(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 Nz(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-${Tt()}`;t.classList.add(i),r.before&&(e+=`.${i}::before {${Nj(r.before)}}
197
+ `),r.after&&(e+=`.${i}::after {${Nj(r.after)}}
198
+ `)}const s=Nse(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(){$se()}}function Fse(n,{defaultStyles:e,parentStyles:t}){return n.computedStyleMap?Lz(n.computedStyleMap(),{defaultStyles:e,parentStyles:t}):VE(WE(n),{defaultStyles:e,parentStyles:t})}function jj(n,e){const t=WE(n,e),r=t.getPropertyValue("content");if(!(r===""||r==="none"))return VE(t,{defaultStyles:Gd,parentStyles:Gd})}function Lz(n,{defaultStyles:e,parentStyles:t}){var o;const r={},i={currentColor:((o=n.get("color"))==null?void 0:o.toString())||"",parentStyles:t,defaultStyles:e,getStyle:a=>{var l;return((l=n.get(a))==null?void 0:l.toString())??""}};for(const a of n.keys()){if(!Ez(a))continue;const l=n.get(a).toString();if(e[a]===l)continue;const c=Cn(jz,a);c&&c(l,a,i)||(r[a]=l)}return r}function VE(n,{defaultStyles:e,parentStyles:t}){const r={},i={currentColor:n.color,parentStyles:t,defaultStyles:e,getStyle:o=>n.getPropertyValue(o)};for(const o in n){if(!Ez(o))continue;const a=n.getPropertyValue(o);if(e[o]===a)continue;const l=Cn(jz,o);l&&l(a,o,i)||(r[o]=a)}return r}function Nj(n){let e="";for(const[t,r]of Object.entries(n))e+=`${t}: ${r};`;return e}let Dd;const Lj={};function zse(){if(!Dd){const n=document.createElement("iframe");n.style.display="none",document.body.appendChild(n);const e=Fr(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),Dd={iframe:n,foreignObject:r,document:e}}return Dd}function $se(){Dd&&(document.body.removeChild(Dd.iframe),Dd=void 0)}const Fj={defaultStyles:Gd,parentStyles:Gd};function Bse(n){let e=Lj[n];if(!e){const{foreignObject:t,document:r}=zse(),s=r.createElement(n);t.appendChild(s),e=s.computedStyleMap?Lz(s.computedStyleMap(),Fj):VE(WE(s),Fj),t.removeChild(s),Lj[n]=e}return e}function Use(n,e){Array.from(n.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function zj(n,e){return n.replaceWith(e),e}async function Ff(n,e){const t=document.createElement("img");e&&Use(e,t),t.setAttribute("src",n??"data:"),t.setAttribute("decoding","sync"),t.setAttribute("loading","eager");try{await t.decode()}catch{}return t}async function Hse(n){try{const e=n.toDataURL();return await Ff(e,n)}catch{return await Ff(null,n)}}async function Kse(n){try{const e=await Us.getVideoFrameAsDataUrl(n);return Ff(e,n)}catch(e){console.error("Could not get video frame",e)}if(n.poster){const e=await Z0(n.poster);return Ff(e,n)}return Ff(null,n)}async function Fz(n){if(n instanceof HTMLCanvasElement)return zj(n,await Hse(n));if(n instanceof HTMLVideoElement)return zj(n,await Kse(n));if(n instanceof HTMLImageElement){const e=n.currentSrc||n.src,t=await Z0(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(fk(n),e=>Fz(e)))}function Pa(n){const e=P.useRef();return P.useLayoutEffect(()=>{e.current=n}),P.useDebugValue(n),P.useCallback((...t)=>{const r=e.current;return tt(r,"fn does not exist"),r(...t)},[])}const qE=P.createContext(null);function Wse({context:n,editor:e,children:t}){const r=e.options.exportProvider;return p.jsx(RE,{editor:e,children:p.jsx($4,{container:e.getContainer(),children:p.jsx(qE.Provider,{value:n,children:p.jsx(r,{children:t})})})})}function Up(){return P.useContext(qE)}function Vse(){const n=P.useContext(qE),[e]=P.useState(hI);return P.useEffect(()=>(n==null||n.waitUntil(e),()=>{e.resolve()}),[e,n]),Pa(()=>{e.resolve()})}var qse=Object.create,zz=Object.defineProperty,Gse=Object.getOwnPropertyDescriptor,Yse=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),$z=n=>{throw TypeError(n)},Bz=(n,e,t)=>e in n?zz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Xse=n=>[,,,qse(null)],Uz=["class","method","getter","setter","accessor","field","value","get","set"],Hz=n=>n!==void 0&&typeof n!="function"?$z("Function expected"):n,Zse=(n,e,t,r,s)=>({kind:Uz[n],name:e,metadata:r,addInitializer:i=>t._?$z("Already initialized"):s.push(Hz(i||null))}),Jse=(n,e)=>Bz(e,Yse("metadata"),n[3]),Qse=(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},eie=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=Uz[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Gse(s,t)),b=r.length-1;b>=0;b--)l=Zse(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,Hz(o)&&(x[y]=o);return x&&zz(s,t,x),s},$j=(n,e,t)=>Bz(n,typeof e!="symbol"?e+"":e,t),Kz,ev;Kz=[bs];class GE{constructor(e){this.maxDelayTimeMs=e,Qse(ev,5,this),$j(this,"isResolved",!1),$j(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 bP(0)}async resolve(){const e=bP(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}}ev=Xse();eie(ev,1,"waitUntil",Kz,GE);Jse(ev,GE);function tie(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:E})=>l.has(E));let d=null;if(t.bounds)d=t.bounds;else for(const{id:E}of c){const _=n.getShapeMaskedPageBounds(E);_&&(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 g=d.width*r,m=d.height*r;try{(C=(b=document.body).focus)==null||C.call(b)}catch{}const y=new GE(n.options.maxExportDelayMs),v=hI();return y.waitUntil(v),{jsx:p.jsx(nie,{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:g,height:m,exportDelay:y}}function nie({editor:n,preserveAspectRatio:e,scale:t,pixelRatio:r,bbox:s,background:i,singleFrameShapeId:o,isDarkMode:a,renderingShapes:l,onMount:c,waitUntil:d}){const f=Su(),g=Ha({isDarkMode:a}),m=b0("export state",{defsById:{},shapeElements:null}),{defsById:y,shapeElements:v}=ie(m),x=Pa(E=>{m.update(_=>{if(wi(_.defsById,E.key))return _;const M=Promise.resolve(E.getElement());return d(M.then(A=>{m.update(O=>({...O,defsById:{...O.defsById,[E.key]:{pending:!1,element:A}}}))})),{..._,defsById:{..._.defsById,[E.key]:{pending:!0,element:M}}}})}),b=P.useMemo(()=>({isDarkMode:a,waitUntil:d,addExportDef:x,scale:t,pixelRatio:r,async resolveAssetUrl(E,_){const M=n.getAsset(E);return!M||M.type!=="image"&&M.type!=="video"?null:await n.resolveAssetUrl(E,{screenScale:t*(_/M.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 E={},_=l.map(async({id:A,opacity:O,index:D,backgroundIndex:B})=>{var N,L;if(A===o)return[];const U=n.getShape(A);if(n.isShapeOfType(U,"group"))return[];const G=[],z=n.getShapeUtil(U);if(z.toSvg||z.toBackgroundSvg){const[V,Z]=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(),Y=1;"scale"in U.props&&U.props.scale!==1&&(Y=U.props.scale,$=`${$} scale(${U.props.scale}, ${U.props.scale})`);const re=n.getShapeMask(U.id),K=re?ve.From(ve.Inverse(W)).applyToPoints(re):null,ne=AE(f,U.id);K&&(E[ne]={pending:!1,element:p.jsx("clipPath",{id:ne,children:p.jsx("path",{d:`M${K.map(({x:ge,y:Pe})=>`${ge/Y},${Pe/Y}`).join("L")}Z`})})}),V&&G.push({zIndex:D,element:p.jsx("g",{transform:$,opacity:O,clipPath:re?`url(#${ne})`:void 0,children:V},`fg_${U.id}`)}),Z&&G.push({zIndex:B,element:p.jsx("g",{transform:$,opacity:O,clipPath:re?`url(#${ne})`:void 0,children:Z},`bg_${U.id}`)})}else G.push({zIndex:D,element:p.jsx(Bj,{shape:U,util:z,component:ez,className:"tl-shape",bbox:s,opacity:O},`fg_${U.id}`)}),z.backgroundComponent&&G.push({zIndex:B,element:p.jsx(Bj,{shape:U,util:z,component:tz,className:"tl-shape tl-shape-background",bbox:s,opacity:O},`bg_${U.id}`)});return G}),M=(await Promise.all(_)).flat();hh.flushSync(()=>{m.update(A=>({...A,shapeElements:M.sort((O,D)=>O.zIndex-D.zIndex).map(({element:O})=>O),defsById:{...A.defsById,...E}}))})})()},[s,n,b,f,l,o,m]),P.useEffect(()=>{const E=new Set;for(const{id:_}of l)for(const M of n.fonts.getShapeFontFaces(_))E.add(M);for(const _ of E)x({key:Tt(),getElement:async()=>{const M=await n.fonts.toEmbeddedCssDeclaration(_);return p.jsx("style",{nonce:n.options.nonce,children:M})}})},[n,l,x]),P.useEffect(()=>{v!==null&&c()},[c,v]),p.jsx(Wse,{editor:n,context:b,children:p.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:s.width*t,height:s.height*t,viewBox:`${s.minX} ${s.minY} ${s.width} ${s.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:i?o?g.solid:g.background:"transparent"},"data-color-mode":a?"dark":"light",className:`tl-container tl-theme__force-sRGB ${a?"tl-theme__dark":"tl-theme__light"}`,children:[p.jsx("defs",{children:Object.entries(y).map(([E,_])=>_.pending?null:p.jsx(P.Fragment,{children:_.element},E))}),v]})})}function Bj({shape:n,util:e,className:t,component:r,bbox:s,opacity:i}){const o=Q(),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 p.jsx(ME,{fallback:()=>null,children:p.jsx("foreignObject",{x:s.minX,y:s.minY,width:s.w,height:s.h,className:"tl-shape-foreign-object tl-export-embed-styles",children:p.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:p.jsx(r,{shape:n,util:e})})})})}let rie=1;async function sie(n,e,t={}){const r=tie(n,e,t);if(!r)return;const s=n.getContainer(),i=document.createElement("div");i.className=Dz,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=zL.createRoot(i,{identifierPrefix:`export_${rie++}_`});try{await Promise.resolve(),hh.flushSync(()=>{o.render(r.jsx)}),await r.exportDelay.resolve();const a=i.firstElementChild;return tt(a instanceof SVGSVGElement,"Expected an SVG element"),await iie(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{o.unmount(),s.removeChild(i)},0)}}async function iie(n){const e=[...n.querySelectorAll("foreignObject.tl-export-embed-styles > *")];if(!e.length)return;const t=new Lse(n);try{t.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(i=>Fz(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}
199
+ ${s}`,n.prepend(i)}}finally{t.dispose()}}let gC=null;function oie(){return gC||(gC={maxWidth:mC("width"),maxHeight:mC("height"),maxArea:mC("area")}),gC}/*!
200
+ * Extracted from https://github.com/jhildenbiddle/canvas-size
201
+ * MIT License: https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE
202
+ * Copyright (c) John Hildenbiddle
203
+ */const Uj=8192,aie=4096*4096,lie={area:[16384,14188,11402,11180,10836,8192,4096],height:[8388607,65535,32767,16384,8192,4096],width:[4194303,65535,32767,16384,8192,4096]};function mC(n){const e=document.createElement("canvas");e.width=1,e.height=1;const t=e.getContext("2d");for(const r of lie[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 cie(n,e){if(n<=Uj&&e<=Uj&&n*e<=aie)return[n,e];const{maxWidth:t,maxHeight:r,maxArea:s}=oie(),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 uie(n,e){const{type:t,width:r,height:s,quality:i=1,pixelRatio:o=2}=e;let[a,l]=cie(r*o,s*o);a=Math.floor(a),l=Math.floor(l);const c=a/r,d=await Ur.blobToDataUrl(new Blob([n],{type:"image/svg+xml"})),f=await new Promise(m=>{const y=Jf();y.crossOrigin="anonymous",y.onload=async()=>{kt.isSafari&&await bP(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 g=await new Promise(m=>f.toBlob(y=>{(!y||bn.throwToBlob.get())&&m(null),m(y)},"image/"+t,i));if(!g)return null;if(t==="png"){const m=new DataView(await g.arrayBuffer());return Mo.setPhysChunk(m,c,{type:"image/"+t})}else return g}const $r={menus:ln("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()}}},wS=new JV,die={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,nonce:void 0};function Hj(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 _n(n)}}class hie{constructor(e){R(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(!Hj(s,e.get(r)))return!1;t.add(r)}for(const[r,s]of e)if(!t.has(r)&&!Hj(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 pk extends hie{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:_n(r,"type")}}}function fie(n,e,t){return Gi(n).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:t})})}const pie="https://cdn.tldraw.com";function En(){return`${pie}/${j4}`}function gie(n){switch(n.type){case"shapes":return`s${n.shapeIds.map(t=>yC(t.slice(6))).join(".")}`;case"page":return"p"+yC(Es.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+="."+yC(Es.parseId(t))),r}default:_n(n)}}function mie(n){switch(n[0]){case"s":return{type:"shapes",shapeIds:n.slice(1).split(".").filter(Boolean).map(r=>jt(decodeURIComponent(r)))};case"p":return{type:"page",pageId:Es.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?Es.createId(decodeURIComponent(o)):void 0}}default:throw Error("Invalid deep link string")}}function yC(n){return encodeURIComponent(n).replace(/\./g,"%2E")}function yie(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 Im(n,e,t,r){if(t.length===0)return[];const s=new Map;for(const o of rt(t.map(a=>n.getShape(a)))){const{parentId:a}=o;s.has(a)||s.set(a,{children:rt(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})=>Sie(o,a,i));break}case"toFront":{s.forEach(({moving:o,children:a})=>vie(o,a,i));break}case"forward":{s.forEach(({moving:o,children:a})=>xie(n,o,a,i,r));break}case"backward":{s.forEach(({moving:o,children:a})=>wie(n,o,a,i,r));break}}return i}function Sie(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=zd(s,i,n.size);t.push(...Array.from(n.values()).sort(tr).map((a,l)=>({...a,index:o[l]})))}}function vie(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=zd(s,i,n.size);t.push(...Array.from(n.values()).sort(tr).map((a,l)=>({...a,index:o[l]})))}}function Kj(n,e){const t=n.getShapeGeometry(e),r=n.getShapePageTransform(e);return!t||!r?null:r.applyToPoints(t.vertices)}function Wz(n,e){const t=Array.from(e).map(s=>{const i=Kj(n,s);return i?{shape:s,vertices:i}:null}).filter(Boolean);return s=>{const i=Kj(n,s);return i?t.some(o=>HE(o.vertices,i)):!1}}function xie(n,e,t,r,s){var l;const i=Wz(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;zd(t[c].index,(l=t[c+1])==null?void 0:l.index,c-f).forEach((g,m)=>{const y=t[f+m];e.has(y)&&r.push({...y,index:g})}),a={name:"skipping"};break}}}}function wie(n,e,t,r,s){var l;const i=Wz(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;zd((l=t[c-1])==null?void 0:l.index,t[c].index,a.selectIndex-c).forEach((f,g)=>{const m=t[c+g+1];e.has(m)&&r.push({...m,index:f})}),a={name:"skipping"};break}}}}function Vz({editor:n,ids:e}){const t=rt(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 cy({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=ys(l.parentId)?e.getShapePageTransform(l.parentId):ve.Identity(),f=k.RotWith(c,s??i,n),g=ve.applyToPoint(ve.Inverse(d),f),m=Uc(l.rotation+n);return{id:l.id,type:l.type,x:g.x,y:g.y,rotation:m}}));const a=[];o.forEach(({shape:l})=>{var g,m,y;const c=e.getShape(l.id);if(!c)return;const d=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const v=(g=d.onRotateStart)==null?void 0:g.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 bie=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(Bc(i))return s();const a=i,l=t.getDiffSince(o);if(l===Ks)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 g(m){f(m.fromId).push(m),f(m.toId).push(m)}for(const m of l){for(const y of mn(m.added))g(y);for(const[y,v]of mn(m.updated))d(y),g(v);for(const y of mn(m.removed))d(y)}return c??a})};function Cie(n,e,t){const r=n.getShapeMaskedPageBounds(e);return r===void 0?!0:!t.includes(r)}const Pie=n=>{function e(t){const r=t.getCurrentPageShapeIds(),s=t.getViewportPageBounds(),i=new Set;return r.forEach(o=>{Cie(t,o,s)&&i.add(o)}),i}return le("getCulledShapes",t=>{if(Bc(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})},kie=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(tr),o.forEach(a=>{s[a.parentId]||(s[a.parentId]=[]),s[a.parentId].push(a.id)}),s}return le("parentsToChildrenWithIndexes",(s,i)=>{if(Bc(s))return r();const o=t.getDiffSince(i);if(o===Ks)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,g=o.length;f<g;f++){d=o[f];for(const m of Object.values(d.added))Pd(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(Pd(y)&&Pd(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))Pd(m)&&(l(m.parentId),a[m.parentId].splice(a[m.parentId].indexOf(m.id),1))}for(const f of c){const g=rt(f.map(m=>n.get(m)));g.sort(tr),f.splice(0,f.length,...g.map(m=>m.id))}return a??s})},SC=(n,e,t)=>{for(;!ps(t.parentId);){const r=n.get(t.parentId);if(!r)return!1;t=r}return t.parentId===e},Iie=(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=>SC(n,i,n.get(o))))}return le("_shapeIdsInCurrentPage",(i,o)=>{if(Bc(i))return s();const a=e();if(a!==r)return s();const l=n.history.getDiffSince(o);if(l===Ks)return s();const c=new iy(i);for(const f of l){for(const g of Object.values(f.added))Pd(g)&&SC(n,a,g)&&c.add(g.id);for(const[g,m]of Object.values(f.updated))Pd(m)&&(SC(n,a,m)?c.add(m.id):c.remove(m.id));for(const g of Object.keys(f.removed))ys(g)&&c.remove(g)}const d=c.get();return d?Sf(d.value,d.diff):i})};var Eie=Object.create,qz=Object.defineProperty,_ie=Object.getOwnPropertyDescriptor,Tie=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Gz=n=>{throw TypeError(n)},Yz=(n,e,t)=>e in n?qz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Mie=n=>[,,,Eie(null)],Xz=["class","method","getter","setter","accessor","field","value","get","set"],Zz=n=>n!==void 0&&typeof n!="function"?Gz("Function expected"):n,Aie=(n,e,t,r,s)=>({kind:Xz[n],name:e,metadata:r,addInitializer:i=>t._?Gz("Already initialized"):s.push(Zz(i||null))}),Oie=(n,e)=>Yz(e,Tie("metadata"),n[3]),Rie=(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},Jz=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=Xz[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,_ie(s,t)),b=r.length-1;b>=0;b--)l=Aie(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,Zz(o)&&(x[y]=o);return x&&qz(s,t,x),s},ud=(n,e,t)=>Yz(n,typeof e!="symbol"?e+"":e,t),Qz,e$,Hp;const Die=40;e$=[bs],Qz=[bs];class tv{constructor(e){this.editor=e,Rie(Hp,5,this),ud(this,"_clickId",""),ud(this,"_clickTimeout"),ud(this,"_clickScreenPoint"),ud(this,"_previousScreenPoint"),ud(this,"_clickState","idle"),ud(this,"lastPointerInfo",{})}_getClickTimeout(e,t=Tt()){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=k.From(e.point),this._previousScreenPoint&&k.Dist2(this._previousScreenPoint,this._clickScreenPoint)>Die**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=k.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&&k.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"}}Hp=Mie();Jz(Hp,1,"_getClickTimeout",e$,tv);Jz(Hp,1,"cancelDoubleClickTimeout",Qz,tv);Oie(Hp,tv);class jie{constructor(e){R(this,"_isEdgeScrolling",!1);R(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?Un.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,g=i?t:t-a;return c<f?Math.min(1,(f-c)/a):d>g?-Math.min(1,(d-g)/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:g}=t.getCamera();t.setCamera(new k(d+l,f+c,g))}}class Nie{constructor(e,t){R(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(),document.body.addEventListener("keydown",this.handleKeyDown.bind(this)),document.body.addEventListener("mousedown",this.handleMouseDown.bind(this))}updateContainerClass(){const e=this.editor.getContainer();this.editor.getInstanceState().isFocused?e.classList.add("tl-container__focused"):e.classList.remove("tl-container__focused"),e.classList.add("tl-container__no-focus-ring")}handleKeyDown(e){const t=this.editor.getContainer();e.key==="Tab"&&t.classList.remove("tl-container__no-focus-ring")}handleMouseDown(){this.editor.getContainer().classList.add("tl-container__no-focus-ring")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var e;document.body.removeEventListener("keydown",this.handleKeyDown.bind(this)),document.body.removeEventListener("mousedown",this.handleMouseDown.bind(this)),(e=this.disposeSideEffectListener)==null||e.call(this)}}class Lie{constructor(e,t){R(this,"shapeFontFacesCache");R(this,"shapeFontLoadStateCache");R(this,"fontStates",new tk("font states"));R(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:zy}),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:zy})})}getShapeFontFaces(e){const t=typeof e=="string"?e:e.id;return this.shapeFontFacesCache.get(t)??bi}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,Ps(()=>{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&&Cs(Wj).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)})`,{...rh(Wj,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 Ur.urlToDataUrl(t),s=rt([`url("${r}")`,e.src.format?`format(${e.src.format})`:null,e.src.tech?`tech(${e.src.tech})`:null]).join(" ");return rt(["@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(`
204
+ `)}}const Wj={style:"normal",weight:"normal",stretch:"normal",unicodeRange:"U+0-10FFFF",featureSettings:"normal",ascentOverride:"normal",descentOverride:"normal",lineGapOverride:"normal"};function cf(n){return zie}class Fie{constructor(){R(this,"length",0);R(this,"head",null);R(this,"tail",this)}push(e){return new YE(e,this)}toArray(){return bi}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const zie=new Fie;class YE{constructor(e,t){R(this,"length");this.head=e,this.tail=t,this.length=t.length+1}push(e){return new YE(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 $ie{constructor(e){R(this,"store");R(this,"dispose");R(this,"state","recording");R(this,"pendingDiff",new Uie);R(this,"stacks",ln("HistoryManager.stacks",{undos:cf(),redos:cf()},{isEqual:(e,t)=>e.undos===t.undos&&e.redos===t.redos}));R(this,"annotateError");R(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??Zf,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:cf()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:_n(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=Bie[t.history]);try{if(this._isInBatch)return Ps(e),this;this._isInBatch=!0;try{Ps(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=q5(a),c=nk(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":Nf(c,[nk(f.diff)]);break;case"stop":if(!t)break e;if(f.id===t){d=!0;break e}break;default:_n(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=oS();for(;s.head;){const o=s.head;if(r=r.push(o),s=s.tail,o.type==="diff")Nf(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=oS();return Nf(s,r.reverse()),this.stacks.update(({redos:o})=>({undos:t.push({type:"diff",diff:s}),redos:o})),this}_mark(e){Ps(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:cf(),redos:cf()}),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 Bie={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class Uie{constructor(){R(this,"diff",oS());R(this,"isEmptyAtom",ln("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=oS(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){Nf(this.diff,[e]),this.isEmptyAtom.set(q5(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class Hie{constructor(e){R(this,"scribbleItems",new Map);R(this,"state","paused");this.editor=e}addScribble(e,t=Tt()){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||k.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 Kie=Object.create,t$=Object.defineProperty,Wie=Object.getOwnPropertyDescriptor,Vie=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),n$=n=>{throw TypeError(n)},r$=(n,e,t)=>e in n?t$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,qie=n=>[,,,Kie(null)],s$=["class","method","getter","setter","accessor","field","value","get","set"],i$=n=>n!==void 0&&typeof n!="function"?n$("Function expected"):n,Gie=(n,e,t,r,s)=>({kind:s$[n],name:e,metadata:r,addInitializer:i=>t._?n$("Already initialized"):s.push(i$(i||null))}),Yie=(n,e)=>r$(e,Vie("metadata"),n[3]),Xie=(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},nv=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=s$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Wie(s,t)),b=r.length-1;b>=0;b--)l=Gie(d,t,a={},n[3],v),l.static=f,l.private=g,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&&t$(s,t,x),s},Zie=(n,e,t)=>r$(n,e+"",t),o$,a$,l$,c$,vu;const Ge=n=>Math.round(n*10**8)/10**8;function Sa(n,e,t,r,s){const i=n.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&Ge(a.length)===Ge(t)&&Ui(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=Sa(n,l,t,r,Ui(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));i.push(...c)}}),i}function Jie(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=>Ge(i.startEdge[0].x)===Ge(o.startEdge[0].x)&&Ge(i.startEdge[0].y)===Ge(o.startEdge[0].y)&&Ge(i.startEdge[1].x)===Ge(o.startEdge[1].x)&&Ge(i.startEdge[1].y)===Ge(o.startEdge[1].y))&&s.gaps.some(o=>Ge(i.endEdge[0].x)===Ge(o.endEdge[0].x)&&Ge(i.endEdge[0].y)===Ge(o.endEdge[0].y)&&Ge(i.endEdge[1].x)===Ge(o.endEdge[1].x)&&Ge(i.endEdge[1].y)===Ge(o.endEdge[1].y)))){n.splice(e,1);break}}}}c$=[le],l$=[le],a$=[le],o$=[le];class fh{constructor(e){this.manager=e,Xie(vu,5,this),Zie(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:Fr(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&&nf(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)&&e.push({startNode:r,endNode:s,startEdge:[new k(r.pageBounds.maxX,r.pageBounds.minY),new k(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new k(s.pageBounds.minX,s.pageBounds.minY),new k(s.pageBounds.minX,s.pageBounds.maxY)],length:s.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Ui(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&&nf(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)&&t.push({startNode:r,endNode:s,startEdge:[new k(r.pageBounds.minX,r.pageBounds.maxY),new k(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new k(s.pageBounds.minX,s.pageBounds.minY),new k(s.pageBounds.maxX,s.pageBounds.minY)],length:s.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Ui(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:E},_)=>({id:"selection:"+_,x:C+s.x,y:E+s.y})),c=o,d=[],f=[],g=new k(i,i);this.collectPointSnaps({minOffset:g,nearestSnapsX:d,nearestSnapsY:f,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:f,minOffset:g});const m=new k(e==="x"?0:((x=d[0])==null?void 0:x.nudge)??0,e==="y"?0:((b=f[0])==null?void 0:b.nudge)??0);g.x=0,g.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:g,nearestSnapsX:d,nearestSnapsY:f,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:f,minOffset:g});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 O,D;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=ere(d)),c<0&&(d=Qne(d)),i&&(a.center=e.center);const f=d==="top"||d==="bottom",g=d==="left"||d==="right",m=Vj(d,a),y=this.getSnappablePoints(),v=[],x=[],b=new k(o,o);this.collectPointSnaps({minOffset:b,nearestSnapsX:v,nearestSnapsY:x,otherNodeSnapPoints:y,selectionSnapPoints:m});const C=new k(f?0:((O=v[0])==null?void 0:O.nudge)??0,g?0:((D=x[0])==null?void 0:D.nudge)??0);if(s&&tre(d)&&C.len()!==0){const B=v.length&&x.length?Math.abs(C.x)<Math.abs(C.y)?"x":"y":v.length?"x":"y",U=e.aspectRatio;B==="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 E=k.Add(t,C),{box:_}=ye.Resize(e,r,i?E.x*2:E.x,i?E.y*2:E.y,s);i&&(_.center=e.center);const M=Vj("any",_);v.length=0,x.length=0,b.x=0,b.y=0,this.collectPointSnaps({minOffset:b,nearestSnapsX:v,nearestSnapsY:x,otherNodeSnapPoints:y,selectionSnapPoints:M});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=k.Sub(o,a),c=Math.abs(l.x),d=Math.abs(l.y);Ge(c)<=Ge(r.x)&&(Ge(c)<Ge(r.x)&&(s.length=0),s.push({type:"points",points:{thisPoint:o,otherPoint:a},nudge:a.x-o.x}),r.x=c),Ge(d)<=Ge(r.y)&&(Ge(d)<Ge(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(!nf(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&&Ge(Math.abs(c))<=Ge(t.x)){Ge(Math.abs(c))<Ge(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"),E=C&&Ui(a.breadthIntersection[0],a.breadthIntersection[1],C.gap.breadthIntersection[0],C.gap.breadthIntersection[1]);C&&C.gap.length>a.length&&E?r[r.indexOf(C)]=b:(!C||!E)&&r.push(b)}const f=a.startNode.pageBounds.minX-a.length,g=e.maxX,m=f-g;Ge(Math.abs(m))<=Ge(t.x)&&(Ge(Math.abs(m))<Ge(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;Ge(Math.abs(x))<=Ge(t.x)&&(Ge(Math.abs(x))<Ge(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(!nf(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&&Ge(Math.abs(c))<=Ge(t.y)){Ge(Math.abs(c))<Ge(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"),E=C&&nf(C.gap.breadthIntersection[0],C.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);C&&C.gap.length>a.length&&E?s[s.indexOf(C)]=b:(!C||!E)&&s.push(b);continue}const f=a.startNode.pageBounds.minY-a.length,g=e.maxY,m=f-g;Ge(Math.abs(m))<=Ge(t.y)&&(Ge(Math.abs(m))<Ge(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;Ge(Math.abs(x))<=Ge(t.y)&&(Ge(Math.abs(x))<Ge(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=Ge(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=Ge(i.points.otherPoint.y);s[o]||(s[o]=[]),s[o].push(i.points)}}return Object.values(r).concat(Object.values(s)).map(i=>({id:Tt(),type:"points",points:fI(i.map(o=>k.From(o.otherPoint)).concat(i.map(o=>k.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:g,length:m,endEdge:y}}=l;switch(l.type){case"gap_center":{const v=(m-e.width)/2,x=Ui(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:Tt(),gaps:[...Sa(i,f.id,v,"backward",x),{startEdge:d,endEdge:o.left},{startEdge:o.right,endEdge:y},...Sa(i,g.id,v,"forward",x)]});break}case"gap_duplicate":{const v=Ui(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:Tt(),gaps:l.protrusionDirection==="left"?[{startEdge:o.right,endEdge:d.map(x=>x.clone().addXY(-f.pageBounds.width,0))},{startEdge:d,endEdge:y},...Sa(i,g.id,m,"forward",v)]:[...Sa(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:g,length:m,endEdge:y}}=l;switch(l.type){case"gap_center":{const v=(m-e.height)/2,x=Ui(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:Tt(),gaps:[...Sa(s,f.id,v,"backward",x),{startEdge:d,endEdge:o.top},{startEdge:o.bottom,endEdge:y},...Sa(s,l.gap.endNode.id,v,"forward",x)]});break}case"gap_duplicate":{const v=Ui(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:Tt(),gaps:l.protrusionDirection==="top"?[{startEdge:o.bottom,endEdge:d.map(x=>x.clone().addXY(0,-f.pageBounds.height))},{startEdge:d,endEdge:y},...Sa(s,g.id,m,"forward",v)]:[...Sa(s,f.id,m,"backward",v),{startEdge:d,endEdge:y},{startEdge:y.map(x=>x.clone().addXY(0,g.pageBounds.height)),endEdge:o.top}]})}break}}return Jie(a),a}}vu=qie();nv(vu,1,"getSnapPointsCache",c$,fh);nv(vu,1,"getSnappablePoints",l$,fh);nv(vu,1,"getSnappableGapNodes",a$,fh);nv(vu,1,"getVisibleGaps",o$,fh);Yie(vu,fh);function Vj(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 Qie=Object.create,u$=Object.defineProperty,eoe=Object.getOwnPropertyDescriptor,toe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),d$=n=>{throw TypeError(n)},h$=(n,e,t)=>e in n?u$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,noe=n=>[,,,Qie(null)],f$=["class","method","getter","setter","accessor","field","value","get","set"],p$=n=>n!==void 0&&typeof n!="function"?d$("Function expected"):n,roe=(n,e,t,r,s)=>({kind:f$[n],name:e,metadata:r,addInitializer:i=>t._?d$("Already initialized"):s.push(p$(i||null))}),soe=(n,e)=>h$(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},ooe=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=f$[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=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,p$(o)&&(x[y]=o);return x&&u$(s,t,x),s},aoe=(n,e,t)=>h$(n,e+"",t),g$,rv;const loe=()=>null,coe=()=>[];g$=[le];class XE{constructor(e){this.manager=e,ioe(rv,5,this),aoe(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):loe,i=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):coe;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=Fr(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=Fr(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))k.DistMin(r,c,i)&&(i=k.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=Fr(this.editor.getShapePageTransform(c)),g=this.editor.getPointInShapeSpace(c,r),m=d.nearestPoint(g),y=f.applyToPoint(m);k.DistMin(r,y,a)&&(a=k.Dist(r,y),l=y)}return l||null}snapHandle({currentShapeId:e,handle:t}){const s=Fr(this.editor.getShapePageTransform(e)).applyToPoint(t),i=this.getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:s});return i?(this.manager.setIndicators([{id:Tt(),type:"points",points:[i]}]),{nudge:k.Sub(i,s)}):null}}rv=noe();ooe(rv,1,"getSnapGeometryCache",g$,XE);soe(rv,XE);var uoe=Object.create,m$=Object.defineProperty,doe=Object.getOwnPropertyDescriptor,hoe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),y$=n=>{throw TypeError(n)},S$=(n,e,t)=>e in n?m$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,foe=n=>[,,,uoe(null)],v$=["class","method","getter","setter","accessor","field","value","get","set"],x$=n=>n!==void 0&&typeof n!="function"?y$("Function expected"):n,poe=(n,e,t,r,s)=>({kind:v$[n],name:e,metadata:r,addInitializer:i=>t._?y$("Already initialized"):s.push(x$(i||null))}),goe=(n,e)=>S$(e,hoe("metadata"),n[3]),moe=(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},ZE=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=v$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,doe(s,t)),b=r.length-1;b>=0;b--)l=poe(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,x$(o)&&(x[y]=o);return x&&m$(s,t,x),s},vC=(n,e,t)=>S$(n,typeof e!="symbol"?e+"":e,t),w$,b$,C$,ph;C$=[le],b$=[le],w$=[le];class Kp{constructor(e){this.editor=e,moe(ph,5,this),vC(this,"shapeBounds"),vC(this,"handles"),vC(this,"_snapIndicators",ln("snapLines",void 0)),this.shapeBounds=new fh(this),this.handles=new XE(this)}getIndicators(){return this._snapIndicators.get()??bi}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(ys(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())}}ph=foe();ZE(ph,1,"getSnapThreshold",C$,Kp);ZE(ph,1,"getSnappableShapes",b$,Kp);ZE(ph,1,"getCurrentCommonAncestor",w$,Kp);goe(ph,Kp);const yoe=/\r?\n|\r/g;function qj(n){return n.replace(yoe,`
205
+ `).split(`
206
+ `).map(e=>e||" ").join(`
207
+ `)}const Soe={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},voe=/\s/;class xoe{constructor(e){R(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=qj(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,g=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],E=C.top+o,_=C.left+i,M=C.right+i,A=_<m,O=voe.test(x);if(O!==f||E!==g||!d){if(d){if(t&&E!==g){y=!0;break}r.push(d)}d={box:{x:_,y:E,w:C.width,h:C.height},text:x},m=_}else A&&(d.box.x=_),d.box.w=A?d.box.w+C.width:M-d.box.x,d.text+=x;x===`
208
+ `&&(m=0),f=O,g=E,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",Soe[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=qj(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 woe=Object.create,P$=Object.defineProperty,boe=Object.getOwnPropertyDescriptor,Coe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),k$=n=>{throw TypeError(n)},I$=(n,e,t)=>e in n?P$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Poe=n=>[,,,woe(null)],E$=["class","method","getter","setter","accessor","field","value","get","set"],_$=n=>n!==void 0&&typeof n!="function"?k$("Function expected"):n,koe=(n,e,t,r,s)=>({kind:E$[n],name:e,metadata:r,addInitializer:i=>t._?k$("Already initialized"):s.push(_$(i||null))}),Ioe=(n,e)=>I$(e,Coe("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},T$=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=E$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,boe(s,t)),b=r.length-1;b>=0;b--)l=koe(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,_$(o)&&(x[y]=o);return x&&P$(s,t,x),s},Em=(n,e,t)=>I$(n,typeof e!="symbol"?e+"":e,t),M$,A$,Wp;const Gj=u3;A$=[bs],M$=[bs];class sv{constructor(e){this.editor=e,Eoe(Wp,5,this),Em(this,"cancelRaf"),Em(this,"isPaused",!0),Em(this,"now",0),Em(this,"prevPoint",new k),this.editor.disposables.add(this.dispose),this.start()}start(){var e;this.isPaused=!1,(e=this.cancelRaf)==null||e.call(this),this.cancelRaf=Gj(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=Gj(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=k.Sub(r,t);this.prevPoint=r.clone();const o=i.len(),a=o?i.div(o):new k(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)}}Wp=Poe();T$(Wp,1,"tick",A$,sv);T$(Wp,1,"dispose",M$,sv);Ioe(Wp,sv);var _oe=Object.create,O$=Object.defineProperty,Toe=Object.getOwnPropertyDescriptor,Moe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),R$=n=>{throw TypeError(n)},D$=(n,e,t)=>e in n?O$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Aoe=n=>[,,,_oe(null)],j$=["class","method","getter","setter","accessor","field","value","get","set"],N$=n=>n!==void 0&&typeof n!="function"?R$("Function expected"):n,Ooe=(n,e,t,r,s)=>({kind:j$[n],name:e,metadata:r,addInitializer:i=>t._?R$("Already initialized"):s.push(N$(i||null))}),Roe=(n,e)=>D$(e,Moe("metadata"),n[3]),Doe=(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},Ei=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=j$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Toe(s,t)),b=r.length-1;b>=0;b--)l=Ooe(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,N$(o)&&(x[y]=o);return x&&O$(s,t,x),s},Yj=(n,e,t)=>D$(n,typeof e!="symbol"?e+"":e,t),L$,F$,z$,$$,B$,U$,H$,K$,W$,V$,q$,G$,Xr;G$=[le],q$=[le],V$=[le],W$=[le],K$=[le],H$=[le],U$=[le],B$=[le],$$=[le],z$=[le],F$=[le],L$=[le];class Ts{constructor(e,t){if(this.user=e,this.inferDarkMode=t,Doe(Xr,5,this),Yj(this,"systemColorScheme",ln("systemColorScheme","light")),Yj(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??Po.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??Po.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){var e;return((e=this.user.userPreferences.get().name)==null?void 0:e.trim())??Po.name}getLocale(){return this.user.userPreferences.get().locale??Po.locale}getColor(){return this.user.userPreferences.get().color??Po.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??Po.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??Po.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??Po.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??Po.isPasteAtCursorMode}}Xr=Aoe();Ei(Xr,1,"getUserPreferences",G$,Ts);Ei(Xr,1,"getIsDarkMode",q$,Ts);Ei(Xr,1,"getEdgeScrollSpeed",V$,Ts);Ei(Xr,1,"getAnimationSpeed",W$,Ts);Ei(Xr,1,"getId",K$,Ts);Ei(Xr,1,"getName",H$,Ts);Ei(Xr,1,"getLocale",U$,Ts);Ei(Xr,1,"getColor",B$,Ts);Ei(Xr,1,"getIsSnapMode",$$,Ts);Ei(Xr,1,"getIsWrapMode",z$,Ts);Ei(Xr,1,"getIsDynamicResizeMode",F$,Ts);Ei(Xr,1,"getIsPasteAtCursorMode",L$,Ts);Roe(Xr,Ts);const joe={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"},Noe=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class Ne{constructor(e,t){R(this,"performanceTracker");R(this,"id");R(this,"type");R(this,"shapeType");R(this,"initial");R(this,"children");R(this,"isLockable");R(this,"parent");R(this,"_path");R(this,"_current");R(this,"_isActive");R(this,"_currentToolIdMask",ln("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=ln("toolIsActive"+this.id,!1),this._current=ln("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 UL}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=joe[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(bn.measurePerformance.get()&&Noe.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;bn.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)}}R(Ne,"id"),R(Ne,"initial"),R(Ne,"children"),R(Ne,"isLockable",!0);class gk 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}}}}R(gk,"id","root"),R(gk,"initial","");var Loe=Object.create,Y$=Object.defineProperty,Foe=Object.getOwnPropertyDescriptor,X$=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Z$=n=>{throw TypeError(n)},J$=(n,e,t)=>e in n?Y$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,zoe=n=>[,,,Loe((n==null?void 0:n[X$("metadata")])??null)],Q$=["class","method","getter","setter","accessor","field","value","get","set"],eB=n=>n!==void 0&&typeof n!="function"?Z$("Function expected"):n,$oe=(n,e,t,r,s)=>({kind:Q$[n],name:e,metadata:r,addInitializer:i=>t._?Z$("Already initialized"):s.push(eB(i||null))}),Boe=(n,e)=>J$(e,X$("metadata"),n[3]),Uoe=(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},Ee=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=Q$[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Foe(s,t)),b=r.length-1;b>=0;b--)l=$oe(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,eB(o)&&(x[y]=o);return x&&Y$(s,t,x),s},Ue=(n,e,t)=>J$(n,typeof e!="symbol"?e+"":e,t),tB,nB,rB,sB,iB,oB,aB,lB,cB,uB,dB,hB,fB,pB,gB,mB,yB,SB,vB,xB,wB,bB,CB,PB,kB,IB,EB,_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,mk,Ie;class ke extends(mk=sse,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],EB=[le],IB=[le],kB=[le],PB=[le],CB=[le],bB=[le],wB=[le],xB=[le],vB=[le],SB=[le],yB=[le],mB=[le],gB=[le],pB=[le],fB=[le],hB=[le],dB=[le],uB=[le],cB=[le],lB=[le({isEqual:(e,t)=>e.equals(t)})],aB=[le],oB=[le],iB=[le],sB=[bs],rB=[bs],nB=[bs],tB=[bs],mk){constructor({store:e,user:t,shapeUtils:r,bindingUtils:s,tools:i,getContainer:o,cameraOptions:a,textOptions:l,initialState:c,autoFocus:d,inferDarkMode:f,options:g,isShapeHidden:m,fontAssetUrls:y}){var G;super(),Uoe(Ie,5,this),Ue(this,"id",Tt()),Ue(this,"_isShapeHiddenPredicate"),Ue(this,"options"),Ue(this,"contextId",Tt()),Ue(this,"store"),Ue(this,"root"),Ue(this,"disposables",new Set),Ue(this,"isDisposed",!1),Ue(this,"_tickManager"),Ue(this,"snaps"),Ue(this,"timers",wS.forContext(this.contextId)),Ue(this,"user"),Ue(this,"textMeasure"),Ue(this,"fonts"),Ue(this,"environment",kt),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",$r.forContext(this.contextId)),Ue(this,"_currentRichTextEditor",ln("rich text editor",null)),Ue(this,"_textOptions"),Ue(this,"_cameraOptions",ln("camera options",dj)),Ue(this,"_viewportAnimation",null),Ue(this,"_willSetInitialBounds",!0),Ue(this,"_isLockedOnFollowingUser",ln("isLockedOnFollowingUser",!1)),Ue(this,"_cameraState",ln("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 k,originScreenPoint:new k,previousPagePoint:new k,previousScreenPoint:new k,currentPagePoint:new k,currentScreenPoint:new k,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 k}),Ue(this,"_clickManager",new tv(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={...die,...g},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new $ie({store:e,annotateError:z=>{this.annotateError(z,{origin:"history.batch",willCrashApp:!0}),this.crash(z)}}),this.snaps=new Kp(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...dj,...a}),this._textOptions=ln("text options",l??null),this.user=new Ts(t??mz(),f??!1),this.disposables.add(()=>this.user.dispose()),this.getContainer=o,this.textMeasure=new xoe(this),this.fonts=new Lie(this,y),this._tickManager=new sv(this);class v extends gk{}R(v,"initial",c??""),this.root=new v(this),this.root.children={};const x=Cz(r),b={},C={},E=new Map;for(const z of x){const N=new z(this);b[z.type]=N;const L=J5(z.props??{});C[z.type]=L;for(const V of L.keys())if(!E.has(V.id))E.set(V.id,V);else if(E.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 _=wz(s),M={};for(const z of _){const N=new z(this);M[z.type]=N}this.bindingUtils=M;for(const z of[...i]){if(wi(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 Hie(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 Z=z.erasingShapeIds.filter($=>!N.has($));Z.length!==z.erasingShapeIds.length&&(L||(L={...z}),L.erasingShapeIds=Z),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 O=new Map;const D=new Set,B=new Set;let U=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var z,N,L,V;D.clear();for(const Z of B){B.delete(Z);const W=this.getShape(Z);if(!W)continue;const $=this.getShapeUtil(W),Y=(z=$.onChildrenChange)==null?void 0:z.call($,W);Y!=null&&Y.length&&this.updateShapes(Y)}if(U.size){const Z=U;U=new Set;for(const W of Z){const $=this.getBindingUtil(W);(N=$.onOperationComplete)==null||N.call($)}}if(O.size){const Z=O;O=new Map;for(const W of Z.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,Z,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=(Z=this.getBindingUtil($)).onAfterChangeToShape)==null||W.call(Z,{binding:$,shapeBefore:z,shapeAfter:N}));if(z.parentId!==N.parentId){const $=Y=>{var K,ne,ge,Pe;const re=this.getShape(Y);if(re)for(const ce of this.getBindingsInvolvingShape(re))U.add(ce.type),ce.fromId===re.id&&((ne=(K=this.getBindingUtil(ce)).onAfterChangeFromShape)==null||ne.call(K,{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&&ps(N.parentId)){const $=new Set([z.id]);this.visitDescendants(z.id,Y=>{$.add(Y)});for(const Y of this.getPageStates()){if(Y.pageId===N.parentId)continue;const re=A(Y,$);re&&this.store.put([re])}}z.parentId&&ys(z.parentId)&&B.add(z.parentId),N.parentId!==z.parentId&&ys(N.parentId)&&B.add(N.parentId)},beforeDelete:z=>{var Z,W,$,Y;if(D.has(z.id))return;z.parentId&&ys(z.parentId)&&B.add(z.parentId),D.add(z.id);const N=[];for(const re of this.getBindingsInvolvingShape(z)){U.add(re.type),N.push(re.id);const K=this.getBindingUtil(re);re.fromId===z.id?((Z=K.onBeforeIsolateToShape)==null||Z.call(K,{binding:re,removedShape:z}),(W=K.onBeforeDeleteFromShape)==null||W.call(K,{binding:re,shape:z})):(($=K.onBeforeIsolateFromShape)==null||$.call(K,{binding:re,removedShape:z}),(Y=K.onBeforeDeleteToShape)==null||Y.call(K,{binding:re,shape:z}))}N.length&&this.deleteBindings(N);const L=new Set([z.id]),V=rt(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,Z;const L=(Z=(V=this.getBindingUtil(N)).onBeforeChange)==null?void 0:Z.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=Do.createId(z.id),L=Vi.createId(z.id);this.store.has(N)||this.store.put([Do.create({id:N})]),this.store.has(L)||this.store.put([Vi.create({id:L,pageId:z.id})])},afterDelete:(z,N)=>{var Z,W;if(((Z=this.getInstanceState())==null?void 0:Z.currentPageId)===z.id){const $=(W=this.getPages().find(Y=>Y.id!==z.id))==null?void 0:W.id;$?this.store.put([{...this.getInstanceState(),currentPageId:$}]):N==="user"&&this.store.ensureStoreIsUsable()}const L=Do.createId(z.id),V=Vi.createId(z.id);this.store.remove([L,V])}},instance:{afterChange:(z,N,L)=>{var V;if(!this.store.has(N.currentPageId)){const Z=this.store.has(z.currentPageId)?z.currentPageId:(V=this.getPages()[0])==null?void 0:V.id;Z?this.store.update(N.id,W=>({...W,currentPageId:Z})):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(Z=>{var $,Y;let W=($=this.getShape(Z))==null?void 0:$.parentId;for(;ys(W);){if(N.selectedShapeIds.includes(W))return!1;W=(Y=this.getShape(W))==null?void 0:Y.parentId}return!0});let V=null;if(L.length>0){const Z=this.findCommonAncestor(rt(L.map(W=>this.getShape(W))),W=>this.isShapeOfType(W,"group"));Z&&(V=Z)}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=Iie(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=kie(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 jie(this),this.focusManager=new Nie(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 UL,(G=this.store.props.collaboration)!=null&&G.mode){const z=this.store.props.collaboration.mode;this.disposables.add(Yi("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=Cn(this.shapeUtils,t);return tt(r,`No shape util found for type "${t}"`),r}hasShapeUtil(e){const t=typeof e=="string"?e:e.type;return wi(this.shapeUtils,t)}getBindingUtil(e){const t=typeof e=="string"?e:e.type,r=Cn(this.bindingUtils,t);return tt(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??Tt()),this}markHistoryStoppingPoint(e){const t=`[${e??"stop"}]_${Tt()}`;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 pI(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(ik)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(zr)}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 Vi.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 rt(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=rt(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){return 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 rt(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:fI(t)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return rt(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 Fr(this._textOptions.get(),"Cannot use text without setting textOptions")}_unsafe_getCameraId(){return Do.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}=Zj(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 _n(e.constraints.initialZoom)}}getBaseZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.baseZoom==="default")return 1;const{zx:t,zy:r}=Zj(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 _n(e.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(e){var r;const t=Xt({...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=er(a.zoomSteps),d=this.getViewportScreenBounds();if(a.constraints){const{constraints:f}=a,g=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-g*2)/y.h,b=this.getBaseZoom(),C=c*b,E=l*b;if(t!=null&&t.reset&&(o=this.getInitialZoom()),o<E||o>C){const{x:z,y:N,z:L}=r,V=-z+d.w/L/2,Z=-N+d.h/L/2;o=Rn(o,E,C);const W=-z+d.w/o/2,$=-N+d.h/o/2;s=z+W-V,i=N+$-Z}const _=m/o-y.x,M=g/o-y.y,A=(d.w-m*2)/o-y.w,O=(d.h-g*2)/o-y.h,D=_+A*f.origin.x,B=M+O*f.origin.y,U=typeof f.behavior=="string"?f.behavior:f.behavior.x,G=typeof f.behavior=="string"?f.behavior:f.behavior.y;if(t!=null&&t.reset)s=D,i=B;else{switch(U){case"fixed":{s=D;break}case"contain":{o<v?s=D:s=Rn(s,_+A,_);break}case"inside":{o<v?s=Rn(s,_,(d.w-m)/o-y.w):s=Rn(s,_+A,_);break}case"outside":{s=Rn(s,m/o-y.w,(d.w-m)/o);break}case"free":break;default:throw _n(U)}switch(G){case"fixed":{i=B;break}case"contain":{o<x?i=B:i=Rn(i,M+O,M);break}case"inside":{o<x?i=Rn(i,M,(d.h-g)/o-y.h):i=Rn(i,M+O,M);break}case"outside":{i=Rn(i,g/o-y.h,(d.h-g)/o);break}case"free":break;default:throw _n(G)}}}else if(o>c||o<l){const{x:f,y:g,z:m}=r;o=Rn(o,l,c),s=f+(-f+d.w/o/2)-(-f+d.w/m/2),i=g+(-g+d.h/o/2)-(-g+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:(Ps(()=>{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(zr);if(l.x/o-s!==c.x||l.y/o-i!==c.y){const f={type:"pointer",target:"canvas",name:"pointer_move",point:k.AddXY(l,d.x,d.y),pointerId:hj.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,metaKey:this.inputs.metaKey,accelKey:Pr(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=k.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 k(-(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(rt(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 g=this.getInitialZoom();l!==g&&(f=g)}return this.setCamera(new k(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=er(a)*l;for(let d=1;d<a.length;d++){const f=a[d-1]*l,g=a[d]*l;if(!(g-o<=(g-f)/2)){c=g;break}}this.setCamera(new k(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,g=s[d]*i;if(!(g-l>=(g-f)/2)){c=f;break}}this.setCamera(new k(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(Lte,s.width*.28),o=this.getBaseZoom(),a=r.zoomSteps[0],l=er(r.zoomSteps);let c=Rn(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 k(-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 k(-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 k(-c,-d,this.getViewportScreenBounds().width/(f-c)),{force:!0})}_animateToViewport(e,t={animation:aC}){const{animation:r,...s}=t;if(!r)return;const{duration:i=0,easing:o=Un.easeInOutCubic}=r,a=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||a===0?this._setCamera(new k(-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:g,y:m,z:y}=this.getCamera(),v=k.Mul(o,l*f/y);l*=1-i,l<a?c():this._setCamera(new k(g+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,!jl(document.body.scrollWidth,e.maxX,1),!jl(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(k.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 k(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(zr),{x:r,y:s,z:i=1}=this.getCamera();return new k((e.x-t.x)/i-r,(e.y-t.y)/i-s,e.z??.5)}pageToScreen(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(zr),{x:r,y:s,z:i=1}=this.getCamera();return new k((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 k((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=>gV(e.filter(i=>i.userId===r),i=>i.lastActivityTimestamp??0)):bi}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 Ps(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const i=Yi("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(),g=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(g<this.options.followChaseViewportSnap&&m<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const y=Rn(c*.5,.1,.8),v=new ye(St(f.minX,d.minX,y),St(f.minY,d.minY,y),St(f.width,d.width,y),St(f.height,d.height,y)),x=new k(-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 g=!1;const m=this.getShapeUtil(f);e&&(g=!d&&i.includes(l),g&&(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||g);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(qV)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return Array.from(this._getAllPagesQuery().get()).sort(tr)}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=yie(e.name??"Page 1",t.map(o=>o.name));let s=e.index;(!s||t.some(o=>o.index===s))&&(s=Oo(t[t.length-1].index));const i=Es.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=Es.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=Qf(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(()=>{var r,s;(s=(r=this.store.props.assets).remove)==null||s.call(r,t),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(ps(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||ps(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(ps(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=Rj(s,i);return o?o.map(k.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&&k.Equals(o,r[a])))return t.clone();const i=Rj(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(ps(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(ps(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=rt(r.map(c=>this.getShape(c)));if(s.length===1){const c=s[0].parentId;return ps(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 Pie(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,g=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&&!Ws(e,C)?!1:i?i(b):!0});for(let b=v.length-1;b>=0;b--){const C=v[b],E=this.getShapeGeometry(C),_=E instanceof Ii,M=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 O of E.children)if(O.isLabel&&O.isPointInBounds(M))return C}if(this.isShapeOfType(C,"frame")){const O=E.distanceToPoint(M,c);if(Math.abs(O)<=o)return y||C;if(E.hitTestPoint(M,0,!0))return y||g||(d?C:void 0);continue}let A;if(_){let O=1/0;for(const D of E.children){if(D.isLabel&&!l)continue;const B=D.distanceToPoint(M,c);B<O&&(O=B)}A=O}else o===0&&(E.bounds.w<1||E.bounds.h<1)||E.bounds.containsPoint(M,o)?A=E.distanceToPoint(M,c):A=1/0;if(E.isClosed){if(A<=o){if(E.isFilled||_&&E.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:O}=E;O<f&&(f=O,g=C)}}}else if(A<this.options.hitTestMargin/r)return C}return y||g||void 0}getShapesAtPoint(e,t={}){return this.getCurrentPageShapes().filter(r=>!this.isShapeHidden(r)&&this.isPointInShape(r,e,t))}isPointInShape(e,t,r={}){const{hitInside:s=!1,margin:i=0}=r,o=typeof e=="string"?e:e.id,a=this.getShapeMask(o);return a&&!Ws(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 k(0,0);if(ps(s.parentId))return k.From(t);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(t):k.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++)v6(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(ys(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||!ys(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 ps(r.parentId)?r.parentId:this.getAncestorPageId(this.getShape(r.parentId))}reparentShapes(e,t,r){const s=typeof e[0]=="string"?e:e.map(g=>g.id);if(s.length===0)return this;const i=[],o=ps(t)?ve.Identity():this.getShapePageTransform(t),a=o.rotation();let l=[];const c=rt(this.getSortedChildIdsForParent(t).map(g=>this.getShape(g)));if(r){const g=c.find(m=>m.index===r);if(g){const m=c[c.indexOf(g)+1];m?l=zd(r,m.index,s.length):l=Rw(r,s.length)}else{const m=c.sort(tr).find(y=>y.index>r);m?l=zd(r,m.index,s.length):l=Rw(r,s.length)}}else{const g=c.length&&c[c.length-1];l=g?Rw(g.index,s.length):ep(s.length)}const d=o.clone().invert(),f=rt(s.map(g=>this.getShape(g))).sort(tr);return this.run(()=>{for(let g=0;g<f.length;g++){const m=f[g],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[g]})}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 Oo(s.index)}getSortedChildIdsForParent(e){const t=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[t];return r||bi}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(tr))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=bie(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)??bi;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??qc(),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=bo(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=Vz({editor:this,ids:s});return i?(cy({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=bo(r,i)),r=bo(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=bo(r,o));const a=(d=s.onTranslateEnd)==null?void 0:d.call(s,e,r);return a&&(r=bo(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=k.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(g=>g.id);if(r.length<=0)return this;const s=new Set(r),i=this.getShapeAndDescendantIds(r),o=[...i].reverse(),a=new Map;for(const g of i)a.set(g,jt());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=Xj(this,i,g=>{const m=[];for(const v of g){const x=this.getBinding(v);if(!x)continue;const b=qc();m.push({...x,id:b,fromId:Fr(a.get(x.fromId)),toId:Fr(a.get(x.toId))})}const y=[];for(const v of o){const x=Fr(a.get(v)),b=this.getShape(v);if(!b)continue;let C=0,E=0;if(t&&s.has(v)){const _=this.getShapeParentTransform(b),M=new k(t.x,t.y).rot(-_.rotation());C=M.x,E=M.y}y.push({shape:{...b,id:x,x:b.x+C,y:b.y+E,index:"a1",parentId:a.get(b.parentId)??b.parentId},originalShape:b})}return{shapesToCreateWithOriginals:y,bindingsToCreate:m}});l.forEach(({shape:g,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,E=Qf(m.index,C==null?void 0:C.index);g.index=E});const d=l.map(({shape:g})=>g);if(d.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){_m(this);return}if(this.createShapes(d),this.createBindings(c),this.setSelectedShapes(rt(r.map(g=>a.get(g)))),t!==void 0){const g=this.getSelectionPageBounds(),m=this.getViewportPageBounds();g&&!m.contains(g)&&this.centerOnPoint(g.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(e,t){const r=typeof e[0]=="string"?e:e.map(a=>a.id);if(r.length===0)return this;if(this.getIsReadonly())return this;const s=this.getCurrentPageId();if(t===s)return this;if(!this.store.has(t))return this;const i=this.getContentFromCurrentPage(r);if(!i)return this;if(this.getPageShapeIds(t).size+i.shapes.length>this.options.maxShapesPerPage)return _m(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=Im(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=Im(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=Im(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=Im(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=rt(r.map(l=>this.getShape(l)));for(const l of s)if(this.isShapeOfType(l,"group")){const c=rt(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,g=this.getShapePageTransform(l.id);d&&f&&g&&(i.push({shape:l,localBounds:f,pageTransform:g,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 b,C;const s=r??this.options.adjacentShapeMargin,i=typeof e[0]=="string"?e:e.map(E=>E.id);if(this.getIsReadonly())return this;const o=rt(i.map(E=>this.getShape(E))),a=[],l=new Set;for(const E of o){if(l.has(E.id))continue;l.add(E.id);const _=this.getShapePageBounds(E);if(!_||!((C=(b=this.getShapeUtil(E)).canBeLaidOut)!=null&&C.call(b,E,{type:"stack",shapes:o})))continue;const M=[E],A=[_];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(E.id,"arrow"),initialShapes:o,resultShapes:M,resultBounds:A,visited:l});const O=ye.Common(A);O&&a.push({shapes:M,pageBounds:O})}const c=a.length;if(s===0&&c<3||c<2)return this;let d,f,g,m;t==="horizontal"?(d="x",f="minX",g="maxX",m="width"):(d="y",f="minY",g="maxY",m="height");let y=0;if(s===0){const E={};a.sort((M,A)=>M.pageBounds[f]-A.pageBounds[f]);for(let M=0;M<c-1;M++){const A=a[M],D=a[M+1].pageBounds[f]-A.pageBounds[g];E[D]||(E[D]=0),E[D]++}let _=1;for(const[M,A]of Object.entries(E))A>_&&(_=A,y=parseFloat(M));if(_===1){let M=0;for(const[A,O]of Object.entries(E))y+=parseFloat(A)*O,M+=O;y/=M}}else y=s;const v=[];let x=a[0].pageBounds[g];for(let E=1;E<a.length;E++){const{shapes:_,pageBounds:M}=a[E],A=new k;A[d]=x+y-M[d];for(const O of _){const D=A.clone(),B=this.getShapeParent(O);if(B){const U=this.getShapePageTransform(B);U&&D.rot(-U.rotation())}D.add(O),v.push(this.getChangesToTranslateShape(O,D))}x+=M[m]+y}return this.updateShapes(v),this}packShapes(e,t){var M,A;if(this.getIsReadonly())return this;const r=t??this.options.adjacentShapeMargin,s=typeof e[0]=="string"?e:e.map(O=>O.id),i=rt(s.map(O=>this.getShape(O))),o=[],a=[],l=new Set;for(const O of i){if(l.has(O.id))continue;l.add(O.id);const D=this.getShapePageBounds(O);if(!D||!((A=(M=this.getShapeUtil(O)).canBeLaidOut)!=null&&A.call(M,O,{type:"pack",shapes:i})))continue;const B=[O],U=[D];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(O.id,"arrow"),initialShapes:i,resultShapes:B,resultBounds:U,visited:l});const G=ye.Common(U);G&&(o.push({shapes:B,pageBounds:G,nextPageBounds:G.clone()}),a.push(G))}if(o.length<2)return this;let c=0;for(const{pageBounds:O}of o)c+=O.width*O.height;const d=ye.Common(a),f=d.width;o.sort((O,D)=>O.pageBounds.width-D.pageBounds.width).sort((O,D)=>O.pageBounds.height-D.pageBounds.height);const g=Math.max(Math.ceil(Math.sqrt(c/.95)),f),m=[new ye(d.x,d.y,g,1/0)];let y=0,v=0,x,b;for(const{nextPageBounds:O}of o)for(let D=m.length-1;D>=0;D--)if(x=m[D],!(O.width>x.width||O.height>x.height)){O.x=x.x,O.y=x.y,v=Math.max(v,O.maxY),y=Math.max(y,O.maxX),O.width===x.width&&O.height===x.height?(b=m.pop(),D<m.length&&(m[D]=b)):O.height===x.height?(x.x+=O.width+r,x.width-=O.width+r):O.width===x.width?(x.y+=O.height+r,x.height-=O.height+r):(m.push(new ye(x.x+(O.width+r),x.y,x.width-(O.width+r),O.height)),x.y+=O.height+r,x.height-=O.height+r);break}const C=ye.Common(o.map(O=>O.nextPageBounds)),E=k.Sub(d.center,C.center),_=[];for(const{shapes:O,pageBounds:D,nextPageBounds:B}of o){const U=k.Sub(B.point,D.point).add(E);for(const G of O){const z=U.clone();if(this.getShapeParent(G)){const L=this.getShapeParentTransform(G);L&&z.rot(-L.rotation())}z.add(G),_.push(this.getChangesToTranslateShape(G,z))}}return _.length&&this.updateShapes(_),this}alignShapes(e,t){var d,f;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(g=>g.id),s=rt(r.map(g=>this.getShape(g))),i=[],o=[],a=new Set;for(const g of s){if(a.has(g.id))continue;a.add(g.id);const m=this.getShapePageBounds(g);if(!m||!((f=(d=this.getShapeUtil(g)).canBeLaidOut)!=null&&f.call(d,g,{type:"align",shapes:s})))continue;const y=[g],v=[m];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(g.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:g,pageBounds:m})=>{const y=new k;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 g){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 E,_;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(M=>M.id),s=rt(r.map(M=>this.getShape(M))),i=[],o=new Set;for(const M of s){if(o.has(M.id))continue;o.add(M.id);const A=this.getShapePageBounds(M);if(!A||!((_=(E=this.getShapeUtil(M)).canBeLaidOut)!=null&&_.call(E,M,{type:"distribute",shapes:s})))continue;const O=[M],D=[A];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(M.id,"arrow"),initialShapes:s,resultShapes:O,resultBounds:D,visited:o});const B=ye.Common(D);B&&i.push({shapes:O,pageBounds:B})}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=[],g=i.sort((M,A)=>M.pageBounds[l]-A.pageBounds[l])[0],m=i.sort((M,A)=>A.pageBounds[c]-M.pageBounds[c])[0];if(g===m){const M=new Set(g.shapes.map(A=>A.id));return this.distributeShapes(r.filter(A=>!M.has(A)),t)}const y=i.filter(M=>M!==g&&M!==m).sort((M,A)=>M.pageBounds[l]===A.pageBounds[l]?M.shapes[0].id<A.shapes[0].id?-1:1:M.pageBounds[l]-A.pageBounds[l]),v=g.pageBounds[c],x=m.pageBounds[l]-v,b=y.reduce((M,A)=>M+A.pageBounds[d],0),C=(x-b)/(y.length+1);for(let M=v+C,A=0;A<y.length;A++){const{shapes:O,pageBounds:D}=y[A],B=new k;B[a]=M-D[a],M+D[d]>m.pageBounds[c]-1&&(B[a]=m.pageBounds[c]-D[c]-1);for(const U of O){const G=B.clone(),z=this.getShapeParent(U);if(z){const N=this.getShapePageTransform(z);N&&G.rot(-N.rotation())}G.add(U),f.push(this.getChangesToTranslateShape(U,G))}M+=D[d]+C}return this.updateShapes(f),this}stretchShapes(e,t){var g,m;const r=typeof e[0]=="string"?e:e.map(y=>y.id);if(this.getIsReadonly())return this;const s=rt(r.map(y=>this.getShape(y))).filter(y=>{var v;return((v=this.getShapePageTransform(y))==null?void 0:v.rotation())%(wt/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=(g=this.getShapeUtil(y)).canBeLaidOut)!=null&&m.call(g,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 k;x[c]=l[d]-v[d];const b=v.center.clone();b[c]=l[d];const C=new k(1,1);C[c]=l[f]/v[f];for(const E of y){const _=x.clone(),M=this.getShapeParentTransform(E);M&&x.rot(-M.rotation()),_.add(E);const A=this.getChangesToTranslateShape(E,_);this.updateShape(A),this.resizeShape(E.id,C,{initialBounds:this.getShapeGeometry(E).bounds,scaleOrigin:b,isAspectRatioLocked:this.getShapeUtil(E).isAspectRatioLocked(E),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 k(1,t.y)),Number.isFinite(t.y)||(t=new k(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(!X3(l,c))return this._resizeUnalignedShape(s,t,{...r,initialBounds:d,scaleOrigin:o,scaleAxisRotation:c,initialPageTransform:a,isAspectRatioLocked:f,initialShape:i});const g=this.getShapeUtil(i);f&&(Math.abs(t.x)>Math.abs(t.y)?t=new k(t.x,Math.sign(t.y)*Math.abs(t.x)):t=new k(Math.sign(t.x)*Math.abs(t.y),t.y));let m=!1;if(g.onResize&&g.canResize(i)){const b=this._scalePagePoint(ve.applyToPoint(a,new k(0,0)),o,t,c),C=this.getPointInParentSpace(i.id,b),E=new k(t.x,t.y),_=jl((l-c)%Math.PI,0);E.x=_?t.x:t.y,E.y=_?t.y:t.x;const M=ve.applyToPoint(a,new k),{x:A,y:O}=this.getPointInParentSpace(i.id,M);let D=i;r.skipStartAndEndCallbacks||(D=bo(i,((v=g.onResizeStart)==null?void 0:v.call(g,i))??void 0));const B=g.onResize({...i,x:A,y:O},{newPoint:C,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:E.x,scaleY:E.y,initialBounds:d,initialShape:i});B&&(m=!0),D=bo(D,{id:s,type:i.type,x:C.x,y:C.y,...B}),r.skipStartAndEndCallbacks||(D=bo(D,((x=g.onResizeEnd)==null?void 0:x.call(g,i,D))??void 0)),this.updateShapes([D])}if(!m){const b=ve.applyToPoint(a,d.center),C=this._scalePagePoint(b,o,t,c),E=this.getPointInParentSpace(i.id,b),_=this.getPointInParentSpace(i.id,C),M=k.Sub(_,E);this.updateShapes([{id:s,type:i.type,x:i.x+M.x,y:i.y+M.y}])}return this}_scalePagePoint(e,t,r,s){const i=k.RotWith(e,t,-s).sub(t),o=k.MulV(i,r);return k.Add(o,t).rotWith(t,s)}_resizeUnalignedShape(e,t,r){const{type:s}=r.initialShape,i=new k(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 g=k.Sub(a,d),m=k.Add(f,g),{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 _m(this),this;const s=this.getFocusedGroupId();return this.run(()=>{var d,f;const i=this.getCurrentPageShapesSorted(),o=e.map(g=>{if(g.id||(g={id:jt(),...g}),!g.parentId||!(this.store.has(g.parentId)||e.some(m=>m.id===g.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,g.type)&&this.isPointInShape(x,{x:g.x??0,y:g.y??0},{margin:0,hitInside:!0})){m=x.id;break}}const y=g.parentId;if(m===g.id&&(m=s),m!==y&&(g={...g},g.parentId=m,ys(m))){const v=this.getPointInShapeSpace(this.getShape(m),{x:g.x??0,y:g.y??0});g.x=v.x,g.y=v.y,g.rotation=-this.getShapePageTransform(m).rotation()+(g.rotation??0)}}return g}),a=new Map,l=[],{opacityForNextShape:c}=this.getInstanceState();for(const g of o){const m=this.getShapeUtil(g);let y=g.index;if(!y){const C=g.parentId??s;a.has(C)||a.set(C,this.getHighestIndexForParent(C)),y=a.get(C),a.set(C,Oo(y))}const v=m.getDefaultProps();for(const[C,E]of this.styleProps[g.type])v[E]=this.getStyleForNextShape(C);let x=this.store.schema.types.shape.create({...g,index:y,opacity:g.opacity??c,parentId:g.parentId??s,props:"props"in g?{...v,...g.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(g=>{g.meta={...this.getInitialMetaForShape(g),...g.meta}}),this.store.put(l)}),this}animateShape(e,t={animation:aC}){return this.animateShapes([e],t)}animateShapes(e,t={animation:aC}){if(!t.animation)return this;const{duration:r=500,easing:s=Un.linear}=t.animation,i=Tt();let o=r,a;const l=[];let c,d;for(let g=0,m=e.length;g<m;g++){if(c=e[g],!c)continue;const y=this.getShape(c.id);y&&(d={start:Xt(y),end:bo(Xt(y),c)},l.push(d),this.animatingShapes.set(y.id,i))}const f=g=>{var x,b;if(o-=g,o<0){const{animatingShapes:C}=this,E=e.filter(_=>_&&C.get(_.id)===i);E.length&&this.updateShapes(E),this.off("tick",f);return}a=s(1-o/r);const{animatingShapes:m}=this,y=[];let v;for(let C=0,E=l.length;C<E;C++){const{start:_,end:M}=l[C];v=m.get(_.id),v===i&&y.push({...M,x:_.x+(M.x-_.x)*a,y:_.y+(M.y-_.y)*a,opacity:_.opacity+(M.opacity-_.opacity)*a,rotation:_.rotation+(M.rotation-_.rotation)*a,props:((b=(x=this.getShapeUtil(M)).getInterpolatedProps)==null?void 0:b.call(x,_,M,a))??M.props})}this._updateShapes(y)};return this.on("tick",f),this}groupShapes(e,t={}){var y;const{groupId:r=jt(),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=rt((this._shouldIgnoreShapeLock?i:this._getUnlockedShapeIds(i)).map(v=>this.getShape(v))),a=o.sort(tr).map(v=>v.id),l=ye.Common(rt(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 g=o.filter(v=>v.parentId===f).sort(tr),m=(y=g[g.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=rt((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 g=0,m=f.length;g<m;g++)o.add(f[g]);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=bo(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,Cn(e.props,s))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),t=new pk;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 Cn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),t=new pk;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 Xj(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 g=this.getAsset(f);g&&l.push(g)}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=Xt(r),l=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await Ur.blobToDataUrl(await Gi(l).then(c=>c.blob())),t.push(a)}else t.push(r)})),e.assets=t,e}putContentOntoCurrentPage(e,t={}){var U,G,z;if(this.getIsReadonly())return this;if(!e.schema)throw Error(`Could not put content:
209
+ 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=[],g={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(g);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,jt()])),v=new Map(s?f.map(N=>[N.id,N.id]):f.map(N=>[N.id,qc()]));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 Z=L?V.length+1:V.length;if(Z<b)b=Z,C=V,x=L?N.id:N.parentId;else if(Z===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 E=!1;if(!ps(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)&&(E=!0)}}else x=a}E||(E=y.has(x)),E&&(x=this.getShape(x).parentId);let _=this.getHighestIndexForParent(x);const M=[],A=d.map(N=>{const L=y.get(N.id),V={...N,id:L};return l.includes(N.id)&&(V.parentId=a,M.push(V)),y.has(V.parentId)?V.parentId=y.get(N.parentId):(l.push(V.id),V.index=_,_=Oo(_)),V});if(A.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return _m(this),this;const O=f.map(N=>({...N,id:Fr(v.get(N.id)),fromId:Fr(y.get(N.fromId)),toId:Fr(y.get(N.toId))})),D=[],B=[];for(const N of c)this.store.has(N.id)||((N.type==="image"&&((G=N.props.src)!=null&&G.startsWith("data:image"))||N.type==="video"&&((z=N.props.src)!=null&&z.startsWith("data:video")))&&(B.push(Xt(N)),N.props.src=null),D.push(N));return Promise.allSettled(B.map(async N=>{const L=await fie(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(()=>{D.length>0&&this.createAssets(D),this.createShapes(A),this.createBindings(O),r&&this.select(...M.map(W=>W.id)),x!==a&&this.reparentShapes(M.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(ps(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(M.length===1){const W=M[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(rt(M.map(({id:W})=>this.getShapePageBounds(W)))).center,Z=k.Sub(o,V);this.updateShapes(M.map(({id:W})=>{const $=this.getShape(W),Y=this.getShapeParentTransform(W).decompose().rotation,re=k.Rot(Z,-Y);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 sie(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 uie(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:_n(r.format)}}_updateInputsFromEvent(e){const{pointerVelocity:t,previousScreenPoint:r,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:o}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(zr),{x:l,y:c,z:d}=um(()=>this.getCamera()),f=e.point.x-a.x,g=e.point.y-a.y,m=e.point.z??.5;r.setTo(i),s.setTo(o),i.set(f,g);const y=f/d-l,v=g/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:pS,typeName:"pointer",x:o.x,y:o.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===hj.CAMERA_MOVE?((x=this.store.unsafeGetWithoutCapture(pS))==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 cse(this.store)}loadSnapshot(e,t){return vz(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=rt(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:_n(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(mie(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",gie((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=f0(o=>o(),(e==null?void 0:e.debounceMs)??500),i=Yi("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:Pr(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:Pr(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:Pr(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:Pr(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(zr),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:g,y:m}=k.SubXY(e.point,o.screenBounds.x,o.screenBounds.y);this.stopCameraAnimation(),o.followingUserId&&this.stopFollowingUser();const{x:y,y:v,z:x}=um(()=>this.getCamera()),{panSpeed:b}=l;this._setCamera(new k(y+d*b/x-g/x+g/c,v+f*b/x-m/x+m/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:g,y:m,z:y}=um(()=>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:E,y:_}=this.inputs.currentScreenPoint;let M=b;f==="zoom"&&(Math.abs(x)>10?M=10*Math.sign(x)/100:M=x/100);const A=y+(M??0)*d*y;this._setCamera(new k(g+E/A-E/y,m+_/A-_/y,A),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new k(g+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===fj&&(this.capturedPointerId=e.pointerId),t.buttons.add(e.button),t.isPointing=!0,t.isDragging=!1,!d&&c&&this.updateInstanceState({isPenMode:!0}),e.button===pj?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===bm&&(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:g,z:m}=um(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:y,previousScreenPoint:v}=this.inputs,{panSpeed:x}=l,b=k.Sub(y,v);this.setCamera(new k(f+b.x*x/m,g+b.y*x/m,m),{immediate:!0}),this.maybeTrackPerformance("Panning");return}t.isPointing&&!t.isDragging&&k.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,g=Math.min(2,f.len());switch(e.button){case fj:{this.setCursor({type:"grab",rotation:0});break}case bm:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}g>0&&this.slideCamera({speed:g,direction:f})}else e.button===pj&&(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 k(0,-1);break}case"ArrowRight":{c=new k(1,0);break}case"ArrowDown":{c=new k(0,1);break}case"ArrowLeft":{c=new k(-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(bm)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===bm?e.name="middle_click":e.button===DE&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(zr);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){bn.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}Ie=zoe(mk);Ee(Ie,1,"getIsShapeHiddenCache",S6,ke);Ee(Ie,1,"getCanUndo",y6,ke);Ee(Ie,1,"getCanRedo",m6,ke);Ee(Ie,1,"getPath",g6,ke);Ee(Ie,1,"getCurrentTool",p6,ke);Ee(Ie,1,"getCurrentToolId",f6,ke);Ee(Ie,1,"getDocumentSettings",h6,ke);Ee(Ie,1,"getInstanceState",d6,ke);Ee(Ie,1,"getOpenMenus",u6,ke);Ee(Ie,1,"getIsMenuOpen",c6,ke);Ee(Ie,1,"getPageStates",l6,ke);Ee(Ie,1,"_getPageStatesQuery",a6,ke);Ee(Ie,1,"getCurrentPageState",o6,ke);Ee(Ie,1,"_getCurrentPageStateId",i6,ke);Ee(Ie,1,"getSelectedShapeIds",s6,ke);Ee(Ie,1,"getSelectedShapes",r6,ke);Ee(Ie,1,"getOnlySelectedShapeId",n6,ke);Ee(Ie,1,"getOnlySelectedShape",t6,ke);Ee(Ie,1,"getSelectionPageBounds",e6,ke);Ee(Ie,1,"getSelectionRotation",QB,ke);Ee(Ie,1,"getSelectionRotatedPageBounds",JB,ke);Ee(Ie,1,"getSelectionRotatedScreenBounds",ZB,ke);Ee(Ie,1,"getFocusedGroupId",XB,ke);Ee(Ie,1,"getFocusedGroup",YB,ke);Ee(Ie,1,"getEditingShapeId",GB,ke);Ee(Ie,1,"getEditingShape",qB,ke);Ee(Ie,1,"getRichTextEditor",VB,ke);Ee(Ie,1,"getHoveredShapeId",WB,ke);Ee(Ie,1,"getHoveredShape",KB,ke);Ee(Ie,1,"getHintingShapeIds",HB,ke);Ee(Ie,1,"getHintingShape",UB,ke);Ee(Ie,1,"getErasingShapeIds",BB,ke);Ee(Ie,1,"getErasingShapes",$B,ke);Ee(Ie,1,"_unsafe_getCameraId",zB,ke);Ee(Ie,1,"getCamera",FB,ke);Ee(Ie,1,"getViewportPageBoundsForFollowing",LB,ke);Ee(Ie,1,"getCameraForFollowing",NB,ke);Ee(Ie,1,"getZoomLevel",jB,ke);Ee(Ie,1,"getViewportScreenBounds",DB,ke);Ee(Ie,1,"getViewportScreenCenter",RB,ke);Ee(Ie,1,"getViewportPageBounds",OB,ke);Ee(Ie,1,"_getCollaboratorsQuery",AB,ke);Ee(Ie,1,"getCollaborators",MB,ke);Ee(Ie,1,"getCollaboratorsOnCurrentPage",TB,ke);Ee(Ie,1,"getRenderingShapes",_B,ke);Ee(Ie,1,"_getAllPagesQuery",EB,ke);Ee(Ie,1,"getPages",IB,ke);Ee(Ie,1,"getCurrentPageId",kB,ke);Ee(Ie,1,"getCurrentPageShapeIdsSorted",PB,ke);Ee(Ie,1,"_getAllAssetsQuery",CB,ke);Ee(Ie,1,"_getShapeHandlesCache",bB,ke);Ee(Ie,1,"_getShapePageTransformCache",wB,ke);Ee(Ie,1,"_getShapePageBoundsCache",xB,ke);Ee(Ie,1,"_getShapeClipPathCache",vB,ke);Ee(Ie,1,"_getShapeMaskCache",SB,ke);Ee(Ie,1,"_getShapeMaskedPageBoundsCache",yB,ke);Ee(Ie,1,"_notVisibleShapes",mB,ke);Ee(Ie,1,"getCulledShapes",gB,ke);Ee(Ie,1,"getCurrentPageBounds",pB,ke);Ee(Ie,1,"getCurrentPageShapes",fB,ke);Ee(Ie,1,"getCurrentPageShapesSorted",hB,ke);Ee(Ie,1,"getCurrentPageRenderingShapesSorted",dB,ke);Ee(Ie,1,"_getBindingsIndexCache",uB,ke);Ee(Ie,1,"_getSelectionSharedStyles",cB,ke);Ee(Ie,1,"getSharedStyles",lB,ke);Ee(Ie,1,"getSharedOpacity",aB,ke);Ee(Ie,1,"getIsFocused",oB,ke);Ee(Ie,1,"getIsReadonly",iB,ke);Ee(Ie,1,"_setShiftKeyTimeout",sB,ke);Ee(Ie,1,"_setAltKeyTimeout",rB,ke);Ee(Ie,1,"_setCtrlKeyTimeout",nB,ke);Ee(Ie,1,"_setMetaKeyTimeout",tB,ke);Boe(Ie,ke);function _m(n,e=n.getCurrentPageId()){const t=n.getPage(e).name;n.emit("max-shapes",{name:t,pageId:e,count:n.options.maxShapesPerPage})}function bo(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 v6(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++)v6(n,s[i],t)}function Xj(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=Lr.ok(t(i))}catch(a){r=Lr.err(a)}});n.store.applyDiff(nk(s),{runCallbacks:!1})},{history:"ignore"}),r.ok)return r.value;throw r.error}function Zj(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 Vp(){const n=Q(),e=Up();return ie("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??n.user.getIsDarkMode(),[e,n])}const Jj="<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'/>",Qj="<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'/>",Tm='<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 gl(n,e,t,r,s,i=16,o=16){const a=(-t-e)*(wt/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 Hoe=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],Koe={none:()=>"none","ew-resize":(n,e,t)=>gl(Qj,n,0,e,t),"ns-resize":(n,e,t)=>gl(Qj,n,90,e,t),"nesw-resize":(n,e,t)=>gl(Jj,n,0,e,t),"nwse-resize":(n,e,t)=>gl(Jj,n,90,e,t),"nwse-rotate":(n,e,t)=>gl(Tm,n,0,e,t),"nesw-rotate":(n,e,t)=>gl(Tm,n,90,e,t),"senw-rotate":(n,e,t)=>gl(Tm,n,180,e,t),"swne-rotate":(n,e,t)=>gl(Tm,n,270,e,t)};function zs(n,e=0,t="black"){return Koe[n](kG(e),!1,t)}function Woe(){const n=Q(),e=Mn(),t=Vp();_a("useCursor",()=>{const{type:r,rotation:s}=n.getInstanceState().cursor;if(Hoe.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",zs(r,s,t?"white":"black"))},[n,e,t])}function Voe(){const n=Q(),e=Mn(),t=Vp(),r=ie(bn.forceSrgb);ot.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 qoe(){const[n,e]=P.useState(0);P.useEffect(()=>e(t=>t+1),[])}const Goe=n=>n.props.src,Yoe={upload:async(n,e)=>({src:await Ur.blobToDataUrl(e)})};function Xoe(n){return"schema"in n&&n.schema?n.schema:Ete({shapes:"shapeUtils"in n&&n.shapeUtils?eN(Cz(n.shapeUtils)):void 0,bindings:"bindingUtils"in n&&n.bindingUtils?eN(wz(n.bindingUtils)):void 0,migrations:"migrations"in n?n.migrations:void 0})}function fp({initialData:n,defaultName:e="",id:t,assets:r=Yoe,onMount:s,collaboration:i,...o}={}){const a=Xoe(o),l=new SE({id:t,schema:a,initialData:n,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??Goe,remove:r.remove??(()=>Promise.resolve())},onMount:c=>{tt(c instanceof ke),s==null||s(c)},collaboration:i}});if(o.snapshot){if(n)throw new Error("Cannot provide both initialData and snapshot");vz(l,o.snapshot,{forceOverwriteSessionState:!0})}return l}function eN(n){return Object.fromEntries(n.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}function Zoe(){window.alert(`Oops! We could not save changes to your browser's storage. 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.
213
+ • If your hard disk is full, try clearing up some space and then reload the page.`)}function Joe(){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.
214
+
215
+ Keep seeing this message?
216
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const Qoe=350,eae=1e4,tN=Symbol("UPDATE_INSTANCE_STATE"),tae=n=>n;class nae{constructor(e){R(this,"onmessage")}postMessage(e){}close(){}}const rae=typeof BroadcastChannel>"u"?nae:BroadcastChannel;class sae{constructor(e,{persistenceKey:t,sessionId:r=xS,onLoad:s,onLoadError:i},o=new rae(`tldraw-tab-sync-${t}`)){R(this,"disposables",new Set);R(this,"diffQueue",[]);R(this,"didDispose",!1);R(this,"shouldDoFullDBWrite",!0);R(this,"isReloading",!1);R(this,"persistenceKey");R(this,"sessionId");R(this,"serializedSchema");R(this,"isDebugging",!1);R(this,"documentTypes");R(this,"$sessionStateSnapshot");R(this,"db");R(this,"initTime",Date.now());R(this,"isPersisting",!1);R(this,"didLastWriteError",!1);R(this,"scheduledPersistTimeout",null);this.store=e,this.channel=o,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.db=new iS(t),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=zE(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(tae({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(tN),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),Joe();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??lse(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&&uk(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"),Ps(()=>{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?eae:Qoe))}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(tt(!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=yE(e.filter(r=>r!==tN));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),Zoe(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function x6(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 iae(n){const[e,t]=x6({status:"loading"});return n=uh(n),P.useEffect(()=>{const{persistenceKey:r,sessionId:s,...i}=n;if(!r){t({status:"not-synced",store:fp(i)});return}t({status:"loading"});const o=new qo,a={upload:async(f,g)=>(await d.db.storeAsset(f.id,g),{src:f.id}),resolve:async f=>f.props.src?f.props.src.startsWith("asset:")?await o.get(f,async()=>{const g=await d.db.getAsset(f.id);return g?URL.createObjectURL(g):null}):f.props.src:null,remove:async f=>{await d.db.removeAssets(f)},...i.assets},l=fp({...i,assets:a});let c=!1;const d=new sae(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 oae(){const n=Q(),e=Mn();P.useEffect(()=>{const t=i=>e.style.setProperty("--tl-zoom",i.toString()),r=f0(t,100),s=new gu("useZoomCss",()=>{n.getCurrentPageShapeIds().size<300?t(n.getZoomLevel()):r(n.getZoomLevel())});return s.attach(),s.execute(),()=>{s.detach(),r.cancel()}},[n,e])}function yk(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 aae(n){const e=atob(n),t=yk(e);return crypto.subtle.importKey("spki",new Uint8Array(t),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const lae=5,Pf={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},cae=Math.max(...Object.values(Pf)),kf={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},uae=Object.keys(kf).length,xC="sales@tldraw.com",dae=`${En()}/watermarks/watermark-track.svg`;class iv{constructor(e,t,r){R(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");R(this,"isDevelopment");R(this,"isTest");R(this,"isCryptoAvailable");R(this,"state",ln("license state","pending"));R(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=hae(s);!this.isDevelopment&&i&&Gi(dae),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 aae(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,new Uint8Array(yk(atob(r))),new Uint8Array(yk(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>uae&&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[kf.ID],hosts:l[kf.HOSTS],flags:l[kf.FLAGS],expiryDate:l[kf.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,Pf.ANNUAL_LICENSE),o=this.isFlagEnabled(r.flags,Pf.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,Pf.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,Pf.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()+lae+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 ${xC} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const t=this.getExpirationDateWithGracePeriod(e),r={major:new Date(uj.major),minor:new Date(uj.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 ${xC} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${xC} if you would like to use tldraw on other domains.`]),e.license.flags>=cae*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;")}}R(iv,"className","tl-watermark_SEE-LICENSE");function hae(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 w6=P.createContext({}),fae=()=>P.useContext(w6);function pae({licenseKey:n,children:e}){const[t]=P.useState(()=>new iv(n));return p.jsx(w6.Provider,{value:t,children:e})}function Ka(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=Mn();P.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;const i=n.current;if(i&&i.scrollHeight>i.clientHeight)return;et(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 gae='<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>',mae='<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 yae(n){return ie("watermarkState",()=>n.state.get(),[n])}const Sae=`data:image/svg+xml;utf8,${encodeURIComponent(gae)}`,vae=`data:image/svg+xml;utf8,${encodeURIComponent(mae)}`,xae=P.memo(function(){const e=fae(),t=Q(),r=ie("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),s=yae(e);return["licensed-with-watermark","unlicensed"].includes(s)?p.jsxs(p.Fragment,{children:[p.jsx(bae,{}),p.jsx(wae,{src:r?vae:Sae})]}):null}),wae=P.memo(function({src:e}){const t=Q(),r=ie("debug mode",()=>t.getInstanceState().isDebugMode,[t]),s=ie("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),i=jE(),o=P.useRef(null);Ka(o);const a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark";return p.jsx("div",{ref:o,className:iv.className,"data-debug":r,"data-mobile":s,draggable:!1,...i,children:kt.isWebview?p.jsx("a",{draggable:!1,role:"button",onPointerDown:c=>{Zt(c),et(c)},onClick:()=>G0.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}}):p.jsx("a",{href:l,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:c=>{Zt(c)},style:{mask:a,WebkitMask:a}})})}),bae=P.memo(function(){const e=Q(),t=iv.className,r=`/* ------------------- SEE LICENSE -------------------
217
+ The tldraw watermark is part of tldraw's license. It is shown for unlicensed
218
+ or "licensed-with-watermark" users. By using this library, you agree to
219
+ preserve the watermark's behavior, keeping it visible, unobscured, and
220
+ available to user-interaction.
221
+
222
+ To remove the watermark, please purchase a license at tldraw.dev.
223
+ */
224
+
225
+ .${t} {
226
+ position: absolute;
227
+ bottom: var(--space-2);
228
+ right: var(--space-2);
229
+ width: 96px;
230
+ height: 32px;
231
+ display: flex;
232
+ align-items: center;
233
+ justify-content: center;
234
+ z-index: var(--layer-watermark) !important;
235
+ background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
236
+ opacity: 1;
237
+ border-radius: 5px;
238
+ pointer-events: all;
239
+ padding: 2px;
240
+ box-sizing: content-box;
241
+ }
242
+
243
+ .${t} > a {
244
+ position: absolute;
245
+ width: 96px;
246
+ height: 32px;
247
+ pointer-events: all;
248
+ cursor: inherit;
249
+ color: var(--color-text);
250
+ opacity: .38;
251
+ background-color: currentColor;
252
+ }
253
+
254
+ .${t}[data-debug='true'] {
255
+ bottom: 46px;
256
+ }
257
+
258
+ .${t}[data-mobile='true'] {
259
+ border-radius: 4px 0px 0px 4px;
260
+ right: -2px;
261
+ width: 8px;
262
+ height: 48px;
263
+ }
264
+
265
+ .${t}[data-mobile='true'] > a {
266
+ width: 8px;
267
+ height: 32px;
268
+ }
269
+
270
+ @media (hover: hover) {
271
+ .${t} > a {
272
+ pointer-events: none;
273
+ }
274
+
275
+ .${t}:hover {
276
+ background-color: var(--color-background);
277
+ transition: background-color 0.2s ease-in-out;
278
+ transition-delay: 0.32s;
279
+ }
280
+
281
+ .${t}:hover > a {
282
+ animation: delayed_link 0.2s forwards ease-in-out;
283
+ animation-delay: 0.32s;
284
+ }
285
+
286
+ .${t} > a:focus-visible {
287
+ opacity: 1;
288
+ }
289
+ }
290
+
291
+
292
+ @keyframes delayed_link {
293
+ 0% {
294
+ cursor: inherit;
295
+ opacity: .38;
296
+ pointer-events: none;
297
+ }
298
+ 100% {
299
+ cursor: pointer;
300
+ opacity: 1;
301
+ pointer-events: all;
302
+ }
303
+ }`;return p.jsx("style",{nonce:e.options.nonce,children:r})}),Cae=[],Pae=[],kae=[],Iae="tl-container",Eae=P.memo(function({store:e,components:t,className:r,user:s,options:i,...o}){const[a,l]=P.useState(null),c=P.useMemo(()=>s??mz(),[s]),d=(t==null?void 0:t.ErrorFallback)===void 0?az:t==null?void 0:t.ErrorFallback,f={...o,shapeUtils:o.shapeUtils??Cae,bindingUtils:o.bindingUtils??Pae,tools:o.tools??kae,components:t,options:uh(i)};return p.jsx("div",{ref:l,"data-tldraw":j4,draggable:!1,className:ze(`${Iae} tl-theme__light`,r),onPointerDown:Zt,tabIndex:-1,children:p.jsx(hp,{fallback:d,onError:g=>pI(g,{tags:{origin:"react.tldraw-before-app"}}),children:a&&p.jsx(pae,{licenseKey:o.licenseKey,children:p.jsx($4,{container:a,children:p.jsx(qre,{overrides:t,children:e?e instanceof SE?p.jsx(C6,{...f,store:e,user:c}):p.jsx(b6,{...f,store:e,user:c}):p.jsx(_ae,{...f,store:e,user:c})})})})})})});function _ae(n){const{defaultName:e,snapshot:t,initialData:r,shapeUtils:s,bindingUtils:i,persistenceKey:o,sessionId:a,user:l,assets:c,migrations:d}=n,f=iae({shapeUtils:s,bindingUtils:i,initialData:r,persistenceKey:o,sessionId:a,defaultName:e,snapshot:t,assets:c,migrations:d});return p.jsx(b6,{...n,store:f,user:l})}const b6=P.memo(function({store:e,user:t,...r}){const s=Mn();P.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,t]);const{LoadingScreen:i}=Jt();switch(e.status){case"error":throw e.error;case"loading":return i?p.jsx(i,{}):null}return p.jsx(C6,{...r,store:e.store,user:t})}),wC=()=>document.location.search.includes("tldraw_preserve_focus");function C6({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:g,licenseKey:m,deepLinks:y,isShapeHidden:v,assetUrls:x}){const{ErrorFallback:b}=Jt(),C=Mn(),[E,_]=x6(null),M=P.useRef(null),A=uh(y===!0?{}:y),O=P.useRef({autoFocus:l&&!wC(),inferDarkMode:c,initialState:a,cameraOptions:d,deepLinks:A});P.useLayoutEffect(()=>{O.current={autoFocus:l&&!wC(),inferDarkMode:c,initialState:a,cameraOptions:d,deepLinks:A}},[l,c,a,d,A]),P.useLayoutEffect(()=>{const{autoFocus:L,inferDarkMode:V,initialState:Z,cameraOptions:W,deepLinks:$}=O.current,Y=new ke({store:t,shapeUtils:s,bindingUtils:i,tools:r,getContainer:()=>C,user:o,initialState:Z,autoFocus:L,inferDarkMode:V,cameraOptions:W,textOptions:f,options:g,licenseKey:m,isShapeHidden:v,fontAssetUrls:x==null?void 0:x.fonts});return Y.updateViewportScreenBounds(M.current??C),$&&($!=null&&$.getUrl?Y.navigateToDeepLink({...$,url:$.getUrl(Y)}):Y.navigateToDeepLink($)),_(Y),()=>{Y.dispose()}},[i,C,g,s,t,r,o,_,m,v,f,x]),P.useLayoutEffect(()=>{if(E&&A)return E.registerDeepLinkListener(A)},[E,A]),P.useLayoutEffect(()=>{E&&d&&E.setCameraOptions(d)},[E,d]);const D=P.useSyncExternalStore(P.useCallback(L=>E?(E.on("crash",L),()=>E.off("crash",L)):()=>{},[E]),()=>(E==null?void 0:E.getCrashingError())??null);P.useEffect(function(){if(!E)return;function V(){E&&E.focus()}function Z(){E&&E.blur()}if(l&&wC())return E.getContainer().addEventListener("pointerdown",V),document.body.addEventListener("pointerdown",Z),()=>{var W;(W=E.getContainer())==null||W.removeEventListener("pointerdown",V),document.body.removeEventListener("pointerdown",Z)}},[E,l]);const[B,U]=P.useState(null);let G=B;E!==(G==null?void 0:G.editor)&&(G=null),P.useEffect(()=>{if(!E)return;let L=!1;return U({editor:E,isLoaded:!1}),E.fonts.loadRequiredFontsForCurrentPage(E.options.maxFontsToLoadBeforeRender).finally(()=>{L||U({editor:E,isLoaded:!0})}),()=>{L=!0}},[E]);const{Canvas:z,LoadingScreen:N}=Jt();return!E||!(G!=null&&G.isLoaded)?p.jsxs(p.Fragment,{children:[N&&p.jsx(N,{}),p.jsx("div",{className:"tl-canvas",ref:M})]}):p.jsx(hp,{fallback:b,onError:L=>E.annotateError(L,{origin:"react.tldraw",willCrashApp:!0}),children:D?p.jsx(Mae,{crashingError:D}):p.jsx(RE,{editor:E,children:p.jsxs(Tae,{onMount:n,children:[e??(z?p.jsx(z,{},E.contextId):null),p.jsx(xae,{})]})})})}function Tae({children:n,onMount:e}){return oae(),Woe(),Voe(),qoe(),P6(t=>{const r=t.store.props.onMount(t),s=e==null?void 0:e(t);return()=>{r==null||r(),s==null||s()}}),n}function Mae({crashingError:n}){throw n}function Aae({children:n}){return p.jsx("div",{className:"tl-loading",children:n})}function P6(n){const e=Q(),t=Pa(r=>{let s;return r.run(()=>{s=n==null?void 0:n(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});ot.useLayoutEffect(()=>{if(e)return t==null?void 0:t(e)},[e,t])}function zl({children:n,className:e="",...t}){return p.jsx("div",{...t,className:ze("tl-html-container",e),children:n})}class uy{constructor(e){this.editor=e}}R(uy,"props"),R(uy,"migrations"),R(uy,"type");function ov(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,g=n.props.h*o;const m=new k(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(g>0){if(g<c){switch(s){case"top_left":case"top":case"top_right":{m.y=g-c;break}case"right":case"left":{m.y=(g-c)/2;break}default:m.y=0}g=c}}else if(m.y=g,g=-g,g<c){switch(s){case"top_left":case"top":case"top_right":{m.y=-g;break}default:m.y=-c}g=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,g)}}}class gh extends Ji{getGeometry(e){return new Uo({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return ov(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,r){return{...t.props,w:St(e.props.w,t.props.w,r),h:St(e.props.h,t.props.h,r)}}}var nP;let Oae=(nP=class extends Ne{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},R(nP,"id","idle"),nP);var rP;let Rae=(rP=class extends Ne{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=this.parent.shapeType,s=jt(),i=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),o=eo(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=jt();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 k(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=Xt(s),f=eo(new k(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")}},R(rP,"id","pointing"),rP);function eo(n,e){const t=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return t?n.clone().snapToGrid(r):n.clone()}class Sk extends Ne{static children(){return[Oae,Rae]}}R(Sk,"id","box"),R(Sk,"initial","idle");function Dae(n,e,t){const r=P.useRef(!1),s=P.useCallback(o=>{r.current=o,o?$r.addOpenMenu(n):$r.deleteOpenMenu(n),e==null||e(o)},[n,e]),i=ie("is menu open",()=>$r.getOpenMenus().includes(n),[n]);return P.useEffect(()=>(r.current&&(t==null||t("open-menu"),$r.addOpenMenu(n)),()=>{r.current&&($r.deleteOpenMenu(n),$r.getOpenMenus().forEach(o=>{o.startsWith(n)&&(t==null||t("close-menu"),$r.deleteOpenMenu(o))}),r.current=!1)}),[n,t]),[i,s]}function av(n){const e=Q();return ie("isEditing",()=>e.getEditingShapeId()===n,[e,n])}function jae(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=Mn();P.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;et(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 ko(n){const e=Q();return P.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===DE){e.dispatch({type:"pointer",target:"selection",handle:n,name:"right_click",...Hs(c)});return}if(c.button!==0)return;const d=SS(c.currentTarget);function f(){d.removeEventListener("pointerup",f),Fp(d,c)}Lp(d,c),d.addEventListener("pointerup",f),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:n,...Hs(c)}),Zt(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,...Hs(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:n,...Hs(c)})}}},[e,n])}function Nae(n){const[e,t]=P.useState(()=>({store:fp(n),opts:n}));if(!GL(e.opts,n)){const r={store:fp(n),opts:n};return t(r),r.store}return e.store}const Lae=20,Fae=8;function JE(n,e=Lae){return Math.max(Fae,Math.ceil(n/e))}class kd extends nc{constructor(t){super({...t,isFilled:!1,isClosed:!1});R(this,"_center");R(this,"radius");R(this,"start");R(this,"end");R(this,"largeArcFlag");R(this,"sweepFlag");R(this,"measure");R(this,"angleStart");R(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=k.Angle(r,o),this.angleEnd=k.Angle(r,a),this.radius=k.Dist(r,o),this.measure=IG(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=TP(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 g,m=1/0,y;for(const v of[l,c,f])y=k.Dist2(t,v),y<m&&(g=v,m=y);if(!g)throw Error("nearest point not found");return g}hitTestLineSegment(t,r){const{_center:s,radius:i,measure:o,angleStart:a,angleEnd:l}=this,c=Bp(t,r,s,i);return c===null?!1:c.some(d=>{const f=TP(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=JE(Math.abs(s));l<c+1;l++){const d=l/c*r,f=o+d;a.push(Yc(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 QE extends nc{constructor(t){super({isClosed:!0,...t});R(this,"_center");R(this,"radius");R(this,"x");R(this,"y");this.config=t;const{x:r=0,y:s=0,radius:i}=t;this.x=r,this.y=s,this._center=new k(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=Dt*r,i=[];for(let o=0,a=JE(s);o<a;o++){const l=o/a*Dt;i.push(Yc(t,r,l))}return i}nearestPoint(t){const{_center:r,radius:s}=this;return r.equals(t)?k.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 Bp(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 Cr extends dh{constructor(t){const{start:r,cp1:s,cp2:i,end:o}=t;super({...t,points:[r,o]});R(this,"a");R(this,"b");R(this,"c");R(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 k((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 Cr.GetAtT(this,.5)}nearestPoint(t){let r,s=1/0,i,o;for(const a of this.segments)o=a.nearestPoint(t),i=k.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 k((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=Cr.GetAtT(this,o/t),i+=k.Dist(s,r),s=r;return i}}class zae extends nc{constructor(t){super({...t,isClosed:!1,isFilled:!1});R(this,"points");R(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,g=o===0?a:new k(l.x+(c.x-a.x)/6*i,l.y+(c.y-a.y)/6*i),m=o===s?c:new k(c.x-(d.x-l.x)/6*i,c.y-(d.y-l.y)/6*i),y=c;this._segments.push(new Cr({start:f,cp1:g,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=k.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 $ae extends nc{constructor(t){super({...t,isClosed:!0});R(this,"w");R(this,"h");R(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 Ia({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=wt*(s+i)*(1+3*o/(10+Math.sqrt(4-3*o))),l=JE(a),c=Dt/l,d=Math.cos(c),f=Math.sin(c);let g=0,m=1,y=0,v=1;const x=Array(l);for(let b=0;b<l;b++)x[b]=new k(s+s*m,i+i*g),y=f*m+d*g,v=d*m-f*g,g=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=k.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 G3(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 Bae extends nc{constructor(t){super({...t,isClosed:!0});R(this,"w");R(this,"h");R(this,"a");R(this,"b");R(this,"c");R(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 kd({start:new k(0,i),end:new k(r,i),center:new k(r/2,i),sweepFlag:1,largeArcFlag:1}),this.b=new Ia({start:new k(r,i),end:new k(r,s-i)}),this.c=new kd({start:new k(r,s-i),end:new k(0,s-i),center:new k(r/2,s-i),sweepFlag:1,largeArcFlag:1}),this.d=new Ia({start:new k(0,s-i),end:new k(0,i)})}else{const i=s/2;this.a=new kd({start:new k(i,s),end:new k(i,0),center:new k(i,i),sweepFlag:1,largeArcFlag:1}),this.b=new Ia({start:new k(i,0),end:new k(r-i,0)}),this.c=new kd({start:new k(r-i,0),end:new k(r-i,s),center:new k(r-i,i),sweepFlag:1,largeArcFlag:1}),this.d=new Ia({start:new k(r-i,s),end:new k(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=k.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?(wt*(r/2)+(t-r))*2:(wt*(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 Uae({shouldReload:n=!0}={}){YV();for(const e of iS.connectedInstances)await e.close();await Promise.all(lE().map(e=>z5(e))),GV(),n&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Uae);function Hae(n,e="_blank"){G0.openWindow(n,e)}Yl("@tldraw/editor","3.11.1","esm");function k6(){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 I6=()=>{},E6=P.createContext(null);function Kae({onEvent:n,children:e}){return p.jsx(E6.Provider,{value:n??I6,children:e})}function jn(){return P.useContext(E6)??I6}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 Wae(n,e){const t=P.createContext(e),r=i=>{const{children:o,...a}=i,l=P.useMemo(()=>a,Object.values(a));return p.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 Xo(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:g,children:m,...y}=f,v=((b=g==null?void 0:g[n])==null?void 0:b[l])||a,x=P.useMemo(()=>y,Object.values(y));return p.jsx(v.Provider,{value:x,children:m})};c.displayName=i+"Provider";function d(f,g){var v;const m=((v=g==null?void 0:g[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,Vae(s,...e)]}function Vae(...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 nN(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function lv(...n){return e=>{let t=!1;const r=n.map(s=>{const i=nN(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():nN(n[s],null)}}}}function Wt(...n){return P.useCallback(lv(...n),n)}function Yd(n){const e=qae(n),t=P.forwardRef((r,s)=>{const{children:i,...o}=r,a=P.Children.toArray(i),l=a.find(Yae);if(l){const c=l.props.children,d=a.map(f=>f===l?P.Children.count(c)>1?P.Children.only(null):P.isValidElement(c)?c.props.children:null:f);return p.jsx(e,{...o,ref:s,children:P.isValidElement(c)?P.cloneElement(c,void 0,d):null})}return p.jsx(e,{...o,ref:s,children:i})});return t.displayName=`${n}.Slot`,t}function qae(n){const e=P.forwardRef((t,r)=>{const{children:s,...i}=t;if(P.isValidElement(s)){const o=Zae(s),a=Xae(i,s.props);return s.type!==P.Fragment&&(a.ref=r?lv(r,o):o),P.cloneElement(s,a)}return P.Children.count(s)>1?P.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var Gae=Symbol("radix.slottable");function Yae(n){return P.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===Gae}function Xae(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 Zae(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 Jae=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],bt=Jae.reduce((n,e)=>{const t=Yd(`Primitive.${e}`),r=P.forwardRef((s,i)=>{const{asChild:o,...a}=s,l=o?t:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),p.jsx(l,{...a,ref:i})});return r.displayName=`Primitive.${e}`,{...n,[e]:r}},{});function e_(n,e){n&&hh.flushSync(()=>n.dispatchEvent(e))}function cv(n){const e=n+"CollectionProvider",[t,r]=Xo(e),[s,i]=t(e,{collectionRef:{current:null},itemMap:new Map}),o=v=>{const{scope:x,children:b}=v,C=ot.useRef(null),E=ot.useRef(new Map).current;return p.jsx(s,{scope:x,itemMap:E,collectionRef:C,children:b})};o.displayName=e;const a=n+"CollectionSlot",l=Yd(a),c=ot.forwardRef((v,x)=>{const{scope:b,children:C}=v,E=i(a,b),_=Wt(x,E.collectionRef);return p.jsx(l,{ref:_,children:C})});c.displayName=a;const d=n+"CollectionItemSlot",f="data-radix-collection-item",g=Yd(d),m=ot.forwardRef((v,x)=>{const{scope:b,children:C,...E}=v,_=ot.useRef(null),M=Wt(x,_),A=i(d,b);return ot.useEffect(()=>(A.itemMap.set(_,{ref:_,...E}),()=>void A.itemMap.delete(_))),p.jsx(g,{[f]:"",ref:M,children:C})});m.displayName=d;function y(v){const x=i(n+"CollectionConsumer",v);return ot.useCallback(()=>{const C=x.collectionRef.current;if(!C)return[];const E=Array.from(C.querySelectorAll(`[${f}]`));return Array.from(x.itemMap.values()).sort((A,O)=>E.indexOf(A.ref.current)-E.indexOf(O.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:o,Slot:c,ItemSlot:m},y,r]}var Qae=P.createContext(void 0);function t_(n){const e=P.useContext(Qae);return n||e||"ltr"}function cr(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 ele(n,e=globalThis==null?void 0:globalThis.document){const t=cr(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 tle="DismissableLayer",vk="dismissableLayer.update",nle="dismissableLayer.pointerDownOutside",rle="dismissableLayer.focusOutside",rN,_6=P.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),qp=P.forwardRef((n,e)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:o,onDismiss:a,...l}=n,c=P.useContext(_6),[d,f]=P.useState(null),g=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=P.useState({}),y=Wt(e,O=>f(O)),v=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),b=v.indexOf(x),C=d?v.indexOf(d):-1,E=c.layersWithOutsidePointerEventsDisabled.size>0,_=C>=b,M=ile(O=>{const D=O.target,B=[...c.branches].some(U=>U.contains(D));!_||B||(s==null||s(O),o==null||o(O),O.defaultPrevented||a==null||a())},g),A=ole(O=>{const D=O.target;[...c.branches].some(U=>U.contains(D))||(i==null||i(O),o==null||o(O),O.defaultPrevented||a==null||a())},g);return ele(O=>{C===c.layers.size-1&&(r==null||r(O),!O.defaultPrevented&&a&&(O.preventDefault(),a()))},g),P.useEffect(()=>{if(d)return t&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(rN=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),sN(),()=>{t&&c.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=rN)}},[d,g,t,c]),P.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),sN())},[d,c]),P.useEffect(()=>{const O=()=>m({});return document.addEventListener(vk,O),()=>document.removeEventListener(vk,O)},[]),p.jsx(bt.div,{...l,ref:y,style:{pointerEvents:E?_?"auto":"none":void 0,...n.style},onFocusCapture:De(n.onFocusCapture,A.onFocusCapture),onBlurCapture:De(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:De(n.onPointerDownCapture,M.onPointerDownCapture)})});qp.displayName=tle;var sle="DismissableLayerBranch",T6=P.forwardRef((n,e)=>{const t=P.useContext(_6),r=P.useRef(null),s=Wt(e,r);return P.useEffect(()=>{const i=r.current;if(i)return t.branches.add(i),()=>{t.branches.delete(i)}},[t.branches]),p.jsx(bt.div,{...n,ref:s})});T6.displayName=sle;function ile(n,e=globalThis==null?void 0:globalThis.document){const t=cr(n),r=P.useRef(!1),s=P.useRef(()=>{});return P.useEffect(()=>{const i=a=>{if(a.target&&!r.current){let l=function(){M6(nle,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 ole(n,e=globalThis==null?void 0:globalThis.document){const t=cr(n),r=P.useRef(!1);return P.useEffect(()=>{const s=i=>{i.target&&!r.current&&M6(rle,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 sN(){const n=new CustomEvent(vk);document.dispatchEvent(n)}function M6(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?e_(s,i):s.dispatchEvent(i)}var ale=qp,lle=T6,bC=0;function n_(){P.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??iN()),document.body.insertAdjacentElement("beforeend",n[1]??iN()),bC++,()=>{bC===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),bC--}},[])}function iN(){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 CC="focusScope.autoFocusOnMount",PC="focusScope.autoFocusOnUnmount",oN={bubbles:!1,cancelable:!0},cle="FocusScope",uv=P.forwardRef((n,e)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:i,...o}=n,[a,l]=P.useState(null),c=cr(s),d=cr(i),f=P.useRef(null),g=Wt(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(E){if(m.paused||!a)return;const _=E.target;a.contains(_)?f.current=_:wl(f.current,{select:!0})},x=function(E){if(m.paused||!a)return;const _=E.relatedTarget;_!==null&&(a.contains(_)||wl(f.current,{select:!0}))},b=function(E){if(document.activeElement===document.body)for(const M of E)M.removedNodes.length>0&&wl(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){lN.add(m);const v=document.activeElement;if(!a.contains(v)){const b=new CustomEvent(CC,oN);a.addEventListener(CC,c),a.dispatchEvent(b),b.defaultPrevented||(ule(gle(A6(a)),{select:!0}),document.activeElement===v&&wl(a))}return()=>{a.removeEventListener(CC,c),setTimeout(()=>{const b=new CustomEvent(PC,oN);a.addEventListener(PC,d),a.dispatchEvent(b),b.defaultPrevented||wl(v??document.body,{select:!0}),a.removeEventListener(PC,d),lN.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,[E,_]=dle(C);E&&_?!v.shiftKey&&b===_?(v.preventDefault(),t&&wl(E,{select:!0})):v.shiftKey&&b===E&&(v.preventDefault(),t&&wl(_,{select:!0})):b===C&&v.preventDefault()}},[t,r,m.paused]);return p.jsx(bt.div,{tabIndex:-1,...o,ref:g,onKeyDown:y})});uv.displayName=cle;function ule(n,{select:e=!1}={}){const t=document.activeElement;for(const r of n)if(wl(r,{select:e}),document.activeElement!==t)return}function dle(n){const e=A6(n),t=aN(e,n),r=aN(e.reverse(),n);return[t,r]}function A6(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 aN(n,e){for(const t of n)if(!hle(t,{upTo:e}))return t}function hle(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 fle(n){return n instanceof HTMLInputElement&&"select"in n}function wl(n,{select:e=!1}={}){if(n&&n.focus){const t=document.activeElement;n.focus({preventScroll:!0}),n!==t&&fle(n)&&e&&n.select()}}var lN=ple();function ple(){let n=[];return{add(e){const t=n[0];e!==t&&(t==null||t.pause()),n=cN(n,e),n.unshift(e)},remove(e){var t;n=cN(n,e),(t=n[0])==null||t.resume()}}}function cN(n,e){const t=[...n],r=t.indexOf(e);return r!==-1&&t.splice(r,1),t}function gle(n){return n.filter(e=>e.tagName!=="A")}var Wl=globalThis!=null&&globalThis.document?P.useLayoutEffect:()=>{},mle=QW[" useId ".trim().toString()]||(()=>{}),yle=0;function Ra(n){const[e,t]=P.useState(mle());return Wl(()=>{t(r=>r??String(yle++))},[n]),n||(e?`radix-${e}`:"")}const Sle=["top","right","bottom","left"],Vl=Math.min,$s=Math.max,bS=Math.round,Mm=Math.floor,Lo=n=>({x:n,y:n}),vle={left:"right",right:"left",bottom:"top",top:"bottom"},xle={start:"end",end:"start"};function xk(n,e,t){return $s(n,Vl(e,t))}function La(n,e){return typeof n=="function"?n(e):n}function Fa(n){return n.split("-")[0]}function mh(n){return n.split("-")[1]}function r_(n){return n==="x"?"y":"x"}function s_(n){return n==="y"?"height":"width"}function ql(n){return["top","bottom"].includes(Fa(n))?"y":"x"}function i_(n){return r_(ql(n))}function wle(n,e,t){t===void 0&&(t=!1);const r=mh(n),s=i_(n),i=s_(s);let o=s==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(o=CS(o)),[o,CS(o)]}function ble(n){const e=CS(n);return[wk(n),e,wk(e)]}function wk(n){return n.replace(/start|end/g,e=>xle[e])}function Cle(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 Ple(n,e,t,r){const s=mh(n);let i=Cle(Fa(n),t==="start",r);return s&&(i=i.map(o=>o+"-"+s),e&&(i=i.concat(i.map(wk)))),i}function CS(n){return n.replace(/left|right|bottom|top/g,e=>vle[e])}function kle(n){return{top:0,right:0,bottom:0,left:0,...n}}function O6(n){return typeof n!="number"?kle(n):{top:n,right:n,bottom:n,left:n}}function PS(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 uN(n,e,t){let{reference:r,floating:s}=n;const i=ql(e),o=i_(e),a=s_(o),l=Fa(e),c=i==="y",d=r.x+r.width/2-s.width/2,f=r.y+r.height/2-s.height/2,g=r[a]/2-s[a]/2;let 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(mh(e)){case"start":m[o]-=g*(t&&c?-1:1);break;case"end":m[o]+=g*(t&&c?-1:1);break}return m}const Ile=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}=uN(c,r,l),g=r,m={},y=0;for(let v=0;v<a.length;v++){const{name:x,fn:b}=a[v],{x:C,y:E,data:_,reset:M}=await b({x:d,y:f,initialPlacement:r,placement:g,strategy:s,middlewareData:m,rects:c,platform:o,elements:{reference:n,floating:e}});d=C??d,f=E??f,m={...m,[x]:{...m[x],..._}},M&&y<=50&&(y++,typeof M=="object"&&(M.placement&&(g=M.placement),M.rects&&(c=M.rects===!0?await o.getElementRects({reference:n,floating:e,strategy:s}):M.rects),{x:d,y:f}=uN(c,g,l)),v=-1)}return{x:d,y:f,placement:g,strategy:s,middlewareData:m}};async function pp(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:g=!1,padding:m=0}=La(e,n),y=O6(m),x=a[g?f==="floating"?"reference":"floating":f],b=PS(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,E=await(i.getOffsetParent==null?void 0:i.getOffsetParent(a.floating)),_=await(i.isElement==null?void 0:i.isElement(E))?await(i.getScale==null?void 0:i.getScale(E))||{x:1,y:1}:{x:1,y:1},M=PS(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:C,offsetParent:E,strategy:l}):C);return{top:(b.top-M.top+y.top)/_.y,bottom:(M.bottom-b.bottom+y.bottom)/_.y,left:(b.left-M.left+y.left)/_.x,right:(M.right-b.right+y.right)/_.x}}const Ele=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}=La(n,e)||{};if(c==null)return{};const f=O6(d),g={x:t,y:r},m=i_(s),y=s_(m),v=await o.getDimensions(c),x=m==="y",b=x?"top":"left",C=x?"bottom":"right",E=x?"clientHeight":"clientWidth",_=i.reference[y]+i.reference[m]-g[m]-i.floating[y],M=g[m]-i.reference[m],A=await(o.getOffsetParent==null?void 0:o.getOffsetParent(c));let O=A?A[E]:0;(!O||!await(o.isElement==null?void 0:o.isElement(A)))&&(O=a.floating[E]||i.floating[y]);const D=_/2-M/2,B=O/2-v[y]/2-1,U=Vl(f[b],B),G=Vl(f[C],B),z=U,N=O-v[y]-G,L=O/2-v[y]/2+D,V=xk(z,L,N),Z=!l.arrow&&mh(s)!=null&&L!==V&&i.reference[y]/2-(L<z?U:G)-v[y]/2<0,W=Z?L<z?L-z:L-N:0;return{[m]:g[m]+W,data:{[m]:V,centerOffset:L-V-W,...Z&&{alignmentOffset:W}},reset:Z}}}),_le=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:g,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:v=!0,...x}=La(n,e);if((t=i.arrow)!=null&&t.alignmentOffset)return{};const b=Fa(s),C=ql(a),E=Fa(a)===a,_=await(l.isRTL==null?void 0:l.isRTL(c.floating)),M=g||(E||!v?[CS(a)]:ble(a)),A=y!=="none";!g&&A&&M.push(...Ple(a,v,y,_));const O=[a,...M],D=await pp(e,x),B=[];let U=((r=i.flip)==null?void 0:r.overflows)||[];if(d&&B.push(D[b]),f){const L=wle(s,o,_);B.push(D[L[0]],D[L[1]])}if(U=[...U,{placement:s,overflows:B}],!B.every(L=>L<=0)){var G,z;const L=(((G=i.flip)==null?void 0:G.index)||0)+1,V=O[L];if(V)return{data:{index:L,overflows:U},reset:{placement:V}};let Z=(z=U.filter(W=>W.overflows[0]<=0).sort((W,$)=>W.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!Z)switch(m){case"bestFit":{var N;const W=(N=U.filter($=>{if(A){const Y=ql($.placement);return Y===C||Y==="y"}return!0}).map($=>[$.placement,$.overflows.filter(Y=>Y>0).reduce((Y,re)=>Y+re,0)]).sort(($,Y)=>$[1]-Y[1])[0])==null?void 0:N[0];W&&(Z=W);break}case"initialPlacement":Z=a;break}if(s!==Z)return{reset:{placement:Z}}}return{}}}};function dN(n,e){return{top:n.top-e.height,right:n.right-e.width,bottom:n.bottom-e.height,left:n.left-e.width}}function hN(n){return Sle.some(e=>n[e]>=0)}const Tle=function(n){return n===void 0&&(n={}),{name:"hide",options:n,async fn(e){const{rects:t}=e,{strategy:r="referenceHidden",...s}=La(n,e);switch(r){case"referenceHidden":{const i=await pp(e,{...s,elementContext:"reference"}),o=dN(i,t.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:hN(o)}}}case"escaped":{const i=await pp(e,{...s,altBoundary:!0}),o=dN(i,t.floating);return{data:{escapedOffsets:o,escaped:hN(o)}}}default:return{}}}}};async function Mle(n,e){const{placement:t,platform:r,elements:s}=n,i=await(r.isRTL==null?void 0:r.isRTL(s.floating)),o=Fa(t),a=mh(t),l=ql(t)==="y",c=["left","top"].includes(o)?-1:1,d=i&&l?-1:1,f=La(e,n);let{mainAxis:g,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:g*c}:{x:g*c,y:m*d}}const Ale=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 Mle(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}}}}},Ole=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}=La(n,e),c={x:t,y:r},d=await pp(e,l),f=ql(Fa(s)),g=r_(f);let m=c[g],y=c[f];if(i){const x=g==="y"?"top":"left",b=g==="y"?"bottom":"right",C=m+d[x],E=m-d[b];m=xk(C,m,E)}if(o){const x=f==="y"?"top":"left",b=f==="y"?"bottom":"right",C=y+d[x],E=y-d[b];y=xk(C,y,E)}const v=a.fn({...e,[g]:m,[f]:y});return{...v,data:{x:v.x-t,y:v.y-r,enabled:{[g]:i,[f]:o}}}}}},Rle=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}=La(n,e),d={x:t,y:r},f=ql(s),g=r_(f);let m=d[g],y=d[f];const v=La(a,e),x=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const E=g==="y"?"height":"width",_=i.reference[g]-i.floating[E]+x.mainAxis,M=i.reference[g]+i.reference[E]-x.mainAxis;m<_?m=_:m>M&&(m=M)}if(c){var b,C;const E=g==="y"?"width":"height",_=["top","left"].includes(Fa(s)),M=i.reference[f]-i.floating[E]+(_&&((b=o.offset)==null?void 0:b[f])||0)+(_?0:x.crossAxis),A=i.reference[f]+i.reference[E]+(_?0:((C=o.offset)==null?void 0:C[f])||0)-(_?x.crossAxis:0);y<M?y=M:y>A&&(y=A)}return{[g]:m,[f]:y}}}},Dle=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}=La(n,e),d=await pp(e,c),f=Fa(s),g=mh(s),m=ql(s)==="y",{width:y,height:v}=i.floating;let x,b;f==="top"||f==="bottom"?(x=f,b=g===(await(o.isRTL==null?void 0:o.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,x=g==="end"?"top":"bottom");const C=v-d.top-d.bottom,E=y-d.left-d.right,_=Vl(v-d[x],C),M=Vl(y-d[b],E),A=!e.middlewareData.shift;let O=_,D=M;if((t=e.middlewareData.shift)!=null&&t.enabled.x&&(D=E),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(O=C),A&&!g){const U=$s(d.left,0),G=$s(d.right,0),z=$s(d.top,0),N=$s(d.bottom,0);m?D=y-2*(U!==0||G!==0?U+G:$s(d.left,d.right)):O=v-2*(z!==0||N!==0?z+N:$s(d.top,d.bottom))}await l({...e,availableWidth:D,availableHeight:O});const B=await o.getDimensions(a.floating);return y!==B.width||v!==B.height?{reset:{rects:!0}}:{}}}};function dv(){return typeof window<"u"}function yh(n){return R6(n)?(n.nodeName||"").toLowerCase():"#document"}function Gs(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function Zo(n){var e;return(e=(R6(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function R6(n){return dv()?n instanceof Node||n instanceof Gs(n).Node:!1}function to(n){return dv()?n instanceof Element||n instanceof Gs(n).Element:!1}function Ho(n){return dv()?n instanceof HTMLElement||n instanceof Gs(n).HTMLElement:!1}function fN(n){return!dv()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Gs(n).ShadowRoot}function Gp(n){const{overflow:e,overflowX:t,overflowY:r,display:s}=no(n);return/auto|scroll|overlay|hidden|clip/.test(e+r+t)&&!["inline","contents"].includes(s)}function jle(n){return["table","td","th"].includes(yh(n))}function hv(n){return[":popover-open",":modal"].some(e=>{try{return n.matches(e)}catch{return!1}})}function o_(n){const e=a_(),t=to(n)?no(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 Nle(n){let e=Gl(n);for(;Ho(e)&&!Xd(e);){if(o_(e))return e;if(hv(e))return null;e=Gl(e)}return null}function a_(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Xd(n){return["html","body","#document"].includes(yh(n))}function no(n){return Gs(n).getComputedStyle(n)}function fv(n){return to(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function Gl(n){if(yh(n)==="html")return n;const e=n.assignedSlot||n.parentNode||fN(n)&&n.host||Zo(n);return fN(e)?e.host:e}function D6(n){const e=Gl(n);return Xd(e)?n.ownerDocument?n.ownerDocument.body:n.body:Ho(e)&&Gp(e)?e:D6(e)}function gp(n,e,t){var r;e===void 0&&(e=[]),t===void 0&&(t=!0);const s=D6(n),i=s===((r=n.ownerDocument)==null?void 0:r.body),o=Gs(s);if(i){const a=bk(o);return e.concat(o,o.visualViewport||[],Gp(s)?s:[],a&&t?gp(a):[])}return e.concat(s,gp(s,[],t))}function bk(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function j6(n){const e=no(n);let t=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Ho(n),i=s?n.offsetWidth:t,o=s?n.offsetHeight:r,a=bS(t)!==i||bS(r)!==o;return a&&(t=i,r=o),{width:t,height:r,$:a}}function l_(n){return to(n)?n:n.contextElement}function jd(n){const e=l_(n);if(!Ho(e))return Lo(1);const t=e.getBoundingClientRect(),{width:r,height:s,$:i}=j6(e);let o=(i?bS(t.width):t.width)/r,a=(i?bS(t.height):t.height)/s;return(!o||!Number.isFinite(o))&&(o=1),(!a||!Number.isFinite(a))&&(a=1),{x:o,y:a}}const Lle=Lo(0);function N6(n){const e=Gs(n);return!a_()||!e.visualViewport?Lle:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Fle(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Gs(n)?!1:e}function iu(n,e,t,r){e===void 0&&(e=!1),t===void 0&&(t=!1);const s=n.getBoundingClientRect(),i=l_(n);let o=Lo(1);e&&(r?to(r)&&(o=jd(r)):o=jd(n));const a=Fle(i,t,r)?N6(i):Lo(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 g=Gs(i),m=r&&to(r)?Gs(r):r;let y=g,v=bk(y);for(;v&&r&&m!==y;){const x=jd(v),b=v.getBoundingClientRect(),C=no(v),E=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+=E,c+=_,y=Gs(v),v=bk(y)}}return PS({width:d,height:f,x:l,y:c})}function c_(n,e){const t=fv(n).scrollLeft;return e?e.left+t:iu(Zo(n)).left+t}function L6(n,e,t){t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=r.left+e.scrollLeft-(t?0:c_(n,r)),i=r.top+e.scrollTop;return{x:s,y:i}}function zle(n){let{elements:e,rect:t,offsetParent:r,strategy:s}=n;const i=s==="fixed",o=Zo(r),a=e?hv(e.floating):!1;if(r===o||a&&i)return t;let l={scrollLeft:0,scrollTop:0},c=Lo(1);const d=Lo(0),f=Ho(r);if((f||!f&&!i)&&((yh(r)!=="body"||Gp(o))&&(l=fv(r)),Ho(r))){const m=iu(r);c=jd(r),d.x=m.x+r.clientLeft,d.y=m.y+r.clientTop}const g=o&&!f&&!i?L6(o,l,!0):Lo(0);return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-l.scrollLeft*c.x+d.x+g.x,y:t.y*c.y-l.scrollTop*c.y+d.y+g.y}}function $le(n){return Array.from(n.getClientRects())}function Ble(n){const e=Zo(n),t=fv(n),r=n.ownerDocument.body,s=$s(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),i=$s(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let o=-t.scrollLeft+c_(n);const a=-t.scrollTop;return no(r).direction==="rtl"&&(o+=$s(e.clientWidth,r.clientWidth)-s),{width:s,height:i,x:o,y:a}}function Ule(n,e){const t=Gs(n),r=Zo(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=a_();(!c||c&&e==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:i,height:o,x:a,y:l}}function Hle(n,e){const t=iu(n,!0,e==="fixed"),r=t.top+n.clientTop,s=t.left+n.clientLeft,i=Ho(n)?jd(n):Lo(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 pN(n,e,t){let r;if(e==="viewport")r=Ule(n,t);else if(e==="document")r=Ble(Zo(n));else if(to(e))r=Hle(e,t);else{const s=N6(n);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return PS(r)}function F6(n,e){const t=Gl(n);return t===e||!to(t)||Xd(t)?!1:no(t).position==="fixed"||F6(t,e)}function Kle(n,e){const t=e.get(n);if(t)return t;let r=gp(n,[],!1).filter(a=>to(a)&&yh(a)!=="body"),s=null;const i=no(n).position==="fixed";let o=i?Gl(n):n;for(;to(o)&&!Xd(o);){const a=no(o),l=o_(o);!l&&a.position==="fixed"&&(s=null),(i?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||Gp(o)&&!l&&F6(n,o))?r=r.filter(d=>d!==o):s=a,o=Gl(o)}return e.set(n,r),r}function Wle(n){let{element:e,boundary:t,rootBoundary:r,strategy:s}=n;const o=[...t==="clippingAncestors"?hv(e)?[]:Kle(e,this._c):[].concat(t),r],a=o[0],l=o.reduce((c,d)=>{const f=pN(e,d,s);return c.top=$s(f.top,c.top),c.right=Vl(f.right,c.right),c.bottom=Vl(f.bottom,c.bottom),c.left=$s(f.left,c.left),c},pN(e,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Vle(n){const{width:e,height:t}=j6(n);return{width:e,height:t}}function qle(n,e,t){const r=Ho(e),s=Zo(e),i=t==="fixed",o=iu(n,!0,i,e);let a={scrollLeft:0,scrollTop:0};const l=Lo(0);if(r||!r&&!i)if((yh(e)!=="body"||Gp(s))&&(a=fv(e)),r){const g=iu(e,!0,i,e);l.x=g.x+e.clientLeft,l.y=g.y+e.clientTop}else s&&(l.x=c_(s));const c=s&&!r&&!i?L6(s,a):Lo(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 kC(n){return no(n).position==="static"}function gN(n,e){if(!Ho(n)||no(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return Zo(n)===t&&(t=t.ownerDocument.body),t}function z6(n,e){const t=Gs(n);if(hv(n))return t;if(!Ho(n)){let s=Gl(n);for(;s&&!Xd(s);){if(to(s)&&!kC(s))return s;s=Gl(s)}return t}let r=gN(n,e);for(;r&&jle(r)&&kC(r);)r=gN(r,e);return r&&Xd(r)&&kC(r)&&!o_(r)?t:r||Nle(n)||t}const Gle=async function(n){const e=this.getOffsetParent||z6,t=this.getDimensions,r=await t(n.floating);return{reference:qle(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Yle(n){return no(n).direction==="rtl"}const Xle={convertOffsetParentRelativeRectToViewportRelativeRect:zle,getDocumentElement:Zo,getClippingRect:Wle,getOffsetParent:z6,getElementRects:Gle,getClientRects:$le,getDimensions:Vle,getScale:jd,isElement:to,isRTL:Yle};function $6(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function Zle(n,e){let t=null,r;const s=Zo(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:g,height:m}=c;if(a||e(),!g||!m)return;const y=Mm(f),v=Mm(s.clientWidth-(d+g)),x=Mm(s.clientHeight-(f+m)),b=Mm(d),E={rootMargin:-y+"px "+-v+"px "+-x+"px "+-b+"px",threshold:$s(0,Vl(1,l))||1};let _=!0;function M(A){const O=A[0].intersectionRatio;if(O!==l){if(!_)return o();O?o(!1,O):r=setTimeout(()=>{o(!1,1e-7)},1e3)}O===1&&!$6(c,n.getBoundingClientRect())&&o(),_=!1}try{t=new IntersectionObserver(M,{...E,root:s.ownerDocument})}catch{t=new IntersectionObserver(M,E)}t.observe(n)}return o(!0),i}function Jle(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=l_(n),d=s||i?[...c?gp(c):[],...gp(e)]:[];d.forEach(b=>{s&&b.addEventListener("scroll",t,{passive:!0}),i&&b.addEventListener("resize",t)});const f=c&&a?Zle(c,t):null;let g=-1,m=null;o&&(m=new ResizeObserver(b=>{let[C]=b;C&&C.target===c&&m&&(m.unobserve(e),cancelAnimationFrame(g),g=requestAnimationFrame(()=>{var E;(E=m)==null||E.observe(e)})),t()}),c&&!l&&m.observe(c),m.observe(e));let y,v=l?iu(n):null;l&&x();function x(){const b=iu(n);v&&!$6(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 Qle=Ale,ece=Ole,tce=_le,nce=Dle,rce=Tle,mN=Ele,sce=Rle,ice=(n,e,t)=>{const r=new Map,s={platform:Xle,...t},i={...s.platform,_c:r};return Ile(n,e,{...s,platform:i})};var dy=typeof document<"u"?P.useLayoutEffect:P.useEffect;function kS(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(!kS(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)&&!kS(n[i],e[i]))return!1}return!0}return n!==n&&e!==e}function B6(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function yN(n,e){const t=B6(n);return Math.round(e*t)/t}function IC(n){const e=P.useRef(n);return dy(()=>{e.current=n}),e}function oce(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}),[g,m]=P.useState(r);kS(g,r)||m(r);const[y,v]=P.useState(null),[x,b]=P.useState(null),C=P.useCallback($=>{$!==A.current&&(A.current=$,v($))},[]),E=P.useCallback($=>{$!==O.current&&(O.current=$,b($))},[]),_=i||y,M=o||x,A=P.useRef(null),O=P.useRef(null),D=P.useRef(d),B=l!=null,U=IC(l),G=IC(s),z=IC(c),N=P.useCallback(()=>{if(!A.current||!O.current)return;const $={placement:e,strategy:t,middleware:g};G.current&&($.platform=G.current),ice(A.current,O.current,$).then(Y=>{const re={...Y,isPositioned:z.current!==!1};L.current&&!kS(D.current,re)&&(D.current=re,hh.flushSync(()=>{f(re)}))})},[g,e,t,G,z]);dy(()=>{c===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[c]);const L=P.useRef(!1);dy(()=>(L.current=!0,()=>{L.current=!1}),[]),dy(()=>{if(_&&(A.current=_),M&&(O.current=M),_&&M){if(U.current)return U.current(_,M,N);N()}},[_,M,N,U,B]);const V=P.useMemo(()=>({reference:A,floating:O,setReference:C,setFloating:E}),[C,E]),Z=P.useMemo(()=>({reference:_,floating:M}),[_,M]),W=P.useMemo(()=>{const $={position:t,left:0,top:0};if(!Z.floating)return $;const Y=yN(Z.floating,d.x),re=yN(Z.floating,d.y);return a?{...$,transform:"translate("+Y+"px, "+re+"px)",...B6(Z.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:Y,top:re}},[t,a,Z.floating,d.x,d.y]);return P.useMemo(()=>({...d,update:N,refs:V,elements:Z,floatingStyles:W}),[d,N,V,Z,W])}const ace=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?mN({element:r.current,padding:s}).fn(t):{}:r?mN({element:r,padding:s}).fn(t):{}}}},lce=(n,e)=>({...Qle(n),options:[n,e]}),cce=(n,e)=>({...ece(n),options:[n,e]}),uce=(n,e)=>({...sce(n),options:[n,e]}),dce=(n,e)=>({...tce(n),options:[n,e]}),hce=(n,e)=>({...nce(n),options:[n,e]}),fce=(n,e)=>({...rce(n),options:[n,e]}),pce=(n,e)=>({...ace(n),options:[n,e]});var gce="Arrow",U6=P.forwardRef((n,e)=>{const{children:t,width:r=10,height:s=5,...i}=n;return p.jsx(bt.svg,{...i,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:n.asChild?t:p.jsx("polygon",{points:"0,0 30,0 15,10"})})});U6.displayName=gce;var mce=U6;function H6(n){const[e,t]=P.useState(void 0);return Wl(()=>{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 u_="Popper",[K6,pv]=Xo(u_),[yce,W6]=K6(u_),V6=n=>{const{__scopePopper:e,children:t}=n,[r,s]=P.useState(null);return p.jsx(yce,{scope:e,anchor:r,onAnchorChange:s,children:t})};V6.displayName=u_;var q6="PopperAnchor",G6=P.forwardRef((n,e)=>{const{__scopePopper:t,virtualRef:r,...s}=n,i=W6(q6,t),o=P.useRef(null),a=Wt(e,o);return P.useEffect(()=>{i.onAnchorChange((r==null?void 0:r.current)||o.current)}),r?null:p.jsx(bt.div,{...s,ref:a})});G6.displayName=q6;var d_="PopperContent",[Sce,vce]=K6(d_),Y6=P.forwardRef((n,e)=>{var Re,Ce,_e,We,st,hn;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:g=!1,updatePositionStrategy:m="optimized",onPlaced:y,...v}=n,x=W6(d_,t),[b,C]=P.useState(null),E=Wt(e,_t=>C(_t)),[_,M]=P.useState(null),A=H6(_),O=(A==null?void 0:A.width)??0,D=(A==null?void 0:A.height)??0,B=r+(i!=="center"?"-"+i:""),U=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},G=Array.isArray(c)?c:[c],z=G.length>0,N={padding:U,boundary:G.filter(wce),altBoundary:z},{refs:L,floatingStyles:V,placement:Z,isPositioned:W,middlewareData:$}=oce({strategy:"fixed",placement:B,whileElementsMounted:(..._t)=>Jle(..._t,{animationFrame:m==="always"}),elements:{reference:x.anchor},middleware:[lce({mainAxis:s+D,alignmentAxis:o}),l&&cce({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?uce():void 0,...N}),l&&dce({...N}),hce({...N,apply:({elements:_t,rects:Qt,availableWidth:Nt,availableHeight:At})=>{const{width:Jr,height:Qr}=Qt.reference,es=_t.floating.style;es.setProperty("--radix-popper-available-width",`${Nt}px`),es.setProperty("--radix-popper-available-height",`${At}px`),es.setProperty("--radix-popper-anchor-width",`${Jr}px`),es.setProperty("--radix-popper-anchor-height",`${Qr}px`)}}),_&&pce({element:_,padding:a}),bce({arrowWidth:O,arrowHeight:D}),g&&fce({strategy:"referenceHidden",...N})]}),[Y,re]=J6(Z),K=cr(y);Wl(()=>{W&&(K==null||K())},[W,K]);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 Wl(()=>{b&&Be(window.getComputedStyle(b).zIndex)},[b]),p.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":[(We=$.transformOrigin)==null?void 0:We.x,(st=$.transformOrigin)==null?void 0:st.y].join(" "),...((hn=$.hide)==null?void 0:hn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:p.jsx(Sce,{scope:t,placedSide:Y,onArrowChange:M,arrowX:ne,arrowY:ge,shouldHideArrow:Pe,children:p.jsx(bt.div,{"data-side":Y,"data-align":re,...v,ref:E,style:{...v.style,animation:W?void 0:"none"}})})})});Y6.displayName=d_;var X6="PopperArrow",xce={top:"bottom",right:"left",bottom:"top",left:"right"},Z6=P.forwardRef(function(e,t){const{__scopePopper:r,...s}=e,i=vce(X6,r),o=xce[i.placedSide];return p.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:p.jsx(mce,{...s,ref:t,style:{...s.style,display:"block"}})})});Z6.displayName=X6;function wce(n){return n!==null}var bce=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]=J6(t),f={start:"0%",center:"50%",end:"100%"}[d],g=(((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:`${g}px`,v=`${-l}px`):c==="top"?(y=o?f:`${g}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 J6(n){const[e,t="center"]=n.split("-");return[e,t]}var h_=V6,f_=G6,Q6=Y6,e8=Z6,Cce="Portal",Yp=P.forwardRef((n,e)=>{var a;const{container:t,...r}=n,[s,i]=P.useState(!1);Wl(()=>i(!0),[]);const o=t||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return o?gse.createPortal(p.jsx(bt.div,{...r,ref:e}),o):null});Yp.displayName=Cce;function Pce(n,e){return P.useReducer((t,r)=>e[t][r]??t,n)}var oo=n=>{const{present:e,children:t}=n,r=kce(e),s=typeof t=="function"?t({present:r.isPresent}):P.Children.only(t),i=Wt(r.ref,Ice(s));return typeof t=="function"||r.isPresent?P.cloneElement(s,{ref:i}):null};oo.displayName="Presence";function kce(n){const[e,t]=P.useState(),r=P.useRef({}),s=P.useRef(n),i=P.useRef("none"),o=n?"mounted":"unmounted",[a,l]=Pce(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return P.useEffect(()=>{const c=Am(r.current);i.current=a==="mounted"?c:"none"},[a]),Wl(()=>{const c=r.current,d=s.current;if(d!==n){const g=i.current,m=Am(c);n?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&g!==m?"ANIMATION_OUT":"UNMOUNT"),s.current=n}},[n,l]),Wl(()=>{if(e){let c;const d=e.ownerDocument.defaultView??window,f=m=>{const v=Am(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)})}},g=m=>{m.target===e&&(i.current=Am(r.current))};return e.addEventListener("animationstart",g),e.addEventListener("animationcancel",f),e.addEventListener("animationend",f),()=>{d.clearTimeout(c),e.removeEventListener("animationstart",g),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 Am(n){return(n==null?void 0:n.animationName)||"none"}function Ice(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 rc({prop:n,defaultProp:e,onChange:t=()=>{}}){const[r,s]=Ece({defaultProp:e,onChange:t}),i=n!==void 0,o=i?n:r,a=cr(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 Ece({defaultProp:n,onChange:e}){const t=P.useState(n),[r]=t,s=P.useRef(r),i=cr(e);return P.useEffect(()=>{s.current!==r&&(i(r),s.current=r)},[r,s,i]),t}var EC="rovingFocusGroup.onEntryFocus",_ce={bubbles:!1,cancelable:!0},gv="RovingFocusGroup",[Ck,t8,Tce]=cv(gv),[Mce,n8]=Xo(gv,[Tce]),[Ace,Oce]=Mce(gv),r8=P.forwardRef((n,e)=>p.jsx(Ck.Provider,{scope:n.__scopeRovingFocusGroup,children:p.jsx(Ck.Slot,{scope:n.__scopeRovingFocusGroup,children:p.jsx(Rce,{...n,ref:e})})}));r8.displayName=gv;var Rce=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,g=P.useRef(null),m=Wt(e,g),y=t_(i),[v=null,x]=rc({prop:o,defaultProp:a,onChange:l}),[b,C]=P.useState(!1),E=cr(c),_=t8(t),M=P.useRef(!1),[A,O]=P.useState(0);return P.useEffect(()=>{const D=g.current;if(D)return D.addEventListener(EC,E),()=>D.removeEventListener(EC,E)},[E]),p.jsx(Ace,{scope:t,orientation:r,dir:y,loop:s,currentTabStopId:v,onItemFocus:P.useCallback(D=>x(D),[x]),onItemShiftTab:P.useCallback(()=>C(!0),[]),onFocusableItemAdd:P.useCallback(()=>O(D=>D+1),[]),onFocusableItemRemove:P.useCallback(()=>O(D=>D-1),[]),children:p.jsx(bt.div,{tabIndex:b||A===0?-1:0,"data-orientation":r,...f,ref:m,style:{outline:"none",...n.style},onMouseDown:De(n.onMouseDown,()=>{M.current=!0}),onFocus:De(n.onFocus,D=>{const B=!M.current;if(D.target===D.currentTarget&&B&&!b){const U=new CustomEvent(EC,_ce);if(D.currentTarget.dispatchEvent(U),!U.defaultPrevented){const G=_().filter(Z=>Z.focusable),z=G.find(Z=>Z.active),N=G.find(Z=>Z.id===v),V=[z,N,...G].filter(Boolean).map(Z=>Z.ref.current);o8(V,d)}}M.current=!1}),onBlur:De(n.onBlur,()=>C(!1))})})}),s8="RovingFocusGroupItem",i8=P.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:s=!1,tabStopId:i,...o}=n,a=Ra(),l=i||a,c=Oce(s8,t),d=c.currentTabStopId===l,f=t8(t),{onFocusableItemAdd:g,onFocusableItemRemove:m}=c;return P.useEffect(()=>{if(r)return g(),()=>m()},[r,g,m]),p.jsx(Ck.ItemSlot,{scope:t,id:l,focusable:r,active:s,children:p.jsx(bt.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=Nce(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?Lce(b,C+1):b.slice(C+1)}setTimeout(()=>o8(b))}})})})});i8.displayName=s8;var Dce={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function jce(n,e){return e!=="rtl"?n:n==="ArrowLeft"?"ArrowRight":n==="ArrowRight"?"ArrowLeft":n}function Nce(n,e,t){const r=jce(n.key,t);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Dce[r]}function o8(n,e=!1){const t=document.activeElement;for(const r of n)if(r===t||(r.focus({preventScroll:e}),document.activeElement!==t))return}function Lce(n,e){return n.map((t,r)=>n[(e+r)%n.length])}var Fce=r8,zce=i8,$ce=function(n){if(typeof document>"u")return null;var e=Array.isArray(n)?n[0]:n;return e.ownerDocument.body},dd=new WeakMap,Om=new WeakMap,Rm={},_C=0,a8=function(n){return n&&(n.host||a8(n.parentNode))},Bce=function(n,e){return e.map(function(t){if(n.contains(t))return t;var r=a8(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})},Uce=function(n,e,t,r){var s=Bce(e,Array.isArray(n)?n:[n]);Rm[t]||(Rm[t]=new WeakMap);var i=Rm[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(g){if(a.has(g))d(g);else try{var m=g.getAttribute(r),y=m!==null&&m!=="false",v=(dd.get(g)||0)+1,x=(i.get(g)||0)+1;dd.set(g,v),i.set(g,x),o.push(g),v===1&&y&&Om.set(g,!0),x===1&&g.setAttribute(t,"true"),y||g.setAttribute(r,"true")}catch(b){console.error("aria-hidden: cannot operate on ",g,b)}})};return d(e),a.clear(),_C++,function(){o.forEach(function(f){var g=dd.get(f)-1,m=i.get(f)-1;dd.set(f,g),i.set(f,m),g||(Om.has(f)||f.removeAttribute(r),Om.delete(f)),m||f.removeAttribute(t)}),_C--,_C||(dd=new WeakMap,dd=new WeakMap,Om=new WeakMap,Rm={})}},p_=function(n,e,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(n)?n:[n]),s=$ce(n);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),Uce(r,s,t,"aria-hidden")):function(){return null}},Ao=function(){return Ao=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},Ao.apply(this,arguments)};function l8(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 Hce(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 hy="right-scroll-bar-position",fy="width-before-scroll-bar",Kce="with-scroll-bars-hidden",Wce="--removed-body-scroll-bar-size";function TC(n,e){return typeof n=="function"?n(e):n&&(n.current=e),n}function Vce(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 qce=typeof window<"u"?P.useLayoutEffect:P.useEffect,SN=new WeakMap;function Gce(n,e){var t=Vce(null,function(r){return n.forEach(function(s){return TC(s,r)})});return qce(function(){var r=SN.get(t);if(r){var s=new Set(r),i=new Set(n),o=t.current;s.forEach(function(a){i.has(a)||TC(a,null)}),i.forEach(function(a){s.has(a)||TC(a,o)})}SN.set(t,n)},[n]),t}function Yce(n){return n}function Xce(n,e){e===void 0&&(e=Yce);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 Zce(n){n===void 0&&(n={});var e=Xce(null);return e.options=Ao({async:!0,ssr:!1},n),e}var c8=function(n){var e=n.sideCar,t=l8(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,Ao({},t))};c8.isSideCarExport=!0;function Jce(n,e){return n.useMedium(e),c8}var u8=Zce(),MC=function(){},mv=P.forwardRef(function(n,e){var t=P.useRef(null),r=P.useState({onScrollCapture:MC,onWheelCapture:MC,onTouchMoveCapture:MC}),s=r[0],i=r[1],o=n.forwardProps,a=n.children,l=n.className,c=n.removeScrollBar,d=n.enabled,f=n.shards,g=n.sideCar,m=n.noIsolation,y=n.inert,v=n.allowPinchZoom,x=n.as,b=x===void 0?"div":x,C=n.gapMode,E=l8(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),_=g,M=Gce([t,e]),A=Ao(Ao({},E),s);return P.createElement(P.Fragment,null,d&&P.createElement(_,{sideCar:u8,removeScrollBar:c,shards:f,noIsolation:m,inert:y,setCallbacks:i,allowPinchZoom:!!v,lockRef:t,gapMode:C}),o?P.cloneElement(P.Children.only(a),Ao(Ao({},A),{ref:M})):P.createElement(b,Ao({},A,{className:l,ref:M}),a))});mv.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};mv.classNames={fullWidth:fy,zeroRight:hy};var Qce=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function eue(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var e=Qce();return e&&n.setAttribute("nonce",e),n}function tue(n,e){n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}function nue(n){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(n)}var rue=function(){var n=0,e=null;return{add:function(t){n==0&&(e=eue())&&(tue(e,t),nue(e)),n++},remove:function(){n--,!n&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},sue=function(){var n=rue();return function(e,t){P.useEffect(function(){return n.add(e),function(){n.remove()}},[e&&t])}},d8=function(){var n=sue(),e=function(t){var r=t.styles,s=t.dynamic;return n(r,s),null};return e},iue={left:0,top:0,right:0,gap:0},AC=function(n){return parseInt(n||"",10)||0},oue=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[AC(t),AC(r),AC(s)]},aue=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return iue;var e=oue(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])}},lue=d8(),Nd="data-scroll-locked",cue=function(n,e,t,r){var s=n.left,i=n.top,o=n.right,a=n.gap;return t===void 0&&(t="margin"),`
304
+ .`.concat(Kce,` {
305
+ overflow: hidden `).concat(r,`;
306
+ padding-right: `).concat(a,"px ").concat(r,`;
307
+ }
308
+ body[`).concat(Nd,`] {
309
+ overflow: hidden `).concat(r,`;
310
+ overscroll-behavior: contain;
311
+ `).concat([e&&"position: relative ".concat(r,";"),t==="margin"&&`
312
+ padding-left: `.concat(s,`px;
313
+ padding-top: `).concat(i,`px;
314
+ padding-right: `).concat(o,`px;
315
+ margin-left:0;
316
+ margin-top:0;
317
+ margin-right: `).concat(a,"px ").concat(r,`;
318
+ `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
319
+ }
320
+
321
+ .`).concat(hy,` {
322
+ right: `).concat(a,"px ").concat(r,`;
323
+ }
324
+
325
+ .`).concat(fy,` {
326
+ margin-right: `).concat(a,"px ").concat(r,`;
327
+ }
328
+
329
+ .`).concat(hy," .").concat(hy,` {
330
+ right: 0 `).concat(r,`;
331
+ }
332
+
333
+ .`).concat(fy," .").concat(fy,` {
334
+ margin-right: 0 `).concat(r,`;
335
+ }
336
+
337
+ body[`).concat(Nd,`] {
338
+ `).concat(Wce,": ").concat(a,`px;
339
+ }
340
+ `)},vN=function(){var n=parseInt(document.body.getAttribute(Nd)||"0",10);return isFinite(n)?n:0},uue=function(){P.useEffect(function(){return document.body.setAttribute(Nd,(vN()+1).toString()),function(){var n=vN()-1;n<=0?document.body.removeAttribute(Nd):document.body.setAttribute(Nd,n.toString())}},[])},due=function(n){var e=n.noRelative,t=n.noImportant,r=n.gapMode,s=r===void 0?"margin":r;uue();var i=P.useMemo(function(){return aue(s)},[s]);return P.createElement(lue,{styles:cue(i,!e,s,t?"":"!important")})},Pk=!1;if(typeof window<"u")try{var Dm=Object.defineProperty({},"passive",{get:function(){return Pk=!0,!0}});window.addEventListener("test",Dm,Dm),window.removeEventListener("test",Dm,Dm)}catch{Pk=!1}var hd=Pk?{passive:!1}:!1,hue=function(n){return n.tagName==="TEXTAREA"},h8=function(n,e){if(!(n instanceof Element))return!1;var t=window.getComputedStyle(n);return t[e]!=="hidden"&&!(t.overflowY===t.overflowX&&!hue(n)&&t[e]==="visible")},fue=function(n){return h8(n,"overflowY")},pue=function(n){return h8(n,"overflowX")},xN=function(n,e){var t=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=f8(n,r);if(s){var i=p8(n,r),o=i[1],a=i[2];if(o>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},gue=function(n){var e=n.scrollTop,t=n.scrollHeight,r=n.clientHeight;return[e,t,r]},mue=function(n){var e=n.scrollLeft,t=n.scrollWidth,r=n.clientWidth;return[e,t,r]},f8=function(n,e){return n==="v"?fue(e):pue(e)},p8=function(n,e){return n==="v"?gue(e):mue(e)},yue=function(n,e){return n==="h"&&e==="rtl"?-1:1},Sue=function(n,e,t,r,s){var i=yue(n,window.getComputedStyle(e).direction),o=i*r,a=t.target,l=e.contains(a),c=!1,d=o>0,f=0,g=0;do{var m=p8(n,a),y=m[0],v=m[1],x=m[2],b=v-x-i*y;(y||b)&&f8(n,a)&&(f+=b,g+=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(g)<1)&&(c=!0),c},jm=function(n){return"changedTouches"in n?[n.changedTouches[0].clientX,n.changedTouches[0].clientY]:[0,0]},wN=function(n){return[n.deltaX,n.deltaY]},bN=function(n){return n&&"current"in n?n.current:n},vue=function(n,e){return n[0]===e[0]&&n[1]===e[1]},xue=function(n){return`
341
+ .block-interactivity-`.concat(n,` {pointer-events: none;}
342
+ .allow-interactivity-`).concat(n,` {pointer-events: all;}
343
+ `)},wue=0,fd=[];function bue(n){var e=P.useRef([]),t=P.useRef([0,0]),r=P.useRef(),s=P.useState(wue++)[0],i=P.useState(d8)[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=Hce([n.lockRef.current],(n.shards||[]).map(bN),!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=jm(v),C=t.current,E="deltaX"in v?v.deltaX:C[0]-b[0],_="deltaY"in v?v.deltaY:C[1]-b[1],M,A=v.target,O=Math.abs(E)>Math.abs(_)?"h":"v";if("touches"in v&&O==="h"&&A.type==="range")return!1;var D=xN(O,A);if(!D)return!0;if(D?M=O:(M=O==="v"?"h":"v",D=xN(O,A)),!D)return!1;if(!r.current&&"changedTouches"in v&&(E||_)&&(r.current=M),!M)return!0;var B=r.current||M;return Sue(B,x,v,B==="h"?E:_)},[]),l=P.useCallback(function(v){var x=v;if(!(!fd.length||fd[fd.length-1]!==i)){var b="deltaY"in x?wN(x):jm(x),C=e.current.filter(function(M){return M.name===x.type&&(M.target===x.target||x.target===M.shadowParent)&&vue(M.delta,b)})[0];if(C&&C.should){x.cancelable&&x.preventDefault();return}if(!C){var E=(o.current.shards||[]).map(bN).filter(Boolean).filter(function(M){return M.contains(x.target)}),_=E.length>0?a(x,E[0]):!o.current.noIsolation;_&&x.cancelable&&x.preventDefault()}}},[]),c=P.useCallback(function(v,x,b,C){var E={name:v,delta:x,target:b,should:C,shadowParent:Cue(b)};e.current.push(E),setTimeout(function(){e.current=e.current.filter(function(_){return _!==E})},1)},[]),d=P.useCallback(function(v){t.current=jm(v),r.current=void 0},[]),f=P.useCallback(function(v){c(v.type,wN(v),v.target,a(v,n.lockRef.current))},[]),g=P.useCallback(function(v){c(v.type,jm(v),v.target,a(v,n.lockRef.current))},[]);P.useEffect(function(){return fd.push(i),n.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:g}),document.addEventListener("wheel",l,hd),document.addEventListener("touchmove",l,hd),document.addEventListener("touchstart",d,hd),function(){fd=fd.filter(function(v){return v!==i}),document.removeEventListener("wheel",l,hd),document.removeEventListener("touchmove",l,hd),document.removeEventListener("touchstart",d,hd)}},[]);var m=n.removeScrollBar,y=n.inert;return P.createElement(P.Fragment,null,y?P.createElement(i,{styles:xue(s)}):null,m?P.createElement(due,{gapMode:n.gapMode}):null)}function Cue(n){for(var e=null;n!==null;)n instanceof ShadowRoot&&(e=n.host,n=n.host),n=n.parentNode;return e}const Pue=Jce(u8,bue);var yv=P.forwardRef(function(n,e){return P.createElement(mv,Ao({},n,{ref:e,sideCar:Pue}))});yv.classNames=mv.classNames;var kk=["Enter"," "],kue=["ArrowDown","PageUp","Home"],g8=["ArrowUp","PageDown","End"],Iue=[...kue,...g8],Eue={ltr:[...kk,"ArrowRight"],rtl:[...kk,"ArrowLeft"]},_ue={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xp="Menu",[mp,Tue,Mue]=cv(Xp),[xu,Sv]=Xo(Xp,[Mue,pv,n8]),Zp=pv(),m8=n8(),[y8,sc]=xu(Xp),[Aue,Jp]=xu(Xp),S8=n=>{const{__scopeMenu:e,open:t=!1,children:r,dir:s,onOpenChange:i,modal:o=!0}=n,a=Zp(e),[l,c]=P.useState(null),d=P.useRef(!1),f=cr(i),g=t_(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})}},[]),p.jsx(h_,{...a,children:p.jsx(y8,{scope:e,open:t,onOpenChange:f,content:l,onContentChange:c,children:p.jsx(Aue,{scope:e,onClose:P.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:g,modal:o,children:r})})})};S8.displayName=Xp;var Oue="MenuAnchor",g_=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=Zp(t);return p.jsx(f_,{...s,...r,ref:e})});g_.displayName=Oue;var m_="MenuPortal",[Rue,v8]=xu(m_,{forceMount:void 0}),x8=n=>{const{__scopeMenu:e,forceMount:t,children:r,container:s}=n,i=sc(m_,e);return p.jsx(Rue,{scope:e,forceMount:t,children:p.jsx(oo,{present:t||i.open,children:p.jsx(Yp,{asChild:!0,container:s,children:r})})})};x8.displayName=m_;var Pi="MenuContent",[Due,y_]=xu(Pi),w8=P.forwardRef((n,e)=>{const t=v8(Pi,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,i=sc(Pi,n.__scopeMenu),o=Jp(Pi,n.__scopeMenu);return p.jsx(mp.Provider,{scope:n.__scopeMenu,children:p.jsx(oo,{present:r||i.open,children:p.jsx(mp.Slot,{scope:n.__scopeMenu,children:o.modal?p.jsx(jue,{...s,ref:e}):p.jsx(Nue,{...s,ref:e})})})})}),jue=P.forwardRef((n,e)=>{const t=sc(Pi,n.__scopeMenu),r=P.useRef(null),s=Wt(e,r);return P.useEffect(()=>{const i=r.current;if(i)return p_(i)},[]),p.jsx(S_,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:De(n.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),Nue=P.forwardRef((n,e)=>{const t=sc(Pi,n.__scopeMenu);return p.jsx(S_,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),Lue=Yd("MenuContent.ScrollLock"),S_=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:g,onDismiss:m,disableOutsideScroll:y,...v}=n,x=sc(Pi,t),b=Jp(Pi,t),C=Zp(t),E=m8(t),_=Tue(t),[M,A]=P.useState(null),O=P.useRef(null),D=Wt(e,O,x.onContentChange),B=P.useRef(0),U=P.useRef(""),G=P.useRef(0),z=P.useRef(null),N=P.useRef("right"),L=P.useRef(0),V=y?yv:P.Fragment,Z=y?{as:Lue,allowPinchZoom:!0}:void 0,W=Y=>{var Re,Ce;const re=U.current+Y,K=_().filter(_e=>!_e.disabled),ne=document.activeElement,ge=(Re=K.find(_e=>_e.ref.current===ne))==null?void 0:Re.textValue,Pe=K.map(_e=>_e.textValue),ce=Yue(Pe,re,ge),Be=(Ce=K.find(_e=>_e.textValue===ce))==null?void 0:Ce.ref.current;(function _e(We){U.current=We,window.clearTimeout(B.current),We!==""&&(B.current=window.setTimeout(()=>_e(""),1e3))})(re),Be&&setTimeout(()=>Be.focus())};P.useEffect(()=>()=>window.clearTimeout(B.current),[]),n_();const $=P.useCallback(Y=>{var K,ne;return N.current===((K=z.current)==null?void 0:K.side)&&Zue(Y,(ne=z.current)==null?void 0:ne.area)},[]);return p.jsx(Due,{scope:t,searchRef:U,onItemEnter:P.useCallback(Y=>{$(Y)&&Y.preventDefault()},[$]),onItemLeave:P.useCallback(Y=>{var re;$(Y)||((re=O.current)==null||re.focus(),A(null))},[$]),onTriggerLeave:P.useCallback(Y=>{$(Y)&&Y.preventDefault()},[$]),pointerGraceTimerRef:G,onPointerGraceIntentChange:P.useCallback(Y=>{z.current=Y},[]),children:p.jsx(V,{...Z,children:p.jsx(uv,{asChild:!0,trapped:s,onMountAutoFocus:De(i,Y=>{var re;Y.preventDefault(),(re=O.current)==null||re.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:p.jsx(qp,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:g,onDismiss:m,children:p.jsx(Fce,{asChild:!0,...E,dir:b.dir,orientation:"vertical",loop:r,currentTabStopId:M,onCurrentTabStopIdChange:A,onEntryFocus:De(l,Y=>{b.isUsingKeyboardRef.current||Y.preventDefault()}),preventScrollOnEntryFocus:!0,children:p.jsx(Q6,{role:"menu","aria-orientation":"vertical","data-state":F8(x.open),"data-radix-menu-content":"",dir:b.dir,...C,...v,ref:D,style:{outline:"none",...v.style},onKeyDown:De(v.onKeyDown,Y=>{const K=Y.target.closest("[data-radix-menu-content]")===Y.currentTarget,ne=Y.ctrlKey||Y.altKey||Y.metaKey,ge=Y.key.length===1;K&&(Y.key==="Tab"&&Y.preventDefault(),!ne&&ge&&W(Y.key));const Pe=O.current;if(Y.target!==Pe||!Iue.includes(Y.key))return;Y.preventDefault();const Be=_().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);g8.includes(Y.key)&&Be.reverse(),que(Be)}),onBlur:De(n.onBlur,Y=>{Y.currentTarget.contains(Y.target)||(window.clearTimeout(B.current),U.current="")}),onPointerMove:De(n.onPointerMove,yp(Y=>{const re=Y.target,K=L.current!==Y.clientX;if(Y.currentTarget.contains(re)&&K){const ne=Y.clientX>L.current?"right":"left";N.current=ne,L.current=Y.clientX}}))})})})})})})});w8.displayName=Pi;var Fue="MenuGroup",v_=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return p.jsx(bt.div,{role:"group",...r,ref:e})});v_.displayName=Fue;var zue="MenuLabel",b8=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return p.jsx(bt.div,{...r,ref:e})});b8.displayName=zue;var IS="MenuItem",CN="menu.itemSelect",vv=P.forwardRef((n,e)=>{const{disabled:t=!1,onSelect:r,...s}=n,i=P.useRef(null),o=Jp(IS,n.__scopeMenu),a=y_(IS,n.__scopeMenu),l=Wt(e,i),c=P.useRef(!1),d=()=>{const f=i.current;if(!t&&f){const g=new CustomEvent(CN,{bubbles:!0,cancelable:!0});f.addEventListener(CN,m=>r==null?void 0:r(m),{once:!0}),e_(f,g),g.defaultPrevented?c.current=!1:o.onClose()}};return p.jsx(C8,{...s,ref:l,disabled:t,onClick:De(n.onClick,d),onPointerDown:f=>{var g;(g=n.onPointerDown)==null||g.call(n,f),c.current=!0},onPointerUp:De(n.onPointerUp,f=>{var g;c.current||(g=f.currentTarget)==null||g.click()}),onKeyDown:De(n.onKeyDown,f=>{const g=a.searchRef.current!=="";t||g&&f.key===" "||kk.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});vv.displayName=IS;var C8=P.forwardRef((n,e)=>{const{__scopeMenu:t,disabled:r=!1,textValue:s,...i}=n,o=y_(IS,t),a=m8(t),l=P.useRef(null),c=Wt(e,l),[d,f]=P.useState(!1),[g,m]=P.useState("");return P.useEffect(()=>{const y=l.current;y&&m((y.textContent??"").trim())},[i.children]),p.jsx(mp.ItemSlot,{scope:t,disabled:r,textValue:s??g,children:p.jsx(zce,{asChild:!0,...a,focusable:!r,children:p.jsx(bt.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,yp(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:De(n.onPointerLeave,yp(y=>o.onItemLeave(y))),onFocus:De(n.onFocus,()=>f(!0)),onBlur:De(n.onBlur,()=>f(!1))})})})}),$ue="MenuCheckboxItem",P8=P.forwardRef((n,e)=>{const{checked:t=!1,onCheckedChange:r,...s}=n;return p.jsx(T8,{scope:n.__scopeMenu,checked:t,children:p.jsx(vv,{role:"menuitemcheckbox","aria-checked":ES(t)?"mixed":t,...s,ref:e,"data-state":b_(t),onSelect:De(s.onSelect,()=>r==null?void 0:r(ES(t)?!0:!t),{checkForDefaultPrevented:!1})})})});P8.displayName=$ue;var k8="MenuRadioGroup",[Bue,Uue]=xu(k8,{value:void 0,onValueChange:()=>{}}),I8=P.forwardRef((n,e)=>{const{value:t,onValueChange:r,...s}=n,i=cr(r);return p.jsx(Bue,{scope:n.__scopeMenu,value:t,onValueChange:i,children:p.jsx(v_,{...s,ref:e})})});I8.displayName=k8;var E8="MenuRadioItem",_8=P.forwardRef((n,e)=>{const{value:t,...r}=n,s=Uue(E8,n.__scopeMenu),i=t===s.value;return p.jsx(T8,{scope:n.__scopeMenu,checked:i,children:p.jsx(vv,{role:"menuitemradio","aria-checked":i,...r,ref:e,"data-state":b_(i),onSelect:De(r.onSelect,()=>{var o;return(o=s.onValueChange)==null?void 0:o.call(s,t)},{checkForDefaultPrevented:!1})})})});_8.displayName=E8;var x_="MenuItemIndicator",[T8,Hue]=xu(x_,{checked:!1}),M8=P.forwardRef((n,e)=>{const{__scopeMenu:t,forceMount:r,...s}=n,i=Hue(x_,t);return p.jsx(oo,{present:r||ES(i.checked)||i.checked===!0,children:p.jsx(bt.span,{...s,ref:e,"data-state":b_(i.checked)})})});M8.displayName=x_;var Kue="MenuSeparator",A8=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return p.jsx(bt.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});A8.displayName=Kue;var Wue="MenuArrow",O8=P.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=Zp(t);return p.jsx(e8,{...s,...r,ref:e})});O8.displayName=Wue;var w_="MenuSub",[Vue,R8]=xu(w_),D8=n=>{const{__scopeMenu:e,children:t,open:r=!1,onOpenChange:s}=n,i=sc(w_,e),o=Zp(e),[a,l]=P.useState(null),[c,d]=P.useState(null),f=cr(s);return P.useEffect(()=>(i.open===!1&&f(!1),()=>f(!1)),[i.open,f]),p.jsx(h_,{...o,children:p.jsx(y8,{scope:e,open:r,onOpenChange:f,content:c,onContentChange:d,children:p.jsx(Vue,{scope:e,contentId:Ra(),triggerId:Ra(),trigger:a,onTriggerChange:l,children:t})})})};D8.displayName=w_;var If="MenuSubTrigger",j8=P.forwardRef((n,e)=>{const t=sc(If,n.__scopeMenu),r=Jp(If,n.__scopeMenu),s=R8(If,n.__scopeMenu),i=y_(If,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]),p.jsx(g_,{asChild:!0,...c,children:p.jsx(C8,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":s.contentId,"data-state":F8(t.open),...n,ref:lv(e,s.onTriggerChange),onClick:f=>{var g;(g=n.onClick)==null||g.call(n,f),!(n.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:De(n.onPointerMove,yp(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,yp(f=>{var m,y;d();const g=(m=t.content)==null?void 0:m.getBoundingClientRect();if(g){const v=(y=t.content)==null?void 0:y.dataset.side,x=v==="right",b=x?-5:5,C=g[x?"left":"right"],E=g[x?"right":"left"];i.onPointerGraceIntentChange({area:[{x:f.clientX+b,y:f.clientY},{x:C,y:g.top},{x:E,y:g.top},{x:E,y:g.bottom},{x:C,y:g.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 g=i.searchRef.current!=="";n.disabled||g&&f.key===" "||Eue[r.dir].includes(f.key)&&(t.onOpenChange(!0),(m=t.content)==null||m.focus(),f.preventDefault())})})})});j8.displayName=If;var N8="MenuSubContent",L8=P.forwardRef((n,e)=>{const t=v8(Pi,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,i=sc(Pi,n.__scopeMenu),o=Jp(Pi,n.__scopeMenu),a=R8(N8,n.__scopeMenu),l=P.useRef(null),c=Wt(e,l);return p.jsx(mp.Provider,{scope:n.__scopeMenu,children:p.jsx(oo,{present:r||i.open,children:p.jsx(mp.Slot,{scope:n.__scopeMenu,children:p.jsx(S_,{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),g=_ue[o.dir].includes(d.key);f&&g&&(i.onOpenChange(!1),(m=a.trigger)==null||m.focus(),d.preventDefault())})})})})})});L8.displayName=N8;function F8(n){return n?"open":"closed"}function ES(n){return n==="indeterminate"}function b_(n){return ES(n)?"indeterminate":n?"checked":"unchecked"}function que(n){const e=document.activeElement;for(const t of n)if(t===e||(t.focus(),document.activeElement!==e))return}function Gue(n,e){return n.map((t,r)=>n[(e+r)%n.length])}function Yue(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=Gue(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 Xue(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 Zue(n,e){if(!e)return!1;const t={x:n.clientX,y:n.clientY};return Xue(t,e)}function yp(n){return e=>e.pointerType==="mouse"?n(e):void 0}var z8=S8,$8=g_,B8=x8,U8=w8,H8=v_,K8=b8,W8=vv,V8=P8,q8=I8,G8=_8,Y8=M8,X8=A8,Z8=O8,J8=D8,Q8=j8,eU=L8,C_="ContextMenu",[Jue,Dbe]=Xo(C_,[Sv]),Ar=Sv(),[Que,tU]=Jue(C_),nU=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,dir:s,modal:i=!0}=n,[o,a]=P.useState(!1),l=Ar(e),c=cr(r),d=P.useCallback(f=>{a(f),c(f)},[c]);return p.jsx(Que,{scope:e,open:o,onOpenChange:d,modal:i,children:p.jsx(z8,{...l,dir:s,open:o,onOpenChange:d,modal:i,children:t})})};nU.displayName=C_;var rU="ContextMenuTrigger",sU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,disabled:r=!1,...s}=n,i=tU(rU,t),o=Ar(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=g=>{a.current={x:g.clientX,y:g.clientY},i.onOpenChange(!0)};return P.useEffect(()=>d,[d]),P.useEffect(()=>void(r&&d()),[r,d]),p.jsxs(p.Fragment,{children:[p.jsx($8,{...o,virtualRef:l}),p.jsx(bt.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,g=>{d(),f(g),g.preventDefault()}),onPointerDown:r?n.onPointerDown:De(n.onPointerDown,Nm(g=>{d(),c.current=window.setTimeout(()=>f(g),700)})),onPointerMove:r?n.onPointerMove:De(n.onPointerMove,Nm(d)),onPointerCancel:r?n.onPointerCancel:De(n.onPointerCancel,Nm(d)),onPointerUp:r?n.onPointerUp:De(n.onPointerUp,Nm(d))})]})});sU.displayName=rU;var ede="ContextMenuPortal",P_=n=>{const{__scopeContextMenu:e,...t}=n,r=Ar(e);return p.jsx(B8,{...r,...t})};P_.displayName=ede;var iU="ContextMenuContent",oU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=tU(iU,t),i=Ar(t),o=P.useRef(!1);return p.jsx(U8,{...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)"}})});oU.displayName=iU;var tde="ContextMenuGroup",aU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(H8,{...s,...r,ref:e})});aU.displayName=tde;var nde="ContextMenuLabel",rde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(K8,{...s,...r,ref:e})});rde.displayName=nde;var sde="ContextMenuItem",lU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(W8,{...s,...r,ref:e})});lU.displayName=sde;var ide="ContextMenuCheckboxItem",cU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(V8,{...s,...r,ref:e})});cU.displayName=ide;var ode="ContextMenuRadioGroup",ade=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(q8,{...s,...r,ref:e})});ade.displayName=ode;var lde="ContextMenuRadioItem",cde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(G8,{...s,...r,ref:e})});cde.displayName=lde;var ude="ContextMenuItemIndicator",dde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(Y8,{...s,...r,ref:e})});dde.displayName=ude;var hde="ContextMenuSeparator",fde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(X8,{...s,...r,ref:e})});fde.displayName=hde;var pde="ContextMenuArrow",gde=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(Z8,{...s,...r,ref:e})});gde.displayName=pde;var mde="ContextMenuSub",uU=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,open:s,defaultOpen:i}=n,o=Ar(e),[a,l]=rc({prop:s,defaultProp:i,onChange:r});return p.jsx(J8,{...o,open:a,onOpenChange:l,children:t})};uU.displayName=mde;var yde="ContextMenuSubTrigger",dU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(Q8,{...s,...r,ref:e})});dU.displayName=yde;var Sde="ContextMenuSubContent",hU=P.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Ar(t);return p.jsx(eU,{...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)"}})});hU.displayName=Sde;function Nm(n){return e=>e.pointerType!=="mouse"?n(e):void 0}var vde=nU,xde=sU,wde=P_,bde=oU,Cde=cU,k_="DropdownMenu",[Pde,jbe]=Xo(k_,[Sv]),Or=Sv(),[kde,fU]=Pde(k_),pU=n=>{const{__scopeDropdownMenu:e,children:t,dir:r,open:s,defaultOpen:i,onOpenChange:o,modal:a=!0}=n,l=Or(e),c=P.useRef(null),[d=!1,f]=rc({prop:s,defaultProp:i,onChange:o});return p.jsx(kde,{scope:e,triggerId:Ra(),triggerRef:c,contentId:Ra(),open:d,onOpenChange:f,onOpenToggle:P.useCallback(()=>f(g=>!g),[f]),modal:a,children:p.jsx(z8,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:t})})};pU.displayName=k_;var gU="DropdownMenuTrigger",mU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...s}=n,i=fU(gU,t),o=Or(t);return p.jsx($8,{asChild:!0,...o,children:p.jsx(bt.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:lv(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())})})})});mU.displayName=gU;var Ide="DropdownMenuPortal",yU=n=>{const{__scopeDropdownMenu:e,...t}=n,r=Or(e);return p.jsx(B8,{...r,...t})};yU.displayName=Ide;var SU="DropdownMenuContent",vU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=fU(SU,t),i=Or(t),o=P.useRef(!1);return p.jsx(U8,{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)"}})});vU.displayName=SU;var Ede="DropdownMenuGroup",xU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(H8,{...s,...r,ref:e})});xU.displayName=Ede;var _de="DropdownMenuLabel",Tde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(K8,{...s,...r,ref:e})});Tde.displayName=_de;var Mde="DropdownMenuItem",wU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(W8,{...s,...r,ref:e})});wU.displayName=Mde;var Ade="DropdownMenuCheckboxItem",bU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(V8,{...s,...r,ref:e})});bU.displayName=Ade;var Ode="DropdownMenuRadioGroup",Rde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(q8,{...s,...r,ref:e})});Rde.displayName=Ode;var Dde="DropdownMenuRadioItem",jde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(G8,{...s,...r,ref:e})});jde.displayName=Dde;var Nde="DropdownMenuItemIndicator",Lde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(Y8,{...s,...r,ref:e})});Lde.displayName=Nde;var Fde="DropdownMenuSeparator",zde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(X8,{...s,...r,ref:e})});zde.displayName=Fde;var $de="DropdownMenuArrow",Bde=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(Z8,{...s,...r,ref:e})});Bde.displayName=$de;var Ude=n=>{const{__scopeDropdownMenu:e,children:t,open:r,onOpenChange:s,defaultOpen:i}=n,o=Or(e),[a=!1,l]=rc({prop:r,defaultProp:i,onChange:s});return p.jsx(J8,{...o,open:a,onOpenChange:l,children:t})},Hde="DropdownMenuSubTrigger",CU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(Q8,{...s,...r,ref:e})});CU.displayName=Hde;var Kde="DropdownMenuSubContent",PU=P.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=Or(t);return p.jsx(eU,{...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)"}})});PU.displayName=Kde;var I_=pU,E_=mU,xv=yU,__=vU,Wde=xU,Vde=wU,qde=bU,Gde=Ude,Yde=CU,Xde=PU;function Ht(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=kU(n,i);o.length&&r.set(i,o)}for(const[i,o]of r){const a=n.getShapeUtil(i),l=rt(o.map(c=>n.getShape(c)));(s=a.onDragShapesOut)==null||s.call(a,i,l)}}function kU(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:g}=n.getShapeGeometry(l);if(!f.some(m=>Ws(m,d))){if(g){if(HE(d,f))continue}else if(fse(d,f))continue;a.push(l)}}return a}function _S(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 Zde(n,e){const t=rt(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 Jde=50;function Qde(n,e,t={}){const r=n.getShape(e);if(!r)return;const s=n.getSortedChildIdsForParent(r.id),i=rt(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=Jde}=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 g=new k(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-g.x,y:r.y-g.y,props:{w:l,h:c}}),n.updateShapes(m)})}const IU=P.createContext(null);function ehe({assetUrls:n,children:e}){return P.useEffect(()=>{for(const t of Object.values(n.icons)){const r=Jf();r.src=t,r.decode()}for(const t of Object.values(n.embedIcons)){const r=Jf();r.src=t,r.decode()}},[n]),p.jsx(IU.Provider,{value:n,children:e})}function T_(){const n=P.useContext(IU);if(!n)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return n}const Ik={"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.heart":"Heart","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","people-menu.anonymous-user":"New user","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…"},the=new Set(["ar","fa","he","ur","ku"]),pd={locale:"en",label:"English",messages:Ik,dir:"ltr"};async function nhe(n,e){if(!(await Gi(e.translations.en)).ok)return console.warn("No main translations found."),pd;if(n==="en")return pd;const r=dp.find(o=>o.locale===n);if(!r)return console.warn(`No translation found for locale ${n}`),pd;const i=await(await Gi(e.translations[r.locale])).json();if(!i)return console.warn(`No messages found for locale ${n}`),pd;for(const o in pd.messages)i[o];return{locale:n,label:r.label,dir:the.has(r.locale)?"rtl":"ltr",messages:{...pd.messages,...i}}}const EU=P.createContext(null);function _U(){const n=P.useContext(EU);if(!n)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return n}function rhe({overrides:n,locale:e,children:t}){const r=T_(),[s,i]=P.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...Ik,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:Ik});return P.useEffect(()=>{let o=!1;async function a(){const l=await nhe(e,r);l&&!o&&(n&&n[e]?i({...l,messages:{...l.messages,...n[e]}}):i(l))}return a(),()=>{o=!0}},[r,e,n]),p.jsx(EU.Provider,{value:s,children:t})}function gt(){const n=_U();return P.useCallback(function(t){return n.messages[t]??t},[n])}const He=P.forwardRef(function({children:e,type:t,isActive:r,...s},i){return p.jsx("button",{ref:i,type:"button",draggable:!1,"data-isactive":r,...s,className:ze("tlui-button",`tlui-button__${t}`,s.className),children:e})});function Pn({children:n}){return p.jsx("span",{className:"tlui-button__label",children:n})}var M_="Dialog",[TU,Nbe]=Xo(M_),[she,ao]=TU(M_),MU=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]=rc({prop:r,defaultProp:s,onChange:i});return p.jsx(she,{scope:e,triggerRef:a,contentRef:l,contentId:Ra(),titleId:Ra(),descriptionId:Ra(),open:c,onOpenChange:d,onOpenToggle:P.useCallback(()=>d(f=>!f),[d]),modal:o,children:t})};MU.displayName=M_;var AU="DialogTrigger",ihe=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ao(AU,t),i=Wt(e,s.triggerRef);return p.jsx(bt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":R_(s.open),...r,ref:i,onClick:De(n.onClick,s.onOpenToggle)})});ihe.displayName=AU;var A_="DialogPortal",[ohe,OU]=TU(A_,{forceMount:void 0}),RU=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:s}=n,i=ao(A_,e);return p.jsx(ohe,{scope:e,forceMount:t,children:P.Children.map(r,o=>p.jsx(oo,{present:t||i.open,children:p.jsx(Yp,{asChild:!0,container:s,children:o})}))})};RU.displayName=A_;var TS="DialogOverlay",DU=P.forwardRef((n,e)=>{const t=OU(TS,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,i=ao(TS,n.__scopeDialog);return i.modal?p.jsx(oo,{present:r||i.open,children:p.jsx(lhe,{...s,ref:e})}):null});DU.displayName=TS;var ahe=Yd("DialogOverlay.RemoveScroll"),lhe=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ao(TS,t);return p.jsx(yv,{as:ahe,allowPinchZoom:!0,shards:[s.contentRef],children:p.jsx(bt.div,{"data-state":R_(s.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),ou="DialogContent",jU=P.forwardRef((n,e)=>{const t=OU(ou,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,i=ao(ou,n.__scopeDialog);return p.jsx(oo,{present:r||i.open,children:i.modal?p.jsx(che,{...s,ref:e}):p.jsx(uhe,{...s,ref:e})})});jU.displayName=ou;var che=P.forwardRef((n,e)=>{const t=ao(ou,n.__scopeDialog),r=P.useRef(null),s=Wt(e,t.contentRef,r);return P.useEffect(()=>{const i=r.current;if(i)return p_(i)},[]),p.jsx(NU,{...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())})}),uhe=P.forwardRef((n,e)=>{const t=ao(ou,n.__scopeDialog),r=P.useRef(!1),s=P.useRef(!1);return p.jsx(NU,{...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()}})}),NU=P.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:i,...o}=n,a=ao(ou,t),l=P.useRef(null),c=Wt(e,l);return n_(),p.jsxs(p.Fragment,{children:[p.jsx(uv,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:i,children:p.jsx(qp,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":R_(a.open),...o,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),p.jsxs(p.Fragment,{children:[p.jsx(hhe,{titleId:a.titleId}),p.jsx(phe,{contentRef:l,descriptionId:a.descriptionId})]})]})}),O_="DialogTitle",LU=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ao(O_,t);return p.jsx(bt.h2,{id:s.titleId,...r,ref:e})});LU.displayName=O_;var FU="DialogDescription",dhe=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ao(FU,t);return p.jsx(bt.p,{id:s.descriptionId,...r,ref:e})});dhe.displayName=FU;var zU="DialogClose",$U=P.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=ao(zU,t);return p.jsx(bt.button,{type:"button",...r,ref:e,onClick:De(n.onClick,()=>s.onOpenChange(!1))})});$U.displayName=zU;function R_(n){return n?"open":"closed"}var BU="DialogTitleWarning",[Lbe,UU]=Wae(BU,{contentName:ou,titleName:O_,docsSlug:"dialog"}),hhe=({titleId:n})=>{const e=UU(BU),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
344
+
345
+ If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
346
+
347
+ 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},fhe="DialogDescriptionWarning",phe=({contentRef:n,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${UU(fhe).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},ghe=MU,mhe=RU,yhe=DU,She=jU,vhe=LU;const Ko=P.memo(function({small:e,invertIcon:t,icon:r,color:s,className:i,...o}){const a=T_(),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"?p.jsx("div",{className:ze("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},i)}):p.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 p.jsx(Ko,{className:"tlui-button__icon",icon:n,small:e,invertIcon:t})}function wv({className:n,children:e}){return p.jsx("div",{className:ze("tlui-dialog__header",n),children:e})}function bv({className:n,children:e,style:t}){return p.jsx(vhe,{dir:"ltr",className:ze("tlui-dialog__header__title",n),style:t,children:e})}function Cv(){return p.jsx("div",{className:"tlui-dialog__header__close",children:p.jsx($U,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:p.jsx(He,{type:"icon","aria-label":"Close",onTouchEnd:n=>n.target.click(),children:p.jsx(ct,{small:!0,icon:"cross-2"})})})})}function Sp({className:n,children:e,style:t}){return p.jsx("div",{className:ze("tlui-dialog__body",n),style:t,children:e})}function D_({className:n,children:e}){return p.jsx("div",{className:ze("tlui-dialog__footer",n),children:e})}const Qp=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:g,onBlur:m,shouldManuallyMaintainScrollPositionWhenFocused:y=!1,children:v,value:x,"data-testid":b},C){const E=Mr(),_=P.useRef(null);P.useImperativeHandle(C,()=>_.current);const M=gt(),A=P.useRef(a??""),O=P.useRef(a??""),D=P.useRef(!1),[B,U]=P.useState(!1),G=P.useCallback(W=>{U(!0);const $=W.currentTarget;O.current=$.value,E?E.timers.requestAnimationFrame(()=>{i&&$.select()}):wS.requestAnimationFrame("anon",()=>{i&&$.select()}),g==null||g()},[i,E,g]),z=P.useCallback(W=>{const $=W.currentTarget.value;O.current=$,d==null||d($)},[d]),N=P.useCallback(W=>{switch(W.key){case"Enter":{if(D.current)return;W.currentTarget.blur(),Zt(W),c==null||c(W.currentTarget.value);break}case"Escape":{W.currentTarget.value=A.current,f==null||f(W.currentTarget.value),W.currentTarget.blur(),Zt(W);break}}},[c,f]),L=P.useCallback(W=>{U(!1);const $=W.currentTarget.value;m==null||m($)},[m]),V=P.useCallback(()=>D.current=!0,[]),Z=P.useCallback(()=>D.current=!1,[]);return P.useEffect(()=>{if(!kt.isIos)return;const W=window.visualViewport;if(B&&y&&W){const $=()=>{var Y;(Y=_.current)==null||Y.scrollIntoView({block:"center"})};return W.addEventListener("resize",$),W.addEventListener("scroll",$),E?E.timers.requestAnimationFrame(()=>{var Y;(Y=_.current)==null||Y.scrollIntoView({block:"center"})}):wS.requestAnimationFrame("anon",()=>{var Y;(Y=_.current)==null||Y.scrollIntoView({block:"center"})}),()=>{W.removeEventListener("resize",$),W.removeEventListener("scroll",$)}}},[B,E,y]),p.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[v,t&&p.jsx("label",{children:M(t)}),s&&p.jsx(Ko,{icon:s,className:"tlui-icon-left",small:!0}),p.jsx("input",{ref:_,className:ze("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:N,onChange:z,onFocus:G,onBlur:L,onCompositionStart:V,onCompositionEnd:Z,autoFocus:o,placeholder:l,value:x,"data-testid":b}),r&&p.jsx(Ko,{icon:r,small:!!t})]})});function PN(n){return Ys.isValid(n)?{isValid:!0,hasProtocol:!0}:Ys.isValid("https://"+n)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const xhe=Gn(function({onClose:e}){const r=Q().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?p.jsx(whe,{onClose:e,selectedShape:r}):null}),whe=Gn(function({onClose:e,selectedShape:t}){const r=Q(),s=gt(),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=PN(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,E)=>E),x=PN(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]),g=P.useCallback(()=>{e()},[e]);if(!t)return e(),null;const m=o.current&&!a.valid;return p.jsxs(p.Fragment,{children:[p.jsxs(wv,{children:[p.jsx(bv,{children:s("edit-link-dialog.title")}),p.jsx(Cv,{})]}),p.jsx(Sp,{children:p.jsxs("div",{className:"tlui-edit-link-dialog",children:[p.jsx(Qp,{ref:i,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:f,onCancel:g}),p.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),p.jsxs(D_,{className:"tlui-dialog__footer__actions",children:[p.jsx(He,{type:"normal",onClick:g,onTouchEnd:g,children:p.jsx(Pn,{children:s("edit-link-dialog.cancel")})}),m?p.jsx(He,{type:"danger",onTouchEnd:d,onClick:d,children:p.jsx(Pn,{children:s("edit-link-dialog.clear")})}):p.jsx(He,{type:"primary",disabled:!a.valid,onTouchEnd:f,onClick:f,children:p.jsx(Pn,{children:s("edit-link-dialog.save")})})]})]})});var bhe={};const kN=/(^\/[f|p|r|ro|s|v]\/[^/]+\/?$)/,j_=[{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=Ze(n);if(e&&e.pathname.match(kN))return e.searchParams.append("embed","true"),n},fromEmbedUrl:n=>{const e=Ze(n);if(e&&e.pathname.match(kN))return e.searchParams.delete("embed"),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=Ze(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|m)/);let t;if(e){const[,r,s,i,o]=e,a=o==="z"?"roadmap":"satellite",l=a==="roadmap"?i:-Math.log2(parseInt(i)/14772321)/.8;t=`https://${new URL(n).host.replace("www.","")}/maps/embed/v1/view?key=${bhe.NEXT_PUBLIC_GC_API_KEY}&center=${r},${s}&zoom=${l}&maptype=${a}`}else t="";return t}},fromEmbedUrl:n=>{const e=Ze(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")??"12",s=e.searchParams.get("maptype")??"roadmap",i=s==="roadmap"?r:14772321*Math.pow(2,parseInt(r)*-.8),[o,a]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${a},${i}${s==="roadmap"?"z":"m"}`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:n=>{const e=Ze(n),t=e&&e.pathname.match(/\/v\/(.+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Ze(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=Ze(n),t=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Ze(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=Ze(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=Ze(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=Ze(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=Ze(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=Ze(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=Ze(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=Ze(n);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return n.split("/").pop()?n:void 0},fromEmbedUrl:n=>{const e=Ze(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=Ze(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${n}?embed=true`},fromEmbedUrl:n=>{const e=Ze(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=Ze(n);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Ze(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=Ze(n);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Ze(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=Ze(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=Ze(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=Ze(n);if(e&&e.hash.match(/#room=/))return n},fromEmbedUrl:n=>{const e=Ze(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=Ze(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=Ze(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=Ze(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${n}?embed`},fromEmbedUrl:n=>{const e=Ze(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],Che={"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},Phe=j_.map(n=>n.type);function khe(n){return Phe.includes(n)}function Ihe(n){return"icon"in n}function HU(){const n=Mr();if(n&&n.hasShapeUtil("embed"))return n.getShapeUtil("embed")}function N_(){const n=HU();return e=>n?n.getEmbedDefinition(e):void 0}function Ehe(){const n=HU();return n?n.getEmbedDefinitions():[]}const KU=Gn(function({onClose:e}){const t=Q(),r=gt(),s=T_(),[i,o]=P.useState(null),[a,l]=P.useState(""),[c,d]=P.useState(null),[f,g]=P.useState(!1),m=P.useRef(-1),y=Ehe(),v=N_();return p.jsxs(p.Fragment,{children:[p.jsxs(wv,{children:[p.jsx(bv,{children:i?`${r("embed-dialog.title")} — ${i.title}`:r("embed-dialog.title")}),p.jsx(Cv,{})]}),i?p.jsxs(p.Fragment,{children:[p.jsxs(Sp,{className:"tlui-embed-dialog__enter",children:[p.jsx(Qp,{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),g(!1),clearTimeout(m.current),m.current=t.timers.setTimeout(()=>g(!b),320)}}),a===""?p.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[p.jsx("span",{children:r("embed-dialog.instruction")})," ",i.instructionLink&&p.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:i.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",p.jsx(Ko,{icon:"external-link",small:!0})]})]}):p.jsx("div",{className:"tlui-embed-dialog__warning",children:f?r("embed-dialog.invalid-url"):" "})]}),p.jsxs(D_,{className:"tlui-dialog__footer__actions",children:[p.jsx(He,{type:"normal",onClick:()=>{o(null),d(null),l("")},children:p.jsx(Pn,{children:r("embed-dialog.back")})}),p.jsx("div",{className:"tlui-embed__spacer"}),p.jsx(He,{type:"normal",onClick:e,children:p.jsx(Pn,{children:r("embed-dialog.cancel")})}),p.jsx(He,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:c.definition}),e())},children:p.jsx(Pn,{children:r("embed-dialog.create")})})]})]}):p.jsx(p.Fragment,{children:p.jsx(Sp,{className:"tlui-embed-dialog__list",children:y.map(x=>{const b=khe(x.type)?s.embedIcons[x.type]:Ihe(x)?x.icon:void 0;return p.jsxs(He,{type:"menu",onClick:()=>o(x),children:[p.jsx(Pn,{children:x.title}),b&&p.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${b})`}})]},x.type)})})})]})});async function _he(n,e,t){const r=rt(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 Ps(()=>{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 g="a1";for(const b of d)if(b.parentId===f){b.index>g&&(g=b.index);break}let m,y,v;if(ys(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 k(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=jt();n.createShape({id:x,type:"image",index:g,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 Pv(){const n=Mr();return(n==null?void 0:n.store.props.collaboration)!==void 0}function The(){const n=Mr();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 OC=[0,389,436,476,580,640,840,1023];var dn=(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))(dn||{});const WU=ot.createContext(null);function Mhe({forceMobile:n=!1,children:e}){const t=Mr(),r=ie("breakpoint",()=>{const{width:s}=(t==null?void 0:t.getViewportScreenBounds())??{width:window.innerWidth},i=n?dn.MOBILE_SM:OC.length-1;for(let o=0;o<i;o++)if(s>OC[o]&&s<=OC[o+1])return o;return i},[t]);return p.jsx(WU.Provider,{value:r,children:e})}function Rr(){const n=P.useContext(WU);if(n===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return n}const Ek=P.createContext(null);function Ahe({context:n,children:e}){const t=P.useContext(Ek),r=jn(),s=b0("dialogs",[]),i=P.useMemo(()=>({dialogs:s,addDialog(o){const a=o.id??Tt();return s.update(l=>[...l.filter(c=>c.id!==o.id),{...o,id:a}]),r("open-menu",{source:"dialog",id:a}),$r.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}),$r.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}),$r.deleteOpenMenu(a.id,n)}),s.set([]))}}),[r,s,n]);return t?p.jsx(p.Fragment,{children:e}):p.jsx(Ek.Provider,{value:i,children:e})}function eg(){const n=P.useContext(Ek);if(!n)throw new Error("useDialogs must be used within a DialogsProvider");return n}var Ohe="VisuallyHidden",L_=P.forwardRef((n,e)=>p.jsx(bt.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}}));L_.displayName=Ohe;var F_="ToastProvider",[z_,Rhe,Dhe]=cv("Toast"),[VU,Fbe]=Xo("Toast",[Dhe]),[jhe,kv]=VU(F_),qU=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),g=P.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${F_}\`. Expected non-empty \`string\`.`),p.jsx(z_.Provider,{scope:e,children:p.jsx(jhe,{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:g,children:o})})};qU.displayName=F_;var GU="ToastViewport",Nhe=["F8"],_k="toast.viewportPause",Tk="toast.viewportResume",YU=P.forwardRef((n,e)=>{const{__scopeToast:t,hotkey:r=Nhe,label:s="Notifications ({hotkey})",...i}=n,o=kv(GU,t),a=Rhe(t),l=P.useRef(null),c=P.useRef(null),d=P.useRef(null),f=P.useRef(null),g=Wt(e,f,o.onViewportChange),m=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=o.toastCount>0;P.useEffect(()=>{const x=b=>{var E;r.length!==0&&r.every(_=>b[_]||b.code===_)&&((E=f.current)==null||E.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(_k);b.dispatchEvent(A),o.isClosePausedRef.current=!0}},E=()=>{if(o.isClosePausedRef.current){const A=new CustomEvent(Tk);b.dispatchEvent(A),o.isClosePausedRef.current=!1}},_=A=>{!x.contains(A.relatedTarget)&&E()},M=()=>{x.contains(document.activeElement)||E()};return x.addEventListener("focusin",C),x.addEventListener("focusout",_),x.addEventListener("pointermove",C),x.addEventListener("pointerleave",M),window.addEventListener("blur",C),window.addEventListener("focus",E),()=>{x.removeEventListener("focusin",C),x.removeEventListener("focusout",_),x.removeEventListener("pointermove",C),x.removeEventListener("pointerleave",M),window.removeEventListener("blur",C),window.removeEventListener("focus",E)}}},[y,o.isClosePausedRef]);const v=P.useCallback(({tabbingDirection:x})=>{const C=a().map(E=>{const _=E.ref.current,M=[_,...Yhe(_)];return x==="forwards"?M:M.reverse()});return(x==="forwards"?C.reverse():C).flat()},[a]);return P.useEffect(()=>{const x=f.current;if(x){const b=C=>{var M,A,O;const E=C.altKey||C.ctrlKey||C.metaKey;if(C.key==="Tab"&&!E){const D=document.activeElement,B=C.shiftKey;if(C.target===x&&B){(M=c.current)==null||M.focus();return}const z=v({tabbingDirection:B?"backwards":"forwards"}),N=z.findIndex(L=>L===D);RC(z.slice(N+1))?C.preventDefault():B?(A=c.current)==null||A.focus():(O=d.current)==null||O.focus()}};return x.addEventListener("keydown",b),()=>x.removeEventListener("keydown",b)}},[a,v]),p.jsxs(lle,{ref:l,role:"region","aria-label":s.replace("{hotkey}",m),tabIndex:-1,style:{pointerEvents:y?void 0:"none"},children:[y&&p.jsx(Mk,{ref:c,onFocusFromOutsideViewport:()=>{const x=v({tabbingDirection:"forwards"});RC(x)}}),p.jsx(z_.Slot,{scope:t,children:p.jsx(bt.ol,{tabIndex:-1,...i,ref:g})}),y&&p.jsx(Mk,{ref:d,onFocusFromOutsideViewport:()=>{const x=v({tabbingDirection:"backwards"});RC(x)}})]})});YU.displayName=GU;var XU="ToastFocusProxy",Mk=P.forwardRef((n,e)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...s}=n,i=kv(XU,t);return p.jsx(L_,{"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()}})});Mk.displayName=XU;var Iv="Toast",Lhe="toast.swipeStart",Fhe="toast.swipeMove",zhe="toast.swipeCancel",$he="toast.swipeEnd",ZU=P.forwardRef((n,e)=>{const{forceMount:t,open:r,defaultOpen:s,onOpenChange:i,...o}=n,[a=!0,l]=rc({prop:r,defaultProp:s,onChange:i});return p.jsx(oo,{present:t||a,children:p.jsx(Hhe,{open:a,...o,ref:e,onClose:()=>l(!1),onPause:cr(n.onPause),onResume:cr(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)})})})});ZU.displayName=Iv;var[Bhe,Uhe]=VU(Iv,{onClose(){}}),Hhe=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:g,onSwipeEnd:m,...y}=n,v=kv(Iv,t),[x,b]=P.useState(null),C=Wt(e,L=>b(L)),E=P.useRef(null),_=P.useRef(null),M=s||v.duration,A=P.useRef(0),O=P.useRef(M),D=P.useRef(0),{onToastAdd:B,onToastRemove:U}=v,G=cr(()=>{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(D.current),A.current=new Date().getTime(),D.current=window.setTimeout(G,L))},[G]);P.useEffect(()=>{const L=v.viewport;if(L){const V=()=>{z(O.current),c==null||c()},Z=()=>{const W=new Date().getTime()-A.current;O.current=O.current-W,window.clearTimeout(D.current),l==null||l()};return L.addEventListener(_k,Z),L.addEventListener(Tk,V),()=>{L.removeEventListener(_k,Z),L.removeEventListener(Tk,V)}}},[v.viewport,M,l,c,z]),P.useEffect(()=>{i&&!v.isClosePausedRef.current&&z(M)},[i,M,v.isClosePausedRef,z]),P.useEffect(()=>(B(),()=>U()),[B,U]);const N=P.useMemo(()=>x?s9(x):null,[x]);return v.viewport?p.jsxs(p.Fragment,{children:[N&&p.jsx(Khe,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:N}),p.jsx(Bhe,{scope:t,onClose:G,children:hh.createPortal(p.jsx(z_.ItemSlot,{scope:t,children:p.jsx(ale,{asChild:!0,onEscapeKeyDown:De(a,()=>{v.isFocusedToastEscapeKeyDownRef.current||G(),v.isFocusedToastEscapeKeyDownRef.current=!1}),children:p.jsx(bt.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,G()))}),onPointerDown:De(n.onPointerDown,L=>{L.button===0&&(E.current={x:L.clientX,y:L.clientY})}),onPointerMove:De(n.onPointerMove,L=>{if(!E.current)return;const V=L.clientX-E.current.x,Z=L.clientY-E.current.y,W=!!_.current,$=["left","right"].includes(v.swipeDirection),Y=["left","up"].includes(v.swipeDirection)?Math.min:Math.max,re=$?Y(0,V):0,K=$?0:Y(0,Z),ne=L.pointerType==="touch"?10:2,ge={x:re,y:K},Pe={originalEvent:L,delta:ge};W?(_.current=ge,Lm(Fhe,f,Pe,{discrete:!1})):IN(ge,v.swipeDirection,ne)?(_.current=ge,Lm(Lhe,d,Pe,{discrete:!1}),L.target.setPointerCapture(L.pointerId)):(Math.abs(V)>ne||Math.abs(Z)>ne)&&(E.current=null)}),onPointerUp:De(n.onPointerUp,L=>{const V=_.current,Z=L.target;if(Z.hasPointerCapture(L.pointerId)&&Z.releasePointerCapture(L.pointerId),_.current=null,E.current=null,V){const W=L.currentTarget,$={originalEvent:L,delta:V};IN(V,v.swipeDirection,v.swipeThreshold)?Lm($he,m,$,{discrete:!0}):Lm(zhe,g,$,{discrete:!0}),W.addEventListener("click",Y=>Y.preventDefault(),{once:!0})}})})})}),v.viewport)})]}):null}),Khe=n=>{const{__scopeToast:e,children:t,...r}=n,s=kv(Iv,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:p.jsx(Yp,{asChild:!0,children:p.jsx(L_,{...r,children:i&&p.jsxs(p.Fragment,{children:[s.label," ",t]})})})},Whe="ToastTitle",JU=P.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return p.jsx(bt.div,{...r,ref:e})});JU.displayName=Whe;var Vhe="ToastDescription",QU=P.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return p.jsx(bt.div,{...r,ref:e})});QU.displayName=Vhe;var e9="ToastAction",t9=P.forwardRef((n,e)=>{const{altText:t,...r}=n;return t.trim()?p.jsx(r9,{altText:t,asChild:!0,children:p.jsx($_,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${e9}\`. Expected non-empty \`string\`.`),null)});t9.displayName=e9;var n9="ToastClose",$_=P.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n,s=Uhe(n9,t);return p.jsx(r9,{asChild:!0,children:p.jsx(bt.button,{type:"button",...r,ref:e,onClick:De(n.onClick,s.onClose)})})});$_.displayName=n9;var r9=P.forwardRef((n,e)=>{const{__scopeToast:t,altText:r,...s}=n;return p.jsx(bt.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function s9(n){const e=[];return Array.from(n.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),Ghe(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(...s9(r))}}),e}function Lm(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?e_(s,i):s.dispatchEvent(i)}var IN=(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=cr(n);Wl(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[e])}function Ghe(n){return n.nodeType===n.ELEMENT_NODE}function Yhe(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 RC(n){const e=document.activeElement;return n.some(t=>t===e?!0:(t.focus(),document.activeElement!==e))}var Xhe=ZU,Zhe=JU,Jhe=QU,Qhe=t9,EN=$_;const Ak=P.createContext(null);function efe({children:n}){const e=b0("toasts",[]),t=P.useContext(Ak),r=P.useMemo(()=>({toasts:e,addToast(s){const i=s.id??Tt();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?p.jsx(p.Fragment,{children:n}):p.jsx(qU,{children:p.jsx(Ak.Provider,{value:r,children:n})})}function Wa(){const n=P.useContext(Ak);if(!n)throw new Error("useToasts must be used within a ToastsProvider");return n}var DC={exports:{}},_N;function tfe(){return _N||(_N=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,g=c.length;f<g;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 g=[];return c.forEach(function(m){g.push(t(m))}),a.decompress(g.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,g,m={},y={},v="",x="",b="",C=2,E=3,_=2,M=[],A=0,O=0,D;for(D=0;D<l.length;D+=1)if(v=l.charAt(D),Object.prototype.hasOwnProperty.call(m,v)||(m[v]=E++,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,O==c-1?(O=0,M.push(d(A)),A=0):O++;for(g=b.charCodeAt(0),f=0;f<8;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1}else{for(g=1,f=0;f<_;f++)A=A<<1|g,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=0;for(g=b.charCodeAt(0),f=0;f<16;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1}C--,C==0&&(C=Math.pow(2,_),_++),delete y[b]}else for(g=m[b],f=0;f<_;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1;C--,C==0&&(C=Math.pow(2,_),_++),m[x]=E++,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,O==c-1?(O=0,M.push(d(A)),A=0):O++;for(g=b.charCodeAt(0),f=0;f<8;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1}else{for(g=1,f=0;f<_;f++)A=A<<1|g,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=0;for(g=b.charCodeAt(0),f=0;f<16;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1}C--,C==0&&(C=Math.pow(2,_),_++),delete y[b]}else for(g=m[b],f=0;f<_;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1;C--,C==0&&(C=Math.pow(2,_),_++)}for(g=2,f=0;f<_;f++)A=A<<1|g&1,O==c-1?(O=0,M.push(d(A)),A=0):O++,g=g>>1;for(;;)if(A=A<<1,O==c-1){M.push(d(A));break}else O++;return M.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=[],g=4,m=4,y=3,v="",x=[],b,C,E,_,M,A,O,D={val:d(0),position:c,index:1};for(b=0;b<3;b+=1)f[b]=b;for(E=0,M=Math.pow(2,2),A=1;A!=M;)_=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=d(D.index++)),E|=(_>0?1:0)*A,A<<=1;switch(E){case 0:for(E=0,M=Math.pow(2,8),A=1;A!=M;)_=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=d(D.index++)),E|=(_>0?1:0)*A,A<<=1;O=t(E);break;case 1:for(E=0,M=Math.pow(2,16),A=1;A!=M;)_=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=d(D.index++)),E|=(_>0?1:0)*A,A<<=1;O=t(E);break;case 2:return""}for(f[3]=O,C=O,x.push(O);;){if(D.index>l)return"";for(E=0,M=Math.pow(2,y),A=1;A!=M;)_=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=d(D.index++)),E|=(_>0?1:0)*A,A<<=1;switch(O=E){case 0:for(E=0,M=Math.pow(2,8),A=1;A!=M;)_=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=d(D.index++)),E|=(_>0?1:0)*A,A<<=1;f[m++]=t(E),O=m-1,g--;break;case 1:for(E=0,M=Math.pow(2,16),A=1;A!=M;)_=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=d(D.index++)),E|=(_>0?1:0)*A,A<<=1;f[m++]=t(E),O=m-1,g--;break;case 2:return x.join("")}if(g==0&&(g=Math.pow(2,y),y++),f[O])v=f[O];else if(O===m)v=C+C.charAt(0);else return null;x.push(v),f[m++]=C+v.charAt(0),g--,C=v,g==0&&(g=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})}(DC)),DC.exports}var nfe=tfe();const i9=$a(nfe),B_="web image/vnd.tldraw+png",rfe={png:B_},sfe={[B_]:"image/png"};function ife(n){return Cn(rfe,n)??null}function ofe(n){return Cn(sfe,n)??n}function afe(n){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(n)}function lfe(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=qL(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function cfe(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 Ok(n,e,t,r){return n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"url",point:t,url:e,sources:r})}const ufe=[B_,"image/png","image/jpeg","image/webp","image/svg+xml"];function TN(n){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=n.trim(),e.body.textContent||e.body.innerText||""}const dfe=n=>{try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},hfe=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 Z4(e)},ffe=n=>/^<svg/.test(n),pfe=["input","select","textarea"];function jC(n){const{activeElement:e}=document;return n.menus.hasAnyOpenMenus()||e&&(e.isContentEditable||pfe.indexOf(e.tagName.toLowerCase())>-1)}const Fm=(n,e,t,r)=>{const s=hfe(e);if(s)for(const i of s)Ok(n,i,t);else dfe(e)?Ok(n,e,t):ffe(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}))},gfe=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}}a9(n,r,t)},o9=async({editor:n,clipboardItems:e,point:t,fallbackFiles:r})=>{const s=[];for(const i of e){for(const o of ufe)if(i.types.includes(o)){const a=i.getType(o).then(l=>Ur.rewriteMimeType(l,ofe(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 Ur.blobToText(o)})()}),i.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{const o=await i.getType("text/uri-list");return await Ur.blobToText(o)})()}),i.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{const o=await i.getType("text/plain");return await Ur.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 a9(n,s,t)};async function a9(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=rt(await Promise.all(r.map(o=>o.source)));return await cfe(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=i9.decompressFromBase64(c);if(f===null){o({type:"error",data:f,reason:"found tldraw data comment but could not parse base64"});return}else{const g=JSON.parse(f);if(g.type!=="application/tldraw"&&o({type:"error",data:g,reason:`found tldraw data comment but JSON was of a different type: ${g.type}`}),typeof g.data=="string"){o({type:"error",data:g,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}o({type:"tldraw",data:g.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");Fm(n,c,t,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&i.data.trim()){Fm(n,TN(i.data),t,s);return}if(s.some(c=>c.type==="text"&&c.subtype!=="html")){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"text",text:TN(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");Fm(n,c,t,s);return}}}for(const i of s)if(i.type==="text"&&i.subtype==="url"){Ok(n,i.data,t,s);return}for(const i of s)if(i.type==="text"&&i.subtype==="text"&&i.data.trim()){Fm(n,i.data,t,s);return}}const MS=async n=>{var r;const e=await n.resolveAssetsInContent(n.getContentFromCurrentPage(n.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=i9.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(QV);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 mfe(){const n=Mr(),e=jn(),t=P.useCallback(async function(o){tt(n,"editor is required for copy"),n.getSelectedShapeIds().length!==0&&(await MS(n),e("copy",{source:o}))},[n,e]),r=P.useCallback(async function(o){n&&n.getSelectedShapeIds().length!==0&&(await MS(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?(o9({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 yfe(){const n=Q(),e=jn(),t=ie("editor.isFocused",()=>n.getInstanceState().isFocused,[n]);P.useEffect(()=>{if(!t)return;const r=async l=>{n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||jC(n)||(et(l),await MS(n),e("copy",{source:"kbd"}))};async function s(l){n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||jC(n)||(et(l),await MS(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 g,m;if(i){Zt(l);return}if(n.getEditingShapeId()!==null||jC(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&&gfe(n,l.clipboardData,c)};if((g=navigator.clipboard)!=null&&g.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&&o9({editor:n,clipboardItems:v,point:c,fallbackFiles:y})},()=>{f()})}else f();et(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 MN={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",svg:"text/plain"};function Sfe(n,e,t={}){const r=e!=null&&e.length?e:[...n.getCurrentPageShapeIds()],s=t.format??"png";return{blobPromise:n.toImage(r,t).then(i=>Ur.rewriteMimeType(i.blob,MN[s])),mimeType:MN[s]}}function vfe(...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}=Sfe(e,t,r),o={[i]:s},a=ife(r.format);return a&&afe(a)&&(o[a]=s.then(l=>Ur.rewriteMimeType(l,a))),lfe(o)}switch(r.format){case"svg":return xfe(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:_n(r.format)}}async function xfe(n){var e,t;await((t=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:t.call(e,await n()))}function wfe(){const n=Mr(),{addToast:e}=Wa(),t=gt();return P.useCallback((r,s="svg")=>{tt(n,"useCopyAs: editor is required"),vfe(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 bfe(...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 ${AN()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?s=a.props.name||"frame":s=`${V0(a.id)} at ${AN()}`}s+=`.${r.format}`;const{blob:i}=await e.toImage(t,r),o=new File([i],s,{type:i.type});Cfe(o)}function AN(){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 Cfe(n){const e=document.createElement("a"),t=URL.createObjectURL(n);e.href=t,e.download=n.name,e.click(),URL.revokeObjectURL(t)}function Pfe(){const n=Mr(),{addToast:e}=Wa(),t=gt();return P.useCallback((r,s="png",i)=>{tt(n,"useExportAs: editor is required"),bfe(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 l9=ot.createContext([]);function kfe(){const n=Mr(),e=P.useRef(),t=_l(ot.useContext(l9));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(","))??_V,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 Ife(){const n=Mr(),e=P.useRef(null),t=P.useRef(null);return P.useCallback(async function(){tt(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-${Tt()}`;s.className=a,i.innerHTML=`
348
+ .${a} {
349
+ display: none;
350
+ }
351
+
352
+ .${a} svg {
353
+ max-width: 100%;
354
+ height: 100%;
355
+ display: block;
356
+ }
357
+
358
+ @media print {
359
+ html, body {
360
+ min-height: 100%;
361
+ height: 100%;
362
+ margin: 0;
363
+ }
364
+
365
+ body {
366
+ position: relative;
367
+ }
368
+
369
+ body > * {
370
+ display: none;
371
+ }
372
+
373
+ .tldraw__editor {
374
+ display: none;
375
+ }
376
+
377
+ .${a} {
378
+ display: block !important;
379
+ background: white;
380
+ min-height: 100%;
381
+ height: 100%;
382
+ max-width: 100%;
383
+ }
384
+
385
+ .${a}__item {
386
+ padding: 10mm;
387
+ display: flex;
388
+ min-height: 100%;
389
+ flex-direction: column;
390
+ page-break-after: always;
391
+ position: relative;
392
+ overflow: hidden;
393
+ height: 100%;
394
+ }
395
+
396
+ .${a}__item__main {
397
+ flex: 1;
398
+ display: flex;
399
+ align-items: center;
400
+ justify-content: center;
401
+ max-height: 100%;
402
+ }
403
+
404
+ .${a}__item__header {
405
+ display: none;
406
+ }
407
+
408
+ .${a}__item__footer {
409
+ display: none;
410
+ text-align: right;
411
+ }
412
+
413
+ .${a}__item__footer__hide {
414
+ display: none;
415
+ }
416
+
417
+
418
+ }
419
+
420
+ `;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,E){try{s.innerHTML+=`<div class="${a}__item">
421
+ <div class="${a}__item__header">
422
+ ${b.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
423
+ </div>
424
+ <div class="${a}__item__main">
425
+ ${E}
426
+ </div>
427
+ <div class="${a}__item__footer ${a}__item__footer__${C?"":"hide"}">
428
+ ${C??""}
429
+ </div>
430
+ </div>`}catch(_){console.error(_)}}function f(){kt.isChromeForIos?(l(),window.print()):kt.isSafari?(l(),document.execCommand("print",!1)):window.print()}const g=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(g,x);if(b){const C=y.find(E=>E.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 U_(){const{addToast:n,removeToast:e,clearToasts:t}=Wa(),{addDialog:r,clearDialogs:s,removeDialog:i}=eg(),o=gt(),a=kfe(),l=Ife(),{cut:c,copy:d,paste:f}=mfe(),g=wfe(),m=Pfe(),y=N_(),x=Rr()<dn.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:g,exportAs:m,getEmbedDefinition:y}),[n,e,t,r,i,s,o,x,a,l,c,d,f,g,m,y])}function Efe(n,e){const t={};for(const r of n)if(r.translations)for(const[s,i]of Cs(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 c9(n){return P.useMemo(()=>n,n)}function _fe(n){const e=c9(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 Cs(r.translations)){let o=t[s];o||(o=t[s]={}),Object.assign(o,i)}return t},[e])}function Tfe(n){const e=U_(),t=c9(n==null?[]:Array.isArray(n)?n:[n]);return P.useMemo(()=>Efe(t,e),[t,e])}const u9=P.createContext(null);function Mfe(n){return Object.fromEntries(n.map(e=>[e.id,e]))}function zm(n,e){if(n.getSelectedShapes().length===0)return n.getDocumentSettings().name||e}function Afe({overrides:n,children:e}){const t=Mr(),r=Pv(),s=U_(),i=jn(),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:xhe})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(m){i("insert-embed",{source:m}),s.addDialog({component:KU})}},{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",zm(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",zm(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",zm(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",zm(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}}))),Ht(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}Hae(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 k(b.x,b.y);C.rot(-b.rotation),C.add(new k(b.props.w/2-300/2,b.props.h/2-320/2)),C.rot(b.rotation);const E={id:jt(),type:"bookmark",rotation:b.rotation,x:C.x,y:C.y,opacity:1,props:{url:b.props.url}};v.push(E),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=rt(y.map(C=>l.getShape(C))),x=[],b=[];for(const C of v){if(!l.isShapeOfType(C,"bookmark"))continue;const{url:E}=C.props,_=s.getEmbedDefinition(E);if(!_||!_.definition)continue;const{width:M,height:A}=_.definition,O=new k(C.x,C.y);O.rot(-C.rotation),O.add(new k(C.props.w/2-M/2,C.props.h/2-A/2)),O.rot(C.rotation);const D={id:jt(),type:"embed",x:O.x,y:O.y,rotation:C.rotation,props:{url:E,w:M,h:A}};x.push(D),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(rt(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"),Zde(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"),Qde(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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"),Ht(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),Ht(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",l.options.adjacentShapeMargin),Ht(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",l.options.adjacentShapeMargin),Ht(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",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()%(Kt/2),v=jl(y,0)||jl(y,Kt/2),x=l.getSelectedShapeIds();l.rotateShapesBy(x,Kt/2-(v?0:y)),Ht(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()%(Kt/2),v=jl(y,0),x=l.getSelectedShapeIds();l.rotateShapesBy(x,v?-(Kt/2):-y),Ht(l,x)})))}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(m){i("zoom-in",{source:m,towardsCursor:!1}),l.zoomIn(void 0,{animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-in-on-cursor",label:"action.zoom-in",kbd:"!$=,!=",readonlyOk:!0,onSelect(m){i("zoom-in",{source:m,towardsCursor:!0}),l.zoomIn(l.inputs.currentScreenPoint,{animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(m){i("zoom-out",{source:m,towardsCursor:!1}),l.zoomOut(void 0,{animation:{duration:l.options.animationMediumMs}})}},{id:"zoom-out-on-cursor",label:"action.zoom-out",kbd:"!$-,!-",readonlyOk:!0,onSelect(m){i("zoom-out",{source:m,towardsCursor:!0}),l.zoomOut(l.inputs.currentScreenPoint,{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=Es.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=Xs;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=su;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 _he(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")}},{id:"change-page-prev",kbd:"?left,?up",onSelect:async m=>{const y=l.getPages(),v=y.findIndex(x=>x.id===l.getCurrentPageId());v<1||(i("change-page",{source:m,direction:"prev"}),l.setCurrentPage(y[v-1].id))}},{id:"change-page-next",kbd:"?right,?down",onSelect:async m=>{const y=l.getPages(),v=y.findIndex(x=>x.id===l.getCurrentPageId());if(v===-1||v>=y.length-1){if(l.getCurrentPageShapes().length<=0||l.getIsReadonly())return;i("new-page",{source:m}),l.run(()=>{l.markHistoryStoppingPoint("creating page");const x=Es.createId();l.createPage({name:s.msg("page-menu.new-page-initial-name"),id:x}),l.setCurrentPage(x)});return}l.setCurrentPage(y[v+1].id),i("change-page",{source:m,direction:"next"})}}];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 g=Mfe(f);return n?n(l,g,s):g},[s,t,i,n,o,r]);return p.jsx(u9.Provider,{value:a,children:e})}function wu(){const n=P.useContext(u9);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function vp(n,e){return n?typeof n=="string"?n:e?n[e]??n.default:void 0:void 0}function Qs(){const n=Mr();return ie("isReadonlyMode",()=>!!(n!=null&&n.getIsReadonly()),[n])}const Ofe=kt.isDarwin?"⌘":"Ctrl",Rfe=kt.isDarwin?"⌥":"Alt";function d9(n){return n===","?[","]:n.split(",")[0].split("").map(e=>{const t=e.replace(/\$/g,Ofe).replace(/\?/g,Rfe).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Rk(n){return"— "+d9(n).join(" ")}function zf({children:n,visibleOnMobileLayout:e=!1}){const t=Rr();return!e&&t<dn.MOBILE?null:p.jsx("kbd",{className:"tlui-kbd",children:d9(n).map((r,s)=>p.jsx("span",{children:r},s))})}const h9=P.createContext(null);function Ev(){const n=P.useContext(h9);if(!n)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return n}function Vr({type:n,sourceId:e,children:t}){return p.jsx(h9.Provider,{value:{type:n,sourceId:e},children:t})}function _v({id:n,kbd:e,label:t,readonlyOk:r,onSelect:s,toggle:i=!1,disabled:o=!1,checked:a=!1}){const{type:l,sourceId:c}=Ev(),d=Qs(),f=gt();if(d&&!r)return null;const g=vp(t,l),m=g?f(g):void 0;switch(l){case"menu":return p.jsxs(qde,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:m,onSelect:y=>{s==null||s(c),et(y)},disabled:o,checked:a,children:[p.jsx(Ko,{small:!0,icon:i?a?"toggle-on":"toggle-off":a?"check":"none"}),m&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:m}),e&&p.jsx(zf,{children:e})]});case"context-menu":return p.jsxs(Cde,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:m,onSelect:y=>{s(c),et(y)},disabled:o,checked:a,children:[p.jsx(Ko,{small:!0,icon:i?a?"toggle-on":"toggle-off":a?"check":"none"}),m&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:m}),e&&p.jsx(zf,{children:e})]},n);default:return null}}function Va(n,e){const t=Mr(),r=P.useCallback(o=>{o&&(t==null||t.complete()),e==null||e(o)},[t,e]),s=jn(),i=P.useCallback(o=>{s(o,{source:"unknown",id:n})},[n,s]);return Dae(t?`${n}-${t.contextId}`:n,r,i)}function H_({id:n,children:e,modal:t=!1,debugOpen:r=!1}){const[s,i]=Va(n);return p.jsx(I_,{open:r||s,dir:"ltr",modal:t,onOpenChange:i,children:e})}function K_({children:n,...e}){return p.jsx(E_,{dir:"ltr",asChild:!0,onTouchEnd:t=>et(t),...e,children:n})}function W_({className:n,side:e="bottom",align:t="start",sideOffset:r=8,alignOffset:s=8,children:i}){const o=Mn();return p.jsx(xv,{container:o,children:p.jsx(__,{className:ze("tlui-menu",n),side:e,sideOffset:r,align:t,alignOffset:s,collisionPadding:4,children:i})})}function Dfe({id:n,children:e}){const[t,r]=Va(n);return p.jsx(Gde,{open:t,onOpenChange:r,children:e})}function jfe({id:n,label:e,title:t,disabled:r}){return p.jsx(Yde,{dir:"ltr",asChild:!0,disabled:r,children:p.jsxs(He,{"data-testid":n,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[p.jsx(Pn,{children:e}),p.jsx(ct,{icon:"chevron-right",small:!0})]})})}function Nfe({id:n,alignOffset:e=-1,sideOffset:t=-6,size:r="small",children:s}){const i=Mn();return p.jsx(xv,{container:i,children:p.jsx(Xde,{"data-testid":n,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:t,collisionPadding:4,"data-size":r,children:s})})}function Lfe({children:n}){return p.jsx(Wde,{dir:"ltr",className:"tlui-menu__group",children:n})}function Ffe({noClose:n,children:e}){return p.jsx(Vde,{dir:"ltr",asChild:!0,onClick:n?et:void 0,children:e})}function lt({id:n,label:e,children:t}){const{type:r,sourceId:s}=Ev(),i=gt(),o=vp(e,r),a=o?i(o):void 0;switch(r){case"panel":return p.jsx("div",{className:"tlui-menu__group","data-testid":`${s}-group.${n}`,children:t});case"menu":return p.jsx(Lfe,{"data-testid":`${s}-group.${n}`,children:t});case"context-menu":return p.jsx(aU,{dir:"ltr",className:"tlui-menu__group","data-testid":`${s}-group.${n}`,children:t});case"keyboard-shortcuts":return p.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${s}-group.${n}`,children:[p.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),p.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function Ms({id:n,disabled:e=!1,label:t,size:r="small",children:s}){const{type:i,sourceId:o}=Ev(),a=Mn(),l=gt(),c=t?typeof t=="string"?t:t[i]??t.default:void 0,d=c?l(c):void 0;switch(i){case"menu":return p.jsxs(Dfe,{id:`${o}-sub.${n}`,children:[p.jsx(jfe,{id:`${o}-sub.${n}-button`,disabled:e,label:d,title:d}),p.jsx(Nfe,{id:`${o}-sub.${n}-content`,size:r,children:s})]});case"context-menu":return e?null:p.jsxs(zfe,{id:`${o}-sub.${n}`,children:[p.jsx(dU,{dir:"ltr",disabled:e,asChild:!0,children:p.jsxs(He,{"data-testid":`${o}-sub.${n}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[p.jsx(Pn,{children:d}),p.jsx(ct,{icon:"chevron-right",small:!0})]})}),p.jsx(P_,{container:a,children:p.jsx(hU,{"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 zfe({id:n,children:e}){const[t,r]=Va(n);return p.jsx(uU,{open:t,onOpenChange:r,children:e})}const $fe=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Bfe(){const n=Q(),e=jn(),t=ie("colorScheme",()=>n.user.getUserPreferences().colorScheme??(n.user.getIsDarkMode()?"dark":"light"),[n]);return p.jsx(Ms,{id:"help menu color-scheme",label:"menu.theme",children:p.jsx(lt,{id:"theme",children:$fe.map(({colorScheme:r,label:s})=>p.jsx(_v,{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 Ufe=({id:n,component:e,onClose:t,preventBackgroundClose:r})=>{const{removeDialog:s}=eg(),i=P.useRef(!1),o=Mn(),a=P.useCallback(l=>{if(!l){if(t)try{t()}catch(c){console.warn(c)}s(n)}},[n,t,s]);return p.jsx(ghe,{onOpenChange:a,defaultOpen:!0,children:p.jsx(mhe,{container:o,children:p.jsx(yhe,{dir:"ltr",className:"tlui-dialog__overlay",onClick:l=>{i.current||!r&&l.target===l.currentTarget&&a(!1)},children:p.jsx(She,{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:p.jsx(e,{onClose:()=>{i.current=!1,a(!1)}})})})})})},Hfe=P.memo(function(){const{dialogs:e}=eg();return ie("dialogs",()=>e.get(),[e]).map(r=>p.jsx(Ufe,{...r},r.id))}),Kfe=4e3,Wfe={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Vfe({toast:n}){const{removeToast:e}=Wa(),t=gt(),r=o=>{o||e(n.id)},s=n.actions&&n.actions.length>0,i=n.icon||n.severity&&Wfe[n.severity];return p.jsxs(Xhe,{onOpenChange:r,className:"tlui-toast__container",duration:n.keepOpen?1/0:Kfe,"data-severity":n.severity,children:[i&&p.jsx("div",{className:"tlui-toast__icon",children:p.jsx(Ko,{icon:i})}),p.jsxs("div",{className:"tlui-toast__main","data-title":!!n.title,"data-description":!!n.description,"data-actions":!!n.actions,children:[p.jsxs("div",{className:"tlui-toast__content",children:[n.title&&p.jsx(Zhe,{className:"tlui-toast__title",children:n.title}),n.description&&p.jsx(Jhe,{className:"tlui-toast__description",children:n.description})]}),n.actions&&p.jsxs("div",{className:"tlui-toast__actions",children:[n.actions.map((o,a)=>p.jsx(Qhe,{altText:o.label,asChild:!0,onClick:o.onClick,children:p.jsx(He,{type:o.type,children:p.jsx(Pn,{children:o.label})})},a)),p.jsx(EN,{asChild:!0,children:p.jsx(He,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:p.jsx(Pn,{children:n.closeLabel??t("toast.close")})})})]})]}),!s&&p.jsx(EN,{asChild:!0,children:p.jsx(He,{type:"normal",className:"tlui-toast__close",children:p.jsx(Pn,{children:n.closeLabel??t("toast.close")})})})]})}const qfe=P.memo(function(){const{toasts:e}=Wa(),t=ie("toasts",()=>e.get(),[]);return p.jsxs(p.Fragment,{children:[t.map(r=>p.jsx(Vfe,{toast:r},r.id)),p.jsx(YU,{className:"tlui-toast__viewport"})]})});function lo({actionId:n="",...e}){const r=wu()[n];return r?p.jsx(_v,{...r,...e}):null}function ON(n){return p.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...n,children:p.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[p.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),p.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:p.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}function sr({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}=Ev(),g=gt(),[m,y]=P.useState(!1);if(Qs()&&!t)return null;const x=vp(i,d),b=s?Rk(s):void 0,C=x?g(x):void 0,E=C&&b?`${C} ${b}`:C;switch(d){case"menu":return p.jsx(Ffe,{children:p.jsxs(He,{type:"menu","data-testid":`${f}.${r}`,disabled:n,title:E,onClick:_=>{l&&et(_),m?y(!1):a(f)},children:[p.jsx(Pn,{children:C}),s&&p.jsx(zf,{children:s})]})});case"context-menu":return n?null:p.jsxs(lU,{dir:"ltr",title:E,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${f}.${r}`,onSelect:_=>{l&&et(_),m?y(!1):a(f)},children:[p.jsx("span",{className:"tlui-button__label",draggable:!1,children:C}),s&&p.jsx(zf,{children:s}),e&&p.jsx(ON,{})]});case"panel":return p.jsxs(He,{"data-testid":`${f}.${r}`,type:"menu",title:E,disabled:n,onClick:()=>a(f),children:[p.jsx(Pn,{children:C}),e?p.jsx(ON,{}):o&&p.jsx(ct,{icon:o})]});case"small-icons":case"icons":return p.jsx(He,{"data-testid":`${f}.${r}`,type:"icon",title:E,disabled:n,onClick:()=>a(f),children:p.jsx(ct,{icon:o,small:d==="small-icons"})});case"keyboard-shortcuts":return s?p.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${f}.${r}`,children:[p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:C}),p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:p.jsx(zf,{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 p.jsxs(He,{type:"low",onClick:()=>a(f),children:[p.jsx(ct,{icon:o}),p.jsx(Pn,{children:C})]});case"toolbar":return p.jsx(He,{type:"tool","data-testid":`tools.${r}`,"aria-label":C,"data-value":r,onClick:()=>a("toolbar"),title:E,disabled:n,onTouchStart:_=>{et(_),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:p.jsx(ct,{icon:o})});case"toolbar-overflow":return p.jsx(He,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"aria-label":C,"data-testid":`tools.more.${r}`,title:E,disabled:n,role:"radio","aria-checked":c?"true":"false","data-value":r,children:p.jsx(ct,{icon:o})});default:throw _n(d)}}function ue({actionId:n="",...e}){const r=wu()[n];return r?p.jsx(sr,{...r,...e}):null}const f9=P.createContext(null);function Gfe({overrides:n,children:e}){const t=Mr(),r=jn(),s=U_(),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"})}},...[...qi.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(qi,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:KU}),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 p.jsx(f9.Provider,{value:i,children:e})}function V_(){const n=P.useContext(f9);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function gs({toolId:n="",...e}){const r=V_()[n];return r?p.jsx(sr,{...r,...e}):null}function Yfe({children:n}){const e=Q();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])?p.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}):null}const{PI:Xfe}=Math,Ld=Xfe+1e-4;function p9(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,g=f,m=f,y=g,v=!1,x;for(let b=0;b<n.length;b++){x=n[b];const{point:C,vector:E}=n[b],_=x.vector.dpr(d),M=(b<n.length-1?n[b+1]:n[b]).vector,A=b<n.length-1?M.dpr(x.vector):1,O=_<0&&!v,D=A!==null&&A<.2;if(O||D){if(A>-.62&&o-x.runningLength>x.radius){const U=d.clone().mul(x.radius);d.clone().cpr(M)<0?(m=k.Add(C,U),y=k.Sub(C,U)):(m=k.Sub(C,U),y=k.Add(C,U)),l.push(m),c.push(y)}else{const U=d.clone().mul(x.radius).per(),G=k.Sub(x.input,U);for(let z=1/13,N=0;N<1;N+=z)m=k.RotWith(G,x.input,Ld*N),l.push(m),y=k.RotWith(G,x.input,Ld+Ld*-N),c.push(y)}f=m,g=y,D&&(v=!0);continue}if(v=!1,x===s||x===i){const U=k.Per(E).mul(x.radius);l.push(k.Sub(C,U)),c.push(k.Add(C,U));continue}const B=k.Lrp(M,E,A).per().mul(x.radius);m=k.Sub(C,B),(b<=1||k.Dist2(f,m)>a)&&(l.push(m),f=m),y=k.Add(C,B),(b<=1||k.Dist2(g,y)>a)&&(c.push(y),g=y),d=E}return{left:l,right:c}}function q_(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,g=s.taper===!1?0:s.taper===!0?Math.max(t,d):s.taper,{left:m,right:y}=p9(n,e),v=l.point,x=n.length>1?n[n.length-1].point:k.AddXY(l.point,1,1);if(n.length===1&&(!(f||g)||i)){const _=k.Add(v,k.Sub(v,x).uni().per().mul(-l.radius)),M=[];for(let A=1/13,O=A;O<=1;O+=A)M.push(k.RotWith(_,v,Ld*2*O));return M}const b=[];if(!(f||g&&n.length===1))if(o)for(let _=1/8,M=_;M<=1;M+=_){const A=k.RotWith(y[0],v,Ld*M);b.push(A)}else{const _=k.Sub(m[0],y[0]),M=k.Mul(_,.5),A=k.Mul(_,.51);b.push(k.Sub(v,M),k.Sub(v,A),k.Add(v,A),k.Add(v,M))}const C=[],E=c.vector.clone().per().neg();if(g||f&&n.length===1)C.push(x);else if(a){const _=k.Add(x,k.Mul(E,c.radius));for(let M=1/29,A=M;A<1;A+=M)C.push(k.RotWith(_,x,Ld*3*A))}else C.push(k.Add(x,k.Mul(E,c.radius)),k.Add(x,k.Mul(E,c.radius*.99)),k.Sub(x,k.Mul(E,c.radius*.99)),k.Sub(x,k.Mul(E,c.radius)));return m.concat(C,y.reverse(),b)}const Zfe=.025,Jfe=.01;function Wo(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(k.From),a=0;if(!s){let b=o[0];for(;b&&!(b.z>=Zfe);)o.shift(),b=o[0]}if(!s){let b=o[o.length-1];for(;b&&!(b.z>=Jfe);)o.pop(),b=o[o.length-1]}if(o.length===0)return[{point:k.From(n[0]),input:k.From(n[0]),pressure:s?.5:.15,vector:new k(1,1),distance:0,runningLength:0,radius:1}];let l=o[1];for(;l&&!(k.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&&!(k.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&&k.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 E=k.Lrp(o[0],b,C/4);E.z=(o[0].z+(b.z-o[0].z))*C/4,o.push(E)}}const f=[{point:o[0],input:o[0],pressure:s?.5:o[0].z,vector:new k(1,1),distance:0,runningLength:0,radius:1}];let g=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=k.Dist(y,m.point),g+=v,!(b<4&&g<r)&&(m={input:o[b],point:y,pressure:s?.5:o[b].z,vector:k.Sub(m.point,y).uni(),distance:v,runningLength:g,radius:1},f.push(m)));if((x=f[1])!=null&&x.vector&&(f[0].vector=f[1].vector.clone()),g<1){const b=Math.max(.5,...f.map(C=>C.pressure));f.forEach(C=>C.pressure=b)}return f}const{min:ml}=Math,NC=.275;function Tv(n,e){const{size:t=16,thinning:r=.5,simulatePressure:s=!0,easing:i=x=>x,start:o={},end:a={}}=e,{easing:l=Un.easeOutQuad}=o,{easing:c=Un.easeOutCubic}=a,d=n[n.length-1].runningLength;let f,g=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 E=ml(1,m.distance/t);if(s){const _=ml(1,1-E);x=ml(1,g+(_-g)*(E*NC))}else x=ml(1,g+(m.pressure-g)*.5);g=g+(x-g)*.5}for(let b=0;b<n.length;b++){if(m=n[b],r){let{pressure:C}=m;const E=ml(1,m.distance/t);if(s){const _=ml(1,1-E);C=ml(1,g+(_-g)*(E*NC))}else C=ml(1,g+(C-g)*(E*NC));m.radius=t*i(.5-r*(.5-C)),g=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,E=d-b<v?c((d-b)/v):1;m.radius=Math.max(.01,m.radius*Math.min(C,E))}return n}function Qfe(n,e={}){return q_(Tv(Wo(n,e),e),e)}function RN({scribble:n,zoom:e,color:t,opacity:r,className:s}){if(!n.points.length)return null;const i=Qfe(n.points,{size:n.size/e,start:{taper:n.taper,easing:Un.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=LE(i);return p.jsx("svg",{className:s&&ze("tl-overlays__item",s),children:p.jsx("path",{className:"tl-scribble",d:o,fill:t??`var(--color-${n.color})`,opacity:r??n.opacity})})}const epe=({bounds:n,rotation:e})=>{const t=Q();return ie("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?p.jsx(nz,{bounds:n,rotation:e}):null};function tpe({size:n,width:e,height:t,hideAlternateHandles:r}){const s=te(n/3),i=s/2;return p.jsxs("svg",{className:"tl-overlays__item",children:[p.jsx("polyline",{className:"tl-corner-crop-handle",points:`
431
+ ${te(0-i)},${te(n)}
432
+ ${te(0-i)},${te(0-i)}
433
+ ${te(n)},${te(0-i)}`,strokeWidth:s,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),p.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:te(e/2-n),y1:te(0-i),x2:te(e/2+n),y2:te(0-i),strokeWidth:s,"data-testid":"selection.crop.top","aria-label":"top handle"}),p.jsx("polyline",{className:ze("tl-corner-crop-handle",{"tl-hidden":r}),points:`
434
+ ${te(e-n)},${te(0-i)}
435
+ ${te(e+i)},${te(0-i)}
436
+ ${te(e+i)},${te(n)}`,strokeWidth:s,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),p.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:te(e+i),y1:te(t/2-n),x2:te(e+i),y2:te(t/2+n),strokeWidth:s,"data-testid":"selection.crop.right","aria-label":"right handle"}),p.jsx("polyline",{className:"tl-corner-crop-handle",points:`
437
+ ${te(e+i)},${te(t-n)}
438
+ ${te(e+i)},${te(t+i)}
439
+ ${te(e-n)},${te(t+i)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),p.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:te(e/2-n),y1:te(t+i),x2:te(e/2+n),y2:te(t+i),strokeWidth:s,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),p.jsx("polyline",{className:ze("tl-corner-crop-handle",{"tl-hidden":r}),points:`
440
+ ${te(0+n)},${te(t+i)}
441
+ ${te(0-i)},${te(t+i)}
442
+ ${te(0-i)},${te(t-n)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),p.jsx("line",{className:ze("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:te(0-i),y1:te(t/2-n),x2:te(0-i),y2:te(t/2+n),strokeWidth:s,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const npe=Gn(function({bounds:e,rotation:t}){const r=Q(),s=P.useRef(null),i=Qs(),o=ko("top"),a=ko("right"),l=ko("bottom"),c=ko("left"),d=ko("top_left"),f=ko("top_right"),g=ko("bottom_right"),m=ko("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,E=C instanceof ye?e.clone().expand(C).zeroFix():e.clone().expandBy(C).zeroFix();if(ch(s,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:E.x-e.x,y:E.y-e.y}),x&&r.isShapeHidden(x))return null;const _=r.getZoomLevel(),M=r.getInstanceState().isChangingStyle,A=E.width,O=E.height,D=8/_,B=A<D*2,U=O<D*2,G=A<D*4,z=O<D*4,N=A<D*5,L=O<D*5,V=v?1.75:1,Z=6/_*V,W=(G?Z/2:Z)*(V*.75),$=(z?Z/2:Z)*(V*.75),Y=(x?!r.getShapeUtil(x).hideSelectionBoundsFg(x):!0)&&!M;let re=Y&&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")||Y&&r.isIn("select.resizing")&&x&&r.isShapeOfType(x,"text");x&&re&&kt.isFirefox&&r.isShapeOfType(x,"embed")&&(re=!1);const K=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!M&&!i,ne=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!M&&!i,ge=!v&&!(B||U)&&(ne||K)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!b,Pe=v&&(!G||!z)&&(ne||K)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!b,ce=ne&&(x?r.getShapeUtil(x).canResize(x)&&!r.getShapeUtil(x).hideResizeHandles(x):!0)&&!K&&!b,Be=B||U,Re=B&&U,Ce=N||L,_e=ce||K,We=!ge,st=!ne||!Pe,hn=!ne||!_e,_t=!ne||!_e||Be,Qt=!ne||!_e||Be,Nt=!ne||!_e||Re&&!K;let At=!0,Jr=!0;if(K)At=Ce,Jr=Ce;else if(ce){At=Be||Re||v;const ts=v&&x&&x.type==="text";Jr=At&&!ts}const Qr=Math.min(24/_,O-$*3),es=ne&&v&&x&&r.isShapeOfType(x,"text")&&Qr*_>=4;return p.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:p.jsxs("g",{ref:s,children:[re&&p.jsx("rect",{className:"tl-selection__fg__outline",width:te(A),height:te(O)}),p.jsx($m,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:Z,corner:"top_left_rotate",cursor:y?zs("nwse-rotate",t):void 0,isHidden:We}),p.jsx($m,{"data-testid":"selection.rotate.top-right",cx:A+Z*3,cy:0,targetSize:Z,corner:"top_right_rotate",cursor:y?zs("nesw-rotate",t):void 0,isHidden:We}),p.jsx($m,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:O+Z*3,targetSize:Z,corner:"bottom_left_rotate",cursor:y?zs("swne-rotate",t):void 0,isHidden:We}),p.jsx($m,{"data-testid":"selection.rotate.bottom-right",cx:A+Z*3,cy:O+Z*3,targetSize:Z,corner:"bottom_right_rotate",cursor:y?zs("senw-rotate",t):void 0,isHidden:We}),p.jsx(spe,{"data-testid":"selection.rotate.mobile",cx:G?-Z*1.5:A/2,cy:G?O/2:-Z*1.5,size:D,isHidden:st}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":At}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:te(0-(z?$*2:$)),width:te(A),height:te(Math.max(1,$*2)),style:y?{cursor:zs("ns-resize",t)}:void 0,...o}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Jr}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:te(A-(G?0:W)),y:0,height:te(O),width:te(Math.max(1,W*2)),style:y?{cursor:zs("ew-resize",t)}:void 0,...a}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":At}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:te(O-(z?0:$)),width:te(A),height:te(Math.max(1,$*2)),style:y?{cursor:zs("ns-resize",t)}:void 0,...l}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Jr}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:te(0-(G?W*2:W)),y:0,height:te(O),width:te(Math.max(1,W*2)),style:y?{cursor:zs("ew-resize",t)}:void 0,...c}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":hn}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:te(0-(G?W*2:W*1.5)),y:te(0-(z?$*2:$*1.5)),width:te(W*3),height:te($*3),style:y?{cursor:zs("nwse-resize",t)}:void 0,...d}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":_t}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:te(A-(G?0:W*1.5)),y:te(0-(z?$*2:$*1.5)),width:te(W*3),height:te($*3),style:y?{cursor:zs("nesw-resize",t)}:void 0,...f}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Nt}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:te(A-(G?W:W*1.5)),y:te(O-(z?$:$*1.5)),width:te(W*3),height:te($*3),style:y?{cursor:zs("nwse-resize",t)}:void 0,...g}),p.jsx("rect",{className:ze("tl-transparent",{"tl-hidden":Qt}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:te(0-(G?W*3:W*1.5)),y:te(O-(z?0:$*1.5)),width:te(W*3),height:te($*3),style:y?{cursor:zs("nesw-resize",t)}:void 0,...m}),ce&&p.jsxs(p.Fragment,{children:[p.jsx("rect",{"data-testid":"selection.resize.top-left",className:ze("tl-corner-handle",{"tl-hidden":hn}),"aria-label":"top_left handle",x:te(0-D/2),y:te(0-D/2),width:te(D),height:te(D)}),p.jsx("rect",{"data-testid":"selection.resize.top-right",className:ze("tl-corner-handle",{"tl-hidden":_t}),"aria-label":"top_right handle",x:te(A-D/2),y:te(0-D/2),width:te(D),height:te(D)}),p.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ze("tl-corner-handle",{"tl-hidden":Nt}),"aria-label":"bottom_right handle",x:te(A-D/2),y:te(O-D/2),width:te(D),height:te(D)}),p.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ze("tl-corner-handle",{"tl-hidden":Qt}),"aria-label":"bottom_left handle",x:te(0-D/2),y:te(O-D/2),width:te(D),height:te(D)})]}),es&&p.jsxs(p.Fragment,{children:[p.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:te(0-D/4),y:te(O/2-Qr/2),rx:D/4,width:te(D/2),height:te(Qr)}),p.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:D/4,x:te(A-D/4),y:te(O/2-Qr/2),width:te(D/2),height:te(Qr)})]}),K&&p.jsx(tpe,{size:D,width:A,height:O,hideAlternateHandles:Ce})]})})}),$m=function({cx:e,cy:t,targetSize:r,corner:s,cursor:i,isHidden:o,"data-testid":a}){const l=ko(s);return p.jsx("rect",{className:ze("tl-transparent","tl-rotate-corner",{"tl-hidden":o}),"data-testid":a,"aria-label":`${s} target`,pointerEvents:"all",x:te(e-r*3),y:te(t-r*3),width:te(Math.max(1,r*3)),height:te(Math.max(1,r*3)),cursor:i,...l})},rpe=Math.sqrt(Math.PI),spe=function({cx:e,cy:t,size:r,isHidden:s,"data-testid":i}){const o=ko("mobile_rotate"),a=Q(),l=ie("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return p.jsxs("g",{children:[p.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}),p.jsx("circle",{className:ze("tl-mobile-rotate__fg",{"tl-hidden":s}),cx:e,cy:t,r:r/rpe})]})};function ipe(){const n=Q(),e=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]);return p.jsx(rz,{hideAll:!e})}function Dk(n,e,t){const{arrowheadStart:r,arrowheadEnd:s}=e.props,i=Id(n,e,t),o=i.start.clone(),a=i.end.clone(),l=k.Med(o,a);if(k.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=k.Sub(a,o).uni(),d=AS(n,e,"start"),f=AS(n,e,"end"),g=n.getShapePageTransform(e);DN(a,i.start,g,f),DN(o,i.end,g,d);let m=0,y=0,v=0,x=0,b=$f*e.props.scale;const C=d&&f&&d.shape===f.shape,E=d&&f?G_(n,d.shape.id,f.shape.id):"safe";E==="safe"&&d&&f&&!C&&!d.isExact&&!f.isExact&&(f.didIntersect&&!d.didIntersect?d.isClosed&&o.setTo(a.clone().add(c.clone().mul($f*e.props.scale))):f.didIntersect||f.isClosed&&a.setTo(o.clone().sub(c.clone().mul($f*e.props.scale))));const _=k.Sub(a,o),M=k.Len(_)?_.uni():k.From(_),A=!k.Equals(M,c);C||(E!=="start-contains-end"&&d&&r!=="none"&&!d.isExact&&(v=No[e.props.size]/2+("size"in d.shape.props?No[d.shape.props.size]/2:0),m=(OS+v)*e.props.scale,b+=v*e.props.scale),E!=="end-contains-start"&&f&&s!=="none"&&!f.isExact&&(x=No[e.props.size]/2+("size"in f.shape.props?No[f.shape.props.size]/2:0),y=(OS+x)*e.props.scale,b+=x*e.props.scale));const O=o.clone().add(M.clone().mul(m*(A?-1:1))),D=a.clone().sub(M.clone().mul(y*(A?-1:1)));k.DistMin(O,D,b)&&(m!==0&&y!==0?(m*=-1.5,y*=-1.5):m!==0?m*=-1:y!==0&&(y*=-1)),o.add(M.clone().mul(m*(A?-1:1))),a.sub(M.clone().mul(y*(A?-1:1))),A?(d&&f&&a.setTo(k.Add(o,M.clone().mul(-10*e.props.scale))),l.setTo(k.Med(i.start,i.end))):l.setTo(k.Med(o,a));const B=k.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:B>0,length:B}}function DN(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?BE:use)(o,a,r.outline);let f;if(d!==null&&(f=d.sort((y,v)=>k.Dist2(y,o)-k.Dist2(v,o))[0]??(l?void 0:a)),f===void 0)return;const g=ve.applyToPoint(r.transform,f),m=ve.applyToPoint(ve.Inverse(t),g);n.setTo(m),r.didIntersect=!0}function ope(n,e,t){const{arrowheadEnd:r,arrowheadStart:s}=e.props,i=e.props.bend;if(Math.abs(i)>Math.abs(e.props.bend*(dpe*e.props.scale)))return Dk(n,e,t);const o=Id(n,e,t),a=k.Med(o.start,o.end),l=k.Sub(o.end,o.start),c=k.Len(l)?l.uni():k.From(l),d=k.Add(a,c.per().mul(-i)),f=AS(n,e,"start"),g=AS(n,e,"end"),m=o.start.clone(),y=o.end.clone(),v=d.clone();if(k.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?Ap:Y3,C=jN(m,y,v),E=k.Angle(C.center,m),_=k.Angle(C.center,y),M=b(E,_);if(C.length===0||C.size===0||!MR(C.length)||!MR(C.size))return Dk(n,e,t);const A=m.clone(),O=y.clone(),D=v.clone(),B=n.getShapePageTransform(e);let U=0,G=0,z=$f*e.props.scale;if(f&&!f.isExact){const re=ve.applyToPoint(B,A),K=ve.applyToPoint(B,C.center),ne=ve.applyToPoint(B,O),ge=ve.Inverse(f.transform),Pe=ve.applyToPoint(ge,re),ce=ve.applyToPoint(ge,K),Be=ve.applyToPoint(ge,ne),{isClosed:Re}=f,Ce=Re?dk:Oj;let _e,We=Ce(ce,C.radius,f.outline);if(We){const st=ce.angle(Pe),hn=ce.angle(Be),_t=b(st,hn);We=We.filter(Nt=>b(st,ce.angle(Nt))<=_t);const Qt=_t*.25;We.sort(Re?(Nt,At)=>Math.abs(b(st,ce.angle(Nt))-Qt)<Math.abs(b(st,ce.angle(At))-Qt)?-1:1:(Nt,At)=>b(st,ce.angle(Nt))<b(st,ce.angle(At))?-1:1),_e=We[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 st=No[e.props.size]/2+("size"in f.shape.props?No[f.shape.props.size]/2:0);U=(OS+st)*e.props.scale,z+=st*e.props.scale}}if(g&&!g.isExact){const re=ve.applyToPoint(B,A),K=ve.applyToPoint(B,O),ne=ve.applyToPoint(B,C.center),ge=ve.Inverse(g.transform),Pe=ve.applyToPoint(ge,re),ce=ve.applyToPoint(ge,ne),Be=ve.applyToPoint(ge,K),Re=g.isClosed,Ce=Re?dk:Oj;let _e,We=Ce(ce,C.radius,g.outline);if(We){const st=ce.angle(Pe),hn=ce.angle(Be),_t=b(st,hn),Qt=_t*.75;We=We.filter(Nt=>b(st,ce.angle(Nt))<=_t),We.sort(Re?(Nt,At)=>Math.abs(b(st,ce.angle(Nt))-Qt)<Math.abs(b(st,ce.angle(At))-Qt)?-1:1:(Nt,At)=>b(st,ce.angle(Nt))<b(st,ce.angle(At))?-1:1),We[0]?_e=We[0]:_e=Re?void 0:Be}else _e=Re?void 0:Be;if(_e&&(O.setTo(n.getPointInShapeSpace(e,ve.applyToPoint(g.transform,_e))),g.didIntersect=!0,r!=="none")){const st=No[e.props.size]/2+("size"in g.shape.props?No[g.shape.props.size]/2:0);G=(OS+st)*e.props.scale,z+=st*e.props.scale}}let N=k.Angle(C.center,A),L=k.Angle(C.center,O),V=b(N,L),Z=V*C.radius;const W=A.clone(),$=O.clone();if(U!==0&&W.setTo(C.center).add(k.FromAngle(N+V*(U/Z*(x?1:-1))).mul(C.radius)),G!==0&&$.setTo(C.center).add(k.FromAngle(L+V*(G/Z*(x?-1:1))).mul(C.radius)),k.DistMin(W,$,z)&&(U!==0&&G!==0?(U*=-1.5,G*=-1.5):U!==0?U*=-2:G!==0&&(G*=-2)),U!==0&&A.setTo(C.center).add(k.FromAngle(N+V*(U/Z*(x?1:-1))).mul(C.radius)),G!==0&&O.setTo(C.center).add(k.FromAngle(L+V*(G/Z*(x?-1:1))).mul(C.radius)),f&&g&&!f.isExact&&!g.isExact){N=k.Angle(C.center,A),L=k.Angle(C.center,O),V=b(N,L),Z=V*C.radius;const re=G_(n,f.shape.id,g.shape.id);re==="double-bound"&&Z<30?(A.setTo(m),O.setTo(y),D.setTo(v)):re==="safe"&&(f&&!f.didIntersect&&A.setTo(m),(g&&!g.didIntersect||b(E,N)>b(E,L))&&O.setTo(C.center).add(k.FromAngle(N+V*(Math.min(.9,$f*e.props.scale/Z)*(x?1:-1))).mul(C.radius)))}ape(C.center,C.radius,A,O,D,M,x),A.equals(O)&&(A.setTo(D.clone().addXY(1,1)),O.setTo(D.clone().subXY(1,1))),m.setTo(A),y.setTo(O),v.setTo(D);const Y=jN(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:Y,isValid:Y.length!==0&&isFinite(Y.center.x)&&isFinite(Y.center.y)}}function jN(n,e,t){const r=jI(n,e,t)??k.Med(n,e),s=k.Dist(r,n),i=+k.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=+(wt>c),f=(Dt-c)*(i?1:-1),g=f*s;return{center:r,radius:s,size:f,length:g,largeArcFlag:d,sweepFlag:i}}function ape(n,e,t,r,s,i,o){const a=k.Angle(n,t),l=k.Angle(n,r);let c=Ap(a,l);if(o||(c=Dt-c),s.setTo(n).add(k.FromAngle(a+c*(.5*(o?1:-1))).mul(e)),c>i){s.rotWith(n,wt);const d=r.clone();r.setTo(t),t.setTo(d)}}const lpe=8;function cpe(n){return Math.abs(n.props.bend)<lpe*n.props.scale}function AS(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 Ii?o.children[0].vertices:o.vertices;return{shape:s,transform:i,isClosed:o.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function NN(n,e,t,r){const s=n.getShape(t.toId);if(s){const{point:i,size:o}=n.getShapeGeometry(s).bounds,a=k.Add(i,k.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 k(0,0)}function xs(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 upe=vE("arrow info",(n,e)=>{const t=xs(n,e);return cpe(e)?Dk(n,e,t):ope(n,e,t)});function jo(n,e){const t=typeof e=="string"?e:e.id;return upe.get(n,t)}function Id(n,e,t){var a,l;const r=n.getShapePageTransform(e),s=G_(n,(a=t.start)==null?void 0:a.toId,(l=t.end)==null?void 0:l.toId),i=t.start?NN(n,r,t.start,s==="double-bound"||s==="start-contains-end"):k.From(e.props.start),o=t.end?NN(n,r,t.end,s==="double-bound"||s==="end-contains-start"):k.From(e.props.end);return{start:i,end:o}}function uf(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 py(n,e,t){const r=n.getBindingsFromShape(e,"arrow").filter(s=>s.props.terminal===t);n.deleteBindings(r)}const $f=10,OS=10,dpe=10,No={s:2,m:3.5,l:5,xl:10};function G_(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 gy extends uy{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const t=this.editor.getShape(e.fromId);t&&LC(this.editor,t)}onAfterChange({bindingAfter:e}){const t=this.editor.getShape(e.fromId);t&&LC(this.editor,t)}onAfterChangeFromShape({shapeAfter:e}){LC(this.editor,e)}onAfterChangeToShape({binding:e}){g9(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const t=this.editor.getShape(e.fromId);t&&RS({editor:this.editor,arrow:t,terminal:e.props.terminal})}}R(gy,"type","arrow"),R(gy,"props",i4),R(gy,"migrations",o4);function g9(n,e){var x;const t=n.getShape(e);if(!t)return;const r=xs(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),g=n.getShapeNearestSibling(d,a);let m;if(f&&g)m=f.index>g.index?f:g;else if(f&&!g)m=f;else if(g&&!f)m=g;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=Qf(m.index,v[0].index)}else y=Oo(m.index);y!==d.index&&n.updateShapes([{id:e,type:"arrow",index:y}])}function LC(n,e){const t=xs(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)&&RS({editor:n,arrow:e,terminal:r,unbind:!0})}g9(n,e.id)}function RS({editor:n,arrow:e,terminal:t,unbind:r=!1,useHandle:s=!1}){const i=jo(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,g=k.Med(d,f),m=k.Sub(d,f).per().uni().mul(i.handleArc.radius*2*Math.sign(e.props.bend)),y=Bp(i.handleArc.center,k.Add(g,m),i.handleArc.center,i.handleArc.radius);tt((y==null?void 0:y.length)===1);const v=k.Dist(g,y[0])*Math.sign(e.props.bend);jl(v,c.props.bend)||(c.props.bend=v)}n.updateShape(c),r&&py(n,e,t)}const m9=[gy],ar={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},Ir={s:2,m:3.5,l:5,xl:10},Zd={s:18,m:24,l:36,xl:44},Da={s:18,m:22,l:26,xl:32},hpe={s:18,m:20,l:24,xl:28},za={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},fpe=20,Y_=4.25,Br=16;function ppe(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 gpe(n,e,t){var b,C,E;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,jt()),_.boundElements!==null)for(const M of _.boundElements)M.type==="text"&&f.add(M.id)});let g=o3;for(const _ of r){if(f.has(_.id))continue;const M=c.get(_.id),A={id:M,typeName:"shape",parentId:l,index:g,x:_.x,y:_.y,rotation:0,isLocked:_.locked,opacity:mpe(_.opacity),meta:{}};switch(_.angle!==0&&a.set(M,_.angle),_.groupIds&&_.groupIds.length>0?o.has(_.groupIds[0])?(b=o.get(_.groupIds[0]))==null||b.push(M):o.set(_.groupIds[0],[M]):d.push(M),_.type){case"rectangle":case"ellipse":case"diamond":{let O="",D="middle";if(_.boundElements!==null){for(const U of _.boundElements)if(U.type==="text"){const G=r.find(z=>z.id===U.id);G&&(O=G.text,D=Cpe[G.textAlign])}}const B=_.backgroundColor==="transparent"?_.strokeColor:_.backgroundColor;i.shapes.push({...A,type:"geo",props:{geo:_.type,url:_.link??"",w:_.width,h:_.height,size:Bm[_.strokeWidth]??"draw",color:df[B]??"black",richText:ki(O),align:D,dash:Um(_),fill:Ipe(_)}});break}case"freedraw":{i.shapes.push({...A,type:"draw",props:{dash:Um(_),size:Bm[_.strokeWidth],color:df[_.strokeColor]??"black",segments:[{type:"free",points:_.points.map(([O,D,B=.5])=>({x:O,y:D,z:B}))}]}});break}case"line":{if(_.points.slice().length<2)break;const D=ep(_.points.length);i.shapes.push({...A,type:"line",props:{dash:Um(_),size:Bm[_.strokeWidth],color:df[_.strokeColor]??"black",spline:_.roundness?"cubic":"line",points:{...Object.fromEntries(_.points.map(([B,U],G)=>{const z=D[G];return[z,{id:z,index:z,x:B,y:U}]}))}}});break}case"arrow":{let O="";if(_.boundElements!==null){for(const z of _.boundElements)if(z.type==="text"){const N=r.find(L=>L.id===z.id);N&&(O=N.text)}}const D=_.points[0],B=_.points[_.points.length-1],U=c.get((C=_.startBinding)==null?void 0:C.elementId),G=c.get((E=_.endBinding)==null?void 0:E.elementId);i.shapes.push({...A,type:"arrow",props:{text:O,bend:kpe(_,D,B),dash:Um(_),size:Bm[_.strokeWidth]??"m",color:df[_.strokeColor]??"black",start:{x:D[0],y:D[1]},end:{x:B[0],y:B[1]},arrowheadEnd:LN[_.endArrowhead]??"none",arrowheadStart:LN[_.startArrowhead]??"none"}}),U&&i.bindings.push({id:qc(),typeName:"binding",type:"arrow",fromId:M,toId:U,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),G&&i.bindings.push({id:qc(),typeName:"binding",type:"arrow",fromId:M,toId:G,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:O,scale:D}=Spe(_.fontSize);i.shapes.push({...A,type:"text",props:{size:O,scale:D,font:vpe[_.fontFamily]??"draw",color:df[_.strokeColor]??"black",richText:ki(_.text),textAlign:Ppe[_.textAlign]}});break}case"image":{const O=s[_.fileId];if(!O)break;const D=Hl.createId();i.assets.push({id:D,typeName:"asset",type:"image",props:{w:_.width,h:_.height,fileSize:O.size,name:_.id??"Untitled",isAnimated:!1,mimeType:O.mimeType,src:O.dataURL},meta:{}}),i.shapes.push({...A,type:"image",props:{w:_.width,h:_.height,assetId:D}})}}g=Oo(g)}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 M=n.getShape(_[0]);M!=null&&M.parentId&&ys(M.parentId)&&d.push(M.parentId)}for(const[_,M]of a)n.select(_),n.rotateShapesBy([_],M);const y=rt(d.map(_=>n.getShape(_))),v=ye.Common(y.map(_=>n.getShapePageBounds(_))),x=n.getViewportPageBounds().center;n.updateShapes(y.map(_=>{const M={x:(_.x??0)-(v.x+v.w/2),y:(_.y??0)-(v.y+v.h/2)};return{id:_.id,type:_.type,x:x.x+M.x,y:x.y+M.y}})),n.setSelectedShapes(d)}const mpe=n=>{const e=n/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Bm={1:"s",2:"m",3:"l",4:"xl"},ype={16:"s",20:"m",28:"l",36:"xl"};function Spe(n){const e=ype[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 vpe={1:"draw",2:"sans",3:"mono"},xpe={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 Co(n,e,t){const r=[0,1,2,3,4].map(s=>xpe[n][s]);return Object.fromEntries(r.map((s,i)=>[s,i<3?e:t]))}const df={...Co("gray","grey","black"),...Co("red","light-red","red"),...Co("pink","light-red","red"),...Co("grape","light-violet","violet"),...Co("blue","light-blue","blue"),...Co("cyan","light-blue","blue"),...Co("teal","light-green","green"),...Co("green","light-green","green"),...Co("yellow","yellow","orange"),...Co("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},wpe={solid:"draw",dashed:"dashed",dotted:"dotted"},bpe={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Cpe={left:"start",center:"middle",right:"end"},Ppe={left:"start",center:"middle",right:"end"},LN={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function kpe(n,e,t){let r=0;if(n.points.length>2){const s=new k(e[0],e[1]),i=new k(t[0],t[1]),o=new k(n.points[1][0],n.points[1][1]),a=k.Sub(i,s),l=k.Per(a),c=k.Med(i,s),d=k.Sub(c,l),f=k.Add(c,l),g=k.NearestPointOnLineSegment(d,f,o,!1);r=k.Dist(g,c),k.Clockwise(g,i,c)&&(r*=-1)}return r}const Um=n=>{let e=wpe[n.strokeStyle]??"draw";return e==="draw"&&n.roughness===0&&(e="solid"),e},Ipe=n=>n.backgroundColor==="transparent"?"none":bpe[n.fillStyle]??"solid",Epe=/(^|[^`])`([^`]+)`(?!`)/,_pe=/(^|[^`])`([^`]+)`(?!`)/g,y9=$o.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",Vn(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[Qc({find:Epe,type:this.type})]},addPasteRules(){return[Bl({find:_pe,type:this.type})]}}),Tpe=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,Mpe=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,S9=$o.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",Vn(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[Qc({find:Tpe,type:this.type})]},addPasteRules(){return[Bl({find:Mpe,type:this.type})]}}),Ape="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2ntley5rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6logistics9properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3ncaster6d0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2psy3ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",Ope="ελ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",Jd=(n,e)=>{for(const t in e)n[t]=e[t];return n},jk="numeric",Nk="ascii",Lk="alpha",Bf="asciinumeric",Ef="alphanumeric",Fk="domain",v9="emoji",Rpe="scheme",Dpe="slashscheme",FC="whitespace";function jpe(n,e){return n in e||(e[n]=[]),e[n]}function zc(n,e,t){e[jk]&&(e[Bf]=!0,e[Ef]=!0),e[Nk]&&(e[Bf]=!0,e[Lk]=!0),e[Bf]&&(e[Ef]=!0),e[Lk]&&(e[Ef]=!0),e[Ef]&&(e[Fk]=!0),e[v9]&&(e[Fk]=!0);for(const r in e){const s=jpe(r,t);s.indexOf(n)<0&&s.push(n)}}function Npe(n,e){const t={};for(const r in e)e[r].indexOf(n)>=0&&(t[r]=!0);return t}function vs(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}vs.groups={};vs.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||vs.groups;let s;return e&&e.j?s=e:(s=new vs(e),t&&r&&zc(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||vs.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 vs,Jd(o.j,a.j),o.jr.push.apply(o.jr,a.jr),o.jd=a.jd,o.t=a.t):o=new vs,i){if(r)if(o.t&&typeof o.t=="string"){const l=Jd(Npe(o.t,r),t);zc(i,l,r)}else t&&zc(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),gn=(n,e,t,r,s)=>n.tr(e,t,r,s),FN=(n,e,t,r,s)=>n.ts(e,t,r,s),Se=(n,e,t,r,s)=>n.tt(e,t,r,s),va="WORD",zk="UWORD",x9="ASCIINUMERICAL",w9="ALPHANUMERICAL",xp="LOCALHOST",$k="TLD",Bk="UTLD",my="SCHEME",Sd="SLASH_SCHEME",X_="NUM",Uk="WS",Z_="NL",Uf="OPENBRACE",Hf="CLOSEBRACE",DS="OPENBRACKET",jS="CLOSEBRACKET",NS="OPENPAREN",LS="CLOSEPAREN",FS="OPENANGLEBRACKET",zS="CLOSEANGLEBRACKET",$S="FULLWIDTHLEFTPAREN",BS="FULLWIDTHRIGHTPAREN",US="LEFTCORNERBRACKET",HS="RIGHTCORNERBRACKET",KS="LEFTWHITECORNERBRACKET",WS="RIGHTWHITECORNERBRACKET",VS="FULLWIDTHLESSTHAN",qS="FULLWIDTHGREATERTHAN",GS="AMPERSAND",J_="APOSTROPHE",YS="ASTERISK",Pl="AT",XS="BACKSLASH",ZS="BACKTICK",JS="CARET",Tl="COLON",Q_="COMMA",QS="DOLLAR",Io="DOT",e0="EQUALS",eT="EXCLAMATION",fi="HYPHEN",Kf="PERCENT",t0="PIPE",n0="PLUS",r0="POUND",Wf="QUERY",tT="QUOTE",b9="FULLWIDTHMIDDLEDOT",nT="SEMI",Eo="SLASH",Vf="TILDE",s0="UNDERSCORE",C9="EMOJI",i0="SYM";var P9=Object.freeze({__proto__:null,WORD:va,UWORD:zk,ASCIINUMERICAL:x9,ALPHANUMERICAL:w9,LOCALHOST:xp,TLD:$k,UTLD:Bk,SCHEME:my,SLASH_SCHEME:Sd,NUM:X_,WS:Uk,NL:Z_,OPENBRACE:Uf,CLOSEBRACE:Hf,OPENBRACKET:DS,CLOSEBRACKET:jS,OPENPAREN:NS,CLOSEPAREN:LS,OPENANGLEBRACKET:FS,CLOSEANGLEBRACKET:zS,FULLWIDTHLEFTPAREN:$S,FULLWIDTHRIGHTPAREN:BS,LEFTCORNERBRACKET:US,RIGHTCORNERBRACKET:HS,LEFTWHITECORNERBRACKET:KS,RIGHTWHITECORNERBRACKET:WS,FULLWIDTHLESSTHAN:VS,FULLWIDTHGREATERTHAN:qS,AMPERSAND:GS,APOSTROPHE:J_,ASTERISK:YS,AT:Pl,BACKSLASH:XS,BACKTICK:ZS,CARET:JS,COLON:Tl,COMMA:Q_,DOLLAR:QS,DOT:Io,EQUALS:e0,EXCLAMATION:eT,HYPHEN:fi,PERCENT:Kf,PIPE:t0,PLUS:n0,POUND:r0,QUERY:Wf,QUOTE:tT,FULLWIDTHMIDDLEDOT:b9,SEMI:nT,SLASH:Eo,TILDE:Vf,UNDERSCORE:s0,EMOJI:C9,SYM:i0});const pa=/[a-z]/,hf=new RegExp("\\p{L}","u"),zC=new RegExp("\\p{Emoji}","u"),ga=/\d/,$C=/\s/,zN="\r",BC=`
443
+ `,Lpe="️",Fpe="‍",UC="";let Hm=null,Km=null;function zpe(n=[]){const e={};vs.groups=e;const t=new vs;Hm==null&&(Hm=$N(Ape)),Km==null&&(Km=$N(Ope)),Se(t,"'",J_),Se(t,"{",Uf),Se(t,"}",Hf),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,"<",VS),Se(t,">",qS),Se(t,"&",GS),Se(t,"*",YS),Se(t,"@",Pl),Se(t,"`",ZS),Se(t,"^",JS),Se(t,":",Tl),Se(t,",",Q_),Se(t,"$",QS),Se(t,".",Io),Se(t,"=",e0),Se(t,"!",eT),Se(t,"-",fi),Se(t,"%",Kf),Se(t,"|",t0),Se(t,"+",n0),Se(t,"#",r0),Se(t,"?",Wf),Se(t,'"',tT),Se(t,"/",Eo),Se(t,";",nT),Se(t,"~",Vf),Se(t,"_",s0),Se(t,"\\",XS),Se(t,"・",b9);const r=gn(t,ga,X_,{[jk]:!0});gn(r,ga,r);const s=gn(r,pa,x9,{[Bf]:!0}),i=gn(r,hf,w9,{[Ef]:!0}),o=gn(t,pa,va,{[Nk]:!0});gn(o,ga,s),gn(o,pa,o),gn(s,ga,s),gn(s,pa,s);const a=gn(t,hf,zk,{[Lk]:!0});gn(a,pa),gn(a,ga,i),gn(a,hf,a),gn(i,ga,i),gn(i,pa),gn(i,hf,i);const l=Se(t,BC,Z_,{[FC]:!0}),c=Se(t,zN,Uk,{[FC]:!0}),d=gn(t,$C,Uk,{[FC]:!0});Se(t,UC,d),Se(c,BC,l),Se(c,UC,d),gn(c,$C,d),Se(d,zN),Se(d,BC),gn(d,$C,d),Se(d,UC,d);const f=gn(t,zC,C9,{[v9]:!0});Se(f,"#"),gn(f,zC,f),Se(f,Lpe,f);const g=Se(f,Fpe);Se(g,"#"),gn(g,zC,f);const m=[[pa,o],[ga,s]],y=[[pa,null],[hf,a],[ga,i]];for(let v=0;v<Hm.length;v++)yl(t,Hm[v],$k,va,m);for(let v=0;v<Km.length;v++)yl(t,Km[v],Bk,zk,y);zc($k,{tld:!0,ascii:!0},e),zc(Bk,{utld:!0,alpha:!0},e),yl(t,"file",my,va,m),yl(t,"mailto",my,va,m),yl(t,"http",Sd,va,m),yl(t,"https",Sd,va,m),yl(t,"ftp",Sd,va,m),yl(t,"ftps",Sd,va,m),zc(my,{scheme:!0,ascii:!0},e),zc(Sd,{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]?{[Rpe]:!0}:{[Dpe]:!0};x.indexOf("-")>=0?C[Fk]=!0:pa.test(x)?ga.test(x)?C[Bf]=!0:C[Nk]=!0:C[jk]=!0,FN(t,x,x,C)}return FN(t,"localhost",xp,{ascii:!0}),t.jd=new vs(i0),{start:t,tokens:Jd({groups:e},P9)}}function k9(n,e){const t=$pe(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,g=-1;for(;o<r&&(l=a.go(t[o]));)a=l,a.accepts()?(f=0,g=0,d=a):f>=0&&(f+=t[o].length,g++),c+=t[o].length,i+=t[o].length,o++;i-=f,o-=g,c-=f,s.push({t:d.t,v:e.slice(i-c,i),s:i-c,e:i})}return s}function $pe(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 yl(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 vs(r),i.jr=s.slice(),n.j[l]=i),n=i}return i=new vs(t),i.jr=s.slice(),n.j[e[o-1]]=i,i}function $N(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 wp={defaultProtocol:"http",events:null,format:BN,formatHref:BN,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function rT(n,e=null){let t=Jd({},wp);n&&(t=Jd(t,n instanceof rT?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}rT.prototype={o:wp,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]:wp[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 BN(n){return n}function I9(n,e){this.t="token",this.v=n,this.tk=e}I9.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=wp.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&&Jd(o,d),{tagName:s,attributes:o,content:i,eventListeners:f}}};function Mv(n,e){class t extends I9{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 UN=Mv("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),HN=Mv("text"),Bpe=Mv("nl"),Wm=Mv("url",{isLink:!0,toHref(n=wp.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==xp&&n[1].t===Tl}}),hi=n=>new vs(n);function Upe({groups:n}){const e=n.domain.concat([GS,YS,Pl,XS,ZS,JS,QS,e0,fi,X_,Kf,t0,n0,r0,Eo,i0,Vf,s0]),t=[Tl,Q_,Io,eT,Kf,Wf,tT,nT,FS,zS,Uf,Hf,jS,DS,NS,LS,$S,BS,US,HS,KS,WS,VS,qS],r=[GS,J_,YS,XS,ZS,JS,QS,e0,fi,Uf,Hf,Kf,t0,n0,r0,Wf,Eo,i0,Vf,s0],s=hi(),i=Se(s,Vf);ut(i,r,i),ut(i,n.domain,i);const o=hi(),a=hi(),l=hi();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,Pl);Se(i,Pl,c),Se(a,Pl,c),Se(l,Pl,c);const d=Se(i,Io);ut(d,r,i),ut(d,n.domain,i);const f=hi();ut(c,n.domain,f),ut(f,n.domain,f);const g=Se(f,Io);ut(g,n.domain,f);const m=hi(UN);ut(g,n.tld,m),ut(g,n.utld,m),Se(c,xp,m);const y=Se(f,fi);Se(y,fi,y),ut(y,n.domain,f),ut(m,n.domain,f),Se(m,Io,g),Se(m,fi,y);const v=Se(m,Tl);ut(v,n.numeric,UN);const x=Se(o,fi),b=Se(o,Io);Se(x,fi,x),ut(x,n.domain,o),ut(b,r,i),ut(b,n.domain,o);const C=hi(Wm);ut(b,n.tld,C),ut(b,n.utld,C),ut(C,n.domain,o),ut(C,r,i),Se(C,Io,b),Se(C,fi,x),Se(C,Pl,c);const E=Se(C,Tl),_=hi(Wm);ut(E,n.numeric,_);const M=hi(Wm),A=hi();ut(M,e,M),ut(M,t,A),ut(A,e,M),ut(A,t,A),Se(C,Eo,M),Se(_,Eo,M);const O=Se(a,Tl),D=Se(l,Tl),B=Se(D,Eo),U=Se(B,Eo);ut(a,n.domain,o),Se(a,Io,b),Se(a,fi,x),ut(l,n.domain,o),Se(l,Io,b),Se(l,fi,x),ut(O,n.domain,M),Se(O,Eo,M),Se(O,Wf,M),ut(U,n.domain,M),ut(U,e,M),Se(U,Eo,M);const G=[[Uf,Hf],[DS,jS],[NS,LS],[FS,zS],[$S,BS],[US,HS],[KS,WS],[VS,qS]];for(let z=0;z<G.length;z++){const[N,L]=G[z],V=Se(M,N);Se(A,N,V),Se(V,L,M);const Z=hi(Wm);ut(V,e,Z);const W=hi();ut(V,t),ut(Z,e,Z),ut(Z,t,W),ut(W,e,Z),ut(W,t,W),Se(Z,L,M),Se(W,L,M)}return Se(s,xp,C),Se(s,Z_,Bpe),{start:s,tokens:P9}}function Hpe(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,g=-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()?(g=0,f=a):g>=0&&g++,s++,d++;if(g<0)s-=d,s<r&&(o.push(t[s]),s++);else{o.length>0&&(i.push(HC(HN,e,o)),o=[]),s-=g,d-=g;const m=f.t,y=t.slice(s-d,s);i.push(HC(m,e,y))}}return o.length>0&&i.push(HC(HN,e,o)),i}function HC(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 Kpe=typeof console<"u"&&console&&console.warn||(()=>{}),Wpe="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",Yt={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function Vpe(){return vs.groups={},Yt.scanner=null,Yt.parser=null,Yt.tokenQueue=[],Yt.pluginQueue=[],Yt.customSchemes=[],Yt.initialized=!1,Yt}function KN(n,e=!1){if(Yt.initialized&&Kpe(`linkifyjs: already initialized - will not register custom scheme "${n}" ${Wpe}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(n))throw new Error(`linkifyjs: incorrect scheme format.
444
+ 1. Must only contain digits, lowercase ASCII letters or "-"
445
+ 2. Cannot start or end with "-"
446
+ 3. "-" cannot repeat`);Yt.customSchemes.push([n,e])}function qpe(){Yt.scanner=zpe(Yt.customSchemes);for(let n=0;n<Yt.tokenQueue.length;n++)Yt.tokenQueue[n][1]({scanner:Yt.scanner});Yt.parser=Upe(Yt.scanner.tokens);for(let n=0;n<Yt.pluginQueue.length;n++)Yt.pluginQueue[n][1]({scanner:Yt.scanner,parser:Yt.parser});return Yt.initialized=!0,Yt}function sT(n){return Yt.initialized||qpe(),Hpe(Yt.parser.start,n,k9(Yt.scanner.start,n))}sT.scan=k9;function E9(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 rT(t),s=sT(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 Gpe(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function Ype(n){return new ur({key:new Zs("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=LJ(t.doc,[...e]);if(qJ(a).forEach(({newRange:c})=>{const d=zJ(r.doc,c,m=>m.isTextblock);let f,g;if(d.length>1?(f=d[0],g=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],g=r.doc.textBetween(f.pos,c.to,void 0," ")),f&&g){const m=g.split(" ").filter(b=>b!=="");if(m.length<=0)return!1;const y=m[m.length-1],v=f.pos+g.lastIndexOf(y);if(!y)return!1;const x=sT(y).map(b=>b.toObject(n.defaultProtocol));if(!Gpe(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=>{sE(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 Xpe(n){return new ur({key:new Zs("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(g=>g.nodeName==="A"))return!1;const l=j5(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 Zpe(n){return new ur({key:new Zs("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=E9(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 Jpe=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;function Mc(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(Jpe,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}const Qpe=$o.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"){KN(n);return}KN(n.scheme,n.optionalSlashes)})},onDestroy(){Vpe()},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)=>!!Mc(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=>!!Mc(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=>!!Mc(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",Vn(this.options.HTMLAttributes,n),0]:["a",Vn(this.options.HTMLAttributes,{...n,href:""}),0]},addCommands(){return{setLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:r=>!!Mc(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=>!!Mc(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[Bl({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:r}=this.options,s=E9(n).filter(i=>i.isLink&&this.options.isAllowedUri(i.value,{defaultValidate:o=>!!Mc(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(Ype({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:r=>this.options.isAllowedUri(r,{defaultValidate:s=>!!Mc(s,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),this.options.openOnClick===!0&&n.push(Xpe({type:this.type})),this.options.linkOnPaste&&n.push(Zpe({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type})),n}}),ege=/^\s*>\s$/,tge=so.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return["blockquote",Vn(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[cp({find:ege,type:this.type})]}}),nge=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,rge=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,sge=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,ige=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,oge=$o.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",Vn(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[Qc({find:nge,type:this.type}),Qc({find:sge,type:this.type})]},addPasteRules(){return[Bl({find:rge,type:this.type}),Bl({find:ige,type:this.type})]}}),age="listItem",WN="textStyle",VN=/^\s*([-+*])\s$/,lge=so.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",Vn(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(age,this.editor.getAttributes(WN)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=cp({find:VN,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=cp({find:VN,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(WN),editor:this.editor})),[n]}}),cge=/^```([a-z]+)?[\s\n]$/,uge=/^~~~([a-z]+)?[\s\n]$/,dge=so.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",Vn(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(`
447
+
448
+ `);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[XP({find:cge,type:this.type,getAttributes:n=>({language:n[1]})}),XP({find:uge,type:this.type,getAttributes:n=>({language:n[1]})})]},addProseMirrorPlugins(){return[new ur({key:new Zs("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,`
449
+ `));return o.replaceSelectionWith(this.type.create({language:i},l)),o.selection.$from.parent.type!==this.type&&o.setSelection(nt.near(o.doc.resolve(Math.max(0,o.selection.from-2)))),o.setMeta("paste",!0),n.dispatch(o),!0}}})]}}),hge=so.create({name:"doc",topNode:!0,content:"block+"});function fge(n={}){return new ur({view(e){return new pge(e,n)}})}class pge{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=PF(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 gge=lr.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[fge(this.options)]}});class yn extends at{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return yn.valid(r)?new yn(r):at.near(r)}content(){return Te.empty}eq(e){return e instanceof yn&&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 yn(e.resolve(t.pos))}getBookmark(){return new iT(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!mge(e)||!yge(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&&yn.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(yn.valid(l))return l}for(;;){let o=t>0?i.firstChild:i.lastChild;if(!o){if(i.isAtom&&!i.isText&&!Ke.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(yn.valid(a))return a}return null}}}yn.prototype.visible=!1;yn.findFrom=yn.findGapCursorFrom;at.jsonID("gapcursor",yn);class iT{constructor(e){this.pos=e}map(e){return new iT(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return yn.valid(t)?new yn(t):at.near(t)}}function mge(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 yge(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 Sge(){return new ur({props:{decorations:bge,createSelectionBetween(n,e,t){return e.pos==t.pos&&yn.valid(t)?new yn(t):null},handleClick:xge,handleKeyDown:vge,handleDOMEvents:{beforeinput:wge}}})}const vge=d5({ArrowLeft:Vm("horiz",-1),ArrowRight:Vm("horiz",1),ArrowUp:Vm("vert",-1),ArrowDown:Vm("vert",1)});function Vm(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 nt){if(!i.endOfTextblock(t)||a.depth==0)return!1;l=!1,a=r.doc.resolve(e>0?a.after():a.before())}let c=yn.findGapCursorFrom(a,e,l);return c?(s&&s(r.tr.setSelection(new yn(c))),!0):!1}}function xge(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!yn.valid(r))return!1;let s=n.posAtCoords({left:t.clientX,top:t.clientY});return s&&s.inside>-1&&Ke.isSelectable(n.state.doc.nodeAt(s.inside))?!1:(n.dispatch(n.state.tr.setSelection(new yn(r))),!0)}function wge(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof yn))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(nt.near(i.doc.resolve(t.pos+1))),n.dispatch(i),!1}function bge(n){if(!(n.selection instanceof yn))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",Dn.create(n.doc,[Si.widget(n.selection.head,e,{key:"gapcursor"})])}const Cge=lr.create({name:"gapCursor",addProseMirrorPlugins(){return[Sge()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=ft(Le(n,"allowGapCursor",t)))!==null&&e!==void 0?e:null}}}),Pge=so.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",Vn(this.options.HTMLAttributes,n)]},renderText(){return`
450
+ `},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(g=>a.includes(g.type.name));c.ensureMarks(f)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),kge=so.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]}`,Vn(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=>XP({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${n}})\\s$`),type:this.type,getAttributes:{level:n}}))}});var o0=200,Kn=function(){};Kn.prototype.append=function(e){return e.length?(e=Kn.from(e),!this.length&&e||e.length<o0&&this.leafAppend(e)||this.length<o0&&e.leafPrepend(this)||this.appendInner(e)):this};Kn.prototype.prepend=function(e){return e.length?Kn.from(e).append(this):this};Kn.prototype.appendInner=function(e){return new Ige(this,e)};Kn.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?Kn.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};Kn.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};Kn.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)};Kn.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};Kn.from=function(e){return e instanceof Kn?e:e&&e.length?new _9(e):Kn.empty};var _9=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<=o0)return new e(this.values.concat(s.flatten()))},e.prototype.leafPrepend=function(s){if(this.length+s.length<=o0)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}(Kn);Kn.empty=new _9([]);var Ige=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}(Kn);const Ege=500;class Ki{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,g)=>{if(!f.step){s||(s=this.remapping(r,g+1),i=s.maps.length),i--,d.push(f);return}if(s){d.push(new _o(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 _o(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 Ki(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]),g=new _o(e.mapping.maps[d],f,t),m;(m=l&&l.merge(g))&&(g=m,d?i.pop():a=a.slice(0,a.length-1)),i.push(g),t&&(o++,t=void 0),s||(l=g)}let c=o-r.depth;return c>Tge&&(a=_ge(a,c),o-=c),new Ki(a.append(i),o)}remapping(e,t){let r=new rp;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 Ki(this.items.append(e.map(t=>new _o(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(g=>{g.selection&&a--},s);let l=t;this.items.forEach(g=>{let m=i.getMirror(--l);if(m==null)return;o=Math.min(o,m);let y=i.maps[m];if(g.step){let v=e.steps[m].invert(e.docs[m]),x=g.selection&&g.selection.map(i.slice(l+1,m));x&&a++,r.push(new _o(y,v,x))}else r.push(new _o(y))},s);let c=[];for(let g=t;g<o;g++)c.push(new _o(i.maps[g]));let d=this.items.slice(0,s).append(c).append(r),f=new Ki(d,a);return f.emptyItemCount()>Ege&&(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 _o(c.invert(),l,d),g,m=s.length-1;(g=s.length&&s[m].merge(f))?s[m]=g:s.push(f)}}else o.map&&r--},this.items.length,0),new Ki(Kn.from(s.reverse()),i)}}Ki.empty=new Ki(Kn.empty,0);function _ge(n,e){let t;return n.forEach((r,s)=>{if(r.selection&&e--==0)return t=s,!1}),n.slice(t)}class _o{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 _o(t.getMap().invert(),t,this.selection)}}}class kl{constructor(e,t,r,s,i){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=s,this.prevComposition=i}}const Tge=20;function Mge(n,e,t,r){let s=t.getMeta(Gc),i;if(s)return s.historyState;t.getMeta(Rge)&&(n=new kl(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(Gc))return o.getMeta(Gc).redo?new kl(n.done.addTransform(t,void 0,r,yy(e)),n.undone,qN(t.mapping.maps),n.prevTime,n.prevComposition):new kl(n.done,n.undone.addTransform(t,void 0,r,yy(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||!Age(t,n.prevRanges)),c=o?KC(n.prevRanges,t.mapping):qN(t.mapping.maps);return new kl(n.done.addTransform(t,l?e.selection.getBookmark():void 0,r,yy(e)),Ki.empty,c,t.time,a??n.prevComposition)}else return(i=t.getMeta("rebased"))?new kl(n.done.rebased(t,i),n.undone.rebased(t,i),KC(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new kl(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),KC(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Age(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 qN(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 KC(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 Oge(n,e,t){let r=yy(e),s=Gc.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 kl(t?a:i.remaining,t?i.remaining:a,null,0,-1);return i.transform.setSelection(o).setMeta(Gc,{redo:t,historyState:l})}let WC=!1,GN=null;function yy(n){let e=n.plugins;if(GN!=e){WC=!1,GN=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){WC=!0;break}}return WC}const Gc=new Zs("history"),Rge=new Zs("closeHistory");function Dge(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ur({key:Gc,state:{init(){return new kl(Ki.empty,Ki.empty,null,0,-1)},apply(e,t,r){return Mge(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,s=r=="historyUndo"?M9:r=="historyRedo"?A9:null;return s?(t.preventDefault(),s(e.state,e.dispatch)):!1}}}})}function T9(n,e){return(t,r)=>{let s=Gc.getState(t);if(!s||(n?s.undone:s.done).eventCount==0)return!1;if(r){let i=Oge(s,t,n);i&&r(e?i.scrollIntoView():i)}return!0}}const M9=T9(!1,!0),A9=T9(!0,!0),jge=lr.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>M9(n,e),redo:()=>({state:n,dispatch:e})=>A9(n,e)}},addProseMirrorPlugins(){return[Dge(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()}}}),Nge=so.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{}}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:n}){return["hr",Vn(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}):YJ(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(nt.create(o.doc,c.pos+1)):c.nodeAfter.isBlock?o.setSelection(Ke.create(o.doc,c.pos)):o.setSelection(nt.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(nt.create(o.doc,d+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[EQ({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),Lge=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Fge=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,zge=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,$ge=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Bge=$o.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",Vn(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[Qc({find:Lge,type:this.type}),Qc({find:zge,type:this.type})]},addPasteRules(){return[Bl({find:Fge,type:this.type}),Bl({find:$ge,type:this.type})]}}),Uge=so.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",Vn(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)}}}),Hge="listItem",YN="textStyle",XN=/^(\d+)\.\s$/,Kge=so.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:null,parseHTML:n=>n.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:n}){const{start:e,...t}=n;return e===1?["ol",Vn(this.options.HTMLAttributes,t),0]:["ol",Vn(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(Hge,this.editor.getAttributes(YN)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let n=cp({find:XN,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=cp({find:XN,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(YN)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[n]}}),Wge=so.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Vn(this.options.HTMLAttributes,n),0]},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Vge=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,qge=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Gge=$o.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",Vn(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[Qc({find:Vge,type:this.type})]},addPasteRules(){return[Bl({find:qge,type:this.type})]}}),Yge=so.create({name:"text",group:"inline"}),Xge=lr.create({name:"starterKit",addExtensions(){const n=[];return this.options.bold!==!1&&n.push(oge.configure(this.options.bold)),this.options.blockquote!==!1&&n.push(tge.configure(this.options.blockquote)),this.options.bulletList!==!1&&n.push(lge.configure(this.options.bulletList)),this.options.code!==!1&&n.push(y9.configure(this.options.code)),this.options.codeBlock!==!1&&n.push(dge.configure(this.options.codeBlock)),this.options.document!==!1&&n.push(hge.configure(this.options.document)),this.options.dropcursor!==!1&&n.push(gge.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&n.push(Cge.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&n.push(Pge.configure(this.options.hardBreak)),this.options.heading!==!1&&n.push(kge.configure(this.options.heading)),this.options.history!==!1&&n.push(jge.configure(this.options.history)),this.options.horizontalRule!==!1&&n.push(Nge.configure(this.options.horizontalRule)),this.options.italic!==!1&&n.push(Bge.configure(this.options.italic)),this.options.listItem!==!1&&n.push(Uge.configure(this.options.listItem)),this.options.orderedList!==!1&&n.push(Kge.configure(this.options.orderedList)),this.options.paragraph!==!1&&n.push(Wge.configure(this.options.paragraph)),this.options.strike!==!1&&n.push(Gge.configure(this.options.strike)),this.options.text!==!1&&n.push(Yge.configure(this.options.text)),n}}),oT={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"}}}},Zge=mn(oT).flatMap(n=>mn(n).flatMap(e=>Object.values(e))),Jge=lr.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 Qge=Jge;const eme=lr.create({name:"keyboardShiftEnterHandler",addKeyboardShortcuts(){return{"Shift-Enter":({editor:n})=>n.commands.enter()}}});y9.config.excludes=void 0;S9.config.priority=1100;const tg=[Xge.configure({blockquote:!1,codeBlock:!1,horizontalRule:!1}),Qpe.configure({openOnClick:!1,autolink:!0}),S9,eme,Qge];function aT(n,e){var s;const t=((s=n.getTextOptions().tipTapConfig)==null?void 0:s.extensions)??tg;return BJ(e,t).replaceAll('<p dir="auto"></p>',"<p><br /></p>")??""}function a0(n,e){return`<div class="tl-rich-text">${aT(n,e)}</div>`}const tme=new qo;function To(n){return n.content.length===1&&!n.content[0].content}function au(n,e){return To(e)?"":tme.get(e,()=>{var r;const t=((r=n.getTextOptions().tipTapConfig)==null?void 0:r.extensions)??tg;return HJ(e,t,{blockSeparator:`
451
+ `})})}function nme(n,e){var r;const t=((r=n.getTextOptions().tipTapConfig)==null?void 0:r.extensions)??tg;return UJ(e,t)}function O9(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=Cn(oT,e.family);if(!r)return e;const s=Cn(r,e.style);if(!s)return e;const i=Cn(s,e.weight);return i&&t(i),e}const rme=" ",Xf=class Xf{static normalizeText(e){return e.replace(Xf.fixNewLines,`
452
+ `)}static normalizeTextForDom(e){return e.replace(Xf.fixNewLines,`
453
+ `).split(`
454
+ `).map(t=>t||" ").join(`
455
+ `)}};R(Xf,"fixNewLines",/\r?\n|\r/g);let l0=Xf;const sme=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function R9(n){return sme.test(n)}function ime(n){return n.replace(/\t/g,rme)}function ome(n){const e=n.split(`
456
+ `);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(`
457
+ `)}const D9={"&amp;":"&","&quot;":'"',"&apos;":"'","&#27;":"'","&#34;":'"',"&#38;":"&","&#39;":"'","&#8211;":"–","&#8212;":"—","&#8216;":"‘","&#8217;":"’","&#8220;":"“","&#8221;":"”","&#8230;":"…"},ame=new RegExp(Object.keys(D9).join("|"),"g");function lme(n){return n.replace(ame,e=>D9[e])}function cme(n){return n.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function ume(n){return cme(ome(ime(n)))}const j9=5e3,N9=10*1024*1024;function dme(n,e){n.registerExternalAssetHandler("file",async t=>hme(n,t,e)),n.registerExternalAssetHandler("url",async t=>fme(n,t,e)),n.registerExternalContentHandler("svg-text",async t=>pme(n,t)),n.registerExternalContentHandler("embed",t=>gme(n,t)),n.registerExternalContentHandler("files",async t=>mme(n,t,e)),n.registerExternalContentHandler("text",async t=>yme(n,t)),n.registerExternalContentHandler("url",async t=>Sme(n,t,e)),n.registerExternalContentHandler("tldraw",async t=>vme(n,t)),n.registerExternalContentHandler("excalidraw",async t=>xme(n,t))}async function hme(n,{file:e,assetId:t},{acceptedImageMimeTypes:r=kp,acceptedVideoMimeTypes:s=p0,maxAssetSize:i=N9,maxImageDimension:o=j9,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"}),tt(c||d,`File type not allowed: ${e.type}`),e.size>i&&a.addToast({title:l("assets.files.size-too-big"),severity:"error"}),tt(e.size<=i,`File size too big: ${(e.size/1024).toFixed()}kb > ${(i/1024).toFixed()}kb`);const f=HL(await e.arrayBuffer());t=t??Hl.createId(f);const g=await L9(e,t,c,d,o),m=await n.uploadAsset(g,e);return g.props.src=m.src,m.meta&&(g.meta={...g.meta,...m.meta}),Hl.create(g)}async function fme(n,{url:e},{toasts:t,msg:r}){var i,o,a,l,c;let s;try{const f=await(await Gi(e,{method:"GET",mode:"no-cors"})).text(),g=new DOMParser().parseFromString(f,"text/html");s={image:((i=g.head.querySelector('meta[property="og:image"]'))==null?void 0:i.getAttribute("content"))??"",favicon:((o=g.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:o.getAttribute("href"))??((a=g.head.querySelector('link[rel="icon"]'))==null?void 0:a.getAttribute("href"))??"",title:((l=g.head.querySelector('meta[property="og:title"]'))==null?void 0:l.getAttribute("content"))??e,description:((c=g.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:Hl.createId(gI(e)),typeName:"asset",type:"bookmark",props:{src:e,description:s.description,image:s.image,favicon:s.favicon,title:s.title},meta:{}}}async function pme(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");F9(n,[a],r)}function gme(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=jt(),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 mme(n,{point:e,files:t},{maxAssetSize:r=N9,maxImageDimension:s=j9,acceptedImageMimeTypes:i=kp,acceptedVideoMimeTypes:o=p0,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 k(c.x,c.y),f=[],g=[];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=HL(await m.arrayBuffer()),C=Hl.createId(b),E=await L9(m,C,v,x,s);let _;v&&(_=n.createTemporaryAssetPreview(C,m)),f.push(E),g.push({asset:E,file:m,temporaryAssetPreview:_})}Promise.allSettled(g.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}})),F9(n,f,d)}async function yme(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=ume(t),a=r?nme(n,r):ki(o);let l,c,d,f="middle";const g=r??o.replace(/\n/g,"<br>"),m=r?a.content.length>1:o.split(`
458
+ `).length>1,y=R9(o);m&&(f=m?y?"end":"start":"middle");const v=n.textMeasure.measureHtml(g,{...ar,fontFamily:za[i.font],fontSize:Zd[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(g,{...ar,fontFamily:za[i.font],fontSize:Zd[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:jt(),type:"text",x:s.x-l/2,y:s.y-c/2,props:{richText:a,textAlign:f,autoSize:d,w:l}}])}async function Sme(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=Hl.createId(gI(t)),c=wme(n,t,a);let d=n.getAsset(l),f=!1;if(!d){f=!0;try{const g=await n.getAssetForExternalContent({type:"url",url:t});if(!g)throw Error("Could not create an asset");d=g}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 vme(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 xme(n,{point:e,content:t}){n.run(()=>{gpe(n,t,e)})}async function L9(n,e,t,r,s){let i=n.type;n.type==="video/quicktime"&&(i="video/mp4");const o=t?await Us.getImageSize(n):await Us.getVideoSize(n),a=await Us.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=ppe(c,{w:s,h:s});c!==d&&Us.isStaticImageType(n.type)&&(l.props.w=d.w,l.props.h=d.h)}return l}async function F9(n,e,t){if(!e.length)return[];const r=k.From(t),s=[];for(let i=0;i<e.length;i++){const o=e[i];switch(o.type){case"image":{s.push({id:jt(),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:jt(),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)),z9(n,t)}),s.map(i=>i.id)}function z9(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=k.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 k(r.minX,r.minY),o=i.clone().snapToGrid(s),a=k.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 wme(n,e,t){const r={id:jt(),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),z9(n,t)}),n.getShape(r.id)}var sP;let bme=(sP=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}))}}},R(sP,"id","idle"),sP);var iP;let Cme=(iP=class extends Ne{constructor(){super(...arguments);R(this,"shape");R(this,"markId","");R(this,"preciseTimeout",-1);R(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=jt();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`);const s=eo(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(g=>g.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)}},R(iP,"id","pointing"),iP);class Hk extends Ne{constructor(){super(...arguments);R(this,"shapeType","arrow")}static children(){return[bme,Cme]}}R(Hk,"id","arrow"),R(Hk,"initial","idle");class lT extends Ne{constructor(){super(...arguments);R(this,"info",{});R(this,"initialShape");R(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");R(this,"util",this.editor.getShapeUtil(this.shapeType));R(this,"isPen",!1);R(this,"isPenOrStylus",!1);R(this,"segmentMode","free");R(this,"didJustShiftClickToExtendPreviousShapeLine",!1);R(this,"pagePointWhereCurrentSegmentChanged",{});R(this,"pagePointWhereNextSegmentChanged",null);R(this,"lastRecordedPoint",{});R(this,"mergeNextPoint",!1);R(this,"currentLineLength",0);R(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?k.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=Ir[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&&k.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=er(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=er(l.points);if(!c)throw Error("Expected a previous point!");const{x:d,y:f}=this.editor.getPointInShapeSpace(a,t).toFixed(),g={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,g];this.currentLineLength<Ir[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=jt();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(),g=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,m={x:c,y:d,z:g};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(k.Dist2(y,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const x=er(l);if(!x)throw Error("Expected a previous segment!");const b=er(x.points);if(!b)throw Error("Expected a previous last point!");let C;const E=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(x.type==="straight"){this.currentLineLength+=k.Dist(b,E),C={type:"straight",points:[{...b},E]};const M=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=ve.applyToPoint(M,b)}else C={type:"straight",points:[E,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(k.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=er(b.points);if(!C)throw Error("No previous point!");const E={type:"free",points:[...k.PointsBetween(C,m,6).map(A=>({x:Ca(A.x),y:Ca(A.y),z:Ca(A.z)}))]},_=[...x,E];this.currentLineLength<Ir[a.props.size]*4&&(this.currentLineLength=this.getLineLength(_));const M={id:s,type:this.shapeType,props:{segments:_}};this.canClose()&&(M.props.isClosed=this.getIsClosed(_,i,o)),this.editor.updateShapes([M])}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 E,_=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(_=!b,this.didJustShiftClickToExtendPreviousShapeLine=!1):_=!b;let M=this.editor.getPointInShapeSpace(a,C).toFixed().toJson(),A=!1,O;if((this.editor.user.getIsSnapMode()?!b:b)&&y.length>2){let U,G=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],Z=er(L.points);if(!(V&&Z))continue;const W=k.NearestPointOnLineSegment(V,Z,M);if(k.DistMin(W,M,G)){U=W.toFixed().toJson(),G=k.Dist(W,M),O=L;break}}U&&(A=!0,M=U)}if(A&&O){const U=this.editor.getShapePageTransform(a),G=O.points[0],z=er(O.points);if(!z)throw Error("Expected a last point!");const N=ve.applyToPoint(U,G),L=ve.applyToPoint(U,z),V=ve.applyToPoint(U,M);this.editor.snaps.setIndicators([{id:Tt(),type:"points",points:[N,V,L]}])}else{if(this.editor.snaps.clearIndicators(),_){const U=k.Angle(x,C),z=Wy(U,24)-U;E=k.RotWith(C,x,z)}else E=C;M=this.editor.getPointInShapeSpace(a,E).toFixed().toJson()}this.currentLineLength+=k.Dist(v.points[0],M),y[y.length-1]={...v,type:"straight",points:[v.points[0],M]};const B={id:s,type:this.shapeType,props:{segments:y}};this.canClose()&&(B.props.isClosed=this.getIsClosed(l,i,o)),this.editor.updateShapes([B]);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+=k.Dist(x[x.length-1],m),x.push(m);y[y.length-1]={...v,points:x},this.currentLineLength<Ir[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=jt(),E=this.editor.getShape(s).props;this.editor.createShapes([{id:C,type:this.shapeType,x:Ca(r.currentPagePoint.x),y:Ca(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:E.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(f*1.25).toFixed():.5}]}]}}]),this.initialShape=Xt(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+=k.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)}}R(lT,"id","drawing");var oP;let $9=(oP=class extends Ne{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},R(oP,"id","idle"),oP);class Sy extends Ne{constructor(){super(...arguments);R(this,"shapeType","draw")}static children(){return[$9,lT]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}R(Sy,"id","draw"),R(Sy,"initial","idle"),R(Sy,"isLockable",!1);class Kk extends Sk{constructor(){super(...arguments);R(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)&&Pme(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")}}R(Kk,"id","frame"),R(Kk,"initial","idle");function Pme(n,e,t){return e.includes(n.id)?!1:n.parentId===t.parentId}var aP;let kme=(aP=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")}},R(aP,"id","idle"),aP);var lP;let Ime=(lP=class extends Ne{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=jt(),s=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`),i=eo(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(qi),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=jt();this.editor.markHistoryStoppingPoint(`creating_geo:${t}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(qi),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(qi),scale:r,...i}}]);const o=this.editor.getShape(t);if(!o)return;const{w:a,h:l}=o.props,c=new k(a/2,l/2).mul(r),d=this.editor.getShapeParentTransform(o);d&&c.rot(-d.rotation());const f=eo(new k(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(qi),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},R(lP,"id","pointing"),lP);class Wk extends Ne{constructor(){super(...arguments);R(this,"shapeType","geo")}static children(){return[kme,Ime]}}R(Wk,"id","geo"),R(Wk,"initial","idle");class vy extends Ne{constructor(){super(...arguments);R(this,"shapeType","highlight")}static children(){return[$9,lT]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}R(vy,"id","highlight"),R(vy,"initial","idle"),R(vy,"isLockable",!1);var cP;let Eme=(cP=class extends Ne{constructor(){super(...arguments);R(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")}},R(cP,"id","idle"),cP);const ZN=2;var uP;let _me=(uP=class extends Ne{constructor(){super(...arguments);R(this,"shape",{});R(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(tr),l=a[a.length-1],c=a[a.length-2],d=ve.applyToPoint(this.editor.getShapeParentTransform(this.shape),new k(this.shape.x,this.shape.y)),f=k.Sub(s,d).addXY(.1,.1),g=eo(f,this.editor),m=Xt(this.shape.props.points);if(k.DistMin(l,c,ZN)||k.DistMin(g,l,ZN))m[l.id]={id:l.id,index:l.index,x:g.x,y:g.y};else{const y=Oo(l.index);m[y]={id:y,index:y,x:g.x,y:g.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:m}}])}else{const o=jt();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${o}`);const a=eo(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=er(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()}},R(uP,"id","pointing"),uP);class Vk extends Ne{constructor(){super(...arguments);R(this,"shapeType","line")}static children(){return[Eme,_me]}}R(Vk,"id","line"),R(Vk,"initial","idle");var dP;let Tme=(dP=class extends Ne{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},R(dP,"id","idle"),dP);const Mme=0,Rt=200,Av=new k(Rt/2,Rt/2),B9=10,Ame=n=>[[["a1"],new k(Rt*.5,Rt*-.5-n.options.adjacentShapeMargin)],[["a2"],new k(Rt*1.5+n.options.adjacentShapeMargin,Rt*.5)],[["a3"],new k(Rt*.5,Rt*1.5+n.options.adjacentShapeMargin)],[["a4"],new k(Rt*-.5-n.options.adjacentShapeMargin,Rt*.5)]];function Ome(n,e){if(e===1)return Ame(n);const t=Rt*e,r=n.options.adjacentShapeMargin*e;return[[["a1"],new k(t*.5,t*-.5-r)],[["a2"],new k(t*1.5+r,t*.5)],[["a3"],new k(t*.5,t*1.5+r)],[["a4"],new k(t*-.5-r,t*.5)]]}function U9(n,e,t,r,s,i){return Object.fromEntries(Ome(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 H9(n,e,t,r){const s=new Set(n.getSelectedShapeIds()),i=(Rt+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(U9(n,f.point(),e,d.props.growY,r,t))))}const l=a.length;let c;for(const[d,f]of o)for(let g=0;g<l;g++)c=a[g],c&&(k.Dist2(f,c)>i||n.isPointInShape(d,c)&&(a[g]=void 0));return rt(a)}function K9(n,e,t,r,s=!1){let i;const o=n.getCurrentPageShapesSorted(),a=(Rt+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&&k.Dist2(d.center,t)<a&&n.isPointInShape(c,t)){i=c;break}}}if(n.complete(),!i||s){n.markHistoryStoppingPoint("creating note shape");const l=jt();n.createShape({id:l,type:"note",x:t.x,y:t.y,rotation:r,opacity:e.opacity,props:{...e.props,richText:ki(""),growY:0,fontSizeAdjustment:0,url:""}});const c=n.getShape(l);if(!c)return;const d=n.getPointInParentSpace(c,k.Sub(t,k.Rot(Av.clone().mul(c.props.scale),r)));n.updateShape({id:l,type:"note",x:d.x,y:d.y}),i=n.getShape(l)}return Dme(n),i}const Rme=16;function Dme(n){const e=n.getSelectionPageBounds(),t=n.getViewportPageBounds();if(e&&!t.contains(e)){const r=e.clone().expandBy(Rme/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 hP;let jme=(hP=class extends Ne{constructor(){super(...arguments);R(this,"dragged",!1);R(this,"info",{});R(this,"markId","");R(this,"shape",{})}onEnter(){const{editor:t}=this,r=jt();this.markId=t.markHistoryStoppingPoint(`creating_note:${r}`);const s=this.editor.inputs.originPagePoint.clone(),i=Nme(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);i&&s.sub(i),this.shape=Lme(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)}},R(hP,"id","pointing"),hP);function Nme(n,e,t){let r=B9/n.getZoomLevel(),s;for(const i of H9(n,0,t,0)){const o=k.Sub(e,i),a=o.len();a<r&&(r=a,s=o)}return s}function Lme(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=eo(new k(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 qk extends Ne{constructor(){super(...arguments);R(this,"shapeType","note")}static children(){return[Tme,jme]}}R(qk,"id","note"),R(qk,"initial","idle");function Fme(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 Ea=$L(Fme,32);var fP;let zme=(fP=class extends Ne{onPointerMove(e){switch(e.target){case"shape":case"canvas":Ea(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){Ea.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")}},R(fP,"id","idle"),fP);var pP;let $me=(pP=class extends Ne{constructor(){super(...arguments);R(this,"shape");R(this,"markId","");R(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=jt();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=jt(),{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:ki(""),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 k;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,ys(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 k(c,d),g=eo(f,this.editor),m=k.Sub(f,g);this.editor.updateShape({...o,x:c-m.x,y:d-m.y})}else this.editor.updateShape({...o,x:c,y:d});return o}},R(pP,"id","pointing"),pP);class Gk extends Ne{constructor(){super(...arguments);R(this,"shapeType","text")}static children(){return[zme,$me]}}R(Gk,"id","text"),R(Gk,"initial","idle");const Bme=[Gk,Sy,Wk,qk,Vk,Kk,Hk,vy],Ume=ot.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 p.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:Zt,onContextMenu:e?Zt:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:et})});function Hme(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 W9(n){return n==="start-legacy"||n==="middle-legacy"||n==="end-legacy"}function Kme(n,e,t){const r=V9(n),s=r.isEditing,i=Q(),o=P.useRef(null),a=(t||"").trim().length===0;P.useEffect(()=>{function d(f){var g,m;f.shapeId===n&&((m=(g=o.current)==null?void 0:g.select)==null||m.call(g))}return i.on("select-all-text",d),()=>{i.off("select-all-text",d)}},[i,n,s]),P.useEffect(()=>{var d,f,g,m;s&&(document.activeElement!==o.current&&((d=o.current)==null||d.focus()),i.getInstanceState().isCoarsePointer&&((f=o.current)==null||f.select()),kt.isSafari&&((g=o.current)==null||g.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=l0.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 V9(n){const e=Q(),t=ie("isEditing",()=>e.getEditingShapeId()===n,[e]),r=ie("isEditingAnything",()=>!!e.getEditingShapeId(),[e]),s=P.useCallback(i=>{e.dispatch({...Hs(i),type:"pointer",name:"pointer_down",target:"shape",shape:e.getShape(n)}),Zt(i)},[e,n]);return{handleFocus:Zf,handleBlur:Zf,handleInputPointerDown:s,handleDoubleClick:Zt,isEditing:t,isEditingAnything:r}}const Wme=ot.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:g=0,onKeyDown:m,classNamePrefix:y,style:v,textWidth:x,textHeight:b}){const{rInput:C,isEmpty:E,isEditing:_,isEditingAnything:M,...A}=Kme(e,t,r),O=l0.normalizeTextForDom(r||""),D=O.length>0,B=W9(l);if(!_&&!D)return null;const U=y||"tl-text";return p.jsx("div",{className:`${U}-label tl-text-wrapper tl-plain-text-wrapper`,"data-font":i,"data-align":l,"data-hastext":!E,"data-isediting":_,"data-iseditinganything":M,"data-textwrap":!!d,"data-isselected":f,style:{justifyContent:l==="middle"||B?"center":l,alignItems:c==="middle"?"center":c,padding:g,...v},children:p.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:[p.jsx("div",{className:`${U} tl-text tl-text-content`,dir:"auto",children:O.split(`
459
+ `).map((G,z)=>p.jsx("div",{dir:"auto",children:G},z))}),(M||f)&&p.jsx(Ume,{ref:C,text:r,isEditing:_,shapeId:e,...A,handleKeyDown:m??A.handleKeyDown})]})})});function _i(){return Ha({isDarkMode:Vp()})}function cT(n){return{key:`${Na.id}:${n}`,async getElement(){return n!=="pattern"?null:p.jsx(Vme,{})}}}function Vme(){const n=dT(),e=Su(),t=_i(),r=8/12;return p.jsxs(p.Fragment,{children:[p.jsxs("mask",{id:e,children:[p.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),p.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[p.jsx("line",{x1:r*1,y1:r*3,x2:r*3,y2:r*1}),p.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),p.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),p.jsx("pattern",{id:n(1,t.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:p.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:t.solid,mask:`url(#${e})`})})]})}function uT(){return{key:`${Na.id}:pattern`,component:Xme}}const _f=8,JN=(n,e,t)=>new Promise((r,s)=>{const i=_f*e*n,o=document.createElement("canvas");o.width=i,o.height=i;const a=o.getContext("2d");if(!a)return;a.fillStyle=t?dS.darkMode.solid:dS.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||bn.throwToBlob.get()?s():r(d)})}),QN=(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 VC=null;function qme(){return VC||(VC={white:QN([1,1],n=>{n.fillStyle="#f8f9fa",n.fillRect(0,0,1,1)}),black:QN([1,1],n=>{n.fillStyle="#212529",n.fillRect(0,0,1,1)})}),VC}function q9(n){return Math.ceil(Math.log2(Math.max(1,n)))}function dT(){const n=Zi("hash_pattern");return P.useCallback((e,t)=>{const r=q9(e);return AE(n,`${t}_${r}`)},[n])}function G9(n){const e=[],r=q9(n);for(let s=0;s<=r;s++)e.push(Math.pow(2,s));return e}function Gme(n){const e=qme();return G9(n).flatMap(t=>[{zoom:t,url:e.white,theme:"light"},{zoom:t,url:e.black,theme:"dark"}])}function Yme(){const n=Q(),e=ie("devicePixelRatio",()=>n.getInstanceState().devicePixelRatio,[n]),t=ie("maxZoom",()=>Math.ceil(er(n.getCameraOptions().zoomSteps)),[n]),[r,s]=P.useState(!1),[i,o]=P.useState(()=>Gme(t)),a=dT();return P.useEffect(()=>{const c=Promise.all(G9(t).flatMap(f=>[JN(e,f,!1).then(g=>({zoom:f,theme:"light",url:URL.createObjectURL(g)})),JN(e,f,!0).then(g=>({zoom:f,theme:"dark",url:URL.createObjectURL(g)}))]));let d=!1;return c.then(f=>{d||(o(f),s(!0))}),()=>{d=!0,s(!1),c.then(f=>{for(const{url:g}of f)URL.revokeObjectURL(g)})}},[e,t]),{defs:p.jsx(p.Fragment,{children:i.map(c=>{const d=a(c.zoom,c.theme);return p.jsx("pattern",{id:d,width:_f,height:_f,patternUnits:"userSpaceOnUse",children:p.jsx("image",{href:c.url,width:_f,height:_f})},d)})}),isReady:r}}function Xme(){const n=Q(),e=P.useRef(null),{defs:t,isReady:r}=Yme();return P.useEffect(()=>{if(r&&kt.isSafari){const s=Y9(e.current);s&&n.timers.requestAnimationFrame(()=>{s.style.display="none",n.timers.requestAnimationFrame(()=>{s.style.display=""})})}},[n,r]),p.jsx("g",{ref:e,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function Y9(n){return n.classList.contains("tl-html-layer")?n:n.parentElement?Y9(n.parentElement):null}const vr=ot.memo(function({theme:e,d:t,color:r,fill:s,scale:i}){switch(s){case"none":return null;case"solid":return p.jsx("path",{fill:e[r].semi,d:t});case"semi":return p.jsx("path",{fill:e.solid,d:t});case"fill":return p.jsx("path",{fill:e[r].fill,d:t});case"pattern":return p.jsx(Zme,{theme:e,color:r,fill:s,d:t,scale:i})}});function Zme({d:n,color:e,theme:t}){const r=Q(),s=Up(),i=ie("zoomLevel",()=>r.getZoomLevel(),[r]),o=dT(),a=r.getZoomLevel()<=.18;return p.jsxs(p.Fragment,{children:[p.jsx("path",{fill:t[e].pattern,d:n}),p.jsx("path",{fill:s?`url(#${o(1,t.id)})`:a?t[e].semi:`url(#${o(i,t.id)})`,d:n})]})}function Jme(n){return n.replace(/\s/g," ")}function Yk(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(p.jsx("tspan",{alignmentBaseline:"mathematical",x:i,y:d.y+o,children:`
460
+ `},l.length)),l.push(p.jsx("tspan",{alignmentBaseline:"mathematical",x:d.x+i,y:d.y+o,unicodeBidi:"plaintext",children:Jme(c)},l.length)),a=d.y;return p.jsx("text",{fontSize:t.fontSize,fontFamily:t.fontFamily,fontStyle:t.fontStyle,fontWeight:t.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,children:l})}function Qme({fontSize:n,font:e,align:t,verticalAlign:r,text:s,labelColor:i,bounds:o,padding:a=16,stroke:l=!0}){const c=Q(),d=_i(),f={fontSize:n,fontFamily:t4[e],textAlign:t,verticalTextAlign:r,width:Math.ceil(o.width),height:Math.ceil(o.height),padding:a,lineHeight:ar.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:i,stroke:void 0,strokeWidth:void 0},g=c.textMeasure.measureTextSpans(s,f),m=Hme(t,a,g,o.width);m&&(f.offsetX=m),f.offsetX+=o.x,f.offsetY+=o.y;const y=Yk(c,g,f);let v=null;return l&&(f.fill=d.background,f.stroke=d.background,f.strokeWidth=2,v=Yk(c,g,f)),p.jsxs(p.Fragment,{children:[v,y]})}const eye=vE("arrow label size",(n,e)=>{n.fonts.trackFontsForShape(e);const t=jo(n,e);let r=0,s=0;const i=t.isStraight?new Ia({start:k.From(t.start.point),end:k.From(t.end.point)}):new kd({center:k.Cast(t.handleArc.center),start:k.Cast(t.start.point),end:k.Cast(t.end.point),sweepFlag:t.bodyArc.sweepFlag,largeArcFlag:t.bodyArc.largeArcFlag});if(e.props.text.trim()){const o=i.bounds,a=Xk(e),{w:l,h:c}=n.textMeasure.measureText(e.props.text,{...ar,fontFamily:za[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:g}=n.textMeasure.measureText(e.props.text,{...ar,fontFamily:za[e.props.font],fontSize:a,maxWidth:r});r=f,s=g}}return new k(r,s).addScalar(Y_*2*e.props.scale)},{areRecordsEqual:(n,e)=>n.props===e.props});function hT(n,e){return e.props.text.trim()===""?new k(0,0).addScalar(Y_*2*e.props.scale):eye.get(n,e.id)??new k(0,0)}function X9(n){const e=Ir[n.props.size];return(fpe+(e-Ir.s)*2+(e===Ir.xl?20:0))*n.props.scale}function tye(n,e,t){const r=hT(n,e),s=X9(e),i=k.Nudge(t.start.point,t.end.point,s),o=k.Nudge(t.end.point,t.start.point,s),a=BE(i,o,ye.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;k.Dist2(l,i)>k.Dist2(c,i)&&([c,l]=a);const d=i.add(k.Sub(t.middle,l)),f=o.add(k.Sub(t.middle,c)),g=k.Dist(t.start.point,d)/t.length,m=k.Dist(t.start.point,f)/t.length;return{start:g,end:m}}function nye(n,e,t){const r=hT(n,e),s=X9(e),i=Math.sign(e.props.bend),o=s/t.handleArc.radius*i,a=k.Angle(t.bodyArc.center,t.start.point)-o,l=k.Angle(t.bodyArc.center,t.end.point)+o,c=Yc(t.bodyArc.center,t.bodyArc.radius,a),d=Yc(t.bodyArc.center,t.bodyArc.radius,l),f=[],g=tL(t.bodyArc.center,t.bodyArc.radius,a,l,i,ye.FromCenter(c,r).corners);f.push(new wn({points:ye.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const m=tL(t.bodyArc.center,t.bodyArc.radius,a,l,i,ye.FromCenter(d,r).corners);f.push(new wn({points:ye.FromCenter(d,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const O of[...g??[],...m??[],c,d])f.push(new QE({x:O.x-3,y:O.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const y=(g&&nL(t.start.point,g))??t.middle,v=(m&&nL(t.end.point,m))??t.middle,x=k.Angle(t.bodyArc.center,t.start.point),b=k.Angle(t.bodyArc.center,t.end.point),C=k.Angle(t.bodyArc.center,y),E=k.Angle(t.bodyArc.center,v);if(Il(x,C,i)>Il(x,E,i))return{start:.5,end:.5,dbg:f};const _=Il(x,b,i),M=Il(x,C,i)/_,A=Il(x,E,i)/_;return{start:M,end:A,dbg:f}}function xy(n,e){let t;const r=[],s=jo(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=tye(n,e,s),l=eL(n,e,a,i);t=k.Lrp(s.start.point,s.end.point,l)}else{const a=nye(n,e,s);a.dbg&&r.push(...a.dbg);const l=eL(n,e,a,i),c=rye(k.Angle(s.bodyArc.center,s.start.point),k.Angle(s.bodyArc.center,s.end.point),Math.sign(e.props.bend),l);t=Yc(s.bodyArc.center,s.bodyArc.radius,c)}const o=hT(n,e);return{box:ye.FromCenter(t,o),debugGeom:r}}function eL(n,e,t,r){const{hasEndArrowhead:s,hasEndBinding:i,hasStartBinding:o,hasStartArrowhead:a}=r,l=e7(n,e);let c=Rn(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 tL(n,e,t,r,s,i){const o=dk(n,e,i),a=Il(t,r,s);return o==null?void 0:o.filter(l=>{const c=Il(t,k.Angle(n,l),s);return c>=0&&c<=a})}function nL(n,e){let t=null,r=-1/0;for(const s of e){const i=k.Dist2(n,s);i>r&&(t=s,r=i)}return t}function rye(n,e,t,r){const s=Il(n,e,t);return n+s*r*t*-1}function Xk(n){return hpe[n.props.size]*n.props.scale}function sye(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?k.Dist(s,r):Math.abs(n.bodyArc.length),o=Math.max(Math.min(i/5,t*3),t);let a;if(n.isStraight)a=k.Nudge(r,s,o);else{const l=dse(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 k.IsNaN(a)&&(a=n.start.point),{point:r,int:a}}function iye({point:n,int:e}){const t=k.RotWith(e,n,wt/6),r=k.RotWith(e,n,-wt/6);return`M ${t.x} ${t.y} L ${n.x} ${n.y} L ${r.x} ${r.y}`}function oye({point:n,int:e}){const t=k.RotWith(e,n,wt/6),r=k.RotWith(e,n,-wt/6);return`M ${t.x} ${t.y} L ${r.x} ${r.y} L ${n.x} ${n.y} Z`}function aye({point:n,int:e}){const t=k.Sub(e,n).div(2),r=k.Add(n,k.Rot(t,Kt)),s=k.Sub(n,k.Rot(t,Kt));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${s.x} ${s.y} Z`}function lye({point:n,int:e}){const t=k.Lrp(n,e,.45),r=k.Dist(t,n);return`M ${t.x-r},${t.y}
461
+ a ${r},${r} 0 1,0 ${r*2},0
462
+ a ${r},${r} 0 1,0 -${r*2},0 `}function cye({point:n,int:e}){const t=k.Lrp(n,e,.75),r=k.RotWith(t,n,wt/4),s=k.RotWith(t,n,-wt/4),i=k.Lrp(r,s,.5);return i.add(k.Sub(i,n)),`M ${i.x} ${i.y} L ${s.x} ${s.y} ${n.x} ${n.y} L ${r.x} ${r.y} Z`}function uye({int:n,point:e}){const t=k.Lrp(e,n,.85),r=k.Sub(t,e).div(2),s=k.Add(e,k.Rot(r,Kt)),i=k.Sub(e,k.Rot(r,Kt)),o=k.Add(t,k.Rot(r,Kt)),a=k.Sub(t,k.Rot(r,Kt));return`M ${s.x} ${s.y} L ${o.x} ${o.y} L ${a.x} ${a.y} L ${i.x} ${i.y} Z`}function dye({int:n,point:e}){const t=k.Sub(n,e).div(2),r=k.Add(e,k.Rot(t,Kt)),s=k.Sub(e,k.Rot(t,Kt));return`M ${r.x} ${r.y} L ${s.x} ${s.y}`}function c0(n,e,t){const r=e==="end"?n.end.arrowhead:n.start.arrowhead;if(r==="none")return;const s=sye(n,e,t);if(s){switch(r){case"bar":return dye(s);case"square":return uye(s);case"diamond":return cye(s);case"dot":return lye(s);case"inverted":return aye(s);case"arrow":return iye(s);case"triangle":return oye(s)}return""}}function hye(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 Z9(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 J9(n,e){return`M${n.x},${n.y}L${e.x},${e.y}`}function fye(n){return J9(n.start.handle,n.end.handle)}function Q9(n){return J9(n.start.point,n.end.point)}class wy extends Ji{constructor(){super(...arguments);R(this,"_resizeInitialBindings",new qo)}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=xs(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?[oT[`tldraw_${t.props.font}`].normal.normal]:bi}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=jo(this.editor,t),s=[],i=r.isStraight?new Ia({start:k.From(r.start.point),end:k.From(r.end.point)}):new kd({center:k.Cast(r.handleArc.center),start:k.Cast(r.start.point),end:k.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let o;if(t.props.text.trim()){const a=xy(this.editor,t);s.push(...a.debugGeom),o=new Uo({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Ii({children:[...o?[i,o]:[i],...s]})}getHandles(t){const r=jo(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=xs(this.editor,t);if(i==="middle"){const{start:A,end:O}=Id(this.editor,t,o),D=k.Sub(O,A),B=k.Per(D),U=k.Med(O,A),G=k.Sub(U,B),z=k.Add(U,B),N=k.NearestPointOnLineSegment(G,z,r,!1);let L=k.Dist(N,U);return k.Clockwise(N,O,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 py(this.editor,t,i),a.props[i]={x:r.x,y:r.y},a;const f=this.editor.getShapePageTransform(t.id).applyToPoint(r),g=this.editor.getShapeAtPoint(f,{hitInside:!0,hitFrameInside:!0,margin:0,filter:A=>!A.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:A,binding:"arrow"})});if(!g){py(this.editor,t,i);const A=eo(new k(r.x,r.y),this.editor);return a.props[i]={x:A.x,y:A.y},a}const m=this.editor.getShapeGeometry(g),y=ye.ZeroFix(m.bounds),x=this.editor.getShapePageTransform(a.id).applyToPoint(r),b=this.editor.getPointInShapeSpace(g,x);let C=s;C||(!l||l&&g.id!==l.toId)&&(C=this.editor.inputs.pointerVelocity.len()<.5),s||(m.isClosed||(C=!0),d&&g.id===d.toId&&d.props.isPrecise&&(C=!0));const E={x:(b.x-y.minX)/y.width,y:(b.y-y.minY)/y.height};C&&k.Dist(b,y.center)<Math.max(4,Math.min(Math.min(y.width,y.height)*.15,16))/this.editor.getZoomLevel()&&(E.x=.5,E.y=.5);const _={terminal:i,normalizedAnchor:E,isPrecise:C,isExact:this.editor.inputs.altKey};uf(this.editor,t,g.id,_),this.editor.setHintingShapes([g.id]);const M=xs(this.editor,t);return M.start&&M.end&&M.start.toId===M.end.toId&&k.Equals(M.start.props.normalizedAnchor,M.end.props.normalizedAnchor)&&uf(this.editor,t,M.end.toId,{...M.end.props,normalizedAnchor:{x:M.end.props.normalizedAnchor.x+.05,y:M.end.props.normalizedAnchor.y}}),a}onTranslateStart(t){const r=xs(this.editor,t),s=Id(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)))){sL.set(t,{pagePosition:i.applyToPoint(t),terminalBindings:rh(s,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:i.applyToPoint(l)}:null})}),r.start&&(RS({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&RS({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=sL.get(t);if(!s)return;const i=this.editor.getShapePageTransform(r.id),o=k.Sub(i.applyToPoint(r),s.pagePosition);for(const a of Object.values(s.terminalBindings)){if(!a)continue;const l=k.Add(a.pagePosition,k.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),g={x:(f.x-d.minX)/d.width,y:(f.y-d.minY)/d.height};uf(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:g,isPrecise:!0})}else py(this.editor,r,a.binding.props.terminal)}}onResize(t,r){const{scaleX:s,scaleY:i}=r,o=this._resizeInitialBindings.get(t,()=>xs(this.editor,t)),a=Id(this.editor,t,o),{start:l,end:c}=Xt(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),g=Math.abs(i),m=o!=null&&o.start?k.From(o.start.props.normalizedAnchor):null,y=o!=null&&o.end?k.From(o.end.props.normalizedAnchor):null;return s<0&&i>=0?(d!==0&&(d*=-1,d*=Math.max(f,g)),m&&(m.x=1-m.x),y&&(y.x=1-y.x)):s>=0&&i<0?(d!==0&&(d*=-1,d*=Math.max(f,g)),m&&(m.y=1-m.y),y&&(y.y=1-y.y)):s>=0&&i>=0?d!==0&&(d*=Math.max(f,g)):s<0&&i<0&&(d!==0&&(d*=Math.max(f,g)),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&&uf(this.editor,t,o.start.toId,{...o.start.props,normalizedAnchor:m.toJson()}),o.end&&y&&uf(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=_i(),s=this.editor.getOnlySelectedShape(),i=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),o=jo(this.editor,t);if(!(o!=null&&o.isValid))return null;const a=xy(this.editor,t),l=t.id===this.editor.getOnlySelectedShapeId(),d=this.editor.getEditingShapeId()===t.id||t.props.text;return p.jsxs(p.Fragment,{children:[p.jsx(Kl,{style:{minWidth:50,minHeight:50},children:p.jsx(rL,{shape:t,shouldDisplayHandles:i&&(s==null?void 0:s.id)===t.id})}),d&&p.jsx(Wme,{shapeId:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:Xk(t),lineHeight:ar.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w-Y_*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=av(t.id),s=Zi(t.id+"_clip"),i=jo(this.editor,t);if(!i)return null;const{start:o,end:a}=Id(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(k.Equals(o,a))return null;const f=Ir[t.props.size]*t.props.scale,g=i.start.arrowhead&&c0(i,"start",f),m=i.end.arrowhead&&c0(i,"end",f),y=i.isStraight?Q9(i):Z9(i),v=g&&i.start.arrowhead!=="arrow"||m&&i.end.arrowhead!=="arrow"||!!d;if(r&&d)return p.jsx("rect",{x:te(d.x),y:te(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 p.jsxs("g",{children:[v&&p.jsx("defs",{children:p.jsx(t7,{hasText:t.props.text.trim().length>0,bounds:c,labelBounds:d?d.getBounds():new ye(0,0,0,0),as:x&&g?g:"",ae:b&&m?m:""})}),p.jsxs("g",{style:{clipPath:v?`url(#${s})`:void 0,WebkitClipPath:v?`url(#${s})`:void 0},children:[v&&p.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),p.jsx("path",{d:y})]}),g&&p.jsx("path",{d:g}),m&&p.jsx("path",{d:m}),d&&p.jsx("rect",{x:te(d.x),y:te(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(cT(t.props.fill));const s=Ha(r),i=1/t.props.scale;return p.jsxs("g",{transform:`scale(${i})`,children:[p.jsx(rL,{shape:t,shouldDisplayHandles:!1}),p.jsx(Qme,{fontSize:Xk(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:s[t.props.labelColor].solid,bounds:xy(this.editor,t).box.clone().expandBy(-4.25*t.props.scale),padding:0})]})}getCanvasSvgDefs(){return[uT(),{key:"arrow:dot",component:pye},{key:"arrow:cross",component:gye}]}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:St(t.props.scale,r.props.scale,s),start:{x:St(t.props.start.x,r.props.start.x,s),y:St(t.props.start.y,r.props.start.y,s)},end:{x:St(t.props.end.x,r.props.end.x,s),y:St(t.props.end.y,r.props.end.y,s)},bend:St(t.props.bend,r.props.bend,s),labelPosition:St(t.props.labelPosition,r.props.labelPosition,s)}}}R(wy,"type","arrow"),R(wy,"props",r4),R(wy,"migrations",s4);function e7(n,e){const t=jo(n,e);return t.isStraight?k.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const rL=Gn(function({shape:e,shouldDisplayHandles:t}){const r=Q(),s=_i(),i=jo(r,e),o=ye.ZeroFix(r.getShapeGeometry(e).bounds),a=xs(r,e),l=ie("force solid",()=>r.getZoomLevel()<.2,[r]),c=Zi(e.id+"_clip"),d=Zi("arrowhead-dot"),f=Zi("arrowhead-cross");if(!(i!=null&&i.isValid))return null;const g=Ir[e.props.size]*e.props.scale,m=i.start.arrowhead&&c0(i,"start",g),y=i.end.arrowhead&&c0(i,"end",g),v=i.isStraight?Q9(i):Z9(i);let x=null;if(t){const A=2/r.getZoomLevel(),{strokeDasharray:O,strokeDashoffset:D}=Hi(e7(r,e),A,{end:"skip",start:"skip",lengthRatio:2.5});x=a.start||a.end?p.jsx("path",{className:"tl-arrow-hint",d:i.isStraight?fye(i):hye(i),strokeDasharray:O,strokeDashoffset:D,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}=Hi(i.isStraight?i.length:Math.abs(i.bodyArc.length),g,{style:e.props.dash,forceSolid:l}),E=xy(r,e),_=!(i.start.arrowhead==="none"||i.start.arrowhead==="arrow"),M=!(i.end.arrowhead==="none"||i.end.arrowhead==="arrow");return p.jsxs(p.Fragment,{children:[p.jsx("defs",{children:p.jsx("clipPath",{id:c,children:p.jsx(t7,{hasText:e.props.text.trim().length>0,bounds:o,labelBounds:E.box,as:_&&m?m:"",ae:M&&y?y:""})})}),p.jsxs("g",{fill:"none",stroke:s[e.props.color].solid,strokeWidth:g,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[x,p.jsxs("g",{style:{clipPath:`url(#${c})`,WebkitClipPath:`url(#${c})`},children:[p.jsx("rect",{x:te(o.minX-100),y:te(o.minY-100),width:te(o.width+200),height:te(o.height+200),opacity:0}),p.jsx("path",{d:v,strokeDasharray:b,strokeDashoffset:C})]}),m&&_&&e.props.fill!=="none"&&p.jsx(vr,{theme:s,d:m,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),y&&M&&e.props.fill!=="none"&&p.jsx(vr,{theme:s,d:y,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),m&&p.jsx("path",{d:m}),y&&p.jsx("path",{d:y})]})]})});function t7({hasText:n,bounds:e,labelBounds:t,as:r,ae:s}){const i=`M${te(e.minX-100)},${te(e.minY-100)} h${e.width+200} v${e.height+200} h-${e.width+200} Z`,o=`M${te(t.minX)},${te(t.minY)} v${t.height} h${t.width} v-${t.height} Z`;return p.jsx("path",{d:`${i}${n?o:""}${r}${s}`})}const sL=new WeakMap;function pye(){const n=Zi("arrowhead-dot");return p.jsx("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:p.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function gye(){const n=Zi("arrowhead-cross");return p.jsxs("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[p.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),p.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const iL="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 Qd({url:n}){const e=Q(),t=ie("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return p.jsx("a",{className:ze("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t}),href:n,target:"_blank",rel:"noopener noreferrer",onPointerDown:Zt,onPointerUp:Zt,title:n,draggable:!1,children:p.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${iL}") center 100% / 100% no-repeat`,WebkitMask:`url("${iL}") center 100% / 100% no-repeat`}})})}const oL="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",mye=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function u0(n){return mye.map(t=>{const{offsetX:r,offsetY:s,blur:i,spread:o,color:a}=t,l=new k(r,s),{x:c,y:d}=l.rot(-n);return`${c}px ${d}px ${i}px ${o}px ${a}`}).join(", ")}const yye=300,n7=320,Sye=46,vye=101;class by extends gh{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:yye,h:n7,assetId:null}}component(e){return p.jsx(xye,{shape:e,util:this})}indicator(e){return p.jsx("rect",{width:te(e.props.w),height:te(e.props.h),rx:"6",ry:"6"})}onBeforeCreate(e){return aL(this.editor,e)}onBeforeUpdate(e,t){if(e.props.url!==t.props.url)if(Ys.isValid(t.props.url))bye(this.editor,t);else return{...t,props:{...t.props,url:e.props.url}};if(e.props.assetId!==t.props.assetId)return aL(this.editor,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:St(e.props.w,t.props.w,r),h:St(e.props.h,t.props.h,r)}}}R(by,"type","bookmark"),R(by,"props",u4),R(by,"migrations",d4);function xye({shape:n,util:e}){const t=n.props.assetId?e.editor.getAsset(n.props.assetId):null,r=!!Up()&&kt.isSafari,s=e.editor.getShapePageTransform(n).rotation(),i=wye(n),[o,a]=P.useState(!0),l=()=>a(!1);return p.jsx(zl,{children:p.jsxs("div",{className:ze("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:u0(s),maxHeight:n.props.h},children:[(!t||t.props.image)&&p.jsxs("div",{className:"tl-bookmark__image_container",children:[t?p.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:t==null?void 0:t.props.image,alt:(t==null?void 0:t.props.title)||""}):p.jsx("div",{className:"tl-bookmark__placeholder"}),(t==null?void 0:t.props.image)&&p.jsx(Qd,{url:n.props.url})]}),p.jsxs("div",{className:"tl-bookmark__copy_container",children:[t!=null&&t.props.title?p.jsx("h2",{className:"tl-bookmark__heading",children:lme(t.props.title)}):null,t!=null&&t.props.description&&(t!=null&&t.props.image)?p.jsx("p",{className:"tl-bookmark__description",children:t.props.description}):null,p.jsxs("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Zt,onPointerUp:Zt,onClick:Zt,children:[o&&(t!=null&&t.props.favicon)?p.jsx("img",{className:"tl-bookmark__favicon",src:t==null?void 0:t.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:l,alt:`favicon of ${i}`}):p.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${oL}") center 100% / 100% no-repeat`,WebkitMask:`url("${oL}") center 100% / 100% no-repeat`}}),p.jsx("span",{children:i})]})]})]})})}function aL(n,e){const t=e.props.assetId?n.getAsset(e.props.assetId):null;let r=n7;return t&&(t.props.image||(t.props.title?r=vye:r=Sye)),{...e,props:{...e.props,h:r}}}const wye=n=>{try{return new URL(n.props.url).hostname.replace(/^www\./,"")}catch{return n.props.url}};function bye(n,e){const{url:t}=e.props,r=Hl.createId(gI(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}}]),Cye(n,e))}const Cye=f0(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 lu(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${Pt(r)}L${Pt(s)}`;let i="";for(let o=2,a=t-1;o<a;o++)r=n[o].point,s=n[o+1].point,i+=Ss(r,s);return e?`M${Ss(n[0].point,n[1].point)}Q${Pt(n[1].point)}${Ss(n[1].point,n[2].point)}T${i}${Ss(n[t-1].point,n[0].point)}${Ss(n[0].point,n[1].point)}Z`:`M${Pt(n[0].point)}Q${Pt(n[1].point)}${Ss(n[1].point,n[2].point)}${n.length>3?"T":""}${i}L${Pt(n[t-1].point)}`}function Pye(n,e={}){const{start:t={},end:r={}}=e,{cap:s=!0}=t,{cap:i=!0}=r;tt(!t.taper&&!r.taper,"cap taper not supported here"),tt(!t.easing&&!r.easing,"cap easing not supported here"),tt(s&&i,"cap must be true");const o=Wo(n,e);Tv(o,e);const a=kye(o);let l="";for(const c of a)l+=Eye(c,e);return l}function kye(n){if(n.length<=2)return[n];const e=[];let t=[n[0]],r=k.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=k.Sub(l.point,a.point).uni(),i=k.Dpr(r,s),r=s,i<-.8){const f={...a,point:a.input};t.push(f),e.push(qC(t)),t=[f];continue}if(t.push(a),!(i>.7)&&(k.Dist2(o.point,a.point)+k.Dist2(a.point,l.point))/((o.radius+a.radius+l.radius)/3)**2<1.5){t.push(a),e.push(qC(t)),t=[a];continue}}return t.push(n[n.length-1]),e.push(qC(t)),e}function qC(n){const e=n[0];let t;for(;n.length>2&&(t=n[1],k.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],k.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:k.Sub(n[0].point,n[1].point).uni()},n[n.length-1]={...n[n.length-1],vector:k.Sub(n[n.length-2].point,n[n.length-1].point).uni()}),n}function Iye(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 Eye(n,e={}){if(n.length===0)return"";if(n.length===1)return Iye(n[0].point.x,n[0].point.y,n[0].radius);const{left:t,right:r}=p9(n,e);r.reverse();let s=`M${Pt(t[0])}T`;for(let i=1;i<t.length;i++)s+=Ss(t[i-1],t[i]);{const i=n[n.length-1],o=i.radius,a=i.vector.clone().per().neg(),l=k.Add(i.point,k.Mul(a,o)),c=k.Add(i.point,k.Mul(a,-o));s+=`${Pt(l)}A${te(o)},${te(o)} 0 0 1 ${Pt(c)}T`}for(let i=1;i<r.length;i++)s+=Ss(r[i-1],r[i]);{const i=n[0],o=i.radius,a=i.vector.clone().per(),l=k.Add(i.point,k.Mul(a,o)),c=k.Add(i.point,k.Mul(a,-o));s+=`${Pt(l)}A${te(o)},${te(o)} 0 0 1 ${Pt(c)}Z`}return s}const r7=(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=St(c.z,a[d].z,t)),{x:St(c.x,a[d].x,t),y:St(c.y,a[d].y,t),z:f}})}]},_ye=n=>n*.65+CG(n*wt/2)*.35,Tye=n=>({size:n,thinning:.5,streamline:Fd(n,[9,16],[.64,.74],!0),smoothing:.62,easing:Un.easeOutSine,simulatePressure:!0}),Mye=n=>({size:1+n*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:_ye}),lL=n=>({size:n,thinning:0,streamline:Fd(n,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:Un.linear}),Aye=n=>({size:n,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Un.linear});function fT({strokeWidth:n,showAsComplete:e}){return{size:1+n,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:Un.easeOutSine,last:e}}function Zk(n,e,t,r){const s=n.isComplete||t;return r?n.isPen?{...Aye(e),last:s}:{...lL(e),last:s}:n.dash==="draw"?n.isPen?{...Mye(e),last:s}:{...Tye(e),last:s}:{...lL(e),last:s}}function eh(n){const e=[];for(const t of n)if(t.type==="free"||t.points.length<2)e.push(...t.points.map(k.Cast));else{const r=Math.max(4,Math.floor(k.Dist(t.points[0],t.points[1])/16));e.push(...k.PointsBetween(t.points[0],t.points[1],r))}return e}function Oye(n,e,t){return{draw:"none",solid:"none",dotted:`${t} ${e*2}`,dashed:`${e*2} ${e*2}`}[n.props.dash]}class Cy extends Ji{constructor(){super(...arguments);R(this,"options",{maxPointsPerShape:600})}hideResizeHandles(t){return GC(t)}hideRotateHandle(t){return GC(t)}hideSelectionBoundsFg(t){return GC(t)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(t){const r=eh(t.props.segments),s=(Ir[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 QE({x:-s,y:-s,radius:s,isFilled:!0})}const i=Wo(r,Zk(t.props,s,t.props.isPen,!0)).map(o=>o.point);return t.props.isClosed?new wn({points:i,isFilled:t.props.fill!=="none"}):new dh({points:i})}component(t){return p.jsx(Kl,{children:p.jsx(cL,{shape:t})})}indicator(t){var d;const r=eh(t.props.segments);let s=(Ir[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+=ro(t.id)()*(s/6));const o=t.props.isComplete||((d=er(t.props.segments))==null?void 0:d.type)==="straight",a=Zk(t.props,s,o,!0),l=Wo(r,a),c=l.length>1?lu(l,t.props.isClosed):s7(r[0],s);return p.jsx("path",{d:c})}toSvg(t,r){r.addExportDef(cT(t.props.fill));const s=1/t.props.scale;return p.jsx("g",{transform:`scale(${s})`,children:p.jsx(cL,{shape:t,zoomOverride:1})})}getCanvasSvgDefs(){return[uT()]}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:Ca(s*l),y:Ca(i*c),z:d}))});return{props:{segments:o}}}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return Ir[t.props.size]*r/2*t.props.scale}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,segments:r7(t.props.segments,r.props.segments,s),scale:St(t.props.scale,r.props.scale,s)}}}R(Cy,"type","draw"),R(Cy,"props",f4),R(Cy,"migrations",p4);function s7(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 GC(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function cL({shape:n,zoomOverride:e}){var m;const t=_i(),r=Q(),s=eh(n.props.segments),i=n.props.isComplete||((m=er(n.props.segments))==null?void 0:m.type)==="straight";let o=(Ir[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+=ro(n.id)()*(o/6));const c=Zk(n.props,o,i,a);if(!a&&n.props.dash==="draw")return p.jsxs(p.Fragment,{children:[n.props.isClosed&&n.props.fill&&s.length>1?p.jsx(vr,{d:lu(Wo(s,c),n.props.isClosed),theme:t,color:n.props.color,fill:n.props.isClosed?n.props.fill:"none",scale:n.props.scale}):null,p.jsx("path",{d:Pye(s,c),strokeLinecap:"round",fill:t[n.props.color].solid})]});const d=Wo(s,c),f=d.length<2,g=f?s7(s[0],0):lu(d,n.props.isClosed);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{d:g,theme:t,color:n.props.color,fill:f||n.props.isClosed?n.props.fill:"none",scale:n.props.scale}),p.jsx("path",{d:g,strokeLinecap:"round",fill:f?t[n.props.color].solid:"none",stroke:t[n.props.color].solid,strokeWidth:o,strokeDasharray:f?"none":Oye(n,o,l),strokeDashoffset:"0"})]})}function Rye(n){if(typeof n!="string")throw new TypeError("Expected a string");return n.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Dye(n,e){const t=Ze(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(i7(s.hostnames,r)){const i=s.fromEmbedUrl(e);if(i)return{definition:s,url:i,embedUrl:e}}}const jye=n=>n.split("*").map(e=>Rye(e)).join(".+"),i7=(n,e)=>!!n.find(t=>{const r=new RegExp(jye(t));return e.match(r)});function Nye(n,e){const t=Ze(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(i7(s.hostnames,r)){const i=s.toEmbedUrl(e);if(i)return{definition:s,embedUrl:i,url:e}}}function Lye(n,e){try{return Nye(n,e)??Dye(n,e)}catch{return}}const Fye=n=>Object.entries(n).filter(([e,t])=>t).map(([e])=>e).join(" "),ba=class ba extends gh{static setEmbedDefinitions(e){ba.embedDefinitions=e}getEmbedDefinitions(){return ba.embedDefinitions}getEmbedDefinition(e){return Lye(ba.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 ov(e,t,{minWidth:i,minHeight:o})}component(e){const t=Up(),{w:r,h:s,url:i}=e.props,o=av(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 p.jsx(zl,{className:"tl-embed-container",id:e.id,children:p.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:u0(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 p.jsx(zl,{className:"tl-embed-container",id:e.id,children:p.jsx(zye,{id:m,width:te(r),height:te(s),isInteractive:d,pageRotation:c})})}const g=Fye({...Che,...(a==null?void 0:a.definition.overridePermissions)??{}});return p.jsx(zl,{className:"tl-embed-container",id:e.id,children:a!=null&&a.definition?p.jsx("iframe",{className:"tl-embed",sandbox:g,src:a.embedUrl,width:te(r),height:te(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:d?"auto":"none",zIndex:d?"":"-1",boxShadow:u0(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 p.jsx("rect",{width:te(e.props.w),height:te(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:St(e.props.w,t.props.w,r),h:St(e.props.h,t.props.h,r)}}};R(ba,"type","embed"),R(ba,"props",g4),R(ba,"migrations",m4),R(ba,"embedDefinitions",j_);let d0=ba;function zye({id:n,isInteractive:e,width:t,height:r,style:s,pageRotation:i}){if(!n.match(/^[0-9a-f]+$/))throw Error("No gist id!");return p.jsx("iframe",{className:"tl-embed",draggable:!1,width:te(t),height:te(r),frameBorder:"0",scrolling:"no",referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:e?"all":"none",zIndex:e?"":"-1",boxShadow:u0(i)},srcDoc:`
463
+ <html>
464
+ <head>
465
+ <base target="_blank">
466
+ </head>
467
+ <body>
468
+ <script src=${`https://gist.github.com/${n}.js`}><\/script>
469
+ <style type="text/css">
470
+ * { margin: 0px; }
471
+ table { height: 100%; background-color: red; }
472
+ .gist { background-color: none; height: 100%; }
473
+ .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
474
+ </style>
475
+ </body>
476
+ </html>`})}function Jk(n,e){const s=((Uc(n.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(s)}const uL=new WeakMap;function dL(n,e,t){let r=uL.get(e.props);if(!r){const s=pT(e.props.name,"Frame")+"​",i=n.textMeasure.measureTextSpans(s,t),o=i[0],a=er(i);r=a.box.w+a.box.x-o.box.x,uL.set(e.props,r)}return new ye(0,-t.height,r,t.height)}function hL(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 o7(n,e,t){const r=t?"":"px",s=t?"":"deg";let i;switch(e){case 0:i="";break;case 3:i=`translate(${te(n.props.w)}${r}, 0${r}) rotate(90${s})`;break;case 2:i=`translate(${te(n.props.w)}${r}, ${te(n.props.h)}${r}) rotate(180${s})`;break;case 1:i=`translate(0${r}, ${te(n.props.h)}${r}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return i}const $ye=P.forwardRef(({id:n,name:e,isEditing:t},r)=>{const s=Q(),i=P.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Zt(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 p.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[p.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}),pT(e,"Frame")+"​"]})}),Bye=P.memo(function({id:e,name:t,width:r,height:s}){const i=Q(),{side:o,translation:a}=ie("shape rotation",()=>{const d=i.getShape(e);if(!d)return{side:0,translation:"translate(0, 0)"};const f=Jk(i,d);return{side:f,translation:o7(d,f,!1)}},[i,e]),l=P.useRef(null),c=av(e);return P.useEffect(()=>{const d=l.current;d&&c&&(d.focus(),d.select())},[l,c]),p.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:p.jsx("div",{className:"tl-frame-heading-hit-area",children:p.jsx($ye,{ref:l,id:e,name:t,isEditing:c})})})});function pT(n,e){return n.match(/^\s*$/)?e:n}class Py extends gh{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){const{editor:t}=this,r=t.getZoomLevel(),s=hL(e,"black"),i=dL(t,e,s),o=Jk(t,e);let a,l,c,d;const{w:f,h:g}=i,m=Math.min(f,e.props.w*r),y=Math.min(g,e.props.h*r);switch(o){case 0:{a=-8/r,l=(-g-4)/r,c=(m+16)/r,d=g/r;break}case 1:{a=(-g-4)/r,d=(y+16)/r,l=e.props.h-d+8/r,c=g/r;break}case 2:{a=e.props.w-(m+8)/r,l=e.props.h+4/r,c=(y+16)/r,d=g/r;break}case 3:{a=e.props.w+4/r,d=(y+16)/r,l=-8/r,c=g/r;break}}return new Ii({children:[new Uo({width:e.props.w,height:e.props.h,isFilled:!1}),new Uo({x:a,y:l,width:c,height:d,isFilled:!0,isLabel:!0})]})}getText(e){return e.props.name}component(e){const t=_i(),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 p.jsxs(p.Fragment,{children:[p.jsx(Kl,{children:p.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:p.jsx(Bye,{id:e.id,name:e.props.name,width:e.props.w,height:e.props.h})]})}toSvg(e,t){const r=Ha({isDarkMode:t.isDarkMode}),s=Jk(this.editor,e),i=o7(e,s,!0),o=hL(e,r.text),a=pT(e.props.name,"Frame")+"​",l=dL(this.editor,e,o),c=this.editor.textMeasure.measureTextSpans(a,o),d=Yk(this.editor,c,o);return p.jsxs(p.Fragment,{children:[p.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),p.jsxs("g",{transform:i,children:[p.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 p.jsx("rect",{width:te(e.props.w),height:te(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 ov(e,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:St(e.props.w,t.props.w,r),h:St(e.props.h,t.props.h,r)}}}R(Py,"type","frame"),R(Py,"props",y4),R(Py,"migrations",S4);const Uye=ot.forwardRef(function({shapeId:e,isEditing:t,richText:r,handleFocus:s,handleChange:i,handleBlur:o,handleKeyDown:a,handleDoubleClick:l},c){const d=Q(),f=Su("tip-tap-editor"),g=d.getTextOptions().tipTapConfig,m=P.useRef(r),y=P.useRef(null),v=P.useRef(null);P.useLayoutEffect(()=>{y.current?m.current!==r&&y.current.commands.setContent(r):m.current=r},[r]);const x=P.useRef({selectAll:!1,caretPosition:null});P.useLayoutEffect(()=>{function A(D){D.shapeId===d.getEditingShapeId()&&(x.current.selectAll=!0)}function O(D){D.shapeId===d.getEditingShapeId()&&(x.current.caretPosition=D.point)}return d.on("select-all-text",A),d.on("place-caret",O),()=>{d.off("select-all-text",A),d.off("place-caret",O)}},[d,t]);const b=Pa(i),C=Pa(a),E=Pa(s),_=Pa(o),M=Pa(l);return P.useLayoutEffect(()=>{if(!t||!g||!v.current)return;const{editorProps:A,...O}=g,D=new IQ({element:v.current,autofocus:!0,editable:t,onUpdate:U=>{const G=U.editor.state.doc.toJSON();m.current=G,b({richText:G})},onFocus:E,onBlur:_,onCreate:U=>{var L;if(d.getEditingShapeId()!==e)return;const G=U.editor;d.setRichTextEditor(G);const{selectAll:z,caretPosition:N}=x.current;if(z)G.chain().focus().selectAll().run();else if(N){const V=(L=G.view.posAtCoords({left:N.x,top:N.y}))==null?void 0:L.pos;V?G.chain().focus().setTextSelection(V).run():G.chain().focus().selectAll().run()}},editorProps:{handleKeyDown:(U,G)=>{G.key==="Tab"&&Hye(d,U,G),C(G)},handleDoubleClick:(U,G,z)=>M(z),...A},coreExtensionOptions:{clipboardTextSerializer:{blockSeparator:`
477
+ `}},...O,content:m.current}),B=d.timers.setTimeout(()=>{x.current.caretPosition||x.current.selectAll?D.commands.focus():D.commands.focus("end"),x.current.selectAll=!1,x.current.caretPosition=null},100);return y.current=D,()=>{y.current=null,clearTimeout(B),D.destroy()}},[t,g,E,_,M,b,C,d,e]),!t||!g?null:p.jsx("div",{id:f,ref:c,tabIndex:-1,"data-testid":"rich-text-area",className:"tl-rich-text tl-text tl-text-input",onContextMenu:t?Zt:void 0,onPointerDownCapture:Zt,onTouchEnd:Zt,onDragStart:et,children:p.jsx("div",{className:"tl-rich-text",ref:v})})});function Hye(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 g=s.doc.resolve(d).blockRange();if(!g)break;const m=g.start,y=g.end,v=s.doc.textBetween(m,y,`
478
+ `);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 Kye(n,e,t){const r=V9(n),s=r.isEditing,i=Q(),o=P.useRef(null),a=t&&To(t);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=ot.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:g=0,onKeyDown:m,classNamePrefix:y,style:v,textWidth:x,textHeight:b}){const C=Q(),E=ot.useRef(!1),{rInput:_,isEmpty:M,isEditing:A,isEditingAnything:O,...D}=Kye(e,t,r),B=P.useMemo(()=>{if(r)return aT(C,r)},[C,r]),U=ie("isSelectToolActive",()=>C.getCurrentToolId()==="select",[C]);DI("isDragging",()=>{C.getInstanceState(),E.current=C.inputs.isDragging},[C]);const G=W9(l),z=L=>{var V;if(L.target instanceof HTMLElement&&(L.target.tagName==="A"||L.target.closest("a"))){if(et(L),!U)return;const Z=((V=L.target.closest("a"))==null?void 0:V.getAttribute("href"))??"",W=$=>{$.name==="pointer_up"&&(E.current||window.open(Z,"_blank","noopener, noreferrer"),C.off("event",W))};C.on("event",W)}};if(!A&&M)return null;const N=y||"tl-text";return p.jsx("div",{className:`${N}-label tl-text-wrapper tl-rich-text-wrapper`,"data-font":i,"data-align":l,"data-hastext":!M,"data-isediting":A,"data-iseditinganything":O,"data-textwrap":!!d,"data-isselected":f,style:{justifyContent:l==="middle"||G?"center":l,alignItems:c==="middle"?"center":c,padding:g,...v},children:p.jsxs("div",{className:`${N}-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:[p.jsx("div",{className:`${N} tl-text tl-text-content`,dir:"auto",children:r&&p.jsx("div",{className:"tl-rich-text","data-is-select-tool-active":U,dangerouslySetInnerHTML:{__html:B||""},onPointerDown:z,"data-iseditinganything":O})}),(O||f)&&p.jsx(Uye,{ref:_,richText:r,isEditing:A,shapeId:e,...D,handleKeyDown:m??D.handleKeyDown})]})})});function mT({bounds:n,richText:e,fontSize:t,font:r,align:s,verticalAlign:i,wrap:o,labelColor:a,padding:l}){const c=Q(),d=aT(c,e),f=s==="middle"?"center":s==="start"?"start":"end",g=s==="middle"?"center":s==="start"?"flex-start":"flex-end",m=i==="middle"?"center":i==="start"?"flex-start":"flex-end",y={display:"flex",fontFamily:t4[r],height:"100%",justifyContent:g,alignItems:m,padding:`${l}px`},v={fontSize:`${t}px`,wrap:o?"wrap":"nowrap",color:a,lineHeight:ar.lineHeight,textAlign:f,width:"100%",wordWrap:"break-word",overflowWrap:"break-word",whiteSpace:"pre-wrap"};return p.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:p.jsx("div",{style:y,children:p.jsx("div",{dangerouslySetInnerHTML:{__html:d},style:v})})})}function fL(n,e){return n>e?(wt*(e/2)+(n-e))*2:(wt*(n/2)+(e-n))*2}function a7(n,e){return yT(n,e).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function Wye(n,e,t,r){const s=n/4,i=e/4,o=ro(r),a=t*.75,l=C=>C.addXY(o()*a,o()*a),c=new k(n/2,e),d=new k(0,i*1.2),f=new k(n/2,i*.9),g=new k(n,i*1.2),m=l(new k(n/2,e)),y=l(new k(0,i*1.2)),v=l(new k(n/2,i*.9)),x=l(new k(n,i*1.2));return[new Cr({start:c,cp1:new k(s*1.5,i*3),cp2:new k(0,i*2.5),end:d}),new Cr({start:d,cp1:new k(0,-i*.32),cp2:new k(s*1.85,-i*.32),end:f}),new Cr({start:f,cp1:new k(s*2.15,-i*.32),cp2:new k(n,-i*.32),end:g}),new Cr({start:g,cp1:new k(n,i*2.5),cp2:new k(s*2.5,i*3),end:m}),new Cr({start:m,cp1:new k(s*1.5,i*3),cp2:new k(0,i*2.5),end:y}),new Cr({start:y,cp1:new k(0,-i*.32),cp2:new k(s*1.85,-i*.32),end:v}),new Cr({start:v,cp1:new k(s*2.15,-i*.32),cp2:new k(n,-i*.32),end:x}),new Cr({start:x,cp1:new k(n,i*2.5),cp2:new k(s*2.5,i*3),end:c})].map((C,E)=>C.getSvgPathData(E===0)).join(" ")+" Z"}function yT(n,e){const t=n/4,r=e/4;return[new Cr({start:new k(n/2,e),cp1:new k(t*1.5,r*3),cp2:new k(0,r*2.5),end:new k(0,r*1.2)}),new Cr({start:new k(0,r*1.2),cp1:new k(0,-r*.32),cp2:new k(t*1.85,-r*.32),end:new k(n/2,r*.9)}),new Cr({start:new k(n/2,r*.9),cp1:new k(t*2.15,-r*.32),cp2:new k(n,-r*.32),end:new k(n,r*1.2)}),new Cr({start:new k(n,r*1.2),cp1:new k(n,r*2.5),cp2:new k(t*2.5,r*3),end:new k(n/2,e)})]}function Vye(n){return{size:1+n,thinning:.25,end:{taper:n},start:{taper:n},streamline:0,smoothing:1,simulatePressure:!1}}function qye(n,e,t,r){const s=ro(n),i=e/2,o=t/2,a=G3(i,o),l=[],c=Dt*s(),d=Dt+Kt/2+Math.abs(s())*Kt,f=Math.max(16,a/10);for(let g=0;g<f;g++){const m=g/(f-1),y=c+m*d,v=Math.cos(y),x=Math.sin(y);l.push(new k(i*v+e*.5+.05*s(),o*x+t/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?Un.easeInOutSine(m):Un.easeInExpo(m)))/2)))}return Wo(l,Vye(r))}function Gye(n,e,t,r){return lu(qye(n,e,t,r))}function Qk(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+=`${Pt(r)}L${Pt(s)}Q${Pt(i)}`;return e+=`${Pt(n[0])}`,e}function eI(n,e,t,r,s){const i=[],o=ro(n);let a=e[0],l;const c=e.length;for(let d=0,f=c*s;d<f;d++){l=k.AddXY(e[(d+1)%c],o()*t,o()*t);const g=k.Sub(l,a),m=k.Len(g),y=k.Div(g,m).mul(Math.min(m/4,r));i.push(k.Add(a,y),k.Add(l,y.neg()),l),a=l}return i}function Yye(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 k(r,0),delta:new k(1,0)},{type:"arc",center:new k(n-r,r),startAngle:-wt/2},{type:"straight",start:new k(n-r,e),delta:new k(-1,0)},{type:"arc",center:new k(r,r),startAngle:wt/2}]:[{type:"straight",start:new k(n,r),delta:new k(0,1)},{type:"arc",center:new k(r,e-r),startAngle:0},{type:"straight",start:new k(0,e-r),delta:new k(0,-1)},{type:"arc",center:new k(r,r),startAngle:wt}];let l=0;const c=[];for(let d=0;d<t;d++){const f=a[0];f.type==="straight"?c.push(k.Add(f.start,k.Mul(f.delta,l))):c.push(Yc(f.center,r,f.startAngle+l/r)),l+=o;let g=f.type==="straight"?s:wt*r;for(;l>g;)l-=g,a.push(a.shift()),g=a[0].type==="straight"?s:wt*r}return c}const Xye={s:50,m:70,l:100,xl:130},Zye=.2;function Ov(n,e,t,r,s){const i=ro(t),o=fL(n,e),a=Math.max(Math.ceil(o/Xye[r]),6,Math.ceil(o/Math.min(n,e))),l=o/a*Zye,c=Math.max(n-l*2,1),d=Math.max(e-l*2,1),g=fL(c,d)/a,m=(n-c)/2,y=(e-d)/2,v=Yye(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[_]=k.AddXY(C[_],i()*x*s,i()*b*s),C[a-_-1]=k.AddXY(C[a-_-1],i()*x*s,i()*b*s);const E=[];for(let _=0;_<C.length;_++){const M=_===C.length-1?0:_+1,A=C[_],O=C[M],D=v[_],B=v[M],U=k.Dist(D,B),G=g-U,N=k.Dist(A,O)/U,L=(Math.max(m,y)+G)*N,V=k.Lrp(D,B,.5).add(k.Sub(B,D).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 Z=jI(A,O,V),W=k.Dist(Z||k.Average([A,O]),A);E.push({leftPoint:A,rightPoint:O,arcPoint:V,center:Z,radius:W})}return E}function Jye(n,e,t,r,s){const i=[],o=Ov(n,e,t,r,s);for(const{center:a,radius:l,leftPoint:c,rightPoint:d}of o)i.push(...EG(c,d,a,l,10));return i}function tI(n,e,t,r,s){const i=Ov(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=k.Clockwise(a,l,d)?"0":"1";o+=` A${te(c)},${te(c)} 0 ${f},1 ${l.toFixed()}`}return o+=" Z",o}const Qye={s:.5,m:.7,l:.9,xl:1.6};function eSe(n,e,t,r,s){const i=ro(t),o=Qye[r]*s,a=Ov(n,e,t,r,s),d=a.reduce((y,v)=>y+k.Dist2(v.leftPoint,v.rightPoint),0)/a.length>(o*15)**2?y=>k.AddXY(y,i()*o*2,i()*o*2):y=>y;let f=`M${a[0].leftPoint.toFixed()}`,g=d(a[0].leftPoint),m=`M${g.toFixed()}`;for(const{leftPoint:y,center:v,rightPoint:x,radius:b,arcPoint:C}of a){if(v===null){f+=` L${x.toFixed()}`;const D=d(x);m+=` L${D.toFixed()}`,g=D;continue}const E=k.Clockwise(y,x,v)?"0":"1";f+=` A${te(b)},${te(b)} 0 ${E},1 ${x.toFixed()}`;const _=d(x),M=d(C),A=jI(g,_,M);if(!A){m+=` L${_.toFixed()}`,g=_;continue}const O=Math.abs(k.Dist(A,g));m+=` A${te(O)},${te(O)} 0 ${E},1 ${_.toFixed()}`,g=_}return f+m+" Z"}function nI(n,e){switch(n.geo){case"x-box":return tSe(n.w,n.h,e,n.dash);case"check-box":return nSe(n.w,n.h);default:return}}function tSe(n,e,t,r){const s=r==="draw"?.62:0;if(r==="dashed")return[[new k(0,0),new k(n/2,e/2)],[new k(n,e),new k(n/2,e/2)],[new k(0,e),new k(n/2,e/2)],[new k(n,0),new k(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 k(i(t*s),o(t*s)),new k(i(n-t*s),o(e-t*s))],[new k(i(t*s),o(e-t*s)),new k(i(n-t*s),o(t*s))]]}function nSe(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 k(i(r+t*.25),o(s+t*.52)),new k(i(r+t*.45),o(s+t*.82))],[new k(i(r+t*.45),o(s+t*.82)),new k(i(r+t*.82),o(s+t*.22))]]}function pL({shape:n,shouldScale:e,forceSolid:t}){const r=e?n.props.scale:1,s=Q(),i=_i(),{id:o,props:a}=n,{w:l,color:c,fill:d,dash:f,growY:g,size:m,scale:y}=a,v=Ir[m]*r,x=a.h+g;switch(a.geo){case"cloud":if(f==="solid"){const b=tI(l,x,o,m,y);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:b,color:c,fill:d,scale:r}),p.jsx("path",{d:b,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}else if(f==="draw"){const b=eSe(l,x,o,m,y);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:b,color:c,fill:d,scale:r}),p.jsx("path",{d:b,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}else{const b=tI(l,x,o,m,y),C=Ov(l,x,o,m,y);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:b,color:c,fill:d,scale:r}),p.jsx("g",{strokeWidth:v,stroke:i[c].solid,fill:"none",pointerEvents:"all",children:C.map(({leftPoint:E,rightPoint:_,center:M,radius:A},O)=>{const D=M?A*Uc(Uc(k.Angle(M,_))-Uc(k.Angle(M,E))):k.Dist(E,_),{strokeDasharray:B,strokeDashoffset:U}=Hi(D,v,{style:f,start:"outset",end:"outset",forceSolid:t});return p.jsx("path",{d:M?`M${E.x},${E.y}A${A},${A},0,0,1,${_.x},${_.y}`:`M${E.x},${E.y}L${_.x},${_.y}`,strokeDasharray:B,strokeDashoffset:U},O)})})]})}case"ellipse":{const b=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=b.getSvgPathData(!0);if(f==="dashed"||f==="dotted"){const E=b.length,{strokeDasharray:_,strokeDashoffset:M}=Hi(E<64?E*2:E,v,{style:f,snap:4,closed:!0,forceSolid:t});return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:C,color:c,fill:d,scale:r}),p.jsx("path",{d:C,strokeWidth:v,fill:"none",stroke:i[c].solid,strokeDasharray:_,strokeDashoffset:M})]})}else{const _=(e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n)).getSvgPathData(!0);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:_,color:c,fill:d,scale:r}),p.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 E=b.getLength(),{strokeDasharray:_,strokeDashoffset:M}=Hi(E<64?E*2:E,v,{style:f,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:t});return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:C,color:c,fill:d,scale:r}),p.jsx("path",{d:C,strokeWidth:v,fill:"none",stroke:i[c].solid,strokeDasharray:_,strokeDashoffset:M})]})}else return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:C,color:c,fill:d,scale:r}),p.jsx("path",{d:C,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}case"heart":if(f==="dashed"||f==="dotted"||f==="solid"){const b=a7(l,x),C=yT(l,x);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:b,color:c,fill:d,scale:r}),C.map((E,_)=>{const{strokeDasharray:M,strokeDashoffset:A}=Hi(E.length,v,{style:f,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:t});return p.jsx("path",{d:E.getSvgPathData(),strokeWidth:v,fill:"none",stroke:i[c].solid,strokeDasharray:M,strokeDashoffset:A,pointerEvents:"all"},`curve_${_}`)})]})}else{const b=Wye(l,x,v,n.id);return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:b,color:c,fill:d,scale:r}),p.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 Ii?b.children[0].vertices:b.vertices,E=nI(n.props,v);if(f==="solid"){let _="M"+C[0]+"L"+C.slice(1)+"Z";if(E)for(const[M,A]of E)_+=`M${M.x},${M.y}L${A.x},${A.y}`;return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:_,color:c,fill:d,scale:r}),p.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 p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:_,color:c,fill:d,scale:r}),p.jsxs("g",{strokeWidth:v,stroke:i[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(C.length)).map((M,A)=>{const O=k.ToFixed(C[A]),D=k.ToFixed(C[(A+1)%C.length]),B=k.Dist(O,D),{strokeDasharray:U,strokeDashoffset:G}=Hi(B,v,{style:f,start:"outset",end:"outset",forceSolid:t});return p.jsx("line",{x1:O.x,y1:O.y,x2:D.x,y2:D.y,strokeDasharray:U,strokeDashoffset:G},A)}),E&&E.map(([M,A],O)=>{const D=k.Dist(M,A),{strokeDasharray:B,strokeDashoffset:U}=Hi(D,v,{style:f,start:"skip",end:"skip",snap:f==="dotted"?4:void 0,forceSolid:t});return p.jsx("path",{d:`M${M.x},${M.y}L${A.x},${A.y}`,stroke:i[c].solid,strokeWidth:v,fill:"none",strokeDasharray:B,strokeDashoffset:U},`line_fg_${O}`)})]})]})}else if(f==="draw"){let _=Qk(eI(o,C,v/3,v*2,2));if(E)for(const[A,O]of E)_+=`M${A.toFixed()}L${O.toFixed()}`;const M=Qk(eI(o,C,0,v*2,1));return p.jsxs(p.Fragment,{children:[p.jsx(vr,{theme:i,d:M,color:c,fill:d,scale:r}),p.jsx("path",{d:_,stroke:i[c].solid,strokeWidth:v,fill:"none"})]})}}}}const gL=17*3;class ky extends gh{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:ki("")}}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 wn({points:Jye(t,r,e.id,e.props.size,e.props.scale),isFilled:o});break}case"triangle":{a=new wn({points:[new k(s,0),new k(t,r),new k(0,r)],isFilled:o});break}case"diamond":{a=new wn({points:[new k(s,0),new k(t,i),new k(s,r),new k(0,i)],isFilled:o});break}case"pentagon":{a=new wn({points:A1(t,r,5),isFilled:o});break}case"hexagon":{a=new wn({points:A1(t,r,6),isFilled:o});break}case"octagon":{a=new wn({points:A1(t,r,8),isFilled:o});break}case"ellipse":{a=new $ae({width:t,height:r,isFilled:o});break}case"oval":{a=new Bae({width:t,height:r,isFilled:o});break}case"star":{const C=Dt/5/2,E=Math.floor(5/4)*2,_=5*2-E,M=0,A=Math.floor(5/2)*2,O=Math.cos(-Kt+E*C)*t/2,D=Math.cos(-Kt+_*C)*t/2,B=Math.sin(-Kt+M*C)*r/2,U=Math.sin(-Kt+A*C)*r/2,G=t-Math.abs(O-D),z=r-Math.abs(U-B),N=t/2+D-(t/2-O),L=r/2+B-(r/2-U),V=1,Z=(t-N)/2,W=(r-L)/2,$=(t+G)/2,Y=(r+z)/2,re=$*V/2,K=Y*V/2;a=new wn({points:Array.from(Array(5*2)).map((ne,ge)=>{const Pe=-Kt+ge*C;return new k(Z+(ge%2?re:$)*Math.cos(Pe),W+(ge%2?K:Y)*Math.sin(Pe))}),isFilled:o});break}case"rhombus":{const b=Math.min(t*.38,r*.38);a=new wn({points:[new k(b,0),new k(t,0),new k(t-b,r),new k(0,r)],isFilled:o});break}case"rhombus-2":{const b=Math.min(t*.38,r*.38);a=new wn({points:[new k(0,0),new k(t-b,0),new k(t,r),new k(b,r)],isFilled:o});break}case"trapezoid":{const b=Math.min(t*.38,r*.38);a=new wn({points:[new k(b,0),new k(t-b,0),new k(t,r),new k(0,r)],isFilled:o});break}case"arrow-right":{const b=Math.min(t,r)*.38,C=r*.16;a=new wn({points:[new k(0,C),new k(t-b,C),new k(t-b,0),new k(t,r/2),new k(t-b,r),new k(t-b,r-C),new k(0,r-C)],isFilled:o});break}case"arrow-left":{const b=Math.min(t,r)*.38,C=r*.16;a=new wn({points:[new k(b,0),new k(b,C),new k(t,C),new k(t,r-C),new k(b,r-C),new k(b,r),new k(0,r/2)],isFilled:o});break}case"arrow-up":{const b=t*.16,C=Math.min(t,r)*.38;a=new wn({points:[new k(t/2,0),new k(t,C),new k(t-b,C),new k(t-b,r),new k(b,r),new k(b,C),new k(0,C)],isFilled:o});break}case"arrow-down":{const b=t*.16,C=Math.min(t,r)*.38;a=new wn({points:[new k(b,0),new k(t-b,0),new k(t-b,r-C),new k(t,r-C),new k(t/2,r),new k(0,r-C),new k(b,r-C)],isFilled:o});break}case"check-box":case"x-box":case"rectangle":{a=new Uo({width:t,height:r,isFilled:o});break}case"heart":{const C=yT(t,r).reduce((E,_)=>(E.push(..._.vertices),E),[]);a=new wn({points:C,isFilled:o});break}default:_n(e.props.geo)}const l=qm(this.editor,e),c=t/e.props.scale,d=r/e.props.scale,f=Math.min(100,c/2),g=Math.min(Da[e.props.size]*ar.lineHeight+Br*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(g,Math.max(1,d-8)))),v=nI(e.props,Ir[e.props.size]*e.props.scale),x=v?v.map(b=>new dh({points:b})):[];return new Ii({children:[a,new Uo({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:_n(e.props.geo)}}getText(e){return au(this.editor,e.props.richText)}getFontFaces(e){return oE(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=_i(),{editor:g}=this,m=ie("isGeoOnlySelected",()=>e.id===g.getOnlySelectedShapeId(),[g]),y=g.getEditingShapeId()!==null,v=To(e.props.richText),x=y||!v,b=ie("force solid",()=>g.getZoomLevel()<.2,[g]);return p.jsxs(p.Fragment,{children:[p.jsx(Kl,{children:p.jsx(pL,{shape:e,shouldScale:!0,forceSolid:b})}),x&&p.jsx(zl,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+s.growY},children:p.jsx(gT,{shapeId:t,type:r,font:o,fontSize:Da[c]*e.props.scale,lineHeight:ar.lineHeight,padding:Br*e.props.scale,fill:i,align:a,verticalAlign:l,richText:d,isSelected:m,labelColor:f[s.labelColor].solid,wrap:!0})}),e.props.url&&p.jsx(Qd,{url:e.props.url})]})}indicator(e){const{id:t,props:r}=e,{w:s,size:i}=r,o=r.h+r.growY,a=Ir[i],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?p.jsx("path",{d:Gye(t,s,o,a)}):p.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return p.jsx("path",{d:a7(s,o)});case"oval":return p.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return p.jsx("path",{d:tI(s,o,t,i,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),d=c instanceof Ii?c.children[0].vertices:c.vertices;let f;if(r.dash==="draw"){const m=eI(t,d,0,a*2*e.props.scale,1);f=Qk(m)}else f="M"+d[0]+"L"+d.slice(1)+"Z";const g=nI(e.props,a);if(g)for(const[m,y]of g)f+=`M${m.x},${m.y}L${y.x},${y.y}`;return p.jsx("path",{d:f})}}}toSvg(e,t){const r={...e,props:{...e.props,w:e.props.w/e.props.scale,h:e.props.h/e.props.scale}},s=r.props;t.addExportDef(cT(s.fill));let i;if(!To(s.richText)){const o=Ha(t),a=new ye(0,0,s.w,s.h+s.growY);i=p.jsx(mT,{fontSize:Da[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,richText:s.richText,labelColor:o[s.labelColor].solid,bounds:a,padding:Br*e.props.scale})}return p.jsxs(p.Fragment,{children:[p.jsx(pL,{shouldScale:!1,shape:r,forceSolid:!1}),i]})}getCanvasSvgDefs(){return[uT()]}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,g=0,m=0;const y=gL;if(!To(e.props.richText)){let _=Math.max(Math.abs(d),y),M=Math.max(Math.abs(f),y);_<y&&M===y&&(_=y),_===y&&M<y&&(M=y);const A=qm(this.editor,{...e,props:{...e.props,w:_*e.props.scale,h:M*e.props.scale}}),O=Math.max(Math.abs(d),A.w)*Math.sign(d),D=Math.max(Math.abs(f),A.h)*Math.sign(f);g=Math.abs(O)-Math.abs(d),m=Math.abs(D)-Math.abs(f),d=O,f=D}const v=d*e.props.scale,x=f*e.props.scale,b=new k(0,0);s<0&&(b.x+=v),(t==="left"||t==="top_left"||t==="bottom_left")&&(b.x+=s<0?g:-g),i<0&&(b.y+=x),(t==="top"||t==="top_left"||t==="top_right")&&(b.y+=i<0?m:-m);const{x:C,y:E}=b.rot(e.rotation).add(r);return{x:C,y:E,props:{w:Math.max(Math.abs(v),1),h:Math.max(Math.abs(x),1),growY:0}}}onBeforeCreate(e){if(To(e.props.richText))return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const t=e.props.h/e.props.scale,r=qm(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(Np(e.props.richText,t.props.richText)&&e.props.font===t.props.font&&e.props.size===t.props.size)return;const r=To(e.props.richText),s=To(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=qm(this.editor,t);if(r&&!s&&au(this.editor,t.props.richText)){let d=Math.max(i,l.w),f=Math.max(o,l.h);const g=gL;return i<g&&o<g&&(d=Math.max(d,g),f=Math.max(f,g),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:St(e.props.w,t.props.w,r),h:St(e.props.h,t.props.h,r),scale:St(e.props.scale,t.props.scale,r)}}}R(ky,"type","geo"),R(ky,"props",v4),R(ky,"migrations",x4);function qm(n,e){const{richText:t,font:r,size:s,w:i}=e.props;if(!t||To(t))return{w:0,h:0};const o=n.textMeasure.measureText("w",{...ar,fontFamily:za[r],fontSize:Da[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=a0(n,t),c=n.textMeasure.measureHtml(l,{...ar,fontFamily:za[r],fontSize:Da[s],minWidth:o.w,maxWidth:Math.max(0,Math.ceil(o.w+a[s]),Math.ceil(i/e.props.scale-Br*2))});return{w:c.w+Br*2,h:c.h+Br*2}}function rSe(){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(bn.forceSrgb)||!n?"srgb":"p3"}class Iy extends Ji{constructor(){super(...arguments);R(this,"options",{maxPointsPerShape:600,underlayOpacity:.82,overlayOpacity:.35})}hideResizeHandles(t){return Gm(t)}hideRotateHandle(t){return Gm(t)}hideSelectionBoundsFg(t){return Gm(t)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=Oc(t);if(Gm(t))return new QE({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:s,sw:i}=mL(t,r,!0),o=fT({strokeWidth:i,showAsComplete:!0});return Tv(s,o),new wn({points:q_(s,o),isFilled:!0})}component(t){const r=YC(this.editor,t),s=Oc(t);return p.jsx(Kl,{children:p.jsx(Ym,{shape:t,forceSolid:r,strokeWidth:s,opacity:this.options.overlayOpacity})})}backgroundComponent(t){const r=YC(this.editor,t),s=Oc(t);return p.jsx(Kl,{children:p.jsx(Ym,{shape:t,forceSolid:r,strokeWidth:s,opacity:this.options.underlayOpacity})})}indicator(t){const r=YC(this.editor,t),s=Oc(t),{strokePoints:i,sw:o}=mL(t,s,r),a=eh(t.props.segments);let l;return i.length<2?l=iSe(a[0],o):l=lu(i,!1),p.jsx("path",{d:l})}toSvg(t){const r=Oc(t),s=r<1.5,i=1/t.props.scale;return p.jsx("g",{transform:`scale(${i})`,children:p.jsx(Ym,{forceSolid:s,strokeWidth:r,shape:t,opacity:this.options.overlayOpacity})})}toBackgroundSvg(t){const r=Oc(t),s=r<1.5,i=1/t.props.scale;return p.jsx("g",{transform:`scale(${i})`,children:p.jsx(Ym,{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:r7(t.props.segments,r.props.segments,s),scale:St(t.props.scale,r.props.scale,s)}}}R(Iy,"type","highlight"),R(Iy,"props",C4),R(Iy,"migrations",P4);function sSe(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 iSe(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 mL(n,e,t){var l;const r=eh(n.props.segments),s=n.props.isComplete||((l=er(n.props.segments))==null?void 0:l.type)==="straight";let i=e;!t&&!n.props.isPen&&r.length===1&&(i+=ro(n.id)()*(e/6));const o=fT({strokeWidth:i,showAsComplete:s});return{strokePoints:Wo(r,o),sw:i}}function Oc(n){return Zd[n.props.size]*1.12*n.props.scale}function Gm(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function Ym({strokeWidth:n,forceSolid:e,shape:t,opacity:r}){var g;const s=_i(),i=eh(t.props.segments);let o=n;!e&&!t.props.isPen&&i.length===1&&(o+=ro(t.id)()*(o/6));const a=fT({strokeWidth:o,showAsComplete:t.props.isComplete||((g=er(t.props.segments))==null?void 0:g.type)==="straight"}),l=Wo(i,a),c=l.length>1?lu(l,!1):sSe(t.props.segments[0].points[0]),d=rSe(),f=s[t.props.color].highlight[d];return p.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:f,strokeWidth:o,opacity:r})}function YC(n,e){return ie("forceSolid",()=>{const t=Oc(e),r=n.getZoomLevel();return t/r<1.5},[n])}function l7(){return p.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[p.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),p.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),p.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}const yL=8;function oSe(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}function bp(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 aSe(n,e,t={}){const{handle:r,change:s,crop:i}=e,{w:o,h:a}=e.uncroppedSize,{minWidth:l=yL,minHeight:c=yL}=t,d=Xt(i),f=new k(n.x,n.y),g=new k(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,g.y=(d.topLeft.y-i.topLeft.y)*a):d.topLeft.y<=0?(d.topLeft.y=0,g.y=(d.topLeft.y-i.topLeft.y)*a):g.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,g.x=(d.topLeft.x-i.topLeft.x)*o):d.topLeft.x<=0?(d.topLeft.x=0,g.x=(d.topLeft.x-i.topLeft.x)*o):g.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(g.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 c7({shapeId:n,assetId:e,width:t}){const r=Q(),s=Up(),i=Vse(),[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 g=Yi("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&&(SL(r,e,y,s,C=>v(m,C)),f==null||f())};f==null||f(),r.on("tick",b),f=()=>r.off("tick",b)}else SL(r,e,y,s,x=>v(m,x))});return()=>{g(),f==null||f(),d=!0}},[r,e,s,i,n,t]),o}function SL(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 lSe(n){const t=await(await Gi(n)).blob();return Ur.blobToDataUrl(t)}const cSe=new qo;class Ey extends gh{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=ov(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:g}=e.props.crop;return r.props.crop={topLeft:{x:c?1-g.x:f.x,y:d?1-g.y:f.y},bottomRight:{x:c?1-f.x:g.x,y:d?1-f.y:g.y}},r}component(e){return p.jsx(uSe,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:p.jsx("rect",{width:te(e.props.w),height:te(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}=bp(e.props,e.props.crop),i=await cSe.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 lSe(o)||""),u7(this.editor,r.id)){const{promise:a}=h7(o);o=await a}return o});return i?p.jsx(dSe,{shape:e,src:i}):null}onDoubleClickEdge(e){const t=e.props;if(!t||this.editor.getCroppingShapeId()!==e.id)return;const r=Xt(t.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},{w:s,h:i}=bp(e.props,r),o=new k(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,g,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=((g=i.props.crop)==null?void 0:g.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:St(a.x,c.x,r),y:St(a.y,c.y,r)},bottomRight:{x:St(l.x,d.x,r),y:St(l.y,d.y,r)}}}return{...r>.5?t.props:e.props,w:St(e.props.w,t.props.w,r),h:St(e.props.h,t.props.h,r),crop:s(e,t)}}}R(Ey,"type","image"),R(Ey,"props",k4),R(Ey,"migrations",I4);const uSe=P.memo(function({shape:e}){var C;const t=Q(),{w:r}=bp(e.props,e.props.crop),{asset:s,url:i}=c7({shapeId:e.id,assetId:e.props.assetId,width:r}),o=k6(),[a,l]=P.useState(""),[c,d]=P.useState(null),f=s&&u7(t,s.id);P.useEffect(()=>{if(i&&f){const{promise:E,cancel:_}=h7(i);return E.then(M=>{l(M),d(i)}),()=>{_()}}},[t,f,o,i]);const g=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=d7(e),v=i===c?null:i,x=m?a:c;if(!i&&!(s!=null&&s.props.src))return p.jsxs(zl,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--color-text-3)",backgroundColor:"var(--color-low)",border:"1px solid var(--color-low-border)"},children:[p.jsx("div",{className:ze("tl-image-container",s&&"tl-image-container-loading"),style:y,children:s?null:p.jsx(l7,{})}),"url"in e.props&&e.props.url&&p.jsx(Qd,{url:e.props.url})]});const b=f?"anonymous":void 0;return p.jsxs(p.Fragment,{children:[g&&x&&p.jsx("div",{style:y,children:p.jsx("img",{className:"tl-image",style:{...qf(e),opacity:.1},crossOrigin:b,src:x,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),p.jsxs(zl,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[p.jsxs("div",{className:ze("tl-image-container"),style:y,children:[x&&p.jsx("img",{className:"tl-image",style:qf(e),crossOrigin:b,src:x,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},x),v&&p.jsx("img",{className:"tl-image",style:qf(e),crossOrigin:b,src:v,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>d(v)},v)]}),e.props.url&&p.jsx(Qd,{url:e.props.url})]})]})});function u7(n,e){const t=e?n.getAsset(e):void 0;return t?"mimeType"in t.props&&Us.isAnimatedImageType(t==null?void 0:t.props.mimeType)||"isAnimated"in t.props&&t.props.isAnimated:!1}function d7(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}=bp(n.props,e),i=-t.x*r,o=-t.y*s;return{transform:`translate(${i}px, ${o}px)`,width:r,height:s}}function qf(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 dSe({shape:n,src:e}){const t=Su(),r=d7(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 k(0,0),new k(l,0),new k(l,c),new k(0,c)],f=qf(n,{width:o,height:a});return p.jsxs(p.Fragment,{children:[p.jsx("defs",{children:p.jsx("clipPath",{id:t,children:p.jsx("polygon",{points:d.map(g=>`${g.x},${g.y}`).join(" ")})})}),p.jsx("g",{clipPath:`url(#${t})`,children:p.jsx("image",{href:e,width:o,height:a,style:f?{...f,transform:`${i} ${f.transform}`}:{transform:i}})})]})}else return p.jsx("image",{href:e,width:n.props.w,height:n.props.h,style:qf(n,{width:n.props.w,height:n.props.h})})}function h7(n){let e=!1;return{promise:new Promise(r=>{const s=Jf();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 f7(n){return{size:n,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function p7(n,e,t){const r=e.vertices,s=f7(t);return Wo(r,s)}function hSe(n,e,t){const r=f7(t);return q_(Tv(p7(n,e,t),r),r)}function fSe(n,e,t){const r=hSe(n,e,t);return LE(r)}function pSe(n,e,t){if(n.props.dash==="draw"){const r=p7(n,e,t);return lu(r)}return e.getSvgPathData()}function g7(n,e,t){let r=`M ${Pt(e[0])}L`,s=`M ${Pt(e[0])}L`;const i=t/3,o=t*2,a=ro(n);let l=e[0],c,d=e[0],f;const g=e.length;for(let m=0,y=g-1;m<y;m++){c=e[m+1],f=k.AddXY(e[m+1],a()*i,a()*i);const v=k.Sub(c,l),x=k.Len(v),b=k.Div(v,x).mul(Math.min(x/4,o)),C=k.Add(l,b),E=k.Add(c,b.neg()),_=k.Sub(f,d),M=k.Len(_),A=k.Div(_,M).mul(Math.min(M/4,o)),O=k.Add(d,A),D=k.Add(f,A.neg());m===y-1?(r+=`${Pt(C)}L ${Pt(c)}`,s+=`${Pt(O)}L ${Pt(f)}`):(r+=`${Pt(C)}L ${Pt(E)}Q ${Pt(c)}`,s+=`${Pt(O)}L ${Pt(D)}Q ${Pt(f)}`,l=c,d=f)}return[r,r+s]}const gSe=new qo;class _y extends Ji{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,t]=ep(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 Mf(e)}getHandles(e){return gSe.get(e.props,()=>{const t=Mf(e),r=Tf(e),s=r.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<r.length-1;i++){const o=Qf(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(tr)})}onResize(e,t){const{scaleX:r,scaleY:s}=t;return{props:{points:rh(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=eo(new k(t.x,t.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[t.id]:{id:t.id,index:t.index,x:r.x,y:r.y}}}}}component(e){return p.jsx(Kl,{style:{minWidth:50,minHeight:50},children:p.jsx(vL,{shape:e})})}indicator(e){const t=No[e.props.size]*e.props.scale,r=Mf(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]=g7(e.id,o,t);i=a}}else i=pSe(e,r,t);return p.jsx("path",{d:i})}toSvg(e){return p.jsx(vL,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const t=Tf(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(k.From)},getSelfSnapOutline:r=>{const s=this.getHandles(e).filter(o=>o.type==="vertex").findIndex(o=>o.id===r.id),i=Mf(e).segments.filter((o,a)=>a!==s-1&&a!==s);return i.length?new Ii({children:i}):null}}}getInterpolatedProps(e,t,r){const s=Tf(e),i=Tf(t),o=[],a=[];let l=o3;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=Oo(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=Oo(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:St(c.x,f.x,r),y:St(c.y,f.y,r)}]})),scale:St(e.props.scale,t.props.scale,r)}}}R(_y,"type","line"),R(_y,"props",E4),R(_y,"migrations",_4);function Tf(n){return Object.values(n.props.points).sort(tr)}function Mf(n){const e=Tf(n).map(k.From);switch(n.props.spline){case"cubic":return new zae({points:e});case"line":return new dh({points:e})}}function vL({shape:n,shouldScale:e=!1,forceSolid:t=!1}){const r=_i(),s=Mf(n),{dash:i,color:o,size:a}=n.props,l=1/n.props.scale,c=e?l:1,d=No[a]*n.props.scale;if(n.props.spline==="line"){if(i==="solid"){const f=s.points,g="M"+f[0]+"L"+f.slice(1);return p.jsx("path",{d:g,stroke:r[o].solid,strokeWidth:d,fill:"none",transform:`scale(${c})`})}if(i==="dashed"||i==="dotted")return p.jsx("g",{stroke:r[o].solid,strokeWidth:d,transform:`scale(${c})`,children:s.segments.map((f,g)=>{const{strokeDasharray:m,strokeDashoffset:y}=t?{strokeDasharray:"none",strokeDashoffset:"none"}:Hi(f.length,d,{style:i,start:g>0?"outset":"none",end:g<s.segments.length-1?"outset":"none"});return p.jsx("path",{strokeDasharray:m,strokeDashoffset:y,d:f.getSvgPathData(!0),fill:"none"},g)})});if(i==="draw"){const f=s.points,[g,m]=g7(n.id,f,d);return p.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 p.jsx("path",{strokeWidth:d,stroke:r[o].solid,fill:"none",d:f,transform:`scale(${c})`});if(i==="dashed"||i==="dotted")return p.jsx("g",{stroke:r[o].solid,strokeWidth:d,transform:`scale(${c})`,children:s.segments.map((g,m)=>{const{strokeDasharray:y,strokeDashoffset:v}=Hi(g.length,d,{style:i,start:m>0?"outset":"none",end:m<s.segments.length-1?"outset":"none",forceSolid:t});return p.jsx("path",{strokeDasharray:y,strokeDashoffset:v,d:g.getSvgPathData(),fill:"none"},m)})});if(i==="draw")return p.jsx("path",{d:fSe(n,s,d),strokeWidth:1,stroke:r[o].solid,fill:r[o].solid,transform:`scale(${c})`})}}class Ty extends Ji{constructor(){super(...arguments);R(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 _n(t)}}isAspectRatioLocked(){return this.options.resizeMode==="scale"}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",richText:ki(""),size:"m",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(t){const{labelHeight:r,labelWidth:s}=m7(this.editor,t),{scale:i}=t.props,o=r*i,a=s*i,l=Rt*i,c=Xm(t);return new Ii({children:[new Uo({width:l,height:c,isFilled:!0}),new Uo({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=Xm(t),a=Rt*r,l=Mme/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 Z3(t,r);default:throw _n(s)}}getText(t){return au(this.editor,t.props.richText)}getFontFaces(t){return oE(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:g,fontSizeAdjustment:m}}=t,y=SSe(r),v=_i(),x=Rt*o,b=Xm(t),C=ie("shape rotation",()=>{var A;return((A=this.editor.getShapePageTransform(r))==null?void 0:A.rotation())??0},[this.editor]),E=ie("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),_=ie("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),M=t.id===this.editor.getOnlySelectedShapeId();return p.jsxs(p.Fragment,{children:[p.jsx("div",{id:r,className:"tl-note__container",style:{width:x,height:b,backgroundColor:v[a].note.fill,borderBottom:E?_?`${2*o}px solid rgb(20, 20, 20)`:`${2*o}px solid rgb(144, 144, 144)`:"none",boxShadow:E?"none":vSe(t.id,C,o)},children:p.jsx(gT,{shapeId:r,type:s,font:l,fontSize:(m||Da[c])*o,lineHeight:ar.lineHeight,align:d,verticalAlign:g,richText:f,isSelected:M,labelColor:i==="black"?v[a].note.text:v[i].fill,wrap:!0,padding:Br*o,onKeyDown:y})}),"url"in t.props&&t.props.url&&p.jsx(Qd,{url:t.props.url})]})}indicator(t){const{scale:r}=t.props;return p.jsx("rect",{rx:r,width:te(Rt*r),height:te(Xm(t))})}toSvg(t,r){const s=Ha({isDarkMode:r.isDarkMode}),i=xSe(t),o=p.jsx(mT,{fontSize:t.props.fontSizeAdjustment||Da[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:Br*t.props.scale});return p.jsxs(p.Fragment,{children:[p.jsx("rect",{x:5,y:5,rx:1,width:Rt-10,height:i.h,fill:"rgba(0,0,0,.1)"}),p.jsx("rect",{rx:1,width:Rt,height:i.h,fill:s[t.props.color].note.fill}),o]})}onBeforeCreate(t){return xL(this.editor,t)}onBeforeUpdate(t,r){if(!(Np(t.props.richText,r.props.richText)&&t.props.font===r.props.font&&t.props.size===r.props.size))return xL(this.editor,r)}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:St(t.props.scale,r.props.scale,s)}}}R(Ty,"type","note"),R(Ty,"props",T4),R(Ty,"migrations",M4);function xL(n,e){const{labelHeight:t,fontSizeAdjustment:r}=m7(n,e),s=Math.max(0,t-Rt);if(s!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:s,fontSizeAdjustment:r}}}function mSe(n,e){const{richText:t}=e.props;if(To(t))return{labelHeight:Da[e.props.size]*ar.lineHeight+Br*2,labelWidth:100,fontSizeAdjustment:0};const r=Da[e.props.size];let s=0,i=0,o=Rt,a=Rt;const l=1;do{s=Math.min(r,r-i);const c=a0(n,t),d=n.textMeasure.measureHtml(c,{...ar,fontFamily:za[e.props.font],fontSize:s,maxWidth:Rt-Br*2-l,disableOverflowWrapBreaking:!0});if(o=d.h+Br*2,a=d.w+Br*2,s<=14){const f=a0(n,t),g=n.textMeasure.measureHtml(f,{...ar,fontFamily:za[e.props.font],fontSize:s,maxWidth:Rt-Br*2-l});o=g.h+Br*2,a=g.w+Br*2;break}if(d.scrollWidth.toFixed(0)===d.w.toFixed(0))break}while(i++<50);return{labelHeight:o,labelWidth:a,fontSizeAdjustment:s}}const ySe=new qo;function m7(n,e){return ySe.get(e,()=>mSe(n,e))}function SSe(n){const e=Q(),t=_U();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"||R9(au(e,s.props.richText))),d=(Rt+e.options.adjacentShapeMargin+(o&&!r.shiftKey?s.props.growY:0))*s.props.scale,f=new k(i?r.shiftKey!=c?-1:1:0,o?r.shiftKey?-1:1:0).mul(d).add(Av.clone().mul(s.props.scale)).rot(l).add(a.point()),g=K9(e,s,f,l);g&&(e.markHistoryStoppingPoint("editing adjacent shape"),_S(e,g,!0))}},[n,e,t.dir])}function Xm(n){return(Rt+n.props.growY)*n.props.scale}function vSe(n,e,t){const r=ro(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),
479
+ 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)}),
480
+ 0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+i)/2)).toFixed(2)})`}function xSe(n){return new ye(0,0,Rt,Rt+n.props.growY)}const wSe=vE("text size",(n,e)=>(n.fonts.trackFontsForShape(e),y7(n,e.props)),{areRecordsEqual:(n,e)=>n.props===e.props});class My extends Ji{constructor(){super(...arguments);R(this,"options",{extraArrowHorizontalPadding:10})}getDefaultProps(){return{color:"black",size:"m",w:8,font:"draw",textAlign:"start",autoSize:!0,scale:1,richText:ki("")}}getMinDimensions(t){return wSe.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 Uo({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 oE(this.editor,t.props.richText,{family:`tldraw_${t.props.font}`,weight:"normal",style:"normal"})}getText(t){return au(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),g=t.id===this.editor.getOnlySelectedShapeId(),m=_i(),y=bSe(r);return p.jsx(gT,{shapeId:r,classNamePrefix:"tl-text-shape",type:"text",font:s,fontSize:Zd[i],lineHeight:ar.lineHeight,align:c,verticalAlign:"middle",richText:o,labelColor:m[a].solid,isSelected:g,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=Q();return t.props.autoSize&&s.getEditingShapeId()===t.id?null:p.jsx("rect",{width:te(r.width),height:te(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=Ha(r),l=new ye(0,0,i,o);return p.jsx(mT,{fontSize:Zd[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,...Z3(t,r)};{const c=Math.max(1,Math.abs(i.width*a)),{x:d,y:f}=a<0?k.Sub(s,k.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){au(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=!Np(t.props.richText,r.props.richText);if(!s&&!i)return;const o=this.getMinDimensions(t),a=y7(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 g;switch(r.props.textAlign){case"middle":{g=new k((d-l)/2,i?0:(f-c)/2);break}case"end":{g=new k(d-l,i?0:(f-c)/2);break}default:{if(i)break;g=new k(0,(f-c)/2);break}}if(g){g.rot(r.rotation);const{x:m,y}=r;return{...r,x:m-g.x,y:y-g.y,props:{...r.props,w:d}}}else return{...r,props:{...r.props,w:d}}}}R(My,"type","text"),R(My,"props",A4),R(My,"migrations",O4);function y7(n,e){const{font:t,richText:r,autoSize:s,size:i,w:o}=e,a=s?16:Math.max(16,o),l=Zd[i],c=s?null:Math.floor(Math.max(a,o)),d=a0(n,r),f=n.textMeasure.measureHtml(d,{...ar,fontFamily:za[t],fontSize:l,maxWidth:c});return s&&(f.w+=1),{width:Math.max(a,f.w),height:Math.max(l,f.h)}}function bSe(n){const e=Q();return P.useCallback(t=>{if(e.getEditingShapeId()===n)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&e.complete();break}}},[e,n])}const CSe=new qo;class Ay extends gh{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return p.jsx(PSe,{shape:e})}indicator(e){return p.jsx("rect",{width:te(e.props.w),height:te(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 CSe.get(r,async()=>{const i=await t.resolveAssetUrl(r.id,e.props.w);if(!i)return null;const o=await Us.loadVideo(i);return await Us.getVideoFrameAsDataUrl(o,0)});return s?p.jsx("image",{href:s,width:e.props.w,height:e.props.h}):null}}R(Ay,"type","video"),R(Ay,"props",R4),R(Ay,"migrations",D4);const PSe=P.memo(function({shape:e}){const t=Q(),r=t.getShapeGeometry(e).bounds.w*t.getZoomLevel()>=110,s=av(e.id),i=k6(),{Spinner:o}=Jt(),{asset:a,url:l}=c7({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),c=P.useRef(null),[d,f]=P.useState(!1),[g,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]),p.jsxs(p.Fragment,{children:[p.jsx(zl,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:p.jsx("div",{className:"tl-counter-scaled",children:p.jsx("div",{className:"tl-video-container",children:a?o&&!a.props.src?p.jsx(o,{}):l?p.jsxs(p.Fragment,{children:[p.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":g}),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:p.jsx("source",{src:l})}),!d&&o&&p.jsx(o,{})]}):null:p.jsx(l7,{})})})}),"url"in e.props&&e.props.url&&p.jsx(Qd,{url:e.props.url})]})}),S7=[My,by,Cy,ky,Ty,_y,Py,wy,Iy,d0,Ey,Ay];function kSe(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 v7 extends Ne{constructor(){super(...arguments);R(this,"info",{});R(this,"scribbleId","id");R(this,"markId","");R(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 g=t.getShapeMask(f.id);if(g&&!Ws(a,g))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)}}R(v7,"id","erasing");var gP;let ISe=(gP=class extends Ne{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},R(gP,"id","idle"),gP);var mP;let ESe=(mP=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")}},R(mP,"id","pointing"),mP);class Oy extends Ne{static children(){return[ISe,ESe,v7]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}R(Oy,"id","eraser"),R(Oy,"initial","idle"),R(Oy,"isLockable",!1);class x7 extends Ne{constructor(){super(...arguments);R(this,"initialCamera",new k)}onEnter(){this.initialCamera=k.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=k.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")}}R(x7,"id","dragging");var yP;let _Se=(yP=class extends Ne{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},R(yP,"id","idle"),yP);var SP;let TSe=(SP=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")}},R(SP,"id","pointing"),SP);class Ry extends Ne{static children(){return[_Se,TSe,x7]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomIn(t,{animation:{duration:220,easing:Un.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomOut(t,{animation:{duration:320,easing:Un.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:Un.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:Un.easeOutQuint}})}}}R(Ry,"id","hand"),R(Ry,"initial","idle"),R(Ry,"isLockable",!1);var vP;let MSe=(vP=class extends Ne{onPointerDown(e){this.parent.transition("lasering",e)}},R(vP,"id","idle"),vP);class w7 extends Ne{constructor(){super(...arguments);R(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")}}R(w7,"id","lasering");class Dy extends Ne{static children(){return[MSe,w7]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}R(Dy,"id","laser"),R(Dy,"initial","idle"),R(Dy,"isLockable",!1);class b7 extends Ne{constructor(){super(...arguments);R(this,"info",{});R(this,"initialSelectedShapeIds",[]);R(this,"excludedShapeIds",new Set);R(this,"isWrapMode",!1);R(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:g}=f;let m,y,v,x,b,C;const E=t.getCurrentPageRenderingShapesSorted(),_=t.getCurrentPageId();e:for(let O=0,D=E.length;O<D;O++){if(v=E[O],r.has(v.id)||c.has(v.id)||(x=t.getShapePageBounds(v),!x))continue e;if(f.contains(x)){this.handleHit(v,o,_,c,g);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(g);const B=t.getShapeGeometry(v);t:for(let U=0;U<4;U++)if(m=C[U],y=C[(U+1)%4],B.hitTestLineSegment(m,y,0)){this.handleHit(v,o,_,c,g);break t}}}const M=t.getInstanceState().brush;(!M||!f.equals(M))&&t.updateInstanceState({brush:{...f.toJson()}});const A=t.getSelectedShapeIds();(A.length!==c.size||A.some(O=>!c.has(O)))&&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&&!HE(l,o)&&!Ws(r,l)||i.add(a.id)}}R(b7,"id","brushing");const th={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 C7 extends Ne{constructor(){super(...arguments);R(this,"info",{})}updateCursor(){const t=this.editor.getSelectedShapes(),r=th[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")}}R(C7,"id","pointing_resize_handle");class ST extends Ne{constructor(){super(...arguments);R(this,"info",{});R(this,"markId","");R(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=th[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){var g;const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t)return;const s=this.editor.getShapeUtil(t.type);if(!s)return;const 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=(((g=s.onCrop)==null?void 0:g.bind(s))??aSe)(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(),Ht(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=k.RotWith(i.getHandlePoint(this.info.handle),i.point,t),a=k.Sub(r,o);return{shape:s,cursorHandleOffset:a}}}R(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 P7(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}=bp(e.props,r),a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=Xt(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 xP;let ASe=(xP=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 k(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 k(0,0)))return;r&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const o=P7(this.editor,i,s);o&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([o]))}},R(xP,"id","idle"),xP);class k7 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)}}R(k7,"id","pointing_crop");class xT extends Ne{constructor(){super(...arguments);R(this,"info",{})}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=th[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"))}}R(xT,"id","pointing_crop_handle");class I7 extends Ne{constructor(){super(...arguments);R(this,"info",{});R(this,"markId","");R(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=P7(this.editor,t,i);o&&this.editor.updateShapes([o])}}R(I7,"id","translating_crop");class rI extends Ne{constructor(){super(...arguments);R(this,"markId","");R(this,"didExit",!1)}static children(){return[ASe,I7,k7,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))}}R(rI,"id","crop"),R(rI,"initial","idle");class E7 extends Ne{constructor(){super(...arguments);R(this,"shapeId","");R(this,"initialHandle",{});R(this,"initialAdjacentHandle",null);R(this,"initialPagePoint",{});R(this,"markId","");R(this,"initialPageTransform");R(this,"initialPageRotation");R(this,"info",{});R(this,"isPrecise",!1);R(this,"isPreciseId",null);R(this,"pointingId",null);R(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=Xt(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=Xt(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(tr),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=xs(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(),Ht(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 O;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:g,ctrlKey:m,altKey:y,pointerVelocity:v}}=t,x=this.info.shape,b=t.getShape(r);if(!b)return;const C=t.getShapeUtil(b);let E=f.clone().sub(s).rot(-o).add(i);if(g&&a&&i.id!=="middle"){const D=k.Angle(a,E),U=Wy(D,24)-D;E=k.RotWith(E,a,U)}t.snaps.clearIndicators();let _={...i,x:E.x,y:E.y};if(i.canSnap&&(c?!m:m)){if(!t.getShapePageTransform(b.id))throw Error("Expected a page transform");const B=d.handles.snapHandle({currentShapeId:r,handle:_});B&&(B.nudge.rot(-t.getShapeParentTransform(b).rotation()),E.add(B.nudge),_={...i,x:E.x,y:E.y})}const M=(O=C.onHandleDrag)==null?void 0:O.call(C,b,{handle:_,isPrecise:this.isPrecise||y,initial:x}),A={id:b.id,type:b.type,...M};if(i.type==="vertex"&&this.editor.isShapeOfType(b,"arrow")){const D=xs(t,b)[i.id];D?l[0]!==D.toId&&(t.setHintingShapes([D.toId]),this.pointingId=D.toId,this.isPrecise=v.len()<.5||y,this.isPreciseId=this.isPrecise?D.toId:null,this.resetExactTimeout()):l.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}M&&t.updateShapes([A])}}R(E7,"id","dragging_handle");function _7(n){return n.isLabel?[n]:n instanceof Ii?n.children.filter(e=>e.isLabel):[]}class T7 extends Ne{constructor(){super(...arguments);R(this,"hitShapeForPointerUp",null);R(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"),Ea(this.editor),this.editor.select(r)}onExit(){var i;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null),Ea.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":{Ea(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=_7(i),a=o.length===1?o[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&au(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=kt.isIos||kt.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}),Ea(this.editor)}onComplete(t){this.parent.transition("idle",t)}onCancel(t){this.parent.transition("idle",t)}}R(T7,"id","editing_shape");function wL(n){const e=n.getOnlySelectedShape();return!!(e&&!n.isShapeOrAncestorLocked(e)&&n.getShapeUtil(e).canCrop(e))}function h0(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(ys(c)){const d=n.getShape(c);n.isPointInShape(d,r,{margin:0,hitInside:!0})||n.setFocusedGroup(null)}}}}const OSe=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var wP;let RSe=(wP=class extends Ne{onEnter(){this.parent.setCurrentToolIdMask(void 0),Ea(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){Ea.cancel()}onPointerMove(){Ea(this.editor)}onPointerDown(e){const t=e.ctrlKey&&wL(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))&&bL(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")){h0(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){h0(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]),Ht(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))&&bL(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(bn.editOnType.get()&&!OSe.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}wL(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"),_S(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&&Ws(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=jt(),{x:r,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:t,type:"text",x:r,y:s,props:{richText:ki(""),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 k(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 k(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),o=this.editor.getInstanceState().isGridMode?r?i*NSe:i:r?DSe:jSe,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,s.mul(o)),Ht(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},R(wP,"id","idle"),wP);const DSe=10,jSe=1,NSe=5;function bL(n,e){const t=n.getSelectionRotatedPageBounds();if(!t)return!1;const r=n.getSelectionRotation();return r?Ws(e,t.corners.map(s=>k.RotWith(s,t.point,r))):t.containsPoint(e)}class M7 extends Ne{constructor(){super(...arguments);R(this,"shapeId","");R(this,"markId","");R(this,"wasAlreadySelected",!1);R(this,"didDrag",!1);R(this,"didCtrlOnEnter",!1);R(this,"info",{});R(this,"_labelDragOffset",new k(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=k.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=jo(this.editor,r),i=this.editor.getShapeGeometry(r),o=i.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=o.nearestPoint(k.Add(a,this._labelDragOffset));let c;if(s.isStraight){const d=k.Dist(s.start.point,s.end.point);c=1-k.Dist(s.end.point,l)/d}else{const{_center:d,measure:f,angleEnd:g,angleStart:m}=i.children[0];c=TP(f,m,g,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")}}R(M7,"id","pointing_arrow_label");class A7 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){h0(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}R(A7,"id","pointing_canvas");class O7 extends Ne{constructor(){super(...arguments);R(this,"didCtrlOnEnter",!1);R(this,"info",{})}onEnter(t){this.info=t,this.didCtrlOnEnter=t.accelKey;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const s=xs(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=CL(s,t,r,!1);if(i){_S(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=CL(t,r,s,!0);if(i){const o=t.getPointInParentSpace(i,t.inputs.originPagePoint).sub(k.Rot(Av.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:()=>{_S(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")}}R(O7,"id","pointing_handle");function CL(n,e,t,r){const s=n.getShapePageTransform(e.id),i=s.point(),o=s.rotation(),l=U9(n,i,o,e.props.growY*e.props.scale,0,e.props.scale)[t.index];if(l)return K9(n,e,l,o,r)}class R7 extends Ne{constructor(){super(...arguments);R(this,"info",{})}updateCursor(){this.editor.setCursor({type:th[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")}}R(R7,"id","pointing_rotate_handle");class D7 extends Ne{constructor(){super(...arguments);R(this,"info",{})}onEnter(t){this.info=t}onPointerUp(t){h0(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")}}R(D7,"id","pointing_selection");class j7 extends Ne{constructor(){super(...arguments);R(this,"hitShape",{});R(this,"hitShapeForPointerUp",{});R(this,"isDoubleClick",!1);R(this,"didCtrlOnEnter",!1);R(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,g=>r.includes(g.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 g=(d=f.onClick)==null?void 0:d.call(f,c);if(g){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([g]),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,g=>!r.includes(g.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 g=this.editor.getShapeUtil(c).getGeometry(c),m=_7(g),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 g=this.editor.getShapeAncestors(f);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(m=>!g.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")}}R(j7,"id","pointing_shape");class N7 extends Ne{constructor(){super(...arguments);R(this,"info",{});R(this,"markId","");R(this,"didHoldCommand",!1);R(this,"creationCursorOffset",{x:0,y:0});R(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(Ht(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 D=[...i.values()][0];this.editor.isShapeOfType(D.shape,"text")&&(f=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:g}=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&&!g){const{gridSize:D}=this.editor.getDocumentSettings();m.snapToGrid(D)}const v=this.info.handle,x=PL(v,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!g:g)&&c%Kt===0){const{nudge:D}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:k.Sub(m,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:PL(v,c),isAspectRatioLocked:f,isResizingFromCenter:t});m.add(D)}const C=k.RotWith(t?o.center:o.getHandlePoint(x),o.point,c),E=k.Sub(m,C).rot(-c),_=k.Sub(y,C).rot(-c),M=k.DivV(E,_);Number.isFinite(M.x)||(M.x=1),Number.isFinite(M.y)||(M.y=1);const A=v==="top"||v==="bottom",O=v==="left"||v==="right";f?O?M.y=Math.abs(M.x):A?M.x=Math.abs(M.y):Math.abs(M.x)>Math.abs(M.y)?M.y=Math.abs(M.x)*(M.y<0?-1:1):M.x=Math.abs(M.y)*(M.x<0?-1:1):(A&&(M.x=1),O&&(M.y=1)),this.info.isCreating||this.updateCursor({dragHandle:v,isFlippedX:M.x<0,isFlippedY:M.y<0,rotation:c});for(const D of i.keys()){const B=i.get(D);this.editor.resizeShape(D,M,{initialShape:B.shape,initialBounds:B.bounds,initialPageTransform:B.pageTransform,dragHandle:v,mode:l.length===1&&D===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:D,children:B}of s){if(!B.length)continue;const U=i.get(D).shape,G=this.editor.getShape(D);if(!(U&&G))continue;const z=G.x-U.x,N=G.y-U.y,L=new k(z,N).rot(-U.rotation);if(L.x!==0||L.y!==0)for(const V of B)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:D}of s)if(D.length)for(const B of D)this.editor.updateShape({id:B.id,type:B.type,x:B.x,y:B.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=k.RotWith(i.getHandlePoint(this.info.handle),i.point,r),a=k.Sub(s,o),l=new Map,c=[];t.forEach(f=>{const g=this.editor.getShape(f);if(g){if(g.type==="frame"&&c.push({id:f,children:rt(this.editor.getSortedChildIdsForParent(g).map(m=>this.editor.getShape(m)))}),l.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")&&t.length===1)return;this.editor.visitDescendants(g.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=>!X3(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)}}}R(N7,"id","resizing");const XC=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function PL(n,e){e=e%Dt;const t=Math.round(e/(wt/4)),r=XC.indexOf(n);return XC[(r+t)%XC.length]}const kL=Math.PI/180;class L7 extends Ne{constructor(){super(...arguments);R(this,"snapshot",{});R(this,"info",{});R(this,"markId","")}onEnter(t){this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=Vz({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});cy({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:th[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});cy({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:th[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(){cy({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ht(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=Wy(f,24);else if(t&&(f=Math.round(f/kL)*kL,this.editor.getInstanceState().isCoarsePointer)){const g=Wy(f,4),m=ey(f,g);Math.abs(m)<PG(5)&&(f=g)}return f-l}}R(L7,"id","rotating");class F7 extends Ne{constructor(){super(...arguments);R(this,"hits",new Set);R(this,"size",0);R(this,"scribbleId","id");R(this,"initialSelectedShapeIds",new Set);R(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 g,m,y,v;const x=0;for(let E=0,_=f.length;E<_;E++){if(g=f[E],r.isShapeOfType(g,"group")||c.has(g.id)||r.isShapeOrAncestorLocked(g)||(m=r.getShapeGeometry(g),r.isShapeOfType(g,"frame")&&m.bounds.containsPoint(r.getPointInShapeSpace(g,o))))continue;const M=r.getShapePageTransform(g);if(!m||!M)continue;const A=M.clone().invert();y=A.applyToPoint(a),v=A.applyToPoint(l);const{bounds:O}=m;if(!(O.minX-x>Math.max(y.x,v.x)||O.minY-x>Math.max(y.y,v.y)||O.maxX+x<Math.min(y.x,v.x)||O.maxY+x<Math.min(y.y,v.y))&&m.hitTestLineSegment(y,v,x)){const D=this.editor.getOutermostSelectableShape(g),B=this.editor.getShapeMask(D.id);if(B&&BE(a,l,B)!==null&&!Ws(l,B))continue;c.add(D.id)}}const b=r.getSelectedShapeIds(),C=new Set(i?[...c,...d]:[...c]);(b.length!==C.size||b.some(E=>!C.has(E)))&&this.editor.setSelectedShapes(Array.from(C))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}R(F7,"id","scribble_brushing");var LSe=Object.create,z7=Object.defineProperty,FSe=Object.getOwnPropertyDescriptor,zSe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),$7=n=>{throw TypeError(n)},B7=(n,e,t)=>e in n?z7(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,$Se=n=>[,,,LSe(null)],U7=["class","method","getter","setter","accessor","field","value","get","set"],H7=n=>n!==void 0&&typeof n!="function"?$7("Function expected"):n,BSe=(n,e,t,r,s)=>({kind:U7[n],name:e,metadata:r,addInitializer:i=>t._?$7("Already initialized"):s.push(H7(i||null))}),USe=(n,e)=>B7(e,zSe("metadata"),n[3]),HSe=(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},KSe=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=U7[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,FSe(s,t)),b=r.length-1;b>=0;b--)l=BSe(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,H7(o)&&(x[y]=o);return x&&z7(s,t,x),s},ZC=(n,e,t)=>B7(n,typeof e!="symbol"?e+"":e,t),K7,Rv;const WSe=20,VSe=100;K7=[bs];class wT{constructor(e){this.editor=e,HSe(Rv,5,this),ZC(this,"prevDroppingShapeId",null),ZC(this,"droppingNodeTimer",null),ZC(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,WSe,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,VSe,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,g;t=rt(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&&((g=(f=this.editor.getShapeUtil(a)).onDragShapesOver)==null||g.call(f,a,t)),this.hintParents(t),r==null||r(),this.prevDroppingShapeId=s}hintParents(e){const t=new Map;for(const s of e){const 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&&kU(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()}}Rv=$Se();KSe(Rv,1,"dispose",K7,wT);USe(Rv,wT);var qSe=Object.create,W7=Object.defineProperty,GSe=Object.getOwnPropertyDescriptor,V7=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),q7=n=>{throw TypeError(n)},G7=(n,e,t)=>e in n?W7(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,YSe=n=>[,,,qSe((n==null?void 0:n[V7("metadata")])??null)],Y7=["class","method","getter","setter","accessor","field","value","get","set"],X7=n=>n!==void 0&&typeof n!="function"?q7("Function expected"):n,XSe=(n,e,t,r,s)=>({kind:Y7[n],name:e,metadata:r,addInitializer:i=>t._?q7("Already initialized"):s.push(X7(i||null))}),ZSe=(n,e)=>G7(e,V7("metadata"),n[3]),JSe=(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},QSe=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=Y7[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,GSe(s,t)),b=r.length-1;b>=0;b--)l=XSe(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,X7(o)&&(x[y]=o);return x&&W7(s,t,x),s},bl=(n,e,t)=>G7(n,typeof e!="symbol"?e+"":e,t),Z7,sI,Dv;class jv extends(sI=Ne,Z7=[bs],sI){constructor(){super(...arguments),JSe(Dv,5,this),bl(this,"info",{}),bl(this,"selectionSnapshot",{}),bl(this,"snapshot",{}),bl(this,"markId",""),bl(this,"isCloning",!1),bl(this,"isCreating",!1),bl(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=IL(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=IL(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),Ht(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=k.Average(e.map(i=>this.editor.getShapePageTransform(i.id).point())),s=k.Sub(r,this.selectionSnapshot.averagePagePoint);k.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),e0e({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=ps(s.parentId)?null:ve.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=i})}}Dv=YSe(sI);QSe(Dv,1,"updateParentTransforms",Z7,jv);ZSe(Dv,jv);bl(jv,"id","translating");function IL(n){var f;const e=[],t=[],r=n.getSelectedShapeIds(),s=rt(r.map(g=>{const m=n.getShape(g);if(!m)return null;e.push(m);const y=n.getShapePageTransform(g),v=y.point(),x=y.rotation();t.push(v);const b=Es.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 g=n.getSelectionPageBounds();g&&(o=g.cornersAndCenter.map((m,y)=>({id:"selection:"+y,x:m.x,y:m.y})))}let a,l;const{originPagePoint:c}=n.inputs,d=s.filter(g=>n.isShapeOfType(g.shape,"note")&&n.isPointInShape(g.shape,c));if(d.length!==0)if(d.length===1)l=d[0];else{const g=n.getCurrentPageShapesSorted();l=(f=d.map(m=>({snapshot:m,index:g.findIndex(y=>y.id===m.shape.id)})).sort((m,y)=>y.index-m.index)[0])==null?void 0:f.snapshot}return l&&(a=H9(n,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:k.Average(t),movingShapes:e,shapeSnapshots:s,initialPageBounds:n.getSelectionPageBounds(),initialSnapPoints:o,noteAdjacentPositions:a,noteSnapshot:l}}function e0e({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=k.Sub(t.currentPagePoint,t.originPagePoint),g=n.inputs.shiftKey?Math.abs(f.x)<Math.abs(f.y)?"x":"y":null;g==="x"?f.x=0:g==="y"&&(f.y=0),n.snaps.clearIndicators();const 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:g,initialSelectionSnapPoints:o});f.add(C)}else if(r&&s){const{scale:C}=r.shape.props,E=r.pagePoint.clone().add(f).add(Av.clone().mul(C).rot(r.pageRotation));let _=B9/n.getZoomLevel(),M=new k(0,0);for(const A of s){const O=k.Sub(E,A),D=O.len();D<_&&(y=!0,_=D,M=O)}f.sub(M)}const v=k.Add(l,f),x=n.snaps.getIndicators();c&&!t.ctrlKey&&!y&&x.length===0&&v.snapToGrid(d);const b=k.Sub(v,l);n.updateShapes(rt(a.map(({shape:C,pagePoint:E,parentTransform:_})=>{const M=k.Add(E,b),A=_?ve.applyToPoint(_,M):M;return{id:C.id,type:C.type,x:A.x,y:A.y}})))}class jy extends Ne{constructor(){super(...arguments);R(this,"reactor")}static children(){return[rI,ST,RSe,A7,j7,jv,b7,F7,xT,D7,C7,T7,N7,L7,R7,M7,O7,E7]}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=Yi("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)}}R(jy,"id","select"),R(jy,"initial","idle"),R(jy,"isLockable",!1);class J7 extends Ne{constructor(){super(...arguments);R(this,"info",{})}onEnter(t){this.info=t}onPointerDown(){this.parent.transition("pointing",this.info)}}R(J7,"id","idle");class Q7 extends Ne{constructor(){super(...arguments);R(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)}}R(Q7,"id","pointing");class eH extends Ne{constructor(){super(...arguments);R(this,"info",{});R(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)}}R(eH,"id","zoom_brushing");class Ny extends Ne{constructor(){super(...arguments);R(this,"info",{})}static children(){return[J7,eH,Q7]}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})}}R(Ny,"id","zoom"),R(Ny,"initial","idle"),R(Ny,"isLockable",!1);const t0e=[Oy,Ry,Dy,Ny,jy];function n0e(){const n=Q(),e=ie("follow",()=>n.getInstanceState().followingUserId,[n]);return e?p.jsx(r0e,{userId:e}):null}function r0e({userId:n}){const e=q0(n);return e?p.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let iI={fonts:{tldraw_mono:`${En()}/fonts/IBMPlexMono-Medium.woff2`,tldraw_mono_italic:`${En()}/fonts/IBMPlexMono-MediumItalic.woff2`,tldraw_mono_bold:`${En()}/fonts/IBMPlexMono-Bold.woff2`,tldraw_mono_italic_bold:`${En()}/fonts/IBMPlexMono-BoldItalic.woff2`,tldraw_serif:`${En()}/fonts/IBMPlexSerif-Medium.woff2`,tldraw_serif_italic:`${En()}/fonts/IBMPlexSerif-MediumItalic.woff2`,tldraw_serif_bold:`${En()}/fonts/IBMPlexSerif-Bold.woff2`,tldraw_serif_italic_bold:`${En()}/fonts/IBMPlexSerif-BoldItalic.woff2`,tldraw_sans:`${En()}/fonts/IBMPlexSans-Medium.woff2`,tldraw_sans_italic:`${En()}/fonts/IBMPlexSans-MediumItalic.woff2`,tldraw_sans_bold:`${En()}/fonts/IBMPlexSans-Bold.woff2`,tldraw_sans_italic_bold:`${En()}/fonts/IBMPlexSans-BoldItalic.woff2`,tldraw_draw:`${En()}/fonts/Shantell_Sans-Informal_Regular.woff2`,tldraw_draw_italic:`${En()}/fonts/Shantell_Sans-Informal_Regular_Italic.woff2`,tldraw_draw_bold:`${En()}/fonts/Shantell_Sans-Informal_Bold.woff2`,tldraw_draw_italic_bold:`${En()}/fonts/Shantell_Sans-Informal_Bold_Italic.woff2`}};function s0e(n){return P.useMemo(()=>n?{fonts:{...iI.fonts,...n==null?void 0:n.fonts}}:iI,[n])}const i0e=["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 ff={...iI,icons:Object.fromEntries(i0e.map(n=>[n,`${En()}/icons/icon/0_merged.svg#${n}`])),translations:Object.fromEntries(dp.map(n=>[n.locale,`${En()}/translations/${n.locale}.json`])),embedIcons:Object.fromEntries(j_.map(n=>[n.type,`${En()}/embed-icons/${n.type}.png`]))};function o0e(n){return n?{fonts:Object.assign({...ff.fonts},{...n==null?void 0:n.fonts}),icons:Object.assign({...ff.icons},{...n==null?void 0:n.icons}),embedIcons:Object.assign({...ff.embedIcons},{...n==null?void 0:n.embedIcons}),translations:Object.assign({...ff.translations},{...n==null?void 0:n.translations})}:ff}var bT="Popover",[tH,r1e]=Xo(bT,[pv]),ng=pv(),[a0e,ic]=tH(bT),nH=n=>{const{__scopePopover:e,children:t,open:r,defaultOpen:s,onOpenChange:i,modal:o=!1}=n,a=ng(e),l=P.useRef(null),[c,d]=P.useState(!1),[f=!1,g]=rc({prop:r,defaultProp:s,onChange:i});return p.jsx(h_,{...a,children:p.jsx(a0e,{scope:e,contentId:Ra(),triggerRef:l,open:f,onOpenChange:g,onOpenToggle:P.useCallback(()=>g(m=>!m),[g]),hasCustomAnchor:c,onCustomAnchorAdd:P.useCallback(()=>d(!0),[]),onCustomAnchorRemove:P.useCallback(()=>d(!1),[]),modal:o,children:t})})};nH.displayName=bT;var rH="PopoverAnchor",l0e=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=ic(rH,t),i=ng(t),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=s;return P.useEffect(()=>(o(),()=>a()),[o,a]),p.jsx(f_,{...i,...r,ref:e})});l0e.displayName=rH;var sH="PopoverTrigger",iH=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=ic(sH,t),i=ng(t),o=Wt(e,s.triggerRef),a=p.jsx(bt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":uH(s.open),...r,ref:o,onClick:De(n.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:p.jsx(f_,{asChild:!0,...i,children:a})});iH.displayName=sH;var CT="PopoverPortal",[c0e,u0e]=tH(CT,{forceMount:void 0}),oH=n=>{const{__scopePopover:e,forceMount:t,children:r,container:s}=n,i=ic(CT,e);return p.jsx(c0e,{scope:e,forceMount:t,children:p.jsx(oo,{present:t||i.open,children:p.jsx(Yp,{asChild:!0,container:s,children:r})})})};oH.displayName=CT;var nh="PopoverContent",aH=P.forwardRef((n,e)=>{const t=u0e(nh,n.__scopePopover),{forceMount:r=t.forceMount,...s}=n,i=ic(nh,n.__scopePopover);return p.jsx(oo,{present:r||i.open,children:i.modal?p.jsx(h0e,{...s,ref:e}):p.jsx(f0e,{...s,ref:e})})});aH.displayName=nh;var d0e=Yd("PopoverContent.RemoveScroll"),h0e=P.forwardRef((n,e)=>{const t=ic(nh,n.__scopePopover),r=P.useRef(null),s=Wt(e,r),i=P.useRef(!1);return P.useEffect(()=>{const o=r.current;if(o)return p_(o)},[]),p.jsx(yv,{as:d0e,allowPinchZoom:!0,children:p.jsx(lH,{...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})})})}),f0e=P.forwardRef((n,e)=>{const t=ic(nh,n.__scopePopover),r=P.useRef(!1),s=P.useRef(!1);return p.jsx(lH,{...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()}})}),lH=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,g=ic(nh,t),m=ng(t);return n_(),p.jsx(uv,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:i,children:p.jsx(qp,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:d,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>g.onOpenChange(!1),children:p.jsx(Q6,{"data-state":uH(g.open),role:"dialog",id:g.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)"}})})})}),cH="PopoverClose",p0e=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=ic(cH,t);return p.jsx(bt.button,{type:"button",...r,ref:e,onClick:De(n.onClick,()=>s.onOpenChange(!1))})});p0e.displayName=cH;var g0e="PopoverArrow",m0e=P.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=ng(t);return p.jsx(e8,{...s,...r,ref:e})});m0e.displayName=g0e;function uH(n){return n?"open":"closed"}var PT=nH,kT=iH,IT=oH,ET=aH;function cu({id:n,children:e,onOpenChange:t,open:r}){const[s,i]=Va(n,t);return p.jsx(PT,{onOpenChange:i,open:r||s,children:p.jsx("div",{className:"tlui-popover",children:e})})}function uu({children:n}){return p.jsx(kT,{asChild:!0,dir:"ltr",children:n})}function du({side:n,children:e,align:t="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:i=!1}){const o=Mn();return p.jsx(IT,{container:o,children:p.jsx(ET,{className:"tlui-popover__content",side:n,sideOffset:r,align:t,alignOffset:s,dir:"ltr",onEscapeKeyDown:a=>i&&a.preventDefault(),children:e})})}function y0e(n){return n.getSelectedShapeIds().map(r=>n.getShape(r)).filter(r=>{if(!r)return!1;if(n.isShapeOfType(r,"arrow")){const s=xs(n,r);if(s.start||s.end)return!1}return!0})}const dH=()=>{const n=Q();return ie("threeStackableItems",()=>y0e(n).length>2,[n])},qa=()=>{const n=Q();return ie("isInSelectState",()=>n.isIn("select"),[n])},hH=()=>{const n=Q();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=xs(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])},fH=()=>{const n=Q();return ie("allowUngroup",()=>n.getSelectedShapeIds().some(e=>{var t;return((t=n.getShape(e))==null?void 0:t.type)==="group"}),[n])},S0e=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function pH(n,e){const t=Q();return ie("selectedShapes",()=>t.getSelectedShapes().length>=n,[t,n,e])}function Zr(n,e){const t=Q();return ie("selectedShapes",()=>{const r=t.getSelectedShapes().filter(s=>!t.isShapeOrAncestorLocked(s)).length;return n===void 0?r:r>=n},[t])}function v0e(){const n=Q();return ie("showAutoSizeToggle",()=>{const e=n.getSelectedShapes();return e.length===1&&n.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[n])}function gH(){const n=Q();return ie("hasLinkShapeSelected",()=>{const e=n.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[n])}function x0e(){const n=Q();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 mH(){const n=Q();return ie("useCanRedo",()=>n.getCanRedo(),[n])}function yH(){const n=Q();return ie("useCanUndo",()=>n.getCanUndo(),[n])}function w0e(){return p.jsxs(p.Fragment,{children:[p.jsx(b0e,{}),p.jsx(C0e,{}),p.jsx(P0e,{}),p.jsx(k0e,{}),p.jsx(I0e,{}),p.jsx(T0e,{}),p.jsx(M0e,{}),p.jsx(A0e,{})]})}function b0e(){const n=Zr(2),e=qa(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"align-left",disabled:!t}),p.jsx(ue,{actionId:"align-center-horizontal",disabled:!t}),p.jsx(ue,{actionId:"align-right",disabled:!t}),p.jsx(ue,{actionId:"stretch-horizontal",disabled:!t}),p.jsx(ue,{actionId:"align-top",disabled:!t}),p.jsx(ue,{actionId:"align-center-vertical",disabled:!t}),p.jsx(ue,{actionId:"align-bottom",disabled:!t}),p.jsx(ue,{actionId:"stretch-vertical",disabled:!t})]})}function C0e(){const n=Zr(3),e=qa(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"distribute-horizontal",disabled:!t}),p.jsx(ue,{actionId:"distribute-vertical",disabled:!t})]})}function P0e(){const n=dH(),e=qa(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"stack-horizontal",disabled:!t}),p.jsx(ue,{actionId:"stack-vertical",disabled:!t})]})}function k0e(){const n=Zr(1),e=qa(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"send-to-back",disabled:!t}),p.jsx(ue,{actionId:"send-backward",disabled:!t}),p.jsx(ue,{actionId:"bring-forward",disabled:!t}),p.jsx(ue,{actionId:"bring-to-front",disabled:!t})]})}function I0e(){return Rr()<dn.TABLET_SM?p.jsx(E0e,{}):p.jsx(_0e,{})}function E0e(){const n=Q(),e=ie("zoom is 1",()=>n.getZoomLevel()===1,[n]);return p.jsx(ue,{actionId:"zoom-to-100",disabled:e})}function _0e(){const n=Zr(1),e=qa(),t=n&&e;return p.jsx(ue,{actionId:"rotate-ccw",disabled:!t})}function T0e(){const n=Zr(1),e=qa(),t=n&&e;return p.jsx(ue,{actionId:"rotate-cw",disabled:!t})}function M0e(){const n=gH(),e=qa(),t=n&&e;return p.jsx(ue,{actionId:"edit-link",disabled:!t})}function A0e(){const n=hH(),e=fH();return n?p.jsx(EL,{}):e?p.jsx(O0e,{}):p.jsx(EL,{})}function EL(){const n=Zr(2),e=qa(),t=n&&e;return p.jsx(ue,{actionId:"group",disabled:!t})}function O0e(){return p.jsx(ue,{actionId:"ungroup"})}const R0e=P.memo(function({children:e}){const t=gt(),r=Rr(),s=Qs(),i=P.useRef(null);Ka(i);const o=Q(),a=ie("should display quick actions when in readonly",()=>o.isInAny("hand","zoom"),[o]),l=e??p.jsx(w0e,{});if(!(s&&!a))return p.jsxs(cu,{id:"actions-menu",children:[p.jsx(uu,{children:p.jsx(He,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:p.jsx(ct,{icon:"dots-vertical",small:!0})})}),p.jsx(du,{side:r>=dn.TABLET?"bottom":"top",sideOffset:6,children:p.jsx("div",{ref:i,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:p.jsx(Vr,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function SH(){return v0e()?p.jsx(ue,{actionId:"toggle-auto-size"}):null}function vH(){return gH()?p.jsx(ue,{actionId:"edit-link"}):null}function D0e(){return Zr(1)?p.jsx(ue,{actionId:"duplicate"}):null}function xH(){const n=Q();return ie("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const r=n.getOnlySelectedShape();return!(r&&n.isShapeOfType(r,"image"))},[n])?p.jsx(ue,{actionId:"flatten-to-image"}):null}function wH(){return hH()?p.jsx(ue,{actionId:"group"}):null}function bH(){return fH()?p.jsx(ue,{actionId:"ungroup"}):null}function CH(){const n=Q();return ie("allow unframe",()=>{const t=n.getSelectedShapes();return t.length===0?!1:t.every(r=>n.isShapeOfType(r,"frame"))},[n])?p.jsx(ue,{actionId:"remove-frame"}):null}function PH(){const n=Q();return ie("allow fit frame to content",()=>{const t=n.getOnlySelectedShape();return t?n.isShapeOfType(t,"frame")&&n.getSortedChildIdsForParent(t).length>0:!1},[n])?p.jsx(ue,{actionId:"fit-frame-to-content"}):null}function kH(){const n=Q();return ie("selected shapes",()=>n.getSelectedShapes().length>0,[n])?p.jsx(ue,{actionId:"toggle-lock"}):null}function _T(){const n=Q(),e=ie("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return p.jsx(lo,{actionId:"toggle-transparent",checked:e,toggle:!0})}function j0e(){const n=Q(),e=ie("any shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(ue,{actionId:"unlock-all",disabled:!e})}function IH(){const n=Q(),e=ie("zoomed to 100",()=>n.getZoomLevel()===1,[n]);return p.jsx(ue,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function EH(){const n=Q(),e=ie("has shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(ue,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function _H(){const n=Q(),e=ie("has shapes",()=>n.getSelectedShapeIds().length>0,[n]);return p.jsx(ue,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function TH(){return p.jsxs(lt,{id:"clipboard",children:[p.jsx(L0e,{}),p.jsx(F0e,{}),p.jsx(z0e,{}),p.jsx(D0e,{}),p.jsx($0e,{})]})}function N0e(){var t;const n=Q(),e=ie("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsxs(Ms,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[p.jsxs(lt,{id:"copy-as-group",children:[p.jsx(ue,{actionId:"copy-as-svg"}),!!((t=window.navigator.clipboard)!=null&&t.write)&&p.jsx(ue,{actionId:"copy-as-png"})]}),p.jsx(lt,{id:"copy-as-bg",children:p.jsx(_T,{})})]})}function L0e(){const n=Zr(1);return p.jsx(ue,{actionId:"cut",disabled:!n})}function F0e(){const n=pH(1);return p.jsx(ue,{actionId:"copy",disabled:!n})}function z0e(){const n=S0e;return p.jsx(ue,{actionId:"paste",disabled:!n})}function MH(){const n=Q();return ie("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n])?p.jsxs(lt,{id:"conversions",children:[p.jsx(N0e,{}),p.jsxs(Ms,{id:"export-as",label:"context-menu.export-as",size:"small",children:[p.jsxs(lt,{id:"export-as-group",children:[p.jsx(ue,{actionId:"export-as-svg"}),p.jsx(ue,{actionId:"export-as-png"})]}),p.jsx(lt,{id:"export-as-bg",children:p.jsx(_T,{})})]})]}):null}function AH(){const n=Q(),e=ie("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(ue,{actionId:"select-all",disabled:!e})}function $0e(){const n=Zr(1);return p.jsx(ue,{actionId:"delete",disabled:!n})}function B0e(){const n=Qs();return!pH(1)||n?null:p.jsxs(Ms,{id:"edit",label:"context-menu.edit",size:"small",children:[p.jsx(wH,{}),p.jsx(bH,{}),p.jsx(xH,{}),p.jsx(vH,{}),p.jsx(PH,{}),p.jsx(CH,{}),p.jsx(RH,{}),p.jsx(OH,{}),p.jsx(SH,{}),p.jsx(kH,{})]})}function U0e(){const n=Zr(2),e=x0e();return Qs()||!(n||e)?null:p.jsxs(Ms,{id:"arrange",label:"context-menu.arrange",size:"small",children:[n&&p.jsxs(lt,{id:"align",children:[p.jsx(ue,{actionId:"align-left"}),p.jsx(ue,{actionId:"align-center-horizontal"}),p.jsx(ue,{actionId:"align-right"}),p.jsx(ue,{actionId:"align-top"}),p.jsx(ue,{actionId:"align-center-vertical"}),p.jsx(ue,{actionId:"align-bottom"})]}),p.jsx(H0e,{}),n&&p.jsxs(lt,{id:"stretch",children:[p.jsx(ue,{actionId:"stretch-horizontal"}),p.jsx(ue,{actionId:"stretch-vertical"})]}),(n||e)&&p.jsxs(lt,{id:"flip",children:[p.jsx(ue,{actionId:"flip-horizontal"}),p.jsx(ue,{actionId:"flip-vertical"})]}),p.jsx(K0e,{})]})}function H0e(){return Zr(3)?p.jsxs(lt,{id:"distribute",children:[p.jsx(ue,{actionId:"distribute-horizontal"}),p.jsx(ue,{actionId:"distribute-vertical"})]}):null}function K0e(){const n=Zr(2),e=dH();return n?p.jsxs(lt,{id:"order",children:[p.jsx(ue,{actionId:"pack"}),e&&p.jsx(ue,{actionId:"stack-horizontal"}),e&&p.jsx(ue,{actionId:"stack-vertical"})]}):null}function W0e(){const n=Qs(),e=Zr(1);return n||!e?null:p.jsx(Ms,{id:"reorder",label:"context-menu.reorder",size:"small",children:p.jsxs(lt,{id:"reorder",children:[p.jsx(ue,{actionId:"bring-to-front"}),p.jsx(ue,{actionId:"bring-forward"}),p.jsx(ue,{actionId:"send-backward"}),p.jsx(ue,{actionId:"send-to-back"})]})})}function V0e(){const n=Q(),e=ie("pages",()=>n.getPages(),[n]),t=ie("current page id",()=>n.getCurrentPageId(),[n]),{addToast:r}=Wa(),s=jn(),i=Qs();return!Zr(1)||i?null:p.jsxs(Ms,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[p.jsx(lt,{id:"pages",children:e.map(a=>p.jsx(sr,{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))}),p.jsx(lt,{id:"new-page",children:p.jsx(ue,{actionId:"move-to-new-page"})})]})}function OH(){const n=Q();return ie("oneEmbedSelected",()=>{const t=n.getOnlySelectedShape();return t?!!(n.isShapeOfType(t,"embed")&&t.props.url&&!n.isShapeOrAncestorLocked(t)):!1},[n])?p.jsx(ue,{actionId:"convert-to-bookmark"}):null}function RH(){const n=Q(),e=N_();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])?p.jsx(ue,{actionId:"convert-to-embed"}):null}function q0e(){const n=Q(),e=ie("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return p.jsx(lo,{actionId:"toggle-snap-mode",checked:e})}function G0e(){const n=Q(),e=ie("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return p.jsx(lo,{actionId:"toggle-tool-lock",checked:e})}function Y0e(){const n=Q(),e=ie("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return p.jsx(lo,{actionId:"toggle-grid",checked:e})}function X0e(){const n=Q(),e=ie("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return p.jsx(lo,{actionId:"toggle-wrap-mode",checked:e})}function Z0e(){const n=Q(),e=ie("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return p.jsx(lo,{actionId:"toggle-focus-mode",checked:e})}function J0e(){const n=Q(),e=ie("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return p.jsx(lo,{actionId:"toggle-edge-scrolling",checked:e===1})}function Q0e(){const n=Q(),e=ie("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return p.jsx(lo,{actionId:"toggle-reduce-motion",checked:e===0})}function eve(){const n=Q(),e=ie("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return p.jsx(lo,{actionId:"toggle-debug-mode",checked:e})}function tve(){const n=Q(),e=ie("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return p.jsx(lo,{actionId:"toggle-dynamic-size-mode",checked:e})}function nve(){const n=Q(),e=ie("paste at cursor",()=>n.user.getIsPasteAtCursorMode(),[n]);return p.jsx(lo,{actionId:"toggle-paste-at-cursor",checked:e})}function rve(){const n=Q();return ie("show cursor chat",()=>n.getCurrentToolId()==="select"&&!n.getInstanceState().isCoarsePointer,[n])?p.jsx(ue,{actionId:"open-cursor-chat"}):null}function sve(){const n=Q(),e=Pv(),t=ie("isSelectToolActive",()=>n.getCurrentToolId()==="select",[n]),r=ie("isSinglePageMode",()=>n.options.maxPages<=1,[n]);return t?p.jsxs(p.Fragment,{children:[e&&p.jsx(rve,{}),p.jsxs(lt,{id:"modify",children:[p.jsx(B0e,{}),p.jsx(U0e,{}),p.jsx(W0e,{}),!r&&p.jsx(V0e,{})]}),p.jsx(TH,{}),p.jsx(MH,{}),p.jsx(lt,{id:"select-all",children:p.jsx(AH,{})})]}):null}const ive=P.memo(function({children:e,disabled:t=!1}){const r=Q(),{Canvas:s}=Jt(),i=P.useCallback(d=>{if(d){if(r.getInstanceState().isCoarsePointer){const f=r.getSelectedShapes(),{inputs:{currentPagePoint:g}}=r,m=r.getShapesAtPoint(g);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=Mn(),[a,l]=Va("context menu",i),c=e??p.jsx(sve,{});return p.jsxs(vde,{dir:"ltr",onOpenChange:l,modal:!1,children:[p.jsx(xde,{onContextMenu:void 0,dir:"ltr",disabled:t,children:s?p.jsx(s,{}):null}),a&&p.jsx(wde,{container:o,children:p.jsx(bde,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:et,children:p.jsx(Vr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),ove=2e3,ave=5e3,lve=Gn(function(){const e=Q(),{isChatting:t,chatMessage:r}=e.getInstanceState(),s=P.useRef(-1),[i,o]=P.useState("");return P.useEffect(()=>{if(!t&&r||t){const l=t?ave:ove;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),o(""),e.focus()},l)}return()=>{clearTimeout(s.current)}},[e,r,t]),t?p.jsx(uve,{value:i,setValue:o,chatMessage:r}):r.trim()?p.jsx(cve,{chatMessage:r}):null});function DH(n){const e=Q();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 cve=({chatMessage:n})=>{const e=Q(),t=P.useRef(null);return DH(t),p.jsx("div",{ref:t,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:n})},uve=Gn(function({chatMessage:e,value:t,setValue:r}){const s=Q(),i=gt(),o=P.useRef(null),a=e||i("cursor-chat.type-to-chat");DH(o),P.useLayoutEffect(()=>{const g=o.current;if(!g)return;const m=s.textMeasure.measureText(t||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});g.style.setProperty("width",m.w+"px")},[s,t,a]),P.useLayoutEffect(()=>{const g=s.timers.requestAnimationFrame(()=>{var m;(m=o.current)==null||m.focus()});return()=>{cancelAnimationFrame(g)}},[s]);const l=P.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=P.useCallback(g=>{const{value:m}=g.target;r(m.slice(0,64)),s.updateInstanceState({chatMessage:m})},[s,r]),d=P.useCallback(g=>{const m=o.current;if(!m)return;const{value:y}=m;switch(g.key){case"Enter":{if(et(g),g.stopPropagation(),!y){l();return}r("");break}case"Escape":{et(g),g.stopPropagation(),l();break}}},[l,r]),f=P.useCallback(g=>{g.stopPropagation()},[]);return p.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 oI({checked:n}){return p.jsx(Ko,{icon:n?"check":"none",className:"tlui-button__icon",small:!0})}function dve(){const n=Q(),{addToast:e}=Wa(),{addDialog:t}=eg(),[r,s]=ot.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(lt,{id:"items",children:[p.jsx(sr,{id:"hard-reset",onSelect:oz,label:"Hard reset"}),p.jsx(sr,{id:"add-toast",onSelect:()=>{e({id:Tt(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:Tt(),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:Tt(),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:Tt(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),p.jsx(sr,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:i})=>p.jsx(pve,{displayDontShowAgain:!0,onCancel:()=>i(),onContinue:()=>i()}),onClose:()=>{}})}}),p.jsx(sr,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>gve(n,100)}),p.jsx(sr,{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})(),p.jsx(sr,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"})]}),p.jsxs(lt,{id:"flags",children:[p.jsx(hve,{}),p.jsx(fve,{})]})]})}function hve(){const n=Object.values(bn);return n.length?p.jsx(Ms,{id:"debug flags",label:"Debug Flags",children:p.jsx(lt,{id:"debug flags",children:n.map(e=>p.jsx(jH,{flag:e},e.name))})}):null}function fve(){const n=Object.values(Fte);return n.length?p.jsx(Ms,{id:"feature flags",label:"Feature Flags",children:p.jsx(lt,{id:"feature flags",children:n.map(e=>p.jsx(jH,{flag:e},e.name))})}):null}function pve({title:n="title",body:e="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:i,onContinue:o}){const[a,l]=ot.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(wv,{children:[p.jsx(bv,{children:n}),p.jsx(Cv,{})]}),p.jsx(Sp,{style:{maxWidth:350},children:e}),p.jsxs(D_,{className:"tlui-dialog__footer__actions",children:[s&&p.jsxs(He,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[p.jsx(oI,{checked:a}),p.jsx(Pn,{children:"Don’t show again"})]}),p.jsx(He,{type:"normal",onClick:i,children:p.jsx(Pn,{children:t})}),p.jsx(He,{type:"primary",onClick:async()=>o(),children:p.jsx(Pn,{children:r})})]})]})}const jH=Gn(function({flag:e,onChange:t}){const r=e.get();return p.jsx(_v,{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 _L=0;function gve(n,e){const t=n.options.adjacentShapeMargin,r=Array(e),s=Math.floor(Math.sqrt(e));for(let i=0;i<e;i++)_L++,r[i]={id:jt("box"+_L),type:"geo",x:i%s*(100+t),y:Math.floor(i/s)*(100+t)};n.run(()=>{n.createShapes(r).setSelectedShapes(r.map(i=>i.id))})}function mve({children:n}){const e=n??p.jsx(dve,{});return p.jsxs(H_,{id:"debug",children:[p.jsx(K_,{children:p.jsx(He,{type:"icon",title:"Debug menu",children:p.jsx(ct,{icon:"dots-horizontal"})})}),p.jsx(W_,{side:"top",align:"end",alignOffset:0,children:p.jsx(Vr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const yve=P.memo(function(){const{DebugMenu:e}=oc(),t=P.useRef(null);return Ka(t),p.jsxs("div",{ref:t,className:"tlui-debug-panel",children:[p.jsx(vve,{}),p.jsx(xve,{}),e&&p.jsx(e,{})]})});function Sve(n=!0){const[e,t]=P.useState(0),r=Q();P.useEffect(()=>{if(!n)return;const s=()=>t(i=>i+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const vve=Gn(function(){Sve();const e=Q(),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:""} / [${k.ToInt(e.getPointInShapeSpace(i,e.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${k.ToInt(e.inputs.originPagePoint)}] → [${k.ToInt(e.inputs.currentPagePoint)}] = ${k.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return p.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${o}${a}`})});function xve(){const n=Q(),e=ie("show_fps",()=>bn.showFps.get(),[bn]),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 g=s*.75;(f<g&&!c||f>=g&&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?p.jsx("div",{ref:t}):null}const wve=P.memo(function(){const e=Rr(),t=P.useRef(null);Ka(t);const{MainMenu:r,QuickActions:s,ActionsMenu:i,PageMenu:o}=oc(),a=Q(),l=ie("isSinglePageMode",()=>a.options.maxPages<=1,[a]),c=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=dn.TABLET;return!r&&!o&&!c?null:p.jsx("div",{ref:t,className:"tlui-menu-zone",children:p.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&p.jsx(r,{}),o&&!l&&p.jsx(o,{}),c?p.jsxs(p.Fragment,{children:[s&&p.jsx(s,{}),i&&p.jsx(i,{})]}):null]})})});function bve(){const n=Q(),e=wu(),[t,r]=P.useState(!1),s=P.useRef(!1);return _a("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?p.jsx(ue,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Cve(){const n=Q();return ie("is pen mode",()=>n.getInstanceState().isPenMode,[n])?p.jsx(ue,{actionId:"exit-pen-mode"}):null}function Pve(){const n=Q(),e=wu();return ie("is following user",()=>!!n.getInstanceState().followingUserId,[n])?p.jsx(sr,{...e["stop-following"]}):null}function kve(){return p.jsxs(p.Fragment,{children:[p.jsx(Cve,{}),p.jsx(bve,{}),p.jsx(Pve,{})]})}function Ive({children:n}){const e=n??p.jsx(kve,{});return p.jsx("div",{className:"tlui-helper-buttons",children:p.jsx(Vr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function Eve(){const n=Pv();return p.jsxs(p.Fragment,{children:[p.jsxs(lt,{label:"shortcuts-dialog.tools",id:"tools",children:[p.jsx(ue,{actionId:"toggle-tool-lock"}),p.jsx(ue,{actionId:"insert-media"}),p.jsx(gs,{toolId:"select"}),p.jsx(gs,{toolId:"draw"}),p.jsx(gs,{toolId:"eraser"}),p.jsx(gs,{toolId:"hand"}),p.jsx(gs,{toolId:"rectangle"}),p.jsx(gs,{toolId:"ellipse"}),p.jsx(gs,{toolId:"arrow"}),p.jsx(gs,{toolId:"line"}),p.jsx(gs,{toolId:"text"}),p.jsx(gs,{toolId:"frame"}),p.jsx(gs,{toolId:"note"}),p.jsx(gs,{toolId:"laser"}),p.jsx(sr,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),p.jsxs(lt,{label:"shortcuts-dialog.preferences",id:"preferences",children:[p.jsx(ue,{actionId:"toggle-dark-mode"}),p.jsx(ue,{actionId:"toggle-focus-mode"}),p.jsx(ue,{actionId:"toggle-grid"})]}),p.jsxs(lt,{label:"shortcuts-dialog.edit",id:"edit",children:[p.jsx(ue,{actionId:"undo"}),p.jsx(ue,{actionId:"redo"}),p.jsx(ue,{actionId:"cut"}),p.jsx(ue,{actionId:"copy"}),p.jsx(ue,{actionId:"paste"}),p.jsx(ue,{actionId:"select-all"}),p.jsx(ue,{actionId:"delete"}),p.jsx(ue,{actionId:"duplicate"})]}),p.jsxs(lt,{label:"shortcuts-dialog.view",id:"view",children:[p.jsx(ue,{actionId:"zoom-in"}),p.jsx(ue,{actionId:"zoom-out"}),p.jsx(ue,{actionId:"zoom-to-100"}),p.jsx(ue,{actionId:"zoom-to-fit"}),p.jsx(ue,{actionId:"zoom-to-selection"})]}),p.jsxs(lt,{label:"shortcuts-dialog.transform",id:"transform",children:[p.jsx(ue,{actionId:"bring-to-front"}),p.jsx(ue,{actionId:"bring-forward"}),p.jsx(ue,{actionId:"send-backward"}),p.jsx(ue,{actionId:"send-to-back"}),p.jsx(ue,{actionId:"group"}),p.jsx(ue,{actionId:"ungroup"}),p.jsx(ue,{actionId:"flip-horizontal"}),p.jsx(ue,{actionId:"flip-vertical"}),p.jsx(ue,{actionId:"align-top"}),p.jsx(ue,{actionId:"align-center-vertical"}),p.jsx(ue,{actionId:"align-bottom"}),p.jsx(ue,{actionId:"align-left"}),p.jsx(ue,{actionId:"align-center-horizontal"}),p.jsx(ue,{actionId:"align-right"})]}),n&&p.jsx(lt,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:p.jsx(ue,{actionId:"open-cursor-chat"})})]})}const _ve=P.memo(function({children:e}){const t=gt(),r=Rr(),s=e??p.jsx(Eve,{});return p.jsxs(p.Fragment,{children:[p.jsxs(wv,{className:"tlui-shortcuts-dialog__header",children:[p.jsx(bv,{children:t("shortcuts-dialog.title")}),p.jsx(Cv,{})]}),p.jsx(Sp,{className:ze("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=dn.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=dn.TABLET}),children:p.jsx(Vr,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),p.jsx("div",{className:"tlui-dialog__scrim"})]})});function NH(){const n=Mr(),e=jn(),t=ie("locale",()=>n==null?void 0:n.user.getLocale(),[n]);return n?p.jsx(Ms,{id:"help menu language",label:"menu.language",children:p.jsx(lt,{id:"languages",children:dp.map(({locale:r,label:s})=>p.jsx(_v,{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 Tve(){return p.jsxs(p.Fragment,{children:[p.jsx(NH,{}),p.jsx(LH,{})]})}function LH(){const{KeyboardShortcutsDialog:n}=oc(),{addDialog:e}=eg(),t=P.useCallback(()=>{n&&e({component:n})},[e,n]);return n?p.jsx(sr,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:t}):null}function Mve(){return p.jsxs(p.Fragment,{children:[p.jsxs(lt,{id:"basic",children:[p.jsx(Ove,{}),p.jsx(Nve,{}),p.jsx(Ave,{}),p.jsx(Lve,{})]}),p.jsx(Fve,{})]})}function Ave(){return p.jsxs(Ms,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[p.jsxs(lt,{id:"export-all-as-group",children:[p.jsx(ue,{actionId:"export-all-as-svg"}),p.jsx(ue,{actionId:"export-all-as-png"})]}),p.jsx(lt,{id:"export-all-as-bg",children:p.jsx(_T,{})})]})}function Ove(){return p.jsxs(Ms,{id:"edit",label:"menu.edit",children:[p.jsx(jve,{}),p.jsx(TH,{}),p.jsx(MH,{}),p.jsx(Rve,{}),p.jsx(Dve,{}),p.jsx(lt,{id:"select-all",children:p.jsx(AH,{})})]})}function Rve(){return p.jsxs(lt,{id:"misc",children:[p.jsx(wH,{}),p.jsx(bH,{}),p.jsx(vH,{}),p.jsx(SH,{}),p.jsx(CH,{}),p.jsx(PH,{}),p.jsx(RH,{}),p.jsx(OH,{}),p.jsx(xH,{})]})}function Dve(){return p.jsxs(lt,{id:"lock",children:[p.jsx(kH,{}),p.jsx(j0e,{})]})}function jve(){const n=yH(),e=mH();return p.jsxs(lt,{id:"undo-redo",children:[p.jsx(ue,{actionId:"undo",disabled:!n}),p.jsx(ue,{actionId:"redo",disabled:!e})]})}function Nve(){return p.jsx(Ms,{id:"view",label:"menu.view",children:p.jsxs(lt,{id:"view-actions",children:[p.jsx(ue,{actionId:"zoom-in"}),p.jsx(ue,{actionId:"zoom-out"}),p.jsx(IH,{}),p.jsx(EH,{}),p.jsx(_H,{})]})})}function Lve(){return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"insert-embed"}),p.jsx(ue,{actionId:"insert-media"})]})}function Fve(){return p.jsxs(lt,{id:"preferences",children:[p.jsxs(Ms,{id:"preferences",label:"menu.preferences",children:[p.jsxs(lt,{id:"preferences-actions",children:[p.jsx(q0e,{}),p.jsx(G0e,{}),p.jsx(Y0e,{}),p.jsx(X0e,{}),p.jsx(Z0e,{}),p.jsx(J0e,{}),p.jsx(Q0e,{}),p.jsx(tve,{}),p.jsx(nve,{}),p.jsx(eve,{})]}),p.jsx(lt,{id:"color-scheme",children:p.jsx(Bfe,{})})]}),p.jsx(NH,{}),p.jsx(LH,{})]})}const zve=P.memo(function({children:e}){const t=Mn(),[r,s]=Va("main menu"),i=gt(),o=e??p.jsx(Mve,{});return p.jsxs(I_,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[p.jsx(E_,{asChild:!0,dir:"ltr",children:p.jsx(He,{type:"icon","data-testid":"main-menu.button",title:i("menu.title"),children:p.jsx(ct,{icon:"menu",small:!0})})}),p.jsx(xv,{container:t,children:p.jsx(__,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:p.jsx(Vr,{type:"menu",sourceId:"main-menu",children:o})})})]})}),JC={};function pf(n){if(JC[n])return JC[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 JC[n]=a,a}const Ly=10,FH=4*6*Ly+12+4*12;function vd(n,{center:e,radius:t,numArcSegments:r=20,startAngle:s=0,endAngle:i=Dt,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 xd(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 $ve(n,e,t){const r=Ly;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 vd(n,{center:e.center,radius:t,numArcSegments:Ly*4}),Ly*4*6;let i=0;return xd(n,i,s.minX,s.minY,s.w,s.h),i+=12,xd(n,i,s.minX,e.minY,s.w,t),i+=12,xd(n,i,s.maxX,s.minY,t,s.h),i+=12,xd(n,i,s.minX,s.maxY,s.w,t),i+=12,xd(n,i,e.minX,s.minY,t,s.h),i+=12,vd(n,{numArcSegments:r,offset:i,center:s.point,radius:t,startAngle:wt,endAngle:wt*1.5}),i+=r*6,vd(n,{numArcSegments:r,offset:i,center:k.Add(s.point,new k(s.w,0)),radius:t,startAngle:wt*1.5,endAngle:Dt}),i+=r*6,vd(n,{numArcSegments:r,offset:i,center:k.Add(s.point,s.size),radius:t,startAngle:0,endAngle:Kt}),i+=r*6,vd(n,{numArcSegments:r,offset:i,center:k.Add(s.point,new k(0,s.h)),radius:t,startAngle:Kt,endAngle:wt}),FH}function Bve(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
481
+ precision mediump float;
482
+
483
+ in vec2 shapeVertexPosition;
484
+
485
+ uniform vec4 canvasPageBounds;
486
+
487
+ // taken (with thanks) from
488
+ // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
489
+ void main() {
490
+ // convert the position from pixels to 0.0 to 1.0
491
+ vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
492
+
493
+ // convert from 0->1 to 0->2
494
+ vec2 zeroToTwo = zeroToOne * 2.0;
495
+
496
+ // convert from 0->2 to -1->+1 (clipspace)
497
+ vec2 clipSpace = zeroToTwo - 1.0;
498
+
499
+ gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
500
+ }`,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
501
+ precision mediump float;
502
+
503
+ uniform vec4 fillColor;
504
+ out vec4 outputColor;
505
+
506
+ void main() {
507
+ outputColor = fillColor;
508
+ }`,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:Zm(e,1024),unselectedShapes:Zm(e,4096),viewport:Zm(e,FH),collaborators:Zm(e,1024),prepareTriangles(g,m){e.bindBuffer(e.ARRAY_BUFFER,g.buffer),e.bufferData(e.ARRAY_BUFFER,g.vertices,e.STATIC_DRAW,0,m),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(g){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,g/2),e.disable(e.BLEND)},drawTriangles(g){e.drawArrays(e.TRIANGLES,0,g/2)},setFillColor(g){e.uniform4fv(c,g)},setCanvasPageBounds(g){e.uniform4fv(l,g)}}}function Zm(n,e){const t=n.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(e)}}function TL(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 Uve=Object.create,zH=Object.defineProperty,Hve=Object.getOwnPropertyDescriptor,Kve=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),$H=n=>{throw TypeError(n)},BH=(n,e,t)=>e in n?zH(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Wve=n=>[,,,Uve(null)],UH=["class","method","getter","setter","accessor","field","value","get","set"],HH=n=>n!==void 0&&typeof n!="function"?$H("Function expected"):n,Vve=(n,e,t,r,s)=>({kind:UH[n],name:e,metadata:r,addInitializer:i=>t._?$H("Already initialized"):s.push(HH(i||null))}),qve=(n,e)=>BH(e,Kve("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},Jo=(n,e,t,r,s,i)=>{for(var o,a,l,c,d=e&7,f=!1,g=!1,m=2,y=UH[d+5],v=n[m]||(n[m]=[]),x=(s=s.prototype,Hve(s,t)),b=r.length-1;b>=0;b--)l=Vve(d,t,a={},n[3],v),l.static=f,l.private=g,c=l.access={has:C=>t in C},c.get=C=>C[t],o=(0,r[b])(x[y],l),a._=1,HH(o)&&(x[y]=o);return x&&zH(s,t,x),s},ma=(n,e,t)=>BH(n,typeof e!="symbol"?e+"":e,t),KH,WH,VH,qH,GH,YH,XH,ZH,JH,QH,ei;QH=[bs],JH=[le],ZH=[le],XH=[le],YH=[le],GH=[le],qH=[le],VH=[le],WH=[le],KH=[bs];class Ti{constructor(e,t,r){this.editor=e,this.elem=t,this.container=r,Gve(ei,5,this),ma(this,"disposables",[]),ma(this,"gl"),ma(this,"shapeGeometryCache"),ma(this,"colors"),ma(this,"id",Tt()),ma(this,"canvasBoundingClientRect",ln("canvasBoundingClientRect",new ye)),ma(this,"originPagePoint",new k),ma(this,"originPageCenter",new k),ma(this,"isInViewport",!1),this.gl=Bve(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 xd(o,0,i.x,i.y,i.w,i.h),o}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),Yi("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:pf(e.getPropertyValue("--color-text-3").trim()),selectFill:pf(e.getPropertyValue("--color-selected").trim()),viewportFill:pf(e.getPropertyValue("--color-muted-1").trim()),background:pf(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 k(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 k(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 k(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,g=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,g+o.height-l),b=Math.max(0,-(m-o.height-l));a+=(y-v)/2,l+=(x-b)/2,a=Rn(a,d,f),l=Rn(l,g,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 k(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 g=f.length;r.has(d)?(TL(this.gl.selectedShapes,i,f),i+=g):(TL(this.gl.unselectedShapes,o,f),o+=g)}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=$ve(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),kt.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&&(vd(i,{center:k.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(pf(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,o/2,r/2),o+=r}}ei=Wve();Jo(ei,1,"close",QH,Ti);Jo(ei,1,"getDpr",JH,Ti);Jo(ei,1,"getContentPageBounds",ZH,Ti);Jo(ei,1,"getContentScreenBounds",XH,Ti);Jo(ei,1,"getCanvasSize",YH,Ti);Jo(ei,1,"getCanvasClientPosition",GH,Ti);Jo(ei,1,"getCanvasPageBounds",qH,Ti);Jo(ei,1,"getZoom",VH,Ti);Jo(ei,1,"getCanvasPageBoundsArray",WH,Ti);Jo(ei,1,"render",KH,Ti);qve(ei,Ti);function Yve(){const n=Q(),e=Mn(),t=P.useRef(null),r=P.useRef(!1),s=P.useRef();P.useEffect(()=>{try{const d=new Ti(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),g=s.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);s.current.originPagePoint.setTo(g),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(Lp(f,d),!n.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const g=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(g)&&!m.containsPoint(g)){s.current.isInViewport=m.containsPoint(g);const b=k.Sub(m.center,m.point),C=k.Add(g,b);s.current.originPagePoint.setTo(C),s.current.originPageCenter.setTo(g),n.centerOnPoint(g,{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&&Fp(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(k.Sub(f,v));return}n.centerOnPoint(f)}const g=s.current.getMinimapPagePoint(d.clientX,d.clientY),m=n.pageToScreen(g),y={type:"pointer",target:"canvas",name:"pointer_move",...Hs(d),point:m,isPen:n.getInstanceState().isPenMode};n.dispatch(y)},[n]),l=P.useCallback(d=>{const f=Y4(d);n.dispatch({type:"wheel",name:"wheel",delta:f,point:new k(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey,metaKey:d.metaKey,accelKey:Pr(d)})},[n]),c=Vp();return P.useEffect(()=>{n.timers.setTimeout(()=>{var d,f;(d=s.current)==null||d.updateColors(),(f=s.current)==null||f.render()})},[c,n]),p.jsx("div",{className:"tlui-minimap",children:p.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:i,onPointerMove:a,onPointerDown:o,onWheelCapture:l})})}function Xve(n,e){const[t,r]=ot.useState(e);ot.useLayoutEffect(()=>{const i=vI(n);if(i)try{r(JSON.parse(i))}catch{console.error(`Could not restore value ${n} from local storage.`)}},[n]);const s=ot.useCallback(i=>{r(o=>{const a=typeof i=="function"?i(o):i;return xI(n,JSON.stringify(a)),a})},[n]);return[t,s]}const Zve=P.memo(function(){const e=wu(),t=gt(),r=Rr(),s=P.useRef(null);Ka(s);const[i,o]=Xve("minimap",!0),a=P.useCallback(()=>{o(d=>!d)},[o]),{ZoomMenu:l,Minimap:c}=oc();return r<dn.MOBILE?null:p.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[p.jsx("div",{className:"tlui-buttons__horizontal",children:l&&r<dn.TABLET?p.jsx(l,{}):i?p.jsxs(p.Fragment,{children:[l&&p.jsx(l,{}),c&&p.jsx(He,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:p.jsx(ct,{icon:i?"chevrons-ne":"chevrons-sw"})})]}):p.jsxs(p.Fragment,{children:[p.jsx(He,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(vp(e["zoom-out"].label))} ${Rk(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:p.jsx(ct,{icon:"minus"})}),l&&p.jsx(l,{}),p.jsx(He,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(vp(e["zoom-in"].label))} ${Rk(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:p.jsx(ct,{icon:"plus"})}),c&&p.jsx(He,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:p.jsx(ct,{icon:i?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=dn.TABLET&&!i&&p.jsx(c,{})]})}),Jve=function({name:e,id:t,isCurrentPage:r,onCancel:s}){const i=Q(),o=jn(),a=P.useRef(null),l=P.useRef(null),c=P.useCallback(()=>{l.current=i.markHistoryStoppingPoint("rename page")},[i]),d=P.useCallback(g=>{i.renamePage(t,g||"New Page"),o("rename-page",{source:"page-menu"})},[i,t,o]),f=P.useCallback(()=>{l.current&&i.bailToMark(l.current),s()},[i,s]);return p.jsx(Qp,{className:"tlui-page-menu__item__input",ref:g=>a.current=g,defaultValue:e,onValueChange:d,onCancel:f,onFocus:c,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},aI=(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=Oo(a.index):!a&&l?i=VV(o[0].index):i=Qf(a.index,l.index),i!==o[t].index&&(n.markHistoryStoppingPoint("moving page"),n.updatePage({id:e,index:i}),s("move-page",{source:"page-menu"}))},ML=Gn(function({index:e,listSize:t,item:r,onRename:s}){const i=Q(),o=gt(),a=i.getPages(),l=jn(),c=P.useCallback(()=>{i.markHistoryStoppingPoint("creating page");const m=Es.createId();i.duplicatePage(r.id,m),l("duplicate-page",{source:"page-menu"})},[i,r,l]),d=P.useCallback(()=>{aI(i,r.id,e,e-1,l)},[i,r,e,l]),f=P.useCallback(()=>{aI(i,r.id,e,e+1,l)},[i,r,e,l]),g=P.useCallback(()=>{i.markHistoryStoppingPoint("deleting page"),i.deletePage(r.id),l("delete-page",{source:"page-menu"})},[i,r,l]);return p.jsxs(H_,{id:`page item submenu ${e}`,children:[p.jsx(K_,{children:p.jsx(He,{type:"icon",title:o("page-menu.submenu.title"),children:p.jsx(ct,{icon:"dots-vertical",small:!0})})}),p.jsx(W_,{alignOffset:0,side:"right",sideOffset:-4,children:p.jsxs(Vr,{type:"menu",sourceId:"page-menu",children:[p.jsxs(lt,{id:"modify",children:[s&&p.jsx(sr,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),p.jsx(sr,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=i.options.maxPages}),e>0&&p.jsx(sr,{id:"move-up",onSelect:d,label:"page-menu.submenu.move-up"}),e<t-1&&p.jsx(sr,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:f})]}),t>1&&p.jsx(lt,{id:"delete",children:p.jsx(sr,{id:"delete",onSelect:g,label:"page-menu.submenu.delete"})})]})})]})}),Qve=P.memo(function(){const e=Q(),t=jn(),r=gt(),s=Rr(),i=P.useCallback(()=>b(!1),[]),[o,a]=Va("page-menu",i),l=36,c=P.useRef(null),d=ie("pages",()=>e.getPages(),[e]),f=ie("currentPage",()=>e.getCurrentPage(),[e]),g=ie("currentPageId",()=>e.getCurrentPageId(),[e]),m=Qs(),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]),E=P.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[_,M]=P.useState(Object.fromEntries(d.map((N,L)=>[N.id,{y:L*l,offsetY:0,isSelected:!1}])));P.useLayoutEffect(()=>{M(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-${g}"]`);if(N){const L=c.current;if(!L)return;const V=N.offsetTop,Z=L.scrollTop;V<Z&&L.scrollTo({top:V});const W=V+l,$=L.scrollTop+L.offsetHeight;W>$&&L.scrollTo({top:W-L.offsetHeight})}})},[l,g,o,e]);const A=P.useCallback(N=>{const{clientY:L,currentTarget:V}=N,{dataset:{id:Z,index:W}}=V;if(!Z||!W)return;const $=E.current;Lp(N.currentTarget,N),$.status="pointing",$.pointing={id:Z,index:+W};const re=_[Z].y;$.startY=L,$.startIndex=Math.max(0,Math.min(Math.round(re/l),d.length-1))},[l,d.length,_]),O=P.useCallback(N=>{const L=E.current;if(L.status==="pointing"){const{clientY:V}=N,Z=V-L.startY;Math.abs(Z)>5&&(L.status="dragging")}if(L.status==="dragging"){const{clientY:V}=N,Z=V-L.startY,W=_[L.pointing.id],{startIndex:$,pointing:Y}=L,re=W.y+Z,K=Math.max(0,Math.min(Math.round(re/l),d.length-1)),ne={..._};if(ne[Y.id]={y:W.y,offsetY:Z,isSelected:!0},K!==L.dragIndex){L.dragIndex=K;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];K===$?ce=ge*l:K<$?K<=ge&&ge<$?ce=(ge+1)*l:ce=ge*l:K>$&&(K>=ge&&ge>$?ce=(ge-1)*l:ce=ge*l),ce!==ne[Pe.id].y&&(ne[Pe.id]={y:ce,offsetY:0,isSelected:!0})}}M(ne)}},[l,d,_]),D=P.useCallback(N=>{const L=E.current;if(L.status==="dragging"){const{id:V,index:Z}=L.pointing;aI(e,V,Z,L.dragIndex,t)}Fp(N.currentTarget,N),L.status="idle"},[e,t]),B=P.useCallback(N=>{const L=E.current;N.key==="Escape"&&(L.status==="dragging"&&M(Object.fromEntries(d.map((V,Z)=>[V.id,{y:Z*l,offsetY:0,isSelected:!1}]))),L.status="idle")},[l,d]),U=P.useCallback(()=>{m||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const N=Es.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]),G=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 p.jsxs(cu,{id:"pages",onOpenChange:a,open:o,children:[p.jsx(uu,{"data-testid":"main.page-menu",children:p.jsxs(He,{type:"menu",title:f.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[p.jsx("div",{className:"tlui-page-menu__name",children:f.name}),p.jsx(ct,{icon:"chevron-down",small:!0})]})}),p.jsx(du,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:x,children:p.jsxs("div",{className:"tlui-page-menu__wrapper",children:[p.jsxs("div",{className:"tlui-page-menu__header",children:[p.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!m&&p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsx(He,{type:"icon","data-testid":"page-menu.edit",title:r(x?"page-menu.edit-done":"page-menu.edit-start"),onClick:C,children:p.jsx(ct,{icon:x?"check":"edit"})}),p.jsx(He,{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:p.jsx(ct,{icon:"plus"})})]})]}),p.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?p.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:[p.jsx(He,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:A,onPointerUp:D,onPointerMove:O,onKeyDown:B,"data-id":N.id,"data-index":L,children:p.jsx(ct,{icon:"drag-handle-dots"})}),s<dn.TABLET_SM&&v?p.jsxs(He,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const Z=window.prompt("Rename page",N.name);Z&&Z!==N.name&&z(N.id,Z)},onDoubleClick:C,children:[p.jsx(oI,{checked:N.id===f.id}),p.jsx(Pn,{children:N.name})]}):p.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:p.jsx(Jve,{id:N.id,name:N.name,isCurrentPage:N.id===f.id,onCancel:()=>{b(!1),e.menus.clearOpenMenus()}})}),!m&&p.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":x,children:p.jsx(ML,{index:L,item:N,listSize:d.length})})]},N.id+"_editing"):p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[p.jsxs(He,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>G(N.id),onDoubleClick:C,title:r("page-menu.go-to-page"),children:[p.jsx(oI,{checked:N.id===f.id}),p.jsx(Pn,{children:N.name})]}),!m&&p.jsx("div",{className:"tlui-page_menu__item__submenu",children:p.jsx(ML,{index:L,item:N,listSize:d.length,onRename:()=>{if(kt.isIos){const Z=window.prompt("Rename page",N.name);Z&&Z!==N.name&&z(N.id,Z)}else b(!0),g!==N.id&&G(N.id)}})})]},N.id)})})]})})]})});function exe(){const n=Q(),e=Qs(),t=ie("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(e&&!t))return p.jsxs(p.Fragment,{children:[p.jsx(nxe,{}),p.jsx(txe,{})]})}function txe(){const n=Zr(1),e=qa(),t=n&&e;return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"delete",disabled:!t}),p.jsx(ue,{actionId:"duplicate",disabled:!t})]})}function nxe(){const n=yH(),e=mH();return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"undo",disabled:!n}),p.jsx(ue,{actionId:"redo",disabled:!e})]})}const rxe=P.memo(function({children:e}){const t=e??p.jsx(exe,{});return p.jsx(Vr,{type:"small-icons",sourceId:"quick-actions",children:t})});function sxe({userId:n}){var t;const e=q0(n);return e?p.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:((t=e.userName)==null?void 0:t[0])??""},n):null}const ixe=Gn(function({userId:e}){var c;const t=Q(),r=gt(),s=jn(),i=q0(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?p.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal","data-follow":l||a,children:[p.jsxs(He,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>t.zoomToUser(e),onDoubleClick:o,children:[p.jsx(Ko,{icon:"color",color:i.color}),p.jsx("div",{className:"tlui-people-menu__name",children:((c=i.userName)==null?void 0:c.trim())||r("people-menu.anonymous-user")})]}),p.jsx(He,{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,children:p.jsx(ct,{icon:a?"leading":l?"following":"follow"})})]}):null});function oxe({count:n}){return p.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(n)})}const axe=Gn(function(){const e=Q(),t=Mn(),r=gt(),s=jn(),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:g,handleButtonPointerEnter:m,handleButtonPointerUp:y}=ot.useMemo(()=>{const v=()=>{i.current=!1,window.removeEventListener("pointerup",v)};return{handleButtonClick:_=>{const{id:M}=_.currentTarget.dataset;M&&c!==M&&d(M)},handleButtonPointerDown:_=>{const{id:M}=_.currentTarget.dataset;M&&(d(M),i.current=!0,window.addEventListener("pointerup",v))},handleButtonPointerEnter:_=>{if(!i.current)return;const{id:M}=_.currentTarget.dataset;M&&d(M)},handleButtonPointerUp:_=>{const{id:M}=_.currentTarget.dataset;M&&d(M)}}},[c,d]);return p.jsxs(PT,{onOpenChange:l,open:o,children:[p.jsx(kT,{dir:"ltr",asChild:!0,children:p.jsx(He,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:p.jsx(ct,{icon:"color"})})}),p.jsx(IT,{container:t,children:p.jsx(ET,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:p.jsx("div",{className:"tlui-buttons__grid",children:ck.map(v=>p.jsx(He,{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:g,onPointerUp:y,onClick:f,children:p.jsx(ct,{icon:"color"})},v))})})})]})});function lxe(){const n=Q(),e=jn(),t=ie("userName",()=>n.user.getName(),[]),r=gt(),s=P.useRef(t),i=P.useRef(t),[o,a]=P.useState(!1),l=P.useCallback(()=>{a(g=>!g)},[]),c=P.useCallback(g=>{i.current=g,n.user.updateUserPreferences({name:g})},[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 p.jsxs("div",{className:"tlui-people-menu__user",children:[p.jsx(axe,{}),o?p.jsx(Qp,{className:"tlui-people-menu__user__input",defaultValue:t,onValueChange:c,onComplete:l,onCancel:f,onBlur:d,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{o||a(!0)},children:t||r("people-menu.anonymous-user")}),t?null:p.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")})]}),p.jsx(He,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:p.jsx(ct,{icon:o?"check":"edit"})})]})}function cxe({displayUserWhenAlone:n,children:e}){const t=gt(),r=Mn(),s=Q(),i=J4(),o=ie("user",()=>s.user.getColor(),[s]),a=ie("user",()=>s.user.getName(),[s]),[l,c]=Va("people menu");return p.jsxs(PT,{onOpenChange:c,open:l,children:[p.jsx(kT,{dir:"ltr",asChild:!0,children:p.jsxs("button",{className:"tlui-people-menu__avatars-button",title:t("people-menu.title"),children:[i.length>5&&p.jsx(oxe,{count:i.length-5}),p.jsxs("div",{className:"tlui-people-menu__avatars",children:[i.slice(-5).map(d=>p.jsx(sxe,{userId:d},d)),(n||i.length>0)&&p.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:o},children:(a==null?void 0:a[0])??""})]})]})}),p.jsx(IT,{container:r,children:p.jsx(ET,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:et,children:p.jsxs("div",{className:"tlui-people-menu__wrapper",children:[p.jsx("div",{className:"tlui-people-menu__section",children:p.jsx(lxe,{})}),i.length>0&&p.jsx("div",{className:"tlui-people-menu__section",children:i.map(d=>p.jsx(ixe,{userId:d},d+"_presence"))}),e]})})})]})}function uxe(){return p.jsx("div",{className:"tlui-share-zone",draggable:!1,children:p.jsx(cxe,{displayUserWhenAlone:!0})})}const dxe=Object.freeze([Xs,ru,su,Bo]);function eK(n=dxe){const e=Q();return ie("getRelevantStyles",()=>{var i;const t=new pk(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 vi={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"}]},$c=P.memo(function(e){const{uiType:t,items:r,title:s,style:i,value:o,onValueChange:a,onHistoryMark:l,theme:c}=e,d=Q(),f=gt(),g=Rr(),m=P.useRef(!1),y=P.useRef(null),{handleButtonClick:v,handleButtonPointerDown:x,handleButtonPointerEnter:b,handleButtonPointerUp:C}=P.useMemo(()=>{const E=()=>{m.current=!1,window.removeEventListener("pointerup",E);const D=y.current;D&&(["TEXTAREA","INPUT"].includes(D.nodeName)||D.isContentEditable)?D.focus():g>=dn.TABLET_SM&&d.getContainer().focus(),y.current=null};return{handleButtonClick:D=>{const{id:B}=D.currentTarget.dataset;o.type==="shared"&&o.value===B||(l==null||l("point picker item"),a(i,B))},handleButtonPointerDown:D=>{const{id:B}=D.currentTarget.dataset;l==null||l("point picker item"),a(i,B),m.current=!0,y.current=document.activeElement,window.addEventListener("pointerup",E)},handleButtonPointerEnter:D=>{if(!m.current)return;const{id:B}=D.currentTarget.dataset;a(i,B)},handleButtonPointerUp:D=>{const{id:B}=D.currentTarget.dataset;o.type==="shared"&&o.value===B||a(i,B)}}},[d,g,o,l,a,i]);return p.jsx("div",{"data-testid":`style.${t}`,className:ze("tlui-buttons__grid"),children:r.map(E=>{const _=s+" — "+f(`${t}-style.${E.value}`);return p.jsx(He,{type:"icon","data-id":E.value,"data-testid":`style.${t}.${E.value}`,"aria-label":_,"data-state":o.type==="shared"&&o.value===E.value?"hinted":void 0,title:_,className:ze("tlui-button-grid__button"),style:i===Xs?{color:c[E.value].solid}:void 0,onPointerEnter:b,onPointerDown:x,onPointerUp:C,onClick:v,children:p.jsx(ct,{icon:E.icon})},E.value)})})});function tK(n,[e,t]){return Math.min(t,Math.max(e,n))}function hxe(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 nK=["PageUp","PageDown"],rK=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],sK={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Sh="Slider",[lI,fxe,pxe]=cv(Sh),[iK,s1e]=Xo(Sh,[pxe]),[gxe,Nv]=iK(Sh),oK=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:g=()=>{},inverted:m=!1,form:y,...v}=n,x=P.useRef(new Set),b=P.useRef(0),E=o==="horizontal"?mxe:yxe,[_=[],M]=rc({prop:d,defaultProp:c,onChange:G=>{var N;(N=[...x.current][b.current])==null||N.focus(),f(G)}}),A=P.useRef(_);function O(G){const z=bxe(_,G);U(G,z)}function D(G){U(G,b.current)}function B(){const G=A.current[b.current];_[b.current]!==G&&g(_)}function U(G,z,{commit:N}={commit:!1}){const L=Ixe(i),V=Exe(Math.round((G-r)/i)*i+r,L),Z=tK(V,[r,s]);M((W=[])=>{const $=xxe(W,Z,z);if(kxe($,l*i)){b.current=$.indexOf(Z);const Y=String($)!==String(W);return Y&&N&&g($),Y?$:W}else return W})}return p.jsx(gxe,{scope:n.__scopeSlider,name:t,disabled:a,min:r,max:s,valueIndexToChangeRef:b,thumbs:x.current,values:_,orientation:o,form:y,children:p.jsx(lI.Provider,{scope:n.__scopeSlider,children:p.jsx(lI.Slot,{scope:n.__scopeSlider,children:p.jsx(E,{"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:O,onSlideMove:a?void 0:D,onSlideEnd:a?void 0:B,onHomeKeyDown:()=>!a&&U(r,0,{commit:!0}),onEndKeyDown:()=>!a&&U(s,_.length-1,{commit:!0}),onStepKeyDown:({event:G,direction:z})=>{if(!a){const V=nK.includes(G.key)||G.shiftKey&&rK.includes(G.key)?10:1,Z=b.current,W=_[Z],$=i*V*z;U(W+$,Z,{commit:!0})}}})})})})});oK.displayName=Sh;var[aK,lK]=iK(Sh,{startEdge:"left",endEdge:"right",size:"width",direction:1}),mxe=P.forwardRef((n,e)=>{const{min:t,max:r,dir:s,inverted:i,onSlideStart:o,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...d}=n,[f,g]=P.useState(null),m=Wt(e,E=>g(E)),y=P.useRef(void 0),v=t_(s),x=v==="ltr",b=x&&!i||!x&&i;function C(E){const _=y.current||f.getBoundingClientRect(),M=[0,_.width],O=TT(M,b?[t,r]:[r,t]);return y.current=_,O(E-_.left)}return p.jsx(aK,{scope:n.__scopeSlider,startEdge:b?"left":"right",endEdge:b?"right":"left",direction:b?1:-1,size:"width",children:p.jsx(cK,{dir:v,"data-orientation":"horizontal",...d,ref:m,style:{...d.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:E=>{const _=C(E.clientX);o==null||o(_)},onSlideMove:E=>{const _=C(E.clientX);a==null||a(_)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:E=>{const M=sK[b?"from-left":"from-right"].includes(E.key);c==null||c({event:E,direction:M?-1:1})}})})}),yxe=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=Wt(e,d),g=P.useRef(void 0),m=!s;function y(v){const x=g.current||d.current.getBoundingClientRect(),b=[0,x.height],E=TT(b,m?[r,t]:[t,r]);return g.current=x,E(v-x.top)}return p.jsx(aK,{scope:n.__scopeSlider,startEdge:m?"bottom":"top",endEdge:m?"top":"bottom",size:"height",direction:m?1:-1,children:p.jsx(cK,{"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:()=>{g.current=void 0,a==null||a()},onStepKeyDown:v=>{const b=sK[m?"from-bottom":"from-top"].includes(v.key);l==null||l({event:v,direction:b?-1:1})}})})}),cK=P.forwardRef((n,e)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:s,onSlideEnd:i,onHomeKeyDown:o,onEndKeyDown:a,onStepKeyDown:l,...c}=n,d=Nv(Sh,t);return p.jsx(bt.span,{...c,ref:e,onKeyDown:De(n.onKeyDown,f=>{f.key==="Home"?(o(f),f.preventDefault()):f.key==="End"?(a(f),f.preventDefault()):nK.concat(rK).includes(f.key)&&(l(f),f.preventDefault())}),onPointerDown:De(n.onPointerDown,f=>{const g=f.target;g.setPointerCapture(f.pointerId),f.preventDefault(),d.thumbs.has(g)?g.focus():r(f)}),onPointerMove:De(n.onPointerMove,f=>{f.target.hasPointerCapture(f.pointerId)&&s(f)}),onPointerUp:De(n.onPointerUp,f=>{const g=f.target;g.hasPointerCapture(f.pointerId)&&(g.releasePointerCapture(f.pointerId),i(f))})})}),uK="SliderTrack",dK=P.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=Nv(uK,t);return p.jsx(bt.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});dK.displayName=uK;var cI="SliderRange",hK=P.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=Nv(cI,t),i=lK(cI,t),o=P.useRef(null),a=Wt(e,o),l=s.values.length,c=s.values.map(g=>pK(g,s.min,s.max)),d=l>1?Math.min(...c):0,f=100-Math.max(...c);return p.jsx(bt.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...n.style,[i.startEdge]:d+"%",[i.endEdge]:f+"%"}})});hK.displayName=cI;var uI="SliderThumb",fK=P.forwardRef((n,e)=>{const t=fxe(n.__scopeSlider),[r,s]=P.useState(null),i=Wt(e,a=>s(a)),o=P.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return p.jsx(Sxe,{...n,ref:i,index:o})}),Sxe=P.forwardRef((n,e)=>{const{__scopeSlider:t,index:r,name:s,...i}=n,o=Nv(uI,t),a=lK(uI,t),[l,c]=P.useState(null),d=Wt(e,C=>c(C)),f=l?o.form||!!l.closest("form"):!0,g=H6(l),m=o.values[r],y=m===void 0?0:pK(m,o.min,o.max),v=wxe(r,o.values.length),x=g==null?void 0:g[a.size],b=x?Cxe(x,y,a.direction):0;return P.useEffect(()=>{if(l)return o.thumbs.add(l),()=>{o.thumbs.delete(l)}},[l,o.thumbs]),p.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${y}% + ${b}px)`},children:[p.jsx(lI.ItemSlot,{scope:n.__scopeSlider,children:p.jsx(bt.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&&p.jsx(vxe,{name:s??(o.name?o.name+(o.values.length>1?"[]":""):void 0),form:o.form,value:m},r)]})});fK.displayName=uI;var vxe=n=>{const{value:e,...t}=n,r=P.useRef(null),s=hxe(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]),p.jsx("input",{style:{display:"none"},...t,ref:r,defaultValue:e})};function xxe(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 tK(i,[0,100])}function wxe(n,e){return e>2?`Value ${n+1} of ${e}`:e===2?["Minimum","Maximum"][n]:void 0}function bxe(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 Cxe(n,e,t){const r=n/2,i=TT([0,50],[0,r]);return(r-i(e)*t)*t}function Pxe(n){return n.slice(0,-1).map((e,t)=>n[t+1]-e)}function kxe(n,e){if(e>0){const t=Pxe(n);return Math.min(...t)>=e}return!0}function TT(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 Ixe(n){return(String(n).split(".")[1]||"").length}function Exe(n,e){const t=Math.pow(10,e);return Math.round(n*t)/t}var _xe=oK,Txe=dK,Mxe=hK,Axe=fK;const Oxe=P.memo(function({onHistoryMark:e,title:t,steps:r,value:s,label:i,onValueChange:o,["data-testid"]:a}){const l=gt(),c=P.useCallback(g=>{o(g[0])},[o]),d=P.useCallback(()=>{e("click slider")},[e]),f=P.useCallback(()=>{s&&o(s)},[s,o]);return p.jsx("div",{className:"tlui-slider__container",children:p.jsxs(_xe,{"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:[p.jsx(Txe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&p.jsx(Mxe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&p.jsx(Axe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Rxe({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 g=Q(),m=gt(),[y,v]=P.useState(!1),[x,b]=P.useState(!1),C=P.useMemo(()=>{var A;return((A=i.find(O=>c.type==="shared"&&c.value===O.value))==null?void 0:A.icon)??"mixed"},[i,c]),E=P.useMemo(()=>{var A;return((A=o.find(O=>d.type==="shared"&&d.value===O.value))==null?void 0:A.icon)??"mixed"},[o,d]);if(c===void 0&&d===void 0)return null;const _=`style panel ${e} A`,M=`style panel ${t} B`;return p.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[p.jsx("div",{title:m(n),className:"tlui-style-panel__double-select-picker-label",children:m(n)}),p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsxs(cu,{id:_,open:y,onOpenChange:v,children:[p.jsx(uu,{children:p.jsx(He,{type:"icon","data-testid":`style.${e}`,title:m(r)+" — "+(c===null||c.type==="mixed"?m("style-panel.mixed"):m(`${e}-style.${c.value}`)),children:p.jsx(ct,{icon:C,small:!0,invertIcon:!0})})}),p.jsx(du,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:i.map((A,O)=>p.jsx(Vr,{type:"icons",sourceId:"style-panel",children:p.jsx(He,{"data-testid":`style.${e}.${A.value}`,type:"icon",onClick:()=>{f(a,A.value),$r.deleteOpenMenu(_,g.contextId),v(!1)},title:`${m(r)} — ${m(`${e}-style.${A.value}`)}`,children:p.jsx(ct,{icon:A.icon,invertIcon:!0})},A.value)},O))})})]}),p.jsxs(cu,{id:M,open:x,onOpenChange:b,children:[p.jsx(uu,{children:p.jsx(He,{type:"icon","data-testid":`style.${t}`,title:m(s)+" — "+(d===null||d.type==="mixed"?m("style-panel.mixed"):m(`${t}-style.${d.value}`)),children:p.jsx(ct,{icon:E,small:!0})})}),p.jsx(du,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:o.map(A=>p.jsx(Vr,{type:"icons",sourceId:"style-panel",children:p.jsx(He,{type:"icon",title:`${m(s)} — ${m(`${t}-style.${A.value}`)}`,"data-testid":`style.${t}.${A.value}`,onClick:()=>{f(l,A.value),$r.deleteOpenMenu(M,g.contextId),b(!1)},children:p.jsx(ct,{icon:A.icon})})},A.value))})})]})]})]})}const Dxe=P.memo(Rxe);function jxe({id:n,label:e,uiType:t,stylePanelType:r,style:s,items:i,type:o,value:a,onValueChange:l}){const c=gt(),d=Q(),[f,g]=P.useState(!1),m=P.useMemo(()=>{var C;return(C=i.find(E=>a.type==="shared"&&E.value===a.value))==null?void 0:C.icon},[i,a]),y=c(`style-panel.${r}`),v=a.type==="mixed"?c("style-panel.mixed"):y+" — "+c(`${t}-style.${a.value}`),x=e?c(e):"",b=`style panel ${n}`;return p.jsxs(cu,{id:b,open:f,onOpenChange:g,children:[p.jsx(uu,{children:p.jsxs(He,{type:o,"data-testid":`style.${t}`,title:v,children:[x&&p.jsx(Pn,{children:x}),p.jsx(ct,{icon:m??"mixed"})]})}),p.jsx(du,{side:"left",align:"center",alignOffset:0,children:p.jsx("div",{className:ze("tlui-buttons__grid",`tlui-buttons__${r}`),children:p.jsx(Vr,{type:"icons",sourceId:"style-panel",children:i.map(C=>p.jsx(He,{type:"icon","data-testid":`style.${t}.${C.value}`,title:y+" — "+c(`${t}-style.${C.value}`),onClick:()=>{d.markHistoryStoppingPoint("select style dropdown item"),l(s,C.value),$r.deleteOpenMenu(b,d.contextId),g(!1)},children:p.jsx(ct,{icon:C.icon})},C.value))})})})]})}const MT=P.memo(jxe);function Nxe({styles:n}){const e=Vp();if(!n)return null;const t=n.get(qi),r=n.get(fS),s=n.get(hS),i=n.get(yS),o=n.get(Na),a=t===void 0,l=r===void 0&&s===void 0,c=i===void 0,d=o===void 0,f=Ha({isDarkMode:e});return p.jsxs(p.Fragment,{children:[p.jsx(Lxe,{theme:f,styles:n}),!d&&p.jsx(Fxe,{theme:f,styles:n}),!(a&&l&&c)&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[p.jsx(zxe,{styles:n}),p.jsx(Bxe,{styles:n}),p.jsx($xe,{styles:n})]})]})}function rg(){const n=Q(),e=jn();return ot.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 Lxe({styles:n,theme:e}){const t=gt(),r=Q(),s=P.useCallback(f=>r.markHistoryStoppingPoint(f),[r]),i=rg(),o=n.get(Xs),a=n.get(su),l=n.get(ru),c=n.get(Bo),d=a!==void 0||l!==void 0||c!==void 0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[o===void 0?null:p.jsx($c,{title:t("style-panel.color"),uiType:"color",style:Xs,items:vi.color,value:o,onValueChange:i,theme:e,onHistoryMark:s}),p.jsx(Uxe,{})]}),d&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:p.jsx($c,{title:t("style-panel.fill"),uiType:"fill",style:su,items:vi.fill,value:a,onValueChange:i,theme:e,onHistoryMark:s}),l===void 0?null:p.jsx($c,{title:t("style-panel.dash"),uiType:"dash",style:ru,items:vi.dash,value:l,onValueChange:i,theme:e,onHistoryMark:s}),c===void 0?null:p.jsx($c,{title:t("style-panel.size"),uiType:"size",style:Bo,items:vi.size,value:c,onValueChange:(f,g)=>{i(f,g);const m=r.getSelectedShapeIds();m.length>0&&Ht(r,m)},theme:e,onHistoryMark:s})]})]})}function Fxe({theme:n,styles:e}){const t=gt(),r=rg(),s=Q(),i=P.useCallback(d=>s.markHistoryStoppingPoint(d),[s]),o=e.get(Na),a=e.get(ok),l=e.get(gS),c=e.get(mS);return o===void 0&&l===void 0?null:p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:p.jsx($c,{title:t("style-panel.font"),uiType:"font",style:Na,items:vi.font,value:o,onValueChange:r,theme:n,onHistoryMark:i}),a===void 0?null:p.jsxs("div",{className:"tlui-style-panel__row",children:[p.jsx($c,{title:t("style-panel.align"),uiType:"align",style:ok,items:vi.textAlign,value:a,onValueChange:r,theme:n,onHistoryMark:i}),p.jsx("div",{className:"tlui-style-panel__row__extra-button",children:p.jsx(He,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:p.jsx(ct,{icon:"vertical-align-middle"})})})]}),l===void 0?null:p.jsxs("div",{className:"tlui-style-panel__row",children:[p.jsx($c,{title:t("style-panel.label-align"),uiType:"align",style:gS,items:vi.horizontalAlign,value:l,onValueChange:r,theme:n,onHistoryMark:i}),p.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?p.jsx(He,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:p.jsx(ct,{icon:"vertical-align-middle"})}):p.jsx(MT,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:mS,items:vi.verticalAlign,value:c,onValueChange:r})})]})]})}function zxe({styles:n}){const e=rg(),t=n.get(qi);return t===void 0?null:p.jsx(MT,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:qi,items:vi.geo,value:t,onValueChange:e})}function $xe({styles:n}){const e=rg(),t=n.get(yS);return t===void 0?null:p.jsx(MT,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:yS,items:vi.spline,value:t,onValueChange:e})}function Bxe({styles:n}){const e=rg(),t=n.get(fS),r=n.get(hS);return!t||!r?null:p.jsx(Dxe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:hS,itemsA:vi.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:fS,itemsB:vi.arrowheadEnd,valueB:t,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const gf=[.1,.25,.5,.75,1];function Uxe(){const n=Q(),e=P.useCallback(a=>n.markHistoryStoppingPoint(a),[n]),t=ie("opacity",()=>n.getSharedOpacity(),[n]),r=jn(),s=gt(),i=ot.useCallback(a=>{const l=gf[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:gf.indexOf(pV(gf,a=>Math.abs(a-t.value)));return p.jsx(Oxe,{"data-testid":"style.opacity",value:o>=0?o:gf.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:i,steps:gf.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const Hxe=P.memo(function({isMobile:e,children:t}){const r=Q(),s=P.useRef(null);Ka(s);const i=eK(),o=P.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=t??p.jsx(Nxe,{styles:i});return p.jsx("div",{ref:s,className:ze("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:o,children:a})}),Kxe=ot.forwardRef(function({children:e,className:t},r){return Ka(r),jae(r),p.jsx("div",{ref:r,"data-testid":"contextual-toolbar",className:ze("tlui-contextual-toolbar",t),onPointerDown:Zt,children:p.jsx("div",{className:"tlui-menu tlui-buttons__horizontal",role:"radiogroup",children:e})})});function Wxe({textEditor:n,onEditLinkStart:e}){const t=jn(),r=gt(),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})=>p.jsx(He,{title:r(`tool.rich-text-${l}`),"data-testid":`rich-text.${l}`,type:"icon",isActive:n.isActive(l,c),onPointerDown:et,onClick:d,children:p.jsx(ct,{small:!0,icon:l})},l))}function Vxe({textEditor:n,value:e,onComplete:t}){const r=Q(),[s,i]=P.useState(e),o=gt(),a=P.useRef(null),l=jn(),c="rich-text-menu",d=s.startsWith("http")?s:`https://${s}`,f=x=>i(x),g=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]),p.jsxs(p.Fragment,{children:[p.jsx(Qp,{ref:a,"data-testid":"rich-text.link-input",className:"tlui-rich-text__toolbar-link-input",value:s,onValueChange:f,onComplete:g,onCancel:v,placeholder:"example.com"}),p.jsx(He,{className:"tlui-rich-text__toolbar-link-visit",title:o("tool.rich-text-link-visit"),type:"icon",onPointerDown:et,onClick:m,disabled:!s,children:p.jsx(ct,{small:!0,icon:"external-link"})}),p.jsx(He,{className:"tlui-rich-text__toolbar-link-remove",title:o("tool.rich-text-link-remove"),"data-testid":"rich-text.link-remove",type:"icon",onPointerDown:et,onClick:y,children:p.jsx(ct,{small:!0,icon:"trash"})})]})}const qxe=150,Gxe=16,Yxe=16,Xxe=8,Sl=16,Zxe=16**2,Jxe=!0,Qxe=Gn(function({children:e}){const t=Q(),r=ie("textEditor",()=>t.getRichTextEditor(),[t]);return t.getInstanceState().isCoarsePointer||!r?null:p.jsx(ewe,{textEditor:r,children:e})});function ewe({textEditor:n,children:e}){const t=Q(),r=P.useRef(null),{isVisible:s,isInteractive:i,hide:o,show:a,position:l,move:c}=swe(),{isEditingLink:d,onEditLinkStart:f,onEditLinkComplete:g}=nwe(n),m=b0("force toolbar position update",0);P.useEffect(function(){function _(){m.update(M=>M+1)}return wS.requestAnimationFrame("first forced update",_),n.on("selectionUpdate",_),()=>{n.off("selectionUpdate",_)}},[n,m]),DI("shape change",function(){t.getEditingShape(),m.update(_=>_+1)},[t]);const y=P.useRef(!1),[v,x]=P.useState(!1);_a("toolbar position",function(){const _=r.current;if(!_)return;t.getCamera(),m.get();const M=twe(t,_);if(!M){y.current&&(y.current=!1,x(!1));return}t.getCameraState()==="moving"?r.current.style.setProperty("transform",`translate(${M.x}px, ${M.y}px)`):c(M.x,M.y),y.current||(y.current=!0,x(!0))},[t,n,m]);const b=ie("camera state",()=>t.getCameraState(),[t]),C=iwe(n);return P.useEffect(()=>{if(b==="moving"&&Jxe){o(!0);return}if(C||!v){o();return}a()},[v,b,C,a,o]),P.useLayoutEffect(()=>{const E=r.current;E&&(E.dataset.visible=`${s}`)},[s,l]),P.useLayoutEffect(()=>{const E=r.current;E&&E.style.setProperty("transform",`translate(${l.x}px, ${l.y}px)`)},[l]),P.useLayoutEffect(()=>{const E=r.current;E&&(E.dataset.interactive=`${i}`)},[i]),p.jsx(Kxe,{ref:r,className:"tlui-rich-text__toolbar","data-interactive":!1,"data-visible":!1,children:e||(d?p.jsx(Vxe,{textEditor:n,value:n.isActive("link")?n.getAttributes("link").href:"",onComplete:g}):p.jsx(Wxe,{textEditor:n,onEditLinkStart:f}))})}function AL(n){return new ye(n.x,n.y,n.width,n.height)}function twe(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 g=t.getRangeAt(f);r.push(AL(g.getBoundingClientRect()))}const s=ye.Common(r),i=n.getViewportScreenBounds();if(s.x-=i.x,s.y-=i.y,s.midY<Sl||s.midY>i.h-Sl||s.midX<Sl||s.midX>i.w-Sl)return;const o=AL(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-Xxe;return c=Rn(c,Sl,i.w-o.w-Sl),d=Rn(d,Sl,i.h-o.h-Sl),c+=a,d+=l,c=Math.round(c),d=Math.round(d),{x:c,y:d}}function nwe(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}=N0(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 rwe(n,e){return k.Sub(e,n).y**2>=Zxe}function swe(){const n=Q(),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 k(-1e3,-1e3)),c=P.useRef(new k(-1e3,-1e3)),d=P.useRef(-1),f=P.useRef(-1),g=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"&&rwe(c.current,l.current)){const{x:b,y:C}=c.current;l.current=new k(b,C),a({x:b,y:C})}},qxe))},[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)},Gxe);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 k(v,x),a({x:v,y:x}),e.current={name:"shown"},i(!0),r(!0)},Yxe);break}case"hiding":{clearTimeout(d.current),e.current={name:"shown"},r(!0),g(c.current.x,c.current.y);break}}},[n,g]);return{isVisible:s,isInteractive:t,show:y,hide:m,move:g,position:o}}function iwe(n){const[e,t]=P.useState(!1);return P.useEffect(()=>{if(!n)return;const r=f0(({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 owe(){const n=Q(),e=gt(),t=eK(),r=t==null?void 0:t.get(Xs),s=Ha({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}=oc();return l?p.jsxs(cu,{id:"mobile style menu",onOpenChange:a,children:[p.jsx(uu,{children:p.jsx(He,{type:"tool","data-testid":"mobile-styles.button",style:{color:o?"var(--color-muted-1)":i},title:e("style-panel.title"),disabled:o,children:p.jsx(ct,{icon:o?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),p.jsx(du,{side:"top",align:"end",children:l&&p.jsx(l,{isMobile:!0})})]}):null}function awe(){return p.jsxs(p.Fragment,{children:[p.jsx(cwe,{}),p.jsx(uwe,{}),p.jsx(dwe,{}),p.jsx(hwe,{}),p.jsx(fwe,{}),p.jsx(pwe,{}),p.jsx(gwe,{}),p.jsx(mwe,{}),p.jsx(ywe,{}),p.jsx(Swe,{}),p.jsx(xwe,{}),p.jsx(vwe,{}),p.jsx(Cwe,{}),p.jsx(Iwe,{}),p.jsx(wwe,{}),p.jsx(kwe,{}),p.jsx(Pwe,{}),p.jsx(bwe,{}),p.jsx(Ewe,{}),p.jsx(_we,{}),p.jsx(Twe,{}),p.jsx(Mwe,{}),p.jsx(Awe,{}),p.jsx(Owe,{}),p.jsx(Rwe,{}),p.jsx(Dwe,{}),p.jsx(Nwe,{}),p.jsx(jwe,{})]})}function lwe(n){var r;const e=Q(),t=(r=n.meta)==null?void 0:r.geo;return ie("is tool selected",()=>{const s=e.getCurrentToolId(),i=e.getSharedStyles().getAsKnownValue(qi);return t?s==="geo"&&i===t:s===n.id},[e,n.id,t])}function zt({tool:n}){const e=V_(),t=lwe(e[n]);return p.jsx(gs,{toolId:n,isSelected:t})}function cwe(){return p.jsx(zt,{tool:"select"})}function uwe(){return p.jsx(zt,{tool:"hand"})}function dwe(){return p.jsx(zt,{tool:"draw"})}function hwe(){return p.jsx(zt,{tool:"eraser"})}function fwe(){return p.jsx(zt,{tool:"arrow"})}function pwe(){return p.jsx(zt,{tool:"text"})}function gwe(){return p.jsx(zt,{tool:"note"})}function mwe(){return p.jsx(gs,{toolId:"asset"})}function ywe(){return p.jsx(zt,{tool:"rectangle"})}function Swe(){return p.jsx(zt,{tool:"ellipse"})}function vwe(){return p.jsx(zt,{tool:"diamond"})}function xwe(){return p.jsx(zt,{tool:"triangle"})}function wwe(){return p.jsx(zt,{tool:"rhombus"})}function bwe(){return p.jsx(zt,{tool:"heart"})}function Cwe(){return p.jsx(zt,{tool:"hexagon"})}function Pwe(){return p.jsx(zt,{tool:"cloud"})}function kwe(){return p.jsx(zt,{tool:"star"})}function Iwe(){return p.jsx(zt,{tool:"oval"})}function Ewe(){return p.jsx(zt,{tool:"x-box"})}function _we(){return p.jsx(zt,{tool:"check-box"})}function Twe(){return p.jsx(zt,{tool:"arrow-left"})}function Mwe(){return p.jsx(zt,{tool:"arrow-up"})}function Awe(){return p.jsx(zt,{tool:"arrow-down"})}function Owe(){return p.jsx(zt,{tool:"arrow-right"})}function Rwe(){return p.jsx(zt,{tool:"line"})}function Dwe(){return p.jsx(zt,{tool:"highlight"})}function jwe(){return p.jsx(zt,{tool:"frame"})}function Nwe(){return p.jsx(zt,{tool:"laser"})}const QC=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function eP(n,e,t,r){n.addEventListener?n.addEventListener(e,t,r):n.attachEvent&&n.attachEvent("on".concat(e),t)}function mf(n,e,t,r){n.removeEventListener?n.removeEventListener(e,t,r):n.detachEvent&&n.detachEvent("on".concat(e),t)}function gK(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 mK(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 Lwe(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 Cp={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,"-":QC?173:189,"=":QC?61:187,";":QC?59:186,"'":222,"[":219,"]":221,"\\":220},Vo={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Fy={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Qn={16:!1,18:!1,17:!1,91:!1},un={};for(let n=1;n<20;n++)Cp["f".concat(n)]=111+n;let nn=[],Gf=null,yK="all";const wa=new Map,sg=n=>Cp[n.toLowerCase()]||Vo[n.toLowerCase()]||n.toUpperCase().charCodeAt(0),Fwe=n=>Object.keys(Cp).find(e=>Cp[e]===n),zwe=n=>Object.keys(Vo).find(e=>Vo[e]===n);function SK(n){yK=n||"all"}function Pp(){return yK||"all"}function $we(){return nn.slice(0)}function Bwe(){return nn.map(n=>Fwe(n)||zwe(n)||String.fromCharCode(n))}function Uwe(){const n=[];return Object.keys(un).forEach(e=>{un[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=>sg(a))})})}),n}function Hwe(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 Kwe(n){return typeof n=="string"&&(n=sg(n)),nn.indexOf(n)!==-1}function Wwe(n,e){let t,r;n||(n=Pp());for(const s in un)if(Object.prototype.hasOwnProperty.call(un,s))for(t=un[s],r=0;r<t.length;)t[r].scope===n?t.splice(r,1).forEach(o=>{let{element:a}=o;return AT(a)}):r++;Pp()===n&&SK(e||"all")}function Vwe(n){let e=n.keyCode||n.which||n.charCode;const t=nn.indexOf(e);if(t>=0&&nn.splice(t,1),n.key&&n.key.toLowerCase()==="meta"&&nn.splice(0,nn.length),(e===93||e===224)&&(e=91),e in Qn){Qn[e]=!1;for(const r in Vo)Vo[r]===e&&(xi[r]=!1)}}function vK(n){if(typeof n>"u")Object.keys(un).forEach(s=>{Array.isArray(un[s])&&un[s].forEach(i=>Jm(i)),delete un[s]}),AT(null);else if(Array.isArray(n))n.forEach(s=>{s.key&&Jm(s)});else if(typeof n=="object")n.key&&Jm(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=""),Jm({key:n,scope:s,method:i,splitKey:"+"})}}const Jm=n=>{let{key:e,scope:t,method:r,splitKey:s="+"}=n;mK(e).forEach(o=>{const a=o.split(s),l=a.length,c=a[l-1],d=c==="*"?"*":sg(c);if(!un[d])return;t||(t=Pp());const f=l>1?gK(Vo,a):[],g=[];un[d]=un[d].filter(m=>{const v=(r?m.method===r:!0)&&m.scope===t&&Lwe(m.mods,f);return v&&g.push(m.element),!v}),g.forEach(m=>AT(m))})};function OL(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 Qn)Object.prototype.hasOwnProperty.call(Qn,i)&&(!Qn[i]&&e.mods.indexOf(+i)>-1||Qn[i]&&e.mods.indexOf(+i)===-1)&&(s=!1);(e.mods.length===0&&!Qn[16]&&!Qn[18]&&!Qn[17]&&!Qn[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(nn),e.method(n,e)===!1&&(n.preventDefault?n.preventDefault():n.returnValue=!1,n.stopPropagation&&n.stopPropagation(),n.cancelBubble&&(n.cancelBubble=!0)))}}function RL(n,e){const t=un["*"];let r=n.keyCode||n.which||n.charCode;if(!xi.filter.call(this,n))return;if((r===93||r===224)&&(r=91),nn.indexOf(r)===-1&&r!==229&&nn.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=Fy[a];n[a]&&nn.indexOf(l)===-1?nn.push(l):!n[a]&&nn.indexOf(l)>-1?nn.splice(nn.indexOf(l),1):a==="metaKey"&&n[a]&&(nn=nn.filter(c=>c in Fy||c===r))}),r in Qn){Qn[r]=!0;for(const a in Vo)Vo[a]===r&&(xi[a]=!0);if(!t)return}for(const a in Qn)Object.prototype.hasOwnProperty.call(Qn,a)&&(Qn[a]=n[Fy[a]]);n.getModifierState&&!(n.altKey&&!n.ctrlKey)&&n.getModifierState("AltGraph")&&(nn.indexOf(17)===-1&&nn.push(17),nn.indexOf(18)===-1&&nn.push(18),Qn[17]=!0,Qn[18]=!0);const s=Pp();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)&&OL(n,t[a],s,e);if(!(r in un))return;const i=un[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 g=0;g<d.length;g++)f.push(sg(d[g]));f.sort().join("")===nn.sort().join("")&&OL(n,l,s,e)}}function xi(n,e,t){nn=[];const r=mK(n);let s=[],i="all",o=document,a=0,l=!1,c=!0,d="+",f=!1,g=!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&&(g=!0)),typeof e=="string"&&(i=e),g&&vK(n,i);a<r.length;a++)n=r[a].split(d),s=[],n.length>1&&(s=gK(Vo,n)),n=n[n.length-1],n=n==="*"?"*":sg(n),n in un||(un[n]=[]),un[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(!wa.has(o)){const m=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return RL(v,o)},y=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;RL(v,o),Vwe(v)};wa.set(o,{keydownListener:m,keyupListenr:y,capture:f}),eP(o,"keydown",m,f),eP(o,"keyup",y,f)}if(!Gf){const m=()=>{nn=[]};Gf={listener:m,capture:f},eP(window,"focus",m,f)}}}function qwe(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(un).forEach(t=>{un[t].filter(s=>s.scope===e&&s.shortcut===n).forEach(s=>{s&&s.method&&s.method()})})}function AT(n){const e=Object.values(un).flat();if(e.findIndex(r=>{let{element:s}=r;return s===n})<0){const{keydownListener:r,keyupListenr:s,capture:i}=wa.get(n)||{};r&&s&&(mf(n,"keyup",s,i),mf(n,"keydown",r,i),wa.delete(n))}if((e.length<=0||wa.size<=0)&&(Object.keys(wa).forEach(s=>{const{keydownListener:i,keyupListenr:o,capture:a}=wa.get(s)||{};i&&o&&(mf(s,"keyup",o,a),mf(s,"keydown",i,a),wa.delete(s))}),wa.clear(),Object.keys(un).forEach(s=>delete un[s]),Gf)){const{listener:s,capture:i}=Gf;mf(window,"focus",s,i),Gf=null}}const tP={getPressedKeyString:Bwe,setScope:SK,getScope:Pp,deleteScope:Wwe,getPressedKeyCodes:$we,getAllKeyCodes:Uwe,isPressed:Kwe,filter:Hwe,trigger:qwe,unbind:vK,keyMap:Cp,modifier:Vo,modifierMap:Fy};for(const n in tP)Object.prototype.hasOwnProperty.call(tP,n)&&(xi[n]=tP[n]);if(typeof window<"u"){const n=window.hotkeys;xi.noConflict=e=>(e&&window.hotkeys===xi&&(window.hotkeys=n),xi),window.hotkeys=xi}const DL=["copy","cut","paste","asset"];function Gwe(){const n=Q(),e=Qs(),t=wu(),r=V_(),s=ie("is focused",()=>n.getInstanceState().isFocused,[n]);P.useEffect(()=>{if(!s)return;const i=new Array,o=(l,c)=>{xi(l,{element:document.body},c),i.push(()=>{xi.unbind(l,c)})},a=(l,c)=>{xi(l,{element:document.body,keyup:!0,keydown:!1},c),i.push(()=>{xi.unbind(l,c)})};for(const l of Object.values(t))l.kbd&&(e&&!l.readonlyOk||DL.includes(l.id)||o(jL(l.kbd),c=>{Af(n)||(et(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&n.getIsReadonly()||DL.includes(l.id)||o(jL(l.kbd),c=>{Af(n)||(et(c),l.onSelect("kbd"))});return o(",",l=>{if(Af(n)||n.inputs.keys.has("Comma"))return;et(l),n.focus(),n.inputs.keys.add("Comma");const{x:c,y:d,z:f}=n.inputs.currentPagePoint,g=n.pageToScreen({x:c,y:d}),m={type:"pointer",name:"pointer_down",point:{x:g.x,y:g.y,z:f},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:Pr(l),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(m)}),a(",",l=>{if(Af(n)||!n.inputs.keys.has("Comma"))return;n.inputs.keys.delete("Comma");const{x:c,y:d,z:f}=n.inputs.currentScreenPoint,g={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:Pr(l),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(g)}),()=>{i.forEach(l=>l())}},[t,r,e,n,s])}function jL(n){return Ywe(n).map(e=>{let t="";const r=e.includes("!"),s=e.includes("?"),i=e.includes("$"),o=e.replace(/[!?$]/g,"");return r&&s&&i?t=`cmd+shift+alt+${o},ctrl+shift+alt+${o}`:r&&i?t=`cmd+shift+${o},ctrl+shift+${o}`:s&&i?t=`cmd+alt+${o},ctrl+alt+${o}`:s&&r?t=`shift+alt+${o}`:r?t=`shift+${o}`:s?t=`alt+${o}`:i?t=`cmd+${o},ctrl+${o}`:t=o,t}).join(",")}function Ywe(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 Af(n){return n.menus.hasAnyOpenMenus()||n.getEditingShapeId()!==null||n.getCrashingError()}const Xwe=P.createContext(!1),Zwe={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,0:9};function Jwe({children:n}){const e=Q(),t=Su(),r=Rr(),s=gt(),i=P.useRef([]),[o,a]=P.useState(!1),l=Math.min(8,5+r),[c,d]=P.useState(0),f=P.useRef(null),[g,m]=P.useState(null),y=P.useMemo(()=>{const b=g?`:not([data-value="${g}"])`:"";return`
509
+ #${t}_main > *:nth-child(n + ${l+(g?1:2)})${b} {
510
+ display: none;
511
+ }
512
+ #${t}_more > *:nth-child(-n + ${l}) {
513
+ display: none;
514
+ }
515
+ #${t}_more > *:nth-child(-n + ${l+4}) {
516
+ margin-top: 0;
517
+ }
518
+ `},[g,t,l]),v=Pa(()=>{var _;if(!f.current)return;const b=Array.from(f.current.children);d(b.length),b.findIndex(M=>M.getAttribute("data-value")===g)<=l&&m(null);const E=Array.from(f.current.children).findIndex(M=>M.getAttribute("aria-checked")==="true");E!==-1&&(E>=l&&m(b[E].getAttribute("data-value")),i.current=Array.from(((_=f.current)==null?void 0:_.children)??[]).filter(M=>!(M instanceof HTMLElement)||M.tagName.toLowerCase()!=="button"?!1:!!(M.offsetWidth||M.offsetHeight)))});P.useLayoutEffect(()=>{v()}),P.useLayoutEffect(()=>{if(!f.current)return;const b=new MutationObserver(v);return b.observe(f.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{b.disconnect()}},[v]),P.useEffect(()=>{if(!e.options.enableToolbarKeyboardShortcuts)return;function b(C){var _;if(Af(e)||F4()||C.ctrlKey||C.metaKey||C.altKey||C.shiftKey)return;const E=Zwe[C.key];typeof E=="number"&&(et(C),(_=i.current[E])==null||_.click())}return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b)}},[e]);const x="toolbar overflow";return p.jsxs(p.Fragment,{children:[p.jsx("style",{nonce:e.options.nonce,children:y}),p.jsxs("div",{className:ze("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<dn.TABLET_SM}),role:"radiogroup",children:[p.jsx("div",{id:`${t}_main`,ref:f,className:"tlui-toolbar__tools__list",children:p.jsx(Vr,{type:"toolbar",sourceId:"toolbar",children:n})}),c>l+1&&p.jsx(Xwe.Provider,{value:!0,children:p.jsxs(cu,{id:x,open:o,onOpenChange:a,children:[p.jsx(uu,{children:p.jsx(He,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:p.jsx(ct,{icon:"chevron-up"})})}),p.jsx(du,{side:"top",align:"center",children:p.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,onClick:()=>{$r.deleteOpenMenu(x,e.contextId),a(!1)},children:p.jsx(Vr,{type:"toolbar-overflow",sourceId:"toolbar",children:n})})})]})})]})]})}function Qwe({activeToolId:n}){const e=Q(),t=Rr(),r=gt(),s=ie("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),i=ie("current tool",()=>e.getCurrentTool(),[e]);return!n||!i.isLockable?null:p.jsx(He,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ze("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<dn.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:p.jsx(ct,{icon:s?"lock":"unlock",small:!0})})}const ebe=P.memo(function({children:e}){const t=Q(),r=Rr(),s=Qs(),i=ie("current tool id",()=>t.getCurrentToolId(),[t]),o=P.useRef(null);Ka(o);const{ActionsMenu:a,QuickActions:l}=oc(),c=t.options.actionShortcutsLocation==="menu"?!1:t.options.actionShortcutsLocation==="toolbar"?!0:r<dn.TABLET;return p.jsx("div",{ref:o,className:"tlui-toolbar",children:p.jsxs("div",{className:"tlui-toolbar__inner",children:[p.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&p.jsxs("div",{className:"tlui-toolbar__extras",children:[c&&p.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[l&&p.jsx(l,{}),a&&p.jsx(a,{})]}),p.jsx(Qwe,{activeToolId:i})]}),p.jsx(Jwe,{children:e??p.jsx(awe,{})})]}),r<dn.TABLET_SM&&!s&&p.jsx("div",{className:"tlui-toolbar__tools",children:p.jsx(owe,{})})]})})});function tbe(){const n=gt();return p.jsxs("div",{className:ze("tlui-offline-indicator"),children:[n("status.offline"),p.jsx(Ko,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function nbe({maxWidth:n=420,ignoreRightWidth:e=0,stylePanelWidth:t=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:i}){const o=P.useRef(null),a=Rr(),l=P.useCallback(()=>{const c=o.current;if(!c)return;const d=c.parentElement.parentElement,f=d.querySelector(".tlui-layout__top__left"),g=d.querySelector(".tlui-layout__top__right"),m=d.offsetWidth,y=f.offsetWidth,v=g.offsetWidth,x=c.offsetWidth-e;let b=(m-x)/2;m%2!==0&&(b-=.5);const C=y+r,E=c.offsetLeft,_=Math.min(m-v-y-2*r,n),M=Math.max(b,C)-E;g.offsetWidth>t&&a<=6?c.style.setProperty("max-width",_-s+"px"):c.style.setProperty("max-width",_+"px"),c.style.setProperty("transform",`translate(${M}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"),g=d.querySelector(".tlui-layout__top__right"),m=new ResizeObserver(l);return m.observe(f),m.observe(g),m.observe(d),m.observe(c),l(),()=>{m.disconnect()}},[l]),P.useLayoutEffect(()=>{l()}),p.jsx("div",{ref:o,className:"tlui-top-panel__container",children:i})}function rbe(){const n=The()==="offline";return p.jsx(nbe,{children:n&&p.jsx(tbe,{})})}function sbe(){return p.jsxs(p.Fragment,{children:[p.jsx(ue,{actionId:"zoom-in",noClose:!0}),p.jsx(ue,{actionId:"zoom-out",noClose:!0}),p.jsx(IH,{}),p.jsx(EH,{}),p.jsx(_H,{})]})}const ibe=P.memo(function({children:e}){const t=Mn(),[r,s]=Va("zoom menu"),i=e??p.jsx(sbe,{});return p.jsxs(I_,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[p.jsx(E_,{asChild:!0,dir:"ltr",children:p.jsx(obe,{})}),p.jsx(xv,{container:t,children:p.jsx(__,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:p.jsx(Vr,{type:"menu",sourceId:"zoom-menu",children:i})})})]})}),obe=P.forwardRef(function(e,t){const r=Q(),s=Rr(),i=ie("zoom",()=>r.getZoomLevel(),[r]),o=gt(),a=P.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return p.jsx(He,{ref:t,...e,type:"icon",title:`${o("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<dn.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:s<dn.MOBILE?null:p.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(i*100),"%"]})})}),xK=P.createContext(null);function abe({overrides:n={},children:e}){const t=uh(n),r=Pv();return p.jsx(xK.Provider,{value:P.useMemo(()=>({ContextMenu:ive,ActionsMenu:R0e,HelpMenu:null,ZoomMenu:ibe,MainMenu:zve,Minimap:Yve,StylePanel:Hxe,PageMenu:Qve,NavigationPanel:Zve,Toolbar:ebe,RichTextToolbar:Qxe,KeyboardShortcutsDialog:_ve,QuickActions:rxe,HelperButtons:Ive,DebugPanel:yve,DebugMenu:mve,MenuPanel:wve,SharePanel:r?uxe:null,CursorChatBubble:r?lve:null,TopPanel:r?rbe:null,Dialogs:Hfe,Toasts:qfe,...t}),[t,r]),children:e})}function oc(){const n=P.useContext(xK);if(!n)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return n}const lbe=Gn(function({overrides:e,components:t,assetUrls:r,onUiEvent:s,forceMobile:i,mediaMimeTypes:o,children:a}){const l=Mr();return p.jsx(l9.Provider,{value:o,children:p.jsx(ehe,{assetUrls:o0e(r),children:p.jsx(rhe,{overrides:_fe(e),locale:(l==null?void 0:l.user.getLocale())??Po.locale,children:p.jsx(Kae,{onEvent:s,children:p.jsx(efe,{children:p.jsx(Ahe,{context:"tla",children:p.jsx(Mhe,{forceMobile:i,children:p.jsx(abe,{overrides:t,children:p.jsx(cbe,{overrides:e,children:a})})})})})})})})})});function cbe({overrides:n,children:e}){const t=Tfe(n);return p.jsx(Afe,{overrides:t.actions,children:p.jsx(Gfe,{overrides:t.tools,children:e})})}function ube(){const n=Q(),{addToast:e}=Wa();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 dbe=ot.memo(function({renderDebugMenuItems:e,children:t,hideUi:r,components:s,...i}){return p.jsx(lbe,{...i,components:s,children:p.jsx(hbe,{hideUi:r,renderDebugMenuItems:e,children:t})})}),hbe=ot.memo(function({children:e,hideUi:t,...r}){return p.jsxs(p.Fragment,{children:[e,t?null:p.jsx(fbe,{...r})]})}),fbe=ot.memo(function(){const e=Q(),t=gt(),r=Rr(),s=Qs(),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:g,NavigationPanel:m,HelperButtons:y,DebugPanel:v,CursorChatBubble:x,RichTextToolbar:b,Toasts:C,Dialogs:E}=oc();Gwe(),yfe(),ube();const _=P.useRef(!1),M=P.useRef(-1),[A,O]=P.useState(!1);DI("update hide toolbar while delayed",()=>{if(!(kt.isIos||kt.isAndroid))return;if(e.getEditingShapeId()===null){_.current&&(_.current=!1,clearTimeout(M.current),kt.isAndroid?M.current=e.timers.setTimeout(()=>{O(!1)},150):O(!1));return}_.current||(_.current=!0,clearTimeout(M.current),O(!0))},[]);const{"toggle-focus-mode":D}=wu();return p.jsxs("div",{className:ze("tlui-layout",{"tlui-layout__mobile":r<dn.TABLET_SM}),"data-iseditinganything":A,"data-breakpoint":r,children:[i?p.jsx("div",{className:"tlui-layout__top",children:p.jsx(He,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>D.onSelect("menu"),children:p.jsx(ct,{icon:"dot"})})}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"tlui-layout__top",children:[p.jsxs("div",{className:"tlui-layout__top__left",children:[c&&p.jsx(c,{}),y&&p.jsx(y,{})]}),p.jsx("div",{className:"tlui-layout__top__center",children:l&&p.jsx(l,{})}),p.jsxs("div",{className:"tlui-layout__top__right",children:[a&&p.jsx(a,{}),d&&r>=dn.TABLET_SM&&!s&&p.jsx(d,{})]})]}),p.jsxs("div",{className:"tlui-layout__bottom",children:[p.jsxs("div",{className:"tlui-layout__bottom__main",children:[m&&p.jsx(m,{}),f&&p.jsx(f,{}),g&&p.jsx(g,{})]}),o&&v&&p.jsx(v,{})]})]}),b&&p.jsx(b,{}),C&&p.jsx(C,{}),E&&p.jsx(E,{}),p.jsx(n0e,{}),x&&p.jsx(x,{})]})}),pbe=[...t0e,...Bme];function gbe(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:g,...m}=n,y=uh(a),v=P.useMemo(()=>({Scribble:RN,ShapeIndicators:ipe,CollaboratorScribble:RN,SelectionForeground:npe,SelectionBackground:epe,Handles:Yfe,...y}),[y]),x=_l(l),b=P.useMemo(()=>Aw("type",x,S7),[x]),C=_l(c),E=P.useMemo(()=>Aw("type",C,m9),[C]),_=_l(d),M=P.useMemo(()=>Aw("id",pbe,_),[_]),A=_l(s??kp),O=_l(i??p0),D=P.useMemo(()=>({addFontsFromNode:O9,...g,tipTapConfig:{extensions:tg,...g==null?void 0:g.tipTapConfig}}),[g]),B=P.useMemo(()=>[...A,...O],[A,O]),U=s0e(m.assetUrls);return b.find(z=>z.type==="embed")&&f&&d0.setEmbedDefinitions(f),p.jsx(Eae,{initialState:"select",...m,components:v,shapeUtils:b,bindingUtils:E,tools:M,textOptions:D,assetUrls:U,children:p.jsxs(dbe,{...m,components:v,mediaMimeTypes:B,children:[p.jsx(mbe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:A,acceptedVideoMimeTypes:O,onMount:o}),e]})})}function mbe({maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,onMount:s}){const i=Q(),o=Wa(),a=gt();P6(()=>{const d=[];return d.push(kSe(i)),i.fonts.requestFonts(Zge),dme(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}=Jt(),{ContextMenu:c}=oc();return c?p.jsx(c,{}):l?p.jsx(l,{}):null}const ybe={tipTapConfig:{extensions:tg},addFontsFromNode:O9};P.memo(function(e){const[t,r]=P.useState(null),[s,i]=P.useState(null),o=_l(e.shapeUtils??[]),a=P.useMemo(()=>[...S7,...o],[o]),l=_l(e.bindingUtils??[]),c=P.useMemo(()=>[...m9,...l],[l]),d=Nae({snapshot:e.snapshot,shapeUtils:a}),{pageId:f,bounds:g,scale:m,pixelRatio:y,background:v,padding:x,darkMode:b,preserveAspectRatio:C,format:E="svg",licenseKey:_,assetUrls:M,textOptions:A=ybe}=e;return P.useLayoutEffect(()=>{if(!s||!d)return;let O=!1;const D=document.createElement("div");s.appendChild(D),s.classList.add("tl-container","tl-theme__light");const B=new ke({store:d,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>D,licenseKey:_,fontAssetUrls:M==null?void 0:M.fonts,textOptions:A});f&&B.setCurrentPage(f);const U=B.getCurrentPageShapeIds();async function G(){const z=await B.toImage([...U],{bounds:g,scale:m,background:v,padding:x,darkMode:b,preserveAspectRatio:C,format:E});if(!z||O)return;const N=URL.createObjectURL(z.blob);r(N),B.dispose()}return G(),()=>{O=!0}},[E,s,d,a,c,f,g,m,v,x,b,C,_,y,M,A]),P.useEffect(()=>()=>{t&&URL.revokeObjectURL(t)},[t]),p.jsx("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:t&&p.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})})});P.memo(function({children:e}){const t=gt(),r=Rr(),s=P.useRef(null);Ka(s);const i=e??p.jsx(Tve,{});return r<dn.MOBILE?null:p.jsx("div",{ref:s,className:"tlui-help-menu",children:p.jsxs(H_,{id:"help menu",children:[p.jsx(K_,{children:p.jsx(He,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:p.jsx(ct,{icon:"question-mark",small:!0})})}),p.jsx(W_,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:p.jsx(Vr,{type:"menu",sourceId:"help-menu",children:i})})]})})});const Sbe=1,vbe=pt({schemaVersion:Er(1),storeVersion:oy,recordVersions:uS(it,pt({version:oy,subTypeVersions:uS(it,oy).optional(),subTypeKey:it.optional()}))}),xbe=pt({schemaVersion:Er(2),sequences:uS(it,oy)}),wbe=pt({tldrawFileFormatVersion:Cee,schema:Pee("schemaVersion",{1:vbe,2:xbe}),records:Bn(pt({id:it,typeName:it}).allowUnknownProperties())});function bbe(n){var e;try{return!!((e=n.document)!=null&&e.version)}catch{return!1}}function Cbe({json:n,schema:e}){let t;try{t=wbe.validate(JSON.parse(n))}catch(i){try{if(t=JSON.parse(n),bbe(t))return Lr.err({type:"v1File",data:t})}catch{}return Lr.err({type:"notATldrawFile",cause:i})}if(t.tldrawFileFormatVersion>Sbe)return Lr.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r,s;try{const i=Pbe(t.records);s=Object.fromEntries(i.map(o=>[o.id,o])),r=e.migrateStoreSnapshot({store:s,schema:t.schema})}catch(i){return Lr.err({type:"invalidRecords",cause:i})}if(r.type==="error")return Lr.err({type:"migrationFailed",reason:r.reason});try{return Lr.ok(fp({snapshot:{store:s,schema:t.schema},schema:e}))}catch(i){return Lr.err({type:"invalidRecords",cause:i})}}function Pbe(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))}Yl("tldraw","3.11.1","esm");function kbe(){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=Cbe({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 p.jsx("div",{style:{inset:0,position:"fixed"},children:p.jsx(gbe,{assetUrls:iV(),onMount:t,store:n})})}sV.createRoot(document.querySelector("#root")).render(p.jsx(ot.StrictMode,{children:p.jsx(kbe,{})}));