@kitschpatrol/tldraw-cli 4.6.36 → 4.6.38

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 (66) hide show
  1. package/bin/cli.js +1225 -1195
  2. package/dist/lib/index.js +1202 -1176
  3. package/dist/tldraw/assets/index-AkdEZoKY.css +1 -0
  4. package/dist/tldraw/assets/index-DVkTdmOS.js +525 -0
  5. package/dist/tldraw/icons/icon/0_merged.svg +1 -1
  6. package/dist/tldraw/icons/icon/arrow-arc.svg +1 -0
  7. package/dist/tldraw/icons/icon/arrow-elbow.svg +1 -0
  8. package/dist/tldraw/icons/icon/bookmark.svg +1 -0
  9. package/dist/tldraw/icons/icon/comment.svg +1 -0
  10. package/dist/tldraw/icons/icon/help-circle.svg +1 -0
  11. package/dist/tldraw/icons/icon/icon-names.json +6 -0
  12. package/dist/tldraw/icons/icon/manual.svg +1 -0
  13. package/dist/tldraw/icons/icon/question-mark-circle.svg +1 -1
  14. package/dist/tldraw/index.html +2 -2
  15. package/dist/tldraw/translations/ar.json +26 -2
  16. package/dist/tldraw/translations/bn.json +22 -2
  17. package/dist/tldraw/translations/ca.json +25 -2
  18. package/dist/tldraw/translations/cs.json +25 -2
  19. package/dist/tldraw/translations/da.json +25 -2
  20. package/dist/tldraw/translations/de.json +26 -2
  21. package/dist/tldraw/translations/el.json +22 -2
  22. package/dist/tldraw/translations/es.json +26 -2
  23. package/dist/tldraw/translations/fa.json +25 -2
  24. package/dist/tldraw/translations/fi.json +25 -2
  25. package/dist/tldraw/translations/fr.json +26 -2
  26. package/dist/tldraw/translations/gl.json +22 -2
  27. package/dist/tldraw/translations/gu-in.json +22 -2
  28. package/dist/tldraw/translations/he.json +25 -2
  29. package/dist/tldraw/translations/hi-in.json +26 -2
  30. package/dist/tldraw/translations/hr.json +25 -2
  31. package/dist/tldraw/translations/hu.json +25 -2
  32. package/dist/tldraw/translations/id.json +25 -2
  33. package/dist/tldraw/translations/it.json +27 -2
  34. package/dist/tldraw/translations/ja.json +26 -2
  35. package/dist/tldraw/translations/km-kh.json +22 -2
  36. package/dist/tldraw/translations/kn.json +22 -2
  37. package/dist/tldraw/translations/ko-kr.json +64 -3
  38. package/dist/tldraw/translations/main.json +63 -4
  39. package/dist/tldraw/translations/ml.json +22 -2
  40. package/dist/tldraw/translations/mr.json +22 -2
  41. package/dist/tldraw/translations/ms.json +22 -2
  42. package/dist/tldraw/translations/ne.json +25 -2
  43. package/dist/tldraw/translations/nl.json +9 -2
  44. package/dist/tldraw/translations/no.json +23 -2
  45. package/dist/tldraw/translations/pa.json +22 -2
  46. package/dist/tldraw/translations/pl.json +25 -2
  47. package/dist/tldraw/translations/pt-br.json +26 -2
  48. package/dist/tldraw/translations/pt-pt.json +26 -2
  49. package/dist/tldraw/translations/ro.json +25 -2
  50. package/dist/tldraw/translations/ru.json +26 -2
  51. package/dist/tldraw/translations/sl.json +25 -2
  52. package/dist/tldraw/translations/so.json +25 -2
  53. package/dist/tldraw/translations/sv.json +25 -2
  54. package/dist/tldraw/translations/ta.json +22 -2
  55. package/dist/tldraw/translations/te.json +24 -2
  56. package/dist/tldraw/translations/th.json +26 -2
  57. package/dist/tldraw/translations/tl.json +22 -2
  58. package/dist/tldraw/translations/tr.json +26 -2
  59. package/dist/tldraw/translations/uk.json +25 -2
  60. package/dist/tldraw/translations/ur.json +22 -2
  61. package/dist/tldraw/translations/vi.json +26 -2
  62. package/dist/tldraw/translations/zh-cn.json +27 -2
  63. package/dist/tldraw/translations/zh-tw.json +27 -3
  64. package/package.json +18 -18
  65. package/dist/tldraw/assets/index-CVVHYKYT.css +0 -1
  66. package/dist/tldraw/assets/index-Dr4aLNdU.js +0 -518
@@ -0,0 +1,525 @@
1
+ var EG=Object.defineProperty;var IG=(n,e,t)=>e in n?EG(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var R=(n,e,t)=>IG(n,typeof e!="symbol"?e+"":e,t);function TG(n,e){for(var t=0;t<e.length;t++){const r=e[t];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in n)){const o=Object.getOwnPropertyDescriptor(r,s);o&&Object.defineProperty(n,s,o.get?o:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function t(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=t(s);fetch(s.href,o)}})();var Os=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Za(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var yb={exports:{}},wf={},Sb={exports:{}},yt={};/**
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 NA;function _G(){if(NA)return yt;NA=1;var n=Symbol.for("react.element"),e=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),o=Symbol.for("react.provider"),i=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),c=Symbol.for("react.memo"),u=Symbol.for("react.lazy"),h=Symbol.iterator;function p(H){return H===null||typeof H!="object"?null:(H=h&&H[h]||H["@@iterator"],typeof H=="function"?H:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S=Object.assign,v={};function y(H,te,he){this.props=H,this.context=te,this.refs=v,this.updater=he||m}y.prototype.isReactComponent={},y.prototype.setState=function(H,te){if(typeof H!="object"&&typeof H!="function"&&H!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,H,te,"setState")},y.prototype.forceUpdate=function(H){this.updater.enqueueForceUpdate(this,H,"forceUpdate")};function w(){}w.prototype=y.prototype;function C(H,te,he){this.props=H,this.context=te,this.refs=v,this.updater=he||m}var T=C.prototype=new w;T.constructor=C,S(T,y.prototype),T.isPureReactComponent=!0;var E=Array.isArray,_=Object.prototype.hasOwnProperty,A={current:null},O={key:!0,ref:!0,__self:!0,__source:!0};function D(H,te,he){var Pe,ue={},Ae=null,ze=null;if(te!=null)for(Pe in te.ref!==void 0&&(ze=te.ref),te.key!==void 0&&(Ae=""+te.key),te)_.call(te,Pe)&&!O.hasOwnProperty(Pe)&&(ue[Pe]=te[Pe]);var ve=arguments.length-2;if(ve===1)ue.children=he;else if(1<ve){for(var Te=Array(ve),je=0;je<ve;je++)Te[je]=arguments[je+2];ue.children=Te}if(H&&H.defaultProps)for(Pe in ve=H.defaultProps,ve)ue[Pe]===void 0&&(ue[Pe]=ve[Pe]);return{$$typeof:n,type:H,key:Ae,ref:ze,props:ue,_owner:A.current}}function F(H,te){return{$$typeof:n,type:H.type,key:te,ref:H.ref,props:H.props,_owner:H._owner}}function U(H){return typeof H=="object"&&H!==null&&H.$$typeof===n}function V(H){var te={"=":"=0",":":"=2"};return"$"+H.replace(/[=:]/g,function(he){return te[he]})}var Y=/\/+/g;function j(H,te){return typeof H=="object"&&H!==null&&H.key!=null?V(""+H.key):te.toString(36)}function N(H,te,he,Pe,ue){var Ae=typeof H;(Ae==="undefined"||Ae==="boolean")&&(H=null);var ze=!1;if(H===null)ze=!0;else switch(Ae){case"string":case"number":ze=!0;break;case"object":switch(H.$$typeof){case n:case e:ze=!0}}if(ze)return ze=H,ue=ue(ze),H=Pe===""?"."+j(ze,0):Pe,E(ue)?(he="",H!=null&&(he=H.replace(Y,"$&/")+"/"),N(ue,te,he,"",function(je){return je})):ue!=null&&(U(ue)&&(ue=F(ue,he+(!ue.key||ze&&ze.key===ue.key?"":(""+ue.key).replace(Y,"$&/")+"/")+H)),te.push(ue)),1;if(ze=0,Pe=Pe===""?".":Pe+":",E(H))for(var ve=0;ve<H.length;ve++){Ae=H[ve];var Te=Pe+j(Ae,ve);ze+=N(Ae,te,he,Te,ue)}else if(Te=p(H),typeof Te=="function")for(H=Te.call(H),ve=0;!(Ae=H.next()).done;)Ae=Ae.value,Te=Pe+j(Ae,ve++),ze+=N(Ae,te,he,Te,ue);else if(Ae==="object")throw te=String(H),Error("Objects are not valid as a React child (found: "+(te==="[object Object]"?"object with keys {"+Object.keys(H).join(", ")+"}":te)+"). If you meant to render a collection of children, use an array instead.");return ze}function z(H,te,he){if(H==null)return H;var Pe=[],ue=0;return N(H,Pe,"","",function(Ae){return te.call(he,Ae,ue++)}),Pe}function G(H){if(H._status===-1){var te=H._result;te=te(),te.then(function(he){(H._status===0||H._status===-1)&&(H._status=1,H._result=he)},function(he){(H._status===0||H._status===-1)&&(H._status=2,H._result=he)}),H._status===-1&&(H._status=0,H._result=te)}if(H._status===1)return H._result.default;throw H._result}var q={current:null},$={transition:null},K={ReactCurrentDispatcher:q,ReactCurrentBatchConfig:$,ReactCurrentOwner:A};function J(){throw Error("act(...) is not supported in production builds of React.")}return yt.Children={map:z,forEach:function(H,te,he){z(H,function(){te.apply(this,arguments)},he)},count:function(H){var te=0;return z(H,function(){te++}),te},toArray:function(H){return z(H,function(te){return te})||[]},only:function(H){if(!U(H))throw Error("React.Children.only expected to receive a single React element child.");return H}},yt.Component=y,yt.Fragment=t,yt.Profiler=s,yt.PureComponent=C,yt.StrictMode=r,yt.Suspense=l,yt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=K,yt.act=J,yt.cloneElement=function(H,te,he){if(H==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+H+".");var Pe=S({},H.props),ue=H.key,Ae=H.ref,ze=H._owner;if(te!=null){if(te.ref!==void 0&&(Ae=te.ref,ze=A.current),te.key!==void 0&&(ue=""+te.key),H.type&&H.type.defaultProps)var ve=H.type.defaultProps;for(Te in te)_.call(te,Te)&&!O.hasOwnProperty(Te)&&(Pe[Te]=te[Te]===void 0&&ve!==void 0?ve[Te]:te[Te])}var Te=arguments.length-2;if(Te===1)Pe.children=he;else if(1<Te){ve=Array(Te);for(var je=0;je<Te;je++)ve[je]=arguments[je+2];Pe.children=ve}return{$$typeof:n,type:H.type,key:ue,ref:Ae,props:Pe,_owner:ze}},yt.createContext=function(H){return H={$$typeof:i,_currentValue:H,_currentValue2:H,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},H.Provider={$$typeof:o,_context:H},H.Consumer=H},yt.createElement=D,yt.createFactory=function(H){var te=D.bind(null,H);return te.type=H,te},yt.createRef=function(){return{current:null}},yt.forwardRef=function(H){return{$$typeof:a,render:H}},yt.isValidElement=U,yt.lazy=function(H){return{$$typeof:u,_payload:{_status:-1,_result:H},_init:G}},yt.memo=function(H,te){return{$$typeof:c,type:H,compare:te===void 0?null:te}},yt.startTransition=function(H){var te=$.transition;$.transition={};try{H()}finally{$.transition=te}},yt.unstable_act=J,yt.useCallback=function(H,te){return q.current.useCallback(H,te)},yt.useContext=function(H){return q.current.useContext(H)},yt.useDebugValue=function(){},yt.useDeferredValue=function(H){return q.current.useDeferredValue(H)},yt.useEffect=function(H,te){return q.current.useEffect(H,te)},yt.useId=function(){return q.current.useId()},yt.useImperativeHandle=function(H,te,he){return q.current.useImperativeHandle(H,te,he)},yt.useInsertionEffect=function(H,te){return q.current.useInsertionEffect(H,te)},yt.useLayoutEffect=function(H,te){return q.current.useLayoutEffect(H,te)},yt.useMemo=function(H,te){return q.current.useMemo(H,te)},yt.useReducer=function(H,te,he){return q.current.useReducer(H,te,he)},yt.useRef=function(H){return q.current.useRef(H)},yt.useState=function(H){return q.current.useState(H)},yt.useSyncExternalStore=function(H,te,he){return q.current.useSyncExternalStore(H,te,he)},yt.useTransition=function(){return q.current.useTransition()},yt.version="18.3.1",yt}var FA;function aI(){return FA||(FA=1,Sb.exports=_G()),Sb.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 zA;function MG(){if(zA)return wf;zA=1;var n=aI(),e=Symbol.for("react.element"),t=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var u,h={},p=null,m=null;c!==void 0&&(p=""+c),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(m=l.ref);for(u in l)r.call(l,u)&&!o.hasOwnProperty(u)&&(h[u]=l[u]);if(a&&a.defaultProps)for(u in l=a.defaultProps,l)h[u]===void 0&&(h[u]=l[u]);return{$$typeof:e,type:a,key:p,ref:m,props:h,_owner:s.current}}return wf.Fragment=t,wf.jsx=i,wf.jsxs=i,wf}var BA;function AG(){return BA||(BA=1,yb.exports=MG()),yb.exports}var g=AG(),k=aI();const We=Za(k),B3=TG({__proto__:null,default:We},[k]);var Xm={},xb={exports:{}},ks={},vb={exports:{}},wb={};/**
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 $A;function OG(){return $A||($A=1,function(n){function e($,K){var J=$.length;$.push(K);e:for(;0<J;){var H=J-1>>>1,te=$[H];if(0<s(te,K))$[H]=K,$[J]=te,J=H;else break e}}function t($){return $.length===0?null:$[0]}function r($){if($.length===0)return null;var K=$[0],J=$.pop();if(J!==K){$[0]=J;e:for(var H=0,te=$.length,he=te>>>1;H<he;){var Pe=2*(H+1)-1,ue=$[Pe],Ae=Pe+1,ze=$[Ae];if(0>s(ue,J))Ae<te&&0>s(ze,ue)?($[H]=ze,$[Ae]=J,H=Ae):($[H]=ue,$[Pe]=J,H=Pe);else if(Ae<te&&0>s(ze,J))$[H]=ze,$[Ae]=J,H=Ae;else break e}}return K}function s($,K){var J=$.sortIndex-K.sortIndex;return J!==0?J:$.id-K.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;n.unstable_now=function(){return o.now()}}else{var i=Date,a=i.now();n.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,h=null,p=3,m=!1,S=!1,v=!1,y=typeof setTimeout=="function"?setTimeout:null,w=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 T($){for(var K=t(c);K!==null;){if(K.callback===null)r(c);else if(K.startTime<=$)r(c),K.sortIndex=K.expirationTime,e(l,K);else break;K=t(c)}}function E($){if(v=!1,T($),!S)if(t(l)!==null)S=!0,G(_);else{var K=t(c);K!==null&&q(E,K.startTime-$)}}function _($,K){S=!1,v&&(v=!1,w(D),D=-1),m=!0;var J=p;try{for(T(K),h=t(l);h!==null&&(!(h.expirationTime>K)||$&&!V());){var H=h.callback;if(typeof H=="function"){h.callback=null,p=h.priorityLevel;var te=H(h.expirationTime<=K);K=n.unstable_now(),typeof te=="function"?h.callback=te:h===t(l)&&r(l),T(K)}else r(l);h=t(l)}if(h!==null)var he=!0;else{var Pe=t(c);Pe!==null&&q(E,Pe.startTime-K),he=!1}return he}finally{h=null,p=J,m=!1}}var A=!1,O=null,D=-1,F=5,U=-1;function V(){return!(n.unstable_now()-U<F)}function Y(){if(O!==null){var $=n.unstable_now();U=$;var K=!0;try{K=O(!0,$)}finally{K?j():(A=!1,O=null)}}else A=!1}var j;if(typeof C=="function")j=function(){C(Y)};else if(typeof MessageChannel<"u"){var N=new MessageChannel,z=N.port2;N.port1.onmessage=Y,j=function(){z.postMessage(null)}}else j=function(){y(Y,0)};function G($){O=$,A||(A=!0,j())}function q($,K){D=y(function(){$(n.unstable_now())},K)}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(){S||m||(S=!0,G(_))},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"):F=0<$?Math.floor(1e3/$):5},n.unstable_getCurrentPriorityLevel=function(){return p},n.unstable_getFirstCallbackNode=function(){return t(l)},n.unstable_next=function($){switch(p){case 1:case 2:case 3:var K=3;break;default:K=p}var J=p;p=K;try{return $()}finally{p=J}},n.unstable_pauseExecution=function(){},n.unstable_requestPaint=function(){},n.unstable_runWithPriority=function($,K){switch($){case 1:case 2:case 3:case 4:case 5:break;default:$=3}var J=p;p=$;try{return K()}finally{p=J}},n.unstable_scheduleCallback=function($,K,J){var H=n.unstable_now();switch(typeof J=="object"&&J!==null?(J=J.delay,J=typeof J=="number"&&0<J?H+J:H):J=H,$){case 1:var te=-1;break;case 2:te=250;break;case 5:te=1073741823;break;case 4:te=1e4;break;default:te=5e3}return te=J+te,$={id:u++,callback:K,priorityLevel:$,startTime:J,expirationTime:te,sortIndex:-1},J>H?($.sortIndex=J,e(c,$),t(l)===null&&$===t(c)&&(v?(w(D),D=-1):v=!0,q(E,J-H))):($.sortIndex=te,e(l,$),S||m||(S=!0,G(_))),$},n.unstable_shouldYield=V,n.unstable_wrapCallback=function($){var K=p;return function(){var J=p;p=K;try{return $.apply(this,arguments)}finally{p=J}}}}(wb)),wb}var UA;function RG(){return UA||(UA=1,vb.exports=OG()),vb.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 HA;function DG(){if(HA)return ks;HA=1;var n=aI(),e=RG();function t(d){for(var f="https://reactjs.org/docs/error-decoder.html?invariant="+d,x=1;x<arguments.length;x++)f+="&args[]="+encodeURIComponent(arguments[x]);return"Minified React error #"+d+"; visit "+f+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var r=new Set,s={};function o(d,f){i(d,f),i(d+"Capture",f)}function i(d,f){for(s[d]=f,d=0;d<f.length;d++)r.add(f[d])}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]*$/,u={},h={};function p(d){return l.call(h,d)?!0:l.call(u,d)?!1:c.test(d)?h[d]=!0:(u[d]=!0,!1)}function m(d,f,x,b){if(x!==null&&x.type===0)return!1;switch(typeof f){case"function":case"symbol":return!0;case"boolean":return b?!1:x!==null?!x.acceptsBooleans:(d=d.toLowerCase().slice(0,5),d!=="data-"&&d!=="aria-");default:return!1}}function S(d,f,x,b){if(f===null||typeof f>"u"||m(d,f,x,b))return!0;if(b)return!1;if(x!==null)switch(x.type){case 3:return!f;case 4:return f===!1;case 5:return isNaN(f);case 6:return isNaN(f)||1>f}return!1}function v(d,f,x,b,I,M,L){this.acceptsBooleans=f===2||f===3||f===4,this.attributeName=b,this.attributeNamespace=I,this.mustUseProperty=x,this.propertyName=d,this.type=f,this.sanitizeURL=M,this.removeEmptyString=L}var y={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(d){y[d]=new v(d,0,!1,d,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(d){var f=d[0];y[f]=new v(f,1,!1,d[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(d){y[d]=new v(d,2,!1,d.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(d){y[d]=new v(d,2,!1,d,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(d){y[d]=new v(d,3,!1,d.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(d){y[d]=new v(d,3,!0,d,null,!1,!1)}),["capture","download"].forEach(function(d){y[d]=new v(d,4,!1,d,null,!1,!1)}),["cols","rows","size","span"].forEach(function(d){y[d]=new v(d,6,!1,d,null,!1,!1)}),["rowSpan","start"].forEach(function(d){y[d]=new v(d,5,!1,d.toLowerCase(),null,!1,!1)});var w=/[\-:]([a-z])/g;function C(d){return d[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(d){var f=d.replace(w,C);y[f]=new v(f,1,!1,d,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(d){var f=d.replace(w,C);y[f]=new v(f,1,!1,d,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(d){var f=d.replace(w,C);y[f]=new v(f,1,!1,d,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(d){y[d]=new v(d,1,!1,d.toLowerCase(),null,!1,!1)}),y.xlinkHref=new v("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(d){y[d]=new v(d,1,!1,d.toLowerCase(),null,!0,!0)});function T(d,f,x,b){var I=y.hasOwnProperty(f)?y[f]:null;(I!==null?I.type!==0:b||!(2<f.length)||f[0]!=="o"&&f[0]!=="O"||f[1]!=="n"&&f[1]!=="N")&&(S(f,x,I,b)&&(x=null),b||I===null?p(f)&&(x===null?d.removeAttribute(f):d.setAttribute(f,""+x)):I.mustUseProperty?d[I.propertyName]=x===null?I.type===3?!1:"":x:(f=I.attributeName,b=I.attributeNamespace,x===null?d.removeAttribute(f):(I=I.type,x=I===3||I===4&&x===!0?"":""+x,b?d.setAttributeNS(b,f,x):d.setAttribute(f,x))))}var E=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,_=Symbol.for("react.element"),A=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),U=Symbol.for("react.provider"),V=Symbol.for("react.context"),Y=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),N=Symbol.for("react.suspense_list"),z=Symbol.for("react.memo"),G=Symbol.for("react.lazy"),q=Symbol.for("react.offscreen"),$=Symbol.iterator;function K(d){return d===null||typeof d!="object"?null:(d=$&&d[$]||d["@@iterator"],typeof d=="function"?d:null)}var J=Object.assign,H;function te(d){if(H===void 0)try{throw Error()}catch(x){var f=x.stack.trim().match(/\n( *(at )?)/);H=f&&f[1]||""}return`
34
+ `+H+d}var he=!1;function Pe(d,f){if(!d||he)return"";he=!0;var x=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(f)if(f=function(){throw Error()},Object.defineProperty(f.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(f,[])}catch(ie){var b=ie}Reflect.construct(d,[],f)}else{try{f.call()}catch(ie){b=ie}d.call(f.prototype)}else{try{throw Error()}catch(ie){b=ie}d()}}catch(ie){if(ie&&b&&typeof ie.stack=="string"){for(var I=ie.stack.split(`
35
+ `),M=b.stack.split(`
36
+ `),L=I.length-1,W=M.length-1;1<=L&&0<=W&&I[L]!==M[W];)W--;for(;1<=L&&0<=W;L--,W--)if(I[L]!==M[W]){if(L!==1||W!==1)do if(L--,W--,0>W||I[L]!==M[W]){var X=`
37
+ `+I[L].replace(" at new "," at ");return d.displayName&&X.includes("<anonymous>")&&(X=X.replace("<anonymous>",d.displayName)),X}while(1<=L&&0<=W);break}}}finally{he=!1,Error.prepareStackTrace=x}return(d=d?d.displayName||d.name:"")?te(d):""}function ue(d){switch(d.tag){case 5:return te(d.type);case 16:return te("Lazy");case 13:return te("Suspense");case 19:return te("SuspenseList");case 0:case 2:case 15:return d=Pe(d.type,!1),d;case 11:return d=Pe(d.type.render,!1),d;case 1:return d=Pe(d.type,!0),d;default:return""}}function Ae(d){if(d==null)return null;if(typeof d=="function")return d.displayName||d.name||null;if(typeof d=="string")return d;switch(d){case O:return"Fragment";case A:return"Portal";case F:return"Profiler";case D:return"StrictMode";case j:return"Suspense";case N:return"SuspenseList"}if(typeof d=="object")switch(d.$$typeof){case V:return(d.displayName||"Context")+".Consumer";case U:return(d._context.displayName||"Context")+".Provider";case Y:var f=d.render;return d=d.displayName,d||(d=f.displayName||f.name||"",d=d!==""?"ForwardRef("+d+")":"ForwardRef"),d;case z:return f=d.displayName||null,f!==null?f:Ae(d.type)||"Memo";case G:f=d._payload,d=d._init;try{return Ae(d(f))}catch{}}return null}function ze(d){var f=d.type;switch(d.tag){case 24:return"Cache";case 9:return(f.displayName||"Context")+".Consumer";case 10:return(f._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return d=f.render,d=d.displayName||d.name||"",f.displayName||(d!==""?"ForwardRef("+d+")":"ForwardRef");case 7:return"Fragment";case 5:return f;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Ae(f);case 8:return f===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 f=="function")return f.displayName||f.name||null;if(typeof f=="string")return f}return null}function ve(d){switch(typeof d){case"boolean":case"number":case"string":case"undefined":return d;case"object":return d;default:return""}}function Te(d){var f=d.type;return(d=d.nodeName)&&d.toLowerCase()==="input"&&(f==="checkbox"||f==="radio")}function je(d){var f=Te(d)?"checked":"value",x=Object.getOwnPropertyDescriptor(d.constructor.prototype,f),b=""+d[f];if(!d.hasOwnProperty(f)&&typeof x<"u"&&typeof x.get=="function"&&typeof x.set=="function"){var I=x.get,M=x.set;return Object.defineProperty(d,f,{configurable:!0,get:function(){return I.call(this)},set:function(L){b=""+L,M.call(this,L)}}),Object.defineProperty(d,f,{enumerable:x.enumerable}),{getValue:function(){return b},setValue:function(L){b=""+L},stopTracking:function(){d._valueTracker=null,delete d[f]}}}}function At(d){d._valueTracker||(d._valueTracker=je(d))}function on(d){if(!d)return!1;var f=d._valueTracker;if(!f)return!0;var x=f.getValue(),b="";return d&&(b=Te(d)?d.checked?"true":"false":d.value),d=b,d!==x?(f.setValue(d),!0):!1}function _t(d){if(d=d||(typeof document<"u"?document:void 0),typeof d>"u")return null;try{return d.activeElement||d.body}catch{return d.body}}function Ot(d,f){var x=f.checked;return J({},f,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:x??d._wrapperState.initialChecked})}function an(d,f){var x=f.defaultValue==null?"":f.defaultValue,b=f.checked!=null?f.checked:f.defaultChecked;x=ve(f.value!=null?f.value:x),d._wrapperState={initialChecked:b,initialValue:x,controlled:f.type==="checkbox"||f.type==="radio"?f.checked!=null:f.value!=null}}function rr(d,f){f=f.checked,f!=null&&T(d,"checked",f,!1)}function Hr(d,f){rr(d,f);var x=ve(f.value),b=f.type;if(x!=null)b==="number"?(x===0&&d.value===""||d.value!=x)&&(d.value=""+x):d.value!==""+x&&(d.value=""+x);else if(b==="submit"||b==="reset"){d.removeAttribute("value");return}f.hasOwnProperty("value")?$n(d,f.type,x):f.hasOwnProperty("defaultValue")&&$n(d,f.type,ve(f.defaultValue)),f.checked==null&&f.defaultChecked!=null&&(d.defaultChecked=!!f.defaultChecked)}function zs(d,f,x){if(f.hasOwnProperty("value")||f.hasOwnProperty("defaultValue")){var b=f.type;if(!(b!=="submit"&&b!=="reset"||f.value!==void 0&&f.value!==null))return;f=""+d._wrapperState.initialValue,x||f===d.value||(d.value=f),d.defaultValue=f}x=d.name,x!==""&&(d.name=""),d.defaultChecked=!!d._wrapperState.initialChecked,x!==""&&(d.name=x)}function $n(d,f,x){(f!=="number"||_t(d.ownerDocument)!==d)&&(x==null?d.defaultValue=""+d._wrapperState.initialValue:d.defaultValue!==""+x&&(d.defaultValue=""+x))}var ps=Array.isArray;function gs(d,f,x,b){if(d=d.options,f){f={};for(var I=0;I<x.length;I++)f["$"+x[I]]=!0;for(x=0;x<d.length;x++)I=f.hasOwnProperty("$"+d[x].value),d[x].selected!==I&&(d[x].selected=I),I&&b&&(d[x].defaultSelected=!0)}else{for(x=""+ve(x),f=null,I=0;I<d.length;I++){if(d[I].value===x){d[I].selected=!0,b&&(d[I].defaultSelected=!0);return}f!==null||d[I].disabled||(f=d[I])}f!==null&&(f.selected=!0)}}function wc(d,f){if(f.dangerouslySetInnerHTML!=null)throw Error(t(91));return J({},f,{value:void 0,defaultValue:void 0,children:""+d._wrapperState.initialValue})}function Nu(d,f){var x=f.value;if(x==null){if(x=f.children,f=f.defaultValue,x!=null){if(f!=null)throw Error(t(92));if(ps(x)){if(1<x.length)throw Error(t(93));x=x[0]}f=x}f==null&&(f=""),x=f}d._wrapperState={initialValue:ve(x)}}function Fu(d,f){var x=ve(f.value),b=ve(f.defaultValue);x!=null&&(x=""+x,x!==d.value&&(d.value=x),f.defaultValue==null&&d.defaultValue!==x&&(d.defaultValue=x)),b!=null&&(d.defaultValue=""+b)}function zu(d){var f=d.textContent;f===d._wrapperState.initialValue&&f!==""&&f!==null&&(d.value=f)}function Bu(d){switch(d){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 Pi(d,f){return d==null||d==="http://www.w3.org/1999/xhtml"?Bu(f):d==="http://www.w3.org/2000/svg"&&f==="foreignObject"?"http://www.w3.org/1999/xhtml":d}var Vo,bc=function(d){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(f,x,b,I){MSApp.execUnsafeLocalFunction(function(){return d(f,x,b,I)})}:d}(function(d,f){if(d.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in d)d.innerHTML=f;else{for(Vo=Vo||document.createElement("div"),Vo.innerHTML="<svg>"+f.valueOf().toString()+"</svg>",f=Vo.firstChild;d.firstChild;)d.removeChild(d.firstChild);for(;f.firstChild;)d.appendChild(f.firstChild)}});function ae(d,f){if(f){var x=d.firstChild;if(x&&x===d.lastChild&&x.nodeType===3){x.nodeValue=f;return}}d.textContent=f}var Ce={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},Je=["Webkit","ms","Moz","O"];Object.keys(Ce).forEach(function(d){Je.forEach(function(f){f=f+d.charAt(0).toUpperCase()+d.substring(1),Ce[f]=Ce[d]})});function jt(d,f,x){return f==null||typeof f=="boolean"||f===""?"":x||typeof f!="number"||f===0||Ce.hasOwnProperty(d)&&Ce[d]?(""+f).trim():f+"px"}function po(d,f){d=d.style;for(var x in f)if(f.hasOwnProperty(x)){var b=x.indexOf("--")===0,I=jt(x,f[x],b);x==="float"&&(x="cssFloat"),b?d.setProperty(x,I):d[x]=I}}var ms=J({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 aa(d,f){if(f){if(ms[d]&&(f.children!=null||f.dangerouslySetInnerHTML!=null))throw Error(t(137,d));if(f.dangerouslySetInnerHTML!=null){if(f.children!=null)throw Error(t(60));if(typeof f.dangerouslySetInnerHTML!="object"||!("__html"in f.dangerouslySetInnerHTML))throw Error(t(61))}if(f.style!=null&&typeof f.style!="object")throw Error(t(62))}}function Bs(d,f){if(d.indexOf("-")===-1)return typeof f.is=="string";switch(d){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var $s=null;function ys(d){return d=d.target||d.srcElement||window,d.correspondingUseElement&&(d=d.correspondingUseElement),d.nodeType===3?d.parentNode:d}var Us=null,Ss=null,Go=null;function $u(d){if(d=of(d)){if(typeof Us!="function")throw Error(t(280));var f=d.stateNode;f&&(f=dm(f),Us(d.stateNode,d.type,f))}}function al(d){Ss?Go?Go.push(d):Go=[d]:Ss=d}function Uu(){if(Ss){var d=Ss,f=Go;if(Go=Ss=null,$u(d),f)for(d=0;d<f.length;d++)$u(f[d])}}function Hu(d,f){return d(f)}function Ku(){}var la=!1;function Vg(d,f,x){if(la)return d(f,x);la=!0;try{return Hu(d,f,x)}finally{la=!1,(Ss!==null||Go!==null)&&(Ku(),Uu())}}function Cc(d,f){var x=d.stateNode;if(x===null)return null;var b=dm(x);if(b===null)return null;x=b[f];e:switch(f){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(b=!b.disabled)||(d=d.type,b=!(d==="button"||d==="input"||d==="select"||d==="textarea")),d=!b;break e;default:d=!1}if(d)return null;if(x&&typeof x!="function")throw Error(t(231,f,typeof x));return x}var Bh=!1;if(a)try{var Pc={};Object.defineProperty(Pc,"passive",{get:function(){Bh=!0}}),window.addEventListener("test",Pc,Pc),window.removeEventListener("test",Pc,Pc)}catch{Bh=!1}function Ov(d,f,x,b,I,M,L,W,X){var ie=Array.prototype.slice.call(arguments,3);try{f.apply(x,ie)}catch(ge){this.onError(ge)}}var ll=!1,cl=null,go=!1,$h=null,Rv={onError:function(d){ll=!0,cl=d}};function Dv(d,f,x,b,I,M,L,W,X){ll=!1,cl=null,Ov.apply(Rv,arguments)}function jv(d,f,x,b,I,M,L,W,X){if(Dv.apply(this,arguments),ll){if(ll){var ie=cl;ll=!1,cl=null}else throw Error(t(198));go||(go=!0,$h=ie)}}function ca(d){var f=d,x=d;if(d.alternate)for(;f.return;)f=f.return;else{d=f;do f=d,(f.flags&4098)!==0&&(x=f.return),d=f.return;while(d)}return f.tag===3?x:null}function mo(d){if(d.tag===13){var f=d.memoizedState;if(f===null&&(d=d.alternate,d!==null&&(f=d.memoizedState)),f!==null)return f.dehydrated}return null}function Gg(d){if(ca(d)!==d)throw Error(t(188))}function Lv(d){var f=d.alternate;if(!f){if(f=ca(d),f===null)throw Error(t(188));return f!==d?null:d}for(var x=d,b=f;;){var I=x.return;if(I===null)break;var M=I.alternate;if(M===null){if(b=I.return,b!==null){x=b;continue}break}if(I.child===M.child){for(M=I.child;M;){if(M===x)return Gg(I),d;if(M===b)return Gg(I),f;M=M.sibling}throw Error(t(188))}if(x.return!==b.return)x=I,b=M;else{for(var L=!1,W=I.child;W;){if(W===x){L=!0,x=I,b=M;break}if(W===b){L=!0,b=I,x=M;break}W=W.sibling}if(!L){for(W=M.child;W;){if(W===x){L=!0,x=M,b=I;break}if(W===b){L=!0,b=M,x=I;break}W=W.sibling}if(!L)throw Error(t(189))}}if(x.alternate!==b)throw Error(t(190))}if(x.tag!==3)throw Error(t(188));return x.stateNode.current===x?d:f}function qg(d){return d=Lv(d),d!==null?Yg(d):null}function Yg(d){if(d.tag===5||d.tag===6)return d;for(d=d.child;d!==null;){var f=Yg(d);if(f!==null)return f;d=d.sibling}return null}var Xg=e.unstable_scheduleCallback,ki=e.unstable_cancelCallback,Nv=e.unstable_shouldYield,Fv=e.unstable_requestPaint,ln=e.unstable_now,zv=e.unstable_getCurrentPriorityLevel,Uh=e.unstable_ImmediatePriority,kc=e.unstable_UserBlockingPriority,Wu=e.unstable_NormalPriority,Bv=e.unstable_LowPriority,qo=e.unstable_IdlePriority,Vu=null,yo=null;function $v(d){if(yo&&typeof yo.onCommitFiberRoot=="function")try{yo.onCommitFiberRoot(Vu,d,void 0,(d.current.flags&128)===128)}catch{}}var Hs=Math.clz32?Math.clz32:Gu,Uv=Math.log,Hv=Math.LN2;function Gu(d){return d>>>=0,d===0?32:31-(Uv(d)/Hv|0)|0}var qu=64,Ei=4194304;function ul(d){switch(d&-d){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 d&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return d&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return d}}function Ec(d,f){var x=d.pendingLanes;if(x===0)return 0;var b=0,I=d.suspendedLanes,M=d.pingedLanes,L=x&268435455;if(L!==0){var W=L&~I;W!==0?b=ul(W):(M&=L,M!==0&&(b=ul(M)))}else L=x&~I,L!==0?b=ul(L):M!==0&&(b=ul(M));if(b===0)return 0;if(f!==0&&f!==b&&(f&I)===0&&(I=b&-b,M=f&-f,I>=M||I===16&&(M&4194240)!==0))return f;if((b&4)!==0&&(b|=x&16),f=d.entangledLanes,f!==0)for(d=d.entanglements,f&=b;0<f;)x=31-Hs(f),I=1<<x,b|=d[x],f&=~I;return b}function Kv(d,f){switch(d){case 1:case 2:case 4:return f+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 f+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 Wv(d,f){for(var x=d.suspendedLanes,b=d.pingedLanes,I=d.expirationTimes,M=d.pendingLanes;0<M;){var L=31-Hs(M),W=1<<L,X=I[L];X===-1?((W&x)===0||(W&b)!==0)&&(I[L]=Kv(W,f)):X<=f&&(d.expiredLanes|=W),M&=~W}}function Hh(d){return d=d.pendingLanes&-1073741825,d!==0?d:d&1073741824?1073741824:0}function Zg(){var d=qu;return qu<<=1,(qu&4194240)===0&&(qu=64),d}function Yu(d){for(var f=[],x=0;31>x;x++)f.push(d);return f}function Ic(d,f,x){d.pendingLanes|=f,f!==536870912&&(d.suspendedLanes=0,d.pingedLanes=0),d=d.eventTimes,f=31-Hs(f),d[f]=x}function Vv(d,f){var x=d.pendingLanes&~f;d.pendingLanes=f,d.suspendedLanes=0,d.pingedLanes=0,d.expiredLanes&=f,d.mutableReadLanes&=f,d.entangledLanes&=f,f=d.entanglements;var b=d.eventTimes;for(d=d.expirationTimes;0<x;){var I=31-Hs(x),M=1<<I;f[I]=0,b[I]=-1,d[I]=-1,x&=~M}}function Xu(d,f){var x=d.entangledLanes|=f;for(d=d.entanglements;x;){var b=31-Hs(x),I=1<<b;I&f|d[b]&f&&(d[b]|=f),x&=~I}}var wt=0;function ua(d){return d&=-d,1<d?4<d?(d&268435455)!==0?16:536870912:4:1}var Jg,Kh,Yo,Qg,em,Wh=!1,Zu=[],Ii=null,vr=null,Xo=null,Tc=new Map,Ti=new Map,_i=[],Vh="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 tm(d,f){switch(d){case"focusin":case"focusout":Ii=null;break;case"dragenter":case"dragleave":vr=null;break;case"mouseover":case"mouseout":Xo=null;break;case"pointerover":case"pointerout":Tc.delete(f.pointerId);break;case"gotpointercapture":case"lostpointercapture":Ti.delete(f.pointerId)}}function dl(d,f,x,b,I,M){return d===null||d.nativeEvent!==M?(d={blockedOn:f,domEventName:x,eventSystemFlags:b,nativeEvent:M,targetContainers:[I]},f!==null&&(f=of(f),f!==null&&Kh(f)),d):(d.eventSystemFlags|=b,f=d.targetContainers,I!==null&&f.indexOf(I)===-1&&f.push(I),d)}function nm(d,f,x,b,I){switch(f){case"focusin":return Ii=dl(Ii,d,f,x,b,I),!0;case"dragenter":return vr=dl(vr,d,f,x,b,I),!0;case"mouseover":return Xo=dl(Xo,d,f,x,b,I),!0;case"pointerover":var M=I.pointerId;return Tc.set(M,dl(Tc.get(M)||null,d,f,x,b,I)),!0;case"gotpointercapture":return M=I.pointerId,Ti.set(M,dl(Ti.get(M)||null,d,f,x,b,I)),!0}return!1}function Gh(d){var f=Ac(d.target);if(f!==null){var x=ca(f);if(x!==null){if(f=x.tag,f===13){if(f=mo(x),f!==null){d.blockedOn=f,em(d.priority,function(){Yo(x)});return}}else if(f===3&&x.stateNode.current.memoizedState.isDehydrated){d.blockedOn=x.tag===3?x.stateNode.containerInfo:null;return}}}d.blockedOn=null}function Mi(d){if(d.blockedOn!==null)return!1;for(var f=d.targetContainers;0<f.length;){var x=Wt(d.domEventName,d.eventSystemFlags,f[0],d.nativeEvent);if(x===null){x=d.nativeEvent;var b=new x.constructor(x.type,x);$s=b,x.target.dispatchEvent(b),$s=null}else return f=of(x),f!==null&&Kh(f),d.blockedOn=x,!1;f.shift()}return!0}function qh(d,f,x){Mi(d)&&x.delete(f)}function Gv(){Wh=!1,Ii!==null&&Mi(Ii)&&(Ii=null),vr!==null&&Mi(vr)&&(vr=null),Xo!==null&&Mi(Xo)&&(Xo=null),Tc.forEach(qh),Ti.forEach(qh)}function _c(d,f){d.blockedOn===f&&(d.blockedOn=null,Wh||(Wh=!0,e.unstable_scheduleCallback(e.unstable_NormalPriority,Gv)))}function Mc(d){function f(I){return _c(I,d)}if(0<Zu.length){_c(Zu[0],d);for(var x=1;x<Zu.length;x++){var b=Zu[x];b.blockedOn===d&&(b.blockedOn=null)}}for(Ii!==null&&_c(Ii,d),vr!==null&&_c(vr,d),Xo!==null&&_c(Xo,d),Tc.forEach(f),Ti.forEach(f),x=0;x<_i.length;x++)b=_i[x],b.blockedOn===d&&(b.blockedOn=null);for(;0<_i.length&&(x=_i[0],x.blockedOn===null);)Gh(x),x.blockedOn===null&&_i.shift()}var B=E.ReactCurrentBatchConfig,ee=!0;function fe(d,f,x,b){var I=wt,M=B.transition;B.transition=null;try{wt=1,Rt(d,f,x,b)}finally{wt=I,B.transition=M}}function Oe(d,f,x,b){var I=wt,M=B.transition;B.transition=null;try{wt=4,Rt(d,f,x,b)}finally{wt=I,B.transition=M}}function Rt(d,f,x,b){if(ee){var I=Wt(d,f,x,b);if(I===null)aw(d,f,b,tt,x),tm(d,b);else if(nm(I,d,f,x,b))b.stopPropagation();else if(tm(d,b),f&4&&-1<Vh.indexOf(d)){for(;I!==null;){var M=of(I);if(M!==null&&Jg(M),M=Wt(d,f,x,b),M===null&&aw(d,f,b,tt,x),M===I)break;I=M}I!==null&&b.stopPropagation()}else aw(d,f,b,null,x)}}var tt=null;function Wt(d,f,x,b){if(tt=null,d=ys(b),d=Ac(d),d!==null)if(f=ca(d),f===null)d=null;else if(x=f.tag,x===13){if(d=mo(f),d!==null)return d;d=null}else if(x===3){if(f.stateNode.current.memoizedState.isDehydrated)return f.tag===3?f.stateNode.containerInfo:null;d=null}else f!==d&&(d=null);return tt=d,null}function wn(d){switch(d){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(zv()){case Uh:return 1;case kc:return 4;case Wu:case Bv:return 16;case qo:return 536870912;default:return 16}default:return 16}}var Vt=null,zt=null,Un=null;function xs(){if(Un)return Un;var d,f=zt,x=f.length,b,I="value"in Vt?Vt.value:Vt.textContent,M=I.length;for(d=0;d<x&&f[d]===I[d];d++);var L=x-d;for(b=1;b<=L&&f[x-b]===I[M-b];b++);return Un=I.slice(d,1<b?1-b:void 0)}function bn(d){var f=d.keyCode;return"charCode"in d?(d=d.charCode,d===0&&f===13&&(d=13)):d=f,d===10&&(d=13),32<=d||d===13?d:0}function sr(){return!0}function Kr(){return!1}function gn(d){function f(x,b,I,M,L){this._reactName=x,this._targetInst=I,this.type=b,this.nativeEvent=M,this.target=L,this.currentTarget=null;for(var W in d)d.hasOwnProperty(W)&&(x=d[W],this[W]=x?x(M):M[W]);return this.isDefaultPrevented=(M.defaultPrevented!=null?M.defaultPrevented:M.returnValue===!1)?sr:Kr,this.isPropagationStopped=Kr,this}return J(f.prototype,{preventDefault:function(){this.defaultPrevented=!0;var x=this.nativeEvent;x&&(x.preventDefault?x.preventDefault():typeof x.returnValue!="unknown"&&(x.returnValue=!1),this.isDefaultPrevented=sr)},stopPropagation:function(){var x=this.nativeEvent;x&&(x.stopPropagation?x.stopPropagation():typeof x.cancelBubble!="unknown"&&(x.cancelBubble=!0),this.isPropagationStopped=sr)},persist:function(){},isPersistent:sr}),f}var wr={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(d){return d.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Zo=gn(wr),hl=J({},wr,{view:0,detail:0}),Ju=gn(hl),fl,qv,Yh,rm=J({},hl,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Xv,button:0,buttons:0,relatedTarget:function(d){return d.relatedTarget===void 0?d.fromElement===d.srcElement?d.toElement:d.fromElement:d.relatedTarget},movementX:function(d){return"movementX"in d?d.movementX:(d!==Yh&&(Yh&&d.type==="mousemove"?(fl=d.screenX-Yh.screenX,qv=d.screenY-Yh.screenY):qv=fl=0,Yh=d),fl)},movementY:function(d){return"movementY"in d?d.movementY:qv}}),E2=gn(rm),eV=J({},rm,{dataTransfer:0}),tV=gn(eV),nV=J({},hl,{relatedTarget:0}),Yv=gn(nV),rV=J({},wr,{animationName:0,elapsedTime:0,pseudoElement:0}),sV=gn(rV),oV=J({},wr,{clipboardData:function(d){return"clipboardData"in d?d.clipboardData:window.clipboardData}}),iV=gn(oV),aV=J({},wr,{data:0}),I2=gn(aV),lV={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},cV={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"},uV={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function dV(d){var f=this.nativeEvent;return f.getModifierState?f.getModifierState(d):(d=uV[d])?!!f[d]:!1}function Xv(){return dV}var hV=J({},hl,{key:function(d){if(d.key){var f=lV[d.key]||d.key;if(f!=="Unidentified")return f}return d.type==="keypress"?(d=bn(d),d===13?"Enter":String.fromCharCode(d)):d.type==="keydown"||d.type==="keyup"?cV[d.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Xv,charCode:function(d){return d.type==="keypress"?bn(d):0},keyCode:function(d){return d.type==="keydown"||d.type==="keyup"?d.keyCode:0},which:function(d){return d.type==="keypress"?bn(d):d.type==="keydown"||d.type==="keyup"?d.keyCode:0}}),fV=gn(hV),pV=J({},rm,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),T2=gn(pV),gV=J({},hl,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Xv}),mV=gn(gV),yV=J({},wr,{propertyName:0,elapsedTime:0,pseudoElement:0}),SV=gn(yV),xV=J({},rm,{deltaX:function(d){return"deltaX"in d?d.deltaX:"wheelDeltaX"in d?-d.wheelDeltaX:0},deltaY:function(d){return"deltaY"in d?d.deltaY:"wheelDeltaY"in d?-d.wheelDeltaY:"wheelDelta"in d?-d.wheelDelta:0},deltaZ:0,deltaMode:0}),vV=gn(xV),wV=[9,13,27,32],Zv=a&&"CompositionEvent"in window,Xh=null;a&&"documentMode"in document&&(Xh=document.documentMode);var bV=a&&"TextEvent"in window&&!Xh,_2=a&&(!Zv||Xh&&8<Xh&&11>=Xh),M2=" ",A2=!1;function O2(d,f){switch(d){case"keyup":return wV.indexOf(f.keyCode)!==-1;case"keydown":return f.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function R2(d){return d=d.detail,typeof d=="object"&&"data"in d?d.data:null}var Qu=!1;function CV(d,f){switch(d){case"compositionend":return R2(f);case"keypress":return f.which!==32?null:(A2=!0,M2);case"textInput":return d=f.data,d===M2&&A2?null:d;default:return null}}function PV(d,f){if(Qu)return d==="compositionend"||!Zv&&O2(d,f)?(d=xs(),Un=zt=Vt=null,Qu=!1,d):null;switch(d){case"paste":return null;case"keypress":if(!(f.ctrlKey||f.altKey||f.metaKey)||f.ctrlKey&&f.altKey){if(f.char&&1<f.char.length)return f.char;if(f.which)return String.fromCharCode(f.which)}return null;case"compositionend":return _2&&f.locale!=="ko"?null:f.data;default:return null}}var kV={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 D2(d){var f=d&&d.nodeName&&d.nodeName.toLowerCase();return f==="input"?!!kV[d.type]:f==="textarea"}function j2(d,f,x,b){al(b),f=lm(f,"onChange"),0<f.length&&(x=new Zo("onChange","change",null,x,b),d.push({event:x,listeners:f}))}var Zh=null,Jh=null;function EV(d){Q2(d,0)}function sm(d){var f=sd(d);if(on(f))return d}function IV(d,f){if(d==="change")return f}var L2=!1;if(a){var Jv;if(a){var Qv="oninput"in document;if(!Qv){var N2=document.createElement("div");N2.setAttribute("oninput","return;"),Qv=typeof N2.oninput=="function"}Jv=Qv}else Jv=!1;L2=Jv&&(!document.documentMode||9<document.documentMode)}function F2(){Zh&&(Zh.detachEvent("onpropertychange",z2),Jh=Zh=null)}function z2(d){if(d.propertyName==="value"&&sm(Jh)){var f=[];j2(f,Jh,d,ys(d)),Vg(EV,f)}}function TV(d,f,x){d==="focusin"?(F2(),Zh=f,Jh=x,Zh.attachEvent("onpropertychange",z2)):d==="focusout"&&F2()}function _V(d){if(d==="selectionchange"||d==="keyup"||d==="keydown")return sm(Jh)}function MV(d,f){if(d==="click")return sm(f)}function AV(d,f){if(d==="input"||d==="change")return sm(f)}function OV(d,f){return d===f&&(d!==0||1/d===1/f)||d!==d&&f!==f}var Jo=typeof Object.is=="function"?Object.is:OV;function Qh(d,f){if(Jo(d,f))return!0;if(typeof d!="object"||d===null||typeof f!="object"||f===null)return!1;var x=Object.keys(d),b=Object.keys(f);if(x.length!==b.length)return!1;for(b=0;b<x.length;b++){var I=x[b];if(!l.call(f,I)||!Jo(d[I],f[I]))return!1}return!0}function B2(d){for(;d&&d.firstChild;)d=d.firstChild;return d}function $2(d,f){var x=B2(d);d=0;for(var b;x;){if(x.nodeType===3){if(b=d+x.textContent.length,d<=f&&b>=f)return{node:x,offset:f-d};d=b}e:{for(;x;){if(x.nextSibling){x=x.nextSibling;break e}x=x.parentNode}x=void 0}x=B2(x)}}function U2(d,f){return d&&f?d===f?!0:d&&d.nodeType===3?!1:f&&f.nodeType===3?U2(d,f.parentNode):"contains"in d?d.contains(f):d.compareDocumentPosition?!!(d.compareDocumentPosition(f)&16):!1:!1}function H2(){for(var d=window,f=_t();f instanceof d.HTMLIFrameElement;){try{var x=typeof f.contentWindow.location.href=="string"}catch{x=!1}if(x)d=f.contentWindow;else break;f=_t(d.document)}return f}function ew(d){var f=d&&d.nodeName&&d.nodeName.toLowerCase();return f&&(f==="input"&&(d.type==="text"||d.type==="search"||d.type==="tel"||d.type==="url"||d.type==="password")||f==="textarea"||d.contentEditable==="true")}function RV(d){var f=H2(),x=d.focusedElem,b=d.selectionRange;if(f!==x&&x&&x.ownerDocument&&U2(x.ownerDocument.documentElement,x)){if(b!==null&&ew(x)){if(f=b.start,d=b.end,d===void 0&&(d=f),"selectionStart"in x)x.selectionStart=f,x.selectionEnd=Math.min(d,x.value.length);else if(d=(f=x.ownerDocument||document)&&f.defaultView||window,d.getSelection){d=d.getSelection();var I=x.textContent.length,M=Math.min(b.start,I);b=b.end===void 0?M:Math.min(b.end,I),!d.extend&&M>b&&(I=b,b=M,M=I),I=$2(x,M);var L=$2(x,b);I&&L&&(d.rangeCount!==1||d.anchorNode!==I.node||d.anchorOffset!==I.offset||d.focusNode!==L.node||d.focusOffset!==L.offset)&&(f=f.createRange(),f.setStart(I.node,I.offset),d.removeAllRanges(),M>b?(d.addRange(f),d.extend(L.node,L.offset)):(f.setEnd(L.node,L.offset),d.addRange(f)))}}for(f=[],d=x;d=d.parentNode;)d.nodeType===1&&f.push({element:d,left:d.scrollLeft,top:d.scrollTop});for(typeof x.focus=="function"&&x.focus(),x=0;x<f.length;x++)d=f[x],d.element.scrollLeft=d.left,d.element.scrollTop=d.top}}var DV=a&&"documentMode"in document&&11>=document.documentMode,ed=null,tw=null,ef=null,nw=!1;function K2(d,f,x){var b=x.window===x?x.document:x.nodeType===9?x:x.ownerDocument;nw||ed==null||ed!==_t(b)||(b=ed,"selectionStart"in b&&ew(b)?b={start:b.selectionStart,end:b.selectionEnd}:(b=(b.ownerDocument&&b.ownerDocument.defaultView||window).getSelection(),b={anchorNode:b.anchorNode,anchorOffset:b.anchorOffset,focusNode:b.focusNode,focusOffset:b.focusOffset}),ef&&Qh(ef,b)||(ef=b,b=lm(tw,"onSelect"),0<b.length&&(f=new Zo("onSelect","select",null,f,x),d.push({event:f,listeners:b}),f.target=ed)))}function om(d,f){var x={};return x[d.toLowerCase()]=f.toLowerCase(),x["Webkit"+d]="webkit"+f,x["Moz"+d]="moz"+f,x}var td={animationend:om("Animation","AnimationEnd"),animationiteration:om("Animation","AnimationIteration"),animationstart:om("Animation","AnimationStart"),transitionend:om("Transition","TransitionEnd")},rw={},W2={};a&&(W2=document.createElement("div").style,"AnimationEvent"in window||(delete td.animationend.animation,delete td.animationiteration.animation,delete td.animationstart.animation),"TransitionEvent"in window||delete td.transitionend.transition);function im(d){if(rw[d])return rw[d];if(!td[d])return d;var f=td[d],x;for(x in f)if(f.hasOwnProperty(x)&&x in W2)return rw[d]=f[x];return d}var V2=im("animationend"),G2=im("animationiteration"),q2=im("animationstart"),Y2=im("transitionend"),X2=new Map,Z2="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 pl(d,f){X2.set(d,f),o(f,[d])}for(var sw=0;sw<Z2.length;sw++){var ow=Z2[sw],jV=ow.toLowerCase(),LV=ow[0].toUpperCase()+ow.slice(1);pl(jV,"on"+LV)}pl(V2,"onAnimationEnd"),pl(G2,"onAnimationIteration"),pl(q2,"onAnimationStart"),pl("dblclick","onDoubleClick"),pl("focusin","onFocus"),pl("focusout","onBlur"),pl(Y2,"onTransitionEnd"),i("onMouseEnter",["mouseout","mouseover"]),i("onMouseLeave",["mouseout","mouseover"]),i("onPointerEnter",["pointerout","pointerover"]),i("onPointerLeave",["pointerout","pointerover"]),o("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),o("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),o("onBeforeInput",["compositionend","keypress","textInput","paste"]),o("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),o("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),o("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var tf="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(" "),NV=new Set("cancel close invalid load scroll toggle".split(" ").concat(tf));function J2(d,f,x){var b=d.type||"unknown-event";d.currentTarget=x,jv(b,f,void 0,d),d.currentTarget=null}function Q2(d,f){f=(f&4)!==0;for(var x=0;x<d.length;x++){var b=d[x],I=b.event;b=b.listeners;e:{var M=void 0;if(f)for(var L=b.length-1;0<=L;L--){var W=b[L],X=W.instance,ie=W.currentTarget;if(W=W.listener,X!==M&&I.isPropagationStopped())break e;J2(I,W,ie),M=X}else for(L=0;L<b.length;L++){if(W=b[L],X=W.instance,ie=W.currentTarget,W=W.listener,X!==M&&I.isPropagationStopped())break e;J2(I,W,ie),M=X}}}if(go)throw d=$h,go=!1,$h=null,d}function Xt(d,f){var x=f[fw];x===void 0&&(x=f[fw]=new Set);var b=d+"__bubble";x.has(b)||(eM(f,d,2,!1),x.add(b))}function iw(d,f,x){var b=0;f&&(b|=4),eM(x,d,b,f)}var am="_reactListening"+Math.random().toString(36).slice(2);function nf(d){if(!d[am]){d[am]=!0,r.forEach(function(x){x!=="selectionchange"&&(NV.has(x)||iw(x,!1,d),iw(x,!0,d))});var f=d.nodeType===9?d:d.ownerDocument;f===null||f[am]||(f[am]=!0,iw("selectionchange",!1,f))}}function eM(d,f,x,b){switch(wn(f)){case 1:var I=fe;break;case 4:I=Oe;break;default:I=Rt}x=I.bind(null,f,x,d),I=void 0,!Bh||f!=="touchstart"&&f!=="touchmove"&&f!=="wheel"||(I=!0),b?I!==void 0?d.addEventListener(f,x,{capture:!0,passive:I}):d.addEventListener(f,x,!0):I!==void 0?d.addEventListener(f,x,{passive:I}):d.addEventListener(f,x,!1)}function aw(d,f,x,b,I){var M=b;if((f&1)===0&&(f&2)===0&&b!==null)e:for(;;){if(b===null)return;var L=b.tag;if(L===3||L===4){var W=b.stateNode.containerInfo;if(W===I||W.nodeType===8&&W.parentNode===I)break;if(L===4)for(L=b.return;L!==null;){var X=L.tag;if((X===3||X===4)&&(X=L.stateNode.containerInfo,X===I||X.nodeType===8&&X.parentNode===I))return;L=L.return}for(;W!==null;){if(L=Ac(W),L===null)return;if(X=L.tag,X===5||X===6){b=M=L;continue e}W=W.parentNode}}b=b.return}Vg(function(){var ie=M,ge=ys(x),Se=[];e:{var pe=X2.get(d);if(pe!==void 0){var Me=Zo,Ne=d;switch(d){case"keypress":if(bn(x)===0)break e;case"keydown":case"keyup":Me=fV;break;case"focusin":Ne="focus",Me=Yv;break;case"focusout":Ne="blur",Me=Yv;break;case"beforeblur":case"afterblur":Me=Yv;break;case"click":if(x.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":Me=E2;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Me=tV;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Me=mV;break;case V2:case G2:case q2:Me=sV;break;case Y2:Me=SV;break;case"scroll":Me=Ju;break;case"wheel":Me=vV;break;case"copy":case"cut":case"paste":Me=iV;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Me=T2}var Be=(f&4)!==0,Cn=!Be&&d==="scroll",re=Be?pe!==null?pe+"Capture":null:pe;Be=[];for(var Z=ie,oe;Z!==null;){oe=Z;var we=oe.stateNode;if(oe.tag===5&&we!==null&&(oe=we,re!==null&&(we=Cc(Z,re),we!=null&&Be.push(rf(Z,we,oe)))),Cn)break;Z=Z.return}0<Be.length&&(pe=new Me(pe,Ne,null,x,ge),Se.push({event:pe,listeners:Be}))}}if((f&7)===0){e:{if(pe=d==="mouseover"||d==="pointerover",Me=d==="mouseout"||d==="pointerout",pe&&x!==$s&&(Ne=x.relatedTarget||x.fromElement)&&(Ac(Ne)||Ne[da]))break e;if((Me||pe)&&(pe=ge.window===ge?ge:(pe=ge.ownerDocument)?pe.defaultView||pe.parentWindow:window,Me?(Ne=x.relatedTarget||x.toElement,Me=ie,Ne=Ne?Ac(Ne):null,Ne!==null&&(Cn=ca(Ne),Ne!==Cn||Ne.tag!==5&&Ne.tag!==6)&&(Ne=null)):(Me=null,Ne=ie),Me!==Ne)){if(Be=E2,we="onMouseLeave",re="onMouseEnter",Z="mouse",(d==="pointerout"||d==="pointerover")&&(Be=T2,we="onPointerLeave",re="onPointerEnter",Z="pointer"),Cn=Me==null?pe:sd(Me),oe=Ne==null?pe:sd(Ne),pe=new Be(we,Z+"leave",Me,x,ge),pe.target=Cn,pe.relatedTarget=oe,we=null,Ac(ge)===ie&&(Be=new Be(re,Z+"enter",Ne,x,ge),Be.target=oe,Be.relatedTarget=Cn,we=Be),Cn=we,Me&&Ne)t:{for(Be=Me,re=Ne,Z=0,oe=Be;oe;oe=nd(oe))Z++;for(oe=0,we=re;we;we=nd(we))oe++;for(;0<Z-oe;)Be=nd(Be),Z--;for(;0<oe-Z;)re=nd(re),oe--;for(;Z--;){if(Be===re||re!==null&&Be===re.alternate)break t;Be=nd(Be),re=nd(re)}Be=null}else Be=null;Me!==null&&tM(Se,pe,Me,Be,!1),Ne!==null&&Cn!==null&&tM(Se,Cn,Ne,Be,!0)}}e:{if(pe=ie?sd(ie):window,Me=pe.nodeName&&pe.nodeName.toLowerCase(),Me==="select"||Me==="input"&&pe.type==="file")var Ue=IV;else if(D2(pe))if(L2)Ue=AV;else{Ue=_V;var qe=TV}else(Me=pe.nodeName)&&Me.toLowerCase()==="input"&&(pe.type==="checkbox"||pe.type==="radio")&&(Ue=MV);if(Ue&&(Ue=Ue(d,ie))){j2(Se,Ue,x,ge);break e}qe&&qe(d,pe,ie),d==="focusout"&&(qe=pe._wrapperState)&&qe.controlled&&pe.type==="number"&&$n(pe,"number",pe.value)}switch(qe=ie?sd(ie):window,d){case"focusin":(D2(qe)||qe.contentEditable==="true")&&(ed=qe,tw=ie,ef=null);break;case"focusout":ef=tw=ed=null;break;case"mousedown":nw=!0;break;case"contextmenu":case"mouseup":case"dragend":nw=!1,K2(Se,x,ge);break;case"selectionchange":if(DV)break;case"keydown":case"keyup":K2(Se,x,ge)}var Ye;if(Zv)e:{switch(d){case"compositionstart":var et="onCompositionStart";break e;case"compositionend":et="onCompositionEnd";break e;case"compositionupdate":et="onCompositionUpdate";break e}et=void 0}else Qu?O2(d,x)&&(et="onCompositionEnd"):d==="keydown"&&x.keyCode===229&&(et="onCompositionStart");et&&(_2&&x.locale!=="ko"&&(Qu||et!=="onCompositionStart"?et==="onCompositionEnd"&&Qu&&(Ye=xs()):(Vt=ge,zt="value"in Vt?Vt.value:Vt.textContent,Qu=!0)),qe=lm(ie,et),0<qe.length&&(et=new I2(et,d,null,x,ge),Se.push({event:et,listeners:qe}),Ye?et.data=Ye:(Ye=R2(x),Ye!==null&&(et.data=Ye)))),(Ye=bV?CV(d,x):PV(d,x))&&(ie=lm(ie,"onBeforeInput"),0<ie.length&&(ge=new I2("onBeforeInput","beforeinput",null,x,ge),Se.push({event:ge,listeners:ie}),ge.data=Ye))}Q2(Se,f)})}function rf(d,f,x){return{instance:d,listener:f,currentTarget:x}}function lm(d,f){for(var x=f+"Capture",b=[];d!==null;){var I=d,M=I.stateNode;I.tag===5&&M!==null&&(I=M,M=Cc(d,x),M!=null&&b.unshift(rf(d,M,I)),M=Cc(d,f),M!=null&&b.push(rf(d,M,I))),d=d.return}return b}function nd(d){if(d===null)return null;do d=d.return;while(d&&d.tag!==5);return d||null}function tM(d,f,x,b,I){for(var M=f._reactName,L=[];x!==null&&x!==b;){var W=x,X=W.alternate,ie=W.stateNode;if(X!==null&&X===b)break;W.tag===5&&ie!==null&&(W=ie,I?(X=Cc(x,M),X!=null&&L.unshift(rf(x,X,W))):I||(X=Cc(x,M),X!=null&&L.push(rf(x,X,W)))),x=x.return}L.length!==0&&d.push({event:f,listeners:L})}var FV=/\r\n?/g,zV=/\u0000|\uFFFD/g;function nM(d){return(typeof d=="string"?d:""+d).replace(FV,`
38
+ `).replace(zV,"")}function cm(d,f,x){if(f=nM(f),nM(d)!==f&&x)throw Error(t(425))}function um(){}var lw=null,cw=null;function uw(d,f){return d==="textarea"||d==="noscript"||typeof f.children=="string"||typeof f.children=="number"||typeof f.dangerouslySetInnerHTML=="object"&&f.dangerouslySetInnerHTML!==null&&f.dangerouslySetInnerHTML.__html!=null}var dw=typeof setTimeout=="function"?setTimeout:void 0,BV=typeof clearTimeout=="function"?clearTimeout:void 0,rM=typeof Promise=="function"?Promise:void 0,$V=typeof queueMicrotask=="function"?queueMicrotask:typeof rM<"u"?function(d){return rM.resolve(null).then(d).catch(UV)}:dw;function UV(d){setTimeout(function(){throw d})}function hw(d,f){var x=f,b=0;do{var I=x.nextSibling;if(d.removeChild(x),I&&I.nodeType===8)if(x=I.data,x==="/$"){if(b===0){d.removeChild(I),Mc(f);return}b--}else x!=="$"&&x!=="$?"&&x!=="$!"||b++;x=I}while(x);Mc(f)}function gl(d){for(;d!=null;d=d.nextSibling){var f=d.nodeType;if(f===1||f===3)break;if(f===8){if(f=d.data,f==="$"||f==="$!"||f==="$?")break;if(f==="/$")return null}}return d}function sM(d){d=d.previousSibling;for(var f=0;d;){if(d.nodeType===8){var x=d.data;if(x==="$"||x==="$!"||x==="$?"){if(f===0)return d;f--}else x==="/$"&&f++}d=d.previousSibling}return null}var rd=Math.random().toString(36).slice(2),Ai="__reactFiber$"+rd,sf="__reactProps$"+rd,da="__reactContainer$"+rd,fw="__reactEvents$"+rd,HV="__reactListeners$"+rd,KV="__reactHandles$"+rd;function Ac(d){var f=d[Ai];if(f)return f;for(var x=d.parentNode;x;){if(f=x[da]||x[Ai]){if(x=f.alternate,f.child!==null||x!==null&&x.child!==null)for(d=sM(d);d!==null;){if(x=d[Ai])return x;d=sM(d)}return f}d=x,x=d.parentNode}return null}function of(d){return d=d[Ai]||d[da],!d||d.tag!==5&&d.tag!==6&&d.tag!==13&&d.tag!==3?null:d}function sd(d){if(d.tag===5||d.tag===6)return d.stateNode;throw Error(t(33))}function dm(d){return d[sf]||null}var pw=[],od=-1;function ml(d){return{current:d}}function Zt(d){0>od||(d.current=pw[od],pw[od]=null,od--)}function Gt(d,f){od++,pw[od]=d.current,d.current=f}var yl={},br=ml(yl),vs=ml(!1),Oc=yl;function id(d,f){var x=d.type.contextTypes;if(!x)return yl;var b=d.stateNode;if(b&&b.__reactInternalMemoizedUnmaskedChildContext===f)return b.__reactInternalMemoizedMaskedChildContext;var I={},M;for(M in x)I[M]=f[M];return b&&(d=d.stateNode,d.__reactInternalMemoizedUnmaskedChildContext=f,d.__reactInternalMemoizedMaskedChildContext=I),I}function ws(d){return d=d.childContextTypes,d!=null}function hm(){Zt(vs),Zt(br)}function oM(d,f,x){if(br.current!==yl)throw Error(t(168));Gt(br,f),Gt(vs,x)}function iM(d,f,x){var b=d.stateNode;if(f=f.childContextTypes,typeof b.getChildContext!="function")return x;b=b.getChildContext();for(var I in b)if(!(I in f))throw Error(t(108,ze(d)||"Unknown",I));return J({},x,b)}function fm(d){return d=(d=d.stateNode)&&d.__reactInternalMemoizedMergedChildContext||yl,Oc=br.current,Gt(br,d),Gt(vs,vs.current),!0}function aM(d,f,x){var b=d.stateNode;if(!b)throw Error(t(169));x?(d=iM(d,f,Oc),b.__reactInternalMemoizedMergedChildContext=d,Zt(vs),Zt(br),Gt(br,d)):Zt(vs),Gt(vs,x)}var ha=null,pm=!1,gw=!1;function lM(d){ha===null?ha=[d]:ha.push(d)}function WV(d){pm=!0,lM(d)}function Sl(){if(!gw&&ha!==null){gw=!0;var d=0,f=wt;try{var x=ha;for(wt=1;d<x.length;d++){var b=x[d];do b=b(!0);while(b!==null)}ha=null,pm=!1}catch(I){throw ha!==null&&(ha=ha.slice(d+1)),Xg(Uh,Sl),I}finally{wt=f,gw=!1}}return null}var ad=[],ld=0,gm=null,mm=0,So=[],xo=0,Rc=null,fa=1,pa="";function Dc(d,f){ad[ld++]=mm,ad[ld++]=gm,gm=d,mm=f}function cM(d,f,x){So[xo++]=fa,So[xo++]=pa,So[xo++]=Rc,Rc=d;var b=fa;d=pa;var I=32-Hs(b)-1;b&=~(1<<I),x+=1;var M=32-Hs(f)+I;if(30<M){var L=I-I%5;M=(b&(1<<L)-1).toString(32),b>>=L,I-=L,fa=1<<32-Hs(f)+I|x<<I|b,pa=M+d}else fa=1<<M|x<<I|b,pa=d}function mw(d){d.return!==null&&(Dc(d,1),cM(d,1,0))}function yw(d){for(;d===gm;)gm=ad[--ld],ad[ld]=null,mm=ad[--ld],ad[ld]=null;for(;d===Rc;)Rc=So[--xo],So[xo]=null,pa=So[--xo],So[xo]=null,fa=So[--xo],So[xo]=null}var Ks=null,Ws=null,tn=!1,Qo=null;function uM(d,f){var x=Co(5,null,null,0);x.elementType="DELETED",x.stateNode=f,x.return=d,f=d.deletions,f===null?(d.deletions=[x],d.flags|=16):f.push(x)}function dM(d,f){switch(d.tag){case 5:var x=d.type;return f=f.nodeType!==1||x.toLowerCase()!==f.nodeName.toLowerCase()?null:f,f!==null?(d.stateNode=f,Ks=d,Ws=gl(f.firstChild),!0):!1;case 6:return f=d.pendingProps===""||f.nodeType!==3?null:f,f!==null?(d.stateNode=f,Ks=d,Ws=null,!0):!1;case 13:return f=f.nodeType!==8?null:f,f!==null?(x=Rc!==null?{id:fa,overflow:pa}:null,d.memoizedState={dehydrated:f,treeContext:x,retryLane:1073741824},x=Co(18,null,null,0),x.stateNode=f,x.return=d,d.child=x,Ks=d,Ws=null,!0):!1;default:return!1}}function Sw(d){return(d.mode&1)!==0&&(d.flags&128)===0}function xw(d){if(tn){var f=Ws;if(f){var x=f;if(!dM(d,f)){if(Sw(d))throw Error(t(418));f=gl(x.nextSibling);var b=Ks;f&&dM(d,f)?uM(b,x):(d.flags=d.flags&-4097|2,tn=!1,Ks=d)}}else{if(Sw(d))throw Error(t(418));d.flags=d.flags&-4097|2,tn=!1,Ks=d}}}function hM(d){for(d=d.return;d!==null&&d.tag!==5&&d.tag!==3&&d.tag!==13;)d=d.return;Ks=d}function ym(d){if(d!==Ks)return!1;if(!tn)return hM(d),tn=!0,!1;var f;if((f=d.tag!==3)&&!(f=d.tag!==5)&&(f=d.type,f=f!=="head"&&f!=="body"&&!uw(d.type,d.memoizedProps)),f&&(f=Ws)){if(Sw(d))throw fM(),Error(t(418));for(;f;)uM(d,f),f=gl(f.nextSibling)}if(hM(d),d.tag===13){if(d=d.memoizedState,d=d!==null?d.dehydrated:null,!d)throw Error(t(317));e:{for(d=d.nextSibling,f=0;d;){if(d.nodeType===8){var x=d.data;if(x==="/$"){if(f===0){Ws=gl(d.nextSibling);break e}f--}else x!=="$"&&x!=="$!"&&x!=="$?"||f++}d=d.nextSibling}Ws=null}}else Ws=Ks?gl(d.stateNode.nextSibling):null;return!0}function fM(){for(var d=Ws;d;)d=gl(d.nextSibling)}function cd(){Ws=Ks=null,tn=!1}function vw(d){Qo===null?Qo=[d]:Qo.push(d)}var VV=E.ReactCurrentBatchConfig;function af(d,f,x){if(d=x.ref,d!==null&&typeof d!="function"&&typeof d!="object"){if(x._owner){if(x=x._owner,x){if(x.tag!==1)throw Error(t(309));var b=x.stateNode}if(!b)throw Error(t(147,d));var I=b,M=""+d;return f!==null&&f.ref!==null&&typeof f.ref=="function"&&f.ref._stringRef===M?f.ref:(f=function(L){var W=I.refs;L===null?delete W[M]:W[M]=L},f._stringRef=M,f)}if(typeof d!="string")throw Error(t(284));if(!x._owner)throw Error(t(290,d))}return d}function Sm(d,f){throw d=Object.prototype.toString.call(f),Error(t(31,d==="[object Object]"?"object with keys {"+Object.keys(f).join(", ")+"}":d))}function pM(d){var f=d._init;return f(d._payload)}function gM(d){function f(re,Z){if(d){var oe=re.deletions;oe===null?(re.deletions=[Z],re.flags|=16):oe.push(Z)}}function x(re,Z){if(!d)return null;for(;Z!==null;)f(re,Z),Z=Z.sibling;return null}function b(re,Z){for(re=new Map;Z!==null;)Z.key!==null?re.set(Z.key,Z):re.set(Z.index,Z),Z=Z.sibling;return re}function I(re,Z){return re=El(re,Z),re.index=0,re.sibling=null,re}function M(re,Z,oe){return re.index=oe,d?(oe=re.alternate,oe!==null?(oe=oe.index,oe<Z?(re.flags|=2,Z):oe):(re.flags|=2,Z)):(re.flags|=1048576,Z)}function L(re){return d&&re.alternate===null&&(re.flags|=2),re}function W(re,Z,oe,we){return Z===null||Z.tag!==6?(Z=db(oe,re.mode,we),Z.return=re,Z):(Z=I(Z,oe),Z.return=re,Z)}function X(re,Z,oe,we){var Ue=oe.type;return Ue===O?ge(re,Z,oe.props.children,we,oe.key):Z!==null&&(Z.elementType===Ue||typeof Ue=="object"&&Ue!==null&&Ue.$$typeof===G&&pM(Ue)===Z.type)?(we=I(Z,oe.props),we.ref=af(re,Z,oe),we.return=re,we):(we=Um(oe.type,oe.key,oe.props,null,re.mode,we),we.ref=af(re,Z,oe),we.return=re,we)}function ie(re,Z,oe,we){return Z===null||Z.tag!==4||Z.stateNode.containerInfo!==oe.containerInfo||Z.stateNode.implementation!==oe.implementation?(Z=hb(oe,re.mode,we),Z.return=re,Z):(Z=I(Z,oe.children||[]),Z.return=re,Z)}function ge(re,Z,oe,we,Ue){return Z===null||Z.tag!==7?(Z=Uc(oe,re.mode,we,Ue),Z.return=re,Z):(Z=I(Z,oe),Z.return=re,Z)}function Se(re,Z,oe){if(typeof Z=="string"&&Z!==""||typeof Z=="number")return Z=db(""+Z,re.mode,oe),Z.return=re,Z;if(typeof Z=="object"&&Z!==null){switch(Z.$$typeof){case _:return oe=Um(Z.type,Z.key,Z.props,null,re.mode,oe),oe.ref=af(re,null,Z),oe.return=re,oe;case A:return Z=hb(Z,re.mode,oe),Z.return=re,Z;case G:var we=Z._init;return Se(re,we(Z._payload),oe)}if(ps(Z)||K(Z))return Z=Uc(Z,re.mode,oe,null),Z.return=re,Z;Sm(re,Z)}return null}function pe(re,Z,oe,we){var Ue=Z!==null?Z.key:null;if(typeof oe=="string"&&oe!==""||typeof oe=="number")return Ue!==null?null:W(re,Z,""+oe,we);if(typeof oe=="object"&&oe!==null){switch(oe.$$typeof){case _:return oe.key===Ue?X(re,Z,oe,we):null;case A:return oe.key===Ue?ie(re,Z,oe,we):null;case G:return Ue=oe._init,pe(re,Z,Ue(oe._payload),we)}if(ps(oe)||K(oe))return Ue!==null?null:ge(re,Z,oe,we,null);Sm(re,oe)}return null}function Me(re,Z,oe,we,Ue){if(typeof we=="string"&&we!==""||typeof we=="number")return re=re.get(oe)||null,W(Z,re,""+we,Ue);if(typeof we=="object"&&we!==null){switch(we.$$typeof){case _:return re=re.get(we.key===null?oe:we.key)||null,X(Z,re,we,Ue);case A:return re=re.get(we.key===null?oe:we.key)||null,ie(Z,re,we,Ue);case G:var qe=we._init;return Me(re,Z,oe,qe(we._payload),Ue)}if(ps(we)||K(we))return re=re.get(oe)||null,ge(Z,re,we,Ue,null);Sm(Z,we)}return null}function Ne(re,Z,oe,we){for(var Ue=null,qe=null,Ye=Z,et=Z=0,Wn=null;Ye!==null&&et<oe.length;et++){Ye.index>et?(Wn=Ye,Ye=null):Wn=Ye.sibling;var Et=pe(re,Ye,oe[et],we);if(Et===null){Ye===null&&(Ye=Wn);break}d&&Ye&&Et.alternate===null&&f(re,Ye),Z=M(Et,Z,et),qe===null?Ue=Et:qe.sibling=Et,qe=Et,Ye=Wn}if(et===oe.length)return x(re,Ye),tn&&Dc(re,et),Ue;if(Ye===null){for(;et<oe.length;et++)Ye=Se(re,oe[et],we),Ye!==null&&(Z=M(Ye,Z,et),qe===null?Ue=Ye:qe.sibling=Ye,qe=Ye);return tn&&Dc(re,et),Ue}for(Ye=b(re,Ye);et<oe.length;et++)Wn=Me(Ye,re,et,oe[et],we),Wn!==null&&(d&&Wn.alternate!==null&&Ye.delete(Wn.key===null?et:Wn.key),Z=M(Wn,Z,et),qe===null?Ue=Wn:qe.sibling=Wn,qe=Wn);return d&&Ye.forEach(function(Il){return f(re,Il)}),tn&&Dc(re,et),Ue}function Be(re,Z,oe,we){var Ue=K(oe);if(typeof Ue!="function")throw Error(t(150));if(oe=Ue.call(oe),oe==null)throw Error(t(151));for(var qe=Ue=null,Ye=Z,et=Z=0,Wn=null,Et=oe.next();Ye!==null&&!Et.done;et++,Et=oe.next()){Ye.index>et?(Wn=Ye,Ye=null):Wn=Ye.sibling;var Il=pe(re,Ye,Et.value,we);if(Il===null){Ye===null&&(Ye=Wn);break}d&&Ye&&Il.alternate===null&&f(re,Ye),Z=M(Il,Z,et),qe===null?Ue=Il:qe.sibling=Il,qe=Il,Ye=Wn}if(Et.done)return x(re,Ye),tn&&Dc(re,et),Ue;if(Ye===null){for(;!Et.done;et++,Et=oe.next())Et=Se(re,Et.value,we),Et!==null&&(Z=M(Et,Z,et),qe===null?Ue=Et:qe.sibling=Et,qe=Et);return tn&&Dc(re,et),Ue}for(Ye=b(re,Ye);!Et.done;et++,Et=oe.next())Et=Me(Ye,re,et,Et.value,we),Et!==null&&(d&&Et.alternate!==null&&Ye.delete(Et.key===null?et:Et.key),Z=M(Et,Z,et),qe===null?Ue=Et:qe.sibling=Et,qe=Et);return d&&Ye.forEach(function(kG){return f(re,kG)}),tn&&Dc(re,et),Ue}function Cn(re,Z,oe,we){if(typeof oe=="object"&&oe!==null&&oe.type===O&&oe.key===null&&(oe=oe.props.children),typeof oe=="object"&&oe!==null){switch(oe.$$typeof){case _:e:{for(var Ue=oe.key,qe=Z;qe!==null;){if(qe.key===Ue){if(Ue=oe.type,Ue===O){if(qe.tag===7){x(re,qe.sibling),Z=I(qe,oe.props.children),Z.return=re,re=Z;break e}}else if(qe.elementType===Ue||typeof Ue=="object"&&Ue!==null&&Ue.$$typeof===G&&pM(Ue)===qe.type){x(re,qe.sibling),Z=I(qe,oe.props),Z.ref=af(re,qe,oe),Z.return=re,re=Z;break e}x(re,qe);break}else f(re,qe);qe=qe.sibling}oe.type===O?(Z=Uc(oe.props.children,re.mode,we,oe.key),Z.return=re,re=Z):(we=Um(oe.type,oe.key,oe.props,null,re.mode,we),we.ref=af(re,Z,oe),we.return=re,re=we)}return L(re);case A:e:{for(qe=oe.key;Z!==null;){if(Z.key===qe)if(Z.tag===4&&Z.stateNode.containerInfo===oe.containerInfo&&Z.stateNode.implementation===oe.implementation){x(re,Z.sibling),Z=I(Z,oe.children||[]),Z.return=re,re=Z;break e}else{x(re,Z);break}else f(re,Z);Z=Z.sibling}Z=hb(oe,re.mode,we),Z.return=re,re=Z}return L(re);case G:return qe=oe._init,Cn(re,Z,qe(oe._payload),we)}if(ps(oe))return Ne(re,Z,oe,we);if(K(oe))return Be(re,Z,oe,we);Sm(re,oe)}return typeof oe=="string"&&oe!==""||typeof oe=="number"?(oe=""+oe,Z!==null&&Z.tag===6?(x(re,Z.sibling),Z=I(Z,oe),Z.return=re,re=Z):(x(re,Z),Z=db(oe,re.mode,we),Z.return=re,re=Z),L(re)):x(re,Z)}return Cn}var ud=gM(!0),mM=gM(!1),xm=ml(null),vm=null,dd=null,ww=null;function bw(){ww=dd=vm=null}function Cw(d){var f=xm.current;Zt(xm),d._currentValue=f}function Pw(d,f,x){for(;d!==null;){var b=d.alternate;if((d.childLanes&f)!==f?(d.childLanes|=f,b!==null&&(b.childLanes|=f)):b!==null&&(b.childLanes&f)!==f&&(b.childLanes|=f),d===x)break;d=d.return}}function hd(d,f){vm=d,ww=dd=null,d=d.dependencies,d!==null&&d.firstContext!==null&&((d.lanes&f)!==0&&(bs=!0),d.firstContext=null)}function vo(d){var f=d._currentValue;if(ww!==d)if(d={context:d,memoizedValue:f,next:null},dd===null){if(vm===null)throw Error(t(308));dd=d,vm.dependencies={lanes:0,firstContext:d}}else dd=dd.next=d;return f}var jc=null;function kw(d){jc===null?jc=[d]:jc.push(d)}function yM(d,f,x,b){var I=f.interleaved;return I===null?(x.next=x,kw(f)):(x.next=I.next,I.next=x),f.interleaved=x,ga(d,b)}function ga(d,f){d.lanes|=f;var x=d.alternate;for(x!==null&&(x.lanes|=f),x=d,d=d.return;d!==null;)d.childLanes|=f,x=d.alternate,x!==null&&(x.childLanes|=f),x=d,d=d.return;return x.tag===3?x.stateNode:null}var xl=!1;function Ew(d){d.updateQueue={baseState:d.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function SM(d,f){d=d.updateQueue,f.updateQueue===d&&(f.updateQueue={baseState:d.baseState,firstBaseUpdate:d.firstBaseUpdate,lastBaseUpdate:d.lastBaseUpdate,shared:d.shared,effects:d.effects})}function ma(d,f){return{eventTime:d,lane:f,tag:0,payload:null,callback:null,next:null}}function vl(d,f,x){var b=d.updateQueue;if(b===null)return null;if(b=b.shared,(Ct&2)!==0){var I=b.pending;return I===null?f.next=f:(f.next=I.next,I.next=f),b.pending=f,ga(d,x)}return I=b.interleaved,I===null?(f.next=f,kw(b)):(f.next=I.next,I.next=f),b.interleaved=f,ga(d,x)}function wm(d,f,x){if(f=f.updateQueue,f!==null&&(f=f.shared,(x&4194240)!==0)){var b=f.lanes;b&=d.pendingLanes,x|=b,f.lanes=x,Xu(d,x)}}function xM(d,f){var x=d.updateQueue,b=d.alternate;if(b!==null&&(b=b.updateQueue,x===b)){var I=null,M=null;if(x=x.firstBaseUpdate,x!==null){do{var L={eventTime:x.eventTime,lane:x.lane,tag:x.tag,payload:x.payload,callback:x.callback,next:null};M===null?I=M=L:M=M.next=L,x=x.next}while(x!==null);M===null?I=M=f:M=M.next=f}else I=M=f;x={baseState:b.baseState,firstBaseUpdate:I,lastBaseUpdate:M,shared:b.shared,effects:b.effects},d.updateQueue=x;return}d=x.lastBaseUpdate,d===null?x.firstBaseUpdate=f:d.next=f,x.lastBaseUpdate=f}function bm(d,f,x,b){var I=d.updateQueue;xl=!1;var M=I.firstBaseUpdate,L=I.lastBaseUpdate,W=I.shared.pending;if(W!==null){I.shared.pending=null;var X=W,ie=X.next;X.next=null,L===null?M=ie:L.next=ie,L=X;var ge=d.alternate;ge!==null&&(ge=ge.updateQueue,W=ge.lastBaseUpdate,W!==L&&(W===null?ge.firstBaseUpdate=ie:W.next=ie,ge.lastBaseUpdate=X))}if(M!==null){var Se=I.baseState;L=0,ge=ie=X=null,W=M;do{var pe=W.lane,Me=W.eventTime;if((b&pe)===pe){ge!==null&&(ge=ge.next={eventTime:Me,lane:0,tag:W.tag,payload:W.payload,callback:W.callback,next:null});e:{var Ne=d,Be=W;switch(pe=f,Me=x,Be.tag){case 1:if(Ne=Be.payload,typeof Ne=="function"){Se=Ne.call(Me,Se,pe);break e}Se=Ne;break e;case 3:Ne.flags=Ne.flags&-65537|128;case 0:if(Ne=Be.payload,pe=typeof Ne=="function"?Ne.call(Me,Se,pe):Ne,pe==null)break e;Se=J({},Se,pe);break e;case 2:xl=!0}}W.callback!==null&&W.lane!==0&&(d.flags|=64,pe=I.effects,pe===null?I.effects=[W]:pe.push(W))}else Me={eventTime:Me,lane:pe,tag:W.tag,payload:W.payload,callback:W.callback,next:null},ge===null?(ie=ge=Me,X=Se):ge=ge.next=Me,L|=pe;if(W=W.next,W===null){if(W=I.shared.pending,W===null)break;pe=W,W=pe.next,pe.next=null,I.lastBaseUpdate=pe,I.shared.pending=null}}while(!0);if(ge===null&&(X=Se),I.baseState=X,I.firstBaseUpdate=ie,I.lastBaseUpdate=ge,f=I.shared.interleaved,f!==null){I=f;do L|=I.lane,I=I.next;while(I!==f)}else M===null&&(I.shared.lanes=0);Fc|=L,d.lanes=L,d.memoizedState=Se}}function vM(d,f,x){if(d=f.effects,f.effects=null,d!==null)for(f=0;f<d.length;f++){var b=d[f],I=b.callback;if(I!==null){if(b.callback=null,b=x,typeof I!="function")throw Error(t(191,I));I.call(b)}}}var lf={},Oi=ml(lf),cf=ml(lf),uf=ml(lf);function Lc(d){if(d===lf)throw Error(t(174));return d}function Iw(d,f){switch(Gt(uf,f),Gt(cf,d),Gt(Oi,lf),d=f.nodeType,d){case 9:case 11:f=(f=f.documentElement)?f.namespaceURI:Pi(null,"");break;default:d=d===8?f.parentNode:f,f=d.namespaceURI||null,d=d.tagName,f=Pi(f,d)}Zt(Oi),Gt(Oi,f)}function fd(){Zt(Oi),Zt(cf),Zt(uf)}function wM(d){Lc(uf.current);var f=Lc(Oi.current),x=Pi(f,d.type);f!==x&&(Gt(cf,d),Gt(Oi,x))}function Tw(d){cf.current===d&&(Zt(Oi),Zt(cf))}var cn=ml(0);function Cm(d){for(var f=d;f!==null;){if(f.tag===13){var x=f.memoizedState;if(x!==null&&(x=x.dehydrated,x===null||x.data==="$?"||x.data==="$!"))return f}else if(f.tag===19&&f.memoizedProps.revealOrder!==void 0){if((f.flags&128)!==0)return f}else if(f.child!==null){f.child.return=f,f=f.child;continue}if(f===d)break;for(;f.sibling===null;){if(f.return===null||f.return===d)return null;f=f.return}f.sibling.return=f.return,f=f.sibling}return null}var _w=[];function Mw(){for(var d=0;d<_w.length;d++)_w[d]._workInProgressVersionPrimary=null;_w.length=0}var Pm=E.ReactCurrentDispatcher,Aw=E.ReactCurrentBatchConfig,Nc=0,un=null,Ln=null,Hn=null,km=!1,df=!1,hf=0,GV=0;function Cr(){throw Error(t(321))}function Ow(d,f){if(f===null)return!1;for(var x=0;x<f.length&&x<d.length;x++)if(!Jo(d[x],f[x]))return!1;return!0}function Rw(d,f,x,b,I,M){if(Nc=M,un=f,f.memoizedState=null,f.updateQueue=null,f.lanes=0,Pm.current=d===null||d.memoizedState===null?ZV:JV,d=x(b,I),df){M=0;do{if(df=!1,hf=0,25<=M)throw Error(t(301));M+=1,Hn=Ln=null,f.updateQueue=null,Pm.current=QV,d=x(b,I)}while(df)}if(Pm.current=Tm,f=Ln!==null&&Ln.next!==null,Nc=0,Hn=Ln=un=null,km=!1,f)throw Error(t(300));return d}function Dw(){var d=hf!==0;return hf=0,d}function Ri(){var d={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Hn===null?un.memoizedState=Hn=d:Hn=Hn.next=d,Hn}function wo(){if(Ln===null){var d=un.alternate;d=d!==null?d.memoizedState:null}else d=Ln.next;var f=Hn===null?un.memoizedState:Hn.next;if(f!==null)Hn=f,Ln=d;else{if(d===null)throw Error(t(310));Ln=d,d={memoizedState:Ln.memoizedState,baseState:Ln.baseState,baseQueue:Ln.baseQueue,queue:Ln.queue,next:null},Hn===null?un.memoizedState=Hn=d:Hn=Hn.next=d}return Hn}function ff(d,f){return typeof f=="function"?f(d):f}function jw(d){var f=wo(),x=f.queue;if(x===null)throw Error(t(311));x.lastRenderedReducer=d;var b=Ln,I=b.baseQueue,M=x.pending;if(M!==null){if(I!==null){var L=I.next;I.next=M.next,M.next=L}b.baseQueue=I=M,x.pending=null}if(I!==null){M=I.next,b=b.baseState;var W=L=null,X=null,ie=M;do{var ge=ie.lane;if((Nc&ge)===ge)X!==null&&(X=X.next={lane:0,action:ie.action,hasEagerState:ie.hasEagerState,eagerState:ie.eagerState,next:null}),b=ie.hasEagerState?ie.eagerState:d(b,ie.action);else{var Se={lane:ge,action:ie.action,hasEagerState:ie.hasEagerState,eagerState:ie.eagerState,next:null};X===null?(W=X=Se,L=b):X=X.next=Se,un.lanes|=ge,Fc|=ge}ie=ie.next}while(ie!==null&&ie!==M);X===null?L=b:X.next=W,Jo(b,f.memoizedState)||(bs=!0),f.memoizedState=b,f.baseState=L,f.baseQueue=X,x.lastRenderedState=b}if(d=x.interleaved,d!==null){I=d;do M=I.lane,un.lanes|=M,Fc|=M,I=I.next;while(I!==d)}else I===null&&(x.lanes=0);return[f.memoizedState,x.dispatch]}function Lw(d){var f=wo(),x=f.queue;if(x===null)throw Error(t(311));x.lastRenderedReducer=d;var b=x.dispatch,I=x.pending,M=f.memoizedState;if(I!==null){x.pending=null;var L=I=I.next;do M=d(M,L.action),L=L.next;while(L!==I);Jo(M,f.memoizedState)||(bs=!0),f.memoizedState=M,f.baseQueue===null&&(f.baseState=M),x.lastRenderedState=M}return[M,b]}function bM(){}function CM(d,f){var x=un,b=wo(),I=f(),M=!Jo(b.memoizedState,I);if(M&&(b.memoizedState=I,bs=!0),b=b.queue,Nw(EM.bind(null,x,b,d),[d]),b.getSnapshot!==f||M||Hn!==null&&Hn.memoizedState.tag&1){if(x.flags|=2048,pf(9,kM.bind(null,x,b,I,f),void 0,null),Kn===null)throw Error(t(349));(Nc&30)!==0||PM(x,f,I)}return I}function PM(d,f,x){d.flags|=16384,d={getSnapshot:f,value:x},f=un.updateQueue,f===null?(f={lastEffect:null,stores:null},un.updateQueue=f,f.stores=[d]):(x=f.stores,x===null?f.stores=[d]:x.push(d))}function kM(d,f,x,b){f.value=x,f.getSnapshot=b,IM(f)&&TM(d)}function EM(d,f,x){return x(function(){IM(f)&&TM(d)})}function IM(d){var f=d.getSnapshot;d=d.value;try{var x=f();return!Jo(d,x)}catch{return!0}}function TM(d){var f=ga(d,1);f!==null&&ri(f,d,1,-1)}function _M(d){var f=Ri();return typeof d=="function"&&(d=d()),f.memoizedState=f.baseState=d,d={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:ff,lastRenderedState:d},f.queue=d,d=d.dispatch=XV.bind(null,un,d),[f.memoizedState,d]}function pf(d,f,x,b){return d={tag:d,create:f,destroy:x,deps:b,next:null},f=un.updateQueue,f===null?(f={lastEffect:null,stores:null},un.updateQueue=f,f.lastEffect=d.next=d):(x=f.lastEffect,x===null?f.lastEffect=d.next=d:(b=x.next,x.next=d,d.next=b,f.lastEffect=d)),d}function MM(){return wo().memoizedState}function Em(d,f,x,b){var I=Ri();un.flags|=d,I.memoizedState=pf(1|f,x,void 0,b===void 0?null:b)}function Im(d,f,x,b){var I=wo();b=b===void 0?null:b;var M=void 0;if(Ln!==null){var L=Ln.memoizedState;if(M=L.destroy,b!==null&&Ow(b,L.deps)){I.memoizedState=pf(f,x,M,b);return}}un.flags|=d,I.memoizedState=pf(1|f,x,M,b)}function AM(d,f){return Em(8390656,8,d,f)}function Nw(d,f){return Im(2048,8,d,f)}function OM(d,f){return Im(4,2,d,f)}function RM(d,f){return Im(4,4,d,f)}function DM(d,f){if(typeof f=="function")return d=d(),f(d),function(){f(null)};if(f!=null)return d=d(),f.current=d,function(){f.current=null}}function jM(d,f,x){return x=x!=null?x.concat([d]):null,Im(4,4,DM.bind(null,f,d),x)}function Fw(){}function LM(d,f){var x=wo();f=f===void 0?null:f;var b=x.memoizedState;return b!==null&&f!==null&&Ow(f,b[1])?b[0]:(x.memoizedState=[d,f],d)}function NM(d,f){var x=wo();f=f===void 0?null:f;var b=x.memoizedState;return b!==null&&f!==null&&Ow(f,b[1])?b[0]:(d=d(),x.memoizedState=[d,f],d)}function FM(d,f,x){return(Nc&21)===0?(d.baseState&&(d.baseState=!1,bs=!0),d.memoizedState=x):(Jo(x,f)||(x=Zg(),un.lanes|=x,Fc|=x,d.baseState=!0),f)}function qV(d,f){var x=wt;wt=x!==0&&4>x?x:4,d(!0);var b=Aw.transition;Aw.transition={};try{d(!1),f()}finally{wt=x,Aw.transition=b}}function zM(){return wo().memoizedState}function YV(d,f,x){var b=Pl(d);if(x={lane:b,action:x,hasEagerState:!1,eagerState:null,next:null},BM(d))$M(f,x);else if(x=yM(d,f,x,b),x!==null){var I=Vr();ri(x,d,b,I),UM(x,f,b)}}function XV(d,f,x){var b=Pl(d),I={lane:b,action:x,hasEagerState:!1,eagerState:null,next:null};if(BM(d))$M(f,I);else{var M=d.alternate;if(d.lanes===0&&(M===null||M.lanes===0)&&(M=f.lastRenderedReducer,M!==null))try{var L=f.lastRenderedState,W=M(L,x);if(I.hasEagerState=!0,I.eagerState=W,Jo(W,L)){var X=f.interleaved;X===null?(I.next=I,kw(f)):(I.next=X.next,X.next=I),f.interleaved=I;return}}catch{}finally{}x=yM(d,f,I,b),x!==null&&(I=Vr(),ri(x,d,b,I),UM(x,f,b))}}function BM(d){var f=d.alternate;return d===un||f!==null&&f===un}function $M(d,f){df=km=!0;var x=d.pending;x===null?f.next=f:(f.next=x.next,x.next=f),d.pending=f}function UM(d,f,x){if((x&4194240)!==0){var b=f.lanes;b&=d.pendingLanes,x|=b,f.lanes=x,Xu(d,x)}}var Tm={readContext:vo,useCallback:Cr,useContext:Cr,useEffect:Cr,useImperativeHandle:Cr,useInsertionEffect:Cr,useLayoutEffect:Cr,useMemo:Cr,useReducer:Cr,useRef:Cr,useState:Cr,useDebugValue:Cr,useDeferredValue:Cr,useTransition:Cr,useMutableSource:Cr,useSyncExternalStore:Cr,useId:Cr,unstable_isNewReconciler:!1},ZV={readContext:vo,useCallback:function(d,f){return Ri().memoizedState=[d,f===void 0?null:f],d},useContext:vo,useEffect:AM,useImperativeHandle:function(d,f,x){return x=x!=null?x.concat([d]):null,Em(4194308,4,DM.bind(null,f,d),x)},useLayoutEffect:function(d,f){return Em(4194308,4,d,f)},useInsertionEffect:function(d,f){return Em(4,2,d,f)},useMemo:function(d,f){var x=Ri();return f=f===void 0?null:f,d=d(),x.memoizedState=[d,f],d},useReducer:function(d,f,x){var b=Ri();return f=x!==void 0?x(f):f,b.memoizedState=b.baseState=f,d={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:d,lastRenderedState:f},b.queue=d,d=d.dispatch=YV.bind(null,un,d),[b.memoizedState,d]},useRef:function(d){var f=Ri();return d={current:d},f.memoizedState=d},useState:_M,useDebugValue:Fw,useDeferredValue:function(d){return Ri().memoizedState=d},useTransition:function(){var d=_M(!1),f=d[0];return d=qV.bind(null,d[1]),Ri().memoizedState=d,[f,d]},useMutableSource:function(){},useSyncExternalStore:function(d,f,x){var b=un,I=Ri();if(tn){if(x===void 0)throw Error(t(407));x=x()}else{if(x=f(),Kn===null)throw Error(t(349));(Nc&30)!==0||PM(b,f,x)}I.memoizedState=x;var M={value:x,getSnapshot:f};return I.queue=M,AM(EM.bind(null,b,M,d),[d]),b.flags|=2048,pf(9,kM.bind(null,b,M,x,f),void 0,null),x},useId:function(){var d=Ri(),f=Kn.identifierPrefix;if(tn){var x=pa,b=fa;x=(b&~(1<<32-Hs(b)-1)).toString(32)+x,f=":"+f+"R"+x,x=hf++,0<x&&(f+="H"+x.toString(32)),f+=":"}else x=GV++,f=":"+f+"r"+x.toString(32)+":";return d.memoizedState=f},unstable_isNewReconciler:!1},JV={readContext:vo,useCallback:LM,useContext:vo,useEffect:Nw,useImperativeHandle:jM,useInsertionEffect:OM,useLayoutEffect:RM,useMemo:NM,useReducer:jw,useRef:MM,useState:function(){return jw(ff)},useDebugValue:Fw,useDeferredValue:function(d){var f=wo();return FM(f,Ln.memoizedState,d)},useTransition:function(){var d=jw(ff)[0],f=wo().memoizedState;return[d,f]},useMutableSource:bM,useSyncExternalStore:CM,useId:zM,unstable_isNewReconciler:!1},QV={readContext:vo,useCallback:LM,useContext:vo,useEffect:Nw,useImperativeHandle:jM,useInsertionEffect:OM,useLayoutEffect:RM,useMemo:NM,useReducer:Lw,useRef:MM,useState:function(){return Lw(ff)},useDebugValue:Fw,useDeferredValue:function(d){var f=wo();return Ln===null?f.memoizedState=d:FM(f,Ln.memoizedState,d)},useTransition:function(){var d=Lw(ff)[0],f=wo().memoizedState;return[d,f]},useMutableSource:bM,useSyncExternalStore:CM,useId:zM,unstable_isNewReconciler:!1};function ei(d,f){if(d&&d.defaultProps){f=J({},f),d=d.defaultProps;for(var x in d)f[x]===void 0&&(f[x]=d[x]);return f}return f}function zw(d,f,x,b){f=d.memoizedState,x=x(b,f),x=x==null?f:J({},f,x),d.memoizedState=x,d.lanes===0&&(d.updateQueue.baseState=x)}var _m={isMounted:function(d){return(d=d._reactInternals)?ca(d)===d:!1},enqueueSetState:function(d,f,x){d=d._reactInternals;var b=Vr(),I=Pl(d),M=ma(b,I);M.payload=f,x!=null&&(M.callback=x),f=vl(d,M,I),f!==null&&(ri(f,d,I,b),wm(f,d,I))},enqueueReplaceState:function(d,f,x){d=d._reactInternals;var b=Vr(),I=Pl(d),M=ma(b,I);M.tag=1,M.payload=f,x!=null&&(M.callback=x),f=vl(d,M,I),f!==null&&(ri(f,d,I,b),wm(f,d,I))},enqueueForceUpdate:function(d,f){d=d._reactInternals;var x=Vr(),b=Pl(d),I=ma(x,b);I.tag=2,f!=null&&(I.callback=f),f=vl(d,I,b),f!==null&&(ri(f,d,b,x),wm(f,d,b))}};function HM(d,f,x,b,I,M,L){return d=d.stateNode,typeof d.shouldComponentUpdate=="function"?d.shouldComponentUpdate(b,M,L):f.prototype&&f.prototype.isPureReactComponent?!Qh(x,b)||!Qh(I,M):!0}function KM(d,f,x){var b=!1,I=yl,M=f.contextType;return typeof M=="object"&&M!==null?M=vo(M):(I=ws(f)?Oc:br.current,b=f.contextTypes,M=(b=b!=null)?id(d,I):yl),f=new f(x,M),d.memoizedState=f.state!==null&&f.state!==void 0?f.state:null,f.updater=_m,d.stateNode=f,f._reactInternals=d,b&&(d=d.stateNode,d.__reactInternalMemoizedUnmaskedChildContext=I,d.__reactInternalMemoizedMaskedChildContext=M),f}function WM(d,f,x,b){d=f.state,typeof f.componentWillReceiveProps=="function"&&f.componentWillReceiveProps(x,b),typeof f.UNSAFE_componentWillReceiveProps=="function"&&f.UNSAFE_componentWillReceiveProps(x,b),f.state!==d&&_m.enqueueReplaceState(f,f.state,null)}function Bw(d,f,x,b){var I=d.stateNode;I.props=x,I.state=d.memoizedState,I.refs={},Ew(d);var M=f.contextType;typeof M=="object"&&M!==null?I.context=vo(M):(M=ws(f)?Oc:br.current,I.context=id(d,M)),I.state=d.memoizedState,M=f.getDerivedStateFromProps,typeof M=="function"&&(zw(d,f,M,x),I.state=d.memoizedState),typeof f.getDerivedStateFromProps=="function"||typeof I.getSnapshotBeforeUpdate=="function"||typeof I.UNSAFE_componentWillMount!="function"&&typeof I.componentWillMount!="function"||(f=I.state,typeof I.componentWillMount=="function"&&I.componentWillMount(),typeof I.UNSAFE_componentWillMount=="function"&&I.UNSAFE_componentWillMount(),f!==I.state&&_m.enqueueReplaceState(I,I.state,null),bm(d,x,I,b),I.state=d.memoizedState),typeof I.componentDidMount=="function"&&(d.flags|=4194308)}function pd(d,f){try{var x="",b=f;do x+=ue(b),b=b.return;while(b);var I=x}catch(M){I=`
39
+ Error generating stack: `+M.message+`
40
+ `+M.stack}return{value:d,source:f,stack:I,digest:null}}function $w(d,f,x){return{value:d,source:null,stack:x??null,digest:f??null}}function Uw(d,f){try{console.error(f.value)}catch(x){setTimeout(function(){throw x})}}var eG=typeof WeakMap=="function"?WeakMap:Map;function VM(d,f,x){x=ma(-1,x),x.tag=3,x.payload={element:null};var b=f.value;return x.callback=function(){Lm||(Lm=!0,rb=b),Uw(d,f)},x}function GM(d,f,x){x=ma(-1,x),x.tag=3;var b=d.type.getDerivedStateFromError;if(typeof b=="function"){var I=f.value;x.payload=function(){return b(I)},x.callback=function(){Uw(d,f)}}var M=d.stateNode;return M!==null&&typeof M.componentDidCatch=="function"&&(x.callback=function(){Uw(d,f),typeof b!="function"&&(bl===null?bl=new Set([this]):bl.add(this));var L=f.stack;this.componentDidCatch(f.value,{componentStack:L!==null?L:""})}),x}function qM(d,f,x){var b=d.pingCache;if(b===null){b=d.pingCache=new eG;var I=new Set;b.set(f,I)}else I=b.get(f),I===void 0&&(I=new Set,b.set(f,I));I.has(x)||(I.add(x),d=pG.bind(null,d,f,x),f.then(d,d))}function YM(d){do{var f;if((f=d.tag===13)&&(f=d.memoizedState,f=f!==null?f.dehydrated!==null:!0),f)return d;d=d.return}while(d!==null);return null}function XM(d,f,x,b,I){return(d.mode&1)===0?(d===f?d.flags|=65536:(d.flags|=128,x.flags|=131072,x.flags&=-52805,x.tag===1&&(x.alternate===null?x.tag=17:(f=ma(-1,1),f.tag=2,vl(x,f,1))),x.lanes|=1),d):(d.flags|=65536,d.lanes=I,d)}var tG=E.ReactCurrentOwner,bs=!1;function Wr(d,f,x,b){f.child=d===null?mM(f,null,x,b):ud(f,d.child,x,b)}function ZM(d,f,x,b,I){x=x.render;var M=f.ref;return hd(f,I),b=Rw(d,f,x,b,M,I),x=Dw(),d!==null&&!bs?(f.updateQueue=d.updateQueue,f.flags&=-2053,d.lanes&=~I,ya(d,f,I)):(tn&&x&&mw(f),f.flags|=1,Wr(d,f,b,I),f.child)}function JM(d,f,x,b,I){if(d===null){var M=x.type;return typeof M=="function"&&!ub(M)&&M.defaultProps===void 0&&x.compare===null&&x.defaultProps===void 0?(f.tag=15,f.type=M,QM(d,f,M,b,I)):(d=Um(x.type,null,b,f,f.mode,I),d.ref=f.ref,d.return=f,f.child=d)}if(M=d.child,(d.lanes&I)===0){var L=M.memoizedProps;if(x=x.compare,x=x!==null?x:Qh,x(L,b)&&d.ref===f.ref)return ya(d,f,I)}return f.flags|=1,d=El(M,b),d.ref=f.ref,d.return=f,f.child=d}function QM(d,f,x,b,I){if(d!==null){var M=d.memoizedProps;if(Qh(M,b)&&d.ref===f.ref)if(bs=!1,f.pendingProps=b=M,(d.lanes&I)!==0)(d.flags&131072)!==0&&(bs=!0);else return f.lanes=d.lanes,ya(d,f,I)}return Hw(d,f,x,b,I)}function eA(d,f,x){var b=f.pendingProps,I=b.children,M=d!==null?d.memoizedState:null;if(b.mode==="hidden")if((f.mode&1)===0)f.memoizedState={baseLanes:0,cachePool:null,transitions:null},Gt(md,Vs),Vs|=x;else{if((x&1073741824)===0)return d=M!==null?M.baseLanes|x:x,f.lanes=f.childLanes=1073741824,f.memoizedState={baseLanes:d,cachePool:null,transitions:null},f.updateQueue=null,Gt(md,Vs),Vs|=d,null;f.memoizedState={baseLanes:0,cachePool:null,transitions:null},b=M!==null?M.baseLanes:x,Gt(md,Vs),Vs|=b}else M!==null?(b=M.baseLanes|x,f.memoizedState=null):b=x,Gt(md,Vs),Vs|=b;return Wr(d,f,I,x),f.child}function tA(d,f){var x=f.ref;(d===null&&x!==null||d!==null&&d.ref!==x)&&(f.flags|=512,f.flags|=2097152)}function Hw(d,f,x,b,I){var M=ws(x)?Oc:br.current;return M=id(f,M),hd(f,I),x=Rw(d,f,x,b,M,I),b=Dw(),d!==null&&!bs?(f.updateQueue=d.updateQueue,f.flags&=-2053,d.lanes&=~I,ya(d,f,I)):(tn&&b&&mw(f),f.flags|=1,Wr(d,f,x,I),f.child)}function nA(d,f,x,b,I){if(ws(x)){var M=!0;fm(f)}else M=!1;if(hd(f,I),f.stateNode===null)Am(d,f),KM(f,x,b),Bw(f,x,b,I),b=!0;else if(d===null){var L=f.stateNode,W=f.memoizedProps;L.props=W;var X=L.context,ie=x.contextType;typeof ie=="object"&&ie!==null?ie=vo(ie):(ie=ws(x)?Oc:br.current,ie=id(f,ie));var ge=x.getDerivedStateFromProps,Se=typeof ge=="function"||typeof L.getSnapshotBeforeUpdate=="function";Se||typeof L.UNSAFE_componentWillReceiveProps!="function"&&typeof L.componentWillReceiveProps!="function"||(W!==b||X!==ie)&&WM(f,L,b,ie),xl=!1;var pe=f.memoizedState;L.state=pe,bm(f,b,L,I),X=f.memoizedState,W!==b||pe!==X||vs.current||xl?(typeof ge=="function"&&(zw(f,x,ge,b),X=f.memoizedState),(W=xl||HM(f,x,W,b,pe,X,ie))?(Se||typeof L.UNSAFE_componentWillMount!="function"&&typeof L.componentWillMount!="function"||(typeof L.componentWillMount=="function"&&L.componentWillMount(),typeof L.UNSAFE_componentWillMount=="function"&&L.UNSAFE_componentWillMount()),typeof L.componentDidMount=="function"&&(f.flags|=4194308)):(typeof L.componentDidMount=="function"&&(f.flags|=4194308),f.memoizedProps=b,f.memoizedState=X),L.props=b,L.state=X,L.context=ie,b=W):(typeof L.componentDidMount=="function"&&(f.flags|=4194308),b=!1)}else{L=f.stateNode,SM(d,f),W=f.memoizedProps,ie=f.type===f.elementType?W:ei(f.type,W),L.props=ie,Se=f.pendingProps,pe=L.context,X=x.contextType,typeof X=="object"&&X!==null?X=vo(X):(X=ws(x)?Oc:br.current,X=id(f,X));var Me=x.getDerivedStateFromProps;(ge=typeof Me=="function"||typeof L.getSnapshotBeforeUpdate=="function")||typeof L.UNSAFE_componentWillReceiveProps!="function"&&typeof L.componentWillReceiveProps!="function"||(W!==Se||pe!==X)&&WM(f,L,b,X),xl=!1,pe=f.memoizedState,L.state=pe,bm(f,b,L,I);var Ne=f.memoizedState;W!==Se||pe!==Ne||vs.current||xl?(typeof Me=="function"&&(zw(f,x,Me,b),Ne=f.memoizedState),(ie=xl||HM(f,x,ie,b,pe,Ne,X)||!1)?(ge||typeof L.UNSAFE_componentWillUpdate!="function"&&typeof L.componentWillUpdate!="function"||(typeof L.componentWillUpdate=="function"&&L.componentWillUpdate(b,Ne,X),typeof L.UNSAFE_componentWillUpdate=="function"&&L.UNSAFE_componentWillUpdate(b,Ne,X)),typeof L.componentDidUpdate=="function"&&(f.flags|=4),typeof L.getSnapshotBeforeUpdate=="function"&&(f.flags|=1024)):(typeof L.componentDidUpdate!="function"||W===d.memoizedProps&&pe===d.memoizedState||(f.flags|=4),typeof L.getSnapshotBeforeUpdate!="function"||W===d.memoizedProps&&pe===d.memoizedState||(f.flags|=1024),f.memoizedProps=b,f.memoizedState=Ne),L.props=b,L.state=Ne,L.context=X,b=ie):(typeof L.componentDidUpdate!="function"||W===d.memoizedProps&&pe===d.memoizedState||(f.flags|=4),typeof L.getSnapshotBeforeUpdate!="function"||W===d.memoizedProps&&pe===d.memoizedState||(f.flags|=1024),b=!1)}return Kw(d,f,x,b,M,I)}function Kw(d,f,x,b,I,M){tA(d,f);var L=(f.flags&128)!==0;if(!b&&!L)return I&&aM(f,x,!1),ya(d,f,M);b=f.stateNode,tG.current=f;var W=L&&typeof x.getDerivedStateFromError!="function"?null:b.render();return f.flags|=1,d!==null&&L?(f.child=ud(f,d.child,null,M),f.child=ud(f,null,W,M)):Wr(d,f,W,M),f.memoizedState=b.state,I&&aM(f,x,!0),f.child}function rA(d){var f=d.stateNode;f.pendingContext?oM(d,f.pendingContext,f.pendingContext!==f.context):f.context&&oM(d,f.context,!1),Iw(d,f.containerInfo)}function sA(d,f,x,b,I){return cd(),vw(I),f.flags|=256,Wr(d,f,x,b),f.child}var Ww={dehydrated:null,treeContext:null,retryLane:0};function Vw(d){return{baseLanes:d,cachePool:null,transitions:null}}function oA(d,f,x){var b=f.pendingProps,I=cn.current,M=!1,L=(f.flags&128)!==0,W;if((W=L)||(W=d!==null&&d.memoizedState===null?!1:(I&2)!==0),W?(M=!0,f.flags&=-129):(d===null||d.memoizedState!==null)&&(I|=1),Gt(cn,I&1),d===null)return xw(f),d=f.memoizedState,d!==null&&(d=d.dehydrated,d!==null)?((f.mode&1)===0?f.lanes=1:d.data==="$!"?f.lanes=8:f.lanes=1073741824,null):(L=b.children,d=b.fallback,M?(b=f.mode,M=f.child,L={mode:"hidden",children:L},(b&1)===0&&M!==null?(M.childLanes=0,M.pendingProps=L):M=Hm(L,b,0,null),d=Uc(d,b,x,null),M.return=f,d.return=f,M.sibling=d,f.child=M,f.child.memoizedState=Vw(x),f.memoizedState=Ww,d):Gw(f,L));if(I=d.memoizedState,I!==null&&(W=I.dehydrated,W!==null))return nG(d,f,L,b,W,I,x);if(M){M=b.fallback,L=f.mode,I=d.child,W=I.sibling;var X={mode:"hidden",children:b.children};return(L&1)===0&&f.child!==I?(b=f.child,b.childLanes=0,b.pendingProps=X,f.deletions=null):(b=El(I,X),b.subtreeFlags=I.subtreeFlags&14680064),W!==null?M=El(W,M):(M=Uc(M,L,x,null),M.flags|=2),M.return=f,b.return=f,b.sibling=M,f.child=b,b=M,M=f.child,L=d.child.memoizedState,L=L===null?Vw(x):{baseLanes:L.baseLanes|x,cachePool:null,transitions:L.transitions},M.memoizedState=L,M.childLanes=d.childLanes&~x,f.memoizedState=Ww,b}return M=d.child,d=M.sibling,b=El(M,{mode:"visible",children:b.children}),(f.mode&1)===0&&(b.lanes=x),b.return=f,b.sibling=null,d!==null&&(x=f.deletions,x===null?(f.deletions=[d],f.flags|=16):x.push(d)),f.child=b,f.memoizedState=null,b}function Gw(d,f){return f=Hm({mode:"visible",children:f},d.mode,0,null),f.return=d,d.child=f}function Mm(d,f,x,b){return b!==null&&vw(b),ud(f,d.child,null,x),d=Gw(f,f.pendingProps.children),d.flags|=2,f.memoizedState=null,d}function nG(d,f,x,b,I,M,L){if(x)return f.flags&256?(f.flags&=-257,b=$w(Error(t(422))),Mm(d,f,L,b)):f.memoizedState!==null?(f.child=d.child,f.flags|=128,null):(M=b.fallback,I=f.mode,b=Hm({mode:"visible",children:b.children},I,0,null),M=Uc(M,I,L,null),M.flags|=2,b.return=f,M.return=f,b.sibling=M,f.child=b,(f.mode&1)!==0&&ud(f,d.child,null,L),f.child.memoizedState=Vw(L),f.memoizedState=Ww,M);if((f.mode&1)===0)return Mm(d,f,L,null);if(I.data==="$!"){if(b=I.nextSibling&&I.nextSibling.dataset,b)var W=b.dgst;return b=W,M=Error(t(419)),b=$w(M,b,void 0),Mm(d,f,L,b)}if(W=(L&d.childLanes)!==0,bs||W){if(b=Kn,b!==null){switch(L&-L){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&(b.suspendedLanes|L))!==0?0:I,I!==0&&I!==M.retryLane&&(M.retryLane=I,ga(d,I),ri(b,d,I,-1))}return cb(),b=$w(Error(t(421))),Mm(d,f,L,b)}return I.data==="$?"?(f.flags|=128,f.child=d.child,f=gG.bind(null,d),I._reactRetry=f,null):(d=M.treeContext,Ws=gl(I.nextSibling),Ks=f,tn=!0,Qo=null,d!==null&&(So[xo++]=fa,So[xo++]=pa,So[xo++]=Rc,fa=d.id,pa=d.overflow,Rc=f),f=Gw(f,b.children),f.flags|=4096,f)}function iA(d,f,x){d.lanes|=f;var b=d.alternate;b!==null&&(b.lanes|=f),Pw(d.return,f,x)}function qw(d,f,x,b,I){var M=d.memoizedState;M===null?d.memoizedState={isBackwards:f,rendering:null,renderingStartTime:0,last:b,tail:x,tailMode:I}:(M.isBackwards=f,M.rendering=null,M.renderingStartTime=0,M.last=b,M.tail=x,M.tailMode=I)}function aA(d,f,x){var b=f.pendingProps,I=b.revealOrder,M=b.tail;if(Wr(d,f,b.children,x),b=cn.current,(b&2)!==0)b=b&1|2,f.flags|=128;else{if(d!==null&&(d.flags&128)!==0)e:for(d=f.child;d!==null;){if(d.tag===13)d.memoizedState!==null&&iA(d,x,f);else if(d.tag===19)iA(d,x,f);else if(d.child!==null){d.child.return=d,d=d.child;continue}if(d===f)break e;for(;d.sibling===null;){if(d.return===null||d.return===f)break e;d=d.return}d.sibling.return=d.return,d=d.sibling}b&=1}if(Gt(cn,b),(f.mode&1)===0)f.memoizedState=null;else switch(I){case"forwards":for(x=f.child,I=null;x!==null;)d=x.alternate,d!==null&&Cm(d)===null&&(I=x),x=x.sibling;x=I,x===null?(I=f.child,f.child=null):(I=x.sibling,x.sibling=null),qw(f,!1,I,x,M);break;case"backwards":for(x=null,I=f.child,f.child=null;I!==null;){if(d=I.alternate,d!==null&&Cm(d)===null){f.child=I;break}d=I.sibling,I.sibling=x,x=I,I=d}qw(f,!0,x,null,M);break;case"together":qw(f,!1,null,null,void 0);break;default:f.memoizedState=null}return f.child}function Am(d,f){(f.mode&1)===0&&d!==null&&(d.alternate=null,f.alternate=null,f.flags|=2)}function ya(d,f,x){if(d!==null&&(f.dependencies=d.dependencies),Fc|=f.lanes,(x&f.childLanes)===0)return null;if(d!==null&&f.child!==d.child)throw Error(t(153));if(f.child!==null){for(d=f.child,x=El(d,d.pendingProps),f.child=x,x.return=f;d.sibling!==null;)d=d.sibling,x=x.sibling=El(d,d.pendingProps),x.return=f;x.sibling=null}return f.child}function rG(d,f,x){switch(f.tag){case 3:rA(f),cd();break;case 5:wM(f);break;case 1:ws(f.type)&&fm(f);break;case 4:Iw(f,f.stateNode.containerInfo);break;case 10:var b=f.type._context,I=f.memoizedProps.value;Gt(xm,b._currentValue),b._currentValue=I;break;case 13:if(b=f.memoizedState,b!==null)return b.dehydrated!==null?(Gt(cn,cn.current&1),f.flags|=128,null):(x&f.child.childLanes)!==0?oA(d,f,x):(Gt(cn,cn.current&1),d=ya(d,f,x),d!==null?d.sibling:null);Gt(cn,cn.current&1);break;case 19:if(b=(x&f.childLanes)!==0,(d.flags&128)!==0){if(b)return aA(d,f,x);f.flags|=128}if(I=f.memoizedState,I!==null&&(I.rendering=null,I.tail=null,I.lastEffect=null),Gt(cn,cn.current),b)break;return null;case 22:case 23:return f.lanes=0,eA(d,f,x)}return ya(d,f,x)}var lA,Yw,cA,uA;lA=function(d,f){for(var x=f.child;x!==null;){if(x.tag===5||x.tag===6)d.appendChild(x.stateNode);else if(x.tag!==4&&x.child!==null){x.child.return=x,x=x.child;continue}if(x===f)break;for(;x.sibling===null;){if(x.return===null||x.return===f)return;x=x.return}x.sibling.return=x.return,x=x.sibling}},Yw=function(){},cA=function(d,f,x,b){var I=d.memoizedProps;if(I!==b){d=f.stateNode,Lc(Oi.current);var M=null;switch(x){case"input":I=Ot(d,I),b=Ot(d,b),M=[];break;case"select":I=J({},I,{value:void 0}),b=J({},b,{value:void 0}),M=[];break;case"textarea":I=wc(d,I),b=wc(d,b),M=[];break;default:typeof I.onClick!="function"&&typeof b.onClick=="function"&&(d.onclick=um)}aa(x,b);var L;x=null;for(ie in I)if(!b.hasOwnProperty(ie)&&I.hasOwnProperty(ie)&&I[ie]!=null)if(ie==="style"){var W=I[ie];for(L in W)W.hasOwnProperty(L)&&(x||(x={}),x[L]="")}else ie!=="dangerouslySetInnerHTML"&&ie!=="children"&&ie!=="suppressContentEditableWarning"&&ie!=="suppressHydrationWarning"&&ie!=="autoFocus"&&(s.hasOwnProperty(ie)?M||(M=[]):(M=M||[]).push(ie,null));for(ie in b){var X=b[ie];if(W=I!=null?I[ie]:void 0,b.hasOwnProperty(ie)&&X!==W&&(X!=null||W!=null))if(ie==="style")if(W){for(L in W)!W.hasOwnProperty(L)||X&&X.hasOwnProperty(L)||(x||(x={}),x[L]="");for(L in X)X.hasOwnProperty(L)&&W[L]!==X[L]&&(x||(x={}),x[L]=X[L])}else x||(M||(M=[]),M.push(ie,x)),x=X;else ie==="dangerouslySetInnerHTML"?(X=X?X.__html:void 0,W=W?W.__html:void 0,X!=null&&W!==X&&(M=M||[]).push(ie,X)):ie==="children"?typeof X!="string"&&typeof X!="number"||(M=M||[]).push(ie,""+X):ie!=="suppressContentEditableWarning"&&ie!=="suppressHydrationWarning"&&(s.hasOwnProperty(ie)?(X!=null&&ie==="onScroll"&&Xt("scroll",d),M||W===X||(M=[])):(M=M||[]).push(ie,X))}x&&(M=M||[]).push("style",x);var ie=M;(f.updateQueue=ie)&&(f.flags|=4)}},uA=function(d,f,x,b){x!==b&&(f.flags|=4)};function gf(d,f){if(!tn)switch(d.tailMode){case"hidden":f=d.tail;for(var x=null;f!==null;)f.alternate!==null&&(x=f),f=f.sibling;x===null?d.tail=null:x.sibling=null;break;case"collapsed":x=d.tail;for(var b=null;x!==null;)x.alternate!==null&&(b=x),x=x.sibling;b===null?f||d.tail===null?d.tail=null:d.tail.sibling=null:b.sibling=null}}function Pr(d){var f=d.alternate!==null&&d.alternate.child===d.child,x=0,b=0;if(f)for(var I=d.child;I!==null;)x|=I.lanes|I.childLanes,b|=I.subtreeFlags&14680064,b|=I.flags&14680064,I.return=d,I=I.sibling;else for(I=d.child;I!==null;)x|=I.lanes|I.childLanes,b|=I.subtreeFlags,b|=I.flags,I.return=d,I=I.sibling;return d.subtreeFlags|=b,d.childLanes=x,f}function sG(d,f,x){var b=f.pendingProps;switch(yw(f),f.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Pr(f),null;case 1:return ws(f.type)&&hm(),Pr(f),null;case 3:return b=f.stateNode,fd(),Zt(vs),Zt(br),Mw(),b.pendingContext&&(b.context=b.pendingContext,b.pendingContext=null),(d===null||d.child===null)&&(ym(f)?f.flags|=4:d===null||d.memoizedState.isDehydrated&&(f.flags&256)===0||(f.flags|=1024,Qo!==null&&(ib(Qo),Qo=null))),Yw(d,f),Pr(f),null;case 5:Tw(f);var I=Lc(uf.current);if(x=f.type,d!==null&&f.stateNode!=null)cA(d,f,x,b,I),d.ref!==f.ref&&(f.flags|=512,f.flags|=2097152);else{if(!b){if(f.stateNode===null)throw Error(t(166));return Pr(f),null}if(d=Lc(Oi.current),ym(f)){b=f.stateNode,x=f.type;var M=f.memoizedProps;switch(b[Ai]=f,b[sf]=M,d=(f.mode&1)!==0,x){case"dialog":Xt("cancel",b),Xt("close",b);break;case"iframe":case"object":case"embed":Xt("load",b);break;case"video":case"audio":for(I=0;I<tf.length;I++)Xt(tf[I],b);break;case"source":Xt("error",b);break;case"img":case"image":case"link":Xt("error",b),Xt("load",b);break;case"details":Xt("toggle",b);break;case"input":an(b,M),Xt("invalid",b);break;case"select":b._wrapperState={wasMultiple:!!M.multiple},Xt("invalid",b);break;case"textarea":Nu(b,M),Xt("invalid",b)}aa(x,M),I=null;for(var L in M)if(M.hasOwnProperty(L)){var W=M[L];L==="children"?typeof W=="string"?b.textContent!==W&&(M.suppressHydrationWarning!==!0&&cm(b.textContent,W,d),I=["children",W]):typeof W=="number"&&b.textContent!==""+W&&(M.suppressHydrationWarning!==!0&&cm(b.textContent,W,d),I=["children",""+W]):s.hasOwnProperty(L)&&W!=null&&L==="onScroll"&&Xt("scroll",b)}switch(x){case"input":At(b),zs(b,M,!0);break;case"textarea":At(b),zu(b);break;case"select":case"option":break;default:typeof M.onClick=="function"&&(b.onclick=um)}b=I,f.updateQueue=b,b!==null&&(f.flags|=4)}else{L=I.nodeType===9?I:I.ownerDocument,d==="http://www.w3.org/1999/xhtml"&&(d=Bu(x)),d==="http://www.w3.org/1999/xhtml"?x==="script"?(d=L.createElement("div"),d.innerHTML="<script><\/script>",d=d.removeChild(d.firstChild)):typeof b.is=="string"?d=L.createElement(x,{is:b.is}):(d=L.createElement(x),x==="select"&&(L=d,b.multiple?L.multiple=!0:b.size&&(L.size=b.size))):d=L.createElementNS(d,x),d[Ai]=f,d[sf]=b,lA(d,f,!1,!1),f.stateNode=d;e:{switch(L=Bs(x,b),x){case"dialog":Xt("cancel",d),Xt("close",d),I=b;break;case"iframe":case"object":case"embed":Xt("load",d),I=b;break;case"video":case"audio":for(I=0;I<tf.length;I++)Xt(tf[I],d);I=b;break;case"source":Xt("error",d),I=b;break;case"img":case"image":case"link":Xt("error",d),Xt("load",d),I=b;break;case"details":Xt("toggle",d),I=b;break;case"input":an(d,b),I=Ot(d,b),Xt("invalid",d);break;case"option":I=b;break;case"select":d._wrapperState={wasMultiple:!!b.multiple},I=J({},b,{value:void 0}),Xt("invalid",d);break;case"textarea":Nu(d,b),I=wc(d,b),Xt("invalid",d);break;default:I=b}aa(x,I),W=I;for(M in W)if(W.hasOwnProperty(M)){var X=W[M];M==="style"?po(d,X):M==="dangerouslySetInnerHTML"?(X=X?X.__html:void 0,X!=null&&bc(d,X)):M==="children"?typeof X=="string"?(x!=="textarea"||X!=="")&&ae(d,X):typeof X=="number"&&ae(d,""+X):M!=="suppressContentEditableWarning"&&M!=="suppressHydrationWarning"&&M!=="autoFocus"&&(s.hasOwnProperty(M)?X!=null&&M==="onScroll"&&Xt("scroll",d):X!=null&&T(d,M,X,L))}switch(x){case"input":At(d),zs(d,b,!1);break;case"textarea":At(d),zu(d);break;case"option":b.value!=null&&d.setAttribute("value",""+ve(b.value));break;case"select":d.multiple=!!b.multiple,M=b.value,M!=null?gs(d,!!b.multiple,M,!1):b.defaultValue!=null&&gs(d,!!b.multiple,b.defaultValue,!0);break;default:typeof I.onClick=="function"&&(d.onclick=um)}switch(x){case"button":case"input":case"select":case"textarea":b=!!b.autoFocus;break e;case"img":b=!0;break e;default:b=!1}}b&&(f.flags|=4)}f.ref!==null&&(f.flags|=512,f.flags|=2097152)}return Pr(f),null;case 6:if(d&&f.stateNode!=null)uA(d,f,d.memoizedProps,b);else{if(typeof b!="string"&&f.stateNode===null)throw Error(t(166));if(x=Lc(uf.current),Lc(Oi.current),ym(f)){if(b=f.stateNode,x=f.memoizedProps,b[Ai]=f,(M=b.nodeValue!==x)&&(d=Ks,d!==null))switch(d.tag){case 3:cm(b.nodeValue,x,(d.mode&1)!==0);break;case 5:d.memoizedProps.suppressHydrationWarning!==!0&&cm(b.nodeValue,x,(d.mode&1)!==0)}M&&(f.flags|=4)}else b=(x.nodeType===9?x:x.ownerDocument).createTextNode(b),b[Ai]=f,f.stateNode=b}return Pr(f),null;case 13:if(Zt(cn),b=f.memoizedState,d===null||d.memoizedState!==null&&d.memoizedState.dehydrated!==null){if(tn&&Ws!==null&&(f.mode&1)!==0&&(f.flags&128)===0)fM(),cd(),f.flags|=98560,M=!1;else if(M=ym(f),b!==null&&b.dehydrated!==null){if(d===null){if(!M)throw Error(t(318));if(M=f.memoizedState,M=M!==null?M.dehydrated:null,!M)throw Error(t(317));M[Ai]=f}else cd(),(f.flags&128)===0&&(f.memoizedState=null),f.flags|=4;Pr(f),M=!1}else Qo!==null&&(ib(Qo),Qo=null),M=!0;if(!M)return f.flags&65536?f:null}return(f.flags&128)!==0?(f.lanes=x,f):(b=b!==null,b!==(d!==null&&d.memoizedState!==null)&&b&&(f.child.flags|=8192,(f.mode&1)!==0&&(d===null||(cn.current&1)!==0?Nn===0&&(Nn=3):cb())),f.updateQueue!==null&&(f.flags|=4),Pr(f),null);case 4:return fd(),Yw(d,f),d===null&&nf(f.stateNode.containerInfo),Pr(f),null;case 10:return Cw(f.type._context),Pr(f),null;case 17:return ws(f.type)&&hm(),Pr(f),null;case 19:if(Zt(cn),M=f.memoizedState,M===null)return Pr(f),null;if(b=(f.flags&128)!==0,L=M.rendering,L===null)if(b)gf(M,!1);else{if(Nn!==0||d!==null&&(d.flags&128)!==0)for(d=f.child;d!==null;){if(L=Cm(d),L!==null){for(f.flags|=128,gf(M,!1),b=L.updateQueue,b!==null&&(f.updateQueue=b,f.flags|=4),f.subtreeFlags=0,b=x,x=f.child;x!==null;)M=x,d=b,M.flags&=14680066,L=M.alternate,L===null?(M.childLanes=0,M.lanes=d,M.child=null,M.subtreeFlags=0,M.memoizedProps=null,M.memoizedState=null,M.updateQueue=null,M.dependencies=null,M.stateNode=null):(M.childLanes=L.childLanes,M.lanes=L.lanes,M.child=L.child,M.subtreeFlags=0,M.deletions=null,M.memoizedProps=L.memoizedProps,M.memoizedState=L.memoizedState,M.updateQueue=L.updateQueue,M.type=L.type,d=L.dependencies,M.dependencies=d===null?null:{lanes:d.lanes,firstContext:d.firstContext}),x=x.sibling;return Gt(cn,cn.current&1|2),f.child}d=d.sibling}M.tail!==null&&ln()>yd&&(f.flags|=128,b=!0,gf(M,!1),f.lanes=4194304)}else{if(!b)if(d=Cm(L),d!==null){if(f.flags|=128,b=!0,x=d.updateQueue,x!==null&&(f.updateQueue=x,f.flags|=4),gf(M,!0),M.tail===null&&M.tailMode==="hidden"&&!L.alternate&&!tn)return Pr(f),null}else 2*ln()-M.renderingStartTime>yd&&x!==1073741824&&(f.flags|=128,b=!0,gf(M,!1),f.lanes=4194304);M.isBackwards?(L.sibling=f.child,f.child=L):(x=M.last,x!==null?x.sibling=L:f.child=L,M.last=L)}return M.tail!==null?(f=M.tail,M.rendering=f,M.tail=f.sibling,M.renderingStartTime=ln(),f.sibling=null,x=cn.current,Gt(cn,b?x&1|2:x&1),f):(Pr(f),null);case 22:case 23:return lb(),b=f.memoizedState!==null,d!==null&&d.memoizedState!==null!==b&&(f.flags|=8192),b&&(f.mode&1)!==0?(Vs&1073741824)!==0&&(Pr(f),f.subtreeFlags&6&&(f.flags|=8192)):Pr(f),null;case 24:return null;case 25:return null}throw Error(t(156,f.tag))}function oG(d,f){switch(yw(f),f.tag){case 1:return ws(f.type)&&hm(),d=f.flags,d&65536?(f.flags=d&-65537|128,f):null;case 3:return fd(),Zt(vs),Zt(br),Mw(),d=f.flags,(d&65536)!==0&&(d&128)===0?(f.flags=d&-65537|128,f):null;case 5:return Tw(f),null;case 13:if(Zt(cn),d=f.memoizedState,d!==null&&d.dehydrated!==null){if(f.alternate===null)throw Error(t(340));cd()}return d=f.flags,d&65536?(f.flags=d&-65537|128,f):null;case 19:return Zt(cn),null;case 4:return fd(),null;case 10:return Cw(f.type._context),null;case 22:case 23:return lb(),null;case 24:return null;default:return null}}var Om=!1,kr=!1,iG=typeof WeakSet=="function"?WeakSet:Set,De=null;function gd(d,f){var x=d.ref;if(x!==null)if(typeof x=="function")try{x(null)}catch(b){mn(d,f,b)}else x.current=null}function Xw(d,f,x){try{x()}catch(b){mn(d,f,b)}}var dA=!1;function aG(d,f){if(lw=ee,d=H2(),ew(d)){if("selectionStart"in d)var x={start:d.selectionStart,end:d.selectionEnd};else e:{x=(x=d.ownerDocument)&&x.defaultView||window;var b=x.getSelection&&x.getSelection();if(b&&b.rangeCount!==0){x=b.anchorNode;var I=b.anchorOffset,M=b.focusNode;b=b.focusOffset;try{x.nodeType,M.nodeType}catch{x=null;break e}var L=0,W=-1,X=-1,ie=0,ge=0,Se=d,pe=null;t:for(;;){for(var Me;Se!==x||I!==0&&Se.nodeType!==3||(W=L+I),Se!==M||b!==0&&Se.nodeType!==3||(X=L+b),Se.nodeType===3&&(L+=Se.nodeValue.length),(Me=Se.firstChild)!==null;)pe=Se,Se=Me;for(;;){if(Se===d)break t;if(pe===x&&++ie===I&&(W=L),pe===M&&++ge===b&&(X=L),(Me=Se.nextSibling)!==null)break;Se=pe,pe=Se.parentNode}Se=Me}x=W===-1||X===-1?null:{start:W,end:X}}else x=null}x=x||{start:0,end:0}}else x=null;for(cw={focusedElem:d,selectionRange:x},ee=!1,De=f;De!==null;)if(f=De,d=f.child,(f.subtreeFlags&1028)!==0&&d!==null)d.return=f,De=d;else for(;De!==null;){f=De;try{var Ne=f.alternate;if((f.flags&1024)!==0)switch(f.tag){case 0:case 11:case 15:break;case 1:if(Ne!==null){var Be=Ne.memoizedProps,Cn=Ne.memoizedState,re=f.stateNode,Z=re.getSnapshotBeforeUpdate(f.elementType===f.type?Be:ei(f.type,Be),Cn);re.__reactInternalSnapshotBeforeUpdate=Z}break;case 3:var oe=f.stateNode.containerInfo;oe.nodeType===1?oe.textContent="":oe.nodeType===9&&oe.documentElement&&oe.removeChild(oe.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(t(163))}}catch(we){mn(f,f.return,we)}if(d=f.sibling,d!==null){d.return=f.return,De=d;break}De=f.return}return Ne=dA,dA=!1,Ne}function mf(d,f,x){var b=f.updateQueue;if(b=b!==null?b.lastEffect:null,b!==null){var I=b=b.next;do{if((I.tag&d)===d){var M=I.destroy;I.destroy=void 0,M!==void 0&&Xw(f,x,M)}I=I.next}while(I!==b)}}function Rm(d,f){if(f=f.updateQueue,f=f!==null?f.lastEffect:null,f!==null){var x=f=f.next;do{if((x.tag&d)===d){var b=x.create;x.destroy=b()}x=x.next}while(x!==f)}}function Zw(d){var f=d.ref;if(f!==null){var x=d.stateNode;switch(d.tag){case 5:d=x;break;default:d=x}typeof f=="function"?f(d):f.current=d}}function hA(d){var f=d.alternate;f!==null&&(d.alternate=null,hA(f)),d.child=null,d.deletions=null,d.sibling=null,d.tag===5&&(f=d.stateNode,f!==null&&(delete f[Ai],delete f[sf],delete f[fw],delete f[HV],delete f[KV])),d.stateNode=null,d.return=null,d.dependencies=null,d.memoizedProps=null,d.memoizedState=null,d.pendingProps=null,d.stateNode=null,d.updateQueue=null}function fA(d){return d.tag===5||d.tag===3||d.tag===4}function pA(d){e:for(;;){for(;d.sibling===null;){if(d.return===null||fA(d.return))return null;d=d.return}for(d.sibling.return=d.return,d=d.sibling;d.tag!==5&&d.tag!==6&&d.tag!==18;){if(d.flags&2||d.child===null||d.tag===4)continue e;d.child.return=d,d=d.child}if(!(d.flags&2))return d.stateNode}}function Jw(d,f,x){var b=d.tag;if(b===5||b===6)d=d.stateNode,f?x.nodeType===8?x.parentNode.insertBefore(d,f):x.insertBefore(d,f):(x.nodeType===8?(f=x.parentNode,f.insertBefore(d,x)):(f=x,f.appendChild(d)),x=x._reactRootContainer,x!=null||f.onclick!==null||(f.onclick=um));else if(b!==4&&(d=d.child,d!==null))for(Jw(d,f,x),d=d.sibling;d!==null;)Jw(d,f,x),d=d.sibling}function Qw(d,f,x){var b=d.tag;if(b===5||b===6)d=d.stateNode,f?x.insertBefore(d,f):x.appendChild(d);else if(b!==4&&(d=d.child,d!==null))for(Qw(d,f,x),d=d.sibling;d!==null;)Qw(d,f,x),d=d.sibling}var or=null,ti=!1;function wl(d,f,x){for(x=x.child;x!==null;)gA(d,f,x),x=x.sibling}function gA(d,f,x){if(yo&&typeof yo.onCommitFiberUnmount=="function")try{yo.onCommitFiberUnmount(Vu,x)}catch{}switch(x.tag){case 5:kr||gd(x,f);case 6:var b=or,I=ti;or=null,wl(d,f,x),or=b,ti=I,or!==null&&(ti?(d=or,x=x.stateNode,d.nodeType===8?d.parentNode.removeChild(x):d.removeChild(x)):or.removeChild(x.stateNode));break;case 18:or!==null&&(ti?(d=or,x=x.stateNode,d.nodeType===8?hw(d.parentNode,x):d.nodeType===1&&hw(d,x),Mc(d)):hw(or,x.stateNode));break;case 4:b=or,I=ti,or=x.stateNode.containerInfo,ti=!0,wl(d,f,x),or=b,ti=I;break;case 0:case 11:case 14:case 15:if(!kr&&(b=x.updateQueue,b!==null&&(b=b.lastEffect,b!==null))){I=b=b.next;do{var M=I,L=M.destroy;M=M.tag,L!==void 0&&((M&2)!==0||(M&4)!==0)&&Xw(x,f,L),I=I.next}while(I!==b)}wl(d,f,x);break;case 1:if(!kr&&(gd(x,f),b=x.stateNode,typeof b.componentWillUnmount=="function"))try{b.props=x.memoizedProps,b.state=x.memoizedState,b.componentWillUnmount()}catch(W){mn(x,f,W)}wl(d,f,x);break;case 21:wl(d,f,x);break;case 22:x.mode&1?(kr=(b=kr)||x.memoizedState!==null,wl(d,f,x),kr=b):wl(d,f,x);break;default:wl(d,f,x)}}function mA(d){var f=d.updateQueue;if(f!==null){d.updateQueue=null;var x=d.stateNode;x===null&&(x=d.stateNode=new iG),f.forEach(function(b){var I=mG.bind(null,d,b);x.has(b)||(x.add(b),b.then(I,I))})}}function ni(d,f){var x=f.deletions;if(x!==null)for(var b=0;b<x.length;b++){var I=x[b];try{var M=d,L=f,W=L;e:for(;W!==null;){switch(W.tag){case 5:or=W.stateNode,ti=!1;break e;case 3:or=W.stateNode.containerInfo,ti=!0;break e;case 4:or=W.stateNode.containerInfo,ti=!0;break e}W=W.return}if(or===null)throw Error(t(160));gA(M,L,I),or=null,ti=!1;var X=I.alternate;X!==null&&(X.return=null),I.return=null}catch(ie){mn(I,f,ie)}}if(f.subtreeFlags&12854)for(f=f.child;f!==null;)yA(f,d),f=f.sibling}function yA(d,f){var x=d.alternate,b=d.flags;switch(d.tag){case 0:case 11:case 14:case 15:if(ni(f,d),Di(d),b&4){try{mf(3,d,d.return),Rm(3,d)}catch(Be){mn(d,d.return,Be)}try{mf(5,d,d.return)}catch(Be){mn(d,d.return,Be)}}break;case 1:ni(f,d),Di(d),b&512&&x!==null&&gd(x,x.return);break;case 5:if(ni(f,d),Di(d),b&512&&x!==null&&gd(x,x.return),d.flags&32){var I=d.stateNode;try{ae(I,"")}catch(Be){mn(d,d.return,Be)}}if(b&4&&(I=d.stateNode,I!=null)){var M=d.memoizedProps,L=x!==null?x.memoizedProps:M,W=d.type,X=d.updateQueue;if(d.updateQueue=null,X!==null)try{W==="input"&&M.type==="radio"&&M.name!=null&&rr(I,M),Bs(W,L);var ie=Bs(W,M);for(L=0;L<X.length;L+=2){var ge=X[L],Se=X[L+1];ge==="style"?po(I,Se):ge==="dangerouslySetInnerHTML"?bc(I,Se):ge==="children"?ae(I,Se):T(I,ge,Se,ie)}switch(W){case"input":Hr(I,M);break;case"textarea":Fu(I,M);break;case"select":var pe=I._wrapperState.wasMultiple;I._wrapperState.wasMultiple=!!M.multiple;var Me=M.value;Me!=null?gs(I,!!M.multiple,Me,!1):pe!==!!M.multiple&&(M.defaultValue!=null?gs(I,!!M.multiple,M.defaultValue,!0):gs(I,!!M.multiple,M.multiple?[]:"",!1))}I[sf]=M}catch(Be){mn(d,d.return,Be)}}break;case 6:if(ni(f,d),Di(d),b&4){if(d.stateNode===null)throw Error(t(162));I=d.stateNode,M=d.memoizedProps;try{I.nodeValue=M}catch(Be){mn(d,d.return,Be)}}break;case 3:if(ni(f,d),Di(d),b&4&&x!==null&&x.memoizedState.isDehydrated)try{Mc(f.containerInfo)}catch(Be){mn(d,d.return,Be)}break;case 4:ni(f,d),Di(d);break;case 13:ni(f,d),Di(d),I=d.child,I.flags&8192&&(M=I.memoizedState!==null,I.stateNode.isHidden=M,!M||I.alternate!==null&&I.alternate.memoizedState!==null||(nb=ln())),b&4&&mA(d);break;case 22:if(ge=x!==null&&x.memoizedState!==null,d.mode&1?(kr=(ie=kr)||ge,ni(f,d),kr=ie):ni(f,d),Di(d),b&8192){if(ie=d.memoizedState!==null,(d.stateNode.isHidden=ie)&&!ge&&(d.mode&1)!==0)for(De=d,ge=d.child;ge!==null;){for(Se=De=ge;De!==null;){switch(pe=De,Me=pe.child,pe.tag){case 0:case 11:case 14:case 15:mf(4,pe,pe.return);break;case 1:gd(pe,pe.return);var Ne=pe.stateNode;if(typeof Ne.componentWillUnmount=="function"){b=pe,x=pe.return;try{f=b,Ne.props=f.memoizedProps,Ne.state=f.memoizedState,Ne.componentWillUnmount()}catch(Be){mn(b,x,Be)}}break;case 5:gd(pe,pe.return);break;case 22:if(pe.memoizedState!==null){vA(Se);continue}}Me!==null?(Me.return=pe,De=Me):vA(Se)}ge=ge.sibling}e:for(ge=null,Se=d;;){if(Se.tag===5){if(ge===null){ge=Se;try{I=Se.stateNode,ie?(M=I.style,typeof M.setProperty=="function"?M.setProperty("display","none","important"):M.display="none"):(W=Se.stateNode,X=Se.memoizedProps.style,L=X!=null&&X.hasOwnProperty("display")?X.display:null,W.style.display=jt("display",L))}catch(Be){mn(d,d.return,Be)}}}else if(Se.tag===6){if(ge===null)try{Se.stateNode.nodeValue=ie?"":Se.memoizedProps}catch(Be){mn(d,d.return,Be)}}else if((Se.tag!==22&&Se.tag!==23||Se.memoizedState===null||Se===d)&&Se.child!==null){Se.child.return=Se,Se=Se.child;continue}if(Se===d)break e;for(;Se.sibling===null;){if(Se.return===null||Se.return===d)break e;ge===Se&&(ge=null),Se=Se.return}ge===Se&&(ge=null),Se.sibling.return=Se.return,Se=Se.sibling}}break;case 19:ni(f,d),Di(d),b&4&&mA(d);break;case 21:break;default:ni(f,d),Di(d)}}function Di(d){var f=d.flags;if(f&2){try{e:{for(var x=d.return;x!==null;){if(fA(x)){var b=x;break e}x=x.return}throw Error(t(160))}switch(b.tag){case 5:var I=b.stateNode;b.flags&32&&(ae(I,""),b.flags&=-33);var M=pA(d);Qw(d,M,I);break;case 3:case 4:var L=b.stateNode.containerInfo,W=pA(d);Jw(d,W,L);break;default:throw Error(t(161))}}catch(X){mn(d,d.return,X)}d.flags&=-3}f&4096&&(d.flags&=-4097)}function lG(d,f,x){De=d,SA(d)}function SA(d,f,x){for(var b=(d.mode&1)!==0;De!==null;){var I=De,M=I.child;if(I.tag===22&&b){var L=I.memoizedState!==null||Om;if(!L){var W=I.alternate,X=W!==null&&W.memoizedState!==null||kr;W=Om;var ie=kr;if(Om=L,(kr=X)&&!ie)for(De=I;De!==null;)L=De,X=L.child,L.tag===22&&L.memoizedState!==null?wA(I):X!==null?(X.return=L,De=X):wA(I);for(;M!==null;)De=M,SA(M),M=M.sibling;De=I,Om=W,kr=ie}xA(d)}else(I.subtreeFlags&8772)!==0&&M!==null?(M.return=I,De=M):xA(d)}}function xA(d){for(;De!==null;){var f=De;if((f.flags&8772)!==0){var x=f.alternate;try{if((f.flags&8772)!==0)switch(f.tag){case 0:case 11:case 15:kr||Rm(5,f);break;case 1:var b=f.stateNode;if(f.flags&4&&!kr)if(x===null)b.componentDidMount();else{var I=f.elementType===f.type?x.memoizedProps:ei(f.type,x.memoizedProps);b.componentDidUpdate(I,x.memoizedState,b.__reactInternalSnapshotBeforeUpdate)}var M=f.updateQueue;M!==null&&vM(f,M,b);break;case 3:var L=f.updateQueue;if(L!==null){if(x=null,f.child!==null)switch(f.child.tag){case 5:x=f.child.stateNode;break;case 1:x=f.child.stateNode}vM(f,L,x)}break;case 5:var W=f.stateNode;if(x===null&&f.flags&4){x=W;var X=f.memoizedProps;switch(f.type){case"button":case"input":case"select":case"textarea":X.autoFocus&&x.focus();break;case"img":X.src&&(x.src=X.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(f.memoizedState===null){var ie=f.alternate;if(ie!==null){var ge=ie.memoizedState;if(ge!==null){var Se=ge.dehydrated;Se!==null&&Mc(Se)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(t(163))}kr||f.flags&512&&Zw(f)}catch(pe){mn(f,f.return,pe)}}if(f===d){De=null;break}if(x=f.sibling,x!==null){x.return=f.return,De=x;break}De=f.return}}function vA(d){for(;De!==null;){var f=De;if(f===d){De=null;break}var x=f.sibling;if(x!==null){x.return=f.return,De=x;break}De=f.return}}function wA(d){for(;De!==null;){var f=De;try{switch(f.tag){case 0:case 11:case 15:var x=f.return;try{Rm(4,f)}catch(X){mn(f,x,X)}break;case 1:var b=f.stateNode;if(typeof b.componentDidMount=="function"){var I=f.return;try{b.componentDidMount()}catch(X){mn(f,I,X)}}var M=f.return;try{Zw(f)}catch(X){mn(f,M,X)}break;case 5:var L=f.return;try{Zw(f)}catch(X){mn(f,L,X)}}}catch(X){mn(f,f.return,X)}if(f===d){De=null;break}var W=f.sibling;if(W!==null){W.return=f.return,De=W;break}De=f.return}}var cG=Math.ceil,Dm=E.ReactCurrentDispatcher,eb=E.ReactCurrentOwner,bo=E.ReactCurrentBatchConfig,Ct=0,Kn=null,Mn=null,ir=0,Vs=0,md=ml(0),Nn=0,yf=null,Fc=0,jm=0,tb=0,Sf=null,Cs=null,nb=0,yd=1/0,Sa=null,Lm=!1,rb=null,bl=null,Nm=!1,Cl=null,Fm=0,xf=0,sb=null,zm=-1,Bm=0;function Vr(){return(Ct&6)!==0?ln():zm!==-1?zm:zm=ln()}function Pl(d){return(d.mode&1)===0?1:(Ct&2)!==0&&ir!==0?ir&-ir:VV.transition!==null?(Bm===0&&(Bm=Zg()),Bm):(d=wt,d!==0||(d=window.event,d=d===void 0?16:wn(d.type)),d)}function ri(d,f,x,b){if(50<xf)throw xf=0,sb=null,Error(t(185));Ic(d,x,b),((Ct&2)===0||d!==Kn)&&(d===Kn&&((Ct&2)===0&&(jm|=x),Nn===4&&kl(d,ir)),Ps(d,b),x===1&&Ct===0&&(f.mode&1)===0&&(yd=ln()+500,pm&&Sl()))}function Ps(d,f){var x=d.callbackNode;Wv(d,f);var b=Ec(d,d===Kn?ir:0);if(b===0)x!==null&&ki(x),d.callbackNode=null,d.callbackPriority=0;else if(f=b&-b,d.callbackPriority!==f){if(x!=null&&ki(x),f===1)d.tag===0?WV(CA.bind(null,d)):lM(CA.bind(null,d)),$V(function(){(Ct&6)===0&&Sl()}),x=null;else{switch(ua(b)){case 1:x=Uh;break;case 4:x=kc;break;case 16:x=Wu;break;case 536870912:x=qo;break;default:x=Wu}x=AA(x,bA.bind(null,d))}d.callbackPriority=f,d.callbackNode=x}}function bA(d,f){if(zm=-1,Bm=0,(Ct&6)!==0)throw Error(t(327));var x=d.callbackNode;if(Sd()&&d.callbackNode!==x)return null;var b=Ec(d,d===Kn?ir:0);if(b===0)return null;if((b&30)!==0||(b&d.expiredLanes)!==0||f)f=$m(d,b);else{f=b;var I=Ct;Ct|=2;var M=kA();(Kn!==d||ir!==f)&&(Sa=null,yd=ln()+500,Bc(d,f));do try{hG();break}catch(W){PA(d,W)}while(!0);bw(),Dm.current=M,Ct=I,Mn!==null?f=0:(Kn=null,ir=0,f=Nn)}if(f!==0){if(f===2&&(I=Hh(d),I!==0&&(b=I,f=ob(d,I))),f===1)throw x=yf,Bc(d,0),kl(d,b),Ps(d,ln()),x;if(f===6)kl(d,b);else{if(I=d.current.alternate,(b&30)===0&&!uG(I)&&(f=$m(d,b),f===2&&(M=Hh(d),M!==0&&(b=M,f=ob(d,M))),f===1))throw x=yf,Bc(d,0),kl(d,b),Ps(d,ln()),x;switch(d.finishedWork=I,d.finishedLanes=b,f){case 0:case 1:throw Error(t(345));case 2:$c(d,Cs,Sa);break;case 3:if(kl(d,b),(b&130023424)===b&&(f=nb+500-ln(),10<f)){if(Ec(d,0)!==0)break;if(I=d.suspendedLanes,(I&b)!==b){Vr(),d.pingedLanes|=d.suspendedLanes&I;break}d.timeoutHandle=dw($c.bind(null,d,Cs,Sa),f);break}$c(d,Cs,Sa);break;case 4:if(kl(d,b),(b&4194240)===b)break;for(f=d.eventTimes,I=-1;0<b;){var L=31-Hs(b);M=1<<L,L=f[L],L>I&&(I=L),b&=~M}if(b=I,b=ln()-b,b=(120>b?120:480>b?480:1080>b?1080:1920>b?1920:3e3>b?3e3:4320>b?4320:1960*cG(b/1960))-b,10<b){d.timeoutHandle=dw($c.bind(null,d,Cs,Sa),b);break}$c(d,Cs,Sa);break;case 5:$c(d,Cs,Sa);break;default:throw Error(t(329))}}}return Ps(d,ln()),d.callbackNode===x?bA.bind(null,d):null}function ob(d,f){var x=Sf;return d.current.memoizedState.isDehydrated&&(Bc(d,f).flags|=256),d=$m(d,f),d!==2&&(f=Cs,Cs=x,f!==null&&ib(f)),d}function ib(d){Cs===null?Cs=d:Cs.push.apply(Cs,d)}function uG(d){for(var f=d;;){if(f.flags&16384){var x=f.updateQueue;if(x!==null&&(x=x.stores,x!==null))for(var b=0;b<x.length;b++){var I=x[b],M=I.getSnapshot;I=I.value;try{if(!Jo(M(),I))return!1}catch{return!1}}}if(x=f.child,f.subtreeFlags&16384&&x!==null)x.return=f,f=x;else{if(f===d)break;for(;f.sibling===null;){if(f.return===null||f.return===d)return!0;f=f.return}f.sibling.return=f.return,f=f.sibling}}return!0}function kl(d,f){for(f&=~tb,f&=~jm,d.suspendedLanes|=f,d.pingedLanes&=~f,d=d.expirationTimes;0<f;){var x=31-Hs(f),b=1<<x;d[x]=-1,f&=~b}}function CA(d){if((Ct&6)!==0)throw Error(t(327));Sd();var f=Ec(d,0);if((f&1)===0)return Ps(d,ln()),null;var x=$m(d,f);if(d.tag!==0&&x===2){var b=Hh(d);b!==0&&(f=b,x=ob(d,b))}if(x===1)throw x=yf,Bc(d,0),kl(d,f),Ps(d,ln()),x;if(x===6)throw Error(t(345));return d.finishedWork=d.current.alternate,d.finishedLanes=f,$c(d,Cs,Sa),Ps(d,ln()),null}function ab(d,f){var x=Ct;Ct|=1;try{return d(f)}finally{Ct=x,Ct===0&&(yd=ln()+500,pm&&Sl())}}function zc(d){Cl!==null&&Cl.tag===0&&(Ct&6)===0&&Sd();var f=Ct;Ct|=1;var x=bo.transition,b=wt;try{if(bo.transition=null,wt=1,d)return d()}finally{wt=b,bo.transition=x,Ct=f,(Ct&6)===0&&Sl()}}function lb(){Vs=md.current,Zt(md)}function Bc(d,f){d.finishedWork=null,d.finishedLanes=0;var x=d.timeoutHandle;if(x!==-1&&(d.timeoutHandle=-1,BV(x)),Mn!==null)for(x=Mn.return;x!==null;){var b=x;switch(yw(b),b.tag){case 1:b=b.type.childContextTypes,b!=null&&hm();break;case 3:fd(),Zt(vs),Zt(br),Mw();break;case 5:Tw(b);break;case 4:fd();break;case 13:Zt(cn);break;case 19:Zt(cn);break;case 10:Cw(b.type._context);break;case 22:case 23:lb()}x=x.return}if(Kn=d,Mn=d=El(d.current,null),ir=Vs=f,Nn=0,yf=null,tb=jm=Fc=0,Cs=Sf=null,jc!==null){for(f=0;f<jc.length;f++)if(x=jc[f],b=x.interleaved,b!==null){x.interleaved=null;var I=b.next,M=x.pending;if(M!==null){var L=M.next;M.next=I,b.next=L}x.pending=b}jc=null}return d}function PA(d,f){do{var x=Mn;try{if(bw(),Pm.current=Tm,km){for(var b=un.memoizedState;b!==null;){var I=b.queue;I!==null&&(I.pending=null),b=b.next}km=!1}if(Nc=0,Hn=Ln=un=null,df=!1,hf=0,eb.current=null,x===null||x.return===null){Nn=1,yf=f,Mn=null;break}e:{var M=d,L=x.return,W=x,X=f;if(f=ir,W.flags|=32768,X!==null&&typeof X=="object"&&typeof X.then=="function"){var ie=X,ge=W,Se=ge.tag;if((ge.mode&1)===0&&(Se===0||Se===11||Se===15)){var pe=ge.alternate;pe?(ge.updateQueue=pe.updateQueue,ge.memoizedState=pe.memoizedState,ge.lanes=pe.lanes):(ge.updateQueue=null,ge.memoizedState=null)}var Me=YM(L);if(Me!==null){Me.flags&=-257,XM(Me,L,W,M,f),Me.mode&1&&qM(M,ie,f),f=Me,X=ie;var Ne=f.updateQueue;if(Ne===null){var Be=new Set;Be.add(X),f.updateQueue=Be}else Ne.add(X);break e}else{if((f&1)===0){qM(M,ie,f),cb();break e}X=Error(t(426))}}else if(tn&&W.mode&1){var Cn=YM(L);if(Cn!==null){(Cn.flags&65536)===0&&(Cn.flags|=256),XM(Cn,L,W,M,f),vw(pd(X,W));break e}}M=X=pd(X,W),Nn!==4&&(Nn=2),Sf===null?Sf=[M]:Sf.push(M),M=L;do{switch(M.tag){case 3:M.flags|=65536,f&=-f,M.lanes|=f;var re=VM(M,X,f);xM(M,re);break e;case 1:W=X;var Z=M.type,oe=M.stateNode;if((M.flags&128)===0&&(typeof Z.getDerivedStateFromError=="function"||oe!==null&&typeof oe.componentDidCatch=="function"&&(bl===null||!bl.has(oe)))){M.flags|=65536,f&=-f,M.lanes|=f;var we=GM(M,W,f);xM(M,we);break e}}M=M.return}while(M!==null)}IA(x)}catch(Ue){f=Ue,Mn===x&&x!==null&&(Mn=x=x.return);continue}break}while(!0)}function kA(){var d=Dm.current;return Dm.current=Tm,d===null?Tm:d}function cb(){(Nn===0||Nn===3||Nn===2)&&(Nn=4),Kn===null||(Fc&268435455)===0&&(jm&268435455)===0||kl(Kn,ir)}function $m(d,f){var x=Ct;Ct|=2;var b=kA();(Kn!==d||ir!==f)&&(Sa=null,Bc(d,f));do try{dG();break}catch(I){PA(d,I)}while(!0);if(bw(),Ct=x,Dm.current=b,Mn!==null)throw Error(t(261));return Kn=null,ir=0,Nn}function dG(){for(;Mn!==null;)EA(Mn)}function hG(){for(;Mn!==null&&!Nv();)EA(Mn)}function EA(d){var f=MA(d.alternate,d,Vs);d.memoizedProps=d.pendingProps,f===null?IA(d):Mn=f,eb.current=null}function IA(d){var f=d;do{var x=f.alternate;if(d=f.return,(f.flags&32768)===0){if(x=sG(x,f,Vs),x!==null){Mn=x;return}}else{if(x=oG(x,f),x!==null){x.flags&=32767,Mn=x;return}if(d!==null)d.flags|=32768,d.subtreeFlags=0,d.deletions=null;else{Nn=6,Mn=null;return}}if(f=f.sibling,f!==null){Mn=f;return}Mn=f=d}while(f!==null);Nn===0&&(Nn=5)}function $c(d,f,x){var b=wt,I=bo.transition;try{bo.transition=null,wt=1,fG(d,f,x,b)}finally{bo.transition=I,wt=b}return null}function fG(d,f,x,b){do Sd();while(Cl!==null);if((Ct&6)!==0)throw Error(t(327));x=d.finishedWork;var I=d.finishedLanes;if(x===null)return null;if(d.finishedWork=null,d.finishedLanes=0,x===d.current)throw Error(t(177));d.callbackNode=null,d.callbackPriority=0;var M=x.lanes|x.childLanes;if(Vv(d,M),d===Kn&&(Mn=Kn=null,ir=0),(x.subtreeFlags&2064)===0&&(x.flags&2064)===0||Nm||(Nm=!0,AA(Wu,function(){return Sd(),null})),M=(x.flags&15990)!==0,(x.subtreeFlags&15990)!==0||M){M=bo.transition,bo.transition=null;var L=wt;wt=1;var W=Ct;Ct|=4,eb.current=null,aG(d,x),yA(x,d),RV(cw),ee=!!lw,cw=lw=null,d.current=x,lG(x),Fv(),Ct=W,wt=L,bo.transition=M}else d.current=x;if(Nm&&(Nm=!1,Cl=d,Fm=I),M=d.pendingLanes,M===0&&(bl=null),$v(x.stateNode),Ps(d,ln()),f!==null)for(b=d.onRecoverableError,x=0;x<f.length;x++)I=f[x],b(I.value,{componentStack:I.stack,digest:I.digest});if(Lm)throw Lm=!1,d=rb,rb=null,d;return(Fm&1)!==0&&d.tag!==0&&Sd(),M=d.pendingLanes,(M&1)!==0?d===sb?xf++:(xf=0,sb=d):xf=0,Sl(),null}function Sd(){if(Cl!==null){var d=ua(Fm),f=bo.transition,x=wt;try{if(bo.transition=null,wt=16>d?16:d,Cl===null)var b=!1;else{if(d=Cl,Cl=null,Fm=0,(Ct&6)!==0)throw Error(t(331));var I=Ct;for(Ct|=4,De=d.current;De!==null;){var M=De,L=M.child;if((De.flags&16)!==0){var W=M.deletions;if(W!==null){for(var X=0;X<W.length;X++){var ie=W[X];for(De=ie;De!==null;){var ge=De;switch(ge.tag){case 0:case 11:case 15:mf(8,ge,M)}var Se=ge.child;if(Se!==null)Se.return=ge,De=Se;else for(;De!==null;){ge=De;var pe=ge.sibling,Me=ge.return;if(hA(ge),ge===ie){De=null;break}if(pe!==null){pe.return=Me,De=pe;break}De=Me}}}var Ne=M.alternate;if(Ne!==null){var Be=Ne.child;if(Be!==null){Ne.child=null;do{var Cn=Be.sibling;Be.sibling=null,Be=Cn}while(Be!==null)}}De=M}}if((M.subtreeFlags&2064)!==0&&L!==null)L.return=M,De=L;else e:for(;De!==null;){if(M=De,(M.flags&2048)!==0)switch(M.tag){case 0:case 11:case 15:mf(9,M,M.return)}var re=M.sibling;if(re!==null){re.return=M.return,De=re;break e}De=M.return}}var Z=d.current;for(De=Z;De!==null;){L=De;var oe=L.child;if((L.subtreeFlags&2064)!==0&&oe!==null)oe.return=L,De=oe;else e:for(L=Z;De!==null;){if(W=De,(W.flags&2048)!==0)try{switch(W.tag){case 0:case 11:case 15:Rm(9,W)}}catch(Ue){mn(W,W.return,Ue)}if(W===L){De=null;break e}var we=W.sibling;if(we!==null){we.return=W.return,De=we;break e}De=W.return}}if(Ct=I,Sl(),yo&&typeof yo.onPostCommitFiberRoot=="function")try{yo.onPostCommitFiberRoot(Vu,d)}catch{}b=!0}return b}finally{wt=x,bo.transition=f}}return!1}function TA(d,f,x){f=pd(x,f),f=VM(d,f,1),d=vl(d,f,1),f=Vr(),d!==null&&(Ic(d,1,f),Ps(d,f))}function mn(d,f,x){if(d.tag===3)TA(d,d,x);else for(;f!==null;){if(f.tag===3){TA(f,d,x);break}else if(f.tag===1){var b=f.stateNode;if(typeof f.type.getDerivedStateFromError=="function"||typeof b.componentDidCatch=="function"&&(bl===null||!bl.has(b))){d=pd(x,d),d=GM(f,d,1),f=vl(f,d,1),d=Vr(),f!==null&&(Ic(f,1,d),Ps(f,d));break}}f=f.return}}function pG(d,f,x){var b=d.pingCache;b!==null&&b.delete(f),f=Vr(),d.pingedLanes|=d.suspendedLanes&x,Kn===d&&(ir&x)===x&&(Nn===4||Nn===3&&(ir&130023424)===ir&&500>ln()-nb?Bc(d,0):tb|=x),Ps(d,f)}function _A(d,f){f===0&&((d.mode&1)===0?f=1:(f=Ei,Ei<<=1,(Ei&130023424)===0&&(Ei=4194304)));var x=Vr();d=ga(d,f),d!==null&&(Ic(d,f,x),Ps(d,x))}function gG(d){var f=d.memoizedState,x=0;f!==null&&(x=f.retryLane),_A(d,x)}function mG(d,f){var x=0;switch(d.tag){case 13:var b=d.stateNode,I=d.memoizedState;I!==null&&(x=I.retryLane);break;case 19:b=d.stateNode;break;default:throw Error(t(314))}b!==null&&b.delete(f),_A(d,x)}var MA;MA=function(d,f,x){if(d!==null)if(d.memoizedProps!==f.pendingProps||vs.current)bs=!0;else{if((d.lanes&x)===0&&(f.flags&128)===0)return bs=!1,rG(d,f,x);bs=(d.flags&131072)!==0}else bs=!1,tn&&(f.flags&1048576)!==0&&cM(f,mm,f.index);switch(f.lanes=0,f.tag){case 2:var b=f.type;Am(d,f),d=f.pendingProps;var I=id(f,br.current);hd(f,x),I=Rw(null,f,b,d,I,x);var M=Dw();return f.flags|=1,typeof I=="object"&&I!==null&&typeof I.render=="function"&&I.$$typeof===void 0?(f.tag=1,f.memoizedState=null,f.updateQueue=null,ws(b)?(M=!0,fm(f)):M=!1,f.memoizedState=I.state!==null&&I.state!==void 0?I.state:null,Ew(f),I.updater=_m,f.stateNode=I,I._reactInternals=f,Bw(f,b,d,x),f=Kw(null,f,b,!0,M,x)):(f.tag=0,tn&&M&&mw(f),Wr(null,f,I,x),f=f.child),f;case 16:b=f.elementType;e:{switch(Am(d,f),d=f.pendingProps,I=b._init,b=I(b._payload),f.type=b,I=f.tag=SG(b),d=ei(b,d),I){case 0:f=Hw(null,f,b,d,x);break e;case 1:f=nA(null,f,b,d,x);break e;case 11:f=ZM(null,f,b,d,x);break e;case 14:f=JM(null,f,b,ei(b.type,d),x);break e}throw Error(t(306,b,""))}return f;case 0:return b=f.type,I=f.pendingProps,I=f.elementType===b?I:ei(b,I),Hw(d,f,b,I,x);case 1:return b=f.type,I=f.pendingProps,I=f.elementType===b?I:ei(b,I),nA(d,f,b,I,x);case 3:e:{if(rA(f),d===null)throw Error(t(387));b=f.pendingProps,M=f.memoizedState,I=M.element,SM(d,f),bm(f,b,null,x);var L=f.memoizedState;if(b=L.element,M.isDehydrated)if(M={element:b,isDehydrated:!1,cache:L.cache,pendingSuspenseBoundaries:L.pendingSuspenseBoundaries,transitions:L.transitions},f.updateQueue.baseState=M,f.memoizedState=M,f.flags&256){I=pd(Error(t(423)),f),f=sA(d,f,b,x,I);break e}else if(b!==I){I=pd(Error(t(424)),f),f=sA(d,f,b,x,I);break e}else for(Ws=gl(f.stateNode.containerInfo.firstChild),Ks=f,tn=!0,Qo=null,x=mM(f,null,b,x),f.child=x;x;)x.flags=x.flags&-3|4096,x=x.sibling;else{if(cd(),b===I){f=ya(d,f,x);break e}Wr(d,f,b,x)}f=f.child}return f;case 5:return wM(f),d===null&&xw(f),b=f.type,I=f.pendingProps,M=d!==null?d.memoizedProps:null,L=I.children,uw(b,I)?L=null:M!==null&&uw(b,M)&&(f.flags|=32),tA(d,f),Wr(d,f,L,x),f.child;case 6:return d===null&&xw(f),null;case 13:return oA(d,f,x);case 4:return Iw(f,f.stateNode.containerInfo),b=f.pendingProps,d===null?f.child=ud(f,null,b,x):Wr(d,f,b,x),f.child;case 11:return b=f.type,I=f.pendingProps,I=f.elementType===b?I:ei(b,I),ZM(d,f,b,I,x);case 7:return Wr(d,f,f.pendingProps,x),f.child;case 8:return Wr(d,f,f.pendingProps.children,x),f.child;case 12:return Wr(d,f,f.pendingProps.children,x),f.child;case 10:e:{if(b=f.type._context,I=f.pendingProps,M=f.memoizedProps,L=I.value,Gt(xm,b._currentValue),b._currentValue=L,M!==null)if(Jo(M.value,L)){if(M.children===I.children&&!vs.current){f=ya(d,f,x);break e}}else for(M=f.child,M!==null&&(M.return=f);M!==null;){var W=M.dependencies;if(W!==null){L=M.child;for(var X=W.firstContext;X!==null;){if(X.context===b){if(M.tag===1){X=ma(-1,x&-x),X.tag=2;var ie=M.updateQueue;if(ie!==null){ie=ie.shared;var ge=ie.pending;ge===null?X.next=X:(X.next=ge.next,ge.next=X),ie.pending=X}}M.lanes|=x,X=M.alternate,X!==null&&(X.lanes|=x),Pw(M.return,x,f),W.lanes|=x;break}X=X.next}}else if(M.tag===10)L=M.type===f.type?null:M.child;else if(M.tag===18){if(L=M.return,L===null)throw Error(t(341));L.lanes|=x,W=L.alternate,W!==null&&(W.lanes|=x),Pw(L,x,f),L=M.sibling}else L=M.child;if(L!==null)L.return=M;else for(L=M;L!==null;){if(L===f){L=null;break}if(M=L.sibling,M!==null){M.return=L.return,L=M;break}L=L.return}M=L}Wr(d,f,I.children,x),f=f.child}return f;case 9:return I=f.type,b=f.pendingProps.children,hd(f,x),I=vo(I),b=b(I),f.flags|=1,Wr(d,f,b,x),f.child;case 14:return b=f.type,I=ei(b,f.pendingProps),I=ei(b.type,I),JM(d,f,b,I,x);case 15:return QM(d,f,f.type,f.pendingProps,x);case 17:return b=f.type,I=f.pendingProps,I=f.elementType===b?I:ei(b,I),Am(d,f),f.tag=1,ws(b)?(d=!0,fm(f)):d=!1,hd(f,x),KM(f,b,I),Bw(f,b,I,x),Kw(null,f,b,!0,d,x);case 19:return aA(d,f,x);case 22:return eA(d,f,x)}throw Error(t(156,f.tag))};function AA(d,f){return Xg(d,f)}function yG(d,f,x,b){this.tag=d,this.key=x,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=f,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=b,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Co(d,f,x,b){return new yG(d,f,x,b)}function ub(d){return d=d.prototype,!(!d||!d.isReactComponent)}function SG(d){if(typeof d=="function")return ub(d)?1:0;if(d!=null){if(d=d.$$typeof,d===Y)return 11;if(d===z)return 14}return 2}function El(d,f){var x=d.alternate;return x===null?(x=Co(d.tag,f,d.key,d.mode),x.elementType=d.elementType,x.type=d.type,x.stateNode=d.stateNode,x.alternate=d,d.alternate=x):(x.pendingProps=f,x.type=d.type,x.flags=0,x.subtreeFlags=0,x.deletions=null),x.flags=d.flags&14680064,x.childLanes=d.childLanes,x.lanes=d.lanes,x.child=d.child,x.memoizedProps=d.memoizedProps,x.memoizedState=d.memoizedState,x.updateQueue=d.updateQueue,f=d.dependencies,x.dependencies=f===null?null:{lanes:f.lanes,firstContext:f.firstContext},x.sibling=d.sibling,x.index=d.index,x.ref=d.ref,x}function Um(d,f,x,b,I,M){var L=2;if(b=d,typeof d=="function")ub(d)&&(L=1);else if(typeof d=="string")L=5;else e:switch(d){case O:return Uc(x.children,I,M,f);case D:L=8,I|=8;break;case F:return d=Co(12,x,f,I|2),d.elementType=F,d.lanes=M,d;case j:return d=Co(13,x,f,I),d.elementType=j,d.lanes=M,d;case N:return d=Co(19,x,f,I),d.elementType=N,d.lanes=M,d;case q:return Hm(x,I,M,f);default:if(typeof d=="object"&&d!==null)switch(d.$$typeof){case U:L=10;break e;case V:L=9;break e;case Y:L=11;break e;case z:L=14;break e;case G:L=16,b=null;break e}throw Error(t(130,d==null?d:typeof d,""))}return f=Co(L,x,f,I),f.elementType=d,f.type=b,f.lanes=M,f}function Uc(d,f,x,b){return d=Co(7,d,b,f),d.lanes=x,d}function Hm(d,f,x,b){return d=Co(22,d,b,f),d.elementType=q,d.lanes=x,d.stateNode={isHidden:!1},d}function db(d,f,x){return d=Co(6,d,null,f),d.lanes=x,d}function hb(d,f,x){return f=Co(4,d.children!==null?d.children:[],d.key,f),f.lanes=x,f.stateNode={containerInfo:d.containerInfo,pendingChildren:null,implementation:d.implementation},f}function xG(d,f,x,b,I){this.tag=f,this.containerInfo=d,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Yu(0),this.expirationTimes=Yu(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Yu(0),this.identifierPrefix=b,this.onRecoverableError=I,this.mutableSourceEagerHydrationData=null}function fb(d,f,x,b,I,M,L,W,X){return d=new xG(d,f,x,W,X),f===1?(f=1,M===!0&&(f|=8)):f=0,M=Co(3,null,null,f),d.current=M,M.stateNode=d,M.memoizedState={element:b,isDehydrated:x,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ew(M),d}function vG(d,f,x){var b=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:A,key:b==null?null:""+b,children:d,containerInfo:f,implementation:x}}function OA(d){if(!d)return yl;d=d._reactInternals;e:{if(ca(d)!==d||d.tag!==1)throw Error(t(170));var f=d;do{switch(f.tag){case 3:f=f.stateNode.context;break e;case 1:if(ws(f.type)){f=f.stateNode.__reactInternalMemoizedMergedChildContext;break e}}f=f.return}while(f!==null);throw Error(t(171))}if(d.tag===1){var x=d.type;if(ws(x))return iM(d,x,f)}return f}function RA(d,f,x,b,I,M,L,W,X){return d=fb(x,b,!0,d,I,M,L,W,X),d.context=OA(null),x=d.current,b=Vr(),I=Pl(x),M=ma(b,I),M.callback=f??null,vl(x,M,I),d.current.lanes=I,Ic(d,I,b),Ps(d,b),d}function Km(d,f,x,b){var I=f.current,M=Vr(),L=Pl(I);return x=OA(x),f.context===null?f.context=x:f.pendingContext=x,f=ma(M,L),f.payload={element:d},b=b===void 0?null:b,b!==null&&(f.callback=b),d=vl(I,f,L),d!==null&&(ri(d,I,L,M),wm(d,I,L)),L}function Wm(d){if(d=d.current,!d.child)return null;switch(d.child.tag){case 5:return d.child.stateNode;default:return d.child.stateNode}}function DA(d,f){if(d=d.memoizedState,d!==null&&d.dehydrated!==null){var x=d.retryLane;d.retryLane=x!==0&&x<f?x:f}}function pb(d,f){DA(d,f),(d=d.alternate)&&DA(d,f)}function wG(){return null}var jA=typeof reportError=="function"?reportError:function(d){console.error(d)};function gb(d){this._internalRoot=d}Vm.prototype.render=gb.prototype.render=function(d){var f=this._internalRoot;if(f===null)throw Error(t(409));Km(d,f,null,null)},Vm.prototype.unmount=gb.prototype.unmount=function(){var d=this._internalRoot;if(d!==null){this._internalRoot=null;var f=d.containerInfo;zc(function(){Km(null,d,null,null)}),f[da]=null}};function Vm(d){this._internalRoot=d}Vm.prototype.unstable_scheduleHydration=function(d){if(d){var f=Qg();d={blockedOn:null,target:d,priority:f};for(var x=0;x<_i.length&&f!==0&&f<_i[x].priority;x++);_i.splice(x,0,d),x===0&&Gh(d)}};function mb(d){return!(!d||d.nodeType!==1&&d.nodeType!==9&&d.nodeType!==11)}function Gm(d){return!(!d||d.nodeType!==1&&d.nodeType!==9&&d.nodeType!==11&&(d.nodeType!==8||d.nodeValue!==" react-mount-point-unstable "))}function LA(){}function bG(d,f,x,b,I){if(I){if(typeof b=="function"){var M=b;b=function(){var ie=Wm(L);M.call(ie)}}var L=RA(f,b,d,0,null,!1,!1,"",LA);return d._reactRootContainer=L,d[da]=L.current,nf(d.nodeType===8?d.parentNode:d),zc(),L}for(;I=d.lastChild;)d.removeChild(I);if(typeof b=="function"){var W=b;b=function(){var ie=Wm(X);W.call(ie)}}var X=fb(d,0,!1,null,null,!1,!1,"",LA);return d._reactRootContainer=X,d[da]=X.current,nf(d.nodeType===8?d.parentNode:d),zc(function(){Km(f,X,x,b)}),X}function qm(d,f,x,b,I){var M=x._reactRootContainer;if(M){var L=M;if(typeof I=="function"){var W=I;I=function(){var X=Wm(L);W.call(X)}}Km(f,L,d,I)}else L=bG(x,f,d,I,b);return Wm(L)}Jg=function(d){switch(d.tag){case 3:var f=d.stateNode;if(f.current.memoizedState.isDehydrated){var x=ul(f.pendingLanes);x!==0&&(Xu(f,x|1),Ps(f,ln()),(Ct&6)===0&&(yd=ln()+500,Sl()))}break;case 13:zc(function(){var b=ga(d,1);if(b!==null){var I=Vr();ri(b,d,1,I)}}),pb(d,1)}},Kh=function(d){if(d.tag===13){var f=ga(d,134217728);if(f!==null){var x=Vr();ri(f,d,134217728,x)}pb(d,134217728)}},Yo=function(d){if(d.tag===13){var f=Pl(d),x=ga(d,f);if(x!==null){var b=Vr();ri(x,d,f,b)}pb(d,f)}},Qg=function(){return wt},em=function(d,f){var x=wt;try{return wt=d,f()}finally{wt=x}},Us=function(d,f,x){switch(f){case"input":if(Hr(d,x),f=x.name,x.type==="radio"&&f!=null){for(x=d;x.parentNode;)x=x.parentNode;for(x=x.querySelectorAll("input[name="+JSON.stringify(""+f)+'][type="radio"]'),f=0;f<x.length;f++){var b=x[f];if(b!==d&&b.form===d.form){var I=dm(b);if(!I)throw Error(t(90));on(b),Hr(b,I)}}}break;case"textarea":Fu(d,x);break;case"select":f=x.value,f!=null&&gs(d,!!x.multiple,f,!1)}},Hu=ab,Ku=zc;var CG={usingClientEntryPoint:!1,Events:[of,sd,dm,al,Uu,ab]},vf={findFiberByHostInstance:Ac,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},PG={bundleType:vf.bundleType,version:vf.version,rendererPackageName:vf.rendererPackageName,rendererConfig:vf.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:E.ReactCurrentDispatcher,findHostInstanceByFiber:function(d){return d=qg(d),d===null?null:d.stateNode},findFiberByHostInstance:vf.findFiberByHostInstance||wG,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 Ym=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Ym.isDisabled&&Ym.supportsFiber)try{Vu=Ym.inject(PG),yo=Ym}catch{}}return ks.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=CG,ks.createPortal=function(d,f){var x=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!mb(f))throw Error(t(200));return vG(d,f,null,x)},ks.createRoot=function(d,f){if(!mb(d))throw Error(t(299));var x=!1,b="",I=jA;return f!=null&&(f.unstable_strictMode===!0&&(x=!0),f.identifierPrefix!==void 0&&(b=f.identifierPrefix),f.onRecoverableError!==void 0&&(I=f.onRecoverableError)),f=fb(d,1,!1,null,null,x,!1,b,I),d[da]=f.current,nf(d.nodeType===8?d.parentNode:d),new gb(f)},ks.findDOMNode=function(d){if(d==null)return null;if(d.nodeType===1)return d;var f=d._reactInternals;if(f===void 0)throw typeof d.render=="function"?Error(t(188)):(d=Object.keys(d).join(","),Error(t(268,d)));return d=qg(f),d=d===null?null:d.stateNode,d},ks.flushSync=function(d){return zc(d)},ks.hydrate=function(d,f,x){if(!Gm(f))throw Error(t(200));return qm(null,d,f,!0,x)},ks.hydrateRoot=function(d,f,x){if(!mb(d))throw Error(t(405));var b=x!=null&&x.hydratedSources||null,I=!1,M="",L=jA;if(x!=null&&(x.unstable_strictMode===!0&&(I=!0),x.identifierPrefix!==void 0&&(M=x.identifierPrefix),x.onRecoverableError!==void 0&&(L=x.onRecoverableError)),f=RA(f,null,d,1,x??null,I,!1,M,L),d[da]=f.current,nf(d),b)for(d=0;d<b.length;d++)x=b[d],I=x._getVersion,I=I(x._source),f.mutableSourceEagerHydrationData==null?f.mutableSourceEagerHydrationData=[x,I]:f.mutableSourceEagerHydrationData.push(x,I);return new Vm(f)},ks.render=function(d,f,x){if(!Gm(f))throw Error(t(200));return qm(null,d,f,!1,x)},ks.unmountComponentAtNode=function(d){if(!Gm(d))throw Error(t(40));return d._reactRootContainer?(zc(function(){qm(null,null,d,!1,function(){d._reactRootContainer=null,d[da]=null})}),!0):!1},ks.unstable_batchedUpdates=ab,ks.unstable_renderSubtreeIntoContainer=function(d,f,x,b){if(!Gm(x))throw Error(t(200));if(d==null||d._reactInternals===void 0)throw Error(t(38));return qm(d,f,x,!1,b)},ks.version="18.3.1-next-f1338f8080-20240426",ks}var KA;function $3(){if(KA)return xb.exports;KA=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(),xb.exports=DG(),xb.exports}var WA;function jG(){if(WA)return Xm;WA=1;var n=$3();return Xm.createRoot=n.createRoot,Xm.hydrateRoot=n.hydrateRoot,Xm}var U3=jG();const LG=Za(U3);function be(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 NG(n){const e=be("./icons/icon/0_merged.svg",n);return{fonts:{tldraw_mono_bold:be("./fonts/IBMPlexMono-Bold.woff2",n),tldraw_mono_italic_bold:be("./fonts/IBMPlexMono-BoldItalic.woff2",n),tldraw_mono:be("./fonts/IBMPlexMono-Medium.woff2",n),tldraw_mono_italic:be("./fonts/IBMPlexMono-MediumItalic.woff2",n),tldraw_sans_bold:be("./fonts/IBMPlexSans-Bold.woff2",n),tldraw_sans_italic_bold:be("./fonts/IBMPlexSans-BoldItalic.woff2",n),tldraw_sans:be("./fonts/IBMPlexSans-Medium.woff2",n),tldraw_sans_italic:be("./fonts/IBMPlexSans-MediumItalic.woff2",n),tldraw_serif_bold:be("./fonts/IBMPlexSerif-Bold.woff2",n),tldraw_serif_italic_bold:be("./fonts/IBMPlexSerif-BoldItalic.woff2",n),tldraw_serif:be("./fonts/IBMPlexSerif-Medium.woff2",n),tldraw_serif_italic:be("./fonts/IBMPlexSerif-MediumItalic.woff2",n),tldraw_draw_bold:be("./fonts/Shantell_Sans-Informal_Bold.woff2",n),tldraw_draw_italic_bold:be("./fonts/Shantell_Sans-Informal_Bold_Italic.woff2",n),tldraw_draw:be("./fonts/Shantell_Sans-Informal_Regular.woff2",n),tldraw_draw_italic:be("./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-arc":e+"#arrow-arc","arrow-elbow":e+"#arrow-elbow","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",bookmark:e+"#bookmark","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",comment:e+"#comment","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","help-circle":e+"#help-circle",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",manual:e+"#manual",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:be("./translations/ar.json",n),bn:be("./translations/bn.json",n),ca:be("./translations/ca.json",n),cs:be("./translations/cs.json",n),da:be("./translations/da.json",n),de:be("./translations/de.json",n),el:be("./translations/el.json",n),en:be("./translations/en.json",n),es:be("./translations/es.json",n),fa:be("./translations/fa.json",n),fi:be("./translations/fi.json",n),fr:be("./translations/fr.json",n),gl:be("./translations/gl.json",n),"gu-in":be("./translations/gu-in.json",n),he:be("./translations/he.json",n),"hi-in":be("./translations/hi-in.json",n),hr:be("./translations/hr.json",n),hu:be("./translations/hu.json",n),id:be("./translations/id.json",n),it:be("./translations/it.json",n),ja:be("./translations/ja.json",n),"km-kh":be("./translations/km-kh.json",n),kn:be("./translations/kn.json",n),"ko-kr":be("./translations/ko-kr.json",n),ku:be("./translations/ku.json",n),languages:be("./translations/languages.json",n),main:be("./translations/main.json",n),ml:be("./translations/ml.json",n),mr:be("./translations/mr.json",n),ms:be("./translations/ms.json",n),my:be("./translations/my.json",n),ne:be("./translations/ne.json",n),nl:be("./translations/nl.json",n),no:be("./translations/no.json",n),pa:be("./translations/pa.json",n),pl:be("./translations/pl.json",n),"pt-br":be("./translations/pt-br.json",n),"pt-pt":be("./translations/pt-pt.json",n),ro:be("./translations/ro.json",n),ru:be("./translations/ru.json",n),sl:be("./translations/sl.json",n),so:be("./translations/so.json",n),sv:be("./translations/sv.json",n),ta:be("./translations/ta.json",n),te:be("./translations/te.json",n),th:be("./translations/th.json",n),tl:be("./translations/tl.json",n),tr:be("./translations/tr.json",n),uk:be("./translations/uk.json",n),ur:be("./translations/ur.json",n),vi:be("./translations/vi.json",n),"zh-cn":be("./translations/zh-cn.json",n),"zh-tw":be("./translations/zh-tw.json",n)},embedIcons:{codepen:be("./embed-icons/codepen.png",n),codesandbox:be("./embed-icons/codesandbox.png",n),desmos:be("./embed-icons/desmos.png",n),excalidraw:be("./embed-icons/excalidraw.png",n),felt:be("./embed-icons/felt.png",n),figma:be("./embed-icons/figma.png",n),github_gist:be("./embed-icons/github_gist.png",n),google_calendar:be("./embed-icons/google_calendar.png",n),google_maps:be("./embed-icons/google_maps.png",n),google_slides:be("./embed-icons/google_slides.png",n),observable:be("./embed-icons/observable.png",n),replit:be("./embed-icons/replit.png",n),scratch:be("./embed-icons/scratch.png",n),spotify:be("./embed-icons/spotify.png",n),tldraw:be("./embed-icons/tldraw.png",n),val_town:be("./embed-icons/val_town.png",n),vimeo:be("./embed-icons/vimeo.png",n),youtube:be("./embed-icons/youtube.png",n)}}}const bb="__TLDRAW_LIBRARY_VERSIONS__";function FG(){if(globalThis[bb])return globalThis[bb];const n={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,bb,{value:n,writable:!1,configurable:!1,enumerable:!1}),n}function lc(n,e,t){if(!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=FG();if(r.versions.push({name:n,version:e,modules:t}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,VA(r)},100)}catch{VA(r)}}function VA(n){if(!n.versions.length||n.didWarn)return;const e=n.versions.sort((a,l)=>GA(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),Cb(s,a.name,new Set).add(a.version);continue}a.version===t?r.add(a.name):(r.delete(a.name),Cb(s,a.name,new Set).add(a.version))}if(s.size>0){const a=[`${xa("[tldraw]",["bold","bgRed","textWhite"])} ${xa("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 ${xa(`v${t}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${xa(l,["bold"])}`),"","The following libraries are not on the latest version, or have multiple versions installed:",...Array.from(s,([l,c])=>{const u=Array.from(c).sort(GA).map(h=>xa(`v${h}`,h===t?["textGreen"]:["textRed"]));return` • ❌ ${xa(l,["bold"])} (${u.join(", ")})`})];console.log(a.join(`
41
+ `)),n.didWarn=!0;return}const o=new Map;for(const a of e)Cb(o,a.name,{version:a.version,modules:[]}).modules.push(a.modules);const i=new Map;for(const[a,l]of o)l.modules.length>1&&i.set(a,l);if(i.size>0){const a=[`${xa("[tldraw]",["bold","bgRed","textWhite"])} ${xa("You have multiple instances of some tldraw libraries active. This can lead to bugs and unexpected behavior. ",["textRed","bold"])}`,"","This usually means that your bundler is misconfigured, and is importing the same library multiple times - usually once as an ES Module, and once as a CommonJS module.","","The following libraries have been imported multiple times:",...Array.from(i,([l,c])=>{const u=c.modules.map((h,p)=>h==="esm"?` ${p+1}. ES Modules`:` ${p+1}. CommonJS`).join(`
42
+ `);return` • ❌ ${xa(l,["bold"])} v${c.version}:
43
+ ${u}`}),"","You should configure your bundler to only import one version of each library."];console.log(a.join(`
44
+ `)),n.didWarn=!0;return}}function GA(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 zG={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function xa(n,e=[]){return`\x1B[${e.map(t=>zG[t]).join(";")}m${n}\x1B[m`}function Cb(n,e,t){return n.has(e)?n.get(e):(n.set(e,t),t)}var Pb,qA;function BG(){if(qA)return Pb;qA=1;var n="Expected a function",e=NaN,t="[object Symbol]",r=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,i=/^0o[0-7]+$/i,a=parseInt,l=typeof Os=="object"&&Os&&Os.Object===Object&&Os,c=typeof self=="object"&&self&&self.Object===Object&&self,u=l||c||Function("return this")(),h=Object.prototype,p=h.toString,m=Math.max,S=Math.min,v=function(){return u.Date.now()};function y(A,O,D){var F,U,V,Y,j,N,z=0,G=!1,q=!1,$=!0;if(typeof A!="function")throw new TypeError(n);O=_(O)||0,C(D)&&(G=!!D.leading,q="maxWait"in D,V=q?m(_(D.maxWait)||0,O):V,$="trailing"in D?!!D.trailing:$);function K(ve){var Te=F,je=U;return F=U=void 0,z=ve,Y=A.apply(je,Te),Y}function J(ve){return z=ve,j=setTimeout(he,O),G?K(ve):Y}function H(ve){var Te=ve-N,je=ve-z,At=O-Te;return q?S(At,V-je):At}function te(ve){var Te=ve-N,je=ve-z;return N===void 0||Te>=O||Te<0||q&&je>=V}function he(){var ve=v();if(te(ve))return Pe(ve);j=setTimeout(he,H(ve))}function Pe(ve){return j=void 0,$&&F?K(ve):(F=U=void 0,Y)}function ue(){j!==void 0&&clearTimeout(j),z=0,F=N=U=j=void 0}function Ae(){return j===void 0?Y:Pe(v())}function ze(){var ve=v(),Te=te(ve);if(F=arguments,U=this,N=ve,Te){if(j===void 0)return J(N);if(q)return j=setTimeout(he,O),K(N)}return j===void 0&&(j=setTimeout(he,O)),Y}return ze.cancel=ue,ze.flush=Ae,ze}function w(A,O,D){var F=!0,U=!0;if(typeof A!="function")throw new TypeError(n);return C(D)&&(F="leading"in D?!!D.leading:F,U="trailing"in D?!!D.trailing:U),y(A,O,{leading:F,maxWait:O,trailing:U})}function C(A){var O=typeof A;return!!A&&(O=="object"||O=="function")}function T(A){return!!A&&typeof A=="object"}function E(A){return typeof A=="symbol"||T(A)&&p.call(A)==t}function _(A){if(typeof A=="number")return A;if(E(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=o.test(A);return D||i.test(A)?a(A.slice(2),D?2:8):s.test(A)?e:+A}return Pb=w,Pb}var $G=BG();const H3=Za($G);var kb,YA;function UG(){if(YA)return kb;YA=1;var n=200,e="__lodash_hash_undefined__",t=1/0,r="[object Function]",s="[object GeneratorFunction]",o=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,a=typeof Os=="object"&&Os&&Os.Object===Object&&Os,l=typeof self=="object"&&self&&self.Object===Object&&self,c=a||l||Function("return this")();function u(ae,Ce){var Je=ae?ae.length:0;return!!Je&&p(ae,Ce,0)>-1}function h(ae,Ce,Je,jt){for(var po=ae.length,ms=Je+-1;++ms<po;)if(Ce(ae[ms],ms,ae))return ms;return-1}function p(ae,Ce,Je){if(Ce!==Ce)return h(ae,m,Je);for(var jt=Je-1,po=ae.length;++jt<po;)if(ae[jt]===Ce)return jt;return-1}function m(ae){return ae!==ae}function S(ae,Ce){return ae.has(Ce)}function v(ae,Ce){return ae==null?void 0:ae[Ce]}function y(ae){var Ce=!1;if(ae!=null&&typeof ae.toString!="function")try{Ce=!!(ae+"")}catch{}return Ce}function w(ae){var Ce=-1,Je=Array(ae.size);return ae.forEach(function(jt){Je[++Ce]=jt}),Je}var C=Array.prototype,T=Function.prototype,E=Object.prototype,_=c["__core-js_shared__"],A=function(){var ae=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||"");return ae?"Symbol(src)_1."+ae:""}(),O=T.toString,D=E.hasOwnProperty,F=E.toString,U=RegExp("^"+O.call(D).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),V=C.splice,Y=gs(c,"Map"),j=gs(c,"Set"),N=gs(Object,"create");function z(ae){var Ce=-1,Je=ae?ae.length:0;for(this.clear();++Ce<Je;){var jt=ae[Ce];this.set(jt[0],jt[1])}}function G(){this.__data__=N?N(null):{}}function q(ae){return this.has(ae)&&delete this.__data__[ae]}function $(ae){var Ce=this.__data__;if(N){var Je=Ce[ae];return Je===e?void 0:Je}return D.call(Ce,ae)?Ce[ae]:void 0}function K(ae){var Ce=this.__data__;return N?Ce[ae]!==void 0:D.call(Ce,ae)}function J(ae,Ce){var Je=this.__data__;return Je[ae]=N&&Ce===void 0?e:Ce,this}z.prototype.clear=G,z.prototype.delete=q,z.prototype.get=$,z.prototype.has=K,z.prototype.set=J;function H(ae){var Ce=-1,Je=ae?ae.length:0;for(this.clear();++Ce<Je;){var jt=ae[Ce];this.set(jt[0],jt[1])}}function te(){this.__data__=[]}function he(ae){var Ce=this.__data__,Je=rr(Ce,ae);if(Je<0)return!1;var jt=Ce.length-1;return Je==jt?Ce.pop():V.call(Ce,Je,1),!0}function Pe(ae){var Ce=this.__data__,Je=rr(Ce,ae);return Je<0?void 0:Ce[Je][1]}function ue(ae){return rr(this.__data__,ae)>-1}function Ae(ae,Ce){var Je=this.__data__,jt=rr(Je,ae);return jt<0?Je.push([ae,Ce]):Je[jt][1]=Ce,this}H.prototype.clear=te,H.prototype.delete=he,H.prototype.get=Pe,H.prototype.has=ue,H.prototype.set=Ae;function ze(ae){var Ce=-1,Je=ae?ae.length:0;for(this.clear();++Ce<Je;){var jt=ae[Ce];this.set(jt[0],jt[1])}}function ve(){this.__data__={hash:new z,map:new(Y||H),string:new z}}function Te(ae){return ps(this,ae).delete(ae)}function je(ae){return ps(this,ae).get(ae)}function At(ae){return ps(this,ae).has(ae)}function on(ae,Ce){return ps(this,ae).set(ae,Ce),this}ze.prototype.clear=ve,ze.prototype.delete=Te,ze.prototype.get=je,ze.prototype.has=At,ze.prototype.set=on;function _t(ae){var Ce=-1,Je=ae?ae.length:0;for(this.__data__=new ze;++Ce<Je;)this.add(ae[Ce])}function Ot(ae){return this.__data__.set(ae,e),this}function an(ae){return this.__data__.has(ae)}_t.prototype.add=_t.prototype.push=Ot,_t.prototype.has=an;function rr(ae,Ce){for(var Je=ae.length;Je--;)if(Bu(ae[Je][0],Ce))return Je;return-1}function Hr(ae){if(!Vo(ae)||Nu(ae))return!1;var Ce=Pi(ae)||y(ae)?U:i;return Ce.test(Fu(ae))}function zs(ae,Ce,Je){var jt=-1,po=u,ms=ae.length,aa=!0,Bs=[],$s=Bs;if(ms>=n){var ys=$n(ae);if(ys)return w(ys);aa=!1,po=S,$s=new _t}else $s=Bs;e:for(;++jt<ms;){var Us=ae[jt],Ss=Us;if(Us=Us!==0?Us:0,aa&&Ss===Ss){for(var Go=$s.length;Go--;)if($s[Go]===Ss)continue e;Bs.push(Us)}else po($s,Ss,Je)||($s!==Bs&&$s.push(Ss),Bs.push(Us))}return Bs}var $n=j&&1/w(new j([,-0]))[1]==t?function(ae){return new j(ae)}:bc;function ps(ae,Ce){var Je=ae.__data__;return wc(Ce)?Je[typeof Ce=="string"?"string":"hash"]:Je.map}function gs(ae,Ce){var Je=v(ae,Ce);return Hr(Je)?Je:void 0}function wc(ae){var Ce=typeof ae;return Ce=="string"||Ce=="number"||Ce=="symbol"||Ce=="boolean"?ae!=="__proto__":ae===null}function Nu(ae){return!!A&&A in ae}function Fu(ae){if(ae!=null){try{return O.call(ae)}catch{}try{return ae+""}catch{}}return""}function zu(ae){return ae&&ae.length?zs(ae):[]}function Bu(ae,Ce){return ae===Ce||ae!==ae&&Ce!==Ce}function Pi(ae){var Ce=Vo(ae)?F.call(ae):"";return Ce==r||Ce==s}function Vo(ae){var Ce=typeof ae;return!!ae&&(Ce=="object"||Ce=="function")}function bc(){}return kb=zu,kb}var HG=UG();const KG=Za(HG);function K3(n){const e=(...t)=>{try{return n(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Ap=()=>{},Gr={ok(n){return{ok:!0,value:n}},err(n){return{ok:!1,error:n}}};function xt(n,e){const t=e&&n&&typeof n=="object"&&e in n?n[e]:n;throw new Error(`Unknown switch case ${t}`)}const Ve=K3((n,e)=>{if(!n)throw new Error(e||"Assertion Error")}),qr=K3((n,e)=>{if(n==null)throw new Error(e??"value must be defined");return n});function lI(){let n,e;const t=new Promise((r,s)=>{n=r,e=s});return Object.assign(t,{resolve:n,reject:e})}function xk(n){return new Promise(e=>setTimeout(e,n))}const $f={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},WG=$f.Good;class W3{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?$f.Good:t>30?$f.Mid:$f.Poor,s=r===$f.Mid?"black":"white",o=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${o} %c${t}%c fps`,`color: white; background: ${WG};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 cI(n,e){const t=[];e:for(const r of n){for(const s of t)if(e?e(r,s):r===s)continue e;t.push(r)}return t}function st(n){return n.filter(e=>e!=null)}function cr(n){return n[n.length-1]}function V3(n,e){let t,r=1/0;for(const s of n){const o=e(s);o<r&&(t=s,r=o)}return t}function VG(n,e){let t,r=-1/0;for(const s of n){const o=e(s);o>r&&(t=s,r=o)}return t}function ES(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 up(n,e,t){const r=new Set(e.map(o=>o[n])),s=[];for(const o of t)r.has(o[n])||s.push(o);for(const o of e)s.push(o);return s}/*!
45
+ * MIT License: https://github.com/NoHomey/bind-decorator/blob/master/License
46
+ * Copyright (c) 2016 Ivo Stratev
47
+ */function Rs(...n){if(n.length===2){const[e,t]=n;t.addInitializer(function(){Ve(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const s=e.bind(this),o=Reflect.defineProperty(this,t.name,{value:s,writable:!0,configurable:!0});Ve(o,"Cannot bind a non-configurable class method.")})}else{const[e,t,r]=n;if(!r||typeof r.value!="function")throw new TypeError(`Only methods can be decorated with @bind. <${t}> is not a method!`);return{configurable:!0,get(){const s=r.value.bind(this);return Object.defineProperty(this,t,{value:s,configurable:!0,writable:!0}),s}}}}class zo{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 r0(n,e){let t;const r=(...s)=>(t||(t={},t.promise=new Promise((o,i)=>{t.resolve=o,t.reject=i})),clearTimeout(t.timeout),t.latestArgs=s,t.timeout=setTimeout(()=>{const o=t;t=void 0;try{o.resolve(n(...o.latestArgs))}catch(i){o.reject(i)}},e),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const XA=new WeakMap;function uI(n,e){if(typeof n!="object"||n===null)return;let t=XA.get(n);t||(t={tags:{},extras:{}},XA.set(n,t)),e.tags&&(t.tags={...t.tags,...e.tags}),e.extras&&(t.extras={...t.extras,...e.extras})}async function di(n,e){return window.fetch(n,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Op=(n,e)=>{const t=new window.Image(n,e);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Jr{static async dataUrlToArrayBuffer(e){return di(e).then(function(t){return t.arrayBuffer()})}static async urlToArrayBuffer(e){return await(await di(e)).arrayBuffer()}static async urlToBlob(e){return await(await di(e)).blob()}static async urlToDataUrl(e){if(e.startsWith("data:"))return e;const t=await Jr.urlToBlob(e);return await Jr.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=o=>r(o),s.onabort=o=>r(o),s.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((t,r)=>{if(e){const s=new FileReader;s.onload=()=>t(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsText(e)}})}static rewriteMimeType(e,t){return e.type===t?e:e instanceof File?new File([e],e.name,{type:t}):new Blob([e],{type:t})}}function dI(n){let e=0;for(let t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e|=0;return e+""}function G3(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 ZA=globalThis.crypto,GG="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",qG=128;let Wc,zd;function YG(n){!Wc||Wc.length<n?(Wc=new Uint8Array(n*qG),ZA.getRandomValues(Wc),zd=0):zd+n>Wc.length&&(ZA.getRandomValues(Wc),zd=0),zd+=n}function XG(n=21){YG(n-=0);let e="";for(let t=zd-n;t<zd;t++)e+=GG[Wc[t]&63];return e}let ZG=XG;function Mt(n){return ZG(n)}/*!
57
+ * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
58
+ * Copyright (c) Philip van Heemstra
59
+ */function JG(n){const e=new Uint8Array(n);if(!e||!(typeof Buffer<"u"&&Buffer.isBuffer(e)||e instanceof Uint8Array)||e.length<16||!(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10))return!1;function r(o,i,a,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,h=new TextDecoder,p=o.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;o=o.subarray(a,l);let m=-1,S=0,v=0,y="";e:for(;S<o.length;){const w=S+c,C=o.subarray(S,w),T=h.decode(C,{stream:!0}),E=y+T;let _,A=-1;for(;(_=i.exec(E))!==null;){A=_.index-y.length,m=v+A;break e}S=w,v+=T.length;const O=A>-1?A+u:T.length-u;y=T.slice(O)}return m>=0&&(m+=a>=0?a:p+a),m}const s=r(e,"IDAT",12);return s>=12?r(e,"acTL",8,s)>=8:!1}const QG=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 JA(n,e){let t=0;for(;n[e+t];)t+=n[e+t]+1;return t+1}function eq(n){return new TextDecoder("ascii").decode(n.slice(0,3))==="GIF"}function tq(n){const e=new Uint8Array(n);let t,r,s=0,o=0;if(!eq(n))return!1;for(t=e[10]&128,r=e[10]&7,s+=6,s+=7,s+=t?3*Math.pow(2,r+1):0;o<2&&s<e.length;)switch(e[s]){case 44:o+=1,t=e[s+9]&128,r=e[s+9]&7,s+=10,s+=t?3*Math.pow(2,r+1):0,s+=JA(e,s+1)+1;break;case 33:s+=2,s+=JA(e,s);break;case 59:s=e.length;break;default:s=e.length;break}return o>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 vk=[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"&&(vk=new Int32Array(vk));const nq=(n,e)=>{let t=-1;for(let r=0;r<n.length;r++)t=vk[(t^n[r])&255]^t>>>8;return t^-1},QA=4,eO=4;class Hi{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(!Hi.isPng(e,t))throw new Error("Not a PNG");for(t+=8;t<=e.buffer.byteLength;){const s=t,o=e.getInt32(t);t+=4;const i=Hi.getChunkType(e,t);if(i==="IDAT"&&r[i]){t+=o+QA+eO;continue}if(i==="IEND")break;r[i]={start:s,dataOffset:t+4,size:o},t+=o+QA+eO}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 Hi.readChunks(e)[t]}static setPhysChunk(e,t=1,r){let s=46,o=0;const i=Hi.findChunk(e,"pHYs");i&&(s=i.start,o=i.size);const a=Hi.findChunk(e,"IDAT");a&&(s=a.start,o=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const u=2835.5;c.setInt32(8,u*t),c.setInt32(12,u*t),c.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));c.setInt32(17,nq(h));const p=e.buffer.slice(0,s),m=e.buffer.slice(s+o);return new Blob([p,l,m],r)}}/*!
68
+ * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
69
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
70
+ */function rq(n){return!n||n.length<12?!1:n[8]===87&&n[9]===69&&n[10]===66&&n[11]===80}function sq(n){const e=new Uint8Array(n);return!rq(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const q3=Object.freeze(["image/svg+xml"]),Y3=Object.freeze(["image/jpeg","image/png","image/webp"]),X3=Object.freeze(["image/gif","image/apng","image/avif"]),lg=Object.freeze([...Y3,...q3,...X3]),s0=Object.freeze(["video/mp4","video/webm","video/quicktime"]),oq=Object.freeze([...lg,...s0]),iq=oq.join(",");class Zs{static loadVideo(e){return new Promise((t,r)=>{const s=document.createElement("video");s.onloadeddata=()=>t(s),s.onerror=o=>{console.error(o),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=e})}static async getVideoFrameAsDataUrl(e,t=0){const r=lI();let s=!1;const o=()=>{if(!s)if(e.readyState>=e.HAVE_METADATA)s=!0,e.currentTime=t;else return;if(e.readyState>=e.HAVE_CURRENT_DATA){const a=document.createElement("canvas");a.width=e.videoWidth,a.height=e.videoHeight;const l=a.getContext("2d");if(!l)throw new Error("Could not get 2d context");l.drawImage(e,0,0),r.resolve(a.toDataURL())}},i=a=>{console.error(a),r.reject(new Error("Could not get video frame"))};e.addEventListener("loadedmetadata",o),e.addEventListener("loadeddata",o),e.addEventListener("canplay",o),e.addEventListener("seeked",o),e.addEventListener("error",i),e.addEventListener("stalled",i),o();try{return await r}finally{e.removeEventListener("loadedmetadata",o),e.removeEventListener("loadeddata",o),e.removeEventListener("canplay",o),e.removeEventListener("seeked",o),e.removeEventListener("error",i),e.removeEventListener("stalled",i)}}static getImageAndDimensions(e){return new Promise((t,r)=>{const s=Op();s.onload=()=>{let o;s.naturalWidth?o={w:s.naturalWidth,h:s.naturalHeight}:(document.body.appendChild(s),o={w:s.clientWidth,h:s.clientHeight},document.body.removeChild(s)),t({...o,image:s})},s.onerror=o=>{console.error(o),r(new Error("Could not load image"))},s.crossOrigin="anonymous",s.referrerPolicy="strict-origin-when-cross-origin",s.style.visibility="hidden",s.style.position="absolute",s.style.opacity="0",s.style.zIndex="-9999",s.src=e})}static async getVideoSize(e){return Zs.usingObjectURL(e,async t=>{const r=await Zs.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const{w:t,h:r}=await Zs.usingObjectURL(e,Zs.getImageAndDimensions);try{if(e.type==="image/png"){const s=new DataView(await e.arrayBuffer());if(Hi.isPng(s,0)){const o=Hi.findChunk(s,"pHYs");if(o){const i=Hi.parsePhys(s,o.dataOffset);if(i.unit===0&&i.ppux===i.ppuy){const l=Math.max(i.ppux/2834.645669291339,1);return{w:Math.round(t/l),h:Math.round(r/l)}}}}}}catch(s){return console.error(s),{w:t,h:r}}return{w:t,h:r}}static async isAnimated(e){return e.type==="image/gif"?tq(await e.arrayBuffer()):e.type==="image/avif"?QG(await e.arrayBuffer()):e.type==="image/webp"?sq(await e.arrayBuffer()):e.type==="image/apng"?JG(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return X3.includes(e||"")}static isStaticImageType(e){return Y3.includes(e||"")}static isVectorImageType(e){return q3.includes(e||"")}static isImageType(e){return lg.includes(e||"")}static async usingObjectURL(e,t){const r=URL.createObjectURL(e);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function rt(n,e,t){return n+(e-n)*t}function rh(n,e,t){return(t-n)/(e-n)}function Bo(n=""){let e=0,t=0,r=0,s=0;function o(){const i=e^e<<11;return e=t,t=r,r=s,s^=(s>>>19^i^i>>>8)>>>0,s/4294967296*2}for(let i=0;i<n.length+64;i++)e^=n.charCodeAt(i)|0,o();return o}function sh(n,e,t,r=!1){const[s,o]=e,[i,a]=t,l=i+(n-s)/(o-s)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function Do(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function kn(n,e){if(Do(n,e))return n[e]}function Z3(n){return Object.keys(n)}function Sn(n){return Object.values(n)}function Qr(n){return Object.entries(n)}function J3(n){return Object.fromEntries(n)}function dp(n,e){const t={};let r=!1;for(const[s,o]of Qr(n))e(s,o)?t[s]=o:r=!0;return r?t:n}function cc(n,e){const t={};for(const[r,s]of Qr(n)){const o=e(r,s);t[r]=o}return t}function Q3(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 aq(n){const e=lq(n.chars),t=cq(e,n.firstPositive,n.mostPositive,n.mostNegative),r=n.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=uq(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 lq(n){const e={},t={},r=n.length;for(let s=0;s<r;s++){const o=n[s];e[s]=o,t[o]=s}return{byCode:e,byChar:t,length:r}}function cq(n,e,t,r){const s=n.byChar[e],o=n.byChar[t],i=n.byChar[r];if(s===void 0||o===void 0||i===void 0)throw new Error("invalid charSet");if(o-s<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(s-i<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:n.byCode[s],mostPositive:n.byCode[o],firstNegative:n.byCode[s-1],mostNegative:n.byCode[i]}}function uq(n,e){const t={};for(let r=0;r<100&&(t[r]=Math.pow(e,r),!(t[r]>n));r++);return t}var Eb=null;function hI(){return Eb||(Eb=aq({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Kl(n,e,t){const r=t.byChar[n],s=t.byChar[e];return Math.abs(r-s)}function fI(n,e){const t=n[0];if(t>e.mostPositive||t<e.mostNegative)throw new Error("invalid firstChar on key");return t===e.mostPositive?Kl(t,e.firstPositive,e)+1+IS(n.slice(1),"positive",e):t===e.mostNegative?Kl(t,e.firstNegative,e)+1+IS(n.slice(1),"negative",e):t>=e.firstPositive?Kl(t,e.firstPositive,e)+2:Kl(t,e.firstNegative,e)+2}function IS(n,e,t){const r=n[0];if(r>t.mostPositive||r<t.mostNegative)throw new Error("invalid firstChar on key");return r===t.mostPositive&&e==="positive"?Kl(r,t.mostNegative,t)+1+IS(n.slice(1),e,t):r===t.mostNegative&&e==="negative"?Kl(r,t.mostPositive,t)+1+IS(n.slice(1),e,t):e==="positive"?Kl(r,t.mostNegative,t)+2:Kl(r,t.mostPositive,t)+2}function o0(n,e,t,r,s){const o=Math.max(n.length,e.length);return t==="start"?[n.padStart(o,r),e.padStart(o,r)]:[n.padEnd(o,r),e.padEnd(o,r)]}function dq(n,e,t){let[r,s]=o0(n,e,"end",t.first),o=wk(r,s,t);o===1&&(r=r.padEnd(r.length+1,t.first),o=t.length);const i=nF(Math.floor(o/2),t);return pI(r,i,t)}function wk(n,e,t){const[r,s]=o0(n,e,"end",t.first).sort(),o=eF(s,r,t);return hq(o,t)}function pI(n,e,t){const r=t.length,[s,o]=o0(n,e,"start",t.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){const c=t.byChar[s[l]],u=t.byChar[o[l]],h=c+u+a;a=Math.floor(h/r);const p=h%r;i.unshift(t.byCode[p])}return a>0&&i.unshift(t.byCode[a]),i.join("")}function eF(n,e,t){const r=t.length,[s,o]=o0(n,e,"start",t.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){let c=t.byChar[s[l]];const u=t.byChar[o[l]]+a;c<u?(a=1,c+=r):a=0;const h=c-u;i.unshift(t.byCode[h])}if(a>0)throw new Error("Subtraction result is negative. Ensure a is greater than or equal to b.");for(;i.length>1&&i[0]===t.byCode[0];)i.shift();return i.join("")}function tF(n,e){return pI(n,e.byCode[1],e)}function bk(n,e){return eF(n,e.byCode[1],e)}function nF(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 hq(n,e){let t=0;const r=n.length,s=e.length;for(let o=0;o<r;o++)t+=e.byChar[n[o]]*Math.pow(s,r-o-1);return t}function fq(n){return n.firstPositive+n.byCode[0]}function pq(n,e){return fI(n,e)===n.length}function tO(n,e){TS(n,e)}function TS(n,e){const t=oF(n,e),r=fI(t,e);if(r>n.length)throw new Error("invalid order key length: "+n);return n.slice(0,r)}function rF(n,e){if(!pq(n,e))throw new Error("invalid integer length: "+n)}function sF(n,e){rF(n,e);const[t,r]=iF(n,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=tF(r,e);return t+i}const o=mq(t,e);return aF(o,"lower",e)}function gq(n,e){rF(n,e);const[t,r]=iF(n,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=bk(r,e);return t+i}const o=yq(t,e);return aF(o,"upper",e)}function oF(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 iF(n,e){const t=oF(n,e),r=n.slice(t.length);return[t,r]}function mq(n,e){const t=n>=e.firstPositive,r=tF(n,e),s=n[n.length-1]===e.mostPositive,o=r[r.length-1]===e.mostPositive;return t&&o?r+e.mostNegative:!t&&s?n.slice(0,n.length-1):r}function yq(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 bk(s,e)}return!t&&r?n+e.mostPositive:bk(n,e)}function aF(n,e,t){const r=fI(n,t),s=e==="upper"?t.byCode[t.length-1]:t.byCode[0];return n+s.repeat(r-n.length)}function lF(n,e){const t=nF(Math.floor(Math.random()*e.jitterRange),e);return pI(n,t,e)}function Sq(n,e,t){const r=n.padEnd(n.length+e,t.first);return lF(r,t)}function xq(n,e,t){const r=TS(n,t),s=sF(r,t);let o=0;if(e!==null){const a=wk(n,e,t);a<t.jitterRange+1&&(o=Math.max(o,nO(a,t)))}const i=wk(n,s,t);return i<t.jitterRange+1&&(o=Math.max(o,nO(i,t))),o}function nO(n,e){const t=e.jitterRange-n,r=Object.entries(e.paddingDict).find(([s,o])=>o>t);return r?parseInt(r[0]):0}function vq(n,e,t=hI()){if(n!==null&&tO(n,t),e!==null&&tO(e,t),n===null&&e===null)return fq(t);if(n===null){const r=TS(e,t);return gq(r,t)}if(e===null){const r=TS(n,t);return sF(r,t)}if(n>=e)throw new Error(n+" >= "+e);return dq(n,e,t)}function cF(n,e,t=hI()){const r=vq(n,e,t),s=xq(r,e,t);return s?Sq(r,s,t):lF(r,t)}function uF(n,e,t,r=hI()){return wq(n,e,t,r,cF,uF)}function wq(n,e,t,r,s,o){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 u=0;u<t-1;u++)l=s(l,e,r),c.push(l);return c}if(n==null){let l=s(n,e,r);const c=[l];for(let u=0;u<t-1;u++)l=s(n,l,r),c.push(l);return c.reverse(),c}const i=Math.floor(t/2),a=s(n,e,r);return[...o(n,a,i,r),a,...o(a,e,t-i-1,r)]}const Ch=uF,dF="a0";function bq(n){try{cF(n,null)}catch{throw new Error("invalid index: "+n)}}function oh(n,e,t){return Ch(n??null,e??null,t)}function Ib(n,e){return Ch(n??null,null,e)}function Rp(n,e){return Ch(n??null,e??null,1)[0]}function Wi(n=null){return Ch(n,null,1)[0]}function Cq(n=null){return Ch(null,n,1)[0]}function Dp(n,e="a1"){return[e,...Ch(e,null,n)]}function ur(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function Pq(n,e){return n.id>e.id?1:-1}function gI(n){try{return localStorage.getItem(n)}catch{return null}}function mI(n,e){try{localStorage.setItem(n,e)}catch{}}function kq(){try{localStorage.clear()}catch{}}function hF(n){try{return sessionStorage.getItem(n)}catch{return null}}function yI(n,e){try{sessionStorage.setItem(n,e)}catch{}}function fF(n){try{sessionStorage.removeItem(n)}catch{}}function Eq(){try{sessionStorage.clear()}catch{}}const Bd=[],Iq=60,Hy=Math.ceil(1e3/Iq);let bf,Tb=0,Ck=0;const Tq=()=>{const n=Bd.splice(0,Bd.length);for(const e of n)e()};function pF(){if(bf)return;const n=Date.now(),e=n-Ck;if(Tb+e<Hy){bf=requestAnimationFrame(()=>{bf=void 0,pF()});return}bf=requestAnimationFrame(()=>{bf=void 0,Ck=n,Tb=Math.min(Tb+e-Hy,Hy*10),Tq()})}let rO=!1;function gF(n){return Bd.includes(n)||(Bd.push(n),rO||(rO=!0,Ck=Date.now()-Hy-1),pF()),()=>{const e=Bd.indexOf(n);e>-1&&Bd.splice(e,1)}}class _q{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 o=window.setTimeout(t,r,s),i=this.timeouts.get(e)??[];return this.timeouts.set(e,[...i,o]),o}setInterval(e,t,r,...s){const o=window.setInterval(t,r,s),i=this.intervals.get(e)??[];return this.intervals.set(e,[...i,o]),o}requestAnimationFrame(e,t){const r=window.requestAnimationFrame(t),s=this.rafs.get(e)??[];return this.rafs.set(e,[...s,r]),r}dispose(e){var t,r,s;(t=this.timeouts.get(e))==null||t.forEach(o=>clearTimeout(o)),(r=this.intervals.get(e))==null||r.forEach(o=>clearInterval(o)),(s=this.rafs.get(e))==null||s.forEach(o=>cancelAnimationFrame(o)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(const e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(t,r,...s)=>this.setTimeout(e,t,r,s),setInterval:(t,r,...s)=>this.setInterval(e,t,r,s),requestAnimationFrame:t=>this.requestAnimationFrame(e,t),dispose:()=>this.dispose(e)}}}const Qe=(n,e)=>{try{return new URL(n,e)}catch{return}};function Mq(n){return n!==void 0}function Aq(){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 mF=Aq(),en=mF[0];mF[1];const Oq=Object.getPrototypeOf(en({}));lc("@tldraw/utils","3.13.1","esm");var sO={},Cf,oO;function ls(){if(oO)return Cf;oO=1;var n=function(e){return e&&e.Math===Math&&e};return Cf=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Os=="object"&&Os)||n(typeof Cf=="object"&&Cf)||function(){return this}()||Function("return this")(),Cf}var _b={},Mb,iO;function cs(){return iO||(iO=1,Mb=function(n){try{return!!n()}catch{return!0}}),Mb}var Ab,aO;function uc(){if(aO)return Ab;aO=1;var n=cs();return Ab=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Ab}var Ob,lO;function i0(){if(lO)return Ob;lO=1;var n=cs();return Ob=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),Ob}var Rb,cO;function Ja(){if(cO)return Rb;cO=1;var n=i0(),e=Function.prototype.call;return Rb=n?e.bind(e):function(){return e.apply(e,arguments)},Rb}var Db={},uO;function Rq(){if(uO)return Db;uO=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return Db.f=t?function(s){var o=e(this,s);return!!o&&o.enumerable}:n,Db}var jb,dO;function yF(){return dO||(dO=1,jb=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),jb}var Lb,hO;function er(){if(hO)return Lb;hO=1;var n=i0(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return Lb=n?r:function(s){return function(){return t.apply(s,arguments)}},Lb}var Nb,fO;function Ph(){if(fO)return Nb;fO=1;var n=er(),e=n({}.toString),t=n("".slice);return Nb=function(r){return t(e(r),8,-1)},Nb}var Fb,pO;function Dq(){if(pO)return Fb;pO=1;var n=er(),e=cs(),t=Ph(),r=Object,s=n("".split);return Fb=e(function(){return!r("z").propertyIsEnumerable(0)})?function(o){return t(o)==="String"?s(o,""):r(o)}:r,Fb}var zb,gO;function SF(){return gO||(gO=1,zb=function(n){return n==null}),zb}var Bb,mO;function kh(){if(mO)return Bb;mO=1;var n=SF(),e=TypeError;return Bb=function(t){if(n(t))throw new e("Can't call method on "+t);return t},Bb}var $b,yO;function a0(){if(yO)return $b;yO=1;var n=Dq(),e=kh();return $b=function(t){return n(e(t))},$b}var Ub,SO;function us(){if(SO)return Ub;SO=1;var n=typeof document=="object"&&document.all;return Ub=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},Ub}var Hb,xO;function Qa(){if(xO)return Hb;xO=1;var n=us();return Hb=function(e){return typeof e=="object"?e!==null:n(e)},Hb}var Kb,vO;function l0(){if(vO)return Kb;vO=1;var n=ls(),e=us(),t=function(r){return e(r)?r:void 0};return Kb=function(r,s){return arguments.length<2?t(n[r]):n[r]&&n[r][s]},Kb}var Wb,wO;function xF(){if(wO)return Wb;wO=1;var n=er();return Wb=n({}.isPrototypeOf),Wb}var Vb,bO;function jq(){if(bO)return Vb;bO=1;var n=ls(),e=n.navigator,t=e&&e.userAgent;return Vb=t?String(t):"",Vb}var Gb,CO;function Lq(){if(CO)return Gb;CO=1;var n=ls(),e=jq(),t=n.process,r=n.Deno,s=t&&t.versions||r&&r.version,o=s&&s.v8,i,a;return o&&(i=o.split("."),a=i[0]>0&&i[0]<4?1:+(i[0]+i[1])),!a&&e&&(i=e.match(/Edge\/(\d+)/),(!i||i[1]>=74)&&(i=e.match(/Chrome\/(\d+)/),i&&(a=+i[1]))),Gb=a,Gb}var qb,PO;function vF(){if(PO)return qb;PO=1;var n=Lq(),e=cs(),t=ls(),r=t.String;return qb=!!Object.getOwnPropertySymbols&&!e(function(){var s=Symbol("symbol detection");return!r(s)||!(Object(s)instanceof Symbol)||!Symbol.sham&&n&&n<41}),qb}var Yb,kO;function wF(){if(kO)return Yb;kO=1;var n=vF();return Yb=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",Yb}var Xb,EO;function bF(){if(EO)return Xb;EO=1;var n=l0(),e=us(),t=xF(),r=wF(),s=Object;return Xb=r?function(o){return typeof o=="symbol"}:function(o){var i=n("Symbol");return e(i)&&t(i.prototype,s(o))},Xb}var Zb,IO;function Nq(){if(IO)return Zb;IO=1;var n=String;return Zb=function(e){try{return n(e)}catch{return"Object"}},Zb}var Jb,TO;function SI(){if(TO)return Jb;TO=1;var n=us(),e=Nq(),t=TypeError;return Jb=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},Jb}var Qb,_O;function xI(){if(_O)return Qb;_O=1;var n=SI(),e=SF();return Qb=function(t,r){var s=t[r];return e(s)?void 0:n(s)},Qb}var e1,MO;function Fq(){if(MO)return e1;MO=1;var n=Ja(),e=us(),t=Qa(),r=TypeError;return e1=function(s,o){var i,a;if(o==="string"&&e(i=s.toString)&&!t(a=n(i,s))||e(i=s.valueOf)&&!t(a=n(i,s))||o!=="string"&&e(i=s.toString)&&!t(a=n(i,s)))return a;throw new r("Can't convert object to primitive value")},e1}var t1={exports:{}},n1,AO;function CF(){return AO||(AO=1,n1=!1),n1}var r1,OO;function vI(){if(OO)return r1;OO=1;var n=ls(),e=Object.defineProperty;return r1=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},r1}var RO;function wI(){if(RO)return t1.exports;RO=1;var n=CF(),e=ls(),t=vI(),r="__core-js_shared__",s=t1.exports=e[r]||t(r,{});return(s.versions||(s.versions=[])).push({version:"3.42.0",mode:n?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.42.0/LICENSE",source:"https://github.com/zloirock/core-js"}),t1.exports}var s1,DO;function bI(){if(DO)return s1;DO=1;var n=wI();return s1=function(e,t){return n[e]||(n[e]=t||{})},s1}var o1,jO;function cg(){if(jO)return o1;jO=1;var n=kh(),e=Object;return o1=function(t){return e(n(t))},o1}var i1,LO;function dc(){if(LO)return i1;LO=1;var n=er(),e=cg(),t=n({}.hasOwnProperty);return i1=Object.hasOwn||function(s,o){return t(e(s),o)},i1}var a1,NO;function PF(){if(NO)return a1;NO=1;var n=er(),e=0,t=Math.random(),r=n(1 .toString);return a1=function(s){return"Symbol("+(s===void 0?"":s)+")_"+r(++e+t,36)},a1}var l1,FO;function el(){if(FO)return l1;FO=1;var n=ls(),e=bI(),t=dc(),r=PF(),s=vF(),o=wF(),i=n.Symbol,a=e("wks"),l=o?i.for||i:i&&i.withoutSetter||r;return l1=function(c){return t(a,c)||(a[c]=s&&t(i,c)?i[c]:l("Symbol."+c)),a[c]},l1}var c1,zO;function zq(){if(zO)return c1;zO=1;var n=Ja(),e=Qa(),t=bF(),r=xI(),s=Fq(),o=el(),i=TypeError,a=o("toPrimitive");return c1=function(l,c){if(!e(l)||t(l))return l;var u=r(l,a),h;if(u){if(c===void 0&&(c="default"),h=n(u,l,c),!e(h)||t(h))return h;throw new i("Can't convert object to primitive value")}return c===void 0&&(c="number"),s(l,c)},c1}var u1,BO;function kF(){if(BO)return u1;BO=1;var n=zq(),e=bF();return u1=function(t){var r=n(t,"string");return e(r)?r:r+""},u1}var d1,$O;function EF(){if($O)return d1;$O=1;var n=ls(),e=Qa(),t=n.document,r=e(t)&&e(t.createElement);return d1=function(s){return r?t.createElement(s):{}},d1}var h1,UO;function IF(){if(UO)return h1;UO=1;var n=uc(),e=cs(),t=EF();return h1=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),h1}var HO;function TF(){if(HO)return _b;HO=1;var n=uc(),e=Ja(),t=Rq(),r=yF(),s=a0(),o=kF(),i=dc(),a=IF(),l=Object.getOwnPropertyDescriptor;return _b.f=n?l:function(u,h){if(u=s(u),h=o(h),a)try{return l(u,h)}catch{}if(i(u,h))return r(!e(t.f,u,h),u[h])},_b}var f1={},p1,KO;function _F(){if(KO)return p1;KO=1;var n=uc(),e=cs();return p1=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),p1}var g1,WO;function Tu(){if(WO)return g1;WO=1;var n=Qa(),e=String,t=TypeError;return g1=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},g1}var VO;function ug(){if(VO)return f1;VO=1;var n=uc(),e=IF(),t=_F(),r=Tu(),s=kF(),o=TypeError,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,l="enumerable",c="configurable",u="writable";return f1.f=n?t?function(p,m,S){if(r(p),m=s(m),r(S),typeof p=="function"&&m==="prototype"&&"value"in S&&u in S&&!S[u]){var v=a(p,m);v&&v[u]&&(p[m]=S.value,S={configurable:c in S?S[c]:v[c],enumerable:l in S?S[l]:v[l],writable:!1})}return i(p,m,S)}:i:function(p,m,S){if(r(p),m=s(m),r(S),e)try{return i(p,m,S)}catch{}if("get"in S||"set"in S)throw new o("Accessors not supported");return"value"in S&&(p[m]=S.value),p},f1}var m1,GO;function CI(){if(GO)return m1;GO=1;var n=uc(),e=ug(),t=yF();return m1=n?function(r,s,o){return e.f(r,s,t(1,o))}:function(r,s,o){return r[s]=o,r},m1}var y1={exports:{}},S1,qO;function Bq(){if(qO)return S1;qO=1;var n=uc(),e=dc(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,s=e(t,"name"),o=s&&(function(){}).name==="something",i=s&&(!n||n&&r(t,"name").configurable);return S1={EXISTS:s,PROPER:o,CONFIGURABLE:i},S1}var x1,YO;function MF(){if(YO)return x1;YO=1;var n=er(),e=us(),t=wI(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(s){return r(s)}),x1=t.inspectSource,x1}var v1,XO;function $q(){if(XO)return v1;XO=1;var n=ls(),e=us(),t=n.WeakMap;return v1=e(t)&&/native code/.test(String(t)),v1}var w1,ZO;function AF(){if(ZO)return w1;ZO=1;var n=bI(),e=PF(),t=n("keys");return w1=function(r){return t[r]||(t[r]=e(r))},w1}var b1,JO;function PI(){return JO||(JO=1,b1={}),b1}var C1,QO;function OF(){if(QO)return C1;QO=1;var n=$q(),e=ls(),t=Qa(),r=CI(),s=dc(),o=wI(),i=AF(),a=PI(),l="Object already initialized",c=e.TypeError,u=e.WeakMap,h,p,m,S=function(C){return m(C)?p(C):h(C,{})},v=function(C){return function(T){var E;if(!t(T)||(E=p(T)).type!==C)throw new c("Incompatible receiver, "+C+" required");return E}};if(n||o.state){var y=o.state||(o.state=new u);y.get=y.get,y.has=y.has,y.set=y.set,h=function(C,T){if(y.has(C))throw new c(l);return T.facade=C,y.set(C,T),T},p=function(C){return y.get(C)||{}},m=function(C){return y.has(C)}}else{var w=i("state");a[w]=!0,h=function(C,T){if(s(C,w))throw new c(l);return T.facade=C,r(C,w,T),T},p=function(C){return s(C,w)?C[w]:{}},m=function(C){return s(C,w)}}return C1={set:h,get:p,has:m,enforce:S,getterFor:v},C1}var eR;function Uq(){if(eR)return y1.exports;eR=1;var n=er(),e=cs(),t=us(),r=dc(),s=uc(),o=Bq().CONFIGURABLE,i=MF(),a=OF(),l=a.enforce,c=a.get,u=String,h=Object.defineProperty,p=n("".slice),m=n("".replace),S=n([].join),v=s&&!e(function(){return h(function(){},"length",{value:8}).length!==8}),y=String(String).split("String"),w=y1.exports=function(C,T,E){p(u(T),0,7)==="Symbol("&&(T="["+m(u(T),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),E&&E.getter&&(T="get "+T),E&&E.setter&&(T="set "+T),(!r(C,"name")||o&&C.name!==T)&&(s?h(C,"name",{value:T,configurable:!0}):C.name=T),v&&E&&r(E,"arity")&&C.length!==E.arity&&h(C,"length",{value:E.arity});try{E&&r(E,"constructor")&&E.constructor?s&&h(C,"prototype",{writable:!1}):C.prototype&&(C.prototype=void 0)}catch{}var _=l(C);return r(_,"source")||(_.source=S(y,typeof T=="string"?T:"")),C};return Function.prototype.toString=w(function(){return t(this)&&c(this).source||i(this)},"toString"),y1.exports}var P1,tR;function RF(){if(tR)return P1;tR=1;var n=us(),e=ug(),t=Uq(),r=vI();return P1=function(s,o,i,a){a||(a={});var l=a.enumerable,c=a.name!==void 0?a.name:o;if(n(i)&&t(i,c,a),a.global)l?s[o]=i:r(o,i);else{try{a.unsafe?s[o]&&(l=!0):delete s[o]}catch{}l?s[o]=i:e.f(s,o,{value:i,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return s},P1}var k1={},E1,nR;function Hq(){if(nR)return E1;nR=1;var n=Math.ceil,e=Math.floor;return E1=Math.trunc||function(r){var s=+r;return(s>0?e:n)(s)},E1}var I1,rR;function _u(){if(rR)return I1;rR=1;var n=Hq();return I1=function(e){var t=+e;return t!==t||t===0?0:n(t)},I1}var T1,sR;function Kq(){if(sR)return T1;sR=1;var n=_u(),e=Math.max,t=Math.min;return T1=function(r,s){var o=n(r);return o<0?e(o+s,0):t(o,s)},T1}var _1,oR;function DF(){if(oR)return _1;oR=1;var n=_u(),e=Math.min;return _1=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},_1}var M1,iR;function dg(){if(iR)return M1;iR=1;var n=DF();return M1=function(e){return n(e.length)},M1}var A1,aR;function Wq(){if(aR)return A1;aR=1;var n=a0(),e=Kq(),t=dg(),r=function(s){return function(o,i,a){var l=n(o),c=t(l);if(c===0)return!s&&-1;var u=e(a,c),h;if(s&&i!==i){for(;c>u;)if(h=l[u++],h!==h)return!0}else for(;c>u;u++)if((s||u in l)&&l[u]===i)return s||u||0;return!s&&-1}};return A1={includes:r(!0),indexOf:r(!1)},A1}var O1,lR;function jF(){if(lR)return O1;lR=1;var n=er(),e=dc(),t=a0(),r=Wq().indexOf,s=PI(),o=n([].push);return O1=function(i,a){var l=t(i),c=0,u=[],h;for(h in l)!e(s,h)&&e(l,h)&&o(u,h);for(;a.length>c;)e(l,h=a[c++])&&(~r(u,h)||o(u,h));return u},O1}var R1,cR;function kI(){return cR||(cR=1,R1=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),R1}var uR;function Vq(){if(uR)return k1;uR=1;var n=jF(),e=kI(),t=e.concat("length","prototype");return k1.f=Object.getOwnPropertyNames||function(s){return n(s,t)},k1}var D1={},dR;function Gq(){return dR||(dR=1,D1.f=Object.getOwnPropertySymbols),D1}var j1,hR;function qq(){if(hR)return j1;hR=1;var n=l0(),e=er(),t=Vq(),r=Gq(),s=Tu(),o=e([].concat);return j1=n("Reflect","ownKeys")||function(a){var l=t.f(s(a)),c=r.f;return c?o(l,c(a)):l},j1}var L1,fR;function Yq(){if(fR)return L1;fR=1;var n=dc(),e=qq(),t=TF(),r=ug();return L1=function(s,o,i){for(var a=e(o),l=r.f,c=t.f,u=0;u<a.length;u++){var h=a[u];!n(s,h)&&!(i&&n(i,h))&&l(s,h,c(o,h))}},L1}var N1,pR;function Xq(){if(pR)return N1;pR=1;var n=cs(),e=us(),t=/#|\.prototype\./,r=function(l,c){var u=o[s(l)];return u===a?!0:u===i?!1:e(c)?n(c):!!c},s=r.normalize=function(l){return String(l).replace(t,".").toLowerCase()},o=r.data={},i=r.NATIVE="N",a=r.POLYFILL="P";return N1=r,N1}var F1,gR;function Eh(){if(gR)return F1;gR=1;var n=ls(),e=TF().f,t=CI(),r=RF(),s=vI(),o=Yq(),i=Xq();return F1=function(a,l){var c=a.target,u=a.global,h=a.stat,p,m,S,v,y,w;if(u?m=n:h?m=n[c]||s(c,{}):m=n[c]&&n[c].prototype,m)for(S in l){if(y=l[S],a.dontCallGetSet?(w=e(m,S),v=w&&w.value):v=m[S],p=i(u?S:c+(h?".":"#")+S,a.forced),!p&&v!==void 0){if(typeof y==typeof v)continue;o(y,v)}(a.sham||v&&v.sham)&&t(y,"sham",!0),r(m,S,y,a)}},F1}var z1={},B1,mR;function Zq(){if(mR)return B1;mR=1;var n=jF(),e=kI();return B1=Object.keys||function(r){return n(r,e)},B1}var yR;function Jq(){if(yR)return z1;yR=1;var n=uc(),e=_F(),t=ug(),r=Tu(),s=a0(),o=Zq();return z1.f=n&&!e?Object.defineProperties:function(a,l){r(a);for(var c=s(l),u=o(l),h=u.length,p=0,m;h>p;)t.f(a,m=u[p++],c[m]);return a},z1}var $1,SR;function Qq(){if(SR)return $1;SR=1;var n=l0();return $1=n("document","documentElement"),$1}var U1,xR;function LF(){if(xR)return U1;xR=1;var n=Tu(),e=Jq(),t=kI(),r=PI(),s=Qq(),o=EF(),i=AF(),a=">",l="<",c="prototype",u="script",h=i("IE_PROTO"),p=function(){},m=function(C){return l+u+a+C+l+"/"+u+a},S=function(C){C.write(m("")),C.close();var T=C.parentWindow.Object;return C=null,T},v=function(){var C=o("iframe"),T="java"+u+":",E;return C.style.display="none",s.appendChild(C),C.src=String(T),E=C.contentWindow.document,E.open(),E.write(m("document.F=Object")),E.close(),E.F},y,w=function(){try{y=new ActiveXObject("htmlfile")}catch{}w=typeof document<"u"?document.domain&&y?S(y):v():S(y);for(var C=t.length;C--;)delete w[c][t[C]];return w()};return r[h]=!0,U1=Object.create||function(T,E){var _;return T!==null?(p[c]=n(T),_=new p,p[c]=null,_[h]=T):_=w(),E===void 0?_:e.f(_,E)},U1}var H1,vR;function EI(){if(vR)return H1;vR=1;var n=el(),e=LF(),t=ug().f,r=n("unscopables"),s=Array.prototype;return s[r]===void 0&&t(s,r,{configurable:!0,value:e(null)}),H1=function(o){s[r][o]=!0},H1}var wR;function eY(){if(wR)return sO;wR=1;var n=Eh(),e=cg(),t=dg(),r=_u(),s=EI();return n({target:"Array",proto:!0},{at:function(i){var a=e(this),l=t(a),c=r(i),u=c>=0?c:l+c;return u<0||u>=l?void 0:a[u]}}),s("at"),sO}var K1,bR;function hg(){if(bR)return K1;bR=1;var n=ls(),e=er();return K1=function(t,r){return e(n[t].prototype[r])},K1}var W1,CR;function tY(){if(CR)return W1;CR=1,eY();var n=hg();return W1=n("Array","at"),W1}var V1,PR;function nY(){if(PR)return V1;PR=1;var n=tY();return V1=n,V1}nY();var kR={},G1,ER;function NF(){if(ER)return G1;ER=1;var n=Ph();return G1=Array.isArray||function(t){return n(t)==="Array"},G1}var q1,IR;function rY(){if(IR)return q1;IR=1;var n=TypeError,e=9007199254740991;return q1=function(t){if(t>e)throw n("Maximum allowed index exceeded");return t},q1}var Y1,TR;function sY(){if(TR)return Y1;TR=1;var n=Ph(),e=er();return Y1=function(t){if(n(t)==="Function")return e(t)},Y1}var X1,_R;function oY(){if(_R)return X1;_R=1;var n=sY(),e=SI(),t=i0(),r=n(n.bind);return X1=function(s,o){return e(s),o===void 0?s:t?r(s,o):function(){return s.apply(o,arguments)}},X1}var Z1,MR;function FF(){if(MR)return Z1;MR=1;var n=NF(),e=dg(),t=rY(),r=oY(),s=function(o,i,a,l,c,u,h,p){for(var m=c,S=0,v=h?r(h,p):!1,y,w;S<l;)S in a&&(y=v?v(a[S],S,i):a[S],u>0&&n(y)?(w=e(y),m=s(o,i,y,w,m,u-1)-1):(t(m+1),o[m]=y),m++),S++;return m};return Z1=s,Z1}var J1,AR;function iY(){if(AR)return J1;AR=1;var n=el(),e=n("toStringTag"),t={};return t[e]="z",J1=String(t)==="[object z]",J1}var Q1,OR;function zF(){if(OR)return Q1;OR=1;var n=iY(),e=us(),t=Ph(),r=el(),s=r("toStringTag"),o=Object,i=t(function(){return arguments}())==="Arguments",a=function(l,c){try{return l[c]}catch{}};return Q1=n?t:function(l){var c,u,h;return l===void 0?"Undefined":l===null?"Null":typeof(u=a(c=o(l),s))=="string"?u:i?t(c):(h=t(c))==="Object"&&e(c.callee)?"Arguments":h},Q1}var eC,RR;function aY(){if(RR)return eC;RR=1;var n=er(),e=cs(),t=us(),r=zF(),s=l0(),o=MF(),i=function(){},a=s("Reflect","construct"),l=/^\s*(?:class|function)\b/,c=n(l.exec),u=!l.test(i),h=function(S){if(!t(S))return!1;try{return a(i,[],S),!0}catch{return!1}},p=function(S){if(!t(S))return!1;switch(r(S)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return u||!!c(l,o(S))}catch{return!0}};return p.sham=!0,eC=!a||e(function(){var m;return h(h.call)||!h(Object)||!h(function(){m=!0})||m})?p:h,eC}var tC,DR;function lY(){if(DR)return tC;DR=1;var n=NF(),e=aY(),t=Qa(),r=el(),s=r("species"),o=Array;return tC=function(i){var a;return n(i)&&(a=i.constructor,e(a)&&(a===o||n(a.prototype))?a=void 0:t(a)&&(a=a[s],a===null&&(a=void 0))),a===void 0?o:a},tC}var nC,jR;function BF(){if(jR)return nC;jR=1;var n=lY();return nC=function(e,t){return new(n(e))(t===0?0:t)},nC}var LR;function cY(){if(LR)return kR;LR=1;var n=Eh(),e=FF(),t=SI(),r=cg(),s=dg(),o=BF();return n({target:"Array",proto:!0},{flatMap:function(a){var l=r(this),c=s(l),u;return t(a),u=o(l,0),u.length=e(u,l,l,c,0,1,a,arguments.length>1?arguments[1]:void 0),u}}),kR}var NR={},FR;function uY(){if(FR)return NR;FR=1;var n=EI();return n("flatMap"),NR}var rC,zR;function dY(){if(zR)return rC;zR=1,cY(),uY();var n=hg();return rC=n("Array","flatMap"),rC}var sC,BR;function hY(){if(BR)return sC;BR=1;var n=dY();return sC=n,sC}hY();var $R={},UR;function fY(){if(UR)return $R;UR=1;var n=Eh(),e=FF(),t=cg(),r=dg(),s=_u(),o=BF();return n({target:"Array",proto:!0},{flat:function(){var a=arguments.length?arguments[0]:void 0,l=t(this),c=r(l),u=o(l,0);return u.length=e(u,l,l,c,0,a===void 0?1:s(a)),u}}),$R}var HR={},KR;function pY(){if(KR)return HR;KR=1;var n=EI();return n("flat"),HR}var oC,WR;function gY(){if(WR)return oC;WR=1,fY(),pY();var n=hg();return oC=n("Array","flat"),oC}var iC,VR;function mY(){if(VR)return iC;VR=1;var n=gY();return iC=n,iC}mY();var GR={},aC,qR;function fg(){if(qR)return aC;qR=1;var n=zF(),e=String;return aC=function(t){if(n(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return e(t)},aC}var YR;function yY(){if(YR)return GR;YR=1;var n=Eh(),e=er(),t=kh(),r=_u(),s=fg(),o=cs(),i=e("".charAt),a=o(function(){return"𠮷".at(-2)!=="\uD842"});return n({target:"String",proto:!0,forced:a},{at:function(c){var u=s(t(this)),h=u.length,p=r(c),m=p>=0?p:h+p;return m<0||m>=h?void 0:i(u,m)}}),GR}var lC,XR;function SY(){if(XR)return lC;XR=1,yY();var n=hg();return lC=n("String","at"),lC}var cC,ZR;function xY(){if(ZR)return cC;ZR=1;var n=SY();return cC=n,cC}xY();var JR={},uC,QR;function $F(){if(QR)return uC;QR=1;var n=Tu();return uC=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},uC}var dC,eD;function vY(){if(eD)return dC;eD=1;var n=cs(),e=ls(),t=e.RegExp,r=n(function(){var i=t("a","y");return i.lastIndex=2,i.exec("abcd")!==null}),s=r||n(function(){return!t("a","y").sticky}),o=r||n(function(){var i=t("^r","gy");return i.lastIndex=2,i.exec("str")!==null});return dC={BROKEN_CARET:o,MISSED_STICKY:s,UNSUPPORTED_Y:r},dC}var hC,tD;function wY(){if(tD)return hC;tD=1;var n=cs(),e=ls(),t=e.RegExp;return hC=n(function(){var r=t(".","s");return!(r.dotAll&&r.test(`
71
+ `)&&r.flags==="s")}),hC}var fC,nD;function bY(){if(nD)return fC;nD=1;var n=cs(),e=ls(),t=e.RegExp;return fC=n(function(){var r=t("(?<a>b)","g");return r.exec("b").groups.a!=="b"||"b".replace(r,"$<a>c")!=="bc"}),fC}var pC,rD;function II(){if(rD)return pC;rD=1;var n=Ja(),e=er(),t=fg(),r=$F(),s=vY(),o=bI(),i=LF(),a=OF().get,l=wY(),c=bY(),u=o("native-string-replace",String.prototype.replace),h=RegExp.prototype.exec,p=h,m=e("".charAt),S=e("".indexOf),v=e("".replace),y=e("".slice),w=function(){var _=/a/,A=/b*/g;return n(h,_,"a"),n(h,A,"a"),_.lastIndex!==0||A.lastIndex!==0}(),C=s.BROKEN_CARET,T=/()??/.exec("")[1]!==void 0,E=w||T||C||l||c;return E&&(p=function(A){var O=this,D=a(O),F=t(A),U=D.raw,V,Y,j,N,z,G,q;if(U)return U.lastIndex=O.lastIndex,V=n(p,U,F),O.lastIndex=U.lastIndex,V;var $=D.groups,K=C&&O.sticky,J=n(r,O),H=O.source,te=0,he=F;if(K&&(J=v(J,"y",""),S(J,"g")===-1&&(J+="g"),he=y(F,O.lastIndex),O.lastIndex>0&&(!O.multiline||O.multiline&&m(F,O.lastIndex-1)!==`
72
+ `)&&(H="(?: "+H+")",he=" "+he,te++),Y=new RegExp("^(?:"+H+")",J)),T&&(Y=new RegExp("^"+H+"$(?!\\s)",J)),w&&(j=O.lastIndex),N=n(h,K?Y:O,he),K?N?(N.input=y(N.input,te),N[0]=y(N[0],te),N.index=O.lastIndex,O.lastIndex+=N[0].length):O.lastIndex=0:w&&N&&(O.lastIndex=O.global?N.index+N[0].length:j),T&&N&&N.length>1&&n(u,N[0],Y,function(){for(z=1;z<arguments.length-2;z++)arguments[z]===void 0&&(N[z]=void 0)}),N&&$)for(N.groups=G=i(null),z=0;z<$.length;z++)q=$[z],G[q[0]]=N[q[1]];return N}),pC=p,pC}var sD;function UF(){if(sD)return JR;sD=1;var n=Eh(),e=II();return n({target:"RegExp",proto:!0,forced:/./.exec!==e},{exec:e}),JR}var oD={},gC,iD;function CY(){if(iD)return gC;iD=1;var n=i0(),e=Function.prototype,t=e.apply,r=e.call;return gC=typeof Reflect=="object"&&Reflect.apply||(n?r.bind(t):function(){return r.apply(t,arguments)}),gC}var mC,aD;function PY(){if(aD)return mC;aD=1,UF();var n=Ja(),e=RF(),t=II(),r=cs(),s=el(),o=CI(),i=s("species"),a=RegExp.prototype;return mC=function(l,c,u,h){var p=s(l),m=!r(function(){var w={};return w[p]=function(){return 7},""[l](w)!==7}),S=m&&!r(function(){var w=!1,C=/a/;return l==="split"&&(C={},C.constructor={},C.constructor[i]=function(){return C},C.flags="",C[p]=/./[p]),C.exec=function(){return w=!0,null},C[p](""),!w});if(!m||!S||u){var v=/./[p],y=c(p,""[l],function(w,C,T,E,_){var A=C.exec;return A===t||A===a.exec?m&&!_?{done:!0,value:n(v,C,T,E)}:{done:!0,value:n(w,T,C,E)}:{done:!1}});e(String.prototype,l,y[0]),e(a,p,y[1])}h&&o(a[p],"sham",!0)},mC}var yC,lD;function kY(){if(lD)return yC;lD=1;var n=er(),e=_u(),t=fg(),r=kh(),s=n("".charAt),o=n("".charCodeAt),i=n("".slice),a=function(l){return function(c,u){var h=t(r(c)),p=e(u),m=h.length,S,v;return p<0||p>=m?l?"":void 0:(S=o(h,p),S<55296||S>56319||p+1===m||(v=o(h,p+1))<56320||v>57343?l?s(h,p):S:l?i(h,p,p+2):(S-55296<<10)+(v-56320)+65536)}};return yC={codeAt:a(!1),charAt:a(!0)},yC}var SC,cD;function EY(){if(cD)return SC;cD=1;var n=kY().charAt;return SC=function(e,t,r){return t+(r?n(e,t).length:1)},SC}var xC,uD;function HF(){if(uD)return xC;uD=1;var n=er(),e=cg(),t=Math.floor,r=n("".charAt),s=n("".replace),o=n("".slice),i=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,a=/\$([$&'`]|\d{1,2})/g;return xC=function(l,c,u,h,p,m){var S=u+l.length,v=h.length,y=a;return p!==void 0&&(p=e(p),y=i),s(m,y,function(w,C){var T;switch(r(C,0)){case"$":return"$";case"&":return l;case"`":return o(c,0,u);case"'":return o(c,S);case"<":T=p[o(C,1,-1)];break;default:var E=+C;if(E===0)return w;if(E>v){var _=t(E/10);return _===0?w:_<=v?h[_-1]===void 0?r(C,1):h[_-1]+r(C,1):w}T=h[E-1]}return T===void 0?"":T})},xC}var vC,dD;function IY(){if(dD)return vC;dD=1;var n=Ja(),e=Tu(),t=us(),r=Ph(),s=II(),o=TypeError;return vC=function(i,a){var l=i.exec;if(t(l)){var c=n(l,i,a);return c!==null&&e(c),c}if(r(i)==="RegExp")return n(s,i,a);throw new o("RegExp#exec called on incompatible receiver")},vC}var hD;function TY(){if(hD)return oD;hD=1;var n=CY(),e=Ja(),t=er(),r=PY(),s=cs(),o=Tu(),i=us(),a=Qa(),l=_u(),c=DF(),u=fg(),h=kh(),p=EY(),m=xI(),S=HF(),v=IY(),y=el(),w=y("replace"),C=Math.max,T=Math.min,E=t([].concat),_=t([].push),A=t("".indexOf),O=t("".slice),D=function(Y){return Y===void 0?Y:String(Y)},F=function(){return"a".replace(/./,"$0")==="$0"}(),U=function(){return/./[w]?/./[w]("a","$0")==="":!1}(),V=!s(function(){var Y=/./;return Y.exec=function(){var j=[];return j.groups={a:"7"},j},"".replace(Y,"$<a>")!=="7"});return r("replace",function(Y,j,N){var z=U?"$":"$0";return[function(q,$){var K=h(this),J=a(q)?m(q,w):void 0;return J?e(J,q,K,$):e(j,u(K),q,$)},function(G,q){var $=o(this),K=u(G);if(typeof q=="string"&&A(q,z)===-1&&A(q,"$<")===-1){var J=N(j,$,K,q);if(J.done)return J.value}var H=i(q);H||(q=u(q));var te=$.global,he;te&&(he=$.unicode,$.lastIndex=0);for(var Pe=[],ue;ue=v($,K),!(ue===null||(_(Pe,ue),!te));){var Ae=u(ue[0]);Ae===""&&($.lastIndex=p(K,c($.lastIndex),he))}for(var ze="",ve=0,Te=0;Te<Pe.length;Te++){ue=Pe[Te];for(var je=u(ue[0]),At=C(T(l(ue.index),K.length),0),on=[],_t,Ot=1;Ot<ue.length;Ot++)_(on,D(ue[Ot]));var an=ue.groups;if(H){var rr=E([je],on,At,K);an!==void 0&&_(rr,an),_t=u(n(q,void 0,rr))}else _t=S(je,K,At,on,an,q);At>=ve&&(ze+=O(K,ve,At)+_t,ve=At+je.length)}return ze+O(K,ve)}]},!V||!F||U),oD}var fD={},wC,pD;function _Y(){if(pD)return wC;pD=1;var n=Qa(),e=Ph(),t=el(),r=t("match");return wC=function(s){var o;return n(s)&&((o=s[r])!==void 0?!!o:e(s)==="RegExp")},wC}var bC,gD;function MY(){if(gD)return bC;gD=1;var n=Ja(),e=dc(),t=xF(),r=$F(),s=RegExp.prototype;return bC=function(o){var i=o.flags;return i===void 0&&!("flags"in s)&&!e(o,"flags")&&t(s,o)?n(r,o):i},bC}var mD;function AY(){if(mD)return fD;mD=1;var n=Eh(),e=Ja(),t=er(),r=kh(),s=us(),o=Qa(),i=_Y(),a=fg(),l=xI(),c=MY(),u=HF(),h=el(),p=CF(),m=h("replace"),S=TypeError,v=t("".indexOf),y=t("".replace),w=t("".slice),C=Math.max;return n({target:"String",proto:!0},{replaceAll:function(E,_){var A=r(this),O,D,F,U,V,Y,j,N,z,G,q=0,$="";if(o(E)){if(O=i(E),O&&(D=a(r(c(E))),!~v(D,"g")))throw new S("`.replaceAll` does not allow non-global regexes");if(F=l(E,m),F)return e(F,E,A,_);if(p&&O)return y(a(A),E,_)}for(U=a(A),V=a(E),Y=s(_),Y||(_=a(_)),j=V.length,N=C(1,j),z=v(U,V);z!==-1;)G=Y?a(_(V,z,U)):u(V,U,z,[],void 0,_),$+=w(U,q,z)+G,q=z+j,z=z+N>U.length?-1:v(U,V,z+N);return q<U.length&&($+=w(U,q)),$}}),fD}var CC,yD;function OY(){if(yD)return CC;yD=1,UF(),TY(),AY();var n=hg();return CC=n("String","replaceAll"),CC}var PC,SD;function RY(){if(SD)return PC;SD=1;var n=OY();return PC=n,PC}RY();function KF(n){return n&&typeof n=="object"&&"parents"in n}function WF(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 _S(n,e){if(n.children.remove(e)&&n.children.isEmpty&&KF(n))for(let t=0,r=n.parents.length;t<r;t++)_S(n.parents[t],n)}function TI(n,e){if(n.children.add(e)&&KF(n))for(let t=0,r=n.parents.length;t<r;t++)TI(n.parents[t],n)}function VF(n,e){return n===e||Object.is(n,e)||!!(n&&e&&typeof n.equals=="function"&&n.equals(e))}function hc(n,e){const t=Symbol.for(`com.tldraw.state/${n}`),r=globalThis;return r[t]??(r[t]=e()),r[t]}const jr=hc("empty_array",()=>Object.freeze([])),xD=8;class MS{constructor(){R(this,"arraySize",0);R(this,"array",Array(xD));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<xD?(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 eo=Symbol.for("com.tldraw.state/RESET_VALUE");class GF{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===eo){this.clear();return}this.buffer[this.index]=[e,t,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){const{index:t,capacity:r,buffer:s}=this;for(let o=0;o<r;o++){const i=(t-1+r-o)%r,a=s[i];if(!a)return eo;const[l,c]=a;if(o===0&&e>=c)return[];if(l<=e&&e<c){const u=o+1,h=new Array(u);for(let p=0;p<u;p++)h[p]=s[(i+p)%r][2];return h}}return eo}}const Wl=-1;class DY{constructor(e,t,r){R(this,"_isActivelyListening",!1);R(this,"lastTraversedEpoch",Wl);R(this,"lastReactedEpoch",Wl);R(this,"_scheduleCount",0);R(this,"__debug_ancestor_epochs__",null);R(this,"parentSet",new MS);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!==Is()){if(this.parents.length&&!WF(this)){this.lastReactedEpoch=Is();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++)TI(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,t=this.parents.length;e<t;e++)_S(this.parents[e],this)}execute(){try{ZF(this);const e=Is(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,t}finally{JF()}}}const Mu=hc("EffectScheduler",()=>DY);function jo(n,e,t){const r=new Mu(n,e,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function jY(n,e,t){const r=new Mu(n,e,t);return{scheduler:r,start:s=>{const o=(s==null?void 0:s.force)??!1;r.attach(),o?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}let LY=class{constructor(e){R(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(It.globalIsReacting)for(const e of this.initialAtomValues.keys())YF(e);else this.isRoot?qF(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,e)})}abort(){It.globalEpoch++,this.initialAtomValues.forEach((e,t)=>{var r;t.set(e),(r=t.historyBuffer)==null||r.clear()}),this.commit()}};const It=hc("transactions",()=>({globalEpoch:Wl+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Wl+1}));function NY(){return It.reactionEpoch}function Is(){return It.globalEpoch}function FY(){return It.globalIsReacting}function _I(n,e){e.lastTraversedEpoch!==It.globalEpoch&&(e.lastTraversedEpoch=It.globalEpoch,e instanceof Mu?n.add(e):e.children.visit(t=>_I(n,t)))}function qF(n){var t;if(It.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=It.currentTransaction;try{It.currentTransaction=null,It.globalIsReacting=!0,It.reactionEpoch=It.globalEpoch;const r=new Set;for(const o of n)o.children.visit(i=>_I(r,i));for(const o of r)o.maybeScheduleEffect();let s=0;for(;(t=It.cleanupReactors)!=null&&t.size;){if(s++>1e3)throw new Error("Reaction update depth limit exceeded");const o=It.cleanupReactors;It.cleanupReactors=null;for(const i of o)i.maybeScheduleEffect()}}finally{It.cleanupReactors=null,It.globalIsReacting=!1,It.currentTransaction=e}}function zY(n,e){It.currentTransaction?It.currentTransaction.initialAtomValues.has(n)||It.currentTransaction.initialAtomValues.set(n,e):It.globalIsReacting?YF(n):qF([n])}function YF(n){const e=It.cleanupReactors??(It.cleanupReactors=new Set);n.children.visit(t=>_I(e,t))}function BY(){It.globalEpoch++}function $Y(n){const e=new LY(It.currentTransaction);It.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{It.currentTransaction=It.currentTransaction.parent}}function to(n){return It.currentTransaction?n():$Y(n)}let vD=!1;function UY(){vD||(vD=!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 Ar=Symbol.for("com.tldraw.state/UNINITIALIZED");function ru(n){return n===Ar}const Pk=hc("WithDiff",()=>class{constructor(e,t){this.value=e,this.diff=t}});function Uf(n,e){return new Pk(n,e)}class HY{constructor(e,t,r){R(this,"lastChangedEpoch",Wl);R(this,"lastTraversedEpoch",Wl);R(this,"__debug_ancestor_epochs__",null);R(this,"lastCheckedEpoch",Wl);R(this,"parentSet",new MS);R(this,"parents",[]);R(this,"parentEpochs",[]);R(this,"children",new MS);R(this,"historyBuffer");R(this,"state",Ar);R(this,"error",null);R(this,"computeDiff");R(this,"isEqual");this.name=e,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new GF(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??VF}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var s;const t=this.lastChangedEpoch===Wl,r=Is();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&FY()&&this.lastTraversedEpoch<NY()||!WF(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{ZF(this);const o=this.derive(this.state,this.lastCheckedEpoch),i=o instanceof Pk?o.value:o,a=this.state===Ar;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=o instanceof Pk?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Is(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,i,this.lastCheckedEpoch,Is()))??eo)}this.lastChangedEpoch=Is(),this.state=i}return this.error=null,this.lastCheckedEpoch=Is(),this.state}catch(o){if(this.state!==Ar&&(this.state=Ar,this.lastChangedEpoch=Is()),this.lastCheckedEpoch=Is(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!e)throw o;return this.state}finally{JF()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{AS(this)}}getDiffSince(e){var t;return this.__unsafe__getWithoutCapture(!0),AS(this),e>=this.lastChangedEpoch?jr:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??eo}}const pg=hc("Computed",()=>HY);function KY(n={},e,t,r){const s=r.value,o=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let i=this[o];return i||(i=new pg(t,s.bind(this),n),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[XF]=!0,r}function WY(n={},e,t,r){const s=r.get,o=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let i=this[o];return i||(i=new pg(t,s.bind(this),n),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function VY(n,e,t){Ve(t.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(t.name)),s=function(){let o=this[r];return o||(o=new pg(String(t.name),e.bind(this),n),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()};return s[XF]=!0,s}function wD(n={},e){if(e.length===2){const[t,r]=e;return VY(n,t,r)}else{const[t,r,s]=e;return s.get?(UY(),WY(n,t,r,s)):KY(n,t,r,s)}}const XF="@@__isComputedMethod__@@";function le(){if(arguments.length===1){const n=arguments[0];return(...e)=>wD(n,e)}else return typeof arguments[0]=="string"?new pg(arguments[0],arguments[1],arguments[2]):wD(void 0,arguments)}function MI(n){return n&&n instanceof pg}class GY{constructor(e,t){R(this,"offset",0);R(this,"maybeRemoved");this.below=e,this.child=t}}const nn=hc("capture",()=>({stack:null}));function Hf(n){const e=nn.stack;nn.stack=null;try{return n()}finally{nn.stack=e}}function ZF(n){if(nn.stack=new GY(nn.stack,n),n.__debug_ancestor_epochs__){const e=n.__debug_ancestor_epochs__;n.__debug_ancestor_epochs__=null;for(const t of n.parents)t.__unsafe__getWithoutCapture(!0);qY(n,e)}n.parentSet.clear()}function JF(){const n=nn.stack;if(nn.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)||_S(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)||_S(t,n.child)}n.child.__debug_ancestor_epochs__&&QF(n.child,n.child.__debug_ancestor_epochs__)}function AS(n){if(nn.stack){if(nn.stack.child.parentSet.has(n))return;if(nn.stack.child.parentSet.add(n),nn.stack.child.isActivelyListening&&TI(n,nn.stack.child),nn.stack.offset<nn.stack.child.parents.length){const t=nn.stack.child.parents[nn.stack.offset];t!==n&&(nn.stack.maybeRemoved?nn.stack.maybeRemoved.push(t):nn.stack.maybeRemoved=[t])}nn.stack.child.parents[nn.stack.offset]=n,nn.stack.child.parentEpochs[nn.stack.offset]=n.lastChangedEpoch,nn.stack.offset++}}function QF(n,e){for(let t=0;t<n.parents.length;t++){const r=n.parents[t],s=n.parentEpochs[t];e.set(r,s),MI(r)&&QF(r,e)}return e}function e5(n,e){const t={};for(let r=0;r<n.parents.length;r++){const s=n.parents[r];if(!e.has(s))continue;const o=e.get(s);s.lastChangedEpoch!==o&&(MI(s)?t[s.name]=e5(s,e):t[s.name]=null)}return t}function qY(n,e){const t=e5(n,e);if(Object.keys(t).length===0){console.log(`Effect(${n.name}) was executed manually.`);return}let r=MI(n)?`Computed(${n.name}) is recomputing because:`:`Effect(${n.name}) is executing because:`;function s(o,i){const a=`
86
+ `+" ".repeat(i)+"↳ ";for(const[l,c]of Object.entries(o))c?(r+=`${a}Computed(${l}) changed`,s(c,i+2)):r+=`${a}Atom(${l}) changed`}s(t,1),console.log(r)}class YY{constructor(e,t,r){R(this,"isEqual");R(this,"computeDiff");R(this,"lastChangedEpoch",Is());R(this,"children",new MS);R(this,"historyBuffer");this.name=e,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new GF(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return AS(this),this.current}set(e,t){var s,o;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,e))??VF(this.current,e))return this.current;BY(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Is(),t??((o=this.computeDiff)==null?void 0:o.call(this,this.current,e,this.lastChangedEpoch,Is()))??eo),this.lastChangedEpoch=Is();const r=this.current;return this.current=e,zY(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var t;return AS(this),e>=this.lastChangedEpoch?jr:((t=this.historyBuffer)==null?void 0:t.getChangesSince(e))??eo}}const XY=hc("Atom",()=>YY);function hn(n,e,t){return new XY(n,e,t)}const t5=1,ZY=hc("apiVersion",()=>t5);if(ZY!==t5)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");lc("@tldraw/state","3.13.1","esm");function c0(n,e,t=[]){const r=We.useRef(e);r.current=e;const[s,o,i]=We.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),c=new Mu(`useStateTracking(${n})`,()=>{var h;return(h=r.current)==null?void 0:h.call(r)},{scheduleEffect(){a==null||a()}});return[c,l,()=>c.scheduleCount]},[n,...t]);return We.useSyncExternalStore(o,i,i),We.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const bD={apply(n,e,t){return c0(n.displayName??n.name??"tracked(???)",()=>n.apply(e,t))}},JY=Symbol.for("react.memo"),QY=Symbol.for("react.forward_ref");function tr(n){let e=null;const t=n.$$typeof;return t===JY&&(n=n.type,e=n.compare),t===QY?k.memo(k.forwardRef(new Proxy(n.render,bD))):k.memo(new Proxy(n,bD),e)}function gg(n,e,t){return k.useState(()=>{const r=typeof e=="function"?e():e;return hn(`useAtom(${n})`,r,t)})[0]}function eX(){const n=arguments[0],e=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return k.useMemo(()=>le(`useComputed(${n})`,e,t),r)}function ec(n,e,t=jr){k.useEffect(()=>{const r=new Mu(n,e);return r.attach(),r.execute(),()=>{r.detach()}},t)}function u0(n,e,t=[]){const r=k.useRef(-1),s=k.useMemo(()=>new Mu(n,e,{scheduleEffect:o=>{const i=requestAnimationFrame(o);return r.current=i,i}}),t);k.useEffect(()=>(s.attach(),s.execute(),()=>{s.detach(),cancelAnimationFrame(r.current)}),[s])}function se(){const n=arguments,e=n.length===3?n[2]:[n[0]],t=n.length===3?n[0]:`useValue(${n[0].name})`,r=k.useRef(!0);r.current=!0;const s=k.useMemo(()=>n.length===1?n[0]:le(t,()=>{if(r.current)return n[1]();try{return n[1]()}catch{return{}}}),e);try{const{subscribe:o,getSnapshot:i}=k.useMemo(()=>({subscribe:a=>jo(`useValue(${t})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return k.useSyncExternalStore(o,i,i)}finally{r.current=!1}}lc("@tldraw/state-react","3.13.1","esm");/*!
87
+ * This file was lovingly and delicately extracted from Immutable.js
88
+ * MIT License: https://github.com/immutable-js/immutable-js/blob/main/LICENSE
89
+ * Copyright (c) 2014-present, Lee Byron and other contributors.
90
+ */function AI(n){return n>>>1&1073741824|n&3221225471}const tX=Object.prototype.valueOf;function du(n){if(n==null)return CD(n);if(typeof n.hashCode=="function")return AI(n.hashCode(n));const e=iX(n);if(e==null)return CD(e);switch(typeof e){case"boolean":return e?1108378657:1108378656;case"number":return nX(e);case"string":return e.length>aX?rX(e):kk(e);case"object":case"function":return oX(e);case"symbol":return sX(e);default:if(typeof e.toString=="function")return kk(e.toString());throw new Error("Value type "+typeof e+" cannot be hashed.")}}function CD(n){return n===null?1108378658:1108378659}function nX(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 AI(e)}function rX(n){let e=IC[n];return e===void 0&&(e=kk(n),EC===lX&&(EC=0,IC={}),EC++,IC[n]=e),e}function kk(n){let e=0;for(let t=0;t<n.length;t++)e=31*e+n.charCodeAt(t)|0;return AI(e)}function sX(n){let e=kD[n];return e!==void 0||(e=n5(),kD[n]=e),e}function oX(n){let e=PD.get(n);return e!==void 0||(e=n5(),PD.set(n,e)),e}function iX(n){return n.valueOf!==tX&&typeof n.valueOf=="function"?n.valueOf(n):n}function n5(){const n=++kC;return kC&1073741824&&(kC=0),n}const PD=new WeakMap,kD=Object.create(null);let kC=0;const aX=16,lX=255;let EC=0,IC={};const ih=5,mg=1<<ih,ah=mg-1,Ka={};function ED(){return{value:!1}}function li(n){n&&(n.value=!0)}function OI(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 lh=Object.is;class r5{}class RI{constructor(e){R(this,"_root");R(this,"size");R(this,"__ownerID");R(this,"__hash");R(this,"__altered");return e==null?Vd():e instanceof RI?e:Vd().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 _D(this,e,t)}delete(e){return _D(this,e,Ka)}deleteAll(e){return this.withMutations(t=>{for(const r of e)t.delete(r)})}__ensureOwner(e){return e===this.__ownerID?this:e?LI(this.size,this._root,e,this.__hash):this.size===0?Vd():(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 r5)}[Symbol.iterator](){return this.entries()[Symbol.iterator]()}entries(){return new TC(this,cX,!1)}keys(){return new TC(this,s5,!1)}values(){return new TC(this,o5,!1)}}class DI{constructor(e,t){this.ownerID=e,this.entries=t}get(e,t,r,s){const o=this.entries;for(let i=0,a=o.length;i<a;i++)if(lh(r,o[i][0]))return o[i][1];return s}update(e,t,r,s,o,i,a){const l=o===Ka,c=this.entries;let u=0;const h=c.length;for(;u<h&&!lh(s,c[u][0]);u++);const p=u<h;if(p?c[u][1]===o:l)return this;if(li(a),(l||!p)&&li(i),l&&c.length===1)return;if(!p&&!l&&c.length>=yX)return hX(e,c,s,o);const m=e&&e===this.ownerID,S=m?c:OI(c);return p?l?u===h-1?S.pop():S[u]=S.pop():S[u]=[s,o]:S.push([s,o]),m?(this.entries=S,this):new DI(e,S)}}class d0{constructor(e,t,r){this.ownerID=e,this.bitmap=t,this.nodes=r}get(e,t,r,s){t===void 0&&(t=du(r));const o=1<<((e===0?t:t>>>e)&ah),i=this.bitmap;return(i&o)===0?s:this.nodes[AD(i&o-1)].get(e+ih,t,r,s)}update(e,t,r,s,o,i,a){r===void 0&&(r=du(s));const l=(t===0?r:r>>>t)&ah,c=1<<l,u=this.bitmap,h=(u&c)!==0;if(!h&&o===Ka)return this;const p=AD(u&c-1),m=this.nodes,S=h?m[p]:void 0,v=NI(S,e,t+ih,r,s,o,i,a);if(v===S)return this;if(!h&&v&&m.length>=SX)return pX(e,m,u,l,v);if(h&&!v&&m.length===2&&MD(m[p^1]))return m[p^1];if(h&&v&&m.length===1&&MD(v))return v;const y=e&&e===this.ownerID,w=h?v?u:u^c:u|c,C=h?v?i5(m,p,v,y):mX(m,p,y):gX(m,p,v,y);return y?(this.bitmap=w,this.nodes=C,this):new d0(e,w,C)}}class jI{constructor(e,t,r){this.ownerID=e,this.count=t,this.nodes=r}get(e,t,r,s){t===void 0&&(t=du(r));const o=(e===0?t:t>>>e)&ah,i=this.nodes[o];return i?i.get(e+ih,t,r,s):s}update(e,t,r,s,o,i,a){r===void 0&&(r=du(s));const l=(t===0?r:r>>>t)&ah,c=o===Ka,u=this.nodes,h=u[l];if(c&&!h)return this;const p=NI(h,e,t+ih,r,s,o,i,a);if(p===h)return this;let m=this.count;if(!h)m++;else if(!p&&(m--,m<xX))return fX(e,u,m,l);const S=e&&e===this.ownerID,v=i5(u,l,p,S);return S?(this.count=m,this.nodes=v,this):new jI(e,m,v)}}class h0{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entries=r}get(e,t,r,s){const o=this.entries;for(let i=0,a=o.length;i<a;i++)if(lh(r,o[i][0]))return o[i][1];return s}update(e,t,r,s,o,i,a){r===void 0&&(r=du(s));const l=o===Ka;if(r!==this.keyHash)return l?this:(li(a),li(i),FI(this,e,t,r,[s,o]));const c=this.entries;let u=0;const h=c.length;for(;u<h&&!lh(s,c[u][0]);u++);const p=u<h;if(p?c[u][1]===o:l)return this;if(li(a),(l||!p)&&li(i),l&&h===2)return new Au(e,this.keyHash,c[u^1]);const m=e&&e===this.ownerID,S=m?c:OI(c);return p?l?u===h-1?S.pop():S[u]=S.pop():S[u]=[s,o]:S.push([s,o]),m?(this.entries=S,this):new h0(e,this.keyHash,S)}}class Au{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entry=r}get(e,t,r,s){return lh(r,this.entry[0])?this.entry[1]:s}update(e,t,r,s,o,i,a){const l=o===Ka,c=lh(s,this.entry[0]);if(c?o===this.entry[1]:l)return this;if(li(a),l){li(i);return}return c?e&&e===this.ownerID?(this.entry[1]=o,this):new Au(e,this.keyHash,[s,o]):(li(i),FI(this,e,t,du(s),[s,o]))}}class TC{constructor(e,t,r){R(this,"_stack");this._type=t,this._reverse=r,this._stack=e._root&&ID(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 o;if(r.entry){if(s===0)return _C(e,r.entry)}else if("entries"in r&&r.entries){if(o=r.entries.length-1,s<=o)return _C(e,r.entries[this._reverse?o-s:s])}else if(o=r.nodes.length-1,s<=o){const i=r.nodes[this._reverse?o-s:s];if(i){if(i.entry)return _C(e,i.entry);t=this._stack=ID(i,t)}continue}t=this._stack=this._stack.__prev}return dX()}}function _C(n,e){return uX(n,e[0],e[1])}function ID(n,e){return{node:n,index:0,__prev:e}}const s5=0,o5=1,cX=2;function uX(n,e,t,r){const s=n===s5?e:n===o5?t:[e,t];return r?r.value=s:r={value:s,done:!1},r}function dX(){return{value:void 0,done:!0}}function LI(n,e,t,r){const s=Object.create(RI.prototype);return s.size=n,s._root=e,s.__ownerID=t,s.__hash=r,s.__altered=!1,s}let TD;function Vd(){return TD||(TD=LI(0))}function _D(n,e,t){let r,s;if(n._root){const o=ED(),i=ED();if(r=NI(n._root,n.__ownerID,0,void 0,e,t,o,i),!i.value)return n;s=n.size+(o.value?t===Ka?-1:1:0)}else{if(t===Ka)return n;s=1,r=new DI(n.__ownerID,[[e,t]])}return n.__ownerID?(n.size=s,n._root=r,n.__hash=void 0,n.__altered=!0,n):r?LI(s,r):Vd()}function NI(n,e,t,r,s,o,i,a){return n?n.update(e,t,r,s,o,i,a):o===Ka?n:(li(a),li(i),new Au(e,r,[s,o]))}function MD(n){return n.constructor===Au||n.constructor===h0}function FI(n,e,t,r,s){if(n.keyHash===r)return new h0(e,r,[n.entry,s]);const o=(t===0?n.keyHash:n.keyHash>>>t)&ah,i=(t===0?r:r>>>t)&ah;let a;const l=o===i?[FI(n,e,t+ih,r,s)]:(a=new Au(e,r,s),o<i?[n,a]:[a,n]);return new d0(e,1<<o|1<<i,l)}function hX(n,e,t,r){n||(n=new r5);let s=new Au(n,du(t),[t,r]);for(let o=0;o<e.length;o++){const i=e[o];s=s.update(n,0,void 0,i[0],i[1])}return s}function fX(n,e,t,r){let s=0,o=0;const i=new Array(t);for(let a=0,l=1,c=e.length;a<c;a++,l<<=1){const u=e[a];u!==void 0&&a!==r&&(s|=l,i[o++]=u)}return new d0(n,s,i)}function pX(n,e,t,r,s){let o=0;const i=new Array(mg);for(let a=0;t!==0;a++,t>>>=1)i[a]=t&1?e[o++]:void 0;return i[r]=s,new jI(n,o+1,i)}function AD(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 i5(n,e,t,r){const s=r?n:OI(n);return s[e]=t,s}function gX(n,e,t,r){const s=n.length+1;if(r&&e+1===s)return n[e]=t,n;const o=new Array(s);let i=0;for(let a=0;a<s;a++)a===e?(o[a]=t,i=-1):o[a]=n[a+i];return o}function mX(n,e,t){const r=n.length-1;if(t&&e===r)return n.pop(),n;const s=new Array(r);let o=0;for(let i=0;i<r;i++)i===e&&(o=1),s[i]=n[i+o];return s}const yX=mg/4,SX=mg/2,xX=mg/4;var F3,z3;class Ek{constructor(e,t){R(this,"atoms");R(this,F3,"AtomMap");this.name=e;let r=Vd();t&&(r=r.withMutations(s=>{for(const[o,i]of t)s.set(o,hn(`${e}:${String(o)}`,i))})),this.atoms=hn(`${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 Ve(t!==Ar),t}__unsafe__getWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t)return;const r=t.__unsafe__getWithoutCapture();return Ve(r!==Ar),r}has(e){const t=this.getAtom(e);return t?t.get()!==Ar:!1}__unsafe__hasWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(Ve(t.__unsafe__getWithoutCapture()!==Ar),!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,hn(`${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();Ve(s!==Ar),r.set(t(s))}delete(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(to(()=>{t.set(Ar),this.atoms.update(r=>r.delete(e))}),!0):!1}deleteMany(e){return to(()=>{const t=[],r=this.atoms.get().withMutations(s=>{for(const o of e){const i=s.get(o);if(!i)continue;const a=i.get();Ve(a!==Ar),t.push([o,a]),s.delete(o),i.set(Ar)}});return t.length&&this.atoms.set(r),t})}clear(){return to(()=>{for(const e of this.atoms.__unsafe__getWithoutCapture().values())e.set(Ar);this.atoms.set(Vd())})}*entries(){for(const[e,t]of this.atoms.get()){const r=t.get();Ve(r!==Ar),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();Ve(t!==Ar),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)}[(z3=Symbol.iterator,F3=Symbol.toStringTag,z3)](){return this.entries()}}class Ky{constructor(e){R(this,"nextValue");R(this,"diff");this.previousValue=e}get(){var r,s,o,i;const e=((s=(r=this.diff)==null?void 0:r.removed)==null?void 0:s.size)??0,t=((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.size)??0;if(!(e===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(e,t){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(e),this.diff??(this.diff={}),t?(r=this.diff.removed)==null||r.delete(e):((s=this.diff).added??(s.added=new Set),this.diff.added.add(e))}add(e){var s,o,i;const t=this.previousValue.has(e);if(t)return((o=(s=this.diff)==null?void 0:s.removed)==null?void 0:o.has(e))?this._add(e,t):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,t)}_remove(e,t){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(e),this.diff??(this.diff={}),t?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(e)):(s=this.diff.added)==null||s.delete(e)}remove(e){var s,o,i,a;const t=this.previousValue.has(e);if(!t)return((o=(s=this.diff)==null?void 0:s.added)==null?void 0:o.has(e))?this._remove(e,t):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(e)||this._remove(e,t)}}class f0{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,o]of Qr(t.ephemeralKeys))o&&r.add(s);this.ephemeralKeySet=r}create(e){const t={...this.createDefaultProperties(),id:"id"in e?e.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{...en(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??Mt())}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 f0(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 ra(n,e){return new f0(n,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function OS(){return{added:{},updated:{},removed:{}}}function Ik(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 a5(n){return Object.keys(n.added).length===0&&Object.keys(n.updated).length===0&&Object.keys(n.removed).length===0}function zI(n){const e={added:{},removed:{},updated:{}};return hp(e,n),e}function hp(n,e){for(const t of e){for(const[r,s]of Qr(t.added))if(n.removed[r]){const o=n.removed[r];delete n.removed[r],o!==s&&(n.updated[r]=[o,s])}else n.added[r]=s;for(const[r,[s,o]]of Qr(t.updated)){if(n.added[r]){n.added[r]=o,delete n.updated[r],delete n.removed[r];continue}if(n.updated[r]){n.updated[r]=[n.updated[r][0],o],delete n.removed[r];continue}n.updated[r]=t.updated[r],delete n.removed[r]}for(const[r,s]of Qr(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 Kf={exports:{}};Kf.exports;var OD;function vX(){return OD||(OD=1,function(n,e){var t=200,r="__lodash_hash_undefined__",s=1,o=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",p="[object Error]",m="[object Function]",S="[object GeneratorFunction]",v="[object Map]",y="[object Number]",w="[object Null]",C="[object Object]",T="[object Promise]",E="[object Proxy]",_="[object RegExp]",A="[object Set]",O="[object String]",D="[object Symbol]",F="[object Undefined]",U="[object WeakMap]",V="[object ArrayBuffer]",Y="[object DataView]",j="[object Float32Array]",N="[object Float64Array]",z="[object Int8Array]",G="[object Int16Array]",q="[object Int32Array]",$="[object Uint8Array]",K="[object Uint8ClampedArray]",J="[object Uint16Array]",H="[object Uint32Array]",te=/[\\^$.*+?()[\]{}|]/g,he=/^\[object .+?Constructor\]$/,Pe=/^(?:0|[1-9]\d*)$/,ue={};ue[j]=ue[N]=ue[z]=ue[G]=ue[q]=ue[$]=ue[K]=ue[J]=ue[H]=!0,ue[a]=ue[l]=ue[V]=ue[u]=ue[Y]=ue[h]=ue[p]=ue[m]=ue[v]=ue[y]=ue[C]=ue[_]=ue[A]=ue[O]=ue[U]=!1;var Ae=typeof Os=="object"&&Os&&Os.Object===Object&&Os,ze=typeof self=="object"&&self&&self.Object===Object&&self,ve=Ae||ze||Function("return this")(),Te=e&&!e.nodeType&&e,je=Te&&!0&&n&&!n.nodeType&&n,At=je&&je.exports===Te,on=At&&Ae.process,_t=function(){try{return on&&on.binding&&on.binding("util")}catch{}}(),Ot=_t&&_t.isTypedArray;function an(B,ee){for(var fe=-1,Oe=B==null?0:B.length,Rt=0,tt=[];++fe<Oe;){var Wt=B[fe];ee(Wt,fe,B)&&(tt[Rt++]=Wt)}return tt}function rr(B,ee){for(var fe=-1,Oe=ee.length,Rt=B.length;++fe<Oe;)B[Rt+fe]=ee[fe];return B}function Hr(B,ee){for(var fe=-1,Oe=B==null?0:B.length;++fe<Oe;)if(ee(B[fe],fe,B))return!0;return!1}function zs(B,ee){for(var fe=-1,Oe=Array(B);++fe<B;)Oe[fe]=ee(fe);return Oe}function $n(B){return function(ee){return B(ee)}}function ps(B,ee){return B.has(ee)}function gs(B,ee){return B==null?void 0:B[ee]}function wc(B){var ee=-1,fe=Array(B.size);return B.forEach(function(Oe,Rt){fe[++ee]=[Rt,Oe]}),fe}function Nu(B,ee){return function(fe){return B(ee(fe))}}function Fu(B){var ee=-1,fe=Array(B.size);return B.forEach(function(Oe){fe[++ee]=Oe}),fe}var zu=Array.prototype,Bu=Function.prototype,Pi=Object.prototype,Vo=ve["__core-js_shared__"],bc=Bu.toString,ae=Pi.hasOwnProperty,Ce=function(){var B=/[^.]+$/.exec(Vo&&Vo.keys&&Vo.keys.IE_PROTO||"");return B?"Symbol(src)_1."+B:""}(),Je=Pi.toString,jt=RegExp("^"+bc.call(ae).replace(te,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),po=At?ve.Buffer:void 0,ms=ve.Symbol,aa=ve.Uint8Array,Bs=Pi.propertyIsEnumerable,$s=zu.splice,ys=ms?ms.toStringTag:void 0,Us=Object.getOwnPropertySymbols,Ss=po?po.isBuffer:void 0,Go=Nu(Object.keys,Object),$u=ua(ve,"DataView"),al=ua(ve,"Map"),Uu=ua(ve,"Promise"),Hu=ua(ve,"Set"),Ku=ua(ve,"WeakMap"),la=ua(Object,"create"),Vg=vr($u),Cc=vr(al),Bh=vr(Uu),Pc=vr(Hu),Ov=vr(Ku),ll=ms?ms.prototype:void 0,cl=ll?ll.valueOf:void 0;function go(B){var ee=-1,fe=B==null?0:B.length;for(this.clear();++ee<fe;){var Oe=B[ee];this.set(Oe[0],Oe[1])}}function $h(){this.__data__=la?la(null):{},this.size=0}function Rv(B){var ee=this.has(B)&&delete this.__data__[B];return this.size-=ee?1:0,ee}function Dv(B){var ee=this.__data__;if(la){var fe=ee[B];return fe===r?void 0:fe}return ae.call(ee,B)?ee[B]:void 0}function jv(B){var ee=this.__data__;return la?ee[B]!==void 0:ae.call(ee,B)}function ca(B,ee){var fe=this.__data__;return this.size+=this.has(B)?0:1,fe[B]=la&&ee===void 0?r:ee,this}go.prototype.clear=$h,go.prototype.delete=Rv,go.prototype.get=Dv,go.prototype.has=jv,go.prototype.set=ca;function mo(B){var ee=-1,fe=B==null?0:B.length;for(this.clear();++ee<fe;){var Oe=B[ee];this.set(Oe[0],Oe[1])}}function Gg(){this.__data__=[],this.size=0}function Lv(B){var ee=this.__data__,fe=Gu(ee,B);if(fe<0)return!1;var Oe=ee.length-1;return fe==Oe?ee.pop():$s.call(ee,fe,1),--this.size,!0}function qg(B){var ee=this.__data__,fe=Gu(ee,B);return fe<0?void 0:ee[fe][1]}function Yg(B){return Gu(this.__data__,B)>-1}function Xg(B,ee){var fe=this.__data__,Oe=Gu(fe,B);return Oe<0?(++this.size,fe.push([B,ee])):fe[Oe][1]=ee,this}mo.prototype.clear=Gg,mo.prototype.delete=Lv,mo.prototype.get=qg,mo.prototype.has=Yg,mo.prototype.set=Xg;function ki(B){var ee=-1,fe=B==null?0:B.length;for(this.clear();++ee<fe;){var Oe=B[ee];this.set(Oe[0],Oe[1])}}function Nv(){this.size=0,this.__data__={hash:new go,map:new(al||mo),string:new go}}function Fv(B){var ee=wt(this,B).delete(B);return this.size-=ee?1:0,ee}function ln(B){return wt(this,B).get(B)}function zv(B){return wt(this,B).has(B)}function Uh(B,ee){var fe=wt(this,B),Oe=fe.size;return fe.set(B,ee),this.size+=fe.size==Oe?0:1,this}ki.prototype.clear=Nv,ki.prototype.delete=Fv,ki.prototype.get=ln,ki.prototype.has=zv,ki.prototype.set=Uh;function kc(B){var ee=-1,fe=B==null?0:B.length;for(this.__data__=new ki;++ee<fe;)this.add(B[ee])}function Wu(B){return this.__data__.set(B,r),this}function Bv(B){return this.__data__.has(B)}kc.prototype.add=kc.prototype.push=Wu,kc.prototype.has=Bv;function qo(B){var ee=this.__data__=new mo(B);this.size=ee.size}function Vu(){this.__data__=new mo,this.size=0}function yo(B){var ee=this.__data__,fe=ee.delete(B);return this.size=ee.size,fe}function $v(B){return this.__data__.get(B)}function Hs(B){return this.__data__.has(B)}function Uv(B,ee){var fe=this.__data__;if(fe instanceof mo){var Oe=fe.__data__;if(!al||Oe.length<t-1)return Oe.push([B,ee]),this.size=++fe.size,this;fe=this.__data__=new ki(Oe)}return fe.set(B,ee),this.size=fe.size,this}qo.prototype.clear=Vu,qo.prototype.delete=yo,qo.prototype.get=$v,qo.prototype.has=Hs,qo.prototype.set=Uv;function Hv(B,ee){var fe=Ti(B),Oe=!fe&&Tc(B),Rt=!fe&&!Oe&&Vh(B),tt=!fe&&!Oe&&!Rt&&qh(B),Wt=fe||Oe||Rt||tt,wn=Wt?zs(B.length,String):[],Vt=wn.length;for(var zt in B)ae.call(B,zt)&&!(Wt&&(zt=="length"||Rt&&(zt=="offset"||zt=="parent")||tt&&(zt=="buffer"||zt=="byteLength"||zt=="byteOffset")||Qg(zt,Vt)))&&wn.push(zt);return wn}function Gu(B,ee){for(var fe=B.length;fe--;)if(Xo(B[fe][0],ee))return fe;return-1}function qu(B,ee,fe){var Oe=ee(B);return Ti(B)?Oe:rr(Oe,fe(B))}function Ei(B){return B==null?B===void 0?F:w:ys&&ys in Object(B)?Jg(B):Ii(B)}function ul(B){return Mi(B)&&Ei(B)==a}function Ec(B,ee,fe,Oe,Rt){return B===ee?!0:B==null||ee==null||!Mi(B)&&!Mi(ee)?B!==B&&ee!==ee:Kv(B,ee,fe,Oe,Ec,Rt)}function Kv(B,ee,fe,Oe,Rt,tt){var Wt=Ti(B),wn=Ti(ee),Vt=Wt?l:Yo(B),zt=wn?l:Yo(ee);Vt=Vt==a?C:Vt,zt=zt==a?C:zt;var Un=Vt==C,xs=zt==C,bn=Vt==zt;if(bn&&Vh(B)){if(!Vh(ee))return!1;Wt=!0,Un=!1}if(bn&&!Un)return tt||(tt=new qo),Wt||qh(B)?Yu(B,ee,fe,Oe,Rt,tt):Ic(B,ee,Vt,fe,Oe,Rt,tt);if(!(fe&s)){var sr=Un&&ae.call(B,"__wrapped__"),Kr=xs&&ae.call(ee,"__wrapped__");if(sr||Kr){var gn=sr?B.value():B,wr=Kr?ee.value():ee;return tt||(tt=new qo),Rt(gn,wr,fe,Oe,tt)}}return bn?(tt||(tt=new qo),Vv(B,ee,fe,Oe,Rt,tt)):!1}function Wv(B){if(!Gh(B)||Wh(B))return!1;var ee=dl(B)?jt:he;return ee.test(vr(B))}function Hh(B){return Mi(B)&&nm(B.length)&&!!ue[Ei(B)]}function Zg(B){if(!Zu(B))return Go(B);var ee=[];for(var fe in Object(B))ae.call(B,fe)&&fe!="constructor"&&ee.push(fe);return ee}function Yu(B,ee,fe,Oe,Rt,tt){var Wt=fe&s,wn=B.length,Vt=ee.length;if(wn!=Vt&&!(Wt&&Vt>wn))return!1;var zt=tt.get(B);if(zt&&tt.get(ee))return zt==ee;var Un=-1,xs=!0,bn=fe&o?new kc:void 0;for(tt.set(B,ee),tt.set(ee,B);++Un<wn;){var sr=B[Un],Kr=ee[Un];if(Oe)var gn=Wt?Oe(Kr,sr,Un,ee,B,tt):Oe(sr,Kr,Un,B,ee,tt);if(gn!==void 0){if(gn)continue;xs=!1;break}if(bn){if(!Hr(ee,function(wr,Zo){if(!ps(bn,Zo)&&(sr===wr||Rt(sr,wr,fe,Oe,tt)))return bn.push(Zo)})){xs=!1;break}}else if(!(sr===Kr||Rt(sr,Kr,fe,Oe,tt))){xs=!1;break}}return tt.delete(B),tt.delete(ee),xs}function Ic(B,ee,fe,Oe,Rt,tt,Wt){switch(fe){case Y:if(B.byteLength!=ee.byteLength||B.byteOffset!=ee.byteOffset)return!1;B=B.buffer,ee=ee.buffer;case V:return!(B.byteLength!=ee.byteLength||!tt(new aa(B),new aa(ee)));case u:case h:case y:return Xo(+B,+ee);case p:return B.name==ee.name&&B.message==ee.message;case _:case O:return B==ee+"";case v:var wn=wc;case A:var Vt=Oe&s;if(wn||(wn=Fu),B.size!=ee.size&&!Vt)return!1;var zt=Wt.get(B);if(zt)return zt==ee;Oe|=o,Wt.set(B,ee);var Un=Yu(wn(B),wn(ee),Oe,Rt,tt,Wt);return Wt.delete(B),Un;case D:if(cl)return cl.call(B)==cl.call(ee)}return!1}function Vv(B,ee,fe,Oe,Rt,tt){var Wt=fe&s,wn=Xu(B),Vt=wn.length,zt=Xu(ee),Un=zt.length;if(Vt!=Un&&!Wt)return!1;for(var xs=Vt;xs--;){var bn=wn[xs];if(!(Wt?bn in ee:ae.call(ee,bn)))return!1}var sr=tt.get(B);if(sr&&tt.get(ee))return sr==ee;var Kr=!0;tt.set(B,ee),tt.set(ee,B);for(var gn=Wt;++xs<Vt;){bn=wn[xs];var wr=B[bn],Zo=ee[bn];if(Oe)var hl=Wt?Oe(Zo,wr,bn,ee,B,tt):Oe(wr,Zo,bn,B,ee,tt);if(!(hl===void 0?wr===Zo||Rt(wr,Zo,fe,Oe,tt):hl)){Kr=!1;break}gn||(gn=bn=="constructor")}if(Kr&&!gn){var Ju=B.constructor,fl=ee.constructor;Ju!=fl&&"constructor"in B&&"constructor"in ee&&!(typeof Ju=="function"&&Ju instanceof Ju&&typeof fl=="function"&&fl instanceof fl)&&(Kr=!1)}return tt.delete(B),tt.delete(ee),Kr}function Xu(B){return qu(B,Gv,Kh)}function wt(B,ee){var fe=B.__data__;return em(ee)?fe[typeof ee=="string"?"string":"hash"]:fe.map}function ua(B,ee){var fe=gs(B,ee);return Wv(fe)?fe:void 0}function Jg(B){var ee=ae.call(B,ys),fe=B[ys];try{B[ys]=void 0;var Oe=!0}catch{}var Rt=Je.call(B);return Oe&&(ee?B[ys]=fe:delete B[ys]),Rt}var Kh=Us?function(B){return B==null?[]:(B=Object(B),an(Us(B),function(ee){return Bs.call(B,ee)}))}:_c,Yo=Ei;($u&&Yo(new $u(new ArrayBuffer(1)))!=Y||al&&Yo(new al)!=v||Uu&&Yo(Uu.resolve())!=T||Hu&&Yo(new Hu)!=A||Ku&&Yo(new Ku)!=U)&&(Yo=function(B){var ee=Ei(B),fe=ee==C?B.constructor:void 0,Oe=fe?vr(fe):"";if(Oe)switch(Oe){case Vg:return Y;case Cc:return v;case Bh:return T;case Pc:return A;case Ov:return U}return ee});function Qg(B,ee){return ee=ee??i,!!ee&&(typeof B=="number"||Pe.test(B))&&B>-1&&B%1==0&&B<ee}function em(B){var ee=typeof B;return ee=="string"||ee=="number"||ee=="symbol"||ee=="boolean"?B!=="__proto__":B===null}function Wh(B){return!!Ce&&Ce in B}function Zu(B){var ee=B&&B.constructor,fe=typeof ee=="function"&&ee.prototype||Pi;return B===fe}function Ii(B){return Je.call(B)}function vr(B){if(B!=null){try{return bc.call(B)}catch{}try{return B+""}catch{}}return""}function Xo(B,ee){return B===ee||B!==B&&ee!==ee}var Tc=ul(function(){return arguments}())?ul:function(B){return Mi(B)&&ae.call(B,"callee")&&!Bs.call(B,"callee")},Ti=Array.isArray;function _i(B){return B!=null&&nm(B.length)&&!dl(B)}var Vh=Ss||Mc;function tm(B,ee){return Ec(B,ee)}function dl(B){if(!Gh(B))return!1;var ee=Ei(B);return ee==m||ee==S||ee==c||ee==E}function nm(B){return typeof B=="number"&&B>-1&&B%1==0&&B<=i}function Gh(B){var ee=typeof B;return B!=null&&(ee=="object"||ee=="function")}function Mi(B){return B!=null&&typeof B=="object"}var qh=Ot?$n(Ot):Hh;function Gv(B){return _i(B)?Hv(B):Zg(B)}function _c(){return[]}function Mc(){return!1}n.exports=tm}(Kf,Kf.exports)),Kf.exports}var wX=vX();const Ih=Za(wX);function bX(n){if(n.length===0)return new Set;const e=n[0],t=n.slice(1),r=new Set;for(const s of e)t.every(o=>o.has(s))&&r.add(s);return r}function CX(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 RD(n,e){for(const[t,r]of Object.entries(n)){const s=r,o=e[t];if("eq"in s&&o!==s.eq||"neq"in s&&o===s.neq||"gt"in s&&(typeof o!="number"||o<=s.gt))return!1}return!0}function DD(n,e,t){const r=Object.fromEntries(Object.keys(t).map(s=>[s,new Set]));for(const[s,o]of Object.entries(t))if("eq"in o){const a=n.index(e,s).get().get(o.eq);if(a)for(const l of a)r[s].add(l)}else if("neq"in o){const i=n.index(e,s);for(const[a,l]of i.get())if(a!==o.neq)for(const c of l)r[s].add(c)}else if("gt"in o){const i=n.index(e,s);for(const[a,l]of i.get())if(a>o.gt)for(const c of l)r[s].add(c)}return bX(Object.values(r))}class PX{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(ru(r))return this.history.get();const o=this.history.getDiffSince(s);if(o===eo)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of o){for(const h of Sn(u.added))if(h.typeName===e)if(i.removed[h.id]){const p=i.removed[h.id];delete i.removed[h.id],l--,p!==h&&(i.updated[h.id]=[p,h],c++)}else i.added[h.id]=h,a++;for(const[h,p]of Sn(u.updated))p.typeName===e&&(i.added[p.id]?i.added[p.id]=p:i.updated[p.id]?i.updated[p.id]=[i.updated[p.id][0],p]:(i.updated[p.id]=[h,p],c++));for(const h of Sn(u.removed))h.typeName===e&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?Uf(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(e,t),t}index(e,t){const r=e+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const s=this.__uncached_createIndex(e,t);return this.indexCache.set(r,s),s}__uncached_createIndex(e,t){const r=this.filterHistory(e),s=()=>{r.get();const o=new Map;for(const i of this.recordMap.values())if(i.typeName===e){const a=i[t];o.has(a)||o.set(a,new Set),o.get(a).add(i.id)}return o};return le("index:"+e+":"+t,(o,i)=>{if(ru(o))return s();const a=r.getDiffSince(i);if(a===eo)return s();const l=new Map,c=(m,S)=>{let v=l.get(m);v||(v=new Ky(o.get(m)??new Set)),v.add(S),l.set(m,v)},u=(m,S)=>{let v=l.get(m);v||(v=new Ky(o.get(m)??new Set)),v.remove(S),l.set(m,v)};for(const m of a){for(const S of Sn(m.added))if(S.typeName===e){const v=S[t];c(v,S.id)}for(const[S,v]of Sn(m.updated))if(v.typeName===e){const y=S[t],w=v[t];y!==w&&(u(y,v.id),c(w,v.id))}for(const S of Sn(m.removed))if(S.typeName===e){const v=S[t];u(v,S.id)}}let h,p;for(const[m,S]of l){const v=S.get();v&&(h||(h=new Map(o)),p||(p=new Map),v.value.size===0?h.delete(m):h.set(m,v.value),p.set(m,v.diff))}return h&&p?Uf(h,p):o},{historyLength:100})}record(e,t=()=>({}),r="record:"+e+(t?":"+t.toString():"")){const s=this.ids(e,t,r);return le(r,()=>{for(const o of s.get())return this.recordMap.get(o)})}records(e,t=()=>({}),r="records:"+e+(t?":"+t.toString():"")){const s=this.ids(e,t,"ids:"+r);return le(r,()=>Array.from(s.get(),o=>this.recordMap.get(o)),{isEqual:ES})}ids(e,t=()=>({}),r="ids:"+e+(t?":"+t.toString():"")){const s=this.filterHistory(e),o=()=>{s.get();const l=t();if(Object.keys(l).length===0){const c=new Set;for(const u of this.recordMap.values())u.typeName===e&&c.add(u.id);return c}return DD(this,e,l)},i=l=>{const c=o(),u=CX(l,c);return u?Uf(c,u):l},a=le("ids_query:"+r,t,{isEqual:Ih});return le("query:"+r,(l,c)=>{const u=a.get();if(ru(l))return o();if(c<a.lastChangedEpoch)return i(l);const h=s.getDiffSince(c);if(h===eo)return i(l);const p=new Ky(l);for(const S of h){for(const v of Sn(S.added))v.typeName===e&&RD(u,v)&&p.add(v.id);for(const[v,y]of Sn(S.updated))y.typeName===e&&(RD(u,y)?p.add(y.id):p.remove(y.id));for(const v of Sn(S.removed))v.typeName===e&&p.remove(v.id)}const m=p.get();return m?Uf(m.value,m.diff):l},{historyLength:50})}exec(e,t){const r=DD(this,e,t);return r.size===0?jr:Array.from(r,s=>this.recordMap.get(s))}}class kX{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 o of r)s=o(s,t);return s}return e}handleAfterCreate(e,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const s of r)s(e,t)}handleBeforeChange(e,t,r){if(!this._isEnabled)return t;const s=this._beforeChangeHandlers[t.typeName];if(s){let o=t;for(const i of s)o=i(e,o,r);return o}return t}handleAfterChange(e,t,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[t.typeName];if(s)for(const o of s)o(e,t,r)}handleBeforeDelete(e,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const s of r)if(s(e,t)===!1)return!1}return!0}handleAfterDelete(e,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const s of r)s(e,t)}handleOperationComplete(e){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(e)}register(e){const t=[];for(const[r,s]of Object.entries(e))s!=null&&s.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,s.beforeCreate)),s!=null&&s.afterCreate&&t.push(this.registerAfterCreateHandler(r,s.afterCreate)),s!=null&&s.beforeChange&&t.push(this.registerBeforeChangeHandler(r,s.beforeChange)),s!=null&&s.afterChange&&t.push(this.registerAfterChangeHandler(r,s.afterChange)),s!=null&&s.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,s.beforeDelete)),s!=null&&s.afterDelete&&t.push(this.registerAfterDeleteHandler(r,s.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(e,t){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(t),()=>Hc(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>Hc(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>Hc(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>Hc(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>Hc(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>Hc(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Hc(this._operationCompleteHandlers,e)}}function Hc(n,e){const t=n.indexOf(e);t>=0&&n.splice(t,1)}class BI{constructor(e){R(this,"id");R(this,"records");R(this,"history",hn("history",0,{historyLength:1e3}));R(this,"query");R(this,"listeners",new Set);R(this,"historyAccumulator",new IX);R(this,"historyReactor");R(this,"schema");R(this,"props");R(this,"scopedTypes");R(this,"sideEffects",new kX(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??Mt(),this.schema=r,this.props=e.props,t?this.records=new Ek("store",Qr(t).map(([o,i])=>[o,this.schema.validateRecord(this,i,"initialize",null)])):this.records=new Ek("store"),this.query=new PX(this.records,this.history),this.historyReactor=jY("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>this.cancelHistoryReactor=gF(o)}),this.scopedTypes={document:new Set(Sn(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(Sn(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(Sn(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}cancelHistoryReactor(){}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:t,source:r}of e){let s=null,o=null,i=null;for(const{onHistory:a,filters:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(o??(o=this.filterChangesByScope(t,"document")),!o)continue;a({changes:o,source:r})}else if(l.scope==="session"){if(s??(s=this.filterChangesByScope(t,"session")),!s)continue;a({changes:s,source:r})}else{if(i??(i=this.filterChangesByScope(t,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,t){const r={added:dp(e.added,(s,o)=>this.scopedTypes[t].has(o.typeName)),updated:dp(e.updated,(s,o)=>this.scopedTypes[t].has(o[1].typeName)),removed:dp(e.removed,(s,o)=>this.scopedTypes[t].has(o.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(e){this.historyAccumulator.add({changes:e,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,e)}validate(e){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,e,null))}put(e,t){this.atomic(()=>{const r={},s={};let o,i=!1;const a=this.isMergingRemoteChanges?"remote":"user";for(let l=0,c=e.length;l<c;l++){o=e[l];const u=this.records.__unsafe__getWithoutCapture(o.id);if(u){if(o=this.sideEffects.handleBeforeChange(u,o,a),this.schema.validateRecord(this,o,t??"updateRecord",u)===u)continue;o=o,this.records.set(o.id,o),i=!0,r[o.id]=[u,o],this.addDiffForAfterEvent(u,o)}else o=this.sideEffects.handleBeforeCreate(o,a),i=!0,o=this.schema.validateRecord(this,o,t??"createRecord",null),o=o,s[o.id]=o,this.addDiffForAfterEvent(null,o),this.records.set(o.id,o)}i&&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 i of e){const a=this.records.__unsafe__getWithoutCapture(i);a&&this.sideEffects.handleBeforeDelete(a,r)===!1&&t.delete(i)}const s=this.records.deleteMany(t);if(s.length===0)return;const o={};for(const[i,a]of s)o[i]=a,this.addDiffForAfterEvent(a,null);this.updateHistory({added:{},updated:{},removed:o})})}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.atomic(e,!0,!0)}finally{this.ensureStoreIsUsable()}}extractingChanges(e){const t=[],r=this.historyAccumulator.addInterceptor(s=>t.push(s.changes));try{return to(e),zI(t)}finally{r()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=Sn(e.added);for(const[i,a]of Sn(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){s.push(a);continue}let u=null;for(const[h,p]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(p,kn(c,h))||(u||(u={...c}),u[h]=p);u&&s.push(u)}else s.push(a)}const o=Z3(e.removed);s.length&&this.put(s),o.length&&this.remove(o)},t)}createCache(e){const t=new zo;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,o)=>{const i=r!=null&&r.areRecordsEqual?le(`${e}:${s}:isEqual`,()=>o.get(),{isEqual:r.areRecordsEqual}):o;return le(e+":"+s,()=>t(i.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(Ve(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&Ve(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(e){let t=0,r=e?"remote":"user";for(;this.pendingAfterEvents;){const s=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(t++,t>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:o,after:i}of s.values())o&&i&&o!==i&&!Ih(o,i)?this.sideEffects.handleAfterChange(o,i,r):o&&!i?this.sideEffects.handleAfterDelete(o,r):!o&&i&&this.sideEffects.handleAfterCreate(i,r);this.pendingAfterEvents?r="user":this.sideEffects.handleOperationComplete(r)}}}atomic(e,t=!0,r=!1){return to(()=>{if(this._isInAtomicOp){this.pendingAfterEvents||(this.pendingAfterEvents=new Map);const o=this.sideEffects.isEnabled();Ve(!r,"cannot call mergeRemoteChanges while in atomic operation");try{return o&&!t&&this.sideEffects.setIsEnabled(!1),e()}finally{this.sideEffects.setIsEnabled(o)}}this.pendingAfterEvents=new Map;const s=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t??s),this._isInAtomicOp=!0,r&&(this.isMergingRemoteChanges=!0);try{const o=e();return this.isMergingRemoteChanges=!1,this.flushAtomicCallbacks(r),o}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(s),this._isInAtomicOp=!1,this.isMergingRemoteChanges=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(t=>e(t,this.isMergingRemoteChanges?"remote":"user"))}}function EX(n){if(n.length===0)return[];const e=[];let t=[n[0]],r;for(let s=1,o=n.length;s<o;s++)r=n[s],t[0].source!==r.source&&(e.push(t),t=[]),t.push(r);return e.push(t),e.map(s=>({source:s[0].source,changes:zI(s.map(o=>o.changes))}))}class IX{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=EX(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function p0(n,e,t){const r=new zo;return{get(s,o){return r.get(s,()=>(s instanceof BI?s:s.store).createComputedCache(n,l=>e(s,l),t)).get(o)}}}function TX(n){const e=[];for(let t=n.length-1;t>=0;t--){const r=n[t];if("id"in r)e.unshift(r);else{const s=r.dependsOn,o=e[0];o&&(e[0]={...o,dependsOn:s.concat(o.dependsOn??[])})}}return e}function Gd({sequence:n,sequenceId:e,retroactive:t=!0}){const r={sequenceId:e,retroactive:t,sequence:TX(n)};return l5(r),r}function Ls(n,e){return Object.fromEntries(Qr(e).map(([t,r])=>[t,`${n}/${r}`]))}function co(n){const e=n.sequenceId;return Gd({sequenceId:e,retroactive:n.retroactive??!0,sequence:n.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>{var s,o;return r.typeName===n.recordType&&(((s=t.filter)==null?void 0:s.call(t,r))??!0)&&(((o=n.filter)==null?void 0:o.call(n,r))??!0)}}:t)})}function _X(n){const e=new Map(n.map(o=>[o.id,o])),t=new Set,r=[];function s(o){Ve(!t.has(o.id),`Circular dependency in migrations: ${o.id}`),t.add(o.id);const{version:i,sequenceId:a}=RS(o.id),l=e.get(`${a}/${i-1}`);if(l&&s(l),o.dependsOn)for(const c of o.dependsOn){const u=e.get(c);u&&s(u)}e.delete(o.id),r.push(o)}for(const o of e.values())s(o);return r}function RS(n){const[e,t]=n.split("/");return{sequenceId:e,version:parseInt(t)}}function jD(n,e){e&&Ve(n.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${n}'`),Ve(n.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${n}'`)}function l5(n){if(Ve(!n.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${n.sequenceId}`),Ve(n.sequenceId.length,"sequenceId must be a non-empty string"),n.sequence.length===0)return;jD(n.sequence[0].id,n.sequenceId);let e=RS(n.sequence[0].id).version;Ve(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;jD(r,n.sequenceId);const s=RS(r).version;Ve(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 Dl=(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))(Dl||{});function MX(n){if(n.schemaVersion>2||n.schemaVersion<1)return Gr.err("Bad schema version");if(n.schemaVersion===2)return Gr.ok(n);const e={schemaVersion:2,sequences:{"com.tldraw.store":n.storeVersion}};for(const[t,r]of Object.entries(n.recordVersions))if(e.sequences[`com.tldraw.${t}`]=r.version,"subTypeKey"in r)for(const[s,o]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${t}.${s}`]=o;return Gr.ok(e)}class $I{constructor(e,t){R(this,"migrations",{});R(this,"sortedMigrations");var s;this.types=e,this.options=t;for(const o of t.migrations??[])Ve(!this.migrations[o.sequenceId],`Duplicate migration sequenceId ${o.sequenceId}`),l5(o),this.migrations[o.sequenceId]=o;const r=Object.values(this.migrations).flatMap(o=>o.sequence);this.sortedMigrations=_X(r);for(const o of this.sortedMigrations)if((s=o.dependsOn)!=null&&s.length)for(const i of o.dependsOn){const a=r.find(l=>l.id===i);Ve(a,`Migration '${o.id}' depends on missing migration '${i}'`)}}static create(e,t){return new $I(e,t??{})}validateRecord(e,t,r,s){try{const o=kn(this.types,t.typeName);if(!o)throw new Error(`Missing definition for record type ${t.typeName}`);return o.validate(t,s??void 0)}catch(o){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:t,phase:r,recordBefore:s,error:o});throw o}}getMigrationsSince(e){const t=MX(e);if(!t.ok)return t;const r=t.value,s=new Set(Object.keys(r.sequences).filter(i=>this.migrations[i]));for(const i in this.migrations)r.sequences[i]===void 0&&this.migrations[i].retroactive&&s.add(i);if(s.size===0)return Gr.ok([]);const o=new Set;for(const i of s){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)o.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return Gr.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))o.add(u.id)}return Gr.ok(this.sortedMigrations.filter(({id:i})=>o.has(i)))}migratePersistedRecord(e,t,r="up"){const s=this.getMigrationsSince(t);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:Dl.MigrationError};let o=s.value;if(o.length===0)return{type:"success",value:e};if(o.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?Dl.TargetVersionTooOld:Dl.TargetVersionTooNew};if(r==="down"){if(!o.every(i=>i.down))return{type:"error",reason:Dl.TargetVersionTooOld};o=o.slice().reverse()}e=en(e);try{for(const i of o){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(e):!0))continue;const l=i[r](e);l&&(e=en(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Dl.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:Dl.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:t};t=en(t);try{for(const o of s)if(o.scope==="record")for(const[i,a]of Object.entries(t)){if(!(o.filter?o.filter(a):!0))continue;const c=o.up(a);c&&(t[i]=en(c))}else if(o.scope==="store"){const i=o.up(t);i&&(t=en(i))}else xt(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Dl.MigrationError}}return{type:"success",value:t}}createIntegrityChecker(e){var t,r;return((r=(t=this.options).createIntegrityChecker)==null?void 0:r.call(t,e))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:t})=>[e,t.length?RS(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const t=kn(this.types,e);return Ve(t,"record type does not exists"),t}}lc("@tldraw/store","3.13.1","esm");function AX(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=AX(r),o=t.split(`
91
+ `).map((i,a)=>a===0?i:` ${i}`).join(`
92
+ `);super(r?`At ${s}: ${o}`:o);R(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Ds(n,e){try{return e()}catch(t){throw t instanceof vt?new vt(t.rawMessage,[n,...t.path]):new vt(t.toString(),[n])}}function tc(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:xt(e)}}class Fr{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 FX(this)}optional(){return u5(this)}refine(e){return new Fr(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=>(Ds(`(check ${e})`,()=>t(r)),r)):this.refine(r=>(e(r),r))}}class OX extends Fr{constructor(e){super(t=>{const r=LD.validate(t);for(let s=0;s<r.length;s++)Ds(s,()=>e.validate(r[s]));return r},(t,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=LD.validate(r);let o=t.length!==s.length;for(let i=0;i<s.length;i++){const a=s[i];if(i>=t.length){o=!0,Ds(i,()=>e.validate(a));continue}if(Object.is(t[i],a))continue;const l=Ds(i,()=>e.validateUsingKnownGoodVersion(t[i],a));Object.is(l,t[i])||(o=!0)}return o?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 DS extends Fr{constructor(e,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new vt(`Expected object, got ${tc(r)}`);for(const[s,o]of Object.entries(e))Ds(s,()=>{o.validate(kn(r,s))});if(!t){for(const s of Object.keys(r))if(!Do(e,s))throw new vt("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new vt(`Expected object, got ${tc(s)}`);let o=!1;for(const[i,a]of Object.entries(e)){const l=kn(r,i),c=kn(s,i);if(Object.is(l,c))continue;const u=Ds(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(o=!0)}if(!t){for(const i of Object.keys(s))if(!Do(e,i))throw new vt("Unexpected property",[i])}for(const i of Object.keys(r))if(!Do(s,i)){o=!0;break}return o?s:r}),this.config=e,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new DS(this.config,!0)}extend(e){return new DS({...this.config,...e})}}class g0 extends Fr{constructor(e,t,r,s){super(o=>{this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(o);return i===void 0?this.unknownValueValidation(o,a):Ds(`(${e} = ${a})`,()=>i.validate(o))},(o,i)=>{this.expectObject(i),this.expectObject(o);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):kn(o,e)!==kn(i,e)?Ds(`(${e} = ${l})`,()=>a.validate(i)):Ds(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(o,i):a.validate(i))}),this.key=e,this.config=t,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(e){if(typeof e!="object"||e===null)throw new vt(`Expected an object, got ${tc(e)}`,[])}getMatchingSchemaAndVariant(e){const t=kn(e,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new vt(`Expected a string for key "${this.key}", got ${tc(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new vt(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:Do(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(e){return new g0(this.key,this.config,e,this.useNumberKeys)}}class RX extends Fr{constructor(e,t){super(r=>{if(typeof r!="object"||r===null)throw new vt(`Expected object, got ${tc(r)}`);for(const[s,o]of Object.entries(r))Ds(s,()=>{e.validate(s),t.validate(o)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new vt(`Expected object, got ${tc(s)}`);let o=!1;for(const[i,a]of Object.entries(s)){if(!Do(r,i)){o=!0,Ds(i,()=>{e.validate(i),t.validate(a)});continue}const l=kn(r,i),c=a;if(Object.is(l,c))continue;const u=Ds(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,c):t.validate(c));Object.is(u,l)||(o=!0)}for(const i of Object.keys(r))if(!Do(s,i)){o=!0;break}return o?s:r}),this.keyValidator=e,this.valueValidator=t}}function UI(n){return new Fr(e=>{if(typeof e!==n)throw new vt(`Expected ${n}, got ${tc(e)}`);return e})}const DX=new Fr(n=>n),jX=new Fr(n=>n),it=UI("string"),Ze=UI("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}`)}),jS=Ze.check(n=>{if(n<0)throw new vt(`Expected a positive number, got ${n}`)}),Tn=Ze.check(n=>{if(n<=0)throw new vt(`Expected a non-zero positive number, got ${n}`)}),c5=Ze.check(n=>{if(!Number.isInteger(n))throw new vt(`Expected an integer, got ${n}`)}),Wy=c5.check(n=>{if(n<0)throw new vt(`Expected a positive integer, got ${n}`)}),LX=c5.check(n=>{if(n<=0)throw new vt(`Expected a non-zero positive integer, got ${n}`)}),St=UI("boolean");function Nr(n){return new Fr(e=>{if(e!==n)throw new vt(`Expected ${n}, got ${JSON.stringify(e)}`);return n})}const LD=new Fr(n=>{if(!Array.isArray(n))throw new vt(`Expected an array, got ${tc(n)}`);return n});function Gn(n){return new OX(n)}function mt(n){return new DS(n)}function Tk(n){return typeof n=="object"&&n!==null&&(Object.getPrototypeOf(n)===Object.prototype||Object.getPrototypeOf(n)===null||Object.getPrototypeOf(n)===Oq)}function _k(n){return n===null||typeof n=="number"||typeof n=="string"||typeof n=="boolean"?!0:Array.isArray(n)?n.every(_k):Tk(n)?Object.values(n).every(_k):!1}const fr=new Fr(n=>{if(_k(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,fr.validate(e[r]);continue}const s=n[r],o=e[r];if(Object.is(s,o))continue;const i=fr.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(t=!0)}return t?e:n}else if(Tk(n)&&Tk(e)){let t=!1;for(const r of Object.keys(e)){if(!Do(n,r)){t=!0,fr.validate(e[r]);continue}const s=n[r],o=e[r];if(Object.is(s,o))continue;const i=fr.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(t=!0)}for(const r of Object.keys(n))if(!Do(e,r)){t=!0;break}return t?e:n}else return fr.validate(e)});function LS(n,e){return new RX(n,e)}function HI(n,e){return new g0(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 NX(n,e){return new g0(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 sa(n,e){return new Fr(t=>Ds(n,()=>e.validate(t)),(t,r)=>Ds(n,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(t,r):e.validate(r)))}function m0(n){return new Fr(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 u5(n){return new Fr(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 FX(n){return new Fr(e=>e===null?null:n.validate(e),(e,t)=>t===null?null:n.validateUsingKnownGoodVersion&&e!==null?n.validateUsingKnownGoodVersion(e,t):n.validate(t))}function Th(...n){return m0(new Set(n))}function KI(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 zX=new Set(["http:","https:","mailto:"]),ao=it.check(n=>{if(n==="")return;const e=KI(n);if(!zX.has(e.protocol.toLowerCase()))throw new vt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)}),BX=new Set(["http:","https:","data:","asset:"]),hu=it.check(n=>{if(n==="")return;const e=KI(n);if(!BX.has(e.protocol.toLowerCase()))throw new vt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});it.check(n=>{if(n==="")return;if(!KI(n).protocol.toLowerCase().match(/^https?:$/))throw new vt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});const WI=it.refine(n=>{try{return bq(n),n}catch{throw new vt(`Expected an index key, got ${JSON.stringify(n)}`)}});lc("@tldraw/validate","3.13.1","esm");function no(n){return it.refine(e=>{if(!e.startsWith(`${n}:`))throw new Error(`${n} ID must start with "${n}:"`);return e})}const y0=no("asset");function VI(n,e){return mt({id:y0,typeName:Nr("asset"),type:Nr(n),props:e,meta:fr})}const fu=mt({x:Ze,y:Ze,z:Ze.optional()}),fp=mt({x:Ze,y:Ze,w:Ze,h:Ze}),d5=Ze.check(n=>{if(n<0||n>1)throw new vt("Opacity must be between 0 and 1")}),$X=it.refine(n=>{if(!n.startsWith("page:")&&!n.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return n}),Eo=no("shape");function UX(n,e,t){return mt({id:Eo,typeName:Nr("shape"),x:Ze,y:Ze,rotation:Ze,index:WI,parentId:$X,type:Nr(n),isLocked:St,opacity:d5,props:e?mt(e):fr,meta:t?mt(t):fr})}const HX=no("binding");function KX(n,e,t){return mt({id:HX,typeName:Nr("binding"),type:Nr(n),fromId:Eo,toId:Eo,props:e?mt(e):fr,meta:t?mt(t):fr})}Ls("com.tldraw.binding",{});co({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function su(n){return`binding:${Mt()}`}function WX(n,e){return cc(e,(t,r)=>`com.tldraw.binding.${n}/${r}`)}function VX(n){return ra("binding",{scope:"document",validator:sa("binding",HI("type",cc(n,(e,{props:t,meta:r})=>KX(e,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class nr{constructor(e,t,r){this.id=e,this.defaultValue=t,this.type=r}static define(e,t){const{defaultValue:r,type:s=jX}=t;return new nr(e,r,s)}static defineEnum(e,t){const{defaultValue:r,values:s}=t;return new GX(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 GX extends nr{constructor(e,t,r){super(e,t,Th(...r)),this.values=r}}const Zm=Ls("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),qX=co({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:Zm.AddIsLocked,up:n=>{n.isLocked=!1},down:n=>{delete n.isLocked}},{id:Zm.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:Zm.AddMeta,up:n=>{n.meta={}}},{id:Zm.AddWhite,up:n=>{},down:n=>{n.props.color==="white"&&(n.props.color="black")}}]});function $d(n){return n?n.typeName==="shape":!1}function Ts(n){return n?n.startsWith("shape:"):!1}function Nt(n){return`shape:${n??Mt()}`}function h5(n){const e=new Map;for(const[t,r]of Object.entries(n))if(r instanceof nr){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 $o(n,e){return cc(e,(t,r)=>`com.tldraw.shape.${n}/${r}`)}function YX(n){return ra("shape",{scope:"document",validator:sa("shape",HI("type",cc(n,(e,{props:t,meta:r})=>UX(e,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function ND(n,e){const t=[];for(const[r,{migrations:s}]of Object.entries(e)){const o=`com.tldraw.${n}.${r}`;s?"sequenceId"in s?(Ve(o===s.sequenceId,`sequenceId mismatch for ${r} ${f0} migrations. Expected '${o}', got '${s.sequenceId}'`),t.push(s)):"sequence"in s?t.push(Gd({sequenceId:o,retroactive:!0,sequence:s.sequence.map(i=>"id"in i?f5(n,r,i):i)})):t.push(Gd({sequenceId:o,retroactive:!0,sequence:Object.keys(s.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${o}/${i}`,scope:"record",filter:a=>a.typeName===n&&a.type===r,up:a=>{const l=s.migrators[i].up(a);if(l)return l},down:a=>{const l=s.migrators[i].down(a);if(l)return l}}))})):t.push(Gd({sequenceId:o,retroactive:!0,sequence:[]}))}return t}function f5(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 p5=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],NS={lightMode:{id:"light",text:"#000000",background:"#f9fafb",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",frame:{headingStroke:"#717171",headingFill:"#ffffff",stroke:"#717171",fill:"#ffffff",text:"#000000"},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",frame:{headingStroke:"#6681ec",headingFill:"#f9fafe",stroke:"#6681ec",fill:"#f9fafe",text:"#000000"},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",frame:{headingStroke:"#37a684",headingFill:"#f8fcfa",stroke:"#37a684",fill:"#f8fcfa",text:"#000000"},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",frame:{headingStroke:"#aaaaab",headingFill:"#fbfcfc",stroke:"#aaaaab",fill:"#fcfcfd",text:"#000000"},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",frame:{headingStroke:"#6cb2f3",headingFill:"#f8fbfe",stroke:"#6cb2f3",fill:"#fafcff",text:"#000000"},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",frame:{headingStroke:"#6dbe7c",headingFill:"#f8fcf9",stroke:"#6dbe7c",fill:"#fafdfa",text:"#000000"},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",frame:{headingStroke:"#f89090",headingFill:"#fffafa",stroke:"#f89090",fill:"#fffbfb",text:"#000000"},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",frame:{headingStroke:"#e59bf5",headingFill:"#fefaff",stroke:"#e59bf5",fill:"#fefbff",text:"#000000"},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",frame:{headingStroke:"#e68544",headingFill:"#fef9f6",stroke:"#e68544",fill:"#fef9f6",text:"#000000"},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",frame:{headingStroke:"#e55757",headingFill:"#fef7f7",stroke:"#e55757",fill:"#fef9f9",text:"#000000"},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",frame:{headingStroke:"#bc62d3",headingFill:"#fcf7fd",stroke:"#bc62d3",fill:"#fdf9fd",text:"#000000"},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",frame:{headingStroke:"#f3bb6c",headingFill:"#fefcf8",stroke:"#f3bb6c",fill:"#fffdfa",text:"#000000"},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",frame:{headingStroke:"#7d7d7d",headingFill:"#ffffff",stroke:"#7d7d7d",fill:"#ffffff",text:"#000000"},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",frame:{headingStroke:"#5c5c5c",headingFill:"#252525",stroke:"#5c5c5c",fill:"#0c0c0c",text:"#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",frame:{headingStroke:"#384994",headingFill:"#1C2036",stroke:"#384994",fill:"#11141f",text:"#f2f2f2"},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",frame:{headingStroke:"#10513C",headingFill:"#14241f",stroke:"#10513C",fill:"#0E1614",text:"#f2f2f2"},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",frame:{headingStroke:"#42474D",headingFill:"#23262A",stroke:"#42474D",fill:"#151719",text:"#f2f2f2"},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",frame:{headingStroke:"#075797",headingFill:"#142839",stroke:"#075797",fill:"#0B1823",text:"#f2f2f2"},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",frame:{headingStroke:"#1C5427",headingFill:"#18251A",stroke:"#1C5427",fill:"#0F1911",text:"#f2f2f2"},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",frame:{headingStroke:"#6f3232",headingFill:"#341818",stroke:"#6f3232",fill:"#181212",text:"#f2f2f2"},note:{fill:"#7a3333",text:"#f2f2f2"},semi:"#3c2b2b",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",frame:{headingStroke:"#6c367a",headingFill:"#2D2230",stroke:"#6c367a",fill:"#1C151E",text:"#f2f2f2"},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",frame:{headingStroke:"#773a0e",headingFill:"#2f1d13",stroke:"#773a0e",fill:"#1c1512",text:"#f2f2f2"},note:{fill:"#7c3905",text:"#f2f2f2"},semi:"#3b2e27",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",frame:{headingStroke:"#701e1e",headingFill:"#301616",stroke:"#701e1e",fill:"#1b1313",text:"#f2f2f2"},note:{fill:"#7e201f",text:"#f2f2f2"},semi:"#382726",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",frame:{headingStroke:"#6d1583",headingFill:"#27152e",stroke:"#6d1583",fill:"#1b0f21",text:"#f2f2f2"},note:{fill:"#5f1c70",text:"#f2f2f2"},semi:"#342938",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",frame:{headingStroke:"#684e12",headingFill:"#2a2113",stroke:"#684e12",fill:"#1e1911",text:"#f2f2f2"},note:{fill:"#8a5e1c",text:"#f2f2f2"},semi:"#3b352b",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",frame:{headingStroke:"#ffffff",headingFill:"#ffffff",stroke:"#ffffff",fill:"#ffffff",text:"#000000"},note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function tl(n){return n.isDarkMode?NS.darkMode:NS.lightMode}const ts=nr.defineEnum("tldraw:color",{defaultValue:"black",values:p5}),GI=nr.defineEnum("tldraw:labelColor",{defaultValue:"black",values:p5}),pu=nr.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),gu=nr.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Wa=nr.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),g5={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Xi=nr.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),XX=["arc","elbow"],jp=nr.defineEnum("tldraw:arrowKind",{defaultValue:"arc",values:XX}),m5=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],FS=nr.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:m5}),zS=nr.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:m5}),y5={kind:jp,labelColor:GI,color:ts,fill:gu,dash:pu,size:Xi,arrowheadStart:FS,arrowheadEnd:zS,font:Wa,start:fu,end:fu,bend:Ze,text:it,labelPosition:Ze,scale:Tn,elbowMidPoint:Ze},Vc=$o("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5,AddElbow:6});function Pf(n){return f5("shape","arrow",n)}const S5=Gd({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[Pf({id:Vc.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"}),Pf({id:Vc.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)}}),Pf({id:Vc.AddLabelPosition,up:n=>{n.labelPosition=.5},down:n=>{delete n.labelPosition}}),{id:Vc.ExtractBindings,scope:"store",up:n=>{const e=Object.values(n).filter(t=>t.typeName==="shape"&&t.type==="arrow");for(const t of e){const{start:r,end:s}=t.props;if(r.type==="binding"){const o=su(),i={typeName:"binding",id:o,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};n[o]=i,t.props.start={x:0,y:0}}else delete t.props.start.type;if(s.type==="binding"){const o=su(),i={typeName:"binding",id:o,type:"arrow",fromId:t.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};n[o]=i,t.props.end={x:0,y:0}}else delete t.props.end.type}}},Pf({id:Vc.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}),Pf({id:Vc.AddElbow,up:n=>{n.kind="arc",n.elbowMidPoint=.5},down:n=>{delete n.kind,delete n.elbowMidPoint}})]}),ZX=Th("center","edge-point","edge","none"),x5={terminal:Th("start","end"),normalizedAnchor:fu,isExact:St,isPrecise:St,snap:ZX},JX=WX("arrow",{AddSnap:1}),v5={sequence:[{dependsOn:[Vc.ExtractBindings]},{id:JX.AddSnap,up:n=>{n.snap="none"},down:n=>{delete n.snap}}]},QX=sa("camera",mt({typeName:Nr("camera"),id:no("camera"),x:Ze,y:Ze,z:Ze,meta:fr})),eZ=Ls("com.tldraw.camera",{AddMeta:1}),tZ=co({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:eZ.AddMeta,up:n=>{n.meta={}}}]}),Vi=ra("camera",{validator:QX,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),nZ=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"]),w5=m0(nZ),rZ=mt({type:w5,rotation:Ze}),sZ=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),oZ=m0(sZ),iZ=new Set(["starting","paused","active","stopping"]),b5=mt({id:it,points:Gn(fu),size:jS,color:oZ,opacity:Ze,state:m0(iZ),delay:Ze,shrink:Ze,taper:St}),Lp=no("page"),aZ=sa("page",mt({typeName:Nr("page"),id:Lp,name:it,index:WI,meta:fr})),lZ=Ls("com.tldraw.page",{AddMeta:1}),cZ=co({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:lZ.AddMeta,up:n=>{n.meta={}}}]}),es=ra("page",{validator:aZ,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Tr(n){return es.isId(n)}const uZ={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 C5(n){return n?dp(n,e=>uZ[e]):null}no("instance");function dZ(n){const e={};for(const[r,s]of n)e[r]=u5(s);const t=sa("instance",mt({typeName:Nr("instance"),id:no("instance"),currentPageId:Lp,followingUserId:it.nullable(),brush:fp.nullable(),opacityForNextShape:d5,stylesForNextShape:mt(e),cursor:rZ,scribbles:Gn(b5),isFocusMode:St,isDebugMode:St,isToolLocked:St,exportBackground:St,screenBounds:fp,insets:Gn(St),zoomBrush:fp.nullable(),isPenMode:St,isGridMode:St,chatMessage:it,isChatting:St,highlightedUserIds:Gn(it),isFocused:St,devicePixelRatio:Ze,isCoarsePointer:St,isHoveringCanvas:St.nullable(),openMenus:Gn(it),isChangingStyle:St,isReadonly:St,meta:fr,duplicateProps:mt({shapeIds:Gn(no("shape")),offset:mt({x:Ze,y:Ze})}).nullable()}));return ra("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 Jt=Ls("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}),hZ=co({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:Jt.AddTransparentExportBgs,up:n=>({...n,exportBackground:!0})},{id:Jt.RemoveDialog,up:({dialog:n,...e})=>e},{id:Jt.AddToolLockMode,up:n=>({...n,isToolLocked:!1})},{id:Jt.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:Jt.AddLabelColor,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:{...n,labelColor:"black"}})},{id:Jt.AddFollowingUserId,up:n=>({...n,followingUserId:null})},{id:Jt.RemoveAlignJustify,up:n=>{let e=n.propsForNextShape.align;return e==="justify"&&(e="start"),{...n,propsForNextShape:{...n.propsForNextShape,align:e}}}},{id:Jt.AddZoom,up:n=>({...n,zoomBrush:null})},{id:Jt.AddVerticalAlign,up:n=>({...n,propsForNextShape:{...n.propsForNextShape,verticalAlign:"middle"}})},{id:Jt.AddScribbleDelay,up:n=>n.scribble!==null?{...n,scribble:{...n.scribble,delay:0}}:{...n}},{id:Jt.RemoveUserId,up:({userId:n,...e})=>e},{id:Jt.AddIsPenModeAndIsGridMode,up:n=>({...n,isPenMode:!1,isGridMode:!1})},{id:Jt.HoistOpacity,up:({propsForNextShape:{opacity:n,...e},...t})=>({...t,opacityForNextShape:Number(n??"1"),propsForNextShape:e})},{id:Jt.AddChat,up:n=>({...n,chatMessage:"",isChatting:!1})},{id:Jt.AddHighlightedUserIds,up:n=>({...n,highlightedUserIds:[]})},{id:Jt.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:n,...e})=>({...e,stylesForNextShape:{}})},{id:Jt.AddMeta,up:n=>({...n,meta:{}})},{id:Jt.RemoveCursorColor,up:n=>{const{color:e,...t}=n.cursor;return{...n,cursor:t}}},{id:Jt.AddLonelyProperties,up:n=>({...n,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:Jt.ReadOnlyReadonly,up:({isReadOnly:n,...e})=>({...e,isReadonly:n})},{id:Jt.AddHoveringCanvas,up:n=>({...n,isHoveringCanvas:null})},{id:Jt.AddScribbles,up:({scribble:n,...e})=>({...e,scribbles:[]})},{id:Jt.AddInset,up:n=>({...n,insets:[!1,!1,!1,!1]}),down:({insets:n,...e})=>({...e})},{id:Jt.AddDuplicateProps,up:n=>({...n,duplicateProps:null}),down:({duplicateProps:n,...e})=>({...e})},{id:Jt.RemoveCanMoveCamera,up:({canMoveCamera:n,...e})=>({...e}),down:n=>({...n,canMoveCamera:!0})}]}),Yr="instance:instance",fZ=sa("instance_page_state",mt({typeName:Nr("instance_page_state"),id:no("instance_page_state"),pageId:Lp,selectedShapeIds:Gn(Eo),hintingShapeIds:Gn(Eo),erasingShapeIds:Gn(Eo),hoveredShapeId:Eo.nullable(),editingShapeId:Eo.nullable(),croppingShapeId:Eo.nullable(),focusedGroupId:Eo.nullable(),meta:fr})),kf=Ls("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),pZ=co({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:kf.AddCroppingId,up(n){n.croppingShapeId=null}},{id:kf.RemoveInstanceIdAndCameraId,up(n){delete n.instanceId,delete n.cameraId}},{id:kf.AddMeta,up:n=>{n.meta={}}},{id:kf.RenameProperties,up:n=>{},down:n=>{}},{id:kf.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}}]}),ci=ra("instance_page_state",{validator:fZ,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:{}})),gZ=sa("pointer",mt({typeName:Nr("pointer"),id:no("pointer"),x:Ze,y:Ze,lastActivityTimestamp:Ze,meta:fr})),mZ=Ls("com.tldraw.pointer",{AddMeta:1}),yZ=co({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:mZ.AddMeta,up:n=>{n.meta={}}}]}),qI=ra("pointer",{validator:gZ,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),BS=qI.createId("pointer"),SZ=sa("instance_presence",mt({typeName:Nr("instance_presence"),id:no("instance_presence"),userId:it,userName:it,lastActivityTimestamp:Ze.nullable(),followingUserId:it.nullable(),cursor:mt({x:Ze,y:Ze,type:w5,rotation:Ze}).nullable(),color:it,camera:mt({x:Ze,y:Ze,z:Ze}).nullable(),screenBounds:fp.nullable(),selectedShapeIds:Gn(no("shape")),currentPageId:no("page"),brush:fp.nullable(),scribbles:Gn(b5),chatMessage:it,meta:fr})),xd=Ls("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),xZ=co({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:xd.AddScribbleDelay,up:n=>{n.scribble!==null&&(n.scribble.delay=0)}},{id:xd.RemoveInstanceId,up:n=>{delete n.instanceId}},{id:xd.AddChatMessage,up:n=>{n.chatMessage=""}},{id:xd.AddMeta,up:n=>{n.meta={}}},{id:xd.RenameSelectedShapeIds,up:n=>{}},{id:xd.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})}}]}),vZ=ra("instance_presence",{validator:SZ,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),wZ=sa("document",mt({typeName:Nr("document"),id:Nr("document:document"),gridSize:Ze,name:it,meta:fr})),FD=Ls("com.tldraw.document",{AddName:1,AddMeta:2}),bZ=co({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:FD.AddName,up:n=>{n.name=""},down:n=>{delete n.name}},{id:FD.AddMeta,up:n=>{n.meta={}}}]}),YI=ra("document",{validator:wZ,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),Mk=YI.createId("document");function CZ(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function zD(n){n.typeName==="asset"&&("src"in n&&(n.src="<redacted>"),"src"in n.props&&(n.props.src="<redacted>"))}function PZ({error:n,phase:e,record:t,recordBefore:r}){throw uI(n,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?zD(en(r)):void 0,recordAfter:zD(en(t))}}),n}function kZ(){return[es.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function EZ(n){const e=n.query.ids("page"),t=n.query.records("instance_page_state"),r=()=>{if(!n.has(Mk))return n.put([YI.create({id:Mk,name:n.props.defaultName})]),r();if(!n.has(BS))return n.put([qI.create({id:BS})]),r();const s=e.get();if(s.size===0)return n.put(kZ()),r();const o=()=>[...s].map(u=>n.get(u)).sort(CZ)[0].id,i=n.get(Yr);if(i){if(!s.has(i.currentPageId))return n.put([{...i,currentPageId:o()}]),r()}else return n.put([n.schema.types.instance.create({id:Yr,currentPageId:o(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of s){const h=ci.createId(u);n.get(h)||a.add(h);const m=Vi.createId(u);n.has(m)||l.add(m)}a.size>0&&n.put([...a].map(u=>ci.create({id:u,pageId:ci.parseId(u)}))),l.size>0&&n.put([...l].map(u=>Vi.create({id:u})));const c=t.get();for(const u of c){if(!s.has(u.pageId)){n.remove([u.id]);continue}if(u.croppingShapeId&&!n.has(u.croppingShapeId))return n.put([{...u,croppingShapeId:null}]),r();if(u.focusedGroupId&&!n.has(u.focusedGroupId))return n.put([{...u,focusedGroupId:null}]),r();if(u.hoveredShapeId&&!n.has(u.hoveredShapeId))return n.put([{...u,hoveredShapeId:null}]),r();const h=u.selectedShapeIds.filter(S=>n.has(S));if(h.length!==u.selectedShapeIds.length)return n.put([{...u,selectedShapeIds:h}]),r();const p=u.hintingShapeIds.filter(S=>n.has(S));if(p.length!==u.hintingShapeIds.length)return n.put([{...u,hintingShapeIds:p}]),r();const m=u.erasingShapeIds.filter(S=>n.has(S));if(m.length!==u.erasingShapeIds.length)return n.put([{...u,erasingShapeIds:m}]),r()}};return r}const IZ=VI("bookmark",mt({title:it,description:it,image:it,favicon:it,src:hu.nullable()})),BD=Ls("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),TZ=co({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:n=>n.type==="bookmark",sequence:[{id:BD.MakeUrlsValid,up:n=>{hu.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:BD.AddFavicon,up:n=>{hu.isValid(n.props.favicon)||(n.props.favicon="")},down:n=>{delete n.props.favicon}}]}),_Z=VI("image",mt({w:Ze,h:Ze,name:it,isAnimated:St,mimeType:it.nullable(),src:hu.nullable(),fileSize:Tn.optional()})),Ef=Ls("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),MZ=co({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:n=>n.type==="image",sequence:[{id:Ef.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:Ef.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:Ef.MakeUrlsValid,up:n=>{hu.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:Ef.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:Ef.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),AZ=VI("video",mt({w:Ze,h:Ze,name:it,isAnimated:St,mimeType:it.nullable(),src:hu.nullable(),fileSize:Ze.optional()})),If=Ls("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),OZ=co({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:n=>n.type==="video",sequence:[{id:If.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:If.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:If.MakeUrlsValid,up:n=>{hu.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:If.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:If.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),RZ=sa("asset",HI("type",{image:_Z,video:AZ,bookmark:IZ})),DZ=Ls("com.tldraw.asset",{AddMeta:1}),jZ=co({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:DZ.AddMeta,up:n=>{n.meta={}}}]}),nc=ra("asset",{validator:RZ,scope:"document"}).withDefaultProperties(()=>({meta:{}})),P5={w:Tn,h:Tn,assetId:y0.nullable(),url:ao},$D=$o("bookmark",{NullAssetId:1,MakeUrlsValid:2}),k5={sequence:[{id:$D.NullAssetId,up:n=>{n.assetId===void 0&&(n.assetId=null)},down:"retired"},{id:$D.MakeUrlsValid,up:n=>{ao.isValid(n.url)||(n.url="")},down:n=>{}}]},E5=mt({type:Th("free","straight"),points:Gn(fu)}),I5={color:ts,fill:gu,dash:pu,size:Xi,segments:Gn(E5),isComplete:St,isClosed:St,isPen:St,scale:Tn},UD=$o("draw",{AddInPen:1,AddScale:2}),T5={sequence:[{id:UD.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:UD.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},LZ=/(^\/r\/[^/]+\/?$)/,NZ=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:n=>{const e=Qe(n);if(e&&e.pathname.match(LZ))return n}},{hostnames:["figma.com"],fromEmbedUrl:n=>{const e=Qe(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{hostnames:["google.*"],fromEmbedUrl:n=>{const e=Qe(n);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:n=>{const e=Qe(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:n=>{const e=Qe(n),t=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s,o]=t;return`https://codepen.io/${s}/pen/${o}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:n=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s]=t;return`https://scratch.mit.edu/projects/${s}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:n=>{const e=Qe(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=Qe(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=Qe(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=Qe(n);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return n.split("/").pop()?n:void 0}},{hostnames:["replit.com"],fromEmbedUrl:n=>{const e=Qe(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:n=>{const e=Qe(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=Qe(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=Qe(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=Qe(n);if(e&&e.hash.match(/#room=/))return n}},{hostnames:["observablehq.com"],fromEmbedUrl:n=>{const e=Qe(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=Qe(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],_5={w:Tn,h:Tn,url:it},Jm=$o("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),M5={sequence:[{id:Jm.GenOriginalUrlInEmbed,up:n=>{try{const e=n.url,t=new URL(e).host.replace("www.","");let r;for(const s of NZ)if(s.hostnames.includes(t))try{r=s.fromEmbedUrl(e)}catch(o){console.warn(o)}n.tmpOldUrl=n.url,n.url=r??""}catch{n.url="",n.tmpOldUrl=n.url}},down:"retired"},{id:Jm.RemoveDoesResize,up:n=>{delete n.doesResize},down:"retired"},{id:Jm.RemoveTmpOldUrl,up:n=>{delete n.tmpOldUrl},down:"retired"},{id:Jm.RemovePermissionOverrides,up:n=>{delete n.overridePermissions},down:"retired"}]},A5={w:Tn,h:Tn,name:it,color:Th(...ts.values)},FZ=$o("frame",{AddColorProp:1}),O5={sequence:[{id:FZ.AddColorProp,up:n=>{n.color="black"},down:n=>{delete n.color}}]},XI=mt({type:it,content:Gn(DX)});function Fo(n){return{type:"doc",content:n.split(`
93
+ `).map(r=>r?{type:"paragraph",content:[{type:"text",text:r}]}:{type:"paragraph"})}}const $S=nr.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),US=nr.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),ui=nr.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"]}),R5={geo:ui,labelColor:GI,color:ts,fill:gu,dash:pu,size:Xi,font:Wa,align:$S,verticalAlign:US,url:ao,w:Tn,h:Tn,growY:jS,richText:XI,scale:Tn},ji=$o("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9,AddRichText:10}),D5={sequence:[{id:ji.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:ji.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"},{id:ji.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:ji.AddCheckBox,up:n=>{},down:"retired"},{id:ji.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:ji.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:ji.AddCloud,up:n=>{},down:"retired"},{id:ji.MakeUrlsValid,up:n=>{ao.isValid(n.url)||(n.url="")},down:n=>{}},{id:ji.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:ji.AddRichText,up:n=>{n.richText=Fo(n.text),delete n.text}}]},j5={},L5={sequence:[]},N5={color:ts,size:Xi,segments:Gn(E5),isComplete:St,isPen:St,scale:Tn},zZ=$o("highlight",{AddScale:1}),F5={sequence:[{id:zZ.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},BZ=mt({topLeft:fu,bottomRight:fu}),z5={w:Tn,h:Tn,playing:St,url:ao,assetId:y0.nullable(),crop:BZ.nullable(),flipX:St,flipY:St,altText:it},Tf=$o("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4,AddAltText:5}),B5={sequence:[{id:Tf.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:Tf.AddCropProp,up:n=>{n.crop=null},down:n=>{delete n.crop}},{id:Tf.MakeUrlsValid,up:n=>{ao.isValid(n.url)||(n.url="")},down:n=>{}},{id:Tf.AddFlipProps,up:n=>{n.flipX=!1,n.flipY=!1},down:n=>{delete n.flipX,delete n.flipY}},{id:Tf.AddAltText,up:n=>{n.altText=""},down:n=>{delete n.altText}}]},HS=nr.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),$Z=mt({id:it,index:WI,x:Ze,y:Ze}),$5={color:ts,dash:pu,size:Xi,spline:HS,points:LS(it,$Z),scale:Tn},_f=$o("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),U5={sequence:[{id:_f.AddSnapHandles,up:n=>{for(const e of Object.values(n.handles))e.canSnap=!0},down:"retired"},{id:_f.RemoveExtraHandleProps,up:n=>{n.handles=J3(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(ur);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:_f.HandlesToPoints,up:n=>{const e=Object.entries(n.handles).map(([t,{x:r,y:s}])=>({x:r,y:s,index:t})).sort(ur);n.points=e.map(({x:t,y:r})=>({x:t,y:r})),delete n.handles},down:n=>{const e=Dp(n.points.length);n.handles=Object.fromEntries(n.points.map((t,r)=>[e[r],{x:t.x,y:t.y}])),delete n.points}},{id:_f.PointIndexIds,up:n=>{const e=Dp(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(ur);n.points=e.map(({x:t,y:r})=>({x:t,y:r}))}},{id:_f.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},H5={color:ts,labelColor:GI,size:Xi,font:Wa,fontSizeAdjustment:jS,align:$S,verticalAlign:US,growY:jS,url:ao,richText:XI,scale:Tn},va=$o("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8,AddRichText:9}),K5={sequence:[{id:va.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:va.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:va.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:va.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:va.MakeUrlsValid,up:n=>{ao.isValid(n.url)||(n.url="")},down:n=>{}},{id:va.AddFontSizeAdjustment,up:n=>{n.fontSizeAdjustment=0},down:n=>{delete n.fontSizeAdjustment}},{id:va.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:va.AddLabelColor,up:n=>{n.labelColor="black"},down:n=>{delete n.labelColor}},{id:va.AddRichText,up:n=>{n.richText=Fo(n.text),delete n.text}}]},Ak=nr.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),W5={color:ts,size:Xi,font:Wa,textAlign:Ak,w:Tn,richText:XI,scale:Tn,autoSize:St},MC=$o("text",{RemoveJustify:1,AddTextAlign:2,AddRichText:3}),V5={sequence:[{id:MC.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:MC.AddTextAlign,up:n=>{n.textAlign=n.align,delete n.align},down:n=>{n.align=n.textAlign,delete n.textAlign}},{id:MC.AddRichText,up:n=>{n.richText=Fo(n.text),delete n.text}}]},G5={w:Tn,h:Tn,time:Ze,playing:St,url:ao,assetId:y0.nullable(),altText:it},AC=$o("video",{AddUrlProp:1,MakeUrlsValid:2,AddAltText:3}),q5={sequence:[{id:AC.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:AC.MakeUrlsValid,up:n=>{ao.isValid(n.url)||(n.url="")},down:n=>{}},{id:AC.AddAltText,up:n=>{n.altText=""},down:n=>{delete n.altText}}]},Qm=Ls("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),UZ=Gd({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:Qm.RemoveCodeAndIconShapeTypes,scope:"store",up:n=>{for(const[e,t]of Qr(n))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete n[e]}},{id:Qm.AddInstancePresenceType,scope:"store",up(n){}},{id:Qm.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:n=>{for(const[e,t]of Qr(n))t.typeName.match(/^(user|user_presence)$/)&&delete n[e]}},{id:Qm.RemoveUserDocument,scope:"store",up:n=>{for(const[e,t]of Qr(n))t.typeName.match("user_document")&&delete n[e]}}]}),HZ={arrow:{migrations:S5,props:y5},bookmark:{migrations:k5,props:P5},draw:{migrations:T5,props:I5},embed:{migrations:M5,props:_5},frame:{migrations:O5,props:A5},geo:{migrations:D5,props:R5},group:{migrations:L5,props:j5},highlight:{migrations:F5,props:N5},image:{migrations:B5,props:z5},line:{migrations:U5,props:$5},note:{migrations:K5,props:H5},text:{migrations:V5,props:W5},video:{migrations:q5,props:G5}},KZ={arrow:{migrations:v5,props:x5}};function WZ({shapes:n=HZ,bindings:e=KZ,migrations:t}={}){const r=new Map;for(const a of Sn(n))for(const l of h5(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=YX(n),o=VX(e),i=dZ(r);return $I.create({asset:nc,binding:o,camera:Vi,document:YI,instance:i,instance_page_state:ci,page:es,instance_presence:vZ,pointer:qI,shape:s},{migrations:[UZ,jZ,tZ,bZ,hZ,pZ,cZ,xZ,yZ,qX,TZ,MZ,OZ,...ND("shape",n),...ND("binding",e),...t??[]],onValidationFailure:PZ,createIntegrityChecker:EZ})}const Np=[{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 VZ(){const n=typeof window<"u"?window.navigator.languages??["en"]:["en"];return GZ(n)}function GZ(n){for(const e of n){const t=qZ(e);if(t)return t}return"en"}const HD={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function qZ(n){const e=Np.find(s=>s.locale===n.toLowerCase());if(e)return e.locale;const[t,r]=n.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=Np.find(o=>o.locale===t);if(s)return s.locale}return t in HD?HD[t]:null}lc("@tldraw/tlschema","3.13.1","esm");var OC={exports:{}};/*!
94
+ Copyright (c) 2018 Jed Watson.
95
+ Licensed under the MIT License (MIT), see
96
+ http://jedwatson.github.io/classnames
97
+ */var KD;function YZ(){return KD||(KD=1,function(n){(function(){var e={}.hasOwnProperty;function t(){for(var o="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(o=s(o,r(a)))}return o}function r(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return t.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var i="";for(var a in o)e.call(o,a)&&o[a]&&(i=s(i,a));return i}function s(o,i){return i?o?o+" "+i:o+i:o}n.exports?(t.default=t,n.exports=t):window.classNames=t})()}(OC)),OC.exports}var XZ=YZ();const $e=Za(XZ),Y5="3.13.1",WD={major:"2024-09-13T14:36:29.063Z",minor:"2025-05-22T13:38:59.946Z"},ZZ={error:null};class ZI extends k.Component{constructor(){super(...arguments);R(this,"state",ZZ)}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,s;(s=(r=this.props).onError)==null||s.call(r,t)}render(){const{error:t}=this.state;if(t!==null){const{fallback:r}=this.props;return g.jsx(r,{error:t})}return this.props.children}}function Fp({children:n,fallback:e,...t}){return e===null?n:g.jsx(ZI,{fallback:e,...t,children:n})}function JI(n,e){return S0(`${n}_${e}`)}function Ou(n){return S0(`${k.useId()}${n??""}`)}function hi(n){const e=qr(k.useContext(X5));return S0(`${e}_${n}`)}function S0(n){return n.replace(/:/g,"_")}const X5=k.createContext(null);function JZ({children:n}){const e=Ou();return g.jsx(X5.Provider,{value:e,children:n})}const QI=k.createContext(null);function ne(){const n=We.useContext(QI);if(!n)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return n}function Sr(){return We.useContext(QI)}function eT({editor:n,children:e}){return g.jsx(QI.Provider,{value:n,children:g.jsx(JZ,{children:e})})}function QZ(){return g.jsx("div",{className:"tl-background"})}function yg(n,e,t,r,s,o){k.useLayoutEffect(()=>{const i=n.current;if(!i||e===void 0)return;let a=`translate(${e}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),s!==void 0&&(a+=` rotate(${s}rad)`),o&&(a+=` translate(${o.x}px, ${o.y}px)`),i.style.transform=a})}const qn={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};class P{constructor(e=0,t=0,r=1){this.x=e,this.y=t,this.z=r}get pressure(){return this.z}set(e=this.x,t=this.y,r=this.z){return this.x=e,this.y=t,this.z=r,this}setTo({x:e=0,y:t=0,z:r=1}){return this.x=e,this.y=t,this.z=r,this}rot(e){if(e===0)return this;const{x:t,y:r}=this,s=Math.sin(e),o=Math.cos(e);return this.x=t*o-r*s,this.y=t*s+r*o,this}rotWith(e,t){if(t===0)return this;const r=this.x-e.x,s=this.y-e.y,o=Math.sin(t),i=Math.cos(t);return this.x=e.x+(r*i-s*o),this.y=e.y+(r*o+s*i),this}clone(){const{x:e,y:t,z:r}=this;return new P(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=P.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 P.Dpr(this,e)}cpr(e){return P.Cpr(this,e)}len2(){return P.Len2(this)}len(){return P.Len(this)}pry(e){return P.Pry(this,e)}per(){const{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){return P.Uni(this)}tan(e){return P.Tan(this,e)}dist(e){return P.Dist(this,e)}distanceToLineSegment(e,t){return P.DistanceToLineSegment(e,t,this)}slope(e){return P.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 P.Angle(this,e)}toAngle(){return P.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 P.Equals(this,e)}equalsXY(e,t){return P.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 P.ToFixed(this)}toString(){return P.ToString(P.ToFixed(this))}toJson(){return P.ToJson(this)}toArray(){return P.ToArray(this)}static Add(e,t){return new P(e.x+t.x,e.y+t.y)}static AddXY(e,t,r){return new P(e.x+t,e.y+r)}static Sub(e,t){return new P(e.x-t.x,e.y-t.y)}static SubXY(e,t,r){return new P(e.x-t,e.y-r)}static AddScalar(e,t){return new P(e.x+t,e.y+t)}static SubScalar(e,t){return new P(e.x-t,e.y-t)}static Div(e,t){return new P(e.x/t,e.y/t)}static Mul(e,t){return new P(e.x*t,e.y*t)}static DivV(e,t){return new P(e.x/t.x,e.y/t.y)}static MulV(e,t){return new P(e.x*t.x,e.y*t.y)}static Neg(e){return new P(-e.x,-e.y)}static Per(e){return new P(e.y,-e.x)}static Abs(e){return new P(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 ManhattanDist(e,t){return Math.abs(e.x-t.x)+Math.abs(e.y-t.y)}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 P(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 P.Dpr(e,t)/P.Len(t)}static Uni(e){return P.Div(e,P.Len(e))}static Tan(e,t){return P.Uni(P.Sub(e,t))}static Min(e,t){return new P(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new P(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:r=1}){return new P(e,t,r)}static FromArray(e){return new P(e[0],e[1])}static Rot(e,t=0){const r=Math.sin(t),s=Math.cos(t);return new P(e.x*s-e.y*r,e.x*r+e.y*s)}static RotWith(e,t,r){const s=e.x-t.x,o=e.y-t.y,i=Math.sin(r),a=Math.cos(r);return new P(t.x+(s*a-o*i),t.y+(s*i+o*a))}static NearestPointOnLineThroughPoint(e,t,r){return P.Mul(t,P.Sub(r,e).pry(t)).add(e)}static NearestPointOnLineSegment(e,t,r,s=!0){if(P.Equals(e,r)||P.Equals(t,r))return P.From(r);const o=P.Tan(t,e),i=P.Add(e,P.Mul(o,P.Sub(r,e).pry(o)));if(s){if(i.x<Math.min(e.x,t.x))return P.Cast(e.x<t.x?e:t);if(i.x>Math.max(e.x,t.x))return P.Cast(e.x>t.x?e:t);if(i.y<Math.min(e.y,t.y))return P.Cast(e.y<t.y?e:t);if(i.y>Math.max(e.y,t.y))return P.Cast(e.y>t.y?e:t)}return i}static DistanceToLineThroughPoint(e,t,r){return P.Dist(r,P.NearestPointOnLineThroughPoint(e,t,r))}static DistanceToLineSegment(e,t,r,s=!0){return P.Dist(r,P.NearestPointOnLineSegment(e,t,r,s))}static Snap(e,t=1){return new P(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof P?e:P.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 AngleBetween(e,t){const r=e.x*t.x+e.y*t.y,s=Math.sqrt((Math.pow(e.x,2)+Math.pow(e.y,2))*(Math.pow(t.x,2)+Math.pow(t.y,2)));return(e.x*t.y-e.y*t.x<0?-1:1)*Math.acos(r/s)}static Lrp(e,t,r){return P.Sub(t,e).mul(r).add(e)}static Med(e,t){return new P((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=P.Len(e);return new P(t*e.x/r,t*e.y/r)}static ScaleWithOrigin(e,t,r){return P.Sub(e,r).mul(t).add(r)}static ToFixed(e){return new P(Aa(e.x),Aa(e.y))}static ToInt(e){return new P(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 P.Add(e,P.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 P(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 P(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 P(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new P(Math.min(Math.max(e.x,t),r),Math.min(Math.max(e.y,t),r))}static PointsBetween(e,t,r=6){const s=[];for(let o=0;o<r;o++){const i=qn.easeInQuad(o/(r-1)),a=P.Lrp(e,t,i);a.z=Math.min(1,.5+Math.abs(.5-eJ(i))*.65),s.push(a)}return s}static SnapToGrid(e,t=8){return new P(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}const eJ=n=>n<.5?2*n*n:-1+(4-2*n)*n;function kt(n){return`${Q(n.x)},${Q(n.y)} `}function _s(n,e){return`${Q((n.x+e.x)/2)},${Q((n.y+e.y)/2)} `}const bt=Math.PI,qt=bt/2,Dt=bt*2,tJ=Math.sin;function $t(n,e,t){return Math.max(e,typeof t<"u"?Math.min(n,t):n)}function ey(n,e=1e10){return n?Math.round(n*e)/e:0}function ro(n,e,t=1e-6){return Math.abs(n-e)<=t}function Z5(n,e){const t=Math.pow(n-e,2)/Math.pow(n+e,2);return bt*(n+e)*(1+3*t/(10+Math.sqrt(4-3*t)))}function ou(n){return n=n%Dt,n<0?n=n+Dt:n===0&&(n=0),n}function x0(n,e){return n=ou(n),e=ou(e),n>e&&(e+=Dt),e-n}function nJ(n,e){return Dt-x0(n,e)}function Vy(n,e){const t=(e-n)%Dt;return 2*t%Dt-t}function Ok(n){return(Dt+n)%Dt}function KS(n,e){const t=Dt/e;let r=Math.floor((Ok(n)+t/2)/t)*t%Dt;return r<bt&&(r+=Dt),r>bt&&(r-=Dt),r}function J5(n,e){return n===e||ro(n%(Math.PI/2)-e%(Math.PI/2),0)}function rJ(n){return n*bt/180}function sJ(n){return n*180/bt}function v0(n,e,t){return new P(n.x,n.y).add(P.FromAngle(t,e))}function RC(n,e,t){const r=n/2,s=e/2,o=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let S=0;S<t;S++){const v=Dt/t,y=-qt+S*v,w=r+r*Math.cos(y),C=s+s*Math.sin(y);w<i&&(i=w),C<l&&(l=C),w>a&&(a=w),C>c&&(c=C),o.push(new P(w,C))}const u=a-i,h=c-l,p=n-u,m=e-h;if(p!==0||m!==0)for(let S=0;S<o.length;S++){const v=o[S];v.x=(v.x-i)/u*n,v.y=(v.y-l)/h*e}return o}function Mf(n,e,t,r){return n<r&&t<e}function si(n,e,t,r){const s=Math.max(n,t),o=Math.min(e,r);return s<=o?[s,o]:null}function VD(n,e,t){return(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y)}function so(n,e){let t=0,r,s;for(let o=0;o<e.length;o++){if(r=e[o],r.x===n.x&&r.y===n.y||(s=e[(o+1)%e.length],P.Dist(n,r)+P.Dist(n,s)===P.Dist(r,s)))return!0;r.y<=n.y?s.y>n.y&&VD(r,s,n)>0&&(t+=1):s.y<=n.y&&VD(r,s,n)<0&&(t-=1)}return t!==0}function Q(n){return Math.round(n*1e4)/1e4}function Aa(n){return Math.round(n*100)/100}const GD=n=>Math.abs(n)<Number.MAX_SAFE_INTEGER;function qD(n,e,t,r){let s;if(Math.abs(n)>bt){s=Vy(e,r);const o=Vy(r,t);return Math.abs(s)<Math.abs(o)?s/n:(n-o)/n}else{s=Vy(e,r);const o=s/n;return Math.sign(s)!==Math.sign(n)?Math.abs(o)>.5?1:0:o}}function oJ(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 tT(n,e,t){const r=-2*(n.x*(e.y-t.y)-n.y*(e.x-t.x)+e.x*t.y-t.x*e.y),s=((n.x*n.x+n.y*n.y)*(t.y-e.y)+(e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y))/r,o=((n.x*n.x+n.y*n.y)*(e.x-t.x)+(e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x))/r;return!Number.isFinite(s)||!Number.isFinite(o)?null:new P(s,o)}function iJ(n,e,t,r,s){if(t===null)return[P.From(n),P.From(e)];const o=[],i=P.Angle(t,n),a=P.Angle(t,e),l=x0(i,a);for(let c=0;c<s;c++){const u=c/(s-1),h=i+l*u,p=v0(t,r,h);o.push(p)}return o}const DC=({brush:n,color:e,opacity:t,className:r})=>{const s=k.useRef(null);yg(s,n.x,n.y);const o=Q(Math.max(1,n.w)),i=Q(Math.max(1,n.h));return g.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?g.jsxs("g",{className:"tl-brush",opacity:t,children:[g.jsx("rect",{width:o,height:i,fill:e,opacity:.75}),g.jsx("rect",{width:o,height:i,fill:"none",stroke:e,opacity:.1})]}):g.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:o,height:i})})},Tt={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1,hasCanvasSupport:!1};typeof window<"u"&&"navigator"in window&&(Tt.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Tt.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Tt.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Tt.isFirefox=/firefox/i.test(navigator.userAgent),Tt.isAndroid=/android/i.test(navigator.userAgent),Tt.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Tt.hasCanvasSupport=typeof window<"u"&&"Promise"in window&&"HTMLCanvasElement"in window);const YD={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.05,.1,.25,.5,1,2,4,8]},jC={duration:0,easing:qn.easeInOutCubic},XD={CAMERA_MOVE:-10},aJ=["top","right","bottom","left"],ZD=0,nT=2,ty=1,JD=5,lJ=128;var LC={};const cJ={},Q5=Ir("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),sn={logPreventDefaults:Ir("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Ir("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Ir("logElementRemoves",{defaults:{all:!1}}),debugSvg:Ir("debugSvg",{defaults:{all:!1}}),showFps:Ir("showFps",{defaults:{all:!1}}),measurePerformance:Ir("measurePerformance",{defaults:{all:!1}}),throwToBlob:Ir("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Ir("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Ir("debugCursors",{defaults:{all:!1}}),forceSrgb:Ir("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Ir("debugGeometry",{defaults:{all:!1}}),hideShapes:Ir("hideShapes",{defaults:{all:!1}}),editOnType:Ir("editOnType",{defaults:{all:!1}}),a11y:Ir("a11y",{defaults:{all:!1}}),debugElbowArrows:Ir("debugElbowArrows",{defaults:{all:!1}})};if(typeof Element<"u"){const n=Element.prototype.removeChild;jo("element removal logging",()=>{sn.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),n.call(this,e)}:Element.prototype.removeChild=n})}function Ir(n,{defaults:e,shouldStoreForSession:t=!0}){return uJ({name:n,defaults:e,shouldStoreForSession:t})}function uJ(n){const e=hJ(n),t=n.shouldStoreForSession?dJ(n.name):null,r=hn(`debug:${n.name}`,t??e);return typeof window<"u"&&(n.shouldStoreForSession&&jo(`debug:${n.name}`,()=>{const s=r.get();s===e?fF(`tldraw_debug:${n.name}`):yI(`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,{reset:()=>r.set(e)})}function dJ(n){try{return JSON.parse(hF(`tldraw_debug:${n}`)??"null")}catch{return null}}function NC(n){try{return n()}catch{return null}}function hJ(n){switch(NC(()=>LC.TLDRAW_ENV)??NC(()=>LC.VERCEL_PUBLIC_TLDRAW_ENV)??NC(()=>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 WS(n){if(n instanceof HTMLElement)return n;if(n.parentElement)return WS(n.parentElement);throw Error("Could not find a parent element of an HTML type!")}function nt(n){n.preventDefault(),sn.logPreventDefaults.get()&&console.warn("preventDefault called on event:",n)}function Sg(n,e){if(n.setPointerCapture(e.pointerId),sn.logPointerCaptures.get()){const t=Q5.get();t.set(n,(t.get(n)??0)+1),console.warn("setPointerCapture called on element:",n,e)}}function xg(n,e){if(n.hasPointerCapture(e.pointerId)&&(n.releasePointerCapture(e.pointerId),sn.logPointerCaptures.get())){const t=Q5.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 Yt=n=>n.stopPropagation(),_r=(n,e,t)=>{n&&n.style.setProperty(e,t)};function e4(n=!1){const{activeElement:e}=document,t=n?["input","textarea"]:["input","select","button","textarea"];return!!(e&&(e.isContentEditable||t.indexOf(e.tagName.toLowerCase())>-1||e.classList.contains("tlui-slider__thumb")))}const pr=n=>Tt.isDarwin?n.metaKey:n.ctrlKey||n.metaKey;function Js(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 rT(){const n=ne(),e=se("current tool",()=>n.getCurrentTool(),[n]);return k.useMemo(function(){let s,o;function i(y){if(!y.isKilled){if(y.button===nT){n.dispatch({type:"pointer",target:"canvas",name:"right_click",...Js(y)});return}y.button!==0&&y.button!==1&&y.button!==5||(Sg(y.currentTarget,y),n.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Js(y)}))}}function a(y){if(y.isKilled||y.clientX===s&&y.clientY===o)return;s=y.clientX,o=y.clientY;const w=e.useCoalescedEvents&&y.nativeEvent.getCoalescedEvents?y.nativeEvent.getCoalescedEvents():[y];for(const C of w)n.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Js(C)})}function l(y){y.isKilled||y.button!==0&&y.button!==1&&y.button!==2&&y.button!==5||(s=y.clientX,o=y.clientY,xg(y.currentTarget,y),n.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Js(y)}))}function c(y){if(y.isKilled||n.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const w=y.pointerType==="mouse"||y.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:w?!0:null})}function u(y){if(y.isKilled||n.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const w=y.pointerType==="mouse"||y.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:w?!1:null})}function h(y){y.isKilled=!0,nt(y)}function p(y){y.isKilled=!0,y.target instanceof HTMLElement&&y.target.tagName!=="A"&&y.target.tagName!=="TEXTAREA"&&!y.target.isContentEditable&&!(n.getEditingShape()&&y.target.className.includes("tl-text-content"))&&nt(y)}function m(y){nt(y)}async function S(y){var C,T;if(nt(y),Yt(y),(T=(C=y.dataTransfer)==null?void 0:C.files)!=null&&T.length){const E=Array.from(y.dataTransfer.files);await n.putExternalContent({type:"files",files:E,point:n.screenToPage({x:y.clientX,y:y.clientY}),ignoreParent:!1});return}const w=y.dataTransfer.getData("url");if(w){await n.putExternalContent({type:"url",url:w,point:n.screenToPage({x:y.clientX,y:y.clientY})});return}}function v(y){Yt(y)}return{onPointerDown:i,onPointerMove:a,onPointerUp:l,onPointerEnter:c,onPointerLeave:u,onDragOver:m,onDrop:S,onTouchStart:h,onTouchEnd:p,onClick:v}},[n,e])}function fJ(){const n=ne();k.useEffect(()=>{let e=n.getInstanceState().isCoarsePointer;const t=i=>{const a=i.pointerType!=="mouse";e!==a&&(e=a,n.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",t,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),s=Tt.isFirefox&&!Tt.isAndroid&&!Tt.isIos,o=()=>{const i=s?!1:r.matches;e===i&&(e=i,n.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",o),o()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",o)}},[n])}const t4=k.createContext(null);function n4({container:n,children:e}){return g.jsx(t4.Provider,{value:n,children:e})}function _n(){return qr(k.useContext(t4),"useContainer used outside of <Tldraw />")}function pJ(){const n=ne(),e=_n(),t=se("isEditing",()=>n.getEditingShapeId(),[n]),r=se("isFocused",()=>n.getIsFocused(),[n]);k.useEffect(()=>{if(!e)return;function s(o){if(o.isSpecialRedispatchedEvent)return;nt(o),Yt(o);const i=e.querySelector(".tl-canvas");if(!i)return;const a=new DragEvent(o.type,o);a.isSpecialRedispatchedEvent=!0,i.dispatchEvent(a)}return e.addEventListener("dragover",s),e.addEventListener("drop",s),()=>{e.removeEventListener("dragover",s),e.removeEventListener("drop",s)}},[e]),k.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let s=null;const o=()=>{s!=null&&s();const i=`(resolution: ${window.devicePixelRatio}dppx)`,a=matchMedia(i),l=c=>{c.type==="change"&&o()};a.addEventListener?a.addEventListener("change",o):a.addListener&&a.addListener(l),s=()=>{a.removeEventListener?a.removeEventListener("change",o):a.removeListener&&a.removeListener(l)},n.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{s==null||s()}},[n]),k.useEffect(()=>{if(!r)return;const s=l=>{if(l.altKey&&(n.isIn("zoom")||!n.getPath().endsWith(".idle"))&&!Af(n)&&nt(l),l.isKilled)return;l.isKilled=!0;const c=!!n.getSelectedShapeIds().length;switch(l.key){case"=":case"-":case"0":{if(l.metaKey||l.ctrlKey){nt(l);return}break}case"Tab":{if(Af(n))return;c&&!t&&nt(l);break}case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(Af(n))return;c&&(l.metaKey||l.ctrlKey)&&nt(l);break}case",":return;case"Escape":{if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&nt(l),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),e.focus());return}default:if(Af(n))return}const u={type:"keyboard",name:l.repeat?"key_repeat":"key_down",key:l.key,code:l.code,shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:pr(l)};n.dispatch(u)},o=l=>{if(l.isKilled||(l.isKilled=!0,Af(n))||l.key===",")return;const c={type:"keyboard",name:"key_up",key:l.key,code:l.code,shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:pr(l)};n.dispatch(c)};function i(l){var c,u;if(e.contains(l.target)){const h=l.touches[0].pageX,p=l.touches[0].radiusX||0;(h-p<10||h+p>n.getViewportScreenBounds().width-10)&&(((c=l.target)==null?void 0:c.tagName)==="BUTTON"&&((u=l.target)==null||u.click()),nt(l))}}const a=l=>{e.contains(l.target)&&(l.ctrlKey||l.metaKey)&&nt(l)};return e.addEventListener("touchstart",i,{passive:!1}),e.addEventListener("wheel",a,{passive:!1}),document.addEventListener("gesturestart",nt),document.addEventListener("gesturechange",nt),document.addEventListener("gestureend",nt),e.addEventListener("keydown",s),e.addEventListener("keyup",o),()=>{e.removeEventListener("touchstart",i),e.removeEventListener("wheel",a),document.removeEventListener("gesturestart",nt),document.removeEventListener("gesturechange",nt),document.removeEventListener("gestureend",nt),e.removeEventListener("keydown",s),e.removeEventListener("keyup",o)}},[n,e,r,t])}function Af(n){return n.menus.hasOpenMenus()||e4()}const gJ=["textarea","input"];function mJ(n){const e=ne();k.useEffect(()=>{const t=n.current;if(!t)return;const r=s=>{var o;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:i}=s;if(gJ.includes((o=i.tagName)==null?void 0:o.toLocaleLowerCase())||i.isContentEditable||e.isIn("select.editing_shape"))return;nt(s)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[e,n])}function yJ(n,e,t){return Math.max(e,Math.min(n,t))}const gr={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 QD(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function ej(n,e,t,r=.15){return r===0?yJ(n,e,t):n<e?-QD(e-n,t-e,r)+e:n>t?+QD(n-t,t-e,r)+t:n}function SJ(n,[e,t],[r,s]){const[[o,i],[a,l]]=n;return[ej(e,o,i,r),ej(t,a,l,s)]}function xJ(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 vJ(n){var e=xJ(n,"string");return typeof e=="symbol"?e:String(e)}function Rr(n,e,t){return e=vJ(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function tj(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 fn(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?tj(Object(t),!0).forEach(function(r){Rr(n,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):tj(Object(t)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))})}return n}const r4={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 nj(n){return n?n[0].toUpperCase()+n.slice(1):""}const wJ=["enter","leave"];function bJ(n=!1,e){return n&&!wJ.includes(e)}function CJ(n,e="",t=!1){const r=r4[n],s=r&&r[e]||e;return"on"+nj(n)+nj(s)+(bJ(t,s)?"Capture":"")}const PJ=["gotpointercapture","lostpointercapture"];function kJ(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const r=PJ.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:t}}function EJ(n,e=""){const t=r4[n],r=t&&t[e]||e;return n+r}function s4(n){return"touches"in n}function IJ(n){return s4(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function TJ(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 Rk(n,e){try{const t=e.clientX-n.clientX,r=e.clientY-n.clientY,s=(e.clientX+n.clientX)/2,o=(e.clientY+n.clientY)/2,i=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function _J(n){return TJ(n).map(e=>e.identifier)}function rj(n,e){const[t,r]=Array.from(n.touches).filter(s=>e.includes(s.identifier));return Rk(t,r)}const sj=40,oj=800;function o4(n){let{deltaX:e,deltaY:t,deltaMode:r}=n;return r===1?(e*=sj,t*=sj):r===2&&(e*=oj,t*=oj),[e,t]}function MJ(n){const e={};if("buttons"in n&&(e.buttons=n.buttons),"shiftKey"in n){const{shiftKey:t,altKey:r,metaKey:s,ctrlKey:o}=n;Object.assign(e,{shiftKey:t,altKey:r,metaKey:s,ctrlKey:o})}return e}function VS(n,...e){return typeof n=="function"?n(...e):n}function AJ(){}function OJ(...n){return n.length===0?AJ:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function ij(n,e){return Object.assign({},e,n||{})}const RJ=32;class i4{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 o=0;if(e&&(t.event=e,r.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,MJ(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const A=t._delta.map(Math.abs);gr.addTo(t._distance,A)}this.axisIntent&&this.axisIntent(e);const[i,a]=t._movement,[l,c]=r.threshold,{_step:u,values:h}=t;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),t.intentional=u[0]!==!1||u[1]!==!1,!t.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[A,O]=h;p[0]=u[0]!==!1?A-u[0]:0,p[1]=u[1]!==!1?O-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(p);const m=t.offset,S=t._active&&!t._blocked||t.active;S&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=s[this.ingKey]=t._active,e&&(t.first&&("bounds"in r&&(t._bounds=VS(r.bounds,t)),this.setup&&this.setup()),t.movement=p,this.computeOffset()));const[v,y]=t.offset,[[w,C],[T,E]]=t._bounds;t.overflow=[v<w?-1:v>C?1:0,y<T?-1:y>E?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const _=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=SJ(t._bounds,t.offset,_),t.delta=gr.sub(t.offset,m),this.computeMovement(),S&&(!t.last||o>RJ)){t.delta=gr.sub(t.offset,m);const A=t.delta.map(Math.abs);gr.addTo(t.distance,A),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&o>0&&(t.velocity=[A[0]/o,A[1]/o],t.timeDelta=o)}}emit(){const e=this.state,t=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const s=this.handler(fn(fn(fn({},t),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function DJ([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 jJ extends i4{constructor(...e){super(...e),Rr(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=gr.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=gr.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[IJ(e)]:r.axisThreshold;t.axis=DJ(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 LJ=n=>n,aj=.15,a4={enabled(n=!0){return n},eventOptions(n,e,t){return fn(fn({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[aj,aj];case!1:return[0,0];default:return gr.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return gr.toVector(n)},transform(n,e,t){const r=n||t.shared.transform;return this.hasCustomTransform=!!r,r||LJ},threshold(n){return gr.toVector(n,0)}},NJ=0,vg=fn(fn({},a4),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=NJ){return n},bounds(n={}){if(typeof n=="function")return o=>vg.bounds(n(o));if("current"in n)return()=>n.current;if(typeof HTMLElement=="function"&&n instanceof HTMLElement)return n;const{left:e=-1/0,right:t=1/0,top:r=-1/0,bottom:s=1/0}=n;return[[e,t],[r,s]]}}),wg=typeof window<"u"&&window.document&&window.document.createElement;function l4(){return wg&&"ontouchstart"in window}function FJ(){return l4()||wg&&window.navigator.maxTouchPoints>1}function zJ(){return wg&&"onpointerdown"in window}function BJ(){return wg&&"exitPointerLock"in window.document}function $J(){try{return"constructor"in GestureEvent}catch{return!1}}const To={isBrowser:wg,gesture:$J(),touch:l4(),touchscreen:FJ(),pointer:zJ(),pointerLock:BJ()},UJ=250,HJ=180,KJ=.5,WJ=50,VJ=250,GJ=10,lj={mouse:0,touch:0,pen:8};fn(fn({},vg),{},{device(n,e,{pointer:{touch:t=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&To.pointerLock,To.touch&&t?"touch":this.pointerLock?"mouse":To.pointer&&!s?"pointer":To.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?UJ:void 0,!(!To.touchscreen||t===!1))return n||(t!==void 0?"y":void 0)},pointerCapture(n,e,{pointer:{capture:t=!0,buttons:r=1,keys:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&t},threshold(n,e,{filterTaps:t=!1,tapsThreshold:r=3,axis:s=void 0}){const o=gr.toVector(n,t?r:s?1:0);return this.filterTaps=t,this.tapsThreshold=r,o},swipe({velocity:n=KJ,distance:e=WJ,duration:t=VJ}={}){return{velocity:this.transform(gr.toVector(n)),distance:this.transform(gr.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return HJ;case!1:return 0;default:return n}},axisThreshold(n){return n?fn(fn({},lj),n):lj},keyboardDisplacement(n=GJ){return n}});function c4(n){const[e,t]=n.overflow,[r,s]=n._delta,[o,i]=n._direction;(e<0&&r>0&&o<0||e>0&&r<0&&o>0)&&(n._movement[0]=n._movementBound[0]),(t<0&&s>0&&i<0||t>0&&s<0&&i>0)&&(n._movement[1]=n._movementBound[1])}const qJ=30,YJ=100;class XJ extends i4{constructor(...e){super(...e),Rr(this,"ingKey","pinching"),Rr(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=gr.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)*qJ-Math.abs(r);s<0?e.axis="angle":s>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const t=this.state,r=this.ctrl.touchIds;if(t._active&&t._touchIds.every(o=>r.has(o))||r.size<2)return;this.start(e),t._touchIds=Array.from(r).slice(0,2);const s=rj(e,t._touchIds);s&&this.pinchStart(e,s)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const t=this.state,r=t._pointerEvents,s=this.ctrl.pointerIds;if(t._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(e.pointerId,e),t._pointerEvents.size<2))return;this.start(e);const o=Rk(...Array.from(r.values()));o&&this.pinchStart(e,o)}pinchStart(e,t){const r=this.state;r.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const t=rj(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=Rk(...Array.from(t.values()));r&&this.pinchMove(e,r)}pinchMove(e,t){const r=this.state,s=r._values[1],o=t.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),this.computeValues([t.distance,t.angle-360*i]),r.origin=t.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const t=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}t._pointerEvents.has(e.pointerId)&&t._pointerEvents.delete(e.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const t=this.state;t._active||(this.start(e),this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY];const r=t._movement;t._movement=[e.scale-1,e.rotation],t._delta=gr.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=[-o4(e)[1]/YJ*r.offset[0],0],gr.addTo(r._movement,r._delta),c4(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 ZJ=fn(fn({},a4),{},{device(n,e,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!To.touch&&To.gesture)return"gesture";if(To.touch&&r)return"touch";if(To.touchscreen){if(To.pointer)return"pointer";if(To.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:r={}}){const s=i=>{const a=ij(VS(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=ij(VS(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(i)]},threshold(n,e,t){return this.lockDirection=t.axis==="lock",gr.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});fn(fn({},vg),{},{mouseOnly:(n=!0)=>n});class JJ extends jJ{constructor(...e){super(...e),Rr(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=o4(e),gr.addTo(t._movement,t._delta),c4(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 QJ=vg;fn(fn({},vg),{},{mouseOnly:(n=!0)=>n});const sT=new Map,Dk=new Map;function eQ(n){sT.set(n.key,n.engine),Dk.set(n.key,n.resolver)}const tQ={key:"pinch",engine:XJ,resolver:ZJ},nQ={key:"wheel",engine:JJ,resolver:QJ};function rQ(n,e){if(n==null)return{};var t={},r=Object.keys(n),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(t[s]=n[s]);return t}function sQ(n,e){if(n==null)return{};var t=rQ(n,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(n);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(n,r)&&(t[r]=n[r])}return t}const oQ={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=To.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},iQ=["target","eventOptions","window","enabled","transform"];function Gy(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]=Gy(n[r],s);break;case"boolean":s&&(t[r]=n[r]);break}return t}function aQ(n,e,t={}){const r=n,{target:s,eventOptions:o,window:i,enabled:a,transform:l}=r,c=sQ(r,iQ);if(t.shared=Gy({target:s,eventOptions:o,window:i,enabled:a,transform:l},oQ),e){const u=Dk.get(e);t[e]=Gy(fn({shared:t.shared},c),u)}else for(const u in c){const h=Dk.get(u);h&&(t[u]=Gy(fn({shared:t.shared},c[u]),h))}return t}class u4{constructor(e,t){Rr(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,r,s,o){const i=this._listeners,a=EJ(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=fn(fn({},l),o);e.addEventListener(a,s,c);const u=()=>{e.removeEventListener(a,s,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class lQ{constructor(){Rr(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 cQ{constructor(e){Rr(this,"gestures",new Set),Rr(this,"_targetEventStore",new u4(this)),Rr(this,"gestureEventStores",{}),Rr(this,"gestureTimeoutStores",{}),Rr(this,"handlers",{}),Rr(this,"config",{}),Rr(this,"pointerIds",new Set),Rr(this,"touchIds",new Set),Rr(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),uQ(this,e)}setEventIds(e){if(s4(e))return this.touchIds=new Set(_J(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=aQ(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,r={};let s;if(!(t.target&&(s=t.target(),!s))){if(t.enabled){for(const i of this.gestures){const a=this.config[i],l=cj(r,a.eventOptions,!!s);if(a.enabled){const c=sT.get(i);new c(this,e,i).bind(l)}}const o=cj(r,t.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](fn(fn({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const o in r)r[o]=OJ(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:l}=kJ(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:l})}}}}function vd(n,e){n.gestures.add(e),n.gestureEventStores[e]=new u4(n,e),n.gestureTimeoutStores[e]=new lQ}function uQ(n,e){e.drag&&vd(n,"drag"),e.wheel&&vd(n,"wheel"),e.scroll&&vd(n,"scroll"),e.move&&vd(n,"move"),e.pinch&&vd(n,"pinch"),e.hover&&vd(n,"hover")}const cj=(n,e,t)=>(r,s,o,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:e.capture,h=(c=i.passive)!==null&&c!==void 0?c:e.passive;let p=a?r:CJ(r,s,u);t&&h&&(p+="Passive"),n[p]=n[p]||[],n[p].push(o)},dQ=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function hQ(n){const e={},t={},r=new Set;for(let s in n)dQ.test(s)?(r.add(RegExp.lastMatch),t[s]=n[s]):e[s]=n[s];return[t,e,r]}function wd(n,e,t,r,s,o){if(!n.has(t)||!sT.has(r))return;const i=t+"Start",a=t+"End",l=c=>{let u;return c.first&&i in e&&e[i](c),t in e&&(u=e[t](c)),c.last&&a in e&&e[a](c),u};s[r]=l,o[r]=o[r]||{}}function fQ(n,e){const[t,r,s]=hQ(n),o={};return wd(s,t,"onDrag","drag",o,e),wd(s,t,"onWheel","wheel",o,e),wd(s,t,"onScroll","scroll",o,e),wd(s,t,"onPinch","pinch",o,e),wd(s,t,"onMove","move",o,e),wd(s,t,"onHover","hover",o,e),{handlers:o,config:e,nativeHandlers:r}}function pQ(n,e={},t,r){const s=We.useMemo(()=>new cQ(n),[]);if(s.applyHandlers(n,r),s.applyConfig(e,t),We.useEffect(s.effect.bind(s)),We.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function gQ(n){return n.forEach(eQ),function(t,r){const{handlers:s,nativeHandlers:o,config:i}=fQ(t,r||{});return pQ(s,i,void 0,o)}}const uj=10,mQ=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function d4(n){let{deltaY:e,deltaX:t}=n,r=0;return n.ctrlKey||n.altKey||n.metaKey?r=(Math.abs(e)>uj?uj*Math.sign(e):e)/100:n.shiftKey&&!mQ&&(t=e,e=0),{x:-t,y:-e,z:-r}}const yQ=gQ([nQ,tQ]);let bd;const SQ=n=>bd===void 0?(bd=n,!1):n-bd>120&&n-bd<160?(bd=n,!0):(bd=n,!1);function xQ(n){const e=ne(),t=k.useMemo(()=>{let r="not sure";const s=({event:S})=>{if(!e.getInstanceState().isFocused||(r="not sure",SQ(Date.now())))return;const v=e.getEditingShapeId();if(v){const C=e.getShape(v);if(C&&e.getShapeUtil(C).canScroll(C)){const E=e.getShapePageBounds(v);if(E!=null&&E.containsPoint(e.inputs.currentPagePoint))return}}nt(S),Yt(S);const y=d4(S);if(y.x===0&&y.y===0)return;const w={type:"wheel",name:"wheel",delta:y,point:new P(S.clientX,S.clientY),shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey,metaKey:S.metaKey,accelKey:pr(S)};e.dispatch(w)};let o=1,i=1,a=0;const l=new P,c=new P,u=S=>{const v=n.current;r="not sure";const{event:y,origin:w,da:C}=S;y instanceof WheelEvent||(y.target===v||v!=null&&v.contains(y.target))&&(c.x=w[0],c.y=w[1],l.x=w[0],l.y=w[1],o=C[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:w[0],y:w[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:pr(y)}))},h=S=>{if(S&&(r="zooming"),r==="zooming")return;const v=Math.abs(a-o),y=P.Dist(l,c);switch(r){case"not sure":{v>24?r="zooming":y>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:u,onPinchEnd:S=>{const v=n.current,{event:y,origin:w,offset:C}=S;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const T=C[0]**e.getCameraOptions().zoomSpeed;r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:w[0],y:w[1],z:T},delta:{x:w[0],y:w[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:pr(y)})})},onPinch:S=>{const v=n.current,{event:y,origin:w,offset:C,da:T}=S;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const E=S.type==="gesturechange"||S.type==="gestureend";a=T[0];const _=w[0]-c.x,A=w[1]-c.y;switch(c.x=w[0],c.y=w[1],h(E),r){case"zooming":{const O=C[0]**e.getCameraOptions().zoomSpeed;e.dispatch({type:"pinch",name:"pinch",point:{x:w[0],y:w[1],z:O},delta:{x:_,y:A},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:pr(y)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:w[0],y:w[1],z:i},delta:{x:_,y:A},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:pr(y)});break}}}}},[e,n]);yQ(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:o}=e.getCameraOptions(),i=s[0]*r;return{max:(s[s.length-1]*r)**(1/o),min:i**(1/o)}}}})}function FC(n,e,t){const r=n.getShape(e),s=n.getShapeHandles(r);return{shape:r,handle:s.find(o=>o.id===t)}}function vQ(n,e){const t=ne();return k.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=WS(l.currentTarget);Sg(c,l);const{shape:u,handle:h}=FC(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...Js(l)})};let s,o;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===s&&l.clientY===o)return;s=l.clientX,o=l.clientY;const{shape:c,handle:u}=FC(t,n,e);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...Js(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=WS(l.currentTarget);xg(c,l);const{shape:u,handle:h}=FC(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...Js(l)})}}},[t,n,e])}function wQ(n){const e=ne();k.useLayoutEffect(()=>{const t=H3(()=>{n.current&&e.updateViewportScreenBounds(n.current)},200,{trailing:!0}),r=e.timers.setInterval(t,1e3);window.addEventListener("resize",t);const s=new ResizeObserver(a=>{a[0].contentRect&&t()}),o=n.current;let i=null;return o&&(s.observe(o),i=bQ(o),i.addEventListener("scroll",t)),()=>{clearInterval(r),window.removeEventListener("resize",t),s.disconnect(),i==null||i.removeEventListener("scroll",t),t.cancel()}},[e,n])}/*!
98
+ * Author: excalidraw
99
+ * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
100
+ * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
101
+ */const bQ=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 P(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 left(){return this.x}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get right(){return this.x+this.w}get minY(){return this.y}set minY(e){this.y=e}get top(){return this.y}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get bottom(){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 P(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 P(this.minX,this.minY),new P(this.maxX,this.minY),new P(this.maxX,this.maxY),new P(this.minX,this.maxY)]}get cornersAndCenter(){return[new P(this.minX,this.minY),new P(this.maxX,this.minY),new P(this.maxX,this.maxY),new P(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 P(this.w,this.h)}toFixed(){return this.x=ey(this.x),this.y=ey(this.y),this.w=ey(this.w),this.h=ey(this.h),this}setTo(e){return this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h,this}set(e=0,t=0,r=0,s=0){return this.x=e,this.y=t,this.w=r,this.h=s,this}expand(e){const t=Math.min(this.minX,e.minX),r=Math.min(this.minY,e.minY),s=Math.max(this.maxX,e.maxX),o=Math.max(this.maxY,e.maxY);return this.x=t,this.y=r,this.w=s-t,this.h=o-r,this}expandBy(e){return this.x-=e,this.y-=e,this.w+=e*2,this.h+=e*2,this}scale(e){return this.x/=e,this.y/=e,this.w/=e,this.h/=e,this}clone(){const{x:e,y:t,w:r,h:s}=this;return new 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,o=Math.round(this.maxY/e)*e;this.minX=t,this.minY=r,this.width=Math.max(1,s-t),this.height=Math.max(1,o-r)}collides(e){return 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 P(this.minX,this.minY);case"top_right":return new P(this.maxX,this.minY);case"bottom_left":return new P(this.minX,this.maxY);case"bottom_right":return new P(this.maxX,this.maxY);case"top":return new P(this.midX,this.minY);case"right":return new P(this.maxX,this.midY);case"bottom":return new P(this.midX,this.maxY);case"left":return new P(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(e,t,r){const{minX:s,minY:o,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:h}=this;switch(e){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{u+=t;break}}switch(e){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const p=(u-l)/(i-s),m=(h-c)/(a-o),S=p<0,v=m<0;if(S){const y=u;u=l,l=y}if(v){const y=h;h=c,c=y}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(h-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),o=Math.max(this.maxY,e.h+e.y);return this.x=t,this.y=r,this.width=s-t,this.height=o-r,this}static From(e){return new 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,o=-1/0,i;for(let a=0,l=e.length;a<l;a++)i=e[a],t=Math.min(i.x,t),r=Math.min(i.y,r),s=Math.max(i.x,s),o=Math.max(i.y,o);return new ye(t,r,s-t,o-r)}static Expand(e,t){const r=Math.min(t.minX,e.minX),s=Math.min(t.minY,e.minY),o=Math.max(t.maxX,e.maxX),i=Math.max(t.maxY,e.maxY);return new ye(r,s,o-r,i-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,o=-1/0;for(let i=0;i<e.length;i++){const a=e[i];t=Math.min(t,a.minX),r=Math.min(r,a.minY),s=Math.max(s,a.maxX),o=Math.max(o,a.maxY)}return new ye(t,r,s-t,o-r)}static Sides(e,t=0){const{corners:r}=e;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]}static Resize(e,t,r,s,o=!1){const{minX:i,minY:a,maxX:l,maxY:c}=e;let{minX:u,minY:h,maxX:p,maxY:m}=e;switch(t){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(t){case"top":case"top_left":case"top_right":{h+=s;break}case"bottom":case"bottom_left":case"bottom_right":{m+=s;break}}const S=(p-u)/(l-i),v=(m-h)/(c-a),y=S<0,w=v<0;if(o){const T=(l-i)/(c-a),E=Math.abs(p-u),_=Math.abs(m-h),A=E*(v<0?1:-1)*(1/T),O=_*(S<0?1:-1)*T,D=T<E/_;switch(t){case"top_left":{D?h=m+A:u=p+O;break}case"top_right":{D?h=m+A:p=u-O;break}case"bottom_right":{D?m=h-A:p=u-O;break}case"bottom_left":{D?m=h-A:u=p+O;break}case"bottom":case"top":{const F=(u+p)/2,U=_*T;u=F-U/2,p=F+U/2;break}case"left":case"right":{const F=(h+m)/2,U=E/T;h=F-U/2,m=F+U/2;break}}}if(y){const T=p;p=u,u=T}if(w){const T=m;m=h,h=T}const C=new ye(u,h,Math.abs(p-u),Math.abs(m-h));return{box:C,scaleX:+(C.width/e.width*(S>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 CQ(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 PQ(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 kQ(n){return n==="top_left"||n==="top_right"||n==="bottom_right"||n==="bottom_left"}class de{constructor(e,t,r,s,o,i){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=o,this.f=i}equals(e){return this===e||this.a===e.a&&this.b===e.b&&this.c===e.c&&this.d===e.d&&this.e===e.e&&this.f===e.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(e){const t=e,{a:r,b:s,c:o,d:i,e:a,f:l}=this;return this.a=r*t.a+o*t.b,this.c=r*t.c+o*t.d,this.e=r*t.e+o*t.f+a,this.b=s*t.a+i*t.b,this.d=s*t.c+i*t.d,this.f=s*t.e+i*t.f+l,this}rotate(e,t,r){return e===0?this:t===void 0?this.multiply(de.Rotate(e)):this.translate(t,r).multiply(de.Rotate(e)).translate(-t,-r)}translate(e,t){return this.multiply(de.Translate(e,t))}scale(e,t){return this.multiply(de.Scale(e,t))}invert(){const{a:e,b:t,c:r,d:s,e:o,f:i}=this,a=e*s-t*r;return this.a=s/a,this.b=t/-a,this.c=r/-a,this.d=e/a,this.e=(s*o-r*i)/-a,this.f=(t*o-e*i)/a,this}applyToPoint(e){return de.applyToPoint(this,e)}applyToPoints(e){return de.applyToPoints(this,e)}rotation(){return de.Rotation(this)}point(){return de.Point(this)}decomposed(){return de.Decompose(this)}toCssString(){return de.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return de.Decompose(this)}clone(){return new de(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new de(1,0,0,1,0,0)}static Translate(e,t){return new de(1,0,0,1,e,t)}static Rotate(e,t,r){if(e===0)return de.Identity();const s=Math.cos(e),o=Math.sin(e),i=new de(s,o,-o,s,0,0);return t===void 0?i:de.Compose(de.Translate(t,r),i,de.Translate(-t,-r))}static Scale(e,t,r,s){const o=new de(e,0,0,t,0,0);return r===void 0?o:de.Translate(r,s).multiply(o).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=de.Identity();for(let r=0,s=e.length;r<s;r++)t.multiply(e[r]);return t}static Point(e){return new P(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=qt+Math.acos(e.b/r)*(e.d>0?-1:1)}else t=0;return Ok(t)}static Decompose(e){let t,r,s;if(e.a!==0||e.c!==0){const o=(e.a*e.a+e.c*e.c)**.5;t=o,r=(e.a*e.d-e.b*e.c)/o,s=Math.acos(e.a/o)*(e.c>0?-1:1)}else if(e.b!==0||e.d!==0){const o=(e.b*e.b+e.d*e.d)**.5;t=(e.a*e.d-e.b*e.c)/o,r=o,s=qt+Math.acos(e.b/o)*(e.d>0?-1:1)}else t=0,r=0,s=0;return{x:e.e,y:e.f,scaleX:t,scaleY:r,rotation:Ok(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(${Q(e.a)}, ${Q(e.b)}, ${Q(e.c)}, ${Q(e.d)}, ${Q(e.e)}, ${Q(e.f)})`}static applyToPoint(e,t){return new P(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 P(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 de(e.a,e.b,e.c,e.d,e.e,e.f)}static Cast(e){return e instanceof de?e:de.From(e)}}function h4(n,e){return e===0?n:h4(e,n%e)}function f4(n){const e=n.toString().split(".")[1];if(!e)return 1;const t=Math.pow(10,e.length),r=parseInt(e,10);return t/h4(r,t)}function w0(n,e,t,r){const s=n.x-t.x,o=n.y-t.y,i=r.x-t.x,a=r.y-t.y,l=e.x-n.x,c=e.y-n.y,u=i*o-a*s,h=l*o-c*s,p=a*l-i*c;if(u===0||h===0||p===0)return null;if(p!==0){const m=u/p,S=h/p;if(0<=m&&m<=1&&0<=S&&S<=1)return P.AddXY(n,m*l,m*c)}return null}function bg(n,e,t,r){const s=(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y),o=2*((e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y)),i=t.x*t.x+t.y*t.y+n.x*n.x+n.y*n.y-2*(t.x*n.x+t.y*n.y)-r*r,a=o*o-4*s*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-o+l)/(2*s),u=(-o-l)/(2*s);if((c<0||c>1)&&(u<0||u>1))return null;const h=[];return 0<=c&&c<=1&&h.push(P.Lrp(n,e,c)),0<=u&&u<=1&&h.push(P.Lrp(n,e,u)),h.length===0?null:h}function EQ(n,e,t){const r=[];let s;for(let o=0,i=t.length-1;o<i;o++)s=w0(n,e,t[o],t[o+1]),s&&r.push(s);return r.length===0?null:r}function p4(n,e,t){const r=[];let s;for(let o=1,i=t.length;o<i+1;o++)s=w0(n,e,t[o-1],t[o%t.length]),s&&r.push(s);return r.length===0?null:r}function IQ(n,e,t,r){let s=t.x-n.x,o=t.y-n.y;const i=Math.sqrt(s*s+o*o),a=(i*i-r*r+e*e)/(2*i),l=Math.sqrt(e*e-a*a);return s/=i,o/=i,[new P(n.x+s*a-o*l,n.y+o*a+s*l),new P(n.x+s*a+o*l,n.y+o*a-s*l)]}function TQ(n,e,t){const r=[];let s,o,i;for(let a=0,l=t.length;a<l;a++)s=t[a],o=t[(a+1)%t.length],i=bg(s,o,n,e),i&&r.push(...i);return r.length===0?null:r}function _Q(n,e,t){const r=[];let s,o,i;for(let a=1,l=t.length;a<l;a++)s=t[a-1],o=t[a],i=bg(s,o,n,e),i&&r.push(...i);return r.length===0?null:r}function ny(n,e,t){return(t.y-n.y)*(e.x-n.x)>(e.y-n.y)*(t.x-n.x)}function oT(n,e,t,r){return ny(n,t,r)!==ny(e,t,r)&&ny(n,e,t)!==ny(n,e,r)}function dj(n,e){const t=new Map;let r,s,o,i;for(let a=0,l=n.length;a<l;a++)if(r=n[a],so(r,e)){const c=qy(r);t.has(c)||t.set(c,r)}for(let a=0,l=e.length;a<l;a++)if(r=e[a],so(r,n)){const c=qy(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,u=e.length;c<u;c++){o=e[c],i=e[(c+1)%e.length];const h=w0(r,s,o,i);if(h!==null){const p=qy(h);t.has(p)||t.set(p,h)}}}return t.size===0?null:MQ([...t.values()])}function hj(n,e,t,r){const s=new Map;for(let o=0,i=t?n.length:n.length-1;o<i;o++){const a=n[o],l=n[(o+1)%n.length];for(let c=0,u=r?e.length:e.length-1;c<u;c++){const h=e[c],p=e[(c+1)%e.length],m=w0(a,l,h,p);if(m!==null){const S=qy(m);s.has(S)||s.set(S,m)}}}return[...s.values()]}function qy(n){return`${n.x},${n.y}`}function MQ(n){const e=P.Average(n);return n.sort((t,r)=>P.Angle(e,t)-P.Angle(e,r))}function iT(n,e){let t,r,s,o;for(let i=0,a=n.length;i<a;i++){t=n[i],r=n[(i+1)%a];for(let l=0,c=e.length;l<c;l++)if(s=e[l],o=e[(l+1)%c],oT(t,r,s,o))return!0}return!1}function AQ(n,e){let t,r,s,o;for(let i=0,a=n.length;i<a;i++){t=n[i],r=n[(i+1)%a];for(let l=1,c=e.length;l<c;l++)if(s=e[l-1],o=e[l],oT(t,r,s,o))return!0}return!1}const qi={EXCLUDE_NON_STANDARD:{includeLabels:!1,includeInternal:!1},EXCLUDE_LABELS:{includeLabels:!1,includeInternal:!0}};class nl{constructor(e){R(this,"isFilled",!1);R(this,"isClosed",!0);R(this,"isLabel",!1);R(this,"isInternal",!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.isInternal=e.isInternal??!1,this.debugColor=e.debugColor,this.ignore=e.ignore}isExcludedByFilter(e){return e?!!(this.isLabel&&!e.includeLabels||this.isInternal&&!e.includeInternal):!1}hitTestPoint(e,t=0,r=!1,s){return this.isClosed&&(this.isFilled||r)&&so(e,this.vertices)?!0:P.Dist2(e,this.nearestPoint(e))<=t*t}distanceToPoint(e,t=!1,r){return P.Dist(e,this.nearestPoint(e,r))*(this.isClosed&&(this.isFilled||t)&&so(e,this.vertices)?-1:1)}distanceToLineSegment(e,t,r){if(P.Equals(e,t))return this.distanceToPoint(e,!1,r);const{vertices:s}=this;let o,i=1/0,a,l,c;for(let u=0;u<s.length;u++)l=s[u],c=P.NearestPointOnLineSegment(e,t,l,!0),a=P.Dist2(l,c),a<i&&(i=a,o=c);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&so(o,this.vertices)?-i:i}hitTestLineSegment(e,t,r=0,s){return this.distanceToLineSegment(e,t,s)<=r}intersectLineSegment(e,t,r){return(this.isClosed?p4(e,t,this.vertices):EQ(e,t,this.vertices))??[]}intersectCircle(e,t,r){return(this.isClosed?TQ(e,t,this.vertices):_Q(e,t,this.vertices))??[]}intersectPolygon(e,t){return hj(e,this.vertices,!0,this.isClosed)}intersectPolyline(e,t){return hj(e,this.vertices,!1,this.isClosed)}interpolateAlongEdge(e,t){const{vertices:r}=this;if(e<=0)return r[0];const s=e*this.length;let o=0;for(let i=0;i<(this.isClosed?r.length:r.length-1);i++){const a=r[i],l=r[(i+1)%r.length],c=P.Dist(a,l),u=o+c;if(u>=s)return P.Lrp(a,l,rh(o,u,s));o=u}return this.isClosed?r[0]:r[r.length-1]}uninterpolateAlongEdge(e,t){const{vertices:r,length:s}=this;let o=null,i=1/0,a=0;for(let c=0;c<(this.isClosed?r.length:r.length-1);c++){const u=r[c],h=r[(c+1)%r.length],p=P.NearestPointOnLineSegment(u,h,e,!0),m=P.Dist(p,e);m<i&&(i=m,o={start:u,end:h,nearestPoint:p,distanceToStart:a}),a+=P.Dist(u,h)}return Ve(o),(o.distanceToStart+P.Dist(o.start,o.nearestPoint))/s}nearestPointOnLineSegment(e,t){const{vertices:r}=this;let s,o=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=P.NearestPointOnLineSegment(e,t,a,!0),i=P.Dist2(a,l),i<o&&(o=i,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)}transform(e,t){return new aT(this,e,t)}get vertices(){return this._vertices||(this._vertices=this.getVertices(qi.EXCLUDE_LABELS)),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 o=e[r],i=e[(r+1)%s];t+=o.x*i.y-i.x*o.y}return t/2}toSimpleSvgPath(){let e="";const{vertices:t}=this,r=t.length;if(r===0)return e;e+=`M${t[0].x},${t[0].y}`;for(let s=1;s<r;s++)e+=`L${t[s].x},${t[s].y}`;return this.isClosed&&(e+="Z"),e}get length(){return this._length?this._length:(this._length=this.getLength(qi.EXCLUDE_LABELS),this._length)}getLength(e){const t=this.getVertices(e??qi.EXCLUDE_LABELS);if(t.length===0)return 0;let r=t[0],s=0;for(let o=1;o<t.length;o++){const i=t[o];s+=P.Dist(r,i),r=i}return this.isClosed&&(s+=P.Dist(t[t.length-1],t[0])),s}}class aT extends nl{constructor(t,r,s){super(t);R(this,"inverse");R(this,"decomposed");this.geometry=t,this.matrix=r,this.inverse=de.Inverse(r),this.decomposed=de.Decompose(r),s&&(s.isLabel!=null&&(this.isLabel=s.isLabel),s.isInternal!=null&&(this.isInternal=s.isInternal),s.debugColor!=null&&(this.debugColor=s.debugColor),s.ignore!=null&&(this.ignore=s.ignore)),Ve(ro(this.decomposed.scaleX,this.decomposed.scaleY),"non-uniform scaling is not yet supported")}getVertices(t){return this.geometry.getVertices(t).map(r=>de.applyToPoint(this.matrix,r))}nearestPoint(t,r){return de.applyToPoint(this.matrix,this.geometry.nearestPoint(de.applyToPoint(this.inverse,t),r))}hitTestPoint(t,r=0,s,o){return this.geometry.hitTestPoint(de.applyToPoint(this.inverse,t),r/this.decomposed.scaleX,s,o)}distanceToPoint(t,r=!1,s){return this.geometry.distanceToPoint(de.applyToPoint(this.inverse,t),r,s)*this.decomposed.scaleX}distanceToLineSegment(t,r,s){return this.geometry.distanceToLineSegment(de.applyToPoint(this.inverse,t),de.applyToPoint(this.inverse,r),s)*this.decomposed.scaleX}hitTestLineSegment(t,r,s=0,o){return this.geometry.hitTestLineSegment(de.applyToPoint(this.inverse,t),de.applyToPoint(this.inverse,r),s/this.decomposed.scaleX,o)}intersectLineSegment(t,r,s){return de.applyToPoints(this.matrix,this.geometry.intersectLineSegment(de.applyToPoint(this.inverse,t),de.applyToPoint(this.inverse,r),s))}intersectCircle(t,r,s){return de.applyToPoints(this.matrix,this.geometry.intersectCircle(de.applyToPoint(this.inverse,t),r/this.decomposed.scaleX,s))}intersectPolygon(t,r){return de.applyToPoints(this.matrix,this.geometry.intersectPolygon(de.applyToPoints(this.inverse,t),r))}intersectPolyline(t,r){return de.applyToPoints(this.matrix,this.geometry.intersectPolyline(de.applyToPoints(this.inverse,t),r))}transform(t,r){return new aT(this.geometry,de.Multiply(t,this.matrix),{isLabel:(r==null?void 0:r.isLabel)??this.isLabel,isInternal:(r==null?void 0:r.isInternal)??this.isInternal,debugColor:(r==null?void 0:r.debugColor)??this.debugColor,ignore:(r==null?void 0:r.ignore)??this.ignore})}getSvgPathData(){throw new Error("Cannot get SVG path data for transformed geometry.")}}class ds extends nl{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(t){return this.isExcludedByFilter(t)?[]:this.children.filter(r=>!r.isExcludedByFilter(t)).flatMap(r=>r.getVertices(t))}nearestPoint(t,r){let s=1/0,o;const{children:i}=this;if(i.length===0)throw Error("no children");let a,l;for(const c of i)c.isExcludedByFilter(r)||(a=c.nearestPoint(t,r),l=P.Dist2(a,t),l<s&&(s=l,o=a));if(!o)throw Error("nearest point not found");return o}distanceToPoint(t,r=!1,s){let o=1/0;for(const i of this.children){if(i.isExcludedByFilter(s))continue;const a=i.distanceToPoint(t,r,s);a<o&&(o=a)}return o}hitTestPoint(t,r,s,o=qi.EXCLUDE_LABELS){return!!this.children.filter(i=>!i.isExcludedByFilter(o)).find(i=>i.hitTestPoint(t,r,s))}hitTestLineSegment(t,r,s,o=qi.EXCLUDE_LABELS){return!!this.children.filter(i=>!i.isExcludedByFilter(o)).find(i=>i.hitTestLineSegment(t,r,s))}intersectLineSegment(t,r,s){return this.children.flatMap(o=>o.isExcludedByFilter(s)?jr:o.intersectLineSegment(t,r,s))}intersectCircle(t,r,s){return this.children.flatMap(o=>o.isExcludedByFilter(s)?jr:o.intersectCircle(t,r,s))}intersectPolygon(t,r){return this.children.flatMap(s=>s.isExcludedByFilter(r)?jr:s.intersectPolygon(t,r))}intersectPolyline(t,r){return this.children.flatMap(s=>s.isExcludedByFilter(r)?jr:s.intersectPolyline(t,r))}interpolateAlongEdge(t,r){const s=this.getLength(r),o=t*s;let i=0;for(const a of this.children){if(a.isExcludedByFilter(r))continue;const l=a.length,c=i+l;if(c>=o)return a.interpolateAlongEdge(rh(i,c,o),r);i=c}return this.children[this.children.length-1].interpolateAlongEdge(1,r)}uninterpolateAlongEdge(t,r){const s=this.getLength(r);let o=null,i=1/0,a=0;for(const u of this.children){if(u.isExcludedByFilter(r))continue;const h=u.getLength(r),p=a+h,m=u.distanceToPoint(t,!1,r);m<i&&(i=m,o={startLength:a,endLength:p,child:u}),a=p}Ve(o);const l=o.child.uninterpolateAlongEdge(t,r);return rt(o.startLength,o.endLength,l)/s}transform(t){return new ds({children:this.children.map(r=>r.transform(t)),isLabel:this.isLabel,debugColor:this.debugColor,ignore:this.ignore})}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,o=r.length;s<o;s++){const i=r[s],a=r[(s-1+o)%o],l=i.dist(a),c=r[(s+1)%o],u=i.dist(c),h=i.clone().lrp(a,4/l),p=i,m=i.clone().lrp(c,4/u);t+=`M${h.x},${h.y} L${p.x},${p.y} L${m.x},${m.y} `}return t}getLength(t){let r=0;for(const s of this.children)s.isExcludedByFilter(t)||(r+=s.length);return r}getSvgPathData(){return this.children.map((t,r)=>t.isLabel?"":t.getSvgPathData(r===0)).join(" ")}}function OQ(n=!0){const[e,t]=k.useState(0),r=ne();k.useEffect(()=>{if(!n)return;const s=()=>t(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const RQ=tr(function({showStroke:e=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const s=ne();OQ(r);const o=s.getZoomLevel(),i=s.getRenderingShapes(),{inputs:{currentPagePoint:a}}=s;return g.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=s.getShape(l.id);if(c.type==="group")return null;const u=s.getShapeGeometry(c),h=s.getShapePageTransform(c),p=s.getPointInShapeSpace(c,a),m=u.nearestPoint(p),S=u.distanceToPoint(p,!0),v=Math.abs(S)*o,y=S<0,{vertices:w}=u;return g.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&g.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/o,fill:"none",children:g.jsx(g4,{geometry:u})}),t&&w.map((C,T)=>g.jsx("circle",{cx:C.x,cy:C.y,r:2/o,fill:`hsl(${sh(T,[0,w.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/o},`v${T}`)),r&&v<150&&g.jsx("line",{x1:m.x,y1:m.y,x2:p.x,y2:p.y,opacity:1-v/150,stroke:y?"goldenrod":"dodgerblue",strokeWidth:2/o})]},l.id+"_outline")})})});function g4({geometry:n}){return n instanceof ds?g.jsx("g",{stroke:n.debugColor,children:[...n.children,...n.ignoredChildren].map((e,t)=>g.jsx(g4,{geometry:e},t))}):g.jsx("path",{d:n.toSimpleSvgPath(),stroke:n.debugColor})}function m4(n){return KG(n)}function y4(){const n=ne(),e=eX("userIds",()=>m4(n.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>{var s;return t.join(",")===((s=r.join)==null?void 0:s.call(r,","))}},[n]);return se(e)}function b0(n){const e=ne();return se(`latestPresence:${n}`,()=>e.getCollaborators().find(r=>r.userId===n),[e,n])??null}const DQ=tr(function(){return y4().map(t=>g.jsx(jQ,{collaboratorId:t},t))}),jQ=tr(function({collaboratorId:e}){const t=ne(),r=b0(e),s=NQ(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(s){case"inactive":{const{followingUserId:o,highlightedUserIds:i}=t.getInstanceState();if(!(o===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:o}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||o.includes(r.userId)))return null;break}}return g.jsx(LQ,{latestPresence:r})}),LQ=tr(function({latestPresence:e}){const t=ne(),{CollaboratorBrush:r,CollaboratorScribble:s,CollaboratorCursor:o,CollaboratorHint:i,CollaboratorShapeIndicator:a}=Ft(),l=t.getZoomLevel(),c=t.getViewportPageBounds(),{userId:u,chatMessage:h,brush:p,scribbles:m,selectedShapeIds:S,userName:v,cursor:y,color:w}=e;if(!y)return null;const C=!(y.x<c.minX-12/l||y.y<c.minY-16/l||y.x>c.maxX-12/l||y.y>c.maxY-16/l);return g.jsxs(g.Fragment,{children:[p&&r?g.jsx(r,{className:"tl-collaborator__brush",userId:u,brush:p,color:w,opacity:.1},u+"_brush"):null,C&&o?g.jsx(o,{className:"tl-collaborator__cursor",userId:u,point:y,color:w,zoom:l,name:v!=="New User"?v:null,chatMessage:h??""},u+"_cursor"):i?g.jsx(i,{className:"tl-collaborator__cursor-hint",userId:u,point:y,color:w,zoom:l,viewport:c},u+"_cursor_hint"):null,s&&m.length?g.jsx(g.Fragment,{children:m.map(T=>g.jsx(s,{className:"tl-collaborator__scribble",userId:u,scribble:T,color:w,zoom:l,opacity:T.color==="laser"?.5:.1},u+"_scribble_"+T.id))}):null,a&&S.filter(T=>!t.isShapeHidden(T)).map(T=>g.jsx(a,{className:"tl-collaborator__shape-indicator",userId:u,shapeId:T,color:w,opacity:.5},u+"_"+T))]})});function fj(n,e){return e>n.options.collaboratorInactiveTimeoutMs?"inactive":e>n.options.collaboratorIdleTimeoutMs?"idle":"active"}function NQ(n,e){const t=k.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,s]=k.useState(()=>fj(n,Date.now()-t.current));return k.useEffect(()=>{const o=n.timers.setInterval(()=>{s(fj(n,Date.now()-t.current))},n.options.collaboratorCheckIntervalMs);return()=>clearInterval(o)},[n]),e&&(t.current=e.lastActivityTimestamp??1/0),r}function FQ(){const n=ne(),e=se("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),[t,r]=k.useState(!1),s=e||t,o=rT(),i=k.useRef({isDown:!1,isDragging:!1,start:new P}),a=k.useCallback(u=>{u.button===0&&(r(!0),i.current={isDown:!0,isDragging:!1,start:new P(u.clientX,u.clientY)}),n.menus.clearOpenMenus()},[n]),l=k.useCallback(u=>{var h,p,m;if(i.current.isDown){if(i.current.isDragging){(h=o.onPointerMove)==null||h.call(o,u);return}if(P.Dist2(i.current.start,new P(u.clientX,u.clientY))>n.options.dragDistanceSquared){i.current={...i.current,isDown:!0,isDragging:!0};const{x:S,y:v}=i.current.start;(p=o.onPointerDown)==null||p.call(o,{...u,clientX:S,clientY:v,button:0}),(m=o.onPointerMove)==null||m.call(o,u)}}},[o,n]),c=k.useCallback(u=>{var h;(h=o.onPointerUp)==null||h.call(o,u),r(!1),i.current={isDown:!1,isDragging:!1,start:new P(u.clientX,u.clientY)}},[o]);return s&&g.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...o,onPointerDown:a,onPointerMove:l,onPointerUp:c})}const jk=(n,e)=>n.props===e.props&&n.meta===e.meta,S4=k.memo(function({id:e,shape:t,util:r,index:s,backgroundIndex:o,opacity:i,dprMultiple:a}){const l=ne(),{ShapeErrorFallback:c}=Ft(),u=k.useRef(null),h=k.useRef(null);k.useEffect(()=>jo("load fonts",()=>{const v=l.fonts.getShapeFontFaces(e);l.fonts.requestFonts(v)}),[l,e]);const p=k.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});ec("set shape stuff",()=>{const v=l.getShape(e);if(!v)return;const y=p.current,w=l.getShapeClipPath(e)??"none";w!==y.clipPath&&(_r(u.current,"clip-path",w),_r(h.current,"clip-path",w),y.clipPath=w);const C=l.getShapePageTransform(e),T=de.toCssString(C),E=l.getShapeGeometry(v).bounds;T!==y.transform&&(_r(u.current,"transform",T),_r(h.current,"transform",T),y.transform=T);const _=E.w%a,A=E.h%a,O=_===0?E.w:E.w+(a-_),D=A===0?E.h:E.h+(a-A);(O!==y.width||D!==y.height)&&(_r(u.current,"width",Math.max(O,a)+"px"),_r(u.current,"height",Math.max(D,a)+"px"),_r(h.current,"width",Math.max(O,a)+"px"),_r(h.current,"height",Math.max(D,a)+"px"),y.width=O,y.height=D)},[l]),k.useLayoutEffect(()=>{const v=u.current,y=h.current;_r(v,"opacity",i),_r(y,"opacity",i),_r(v,"z-index",s),_r(y,"z-index",o)},[i,s,o]),ec("set display",()=>{if(!l.getShape(e))return;const w=l.getCulledShapes().has(e);w!==p.current.isCulled&&(_r(u.current,"display",w?"none":"block"),_r(h.current,"display",w?"none":"block"),p.current.isCulled=w)},[l]);const m=k.useCallback(v=>l.annotateError(v,{origin:"shape",willCrashApp:!1}),[l]);if(!t)return null;const S="fill"in t.props&&t.props.fill!=="none";return g.jsxs(g.Fragment,{children:[r.backgroundComponent&&g.jsx("div",{ref:h,className:"tl-shape tl-shape-background","data-shape-type":t.type,"data-shape-id":t.id,draggable:!1,children:g.jsx(Fp,{fallback:c,onError:m,children:g.jsx(v4,{shape:t,util:r})})}),g.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":S,"data-shape-id":t.id,draggable:!1,children:g.jsx(Fp,{fallback:c,onError:m,children:g.jsx(x4,{shape:t,util:r})})})]})}),x4=k.memo(function({shape:e,util:t}){return c0("InnerShape:"+e.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(e.id)),[t,e.id])},(n,e)=>jk(n.shape,e.shape)&&n.util===e.util),v4=k.memo(function({shape:e,util:t}){return c0("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 zQ({className:n}){const e=ne(),{SelectionBackground:t,Background:r,SvgDefs:s,ShapeIndicators:o}=Ft(),i=k.useRef(null),a=k.useRef(null),l=k.useRef(null),c=_n();wQ(i),pJ(),fJ(),xQ(i),mJ(i);const u=k.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});ec("position layers",function(){const{x:T,y:E,z:_}=e.getCamera();if(u.current.allowTextOutline&&Tt.isSafari&&(c.style.setProperty("--tl-text-outline","none"),u.current.allowTextOutline=!1),u.current.allowTextOutline&&_<e.options.textShadowLod!==u.current.lodDisableTextOutline){const D=_<e.options.textShadowLod;c.style.setProperty("--tl-text-outline",D?"none":"var(--tl-text-outline-reference)"),u.current.lodDisableTextOutline=D}const A=_>=1?sh(_,[1,8],[.125,.5],!0):sh(_,[.1,1],[-2,.125],!0),O=`scale(${Q(_)}) translate(${Q(T+A)}px,${Q(E+A)}px)`;_r(a.current,"transform",O),_r(l.current,"transform",O)},[e,c]);const h=rT(),p=se("shapeSvgDefs",()=>{const C=new Map;for(const T of Sn(e.shapeUtils)){if(!T)return;const E=T.getCanvasSvgDefs();for(const{key:_,component:A}of E)C.has(_)||C.set(_,g.jsx(A,{},_))}return[...C.values()]},[e]),m=se("debug_shapes",()=>sn.hideShapes.get(),[sn]),S=se("debug_svg",()=>sn.debugSvg.get(),[sn]),v=se("debug_geometry",()=>sn.debugGeometry.get(),[sn]),y=se("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),w=se("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return g.jsxs(g.Fragment,{children:[g.jsxs("div",{ref:i,draggable:!1,"data-iseditinganything":y,"data-isselectinganything":w,className:$e("tl-canvas",n),"data-testid":"canvas",...h,children:[g.jsx("svg",{className:"tl-svg-context",children:g.jsxs("defs",{children:[p,g.jsx(eee,{}),g.jsx(tee,{}),s&&g.jsx(s,{})]})}),r&&g.jsx("div",{className:"tl-background__wrapper",children:g.jsx(r,{})}),g.jsx($Q,{}),g.jsxs("div",{ref:a,className:"tl-html-layer tl-shapes",draggable:!1,children:[g.jsx(oee,{}),t&&g.jsx(see,{}),m?null:S?g.jsx(XQ,{}):g.jsx(JQ,{})]}),g.jsx("div",{className:"tl-overlays",children:g.jsxs("div",{ref:l,className:"tl-html-layer",children:[v?g.jsx(RQ,{}):null,g.jsx(HQ,{}),g.jsx(UQ,{}),g.jsx(KQ,{}),o&&g.jsx(o,{}),g.jsx(QQ,{}),g.jsx(WQ,{}),g.jsx(ree,{}),g.jsx(VQ,{}),g.jsx(YQ,{}),g.jsx(DQ,{})]})}),g.jsx(iee,{})]}),g.jsx(FQ,{}),g.jsx(BQ,{})]})}function BQ(){const{InFrontOfTheCanvas:n}=Ft();return n?g.jsx(n,{}):null}function $Q(){const n=ne(),e=se("gridSize",()=>n.getDocumentSettings().gridSize,[n]),{x:t,y:r,z:s}=se("camera",()=>n.getCamera(),[n]),o=se("isGridMode",()=>n.getInstanceState().isGridMode,[n]),{Grid:i}=Ft();return i&&o?g.jsx(i,{x:t,y:r,z:s,size:e}):null}function UQ(){const n=ne(),e=se("scribbles",()=>n.getInstanceState().scribbles,[n]),t=se("zoomLevel",()=>n.getZoomLevel(),[n]),{Scribble:r}=Ft();return r&&e.length?e.map(s=>g.jsx(r,{className:"tl-user-scribble",scribble:s,zoom:t},s.id)):null}function HQ(){const n=ne(),e=se("brush",()=>n.getInstanceState().brush,[n]),{Brush:t}=Ft();return t&&e?g.jsx(t,{className:"tl-user-brush",brush:e}):null}function KQ(){const n=ne(),e=se("zoomBrush",()=>n.getInstanceState().zoomBrush,[n]),{ZoomBrush:t}=Ft();return t&&e?g.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function WQ(){const n=ne(),e=se("snapLines",()=>n.snaps.getIndicators(),[n]),t=se("zoomLevel",()=>n.getZoomLevel(),[n]),{SnapIndicator:r}=Ft();return r&&e.length>0?e.map(s=>g.jsx(r,{className:"tl-user-snapline",line:s,zoom:t},s.id)):null}function VQ(){const n=ne(),e=se("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=n.getInstanceState();if(t||r)return!1;const s=n.getOnlySelectedShape();return!s||!n.getShapeHandles(s)?!1:s.id},[n]);return e?g.jsx(GQ,{shapeId:e}):null}function GQ({shapeId:n}){const e=ne(),{Handles:t}=Ft(),r=se("zoomLevel",()=>e.getZoomLevel(),[e]),s=se("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),o=se("handles transform",()=>e.getShapePageTransform(n),[e,n]),i=se("handles",()=>{const l=e.getShapeHandles(n);if(!l)return null;const c=(s?e.options.coarseHandleRadius:e.options.handleRadius)/r*2;return l.filter(u=>u.type!=="virtual"||!l.some(h=>h!==u&&h.type==="vertex"&&P.Dist(u,h)<c)).sort(u=>u.type==="vertex"?1:-1)},[e,r,s,n]),a=se("isHidden",()=>e.isShapeHidden(n),[e,n]);return!t||!i||!o||a?null:g.jsx(t,{children:g.jsx("g",{transform:de.toCssString(o),children:i.map(l=>g.jsx(qQ,{shapeId:n,handle:l,zoom:r,isCoarse:s},l.id))})})}function qQ({shapeId:n,handle:e,zoom:t,isCoarse:r}){const s=vQ(n,e.id),{Handle:o}=Ft();return o?g.jsx("g",{role:"button","aria-label":e.label||"handle",transform:`translate(${e.x}, ${e.y})`,...s,children:g.jsx(o,{shapeId:n,handle:e,zoom:t,isCoarse:r})}):null}function YQ(){const{Overlays:n}=Ft();return n?g.jsx("div",{className:"tl-custom-overlays tl-overlays__item",children:g.jsx(n,{})}):null}function XQ(){const n=ne(),e=se("rendering shapes",()=>n.getRenderingShapes(),[n]),t=se("dpr multiple",()=>f4(Math.floor(n.getInstanceState().devicePixelRatio*100)/100),[n]);return e.map(r=>g.jsxs(k.Fragment,{children:[g.jsx(S4,{...r,dprMultiple:t}),g.jsx(nee,{id:r.id,mode:"iframe"})]},r.id+"_fragment"))}function ZQ(){const n=ne(),e=k.useRef(new Set);return ec("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 JQ(){const n=ne(),e=se("rendering shapes",()=>n.getRenderingShapes(),[n]),t=se("dpr multiple",()=>f4(Math.floor(n.getInstanceState().devicePixelRatio*100)/100),[n]);return g.jsxs(g.Fragment,{children:[e.map(r=>g.jsx(S4,{...r,dprMultiple:t},r.id+"_shape")),Tt.isSafari&&g.jsx(ZQ,{})]})}function QQ(){const n=ne(),{ShapeIndicator:e}=Ft(),t=se("hinting shape ids",()=>cI(n.getHintingShapeIds()),[n]);return!t.length||!e?null:t.map(r=>g.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function eee(){return g.jsxs("g",{id:hi("cursor"),children:[g.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[g.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),g.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),g.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[g.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),g.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),g.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[g.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),g.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function tee(){const n=hi("cursor_hint");return g.jsx("path",{id:n,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function nee({id:n,mode:e}){const t=ne(),[r,s]=k.useState(null),o=se("is in root",()=>{const i=t.getShape(n);return(i==null?void 0:i.parentId)===t.getCurrentPageId()},[t,n]);return k.useEffect(()=>{if(!o)return;let i=null;const a=jo("shape to svg",async()=>{const l=Math.random();i=l;const u=t.isShapeOfType(n,"frame")?0:10;let h=t.getShapePageBounds(n);if(!h)return;h=h.clone().expandBy(u);const p=await t.getSvgString([n],{padding:u});if(i!==l||!p)return;const m=`data:image/svg+xml;utf8,${encodeURIComponent(p.svg)}`;s({src:m,bounds:h})});return()=>{i=null,a()}},[t,n,o]),!o||!r?null:e==="iframe"?g.jsx("iframe",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,border:"none",transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}}):g.jsx("img",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function ree(){const n=ne(),e=se("selection rotation",function(){return n.getSelectionRotation()},[n]),t=se("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionForeground:r}=Ft();return!t||!r?null:g.jsx(r,{bounds:t,rotation:e})}function see(){const n=ne(),e=se("selection rotation",()=>n.getSelectionRotation(),[n]),t=se("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionBackground:r}=Ft();return!t||!r?null:g.jsx(r,{bounds:t,rotation:e})}function oee(){const{OnTheCanvas:n}=Ft();return n?g.jsx(n,{}):null}function iee(){const n=ne(),e=se("camera state",()=>n.getCameraState(),[n]);return g.jsx("div",{className:$e("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function aee({className:n,zoom:e,point:t,color:r,viewport:s,opacity:o=1}){const i=k.useRef(null);yg(i,$t(t.x,s.minX+5/e,s.maxX-5/e),$t(t.y,s.minY+5/e,s.maxY-5/e),1/e,P.Angle(s.center,t));const a=hi("cursor_hint");return g.jsxs("svg",{ref:i,className:$e("tl-overlays__item",n),children:[g.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--color-background)"}),g.jsx("use",{href:`#${a}`,color:r,opacity:o})]})}const pj=k.memo(function({className:e,zoom:t,point:r,color:s,name:o,chatMessage:i}){const a=k.useRef(null);yg(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t);const l=hi("cursor");return r?g.jsxs("div",{ref:a,className:$e("tl-overlays__item",e),children:[g.jsx("svg",{className:"tl-cursor",children:g.jsx("use",{href:`#${l}`,color:s})}),i?g.jsxs(g.Fragment,{children:[o&&g.jsx("div",{className:"tl-nametag-title",style:{color:s},children:o}),g.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:s},children:i})]}):o&&g.jsx("div",{className:"tl-nametag",style:{backgroundColor:s},children:o})]}):null});function lee({x:n,y:e,z:t,size:r}){const s=Ou("grid"),o=ne(),{gridSteps:i}=o.options;return g.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[g.jsx("defs",{children:i.map(({min:a,mid:l,step:c},u)=>{const h=c*r*t,p=.5+n*t,m=.5+e*t,S=p>0?p%h:h+p%h,v=m>0?m%h:h+m%h,y=t<l?sh(t,[a,l],[0,1]):1;return g.jsx("pattern",{id:JI(s,`${c}`),width:h,height:h,patternUnits:"userSpaceOnUse",children:g.jsx("circle",{className:"tl-grid-dot",cx:S,cy:v,r:1,opacity:y})},u)})}),i.map(({step:a},l)=>g.jsx("rect",{width:"100%",height:"100%",fill:`url(#${s}_${a})`},l))]})}function cee({handle:n,isCoarse:e,className:t,zoom:r}){const s=ne(),o=(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=aJ.indexOf(n.id);return g.jsxs("g",{className:$e(`tl-handle tl-handle__${n.type}`,t),children:[g.jsx("circle",{className:"tl-handle__bg",r:o}),g.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*c})`})]})}const i=(n.type==="create"&&e?3:4)/Math.max(r,.25);return g.jsxs("g",{className:$e(`tl-handle tl-handle__${n.type}`,t),children:[g.jsx("circle",{className:"tl-handle__bg",r:o}),g.jsx("circle",{className:"tl-handle__fg",r:i})]})}const uee=({children:n})=>g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}),dee=()=>{const{Spinner:n}=Ft();return g.jsx(Y$,{children:n?g.jsx(n,{}):null})};function lT(n,e=!0){const t=n.length;if(t<2)return"";let r=n[0],s=n[1];if(t===2)return`M${kt(r)}L${kt(s)}`;let o="";for(let i=2,a=t-1;i<a;i++)r=n[i],s=n[i+1],o+=_s(r,s);return e?`M${_s(n[0],n[1])}Q${kt(n[1])}${_s(n[1],n[2])}T${o}${_s(n[t-1],n[0])}${_s(n[0],n[1])}Z`:`M${kt(n[0])}Q${kt(n[1])}${_s(n[1],n[2])}${n.length>3?"T":""}${o}L${kt(n[t-1])}`}function gj({scribble:n,zoom:e,color:t,opacity:r,className:s}){return n.points.length?g.jsx("svg",{className:s&&$e("tl-overlays__item",s),children:g.jsx("path",{className:"tl-scribble",d:lT(n.points,!1),stroke:t??`var(--color-${n.color})`,fill:"none",strokeWidth:8/e,opacity:r??n.opacity})}):null}function hee({bounds:n,rotation:e}){const t=ne(),r=k.useRef(null),s=se("only selected shape",()=>t.getOnlySelectedShape(),[t]),o=s?t.getShapeUtil(s).expandSelectionOutlinePx(s):0;return yg(r,n==null?void 0:n.x,n==null?void 0:n.y,1,e,{x:-o,y:-o}),n=o instanceof ye?n.clone().expand(o).zeroFix():n.clone().expandBy(o).zeroFix(),g.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:g.jsx("rect",{className:$e("tl-selection__fg__outline"),width:Q(n.width),height:Q(n.height)})})}const fee=()=>g.jsx("div",{className:"tl-shape-error-boundary"}),pee=k.memo(({shape:n,util:e})=>c0("Indicator: "+n.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(n.id))),(n,e)=>n.shape.props===e.shape.props&&n.shape.meta===e.shape.meta),gee=k.memo(({editor:n,id:e})=>{const t=se("shape for indicator",()=>n.store.get(e),[n,e]),{ShapeIndicatorErrorFallback:r}=Ft();return!t||t.isLocked?null:g.jsx(Fp,{fallback:r,onError:s=>n.annotateError(s,{origin:"react.shapeIndicator",willCrashApp:!1}),children:g.jsx(pee,{shape:t,util:n.getShapeUtil(t)},t.id)})}),mj=k.memo(function({shapeId:e,className:t,color:r,hidden:s,opacity:o}){const i=ne(),a=k.useRef(null);return ec("indicator transform",()=>{if(s)return;const l=a.current;if(!l)return;const c=i.getShapePageTransform(e);c&&l.style.setProperty("transform",c.toCssString())},[i,e,s]),k.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",s?"none":"block")},[s]),g.jsx("svg",{ref:a,className:$e("tl-overlays__item",t),children:g.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:o,children:g.jsx(gee,{editor:i,id:e})})})}),mee=()=>g.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),w4=k.memo(function({hideAll:e,showAll:t}){const r=ne();if(e&&t)throw Error("You cannot set both hideAll and showAll props to true, cmon now");const s=k.useRef(new Set),o=se("should display selected ids",()=>{const l=s.current,c=new Set,u=r.getInstanceState(),h=u.isChangingStyle,p=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(h||!(p||m))return s.current=c,c;for(const S of r.getSelectedShapeIds())c.add(S);if(p&&u.isHoveringCanvas&&!u.isCoarsePointer){const S=r.getHoveredShapeId();S&&c.add(S)}if(l.size!==c.size)return s.current=c,c;for(const S of c)if(!l.has(S))return s.current=c,c;return l},[r]),i=se("rendering shapes",()=>r.getRenderingShapes(),[r]),{ShapeIndicator:a}=Ft();return a?i.map(({id:l})=>g.jsx(a,{shapeId:l,hidden:!t&&(e||!o.has(l))},l+"_indicator")):null});function yee({points:n,zoom:e}){const t=2.5/e,r=n.reduce((p,m)=>Math.min(p,m.x),1/0),s=n.reduce((p,m)=>Math.max(p,m.x),-1/0),o=n.reduce((p,m)=>Math.min(p,m.y),1/0),i=n.reduce((p,m)=>Math.max(p,m.y),-1/0),a=n.some(p=>p.x===r&&p.y===o);let l,c,u,h;return a?(l=r,c=o,u=s,h=i):(l=r,c=i,u=s,h=o),g.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[g.jsx("line",{x1:l,y1:c,x2:u,y2:h}),n.map((p,m)=>g.jsx("g",{transform:`translate(${p.x},${p.y})`,children:g.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},m))]})}function See({gaps:n,direction:e,zoom:t}){const r=3.5/t;let s=[-1/0,1/0],o=null;const i=e==="horizontal";for(const l of n){if(o=si(s[0],s[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),o)s=o;else continue;if(o=si(s[0],s[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),o)s=o;else continue}if(s===null)return null;const a=(s[0]+s[1])/2;return g.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:n.map(({startEdge:l,endEdge:c},u)=>g.jsx(k.Fragment,{children:i?g.jsxs(g.Fragment,{children:[g.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),g.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),g.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),g.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):g.jsxs(g.Fragment,{children:[g.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),g.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),g.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),g.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},u))})}function xee({className:n,line:e,zoom:t}){return g.jsx("svg",{className:$e("tl-overlays__item",n),children:e.type==="points"?g.jsx(yee,{...e,zoom:t}):e.type==="gaps"?g.jsx(See,{...e,zoom:t}):null})}function vee(){return g.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16","aria-hidden":"false",children:g.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[g.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),g.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:g.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const wee=()=>null;function b4(n,e){const t=k.useRef(n);return e(n,t.current)?t.current:(t.current=n,n)}const bee=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:ES(n,e));function $l(n){return b4(n,bee)}const Cee=(n,e)=>(n??(n=null),e??(e=null),n===e?!0:!n||!e?!1:Q3(n,e));function _h(n){return b4(n,Cee)}const C4=k.createContext(null);function Pee({overrides:n={},children:e}){const t=_h(n),r=k.useMemo(()=>({Background:QZ,Brush:DC,Canvas:zQ,CollaboratorBrush:DC,CollaboratorCursor:pj,CollaboratorHint:aee,CollaboratorScribble:gj,CollaboratorShapeIndicator:mj,Cursor:pj,Grid:lee,Handle:cee,Handles:uee,InFrontOfTheCanvas:null,LoadingScreen:dee,OnTheCanvas:null,Overlays:null,Scribble:gj,SelectionBackground:null,SelectionForeground:hee,ShapeIndicator:mj,ShapeIndicators:w4,SnapIndicator:xee,Spinner:vee,SvgDefs:wee,ZoomBrush:DC,ErrorFallback:k4,ShapeErrorFallback:fee,ShapeIndicatorErrorFallback:mee,...t}),[t]);return g.jsx(C4.Provider,{value:r,children:e})}function Ft(){const n=k.useContext(C4);if(!n)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return n}const C0={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 P4(){C0.hardReset()}function kee(){C0.refreshPage()}const Eee="https://github.com/tldraw/tldraw/issues/new",k4=({error:n,editor:e})=>{const t=k.useRef(null),[r,s]=k.useState(!1),[o,i]=k.useState(!1),[a,l]=k.useState(!1);let c=null;try{c=Ft().Canvas??null}catch{}const u=n instanceof Error?n.message:String(n),h=n instanceof Error?n.stack:null,p=se("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[m,S]=k.useState(null);k.useLayoutEffect(()=>{var _;p!==null&&S(p);let T=(_=t.current)==null?void 0:_.parentElement,E=!1;for(;T;){if(T.classList.contains("tl-theme__dark")||T.classList.contains("tl-theme__light")){E=!0;break}T=T.parentElement}if(E){S(null);return}typeof window<"u"&&"matchMedia"in window&&S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),k.useEffect(()=>{if(o){const T=e==null?void 0:e.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(T)}},[o,e]);const v=()=>{const T=document.createElement("textarea");T.value=h??u,document.body.appendChild(T),T.select(),document.execCommand("copy"),T.remove(),i(!0)},y=()=>{kee()},w=async()=>{P4()},C=new URL(Eee);return C.searchParams.set("title",u),C.searchParams.set("labels","bug"),C.searchParams.set("body",`Hey, I ran into an error while using tldraw:
102
+
103
+ \`\`\`js
104
+ ${h??u}
105
+ \`\`\`
106
+
107
+ My browser: ${navigator.userAgent}`),g.jsxs("div",{ref:t,className:$e("tl-container tl-error-boundary",m===null?"":m?"tl-theme__dark":"tl-theme__light"),children:[g.jsx("div",{className:"tl-error-boundary__overlay"}),e&&g.jsx(ZI,{onError:Ap,fallback:()=>null,children:g.jsx(eT,{editor:e,children:g.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?g.jsx(c,{}):null})})}),g.jsx("div",{className:$e("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?g.jsxs(g.Fragment,{children:[g.jsx("h2",{children:"Are you sure?"}),g.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),g.jsxs("div",{className:"tl-error-boundary__content__actions",children:[g.jsx("button",{className:"tlui-button",onClick:()=>l(!1),children:"Cancel"}),g.jsx("button",{className:"tlui-button tl-error-boundary__reset",onClick:w,children:"Reset data"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("h2",{children:"Something went wrong"}),g.jsx("p",{children:"Please refresh your browser."}),g.jsx("p",{children:"If the issue continues after refreshing, you may need to reset the tldraw data stored on your device."}),g.jsxs("p",{children:[g.jsx("strong",{children:"Note:"})," Resetting will erase your current project and any unsaved work."]}),!1,r&&g.jsxs(g.Fragment,{children:["Message:",g.jsx("h4",{children:g.jsx("code",{children:u})}),"Stack trace:",g.jsxs("div",{className:"tl-error-boundary__content__error",children:[g.jsx("pre",{children:g.jsx("code",{children:h??u})}),g.jsx("button",{className:"tlui-button",onClick:v,children:o?"Copied!":"Copy"})]})]}),g.jsxs("div",{className:"tl-error-boundary__content__actions",children:[g.jsx("button",{className:"tlui-button",onClick:()=>s(!r),children:r?"Hide details":"Show details"}),g.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[g.jsx("button",{className:"tlui-button tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),g.jsx("button",{className:"tlui-button tl-error-boundary__refresh",onClick:y,children:"Refresh Page"})]})]})]})})]})},E4="TLDRAW_USER_DATA_v3",I4=mt({id:it,name:it.nullable().optional(),color:it.nullable().optional(),locale:it.nullable().optional(),animationSpeed:Ze.nullable().optional(),edgeScrollSpeed:Ze.nullable().optional(),colorScheme:Th("light","dark","system").optional(),isSnapMode:St.nullable().optional(),isWrapMode:St.nullable().optional(),isDynamicSizeMode:St.nullable().optional(),isPasteAtCursorMode:St.nullable().optional()}),ka={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},cT=Math.max(...Object.values(ka));function Iee(n){n.version<ka.AddAnimationSpeed&&(n.user.animationSpeed=1),n.version<ka.AddIsSnapMode&&(n.user.isSnapMode=!1),n.version<ka.MakeFieldsNullable,n.version<ka.AddEdgeScrollSpeed&&(n.user.edgeScrollSpeed=1),n.version<ka.AddExcalidrawSelectMode&&(n.user.isWrapMode=!1),n.version<ka.AllowSystemColorScheme&&(n.user.isDarkMode===!0?n.user.colorScheme="dark":n.user.isDarkMode===!1&&(n.user.colorScheme="light"),delete n.user.isDarkMode),n.version<ka.AddDynamicSizeMode&&(n.user.isDynamicSizeMode=!1),n.version<ka.AddPasteAtCursor&&(n.user.isPasteAtCursorMode=!1),n.version=cT}const Lk=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function T4(){return Lk[Math.floor(Math.random()*Lk.length)]}function Tee(){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 Fi=Object.freeze({name:"",locale:VZ(),color:T4(),edgeScrollSpeed:1,animationSpeed:Tee()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"light"});function zC(){return{id:Mt(),color:T4()}}function _4(n){if(n===null||typeof n!="object"||!("version"in n)||!("user"in n)||typeof n.version!="number")return zC();const e=en(n);Iee(e);try{return I4.validate(e.user)}catch{return zC()}}function _ee(){const n=JSON.parse(gI(E4)||"null")??null;return _4(n)}const P0=hn("globalUserData",null);function Mee(){mI(E4,JSON.stringify({version:cT,user:P0.get()}))}function M4(n){I4.validate(n),P0.set(n),Mee(),Aee()}const qd=typeof BroadcastChannel<"u"?new BroadcastChannel("tldraw-user-sync"):null;qd==null||qd.addEventListener("message",n=>{const e=n.data;(e==null?void 0:e.type)===O4&&(e==null?void 0:e.origin)!==A4()&&P0.set(_4(e.data))});let BC=null;function A4(){return BC===null&&(BC=Mt()),BC}const O4="tldraw-user-preferences-change";function Aee(){qd==null||qd.postMessage({type:O4,origin:A4(),data:{user:R4(),version:cT}})}function R4(){let n=P0.get();return n||(n=_ee(),M4(n)),n}const Oee=le("defaultLocalStorageUserPrefs",()=>R4());function D4(n={}){return{userPreferences:n.userPreferences??Oee,setUserPreferences:n.setUserPreferences??M4}}var $C={exports:{}},yj;function Ree(){return yj||(yj=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,u){this.fn=l,this.context=c,this.once=u||!1}function o(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var m=new s(u,h||l,p),S=t?t+c:c;return l._events[S]?l._events[S].fn?l._events[S]=[l._events[S],m]:l._events[S].push(m):(l._events[S]=m,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,h;if(this._eventsCount===0)return c;for(h in u=this._events)e.call(u,h)&&c.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=t?t+c:c,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,m=h.length,S=new Array(m);p<m;p++)S[p]=h[p].fn;return S},a.prototype.listenerCount=function(c){var u=t?t+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,p,m,S){var v=t?t+c:c;if(!this._events[v])return!1;var y=this._events[v],w=arguments.length,C,T;if(y.fn){switch(y.once&&this.removeListener(c,y.fn,void 0,!0),w){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,u),!0;case 3:return y.fn.call(y.context,u,h),!0;case 4:return y.fn.call(y.context,u,h,p),!0;case 5:return y.fn.call(y.context,u,h,p,m),!0;case 6:return y.fn.call(y.context,u,h,p,m,S),!0}for(T=1,C=new Array(w-1);T<w;T++)C[T-1]=arguments[T];y.fn.apply(y.context,C)}else{var E=y.length,_;for(T=0;T<E;T++)switch(y[T].once&&this.removeListener(c,y[T].fn,void 0,!0),w){case 1:y[T].fn.call(y[T].context);break;case 2:y[T].fn.call(y[T].context,u);break;case 3:y[T].fn.call(y[T].context,u,h);break;case 4:y[T].fn.call(y[T].context,u,h,p);break;default:if(!C)for(_=1,C=new Array(w-1);_<w;_++)C[_-1]=arguments[_];y[T].fn.apply(y[T].context,C)}}return!0},a.prototype.on=function(c,u,h){return o(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return o(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,p){var m=t?t+c:c;if(!this._events[m])return this;if(!u)return i(this,m),this;var S=this._events[m];if(S.fn)S.fn===u&&(!p||S.once)&&(!h||S.context===h)&&i(this,m);else{for(var v=0,y=[],w=S.length;v<w;v++)(S[v].fn!==u||p&&!S[v].once||h&&S[v].context!==h)&&y.push(S[v]);y.length?this._events[m]=y.length===1?y[0]:y:i(this,m)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=t?t+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,n.exports=a}($C)),$C.exports}var Dee=Ree();const jee=Za(Dee),Yd="TLDRAW_TAB_ID_v2",La=globalThis.window;function Lee(){return La?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(La.navigator.platform)||Tt.isDarwin&&"ontouchend"in document:!1}const GS=La?La[Yd]??hF(Yd)??"TLDRAW_INSTANCE_STATE_V1_"+Mt():"<error>";La&&(La[Yd]=GS,Lee()?yI(Yd,GS):fF(Yd));La==null||La.addEventListener("beforeunload",()=>{yI(Yd,GS)});const j4={Initial:0},k0=Math.max(...Object.values(j4));function Nee(n){n.version<j4.Initial,n.version=k0}const L4=mt({version:Ze,currentPageId:Lp.optional(),isFocusMode:St.optional(),exportBackground:St.optional(),isDebugMode:St.optional(),isToolLocked:St.optional(),isGridMode:St.optional(),pageStates:Gn(mt({pageId:Lp,camera:mt({x:Ze,y:Ze,z:Ze}).optional(),selectedShapeIds:Gn(Eo).optional(),focusedGroupId:Eo.nullable().optional()})).optional()});function Fee(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!==k0&&(n=en(n),Nee(n));try{return L4.validate(n)}catch(e){return console.warn(e),null}}function uT(n){const e=n.query.ids("page");return le("sessionStateSnapshot",()=>{const t=n.get(Yr);if(!t)return null;const r=[...e.get()];return{version:k0,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(s=>{const o=n.get(ci.createId(s)),i=n.get(Vi.createId(s));return{pageId:s,camera:{x:(i==null?void 0:i.x)??0,y:(i==null?void 0:i.y)??0,z:(i==null?void 0:i.z)??1},selectedShapeIds:(o==null?void 0:o.selectedShapeIds)??[],focusedGroupId:(o==null?void 0:o.focusedGroupId)??null}})}},{isEqual:Ih})}function Nk(n,e,t){const r=Fee(e);if(!r)return;const s=C5(n.get(Yr)),o=t!=null&&t.forceOverwrite?r:s,i=t!=null&&t.forceOverwrite?s:r,a=n.schema.types.instance.create({id:Yr,...s,currentPageId:r.currentPageId,isDebugMode:(o==null?void 0:o.isDebugMode)??(i==null?void 0:i.isDebugMode),isFocusMode:(o==null?void 0:o.isFocusMode)??(i==null?void 0:i.isFocusMode),isToolLocked:(o==null?void 0:o.isToolLocked)??(i==null?void 0:i.isToolLocked),isGridMode:(o==null?void 0:o.isGridMode)??(i==null?void 0:i.isGridMode),exportBackground:(o==null?void 0:o.exportBackground)??(i==null?void 0:i.exportBackground)});n.atomic(()=>{var l,c,u;for(const h of r.pageStates??[]){if(!n.has(h.pageId))continue;const p=Vi.createId(h.pageId),m=ci.createId(h.pageId),S=n.get(p),v=n.get(m);n.put([Vi.create({id:p,x:((l=h.camera)==null?void 0:l.x)??(S==null?void 0:S.x),y:((c=h.camera)==null?void 0:c.y)??(S==null?void 0:S.y),z:((u=h.camera)==null?void 0:u.z)??(S==null?void 0:S.z)}),ci.create({id:m,pageId:h.pageId,selectedShapeIds:h.selectedShapeIds??(v==null?void 0:v.selectedShapeIds),focusedGroupId:h.focusedGroupId??(v==null?void 0:v.focusedGroupId)})])}n.put([a]),n.ensureStoreIsUsable()})}function zee(n){var s;const e=[];for(const o of Object.values(n))(s=o.typeName)!=null&&s.match(/^(instance.*|pointer|camera)$/)&&e.push(o);const t=e.filter(o=>o.typeName==="instance"&&o.id!==Yr)[0];if(!t)return null;const r={version:k0,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:e.filter(o=>o.typeName==="instance_page_state"&&o.instanceId===t.id).map(o=>{const i=n[o.cameraId]??{x:0,y:0,z:1};return{pageId:o.pageId,camera:{x:i.x,y:i.y,z:i.z},selectedShapeIds:o.selectedShapeIds,focusedGroupId:o.focusedGroupId}})};try{return L4.validate(r),r}catch{return null}}function N4(n,e,t){let r={};if("store"in e){const i=n.schema.migrateStoreSnapshot(e);if(i.type!=="success")throw new Error("Failed to migrate store snapshot: "+i.reason);r.document={schema:n.schema.serialize(),store:dp(i.value,(a,{typeName:l})=>n.scopedTypes.document.has(l))}}else r=e;const s=C5(n.get(Yr)),o=F4.get(n,uT).get();n.atomic(()=>{r.document&&n.loadStoreSnapshot(r.document),s&&n.update(Yr,i=>({...i,...s})),o&&Nk(n,o),r.session&&Nk(n,r.session,{forceOverwrite:t==null?void 0:t.forceOverwriteSessionState})})}const F4=new zo;function Bee(n){const t=F4.get(n,uT).get();if(!t)throw new Error("Session state is not ready yet");return{document:n.getStoreSnapshot(),session:t}}function z4(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 rc({children:n,className:e="",...t}){return g.jsx("svg",{...t,className:$e("tl-svg-container",e),children:n})}class Ra extends nl{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:o,u:i,ul:a}=this;if(o.len()===0||a===0)return r;const l=P.Sub(t,r).dpr(i)/a,c=r.x+i.x*l;if(c<Math.min(r.x,s.x))return r.x<s.x?r:s;if(c>Math.max(r.x,s.x))return r.x>s.x?r:s;const u=r.y+i.y*l;return u<Math.min(r.y,s.y)?r.y<s.y?r:s:u>Math.max(r.y,s.y)?r.y>s.y?r:s:new P(c,u)}hitTestLineSegment(t,r,s=0){return oT(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 fc extends nl{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 o=t[r],i=t[r+1];this._segments.push(new Ra({start:o,end:i}))}this.isClosed&&this._segments.push(new Ra({start:t[t.length-1],end:t[0]}))}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){return this.points}nearestPoint(t){const{segments:r}=this;let s=this.points[0],o=1/0,i,a;for(let l=0;l<r.length;l++)i=r[l].nearestPoint(t),a=P.Dist2(i,t),a<o&&(s=i,o=a);if(!s)throw Error("nearest point not found");return s}hitTestLineSegment(t,r,s=0){const{segments:o}=this;for(let i=0,a=o.length;i<a;i++)if(o[i].hitTestLineSegment(t,r,s))return!0;return!1}getSvgPathData(){const{vertices:t}=this;return t.length<2?"":t.reduce((r,s,o)=>o===0?`M ${s.x} ${s.y}`:`${r} L ${s.x} ${s.y}`,"")}}class Pn extends fc{constructor(e){super({...e}),this.isClosed=!0}}class Zi extends Pn{constructor(t){const{x:r=0,y:s=0,width:o,height:i}=t;super({...t,points:[new P(r,s),new P(r+o,s),new P(r+o,s+i),new P(r,s+i)]});R(this,"x");R(this,"y");R(this,"w");R(this,"h");this.x=r,this.y=s,this.w=o,this.h=i}getBounds(){return new ye(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:s,h:o}=this;return`M${t},${r} h${s} v${o} h-${s}z`}}class fi{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 jr}canSnap(e){return!0}canTabTo(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){}getAriaDescriptor(e){}}R(fi,"props"),R(fi,"migrations"),R(fi,"type");function oi(n,e,t={}){const{closed:r=!1,snap:s=1,start:o="outset",end:i="outset",lengthRatio:a=2,style:l="dashed",forceSolid:c=!1}=t;let u=0,h=0,p=1,m=0,S=0;if(c)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(l){case"dashed":{p=1,u=Math.min(e*a,n/4);break}case"dotted":{p=100,u=e/p;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(o==="outset"?(n+=u/2,S+=u/2):o==="skip"&&(n-=u,S-=u),i==="outset"?n+=u/2:i==="skip"&&(n-=u)),h=Math.floor(n/u/(2*p)),h-=h%s,h<3&&l==="dashed"?n/e<4?(u=n,h=1,m=0):(u=n*(1/3),m=n*(1/3)):(u=n/h/(2*p),r?(S=u/2,m=(n-h*u)/h):m=(n-h*u)/Math.max(1,h-1)),{strokeDasharray:[u,m].join(" "),strokeDashoffset:S.toString()}}function Sj({bounds:n,className:e}){const t=ne(),r=se("zoom level",()=>t.getZoomLevel(),[t]);return g.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:n.sides.map((s,o)=>{const{strokeDasharray:i,strokeDashoffset:a}=oi(s[0].dist(s[1]),1/r,{style:"dashed",lengthRatio:4});return g.jsx("line",{x1:s[0].x,y1:s[0].y,x2:s[1].x,y2:s[1].y,strokeDasharray:i,strokeDashoffset:a},o)})})}class Yy extends fi{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const t=this.editor.getSortedChildIdsForParent(e.id);return t.length===0?new Zi({width:1,height:1,isFilled:!1}):new ds({children:t.map(r=>{const s=this.editor.getShape(r);return this.editor.getShapeGeometry(r).transform(this.editor.getShapeLocalTransform(s),{isLabel:!1})})})}component(e){const t=this.editor.getErasingShapeIds().includes(e.id),{hintingShapeIds:r}=this.editor.getCurrentPageState(),s=r.length>0&&r.some(a=>a!==e.id&&this.editor.isShapeOfType(this.editor.getShape(a),"group")),o=this.editor.getCurrentPageState().focusedGroupId!==e.id;if(!t&&(o||s))return null;const i=this.editor.getShapeGeometry(e).bounds;return g.jsx(rc,{children:g.jsx(Sj,{className:"tl-group",bounds:i})})}indicator(e){const t=this.editor.getShapeGeometry(e).bounds;return g.jsx(Sj,{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(Yy,"type","group"),R(Yy,"props",j5),R(Yy,"migrations",L5);const B4=[Yy],$ee=new Set(B4.map(n=>n.type));function $4(n){const e=[...B4],t=new Set;for(const r of n){if($ee.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 Mh=$3();const Uee=Za(Mh);function U4(n,e){const t=new Map;return async function(s){const o=t.get(s);if(o)return o;const i=(async()=>{try{const a=await di(s,e);return Ve(a.ok),await n(a)}catch(a){return console.error(a),null}})();return t.set(s,i),i}}const E0=U4(async n=>await Jr.blobToDataUrl(await n.blob())),Hee=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,Kee=/@font-face\s*{([^}]+)}/gi,H4=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,Wee=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function Vee(n){return Array.from(n.matchAll(Hee),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function K4(n,e){return Array.from(n.matchAll(Kee),t=>{const r=t[1],s=Array.from(r.matchAll(H4),i=>{var l;const a=i[1]||i[2]||i[3];return{original:a,resolved:((l=Qe(a,e))==null?void 0:l.href)??null}}),o=new Set(Array.from(r.matchAll(Wee),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:s,fontFamilies:o}})}function Gee(n){const e=/\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi,t=/\s*,\s*/gi,r=new Set;for(;;){const s=e.exec(n);if(!s)break;const o=s[1]||s[2]||s[3];if(r.add(o.toLowerCase()),t.lastIndex=e.lastIndex,!t.exec(n))break;e.lastIndex=t.lastIndex}return r}function W4(n){return!(n.startsWith("-")||n.startsWith("animation")||n.startsWith("transition")||n==="cursor"||n==="pointer-events"||n==="user-select"||n==="touch-action")}function qee(n,e){return{imports:Vee(n),fontFaces:K4(n,e)}}function Yee(n){return Array.from(n.matchAll(H4),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}var Xee=Object.create,V4=Object.defineProperty,Zee=Object.getOwnPropertyDescriptor,Jee=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),G4=n=>{throw TypeError(n)},q4=(n,e,t)=>e in n?V4(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Qee=n=>[,,,Xee(null)],Y4=["class","method","getter","setter","accessor","field","value","get","set"],X4=n=>n!==void 0&&typeof n!="function"?G4("Function expected"):n,ete=(n,e,t,r,s)=>({kind:Y4[n],name:e,metadata:r,addInitializer:o=>t._?G4("Already initialized"):s.push(X4(o||null))}),tte=(n,e)=>q4(e,Jee("metadata"),n[3]),nte=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},rte=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=Y4[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,Zee(s,t)),w=r.length-1;w>=0;w--)l=ete(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,X4(i)&&(y[S]=i);return y&&V4(s,t,y),s},ry=(n,e,t)=>q4(n,typeof e!="symbol"?e+"":e,t),Z4,I0;const J4="tldraw-svg-export";Z4=[Rs];class dT{constructor(){nte(I0,5,this),ry(this,"fontFacesPromise",null),ry(this,"foundFontNames",new Set),ry(this,"fontFacesToEmbed",new Set),ry(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Ve(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=ste()}onFontFamilyValue(e){Ve(this.fontFacesPromise,"FontEmbedder not started");const t=Gee(e);for(const r of t){if(this.foundFontNames.has(r))return;this.foundFontNames.add(r),this.pendingPromises.push(this.fontFacesPromise.then(s=>{const o=s.filter(i=>i.fontFamilies.has(r));for(const i of o)if(!this.fontFacesToEmbed.has(i)){this.fontFacesToEmbed.add(i);for(const a of i.urls)!a.resolved||a.embedded||(a.embedded=E0(a.resolved))}}))}}async createCss(){await Promise.all(this.pendingPromises);let e="";for(const t of this.fontFacesToEmbed){let r=`@font-face {${t.fontFace}}`;for(const s of t.urls){if(!s.embedded)continue;const o=await s.embedded;o&&(r=r.replace(s.original,o))}e+=r}return e}}I0=Qee();rte(I0,1,"onFontFamilyValue",Z4,dT);tte(I0,dT);async function ste(){var t;const n=[],e=Array.from(document.styleSheets).filter(r=>{var s;return!((s=r.ownerNode)!=null&&s.closest(`.${J4}`))});for(const r of e){let s;try{s=r.cssRules}catch{}if(s){for(const o of r.cssRules)if(o instanceof CSSFontFaceRule)n.push(K4(o.cssText,r.href??document.baseURI));else if(o instanceof CSSImportRule){const i=new URL(o.href,((t=o.parentStyleSheet)==null?void 0:t.href)??document.baseURI);n.push(Fk(i.href))}}else r.href&&n.push(Fk(r.href))}return st(await Promise.all(n)).flat()}const Fk=U4(async n=>{const e=qee(await n.text(),n.url),t=await Promise.all(e.imports.map(({url:r})=>Fk(new URL(r,n.url).href)));return[...e.fontFaces,...st(t).flat()]}),Gs=(n,e,{currentColor:t})=>n==="currentColor"||n===t,ft=(n,e,{parentStyles:t})=>t[e]===n,dn=n=>(e,t,{getStyle:r})=>{const s=r(`border-${n}-width`),o=r(`border-${n}-style`);return s==="0px"||o==="none"},Q4={"border-block-end-color":Gs,"border-block-start-color":Gs,"border-bottom-color":Gs,"border-inline-end-color":Gs,"border-inline-start-color":Gs,"border-left-color":Gs,"border-right-color":Gs,"border-top-color":Gs,"caret-color":Gs,"column-rule-color":Gs,"outline-color":Gs,"text-decoration":(n,e,{currentColor:t})=>n==="none solid currentColor"||n==="none solid "+t,"text-decoration-color":Gs,"text-emphasis-color":Gs,"border-collapse":ft,"border-spacing":ft,"caption-side":ft,cursor:ft,direction:ft,"empty-cells":ft,"font-family":ft,"font-size":ft,"font-style":ft,"font-variant":ft,"font-weight":ft,"font-size-adjust":ft,"font-stretch":ft,font:ft,"letter-spacing":ft,"line-height":ft,"list-style-image":ft,"list-style-position":ft,"list-style-type":ft,"list-style":ft,orphans:ft,"overflow-wrap":ft,quotes:ft,"stroke-linecap":ft,"stroke-linejoin":ft,"tab-size":ft,"text-align":ft,"text-align-last":ft,"text-indent":ft,"text-justify":ft,"text-shadow":ft,"text-transform":ft,visibility:ft,"white-space":ft,"white-space-collapse":ft,widows:ft,"word-break":ft,"word-spacing":ft,"word-wrap":ft,"border-top":dn("top"),"border-right":dn("right"),"border-bottom":dn("bottom"),"border-left":dn("left"),"border-block-end":dn("block-end"),"border-block-start":dn("block-start"),"border-inline-end":dn("inline-end"),"border-inline-start":dn("inline-start"),"border-top-style":dn("top"),"border-right-style":dn("right"),"border-bottom-style":dn("bottom"),"border-left-style":dn("left"),"border-block-end-style":dn("block-end"),"border-block-start-style":dn("block-start"),"border-inline-end-style":dn("inline-end"),"border-inline-start-style":dn("inline-start"),"border-top-width":dn("top"),"border-right-width":dn("right"),"border-bottom-width":dn("bottom"),"border-left-width":dn("left"),"border-block-end-width":dn("block-end"),"border-block-start-width":dn("block-start"),"border-inline-end-width":dn("inline-end")};function ez(n){if(n.shadowRoot)return n.shadowRoot.childNodes;if(lte(n)){const e=n.assignedNodes();if(e!=null&&e.length)return e}return n.childNodes}function*zk(n){for(const e of ez(n))ote(e)&&(yield e)}function T0(n){var e;return((e=n.ownerDocument)==null?void 0:e.defaultView)??globalThis}function ote(n){return n instanceof T0(n).Element}function ite(n){return n instanceof T0(n).ShadowRoot}function ate(n){return"getRootNode"in n&&ite(n.getRootNode())}function lte(n){return ate(n)&&n instanceof T0(n).HTMLSlotElement}function cte(n){return n.style}function hT(n,e){return T0(n).getComputedStyle(n,e)}const ch={};class ute{constructor(e){R(this,"styles",new Map);R(this,"fonts",new dT);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const t=Array.from(zk(e));for(;t.length;){const r=t.pop();t.push(...zk(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:t=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const s=t?pte(e.tagName.toLowerCase()):ch,o=Object.assign({},ch);if(r){let l=e.parentElement;for(;l;){const c=(a=this.styles.get(l))==null?void 0:a.self;for(const u in c)o[u]||(o[u]=c[u]);l=l.parentElement}}const i={self:dte(e,{defaultStyles:s,parentStyles:o}),before:xj(e,"::before"),after:xj(e,"::after")};this.styles.set(e,i)}fetchResources(){const e=[];for(const t of this.styles.values())for(const r of Sn(t))if(r)for(const[s,o]of Object.entries(r)){if(!o)continue;s==="font-family"&&this.fonts.onFontFamilyValue(o);const i=Yee(o);i.length!==0&&e.push(...i.map(async({url:a,original:l})=>{const c=await E0(a)??"data:";r[s]=o.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 o=r.shadowRoot;if(o){const i=document.createElement("div");this.styles.set(i,this.styles.get(r)),i.setAttribute("data-tl-custom-element",r.tagName),(s??r.parentElement).appendChild(i);for(const a of o.childNodes)a instanceof Element?t(a,i):i.appendChild(a.cloneNode(!0));r.remove()}else if(s){if(r.tagName.toLowerCase()==="style")return;const i=r.cloneNode(!1);this.styles.set(i,this.styles.get(r)),s.appendChild(i);for(const a of ez(r))a instanceof Element?t(a,i):i.appendChild(a.cloneNode(!0))}};for(const r of this.styles.keys())t(r,null)}embedStyles(){let e="";for(const[t,r]of this.styles){if(r.after||r.before){const o=`pseudo-${Mt()}`;t.classList.add(o),r.before&&(e+=`.${o}::before {${vj(r.before)}}
108
+ `),r.after&&(e+=`.${o}::after {${vj(r.after)}}
109
+ `)}const s=cte(t);for(const[o,i]of Object.entries(r.self))i&&s.setProperty(o,i);s.fontKerning==="auto"&&(s.fontKerning="normal")}return e}async getFontFaceCss(){return await this.fonts.createCss()}dispose(){fte()}}function dte(n,{defaultStyles:e,parentStyles:t}){return n.computedStyleMap?tz(n.computedStyleMap(),{defaultStyles:e,parentStyles:t}):fT(hT(n),{defaultStyles:e,parentStyles:t})}function xj(n,e){const t=hT(n,e),r=t.getPropertyValue("content");if(!(r===""||r==="none"))return fT(t,{defaultStyles:ch,parentStyles:ch})}function tz(n,{defaultStyles:e,parentStyles:t}){var i;const r={},o={currentColor:((i=n.get("color"))==null?void 0:i.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(!W4(a))continue;const l=n.get(a).toString();if(e[a]===l)continue;const c=kn(Q4,a);c&&c(l,a,o)||(r[a]=l)}return r}function fT(n,{defaultStyles:e,parentStyles:t}){const r={},o={currentColor:n.color,parentStyles:t,defaultStyles:e,getStyle:i=>n.getPropertyValue(i)};for(const i in n){if(!W4(i))continue;const a=n.getPropertyValue(i);if(e[i]===a)continue;const l=kn(Q4,i);l&&l(a,i,o)||(r[i]=a)}return r}function vj(n){let e="";for(const[t,r]of Object.entries(n))e+=`${t}: ${r};`;return e}let Xd;const wj={};function hte(){if(!Xd){const n=document.createElement("iframe");n.style.display="none",document.body.appendChild(n);const e=qr(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),Xd={iframe:n,foreignObject:r,document:e}}return Xd}function fte(){Xd&&(document.body.removeChild(Xd.iframe),Xd=void 0)}const bj={defaultStyles:ch,parentStyles:ch};function pte(n){let e=wj[n];if(!e){const{foreignObject:t,document:r}=hte(),s=r.createElement(n);t.appendChild(s),e=s.computedStyleMap?tz(s.computedStyleMap(),bj):fT(hT(s),bj),t.removeChild(s),wj[n]=e}return e}function gte(n,e){Array.from(n.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function Cj(n,e){return n.replaceWith(e),e}async function pp(n,e){const t=document.createElement("img");e&&gte(e,t),t.setAttribute("src",n??"data:"),t.setAttribute("decoding","sync"),t.setAttribute("loading","eager");try{await t.decode()}catch{}return t}async function mte(n){try{const e=n.toDataURL();return await pp(e,n)}catch{return await pp(null,n)}}async function yte(n){try{const e=await Zs.getVideoFrameAsDataUrl(n);return pp(e,n)}catch(e){console.error("Could not get video frame",e)}if(n.poster){const e=await E0(n.poster);return pp(e,n)}return pp(null,n)}async function nz(n){if(n instanceof HTMLCanvasElement)return Cj(n,await mte(n));if(n instanceof HTMLVideoElement)return Cj(n,await yte(n));if(n instanceof HTMLImageElement){const e=n.currentSrc||n.src,t=await E0(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(zk(n),e=>nz(e)))}function Oa(n){const e=k.useRef();return k.useLayoutEffect(()=>{e.current=n}),k.useDebugValue(n),k.useCallback((...t)=>{const r=e.current;return Ve(r,"fn does not exist"),r(...t)},[])}const pT=k.createContext(null);function Ste({context:n,editor:e,children:t}){const r=e.options.exportProvider;return g.jsx(eT,{editor:e,children:g.jsx(n4,{container:e.getContainer(),children:g.jsx(pT.Provider,{value:n,children:g.jsx(r,{children:t})})})})}function Cg(){return k.useContext(pT)}function xte(){const n=k.useContext(pT),[e]=k.useState(lI);return k.useEffect(()=>(n==null||n.waitUntil(e),()=>{e.resolve()}),[e,n]),Oa(()=>{e.resolve()})}var vte=Object.create,rz=Object.defineProperty,wte=Object.getOwnPropertyDescriptor,bte=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),sz=n=>{throw TypeError(n)},oz=(n,e,t)=>e in n?rz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Cte=n=>[,,,vte(null)],iz=["class","method","getter","setter","accessor","field","value","get","set"],az=n=>n!==void 0&&typeof n!="function"?sz("Function expected"):n,Pte=(n,e,t,r,s)=>({kind:iz[n],name:e,metadata:r,addInitializer:o=>t._?sz("Already initialized"):s.push(az(o||null))}),kte=(n,e)=>oz(e,bte("metadata"),n[3]),Ete=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Ite=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=iz[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,wte(s,t)),w=r.length-1;w>=0;w--)l=Pte(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,az(i)&&(y[S]=i);return y&&rz(s,t,y),s},Pj=(n,e,t)=>oz(n,typeof e!="symbol"?e+"":e,t),lz,_0;lz=[Rs];class gT{constructor(e){this.maxDelayTimeMs=e,Ete(_0,5,this),Pj(this,"isResolved",!1),Pj(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 xk(0)}async resolve(){const e=xk(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}}_0=Cte();Ite(_0,1,"waitUntil",lz,gT);kte(_0,gT);function Tte(n,e,t={}){var w,C;if(!window.document)throw Error("No document");const{scale:r=1,background:s=n.getInstanceState().exportBackground,padding:o=n.options.defaultSvgPadding,preserveAspectRatio:i}=t,a=t.darkMode??n.user.getIsDarkMode(),l=n.getShapeAndDescendantIds(e),c=n.getUnorderedRenderingShapes(!1).filter(({id:T})=>l.has(T));let u=null;if(t.bounds)u=t.bounds;else for(const{id:T}of c){const E=n.getShapeMaskedPageBounds(T);E&&(u?u.union(E):u=E.clone())}if(!u)return;const h=e.length===1&&n.isShapeOfType(n.getShape(e[0]),"frame")?e[0]:null;h||u.expandBy(o);const p=u.width*r,m=u.height*r;try{(C=(w=document.body).focus)==null||C.call(w)}catch{}const S=new gT(n.options.maxExportDelayMs),v=lI();return S.waitUntil(v),{jsx:g.jsx(_te,{editor:n,preserveAspectRatio:i,scale:r,pixelRatio:t.pixelRatio??null,bbox:u,background:s,singleFrameShapeId:h,isDarkMode:a,renderingShapes:c,onMount:v.resolve,waitUntil:S.waitUntil}),width:p,height:m,exportDelay:S}}function _te({editor:n,preserveAspectRatio:e,scale:t,pixelRatio:r,bbox:s,background:o,singleFrameShapeId:i,isDarkMode:a,renderingShapes:l,onMount:c,waitUntil:u}){const h=Ou(),p=tl({isDarkMode:a}),m=gg("export state",{defsById:{},shapeElements:null}),{defsById:S,shapeElements:v}=se(m),y=Oa(E=>{m.update(_=>{if(Do(_.defsById,E.key))return _;const A=Promise.resolve(E.getElement());return u(A.then(O=>{m.update(D=>({...D,defsById:{...D.defsById,[E.key]:{pending:!1,element:O}}}))})),{..._,defsById:{..._.defsById,[E.key]:{pending:!0,element:A}}}})}),w=k.useMemo(()=>({isDarkMode:a,waitUntil:u,addExportDef:y,scale:t,pixelRatio:r,async resolveAssetUrl(E,_){const A=n.getAsset(E);return!A||A.type!=="image"&&A.type!=="video"?null:await n.resolveAssetUrl(E,{screenScale:t*(_/A.props.w),shouldResolveToOriginal:r===null,dpr:r??void 0})}}),[a,u,y,t,r,n]),C=k.useRef(!1);k.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:O,opacity:D,index:F,backgroundIndex:U})=>{var N,z;if(O===i)return[];const V=n.getShape(O);if(n.isShapeOfType(V,"group"))return[];const Y=[],j=n.getShapeUtil(V);if(j.toSvg||j.toBackgroundSvg){const[G,q]=await Promise.all([(N=j.toSvg)==null?void 0:N.call(j,V,w),(z=j.toBackgroundSvg)==null?void 0:z.call(j,V,w)]),$=n.getShapePageTransform(V);let K=$.toCssString(),J=1;"scale"in V.props&&V.props.scale!==1&&(J=V.props.scale,K=`${K} scale(${V.props.scale}, ${V.props.scale})`);const H=n.getShapeMask(V.id),te=H?de.From(de.Inverse($)).applyToPoints(H):null,he=JI(h,V.id);te&&(E[he]={pending:!1,element:g.jsx("clipPath",{id:he,children:g.jsx("path",{d:`M${te.map(({x:Pe,y:ue})=>`${Pe/J},${ue/J}`).join("L")}Z`})})}),G&&Y.push({zIndex:F,element:g.jsx("g",{transform:K,opacity:D,clipPath:H?`url(#${he})`:void 0,children:G},`fg_${V.id}`)}),q&&Y.push({zIndex:U,element:g.jsx("g",{transform:K,opacity:D,clipPath:H?`url(#${he})`:void 0,children:q},`bg_${V.id}`)})}else Y.push({zIndex:F,element:g.jsx(kj,{shape:V,util:j,component:x4,className:"tl-shape",bbox:s,opacity:D},`fg_${V.id}`)}),j.backgroundComponent&&Y.push({zIndex:U,element:g.jsx(kj,{shape:V,util:j,component:v4,className:"tl-shape tl-shape-background",bbox:s,opacity:D},`bg_${V.id}`)});return Y}),A=(await Promise.all(_)).flat();Mh.flushSync(()=>{m.update(O=>({...O,shapeElements:A.sort((D,F)=>D.zIndex-F.zIndex).map(({element:D})=>D),defsById:{...O.defsById,...E}}))})})()},[s,n,w,h,l,i,m]),k.useEffect(()=>{const E=new Set;for(const{id:_}of l)for(const A of n.fonts.getShapeFontFaces(_))E.add(A);for(const _ of E)y({key:Mt(),getElement:async()=>{const A=await n.fonts.toEmbeddedCssDeclaration(_);return g.jsx("style",{nonce:n.options.nonce,children:A})}})},[n,l,y]),k.useEffect(()=>{v!==null&&c()},[c,v]);let T=o?p.background:"transparent";if(i&&o){const E=n.getShapeUtil("frame");if(E!=null&&E.options.showColors){const _=n.getShape(i);T=p[_.props.color].frame.fill}else T=p.solid}return g.jsx(Ste,{editor:n,context:w,children:g.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:s.width*t,height:s.height*t,viewBox:`${s.minX} ${s.minY} ${s.width} ${s.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:T},"data-color-mode":a?"dark":"light",className:`tl-container tl-theme__force-sRGB ${a?"tl-theme__dark":"tl-theme__light"}`,children:[g.jsx("defs",{children:Object.entries(S).map(([E,_])=>_.pending?null:g.jsx(k.Fragment,{children:_.element},E))}),v]})})}function kj({shape:n,util:e,className:t,component:r,bbox:s,opacity:o}){const i=ne(),a=de.Translate(-s.minX,-s.minY).multiply(i.getShapePageTransform(n.id)),l=i.getShapeGeometry(n.id).bounds,c=Math.max(l.width,1),u=Math.max(l.height,1);return g.jsx(ZI,{fallback:()=>null,children:g.jsx("foreignObject",{x:s.minX,y:s.minY,width:s.w,height:s.h,className:"tl-shape-foreign-object tl-export-embed-styles",children:g.jsx("div",{className:t,"data-shape-type":n.type,style:{clipPath:i.getShapeClipPath(n.id),transform:a.toCssString(),width:c,height:u,opacity:o},children:g.jsx(r,{shape:n,util:e})})})})}let Mte=1;async function Ate(n,e,t={}){const r=Tte(n,e,t);if(!r)return;const s=n.getContainer(),o=document.createElement("div");o.className=J4,o.inert=!0,o.tabIndex=-1,Object.assign(o.style,{position:"absolute",top:"0px",left:"0px",width:r.width+"px",height:r.height+"px",pointerEvents:"none",opacity:0}),s.appendChild(o);const i=U3.createRoot(o,{identifierPrefix:`export_${Mte++}_`});try{await Promise.resolve(),Mh.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=o.firstElementChild;return Ve(a instanceof SVGSVGElement,"Expected an SVG element"),await Ote(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),s.removeChild(o)},0)}}async function Ote(n){const e=[...n.querySelectorAll("foreignObject.tl-export-embed-styles > *")];if(!e.length)return;const t=new ute(n);try{t.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(o=>nz(o)));for(const o of e)t.readRootElementStyles(o);await t.fetchResources();const r=await t.getFontFaceCss();t.unwrapCustomElements();const s=t.embedStyles();if(r||s){const o=document.createElementNS("http://www.w3.org/2000/svg","style");o.textContent=`${r}
110
+ ${s}`,n.prepend(o)}}finally{t.dispose()}}let UC=null;function Rte(){return UC||(UC={maxWidth:HC("width"),maxHeight:HC("height"),maxArea:HC("area")}),UC}/*!
111
+ * Extracted from https://github.com/jhildenbiddle/canvas-size
112
+ * MIT License: https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE
113
+ * Copyright (c) John Hildenbiddle
114
+ */const Ej=8192,Dte=4096*4096,jte={area:[16384,14188,11402,11180,10836,8192,4096],height:[8388607,65535,32767,16384,8192,4096],width:[4194303,65535,32767,16384,8192,4096]};function HC(n){const e=document.createElement("canvas");e.width=1,e.height=1;const t=e.getContext("2d");for(const r of jte[n]){const s=n==="height"?1:r,o=n==="width"?1:r,i=document.createElement("canvas");i.width=s,i.height=o,i.getContext("2d").fillRect(s-1,o-1,1,1),t.drawImage(i,s-1,o-1,1,1,0,0,1,1);const l=t.getImageData(0,0,1,1).data[3]!==0;if(i.width=0,i.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 Lte(n,e){if(n<=Ej&&e<=Ej&&n*e<=Dte)return[n,e];const{maxWidth:t,maxHeight:r,maxArea:s}=Rte(),o=n/e;if(n>t&&(n=t,e=n/o),e>r&&(e=r,n=e*o),n*e>s){const i=Math.sqrt(s/(n*e));n*=i,e*=i}return[n,e]}async function Nte(n,e){const{type:t,width:r,height:s,quality:o=1,pixelRatio:i=2}=e;let[a,l]=Lte(r*i,s*i);a=Math.floor(a),l=Math.floor(l);const c=a/r,u=await Jr.blobToDataUrl(new Blob([n],{type:"image/svg+xml"})),h=await new Promise(m=>{const S=Op();S.crossOrigin="anonymous",S.onload=async()=>{Tt.isSafari&&await xk(250);const v=document.createElement("canvas"),y=v.getContext("2d");v.width=a,v.height=l,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(S,0,0,a,l),URL.revokeObjectURL(u),m(v)},S.onerror=()=>{m(null)},S.src=u});if(!h)return null;const p=await new Promise(m=>h.toBlob(S=>{(!S||sn.throwToBlob.get())&&m(null),m(S)},"image/"+t,o));if(!p)return null;if(t==="png"){const m=new DataView(await p.arrayBuffer());return Hi.setPhysChunk(m,c,{type:"image/"+t})}else return p}const Xr={menus:hn("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()}}},qS=new _q,Fte={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:k.Fragment,enableToolbarKeyboardShortcuts:!0,maxFontsToLoadBeforeRender:1/0,nonce:void 0};function Ij(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 xt(n)}}class zte{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(!Ij(s,e.get(r)))return!1;t.add(r)}for(const[r,s]of e)if(!t.has(r)&&!Ij(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 Bk extends zte{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:xt(r,"type")}}}function Bte(n,e,t){return di(n).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:t})})}const $te="https://cdn.tldraw.com";function An(){return`${$te}/${Y5}`}function Ute(n){switch(n.type){case"shapes":return`s${n.shapeIds.map(t=>KC(t.slice(6))).join(".")}`;case"page":return"p"+KC(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+="."+KC(es.parseId(t))),r}default:xt(n)}}function Hte(n){switch(n[0]){case"s":return{type:"shapes",shapeIds:n.slice(1).split(".").filter(Boolean).map(r=>Nt(decodeURIComponent(r)))};case"p":return{type:"page",pageId:es.createId(decodeURIComponent(n.slice(1)))};case"v":{const[t,r,s,o,i]=n.slice(1).split(".");return{type:"viewport",bounds:new ye(Number(t),Number(r),Number(s),Number(o)),pageId:i?es.createId(decodeURIComponent(i)):void 0}}default:throw Error("Invalid deep link string")}}function KC(n){return encodeURIComponent(n).replace(/\./g,"%2E")}function Kte(n,e){var s;let t=n;const r=new Set(e);for(;r.has(t);)t=(s=/^.*(\d+)$/.exec(t))!=null&&s[1]?t.replace(/(\d+)(?=\D?)$/,o=>(+o+1).toString()):`${t} 1`;return t}function sy(n,e,t,r){if(t.length===0)return[];const s=new Map;for(const i of st(t.map(a=>n.getShape(a)))){const{parentId:a}=i;s.has(a)||s.set(a,{children:st(n.getSortedChildIdsForParent(a).map(l=>n.getShape(l))),moving:new Set}),s.get(a).moving.add(i)}const o=[];switch(e){case"toBack":{s.forEach(({moving:i,children:a})=>Wte(i,a,o));break}case"toFront":{s.forEach(({moving:i,children:a})=>Vte(i,a,o));break}case"forward":{s.forEach(({moving:i,children:a})=>Gte(n,i,a,o,r));break}case"backward":{s.forEach(({moving:i,children:a})=>qte(n,i,a,o,r));break}}return o}function Wte(n,e,t){const r=e.length;if(n.size===r)return;let s,o;for(let i=0;i<r;i++){const a=e[i];if(n.has(a))s=a.index,n.delete(a);else{o=a.index;break}}if(n.size!==0){const i=oh(s,o,n.size);t.push(...Array.from(n.values()).sort(ur).map((a,l)=>({...a,index:i[l]})))}}function Vte(n,e,t){const r=e.length;if(n.size===r)return;let s,o;for(let i=r-1;i>-1;i--){const a=e[i];if(n.has(a))o=a.index,n.delete(a);else{s=a.index;break}}if(n.size!==0){const i=oh(s,o,n.size);t.push(...Array.from(n.values()).sort(ur).map((a,l)=>({...a,index:i[l]})))}}function cz(n,e){const t=Array.from(e).map(s=>{const o=n.getShapePageGeometry(s).vertices;return o?{shape:s,vertices:o}:null}).filter(Boolean);return s=>{const o=n.getShapePageGeometry(s).vertices;return o?t.some(i=>iT(i.vertices,o)):!1}}function Gte(n,e,t,r,s){var l;const o=cz(n,e),i=t.length;if(e.size===i)return;let a={name:"skipping"};for(let c=0;c<i;c++){const u=e.has(t[c]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(u||!(s!=null&&s.considerAllShapes)&&!o(t[c]))continue;const{selectIndex:h}=a;oh(t[c].index,(l=t[c+1])==null?void 0:l.index,c-h).forEach((p,m)=>{const S=t[h+m];e.has(S)&&r.push({...S,index:p})}),a={name:"skipping"};break}}}}function qte(n,e,t,r,s){var l;const o=cz(n,e),i=t.length;if(e.size===i)return;let a={name:"skipping"};for(let c=i-1;c>-1;c--){const u=e.has(t[c]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(u||!(s!=null&&s.considerAllShapes)&&!o(t[c]))continue;oh((l=t[c-1])==null?void 0:l.index,t[c].index,a.selectIndex-c).forEach((h,p)=>{const m=t[c+p+1];e.has(m)&&r.push({...m,index:h})}),a={name:"skipping"};break}}}}function uz({editor:n,ids:e}){const t=st(e.map(i=>n.getShape(i))),r=n.getShapesSharedRotation(e),s=n.getShapesRotatedPageBounds(e);if(!s)return null;const o=s.center.clone().rotWith(s.point,r);return{initialPageCenter:o,initialCursorAngle:o.angle(n.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:t.map(i=>({shape:i,initialPagePoint:n.getShapePageTransform(i.id).point()}))}}function Xy({delta:n,editor:e,snapshot:t,stage:r,centerOverride:s}){const{initialPageCenter:o,shapeSnapshots:i}=t;e.updateShapes(i.map(({shape:l,initialPagePoint:c})=>{const u=Ts(l.parentId)?e.getShapePageTransform(l.parentId):de.Identity(),h=P.RotWith(c,s??o,n),p=de.applyToPoint(de.Inverse(u),h),m=ou(l.rotation+n);return{id:l.id,type:l.type,x:p.x,y:p.y,rotation:m}}));const a=[];i.forEach(({shape:l})=>{var p,m,S;const c=e.getShape(l.id);if(!c)return;const u=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const v=(p=u.onRotateStart)==null?void 0:p.call(u,l);v&&a.push(v)}const h=(m=u.onRotate)==null?void 0:m.call(u,l,c);if(h&&a.push(h),r==="end"||r==="one-off"){const v=(S=u.onRotateEnd)==null?void 0:S.call(u,l,c);v&&a.push(v)}}),a.length>0&&e.updateShapes(a)}const Yte=n=>{const{store:e}=n,t=e.query.filterHistory("binding"),r=e.query.records("binding");function s(){const o=r.get(),i=new Map;for(const a of o){const{fromId:l,toId:c}=a,u=i.get(l);u?u.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return le("arrowBindingsIndex",(o,i)=>{if(ru(o))return s();const a=o,l=t.getDiffSince(i);if(l===eo)return s();let c;function u(m){c??(c=new Map(a));const S=c.get(m.fromId),v=S==null?void 0:S.filter(C=>C.id!==m.id);v!=null&&v.length?c.set(m.fromId,v):c.delete(m.fromId);const y=c.get(m.toId),w=y==null?void 0:y.filter(C=>C.id!==m.id);w!=null&&w.length?c.set(m.toId,w):c.delete(m.toId)}function h(m){c??(c=new Map(a));let S=c.get(m);return S?S===a.get(m)&&(S=S.slice(0),c.set(m,S)):(S=[],c.set(m,S)),S}function p(m){h(m.fromId).push(m),h(m.toId).push(m)}for(const m of l){for(const S of Sn(m.added))p(S);for(const[S,v]of Sn(m.updated))u(S),p(v);for(const S of Sn(m.removed))u(S)}return c??a})};function Xte(n,e,t){const r=n.getShapeMaskedPageBounds(e);return r===void 0?!0:!t.includes(r)}const Zte=n=>{function e(t){const r=t.getCurrentPageShapeIds(),s=t.getViewportPageBounds(),o=new Set;return r.forEach(i=>{Xte(t,i,s)&&o.add(i)}),o}return le("notVisibleShapes",t=>{if(ru(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})},Jte=n=>{const e=n.query.ids("shape"),t=n.query.filterHistory("shape");function r(){const s={},o=e.get(),i=Array(o.size);return o.forEach(a=>i.push(n.get(a))),i.sort(ur),i.forEach(a=>{s[a.parentId]||(s[a.parentId]=[]),s[a.parentId].push(a.id)}),s}return le("parentsToChildrenWithIndexes",(s,o)=>{if(ru(s))return r();const i=t.getDiffSince(o);if(i===eo)return r();if(i.length===0)return s;let a=null;const l=h=>{a||(a={...s}),a[h]?a[h]===s[h]&&(a[h]=[...a[h]]):a[h]=[]},c=new Set;let u;for(let h=0,p=i.length;h<p;h++){u=i[h];for(const m of Object.values(u.added))$d(m)&&(l(m.parentId),a[m.parentId].push(m.id),c.add(a[m.parentId]));for(const[m,S]of Object.values(u.updated))if($d(S)&&$d(m)){if(m.parentId!==S.parentId)l(m.parentId),l(S.parentId),a[m.parentId].splice(a[m.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),c.add(a[S.parentId]);else if(m.index!==S.index){l(S.parentId);const v=a[S.parentId].indexOf(S.id);a[S.parentId][v]=S.id,c.add(a[S.parentId])}}for(const m of Object.values(u.removed))$d(m)&&(l(m.parentId),a[m.parentId].splice(a[m.parentId].indexOf(m.id),1))}for(const h of c){const p=st(h.map(m=>n.get(m)));p.sort(ur),h.splice(0,h.length,...p.map(m=>m.id))}return a??s})},WC=(n,e,t)=>{for(;!Tr(t.parentId);){const r=n.get(t.parentId);if(!r)return!1;t=r}return t.parentId===e},Qte=(n,e)=>{const t=n.query.ids("shape");let r=null;function s(){const o=e();return r=o,new Set([...t.get()].filter(i=>WC(n,o,n.get(i))))}return le("_shapeIdsInCurrentPage",(o,i)=>{if(ru(o))return s();const a=e();if(a!==r)return s();const l=n.history.getDiffSince(i);if(l===eo)return s();const c=new Ky(o);for(const h of l){for(const p of Object.values(h.added))$d(p)&&WC(n,a,p)&&c.add(p.id);for(const[p,m]of Object.values(h.updated))$d(m)&&(WC(n,a,m)?c.add(m.id):c.remove(m.id));for(const p of Object.keys(h.removed))Ts(p)&&c.remove(p)}const u=c.get();return u?Uf(u.value,u.diff):o})};var ene=Object.create,dz=Object.defineProperty,tne=Object.getOwnPropertyDescriptor,nne=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),hz=n=>{throw TypeError(n)},fz=(n,e,t)=>e in n?dz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,rne=n=>[,,,ene(null)],pz=["class","method","getter","setter","accessor","field","value","get","set"],gz=n=>n!==void 0&&typeof n!="function"?hz("Function expected"):n,sne=(n,e,t,r,s)=>({kind:pz[n],name:e,metadata:r,addInitializer:o=>t._?hz("Already initialized"):s.push(gz(o||null))}),one=(n,e)=>fz(e,nne("metadata"),n[3]),ine=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},mz=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=pz[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,tne(s,t)),w=r.length-1;w>=0;w--)l=sne(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,gz(i)&&(y[S]=i);return y&&dz(s,t,y),s},Cd=(n,e,t)=>fz(n,typeof e!="symbol"?e+"":e,t),yz,Sz,Pg;const ane=40;Sz=[Rs],yz=[Rs];class M0{constructor(e){this.editor=e,ine(Pg,5,this),Cd(this,"_clickId",""),Cd(this,"_clickTimeout"),Cd(this,"_clickScreenPoint"),Cd(this,"_previousScreenPoint"),Cd(this,"_clickState","idle"),Cd(this,"lastPointerInfo",{})}_getClickTimeout(e,t=Mt()){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=P.From(e.point),this._previousScreenPoint&&P.Dist2(this._previousScreenPoint,this._clickScreenPoint)>ane**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=P.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&&P.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"}}Pg=rne();mz(Pg,1,"_getClickTimeout",Sz,M0);mz(Pg,1,"cancelDoubleClickTimeout",yz,M0);one(Pg,M0);class lne{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?qn.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*s,y:r.y*s})}}getEdgeProximityFactors(e,t,r,s,o){const{editor:i}=this,a=i.options.edgeScrollDistance,l=r?i.options.coarsePointerWidth:0,c=e-l,u=e+l,h=s?0:a,p=o?t:t-a;return c<h?Math.min(1,(h-c)/a):u>p?-Math.min(1,(u-p)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=e,s=e.getViewportScreenBounds(),{isCoarsePointer:o,insets:[i,a,l,c]}=e.getInstanceState(),u=this.getEdgeProximityFactors(t,s.w,o,c,a),h=this.getEdgeProximityFactors(r,s.h,o,i,l);return{x:u,y:h}}moveCameraWhenCloseToEdge(e){const{editor:t}=this;if(!t.inputs.isDragging||t.inputs.isPanning||t.getCameraOptions().isLocked||e.x===0&&e.y===0)return;const r=t.getViewportScreenBounds(),s=r.w<1e3?.612:1,o=r.h<1e3?.612:1,i=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,l=a*e.x*s/i,c=a*e.y*o/i,{x:u,y:h,z:p}=t.getCamera();t.setCamera(new P(u+l,h+c,p))}}class cne{constructor(e,t){R(this,"disposeSideEffectListener");this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(s,o)=>{s.isFocused!==o.isFocused&&this.updateContainerClass()});const r=e.getInstanceState().isFocused;t!==r&&e.updateInstanceState({isFocused:!!t}),this.updateContainerClass(),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();["Tab","ArrowUp","ArrowDown"].includes(e.key)&&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 une{constructor(e,t){R(this,"shapeFontFacesCache");R(this,"shapeFontLoadStateCache");R(this,"fontStates",new Ek("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:ES,areRecordsEqual:(r,s)=>r.props===s.props}),this.shapeFontLoadStateCache=e.store.createCache(r=>{const s=le("font faces",()=>this.getShapeFontFaces(r));return le("font load state",()=>s.get().map(i=>this.getFontState(i)),{isEqual:ES})})}getShapeFontFaces(e){const t=typeof e=="string"?e:e.id;return this.shapeFontFacesCache.get(t)??jr}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 o of this.getShapeFontFaces(this.editor.getShape(s)))t.add(o);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,o=>({...o,state:"ready"}))}).catch(o=>{console.error(o),this.fontStates.update(e,i=>({...i,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,to(()=>{for(const r of t)this.ensureFontIsLoaded(r)})});for(const t of e)this.fontsToLoad.add(t)}findOrCreateFontFace(e){var s;for(const o of document.fonts)if(o.family===e.family&&Qr(Tj).every(([i,a])=>o[i]===(e[i]??a)))return o;const t=((s=this.assetUrls)==null?void 0:s[e.src.url])??e.src.url,r=new FontFace(e.family,`url(${JSON.stringify(t)})`,{...cc(Tj,o=>e[o]),display:"swap"});return document.fonts.add(r),r}async toEmbeddedCssDeclaration(e){var o;const t=((o=this.assetUrls)==null?void 0:o[e.src.url])??e.src.url,r=await Jr.urlToDataUrl(t),s=st([`url("${r}")`,e.src.format?`format(${e.src.format})`:null,e.src.tech?`tech(${e.src.tech})`:null]).join(" ");return st(["@font-face {",` font-family: "${e.family}";`,e.ascentOverride?` ascent-override: ${e.ascentOverride};`:null,e.descentOverride?` descent-override: ${e.descentOverride};`:null,e.stretch?` font-stretch: ${e.stretch};`:null,e.style?` font-style: ${e.style};`:null,e.weight?` font-weight: ${e.weight};`:null,e.featureSettings?` font-feature-settings: ${e.featureSettings};`:null,e.lineGapOverride?` line-gap-override: ${e.lineGapOverride};`:null,e.unicodeRange?` unicode-range: ${e.unicodeRange};`:null,` src: ${s};`,"}"]).join(`
115
+ `)}}const Tj={style:"normal",weight:"normal",stretch:"normal",unicodeRange:"U+0-10FFFF",featureSettings:"normal",ascentOverride:"normal",descentOverride:"normal",lineGapOverride:"normal"};function Of(n){return hne}class dne{constructor(){R(this,"length",0);R(this,"head",null);R(this,"tail",this)}push(e){return new mT(e,this)}toArray(){return jr}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const hne=new dne;class mT{constructor(e,t){R(this,"length");this.head=e,this.tail=t,this.length=t.length+1}push(e){return new mT(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 fne{constructor(e){R(this,"store");R(this,"dispose");R(this,"state","recording");R(this,"pendingDiff",new gne);R(this,"stacks",hn("HistoryManager.stacks",{undos:Of(),redos:Of()},{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??Ap,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:Of()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:xt(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=pne[t.history]);try{if(this._isInBatch)return to(e),this;this._isInBatch=!0;try{to(e)}catch(s){throw this.annotateError(s),s}finally{this._isInBatch=!1}return this}finally{this.state=r}}_undo({pushToRedoStack:e,toMark:t=void 0}){var s;const r=this.state;this.state="paused";try{let{undos:o,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),l=a5(a),c=Ik(a);e&&!l&&(i=i.push({type:"diff",diff:a}));let u=!1;if(l)for(;((s=o.head)==null?void 0:s.type)==="stop";){const h=o.head;if(o=o.tail,e&&(i=i.push(h)),h.id===t){u=!0;break}}if(!u)e:for(;o.head;){const h=o.head;switch(o=o.tail,e&&(i=i.push(h)),h.type){case"diff":hp(c,[Ik(h.diff)]);break;case"stop":if(!t)break e;if(h.id===t){u=!0;break e}break;default:xt(h)}}if(!u&&t)return this;this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:o,redos:i})}finally{this.state=r}return this}undo(){return this._undo({pushToRedoStack:!0}),this}redo(){var t;const e=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:s}=this.stacks.get();if(s.length===0)return this;for(;((t=s.head)==null?void 0:t.type)==="stop";)r=r.push(s.head),s=s.tail;const o=OS();for(;s.head;){const i=s.head;if(r=r.push(i),s=s.tail,i.type==="diff")hp(o,[i.diff]);else break}this.store.applyDiff(o,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:s})}finally{this.state=e}return this}bail(){return this._undo({pushToRedoStack:!1}),this}bailToMark(e){return this._undo({pushToRedoStack:!1,toMark:e}),this}squashToMark(e){var o;let t=this.stacks.get().undos;const r=[];for(;t.head&&!(t.head.type==="stop"&&t.head.id===e);)t.head.type==="diff"&&r.push(t.head.diff),t=t.tail;if(!t.head||((o=t.head)==null?void 0:o.id)!==e)return console.error("Could not find mark to squash to: ",e),this;if(r.length===0)return this;const s=OS();return hp(s,r.reverse()),this.stacks.update(({redos:i})=>({undos:t.push({type:"diff",diff:s}),redos:i})),this}_mark(e){to(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:Of(),redos:Of()}),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 pne={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class gne{constructor(){R(this,"diff",OS());R(this,"isEmptyAtom",hn("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=OS(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){hp(this.diff,[e]),this.isEmptyAtom.set(a5(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class mne{constructor(e){R(this,"scribbleItems",new Map);R(this,"state","paused");this.editor=e}addScribble(e,t=Mt()){const r={id:t,scribble:{id:t,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...e,state:"starting"},timeoutMs:0,delayRemaining:e.delay??0,prev:null,next:null};return this.scribbleItems.set(t,r),r}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}stop(e){const t=this.scribbleItems.get(e);if(!t)throw Error(`Scribble with id ${e} not found`);return t.delayRemaining=Math.min(t.delayRemaining,200),t.scribble.state="stopping",t}addPoint(e,t,r,s=.5){const o=this.scribbleItems.get(e);if(!o)throw Error(`Scribble with id ${e} not found`);const{prev:i}=o,a={x:t,y:r,z:s};return(!i||P.Dist(i,a)>=1)&&(o.next=a),o}tick(e){this.scribbleItems.size!==0&&this.editor.run(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next: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:o,next:i,scribble:a}=t;switch(a.state){case"active":{i&&i!==o?(t.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):s===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&s===0){if(a.points.length===1){this.scribbleItems.delete(t.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:t})=>({...t,points:[...t.points]})).slice(-5)})})}}var yne=Object.create,xz=Object.defineProperty,Sne=Object.getOwnPropertyDescriptor,xne=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),vz=n=>{throw TypeError(n)},wz=(n,e,t)=>e in n?xz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,vne=n=>[,,,yne(null)],bz=["class","method","getter","setter","accessor","field","value","get","set"],Cz=n=>n!==void 0&&typeof n!="function"?vz("Function expected"):n,wne=(n,e,t,r,s)=>({kind:bz[n],name:e,metadata:r,addInitializer:o=>t._?vz("Already initialized"):s.push(Cz(o||null))}),bne=(n,e)=>wz(e,xne("metadata"),n[3]),Cne=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},A0=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=bz[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,Sne(s,t)),w=r.length-1;w>=0;w--)l=wne(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,Cz(i)&&(y[S]=i);return y&&xz(s,t,y),s},Pne=(n,e,t)=>wz(n,e+"",t),Pz,kz,Ez,Iz,Ru;const Xe=n=>Math.round(n*10**8)/10**8;function Ea(n,e,t,r,s){const o=n.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&Xe(a.length)===Xe(t)&&si(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));if(o.length===0)return[];const i=new Set;return o.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=Ea(n,l,t,r,si(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));o.push(...c)}}),o}function kne(n){n.sort((e,t)=>t.gaps.length-e.gaps.length);for(let e=n.length-1;e>0;e--){const t=n[e];for(let r=e-1;r>=0;r--){const s=n[r];if(s.direction===t.direction&&t.gaps.every(o=>s.gaps.some(i=>Xe(o.startEdge[0].x)===Xe(i.startEdge[0].x)&&Xe(o.startEdge[0].y)===Xe(i.startEdge[0].y)&&Xe(o.startEdge[1].x)===Xe(i.startEdge[1].x)&&Xe(o.startEdge[1].y)===Xe(i.startEdge[1].y))&&s.gaps.some(i=>Xe(o.endEdge[0].x)===Xe(i.endEdge[0].x)&&Xe(o.endEdge[0].y)===Xe(i.endEdge[0].y)&&Xe(o.endEdge[1].x)===Xe(i.endEdge[1].x)&&Xe(o.endEdge[1].y)===Xe(i.endEdge[1].y)))){n.splice(e,1);break}}}}Iz=[le],Ez=[le],kz=[le],Pz=[le];class Ah{constructor(e){this.manager=e,Cne(Ru,5,this),Pne(this,"editor"),this.editor=e.editor}getSnapPointsCache(){const{editor:e}=this;return e.store.createComputedCache("snapPoints",t=>{const r=e.getShapePageTransform(t.id);if(!r)return;const o=e.getShapeUtil(t).getBoundsSnapGeometry(t).points??e.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!o))return o.map((i,a)=>{const{x:l,y:c}=de.applyToPoint(r,i);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 o=e.get(s);o&&r.push(...o)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:qr(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){const e=[],t=[];let r,s;const o=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<o.length;a++){r=o[a];for(let l=a+1;l<o.length;l++)s=o[l],r.pageBounds.maxX<s.pageBounds.minX&&Mf(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)&&e.push({startNode:r,endNode:s,startEdge:[new P(r.pageBounds.maxX,r.pageBounds.minY),new P(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new P(s.pageBounds.minX,s.pageBounds.minY),new P(s.pageBounds.minX,s.pageBounds.maxY)],length:s.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:si(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)})}const i=o.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)s=i[l],r.pageBounds.maxY<s.pageBounds.minY&&Mf(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)&&t.push({startNode:r,endNode:s,startEdge:[new P(r.pageBounds.minX,r.pageBounds.maxY),new P(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new P(s.pageBounds.minX,s.pageBounds.minY),new P(s.pageBounds.maxX,s.pageBounds.minY)],length:s.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:si(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 y,w;const o=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(s),l=r.map(({x:C,y:T},E)=>({id:"selection:"+E,x:C+s.x,y:T+s.y})),c=i,u=[],h=[],p=new P(o,o);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const m=new P(e==="x"?0:((y=u[0])==null?void 0:y.nudge)??0,e==="y"?0:((w=h[0])==null?void 0:w.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(C=>{C.x+=m.x,C.y+=m.y}),a.translate(m),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const S=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),v=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...v,...S]),{nudge:m}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:t,handle:r,isAspectRatioLocked:s,isResizingFromCenter:o}){var O,D;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=ye.Resize(e,r,o?t.x*2:t.x,o?t.y*2:t.y,s);let u=r;l<0&&(u=PQ(u)),c<0&&(u=CQ(u)),o&&(a.center=e.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",m=_j(u,a),S=this.getSnappablePoints(),v=[],y=[],w=new P(i,i);this.collectPointSnaps({minOffset:w,nearestSnapsX:v,nearestSnapsY:y,otherNodeSnapPoints:S,selectionSnapPoints:m});const C=new P(h?0:((O=v[0])==null?void 0:O.nudge)??0,p?0:((D=y[0])==null?void 0:D.nudge)??0);if(s&&kQ(u)&&C.len()!==0){const F=v.length&&y.length?Math.abs(C.x)<Math.abs(C.y)?"x":"y":v.length?"x":"y",U=e.aspectRatio;F==="x"?(y.length=0,C.y=C.x/U,(u==="bottom_left"||u==="top_right")&&(C.y=-C.y)):(v.length=0,C.x=C.y*U,(u==="bottom_left"||u==="top_right")&&(C.x=-C.x))}const T=P.Add(t,C),{box:E}=ye.Resize(e,r,o?T.x*2:T.x,o?T.y*2:T.y,s);o&&(E.center=e.center);const _=_j("any",E);v.length=0,y.length=0,w.x=0,w.y=0,this.collectPointSnaps({minOffset:w,nearestSnapsX:v,nearestSnapsY:y,otherNodeSnapPoints:S,selectionSnapPoints:_});const A=this.getPointSnapLines({nearestSnapsX:v,nearestSnapsY:y});return this.manager.setIndicators([...A]),{nudge:C}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:s,nearestSnapsY:o}){for(const i of e)for(const a of t){const l=P.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);Xe(c)<=Xe(r.x)&&(Xe(c)<Xe(r.x)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),Xe(u)<=Xe(r.y)&&(Xe(u)<Xe(r.y)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:e,minOffset:t,nearestSnapsX:r,nearestSnapsY:s}){const{horizontal:o,vertical:i}=this.getVisibleGaps();for(const a of o){if(!Mf(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&&Xe(Math.abs(c))<=Xe(t.x)){Xe(Math.abs(c))<Xe(t.x)&&(r.length=0),t.x=Math.abs(c);const w={type:"gap_center",gap:a,nudge:c},C=r.find(({type:E})=>E==="gap_center"),T=C&&si(a.breadthIntersection[0],a.breadthIntersection[1],C.gap.breadthIntersection[0],C.gap.breadthIntersection[1]);C&&C.gap.length>a.length&&T?r[r.indexOf(C)]=w:(!C||!T)&&r.push(w)}const h=a.startNode.pageBounds.minX-a.length,p=e.maxX,m=h-p;Xe(Math.abs(m))<=Xe(t.x)&&(Xe(Math.abs(m))<Xe(t.x)&&(r.length=0),t.x=Math.abs(m),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:m}));const S=a.endNode.pageBounds.maxX+a.length,v=e.minX,y=S-v;Xe(Math.abs(y))<=Xe(t.x)&&(Xe(Math.abs(y))<Xe(t.x)&&(r.length=0),t.x=Math.abs(y),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:y}))}for(const a of i){if(!Mf(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&&Xe(Math.abs(c))<=Xe(t.y)){Xe(Math.abs(c))<Xe(t.y)&&(s.length=0),t.y=Math.abs(c);const w={type:"gap_center",gap:a,nudge:c},C=s.find(({type:E})=>E==="gap_center"),T=C&&Mf(C.gap.breadthIntersection[0],C.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);C&&C.gap.length>a.length&&T?s[s.indexOf(C)]=w:(!C||!T)&&s.push(w);continue}const h=a.startNode.pageBounds.minY-a.length,p=e.maxY,m=h-p;Xe(Math.abs(m))<=Xe(t.y)&&(Xe(Math.abs(m))<Xe(t.y)&&(s.length=0),t.y=Math.abs(m),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:m}));const S=a.endNode.pageBounds.maxY+a.length,v=e.minY,y=S-v;Xe(Math.abs(y))<=Xe(t.y)&&(Xe(Math.abs(y))<Xe(t.y)&&(s.length=0),t.y=Math.abs(y),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:y}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:t}){const r={},s={};if(e.length>0){for(const o of e)if(o.type==="points"){const i=Xe(o.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(o.points)}}if(t.length>0){for(const o of t)if(o.type==="points"){const i=Xe(o.points.otherPoint.y);s[i]||(s[i]=[]),s[i].push(o.points)}}return Object.values(r).concat(Object.values(s)).map(o=>({id:Mt(),type:"points",points:cI(o.map(i=>P.From(i.otherPoint)).concat(o.map(i=>P.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:s,horizontal:o}=this.getVisibleGaps(),i={top:e.sides[0],right:e.sides[1],bottom:[e.corners[3],e.corners[2]],left:[e.corners[0],e.corners[3]]},a=[];if(t.length>0)for(const l of t){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:m,endEdge:S}}=l;switch(l.type){case"gap_center":{const v=(m-e.width)/2,y=si(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:Mt(),gaps:[...Ea(o,h.id,v,"backward",y),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:S},...Ea(o,p.id,v,"forward",y)]});break}case"gap_duplicate":{const v=si(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:Mt(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(y=>y.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:S},...Ea(o,p.id,m,"forward",v)]:[...Ea(o,h.id,m,"backward",v),{startEdge:u,endEdge:S},{startEdge:S.map(y=>y.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:m,endEdge:S}}=l;switch(l.type){case"gap_center":{const v=(m-e.height)/2,y=si(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:Mt(),gaps:[...Ea(s,h.id,v,"backward",y),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:S},...Ea(s,l.gap.endNode.id,v,"forward",y)]});break}case"gap_duplicate":{const v=si(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:Mt(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(y=>y.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:S},...Ea(s,p.id,m,"forward",v)]:[...Ea(s,h.id,m,"backward",v),{startEdge:u,endEdge:S},{startEdge:S.map(y=>y.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return kne(a),a}}Ru=vne();A0(Ru,1,"getSnapPointsCache",Iz,Ah);A0(Ru,1,"getSnappablePoints",Ez,Ah);A0(Ru,1,"getSnappableGapNodes",kz,Ah);A0(Ru,1,"getVisibleGaps",Pz,Ah);bne(Ru,Ah);function _j(n,e){const{minX:t,maxX:r,minY:s,maxY:o}=e,i=[];switch(n){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:t,y:s})}switch(n){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:s})}switch(n){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:o})}switch(n){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:t,y:o})}return i}var Ene=Object.create,Tz=Object.defineProperty,Ine=Object.getOwnPropertyDescriptor,Tne=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),_z=n=>{throw TypeError(n)},Mz=(n,e,t)=>e in n?Tz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_ne=n=>[,,,Ene(null)],Az=["class","method","getter","setter","accessor","field","value","get","set"],Oz=n=>n!==void 0&&typeof n!="function"?_z("Function expected"):n,Mne=(n,e,t,r,s)=>({kind:Az[n],name:e,metadata:r,addInitializer:o=>t._?_z("Already initialized"):s.push(Oz(o||null))}),Ane=(n,e)=>Mz(e,Tne("metadata"),n[3]),One=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Rne=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=Az[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,Ine(s,t)),w=r.length-1;w>=0;w--)l=Mne(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,Oz(i)&&(y[S]=i);return y&&Tz(s,t,y),s},Dne=(n,e,t)=>Mz(n,e+"",t),Rz,O0;const jne=()=>null,Lne=()=>[];Rz=[le];class yT{constructor(e){this.manager=e,One(O0,5,this),Dne(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):jne,o=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):Lne;return{outline:r.outline===void 0?e.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:s,getSelfSnapPoints:o}})}*iterateSnapPointsInPageSpace(e,t){var s,o;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapPoints(t);if(r&&r.length){const i=qr(this.editor.getShapePageTransform(e));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const a=(o=this.getSnapGeometryCache().get(i))==null?void 0:o.points;if(!a||!a.length)continue;const l=qr(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(e,t){var s,o;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapOutline(t);r&&(yield{shapeId:e,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const a=(o=this.getSnapGeometryCache().get(i))==null?void 0:o.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:r}){const s=this.manager.getSnapThreshold();let o=s,i=null;for(const c of this.iterateSnapPointsInPageSpace(e,t))P.DistMin(r,c,o)&&(o=P.Dist(r,c),i=c);if(i)return i;let a=s,l=null;for(const{shapeId:c,outline:u}of this.iterateSnapOutlines(e,t)){const h=qr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),m=u.nearestPoint(p),S=h.applyToPoint(m);P.DistMin(r,S,a)&&(a=P.Dist(r,S),l=S)}return l||null}snapHandle({currentShapeId:e,handle:t}){const s=qr(this.editor.getShapePageTransform(e)).applyToPoint(t),o=this.getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:s});return o?(this.manager.setIndicators([{id:Mt(),type:"points",points:[o]}]),{nudge:P.Sub(o,s)}):null}}O0=_ne();Rne(O0,1,"getSnapGeometryCache",Rz,yT);Ane(O0,yT);var Nne=Object.create,Dz=Object.defineProperty,Fne=Object.getOwnPropertyDescriptor,zne=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),jz=n=>{throw TypeError(n)},Lz=(n,e,t)=>e in n?Dz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Bne=n=>[,,,Nne(null)],Nz=["class","method","getter","setter","accessor","field","value","get","set"],Fz=n=>n!==void 0&&typeof n!="function"?jz("Function expected"):n,$ne=(n,e,t,r,s)=>({kind:Nz[n],name:e,metadata:r,addInitializer:o=>t._?jz("Already initialized"):s.push(Fz(o||null))}),Une=(n,e)=>Lz(e,zne("metadata"),n[3]),Hne=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},ST=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=Nz[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,Fne(s,t)),w=r.length-1;w>=0;w--)l=$ne(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,Fz(i)&&(y[S]=i);return y&&Dz(s,t,y),s},VC=(n,e,t)=>Lz(n,typeof e!="symbol"?e+"":e,t),zz,Bz,$z,Oh;$z=[le],Bz=[le],zz=[le];class kg{constructor(e){this.editor=e,Hne(Oh,5,this),VC(this,"shapeBounds"),VC(this,"handles"),VC(this,"_snapIndicators",hn("snapLines",void 0)),this.shapeBounds=new Ah(this),this.handles=new yT(this)}getIndicators(){return this._snapIndicators.get()??jr}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(e){this._snapIndicators.set(e)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:e}=this,t=e.getViewportPageBounds(),r=e.getSelectedShapeIds(),s=new Set,o=i=>{if(Ts(i)){const l=e.getShape(i);l&&e.isShapeOfType(l,"frame")&&s.add(i)}const a=e.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=e.getShape(l);if(!c||!e.getShapeUtil(c).canSnap(c))continue;const h=e.getShapePageBounds(l);if(h&&t.includes(h)){if(e.isShapeOfType(c,"group")){o(l);continue}s.add(l)}}};return o(this.getCurrentCommonAncestor()??e.getCurrentPageId()),s}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Oh=Bne();ST(Oh,1,"getSnapThreshold",$z,kg);ST(Oh,1,"getSnappableShapes",Bz,kg);ST(Oh,1,"getCurrentCommonAncestor",zz,kg);Une(Oh,kg);const Kne=/\r?\n|\r/g;function Mj(n){return n.replace(Kne,`
116
+ `).split(`
117
+ `).map(e=>e||" ").join(`
118
+ `)}const Wne={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},Vne=/\s/;class Gne{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=Mj(e),this.measureHtml(r.innerHTML,t)}measureHtml(e,t){const r=this.baseElem.cloneNode();if(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"),t.otherStyles)for(const[i,a]of Object.entries(t.otherStyles))r.style.setProperty(i,a);const s=r.scrollWidth,o=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:o.width,h:o.height,scrollWidth:s}}measureElementTextNodeSpans(e,{shouldTruncateToFirstLine:t=!1}={}){const r=[],s=e.getBoundingClientRect(),o=-s.left,i=-s.top,a=new Range,l=e.childNodes[0];let c=0,u=null,h=null,p=0,m=0,S=!1;for(const v of e.childNodes)if(v.nodeType===Node.TEXT_NODE)for(const y of v.textContent??""){a.setStart(l,c),a.setEnd(l,c+y.length);const w=a.getClientRects(),C=w[w.length-1],T=C.top+i,E=C.left+o,_=C.right+o,A=E<m,O=Vne.test(y);if(O!==h||T!==p||!u){if(u){if(t&&T!==p){S=!0;break}r.push(u)}u={box:{x:E,y:T,w:C.width,h:C.height},text:y},m=E}else A&&(u.box.x=E),u.box.w=A?u.box.w+C.width:_-u.box.x,u.text+=y;y===`
119
+ `&&(m=0),h=O,p=T,c+=y.length}return u&&r.push(u),{spans:r,didTruncate:S}}measureTextSpans(e,t){if(e==="")return[];const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(r);const s=Math.ceil(t.width-t.padding*2);if(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",Wne[t.textAlign]),r.style.setProperty("font-style",t.fontStyle),t.otherStyles)for(const[c,u]of Object.entries(t.otherStyles))r.style.setProperty(c,u);const o=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";o&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=Mj(e);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:o});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=i;const u=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,h=u[u.length-1];return u.push({text:"…",box:{x:Math.min(h.box.x+h.box.w,t.width-t.padding-c),y:h.box.y,w:c,h:h.box.h}}),u}return r.remove(),a}}var qne=Object.create,Uz=Object.defineProperty,Yne=Object.getOwnPropertyDescriptor,Xne=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Hz=n=>{throw TypeError(n)},Kz=(n,e,t)=>e in n?Uz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Zne=n=>[,,,qne(null)],Wz=["class","method","getter","setter","accessor","field","value","get","set"],Vz=n=>n!==void 0&&typeof n!="function"?Hz("Function expected"):n,Jne=(n,e,t,r,s)=>({kind:Wz[n],name:e,metadata:r,addInitializer:o=>t._?Hz("Already initialized"):s.push(Vz(o||null))}),Qne=(n,e)=>Kz(e,Xne("metadata"),n[3]),ere=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Gz=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=Wz[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,Yne(s,t)),w=r.length-1;w>=0;w--)l=Jne(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,Vz(i)&&(y[S]=i);return y&&Uz(s,t,y),s},oy=(n,e,t)=>Kz(n,typeof e!="symbol"?e+"":e,t),qz,Yz,Eg;const Aj=gF;Yz=[Rs],qz=[Rs];class R0{constructor(e){this.editor=e,ere(Eg,5,this),oy(this,"cancelRaf"),oy(this,"isPaused",!0),oy(this,"now",0),oy(this,"prevPoint",new P),this.editor.disposables.add(this.dispose),this.start()}start(){var e;this.isPaused=!1,(e=this.cancelRaf)==null||e.call(this),this.cancelRaf=Aj(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=Aj(this.tick)}dispose(){var e;this.isPaused=!0,(e=this.cancelRaf)==null||e.call(this)}updatePointerVelocity(e){const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:s}}}=this;if(e===0)return;const o=P.Sub(r,t);this.prevPoint=r.clone();const i=o.len(),a=i?o.div(i):new P(0,0),l=s.clone().lrp(a.mul(i/e),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),s.equals(l)||(this.editor.inputs.pointerVelocity=l)}}Eg=Zne();Gz(Eg,1,"tick",Yz,R0);Gz(Eg,1,"dispose",qz,R0);Qne(Eg,R0);var tre=Object.create,Xz=Object.defineProperty,nre=Object.getOwnPropertyDescriptor,rre=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),Zz=n=>{throw TypeError(n)},Jz=(n,e,t)=>e in n?Xz(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,sre=n=>[,,,tre(null)],Qz=["class","method","getter","setter","accessor","field","value","get","set"],eB=n=>n!==void 0&&typeof n!="function"?Zz("Function expected"):n,ore=(n,e,t,r,s)=>({kind:Qz[n],name:e,metadata:r,addInitializer:o=>t._?Zz("Already initialized"):s.push(eB(o||null))}),ire=(n,e)=>Jz(e,rre("metadata"),n[3]),are=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Uo=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=Qz[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,nre(s,t)),w=r.length-1;w>=0;w--)l=ore(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,eB(i)&&(y[S]=i);return y&&Xz(s,t,y),s},Oj=(n,e,t)=>Jz(n,typeof e!="symbol"?e+"":e,t),tB,nB,rB,sB,oB,iB,aB,lB,cB,uB,dB,hB,hs;hB=[le],dB=[le],uB=[le],cB=[le],lB=[le],aB=[le],iB=[le],oB=[le],sB=[le],rB=[le],nB=[le],tB=[le];class Ns{constructor(e,t){if(this.user=e,this.inferDarkMode=t,are(hs,5,this),Oj(this,"systemColorScheme",hn("systemColorScheme","light")),Oj(this,"disposables",new Set),typeof window>"u"||!("matchMedia"in window))return;const r=window.matchMedia("(prefers-color-scheme: dark)");r!=null&&r.matches&&this.systemColorScheme.set("dark");const s=o=>{o.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")};r==null||r.addEventListener("change",s),this.disposables.add(()=>r==null?void 0:r.removeEventListener("change",s))}dispose(){this.disposables.forEach(e=>e())}updateUserPreferences(e){this.user.setUserPreferences({...this.user.userPreferences.get(),...e})}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??Fi.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??Fi.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){var e;return((e=this.user.userPreferences.get().name)==null?void 0:e.trim())??Fi.name}getLocale(){return this.user.userPreferences.get().locale??Fi.locale}getColor(){return this.user.userPreferences.get().color??Fi.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??Fi.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??Fi.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??Fi.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??Fi.isPasteAtCursorMode}}hs=sre();Uo(hs,1,"getUserPreferences",hB,Ns);Uo(hs,1,"getIsDarkMode",dB,Ns);Uo(hs,1,"getEdgeScrollSpeed",uB,Ns);Uo(hs,1,"getAnimationSpeed",cB,Ns);Uo(hs,1,"getId",lB,Ns);Uo(hs,1,"getName",aB,Ns);Uo(hs,1,"getLocale",iB,Ns);Uo(hs,1,"getColor",oB,Ns);Uo(hs,1,"getIsSnapMode",sB,Ns);Uo(hs,1,"getIsWrapMode",rB,Ns);Uo(hs,1,"getIsDynamicResizeMode",nB,Ns);Uo(hs,1,"getIsPasteAtCursorMode",tB,Ns);ire(hs,Ns);const lre={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"},cre=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class Le{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,"useCoalescedEvents");R(this,"parent");R(this,"_path");R(this,"_current");R(this,"_isActive");R(this,"_currentToolIdMask",hn("curent tool id mask",void 0));this.editor=e;const{id:r,children:s,initial:o,isLockable:i,useCoalescedEvents:a}=this.constructor;this.id=r,this._isActive=hn("toolIsActive"+this.id,!1),this._current=hn("toolState"+this.id,void 0),this._path=le("toolPath"+this.id,()=>{const l=this.getCurrent();return this.id+(l?`.${l.getPath()}`:"")}),this.parent=t??{},this.parent?s&&o?(this.type="branch",this.initial=o,this.children=Object.fromEntries(s().map(l=>[l.id,new l(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",s&&o&&(this.initial=o,this.children=Object.fromEntries(s().map(l=>[l.id,new l(this.editor,this)])),this._current.set(this.children[this.initial]))),this.isLockable=i,this.useCoalescedEvents=a,this.performanceTracker=new W3}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}transition(e,t={}){var o;const r=e.split(".");let s=this;for(let i=0;i<r.length;i++){const a=r[i],l=s.getCurrent(),c=(o=s.children)==null?void 0:o[a];if(!c)throw Error(`${s.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(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=lre[e.name],r=this._current.__unsafe__getWithoutCapture();(s=this[t])==null||s.call(this,e),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(e)}enter(e,t){var r;if(sn.measurePerformance.get()&&cre.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,e,t),this.children&&this.initial&&this.getIsActive()){const s=this.children[this.initial];this._current.set(s),s.enter(e,t)}}exit(e,t){var r,s;sn.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,e,t),this.getIsActive()||(s=this.getCurrent())==null||s.exit(e,t)}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(e){this._currentToolIdMask.set(e)}}R(Le,"id"),R(Le,"initial"),R(Le,"children"),R(Le,"isLockable",!0),R(Le,"useCoalescedEvents",!1);class $k extends Le{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($k,"id","root"),R($k,"initial","");var ure=Object.create,fB=Object.defineProperty,dre=Object.getOwnPropertyDescriptor,pB=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),gB=n=>{throw TypeError(n)},mB=(n,e,t)=>e in n?fB(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,hre=n=>[,,,ure((n==null?void 0:n[pB("metadata")])??null)],yB=["class","method","getter","setter","accessor","field","value","get","set"],SB=n=>n!==void 0&&typeof n!="function"?gB("Function expected"):n,fre=(n,e,t,r,s)=>({kind:yB[n],name:e,metadata:r,addInitializer:o=>t._?gB("Already initialized"):s.push(SB(o||null))}),pre=(n,e)=>mB(e,pB("metadata"),n[3]),gre=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},Ie=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=yB[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,dre(s,t)),w=r.length-1;w>=0;w--)l=fre(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,SB(i)&&(y[S]=i);return y&&fB(s,t,y),s},He=(n,e,t)=>mB(n,typeof e!="symbol"?e+"":e,t),xB,vB,wB,bB,CB,PB,kB,EB,IB,TB,_B,MB,AB,OB,RB,DB,jB,LB,NB,FB,zB,BB,$B,UB,HB,KB,WB,VB,GB,qB,YB,XB,ZB,JB,QB,e$,t$,n$,r$,s$,o$,i$,a$,l$,c$,u$,d$,h$,f$,p$,g$,m$,y$,S$,x$,v$,w$,b$,C$,P$,k$,E$,I$,T$,_$,M$,A$,O$,R$,D$,j$,L$,N$,Uk,Ee;let ke=class extends(Uk=jee,N$=[le],L$=[le],j$=[le],D$=[le],R$=[le],O$=[le],A$=[le],M$=[le],_$=[le],T$=[le],I$=[le],E$=[le],k$=[le],P$=[le],C$=[le],b$=[le],w$=[le],v$=[le],x$=[le],S$=[le],y$=[le],m$=[le],g$=[le],p$=[le],f$=[le],h$=[le],d$=[le],u$=[le],c$=[le],l$=[le],a$=[le],i$=[le],o$=[le],s$=[le],r$=[le],n$=[le],t$=[le],e$=[le],QB=[le],JB=[le],ZB=[le],XB=[le],YB=[le],qB=[le],GB=[le],VB=[le],WB=[le],KB=[le],HB=[le],UB=[le],$B=[le],BB=[le],zB=[le],FB=[le],NB=[le],LB=[le],jB=[le],DB=[le],RB=[le],OB=[le],AB=[le],MB=[le],_B=[le],TB=[le],IB=[le],EB=[le({isEqual:(e,t)=>e.equals(t)})],kB=[le],PB=[le],CB=[le],bB=[Rs],wB=[Rs],vB=[Rs],xB=[Rs],Uk){constructor({store:e,user:t,shapeUtils:r,bindingUtils:s,tools:o,getContainer:i,cameraOptions:a,textOptions:l,initialState:c,autoFocus:u,inferDarkMode:h,options:p,isShapeHidden:m,getShapeVisibility:S,fontAssetUrls:v}){var Y;super(),gre(Ee,5,this),He(this,"id",Mt()),He(this,"_getShapeVisibility"),He(this,"options"),He(this,"contextId",Mt()),He(this,"store"),He(this,"root"),He(this,"disposables",new Set),He(this,"isDisposed",!1),He(this,"_tickManager"),He(this,"snaps"),He(this,"timers",qS.forContext(this.contextId)),He(this,"user"),He(this,"textMeasure"),He(this,"fonts"),He(this,"environment",Tt),He(this,"scribbles"),He(this,"sideEffects"),He(this,"edgeScrollManager"),He(this,"focusManager"),He(this,"getContainer"),He(this,"shapeUtils"),He(this,"styleProps"),He(this,"bindingUtils"),He(this,"history"),He(this,"_shouldIgnoreShapeLock",!1),He(this,"_crashingError",null),He(this,"_isChangingStyleTimeout",-1),He(this,"menus",Xr.forContext(this.contextId)),He(this,"_currentRichTextEditor",hn("rich text editor",null)),He(this,"_textOptions"),He(this,"_cameraOptions",hn("camera options",YD)),He(this,"_viewportAnimation",null),He(this,"_willSetInitialBounds",!0),He(this,"_isLockedOnFollowingUser",hn("isLockedOnFollowingUser",!1)),He(this,"_cameraState",hn("camera state","idle")),He(this,"_cameraStateTimeoutRemaining",0),He(this,"_currentPageShapeIds"),He(this,"_shapeGeometryCaches",{}),He(this,"_shapePageGeometryCaches",{}),He(this,"_parentIdsToChildIds"),He(this,"animatingShapes",new Map),He(this,"externalAssetContentHandlers",{file:null,url:null}),He(this,"temporaryAssetPreview",new Map),He(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null,tldraw:null,excalidraw:null}),He(this,"inputs",{originPagePoint:new P,originScreenPoint:new P,previousPagePoint:new P,previousScreenPoint:new P,currentPagePoint:new P,currentScreenPoint:new P,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 P}),He(this,"_clickManager",new M0(this)),He(this,"_prevCursor","default"),He(this,"_shiftKeyTimeout",-1),He(this,"_altKeyTimeout",-1),He(this,"_ctrlKeyTimeout",-1),He(this,"_metaKeyTimeout",-1),He(this,"_restoreToolId","select"),He(this,"_pinchStart",1),He(this,"_didPinch",!1),He(this,"_selectedShapeIdsAtPointerDown",[]),He(this,"_longPressTimeout",-1),He(this,"capturedPointerId",null),He(this,"performanceTracker"),He(this,"performanceTrackerTimeout",-1),He(this,"_pendingEventsForNextTick",[]),Ve(!(m&&S),"Cannot use both isShapeHidden and getShapeVisibility"),this._getShapeVisibility=m?(j,N)=>m(j,N)?"hidden":"inherit":S,this.options={...Fte,...p},this.store=e,this.history=new fne({store:e,annotateError:j=>{this.annotateError(j,{origin:"history.batch",willCrashApp:!0}),this.crash(j)}}),this.snaps=new kg(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...YD,...a}),this._textOptions=hn("text options",l??null),this.user=new Ns(t??D4(),h??!1),this.disposables.add(()=>this.user.dispose()),this.getContainer=i,this.textMeasure=new Gne(this),this.fonts=new une(this,v),this._tickManager=new R0(this);class y extends $k{}R(y,"initial",c??""),this.root=new y(this),this.root.children={};const w=$4(r),C={},T={},E=new Map;for(const j of w){const N=new j(this);C[j.type]=N;const z=h5(j.props??{});T[j.type]=z;for(const G of z.keys())if(!E.has(G.id))E.set(G.id,G);else if(E.get(G.id)!==G)throw Error(`Multiple style props with id "${G.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=C,this.styleProps=T;const _=z4(s),A={};for(const j of _){const N=new j(this);A[j.type]=N}this.bindingUtils=A;for(const j of[...o]){if(Do(this.root.children,j.id))throw Error(`Can't override tool with id "${j.id}"`);this.root.children[j.id]=new j(this,this.root)}this.scribbles=new mne(this);const O=(j,N)=>{let z=null;const G=j.selectedShapeIds.filter(K=>!N.has(K));G.length!==j.selectedShapeIds.length&&(z||(z={...j}),z.selectedShapeIds=G);const q=j.erasingShapeIds.filter(K=>!N.has(K));q.length!==j.erasingShapeIds.length&&(z||(z={...j}),z.erasingShapeIds=q),j.hoveredShapeId&&N.has(j.hoveredShapeId)&&(z||(z={...j}),z.hoveredShapeId=null),j.editingShapeId&&N.has(j.editingShapeId)&&(z||(z={...j}),z.editingShapeId=null);const $=j.hintingShapeIds.filter(K=>!N.has(K));return $.length!==j.hintingShapeIds.length&&(z||(z={...j}),z.hintingShapeIds=$),j.focusedGroupId&&N.has(j.focusedGroupId)&&(z||(z={...j}),z.focusedGroupId=null),z};this.sideEffects=this.store.sideEffects;let D=new Map;const F=new Set,U=new Set;let V=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var j,N,z,G;F.clear();for(const q of U){U.delete(q);const $=this.getShape(q);if(!$)continue;const K=this.getShapeUtil($),J=(j=K.onChildrenChange)==null?void 0:j.call(K,$);J!=null&&J.length&&this.updateShapes(J)}if(V.size){const q=V;V=new Set;for(const $ of q){const K=this.getBindingUtil($);(N=K.onOperationComplete)==null||N.call(K)}}if(D.size){const q=D;D=new Map;for(const $ of q.values())(G=(z=this.getBindingUtil($.binding)).onAfterDelete)==null||G.call(z,$)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(j,N)=>{var z,G,q,$;for(const K of this.getBindingsInvolvingShape(N))V.add(K.type),K.fromId===N.id&&((G=(z=this.getBindingUtil(K)).onAfterChangeFromShape)==null||G.call(z,{binding:K,shapeBefore:j,shapeAfter:N})),K.toId===N.id&&(($=(q=this.getBindingUtil(K)).onAfterChangeToShape)==null||$.call(q,{binding:K,shapeBefore:j,shapeAfter:N}));if(j.parentId!==N.parentId){const K=J=>{var te,he,Pe,ue;const H=this.getShape(J);if(H)for(const Ae of this.getBindingsInvolvingShape(H))V.add(Ae.type),Ae.fromId===H.id&&((he=(te=this.getBindingUtil(Ae)).onAfterChangeFromShape)==null||he.call(te,{binding:Ae,shapeBefore:H,shapeAfter:H})),Ae.toId===H.id&&((ue=(Pe=this.getBindingUtil(Ae)).onAfterChangeToShape)==null||ue.call(Pe,{binding:Ae,shapeBefore:H,shapeAfter:H}))};K(N.id),this.visitDescendants(N.id,K)}if(j.parentId!==N.parentId&&Tr(N.parentId)){const K=new Set([j.id]);this.visitDescendants(j.id,J=>{K.add(J)});for(const J of this.getPageStates()){if(J.pageId===N.parentId)continue;const H=O(J,K);H&&this.store.put([H])}}j.parentId&&Ts(j.parentId)&&U.add(j.parentId),N.parentId!==j.parentId&&Ts(N.parentId)&&U.add(N.parentId)},beforeDelete:j=>{var q,$,K,J;if(F.has(j.id))return;j.parentId&&Ts(j.parentId)&&U.add(j.parentId),F.add(j.id);const N=[];for(const H of this.getBindingsInvolvingShape(j)){V.add(H.type),N.push(H.id);const te=this.getBindingUtil(H);H.fromId===j.id?((q=te.onBeforeIsolateToShape)==null||q.call(te,{binding:H,removedShape:j}),($=te.onBeforeDeleteFromShape)==null||$.call(te,{binding:H,shape:j})):((K=te.onBeforeIsolateFromShape)==null||K.call(te,{binding:H,removedShape:j}),(J=te.onBeforeDeleteToShape)==null||J.call(te,{binding:H,shape:j}))}N.length&&this.deleteBindings(N);const z=new Set([j.id]),G=st(this.getPageStates().map(H=>O(H,z)));G.length&&this.store.put(G)}},binding:{beforeCreate:j=>{var z,G;const N=(G=(z=this.getBindingUtil(j)).onBeforeCreate)==null?void 0:G.call(z,{binding:j});return N||j},afterCreate:j=>{var N,z;V.add(j.type),(z=(N=this.getBindingUtil(j)).onAfterCreate)==null||z.call(N,{binding:j})},beforeChange:(j,N)=>{var G,q;const z=(q=(G=this.getBindingUtil(N)).onBeforeChange)==null?void 0:q.call(G,{bindingBefore:j,bindingAfter:N});return z||N},afterChange:(j,N)=>{var z,G;V.add(N.type),(G=(z=this.getBindingUtil(N)).onAfterChange)==null||G.call(z,{bindingBefore:j,bindingAfter:N})},beforeDelete:j=>{var N,z;(z=(N=this.getBindingUtil(j)).onBeforeDelete)==null||z.call(N,{binding:j})},afterDelete:j=>{var N,z;(z=(N=this.getBindingUtil(j)).onAfterDelete)==null||z.call(N,{binding:j}),V.add(j.type)}},page:{afterCreate:j=>{const N=Vi.createId(j.id),z=ci.createId(j.id);this.store.has(N)||this.store.put([Vi.create({id:N})]),this.store.has(z)||this.store.put([ci.create({id:z,pageId:j.id})])},afterDelete:(j,N)=>{var q,$;if(((q=this.getInstanceState())==null?void 0:q.currentPageId)===j.id){const K=($=this.getPages().find(J=>J.id!==j.id))==null?void 0:$.id;K?this.store.put([{...this.getInstanceState(),currentPageId:K}]):N==="user"&&this.store.ensureStoreIsUsable()}const z=Vi.createId(j.id),G=ci.createId(j.id);this.store.remove([z,G])}},instance:{afterChange:(j,N,z)=>{var G;if(!this.store.has(N.currentPageId)){const q=this.store.has(j.currentPageId)?j.currentPageId:(G=this.getPages()[0])==null?void 0:G.id;q?this.store.update(N.id,$=>({...$,currentPageId:q})):z==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(j,N)=>{if((j==null?void 0:j.selectedShapeIds)!==(N==null?void 0:N.selectedShapeIds)){const z=N.selectedShapeIds.filter(q=>{var K,J;let $=(K=this.getShape(q))==null?void 0:K.parentId;for(;Ts($);){if(N.selectedShapeIds.includes($))return!1;$=(J=this.getShape($))==null?void 0:J.parentId}return!0});let G=null;if(z.length>0){const q=this.findCommonAncestor(st(z.map($=>this.getShape($))),$=>this.isShapeOfType($,"group"));q&&(G=q)}else N!=null&&N.focusedGroupId&&(G=N.focusedGroupId);(z.length!==N.selectedShapeIds.length||G!==N.focusedGroupId)&&this.store.put([{...N,selectedShapeIds:z,focusedGroupId:G??null}])}}}})),this._currentPageShapeIds=Qte(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=Jte(this.store),this.disposables.add(this.store.listen(j=>{this.emit("change",j)})),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 lne(this),this.focusManager=new cne(this,u),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 W3,(Y=this.store.props.collaboration)!=null&&Y.mode){const j=this.store.props.collaboration.mode;this.disposables.add(jo("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:j.get()==="readonly"}])}))}}getIsShapeHiddenCache(){return this._getShapeVisibility?this.store.createComputedCache("isShapeHidden",e=>{const t=this._getShapeVisibility(e,this);return(es.isId(e.parentId)?!1:this.isShapeHidden(e.parentId))?t!=="visible":t==="hidden"}):null}isShapeHidden(e){return this._getShapeVisibility?!!this.getIsShapeHiddenCache().get(typeof e=="string"?e:e.id):!1}dispose(){this.disposables.forEach(e=>e()),this.disposables.clear(),this.store.dispose(),this.isDisposed=!0}getShapeUtil(e){const t=typeof e=="string"?e:e.type,r=kn(this.shapeUtils,t);return Ve(r,`No shape util found for type "${t}"`),r}hasShapeUtil(e){const t=typeof e=="string"?e:e.type;return Do(this.shapeUtils,t)}getBindingUtil(e){const t=typeof e=="string"?e:e.type,r=kn(this.bindingUtils,t);return Ve(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??Mt()),this}markHistoryStoppingPoint(e){const t=`[${e??"stop"}]_${Mt()}`;return this.history._mark(t),t}getMarkIdMatching(e){return this.history.getMarkIdMatching(e)}squashToMark(e){return this.history.squashToMark(e),this}bail(){return this.history.bail(),this}bailToMark(e){return this.history.bailToMark(e),this}run(e,t){const r=this._shouldIgnoreShapeLock;this._shouldIgnoreShapeLock=(t==null?void 0:t.ignoreShapeLock)??r;try{this.history.batch(e,t)}finally{this._shouldIgnoreShapeLock=r}return this}batch(e,t){return this.run(e,t)}annotateError(e,{origin:t,willCrashApp:r,tags:s,extras:o}){const i=this.createErrorAnnotations(t,r);return uI(e,{tags:{...i.tags,...s},extras:{...i.extras,...o}}),r&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(e,t){try{const r=this.getEditingShapeId();return{tags:{origin:e,willCrashApp:t},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes().map(s=>{const{props:o,...i}=s,{text:a,richText:l,...c}=o;return{...i,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 o=r.getCurrent();if((o==null?void 0:o.id)===s){if(t.length===0)return!0;r=o;continue}else return!1}return!1}isInAny(...e){return e.some(t=>this.isIn(t))}setCurrentTool(e,t={}){return this.root.transition(e,t),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const e=this.getCurrentTool();return e?e.getCurrentToolIdMask()??e.id:""}getStateDescendant(e){var s;const t=e.split(".").reverse();let r=this.root;for(;t.length>0;){const o=t.pop();if(!o)return r;const i=(s=r.children)==null?void 0:s[o];if(!i)return;r=i}return r}getDocumentSettings(){return this.store.get(Mk)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(Yr)}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 ci.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(){return st(this.getSelectedShapeIds().map(e=>this.store.get(e)))}setSelectedShapes(e){return this.run(()=>{const t=e.map(o=>typeof o=="string"?o:o.id),{selectedShapeIds:r}=this.getCurrentPageState(),s=new Set(r);if(t.length===s.size&&t.every(o=>s.has(o)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:t}])},{history:"record-preserveRedoStack"})}isAncestorSelected(e){const t=typeof e=="string"?e:(e==null?void 0:e.id)??null,r=this.getShape(t);if(!r)return!1;const s=this.getSelectedShapeIds();return!!this.findShapeAncestor(r,o=>s.includes(o.id))}select(...e){const t=typeof e[0]=="string"?e:e.map(r=>r.id);return this.setSelectedShapes(t),this}deselect(...e){const t=typeof e[0]=="string"?e:e.map(s=>s.id),r=this.getSelectedShapeIds();return r.length>0&&t.length>0&&this.setSelectedShapes(r.filter(s=>!t.includes(s))),this}selectAll(){const e=this.getSortedChildIdsForParent(this.getCurrentPageId());return e.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(e)),this)}selectAdjacentShape(e){var c,u;const t=this.getSelectedShapeIds(),r=t[0]?(c=this.getShape(t[0]))==null?void 0:c.parentId:null,o=r&&t.every(h=>{var p;return((p=this.getShape(h))==null?void 0:p.parentId)===r})&&!Tr(r)?this._getShapesInReadingOrder(this.getCurrentPageShapes().filter(h=>h.parentId===r)):this.getCurrentPageShapesInReadingOrder(),i=t.length===1?t[0]:(u=o.find(h=>t.includes(h.id)))==null?void 0:u.id;let a;if(e==="next"||e==="prev"){const h=o.map(S=>S.id),m=((i?h.indexOf(i):-1)+(e==="next"?1:-1)+h.length)%h.length;a=h[m]}else{if(!i)return;a=this.getNearestAdjacentShape(i,e)}const l=this.getShape(a);l&&this._selectShapesAndZoom([l.id])}getCurrentPageShapesInReadingOrder(){const e=this.getCurrentPageShapes().filter(t=>Tr(t.parentId));return this._getShapesInReadingOrder(e)}_getShapesInReadingOrder(e){const s=e.filter(a=>this.getShapeUtil(a).canTabTo(a));if(s.length<=1)return s;const o=s.map(a=>({shape:a,center:this.getShapePageBounds(a).center}));o.sort((a,l)=>a.center.y-l.center.y);const i=[];for(const a of o){let l=-1;for(let c=i.length-1;c>=0;c--){const u=i[c],h=u[u.length-1];if(Math.abs(a.center.y-h.center.y)<100){l=c;break}}l===-1?i.push([a]):i[l].push(a)}for(const a of i)a.sort((l,c)=>l.center.x-c.center.x);for(const a of i)if(!(a.length<=2))for(let l=0;l<a.length-2;l++){const c=a[l],u=a[l+1],h=a[l+2],p=P.Dist2(c.center,u.center);P.Dist2(c.center,h.center)<p*.9&&Math.abs(P.Angle(c.center,h.center)*(180/Math.PI))<=20&&([a[l+1],a[l+2]]=[a[l+2],a[l+1]])}return i.flat().map(a=>a.shape)}getNearestAdjacentShape(e,t){const r={right:0,left:180,down:90,up:270},s=this.getShape(e);if(!s)return e;const i=this.getCurrentPageShapes().filter(h=>this.getShapeUtil(h).canTabTo(h)&&h.id!==e);if(!i.length)return e;const a=this.getShapePageBounds(s).center,c=i.map(h=>({shape:h,center:this.getShapePageBounds(h).center})).filter(({center:h})=>{const p=h.x>a.x,m=h.y>a.y,S=h.x-a.x,v=h.y-a.y,y=Math.abs(v)<Math.abs(S)*2,w=Math.abs(S)<Math.abs(v)*2;if(t==="left"||t==="right")return y&&(t==="right"?p:!p);if(t==="up"||t==="down")return w&&(t==="down"?m:!m)});return c.length===0?e:V3(c,({center:h})=>{const p=P.Dist2(a,h),m=["left","right"].includes(t)?"x":"y",S=Math.abs(h[m]-a[m]),v=["left","right"].includes(t)?"y":"x",y=Math.abs(h[v]-a[v]),w=Math.abs(P.Angle(a,h)*(180/Math.PI)),C=Math.abs(w-r[t]);return p*1+y*2+(p-S)*1.5+C*.5}).shape.id}selectParentShape(){const e=this.getOnlySelectedShape();if(!e)return;const t=this.getShape(e.parentId);t&&this._selectShapesAndZoom([t.id])}selectFirstChildShape(){const e=this.getSelectedShapes();if(!e.length)return;const t=e[0],r=this.getSortedChildIdsForParent(t.id).map(o=>this.getShape(o)).filter(o=>o),s=this._getShapesInReadingOrder(r);s.length!==0&&this._selectShapesAndZoom([s[0].id])}_selectShapesAndZoom(e){this.setSelectedShapes(e),this.zoomToSelectionIfOffscreen(256,{animation:{duration:this.options.animationMediumMs},inset:0})}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var e;return((e=this.getOnlySelectedShape())==null?void 0:e.id)??null}getOnlySelectedShape(){const e=this.getSelectedShapes();return e.length===1?e[0]:null}getShapesPageBounds(e){const t=st(e.map(r=>this.getShapePageBounds(r)));return t.length===0?null:ye.Common(t)}getSelectionPageBounds(){return this.getShapesPageBounds(this.getSelectedShapeIds())}getShapesSharedRotation(e){let t=!1,r=0;for(let s=0,o=e.length;s<o;s++){const i=this.getShapePageTransform(e[s]);if(i)if(t){if(i.rotation()!==r)return 0}else t=!0,r=i.rotation()}return r}getSelectionRotation(){return this.getShapesSharedRotation(this.getSelectedShapeIds())}getShapesRotatedPageBounds(e){if(e.length===0)return;const t=this.getShapesSharedRotation(e);if(t===0)return this.getShapesPageBounds(e)??void 0;if(e.length===1){const s=this.getShapeGeometry(e[0]).bounds.clone(),o=this.getShapePageTransform(e[0]);return s.point=o.applyToPoint(s.point),s}const r=ye.FromPoints(e.flatMap(s=>{const o=this.getShapePageTransform(s);return o?o.applyToPoints(this.getShapeGeometry(s).bounds.corners):[]}).map(s=>s.rot(-t)));return r.point=r.point.rot(t),r}getSelectionRotatedPageBounds(){return this.getShapesRotatedPageBounds(this.getSelectedShapeIds())}getSelectionRotatedScreenBounds(){const e=this.getSelectionRotatedPageBounds();if(!e)return;const{x:t,y:r}=this.pageToScreen(e.point),s=this.getZoomLevel();return new 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;this.setRichTextEditor(null);const r=this.getEditingShapeId();if(t!==r){if(t){const s=this.getShape(t);if(s&&this.getShapeUtil(s).canEdit(s))return this.run(()=>{var o,i,a,l;if(this._updateCurrentPageState({editingShapeId:t}),r){const c=this.getShape(r);c&&((i=(o=this.getShapeUtil(c)).onEditEnd)==null||i.call(o,c))}(l=(a=this.getShapeUtil(s)).onEditStart)==null||l.call(a,s)},{history:"ignore"}),this}this.run(()=>{var s,o;if(this._updateCurrentPageState({editingShapeId:null}),this._currentRichTextEditor.set(null),r){const i=this.getShape(r);i&&((o=(s=this.getShapeUtil(i)).onEditEnd)==null||o.call(s,i))}},{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 st(e.map(t=>this.getShape(t)))}setHintingShapes(e){const t=typeof e[0]=="string"?e:e.map(r=>r.id);return this.run(()=>{this._updateCurrentPageState({hintingShapeIds:cI(t)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return st(e.map(t=>this.getShape(t)))}setErasingShapes(e){const t=typeof e[0]=="string"?e:e.map(s=>s.id);t.sort();const r=this.getErasingShapeIds();return this.run(()=>{if(t.length===r.length){for(let s=0;s<t.length;s++)if(t[s]!==r[s]){this._updateCurrentPageState({erasingShapeIds:t});break}}else this._updateCurrentPageState({erasingShapeIds:t})},{history:"ignore"}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(e){const t=typeof e=="string"?e:(e==null?void 0:e.id)??null;return t!==this.getCroppingShapeId()&&this.run(()=>{if(!t)this.updateCurrentPageState({croppingShapeId:null});else{const r=this.getShape(t),s=this.getShapeUtil(r);r&&s.canCrop(r)&&this.updateCurrentPageState({croppingShapeId:t})}},{history:"ignore"}),this}getTextOptions(){return qr(this._textOptions.get(),"Cannot use text without setting textOptions")}_unsafe_getCameraId(){return Vi.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}_getFollowingPresence(e){const t=[this.user.getId()],r=this.getCollaborators();let s=null;for(;e&&!t.includes(e);)s=r.find(o=>o.userId===e)??null,e=(s==null?void 0:s.followingUserId)??null,s&&t.push(s.userId);return s}getViewportPageBoundsForFollowing(){const e=this._getFollowingPresence(this.getInstanceState().followingUserId);if(!(e!=null&&e.camera)||!(e!=null&&e.screenBounds))return null;const{w:t,h:r}=e.screenBounds,{x:s,y:o,z:i}=e.camera,a=new ye(-s,-o,t/i,r/i),l=this.getViewportScreenBounds().clone(),c=l.width/l.height;return l.width=a.width,l.height=l.width/c,l.height<a.height&&(l.height=a.height,l.width=l.height*c),l.center=a.center,l}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}=Dj(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 xt(e.constraints.initialZoom)}}getBaseZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.baseZoom==="default")return 1;const{zx:t,zy:r}=Dj(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 xt(e.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(e){var r;const t=en({...this._cameraOptions.__unsafe__getWithoutCapture(),...e});return((r=t.zoomSteps)==null?void 0:r.length)<1&&(t.zoomSteps=[1]),this._cameraOptions.set(t),this.setCamera(this.getCamera()),this}getConstrainedCamera(e,t){const r=this.getCamera();let{x:s,y:o,z:i=r.z}=e;if(!(t!=null&&t.force)){const a=this.getCameraOptions(),l=a.zoomSteps[0],c=cr(a.zoomSteps),u=this.getViewportScreenBounds();if(a.constraints){const{constraints:h}=a,p=Math.min(h.padding.y,u.w/2),m=Math.min(h.padding.x,u.h/2),S=ye.From(a.constraints.bounds),v=(u.w-m*2)/S.w,y=(u.h-p*2)/S.h,w=this.getBaseZoom(),C=c*w,T=l*w;if(t!=null&&t.reset&&(i=this.getInitialZoom()),i<T||i>C){const{x:Y,y:j,z:N}=r,z=-Y+u.w/N/2,G=-j+u.h/N/2;i=$t(i,T,C);const q=-Y+u.w/i/2,$=-j+u.h/i/2;s=Y+q-z,o=j+$-G}const E=m/i-S.x,_=p/i-S.y,A=(u.w-m*2)/i-S.w,O=(u.h-p*2)/i-S.h,D=E+A*h.origin.x,F=_+O*h.origin.y,U=typeof h.behavior=="string"?h.behavior:h.behavior.x,V=typeof h.behavior=="string"?h.behavior:h.behavior.y;if(t!=null&&t.reset)s=D,o=F;else{switch(U){case"fixed":{s=D;break}case"contain":{i<v?s=D:s=$t(s,E+A,E);break}case"inside":{i<v?s=$t(s,E,(u.w-m)/i-S.w):s=$t(s,E+A,E);break}case"outside":{s=$t(s,m/i-S.w,(u.w-m)/i);break}case"free":break;default:throw xt(U)}switch(V){case"fixed":{o=F;break}case"contain":{i<y?o=F:o=$t(o,_+O,_);break}case"inside":{i<y?o=$t(o,_,(u.h-p)/i-S.h):o=$t(o,_+O,_);break}case"outside":{o=$t(o,p/i-S.h,(u.h-p)/i);break}case"free":break;default:throw xt(V)}}}else if(i>c||i<l){const{x:h,y:p,z:m}=r;i=$t(i,l,c),s=h+(-h+u.w/i/2)-(-h+u.w/m/2),o=p+(-p+u.h/i/2)-(-p+u.h/m/2)}}return{x:s,y:o,z:i}}_setCamera(e,t){const r=this.getCamera(),{x:s,y:o,z:i}=this.getConstrainedCamera(e,t);return r.x===s&&r.y===o&&r.z===i?this:(to(()=>{const a={...r,x:s,y:o,z:i};this.run(()=>{this.store.put([a])},{history:"ignore"});const{currentScreenPoint:l,currentPagePoint:c}=this.inputs,{screenBounds:u}=this.store.unsafeGetWithoutCapture(Yr);if(l.x/i-s!==c.x||l.y/i-o!==c.y){const h={type:"pointer",target:"canvas",name:"pointer_move",point:P.AddXY(l,u.x,u.y),pointerId:XD.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(h):this.dispatch(h)}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=P.Cast(e);Number.isFinite(s.x)||(s.x=0),Number.isFinite(s.y)||(s.y=0),(s.z===void 0||!Number.isFinite(s.z))&&(e.z=this.getZoomLevel());const o=this.getConstrainedCamera(s,t);if(t!=null&&t.animation){const{width:i,height:a}=this.getViewportScreenBounds();this._animateToViewport(new ye(-o.x,-o.y,i/o.z,a/o.z),t)}else this._setCamera(o,{...t,force:!0});return this}centerOnPoint(e,t){const{isLocked:r}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const{width:s,height:o}=this.getViewportPageBounds();return this.setCamera(new P(-(e.x-s/2),-(e.y-o/2),this.getCamera().z),t),this}zoomToFit(e){const t=[...this.getCurrentPageShapeIds()];if(t.length<=0)return this;const r=ye.Common(st(t.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(r,e),this}resetZoom(e=this.getViewportScreenCenter(),t){const{isLocked:r,constraints:s}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const o=this.getCamera(),{x:i,y:a,z:l}=o,{x:c,y:u}=e;let h=1;if(s){const p=this.getInitialZoom();l!==p&&(h=p)}return this.setCamera(new P(i+(c/h-c)-(c/l-c),a+(u/h-u)-(u/l-u),h),t),this}zoomIn(e=this.getViewportScreenCenter(),t){const{isLocked:r}=this.getCameraOptions();if(r&&!(t!=null&&t.force))return this;const{x:s,y:o,z:i}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const l=this.getBaseZoom();let c=cr(a)*l;for(let u=1;u<a.length;u++){const h=a[u-1]*l,p=a[u]*l;if(!(p-i<=(p-h)/2)){c=p;break}}this.setCamera(new P(s+(e.x/c-e.x)-(e.x/i-e.x),o+(e.y/c-e.y)-(e.y/i-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 o=this.getBaseZoom(),{x:i,y:a,z:l}=this.getCamera();let c=s[0]*o;for(let u=s.length-1;u>0;u--){const h=s[u-1]*o,p=s[u]*o;if(!(p-l>=(p-h)/2)){c=h;break}}this.setCamera(new P(i+(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}zoomToSelectionIfOffscreen(e=16,t){const r=this.getSelectionPageBounds(),s=this.getViewportPageBounds();if(r&&!s.contains(r)){const o=r.clone().expandBy(e/this.getZoomLevel()).expand(s),i=s.clone().translate({x:(o.center.x-s.center.x)*2,y:(o.center.y-s.center.y)*2});this.zoomToBounds(i,t)}}zoomToBounds(e,t){const r=this._cameraOptions.__unsafe__getWithoutCapture();if(r.isLocked&&!(t!=null&&t.force))return this;const s=this.getViewportScreenBounds(),o=(t==null?void 0:t.inset)??Math.min(lJ,s.width*.28),i=this.getBaseZoom(),a=r.zoomSteps[0],l=cr(r.zoomSteps);let c=$t(Math.min((s.width-o)/e.w,(s.height-o)/e.h),a*i,l*i);return(t==null?void 0:t.targetZoom)!==void 0&&(c=Math.min(t.targetZoom,c)),this.setCamera(new P(-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:o,end:i}=this._viewportAnimation;if(t>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new P(-i.x,-i.y,this.getViewportScreenBounds().width/i.width));return}const a=s-t,l=r(1-a/s),c=o.minX+(i.minX-o.minX)*l,u=o.minY+(i.minY-o.minY)*l,h=o.maxX+(i.maxX-o.maxX)*l;this._setCamera(new P(-c,-u,this.getViewportScreenBounds().width/(h-c)),{force:!0})}_animateToViewport(e,t={animation:jC}){const{animation:r,...s}=t;if(!r)return;const{duration:o=0,easing:i=qn.easeInOutCubic}=r,a=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),o===0||a===0?this._setCamera(new P(-e.x,-e.y,this.getViewportScreenBounds().width/e.width),{...s}):(this._viewportAnimation={elapsed:0,duration:o/a,easing:i,start:l.clone(),end:e.clone()},this.once("stop-camera-animation",()=>{this.off("tick",this._animateViewport),this._viewportAnimation=null}),this.on("tick",this._animateViewport),this)}slideCamera(e={}){const{isLocked:t}=this.getCameraOptions();if(t&&!(e!=null&&e.force))return this;if(this.user.getAnimationSpeed()===0)return this;this.stopCameraAnimation();const{speed:s,friction:o=this.options.cameraSlideFriction,direction:i,speedThreshold:a=.01}=e;let l=Math.min(s,1);const c=()=>{this.off("tick",u),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=h=>{const{x:p,y:m,z:S}=this.getCamera(),v=P.Mul(i,l*h/S);l*=1-o,l<a?c():this._setCamera(new P(p+v.x,m+v.y,S))};return this.on("tick",u),this}zoomToUser(e,t={animation:{duration:500}}){const r=this.getCollaborators().find(o=>o.userId===e);if(!r)return this;const s=r.cursor;return s?(this.run(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const o=r.currentPageId===this.getCurrentPageId();o||this.setCurrentPage(r.currentPageId),t&&t.animation&&!o&&(t.animation=void 0),this.centerOnPoint(s,t);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,e]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],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,!ro(document.body.scrollWidth,e.maxX,1),!ro(document.body.scrollHeight,e.maxY,1),e.minX!==0],{_willSetInitialBounds:s}=this;this._willSetInitialBounds=!1;const{screenBounds:o,insets:i}=this.getInstanceState();if(e.equals(o)&&r.every((a,l)=>a===i[l]))return this;if(s)this.updateInstanceState({screenBounds:e.toJson(),insets:r}),this.setCamera(this.getCamera());else if(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(P.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 P(e.midX-e.minX,e.midY-e.minY)}getViewportPageBounds(){const{w:e,h:t}=this.getViewportScreenBounds(),{x:r,y:s,z:o}=this.getCamera();return new ye(-r,-s,e/o,t/o)}screenToPage(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(Yr),{x:r,y:s,z:o=1}=this.getCamera();return new P((e.x-t.x)/o-r,(e.y-t.y)/o-s,e.z??.5)}pageToScreen(e){const{screenBounds:t}=this.store.unsafeGetWithoutCapture(Yr),{x:r,y:s,z:o=1}=this.getCamera();return new P((e.x+r)*o+t.x,(e.y+s)*o+t.y,e.z??.5)}pageToViewport(e){const{x:t,y:r,z:s=1}=this.getCamera();return new P((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=>VG(e.filter(o=>o.userId===r),o=>o.lastActivityTimestamp??0)):jr}getCollaboratorsOnCurrentPage(){const e=this.getCurrentPageId();return this.getCollaborators().filter(t=>t.currentPageId===e)}startFollowingUser(e){if(this.stopFollowingUser(),this.user.getId()||console.warn("You should set the userId for the current instance before following a user"),!this._getFollowingPresence(e))return this;const s=le("latestLeaderPresence",()=>this._getFollowingPresence(e));return to(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const o=jo("update current page",()=>{const l=s.get();if(!l){this.stopFollowingUser();return}l.currentPageId!==this.getCurrentPageId()&&this.getPage(l.currentPageId)&&this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:l.currentPageId}]),this._isLockedOnFollowingUser.set(!0)},{history:"ignore"})}),i=()=>{o(),this._isLockedOnFollowingUser.set(!1),this.off("frame",a),this.off("stop-following",i)},a=()=>{if(!s.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const c=this.user.getAnimationSpeed();if(c===0){this._isLockedOnFollowingUser.set(!0);return}const u=this.getViewportPageBoundsForFollowing();if(!u){this.stopFollowingUser();return}const h=this.getViewportPageBounds(),p=Math.abs(u.minX-h.minX)+Math.abs(u.maxX-h.maxX),m=Math.abs(u.minY-h.minY)+Math.abs(u.maxY-h.maxY);if(p<this.options.followChaseViewportSnap&&m<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const S=$t(c*.5,.1,.8),v=new ye(rt(h.minX,u.minX,S),rt(h.minY,u.minY,S),rt(h.width,u.width,S),rt(h.height,u.height,S)),y=new P(-v.x,-v.y,this.getViewportScreenBounds().width/v.width);this.stopCameraAnimation(),this._setCamera(y)};this.once("stop-following",i),this.addListener("frame",a),a()}),this}stopFollowingUser(){return this.run(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")},{history:"ignore"}),this}getUnorderedRenderingShapes(e){const t=[];let r=this.options.maxShapesPerPage*2,s=this.options.maxShapesPerPage;const o=this.getErasingShapeIds(),i=(l,c,u)=>{const h=this.getShape(l);if(!h)return;if(this.isShapeHidden(h)){const y=u||o.includes(l);for(const w of this.getSortedChildIdsForParent(l))i(w,c,y);return}c*=h.opacity;let p=!1;const m=this.getShapeUtil(h);e&&(p=!u&&o.includes(l),p&&(c*=.32)),t.push({id:l,shape:h,util:m,index:r,backgroundIndex:s,opacity:c}),r+=1,s+=1;const S=this.getSortedChildIdsForParent(l);if(!S.length)return;let v=null;m.providesBackgroundForChildren(h)&&(v=s,s=r,r+=this.options.maxShapesPerPage);for(const y of S)i(y,c,u||p);v!==null&&(s=v)},a=e?[this.getCurrentPage()]:this.getPages();for(const l of a)for(const c of this.getSortedChildIdsForParent(l.id))i(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(Pq)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return Array.from(this._getAllPagesQuery().get()).sort(ur)}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=Kte(e.name??"Page 1",t.map(i=>i.name));let s=e.index;(!s||t.some(i=>i.index===s))&&(s=Wi(t[t.length-1].index));const o=es.create({meta:{},...e,name:r,index:s});this.store.put([o])}),this}deletePage(e){const t=typeof e=="string"?e:e.id;return this.run(()=>{if(this.getIsReadonly())return;const r=this.getPages();if(r.length===1)return;const s=this.getPage(t);if(s){if(t===this.getCurrentPageId()){const o=r.findIndex(a=>a.id===t),i=r[o-1]??r[o+1];this.setCurrentPage(i.id)}this.store.remove([s.id])}}),this}duplicatePage(e,t=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 o={...this.getCamera()},i=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.run(()=>{var c;const a=this.getPages(),l=Rp(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(o),i)return this.putContentOntoCurrentPage(i)}),this}renamePage(e,t){const r=typeof e=="string"?e:e.id;return this.getIsReadonly()?this:(this.updatePage({id:r,name:t}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(e){return this.getIsReadonly()?this:e.length<=0?this:(this.run(()=>this.store.put(e),{history:"ignore"}),this)}updateAssets(e){return this.getIsReadonly()?this:e.length<=0?this:(this.run(()=>{this.store.put(e.map(t=>({...this.store.get(t.id),...t})))},{history:"ignore"}),this)}deleteAssets(e){if(this.getIsReadonly())return this;const t=typeof e[0]=="string"?e:e.map(r=>r.id);return t.length<=0?this:(this.run(()=>{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:o=!1,dpr:i=this.getInstanceState().devicePixelRatio}=t,l=(u=>Math.pow(2,Math.ceil(Math.log2(u))))(s),c="connection"in navigator?navigator.connection.effectiveType:null;return await this.store.props.assets.resolve(r,{screenScale:s||1,steppedScreenScale:l,dpr:i,networkEffectiveType:c,shouldResolveToOriginal:o})}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:jk})),this._shapeGeometryCaches[r].get(typeof e=="string"?e:e.id)}getShapePageGeometry(e,t){const r=(t==null?void 0:t.context)??"none";return this._shapePageGeometryCaches[r]||(this._shapePageGeometryCaches[r]=this.store.createComputedCache("bounds",s=>{const o=this.getShapeGeometry(s.id,t),i=this.getShapePageTransform(s.id);return o.transform(i)},{areRecordsEqual:()=>!0})),this._shapePageGeometryCaches[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)},{areRecordsEqual:jk})}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 de.Identity().translate(r.x,r.y).rotate(r.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if(Tr(e.parentId))return this.getShapeLocalTransform(e);const t=this._getShapePageTransformCache().get(e.parentId)??de.Identity();return de.Compose(t,this.getShapeLocalTransform(e))})}getShapeParentTransform(e){const t=typeof e=="string"?e:e.id,r=this.getShape(t);return!r||Tr(r.parentId)?de.Identity():this._getShapePageTransformCache().get(r.parentId)??de.Identity()}getShapePageTransform(e){const t=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(t)??de.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",e=>this.getShapePageGeometry(e).bounds)}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(${de.applyToPoints(de.Inverse(r),t).map(o=>`${o.x}px ${o.y}px`).join(",")})`:void 0})}getShapeClipPath(e){return this._getShapeClipPathCache().get(typeof e=="string"?e:e.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",e=>{if(Tr(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.getShapePageGeometry(s.id).vertices).reduce((s,o)=>{if(!(o&&s))return;const i=dj(s,o);return i?i.map(P.Cast):[]})})}getShapeMask(e){return this._getShapeMaskCache().get(typeof e=="string"?e:e.id)}getShapeMaskedPageBounds(e){return typeof e!="string"&&(e=e.id),this._getShapeMaskedPageBoundsCache().get(e)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",e=>{const t=this._getShapePageBoundsCache().get(e.id);if(!t)return;const r=this._getShapeMaskCache().get(e.id);if(r){if(r.length===0)return;const{corners:s}=t;if(s.every((i,a)=>i&&P.Equals(i,r[a])))return t.clone();const o=dj(r,s);return o?ye.FromPoints(o):void 0}return t})}getShapeAncestors(e,t=[]){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return t;const o=s.parentId;if(Tr(o))return t.reverse(),t;const i=this.store.get(o);return i?(t.push(i),this.getShapeAncestors(i,t)):t}findShapeAncestor(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return;const o=s.parentId;if(Tr(o))return;const i=this.getShape(o);if(i)return t(i)?i:this.findShapeAncestor(i,t)}hasAncestor(e,t){const r=typeof e=="string"?e:e==null?void 0:e.id,s=r&&this.getShape(r);return s?s.parentId===t?!0:this.hasAncestor(this.getShapeParent(s),t):!1}findCommonAncestor(e,t){var l;if(e.length===0)return;const r=typeof e[0]=="string"?e:e.map(c=>c.id),s=st(r.map(c=>this.getShape(c)));if(s.length===1){const c=s[0].parentId;return Tr(c)?void 0:t?(l=this.findShapeAncestor(s[0],t))==null?void 0:l.id:c}const[o,...i]=s;let a=this.getShapeParent(o);for(;a;){if(t&&!t(a)){a=this.getShapeParent(a);continue}if(i.every(c=>this.hasAncestor(c,a.id)))return a.id;a=this.getShapeParent(a)}}isShapeOrAncestorLocked(e){const t=typeof e=="string"?this.getShape(e):e;return t===void 0?!1:t.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(t))}_notVisibleShapes(){return Zte(this)}getCulledShapes(){const e=this._notVisibleShapes().get(),t=this.getSelectedShapeIds(),r=this.getEditingShapeId(),s=new Set(e);return r&&s.delete(r),t.forEach(o=>{s.delete(o)}),s}getCurrentPageBounds(){let e;return this.getCurrentPageShapeIdsSorted().forEach(t=>{const r=this.getShapeMaskedPageBounds(t);r&&(e?e=e.expand(r):e=r.clone())}),e}getSelectedShapeAtPoint(e){const t=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(r=>r.type!=="group"&&t.includes(r.id)).reverse().find(r=>this.isPointInShape(r,e,{hitInside:!0,margin:0}))}getShapeAtPoint(e,t={}){var y;const r=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:o,margin:i=0,hitLocked:a=!1,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:u=!1}=t;let h=1/0,p=null,m=1/0,S=null;const v=(t.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(w=>{if(w.isLocked&&!a||this.isShapeHidden(w)||this.isShapeOfType(w,"group"))return!1;const C=this.getShapeMask(w);return C&&!so(e,C)?!1:o?o(w):!0});for(let w=v.length-1;w>=0;w--){const C=v[w],T=this.getShapeGeometry(C),E=T instanceof ds,_=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")&&((y=this.getShapeUtil(C).getText(C))!=null&&y.trim())){for(const O of T.children)if(O.isLabel&&O.isPointInBounds(_))return C}if(this.isShapeOfType(C,"frame")){const O=T.distanceToPoint(_,c);if(Math.abs(O)<=i)return S||C;if(T.hitTestPoint(_,0,!0))return S||p||(u?C:void 0);continue}let A;if(E){let O=1/0;for(const D of T.children){if(D.isLabel&&!l)continue;const F=D.distanceToPoint(_,c);F<O&&(O=F)}A=O}else i===0&&(T.bounds.w<1||T.bounds.h<1)||T.bounds.containsPoint(_,i)?A=T.distanceToPoint(_,c):A=1/0;if(T.isClosed){if(A<=i){if(T.isFilled||E&&T.children[0].isFilled)return S||C;if(this.getShapePageBounds(C).contains(s))continue;if(Math.abs(A)<i)Math.abs(A)<m&&(m=Math.abs(A),S=C);else if(!S){const{area:O}=T;O<h&&(h=O,p=C)}}}else if(A<this.options.hitTestMargin/r)return C}return S||p||void 0}getShapesAtPoint(e,t={}){return this.getCurrentPageShapes().filter(r=>!this.isShapeHidden(r)&&this.isPointInShape(r,e,t))}isPointInShape(e,t,r={}){const{hitInside:s=!1,margin:o=0}=r,i=typeof e=="string"?e:e.id,a=this.getShapeMask(i);return a&&!so(t,a)?!1:this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(e,t),o,s)}getPointInShapeSpace(e,t){const r=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(r).clone().invert().applyToPoint(t)}getPointInParentSpace(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return new P(0,0);if(Tr(s.parentId))return P.From(t);const o=this.getShapePageTransform(s.parentId);return o?o.clone().invert().applyToPoint(t):P.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++)F$(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(Ts(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||!Ts(r.parentId)))return this.store.get(r.parentId)}getShapeNearestSibling(e,t){return t?t.parentId===e.parentId?t:this.findShapeAncestor(t,s=>s.parentId===e.parentId):void 0}isShapeInPage(e,t=this.getCurrentPageId()){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return!1;let o=!1;if(s.parentId===t)o=!0;else{let i=this.getShape(s.parentId);e:for(;i;){if(i.parentId===t){o=!0;break e}i=this.getShape(i.parentId)}}return o}getAncestorPageId(e){const t=typeof e=="string"?e:e==null?void 0:e.id,r=t&&this.getShape(t);if(r)return Tr(r.parentId)?r.parentId:this.getAncestorPageId(this.getShape(r.parentId))}reparentShapes(e,t,r){const s=typeof e[0]=="string"?e:e.map(p=>p.id);if(s.length===0)return this;const o=[],i=Tr(t)?de.Identity():this.getShapePageTransform(t),a=i.rotation();let l=[];const c=st(this.getSortedChildIdsForParent(t).map(p=>this.getShape(p)));if(r){const p=c.find(m=>m.index===r);if(p){const m=c[c.indexOf(p)+1];m?l=oh(r,m.index,s.length):l=Ib(r,s.length)}else{const m=c.sort(ur).find(S=>S.index>r);m?l=oh(r,m.index,s.length):l=Ib(r,s.length)}}else{const p=c.length&&c[c.length-1];l=p?Ib(p.index,s.length):Dp(s.length)}const u=i.clone().invert(),h=st(s.map(p=>this.getShape(p))).sort(ur);return this.run(()=>{for(let p=0;p<h.length;p++){const m=h[p],S=this.getShapePageTransform(m);if(!S)continue;const v=S.point();if(!v)continue;const y=u.applyToPoint(v),w=S.rotation()-a;o.push({id:m.id,type:m.type,parentId:t,x:y.x,y:y.y,rotation:w,index:l[p]})}this.updateShapes(o)},{ignoreShapeLock:!0}),this}getHighestIndexForParent(e){const t=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[t];if(!r||r.length===0)return"a1";const s=this.getShape(r[r.length-1]);return Wi(s.index)}getSortedChildIdsForParent(e){const t=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[t];return r||jr}visitDescendants(e,t){const r=typeof e=="string"?e:e.id,s=this.getSortedChildIdsForParent(r);for(const o of s)t(o)!==!1&&this.visitDescendants(o,t);return this}getShapeAndDescendantIds(e){const t=new Set;for(const r of e.map(s=>this.getShape(s)).sort(ur))t.add(r.id),this.visitDescendants(r,s=>{t.add(s)});return t}getDroppingOverShape(e,t=[]){const r=this.getCurrentPageShapesSorted();for(let s=r.length-1;s>=0;s--){const o=r[s];if(this.isShapeHidden(o)||this.getSelectedShapeIds().includes(o.id)||!this.getShapeUtil(o).canDropShapes(o,t)||t.find(a=>a.id===o.id||this.hasAncestor(o,a.id)))continue;const i=this.getShapeMaskedPageBounds(o.id);if(i&&i.containsPoint(e)&&this.getShapeGeometry(o).hitTestPoint(this.getPointInShapeSpace(o,e),0,!0))return o}}getOutermostSelectableShape(e,t){const r=typeof e=="string"?e:e.id,s=this.getShape(r);let o=s,i=s;const a=this.getFocusedGroup();for(;i;){if(this.isShapeOfType(i,"group")&&(a==null?void 0:a.id)!==i.id&&!this.hasAncestor(a,i.id)&&((t==null?void 0:t(i))??!0))o=i;else if((a==null?void 0:a.id)===i.id)break;i=this.getShapeParent(i)}return o}_getBindingsIndexCache(){const e=Yte(this);return this.store.createComputedCache("bindingsIndex",t=>e.get().get(t.id),{areRecordsEqual:()=>!0})}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)??jr;return t?s.filter(o=>o.type===t):s}createBindings(e){const t=[];for(const r of e){const s=this.getShape(r.fromId),o=this.getShape(r.toId);if(!s||!o||!this.canBindShapes({fromShape:s,toShape:o,binding:r}))continue;const a=this.getBindingUtil(r.type).getDefaultProps(),l=this.store.schema.types.binding.create({...r,id:r.id??su(),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 o=Li(s,r);if(o===s)continue;const i=this.getShape(o.fromId),a=this.getShape(o.toId);!i||!a||this.canBindShapes({fromShape:i,toShape:a,binding:o})&&t.push(o)}return this.store.put(t),this}updateBinding(e){return this.updateBindings([e])}deleteBindings(e,{isolateShapes:t=!1}={}){const r=e.map(s=>typeof s=="string"?s:s.id);return t?this.store.atomic(()=>{var s,o;for(const i of r){const a=this.getBinding(i);if(!a)continue;const l=this.getBindingUtil(a);(s=l.onBeforeIsolateFromShape)==null||s.call(l,{binding:a,removedShape:this.getShape(a.toId)}),(o=l.onBeforeIsolateToShape)==null||o.call(l,{binding:a,removedShape:this.getShape(a.fromId)}),this.store.remove([i])}}):this.store.remove(r),this}deleteBinding(e,t){return this.deleteBindings([e],t)}canBindShapes({fromShape:e,toShape:t,binding:r}){const s=typeof e=="string"?e:e.type,o=typeof t=="string"?t:t.type,i=typeof r=="string"?r:r.type,a={fromShapeType:s,toShapeType:o,bindingType:i};return s===o?this.getShapeUtil(s).canBind(a):this.getShapeUtil(s).canBind(a)&&this.getShapeUtil(o).canBind(a)}rotateShapesBy(e,t,r){const s=typeof e[0]=="string"?e:e.map(i=>i.id);if(s.length<=0)return this;const o=uz({editor:this,ids:s});return o?(Xy({delta:t,snapshot:o,editor:this,stage:"one-off",centerOverride:r==null?void 0:r.center}),this):this}getChangesToTranslateShape(e,t){var l,c,u;let r=e;const s=this.getShapeUtil(e),o=(l=s.onTranslateStart)==null?void 0:l.call(s,r);o&&(r=Li(r,o)),r=Li(r,{id:e.id,type:e.type,x:t.x,y:t.y});const i=(c=s.onTranslate)==null?void 0:c.call(s,e,r);i&&(r=Li(r,i));const a=(u=s.onTranslateEnd)==null?void 0:u.call(s,e,r);return a&&(r=Li(r,a)),r}nudgeShapes(e,t){const r=typeof e[0]=="string"?e:e.map(o=>o.id);if(r.length<=0)return this;const s=[];for(const o of r){const i=this.getShape(o),a=P.From(t),l=this.getShapeParentTransform(i);l&&a.rot(-l.rotation()),s.push(this.getChangesToTranslateShape(i,a.add(i)))}return this.updateShapes(s),this}duplicateShapes(e,t){return this.run(()=>{const r=typeof e[0]=="string"?e:e.map(p=>p.id);if(r.length<=0)return this;const s=new Set(r),o=this.getShapeAndDescendantIds(r),i=[...o].reverse(),a=new Map;for(const p of o)a.set(p,Nt());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=Rj(this,o,p=>{const m=[];for(const v of p){const y=this.getBinding(v);if(!y)continue;const w=su();m.push({...y,id:w,fromId:qr(a.get(y.fromId)),toId:qr(a.get(y.toId))})}const S=[];for(const v of i){const y=qr(a.get(v)),w=this.getShape(v);if(!w)continue;let C=0,T=0;if(t&&s.has(v)){const E=this.getShapeParentTransform(w),_=new P(t.x,t.y).rot(-E.rotation());C=_.x,T=_.y}S.push({shape:{...w,id:y,x:w.x+C,y:w.y+T,index:"a1",parentId:a.get(w.parentId)??w.parentId},originalShape:w})}return{shapesToCreateWithOriginals:S,bindingsToCreate:m}});l.forEach(({shape:p,originalShape:m})=>{const S=m.parentId,v=this.getSortedChildIdsForParent(S),y=v.indexOf(m.id),w=v[y+1],C=w?this.getShape(w):void 0,T=Rp(m.index,C==null?void 0:C.index);p.index=T});const u=l.map(({shape:p})=>p);if(u.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){iy(this);return}if(this.createShapes(u),this.createBindings(c),this.setSelectedShapes(st(r.map(p=>a.get(p)))),t!==void 0){const p=this.getSelectionPageBounds(),m=this.getViewportPageBounds();p&&!m.contains(p)&&this.centerOnPoint(p.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(e,t){const r=typeof e[0]=="string"?e:e.map(a=>a.id);if(r.length===0)return this;if(this.getIsReadonly())return this;const s=this.getCurrentPageId();if(t===s)return this;if(!this.store.has(t))return this;const o=this.getContentFromCurrentPage(r);if(!o)return this;if(this.getPageShapeIds(t).size+o.shapes.length>this.options.maxShapesPerPage)return iy(this,t),this;const i=this.getCamera().z;return this.run(()=>{this.deleteShapes(r),this.setCurrentPage(t),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(o,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:i}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(e){const t=typeof e[0]=="string"?e:e.map(i=>i.id);if(this.getIsReadonly()||t.length===0)return this;let r=!0,s=!0;const o=[];for(const i of t){const a=this.getShape(i);a&&(o.push(a),a.isLocked?s=!1:r=!1)}return this.run(()=>{s?(this.updateShapes(o.map(i=>({id:i.id,type:i.type,isLocked:!0}))),this.setSelectedShapes([])):r?this.updateShapes(o.map(i=>({id:i.id,type:i.type,isLocked:!1}))):this.updateShapes(o.map(i=>({id:i.id,type:i.type,isLocked:!0})))}),this}sendToBack(e){const t=typeof e[0]=="string"?e:e.map(s=>s.id),r=sy(this,"toBack",t,{considerAllShapes:!0});return r&&this.updateShapes(r),this}sendBackward(e,t={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id),s=sy(this,"backward",r,t);return s&&this.updateShapes(s),this}bringForward(e,t={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id),s=sy(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=sy(this,"toFront",t);return r&&this.updateShapes(r),this}collectShapesViaArrowBindings(e){const{initialShapes:t,resultShapes:r,resultBounds:s,bindings:o,visited:i}=e;for(const a of o)for(const l of[a.fromId,a.toId])if(!i.has(l)){const c=t.find(u=>u.id===l);if(c&&!i.has(c.id)){i.add(c.id);const u=this.getShapePageBounds(c);if(!u)continue;r.push(c),s.push(u),this.collectShapesViaArrowBindings({...e,bindings:this.getBindingsInvolvingShape(c,"arrow")})}}}flipShapes(e,t){if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(l=>l.id),s=st(r.map(l=>this.getShape(l)));for(const l of s)if(this.isShapeOfType(l,"group")){const c=st(this.getSortedChildIdsForParent(l.id).map(u=>this.getShape(u)));s.push(...c)}const o=[],i=[];for(const l of s){const c=this.getShapeUtil(l);if(!c.canBeLaidOut(l,{type:"flip",shapes:s}))continue;const u=this.getShapePageBounds(l),h=this.getShapeGeometry(l).bounds,p=this.getShapePageTransform(l.id);u&&h&&p&&(o.push({shape:l,localBounds:h,pageTransform:p,isAspectRatioLocked:c.isAspectRatioLocked(l)}),i.push(u))}if(!o.length)return this;const a=ye.Common(i).center;return this.run(()=>{for(const{shape:l,localBounds:c,pageTransform:u,isAspectRatioLocked:h}of o)this.resizeShape(l.id,{x:t==="horizontal"?-1:1,y:t==="vertical"?-1:1},{initialBounds:c,initialPageTransform:u,initialShape:l,isAspectRatioLocked:h,mode:"scale_shape",scaleOrigin:a,scaleAxisRotation:0})}),this}stackShapes(e,t,r){var w,C;const s=r??this.options.adjacentShapeMargin,o=typeof e[0]=="string"?e:e.map(T=>T.id);if(this.getIsReadonly())return this;const i=st(o.map(T=>this.getShape(T))),a=[],l=new Set;for(const T of i){if(l.has(T.id))continue;l.add(T.id);const E=this.getShapePageBounds(T);if(!E||!((C=(w=this.getShapeUtil(T)).canBeLaidOut)!=null&&C.call(w,T,{type:"stack",shapes:i})))continue;const _=[T],A=[E];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(T.id,"arrow"),initialShapes:i,resultShapes:_,resultBounds:A,visited:l});const O=ye.Common(A);O&&a.push({shapes:_,pageBounds:O})}const c=a.length;if(s===0&&c<3||c<2)return this;let u,h,p,m;t==="horizontal"?(u="x",h="minX",p="maxX",m="width"):(u="y",h="minY",p="maxY",m="height");let S=0;if(s===0){const T={};a.sort((_,A)=>_.pageBounds[h]-A.pageBounds[h]);for(let _=0;_<c-1;_++){const A=a[_],D=a[_+1].pageBounds[h]-A.pageBounds[p];T[D]||(T[D]=0),T[D]++}let E=1;for(const[_,A]of Object.entries(T))A>E&&(E=A,S=parseFloat(_));if(E===1){let _=0;for(const[A,O]of Object.entries(T))S+=parseFloat(A)*O,_+=O;S/=_}}else S=s;const v=[];let y=a[0].pageBounds[p];for(let T=1;T<a.length;T++){const{shapes:E,pageBounds:_}=a[T],A=new P;A[u]=y+S-_[u];for(const O of E){const D=A.clone(),F=this.getShapeParent(O);if(F){const U=this.getShapePageTransform(F);U&&D.rot(-U.rotation())}D.add(O),v.push(this.getChangesToTranslateShape(O,D))}y+=_[m]+S}return this.updateShapes(v),this}packShapes(e,t){var _,A;if(this.getIsReadonly())return this;const r=t??this.options.adjacentShapeMargin,s=typeof e[0]=="string"?e:e.map(O=>O.id),o=st(s.map(O=>this.getShape(O))),i=[],a=[],l=new Set;for(const O of o){if(l.has(O.id))continue;l.add(O.id);const D=this.getShapePageBounds(O);if(!D||!((A=(_=this.getShapeUtil(O)).canBeLaidOut)!=null&&A.call(_,O,{type:"pack",shapes:o})))continue;const F=[O],U=[D];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(O.id,"arrow"),initialShapes:o,resultShapes:F,resultBounds:U,visited:l});const V=ye.Common(U);V&&(i.push({shapes:F,pageBounds:V,nextPageBounds:V.clone()}),a.push(V))}if(i.length<2)return this;let c=0;for(const{pageBounds:O}of i)c+=O.width*O.height;const u=ye.Common(a),h=u.width;i.sort((O,D)=>O.pageBounds.width-D.pageBounds.width).sort((O,D)=>O.pageBounds.height-D.pageBounds.height);const p=Math.max(Math.ceil(Math.sqrt(c/.95)),h),m=[new ye(u.x,u.y,p,1/0)];let S=0,v=0,y,w;for(const{nextPageBounds:O}of i)for(let D=m.length-1;D>=0;D--)if(y=m[D],!(O.width>y.width||O.height>y.height)){O.x=y.x,O.y=y.y,v=Math.max(v,O.maxY),S=Math.max(S,O.maxX),O.width===y.width&&O.height===y.height?(w=m.pop(),D<m.length&&(m[D]=w)):O.height===y.height?(y.x+=O.width+r,y.width-=O.width+r):O.width===y.width?(y.y+=O.height+r,y.height-=O.height+r):(m.push(new ye(y.x+(O.width+r),y.y,y.width-(O.width+r),O.height)),y.y+=O.height+r,y.height-=O.height+r);break}const C=ye.Common(i.map(O=>O.nextPageBounds)),T=P.Sub(u.center,C.center),E=[];for(const{shapes:O,pageBounds:D,nextPageBounds:F}of i){const U=P.Sub(F.point,D.point).add(T);for(const V of O){const Y=U.clone();if(this.getShapeParent(V)){const N=this.getShapeParentTransform(V);N&&Y.rot(-N.rotation())}Y.add(V),E.push(this.getChangesToTranslateShape(V,Y))}}return E.length&&this.updateShapes(E),this}alignShapes(e,t){var u,h;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(p=>p.id),s=st(r.map(p=>this.getShape(p))),o=[],i=[],a=new Set;for(const p of s){if(a.has(p.id))continue;a.add(p.id);const m=this.getShapePageBounds(p);if(!m||!((h=(u=this.getShapeUtil(p)).canBeLaidOut)!=null&&h.call(u,p,{type:"align",shapes:s})))continue;const S=[p],v=[m];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(p.id,"arrow"),initialShapes:s,resultShapes:S,resultBounds:v,visited:a});const y=ye.Common(v);y&&(o.push({shapes:S,pageBounds:y}),i.push(y))}if(o.length<2)return this;const l=ye.Common(i),c=[];return o.forEach(({shapes:p,pageBounds:m})=>{const S=new P;switch(t){case"top":{S.y=l.minY-m.minY;break}case"center-vertical":{S.y=l.midY-m.minY-m.height/2;break}case"bottom":{S.y=l.maxY-m.minY-m.height;break}case"left":{S.x=l.minX-m.minX;break}case"center-horizontal":{S.x=l.midX-m.minX-m.width/2;break}case"right":{S.x=l.maxX-m.minX-m.width;break}}for(const v of p){const y=S.clone(),w=this.getShapeParent(v);if(w){const C=this.getShapePageTransform(w);C&&y.rot(-C.rotation())}y.add(v),c.push(this.getChangesToTranslateShape(v,y))}}),this.updateShapes(c),this}distributeShapes(e,t){var T,E;if(this.getIsReadonly())return this;const r=typeof e[0]=="string"?e:e.map(_=>_.id),s=st(r.map(_=>this.getShape(_))),o=[],i=new Set;for(const _ of s){if(i.has(_.id))continue;i.add(_.id);const A=this.getShapePageBounds(_);if(!A||!((E=(T=this.getShapeUtil(_)).canBeLaidOut)!=null&&E.call(T,_,{type:"distribute",shapes:s})))continue;const O=[_],D=[A];this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(_.id,"arrow"),initialShapes:s,resultShapes:O,resultBounds:D,visited:i});const F=ye.Common(D);F&&o.push({shapes:O,pageBounds:F})}if(o.length<3)return this;let a,l,c,u;t==="horizontal"?(a="x",l="minX",c="maxX",u="width"):(a="y",l="minY",c="maxY",u="height");const h=[],p=o.sort((_,A)=>_.pageBounds[l]-A.pageBounds[l])[0],m=o.sort((_,A)=>A.pageBounds[c]-_.pageBounds[c])[0];if(p===m){const _=new Set(p.shapes.map(A=>A.id));return this.distributeShapes(r.filter(A=>!_.has(A)),t)}const S=o.filter(_=>_!==p&&_!==m).sort((_,A)=>_.pageBounds[l]===A.pageBounds[l]?_.shapes[0].id<A.shapes[0].id?-1:1:_.pageBounds[l]-A.pageBounds[l]),v=p.pageBounds[c],y=m.pageBounds[l]-v,w=S.reduce((_,A)=>_+A.pageBounds[u],0),C=(y-w)/(S.length+1);for(let _=v+C,A=0;A<S.length;A++){const{shapes:O,pageBounds:D}=S[A],F=new P;F[a]=_-D[a],_+D[u]>m.pageBounds[c]-1&&(F[a]=m.pageBounds[c]-D[c]-1);for(const U of O){const V=F.clone(),Y=this.getShapeParent(U);if(Y){const j=this.getShapePageTransform(Y);j&&V.rot(-j.rotation())}V.add(U),h.push(this.getChangesToTranslateShape(U,V))}_+=D[u]+C}return this.updateShapes(h),this}stretchShapes(e,t){var p,m;const r=typeof e[0]=="string"?e:e.map(S=>S.id);if(this.getIsReadonly())return this;const s=st(r.map(S=>this.getShape(S))).filter(S=>{var v;return((v=this.getShapePageTransform(S))==null?void 0:v.rotation())%(bt/2)===0}),o=[],i=[],a=new Set;for(const S of s){if(a.has(S.id))continue;a.add(S.id);const v=this.getShapePageBounds(S);if(!v)continue;const y=[S],w=[v];if(!((m=(p=this.getShapeUtil(S)).canBeLaidOut)!=null&&m.call(p,S,{type:"stretch",shapes:s})))continue;this.collectShapesViaArrowBindings({bindings:this.getBindingsToShape(S.id,"arrow"),initialShapes:s,resultShapes:y,resultBounds:w,visited:a});const C=ye.Common(w);C&&(o.push({shapes:y,pageBounds:C}),i.push(C))}if(o.length<2)return this;const l=ye.Common(i);let c,u,h;return t==="horizontal"?(c="x",u="minX",h="width"):(c="y",u="minY",h="height"),this.run(()=>{o.forEach(({shapes:S,pageBounds:v})=>{const y=new P;y[c]=l[u]-v[u];const w=v.center.clone();w[c]=l[u];const C=new P(1,1);C[c]=l[h]/v[h];for(const T of S){const E=y.clone(),_=this.getShapeParentTransform(T);_&&y.rot(-_.rotation()),E.add(T);const A=this.getChangesToTranslateShape(T,E);this.updateShape(A),this.resizeShape(T.id,C,{initialBounds:this.getShapeGeometry(T).bounds,scaleOrigin:w,isAspectRatioLocked:this.getShapeUtil(T).isAspectRatioLocked(T),scaleAxisRotation:0})}})}),this}resizeShape(e,t,r={}){var S,v,y;const s=typeof e=="string"?e:e.id;if(this.getIsReadonly())return this;Number.isFinite(t.x)||(t=new P(1,t.y)),Number.isFinite(t.y)||(t=new P(t.x,1));const o=r.initialShape??this.getShape(s);if(!o)return this;const i=r.scaleOrigin??((S=this.getShapePageBounds(s))==null?void 0:S.center);if(!i)return this;const a=r.initialPageTransform?de.Cast(r.initialPageTransform):this.getShapePageTransform(s);if(!a)return this;const l=a.rotation();if(l==null)return this;const c=r.scaleAxisRotation??l,u=r.initialBounds??this.getShapeGeometry(s).bounds;if(!u)return this;const h=r.isAspectRatioLocked??this.getShapeUtil(o).isAspectRatioLocked(o);if(!J5(l,c))return this._resizeUnalignedShape(s,t,{...r,initialBounds:u,scaleOrigin:i,scaleAxisRotation:c,initialPageTransform:a,isAspectRatioLocked:h,initialShape:o});const p=this.getShapeUtil(o);h&&(Math.abs(t.x)>Math.abs(t.y)?t=new P(t.x,Math.sign(t.y)*Math.abs(t.x)):t=new P(Math.sign(t.x)*Math.abs(t.y),t.y));let m=!1;if(p.onResize&&p.canResize(o)){const w=this._scalePagePoint(de.applyToPoint(a,new P(0,0)),i,t,c),C=this.getPointInParentSpace(o.id,w),T=new P(t.x,t.y),E=ro((l-c)%Math.PI,0);T.x=E?t.x:t.y,T.y=E?t.y:t.x;const _=de.applyToPoint(a,new P),{x:A,y:O}=this.getPointInParentSpace(o.id,_);let D=o;r.skipStartAndEndCallbacks||(D=Li(o,((v=p.onResizeStart)==null?void 0:v.call(p,o))??void 0));const F=p.onResize({...o,x:A,y:O},{newPoint:C,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:T.x,scaleY:T.y,initialBounds:u,initialShape:o});F&&(m=!0),D=Li(D,{id:s,type:o.type,x:C.x,y:C.y,...F}),r.skipStartAndEndCallbacks||(D=Li(D,((y=p.onResizeEnd)==null?void 0:y.call(p,o,D))??void 0)),this.updateShapes([D])}if(!m){const w=de.applyToPoint(a,u.center),C=this._scalePagePoint(w,i,t,c),T=this.getPointInParentSpace(o.id,w),E=this.getPointInParentSpace(o.id,C),_=P.Sub(E,T);this.updateShapes([{id:s,type:o.type,x:o.x+_.x,y:o.y+_.y}])}return this}_scalePagePoint(e,t,r,s){const o=P.RotWith(e,t,-s).sub(t),i=P.MulV(o,r);return P.Add(i,t).rotWith(t,s)}_resizeUnalignedShape(e,t,r){const{type:s}=r.initialShape,o=new P(t.x,t.y);if(Math.abs(t.x)>Math.abs(t.y)?o.x=Math.sign(t.x)*Math.abs(t.y):o.y=Math.sign(t.y)*Math.abs(t.x),this.resizeShape(e,o,{initialShape:r.initialShape,initialBounds:r.initialBounds,isAspectRatioLocked:r.isAspectRatioLocked}),Math.sign(t.x)*Math.sign(t.y)<0){let{rotation:y}=de.Decompose(r.initialPageTransform);y-=2*y,this.updateShapes([{id:e,type:s,rotation:y}])}const i=de.applyToPoint(r.initialPageTransform,r.initialBounds.center),a=this._scalePagePoint(i,r.scaleOrigin,t,r.scaleAxisRotation),l=this.getShapePageBounds(e),c=this.getShapePageTransform(e),u=l.center,h=c.point();if(!u||!h)return this;const p=P.Sub(a,u),m=P.Add(h,p),{x:S,y:v}=this.getPointInParentSpace(e,m);return this.updateShapes([{id:e,type:s,x:S,y:v}]),this}getInitialMetaForShape(e){return{}}createShape(e){return this.createShapes([e]),this}createShapes(e){if(!Array.isArray(e))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getIsReadonly())return this;if(e.length<=0)return this;const t=this.getCurrentPageShapeIds();if(e.length+t.size>this.options.maxShapesPerPage)return iy(this),this;const s=this.getFocusedGroupId();return this.run(()=>{var u,h;const o=this.getCurrentPageShapesSorted(),i=e.map(p=>{if(p.id||(p={id:Nt(),...p}),!p.parentId||!(this.store.has(p.parentId)||e.some(m=>m.id===p.parentId))){let m=this.getFocusedGroupId();for(let v=o.length-1;v>=0;v--){const y=o[v];if(!this.isShapeHidden(y)&&this.getShapeUtil(y).canReceiveNewChildrenOfType(y,p.type)&&this.isPointInShape(y,{x:p.x??0,y:p.y??0},{margin:0,hitInside:!0})){m=y.id;break}}const S=p.parentId;if(m===p.id&&(m=s),m!==S&&(p={...p},p.parentId=m,Ts(m))){const v=this.getPointInShapeSpace(this.getShape(m),{x:p.x??0,y:p.y??0});p.x=v.x,p.y=v.y,p.rotation=-this.getShapePageTransform(m).rotation()+(p.rotation??0)}}return p}),a=new Map,l=[],{opacityForNextShape:c}=this.getInstanceState();for(const p of i){const m=this.getShapeUtil(p);let S=p.index;if(!S){const C=p.parentId??s;a.has(C)||a.set(C,this.getHighestIndexForParent(C)),S=a.get(C),a.set(C,Wi(S))}const v=m.getDefaultProps();for(const[C,T]of this.styleProps[p.type])v[T]=this.getStyleForNextShape(C);let y=this.store.schema.types.shape.create({...p,index:S,opacity:p.opacity??c,parentId:p.parentId??s,props:"props"in p?{...v,...p.props}:v});if(y.index===void 0)throw Error("no index!");const w=(h=(u=this.getShapeUtil(y)).onBeforeCreate)==null?void 0:h.call(u,y);w&&(y=w),l.push(y)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)}),this}animateShape(e,t={animation:jC}){return this.animateShapes([e],t)}animateShapes(e,t={animation:jC}){if(!t.animation)return this;const{duration:r=500,easing:s=qn.linear}=t.animation,o=Mt();let i=r,a;const l=[];let c,u;for(let p=0,m=e.length;p<m;p++){if(c=e[p],!c)continue;const S=this.getShape(c.id);S&&(u={start:en(S),end:Li(en(S),c)},l.push(u),this.animatingShapes.set(S.id,o))}const h=p=>{var y,w;if(i-=p,i<0){const{animatingShapes:C}=this,T=e.filter(E=>E&&C.get(E.id)===o);T.length&&this.updateShapes(T),this.off("tick",h);return}a=s(1-i/r);const{animatingShapes:m}=this,S=[];let v;for(let C=0,T=l.length;C<T;C++){const{start:E,end:_}=l[C];v=m.get(E.id),v===o&&S.push({..._,x:E.x+(_.x-E.x)*a,y:E.y+(_.y-E.y)*a,opacity:E.opacity+(_.opacity-E.opacity)*a,rotation:E.rotation+(_.rotation-E.rotation)*a,props:((w=(y=this.getShapeUtil(_)).getInterpolatedProps)==null?void 0:w.call(y,E,_,a))??_.props})}this._updateShapes(S)};return this.on("tick",h),this}groupShapes(e,t={}){var S;const{groupId:r=Nt(),select:s=!0}=t;if(!Array.isArray(e))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getIsReadonly())return this;const o=typeof e[0]=="string"?e:e.map(v=>v.id);if(o.length<=1)return this;const i=st((this._shouldIgnoreShapeLock?o:this._getUnlockedShapeIds(o)).map(v=>this.getShape(v))),a=i.sort(ur).map(v=>v.id),l=ye.Common(st(i.map(v=>this.getShapePageBounds(v)))),{x:c,y:u}=l.point,h=this.findCommonAncestor(i)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const p=i.filter(v=>v.parentId===h).sort(ur),m=(S=p[p.length-1])==null?void 0:S.index;return this.run(()=>{this.createShapes([{id:r,type:"group",parentId:h,index:m,x:c,y:u,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),o=st((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(l=>this.getShape(l)));if(o.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const i=new Set,a=[];return o.forEach(l=>{this.isShapeOfType(l,"group")?a.push(l):i.add(l.id)}),a.length===0?this:(this.run(()=>{let l;for(let c=0,u=a.length;c<u;c++){l=a[c];const h=this.getSortedChildIdsForParent(l.id);for(let p=0,m=h.length;p<m;p++)i.add(h[p]);this.reparentShapes(h,l.parentId,l.index)}this.deleteShapes(a.map(c=>c.id)),r&&this.select(...i)}),this)}updateShape(e){return this.updateShapes([e]),this}updateShapes(e){const t=Array(e.length);for(let r=0,s=e.length;r<s;r++){const o=e[r];if(!o)continue;const i=this.getShape(o.id);if(i){if(!this._shouldIgnoreShapeLock){if(i.isLocked){if(!(Object.hasOwn(o,"isLocked")&&!o.isLocked))continue}else if(this.isShapeOrAncestorLocked(i))continue}this.animatingShapes.delete(o.id),t.push(o)}}return this._updateShapes(t),this}_updateShapes(e){this.getIsReadonly()||this.run(()=>{var o,i;const t=[];let r,s;for(let a=0,l=e.length;a<l;a++){const c=e[a];c&&(r=this.getShape(c.id),r&&(s=Li(r,c),s!==r&&(s=((i=(o=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:i.call(o,r,s))??s,t.push(s))))}this.store.put(t)})}_getUnlockedShapeIds(e){return e.filter(t=>{var r;return!((r=this.getShape(t))!=null&&r.isLocked)})}deleteShapes(e){if(this.getIsReadonly())return this;if(!Array.isArray(e))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");const t=typeof e[0]=="string"?e:e.map(o=>o.id),r=this._shouldIgnoreShapeLock?t:this._getUnlockedShapeIds(t);if(r.length===0)return this;const s=new Set(r);for(const o of r)this.visitDescendants(o,i=>{s.add(i)});return this.run(()=>this.store.remove([...s]))}deleteShape(e){return this.deleteShapes([typeof e=="string"?e:e.id]),this}_extractSharedStyles(e,t){if(this.isShapeOfType(e,"group")){const r=this._parentIdsToChildIds.get()[e.id];if(!r)return;for(let s=0,o=r.length;s<o;s++)this._extractSharedStyles(this.getShape(r[s]),t)}else for(const[r,s]of this.styleProps[e.type])t.applyValue(r,kn(e.props,s))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),t=new Bk;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 kn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),t=new Bk;if(!e)return t;if(e.shapeType)if(e.shapeType==="frame"&&!this.getShapeUtil("frame").options.showColors)for(const r of this.styleProps[e.shapeType].keys())r.id!=="tldraw:color"&&t.applyValue(r,this.getStyleForNextShape(r));else for(const r of this.styleProps[e.shapeType].keys())t.applyValue(r,this.getStyleForNextShape(r));return t}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const e=[],t=s=>{const o=this.getShape(s);if(o)if(this.isShapeOfType(o,"group"))for(const i of this.getSortedChildIdsForParent(o.id))t(i);else e.push(o)};for(const s of this.getSelectedShapeIds())t(s);let r=null;for(const s of e)if(r===null)r=s.opacity;else if(r!==s.opacity)return{type:"mixed"};if(r!==null)return{type:"shared",value:r}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(e,t){return this.updateInstanceState({opacityForNextShape:e},t),this}setOpacityForSelectedShapes(e){const t=this.getSelectedShapes();if(t.length>0){const r=[],s=o=>{if(this.isShapeOfType(o,"group")){const i=this.getSortedChildIdsForParent(o);for(const a of i)s(this.getShape(a))}else r.push(o)};for(const o of t)s(o);this.updateShapes(r.map(o=>({id:o.id,type:o.type,opacity:e})))}return this}setStyleForNextShapes(e,t,r){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[e.id]:t}},r),this}setStyleForSelectedShapes(e,t){const r=this.getSelectedShapes();if(r.length>0){const s=[],o=i=>{if(this.isShapeOfType(i,"group")){const a=this.getSortedChildIdsForParent(i.id);for(const l of a)o(this.getShape(l))}else{const a=this.getShapeUtil(i),l=this.styleProps[i.type].get(e);if(l){const c={id:i.id,type:i.type,props:{[l]:t}};s.push({util:a,originalShape:i,updatePartial:c})}}};for(const i of r)o(i);this.updateShapes(s.map(({updatePartial:i})=>i))}return this}registerExternalAssetHandler(e,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 Rj(this,r,s=>{const o=[];for(const u of s){const h=this.getBinding(u);h&&o.push(h)}const i=[],a=[];for(const u of r){const h=this.getShape(u);if(!h)continue;if(!r.has(h.parentId)){const m=this.getShapePageTransform(h.id),S=m.point();a.push({...h,x:S.x,y:S.y,rotation:m.rotation(),parentId:this.getCurrentPageId()}),i.push(h.id)}else a.push(h)}const l=[],c=new Set;for(const u of a){if(!("assetId"in u.props))continue;const h=u.props.assetId;if(!h||c.has(h))continue;c.add(h);const p=this.getAsset(h);p&&l.push(p)}return{schema:this.store.schema.serialize(),shapes:a,rootShapeIds:i,bindings:o,assets:l}})}async resolveAssetsInContent(e){if(!e)return;const t=[];return await Promise.allSettled(e.assets.map(async r=>{var s,o,i;if((r.type==="image"||r.type==="video")&&!((s=r.props.src)!=null&&s.startsWith("data:image"))&&!((o=r.props.src)!=null&&o.startsWith("data:video"))&&!((i=r.props.src)!=null&&i.startsWith("http"))){const a=en(r),l=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await Jr.blobToDataUrl(await di(l).then(c=>c.blob())),t.push(a)}else t.push(r)})),e.assets=t,e}putContentOntoCurrentPage(e,t={}){var U,V,Y;if(this.getIsReadonly())return this;if(!e.schema)throw Error(`Could not put content:
120
+ content is missing a schema.`);const{select:r=!1,preserveIds:s=!1,preservePosition:o=!1}=t;let{point:i=void 0}=t;const a=this.getCurrentPageId(),{rootShapeIds:l}=e,c=[],u=[],h=[],p={store:{...Object.fromEntries(e.assets.map(j=>[j.id,j])),...Object.fromEntries(e.shapes.map(j=>[j.id,j])),...Object.fromEntries(((U=e.bindings)==null?void 0:U.map(j=>[j.id,j]))??[])},schema:e.schema},m=this.store.schema.migrateStoreSnapshot(p);if(m.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(m.value))switch(j.typeName){case"asset":{c.push(j);break}case"shape":{u.push(j);break}case"binding":{h.push(j);break}}const S=new Map(s?u.map(j=>[j.id,j.id]):u.map(j=>[j.id,Nt()])),v=new Map(s?h.map(j=>[j.id,j.id]):h.map(j=>[j.id,su()]));let y=this.getCurrentPageId(),w=1/0,C=[];for(const j of this.getSelectedShapes()){if(w===0)break;const N=this.isShapeOfType(j,"frame"),z=this.getShapeAncestors(j);N&&z.push(j);const G=N?z.length+1:z.length;if(G<w)w=G,C=z,y=N?j.id:j.parentId;else if(G===w){if(C.length!==z.length)throw Error(`Ancestors: ${C.length} !== ${z.length}`);if(C.length===0){y=a;break}else{y=a;for(let q=0;q<C.length&&z[q]===C[q];q++)y=z[q].id}}}let T=!1;if(!Tr(y)){const j=this.getShape(y);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))y=a;else if(l.length===1){const N=u.find(z=>z.id===l[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(N,"frame")&&N.props.w===(j==null?void 0:j.props.w)&&N.props.h===(j==null?void 0:j.props.h)&&(T=!0)}}else y=a}T||(T=S.has(y)),T&&(y=this.getShape(y).parentId);let E=this.getHighestIndexForParent(y);const _=[],A=u.map(j=>{const N=S.get(j.id),z={...j,id:N};return l.includes(j.id)&&(z.parentId=a,_.push(z)),S.has(z.parentId)?z.parentId=S.get(j.parentId):(l.push(z.id),z.index=E,E=Wi(E)),z});if(A.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return iy(this),this;const O=h.map(j=>({...j,id:qr(v.get(j.id)),fromId:qr(S.get(j.fromId)),toId:qr(S.get(j.toId))})),D=[],F=[];for(const j of c)this.store.has(j.id)||((j.type==="image"&&((V=j.props.src)!=null&&V.startsWith("data:image"))||j.type==="video"&&((Y=j.props.src)!=null&&Y.startsWith("data:video")))&&(F.push(en(j)),j.props.src=null),D.push(j));return Promise.allSettled(F.map(async j=>{const N=await Bte(j.props.src,j.props.name,j.props.mimeType??"image/png"),z=await this.getAssetForExternalContent({type:"file",file:N,assetId:j.id});if(!z){this.deleteAssets([j.id]);return}this.updateAssets([{...z,id:j.id}])})),this.run(()=>{D.length>0&&this.createAssets(D),this.createShapes(A),this.createBindings(O),r&&this.select(..._.map(q=>q.id)),y!==a&&this.reparentShapes(_.map(q=>q.id),y);const j=A.map(q=>this.getShape(q.id)),N=ye.Common(j.map(q=>this.getShapePageBounds(q)));if(i===void 0)if(Tr(y)){const q=this.getViewportPageBounds();o||q.includes(ye.From(N))?i=N.center:i=q.center}else{const q=this.getShape(y);i=de.applyToPoint(this.getShapePageTransform(q),this.getShapeGeometry(q).bounds.center)}if(_.length===1){const q=_[0];if(this.isShapeOfType(q,"frame"))for(;this.getShapesAtPoint(i).some($=>this.isShapeOfType($,"frame")&&$.props.w===q.props.w&&$.props.h===q.props.h);)i.x+=N.w+16}const z=ye.Common(st(_.map(({id:q})=>this.getShapePageBounds(q)))).center,G=P.Sub(i,z);this.updateShapes(_.map(({id:q})=>{const $=this.getShape(q),K=this.getShapeParentTransform(q).decompose().rotation,J=P.Rot(G,-K);return{id:$.id,type:$.type,x:$.x+J.x,y:$.y+J.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 Ate(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 o=await Nte(s.svg,{type:r.format,quality:r.quality,pixelRatio:r.pixelRatio,width:s.width,height:s.height});if(!o)throw new Error("Could not construct image.");return{blob:o,width:s.width,height:s.height}}default:xt(r.format)}}_updateInputsFromEvent(e){const{pointerVelocity:t,previousScreenPoint:r,previousPagePoint:s,currentScreenPoint:o,currentPagePoint:i}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(Yr),{x:l,y:c,z:u}=Hf(()=>this.getCamera()),h=e.point.x-a.x,p=e.point.y-a.y,m=e.point.z??.5;r.setTo(o),s.setTo(i),o.set(h,p);const S=h/u-l,v=p/u-c;isFinite(S)&&isFinite(v)&&i.set(S,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(o),this.inputs.originPagePoint.setTo(i)),this.run(()=>{var y;this.store.put([{id:BS,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===XD.CAMERA_MOVE?((y=this.store.unsafeGetWithoutCapture(BS))==null?void 0:y.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 Bee(this.store)}loadSnapshot(e,t){return N4(this.store,e,t),this}_zoomToFitPageContentAt100Percent(){const e=this.getCurrentPageBounds();e&&this.zoomToBounds(e,{immediate:!0,targetZoom:this.getBaseZoom()})}_navigateToDeepLink(e){this.run(()=>{switch(e.type){case"page":{const t=this.getPage(e.pageId);t&&this.setCurrentPage(t),this._zoomToFitPageContentAt100Percent();return}case"shapes":{const t=st(e.shapeIds.map(i=>this.getShape(i))),r={};for(const i of t){const a=this.getAncestorPageId(i);a&&(r[a]??(r[a]=[]),r[a].push(i))}const[s,o]=Object.entries(r).sort(([i,a],[l,c])=>c.length-a.length)[0]??["",[]];if(!s||!o.length)this._zoomToFitPageContentAt100Percent();else{this.setCurrentPage(s);const i=ye.Common(o.map(a=>this.getShapePageBounds(a)));this.zoomToBounds(i,{immediate:!0,targetZoom:this.getBaseZoom()})}return}case"viewport":{if(e.pageId){if(!this.getPage(e.pageId)){this._zoomToFitPageContentAt100Percent();return}this.setCurrentPage(e.pageId)}this.zoomToBounds(e.bounds,{immediate:!0,inset:0});return}default:xt(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(Hte(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",Ute((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 i=((l=e==null?void 0:e.getUrl)==null?void 0:l.call(e,this))??window.location.href;return this.createDeepLink({param:e==null?void 0:e.param,url:i,to:(c=e==null?void 0:e.getTarget)==null?void 0:c.call(e,this)}).toString()}),r=(e==null?void 0:e.onChange)??(()=>{var a;const i=this.createDeepLink({param:e==null?void 0:e.param,to:(a=e==null?void 0:e.getTarget)==null?void 0:a.call(e,this)});window.history.replaceState({},document.title,i.toString())}),s=r0(i=>i(),(e==null?void 0:e.debounceMs)??500),o=jo("update url on state change",()=>r(new URL(t.get()),this),{scheduleEffect:s});return()=>{o(),s.cancel()}}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_setShiftKeyTimeout(){this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,metaKey:this.inputs.metaKey,accelKey: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:o}=t;t.isPointing||(t.isDragging=!1);const i=this.store.unsafeGetWithoutCapture(Yr),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:u,y:h}}=e,{x:p,y:m}=P.SubXY(e.point,i.screenBounds.x,i.screenBounds.y);this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:S,y:v,z:y}=Hf(()=>this.getCamera()),{panSpeed:w}=l;this._setCamera(new P(S+u*w/y-p/y+p/c,v+h*w/y-m/y+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:u,wheelBehavior:h}=l;if(h!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:p,y:m,z:S}=Hf(()=>this.getCamera()),{x:v,y,z:w=0}=e.delta;let C=h;switch(e.ctrlKey&&(C=h==="pan"?"zoom":"pan"),C){case"zoom":{const{x:T,y:E}=this.inputs.currentScreenPoint;let _=w;h==="zoom"&&(Math.abs(y)>10?_=10*Math.sign(y)/100:_=y/100);const A=S+(_??0)*u*S;this._setCamera(new P(p+T/A-T/S,m+E/A-E/S,A),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new P(p+v*c/S,m+y*c/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}break}case"pointer":{if(t.isPinching)return;this._updateInputsFromEvent(e);const{isPen:c}=e,{isPenMode:u}=i;switch(e.name){case"pointer_down":{if(u&&!c)return;if(this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{const h=this.getViewportScreenBounds();this.dispatch({...e,point:this.inputs.originScreenPoint.clone().addXY(h.x,h.y),name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),e.button===ZD&&(this.capturedPointerId=e.pointerId),t.buttons.add(e.button),t.isPointing=!0,t.isDragging=!1,!u&&c&&this.updateInstanceState({isPenMode:!0}),e.button===JD?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===ty&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!c&&u)return;const{x:h,y:p,z:m}=Hf(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:S,previousScreenPoint:v}=this.inputs,y=P.Sub(S,v);this.setCamera(new P(h+y.x/m,p+y.y/m,m),{immediate:!0}),this.maybeTrackPerformance("Panning");return}t.isPointing&&!t.isDragging&&P.Dist2(s,o)*this.getZoomLevel()>(i.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),i.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 h=this.inputs.pointerVelocity,p=Math.min(2,h.len());switch(e.button){case ZD:{this.setCursor({type:"grab",rotation:0});break}case ty:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}p>0&&this.slideCamera({speed:p,direction:h})}else e.button===JD&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(e.key==="ShiftRight"&&(e.key="ShiftLeft"),e.key==="AltRight"&&(e.key="AltLeft"),e.code==="ControlRight"&&(e.code="ControlLeft"),e.code==="MetaRight"&&(e.code="MetaLeft"),e.name){case"key_down":{if(t.keys.add(e.code),e.code==="Space"&&!e.ctrlKey&&(this.inputs.isPanning||(this._prevCursor=i.cursor.type),this.inputs.isPanning=!0,this.inputs.isSpacebarPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0})),this.inputs.isSpacebarPanning){let c;switch(e.code){case"ArrowUp":{c=new P(0,-1);break}case"ArrowRight":{c=new P(1,0);break}case"ArrowDown":{c=new P(0,1);break}case"ArrowLeft":{c=new P(-1,0);break}}if(c){const u=this.getViewportPageBounds(),h=u.clone().translate(c.mulV({x:u.w,y:u.h}));this._animateToViewport(h,{animation:{duration:320}})}}break}case"key_up":{t.keys.delete(e.code),e.code==="Space"&&(this.inputs.buttons.has(ty)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===ty?e.name="middle_click":e.button===nT&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(Yr);if(e.isPen===c){const u=this._clickManager.handlePointerEvent(e);if(e.name!==u.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(u),this.emit("event",u);return}}}return this.root.handleEvent(e),this.emit("event",e),e.type==="pointer"&&e.name==="pointer_down"&&this.menus.clearOpenMenus(),this}maybeTrackPerformance(e){sn.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}};Ee=hre(Uk);Ie(Ee,1,"getIsShapeHiddenCache",N$,ke);Ie(Ee,1,"getCanUndo",L$,ke);Ie(Ee,1,"getCanRedo",j$,ke);Ie(Ee,1,"getPath",D$,ke);Ie(Ee,1,"getCurrentTool",R$,ke);Ie(Ee,1,"getCurrentToolId",O$,ke);Ie(Ee,1,"getDocumentSettings",A$,ke);Ie(Ee,1,"getInstanceState",M$,ke);Ie(Ee,1,"getOpenMenus",_$,ke);Ie(Ee,1,"getIsMenuOpen",T$,ke);Ie(Ee,1,"getPageStates",I$,ke);Ie(Ee,1,"_getPageStatesQuery",E$,ke);Ie(Ee,1,"getCurrentPageState",k$,ke);Ie(Ee,1,"_getCurrentPageStateId",P$,ke);Ie(Ee,1,"getSelectedShapeIds",C$,ke);Ie(Ee,1,"getSelectedShapes",b$,ke);Ie(Ee,1,"getCurrentPageShapesInReadingOrder",w$,ke);Ie(Ee,1,"getOnlySelectedShapeId",v$,ke);Ie(Ee,1,"getOnlySelectedShape",x$,ke);Ie(Ee,1,"getSelectionPageBounds",S$,ke);Ie(Ee,1,"getSelectionRotation",y$,ke);Ie(Ee,1,"getSelectionRotatedPageBounds",m$,ke);Ie(Ee,1,"getSelectionRotatedScreenBounds",g$,ke);Ie(Ee,1,"getFocusedGroupId",p$,ke);Ie(Ee,1,"getFocusedGroup",f$,ke);Ie(Ee,1,"getEditingShapeId",h$,ke);Ie(Ee,1,"getEditingShape",d$,ke);Ie(Ee,1,"getRichTextEditor",u$,ke);Ie(Ee,1,"getHoveredShapeId",c$,ke);Ie(Ee,1,"getHoveredShape",l$,ke);Ie(Ee,1,"getHintingShapeIds",a$,ke);Ie(Ee,1,"getHintingShape",i$,ke);Ie(Ee,1,"getErasingShapeIds",o$,ke);Ie(Ee,1,"getErasingShapes",s$,ke);Ie(Ee,1,"_unsafe_getCameraId",r$,ke);Ie(Ee,1,"getCamera",n$,ke);Ie(Ee,1,"getViewportPageBoundsForFollowing",t$,ke);Ie(Ee,1,"getCameraForFollowing",e$,ke);Ie(Ee,1,"getZoomLevel",QB,ke);Ie(Ee,1,"getViewportScreenBounds",JB,ke);Ie(Ee,1,"getViewportScreenCenter",ZB,ke);Ie(Ee,1,"getViewportPageBounds",XB,ke);Ie(Ee,1,"_getCollaboratorsQuery",YB,ke);Ie(Ee,1,"getCollaborators",qB,ke);Ie(Ee,1,"getCollaboratorsOnCurrentPage",GB,ke);Ie(Ee,1,"getRenderingShapes",VB,ke);Ie(Ee,1,"_getAllPagesQuery",WB,ke);Ie(Ee,1,"getPages",KB,ke);Ie(Ee,1,"getCurrentPageId",HB,ke);Ie(Ee,1,"getCurrentPageShapeIdsSorted",UB,ke);Ie(Ee,1,"_getAllAssetsQuery",$B,ke);Ie(Ee,1,"_getShapeHandlesCache",BB,ke);Ie(Ee,1,"_getShapePageTransformCache",zB,ke);Ie(Ee,1,"_getShapePageBoundsCache",FB,ke);Ie(Ee,1,"_getShapeClipPathCache",NB,ke);Ie(Ee,1,"_getShapeMaskCache",LB,ke);Ie(Ee,1,"_getShapeMaskedPageBoundsCache",jB,ke);Ie(Ee,1,"_notVisibleShapes",DB,ke);Ie(Ee,1,"getCulledShapes",RB,ke);Ie(Ee,1,"getCurrentPageBounds",OB,ke);Ie(Ee,1,"getCurrentPageShapes",AB,ke);Ie(Ee,1,"getCurrentPageShapesSorted",MB,ke);Ie(Ee,1,"getCurrentPageRenderingShapesSorted",_B,ke);Ie(Ee,1,"_getBindingsIndexCache",TB,ke);Ie(Ee,1,"_getSelectionSharedStyles",IB,ke);Ie(Ee,1,"getSharedStyles",EB,ke);Ie(Ee,1,"getSharedOpacity",kB,ke);Ie(Ee,1,"getIsFocused",PB,ke);Ie(Ee,1,"getIsReadonly",CB,ke);Ie(Ee,1,"_setShiftKeyTimeout",bB,ke);Ie(Ee,1,"_setAltKeyTimeout",wB,ke);Ie(Ee,1,"_setCtrlKeyTimeout",vB,ke);Ie(Ee,1,"_setMetaKeyTimeout",xB,ke);pre(Ee,ke);function iy(n,e=n.getCurrentPageId()){const t=n.getPage(e).name;n.emit("max-shapes",{name:t,pageId:e,count:n.options.maxShapesPerPage})}function Li(n,e){if(!e)return n;let t=null;const r=Object.entries(e);for(let s=0,o=r.length;s<o;s++){const[i,a]=r[s];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==n[i]){if(t||(t={...n}),i==="props"||i==="meta"){t[i]={...n[i]};for(const[l,c]of Object.entries(a))t[i][l]=c;continue}t[i]=a}}return t||n}function F$(n,e,t){const r=n.getShape(e);if(!r)return;t.push(r);const s=n.getSortedChildIdsForParent(e);for(let o=0,i=s.length;o<i;o++)F$(n,s[o],t)}function Rj(n,e,t){let r;if(n.run(()=>{const s=n.store.extractingChanges(()=>{const o=new Set,i=new Set;for(const a of e)if(n.getShape(a))for(const c of n.getBindingsInvolvingShape(a)){const u=e.has(c.fromId),h=e.has(c.toId);if(u&&h){o.add(c.id);continue}(!u||!h)&&i.add(c.id)}n.deleteBindings([...i],{isolateShapes:!0});try{r=Gr.ok(t(o))}catch(a){r=Gr.err(a)}});n.store.applyDiff(Ik(s),{runCallbacks:!1})},{history:"ignore"}),r.ok)return r.value;throw r.error}function Dj(n,e){if(!e.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=e.constraints,s=n.getViewportScreenBounds(),o=ye.From(e.constraints.bounds),i=(s.w-t*2)/o.w,a=(s.h-r*2)/o.h;return{zx:i,zy:a}}function Ig(){const n=ne(),e=Cg();return se("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'/>",Lj="<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'/>",ay='<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 Tl(n,e,t,r,s,o=16,i=16){const a=(-t-e)*(bt/180),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,h=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${s};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${h}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${e+t} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+n.replaceAll('"',"'")+`</g></svg>") ${o} ${i}, pointer`}const mre=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],yre={none:()=>"none","ew-resize":(n,e,t)=>Tl(Lj,n,0,e,t),"ns-resize":(n,e,t)=>Tl(Lj,n,90,e,t),"nesw-resize":(n,e,t)=>Tl(jj,n,0,e,t),"nwse-resize":(n,e,t)=>Tl(jj,n,90,e,t),"nwse-rotate":(n,e,t)=>Tl(ay,n,0,e,t),"nesw-rotate":(n,e,t)=>Tl(ay,n,90,e,t),"senw-rotate":(n,e,t)=>Tl(ay,n,180,e,t),"swne-rotate":(n,e,t)=>Tl(ay,n,270,e,t)};function qs(n,e=0,t="black"){return yre[n](sJ(e),!1,t)}function Sre(){const n=ne(),e=_n(),t=Ig();ec("useCursor",()=>{const{type:r,rotation:s}=n.getInstanceState().cursor;if(mre.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",qs(r,s,t?"white":"black"))},[n,e,t])}function xre(){const n=ne(),e=_n(),t=Ig(),r=se(sn.forceSrgb);We.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 vre(){const[n,e]=k.useState(0);k.useEffect(()=>e(t=>t+1),[])}const wre=n=>n.props.src,bre={upload:async(n,e)=>({src:await Jr.blobToDataUrl(e)})};function Cre(n){return"schema"in n&&n.schema?n.schema:WZ({shapes:"shapeUtils"in n&&n.shapeUtils?Nj($4(n.shapeUtils)):void 0,bindings:"bindingUtils"in n&&n.bindingUtils?Nj(z4(n.bindingUtils)):void 0,migrations:"migrations"in n?n.migrations:void 0})}function zp({initialData:n,defaultName:e="",id:t,assets:r=bre,onMount:s,collaboration:o,...i}={}){const a=Cre(i),l=new BI({id:t,schema:a,initialData:n,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??wre,remove:r.remove??(()=>Promise.resolve())},onMount:c=>{Ve(c instanceof ke),s==null||s(c)},collaboration:o}});if(i.snapshot){if(n)throw new Error("Cannot provide both initialData and snapshot");N4(l,i.snapshot,{forceOverwriteSessionState:!0})}return l}function Nj(n){return Object.fromEntries(n.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}const Pre=(n,e)=>e.some(t=>n instanceof t);let Fj,zj;function kre(){return Fj||(Fj=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Ere(){return zj||(zj=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const z$=new WeakMap,Hk=new WeakMap,B$=new WeakMap,GC=new WeakMap,xT=new WeakMap;function Ire(n){const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("success",o),n.removeEventListener("error",i)},o=()=>{t(Na(n.result)),s()},i=()=>{r(n.error),s()};n.addEventListener("success",o),n.addEventListener("error",i)});return e.then(t=>{t instanceof IDBCursor&&z$.set(t,n)}).catch(()=>{}),xT.set(e,n),e}function Tre(n){if(Hk.has(n))return;const e=new Promise((t,r)=>{const s=()=>{n.removeEventListener("complete",o),n.removeEventListener("error",i),n.removeEventListener("abort",i)},o=()=>{t(),s()},i=()=>{r(n.error||new DOMException("AbortError","AbortError")),s()};n.addEventListener("complete",o),n.addEventListener("error",i),n.addEventListener("abort",i)});Hk.set(n,e)}let Kk={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return Hk.get(n);if(e==="objectStoreNames")return n.objectStoreNames||B$.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Na(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 _re(n){Kk=n(Kk)}function Mre(n){return n===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){const r=n.call(qC(this),e,...t);return B$.set(r,e.sort?e.sort():[e]),Na(r)}:Ere().includes(n)?function(...e){return n.apply(qC(this),e),Na(z$.get(this))}:function(...e){return Na(n.apply(qC(this),e))}}function Are(n){return typeof n=="function"?Mre(n):(n instanceof IDBTransaction&&Tre(n),Pre(n,kre())?new Proxy(n,Kk):n)}function Na(n){if(n instanceof IDBRequest)return Ire(n);if(GC.has(n))return GC.get(n);const e=Are(n);return e!==n&&(GC.set(n,e),xT.set(e,n)),e}const qC=n=>xT.get(n);function $$(n,e,{blocked:t,upgrade:r,blocking:s,terminated:o}={}){const i=indexedDB.open(n,e),a=Na(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Na(i.result),l.oldVersion,l.newVersion,Na(i.transaction),l)}),t&&i.addEventListener("blocked",l=>t(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),s&&l.addEventListener("versionchange",c=>s(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function U$(n,{blocked:e}={}){const t=indexedDB.deleteDatabase(n);return e&&t.addEventListener("blocked",r=>e(r.oldVersion,r)),Na(t).then(()=>{})}const Ore=["get","getKey","getAll","getAllKeys","count"],Rre=["put","add","delete","clear"],YC=new Map;function Bj(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(YC.get(e))return YC.get(e);const t=e.replace(/FromIndex$/,""),r=e!==t,s=Rre.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(s||Ore.includes(t)))return;const o=async function(i,...a){const l=this.transaction(i,s?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[t](...a),s&&l.done]))[0]};return YC.set(e,o),o}_re(n=>({...n,get:(e,t,r)=>Bj(e,t)||n.get(e,t,r),has:(e,t)=>!!Bj(e,t)||n.has(e,t)}));const Dre="TLDRAW_DOCUMENT_v2",jre="TLDRAW_ASSET_STORE_v1",H$="TLDRAW_DB_NAME_INDEX_v2",pt={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function K$(n){const e=Dre+n;return Nre(e),await $$(e,4,{upgrade(t){t.objectStoreNames.contains(pt.Records)||t.createObjectStore(pt.Records),t.objectStoreNames.contains(pt.Schema)||t.createObjectStore(pt.Schema),t.objectStoreNames.contains(pt.SessionState)||t.createObjectStore(pt.SessionState),t.objectStoreNames.contains(pt.Assets)||t.createObjectStore(pt.Assets)}})}async function Lre(n){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):vT(),t=jre+n;if(!e.find(p=>p===t))return;const s=await $$(t,1,{upgrade(p){p.objectStoreNames.contains("assets")||p.createObjectStore("assets")}});if(!s.objectStoreNames.contains("assets"))return;const o=s.transaction(["assets"],"readonly"),i=o.objectStore("assets"),a=await i.getAllKeys(),l=await Promise.all(a.map(async p=>[p,await i.get(p)]));await o.done;const c=await K$(n),u=c.transaction([pt.Assets],"readwrite"),h=u.objectStore(pt.Assets);for(const[p,m]of l)h.put(m,p);await u.done,s.close(),c.close(),await U$(t)}const _p=class _p{constructor(e){R(this,"getDbPromise");R(this,"isClosed",!1);R(this,"pendingTransactionSet",new Set);_p.connectedInstances.add(this),this.getDbPromise=(async()=>(await Lre(e),await K$(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Ap)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),_p.connectedInstances.delete(this))}tx(e,t,r){const s=(async()=>{Ve(!this.isClosed,"db is closed");const i=(await this.getDb()).transaction(t,e),a=i.done.catch(l=>{if(!this.isClosed)throw l});try{return await r(i)}finally{this.isClosed?i.abort():await a}})();return this.pendingTransactionSet.add(s),s.finally(()=>this.pendingTransactionSet.delete(s)),s}async load({sessionId:e}={}){return await this.tx("readonly",[pt.Records,pt.Schema,pt.SessionState],async t=>{var l,c;const r=t.objectStore(pt.Records),s=t.objectStore(pt.Schema),o=t.objectStore(pt.SessionState);let i=e?(l=await o.get(e))==null?void 0:l.snapshot:null;return i||(i=(c=(await o.getAll()).sort((h,p)=>h.updatedAt-p.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(pt.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:t,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[pt.Records,pt.Schema,pt.SessionState],async o=>{const i=o.objectStore(pt.Records),a=o.objectStore(pt.Schema),l=o.objectStore(pt.SessionState);for(const[c,u]of Object.entries(t.added))await i.put(u,c);for(const[c,u]of Object.values(t.updated))await i.put(u,u.id);for(const c of Object.keys(t.removed))await i.delete(c);a.put(e.serialize(),pt.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",[pt.Records,pt.Schema,pt.SessionState],async o=>{const i=o.objectStore(pt.Records),a=o.objectStore(pt.Schema),l=o.objectStore(pt.SessionState);await i.clear();for(const[c,u]of Object.entries(t))await i.put(u,c);a.put(e.serialize(),pt.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",[pt.SessionState],async e=>{const t=e.objectStore(pt.SessionState),r=(await t.getAll()).sort((o,i)=>o.updatedAt-i.updatedAt);if(r.length<10){await e.done;return}const s=r.slice(0,r.length-10);for(const{id:o}of s)await t.delete(o)})}async getAsset(e){return await this.tx("readonly",[pt.Assets],async t=>await t.objectStore(pt.Assets).get(e))}async storeAsset(e,t){await this.tx("readwrite",[pt.Assets],async r=>{await r.objectStore(pt.Assets).put(t,e)})}async removeAssets(e){await this.tx("readwrite",[pt.Assets],async t=>{const r=t.objectStore(pt.Assets);for(const s of e)await r.delete(s)})}};R(_p,"connectedInstances",new Set);let YS=_p;function vT(){const n=JSON.parse(gI(H$)||"[]")??[];return Array.isArray(n)?n:[]}function Nre(n){const e=new Set(vT());e.add(n),mI(H$,JSON.stringify([...e]))}function Fre(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
121
+
122
+ Keep seeing this message?
123
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
124
+ • If your hard disk is full, try clearing up some space and then reload the page.`)}function zre(){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.
125
+
126
+ Keep seeing this message?
127
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const Bre=350,$re=1e4,$j=Symbol("UPDATE_INSTANCE_STATE"),Ure=n=>n;class Hre{constructor(e){R(this,"onmessage")}postMessage(e){}close(){}}const Kre=typeof BroadcastChannel>"u"?Hre:BroadcastChannel;class Wre{constructor(e,{persistenceKey:t,sessionId:r=GS,onLoad:s,onLoadError:o},i=new Kre(`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=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.db=new YS(t),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=uT(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(Ure({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($j),this.schedulePersist()},{scope:"session"})),this.connect(s,o),this.documentTypes=new Set(Object.values(this.store.schema.types).filter(a=>a.scope==="document").map(a=>a.typeName))}debug(...e){this.isDebugging&&console.debug(...e)}async connect(e,t){this.debug("connecting");let r;try{r=await this.db.load({sessionId:this.sessionId})}catch(s){t(s),zre();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const s=Object.fromEntries(r.records.map(l=>[l.id,l])),o=r.sessionStateSnapshot??zee(s),i=this.store.schema.migrateStoreSnapshot({store:s,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),t(new Error(`Failed to migrate store: ${i.reason}`));return}const a=Object.values(i.value).filter(l=>this.documentTypes.has(l.typeName));a.length>0&&this.store.mergeRemoteChanges(()=>{this.store.put(a,"initialize")}),o&&Nk(this.store,o,{forceOverwrite:!0})}this.channel.onmessage=({data:s})=>{var a,l;this.debug("got message",s);const o=s,i=this.store.schema.getMigrationsSince(o.schema);if(i.ok){if(i.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}}else{if(Date.now()-this.initTime<5e3){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}o.type==="diff"&&(this.debug("applying diff"),to(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(o.changes)})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),e(this)}catch(s){if(this.debug("error loading data from store",s),this.didDispose)return;t(s);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(e=>e())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?$re:Bre))}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(Ve(!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=zI(e.filter(r=>r!==$j));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),Fre(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function W$(n){const e=k.useRef(n),[t,r]=k.useState(n);t!==e.current&&r(e.current);const s=k.useCallback(o=>{typeof o=="function"?e.current=o(e.current):e.current=o,r(e.current)},[]);return[t,s]}function Vre(n){const[e,t]=W$({status:"loading"});return n=_h(n),k.useEffect(()=>{const{persistenceKey:r,sessionId:s,...o}=n;if(!r){t({status:"not-synced",store:zp(o)});return}t({status:"loading"});const i=new zo,a={upload:async(h,p)=>(await u.db.storeAsset(h.id,p),{src:h.id}),resolve:async h=>h.props.src?h.props.src.startsWith("asset:")?await i.get(h,async()=>{const p=await u.db.getAsset(h.id);return p?URL.createObjectURL(p):null}):h.props.src:null,remove:async h=>{await u.db.removeAssets(h)},...o.assets},l=zp({...o,assets:a});let c=!1;const u=new Wre(l,{sessionId:s,persistenceKey:r,onLoad(){c||t({store:l,status:"synced-local"})},onLoadError(h){c||t({status:"error",error:h})}});return()=>{c=!0,u.close()}},[n,t]),e}function Gre(){const n=ne(),e=_n();k.useEffect(()=>{const t=o=>e.style.setProperty("--tl-zoom",o.toString()),r=r0(t,100),s=new Mu("useZoomCss",()=>{n.getCurrentPageShapeIds().size<300?t(n.getZoomLevel()):r(n.getZoomLevel())});return s.attach(),s.execute(),()=>{s.detach(),r.cancel()}},[n,e])}function Wk(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 qre(n){const e=atob(n),t=Wk(e);return crypto.subtle.importKey("spki",new Uint8Array(t),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const Yre=5,Wf={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},Xre=Math.max(...Object.values(Wf)),Vf={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},Zre=Object.keys(Vf).length,XC="sales@tldraw.com",Jre=`${An()}/watermarks/watermark-track.svg`;class D0{constructor(e,t,r){R(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");R(this,"isDevelopment");R(this,"isTest");R(this,"isCryptoAvailable");R(this,"state",hn("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 o=Qre(s);!this.isDevelopment&&o&&di(Jre),o?this.state.set("unlicensed"):s.isLicensedWithWatermark?this.state.set("licensed-with-watermark"):this.state.set("licensed")})}getIsDevelopment(e){return e==="development"?!0:e==="production"?!1:!["https:","vscode-webview:"].includes(window.location.protocol)||window.location.hostname==="localhost"}async extractLicenseKey(e){const[t,r]=e.split("."),[s,o]=t.split("/");if(!s.startsWith("tldraw-"))throw new Error(`Unsupported prefix '${s}'`);const i=await qre(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(Wk(atob(r))),new Uint8Array(Wk(atob(o))))}catch(c){throw console.error(c),new Error("Could not perform signature validation")}if(!a)throw new Error("Invalid signature");let l;try{l=JSON.parse(atob(o))}catch{throw new Error("Could not parse object")}return l.length>Zre&&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[Vf.ID],hosts:l[Vf.HOSTS],flags:l[Vf.FLAGS],expiryDate:l[Vf.EXPIRY_DATE]}}async getLicenseFromKey(e){if(!e)return this.isDevelopment||this.outputNoLicenseKeyProvided(),{isLicenseParseable:!1,reason:"no-key-provided"};if(this.isDevelopment&&!this.isCryptoAvailable)return this.verbose&&(console.log("tldraw: you seem to be in a development environment that does not support crypto. License not verified."),console.log("You should check that this works in production separately.")),{isLicenseParseable:!1,reason:"has-key-development-mode"};let t=e.replace(/[\u200B-\u200D\uFEFF]/g,"");t=t.replace(/\r?\n|\r/g,"");try{const r=await this.extractLicenseKey(t),s=new Date(r.expiryDate),o=this.isFlagEnabled(r.flags,Wf.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,Wf.PERPETUAL_LICENSE),a={license:r,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(r),expiryDate:s,isAnnualLicense:o,isAnnualLicenseExpired:o&&this.isAnnualLicenseExpired(s),isPerpetualLicense:i,isPerpetualLicenseExpired:i&&this.isPerpetualLicenseExpired(s),isInternalLicense:this.isFlagEnabled(r.flags,Wf.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,Wf.WITH_WATERMARK)};return this.outputLicenseInfoIfNeeded(a),a}catch(r){return this.outputInvalidLicenseKey(r.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(e){const t=window.location.hostname.toLowerCase();return e.hosts.some(r=>{const s=r.toLowerCase().trim();if(s===t||`www.${s}`===t||s===`www.${t}`||r==="*")return!0;if(r.includes("*")){const o=new RegExp(r.replace(/\*/g,".*?"));return o.test(t)||o.test(`www.${t}`)}if(window.location.protocol==="vscode-webview:"){const i=new URL(window.location.href).searchParams.get("extensionId");if(s===i)return!0}return!1})}getExpirationDateWithoutGracePeriod(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}getExpirationDateWithGracePeriod(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+Yre+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(WD.major),minor:new Date(WD.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>=Xre*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(D0,"className","tl-watermark_SEE-LICENSE");function Qre(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 V$=k.createContext({}),ese=()=>k.useContext(V$);function tse({licenseKey:n,children:e}){const[t]=k.useState(()=>new D0(n));return g.jsx(V$.Provider,{value:t,children:e})}function rl(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=_n();k.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;const o=n.current;if(o&&o.scrollHeight>o.clientHeight)return;nt(s);const i=e.querySelector(".tl-canvas");if(!i)return;const a=new WheelEvent("wheel",s);a.isSpecialRedispatchedEvent=!0,i.dispatchEvent(a)}const r=n.current;if(r)return r.addEventListener("wheel",t,{passive:!1}),()=>{r.removeEventListener("wheel",t)}},[e,n])}const nse='<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>',rse='<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 sse(n){return se("watermarkState",()=>n.state.get(),[n])}const ose=`data:image/svg+xml;utf8,${encodeURIComponent(nse)}`,ise=`data:image/svg+xml;utf8,${encodeURIComponent(rse)}`,ase=k.memo(function(){const e=ese(),t=ne(),r=se("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),s=sse(e);return["licensed-with-watermark","unlicensed"].includes(s)?g.jsxs(g.Fragment,{children:[g.jsx(cse,{}),g.jsx(lse,{src:r?ise:ose})]}):null}),lse=k.memo(function({src:e}){const t=ne(),r=se("debug mode",()=>t.getInstanceState().isDebugMode,[t]),s=se("is mobile",()=>t.getViewportScreenBounds().width<700,[t]),o=rT(),i=k.useRef(null);rl(i);const a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark";return g.jsx("div",{ref:i,className:D0.className,"data-debug":r,"data-mobile":s,draggable:!1,...o,children:g.jsx("button",{draggable:!1,role:"button",onPointerDown:c=>{Yt(c),nt(c)},title:"made with tldraw",onClick:()=>C0.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}})})}),cse=k.memo(function(){const e=ne(),t=D0.className,r=`/* ------------------- SEE LICENSE -------------------
128
+ The tldraw watermark is part of tldraw's license. It is shown for unlicensed
129
+ or "licensed-with-watermark" users. By using this library, you agree to
130
+ preserve the watermark's behavior, keeping it visible, unobscured, and
131
+ available to user-interaction.
132
+
133
+ To remove the watermark, please purchase a license at tldraw.dev.
134
+ */
135
+
136
+ .${t} {
137
+ position: absolute;
138
+ bottom: var(--space-2);
139
+ right: var(--space-2);
140
+ width: 96px;
141
+ height: 32px;
142
+ display: flex;
143
+ align-items: center;
144
+ justify-content: center;
145
+ z-index: var(--layer-watermark) !important;
146
+ background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
147
+ opacity: 1;
148
+ border-radius: 5px;
149
+ pointer-events: all;
150
+ padding: 2px;
151
+ box-sizing: content-box;
152
+ }
153
+
154
+ .${t} > button {
155
+ position: absolute;
156
+ width: 96px;
157
+ height: 32px;
158
+ pointer-events: all;
159
+ cursor: inherit;
160
+ color: var(--color-text);
161
+ opacity: .38;
162
+ border: 0;
163
+ padding: 0;
164
+ background-color: currentColor;
165
+ }
166
+
167
+ .${t}[data-debug='true'] {
168
+ bottom: 46px;
169
+ }
170
+
171
+ .${t}[data-mobile='true'] {
172
+ border-radius: 4px 0px 0px 4px;
173
+ right: -2px;
174
+ width: 8px;
175
+ height: 48px;
176
+ }
177
+
178
+ .${t}[data-mobile='true'] > button {
179
+ width: 8px;
180
+ height: 32px;
181
+ }
182
+
183
+ @media (hover: hover) {
184
+ .${t} > button {
185
+ pointer-events: none;
186
+ }
187
+
188
+ .${t}:hover {
189
+ background-color: var(--color-background);
190
+ transition: background-color 0.2s ease-in-out;
191
+ transition-delay: 0.32s;
192
+ }
193
+
194
+ .${t}:hover > button {
195
+ animation: delayed_link 0.2s forwards ease-in-out;
196
+ animation-delay: 0.32s;
197
+ }
198
+
199
+ .${t} > button:focus-visible {
200
+ opacity: 1;
201
+ }
202
+ }
203
+
204
+
205
+ @keyframes delayed_link {
206
+ 0% {
207
+ cursor: inherit;
208
+ opacity: .38;
209
+ pointer-events: none;
210
+ }
211
+ 100% {
212
+ cursor: pointer;
213
+ opacity: 1;
214
+ pointer-events: all;
215
+ }
216
+ }`;return g.jsx("style",{nonce:e.options.nonce,children:r})}),use=[],dse=[],hse=[],fse="tl-container",pse=k.memo(function({store:e,components:t,className:r,user:s,options:o,...i}){const[a,l]=k.useState(null),c=k.useMemo(()=>s??D4(),[s]),u=(t==null?void 0:t.ErrorFallback)===void 0?k4:t==null?void 0:t.ErrorFallback,h={...i,shapeUtils:i.shapeUtils??use,bindingUtils:i.bindingUtils??dse,tools:i.tools??hse,components:t,options:_h(o)};return g.jsx("div",{ref:l,"data-tldraw":Y5,draggable:!1,className:$e(`${fse} tl-theme__light`,r),onPointerDown:Yt,tabIndex:-1,role:"application","aria-label":(o==null?void 0:o.branding)??"tldraw",children:g.jsx(Fp,{fallback:u,onError:p=>uI(p,{tags:{origin:"react.tldraw-before-app"}}),children:a&&g.jsx(tse,{licenseKey:i.licenseKey,children:g.jsx(n4,{container:a,children:g.jsx(Pee,{overrides:t,children:e?e instanceof BI?g.jsx(q$,{...h,store:e,user:c}):g.jsx(G$,{...h,store:e,user:c}):g.jsx(gse,{...h,store:e,user:c})})})})})})});function gse(n){const{defaultName:e,snapshot:t,initialData:r,shapeUtils:s,bindingUtils:o,persistenceKey:i,sessionId:a,user:l,assets:c,migrations:u}=n,h=Vre({shapeUtils:s,bindingUtils:o,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:t,assets:c,migrations:u});return g.jsx(G$,{...n,store:h,user:l})}const G$=k.memo(function({store:e,user:t,...r}){const s=_n();k.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,t]);const{LoadingScreen:o}=Ft();switch(e.status){case"error":throw e.error;case"loading":return o?g.jsx(o,{}):null}return g.jsx(q$,{...r,store:e.store,user:t})}),ZC=()=>document.location.search.includes("tldraw_preserve_focus");function q$({onMount:n,children:e,store:t,tools:r,shapeUtils:s,bindingUtils:o,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,textOptions:h,options:p,licenseKey:m,deepLinks:S,isShapeHidden:v,getShapeVisibility:y,assetUrls:w}){const{ErrorFallback:C}=Ft(),T=_n(),[E,_]=W$(null),A=k.useRef(null),O=_h(S===!0?{}:S),D=k.useRef({autoFocus:l&&!ZC(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:O});k.useLayoutEffect(()=>{D.current={autoFocus:l&&!ZC(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:O}},[l,c,a,u,O]),k.useLayoutEffect(()=>{const{autoFocus:z,inferDarkMode:G,initialState:q,cameraOptions:$,deepLinks:K}=D.current,J=new ke({store:t,shapeUtils:s,bindingUtils:o,tools:r,getContainer:()=>T,user:i,initialState:q,autoFocus:z,inferDarkMode:G,cameraOptions:$,textOptions:h,options:p,licenseKey:m,isShapeHidden:v,getShapeVisibility:y,fontAssetUrls:w==null?void 0:w.fonts});return J.updateViewportScreenBounds(A.current??T),K&&(K!=null&&K.getUrl?J.navigateToDeepLink({...K,url:K.getUrl(J)}):J.navigateToDeepLink(K)),_(J),()=>{J.dispose()}},[o,T,p,s,t,r,i,_,m,v,y,h,w]),k.useLayoutEffect(()=>{if(E&&O)return E.registerDeepLinkListener(O)},[E,O]),k.useLayoutEffect(()=>{E&&u&&E.setCameraOptions(u)},[E,u]);const F=k.useSyncExternalStore(k.useCallback(z=>E?(E.on("crash",z),()=>E.off("crash",z)):()=>{},[E]),()=>(E==null?void 0:E.getCrashingError())??null);k.useEffect(function(){if(!E)return;function G(){E&&E.focus()}function q(){E&&E.blur()}if(l&&ZC())return E.getContainer().addEventListener("pointerdown",G),document.body.addEventListener("pointerdown",q),()=>{var $;($=E.getContainer())==null||$.removeEventListener("pointerdown",G),document.body.removeEventListener("pointerdown",q)}},[E,l]);const[U,V]=k.useState(null);let Y=U;E!==(Y==null?void 0:Y.editor)&&(Y=null),k.useEffect(()=>{if(!E)return;let z=!1;return V({editor:E,isLoaded:!1}),E.fonts.loadRequiredFontsForCurrentPage(E.options.maxFontsToLoadBeforeRender).finally(()=>{z||V({editor:E,isLoaded:!0})}),()=>{z=!0}},[E]);const{Canvas:j,LoadingScreen:N}=Ft();return!E||!(Y!=null&&Y.isLoaded)?g.jsxs(g.Fragment,{children:[N&&g.jsx(N,{}),g.jsx("div",{className:"tl-canvas",ref:A})]}):g.jsx(Fp,{fallback:C,onError:z=>E.annotateError(z,{origin:"react.tldraw",willCrashApp:!0}),children:F?g.jsx(yse,{crashingError:F}):g.jsx(eT,{editor:E,children:g.jsxs(mse,{onMount:n,children:[e??(j?g.jsx(j,{},E.contextId):null),g.jsx(ase,{})]})})})}function mse({children:n,onMount:e}){return Gre(),Sre(),xre(),vre(),X$(t=>{const r=t.store.props.onMount(t),s=e==null?void 0:e(t);return()=>{r==null||r(),s==null||s()}}),n}function yse({crashingError:n}){throw n}function Y$({children:n}){return g.jsx("div",{className:"tl-loading","aria-busy":"true",tabIndex:0,children:n})}function X$(n){const e=ne(),t=Oa(r=>{let s;return r.run(()=>{s=n==null?void 0:n(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});We.useLayoutEffect(()=>{if(e)return t==null?void 0:t(e)},[e,t])}function Xl({children:n,className:e="",...t}){return g.jsx("div",{...t,className:$e("tl-html-container",e),children:n})}class Zy{constructor(e){this.editor=e}}R(Zy,"props"),R(Zy,"migrations"),R(Zy,"type");function j0(n,e,t={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=t;let h=n.props.w*o,p=n.props.h*i;const m=new P(0,0);if(h>0){if(h<a){switch(s){case"top_left":case"left":case"bottom_left":{m.x=h-a;break}case"top":case"bottom":{m.x=(h-a)/2;break}default:m.x=0}h=a}}else if(m.x=h,h=-h,h<a){switch(s){case"top_left":case"left":case"bottom_left":{m.x=-h;break}default:m.x=-a}h=a}if(p>0){if(p<c){switch(s){case"top_left":case"top":case"top_right":{m.y=p-c;break}case"right":case"left":{m.y=(p-c)/2;break}default:m.y=0}p=c}}else if(m.y=p,p=-p,p<c){switch(s){case"top_left":case"top":case"top_right":{m.y=-p;break}default:m.y=-c}p=c}const{x:S,y:v}=m.rot(n.rotation).add(r);return{...n,x:S,y:v,props:{w:Math.min(l,h),h:Math.min(u,p)}}}class Rh extends fi{getGeometry(e){return new Zi({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return j0(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,r){return{...t.props,w:rt(e.props.w,t.props.w,r),h:rt(e.props.h,t.props.h,r)}}}function Z$(n,{initialBounds:e,scaleX:t,scaleY:r,newPoint:s,handle:o}){let i;switch(o){case"bottom_left":case"bottom_right":case"top_left":case"top_right":{i=Math.max(.01,Math.max(Math.abs(t),Math.abs(r)));break}case"left":case"right":{i=Math.max(.01,Math.abs(t));break}case"bottom":case"top":{i=Math.max(.01,Math.abs(r));break}default:throw xt(o)}const a=new P(0,0);t<0&&(a.x=-(e.width*i)),r<0&&(a.y=-(e.height*i));const{x:l,y:c}=P.Add(s,a.rot(n.rotation));return{x:l,y:c,props:{scale:i*n.props.scale}}}var QP;let Sse=(QP=class extends Le{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},R(QP,"id","idle"),QP);var ek;let xse=(ek=class extends Le{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=this.parent.shapeType,s=Nt(),o=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),i=lo(t,this.editor);this.editor.createShapes([{id:s,type:r,x:i.x,y:i.y,props:{w:1,h:1}}]).select(s);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?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=Nt();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:t,x:e.x,y:e.y}]);const s=this.editor.getShape(r);if(!s){this.cancel();return}let{w:o,h:i}=s.props;const a=new P(o/2,i/2),l=this.editor.getShapeParentTransform(s);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),o*=c,i*=c,a.mul(c));const u=en(s),h=lo(new P(s.x-a.x,s.y-a.y),this.editor);u.x=h.x,u.y=h.y,u.props.w=o,u.props.h=i,"scale"in s.props&&(u.props.scale=c),this.editor.updateShape(u),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},R(ek,"id","pointing"),ek);function lo(n,e){const t=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return t?n.clone().snapToGrid(r):n.clone()}class Vk extends Le{static children(){return[Sse,xse]}}R(Vk,"id","box"),R(Vk,"initial","idle");function vse(n,e,t){const r=k.useRef(!1),s=k.useCallback(i=>{r.current=i,i?Xr.addOpenMenu(n):Xr.deleteOpenMenu(n),e==null||e(i)},[n,e]),o=se("is menu open",()=>Xr.getOpenMenus().includes(n),[n]);return k.useEffect(()=>(r.current&&(t==null||t("open-menu"),Xr.addOpenMenu(n)),()=>{r.current&&(Xr.deleteOpenMenu(n),Xr.getOpenMenus().forEach(i=>{i.startsWith(n)&&(t==null||t("close-menu"),Xr.deleteOpenMenu(i))}),r.current=!1)}),[n,t]),[o,s]}function Tg(n){const e=ne();return se("isEditing",()=>e.getEditingShapeId()===n,[e,n])}function wse(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=_n();k.useEffect(()=>{function t(s){if(s.isSpecialRedispatchedEvent)return;nt(s);const o=e.querySelector(".tl-canvas");if(!o)return;const i=new PointerEvent(s.type,s);i.isSpecialRedispatchedEvent=!0,o.dispatchEvent(i)}const r=n.current;if(r)return r.addEventListener("mouseover",t,{passive:!1}),()=>{r.removeEventListener("mouseover",t)}},[e,n])}function zi(n){const e=ne();return k.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===nT){e.dispatch({type:"pointer",target:"selection",handle:n,name:"right_click",...Js(c)});return}if(c.button!==0)return;const u=WS(c.currentTarget);function h(){u.removeEventListener("pointerup",h),xg(u,c)}Sg(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:n,...Js(c)}),Yt(c)};let o,i;function a(c){c.isKilled||c.button===0&&(c.clientX===o&&c.clientY===i||(o=c.clientX,i=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:n,...Js(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:n,...Js(c)})}}},[e,n])}function bse(n){const[e,t]=k.useState(()=>({store:zp(n),opts:n}));if(!Q3(e.opts,n)){const r={store:zp(n),opts:n};return t(r),r.store}return e.store}const Cse=20,Pse=8;function wT(n,e=Cse){return Math.max(Pse,Math.ceil(n/e))}class Ud extends nl{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:o,start:i,end:a}=t;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=P.Angle(r,i),this.angleEnd=P.Angle(r,a),this.radius=P.Dist(r,i),this.measure=oJ(this.angleStart,this.angleEnd,s,o),this.start=i,this.end=a,this.sweepFlag=s,this.largeArcFlag=o,this._center=r}nearestPoint(t){const{_center:r,measure:s,radius:o,angleEnd:i,angleStart:a,start:l,end:c}=this,u=qD(s,a,i,r.angle(t));if(u<=0)return l;if(u>=1)return c;const h=P.Sub(t,r).uni().mul(o).add(r);let p,m=1/0,S;for(const v of[l,c,h])S=P.Dist2(t,v),S<m&&(p=v,m=S);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(t,r){const{_center:s,radius:o,measure:i,angleStart:a,angleEnd:l}=this,c=bg(t,r,s,o);return c===null?!1:c.some(u=>{const h=qD(i,a,l,s.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:t,measure:r,length:s,radius:o,angleStart:i}=this,a=[];for(let l=0,c=wT(Math.abs(s));l<c+1;l++){const u=l/c*r,h=i+u;a.push(v0(t,o,h))}return a}getSvgPathData(t=!0){const{start:r,end:s,radius:o,largeArcFlag:i,sweepFlag:a}=this;return`${t?`M${r.toFixed()}`:""} A${o} ${o} 0 ${i} ${a} ${s.toFixed()}`}getLength(){return Math.abs(this.measure*this.radius)}}class bT extends nl{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:o}=t;this.x=r,this.y=s,this._center=new P(o+r,o+s),this.radius=o}getBounds(){return new ye(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,s=Dt*r,o=[];for(let i=0,a=wT(s);i<a;i++){const l=i/a*Dt;o.push(v0(t,r,l))}return o}nearestPoint(t){const{_center:r,radius:s}=this;return r.equals(t)?P.AddXY(r,s,0):P.Sub(t,r).uni().mul(s).add(r)}hitTestLineSegment(t,r,s=0){const{_center:o,radius:i}=this;return bg(t,r,o,i+s)!==null}getSvgPathData(){const{_center:t,radius:r}=this;return`M${t.x+r},${t.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class Dr extends fc{constructor(t){const{start:r,cp1:s,cp2:o,end:i}=t;super({...t,points:[r,i]});R(this,"a");R(this,"b");R(this,"c");R(this,"d");this.a=r,this.b=s,this.c=o,this.d=i}getVertices(){const t=[],{a:r,b:s,c:o,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;t.push(new P((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*s.x+3*(1-c)*(c*c)*o.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*s.y+3*(1-c)*(c*c)*o.y+c*c*c*i.y))}return t}midPoint(){return Dr.GetAtT(this,.5)}nearestPoint(t){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(t),o=P.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}getSvgPathData(t=!0){const{a:r,b:s,c:o,d:i}=this;return`${t?`M ${r.toFixed()} `:""} C${s.toFixed()} ${o.toFixed()} ${i.toFixed()}`}static GetAtT(t,r){const{a:s,b:o,c:i,d:a}=t;return new P((1-r)*(1-r)*(1-r)*s.x+3*((1-r)*(1-r))*r*o.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*s.y+3*((1-r)*(1-r))*r*o.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(t,r=32){let s,o=this.a,i=0;for(let a=1;a<=r;a++)s=Dr.GetAtT(this,a/r),i+=P.Dist(o,s),o=s;return i}}class kse extends nl{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,o=1.25;for(let i=0;i<r-1;i++){const a=i===0?t[0]:t[i-1],l=t[i],c=t[i+1],u=i===s?c:t[i+2],h=l,p=i===0?a:new P(l.x+(c.x-a.x)/6*o,l.y+(c.y-a.y)/6*o),m=i===s?c:new P(c.x-(u.x-l.x)/6*o,c.y-(u.y-l.y)/6*o),S=c;this._segments.push(new Dr({start:h,cp1:p,cp2:m,end:S}))}}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){const t=this.segments.reduce((r,s)=>r.concat(s.vertices),[]);return t.push(this.points[this.points.length-1]),t}nearestPoint(t){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(t),o=P.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.segments.some(s=>s.hitTestLineSegment(t,r))}getSvgPathData(){let t=this.segments.reduce((r,s,o)=>r+s.getSvgPathData(o===0),"");return this.isClosed&&(t+="Z"),t}}class Ese extends nl{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 o=t[r],i=t[(r+1)%s];this._edges.push(new Ra({start:o,end:i}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),s=t/2,o=r/2,i=Math.pow(s-o,2)/Math.pow(s+o,2),a=bt*(s+o)*(1+3*i/(10+Math.sqrt(4-3*i))),l=wT(a),c=Dt/l,u=Math.cos(c),h=Math.sin(c);let p=0,m=1,S=0,v=1;const y=Array(l);for(let w=0;w<l;w++)y[w]=new P(s+s*m,o+o*p),S=h*m+u*p,v=u*m-h*p,p=S,m=v;return y}nearestPoint(t){let r,s=1/0,o,i;for(const a of this.edges)i=a.nearestPoint(t),o=P.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.edges.some(s=>s.hitTestLineSegment(t,r))}getBounds(){return new ye(0,0,this.w,this.h)}getLength(){const{w:t,h:r}=this,s=t/2,o=r/2,i=Math.max(0,s),a=Math.max(0,o);return Z5(i,a)}getSvgPathData(t=!1){const{w:r,h:s}=this,o=r/2,i=s/2,a=Math.max(0,o),l=Math.max(0,i);return`${t?`M${o-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class Ise extends nl{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 o=r/2;this.a=new Ud({start:new P(0,o),end:new P(r,o),center:new P(r/2,o),sweepFlag:1,largeArcFlag:1}),this.b=new Ra({start:new P(r,o),end:new P(r,s-o)}),this.c=new Ud({start:new P(r,s-o),end:new P(0,s-o),center:new P(r/2,s-o),sweepFlag:1,largeArcFlag:1}),this.d=new Ra({start:new P(0,s-o),end:new P(0,o)})}else{const o=s/2;this.a=new Ud({start:new P(o,s),end:new P(o,0),center:new P(o,o),sweepFlag:1,largeArcFlag:1}),this.b=new Ra({start:new P(o,0),end:new P(r-o,0)}),this.c=new Ud({start:new P(r-o,0),end:new P(r-o,s),center:new P(r-o,o),sweepFlag:1,largeArcFlag:1}),this.d=new Ra({start:new P(r-o,s),end:new P(o,s)})}}nearestPoint(t){let r,s=1/0,o,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(t),o=P.Dist2(i,t),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){const{a:s,b:o,c:i,d:a}=this;return[s,o,i,a].some(l=>l.hitTestLineSegment(t,r))}getVertices(){const{a:t,b:r,c:s,d:o}=this;return[t,r,s,o].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new ye(0,0,this.w,this.h)}getLength(){const{h:t,w:r}=this;return t>r?(bt*(r/2)+(t-r))*2:(bt*(t/2)+(r-t))*2}getSvgPathData(){const{a:t,b:r,c:s,d:o}=this;return[t,r,s,o].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}function ar(n){this.content=n}ar.prototype={constructor:ar,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),o=r.content.slice();return s==-1?o.push(t||n,e):(o[s+1]=e,t&&(o[s]=t)),new ar(o)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new ar(t)},addToStart:function(n,e){return new ar([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new ar(t)},addBefore:function(n,e,t){var r=this.remove(e),s=r.content.slice(),o=r.find(n);return s.splice(o==-1?s.length:o,0,e,t),new ar(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=ar.from(n),n.size?new ar(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=ar.from(n),n.size?new ar(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=ar.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}};ar.from=function(n){if(n instanceof ar)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new ar(e)};function J$(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),o=e.child(r);if(s==o){t+=s.nodeSize;continue}if(!s.sameMarkup(o))return t;if(s.isText&&s.text!=o.text){for(let i=0;s.text[i]==o.text[i];i++)t++;return t}if(s.content.size||o.content.size){let i=J$(s.content,o.content,t+1);if(i!=null)return i}t+=s.nodeSize}}function Q$(n,e,t,r){for(let s=n.childCount,o=e.childCount;;){if(s==0||o==0)return s==o?null:{a:t,b:r};let i=n.child(--s),a=e.child(--o),l=i.nodeSize;if(i==a){t-=l,r-=l;continue}if(!i.sameMarkup(a))return{a:t,b:r};if(i.isText&&i.text!=a.text){let c=0,u=Math.min(i.text.length,a.text.length);for(;c<u&&i.text[i.text.length-c-1]==a.text[a.text.length-c-1];)c++,t--,r--;return{a:t,b:r}}if(i.content.size||a.content.size){let c=Q$(i.content,a.content,t-1,r-1);if(c)return c}t-=l,r-=l}}class me{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,o){for(let i=0,a=0;a<t;i++){let l=this.content[i],c=a+l.nodeSize;if(c>e&&r(l,s+a,o||null,i)!==!1&&l.content.size){let u=a+1;l.nodesBetween(Math.max(0,e-u),Math.min(l.content.size,t-u),r,s+u)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,s){let o="",i=!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&&(i?i=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,s=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(s[s.length-1]=t.withText(t.text+r.text),o=1);o<e.content.length;o++)s.push(e.content[o]);return new me(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 o=0,i=0;i<t;o++){let a=this.content[o],l=i+a.nodeSize;l>e&&((i<e||l>t)&&(a.isText?a=a.cut(Math.max(0,e-i),Math.min(a.text.length,t-i)):a=a.cut(Math.max(0,e-i-1),Math.min(a.content.size,t-i-1))),r.push(a),s+=a.nodeSize),i=l}return new me(r,s)}cutByIndex(e,t){return e==t?me.empty:e==0&&t==this.content.length?this:new me(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let s=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return s[e]=t,new me(s,o)}addToStart(e){return new me([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new me(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 J$(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return Q$(this,e,t,r)}findIndex(e,t=-1){if(e==0)return ly(0,e);if(e==this.size)return ly(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 o=this.child(r),i=s+o.nodeSize;if(i>=e)return i==e||t>0?ly(r+1,i):ly(r,s);s=i}}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 me.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new me(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return me.empty;let t,r=0;for(let s=0;s<e.length;s++){let o=e[s];r+=o.nodeSize,s&&o.isText&&e[s-1].sameMarkup(o)?(t||(t=e.slice(0,s)),t[t.length-1]=o.withText(t[t.length-1].text+o.text)):t&&t.push(o)}return new me(t||e,r)}static from(e){if(!e)return me.empty;if(e instanceof me)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new me([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}me.empty=new me([],0);const JC={index:0,offset:0};function ly(n,e){return JC.index=n,JC.offset=e,JC}function XS(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(!XS(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!XS(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}let Ut=class Gk{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let s=0;s<e.length;s++){let o=e[s];if(this.eq(o))return e;if(this.type.excludes(o.type))t||(t=e.slice(0,s));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(t||(t=e.slice(0,s)),t.push(this),r=!0),t&&t.push(o)}}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&&XS(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 Gk.none;if(e instanceof Gk)return[e];let t=e.slice();return t.sort((r,s)=>r.type.rank-s.type.rank),t}};Ut.none=[];class ZS extends Error{}class _e{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=t6(this.content,e+this.openStart,t);return r&&new _e(r,this.openStart,this.openEnd)}removeBetween(e,t){return new _e(e6(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 _e.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 _e(me.fromJSON(e,t.content),r,s)}static maxOpen(e,t=!0){let r=0,s=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)s++;return new _e(e,r,s)}}_e.empty=new _e(me.empty,0,0);function e6(n,e,t){let{index:r,offset:s}=n.findIndex(e),o=n.maybeChild(r),{index:i,offset:a}=n.findIndex(t);if(s==e||o.isText){if(a!=t&&!n.child(i).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=i)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(e6(o.content,e-s-1,t-s-1)))}function t6(n,e,t,r){let{index:s,offset:o}=n.findIndex(e),i=n.maybeChild(s);if(o==e||i.isText)return n.cut(0,e).append(t).append(n.cut(e));let a=t6(i.content,e-o-1,t);return a&&n.replaceChild(s,i.copy(a))}function Tse(n,e,t){if(t.openStart>n.depth)throw new ZS("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new ZS("Inconsistent open depths");return n6(n,e,t,0)}function n6(n,e,t,r){let s=n.index(r),o=n.node(r);if(s==e.index(r)&&r<n.depth-t.openStart){let i=n6(n,e,t,r+1);return o.copy(o.content.replaceChild(s,i))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let i=n.parent,a=i.content;return au(i,a.cut(0,n.parentOffset).append(t.content).append(a.cut(e.parentOffset)))}else{let{start:i,end:a}=_se(t,n);return au(o,s6(n,i,a,e,r))}else return au(o,JS(n,e,r))}function r6(n,e){if(!e.type.compatibleContent(n.type))throw new ZS("Cannot join "+e.type.name+" onto "+n.type.name)}function qk(n,e,t){let r=n.node(t);return r6(r,e.node(t)),r}function iu(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 gp(n,e,t,r){let s=(e||n).node(t),o=0,i=e?e.index(t):s.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(iu(n.nodeAfter,r),o++));for(let a=o;a<i;a++)iu(s.child(a),r);e&&e.depth==t&&e.textOffset&&iu(e.nodeBefore,r)}function au(n,e){return n.type.checkContent(e),n.copy(e)}function s6(n,e,t,r,s){let o=n.depth>s&&qk(n,e,s+1),i=r.depth>s&&qk(t,r,s+1),a=[];return gp(null,n,s,a),o&&i&&e.index(s)==t.index(s)?(r6(o,i),iu(au(o,s6(n,e,t,r,s+1)),a)):(o&&iu(au(o,JS(n,e,s+1)),a),gp(e,t,s,a),i&&iu(au(i,JS(t,r,s+1)),a)),gp(r,null,s,a),new me(a)}function JS(n,e,t){let r=[];if(gp(null,n,t,r),n.depth>t){let s=qk(n,e,t+1);iu(au(s,JS(n,e,t+1)),r)}return gp(e,null,t,r),new me(r)}function _se(n,e){let t=e.depth-n.openStart,s=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)s=e.node(o).copy(me.from(s));return{start:s.resolveNoCache(n.openStart+t),end:s.resolveNoCache(s.content.size-n.openEnd-t)}}class Bp{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 o=0;o<e;o++)s+=r.child(o).nodeSize;return s}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return Ut.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 o=r.marks;for(var i=0;i<o.length;i++)o[i].type.spec.inclusive===!1&&(!s||!o[i].isInSet(s.marks))&&(o=o[i--].removeFromSet(o));return o}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 o=0;o<r.length;o++)r[o].type.spec.inclusive===!1&&(!s||!r[o].isInSet(s.marks))&&(r=r[o--].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 QS(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,o=t;for(let i=e;;){let{index:a,offset:l}=i.content.findIndex(o),c=o-l;if(r.push(i,a,s+l),!c||(i=i.child(a),i.isText))break;o=c-1,s+=l+1}return new Bp(t,r,o)}static resolveCached(e,t){let r=Uj.get(e);if(r)for(let o=0;o<r.elts.length;o++){let i=r.elts[o];if(i.pos==t)return i}else Uj.set(e,r=new Mse);let s=r.elts[r.i]=Bp.resolve(e,t);return r.i=(r.i+1)%Ase,s}}class Mse{constructor(){this.elts=[],this.i=0}}const Ase=12,Uj=new WeakMap;class QS{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 Ose=Object.create(null);let pi=class Yk{constructor(e,t,r,s=Ut.none){this.type=e,this.attrs=t,this.marks=s,this.content=r||me.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&&XS(this.attrs,t||e.defaultAttrs||Ose)&&Ut.sameSet(this.marks,r||Ut.none)}copy(e=null){return e==this.content?this:new Yk(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Yk(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 _e.empty;let s=this.resolve(e),o=this.resolve(t),i=r?0:s.sharedDepth(t),a=s.start(i),c=s.node(i).content.cut(s.pos-a,o.pos-a);return new _e(c,s.depth-i,o.depth-i)}replace(e,t,r){return Tse(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 Bp.resolveCached(this,e)}resolveNoCache(e){return Bp.resolve(this,e)}rangeHasMark(e,t,r){let s=!1;return t>e&&this.nodesBetween(e,t,o=>(r.isInSet(o.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()+")"),o6(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=me.empty,s=0,o=r.childCount){let i=this.contentMatchAt(e).matchFragment(r,s,o),a=i&&i.matchFragment(this.content,t);if(!a||!a.validEnd)return!1;for(let l=s;l<o;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 o=this.contentMatchAt(e).matchType(r),i=o&&o.matchFragment(this.content,t);return i?i.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=Ut.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(!Ut.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=me.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,s,r);return o.type.checkAttrs(o.attrs),o}};pi.prototype.text=void 0;class ex extends pi{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):o6(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 ex(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new ex(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 o6(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class mu{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Rse(e,t);if(r.next==null)return mu.empty;let s=i6(r);r.next&&r.err("Unexpected trailing text");let o=Bse(zse(s));return $se(o,r),o}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 o=t;s&&o<r;o++)s=s.matchType(e.child(o).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 o(i,a){let l=i.matchFragment(e,r);if(l&&(!t||l.validEnd))return me.from(a.map(c=>c.createAndFill()));for(let c=0;c<i.next.length;c++){let{type:u,next:h}=i.next[c];if(!(u.isText||u.hasRequiredAttrs())&&s.indexOf(h)==-1){s.push(h);let p=o(h,a.concat(u));if(p)return p}}return null}return o(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(),o=s.match;if(o.matchType(e)){let i=[];for(let a=s;a.type;a=a.via)i.push(a.type);return i.reverse()}for(let i=0;i<o.next.length;i++){let{type:a,next:l}=o.next[i];!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 o=s+(r.validEnd?"*":" ")+" ";for(let i=0;i<r.next.length;i++)o+=(i?", ":"")+r.next[i].type.name+"->"+e.indexOf(r.next[i].next);return o}).join(`
217
+ `)}}mu.empty=new mu(!0);class Rse{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 i6(n){let e=[];do e.push(Dse(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Dse(n){let e=[];do e.push(jse(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function jse(n){let e=Fse(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=Lse(n,e);else break;return e}function Hj(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Lse(n,e){let t=Hj(n),r=t;return n.eat(",")&&(n.next!="}"?r=Hj(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Nse(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let s=[];for(let o in t){let i=t[o];i.isInGroup(e)&&s.push(i)}return s.length==0&&n.err("No node type or group '"+e+"' found"),s}function Fse(n){if(n.eat("(")){let e=i6(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=Nse(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 zse(n){let e=[[]];return s(o(n,0),t()),e;function t(){return e.push([])-1}function r(i,a,l){let c={term:l,to:a};return e[i].push(c),c}function s(i,a){i.forEach(l=>l.to=a)}function o(i,a){if(i.type=="choice")return i.exprs.reduce((l,c)=>l.concat(o(c,a)),[]);if(i.type=="seq")for(let l=0;;l++){let c=o(i.exprs[l],a);if(l==i.exprs.length-1)return c;s(c,a=t())}else if(i.type=="star"){let l=t();return r(a,l),s(o(i.expr,l),l),[r(l)]}else if(i.type=="plus"){let l=t();return s(o(i.expr,a),l),s(o(i.expr,l),l),[r(l)]}else{if(i.type=="opt")return[r(a)].concat(o(i.expr,a));if(i.type=="range"){let l=a;for(let c=0;c<i.min;c++){let u=t();s(o(i.expr,l),u),l=u}if(i.max==-1)s(o(i.expr,l),l);else for(let c=i.min;c<i.max;c++){let u=t();r(l,u),s(o(i.expr,l),u),l=u}return[r(l)]}else{if(i.type=="name")return[r(a,void 0,i.value)];throw new Error("Unknown expr type")}}}}function a6(n,e){return e-n}function Kj(n,e){let t=[];return r(e),t.sort(a6);function r(s){let o=n[s];if(o.length==1&&!o[0].term)return r(o[0].to);t.push(s);for(let i=0;i<o.length;i++){let{term:a,to:l}=o[i];!a&&t.indexOf(l)==-1&&r(l)}}}function Bse(n){let e=Object.create(null);return t(Kj(n,0));function t(r){let s=[];r.forEach(i=>{n[i].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let u=0;u<s.length;u++)s[u][0]==a&&(c=s[u][1]);Kj(n,l).forEach(u=>{c||s.push([a,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let o=e[r.join(",")]=new mu(r.indexOf(n.length-1)>-1);for(let i=0;i<s.length;i++){let a=s[i][1].sort(a6);o.next.push({type:s[i][0],next:e[a.join(",")]||t(a)})}return o}}function $se(n,e){for(let t=0,r=[n];t<r.length;t++){let s=r[t],o=!s.validEnd,i=[];for(let a=0;a<s.next.length;a++){let{type:l,next:c}=s.next[a];i.push(l.name),o&&!(l.isText||l.hasRequiredAttrs())&&(o=!1),r.indexOf(c)==-1&&r.push(c)}o&&e.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function l6(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 c6(n,e){let t=Object.create(null);for(let r in n){let s=e&&e[r];if(s===void 0){let o=n[r];if(o.hasDefault)s=o.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=s}return t}function u6(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 o=n[s];o.validate&&o.validate(e[s])}}function d6(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new Hse(n,r,e[r]);return t}let Wj=class h6{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=d6(e,r.attrs),this.defaultAttrs=l6(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==mu.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:c6(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new pi(this,this.computeAttrs(e),me.from(t),Ut.setFrom(r))}createChecked(e=null,t,r){return t=me.from(t),this.checkContent(t),new pi(this,this.computeAttrs(e),t,Ut.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=me.from(t),t.size){let i=this.contentMatch.fillBefore(t);if(!i)return null;t=i.append(t)}let s=this.contentMatch.matchFragment(t),o=s&&s.fillBefore(me.empty,!0);return o?new pi(this,e,t.append(o),Ut.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){u6(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:Ut.none:e}static compile(e,t){let r=Object.create(null);e.forEach((o,i)=>r[o]=new h6(o,t,i));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 o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Use(n,e,t){let r=t.split("|");return s=>{let o=s===null?"null":typeof s;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}class Hse{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Use(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class L0{constructor(e,t,r,s){this.name=e,this.rank=t,this.schema=r,this.spec=s,this.attrs=d6(e,s.attrs),this.excluded=null;let o=l6(this.attrs);this.instance=o?new Ut(this,o):null}create(e=null){return!e&&this.instance?this.instance:new Ut(this,c6(this.attrs,e))}static compile(e,t){let r=Object.create(null),s=0;return e.forEach((o,i)=>r[o]=new L0(o,s++,t,i)),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){u6(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class f6{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=ar.from(e.nodes),t.marks=ar.from(e.marks||{}),this.nodes=Wj.compile(this.spec.nodes,this),this.marks=L0.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 o=this.nodes[s],i=o.spec.content||"",a=o.spec.marks;if(o.contentMatch=r[i]||(r[i]=mu.parse(i,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=a=="_"?null:a?Vj(this,a.split(" ")):a==""||!o.inlineContent?[]:null}for(let s in this.marks){let o=this.marks[s],i=o.spec.excludes;o.excluded=i==null?[o]:i==""?[]:Vj(this,i.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 Wj){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 ex(r,r.defaultAttrs,e,Ut.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return pi.fromJSON(this,e)}markFromJSON(e){return Ut.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Vj(n,e){let t=[];for(let r=0;r<e.length;r++){let s=e[r],o=n.marks[s],i=o;if(o)t.push(o);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(i=l)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Kse(n){return n.tag!=null}function Wse(n){return n.style!=null}let Zd=class Xk{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(s=>{if(Kse(s))this.tags.push(s);else if(Wse(s)){let o=/[^=]*/.exec(s.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(s)}}),this.normalizeLists=!this.tags.some(s=>{if(!/^(ul|ol)\b/.test(s.tag)||!s.node)return!1;let o=e.nodes[s.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new qj(this,t,!1);return r.addAll(e,Ut.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new qj(this,t,!0);return r.addAll(e,Ut.none,t.from,t.to),_e.maxOpen(r.finish())}matchTag(e,t,r){for(let s=r?this.tags.indexOf(r)+1:0;s<this.tags.length;s++){let o=this.tags[s];if(qse(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||t.matchesContext(o.context))){if(o.getAttrs){let i=o.getAttrs(e);if(i===!1)continue;o.attrs=i||void 0}return o}}}matchStyle(e,t,r,s){for(let o=s?this.styles.indexOf(s)+1:0;o<this.styles.length;o++){let i=this.styles[o],a=i.style;if(!(a.indexOf(e)!=0||i.context&&!r.matchesContext(i.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(i.getAttrs){let l=i.getAttrs(t);if(l===!1)continue;i.attrs=l||void 0}return i}}}static schemaRules(e){let t=[];function r(s){let o=s.priority==null?50:s.priority,i=0;for(;i<t.length;i++){let a=t[i];if((a.priority==null?50:a.priority)<o)break}t.splice(i,0,s)}for(let s in e.marks){let o=e.marks[s].spec.parseDOM;o&&o.forEach(i=>{r(i=Yj(i)),i.mark||i.ignore||i.clearMark||(i.mark=s)})}for(let s in e.nodes){let o=e.nodes[s].spec.parseDOM;o&&o.forEach(i=>{r(i=Yj(i)),i.node||i.ignore||i.mark||(i.node=s)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Xk(e,Xk.schemaRules(e)))}};const p6={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},Vse={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},g6={ol:!0,ul:!0},$p=1,Zk=2,Jy=4;function Gj(n,e,t){return e!=null?(e?$p:0)|(e==="full"?Zk:0):n&&n.whitespace=="pre"?$p|Zk:t&-5}class cy{constructor(e,t,r,s,o,i){this.type=e,this.attrs=t,this.marks=r,this.solid=s,this.options=i,this.content=[],this.activeMarks=Ut.none,this.match=o||(i&Jy?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(me.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&$p)){let r=this.content[this.content.length-1],s;if(r&&r.isText&&(s=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==s[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-s[0].length))}}let t=me.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(me.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&&!p6.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class qj{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let s=t.topNode,o,i=Gj(null,t.preserveWhitespace,0)|(r?Jy:0);s?o=new cy(s.type,s.attrs,Ut.none,!0,t.topMatch||s.type.contentMatch,i):r?o=new cy(null,null,Ut.none,!0,null,i):o=new cy(e.schema.topNodeType,null,Ut.none,!0,null,i),this.nodes=[o],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,o=s.options&Zk?"full":this.localPreserveWS||(s.options&$p)>0;if(o==="full"||s.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)o!=="full"?r=r.replace(/\r?\n|\r/g," "):r=r.replace(/\r\n?/g,`
218
+ `);else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let i=s.content[s.content.length-1],a=e.previousSibling;(!i||a&&a.nodeName=="BR"||i.isText&&/[ \t\r\n\u000c]$/.test(i.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let s=this.localPreserveWS,o=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i=e.nodeName.toLowerCase(),a;g6.hasOwnProperty(i)&&this.parser.normalizeLists&&Gse(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:Vse.hasOwnProperty(i))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,u=this.needsBlock;if(p6.hasOwnProperty(i))o.content.length&&o.content[0].isInline&&this.open&&(this.open--,o=this.top),c=!0,o.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let h=l&&l.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),c&&this.sync(o),this.needsBlock=u}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(`
219
+ `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let s=0;s<this.parser.matchedStyles.length;s++){let o=this.parser.matchedStyles[s],i=r.getPropertyValue(o);if(i)for(let a=void 0;;){let l=this.parser.matchStyle(o,i,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 o,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(i,t.attrs||null,r,t.preserveWhitespace);l&&(o=!0,r=l)}else{let l=this.parser.schema.marks[t.mark];r=r.concat(l.create(t.attrs))}let a=this.top;if(i&&i.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,!1));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)}o&&this.sync(a)&&this.open--}addAll(e,t,r,s){let o=r||0;for(let i=r?e.childNodes[r]:e.firstChild,a=s==null?null:e.childNodes[s];i!=a;i=i.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(i,t);this.findAtPoint(e,o)}findPlace(e,t,r){let s,o;for(let i=this.open,a=0;i>=0;i--){let l=this.nodes[i],c=l.findWrapping(e);if(c&&(!s||s.length>c.length+a)&&(s=c,o=l,!c.length))break;if(l.solid){if(r)break;a+=2}}if(!s)return null;this.sync(o);for(let i=0;i<s.length;i++)t=this.enterInner(s[i],null,t,!1);return t}insertNode(e,t,r){if(e.isInline&&this.needsBlock&&!this.top.type){let o=this.textblockFromContext();o&&(t=this.enterInner(o,null,t))}let s=this.findPlace(e,t,r);if(s){this.closeExtra();let o=this.top;o.match&&(o.match=o.match.matchType(e.type));let i=Ut.none;for(let a of s.concat(e.marks))(o.type?o.type.allowsMarkType(a.type):Xj(a.type,e.type))&&(i=a.addToSet(i));return o.content.push(e.mark(i)),!0}return!1}enter(e,t,r,s){let o=this.findPlace(e.create(t),r,!1);return o&&(o=this.enterInner(e,t,r,!0,s)),o}enterInner(e,t,r,s=!1,o){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let a=Gj(e,o,i.options);i.options&Jy&&i.content.length==0&&(a|=Jy);let l=Ut.none;return r=r.filter(c=>(i.type?i.type.allowsMarkType(c.type):Xj(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new cy(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|=$p)}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),o=-(r?r.depth+1:0)+(s?0:1),i=(a,l)=>{for(;a>=0;a--){let c=t[a];if(c==""){if(a==t.length-1||a==0)continue;for(;l>=o;l--)if(i(a-1,l))return!0;return!1}else{let u=l>0||l==0&&s?this.nodes[l].type:r&&l>=o?r.node(l-o).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;l--}}return!0};return i(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 Gse(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&g6.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function qse(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Yj(n){let e={};for(let t in n)e[t]=n[t];return e}function Xj(n,e){let t=e.schema.nodes;for(let r in t){let s=t[r];if(!s.allowsMarkType(n))continue;let o=[],i=a=>{o.push(a);for(let l=0;l<a.edgeCount;l++){let{type:c,next:u}=a.edge(l);if(c==e||o.indexOf(u)<0&&i(u))return!0}};if(i(s.contentMatch))return!0}}class Du{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},r){r||(r=QC(t).createDocumentFragment());let s=r,o=[];return e.forEach(i=>{if(o.length||i.marks.length){let a=0,l=0;for(;a<o.length&&l<i.marks.length;){let c=i.marks[l];if(!this.marks[c.type.name]){l++;continue}if(!c.eq(o[a][0])||c.type.spec.spanning===!1)break;a++,l++}for(;a<o.length;)s=o.pop()[1];for(;l<i.marks.length;){let c=i.marks[l++],u=this.serializeMark(c,i.isInline,t);u&&(o.push([c,s]),s.appendChild(u.dom),s=u.contentDOM||u.dom)}}s.appendChild(this.serializeNodeInner(i,t))}),r}serializeNodeInner(e,t){let{dom:r,contentDOM:s}=Qy(QC(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 o=this.serializeMark(e.marks[s],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let s=this.marks[e.type.name];return s&&Qy(QC(r),s(e,t),null,e.attrs)}static renderSpec(e,t,r=null,s){return Qy(e,t,r,s)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Du(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Zj(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Zj(e.marks)}}function Zj(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function QC(n){return n.document||window.document}const Jj=new WeakMap;function Yse(n){let e=Jj.get(n);return e===void 0&&Jj.set(n,e=Xse(n)),e}function Xse(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 Qy(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],o;if(typeof s!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(o=Yse(r))&&o.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 i=s.indexOf(" ");i>0&&(t=s.slice(0,i),s=s.slice(i+1));let a,l=t?n.createElementNS(t,s):n.createElement(s),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let h in c)if(c[h]!=null){let p=h.indexOf(" ");p>0?l.setAttributeNS(h.slice(0,p),h.slice(p+1),c[h]):l.setAttribute(h,c[h])}}for(let h=u;h<e.length;h++){let p=e[h];if(p===0){if(h<e.length-1||h>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:m,contentDOM:S}=Qy(n,p,t,r);if(l.appendChild(m),S){if(a)throw new RangeError("Multiple content holes");a=S}}}return{dom:l,contentDOM:a}}const m6=65535,y6=Math.pow(2,16);function Zse(n,e){return n+e*y6}function Qj(n){return n&m6}function Jse(n){return(n-(n&m6))/y6}const S6=1,x6=2,eS=4,v6=8;class Jk{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&v6)>0}get deletedBefore(){return(this.delInfo&(S6|eS))>0}get deletedAfter(){return(this.delInfo&(x6|eS))>0}get deletedAcross(){return(this.delInfo&eS)>0}}class Xs{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Xs.empty)return Xs.empty}recover(e){let t=0,r=Qj(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+Jse(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,o=this.inverted?2:1,i=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+o],u=this.ranges[a+i],h=l+c;if(e<=h){let p=c?e==l?-1:e==h?1:t:t,m=l+s+(p<0?0:u);if(r)return m;let S=e==(t<0?l:h)?null:Zse(a/3,e-l),v=e==l?x6:e==h?S6:eS;return(t<0?e!=l:e!=h)&&(v|=v6),new Jk(m,v,S)}s+=u-c}return r?e+s:new Jk(e+s,0,null)}touches(e,t){let r=0,s=Qj(t),o=this.inverted?2:1,i=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+o],u=l+c;if(e<=u&&a==s*3)return!0;r+=this.ranges[a+i]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let s=0,o=0;s<this.ranges.length;s+=3){let i=this.ranges[s],a=i-(this.inverted?o:0),l=i+(this.inverted?0:o),c=this.ranges[s+t],u=this.ranges[s+r];e(a,a+c,l,l+u),o+=u-c}}invert(){return new Xs(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Xs.empty:new Xs(e<0?[0,-e,0]:[0,0,e])}}Xs.empty=new Xs([]);class Up{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 Up(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 Up;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 o=this.from;o<this.to;o++){let i=this._maps[o],a=i.mapResult(e,t);if(a.recover!=null){let l=this.getMirror(o);if(l!=null&&l>o&&l<this.to){o=l,e=this._maps[l].recover(a.recover);continue}}s|=a.delInfo,e=a.pos}return r?e:new Jk(e,s,null)}}const eP=Object.create(null);class zr{getMap(){return Xs.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=eP[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 eP)throw new RangeError("Duplicate use of step JSON ID "+e);return eP[e]=t,t.prototype.jsonID=e,t}}class jn{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new jn(e,null)}static fail(e){return new jn(null,e)}static fromReplace(e,t,r,s){try{return jn.ok(e.replace(t,r,s))}catch(o){if(o instanceof ZS)return jn.fail(o.message);throw o}}}function CT(n,e,t){let r=[];for(let s=0;s<n.childCount;s++){let o=n.child(s);o.content.size&&(o=o.copy(CT(o.content,e,o))),o.isInline&&(o=e(o,t,s)),r.push(o)}return me.fromArray(r)}class Vl extends zr{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)),o=new _e(CT(t.content,(i,a)=>!i.isAtom||!a.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),s),t.openStart,t.openEnd);return jn.fromReplace(e,this.from,this.to,o)}invert(){return new Gi(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 Vl(t.pos,r.pos,this.mark)}merge(e){return e instanceof Vl&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Vl(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 Vl(t.from,t.to,e.markFromJSON(t.mark))}}zr.jsonID("addMark",Vl);class Gi extends zr{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 _e(CT(t.content,s=>s.mark(this.mark.removeFromSet(s.marks)),e),t.openStart,t.openEnd);return jn.fromReplace(e,this.from,this.to,r)}invert(){return new Vl(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 Gi(t.pos,r.pos,this.mark)}merge(e){return e instanceof Gi&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Gi(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 Gi(t.from,t.to,e.markFromJSON(t.mark))}}zr.jsonID("removeMark",Gi);class Gl extends zr{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return jn.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return jn.fromReplace(e,this.pos,this.pos+1,new _e(me.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 Gl(this.pos,t.marks[s]);return new Gl(this.pos,this.mark)}}return new yu(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Gl(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 Gl(t.pos,e.markFromJSON(t.mark))}}zr.jsonID("addNodeMark",Gl);class yu extends zr{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return jn.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return jn.fromReplace(e,this.pos,this.pos+1,new _e(me.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Gl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new yu(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 yu(t.pos,e.markFromJSON(t.mark))}}zr.jsonID("removeNodeMark",yu);class Vn extends zr{constructor(e,t,r,s=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=s}apply(e){return this.structure&&Qk(e,this.from,this.to)?jn.fail("Structure replace would overwrite content"):jn.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Xs([this.from,this.to-this.from,this.slice.size])}invert(e){return new Vn(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 Vn(t.pos,Math.max(t.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Vn)||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?_e.empty:new _e(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Vn(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?_e.empty:new _e(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Vn(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 Vn(t.from,t.to,_e.fromJSON(e,t.slice),!!t.structure)}}zr.jsonID("replace",Vn);class Xn extends zr{constructor(e,t,r,s,o,i,a=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=s,this.slice=o,this.insert=i,this.structure=a}apply(e){if(this.structure&&(Qk(e,this.from,this.gapFrom)||Qk(e,this.gapTo,this.to)))return jn.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return jn.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?jn.fromReplace(e,this.from,this.to,r):jn.fail("Content does not fit in gap")}getMap(){return new Xs([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 Xn(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),o=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||s<t.pos||o>r.pos?null:new Xn(t.pos,r.pos,s,o,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 Xn(t.from,t.to,t.gapFrom,t.gapTo,_e.fromJSON(e,t.slice),t.insert,!!t.structure)}}zr.jsonID("replaceAround",Xn);function Qk(n,e,t){let r=n.resolve(e),s=t-e,o=r.depth;for(;s>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,s--;if(s>0){let i=r.node(o).maybeChild(r.indexAfter(o));for(;s>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,s--}}return!1}function Qse(n,e,t,r){let s=[],o=[],i,a;n.doc.nodesBetween(e,t,(l,c,u)=>{if(!l.isInline)return;let h=l.marks;if(!r.isInSet(h)&&u.type.allowsMarkType(r.type)){let p=Math.max(c,e),m=Math.min(c+l.nodeSize,t),S=r.addToSet(h);for(let v=0;v<h.length;v++)h[v].isInSet(S)||(i&&i.to==p&&i.mark.eq(h[v])?i.to=m:s.push(i=new Gi(p,m,h[v])));a&&a.to==p?a.to=m:o.push(a=new Vl(p,m,r))}}),s.forEach(l=>n.step(l)),o.forEach(l=>n.step(l))}function eoe(n,e,t,r){let s=[],o=0;n.doc.nodesBetween(e,t,(i,a)=>{if(!i.isInline)return;o++;let l=null;if(r instanceof L0){let c=i.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(i.marks)&&(l=[r]):l=i.marks;if(l&&l.length){let c=Math.min(a+i.nodeSize,t);for(let u=0;u<l.length;u++){let h=l[u],p;for(let m=0;m<s.length;m++){let S=s[m];S.step==o-1&&h.eq(s[m].style)&&(p=S)}p?(p.to=c,p.step=o):s.push({style:h,from:Math.max(a,e),to:c,step:o})}}}),s.forEach(i=>n.step(new Gi(i.from,i.to,i.style)))}function PT(n,e,t,r=t.contentMatch,s=!0){let o=n.doc.nodeAt(e),i=[],a=e+1;for(let l=0;l<o.childCount;l++){let c=o.child(l),u=a+c.nodeSize,h=r.matchType(c.type);if(!h)i.push(new Vn(a,u,_e.empty));else{r=h;for(let p=0;p<c.marks.length;p++)t.allowsMarkType(c.marks[p].type)||n.step(new Gi(a,u,c.marks[p]));if(s&&c.isText&&t.whitespace!="pre"){let p,m=/\r?\n|\r/g,S;for(;p=m.exec(c.text);)S||(S=new _e(me.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),i.push(new Vn(a+p.index,a+p.index+p[0].length,S))}}a=u}if(!r.validEnd){let l=r.fillBefore(me.empty,!0);n.replace(a,a,new _e(l,0,0))}for(let l=i.length-1;l>=0;l--)n.step(i[l])}function toe(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Dh(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let s=n.$from.node(r),o=n.$from.index(r),i=n.$to.indexAfter(r);if(r<n.depth&&s.canReplace(o,i,t))return r;if(r==0||s.type.spec.isolating||!toe(s,o,i))break}return null}function noe(n,e,t){let{$from:r,$to:s,depth:o}=e,i=r.before(o+1),a=s.after(o+1),l=i,c=a,u=me.empty,h=0;for(let S=o,v=!1;S>t;S--)v||r.index(S)>0?(v=!0,u=me.from(r.node(S).copy(u)),h++):l--;let p=me.empty,m=0;for(let S=o,v=!1;S>t;S--)v||s.after(S+1)<s.end(S)?(v=!0,p=me.from(s.node(S).copy(p)),m++):c++;n.step(new Xn(l,c,i,a,new _e(u.append(p),h,m),u.size-h,!0))}function kT(n,e,t=null,r=n){let s=roe(n,e),o=s&&soe(r,e);return o?s.map(eL).concat({type:e,attrs:t}).concat(o.map(eL)):null}function eL(n){return{type:n,attrs:null}}function roe(n,e){let{parent:t,startIndex:r,endIndex:s}=n,o=t.contentMatchAt(r).findWrapping(e);if(!o)return null;let i=o.length?o[0]:e;return t.canReplaceWith(r,s,i)?o:null}function soe(n,e){let{parent:t,startIndex:r,endIndex:s}=n,o=t.child(r),i=e.contentMatch.findWrapping(o.type);if(!i)return null;let l=(i.length?i[i.length-1]:e).contentMatch;for(let c=r;l&&c<s;c++)l=l.matchType(t.child(c).type);return!l||!l.validEnd?null:i}function ooe(n,e,t){let r=me.empty;for(let i=t.length-1;i>=0;i--){if(r.size){let a=t[i].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=me.from(t[i].type.create(t[i].attrs,r))}let s=e.start,o=e.end;n.step(new Xn(s,o,s,o,new _e(r,0,0),t.length,!0))}function ioe(n,e,t,r,s){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(i,a)=>{let l=typeof s=="function"?s(i):s;if(i.isTextblock&&!i.hasMarkup(r,l)&&aoe(n.doc,n.mapping.slice(o).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let m=r.whitespace=="pre",S=!!r.contentMatch.matchType(r.schema.linebreakReplacement);m&&!S?c=!1:!m&&S&&(c=!0)}c===!1&&b6(n,i,a,o),PT(n,n.mapping.slice(o).map(a,1),r,void 0,c===null);let u=n.mapping.slice(o),h=u.map(a,1),p=u.map(a+i.nodeSize,1);return n.step(new Xn(h,p,h+1,p-1,new _e(me.from(r.create(l,null,i.marks)),0,0),1,!0)),c===!0&&w6(n,i,a,o),!1}})}function w6(n,e,t,r){e.forEach((s,o)=>{if(s.isText){let i,a=/\r?\n|\r/g;for(;i=a.exec(s.text);){let l=n.mapping.slice(r).map(t+1+o+i.index);n.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function b6(n,e,t,r){e.forEach((s,o)=>{if(s.type==s.type.schema.linebreakReplacement){let i=n.mapping.slice(r).map(t+1+o);n.replaceWith(i,i+1,e.type.schema.text(`
220
+ `))}})}function aoe(n,e,t){let r=n.resolve(e),s=r.index();return r.parent.canReplaceWith(s,s+1,t)}function loe(n,e,t,r,s){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let i=t.create(r,null,s||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,i);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Xn(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new _e(me.from(i),0,0),1,!0))}function Fa(n,e,t=1,r){let s=n.resolve(e),o=s.depth-t,i=r&&r[r.length-1]||s.parent;if(o<0||s.parent.type.spec.isolating||!s.parent.canReplace(s.index(),s.parent.childCount)||!i.type.validContent(s.parent.content.cutByIndex(s.index(),s.parent.childCount)))return!1;for(let c=s.depth-1,u=t-2;c>o;c--,u--){let h=s.node(c),p=s.index(c);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(p,h.childCount),S=r&&r[u+1];S&&(m=m.replaceChild(0,S.type.create(S.attrs)));let v=r&&r[u]||h;if(!h.canReplace(p+1,h.childCount)||!v.type.validContent(m))return!1}let a=s.indexAfter(o),l=r&&r[0];return s.node(o).canReplaceWith(a,a,l?l.type:s.node(o+1).type)}function coe(n,e,t=1,r){let s=n.doc.resolve(e),o=me.empty,i=me.empty;for(let a=s.depth,l=s.depth-t,c=t-1;a>l;a--,c--){o=me.from(s.node(a).copy(o));let u=r&&r[c];i=me.from(u?u.type.create(u.attrs,i):s.node(a).copy(i))}n.step(new Vn(e,e,new _e(o.append(i),t,t),!0))}function pc(n,e){let t=n.resolve(e),r=t.index();return C6(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function uoe(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 o=e.child(s),i=o.type==r?n.type.schema.nodes.text:o.type;if(t=t.matchType(i),!t||!n.type.allowsMarks(o.marks))return!1}return t.validEnd}function C6(n,e){return!!(n&&e&&!n.isLeaf&&uoe(n,e))}function N0(n,e,t=-1){let r=n.resolve(e);for(let s=r.depth;;s--){let o,i,a=r.index(s);if(s==r.depth?(o=r.nodeBefore,i=r.nodeAfter):t>0?(o=r.node(s+1),a++,i=r.node(s).maybeChild(a)):(o=r.node(s).maybeChild(a-1),i=r.node(s+1)),o&&!o.isTextblock&&C6(o,i)&&r.node(s).canReplace(a,a+1))return e;if(s==0)break;e=t<0?r.before(s):r.after(s)}}function doe(n,e,t){let r=null,{linebreakReplacement:s}=n.doc.type.schema,o=n.doc.resolve(e-t),i=o.node().type;if(s&&i.inlineContent){let u=i.whitespace=="pre",h=!!i.contentMatch.matchType(s);u&&!h?r=!1:!u&&h&&(r=!0)}let a=n.steps.length;if(r===!1){let u=n.doc.resolve(e+t);b6(n,u.node(),u.before(),a)}i.inlineContent&&PT(n,e+t-1,i,o.node().contentMatchAt(o.index()),r==null);let l=n.mapping.slice(a),c=l.map(e-t);if(n.step(new Vn(c,l.map(e+t,-1),_e.empty,!0)),r===!0){let u=n.doc.resolve(c);w6(n,u.node(),u.before(),n.steps.length)}return n}function hoe(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 o=r.index(s);if(r.node(s).canReplaceWith(o,o,t))return r.before(s+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let s=r.depth-1;s>=0;s--){let o=r.indexAfter(s);if(r.node(s).canReplaceWith(o,o,t))return r.after(s+1);if(o<r.node(s).childCount)return null}return null}function P6(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let s=t.content;for(let o=0;o<t.openStart;o++)s=s.firstChild.content;for(let o=1;o<=(t.openStart==0&&t.size?2:1);o++)for(let i=r.depth;i>=0;i--){let a=i==r.depth?0:r.pos<=(r.start(i+1)+r.end(i+1))/2?-1:1,l=r.index(i)+(a>0?1:0),c=r.node(i),u=!1;if(o==1)u=c.canReplace(l,l,s);else{let h=c.contentMatchAt(l).findWrapping(s.firstChild.type);u=h&&c.canReplaceWith(l,l,h[0])}if(u)return a==0?r.pos:a<0?r.before(i+1):r.after(i+1)}return null}function F0(n,e,t=e,r=_e.empty){if(e==t&&!r.size)return null;let s=n.resolve(e),o=n.resolve(t);return k6(s,o,r)?new Vn(e,t,r):new foe(s,o,r).fit()}function k6(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class foe{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=me.empty;for(let s=0;s<=e.depth;s++){let o=e.node(s);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(s))})}for(let s=e.depth;s>0;s--)this.placed=me.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 o=this.placed,i=r.depth,a=s.depth;for(;i&&a&&o.childCount==1;)o=o.firstChild.content,i--,a--;let l=new _e(o,i,a);return e>-1?new Xn(r.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||r.pos!=this.$to.pos?new Vn(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 o=t.firstChild;if(t.childCount>1&&(s=0),o.type.spec.isolating&&s<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let s,o=null;r?(o=tP(this.unplaced.content,r-1).firstChild,s=o.content):s=this.unplaced.content;let i=s.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],u,h=null;if(t==1&&(i?c.matchType(i.type)||(h=c.fillBefore(me.from(i),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:a,parent:o,inject:h};if(t==2&&i&&(u=c.findWrapping(i.type)))return{sliceDepth:r,frontierDepth:a,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,s=tP(e,t);return!s.childCount||s.firstChild.isLeaf?!1:(this.unplaced=new _e(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=tP(e,t);if(s.childCount<=1&&t>0){let o=e.size-t<=t+s.size;this.unplaced=new _e(Gf(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new _e(Gf(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:s,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let v=0;v<o.length;v++)this.openFrontierNode(o[v]);let i=this.unplaced,a=r?r.content:i.content,l=i.openStart-e,c=0,u=[],{match:h,type:p}=this.frontier[t];if(s){for(let v=0;v<s.childCount;v++)u.push(s.child(v));h=h.matchFragment(s)}let m=a.size+e-(i.content.size-i.openEnd);for(;c<a.childCount;){let v=a.child(c),y=h.matchType(v.type);if(!y)break;c++,(c>1||l==0||v.content.size)&&(h=y,u.push(E6(v.mark(p.allowedMarks(v.marks)),c==1?l:0,c==a.childCount?m:-1)))}let S=c==a.childCount;S||(m=-1),this.placed=qf(this.placed,t,me.from(u)),this.frontier[t].match=h,S&&m<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let v=0,y=a;v<m;v++){let w=y.lastChild;this.frontier.push({type:w.type,match:w.contentMatchAt(w.childCount)}),y=w.content}this.unplaced=S?e==0?_e.empty:new _e(Gf(i.content,e-1,1),e-1,m<0?i.openEnd:e-1):new _e(Gf(i.content,e,c),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!nP(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],o=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=nP(e,t,s,r,o);if(i){for(let a=t-1;a>=0;a--){let{match:l,type:c}=this.frontier[a],u=nP(e,a,c,l,!0);if(!u||u.childCount)continue e}return{depth:t,fit:i,move:o?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=qf(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let s=e.node(r),o=s.type.contentMatch.fillBefore(s.content,!0,e.index(r));this.openFrontierNode(s.type,s.attrs,o)}return e}openFrontierNode(e,t=null,r){let s=this.frontier[this.depth];s.match=s.match.matchType(e),this.placed=qf(this.placed,this.depth,me.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(me.empty,!0);t.childCount&&(this.placed=qf(this.placed,this.frontier.length,t))}}function Gf(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Gf(n.firstChild.content,e-1,t)))}function qf(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(qf(n.lastChild.content,e-1,t)))}function tP(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function E6(n,e,t){if(e<=0)return n;let r=n.content;return e>1&&(r=r.replaceChild(0,E6(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(me.empty,!0)))),n.copy(r)}function nP(n,e,t,r,s){let o=n.node(e),i=s?n.indexAfter(e):n.index(e);if(i==o.childCount&&!t.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,i);return a&&!poe(t,o.content,i)?a:null}function poe(n,e,t){for(let r=t;r<e.childCount;r++)if(!n.allowsMarks(e.child(r).marks))return!0;return!1}function goe(n){return n.spec.defining||n.spec.definingForContent}function moe(n,e,t,r){if(!r.size)return n.deleteRange(e,t);let s=n.doc.resolve(e),o=n.doc.resolve(t);if(k6(s,o,r))return n.step(new Vn(e,t,r));let i=T6(s,n.doc.resolve(t));i[i.length-1]==0&&i.pop();let a=-(s.depth+1);i.unshift(a);for(let p=s.depth,m=s.pos-1;p>0;p--,m--){let S=s.node(p).type.spec;if(S.defining||S.definingAsContext||S.isolating)break;i.indexOf(p)>-1?a=p:s.before(p)==m&&i.splice(1,0,-p)}let l=i.indexOf(a),c=[],u=r.openStart;for(let p=r.content,m=0;;m++){let S=p.firstChild;if(c.push(S),m==r.openStart)break;p=S.content}for(let p=u-1;p>=0;p--){let m=c[p],S=goe(m.type);if(S&&!m.sameMarkup(s.node(Math.abs(a)-1)))u=p;else if(S||!m.type.isTextblock)break}for(let p=r.openStart;p>=0;p--){let m=(p+u+1)%(r.openStart+1),S=c[m];if(S)for(let v=0;v<i.length;v++){let y=i[(v+l)%i.length],w=!0;y<0&&(w=!1,y=-y);let C=s.node(y-1),T=s.index(y-1);if(C.canReplaceWith(T,T,S.type,S.marks))return n.replace(s.before(y),w?o.after(y):t,new _e(I6(r.content,0,r.openStart,m),m,r.openEnd))}}let h=n.steps.length;for(let p=i.length-1;p>=0&&(n.replace(e,t,r),!(n.steps.length>h));p--){let m=i[p];m<0||(e=s.before(m),t=o.after(m))}}function I6(n,e,t,r,s){if(e<t){let o=n.firstChild;n=n.replaceChild(0,o.copy(I6(o.content,e+1,t,r,o)))}if(e>r){let o=s.contentMatchAt(0),i=o.fillBefore(n).append(n);n=i.append(o.matchFragment(i).fillBefore(me.empty,!0))}return n}function yoe(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let s=hoe(n.doc,e,r.type);s!=null&&(e=t=s)}n.replaceRange(e,t,new _e(me.from(r),0,0))}function Soe(n,e,t){let r=n.doc.resolve(e),s=n.doc.resolve(t),o=T6(r,s);for(let i=0;i<o.length;i++){let a=o[i],l=i==o.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 i=1;i<=r.depth&&i<=s.depth;i++)if(e-r.start(i)==r.depth-i&&t>r.end(i)&&s.end(i)-t!=s.depth-i&&r.start(i-1)==s.start(i-1)&&r.node(i-1).canReplace(r.index(i-1),s.index(i-1)))return n.delete(r.before(i),t);n.delete(e,t)}function T6(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let s=r;s>=0;s--){let o=n.start(s);if(o<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;(o==e.start(s)||s==n.depth&&s==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==o-1)&&t.push(s)}return t}class Jd extends zr{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 jn.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let s=t.type.create(r,null,t.marks);return jn.fromReplace(e,this.pos,this.pos+1,new _e(me.from(s),0,t.isLeaf?0:1))}getMap(){return Xs.empty}invert(e){return new Jd(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 Jd(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 Jd(t.pos,t.attr,t.value)}}zr.jsonID("attr",Jd);class Hp extends zr{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 jn.ok(r)}getMap(){return Xs.empty}invert(e){return new Hp(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 Hp(t.attr,t.value)}}zr.jsonID("docAttr",Hp);let uh=class extends Error{};uh=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};uh.prototype=Object.create(Error.prototype);uh.prototype.constructor=uh;uh.prototype.name="TransformError";class _6{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Up}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new uh(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=_e.empty){let s=F0(this.doc,e,t,r);return s&&this.step(s),this}replaceWith(e,t,r){return this.replace(e,t,new _e(me.from(r),0,0))}delete(e,t){return this.replace(e,t,_e.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return moe(this,e,t,r),this}replaceRangeWith(e,t,r){return yoe(this,e,t,r),this}deleteRange(e,t){return Soe(this,e,t),this}lift(e,t){return noe(this,e,t),this}join(e,t=1){return doe(this,e,t),this}wrap(e,t){return ooe(this,e,t),this}setBlockType(e,t=e,r,s=null){return ioe(this,e,t,r,s),this}setNodeMarkup(e,t,r=null,s){return loe(this,e,t,r,s),this}setNodeAttribute(e,t,r){return this.step(new Jd(e,t,r)),this}setDocAttribute(e,t){return this.step(new Hp(e,t)),this}addNodeMark(e,t){return this.step(new Gl(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof Ut)t.isInSet(r.marks)&&this.step(new yu(e,t));else{let s=r.marks,o,i=[];for(;o=t.isInSet(s);)i.push(new yu(e,o)),s=o.removeFromSet(s);for(let a=i.length-1;a>=0;a--)this.step(i[a])}return this}split(e,t=1,r){return coe(this,e,t,r),this}addMark(e,t,r){return Qse(this,e,t,r),this}removeMark(e,t,r){return eoe(this,e,t,r),this}clearIncompatible(e,t,r){return PT(this,e,t,r),this}}const rP=Object.create(null);class ut{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new xoe(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=_e.empty){let r=t.content.lastChild,s=null;for(let a=0;a<t.openEnd;a++)s=r,r=r.lastChild;let o=e.steps.length,i=this.ranges;for(let a=0;a<i.length;a++){let{$from:l,$to:c}=i[a],u=e.mapping.slice(o);e.replaceRange(u.map(l.pos),u.map(c.pos),a?_e.empty:t),a==0&&rL(e,o,(r?r.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,s=this.ranges;for(let o=0;o<s.length;o++){let{$from:i,$to:a}=s[o],l=e.mapping.slice(r),c=l.map(i.pos),u=l.map(a.pos);o?e.deleteRange(c,u):(e.replaceRangeWith(c,u,t),rL(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let s=e.parent.inlineContent?new ot(e):Dd(e.node(0),e.parent,e.pos,e.index(),t,r);if(s)return s;for(let o=e.depth-1;o>=0;o--){let i=t<0?Dd(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Dd(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new oo(e.node(0))}static atStart(e){return Dd(e,e,0,0,1)||new oo(e)}static atEnd(e){return Dd(e,e,e.content.size,e.childCount,-1)||new oo(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=rP[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 rP)throw new RangeError("Duplicate use of selection JSON ID "+e);return rP[e]=t,t.prototype.jsonID=e,t}getBookmark(){return ot.between(this.$anchor,this.$head).getBookmark()}}ut.prototype.visible=!0;class xoe{constructor(e,t){this.$from=e,this.$to=t}}let tL=!1;function nL(n){!tL&&!n.parent.inlineContent&&(tL=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class ot extends ut{constructor(e,t=e){nL(e),nL(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 ut.near(r);let s=e.resolve(t.map(this.anchor));return new ot(s.parent.inlineContent?s:r,r)}replace(e,t=_e.empty){if(super.replace(e,t),t==_e.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof ot&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new z0(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 ot(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 o=ut.findFrom(t,r,!0)||ut.findFrom(t,-r,!0);if(o)t=o.$head;else return ut.near(t,r)}return e.parent.inlineContent||(s==0?e=t:(e=(ut.findFrom(e,-r,!0)||ut.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=s<0&&(e=t))),new ot(e,t)}}ut.jsonID("text",ot);class z0{constructor(e,t){this.anchor=e,this.head=t}map(e){return new z0(e.map(this.anchor),e.map(this.head))}resolve(e){return ot.between(e.resolve(this.anchor),e.resolve(this.head))}}class Ge extends ut{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),o=e.resolve(s);return r?ut.near(o):new Ge(o)}content(){return new _e(me.from(this.node),0,0)}eq(e){return e instanceof Ge&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ET(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ge(e.resolve(t.anchor))}static create(e,t){return new Ge(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Ge.prototype.visible=!1;ut.jsonID("node",Ge);class ET{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new z0(r,r):new ET(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&Ge.isSelectable(r)?new Ge(t):ut.near(t)}}class oo extends ut{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=_e.empty){if(t==_e.empty){e.delete(0,e.doc.content.size);let r=ut.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new oo(e)}map(e){return new oo(e)}eq(e){return e instanceof oo}getBookmark(){return voe}}ut.jsonID("all",oo);const voe={map(){return this},resolve(n){return new oo(n)}};function Dd(n,e,t,r,s,o=!1){if(e.inlineContent)return ot.create(n,t);for(let i=r-(s>0?0:1);s>0?i<e.childCount:i>=0;i+=s){let a=e.child(i);if(a.isAtom){if(!o&&Ge.isSelectable(a))return Ge.create(n,t-(s<0?a.nodeSize:0))}else{let l=Dd(n,a,t+s,s<0?a.childCount:0,s,o);if(l)return l}t+=a.nodeSize*s}return null}function rL(n,e,t){let r=n.steps.length-1;if(r<e)return;let s=n.steps[r];if(!(s instanceof Vn||s instanceof Xn))return;let o=n.mapping.maps[r],i;o.forEach((a,l,c,u)=>{i==null&&(i=u)}),n.setSelection(ut.near(n.doc.resolve(i),t))}const sL=1,oL=2,iL=4;class woe extends _6{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|sL)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&sL)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=oL,this}ensureMarks(e){return Ut.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&oL)>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)||Ut.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 o=this.storedMarks;if(!o){let i=this.doc.resolve(t);o=r==t?i.marks():i.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,s.text(e,o)),this.selection.empty||this.setSelection(ut.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|=iL,this}get scrolledIntoView(){return(this.updated&iL)>0}}function aL(n,e){return!e||!n?n:n.bind(e)}class Yf{constructor(e,t,r){this.name=e,this.init=aL(t.init,r),this.apply=aL(t.apply,r)}}const boe=[new Yf("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Yf("selection",{init(n,e){return n.selection||ut.atStart(e.doc)},apply(n){return n.selection}}),new Yf("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Yf("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class sP{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=boe.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 Yf(r.key,r.spec.state,r))})}}class Hd{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 o=!1;for(let i=0;i<this.config.plugins.length;i++){let a=this.config.plugins[i];if(a.spec.appendTransaction){let l=s?s[i].n:0,c=s?s[i].state:this,u=l<t.length&&a.spec.appendTransaction.call(a,l?t.slice(l):t,c,r);if(u&&r.filterTransaction(u,i)){if(u.setMeta("appendedTransaction",e),!s){s=[];for(let h=0;h<this.config.plugins.length;h++)s.push(h<i?{state:r,n:t.length}:{state:this,n:0})}t.push(u),r=r.applyInner(u),o=!0}s&&(s[i]={state:r,n:t.length})}}if(!o)return{state:r,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Hd(this.config),r=this.config.fields;for(let s=0;s<r.length;s++){let o=r[s];t[o.name]=o.apply(e,this[o.name],this,t)}return t}get tr(){return new woe(this)}static create(e){let t=new sP(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new Hd(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 sP(this.schema,e.plugins),r=t.fields,s=new Hd(t);for(let o=0;o<r.length;o++){let i=r[o].name;s[i]=this.hasOwnProperty(i)?this[i]:r[o].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],o=s.spec.state;o&&o.toJSON&&(t[r]=o.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 sP(e.schema,e.plugins),o=new Hd(s);return s.fields.forEach(i=>{if(i.name=="doc")o.doc=pi.fromJSON(e.schema,t.doc);else if(i.name=="selection")o.selection=ut.fromJSON(o.doc,t.selection);else if(i.name=="storedMarks")t.storedMarks&&(o.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==i.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,a)){o[i.name]=c.fromJSON.call(l,e,t[a],o);return}}o[i.name]=i.init(e,o)}}),o}}function M6(n,e,t){for(let r in n){let s=n[r];s instanceof Function?s=s.bind(e):r=="handleDOMEvents"&&(s=M6(s,e,{})),t[r]=s}return t}class xr{constructor(e){this.spec=e,this.props={},e.props&&M6(e.props,this,this.props),this.key=e.key?e.key.key:A6("plugin")}getState(e){return e[this.key]}}const oP=Object.create(null);function A6(n){return n in oP?n+"$"+ ++oP[n]:(oP[n]=0,n+"$")}class uo{constructor(e="key"){this.key=A6(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const dr=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},dh=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let eE=null;const Ta=function(n,e,t){let r=eE||(eE=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Coe=function(){eE=null},Su=function(n,e,t,r){return t&&(lL(n,e,t,r,-1)||lL(n,e,t,r,1))},Poe=/^(img|br|input|textarea|hr)$/i;function lL(n,e,t,r,s){for(;;){if(n==t&&e==r)return!0;if(e==(s<0?0:Mo(n))){let o=n.parentNode;if(!o||o.nodeType!=1||_g(n)||Poe.test(n.nodeName)||n.contentEditable=="false")return!1;e=dr(n)+(s<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.contentEditable=="false")return!1;e=s<0?Mo(n):0}else return!1}}function Mo(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function koe(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=Mo(n)}else if(n.parentNode&&!_g(n))e=dr(n),n=n.parentNode;else return null}}function Eoe(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&&!_g(n))e=dr(n)+1,n=n.parentNode;else return null}}function Ioe(n,e,t){for(let r=e==0,s=e==Mo(n);r||s;){if(n==t)return!0;let o=dr(n);if(n=n.parentNode,!n)return!1;r=r&&o==0,s=s&&o==Mo(n)}}function _g(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 B0=function(n){return n.focusNode&&Su(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function qc(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Toe(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function _oe(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(Mo(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(Mo(r.startContainer),r.startOffset)}}}const Ji=typeof navigator<"u"?navigator:null,cL=typeof document<"u"?document:null,gc=Ji&&Ji.userAgent||"",tE=/Edge\/(\d+)/.exec(gc),O6=/MSIE \d/.exec(gc),nE=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(gc),js=!!(O6||nE||tE),Zl=O6?document.documentMode:nE?+nE[1]:tE?+tE[1]:0,mi=!js&&/gecko\/(\d+)/i.test(gc);mi&&+(/Firefox\/(\d+)/.exec(gc)||[0,0])[1];const rE=!js&&/Chrome\/(\d+)/.exec(gc),Lr=!!rE,R6=rE?+rE[1]:0,ns=!js&&!!Ji&&/Apple Computer/.test(Ji.vendor),hh=ns&&(/Mobile\/\w+/.test(gc)||!!Ji&&Ji.maxTouchPoints>2),Io=hh||(Ji?/Mac/.test(Ji.platform):!1),Moe=Ji?/Win/.test(Ji.platform):!1,Da=/Android \d/.test(gc),Mg=!!cL&&"webkitFontSmoothing"in cL.documentElement.style,Aoe=Mg?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ooe(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 wa(n,e){return typeof n=="number"?n:n[e]}function Roe(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 uL(n,e,t){let r=n.someProp("scrollThreshold")||0,s=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let i=t||n.dom;i;){if(i.nodeType!=1){i=dh(i);continue}let a=i,l=a==o.body,c=l?Ooe(o):Roe(a),u=0,h=0;if(e.top<c.top+wa(r,"top")?h=-(c.top-e.top+wa(s,"top")):e.bottom>c.bottom-wa(r,"bottom")&&(h=e.bottom-e.top>c.bottom-c.top?e.top+wa(s,"top")-c.top:e.bottom-c.bottom+wa(s,"bottom")),e.left<c.left+wa(r,"left")?u=-(c.left-e.left+wa(s,"left")):e.right>c.right-wa(r,"right")&&(u=e.right-c.right+wa(s,"right")),u||h)if(l)o.defaultView.scrollBy(u,h);else{let m=a.scrollLeft,S=a.scrollTop;h&&(a.scrollTop+=h),u&&(a.scrollLeft+=u);let v=a.scrollLeft-m,y=a.scrollTop-S;e={left:e.left-v,top:e.top-y,right:e.right-v,bottom:e.bottom-y}}let p=l?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(p))break;i=p=="absolute"?i.offsetParent:dh(i)}}function Doe(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,s;for(let o=(e.left+e.right)/2,i=t+1;i<Math.min(innerHeight,e.bottom);i+=5){let a=n.root.elementFromPoint(o,i);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:D6(n.dom)}}function D6(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=dh(r));return e}function joe({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;j6(t,r==0?0:r-e)}function j6(n,e){for(let t=0;t<n.length;t++){let{dom:r,top:s,left:o}=n[t];r.scrollTop!=s+e&&(r.scrollTop=s+e),r.scrollLeft!=o&&(r.scrollLeft=o)}}let Pd=null;function Loe(n){if(n.setActive)return n.setActive();if(Pd)return n.focus(Pd);let e=D6(n);n.focus(Pd==null?{get preventScroll(){return Pd={preventScroll:!0},!0}}:void 0),Pd||(Pd=!1,j6(e,0))}function L6(n,e){let t,r=2e8,s,o=0,i=e.top,a=e.top,l,c;for(let u=n.firstChild,h=0;u;u=u.nextSibling,h++){let p;if(u.nodeType==1)p=u.getClientRects();else if(u.nodeType==3)p=Ta(u).getClientRects();else continue;for(let m=0;m<p.length;m++){let S=p[m];if(S.top<=i&&S.bottom>=a){i=Math.max(S.bottom,i),a=Math.min(S.top,a);let v=S.left>e.left?S.left-e.left:S.right<e.left?e.left-S.right:0;if(v<r){t=u,r=v,s=v&&t.nodeType==3?{left:S.right<e.left?S.right:S.left,top:e.top}:e,u.nodeType==1&&v&&(o=h+(e.left>=(S.left+S.right)/2?1:0));continue}}else S.top>e.top&&!l&&S.left<=e.left&&S.right>=e.left&&(l=u,c={left:Math.max(S.left,Math.min(S.right,e.left)),top:S.top});!t&&(e.left>=S.right&&e.top>=S.top||e.left>=S.left&&e.top>=S.bottom)&&(o=h+1)}}return!t&&l&&(t=l,s=c,r=0),t&&t.nodeType==3?Noe(t,s):!t||r&&t.nodeType==1?{node:n,offset:o}:L6(t,s)}function Noe(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 o=jl(r,1);if(o.top!=o.bottom&&IT(e,o))return{node:n,offset:s+(e.left>=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function IT(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Foe(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function zoe(n,e,t){let{node:r,offset:s}=L6(e,t),o=-1;if(r.nodeType==1&&!r.firstChild){let i=r.getBoundingClientRect();o=i.left!=i.right&&t.left>(i.left+i.right)/2?1:-1}return n.docView.posFromDOM(r,s,o)}function Boe(n,e,t,r){let s=-1;for(let o=e,i=!1;o!=n.dom;){let a=n.docView.nearestDesc(o,!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&&(!i&&l.left>r.left||l.top>r.top?s=a.posBefore:(!i&&l.right<r.left||l.bottom<r.top)&&(s=a.posAfter),i=!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;o=a.dom.parentNode}return s>-1?s:n.docView.posFromDOM(e,t,-1)}function N6(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)),o=s;;){let i=n.childNodes[o];if(i.nodeType==1){let a=i.getClientRects();for(let l=0;l<a.length;l++){let c=a[l];if(IT(e,c))return N6(i,e,c)}}if((o=(o+1)%r)==s)break}return n}function $oe(n,e){let t=n.dom.ownerDocument,r,s=0,o=_oe(t,e.left,e.top);o&&({node:r,offset:s}=o);let i=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),a;if(!i||!n.dom.contains(i.nodeType!=1?i.parentNode:i)){let c=n.dom.getBoundingClientRect();if(!IT(e,c)||(i=N6(n.dom,e,c),!i))return null}if(ns)for(let c=i;r&&c;c=dh(c))c.draggable&&(r=void 0);if(i=Foe(i,e),r){if(mi&&r.nodeType==1&&(s=Math.min(s,r.childNodes.length),s<r.childNodes.length)){let u=r.childNodes[s],h;u.nodeName=="IMG"&&(h=u.getBoundingClientRect()).right<=e.left&&h.bottom>e.top&&s++}let c;Mg&&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=Boe(n,r,s,e))}a==null&&(a=zoe(n,i,e));let l=n.docView.nearestDesc(i,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function dL(n){return n.top<n.bottom||n.left<n.right}function jl(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(dL(r))return r}return Array.prototype.find.call(t,dL)||n.getBoundingClientRect()}const Uoe=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function F6(n,e,t){let{node:r,offset:s,atom:o}=n.docView.domFromPos(e,t<0?-1:1),i=Mg||mi;if(r.nodeType==3)if(i&&(Uoe.test(r.nodeValue)||(t<0?!s:s==r.nodeValue.length))){let l=jl(Ta(r,s,s),t);if(mi&&s&&/\s/.test(r.nodeValue[s-1])&&s<r.nodeValue.length){let c=jl(Ta(r,s-1,s-1),-1);if(c.top==l.top){let u=jl(Ta(r,s,s+1),-1);if(u.top!=l.top)return Rf(u,u.left<c.left)}}return l}else{let l=s,c=s,u=t<0?1:-1;return t<0&&!s?(c++,u=-1):t>=0&&s==r.nodeValue.length?(l--,u=1):t<0?l--:c++,Rf(jl(Ta(r,l,c),u),u<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&s&&(t<0||s==Mo(r))){let l=r.childNodes[s-1];if(l.nodeType==1)return iP(l.getBoundingClientRect(),!1)}if(o==null&&s<Mo(r)){let l=r.childNodes[s];if(l.nodeType==1)return iP(l.getBoundingClientRect(),!0)}return iP(r.getBoundingClientRect(),t>=0)}if(o==null&&s&&(t<0||s==Mo(r))){let l=r.childNodes[s-1],c=l.nodeType==3?Ta(l,Mo(l)-(i?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return Rf(jl(c,1),!1)}if(o==null&&s<Mo(r)){let l=r.childNodes[s];for(;l.pmViewDesc&&l.pmViewDesc.ignoreForCoords;)l=l.nextSibling;let c=l?l.nodeType==3?Ta(l,0,i?0:1):l.nodeType==1?l:null:null;if(c)return Rf(jl(c,-1),!0)}return Rf(jl(r.nodeType==3?Ta(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 iP(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 z6(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 Hoe(n,e,t){let r=e.selection,s=t=="up"?r.$from:r.$to;return z6(n,e,()=>{let{node:o}=n.docView.domFromPos(s.pos,t=="up"?-1:1);for(;;){let a=n.docView.nearestDesc(o,!0);if(!a)break;if(a.node.isBlock){o=a.contentDOM||a.dom;break}o=a.dom.parentNode}let i=F6(n,s.pos,1);for(let a=o.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=Ta(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;c<l.length;c++){let u=l[c];if(u.bottom>u.top+1&&(t=="up"?i.top-u.top>(u.bottom-i.top)*2:u.bottom-i.bottom>(i.bottom-u.top)*2))return!1}}return!0})}const Koe=/[\u0590-\u08ac]/;function Woe(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let s=r.parentOffset,o=!s,i=s==r.parent.content.size,a=n.domSelection();return a?!Koe.test(r.parent.textContent)||!a.modify?t=="left"||t=="backward"?o:i:z6(n,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:u,anchorOffset:h}=n.domSelectionRange(),p=a.caretBidiLevel;a.modify("move",t,"character");let m=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:S,focusOffset:v}=n.domSelectionRange(),y=S&&!m.contains(S.nodeType==1?S:S.parentNode)||l==S&&c==v;try{a.collapse(u,h),l&&(l!=u||c!=h)&&a.extend&&a.extend(l,c)}catch{}return p!=null&&(a.caretBidiLevel=p),y}):r.pos==r.start()||r.pos==r.end()}let hL=null,fL=null,pL=!1;function Voe(n,e,t){return hL==e&&fL==t?pL:(hL=e,fL=t,pL=t=="up"||t=="down"?Hoe(n,e,t):Woe(n,e,t))}const Lo=0,gL=1,Xc=2,Qi=3;class Ag{constructor(e,t,r,s){this.parent=e,this.children=t,this.dom=r,this.contentDOM=s,this.dirty=Lo,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 o,i;if(e==this.contentDOM)o=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;o=e.previousSibling}for(;o&&!((i=o.pmViewDesc)&&i.parent==this);)o=o.previousSibling;return o?this.posBeforeChild(i)+i.size:this.posAtStart}else{let o,i;if(e==this.contentDOM)o=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;o=e.nextSibling}for(;o&&!((i=o.pmViewDesc)&&i.parent==this);)o=o.nextSibling;return o?this.posBeforeChild(i):this.posAtEnd}let s;if(e==this.dom&&this.contentDOM)s=t>dr(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 o=e;;o=o.parentNode){if(o==this.dom){s=!1;break}if(o.previousSibling)break}if(s==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){s=!0;break}if(o.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 o=this.getDesc(s),i;if(o&&(!t||o.node))if(r&&(i=o.nodeDOM)&&!(i.nodeType==1?i.contains(e.nodeType==1?e:e.parentNode):i==e))r=!1;else return o}}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 o=this.getDesc(s);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;t<this.children.length;t++){let s=this.children[t],o=r+s.size;if(r==e&&o!=r){for(;!s.border&&s.children.length;)for(let i=0;i<s.children.length;i++){let a=s.children[i];if(a.size){s=a;break}}return s}if(e<o)return s.descAt(e-r-s.border);r=o}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,s=0;for(let o=0;r<this.children.length;r++){let i=this.children[r],a=o+i.size;if(a>e||i instanceof $6){s=e-o;break}o=a}if(s)return this.children[r].domFromPos(s-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof B6&&o.side>=0;r--);if(t<=0){let o,i=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,i=!1);return o&&t&&i&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?dr(o.dom)+1:0}}else{let o,i=!0;for(;o=r<this.children.length?this.children[r]:null,!(!o||o.dom.parentNode==this.contentDOM);r++,i=!1);return o&&i&&!o.border&&!o.domAtom?o.domFromPos(0,t):{node:this.contentDOM,offset:o?dr(o.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,o=-1;for(let i=r,a=0;;a++){let l=this.children[a],c=i+l.size;if(s==-1&&e<=c){let u=i+l.border;if(e>=u&&t<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,t,u);e=i;for(let h=a;h>0;h--){let p=this.children[h-1];if(p.size&&p.dom.parentNode==this.contentDOM&&!p.emptyChildAt(1)){s=dr(p.dom)+1;break}e-=p.size}s==-1&&(s=0)}if(s>-1&&(c>t||a==this.children.length-1)){t=c;for(let u=a+1;u<this.children.length;u++){let h=this.children[u];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(-1)){o=dr(h.dom);break}t+=h.size}o==-1&&(o=this.contentDOM.childNodes.length);break}i=c}return{node:this.contentDOM,from:e,to:t,fromOffset:s,toOffset:o}}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 o=Math.min(e,t),i=Math.max(e,t);for(let m=0,S=0;m<this.children.length;m++){let v=this.children[m],y=S+v.size;if(o>S&&i<y)return v.setSelection(e-S-v.border,t-S-v.border,r,s);S=y}let a=this.domFromPos(e,e?-1:1),l=t==e?a:this.domFromPos(t,t?-1:1),c=r.root.getSelection(),u=r.domSelectionRange(),h=!1;if((mi||ns)&&e==t){let{node:m,offset:S}=a;if(m.nodeType==3){if(h=!!(S&&m.nodeValue[S-1]==`
221
+ `),h&&S==m.nodeValue.length)for(let v=m,y;v;v=v.parentNode){if(y=v.nextSibling){y.nodeName=="BR"&&(a=l={node:y.parentNode,offset:dr(y)+1});break}let w=v.pmViewDesc;if(w&&w.node&&w.node.isBlock)break}}else{let v=m.childNodes[S-1];h=v&&(v.nodeName=="BR"||v.contentEditable=="false")}}if(mi&&u.focusNode&&u.focusNode!=l.node&&u.focusNode.nodeType==1){let m=u.focusNode.childNodes[u.focusOffset];m&&m.contentEditable=="false"&&(s=!0)}if(!(s||h&&ns)&&Su(a.node,a.offset,u.anchorNode,u.anchorOffset)&&Su(l.node,l.offset,u.focusNode,u.focusOffset))return;let p=!1;if((c.extend||e==t)&&!h){c.collapse(a.node,a.offset);try{e!=t&&c.extend(l.node,l.offset),p=!0}catch{}}if(!p){if(e>t){let S=a;a=l,l=S}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 o=this.children[s],i=r+o.size;if(r==i?e<=i&&t>=r:e<i&&t>r){let a=r+o.border,l=i-o.border;if(e>=a&&t<=l){this.dirty=e==r||t==i?Xc:gL,e==a&&t==l&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Qi:o.markDirty(e-a,t-a);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?Xc:Qi}r=i}this.dirty=Xc}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Xc:gL;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class B6 extends Ag{constructor(e,t,r,s){let o,i=t.type.toDOM;if(typeof i=="function"&&(i=i(r,()=>{if(!o)return s;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(i.nodeType!=1){let a=document.createElement("span");a.appendChild(i),i=a}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==Lo&&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 Goe extends Ag{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 xu extends Ag{constructor(e,t,r,s,o){super(e,[],r,s),this.mark=t,this.spec=o}static create(e,t,r,s){let o=s.nodeViews[t.type.name],i=o&&o(t,s,r);return(!i||!i.dom)&&(i=Du.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new xu(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&Qi||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Qi&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Lo){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=Lo}}slice(e,t,r){let s=xu.create(this.parent,this.mark,!0,r),o=this.children,i=this.size;t<i&&(o=oE(o,t,i,r)),e>0&&(o=oE(o,0,e,r));for(let a=0;a<o.length;a++)o[a].parent=s;return s.children=o,s}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Jl extends Ag{constructor(e,t,r,s,o,i,a,l,c){super(e,[],o,i),this.node=t,this.outerDeco=r,this.innerDeco=s,this.nodeDOM=a}static create(e,t,r,s,o,i){let a=o.nodeViews[t.type.name],l,c=a&&a(t,o,()=>{if(!l)return i;if(l.parent)return l.parent.posBeforeChild(l)},r,s),u=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:h}=Du.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!h&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let p=u;return u=K6(u,r,t),c?l=new qoe(e,t,r,s,u,h||null,p,c,o,i+1):t.isText?new $0(e,t,r,s,u,p,o):new Jl(e,t,r,s,u,h||null,p,o,i+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=()=>me.empty)}return e}matchesNode(e,t,r){return this.dirty==Lo&&e.eq(this.node)&&tx(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,o=e.composing?this.localCompositionInfo(e,t):null,i=o&&o.pos>-1?o:null,a=o&&o.pos<0,l=new Xoe(this,i&&i.node,e);Qoe(this.node,this.innerDeco,(c,u,h)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!h&&l.syncToMarks(u==this.node.childCount?Ut.none:this.node.child(u).marks,r,e),l.placeWidget(c,e,s)},(c,u,h,p)=>{l.syncToMarks(c.marks,r,e);let m;l.findNodeMatch(c,u,h,p)||a&&e.state.selection.from>s&&e.state.selection.to<s+c.nodeSize&&(m=l.findIndexWithChild(o.node))>-1&&l.updateNodeAt(c,u,h,m,e)||l.updateNextNode(c,u,h,e,p,s)||l.addNode(c,u,h,e,s),s+=c.nodeSize}),l.syncToMarks([],r,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==Xc)&&(i&&this.protectLocalComposition(e,i),U6(this.contentDOM,this.children,e),hh&&eie(this.dom))}localCompositionInfo(e,t){let{from:r,to:s}=e.state.selection;if(!(e.state.selection instanceof ot)||r<t||s>t+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let i=o.nodeValue,a=tie(this.node.content,i,r-t,s-t);return a<0?null:{node:o,pos:a,text:i}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:s}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let i=new Goe(this,o,t,s);e.input.compositionNodes.push(i),this.children=oE(this.children,r,r+s.length,e,i)}update(e,t,r,s){return this.dirty==Qi||!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=Lo}updateOuterDeco(e){if(tx(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=H6(this.dom,this.nodeDOM,sE(this.outerDeco,this.node,t),sE(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 mL(n,e,t,r,s){K6(r,e,n);let o=new Jl(void 0,n,e,t,r,r,r,s,0);return o.contentDOM&&o.updateChildren(s,0),o}class $0 extends Jl{constructor(e,t,r,s,o,i,a){super(e,t,r,s,o,null,i,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==Qi||this.dirty!=Lo&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Lo||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=Lo,!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),o=document.createTextNode(s.text);return new $0(this.parent,s,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Qi)}get domAtom(){return!1}isText(e){return this.node.text==e}}class $6 extends Ag{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Lo&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class qoe extends Jl{constructor(e,t,r,s,o,i,a,l,c,u){super(e,t,r,s,o,i,a,c,u),this.spec=l}update(e,t,r,s){if(this.dirty==Qi)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,s),o}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 U6(n,e,t){let r=n.firstChild,s=!1;for(let o=0;o<e.length;o++){let i=e[o],a=i.dom;if(a.parentNode==n){for(;a!=r;)r=yL(r),s=!0;r=r.nextSibling}else s=!0,n.insertBefore(a,r);if(i instanceof xu){let l=r?r.previousSibling:n.lastChild;U6(i.contentDOM,i.children,t),r=l?l.nextSibling:n.firstChild}}for(;r;)r=yL(r),s=!0;s&&t.trackWrites==n&&(t.trackWrites=null)}const mp=function(n){n&&(this.nodeName=n)};mp.prototype=Object.create(null);const Zc=[new mp];function sE(n,e,t){if(n.length==0)return Zc;let r=t?Zc[0]:new mp,s=[r];for(let o=0;o<n.length;o++){let i=n[o].type.attrs;if(i){i.nodeName&&s.push(r=new mp(i.nodeName));for(let a in i){let l=i[a];l!=null&&(t&&s.length==1&&s.push(r=new mp(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 H6(n,e,t,r){if(t==Zc&&r==Zc)return e;let s=e;for(let o=0;o<r.length;o++){let i=r[o],a=t[o];if(o){let l;a&&a.nodeName==i.nodeName&&s!=n&&(l=s.parentNode)&&l.nodeName.toLowerCase()==i.nodeName||(l=document.createElement(i.nodeName),l.pmIsDeco=!0,l.appendChild(s),a=Zc[0]),s=l}Yoe(s,a||Zc[0],i)}return s}function Yoe(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 o=0;o<r.length;o++)s.indexOf(r[o])==-1&&n.classList.remove(r[o]);for(let o=0;o<s.length;o++)r.indexOf(s[o])==-1&&n.classList.add(s[o]);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 K6(n,e,t){return H6(n,n,Zc,sE(e,t,n.nodeType!=1))}function tx(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 yL(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Xoe{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Zoe(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,o=this.stack.length>>1,i=Math.min(o,e.length);for(;s<i&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=Lo,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<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[o])&&!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=xu.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,l),this.top=l,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,s){let o=-1,i;if(s>=this.preMatch.index&&(i=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,r))o=this.top.children.indexOf(i,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)){o=a;break}}return o<0?!1:(this.destroyBetween(this.index,o),this.index++,!0)}updateNodeAt(e,t,r,s,o){let i=this.top.children[s];return i.dirty==Qi&&i.dom==i.contentDOM&&(i.dirty=Xc),i.update(e,t,r,o)?(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,o,i){for(let a=this.index;a<this.top.children.length;a++){let l=this.top.children[a];if(l instanceof Jl){let c=this.preMatch.matched.get(l);if(c!=null&&c!=o)return!1;let u=l.dom,h,p=this.isLocked(u)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&l.dirty!=Qi&&tx(t,l.outerDeco));if(!p&&l.update(e,t,r,s))return this.destroyBetween(this.index,a),l.dom!=u&&(this.changed=!0),this.index++,!0;if(!p&&(h=this.recreateWrapper(l,e,t,r,s,i)))return this.destroyBetween(this.index,a),this.top.children[this.index]=h,h.contentDOM&&(h.dirty=Xc,h.updateChildren(s,i+1),h.dirty=Lo),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,r,s,o,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!tx(r,e.outerDeco)||!s.eq(e.innerDeco))return null;let a=Jl.create(this.top,t,r,s,o,i);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,o){let i=Jl.create(this.top,e,t,r,s,o);i.contentDOM&&i.updateChildren(s,o+1),this.top.children.splice(this.index++,0,i),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 o=new B6(this.top,e,t,r);this.top.children.splice(this.index++,0,o),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof xu;)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))&&((ns||Lr)&&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 $6(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 Zoe(n,e){let t=e,r=t.children.length,s=n.childCount,o=new Map,i=[];e:for(;s>0;){let a;for(;;)if(r){let c=t.children[r-1];if(c instanceof xu)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,o.set(a,s),i.push(a)}}return{index:s,matched:o,matches:i.reverse()}}function Joe(n,e){return n.type.side-e.type.side}function Qoe(n,e,t,r){let s=e.locals(n),o=0;if(s.length==0){for(let c=0;c<n.childCount;c++){let u=n.child(c);r(u,s,e.forChild(o,u),c),o+=u.nodeSize}return}let i=0,a=[],l=null;for(let c=0;;){let u,h;for(;i<s.length&&s[i].to==o;){let y=s[i++];y.widget&&(u?(h||(h=[u])).push(y):u=y)}if(u)if(h){h.sort(Joe);for(let y=0;y<h.length;y++)t(h[y],c,!!l)}else t(u,c,!!l);let p,m;if(l)m=-1,p=l,l=null;else if(c<n.childCount)m=c,p=n.child(c++);else break;for(let y=0;y<a.length;y++)a[y].to<=o&&a.splice(y--,1);for(;i<s.length&&s[i].from<=o&&s[i].to>o;)a.push(s[i++]);let S=o+p.nodeSize;if(p.isText){let y=S;i<s.length&&s[i].from<y&&(y=s[i].from);for(let w=0;w<a.length;w++)a[w].to<y&&(y=a[w].to);y<S&&(l=p.cut(y-o),p=p.cut(0,y-o),S=y,m=-1)}else for(;i<s.length&&s[i].to<S;)i++;let v=p.isInline&&!p.isLeaf?a.filter(y=>!y.inline):a.slice();r(p,v,e.forChild(o,p),m),o=S}}function eie(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 tie(n,e,t,r){for(let s=0,o=0;s<n.childCount&&o<=r;){let i=n.child(s++),a=o;if(o+=i.nodeSize,!i.isText)continue;let l=i.text;for(;s<n.childCount;){let c=n.child(s++);if(o+=c.nodeSize,!c.isText)break;l+=c.text}if(o>=t){if(o>=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 oE(n,e,t,r,s){let o=[];for(let i=0,a=0;i<n.length;i++){let l=n[i],c=a,u=a+=l.size;c>=t||u<=e?o.push(l):(c<e&&o.push(l.slice(0,e-c,r)),s&&(o.push(s),s=void 0),u>t&&o.push(l.slice(t-c,l.size,r)))}return o}function TT(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let s=n.docView.nearestDesc(t.focusNode),o=s&&s.size==0,i=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(i<0)return null;let a=r.resolve(i),l,c;if(B0(t)){for(l=i;s&&!s.node;)s=s.parent;let h=s.node;if(s&&h.isAtom&&Ge.isSelectable(h)&&s.parent&&!(h.isInline&&Ioe(t.focusNode,t.focusOffset,s.dom))){let p=s.posBefore;c=new Ge(i==p?a:r.resolve(p))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let h=i,p=i;for(let m=0;m<t.rangeCount;m++){let S=t.getRangeAt(m);h=Math.min(h,n.docView.posFromDOM(S.startContainer,S.startOffset,1)),p=Math.max(p,n.docView.posFromDOM(S.endContainer,S.endOffset,-1))}if(h<0)return null;[l,i]=p==n.state.selection.anchor?[p,h]:[h,p],a=r.resolve(i)}else l=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(l<0)return null}let u=r.resolve(l);if(!c){let h=e=="pointer"||n.state.selection.head<a.pos&&!o?1:-1;c=_T(n,u,a,h)}return c}function W6(n){return n.editable?n.hasFocus():G6(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function za(n,e=!1){let t=n.state.selection;if(V6(n,t),!!W6(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Lr){let r=n.domSelectionRange(),s=n.domObserver.currentSelection;if(r.anchorNode&&s.anchorNode&&Su(r.anchorNode,r.anchorOffset,s.anchorNode,s.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)rie(n);else{let{anchor:r,head:s}=t,o,i;SL&&!(t instanceof ot)&&(t.$from.parent.inlineContent||(o=xL(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=xL(n,t.to))),n.docView.setSelection(r,s,n,e),SL&&(o&&vL(o),i&&vL(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&nie(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const SL=ns||Lr&&R6<63;function xL(n,e){let{node:t,offset:r}=n.docView.domFromPos(e,0),s=r<t.childNodes.length?t.childNodes[r]:null,o=r?t.childNodes[r-1]:null;if(ns&&s&&s.contentEditable=="false")return aP(s);if((!s||s.contentEditable=="false")&&(!o||o.contentEditable=="false")){if(s)return aP(s);if(o)return aP(o)}}function aP(n){return n.contentEditable="true",ns&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function vL(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function nie(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(()=>{(!W6(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function rie(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,dr(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!s&&!n.state.selection.visible&&js&&Zl<=11&&(r.disabled=!0,r.disabled=!1)}function V6(n,e){if(e instanceof Ge){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(wL(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else wL(n)}function wL(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function _T(n,e,t,r){return n.someProp("createSelectionBetween",s=>s(n,e,t))||ot.between(e,t,r)}function bL(n){return n.editable&&!n.hasFocus()?!1:G6(n)}function G6(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 sie(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Su(e.node,e.offset,t.anchorNode,t.anchorOffset)}function iE(n,e){let{$anchor:t,$head:r}=n.selection,s=e>0?t.max(r):t.min(r),o=s.parent.inlineContent?s.depth?n.doc.resolve(e>0?s.after():s.before()):null:s;return o&&ut.findFrom(o,e)}function Fl(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function CL(n,e,t){let r=n.state.selection;if(r instanceof ot)if(t.indexOf("s")>-1){let{$head:s}=r,o=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let i=n.state.doc.resolve(s.pos+o.nodeSize*(e<0?-1:1));return Fl(n,new ot(r.$anchor,i))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let s=iE(n.state,e);return s&&s instanceof Ge?Fl(n,s):!1}else if(!(Io&&t.indexOf("m")>-1)){let s=r.$head,o=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter,i;if(!o||o.isText)return!1;let a=e<0?s.pos-o.nodeSize:s.pos;return o.isAtom||(i=n.docView.descAt(a))&&!i.contentDOM?Ge.isSelectable(o)?Fl(n,new Ge(e<0?n.state.doc.resolve(s.pos-o.nodeSize):s)):Mg?Fl(n,new ot(n.state.doc.resolve(e<0?a:a+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof Ge&&r.node.isInline)return Fl(n,new ot(e>0?r.$to:r.$from));{let s=iE(n.state,e);return s?Fl(n,s):!1}}}function nx(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function yp(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function kd(n,e){return e<0?oie(n):iie(n)}function oie(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let s,o,i=!1;for(mi&&t.nodeType==1&&r<nx(t)&&yp(t.childNodes[r],-1)&&(i=!0);;)if(r>0){if(t.nodeType!=1)break;{let a=t.childNodes[r-1];if(yp(a,-1))s=t,o=--r;else if(a.nodeType==3)t=a,r=t.nodeValue.length;else break}}else{if(q6(t))break;{let a=t.previousSibling;for(;a&&yp(a,-1);)s=t.parentNode,o=dr(a),a=a.previousSibling;if(a)t=a,r=nx(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}i?aE(n,t,r):s&&aE(n,s,o)}function iie(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let s=nx(t),o,i;for(;;)if(r<s){if(t.nodeType!=1)break;let a=t.childNodes[r];if(yp(a,1))o=t,i=++r;else break}else{if(q6(t))break;{let a=t.nextSibling;for(;a&&yp(a,1);)o=a.parentNode,i=dr(a)+1,a=a.nextSibling;if(a)t=a,r=0,s=nx(t);else{if(t=t.parentNode,t==n.dom)break;r=s=0}}}o&&aE(n,o,i)}function q6(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function aie(n,e){for(;n&&e==n.childNodes.length&&!_g(n);)e=dr(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 lie(n,e){for(;n&&!e&&!_g(n);)e=dr(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 aE(n,e,t){if(e.nodeType!=3){let o,i;(i=aie(e,t))?(e=i,t=0):(o=lie(e,t))&&(e=o,t=o.nodeValue.length)}let r=n.domSelection();if(!r)return;if(B0(r)){let o=document.createRange();o.setEnd(e,t),o.setStart(e,t),r.removeAllRanges(),r.addRange(o)}else r.extend&&r.extend(e,t);n.domObserver.setCurSelection();let{state:s}=n;setTimeout(()=>{n.state==s&&za(n)},50)}function PL(n,e){let t=n.state.doc.resolve(e);if(!(Lr||Moe)&&t.parent.inlineContent){let s=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),i=(o.top+o.bottom)/2;if(i>s.top&&i<s.bottom&&Math.abs(o.left-s.left)>1)return o.left<s.left?"ltr":"rtl"}if(e<t.end()){let o=n.coordsAtPos(e+1),i=(o.top+o.bottom)/2;if(i>s.top&&i<s.bottom&&Math.abs(o.left-s.left)>1)return o.left>s.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function kL(n,e,t){let r=n.state.selection;if(r instanceof ot&&!r.empty||t.indexOf("s")>-1||Io&&t.indexOf("m")>-1)return!1;let{$from:s,$to:o}=r;if(!s.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=iE(n.state,e);if(i&&i instanceof Ge)return Fl(n,i)}if(!s.parent.inlineContent){let i=e<0?s:o,a=r instanceof oo?ut.near(i,e):ut.findFrom(i,e);return a?Fl(n,a):!1}return!1}function EL(n,e){if(!(n.state.selection instanceof ot))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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let i=n.state.tr;return e<0?i.delete(t.pos-o.nodeSize,t.pos):i.delete(t.pos,t.pos+o.nodeSize),n.dispatch(i),!0}return!1}function IL(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function cie(n){if(!ns||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;IL(n,r,"true"),setTimeout(()=>IL(n,r,"false"),20)}return!1}function uie(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function die(n,e){let t=e.keyCode,r=uie(e);if(t==8||Io&&t==72&&r=="c")return EL(n,-1)||kd(n,-1);if(t==46&&!e.shiftKey||Io&&t==68&&r=="c")return EL(n,1)||kd(n,1);if(t==13||t==27)return!0;if(t==37||Io&&t==66&&r=="c"){let s=t==37?PL(n,n.state.selection.from)=="ltr"?-1:1:-1;return CL(n,s,r)||kd(n,s)}else if(t==39||Io&&t==70&&r=="c"){let s=t==39?PL(n,n.state.selection.from)=="ltr"?1:-1:1;return CL(n,s,r)||kd(n,s)}else{if(t==38||Io&&t==80&&r=="c")return kL(n,-1,r)||kd(n,-1);if(t==40||Io&&t==78&&r=="c")return cie(n)||kL(n,1,r)||kd(n,1);if(r==(Io?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function MT(n,e){n.someProp("transformCopied",m=>{e=m(e,n)});let t=[],{content:r,openStart:s,openEnd:o}=e;for(;s>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){s--,o--;let m=r.firstChild;t.push(m.type.name,m.attrs!=m.type.defaultAttrs?m.attrs:null),r=m.content}let i=n.someProp("clipboardSerializer")||Du.fromSchema(n.state.schema),a=e8(),l=a.createElement("div");l.appendChild(i.serializeFragment(r,{document:a}));let c=l.firstChild,u,h=0;for(;c&&c.nodeType==1&&(u=Q6[c.nodeName.toLowerCase()]);){for(let m=u.length-1;m>=0;m--){let S=a.createElement(u[m]);for(;l.firstChild;)S.appendChild(l.firstChild);l.appendChild(S),h++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${s} ${o}${h?` -${h}`:""} ${JSON.stringify(t)}`);let p=n.someProp("clipboardTextSerializer",m=>m(e,n))||e.content.textBetween(0,e.content.size,`
222
+
223
+ `);return{dom:l,text:p,slice:e}}function Y6(n,e,t,r,s){let o=s.parent.type.spec.code,i,a;if(!t&&!e)return null;let l=e&&(r||o||!t);if(l){if(n.someProp("transformPastedText",p=>{e=p(e,o||r,n)}),o)return e?new _e(me.from(n.state.schema.text(e.replace(/\r\n?/g,`
224
+ `))),0,0):_e.empty;let h=n.someProp("clipboardTextParser",p=>p(e,s,r,n));if(h)a=h;else{let p=s.marks(),{schema:m}=n.state,S=Du.fromSchema(m);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(v=>{let y=i.appendChild(document.createElement("p"));v&&y.appendChild(S.serializeNode(m.text(v,p)))})}}else n.someProp("transformPastedHTML",h=>{t=h(t,n)}),i=gie(t),Mg&&mie(i);let c=i&&i.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let h=+u[3];h>0;h--){let p=i.firstChild;for(;p&&p.nodeType!=1;)p=p.nextSibling;if(!p)break;i=p}if(a||(a=(n.someProp("clipboardParser")||n.someProp("domParser")||Zd.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(l||u),context:s,ruleFromNode(p){return p.nodeName=="BR"&&!p.nextSibling&&p.parentNode&&!hie.test(p.parentNode.nodeName)?{ignore:!0}:null}})),u)a=yie(TL(a,+u[1],+u[2]),u[4]);else if(a=_e.maxOpen(fie(a.content,s),!0),a.openStart||a.openEnd){let h=0,p=0;for(let m=a.content.firstChild;h<a.openStart&&!m.type.spec.isolating;h++,m=m.firstChild);for(let m=a.content.lastChild;p<a.openEnd&&!m.type.spec.isolating;p++,m=m.lastChild);a=TL(a,h,p)}return n.someProp("transformPasted",h=>{a=h(a,n)}),a}const hie=/^(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 fie(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)),o,i=[];if(n.forEach(a=>{if(!i)return;let l=s.findWrapping(a.type),c;if(!l)return i=null;if(c=i.length&&o.length&&Z6(l,o,a,i[i.length-1],0))i[i.length-1]=c;else{i.length&&(i[i.length-1]=J6(i[i.length-1],o.length));let u=X6(a,l);i.push(u),s=s.matchType(u.type),o=l}}),i)return me.from(i)}return n}function X6(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,me.from(n));return n}function Z6(n,e,t,r,s){if(s<n.length&&s<e.length&&n[s]==e[s]){let o=Z6(n,e,t,r.lastChild,s+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(s==n.length-1?t.type:n[s+1]))return r.copy(r.content.append(me.from(X6(t,n,s+1))))}}function J6(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,J6(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(me.empty,!0);return n.copy(t.append(r))}function lE(n,e,t,r,s,o){let i=e<0?n.firstChild:n.lastChild,a=i.content;return n.childCount>1&&(o=0),s<r-1&&(a=lE(a,e,t,r,s+1,o)),s>=t&&(a=e<0?i.contentMatchAt(0).fillBefore(a,o<=s).append(a):a.append(i.contentMatchAt(i.childCount).fillBefore(me.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,i.copy(a))}function TL(n,e,t){return e<n.openStart&&(n=new _e(lE(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new _e(lE(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const Q6={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 _L=null;function e8(){return _L||(_L=document.implementation.createHTMLDocument("title"))}let lP=null;function pie(n){let e=window.trustedTypes;return e?(lP||(lP=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),lP.createHTML(n)):n}function gie(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=e8().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),s;if((s=r&&Q6[r[1].toLowerCase()])&&(n=s.map(o=>"<"+o+">").join("")+n+s.map(o=>"</"+o+">").reverse().join("")),t.innerHTML=pie(n),s)for(let o=0;o<s.length;o++)t=t.querySelector(s[o])||t;return t}function mie(n){let e=n.querySelectorAll(Lr?"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 yie(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:o,openEnd:i}=n;for(let a=r.length-2;a>=0;a-=2){let l=t.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;s=me.from(l.create(r[a+1],s)),o++,i++}return new _e(s,o,i)}const rs={},ss={},Sie={touchstart:!0,touchmove:!0};class xie{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},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 vie(n){for(let e in rs){let t=rs[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{bie(n,r)&&!AT(n,r)&&(n.editable||!(r.type in ss))&&t(n,r)},Sie[e]?{passive:!0}:void 0)}ns&&n.dom.addEventListener("input",()=>null),cE(n)}function ql(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function wie(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 cE(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>AT(n,r))})}function AT(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function bie(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 Cie(n,e){!AT(n,e)&&rs[e.type]&&(n.editable||!(e.type in ss))&&rs[e.type](n,e)}ss.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!n8(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Da&&Lr&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),hh&&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,qc(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||die(n,t)?t.preventDefault():ql(n,"key")};ss.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ss.keypress=(n,e)=>{let t=e;if(n8(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Io&&t.metaKey)return;if(n.someProp("handleKeyPress",s=>s(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof ot)||!r.$from.sameParent(r.$to)){let s=String.fromCharCode(t.charCode);!/[\r\n]/.test(s)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,s))&&n.dispatch(n.state.tr.insertText(s).scrollIntoView()),t.preventDefault()}};function U0(n){return{left:n.clientX,top:n.clientY}}function Pie(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function OT(n,e,t,r,s){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let i=o.depth+1;i>0;i--)if(n.someProp(e,a=>i>o.depth?a(n,t,o.nodeAfter,o.before(i),s,!0):a(n,t,o.node(i),o.before(i),s,!1)))return!0;return!1}function Qd(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 kie(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&Ge.isSelectable(r)?(Qd(n,new Ge(t)),!0):!1}function Eie(n,e){if(e==-1)return!1;let t=n.state.selection,r,s;t instanceof Ge&&(r=t.node);let o=n.state.doc.resolve(e);for(let i=o.depth+1;i>0;i--){let a=i>o.depth?o.nodeAfter:o.node(i);if(Ge.isSelectable(a)){r&&t.$from.depth>0&&i>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?s=o.before(t.$from.depth):s=o.before(i);break}}return s!=null?(Qd(n,Ge.create(n.state.doc,s)),!0):!1}function Iie(n,e,t,r,s){return OT(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(s?Eie(n,t):kie(n,t))}function Tie(n,e,t,r){return OT(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",s=>s(n,e,r))}function _ie(n,e,t,r){return OT(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",s=>s(n,e,r))||Mie(n,t,r)}function Mie(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Qd(n,ot.create(r,0,r.content.size)),!0):!1;let s=r.resolve(e);for(let o=s.depth+1;o>0;o--){let i=o>s.depth?s.nodeAfter:s.node(o),a=s.before(o);if(i.inlineContent)Qd(n,ot.create(r,a+1,a+1+i.content.size));else if(Ge.isSelectable(i))Qd(n,Ge.create(r,a));else continue;return!0}}function RT(n){return rx(n)}const t8=Io?"metaKey":"ctrlKey";rs.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=RT(n),s=Date.now(),o="singleClick";s-n.input.lastClick.time<500&&Pie(t,n.input.lastClick)&&!t[t8]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:s,x:t.clientX,y:t.clientY,type:o,button:t.button};let i=n.posAtCoords(U0(t));i&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Aie(n,i,t,!!r)):(o=="doubleClick"?Tie:_ie)(n,i.pos,i.inside,t)?t.preventDefault():ql(n,"pointer"))};class Aie{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[t8],this.allowDefault=r.shiftKey;let o,i;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),i=t.inside;else{let u=e.state.doc.resolve(t.pos);o=u.parent,i=u.depth?u.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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof Ge&&c.from<=i&&c.to>i)&&(this.mightDrag={node:o,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&mi&&!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)),ql(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(()=>za(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(U0(e))),this.updateAllowDefault(e),this.allowDefault||!t?ql(this.view,"pointer"):Iie(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ns&&this.mightDrag&&!this.mightDrag.node.isAtom||Lr&&!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)?(Qd(this.view,ut.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ql(this.view,"pointer")}move(e){this.updateAllowDefault(e),ql(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)}}rs.touchstart=n=>{n.input.lastTouch=Date.now(),RT(n),ql(n,"pointer")};rs.touchmove=n=>{n.input.lastTouch=Date.now(),ql(n,"pointer")};rs.contextmenu=n=>RT(n);function n8(n,e){return n.composing?!0:ns&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const Oie=Da?5e3:-1;ss.compositionstart=ss.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof ot&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),rx(n,!0),n.markCursor=null;else if(rx(n,!e.selection.empty),mi&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let s=r.focusNode,o=r.focusOffset;s&&s.nodeType==1&&o!=0;){let i=o<0?s.lastChild:s.childNodes[o-1];if(!i)break;if(i.nodeType==3){let a=n.domSelection();a&&a.collapse(i,i.nodeValue.length);break}else s=i,o=-1}}n.input.composing=!0}r8(n,Oie)};ss.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++,r8(n,20))};function r8(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>rx(n),e))}function s8(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Die());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Rie(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=koe(e.focusNode,e.focusOffset),r=Eoe(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let s=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!s||!s.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let i=t.pmViewDesc;if(!(!i||!i.isText(t.nodeValue)))return r}}return t||r}function Die(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function rx(n,e=!1){if(!(Da&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),s8(n),e||n.docView&&n.docView.dirty){let t=TT(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function jie(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 Kp=js&&Zl<15||hh&&Aoe<604;rs.copy=ss.cut=(n,e)=>{let t=e,r=n.state.selection,s=t.type=="cut";if(r.empty)return;let o=Kp?null:t.clipboardData,i=r.content(),{dom:a,text:l}=MT(n,i);o?(t.preventDefault(),o.clearData(),o.setData("text/html",a.innerHTML),o.setData("text/plain",l)):jie(n,a),s&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Lie(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function Nie(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?Wp(n,r.value,null,s,e):Wp(n,r.textContent,r.innerHTML,s,e)},50)}function Wp(n,e,t,r,s){let o=Y6(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",l=>l(n,s,o||_e.empty)))return!0;if(!o)return!1;let i=Lie(o),a=i?n.state.tr.replaceSelectionWith(i,r):n.state.tr.replaceSelection(o);return n.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function o8(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," "):""}ss.paste=(n,e)=>{let t=e;if(n.composing&&!Da)return;let r=Kp?null:t.clipboardData,s=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Wp(n,o8(r),r.getData("text/html"),s,t)?t.preventDefault():Nie(n,t)};let i8=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}};const Fie=Io?"altKey":"ctrlKey";function a8(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[Fie]}rs.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let s=n.state.selection,o=s.empty?null:n.posAtCoords(U0(t)),i;if(!(o&&o.pos>=s.from&&o.pos<=(s instanceof Ge?s.to-1:s.to))){if(r&&r.mightDrag)i=Ge.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let h=n.docView.nearestDesc(t.target,!0);h&&h.node.type.spec.draggable&&h!=n.docView&&(i=Ge.create(n.state.doc,h.posBefore))}}let a=(i||n.state.selection).content(),{dom:l,text:c,slice:u}=MT(n,a);(!t.dataTransfer.files.length||!Lr||R6>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Kp?"Text":"text/html",l.innerHTML),t.dataTransfer.effectAllowed="copyMove",Kp||t.dataTransfer.setData("text/plain",c),n.dragging=new i8(u,a8(n,t),i)};rs.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ss.dragover=ss.dragenter=(n,e)=>e.preventDefault();ss.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let s=n.posAtCoords(U0(t));if(!s)return;let o=n.state.doc.resolve(s.pos),i=r&&r.slice;i?n.someProp("transformPasted",S=>{i=S(i,n)}):i=Y6(n,o8(t.dataTransfer),Kp?null:t.dataTransfer.getData("text/html"),!1,o);let a=!!(r&&a8(n,t));if(n.someProp("handleDrop",S=>S(n,t,i||_e.empty,a))){t.preventDefault();return}if(!i)return;t.preventDefault();let l=i?P6(n.state.doc,o.pos,i):o.pos;l==null&&(l=o.pos);let c=n.state.tr;if(a){let{node:S}=r;S?S.replace(c):c.deleteSelection()}let u=c.mapping.map(l),h=i.openStart==0&&i.openEnd==0&&i.content.childCount==1,p=c.doc;if(h?c.replaceRangeWith(u,u,i.content.firstChild):c.replaceRange(u,u,i),c.doc.eq(p))return;let m=c.doc.resolve(u);if(h&&Ge.isSelectable(i.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(i.content.firstChild))c.setSelection(new Ge(m));else{let S=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach((v,y,w,C)=>S=C),c.setSelection(_T(n,m,c.doc.resolve(S)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};rs.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())&&za(n)},20))};rs.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)};rs.beforeinput=(n,e)=>{if(Lr&&Da&&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",o=>o(n,qc(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 ss)rs[n]=ss[n];function Vp(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 sx{constructor(e,t){this.toDOM=e,this.spec=t||lu,this.side=this.spec.side||0}map(e,t,r,s){let{pos:o,deleted:i}=e.mapResult(t.from+s,this.side<0?-1:1);return i?null:new Ao(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof sx&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Vp(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Ql{constructor(e,t){this.attrs=e,this.spec=t||lu}map(e,t,r,s){let o=e.map(t.from+s,this.spec.inclusiveStart?-1:1)-r,i=e.map(t.to+s,this.spec.inclusiveEnd?1:-1)-r;return o>=i?null:new Ao(o,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Ql&&Vp(this.attrs,e.attrs)&&Vp(this.spec,e.spec)}static is(e){return e.type instanceof Ql}destroy(){}}class DT{constructor(e,t){this.attrs=e,this.spec=t||lu}map(e,t,r,s){let o=e.mapResult(t.from+s,1);if(o.deleted)return null;let i=e.mapResult(t.to+s,-1);return i.deleted||i.pos<=o.pos?null:new Ao(o.pos-r,i.pos-r,this)}valid(e,t){let{index:r,offset:s}=e.content.findIndex(t.from),o;return s==t.from&&!(o=e.child(r)).isText&&s+o.nodeSize==t.to}eq(e){return this==e||e instanceof DT&&Vp(this.attrs,e.attrs)&&Vp(this.spec,e.spec)}destroy(){}}class Ao{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new Ao(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 Ao(e,e,new sx(t,r))}static inline(e,t,r,s){return new Ao(e,t,new Ql(r,s))}static node(e,t,r,s){return new Ao(e,t,new DT(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Ql}get widget(){return this.type instanceof sx}}const jd=[],lu={};class Fn{constructor(e,t){this.local=e.length?e:jd,this.children=t.length?t:jd}static create(e,t){return t.length?ox(t,e,0,lu):Or}find(e,t,r){let s=[];return this.findInner(e??0,t??1e9,s,0,r),s}findInner(e,t,r,s,o){for(let i=0;i<this.local.length;i++){let a=this.local[i];a.from<=t&&a.to>=e&&(!o||o(a.spec))&&r.push(a.copy(a.from+s,a.to+s))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let a=this.children[i]+1;this.children[i+2].findInner(e-a,t-a,r,s+a,o)}}map(e,t,r){return this==Or||e.maps.length==0?this:this.mapInner(e,t,0,0,r||lu)}mapInner(e,t,r,s,o){let i;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,r,s);l&&l.type.valid(t,l)?(i||(i=[])).push(l):o.onRemove&&o.onRemove(this.local[a].spec)}return this.children.length?zie(this.children,i||[],e,t,r,s,o):i?new Fn(i.sort(cu),jd):Or}add(e,t){return t.length?this==Or?Fn.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let s,o=0;e.forEach((a,l)=>{let c=l+r,u;if(u=c8(t,a,c)){for(s||(s=this.children.slice());o<s.length&&s[o]<l;)o+=3;s[o]==l?s[o+2]=s[o+2].addInner(a,u,c+1):s.splice(o,0,l,l+a.nodeSize,ox(u,a,c+1,lu)),o+=3}});let i=l8(o?u8(t):t,-r);for(let a=0;a<i.length;a++)i[a].type.valid(e,i[a])||i.splice(a--,1);return new Fn(i.length?this.local.concat(i).sort(cu):this.local,s||this.children)}remove(e){return e.length==0||this==Or?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,s=this.local;for(let o=0;o<r.length;o+=3){let i,a=r[o]+t,l=r[o+1]+t;for(let u=0,h;u<e.length;u++)(h=e[u])&&h.from>a&&h.to<l&&(e[u]=null,(i||(i=[])).push(h));if(!i)continue;r==this.children&&(r=this.children.slice());let c=r[o+2].removeInner(i,a+1);c!=Or?r[o+2]=c:(r.splice(o,3),o-=3)}if(s.length){for(let o=0,i;o<e.length;o++)if(i=e[o])for(let a=0;a<s.length;a++)s[a].eq(i,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 Fn(s,r):Or}forChild(e,t){if(this==Or)return this;if(t.isLeaf)return Fn.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 o=e+1,i=o+t.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<i&&l.to>o&&l.type instanceof Ql){let c=Math.max(o,l.from)-o,u=Math.min(i,l.to)-o;c<u&&(s||(s=[])).push(l.copy(c,u))}}if(s){let a=new Fn(s.sort(cu),jd);return r?new Ul([a,r]):a}return r||Or}eq(e){if(this==e)return!0;if(!(e instanceof Fn)||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 jT(this.localsInner(e))}localsInner(e){if(this==Or)return jd;if(e.inlineContent||!this.local.some(Ql.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Ql||t.push(this.local[r]);return t}forEachSet(e){e(this)}}Fn.empty=new Fn([],[]);Fn.removeOverlap=jT;const Or=Fn.empty;class Ul{constructor(e){this.members=e}map(e,t){const r=this.members.map(s=>s.map(e,t,lu));return Ul.from(r)}forChild(e,t){if(t.isLeaf)return Fn.empty;let r=[];for(let s=0;s<this.members.length;s++){let o=this.members[s].forChild(e,t);o!=Or&&(o instanceof Ul?r=r.concat(o.members):r.push(o))}return Ul.from(r)}eq(e){if(!(e instanceof Ul)||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 o=this.members[s].localsInner(e);if(o.length)if(!t)t=o;else{r&&(t=t.slice(),r=!1);for(let i=0;i<o.length;i++)t.push(o[i])}}return t?jT(r?t:t.sort(cu)):jd}static from(e){switch(e.length){case 0:return Or;case 1:return e[0];default:return new Ul(e.every(t=>t instanceof Fn)?e:e.reduce((t,r)=>t.concat(r instanceof Fn?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function zie(n,e,t,r,s,o,i){let a=n.slice();for(let c=0,u=o;c<t.maps.length;c++){let h=0;t.maps[c].forEach((p,m,S,v)=>{let y=v-S-(m-p);for(let w=0;w<a.length;w+=3){let C=a[w+1];if(C<0||p>C+u-h)continue;let T=a[w]+u-h;m>=T?a[w+1]=p<=T?-2:-1:p>=u&&y&&(a[w]+=y,a[w+1]+=y)}h+=y}),u=t.maps[c].map(u,-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 u=t.map(n[c]+o),h=u-s;if(h<0||h>=r.content.size){l=!0;continue}let p=t.map(n[c+1]+o,-1),m=p-s,{index:S,offset:v}=r.content.findIndex(h),y=r.maybeChild(S);if(y&&v==h&&v+y.nodeSize==m){let w=a[c+2].mapInner(t,y,u+1,n[c]+o+1,i);w!=Or?(a[c]=h,a[c+1]=m,a[c+2]=w):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=Bie(a,n,e,t,s,o,i),u=ox(c,r,0,i);e=u.local;for(let h=0;h<a.length;h+=3)a[h+1]<0&&(a.splice(h,3),h-=3);for(let h=0,p=0;h<u.children.length;h+=3){let m=u.children[h];for(;p<a.length&&a[p]<m;)p+=3;a.splice(p,0,u.children[h],u.children[h+1],u.children[h+2])}}return new Fn(e.sort(cu),a)}function l8(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 Ao(s.from+e,s.to+e,s.type))}return t}function Bie(n,e,t,r,s,o,i){function a(l,c){for(let u=0;u<l.local.length;u++){let h=l.local[u].map(r,s,c);h?t.push(h):i.onRemove&&i.onRemove(l.local[u].spec)}for(let u=0;u<l.children.length;u+=3)a(l.children[u+2],l.children[u]+c+1)}for(let l=0;l<n.length;l+=3)n[l+1]==-1&&a(n[l+2],e[l]+o+1);return t}function c8(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,s=null;for(let o=0,i;o<n.length;o++)(i=n[o])&&i.from>t&&i.to<r&&((s||(s=[])).push(i),n[o]=null);return s}function u8(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function ox(n,e,t,r){let s=[],o=!1;e.forEach((a,l)=>{let c=c8(n,a,l+t);if(c){o=!0;let u=ox(c,a,t+l+1,r);u!=Or&&s.push(l,l+a.nodeSize,u)}});let i=l8(o?u8(n):n,-t).sort(cu);for(let a=0;a<i.length;a++)i[a].type.valid(e,i[a])||(r.onRemove&&r.onRemove(i[a].spec),i.splice(a--,1));return i.length||s.length?new Fn(i,s):Or}function cu(n,e){return n.from-e.from||n.to-e.to}function jT(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 o=e[s];if(o.from==r.from){o.to!=r.to&&(e==n&&(e=n.slice()),e[s]=o.copy(o.from,r.to),ML(e,s+1,o.copy(r.to,o.to)));continue}else{o.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,o.from),ML(e,s,r.copy(o.from,r.to)));break}}}return e}function ML(n,e,t){for(;e<n.length&&cu(t,n[e])>0;)e++;n.splice(e,0,t)}function cP(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=Or&&e.push(r)}),n.cursorWrapper&&e.push(Fn.create(n.state.doc,[n.cursorWrapper.deco])),Ul.from(e)}const $ie={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Uie=js&&Zl<=11;class Hie{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 Kie{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Hie,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]);js&&Zl<=11&&r.some(s=>s.type=="childList"&&s.removedNodes.length||s.type=="characterData"&&s.oldValue.length>s.target.nodeValue.length)?this.flushSoon():this.flush()}),Uie&&(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,$ie)),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(bL(this.view)){if(this.suppressingSelectionUpdates)return za(this.view);if(js&&Zl<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Su(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 o=e.focusNode;o;o=dh(o))t.add(o);for(let o=e.anchorNode;o;o=dh(o))if(t.has(o)){r=o;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)&&bL(e)&&!this.ignoreSelectionChange(r),o=-1,i=-1,a=!1,l=[];if(e.editable)for(let u=0;u<t.length;u++){let h=this.registerMutation(t[u],l);h&&(o=o<0?h.from:Math.min(h.from,o),i=i<0?h.to:Math.max(h.to,i),h.typeOver&&(a=!0))}if(mi&&l.length){let u=l.filter(h=>h.nodeName=="BR");if(u.length==2){let[h,p]=u;h.parentNode&&h.parentNode.parentNode==p.parentNode?p.remove():h.remove()}else{let{focusNode:h}=this.currentSelection;for(let p of u){let m=p.parentNode;m&&m.nodeName=="LI"&&(!h||Gie(e,h)!=m)&&p.remove()}}}let c=null;o<0&&s&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&B0(r)&&(c=TT(e))&&c.eq(ut.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,za(e),this.currentSelection.set(r),e.scrollToSelection()):(o>-1||s)&&(o>-1&&(e.docView.markDirty(o,i),Wie(e)),this.handleDOMChange(o,i,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||za(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 u=0;u<e.addedNodes.length;u++){let h=e.addedNodes[u];t.push(h),h.nodeType==3&&(this.lastChangedTextNode=h)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let s=e.previousSibling,o=e.nextSibling;if(js&&Zl<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:h,nextSibling:p}=e.addedNodes[u];(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(s=h),(!p||Array.prototype.indexOf.call(e.addedNodes,p)<0)&&(o=p)}let i=s&&s.parentNode==e.target?dr(s)+1:0,a=r.localPosFromDOM(e.target,i,-1),l=o&&o.parentNode==e.target?dr(o):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 AL=new WeakMap,OL=!1;function Wie(n){if(!AL.has(n)&&(AL.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=mi,OL)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."),OL=!0}}function RL(n,e){let t=e.startContainer,r=e.startOffset,s=e.endContainer,o=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return Su(i.node,i.offset,s,o)&&([t,r,s,o]=[s,o,t,r]),{anchorNode:t,anchorOffset:r,focusNode:s,focusOffset:o}}function Vie(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return RL(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?RL(n,t):null}function Gie(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 qie(n,e,t){let{node:r,fromOffset:s,toOffset:o,from:i,to:a}=n.docView.parseRange(e,t),l=n.domSelectionRange(),c,u=l.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:l.anchorOffset}],B0(l)||c.push({node:l.focusNode,offset:l.focusOffset})),Lr&&n.input.lastKeyCode===8)for(let y=o;y>s;y--){let w=r.childNodes[y-1],C=w.pmViewDesc;if(w.nodeName=="BR"&&!C){o=y;break}if(!C||C.size)break}let h=n.state.doc,p=n.someProp("domParser")||Zd.fromSchema(n.state.schema),m=h.resolve(i),S=null,v=p.parse(r,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:s,to:o,preserveWhitespace:m.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Yie,context:m});if(c&&c[0].pos!=null){let y=c[0].pos,w=c[1]&&c[1].pos;w==null&&(w=y),S={anchor:y+i,head:w+i}}return{doc:v,sel:S,from:i,to:a}}function Yie(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(ns&&/^(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||ns&&/^(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 Xie=/^(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 Zie(n,e,t,r,s){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let F=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,U=TT(n,F);if(U&&!n.state.selection.eq(U)){if(Lr&&Da&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",Y=>Y(n,qc(13,"Enter"))))return;let V=n.state.tr.setSelection(U);F=="pointer"?V.setMeta("pointer",!0):F=="key"&&V.scrollIntoView(),o&&V.setMeta("composition",o),n.dispatch(V)}return}let i=n.state.doc.resolve(e),a=i.sharedDepth(t);e=i.before(a+1),t=n.state.doc.resolve(t).after(a+1);let l=n.state.selection,c=qie(n,e,t),u=n.state.doc,h=u.slice(c.from,c.to),p,m;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(p=n.state.selection.to,m="end"):(p=n.state.selection.from,m="start"),n.input.lastKeyCode=null;let S=eae(h.content,c.doc.content,c.from,p,m);if(S&&n.input.domChangeCount++,(hh&&n.input.lastIOSEnter>Date.now()-225||Da)&&s.some(F=>F.nodeType==1&&!Xie.test(F.nodeName))&&(!S||S.endA>=S.endB)&&n.someProp("handleKeyDown",F=>F(n,qc(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!S)if(r&&l instanceof ot&&!l.empty&&l.$head.sameParent(l.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))S={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let F=DL(n,n.state.doc,c.sel);if(F&&!F.eq(n.state.selection)){let U=n.state.tr.setSelection(F);o&&U.setMeta("composition",o),n.dispatch(U)}}return}n.state.selection.from<n.state.selection.to&&S.start==S.endB&&n.state.selection instanceof ot&&(S.start>n.state.selection.from&&S.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?S.start=n.state.selection.from:S.endA<n.state.selection.to&&S.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(S.endB+=n.state.selection.to-S.endA,S.endA=n.state.selection.to)),js&&Zl<=11&&S.endB==S.start+1&&S.endA==S.start&&S.start>c.from&&c.doc.textBetween(S.start-c.from-1,S.start-c.from+1)=="  "&&(S.start--,S.endA--,S.endB--);let v=c.doc.resolveNoCache(S.start-c.from),y=c.doc.resolveNoCache(S.endB-c.from),w=u.resolve(S.start),C=v.sameParent(y)&&v.parent.inlineContent&&w.end()>=S.endA,T;if((hh&&n.input.lastIOSEnter>Date.now()-225&&(!C||s.some(F=>F.nodeName=="DIV"||F.nodeName=="P"))||!C&&v.pos<c.doc.content.size&&(!v.sameParent(y)||!v.parent.inlineContent)&&!/\S/.test(c.doc.textBetween(v.pos,y.pos,"",""))&&(T=ut.findFrom(c.doc.resolve(v.pos+1),1,!0))&&T.head>v.pos)&&n.someProp("handleKeyDown",F=>F(n,qc(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>S.start&&Qie(u,S.start,S.endA,v,y)&&n.someProp("handleKeyDown",F=>F(n,qc(8,"Backspace")))){Da&&Lr&&n.domObserver.suppressSelectionUpdates();return}Lr&&S.endB==S.start&&(n.input.lastChromeDelete=Date.now()),Da&&!C&&v.start()!=y.start()&&y.parentOffset==0&&v.depth==y.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==S.endA&&(S.endB-=2,y=c.doc.resolveNoCache(S.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(F){return F(n,qc(13,"Enter"))})},20));let E=S.start,_=S.endA,A,O,D;if(C){if(v.pos==y.pos)js&&Zl<=11&&v.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>za(n),20)),A=n.state.tr.delete(E,_),O=u.resolve(S.start).marksAcross(u.resolve(S.endA));else if(S.endA==S.endB&&(D=Jie(v.parent.content.cut(v.parentOffset,y.parentOffset),w.parent.content.cut(w.parentOffset,S.endA-w.start()))))A=n.state.tr,D.type=="add"?A.addMark(E,_,D.mark):A.removeMark(E,_,D.mark);else if(v.parent.child(v.index()).isText&&v.index()==y.index()-(y.textOffset?0:1)){let F=v.parent.textBetween(v.parentOffset,y.parentOffset);if(n.someProp("handleTextInput",U=>U(n,E,_,F)))return;A=n.state.tr.insertText(F,E,_)}}if(A||(A=n.state.tr.replace(E,_,c.doc.slice(S.start-c.from,S.endB-c.from))),c.sel){let F=DL(n,A.doc,c.sel);F&&!(Lr&&n.composing&&F.empty&&(S.start!=S.endB||n.input.lastChromeDelete<Date.now()-100)&&(F.head==E||F.head==A.mapping.map(_)-1)||js&&F.empty&&F.head==E)&&A.setSelection(F)}O&&A.ensureMarks(O),o&&A.setMeta("composition",o),n.dispatch(A.scrollIntoView())}function DL(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:_T(n,e.resolve(t.anchor),e.resolve(t.head))}function Jie(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,s=t,o=r,i,a,l;for(let u=0;u<r.length;u++)s=r[u].removeFromSet(s);for(let u=0;u<t.length;u++)o=t[u].removeFromSet(o);if(s.length==1&&o.length==0)a=s[0],i="add",l=u=>u.mark(a.addToSet(u.marks));else if(s.length==0&&o.length==1)a=o[0],i="remove",l=u=>u.mark(a.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(l(e.child(u)));if(me.from(c).eq(n))return{mark:a,type:i}}function Qie(n,e,t,r,s){if(t-e<=s.pos-r.pos||uP(r,!0,!1)<s.pos)return!1;let o=n.resolve(e);if(!r.parent.isTextblock){let a=o.nodeAfter;return a!=null&&t==e+a.nodeSize}if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let i=n.resolve(uP(o,!0,!0));return!i.parent.isTextblock||i.pos>t||uP(i,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(i.parent.content)}function uP(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 o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,s++}return s}function eae(n,e,t,r,s){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:i,b:a}=n.findDiffEnd(e,t+n.size,t+e.size);if(s=="end"){let l=Math.max(0,o-Math.min(i,a));r-=i+l-o}if(i<o&&n.size<e.size){let l=r<=o&&r>=i?o-r:0;o-=l,o&&o<e.size&&jL(e.textBetween(o-1,o+1))&&(o+=l?1:-1),a=o+(a-i),i=o}else if(a<o){let l=r<=o&&r>=a?o-r:0;o-=l,o&&o<n.size&&jL(n.textBetween(o-1,o+1))&&(o+=l?1:-1),i=o+(i-a),a=o}return{start:o,endA:i,endB:a}}function jL(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 tae{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 xie,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(BL),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=FL(this),NL(this),this.nodeViews=zL(this),this.docView=mL(this.state.doc,LL(this),cP(this),this.dom,this),this.domObserver=new Kie(this,(r,s,o,i)=>Zie(this,r,s,o,i)),this.domObserver.start(),vie(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&&cE(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(BL),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,o=!1,i=!1;e.storedMarks&&this.composing&&(s8(this),i=!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=zL(this);rae(m,this.nodeViews)&&(this.nodeViews=m,o=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&cE(this),this.editable=FL(this),NL(this);let l=cP(this),c=LL(this),u=s.plugins!=e.plugins&&!s.doc.eq(e.doc)?"reset":e.scrollToSelection>s.scrollToSelection?"to selection":"preserve",h=o||!this.docView.matchesNode(e.doc,c,l);(h||!e.selection.eq(s.selection))&&(i=!0);let p=u=="preserve"&&i&&this.dom.style.overflowAnchor==null&&Doe(this);if(i){this.domObserver.stop();let m=h&&(js||Lr)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&nae(s.selection,e.selection);if(h){let S=Lr?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Rie(this)),(o||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=mL(e.doc,c,l,this.dom,this)),S&&!this.trackWrites&&(m=!0)}m||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&sie(this))?za(this,m):(V6(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),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():p&&joe(p)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof Ge){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&uL(this,t.getBoundingClientRect(),e)}else uL(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 o=r.from+(this.state.doc.content.size-t.doc.content.size);(o>0&&this.state.doc.nodeAt(o))==r.node&&(s=o)}this.dragging=new i8(e.slice,e.move,s<0?void 0:Ge.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 i=0;i<this.directPlugins.length;i++){let a=this.directPlugins[i].props[e];if(a!=null&&(s=t?t(a):a))return s}let o=this.state.plugins;if(o)for(let i=0;i<o.length;i++){let a=o[i].props[e];if(a!=null&&(s=t?t(a):a))return s}}hasFocus(){if(js){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&&Loe(this.dom),za(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 $oe(this,e)}coordsAtPos(e,t=1){return F6(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 Voe(this,t||this.state,e)}pasteHTML(e,t){return Wp(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Wp(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return MT(this,e)}destroy(){this.docView&&(wie(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],cP(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Coe())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Cie(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?ns&&this.root.nodeType===11&&Toe(this.dom.ownerDocument)==this.dom&&Vie(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function LL(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"),[Ao.node(0,n.state.doc.content.size,e)]}function NL(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:Ao.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function FL(n){return!n.someProp("editable",e=>e(n.state)===!1)}function nae(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 zL(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 rae(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 BL(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 sc={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:"'"},ix={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},sae=typeof navigator<"u"&&/Mac/.test(navigator.platform),oae=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var hr=0;hr<10;hr++)sc[48+hr]=sc[96+hr]=String(hr);for(var hr=1;hr<=24;hr++)sc[hr+111]="F"+hr;for(var hr=65;hr<=90;hr++)sc[hr]=String.fromCharCode(hr+32),ix[hr]=String.fromCharCode(hr);for(var dP in sc)ix.hasOwnProperty(dP)||(ix[dP]=sc[dP]);function iae(n){var e=sae&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||oae&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ix:sc)[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 aae=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),lae=typeof navigator<"u"&&/Win/.test(navigator.platform);function cae(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,s,o,i;for(let a=0;a<e.length-1;a++){let l=e[a];if(/^(cmd|meta|m)$/i.test(l))i=!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))o=!0;else if(/^mod$/i.test(l))aae?i=!0:s=!0;else throw new Error("Unrecognized modifier name: "+l)}return r&&(t="Alt-"+t),s&&(t="Ctrl-"+t),i&&(t="Meta-"+t),o&&(t="Shift-"+t),t}function uae(n){let e=Object.create(null);for(let t in n)e[cae(t)]=n[t];return e}function hP(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 dae(n){return new xr({props:{handleKeyDown:d8(n)}})}function d8(n){let e=uae(n);return function(t,r){let s=iae(r),o,i=e[hP(s,r)];if(i&&i(t.state,t.dispatch,t))return!0;if(s.length==1&&s!=" "){if(r.shiftKey){let a=e[hP(s,r,!1)];if(a&&a(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(lae&&r.ctrlKey&&r.altKey)&&(o=sc[r.keyCode])&&o!=s){let a=e[hP(o,r)];if(a&&a(t.state,t.dispatch,t))return!0}}return!1}}const LT=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function h8(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const f8=(n,e,t)=>{let r=h8(n,t);if(!r)return!1;let s=NT(r);if(!s){let i=r.blockRange(),a=i&&Dh(i);return a==null?!1:(e&&e(n.tr.lift(i,a).scrollIntoView()),!0)}let o=s.nodeBefore;if(b8(n,s,e,-1))return!0;if(r.parent.content.size==0&&(fh(o,"end")||Ge.isSelectable(o)))for(let i=r.depth;;i--){let a=F0(n.doc,r.before(i),r.after(i),_e.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=n.tr.step(a);l.setSelection(fh(o,"end")?ut.findFrom(l.doc.resolve(l.mapping.map(s.pos,-1)),-1):Ge.create(l.doc,s.pos-o.nodeSize)),e(l.scrollIntoView())}return!0}if(i==1||r.node(i-1).childCount>1)break}return o.isAtom&&s.depth==r.depth-1?(e&&e(n.tr.delete(s.pos-o.nodeSize,s.pos).scrollIntoView()),!0):!1},hae=(n,e,t)=>{let r=h8(n,t);if(!r)return!1;let s=NT(r);return s?p8(n,s,e):!1},fae=(n,e,t)=>{let r=m8(n,t);if(!r)return!1;let s=FT(r);return s?p8(n,s,e):!1};function p8(n,e,t){let r=e.nodeBefore,s=r,o=e.pos-1;for(;!s.isTextblock;o--){if(s.type.spec.isolating)return!1;let u=s.lastChild;if(!u)return!1;s=u}let i=e.nodeAfter,a=i,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let u=a.firstChild;if(!u)return!1;a=u}let c=F0(n.doc,o,l,_e.empty);if(!c||c.from!=o||c instanceof Vn&&c.slice.size>=l-o)return!1;if(t){let u=n.tr.step(c);u.setSelection(ot.create(u.doc,o)),t(u.scrollIntoView())}return!0}function fh(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 g8=(n,e,t)=>{let{$head:r,empty:s}=n.selection,o=r;if(!s)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=NT(r)}let i=o&&o.nodeBefore;return!i||!Ge.isSelectable(i)?!1:(e&&e(n.tr.setSelection(Ge.create(n.doc,o.pos-i.nodeSize)).scrollIntoView()),!0)};function NT(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 m8(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const y8=(n,e,t)=>{let r=m8(n,t);if(!r)return!1;let s=FT(r);if(!s)return!1;let o=s.nodeAfter;if(b8(n,s,e,1))return!0;if(r.parent.content.size==0&&(fh(o,"start")||Ge.isSelectable(o))){let i=F0(n.doc,r.before(),r.after(),_e.empty);if(i&&i.slice.size<i.to-i.from){if(e){let a=n.tr.step(i);a.setSelection(fh(o,"start")?ut.findFrom(a.doc.resolve(a.mapping.map(s.pos)),1):Ge.create(a.doc,a.mapping.map(s.pos))),e(a.scrollIntoView())}return!0}}return o.isAtom&&s.depth==r.depth-1?(e&&e(n.tr.delete(s.pos,s.pos+o.nodeSize).scrollIntoView()),!0):!1},S8=(n,e,t)=>{let{$head:r,empty:s}=n.selection,o=r;if(!s)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset<r.parent.content.size)return!1;o=FT(r)}let i=o&&o.nodeAfter;return!i||!Ge.isSelectable(i)?!1:(e&&e(n.tr.setSelection(Ge.create(n.doc,o.pos)).scrollIntoView()),!0)};function FT(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 pae=(n,e)=>{let t=n.selection,r=t instanceof Ge,s;if(r){if(t.node.isTextblock||!pc(n.doc,t.from))return!1;s=t.from}else if(s=N0(n.doc,t.from,-1),s==null)return!1;if(e){let o=n.tr.join(s);r&&o.setSelection(Ge.create(o.doc,s-n.doc.resolve(s).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},gae=(n,e)=>{let t=n.selection,r;if(t instanceof Ge){if(t.node.isTextblock||!pc(n.doc,t.to))return!1;r=t.to}else if(r=N0(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},mae=(n,e)=>{let{$from:t,$to:r}=n.selection,s=t.blockRange(r),o=s&&Dh(s);return o==null?!1:(e&&e(n.tr.lift(s,o).scrollIntoView()),!0)},x8=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
225
+ `).scrollIntoView()),!0)};function zT(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 yae=(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),o=t.indexAfter(-1),i=zT(s.contentMatchAt(o));if(!i||!s.canReplaceWith(o,o,i))return!1;if(e){let a=t.after(),l=n.tr.replaceWith(a,a,i.createAndFill());l.setSelection(ut.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},v8=(n,e)=>{let t=n.selection,{$from:r,$to:s}=t;if(t instanceof oo||r.parent.inlineContent||s.parent.inlineContent)return!1;let o=zT(s.parent.contentMatchAt(s.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let i=(!r.parentOffset&&s.index()<s.parent.childCount?r:s).pos,a=n.tr.insert(i,o.createAndFill());a.setSelection(ot.create(a.doc,i+1)),e(a.scrollIntoView())}return!0},w8=(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 o=t.before();if(Fa(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),s=r&&Dh(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)};function Sae(n){return(e,t)=>{let{$from:r,$to:s}=e.selection;if(e.selection instanceof Ge&&e.selection.node.isBlock)return!r.parentOffset||!Fa(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],i,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=zT(r.node(m-1).contentMatchAt(r.indexAfter(m-1))),o.unshift(l&&a?{type:a}:null),i=m;break}else{if(m==1)return!1;o.unshift(null)}let u=e.tr;(e.selection instanceof ot||e.selection instanceof oo)&&u.deleteSelection();let h=u.mapping.map(r.pos),p=Fa(u.doc,h,o.length,o);if(p||(o[0]=a?{type:a}:null,p=Fa(u.doc,h,o.length,o)),!p)return!1;if(u.split(h,o.length,o),!l&&c&&r.node(i).type!=a){let m=u.mapping.map(r.before(i)),S=u.doc.resolve(m);a&&r.node(i-1).canReplaceWith(S.index(),S.index()+1,a)&&u.setNodeMarkup(u.mapping.map(r.before(i)),a)}return t&&t(u.scrollIntoView()),!0}}const xae=Sae(),vae=(n,e)=>{let{$from:t,to:r}=n.selection,s,o=t.sharedDepth(r);return o==0?!1:(s=t.before(o),e&&e(n.tr.setSelection(Ge.create(n.doc,s))),!0)};function wae(n,e,t){let r=e.nodeBefore,s=e.nodeAfter,o=e.index();return!r||!s||!r.type.compatibleContent(s.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(s.isTextblock||pc(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function b8(n,e,t,r){let s=e.nodeBefore,o=e.nodeAfter,i,a,l=s.type.spec.isolating||o.type.spec.isolating;if(!l&&wae(n,e,t))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(i=(a=s.contentMatchAt(s.childCount)).findWrapping(o.type))&&a.matchType(i[0]||o.type).validEnd){if(t){let m=e.pos+o.nodeSize,S=me.empty;for(let w=i.length-1;w>=0;w--)S=me.from(i[w].create(null,S));S=me.from(s.copy(S));let v=n.tr.step(new Xn(e.pos-1,m,e.pos,m,new _e(S,1,0),i.length,!0)),y=v.doc.resolve(m+2*i.length);y.nodeAfter&&y.nodeAfter.type==s.type&&pc(v.doc,y.pos)&&v.join(y.pos),t(v.scrollIntoView())}return!0}let u=o.type.spec.isolating||r>0&&l?null:ut.findFrom(e,1),h=u&&u.$from.blockRange(u.$to),p=h&&Dh(h);if(p!=null&&p>=e.depth)return t&&t(n.tr.lift(h,p).scrollIntoView()),!0;if(c&&fh(o,"start",!0)&&fh(s,"end")){let m=s,S=[];for(;S.push(m),!m.isTextblock;)m=m.lastChild;let v=o,y=1;for(;!v.isTextblock;v=v.firstChild)y++;if(m.canReplace(m.childCount,m.childCount,v.content)){if(t){let w=me.empty;for(let T=S.length-1;T>=0;T--)w=me.from(S[T].copy(w));let C=n.tr.step(new Xn(e.pos-S.length,e.pos+o.nodeSize,e.pos+y,e.pos+o.nodeSize-y,new _e(w,S.length,0),0,!0));t(C.scrollIntoView())}return!0}}return!1}function C8(n){return function(e,t){let r=e.selection,s=n<0?r.$from:r.$to,o=s.depth;for(;s.node(o).isInline;){if(!o)return!1;o--}return s.node(o).isTextblock?(t&&t(e.tr.setSelection(ot.create(e.doc,n<0?s.start(o):s.end(o)))),!0):!1}}const bae=C8(-1),Cae=C8(1);function Pae(n,e=null){return function(t,r){let{$from:s,$to:o}=t.selection,i=s.blockRange(o),a=i&&kT(i,n,e);return a?(r&&r(t.tr.wrap(i,a).scrollIntoView()),!0):!1}}function $L(n,e=null){return function(t,r){let s=!1;for(let o=0;o<t.selection.ranges.length&&!s;o++){let{$from:{pos:i},$to:{pos:a}}=t.selection.ranges[o];t.doc.nodesBetween(i,a,(l,c)=>{if(s)return!1;if(!(!l.isTextblock||l.hasMarkup(n,e)))if(l.type==n)s=!0;else{let u=t.doc.resolve(c),h=u.index();s=u.parent.canReplaceWith(h,h+1,n)}})}if(!s)return!1;if(r){let o=t.tr;for(let i=0;i<t.selection.ranges.length;i++){let{$from:{pos:a},$to:{pos:l}}=t.selection.ranges[i];o.setBlockType(a,l,n,e)}r(o.scrollIntoView())}return!0}}function BT(...n){return function(e,t,r){for(let s=0;s<n.length;s++)if(n[s](e,t,r))return!0;return!1}}BT(LT,f8,g8);BT(LT,y8,S8);BT(x8,v8,w8,xae);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function kae(n,e=null){return function(t,r){let{$from:s,$to:o}=t.selection,i=s.blockRange(o);if(!i)return!1;let a=r?t.tr:null;return Eae(a,i,n,e)?(r&&r(a.scrollIntoView()),!0):!1}}function Eae(n,e,t,r=null){let s=!1,o=e,i=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=i.resolve(e.start-2);o=new QS(l,l,e.depth),e.endIndex<e.parent.childCount&&(e=new QS(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),s=!0}let a=kT(o,t,r,e);return a?(n&&Iae(n,e,a,s,t),!0):!1}function Iae(n,e,t,r,s){let o=me.empty;for(let u=t.length-1;u>=0;u--)o=me.from(t[u].type.create(t[u].attrs,o));n.step(new Xn(e.start-(r?2:0),e.end,e.start,e.end,new _e(o,0,0),t.length,!0));let i=0;for(let u=0;u<t.length;u++)t[u].type==s&&(i=u+1);let a=t.length-i,l=e.start+t.length-(r?2:0),c=e.parent;for(let u=e.startIndex,h=e.endIndex,p=!0;u<h;u++,p=!1)!p&&Fa(n.doc,l,a)&&(n.split(l,a),l+=2*a),l+=c.child(u).nodeSize;return n}function Tae(n){return function(e,t){let{$from:r,$to:s}=e.selection,o=r.blockRange(s,i=>i.childCount>0&&i.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?_ae(e,t,n,o):Mae(e,t,o):!0:!1}}function _ae(n,e,t,r){let s=n.tr,o=r.end,i=r.$to.end(r.depth);o<i&&(s.step(new Xn(o-1,i,o,i,new _e(me.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new QS(s.doc.resolve(r.$from.pos),s.doc.resolve(i),r.depth));const a=Dh(r);if(a==null)return!1;s.lift(r,a);let l=s.doc.resolve(s.mapping.map(o,-1)-1);return pc(s.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&s.join(l.pos),e(s.scrollIntoView()),!0}function Mae(n,e,t){let r=n.tr,s=t.parent;for(let m=t.end,S=t.endIndex-1,v=t.startIndex;S>v;S--)m-=s.child(S).nodeSize,r.delete(m-1,m+1);let o=r.doc.resolve(t.start),i=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let a=t.startIndex==0,l=t.endIndex==s.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(a?0:1),u+1,i.content.append(l?me.empty:me.from(s))))return!1;let h=o.pos,p=h+i.nodeSize;return r.step(new Xn(h-(a?1:0),p+(l?1:0),h+1,p-1,new _e((a?me.empty:me.from(s.copy(me.empty))).append(l?me.empty:me.from(s.copy(me.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function Aae(n){return function(e,t){let{$from:r,$to:s}=e.selection,o=r.blockRange(s,c=>c.childCount>0&&c.firstChild.type==n);if(!o)return!1;let i=o.startIndex;if(i==0)return!1;let a=o.parent,l=a.child(i-1);if(l.type!=n)return!1;if(t){let c=l.lastChild&&l.lastChild.type==a.type,u=me.from(c?n.create():null),h=new _e(me.from(n.create(null,me.from(a.type.create(null,u)))),c?3:1,0),p=o.start,m=o.end;t(e.tr.step(new Xn(p-(c?3:1),m,p,m,h,1,!0)).scrollIntoView())}return!0}}function H0(n){const{state:e,transaction:t}=n;let{selection:r}=t,{doc:s}=t,{storedMarks:o}=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 o},get selection(){return r},get doc(){return s},get tr(){return r=t.selection,s=t.doc,o=t.storedMarks,t}}}class K0{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:o}=r,i=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([a,l])=>[a,(...u)=>{const h=l(...u)(i);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:r,editor:s,state:o}=this,{view:i}=s,a=[],l=!!e,c=e||o.tr,u=()=>(!l&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(c),a.every(p=>p===!0)),h={...Object.fromEntries(Object.entries(r).map(([p,m])=>[p,(...v)=>{const y=this.buildProps(c,t),w=m(...v)(y);return a.push(w),h}])),run:u};return h}createCan(e){const{rawCommands:t,state:r}=this,s=!1,o=e||r.tr,i=this.buildProps(o,s);return{...Object.fromEntries(Object.entries(t).map(([l,c])=>[l,(...u)=>c(...u)({...i,dispatch:void 0})])),chain:()=>this.createChain(o,s)}}buildProps(e,t=!0){const{rawCommands:r,editor:s,state:o}=this,{view:i}=s,a={tr:e,editor:s,view:i,state:H0({state:o,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,(...u)=>c(...u)(a)]))}};return a}}class Oae{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 Fe(n,e,t){return n.config[e]===void 0&&n.parent?Fe(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?Fe(n.parent,e,t):null}):n.config[e]}function W0(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 P8(n){const e=[],{nodeExtensions:t,markExtensions:r}=W0(n),s=[...t,...r],o={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return n.forEach(i=>{const a={name:i.name,options:i.options,storage:i.storage,extensions:s},l=Fe(i,"addGlobalAttributes",a);if(!l)return;l().forEach(u=>{u.types.forEach(h=>{Object.entries(u.attributes).forEach(([p,m])=>{e.push({type:h,name:p,attribute:{...o,...m}})})})})}),s.forEach(i=>{const a={name:i.name,options:i.options,storage:i.storage},l=Fe(i,"addAttributes",a);if(!l)return;const c=l();Object.entries(c).forEach(([u,h])=>{const p={...o,...h};typeof(p==null?void 0:p.default)=="function"&&(p.default=p.default()),p!=null&&p.isRequired&&(p==null?void 0:p.default)===void 0&&delete p.default,e.push({type:i.name,name:u,attribute:p})})}),e}function Jn(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 Qn(...n){return n.filter(e=>!!e).reduce((e,t)=>{const r={...e};return Object.entries(t).forEach(([s,o])=>{if(!r[s]){r[s]=o;return}if(s==="class"){const a=o?String(o).split(" "):[],l=r[s]?r[s].split(" "):[],c=a.filter(u=>!l.includes(u));r[s]=[...l,...c].join(" ")}else if(s==="style"){const a=o?o.split(";").map(u=>u.trim()).filter(Boolean):[],l=r[s]?r[s].split(";").map(u=>u.trim()).filter(Boolean):[],c=new Map;l.forEach(u=>{const[h,p]=u.split(":").map(m=>m.trim());c.set(h,p)}),a.forEach(u=>{const[h,p]=u.split(":").map(m=>m.trim());c.set(h,p)}),r[s]=Array.from(c.entries()).map(([u,h])=>`${u}: ${h}`).join("; ")}else r[s]=o}),r},{})}function uE(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)=>Qn(t,r),{})}function k8(n){return typeof n=="function"}function gt(n,e=void 0,...t){return k8(n)?e?n.bind(e)(...t):n(...t):n}function Rae(n={}){return Object.keys(n).length===0&&n.constructor===Object}function Dae(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function UL(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((o,i)=>{const a=i.attribute.parseHTML?i.attribute.parseHTML(t):Dae(t.getAttribute(i.name));return a==null?o:{...o,[i.name]:a}},{});return{...r,...s}}}}function HL(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&Rae(t)?!1:t!=null))}function E8(n,e){var t;const r=P8(n),{nodeExtensions:s,markExtensions:o}=W0(n),i=(t=s.find(c=>Fe(c,"topNode")))===null||t===void 0?void 0:t.name,a=Object.fromEntries(s.map(c=>{const u=r.filter(w=>w.type===c.name),h={name:c.name,options:c.options,storage:c.storage,editor:e},p=n.reduce((w,C)=>{const T=Fe(C,"extendNodeSchema",h);return{...w,...T?T(c):{}}},{}),m=HL({...p,content:gt(Fe(c,"content",h)),marks:gt(Fe(c,"marks",h)),group:gt(Fe(c,"group",h)),inline:gt(Fe(c,"inline",h)),atom:gt(Fe(c,"atom",h)),selectable:gt(Fe(c,"selectable",h)),draggable:gt(Fe(c,"draggable",h)),code:gt(Fe(c,"code",h)),whitespace:gt(Fe(c,"whitespace",h)),linebreakReplacement:gt(Fe(c,"linebreakReplacement",h)),defining:gt(Fe(c,"defining",h)),isolating:gt(Fe(c,"isolating",h)),attrs:Object.fromEntries(u.map(w=>{var C;return[w.name,{default:(C=w==null?void 0:w.attribute)===null||C===void 0?void 0:C.default}]}))}),S=gt(Fe(c,"parseHTML",h));S&&(m.parseDOM=S.map(w=>UL(w,u)));const v=Fe(c,"renderHTML",h);v&&(m.toDOM=w=>v({node:w,HTMLAttributes:uE(w,u)}));const y=Fe(c,"renderText",h);return y&&(m.toText=y),[c.name,m]})),l=Object.fromEntries(o.map(c=>{const u=r.filter(y=>y.type===c.name),h={name:c.name,options:c.options,storage:c.storage,editor:e},p=n.reduce((y,w)=>{const C=Fe(w,"extendMarkSchema",h);return{...y,...C?C(c):{}}},{}),m=HL({...p,inclusive:gt(Fe(c,"inclusive",h)),excludes:gt(Fe(c,"excludes",h)),group:gt(Fe(c,"group",h)),spanning:gt(Fe(c,"spanning",h)),code:gt(Fe(c,"code",h)),attrs:Object.fromEntries(u.map(y=>{var w;return[y.name,{default:(w=y==null?void 0:y.attribute)===null||w===void 0?void 0:w.default}]}))}),S=gt(Fe(c,"parseHTML",h));S&&(m.parseDOM=S.map(y=>UL(y,u)));const v=Fe(c,"renderHTML",h);return v&&(m.toDOM=y=>v({mark:y,HTMLAttributes:uE(y,u)})),[c.name,m]}));return new f6({topNode:i,nodes:a,marks:l})}function fP(n,e){return e.nodes[n]||e.marks[n]||null}function KL(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function V0(n,e){const t=Du.fromSchema(e).serializeFragment(n),s=document.implementation.createHTMLDocument().createElement("div");return s.appendChild(t),s.innerHTML}const jae=(n,e=500)=>{let t="";const r=n.parentOffset;return n.parent.nodesBetween(Math.max(0,r-e),r,(s,o,i,a)=>{var l,c;const u=((c=(l=s.type.spec).toText)===null||c===void 0?void 0:c.call(l,{node:s,pos:o,parent:i,index:a}))||s.textContent||"%leaf%";t+=s.isAtom&&!s.isText?u:u.slice(0,Math.max(0,r-o))}),t};function $T(n){return Object.prototype.toString.call(n)==="[object RegExp]"}class G0{constructor(e){this.find=e.find,this.handler=e.handler}}const Lae=(n,e)=>{if($T(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 uy(n){var e;const{editor:t,from:r,to:s,text:o,rules:i,plugin:a}=n,{view:l}=t;if(l.composing)return!1;const c=l.state.doc.resolve(r);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(p=>p.type.spec.code))return!1;let u=!1;const h=jae(c)+o;return i.forEach(p=>{if(u)return;const m=Lae(h,p.find);if(!m)return;const S=l.state.tr,v=H0({state:l.state,transaction:S}),y={from:r-(m[0].length-o.length),to:s},{commands:w,chain:C,can:T}=new K0({editor:t,state:v});p.handler({state:v,range:y,match:m,commands:w,chain:C,can:T})===null||!S.steps.length||(S.setMeta(a,{transform:S,from:r,to:s,text:o}),l.dispatch(S),u=!0)}),u}function Nae(n){const{editor:e,rules:t}=n,r=new xr({state:{init(){return null},apply(s,o,i){const a=s.getMeta(r);if(a)return a;const l=s.getMeta("applyInputRules");return!!l&&setTimeout(()=>{let{text:u}=l;typeof u=="string"?u=u:u=V0(me.from(u),i.schema);const{from:h}=l,p=h+u.length;uy({editor:e,from:h,to:p,text:u,rules:t,plugin:r})}),s.selectionSet||s.docChanged?null:o}},props:{handleTextInput(s,o,i,a){return uy({editor:e,from:o,to:i,text:a,rules:t,plugin:r})},handleDOMEvents:{compositionend:s=>(setTimeout(()=>{const{$cursor:o}=s.state.selection;o&&uy({editor:e,from:o.pos,to:o.pos,text:"",rules:t,plugin:r})}),!1)},handleKeyDown(s,o){if(o.key!=="Enter")return!1;const{$cursor:i}=s.state.selection;return i?uy({editor:e,from:i.pos,to:i.pos,text:`
226
+ `,rules:t,plugin:r}):!1}},isInputRules:!0});return r}function Fae(n){return Object.prototype.toString.call(n).slice(8,-1)}function dy(n){return Fae(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function q0(n,e){const t={...n};return dy(n)&&dy(e)&&Object.keys(e).forEach(r=>{dy(e[r])&&dy(n[r])?t[r]=q0(n[r],e[r]):t[r]=e[r]}),t}class ea{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=gt(Fe(this,"addOptions",{name:this.name}))),this.storage=gt(Fe(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new ea(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>q0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new ea(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=gt(Fe(t,"addOptions",{name:t.name})),t.storage=gt(Fe(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 i=s.marks();if(!!!i.find(c=>(c==null?void 0:c.type.name)===t.name))return!1;const l=i.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 zae(n){return typeof n=="number"}class Bae{constructor(e){this.find=e.find,this.handler=e.handler}}const $ae=(n,e,t)=>{if($T(e))return[...n.matchAll(e)];const r=e(n,t);return r?r.map(s=>{const o=[s.text];return o.index=s.index,o.input=n,o.data=s.data,s.replaceWith&&(s.text.includes(s.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),o.push(s.replaceWith)),o}):[]};function Uae(n){const{editor:e,state:t,from:r,to:s,rule:o,pasteEvent:i,dropEvent:a}=n,{commands:l,chain:c,can:u}=new K0({editor:e,state:t}),h=[];return t.doc.nodesBetween(r,s,(m,S)=>{if(!m.isTextblock||m.type.spec.code)return;const v=Math.max(r,S),y=Math.min(s,S+m.content.size),w=m.textBetween(v-S,y-S,void 0,"");$ae(w,o.find,i).forEach(T=>{if(T.index===void 0)return;const E=v+T.index+1,_=E+T[0].length,A={from:t.tr.mapping.map(E),to:t.tr.mapping.map(_)},O=o.handler({state:t,range:A,match:T,commands:l,chain:c,can:u,pasteEvent:i,dropEvent:a});h.push(O)})}),h.every(m=>m!==null)}let hy=null;const Hae=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 Kae(n){const{editor:e,rules:t}=n;let r=null,s=!1,o=!1,i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,a;try{a=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{a=null}const l=({state:u,from:h,to:p,rule:m,pasteEvt:S})=>{const v=u.tr,y=H0({state:u,transaction:v});if(!(!Uae({editor:e,state:y,from:Math.max(h-1,0),to:p.b-1,rule:m,pasteEvent:S,dropEvent:a})||!v.steps.length)){try{a=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{a=null}return i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,v}};return t.map(u=>new xr({view(h){const p=S=>{var v;r=!((v=h.dom.parentElement)===null||v===void 0)&&v.contains(S.target)?h.dom.parentElement:null,r&&(hy=e)},m=()=>{hy&&(hy=null)};return window.addEventListener("dragstart",p),window.addEventListener("dragend",m),{destroy(){window.removeEventListener("dragstart",p),window.removeEventListener("dragend",m)}}},props:{handleDOMEvents:{drop:(h,p)=>{if(o=r===h.dom.parentElement,a=p,!o){const m=hy;m&&setTimeout(()=>{const S=m.state.selection;S&&m.commands.deleteRange({from:S.from,to:S.to})},10)}return!1},paste:(h,p)=>{var m;const S=(m=p.clipboardData)===null||m===void 0?void 0:m.getData("text/html");return i=p,s=!!(S!=null&&S.includes("data-pm-slice")),!1}}},appendTransaction:(h,p,m)=>{const S=h[0],v=S.getMeta("uiEvent")==="paste"&&!s,y=S.getMeta("uiEvent")==="drop"&&!o,w=S.getMeta("applyPasteRules"),C=!!w;if(!v&&!y&&!C)return;if(C){let{text:_}=w;typeof _=="string"?_=_:_=V0(me.from(_),m.schema);const{from:A}=w,O=A+_.length,D=Hae(_);return l({rule:u,state:m,from:A,to:{b:O},pasteEvt:D})}const T=p.doc.content.findDiffStart(m.doc.content),E=p.doc.content.findDiffEnd(m.doc.content);if(!(!zae(T)||!E||T===E.b))return l({rule:u,state:m,from:T,to:E,pasteEvt:i})}}))}function Wae(n){const e=n.filter((t,r)=>n.indexOf(t)!==r);return Array.from(new Set(e))}class Jc{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=Jc.resolve(e),this.schema=E8(this.extensions,t),this.setupExtensions()}static resolve(e){const t=Jc.sort(Jc.flatten(e)),r=Wae(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=Fe(t,"addExtensions",r);return s?[t,...this.flatten(s())]:t}).flat(10)}static sort(e){return e.sort((r,s)=>{const o=Fe(r,"priority")||100,i=Fe(s,"priority")||100;return o>i?-1:o<i?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:fP(t.name,this.schema)},s=Fe(t,"addCommands",r);return s?{...e,...s()}:e},{})}get plugins(){const{editor:e}=this,t=Jc.sort([...this.extensions].reverse()),r=[],s=[],o=t.map(i=>{const a={name:i.name,options:i.options,storage:i.storage,editor:e,type:fP(i.name,this.schema)},l=[],c=Fe(i,"addKeyboardShortcuts",a);let u={};if(i.type==="mark"&&Fe(i,"exitable",a)&&(u.ArrowRight=()=>ea.handleExit({editor:e,mark:i})),c){const v=Object.fromEntries(Object.entries(c()).map(([y,w])=>[y,()=>w({editor:e})]));u={...u,...v}}const h=dae(u);l.push(h);const p=Fe(i,"addInputRules",a);KL(i,e.options.enableInputRules)&&p&&r.push(...p());const m=Fe(i,"addPasteRules",a);KL(i,e.options.enablePasteRules)&&m&&s.push(...m());const S=Fe(i,"addProseMirrorPlugins",a);if(S){const v=S();l.push(...v)}return l}).flat();return[Nae({editor:e,rules:r}),...Kae({editor:e,rules:s}),...o]}get attributes(){return P8(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=W0(this.extensions);return Object.fromEntries(t.filter(r=>!!Fe(r,"addNodeView")).map(r=>{const s=this.attributes.filter(l=>l.type===r.name),o={name:r.name,options:r.options,storage:r.storage,editor:e,type:Jn(r.name,this.schema)},i=Fe(r,"addNodeView",o);if(!i)return[];const a=(l,c,u,h,p)=>{const m=uE(l,s);return i()({node:l,view:c,getPos:u,decorations:h,innerDecorations:p,editor:e,extension:r,HTMLAttributes:m})};return[r.name,a]}))}setupExtensions(){this.extensions.forEach(e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const r={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:fP(e.name,this.schema)};e.type==="mark"&&(!((t=gt(Fe(e,"keepOnSplit",r)))!==null&&t!==void 0)||t)&&this.splittableMarks.push(e.name);const s=Fe(e,"onBeforeCreate",r),o=Fe(e,"onCreate",r),i=Fe(e,"onUpdate",r),a=Fe(e,"onSelectionUpdate",r),l=Fe(e,"onTransaction",r),c=Fe(e,"onFocus",r),u=Fe(e,"onBlur",r),h=Fe(e,"onDestroy",r);s&&this.editor.on("beforeCreate",s),o&&this.editor.on("create",o),i&&this.editor.on("update",i),a&&this.editor.on("selectionUpdate",a),l&&this.editor.on("transaction",l),c&&this.editor.on("focus",c),u&&this.editor.on("blur",u),h&&this.editor.on("destroy",h)})}}class yr{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=gt(Fe(this,"addOptions",{name:this.name}))),this.storage=gt(Fe(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new yr(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>q0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new yr({...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=gt(Fe(t,"addOptions",{name:t.name})),t.storage=gt(Fe(t,"addStorage",{name:t.name,options:t.options})),t}}function I8(n,e,t){const{from:r,to:s}=e,{blockSeparator:o=`
227
+
228
+ `,textSerializers:i={}}=t||{};let a="";return n.nodesBetween(r,s,(l,c,u,h)=>{var p;l.isBlock&&c>r&&(a+=o);const m=i==null?void 0:i[l.type.name];if(m)return u&&(a+=m({node:l,pos:c,parent:u,index:h,range:e})),!1;l.isText&&(a+=(p=l==null?void 0:l.text)===null||p===void 0?void 0:p.slice(Math.max(r,c)-c,s-c))}),a}function UT(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const Vae=yr.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new xr({key:new uo("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:r,selection:s}=e,{ranges:o}=s,i=Math.min(...o.map(u=>u.$from.pos)),a=Math.max(...o.map(u=>u.$to.pos)),l=UT(t);return I8(r,{from:i,to:a},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),Gae=()=>({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),qae=(n=!1)=>({commands:e})=>e.setContent("",n),Yae=()=>({state:n,tr:e,dispatch:t})=>{const{selection:r}=e,{ranges:s}=r;return t&&s.forEach(({$from:o,$to:i})=>{n.doc.nodesBetween(o.pos,i.pos,(a,l)=>{if(a.type.isText)return;const{doc:c,mapping:u}=e,h=c.resolve(u.map(l)),p=c.resolve(u.map(l+a.nodeSize)),m=h.blockRange(p);if(!m)return;const S=Dh(m);if(a.type.isTextblock){const{defaultType:v}=h.parent.contentMatchAt(h.index());e.setNodeMarkup(m.start,v)}(S||S===0)&&e.lift(m,S)})}),!0},Xae=n=>e=>n(e),Zae=()=>({state:n,dispatch:e})=>v8(n,e),Jae=(n,e)=>({editor:t,tr:r})=>{const{state:s}=t,o=s.doc.slice(n.from,n.to);r.deleteRange(n.from,n.to);const i=r.mapping.map(e);return r.insert(i,o.content),r.setSelection(new ot(r.doc.resolve(i-1))),!0},Qae=()=>({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 o=s.depth;o>0;o-=1)if(s.node(o).type===r.type){if(e){const a=s.before(o),l=s.after(o);n.delete(a,l).scrollIntoView()}return!0}return!1},ele=n=>({tr:e,state:t,dispatch:r})=>{const s=Jn(n,t.schema),o=e.selection.$anchor;for(let i=o.depth;i>0;i-=1)if(o.node(i).type===s){if(r){const l=o.before(i),c=o.after(i);e.delete(l,c).scrollIntoView()}return!0}return!1},tle=n=>({tr:e,dispatch:t})=>{const{from:r,to:s}=n;return t&&e.delete(r,s),!0},nle=()=>({state:n,dispatch:e})=>LT(n,e),rle=()=>({commands:n})=>n.keyboardShortcut("Enter"),sle=()=>({state:n,dispatch:e})=>yae(n,e);function ax(n,e,t={strict:!0}){const r=Object.keys(e);return r.length?r.every(s=>t.strict?e[s]===n[s]:$T(e[s])?e[s].test(n[s]):e[s]===n[s]):!0}function T8(n,e,t={}){return n.find(r=>r.type===e&&ax(Object.fromEntries(Object.keys(t).map(s=>[s,r.attrs[s]])),t))}function WL(n,e,t={}){return!!T8(n,e,t)}function Y0(n,e,t){var r;if(!n||!e)return;let s=n.parent.childAfter(n.parentOffset);if((!s.node||!s.node.marks.some(u=>u.type===e))&&(s=n.parent.childBefore(n.parentOffset)),!s.node||!s.node.marks.some(u=>u.type===e)||(t=t||((r=s.node.marks[0])===null||r===void 0?void 0:r.attrs),!T8([...s.node.marks],e,t)))return;let i=s.index,a=n.start()+s.offset,l=i+1,c=a+s.node.nodeSize;for(;i>0&&WL([...n.parent.child(i-1).marks],e,t);)i-=1,a-=n.parent.child(i).nodeSize;for(;l<n.parent.childCount&&WL([...n.parent.child(l).marks],e,t);)c+=n.parent.child(l).nodeSize,l+=1;return{from:a,to:c}}function mc(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 ole=(n,e={})=>({tr:t,state:r,dispatch:s})=>{const o=mc(n,r.schema),{doc:i,selection:a}=t,{$from:l,from:c,to:u}=a;if(s){const h=Y0(l,o,e);if(h&&h.from<=c&&h.to>=u){const p=ot.create(i,h.from,h.to);t.setSelection(p)}}return!0},ile=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 _8(n){return n instanceof ot}function Qc(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function M8(n,e=null){if(!e)return null;const t=ut.atStart(n),r=ut.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return r;const s=t.from,o=r.to;return e==="all"?ot.create(n,Qc(0,s,o),Qc(n.content.size,s,o)):ot.create(n,Qc(e,s,o),Qc(e,s,o))}function ale(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function HT(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const lle=(n=null,e={})=>({editor:t,view:r,tr:s,dispatch:o})=>{e={scrollIntoView:!0,...e};const i=()=>{(HT()||ale())&&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(o&&n===null&&!_8(t.state.selection))return i(),!0;const a=M8(s.doc,n)||t.state.selection,l=t.state.selection.eq(a);return o&&(l||s.setSelection(a),l&&s.storedMarks&&s.setStoredMarks(s.storedMarks),i()),!0},cle=(n,e)=>t=>n.every((r,s)=>e(r,{...t,index:s})),ule=(n,e)=>({tr:t,commands:r})=>r.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),A8=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&&A8(r)}return n};function Xf(n){const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return A8(t)}function lx(n,e,t){if(n instanceof pi||n instanceof me)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 me.fromArray(n.map(a=>e.nodeFromJSON(a)));const i=e.nodeFromJSON(n);return t.errorOnInvalidContent&&i.check(),i}catch(o){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:o});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",o),lx("",e,t)}if(s){if(t.errorOnInvalidContent){let i=!1,a="";const l=new f6({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=>(i=!0,a=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?Zd.fromSchema(l).parseSlice(Xf(n),t.parseOptions):Zd.fromSchema(l).parse(Xf(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${a}`)})}const o=Zd.fromSchema(e);return t.slice?o.parseSlice(Xf(n),t.parseOptions).content:o.parse(Xf(n),t.parseOptions)}return lx("",e,t)}function dle(n,e,t){const r=n.steps.length-1;if(r<e)return;const s=n.steps[r];if(!(s instanceof Vn||s instanceof Xn))return;const o=n.mapping.maps[r];let i=0;o.forEach((a,l,c,u)=>{i===0&&(i=u)}),n.setSelection(ut.near(n.doc.resolve(i),t))}const hle=n=>!("type"in n),fle=(n,e,t)=>({tr:r,dispatch:s,editor:o})=>{var i;if(s){t={parseOptions:o.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let a;try{a=lx(e,o.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions},errorOnInvalidContent:(i=t.errorOnInvalidContent)!==null&&i!==void 0?i:o.options.enableContentCheck})}catch(S){return o.emit("contentError",{editor:o,error:S,disableCollaboration:()=>{o.storage.collaboration&&(o.storage.collaboration.isDisabled=!0)}}),!1}let{from:l,to:c}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},u=!0,h=!0;if((hle(a)?a:[a]).forEach(S=>{S.check(),u=u?S.isText&&S.marks.length===0:!1,h=h?S.isBlock:!1}),l===c&&h){const{parent:S}=r.doc.resolve(l);S.isTextblock&&!S.type.spec.code&&!S.childCount&&(l-=1,c+=1)}let m;if(u){if(Array.isArray(e))m=e.map(S=>S.text||"").join("");else if(e instanceof me){let S="";e.forEach(v=>{v.text&&(S+=v.text)}),m=S}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&&dle(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},ple=()=>({state:n,dispatch:e})=>pae(n,e),gle=()=>({state:n,dispatch:e})=>gae(n,e),mle=()=>({state:n,dispatch:e})=>f8(n,e),yle=()=>({state:n,dispatch:e})=>y8(n,e),Sle=()=>({state:n,dispatch:e,tr:t})=>{try{const r=N0(n.doc,n.selection.$from.pos,-1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},xle=()=>({state:n,dispatch:e,tr:t})=>{try{const r=N0(n.doc,n.selection.$from.pos,1);return r==null?!1:(t.join(r,2),e&&e(t),!0)}catch{return!1}},vle=()=>({state:n,dispatch:e})=>hae(n,e),wle=()=>({state:n,dispatch:e})=>fae(n,e);function O8(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function ble(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let r,s,o,i;for(let a=0;a<e.length-1;a+=1){const l=e[a];if(/^(cmd|meta|m)$/i.test(l))i=!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))o=!0;else if(/^mod$/i.test(l))HT()||O8()?i=!0:s=!0;else throw new Error(`Unrecognized modifier name: ${l}`)}return r&&(t=`Alt-${t}`),s&&(t=`Ctrl-${t}`),i&&(t=`Meta-${t}`),o&&(t=`Shift-${t}`),t}const Cle=n=>({editor:e,view:t,tr:r,dispatch:s})=>{const o=ble(n).split(/-(?!$)/),i=o.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),a=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),l=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,a))});return l==null||l.steps.forEach(c=>{const u=c.map(r.mapping);u&&s&&r.maybeStep(u)}),!0};function Gp(n,e,t={}){const{from:r,to:s,empty:o}=n.selection,i=e?Jn(e,n.schema):null,a=[];n.doc.nodesBetween(r,s,(h,p)=>{if(h.isText)return;const m=Math.max(r,p),S=Math.min(s,p+h.nodeSize);a.push({node:h,from:m,to:S})});const l=s-r,c=a.filter(h=>i?i.name===h.node.type.name:!0).filter(h=>ax(h.node.attrs,t,{strict:!1}));return o?!!c.length:c.reduce((h,p)=>h+p.to-p.from,0)>=l}const Ple=(n,e={})=>({state:t,dispatch:r})=>{const s=Jn(n,t.schema);return Gp(t,s,e)?mae(t,r):!1},kle=()=>({state:n,dispatch:e})=>w8(n,e),Ele=n=>({state:e,dispatch:t})=>{const r=Jn(n,e.schema);return Tae(r)(e,t)},Ile=()=>({state:n,dispatch:e})=>x8(n,e);function X0(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function VL(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 Tle=(n,e)=>({tr:t,state:r,dispatch:s})=>{let o=null,i=null;const a=X0(typeof n=="string"?n:n.name,r.schema);return a?(a==="node"&&(o=Jn(n,r.schema)),a==="mark"&&(i=mc(n,r.schema)),s&&t.selection.ranges.forEach(l=>{r.doc.nodesBetween(l.$from.pos,l.$to.pos,(c,u)=>{o&&o===c.type&&t.setNodeMarkup(u,void 0,VL(c.attrs,e)),i&&c.marks.length&&c.marks.forEach(h=>{i===h.type&&t.addMark(u,u+c.nodeSize,i.create(VL(h.attrs,e)))})})}),!0):!1},_le=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Mle=()=>({tr:n,dispatch:e})=>{if(e){const t=new oo(n.doc);n.setSelection(t)}return!0},Ale=()=>({state:n,dispatch:e})=>g8(n,e),Ole=()=>({state:n,dispatch:e})=>S8(n,e),Rle=()=>({state:n,dispatch:e})=>vae(n,e),Dle=()=>({state:n,dispatch:e})=>Cae(n,e),jle=()=>({state:n,dispatch:e})=>bae(n,e);function dE(n,e,t={},r={}){return lx(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:r.errorOnInvalidContent})}const Lle=(n,e=!1,t={},r={})=>({editor:s,tr:o,dispatch:i,commands:a})=>{var l,c;const{doc:u}=o;if(t.preserveWhitespace!=="full"){const h=dE(n,s.schema,t,{errorOnInvalidContent:(l=r.errorOnInvalidContent)!==null&&l!==void 0?l:s.options.enableContentCheck});return i&&o.replaceWith(0,u.content.size,h).setMeta("preventUpdate",!e),!0}return i&&o.setMeta("preventUpdate",!e),a.insertContentAt({from:0,to:u.content.size},n,{parseOptions:t,errorOnInvalidContent:(c=r.errorOnInvalidContent)!==null&&c!==void 0?c:s.options.enableContentCheck})};function R8(n,e){const t=mc(e,n.schema),{from:r,to:s,empty:o}=n.selection,i=[];o?(n.storedMarks&&i.push(...n.storedMarks),i.push(...n.selection.$head.marks())):n.doc.nodesBetween(r,s,l=>{i.push(...l.marks)});const a=i.find(l=>l.type.name===t.name);return a?{...a.attrs}:{}}function Nle(n,e){const t=new _6(n);return e.forEach(r=>{r.steps.forEach(s=>{t.step(s)})}),t}function Fle(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 zle(n,e,t){const r=[];return n.nodesBetween(e.from,e.to,(s,o)=>{t(s)&&r.push({node:s,pos:o})}),r}function Ble(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 KT(n){return e=>Ble(e.$from,n)}function Z0(n,e){const t=Jc.resolve(n);return E8(t,e)}function $le(n,e){const t=Z0(e),r=pi.fromJSON(t,n);return V0(r.content,t)}function Ule(n,e){const t=Z0(e),r=Xf(n);return Zd.fromSchema(t).parse(r).toJSON()}function D8(n,e){const t={from:0,to:n.content.size};return I8(n,t,e)}function Hle(n,e,t){const{blockSeparator:r=`
229
+
230
+ `,textSerializers:s={}}=t||{},o=Z0(e),i=pi.fromJSON(o,n);return D8(i,{blockSeparator:r,textSerializers:{...UT(o),...s}})}function Kle(n,e){const t=Jn(e,n.schema),{from:r,to:s}=n.selection,o=[];n.doc.nodesBetween(r,s,a=>{o.push(a)});const i=o.reverse().find(a=>a.type.name===t.name);return i?{...i.attrs}:{}}function j8(n,e){const t=X0(typeof e=="string"?e:e.name,n.schema);return t==="node"?Kle(n,e):t==="mark"?R8(n,e):{}}function Wle(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 Vle(n){const e=Wle(n);return e.length===1?e:e.filter((t,r)=>!e.filter((o,i)=>i!==r).some(o=>t.oldRange.from>=o.oldRange.from&&t.oldRange.to<=o.oldRange.to&&t.newRange.from>=o.newRange.from&&t.newRange.to<=o.newRange.to))}function Gle(n){const{mapping:e,steps:t}=n,r=[];return e.maps.forEach((s,o)=>{const i=[];if(s.ranges.length)s.forEach((a,l)=>{i.push({from:a,to:l})});else{const{from:a,to:l}=t[o];if(a===void 0||l===void 0)return;i.push({from:a,to:l})}i.forEach(({from:a,to:l})=>{const c=e.slice(o).map(a,-1),u=e.slice(o).map(l),h=e.invert().map(c,-1),p=e.invert().map(u);r.push({oldRange:{from:h,to:p},newRange:{from:c,to:u}})})}),Vle(r)}function WT(n,e,t){const r=[];return n===e?t.resolve(n).marks().forEach(s=>{const o=t.resolve(n),i=Y0(o,s.type);i&&r.push({mark:s,...i})}):t.nodesBetween(n,e,(s,o)=>{!s||(s==null?void 0:s.nodeSize)===void 0||r.push(...s.marks.map(i=>({from:o,to:o+s.nodeSize,mark:i})))}),r}function tS(n,e,t){return Object.fromEntries(Object.entries(t).filter(([r])=>{const s=n.find(o=>o.type===e&&o.name===r);return s?s.attribute.keepOnSplit:!1}))}function hE(n,e,t={}){const{empty:r,ranges:s}=n.selection,o=e?mc(e,n.schema):null;if(r)return!!(n.storedMarks||n.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>ax(h.attrs,t,{strict:!1}));let i=0;const a=[];if(s.forEach(({$from:h,$to:p})=>{const m=h.pos,S=p.pos;n.doc.nodesBetween(m,S,(v,y)=>{if(!v.isText&&!v.marks.length)return;const w=Math.max(m,y),C=Math.min(S,y+v.nodeSize),T=C-w;i+=T,a.push(...v.marks.map(E=>({mark:E,from:w,to:C})))})}),i===0)return!1;const l=a.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>ax(h.mark.attrs,t,{strict:!1})).reduce((h,p)=>h+p.to-p.from,0),c=a.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,p)=>h+p.to-p.from,0);return(l>0?l+c:l)>=i}function qle(n,e,t={}){if(!e)return Gp(n,null,t)||hE(n,null,t);const r=X0(e,n.schema);return r==="node"?Gp(n,e,t):r==="mark"?hE(n,e,t):!1}function GL(n,e){const{nodeExtensions:t}=W0(e),r=t.find(i=>i.name===n);if(!r)return!1;const s={name:r.name,options:r.options,storage:r.storage},o=gt(Fe(r,"group",s));return typeof o!="string"?!1:o.split(" ").includes("list")}function VT(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(o=>{s!==!1&&(VT(o,{ignoreWhitespace:t,checkChildren:e})||(s=!1))}),s}return!1}function Yle(n){return n instanceof Ge}function Xle(n,e,t){var r;const{selection:s}=e;let o=null;if(_8(s)&&(o=s.$cursor),o){const a=(r=n.storedMarks)!==null&&r!==void 0?r:o.marks();return!!t.isInSet(a)||!a.some(l=>l.type.excludes(t))}const{ranges:i}=s;return i.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,(u,h,p)=>{if(c)return!1;if(u.isInline){const m=!p||p.type.allowsMarkType(t),S=!!t.isInSet(u.marks)||!u.marks.some(v=>v.type.excludes(t));c=m&&S}return!c}),c})}const Zle=(n,e={})=>({tr:t,state:r,dispatch:s})=>{const{selection:o}=t,{empty:i,ranges:a}=o,l=mc(n,r.schema);if(s)if(i){const c=R8(r,l);t.addStoredMark(l.create({...c,...e}))}else a.forEach(c=>{const u=c.$from.pos,h=c.$to.pos;r.doc.nodesBetween(u,h,(p,m)=>{const S=Math.max(m,u),v=Math.min(m+p.nodeSize,h);p.marks.find(w=>w.type===l)?p.marks.forEach(w=>{l===w.type&&t.addMark(S,v,l.create({...w.attrs,...e}))}):t.addMark(S,v,l.create(e))})});return Xle(r,t,l)},Jle=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),Qle=(n,e={})=>({state:t,dispatch:r,chain:s})=>{const o=Jn(n,t.schema);let i;return t.selection.$anchor.sameParent(t.selection.$head)&&(i=t.selection.$anchor.parent.attrs),o.isTextblock?s().command(({commands:a})=>$L(o,{...i,...e})(t)?!0:a.clearNodes()).command(({state:a})=>$L(o,{...i,...e})(a,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},ece=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,s=Qc(n,0,r.content.size),o=Ge.create(r,s);e.setSelection(o)}return!0},tce=n=>({tr:e,dispatch:t})=>{if(t){const{doc:r}=e,{from:s,to:o}=typeof n=="number"?{from:n,to:n}:n,i=ot.atStart(r).from,a=ot.atEnd(r).to,l=Qc(s,i,a),c=Qc(o,i,a),u=ot.create(r,l,c);e.setSelection(u)}return!0},nce=n=>({state:e,dispatch:t})=>{const r=Jn(n,e.schema);return Aae(r)(e,t)};function qL(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 rce=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:r,editor:s})=>{const{selection:o,doc:i}=e,{$from:a,$to:l}=o,c=s.extensionManager.attributes,u=tS(c,a.node().type.name,a.node().attrs);if(o instanceof Ge&&o.node.isBlock)return!a.parentOffset||!Fa(i,a.pos)?!1:(r&&(n&&qL(t,s.extensionManager.splittableMarks),e.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;const h=l.parentOffset===l.parent.content.size,p=a.depth===0?void 0:Fle(a.node(-1).contentMatchAt(a.indexAfter(-1)));let m=h&&p?[{type:p,attrs:u}]:void 0,S=Fa(e.doc,e.mapping.map(a.pos),1,m);if(!m&&!S&&Fa(e.doc,e.mapping.map(a.pos),1,p?[{type:p}]:void 0)&&(S=!0,m=p?[{type:p,attrs:u}]:void 0),r){if(S&&(o instanceof ot&&e.deleteSelection(),e.split(e.mapping.map(a.pos),1,m),p&&!h&&!a.parentOffset&&a.parent.type!==p)){const v=e.mapping.map(a.before()),y=e.doc.resolve(v);a.node(-1).canReplaceWith(y.index(),y.index()+1,p)&&e.setNodeMarkup(e.mapping.map(a.before()),p)}n&&qL(t,s.extensionManager.splittableMarks),e.scrollIntoView()}return S},sce=(n,e={})=>({tr:t,state:r,dispatch:s,editor:o})=>{var i;const a=Jn(n,r.schema),{$from:l,$to:c}=r.selection,u=r.selection.node;if(u&&u.isBlock||l.depth<2||!l.sameParent(c))return!1;const h=l.node(-1);if(h.type!==a)return!1;const p=o.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 w=me.empty;const C=l.index(-1)?1:l.index(-2)?2:3;for(let D=l.depth-C;D>=l.depth-3;D-=1)w=me.from(l.node(D).copy(w));const T=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,E={...tS(p,l.node().type.name,l.node().attrs),...e},_=((i=a.contentMatch.defaultType)===null||i===void 0?void 0:i.createAndFill(E))||void 0;w=w.append(me.from(a.createAndFill(null,_)||void 0));const A=l.before(l.depth-(C-1));t.replace(A,l.after(-T),new _e(w,4-C,0));let O=-1;t.doc.nodesBetween(A,t.doc.content.size,(D,F)=>{if(O>-1)return!1;D.isTextblock&&D.content.size===0&&(O=F+1)}),O>-1&&t.setSelection(ot.near(t.doc.resolve(O))),t.scrollIntoView()}return!0}const m=c.pos===l.end()?h.contentMatchAt(0).defaultType:null,S={...tS(p,h.type.name,h.attrs),...e},v={...tS(p,l.node().type.name,l.node().attrs),...e};t.delete(l.pos,c.pos);const y=m?[{type:a,attrs:S},{type:m,attrs:v}]:[{type:a,attrs:S}];if(!Fa(t.doc,l.pos,2))return!1;if(s){const{selection:w,storedMarks:C}=r,{splittableMarks:T}=o.extensionManager,E=C||w.$to.parentOffset&&w.$from.marks();if(t.split(l.pos,2,y).scrollIntoView(),!E||!s)return!0;const _=E.filter(A=>T.includes(A.type.name));t.ensureMarks(_)}return!0},pP=(n,e)=>{const t=KT(i=>i.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)&&pc(n.doc,t.pos)&&n.join(t.pos),!0},gP=(n,e)=>{const t=KT(i=>i.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)&&pc(n.doc,r)&&n.join(r),!0},oce=(n,e,t,r={})=>({editor:s,tr:o,state:i,dispatch:a,chain:l,commands:c,can:u})=>{const{extensions:h,splittableMarks:p}=s.extensionManager,m=Jn(n,i.schema),S=Jn(e,i.schema),{selection:v,storedMarks:y}=i,{$from:w,$to:C}=v,T=w.blockRange(C),E=y||v.$to.parentOffset&&v.$from.marks();if(!T)return!1;const _=KT(A=>GL(A.type.name,h))(v);if(T.depth>=1&&_&&T.depth-_.depth<=1){if(_.node.type===m)return c.liftListItem(S);if(GL(_.node.type.name,h)&&m.validContent(_.node.content)&&a)return l().command(()=>(o.setNodeMarkup(_.pos,m),!0)).command(()=>pP(o,m)).command(()=>gP(o,m)).run()}return!t||!E||!a?l().command(()=>u().wrapInList(m,r)?!0:c.clearNodes()).wrapInList(m,r).command(()=>pP(o,m)).command(()=>gP(o,m)).run():l().command(()=>{const A=u().wrapInList(m,r),O=E.filter(D=>p.includes(D.type.name));return o.ensureMarks(O),A?!0:c.clearNodes()}).wrapInList(m,r).command(()=>pP(o,m)).command(()=>gP(o,m)).run()},ice=(n,e={},t={})=>({state:r,commands:s})=>{const{extendEmptyMarkRange:o=!1}=t,i=mc(n,r.schema);return hE(r,i,e)?s.unsetMark(i,{extendEmptyMarkRange:o}):s.setMark(i,e)},ace=(n,e,t={})=>({state:r,commands:s})=>{const o=Jn(n,r.schema),i=Jn(e,r.schema),a=Gp(r,o,t);let l;return r.selection.$anchor.sameParent(r.selection.$head)&&(l=r.selection.$anchor.parent.attrs),a?s.setNode(i,l):s.setNode(o,{...l,...t})},lce=(n,e={})=>({state:t,commands:r})=>{const s=Jn(n,t.schema);return Gp(t,s,e)?r.lift(s):r.wrapIn(s,e)},cce=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let r=0;r<t.length;r+=1){const s=t[r];let o;if(s.spec.isInputRules&&(o=s.getState(n))){if(e){const i=n.tr,a=o.transform;for(let l=a.steps.length-1;l>=0;l-=1)i.step(a.steps[l].invert(a.docs[l]));if(o.text){const l=i.doc.resolve(o.from).marks();i.replaceWith(o.from,o.to,n.schema.text(o.text,l))}else i.delete(o.from,o.to)}return!0}}return!1},uce=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:r,ranges:s}=t;return r||e&&s.forEach(o=>{n.removeMark(o.$from.pos,o.$to.pos)}),!0},dce=(n,e={})=>({tr:t,state:r,dispatch:s})=>{var o;const{extendEmptyMarkRange:i=!1}=e,{selection:a}=t,l=mc(n,r.schema),{$from:c,empty:u,ranges:h}=a;if(!s)return!0;if(u&&i){let{from:p,to:m}=a;const S=(o=c.marks().find(y=>y.type===l))===null||o===void 0?void 0:o.attrs,v=Y0(c,l,S);v&&(p=v.from,m=v.to),t.removeMark(p,m,l)}else h.forEach(p=>{t.removeMark(p.$from.pos,p.$to.pos,l)});return t.removeStoredMark(l),!0},hce=(n,e={})=>({tr:t,state:r,dispatch:s})=>{let o=null,i=null;const a=X0(typeof n=="string"?n:n.name,r.schema);return a?(a==="node"&&(o=Jn(n,r.schema)),a==="mark"&&(i=mc(n,r.schema)),s&&t.selection.ranges.forEach(l=>{const c=l.$from.pos,u=l.$to.pos;let h,p,m,S;t.selection.empty?r.doc.nodesBetween(c,u,(v,y)=>{o&&o===v.type&&(m=Math.max(y,c),S=Math.min(y+v.nodeSize,u),h=y,p=v)}):r.doc.nodesBetween(c,u,(v,y)=>{y<c&&o&&o===v.type&&(m=Math.max(y,c),S=Math.min(y+v.nodeSize,u),h=y,p=v),y>=c&&y<=u&&(o&&o===v.type&&t.setNodeMarkup(y,void 0,{...v.attrs,...e}),i&&v.marks.length&&v.marks.forEach(w=>{if(i===w.type){const C=Math.max(y,c),T=Math.min(y+v.nodeSize,u);t.addMark(C,T,i.create({...w.attrs,...e}))}}))}),p&&(h!==void 0&&t.setNodeMarkup(h,void 0,{...p.attrs,...e}),i&&p.marks.length&&p.marks.forEach(v=>{i===v.type&&t.addMark(m,S,i.create({...v.attrs,...e}))}))}),!0):!1},fce=(n,e={})=>({state:t,dispatch:r})=>{const s=Jn(n,t.schema);return Pae(s,e)(t,r)},pce=(n,e={})=>({state:t,dispatch:r})=>{const s=Jn(n,t.schema);return kae(s,e)(t,r)};var gce=Object.freeze({__proto__:null,blur:Gae,clearContent:qae,clearNodes:Yae,command:Xae,createParagraphNear:Zae,cut:Jae,deleteCurrentNode:Qae,deleteNode:ele,deleteRange:tle,deleteSelection:nle,enter:rle,exitCode:sle,extendMarkRange:ole,first:ile,focus:lle,forEach:cle,insertContent:ule,insertContentAt:fle,joinBackward:mle,joinDown:gle,joinForward:yle,joinItemBackward:Sle,joinItemForward:xle,joinTextblockBackward:vle,joinTextblockForward:wle,joinUp:ple,keyboardShortcut:Cle,lift:Ple,liftEmptyBlock:kle,liftListItem:Ele,newlineInCode:Ile,resetAttributes:Tle,scrollIntoView:_le,selectAll:Mle,selectNodeBackward:Ale,selectNodeForward:Ole,selectParentNode:Rle,selectTextblockEnd:Dle,selectTextblockStart:jle,setContent:Lle,setMark:Zle,setMeta:Jle,setNode:Qle,setNodeSelection:ece,setTextSelection:tce,sinkListItem:nce,splitBlock:rce,splitListItem:sce,toggleList:oce,toggleMark:ice,toggleNode:ace,toggleWrap:lce,undoInputRule:cce,unsetAllMarks:uce,unsetMark:dce,updateAttributes:hce,wrapIn:fce,wrapInList:pce});const mce=yr.create({name:"commands",addCommands(){return{...gce}}}),yce=yr.create({name:"drop",addProseMirrorPlugins(){return[new xr({key:new uo("tiptapDrop"),props:{handleDrop:(n,e,t,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:r})}}})]}}),Sce=yr.create({name:"editable",addProseMirrorPlugins(){return[new xr({key:new uo("editable"),props:{editable:()=>this.editor.options.editable}})]}}),xce=new uo("focusEvents"),vce=yr.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new xr({key:xce,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}}}})]}}),wce=yr.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:a})=>{const{selection:l,doc:c}=a,{empty:u,$anchor:h}=l,{pos:p,parent:m}=h,S=h.parent.isTextblock&&p>0?a.doc.resolve(p-1):h,v=S.parent.type.spec.isolating,y=h.pos-h.parentOffset,w=v&&S.parent.childCount===1?y===h.pos:ut.atStart(c).from===p;return!u||!m.type.isTextblock||m.textContent.length||!w||w&&h.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.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},o={...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 HT()||O8()?o:s},addProseMirrorPlugins(){return[new xr({key:new uo("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:o,from:i,to:a}=e.selection,l=ut.atStart(e.doc).from,c=ut.atEnd(e.doc).to;if(o||!(i===l&&a===c)||!VT(t.doc))return;const p=t.tr,m=H0({state:t,transaction:p}),{commands:S}=new K0({editor:this.editor,state:m});if(S.clearNodes(),!!p.steps.length)return p}})]}}),bce=yr.create({name:"paste",addProseMirrorPlugins(){return[new xr({key:new uo("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),Cce=yr.create({name:"tabindex",addProseMirrorPlugins(){return[new xr({key:new uo("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class Yc{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 Yc(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 Yc(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 Yc(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,r)=>{const s=t.isBlock&&!t.isTextblock,o=t.isAtom&&!t.isText,i=this.pos+r+(o?0:1),a=this.resolvedPos.doc.resolve(i);if(!s&&a.depth<=this.depth)return;const l=new Yc(a,this.editor,s,s?t:null);s&&(l.actualDepth=this.depth+1),e.push(new Yc(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 o=s.node.attrs,i=Object.keys(t);for(let a=0;a<i.length;a+=1){const l=i[a];if(o[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 o=Object.keys(t);return this.children.forEach(i=>{r&&s.length>0||(i.node.type.name===e&&o.every(l=>t[l]===i.node.attrs[l])&&s.push(i),!(r&&s.length>0)&&(s=s.concat(i.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 Pce=`.ProseMirror {
231
+ position: relative;
232
+ }
233
+
234
+ .ProseMirror {
235
+ word-wrap: break-word;
236
+ white-space: pre-wrap;
237
+ white-space: break-spaces;
238
+ -webkit-font-variant-ligatures: none;
239
+ font-variant-ligatures: none;
240
+ font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
241
+ }
242
+
243
+ .ProseMirror [contenteditable="false"] {
244
+ white-space: normal;
245
+ }
246
+
247
+ .ProseMirror [contenteditable="false"] [contenteditable="true"] {
248
+ white-space: pre-wrap;
249
+ }
250
+
251
+ .ProseMirror pre {
252
+ white-space: pre-wrap;
253
+ }
254
+
255
+ img.ProseMirror-separator {
256
+ display: inline !important;
257
+ border: none !important;
258
+ margin: 0 !important;
259
+ width: 0 !important;
260
+ height: 0 !important;
261
+ }
262
+
263
+ .ProseMirror-gapcursor {
264
+ display: none;
265
+ pointer-events: none;
266
+ position: absolute;
267
+ margin: 0;
268
+ }
269
+
270
+ .ProseMirror-gapcursor:after {
271
+ content: "";
272
+ display: block;
273
+ position: absolute;
274
+ top: -2px;
275
+ width: 20px;
276
+ border-top: 1px solid black;
277
+ animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
278
+ }
279
+
280
+ @keyframes ProseMirror-cursor-blink {
281
+ to {
282
+ visibility: hidden;
283
+ }
284
+ }
285
+
286
+ .ProseMirror-hideselection *::selection {
287
+ background: transparent;
288
+ }
289
+
290
+ .ProseMirror-hideselection *::-moz-selection {
291
+ background: transparent;
292
+ }
293
+
294
+ .ProseMirror-hideselection * {
295
+ caret-color: transparent;
296
+ }
297
+
298
+ .ProseMirror-focused .ProseMirror-gapcursor {
299
+ display: block;
300
+ }
301
+
302
+ .tippy-box[data-animation=fade][data-state=hidden] {
303
+ opacity: 0
304
+ }`;function kce(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}class Ece extends Oae{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=kce(Pce,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=k8(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(o=>{const i=typeof o=="string"?`${o}$`:o.key;r=r.filter(a=>!a.key.startsWith(i))}),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?[Sce,Vae.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||t===void 0?void 0:t.blockSeparator}),mce,vce,wce,Cce,yce,bce].filter(o=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[o.name]!==!1:!0):[],...this.options.extensions].filter(o=>["extension","node","mark"].includes(o==null?void 0:o.type));this.extensionManager=new Jc(s,this)}createCommandManager(){this.commandManager=new K0({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=dE(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(i){if(!(i instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(i.message))throw i;this.emit("contentError",{editor:this,error:i,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(a=>a.name!=="collaboration"),this.createExtensionManager()}}),t=dE(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const r=M8(t,this.options.autofocus);this.view=new tae(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:Hd.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 o=this.view.dom;o.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(i=>{var a;return(a=this.capturedTransaction)===null||a===void 0?void 0:a.step(i)});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"),o=e.getMeta("blur");s&&this.emit("focus",{editor:this,event:s.event,transaction:e}),o&&this.emit("blur",{editor:this,event:o.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return j8(this.state,e)}isActive(e,t){const r=typeof e=="string"?e:null,s=typeof e=="string"?t:e;return qle(this.state,r,s)}getJSON(){return this.state.doc.toJSON()}getHTML(){return V0(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
305
+
306
+ `,textSerializers:r={}}=e||{};return D8(this.state.doc,{blockSeparator:t,textSerializers:{...UT(this.schema),...r}})}get isEmpty(){return VT(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 Yc(t,this)}get $doc(){return this.$pos(0)}}function vu(n){return new G0({find:n.find,handler:({state:e,range:t,match:r})=>{const s=gt(n.getAttributes,void 0,r);if(s===!1||s===null)return null;const{tr:o}=e,i=r[r.length-1],a=r[0];if(i){const l=a.search(/\S/),c=t.from+a.indexOf(i),u=c+i.length;if(WT(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;u<t.to&&o.delete(u,t.to),c>t.from&&o.delete(t.from+l,c);const p=t.from+l+i.length;o.addMark(t.from+l,p,n.type.create(s||{})),o.removeStoredMark(n.type)}}})}function Ice(n){return new G0({find:n.find,handler:({state:e,range:t,match:r})=>{const s=gt(n.getAttributes,void 0,r)||{},{tr:o}=e,i=t.from;let a=t.to;const l=n.type.create(s);if(r[1]){const c=r[0].lastIndexOf(r[1]);let u=i+c;u>a?u=a:a=u+r[1].length;const h=r[0][r[0].length-1];o.insertText(h,i+r[0].length-1),o.replaceWith(u,a,l)}else if(r[0]){const c=n.type.isInline?i:i-1;o.insert(c,n.type.create(s)).delete(o.mapping.map(i),o.mapping.map(a))}o.scrollIntoView()}})}function fE(n){return new G0({find:n.find,handler:({state:e,range:t,match:r})=>{const s=e.doc.resolve(t.from),o=gt(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,o)}})}function qp(n){return new G0({find:n.find,handler:({state:e,range:t,match:r,chain:s})=>{const o=gt(n.getAttributes,void 0,r)||{},i=e.tr.delete(t.from,t.to),l=i.doc.resolve(t.from).blockRange(),c=l&&kT(l,n.type,o);if(!c)return null;if(i.wrap(l,c),n.keepMarks&&n.editor){const{selection:h,storedMarks:p}=e,{splittableMarks:m}=n.editor.extensionManager,S=p||h.$to.parentOffset&&h.$from.marks();if(S){const v=S.filter(y=>m.includes(y.type.name));i.ensureMarks(v)}}if(n.keepAttributes){const h=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";s().updateAttributes(h,o).run()}const u=i.doc.resolve(t.from-1).nodeBefore;u&&u.type===n.type&&pc(i.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,u))&&i.join(t.from-1)}})}let xi=class pE{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=gt(Fe(this,"addOptions",{name:this.name}))),this.storage=gt(Fe(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new pE(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>q0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new pE(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=gt(Fe(t,"addOptions",{name:t.name})),t.storage=gt(Fe(t,"addStorage",{name:t.name,options:t.options})),t}};function oc(n){return new Bae({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:s})=>{const o=gt(n.getAttributes,void 0,r,s);if(o===!1||o===null)return null;const{tr:i}=e,a=r[r.length-1],l=r[0];let c=t.to;if(a){const u=l.search(/\S/),h=t.from+l.indexOf(a),p=h+a.length;if(WT(t.from,t.to,e.doc).filter(S=>S.mark.type.excluded.find(y=>y===n.type&&y!==S.mark.type)).filter(S=>S.to>h).length)return null;p<t.to&&i.delete(p,t.to),h>t.from&&i.delete(t.from+u,h),c=t.from+u+a.length,i.addMark(t.from+u,c,n.type.create(o||{})),i.removeStoredMark(n.type)}}})}function GT(n,e,t){const{tipTapConfig:r,addFontsFromNode:s}=n.getTextOptions();Ve(r,"textOptions.tipTapConfig must be set to use rich text"),Ve(s,"textOptions.addFontsFromNode must be set to use rich text");const o=Z0(r.extensions??[]),i=pi.fromJSON(o,e),a=new Set;function l(u){a.add(u)}function c(u,h){h=s(u,h,l);for(const p of u.children)c(p,h)}return c(i,t),Array.from(a)}async function Tce({shouldReload:n=!0}={}){Eq();for(const e of YS.connectedInstances)await e.close();await Promise.all(vT().map(e=>U$(e))),kq(),n&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Tce);function _ce(n,e="_blank"){C0.openWindow(n,e)}lc("@tldraw/editor","3.13.1","esm");function L8(){const[n,e]=k.useState(!1);return k.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 gE=k.createContext(null);function Mce({children:n}){const e=gg("a11y",{msg:"",priority:"assertive"}),t=k.useContext(gE),r=k.useMemo(()=>({currentMsg:e,announce(s){s&&e.set(s)}}),[e]);return t?g.jsx(g.Fragment,{children:n}):g.jsx(gE.Provider,{value:r,children:n})}function J0(){const n=k.useContext(gE);if(!n)throw new Error("useA11y must be used within a A11yContext.Provider");return n}const N8=k.createContext(null);function Ace({assetUrls:n,children:e}){return k.useEffect(()=>{for(const t of Object.values(n.icons)){if(!t)continue;const r=Op();r.src=t,r.decode()}for(const t of Object.values(n.embedIcons)){if(!t)continue;const r=Op();r.src=t,r.decode()}},[n]),g.jsx(N8.Provider,{value:n,children:e})}function qT(){const n=k.useContext(N8);if(!n)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return n}const mE={"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.cloud":"Cloud","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.heart":"Heart","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","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","arrow-kind-style.arc":"Arc","arrow-kind-style.elbow":"Elbow","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.media":"Media","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","tool.rich-text-toolbar-title":"Text formatting","tool.rich-text-orderedList":"Ordered list","tool.bookmark":"Bookmark","a11y.status":"Status","a11y.skip-to-main-content":"Move focus to canvas","a11y.shape-index":"{num} of {total}","a11y.shape-image":"Image","a11y.shape-video":"Video","a11y.multiple-shapes":"{num} shapes selected","a11y.select-shape":"Select next shape","a11y.select-shape-direction":"Select shape in direction","a11y.enter-leave-container":"Enter/leave container","a11y.repeat-shape":"Repeat shape","a11y.move-shape":"Move shape","a11y.move-shape-faster":"Move shape faster","a11y.enlarge-shape":"Enlarge shape","a11y.shrink-shape":"Shrink shape","a11y.pan-camera":"Pan camera","a11y.adjust-shape-styles":"Adjust shape styles","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.title":"Context menu","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.avatar-color":"Avatar color","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","edit-link-dialog.external-link":"External link","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","shortcuts-dialog.a11y":"Accessibility","shortcuts-dialog.text-formatting":"Text formatting","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.arrow-kind":"Line","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.title":"Tools","tool-panel.more":"More","navigation-zone.title":"Navigation","navigation-zone.minimap":"Minimap","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","toast.success":"Success","toast.error":"Error","toast.info":"Info","toast.warning":"Warning","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…","app.loading":"Loading tldraw…","handle.resize-top":"Resize top","handle.resize-bottom":"Resize bottom","handle.resize-left":"Resize left","handle.resize-right":"Resize right","handle.resize-top-left":"Resize top left","handle.resize-top-right":"Resize top right","handle.resize-bottom-left":"Resize bottom left","handle.resize-bottom-right":"Resize bottom right","handle.rotate.top_left_rotate":"Rotate top left","handle.rotate.top_right_rotate":"Rotate top right","handle.rotate.bottom_left_rotate":"Rotate bottom left","handle.rotate.bottom_right_rotate":"Rotate bottom right","handle.rotate.mobile_rotate":"Rotate","handle.crop.top":"Crop top","handle.crop.bottom":"Crop bottom","handle.crop.left":"Crop left","handle.crop.right":"Crop right","handle.crop.top-left":"Crop top left","handle.crop.top-right":"Crop top right","handle.crop.bottom-left":"Crop bottom left","handle.crop.bottom-right":"Crop bottom right","ui.close":"Close","ui.checked":"Checked","ui.unchecked":"Unchecked"},Oce=new Set(["ar","fa","he","ur","ku"]),Ed={locale:"en",label:"English",messages:mE,dir:"ltr"};async function Rce(n,e){if(!(await di(e.translations.en)).ok)return console.warn("No main translations found."),Ed;if(n==="en")return Ed;const r=Np.find(i=>i.locale===n);if(!r)return console.warn(`No translation found for locale ${n}`),Ed;const o=await(await di(e.translations[r.locale])).json();if(!o)return console.warn(`No messages found for locale ${n}`),Ed;for(const i in Ed.messages)o[i];return{locale:n,label:r.label,dir:Oce.has(r.locale)?"rtl":"ltr",messages:{...Ed.messages,...o}}}const F8=k.createContext(null);function z8(){const n=k.useContext(F8);if(!n)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return n}function Dce({overrides:n,locale:e,children:t}){const r=qT(),[s,o]=k.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...mE,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:mE});return k.useEffect(()=>{let i=!1;async function a(){const l=await Rce(e,r);l&&!i&&(n&&n[e]?o({...l,messages:{...l.messages,...n[e]}}):o(l))}return a(),()=>{i=!0}},[r,e,n]),g.jsx(F8.Provider,{value:s,children:t})}function Ke(){const n=z8();return k.useCallback(function(t){return n.messages[t]??t},[n])}const ht=k.forwardRef(function({children:e,type:t,isActive:r,...s},o){return g.jsx("button",{ref:o,type:"button",draggable:!1,"data-isactive":r,...s,className:$e("tlui-button",`tlui-button__${t}`,s.className),children:e})});function jce(){const n=ne(),e=Ke(),t=k.useRef(null),r=k.useCallback(s=>{var i;Yt(s),(i=t.current)==null||i.blur();const o=n.getCurrentPageShapesInReadingOrder();o.length&&(n.setSelectedShapes([o[0].id]),n.zoomToSelectionIfOffscreen(256,{animation:{duration:n.options.animationMediumMs},inset:0}),n.timers.setTimeout(()=>n.getContainer().focus(),100))},[n]);return g.jsx(ht,{ref:t,type:"low",tabIndex:0,className:"tl-skip-to-main-content",onClick:r,children:e("a11y.skip-to-main-content")})}const Lce=k.memo(function(){const e=J0(),t=Ke(),r=se("a11y-msg",()=>e.currentMsg.get(),[]);return Fce(r.msg),Nce(),r.msg&&g.jsx("div",{"aria-label":t("a11y.status"),"aria-live":r.priority||"assertive",role:"status","aria-hidden":"false",style:{position:"absolute",top:"-10000px",left:"-10000px"},children:r.msg})});function B8(n){const{editor:e,selectedShapeIds:t,msg:r}=n;let s="";const o=t.length;if(o>1)s=r("a11y.multiple-shapes").replace("{num}",o.toString());else if(o===1){const i=t[0],a=e.getShape(i);if(!a)return"";const l=e.getShapeUtil(a.type),c=["image","video"].includes(a.type);let u="";a.type==="geo"?u=r(`geo-style.${a.props.geo}`):c?u=r(`a11y.shape-${a.type}`):u=r(`tool.${a.type}`);const h=e.getCurrentPageShapesInReadingOrder(),p=(h.findIndex(y=>y.id===i)+1).toString(),m=h.length.toString(),S=r("a11y.shape-index").replace("{num}",p).replace("{total}",m),v=l.getAriaDescriptor(a)||l.getText(a)||"";s=(v?`${v}, `:"")+`${u}. ${S}`}return s}const Nce=()=>{const n=Sr(),e=J0(),t=Ke(),r=k.useRef([]);u0("announce selection",()=>{if(!n)return;const s=n.isIn("select.idle"),o=n.getSelectedShapeIds();s&&o!==r.current&&(r.current=o,Hf(()=>{const i=B8({editor:n,selectedShapeIds:o,msg:t});i&&e.announce({msg:i})}))},[n,e,t])},Fce=n=>{const e=_n();k.useEffect(()=>{if(sn.a11y.get()){const t=s=>{console.debug(`%ca11y%c: ${s}`,"color: white; background: #40C057; padding: 2px;border-radius: 3px;","font-weight: normal")},r=s=>{const o=document.activeElement;if(s.key==="Tab"&&o&&o!==document.body&&!o.classList.contains("tl-container")){const i=o.getAttribute("aria-label")||o.getAttribute("title")||o.textContent;i&&t(i)}};return n&&t(n),document.addEventListener("keyup",r),()=>document.removeEventListener("keyup",r)}},[e,n])},$8=()=>{},U8=k.createContext(null);function zce({onEvent:n,children:e}){return g.jsx(U8.Provider,{value:n??$8,children:e})}function Bn(){return k.useContext(U8)??$8}function YL(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function Q0(...n){return e=>{let t=!1;const r=n.map(s=>{const o=YL(s,e);return!t&&typeof o=="function"&&(t=!0),o});if(t)return()=>{for(let s=0;s<r.length;s++){const o=r[s];typeof o=="function"?o():YL(n[s],null)}}}}function Ht(...n){return k.useCallback(Q0(...n),n)}function ph(n){const e=Bce(n),t=k.forwardRef((r,s)=>{const{children:o,...i}=r,a=k.Children.toArray(o),l=a.find(Uce);if(l){const c=l.props.children,u=a.map(h=>h===l?k.Children.count(c)>1?k.Children.only(null):k.isValidElement(c)?c.props.children:null:h);return g.jsx(e,{...i,ref:s,children:k.isValidElement(c)?k.cloneElement(c,void 0,u):null})}return g.jsx(e,{...i,ref:s,children:o})});return t.displayName=`${n}.Slot`,t}function Bce(n){const e=k.forwardRef((t,r)=>{const{children:s,...o}=t;if(k.isValidElement(s)){const i=Kce(s),a=Hce(o,s.props);return s.type!==k.Fragment&&(a.ref=r?Q0(r,i):i),k.cloneElement(s,a)}return k.Children.count(s)>1?k.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var $ce=Symbol("radix.slottable");function Uce(n){return k.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===$ce}function Hce(n,e){const t={...e};for(const r in e){const s=n[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?t[r]=(...a)=>{const l=o(...a);return s(...a),l}:s&&(t[r]=s):r==="style"?t[r]={...s,...o}:r==="className"&&(t[r]=[s,o].filter(Boolean).join(" "))}return{...n,...t}}function Kce(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 Wce=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ct=Wce.reduce((n,e)=>{const t=ph(`Primitive.${e}`),r=k.forwardRef((s,o)=>{const{asChild:i,...a}=s,l=i?t:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),g.jsx(l,{...a,ref:o})});return r.displayName=`Primitive.${e}`,{...n,[e]:r}},{});function YT(n,e){n&&Mh.flushSync(()=>n.dispatchEvent(e))}var Vce=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Gce="VisuallyHidden",XT=k.forwardRef((n,e)=>g.jsx(ct.span,{...n,ref:e,style:{...Vce,...n.style}}));XT.displayName=Gce;function qce(n,e){const t=k.createContext(e),r=o=>{const{children:i,...a}=o,l=k.useMemo(()=>a,Object.values(a));return g.jsx(t.Provider,{value:l,children:i})};r.displayName=n+"Provider";function s(o){const i=k.useContext(t);if(i)return i;if(e!==void 0)return e;throw new Error(`\`${o}\` must be used within \`${n}\``)}return[r,s]}function Ho(n,e=[]){let t=[];function r(o,i){const a=k.createContext(i),l=t.length;t=[...t,i];const c=h=>{var w;const{scope:p,children:m,...S}=h,v=((w=p==null?void 0:p[n])==null?void 0:w[l])||a,y=k.useMemo(()=>S,Object.values(S));return g.jsx(v.Provider,{value:y,children:m})};c.displayName=o+"Provider";function u(h,p){var v;const m=((v=p==null?void 0:p[n])==null?void 0:v[l])||a,S=k.useContext(m);if(S)return S;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${o}\``)}return[c,u]}const s=()=>{const o=t.map(i=>k.createContext(i));return function(a){const l=(a==null?void 0:a[n])||o;return k.useMemo(()=>({[`__scope${n}`]:{...a,[n]:l}}),[a,l])}};return s.scopeName=n,[r,Yce(s,...e)]}function Yce(...n){const e=n[0];if(n.length===1)return e;const t=()=>{const r=n.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(o)[`__scope${c}`];return{...a,...h}},{});return k.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return t.scopeName=e.scopeName,t}function ev(n){const e=n+"CollectionProvider",[t,r]=Ho(e),[s,o]=t(e,{collectionRef:{current:null},itemMap:new Map}),i=v=>{const{scope:y,children:w}=v,C=We.useRef(null),T=We.useRef(new Map).current;return g.jsx(s,{scope:y,itemMap:T,collectionRef:C,children:w})};i.displayName=e;const a=n+"CollectionSlot",l=ph(a),c=We.forwardRef((v,y)=>{const{scope:w,children:C}=v,T=o(a,w),E=Ht(y,T.collectionRef);return g.jsx(l,{ref:E,children:C})});c.displayName=a;const u=n+"CollectionItemSlot",h="data-radix-collection-item",p=ph(u),m=We.forwardRef((v,y)=>{const{scope:w,children:C,...T}=v,E=We.useRef(null),_=Ht(y,E),A=o(u,w);return We.useEffect(()=>(A.itemMap.set(E,{ref:E,...T}),()=>void A.itemMap.delete(E))),g.jsx(p,{[h]:"",ref:_,children:C})});m.displayName=u;function S(v){const y=o(n+"CollectionConsumer",v);return We.useCallback(()=>{const C=y.collectionRef.current;if(!C)return[];const T=Array.from(C.querySelectorAll(`[${h}]`));return Array.from(y.itemMap.values()).sort((A,O)=>T.indexOf(A.ref.current)-T.indexOf(O.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:m},S,r]}function Re(n,e,{checkForDefaultPrevented:t=!0}={}){return function(s){if(n==null||n(s),t===!1||!s.defaultPrevented)return e==null?void 0:e(s)}}var Va=globalThis!=null&&globalThis.document?k.useLayoutEffect:()=>{},Xce=B3[" useInsertionEffect ".trim().toString()]||Va;function vi({prop:n,defaultProp:e,onChange:t=()=>{},caller:r}){const[s,o,i]=Zce({defaultProp:e,onChange:t}),a=n!==void 0,l=a?n:s;{const u=k.useRef(n!==void 0);k.useEffect(()=>{const h=u.current;h!==a&&console.warn(`${r} is changing from ${h?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),u.current=a},[a,r])}const c=k.useCallback(u=>{var h;if(a){const p=Jce(u)?u(n):u;p!==n&&((h=i.current)==null||h.call(i,p))}else o(u)},[a,n,o,i]);return[l,c]}function Zce({defaultProp:n,onChange:e}){const[t,r]=k.useState(n),s=k.useRef(t),o=k.useRef(e);return Xce(()=>{o.current=e},[e]),k.useEffect(()=>{var i;s.current!==t&&((i=o.current)==null||i.call(o,t),s.current=t)},[t,s]),[t,r,o]}function Jce(n){return typeof n=="function"}function Qce(n,e){return k.useReducer((t,r)=>e[t][r]??t,n)}var wi=n=>{const{present:e,children:t}=n,r=eue(e),s=typeof t=="function"?t({present:r.isPresent}):k.Children.only(t),o=Ht(r.ref,tue(s));return typeof t=="function"||r.isPresent?k.cloneElement(s,{ref:o}):null};wi.displayName="Presence";function eue(n){const[e,t]=k.useState(),r=k.useRef(null),s=k.useRef(n),o=k.useRef("none"),i=n?"mounted":"unmounted",[a,l]=Qce(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return k.useEffect(()=>{const c=fy(r.current);o.current=a==="mounted"?c:"none"},[a]),Va(()=>{const c=r.current,u=s.current;if(u!==n){const p=o.current,m=fy(c);n?l("MOUNT"):m==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&p!==m?"ANIMATION_OUT":"UNMOUNT"),s.current=n}},[n,l]),Va(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=m=>{const v=fy(r.current).includes(m.animationName);if(m.target===e&&v&&(l("ANIMATION_END"),!s.current)){const y=e.style.animationFillMode;e.style.animationFillMode="forwards",c=u.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=y)})}},p=m=>{m.target===e&&(o.current=fy(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{u.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:k.useCallback(c=>{r.current=c?getComputedStyle(c):null,t(c)},[])}}function fy(n){return(n==null?void 0:n.animationName)||"none"}function tue(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 nue=B3[" useId ".trim().toString()]||(()=>{}),rue=0;function Ba(n){const[e,t]=k.useState(nue());return Va(()=>{t(r=>r??String(rue++))},[n]),n||(e?`radix-${e}`:"")}var sue=k.createContext(void 0);function Og(n){const e=k.useContext(sue);return n||e||"ltr"}function is(n){const e=k.useRef(n);return k.useEffect(()=>{e.current=n}),k.useMemo(()=>(...t)=>{var r;return(r=e.current)==null?void 0:r.call(e,...t)},[])}function oue(n,e=globalThis==null?void 0:globalThis.document){const t=is(n);k.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 iue="DismissableLayer",yE="dismissableLayer.update",aue="dismissableLayer.pointerDownOutside",lue="dismissableLayer.focusOutside",XL,H8=k.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Rg=k.forwardRef((n,e)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:i,onDismiss:a,...l}=n,c=k.useContext(H8),[u,h]=k.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,m]=k.useState({}),S=Ht(e,O=>h(O)),v=Array.from(c.layers),[y]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),w=v.indexOf(y),C=u?v.indexOf(u):-1,T=c.layersWithOutsidePointerEventsDisabled.size>0,E=C>=w,_=uue(O=>{const D=O.target,F=[...c.branches].some(U=>U.contains(D));!E||F||(s==null||s(O),i==null||i(O),O.defaultPrevented||a==null||a())},p),A=due(O=>{const D=O.target;[...c.branches].some(U=>U.contains(D))||(o==null||o(O),i==null||i(O),O.defaultPrevented||a==null||a())},p);return oue(O=>{C===c.layers.size-1&&(r==null||r(O),!O.defaultPrevented&&a&&(O.preventDefault(),a()))},p),k.useEffect(()=>{if(u)return t&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(XL=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),ZL(),()=>{t&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=XL)}},[u,p,t,c]),k.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),ZL())},[u,c]),k.useEffect(()=>{const O=()=>m({});return document.addEventListener(yE,O),()=>document.removeEventListener(yE,O)},[]),g.jsx(ct.div,{...l,ref:S,style:{pointerEvents:T?E?"auto":"none":void 0,...n.style},onFocusCapture:Re(n.onFocusCapture,A.onFocusCapture),onBlurCapture:Re(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:Re(n.onPointerDownCapture,_.onPointerDownCapture)})});Rg.displayName=iue;var cue="DismissableLayerBranch",K8=k.forwardRef((n,e)=>{const t=k.useContext(H8),r=k.useRef(null),s=Ht(e,r);return k.useEffect(()=>{const o=r.current;if(o)return t.branches.add(o),()=>{t.branches.delete(o)}},[t.branches]),g.jsx(ct.div,{...n,ref:s})});K8.displayName=cue;function uue(n,e=globalThis==null?void 0:globalThis.document){const t=is(n),r=k.useRef(!1),s=k.useRef(()=>{});return k.useEffect(()=>{const o=a=>{if(a.target&&!r.current){let l=function(){W8(aue,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},i=window.setTimeout(()=>{e.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(i),e.removeEventListener("pointerdown",o),e.removeEventListener("click",s.current)}},[e,t]),{onPointerDownCapture:()=>r.current=!0}}function due(n,e=globalThis==null?void 0:globalThis.document){const t=is(n),r=k.useRef(!1);return k.useEffect(()=>{const s=o=>{o.target&&!r.current&&W8(lue,t,{originalEvent:o},{discrete:!1})};return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function ZL(){const n=new CustomEvent(yE);document.dispatchEvent(n)}function W8(n,e,t,{discrete:r}){const s=t.originalEvent.target,o=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:t});e&&s.addEventListener(n,e,{once:!0}),r?YT(s,o):s.dispatchEvent(o)}var hue=Rg,fue=K8,mP="focusScope.autoFocusOnMount",yP="focusScope.autoFocusOnUnmount",JL={bubbles:!1,cancelable:!0},pue="FocusScope",tv=k.forwardRef((n,e)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...i}=n,[a,l]=k.useState(null),c=is(s),u=is(o),h=k.useRef(null),p=Ht(e,v=>l(v)),m=k.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;k.useEffect(()=>{if(r){let v=function(T){if(m.paused||!a)return;const E=T.target;a.contains(E)?h.current=E:Ll(h.current,{select:!0})},y=function(T){if(m.paused||!a)return;const E=T.relatedTarget;E!==null&&(a.contains(E)||Ll(h.current,{select:!0}))},w=function(T){if(document.activeElement===document.body)for(const _ of T)_.removedNodes.length>0&&Ll(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",y);const C=new MutationObserver(w);return a&&C.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",y),C.disconnect()}}},[r,a,m.paused]),k.useEffect(()=>{if(a){eN.add(m);const v=document.activeElement;if(!a.contains(v)){const w=new CustomEvent(mP,JL);a.addEventListener(mP,c),a.dispatchEvent(w),w.defaultPrevented||(gue(vue(V8(a)),{select:!0}),document.activeElement===v&&Ll(a))}return()=>{a.removeEventListener(mP,c),setTimeout(()=>{const w=new CustomEvent(yP,JL);a.addEventListener(yP,u),a.dispatchEvent(w),w.defaultPrevented||Ll(v??document.body,{select:!0}),a.removeEventListener(yP,u),eN.remove(m)},0)}}},[a,c,u,m]);const S=k.useCallback(v=>{if(!t&&!r||m.paused)return;const y=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,w=document.activeElement;if(y&&w){const C=v.currentTarget,[T,E]=mue(C);T&&E?!v.shiftKey&&w===E?(v.preventDefault(),t&&Ll(T,{select:!0})):v.shiftKey&&w===T&&(v.preventDefault(),t&&Ll(E,{select:!0})):w===C&&v.preventDefault()}},[t,r,m.paused]);return g.jsx(ct.div,{tabIndex:-1,...i,ref:p,onKeyDown:S})});tv.displayName=pue;function gue(n,{select:e=!1}={}){const t=document.activeElement;for(const r of n)if(Ll(r,{select:e}),document.activeElement!==t)return}function mue(n){const e=V8(n),t=QL(e,n),r=QL(e.reverse(),n);return[t,r]}function V8(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 QL(n,e){for(const t of n)if(!yue(t,{upTo:e}))return t}function yue(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 Sue(n){return n instanceof HTMLInputElement&&"select"in n}function Ll(n,{select:e=!1}={}){if(n&&n.focus){const t=document.activeElement;n.focus({preventScroll:!0}),n!==t&&Sue(n)&&e&&n.select()}}var eN=xue();function xue(){let n=[];return{add(e){const t=n[0];e!==t&&(t==null||t.pause()),n=tN(n,e),n.unshift(e)},remove(e){var t;n=tN(n,e),(t=n[0])==null||t.resume()}}}function tN(n,e){const t=[...n],r=t.indexOf(e);return r!==-1&&t.splice(r,1),t}function vue(n){return n.filter(e=>e.tagName!=="A")}var wue="Portal",Dg=k.forwardRef((n,e)=>{var a;const{container:t,...r}=n,[s,o]=k.useState(!1);Va(()=>o(!0),[]);const i=t||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Uee.createPortal(g.jsx(ct.div,{...r,ref:e}),i):null});Dg.displayName=wue;var SP=0;function ZT(){k.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??nN()),document.body.insertAdjacentElement("beforeend",n[1]??nN()),SP++,()=>{SP===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),SP--}},[])}function nN(){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 Ki=function(){return Ki=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},Ki.apply(this,arguments)};function G8(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(n);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(n,r[s])&&(t[r[s]]=n[r[s]]);return t}function bue(n,e,t){if(t||arguments.length===2)for(var r=0,s=e.length,o;r<s;r++)(o||!(r in e))&&(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return n.concat(o||Array.prototype.slice.call(e))}var nS="right-scroll-bar-position",rS="width-before-scroll-bar",Cue="with-scroll-bars-hidden",Pue="--removed-body-scroll-bar-size";function xP(n,e){return typeof n=="function"?n(e):n&&(n.current=e),n}function kue(n,e){var t=k.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 Eue=typeof window<"u"?k.useLayoutEffect:k.useEffect,rN=new WeakMap;function Iue(n,e){var t=kue(null,function(r){return n.forEach(function(s){return xP(s,r)})});return Eue(function(){var r=rN.get(t);if(r){var s=new Set(r),o=new Set(n),i=t.current;s.forEach(function(a){o.has(a)||xP(a,null)}),o.forEach(function(a){s.has(a)||xP(a,i)})}rN.set(t,n)},[n]),t}function Tue(n){return n}function _ue(n,e){e===void 0&&(e=Tue);var t=[],r=!1,s={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return t.length?t[t.length-1]:n},useMedium:function(o){var i=e(o,r);return t.push(i),function(){t=t.filter(function(a){return a!==i})}},assignSyncMedium:function(o){for(r=!0;t.length;){var i=t;t=[],i.forEach(o)}t={push:function(a){return o(a)},filter:function(){return t}}},assignMedium:function(o){r=!0;var i=[];if(t.length){var a=t;t=[],a.forEach(o),i=t}var l=function(){var u=i;i=[],u.forEach(o)},c=function(){return Promise.resolve().then(l)};c(),t={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),t}}}};return s}function Mue(n){n===void 0&&(n={});var e=_ue(null);return e.options=Ki({async:!0,ssr:!1},n),e}var q8=function(n){var e=n.sideCar,t=G8(n,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return k.createElement(r,Ki({},t))};q8.isSideCarExport=!0;function Aue(n,e){return n.useMedium(e),q8}var Y8=Mue(),vP=function(){},nv=k.forwardRef(function(n,e){var t=k.useRef(null),r=k.useState({onScrollCapture:vP,onWheelCapture:vP,onTouchMoveCapture:vP}),s=r[0],o=r[1],i=n.forwardProps,a=n.children,l=n.className,c=n.removeScrollBar,u=n.enabled,h=n.shards,p=n.sideCar,m=n.noRelative,S=n.noIsolation,v=n.inert,y=n.allowPinchZoom,w=n.as,C=w===void 0?"div":w,T=n.gapMode,E=G8(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),_=p,A=Iue([t,e]),O=Ki(Ki({},E),s);return k.createElement(k.Fragment,null,u&&k.createElement(_,{sideCar:Y8,removeScrollBar:c,shards:h,noRelative:m,noIsolation:S,inert:v,setCallbacks:o,allowPinchZoom:!!y,lockRef:t,gapMode:T}),i?k.cloneElement(k.Children.only(a),Ki(Ki({},O),{ref:A})):k.createElement(C,Ki({},O,{className:l,ref:A}),a))});nv.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};nv.classNames={fullWidth:rS,zeroRight:nS};var Oue=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Rue(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var e=Oue();return e&&n.setAttribute("nonce",e),n}function Due(n,e){n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}function jue(n){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(n)}var Lue=function(){var n=0,e=null;return{add:function(t){n==0&&(e=Rue())&&(Due(e,t),jue(e)),n++},remove:function(){n--,!n&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Nue=function(){var n=Lue();return function(e,t){k.useEffect(function(){return n.add(e),function(){n.remove()}},[e&&t])}},X8=function(){var n=Nue(),e=function(t){var r=t.styles,s=t.dynamic;return n(r,s),null};return e},Fue={left:0,top:0,right:0,gap:0},wP=function(n){return parseInt(n||"",10)||0},zue=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[wP(t),wP(r),wP(s)]},Bue=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return Fue;var e=zue(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])}},$ue=X8(),eh="data-scroll-locked",Uue=function(n,e,t,r){var s=n.left,o=n.top,i=n.right,a=n.gap;return t===void 0&&(t="margin"),`
307
+ .`.concat(Cue,` {
308
+ overflow: hidden `).concat(r,`;
309
+ padding-right: `).concat(a,"px ").concat(r,`;
310
+ }
311
+ body[`).concat(eh,`] {
312
+ overflow: hidden `).concat(r,`;
313
+ overscroll-behavior: contain;
314
+ `).concat([e&&"position: relative ".concat(r,";"),t==="margin"&&`
315
+ padding-left: `.concat(s,`px;
316
+ padding-top: `).concat(o,`px;
317
+ padding-right: `).concat(i,`px;
318
+ margin-left:0;
319
+ margin-top:0;
320
+ margin-right: `).concat(a,"px ").concat(r,`;
321
+ `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
322
+ }
323
+
324
+ .`).concat(nS,` {
325
+ right: `).concat(a,"px ").concat(r,`;
326
+ }
327
+
328
+ .`).concat(rS,` {
329
+ margin-right: `).concat(a,"px ").concat(r,`;
330
+ }
331
+
332
+ .`).concat(nS," .").concat(nS,` {
333
+ right: 0 `).concat(r,`;
334
+ }
335
+
336
+ .`).concat(rS," .").concat(rS,` {
337
+ margin-right: 0 `).concat(r,`;
338
+ }
339
+
340
+ body[`).concat(eh,`] {
341
+ `).concat(Pue,": ").concat(a,`px;
342
+ }
343
+ `)},sN=function(){var n=parseInt(document.body.getAttribute(eh)||"0",10);return isFinite(n)?n:0},Hue=function(){k.useEffect(function(){return document.body.setAttribute(eh,(sN()+1).toString()),function(){var n=sN()-1;n<=0?document.body.removeAttribute(eh):document.body.setAttribute(eh,n.toString())}},[])},Kue=function(n){var e=n.noRelative,t=n.noImportant,r=n.gapMode,s=r===void 0?"margin":r;Hue();var o=k.useMemo(function(){return Bue(s)},[s]);return k.createElement($ue,{styles:Uue(o,!e,s,t?"":"!important")})},SE=!1;if(typeof window<"u")try{var py=Object.defineProperty({},"passive",{get:function(){return SE=!0,!0}});window.addEventListener("test",py,py),window.removeEventListener("test",py,py)}catch{SE=!1}var Id=SE?{passive:!1}:!1,Wue=function(n){return n.tagName==="TEXTAREA"},Z8=function(n,e){if(!(n instanceof Element))return!1;var t=window.getComputedStyle(n);return t[e]!=="hidden"&&!(t.overflowY===t.overflowX&&!Wue(n)&&t[e]==="visible")},Vue=function(n){return Z8(n,"overflowY")},Gue=function(n){return Z8(n,"overflowX")},oN=function(n,e){var t=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=J8(n,r);if(s){var o=Q8(n,r),i=o[1],a=o[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},que=function(n){var e=n.scrollTop,t=n.scrollHeight,r=n.clientHeight;return[e,t,r]},Yue=function(n){var e=n.scrollLeft,t=n.scrollWidth,r=n.clientWidth;return[e,t,r]},J8=function(n,e){return n==="v"?Vue(e):Gue(e)},Q8=function(n,e){return n==="v"?que(e):Yue(e)},Xue=function(n,e){return n==="h"&&e==="rtl"?-1:1},Zue=function(n,e,t,r,s){var o=Xue(n,window.getComputedStyle(e).direction),i=o*r,a=t.target,l=e.contains(a),c=!1,u=i>0,h=0,p=0;do{var m=Q8(n,a),S=m[0],v=m[1],y=m[2],w=v-y-o*S;(S||w)&&J8(n,a)&&(h+=w,p+=S),a=a.parentNode.host||a.parentNode}while(!l&&a!==document.body||l&&(e.contains(a)||e===a));return(u&&Math.abs(h)<1||!u&&Math.abs(p)<1)&&(c=!0),c},gy=function(n){return"changedTouches"in n?[n.changedTouches[0].clientX,n.changedTouches[0].clientY]:[0,0]},iN=function(n){return[n.deltaX,n.deltaY]},aN=function(n){return n&&"current"in n?n.current:n},Jue=function(n,e){return n[0]===e[0]&&n[1]===e[1]},Que=function(n){return`
344
+ .block-interactivity-`.concat(n,` {pointer-events: none;}
345
+ .allow-interactivity-`).concat(n,` {pointer-events: all;}
346
+ `)},ede=0,Td=[];function tde(n){var e=k.useRef([]),t=k.useRef([0,0]),r=k.useRef(),s=k.useState(ede++)[0],o=k.useState(X8)[0],i=k.useRef(n);k.useEffect(function(){i.current=n},[n]),k.useEffect(function(){if(n.inert){document.body.classList.add("block-interactivity-".concat(s));var v=bue([n.lockRef.current],(n.shards||[]).map(aN),!0).filter(Boolean);return v.forEach(function(y){return y.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),v.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(s))})}}},[n.inert,n.lockRef.current,n.shards]);var a=k.useCallback(function(v,y){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!i.current.allowPinchZoom;var w=gy(v),C=t.current,T="deltaX"in v?v.deltaX:C[0]-w[0],E="deltaY"in v?v.deltaY:C[1]-w[1],_,A=v.target,O=Math.abs(T)>Math.abs(E)?"h":"v";if("touches"in v&&O==="h"&&A.type==="range")return!1;var D=oN(O,A);if(!D)return!0;if(D?_=O:(_=O==="v"?"h":"v",D=oN(O,A)),!D)return!1;if(!r.current&&"changedTouches"in v&&(T||E)&&(r.current=_),!_)return!0;var F=r.current||_;return Zue(F,y,v,F==="h"?T:E)},[]),l=k.useCallback(function(v){var y=v;if(!(!Td.length||Td[Td.length-1]!==o)){var w="deltaY"in y?iN(y):gy(y),C=e.current.filter(function(_){return _.name===y.type&&(_.target===y.target||y.target===_.shadowParent)&&Jue(_.delta,w)})[0];if(C&&C.should){y.cancelable&&y.preventDefault();return}if(!C){var T=(i.current.shards||[]).map(aN).filter(Boolean).filter(function(_){return _.contains(y.target)}),E=T.length>0?a(y,T[0]):!i.current.noIsolation;E&&y.cancelable&&y.preventDefault()}}},[]),c=k.useCallback(function(v,y,w,C){var T={name:v,delta:y,target:w,should:C,shadowParent:nde(w)};e.current.push(T),setTimeout(function(){e.current=e.current.filter(function(E){return E!==T})},1)},[]),u=k.useCallback(function(v){t.current=gy(v),r.current=void 0},[]),h=k.useCallback(function(v){c(v.type,iN(v),v.target,a(v,n.lockRef.current))},[]),p=k.useCallback(function(v){c(v.type,gy(v),v.target,a(v,n.lockRef.current))},[]);k.useEffect(function(){return Td.push(o),n.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Id),document.addEventListener("touchmove",l,Id),document.addEventListener("touchstart",u,Id),function(){Td=Td.filter(function(v){return v!==o}),document.removeEventListener("wheel",l,Id),document.removeEventListener("touchmove",l,Id),document.removeEventListener("touchstart",u,Id)}},[]);var m=n.removeScrollBar,S=n.inert;return k.createElement(k.Fragment,null,S?k.createElement(o,{styles:Que(s)}):null,m?k.createElement(Kue,{noRelative:n.noRelative,gapMode:n.gapMode}):null)}function nde(n){for(var e=null;n!==null;)n instanceof ShadowRoot&&(e=n.host,n=n.host),n=n.parentNode;return e}const rde=Aue(Y8,tde);var rv=k.forwardRef(function(n,e){return k.createElement(nv,Ki({},n,{ref:e,sideCar:rde}))});rv.classNames=nv.classNames;var sde=function(n){if(typeof document>"u")return null;var e=Array.isArray(n)?n[0]:n;return e.ownerDocument.body},_d=new WeakMap,my=new WeakMap,yy={},bP=0,eU=function(n){return n&&(n.host||eU(n.parentNode))},ode=function(n,e){return e.map(function(t){if(n.contains(t))return t;var r=eU(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})},ide=function(n,e,t,r){var s=ode(e,Array.isArray(n)?n:[n]);yy[t]||(yy[t]=new WeakMap);var o=yy[t],i=[],a=new Set,l=new Set(s),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};s.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(p){if(a.has(p))u(p);else try{var m=p.getAttribute(r),S=m!==null&&m!=="false",v=(_d.get(p)||0)+1,y=(o.get(p)||0)+1;_d.set(p,v),o.set(p,y),i.push(p),v===1&&S&&my.set(p,!0),y===1&&p.setAttribute(t,"true"),S||p.setAttribute(r,"true")}catch(w){console.error("aria-hidden: cannot operate on ",p,w)}})};return u(e),a.clear(),bP++,function(){i.forEach(function(h){var p=_d.get(h)-1,m=o.get(h)-1;_d.set(h,p),o.set(h,m),p||(my.has(h)||h.removeAttribute(r),my.delete(h)),m||h.removeAttribute(t)}),bP--,bP||(_d=new WeakMap,_d=new WeakMap,my=new WeakMap,yy={})}},JT=function(n,e,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(n)?n:[n]),s=sde(n);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live], script"))),ide(r,s,t,"aria-hidden")):function(){return null}},sv="Dialog",[tU,xPe]=Ho(sv),[ade,bi]=tU(sv),nU=n=>{const{__scopeDialog:e,children:t,open:r,defaultOpen:s,onOpenChange:o,modal:i=!0}=n,a=k.useRef(null),l=k.useRef(null),[c,u]=vi({prop:r,defaultProp:s??!1,onChange:o,caller:sv});return g.jsx(ade,{scope:e,triggerRef:a,contentRef:l,contentId:Ba(),titleId:Ba(),descriptionId:Ba(),open:c,onOpenChange:u,onOpenToggle:k.useCallback(()=>u(h=>!h),[u]),modal:i,children:t})};nU.displayName=sv;var rU="DialogTrigger",lde=k.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=bi(rU,t),o=Ht(e,s.triggerRef);return g.jsx(ct.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":t_(s.open),...r,ref:o,onClick:Re(n.onClick,s.onOpenToggle)})});lde.displayName=rU;var QT="DialogPortal",[cde,sU]=tU(QT,{forceMount:void 0}),oU=n=>{const{__scopeDialog:e,forceMount:t,children:r,container:s}=n,o=bi(QT,e);return g.jsx(cde,{scope:e,forceMount:t,children:k.Children.map(r,i=>g.jsx(wi,{present:t||o.open,children:g.jsx(Dg,{asChild:!0,container:s,children:i})}))})};oU.displayName=QT;var cx="DialogOverlay",iU=k.forwardRef((n,e)=>{const t=sU(cx,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,o=bi(cx,n.__scopeDialog);return o.modal?g.jsx(wi,{present:r||o.open,children:g.jsx(dde,{...s,ref:e})}):null});iU.displayName=cx;var ude=ph("DialogOverlay.RemoveScroll"),dde=k.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=bi(cx,t);return g.jsx(rv,{as:ude,allowPinchZoom:!0,shards:[s.contentRef],children:g.jsx(ct.div,{"data-state":t_(s.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),wu="DialogContent",aU=k.forwardRef((n,e)=>{const t=sU(wu,n.__scopeDialog),{forceMount:r=t.forceMount,...s}=n,o=bi(wu,n.__scopeDialog);return g.jsx(wi,{present:r||o.open,children:o.modal?g.jsx(hde,{...s,ref:e}):g.jsx(fde,{...s,ref:e})})});aU.displayName=wu;var hde=k.forwardRef((n,e)=>{const t=bi(wu,n.__scopeDialog),r=k.useRef(null),s=Ht(e,t.contentRef,r);return k.useEffect(()=>{const o=r.current;if(o)return JT(o)},[]),g.jsx(lU,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Re(n.onCloseAutoFocus,o=>{var i;o.preventDefault(),(i=t.triggerRef.current)==null||i.focus()}),onPointerDownOutside:Re(n.onPointerDownOutside,o=>{const i=o.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&o.preventDefault()}),onFocusOutside:Re(n.onFocusOutside,o=>o.preventDefault())})}),fde=k.forwardRef((n,e)=>{const t=bi(wu,n.__scopeDialog),r=k.useRef(!1),s=k.useRef(!1);return g.jsx(lU,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=n.onCloseAutoFocus)==null||i.call(n,o),o.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=n.onInteractOutside)==null||l.call(n,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=t.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),lU=k.forwardRef((n,e)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,...i}=n,a=bi(wu,t),l=k.useRef(null),c=Ht(e,l);return ZT(),g.jsxs(g.Fragment,{children:[g.jsx(tv,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:g.jsx(Rg,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":t_(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),g.jsxs(g.Fragment,{children:[g.jsx(gde,{titleId:a.titleId}),g.jsx(yde,{contentRef:l,descriptionId:a.descriptionId})]})]})}),e_="DialogTitle",cU=k.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=bi(e_,t);return g.jsx(ct.h2,{id:s.titleId,...r,ref:e})});cU.displayName=e_;var uU="DialogDescription",pde=k.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=bi(uU,t);return g.jsx(ct.p,{id:s.descriptionId,...r,ref:e})});pde.displayName=uU;var dU="DialogClose",hU=k.forwardRef((n,e)=>{const{__scopeDialog:t,...r}=n,s=bi(dU,t);return g.jsx(ct.button,{type:"button",...r,ref:e,onClick:Re(n.onClick,()=>s.onOpenChange(!1))})});hU.displayName=dU;function t_(n){return n?"open":"closed"}var fU="DialogTitleWarning",[vPe,pU]=qce(fU,{contentName:wu,titleName:e_,docsSlug:"dialog"}),gde=({titleId:n})=>{const e=pU(fU),t=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
347
+
348
+ If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
349
+
350
+ For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return k.useEffect(()=>{n&&(document.getElementById(n)||console.error(t))},[t,n]),null},mde="DialogDescriptionWarning",yde=({contentRef:n,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${pU(mde).contentName}}.`;return k.useEffect(()=>{var o;const s=(o=n.current)==null?void 0:o.getAttribute("aria-describedby");e&&s&&(document.getElementById(e)||console.warn(r))},[r,n,e]),null},Sde=nU,xde=oU,vde=iU,wde=aU,bde=cU;function Cde(n){const e=k.useRef({value:n,previous:n});return k.useMemo(()=>(e.current.value!==n&&(e.current.previous=e.current.value,e.current.value=n),e.current.previous),[n])}function gU(n){const[e,t]=k.useState(void 0);return Va(()=>{if(n){t({width:n.offsetWidth,height:n.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let i,a;if("borderBoxSize"in o){const l=o.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=n.offsetWidth,a=n.offsetHeight;t({width:i,height:a})});return r.observe(n,{box:"border-box"}),()=>r.unobserve(n)}else t(void 0)},[n]),e}const Pde=["top","right","bottom","left"],ic=Math.min,Ys=Math.max,ux=Math.round,Sy=Math.floor,Yi=n=>({x:n,y:n}),kde={left:"right",right:"left",bottom:"top",top:"bottom"},Ede={start:"end",end:"start"};function xE(n,e,t){return Ys(n,ic(e,t))}function Ga(n,e){return typeof n=="function"?n(e):n}function qa(n){return n.split("-")[0]}function jh(n){return n.split("-")[1]}function n_(n){return n==="x"?"y":"x"}function r_(n){return n==="y"?"height":"width"}function $a(n){return["top","bottom"].includes(qa(n))?"y":"x"}function s_(n){return n_($a(n))}function Ide(n,e,t){t===void 0&&(t=!1);const r=jh(n),s=s_(n),o=r_(s);let i=s==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(i=dx(i)),[i,dx(i)]}function Tde(n){const e=dx(n);return[vE(n),e,vE(e)]}function vE(n){return n.replace(/start|end/g,e=>Ede[e])}function _de(n,e,t){const r=["left","right"],s=["right","left"],o=["top","bottom"],i=["bottom","top"];switch(n){case"top":case"bottom":return t?e?s:r:e?r:s;case"left":case"right":return e?o:i;default:return[]}}function Mde(n,e,t,r){const s=jh(n);let o=_de(qa(n),t==="start",r);return s&&(o=o.map(i=>i+"-"+s),e&&(o=o.concat(o.map(vE)))),o}function dx(n){return n.replace(/left|right|bottom|top/g,e=>kde[e])}function Ade(n){return{top:0,right:0,bottom:0,left:0,...n}}function mU(n){return typeof n!="number"?Ade(n):{top:n,right:n,bottom:n,left:n}}function hx(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 lN(n,e,t){let{reference:r,floating:s}=n;const o=$a(e),i=s_(e),a=r_(i),l=qa(e),c=o==="y",u=r.x+r.width/2-s.width/2,h=r.y+r.height/2-s.height/2,p=r[a]/2-s[a]/2;let m;switch(l){case"top":m={x:u,y:r.y-s.height};break;case"bottom":m={x:u,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:h};break;case"left":m={x:r.x-s.width,y:h};break;default:m={x:r.x,y:r.y}}switch(jh(e)){case"start":m[i]-=p*(t&&c?-1:1);break;case"end":m[i]+=p*(t&&c?-1:1);break}return m}const Ode=async(n,e,t)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=t,a=o.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(e));let c=await i.getElementRects({reference:n,floating:e,strategy:s}),{x:u,y:h}=lN(c,r,l),p=r,m={},S=0;for(let v=0;v<a.length;v++){const{name:y,fn:w}=a[v],{x:C,y:T,data:E,reset:_}=await w({x:u,y:h,initialPlacement:r,placement:p,strategy:s,middlewareData:m,rects:c,platform:i,elements:{reference:n,floating:e}});u=C??u,h=T??h,m={...m,[y]:{...m[y],...E}},_&&S<=50&&(S++,typeof _=="object"&&(_.placement&&(p=_.placement),_.rects&&(c=_.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:s}):_.rects),{x:u,y:h}=lN(c,p,l)),v=-1)}return{x:u,y:h,placement:p,strategy:s,middlewareData:m}};async function Yp(n,e){var t;e===void 0&&(e={});const{x:r,y:s,platform:o,rects:i,elements:a,strategy:l}=n,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:p=!1,padding:m=0}=Ga(e,n),S=mU(m),y=a[p?h==="floating"?"reference":"floating":h],w=hx(await o.getClippingRect({element:(t=await(o.isElement==null?void 0:o.isElement(y)))==null||t?y:y.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),C=h==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,T=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),E=await(o.isElement==null?void 0:o.isElement(T))?await(o.getScale==null?void 0:o.getScale(T))||{x:1,y:1}:{x:1,y:1},_=hx(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:C,offsetParent:T,strategy:l}):C);return{top:(w.top-_.top+S.top)/E.y,bottom:(_.bottom-w.bottom+S.bottom)/E.y,left:(w.left-_.left+S.left)/E.x,right:(_.right-w.right+S.right)/E.x}}const Rde=n=>({name:"arrow",options:n,async fn(e){const{x:t,y:r,placement:s,rects:o,platform:i,elements:a,middlewareData:l}=e,{element:c,padding:u=0}=Ga(n,e)||{};if(c==null)return{};const h=mU(u),p={x:t,y:r},m=s_(s),S=r_(m),v=await i.getDimensions(c),y=m==="y",w=y?"top":"left",C=y?"bottom":"right",T=y?"clientHeight":"clientWidth",E=o.reference[S]+o.reference[m]-p[m]-o.floating[S],_=p[m]-o.reference[m],A=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let O=A?A[T]:0;(!O||!await(i.isElement==null?void 0:i.isElement(A)))&&(O=a.floating[T]||o.floating[S]);const D=E/2-_/2,F=O/2-v[S]/2-1,U=ic(h[w],F),V=ic(h[C],F),Y=U,j=O-v[S]-V,N=O/2-v[S]/2+D,z=xE(Y,N,j),G=!l.arrow&&jh(s)!=null&&N!==z&&o.reference[S]/2-(N<Y?U:V)-v[S]/2<0,q=G?N<Y?N-Y:N-j:0;return{[m]:p[m]+q,data:{[m]:z,centerOffset:N-z-q,...G&&{alignmentOffset:q}},reset:G}}}),Dde=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:v=!0,...y}=Ga(n,e);if((t=o.arrow)!=null&&t.alignmentOffset)return{};const w=qa(s),C=$a(a),T=qa(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(c.floating)),_=p||(T||!v?[dx(a)]:Tde(a)),A=S!=="none";!p&&A&&_.push(...Mde(a,v,S,E));const O=[a,..._],D=await Yp(e,y),F=[];let U=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&F.push(D[w]),h){const z=Ide(s,i,E);F.push(D[z[0]],D[z[1]])}if(U=[...U,{placement:s,overflows:F}],!F.every(z=>z<=0)){var V,Y;const z=(((V=o.flip)==null?void 0:V.index)||0)+1,G=O[z];if(G){var j;const $=h==="alignment"?C!==$a(G):!1,K=((j=U[0])==null?void 0:j.overflows[0])>0;if(!$||K)return{data:{index:z,overflows:U},reset:{placement:G}}}let q=(Y=U.filter($=>$.overflows[0]<=0).sort(($,K)=>$.overflows[1]-K.overflows[1])[0])==null?void 0:Y.placement;if(!q)switch(m){case"bestFit":{var N;const $=(N=U.filter(K=>{if(A){const J=$a(K.placement);return J===C||J==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(J=>J>0).reduce((J,H)=>J+H,0)]).sort((K,J)=>K[1]-J[1])[0])==null?void 0:N[0];$&&(q=$);break}case"initialPlacement":q=a;break}if(s!==q)return{reset:{placement:q}}}return{}}}};function cN(n,e){return{top:n.top-e.height,right:n.right-e.width,bottom:n.bottom-e.height,left:n.left-e.width}}function uN(n){return Pde.some(e=>n[e]>=0)}const jde=function(n){return n===void 0&&(n={}),{name:"hide",options:n,async fn(e){const{rects:t}=e,{strategy:r="referenceHidden",...s}=Ga(n,e);switch(r){case"referenceHidden":{const o=await Yp(e,{...s,elementContext:"reference"}),i=cN(o,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:uN(i)}}}case"escaped":{const o=await Yp(e,{...s,altBoundary:!0}),i=cN(o,t.floating);return{data:{escapedOffsets:i,escaped:uN(i)}}}default:return{}}}}};async function Lde(n,e){const{placement:t,platform:r,elements:s}=n,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=qa(t),a=jh(t),l=$a(t)==="y",c=["left","top"].includes(i)?-1:1,u=o&&l?-1:1,h=Ga(e,n);let{mainAxis:p,crossAxis:m,alignmentAxis:S}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof S=="number"&&(m=a==="end"?S*-1:S),l?{x:m*u,y:p*c}:{x:p*c,y:m*u}}const Nde=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,r;const{x:s,y:o,placement:i,middlewareData:a}=e,l=await Lde(e,n);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:o+l.y,data:{...l,placement:i}}}}},Fde=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){const{x:t,y:r,placement:s}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:y=>{let{x:w,y:C}=y;return{x:w,y:C}}},...l}=Ga(n,e),c={x:t,y:r},u=await Yp(e,l),h=$a(qa(s)),p=n_(h);let m=c[p],S=c[h];if(o){const y=p==="y"?"top":"left",w=p==="y"?"bottom":"right",C=m+u[y],T=m-u[w];m=xE(C,m,T)}if(i){const y=h==="y"?"top":"left",w=h==="y"?"bottom":"right",C=S+u[y],T=S-u[w];S=xE(C,S,T)}const v=a.fn({...e,[p]:m,[h]:S});return{...v,data:{x:v.x-t,y:v.y-r,enabled:{[p]:o,[h]:i}}}}}},zde=function(n){return n===void 0&&(n={}),{options:n,fn(e){const{x:t,y:r,placement:s,rects:o,middlewareData:i}=e,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Ga(n,e),u={x:t,y:r},h=$a(s),p=n_(h);let m=u[p],S=u[h];const v=Ga(a,e),y=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(l){const T=p==="y"?"height":"width",E=o.reference[p]-o.floating[T]+y.mainAxis,_=o.reference[p]+o.reference[T]-y.mainAxis;m<E?m=E:m>_&&(m=_)}if(c){var w,C;const T=p==="y"?"width":"height",E=["top","left"].includes(qa(s)),_=o.reference[h]-o.floating[T]+(E&&((w=i.offset)==null?void 0:w[h])||0)+(E?0:y.crossAxis),A=o.reference[h]+o.reference[T]+(E?0:((C=i.offset)==null?void 0:C[h])||0)-(E?y.crossAxis:0);S<_?S=_:S>A&&(S=A)}return{[p]:m,[h]:S}}}},Bde=function(n){return n===void 0&&(n={}),{name:"size",options:n,async fn(e){var t,r;const{placement:s,rects:o,platform:i,elements:a}=e,{apply:l=()=>{},...c}=Ga(n,e),u=await Yp(e,c),h=qa(s),p=jh(s),m=$a(s)==="y",{width:S,height:v}=o.floating;let y,w;h==="top"||h==="bottom"?(y=h,w=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(w=h,y=p==="end"?"top":"bottom");const C=v-u.top-u.bottom,T=S-u.left-u.right,E=ic(v-u[y],C),_=ic(S-u[w],T),A=!e.middlewareData.shift;let O=E,D=_;if((t=e.middlewareData.shift)!=null&&t.enabled.x&&(D=T),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(O=C),A&&!p){const U=Ys(u.left,0),V=Ys(u.right,0),Y=Ys(u.top,0),j=Ys(u.bottom,0);m?D=S-2*(U!==0||V!==0?U+V:Ys(u.left,u.right)):O=v-2*(Y!==0||j!==0?Y+j:Ys(u.top,u.bottom))}await l({...e,availableWidth:D,availableHeight:O});const F=await i.getDimensions(a.floating);return S!==F.width||v!==F.height?{reset:{rects:!0}}:{}}}};function ov(){return typeof window<"u"}function Lh(n){return yU(n)?(n.nodeName||"").toLowerCase():"#document"}function io(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function oa(n){var e;return(e=(yU(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function yU(n){return ov()?n instanceof Node||n instanceof io(n).Node:!1}function yi(n){return ov()?n instanceof Element||n instanceof io(n).Element:!1}function ta(n){return ov()?n instanceof HTMLElement||n instanceof io(n).HTMLElement:!1}function dN(n){return!ov()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof io(n).ShadowRoot}function jg(n){const{overflow:e,overflowX:t,overflowY:r,display:s}=Si(n);return/auto|scroll|overlay|hidden|clip/.test(e+r+t)&&!["inline","contents"].includes(s)}function $de(n){return["table","td","th"].includes(Lh(n))}function iv(n){return[":popover-open",":modal"].some(e=>{try{return n.matches(e)}catch{return!1}})}function o_(n){const e=i_(),t=yi(n)?Si(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 Ude(n){let e=ac(n);for(;ta(e)&&!gh(e);){if(o_(e))return e;if(iv(e))return null;e=ac(e)}return null}function i_(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function gh(n){return["html","body","#document"].includes(Lh(n))}function Si(n){return io(n).getComputedStyle(n)}function av(n){return yi(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function ac(n){if(Lh(n)==="html")return n;const e=n.assignedSlot||n.parentNode||dN(n)&&n.host||oa(n);return dN(e)?e.host:e}function SU(n){const e=ac(n);return gh(e)?n.ownerDocument?n.ownerDocument.body:n.body:ta(e)&&jg(e)?e:SU(e)}function Xp(n,e,t){var r;e===void 0&&(e=[]),t===void 0&&(t=!0);const s=SU(n),o=s===((r=n.ownerDocument)==null?void 0:r.body),i=io(s);if(o){const a=wE(i);return e.concat(i,i.visualViewport||[],jg(s)?s:[],a&&t?Xp(a):[])}return e.concat(s,Xp(s,[],t))}function wE(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function xU(n){const e=Si(n);let t=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=ta(n),o=s?n.offsetWidth:t,i=s?n.offsetHeight:r,a=ux(t)!==o||ux(r)!==i;return a&&(t=o,r=i),{width:t,height:r,$:a}}function a_(n){return yi(n)?n:n.contextElement}function th(n){const e=a_(n);if(!ta(e))return Yi(1);const t=e.getBoundingClientRect(),{width:r,height:s,$:o}=xU(e);let i=(o?ux(t.width):t.width)/r,a=(o?ux(t.height):t.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Hde=Yi(0);function vU(n){const e=io(n);return!i_()||!e.visualViewport?Hde:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Kde(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==io(n)?!1:e}function bu(n,e,t,r){e===void 0&&(e=!1),t===void 0&&(t=!1);const s=n.getBoundingClientRect(),o=a_(n);let i=Yi(1);e&&(r?yi(r)&&(i=th(r)):i=th(n));const a=Kde(o,t,r)?vU(o):Yi(0);let l=(s.left+a.x)/i.x,c=(s.top+a.y)/i.y,u=s.width/i.x,h=s.height/i.y;if(o){const p=io(o),m=r&&yi(r)?io(r):r;let S=p,v=wE(S);for(;v&&r&&m!==S;){const y=th(v),w=v.getBoundingClientRect(),C=Si(v),T=w.left+(v.clientLeft+parseFloat(C.paddingLeft))*y.x,E=w.top+(v.clientTop+parseFloat(C.paddingTop))*y.y;l*=y.x,c*=y.y,u*=y.x,h*=y.y,l+=T,c+=E,S=io(v),v=wE(S)}}return hx({width:u,height:h,x:l,y:c})}function l_(n,e){const t=av(n).scrollLeft;return e?e.left+t:bu(oa(n)).left+t}function wU(n,e,t){t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=r.left+e.scrollLeft-(t?0:l_(n,r)),o=r.top+e.scrollTop;return{x:s,y:o}}function Wde(n){let{elements:e,rect:t,offsetParent:r,strategy:s}=n;const o=s==="fixed",i=oa(r),a=e?iv(e.floating):!1;if(r===i||a&&o)return t;let l={scrollLeft:0,scrollTop:0},c=Yi(1);const u=Yi(0),h=ta(r);if((h||!h&&!o)&&((Lh(r)!=="body"||jg(i))&&(l=av(r)),ta(r))){const m=bu(r);c=th(r),u.x=m.x+r.clientLeft,u.y=m.y+r.clientTop}const p=i&&!h&&!o?wU(i,l,!0):Yi(0);return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-l.scrollLeft*c.x+u.x+p.x,y:t.y*c.y-l.scrollTop*c.y+u.y+p.y}}function Vde(n){return Array.from(n.getClientRects())}function Gde(n){const e=oa(n),t=av(n),r=n.ownerDocument.body,s=Ys(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=Ys(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+l_(n);const a=-t.scrollTop;return Si(r).direction==="rtl"&&(i+=Ys(e.clientWidth,r.clientWidth)-s),{width:s,height:o,x:i,y:a}}function qde(n,e){const t=io(n),r=oa(n),s=t.visualViewport;let o=r.clientWidth,i=r.clientHeight,a=0,l=0;if(s){o=s.width,i=s.height;const c=i_();(!c||c&&e==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:o,height:i,x:a,y:l}}function Yde(n,e){const t=bu(n,!0,e==="fixed"),r=t.top+n.clientTop,s=t.left+n.clientLeft,o=ta(n)?th(n):Yi(1),i=n.clientWidth*o.x,a=n.clientHeight*o.y,l=s*o.x,c=r*o.y;return{width:i,height:a,x:l,y:c}}function hN(n,e,t){let r;if(e==="viewport")r=qde(n,t);else if(e==="document")r=Gde(oa(n));else if(yi(e))r=Yde(e,t);else{const s=vU(n);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return hx(r)}function bU(n,e){const t=ac(n);return t===e||!yi(t)||gh(t)?!1:Si(t).position==="fixed"||bU(t,e)}function Xde(n,e){const t=e.get(n);if(t)return t;let r=Xp(n,[],!1).filter(a=>yi(a)&&Lh(a)!=="body"),s=null;const o=Si(n).position==="fixed";let i=o?ac(n):n;for(;yi(i)&&!gh(i);){const a=Si(i),l=o_(i);!l&&a.position==="fixed"&&(s=null),(o?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||jg(i)&&!l&&bU(n,i))?r=r.filter(u=>u!==i):s=a,i=ac(i)}return e.set(n,r),r}function Zde(n){let{element:e,boundary:t,rootBoundary:r,strategy:s}=n;const i=[...t==="clippingAncestors"?iv(e)?[]:Xde(e,this._c):[].concat(t),r],a=i[0],l=i.reduce((c,u)=>{const h=hN(e,u,s);return c.top=Ys(h.top,c.top),c.right=ic(h.right,c.right),c.bottom=ic(h.bottom,c.bottom),c.left=Ys(h.left,c.left),c},hN(e,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Jde(n){const{width:e,height:t}=xU(n);return{width:e,height:t}}function Qde(n,e,t){const r=ta(e),s=oa(e),o=t==="fixed",i=bu(n,!0,o,e);let a={scrollLeft:0,scrollTop:0};const l=Yi(0);function c(){l.x=l_(s)}if(r||!r&&!o)if((Lh(e)!=="body"||jg(s))&&(a=av(e)),r){const m=bu(e,!0,o,e);l.x=m.x+e.clientLeft,l.y=m.y+e.clientTop}else s&&c();o&&!r&&s&&c();const u=s&&!r&&!o?wU(s,a):Yi(0),h=i.left+a.scrollLeft-l.x-u.x,p=i.top+a.scrollTop-l.y-u.y;return{x:h,y:p,width:i.width,height:i.height}}function CP(n){return Si(n).position==="static"}function fN(n,e){if(!ta(n)||Si(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return oa(n)===t&&(t=t.ownerDocument.body),t}function CU(n,e){const t=io(n);if(iv(n))return t;if(!ta(n)){let s=ac(n);for(;s&&!gh(s);){if(yi(s)&&!CP(s))return s;s=ac(s)}return t}let r=fN(n,e);for(;r&&$de(r)&&CP(r);)r=fN(r,e);return r&&gh(r)&&CP(r)&&!o_(r)?t:r||Ude(n)||t}const ehe=async function(n){const e=this.getOffsetParent||CU,t=this.getDimensions,r=await t(n.floating);return{reference:Qde(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function the(n){return Si(n).direction==="rtl"}const nhe={convertOffsetParentRelativeRectToViewportRelativeRect:Wde,getDocumentElement:oa,getClippingRect:Zde,getOffsetParent:CU,getElementRects:ehe,getClientRects:Vde,getDimensions:Jde,getScale:th,isElement:yi,isRTL:the};function PU(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function rhe(n,e){let t=null,r;const s=oa(n);function o(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),o();const c=n.getBoundingClientRect(),{left:u,top:h,width:p,height:m}=c;if(a||e(),!p||!m)return;const S=Sy(h),v=Sy(s.clientWidth-(u+p)),y=Sy(s.clientHeight-(h+m)),w=Sy(u),T={rootMargin:-S+"px "+-v+"px "+-y+"px "+-w+"px",threshold:Ys(0,ic(1,l))||1};let E=!0;function _(A){const O=A[0].intersectionRatio;if(O!==l){if(!E)return i();O?i(!1,O):r=setTimeout(()=>{i(!1,1e-7)},1e3)}O===1&&!PU(c,n.getBoundingClientRect())&&i(),E=!1}try{t=new IntersectionObserver(_,{...T,root:s.ownerDocument})}catch{t=new IntersectionObserver(_,T)}t.observe(n)}return i(!0),o}function she(n,e,t,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=a_(n),u=s||o?[...c?Xp(c):[],...Xp(e)]:[];u.forEach(w=>{s&&w.addEventListener("scroll",t,{passive:!0}),o&&w.addEventListener("resize",t)});const h=c&&a?rhe(c,t):null;let p=-1,m=null;i&&(m=new ResizeObserver(w=>{let[C]=w;C&&C.target===c&&m&&(m.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var T;(T=m)==null||T.observe(e)})),t()}),c&&!l&&m.observe(c),m.observe(e));let S,v=l?bu(n):null;l&&y();function y(){const w=bu(n);v&&!PU(v,w)&&t(),v=w,S=requestAnimationFrame(y)}return t(),()=>{var w;u.forEach(C=>{s&&C.removeEventListener("scroll",t),o&&C.removeEventListener("resize",t)}),h==null||h(),(w=m)==null||w.disconnect(),m=null,l&&cancelAnimationFrame(S)}}const ohe=Nde,ihe=Fde,ahe=Dde,lhe=Bde,che=jde,pN=Rde,uhe=zde,dhe=(n,e,t)=>{const r=new Map,s={platform:nhe,...t},o={...s.platform,_c:r};return Ode(n,e,{...s,platform:o})};var sS=typeof document<"u"?k.useLayoutEffect:k.useEffect;function fx(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(!fx(n[r],e[r]))return!1;return!0}if(s=Object.keys(n),t=s.length,t!==Object.keys(e).length)return!1;for(r=t;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=t;r--!==0;){const o=s[r];if(!(o==="_owner"&&n.$$typeof)&&!fx(n[o],e[o]))return!1}return!0}return n!==n&&e!==e}function kU(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function gN(n,e){const t=kU(n);return Math.round(e*t)/t}function PP(n){const e=k.useRef(n);return sS(()=>{e.current=n}),e}function hhe(n){n===void 0&&(n={});const{placement:e="bottom",strategy:t="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=n,[u,h]=k.useState({x:0,y:0,strategy:t,placement:e,middlewareData:{},isPositioned:!1}),[p,m]=k.useState(r);fx(p,r)||m(r);const[S,v]=k.useState(null),[y,w]=k.useState(null),C=k.useCallback($=>{$!==A.current&&(A.current=$,v($))},[]),T=k.useCallback($=>{$!==O.current&&(O.current=$,w($))},[]),E=o||S,_=i||y,A=k.useRef(null),O=k.useRef(null),D=k.useRef(u),F=l!=null,U=PP(l),V=PP(s),Y=PP(c),j=k.useCallback(()=>{if(!A.current||!O.current)return;const $={placement:e,strategy:t,middleware:p};V.current&&($.platform=V.current),dhe(A.current,O.current,$).then(K=>{const J={...K,isPositioned:Y.current!==!1};N.current&&!fx(D.current,J)&&(D.current=J,Mh.flushSync(()=>{h(J)}))})},[p,e,t,V,Y]);sS(()=>{c===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,h($=>({...$,isPositioned:!1})))},[c]);const N=k.useRef(!1);sS(()=>(N.current=!0,()=>{N.current=!1}),[]),sS(()=>{if(E&&(A.current=E),_&&(O.current=_),E&&_){if(U.current)return U.current(E,_,j);j()}},[E,_,j,U,F]);const z=k.useMemo(()=>({reference:A,floating:O,setReference:C,setFloating:T}),[C,T]),G=k.useMemo(()=>({reference:E,floating:_}),[E,_]),q=k.useMemo(()=>{const $={position:t,left:0,top:0};if(!G.floating)return $;const K=gN(G.floating,u.x),J=gN(G.floating,u.y);return a?{...$,transform:"translate("+K+"px, "+J+"px)",...kU(G.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:K,top:J}},[t,a,G.floating,u.x,u.y]);return k.useMemo(()=>({...u,update:j,refs:z,elements:G,floatingStyles:q}),[u,j,z,G,q])}const fhe=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?pN({element:r.current,padding:s}).fn(t):{}:r?pN({element:r,padding:s}).fn(t):{}}}},phe=(n,e)=>({...ohe(n),options:[n,e]}),ghe=(n,e)=>({...ihe(n),options:[n,e]}),mhe=(n,e)=>({...uhe(n),options:[n,e]}),yhe=(n,e)=>({...ahe(n),options:[n,e]}),She=(n,e)=>({...lhe(n),options:[n,e]}),xhe=(n,e)=>({...che(n),options:[n,e]}),vhe=(n,e)=>({...fhe(n),options:[n,e]});var whe="Arrow",EU=k.forwardRef((n,e)=>{const{children:t,width:r=10,height:s=5,...o}=n;return g.jsx(ct.svg,{...o,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:n.asChild?t:g.jsx("polygon",{points:"0,0 30,0 15,10"})})});EU.displayName=whe;var bhe=EU,c_="Popper",[IU,lv]=Ho(c_),[Che,TU]=IU(c_),_U=n=>{const{__scopePopper:e,children:t}=n,[r,s]=k.useState(null);return g.jsx(Che,{scope:e,anchor:r,onAnchorChange:s,children:t})};_U.displayName=c_;var MU="PopperAnchor",AU=k.forwardRef((n,e)=>{const{__scopePopper:t,virtualRef:r,...s}=n,o=TU(MU,t),i=k.useRef(null),a=Ht(e,i);return k.useEffect(()=>{o.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:g.jsx(ct.div,{...s,ref:a})});AU.displayName=MU;var u_="PopperContent",[Phe,khe]=IU(u_),OU=k.forwardRef((n,e)=>{var ze,ve,Te,je,At,on;const{__scopePopper:t,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:m="optimized",onPlaced:S,...v}=n,y=TU(u_,t),[w,C]=k.useState(null),T=Ht(e,_t=>C(_t)),[E,_]=k.useState(null),A=gU(E),O=(A==null?void 0:A.width)??0,D=(A==null?void 0:A.height)??0,F=r+(o!=="center"?"-"+o:""),U=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},V=Array.isArray(c)?c:[c],Y=V.length>0,j={padding:U,boundary:V.filter(Ihe),altBoundary:Y},{refs:N,floatingStyles:z,placement:G,isPositioned:q,middlewareData:$}=hhe({strategy:"fixed",placement:F,whileElementsMounted:(..._t)=>she(..._t,{animationFrame:m==="always"}),elements:{reference:y.anchor},middleware:[phe({mainAxis:s+D,alignmentAxis:i}),l&&ghe({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?mhe():void 0,...j}),l&&yhe({...j}),She({...j,apply:({elements:_t,rects:Ot,availableWidth:an,availableHeight:rr})=>{const{width:Hr,height:zs}=Ot.reference,$n=_t.floating.style;$n.setProperty("--radix-popper-available-width",`${an}px`),$n.setProperty("--radix-popper-available-height",`${rr}px`),$n.setProperty("--radix-popper-anchor-width",`${Hr}px`),$n.setProperty("--radix-popper-anchor-height",`${zs}px`)}}),E&&vhe({element:E,padding:a}),The({arrowWidth:O,arrowHeight:D}),p&&xhe({strategy:"referenceHidden",...j})]}),[K,J]=jU(G),H=is(S);Va(()=>{q&&(H==null||H())},[q,H]);const te=(ze=$.arrow)==null?void 0:ze.x,he=(ve=$.arrow)==null?void 0:ve.y,Pe=((Te=$.arrow)==null?void 0:Te.centerOffset)!==0,[ue,Ae]=k.useState();return Va(()=>{w&&Ae(window.getComputedStyle(w).zIndex)},[w]),g.jsx("div",{ref:N.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:q?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ue,"--radix-popper-transform-origin":[(je=$.transformOrigin)==null?void 0:je.x,(At=$.transformOrigin)==null?void 0:At.y].join(" "),...((on=$.hide)==null?void 0:on.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:g.jsx(Phe,{scope:t,placedSide:K,onArrowChange:_,arrowX:te,arrowY:he,shouldHideArrow:Pe,children:g.jsx(ct.div,{"data-side":K,"data-align":J,...v,ref:T,style:{...v.style,animation:q?void 0:"none"}})})})});OU.displayName=u_;var RU="PopperArrow",Ehe={top:"bottom",right:"left",bottom:"top",left:"right"},DU=k.forwardRef(function(e,t){const{__scopePopper:r,...s}=e,o=khe(RU,r),i=Ehe[o.placedSide];return g.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:g.jsx(bhe,{...s,ref:t,style:{...s.style,display:"block"}})})});DU.displayName=RU;function Ihe(n){return n!==null}var The=n=>({name:"transformOrigin",options:n,fn(e){var y,w,C;const{placement:t,rects:r,middlewareData:s}=e,i=((y=s.arrow)==null?void 0:y.centerOffset)!==0,a=i?0:n.arrowWidth,l=i?0:n.arrowHeight,[c,u]=jU(t),h={start:"0%",center:"50%",end:"100%"}[u],p=(((w=s.arrow)==null?void 0:w.x)??0)+a/2,m=(((C=s.arrow)==null?void 0:C.y)??0)+l/2;let S="",v="";return c==="bottom"?(S=i?h:`${p}px`,v=`${-l}px`):c==="top"?(S=i?h:`${p}px`,v=`${r.floating.height+l}px`):c==="right"?(S=`${-l}px`,v=i?h:`${m}px`):c==="left"&&(S=`${r.floating.width+l}px`,v=i?h:`${m}px`),{data:{x:S,y:v}}}});function jU(n){const[e,t="center"]=n.split("-");return[e,t]}var d_=_U,h_=AU,LU=OU,NU=DU,kP="rovingFocusGroup.onEntryFocus",_he={bubbles:!1,cancelable:!0},Lg="RovingFocusGroup",[bE,FU,Mhe]=ev(Lg),[Ahe,Nh]=Ho(Lg,[Mhe]),[Ohe,Rhe]=Ahe(Lg),zU=k.forwardRef((n,e)=>g.jsx(bE.Provider,{scope:n.__scopeRovingFocusGroup,children:g.jsx(bE.Slot,{scope:n.__scopeRovingFocusGroup,children:g.jsx(Dhe,{...n,ref:e})})}));zU.displayName=Lg;var Dhe=k.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:s=!1,dir:o,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=n,p=k.useRef(null),m=Ht(e,p),S=Og(o),[v,y]=vi({prop:i,defaultProp:a??null,onChange:l,caller:Lg}),[w,C]=k.useState(!1),T=is(c),E=FU(t),_=k.useRef(!1),[A,O]=k.useState(0);return k.useEffect(()=>{const D=p.current;if(D)return D.addEventListener(kP,T),()=>D.removeEventListener(kP,T)},[T]),g.jsx(Ohe,{scope:t,orientation:r,dir:S,loop:s,currentTabStopId:v,onItemFocus:k.useCallback(D=>y(D),[y]),onItemShiftTab:k.useCallback(()=>C(!0),[]),onFocusableItemAdd:k.useCallback(()=>O(D=>D+1),[]),onFocusableItemRemove:k.useCallback(()=>O(D=>D-1),[]),children:g.jsx(ct.div,{tabIndex:w||A===0?-1:0,"data-orientation":r,...h,ref:m,style:{outline:"none",...n.style},onMouseDown:Re(n.onMouseDown,()=>{_.current=!0}),onFocus:Re(n.onFocus,D=>{const F=!_.current;if(D.target===D.currentTarget&&F&&!w){const U=new CustomEvent(kP,_he);if(D.currentTarget.dispatchEvent(U),!U.defaultPrevented){const V=E().filter(G=>G.focusable),Y=V.find(G=>G.active),j=V.find(G=>G.id===v),z=[Y,j,...V].filter(Boolean).map(G=>G.ref.current);UU(z,u)}}_.current=!1}),onBlur:Re(n.onBlur,()=>C(!1))})})}),BU="RovingFocusGroupItem",$U=k.forwardRef((n,e)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:s=!1,tabStopId:o,children:i,...a}=n,l=Ba(),c=o||l,u=Rhe(BU,t),h=u.currentTabStopId===c,p=FU(t),{onFocusableItemAdd:m,onFocusableItemRemove:S,currentTabStopId:v}=u;return k.useEffect(()=>{if(r)return m(),()=>S()},[r,m,S]),g.jsx(bE.ItemSlot,{scope:t,id:c,focusable:r,active:s,children:g.jsx(ct.span,{tabIndex:h?0:-1,"data-orientation":u.orientation,...a,ref:e,onMouseDown:Re(n.onMouseDown,y=>{r?u.onItemFocus(c):y.preventDefault()}),onFocus:Re(n.onFocus,()=>u.onItemFocus(c)),onKeyDown:Re(n.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){u.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const w=Nhe(y,u.orientation,u.dir);if(w!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let T=p().filter(E=>E.focusable).map(E=>E.ref.current);if(w==="last")T.reverse();else if(w==="prev"||w==="next"){w==="prev"&&T.reverse();const E=T.indexOf(y.currentTarget);T=u.loop?Fhe(T,E+1):T.slice(E+1)}setTimeout(()=>UU(T))}}),children:typeof i=="function"?i({isCurrentTabStop:h,hasTabStop:v!=null}):i})})});$U.displayName=BU;var jhe={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Lhe(n,e){return e!=="rtl"?n:n==="ArrowLeft"?"ArrowRight":n==="ArrowRight"?"ArrowLeft":n}function Nhe(n,e,t){const r=Lhe(n.key,t);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return jhe[r]}function UU(n,e=!1){const t=document.activeElement;for(const r of n)if(r===t||(r.focus({preventScroll:e}),document.activeElement!==t))return}function Fhe(n,e){return n.map((t,r)=>n[(e+r)%n.length])}var f_=zU,cv=$U,CE=["Enter"," "],zhe=["ArrowDown","PageUp","Home"],HU=["ArrowUp","PageDown","End"],Bhe=[...zhe,...HU],$he={ltr:[...CE,"ArrowRight"],rtl:[...CE,"ArrowLeft"]},Uhe={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Ng="Menu",[Zp,Hhe,Khe]=ev(Ng),[ju,uv]=Ho(Ng,[Khe,lv,Nh]),Fg=lv(),KU=Nh(),[WU,yc]=ju(Ng),[Whe,zg]=ju(Ng),VU=n=>{const{__scopeMenu:e,open:t=!1,children:r,dir:s,onOpenChange:o,modal:i=!0}=n,a=Fg(e),[l,c]=k.useState(null),u=k.useRef(!1),h=is(o),p=Og(s);return k.useEffect(()=>{const m=()=>{u.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>u.current=!1;return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),g.jsx(d_,{...a,children:g.jsx(WU,{scope:e,open:t,onOpenChange:h,content:l,onContentChange:c,children:g.jsx(Whe,{scope:e,onClose:k.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};VU.displayName=Ng;var Vhe="MenuAnchor",p_=k.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=Fg(t);return g.jsx(h_,{...s,...r,ref:e})});p_.displayName=Vhe;var g_="MenuPortal",[Ghe,GU]=ju(g_,{forceMount:void 0}),qU=n=>{const{__scopeMenu:e,forceMount:t,children:r,container:s}=n,o=yc(g_,e);return g.jsx(Ghe,{scope:e,forceMount:t,children:g.jsx(wi,{present:t||o.open,children:g.jsx(Dg,{asChild:!0,container:s,children:r})})})};qU.displayName=g_;var No="MenuContent",[qhe,m_]=ju(No),YU=k.forwardRef((n,e)=>{const t=GU(No,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,o=yc(No,n.__scopeMenu),i=zg(No,n.__scopeMenu);return g.jsx(Zp.Provider,{scope:n.__scopeMenu,children:g.jsx(wi,{present:r||o.open,children:g.jsx(Zp.Slot,{scope:n.__scopeMenu,children:i.modal?g.jsx(Yhe,{...s,ref:e}):g.jsx(Xhe,{...s,ref:e})})})})}),Yhe=k.forwardRef((n,e)=>{const t=yc(No,n.__scopeMenu),r=k.useRef(null),s=Ht(e,r);return k.useEffect(()=>{const o=r.current;if(o)return JT(o)},[]),g.jsx(y_,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:Re(n.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),Xhe=k.forwardRef((n,e)=>{const t=yc(No,n.__scopeMenu);return g.jsx(y_,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),Zhe=ph("MenuContent.ScrollLock"),y_=k.forwardRef((n,e)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:m,disableOutsideScroll:S,...v}=n,y=yc(No,t),w=zg(No,t),C=Fg(t),T=KU(t),E=Hhe(t),[_,A]=k.useState(null),O=k.useRef(null),D=Ht(e,O,y.onContentChange),F=k.useRef(0),U=k.useRef(""),V=k.useRef(0),Y=k.useRef(null),j=k.useRef("right"),N=k.useRef(0),z=S?rv:k.Fragment,G=S?{as:Zhe,allowPinchZoom:!0}:void 0,q=K=>{var ze,ve;const J=U.current+K,H=E().filter(Te=>!Te.disabled),te=document.activeElement,he=(ze=H.find(Te=>Te.ref.current===te))==null?void 0:ze.textValue,Pe=H.map(Te=>Te.textValue),ue=cfe(Pe,J,he),Ae=(ve=H.find(Te=>Te.textValue===ue))==null?void 0:ve.ref.current;(function Te(je){U.current=je,window.clearTimeout(F.current),je!==""&&(F.current=window.setTimeout(()=>Te(""),1e3))})(J),Ae&&setTimeout(()=>Ae.focus())};k.useEffect(()=>()=>window.clearTimeout(F.current),[]),ZT();const $=k.useCallback(K=>{var H,te;return j.current===((H=Y.current)==null?void 0:H.side)&&dfe(K,(te=Y.current)==null?void 0:te.area)},[]);return g.jsx(qhe,{scope:t,searchRef:U,onItemEnter:k.useCallback(K=>{$(K)&&K.preventDefault()},[$]),onItemLeave:k.useCallback(K=>{var J;$(K)||((J=O.current)==null||J.focus(),A(null))},[$]),onTriggerLeave:k.useCallback(K=>{$(K)&&K.preventDefault()},[$]),pointerGraceTimerRef:V,onPointerGraceIntentChange:k.useCallback(K=>{Y.current=K},[]),children:g.jsx(z,{...G,children:g.jsx(tv,{asChild:!0,trapped:s,onMountAutoFocus:Re(o,K=>{var J;K.preventDefault(),(J=O.current)==null||J.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:g.jsx(Rg,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:m,children:g.jsx(f_,{asChild:!0,...T,dir:w.dir,orientation:"vertical",loop:r,currentTabStopId:_,onCurrentTabStopIdChange:A,onEntryFocus:Re(l,K=>{w.isUsingKeyboardRef.current||K.preventDefault()}),preventScrollOnEntryFocus:!0,children:g.jsx(LU,{role:"menu","aria-orientation":"vertical","data-state":h9(y.open),"data-radix-menu-content":"",dir:w.dir,...C,...v,ref:D,style:{outline:"none",...v.style},onKeyDown:Re(v.onKeyDown,K=>{const H=K.target.closest("[data-radix-menu-content]")===K.currentTarget,te=K.ctrlKey||K.altKey||K.metaKey,he=K.key.length===1;H&&(K.key==="Tab"&&K.preventDefault(),!te&&he&&q(K.key));const Pe=O.current;if(K.target!==Pe||!Bhe.includes(K.key))return;K.preventDefault();const Ae=E().filter(ze=>!ze.disabled).map(ze=>ze.ref.current);HU.includes(K.key)&&Ae.reverse(),afe(Ae)}),onBlur:Re(n.onBlur,K=>{K.currentTarget.contains(K.target)||(window.clearTimeout(F.current),U.current="")}),onPointerMove:Re(n.onPointerMove,Jp(K=>{const J=K.target,H=N.current!==K.clientX;if(K.currentTarget.contains(J)&&H){const te=K.clientX>N.current?"right":"left";j.current=te,N.current=K.clientX}}))})})})})})})});YU.displayName=No;var Jhe="MenuGroup",S_=k.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return g.jsx(ct.div,{role:"group",...r,ref:e})});S_.displayName=Jhe;var Qhe="MenuLabel",XU=k.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return g.jsx(ct.div,{...r,ref:e})});XU.displayName=Qhe;var px="MenuItem",mN="menu.itemSelect",dv=k.forwardRef((n,e)=>{const{disabled:t=!1,onSelect:r,...s}=n,o=k.useRef(null),i=zg(px,n.__scopeMenu),a=m_(px,n.__scopeMenu),l=Ht(e,o),c=k.useRef(!1),u=()=>{const h=o.current;if(!t&&h){const p=new CustomEvent(mN,{bubbles:!0,cancelable:!0});h.addEventListener(mN,m=>r==null?void 0:r(m),{once:!0}),YT(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return g.jsx(ZU,{...s,ref:l,disabled:t,onClick:Re(n.onClick,u),onPointerDown:h=>{var p;(p=n.onPointerDown)==null||p.call(n,h),c.current=!0},onPointerUp:Re(n.onPointerUp,h=>{var p;c.current||(p=h.currentTarget)==null||p.click()}),onKeyDown:Re(n.onKeyDown,h=>{const p=a.searchRef.current!=="";t||p&&h.key===" "||CE.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});dv.displayName=px;var ZU=k.forwardRef((n,e)=>{const{__scopeMenu:t,disabled:r=!1,textValue:s,...o}=n,i=m_(px,t),a=KU(t),l=k.useRef(null),c=Ht(e,l),[u,h]=k.useState(!1),[p,m]=k.useState("");return k.useEffect(()=>{const S=l.current;S&&m((S.textContent??"").trim())},[o.children]),g.jsx(Zp.ItemSlot,{scope:t,disabled:r,textValue:s??p,children:g.jsx(cv,{asChild:!0,...a,focusable:!r,children:g.jsx(ct.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...o,ref:c,onPointerMove:Re(n.onPointerMove,Jp(S=>{r?i.onItemLeave(S):(i.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Re(n.onPointerLeave,Jp(S=>i.onItemLeave(S))),onFocus:Re(n.onFocus,()=>h(!0)),onBlur:Re(n.onBlur,()=>h(!1))})})})}),efe="MenuCheckboxItem",JU=k.forwardRef((n,e)=>{const{checked:t=!1,onCheckedChange:r,...s}=n;return g.jsx(r9,{scope:n.__scopeMenu,checked:t,children:g.jsx(dv,{role:"menuitemcheckbox","aria-checked":gx(t)?"mixed":t,...s,ref:e,"data-state":w_(t),onSelect:Re(s.onSelect,()=>r==null?void 0:r(gx(t)?!0:!t),{checkForDefaultPrevented:!1})})})});JU.displayName=efe;var QU="MenuRadioGroup",[tfe,nfe]=ju(QU,{value:void 0,onValueChange:()=>{}}),e9=k.forwardRef((n,e)=>{const{value:t,onValueChange:r,...s}=n,o=is(r);return g.jsx(tfe,{scope:n.__scopeMenu,value:t,onValueChange:o,children:g.jsx(S_,{...s,ref:e})})});e9.displayName=QU;var t9="MenuRadioItem",n9=k.forwardRef((n,e)=>{const{value:t,...r}=n,s=nfe(t9,n.__scopeMenu),o=t===s.value;return g.jsx(r9,{scope:n.__scopeMenu,checked:o,children:g.jsx(dv,{role:"menuitemradio","aria-checked":o,...r,ref:e,"data-state":w_(o),onSelect:Re(r.onSelect,()=>{var i;return(i=s.onValueChange)==null?void 0:i.call(s,t)},{checkForDefaultPrevented:!1})})})});n9.displayName=t9;var x_="MenuItemIndicator",[r9,rfe]=ju(x_,{checked:!1}),s9=k.forwardRef((n,e)=>{const{__scopeMenu:t,forceMount:r,...s}=n,o=rfe(x_,t);return g.jsx(wi,{present:r||gx(o.checked)||o.checked===!0,children:g.jsx(ct.span,{...s,ref:e,"data-state":w_(o.checked)})})});s9.displayName=x_;var sfe="MenuSeparator",o9=k.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n;return g.jsx(ct.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});o9.displayName=sfe;var ofe="MenuArrow",i9=k.forwardRef((n,e)=>{const{__scopeMenu:t,...r}=n,s=Fg(t);return g.jsx(NU,{...s,...r,ref:e})});i9.displayName=ofe;var v_="MenuSub",[ife,a9]=ju(v_),l9=n=>{const{__scopeMenu:e,children:t,open:r=!1,onOpenChange:s}=n,o=yc(v_,e),i=Fg(e),[a,l]=k.useState(null),[c,u]=k.useState(null),h=is(s);return k.useEffect(()=>(o.open===!1&&h(!1),()=>h(!1)),[o.open,h]),g.jsx(d_,{...i,children:g.jsx(WU,{scope:e,open:r,onOpenChange:h,content:c,onContentChange:u,children:g.jsx(ife,{scope:e,contentId:Ba(),triggerId:Ba(),trigger:a,onTriggerChange:l,children:t})})})};l9.displayName=v_;var Zf="MenuSubTrigger",c9=k.forwardRef((n,e)=>{const t=yc(Zf,n.__scopeMenu),r=zg(Zf,n.__scopeMenu),s=a9(Zf,n.__scopeMenu),o=m_(Zf,n.__scopeMenu),i=k.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=o,c={__scopeMenu:n.__scopeMenu},u=k.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return k.useEffect(()=>u,[u]),k.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),g.jsx(p_,{asChild:!0,...c,children:g.jsx(ZU,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":s.contentId,"data-state":h9(t.open),...n,ref:Q0(e,s.onTriggerChange),onClick:h=>{var p;(p=n.onClick)==null||p.call(n,h),!(n.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:Re(n.onPointerMove,Jp(h=>{o.onItemEnter(h),!h.defaultPrevented&&!n.disabled&&!t.open&&!i.current&&(o.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:Re(n.onPointerLeave,Jp(h=>{var m,S;u();const p=(m=t.content)==null?void 0:m.getBoundingClientRect();if(p){const v=(S=t.content)==null?void 0:S.dataset.side,y=v==="right",w=y?-5:5,C=p[y?"left":"right"],T=p[y?"right":"left"];o.onPointerGraceIntentChange({area:[{x:h.clientX+w,y:h.clientY},{x:C,y:p.top},{x:T,y:p.top},{x:T,y:p.bottom},{x:C,y:p.bottom}],side:v}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>o.onPointerGraceIntentChange(null),300)}else{if(o.onTriggerLeave(h),h.defaultPrevented)return;o.onPointerGraceIntentChange(null)}})),onKeyDown:Re(n.onKeyDown,h=>{var m;const p=o.searchRef.current!=="";n.disabled||p&&h.key===" "||$he[r.dir].includes(h.key)&&(t.onOpenChange(!0),(m=t.content)==null||m.focus(),h.preventDefault())})})})});c9.displayName=Zf;var u9="MenuSubContent",d9=k.forwardRef((n,e)=>{const t=GU(No,n.__scopeMenu),{forceMount:r=t.forceMount,...s}=n,o=yc(No,n.__scopeMenu),i=zg(No,n.__scopeMenu),a=a9(u9,n.__scopeMenu),l=k.useRef(null),c=Ht(e,l);return g.jsx(Zp.Provider,{scope:n.__scopeMenu,children:g.jsx(wi,{present:r||o.open,children:g.jsx(Zp.Slot,{scope:n.__scopeMenu,children:g.jsx(y_,{id:a.contentId,"aria-labelledby":a.triggerId,...s,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:Re(n.onFocusOutside,u=>{u.target!==a.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Re(n.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:Re(n.onKeyDown,u=>{var m;const h=u.currentTarget.contains(u.target),p=Uhe[i.dir].includes(u.key);h&&p&&(o.onOpenChange(!1),(m=a.trigger)==null||m.focus(),u.preventDefault())})})})})})});d9.displayName=u9;function h9(n){return n?"open":"closed"}function gx(n){return n==="indeterminate"}function w_(n){return gx(n)?"indeterminate":n?"checked":"unchecked"}function afe(n){const e=document.activeElement;for(const t of n)if(t===e||(t.focus(),document.activeElement!==e))return}function lfe(n,e){return n.map((t,r)=>n[(e+r)%n.length])}function cfe(n,e,t){const s=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,o=t?n.indexOf(t):-1;let i=lfe(n,Math.max(o,0));s.length===1&&(i=i.filter(c=>c!==t));const l=i.find(c=>c.toLowerCase().startsWith(s.toLowerCase()));return l!==t?l:void 0}function ufe(n,e){const{x:t,y:r}=n;let s=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const a=e[o],l=e[i],c=a.x,u=a.y,h=l.x,p=l.y;u>r!=p>r&&t<(h-c)*(r-u)/(p-u)+c&&(s=!s)}return s}function dfe(n,e){if(!e)return!1;const t={x:n.clientX,y:n.clientY};return ufe(t,e)}function Jp(n){return e=>e.pointerType==="mouse"?n(e):void 0}var f9=VU,p9=p_,g9=qU,m9=YU,y9=S_,S9=XU,x9=dv,v9=JU,w9=e9,b9=n9,C9=s9,P9=o9,k9=i9,E9=l9,I9=c9,T9=d9,b_="ContextMenu",[hfe,wPe]=Ho(b_,[uv]),Br=uv(),[ffe,_9]=hfe(b_),M9=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,dir:s,modal:o=!0}=n,[i,a]=k.useState(!1),l=Br(e),c=is(r),u=k.useCallback(h=>{a(h),c(h)},[c]);return g.jsx(ffe,{scope:e,open:i,onOpenChange:u,modal:o,children:g.jsx(f9,{...l,dir:s,open:i,onOpenChange:u,modal:o,children:t})})};M9.displayName=b_;var A9="ContextMenuTrigger",O9=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,disabled:r=!1,...s}=n,o=_9(A9,t),i=Br(t),a=k.useRef({x:0,y:0}),l=k.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=k.useRef(0),u=k.useCallback(()=>window.clearTimeout(c.current),[]),h=p=>{a.current={x:p.clientX,y:p.clientY},o.onOpenChange(!0)};return k.useEffect(()=>u,[u]),k.useEffect(()=>void(r&&u()),[r,u]),g.jsxs(g.Fragment,{children:[g.jsx(p9,{...i,virtualRef:l}),g.jsx(ct.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...s,ref:e,style:{WebkitTouchCallout:"none",...n.style},onContextMenu:r?n.onContextMenu:Re(n.onContextMenu,p=>{u(),h(p),p.preventDefault()}),onPointerDown:r?n.onPointerDown:Re(n.onPointerDown,xy(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?n.onPointerMove:Re(n.onPointerMove,xy(u)),onPointerCancel:r?n.onPointerCancel:Re(n.onPointerCancel,xy(u)),onPointerUp:r?n.onPointerUp:Re(n.onPointerUp,xy(u))})]})});O9.displayName=A9;var pfe="ContextMenuPortal",C_=n=>{const{__scopeContextMenu:e,...t}=n,r=Br(e);return g.jsx(g9,{...r,...t})};C_.displayName=pfe;var R9="ContextMenuContent",D9=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=_9(R9,t),o=Br(t),i=k.useRef(!1);return g.jsx(m9,{...o,...r,ref:e,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=n.onCloseAutoFocus)==null||l.call(n,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=n.onInteractOutside)==null||l.call(n,a),!a.defaultPrevented&&!s.modal&&(i.current=!0)},style:{...n.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});D9.displayName=R9;var gfe="ContextMenuGroup",mfe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(y9,{...s,...r,ref:e})});mfe.displayName=gfe;var yfe="ContextMenuLabel",Sfe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(S9,{...s,...r,ref:e})});Sfe.displayName=yfe;var xfe="ContextMenuItem",j9=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(x9,{...s,...r,ref:e})});j9.displayName=xfe;var vfe="ContextMenuCheckboxItem",L9=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(v9,{...s,...r,ref:e})});L9.displayName=vfe;var wfe="ContextMenuRadioGroup",bfe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(w9,{...s,...r,ref:e})});bfe.displayName=wfe;var Cfe="ContextMenuRadioItem",Pfe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(b9,{...s,...r,ref:e})});Pfe.displayName=Cfe;var kfe="ContextMenuItemIndicator",Efe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(C9,{...s,...r,ref:e})});Efe.displayName=kfe;var Ife="ContextMenuSeparator",Tfe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(P9,{...s,...r,ref:e})});Tfe.displayName=Ife;var _fe="ContextMenuArrow",Mfe=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(k9,{...s,...r,ref:e})});Mfe.displayName=_fe;var N9="ContextMenuSub",F9=n=>{const{__scopeContextMenu:e,children:t,onOpenChange:r,open:s,defaultOpen:o}=n,i=Br(e),[a,l]=vi({prop:s,defaultProp:o??!1,onChange:r,caller:N9});return g.jsx(E9,{...i,open:a,onOpenChange:l,children:t})};F9.displayName=N9;var Afe="ContextMenuSubTrigger",z9=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(I9,{...s,...r,ref:e})});z9.displayName=Afe;var Ofe="ContextMenuSubContent",B9=k.forwardRef((n,e)=>{const{__scopeContextMenu:t,...r}=n,s=Br(t);return g.jsx(T9,{...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)"}})});B9.displayName=Ofe;function xy(n){return e=>e.pointerType!=="mouse"?n(e):void 0}var Rfe=M9,Dfe=O9,jfe=C_,Lfe=D9,Nfe=j9,Ffe=L9,hv="DropdownMenu",[zfe,bPe]=Ho(hv,[uv]),$r=uv(),[Bfe,$9]=zfe(hv),U9=n=>{const{__scopeDropdownMenu:e,children:t,dir:r,open:s,defaultOpen:o,onOpenChange:i,modal:a=!0}=n,l=$r(e),c=k.useRef(null),[u,h]=vi({prop:s,defaultProp:o??!1,onChange:i,caller:hv});return g.jsx(Bfe,{scope:e,triggerId:Ba(),triggerRef:c,contentId:Ba(),open:u,onOpenChange:h,onOpenToggle:k.useCallback(()=>h(p=>!p),[h]),modal:a,children:g.jsx(f9,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:t})})};U9.displayName=hv;var H9="DropdownMenuTrigger",K9=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...s}=n,o=$9(H9,t),i=$r(t);return g.jsx(p9,{asChild:!0,...i,children:g.jsx(ct.button,{type:"button",id:o.triggerId,"aria-haspopup":"menu","aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...s,ref:Q0(e,o.triggerRef),onPointerDown:Re(n.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(o.onOpenToggle(),o.open||a.preventDefault())}),onKeyDown:Re(n.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&o.onOpenToggle(),a.key==="ArrowDown"&&o.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});K9.displayName=H9;var $fe="DropdownMenuPortal",W9=n=>{const{__scopeDropdownMenu:e,...t}=n,r=$r(e);return g.jsx(g9,{...r,...t})};W9.displayName=$fe;var V9="DropdownMenuContent",G9=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$9(V9,t),o=$r(t),i=k.useRef(!1);return g.jsx(m9,{id:s.contentId,"aria-labelledby":s.triggerId,...o,...r,ref:e,onCloseAutoFocus:Re(n.onCloseAutoFocus,a=>{var l;i.current||(l=s.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:Re(n.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!s.modal||u)&&(i.current=!0)}),style:{...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)"}})});G9.displayName=V9;var Ufe="DropdownMenuGroup",Hfe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(y9,{...s,...r,ref:e})});Hfe.displayName=Ufe;var Kfe="DropdownMenuLabel",Wfe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(S9,{...s,...r,ref:e})});Wfe.displayName=Kfe;var Vfe="DropdownMenuItem",q9=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(x9,{...s,...r,ref:e})});q9.displayName=Vfe;var Gfe="DropdownMenuCheckboxItem",Y9=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(v9,{...s,...r,ref:e})});Y9.displayName=Gfe;var qfe="DropdownMenuRadioGroup",Yfe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(w9,{...s,...r,ref:e})});Yfe.displayName=qfe;var Xfe="DropdownMenuRadioItem",Zfe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(b9,{...s,...r,ref:e})});Zfe.displayName=Xfe;var Jfe="DropdownMenuItemIndicator",Qfe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(C9,{...s,...r,ref:e})});Qfe.displayName=Jfe;var epe="DropdownMenuSeparator",tpe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(P9,{...s,...r,ref:e})});tpe.displayName=epe;var npe="DropdownMenuArrow",rpe=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(k9,{...s,...r,ref:e})});rpe.displayName=npe;var spe=n=>{const{__scopeDropdownMenu:e,children:t,open:r,onOpenChange:s,defaultOpen:o}=n,i=$r(e),[a,l]=vi({prop:r,defaultProp:o??!1,onChange:s,caller:"DropdownMenuSub"});return g.jsx(E9,{...i,open:a,onOpenChange:l,children:t})},ope="DropdownMenuSubTrigger",X9=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(I9,{...s,...r,ref:e})});X9.displayName=ope;var ipe="DropdownMenuSubContent",Z9=k.forwardRef((n,e)=>{const{__scopeDropdownMenu:t,...r}=n,s=$r(t);return g.jsx(T9,{...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)"}})});Z9.displayName=ipe;var P_=U9,k_=K9,fv=W9,E_=G9,ape=q9,lpe=Y9,cpe=spe,upe=X9,dpe=Z9;function J9(n,[e,t]){return Math.min(t,Math.max(e,n))}var pv="Popover",[Q9,CPe]=Ho(pv,[lv]),Bg=lv(),[hpe,Sc]=Q9(pv),e7=n=>{const{__scopePopover:e,children:t,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=n,a=Bg(e),l=k.useRef(null),[c,u]=k.useState(!1),[h,p]=vi({prop:r,defaultProp:s??!1,onChange:o,caller:pv});return g.jsx(d_,{...a,children:g.jsx(hpe,{scope:e,contentId:Ba(),triggerRef:l,open:h,onOpenChange:p,onOpenToggle:k.useCallback(()=>p(m=>!m),[p]),hasCustomAnchor:c,onCustomAnchorAdd:k.useCallback(()=>u(!0),[]),onCustomAnchorRemove:k.useCallback(()=>u(!1),[]),modal:i,children:t})})};e7.displayName=pv;var t7="PopoverAnchor",fpe=k.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Sc(t7,t),o=Bg(t),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=s;return k.useEffect(()=>(i(),()=>a()),[i,a]),g.jsx(h_,{...o,...r,ref:e})});fpe.displayName=t7;var n7="PopoverTrigger",r7=k.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Sc(n7,t),o=Bg(t),i=Ht(e,s.triggerRef),a=g.jsx(ct.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":l7(s.open),...r,ref:i,onClick:Re(n.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:g.jsx(h_,{asChild:!0,...o,children:a})});r7.displayName=n7;var I_="PopoverPortal",[ppe,gpe]=Q9(I_,{forceMount:void 0}),s7=n=>{const{__scopePopover:e,forceMount:t,children:r,container:s}=n,o=Sc(I_,e);return g.jsx(ppe,{scope:e,forceMount:t,children:g.jsx(wi,{present:t||o.open,children:g.jsx(Dg,{asChild:!0,container:s,children:r})})})};s7.displayName=I_;var mh="PopoverContent",o7=k.forwardRef((n,e)=>{const t=gpe(mh,n.__scopePopover),{forceMount:r=t.forceMount,...s}=n,o=Sc(mh,n.__scopePopover);return g.jsx(wi,{present:r||o.open,children:o.modal?g.jsx(ype,{...s,ref:e}):g.jsx(Spe,{...s,ref:e})})});o7.displayName=mh;var mpe=ph("PopoverContent.RemoveScroll"),ype=k.forwardRef((n,e)=>{const t=Sc(mh,n.__scopePopover),r=k.useRef(null),s=Ht(e,r),o=k.useRef(!1);return k.useEffect(()=>{const i=r.current;if(i)return JT(i)},[]),g.jsx(rv,{as:mpe,allowPinchZoom:!0,children:g.jsx(i7,{...n,ref:s,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Re(n.onCloseAutoFocus,i=>{var a;i.preventDefault(),o.current||(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:Re(n.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;o.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:Re(n.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),Spe=k.forwardRef((n,e)=>{const t=Sc(mh,n.__scopePopover),r=k.useRef(!1),s=k.useRef(!1);return g.jsx(i7,{...n,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=n.onCloseAutoFocus)==null||i.call(n,o),o.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=n.onInteractOutside)==null||l.call(n,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=t.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),i7=k.forwardRef((n,e)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=n,p=Sc(mh,t),m=Bg(t);return ZT(),g.jsx(tv,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:g.jsx(Rg,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:g.jsx(LU,{"data-state":l7(p.open),role:"dialog",id:p.contentId,...m,...h,ref:e,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),a7="PopoverClose",xpe=k.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Sc(a7,t);return g.jsx(ct.button,{type:"button",...r,ref:e,onClick:Re(n.onClick,()=>s.onOpenChange(!1))})});xpe.displayName=a7;var vpe="PopoverArrow",wpe=k.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,s=Bg(t);return g.jsx(NU,{...s,...r,ref:e})});wpe.displayName=vpe;function l7(n){return n?"open":"closed"}var T_=e7,__=r7,M_=s7,A_=o7,bpe="Separator",yN="horizontal",Cpe=["horizontal","vertical"],c7=k.forwardRef((n,e)=>{const{decorative:t,orientation:r=yN,...s}=n,o=Ppe(r)?r:yN,a=t?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return g.jsx(ct.div,{"data-orientation":o,...a,...s,ref:e})});c7.displayName=bpe;function Ppe(n){return Cpe.includes(n)}var kpe=c7,u7=["PageUp","PageDown"],d7=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],h7={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Fh="Slider",[PE,Epe,Ipe]=ev(Fh),[f7,PPe]=Ho(Fh,[Ipe]),[Tpe,gv]=f7(Fh),p7=k.forwardRef((n,e)=>{const{name:t,min:r=0,max:s=100,step:o=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:p=()=>{},inverted:m=!1,form:S,...v}=n,y=k.useRef(new Set),w=k.useRef(0),T=i==="horizontal"?_pe:Mpe,[E=[],_]=vi({prop:u,defaultProp:c,onChange:V=>{var j;(j=[...y.current][w.current])==null||j.focus(),h(V)}}),A=k.useRef(E);function O(V){const Y=jpe(E,V);U(V,Y)}function D(V){U(V,w.current)}function F(){const V=A.current[w.current];E[w.current]!==V&&p(E)}function U(V,Y,{commit:j}={commit:!1}){const N=zpe(o),z=Bpe(Math.round((V-r)/o)*o+r,N),G=J9(z,[r,s]);_((q=[])=>{const $=Rpe(q,G,Y);if(Fpe($,l*o)){w.current=$.indexOf(G);const K=String($)!==String(q);return K&&j&&p($),K?$:q}else return q})}return g.jsx(Tpe,{scope:n.__scopeSlider,name:t,disabled:a,min:r,max:s,valueIndexToChangeRef:w,thumbs:y.current,values:E,orientation:i,form:S,children:g.jsx(PE.Provider,{scope:n.__scopeSlider,children:g.jsx(PE.Slot,{scope:n.__scopeSlider,children:g.jsx(T,{"aria-disabled":a,"data-disabled":a?"":void 0,...v,ref:e,onPointerDown:Re(v.onPointerDown,()=>{a||(A.current=E)}),min:r,max:s,inverted:m,onSlideStart:a?void 0:O,onSlideMove:a?void 0:D,onSlideEnd:a?void 0:F,onHomeKeyDown:()=>!a&&U(r,0,{commit:!0}),onEndKeyDown:()=>!a&&U(s,E.length-1,{commit:!0}),onStepKeyDown:({event:V,direction:Y})=>{if(!a){const z=u7.includes(V.key)||V.shiftKey&&d7.includes(V.key)?10:1,G=w.current,q=E[G],$=o*z*Y;U(q+$,G,{commit:!0})}}})})})})});p7.displayName=Fh;var[g7,m7]=f7(Fh,{startEdge:"left",endEdge:"right",size:"width",direction:1}),_pe=k.forwardRef((n,e)=>{const{min:t,max:r,dir:s,inverted:o,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=n,[h,p]=k.useState(null),m=Ht(e,T=>p(T)),S=k.useRef(void 0),v=Og(s),y=v==="ltr",w=y&&!o||!y&&o;function C(T){const E=S.current||h.getBoundingClientRect(),_=[0,E.width],O=O_(_,w?[t,r]:[r,t]);return S.current=E,O(T-E.left)}return g.jsx(g7,{scope:n.__scopeSlider,startEdge:w?"left":"right",endEdge:w?"right":"left",direction:w?1:-1,size:"width",children:g.jsx(y7,{dir:v,"data-orientation":"horizontal",...u,ref:m,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:T=>{const E=C(T.clientX);i==null||i(E)},onSlideMove:T=>{const E=C(T.clientX);a==null||a(E)},onSlideEnd:()=>{S.current=void 0,l==null||l()},onStepKeyDown:T=>{const _=h7[w?"from-left":"from-right"].includes(T.key);c==null||c({event:T,direction:_?-1:1})}})})}),Mpe=k.forwardRef((n,e)=>{const{min:t,max:r,inverted:s,onSlideStart:o,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=n,u=k.useRef(null),h=Ht(e,u),p=k.useRef(void 0),m=!s;function S(v){const y=p.current||u.current.getBoundingClientRect(),w=[0,y.height],T=O_(w,m?[r,t]:[t,r]);return p.current=y,T(v-y.top)}return g.jsx(g7,{scope:n.__scopeSlider,startEdge:m?"bottom":"top",endEdge:m?"top":"bottom",size:"height",direction:m?1:-1,children:g.jsx(y7,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:v=>{const y=S(v.clientY);o==null||o(y)},onSlideMove:v=>{const y=S(v.clientY);i==null||i(y)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:v=>{const w=h7[m?"from-bottom":"from-top"].includes(v.key);l==null||l({event:v,direction:w?-1:1})}})})}),y7=k.forwardRef((n,e)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:s,onSlideEnd:o,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=n,u=gv(Fh,t);return g.jsx(ct.span,{...c,ref:e,onKeyDown:Re(n.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):u7.concat(d7).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:Re(n.onPointerDown,h=>{const p=h.target;p.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(p)?p.focus():r(h)}),onPointerMove:Re(n.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&s(h)}),onPointerUp:Re(n.onPointerUp,h=>{const p=h.target;p.hasPointerCapture(h.pointerId)&&(p.releasePointerCapture(h.pointerId),o(h))})})}),S7="SliderTrack",x7=k.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=gv(S7,t);return g.jsx(ct.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});x7.displayName=S7;var kE="SliderRange",v7=k.forwardRef((n,e)=>{const{__scopeSlider:t,...r}=n,s=gv(kE,t),o=m7(kE,t),i=k.useRef(null),a=Ht(e,i),l=s.values.length,c=s.values.map(p=>C7(p,s.min,s.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return g.jsx(ct.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...n.style,[o.startEdge]:u+"%",[o.endEdge]:h+"%"}})});v7.displayName=kE;var EE="SliderThumb",w7=k.forwardRef((n,e)=>{const t=Epe(n.__scopeSlider),[r,s]=k.useState(null),o=Ht(e,a=>s(a)),i=k.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return g.jsx(Ape,{...n,ref:o,index:i})}),Ape=k.forwardRef((n,e)=>{const{__scopeSlider:t,index:r,name:s,...o}=n,i=gv(EE,t),a=m7(EE,t),[l,c]=k.useState(null),u=Ht(e,C=>c(C)),h=l?i.form||!!l.closest("form"):!0,p=gU(l),m=i.values[r],S=m===void 0?0:C7(m,i.min,i.max),v=Dpe(r,i.values.length),y=p==null?void 0:p[a.size],w=y?Lpe(y,S,a.direction):0;return k.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),g.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${S}% + ${w}px)`},children:[g.jsx(PE.ItemSlot,{scope:n.__scopeSlider,children:g.jsx(ct.span,{role:"slider","aria-label":n["aria-label"]||v,"aria-valuemin":i.min,"aria-valuenow":m,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...o,ref:u,style:m===void 0?{display:"none"}:n.style,onFocus:Re(n.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&g.jsx(b7,{name:s??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:m},r)]})});w7.displayName=EE;var Ope="RadioBubbleInput",b7=k.forwardRef(({__scopeSlider:n,value:e,...t},r)=>{const s=k.useRef(null),o=Ht(s,r),i=Cde(e);return k.useEffect(()=>{const a=s.current;if(!a)return;const l=window.HTMLInputElement.prototype,u=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==e&&u){const h=new Event("input",{bubbles:!0});u.call(a,e),a.dispatchEvent(h)}},[i,e]),g.jsx(ct.input,{style:{display:"none"},...t,ref:o,defaultValue:e})});b7.displayName=Ope;function Rpe(n=[],e,t){const r=[...n];return r[t]=e,r.sort((s,o)=>s-o)}function C7(n,e,t){const o=100/(t-e)*(n-e);return J9(o,[0,100])}function Dpe(n,e){return e>2?`Value ${n+1} of ${e}`:e===2?["Minimum","Maximum"][n]:void 0}function jpe(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 Lpe(n,e,t){const r=n/2,o=O_([0,50],[0,r]);return(r-o(e)*t)*t}function Npe(n){return n.slice(0,-1).map((e,t)=>n[t+1]-e)}function Fpe(n,e){if(e>0){const t=Npe(n);return Math.min(...t)>=e}return!0}function O_(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 zpe(n){return(String(n).split(".")[1]||"").length}function Bpe(n,e){const t=Math.pow(10,e);return Math.round(n*t)/t}var $pe=p7,Upe=x7,Hpe=v7,Kpe=w7,R_="ToastProvider",[D_,Wpe,Vpe]=ev("Toast"),[P7,kPe]=Ho("Toast",[Vpe]),[Gpe,mv]=P7(R_),k7=n=>{const{__scopeToast:e,label:t="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:o=50,children:i}=n,[a,l]=k.useState(null),[c,u]=k.useState(0),h=k.useRef(!1),p=k.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${R_}\`. Expected non-empty \`string\`.`),g.jsx(D_.Provider,{scope:e,children:g.jsx(Gpe,{scope:e,label:t,duration:r,swipeDirection:s,swipeThreshold:o,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:k.useCallback(()=>u(m=>m+1),[]),onToastRemove:k.useCallback(()=>u(m=>m-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:p,children:i})})};k7.displayName=R_;var E7="ToastViewport",qpe=["F8"],IE="toast.viewportPause",TE="toast.viewportResume",I7=k.forwardRef((n,e)=>{const{__scopeToast:t,hotkey:r=qpe,label:s="Notifications ({hotkey})",...o}=n,i=mv(E7,t),a=Wpe(t),l=k.useRef(null),c=k.useRef(null),u=k.useRef(null),h=k.useRef(null),p=Ht(e,h,i.onViewportChange),m=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=i.toastCount>0;k.useEffect(()=>{const y=w=>{var T;r.length!==0&&r.every(E=>w[E]||w.code===E)&&((T=h.current)==null||T.focus())};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[r]),k.useEffect(()=>{const y=l.current,w=h.current;if(S&&y&&w){const C=()=>{if(!i.isClosePausedRef.current){const A=new CustomEvent(IE);w.dispatchEvent(A),i.isClosePausedRef.current=!0}},T=()=>{if(i.isClosePausedRef.current){const A=new CustomEvent(TE);w.dispatchEvent(A),i.isClosePausedRef.current=!1}},E=A=>{!y.contains(A.relatedTarget)&&T()},_=()=>{y.contains(document.activeElement)||T()};return y.addEventListener("focusin",C),y.addEventListener("focusout",E),y.addEventListener("pointermove",C),y.addEventListener("pointerleave",_),window.addEventListener("blur",C),window.addEventListener("focus",T),()=>{y.removeEventListener("focusin",C),y.removeEventListener("focusout",E),y.removeEventListener("pointermove",C),y.removeEventListener("pointerleave",_),window.removeEventListener("blur",C),window.removeEventListener("focus",T)}}},[S,i.isClosePausedRef]);const v=k.useCallback(({tabbingDirection:y})=>{const C=a().map(T=>{const E=T.ref.current,_=[E,...age(E)];return y==="forwards"?_:_.reverse()});return(y==="forwards"?C.reverse():C).flat()},[a]);return k.useEffect(()=>{const y=h.current;if(y){const w=C=>{var _,A,O;const T=C.altKey||C.ctrlKey||C.metaKey;if(C.key==="Tab"&&!T){const D=document.activeElement,F=C.shiftKey;if(C.target===y&&F){(_=c.current)==null||_.focus();return}const Y=v({tabbingDirection:F?"backwards":"forwards"}),j=Y.findIndex(N=>N===D);EP(Y.slice(j+1))?C.preventDefault():F?(A=c.current)==null||A.focus():(O=u.current)==null||O.focus()}};return y.addEventListener("keydown",w),()=>y.removeEventListener("keydown",w)}},[a,v]),g.jsxs(fue,{ref:l,role:"region","aria-label":s.replace("{hotkey}",m),tabIndex:-1,style:{pointerEvents:S?void 0:"none"},children:[S&&g.jsx(_E,{ref:c,onFocusFromOutsideViewport:()=>{const y=v({tabbingDirection:"forwards"});EP(y)}}),g.jsx(D_.Slot,{scope:t,children:g.jsx(ct.ol,{tabIndex:-1,...o,ref:p})}),S&&g.jsx(_E,{ref:u,onFocusFromOutsideViewport:()=>{const y=v({tabbingDirection:"backwards"});EP(y)}})]})});I7.displayName=E7;var T7="ToastFocusProxy",_E=k.forwardRef((n,e)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...s}=n,o=mv(T7,t);return g.jsx(XT,{"aria-hidden":!0,tabIndex:0,...s,ref:e,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=o.viewport)!=null&&c.contains(a))&&r()}})});_E.displayName=T7;var $g="Toast",Ype="toast.swipeStart",Xpe="toast.swipeMove",Zpe="toast.swipeCancel",Jpe="toast.swipeEnd",_7=k.forwardRef((n,e)=>{const{forceMount:t,open:r,defaultOpen:s,onOpenChange:o,...i}=n,[a,l]=vi({prop:r,defaultProp:s??!0,onChange:o,caller:$g});return g.jsx(wi,{present:t||a,children:g.jsx(tge,{open:a,...i,ref:e,onClose:()=>l(!1),onPause:is(n.onPause),onResume:is(n.onResume),onSwipeStart:Re(n.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Re(n.onSwipeMove,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:Re(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:Re(n.onSwipeEnd,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});_7.displayName=$g;var[Qpe,ege]=P7($g,{onClose(){}}),tge=k.forwardRef((n,e)=>{const{__scopeToast:t,type:r="foreground",duration:s,open:o,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:m,...S}=n,v=mv($g,t),[y,w]=k.useState(null),C=Ht(e,N=>w(N)),T=k.useRef(null),E=k.useRef(null),_=s||v.duration,A=k.useRef(0),O=k.useRef(_),D=k.useRef(0),{onToastAdd:F,onToastRemove:U}=v,V=is(()=>{var z;(y==null?void 0:y.contains(document.activeElement))&&((z=v.viewport)==null||z.focus()),i()}),Y=k.useCallback(N=>{!N||N===1/0||(window.clearTimeout(D.current),A.current=new Date().getTime(),D.current=window.setTimeout(V,N))},[V]);k.useEffect(()=>{const N=v.viewport;if(N){const z=()=>{Y(O.current),c==null||c()},G=()=>{const q=new Date().getTime()-A.current;O.current=O.current-q,window.clearTimeout(D.current),l==null||l()};return N.addEventListener(IE,G),N.addEventListener(TE,z),()=>{N.removeEventListener(IE,G),N.removeEventListener(TE,z)}}},[v.viewport,_,l,c,Y]),k.useEffect(()=>{o&&!v.isClosePausedRef.current&&Y(_)},[o,_,v.isClosePausedRef,Y]),k.useEffect(()=>(F(),()=>U()),[F,U]);const j=k.useMemo(()=>y?L7(y):null,[y]);return v.viewport?g.jsxs(g.Fragment,{children:[j&&g.jsx(nge,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:j}),g.jsx(Qpe,{scope:t,onClose:V,children:Mh.createPortal(g.jsx(D_.ItemSlot,{scope:t,children:g.jsx(hue,{asChild:!0,onEscapeKeyDown:Re(a,()=>{v.isFocusedToastEscapeKeyDownRef.current||V(),v.isFocusedToastEscapeKeyDownRef.current=!1}),children:g.jsx(ct.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":v.swipeDirection,...S,ref:C,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:Re(n.onKeyDown,N=>{N.key==="Escape"&&(a==null||a(N.nativeEvent),N.nativeEvent.defaultPrevented||(v.isFocusedToastEscapeKeyDownRef.current=!0,V()))}),onPointerDown:Re(n.onPointerDown,N=>{N.button===0&&(T.current={x:N.clientX,y:N.clientY})}),onPointerMove:Re(n.onPointerMove,N=>{if(!T.current)return;const z=N.clientX-T.current.x,G=N.clientY-T.current.y,q=!!E.current,$=["left","right"].includes(v.swipeDirection),K=["left","up"].includes(v.swipeDirection)?Math.min:Math.max,J=$?K(0,z):0,H=$?0:K(0,G),te=N.pointerType==="touch"?10:2,he={x:J,y:H},Pe={originalEvent:N,delta:he};q?(E.current=he,vy(Xpe,h,Pe,{discrete:!1})):SN(he,v.swipeDirection,te)?(E.current=he,vy(Ype,u,Pe,{discrete:!1}),N.target.setPointerCapture(N.pointerId)):(Math.abs(z)>te||Math.abs(G)>te)&&(T.current=null)}),onPointerUp:Re(n.onPointerUp,N=>{const z=E.current,G=N.target;if(G.hasPointerCapture(N.pointerId)&&G.releasePointerCapture(N.pointerId),E.current=null,T.current=null,z){const q=N.currentTarget,$={originalEvent:N,delta:z};SN(z,v.swipeDirection,v.swipeThreshold)?vy(Jpe,m,$,{discrete:!0}):vy(Zpe,p,$,{discrete:!0}),q.addEventListener("click",K=>K.preventDefault(),{once:!0})}})})})}),v.viewport)})]}):null}),nge=n=>{const{__scopeToast:e,children:t,...r}=n,s=mv($g,e),[o,i]=k.useState(!1),[a,l]=k.useState(!1);return oge(()=>i(!0)),k.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:g.jsx(Dg,{asChild:!0,children:g.jsx(XT,{...r,children:o&&g.jsxs(g.Fragment,{children:[s.label," ",t]})})})},rge="ToastTitle",M7=k.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return g.jsx(ct.div,{...r,ref:e})});M7.displayName=rge;var sge="ToastDescription",A7=k.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n;return g.jsx(ct.div,{...r,ref:e})});A7.displayName=sge;var O7="ToastAction",R7=k.forwardRef((n,e)=>{const{altText:t,...r}=n;return t.trim()?g.jsx(j7,{altText:t,asChild:!0,children:g.jsx(j_,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${O7}\`. Expected non-empty \`string\`.`),null)});R7.displayName=O7;var D7="ToastClose",j_=k.forwardRef((n,e)=>{const{__scopeToast:t,...r}=n,s=ege(D7,t);return g.jsx(j7,{asChild:!0,children:g.jsx(ct.button,{type:"button",...r,ref:e,onClick:Re(n.onClick,s.onClose)})})});j_.displayName=D7;var j7=k.forwardRef((n,e)=>{const{__scopeToast:t,altText:r,...s}=n;return g.jsx(ct.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function L7(n){const e=[];return Array.from(n.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),ige(r)){const s=r.ariaHidden||r.hidden||r.style.display==="none",o=r.dataset.radixToastAnnounceExclude==="";if(!s)if(o){const i=r.dataset.radixToastAnnounceAlt;i&&e.push(i)}else e.push(...L7(r))}}),e}function vy(n,e,t,{discrete:r}){const s=t.originalEvent.currentTarget,o=new CustomEvent(n,{bubbles:!0,cancelable:!0,detail:t});e&&s.addEventListener(n,e,{once:!0}),r?YT(s,o):s.dispatchEvent(o)}var SN=(n,e,t=0)=>{const r=Math.abs(n.x),s=Math.abs(n.y),o=r>s;return e==="left"||e==="right"?o&&r>t:!o&&s>t};function oge(n=()=>{}){const e=is(n);Va(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[e])}function ige(n){return n.nodeType===n.ELEMENT_NODE}function age(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 EP(n){const e=document.activeElement;return n.some(t=>t===e?!0:(t.focus(),document.activeElement!==e))}var lge=k7,cge=_7,uge=M7,dge=A7,hge=R7,xN=j_,N7="Toggle",F7=k.forwardRef((n,e)=>{const{pressed:t,defaultPressed:r,onPressedChange:s,...o}=n,[i,a]=vi({prop:t,onChange:s,defaultProp:r??!1,caller:N7});return g.jsx(ct.button,{type:"button","aria-pressed":i,"data-state":i?"on":"off","data-disabled":n.disabled?"":void 0,...o,ref:e,onClick:Re(n.onClick,()=>{n.disabled||a(!i)})})});F7.displayName=N7;var xc="ToggleGroup",[z7,B7]=Ho(xc,[Nh]),$7=Nh(),L_=We.forwardRef((n,e)=>{const{type:t,...r}=n;if(t==="single"){const s=r;return g.jsx(fge,{...s,ref:e})}if(t==="multiple"){const s=r;return g.jsx(pge,{...s,ref:e})}throw new Error(`Missing prop \`type\` expected on \`${xc}\``)});L_.displayName=xc;var[U7,H7]=z7(xc),fge=We.forwardRef((n,e)=>{const{value:t,defaultValue:r,onValueChange:s=()=>{},...o}=n,[i,a]=vi({prop:t,defaultProp:r??"",onChange:s,caller:xc});return g.jsx(U7,{scope:n.__scopeToggleGroup,type:"single",value:We.useMemo(()=>i?[i]:[],[i]),onItemActivate:a,onItemDeactivate:We.useCallback(()=>a(""),[a]),children:g.jsx(K7,{...o,ref:e})})}),pge=We.forwardRef((n,e)=>{const{value:t,defaultValue:r,onValueChange:s=()=>{},...o}=n,[i,a]=vi({prop:t,defaultProp:r??[],onChange:s,caller:xc}),l=We.useCallback(u=>a((h=[])=>[...h,u]),[a]),c=We.useCallback(u=>a((h=[])=>h.filter(p=>p!==u)),[a]);return g.jsx(U7,{scope:n.__scopeToggleGroup,type:"multiple",value:i,onItemActivate:l,onItemDeactivate:c,children:g.jsx(K7,{...o,ref:e})})});L_.displayName=xc;var[gge,mge]=z7(xc),K7=We.forwardRef((n,e)=>{const{__scopeToggleGroup:t,disabled:r=!1,rovingFocus:s=!0,orientation:o,dir:i,loop:a=!0,...l}=n,c=$7(t),u=Og(i),h={role:"group",dir:u,...l};return g.jsx(gge,{scope:t,rovingFocus:s,disabled:r,children:s?g.jsx(f_,{asChild:!0,...c,orientation:o,dir:u,loop:a,children:g.jsx(ct.div,{...h,ref:e})}):g.jsx(ct.div,{...h,ref:e})})}),mx="ToggleGroupItem",W7=We.forwardRef((n,e)=>{const t=H7(mx,n.__scopeToggleGroup),r=mge(mx,n.__scopeToggleGroup),s=$7(n.__scopeToggleGroup),o=t.value.includes(n.value),i=r.disabled||n.disabled,a={...n,pressed:o,disabled:i},l=We.useRef(null);return r.rovingFocus?g.jsx(cv,{asChild:!0,...s,focusable:!i,active:o,ref:l,children:g.jsx(vN,{...a,ref:e})}):g.jsx(vN,{...a,ref:e})});W7.displayName=mx;var vN=We.forwardRef((n,e)=>{const{__scopeToggleGroup:t,value:r,...s}=n,o=H7(mx,t),i={role:"radio","aria-checked":n.pressed,"aria-pressed":void 0},a=o.type==="single"?i:void 0;return g.jsx(F7,{...a,...s,ref:e,onPressedChange:l=>{l?o.onItemActivate(r):o.onItemDeactivate(r)}})}),yge=L_,Sge=W7,N_="Toolbar",[xge,EPe]=Ho(N_,[Nh,B7]),F_=Nh(),V7=B7(),[vge,G7]=xge(N_),q7=k.forwardRef((n,e)=>{const{__scopeToolbar:t,orientation:r="horizontal",dir:s,loop:o=!0,...i}=n,a=F_(t),l=Og(s);return g.jsx(vge,{scope:t,orientation:r,dir:l,children:g.jsx(f_,{asChild:!0,...a,orientation:r,dir:l,loop:o,children:g.jsx(ct.div,{role:"toolbar","aria-orientation":r,dir:l,...i,ref:e})})})});q7.displayName=N_;var Y7="ToolbarSeparator",wge=k.forwardRef((n,e)=>{const{__scopeToolbar:t,...r}=n,s=G7(Y7,t);return g.jsx(kpe,{orientation:s.orientation==="horizontal"?"vertical":"horizontal",...r,ref:e})});wge.displayName=Y7;var bge="ToolbarButton",z_=k.forwardRef((n,e)=>{const{__scopeToolbar:t,...r}=n,s=F_(t);return g.jsx(cv,{asChild:!0,...s,focusable:!n.disabled,children:g.jsx(ct.button,{type:"button",...r,ref:e})})});z_.displayName=bge;var Cge="ToolbarLink",Pge=k.forwardRef((n,e)=>{const{__scopeToolbar:t,...r}=n,s=F_(t);return g.jsx(cv,{asChild:!0,...s,focusable:!0,children:g.jsx(ct.a,{...r,ref:e,onKeyDown:Re(n.onKeyDown,o=>{o.key===" "&&o.currentTarget.click()})})})});Pge.displayName=Cge;var X7="ToolbarToggleGroup",Z7=k.forwardRef((n,e)=>{const{__scopeToolbar:t,...r}=n,s=G7(X7,t),o=V7(t);return g.jsx(yge,{"data-orientation":s.orientation,dir:s.dir,...o,...r,ref:e,rovingFocus:!1})});Z7.displayName=X7;var kge="ToolbarToggleItem",J7=k.forwardRef((n,e)=>{const{__scopeToolbar:t,...r}=n,s=V7(t),o={__scopeToolbar:n.__scopeToolbar};return g.jsx(z_,{asChild:!0,...o,children:g.jsx(Sge,{...s,...r,ref:e})})});J7.displayName=kge;var Ege=q7,Ige=z_,Tge=Z7,_ge=J7;function Bt(n,e){var s;const t=new Set;for(const o of e){const i=n.getShape(o);if(!i)continue;n.getShapeUtil(i).onDragShapesOut&&t.add(i);const a=n.getShape(i.parentId);a&&n.getShapeUtil(a).onDragShapesOut&&t.add(a)}const r=new Map;for(const o of t){const i=Q7(n,o);i.length&&r.set(o,i)}for(const[o,i]of r){const a=n.getShapeUtil(o),l=st(i.map(c=>n.getShape(c)));(s=a.onDragShapesOut)==null||s.call(a,o,l)}}function Q7(n,e){const t=n.getSortedChildIdsForParent(e.id);if(t.length===0)return[];const r=n.getShapePageBounds(e);if(!r)return[];let s,o,i;const a=[];for(const l of t){const c=n.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}s??(s=n.getShapeGeometry(e)),o??(o=n.getShapePageTransform(e)),i??(i=o.applyToPoints(s.vertices));const u=n.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:p}=n.getShapeGeometry(l);if(!h.some(m=>so(m,u))){if(p){if(iT(u,h))continue}else if(AQ(u,h))continue;a.push(l)}}return a}function yx(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 Mge(n,e){const t=st(e.map(s=>n.getShape(s)).filter(s=>s&&n.isShapeOfType(s,"frame")));if(!t.length)return;const r=[];n.run(()=>{t.map(s=>{const o=n.getSortedChildIdsForParent(s.id);o.length&&(n.reparentShapes(o,s.parentId,s.index),r.push(...o))}),n.setSelectedShapes(r),n.deleteShapes(e)})}const wN=50;function eH(n,e,t={padding:wN}){const r=ye.FromPoints(n.flatMap(c=>{if(!c)return[];const u=e.getShapeGeometry(c.id),h=e.getShapeLocalTransform(c);return(h==null?void 0:h.applyToPoints(u.vertices))??[]})),s=t.padding??wN,o=r.w+2*s,i=r.h+2*s,a=s-r.minX,l=s-r.minY;return{w:o,h:i,dx:a,dy:l}}function tH(n,e,t={}){const r=n.getShape(e);if(!r)return;const s=n.getSortedChildIdsForParent(r.id),o=st(s.map(h=>n.getShape(h)));if(!o.length)return;const{w:i,h:a,dx:l,dy:c}=eH(o,n,t);if(l===0&&c===0&&r.props.w===i&&r.props.h===a)return;const u=new P(l,c).rot(r.rotation);n.run(()=>{const h=s.map(p=>{const m=n.getShape(p);return{id:m.id,type:m.type,x:m.x+l,y:m.y+c}});h.push({id:r.id,type:r.type,x:r.x-u.x,y:r.y-u.y,props:{w:i,h:a}}),n.updateShapes(h)})}function En({children:n}){return g.jsx("span",{className:"tlui-button__label",children:n})}const Ya=k.memo(function({label:e,small:t,invertIcon:r,icon:s,color:o,className:i,...a}){const l=qT(),c=l.icons[s]??l.icons["question-mark-circle"],u=k.useRef(null);return k.useLayoutEffect(()=>{c||console.error(`Icon not found: ${s}. Add it to the assetUrls.icons object.`),u!=null&&u.current&&(u.current.style.webkitMask=`url(${c}) center 100% / 100% no-repeat`)},[u,c,s]),s==="none"?g.jsx("div",{className:$e("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":t},i)}):g.jsx("div",{...a,ref:u,"aria-label":e,role:"img",className:$e("tlui-icon",{"tlui-icon__small":t},i),style:{color:o,mask:`url(${c}) center 100% / 100% no-repeat`,transform:r?"scale(-1, 1)":void 0}})});function lt({icon:n,small:e,invertIcon:t}){return g.jsx(Ya,{"aria-hidden":"true",label:"",className:"tlui-button__icon",icon:n,small:e,invertIcon:t})}function yv({className:n,children:e}){return g.jsx("div",{className:$e("tlui-dialog__header",n),children:e})}function Sv({className:n,children:e,style:t}){return g.jsx(bde,{dir:"ltr",className:$e("tlui-dialog__header__title",n),style:t,children:e})}function xv(){const n=Ke();return g.jsx("div",{className:"tlui-dialog__header__close",children:g.jsx(hU,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:g.jsx(ht,{type:"icon","aria-label":n("ui.close"),onTouchEnd:e=>e.target.click(),children:g.jsx(lt,{small:!0,icon:"cross-2"})})})})}function Qp({className:n,children:e,style:t}){return g.jsx("div",{className:$e("tlui-dialog__body",n),style:t,children:e})}function B_({className:n,children:e}){return g.jsx("div",{className:$e("tlui-dialog__footer",n),children:e})}const Ug=k.forwardRef(function({className:e,label:t,icon:r,iconLeft:s,iconLabel:o,autoSelect:i=!1,autoFocus:a=!1,defaultValue:l,placeholder:c,onComplete:u,onValueChange:h,onCancel:p,onFocus:m,onBlur:S,shouldManuallyMaintainScrollPositionWhenFocused:v=!1,children:y,value:w,"data-testid":C},T){const E=Sr(),_=k.useRef(null);k.useImperativeHandle(T,()=>_.current);const A=Ke(),O=k.useRef(l??""),D=k.useRef(l??""),F=k.useRef(!1),[U,V]=k.useState(!1),Y=k.useCallback($=>{V(!0);const K=$.currentTarget;D.current=K.value,E?E.timers.requestAnimationFrame(()=>{i&&K.select()}):qS.requestAnimationFrame("anon",()=>{i&&K.select()}),m==null||m()},[i,E,m]),j=k.useCallback($=>{const K=$.currentTarget.value;D.current=K,h==null||h(K)},[h]),N=k.useCallback($=>{switch($.key){case"Enter":{if(F.current)return;$.currentTarget.blur(),Yt($),u==null||u($.currentTarget.value);break}case"Escape":{$.currentTarget.value=O.current,p==null||p($.currentTarget.value),$.currentTarget.blur(),Yt($);break}}},[u,p]),z=k.useCallback($=>{V(!1);const K=$.currentTarget.value;S==null||S(K)},[S]),G=k.useCallback(()=>F.current=!0,[]),q=k.useCallback(()=>F.current=!1,[]);return k.useEffect(()=>{if(!Tt.isIos)return;const $=window.visualViewport;if(U&&v&&$){const K=()=>{var J;(J=_.current)==null||J.scrollIntoView({block:"center"})};return $.addEventListener("resize",K),$.addEventListener("scroll",K),E?E.timers.requestAnimationFrame(()=>{var J;(J=_.current)==null||J.scrollIntoView({block:"center"})}):qS.requestAnimationFrame("anon",()=>{var J;(J=_.current)==null||J.scrollIntoView({block:"center"})}),()=>{$.removeEventListener("resize",K),$.removeEventListener("scroll",K)}}},[U,E,v]),g.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,t&&g.jsx("label",{children:A(t)}),s&&g.jsx(Ya,{label:o?A(o):"",icon:s,className:"tlui-icon-left",small:!0}),g.jsx("input",{ref:_,className:$e("tlui-input",e),type:"text",defaultValue:l,onKeyDownCapture:N,onChange:j,onFocus:Y,onBlur:z,onCompositionStart:G,onCompositionEnd:q,autoFocus:a,placeholder:c,value:w,"data-testid":C}),r&&g.jsx(Ya,{label:o?A(o):"",icon:r,small:!!t})]})});function bN(n){return ao.isValid(n)?{isValid:!0,hasProtocol:!0}:ao.isValid("https://"+n)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Age=tr(function({onClose:e}){const r=ne().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?g.jsx(Oge,{onClose:e,selectedShape:r}):null}),Oge=tr(function({onClose:e,selectedShape:t}){const r=ne(),s=Ke(),o=k.useRef(null);k.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=o.current)==null?void 0:S.focus()})},[r]);const i=k.useRef(t.props.url),[a,l]=k.useState(()=>{const S=bN(t.props.url),v=S.isValid===!0?S.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:v,safe:v,valid:!0}}),c=k.useCallback(S=>{const v=S.replace(/https?:\/\/(https?:\/\/)/,(C,T)=>T),y=bN(v),w=y.isValid===!0?y.hasProtocol?v:"https://"+v:"https://";l({actual:v,safe:w,valid:y.isValid})},[]),u=k.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),e())},[r,e]),h=k.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(S&&"url"in S.props&&S.props.url!==a.safe&&r.updateShapes([{id:S.id,type:S.type,props:{url:a.safe}}]),e())},[r,e,a]),p=k.useCallback(()=>{e()},[e]);if(!t)return e(),null;const m=i.current&&!a.valid;return g.jsxs(g.Fragment,{children:[g.jsxs(yv,{children:[g.jsx(Sv,{children:s("edit-link-dialog.title")}),g.jsx(xv,{})]}),g.jsx(Qp,{children:g.jsxs("div",{className:"tlui-edit-link-dialog",children:[g.jsx(Ug,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,autoSelect:!0,placeholder:"https://example.com",value:a.actual,onValueChange:c,onComplete:h,onCancel:p}),g.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),g.jsxs(B_,{className:"tlui-dialog__footer__actions",children:[g.jsx(ht,{type:"normal",onClick:p,onTouchEnd:p,children:g.jsx(En,{children:s("edit-link-dialog.cancel")})}),m?g.jsx(ht,{type:"danger",onTouchEnd:u,onClick:u,children:g.jsx(En,{children:s("edit-link-dialog.clear")})}):g.jsx(ht,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:g.jsx(En,{children:s("edit-link-dialog.save")})})]})]})});var Rge={};const CN=/(^\/[f|p|r|ro|s|v]\/[^/]+\/?$)/,$_=[{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=Qe(n);if(e&&e.pathname.match(CN))return e.searchParams.append("embed","true"),n},fromEmbedUrl:n=>{const e=Qe(n);if(e&&e.pathname.match(CN))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|design)\/([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=Qe(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,o,i]=e,a=i==="z"?"roadmap":"satellite",l=a==="roadmap"?o:-Math.log2(parseInt(o)/14772321)/.8;t=`https://${new URL(n).host.replace("www.","")}/maps/embed/v1/view?key=${Rge.NEXT_PUBLIC_GC_API_KEY}&center=${r},${s}&zoom=${l}&maptype=${a}`}else t="";return t}},fromEmbedUrl:n=>{const e=Qe(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",o=s==="roadmap"?r:14772321*Math.pow(2,parseInt(r)*-.8),[i,a]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${i},${a},${o}${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=Qe(n),t=e&&e.pathname.match(/\/v\/(.+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Qe(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=Qe(n),t=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:n=>{const e=Qe(n),t=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,t=n.match(e);if(t){const[r,s,o]=t;return`https://codepen.io/${s}/embed/${o}`}},fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s,o]=t;return`https://codepen.io/${s}/pen/${o}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:n=>{const e=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,t=n.match(e);if(t){const[r,s]=t;return`https://scratch.mit.edu/projects/embed/${s}`}},fromEmbedUrl:n=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,s]=t;return`https://scratch.mit.edu/projects/${s}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:n=>{const e=Qe(n);if(!e)return;const t=e.hostname.replace(/^www./,"");if(t==="youtu.be"){const r=e.pathname.split("/").filter(Boolean)[0],s=new URLSearchParams(e.search),o=s.get("t");o&&(s.set("start",o),s.delete("t"));const i=s.toString()?"?"+s.toString():"";return`https://www.youtube.com/embed/${r}${i}`}else if((t==="youtube.com"||t==="m.youtube.com")&&e.pathname.match(/^\/watch/)){const r=e.searchParams.get("v"),s=new URLSearchParams(e.search);s.delete("v");const o=s.get("t");o&&(s.set("start",o),s.delete("t"));const i=s.toString()?"?"+s.toString():"";return`https://www.youtube.com/embed/${r}${i}`}},fromEmbedUrl:n=>{const e=Qe(n);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r){const s=new URLSearchParams(e.search);s.set("v",(r==null?void 0:r[1])??"");const o=s.get("start");return o&&(s.set("t",o),s.delete("start")),`https://www.youtube.com/watch?${s.toString()}`}}}},{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=Qe(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=Qe(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=Qe(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=Qe(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=Qe(n);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return n.split("/").pop()?n:void 0},fromEmbedUrl:n=>{const e=Qe(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=Qe(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${n}?embed=true`},fromEmbedUrl:n=>{const e=Qe(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=Qe(n);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Qe(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=Qe(n);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:n=>{const e=Qe(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=Qe(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=Qe(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=Qe(n);if(e&&e.hash.match(/#room=/))return n},fromEmbedUrl:n=>{const e=Qe(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=Qe(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=Qe(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=Qe(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${n}?embed`},fromEmbedUrl:n=>{const e=Qe(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],Dge={"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},jge=$_.map(n=>n.type);function Lge(n){return jge.includes(n)}function Nge(n){return"icon"in n}function nH(){const n=Sr();if(n&&n.hasShapeUtil("embed"))return n.getShapeUtil("embed")}function U_(){const n=nH();return e=>n?n.getEmbedDefinition(e):void 0}function Fge(){const n=nH();return n?n.getEmbedDefinitions():[]}const rH=tr(function({onClose:e}){const t=ne(),r=Ke(),s=qT(),[o,i]=k.useState(null),[a,l]=k.useState(""),[c,u]=k.useState(null),[h,p]=k.useState(!1),m=k.useRef(-1),S=Fge(),v=U_();return g.jsxs(g.Fragment,{children:[g.jsxs(yv,{children:[g.jsx(Sv,{children:o?`${r("embed-dialog.title")} — ${o.title}`:r("embed-dialog.title")}),g.jsx(xv,{})]}),o?g.jsxs(g.Fragment,{children:[g.jsxs(Qp,{className:"tlui-embed-dialog__enter",children:[g.jsx(Ug,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:y=>{l(y);const w=v(y);u(w&&w.definition.type===o.type?w:null),p(!1),clearTimeout(m.current),m.current=t.timers.setTimeout(()=>p(!w),320)}}),a===""?g.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[g.jsx("span",{children:r("embed-dialog.instruction")})," ",o.instructionLink&&g.jsxs(g.Fragment,{children:[g.jsx("a",{target:"_blank",rel:"noopener noreferrer",href:o.instructionLink,className:"tlui-embed-dialog__instruction__link",children:"Learn more"}),"."]})]}):g.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),g.jsxs(B_,{className:"tlui-dialog__footer__actions",children:[g.jsx(ht,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:g.jsx(En,{children:r("embed-dialog.back")})}),g.jsx("div",{className:"tlui-embed__spacer"}),g.jsx(ht,{type:"normal",onClick:e,children:g.jsx(En,{children:r("embed-dialog.cancel")})}),g.jsx(ht,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:c.definition}),e())},children:g.jsx(En,{children:r("embed-dialog.create")})})]})]}):g.jsx(g.Fragment,{children:g.jsx(Qp,{className:"tlui-embed-dialog__list",children:S.map(y=>{const w=Lge(y.type)?s.embedIcons[y.type]:Nge(y)?y.icon:void 0;return g.jsxs(ht,{type:"menu",onClick:()=>i(y),children:[g.jsx(En,{children:y.title}),w&&g.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${w})`}})]},y.type)})})})]})});function vv(){const n=Sr();return(n==null?void 0:n.store.props.collaboration)!==void 0}function zge(){const n=Sr();return se("sync status",()=>{var e;return(e=n==null?void 0:n.store.props.collaboration)!=null&&e.status?n.store.props.collaboration.status.get():null},[n])}async function Bge(n,e,t){const r=st(e.map(a=>{const l=n.getShape(a);if(!(!l||n.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||n.isShapeOfType(a,"image"))return}const s=[];if(t!==void 0){const a=r.map(l=>({shape:l,bounds:n.getShapeMaskedPageBounds(l).clone().expandBy(t)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){s[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of s)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||s.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=ye.Common(r.map(l=>n.getShapeMaskedPageBounds(l)));s.push({shapes:r,bounds:a})}const o=n.options.flattenImageBoundsPadding;for(const a of s){t!==void 0&&a.bounds.expandBy(-t);const l=await n.getSvgString(a.shapes,{padding:o,background:!1});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 i=[];return to(()=>{for(const a of s){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=n.findCommonAncestor(u)??n.getCurrentPageId();if(!h)continue;let p="a1";for(const w of u)if(w.parentId===h){w.index>p&&(p=w.index);break}let m,S,v;if(Ts(h)){const w=n.getShape(h);if(!w)continue;const C=n.getPointInShapeSpace(w,{x:c.x,y:c.y});v=n.getShapePageTransform(h).rotation(),C.sub(new P(o,o).rot(-v)),m=C.x,S=C.y}else m=c.x-o,S=c.y-o,v=0;n.deleteShapes(u),n.createAssets([{...l,id:l.id}]);const y=Nt();n.createShape({id:y,type:"image",index:p,parentId:h,x:m,y:S,rotation:-v,props:{assetId:l.id,w:c.w+o*2,h:c.h+o*2}}),i.push(y)}}),i}const IP=[0,389,436,476,580,640,840,1023];var vn=(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))(vn||{});const sH=We.createContext(null);function $ge({forceMobile:n=!1,children:e}){const t=Sr(),r=se("breakpoint",()=>{const{width:s}=(t==null?void 0:t.getViewportScreenBounds())??{width:window.innerWidth},o=n?vn.MOBILE_SM:IP.length-1;for(let i=0;i<o;i++)if(s>IP[i]&&s<=IP[i+1])return i;return o},[t]);return g.jsx(sH.Provider,{value:r,children:e})}function Ur(){const n=k.useContext(sH);if(n===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return n}const ME=k.createContext(null);function Uge({context:n,children:e}){const t=k.useContext(ME),r=Bn(),s=gg("dialogs",[]),o=k.useMemo(()=>({dialogs:s,addDialog(i){const a=i.id??Mt();return s.update(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),r("open-menu",{source:"dialog",id:a}),Xr.addOpenMenu(a,n),a},removeDialog(i){var l;const a=s.get().find(c=>c.id===i);return a&&((l=a.onClose)==null||l.call(a),r("close-menu",{source:"dialog",id:i}),Xr.deleteOpenMenu(i,n),s.update(c=>c.filter(u=>u!==a))),i},clearDialogs(){const i=s.get();i.length!==0&&(i.forEach(a=>{var l;(l=a.onClose)==null||l.call(a),r("close-menu",{source:"dialog",id:a.id}),Xr.deleteOpenMenu(a.id,n)}),s.set([]))}}),[r,s,n]);return t?g.jsx(g.Fragment,{children:e}):g.jsx(ME.Provider,{value:o,children:e})}function Hg(){const n=k.useContext(ME);if(!n)throw new Error("useDialogs must be used within a DialogsProvider");return n}const AE=k.createContext(null);function Hge({children:n}){const e=gg("toasts",[]),t=k.useContext(AE),r=k.useMemo(()=>({toasts:e,addToast(s){const o=s.id??Mt();return e.update(i=>[...i.filter(a=>a.id!==s.id),{...s,id:o}]),o},removeToast(s){return e.update(o=>o.filter(i=>i.id!==s)),s},clearToasts(){e.set([])}}),[e]);return t?g.jsx(g.Fragment,{children:n}):g.jsx(lge,{children:g.jsx(AE.Provider,{value:r,children:n})})}function sl(){const n=k.useContext(AE);if(!n)throw new Error("useToasts must be used within a ToastsProvider");return n}var TP={exports:{}},PN;function Kge(){return PN||(PN=1,function(n){var e=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function i(l,c){if(!o[l]){o[l]={};for(var u=0;u<l.length;u++)o[l][l.charAt(u)]=u}return o[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return 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),u=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var m=c.charCodeAt(h);u[h*2]=m>>>8,u[h*2+1]=m%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(m){p.push(t(m))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return s.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(s,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,u){if(l==null)return"";var h,p,m={},S={},v="",y="",w="",C=2,T=3,E=2,_=[],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]=T++,S[v]=!0),y=w+v,Object.prototype.hasOwnProperty.call(m,y))w=y;else{if(Object.prototype.hasOwnProperty.call(S,w)){if(w.charCodeAt(0)<256){for(h=0;h<E;h++)A=A<<1,O==c-1?(O=0,_.push(u(A)),A=0):O++;for(p=w.charCodeAt(0),h=0;h<8;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1}else{for(p=1,h=0;h<E;h++)A=A<<1|p,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=0;for(p=w.charCodeAt(0),h=0;h<16;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1}C--,C==0&&(C=Math.pow(2,E),E++),delete S[w]}else for(p=m[w],h=0;h<E;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1;C--,C==0&&(C=Math.pow(2,E),E++),m[y]=T++,w=String(v)}if(w!==""){if(Object.prototype.hasOwnProperty.call(S,w)){if(w.charCodeAt(0)<256){for(h=0;h<E;h++)A=A<<1,O==c-1?(O=0,_.push(u(A)),A=0):O++;for(p=w.charCodeAt(0),h=0;h<8;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1}else{for(p=1,h=0;h<E;h++)A=A<<1|p,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=0;for(p=w.charCodeAt(0),h=0;h<16;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1}C--,C==0&&(C=Math.pow(2,E),E++),delete S[w]}else for(p=m[w],h=0;h<E;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1;C--,C==0&&(C=Math.pow(2,E),E++)}for(p=2,h=0;h<E;h++)A=A<<1|p&1,O==c-1?(O=0,_.push(u(A)),A=0):O++,p=p>>1;for(;;)if(A=A<<1,O==c-1){_.push(u(A));break}else O++;return _.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],p=4,m=4,S=3,v="",y=[],w,C,T,E,_,A,O,D={val:u(0),position:c,index:1};for(w=0;w<3;w+=1)h[w]=w;for(T=0,_=Math.pow(2,2),A=1;A!=_;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=u(D.index++)),T|=(E>0?1:0)*A,A<<=1;switch(T){case 0:for(T=0,_=Math.pow(2,8),A=1;A!=_;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=u(D.index++)),T|=(E>0?1:0)*A,A<<=1;O=t(T);break;case 1:for(T=0,_=Math.pow(2,16),A=1;A!=_;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=u(D.index++)),T|=(E>0?1:0)*A,A<<=1;O=t(T);break;case 2:return""}for(h[3]=O,C=O,y.push(O);;){if(D.index>l)return"";for(T=0,_=Math.pow(2,S),A=1;A!=_;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=u(D.index++)),T|=(E>0?1:0)*A,A<<=1;switch(O=T){case 0:for(T=0,_=Math.pow(2,8),A=1;A!=_;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=u(D.index++)),T|=(E>0?1:0)*A,A<<=1;h[m++]=t(T),O=m-1,p--;break;case 1:for(T=0,_=Math.pow(2,16),A=1;A!=_;)E=D.val&D.position,D.position>>=1,D.position==0&&(D.position=c,D.val=u(D.index++)),T|=(E>0?1:0)*A,A<<=1;h[m++]=t(T),O=m-1,p--;break;case 2:return y.join("")}if(p==0&&(p=Math.pow(2,S),S++),h[O])v=h[O];else if(O===m)v=C+C.charAt(0);else return null;y.push(v),h[m++]=C+v.charAt(0),p--,C=v,p==0&&(p=Math.pow(2,S),S++)}}};return a}();n!=null?n.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})}(TP)),TP.exports}var Wge=Kge();const oH=Za(Wge),H_="web image/vnd.tldraw+png",Vge={png:H_},Gge={[H_]:"image/png"};function qge(n){return kn(Vge,n)??null}function Yge(n){return kn(Gge,n)??n}function Xge(n){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(n)}function Zge(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=J3(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function Jge(n,e,t,r){const s=e.map(o=>o instanceof File?o:new File([o],"tldrawFile",{type:o.type}));n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r})}async function OE(n,e,t,r){return n.markHistoryStoppingPoint("paste"),await n.putExternalContent({type:"url",point:t,url:e,sources:r})}const Qge=[H_,"image/png","image/jpeg","image/webp","image/svg+xml"];function _P(n){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=n.trim(),e.body.textContent||e.body.innerText||""}const eme=n=>{try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},tme=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 m4(e)},nme=n=>/^<svg/.test(n),rme=["input","select","textarea"];function MP(n){const{activeElement:e}=document;return n.menus.hasAnyOpenMenus()||e&&(e.isContentEditable||rme.indexOf(e.tagName.toLowerCase())>-1)}const wy=(n,e,t,r)=>{const s=tme(e);if(s)for(const o of s)OE(n,o,t);else eme(e)?OE(n,e,t):nme(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}))},sme=async(n,e,t)=>{if(n.getEditingShapeId()!==null)return;if(!e)throw Error("No clipboard data");const r=[];for(const s of Object.values(e.items))switch(s.kind){case"file":{r.push({type:"file",source:new Promise(o=>o(s.getAsFile()))});break}case"string":{s.type==="text/html"?r.push({type:"html",source:new Promise(o=>s.getAsString(o))}):s.type==="text/plain"?r.push({type:"text",source:new Promise(o=>s.getAsString(o))}):r.push({type:s.type,source:new Promise(o=>s.getAsString(o))});break}}aH(n,r,t)},iH=async({editor:n,clipboardItems:e,point:t,fallbackFiles:r})=>{const s=[];for(const o of e){for(const i of Qge)if(o.types.includes(i)){const a=o.getType(i).then(l=>Jr.rewriteMimeType(l,Yge(i)));s.push({type:"blob",source:a});break}o.types.includes("text/html")&&s.push({type:"html",source:(async()=>{const i=await o.getType("text/html");return await Jr.blobToText(i)})()}),o.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{const i=await o.getType("text/uri-list");return await Jr.blobToText(i)})()}),o.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{const i=await o.getType("text/plain");return await Jr.blobToText(i)})()})}return r!=null&&r.length&&s.length===1&&s[0].type==="text"?(s.pop(),s.push(...r.map(o=>({type:"file",source:Promise.resolve(o)})))):r!=null&&r.length&&s.length===0&&s.push(...r.map(o=>({type:"file",source:Promise.resolve(o)}))),await aH(n,s,t)};async function aH(n,e,t){const r=e.filter(o=>(o.type==="file"||o.type==="blob")&&o.source!==null);if(r.length){if(r.length>n.options.maxFilesAtOnce)throw Error("Too many files");const o=st(await Promise.all(r.map(i=>i.source)));return await Jge(n,o,t)}const s=await Promise.all(e.filter(o=>o.type!=="file").map(o=>new Promise(i=>{const a=o;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=oH.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(h);if(p.type!=="application/tldraw"&&i({type:"error",data:p,reason:`found tldraw data comment but JSON was of a different type: ${p.type}`}),typeof p.data=="string"){i({type:"error",data:p,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:p.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const o of s)if(o.type==="tldraw"){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"tldraw",content:o.data,point:t});return}for(const o of s)if(o.type==="excalidraw"){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"excalidraw",content:o.data,point:t});return}for(const o of s){if(o.type==="text"&&o.subtype==="html"){const a=new DOMParser().parseFromString(o.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(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");wy(n,c,t,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&o.data.trim()&&(_P(o.data)??"")){wy(n,_P(o.data),t,s);return}if(s.some(c=>c.type==="text"&&c.subtype!=="html")){const c=_P(o.data)??"";if(c){n.markHistoryStoppingPoint("paste"),n.putExternalContent({type:"text",text:c,html:o.data,point:t,sources:s});return}}}if(o.type==="text"&&o.subtype==="text"&&o.data.startsWith("<iframe ")){const a=new DOMParser().parseFromString(o.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="IFRAME"&&a.firstElementChild.hasAttribute("src")&&a.firstElementChild.getAttribute("src")!==""){const c=a.firstElementChild.getAttribute("src");wy(n,c,t,s);return}}}for(const o of s)if(o.type==="text"&&o.subtype==="url"){OE(n,o.data,t,s);return}for(const o of s)if(o.type==="text"&&o.subtype==="text"&&o.data.trim()){wy(n,o.data,t,s);return}}const Sx=async n=>{var r;const e=await n.resolveAssetsInContent(n.getContentFromCurrentPage(n.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=oH.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const s=e.shapes.map(o=>n.getShapeUtil(o).getText(o)).filter(Mq);if((r=navigator.clipboard)!=null&&r.write){const o=new Blob([`<div data-tldraw>${t}</div>`],{type:"text/html"});let i=s.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${t}</div>`)}};function ome(){const n=Sr(),e=Bn(),t=k.useCallback(async function(i){Ve(n,"editor is required for copy"),n.getSelectedShapeIds().length!==0&&(await Sx(n),e("copy",{source:i}))},[n,e]),r=k.useCallback(async function(i){n&&n.getSelectedShapeIds().length!==0&&(await Sx(n),n.deleteShapes(n.getSelectedShapeIds()),e("cut",{source:i}))},[n,e]),s=k.useCallback(async function(i,a,l){n&&n.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(iH({editor:n,clipboardItems:i,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 ime(){const n=ne(),e=Bn(),t=se("editor.isFocused",()=>n.getInstanceState().isFocused,[n]);k.useEffect(()=>{if(!t)return;const r=async l=>{n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||MP(n)||(nt(l),await Sx(n),e("copy",{source:"kbd"}))};async function s(l){n.getSelectedShapeIds().length===0||n.getEditingShapeId()!==null||MP(n)||(nt(l),await Sx(n),n.deleteShapes(n.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let o=!1;const i=l=>{l.button===1&&(o=!0,n.timers.requestAnimationFrame(()=>{o=!1}))},a=l=>{var p,m;if(o){Yt(l);return}if(n.getEditingShapeId()!==null||MP(n))return;let c,u=!1;n.inputs.shiftKey&&(u=!0),n.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=n.inputs.currentPagePoint);const h=()=>{l.clipboardData&&sme(n,l.clipboardData,c)};if((p=navigator.clipboard)!=null&&p.read){const S=Array.from(((m=l.clipboardData)==null?void 0:m.files)||[]);navigator.clipboard.read().then(v=>{Array.isArray(v)&&v[0]instanceof ClipboardItem&&iH({editor:n,clipboardItems:v,point:c,fallbackFiles:S})},()=>{h()})}else h();nt(l),e("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",s),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",s),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[n,e,t])}const kN={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",svg:"text/plain"};function ame(n,e,t={}){const r=e!=null&&e.length?e:[...n.getCurrentPageShapeIds()],s=t.format??"png";return{blobPromise:n.toImage(r,t).then(o=>Jr.rewriteMimeType(o.blob,kN[s])),mimeType:kN[s]}}function lme(...n){const[e,t,r]=typeof n[2]=="string"?[n[0],n[1],{...n[3],format:n[2]}]:n;if(!navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(navigator.clipboard.write){const{blobPromise:s,mimeType:o}=ame(e,t,r),i={[o]:s},a=qge(r.format);return a&&Xge(a)&&(i[a]=s.then(l=>Jr.rewriteMimeType(l,a))),Zge(i)}switch(r.format){case"svg":return cme(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:xt(r.format)}}async function cme(n){var e,t;await((t=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:t.call(e,await n()))}function ume(){const n=Sr(),{addToast:e}=sl(),t=Ke();return k.useCallback((r,s="svg")=>{Ve(n,"useCopyAs: editor is required"),lme(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 dme(...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 ${EN()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?s=a.props.name||"frame":s=`${S0(a.id)} at ${EN()}`}s+=`.${r.format}`;const{blob:o}=await e.toImage(t,r),i=new File([o],s,{type:o.type});hme(i)}function EN(){const n=new Date,e=String(n.getFullYear()).slice(2),t=String(n.getMonth()+1).padStart(2,"0"),r=String(n.getDate()).padStart(2,"0"),s=String(n.getHours()).padStart(2,"0"),o=String(n.getMinutes()).padStart(2,"0"),i=String(n.getSeconds()).padStart(2,"0");return`${e}-${t}-${r} ${s}.${o}.${i}`}function hme(n){const e=document.createElement("a"),t=URL.createObjectURL(n);e.href=t,e.download=n.name,e.click(),URL.revokeObjectURL(t)}function fme(){const n=Sr(),{addToast:e}=sl(),t=Ke();return k.useCallback((r,s="png",o)=>{Ve(n,"useExportAs: editor is required"),dme(n,r,{format:s,name:o,scale:1}).catch(i=>{console.error(i.message),e({id:"export-fail",title:t("toast.error.export-fail.title"),description:t("toast.error.export-fail.desc"),severity:"error"})})},[n,e,t])}const lH=We.createContext([]);function pme(){const n=Sr(),e=k.useRef(),t=$l(We.useContext(lH));return k.useEffect(()=>{const r=n;if(!r)return;const s=window.document.createElement("input");s.type="file",s.accept=(t==null?void 0:t.join(","))??iq,s.multiple=!0,e.current=s;async function o(i){const a=i.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",o),()=>{e.current=void 0,s.removeEventListener("change",o)}},[n,t]),k.useCallback(()=>{var r;(r=e.current)==null||r.click()},[e])}function gme(){const n=Sr(),e=k.useRef(null),t=k.useRef(null);return k.useCallback(async function(){Ve(n,"usePrint: editor is required");const s=document.createElement("div"),o=document.createElement("style"),i=(w,C)=>{w&&(w.innerHTML=""),C&&document.head.contains(C)&&document.head.removeChild(C),w&&document.body.contains(w)&&document.body.removeChild(w)};i(e.current,t.current),e.current=s,t.current=o;const a=`tl-print-surface-${Mt()}`;s.className=a,o.innerHTML=`
351
+ .${a} {
352
+ display: none;
353
+ }
354
+
355
+ .${a} svg {
356
+ max-width: 100%;
357
+ height: 100%;
358
+ display: block;
359
+ }
360
+
361
+ @media print {
362
+ html, body {
363
+ min-height: 100%;
364
+ height: 100%;
365
+ margin: 0;
366
+ }
367
+
368
+ body {
369
+ position: relative;
370
+ }
371
+
372
+ body > * {
373
+ display: none;
374
+ }
375
+
376
+ .tldraw__editor {
377
+ display: none;
378
+ }
379
+
380
+ .${a} {
381
+ display: block !important;
382
+ background: white;
383
+ min-height: 100%;
384
+ height: 100%;
385
+ max-width: 100%;
386
+ }
387
+
388
+ .${a}__item {
389
+ padding: 10mm;
390
+ display: flex;
391
+ min-height: 100%;
392
+ flex-direction: column;
393
+ page-break-after: always;
394
+ position: relative;
395
+ overflow: hidden;
396
+ height: 100%;
397
+ }
398
+
399
+ .${a}__item__main {
400
+ flex: 1;
401
+ display: flex;
402
+ align-items: center;
403
+ justify-content: center;
404
+ max-height: 100%;
405
+ }
406
+
407
+ .${a}__item__header {
408
+ display: none;
409
+ }
410
+
411
+ .${a}__item__footer {
412
+ display: none;
413
+ text-align: right;
414
+ }
415
+
416
+ .${a}__item__footer__hide {
417
+ display: none;
418
+ }
419
+
420
+
421
+ }
422
+
423
+ `;const l=()=>{document.head.appendChild(o),document.body.appendChild(s)},c=()=>{n.once("tick",()=>{i(s,o)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(w,C,T){try{s.innerHTML+=`<div class="${a}__item">
424
+ <div class="${a}__item__header">
425
+ ${w.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
426
+ </div>
427
+ <div class="${a}__item__main">
428
+ ${T}
429
+ </div>
430
+ <div class="${a}__item__footer ${a}__item__footer__${C?"":"hide"}">
431
+ ${C??""}
432
+ </div>
433
+ </div>`}catch(E){console.error(E)}}function h(){Tt.isChromeForIos?(l(),window.print()):Tt.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=n.getSelectedShapeIds(),m=n.getCurrentPageId(),S=n.getPages(),y={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(n.getSelectedShapeIds().length>0){const w=await n.getSvgString(p,y);if(w){const C=S.find(T=>T.id===m);u(`tldraw — ${C==null?void 0:C.name}`,null,w.svg),h()}}else{const w=n.getCurrentPage(),C=await n.getSvgString(n.getSortedChildIdsForParent(w.id),y);C&&(u(`tldraw — ${w.name}`,null,C.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[n])}function K_(){const{addToast:n,removeToast:e,clearToasts:t}=sl(),{addDialog:r,clearDialogs:s,removeDialog:o}=Hg(),i=Ke(),a=pme(),l=gme(),{cut:c,copy:u,paste:h}=ome(),p=ume(),m=fme(),S=U_(),y=Ur()<vn.TABLET_SM;return k.useMemo(()=>({addToast:n,removeToast:e,clearToasts:t,addDialog:r,removeDialog:o,clearDialogs:s,msg:i,isMobile:y,insertMedia:a,printSelectionOrPages:l,cut:c,copy:u,paste:h,copyAs:p,exportAs:m,getEmbedDefinition:S}),[n,e,t,r,o,s,i,y,a,l,c,u,h,p,m,S])}function mme(n,e){const t={};for(const r of n)if(r.translations)for(const[s,o]of Qr(r.translations)){let i=t[s];i||(i=t[s]={}),Object.assign(i,o)}return{actions:(r,s,o)=>{for(const i of n)i.actions&&(s=i.actions(r,s,o));return s},tools:(r,s,o)=>{for(const i of n)i.tools&&(s=i.tools(r,s,{...e,...o}));return s},translations:t}}function cH(n){return k.useMemo(()=>n,n)}function yme(n){const e=cH(n==null?[]:Array.isArray(n)?n:[n]);return k.useMemo(()=>{const t={};for(const r of e)if(r.translations)for(const[s,o]of Qr(r.translations)){let i=t[s];i||(i=t[s]={}),Object.assign(i,o)}return t},[e])}function Sme(n){const e=K_(),t=cH(n==null?[]:Array.isArray(n)?n:[n]);return k.useMemo(()=>mme(t,e),[t,e])}const uH=k.createContext(null);function xme(n){return Object.fromEntries(n.map(e=>[e.id,e]))}function by(n,e){if(n.getSelectedShapes().length===0)return n.getDocumentSettings().name||e}function vme({overrides:n,children:e}){const t=Sr(),r=vv(),s=K_(),o=Bn(),i=J0(),a=Ke(),l=s.msg("document.default-name"),c=k.useMemo(()=>{const u=t;if(!u)return{};function h(){return u.isIn("select")||(u.complete(),u.setCurrentTool("select")),!1}function p(){return u.isIn("select")&&u.getSelectedShapeIds().length>0}function m(y){if(!p()||h())return;u.markHistoryStoppingPoint("resize shapes");const w=u.getSelectedShapeIds();w.length!==0&&u.run(()=>{w.map(T=>u.getShape(T)).filter(Boolean).forEach(T=>{var E;u.resizeShape(T.id,new P(y,y),{scaleOrigin:(E=u.getSelectionPageBounds())==null?void 0:E.center})})})}const S=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(y){p()&&(h()||(o("edit-link",{source:y}),u.markHistoryStoppingPoint("edit-link"),s.addDialog({component:Age})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"cmd+i,ctrl+i",onSelect(y){o("insert-embed",{source:y}),s.addDialog({component:rH})}},{id:"insert-media",label:"action.insert-media",kbd:"cmd+u,ctrl+u",onSelect(y){o("insert-media",{source:y}),s.insertMedia()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"cmd+z,ctrl+z",onSelect(y){o("undo",{source:y}),u.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"cmd+shift+z,ctrl+shift+z",onSelect(y){o("redo",{source:y}),u.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(y){let w=u.getSelectedShapeIds();w.length===0&&(w=Array.from(u.getCurrentPageShapeIds().values())),w.length!==0&&(o("export-as",{format:"svg",source:y}),s.exportAs(w,"svg",by(u,l)))}},{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(y){let w=u.getSelectedShapeIds();w.length===0&&(w=Array.from(u.getCurrentPageShapeIds().values())),w.length!==0&&(o("export-as",{format:"png",source:y}),s.exportAs(w,"png",by(u,l)))}},{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(y){let w=u.getSelectedShapeIds();w.length===0&&(w=Array.from(u.getCurrentPageShapeIds().values())),w.length!==0&&(o("export-all-as",{format:"svg",source:y}),s.exportAs(Array.from(u.getCurrentPageShapeIds()),"svg",by(u,l)))}},{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(y){const w=Array.from(u.getCurrentPageShapeIds().values());w.length!==0&&(o("export-all-as",{format:"png",source:y}),s.exportAs(w,"png",by(u,l)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"cmd+shift+c,ctrl+shift+c",readonlyOk:!0,onSelect(y){let w=u.getSelectedShapeIds();w.length===0&&(w=Array.from(u.getCurrentPageShapeIds().values())),w.length!==0&&(o("copy-as",{format:"svg",source:y}),s.copyAs(w,"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(y){let w=u.getSelectedShapeIds();w.length===0&&(w=Array.from(u.getCurrentPageShapeIds().values())),w.length!==0&&(o("copy-as",{format:"png",source:y}),s.copyAs(w,"png"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(y){p()&&(h()||(o("toggle-auto-size",{source:y}),u.markHistoryStoppingPoint("toggling auto size"),u.run(()=>{const w=u.getSelectedShapes().filter(C=>u.isShapeOfType(C,"text")&&C.props.autoSize===!1);u.updateShapes(w.map(C=>({id:C.id,type:C.type,props:{...C.props,w:8,autoSize:!0}}))),Bt(u,w.map(C=>C.id))})))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(y){o("open-embed-link",{source:y});const w=u.getSelectedShapeIds(),C="No embed shapes selected";if(w.length!==1){console.error(C);return}const T=u.getShape(w[0]);if(!T||!u.isShapeOfType(T,"embed")){console.error(C);return}_ce(T.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(y){var w,C;if(((w=u.root.getCurrent())==null?void 0:w.id)!=="zoom"&&(o("zoom-tool",{source:y}),!(u.inputs.shiftKey||u.inputs.ctrlKey))){const T=u.root.getCurrent();T&&((C=T.getCurrent())==null?void 0:C.id)==="idle"&&u.setCurrentTool("zoom",{onInteractionEnd:T.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(y){p()&&(h()||u.run(()=>{o("convert-to-bookmark",{source:y});const w=u.getSelectedShapes(),C=[],T=[];for(const E of w){if(!E||!u.isShapeOfType(E,"embed")||!E.props.url)continue;const _=new P(E.x,E.y);_.rot(-E.rotation),_.add(new P(E.props.w/2-300/2,E.props.h/2-320/2)),_.rot(E.rotation);const A={id:Nt(),type:"bookmark",rotation:E.rotation,x:_.x,y:_.y,opacity:1,props:{url:E.props.url}};C.push(A),T.push(E.id)}u.markHistoryStoppingPoint("convert shapes to bookmark"),u.deleteShapes(T),u.createShapes(C)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(y){p()&&(h()||(o("convert-to-embed",{source:y}),u.run(()=>{const w=u.getSelectedShapeIds(),C=st(w.map(_=>u.getShape(_))),T=[],E=[];for(const _ of C){if(!u.isShapeOfType(_,"bookmark"))continue;const{url:A}=_.props,O=s.getEmbedDefinition(A);if(!O||!O.definition)continue;const{width:D,height:F}=O.definition,U=new P(_.x,_.y);U.rot(-_.rotation),U.add(new P(_.props.w/2-D/2,_.props.h/2-F/2)),U.rot(_.rotation);const V={id:Nt(),type:"embed",x:U.x,y:U.y,rotation:_.rotation,props:{url:A,w:D,h:F}};T.push(V),E.push(_.id)}u.markHistoryStoppingPoint("convert shapes to embed"),u.deleteShapes(E),u.createShapes(T)})))}},{id:"duplicate",kbd:"cmd+d,ctrl+d",label:"action.duplicate",icon:"duplicate",onSelect(y){if(!p()||h())return;o("duplicate-shapes",{source:y});const w=u.getInstanceState();let C,T;if(w.duplicateProps)C=w.duplicateProps.shapeIds,T=w.duplicateProps.offset;else{C=u.getSelectedShapeIds();const E=ye.Common(st(C.map(_=>u.getShapePageBounds(_))));T=u.getCameraOptions().isLocked?{x:u.options.adjacentShapeMargin,y:u.options.adjacentShapeMargin}:{x:E.width+u.options.adjacentShapeMargin,y:0}}u.markHistoryStoppingPoint("duplicate shapes"),u.duplicateShapes(C,T),w.duplicateProps&&u.updateInstanceState({duplicateProps:{...w.duplicateProps,shapeIds:u.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"cmd+shift+g,ctrl+shift+g",icon:"ungroup",onSelect(y){p()&&(h()||(o("ungroup-shapes",{source:y}),u.markHistoryStoppingPoint("ungroup"),u.ungroupShapes(u.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"cmd+g,ctrl+g",icon:"group",onSelect(y){if(!p()||h())return;o("group-shapes",{source:y});const w=u.getOnlySelectedShape();w&&u.isShapeOfType(w,"group")?(u.markHistoryStoppingPoint("ungroup"),u.ungroupShapes(u.getSelectedShapeIds())):(u.markHistoryStoppingPoint("group"),u.groupShapes(u.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"cmd+shift+f,ctrl+shift+f",onSelect(y){if(!p())return;o("remove-frame",{source:y});const w=u.getSelectedShapes();w.length>0&&w.every(C=>u.isShapeOfType(C,"frame"))&&(u.markHistoryStoppingPoint("remove-frame"),Mge(u,w.map(C=>C.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(y){if(!p())return;o("fit-frame-to-content",{source:y});const w=u.getOnlySelectedShape();w&&u.isShapeOfType(w,"frame")&&(u.markHistoryStoppingPoint("fit-frame-to-content"),tH(u,w.id))}},{id:"align-left",label:"action.align-left",kbd:"alt+A",icon:"align-left",onSelect(y){p()&&(h()||(o("align-shapes",{operation:"left",source:y}),u.markHistoryStoppingPoint("align left"),u.run(()=>{const w=u.getSelectedShapeIds();u.alignShapes(w,"left"),Bt(u,w)})))}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"alt+H",icon:"align-center-horizontal",onSelect(y){p()&&(h()||(o("align-shapes",{operation:"center-horizontal",source:y}),u.markHistoryStoppingPoint("align center horizontal"),u.run(()=>{const w=u.getSelectedShapeIds();u.alignShapes(w,"center-horizontal"),Bt(u,w)})))}},{id:"align-right",label:"action.align-right",kbd:"alt+D",icon:"align-right",onSelect(y){p()&&(h()||(o("align-shapes",{operation:"right",source:y}),u.markHistoryStoppingPoint("align right"),u.run(()=>{const w=u.getSelectedShapeIds();u.alignShapes(w,"right"),Bt(u,w)})))}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"alt+V",icon:"align-center-vertical",onSelect(y){p()&&(h()||(o("align-shapes",{operation:"center-vertical",source:y}),u.markHistoryStoppingPoint("align center vertical"),u.run(()=>{const w=u.getSelectedShapeIds();u.alignShapes(w,"center-vertical"),Bt(u,w)})))}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"alt+W",onSelect(y){p()&&(h()||(o("align-shapes",{operation:"top",source:y}),u.markHistoryStoppingPoint("align top"),u.run(()=>{const w=u.getSelectedShapeIds();u.alignShapes(w,"top"),Bt(u,w)})))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"alt+S",onSelect(y){p()&&(h()||(o("align-shapes",{operation:"bottom",source:y}),u.markHistoryStoppingPoint("align bottom"),u.run(()=>{const w=u.getSelectedShapeIds();u.alignShapes(w,"bottom"),Bt(u,w)})))}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"alt+shift+h",onSelect(y){p()&&(h()||(o("distribute-shapes",{operation:"horizontal",source:y}),u.markHistoryStoppingPoint("distribute horizontal"),u.run(()=>{const w=u.getSelectedShapeIds();u.distributeShapes(w,"horizontal"),Bt(u,w)})))}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"alt+shift+V",onSelect(y){p()&&(h()||(o("distribute-shapes",{operation:"vertical",source:y}),u.markHistoryStoppingPoint("distribute vertical"),u.run(()=>{const w=u.getSelectedShapeIds();u.distributeShapes(w,"vertical"),Bt(u,w)})))}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(y){p()&&(h()||(o("stretch-shapes",{operation:"horizontal",source:y}),u.markHistoryStoppingPoint("stretch horizontal"),u.run(()=>{const w=u.getSelectedShapeIds();u.stretchShapes(w,"horizontal"),Bt(u,w)})))}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(y){p()&&(h()||(o("stretch-shapes",{operation:"vertical",source:y}),u.markHistoryStoppingPoint("stretch vertical"),u.run(()=>{const w=u.getSelectedShapeIds();u.stretchShapes(w,"vertical"),Bt(u,w)})))}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"shift+h",onSelect(y){p()&&(h()||(o("flip-shapes",{operation:"horizontal",source:y}),u.markHistoryStoppingPoint("flip horizontal"),u.run(()=>{const w=u.getSelectedShapeIds();u.flipShapes(w,"horizontal"),Bt(u,w)})))}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"shift+v",onSelect(y){p()&&(h()||(o("flip-shapes",{operation:"vertical",source:y}),u.markHistoryStoppingPoint("flip vertical"),u.run(()=>{const w=u.getSelectedShapeIds();u.flipShapes(w,"vertical"),Bt(u,w)})))}},{id:"pack",label:"action.pack",icon:"pack",onSelect(y){p()&&(h()||(o("pack-shapes",{source:y}),u.markHistoryStoppingPoint("pack"),u.run(()=>{const w=u.getSelectedShapeIds();u.packShapes(w,u.options.adjacentShapeMargin),Bt(u,w)})))}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(y){p()&&(h()||(o("stack-shapes",{operation:"vertical",source:y}),u.markHistoryStoppingPoint("stack-vertical"),u.run(()=>{const w=u.getSelectedShapeIds();u.stackShapes(w,"vertical",u.options.adjacentShapeMargin),Bt(u,w)})))}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(y){p()&&(h()||(o("stack-shapes",{operation:"horizontal",source:y}),u.markHistoryStoppingPoint("stack-horizontal"),u.run(()=>{const w=u.getSelectedShapeIds();u.stackShapes(w,"horizontal",u.options.adjacentShapeMargin),Bt(u,w)})))}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(y){p()&&(h()||(o("reorder-shapes",{operation:"toFront",source:y}),u.markHistoryStoppingPoint("bring to front"),u.bringToFront(u.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"alt+]",onSelect(y){p()&&(h()||(o("reorder-shapes",{operation:"forward",source:y}),u.markHistoryStoppingPoint("bring forward"),u.bringForward(u.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"alt+[",onSelect(y){p()&&(h()||(o("reorder-shapes",{operation:"backward",source:y}),u.markHistoryStoppingPoint("send backward"),u.sendBackward(u.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(y){p()&&(h()||(o("reorder-shapes",{operation:"toBack",source:y}),u.markHistoryStoppingPoint("send to back"),u.sendToBack(u.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"cmd+x,ctrl+x",onSelect(y){p()&&(h()||(u.markHistoryStoppingPoint("cut"),s.cut(y)))}},{id:"copy",label:"action.copy",kbd:"cmd+c,ctrl+c",readonlyOk:!0,onSelect(y){p()&&(h()||s.copy(y))}},{id:"paste",label:"action.paste",kbd:"cmd+v,ctrl+v",onSelect(y){var w;(w=navigator.clipboard)==null||w.read().then(C=>{s.paste(C,y,y==="context-menu"?u.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:"cmd+a,ctrl+a",readonlyOk:!0,onSelect(y){u.run(()=>{h()||(o("select-all-shapes",{source:y}),u.markHistoryStoppingPoint("select all kbd"),u.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(y){p()&&(h()||(o("select-none-shapes",{source:y}),u.markHistoryStoppingPoint("select none"),u.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del",icon:"trash",onSelect(y){p()&&(h()||(o("delete-shapes",{source:y}),u.markHistoryStoppingPoint("delete"),u.deleteShapes(u.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(y){p()&&(h()||(o("rotate-cw",{source:y}),u.markHistoryStoppingPoint("rotate-cw"),u.run(()=>{const w=u.getSelectionRotation()%(qt/2),C=ro(w,0)||ro(w,qt/2),T=u.getSelectedShapeIds();u.rotateShapesBy(T,qt/2-(C?0:w)),Bt(u,T)})))}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(y){p()&&(h()||(o("rotate-ccw",{source:y}),u.markHistoryStoppingPoint("rotate-ccw"),u.run(()=>{const w=u.getSelectionRotation()%(qt/2),C=ro(w,0),T=u.getSelectedShapeIds();u.rotateShapesBy(T,C?-(qt/2):-w),Bt(u,T)})))}},{id:"zoom-in",label:"action.zoom-in",kbd:"cmd+=,ctrl+=,=",readonlyOk:!0,onSelect(y){o("zoom-in",{source:y,towardsCursor:!1}),u.zoomIn(void 0,{animation:{duration:u.options.animationMediumMs}})}},{id:"zoom-in-on-cursor",label:"action.zoom-in",kbd:"shift+cmd+=,shift+ctrl+=,shift+=",readonlyOk:!0,onSelect(y){o("zoom-in",{source:y,towardsCursor:!0}),u.zoomIn(u.inputs.currentScreenPoint,{animation:{duration:u.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"cmd+-,ctrl+-,-",readonlyOk:!0,onSelect(y){o("zoom-out",{source:y,towardsCursor:!1}),u.zoomOut(void 0,{animation:{duration:u.options.animationMediumMs}})}},{id:"zoom-out-on-cursor",label:"action.zoom-out",kbd:"shift+cmd+-,shift+ctrl+-,shift+-",readonlyOk:!0,onSelect(y){o("zoom-out",{source:y,towardsCursor:!0}),u.zoomOut(u.inputs.currentScreenPoint,{animation:{duration:u.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"shift+0",readonlyOk:!0,onSelect(y){o("reset-zoom",{source:y}),u.resetZoom(void 0,{animation:{duration:u.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"shift+1",readonlyOk:!0,onSelect(y){o("zoom-to-fit",{source:y}),u.zoomToFit({animation:{duration:u.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"shift+2",readonlyOk:!0,onSelect(y){p()&&(h()||(o("zoom-to-selection",{source:y}),u.zoomToSelection({animation:{duration:u.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(y){o("toggle-snap-mode",{source:y}),u.user.updateUserPreferences({isSnapMode:!u.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"cmd+/,ctrl+/",readonlyOk:!0,onSelect(y){const w=u.user.getIsDarkMode()?"light":"dark";o("color-scheme",{source:y,value:w}),u.user.updateUserPreferences({colorScheme:w})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(y){o("toggle-wrap-mode",{source:y}),u.user.updateUserPreferences({isWrapMode:!u.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(y){o("toggle-dynamic-size-mode",{source:y}),u.user.updateUserPreferences({isDynamicSizeMode:!u.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-paste-at-cursor",label:{default:"action.toggle-paste-at-cursor",menu:"action.toggle-paste-at-cursor.menu"},readonlyOk:!1,onSelect(y){o("toggle-paste-at-cursor",{source:y}),u.user.updateUserPreferences({isPasteAtCursorMode:!u.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(y){o("toggle-reduce-motion",{source:y}),u.user.updateUserPreferences({animationSpeed:u.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(y){o("toggle-edge-scrolling",{source:y}),u.user.updateUserPreferences({edgeScrollSpeed:u.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(y){o("toggle-transparent",{source:y}),u.updateInstanceState({exportBackground:!u.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(y){o("toggle-tool-lock",{source:y}),u.updateInstanceState({isToolLocked:!u.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(y){o("unlock-all",{source:y});const w=[];for(const C of u.getCurrentPageShapes())C.isLocked&&w.push({id:C.id,type:C.type,isLocked:!1});w.length>0&&u.updateShapes(w)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"cmd+.,ctrl+.",checkbox:!0,onSelect(y){u.timers.requestAnimationFrame(()=>{u.run(()=>{o("toggle-focus-mode",{source:y}),s.clearDialogs(),s.clearToasts(),u.updateInstanceState({isFocusMode:!u.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"cmd+',ctrl+'",onSelect(y){o("toggle-grid-mode",{source:y}),u.updateInstanceState({isGridMode:!u.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(y){o("toggle-debug-mode",{source:y}),u.updateInstanceState({isDebugMode:!u.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"cmd+p,ctrl+p",readonlyOk:!0,onSelect(y){o("print",{source:y}),s.printSelectionOrPages()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(y){o("exit-pen-mode",{source:y}),u.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(y){o("stop-following",{source:y}),u.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(y){o("zoom-to-content",{source:y});const w=u.getSelectionPageBounds()??u.getCurrentPageBounds();w&&u.zoomToBounds(w,{targetZoom:Math.min(1,u.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"shift+l",onSelect(y){u.markHistoryStoppingPoint("locking"),o("toggle-lock",{source:y}),u.toggleLock(u.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(y){const w=es.createId(),C=u.getSelectedShapeIds();u.run(()=>{u.markHistoryStoppingPoint("move_shapes_to_page"),u.createPage({name:s.msg("page-menu.new-page-initial-name"),id:w}),u.moveShapesToPage(C,w)}),o("move-to-new-page",{source:y})}},{id:"select-white-color",label:"color-style.white",kbd:"alt+t",onSelect(y){const w=ts;u.run(()=>{u.markHistoryStoppingPoint("change-color"),u.isIn("select")&&u.setStyleForSelectedShapes(w,"white"),u.setStyleForNextShapes(w,"white")}),o("set-style",{source:y,id:w.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"alt+f",onSelect(y){const w=gu;u.run(()=>{u.markHistoryStoppingPoint("change-fill"),u.isIn("select")&&u.setStyleForSelectedShapes(w,"fill"),u.setStyleForNextShapes(w,"fill")}),o("set-style",{source:y,id:w.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"shift+f",onSelect:async y=>{const w=u.getSelectedShapeIds();if(w.length===0)return;u.markHistoryStoppingPoint("flattening to image"),o("flatten-to-image",{source:y});const C=await Bge(u,w,u.options.flattenImageBoundsExpand);C!=null&&C.length&&u.setSelectedShapes(C)}},{id:"select-geo-tool",kbd:"g",onSelect:async y=>{o("select-tool",{source:y,id:"geo-previous"}),u.setCurrentTool("geo")}},{id:"change-page-prev",kbd:"alt+left,alt+up",readonlyOk:!0,onSelect:async y=>{const w=u.getPages(),C=w.findIndex(T=>T.id===u.getCurrentPageId());C<1||(o("change-page",{source:y,direction:"prev"}),u.setCurrentPage(w[C-1].id))}},{id:"change-page-next",kbd:"alt+right,alt+down",readonlyOk:!0,onSelect:async y=>{const w=u.getPages(),C=w.findIndex(T=>T.id===u.getCurrentPageId());if(C===-1||C>=w.length-1){if(u.getCurrentPageShapes().length<=0||u.getIsReadonly())return;o("new-page",{source:y}),u.run(()=>{u.markHistoryStoppingPoint("creating page");const T=es.createId();u.createPage({name:s.msg("page-menu.new-page-initial-name"),id:T}),u.setCurrentPage(T)});return}u.setCurrentPage(w[C+1].id),o("change-page",{source:y,direction:"next"})}},{id:"adjust-shape-styles",label:"a11y.adjust-shape-styles",kbd:"cmd+Enter,ctrl+Enter",onSelect:async y=>{if(!p())return;const w=u.getContainer().querySelector(".tlui-style-panel button");w==null||w.focus(),o("adjust-shape-styles",{source:y})}},{id:"enlarge-shapes",label:"a11y.enlarge-shape",kbd:"cmd+alt+shift+=,ctrl+alt+shift+=",onSelect:async y=>{m(1.1),o("enlarge-shapes",{source:y})}},{id:"shrink-shapes",label:"a11y.shrink-shape",kbd:"cmd+alt+shift+-,ctrl+alt+shift+-",onSelect:async y=>{m(1/1.1),o("shrink-shapes",{source:y})}},{id:"a11y-repeat-shape-announce",kbd:"alt+r",label:"a11y.repeat-shape",readonlyOk:!0,onSelect:async y=>{const w=u.getSelectedShapeIds();if(!w.length)return;const C=B8({editor:u,selectedShapeIds:w,msg:a});C&&(i.announce({msg:""}),u.timers.requestAnimationFrame(()=>{i.announce({msg:C})}),o("a11y-repeat-shape-announce",{source:y}))}}];r&&S.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(y){o("open-cursor-chat",{source:y}),!u.getInstanceState().isCoarsePointer&&u.timers.requestAnimationFrame(()=>{u.updateInstanceState({isChatting:!0})})}});const v=xme(S);return n?n(u,v,s):v},[s,t,o,n,l,r,a,i]);return g.jsx(uH.Provider,{value:c,children:e})}function Lu(){const n=k.useContext(uH);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function eg(n,e){return n?typeof n=="string"?n:e?n[e]??n.default:void 0:void 0}function ho(){const n=Sr();return se("isReadonlyMode",()=>!!(n!=null&&n.getIsReadonly()),[n])}const AP=Tt.isDarwin?"⌘":"Ctrl",IN=Tt.isDarwin?"⌥":"Alt";function dH(n){return n===","?[","]:n.split(",")[0].split(/(\[\[[^\]]+\]\])/g).map(e=>e.startsWith("[[")?e.replace(/[[\]]/g,""):e.replace(/cmd\+/g,AP).replace(/ctrl\+/g,AP).replace(/alt\+/g,IN).replace(/shift\+/g,"⇧").replace(/\$/g,AP).replace(/\?/g,IN).replace(/!/g,"⇧").split("")).flat().map(e=>e[0].toUpperCase()+e.slice(1))}function RE(n){return"— "+dH(n).join(" ")}function Sp({children:n,visibleOnMobileLayout:e=!1}){const t=Ur();return!e&&t<vn.MOBILE?null:g.jsx("kbd",{className:"tlui-kbd",children:dH(n).map((r,s)=>g.jsx("span",{children:r},s))})}const hH=k.createContext(null);function wv(){const n=k.useContext(hH);if(!n)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return n}function as({type:n,sourceId:e,children:t}){return g.jsx(hH.Provider,{value:{type:n,sourceId:e},children:t})}function bv({id:n,kbd:e,label:t,readonlyOk:r,onSelect:s,toggle:o=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=wv(),u=ho(),h=Ke();if(u&&!r)return null;const p=eg(t,l),m=p?h(p):void 0;switch(l){case"menu":return g.jsxs(lpe,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:m,onSelect:S=>{s==null||s(c),nt(S)},disabled:i,checked:a,children:[g.jsx(Ya,{small:!0,label:h(a?"ui.checked":"ui.unchecked"),icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),m&&g.jsx("span",{className:"tlui-button__label",draggable:!1,children:m}),e&&g.jsx(Sp,{children:e})]});case"context-menu":return g.jsxs(Ffe,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:m,onSelect:S=>{s(c),nt(S)},disabled:i,checked:a,children:[g.jsx(Ya,{small:!0,label:h(a?"ui.checked":"ui.unchecked"),icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),m&&g.jsx("span",{className:"tlui-button__label",draggable:!1,children:m}),e&&g.jsx(Sp,{children:e})]},n);default:return null}}function ol(n,e){const t=Sr(),r=k.useCallback(i=>{i&&(t==null||t.complete()),e==null||e(i)},[t,e]),s=Bn(),o=k.useCallback(i=>{s(i,{source:"unknown",id:n})},[n,s]);return vse(t?`${n}-${t.contextId}`:n,r,o)}function W_({id:n,children:e,modal:t=!1,debugOpen:r=!1}){const[s,o]=ol(n);return g.jsx(P_,{open:r||s,dir:"ltr",modal:t,onOpenChange:o,children:e})}function V_({children:n,...e}){return g.jsx(k_,{dir:"ltr",asChild:!0,onTouchEnd:t=>nt(t),...e,children:n})}function G_({className:n,side:e="bottom",align:t="start",sideOffset:r=8,alignOffset:s=8,children:o}){const i=_n();return g.jsx(fv,{container:i,children:g.jsx(E_,{className:$e("tlui-menu",n),side:e,sideOffset:r,align:t,alignOffset:s,collisionPadding:4,children:o})})}function wme({id:n,children:e}){const[t,r]=ol(n);return g.jsx(cpe,{open:t,onOpenChange:r,children:e})}function bme({id:n,label:e,title:t,disabled:r}){return g.jsx(upe,{dir:"ltr",asChild:!0,disabled:r,children:g.jsxs(ht,{"data-testid":n,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[g.jsx(En,{children:e}),g.jsx(lt,{icon:"chevron-right",small:!0})]})})}function Cme({id:n,alignOffset:e=-1,sideOffset:t=-6,size:r="small",children:s}){const o=_n();return g.jsx(fv,{container:o,children:g.jsx(dpe,{"data-testid":n,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:t,collisionPadding:4,"data-size":r,children:s})})}function Pme({className:n,children:e}){return g.jsx("div",{dir:"ltr",className:$e("tlui-menu__group",n),children:e})}function kme({noClose:n,children:e}){return g.jsx(ape,{dir:"ltr",asChild:!0,onClick:n?nt:void 0,children:e})}function at({id:n,label:e,className:t,children:r}){const{type:s,sourceId:o}=wv(),i=Ke(),a=eg(e,s),l=a?i(a):void 0;switch(s){case"panel":return g.jsx("div",{className:$e("tlui-menu__group",t),"data-testid":`${o}-group.${n}`,children:r});case"menu":return g.jsx(Pme,{className:t,"data-testid":`${o}-group.${n}`,children:r});case"context-menu":return g.jsx("div",{dir:"ltr",className:$e("tlui-menu__group",t),"data-testid":`${o}-group.${n}`,children:r});case"keyboard-shortcuts":return g.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${n}`,children:[g.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:l}),g.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:r})]});default:return r}}function Fs({id:n,disabled:e=!1,label:t,size:r="small",children:s}){const{type:o,sourceId:i}=wv(),a=_n(),l=Ke(),c=t?typeof t=="string"?t:t[o]??t.default:void 0,u=c?l(c):void 0;switch(o){case"menu":return g.jsxs(wme,{id:`${i}-sub.${n}`,children:[g.jsx(bme,{id:`${i}-sub.${n}-button`,disabled:e,label:u,title:u}),g.jsx(Cme,{id:`${i}-sub.${n}-content`,size:r,children:s})]});case"context-menu":return e?null:g.jsxs(Eme,{id:`${i}-sub.${n}`,children:[g.jsx(z9,{dir:"ltr",disabled:e,asChild:!0,children:g.jsxs(ht,{"data-testid":`${i}-sub.${n}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[g.jsx(En,{children:u}),g.jsx(lt,{icon:"chevron-right",small:!0})]})}),g.jsx(C_,{container:a,children:g.jsx(B9,{"data-testid":`${i}-sub.${n}-content`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:s})})]});default:return s}}function Eme({id:n,children:e}){const[t,r]=ol(n);return g.jsx(F9,{open:t,onOpenChange:r,children:e})}const Ime=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Tme(){const n=ne(),e=Bn(),t=se("colorScheme",()=>n.user.getUserPreferences().colorScheme??(n.user.getIsDarkMode()?"dark":"light"),[n]);return g.jsx(Fs,{id:"help menu color-scheme",label:"menu.theme",children:g.jsx(at,{id:"theme",children:Ime.map(({colorScheme:r,label:s})=>g.jsx(bv,{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 _me=({id:n,component:e,onClose:t,preventBackgroundClose:r})=>{const{removeDialog:s}=Hg(),o=k.useRef(!1),i=_n(),a=k.useCallback(l=>{if(!l){if(t)try{t()}catch(c){console.warn(c)}s(n)}},[n,t,s]);return g.jsx(Sde,{onOpenChange:a,defaultOpen:!0,children:g.jsx(xde,{container:i,children:g.jsx(vde,{dir:"ltr",className:"tlui-dialog__overlay",onClick:l=>{o.current||!r&&l.target===l.currentTarget&&a(!1)},children:g.jsx(wde,{dir:"ltr",className:"tlui-dialog__content","aria-describedby":void 0,onMouseDown:()=>o.current=!0,onMouseUp:()=>o.current=!1,onInteractOutside:l=>{o.current=!1,r&&l.preventDefault()},children:g.jsx(e,{onClose:()=>{o.current=!1,a(!1)}})})})})})},Mme=k.memo(function(){const{dialogs:e}=Hg();return se("dialogs",()=>e.get(),[e]).map(r=>g.jsx(_me,{...r},r.id))}),Ame=4e3,Ome={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Rme({toast:n}){const{removeToast:e}=sl(),t=Ke(),r=a=>{a||e(n.id)},s=n.actions&&n.actions.length>0,o=n.icon||n.severity&&Ome[n.severity],i=n.iconLabel||(n.severity?t(`toast.${n.severity}`):"");return g.jsxs(cge,{onOpenChange:r,className:"tlui-toast__container",duration:n.keepOpen?1/0:Ame,"data-severity":n.severity,children:[o&&g.jsx("div",{className:"tlui-toast__icon",children:g.jsx(Ya,{label:i,icon:o})}),g.jsxs("div",{className:"tlui-toast__main","data-title":!!n.title,"data-description":!!n.description,"data-actions":!!n.actions,children:[g.jsxs("div",{className:"tlui-toast__content",children:[n.title&&g.jsx(uge,{className:"tlui-toast__title",children:n.title}),n.description&&g.jsx(dge,{className:"tlui-toast__description",children:n.description})]}),n.actions&&g.jsxs("div",{className:"tlui-toast__actions",children:[n.actions.map((a,l)=>g.jsx(hge,{altText:a.label,asChild:!0,onClick:a.onClick,children:g.jsx(ht,{type:a.type,children:g.jsx(En,{children:a.label})})},l)),g.jsx(xN,{asChild:!0,children:g.jsx(ht,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:g.jsx(En,{children:n.closeLabel??t("toast.close")})})})]})]}),!s&&g.jsx(xN,{asChild:!0,children:g.jsx(ht,{type:"normal",className:"tlui-toast__close",children:g.jsx(En,{children:n.closeLabel??t("toast.close")})})})]})}const Dme=k.memo(function(){const{toasts:e}=sl(),t=se("toasts",()=>e.get(),[]);return g.jsxs(g.Fragment,{children:[t.map(r=>g.jsx(Rme,{toast:r},r.id)),g.jsx(I7,{className:"tlui-toast__viewport"})]})});function Ci({actionId:n="",...e}){const r=Lu()[n];return r?g.jsx(bv,{...r,...e}):null}function DE(n){const e=Ke();return g.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...n,"aria-label":e("app.loading"),"aria-hidden":"false",children:g.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[g.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),g.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:g.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const In=We.forwardRef(({children:n,className:e,label:t,...r},s)=>g.jsx(Ege,{ref:s,...r,className:$e("tlui-toolbar-container",e),"aria-label":t,children:n})),Yn=We.forwardRef(({asChild:n,children:e,type:t,isActive:r,...s},o)=>g.jsx(Ige,{ref:o,asChild:n,draggable:!1,"data-isactive":r,...s,className:$e("tlui-button",`tlui-button__${t}`,s.className),children:e})),jme=({children:n,className:e,type:t,...r})=>g.jsx(Tge,{type:t,...r,className:$e("tlui-toolbar-toggle-group",e),children:n}),Lme=({children:n,className:e,type:t,value:r,...s})=>g.jsx(_ge,{...s,className:$e("tlui-button",`tlui-button__${t}`,"tlui-toolbar-toggle-group-item",e),value:r,children:n});function Pt({disabled:n=!1,spinner:e=!1,readonlyOk:t=!1,id:r,kbd:s,label:o,icon:i,iconLeft:a,onSelect:l,noClose:c,isSelected:u}){const{type:h,sourceId:p}=wv(),m=Ke(),[S,v]=k.useState(!1);if(ho()&&!t)return null;const w=eg(o,h),C=s?RE(s):void 0,T=w?m(w):void 0,E=T&&C?`${T} ${C}`:T;switch(h){case"menu":return g.jsx(kme,{children:g.jsxs(ht,{type:"menu","data-testid":`${p}.${r}`,disabled:n,title:E,onClick:_=>{c&&nt(_),S?v(!1):l(p)},children:[a&&g.jsx(lt,{icon:a,small:!0}),g.jsx(En,{children:T}),s&&g.jsx(Sp,{children:s})]})});case"context-menu":return n?null:g.jsxs(Nfe,{dir:"ltr",title:E,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${p}.${r}`,onSelect:_=>{c&&nt(_),S?v(!1):l(p)},children:[g.jsx("span",{className:"tlui-button__label",draggable:!1,children:T}),a&&g.jsx(lt,{icon:a,small:!0}),s&&g.jsx(Sp,{children:s}),e&&g.jsx(DE,{})]});case"panel":return g.jsxs(ht,{"data-testid":`${p}.${r}`,type:"menu",title:E,disabled:n,onClick:()=>l(p),children:[g.jsx(En,{children:T}),e?g.jsx(DE,{}):i&&g.jsx(lt,{icon:i})]});case"small-icons":case"icons":return g.jsx(Yn,{"data-testid":`${p}.${r}`,type:"icon",title:E,disabled:n,onClick:()=>l(p),children:g.jsx(lt,{icon:i,small:!0})});case"keyboard-shortcuts":return s?g.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${p}.${r}`,children:[g.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:T}),g.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:g.jsx(Sp,{visibleOnMobileLayout:!0,children:s})})]}):(console.warn(`Menu item '${o}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return g.jsxs(ht,{type:"low",onClick:()=>l(p),children:[g.jsx(lt,{icon:i}),g.jsx(En,{children:T})]});case"toolbar":return g.jsx(Yn,{"aria-label":T,"aria-pressed":u?"true":"false","data-testid":`tools.${r}`,"data-value":r,disabled:n,onClick:()=>l("toolbar"),onTouchStart:_=>{nt(_),l("toolbar")},role:"option",title:E,type:"tool",children:g.jsx(lt,{icon:i})});case"toolbar-overflow":return g.jsx(Yn,{"aria-label":T,"aria-pressed":u?"true":"false",isActive:u,className:"tlui-button-grid__button","data-testid":`tools.more.${r}`,"data-value":r,disabled:n,onClick:()=>l("toolbar"),role:"option",title:E,type:"icon",children:g.jsx(lt,{icon:i})});default:throw xt(h)}}function ce({actionId:n="",...e}){const r=Lu()[n];return r?g.jsx(Pt,{...r,...e}):null}const fH=k.createContext(null);function Nme({overrides:n,children:e}){const t=Sr(),r=Bn(),s=J0(),o=Ke(),i=K_(),a=k.useCallback((c,u,h)=>{s.announce({msg:o(u.label)}),r("select-tool",{source:c,id:h??u.id})},[s,o,r]),l=k.useMemo(()=>{if(!t)return{};const c=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(h){if(t.isIn("select")){const p=t.root.getCurrent();p.exit({},p.id),p.enter({},p.id)}t.setCurrentTool("select"),a(h,this)}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(h){t.setCurrentTool("hand"),a(h,this)}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(h){t.setCurrentTool("eraser"),a(h,this)}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(h){t.setCurrentTool("draw"),a(h,this)}},...[...ui.values].map(h=>({id:h,label:`tool.${h}`,meta:{geo:h},kbd:h==="rectangle"?"r":h==="ellipse"?"o":void 0,icon:"geo-"+h,onSelect(p){t.run(()=>{t.setStyleForNextShapes(ui,h),t.setCurrentTool("geo"),a(p,this,`geo-${h}`)})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(h){t.setCurrentTool("arrow"),a(h,this)}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(h){t.setCurrentTool("line"),a(h,this)}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(h){t.setCurrentTool("frame"),a(h,this)}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(h){t.setCurrentTool("text"),a(h,this)}},{id:"asset",label:"tool.media",icon:"tool-media",kbd:"cmd+u,ctrl+u",onSelect(h){i.insertMedia(),a(h,this,"media")}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(h){t.setCurrentTool("note"),a(h,this)}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(h){t.setCurrentTool("laser"),a(h,this)}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(h){i.addDialog({component:rH}),a(h,this)}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"shift+d",onSelect(h){t.setCurrentTool("highlight"),a(h,this)}}];c.forEach(h=>h.onSelect=h.onSelect.bind(h));const u=Object.fromEntries(c.map(h=>[h.id,h]));return n?n(t,u,i):u},[n,t,i,a]);return g.jsx(fH.Provider,{value:l,children:e})}function q_(){const n=k.useContext(fH);if(!n)throw new Error("useTools must be used within a ToolProvider");return n}function Es({toolId:n="",...e}){const r=q_()[n];return r?g.jsx(Pt,{...r,...e}):null}function Fme({children:n}){const e=ne();return se("shouldDisplayHandles",()=>{if(e.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(e.isInAny("select.editing_shape")){const r=e.getOnlySelectedShape();return r&&e.isShapeOfType(r,"note")}return!1},[e])?g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:n}):null}const TN=["right","bottom","left","top"],zme={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}},Bme={left:"x",right:"x",top:"y",bottom:"y"},Md={top:"bottom",right:"left",bottom:"top",left:"right"},tg={x:{v:(n,e)=>new P(n,e),loEdge:"left",hiEdge:"right",crossMid:"midY",gap:"gapX",midRange:"midXRange",self:"x",cross:"y",size:"width"},y:{v:(n,e)=>new P(e,n),loEdge:"top",hiEdge:"bottom",crossMid:"midX",gap:"gapY",midRange:"midYRange",self:"y",cross:"x",size:"height"}},$me=new zo;function xp(n){return $me.get(n,()=>hn("arrowTarget",null))}function Ume(n){return xp(n).get()}function Y_(n){xp(n).set(null)}function Cv({editor:n,pointInPageSpace:e,arrow:t,isPrecise:r,isExact:s,currentBinding:o,oppositeBinding:i}){if(n.inputs.ctrlKey)return xp(n).set(null),null;const a=n.getShapeUtil("arrow"),l=t?t.props.kind:n.getStyleForNextShape(jp),c=n.getShapeAtPoint(e,{hitInside:!0,hitFrameInside:!0,margin:l==="elbow"?8:0,filter:z=>!z.isLocked&&n.canBindShapes({fromShape:t??Hme,toShape:z,binding:"arrow"})});if(!c)return xp(n).set(null),null;const u=n.getShapeGeometry(c),h=ye.ZeroFix(u.bounds),p=u.center,m=n.getShapePageTransform(c),S=n.getPointInShapeSpace(c,e),v=Math.max(u.bounds.width,u.bounds.height),y=cc(zme,(z,G)=>{const q=tg[Bme[z]],$=P.Mul(G,v).add(p);let K=!1,J=q.v(h[z],h[q.crossMid]),H=0;const te=u.intersectLineSegment(p,$,qi.EXCLUDE_NON_STANDARD);for(const Pe of te){const ue=P.Dist2(Pe,p);ue>H&&(H=ue,J=Pe,K=u.isClosed)}return{point:m.applyToPoint(J),isEnabled:K,far:m.applyToPoint($)}}),w=n.getZoomLevel(),C=a.options.minElbowHandleDistance/w,T=m.applyToPoint(p);for(const z of Z3(y)){const G=y[z];P.DistMin(G.point,T,C)&&(G.isEnabled=!1)}let E=r||s;E||(!o||o&&c.id!==o.toId)&&(E=n.inputs.pointerVelocity.len()<.5),r||(u.isClosed||(E=!0),i&&c.id===i.toId&&i.props.isPrecise&&(E=!0));const _=!s&&E&&u.isClosed,A=!s&&(E&&l==="elbow"||!u.isClosed),O=!s&&E&&l==="elbow"&&u.isClosed,D=E&&(u.isClosed||s),F=!s&&E&&l==="elbow"&&u.isClosed;let U="none",V=e;if(D||(U="center",V=T),A){const z=D?Cy(n,h,a.options.elbowArrowEdgeSnapDistance):1/0,G=u.nearestPoint(S,{includeLabels:!1,includeInternal:!1}),q=m.applyToPoint(G);P.Dist(q,e)<z&&(U="edge",V=q)}if(F){const z=Cy(n,h,a.options.elbowArrowAxisSnapDistance),G=P.DistanceToLineSegment(y.left.far,y.right.far,e),q=P.DistanceToLineSegment(y.top.far,y.bottom.far,e),$=G<q&&G<z?"x":q<z?"y":null;if($){const K=tg[$],J=P.Dist2(y[K.loEdge].far,e),H=P.Dist2(y[K.hiEdge].far,e),te=J<H?K.loEdge:K.hiEdge;y[te].isEnabled&&(U="edge-point",V=y[te].point)}}if(O){const z=Cy(n,h,a.options.elbowArrowPointSnapDistance);let G=null,q=1/0;for(const[$,K]of Qr(y)){if(!K.isEnabled)continue;const J=P.Dist(K.point,e);J<z&&J<q&&(q=J,G=$)}G&&(U="edge-point",V=y[G].point)}if(_){const z=Cy(n,h,l==="elbow"?a.options.elbowArrowCenterSnapDistance:a.options.arcArrowCenterSnapDistance);P.Dist(S,h.center)<z&&(U="center",V=T)}const Y=n.getPointInShapeSpace(c,V),j={x:rh(h.minX,h.maxX,Y.x),y:rh(h.minY,h.maxY,Y.y)},N={target:c,arrowKind:l,handlesInPageSpace:y,centerInPageSpace:T,anchorInPageSpace:V,isExact:s,isPrecise:E,snap:U,normalizedAnchor:j};return xp(n).set(N),N}const Hme={type:"arrow"};function Cy(n,e,t){return $t(Math.min(e.width,e.height)*.15,4,t)/n.getZoomLevel()}function Kme(){const n=ne();return se("should show arrow hints",()=>{if(n.isInAny("arrow.idle","arrow.pointing"))return!0;if(n.isIn("select.pointing_handle")){const t=n.getStateDescendant("select.pointing_handle");if(t.info.shape.type==="arrow"&&(t.info.handle.id==="start"||t.info.handle.id==="end"))return!0}if(n.isIn("select.dragging_handle")){const t=n.getStateDescendant("select.dragging_handle");if(t.info.shape.type==="arrow"&&(t.info.handle.id==="start"||t.info.handle.id==="end"))return!0}return!1},[n])?g.jsx(Wme,{}):null}function Wme(){const n=ne(),{ShapeIndicator:e}=Ft(),t=se("arrow target info",()=>Ume(n),[n]);if(!t)return null;const{handlesInPageSpace:r,snap:s,anchorInPageSpace:o,arrowKind:i,isExact:a,isPrecise:l}=t,c=!a&&i==="elbow";return g.jsxs(g.Fragment,{children:[e&&g.jsx(e,{shapeId:t.target.id}),c&&g.jsxs("svg",{className:"tl-overlays__item",children:[g.jsx("circle",{cx:o.x,cy:o.y,className:`tl-arrow-hint-snap tl-arrow-hint-snap__${l?s??"none":"none"}`}),Object.entries(r).map(([u,h])=>h.isEnabled?g.jsx("circle",{cx:h.point.x,cy:h.point.y,className:"tl-arrow-hint-handle"},u):null)]})]})}const{PI:Vme}=Math,nh=Vme+1e-4;function pH(n,e={}){const{size:t=16,smoothing:r=.5}=e;if(n.length===0||t<=0)return{left:[],right:[]};const s=n[0],o=n[n.length-1],i=o.runningLength,a=Math.pow(t*r,2),l=[],c=[];let u=n[0].vector,h=n[0].point,p=h,m=h,S=p,v=!1,y;for(let w=0;w<n.length;w++){y=n[w];const{point:C,vector:T}=n[w],E=y.vector.dpr(u),_=(w<n.length-1?n[w+1]:n[w]).vector,A=w<n.length-1?_.dpr(y.vector):1,O=E<0&&!v,D=A!==null&&A<.2;if(O||D){if(A>-.62&&i-y.runningLength>y.radius){const U=u.clone().mul(y.radius);u.clone().cpr(_)<0?(m=P.Add(C,U),S=P.Sub(C,U)):(m=P.Sub(C,U),S=P.Add(C,U)),l.push(m),c.push(S)}else{const U=u.clone().mul(y.radius).per(),V=P.Sub(y.input,U);for(let Y=1/13,j=0;j<1;j+=Y)m=P.RotWith(V,y.input,nh*j),l.push(m),S=P.RotWith(V,y.input,nh+nh*-j),c.push(S)}h=m,p=S,D&&(v=!0);continue}if(v=!1,y===s||y===o){const U=P.Per(T).mul(y.radius);l.push(P.Sub(C,U)),c.push(P.Add(C,U));continue}const F=P.Lrp(_,T,A).per().mul(y.radius);m=P.Sub(C,F),(w<=1||P.Dist2(h,m)>a)&&(l.push(m),h=m),S=P.Add(C,F),(w<=1||P.Dist2(p,S)>a)&&(c.push(S),p=S),u=T}return{left:l,right:c}}function X_(n,e={}){const{size:t=16,start:r={},end:s={},last:o=!1}=e,{cap:i=!0}=r,{cap:a=!0}=s;if(n.length===0||t<=0)return[];const l=n[0],c=n[n.length-1],u=c.runningLength,h=r.taper===!1?0:r.taper===!0?Math.max(t,u):r.taper,p=s.taper===!1?0:s.taper===!0?Math.max(t,u):s.taper,{left:m,right:S}=pH(n,e),v=l.point,y=n.length>1?n[n.length-1].point:P.AddXY(l.point,1,1);if(n.length===1&&(!(h||p)||o)){const E=P.Add(v,P.Sub(v,y).uni().per().mul(-l.radius)),_=[];for(let A=1/13,O=A;O<=1;O+=A)_.push(P.RotWith(E,v,nh*2*O));return _}const w=[];if(!(h||p&&n.length===1))if(i)for(let E=1/8,_=E;_<=1;_+=E){const A=P.RotWith(S[0],v,nh*_);w.push(A)}else{const E=P.Sub(m[0],S[0]),_=P.Mul(E,.5),A=P.Mul(E,.51);w.push(P.Sub(v,_),P.Sub(v,A),P.Add(v,A),P.Add(v,_))}const C=[],T=c.vector.clone().per().neg();if(p||h&&n.length===1)C.push(y);else if(a){const E=P.Add(y,P.Mul(T,c.radius));for(let _=1/29,A=_;A<1;A+=_)C.push(P.RotWith(E,y,nh*3*A))}else C.push(P.Add(y,P.Mul(T,c.radius)),P.Add(y,P.Mul(T,c.radius*.99)),P.Sub(y,P.Mul(T,c.radius*.99)),P.Sub(y,P.Mul(T,c.radius)));return m.concat(C,S.reverse(),w)}const Gme=.025,qme=.01;function na(n,e={}){var y;const{streamline:t=.5,size:r=16,simulatePressure:s=!1}=e;if(n.length===0)return[];const o=.15+(1-t)*.85;let i=n.map(P.From),a=0;if(!s){let w=i[0];for(;w&&!(w.z>=Gme);)i.shift(),w=i[0]}if(!s){let w=i[i.length-1];for(;w&&!(w.z>=qme);)i.pop(),w=i[i.length-1]}if(i.length===0)return[{point:P.From(n[0]),input:P.From(n[0]),pressure:s?.5:.15,vector:new P(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(P.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(P.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=e.last||!e.simulatePressure||i.length>1&&P.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&e.simulatePressure){const w=i[1];i=i.slice(0,-1);for(let C=1;C<5;C++){const T=P.Lrp(i[0],w,C/4);T.z=(i[0].z+(w.z-i[0].z))*C/4,i.push(T)}}const h=[{point:i[0],input:i[0],pressure:s?.5:i[0].z,vector:new P(1,1),distance:0,runningLength:0,radius:1}];let p=0,m=h[0],S,v;u&&t>0&&i.push(i[i.length-1].clone());for(let w=1,C=i.length;w<C;w++)S=!o||e.last&&w===C-1?i[w].clone():i[w].clone().lrp(m.point,1-o),!m.point.equals(S)&&(v=P.Dist(S,m.point),p+=v,!(w<4&&p<r)&&(m={input:i[w],point:S,pressure:s?.5:i[w].z,vector:P.Sub(m.point,S).uni(),distance:v,runningLength:p,radius:1},h.push(m)));if((y=h[1])!=null&&y.vector&&(h[0].vector=h[1].vector.clone()),p<1){const w=Math.max(.5,...h.map(C=>C.pressure));h.forEach(C=>C.pressure=w)}return h}const{min:_l}=Math,OP=.275;function Pv(n,e){const{size:t=16,thinning:r=.5,simulatePressure:s=!0,easing:o=y=>y,start:i={},end:a={}}=e,{easing:l=qn.easeOutQuad}=i,{easing:c=qn.easeOutCubic}=a,u=n[n.length-1].runningLength;let h,p=n[0].pressure,m;if(!s&&u<t){const y=n.reduce((w,C)=>Math.max(w,C.pressure),.5);return n.forEach(w=>{w.pressure=y,w.radius=t*o(.5-r*(.5-w.pressure))}),n}else{let y;for(let w=0,C=n.length;w<C&&(m=n[w],!(m.runningLength>t*5));w++){const T=_l(1,m.distance/t);if(s){const E=_l(1,1-T);y=_l(1,p+(E-p)*(T*OP))}else y=_l(1,p+(m.pressure-p)*.5);p=p+(y-p)*.5}for(let w=0;w<n.length;w++){if(m=n[w],r){let{pressure:C}=m;const T=_l(1,m.distance/t);if(s){const E=_l(1,1-T);C=_l(1,p+(E-p)*(T*OP))}else C=_l(1,p+(C-p)*(T*OP));m.radius=t*o(.5-r*(.5-C)),p=C}else m.radius=t/2;h===void 0&&(h=m.radius)}}const S=i.taper===!1?0:i.taper===!0?Math.max(t,u):i.taper,v=a.taper===!1?0:a.taper===!0?Math.max(t,u):a.taper;if(S||v)for(let y=0;y<n.length;y++){m=n[y];const{runningLength:w}=m,C=w<S?l(w/S):1,T=u-w<v?c((u-w)/v):1;m.radius=Math.max(.01,m.radius*Math.min(C,T))}return n}function Yme(n,e={}){return X_(Pv(na(n,e),e),e)}function _N({scribble:n,zoom:e,color:t,opacity:r,className:s}){if(!n.points.length)return null;const o=Yme(n.points,{size:n.size/e,start:{taper:n.taper,easing:qn.linear},last:n.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(o.length<4){const a=n.size/e/2,{x:l,y:c}=n.points[n.points.length-1];i=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=lT(o);return g.jsx("svg",{className:s&&$e("tl-overlays__item",s),children:g.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${n.color})`,opacity:r??n.opacity})})}function Xme({size:n,width:e,height:t,hideAlternateHandles:r}){const s=Q(n/3),o=s/2,i=Ke();return g.jsxs("svg",{className:"tl-overlays__item",children:[g.jsx("polyline",{className:"tl-corner-crop-handle",points:`
434
+ ${Q(0-o)},${Q(n)}
435
+ ${Q(0-o)},${Q(0-o)}
436
+ ${Q(n)},${Q(0-o)}`,strokeWidth:s,"data-testid":"selection.crop.top_left",role:"button","aria-label":i("handle.crop.top-left")}),g.jsx("line",{className:$e("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:Q(e/2-n),y1:Q(0-o),x2:Q(e/2+n),y2:Q(0-o),strokeWidth:s,"data-testid":"selection.crop.top",role:"button","aria-label":i("handle.crop.top")}),g.jsx("polyline",{className:$e("tl-corner-crop-handle",{"tl-hidden":r}),points:`
437
+ ${Q(e-n)},${Q(0-o)}
438
+ ${Q(e+o)},${Q(0-o)}
439
+ ${Q(e+o)},${Q(n)}`,strokeWidth:s,"data-testid":"selection.crop.top_right",role:"button","aria-label":i("handle.crop.top-right")}),g.jsx("line",{className:$e("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:Q(e+o),y1:Q(t/2-n),x2:Q(e+o),y2:Q(t/2+n),strokeWidth:s,"data-testid":"selection.crop.right",role:"button","aria-label":i("handle.crop.right")}),g.jsx("polyline",{className:"tl-corner-crop-handle",points:`
440
+ ${Q(e+o)},${Q(t-n)}
441
+ ${Q(e+o)},${Q(t+o)}
442
+ ${Q(e-n)},${Q(t+o)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_right",role:"button","aria-label":i("handle.crop.bottom-right")}),g.jsx("line",{className:$e("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:Q(e/2-n),y1:Q(t+o),x2:Q(e/2+n),y2:Q(t+o),strokeWidth:s,"data-testid":"selection.crop.bottom",role:"button","aria-label":i("handle.crop.bottom")}),g.jsx("polyline",{className:$e("tl-corner-crop-handle",{"tl-hidden":r}),points:`
443
+ ${Q(0+n)},${Q(t+o)}
444
+ ${Q(0-o)},${Q(t+o)}
445
+ ${Q(0-o)},${Q(t-n)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_left",role:"button","aria-label":i("handle.crop.bottom-left")}),g.jsx("line",{className:$e("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:Q(0-o),y1:Q(t/2-n),x2:Q(0-o),y2:Q(t/2+n),strokeWidth:s,"data-testid":"selection.crop.left",role:"button","aria-label":i("handle.crop.left")})]})}const Zme=tr(function({bounds:e,rotation:t}){const r=ne(),s=Ke(),o=k.useRef(null),i=ho(),a=zi("top"),l=zi("right"),c=zi("bottom"),u=zi("left"),h=zi("top_left"),p=zi("top_right"),m=zi("bottom_right"),S=zi("bottom_left"),v=r.getInstanceState().cursor.type==="default",y=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),C=w&&r.isShapeOrAncestorLocked(w),T=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0,E=T instanceof ye?e.clone().expand(T).zeroFix():e.clone().expandBy(T).zeroFix();if(yg(o,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}),w&&r.isShapeHidden(w))return null;const _=r.getZoomLevel(),A=r.getInstanceState().isChangingStyle,O=E.width,D=E.height,F=8/_,U=O<F*2,V=D<F*2,Y=O<F*4,j=D<F*4,N=O<F*5,z=D<F*5,G=y?1.75:1,q=6/_*G,$=(Y?q/2:q)*(G*.75),K=(j?q/2:q)*(G*.75),J=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!A;let H=J&&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")||J&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&H&&Tt.isFirefox&&r.isShapeOfType(w,"embed")&&(H=!1);const te=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!A&&!i,he=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!A&&!i,Pe=!y&&!(U||V)&&(he||te)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!C,ue=y&&(!Y||!j)&&(he||te)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!C,Ae=he&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!te&&!C,ze=U||V,ve=U&&V,Te=N||z,je=Ae||te,At=!Pe,on=!he||!ue,_t=!he||!je,Ot=!he||!je||ze,an=!he||!je||ze,rr=!he||!je||ve&&!te;let Hr=!0,zs=!0;if(te)Hr=Te,zs=Te;else if(Ae){Hr=ze||ve||y;const gs=y&&w&&w.type==="text";zs=Hr&&!gs}const $n=Math.min(24/_,D-K*3),ps=he&&y&&w&&r.isShapeOfType(w,"text")&&$n*_>=4;return g.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:g.jsxs("g",{ref:o,children:[H&&g.jsx("rect",{className:"tl-selection__fg__outline",width:Q(O),height:Q(D)}),g.jsx(Py,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:q,corner:"top_left_rotate",cursor:v?qs("nwse-rotate",t):void 0,isHidden:At}),g.jsx(Py,{"data-testid":"selection.rotate.top-right",cx:O+q*3,cy:0,targetSize:q,corner:"top_right_rotate",cursor:v?qs("nesw-rotate",t):void 0,isHidden:At}),g.jsx(Py,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:D+q*3,targetSize:q,corner:"bottom_left_rotate",cursor:v?qs("swne-rotate",t):void 0,isHidden:At}),g.jsx(Py,{"data-testid":"selection.rotate.bottom-right",cx:O+q*3,cy:D+q*3,targetSize:q,corner:"bottom_right_rotate",cursor:v?qs("senw-rotate",t):void 0,isHidden:At}),g.jsx(Qme,{"data-testid":"selection.rotate.mobile",cx:Y?-q*1.5:O/2,cy:Y?D/2:-q*1.5,size:F,isHidden:on}),g.jsx(Ml,{hide:Hr,dataTestId:"selection.resize.top",ariaLabel:s("handle.resize-top"),x:0,y:Q(0-(j?K*2:K)),width:Q(O),height:Q(Math.max(1,K*2)),cursor:v?qs("ns-resize",t):void 0,events:a}),g.jsx(Ml,{hide:zs,dataTestId:"selection.resize.right",ariaLabel:s("handle.resize-right"),x:Q(O-(Y?0:$)),y:0,height:Q(D),width:Q(Math.max(1,$*2)),cursor:v?qs("ew-resize",t):void 0,events:l}),g.jsx(Ml,{hide:Hr,dataTestId:"selection.resize.bottom",ariaLabel:s("handle.resize-bottom"),x:0,y:Q(D-(j?0:K)),width:Q(O),height:Q(Math.max(1,K*2)),cursor:v?qs("ns-resize",t):void 0,events:c}),g.jsx(Ml,{hide:zs,dataTestId:"selection.resize.left",ariaLabel:s("handle.resize-left"),x:Q(0-(Y?$*2:$)),y:0,height:Q(D),width:Q(Math.max(1,$*2)),cursor:v?qs("ew-resize",t):void 0,events:u}),g.jsx(Ml,{hide:_t,dataTestId:"selection.target.top-left",ariaLabel:s("handle.resize-top-left"),x:Q(0-(Y?$*2:$*1.5)),y:Q(0-(j?K*2:K*1.5)),width:Q($*3),height:Q(K*3),cursor:v?qs("nwse-resize",t):void 0,events:h}),g.jsx(Ml,{hide:Ot,dataTestId:"selection.target.top-right",ariaLabel:s("handle.resize-top-right"),x:Q(O-(Y?0:$*1.5)),y:Q(0-(j?K*2:K*1.5)),width:Q($*3),height:Q(K*3),cursor:v?qs("nesw-resize",t):void 0,events:p}),g.jsx(Ml,{hide:rr,dataTestId:"selection.target.bottom-right",ariaLabel:s("handle.resize-bottom-right"),x:Q(O-(Y?$:$*1.5)),y:Q(D-(j?K:K*1.5)),width:Q($*3),height:Q(K*3),cursor:v?qs("nwse-resize",t):void 0,events:m}),g.jsx(Ml,{hide:an,dataTestId:"selection.target.bottom-left",ariaLabel:s("handle.resize-bottom-left"),x:Q(0-(Y?$*3:$*1.5)),y:Q(D-(j?0:K*1.5)),width:Q($*3),height:Q(K*3),cursor:v?qs("nesw-resize",t):void 0,events:S}),Ae&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.resize.top-left",className:$e("tl-corner-handle",{"tl-hidden":_t}),x:Q(0-F/2),y:Q(0-F/2),width:Q(F),height:Q(F)}),g.jsx("rect",{"data-testid":"selection.resize.top-right",className:$e("tl-corner-handle",{"tl-hidden":Ot}),x:Q(O-F/2),y:Q(0-F/2),width:Q(F),height:Q(F)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:$e("tl-corner-handle",{"tl-hidden":rr}),x:Q(O-F/2),y:Q(D-F/2),width:Q(F),height:Q(F)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:$e("tl-corner-handle",{"tl-hidden":an}),x:Q(0-F/2),y:Q(D-F/2),width:Q(F),height:Q(F)})]}),ps&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle",x:Q(0-F/4),y:Q(D/2-$n/2),rx:F/4,width:Q(F/2),height:Q($n)}),g.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle",rx:F/4,x:Q(O-F/4),y:Q(D/2-$n/2),width:Q(F/2),height:Q($n)})]}),te&&g.jsx(Xme,{size:F,width:O,height:D,hideAlternateHandles:Te})]})})}),Ml=function({hide:e,dataTestId:t,ariaLabel:r,x:s,y:o,width:i,height:a,cursor:l,events:c}){return g.jsx("rect",{className:$e("tl-resize-handle","tl-transparent",{"tl-hidden":e}),"data-testid":t,role:"button","aria-label":r,pointerEvents:"all",x:s,y:o,width:i,height:a,cursor:l,...c})},Py=function({cx:e,cy:t,targetSize:r,corner:s,cursor:o,isHidden:i,"data-testid":a}){const l=zi(s),u=Ke()(`handle.rotate.${s}`);return g.jsx("rect",{className:$e("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,role:"button","aria-label":u,pointerEvents:"all",x:Q(e-r*3),y:Q(t-r*3),width:Q(Math.max(1,r*3)),height:Q(Math.max(1,r*3)),cursor:o,...l})},Jme=Math.sqrt(Math.PI),Qme=function({cx:e,cy:t,size:r,isHidden:s,"data-testid":o}){const i=zi("mobile_rotate"),a=ne(),l=se("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l)),u=Ke();return g.jsxs("g",{role:"button","aria-label":u("handle.rotate.mobile_rotate"),children:[g.jsx("circle",{"data-testid":o,pointerEvents:"all",className:$e("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":s}),cx:e,cy:t,r:c,...i}),g.jsx("circle",{className:$e("tl-mobile-rotate__fg",{"tl-hidden":s}),cx:e,cy:t,r:r/Jme})]})};function eye(){const n=ne(),e=se("is in a valid select state",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle"),[n]);return g.jsx(w4,{hideAll:!e})}function xx(n,e,t){const{arrowheadStart:r,arrowheadEnd:s}=e.props,o=Wd(n,e,t),i=o.start.clone(),a=o.end.clone(),l=P.Med(i,a);if(P.Equals(i,a))return{bindings:t,type:"straight",start:{handle:i,point:i,arrowhead:e.props.arrowheadStart},end:{handle:a,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:!1,length:0};const c=P.Sub(a,i).uni(),u=wx(n,e,"start"),h=wx(n,e,"end"),p=n.getShapePageTransform(e);MN(a,o.start,p,h),MN(i,o.end,p,u);let m=0,S=0,v=0,y=0,w=vp*e.props.scale;const C=u&&h&&u.shape===h.shape,T=u&&h?Z_(n,u.shape.id,h.shape.id):"safe";T==="safe"&&u&&h&&!C&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(vp*e.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(vp*e.props.scale))));const E=P.Sub(a,i),_=P.Len(E)?E.uni():P.From(E),A=!P.Equals(_,c);C||(T!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(v=Oo[e.props.size]/2+("size"in u.shape.props?Oo[u.shape.props.size]/2:0),m=(ng+v)*e.props.scale,w+=v*e.props.scale),T!=="end-contains-start"&&h&&s!=="none"&&!h.isExact&&(y=Oo[e.props.size]/2+("size"in h.shape.props?Oo[h.shape.props.size]/2:0),S=(ng+y)*e.props.scale,w+=y*e.props.scale));const O=i.clone().add(_.clone().mul(m*(A?-1:1))),D=a.clone().sub(_.clone().mul(S*(A?-1:1)));P.DistMin(O,D,w)&&(m!==0&&S!==0?(m*=-1.5,S*=-1.5):m!==0?m*=-1:S!==0&&(S*=-1)),i.add(_.clone().mul(m*(A?-1:1))),a.sub(_.clone().mul(S*(A?-1:1))),A?(u&&h&&a.setTo(P.Add(i,_.clone().mul(-10*e.props.scale))),l.setTo(P.Med(o.start,o.end))):l.setTo(P.Med(i,a));const F=P.Dist(i,a);return{bindings:t,type:"straight",start:{handle:o.start,point:i,arrowhead:e.props.arrowheadStart},end:{handle:o.end,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:F>0,length:F}}function MN(n,e,t,r){if(r===void 0||r.isExact)return;const s=de.applyToPoint(t,e),o=de.applyToPoint(t,n),i=de.applyToPoint(de.Inverse(r.transform),s),a=de.applyToPoint(de.Inverse(r.transform),o),l=Array.from(r.geometry.intersectLineSegment(i,a,{includeLabels:!1,includeInternal:!1}));let c;if(l.length&&(c=l.sort((p,m)=>P.Dist2(p,i)-P.Dist2(m,i))[0]??(r.isClosed?void 0:a)),c===void 0&&(c=r.geometry.nearestPoint(a),!P.DistMin(c,a,1)))return;const u=de.applyToPoint(r.transform,c),h=de.applyToPoint(de.Inverse(t),u);n.setTo(h),r.didIntersect=!0}function tye(n,e,t){const{arrowheadEnd:r,arrowheadStart:s}=e.props,o=e.props.bend;if(Math.abs(o)>Math.abs(e.props.bend*(wye*e.props.scale)))return xx(n,e,t);const i=Wd(n,e,t),a=P.Med(i.start,i.end),l=P.Sub(i.end,i.start),c=P.Len(l)?l.uni():P.From(l),u=P.Add(a,c.per().mul(-o)),h=wx(n,e,"start"),p=wx(n,e,"end"),m=i.start.clone(),S=i.end.clone(),v=u.clone();if(P.Equals(m,S))return{bindings:t,type:"straight",start:{handle:m,point:m,arrowhead:e.props.arrowheadStart},end:{handle:S,point:S,arrowhead:e.props.arrowheadEnd},middle:v,isValid:!1,length:0};const y=e.props.bend<0,w=y?x0:nJ,C=AN(m,S,v),T=P.Angle(C.center,m),E=P.Angle(C.center,S),_=w(T,E);if(C.length===0||C.size===0||!GD(C.length)||!GD(C.size))return xx(n,e,t);const A=m.clone(),O=S.clone(),D=v.clone(),F=n.getShapePageTransform(e);let U=0,V=0,Y=vp*e.props.scale;if(h&&!h.isExact){const J=de.applyToPoint(F,A),H=de.applyToPoint(F,C.center),te=de.applyToPoint(F,O),he=de.Inverse(h.transform),Pe=de.applyToPoint(he,J),ue=de.applyToPoint(he,H),Ae=de.applyToPoint(he,te),{isClosed:ze}=h;let ve,Te=Array.from(h.geometry.intersectCircle(ue,C.radius,{includeLabels:!1,includeInternal:!1}));if(Te.length){const je=ue.angle(Pe),At=ue.angle(Ae),on=w(je,At);Te=Te.filter(Ot=>w(je,ue.angle(Ot))<=on);const _t=on*.25;Te.sort(ze?(Ot,an)=>Math.abs(w(je,ue.angle(Ot))-_t)<Math.abs(w(je,ue.angle(an))-_t)?-1:1:(Ot,an)=>w(je,ue.angle(Ot))<w(je,ue.angle(an))?-1:1),ve=Te[0]}if(!ve)if(ze){const je=h.geometry.nearestPoint(Pe);P.DistMin(je,Pe,1)&&(ve=je)}else ve=Pe;if(ve&&(A.setTo(n.getPointInShapeSpace(e,de.applyToPoint(h.transform,ve))),h.didIntersect=!0,s!=="none")){const je=Oo[e.props.size]/2+("size"in h.shape.props?Oo[h.shape.props.size]/2:0);U=(ng+je)*e.props.scale,Y+=je*e.props.scale}}if(p&&!p.isExact){const J=de.applyToPoint(F,A),H=de.applyToPoint(F,O),te=de.applyToPoint(F,C.center),he=de.Inverse(p.transform),Pe=de.applyToPoint(he,J),ue=de.applyToPoint(he,te),Ae=de.applyToPoint(he,H),ze=p.isClosed;let ve,Te=Array.from(p.geometry.intersectCircle(ue,C.radius,{includeLabels:!1,includeInternal:!1}));if(Te.length){const je=ue.angle(Pe),At=ue.angle(Ae),on=w(je,At),_t=on*.75;Te=Te.filter(Ot=>w(je,ue.angle(Ot))<=on),Te.sort(ze?(Ot,an)=>Math.abs(w(je,ue.angle(Ot))-_t)<Math.abs(w(je,ue.angle(an))-_t)?-1:1:(Ot,an)=>w(je,ue.angle(Ot))<w(je,ue.angle(an))?-1:1),ve=Te[0]}if(!ve)if(ze){const je=p.geometry.nearestPoint(Ae);P.DistMin(je,Ae,1)&&(ve=je)}else ve=Ae;if(ve&&(O.setTo(n.getPointInShapeSpace(e,de.applyToPoint(p.transform,ve))),p.didIntersect=!0,r!=="none")){const je=Oo[e.props.size]/2+("size"in p.shape.props?Oo[p.shape.props.size]/2:0);V=(ng+je)*e.props.scale,Y+=je*e.props.scale}}let j=P.Angle(C.center,A),N=P.Angle(C.center,O),z=w(j,N),G=z*C.radius;const q=A.clone(),$=O.clone();if(U!==0&&q.setTo(C.center).add(P.FromAngle(j+z*(U/G*(y?1:-1))).mul(C.radius)),V!==0&&$.setTo(C.center).add(P.FromAngle(N+z*(V/G*(y?-1:1))).mul(C.radius)),P.DistMin(q,$,Y)){U!==0&&V!==0?(U*=-1.5,V*=-1.5):U!==0?U*=-2:V!==0&&(V*=-2);const J=.1-w(T,j)*C.radius,H=.1-w(N,E)*C.radius;U=Math.max(U,J),V=Math.max(V,H)}if(U!==0&&A.setTo(C.center).add(P.FromAngle(j+z*(U/G*(y?1:-1))).mul(C.radius)),V!==0&&O.setTo(C.center).add(P.FromAngle(N+z*(V/G*(y?-1:1))).mul(C.radius)),h&&p&&!h.isExact&&!p.isExact){j=P.Angle(C.center,A),N=P.Angle(C.center,O),z=w(j,N),G=z*C.radius;const J=Z_(n,h.shape.id,p.shape.id);J==="double-bound"&&G<30?(A.setTo(m),O.setTo(S),D.setTo(v)):J==="safe"&&(h&&!h.didIntersect&&A.setTo(m),(p&&!p.didIntersect||w(T,j)>w(T,N))&&O.setTo(C.center).add(P.FromAngle(j+z*(Math.min(.9,vp*e.props.scale/G)*(y?1:-1))).mul(C.radius)))}nye(C.center,C.radius,A,O,D,_,y),A.equals(O)&&(A.setTo(D.clone().addXY(1,1)),O.setTo(D.clone().subXY(1,1))),m.setTo(A),S.setTo(O),v.setTo(D);const K=AN(m,S,v);return{bindings:t,type:"arc",start:{point:m,handle:i.start,arrowhead:e.props.arrowheadStart},end:{point:S,handle:i.end,arrowhead:e.props.arrowheadEnd},middle:v,handleArc:C,bodyArc:K,isValid:K.length!==0&&isFinite(K.center.x)&&isFinite(K.center.y)}}function AN(n,e,t){const r=tT(n,e,t)??P.Med(n,e),s=P.Dist(r,n),o=+P.Clockwise(n,t,e),i=((n.y-e.y)**2+(n.x-e.x)**2)**.5,a=((e.y-t.y)**2+(e.x-t.x)**2)**.5,l=((t.y-n.y)**2+(t.x-n.x)**2)**.5,c=Math.acos((a*a+l*l-i*i)/(2*a*l))*2,u=+(bt>c),h=(Dt-c)*(o?1:-1),p=h*s;return{center:r,radius:s,size:h,length:p,largeArcFlag:u,sweepFlag:o}}function nye(n,e,t,r,s,o,i){const a=P.Angle(n,t),l=P.Angle(n,r);let c=x0(a,l);if(i||(c=Dt-c),s.setTo(n).add(P.FromAngle(a+c*(.5*(i?1:-1))).mul(e)),c>o){s.rotWith(n,bt);const u=r.clone();r.setTo(t),t.setTo(u)}}function rye(n,e){const t={min:n.min-e,max:n.max+e};return t.min>t.max?null:t}function sye(n,e){return Ve(n.min<=n.max&&e.min<=e.max),n.min<=e.min&&e.max<=n.max?[{min:n.min,max:e.min},{min:e.max,max:n.max}]:e.max<=n.min||e.min>=n.max?[n]:e.min<=n.min&&n.max<=e.max?[]:vx(n.min,e)?[{min:e.max,max:n.max}]:vx(n.max,e)?[{min:n.min,max:e.min}]:[]}function RP(n,e){return{min:Math.min(n,e),max:Math.max(n,e)}}function vx(n,e){return n>=e.min&&n<=e.max}function ON(n){return n.max-n.min}function ky(n){if(!n)return;const e=n.cross.min;n.cross.min=-n.cross.max,n.cross.max=-e,n.crossTarget=-n.crossTarget}function Ey(n){n&&(n.value=-n.value,n.expanded=n.expanded===null?null:-n.expanded)}const On={Identity:{x:1,y:1,transpose:!1},Rotate90:{x:-1,y:1,transpose:!0},Rotate180:{x:-1,y:-1,transpose:!1},Rotate270:{x:1,y:-1,transpose:!0},FlipY:{x:1,y:-1,transpose:!1}};function oye(n){return n.transpose?{x:n.y,y:n.x,transpose:!0}:n}function iye(n,e){const t={...n};return e.transpose&&(Yl(t,"x","y"),t.transpose=!t.transpose),e.x===-1&&(t.x=-t.x),e.y===-1&&(t.y=-t.y),t}function Yl(n,e,t){const r=n[e];n[e]=n[t],n[t]=r}function RN(n,e){e.x=n.x*e.x,e.y=n.y*e.y,n.transpose&&Yl(e,"x","y")}function Ad(n,e){n.x===-1&&(e.x=-(e.x+e.width)),n.y===-1&&(e.y=-(e.y+e.height)),n.transpose&&(Yl(e,"x","y"),Yl(e,"width","height"))}function DN(n,e){n.x===-1&&(Yl(e,"left","right"),ky(e.top),ky(e.bottom),Ey(e.left),Ey(e.right)),n.y===-1&&(Yl(e,"top","bottom"),ky(e.left),ky(e.right),Ey(e.top),Ey(e.bottom)),n.transpose&&(Yl(e,"left","top"),Yl(e,"right","bottom"))}class aye{constructor(e){R(this,"options");R(this,"A");R(this,"B");R(this,"common");R(this,"gapX");R(this,"gapY");R(this,"midX");R(this,"midY");R(this,"bias");R(this,"transform",On.Identity);R(this,"inverse",On.Identity);this.options=e.options,this.A=e.A,this.B=e.B,this.common=e.common,this.midX=e.midX,this.midY=e.midY,this.gapX=e.gapX,this.gapY=e.gapY,this.bias=new P(1,1)}apply(e){if(this.transform=iye(e,this.transform),this.inverse=oye(this.transform),Ad(e,this.A.original),Ad(e,this.B.original),Ad(e,this.common.original),Ad(e,this.A.expanded),Ad(e,this.B.expanded),Ad(e,this.common.expanded),DN(e,this.A.edges),DN(e,this.B.edges),RN(e,this.bias),e.x===-1&&(this.gapX=-this.gapX,this.midX=this.midX===null?null:-this.midX),e.y===-1&&(this.gapY=-this.gapY,this.midY=this.midY===null?null:-this.midY),e.transpose){let t=this.midX;this.midX=this.midY,this.midY=t,t=this.gapX,this.gapX=this.gapY,this.gapY=t}}reset(){this.apply(this.inverse)}vec(e,t){const r=new P(e,t);return RN(this.inverse,r),r}}const Od=.01;class Ms{constructor(e,t){R(this,"points",[]);R(this,"_midpointHandle",null);this.info=e,this.name=t}add(e,t){return this.points.push(this.info.vec(e,t)),this}midpointHandle(e){Ve(this._midpointHandle===null,"midX/midY called multiple times");const t=P.Lrp(this.points[this.points.length-2],this.points[this.points.length-1],.5);return this._midpointHandle={axis:this.info.transform.transpose?e==="x"?"y":"x":e,point:t,segmentStart:this.points[this.points.length-2].clone(),segmentEnd:this.points[this.points.length-1].clone()},this}build(){const e=[];for(let t=0;t<this.points.length;t++){const r=this.points[t],s=e[e.length-1],o=e[e.length-2];if(!s||!o)e.push(r);else{const i=Math.abs(r.x-s.x),a=Math.abs(r.y-s.y),l=Math.abs(r.x-o.x),c=Math.abs(r.y-o.y);i<Od&&a<Od||(i<Od&&l<Od?s.y=r.y:a<Od&&c<Od?s.x=r.x:e.push(r))}}return{name:this.name,points:e,distance:lye(e),aEdgePicking:"manual",bEdgePicking:"manual",skipPointsWhenDrawing:new Set,midpointHandle:this._midpointHandle}}}function lye(n){let e=0;for(let t=0;t<n.length-1;t++){const r=n[t],s=n[t+1];e+=Math.abs(s.x-r.x)+Math.abs(s.y-r.y)}return e}function Iy(n){const e=n.A.edges.right,t=n.B.edges.left;if(!e||!t)return null;if(e.crossTarget>t.crossTarget&&n.apply(On.FlipY),n.gapX>0&&n.midX!==null)return new Ms(n,"to left 1").add(e.value,e.crossTarget).add(n.midX,e.crossTarget).add(n.midX,t.crossTarget).midpointHandle("x").add(t.value,t.crossTarget).build();if(e.expanded===null||t.expanded===null)return null;if(n.midY!==null)return new Ms(n,"to left 2").add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.midY).add(t.expanded,n.midY).midpointHandle("y").add(t.expanded,t.crossTarget).add(t.value,t.crossTarget).build();const r=Math.abs(e.value-n.common.expanded.right)+Math.abs(e.crossTarget-n.common.expanded.bottom)+Math.abs(n.common.expanded.right-t.expanded)+Math.abs(n.common.expanded.bottom-t.crossTarget)+n.options.expandElbowLegLength+6,s=n.options.expandElbowLegLength+Math.abs(e.crossTarget-n.common.expanded.top)+Math.abs(e.expanded-n.common.expanded.left)+Math.abs(n.common.expanded.top-t.crossTarget)+Math.abs(n.common.expanded.left-t.value)+6+n.bias.y,o=n.gapX<0&&n.midX!==null?n.options.expandElbowLegLength+Math.abs(e.crossTarget-n.A.expanded.bottom)+n.common.expanded.width+Math.abs(n.A.expanded.bottom-n.B.expanded.top)+Math.abs(n.B.expanded.top-t.crossTarget)+n.options.expandElbowLegLength+8:1/0;return r<s&&r<o?new Ms(n,"to left 3").add(e.value,e.crossTarget).add(n.common.expanded.right,e.crossTarget).add(n.common.expanded.right,n.common.expanded.bottom).add(t.expanded,n.common.expanded.bottom).add(t.expanded,t.crossTarget).add(t.value,t.crossTarget).build():s<o?new Ms(n,"to left 4").add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.common.expanded.top).add(n.common.expanded.left,n.common.expanded.top).add(n.common.expanded.left,t.crossTarget).add(t.value,t.crossTarget).build():n.midX!==null?new Ms(n,"to left 5").add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.A.expanded.bottom).add(n.midX,n.A.expanded.bottom).add(n.midX,n.B.expanded.top).midpointHandle("y").add(t.expanded,n.B.expanded.top).add(t.expanded,t.crossTarget).add(t.value,t.crossTarget).build():null}function Jf(n){const e=n.A.edges.right,t=n.B.edges.top;if(!e||!t)return null;if(e.crossTarget<(t.expanded??t.value)&&t.crossTarget>(e.expanded??e.value)||n.A.isPoint&&n.B.expanded.containsPoint(n.A.original.center))return new Ms(n,"to top 1").add(e.value,e.crossTarget).add(t.crossTarget,e.crossTarget).add(t.crossTarget,t.value).build();if(n.gapX>0&&n.midX!==null&&t.expanded!==null)return new Ms(n,"to top 2").add(e.value,e.crossTarget).add(n.midX,e.crossTarget).add(n.midX,t.expanded).midpointHandle("x").add(t.crossTarget,t.expanded).add(t.crossTarget,t.value).build();if(n.gapY>0&&e.expanded!==null&&t.crossTarget<e.expanded&&n.midY!==null)return new Ms(n,"to top 3").add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.midY).add(t.crossTarget,n.midY).midpointHandle("y").add(t.crossTarget,t.value).build();const r=Math.abs(e.value-n.common.expanded.right)+Math.abs(e.crossTarget-n.common.expanded.top)+Math.abs(t.crossTarget-n.common.expanded.right)+Math.abs(t.value-n.common.expanded.top),s=e.expanded!==null&&n.midY!==null&&t.expanded!==null?Math.abs(e.value-e.expanded)+Math.abs(n.B.expanded.left-e.expanded)+Math.abs(n.B.expanded.left-t.crossTarget)+Math.abs(e.crossTarget-n.B.expanded.top)+Math.abs(t.value-t.expanded):1/0,o=e.expanded!==null&&n.midX!==null&&t.expanded!==null?Math.abs(e.value-n.common.expanded.right)+Math.abs(e.crossTarget-n.A.expanded.bottom)+Math.abs(e.expanded-t.crossTarget)+Math.abs(n.A.expanded.bottom-t.expanded)+Math.abs(t.expanded-t.value):1/0;return r<s&&r<o?new Ms(n,"to top 4").add(e.value,e.crossTarget).add(n.common.expanded.right,e.crossTarget).add(n.common.expanded.right,n.common.expanded.top).add(t.crossTarget,n.common.expanded.top).add(t.crossTarget,t.value).build():t.expanded!==null&&e.expanded!==null&&n.midY!==null&&s<o?new Ms(n,"to top 5").add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.midY).add(n.B.expanded.left,n.midY).midpointHandle("y").add(n.B.expanded.left,t.expanded).add(t.crossTarget,t.expanded).add(t.crossTarget,t.value).build():t.expanded!==null&&e.expanded!==null&&n.midX!==null?new Ms(n,"to top 6").add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.A.expanded.bottom).add(n.midX,n.A.expanded.bottom).add(n.midX,t.expanded).midpointHandle("x").add(t.crossTarget,t.expanded).add(t.crossTarget,t.value).build():null}function Ty(n){return n.apply(On.FlipY),Jf(n)}function _y(n){const e=n.A.edges.right,t=n.B.edges.right;if(!e||!t)return null;if((n.gapX<=0||e.crossTarget>n.B.expanded.bottom||e.crossTarget<n.B.expanded.top)&&(t.value>n.A.original.left||t.crossTarget>n.A.expanded.bottom||t.crossTarget<n.A.expanded.top))return new Ms(n,"to right 1").add(e.value,e.crossTarget).add(n.common.expanded.right,e.crossTarget).add(n.common.expanded.right,t.crossTarget).add(t.value,t.crossTarget).build();if(n.midX===null)return null;if(t.expanded!==null&&n.gapX>=0){const r=Math.abs(t.crossTarget-n.B.expanded.bottom)+Math.abs(e.crossTarget-n.B.expanded.bottom),s=Math.abs(t.crossTarget-n.B.expanded.top)+Math.abs(e.crossTarget-n.B.expanded.top),o=r<s?"bottom":"top";return new Ms(n,`to right 2 via ${o}`).add(e.value,e.crossTarget).add(n.midX,e.crossTarget).add(n.midX,n.B.expanded[o]).midpointHandle("x").add(t.expanded,n.B.expanded[o]).add(t.expanded,t.crossTarget).add(t.value,t.crossTarget).build()}if(e.expanded!==null&&n.gapX<=0){const r=Math.abs(t.crossTarget-n.A.expanded.bottom)+Math.abs(e.crossTarget-n.A.expanded.bottom),s=Math.abs(t.crossTarget-n.A.expanded.top)+Math.abs(e.crossTarget-n.A.expanded.top),o=r<s?"bottom":"top";return new Ms(n,`to right 3 via ${o}`).add(e.value,e.crossTarget).add(e.expanded,e.crossTarget).add(e.expanded,n.A.expanded[o]).add(n.midX,n.A.expanded[o]).add(n.midX,t.crossTarget).midpointHandle("x").add(t.value,t.crossTarget).build()}return null}const cye={top:{top:[On.Rotate270,_y],left:[On.Rotate270,Jf],bottom:[On.Rotate270,Iy],right:[On.Rotate270,Ty]},right:{top:[On.Identity,Jf],right:[On.Identity,_y],bottom:[On.Identity,Ty],left:[On.Identity,Iy]},bottom:{top:[On.Rotate90,Iy],left:[On.Rotate90,Ty],bottom:[On.Rotate90,_y],right:[On.Rotate90,Jf]},left:{top:[On.Rotate180,Ty],left:[On.Rotate180,_y],bottom:[On.Rotate180,Jf],right:[On.Rotate180,Iy]}};function Rn(n,e,t){const[r,s]=cye[e][t];n.apply(r);const o=s(n);return n.reset(),o}function uye(n,e){let t=null;if(Math.abs(n.gapX)+1>Math.abs(n.gapY)&&n.midX!==null)n.gapX>0?t=Rn(n,"right","left"):t=Rn(n,"left","right");else{const i=n.A.edges.right,a=n.A.edges.left,l=n.B.edges.top,c=n.B.edges.bottom;n.A.isPoint&&n.B.isPoint?n.gapY>0?t=Rn(n,"bottom","top"):t=Rn(n,"top","bottom"):i&&l&&(i.expanded??i.value)<=l.crossTarget&&i.crossTarget<=(l.expanded??l.value)?t=Rn(n,"right","top"):i&&c&&(i.expanded??i.value)<=c.crossTarget&&i.crossTarget>=(c.expanded??c.value)?t=Rn(n,"right","bottom"):a&&l&&(a.expanded??a.value)>=l.crossTarget&&a.crossTarget<=(l.expanded??l.value)?t=Rn(n,"left","top"):a&&c&&(a.expanded??a.value)>=c.crossTarget&&a.crossTarget>=(c.expanded??c.value)?t=Rn(n,"left","bottom"):n.gapY>0&&n.midY!==null?t=Rn(n,"bottom","top"):n.gapY<0&&n.midY!==null&&(t=Rn(n,"top","bottom"))}if(t)return t.aEdgePicking=e,t.bEdgePicking=e,t;const r=TN.filter(i=>n.A.edges[i]),s=TN.filter(i=>n.B.edges[i]),o=r.flatMap(i=>s.map(a=>[i,a,e,e]));return Kd(n,o)}function dye(n,e){let t=null;const r=n.A.edges.right,s=n.A.edges.left,o=n.B.edges.top,i=n.B.edges.bottom;switch(e){case"right":n.gapX>0&&n.gapX>Math.abs(n.gapY)&&n.midX!==null?t=Rn(n,"right","left"):r&&o&&(r.expanded??r.value)<=o.crossTarget&&r.crossTarget<=(o.expanded??o.value)?t=Rn(n,"right","top"):r&&i&&(r.expanded??r.value)<=i.crossTarget&&r.crossTarget>=(i.expanded??i.value)&&(t=Rn(n,"right","bottom"));break;case"left":n.gapX<0&&Math.abs(n.gapX)>Math.abs(n.gapY)&&n.midX!==null?t=Rn(n,"left","right"):s&&o&&(s.expanded??s.value)>=o.crossTarget&&s.crossTarget<=(o.expanded??o.value)?t=Rn(n,"left","top"):s&&i&&(s.expanded??s.value)>=i.crossTarget&&s.crossTarget>=(i.expanded??i.value)&&(t=Rn(n,"left","bottom"));break;case"top":case"bottom":break;default:xt(e)}if(t)return t.aEdgePicking="manual",t.bEdgePicking="auto",t;switch(e){case"top":return Kd(n,[["top","bottom","manual","auto"],["top","right","manual","auto"],["top","left","manual","auto"],["top","top","manual","auto"]]);case"bottom":return Kd(n,[["bottom","top","manual","auto"],["bottom","right","manual","auto"],["bottom","left","manual","auto"],["bottom","bottom","manual","auto"]]);case"left":return Kd(n,[["left","right","manual","auto"],["left","bottom","manual","auto"],["left","left","manual","auto"],["left","top","manual","auto"]]);case"right":return Kd(n,[["right","left","manual","auto"],["right","bottom","manual","auto"],["right","right","manual","auto"],["right","top","manual","auto"]])}}function hye(n,e,t){const r=Rn(n,e,t);return r||(n.A.isPoint&&n.B.isPoint?Kd(n,[[Md[e],Md[t],"manual","manual"],[e,Md[t],"manual","auto"],[Md[e],t,"auto","manual"]]):n.A.isPoint?Rn(n,Md[e],t):n.B.isPoint?Rn(n,e,Md[t]):null)}function Kd(n,e){let t=null,r=1/0,s=1/0,o=0;for(const[i,a,l,c]of e){o+=1;const u=Rn(n,i,a);u&&(u.aEdgePicking=l,u.bEdgePicking=c,u.points.length<r?(r=u.points.length,s=u.distance,t=u):u.points.length===r&&u.distance+o<s&&(s=u.distance,t=u))}return t}function gH(n,e,t){const r=n.getShapeUtil(e.type).options,s={elbowMidpoint:e.props.elbowMidPoint,expandElbowLegLength:r.expandElbowLegLength[e.props.size]*e.props.scale,minElbowLegLength:r.minElbowLegLength[e.props.size]*e.props.scale};let o=jN(n,e,t.start,e.props.start),i=jN(n,e,t.end,e.props.end);o=zN(o,i,s),i=zN(i,o,s);const a=!!(!o.side&&i.side);let{aTerminal:l,bTerminal:c}=a?{aTerminal:i,bTerminal:o}:{aTerminal:o,bTerminal:i},u={top:Er(l,c,"top",s),right:Er(l,c,"right",s),bottom:Er(l,c,"bottom",s),left:Er(l,c,"left",s)},h={top:Er(c,l,"top",s),right:Er(c,l,"right",s),bottom:Er(c,l,"bottom",s),left:Er(c,l,"left",s)};const p=LN(u,l.side),m=LN(h,c.side);let S=!1;(!p||!m)&&(S=!0,p||(c=Qf(c)),m||(l=Qf(l)),c.bounds.containsPoint(l.target,s.expandElbowLegLength)&&(c=Qf(c)),l.bounds.containsPoint(c.target,s.expandElbowLegLength)&&(l=Qf(l))),S&&(u={top:Er(l,c,"top",s),right:Er(l,c,"right",s),bottom:Er(l,c,"bottom",s),left:Er(l,c,"left",s)},h={top:Er(c,l,"top",s),right:Er(c,l,"right",s),bottom:Er(c,l,"bottom",s),left:Er(c,l,"left",s)});const v=l.isPoint?l.bounds:l.bounds.clone().expandBy(s.expandElbowLegLength),y=c.isPoint?c.bounds:c.bounds.clone().expandBy(s.expandElbowLegLength),w={original:ye.Common([l.bounds,c.bounds]),expanded:ye.Common([v,y])};let C=c.bounds.minX-l.bounds.maxX;C<0&&(C=l.bounds.minX-c.bounds.maxX,C<0&&(C=0),C=-C);let T=c.bounds.minY-l.bounds.maxY;T<0&&(T=l.bounds.minY-c.bounds.maxY,T<0&&(T=0),T=-T);const E=l.minEndSegmentLength*3,_=c.minEndSegmentLength*3,A=(l.isPoint?E:s.minElbowLegLength)+(c.isPoint?_:s.minElbowLegLength);let O=null;C>A?O={a:l.isPoint?l.bounds.maxX+E:v.maxX,b:c.isPoint?c.bounds.minX-_:y.minX}:C<-A&&(O={a:l.isPoint?l.bounds.minX-E:v.minX,b:c.isPoint?c.bounds.maxX+_:y.maxX});let D=null;T>A?D={a:l.isPoint?l.bounds.maxY+E:v.maxY,b:c.isPoint?c.bounds.minY-_:y.minY}:T<-A&&(D={a:l.isPoint?l.bounds.minY-E:v.minY,b:c.isPoint?c.bounds.maxY+_:y.maxY});const F=a?1-s.elbowMidpoint:s.elbowMidpoint,U=O?rt(O.a,O.b,F):null,V=D?rt(D.a,D.b,F):null,Y={options:s,swapOrder:a,A:{isPoint:l.isPoint,target:l.target,isExact:l.isExact,arrowheadOffset:l.arrowheadOffset,minEndSegmentLength:l.minEndSegmentLength,original:l.bounds,expanded:v,edges:u,geometry:l.geometry},B:{isPoint:c.isPoint,target:c.target,isExact:c.isExact,arrowheadOffset:c.arrowheadOffset,minEndSegmentLength:c.minEndSegmentLength,original:c.bounds,expanded:y,edges:h,geometry:c.geometry},common:w,gapX:C,gapY:T,midX:U,midY:V},j=new aye(Y),N=NN(l,c,Y.A.edges),z=NN(c,l,Y.B.edges);let G;return N&&z?G=hye(j,N,z):N&&!z&&(G=dye(j,N)),G||(G=uye(j,N||z?"fallback":"auto")),G&&(FN("first",Y.A,Y.B,G),FN("last",Y.B,Y.A,G),yye(G,l,c),a&&G.points.reverse()),{...Y,route:G,midXRange:O?a?{lo:O.b,hi:O.a}:{lo:O.a,hi:O.b}:null,midYRange:D?a?{lo:D.b,hi:D.a}:{lo:D.a,hi:D.b}:null}}function fye(n,e){const t=n.swapOrder?n.B.target:n.A.target,r=n.swapOrder?n.A.target:n.B.target,s=P.ManhattanDist(e.points[0],e.points[1]),o=P.ManhattanDist(e.points[e.points.length-2],e.points[e.points.length-1]),i=P.ManhattanDist(t,e.points[1]),a=P.ManhattanDist(e.points[e.points.length-2],r),l=s-i,c=o-a,u=[t,...e.points,r];return{name:e.name,distance:e.distance+l+c,points:u.filter(h=>!e.skipPointsWhenDrawing.has(h)),aEdgePicking:e.aEdgePicking,bEdgePicking:e.bEdgePicking,skipPointsWhenDrawing:e.skipPointsWhenDrawing,midpointHandle:e.midpointHandle}}function pye(n){return ro(n.x,.5)&&ro(n.y,.5)?null:Math.abs(n.x-.5)>Math.abs(n.y-.5)-1e-4?n.x<.5?"left":"right":n.y<.5?"top":"bottom"}function jN(n,e,t,r){const s=Oo[e.props.size]*e.props.scale/2,o=s*e.props.scale*3;if(t){const i=n.getShape(t.toId),a=gye(n,e,t.toId,t.props);if(a&&i){let l=0;const c=t.props.terminal==="start"?"arrowheadStart":"arrowheadEnd";if(e.props[c]!=="none"){const p="scale"in i.props?i.props.scale:1,m="size"in i.props?(Oo[i.props.size]??0)*p/2:0;l=s+m+ng*e.props.scale}let u=null;const h=a.target;return t.props.isPrecise&&(u=pye(P.RotWith(t.props.normalizedAnchor,{x:.5,y:.5},a.shapeToArrowTransform.rotation()))),{targetShapeId:t.toId,isPoint:!1,isExact:t.props.isExact,bounds:a.bounds,geometry:a.geometry,target:h,arrowheadOffset:l,minEndSegmentLength:o,side:u,snap:t.props.snap}}}return{targetShapeId:null,bounds:ye.FromCenter(r,{x:0,y:0}),geometry:null,isExact:!1,isPoint:!0,target:P.From(r),arrowheadOffset:0,minEndSegmentLength:o,side:null,snap:"none"}}function gye(n,e,t,r){const s=r.terminal==="start"?e.props.arrowheadStart!=="none":e.props.arrowheadEnd!=="none",o=n.getShapeGeometry(t,s?void 0:{context:"@tldraw/arrow-without-arrowhead"});if(!o)return null;const i=n.getShapePageTransform(e.id),a=n.getShapePageTransform(t),l=i.clone().invert().multiply(a),c=o.transform(l),u={x:.5,y:.5},h=r.isPrecise?r.normalizedAnchor:u,p={x:rt(o.bounds.minX,o.bounds.maxX,h.x),y:rt(o.bounds.minY,o.bounds.maxY,h.y)},m={x:rt(o.bounds.minX,o.bounds.maxX,u.x),y:rt(o.bounds.minY,o.bounds.maxY,u.y)},S=de.applyToPoint(l,p),v=de.applyToPoint(l,m);return{bounds:c.bounds,geometry:c,target:S,center:v,shapeToArrowTransform:l}}const mye={top:{expand:-1,main:"minY",opposite:"maxY",crossMid:"midX",crossMin:"minX",crossMax:"maxX",bRangeExpand:"max",crossAxis:"x"},bottom:{expand:1,main:"maxY",opposite:"minY",crossMid:"midX",crossMin:"minX",crossMax:"maxX",bRangeExpand:"min",crossAxis:"x"},left:{expand:-1,main:"minX",opposite:"maxX",crossMid:"midY",crossMin:"minY",crossMax:"maxY",bRangeExpand:"max",crossAxis:"y"},right:{expand:1,main:"maxX",opposite:"minX",crossMid:"midY",crossMin:"minY",crossMax:"maxY",bRangeExpand:"min",crossAxis:"y"}};function Er(n,e,t,r){const s=mye[t],o=n.targetShapeId===e.targetShapeId&&n.targetShapeId!==null&&(n.snap==="edge"||n.snap==="edge-point")&&(e.snap==="edge"||e.snap==="edge-point"),i=n.bounds[s.main],a=n.isPoint?null:i+s.expand*r.expandElbowLegLength,l=RP(n.bounds[s.crossMin],n.bounds[s.crossMax]);let c=l;if(!c)return null;Ve(l);const u=RP(e.bounds[s.main],e.bounds[s.opposite]);e.isPoint||(u[s.bRangeExpand]-=r.minElbowLegLength*2*s.expand);const h=rye(RP(e.bounds[s.crossMin],e.bounds[s.crossMax]),r.expandElbowLegLength);Ve(u&&h);let p=!1;if(vx(i,u)&&!n.isPoint&&!e.isPoint&&!o){const S=sye(c,h);switch(S.length){case 0:return null;case 1:p=S[0]!==c,c=S[0];break;case 2:p=!0,c=ON(S[0])>ON(S[1])?S[0]:S[1];break;default:xt(S)}}if(!vx(n.target[s.crossAxis],c))return null;const m=n.target[s.crossAxis];return{value:i,expanded:a,cross:c,crossTarget:m,isPartial:p}}function LN(n,e){return e===null?!!(n.bottom||n.left||n.right||n.top):e==="x"?!!n.left||!!n.right:e==="y"?!!n.top||!!n.bottom:!!n[e]}function NN(n,e,t){switch(n.side){case null:return null;case"x":return n.bounds.center.x>e.bounds.center.x&&(t!=null&&t.left)?"left":t!=null&&t.right?"right":null;case"y":return n.bounds.center.y>e.bounds.center.y&&(t!=null&&t.top)?"top":t!=null&&t.bottom?"bottom":null;default:return n.side}}function Qf(n){if(n.isPoint)return n;let e=null,t=0;return(n.snap==="edge"||n.snap==="edge-point")&&(t=n.arrowheadOffset,(n.side==="x"||n.side==="left"||n.side==="right")&&(e="x"),(n.side==="y"||n.side==="top"||n.side==="bottom")&&(e="y")),{targetShapeId:n.targetShapeId,side:e,bounds:new ye(n.target.x,n.target.y,0,0),geometry:n.geometry,target:n.target,arrowheadOffset:t,minEndSegmentLength:n.minEndSegmentLength,isExact:n.isExact,isPoint:!0,snap:n.snap}}function FN(n,e,t,r){if(!e.geometry)return;const s=n==="first"?r.points[0]:r.points[r.points.length-1],o=n==="first"?r.points[1]:r.points[r.points.length-2],i=e.geometry.isClosed?o:e.target,a=P.ManhattanDist(s,i);let l=null,c=1/0;if(e.isExact)l=e.target;else if(e.geometry){const u=e.geometry.intersectLineSegment(o,e.target,{includeLabels:!1,includeInternal:!1});e.geometry.hitTestPoint(e.target,Math.max(1,e.arrowheadOffset),!0,qi.EXCLUDE_NON_STANDARD)&&u.push(e.target);for(const h of u){const p=P.ManhattanDist(i,h);p<c&&(c=p,l=h)}}if(l){let u=e.arrowheadOffset;const h=P.ManhattanDist(o,l),p=e.arrowheadOffset*2;if(h<p){const y=p-e.arrowheadOffset;u=h-y}u<e.minEndSegmentLength&&(e.geometry.bounds.containsPoint(t.target)?u=Math.max(0,u):u=-e.arrowheadOffset);let m=l,S=!1;if(!e.isExact&&u!==0){const y=P.Nudge(l,o,u);m=y,u<0&&!e.geometry.hitTestPoint(y,0,!0,qi.EXCLUDE_NON_STANDARD)?m=l:(u<0&&(S=!0),m=y)}const v=P.ManhattanDist(o,m);if(r.distance+=v-a,s.x=m.x,s.y=m.y,S){const y=P.Lrp(o,s,.5);r.skipPointsWhenDrawing.add(y),r.points.splice(n==="first"?1:r.points.length-1,0,y)}}}function yye(n,e,t){if(n){if(n.points.length>=3){const r=n.points[0],s=n.points[1];if(P.ManhattanDist(r,s)<e.minEndSegmentLength&&(n.points.splice(1,1),n.points.length>=3)){const i=ro(r.x,s.x)?"y":"x";n.points[1][i]=r[i]}}if(n.points.length>=3){const r=n.points[n.points.length-1],s=n.points[n.points.length-2];if(P.ManhattanDist(r,s)<t.minEndSegmentLength&&(n.points.splice(n.points.length-2,1),n.points.length>=3)){const i=ro(r.x,s.x)?"y":"x";n.points[n.points.length-2][i]=r[i]}}}}function zN(n,e,t){if(!n.geometry||n.geometry.isClosed)return n;const r=n.geometry.uninterpolateAlongEdge(n.target,qi.EXCLUDE_NON_STANDARD),s=n.geometry.interpolateAlongEdge(r-.01/n.geometry.length),i=n.geometry.interpolateAlongEdge(r+.01/n.geometry.length).sub(s).per().uni(),a=Math.abs(i.x)>Math.abs(i.y)?tg.x:tg.y;if(n.geometry.bounds.containsPoint(e.target,t.expandElbowLegLength))return n.side=a.self,Qf(n);const l=a.v(n.target[a.self]-n.bounds[a.size]*2,n.target[a.cross]),c=a.v(n.target[a.self]+n.bounds[a.size]*2,n.target[a.cross]);let u=null,h=0,p=null,m=0,S=a.self;for(const v of n.geometry.intersectLineSegment(l,c,qi.EXCLUDE_NON_STANDARD))Math.abs(v[a.self]-n.target[a.self])<1||(v[a.self]<n.target[a.self]?P.ManhattanDist(v,n.target)>h&&(h=P.ManhattanDist(v,n.target),u=v):P.ManhattanDist(v,n.target)>m&&(m=P.ManhattanDist(v,n.target),p=v));return u&&p?h>m?S=a.hiEdge:S=a.loEdge:u&&!p?S=a.hiEdge:!u&&p&&(S=a.loEdge),n.side=S,n}const Sye=8;function xye(n){return n.props.kind!=="arc"?!1:Math.abs(n.props.bend)<Sye*n.props.scale}function wx(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 o=n.getShapePageTransform(s),i=t==="start"?e.props.arrowheadStart!=="none":e.props.arrowheadEnd!=="none",a=n.getShapeGeometry(s,i?void 0:{context:"@tldraw/arrow-without-arrowhead"});return{shape:s,transform:o,isClosed:a.isClosed,isExact:r.props.isExact,didIntersect:!1,geometry:a}}function BN(n,e,t,r){const s=n.getShape(t.toId);if(s){const{point:o,size:i}=n.getShapeGeometry(s).bounds,a=P.Add(o,P.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},i)),l=de.applyToPoint(n.getShapePageTransform(s),a);return de.applyToPoint(de.Inverse(e),l)}else return new P(0,0)}function zn(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 vye=p0("arrow info",(n,e)=>{const t=zn(n,e);if(e.props.kind==="elbow"){const r=gH(n,e,t);if(!(r!=null&&r.route))return xx(n,e,t);const s=r.swapOrder?r.B:r.A,o=r.swapOrder?r.A:r.B;return{type:"elbow",bindings:t,start:{handle:s.target,point:r.route.points[0],arrowhead:e.props.arrowheadStart},end:{handle:o.target,point:r.route.points[r.route.points.length-1],arrowhead:e.props.arrowheadEnd},elbow:r,route:r.route,isValid:!0}}return xye(e)?xx(n,e,t):tye(n,e,t)});function _o(n,e){const t=typeof e=="string"?e:e.id;return vye.get(n,t)}function Wd(n,e,t){var a,l;const r=n.getShapePageTransform(e),s=Z_(n,(a=t.start)==null?void 0:a.toId,(l=t.end)==null?void 0:l.toId),o=t.start?BN(n,r,t.start,s==="double-bound"||s==="start-contains-end"):P.From(e.props.start),i=t.end?BN(n,r,t.end,s==="double-bound"||s==="end-contains-start"):P.From(e.props.end);return{start:o,end:i}}function Df(n,e,t,r){const s=typeof e=="string"?e:e.id,o=typeof t=="string"?t:t.id,i=n.getBindingsFromShape(s,"arrow").filter(l=>l.props.terminal===r.terminal);i.length>1&&n.deleteBindings(i.slice(1));const a=i[0];a?n.updateBinding({...a,toId:o,props:r}):n.createBinding({type:"arrow",fromId:s,toId:o,props:r})}function ep(n,e,t){const r=n.getBindingsFromShape(e,"arrow").filter(s=>s.props.terminal===t);n.deleteBindings(r)}const vp=10,ng=10,wye=10,Oo={s:2,m:3.5,l:5,xl:10};function Z_(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 oS extends Zy{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5},snap:"none"}}onAfterCreate({binding:e}){const t=this.editor.getShape(e.fromId);t&&DP(this.editor,t)}onAfterChange({bindingAfter:e}){const t=this.editor.getShape(e.fromId);t&&DP(this.editor,t)}onAfterChangeFromShape({shapeAfter:e}){DP(this.editor,e)}onAfterChangeToShape({binding:e}){mH(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const t=this.editor.getShape(e.fromId);t&&bx({editor:this.editor,arrow:t,terminal:e.props.terminal})}}R(oS,"type","arrow"),R(oS,"props",x5),R(oS,"migrations",v5);function mH(n,e){var y;const t=n.getShape(e);if(!t)return;const r=zn(n,t),{start:s,end:o}=r,i=s?n.getShape(s.toId):void 0,a=o?n.getShape(o.toId):void 0,l=n.getAncestorPageId(t);if(!l)return;let c;if(i&&a)c=n.findCommonAncestor([i,a])??l;else if(i||a){const w=(y=i||a)==null?void 0:y.parentId;w&&w===t.parentId?c=t.parentId:c=l}else return;c&&c!==t.parentId&&n.reparentShapes([e],c);const u=n.getShape(e);if(!u)throw Error("no reparented arrow");const h=n.getShapeNearestSibling(u,i),p=n.getShapeNearestSibling(u,a);let m;if(h&&p)m=h.index>p.index?h:p;else if(h&&!p)m=h;else if(p&&!h)m=p;else return;let S;const v=n.getSortedChildIdsForParent(m.parentId).map(w=>n.getShape(w)).filter(w=>w.index>m.index);if(v.length){const w=v.find(C=>C.type!=="arrow");if(u.index>m.index&&(!w||u.index<w.index))return;S=Rp(m.index,v[0].index)}else S=Wi(m.index);S!==u.index&&n.updateShapes([{id:e,type:"arrow",index:S}])}function DP(n,e){const t=zn(n,e);for(const r of["start","end"]){const s=t[r];if(!s)continue;const o=n.getShape(s.toId),i=n.getAncestorPageId(e)===n.getAncestorPageId(o);(!o||!i)&&bx({editor:n,arrow:e,terminal:r,unbind:!0})}mH(n,e.id)}function bx({editor:n,arrow:e,terminal:t,unbind:r=!1,useHandle:s=!1}){const o=_o(n,e);if(!o)throw new Error("expected arrow info");const i=s?o.start.handle:o.start.point,a=s?o.end.handle:o.end.point,l=t==="start"?i:a,c={id:e.id,type:"arrow",props:{[t]:{x:l.x,y:l.y},bend:e.props.bend}};if(o.type==="arc"){const u=t==="start"?i:o.start.handle,h=t==="end"?a:o.end.handle,p=P.Med(u,h),m=P.Sub(u,h).per().uni().mul(o.handleArc.radius*2*Math.sign(e.props.bend)),S=bg(o.handleArc.center,P.Add(p,m),o.handleArc.center,o.handleArc.radius);Ve((S==null?void 0:S.length)===1);const v=P.Dist(p,S[0])*Math.sign(e.props.bend);ro(v,c.props.bend)||(c.props.bend=v)}n.updateShape(c),r&&ep(n,e,t)}const yH=[oS],mr={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},Dn={s:2,m:3.5,l:5,xl:10},yh={s:18,m:24,l:36,xl:44},Ua={s:18,m:22,l:26,xl:32},bye={s:18,m:20,l:24,xl:28},Xa={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},Cye=20,SH=4.25,Zr=16;function Pye(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 kye(n,e,t){var w,C,T;const{elements:r,files:s}=e,o={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:n.store.schema.serialize()},i=new Map,a=new Map,l=n.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(E=>{if(c.set(E.id,Nt()),E.boundElements!==null)for(const _ of E.boundElements)_.type==="text"&&h.add(_.id)});let p=dF;for(const E of r){if(h.has(E.id))continue;const _=c.get(E.id),A={id:_,typeName:"shape",parentId:l,index:p,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:Eye(E.opacity),meta:{}};switch(E.angle!==0&&a.set(_,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(w=i.get(E.groupIds[0]))==null||w.push(_):i.set(E.groupIds[0],[_]):u.push(_),E.type){case"rectangle":case"ellipse":case"diamond":{let O="",D="middle";if(E.boundElements!==null){for(const U of E.boundElements)if(U.type==="text"){const V=r.find(Y=>Y.id===U.id);V&&(O=V.text,D=Rye[V.textAlign])}}const F=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;o.shapes.push({...A,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:My[E.strokeWidth]??"draw",color:jf[F]??"black",richText:Fo(O),align:D,dash:Ay(E),fill:Lye(E)}});break}case"freedraw":{o.shapes.push({...A,type:"draw",props:{dash:Ay(E),size:My[E.strokeWidth],color:jf[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([O,D,F=.5])=>({x:O,y:D,z:F}))}]}});break}case"line":{if(E.points.slice().length<2)break;const D=Dp(E.points.length);o.shapes.push({...A,type:"line",props:{dash:Ay(E),size:My[E.strokeWidth],color:jf[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([F,U],V)=>{const Y=D[V];return[Y,{id:Y,index:Y,x:F,y:U}]}))}}});break}case"arrow":{let O="";if(E.boundElements!==null){for(const Y of E.boundElements)if(Y.type==="text"){const j=r.find(N=>N.id===Y.id);j&&(O=j.text)}}const D=E.points[0],F=E.points[E.points.length-1],U=c.get((C=E.startBinding)==null?void 0:C.elementId),V=c.get((T=E.endBinding)==null?void 0:T.elementId);o.shapes.push({...A,type:"arrow",props:{text:O,kind:E.elbowed?"elbow":"arc",bend:jye(E,D,F),dash:Ay(E),size:My[E.strokeWidth]??"m",color:jf[E.strokeColor]??"black",start:{x:D[0],y:D[1]},end:{x:F[0],y:F[1]},arrowheadEnd:$N[E.endArrowhead]??"none",arrowheadStart:$N[E.startArrowhead]??"none"}}),U&&o.bindings.push({id:su(),typeName:"binding",type:"arrow",fromId:_,toId:U,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),V&&o.bindings.push({id:su(),typeName:"binding",type:"arrow",fromId:_,toId:V,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:O,scale:D}=Tye(E.fontSize);o.shapes.push({...A,type:"text",props:{size:O,scale:D,font:_ye[E.fontFamily]??"draw",color:jf[E.strokeColor]??"black",richText:Fo(E.text),textAlign:Dye[E.textAlign]}});break}case"image":{const O=s[E.fileId];if(!O)break;const D=nc.createId();o.assets.push({id:D,typeName:"asset",type:"image",props:{w:E.width,h:E.height,fileSize:O.size,name:E.id??"Untitled",isAnimated:!1,mimeType:O.mimeType,src:O.dataURL},meta:{}}),o.shapes.push({...A,type:"image",props:{w:E.width,h:E.height,assetId:D}})}}p=Wi(p)}const m=t??(n.inputs.shiftKey?n.inputs.currentPagePoint:void 0);n.putContentOntoCurrentPage(o,{point:m,select:!1,preserveIds:!0});for(const E of i.values())if(E.length>1){n.groupShapes(E);const _=n.getShape(E[0]);_!=null&&_.parentId&&Ts(_.parentId)&&u.push(_.parentId)}for(const[E,_]of a)n.select(E),n.rotateShapesBy([E],_);const S=st(u.map(E=>n.getShape(E))),v=ye.Common(S.map(E=>n.getShapePageBounds(E))),y=n.getViewportPageBounds().center;n.updateShapes(S.map(E=>{const _={x:(E.x??0)-(v.x+v.w/2),y:(E.y??0)-(v.y+v.h/2)};return{id:E.id,type:E.type,x:y.x+_.x,y:y.y+_.y}})),n.setSelectedShapes(u)}const Eye=n=>{const e=n/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},My={1:"s",2:"m",3:"l",4:"xl"},Iye={16:"s",20:"m",28:"l",36:"xl"};function Tye(n){const e=Iye[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 _ye={1:"draw",2:"sans",3:"mono"},Mye={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 Ni(n,e,t){const r=[0,1,2,3,4].map(s=>Mye[n][s]);return Object.fromEntries(r.map((s,o)=>[s,o<3?e:t]))}const jf={...Ni("gray","grey","black"),...Ni("red","light-red","red"),...Ni("pink","light-red","red"),...Ni("grape","light-violet","violet"),...Ni("blue","light-blue","blue"),...Ni("cyan","light-blue","blue"),...Ni("teal","light-green","green"),...Ni("green","light-green","green"),...Ni("yellow","yellow","orange"),...Ni("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},Aye={solid:"draw",dashed:"dashed",dotted:"dotted"},Oye={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Rye={left:"start",center:"middle",right:"end"},Dye={left:"start",center:"middle",right:"end"},$N={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function jye(n,e,t){let r=0;if(n.points.length>2){const s=new P(e[0],e[1]),o=new P(t[0],t[1]),i=new P(n.points[1][0],n.points[1][1]),a=P.Sub(o,s),l=P.Per(a),c=P.Med(o,s),u=P.Sub(c,l),h=P.Add(c,l),p=P.NearestPointOnLineSegment(u,h,i,!1);r=P.Dist(p,c),P.Clockwise(p,o,c)&&(r*=-1)}return r}const Ay=n=>{let e=Aye[n.strokeStyle]??"draw";return e==="draw"&&n.roughness===0&&(e="solid"),e},Lye=n=>n.backgroundColor==="transparent"?"none":Oye[n.fillStyle]??"solid",Nye=/(^|[^`])`([^`]+)`(?!`)/,Fye=/(^|[^`])`([^`]+)`(?!`)/g,xH=ea.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",Qn(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[vu({find:Nye,type:this.type})]},addPasteRules(){return[oc({find:Fye,type:this.type})]}}),zye=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,Bye=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,vH=ea.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",Qn(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[vu({find:zye,type:this.type})]},addPasteRules(){return[oc({find:Bye,type:this.type})]}}),$ye="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",Uye="ελ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",Sh=(n,e)=>{for(const t in e)n[t]=e[t];return n},jE="numeric",LE="ascii",NE="alpha",wp="asciinumeric",tp="alphanumeric",FE="domain",wH="emoji",Hye="scheme",Kye="slashscheme",jP="whitespace";function Wye(n,e){return n in e||(e[n]=[]),e[n]}function eu(n,e,t){e[jE]&&(e[wp]=!0,e[tp]=!0),e[LE]&&(e[wp]=!0,e[NE]=!0),e[wp]&&(e[tp]=!0),e[NE]&&(e[tp]=!0),e[tp]&&(e[FE]=!0),e[wH]&&(e[FE]=!0);for(const r in e){const s=Wye(r,t);s.indexOf(n)<0&&s.push(n)}}function Vye(n,e){const t={};for(const r in e)e[r].indexOf(n)>=0&&(t[r]=!0);return t}function As(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}As.groups={};As.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],o=e.jr[r][1];if(o&&s.test(n))return o}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||As.groups;let s;return e&&e.j?s=e:(s=new As(e),t&&r&&eu(e,t,r)),this.jr.push([n,s]),s},ts(n,e,t,r){let s=this;const o=n.length;if(!o)return s;for(let i=0;i<o-1;i++)s=s.tt(n[i]);return s.tt(n[o-1],e,t,r)},tt(n,e,t,r){r=r||As.groups;const s=this;if(e&&e.j)return s.j[n]=e,e;const o=e;let i,a=s.go(n);if(a?(i=new As,Sh(i.j,a.j),i.jr.push.apply(i.jr,a.jr),i.jd=a.jd,i.t=a.t):i=new As,o){if(r)if(i.t&&typeof i.t=="string"){const l=Sh(Vye(i.t,r),t);eu(o,l,r)}else t&&eu(o,t,r);i.t=o}return s.j[n]=i,i}};const dt=(n,e,t,r,s)=>n.ta(e,t,r,s),yn=(n,e,t,r,s)=>n.tr(e,t,r,s),UN=(n,e,t,r,s)=>n.ts(e,t,r,s),xe=(n,e,t,r,s)=>n.tt(e,t,r,s),Ia="WORD",zE="UWORD",bH="ASCIINUMERICAL",CH="ALPHANUMERICAL",rg="LOCALHOST",BE="TLD",$E="UTLD",iS="SCHEME",Ld="SLASH_SCHEME",J_="NUM",UE="WS",Q_="NL",bp="OPENBRACE",Cp="CLOSEBRACE",Cx="OPENBRACKET",Px="CLOSEBRACKET",kx="OPENPAREN",Ex="CLOSEPAREN",Ix="OPENANGLEBRACKET",Tx="CLOSEANGLEBRACKET",_x="FULLWIDTHLEFTPAREN",Mx="FULLWIDTHRIGHTPAREN",Ax="LEFTCORNERBRACKET",Ox="RIGHTCORNERBRACKET",Rx="LEFTWHITECORNERBRACKET",Dx="RIGHTWHITECORNERBRACKET",jx="FULLWIDTHLESSTHAN",Lx="FULLWIDTHGREATERTHAN",Nx="AMPERSAND",Fx="APOSTROPHE",zx="ASTERISK",zl="AT",Bx="BACKSLASH",$x="BACKTICK",Ux="CARET",Hl="COLON",e2="COMMA",Hx="DOLLAR",Bi="DOT",Kx="EQUALS",t2="EXCLAMATION",ko="HYPHEN",Pp="PERCENT",Wx="PIPE",Vx="PLUS",Gx="POUND",kp="QUERY",n2="QUOTE",PH="FULLWIDTHMIDDLEDOT",r2="SEMI",$i="SLASH",Ep="TILDE",qx="UNDERSCORE",kH="EMOJI",Yx="SYM";var EH=Object.freeze({__proto__:null,ALPHANUMERICAL:CH,AMPERSAND:Nx,APOSTROPHE:Fx,ASCIINUMERICAL:bH,ASTERISK:zx,AT:zl,BACKSLASH:Bx,BACKTICK:$x,CARET:Ux,CLOSEANGLEBRACKET:Tx,CLOSEBRACE:Cp,CLOSEBRACKET:Px,CLOSEPAREN:Ex,COLON:Hl,COMMA:e2,DOLLAR:Hx,DOT:Bi,EMOJI:kH,EQUALS:Kx,EXCLAMATION:t2,FULLWIDTHGREATERTHAN:Lx,FULLWIDTHLEFTPAREN:_x,FULLWIDTHLESSTHAN:jx,FULLWIDTHMIDDLEDOT:PH,FULLWIDTHRIGHTPAREN:Mx,HYPHEN:ko,LEFTCORNERBRACKET:Ax,LEFTWHITECORNERBRACKET:Rx,LOCALHOST:rg,NL:Q_,NUM:J_,OPENANGLEBRACKET:Ix,OPENBRACE:bp,OPENBRACKET:Cx,OPENPAREN:kx,PERCENT:Pp,PIPE:Wx,PLUS:Vx,POUND:Gx,QUERY:kp,QUOTE:n2,RIGHTCORNERBRACKET:Ox,RIGHTWHITECORNERBRACKET:Dx,SCHEME:iS,SEMI:r2,SLASH:$i,SLASH_SCHEME:Ld,SYM:Yx,TILDE:Ep,TLD:BE,UNDERSCORE:qx,UTLD:$E,UWORD:zE,WORD:Ia,WS:UE});const ba=/[a-z]/,Lf=new RegExp("\\p{L}","u"),LP=new RegExp("\\p{Emoji}","u"),Ca=/\d/,NP=/\s/,HN="\r",FP=`
446
+ `,Gye="️",qye="‍",zP="";let Oy=null,Ry=null;function Yye(n=[]){const e={};As.groups=e;const t=new As;Oy==null&&(Oy=KN($ye)),Ry==null&&(Ry=KN(Uye)),xe(t,"'",Fx),xe(t,"{",bp),xe(t,"}",Cp),xe(t,"[",Cx),xe(t,"]",Px),xe(t,"(",kx),xe(t,")",Ex),xe(t,"<",Ix),xe(t,">",Tx),xe(t,"(",_x),xe(t,")",Mx),xe(t,"「",Ax),xe(t,"」",Ox),xe(t,"『",Rx),xe(t,"』",Dx),xe(t,"<",jx),xe(t,">",Lx),xe(t,"&",Nx),xe(t,"*",zx),xe(t,"@",zl),xe(t,"`",$x),xe(t,"^",Ux),xe(t,":",Hl),xe(t,",",e2),xe(t,"$",Hx),xe(t,".",Bi),xe(t,"=",Kx),xe(t,"!",t2),xe(t,"-",ko),xe(t,"%",Pp),xe(t,"|",Wx),xe(t,"+",Vx),xe(t,"#",Gx),xe(t,"?",kp),xe(t,'"',n2),xe(t,"/",$i),xe(t,";",r2),xe(t,"~",Ep),xe(t,"_",qx),xe(t,"\\",Bx),xe(t,"・",PH);const r=yn(t,Ca,J_,{[jE]:!0});yn(r,Ca,r);const s=yn(r,ba,bH,{[wp]:!0}),o=yn(r,Lf,CH,{[tp]:!0}),i=yn(t,ba,Ia,{[LE]:!0});yn(i,Ca,s),yn(i,ba,i),yn(s,Ca,s),yn(s,ba,s);const a=yn(t,Lf,zE,{[NE]:!0});yn(a,ba),yn(a,Ca,o),yn(a,Lf,a),yn(o,Ca,o),yn(o,ba),yn(o,Lf,o);const l=xe(t,FP,Q_,{[jP]:!0}),c=xe(t,HN,UE,{[jP]:!0}),u=yn(t,NP,UE,{[jP]:!0});xe(t,zP,u),xe(c,FP,l),xe(c,zP,u),yn(c,NP,u),xe(u,HN),xe(u,FP),yn(u,NP,u),xe(u,zP,u);const h=yn(t,LP,kH,{[wH]:!0});xe(h,"#"),yn(h,LP,h),xe(h,Gye,h);const p=xe(h,qye);xe(p,"#"),yn(p,LP,h);const m=[[ba,i],[Ca,s]],S=[[ba,null],[Lf,a],[Ca,o]];for(let v=0;v<Oy.length;v++)Al(t,Oy[v],BE,Ia,m);for(let v=0;v<Ry.length;v++)Al(t,Ry[v],$E,zE,S);eu(BE,{tld:!0,ascii:!0},e),eu($E,{utld:!0,alpha:!0},e),Al(t,"file",iS,Ia,m),Al(t,"mailto",iS,Ia,m),Al(t,"http",Ld,Ia,m),Al(t,"https",Ld,Ia,m),Al(t,"ftp",Ld,Ia,m),Al(t,"ftps",Ld,Ia,m),eu(iS,{scheme:!0,ascii:!0},e),eu(Ld,{slashscheme:!0,ascii:!0},e),n=n.sort((v,y)=>v[0]>y[0]?1:-1);for(let v=0;v<n.length;v++){const y=n[v][0],C=n[v][1]?{[Hye]:!0}:{[Kye]:!0};y.indexOf("-")>=0?C[FE]=!0:ba.test(y)?Ca.test(y)?C[wp]=!0:C[LE]=!0:C[jE]=!0,UN(t,y,y,C)}return UN(t,"localhost",rg,{ascii:!0}),t.jd=new As(Yx),{start:t,tokens:Sh({groups:e},EH)}}function IH(n,e){const t=Xye(e.replace(/[A-Z]/g,a=>a.toLowerCase())),r=t.length,s=[];let o=0,i=0;for(;i<r;){let a=n,l=null,c=0,u=null,h=-1,p=-1;for(;i<r&&(l=a.go(t[i]));)a=l,a.accepts()?(h=0,p=0,u=a):h>=0&&(h+=t[i].length,p++),c+=t[i].length,o+=t[i].length,i++;o-=h,i-=p,c-=h,s.push({t:u.t,v:e.slice(o-c,o),s:o-c,e:o})}return s}function Xye(n){const e=[],t=n.length;let r=0;for(;r<t;){let s=n.charCodeAt(r),o,i=s<55296||s>56319||r+1===t||(o=n.charCodeAt(r+1))<56320||o>57343?n[r]:n.slice(r,r+2);e.push(i),r+=i.length}return e}function Al(n,e,t,r,s){let o;const i=e.length;for(let a=0;a<i-1;a++){const l=e[a];n.j[l]?o=n.j[l]:(o=new As(r),o.jr=s.slice(),n.j[l]=o),n=o}return o=new As(t),o.jr=s.slice(),n.j[e[i-1]]=o,o}function KN(n){const e=[],t=[];let r=0,s="0123456789";for(;r<n.length;){let o=0;for(;s.indexOf(n[r+o])>=0;)o++;if(o>0){e.push(t.join(""));for(let i=parseInt(n.substring(r,r+o),10);i>0;i--)t.pop();r+=o}else t.push(n[r]),r++}return e}const sg={defaultProtocol:"http",events:null,format:WN,formatHref:WN,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function s2(n,e=null){let t=Sh({},sg);n&&(t=Sh(t,n instanceof s2?n.o:n));const r=t.ignoreTags,s=[];for(let o=0;o<r.length;o++)s.push(r[o].toUpperCase());this.o=t,e&&(this.defaultRender=e),this.ignoreTags=s}s2.prototype={o:sg,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]:sg[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 WN(n){return n}function TH(n,e){this.t="token",this.v=n,this.tk=e}TH.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=sg.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),o=this.toFormattedString(n),i={},a=n.get("className",t,e),l=n.get("target",t,e),c=n.get("rel",t,e),u=n.getObj("attributes",t,e),h=n.getObj("events",t,e);return i.href=r,a&&(i.class=a),l&&(i.target=l),c&&(i.rel=c),u&&Sh(i,u),{tagName:s,attributes:i,content:o,eventListeners:h}}};function kv(n,e){class t extends TH{constructor(s,o){super(s,o),this.t=n}}for(const r in e)t.prototype[r]=e[r];return t.t=n,t}const VN=kv("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),GN=kv("text"),Zye=kv("nl"),Dy=kv("url",{isLink:!0,toHref(n=sg.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==rg&&n[1].t===Hl}}),Po=n=>new As(n);function Jye({groups:n}){const e=n.domain.concat([Nx,zx,zl,Bx,$x,Ux,Hx,Kx,ko,J_,Pp,Wx,Vx,Gx,$i,Yx,Ep,qx]),t=[Fx,Hl,e2,Bi,t2,Pp,kp,n2,r2,Ix,Tx,bp,Cp,Px,Cx,kx,Ex,_x,Mx,Ax,Ox,Rx,Dx,jx,Lx],r=[Nx,Fx,zx,Bx,$x,Ux,Hx,Kx,ko,bp,Cp,Pp,Wx,Vx,Gx,kp,$i,Yx,Ep,qx],s=Po(),o=xe(s,Ep);dt(o,r,o),dt(o,n.domain,o);const i=Po(),a=Po(),l=Po();dt(s,n.domain,i),dt(s,n.scheme,a),dt(s,n.slashscheme,l),dt(i,r,o),dt(i,n.domain,i);const c=xe(i,zl);xe(o,zl,c),xe(a,zl,c),xe(l,zl,c);const u=xe(o,Bi);dt(u,r,o),dt(u,n.domain,o);const h=Po();dt(c,n.domain,h),dt(h,n.domain,h);const p=xe(h,Bi);dt(p,n.domain,h);const m=Po(VN);dt(p,n.tld,m),dt(p,n.utld,m),xe(c,rg,m);const S=xe(h,ko);xe(S,ko,S),dt(S,n.domain,h),dt(m,n.domain,h),xe(m,Bi,p),xe(m,ko,S);const v=xe(m,Hl);dt(v,n.numeric,VN);const y=xe(i,ko),w=xe(i,Bi);xe(y,ko,y),dt(y,n.domain,i),dt(w,r,o),dt(w,n.domain,i);const C=Po(Dy);dt(w,n.tld,C),dt(w,n.utld,C),dt(C,n.domain,i),dt(C,r,o),xe(C,Bi,w),xe(C,ko,y),xe(C,zl,c);const T=xe(C,Hl),E=Po(Dy);dt(T,n.numeric,E);const _=Po(Dy),A=Po();dt(_,e,_),dt(_,t,A),dt(A,e,_),dt(A,t,A),xe(C,$i,_),xe(E,$i,_);const O=xe(a,Hl),D=xe(l,Hl),F=xe(D,$i),U=xe(F,$i);dt(a,n.domain,i),xe(a,Bi,w),xe(a,ko,y),dt(l,n.domain,i),xe(l,Bi,w),xe(l,ko,y),dt(O,n.domain,_),xe(O,$i,_),xe(O,kp,_),dt(U,n.domain,_),dt(U,e,_),xe(U,$i,_);const V=[[bp,Cp],[Cx,Px],[kx,Ex],[Ix,Tx],[_x,Mx],[Ax,Ox],[Rx,Dx],[jx,Lx]];for(let Y=0;Y<V.length;Y++){const[j,N]=V[Y],z=xe(_,j);xe(A,j,z),xe(z,N,_);const G=Po(Dy);dt(z,e,G);const q=Po();dt(z,t),dt(G,e,G),dt(G,t,q),dt(q,e,G),dt(q,t,q),xe(G,N,_),xe(q,N,_)}return xe(s,rg,C),xe(s,Q_,Zye),{start:s,tokens:EH}}function Qye(n,e,t){let r=t.length,s=0,o=[],i=[];for(;s<r;){let a=n,l=null,c=null,u=0,h=null,p=-1;for(;s<r&&!(l=a.go(t[s].t));)i.push(t[s++]);for(;s<r&&(c=l||a.go(t[s].t));)l=null,a=c,a.accepts()?(p=0,h=a):p>=0&&p++,s++,u++;if(p<0)s-=u,s<r&&(i.push(t[s]),s++);else{i.length>0&&(o.push(BP(GN,e,i)),i=[]),s-=p,u-=p;const m=h.t,S=t.slice(s-u,s);o.push(BP(m,e,S))}}return i.length>0&&o.push(BP(GN,e,i)),o}function BP(n,e,t){const r=t[0].s,s=t[t.length-1].e,o=e.slice(r,s);return new n(o,t)}const eSe=typeof console<"u"&&console&&console.warn||(()=>{}),tSe="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",Qt={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function nSe(){return As.groups={},Qt.scanner=null,Qt.parser=null,Qt.tokenQueue=[],Qt.pluginQueue=[],Qt.customSchemes=[],Qt.initialized=!1,Qt}function qN(n,e=!1){if(Qt.initialized&&eSe(`linkifyjs: already initialized - will not register custom scheme "${n}" ${tSe}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(n))throw new Error(`linkifyjs: incorrect scheme format.
447
+ 1. Must only contain digits, lowercase ASCII letters or "-"
448
+ 2. Cannot start or end with "-"
449
+ 3. "-" cannot repeat`);Qt.customSchemes.push([n,e])}function rSe(){Qt.scanner=Yye(Qt.customSchemes);for(let n=0;n<Qt.tokenQueue.length;n++)Qt.tokenQueue[n][1]({scanner:Qt.scanner});Qt.parser=Jye(Qt.scanner.tokens);for(let n=0;n<Qt.pluginQueue.length;n++)Qt.pluginQueue[n][1]({scanner:Qt.scanner,parser:Qt.parser});return Qt.initialized=!0,Qt}function o2(n){return Qt.initialized||rSe(),Qye(Qt.parser.start,n,IH(Qt.scanner.start,n))}o2.scan=IH;function _H(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 s2(t),s=o2(n),o=[];for(let i=0;i<s.length;i++){const a=s[i];a.isLink&&(!e||a.t===e)&&r.check(a)&&o.push(a.toFormattedObject(r))}return o}function sSe(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function oSe(n){return new xr({key:new uo("autolink"),appendTransaction:(e,t,r)=>{const s=e.some(c=>c.docChanged)&&!t.doc.eq(r.doc),o=e.some(c=>c.getMeta("preventAutolink"));if(!s||o)return;const{tr:i}=r,a=Nle(t.doc,[...e]);if(Gle(a).forEach(({newRange:c})=>{const u=zle(r.doc,c,m=>m.isTextblock);let h,p;if(u.length>1?(h=u[0],p=r.doc.textBetween(h.pos,h.pos+h.node.nodeSize,void 0," ")):u.length&&r.doc.textBetween(c.from,c.to," "," ").endsWith(" ")&&(h=u[0],p=r.doc.textBetween(h.pos,c.to,void 0," ")),h&&p){const m=p.split(" ").filter(w=>w!=="");if(m.length<=0)return!1;const S=m[m.length-1],v=h.pos+p.lastIndexOf(S);if(!S)return!1;const y=o2(S).map(w=>w.toObject(n.defaultProtocol));if(!sSe(y))return!1;y.filter(w=>w.isLink).map(w=>({...w,from:v+w.start+1,to:v+w.end+1})).filter(w=>r.schema.marks.code?!r.doc.rangeHasMark(w.from,w.to,r.schema.marks.code):!0).filter(w=>n.validate(w.value)).filter(w=>n.shouldAutoLink(w.value)).forEach(w=>{WT(w.from,w.to,r.doc).some(C=>C.mark.type===n.type)||i.addMark(w.from,w.to,n.type.create({href:w.href}))})}}),!!i.steps.length)return i}})}function iSe(n){return new xr({key:new uo("handleClickLink"),props:{handleClick:(e,t,r)=>{var s,o;if(r.button!==0||!e.editable)return!1;let i=r.target;const a=[];for(;i.nodeName!=="DIV";)a.push(i),i=i.parentNode;if(!a.find(p=>p.nodeName==="A"))return!1;const l=j8(e.state,n.type.name),c=r.target,u=(s=c==null?void 0:c.href)!==null&&s!==void 0?s:l.href,h=(o=c==null?void 0:c.target)!==null&&o!==void 0?o:l.target;return c&&u?(window.open(u,h),!0):!1}}})}function aSe(n){return new xr({key:new uo("handlePasteLink"),props:{handlePaste:(e,t,r)=>{const{state:s}=e,{selection:o}=s,{empty:i}=o;if(i)return!1;let a="";r.content.forEach(c=>{a+=c.textContent});const l=_H(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 lSe=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;function Kc(n,e){const t=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(r=>{const s=typeof r=="string"?r:r.scheme;s&&t.push(s)}),!n||n.replace(lSe,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}const cSe=ea.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(n=>{if(typeof n=="string"){qN(n);return}qN(n.scheme,n.optionalSlashes)})},onDestroy(){nSe()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(n,e)=>!!Kc(n,e.protocols),validate:n=>!!n,shouldAutoLink:n=>!!n}},addAttributes(){return{href:{default:null,parseHTML(n){return n.getAttribute("href")}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class}}},parseHTML(){return[{tag:"a[href]",getAttrs:n=>{const e=n.getAttribute("href");return!e||!this.options.isAllowedUri(e,{defaultValidate:t=>!!Kc(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:n}){return this.options.isAllowedUri(n.href,{defaultValidate:e=>!!Kc(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",Qn(this.options.HTMLAttributes,n),0]:["a",Qn(this.options.HTMLAttributes,{...n,href:""}),0]},addCommands(){return{setLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:r=>!!Kc(r,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().setMark(this.name,n).setMeta("preventAutolink",!0).run():!1},toggleLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:r=>!!Kc(r,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().toggleMark(this.name,n,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run():!1},unsetLink:()=>({chain:n})=>n().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[oc({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:r}=this.options,s=_H(n).filter(o=>o.isLink&&this.options.isAllowedUri(o.value,{defaultValidate:i=>!!Kc(i,t),protocols:t,defaultProtocol:r}));s.length&&s.forEach(o=>e.push({text:o.value,data:{href:o.href},index:o.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(oSe({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:r=>this.options.isAllowedUri(r,{defaultValidate:s=>!!Kc(s,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),this.options.openOnClick===!0&&n.push(iSe({type:this.type})),this.options.linkOnPaste&&n.push(aSe({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type})),n}}),uSe=/^\s*>\s$/,dSe=xi.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return["blockquote",Qn(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[qp({find:uSe,type:this.type})]}}),hSe=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,fSe=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,pSe=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,gSe=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,mSe=ea.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",Qn(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[vu({find:hSe,type:this.type}),vu({find:pSe,type:this.type})]},addPasteRules(){return[oc({find:fSe,type:this.type}),oc({find:gSe,type:this.type})]}}),ySe="listItem",YN="textStyle",XN=/^\s*([-+*])\s$/,SSe=xi.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",Qn(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(ySe,this.editor.getAttributes(YN)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=qp({find:XN,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=qp({find:XN,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(YN),editor:this.editor})),[n]}}),xSe=/^```([a-z]+)?[\s\n]$/,vSe=/^~~~([a-z]+)?[\s\n]$/,wSe=xi.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,o=[...((e=n.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(i=>i.startsWith(t)).map(i=>i.replace(t,""))[0];return o||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:n,HTMLAttributes:e}){return["pre",Qn(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 o=r.parentOffset===r.parent.nodeSize-2,i=r.parent.textContent.endsWith(`
450
+
451
+ `);return!o||!i?!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:o}=t;if(!o||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(ut.near(r.resolve(a))),!0)):n.commands.exitCode()}}},addInputRules(){return[fE({find:xSe,type:this.type,getAttributes:n=>({language:n[1]})}),fE({find:vSe,type:this.type,getAttributes:n=>({language:n[1]})})]},addProseMirrorPlugins(){return[new xr({key:new uo("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,o=s==null?void 0:s.mode;if(!t||!o)return!1;const{tr:i,schema:a}=n.state,l=a.text(t.replace(/\r\n?/g,`
452
+ `));return i.replaceSelectionWith(this.type.create({language:o},l)),i.selection.$from.parent.type!==this.type&&i.setSelection(ot.near(i.doc.resolve(Math.max(0,i.selection.from-2)))),i.setMeta("paste",!0),n.dispatch(i),!0}}})]}}),bSe=xi.create({name:"doc",topNode:!0,content:"block+"});function CSe(n={}){return new xr({view(e){return new PSe(e,n)}})}class PSe{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 o=i=>{this[s](i)};return e.dom.addEventListener(s,o),{name:s,handler:o}})}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,s=this.editorView.dom,o=s.getBoundingClientRect(),i=o.width/s.offsetWidth,a=o.height/s.offsetHeight;if(t){let h=e.nodeBefore,p=e.nodeAfter;if(h||p){let m=this.editorView.nodeDOM(this.cursorPos-(h?h.nodeSize:0));if(m){let S=m.getBoundingClientRect(),v=h?S.bottom:S.top;h&&p&&(v=(v+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let y=this.width/2*a;r={left:S.left,right:S.right,top:v-y,bottom:v+y}}}}if(!r){let h=this.editorView.coordsAtPos(this.cursorPos),p=this.width/2*i;r={left:h.left-p,right:h.left+p,top:h.top,bottom:h.bottom}}let l=this.editorView.dom.offsetParent;this.element||(this.element=l.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 c,u;if(!l||l==document.body&&getComputedStyle(l).position=="static")c=-pageXOffset,u=-pageYOffset;else{let h=l.getBoundingClientRect(),p=h.width/l.offsetWidth,m=h.height/l.offsetHeight;c=h.left-l.scrollLeft*p,u=h.top-l.scrollTop*m}this.element.style.left=(r.left-c)/i+"px",this.element.style.top=(r.top-u)/a+"px",this.element.style.width=(r.right-r.left)/i+"px",this.element.style.height=(r.bottom-r.top)/a+"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,o=typeof s=="function"?s(this.editorView,t,e):s;if(t&&!o){let i=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let a=P6(this.editorView.state.doc,i,this.editorView.dragging.slice);a!=null&&(i=a)}this.setCursor(i),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}const kSe=yr.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[CSe(this.options)]}});class xn extends ut{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return xn.valid(r)?new xn(r):ut.near(r)}content(){return _e.empty}eq(e){return e instanceof xn&&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 xn(e.resolve(t.pos))}getBookmark(){return new i2(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!ESe(e)||!ISe(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&&xn.valid(e))return e;let s=e.pos,o=null;for(let i=e.depth;;i--){let a=e.node(i);if(t>0?e.indexAfter(i)<a.childCount:e.index(i)>0){o=a.child(t>0?e.indexAfter(i):e.index(i)-1);break}else if(i==0)return null;s+=t;let l=e.doc.resolve(s);if(xn.valid(l))return l}for(;;){let i=t>0?o.firstChild:o.lastChild;if(!i){if(o.isAtom&&!o.isText&&!Ge.isSelectable(o)){e=e.doc.resolve(s+o.nodeSize*t),r=!1;continue e}break}o=i,s+=t;let a=e.doc.resolve(s);if(xn.valid(a))return a}return null}}}xn.prototype.visible=!1;xn.findFrom=xn.findGapCursorFrom;ut.jsonID("gapcursor",xn);class i2{constructor(e){this.pos=e}map(e){return new i2(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return xn.valid(t)?new xn(t):ut.near(t)}}function ESe(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 ISe(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 TSe(){return new xr({props:{decorations:OSe,createSelectionBetween(n,e,t){return e.pos==t.pos&&xn.valid(t)?new xn(t):null},handleClick:MSe,handleKeyDown:_Se,handleDOMEvents:{beforeinput:ASe}}})}const _Se=d8({ArrowLeft:jy("horiz",-1),ArrowRight:jy("horiz",1),ArrowUp:jy("vert",-1),ArrowDown:jy("vert",1)});function jy(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,s,o){let i=r.selection,a=e>0?i.$to:i.$from,l=i.empty;if(i instanceof ot){if(!o.endOfTextblock(t)||a.depth==0)return!1;l=!1,a=r.doc.resolve(e>0?a.after():a.before())}let c=xn.findGapCursorFrom(a,e,l);return c?(s&&s(r.tr.setSelection(new xn(c))),!0):!1}}function MSe(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!xn.valid(r))return!1;let s=n.posAtCoords({left:t.clientX,top:t.clientY});return s&&s.inside>-1&&Ge.isSelectable(n.state.doc.nodeAt(s.inside))?!1:(n.dispatch(n.state.tr.setSelection(new xn(r))),!0)}function ASe(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof xn))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=me.empty;for(let i=r.length-1;i>=0;i--)s=me.from(r[i].createAndFill(null,s));let o=n.state.tr.replace(t.pos,t.pos,new _e(s,0,0));return o.setSelection(ot.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function OSe(n){if(!(n.selection instanceof xn))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",Fn.create(n.doc,[Ao.widget(n.selection.head,e,{key:"gapcursor"})])}const RSe=yr.create({name:"gapCursor",addProseMirrorPlugins(){return[TSe()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=gt(Fe(n,"allowGapCursor",t)))!==null&&e!==void 0?e:null}}}),DSe=xi.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",Qn(this.options.HTMLAttributes,n)]},renderText(){return`
453
+ `},addCommands(){return{setHardBreak:()=>({commands:n,chain:e,state:t,editor:r})=>n.first([()=>n.exitCode(),()=>n.command(()=>{const{selection:s,storedMarks:o}=t;if(s.$from.parent.type.spec.isolating)return!1;const{keepMarks:i}=this.options,{splittableMarks:a}=r.extensionManager,l=o||s.$to.parentOffset&&s.$from.marks();return e().insertContent({type:this.name}).command(({tr:c,dispatch:u})=>{if(u&&l&&i){const h=l.filter(p=>a.includes(p.type.name));c.ensureMarks(h)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),jSe=xi.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]}`,Qn(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=>fE({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${n}})\\s$`),type:this.type,getAttributes:{level:n}}))}});var Xx=200,Zn=function(){};Zn.prototype.append=function(e){return e.length?(e=Zn.from(e),!this.length&&e||e.length<Xx&&this.leafAppend(e)||this.length<Xx&&e.leafPrepend(this)||this.appendInner(e)):this};Zn.prototype.prepend=function(e){return e.length?Zn.from(e).append(this):this};Zn.prototype.appendInner=function(e){return new LSe(this,e)};Zn.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?Zn.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};Zn.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};Zn.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)};Zn.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var s=[];return this.forEach(function(o,i){return s.push(e(o,i))},t,r),s};Zn.from=function(e){return e instanceof Zn?e:e&&e.length?new MH(e):Zn.empty};var MH=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,o){return s==0&&o==this.length?this:new e(this.values.slice(s,o))},e.prototype.getInner=function(s){return this.values[s]},e.prototype.forEachInner=function(s,o,i,a){for(var l=o;l<i;l++)if(s(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(s,o,i,a){for(var l=o-1;l>=i;l--)if(s(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(s){if(this.length+s.length<=Xx)return new e(this.values.concat(s.flatten()))},e.prototype.leafPrepend=function(s){if(this.length+s.length<=Xx)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}(Zn);Zn.empty=new MH([]);var LSe=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,o,i){var a=this.left.length;if(s<a&&this.left.forEachInner(r,s,Math.min(o,a),i)===!1||o>a&&this.right.forEachInner(r,Math.max(s-a,0),Math.min(this.length,o)-a,i+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,o,i){var a=this.left.length;if(s>a&&this.right.forEachInvertedInner(r,s-a,Math.max(o,a)-a,i+a)===!1||o<a&&this.left.forEachInvertedInner(r,Math.min(s,a),o,i)===!1)return!1},e.prototype.sliceInner=function(r,s){if(r==0&&s==this.length)return this;var o=this.left.length;return s<=o?this.left.slice(r,s):r>=o?this.right.slice(r-o,s-o):this.left.slice(r,o).append(this.right.slice(0,s-o))},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}(Zn);const NSe=500;class ai{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,o;t&&(s=this.remapping(r,this.items.length),o=s.maps.length);let i=e.tr,a,l,c=[],u=[];return this.items.forEach((h,p)=>{if(!h.step){s||(s=this.remapping(r,p+1),o=s.maps.length),o--,u.push(h);return}if(s){u.push(new Ui(h.map));let m=h.step.map(s.slice(o)),S;m&&i.maybeStep(m).doc&&(S=i.mapping.maps[i.mapping.maps.length-1],c.push(new Ui(S,void 0,void 0,c.length+u.length))),o--,S&&s.appendMap(S,o)}else i.maybeStep(h.step);if(h.selection)return a=s?h.selection.map(s.slice(o)):h.selection,l=new ai(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:i,selection:a}}addTransform(e,t,r,s){let o=[],i=this.eventCount,a=this.items,l=!s&&a.length?a.get(a.length-1):null;for(let u=0;u<e.steps.length;u++){let h=e.steps[u].invert(e.docs[u]),p=new Ui(e.mapping.maps[u],h,t),m;(m=l&&l.merge(p))&&(p=m,u?o.pop():a=a.slice(0,a.length-1)),o.push(p),t&&(i++,t=void 0),s||(l=p)}let c=i-r.depth;return c>zSe&&(a=FSe(a,c),i-=c),new ai(a.append(o),i)}remapping(e,t){let r=new Up;return this.items.forEach((s,o)=>{let i=s.mirrorOffset!=null&&o-s.mirrorOffset>=e?r.maps.length-s.mirrorOffset:void 0;r.appendMap(s.map,i)},e,t),r}addMaps(e){return this.eventCount==0?this:new ai(this.items.append(e.map(t=>new Ui(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],s=Math.max(0,this.items.length-t),o=e.mapping,i=e.steps.length,a=this.eventCount;this.items.forEach(p=>{p.selection&&a--},s);let l=t;this.items.forEach(p=>{let m=o.getMirror(--l);if(m==null)return;i=Math.min(i,m);let S=o.maps[m];if(p.step){let v=e.steps[m].invert(e.docs[m]),y=p.selection&&p.selection.map(o.slice(l+1,m));y&&a++,r.push(new Ui(S,v,y))}else r.push(new Ui(S))},s);let c=[];for(let p=t;p<i;p++)c.push(new Ui(o.maps[p]));let u=this.items.slice(0,s).append(c).append(r),h=new ai(u,a);return h.emptyItemCount()>NSe&&(h=h.compress(this.items.length-r.length)),h}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=[],o=0;return this.items.forEach((i,a)=>{if(a>=e)s.push(i),i.selection&&o++;else if(i.step){let l=i.step.map(t.slice(r)),c=l&&l.getMap();if(r--,c&&t.appendMap(c,r),l){let u=i.selection&&i.selection.map(t.slice(r));u&&o++;let h=new Ui(c.invert(),l,u),p,m=s.length-1;(p=s.length&&s[m].merge(h))?s[m]=p:s.push(h)}}else i.map&&r--},this.items.length,0),new ai(Zn.from(s.reverse()),o)}}ai.empty=new ai(Zn.empty,0);function FSe(n,e){let t;return n.forEach((r,s)=>{if(r.selection&&e--==0)return t=s,!1}),n.slice(t)}class Ui{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 Ui(t.getMap().invert(),t,this.selection)}}}class Bl{constructor(e,t,r,s,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=s,this.prevComposition=o}}const zSe=20;function BSe(n,e,t,r){let s=t.getMeta(uu),o;if(s)return s.historyState;t.getMeta(HSe)&&(n=new Bl(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(uu))return i.getMeta(uu).redo?new Bl(n.done.addTransform(t,void 0,r,aS(e)),n.undone,ZN(t.mapping.maps),n.prevTime,n.prevComposition):new Bl(n.done,n.undone.addTransform(t,void 0,r,aS(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(i&&i.getMeta("addToHistory")===!1)){let a=t.getMeta("composition"),l=n.prevTime==0||!i&&n.prevComposition!=a&&(n.prevTime<(t.time||0)-r.newGroupDelay||!$Se(t,n.prevRanges)),c=i?$P(n.prevRanges,t.mapping):ZN(t.mapping.maps);return new Bl(n.done.addTransform(t,l?e.selection.getBookmark():void 0,r,aS(e)),ai.empty,c,t.time,a??n.prevComposition)}else return(o=t.getMeta("rebased"))?new Bl(n.done.rebased(t,o),n.undone.rebased(t,o),$P(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Bl(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),$P(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function $Se(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,s)=>{for(let o=0;o<e.length;o+=2)r<=e[o+1]&&s>=e[o]&&(t=!0)}),t}function ZN(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,s,o,i)=>e.push(o,i));return e}function $P(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let s=e.map(n[r],1),o=e.map(n[r+1],-1);s<=o&&t.push(s,o)}return t}function USe(n,e,t){let r=aS(e),s=uu.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let i=o.selection.resolve(o.transform.doc),a=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),s,r),l=new Bl(t?a:o.remaining,t?o.remaining:a,null,0,-1);return o.transform.setSelection(i).setMeta(uu,{redo:t,historyState:l})}let UP=!1,JN=null;function aS(n){let e=n.plugins;if(JN!=e){UP=!1,JN=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){UP=!0;break}}return UP}const uu=new uo("history"),HSe=new uo("closeHistory");function KSe(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new xr({key:uu,state:{init(){return new Bl(ai.empty,ai.empty,null,0,-1)},apply(e,t,r){return BSe(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,s=r=="historyUndo"?OH:r=="historyRedo"?RH:null;return s?(t.preventDefault(),s(e.state,e.dispatch)):!1}}}})}function AH(n,e){return(t,r)=>{let s=uu.getState(t);if(!s||(n?s.undone:s.done).eventCount==0)return!1;if(r){let o=USe(s,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}const OH=AH(!1,!0),RH=AH(!0,!0),WSe=yr.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>OH(n,e),redo:()=>({state:n,dispatch:e})=>RH(n,e)}},addProseMirrorPlugins(){return[KSe(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()}}}),VSe=xi.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{}}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:n}){return["hr",Qn(this.options.HTMLAttributes,n)]},addCommands(){return{setHorizontalRule:()=>({chain:n,state:e})=>{const{selection:t}=e,{$from:r,$to:s}=t,o=n();return r.parentOffset===0?o.insertContentAt({from:Math.max(r.pos-1,0),to:s.pos},{type:this.name}):Yle(t)?o.insertContentAt(s.pos,{type:this.name}):o.insertContent({type:this.name}),o.command(({tr:i,dispatch:a})=>{var l;if(a){const{$to:c}=i.selection,u=c.end();if(c.nodeAfter)c.nodeAfter.isTextblock?i.setSelection(ot.create(i.doc,c.pos+1)):c.nodeAfter.isBlock?i.setSelection(Ge.create(i.doc,c.pos)):i.setSelection(ot.create(i.doc,c.pos));else{const h=(l=c.parent.type.contentMatch.defaultType)===null||l===void 0?void 0:l.create();h&&(i.insert(u,h),i.setSelection(ot.create(i.doc,u+1)))}i.scrollIntoView()}return!0}).run()}}},addInputRules(){return[Ice({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),GSe=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,qSe=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,YSe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,XSe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,ZSe=ea.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",Qn(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[vu({find:GSe,type:this.type}),vu({find:YSe,type:this.type})]},addPasteRules(){return[oc({find:qSe,type:this.type}),oc({find:XSe,type:this.type})]}}),JSe=xi.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",Qn(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)}}}),QSe="listItem",QN="textStyle",e3=/^(\d+)\.\s$/,exe=xi.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",Qn(this.options.HTMLAttributes,t),0]:["ol",Qn(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(QSe,this.editor.getAttributes(QN)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let n=qp({find:e3,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=qp({find:e3,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(QN)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[n]}}),txe=xi.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Qn(this.options.HTMLAttributes,n),0]},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),nxe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,rxe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,sxe=ea.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",Qn(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[vu({find:nxe,type:this.type})]},addPasteRules(){return[oc({find:rxe,type:this.type})]}}),oxe=xi.create({name:"text",group:"inline"}),ixe=yr.create({name:"starterKit",addExtensions(){const n=[];return this.options.bold!==!1&&n.push(mSe.configure(this.options.bold)),this.options.blockquote!==!1&&n.push(dSe.configure(this.options.blockquote)),this.options.bulletList!==!1&&n.push(SSe.configure(this.options.bulletList)),this.options.code!==!1&&n.push(xH.configure(this.options.code)),this.options.codeBlock!==!1&&n.push(wSe.configure(this.options.codeBlock)),this.options.document!==!1&&n.push(bSe.configure(this.options.document)),this.options.dropcursor!==!1&&n.push(kSe.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&n.push(RSe.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&n.push(DSe.configure(this.options.hardBreak)),this.options.heading!==!1&&n.push(jSe.configure(this.options.heading)),this.options.history!==!1&&n.push(WSe.configure(this.options.history)),this.options.horizontalRule!==!1&&n.push(VSe.configure(this.options.horizontalRule)),this.options.italic!==!1&&n.push(ZSe.configure(this.options.italic)),this.options.listItem!==!1&&n.push(JSe.configure(this.options.listItem)),this.options.orderedList!==!1&&n.push(exe.configure(this.options.orderedList)),this.options.paragraph!==!1&&n.push(txe.configure(this.options.paragraph)),this.options.strike!==!1&&n.push(sxe.configure(this.options.strike)),this.options.text!==!1&&n.push(oxe.configure(this.options.text)),n}}),a2={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"}}}},axe=Sn(a2).flatMap(n=>Sn(n).flatMap(e=>Object.values(e))),lxe=yr.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})}}}]}}),cxe=yr.create({name:"keyboardShiftEnterHandler",addKeyboardShortcuts(){return{"Shift-Enter":({editor:n})=>n.commands.enter()}}});xH.config.excludes=void 0;vH.config.priority=1100;const Kg=[ixe.configure({blockquote:!1,codeBlock:!1,horizontalRule:!1}),cSe.configure({openOnClick:!1,autolink:!0}),vH,cxe,lxe];function l2(n,e){var s;const t=((s=n.getTextOptions().tipTapConfig)==null?void 0:s.extensions)??Kg;return $le(e,t).replaceAll('<p dir="auto"></p>',"<p><br /></p>")??""}function Zx(n,e){return`<div class="tl-rich-text">${l2(n,e)}</div>`}const uxe=new zo;function ii(n){return n.content.length===1&&!n.content[0].content}function Cu(n,e){return ii(e)?"":uxe.get(e,()=>{var r;const t=((r=n.getTextOptions().tipTapConfig)==null?void 0:r.extensions)??Kg;return Hle(e,t,{blockSeparator:`
454
+ `})})}function dxe(n,e){var r;const t=((r=n.getTextOptions().tipTapConfig)==null?void 0:r.extensions)??Kg;return Ule(e,t)}function DH(n,e,t){for(const i of n.marks)i.type.name==="bold"&&e.weight!=="bold"&&(e={...e,weight:"bold"}),i.type.name==="italic"&&e.style!=="italic"&&(e={...e,style:"italic"}),i.type.name==="code"&&e.family!=="tldraw_mono"&&(e={...e,family:"tldraw_mono"});const r=kn(a2,e.family);if(!r)return e;const s=kn(r,e.style);if(!s)return e;const o=kn(s,e.weight);return o&&t(o),e}const hxe=" ",Mp=class Mp{static normalizeText(e){return e.replace(Mp.fixNewLines,`
455
+ `)}static normalizeTextForDom(e){return e.replace(Mp.fixNewLines,`
456
+ `).split(`
457
+ `).map(t=>t||" ").join(`
458
+ `)}};R(Mp,"fixNewLines",/\r?\n|\r/g);let Jx=Mp;const fxe=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function jH(n){return fxe.test(n)}function pxe(n){return n.replace(/\t/g,hxe)}function gxe(n){const e=n.split(`
459
+ `);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(`
460
+ `)}const LH={"&amp;":"&","&quot;":'"',"&apos;":"'","&#27;":"'","&#34;":'"',"&#38;":"&","&#39;":"'","&#8211;":"–","&#8212;":"—","&#8216;":"‘","&#8217;":"’","&#8220;":"“","&#8221;":"”","&#8230;":"…"},mxe=new RegExp(Object.keys(LH).join("|"),"g");function NH(n){return n.replace(mxe,e=>LH[e])}function yxe(n){return n.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function Sxe(n){return yxe(gxe(pxe(n)))}const FH=5e3,zH=10*1024*1024;function xxe(n,e){n.registerExternalAssetHandler("file",async t=>vxe(n,t,e)),n.registerExternalAssetHandler("url",async t=>wxe(n,t,e)),n.registerExternalContentHandler("svg-text",async t=>bxe(n,t)),n.registerExternalContentHandler("embed",t=>Cxe(n,t)),n.registerExternalContentHandler("files",async t=>Pxe(n,t,e)),n.registerExternalContentHandler("text",async t=>kxe(n,t)),n.registerExternalContentHandler("url",async t=>Exe(n,t,e)),n.registerExternalContentHandler("tldraw",async t=>Ixe(n,t)),n.registerExternalContentHandler("excalidraw",async t=>Txe(n,t))}async function vxe(n,{file:e,assetId:t},{acceptedImageMimeTypes:r=lg,acceptedVideoMimeTypes:s=s0,maxAssetSize:o=zH,maxImageDimension:i=FH,toasts:a,msg:l}){const c=r.includes(e.type),u=s.includes(e.type);!c&&!u&&a.addToast({title:l("assets.files.type-not-allowed"),severity:"error"}),Ve(c||u,`File type not allowed: ${e.type}`),e.size>o&&a.addToast({title:l("assets.files.size-too-big"),severity:"error"}),Ve(e.size<=o,`File size too big: ${(e.size/1024).toFixed()}kb > ${(o/1024).toFixed()}kb`);const h=G3(await e.arrayBuffer());t=t??nc.createId(h);const p=await BH(e,t,c,u,i),m=await n.uploadAsset(p,e);return p.props.src=m.src,m.meta&&(p.meta={...p.meta,...m.meta}),nc.create(p)}async function wxe(n,{url:e},{toasts:t,msg:r}){var o,i,a,l,c;let s;try{const h=await(await di(e,{method:"GET",mode:"no-cors"})).text(),p=new DOMParser().parseFromString(h,"text/html");s={image:((o=p.head.querySelector('meta[property="og:image"]'))==null?void 0:o.getAttribute("content"))??"",favicon:((i=p.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:i.getAttribute("href"))??((a=p.head.querySelector('link[rel="icon"]'))==null?void 0:a.getAttribute("href"))??"",title:((l=p.head.querySelector('meta[property="og:title"]'))==null?void 0:l.getAttribute("content"))??e,description:((c=p.head.querySelector('meta[property="og:description"]'))==null?void 0:c.getAttribute("content"))??""},s.image.startsWith("http")||(s.image=new URL(s.image,e).href),s.favicon.startsWith("http")||(s.favicon=new URL(s.favicon,e).href)}catch(u){console.error(u),t.addToast({title:r("assets.url.failed"),severity:"error"}),s={image:"",favicon:"",title:"",description:""}}return{id:nc.createId(dI(e)),typeName:"asset",type:"bookmark",props:{src:e,description:s.description,image:s.image,favicon:s.favicon,title:s.title},meta:{}}}async function bxe(n,{point:e,text:t}){const r=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),s=new DOMParser().parseFromString(t,"image/svg+xml").querySelector("svg");if(!s)throw new Error("No <svg/> element present");let o=parseFloat(s.getAttribute("width")||"0"),i=parseFloat(s.getAttribute("height")||"0");if(!(o&&i)){document.body.appendChild(s);const l=s.getBoundingClientRect();document.body.removeChild(s),o=l.width,i=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");$H(n,[a],r)}function Cxe(n,{point:e,url:t,embed:r}){const s=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),{width:o,height:i}=r,a=Nt(),l=lo(new P(s.x-(o||450)/2,s.y-(i||450)/2),n),c={id:a,type:"embed",x:l.x,y:l.y,props:{w:o,h:i,url:t}};n.createShapes([c]).select(a)}async function Pxe(n,{point:e,files:t},{maxAssetSize:r=zH,maxImageDimension:s=FH,acceptedImageMimeTypes:o=lg,acceptedVideoMimeTypes:i=s0,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),u=new P(c.x,c.y),h=[],p=[];for(const m of t){if(m.size>r){a.addToast({title:l("assets.files.size-too-big"),severity:"error"}),console.warn(`File size too big: ${(m.size/1024).toFixed()}kb > ${(r/1024).toFixed()}kb`);continue}if(!m.type){a.addToast({title:l("assets.files.upload-failed"),severity:"error"}),console.error("No mime type");continue}if(![...o,...i].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=o.includes(m.type),y=i.includes(m.type),w=G3(await m.arrayBuffer()),C=nc.createId(w),T=await BH(m,C,v,y,s);let E;v&&(E=n.createTemporaryAssetPreview(C,m)),h.push(T),p.push({asset:T,file:m,temporaryAssetPreview:E})}Promise.allSettled(p.map(async m=>{try{const S=await n.getAssetForExternalContent({type:"file",file:m.file});if(!S)throw Error("Could not create an asset");n.updateAssets([{...S,id:m.asset.id}])}catch(S){a.addToast({title:l("assets.files.upload-failed"),severity:"error"}),console.error(S),n.deleteAssets([m.asset.id]);return}})),$H(n,h,u)}async function kxe(n,{point:e,text:t,html:r}){const s=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),o=n.getShapeUtil("text").getDefaultProps(),i=Sxe(t),a=r?dxe(n,r):Fo(i);let l,c,u,h="middle";const p=r??i.replace(/\n/g,"<br>"),m=r?a.content.length>1:i.split(`
461
+ `).length>1,S=jH(i);m&&(h=m?S?"end":"start":"middle");const v=n.textMeasure.measureHtml(p,{...mr,fontFamily:Xa[o.font],fontSize:yh[o.size],maxWidth:null}),y=Math.min(m?n.getViewportPageBounds().width*.9:920,Math.max(200,n.getViewportPageBounds().width*.9));if(v.w>y){const C=n.textMeasure.measureHtml(p,{...mr,fontFamily:Xa[o.font],fontSize:yh[o.size],maxWidth:y});l=C.w,c=C.h,u=!1,h=S?"end":"start"}else l=v.w,c=v.h,u=!0;s.y-c/2<n.getViewportPageBounds().minY+40&&(s.y=n.getViewportPageBounds().minY+40+c/2);const w=lo(new P(s.x-l/2,s.y-c/2),n);n.createShapes([{id:Nt(),type:"text",x:w.x,y:w.y,props:{richText:a,textAlign:h,autoSize:u,w:l}}])}async function Exe(n,{point:e,url:t},{toasts:r,msg:s}){const o=n.getShapeUtil("embed"),i=o==null?void 0:o.getEmbedDefinition(t);if(i)return n.putExternalContent({type:"embed",url:i.url,point:e,embed:i.definition});const a=e??(n.inputs.shiftKey?n.inputs.currentPagePoint:n.getViewportPageBounds().center),l=nc.createId(dI(t)),c=_xe(n,t,a);let u=n.getAsset(l),h=!1;if(!u){h=!0;try{const p=await n.getAssetForExternalContent({type:"url",url:t});if(!p)throw Error("Could not create an asset");u=p}catch{r.addToast({title:s("assets.url.failed"),severity:"error"});return}}n.run(()=>{h&&n.createAssets([u]),n.updateShapes([{id:c.id,type:c.type,props:{assetId:u.id}}])})}async function Ixe(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 Txe(n,{point:e,content:t}){n.run(()=>{kye(n,t,e)})}async function BH(n,e,t,r,s){let o=n.type;n.type==="video/quicktime"&&(o="video/mp4");const i=t?await Zs.getImageSize(n):await Zs.getVideoSize(n),a=await Zs.isAnimated(n)||r,l={id:e,type:t?"image":"video",typeName:"asset",props:{name:n.name,src:"",w:i.w,h:i.h,fileSize:n.size,mimeType:o,isAnimated:a},meta:{}};if(s&&isFinite(s)){const c={w:l.props.w,h:l.props.h},u=Pye(c,{w:s,h:s});c!==u&&Zs.isStaticImageType(n.type)&&(l.props.w=u.w,l.props.h=u.h)}return l}async function $H(n,e,t){if(!e.length)return[];const r=P.From(t),s=[];for(let o=0;o<e.length;o++){const i=e[o];switch(i.type){case"image":{s.push({id:Nt(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":s.push({id:Nt(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}}return n.run(()=>{const o=e.filter(i=>!n.getAsset(i.id));n.store.atomic(()=>{o.length&&n.createAssets(o),n.createShapes(s).select(...s.map(i=>i.id)),UH(n,t)})}),s.map(o=>o.id)}function UH(n,e){const t=n.getViewportPageBounds();let r=n.getSelectionPageBounds();if(r){const s=r.center.sub(e);n.updateShapes(n.getSelectedShapes().map(o=>{const i=n.getShapeParentTransform(o).decompose().rotation,a=P.Rot(s,-i);return{id:o.id,type:o.type,x:o.x-a.x,y:o.y-a.y}}))}if(r=n.getSelectionPageBounds(),r&&n.getInstanceState().isGridMode){const s=n.getDocumentSettings().gridSize,o=new P(r.minX,r.minY),i=o.clone().snapToGrid(s),a=P.Sub(o,i);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 _xe(n,e,t){const r={id:Nt(),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),UH(n,t)}),n.getShape(r.id)}var tk;let Mxe=(tk=class extends Le{constructor(){super(...arguments);R(this,"options",this.editor.getShapeUtil("arrow").options);R(this,"isPrecise",!1);R(this,"isPreciseTimerId",null);R(this,"preciseTargetId",null)}onPointerMove(){this.update()}onPointerDown(t){this.parent.transition("pointing",{...t,isPrecise:this.isPrecise})}onEnter(){this.editor.setCursor({type:"cross",rotation:0}),this.update()}onCancel(){this.editor.setCurrentTool("select")}onExit(){Y_(this.editor),this.isPreciseTimerId!==null&&clearTimeout(this.isPreciseTimerId)}onKeyDown(){this.update()}onKeyUp(t){var r;if(this.update(),t.key==="Enter"){if(this.editor.getIsReadonly())return null;const s=this.editor.getOnlySelectedShape();s&&this.editor.getShapeUtil(s).canEdit(s)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(s.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...t,target:"shape",shape:s}))}}update(){const t=Cv({editor:this.editor,pointInPageSpace:this.editor.inputs.currentPagePoint,arrow:void 0,isPrecise:this.isPrecise,isExact:this.editor.inputs.altKey,currentBinding:void 0,oppositeBinding:void 0});t&&t.target.id!==this.preciseTargetId?(this.isPreciseTimerId!==null&&clearTimeout(this.isPreciseTimerId),this.preciseTargetId=t.target.id,this.isPreciseTimerId=this.editor.timers.setTimeout(()=>{this.isPrecise=!0,this.update()},this.options.hoverPreciseTimeout)):!t&&this.preciseTargetId&&(this.isPrecise=!1,this.preciseTargetId=null,this.isPreciseTimerId!==null&&clearTimeout(this.isPreciseTimerId))}},R(tk,"id","idle"),tk);var nk;let Axe=(nk=class extends Le{constructor(){super(...arguments);R(this,"options",this.editor.getShapeUtil("arrow").options);R(this,"shape");R(this,"isPrecise",!1);R(this,"isPreciseTimerId",null);R(this,"markId","")}onEnter(t){this.markId="",this.isPrecise=!!t.isPrecise,Cv({editor:this.editor,pointInPageSpace:this.editor.inputs.currentPagePoint,arrow:void 0,isPrecise:this.isPrecise,isExact:this.editor.inputs.altKey,currentBinding:void 0,oppositeBinding:void 0})||this.createArrowShape(),this.startPreciseTimeout()}onExit(){this.shape=void 0,Y_(this.editor),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.parent.transition("idle")}createArrowShape(){var h;const{originPagePoint:t}=this.editor.inputs,r=Nt();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`);const s=lo(t,this.editor);this.editor.createShape({id:r,type:"arrow",x:s.x,y:s.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const i=this.editor.getShapeHandles(o);if(!i)throw Error("expected handles for arrow");const a=this.editor.getShapeUtil("arrow"),l=this.shape,c=i.find(p=>p.id==="start"),u=(h=a.onHandleDrag)==null?void 0:h.call(a,o,{handle:{...c,x:0,y:0},isPrecise:!0,initial:l});u&&this.editor.updateShapes([u]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,o;const t=this.shape;if(!t)throw Error("expected shape");const r=this.editor.getShapeHandles(t);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=r.find(u=>u.id==="start"),c=(s=i.onHandleDrag)==null?void 0:s.call(i,t,{handle:{...l,x:0,y:0},isPrecise:this.isPrecise,initial:a});c&&this.editor.updateShapes([c])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),c=r.find(h=>h.id==="end"),u=(o=i.onHandleDrag)==null?void 0:o.call(i,this.editor.getShape(t),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.isPreciseTimerId=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.isPrecise=!0)},this.options.pointingPreciseTimeout)}clearPreciseTimeout(){this.isPreciseTimerId!==null&&clearTimeout(this.isPreciseTimerId)}},R(nk,"id","pointing"),nk);class HE extends Le{constructor(){super(...arguments);R(this,"shapeType","arrow")}static children(){return[Mxe,Axe]}}R(HE,"id","arrow"),R(HE,"initial","idle");class c2 extends Le{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?P.Dist(t.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=t.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape()}onKeyDown(t){if(t.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()}onKeyUp(t){if(t.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()}onExit(){this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()}canClose(){return this.shapeType!=="highlight"}getIsClosed(t,r,s){if(!this.canClose())return!1;const o=Dn[r],i=t[0].points[0],a=t[t.length-1],l=a.points[a.points.length-1];return i!==l&&this.currentLineLength>o*4*s&&P.DistMin(i,l,o*2*s)}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId=this.editor.markHistoryStoppingPoint("draw start");const{z:s=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||s>0&&s<.5||s>.5&&s<1;const o=this.isPenOrStylus?s*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=t.clone(),this.initialShape){const a=this.editor.getShape(this.initialShape.id);if(a&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const l=cr(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=cr(l.points);if(!c)throw Error("Expected a previous point!");const{x:u,y:h}=this.editor.getPointInShapeSpace(a,t).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+o.toFixed(2)},{x:u,y:h,z:+o.toFixed(2)}]},m=de.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=m,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,p];this.currentLineLength<Dn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const v={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(v.props.isClosed=this.getIsClosed(S,a.props.size,a.props.scale)),this.editor.updateShapes([v]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const i=Nt();this.editor.createShapes([{id:i,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+o.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:s,props:{size:o,scale:i}}=t,a=this.editor.getShape(s);if(!a)return;const{segments:l}=a.props,{x:c,y:u,z:h}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),p=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,m={x:c,y:u,z:p};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:S}=this;if(S===null)throw Error("We should have a point where the segment changed");if(P.Dist2(S,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const y=cr(l);if(!y)throw Error("Expected a previous segment!");const w=cr(y.points);if(!w)throw Error("Expected a previous last point!");let C;const T=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(y.type==="straight"){this.currentLineLength+=P.Dist(w,T),C={type:"straight",points:[{...w},T]};const _=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=de.applyToPoint(_,w)}else C={type:"straight",points:[T,m]};const E={id:s,type:this.shapeType,props:{segments:[...l,C]}};this.canClose()&&(E.props.isClosed=this.getIsClosed(l,o,i)),this.editor.updateShapes([E])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:S}=this;if(S===null)throw Error("We should have a point where the segment changed");if(P.Dist2(S,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const y=l.slice(),w=y[y.length-1],C=cr(w.points);if(!C)throw Error("No previous point!");const T={type:"free",points:[...P.PointsBetween(C,m,6).map(A=>({x:Aa(A.x),y:Aa(A.y),z:Aa(A.z)}))]},E=[...y,T];this.currentLineLength<Dn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(E));const _={id:s,type:this.shapeType,props:{segments:E}};this.canClose()&&(_.props.isClosed=this.getIsClosed(E,o,i)),this.editor.updateShapes([_])}break}case"straight":{const S=l.slice(),v=S[S.length-1],{pagePointWhereCurrentSegmentChanged:y}=this,{ctrlKey:w,currentPagePoint:C}=this.editor.inputs;if(!y)throw Error("We should have a point where the segment changed");let T,E=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(E=!w,this.didJustShiftClickToExtendPreviousShapeLine=!1):E=!w;let _=this.editor.getPointInShapeSpace(a,C).toFixed().toJson(),A=!1,O;if((this.editor.user.getIsSnapMode()?!w:w)&&S.length>2){let U,V=8/this.editor.getZoomLevel();for(let Y=0,j=l.length-2;Y<j;Y++){const N=l[Y];if(!N)break;if(N.type==="free")continue;const z=N.points[0],G=cr(N.points);if(!(z&&G))continue;const q=P.NearestPointOnLineSegment(z,G,_);if(P.DistMin(q,_,V)){U=q.toFixed().toJson(),V=P.Dist(q,_),O=N;break}}U&&(A=!0,_=U)}if(A&&O){const U=this.editor.getShapePageTransform(a),V=O.points[0],Y=cr(O.points);if(!Y)throw Error("Expected a last point!");const j=de.applyToPoint(U,V),N=de.applyToPoint(U,Y),z=de.applyToPoint(U,_);this.editor.snaps.setIndicators([{id:Mt(),type:"points",points:[j,z,N]}])}else{if(this.editor.snaps.clearIndicators(),E){const U=P.Angle(y,C),Y=KS(U,24)-U;T=P.RotWith(C,y,Y)}else T=C;_=this.editor.getPointInShapeSpace(a,T).toFixed().toJson()}this.currentLineLength+=P.Dist(v.points[0],_),S[S.length-1]={...v,type:"straight",points:[v.points[0],_]};const F={id:s,type:this.shapeType,props:{segments:S}};this.canClose()&&(F.props.isClosed=this.getIsClosed(l,o,i)),this.editor.updateShapes([F]);break}case"free":{const S=l.slice(),v=S[S.length-1],y=[...v.points];if(y.length&&this.mergeNextPoint){const{z:C}=y[y.length-1];y[y.length-1]={x:m.x,y:m.y,z:C?Math.max(C,m.z):m.z}}else this.currentLineLength+=P.Dist(y[y.length-1],m),y.push(m);S[S.length-1]={...v,points:y},this.currentLineLength<Dn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const w={id:s,type:this.shapeType,props:{segments:S}};if(this.canClose()&&(w.props.isClosed=this.getIsClosed(S,o,i)),this.editor.updateShapes([w]),y.length>this.util.options.maxPointsPerShape){this.editor.updateShapes([{id:s,type:this.shapeType,props:{isComplete:!0}}]);const C=Nt(),T=this.editor.getShape(s).props;this.editor.createShapes([{id:C,type:this.shapeType,x:Aa(r.currentPagePoint.x),y:Aa(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:T.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(h*1.25).toFixed():.5}]}]}}]),this.initialShape=en(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 o=0;o<s.points.length-1;o++){const i=s.points[o],a=s.points[o+1];r+=P.Dist2(a,i)}return Math.sqrt(r)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())}complete(){const{initialShape:t}=this;t&&(this.editor.updateShapes([{id:t.id,type:t.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}R(c2,"id","drawing");var rk;let HH=(rk=class extends Le{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},R(rk,"id","idle"),rk);class np extends Le{constructor(){super(...arguments);R(this,"shapeType","draw")}static children(){return[HH,c2]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}R(np,"id","draw"),R(np,"initial","idle"),R(np,"isLockable",!1),R(np,"useCoalescedEvents",!0);class KE extends Vk{constructor(){super(...arguments);R(this,"shapeType","frame")}onCreate(t){if(!t)return;const r=this.editor.getShapePageBounds(t),s=[],o=this.editor.getShapeAncestors(t).map(i=>i.id);this.editor.getSortedChildIdsForParent(t.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===t.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&Oxe(a,o,t)&&s.push(a.id)}),this.editor.reparentShapes(s,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")}}R(KE,"id","frame"),R(KE,"initial","idle");function Oxe(n,e,t){return e.includes(n.id)?!1:n.parentId===t.parentId}var sk;let Rxe=(sk=class extends Le{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(sk,"id","idle"),sk);var ok;let Dxe=(ok=class extends Le{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:t}=this.editor.inputs,r=Nt(),s=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`),o=lo(t,this.editor);this.editor.createShapes([{id:r,type:"geo",x:o.x,y:o.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(ui),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=Nt();this.editor.markHistoryStoppingPoint(`creating_geo:${t}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(ui),o=s==="star"?{w:200,h:190}:s==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:t,type:"geo",x:e.x,y:e.y,props:{geo:this.editor.getStyleForNextShape(ui),scale:r,...o}}]);const i=this.editor.getShape(t);if(!i)return;const{w:a,h:l}=i.props,c=new P(a/2,l/2).mul(r),u=this.editor.getShapeParentTransform(i);u&&c.rot(-u.rotation());const h=lo(new P(i.x-c.x,i.y-c.y),this.editor);this.editor.select(t),this.editor.updateShape({id:i.id,type:"geo",x:h.x,y:h.y,props:{geo:this.editor.getStyleForNextShape(ui),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},R(ok,"id","pointing"),ok);class WE extends Le{constructor(){super(...arguments);R(this,"shapeType","geo")}static children(){return[Rxe,Dxe]}}R(WE,"id","geo"),R(WE,"initial","idle");class rp extends Le{constructor(){super(...arguments);R(this,"shapeType","highlight")}static children(){return[HH,c2]}onExit(){const t=this.children.drawing;t.initialShape=void 0}}R(rp,"id","highlight"),R(rp,"initial","idle"),R(rp,"useCoalescedEvents",!0),R(rp,"isLockable",!1);var ik;let jxe=(ik=class extends Le{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(ik,"id","idle"),ik);const t3=2;var ak;let Lxe=(ak=class extends Le{constructor(){super(...arguments);R(this,"shape",{});R(this,"markId")}onEnter(t){const{inputs:r}=this.editor,{currentPagePoint:s}=r;this.markId=void 0;const o=t.shapeId&&this.editor.getShape(t.shapeId);if(o&&r.shiftKey){this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${o.id}`),this.shape=o;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(S=>S.type==="vertex").sort(ur),l=a[a.length-1],c=a[a.length-2],u=de.applyToPoint(this.editor.getShapeParentTransform(this.shape),new P(this.shape.x,this.shape.y)),h=P.Sub(s,u).addXY(.1,.1),p=lo(h,this.editor),m=en(this.shape.props.points);if(P.DistMin(l,c,t3)||P.DistMin(p,l,t3))m[l.id]={id:l.id,index:l.index,x:p.x,y:p.y};else{const S=Wi(l.index);m[S]={id:S,index:S,x:p.x,y:p.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:m}}])}else{const i=Nt();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i}`);const a=lo(s,this.editor);this.editor.createShapes([{id:i,type:"line",x:a.x,y:a.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}}onPointerMove(){if(this.shape&&this.editor.inputs.isDragging){const t=this.editor.getShapeHandles(this.shape);if(!t)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=cr(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(ak,"id","pointing"),ak);class VE extends Le{constructor(){super(...arguments);R(this,"shapeType","line")}static children(){return[jxe,Lxe]}}R(VE,"id","line"),R(VE,"initial","idle");var lk;let Nxe=(lk=class extends Le{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},R(lk,"id","idle"),lk);const Fxe=0,Lt=200,Ev=new P(Lt/2,Lt/2),KH=10,zxe=n=>[[["a1"],new P(Lt*.5,Lt*-.5-n.options.adjacentShapeMargin)],[["a2"],new P(Lt*1.5+n.options.adjacentShapeMargin,Lt*.5)],[["a3"],new P(Lt*.5,Lt*1.5+n.options.adjacentShapeMargin)],[["a4"],new P(Lt*-.5-n.options.adjacentShapeMargin,Lt*.5)]];function Bxe(n,e){if(e===1)return zxe(n);const t=Lt*e,r=n.options.adjacentShapeMargin*e;return[[["a1"],new P(t*.5,t*-.5-r)],[["a2"],new P(t*1.5+r,t*.5)],[["a3"],new P(t*.5,t*1.5+r)],[["a4"],new P(t*-.5-r,t*.5)]]}function WH(n,e,t,r,s,o){return Object.fromEntries(Bxe(n,o).map(([i,a],l)=>{const c=a.clone();return l===0&&s?c.y-=s:l===2&&r&&(c.y+=r),[i,c.rot(t).add(e)]}))}function VH(n,e,t,r){const s=new Set(n.getSelectedShapeIds()),o=(Lt+n.options.adjacentShapeMargin+r)**2,i=new Map,a=[];for(const u of n.getCurrentPageShapes()){if(!n.isShapeOfType(u,"note")||t!==u.props.scale||s.has(u.id))continue;const h=n.getShapePageTransform(u.id);e===h.rotation()&&(i.set(u,n.getShapePageBounds(u).center),a.push(...Object.values(WH(n,h.point(),e,u.props.growY,r,t))))}const l=a.length;let c;for(const[u,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(P.Dist2(h,c)>o||n.isPointInShape(u,c)&&(a[p]=void 0));return st(a)}function GH(n,e,t,r,s=!1){let o;const i=n.getCurrentPageShapesSorted(),a=(Lt+n.options.adjacentShapeMargin**2)**e.props.scale;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==e.id){const u=n.getShapePageBounds(c);if(u&&P.Dist2(u.center,t)<a&&n.isPointInShape(c,t)){o=c;break}}}if(n.complete(),!o||s){n.markHistoryStoppingPoint("creating note shape");const l=Nt();n.createShape({id:l,type:"note",x:t.x,y:t.y,rotation:r,opacity:e.opacity,props:{...e.props,richText:Fo(""),growY:0,fontSizeAdjustment:0,url:""}});const c=n.getShape(l);if(!c)return;const u=n.getPointInParentSpace(c,P.Sub(t,P.Rot(Ev.clone().mul(c.props.scale),r)));n.updateShape({id:l,type:"note",x:u.x,y:u.y}),o=n.getShape(l)}return n.zoomToSelectionIfOffscreen(16,{animation:{duration:n.options.animationMediumMs},inset:0}),o}var ck;let $xe=(ck=class extends Le{constructor(){super(...arguments);R(this,"dragged",!1);R(this,"info",{});R(this,"markId","");R(this,"shape",{})}onEnter(){const{editor:t}=this,r=Nt();this.markId=t.markHistoryStoppingPoint(`creating_note:${r}`);const s=this.editor.inputs.originPagePoint.clone(),o=Uxe(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);o&&s.sub(o),this.shape=Hxe(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(ck,"id","pointing"),ck);function Uxe(n,e,t){let r=KH/n.getZoomLevel(),s;for(const o of VH(n,0,t,0)){const i=P.Sub(e,o),a=i.len();a<r&&(r=a,s=i)}return s}function Hxe(n,e,t){n.createShape({id:e,type:"note",x:t.x,y:t.y,props:{scale:n.user.getIsDynamicResizeMode()?1/n.getZoomLevel():1}}).select(e);const r=n.getShape(e),s=n.getShapeGeometry(r).bounds,o=lo(new P(r.x-s.width/2,r.y-s.height/2),n);return n.updateShapes([{id:e,type:"note",x:o.x,y:o.y}]),n.getShape(e)}class GE extends Le{constructor(){super(...arguments);R(this,"shapeType","note")}static children(){return[Nxe,$xe]}}R(GE,"id","note"),R(GE,"initial","idle");function Kxe(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 ja=H3(Kxe,32);var uk;let Wxe=(uk=class extends Le{onPointerMove(e){switch(e.target){case"shape":case"canvas":ja(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){ja.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(uk,"id","idle"),uk);var dk;let Vxe=(dk=class extends Le{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:o,currentPagePoint:i}=r.inputs,a=Math.abs(o.x-i.x),c=Math.sqrt(r.getInstanceState().isCoarsePointer?r.options.coarseDragDistanceSquared:r.options.dragDistanceSquared)*6/r.getZoomLevel();if(a>c){const u=Nt();this.markId=r.markHistoryStoppingPoint(`creating_text:${u}`);const h=this.createTextShape(u,o,!1,a);if(!h){this.cancel();return}this.shape=r.getShape(h),r.select(u),r.setCurrentTool("select.resizing",{...t,target:"selection",handle:"right",isCreating:!0,creatingMarkId:this.markId,creationCursorOffset:{x:a,y:1},onInteractionEnd:"text",onCreate:()=>{r.setEditingShape(h.id)}})}}onPointerUp(){this.complete()}onComplete(){this.cancel()}onCancel(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.editor.markHistoryStoppingPoint("creating text shape");const t=Nt(),{originPagePoint:r}=this.editor.inputs;this.createTextShape(t,r,!0,20)&&(this.editor.select(t),this.editor.setEditingShape(t))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(t,r,s,o){this.editor.createShape({id:t,type:"text",x:r.x,y:r.y,props:{richText:Fo(""),autoSize:s,w:o,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const i=this.editor.getShape(t);if(!i){this.cancel();return}const a=this.editor.getShapePageBounds(i),l=new P;if(s)switch(i.props.textAlign){case"start":{l.x=0;break}case"middle":{l.x=-a.width/2;break}case"end":{l.x=-a.width;break}}else l.x=0;if(l.y=-a.height/2,Ts(i.parentId)){const h=this.editor.getShapeParentTransform(i);l.rot(-h.rotation())}const c=i.x+l.x,u=i.y+l.y;if(this.editor.getInstanceState().isGridMode){const h=new P(c,u),p=lo(h,this.editor),m=P.Sub(h,p);this.editor.updateShape({...i,x:c-m.x,y:u-m.y})}else this.editor.updateShape({...i,x:c,y:u});return i}},R(dk,"id","pointing"),dk);class qE extends Le{constructor(){super(...arguments);R(this,"shapeType","text")}static children(){return[Wxe,Vxe]}}R(qE,"id","text"),R(qE,"initial","idle");const Gxe=[qE,np,WE,GE,VE,KE,HE,rp];function qxe(n,e=20){return Math.max(8,Math.ceil(n/e))}class Ha{constructor(){R(this,"lines",[])}static throughPoints(e,t){const r=new Ha;r.moveTo(e[0].x,e[0].y,t);for(let s=1;s<e.length;s++)r.lineTo(e[s].x,e[s].y);return r}currentLine(){const e=this.lines[this.lines.length-1];return Ve(e,"Start an SVGPathBuilder with `.moveTo()`"),Ve(!e.closed,"Cannot work on a closed line"),e}moveTo(e,t,r){return this.lines.push({initial:{type:"moveTo",x:e,y:t,opts:r},segments:[],closed:!1}),this}lineTo(e,t,r){return this.currentLine().segments.push({type:"lineTo",x:e,y:t,opts:r}),this}arcTo(e,t,r,s,o,i){return this.currentLine().segments.push({type:"arcTo",radius:e,largeArcFlag:t,sweepFlag:r,x:s,y:o,opts:i}),this}close(){return this.currentLine().closed=!0,this}toD(e={}){const t=e.closedOnly??!1,r=[];for(const{initial:s,segments:o,closed:i}of this.lines)if(!(t&&!i)){r.push("M",Q(s.x),Q(s.y));for(const a of o)switch(a.type){case"lineTo":r.push("L",Q(a.x),Q(a.y));break;case"arcTo":r.push("A",a.radius,a.radius,0,a.largeArcFlag?"1":"0",a.sweepFlag?"1":"0",Q(a.x),Q(a.y));break}i&&r.push("Z")}return r.join(" ")}toSvg(e){if(e.forceSolid)return this.toSolidSvg(e);switch(e.style){case"solid":return this.toSolidSvg(e);case"dashed":case"dotted":return this.toDashedSvg(e);case"draw":return this.toDrawSvg(e);default:xt(e,"style")}}toGeometry(){var t,r,s;const e=[];for(const{initial:o,segments:i,closed:a}of this.lines){if(((t=o.opts)==null?void 0:t.geometry)===!1)continue;const l=[new P(o.x,o.y)];for(const u of i)switch(u.type){case"lineTo":{l.push(new P(u.x,u.y));break}case"arcTo":{const h=Ly(l[l.length-1],u);if(h===null)break;if(h==="straight-line"){l.push(new P(u.x,u.y));break}const p=qxe(h.length);for(let m=0;m<p+1;m++){const S=m/p*h.sweepAngle,v=P.Rot(h.startVector,S).mul(h.radius).add(h.center);l.push(v)}break}default:xt(u,"type")}const c=a?new Pn({points:l,isFilled:!1,...(r=o.opts)==null?void 0:r.geometry}):new fc({points:l,...(s=o.opts)==null?void 0:s.geometry});e.push(c)}return e.length===0?null:e.length===1?e[0]:new ds({children:e})}toSolidSvg(e){const{strokeWidth:t,props:r}=e;return g.jsx("path",{strokeWidth:t,d:this.toD(),...r})}toDashedSvg(e){const{style:t,strokeWidth:r,snap:s,end:o,start:i,lengthRatio:a,props:{markerStart:l,markerEnd:c,...u}={}}=e,h=[];for(const{initial:p,segments:m,closed:S}of this.lines){let v=p;for(let y=0;y<m.length;y++){const w=m[y],C=y===0,T=y===m.length-1&&!S,E=this.segmentLength(v,w),{strokeDasharray:_,strokeDashoffset:A}=oi(E,r,{style:t,snap:s,lengthRatio:a,start:C?S?"none":i:"outset",end:T?S?"none":o:"outset"});switch(w.type){case"lineTo":h.push(g.jsx("line",{x1:Q(v.x),y1:Q(v.y),x2:Q(w.x),y2:Q(w.y),strokeDasharray:_,strokeDashoffset:A,markerStart:C?l:void 0,markerEnd:T?c:void 0},y));break;case"arcTo":h.push(g.jsx("path",{d:["M",Q(v.x),Q(v.y),"A",w.radius,w.radius,0,w.largeArcFlag?"1":"0",w.sweepFlag?"1":"0",Q(w.x),Q(w.y)].join(" "),strokeDasharray:_,strokeDashoffset:A,markerStart:C?l:void 0,markerEnd:T?c:void 0},y));break;default:xt(w,"type")}v=w}if(S&&v!==p){const y=P.Dist(v,p),{strokeDasharray:w,strokeDashoffset:C}=oi(y,r,{style:t,snap:s,lengthRatio:a,start:"outset",end:"none"});h.push(g.jsx("line",{x1:Q(v.x),y1:Q(v.y),x2:Q(p.x),y2:Q(p.y),strokeDasharray:w,strokeDashoffset:C,markerEnd:c},"last"))}}return g.jsx("g",{strokeWidth:r,...u,children:h})}toDrawSvg(e){var u,h,p,m,S;const{strokeWidth:t,randomSeed:r,offset:s=t/3,roundness:o=t*2,passes:i=2,props:a}=e,l=[],c=this.lines.map(({initial:v,segments:y,closed:w})=>{const C=[],T=w?y.length+1:y.length;for(let E=0;E<T;E++){let _=y[E-1],A=y[E],O=y[E+1];_||(_=v),A||(A=v,O=y[0]),O||(O=v);let D,F;switch(A.type){case"lineTo":case"moveTo":{D=P.Sub(_,A).norm();break}case"arcTo":{const U=Ly(_,A);if(U===null||U==="straight-line"){D=P.Sub(A,_).norm().per();break}D=P.Per(U.endVector).mul(Math.sign(U.sweepAngle));break}default:xt(A,"type")}switch(O.type){case"lineTo":case"moveTo":{F=P.Sub(O,A).norm();break}case"arcTo":{const U=Ly(A,O);if(U===null||U==="straight-line"){F=P.Sub(O,A).norm().per();break}F=P.Per(U.startVector).mul(Math.sign(U.sweepAngle));break}default:xt(O,"type")}C.push({tangentBefore:D,tangentAfter:F})}return C});for(let v=0;v<i;v++)for(let y=0;y<this.lines.length;y++){const{initial:w,segments:C,closed:T}=this.lines[y],E=Bo(r+v+y),_=((u=w.opts)==null?void 0:u.offset)??s,A={x:w.x+E()*_,y:w.y+E()*_},O=[];let D=P.Dist(A,C[0]);for(let U=0;U<C.length;U++){const V=C[U],Y=U===C.length-1?T?C[0]:null:C[U+1],j=Y?P.Dist(V,Y):1/0,N=Math.min(D,j)-(((h=V.opts)==null?void 0:h.roundness)??o),z=$t(((p=V.opts)==null?void 0:p.offset)??s,0,N/10),G={x:V.x+E()*z,y:V.y+E()*z};O.push(G),D=j}if(T){const U=((m=w.opts)==null?void 0:m.roundness)??o;O.push(A);const V=O[0],Y=Math.min(P.Dist(A,V)/2,U),j=P.Nudge(A,V,Y);l.push("M",Q(j.x),Q(j.y))}else l.push("M",Q(A.x),Q(A.y));const F=T?C.length+1:C.length;for(let U=0;U<F;U++){const V=U===C.length?w:C[U],Y=((S=V.opts)==null?void 0:S.roundness)??o,j=O[U],{tangentBefore:N,tangentAfter:z}=c[y][U],G=U===0?A:O[U-1],q=U===C.length-1&&!T?null:O[(U+1)%O.length];switch(V.type){case"lineTo":case"moveTo":{if(!q||Y===0){l.push("L",Q(j.x),Q(j.y));break}const $=rt(Y,0,$t(rh(Math.PI/2,Math.PI,Math.abs(P.AngleBetween(N,z))),0,1)),K=Math.min(P.Dist(G,j)/2,$),J=P.Mul(N,K).add(j),H=Math.min(P.Dist(q,j)/2,$),te=P.Mul(z,H).add(j);l.push("L",Q(J.x),Q(J.y),"Q",Q(j.x),Q(j.y),Q(te.x),Q(te.y));break}case"arcTo":l.push("A",V.radius,V.radius,0,V.largeArcFlag?"1":"0",V.sweepFlag?"1":"0",Q(j.x),Q(j.y));break;default:xt(V,"type")}}T&&l.push("Z")}return g.jsx("path",{strokeWidth:t,d:l.join(" "),...a})}segmentLength(e,t){switch(t.type){case"lineTo":return P.Dist(e,t);case"arcTo":{const r=Ly(e,t);return r===null?0:r==="straight-line"?P.Dist(e,t):r.length}default:xt(t,"type")}}}/*!
462
+ * Adapted from https://github.com/rveciana/svg-path-properties
463
+ * MIT License: https://github.com/rveciana/svg-path-properties/blob/master/LICENSE
464
+ * https://github.com/rveciana/svg-path-properties/blob/74d850d14998274f6eae279424bdc2194f156490/src/arc.ts#L121
465
+ */function Ly(n,{radius:e,largeArcFlag:t,sweepFlag:r,x:s,y:o}){if(e=Math.abs(e),n.x===s&&n.y===o)return null;if(e===0)return"straight-line";const i=(n.x-s)/2,a=(n.y-o)/2,l=Math.pow(i,2)/Math.pow(e,2)+Math.pow(a,2)/Math.pow(e,2);l>1&&(e=Math.sqrt(l)*e);const c=Math.pow(e,2)*Math.pow(e,2)-Math.pow(e,2)*Math.pow(a,2)-Math.pow(e,2)*Math.pow(i,2),u=Math.pow(e,2)*Math.pow(a,2)+Math.pow(e,2)*Math.pow(i,2);let h=c/u;h=h<0?0:h;const p=(t!==r?1:-1)*Math.sqrt(h),m={x:p*(e*a/e),y:p*(-(e*i)/e)},S={x:m.x+(n.x+s)/2,y:m.y+(n.y+o)/2},v={x:(i-m.x)/e,y:(a-m.y)/e},y={x:(-i-m.x)/e,y:(-a-m.y)/e};let w=P.AngleBetween(v,y);return!r&&w>0?w-=2*Math.PI:r&&w<0&&(w+=2*Math.PI),w%=2*Math.PI,{length:Math.abs(w*e),radius:e,sweepAngle:w,startVector:v,endVector:y,center:S}}const Yxe=We.forwardRef(function({isEditing:e,text:t,handleFocus:r,handleChange:s,handleKeyDown:o,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){const u=h=>{s({plaintext:h.target.value})};return g.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,disabled:!e,readOnly:!e,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:t,onFocus:r,onChange:u,onKeyDown:h=>o(h.nativeEvent),onBlur:i,onTouchEnd:Yt,onContextMenu:e?Yt:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:nt})});function Xxe(n,e,t,r){if((n==="start-legacy"||n==="end-legacy")&&t.length!==0){const s=ye.From(t[0].box);for(const{box:o}of t)s.union(o);if(n==="start-legacy")return(r-2*e-s.width)/2;if(n==="end-legacy")return-(r-2*e-s.width)/2}}function qH(n){return n==="start-legacy"||n==="middle-legacy"||n==="end-legacy"}function Zxe(n,e,t){const r=YH(n),s=r.isEditing,o=ne(),i=k.useRef(null),a=(t||"").trim().length===0;k.useEffect(()=>{function u(h){var p,m;h.shapeId===n&&((m=(p=i.current)==null?void 0:p.select)==null||m.call(p))}return o.on("select-all-text",u),()=>{o.off("select-all-text",u)}},[o,n,s]),k.useEffect(()=>{var u,h,p,m;s&&(document.activeElement!==i.current&&((u=i.current)==null||u.focus()),o.getInstanceState().isCoarsePointer&&((h=i.current)==null||h.select()),Tt.isSafari&&((p=i.current)==null||p.blur(),(m=i.current)==null||m.focus()))},[o,s]);const l=k.useCallback(u=>{if(o.getEditingShapeId()===n)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&o.complete();break}}},[o,n]),c=k.useCallback(({plaintext:u})=>{if(o.getEditingShapeId()!==n)return;const h=Jx.normalizeText(u||"");o.updateShape({id:n,type:e,props:{text:h}})},[o,n,e]);return{rInput:i,handleKeyDown:l,handleChange:c,isEmpty:a,...r}}function u2(n,e){return se("isReadyForEditing",()=>{const t=n.getEditingShapeId();return t!==null&&(t===e||n.getHoveredShapeId()===e)},[n,e])}function YH(n){const e=ne(),t=se("isEditing",()=>e.getEditingShapeId()===n,[e]),r=u2(e,n),s=k.useCallback(o=>{e.dispatch({...Js(o),type:"pointer",name:"pointer_down",target:"shape",shape:e.getShape(n)}),Yt(o)},[e,n]);return{handleFocus:Ap,handleBlur:Ap,handleInputPointerDown:s,handleDoubleClick:Yt,isEditing:t,isReadyForEditing:r}}const Jxe=We.memo(function({shapeId:e,type:t,text:r,labelColor:s,font:o,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:m,classNamePrefix:S,style:v,textWidth:y,textHeight:w}){const{rInput:C,isEmpty:T,isEditing:E,isReadyForEditing:_,...A}=Zxe(e,t,r),O=Jx.normalizeTextForDom(r||""),D=O.length>0,F=qH(l);if(!E&&!D)return null;const U=S||"tl-text";return g.jsx("div",{className:`${U}-label tl-text-wrapper tl-plain-text-wrapper`,"data-font":o,"data-align":l,"data-hastext":!T,"data-isediting":E,"data-is-ready-for-editing":_,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||F?"center":l,alignItems:c==="middle"?"center":c,padding:p,...v},children:g.jsxs("div",{className:`${U}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(y||0),color:s,width:y?Math.ceil(y):void 0,height:w?Math.ceil(w):void 0},children:[g.jsx("div",{className:`${U} tl-text tl-text-content`,dir:"auto",children:O.split(`
466
+ `).map((V,Y)=>g.jsx("div",{dir:"auto",children:V},Y))}),(_||h)&&g.jsx(Yxe,{ref:C,text:r,isEditing:E,shapeId:e,...A,handleKeyDown:m??A.handleKeyDown})]})})});function Ko(){return tl({isDarkMode:Ig()})}function d2(n){return{key:`${Wa.id}:${n}`,async getElement(){return n!=="pattern"?null:g.jsx(Qxe,{})}}}function Qxe(){const n=f2(),e=Ou(),t=Ko(),r=8/12;return g.jsxs(g.Fragment,{children:[g.jsxs("mask",{id:e,children:[g.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),g.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[g.jsx("line",{x1:r*1,y1:r*3,x2:r*3,y2:r*1}),g.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),g.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),g.jsx("pattern",{id:n(1,t.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:g.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:t.solid,mask:`url(#${e})`})})]})}function h2(){return{key:`${Wa.id}:pattern`,component:r0e}}const sp=8,n3=(n,e,t)=>new Promise((r,s)=>{const o=sp*e*n,i=document.createElement("canvas");i.width=o,i.height=o;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?NS.darkMode.solid:NS.lightMode.solid,a.fillRect(0,0,o,o),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*e*n;const l=8/12,c=u=>u*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(),i.toBlob(u=>{!u||sn.throwToBlob.get()?s():r(u)})}),r3=(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 HP=null;function e0e(){return HP||(HP={white:r3([1,1],n=>{n.fillStyle="#f8f9fa",n.fillRect(0,0,1,1)}),black:r3([1,1],n=>{n.fillStyle="#212529",n.fillRect(0,0,1,1)})}),HP}function XH(n){return Math.ceil(Math.log2(Math.max(1,n)))}function f2(){const n=hi("hash_pattern");return k.useCallback((e,t)=>{const r=XH(e);return JI(n,`${t}_${r}`)},[n])}function ZH(n){const e=[],r=XH(n);for(let s=0;s<=r;s++)e.push(Math.pow(2,s));return e}function t0e(n){const e=e0e();return ZH(n).flatMap(t=>[{zoom:t,url:e.white,theme:"light"},{zoom:t,url:e.black,theme:"dark"}])}function n0e(){const n=ne(),e=se("devicePixelRatio",()=>n.getInstanceState().devicePixelRatio,[n]),t=se("maxZoom",()=>Math.ceil(cr(n.getCameraOptions().zoomSteps)),[n]),[r,s]=k.useState(!1),[o,i]=k.useState(()=>t0e(t)),a=f2();return k.useEffect(()=>{const c=Promise.all(ZH(t).flatMap(h=>[n3(e,h,!1).then(p=>({zoom:h,theme:"light",url:URL.createObjectURL(p)})),n3(e,h,!0).then(p=>({zoom:h,theme:"dark",url:URL.createObjectURL(p)}))]));let u=!1;return c.then(h=>{u||(i(h),s(!0))}),()=>{u=!0,s(!1),c.then(h=>{for(const{url:p}of h)URL.revokeObjectURL(p)})}},[e,t]),{defs:g.jsx(g.Fragment,{children:o.map(c=>{const u=a(c.zoom,c.theme);return g.jsx("pattern",{id:u,width:sp,height:sp,patternUnits:"userSpaceOnUse",children:g.jsx("image",{href:c.url,width:sp,height:sp})},u)})}),isReady:r}}function r0e(){const n=ne(),e=k.useRef(null),{defs:t,isReady:r}=n0e();return k.useEffect(()=>{if(r&&Tt.isSafari){const s=JH(e.current);s&&n.timers.requestAnimationFrame(()=>{s.style.display="none",n.timers.requestAnimationFrame(()=>{s.style.display=""})})}},[n,r]),g.jsx("g",{ref:e,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function JH(n){return n.classList.contains("tl-html-layer")?n:n.parentElement?JH(n.parentElement):null}const Mr=We.memo(function({theme:e,d:t,color:r,fill:s,scale:o}){switch(s){case"none":return null;case"solid":return g.jsx("path",{fill:e[r].semi,d:t});case"semi":return g.jsx("path",{fill:e.solid,d:t});case"fill":return g.jsx("path",{fill:e[r].fill,d:t});case"pattern":return g.jsx(s0e,{theme:e,color:r,fill:s,d:t,scale:o})}});function s0e({d:n,color:e,theme:t}){const r=ne(),s=Cg(),o=se("zoomLevel",()=>r.getZoomLevel(),[r]),i=f2(),a=r.getZoomLevel()<=.18;return g.jsxs(g.Fragment,{children:[g.jsx("path",{fill:t[e].pattern,d:n}),g.jsx("path",{fill:s?`url(#${i(1,t.id)})`:a?t[e].semi:`url(#${i(o,t.id)})`,d:n})]})}function o0e(n){return n.replace(/\s/g," ")}function YE(n,e,t){const{padding:r=0}=t;if(e.length===0)return null;const s=ye.From(e[0].box);for(const{box:c}of e)s.union(c);const o=r+(t.offsetX??0),i=(t.offsetY??0)+t.fontSize/2+(t.verticalTextAlign==="start"?r:t.verticalTextAlign==="end"?t.height-r-s.height:(Math.ceil(t.height)-s.height)/2);let a=null;const l=[];for(const{text:c,box:u}of e)a!==null&&u.y>a&&l.push(g.jsx("tspan",{alignmentBaseline:"mathematical",x:o,y:u.y+i,children:`
467
+ `},l.length)),l.push(g.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+o,y:u.y+i,unicodeBidi:"plaintext",children:o0e(c)},l.length)),a=u.y;return g.jsx("text",{fontSize:t.fontSize,fontFamily:t.fontFamily,fontStyle:t.fontStyle,fontWeight:t.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,children:l})}function i0e({fontSize:n,font:e,align:t,verticalAlign:r,text:s,labelColor:o,bounds:i,padding:a=16,stroke:l=!0}){const c=ne(),u=Ko(),h={fontSize:n,fontFamily:g5[e],textAlign:t,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:mr.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:o,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(s,h),m=Xxe(t,a,p,i.width);m&&(h.offsetX=m),h.offsetX+=i.x,h.offsetY+=i.y;const S=YE(c,p,h);let v=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,v=YE(c,p,h)),g.jsxs(g.Fragment,{children:[v,S]})}function QH(n,e,t){switch(e.type){case"straight":return new Ha().moveTo(e.start.point.x,e.start.point.y,{offset:0,roundness:0}).lineTo(e.end.point.x,e.end.point.y,{offset:0,roundness:0}).toSvg(t);case"arc":return new Ha().moveTo(e.start.point.x,e.start.point.y,{offset:0,roundness:0}).arcTo(e.bodyArc.radius,!!e.bodyArc.largeArcFlag,!!e.bodyArc.sweepFlag,e.end.point.x,e.end.point.y,{offset:0,roundness:0}).toSvg(t);case"elbow":{const r=new Ha;r.moveTo(e.start.point.x,e.start.point.y,{offset:0});for(let s=1;s<e.route.points.length;s++){const o=e.route.points[s];e.route.skipPointsWhenDrawing.has(o)||r.lineTo(o.x,o.y,{offset:s===e.route.points.length-1?0:void 0})}return r.toSvg(t)}default:xt(e,"type")}}function a0e(n,e){switch(n.type){case"straight":return new Ha().moveTo(n.start.handle.x,n.start.handle.y).lineTo(n.end.handle.x,n.end.handle.y).toSvg(e);case"arc":return new Ha().moveTo(n.start.handle.x,n.start.handle.y).arcTo(n.handleArc.radius,!!n.handleArc.largeArcFlag,!!n.handleArc.sweepFlag,n.end.handle.x,n.end.handle.y).toSvg(e);case"elbow":{const t=fye(n.elbow,n.route);return Ha.throughPoints(t.points).toSvg(e)}default:xt(n,"type")}}const xh=p0("arrow body geometry",(n,e)=>{const t=_o(n,e);switch(t.type){case"straight":return new Ra({start:P.From(t.start.point),end:P.From(t.end.point)});case"arc":return new Ud({center:P.Cast(t.handleArc.center),start:P.Cast(t.start.point),end:P.Cast(t.end.point),sweepFlag:t.bodyArc.sweepFlag,largeArcFlag:t.bodyArc.largeArcFlag});case"elbow":return new fc({points:t.route.points});default:xt(t,"type")}}),l0e=p0("arrow label size",(n,e)=>{n.fonts.trackFontsForShape(e);let t=0,r=0;const s=xh.get(n,e.id),o=e.props.text||"i",i=s.bounds,a=XE(e),{w:l,h:c}=n.textMeasure.measureText(o,{...mr,fontFamily:Xa[e.props.font],fontSize:a,maxWidth:null});t=l,r=c;let u=!1;const h=_o(n,e),p=tK(e),m=h.type==="elbow"?Math.max(h.elbow.A.arrowheadOffset+p,32)+Math.max(h.elbow.B.arrowheadOffset+p,32):64;if(i.width>i.height?(t=Math.max(Math.min(l,m),Math.min(i.width-m,l)),u=!0):t>16*a&&(t=16*a,u=!0),u){const{w:S,h:v}=n.textMeasure.measureText(o,{...mr,fontFamily:Xa[e.props.font],fontSize:a,maxWidth:t});t=S,r=v}return new P(t,r).addScalar(SH*2*e.props.scale)},{areRecordsEqual:(n,e)=>n.props===e.props});function eK(n,e){return l0e.get(n,e.id)??new P(0,0)}function tK(n){const e=Dn[n.props.size];return(Cye+(e-Dn.s)*2+(e===Dn.xl?20:0))*n.props.scale}function c0e(n,e,t){const r=xh.get(n,e.id),s=[],o=[new ds({children:[r],debugColor:"lime"})],i=eK(n,e),a=tK(e),l=a/r.length;let c,u;if(t.type==="elbow")s.push(t.start.point,t.end.point),c=ye.FromCenter(t.start.point,i).expandBy(a),u=ye.FromCenter(t.end.point,i).expandBy(a);else{const w=r.interpolateAlongEdge(l),C=r.interpolateAlongEdge(1-l);s.push(w,C),c=ye.FromCenter(w,i),u=ye.FromCenter(C,i)}const h=r.intersectPolygon(c.corners),p=r.intersectPolygon(u.corners),m=s3(t.start.point,h),S=s3(t.end.point,p);let v=m?r.uninterpolateAlongEdge(m):.5,y=S?r.uninterpolateAlongEdge(S):.5;v>y&&(v=.5,y=.5);for(const w of[...h,...p,...s])o.push(new bT({x:w.x-3,y:w.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));return o.push(new Pn({points:c.corners,debugColor:"lime",isFilled:!1,ignore:!0}),new Pn({points:u.corners,debugColor:"lime",isFilled:!1,ignore:!0})),{start:v,end:y,dbg:o}}function lS(n,e){const t=[],r=_o(n,e),s={hasStartBinding:!!r.bindings.start,hasEndBinding:!!r.bindings.end,hasStartArrowhead:r.start.arrowhead!=="none",hasEndArrowhead:r.end.arrowhead!=="none"},o=c0e(n,e,r);o.dbg&&t.push(...o.dbg);const i=u0e(e,o,s),l=xh.get(n,e.id).interpolateAlongEdge(i),c=eK(n,e);return{box:ye.FromCenter(l,c),debugGeom:t}}function u0e(n,e,t){const{hasEndArrowhead:r,hasEndBinding:s,hasStartBinding:o,hasStartArrowhead:i}=t;return $t(n.props.labelPosition,i||o?e.start:0,r||s?e.end:1)}function s3(n,e){let t=null,r=-1/0;for(const s of e){const o=P.Dist2(n,s);o>r&&(t=s,r=o)}return t}function XE(n){return bye[n.props.size]*n.props.scale}function nK(n,e){const t=_o(n,e);switch(t.type){case"straight":case"arc":return .5;case"elbow":{const r=t.route.midpointHandle,s=xh.get(n,e.id);return r&&s?s.uninterpolateAlongEdge(r.point):.5}default:xt(t,"type")}}function d0e(n,e,t){const r=e==="end"?n.end.point:n.start.point;let s;switch(n.type){case"straight":{const o=e==="end"?n.start.point:n.end.point,i=P.Dist(o,r),a=$t(i/5,t,t*3);s=P.Nudge(r,o,a);break}case"arc":{const o=Math.abs(n.bodyArc.length),i=$t(o/5,t,t*3),a=IQ(r,i,n.handleArc.center,n.handleArc.radius);s=e==="end"?n.handleArc.sweepFlag?a[0]:a[1]:n.handleArc.sweepFlag?a[1]:a[0];break}case"elbow":{const o=e==="end"?n.route.points[n.route.points.length-2]:n.route.points[1],i=P.ManhattanDist(o,r),a=$t(i/2,t,t*3);s=o?P.Nudge(r,o,a):r;break}default:xt(n,"type")}return P.IsNaN(s)&&(s=r),{point:r,int:s}}function h0e({point:n,int:e}){const t=P.RotWith(e,n,bt/6),r=P.RotWith(e,n,-bt/6);return`M ${t.x} ${t.y} L ${n.x} ${n.y} L ${r.x} ${r.y}`}function f0e({point:n,int:e}){const t=P.RotWith(e,n,bt/6),r=P.RotWith(e,n,-bt/6);return`M ${t.x} ${t.y} L ${r.x} ${r.y} L ${n.x} ${n.y} Z`}function p0e({point:n,int:e}){const t=P.Sub(e,n).div(2),r=P.Add(n,P.Rot(t,qt)),s=P.Sub(n,P.Rot(t,qt));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${s.x} ${s.y} Z`}function g0e({point:n,int:e}){const t=P.Lrp(n,e,.45),r=P.Dist(t,n);return`M ${t.x-r},${t.y}
468
+ a ${r},${r} 0 1,0 ${r*2},0
469
+ a ${r},${r} 0 1,0 -${r*2},0 `}function m0e({point:n,int:e}){const t=P.Lrp(n,e,.75),r=P.RotWith(t,n,bt/4),s=P.RotWith(t,n,-bt/4),o=P.Lrp(r,s,.5);return o.add(P.Sub(o,n)),`M ${o.x} ${o.y} L ${s.x} ${s.y} ${n.x} ${n.y} L ${r.x} ${r.y} Z`}function y0e({int:n,point:e}){const t=P.Lrp(e,n,.85),r=P.Sub(t,e).div(2),s=P.Add(e,P.Rot(r,qt)),o=P.Sub(e,P.Rot(r,qt)),i=P.Add(t,P.Rot(r,qt)),a=P.Sub(t,P.Rot(r,qt));return`M ${s.x} ${s.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${o.x} ${o.y} Z`}function S0e({int:n,point:e}){const t=P.Sub(n,e).div(2),r=P.Add(e,P.Rot(t,qt)),s=P.Sub(e,P.Rot(t,qt));return`M ${r.x} ${r.y} L ${s.x} ${s.y}`}function Qx(n,e,t){const r=e==="end"?n.end.arrowhead:n.start.arrowhead;if(r==="none")return;const s=d0e(n,e,t);if(s){switch(r){case"bar":return S0e(s);case"square":return y0e(s);case"diamond":return m0e(s);case"dot":return g0e(s);case"inverted":return p0e(s);case"arrow":return h0e(s);case"triangle":return f0e(s)}return""}}function x0e({arrow:n}){var i,a;const e=ne(),t=se("elbow arrow grid",()=>{try{return gH(e,e.getShape(n.id),zn(e,n))}catch(l){console.error(l);return}},[e,n.id]);if(!t)return null;const r=ye.Common([t.A.original,t.B.original]).expandBy(50),s=((i=t.route)==null?void 0:i.name)??"",o=(a=t.route)==null?void 0:a.midpointHandle;return g.jsxs(g.Fragment,{children:[t.midX!==null&&g.jsx(tu,{a:{x:t.midX,y:r.minY},b:{x:t.midX,y:r.maxY},stroke:"red"}),t.midY!==null&&g.jsx(tu,{a:{x:r.minX,y:t.midY},b:{x:r.maxX,y:t.midY},stroke:"blue"}),(o==null?void 0:o.axis)==="x"&&t.midXRange&&g.jsx(tu,{a:{x:t.midXRange.lo,y:o.point.y},b:{x:t.midXRange.hi,y:o.point.y},stroke:"red",strokeDasharray:"0 2"}),(o==null?void 0:o.axis)==="y"&&t.midYRange&&g.jsx(tu,{a:{x:o.point.x,y:t.midYRange.lo},b:{x:o.point.x,y:t.midYRange.hi},stroke:"blue",strokeDasharray:"0 2"}),g.jsx(Rd,{box:t.A.original,stroke:"orange"}),g.jsx(Rd,{box:t.A.expanded,stroke:"orange",strokeWidth:.5}),g.jsx(Rd,{box:t.A.original.clone().expandBy(t.options.minElbowLegLength),stroke:"orange",strokeWidth:.5}),g.jsx(Rd,{box:t.B.original,stroke:"lightskyblue"}),g.jsx(Rd,{box:t.B.expanded,stroke:"lightskyblue",strokeWidth:.5}),g.jsx(Rd,{box:t.B.original.clone().expandBy(t.options.minElbowLegLength),stroke:"lightskyblue",strokeWidth:.5}),g.jsx(Ol,{edge:t.A.edges.top,axis:"x",stroke:"orange"}),g.jsx(Ol,{edge:t.B.edges.top,axis:"x",stroke:"lightskyblue"}),g.jsx(Ol,{edge:t.A.edges.right,axis:"y",stroke:"orange"}),g.jsx(Ol,{edge:t.B.edges.right,axis:"y",stroke:"lightskyblue"}),g.jsx(Ol,{edge:t.A.edges.bottom,axis:"x",stroke:"orange"}),g.jsx(Ol,{edge:t.B.edges.bottom,axis:"x",stroke:"lightskyblue"}),g.jsx(Ol,{edge:t.A.edges.left,axis:"y",stroke:"orange"}),g.jsx(Ol,{edge:t.B.edges.left,axis:"y",stroke:"lightskyblue"}),t.route&&g.jsx(v0e,{route:t.route.points,strokeWidth:10}),g.jsx("text",{x:r.minX+5,y:r.minY-3,fontSize:10,fill:"black",stroke:"var(--color-background)",strokeWidth:2,paintOrder:"stroke",children:s}),g.jsxs("text",{x:t.A.expanded.x,y:t.A.expanded.y,fontSize:10,fill:"black",stroke:"var(--color-background)",strokeWidth:2,paintOrder:"stroke",children:["A",t.route&&`, ${t.route.aEdgePicking}`,t.A.isPoint&&", point"]}),g.jsxs("text",{x:t.B.expanded.x,y:t.B.expanded.y,fontSize:10,fill:"black",stroke:"var(--color-background)",strokeWidth:2,paintOrder:"stroke",children:["B",t.route&&`, ${t.route.bEdgePicking}`,t.B.isPoint&&", point"]})]})}function tu({a:n,b:e,...t}){return g.jsx("line",{fill:"none",strokeWidth:1,strokeDasharray:"4,4",stroke:"green",x1:n.x,y1:n.y,x2:e.x,y2:e.y,...t})}function v0e({route:n,...e}){return g.jsx("polyline",{fill:"none",stroke:"darkorchid",strokeWidth:3,opacity:.5,points:n.map(t=>`${t.x},${t.y}`).join(" "),...e})}function Ol({edge:n,axis:e,...t}){if(!n||n.expanded===null)return null;const r=s=>e==="x"?{x:s.y,y:s.x}:s;return g.jsxs("g",{children:[g.jsx(tu,{a:r({x:n.expanded,y:n.cross.min}),b:r({x:n.expanded,y:n.cross.max}),strokeDasharray:"0",strokeWidth:1.5,...t}),g.jsx(tu,{a:r({x:n.expanded-4,y:n.cross.min}),b:r({x:n.expanded+4,y:n.cross.min}),strokeDasharray:"0",strokeWidth:1.5,...t}),g.jsx(tu,{a:r({x:n.expanded-4,y:n.cross.max}),b:r({x:n.expanded+4,y:n.cross.max}),strokeDasharray:"0",strokeWidth:1.5,...t})]})}function Rd({box:n,...e}){return g.jsx("rect",{x:n.minX,y:n.minY,width:n.width,height:n.height,strokeDasharray:"4,4",strokeWidth:1,fill:"none",...e})}const w0e=new zo;function b0e(n){return w0e.get(n,e=>{const t=le("current selected arrow shape",()=>{const s=e.getOnlySelectedShape();return!s||!e.isShapeOfType(s,"arrow")?null:s.id}),r=e.store.query.ids("shape",()=>{const s=t.get();return s?{type:{eq:"arrow"},id:{neq:s}}:{type:{eq:"arrow"}}});return le("elbow arrow snap lines",()=>{var a,l;const s=new Map,o=e.getCurrentPageShapeIds(),i=e.getViewportPageBounds();for(const c of r.get()){if(!o.has(c))continue;const u=e.getShape(c);if((u==null?void 0:u.type)!=="arrow")continue;const h=e.getShapePageBounds(c);if(!h||!i.includes(h))continue;const p=zn(e,u),S=e.getShapePageGeometry(c).getVertices({includeInternal:!1,includeLabels:!1});for(let v=1;v<S.length;v++){const y=S[v-1],w=S[v];let C=P.Angle(y,w);C<0&&(C+=Math.PI);let T=s.get(C);T||(T=new Set,s.set(C,T));const E=op(y,C);T.add({perpDistance:E,startBoundShapeId:(a=p.start)==null?void 0:a.toId,endBoundShapeId:(l=p.end)==null?void 0:l.toId})}}return s})}).get()}function op(n,e){const t=P.FromAngle(e).per();return P.Dpr(n,t)}class cS extends fi{constructor(){super(...arguments);R(this,"options",{expandElbowLegLength:{s:28,m:36,l:44,xl:66},minElbowLegLength:{s:Dn.s*3,m:Dn.m*3,l:Dn.l*3,xl:Dn.xl*3},minElbowHandleDistance:16,arcArrowCenterSnapDistance:16,elbowArrowCenterSnapDistance:24,elbowArrowEdgeSnapDistance:20,elbowArrowPointSnapDistance:24,elbowArrowAxisSnapDistance:16,labelCenterSnapDistance:10,elbowMidpointSnapDistance:10,elbowMinSegmentLengthToShowMidpointHandle:20,hoverPreciseTimeout:600,pointingPreciseTimeout:320});R(this,"_resizeInitialBindings",new zo)}canEdit(){return!0}canBind({toShapeType:t}){return t!=="arrow"}canSnap(){return!1}canTabTo(t){const r=zn(this.editor,t);return!!(r.start||r.end||t.props.text)}hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsBg(){return!0}hideSelectionBoundsFg(){return!0}canBeLaidOut(t,r){if(r.type==="flip"){const s=zn(this.editor,t),{start:o,end:i}=s,{shapes:a=[]}=r;if(o&&!a.find(l=>l.id===o.toId)||i&&!a.find(l=>l.id===i.toId))return!1}return!0}getFontFaces(t){return t.props.text?[a2[`tldraw_${t.props.font}`].normal.normal]:jr}getDefaultProps(){return{kind:"arc",elbowMidPoint:.5,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=this.editor.getEditingShapeId()===t.id,s=_o(this.editor,t),o=[],i=s.type==="straight"?new Ra({start:P.From(s.start.point),end:P.From(s.end.point)}):s.type==="arc"?new Ud({center:P.Cast(s.handleArc.center),start:P.Cast(s.start.point),end:P.Cast(s.end.point),sweepFlag:s.bodyArc.sweepFlag,largeArcFlag:s.bodyArc.largeArcFlag}):new fc({points:s.route.points});let a;if(r||t.props.text.trim()){const l=lS(this.editor,t);sn.debugGeometry.get()&&o.push(...l.debugGeom),a=new Zi({x:l.box.x,y:l.box.y,width:l.box.w,height:l.box.h,isFilled:!0,isLabel:!0})}return new ds({children:[...a?[i,a]:[i],...o]})}getHandles(t){const r=_o(this.editor,t),s=[{id:"start",type:"vertex",index:"a1",x:r.start.handle.x,y:r.start.handle.y},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y}];if(t.props.kind==="arc"&&(r.type==="straight"||r.type==="arc")&&s.push({id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y}),t.props.kind==="elbow"&&r.type==="elbow"&&r.route.midpointHandle){const o=this.editor.getShapePageTransform(t.id),i=o.applyToPoint(r.route.midpointHandle.segmentStart),a=o.applyToPoint(r.route.midpointHandle.segmentEnd);P.Dist(i,a)*this.editor.getZoomLevel()>this.options.elbowMinSegmentLengthToShowMidpointHandle&&s.push({id:"middle",type:"vertex",index:"a2",x:r.route.midpointHandle.point.x,y:r.route.midpointHandle.point.y})}return s}getText(t){return t.props.text}onHandleDrag(t,r){const s=r.handle.id;switch(s){case"middle":switch(t.props.kind){case"arc":return this.onArcMidpointHandleDrag(t,r);case"elbow":return this.onElbowMidpointHandleDrag(t,r);default:xt(t.props.kind)}case"start":case"end":return this.onTerminalHandleDrag(t,r,s);default:xt(s)}}onArcMidpointHandleDrag(t,{handle:r}){const s=zn(this.editor,t),{start:o,end:i}=Wd(this.editor,t,s),a=P.Sub(i,o),l=P.Per(a),c=P.Med(i,o),u=P.Sub(c,l),h=P.Add(c,l),p=P.NearestPointOnLineSegment(u,h,r,!1);let m=P.Dist(p,c);return P.Clockwise(p,i,c)&&(m*=-1),{id:t.id,type:t.type,props:{bend:m}}}onElbowMidpointHandleDrag(t,{handle:r}){var T,E,_,A,O;const s=_o(this.editor,t);if((s==null?void 0:s.type)!=="elbow")return;const o=this.editor.getShapePageTransform(t.id),i=o.applyToPoint(r),a=(T=s.route.midpointHandle)==null?void 0:T.axis;if(!a)return;const l=tg[a],c=s.elbow[l.midRange];if(!c)return;let u=P.Angle(o.applyToPoint(l.v(0,0)),o.applyToPoint(l.v(0,1)));u<0&&(u+=Math.PI);const h=op(i,u),p=op(o.applyToPoint(l.v(c.lo,0)),u),m=op(o.applyToPoint(l.v(c.hi,0)),u),S=this.options.elbowMidpointSnapDistance/this.editor.getZoomLevel(),v=op(o.applyToPoint(l.v(rt(c.lo,c.hi,.5),0)),u);let y=v,w=Math.abs(v-h);for(const[D,F]of b0e(this.editor)){const{isParallel:U,isFlippedParallel:V}=k0e(u,D);if(U||V)for(const Y of F){const j=Y.startBoundShapeId&&(Y.startBoundShapeId===((E=s.bindings.start)==null?void 0:E.toId)||Y.startBoundShapeId===((_=s.bindings.end)==null?void 0:_.toId)),N=Y.endBoundShapeId&&(Y.endBoundShapeId===((A=s.bindings.start)==null?void 0:A.toId)||Y.endBoundShapeId===((O=s.bindings.end)==null?void 0:O.toId));if(!j&&!N)continue;const z=V?-Y.perpDistance:Y.perpDistance,G=Math.abs(z-h);G<w&&(y=z,w=G)}}w>S&&(y=h);const C=$t(rh(p,m,y),0,1);return{id:t.id,type:t.type,props:{elbowMidPoint:C}}}onTerminalHandleDrag(t,{handle:r,isPrecise:s},o){const i=zn(this.editor,t),a={id:t.id,type:"arrow",props:{}},l=i[o],u=i[o==="start"?"end":"start"],h=Cv({editor:this.editor,pointInPageSpace:this.editor.getShapePageTransform(t.id).applyToPoint(r),arrow:t,isPrecise:s,isExact:this.editor.inputs.altKey,currentBinding:l,oppositeBinding:u});if(!h){ep(this.editor,t,o);const S=lo(new P(r.x,r.y),this.editor);return a.props[o]={x:S.x,y:S.y},a}const p={terminal:o,normalizedAnchor:h.normalizedAnchor,isPrecise:h.isPrecise,isExact:this.editor.inputs.altKey,snap:h.snap};Df(this.editor,t,h.target.id,p);const m=zn(this.editor,t);return m.start&&m.end&&m.start.toId===m.end.toId&&P.Equals(m.start.props.normalizedAnchor,m.end.props.normalizedAnchor)&&Df(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=zn(this.editor,t);if(t.props.kind==="elbow"&&this.editor.getOnlySelectedShapeId()===t.id){const a=_o(this.editor,t);if(!a)return;const l={id:t.id,type:"arrow",props:{}};return r.start&&(l.props.start={x:a.start.point.x,y:a.start.point.y},ep(this.editor,t,"start")),r.end&&(l.props.end={x:a.end.point.x,y:a.end.point.y},ep(this.editor,t,"end")),l}const s=Wd(this.editor,t,r),o=this.editor.getShapePageTransform(t.id),i=this.editor.getSelectedShapeIds();if(!(r.start&&(i.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(i.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){i3.set(t,{pagePosition:o.applyToPoint(t),terminalBindings:cc(s,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:o.applyToPoint(l)}:null})}),r.start&&(bx({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&bx({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=i3.get(t);if(!s)return;const o=this.editor.getShapePageTransform(r.id),i=P.Sub(o.applyToPoint(r),s.pagePosition);for(const a of Object.values(s.terminalBindings)){if(!a)continue;const l=P.Add(a.pagePosition,P.Mul(i,.5)),c=this.editor.getShapeAtPoint(l,{hitInside:!0,hitFrameInside:!0,margin:0,filter:u=>!u.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:u,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const u=ye.ZeroFix(this.editor.getShapeGeometry(c).bounds),h=this.editor.getPointInShapeSpace(c,l),p={x:(h.x-u.minX)/u.width,y:(h.y-u.minY)/u.height};Df(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else ep(this.editor,r,a.binding.props.terminal)}}onResize(t,r){const{scaleX:s,scaleY:o}=r,i=this._resizeInitialBindings.get(t,()=>zn(this.editor,t)),a=Wd(this.editor,t,i),{start:l,end:c}=en(t.props);let{bend:u}=t.props;i.start||(l.x=a.start.x*s,l.y=a.start.y*o),i.end||(c.x=a.end.x*s,c.y=a.end.y*o);const h=Math.abs(s),p=Math.abs(o),m=i!=null&&i.start?P.From(i.start.props.normalizedAnchor):null,S=i!=null&&i.end?P.From(i.end.props.normalizedAnchor):null;return s<0&&o>=0?(u!==0&&(u*=-1,u*=Math.max(h,p)),m&&(m.x=1-m.x),S&&(S.x=1-S.x)):s>=0&&o<0?(u!==0&&(u*=-1,u*=Math.max(h,p)),m&&(m.y=1-m.y),S&&(S.y=1-S.y)):s>=0&&o>=0?u!==0&&(u*=Math.max(h,p)):s<0&&o<0&&(u!==0&&(u*=Math.max(h,p)),m&&(m.x=1-m.x,m.y=1-m.y),S&&(S.x=1-S.x,S.y=1-S.y)),i.start&&m&&Df(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:m.toJson()}),i.end&&S&&Df(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:S.toJson()}),{props:{start:l,end:c,bend:u}}}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=Ko(),s=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),i=_o(this.editor,t);if(!(i!=null&&i.isValid))return null;const a=lS(this.editor,t),l=t.id===this.editor.getOnlySelectedShapeId(),u=this.editor.getEditingShapeId()===t.id||t.props.text;return g.jsxs(g.Fragment,{children:[g.jsxs(rc,{style:{minWidth:50,minHeight:50},children:[g.jsx(o3,{shape:t,shouldDisplayHandles:o&&(s==null?void 0:s.id)===t.id}),t.props.kind==="elbow"&&sn.debugElbowArrows.get()&&g.jsx(x0e,{arrow:t})]}),u&&g.jsx(Jxe,{shapeId:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:XE(t),lineHeight:mr.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w-SH*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=Tg(t.id),s=hi(t.id+"_clip"),o=_o(this.editor,t);if(!o)return null;const{start:i,end:a}=Wd(this.editor,t,o==null?void 0:o.bindings),l=this.editor.getShapeGeometry(t),c=l.bounds,u=r||t.props.text.trim()?l.children[1]:null;if(P.Equals(i,a))return null;const h=Dn[t.props.size]*t.props.scale,p=o.start.arrowhead&&Qx(o,"start",h),m=o.end.arrowhead&&Qx(o,"end",h),S=p&&o.start.arrowhead!=="arrow"||m&&o.end.arrowhead!=="arrow"||!!u;if(r&&u)return g.jsx("rect",{x:Q(u.x),y:Q(u.y),width:u.w,height:u.h,rx:3.5*t.props.scale,ry:3.5*t.props.scale});const v=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),y=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return g.jsxs("g",{children:[S&&g.jsx("defs",{children:g.jsx(rK,{radius:3.5*t.props.scale,hasText:t.props.text.trim().length>0,bounds:c,labelBounds:u?u.getBounds():new ye(0,0,0,0),as:v&&p?p:"",ae:y&&m?m:""})}),g.jsxs("g",{style:{clipPath:S?`url(#${s})`:void 0,WebkitClipPath:S?`url(#${s})`:void 0},children:[S&&g.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),QH(t,o,t.props.dash==="draw"?{style:"draw",randomSeed:t.id,strokeWidth:1,passes:1,offset:0,roundness:h*2,props:{strokeWidth:void 0}}:{style:"solid",strokeWidth:1,props:{strokeWidth:void 0}})]}),p&&g.jsx("path",{d:p}),m&&g.jsx("path",{d:m}),u&&g.jsx("rect",{x:Q(u.x),y:Q(u.y),width:u.w,height:u.h,rx:3.5,ry:3.5})]})}onEditStart(t){if(t.props.text.trim()===""){const r=nK(this.editor,t);this.editor.updateShape({id:t.id,type:t.type,props:{labelPosition:r}})}}onEditEnd(t){const{id:r,type:s,props:{text:o}}=t;o.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])}toSvg(t,r){r.addExportDef(d2(t.props.fill));const s=tl(r),o=1/t.props.scale;return g.jsxs("g",{transform:`scale(${o})`,children:[g.jsx(o3,{shape:t,shouldDisplayHandles:!1}),g.jsx(i0e,{fontSize:XE(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:s[t.props.labelColor].solid,bounds:lS(this.editor,t).box.clone().expandBy(-4.25*t.props.scale),padding:0})]})}getCanvasSvgDefs(){return[h2(),{key:"arrow:dot",component:C0e},{key:"arrow:cross",component:P0e}]}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:rt(t.props.scale,r.props.scale,s),start:{x:rt(t.props.start.x,r.props.start.x,s),y:rt(t.props.start.y,r.props.start.y,s)},end:{x:rt(t.props.end.x,r.props.end.x,s),y:rt(t.props.end.y,r.props.end.y,s)},bend:rt(t.props.bend,r.props.bend,s),labelPosition:rt(t.props.labelPosition,r.props.labelPosition,s)}}}R(cS,"type","arrow"),R(cS,"props",y5),R(cS,"migrations",S5);const o3=tr(function({shape:e,shouldDisplayHandles:t}){const r=ne(),s=Ko(),o=_o(r,e),i=se("force solid",()=>r.getZoomLevel()<.2,[r]),a=hi(e.id+"_clip"),l=hi("arrowhead-dot"),c=hi("arrowhead-cross"),u=Tg(e.id),h=r.getShapeGeometry(e);if(!h)return null;const p=ye.ZeroFix(h.bounds),m=zn(r,e);if(!(o!=null&&o.isValid))return null;const S=Dn[e.props.size]*e.props.scale,v=o.start.arrowhead&&Qx(o,"start",S),y=o.end.arrowhead&&Qx(o,"end",S);let w=null;t&&(m.start||m.end)&&(w=a0e(o,{style:"dashed",start:"skip",end:"skip",lengthRatio:2.5,strokeWidth:2/r.getZoomLevel(),props:{className:"tl-arrow-hint",markerStart:m.start?m.start.props.isExact?"":m.start.props.isPrecise?`url(#${c})`:`url(#${l})`:"",markerEnd:m.end?m.end.props.isExact?"":m.end.props.isPrecise?`url(#${c})`:`url(#${l})`:"",opacity:.16}}));const C=lS(r,e),T=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),E=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return g.jsxs(g.Fragment,{children:[g.jsx("defs",{children:g.jsx("clipPath",{id:a,children:g.jsx(rK,{radius:3.5*e.props.scale,hasText:u||e.props.text.trim().length>0,bounds:p,labelBounds:C.box,as:T&&v?v:"",ae:E&&y?y:""})})}),g.jsxs("g",{fill:"none",stroke:s[e.props.color].solid,strokeWidth:S,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[w,g.jsxs("g",{style:{clipPath:`url(#${a})`,WebkitClipPath:`url(#${a})`},children:[g.jsx("rect",{x:Q(p.minX-100),y:Q(p.minY-100),width:Q(p.width+200),height:Q(p.height+200),opacity:0}),QH(e,o,{style:e.props.dash,strokeWidth:S,forceSolid:i,randomSeed:e.id})]}),v&&T&&e.props.fill!=="none"&&g.jsx(Mr,{theme:s,d:v,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),y&&E&&e.props.fill!=="none"&&g.jsx(Mr,{theme:s,d:y,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),v&&g.jsx("path",{d:v}),y&&g.jsx("path",{d:y})]})]})});function rK({radius:n,hasText:e,bounds:t,labelBounds:r,as:s,ae:o}){const i=k.useMemo(()=>{const a=new Ha;return a.moveTo(t.left-100,t.top-100).lineTo(t.right+100,t.top-100).lineTo(t.right+100,t.bottom+100).lineTo(t.left-100,t.bottom+100).close(),e&&a.moveTo(r.left,r.top+n).lineTo(r.left,r.bottom-n).arcTo(n,!1,!1,r.left+n,r.bottom).lineTo(r.right-n,r.bottom).arcTo(n,!1,!1,r.right,r.bottom-n).lineTo(r.right,r.top+n).arcTo(n,!1,!1,r.right-n,r.top).lineTo(r.left+n,r.top).arcTo(n,!1,!1,r.left,r.top+n).close(),a.toD()},[n,e,t.bottom,t.left,t.right,t.top,r.bottom,r.left,r.right,r.top]);return g.jsx("path",{d:`${i}${s}${o}`})}const i3=new WeakMap;function C0e(){const n=hi("arrowhead-dot");return g.jsx("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:g.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function P0e(){const n=hi("arrowhead-cross");return g.jsxs("marker",{id:n,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[g.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),g.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}function k0e(n,e,t=1e-4){const r=Math.abs(n-e),s=r<t,o=Math.abs(r-Math.PI)<t,i=Math.abs(r-Dt)<t;return{isParallel:s||i,isFlippedParallel:o}}const a3="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 vh({url:n}){const e=ne(),t=se("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return g.jsx("a",{className:$e("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t}),href:n,target:"_blank",rel:"noopener noreferrer",onPointerDown:Yt,onPointerUp:Yt,title:n,draggable:!1,children:g.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${a3}") center 100% / 100% no-repeat`,WebkitMask:`url("${a3}") center 100% / 100% no-repeat`}})})}const l3="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",E0e=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function e0(n){return E0e.map(t=>{const{offsetX:r,offsetY:s,blur:o,spread:i,color:a}=t,l=new P(r,s),{x:c,y:u}=l.rot(-n);return`${c}px ${u}px ${o}px ${i}px ${a}`}).join(", ")}const I0e=300,sK=320,T0e=46,_0e=101;class uS extends Rh{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getAriaDescriptor(e){const t=e.props.assetId?this.editor.getAsset(e.props.assetId):null;if(t!=null&&t.props.title)return NH(t.props.title)+(t.props.description?", "+t.props.description:"")}getDefaultProps(){return{url:"",w:I0e,h:sK,assetId:null}}component(e){return g.jsx(M0e,{shape:e,util:this})}indicator(e){return g.jsx("rect",{width:Q(e.props.w),height:Q(e.props.h),rx:"6",ry:"6"})}onBeforeCreate(e){return c3(this.editor,e)}onBeforeUpdate(e,t){if(e.props.url!==t.props.url)if(ao.isValid(t.props.url))O0e(this.editor,t);else return{...t,props:{...t.props,url:e.props.url}};if(e.props.assetId!==t.props.assetId)return c3(this.editor,t)}getInterpolatedProps(e,t,r){return{...r>.5?t.props:e.props,w:rt(e.props.w,t.props.w,r),h:rt(e.props.h,t.props.h,r)}}}R(uS,"type","bookmark"),R(uS,"props",P5),R(uS,"migrations",k5);function M0e({shape:n,util:e}){const t=n.props.assetId?e.editor.getAsset(n.props.assetId):null,r=!!Cg()&&Tt.isSafari,s=e.editor.getShapePageTransform(n).rotation(),o=A0e(n),[i,a]=k.useState(!0),l=()=>a(!1);return g.jsx(Xl,{children:g.jsxs("div",{className:$e("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:e0(s),maxHeight:n.props.h},children:[(!t||t.props.image)&&g.jsxs("div",{className:"tl-bookmark__image_container",children:[t?g.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:t==null?void 0:t.props.image,alt:(t==null?void 0:t.props.title)||""}):g.jsx("div",{className:"tl-bookmark__placeholder"}),(t==null?void 0:t.props.image)&&g.jsx(vh,{url:n.props.url})]}),g.jsxs("div",{className:"tl-bookmark__copy_container",children:[t!=null&&t.props.title?g.jsx("h2",{className:"tl-bookmark__heading",children:NH(t.props.title)}):null,t!=null&&t.props.description&&(t!=null&&t.props.image)?g.jsx("p",{className:"tl-bookmark__description",children:t.props.description}):null,g.jsxs("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Yt,onPointerUp:Yt,onClick:Yt,children:[i&&(t!=null&&t.props.favicon)?g.jsx("img",{className:"tl-bookmark__favicon",src:t==null?void 0:t.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:l,alt:`favicon of ${o}`}):g.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${l3}") center 100% / 100% no-repeat`,WebkitMask:`url("${l3}") center 100% / 100% no-repeat`}}),g.jsx("span",{children:o})]})]})]})})}function c3(n,e){const t=e.props.assetId?n.getAsset(e.props.assetId):null;let r=sK;return t&&(t.props.image||(t.props.title?r=_0e:r=T0e)),{...e,props:{...e.props,h:r}}}const A0e=n=>{try{return new URL(n.props.url).hostname.replace(/^www\./,"")}catch{return n.props.url}};function O0e(n,e){const{url:t}=e.props,r=nc.createId(dI(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}}]),R0e(n,e))}const R0e=r0(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 Pu(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${kt(r)}L${kt(s)}`;let o="";for(let i=2,a=t-1;i<a;i++)r=n[i].point,s=n[i+1].point,o+=_s(r,s);return e?`M${_s(n[0].point,n[1].point)}Q${kt(n[1].point)}${_s(n[1].point,n[2].point)}T${o}${_s(n[t-1].point,n[0].point)}${_s(n[0].point,n[1].point)}Z`:`M${kt(n[0].point)}Q${kt(n[1].point)}${_s(n[1].point,n[2].point)}${n.length>3?"T":""}${o}L${kt(n[t-1].point)}`}function D0e(n,e={}){const{start:t={},end:r={}}=e,{cap:s=!0}=t,{cap:o=!0}=r;Ve(!t.taper&&!r.taper,"cap taper not supported here"),Ve(!t.easing&&!r.easing,"cap easing not supported here"),Ve(s&&o,"cap must be true");const i=na(n,e);Pv(i,e);const a=j0e(i);let l="";for(const c of a)l+=N0e(c,e);return l}function j0e(n){if(n.length<=2)return[n];const e=[];let t=[n[0]],r=P.Sub(n[1].point,n[0].point).uni(),s,o,i,a,l;for(let c=1,u=n.length;c<u-1;c++){if(i=n[c-1],a=n[c],l=n[c+1],s=P.Sub(l.point,a.point).uni(),o=P.Dpr(r,s),r=s,o<-.8){const h={...a,point:a.input};t.push(h),e.push(KP(t)),t=[h];continue}if(t.push(a),!(o>.7)&&(P.Dist2(i.point,a.point)+P.Dist2(a.point,l.point))/((i.radius+a.radius+l.radius)/3)**2<1.5){t.push(a),e.push(KP(t)),t=[a];continue}}return t.push(n[n.length-1]),e.push(KP(t)),e}function KP(n){const e=n[0];let t;for(;n.length>2&&(t=n[1],P.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],P.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:P.Sub(n[0].point,n[1].point).uni()},n[n.length-1]={...n[n.length-1],vector:P.Sub(n[n.length-2].point,n[n.length-1].point).uni()}),n}function L0e(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 N0e(n,e={}){if(n.length===0)return"";if(n.length===1)return L0e(n[0].point.x,n[0].point.y,n[0].radius);const{left:t,right:r}=pH(n,e);r.reverse();let s=`M${kt(t[0])}T`;for(let o=1;o<t.length;o++)s+=_s(t[o-1],t[o]);{const o=n[n.length-1],i=o.radius,a=o.vector.clone().per().neg(),l=P.Add(o.point,P.Mul(a,i)),c=P.Add(o.point,P.Mul(a,-i));s+=`${kt(l)}A${Q(i)},${Q(i)} 0 0 1 ${kt(c)}T`}for(let o=1;o<r.length;o++)s+=_s(r[o-1],r[o]);{const o=n[0],i=o.radius,a=o.vector.clone().per(),l=P.Add(o.point,P.Mul(a,i)),c=P.Add(o.point,P.Mul(a,-i));s+=`${kt(l)}A${Q(i)},${Q(i)} 0 0 1 ${kt(c)}Z`}return s}const oK=(n,e,t)=>{const r=[],s=[];n.forEach(c=>r.push(...c.points)),e.forEach(c=>s.push(...c.points));const o=Math.max(r.length,s.length),i=[],a=[];for(let c=0;c<o;c++)i.push(r[c]||r[r.length-1]),a.push(s[c]||s[s.length-1]);return[{type:"free",points:i.map((c,u)=>{let h=.5;return a[u].z!==void 0&&c.z!==void 0&&(h=rt(c.z,a[u].z,t)),{x:rt(c.x,a[u].x,t),y:rt(c.y,a[u].y,t),z:h}})}]},F0e=n=>n*.65+tJ(n*bt/2)*.35,z0e=n=>({size:n,thinning:.5,streamline:sh(n,[9,16],[.64,.74],!0),smoothing:.62,easing:qn.easeOutSine,simulatePressure:!0}),B0e=n=>({size:1+n*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:F0e}),u3=n=>({size:n,thinning:0,streamline:sh(n,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:qn.linear}),$0e=n=>({size:n,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:qn.linear});function p2({strokeWidth:n,showAsComplete:e}){return{size:1+n,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:qn.easeOutSine,last:e}}function ZE(n,e,t,r){const s=n.isComplete||t;return r?n.isPen?{...$0e(e),last:s}:{...u3(e),last:s}:n.dash==="draw"?n.isPen?{...B0e(e),last:s}:{...z0e(e),last:s}:{...u3(e),last:s}}function wh(n){const e=[];for(const t of n)if(t.type==="free"||t.points.length<2)e.push(...t.points.map(P.Cast));else{const r=Math.max(4,Math.floor(P.Dist(t.points[0],t.points[1])/16));e.push(...P.PointsBetween(t.points[0],t.points[1],r))}return e}function U0e(n,e,t){return{draw:"none",solid:"none",dotted:`${t} ${e*2}`,dashed:`${e*2} ${e*2}`}[n.props.dash]}class dS extends fi{constructor(){super(...arguments);R(this,"options",{maxPointsPerShape:600})}canTabTo(){return!1}hideResizeHandles(t){return WP(t)}hideRotateHandle(t){return WP(t)}hideSelectionBoundsFg(t){return WP(t)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(t){const r=wh(t.props.segments),s=(Dn[t.props.size]+1)*t.props.scale;if(t.props.segments.length===1){const i=ye.FromPoints(r);if(i.width<s*2&&i.height<s*2)return new bT({x:-s,y:-s,radius:s,isFilled:!0})}const o=na(r,ZE(t.props,s,t.props.isPen,!0)).map(i=>i.point);return t.props.isClosed?new Pn({points:o,isFilled:t.props.fill!=="none"}):new fc({points:o})}component(t){return g.jsx(rc,{children:g.jsx(d3,{shape:t})})}indicator(t){var u;const r=wh(t.props.segments);let s=(Dn[t.props.size]+1)*t.props.scale;!se("force solid",()=>{const h=this.editor.getZoomLevel();return h<.5&&h<1.5/s},[this.editor,s])&&!t.props.isPen&&t.props.dash==="draw"&&r.length===1&&(s+=Bo(t.id)()*(s/6));const i=t.props.isComplete||((u=cr(t.props.segments))==null?void 0:u.type)==="straight",a=ZE(t.props,s,i,!0),l=na(r,a),c=l.length>1?Pu(l,t.props.isClosed):iK(r[0],s);return g.jsx("path",{d:c})}toSvg(t,r){r.addExportDef(d2(t.props.fill));const s=1/t.props.scale;return g.jsx("g",{transform:`scale(${s})`,children:g.jsx(d3,{shape:t,zoomOverride:1})})}getCanvasSvgDefs(){return[h2()]}onResize(t,r){const{scaleX:s,scaleY:o}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:Aa(s*l),y:Aa(o*c),z:u}))});return{props:{segments:i}}}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return Dn[t.props.size]*r/2*t.props.scale}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,segments:oK(t.props.segments,r.props.segments,s),scale:rt(t.props.scale,r.props.scale,s)}}}R(dS,"type","draw"),R(dS,"props",I5),R(dS,"migrations",T5);function iK(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 WP(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function d3({shape:n,zoomOverride:e}){var m;const t=Ko(),r=ne(),s=wh(n.props.segments),o=n.props.isComplete||((m=cr(n.props.segments))==null?void 0:m.type)==="straight";let i=(Dn[n.props.size]+1)*n.props.scale;const a=se("force solid",()=>{const S=e??r.getZoomLevel();return S<.5&&S<1.5/i},[r,i,e]),l=se("dot adjustment",()=>(e??r.getZoomLevel())<.2?0:.1,[r,e]);!a&&!n.props.isPen&&n.props.dash==="draw"&&s.length===1&&(i+=Bo(n.id)()*(i/6));const c=ZE(n.props,i,o,a);if(!a&&n.props.dash==="draw")return g.jsxs(g.Fragment,{children:[n.props.isClosed&&n.props.fill&&s.length>1?g.jsx(Mr,{d:Pu(na(s,c),n.props.isClosed),theme:t,color:n.props.color,fill:n.props.isClosed?n.props.fill:"none",scale:n.props.scale}):null,g.jsx("path",{d:D0e(s,c),strokeLinecap:"round",fill:t[n.props.color].solid})]});const u=na(s,c),h=u.length<2,p=h?iK(s[0],0):Pu(u,n.props.isClosed);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{d:p,theme:t,color:n.props.color,fill:h||n.props.isClosed?n.props.fill:"none",scale:n.props.scale}),g.jsx("path",{d:p,strokeLinecap:"round",fill:h?t[n.props.color].solid:"none",stroke:t[n.props.color].solid,strokeWidth:i,strokeDasharray:h?"none":U0e(n,i,l),strokeDashoffset:"0"})]})}function H0e(n){if(typeof n!="string")throw new TypeError("Expected a string");return n.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function K0e(n,e){const t=Qe(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(aK(s.hostnames,r)){const o=s.fromEmbedUrl(e);if(o)return{definition:s,url:o,embedUrl:e}}}const W0e=n=>n.split("*").map(e=>H0e(e)).join(".+"),aK=(n,e)=>!!n.find(t=>{const r=new RegExp(W0e(t));return e.match(r)});function V0e(n,e){const t=Qe(e);if(!t)return;const r=t.host.replace("www.","");for(const s of n)if(aK(s.hostnames,r)){const o=s.toEmbedUrl(e);if(o)return{definition:s,embedUrl:o,url:e}}}function G0e(n,e){try{return V0e(n,e)??K0e(n,e)}catch{return}}const q0e=n=>Object.entries(n).filter(([e,t])=>t).map(([e])=>e).join(" "),Ma=class Ma extends Rh{static setEmbedDefinitions(e){Ma.embedDefinitions=e}getEmbedDefinitions(){return Ma.embedDefinitions}getEmbedDefinition(e){return G0e(Ma.embedDefinitions,e)}getText(e){return e.props.url}getAriaDescriptor(e){const t=this.getEmbedDefinition(e.props.url);return t==null?void 0:t.definition.title}hideSelectionBoundsFg(e){return!this.canResize(e)}canEdit(){return!0}canResize(e){var t,r;return!!((r=(t=this.getEmbedDefinition(e.props.url))==null?void 0:t.definition)!=null&&r.doesResize)}canEditInReadonly(){return!0}getDefaultProps(){return{w:300,h:300,url:""}}isAspectRatioLocked(e){const t=this.getEmbedDefinition(e.props.url);return(t==null?void 0:t.definition.isAspectRatioLocked)??!1}onResize(e,t){const r=this.isAspectRatioLocked(e),s=this.getEmbedDefinition(e.props.url);let o=(s==null?void 0:s.definition.minWidth)??200,i=(s==null?void 0:s.definition.minHeight)??200;if(r){const a=e.props.w/e.props.h;a>1?o*=a:i/=a}return j0(e,t,{minWidth:o,minHeight:i})}component(e){const t=Cg(),{w:r,h:s,url:o}=e.props,i=Tg(e.id),a=this.getEmbedDefinition(o),l=se("is hovering",()=>{const{editingShapeId:m,hoveredShapeId:S}=this.editor.getCurrentPageState();if(m&&S!==m){const v=this.editor.getShape(m);if(v&&this.editor.isShapeOfType(v,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(e).rotation();if(t)return g.jsx(Xl,{className:"tl-embed-container",id:e.id,children:g.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:e0(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:(a==null?void 0:a.definition.backgroundColor)??"var(--color-background)",width:r,height:s}})});const u=i||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const m=a.url.split("/").pop();if(!m)throw Error("No gist id!");return g.jsx(Xl,{className:"tl-embed-container",id:e.id,children:g.jsx(Y0e,{id:m,width:Q(r),height:Q(s),isInteractive:u,pageRotation:c})})}const p=q0e({...Dge,...(a==null?void 0:a.definition.overridePermissions)??{}});return g.jsx(Xl,{className:"tl-embed-container",id:e.id,children:a!=null&&a.definition?g.jsx("iframe",{className:"tl-embed",sandbox:p,src:a.embedUrl,width:Q(r),height:Q(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",tabIndex:i?0:-1,style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:e0(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(e){const t=this.getEmbedDefinition(e.props.url);return g.jsx("rect",{width:Q(e.props.w),height:Q(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:rt(e.props.w,t.props.w,r),h:rt(e.props.h,t.props.h,r)}}};R(Ma,"type","embed"),R(Ma,"props",_5),R(Ma,"migrations",M5),R(Ma,"embedDefinitions",$_);let t0=Ma;function Y0e({id:n,isInteractive:e,width:t,height:r,style:s,pageRotation:o}){if(!n.match(/^[0-9a-f]+$/))throw Error("No gist id!");return g.jsx("iframe",{className:"tl-embed",draggable:!1,width:Q(t),height:Q(r),frameBorder:"0",scrolling:"no",referrerPolicy:"no-referrer-when-downgrade",tabIndex:e?0:-1,style:{...s,pointerEvents:e?"all":"none",zIndex:e?"":"-1",boxShadow:e0(o)},srcDoc:`
470
+ <html>
471
+ <head>
472
+ <base target="_blank">
473
+ </head>
474
+ <body>
475
+ <script src=${`https://gist.github.com/${n}.js`}><\/script>
476
+ <style type="text/css">
477
+ * { margin: 0px; }
478
+ table { height: 100%; background-color: red; }
479
+ .gist { background-color: none; height: 100%; }
480
+ .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
481
+ </style>
482
+ </body>
483
+ </html>`})}function JE(n,e){const s=((ou(n.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(s)}const h3=new WeakMap;function f3(n,e,t){let r=h3.get(e.props);if(!r){const s=g2(e.props.name,"Frame")+"​",o=n.textMeasure.measureTextSpans(s,t),i=o[0],a=cr(o);r=a.box.w+a.box.x-i.box.x,h3.set(e.props,r)}return new ye(0,-t.height,r,t.height)}function p3(n,e){return{fontSize:12,fontFamily:e?"Arial":"Inter, sans-serif",textAlign:"start",width:n,height:24,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",offsetY:-34,offsetX:0}}function lK(n,e,t){const r=t?"":"px",s=t?"":"deg";let o;switch(e){case 0:o="";break;case 3:o=`translate(${Q(n.props.w)}${r}, 0${r}) rotate(90${s})`;break;case 2:o=`translate(${Q(n.props.w)}${r}, ${Q(n.props.h)}${r}) rotate(180${s})`;break;case 1:o=`translate(0${r}, ${Q(n.props.h)}${r}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return o}const X0e=k.forwardRef(({id:n,name:e,isEditing:t},r)=>{const s=ne(),o=k.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Yt(l),l.currentTarget.blur(),s.setEditingShape(null))},[s]),i=k.useCallback(l=>{const c=s.getShape(n);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&s.updateShapes([{id:n,type:"frame",props:{name:h}}])},[n,s]),a=k.useCallback(l=>{const c=s.getShape(n);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&s.updateShapes([{id:n,type:"frame",props:{name:h}}])},[n,s]);return g.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[g.jsx("input",{className:"tl-frame-name-input",ref:r,disabled:!t,readOnly:!t,style:{display:t?void 0:"none"},value:e,autoFocus:!0,onKeyDown:o,onBlur:i,onChange:a,onPointerDown:t?Yt:void 0,draggable:!1}),g2(e,"Frame")+"​"]})}),Z0e=k.memo(function({id:e,name:t,width:r,height:s,fill:o,stroke:i,color:a,offsetX:l,showColors:c}){const u=ne(),{side:h,translation:p}=se("shape rotation",()=>{const v=u.getShape(e);if(!v)return{side:0,translation:"translate(0, 0)"};const y=JE(u,v);return{side:y,translation:lK(v,y,!1)}},[u,l,e]),m=k.useRef(null),S=Tg(e);return k.useEffect(()=>{const v=m.current;v&&S&&(v.focus(),v.select())},[m,S]),g.jsx("div",{className:"tl-frame-heading",style:{overflow:S?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(h===0||h===2?r:s)}px + ${c?"0px":"var(--frame-offset-width)"})`,bottom:"100%",transform:`${p} scale(var(--tl-scale)) translateX(${l}px)`},children:g.jsx("div",{className:"tl-frame-heading-hit-area",style:{color:a,backgroundColor:o,boxShadow:`inset 0px 0px 0px 1px ${i}`},children:g.jsx(X0e,{ref:m,id:e,name:t,isEditing:S})})})}),J0e=12,Q0e=32,eve=-7,tve=4;function g2(n,e){return n.match(/^\s*$/)?e:n}class hS extends Rh{constructor(){super(...arguments);R(this,"options",{showColors:!1})}static configure(t){const r=super.configure.call(this,t);return t.showColors&&(r.props={...r.props,color:ts}),r}canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:"",color:"black"}}getAriaDescriptor(t){return t.props.name}getGeometry(t){const{editor:r}=this,s=r.getZoomLevel(),o=JE(r,t),i=o%2===1,a=i?t.props.h:t.props.w,l=p3(a,!1),c=f3(r,t,l),u=this.options.showColors,h=J0e/s,p=Q0e/s,m=a+(u?1:h),S=c.w/s,v=c.h/s,y=$t(S+h,p,m),w=(u?-1:eve)/s,C=tve/s,T=i?v:y,E=i?y:v;let _,A;switch(o){case 0:{_=w,A=-(v+C);break}case 1:{_=-(v+C),A=t.props.h-(w+y);break}case 2:{_=t.props.w-(w+y),A=t.props.h+C;break}case 3:{_=t.props.w+C,A=w;break}}return new ds({children:[new Zi({width:t.props.w,height:t.props.h,isFilled:!1}),new Zi({x:_,y:A,width:T,height:E,isFilled:!0,isLabel:!0})]})}getText(t){return t.props.name}component(t){const r=Ko(),s=se("is creating this shape",()=>{const m=this.editor.getStateDescendant("select.resizing");if(!m||!m.getIsActive())return!1;const S=m==null?void 0:m.info;return S?S.isCreating&&this.editor.getOnlySelectedShapeId()===t.id:!1},[t.id]),o=se("zoom level",()=>this.editor.getZoomLevel(),[this.editor]),i=this.options.showColors,a=r[t.props.color],l=i?a.frame.fill:r.black.frame.fill,c=i?a.frame.stroke:r.black.frame.stroke,u=i?a.frame.headingStroke:r.background,h=i?a.frame.headingFill:r.background,p=i?a.frame.text:r.text;return g.jsxs(g.Fragment,{children:[g.jsx(rc,{children:g.jsx("rect",{className:$e("tl-frame__body",{"tl-frame__creating":s}),width:t.props.w+1/o,height:t.props.h+1/o,fill:l,stroke:c,y:-.5/o,x:-.5/o})}),s?null:g.jsx(Z0e,{id:t.id,name:t.props.name,fill:h,stroke:u,color:p,width:t.props.w,height:t.props.h,offsetX:i?-1:-7,showColors:this.options.showColors})]})}toSvg(t,r){const s=tl({isDarkMode:r.isDarkMode}),o=JE(this.editor,t),a=o%2===1?t.props.h:t.props.w,l=lK(t,o,!0),c=p3(a-12,!0),u=g2(t.props.name,"Frame")+"​",h=f3(this.editor,t,c),p=this.editor.textMeasure.measureTextSpans(u,c),m=YE(this.editor,p,c),S=this.options.showColors,v=s[t.props.color],y=S?v.frame.fill:s.black.frame.fill,w=S?v.frame.stroke:s.black.frame.stroke,C=S?v.frame.headingStroke:s.background,T=S?v.frame.headingFill:s.background,E=S?v.frame.text:s.text;return g.jsxs(g.Fragment,{children:[g.jsx("rect",{width:t.props.w,height:t.props.h,fill:y,stroke:w,strokeWidth:1,x:0,rx:0,ry:0}),g.jsxs("g",{fill:E,transform:l,children:[g.jsx("rect",{x:h.x-(S?0:6),y:h.y-6,width:Math.min(a,h.width+12),height:h.height,fill:T,stroke:C,rx:4,ry:4}),g.jsx("g",{transform:`translate(${S?8:0}, 4)`,children:m})]})]})}indicator(t){return g.jsx("rect",{width:Q(t.props.w),height:Q(t.props.h),className:"tl-frame-indicator"})}canReceiveNewChildrenOfType(t,r){return!t.isLocked}providesBackgroundForChildren(){return!0}canDropShapes(t,r){return!t.isLocked}onDragShapesOver(t,r){r.every(s=>s.parentId===t.id)||this.editor.reparentShapes(r,t.id)}onDragShapesOut(t,r){const s=this.editor.getShape(t.parentId);s&&this.editor.isShapeOfType(s,"group")?this.editor.reparentShapes(r,s.id):this.editor.reparentShapes(r,this.editor.getCurrentPageId())}onResize(t,r){return j0(t,r)}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,w:rt(t.props.w,r.props.w,s),h:rt(t.props.h,r.props.h,s)}}onDoubleClickEdge(t,r){if(r.target!=="selection")return;const{handle:s}=r;if(!s)return;const o=s==="left"||s==="right",i=s==="top"||s==="bottom",a=this.editor.getSortedChildIdsForParent(t.id),l=st(a.map(m=>this.editor.getShape(m)));if(!l.length)return;const{dx:c,dy:u,w:h,h:p}=eH(l,this.editor,{padding:10});return this.editor.run(()=>{const m=a.map(S=>{const v=this.editor.getShape(S);return{id:v.id,type:v.type,x:o?v.x+c:v.x,y:i?v.y+u:v.y}});this.editor.updateShapes(m)}),{id:t.id,type:t.type,props:{w:o?h:t.props.w,h:i?p:t.props.h}}}onDoubleClickCorner(t){return tH(this.editor,t.id,{padding:10}),{id:t.id,type:t.type}}}R(hS,"type","frame"),R(hS,"props",A5),R(hS,"migrations",O5);const nve=We.forwardRef(function({shapeId:e,isEditing:t,richText:r,handleFocus:s,handleChange:o,handleBlur:i,handleKeyDown:a,handleDoubleClick:l,hasCustomTabBehavior:c},u){const h=ne(),p=Ou("tip-tap-editor"),m=h.getTextOptions().tipTapConfig,S=k.useRef(r),v=k.useRef(null),y=k.useRef(null);k.useLayoutEffect(()=>{v.current?S.current!==r&&v.current.commands.setContent(r):S.current=r},[r]);const w=k.useRef({selectAll:!1,caretPosition:null});k.useLayoutEffect(()=>{function O(F){F.shapeId===h.getEditingShapeId()&&(w.current.selectAll=!0)}function D(F){F.shapeId===h.getEditingShapeId()&&(w.current.caretPosition=F.point)}return h.on("select-all-text",O),h.on("place-caret",D),()=>{h.off("select-all-text",O),h.off("place-caret",D)}},[h,t]);const C=Oa(o),T=Oa(a),E=Oa(s),_=Oa(i),A=Oa(l);return k.useLayoutEffect(()=>{if(!t||!m||!y.current)return;const{editorProps:O,...D}=m,F=new Ece({element:y.current,autofocus:!0,editable:t,onUpdate:V=>{const Y=V.editor.state.doc.toJSON();S.current=Y,C({richText:Y})},onFocus:E,onBlur:_,onCreate:V=>{var z;if(h.getEditingShapeId()!==e)return;const Y=V.editor;h.setRichTextEditor(Y);const{selectAll:j,caretPosition:N}=w.current;if(j)Y.chain().focus().selectAll().run();else if(N){const G=(z=Y.view.posAtCoords({left:N.x,top:N.y}))==null?void 0:z.pos;G?Y.chain().focus().setTextSelection(G).run():Y.chain().focus().selectAll().run()}},editorProps:{handleKeyDown:(V,Y)=>{!c&&Y.key==="Tab"&&rve(h,V,Y),T(Y)},handleDoubleClick:(V,Y,j)=>A(j),...O},coreExtensionOptions:{clipboardTextSerializer:{blockSeparator:`
484
+ `}},...D,content:S.current}),U=h.timers.setTimeout(()=>{w.current.caretPosition||w.current.selectAll?F.commands.focus():F.commands.focus("end"),w.current.selectAll=!1,w.current.caretPosition=null},100);return v.current=F,()=>{v.current=null,clearTimeout(U),F.destroy()}},[t,m,E,_,A,C,T,h,e,c]),!t||!m?null:g.jsx("div",{id:p,ref:u,tabIndex:-1,"data-testid":"rich-text-area",className:"tl-rich-text tl-text tl-text-input",onContextMenu:t?Yt:void 0,onPointerDownCapture:Yt,onTouchEnd:Yt,onDragStart:nt,children:g.jsx("div",{className:"tl-rich-text",ref:y})})});function rve(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:o}=e,{$from:i,$to:a}=s.selection,l=t.shiftKey;let c=s.tr,u=a.end();for(;u>=i.start();){const p=s.doc.resolve(u).blockRange();if(!p)break;const m=p.start,S=p.end,v=s.doc.textBetween(m,S,`
485
+ `);let y=!1;s.doc.nodesBetween(m,S,w=>{if(w.type.name==="bulletList"||w.type.name==="orderedList")return y=!0,!1}),y||(l?v.startsWith(" ")&&(c=c.delete(m+1,m+2)):c=c.insertText(" ",m+1)),u=m-1}const h=s.selection.map(c.doc,c.mapping);c.setSelection(h),c.docChanged&&o(c)}function sve(n,e,t){const r=YH(n),s=r.isEditing,o=ne(),i=k.useRef(null),a=t&&ii(t);k.useEffect(()=>{var h;if(!s)return;const u=(h=i.current)==null?void 0:h.querySelector("[contenteditable]");u&&document.activeElement!==i.current&&u.focus()},[o,s]);const l=k.useCallback(u=>{if(o.getEditingShapeId()===n)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&o.complete();break}}},[o,n]),c=k.useCallback(({richText:u})=>{o.getEditingShapeId()===n&&o.updateShape({id:n,type:e,props:{richText:u}})},[o,n,e]);return{rInput:i,handleKeyDown:l,handleChange:c,isEmpty:a,...r}}const m2=We.memo(function({shapeId:e,type:t,richText:r,labelColor:s,font:o,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:m,classNamePrefix:S,style:v,textWidth:y,textHeight:w,hasCustomTabBehavior:C}){const T=ne(),E=We.useRef(!1),{rInput:_,isEmpty:A,isEditing:O,isReadyForEditing:D,...F}=sve(e,t,r),U=k.useMemo(()=>{if(r)return l2(T,r)},[T,r]),V=se("isSelectToolActive",()=>T.getCurrentToolId()==="select",[T]);u0("isDragging",()=>{T.getInstanceState(),E.current=T.inputs.isDragging},[T]);const Y=qH(l),j=z=>{var G;if(z.target instanceof HTMLElement&&(z.target.tagName==="A"||z.target.closest("a"))){if(nt(z),!V)return;const q=((G=z.target.closest("a"))==null?void 0:G.getAttribute("href"))??"",$=K=>{K.name==="pointer_up"&&(E.current||window.open(q,"_blank","noopener, noreferrer"),T.off("event",$))};T.on("event",$)}};if(!O&&A)return null;const N=S||"tl-text";return g.jsx("div",{className:`${N}-label tl-text-wrapper tl-rich-text-wrapper`,"data-font":o,"data-align":l,"data-hastext":!A,"data-isediting":O,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||Y?"center":l,alignItems:c==="middle"?"center":c,padding:p,...v},children:g.jsxs("div",{className:`${N}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(y||0),color:s,width:y?Math.ceil(y):void 0,height:w?Math.ceil(w):void 0},children:[g.jsx("div",{className:`${N} tl-text tl-text-content`,dir:"auto",children:r&&g.jsx("div",{className:"tl-rich-text","data-is-select-tool-active":V,dangerouslySetInnerHTML:{__html:U||""},onPointerDown:j,"data-is-ready-for-editing":D})}),(D||h)&&g.jsx(nve,{ref:_,richText:r,isEditing:O,shapeId:e,...F,hasCustomTabBehavior:C,handleKeyDown:m??F.handleKeyDown})]})})});function y2({bounds:n,richText:e,fontSize:t,font:r,align:s,verticalAlign:o,wrap:i,labelColor:a,padding:l}){const c=ne(),u=l2(c,e),h=s==="middle"?"center":s==="start"?"start":"end",p=s==="middle"?"center":s==="start"?"flex-start":"flex-end",m=o==="middle"?"center":o==="start"?"flex-start":"flex-end",S={display:"flex",fontFamily:g5[r],height:"100%",justifyContent:p,alignItems:m,padding:`${l}px`},v={fontSize:`${t}px`,wrap:i?"wrap":"nowrap",color:a,lineHeight:mr.lineHeight,textAlign:h,width:"100%",wordWrap:"break-word",overflowWrap:"break-word",whiteSpace:"pre-wrap"};return g.jsx("foreignObject",{x:n.minX,y:n.minY,width:n.w,height:n.h,className:"tl-export-embed-styles tl-rich-text tl-rich-text-svg",children:g.jsx("div",{style:S,children:g.jsx("div",{dangerouslySetInnerHTML:{__html:u},style:v})})})}function g3(n,e){return n>e?(bt*(e/2)+(n-e))*2:(bt*(n/2)+(e-n))*2}function cK(n,e){return S2(n,e).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function ove(n,e,t,r){const s=n/4,o=e/4,i=Bo(r),a=t*.75,l=C=>C.addXY(i()*a,i()*a),c=new P(n/2,e),u=new P(0,o*1.2),h=new P(n/2,o*.9),p=new P(n,o*1.2),m=l(new P(n/2,e)),S=l(new P(0,o*1.2)),v=l(new P(n/2,o*.9)),y=l(new P(n,o*1.2));return[new Dr({start:c,cp1:new P(s*1.5,o*3),cp2:new P(0,o*2.5),end:u}),new Dr({start:u,cp1:new P(0,-o*.32),cp2:new P(s*1.85,-o*.32),end:h}),new Dr({start:h,cp1:new P(s*2.15,-o*.32),cp2:new P(n,-o*.32),end:p}),new Dr({start:p,cp1:new P(n,o*2.5),cp2:new P(s*2.5,o*3),end:m}),new Dr({start:m,cp1:new P(s*1.5,o*3),cp2:new P(0,o*2.5),end:S}),new Dr({start:S,cp1:new P(0,-o*.32),cp2:new P(s*1.85,-o*.32),end:v}),new Dr({start:v,cp1:new P(s*2.15,-o*.32),cp2:new P(n,-o*.32),end:y}),new Dr({start:y,cp1:new P(n,o*2.5),cp2:new P(s*2.5,o*3),end:c})].map((C,T)=>C.getSvgPathData(T===0)).join(" ")+" Z"}function S2(n,e){const t=n/4,r=e/4;return[new Dr({start:new P(n/2,e),cp1:new P(t*1.5,r*3),cp2:new P(0,r*2.5),end:new P(0,r*1.2)}),new Dr({start:new P(0,r*1.2),cp1:new P(0,-r*.32),cp2:new P(t*1.85,-r*.32),end:new P(n/2,r*.9)}),new Dr({start:new P(n/2,r*.9),cp1:new P(t*2.15,-r*.32),cp2:new P(n,-r*.32),end:new P(n,r*1.2)}),new Dr({start:new P(n,r*1.2),cp1:new P(n,r*2.5),cp2:new P(t*2.5,r*3),end:new P(n/2,e)})]}function ive(n){return{size:1+n,thinning:.25,end:{taper:n},start:{taper:n},streamline:0,smoothing:1,simulatePressure:!1}}function ave(n,e,t,r){const s=Bo(n),o=e/2,i=t/2,a=Z5(o,i),l=[],c=Dt*s(),u=Dt+qt/2+Math.abs(s())*qt,h=Math.max(16,a/10);for(let p=0;p<h;p++){const m=p/(h-1),S=c+m*u,v=Math.cos(S),y=Math.sin(S);l.push(new P(o*v+e*.5+.05*s(),i*y+t/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?qn.easeInOutSine(m):qn.easeInExpo(m)))/2)))}return na(l,ive(r))}function lve(n,e,t,r){return Pu(ave(n,e,t,r))}function QE(n){let e="M";const t=n.length;let r,s,o;for(let i=0,a=t;i<a;i+=3)r=n[i],s=n[i+1],o=n[i+2],e+=`${kt(r)}L${kt(s)}Q${kt(o)}`;return e+=`${kt(n[0])}`,e}function eI(n,e,t,r,s){const o=[],i=Bo(n);let a=e[0],l;const c=e.length;for(let u=0,h=c*s;u<h;u++){l=P.AddXY(e[(u+1)%c],i()*t,i()*t);const p=P.Sub(l,a),m=P.Len(p),S=P.Div(p,m).mul(Math.min(m/4,r));o.push(P.Add(a,S),P.Add(l,S.neg()),l),a=l}return o}function cve(n,e,t){const r=Math.min(n,e)/2,s=Math.max(n,e)-r*2,i=(Math.PI*(r*2)+2*s)/t,a=n>e?[{type:"straight",start:new P(r,0),delta:new P(1,0)},{type:"arc",center:new P(n-r,r),startAngle:-bt/2},{type:"straight",start:new P(n-r,e),delta:new P(-1,0)},{type:"arc",center:new P(r,r),startAngle:bt/2}]:[{type:"straight",start:new P(n,r),delta:new P(0,1)},{type:"arc",center:new P(r,e-r),startAngle:0},{type:"straight",start:new P(0,e-r),delta:new P(0,-1)},{type:"arc",center:new P(r,r),startAngle:bt}];let l=0;const c=[];for(let u=0;u<t;u++){const h=a[0];h.type==="straight"?c.push(P.Add(h.start,P.Mul(h.delta,l))):c.push(v0(h.center,r,h.startAngle+l/r)),l+=i;let p=h.type==="straight"?s:bt*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?s:bt*r}return c}const uve={s:50,m:70,l:100,xl:130},dve=.2;function Iv(n,e,t,r,s){const o=Bo(t),i=g3(n,e),a=Math.max(Math.ceil(i/uve[r]),6,Math.ceil(i/Math.min(n,e))),l=i/a*dve,c=Math.max(n-l*2,1),u=Math.max(e-l*2,1),p=g3(c,u)/a,m=(n-c)/2,S=(e-u)/2,v=cve(c,u,a).map(E=>E.addXY(m,S)),y=n<20?0:l*.3,w=e<20?0:l*.3,C=v.slice(0);for(let E=0;E<Math.floor(a/2);E++)C[E]=P.AddXY(C[E],o()*y*s,o()*w*s),C[a-E-1]=P.AddXY(C[a-E-1],o()*y*s,o()*w*s);const T=[];for(let E=0;E<C.length;E++){const _=E===C.length-1?0:E+1,A=C[E],O=C[_],D=v[E],F=v[_],U=P.Dist(D,F),V=p-U,j=P.Dist(A,O)/U,N=(Math.max(m,S)+V)*j,z=P.Lrp(D,F,.5).add(P.Sub(F,D).uni().per().mul(N));z.x<0?z.x=0:z.x>n&&(z.x=n),z.y<0?z.y=0:z.y>e&&(z.y=e);const G=tT(A,O,z),q=P.Dist(G||P.Average([A,O]),A);T.push({leftPoint:A,rightPoint:O,arcPoint:z,center:G,radius:q})}return T}function hve(n,e,t,r,s){const o=[],i=Iv(n,e,t,r,s);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)o.push(...iJ(c,u,a,l,10));return o}function tI(n,e,t,r,s){const o=Iv(n,e,t,r,s);let i=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:a,rightPoint:l,radius:c,center:u}of o){if(u===null){i+=` L${l.toFixed()}`;continue}const h=P.Clockwise(a,l,u)?"0":"1";i+=` A${Q(c)},${Q(c)} 0 ${h},1 ${l.toFixed()}`}return i+=" Z",i}const fve={s:.5,m:.7,l:.9,xl:1.6};function pve(n,e,t,r,s){const o=Bo(t),i=fve[r]*s,a=Iv(n,e,t,r,s),u=a.reduce((S,v)=>S+P.Dist2(v.leftPoint,v.rightPoint),0)/a.length>(i*15)**2?S=>P.AddXY(S,o()*i*2,o()*i*2):S=>S;let h=`M${a[0].leftPoint.toFixed()}`,p=u(a[0].leftPoint),m=`M${p.toFixed()}`;for(const{leftPoint:S,center:v,rightPoint:y,radius:w,arcPoint:C}of a){if(v===null){h+=` L${y.toFixed()}`;const D=u(y);m+=` L${D.toFixed()}`,p=D;continue}const T=P.Clockwise(S,y,v)?"0":"1";h+=` A${Q(w)},${Q(w)} 0 ${T},1 ${y.toFixed()}`;const E=u(y),_=u(C),A=tT(p,E,_);if(!A){m+=` L${E.toFixed()}`,p=E;continue}const O=Math.abs(P.Dist(A,p));m+=` A${Q(O)},${Q(O)} 0 ${T},1 ${E.toFixed()}`,p=E}return h+m+" Z"}function x2(n,e){switch(n.geo){case"x-box":return gve(n.w,n.h,e,n.dash);case"check-box":return mve(n.w,n.h);default:return}}function gve(n,e,t,r){const s=r==="draw"?.62:0;if(r==="dashed")return[[new P(0,0),new P(n/2,e/2)],[new P(n,e),new P(n/2,e/2)],[new P(0,e),new P(n/2,e/2)],[new P(n,0),new P(n/2,e/2)]];const o=a=>Math.max(0,Math.min(n,a)),i=a=>Math.max(0,Math.min(e,a));return[[new P(o(t*s),i(t*s)),new P(o(n-t*s),i(e-t*s))],[new P(o(t*s),i(e-t*s)),new P(o(n-t*s),i(t*s))]]}function mve(n,e){const t=Math.min(n,e)*.82,r=(n-t)/2,s=(e-t)/2,o=a=>Math.max(0,Math.min(n,a)),i=a=>Math.max(0,Math.min(e,a));return[[new P(o(r+t*.25),i(s+t*.52)),new P(o(r+t*.45),i(s+t*.82))],[new P(o(r+t*.45),i(s+t*.82)),new P(o(r+t*.82),i(s+t*.22))]]}function m3({shape:n,shouldScale:e,forceSolid:t}){const r=e?n.props.scale:1,s=ne(),o=Ko(),{id:i,props:a}=n,{w:l,color:c,fill:u,dash:h,growY:p,size:m,scale:S}=a,v=Dn[m]*r,y=a.h+p;switch(a.geo){case"cloud":if(h==="solid"){const w=tI(l,y,i,m,S);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:w,color:c,fill:u,scale:r}),g.jsx("path",{d:w,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}else if(h==="draw"){const w=pve(l,y,i,m,S);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:w,color:c,fill:u,scale:r}),g.jsx("path",{d:w,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}else{const w=tI(l,y,i,m,S),C=Iv(l,y,i,m,S);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:w,color:c,fill:u,scale:r}),g.jsx("g",{strokeWidth:v,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:C.map(({leftPoint:T,rightPoint:E,center:_,radius:A},O)=>{const D=_?A*ou(ou(P.Angle(_,E))-ou(P.Angle(_,T))):P.Dist(T,E),{strokeDasharray:F,strokeDashoffset:U}=oi(D,v,{style:h,start:"outset",end:"outset",forceSolid:t});return g.jsx("path",{d:_?`M${T.x},${T.y}A${A},${A},0,0,1,${E.x},${E.y}`:`M${T.x},${T.y}L${E.x},${E.y}`,strokeDasharray:F,strokeDashoffset:U},O)})})]})}case"ellipse":{const w=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=w.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const T=w.length,{strokeDasharray:E,strokeDashoffset:_}=oi(T<64?T*2:T,v,{style:h,snap:4,closed:!0,forceSolid:t});return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:C,color:c,fill:u,scale:r}),g.jsx("path",{d:C,strokeWidth:v,fill:"none",stroke:o[c].solid,strokeDasharray:E,strokeDashoffset:_})]})}else{const E=(e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n)).getSvgPathData(!0);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:E,color:c,fill:u,scale:r}),g.jsx("path",{d:E,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}}case"oval":{const w=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=w.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const T=w.getLength(),{strokeDasharray:E,strokeDashoffset:_}=oi(T<64?T*2:T,v,{style:h,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:t});return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:C,color:c,fill:u,scale:r}),g.jsx("path",{d:C,strokeWidth:v,fill:"none",stroke:o[c].solid,strokeDasharray:E,strokeDashoffset:_})]})}else return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:C,color:c,fill:u,scale:r}),g.jsx("path",{d:C,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const w=cK(l,y),C=S2(l,y);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:w,color:c,fill:u,scale:r}),C.map((T,E)=>{const{strokeDasharray:_,strokeDashoffset:A}=oi(T.length,v,{style:h,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:t});return g.jsx("path",{d:T.getSvgPathData(),strokeWidth:v,fill:"none",stroke:o[c].solid,strokeDasharray:_,strokeDashoffset:A,pointerEvents:"all"},`curve_${E}`)})]})}else{const w=ove(l,y,v,n.id);return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:w,color:c,fill:u,scale:r}),g.jsx("path",{d:w,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}default:{const w=e?s.getShapeGeometry(n):s.getShapeUtil(n).getGeometry(n),C=w instanceof ds?w.children[0].vertices:w.vertices,T=x2(n.props,v);if(h==="solid"){let E="M"+C[0]+"L"+C.slice(1)+"Z";if(T)for(const[_,A]of T)E+=`M${_.x},${_.y}L${A.x},${A.y}`;return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:E,color:c,fill:u,scale:r}),g.jsx("path",{d:E,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}else if(h==="dashed"||h==="dotted"){const E="M"+C[0]+"L"+C.slice(1)+"Z";return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:E,color:c,fill:u,scale:r}),g.jsxs("g",{strokeWidth:v,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(C.length)).map((_,A)=>{const O=P.ToFixed(C[A]),D=P.ToFixed(C[(A+1)%C.length]),F=P.Dist(O,D),{strokeDasharray:U,strokeDashoffset:V}=oi(F,v,{style:h,start:"outset",end:"outset",forceSolid:t});return g.jsx("line",{x1:O.x,y1:O.y,x2:D.x,y2:D.y,strokeDasharray:U,strokeDashoffset:V},A)}),T&&T.map(([_,A],O)=>{const D=P.Dist(_,A),{strokeDasharray:F,strokeDashoffset:U}=oi(D,v,{style:h,start:"skip",end:"skip",snap:h==="dotted"?4:void 0,forceSolid:t});return g.jsx("path",{d:`M${_.x},${_.y}L${A.x},${A.y}`,stroke:o[c].solid,strokeWidth:v,fill:"none",strokeDasharray:F,strokeDashoffset:U},`line_fg_${O}`)})]})]})}else if(h==="draw"){let E=QE(eI(i,C,v/3,v*2,2));if(T)for(const[A,O]of T)E+=`M${A.toFixed()}L${O.toFixed()}`;const _=QE(eI(i,C,0,v*2,1));return g.jsxs(g.Fragment,{children:[g.jsx(Mr,{theme:o,d:_,color:c,fill:u,scale:r}),g.jsx("path",{d:E,stroke:o[c].solid,strokeWidth:v,fill:"none"})]})}}}}const y3=17*3;class fS extends Rh{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:Fo("")}}getGeometry(e){const t=Math.max(1,e.props.w),r=Math.max(1,e.props.h+e.props.growY),s=t/2,o=r/2,i=e.props.fill!=="none";let a;switch(e.props.geo){case"cloud":{a=new Pn({points:hve(t,r,e.id,e.props.size,e.props.scale),isFilled:i});break}case"triangle":{a=new Pn({points:[new P(s,0),new P(t,r),new P(0,r)],isFilled:i});break}case"diamond":{a=new Pn({points:[new P(s,0),new P(t,o),new P(s,r),new P(0,o)],isFilled:i});break}case"pentagon":{a=new Pn({points:RC(t,r,5),isFilled:i});break}case"hexagon":{a=new Pn({points:RC(t,r,6),isFilled:i});break}case"octagon":{a=new Pn({points:RC(t,r,8),isFilled:i});break}case"ellipse":{a=new Ese({width:t,height:r,isFilled:i});break}case"oval":{a=new Ise({width:t,height:r,isFilled:i});break}case"star":{const C=Dt/5/2,T=Math.floor(5/4)*2,E=5*2-T,_=0,A=Math.floor(5/2)*2,O=Math.cos(-qt+T*C)*t/2,D=Math.cos(-qt+E*C)*t/2,F=Math.sin(-qt+_*C)*r/2,U=Math.sin(-qt+A*C)*r/2,V=t-Math.abs(O-D),Y=r-Math.abs(U-F),j=t/2+D-(t/2-O),N=r/2+F-(r/2-U),z=1,G=(t-j)/2,q=(r-N)/2,$=(t+V)/2,K=(r+Y)/2,J=$*z/2,H=K*z/2;a=new Pn({points:Array.from(Array(5*2)).map((te,he)=>{const Pe=-qt+he*C;return new P(G+(he%2?J:$)*Math.cos(Pe),q+(he%2?H:K)*Math.sin(Pe))}),isFilled:i});break}case"rhombus":{const w=Math.min(t*.38,r*.38);a=new Pn({points:[new P(w,0),new P(t,0),new P(t-w,r),new P(0,r)],isFilled:i});break}case"rhombus-2":{const w=Math.min(t*.38,r*.38);a=new Pn({points:[new P(0,0),new P(t-w,0),new P(t,r),new P(w,r)],isFilled:i});break}case"trapezoid":{const w=Math.min(t*.38,r*.38);a=new Pn({points:[new P(w,0),new P(t-w,0),new P(t,r),new P(0,r)],isFilled:i});break}case"arrow-right":{const w=Math.min(t,r)*.38,C=r*.16;a=new Pn({points:[new P(0,C),new P(t-w,C),new P(t-w,0),new P(t,r/2),new P(t-w,r),new P(t-w,r-C),new P(0,r-C)],isFilled:i});break}case"arrow-left":{const w=Math.min(t,r)*.38,C=r*.16;a=new Pn({points:[new P(w,0),new P(w,C),new P(t,C),new P(t,r-C),new P(w,r-C),new P(w,r),new P(0,r/2)],isFilled:i});break}case"arrow-up":{const w=t*.16,C=Math.min(t,r)*.38;a=new Pn({points:[new P(t/2,0),new P(t,C),new P(t-w,C),new P(t-w,r),new P(w,r),new P(w,C),new P(0,C)],isFilled:i});break}case"arrow-down":{const w=t*.16,C=Math.min(t,r)*.38;a=new Pn({points:[new P(w,0),new P(t-w,0),new P(t-w,r-C),new P(t,r-C),new P(t/2,r),new P(0,r-C),new P(w,r-C)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new Zi({width:t,height:r,isFilled:i});break}case"heart":{const C=S2(t,r).reduce((T,E)=>(T.push(...E.vertices),T),[]);a=new Pn({points:C,isFilled:i});break}default:xt(e.props.geo)}const l=Ny(this.editor,e),c=t/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),p=Math.min(Ua[e.props.size]*mr.lineHeight+Zr*2,u/2),m=Math.min(c,Math.max(l.w,Math.min(h,Math.max(1,c-8)))),S=Math.min(u,Math.max(l.h,Math.min(p,Math.max(1,u-8)))),v=x2(e.props,Dn[e.props.size]*e.props.scale),y=v?v.map(w=>new fc({points:w,isInternal:!0})):[];return new ds({children:[a,new Zi({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"?(u-S)*e.props.scale:(u-S)/2*e.props.scale,width:m*e.props.scale,height:S*e.props.scale,isFilled:!0,isLabel:!0}),...y]})}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.vertices,t.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:r,points:[t.bounds.center]};default:xt(e.props.geo)}}getText(e){return Cu(this.editor,e.props.richText)}getFontFaces(e){return GT(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:o,font:i,align:a,verticalAlign:l,size:c,richText:u}=s,h=Ko(),{editor:p}=this,m=se("isGeoOnlySelected",()=>e.id===p.getOnlySelectedShapeId(),[p]),S=u2(p,e.id),v=ii(e.props.richText),y=S||!v,w=se("force solid",()=>p.getZoomLevel()<.2,[p]);return g.jsxs(g.Fragment,{children:[g.jsx(rc,{children:g.jsx(m3,{shape:e,shouldScale:!0,forceSolid:w})}),y&&g.jsx(Xl,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+s.growY},children:g.jsx(m2,{shapeId:t,type:r,font:i,fontSize:Ua[c]*e.props.scale,lineHeight:mr.lineHeight,padding:Zr*e.props.scale,fill:o,align:a,verticalAlign:l,richText:u,isSelected:m,labelColor:h[s.labelColor].solid,wrap:!0})}),e.props.url&&g.jsx(vh,{url:e.props.url})]})}indicator(e){const t=this.editor.getShapeGeometry(e),r=se("isZoomedOut",()=>this.editor.getZoomLevel()<.25,[this.editor]),s=yve(e,t,r);return g.jsx("path",{d:s})}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(d2(s.fill));let o;if(!ii(s.richText)){const i=tl(t),a=new ye(0,0,s.w,s.h+s.growY);o=g.jsx(y2,{fontSize:Ua[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,richText:s.richText,labelColor:i[s.labelColor].solid,bounds:a,padding:Zr*e.props.scale})}return g.jsxs(g.Fragment,{children:[g.jsx(m3,{shouldScale:!1,shape:r,forceSolid:!1}),o]})}getCanvasSvgDefs(){return[h2()]}onResize(e,{handle:t,newPoint:r,scaleX:s,scaleY:o,initialShape:i}){const a=i.props.w/i.props.scale,l=i.props.h/i.props.scale,c=i.props.growY/i.props.scale;let u=a*s,h=(l+c)*o,p=0,m=0;const S=y3;if(!ii(e.props.richText)){let E=Math.max(Math.abs(u),S),_=Math.max(Math.abs(h),S);E<S&&_===S&&(E=S),E===S&&_<S&&(_=S);const A=Ny(this.editor,{...e,props:{...e.props,w:E*e.props.scale,h:_*e.props.scale}}),O=Math.max(Math.abs(u),A.w)*Math.sign(u),D=Math.max(Math.abs(h),A.h)*Math.sign(h);p=Math.abs(O)-Math.abs(u),m=Math.abs(D)-Math.abs(h),u=O,h=D}const v=u*e.props.scale,y=h*e.props.scale,w=new P(0,0);s<0&&(w.x+=v),(t==="left"||t==="top_left"||t==="bottom_left")&&(w.x+=s<0?p:-p),o<0&&(w.y+=y),(t==="top"||t==="top_left"||t==="top_right")&&(w.y+=o<0?m:-m);const{x:C,y:T}=w.rot(e.rotation).add(r);return{x:C,y:T,props:{w:Math.max(Math.abs(v),1),h:Math.max(Math.abs(y),1),growY:0}}}onBeforeCreate(e){if(ii(e.props.richText))return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const t=e.props.h/e.props.scale,r=Ny(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(Ih(e.props.richText,t.props.richText)&&e.props.font===t.props.font&&e.props.size===t.props.size)return;const r=ii(e.props.richText),s=ii(t.props.richText);if(!r&&s)return{...t,props:{...t.props,growY:0}};const o=e.props.w/e.props.scale,i=e.props.h/e.props.scale,a=e.props.growY/e.props.scale,l=Ny(this.editor,t);if(r&&!s&&Cu(this.editor,t.props.richText)){let u=Math.max(o,l.w),h=Math.max(i,l.h);const p=y3;return o<p&&i<p&&(u=Math.max(u,p),h=Math.max(h,p),u=Math.max(u,h),h=Math.max(u,h)),{...t,props:{...t.props,w:u*t.props.scale,h:h*t.props.scale,growY:0}}}let c=null;if(l.h>i?c=l.h-i:a&&(c=0),c!==null){const u=t.props.w/t.props.scale;return{...t,props:{...t.props,growY:c*t.props.scale,w:Math.max(u,l.w)*t.props.scale}}}if(l.w>o)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:rt(e.props.w,t.props.w,r),h:rt(e.props.h,t.props.h,r),scale:rt(e.props.scale,t.props.scale,r)}}}R(fS,"type","geo"),R(fS,"props",R5),R(fS,"migrations",D5);function Ny(n,e){const{richText:t,font:r,size:s,w:o}=e.props;if(!t||ii(t))return{w:0,h:0};const i=n.textMeasure.measureText("w",{...mr,fontFamily:Xa[r],fontSize:Ua[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=Zx(n,t),c=n.textMeasure.measureHtml(l,{...mr,fontFamily:Xa[r],fontSize:Ua[s],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[s]),Math.ceil(o/e.props.scale-Zr*2))});return{w:c.w+Zr*2,h:c.h+Zr*2}}function yve(n,e,t){const{id:r}=n,{w:s,size:o,geo:i,dash:a,scale:l,growY:c}=n.props,u=Dn[o],h=n.props.h+c;switch(i){case"ellipse":return a==="draw"?lve(r,s,h,u):e.getSvgPathData(!0);case"heart":return cK(s,h);case"oval":return e.getSvgPathData(!0);case"cloud":return tI(s,h,r,o,n.props.scale);default:{const p=e instanceof ds?e.children[0].vertices:e.vertices;let m;if(a==="draw"&&!t){const v=eI(r,p,0,u*2*l,1);m=QE(v)}else m="M"+p[0]+"L"+p.slice(1)+"Z";const S=x2(n.props,u);if(S)for(const[v,y]of S)m+=`M${v.x},${v.y}L${y.x},${y.y}`;return m}}}function Sve(){const[n,e]=k.useState(!1);return k.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),s=matchMedia("(color-gamut: p3)");e(r&&s.matches);const o=()=>e(r&&s.matches);return s.addEventListener("change",o),()=>s.removeEventListener("change",o)},[]),se(sn.forceSrgb)||!n?"srgb":"p3"}class pS extends fi{constructor(){super(...arguments);R(this,"options",{maxPointsPerShape:600,underlayOpacity:.82,overlayOpacity:.35})}canTabTo(){return!1}hideResizeHandles(t){return Fy(t)}hideRotateHandle(t){return Fy(t)}hideSelectionBoundsFg(t){return Fy(t)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=Gc(t);if(Fy(t))return new bT({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:s,sw:o}=S3(t,r,!0),i=p2({strokeWidth:o,showAsComplete:!0});return Pv(s,i),new Pn({points:X_(s,i),isFilled:!0})}component(t){const r=VP(this.editor,t),s=Gc(t);return g.jsx(rc,{children:g.jsx(zy,{shape:t,forceSolid:r,strokeWidth:s,opacity:this.options.overlayOpacity})})}backgroundComponent(t){const r=VP(this.editor,t),s=Gc(t);return g.jsx(rc,{children:g.jsx(zy,{shape:t,forceSolid:r,strokeWidth:s,opacity:this.options.underlayOpacity})})}indicator(t){const r=VP(this.editor,t),s=Gc(t),{strokePoints:o,sw:i}=S3(t,s,r),a=wh(t.props.segments);let l;return o.length<2?l=vve(a[0],i):l=Pu(o,!1),g.jsx("path",{d:l})}toSvg(t){const r=Gc(t),s=r<1.5,o=1/t.props.scale;return g.jsx("g",{transform:`scale(${o})`,children:g.jsx(zy,{forceSolid:s,strokeWidth:r,shape:t,opacity:this.options.overlayOpacity})})}toBackgroundSvg(t){const r=Gc(t),s=r<1.5,o=1/t.props.scale;return g.jsx("g",{transform:`scale(${o})`,children:g.jsx(zy,{forceSolid:s,strokeWidth:r,shape:t,opacity:this.options.underlayOpacity})})}onResize(t,r){const{scaleX:s,scaleY:o}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:s*l,y:o*c,z:u}))});return{props:{segments:i}}}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,...r.props,segments:oK(t.props.segments,r.props.segments,s),scale:rt(t.props.scale,r.props.scale,s)}}}R(pS,"type","highlight"),R(pS,"props",N5),R(pS,"migrations",F5);function xve(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 vve(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 S3(n,e,t){var l;const r=wh(n.props.segments),s=n.props.isComplete||((l=cr(n.props.segments))==null?void 0:l.type)==="straight";let o=e;!t&&!n.props.isPen&&r.length===1&&(o+=Bo(n.id)()*(e/6));const i=p2({strokeWidth:o,showAsComplete:s});return{strokePoints:na(r,i),sw:o}}function Gc(n){return yh[n.props.size]*1.12*n.props.scale}function Fy(n){return n.props.segments.length===1&&n.props.segments[0].points.length<2}function zy({strokeWidth:n,forceSolid:e,shape:t,opacity:r}){var p;const s=Ko(),o=wh(t.props.segments);let i=n;!e&&!t.props.isPen&&o.length===1&&(i+=Bo(t.id)()*(i/6));const a=p2({strokeWidth:i,showAsComplete:t.props.isComplete||((p=cr(t.props.segments))==null?void 0:p.type)==="straight"}),l=na(o,a),c=l.length>1?Pu(l,!1):xve(t.props.segments[0].points[0]),u=Sve(),h=s[t.props.color].highlight[u];return g.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function VP(n,e){return se("forceSolid",()=>{const t=Gc(e),r=n.getZoomLevel();return t/r<1.5},[n])}function uK(){return g.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[g.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),g.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),g.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}const x3=8;function wve(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}function og(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 bve(n,e,t={}){const{handle:r,change:s,crop:o}=e,{w:i,h:a}=e.uncroppedSize,{minWidth:l=x3,minHeight:c=x3}=t,u=en(o),h=new P(n.x,n.y),p=new P(0,0);let m=!1;switch(r){case"top":case"top_left":case"top_right":{if(a<c)break;m=!0,u.topLeft.y=u.topLeft.y+s.y/a,a*(u.bottomRight.y-u.topLeft.y)<c?(u.topLeft.y=u.bottomRight.y-c/a,p.y=(u.topLeft.y-o.topLeft.y)*a):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-o.topLeft.y)*a):p.y=s.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(a<c)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+s.y/a),a*(u.bottomRight.y-u.topLeft.y)<c&&(u.bottomRight.y=u.topLeft.y+c/a);break}}switch(r){case"left":case"top_left":case"bottom_left":{if(i<l)break;m=!0,u.topLeft.x=u.topLeft.x+s.x/i,i*(u.bottomRight.x-u.topLeft.x)<l?(u.topLeft.x=u.bottomRight.x-l/i,p.x=(u.topLeft.x-o.topLeft.x)*i):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-o.topLeft.x)*i):p.x=s.x;break}case"right":case"top_right":case"bottom_right":{if(i<l)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+s.x/i),i*(u.bottomRight.x-u.topLeft.x)<l&&(u.bottomRight.x=u.topLeft.x+l/i);break}}if(m)return h.add(p.rot(n.rotation)),{id:n.id,type:n.type,x:h.x,y:h.y,props:{w:(u.bottomRight.x-u.topLeft.x)*i,h:(u.bottomRight.y-u.topLeft.y)*a,crop:u}}}function dK({shapeId:n,assetId:e,width:t}){const r=ne(),s=Cg(),o=xte(),[i,a]=k.useState(()=>({asset:e?r.getAsset(e)??null:null,url:null})),l=k.useRef(!1),c=k.useRef(null);return k.useEffect(()=>{if(!e)return;let u=!1,h;const p=jo("update state",()=>{if(!s&&n&&r.getCulledShapes().has(n))return;const m=r.getAsset(e);if(!m){a(y=>({...y,asset:null,url:null}));return}if(!m.props.src){const y=r.getTemporaryAssetPreview(m.id);if(y){c.current!==y&&(c.current=y,a(w=>({...w,isPlaceholder:!0,url:y})),o());return}}const S=s?s.scale*(t/m.props.w):r.getZoomLevel()*(t/m.props.w);function v(y,w){u||c.current!==w&&(l.current=!0,c.current=w,a({asset:y,url:w}),o())}if(l.current){let y=0;const w=()=>{y++,y>500/16&&(v3(r,e,S,s,C=>v(m,C)),h==null||h())};h==null||h(),r.on("tick",w),h=()=>r.off("tick",w)}else v3(r,e,S,s,y=>v(m,y))});return()=>{p(),h==null||h(),u=!0}},[r,e,s,o,n,t]),i}function v3(n,e,t,r,s){n.resolveAssetUrl(e,{screenScale:t,shouldResolveToOriginal:r?r.pixelRatio===null:!1,dpr:(r==null?void 0:r.pixelRatio)??void 0}).then(o=>{s(o)})}async function Cve(n){const t=await(await di(n)).blob();return Jr.blobToDataUrl(t)}const Pve=new zo;class gS extends Rh{isAspectRatioLocked(){return!0}canCrop(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null,flipX:!1,flipY:!1,altText:""}}getAriaDescriptor(e){return e.props.altText}onResize(e,t){let r=j0(e,t);const{flipX:s,flipY:o}=t.initialShape.props,{scaleX:i,scaleY:a,mode:l}=t;if(r={...r,props:{...r.props,flipX:i<0!==s,flipY:a<0!==o}},!e.props.crop)return r;const c=l==="scale_shape"&&i===-1||l==="resize_bounds"&&s!==r.props.flipX,u=l==="scale_shape"&&a===-1||l==="resize_bounds"&&o!==r.props.flipY,{topLeft:h,bottomRight:p}=e.props.crop;return r.props.crop={topLeft:{x:c?1-p.x:h.x,y:u?1-p.y:h.y},bottomRight:{x:c?1-h.x:p.x,y:u?1-h.y:p.y}},r}component(e){return g.jsx(kve,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:g.jsx("rect",{width:Q(e.props.w),height:Q(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}=og(e.props,e.props.crop),o=await Pve.get(r,async()=>{let i=await t.resolveAssetUrl(r.id,s);if(!i)return null;if((i.startsWith("blob:")||i.startsWith("http")||i.startsWith("/")||i.startsWith("./"))&&(i=await Cve(i)||""),hK(this.editor,r.id)){const{promise:a}=pK(i);i=await a}return i});return o?g.jsx(Eve,{shape:e,src:o}):null}onDoubleClickEdge(e){const t=e.props;if(!t||this.editor.getCroppingShapeId()!==e.id)return;const r=en(t.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},{w:s,h:o}=og(e.props,r),i=new P(r.topLeft.x*s,r.topLeft.y*o).rot(e.rotation),a={id:e.id,type:e.type,x:e.x-i.x,y:e.y-i.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:o}};this.editor.updateShapes([a])}getInterpolatedProps(e,t,r){function s(o,i){var h,p,m,S;if(o.props.crop===null&&i.props.crop===null)return null;const a=((h=o.props.crop)==null?void 0:h.topLeft)||{x:0,y:0},l=((p=o.props.crop)==null?void 0:p.bottomRight)||{x:1,y:1},c=((m=i.props.crop)==null?void 0:m.topLeft)||{x:0,y:0},u=((S=i.props.crop)==null?void 0:S.bottomRight)||{x:1,y:1};return{topLeft:{x:rt(a.x,c.x,r),y:rt(a.y,c.y,r)},bottomRight:{x:rt(l.x,u.x,r),y:rt(l.y,u.y,r)}}}return{...r>.5?t.props:e.props,w:rt(e.props.w,t.props.w,r),h:rt(e.props.h,t.props.h,r),crop:s(e,t)}}}R(gS,"type","image"),R(gS,"props",z5),R(gS,"migrations",B5);const kve=k.memo(function({shape:e}){var C;const t=ne(),{w:r}=og(e.props,e.props.crop),{asset:s,url:o}=dK({shapeId:e.id,assetId:e.props.assetId,width:r}),i=L8(),[a,l]=k.useState(""),[c,u]=k.useState(null),h=s&&hK(t,s.id);k.useEffect(()=>{if(o&&h){const{promise:T,cancel:E}=pK(o);return T.then(_=>{l(_),u(o)}),()=>{E()}}},[t,h,i,o]);const p=se("show crop preview",()=>e.id===t.getOnlySelectedShapeId()&&t.getCroppingShapeId()===e.id&&t.isIn("select.crop"),[t,e.id]),m=i&&(((C=s==null?void 0:s.props.mimeType)==null?void 0:C.includes("video"))||h),S=fK(e),v=o===c?null:o,y=m?a:c;if(!o&&!(s!=null&&s.props.src))return g.jsxs(Xl,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--color-text-3)",backgroundColor:"var(--color-low)",border:"1px solid var(--color-low-border)"},children:[g.jsx("div",{className:$e("tl-image-container",s&&"tl-image-container-loading"),style:S,children:s?null:g.jsx(uK,{})}),"url"in e.props&&e.props.url&&g.jsx(vh,{url:e.props.url})]});const w=h?"anonymous":void 0;return g.jsxs(g.Fragment,{children:[p&&y&&g.jsx("div",{style:S,children:g.jsx("img",{className:"tl-image",style:{...Ip(e),opacity:.1},crossOrigin:w,src:y,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),g.jsxs(Xl,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[g.jsxs("div",{className:$e("tl-image-container"),style:S,children:[y&&g.jsx("img",{className:"tl-image",style:Ip(e),crossOrigin:w,src:y,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},y),v&&g.jsx("img",{className:"tl-image",style:Ip(e),crossOrigin:w,src:v,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>u(v)},v)]}),e.props.url&&g.jsx(vh,{url:e.props.url})]})]})});function hK(n,e){const t=e?n.getAsset(e):void 0;return t?"mimeType"in t.props&&Zs.isAnimatedImageType(t==null?void 0:t.props.mimeType)||"isAnimated"in t.props&&t.props.isAnimated:!1}function fK(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}=og(n.props,e),o=-t.x*r,i=-t.y*s;return{transform:`translate(${o}px, ${i}px)`,width:r,height:s}}function Ip(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 Eve({shape:n,src:e}){const t=Ou(),r=fK(n),s=n.props.crop;if(r.transform&&s){const{transform:o,width:i,height:a}=r,l=(s.bottomRight.x-s.topLeft.x)*i,c=(s.bottomRight.y-s.topLeft.y)*a,u=[new P(0,0),new P(l,0),new P(l,c),new P(0,c)],h=Ip(n,{width:i,height:a});return g.jsxs(g.Fragment,{children:[g.jsx("defs",{children:g.jsx("clipPath",{id:t,children:g.jsx("polygon",{points:u.map(p=>`${p.x},${p.y}`).join(" ")})})}),g.jsx("g",{clipPath:`url(#${t})`,children:g.jsx("image",{href:e,width:i,height:a,style:h?{...h,transform:`${o} ${h.transform}`}:{transform:o}})})]})}else return g.jsx("image",{href:e,width:n.props.w,height:n.props.h,style:Ip(n,{width:n.props.w,height:n.props.h})})}function pK(n){let e=!1;return{promise:new Promise(r=>{const s=Op();s.onload=()=>{if(e)return;const o=document.createElement("canvas");o.width=s.width,o.height=s.height;const i=o.getContext("2d");i&&(i.drawImage(s,0,0),r(o.toDataURL()))},s.crossOrigin="anonymous",s.src=n}),cancel:()=>e=!0}}function gK(n){return{size:n,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function mK(n,e,t){const r=e.vertices,s=gK(t);return na(r,s)}function Ive(n,e,t){const r=gK(t);return X_(Pv(mK(n,e,t),r),r)}function Tve(n,e,t){const r=Ive(n,e,t);return lT(r)}function _ve(n,e,t){if(n.props.dash==="draw"){const r=mK(n,e,t);return Pu(r)}return e.getSvgPathData()}function yK(n,e,t){let r=`M ${kt(e[0])}L`,s=`M ${kt(e[0])}L`;const o=t/3,i=t*2,a=Bo(n);let l=e[0],c,u=e[0],h;const p=e.length;for(let m=0,S=p-1;m<S;m++){c=e[m+1],h=P.AddXY(e[m+1],a()*o,a()*o);const v=P.Sub(c,l),y=P.Len(v),w=P.Div(v,y).mul(Math.min(y/4,i)),C=P.Add(l,w),T=P.Add(c,w.neg()),E=P.Sub(h,u),_=P.Len(E),A=P.Div(E,_).mul(Math.min(_/4,i)),O=P.Add(u,A),D=P.Add(h,A.neg());m===S-1?(r+=`${kt(C)}L ${kt(c)}`,s+=`${kt(O)}L ${kt(h)}`):(r+=`${kt(C)}L ${kt(T)}Q ${kt(c)}`,s+=`${kt(O)}L ${kt(D)}Q ${kt(h)}`,l=c,u=h)}return[r,r+s]}const Mve=new zo;class mS extends fi{canTabTo(){return!1}hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,t]=Dp(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 ap(e)}getHandles(e){return Mve.get(e.props,()=>{const t=ap(e),r=ip(e),s=r.map(o=>({...o,id:o.index,type:"vertex",canSnap:!0}));for(let o=0;o<r.length-1;o++){const i=Rp(r[o].index,r[o+1].index),l=t.segments[o].midPoint();s.push({id:i,type:"create",index:i,x:l.x,y:l.y,canSnap:!0})}return s.sort(ur)})}onResize(e,t){const{scaleX:r,scaleY:s}=t;return{props:{points:cc(e.props.points,(o,{id:i,index:a,x:l,y:c})=>({id:i,index:a,x:l*r,y:c*s}))}}}onBeforeCreate(e){const{props:{points:t}}=e,r=Object.keys(t);if(r.length<2)return;const s=t[r[0]];if(r.every(i=>{const a=t[i];return a.x===s.x&&a.y===s.y})){const i=r[r.length-1];return t[i]={...t[i],x:t[i].x+.1,y:t[i].y+.1},e}}onHandleDrag(e,{handle:t}){if(t.type!=="vertex")return;const r=lo(new P(t.x,t.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[t.id]:{id:t.id,index:t.index,x:r.x,y:r.y}}}}}component(e){return g.jsx(rc,{style:{minWidth:50,minHeight:50},children:g.jsx(w3,{shape:e})})}indicator(e){const t=Oo[e.props.size]*e.props.scale,r=ap(e),{dash:s}=e.props;let o;if(e.props.spline==="line"){const i=r.points;if(s==="solid"||s==="dotted"||s==="dashed")o="M"+i[0]+"L"+i.slice(1);else{const[a]=yK(e.id,i,t);o=a}}else o=_ve(e,r,t);return g.jsx("path",{d:o})}toSvg(e){return g.jsx(w3,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const t=ip(e);return{points:t,getSelfSnapPoints:r=>{const s=this.getHandles(e).filter(o=>o.type==="vertex").findIndex(o=>o.id===r.id);return t.filter((o,i)=>Math.abs(i-s)>1).map(P.From)},getSelfSnapOutline:r=>{const s=this.getHandles(e).filter(i=>i.type==="vertex").findIndex(i=>i.id===r.id),o=ap(e).segments.filter((i,a)=>a!==s-1&&a!==s);return o.length?new ds({children:o}):null}}}getInterpolatedProps(e,t,r){const s=ip(e),o=ip(t),i=[],a=[];let l=dF;if(s.length>o.length)for(let c=0;c<s.length;c++)i[c]={...s[c]},o[c]===void 0?a[c]={...o[o.length-1],id:l}:a[c]={...o[c],id:l},l=Wi(l);else if(o.length>s.length)for(let c=0;c<o.length;c++)a[c]={...o[c]},s[c]===void 0?i[c]={...s[s.length-1],id:l}:i[c]={...s[c],id:l},l=Wi(l);else for(let c=0;c<o.length;c++)i[c]=s[c],a[c]=o[c];return{...r>.5?t.props:e.props,points:Object.fromEntries(i.map((c,u)=>{const h=a[u];return[c.id,{...c,x:rt(c.x,h.x,r),y:rt(c.y,h.y,r)}]})),scale:rt(e.props.scale,t.props.scale,r)}}}R(mS,"type","line"),R(mS,"props",$5),R(mS,"migrations",U5);function ip(n){return Object.values(n.props.points).sort(ur)}function ap(n){const e=ip(n).map(P.From);switch(n.props.spline){case"cubic":return new kse({points:e});case"line":return new fc({points:e})}}function w3({shape:n,shouldScale:e=!1,forceSolid:t=!1}){const r=Ko(),s=ap(n),{dash:o,color:i,size:a}=n.props,l=1/n.props.scale,c=e?l:1,u=Oo[a]*n.props.scale;if(n.props.spline==="line"){if(o==="solid"){const h=s.points,p="M"+h[0]+"L"+h.slice(1);return g.jsx("path",{d:p,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}if(o==="dashed"||o==="dotted")return g.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:s.segments.map((h,p)=>{const{strokeDasharray:m,strokeDashoffset:S}=t?{strokeDasharray:"none",strokeDashoffset:"none"}:oi(h.length,u,{style:o,start:p>0?"outset":"none",end:p<s.segments.length-1?"outset":"none"});return g.jsx("path",{strokeDasharray:m,strokeDashoffset:S,d:h.getSvgPathData(!0),fill:"none"},p)})});if(o==="draw"){const h=s.points,[p,m]=yK(n.id,h,u);return g.jsx("path",{d:m,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}}if(n.props.spline==="cubic"){const h=s.getSvgPathData();if(o==="solid")return g.jsx("path",{strokeWidth:u,stroke:r[i].solid,fill:"none",d:h,transform:`scale(${c})`});if(o==="dashed"||o==="dotted")return g.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:s.segments.map((p,m)=>{const{strokeDasharray:S,strokeDashoffset:v}=oi(p.length,u,{style:o,start:m>0?"outset":"none",end:m<s.segments.length-1?"outset":"none",forceSolid:t});return g.jsx("path",{strokeDasharray:S,strokeDashoffset:v,d:p.getSvgPathData(),fill:"none"},m)})});if(o==="draw")return g.jsx("path",{d:Tve(n,s,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class yS extends fi{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 xt(t)}}isAspectRatioLocked(){return this.options.resizeMode==="scale"}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",richText:Fo(""),size:"m",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(t){const{labelHeight:r,labelWidth:s}=SK(this.editor,t),{scale:o}=t.props,i=r*o,a=s*o,l=Lt*o,c=By(t);return new ds({children:[new Zi({width:l,height:c,isFilled:!0}),new Zi({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-i:(c-i)/2,width:a,height:i,isFilled:!0,isLabel:!0})]})}getHandles(t){const{scale:r}=t.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const o=this.editor.getZoomLevel();if(o*r<.25)return[];const i=By(t),a=Lt*r,l=Fxe/o*r;return o*r<.5?[{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l}]:[{id:"top",index:"a1",type:"clone",x:a/2,y:-l},{id:"right",index:"a2",type:"clone",x:a+l,y:i/2},{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l},{id:"left",index:"a4",type:"clone",x:-l,y:i/2}]}onResize(t,r){const{resizeMode:s}=this.options;switch(s){case"none":return;case"scale":return Z$(t,r);default:throw xt(s)}}getText(t){return Cu(this.editor,t.props.richText)}getFontFaces(t){return GT(this.editor,t.props.richText,{family:`tldraw_${t.props.font}`,weight:"normal",style:"normal"})}component(t){const{id:r,type:s,props:{labelColor:o,scale:i,color:a,font:l,size:c,align:u,richText:h,verticalAlign:p,fontSizeAdjustment:m}}=t,S=Rve(r),v=Ko(),y=Lt*i,w=By(t),C=se("shape rotation",()=>{var D;return((D=this.editor.getShapePageTransform(r))==null?void 0:D.rotation())??0},[this.editor]),T=se("zoom",()=>this.editor.getZoomLevel()<.35/i,[i,this.editor]),E=se("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),_=t.id===this.editor.getOnlySelectedShapeId(),A=u2(this.editor,t.id),O=ii(h);return g.jsxs(g.Fragment,{children:[g.jsx("div",{id:r,className:"tl-note__container",style:{width:y,height:w,backgroundColor:v[a].note.fill,borderBottom:T?E?`${2*i}px solid rgb(20, 20, 20)`:`${2*i}px solid rgb(144, 144, 144)`:"none",boxShadow:T?"none":Dve(t.id,C,i)},children:(_||A||!O)&&g.jsx(m2,{shapeId:r,type:s,font:l,fontSize:(m||Ua[c])*i,lineHeight:mr.lineHeight,align:u,verticalAlign:p,richText:h,isSelected:_,labelColor:o==="black"?v[a].note.text:v[o].fill,wrap:!0,padding:Zr*i,hasCustomTabBehavior:!0,onKeyDown:S})}),"url"in t.props&&t.props.url&&g.jsx(vh,{url:t.props.url})]})}indicator(t){const{scale:r}=t.props;return g.jsx("rect",{rx:r,width:Q(Lt*r),height:Q(By(t))})}toSvg(t,r){const s=tl({isDarkMode:r.isDarkMode}),o=jve(t),i=g.jsx(y2,{fontSize:t.props.fontSizeAdjustment||Ua[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:o,padding:Zr*t.props.scale});return g.jsxs(g.Fragment,{children:[g.jsx("rect",{x:5,y:5,rx:1,width:Lt-10,height:o.h,fill:"rgba(0,0,0,.1)"}),g.jsx("rect",{rx:1,width:Lt,height:o.h,fill:s[t.props.color].note.fill}),i]})}onBeforeCreate(t){return b3(this.editor,t)}onBeforeUpdate(t,r){if(!(Ih(t.props.richText,r.props.richText)&&t.props.font===r.props.font&&t.props.size===r.props.size))return b3(this.editor,r)}getInterpolatedProps(t,r,s){return{...s>.5?r.props:t.props,scale:rt(t.props.scale,r.props.scale,s)}}}R(yS,"type","note"),R(yS,"props",H5),R(yS,"migrations",K5);function b3(n,e){const{labelHeight:t,fontSizeAdjustment:r}=SK(n,e),s=Math.max(0,t-Lt);if(s!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:s,fontSizeAdjustment:r}}}function Ave(n,e){const{richText:t}=e.props;if(ii(t))return{labelHeight:Ua[e.props.size]*mr.lineHeight+Zr*2,labelWidth:100,fontSizeAdjustment:0};const r=Ua[e.props.size];let s=0,o=0,i=Lt,a=Lt;const l=1;do{s=Math.min(r,r-o);const c=Zx(n,t),u=n.textMeasure.measureHtml(c,{...mr,fontFamily:Xa[e.props.font],fontSize:s,maxWidth:Lt-Zr*2-l,disableOverflowWrapBreaking:!0});if(i=u.h+Zr*2,a=u.w+Zr*2,s<=14){const h=Zx(n,t),p=n.textMeasure.measureHtml(h,{...mr,fontFamily:Xa[e.props.font],fontSize:s,maxWidth:Lt-Zr*2-l});i=p.h+Zr*2,a=p.w+Zr*2;break}if(u.scrollWidth.toFixed(0)===u.w.toFixed(0))break}while(o++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:s}}const Ove=new zo;function SK(n,e){return Ove.get(e,()=>Ave(n,e))}function Rve(n){const e=ne(),t=z8();return k.useCallback(r=>{const s=e.getShape(n);if(!s)return;const o=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(o||i){r.preventDefault();const a=e.getShapePageTransform(n),l=a.rotation(),c=!!(t.dir==="rtl"||jH(Cu(e,s.props.richText))),u=(Lt+e.options.adjacentShapeMargin+(i&&!r.shiftKey?s.props.growY:0))*s.props.scale,h=new P(o?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(Ev.clone().mul(s.props.scale)).rot(l).add(a.point()),p=GH(e,s,h,l);p&&(e.markHistoryStoppingPoint("editing adjacent shape"),yx(e,p,!0))}},[n,e,t.dir])}function By(n){return(Lt+n.props.growY)*n.props.scale}function Dve(n,e,t){const r=Bo(n),s=Math.abs(r())+.5,o=Math.cos(e),i=5*t,a=4*t,l=6*t,c=7*t;return`0px ${i-s}px ${i}px -${i}px rgba(15, 23, 31, .6),
486
+ 0px ${(a+s*c)*Math.max(0,o)}px ${l+s*c}px -${a+s*l}px rgba(15, 23, 31, ${(.3+s*.1).toFixed(2)}),
487
+ 0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+o)/2)).toFixed(2)})`}function jve(n){return new ye(0,0,Lt,Lt+n.props.growY)}const Lve=p0("text size",(n,e)=>(n.fonts.trackFontsForShape(e),xK(n,e.props)),{areRecordsEqual:(n,e)=>n.props===e.props});class SS extends fi{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:Fo("")}}getMinDimensions(t){return Lve.get(this.editor,t.id)}getGeometry(t,r){const{scale:s}=t.props,{width:o,height:i}=this.getMinDimensions(t),a=(r==null?void 0:r.context)??"none";return new Zi({x:(a==="@tldraw/arrow-without-arrowhead"?-this.options.extraArrowHorizontalPadding:0)*s,width:(o+(a==="@tldraw/arrow-without-arrowhead"?this.options.extraArrowHorizontalPadding*2:0))*s,height:i*s,isFilled:!0,isLabel:!0})}getFontFaces(t){return GT(this.editor,t.props.richText,{family:`tldraw_${t.props.font}`,weight:"normal",style:"normal"})}getText(t){return Cu(this.editor,t.props.richText)}canEdit(){return!0}isAspectRatioLocked(){return!0}component(t){const{id:r,props:{font:s,size:o,richText:i,color:a,scale:l,textAlign:c}}=t,{width:u,height:h}=this.getMinDimensions(t),p=t.id===this.editor.getOnlySelectedShapeId(),m=Ko(),S=Nve(r);return g.jsx(m2,{shapeId:r,classNamePrefix:"tl-text-shape",type:"text",font:s,fontSize:yh[o],lineHeight:mr.lineHeight,align:c,verticalAlign:"middle",richText:i,labelColor:m[a].solid,isSelected:p,textWidth:u,textHeight:h,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0,onKeyDown:S})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,s=ne();return t.props.autoSize&&s.getEditingShapeId()===t.id?null:g.jsx("rect",{width:Q(r.width),height:Q(r.height)})}toSvg(t,r){const s=this.editor.getShapeGeometry(t).bounds,o=s.width/(t.props.scale??1),i=s.height/(t.props.scale??1),a=tl(r),l=new ye(0,0,o,i);return g.jsx(y2,{fontSize:yh[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:o,initialShape:i,scaleX:a,handle:l}=r;if(r.mode==="scale_shape"||l!=="right"&&l!=="left")return{id:t.id,type:t.type,...Z$(t,r)};{const c=Math.max(1,Math.abs(o.width*a)),{x:u,y:h}=a<0?P.Sub(s,P.FromAngle(t.rotation).mul(c)):s;return{id:t.id,type:t.type,x:u,y:h,props:{w:c/i.props.scale,autoSize:!1}}}}onEditEnd(t){Cu(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,o=!Ih(t.props.richText,r.props.richText);if(!s&&!o)return;const i=this.getMinDimensions(t),a=xK(this.editor,r.props),l=i.width*t.props.scale,c=i.height*t.props.scale,u=a.width*r.props.scale,h=a.height*r.props.scale;let p;switch(r.props.textAlign){case"middle":{p=new P((u-l)/2,o?0:(h-c)/2);break}case"end":{p=new P(u-l,o?0:(h-c)/2);break}default:{if(o)break;p=new P(0,(h-c)/2);break}}if(p){p.rot(r.rotation);const{x:m,y:S}=r;return{...r,x:m-p.x,y:S-p.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}}}R(SS,"type","text"),R(SS,"props",W5),R(SS,"migrations",V5);function xK(n,e){const{font:t,richText:r,autoSize:s,size:o,w:i}=e,a=s?16:Math.max(16,i),l=yh[o],c=s?null:Math.floor(Math.max(a,i)),u=Zx(n,r),h=n.textMeasure.measureHtml(u,{...mr,fontFamily:Xa[t],fontSize:l,maxWidth:c});return s&&(h.w+=1),{width:Math.max(a,h.w),height:Math.max(l,h.h)}}function Nve(n){const e=ne();return k.useCallback(t=>{if(e.getEditingShapeId()===n)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&e.complete();break}}},[e,n])}const Fve=new zo;class xS extends Rh{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:"",altText:""}}getAriaDescriptor(e){return e.props.altText}component(e){return g.jsx(zve,{shape:e})}indicator(e){return g.jsx("rect",{width:Q(e.props.w),height:Q(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 Fve.get(r,async()=>{const o=await t.resolveAssetUrl(r.id,e.props.w);if(!o)return null;const i=await Zs.loadVideo(o);return await Zs.getVideoFrameAsDataUrl(i,0)});return s?g.jsx("image",{href:s,width:e.props.w,height:e.props.h}):null}}R(xS,"type","video"),R(xS,"props",G5),R(xS,"migrations",q5);const zve=k.memo(function({shape:e}){const t=ne(),r=t.getShapeGeometry(e).bounds.w*t.getZoomLevel()>=110,s=Tg(e.id),o=L8(),{Spinner:i}=Ft(),{asset:a,url:l}=dK({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),c=k.useRef(null),[u,h]=k.useState(!1),[p,m]=k.useState(!1);k.useEffect(()=>{const v=()=>m(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",v),()=>document.removeEventListener("fullscreenchange",v)});const S=k.useCallback(v=>{v.currentTarget&&h(!0)},[]);return k.useEffect(()=>{const v=c.current;v&&s&&document.activeElement!==v&&v.focus()},[s,u]),k.useEffect(()=>{if(o){const v=c.current;if(!v)return;v.pause(),v.currentTime=0}},[c,o]),g.jsxs(g.Fragment,{children:[g.jsx(Xl,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:g.jsx("div",{className:"tl-counter-scaled",children:g.jsx("div",{className:"tl-video-container",children:a?i&&!a.props.src?g.jsx(i,{}):l?g.jsxs(g.Fragment,{children:[g.jsx("video",{ref:c,style:s?{pointerEvents:"all"}:u?void 0:{display:"none"},className:$e("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":p}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:s&&r,onLoadedData:S,hidden:!u,children:g.jsx("source",{src:l})}),!u&&i&&g.jsx(i,{})]}):null:g.jsx(uK,{})})})}),"url"in e.props&&e.props.url&&g.jsx(vh,{url:e.props.url})]})}),vK=[SS,uS,dS,fS,yS,mS,hS,cS,pS,t0,gS,xS];function Bve(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 wK extends Le{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(o=>{if(this.editor.isShapeOrAncestorLocked(o))return!0;if(this.editor.isShapeOfType(o,"group")||this.editor.isShapeOfType(o,"frame")){const i=this.editor.getPointInShapeSpace(o,r);return this.editor.getShapeGeometry(o).bounds.containsPoint(i)}return!1}).map(o=>o.id));const s=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=s.id,this.update()}pushPointToScribble(){const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)}onExit(){this.editor.setErasingShapes([]),this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}update(){const{editor:t,excludedShapeIds:r}=this,s=t.getErasingShapeIds(),o=t.getZoomLevel(),i=t.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=t;this.pushPointToScribble();const c=new Set(s),u=this.editor.options.hitTestMargin/o;for(const h of i){if(t.isShapeOfType(h,"group"))continue;const p=t.getShapeMask(h.id);if(p&&!so(a,p))continue;const m=t.getShapeGeometry(h),S=t.getShapePageTransform(h);if(!m||!S)continue;const v=S.clone().invert(),y=v.applyToPoint(l),w=v.applyToPoint(a),{bounds:C}=m;C.minX-u>Math.max(y.x,w.x)||C.minY-u>Math.max(y.y,w.y)||C.maxX+u<Math.min(y.x,w.x)||C.maxY+u<Math.min(y.y,w.y)||m.hitTestLineSegment(y,w,u)&&c.add(t.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}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(wK,"id","erasing");var hk;let $ve=(hk=class extends Le{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},R(hk,"id","idle"),hk);var fk;let Uve=(fk=class extends Le{onEnter(){const e=this.editor.getZoomLevel(),t=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,s=new Set,o=s.size;for(let i=t.length,a=i-1;a>=0;a--){const 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>o)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(fk,"id","pointing"),fk);class vS extends Le{static children(){return[$ve,Uve,wK]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}R(vS,"id","eraser"),R(vS,"initial","idle"),R(vS,"isLockable",!1);class bK extends Le{constructor(){super(...arguments);R(this,"initialCamera",new P)}onEnter(){this.initialCamera=P.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:t,editor:r}=this,{currentScreenPoint:s,originScreenPoint:o}=r.inputs,i=P.Sub(s,o).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(t.clone().add(i))}complete(){const{editor:t}=this,{pointerVelocity:r}=t.inputs,s=Math.min(r.len(),2);s>.1&&this.editor.slideCamera({speed:s,direction:r}),this.parent.transition("idle")}}R(bK,"id","dragging");var pk;let Hve=(pk=class extends Le{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},R(pk,"id","idle"),pk);var gk;let Kve=(gk=class extends Le{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(gk,"id","pointing"),gk);class wS extends Le{static children(){return[Hve,Kve,bK]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomIn(t,{animation:{duration:220,easing:qn.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:t}=this.editor.inputs;this.editor.zoomOut(t,{animation:{duration:320,easing:qn.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:qn.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:qn.easeOutQuint}})}}}R(wS,"id","hand"),R(wS,"initial","idle"),R(wS,"isLockable",!1);var mk;let Wve=(mk=class extends Le{onCancel(){this.editor.setCurrentTool("select")}onPointerDown(e){this.parent.transition("lasering",e)}},R(mk,"id","idle"),mk);class CK extends Le{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(CK,"id","lasering");class bS extends Le{static children(){return[Wve,CK]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}R(bS,"id","laser"),R(bS,"initial","idle"),R(bS,"isLockable",!1);class PK extends Le{constructor(){super(...arguments);R(this,"info",{});R(this,"initialSelectedShapeIds",[]);R(this,"excludedShapeIds",new Set);R(this,"isWrapMode",!1);R(this,"viewportDidChange",!1);R(this,"initialStartShape",null)}cleanupViewportChangeReactor(){}onEnter(t){const{editor:r}=this,{altKey:s,currentPagePoint:o}=r.inputs;this.isWrapMode=r.user.getIsWrapMode(),this.viewportDidChange=!1;let i=!0;if(this.cleanupViewportChangeReactor=jo("viewport change while brushing",()=>{r.getViewportPageBounds(),!i&&!this.viewportDidChange&&(this.viewportDidChange=!0)}),s){this.parent.transition("scribble_brushing",t);return}this.excludedShapeIds=new Set(r.getCurrentPageShapes().filter(a=>r.isShapeOfType(a,"group")||r.isShapeOrAncestorLocked(a)).map(a=>a.id)),this.info=t,this.initialSelectedShapeIds=r.getSelectedShapeIds().slice(),this.initialStartShape=r.getShapesAtPoint(o)[0],this.hitTestShapes(),i=!1}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null}),this.cleanupViewportChangeReactor()}onTick({elapsed:t}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(t){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",t)}onKeyDown(t){this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:t,excludedShapeIds:r,isWrapMode:s}=this,{inputs:{originPagePoint:o,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=t,c=new Set(a?this.initialSelectedShapeIds:[]),u=s?!l:l,h=ye.FromPoints([o,i]),{corners:p}=h;let m,S,v,y,w,C;const E=t.getViewportPageBounds().contains(h)&&!this.viewportDidChange?t.getCurrentPageRenderingShapesSorted():t.getCurrentPageShapesSorted(),_=t.getCurrentPageId();e:for(let D=0,F=E.length;D<F;D++){if(v=E[D],r.has(v.id)||c.has(v.id)||(y=t.getShapePageBounds(v),!y))continue e;if(h.contains(y)){this.handleHit(v,i,_,c,p);continue e}if(u||t.isShapeOfType(v,"frame"))continue e;if(h.collides(y)){if(w=t.getShapePageTransform(v),!w)continue e;C=w.clone().invert().applyToPoints(p);const U=t.getShapeGeometry(v);t:for(let V=0;V<4;V++)if(m=C[V],S=C[(V+1)%4],U.hitTestLineSegment(m,S,0)){this.handleHit(v,i,_,c,p);break t}}}const A=t.getInstanceState().brush;(!A||!h.equals(A))&&t.updateInstanceState({brush:{...h.toJson()}});const O=t.getSelectedShapeIds();(O.length!==c.size||O.some(D=>!c.has(D)))&&t.setSelectedShapes(Array.from(c))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(t,r,s,o,i){if(t.parentId===s){o.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),l=this.editor.getShapeMask(a.id);l&&!iT(l,i)&&!so(r,l)||o.add(a.id)}}R(PK,"id","brushing");const bh={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 kK extends Le{constructor(){super(...arguments);R(this,"info",{})}updateCursor(){const t=this.editor.getSelectedShapes(),r=bh[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(kK,"id","pointing_resize_handle");class v2 extends Le{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=bh[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){var p;const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t)return;const s=this.editor.getShapeUtil(t.type);if(!s)return;const o=this.editor.inputs.currentPagePoint.clone().sub(r),i=this.editor.inputs.originPagePoint.clone().sub(r),a=o.clone().sub(i).rot(-t.rotation),l=t.props.crop??wve(),c={w:1/(l.bottomRight.x-l.topLeft.x)*t.props.w,h:1/(l.bottomRight.y-l.topLeft.y)*t.props.h},h=(((p=s.onCrop)==null?void 0:p.bind(s))??bve)(t,{handle:this.info.handle,change:a,crop:l,uncroppedSize:c,initialShape:this.snapshot.shape});h&&(this.editor.updateShapes([{id:t.id,type:t.type,...h}]),this.updateCursor())}complete(){this.updateShapes(),Bt(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,s=this.editor.getOnlySelectedShape(),o=this.editor.getSelectionRotatedPageBounds(),i=P.RotWith(o.getHandlePoint(this.info.handle),o.point,t),a=P.Sub(r,i);return{shape:s,cursorHandleOffset:a}}}R(v2,"id","cropping");function w2(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 EK(n,e,t){if(!e)throw Error("Needs to translate a cropped shape!");const{crop:r}=e.props;if(!r)return;const s=n.inputs.shiftKey?Math.abs(t.x)<Math.abs(t.y)?"x":"y":null;s==="x"?t.x=0:s==="y"&&(t.y=0),t.rot(-e.rotation);const{w:o,h:i}=og(e.props,r),a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=en(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-t.x/o)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-t.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:e.id,type:e.type,props:{crop:c}}}var yk;let Vve=(yk=class extends Le{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=w2(this.editor);if(r&&!this.editor.isShapeOfType(r,"group")){this.onPointerDown({...e,shape:r,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(e);break}case"shape":{if(e.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",e);return}else(t=this.editor.getShapeUtil(e.shape))!=null&&t.canCrop(e.shape)?(this.editor.setCroppingShape(e.shape.id),this.editor.setSelectedShapes([e.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",e)):(this.cancel(),this.editor.root.handleEvent(e));break}case"selection":{switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...e,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...e,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}onDoubleClick(e){var o;if(this.editor.inputs.shiftKey||e.phase!=="up")return;const t=this.editor.getCroppingShapeId();if(!t)return;const r=this.editor.getShape(t);if(!r)return;const s=this.editor.getShapeUtil(r);if(s){if(e.target==="selection"){(o=s.onDoubleClickEdge)==null||o.call(s,r,e);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 P(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 P(0,0)))return;r&&s.mul(10);const o=this.editor.getShape(this.editor.getCroppingShapeId());if(!o)return;const i=EK(this.editor,o,s);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},R(yk,"id","idle"),yk);class IK extends Le{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(IK,"id","pointing_crop");class b2 extends Le{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=bh[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(b2,"id","pointing_crop_handle");class TK extends Le{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,o=s.clone().sub(r),i=EK(this.editor,t,o);i&&this.editor.updateShapes([i])}}R(TK,"id","translating_crop");class nI extends Le{constructor(){super(...arguments);R(this,"markId","");R(this,"didExit",!1)}static children(){return[Vve,TK,IK,b2,v2]}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(nI,"id","crop"),R(nI,"initial","idle");class _K extends Le{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:o,handle:i}=t;if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.shapeId=r.id,this.markId="",s)if(o)this.markId=o;else{const c=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);c&&(this.markId=c)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");if(this.initialHandle=en(i),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[i.index]:{id:i.index,index:i.index,x:i.x,y:i.y}}}});const u=this.editor.getShapeHandles(r).find(h=>h.index===i.index);this.initialHandle=en(u)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:s?"cross":"grabbing",rotation:0});const a=this.editor.getShapeHandles(r).sort(ur),l=a.findIndex(c=>c.id===t.handle.id);this.initialAdjacentHandle=null;for(let c=l+1;c<a.length;c++){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==t.handle.id){this.initialAdjacentHandle=u;break}}if(!this.initialAdjacentHandle)for(let c=a.length-1;c>=0;c--){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==t.handle.id){this.initialAdjacentHandle=u;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=zn(this.editor,r)[t.handle.id];this.isPrecise=!1,c&&(this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout())}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),Y_(this.editor),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),Bt(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:o,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.user.getIsSnapMode(),{snaps:c,inputs:{currentPagePoint:u,shiftKey:h,ctrlKey:p,altKey:m,pointerVelocity:S}}=t,v=this.info.shape,y=t.getShape(r);if(!y)return;const w=t.getShapeUtil(y),C=t.isShapeOfType(y,"arrow")?zn(t,y)[o.id]:void 0;let T=u.clone().sub(s).rot(-i).add(o);if(h&&a&&o.id!=="middle"){const D=P.Angle(a,T),U=KS(D,24)-D;T=P.RotWith(T,a,U)}t.snaps.clearIndicators();let E={...o,x:T.x,y:T.y};if(o.canSnap&&(l?!p:p)){if(!t.getShapePageTransform(y.id))throw Error("Expected a page transform");const F=c.handles.snapHandle({currentShapeId:r,handle:E});F&&(F.nudge.rot(-t.getShapeParentTransform(y).rotation()),T.add(F.nudge),E={...o,x:T.x,y:T.y})}const _=(O=w.onHandleDrag)==null?void 0:O.call(w,y,{handle:E,isPrecise:this.isPrecise||m,initial:v}),A={id:y.id,type:y.type,..._};if(o.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const D=zn(t,y)[o.id];D?(C==null?void 0:C.toId)!==D.toId&&(this.pointingId=D.toId,this.isPrecise=S.len()<.5||m,this.isPreciseId=this.isPrecise?D.toId:null,this.resetExactTimeout()):C&&(this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}_&&t.updateShapes([A])}}R(_K,"id","dragging_handle");function MK(n){return n.isLabel?[n]:n instanceof ds?n.children.filter(e=>e.isLabel):[]}class AK extends Le{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"),ja(this.editor),this.editor.select(r)}onExit(){const{editingShapeId:t}=this.editor.getCurrentPageState();t&&(this.editor.setEditingShape(null),ja.cancel(),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":{ja(this.editor);return}}}onPointerDown(t){switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=w2(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 o=this.editor.getShapeUtil(r).getGeometry(r),i=MK(o),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&Cu(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 o=this.editor.getEditingShape(),i=o&&o.id!==r.id;this.editor.setEditingShape(r.id);const a=Tt.isIos||Tt.isAndroid;!a||!i?this.editor.emit("place-caret",{shapeId:r.id,point:t.point}):a&&i&&this.editor.emit("select-all-text",{shapeId:r.id}),ja(this.editor)}onComplete(t){this.parent.transition("idle",t)}onCancel(t){this.parent.transition("idle",t)}}R(AK,"id","editing_shape");function C3(n){const e=n.getOnlySelectedShape();return!!(e&&!n.isShapeOrAncestorLocked(e)&&n.getShapeUtil(e).canCrop(e))}function n0(n,e){const t=n.getSelectedShapeIds(),{currentPagePoint:r}=n.inputs,{shiftKey:s,altKey:o,accelKey:i}=e,a=s||i,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&&!o)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 u;c===l||c.id===n.getFocusedGroupId()||t.includes(c.id)?u=l:u=c,u&&!t.includes(u.id)&&(n.markHistoryStoppingPoint("selecting shape"),n.select(u.id))}}else{if(a)return;{t.length>0&&(n.markHistoryStoppingPoint("selecting none"),n.selectNone());const c=n.getFocusedGroupId();if(Ts(c)){const u=n.getShape(c);n.isPointInShape(u,r,{margin:0,hitInside:!0})||n.setFocusedGroup(null)}}}}const Gve=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Sk;let qve=(Sk=class extends Le{constructor(){super(...arguments);R(this,"selectedShapesOnKeyDown",[])}onEnter(){this.parent.setCurrentToolIdMask(void 0),ja(this.editor),this.selectedShapesOnKeyDown=[],this.editor.setCursor({type:"default",rotation:0})}onExit(){ja.cancel()}onPointerMove(){ja(this.editor)}onPointerDown(t){const r=t.ctrlKey&&C3(this.editor);switch(t.target){case"canvas":{const s=w2(this.editor);if(s&&!s.isLocked){this.onPointerDown({...t,shape:s,target:"shape"});return}const o=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((o.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&P3(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{const{shape:s}=t;if(this.isOverArrowLabelTest(s)){this.parent.transition("pointing_arrow_label",t);break}if(this.editor.isShapeOrAncestorLocked(s)){this.parent.transition("pointing_canvas",t);break}this.parent.transition("pointing_shape",t);break}case"handle":{if(this.editor.getIsReadonly())break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",t):this.parent.transition("pointing_handle",t);break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{if(t.accelKey){this.parent.transition("brushing",t);break}this.parent.transition("pointing_rotate_handle",t);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{if(r)this.parent.transition("crop.pointing_crop_handle",t);else{if(t.accelKey){this.parent.transition("brushing",t);break}this.parent.transition("pointing_resize_handle",t)}break}default:{const s=this.editor.getHoveredShape();if(s&&!this.editor.getSelectedShapeIds().includes(s.id)&&!s.isLocked){this.onPointerDown({...t,shape:s,target:"shape"});return}this.parent.transition("pointing_selection",t)}}break}}}onDoubleClick(t){var r,s,o,i,a;if(!(this.editor.inputs.shiftKey||t.phase!=="up")&&!(t.ctrlKey||t.shiftKey))switch(t.target){case"canvas":{const l=this.editor.getHoveredShape(),c=l&&!this.editor.isShapeOfType(l,"group")?l:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),u=this.editor.getFocusedGroupId();if(c){if(this.editor.isShapeOfType(c,"group")){n0(this.editor,t);return}else{const h=this.editor.getShape(c.parentId);if(h&&this.editor.isShapeOfType(h,"group")&&!(u&&h.id===u)){n0(this.editor,t);return}}this.onDoubleClick({...t,shape:c,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(t);break}case"selection":{if(this.editor.getIsReadonly())break;const l=this.editor.getOnlySelectedShape();if(l){const c=this.editor.getShapeUtil(l);if(!this.canInteractWithShapeInReadOnly(l))return;if(t.handle==="right"||t.handle==="left"||t.handle==="top"||t.handle==="bottom"){const u=(r=c.onDoubleClickEdge)==null?void 0:r.call(c,l,t);if(u){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([u]),Bt(this.editor,[l.id]);return}}if(t.handle==="top_left"||t.handle==="top_right"||t.handle==="bottom_right"||t.handle==="bottom_left"){const u=(s=c.onDoubleClickCorner)==null?void 0:s.call(c,l,t);if(u){this.editor.markHistoryStoppingPoint("double click corner"),this.editor.updateShapes([u]),Bt(this.editor,[l.id]);return}}if(c.canCrop(l)&&!this.editor.isShapeOrAncestorLocked(l)){this.parent.transition("crop",t);return}this.shouldStartEditingShape(l)&&this.startEditingShape(l,t,!0)}break}case"shape":{const{shape:l}=t,c=this.editor.getShapeUtil(l);if(l.type!=="video"&&l.type!=="embed"&&this.editor.getIsReadonly())break;if(c.onDoubleClick){const u=(o=c.onDoubleClick)==null?void 0:o.call(c,l);if(u){this.editor.updateShapes([u]);return}}if(c.canCrop(l)&&!this.editor.isShapeOrAncestorLocked(l)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select((i=t.shape)==null?void 0:i.id),this.parent.transition("crop",t);return}this.shouldStartEditingShape(l)?this.startEditingShape(l,t,!0):this.handleDoubleClickOnCanvas(t);break}case"handle":{if(this.editor.getIsReadonly())break;const{shape:l,handle:c}=t,u=this.editor.getShapeUtil(l),h=(a=u.onDoubleClickHandle)==null?void 0:a.call(u,l,c);h?this.editor.updateShapes([h]):this.shouldStartEditingShape(l)&&this.startEditingShape(l,t,!0)}}}onRightClick(t){switch(t.target){case"canvas":{const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r: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(s){this.onRightClick({...t,shape:s,target:"shape"});return}const o=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((o.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&P3(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:s}=t,o=this.editor.getOutermostSelectableShape(s,i=>!r.includes(i.id));!r.includes(o.id)&&!this.editor.findShapeAncestor(o,i=>r.includes(i.id))&&(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([o.id]));break}}}onCancel(){this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone())}onKeyDown(t){switch(this.selectedShapesOnKeyDown=this.editor.getSelectedShapes(),t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(t.accelKey){t.shiftKey?t.code==="ArrowDown"?this.editor.selectFirstChildShape():t.code==="ArrowUp"&&this.editor.selectParentShape():this.editor.selectAdjacentShape(t.code.replace("Arrow","").toLowerCase());return}this.nudgeSelectedShapes(!1);return}}if(sn.editOnType.get()&&!Gve.includes(t.key)&&!t.altKey&&!t.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...t,target:"shape",shape:r},!0);return}}}onKeyRepeat(t){switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(t.accelKey){this.editor.selectAdjacentShape(t.code.replace("Arrow","").toLowerCase());return}this.nudgeSelectedShapes(!0);break}case"Tab":{this.editor.getSelectedShapes().length&&this.editor.selectAdjacentShape(t.shiftKey?"prev":"next");break}}}onKeyUp(t){switch(t.code){case"Enter":{if(!this.selectedShapesOnKeyDown.length)return;const r=this.editor.getSelectedShapes();if(r.every(o=>this.editor.isShapeOfType(o,"group"))){this.editor.setSelectedShapes(r.flatMap(o=>this.editor.getSortedChildIdsForParent(o.id)));return}const s=this.editor.getOnlySelectedShape();if(s&&this.shouldStartEditingShape(s)){this.startEditingShape(s,{...t,target:"shape",shape:s},!0);return}C3(this.editor)&&this.parent.transition("crop",t);break}case"Tab":{this.editor.getSelectedShapes().length&&this.editor.selectAdjacentShape(t.shiftKey?"prev":"next");break}}}shouldStartEditingShape(t=this.editor.getOnlySelectedShape()){return!t||this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||!this.canInteractWithShapeInReadOnly(t)?!1:this.editor.getShapeUtil(t).canEdit(t)}startEditingShape(t,r,s){this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||(this.editor.markHistoryStoppingPoint("editing shape"),yx(this.editor,t,s),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(t){if(!t)return!1;const r=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(t,"arrow")){const s=this.editor.getShapeGeometry(t).children[1];if(s&&so(r,s.vertices))return!0}return!1}handleDoubleClickOnCanvas(t){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");const r=Nt(),{x:s,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:s,y:o,props:{richText:Fo(""),autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getIsReadonly()&&!a.canEditInReadonly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",t))}nudgeSelectedShapes(t=!1){const{editor:{inputs:{keys:r}}}=this,s=r.has("ShiftLeft"),o=new P(0,0);if(r.has("ArrowLeft")&&(o.x-=1),r.has("ArrowRight")&&(o.x+=1),r.has("ArrowUp")&&(o.y-=1),r.has("ArrowDown")&&(o.y+=1),o.equals(new P(0,0)))return;t||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?s?i*Zve:i:s?Yve:Xve,l=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(l,o.mul(a)),Bt(this.editor,l)}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(t).canEditInReadonly(t))}},R(Sk,"id","idle"),Sk);const Yve=10,Xve=1,Zve=5;function P3(n,e){const t=n.getSelectionRotatedPageBounds();if(!t)return!1;const r=n.getSelectionRotation();return r?so(e,t.corners.map(s=>P.RotWith(s,t.point,r))):t.containsPoint(e)}class OK extends Le{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 P(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(t){const{shape:r}=t;this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.shapeId=r.id,this.didDrag=!1,this.didCtrlOnEnter=t.accelKey,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const o=this.editor.getShapeGeometry(r).children[1];if(!o)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);if(this._labelDragOffset=P.Sub(o.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=this.editor.getShapeUtil("arrow").options,o=xh.get(this.editor,r.id),i=this.editor.getShapePageTransform(r.id),a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint).add(this._labelDragOffset),l=nK(this.editor,r);let c=xh.get(this.editor,r.id).uninterpolateAlongEdge(a);isNaN(c)&&(c=l);const u=i.applyToPoint(o.interpolateAlongEdge(c)),h=i.applyToPoint(o.interpolateAlongEdge(l));P.DistMin(u,h,s.labelCenterSnapDistance/this.editor.getZoomLevel())&&(c=l),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(OK,"id","pointing_arrow_label");class RK extends Le{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){n0(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}R(RK,"id","pointing_canvas");class DK extends Le{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=zn(this.editor,r),o=s[t.handle.id],i=s[t.handle.id==="start"?"end":"start"],a=this.editor.getShapePageTransform(r.id);o&&Cv({editor:this.editor,pointInPageSpace:a.applyToPoint(t.handle),arrow:r,isPrecise:o.props.isPrecise,isExact:t.altKey,currentBinding:o,oppositeBinding:i})}this.editor.setCursor({type:"grabbing",rotation:0})}onExit(){this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})}onPointerUp(){const{shape:t,handle:r}=this.info;if(this.editor.isShapeOfType(t,"note")){const{editor:s}=this,o=k3(s,t,r,!1);if(o){yx(s,o,!0);return}}this.parent.transition("idle",this.info)}onPointerMove(t){const{editor:r}=this;r.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",t):this.startDraggingHandle())}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){const{editor:t}=this;if(t.getIsReadonly())return;const{shape:r,handle:s}=this.info;if(t.isShapeOfType(r,"note")){const o=k3(t,r,s,!0);if(o){const i=t.getPointInParentSpace(o,t.inputs.originPagePoint).sub(P.Rot(Ev.clone().mul(r.props.scale),o.rotation));t.updateShape({...o,x:i.x,y:i.y}),t.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:t.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{yx(t,o,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}R(DK,"id","pointing_handle");function k3(n,e,t,r){const s=n.getShapePageTransform(e.id),o=s.point(),i=s.rotation(),l=WH(n,o,i,e.props.growY*e.props.scale,0,e.props.scale)[t.index];if(l)return GH(n,e,l,i,r)}class jK extends Le{constructor(){super(...arguments);R(this,"info",{})}updateCursor(){this.editor.setCursor({type:bh[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(jK,"id","pointing_rotate_handle");class LK extends Le{constructor(){super(...arguments);R(this,"info",{})}onEnter(t){this.info=t}onPointerUp(t){n0(this.editor,t),this.parent.transition("idle",t)}onPointerMove(t){this.editor.inputs.isDragging&&this.startTranslating(t)}onLongPress(t){this.startTranslating(t)}startTranslating(t){this.editor.getIsReadonly()||this.parent.transition("translating",t)}onDoubleClick(t){var o,i;const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(s){this.parent.transition("idle"),(i=(o=this.parent).onDoubleClick)==null||i.call(o,{...t,target:"shape",shape:this.editor.getShape(s)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}R(LK,"id","pointing_selection");class NK extends Le{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(),o=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i}}=this.editor,{shiftKey:a,altKey:l,accelKey:c}=t;this.hitShape=t.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=c;const u=this.editor.getOutermostSelectableShape(t.shape),h=this.editor.findShapeAncestor(u,p=>r.includes(p.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(t.shape).onClick||u.id===o||r.includes(u.id)||h||r.length>1&&(s!=null&&s.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=u;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(u.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,u.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([u.id]))}onPointerUp(t){var u;const r=this.editor.getSelectedShapeIds(),s=this.editor.getFocusedGroupId(),o=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i}}=this.editor,a=t.shiftKey||t.accelKey,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/o,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const p=(u=h.onClick)==null?void 0:u.call(h,c);if(p){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",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 h=this.editor.getOutermostSelectableShape(l,p=>!r.includes(p.id));if(r.includes(h.id))if(a)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),m=MK(p),S=m.length===1?m[0]:void 0;if(S){const v=this.editor.getPointInShapeSpace(c,i);if(S.bounds.containsPoint(v,0)&&S.hitTestPoint(v)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(c.id);const y=this.editor.getShapeUtil(c);this.editor.getIsReadonly()&&!y.canEditInReadonly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick?this.editor.emit("select-all-text",{shapeId:c.id}):this.editor.emit("place-caret",{shapeId:c.id,point:t.point}))});return}}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c);else if(a){const p=this.editor.getShapeAncestors(h);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(m=>!p.find(S=>S.id===m)),h.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([h.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(NK,"id","pointing_shape");class FK extends Le{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:o={x:0,y:0}}=t;this.info=t,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.creationCursorOffset=o;try{this.snapshot=this._createSnapshot()}catch(i){console.error(i),this.cancel();return}if(this.markId="",r)if(s)this.markId=s;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");r&&this.editor.setCursor({type:"cross",rotation:0}),this.handleResizeStart(),this.updateShapes()}onTick({elapsed:t}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var t,r;if(Bt(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(t=this.info).onCreate)==null||r.call(t,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:s})=>{var a;const o=this.editor.getShapeUtil(s),i=(a=o.onResizeStart)==null?void 0:a.call(o,s);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:s})=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onResizeEnd)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:o,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(o.size===1){const D=[...o.values()][0];this.editor.isShapeOfType(D.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,m=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),S=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:D}=this.editor.getDocumentSettings();m.snapToGrid(D)}const v=this.info.handle,y=E3(v,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%qt===0){const{nudge:D}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:P.Sub(m,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:E3(v,c),isAspectRatioLocked:h,isResizingFromCenter:t});m.add(D)}const C=P.RotWith(t?i.center:i.getHandlePoint(y),i.point,c),T=P.Sub(m,C).rot(-c),E=P.Sub(S,C).rot(-c),_=P.DivV(T,E);Number.isFinite(_.x)||(_.x=1),Number.isFinite(_.y)||(_.y=1);const A=v==="top"||v==="bottom",O=v==="left"||v==="right";h?O?_.y=Math.abs(_.x):A?_.x=Math.abs(_.y):Math.abs(_.x)>Math.abs(_.y)?_.y=Math.abs(_.x)*(_.y<0?-1:1):_.x=Math.abs(_.y)*(_.x<0?-1:1):(A&&(_.x=1),O&&(_.y=1)),this.info.isCreating||this.updateCursor({dragHandle:v,isFlippedX:_.x<0,isFlippedY:_.y<0,rotation:c});for(const D of o.keys()){const F=o.get(D);this.editor.resizeShape(D,_,{initialShape:F.shape,initialBounds:F.bounds,initialPageTransform:F.pageTransform,dragHandle:v,mode:l.length===1&&D===l[0]?"resize_bounds":"scale_shape",scaleOrigin:C,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:D,children:F}of s){if(!F.length)continue;const U=o.get(D).shape,V=this.editor.getShape(D);if(!(U&&V))continue;const Y=V.x-U.x,j=V.y-U.y,N=new P(Y,j).rot(-U.rotation);if(N.x!==0||N.y!==0)for(const z of F)this.editor.updateShape({id:z.id,type:z.type,x:z.x-N.x,y:z.y-N.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:D}of s)if(D.length)for(const F of D)this.editor.updateShape({id:F.id,type:F.type,x:F.x,y:F.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:s,rotation:o}){const i={...this.editor.getInstanceState().cursor};switch(t){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==s&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==s&&(i.type="nwse-resize");break}}i.rotation=o,this.editor.setCursor(i)}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()}_createSnapshot(){const t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:s}}=this.editor,o=this.editor.getSelectionRotatedPageBounds();if(!o)throw Error("Resizing but nothing is selected");const i=P.RotWith(o.getHandlePoint(this.info.handle),o.point,r),a=P.Sub(s,i),l=new Map,c=[];t.forEach(h=>{const p=this.editor.getShape(h);if(p){if(p.type==="frame"&&c.push({id:h,children:st(this.editor.getSortedChildIdsForParent(p).map(m=>this.editor.getShape(m)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&t.length===1)return;this.editor.visitDescendants(p.id,m=>{const S=this.editor.getShape(m);if(S&&(l.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const u=![...l.values()].some(h=>!J5(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:o,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:u,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:de.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(t)}}}R(FK,"id","resizing");const GP=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function E3(n,e){e=e%Dt;const t=Math.round(e/(bt/4)),r=GP.indexOf(n);return GP[(r+t)%GP.length]}const I3=Math.PI/180;class zK extends Le{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=uz({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});Xy({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:bh[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});Xy({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:bh[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(){Xy({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Bt(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{inputs:{shiftKey:r,currentPagePoint:s}}=this.editor,{initialCursorAngle:o,initialShapesRotation:i,initialPageCenter:a}=this.snapshot,l=a.angle(s)-o;let c=i+l;if(r)c=KS(c,24);else if(t&&(c=Math.round(c/I3)*I3,this.editor.getInstanceState().isCoarsePointer)){const u=KS(c,4),h=Vy(c,u);Math.abs(h)<rJ(5)&&(c=u)}return c-i}}R(zK,"id","rotating");class BK extends Le{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:o,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;t&&this.pushPointToScribble();const h=s;let p,m,S,v;const y=0;for(let T=0,E=h.length;T<E;T++){if(p=h[T],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(m=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&m.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const _=r.getShapePageTransform(p);if(!m||!_)continue;const A=_.clone().invert();S=A.applyToPoint(a),v=A.applyToPoint(l);const{bounds:O}=m;if(!(O.minX-y>Math.max(S.x,v.x)||O.minY-y>Math.max(S.y,v.y)||O.maxX+y<Math.min(S.x,v.x)||O.maxY+y<Math.min(S.y,v.y))&&m.hitTestLineSegment(S,v,y)){const D=this.editor.getOutermostSelectableShape(p),F=this.editor.getShapeMask(D.id);if(F&&p4(a,l,F)!==null&&!so(l,F))continue;c.add(D.id)}}const w=r.getSelectedShapeIds(),C=new Set(o?[...c,...u]:[...c]);(w.length!==C.size||w.some(T=>!C.has(T)))&&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(BK,"id","scribble_brushing");var Jve=Object.create,$K=Object.defineProperty,Qve=Object.getOwnPropertyDescriptor,ewe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),UK=n=>{throw TypeError(n)},HK=(n,e,t)=>e in n?$K(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,twe=n=>[,,,Jve(null)],KK=["class","method","getter","setter","accessor","field","value","get","set"],WK=n=>n!==void 0&&typeof n!="function"?UK("Function expected"):n,nwe=(n,e,t,r,s)=>({kind:KK[n],name:e,metadata:r,addInitializer:o=>t._?UK("Already initialized"):s.push(WK(o||null))}),rwe=(n,e)=>HK(e,ewe("metadata"),n[3]),swe=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},owe=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=KK[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,Qve(s,t)),w=r.length-1;w>=0;w--)l=nwe(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,WK(i)&&(y[S]=i);return y&&$K(s,t,y),s},qP=(n,e,t)=>HK(n,typeof e!="symbol"?e+"":e,t),VK,Tv;const iwe=20,awe=100;VK=[Rs];class C2{constructor(e){this.editor=e,swe(Tv,5,this),qP(this,"prevDroppingShapeId",null),qP(this,"droppingNodeTimer",null),qP(this,"first",!0),e.disposables.add(this.dispose)}updateDroppingNode(e,t){var r;this.first&&(this.editor.setHintingShapes(e.map(s=>this.editor.findShapeAncestor(s,o=>o.type!=="group")).filter(s=>s)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,e))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(e,iwe,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,awe,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,u,h,p;t=st(t.map(m=>this.editor.getShape(m.id)));const s=((l=this.editor.getDroppingOverShape(e,t))==null?void 0:l.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(t);return}const{prevDroppingShapeId:o}=this,i=o&&this.editor.getShape(o),a=s&&this.editor.getShape(s);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,t)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,a,t)),this.hintParents(t),r==null||r(),this.prevDroppingShapeId=s}hintParents(e){const t=new Map;for(const s of e){const o=this.editor.findShapeAncestor(s,i=>i.type!=="group");o&&(t.has(o.id)||t.set(o.id,[]),t.get(o.id).push(s.id))}const r=[];for(const[s,o]of t){const i=this.editor.getShape(s);i&&Q7(this.editor,i).length<o.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,s;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),t){const o=this.editor.getShape(t);if(!o)return;(s=(r=this.editor.getShapeUtil(o)).onDropShapesOver)==null||s.call(r,o,e)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}dispose(){this.clear()}}Tv=twe();owe(Tv,1,"dispose",VK,C2);rwe(Tv,C2);var lwe=Object.create,GK=Object.defineProperty,cwe=Object.getOwnPropertyDescriptor,qK=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),YK=n=>{throw TypeError(n)},XK=(n,e,t)=>e in n?GK(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,uwe=n=>[,,,lwe((n==null?void 0:n[qK("metadata")])??null)],ZK=["class","method","getter","setter","accessor","field","value","get","set"],JK=n=>n!==void 0&&typeof n!="function"?YK("Function expected"):n,dwe=(n,e,t,r,s)=>({kind:ZK[n],name:e,metadata:r,addInitializer:o=>t._?YK("Already initialized"):s.push(JK(o||null))}),hwe=(n,e)=>XK(e,qK("metadata"),n[3]),fwe=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},pwe=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=ZK[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,cwe(s,t)),w=r.length-1;w>=0;w--)l=dwe(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,JK(i)&&(y[S]=i);return y&&GK(s,t,y),s},Nl=(n,e,t)=>XK(n,typeof e!="symbol"?e+"":e,t),QK,rI,_v;class Mv extends(rI=Le,QK=[Rs],rI){constructor(){super(...arguments),fwe(_v,5,this),Nl(this,"info",{}),Nl(this,"selectionSnapshot",{}),Nl(this,"snapshot",{}),Nl(this,"markId",""),Nl(this,"isCloning",!1),Nl(this,"isCreating",!1),Nl(this,"dragAndDropManager",new C2(this.editor))}onCreate(e){}onEnter(e){var o;const{isCreating:t=!1,creatingMarkId:r,onCreate:s=()=>{}}=e;if(!((o=this.editor.getSelectedShapeIds())!=null&&o.length)){this.parent.transition("idle");return}if(this.info=e,this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.isCreating=t,this.markId="",t)if(r)this.markId=r;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("translating");if(this.onCreate=s,this.isCloning=!1,this.info=e,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=T3(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=T3(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),Bt(this.editor,this.snapshot.movingShapes.map(t=>t.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(e=this.onCreate)==null||e.call(this,this.editor.getOnlySelectedShape()):this.parent.transition("idle")}cancel(){this.reset(),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.parent.transition("idle",this.info)}handleStart(){const{movingShapes:e}=this.snapshot,t=[];e.forEach(r=>{var i;const s=this.editor.getShapeUtil(r),o=(i=s.onTranslateStart)==null?void 0:i.call(s,r);o&&t.push(o)}),t.length>0&&this.editor.updateShapes(t),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:e}=this.snapshot;if(this.isCloning&&e.length>0){const r=P.Average(e.map(o=>this.editor.getShapePageTransform(o.id).point())),s=P.Sub(r,this.selectionSnapshot.averagePagePoint);P.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(o=>o.id),offset:{x:s.x,y:s.y}}})}const t=[];e.forEach(r=>{var a;const s=this.editor.getShape(r.id),o=this.editor.getShapeUtil(r),i=(a=o.onTranslateEnd)==null?void 0:a.call(o,r,s);i&&t.push(i)}),t.length>0&&this.editor.updateShapes(t)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),gwe({editor:this.editor,snapshot:e});const{movingShapes:t}=e,r=[];t.forEach(s=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onTranslate)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateParentTransforms(){const{editor:e,snapshot:{shapeSnapshots:t}}=this;t.forEach(r=>{const s=e.getShape(r.shape.id);if(!s)return null;const o=Tr(s.parentId)?null:de.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=o})}}_v=uwe(rI);pwe(_v,1,"updateParentTransforms",QK,Mv);hwe(_v,Mv);Nl(Mv,"id","translating");function T3(n){var h;const e=[],t=[],r=n.getSelectedShapeIds(),s=st(r.map(p=>{const m=n.getShape(p);if(!m)return null;e.push(m);const S=n.getShapePageTransform(p),v=S.point(),y=S.rotation();t.push(v);const w=es.isId(m.parentId)?null:de.Inverse(n.getShapePageTransform(m.parentId));return{shape:m,pagePoint:v,pageRotation:y,parentTransform:w}})),o=n.getOnlySelectedShape();let i=[];if(o)i=n.snaps.shapeBounds.getSnapPoints(o.id);else{const p=n.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((m,S)=>({id:"selection:"+S,x:m.x,y:m.y})))}let a,l;const{originPagePoint:c}=n.inputs,u=s.filter(p=>n.isShapeOfType(p.shape,"note")&&n.isPointInShape(p.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const p=n.getCurrentPageShapesSorted();l=(h=u.map(m=>({snapshot:m,index:p.findIndex(S=>S.id===m.shape.id)})).sort((m,S)=>S.index-m.index)[0])==null?void 0:h.snapshot}return l&&(a=VH(n,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:P.Average(t),movingShapes:e,shapeSnapshots:s,initialPageBounds:n.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function gwe({editor:n,snapshot:e}){const{inputs:t}=n,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:o,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=e,c=n.getInstanceState().isGridMode,u=n.getDocumentSettings().gridSize,h=P.Sub(t.currentPagePoint,t.originPagePoint),p=n.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;p==="x"?h.x=0:p==="y"&&(h.y=0),n.snaps.clearIndicators();const m=n.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey;let S=!1;if(m&&n.inputs.pointerVelocity.len()<.5){const{nudge:C}=n.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:o,lockedAxis:p,initialSelectionSnapPoints:i});h.add(C)}else if(r&&s){const{scale:C}=r.shape.props,T=r.pagePoint.clone().add(h).add(Ev.clone().mul(C).rot(r.pageRotation));let E=KH/n.getZoomLevel(),_=new P(0,0);for(const A of s){const O=P.Sub(T,A),D=O.len();D<E&&(S=!0,E=D,_=O)}h.sub(_)}const v=P.Add(l,h),y=n.snaps.getIndicators();c&&!t.ctrlKey&&!S&&y.length===0&&v.snapToGrid(u);const w=P.Sub(v,l);n.updateShapes(st(a.map(({shape:C,pagePoint:T,parentTransform:E})=>{const _=P.Add(T,w),A=E?de.applyToPoint(E,_):_;return{id:C.id,type:C.type,x:A.x,y:A.y}})))}class CS extends Le{constructor(){super(...arguments);R(this,"reactor")}static children(){return[nI,v2,qve,RK,NK,Mv,PK,BK,b2,LK,kK,AK,FK,zK,jK,OK,DK,_K]}cleanUpDuplicateProps(){const t=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const s=new Set(r.duplicateProps.shapeIds);t.length===s.size&&t.every(o=>s.has(o))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=jo("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(CS,"id","select"),R(CS,"initial","idle"),R(CS,"isLockable",!1);class eW extends Le{constructor(){super(...arguments);R(this,"info",{})}onEnter(t){this.info=t}onPointerDown(){this.parent.transition("pointing",this.info)}}R(eW,"id","idle");class tW extends Le{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(tW,"id","pointing");class nW extends Le{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(nW,"id","zoom_brushing");class PS extends Le{constructor(){super(...arguments);R(this,"info",{})}static children(){return[eW,nW,tW]}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(PS,"id","zoom"),R(PS,"initial","idle"),R(PS,"isLockable",!1);const mwe=[vS,wS,bS,PS,CS];function ywe(){const n=ne(),e=se("follow",()=>n.getInstanceState().followingUserId,[n]);return e?g.jsx(Swe,{userId:e}):null}function Swe({userId:n}){const e=b0(n);return e?g.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let sI={fonts:{tldraw_mono:`${An()}/fonts/IBMPlexMono-Medium.woff2`,tldraw_mono_italic:`${An()}/fonts/IBMPlexMono-MediumItalic.woff2`,tldraw_mono_bold:`${An()}/fonts/IBMPlexMono-Bold.woff2`,tldraw_mono_italic_bold:`${An()}/fonts/IBMPlexMono-BoldItalic.woff2`,tldraw_serif:`${An()}/fonts/IBMPlexSerif-Medium.woff2`,tldraw_serif_italic:`${An()}/fonts/IBMPlexSerif-MediumItalic.woff2`,tldraw_serif_bold:`${An()}/fonts/IBMPlexSerif-Bold.woff2`,tldraw_serif_italic_bold:`${An()}/fonts/IBMPlexSerif-BoldItalic.woff2`,tldraw_sans:`${An()}/fonts/IBMPlexSans-Medium.woff2`,tldraw_sans_italic:`${An()}/fonts/IBMPlexSans-MediumItalic.woff2`,tldraw_sans_bold:`${An()}/fonts/IBMPlexSans-Bold.woff2`,tldraw_sans_italic_bold:`${An()}/fonts/IBMPlexSans-BoldItalic.woff2`,tldraw_draw:`${An()}/fonts/Shantell_Sans-Informal_Regular.woff2`,tldraw_draw_italic:`${An()}/fonts/Shantell_Sans-Informal_Regular_Italic.woff2`,tldraw_draw_bold:`${An()}/fonts/Shantell_Sans-Informal_Bold.woff2`,tldraw_draw_italic_bold:`${An()}/fonts/Shantell_Sans-Informal_Bold_Italic.woff2`}};function xwe(n){return k.useMemo(()=>n?{fonts:{...sI.fonts,...n==null?void 0:n.fonts}}:sI,[n])}const vwe=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-arc","arrow-elbow","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bold","bookmark","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","comment","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","help-circle","highlight","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","italic","leading","link","list","lock","manual","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 Nf={...sI,icons:Object.fromEntries(vwe.map(n=>[n,`${An()}/icons/icon/0_merged.svg#${n}`])),translations:Object.fromEntries(Np.map(n=>[n.locale,`${An()}/translations/${n.locale}.json`])),embedIcons:Object.fromEntries($_.map(n=>[n.type,`${An()}/embed-icons/${n.type}.png`]))};function wwe(n){return n?{fonts:Object.assign({...Nf.fonts},{...n==null?void 0:n.fonts}),icons:Object.assign({...Nf.icons},{...n==null?void 0:n.icons}),embedIcons:Object.assign({...Nf.embedIcons},{...n==null?void 0:n.embedIcons}),translations:Object.assign({...Nf.translations},{...n==null?void 0:n.translations})}:Nf}function ku({id:n,children:e,onOpenChange:t,open:r}){const[s,o]=ol(n,t);return g.jsx(T_,{onOpenChange:o,open:r||s,children:g.jsx("div",{className:"tlui-popover",children:e})})}function Eu({children:n}){return g.jsx(__,{asChild:!0,dir:"ltr",children:n})}function Iu({side:n,children:e,align:t="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:o=!1,autoFocusFirstButton:i=!0}){const a=_n(),l=We.useRef(null),c=We.useCallback(()=>{var m;if(!i)return;const p=[...((m=l.current)==null?void 0:m.querySelectorAll("button:not([disabled])"))??[]].filter(S=>S.offsetWidth||S.offsetHeight)[0];p&&p.focus()},[i]);return g.jsx(M_,{container:a,children:g.jsx(A_,{className:"tlui-popover__content",side:n,sideOffset:r,align:t,alignOffset:s,dir:"ltr",ref:l,onOpenAutoFocus:c,onEscapeKeyDown:u=>o&&u.preventDefault(),children:e})})}function bwe(n){return n.getSelectedShapeIds().map(r=>n.getShape(r)).filter(r=>{if(!r)return!1;if(n.isShapeOfType(r,"arrow")){const s=zn(n,r);if(s.start||s.end)return!1}return!0})}const rW=()=>{const n=ne();return se("threeStackableItems",()=>bwe(n).length>2,[n])},il=()=>{const n=ne();return se("isInSelectState",()=>n.isIn("select"),[n])},sW=()=>{const n=ne();return se("allow group",()=>{const e=n.getSelectedShapes();if(e.length<2)return!1;for(const t of e)if(n.isShapeOfType(t,"arrow")){const r=zn(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])},oW=()=>{const n=ne();return se("allowUngroup",()=>n.getSelectedShapeIds().some(e=>{var t;return((t=n.getShape(e))==null?void 0:t.type)==="group"}),[n])},Cwe=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function iW(n,e){const t=ne();return se("selectedShapes",()=>t.getSelectedShapes().length>=n,[t,n,e])}function fs(n,e){const t=ne();return se("selectedShapes",()=>{const r=t.getSelectedShapes().filter(s=>!t.isShapeOrAncestorLocked(s)).length;return n===void 0?r:r>=n},[t])}function Pwe(){const n=ne();return se("showAutoSizeToggle",()=>{const e=n.getSelectedShapes();return e.length===1&&n.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[n])}function aW(){const n=ne();return se("hasLinkShapeSelected",()=>{const e=n.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[n])}function kwe(){const n=ne();return se("onlyFlippableShape",()=>{const e=n.getOnlySelectedShape();return e&&(n.isShapeOfType(e,"group")||n.isShapeOfType(e,"image")||n.isShapeOfType(e,"arrow")||n.isShapeOfType(e,"line")||n.isShapeOfType(e,"draw"))},[n])}function lW(){const n=ne();return se("useCanRedo",()=>n.getCanRedo(),[n])}function cW(){const n=ne();return se("useCanUndo",()=>n.getCanUndo(),[n])}function Ewe(){return g.jsxs(g.Fragment,{children:[g.jsx(Iwe,{}),g.jsx(Twe,{}),g.jsx(_we,{}),g.jsx(Mwe,{}),g.jsx(Awe,{}),g.jsx(Dwe,{}),g.jsx(jwe,{}),g.jsx(Lwe,{})]})}function Iwe(){const n=fs(2),e=il(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"align-left",disabled:!t}),g.jsx(ce,{actionId:"align-center-horizontal",disabled:!t}),g.jsx(ce,{actionId:"align-right",disabled:!t}),g.jsx(ce,{actionId:"stretch-horizontal",disabled:!t}),g.jsx(ce,{actionId:"align-top",disabled:!t}),g.jsx(ce,{actionId:"align-center-vertical",disabled:!t}),g.jsx(ce,{actionId:"align-bottom",disabled:!t}),g.jsx(ce,{actionId:"stretch-vertical",disabled:!t})]})}function Twe(){const n=fs(3),e=il(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"distribute-horizontal",disabled:!t}),g.jsx(ce,{actionId:"distribute-vertical",disabled:!t})]})}function _we(){const n=rW(),e=il(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"stack-horizontal",disabled:!t}),g.jsx(ce,{actionId:"stack-vertical",disabled:!t})]})}function Mwe(){const n=fs(1),e=il(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"send-to-back",disabled:!t}),g.jsx(ce,{actionId:"send-backward",disabled:!t}),g.jsx(ce,{actionId:"bring-forward",disabled:!t}),g.jsx(ce,{actionId:"bring-to-front",disabled:!t})]})}function Awe(){return Ur()<vn.TABLET_SM?g.jsx(Owe,{}):g.jsx(Rwe,{})}function Owe(){const n=ne(),e=se("zoom is 1",()=>n.getZoomLevel()===1,[n]);return g.jsx(ce,{actionId:"zoom-to-100",disabled:e})}function Rwe(){const n=fs(1),e=il(),t=n&&e;return g.jsx(ce,{actionId:"rotate-ccw",disabled:!t})}function Dwe(){const n=fs(1),e=il(),t=n&&e;return g.jsx(ce,{actionId:"rotate-cw",disabled:!t})}function jwe(){const n=aW(),e=il(),t=n&&e;return g.jsx(ce,{actionId:"edit-link",disabled:!t})}function Lwe(){const n=sW(),e=oW();return n?g.jsx(_3,{}):e?g.jsx(Nwe,{}):g.jsx(_3,{})}function _3(){const n=fs(2),e=il(),t=n&&e;return g.jsx(ce,{actionId:"group",disabled:!t})}function Nwe(){return g.jsx(ce,{actionId:"ungroup"})}const Fwe=k.memo(function({children:e}){const t=Ke(),r=Ur(),s=ho(),o=k.useRef(null);rl(o);const i=ne(),a=se("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??g.jsx(Ewe,{});if(!(s&&!a))return g.jsxs(ku,{id:"actions-menu",children:[g.jsx(Eu,{children:g.jsx(Yn,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:g.jsx(lt,{icon:"dots-vertical",small:!0})})}),g.jsx(Iu,{side:r>=vn.TABLET?"bottom":"top",sideOffset:6,children:g.jsx(In,{ref:o,label:t("actions-menu.title"),className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:g.jsx(as,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function uW(){return Pwe()?g.jsx(ce,{actionId:"toggle-auto-size"}):null}function dW(){return aW()?g.jsx(ce,{actionId:"edit-link"}):null}function zwe(){return fs(1)?g.jsx(ce,{actionId:"duplicate"}):null}function hW(){const n=ne();return se("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const r=n.getOnlySelectedShape();return!(r&&n.isShapeOfType(r,"image"))},[n])?g.jsx(ce,{actionId:"flatten-to-image"}):null}function fW(){return sW()?g.jsx(ce,{actionId:"group"}):null}function pW(){return oW()?g.jsx(ce,{actionId:"ungroup"}):null}function gW(){const n=ne();return se("allow unframe",()=>{const t=n.getSelectedShapes();return t.length===0?!1:t.every(r=>n.isShapeOfType(r,"frame"))},[n])?g.jsx(ce,{actionId:"remove-frame"}):null}function mW(){const n=ne();return se("allow fit frame to content",()=>{const t=n.getOnlySelectedShape();return t?n.isShapeOfType(t,"frame")&&n.getSortedChildIdsForParent(t).length>0:!1},[n])?g.jsx(ce,{actionId:"fit-frame-to-content"}):null}function yW(){const n=ne();return se("selected shapes",()=>n.getSelectedShapes().length>0,[n])?g.jsx(ce,{actionId:"toggle-lock"}):null}function P2(){const n=ne(),e=se("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return g.jsx(Ci,{actionId:"toggle-transparent",checked:e,toggle:!0})}function Bwe(){const n=ne(),e=se("any shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsx(ce,{actionId:"unlock-all",disabled:!e})}function SW(){const n=ne(),e=se("zoomed to 100",()=>n.getZoomLevel()===1,[n]);return g.jsx(ce,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function xW(){const n=ne(),e=se("has shapes",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsx(ce,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function vW(){const n=ne(),e=se("has shapes",()=>n.getSelectedShapeIds().length>0,[n]);return g.jsx(ce,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function wW(){return g.jsxs(at,{id:"clipboard",children:[g.jsx(Uwe,{}),g.jsx(Hwe,{}),g.jsx(Kwe,{}),g.jsx(zwe,{}),g.jsx(Wwe,{})]})}function $we(){var t;const n=ne(),e=se("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsxs(Fs,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[g.jsxs(at,{id:"copy-as-group",children:[g.jsx(ce,{actionId:"copy-as-svg"}),!!((t=window.navigator.clipboard)!=null&&t.write)&&g.jsx(ce,{actionId:"copy-as-png"})]}),g.jsx(at,{id:"copy-as-bg",children:g.jsx(P2,{})})]})}function Uwe(){const n=fs(1);return g.jsx(ce,{actionId:"cut",disabled:!n})}function Hwe(){const n=iW(1);return g.jsx(ce,{actionId:"copy",disabled:!n})}function Kwe(){const n=Cwe;return g.jsx(ce,{actionId:"paste",disabled:!n})}function bW(){const n=ne();return se("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n])?g.jsxs(at,{id:"conversions",children:[g.jsx($we,{}),g.jsxs(Fs,{id:"export-as",label:"context-menu.export-as",size:"small",children:[g.jsxs(at,{id:"export-as-group",children:[g.jsx(ce,{actionId:"export-as-svg"}),g.jsx(ce,{actionId:"export-as-png"})]}),g.jsx(at,{id:"export-as-bg",children:g.jsx(P2,{})})]})]}):null}function CW(){const n=ne(),e=se("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return g.jsx(ce,{actionId:"select-all",disabled:!e})}function Wwe(){const n=fs(1);return g.jsx(ce,{actionId:"delete",disabled:!n})}function Vwe(){const n=ho();return!iW(1)||n?null:g.jsxs(Fs,{id:"edit",label:"context-menu.edit",size:"small",children:[g.jsx(fW,{}),g.jsx(pW,{}),g.jsx(hW,{}),g.jsx(dW,{}),g.jsx(mW,{}),g.jsx(gW,{}),g.jsx(kW,{}),g.jsx(PW,{}),g.jsx(uW,{}),g.jsx(yW,{})]})}function Gwe(){const n=fs(2),e=kwe();return ho()||!(n||e)?null:g.jsxs(Fs,{id:"arrange",label:"context-menu.arrange",size:"small",children:[n&&g.jsxs(at,{id:"align",children:[g.jsx(ce,{actionId:"align-left"}),g.jsx(ce,{actionId:"align-center-horizontal"}),g.jsx(ce,{actionId:"align-right"}),g.jsx(ce,{actionId:"align-top"}),g.jsx(ce,{actionId:"align-center-vertical"}),g.jsx(ce,{actionId:"align-bottom"})]}),g.jsx(qwe,{}),n&&g.jsxs(at,{id:"stretch",children:[g.jsx(ce,{actionId:"stretch-horizontal"}),g.jsx(ce,{actionId:"stretch-vertical"})]}),(n||e)&&g.jsxs(at,{id:"flip",children:[g.jsx(ce,{actionId:"flip-horizontal"}),g.jsx(ce,{actionId:"flip-vertical"})]}),g.jsx(Ywe,{})]})}function qwe(){return fs(3)?g.jsxs(at,{id:"distribute",children:[g.jsx(ce,{actionId:"distribute-horizontal"}),g.jsx(ce,{actionId:"distribute-vertical"})]}):null}function Ywe(){const n=fs(2),e=rW();return n?g.jsxs(at,{id:"order",children:[g.jsx(ce,{actionId:"pack"}),e&&g.jsx(ce,{actionId:"stack-horizontal"}),e&&g.jsx(ce,{actionId:"stack-vertical"})]}):null}function Xwe(){const n=ho(),e=fs(1);return n||!e?null:g.jsx(Fs,{id:"reorder",label:"context-menu.reorder",size:"small",children:g.jsxs(at,{id:"reorder",children:[g.jsx(ce,{actionId:"bring-to-front"}),g.jsx(ce,{actionId:"bring-forward"}),g.jsx(ce,{actionId:"send-backward"}),g.jsx(ce,{actionId:"send-to-back"})]})})}function Zwe(){const n=ne(),e=se("pages",()=>n.getPages(),[n]),t=se("current page id",()=>n.getCurrentPageId(),[n]),{addToast:r}=sl(),s=Bn(),o=ho();return!fs(1)||o?null:g.jsxs(Fs,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[g.jsx(at,{id:"pages",children:e.map(a=>g.jsx(Pt,{id:a.id,disabled:t===a.id,label:a.name.length>30?`${a.name.slice(0,30)}…`:a.name,onSelect:()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.moveShapesToPage(n.getSelectedShapeIds(),a.id);const l=n.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{n.markHistoryStoppingPoint("change-page"),n.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),g.jsx(at,{id:"new-page",children:g.jsx(ce,{actionId:"move-to-new-page"})})]})}function PW(){const n=ne();return se("oneEmbedSelected",()=>{const t=n.getOnlySelectedShape();return t?!!(n.isShapeOfType(t,"embed")&&t.props.url&&!n.isShapeOrAncestorLocked(t)):!1},[n])?g.jsx(ce,{actionId:"convert-to-bookmark"}):null}function kW(){const n=ne(),e=U_();return se("oneEmbeddableBookmarkSelected",()=>{const r=n.getOnlySelectedShape();return r?!!(n.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!n.isShapeOrAncestorLocked(r)):!1},[n])?g.jsx(ce,{actionId:"convert-to-embed"}):null}function Jwe(){const n=ne(),e=se("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return g.jsx(Ci,{actionId:"toggle-snap-mode",checked:e})}function Qwe(){const n=ne(),e=se("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return g.jsx(Ci,{actionId:"toggle-tool-lock",checked:e})}function ebe(){const n=ne(),e=se("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return g.jsx(Ci,{actionId:"toggle-grid",checked:e})}function tbe(){const n=ne(),e=se("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return g.jsx(Ci,{actionId:"toggle-wrap-mode",checked:e})}function nbe(){const n=ne(),e=se("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return g.jsx(Ci,{actionId:"toggle-focus-mode",checked:e})}function rbe(){const n=ne(),e=se("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return g.jsx(Ci,{actionId:"toggle-edge-scrolling",checked:e===1})}function sbe(){const n=ne(),e=se("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return g.jsx(Ci,{actionId:"toggle-reduce-motion",checked:e===0})}function obe(){const n=ne(),e=se("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return g.jsx(Ci,{actionId:"toggle-debug-mode",checked:e})}function ibe(){const n=ne(),e=se("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return g.jsx(Ci,{actionId:"toggle-dynamic-size-mode",checked:e})}function abe(){const n=ne(),e=se("paste at cursor",()=>n.user.getIsPasteAtCursorMode(),[n]);return g.jsx(Ci,{actionId:"toggle-paste-at-cursor",checked:e})}function lbe(){const n=ne();return se("show cursor chat",()=>n.getCurrentToolId()==="select"&&!n.getInstanceState().isCoarsePointer,[n])?g.jsx(ce,{actionId:"open-cursor-chat"}):null}function cbe(){const n=ne(),e=vv(),t=se("isSelectToolActive",()=>n.getCurrentToolId()==="select",[n]),r=se("isSinglePageMode",()=>n.options.maxPages<=1,[n]);return t?g.jsxs(g.Fragment,{children:[e&&g.jsx(lbe,{}),g.jsxs(at,{id:"modify",children:[g.jsx(Vwe,{}),g.jsx(Gwe,{}),g.jsx(Xwe,{}),!r&&g.jsx(Zwe,{})]}),g.jsx(wW,{}),g.jsx(bW,{}),g.jsx(at,{id:"select-all",children:g.jsx(CW,{})})]}):null}const ube=k.memo(function({children:e,disabled:t=!1}){const r=ne(),s=Ke(),{Canvas:o}=Ft(),i=k.useCallback(h=>{if(h){if(r.getInstanceState().isCoarsePointer){const p=r.getSelectedShapes(),{inputs:{currentPagePoint:m}}=r,S=r.getShapesAtPoint(m);if(!r.getSelectedShapes().length||!S.some(v=>p.includes(v))){const v=S.filter(y=>r.isShapeOrAncestorLocked(y));v.length&&r.select(...v.map(y=>y.id))}}}else{const p=r.getOnlySelectedShape();p&&r.isShapeOrAncestorLocked(p)&&r.setSelectedShapes([])}},[r]),a=_n(),[l,c]=ol("context menu",i),u=e??g.jsx(cbe,{});return g.jsxs(Rfe,{dir:"ltr",onOpenChange:c,modal:!1,children:[g.jsx(Dfe,{onContextMenu:void 0,dir:"ltr",disabled:t,children:o?g.jsx(o,{}):null}),l&&g.jsx(jfe,{container:a,children:g.jsx(Lfe,{className:"tlui-menu scrollable","data-testid":"context-menu","aria-label":s("context-menu.title"),alignOffset:-4,collisionPadding:4,onContextMenu:nt,children:g.jsx(as,{type:"context-menu",sourceId:"context-menu",children:u})})})]})}),dbe=2e3,hbe=5e3,fbe=tr(function(){const e=ne(),{isChatting:t,chatMessage:r}=e.getInstanceState(),s=k.useRef(-1),[o,i]=k.useState("");return k.useEffect(()=>{if(!t&&r||t){const l=t?hbe:dbe;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(s.current)}},[e,r,t]),t?g.jsx(gbe,{value:o,setValue:i,chatMessage:r}):r.trim()?g.jsx(pbe,{chatMessage:r}):null});function EW(n){const e=ne();k.useLayoutEffect(()=>{var i;if(!n.current)return;const{x:r,y:s}=e.inputs.currentScreenPoint;(i=n.current)==null||i.style.setProperty("transform",`translate(${r}px, ${s}px)`);function o(a){var u;const{minX:l,minY:c}=e.getViewportScreenBounds();(u=n.current)==null||u.style.setProperty("transform",`translate(${a.clientX-l}px, ${a.clientY-c}px)`)}return window.addEventListener("pointermove",o),()=>{window.removeEventListener("pointermove",o)}},[n,e])}const pbe=({chatMessage:n})=>{const e=ne(),t=k.useRef(null);return EW(t),g.jsx("div",{ref:t,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:n})},gbe=tr(function({chatMessage:e,value:t,setValue:r}){const s=ne(),o=Ke(),i=k.useRef(null),a=e||o("cursor-chat.type-to-chat");EW(i),k.useLayoutEffect(()=>{const p=i.current;if(!p)return;const m=s.textMeasure.measureText(t||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});p.style.setProperty("width",m.w+"px")},[s,t,a]),k.useLayoutEffect(()=>{const p=s.timers.requestAnimationFrame(()=>{var m;(m=i.current)==null||m.focus()});return()=>{cancelAnimationFrame(p)}},[s]);const l=k.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=k.useCallback(p=>{const{value:m}=p.target;r(m.slice(0,64)),s.updateInstanceState({chatMessage:m})},[s,r]),u=k.useCallback(p=>{const m=i.current;if(!m)return;const{value:S}=m;switch(p.key){case"Enter":{if(nt(p),p.stopPropagation(),!S){l();return}r("");break}case"Escape":{nt(p),p.stopPropagation(),l();break}}},[l,r]),h=k.useCallback(p=>{p.stopPropagation()},[]);return g.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:l,onChange:c,onKeyDown:u,onPaste:h,value:t,placeholder:a,spellCheck:!1})});function oI({checked:n}){const e=Ke();return g.jsx(Ya,{label:e(n?"ui.checked":"ui.unchecked"),icon:n?"check":"none",className:"tlui-button__icon",small:!0})}function mbe(){const n=ne(),{addToast:e}=sl(),{addDialog:t}=Hg(),[r,s]=We.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(at,{id:"items",children:[g.jsx(Pt,{id:"hard-reset",onSelect:P4,label:"Hard reset"}),g.jsx(Pt,{id:"add-toast",onSelect:()=>{e({id:Mt(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:Mt(),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:Mt(),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:Mt(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),g.jsx(Pt,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:o})=>g.jsx(xbe,{displayDontShowAgain:!0,onCancel:()=>o(),onContinue:()=>o()}),onClose:()=>{}})}}),g.jsx(Pt,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>vbe(n,100)}),g.jsx(Pt,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const o=n.getSelectedShapes(),i=o.length===0?n.getRenderingShapes():o;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),g.jsx(Pt,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"})]}),g.jsxs(at,{id:"flags",children:[g.jsx(ybe,{}),g.jsx(Sbe,{})]})]})}function ybe(){const n=Object.values(sn);return n.length?g.jsx(Fs,{id:"debug flags",label:"Debug Flags",children:g.jsx(at,{id:"debug flags",children:n.map(e=>g.jsx(IW,{flag:e},e.name))})}):null}function Sbe(){const n=Object.values(cJ);return n.length?g.jsx(Fs,{id:"feature flags",label:"Feature Flags",children:g.jsx(at,{id:"feature flags",children:n.map(e=>g.jsx(IW,{flag:e},e.name))})}):null}function xbe({title:n="title",body:e="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,maxWidth:o="350",onCancel:i,onContinue:a}){const[l,c]=We.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(yv,{children:[g.jsx(Sv,{children:n}),g.jsx(xv,{})]}),g.jsx(Qp,{style:{maxWidth:o},children:e}),g.jsxs(B_,{className:"tlui-dialog__footer__actions",children:[s&&g.jsxs(ht,{type:"normal",onClick:()=>c(!l),style:{marginRight:"auto"},children:[g.jsx(oI,{checked:l}),g.jsx(En,{children:"Don’t show again"})]}),g.jsx(ht,{type:"normal",onClick:i,children:g.jsx(En,{children:t})}),g.jsx(ht,{type:"primary",onClick:async()=>a(),children:g.jsx(En,{children:r})})]})]})}const IW=tr(function({flag:e,onChange:t}){const r=e.get();return g.jsx(bv,{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 M3=0;function vbe(n,e){const t=n.options.adjacentShapeMargin,r=Array(e),s=Math.floor(Math.sqrt(e));for(let o=0;o<e;o++)M3++,r[o]={id:Nt("box"+M3),type:"geo",x:o%s*(100+t),y:Math.floor(o/s)*(100+t)};n.run(()=>{n.createShapes(r).setSelectedShapes(r.map(o=>o.id))})}function wbe({children:n}){const e=n??g.jsx(mbe,{});return g.jsxs(W_,{id:"debug",children:[g.jsx(V_,{children:g.jsx(ht,{type:"icon",title:"Debug menu",children:g.jsx(lt,{icon:"dots-horizontal"})})}),g.jsx(G_,{side:"top",align:"end",alignOffset:0,children:g.jsx(as,{type:"menu",sourceId:"debug-panel",children:e})})]})}const bbe=k.memo(function(){const{DebugMenu:e}=vc(),t=k.useRef(null);return rl(t),g.jsxs("footer",{ref:t,className:"tlui-debug-panel",children:[g.jsx(Pbe,{}),g.jsx(kbe,{}),e&&g.jsx(e,{})]})});function Cbe(n=!0){const[e,t]=k.useState(0),r=ne();k.useEffect(()=>{if(!n)return;const s=()=>t(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,n])}const Pbe=tr(function(){Cbe();const e=ne(),t=e.getPath(),r=e.getHoveredShape(),s=e.getOnlySelectedShape(),o=t==="select.idle"||!t.includes("select.")?r:s,i=o&&t.includes("select.")?` / ${o.type||""}${"geo"in o.props?" / "+o.props.geo:""} / [${P.ToInt(e.getPointInShapeSpace(o,e.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${P.ToInt(e.inputs.originPagePoint)}] → [${P.ToInt(e.inputs.currentPagePoint)}] = ${P.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return g.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function kbe(){const n=ne(),e=se("show_fps",()=>sn.showFps.get(),[sn]),t=k.useRef(null);return k.useEffect(()=>{if(!e)return;const r=250;let s=0,o=-1,i=performance.now(),a=0,l=0,c=!1;function u(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>s&&(s=h);const p=s*.75;(h<p&&!c||h>=p&&c)&&(c=!c),t.current.innerHTML=`FPS ${h.toString()}`,t.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}o=n.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(o)}},[e,n]),e?g.jsx("div",{ref:t}):null}const Ebe=k.memo(function(){const e=Ur(),t=Ke(),r=k.useRef(null);rl(r);const{MainMenu:s,QuickActions:o,ActionsMenu:i,PageMenu:a}=vc(),l=ne(),c=se("isSinglePageMode",()=>l.options.maxPages<=1,[l]),u=l.options.actionShortcutsLocation==="menu"?!0:l.options.actionShortcutsLocation==="toolbar"?!1:e>=vn.TABLET;return!s&&!a&&!u?null:g.jsx("nav",{ref:r,className:"tlui-menu-zone",children:g.jsxs("div",{className:"tlui-buttons__horizontal",children:[s&&g.jsx(s,{}),a&&!c&&g.jsx(a,{}),u?g.jsxs(In,{className:"tlui-buttons__horizontal",label:t("actions-menu.title"),children:[o&&g.jsx(o,{}),i&&g.jsx(i,{})]}):null]})})});function Ibe(){const n=ne(),e=Lu(),[t,r]=k.useState(!1),s=k.useRef(!1);return ec("toggle showback to content",()=>{const o=s.current,i=n.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===n.getCulledShapes().size),o!==a&&(r(a),s.current=a)},[n]),t?g.jsx(ce,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Tbe(){const n=ne();return se("is pen mode",()=>n.getInstanceState().isPenMode,[n])?g.jsx(ce,{actionId:"exit-pen-mode"}):null}function _be(){const n=ne(),e=Lu();return se("is following user",()=>!!n.getInstanceState().followingUserId,[n])?g.jsx(Pt,{...e["stop-following"]}):null}function Mbe(){return g.jsxs(g.Fragment,{children:[g.jsx(Tbe,{}),g.jsx(Ibe,{}),g.jsx(_be,{})]})}function Abe({children:n}){const e=n??g.jsx(Mbe,{});return g.jsx("div",{className:"tlui-helper-buttons",children:g.jsx(as,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function Obe(){const n=vv();return g.jsxs(g.Fragment,{children:[g.jsxs(at,{label:"shortcuts-dialog.tools",id:"tools",children:[g.jsx(ce,{actionId:"toggle-tool-lock"}),g.jsx(ce,{actionId:"insert-media"}),g.jsx(Es,{toolId:"select"}),g.jsx(Es,{toolId:"draw"}),g.jsx(Es,{toolId:"eraser"}),g.jsx(Es,{toolId:"hand"}),g.jsx(Es,{toolId:"rectangle"}),g.jsx(Es,{toolId:"ellipse"}),g.jsx(Es,{toolId:"arrow"}),g.jsx(Es,{toolId:"line"}),g.jsx(Es,{toolId:"text"}),g.jsx(Es,{toolId:"frame"}),g.jsx(Es,{toolId:"note"}),g.jsx(Es,{toolId:"laser"}),g.jsx(Pt,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),g.jsxs(at,{label:"shortcuts-dialog.preferences",id:"preferences",children:[g.jsx(ce,{actionId:"toggle-dark-mode"}),g.jsx(ce,{actionId:"toggle-focus-mode"}),g.jsx(ce,{actionId:"toggle-grid"})]}),g.jsxs(at,{label:"shortcuts-dialog.edit",id:"edit",children:[g.jsx(ce,{actionId:"undo"}),g.jsx(ce,{actionId:"redo"}),g.jsx(ce,{actionId:"cut"}),g.jsx(ce,{actionId:"copy"}),g.jsx(ce,{actionId:"paste"}),g.jsx(ce,{actionId:"select-all"}),g.jsx(ce,{actionId:"delete"}),g.jsx(ce,{actionId:"duplicate"})]}),g.jsxs(at,{label:"shortcuts-dialog.view",id:"view",children:[g.jsx(ce,{actionId:"zoom-in"}),g.jsx(ce,{actionId:"zoom-out"}),g.jsx(ce,{actionId:"zoom-to-100"}),g.jsx(ce,{actionId:"zoom-to-fit"}),g.jsx(ce,{actionId:"zoom-to-selection"})]}),g.jsxs(at,{label:"shortcuts-dialog.transform",id:"transform",children:[g.jsx(ce,{actionId:"bring-to-front"}),g.jsx(ce,{actionId:"bring-forward"}),g.jsx(ce,{actionId:"send-backward"}),g.jsx(ce,{actionId:"send-to-back"}),g.jsx(ce,{actionId:"group"}),g.jsx(ce,{actionId:"ungroup"}),g.jsx(ce,{actionId:"flip-horizontal"}),g.jsx(ce,{actionId:"flip-vertical"}),g.jsx(ce,{actionId:"align-top"}),g.jsx(ce,{actionId:"align-center-vertical"}),g.jsx(ce,{actionId:"align-bottom"}),g.jsx(ce,{actionId:"align-left"}),g.jsx(ce,{actionId:"align-center-horizontal"}),g.jsx(ce,{actionId:"align-right"})]}),g.jsxs(at,{label:"shortcuts-dialog.text-formatting",id:"text",children:[g.jsx(Pt,{id:"text-bold",label:"tool.rich-text-bold",kbd:"cmd+b",onSelect:()=>{}}),g.jsx(Pt,{id:"text-italic",label:"tool.rich-text-italic",kbd:"cmd+i",onSelect:()=>{}}),g.jsx(Pt,{id:"text-code",label:"tool.rich-text-code",kbd:"cmd+e",onSelect:()=>{}}),g.jsx(Pt,{id:"text-highlight",label:"tool.rich-text-highlight",kbd:"cmd+shift+h",onSelect:()=>{}}),g.jsx(Pt,{id:"text-strikethrough",label:"tool.rich-text-strikethrough",kbd:"cmd+shift+s",onSelect:()=>{}}),g.jsx(Pt,{id:"text-link",label:"tool.rich-text-link",kbd:"cmd+shift+k",onSelect:()=>{}}),g.jsx(Pt,{id:"text-header",label:"tool.rich-text-header",kbd:"cmd+shift+[[1-6]]",onSelect:()=>{}}),g.jsx(Pt,{id:"text-orderedList",label:"tool.rich-text-orderedList",kbd:"cmd+shift+7",onSelect:()=>{}}),g.jsx(Pt,{id:"text-bulletedlist",label:"tool.rich-text-bulletList",kbd:"cmd+shift+8",onSelect:()=>{}})]}),g.jsxs(at,{label:"shortcuts-dialog.a11y",id:"a11y",children:[g.jsx(Pt,{id:"a11y-select-next-shape",label:"a11y.select-shape",kbd:"[[Tab]]",onSelect:()=>{}}),g.jsx(Pt,{id:"a11y-select-next-shape-direction",label:"a11y.select-shape-direction",kbd:"cmd+↑→↓←",onSelect:()=>{}}),g.jsx(Pt,{id:"a11y-select-next-shape-container",label:"a11y.enter-leave-container",kbd:"cmd+shift+↑→",onSelect:()=>{}}),g.jsx(Pt,{id:"a11y-pan-camera",label:"a11y.pan-camera",kbd:"[[Space]]+↑→↓←",onSelect:()=>{}}),g.jsx(Pt,{id:"adjust-shape-styles",label:"a11y.adjust-shape-styles",kbd:"$+[[Enter]]",onSelect:()=>{}}),g.jsx(Pt,{id:"a11y-move-shape",label:"a11y.move-shape",kbd:"↑→↓←",onSelect:()=>{}}),g.jsx(Pt,{id:"a11y-move-shape-faster",label:"a11y.move-shape-faster",kbd:"shift+↑→↓←",onSelect:()=>{}}),g.jsx(ce,{actionId:"enlarge-shapes"}),g.jsx(ce,{actionId:"shrink-shapes"}),g.jsx(ce,{actionId:"a11y-repeat-shape-announce"})]}),n&&g.jsx(at,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:g.jsx(ce,{actionId:"open-cursor-chat"})})]})}const Rbe=k.memo(function({children:e}){const t=Ke(),r=Ur(),s=e??g.jsx(Obe,{});return g.jsxs(g.Fragment,{children:[g.jsxs(yv,{className:"tlui-shortcuts-dialog__header",children:[g.jsx(Sv,{children:t("shortcuts-dialog.title")}),g.jsx(xv,{})]}),g.jsx(Qp,{className:$e("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=vn.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=vn.TABLET}),children:g.jsx(as,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),g.jsx("div",{className:"tlui-dialog__scrim"})]})});function TW(){const n=Sr(),e=Bn(),t=se("locale",()=>n==null?void 0:n.user.getLocale(),[n]);return n?g.jsx(Fs,{id:"help menu language",label:"menu.language",children:g.jsx(at,{id:"languages",className:"tlui-language-menu",children:Np.map(({locale:r,label:s})=>g.jsx(bv,{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 Dbe(){return g.jsxs(g.Fragment,{children:[g.jsx(TW,{}),g.jsx(_W,{})]})}function _W(){const{KeyboardShortcutsDialog:n}=vc(),{addDialog:e}=Hg(),t=k.useCallback(()=>{n&&e({component:n})},[e,n]);return n?g.jsx(Pt,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:t}):null}function jbe(){return g.jsxs(g.Fragment,{children:[g.jsxs(at,{id:"basic",children:[g.jsx(Nbe,{}),g.jsx($be,{}),g.jsx(Lbe,{}),g.jsx(Ube,{})]}),g.jsx(Hbe,{})]})}function Lbe(){return g.jsxs(Fs,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[g.jsxs(at,{id:"export-all-as-group",children:[g.jsx(ce,{actionId:"export-all-as-svg"}),g.jsx(ce,{actionId:"export-all-as-png"})]}),g.jsx(at,{id:"export-all-as-bg",children:g.jsx(P2,{})})]})}function Nbe(){return g.jsxs(Fs,{id:"edit",label:"menu.edit",children:[g.jsx(Bbe,{}),g.jsx(wW,{}),g.jsx(bW,{}),g.jsx(Fbe,{}),g.jsx(zbe,{}),g.jsx(at,{id:"select-all",children:g.jsx(CW,{})})]})}function Fbe(){return g.jsxs(at,{id:"misc",children:[g.jsx(fW,{}),g.jsx(pW,{}),g.jsx(dW,{}),g.jsx(uW,{}),g.jsx(gW,{}),g.jsx(mW,{}),g.jsx(kW,{}),g.jsx(PW,{}),g.jsx(hW,{})]})}function zbe(){return g.jsxs(at,{id:"lock",children:[g.jsx(yW,{}),g.jsx(Bwe,{})]})}function Bbe(){const n=cW(),e=lW();return g.jsxs(at,{id:"undo-redo",children:[g.jsx(ce,{actionId:"undo",disabled:!n}),g.jsx(ce,{actionId:"redo",disabled:!e})]})}function $be(){return g.jsx(Fs,{id:"view",label:"menu.view",children:g.jsxs(at,{id:"view-actions",children:[g.jsx(ce,{actionId:"zoom-in"}),g.jsx(ce,{actionId:"zoom-out"}),g.jsx(SW,{}),g.jsx(xW,{}),g.jsx(vW,{})]})})}function Ube(){return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"insert-embed"}),g.jsx(ce,{actionId:"insert-media"})]})}function Hbe(){return g.jsxs(at,{id:"preferences",children:[g.jsxs(Fs,{id:"preferences",label:"menu.preferences",children:[g.jsxs(at,{id:"preferences-actions",children:[g.jsx(Jwe,{}),g.jsx(Qwe,{}),g.jsx(ebe,{}),g.jsx(tbe,{}),g.jsx(nbe,{}),g.jsx(rbe,{}),g.jsx(sbe,{}),g.jsx(ibe,{}),g.jsx(abe,{}),g.jsx(obe,{})]}),g.jsx(at,{id:"color-scheme",children:g.jsx(Tme,{})})]}),g.jsx(TW,{}),g.jsx(_W,{})]})}const Kbe=k.memo(function({children:e}){const t=_n(),[r,s]=ol("main menu"),o=Ke(),i=e??g.jsx(jbe,{});return g.jsxs(P_,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[g.jsx(k_,{asChild:!0,dir:"ltr",children:g.jsx(ht,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:g.jsx(lt,{icon:"menu",small:!0})})}),g.jsx(fv,{container:t,children:g.jsx(E_,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:g.jsx(as,{type:"menu",sourceId:"main-menu",children:i})})})]})}),YP={};function Ff(n){if(YP[n])return YP[n];const t=document.createElement("canvas").getContext("2d");t.fillStyle=n,t.fillRect(0,0,1,1);const[r,s,o,i]=t.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,o/255,i/255]);return YP[n]=a,a}const kS=10,MW=4*6*kS+12+4*12;function Nd(n,{center:e,radius:t,numArcSegments:r=20,startAngle:s=0,endAngle:o=Dt,offset:i=0}){const a=(o-s)/r;let l=i;for(let c=s;c<o;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 Fd(n,e,t,r,s,o){n[e++]=t,n[e++]=r,n[e++]=t,n[e++]=r+o,n[e++]=t+s,n[e++]=r,n[e++]=t+s,n[e++]=r,n[e++]=t,n[e++]=r+o,n[e++]=t+s,n[e++]=r+o}function Wbe(n,e,t){const r=kS;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 Nd(n,{center:e.center,radius:t,numArcSegments:kS*4}),kS*4*6;let o=0;return Fd(n,o,s.minX,s.minY,s.w,s.h),o+=12,Fd(n,o,s.minX,e.minY,s.w,t),o+=12,Fd(n,o,s.maxX,s.minY,t,s.h),o+=12,Fd(n,o,s.minX,s.maxY,s.w,t),o+=12,Fd(n,o,e.minX,s.minY,t,s.h),o+=12,Nd(n,{numArcSegments:r,offset:o,center:s.point,radius:t,startAngle:bt,endAngle:bt*1.5}),o+=r*6,Nd(n,{numArcSegments:r,offset:o,center:P.Add(s.point,new P(s.w,0)),radius:t,startAngle:bt*1.5,endAngle:Dt}),o+=r*6,Nd(n,{numArcSegments:r,offset:o,center:P.Add(s.point,s.size),radius:t,startAngle:0,endAngle:qt}),o+=r*6,Nd(n,{numArcSegments:r,offset:o,center:P.Add(s.point,new P(0,s.h)),radius:t,startAngle:qt,endAngle:bt}),MW}function Vbe(n){if(!n)throw new Error("Canvas element not found");const e=n.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const t=`#version 300 es
488
+ precision mediump float;
489
+
490
+ in vec2 shapeVertexPosition;
491
+
492
+ uniform vec4 canvasPageBounds;
493
+
494
+ // taken (with thanks) from
495
+ // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
496
+ void main() {
497
+ // convert the position from pixels to 0.0 to 1.0
498
+ vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
499
+
500
+ // convert from 0->1 to 0->2
501
+ vec2 zeroToTwo = zeroToOne * 2.0;
502
+
503
+ // convert from 0->2 to -1->+1 (clipspace)
504
+ vec2 clipSpace = zeroToTwo - 1.0;
505
+
506
+ gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
507
+ }`,r=e.createShader(e.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(e.shaderSource(r,t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const s=`#version 300 es
508
+ precision mediump float;
509
+
510
+ uniform vec4 fillColor;
511
+ out vec4 outputColor;
512
+
513
+ void main() {
514
+ outputColor = fillColor;
515
+ }`,o=e.createShader(e.FRAGMENT_SHADER);if(!o)throw new Error("Failed to create fragment shader");if(e.shaderSource(o,s),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=e.createProgram();if(!i)throw new Error("Failed to create program");if(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:$y(e,1024),unselectedShapes:$y(e,4096),viewport:$y(e,MW),collaborators:$y(e,1024),prepareTriangles(p,m){e.bindBuffer(e.ARRAY_BUFFER,p.buffer),e.bufferData(e.ARRAY_BUFFER,p.vertices,e.STATIC_DRAW,0,m),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(p){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,p/2),e.disable(e.BLEND)},drawTriangles(p){e.drawArrays(e.TRIANGLES,0,p/2)},setFillColor(p){e.uniform4fv(c,p)},setCanvasPageBounds(p){e.uniform4fv(l,p)}}}function $y(n,e){const t=n.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(e)}}function A3(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 Gbe=Object.create,AW=Object.defineProperty,qbe=Object.getOwnPropertyDescriptor,Ybe=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),OW=n=>{throw TypeError(n)},RW=(n,e,t)=>e in n?AW(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Xbe=n=>[,,,Gbe(null)],DW=["class","method","getter","setter","accessor","field","value","get","set"],jW=n=>n!==void 0&&typeof n!="function"?OW("Function expected"):n,Zbe=(n,e,t,r,s)=>({kind:DW[n],name:e,metadata:r,addInitializer:o=>t._?OW("Already initialized"):s.push(jW(o||null))}),Jbe=(n,e)=>RW(e,Ybe("metadata"),n[3]),Qbe=(n,e,t,r)=>{for(var s=0,o=n[e>>1],i=o&&o.length;s<i;s++)o[s].call(t);return r},ia=(n,e,t,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,p=!1,m=2,S=DW[u+5],v=n[m]||(n[m]=[]),y=(s=s.prototype,qbe(s,t)),w=r.length-1;w>=0;w--)l=Zbe(u,t,a={},n[3],v),l.static=h,l.private=p,c=l.access={has:C=>t in C},c.get=C=>C[t],i=(0,r[w])(y[S],l),a._=1,jW(i)&&(y[S]=i);return y&&AW(s,t,y),s},Pa=(n,e,t)=>RW(n,typeof e!="symbol"?e+"":e,t),LW,NW,FW,zW,BW,$W,UW,HW,KW,WW,fo;WW=[Rs],KW=[le],HW=[le],UW=[le],$W=[le],BW=[le],zW=[le],FW=[le],NW=[le],LW=[Rs];class Wo{constructor(e,t,r){this.editor=e,this.elem=t,this.container=r,Qbe(fo,5,this),Pa(this,"disposables",[]),Pa(this,"gl"),Pa(this,"shapeGeometryCache"),Pa(this,"colors"),Pa(this,"id",Mt()),Pa(this,"canvasBoundingClientRect",hn("canvasBoundingClientRect",new ye)),Pa(this,"originPagePoint",new P),Pa(this,"originPageCenter",new P),Pa(this,"isInViewport",!1),this.gl=Vbe(t),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",s=>{const o=e.getShapeMaskedPageBounds(s.id);if(!o)return null;const i=new Float32Array(12);return Fd(i,0,o.x,o.y,o.w,o.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),jo("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Ff(e.getPropertyValue("--color-text-3").trim()),selectFill:Ff(e.getPropertyValue("--color-selected").trim()),viewportFill:Ff(e.getPropertyValue("--color-muted-1").trim()),background:Ff(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 P(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 P(e.width*t,e.height*t)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const e=this.getCanvasScreenBounds(),t=this.getContentPageBounds(),r=e.width/e.height;let s=t.width,o=s/r;o<t.height&&(o=t.height,s=o*r);const i=new ye(0,0,s,o);return i.center=t.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:t,w:r,h:s}=this.getCanvasPageBounds();return new Float32Array([e,t,r,s])}getMinimapPagePoint(e,t){const r=this.getCanvasPageBounds(),s=this.getCanvasScreenBounds();let o=e-s.x,i=t-s.y;return o*=r.width/s.width,i*=r.height/s.height,o+=r.minX,i+=r.minY,new P(o,i,1)}minimapScreenPointToPagePoint(e,t,r=!1,s=!1){const{editor:o}=this,i=o.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,t);if(s){const c=this.editor.getCurrentPageBounds()??new ye,u=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,m=c.maxY+i.height/2,S=Math.max(0,u+i.width-a),v=Math.max(0,-(h-i.width-a)),y=Math.max(0,p+i.height-l),w=Math.max(0,-(m-i.height-l));a+=(S-v)/2,l+=(y-w)/2,a=$t(a,u,h),l=$t(l,p,m)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new P(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 o=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const p=h.length;r.has(u)?(A3(this.gl.selectedShapes,o,h),o+=p):(A3(this.gl.unselectedShapes,i,h),i+=p)}this.drawShapes(this.gl.unselectedShapes,i,s.shapeFill),this.drawShapes(this.gl.selectedShapes,o,s.selectFill),this.drawViewport(),this.drawCollaborators()}drawShapes(e,t,r){this.gl.prepareTriangles(e,t),this.gl.setFillColor(r),this.gl.drawTriangles(t)}drawViewport(){const e=this.editor.getViewportPageBounds(),t=Wbe(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),Tt.isSafari&&(this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t))}drawCollaborators(){const e=this.editor.getCollaboratorsOnCurrentPage();if(!e.length)return;const t=20,r=t*6,s=r*e.length;this.gl.collaborators.vertices.length<s&&(this.gl.collaborators.vertices=new Float32Array(s));const o=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:l}of e)l&&(Nd(o,{center:P.From(l),radius:3*a,offset:i,numArcSegments:t}),i+=r);this.gl.prepareTriangles(this.gl.collaborators,s),i=0;for(const{color:l}of e)this.gl.setFillColor(Ff(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}fo=Xbe();ia(fo,1,"close",WW,Wo);ia(fo,1,"getDpr",KW,Wo);ia(fo,1,"getContentPageBounds",HW,Wo);ia(fo,1,"getContentScreenBounds",UW,Wo);ia(fo,1,"getCanvasSize",$W,Wo);ia(fo,1,"getCanvasClientPosition",BW,Wo);ia(fo,1,"getCanvasPageBounds",zW,Wo);ia(fo,1,"getZoom",FW,Wo);ia(fo,1,"getCanvasPageBoundsArray",NW,Wo);ia(fo,1,"render",LW,Wo);Jbe(fo,Wo);function e1e(){const n=ne(),e=_n(),t=Ke(),r=k.useRef(null),s=k.useRef(!1),o=k.useRef();k.useEffect(()=>{try{const h=new Wo(n,r.current,e);return o.current=h,o.current.close}catch(h){n.annotateError(h,{origin:"minimap",willCrashApp:!1}),n.timers.setTimeout(()=>{throw h})}},[n,e]);const i=k.useCallback(h=>{if(!n.getCurrentPageShapeIds().size||!o.current)return;const p=o.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!1),m=o.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!0);o.current.originPagePoint.setTo(m),o.current.originPageCenter.setTo(n.getViewportPageBounds().center),n.centerOnPoint(p,{animation:{duration:n.options.animationMediumMs}})},[n]),a=k.useCallback(h=>{if(!o.current)return;const p=h.currentTarget;if(Sg(p,h),!n.getCurrentPageShapeIds().size)return;s.current=!0,o.current.isInViewport=!1;const m=o.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!1),S=n.getViewportPageBounds(),v=o.current.getContentPageBounds();if(new ye(v.x-S.width/2,v.y-S.height/2,v.width+S.width,v.height+S.height).containsPoint(m)&&!S.containsPoint(m)){o.current.isInViewport=S.containsPoint(m);const C=P.Sub(S.center,S.point),T=P.Add(m,C);o.current.originPagePoint.setTo(T),o.current.originPageCenter.setTo(m),n.centerOnPoint(m,{animation:{duration:n.options.animationMediumMs}})}else{const C=o.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,!1,!0);o.current.isInViewport=S.containsPoint(C),o.current.originPagePoint.setTo(C),o.current.originPageCenter.setTo(S.center)}function w(C){p&&xg(p,C),s.current=!1,document.body.removeEventListener("pointerup",w)}document.body.addEventListener("pointerup",w)},[n]),l=k.useCallback(h=>{if(!o.current)return;const p=o.current.minimapScreenPointToPagePoint(h.clientX,h.clientY,h.shiftKey,!0);if(s.current){if(o.current.isInViewport){const y=o.current.originPagePoint.clone().sub(o.current.originPageCenter);n.centerOnPoint(P.Sub(p,y));return}n.centerOnPoint(p)}const m=o.current.getMinimapPagePoint(h.clientX,h.clientY),S=n.pageToScreen(m),v={type:"pointer",target:"canvas",name:"pointer_move",...Js(h),point:S,isPen:n.getInstanceState().isPenMode};n.dispatch(v)},[n]),c=k.useCallback(h=>{const p=d4(h);n.dispatch({type:"wheel",name:"wheel",delta:p,point:new P(h.clientX,h.clientY),shiftKey:h.shiftKey,altKey:h.altKey,ctrlKey:h.metaKey||h.ctrlKey,metaKey:h.metaKey,accelKey:pr(h)})},[n]),u=Ig();return k.useEffect(()=>{n.timers.setTimeout(()=>{var h,p;(h=o.current)==null||h.updateColors(),(p=o.current)==null||p.render()})},[u,n]),g.jsx("div",{className:"tlui-minimap",children:g.jsx("canvas",{role:"img","aria-label":t("navigation-zone.minimap"),ref:r,className:"tlui-minimap__canvas",onDoubleClick:i,onPointerMove:l,onPointerDown:a,onWheelCapture:c})})}function t1e(n,e){const[t,r]=We.useState(e);We.useLayoutEffect(()=>{const o=gI(n);if(o)try{r(JSON.parse(o))}catch{console.error(`Could not restore value ${n} from local storage.`)}},[n]);const s=We.useCallback(o=>{r(i=>{const a=typeof o=="function"?o(i):o;return mI(n,JSON.stringify(a)),a})},[n]);return[t,s]}const n1e=k.memo(function(){const e=Lu(),t=Ke(),r=Ur(),s=k.useRef(null);rl(s);const[o,i]=t1e("minimap",!0),a=k.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=vc();return r<vn.MOBILE?null:g.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[g.jsx(In,{className:"tlui-buttons__horizontal",label:t("navigation-zone.title"),children:l&&r<vn.TABLET?g.jsx(l,{}):g.jsxs(g.Fragment,{children:[!o&&g.jsx(Yn,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(eg(e["zoom-out"].label))} ${RE(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:g.jsx(lt,{icon:"minus"})}),l&&g.jsx(l,{},"zoom-menu"),!o&&g.jsx(Yn,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(eg(e["zoom-in"].label))} ${RE(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:g.jsx(lt,{icon:"plus"})}),c&&g.jsx(Yn,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:g.jsx(lt,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=vn.TABLET&&!o&&g.jsx(c,{})]})}),r1e=function({name:e,id:t,isCurrentPage:r,onCancel:s,onComplete:o}){const i=ne(),a=Bn(),l=k.useRef(null),c=k.useRef(null),u=k.useCallback(()=>{c.current=i.markHistoryStoppingPoint("rename page")},[i]),h=k.useCallback(m=>{i.renamePage(t,m||"New Page"),a("rename-page",{source:"page-menu"})},[i,t,a]),p=k.useCallback(()=>{c.current&&i.bailToMark(c.current),s()},[i,s]);return g.jsx(Ug,{className:"tlui-page-menu__item__input",ref:m=>l.current=m,defaultValue:e,onValueChange:h,onComplete:o,onCancel:p,onFocus:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},iI=(n,e,t,r,s)=>{let o;const i=n.getPages(),a=t>r?i[r-1]:i[r],l=t>r?i[r]:i[r+1];a&&!l?o=Wi(a.index):!a&&l?o=Cq(i[0].index):o=Rp(a.index,l.index),o!==i[t].index&&(n.markHistoryStoppingPoint("moving page"),n.updatePage({id:e,index:o}),s("move-page",{source:"page-menu"}))},O3=tr(function({index:e,listSize:t,item:r,onRename:s}){const o=ne(),i=Ke(),a=o.getPages(),l=Bn(),c=k.useCallback(()=>{o.markHistoryStoppingPoint("creating page");const m=es.createId();o.duplicatePage(r.id,m),l("duplicate-page",{source:"page-menu"})},[o,r,l]),u=k.useCallback(()=>{iI(o,r.id,e,e-1,l)},[o,r,e,l]),h=k.useCallback(()=>{iI(o,r.id,e,e+1,l)},[o,r,e,l]),p=k.useCallback(()=>{o.markHistoryStoppingPoint("deleting page"),o.deletePage(r.id),l("delete-page",{source:"page-menu"})},[o,r,l]);return g.jsxs(W_,{id:`page item submenu ${e}`,children:[g.jsx(V_,{children:g.jsx(ht,{type:"icon",title:i("page-menu.submenu.title"),children:g.jsx(lt,{icon:"dots-vertical",small:!0})})}),g.jsx(G_,{alignOffset:0,side:"right",sideOffset:-4,children:g.jsxs(as,{type:"menu",sourceId:"page-menu",children:[g.jsxs(at,{id:"modify",children:[s&&g.jsx(Pt,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),g.jsx(Pt,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=o.options.maxPages}),e>0&&g.jsx(Pt,{id:"move-up",onSelect:u,label:"page-menu.submenu.move-up"}),e<t-1&&g.jsx(Pt,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),t>1&&g.jsx(at,{id:"delete",children:g.jsx(Pt,{id:"delete",onSelect:p,label:"page-menu.submenu.delete"})})]})})]})}),s1e=k.memo(function(){const e=ne(),t=Bn(),r=Ke(),s=Ur(),o=k.useCallback(()=>w(!1),[]),[i,a]=ol("page-menu",o),l=36,c=k.useRef(null),u=se("pages",()=>e.getPages(),[e]),h=se("currentPage",()=>e.getCurrentPage(),[e]),p=se("currentPageId",()=>e.getCurrentPageId(),[e]),m=ho(),S=se("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),v=se("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[y,w]=k.useState(!1),C=k.useCallback(()=>{m||w(j=>!j)},[m]),T=k.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[E,_]=k.useState(Object.fromEntries(u.map((j,N)=>[j.id,{y:N*l,offsetY:0,isSelected:!1}])));k.useLayoutEffect(()=>{_(Object.fromEntries(u.map((j,N)=>[j.id,{y:N*l,offsetY:0,isSelected:!1}])))},[l,u]),k.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const j=document.querySelector(`[data-testid="page-menu-item-${p}"]`);if(j){const N=c.current;if(!N)return;const z=j.offsetTop,G=N.scrollTop;z<G&&N.scrollTo({top:z});const q=z+l,$=N.scrollTop+N.offsetHeight;q>$&&N.scrollTo({top:q-N.offsetHeight})}})},[l,p,i,e]);const A=k.useCallback(j=>{const{clientY:N,currentTarget:z}=j,{dataset:{id:G,index:q}}=z;if(!G||!q)return;const $=T.current;Sg(j.currentTarget,j),$.status="pointing",$.pointing={id:G,index:+q};const J=E[G].y;$.startY=N,$.startIndex=Math.max(0,Math.min(Math.round(J/l),u.length-1))},[l,u.length,E]),O=k.useCallback(j=>{const N=T.current;if(N.status==="pointing"){const{clientY:z}=j,G=z-N.startY;Math.abs(G)>5&&(N.status="dragging")}if(N.status==="dragging"){const{clientY:z}=j,G=z-N.startY,q=E[N.pointing.id],{startIndex:$,pointing:K}=N,J=q.y+G,H=Math.max(0,Math.min(Math.round(J/l),u.length-1)),te={...E};if(te[K.id]={y:q.y,offsetY:G,isSelected:!0},H!==N.dragIndex){N.dragIndex=H;for(let he=0;he<u.length;he++){const Pe=u[he];if(Pe.id===N.pointing.id)continue;let{y:ue}=te[Pe.id];H===$?ue=he*l:H<$?H<=he&&he<$?ue=(he+1)*l:ue=he*l:H>$&&(H>=he&&he>$?ue=(he-1)*l:ue=he*l),ue!==te[Pe.id].y&&(te[Pe.id]={y:ue,offsetY:0,isSelected:!0})}}_(te)}},[l,u,E]),D=k.useCallback(j=>{const N=T.current;if(N.status==="dragging"){const{id:z,index:G}=N.pointing;iI(e,z,G,N.dragIndex,t)}xg(j.currentTarget,j),N.status="idle"},[e,t]),F=k.useCallback(j=>{const N=T.current;j.key==="Escape"&&(N.status==="dragging"&&_(Object.fromEntries(u.map((z,G)=>[z.id,{y:G*l,offsetY:0,isSelected:!1}]))),N.status="idle")},[l,u]),U=k.useCallback(()=>{m||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const j=es.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:j}),e.setCurrentPage(j),w(!0)}),t("new-page",{source:"page-menu"}))},[e,r,m,t]),V=k.useCallback(j=>{e.setCurrentPage(j),t("change-page",{source:"page-menu"})},[e,t]),Y=k.useCallback((j,N)=>{e.renamePage(j,N),t("rename-page",{source:"page-menu"})},[e,t]);return g.jsxs(ku,{id:"pages",onOpenChange:a,open:i,children:[g.jsx(Eu,{"data-testid":"main.page-menu",children:g.jsxs(ht,{type:"menu",title:h.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[g.jsx("div",{className:"tlui-page-menu__name",children:h.name}),g.jsx(lt,{icon:"chevron-down",small:!0})]})}),g.jsx(Iu,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:y,children:g.jsxs("div",{className:"tlui-page-menu__wrapper",children:[g.jsxs("div",{className:"tlui-page-menu__header",children:[g.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!m&&g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsx(ht,{type:"icon","data-testid":"page-menu.edit",title:r(y?"page-menu.edit-done":"page-menu.edit-start"),onClick:C,children:g.jsx(lt,{icon:y?"check":"edit"})}),g.jsx(ht,{type:"icon","data-testid":"page-menu.create",title:r(S?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:S,onClick:U,children:g.jsx(lt,{icon:"plus"})})]})]}),g.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((j,N)=>{const z=E[j.id]??{offsetY:0};return y?g.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:j.id===h.id?888:N,transform:`translate(0px, ${z.y+z.offsetY}px)`},children:[g.jsx(ht,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:A,onPointerUp:D,onPointerMove:O,onKeyDown:F,"data-id":j.id,"data-index":N,children:g.jsx(lt,{icon:"drag-handle-dots"})}),s<vn.TABLET_SM&&v?g.jsxs(ht,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const G=window.prompt("Rename page",j.name);G&&G!==j.name&&Y(j.id,G)},onDoubleClick:C,children:[g.jsx(oI,{checked:j.id===h.id}),g.jsx(En,{children:j.name})]}):g.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:g.jsx(r1e,{id:j.id,name:j.name,isCurrentPage:j.id===h.id,onComplete:()=>{w(!1),e.menus.clearOpenMenus()},onCancel:()=>{w(!1),e.menus.clearOpenMenus()}})}),!m&&g.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":y,children:g.jsx(O3,{index:N,item:j,listSize:u.length})})]},j.id+"_editing"):g.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[g.jsxs(ht,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>V(j.id),onDoubleClick:C,title:r("page-menu.go-to-page"),children:[g.jsx(oI,{checked:j.id===h.id}),g.jsx(En,{children:j.name})]}),!m&&g.jsx("div",{className:"tlui-page_menu__item__submenu",children:g.jsx(O3,{index:N,item:j,listSize:u.length,onRename:()=>{if(Tt.isIos){const G=window.prompt("Rename page",j.name);G&&G!==j.name&&Y(j.id,G)}else w(!0),p!==j.id&&V(j.id)}})})]},j.id)})})]})})]})});function o1e(){const n=ne(),e=ho(),t=se("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(e&&!t))return g.jsxs(g.Fragment,{children:[g.jsx(a1e,{}),g.jsx(i1e,{})]})}function i1e(){const n=fs(1),e=il(),t=n&&e;return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"delete",disabled:!t}),g.jsx(ce,{actionId:"duplicate",disabled:!t})]})}function a1e(){const n=cW(),e=lW();return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"undo",disabled:!n}),g.jsx(ce,{actionId:"redo",disabled:!e})]})}const l1e=k.memo(function({children:e}){const t=e??g.jsx(o1e,{});return g.jsx(as,{type:"small-icons",sourceId:"quick-actions",children:t})});function c1e({userId:n}){var t;const e=b0(n);return e?g.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:((t=e.userName)==null?void 0:t[0])??""},n):null}const u1e=tr(function({userId:e}){var c;const t=ne(),r=Ke(),s=Bn(),o=b0(e),i=k.useCallback(()=>{t.getInstanceState().followingUserId===e?(t.stopFollowingUser(),s("stop-following",{source:"people-menu"})):(t.startFollowingUser(e),s("start-following",{source:"people-menu"}))},[t,e,s]),a=(o==null?void 0:o.followingUserId)===t.user.getId(),l=t.getInstanceState().followingUserId===e;return o?g.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal","data-follow":l||a,children:[g.jsxs(ht,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>t.zoomToUser(e),onDoubleClick:i,children:[g.jsx(Ya,{label:r("people-menu.avatar-color"),icon:"color",color:o.color}),g.jsx("div",{className:"tlui-people-menu__name",children:((c=o.userName)==null?void 0:c.trim())||r("people-menu.anonymous-user")})]}),g.jsx(ht,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,children:g.jsx(lt,{icon:a?"leading":l?"following":"follow"})})]}):null});function d1e({count:n}){return g.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(n)})}const h1e=tr(function(){const e=ne(),t=_n(),r=Ke(),s=Bn(),o=k.useRef(!1),[i,a]=k.useState(!1),l=k.useCallback(v=>{a(v)},[]),c=e.user.getColor(),u=k.useCallback(v=>{e.user.updateUserPreferences({color:v}),s("set-color",{source:"people-menu"})},[e,s]),{handleButtonClick:h,handleButtonPointerDown:p,handleButtonPointerEnter:m,handleButtonPointerUp:S}=We.useMemo(()=>{const v=()=>{o.current=!1,window.removeEventListener("pointerup",v)};return{handleButtonClick:E=>{const{id:_}=E.currentTarget.dataset;_&&c!==_&&u(_)},handleButtonPointerDown:E=>{const{id:_}=E.currentTarget.dataset;_&&(u(_),o.current=!0,window.addEventListener("pointerup",v))},handleButtonPointerEnter:E=>{if(!o.current)return;const{id:_}=E.currentTarget.dataset;_&&u(_)},handleButtonPointerUp:E=>{const{id:_}=E.currentTarget.dataset;_&&u(_)}}},[c,u]);return g.jsxs(T_,{onOpenChange:l,open:i,children:[g.jsx(__,{dir:"ltr",asChild:!0,children:g.jsx(ht,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:g.jsx(lt,{icon:"color"})})}),g.jsx(M_,{container:t,children:g.jsx(A_,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:g.jsx("div",{className:"tlui-buttons__grid",children:Lk.map(v=>g.jsx(ht,{type:"icon","data-id":v,"data-testid":v,"aria-label":v,isActive:c===v,title:v,className:"tlui-button-grid__button",style:{color:v},onPointerEnter:m,onPointerDown:p,onPointerUp:S,onClick:h,children:g.jsx(lt,{icon:"color"})},v))})})})]})});function f1e(){const n=ne(),e=Bn(),t=se("userName",()=>n.user.getName(),[]),r=Ke(),s=k.useRef(t),o=k.useRef(t),[i,a]=k.useState(!1),l=k.useCallback(()=>{a(p=>!p)},[]),c=k.useCallback(p=>{o.current=p,n.user.updateUserPreferences({name:p})},[n]),u=k.useCallback(()=>{s.current!==o.current&&(e("change-user-name",{source:"people-menu"}),s.current=o.current)},[e]),h=k.useCallback(()=>{a(!1),n.user.updateUserPreferences({name:s.current}),n.menus.clearOpenMenus()},[n]);return g.jsxs("div",{className:"tlui-people-menu__user",children:[g.jsx(h1e,{}),i?g.jsx(Ug,{className:"tlui-people-menu__user__input",defaultValue:t,onValueChange:c,onComplete:l,onCancel:h,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:t||r("people-menu.anonymous-user")}),t?null:g.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")})]}),g.jsx(ht,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:g.jsx(lt,{icon:i?"check":"edit"})})]})}function p1e({children:n}){const e=Ke(),t=_n(),r=ne(),s=y4(),o=se("user",()=>r.user.getColor(),[r]),i=se("user",()=>r.user.getName(),[r]),[a,l]=ol("people menu");return s.length?g.jsxs(T_,{onOpenChange:l,open:a,children:[g.jsx(__,{dir:"ltr",asChild:!0,children:g.jsxs("button",{className:"tlui-people-menu__avatars-button",title:e("people-menu.title"),children:[s.length>5&&g.jsx(d1e,{count:s.length-5}),g.jsxs("div",{className:"tlui-people-menu__avatars",children:[s.slice(-5).map(c=>g.jsx(c1e,{userId:c},c)),s.length>0&&g.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:o},children:(i==null?void 0:i[0])??""})]})]})}),g.jsx(M_,{container:t,children:g.jsx(A_,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,children:g.jsxs("div",{className:"tlui-people-menu__wrapper",children:[g.jsx("div",{className:"tlui-people-menu__section",children:g.jsx(f1e,{})}),s.length>0&&g.jsx("div",{className:"tlui-people-menu__section",children:s.map(c=>g.jsx(u1e,{userId:c},c+"_presence"))}),n]})})})]}):null}function g1e(){return g.jsx("div",{className:"tlui-share-zone",draggable:!1,children:g.jsx(p1e,{})})}const m1e=Object.freeze([ts,pu,gu,Xi]);function VW(n=m1e){const e=ne();return se("getRelevantStyles",()=>{var o;const t=new Bk(e.getSharedStyles()),r=!!((o=e.root.getCurrent())!=null&&o.shapeType),s=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(t.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const i of n)t.applyValue(i,e.getStyleForNextShape(i));return r||s||t.size>0?t:null},[e])}const Qs={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"}],arrowKind:[{value:"arc",icon:"arrow-arc"},{value:"elbow",icon:"arrow-elbow"}],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"}]},nu=k.memo(function(e){const{uiType:t,items:r,title:s,style:o,value:i,onValueChange:a,onHistoryMark:l,theme:c}=e,u=ne(),h=Ke(),p=Ur(),m=k.useRef(!1),S=k.useRef(null),{handleButtonClick:v,handleButtonPointerDown:y,handleButtonPointerEnter:w,handleButtonPointerUp:C}=k.useMemo(()=>{const T=()=>{m.current=!1,window.removeEventListener("pointerup",T);const D=S.current;D&&(["TEXTAREA","INPUT"].includes(D.nodeName)||D.isContentEditable)?D.focus():p>=vn.TABLET_SM&&u.getContainer().focus(),S.current=null};return{handleButtonClick:D=>{const{id:F}=D.currentTarget.dataset;i.type==="shared"&&i.value===F||(l==null||l("point picker item"),a(o,F))},handleButtonPointerDown:D=>{const{id:F}=D.currentTarget.dataset;l==null||l("point picker item"),a(o,F),m.current=!0,S.current=document.activeElement,window.addEventListener("pointerup",T)},handleButtonPointerEnter:D=>{if(!m.current)return;const{id:F}=D.currentTarget.dataset;a(o,F)},handleButtonPointerUp:D=>{const{id:F}=D.currentTarget.dataset;i.type==="shared"&&i.value===F||a(o,F)}}},[u,p,i,l,a,o]);return g.jsx(jme,{"data-testid":`style.${t}`,type:"single",className:$e("tlui-buttons__grid"),children:r.map(T=>{const E=s+" — "+h(`${t}-style.${T.value}`);return g.jsx(Lme,{type:"icon","data-id":T.value,"data-testid":`style.${t}.${T.value}`,"aria-label":E,value:T.value,"data-isactive":i.type==="shared"&&i.value===T.value,title:E,className:$e("tlui-button-grid__button"),style:o===ts?{color:c[T.value].solid}:void 0,onPointerEnter:w,onPointerDown:y,onPointerUp:C,onClick:v,children:g.jsx(lt,{icon:T.icon})},T.value)})})}),y1e=k.memo(function({onHistoryMark:e,title:t,steps:r,value:s,label:o,onValueChange:i,["data-testid"]:a}){const l=Ke(),[c,u]=k.useState(-1);k.useEffect(()=>{u(0)},[]);const h=k.useCallback(v=>{i(v[0])},[i]),p=k.useCallback(()=>{e("click slider")},[e]),m=k.useCallback(()=>{s&&i(s)},[s,i]),S=k.useCallback(v=>{v.key==="Tab"&&v.stopPropagation()},[]);return g.jsx("div",{className:"tlui-slider__container",children:g.jsxs($pe,{"data-testid":a,className:"tlui-slider",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:p,onValueChange:h,onPointerUp:m,onKeyDownCapture:S,onKeyUpCapture:S,title:t+" — "+l(o),children:[g.jsx(Upe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&g.jsx(Hpe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&g.jsx(Kpe,{"aria-label":l("style-panel.opacity"),className:"tlui-slider__thumb",dir:"ltr",tabIndex:c})]})})});function S1e({label:n,uiTypeA:e,uiTypeB:t,labelA:r,labelB:s,itemsA:o,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const p=ne(),m=Ke(),[S,v]=k.useState(!1),[y,w]=k.useState(!1),C=k.useMemo(()=>{var A;return((A=o.find(O=>c.type==="shared"&&c.value===O.value))==null?void 0:A.icon)??"mixed"},[o,c]),T=k.useMemo(()=>{var A;return((A=i.find(O=>u.type==="shared"&&u.value===O.value))==null?void 0:A.icon)??"mixed"},[i,u]);if(c===void 0&&u===void 0)return null;const E=`style panel ${e} A`,_=`style panel ${t} B`;return g.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[g.jsx("div",{title:m(n),className:"tlui-style-panel__double-select-picker-label",children:m(n)}),g.jsxs(In,{label:m(n),className:"tlui-buttons__horizontal",children:[g.jsxs(ku,{id:E,open:S,onOpenChange:v,children:[g.jsx(Eu,{children:g.jsx(Yn,{type:"icon","data-testid":`style.${e}`,title:m(r)+" — "+(c===null||c.type==="mixed"?m("style-panel.mixed"):m(`${e}-style.${c.value}`)),children:g.jsx(lt,{icon:C,small:!0,invertIcon:!0})})}),g.jsx(Iu,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:g.jsx(In,{label:m(r),className:"tlui-buttons__grid",children:g.jsx(as,{type:"icons",sourceId:"style-panel",children:o.map(A=>g.jsx(Yn,{"data-testid":`style.${e}.${A.value}`,type:"icon",onClick:()=>{h(a,A.value),Xr.deleteOpenMenu(E,p.contextId),v(!1)},title:`${m(r)} — ${m(`${e}-style.${A.value}`)}`,children:g.jsx(lt,{icon:A.icon,invertIcon:!0})},A.value))})})})]}),g.jsxs(ku,{id:_,open:y,onOpenChange:w,children:[g.jsx(Eu,{children:g.jsx(Yn,{type:"icon","data-testid":`style.${t}`,title:m(s)+" — "+(u===null||u.type==="mixed"?m("style-panel.mixed"):m(`${t}-style.${u.value}`)),children:g.jsx(lt,{icon:T,small:!0})})}),g.jsx(Iu,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:g.jsx(In,{label:m(s),className:"tlui-buttons__grid",children:g.jsx(as,{type:"icons",sourceId:"style-panel",children:i.map(A=>g.jsx(Yn,{type:"icon",title:`${m(s)} — ${m(`${t}-style.${A.value}`)}`,"data-testid":`style.${t}.${A.value}`,onClick:()=>{h(l,A.value),Xr.deleteOpenMenu(_,p.contextId),w(!1)},children:g.jsx(lt,{icon:A.icon})},A.value))})})})]})]})]})}const x1e=k.memo(S1e);function v1e({id:n,label:e,uiType:t,stylePanelType:r,style:s,items:o,type:i,value:a,onValueChange:l}){const c=Ke(),u=ne(),[h,p]=k.useState(!1),m=k.useMemo(()=>{var C;return(C=o.find(T=>a.type==="shared"&&T.value===a.value))==null?void 0:C.icon},[o,a]),S=c(`style-panel.${r}`),v=a.type==="mixed"?c("style-panel.mixed"):S+" — "+c(`${t}-style.${a.value}`),y=e?c(e):"",w=`style panel ${n}`;return g.jsxs(ku,{id:w,open:h,onOpenChange:p,children:[g.jsx(Eu,{children:g.jsxs(Yn,{type:i,"data-testid":`style.${t}`,"data-direction":"left",title:v,children:[y&&g.jsx(En,{children:y}),g.jsx(lt,{icon:m??"mixed"})]})}),g.jsx(Iu,{side:"left",align:"center",children:g.jsx(In,{label:y,className:$e("tlui-buttons__grid",`tlui-buttons__${r}`),children:g.jsx(as,{type:"icons",sourceId:"style-panel",children:o.map(C=>g.jsx(Yn,{type:"icon","data-testid":`style.${t}.${C.value}`,title:S+" — "+c(`${t}-style.${C.value}`),isActive:m===C.icon,onClick:()=>{u.markHistoryStoppingPoint("select style dropdown item"),l(s,C.value),Xr.deleteOpenMenu(w,u.contextId),p(!1)},children:g.jsx(lt,{icon:C.icon})},C.value))})})})]})}const Av=k.memo(v1e);function w1e({styles:n}){const e=Ig();if(!n)return null;const t=n.get(ui),r=n.get(zS),s=n.get(FS),o=n.get(jp),i=n.get(HS),a=n.get(Wa),l=t===void 0,c=r===void 0&&s===void 0,u=i===void 0,h=o===void 0,p=a===void 0,m=tl({isDarkMode:e});return g.jsxs(g.Fragment,{children:[g.jsx(b1e,{theme:m,styles:n}),!p&&g.jsx(C1e,{theme:m,styles:n}),!(l&&c&&u&&h)&&g.jsxs("div",{className:"tlui-style-panel__section",children:[g.jsx(P1e,{styles:n}),g.jsx(E1e,{styles:n}),g.jsx(I1e,{styles:n}),g.jsx(k1e,{styles:n})]})]})}function zh(){const n=ne(),e=Bn();return We.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 b1e({styles:n,theme:e}){const t=Ke(),r=ne(),s=k.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),o=zh(),i=n.get(ts),a=n.get(gu),l=n.get(pu),c=n.get(Xi),u=a!==void 0||l!==void 0||c!==void 0;return g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"tlui-style-panel__section__common","data-testid":"style.panel",children:[i===void 0?null:g.jsx(In,{label:t("style-panel.color"),children:g.jsx(nu,{title:t("style-panel.color"),uiType:"color",style:ts,items:Qs.color,value:i,onValueChange:o,theme:e,onHistoryMark:s})}),g.jsx(T1e,{})]}),u&&g.jsxs("div",{className:"tlui-style-panel__section",children:[a===void 0?null:g.jsx(In,{label:t("style-panel.fill"),children:g.jsx(nu,{title:t("style-panel.fill"),uiType:"fill",style:gu,items:Qs.fill,value:a,onValueChange:o,theme:e,onHistoryMark:s})}),l===void 0?null:g.jsx(In,{label:t("style-panel.dash"),children:g.jsx(nu,{title:t("style-panel.dash"),uiType:"dash",style:pu,items:Qs.dash,value:l,onValueChange:o,theme:e,onHistoryMark:s})}),c===void 0?null:g.jsx(In,{label:t("style-panel.size"),children:g.jsx(nu,{title:t("style-panel.size"),uiType:"size",style:Xi,items:Qs.size,value:c,onValueChange:(h,p)=>{o(h,p);const m=r.getSelectedShapeIds();m.length>0&&Bt(r,m)},theme:e,onHistoryMark:s})})]})]})}function C1e({theme:n,styles:e}){const t=Ke(),r=zh(),s=ne(),o=k.useCallback(u=>s.markHistoryStoppingPoint(u),[s]),i=e.get(Wa),a=e.get(Ak),l=e.get($S),c=e.get(US);return i===void 0&&l===void 0?null:g.jsxs("div",{className:"tlui-style-panel__section",children:[i===void 0?null:g.jsx(In,{label:t("style-panel.font"),children:g.jsx(nu,{title:t("style-panel.font"),uiType:"font",style:Wa,items:Qs.font,value:i,onValueChange:r,theme:n,onHistoryMark:o})}),a===void 0?null:g.jsxs(In,{label:t("style-panel.align"),className:"tlui-style-panel__row",children:[g.jsx(nu,{title:t("style-panel.align"),uiType:"align",style:Ak,items:Qs.textAlign,value:a,onValueChange:r,theme:n,onHistoryMark:o}),g.jsx("div",{className:"tlui-style-panel__row__extra-button",children:g.jsx(Yn,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:g.jsx(lt,{icon:"vertical-align-middle"})})})]}),l===void 0?null:g.jsxs(In,{label:t("style-panel.label-align"),className:"tlui-style-panel__row",children:[g.jsx(nu,{title:t("style-panel.label-align"),uiType:"align",style:$S,items:Qs.horizontalAlign,value:l,onValueChange:r,theme:n,onHistoryMark:o}),g.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?g.jsx(Yn,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:g.jsx(lt,{icon:"vertical-align-middle"})}):g.jsx(Av,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:US,items:Qs.verticalAlign,value:c,onValueChange:r})})]})]})}function P1e({styles:n}){const e=Ke(),t=zh(),r=n.get(ui);return r===void 0?null:g.jsx(In,{label:e("style-panel.geo"),children:g.jsx(Av,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:ui,items:Qs.geo,value:r,onValueChange:t})})}function k1e({styles:n}){const e=Ke(),t=zh(),r=n.get(HS);return r===void 0?null:g.jsx(In,{label:e("style-panel.spline"),children:g.jsx(Av,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:HS,items:Qs.spline,value:r,onValueChange:t})})}function E1e({styles:n}){const e=Ke(),t=zh(),r=n.get(jp);return r===void 0?null:g.jsx(In,{label:e("style-panel.arrow-kind"),children:g.jsx(Av,{id:"arrow-kind",type:"menu",label:"style-panel.arrow-kind",uiType:"arrow-kind",stylePanelType:"arrow-kind",style:jp,items:Qs.arrowKind,value:r,onValueChange:t})})}function I1e({styles:n}){const e=zh(),t=n.get(zS),r=n.get(FS);return!t||!r?null:g.jsx(x1e,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:FS,itemsA:Qs.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:zS,itemsB:Qs.arrowheadEnd,valueB:t,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const zf=[.1,.25,.5,.75,1];function T1e(){const n=ne(),e=k.useCallback(a=>n.markHistoryStoppingPoint(a),[n]),t=se("opacity",()=>n.getSharedOpacity(),[n]),r=Bn(),s=Ke(),o=We.useCallback(a=>{const l=zf[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 i=t.type==="mixed"?-1:zf.indexOf(V3(zf,a=>Math.abs(a-t.value)));return g.jsx(y1e,{"data-testid":"style.opacity",value:i>=0?i:zf.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:o,steps:zf.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const _1e=k.memo(function({isMobile:e,children:t}){const r=ne(),s=k.useRef(null);rl(s);const o=VW(),i=k.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=t??g.jsx(w1e,{styles:o});return g.jsx("div",{ref:s,className:$e("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:i,children:a})}),M1e=We.forwardRef(function({children:e,className:t,label:r},s){return rl(s),wse(s),g.jsx("div",{ref:s,"data-testid":"contextual-toolbar",className:$e("tlui-contextual-toolbar",t),onPointerDown:Yt,children:g.jsx(In,{className:"tlui-menu tlui-buttons__horizontal",label:r,children:e})})});function A1e({textEditor:n,onEditLinkStart:e}){const t=Bn(),r=Ke(),s="rich-text-menu",[o,i]=k.useState(0);return k.useEffect(function(){function c(){i(u=>u+1)}n.on("update",c),n.on("selectionUpdate",c)},[n]),k.useEffect(()=>{function l(c){e&&pr(c)&&c.shiftKey&&c.key==="k"&&(c.preventDefault(),e())}return document.addEventListener("keydown",l),()=>{document.removeEventListener("keydown",l)}},[e]),k.useMemo(()=>{function l(c,u){t("rich-text",{operation:c,source:s}),n.chain().focus()[u]().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:u})=>{const h=n.isActive(l,c);return g.jsx(Yn,{title:r(`tool.rich-text-${l}`),"data-testid":`rich-text.${l}`,type:"icon",isActive:h,onPointerDown:nt,onClick:u,role:"option","aria-pressed":h,children:g.jsx(lt,{small:!0,icon:l})},l)})}function O1e({textEditor:n,value:e,onComplete:t}){const r=ne(),[s,o]=k.useState(e),i=Ke(),a=k.useRef(null),l=Bn(),c="rich-text-menu",u=s.startsWith("http")?s:`https://${s}`,h=y=>o(y),p=y=>{l("rich-text",{operation:"link-edit",source:c}),!y.startsWith("http://")&&!y.startsWith("https://")&&(y=`https://${y}`),n.commands.setLink({href:y}),r.getInstanceState().isCoarsePointer?n.commands.blur():n.commands.focus(),t()},m=()=>{l("rich-text",{operation:"link-visit",source:c}),window.open(u,"_blank","noopener, noreferrer"),t()},S=()=>{l("rich-text",{operation:"link-remove",source:c}),n.chain().unsetLink().focus().run(),t()},v=()=>t();return k.useEffect(()=>{var y;s||(y=a.current)==null||y.focus()},[s]),k.useEffect(()=>{o(e)},[e]),g.jsxs(g.Fragment,{children:[g.jsx(Ug,{ref:a,"data-testid":"rich-text.link-input",className:"tlui-rich-text__toolbar-link-input",value:s,onValueChange:h,onComplete:p,onCancel:v,placeholder:"example.com"}),g.jsx(ht,{className:"tlui-rich-text__toolbar-link-visit",title:i("tool.rich-text-link-visit"),type:"icon",onPointerDown:nt,onClick:m,disabled:!s,children:g.jsx(lt,{small:!0,icon:"external-link"})}),g.jsx(ht,{className:"tlui-rich-text__toolbar-link-remove",title:i("tool.rich-text-link-remove"),"data-testid":"rich-text.link-remove",type:"icon",onPointerDown:nt,onClick:S,children:g.jsx(lt,{small:!0,icon:"trash"})})]})}const R1e=150,D1e=16,j1e=16,L1e=8,Rl=16,N1e=16**2,F1e=!0,z1e=tr(function({children:e}){const t=ne(),r=se("textEditor",()=>t.getRichTextEditor(),[t]);return t.getInstanceState().isCoarsePointer||!r?null:g.jsx(B1e,{textEditor:r,children:e})});function B1e({textEditor:n,children:e}){const t=ne(),r=Ke(),s=k.useRef(null),{isVisible:o,isInteractive:i,hide:a,show:l,position:c,move:u}=K1e(),{isEditingLink:h,onEditLinkStart:p,onEditLinkComplete:m}=U1e(n),S=gg("force toolbar position update",0);k.useEffect(function(){function _(){S.update(A=>A+1)}return qS.requestAnimationFrame("first forced update",_),n.on("selectionUpdate",_),()=>{n.off("selectionUpdate",_)}},[n,S]),u0("shape change",function(){t.getEditingShape(),S.update(_=>_+1)},[t]);const v=k.useRef(!1),[y,w]=k.useState(!1);ec("toolbar position",function(){const _=s.current;if(!_)return;t.getCamera(),S.get();const A=$1e(t,_);if(!A){v.current&&(v.current=!1,w(!1));return}t.getCameraState()==="moving"?s.current.style.setProperty("transform",`translate(${A.x}px, ${A.y}px)`):u(A.x,A.y),v.current||(v.current=!0,w(!0))},[t,n,S]);const C=se("camera state",()=>t.getCameraState(),[t]),T=W1e(n);return k.useEffect(()=>{if(C==="moving"&&F1e){a(!0);return}if(T||!y){a();return}l()},[y,C,T,l,a]),k.useLayoutEffect(()=>{const E=s.current;E&&(E.dataset.visible=`${o}`)},[o,c]),k.useLayoutEffect(()=>{const E=s.current;E&&E.style.setProperty("transform",`translate(${c.x}px, ${c.y}px)`)},[c]),k.useLayoutEffect(()=>{const E=s.current;E&&(E.dataset.interactive=`${i}`)},[i]),g.jsx(M1e,{ref:s,className:"tlui-rich-text__toolbar","data-interactive":!1,"data-visible":!1,label:r("tool.rich-text-toolbar-title"),children:e||(h?g.jsx(O1e,{textEditor:n,value:n.isActive("link")?n.getAttributes("link").href:"",onComplete:m}):g.jsx(A1e,{textEditor:n,onEditLinkStart:p}))})}function R3(n){return new ye(n.x,n.y,n.width,n.height)}function $1e(n,e){const t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return;const r=[];for(let h=0;h<t.rangeCount;h++){const p=t.getRangeAt(h);r.push(R3(p.getBoundingClientRect()))}const s=ye.Common(r),o=n.getViewportScreenBounds();if(s.x-=o.x,s.y-=o.y,s.midY<Rl||s.midY>o.h-Rl||s.midX<Rl||s.midX>o.w-Rl)return;const i=R3(e.getBoundingClientRect());if(!i.width||!i.height)return;const{scrollLeft:a,scrollTop:l}=n.getContainer();let c=s.midX-i.w/2,u=s.y-i.h-L1e;return c=$t(c,Rl,o.w-i.w-Rl),u=$t(u,Rl,o.h-i.h-Rl),c+=a,u+=l,c=Math.round(c),u=Math.round(u),{x:c,y:u}}function U1e(n){const[e,t]=k.useState(!1);k.useEffect(()=>{if(!n){t(!1);return}const i=()=>{const a=n.isActive("link");t(a)};return n.view.dom.addEventListener("click",i),()=>{n.view.dom.removeEventListener("click",i)}},[n,e]),k.useEffect(()=>{if(n&&n.isActive("link"))try{const{from:i,to:a}=Y0(n.state.doc.resolve(n.state.selection.from),n.schema.marks.link);n.state.selection.empty&&n.commands.setTextSelection({from:i,to:a})}catch{}},[n,e]);const r=k.useCallback(()=>{t(!0)},[]),s=k.useCallback(()=>{t(!1)},[]),o=k.useCallback(()=>{if(t(!1),!n)return;const i=n.state.selection.from;n.commands.setTextSelection({from:i,to:i})},[n]);return{isEditingLink:e,onEditLinkStart:r,onEditLinkComplete:o,onEditLinkCancel:s}}function H1e(n,e){return P.Sub(e,n).y**2>=N1e}function K1e(){const n=ne(),e=k.useRef({name:"hidden"}),[t,r]=k.useState(!1),[s,o]=k.useState(!1),[i,a]=k.useState({x:-1e3,y:-1e3}),l=k.useRef(new P(-1e3,-1e3)),c=k.useRef(new P(-1e3,-1e3)),u=k.useRef(-1),h=k.useRef(-1),p=k.useCallback((v,y)=>{c.current.x=v,c.current.y=y,!(e.current.name==="hidden"||e.current.name==="showing")&&(clearTimeout(h.current),h.current=n.timers.setTimeout(()=>{if(e.current.name==="shown"&&H1e(c.current,l.current)){const{x:w,y:C}=c.current;l.current=new P(w,C),a({x:w,y:C})}},R1e))},[n]),m=k.useCallback((v=!1)=>{switch(e.current.name){case"showing":{clearTimeout(u.current),e.current={name:"hidden"};break}case"shown":{e.current={name:"hiding"},r(!1),v?(e.current={name:"hidden"},o(!1)):u.current=n.timers.setTimeout(()=>{e.current={name:"hidden"},o(!1)},D1e);break}}},[n]),S=k.useCallback(()=>{switch(e.current.name){case"hidden":{e.current={name:"showing"},u.current=n.timers.setTimeout(()=>{const{x:v,y}=c.current;l.current=new P(v,y),a({x:v,y}),e.current={name:"shown"},o(!0),r(!0)},j1e);break}case"hiding":{clearTimeout(u.current),e.current={name:"shown"},r(!0),p(c.current.x,c.current.y);break}}},[n,p]);return{isVisible:s,isInteractive:t,show:S,hide:m,move:p,position:i}}function W1e(n){const[e,t]=k.useState(!1);return k.useEffect(()=>{if(!n)return;const r=r0(({isPointing:l})=>{t(l)},16),s=()=>r({isPointing:!0}),o=()=>r({isPointing:!1}),i=["touchstart","pointerdown","mousedown"],a=["touchend","pointerup","mouseup"];return i.forEach(l=>{n.view.dom.addEventListener(l,s)}),a.forEach(l=>{document.body.addEventListener(l,o)}),()=>{i.forEach(l=>{n.view.dom.removeEventListener(l,s)}),a.forEach(l=>{document.body.removeEventListener(l,o)})}},[n]),e}function V1e(){const n=ne(),e=Ke(),t=VW(),r=t==null?void 0:t.get(ts),s=tl({isDarkMode:n.user.getIsDarkMode()}),o=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,i=se("disable style panel",()=>n.isInAny("hand","zoom","eraser","laser"),[n]),a=k.useCallback(c=>{c||n.updateInstanceState({isChangingStyle:!1})},[n]),{StylePanel:l}=vc();return l?g.jsxs(ku,{id:"mobile style menu",onOpenChange:a,children:[g.jsx(Eu,{children:g.jsx(ht,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":o},title:e("style-panel.title"),disabled:i,children:g.jsx(lt,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),g.jsx(Iu,{side:"top",align:"end",children:l&&g.jsx(l,{isMobile:!0})})]}):null}function G1e(){return g.jsxs(g.Fragment,{children:[g.jsx(Y1e,{}),g.jsx(X1e,{}),g.jsx(Z1e,{}),g.jsx(J1e,{}),g.jsx(Q1e,{}),g.jsx(eCe,{}),g.jsx(tCe,{}),g.jsx(nCe,{}),g.jsx(rCe,{}),g.jsx(sCe,{}),g.jsx(iCe,{}),g.jsx(oCe,{}),g.jsx(cCe,{}),g.jsx(hCe,{}),g.jsx(aCe,{}),g.jsx(dCe,{}),g.jsx(uCe,{}),g.jsx(lCe,{}),g.jsx(fCe,{}),g.jsx(pCe,{}),g.jsx(gCe,{}),g.jsx(mCe,{}),g.jsx(yCe,{}),g.jsx(SCe,{}),g.jsx(xCe,{}),g.jsx(vCe,{}),g.jsx(bCe,{}),g.jsx(wCe,{})]})}function q1e(n){var r;const e=ne(),t=(r=n==null?void 0:n.meta)==null?void 0:r.geo;return se("is tool selected",()=>{if(!n)return!1;const s=e.getCurrentToolId();return s==="geo"?t===e.getSharedStyles().getAsKnownValue(ui):s===n.id},[e,n==null?void 0:n.id,t])}function Kt({tool:n}){const e=q_(),t=q1e(e[n]);return g.jsx(Es,{toolId:n,isSelected:t})}function Y1e(){return g.jsx(Kt,{tool:"select"})}function X1e(){return g.jsx(Kt,{tool:"hand"})}function Z1e(){return g.jsx(Kt,{tool:"draw"})}function J1e(){return g.jsx(Kt,{tool:"eraser"})}function Q1e(){return g.jsx(Kt,{tool:"arrow"})}function eCe(){return g.jsx(Kt,{tool:"text"})}function tCe(){return g.jsx(Kt,{tool:"note"})}function nCe(){return g.jsx(Es,{toolId:"asset"})}function rCe(){return g.jsx(Kt,{tool:"rectangle"})}function sCe(){return g.jsx(Kt,{tool:"ellipse"})}function oCe(){return g.jsx(Kt,{tool:"diamond"})}function iCe(){return g.jsx(Kt,{tool:"triangle"})}function aCe(){return g.jsx(Kt,{tool:"rhombus"})}function lCe(){return g.jsx(Kt,{tool:"heart"})}function cCe(){return g.jsx(Kt,{tool:"hexagon"})}function uCe(){return g.jsx(Kt,{tool:"cloud"})}function dCe(){return g.jsx(Kt,{tool:"star"})}function hCe(){return g.jsx(Kt,{tool:"oval"})}function fCe(){return g.jsx(Kt,{tool:"x-box"})}function pCe(){return g.jsx(Kt,{tool:"check-box"})}function gCe(){return g.jsx(Kt,{tool:"arrow-left"})}function mCe(){return g.jsx(Kt,{tool:"arrow-up"})}function yCe(){return g.jsx(Kt,{tool:"arrow-down"})}function SCe(){return g.jsx(Kt,{tool:"arrow-right"})}function xCe(){return g.jsx(Kt,{tool:"line"})}function vCe(){return g.jsx(Kt,{tool:"highlight"})}function wCe(){return g.jsx(Kt,{tool:"frame"})}function bCe(){return g.jsx(Kt,{tool:"laser"})}const XP=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function ZP(n,e,t,r){n.addEventListener?n.addEventListener(e,t,r):n.attachEvent&&n.attachEvent("on".concat(e),t)}function Bf(n,e,t,r){n.removeEventListener?n.removeEventListener(e,t,r):n.detachEvent&&n.detachEvent("on".concat(e),t)}function GW(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 qW(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 CCe(n,e){const t=n.length>=e.length?n:e,r=n.length>=e.length?e:n;let s=!0;for(let o=0;o<t.length;o++)r.indexOf(t[o])===-1&&(s=!1);return s}const ig={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,"-":XP?173:189,"=":XP?61:187,";":XP?59:186,"'":222,"[":219,"]":221,"\\":220},gi={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},lp={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},lr={16:!1,18:!1,17:!1,91:!1},pn={};for(let n=1;n<20;n++)ig["f".concat(n)]=111+n;let rn=[],Tp=null,YW="all";const _a=new Map,Wg=n=>ig[n.toLowerCase()]||gi[n.toLowerCase()]||n.toUpperCase().charCodeAt(0),PCe=n=>Object.keys(ig).find(e=>ig[e]===n),kCe=n=>Object.keys(gi).find(e=>gi[e]===n);function XW(n){YW=n||"all"}function ag(){return YW||"all"}function ECe(){return rn.slice(0)}function ICe(){return rn.map(n=>PCe(n)||kCe(n)||String.fromCharCode(n))}function TCe(){const n=[];return Object.keys(pn).forEach(e=>{pn[e].forEach(t=>{let{key:r,scope:s,mods:o,shortcut:i}=t;n.push({scope:s,shortcut:i,mods:o,keys:r.split("+").map(a=>Wg(a))})})}),n}function _Ce(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 MCe(n){return typeof n=="string"&&(n=Wg(n)),rn.indexOf(n)!==-1}function ACe(n,e){let t,r;n||(n=ag());for(const s in pn)if(Object.prototype.hasOwnProperty.call(pn,s))for(t=pn[s],r=0;r<t.length;)t[r].scope===n?t.splice(r,1).forEach(i=>{let{element:a}=i;return k2(a)}):r++;ag()===n&&XW(e||"all")}function OCe(n){let e=n.keyCode||n.which||n.charCode;const t=rn.indexOf(e);if(t>=0&&rn.splice(t,1),n.key&&n.key.toLowerCase()==="meta"&&rn.splice(0,rn.length),(e===93||e===224)&&(e=91),e in lr){lr[e]=!1;for(const r in gi)gi[r]===e&&(Ro[r]=!1)}}function ZW(n){if(typeof n>"u")Object.keys(pn).forEach(s=>{Array.isArray(pn[s])&&pn[s].forEach(o=>Uy(o)),delete pn[s]}),k2(null);else if(Array.isArray(n))n.forEach(s=>{s.key&&Uy(s)});else if(typeof n=="object")n.key&&Uy(n);else if(typeof n=="string"){for(var e=arguments.length,t=new Array(e>1?e-1:0),r=1;r<e;r++)t[r-1]=arguments[r];let[s,o]=t;typeof s=="function"&&(o=s,s=""),Uy({key:n,scope:s,method:o,splitKey:"+"})}}const Uy=n=>{let{key:e,scope:t,method:r,splitKey:s="+"}=n;qW(e).forEach(i=>{const a=i.split(s),l=a.length,c=a[l-1],u=c==="*"?"*":Wg(c);if(!pn[u])return;t||(t=ag());const h=l>1?GW(gi,a):[],p=[];pn[u]=pn[u].filter(m=>{const v=(r?m.method===r:!0)&&m.scope===t&&CCe(m.mods,h);return v&&p.push(m.element),!v}),p.forEach(m=>k2(m))})};function D3(n,e,t,r){if(e.element!==r)return;let s;if(e.scope===t||e.scope==="all"){s=e.mods.length>0;for(const o in lr)Object.prototype.hasOwnProperty.call(lr,o)&&(!lr[o]&&e.mods.indexOf(+o)>-1||lr[o]&&e.mods.indexOf(+o)===-1)&&(s=!1);(e.mods.length===0&&!lr[16]&&!lr[18]&&!lr[17]&&!lr[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(rn),e.method(n,e)===!1&&(n.preventDefault?n.preventDefault():n.returnValue=!1,n.stopPropagation&&n.stopPropagation(),n.cancelBubble&&(n.cancelBubble=!0)))}}function j3(n,e){const t=pn["*"];let r=n.keyCode||n.which||n.charCode;if(!Ro.filter.call(this,n))return;if((r===93||r===224)&&(r=91),rn.indexOf(r)===-1&&r!==229&&rn.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=lp[a];n[a]&&rn.indexOf(l)===-1?rn.push(l):!n[a]&&rn.indexOf(l)>-1?rn.splice(rn.indexOf(l),1):a==="metaKey"&&n[a]&&(rn=rn.filter(c=>c in lp||c===r))}),r in lr){lr[r]=!0;for(const a in gi)if(Object.prototype.hasOwnProperty.call(gi,a)){const l=lp[gi[a]];Ro[a]=n[l]}if(!t)return}for(const a in lr)Object.prototype.hasOwnProperty.call(lr,a)&&(lr[a]=n[lp[a]]);n.getModifierState&&!(n.altKey&&!n.ctrlKey)&&n.getModifierState("AltGraph")&&(rn.indexOf(17)===-1&&rn.push(17),rn.indexOf(18)===-1&&rn.push(18),lr[17]=!0,lr[18]=!0);const s=ag();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)&&D3(n,t[a],s,e);if(!(r in pn))return;const o=pn[r],i=o.length;for(let a=0;a<i;a++)if((n.type==="keydown"&&o[a].keydown||n.type==="keyup"&&o[a].keyup)&&o[a].key){const l=o[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let p=0;p<u.length;p++)h.push(Wg(u[p]));h.sort().join("")===rn.sort().join("")&&D3(n,l,s,e)}}function Ro(n,e,t){rn=[];const r=qW(n);let s=[],o="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,p=!1;for(t===void 0&&typeof e=="function"&&(t=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(o=e.scope),e.element&&(i=e.element),e.keyup&&(l=e.keyup),e.keydown!==void 0&&(c=e.keydown),e.capture!==void 0&&(h=e.capture),typeof e.splitKey=="string"&&(u=e.splitKey),e.single===!0&&(p=!0)),typeof e=="string"&&(o=e),p&&ZW(n,o);a<r.length;a++)n=r[a].split(u),s=[],n.length>1&&(s=GW(gi,n)),n=n[n.length-1],n=n==="*"?"*":Wg(n),n in pn||(pn[n]=[]),pn[n].push({keyup:l,keydown:c,scope:o,mods:s,shortcut:r[a],method:t,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!_a.has(i)){const m=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return j3(v,i)},S=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;j3(v,i),OCe(v)};_a.set(i,{keydownListener:m,keyupListenr:S,capture:h}),ZP(i,"keydown",m,h),ZP(i,"keyup",S,h)}if(!Tp){const m=()=>{rn=[]};Tp={listener:m,capture:h},ZP(window,"focus",m,h)}}}function RCe(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(pn).forEach(t=>{pn[t].filter(s=>s.scope===e&&s.shortcut===n).forEach(s=>{s&&s.method&&s.method()})})}function k2(n){const e=Object.values(pn).flat();if(e.findIndex(r=>{let{element:s}=r;return s===n})<0){const{keydownListener:r,keyupListenr:s,capture:o}=_a.get(n)||{};r&&s&&(Bf(n,"keyup",s,o),Bf(n,"keydown",r,o),_a.delete(n))}if((e.length<=0||_a.size<=0)&&(Object.keys(_a).forEach(s=>{const{keydownListener:o,keyupListenr:i,capture:a}=_a.get(s)||{};o&&i&&(Bf(s,"keyup",i,a),Bf(s,"keydown",o,a),_a.delete(s))}),_a.clear(),Object.keys(pn).forEach(s=>delete pn[s]),Tp)){const{listener:s,capture:o}=Tp;Bf(window,"focus",s,o),Tp=null}}const JP={getPressedKeyString:ICe,setScope:XW,getScope:ag,deleteScope:ACe,getPressedKeyCodes:ECe,getAllKeyCodes:TCe,isPressed:MCe,filter:_Ce,trigger:RCe,unbind:ZW,keyMap:ig,modifier:gi,modifierMap:lp};for(const n in JP)Object.prototype.hasOwnProperty.call(JP,n)&&(Ro[n]=JP[n]);if(typeof window<"u"){const n=window.hotkeys;Ro.noConflict=e=>(e&&window.hotkeys===Ro&&(window.hotkeys=n),Ro),window.hotkeys=Ro}const L3=["copy","cut","paste","asset"];function DCe(){const n=ne(),e=ho(),t=Lu(),r=q_(),s=se("is focused",()=>n.getInstanceState().isFocused,[n]);k.useEffect(()=>{if(!s)return;const o=new Array,i=(l,c)=>{Ro(l,{element:document.body},c),o.push(()=>{Ro.unbind(l,c)})},a=(l,c)=>{Ro(l,{element:document.body,keyup:!0,keydown:!1},c),o.push(()=>{Ro.unbind(l,c)})};for(const l of Object.values(t))l.kbd&&(e&&!l.readonlyOk||L3.includes(l.id)||i(N3(l.kbd),c=>{cp(n)||(nt(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&n.getIsReadonly()||L3.includes(l.id)||i(N3(l.kbd),c=>{cp(n)||(nt(c),l.onSelect("kbd"))});return i(",",l=>{if(cp(n)||n.inputs.keys.has("Comma"))return;nt(l),n.focus(),n.inputs.keys.add("Comma");const{x:c,y:u,z:h}=n.inputs.currentPagePoint,p=n.pageToScreen({x:c,y:u}),m={type:"pointer",name:"pointer_down",point:{x:p.x,y:p.y,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:pr(l),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(m)}),a(",",l=>{if(cp(n)||!n.inputs.keys.has("Comma"))return;n.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=n.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:pr(l),pointerId:0,button:0,isPen:n.getInstanceState().isPenMode,target:"canvas"};n.dispatch(p)}),()=>{o.forEach(l=>l())}},[t,r,e,n,s])}function cp(n){return n.menus.hasAnyOpenMenus()||n.getEditingShapeId()!==null||n.getCrashingError()}function N3(n){return jCe(n).map(e=>{let t="";const r=e.includes("!"),s=e.includes("?"),o=e.includes("$"),i=e.replace(/[!?$]/g,"");return r&&s&&o?t=`cmd+shift+alt+${i},ctrl+shift+alt+${i}`:r&&o?t=`cmd+shift+${i},ctrl+shift+${i}`:s&&o?t=`cmd+alt+${i},ctrl+alt+${i}`:s&&r?t=`shift+alt+${i}`:r?t=`shift+${i}`:s?t=`alt+${i}`:o?t=`cmd+${i},ctrl+${i}`:t=i,t}).join(",")}function jCe(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}const LCe=k.createContext(!1),NCe={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,0:9};function FCe({children:n}){const e=ne(),t=Ou(),r=Ur(),s=Ke(),o=k.useRef([]),[i,a]=k.useState(!1),l=Math.min(8,5+r),[c,u]=k.useState(0),h=k.useRef(null),[p,m]=k.useState(null),S=k.useMemo(()=>{const w=p?`:not([data-value="${p}"])`:"";return`
516
+ #${t}_main > *:nth-child(n + ${l+(p?1:2)})${w} {
517
+ display: none;
518
+ }
519
+ #${t}_more > *:nth-child(-n + ${l}) {
520
+ display: none;
521
+ }
522
+ #${t}_more > *:nth-child(-n + ${l+4}) {
523
+ margin-top: 0;
524
+ }
525
+ `},[p,t,l]),v=Oa(()=>{var E;if(!h.current)return;const w=Array.from(h.current.children);u(w.length),w.findIndex(_=>_.getAttribute("data-value")===p)<=l&&m(null);const T=Array.from(h.current.children).findIndex(_=>_.getAttribute("aria-pressed")==="true");T!==-1&&(T>=l&&m(w[T].getAttribute("data-value")),o.current=Array.from(((E=h.current)==null?void 0:E.children)??[]).filter(_=>!(_ instanceof HTMLElement)||_.tagName.toLowerCase()!=="button"?!1:!!(_.offsetWidth||_.offsetHeight)))});k.useLayoutEffect(()=>{v()}),k.useLayoutEffect(()=>{if(!h.current)return;const w=new MutationObserver(v);return w.observe(h.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-pressed"]}),()=>{w.disconnect()}},[v]),k.useEffect(()=>{if(!e.options.enableToolbarKeyboardShortcuts)return;function w(C){var E;if(cp(e)||e4(!0)||C.ctrlKey||C.metaKey||C.altKey||C.shiftKey)return;const T=NCe[C.key];typeof T=="number"&&(nt(C),(E=o.current[T])==null||E.click())}return document.addEventListener("keydown",w),()=>{document.removeEventListener("keydown",w)}},[e]);const y="toolbar overflow";return g.jsxs(g.Fragment,{children:[g.jsx("style",{nonce:e.options.nonce,children:S}),g.jsxs(In,{className:$e("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<vn.TABLET_SM}),label:s("tool-panel.title"),children:[g.jsx("div",{id:`${t}_main`,ref:h,className:"tlui-toolbar__tools__list",children:g.jsx(as,{type:"toolbar",sourceId:"toolbar",children:n})}),c>l+1&&g.jsx(LCe.Provider,{value:!0,children:g.jsxs(ku,{id:y,open:i,onOpenChange:a,children:[g.jsx(Eu,{children:g.jsx(Yn,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:g.jsx(lt,{icon:"chevron-up"})})}),g.jsx(Iu,{side:"top",align:"center",children:g.jsx(In,{className:"tlui-buttons__grid","data-testid":"tools.more-content",label:s("tool-panel.more"),id:`${t}_more`,onClick:()=>{Xr.deleteOpenMenu(y,e.contextId),a(!1)},children:g.jsx(as,{type:"toolbar-overflow",sourceId:"toolbar",children:n})})})]})})]})]})}function zCe({activeToolId:n}){const e=ne(),t=Ur(),r=Ke(),s=se("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),o=se("current tool",()=>e.getCurrentTool(),[e]);return!n||!o.isLockable?null:g.jsx(ht,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:$e("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<vn.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:g.jsx(lt,{icon:s?"lock":"unlock",small:!0})})}const BCe=k.memo(function({children:e}){const t=ne(),r=Ke(),s=Ur(),o=ho(),i=se("current tool id",()=>t.getCurrentToolId(),[t]),a=k.useRef(null);rl(a);const{ActionsMenu:l,QuickActions:c}=vc(),u=t.options.actionShortcutsLocation==="menu"?!1:t.options.actionShortcutsLocation==="toolbar"?!0:s<vn.TABLET;return g.jsx("div",{ref:a,className:"tlui-toolbar",children:g.jsxs("div",{className:"tlui-toolbar__inner",children:[g.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&g.jsxs("div",{className:"tlui-toolbar__extras",children:[u&&g.jsxs(In,{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",label:r("actions-menu.title"),children:[c&&g.jsx(c,{}),l&&g.jsx(l,{})]}),g.jsx(zCe,{activeToolId:i})]}),g.jsx(FCe,{children:e??g.jsx(G1e,{})})]}),s<vn.TABLET_SM&&!o&&g.jsx("div",{className:"tlui-toolbar__tools",children:g.jsx(V1e,{})})]})})});function $Ce(){const n=Ke();return g.jsxs("div",{className:$e("tlui-offline-indicator"),children:[n("status.offline"),g.jsx(Ya,{label:n("status.offline"),icon:"status-offline",small:!0})]})}function UCe({maxWidth:n=420,ignoreRightWidth:e=0,stylePanelWidth:t=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:o}){const i=k.useRef(null),a=Ur(),l=k.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),m=u.offsetWidth,S=h.offsetWidth,v=p.offsetWidth,y=c.offsetWidth-e;let w=(m-y)/2;m%2!==0&&(w-=.5);const C=S+r,T=c.offsetLeft,E=Math.min(m-v-S-2*r,n),_=Math.max(w,C)-T;p.offsetWidth>t&&a<=6?c.style.setProperty("max-width",E-s+"px"):c.style.setProperty("max-width",E+"px"),c.style.setProperty("transform",`translate(${_}px, 0px)`)},[a,e,r,n,s,t]);return k.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),m=new ResizeObserver(l);return m.observe(h),m.observe(p),m.observe(u),m.observe(c),l(),()=>{m.disconnect()}},[l]),k.useLayoutEffect(()=>{l()}),g.jsx("div",{ref:i,className:"tlui-top-panel__container",children:o})}function HCe(){const n=zge()==="offline";return g.jsx(UCe,{children:n&&g.jsx($Ce,{})})}function KCe(){return g.jsxs(g.Fragment,{children:[g.jsx(ce,{actionId:"zoom-in",noClose:!0}),g.jsx(ce,{actionId:"zoom-out",noClose:!0}),g.jsx(SW,{}),g.jsx(xW,{}),g.jsx(vW,{})]})}const WCe=k.memo(function({children:e}){const t=_n(),[r,s]=ol("zoom menu"),o=e??g.jsx(KCe,{});return g.jsxs(P_,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[g.jsx(VCe,{}),g.jsx(fv,{container:t,children:g.jsx(E_,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:g.jsx(as,{type:"menu",sourceId:"zoom-menu",children:o})})})]})}),VCe=()=>{const n=ne(),e=Ur(),t=se("zoom",()=>n.getZoomLevel(),[n]),r=Ke(),s=k.useCallback(()=>{n.resetZoom(n.getViewportScreenCenter(),{animation:{duration:n.options.animationMediumMs}})},[n]),o=`${Math.floor(t*100)}%`;return g.jsx(Yn,{asChild:!0,type:"icon","aria-label":`${r("navigation-zone.zoom")} — ${o}`,title:`${r("navigation-zone.zoom")} — ${o}`,"data-testid":"minimap.zoom-menu-button",className:"tlui-zoom-menu__button",onDoubleClick:s,children:g.jsx(k_,{dir:"ltr",children:e<vn.MOBILE?null:g.jsx("span",{style:{flexGrow:0,textAlign:"center"},children:o})})})},JW=k.createContext(null);function GCe({overrides:n={},children:e}){const t=_h(n),r=vv();return g.jsx(JW.Provider,{value:k.useMemo(()=>({ContextMenu:ube,ActionsMenu:Fwe,HelpMenu:null,ZoomMenu:WCe,MainMenu:Kbe,Minimap:e1e,StylePanel:_1e,PageMenu:s1e,NavigationPanel:n1e,Toolbar:BCe,RichTextToolbar:z1e,KeyboardShortcutsDialog:Rbe,QuickActions:l1e,HelperButtons:Abe,DebugPanel:bbe,DebugMenu:wbe,MenuPanel:Ebe,SharePanel:r?g1e:null,CursorChatBubble:r?fbe:null,TopPanel:r?HCe:null,Dialogs:Mme,Toasts:Dme,A11y:Lce,...t}),[t,r]),children:e})}function vc(){const n=k.useContext(JW);if(!n)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return n}const QW=tr(function({overrides:e,components:t,assetUrls:r,onUiEvent:s,forceMobile:o,mediaMimeTypes:i,children:a}){const l=Sr();return g.jsx(lH.Provider,{value:i,children:g.jsx(Ace,{assetUrls:wwe(r),children:g.jsx(Dce,{overrides:yme(e),locale:(l==null?void 0:l.user.getLocale())??Fi.locale,children:g.jsx(zce,{onEvent:s,children:g.jsx(Hge,{children:g.jsx(Uge,{context:"tla",children:g.jsx(Mce,{children:g.jsx($ge,{forceMobile:o,children:g.jsx(GCe,{overrides:t,children:g.jsx(qCe,{overrides:e,children:a})})})})})})})})})})});function qCe({overrides:n,children:e}){const t=Sme(n);return g.jsx(vme,{overrides:t.actions,children:g.jsx(Nme,{overrides:t.tools,children:e})})}function YCe(){const n=ne(),{addToast:e}=sl();k.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 XCe=We.memo(function({renderDebugMenuItems:e,children:t,hideUi:r,components:s,...o}){return g.jsx(QW,{...o,components:s,children:g.jsx(ZCe,{hideUi:r,renderDebugMenuItems:e,children:t})})}),ZCe=We.memo(function({children:e,hideUi:t,...r}){return g.jsxs(g.Fragment,{children:[e,t?null:g.jsx(JCe,{...r})]})}),JCe=We.memo(function(){const e=ne(),t=Ke(),r=Ur(),s=ho(),o=se("focus",()=>e.getInstanceState().isFocusMode,[e]),i=se("debug",()=>e.getInstanceState().isDebugMode,[e]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:p,NavigationPanel:m,HelperButtons:S,DebugPanel:v,CursorChatBubble:y,RichTextToolbar:w,Toasts:C,Dialogs:T,A11y:E}=vc();DCe(),ime(),YCe();const _=k.useRef(!1),A=k.useRef(-1),[O,D]=k.useState(!1);u0("update hide toolbar while delayed",()=>{if(!(Tt.isIos||Tt.isAndroid))return;if(e.getEditingShapeId()===null){_.current&&(_.current=!1,clearTimeout(A.current),Tt.isAndroid?A.current=e.timers.setTimeout(()=>{D(!1)},150):D(!1));return}_.current||(_.current=!0,clearTimeout(A.current),D(!0))},[]);const{"toggle-focus-mode":F}=Lu();return g.jsxs("div",{className:$e("tlui-layout",{"tlui-layout__mobile":r<vn.TABLET_SM}),"data-iseditinganything":O,"data-breakpoint":r,children:[g.jsx(jce,{}),o?g.jsx("div",{className:"tlui-layout__top",children:g.jsx(ht,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>F.onSelect("menu"),children:g.jsx(lt,{icon:"dot"})})}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"tlui-layout__top",children:[g.jsxs("div",{className:"tlui-layout__top__left",children:[c&&g.jsx(c,{}),S&&g.jsx(S,{})]}),g.jsx("div",{className:"tlui-layout__top__center",children:l&&g.jsx(l,{})}),g.jsxs("div",{className:"tlui-layout__top__right",children:[a&&g.jsx(a,{}),u&&r>=vn.TABLET_SM&&!s&&g.jsx(u,{})]})]}),g.jsxs("div",{className:"tlui-layout__bottom",children:[g.jsxs("div",{className:"tlui-layout__bottom__main",children:[m&&g.jsx(m,{}),h&&g.jsx(h,{}),p&&g.jsx(p,{})]}),i&&v&&g.jsx(v,{}),E&&g.jsx(E,{})]})]}),w&&g.jsx(w,{}),C&&g.jsx(C,{}),T&&g.jsx(T,{}),g.jsx(ywe,{}),y&&g.jsx(y,{})]})}),QCe=()=>{const{Spinner:n}=Ft();return g.jsx(QW,{children:g.jsx(Y$,{children:n?g.jsx(n,{}):null})})},ePe=[...mwe,...Gxe];function tPe(n){const{children:e,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:o,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],embeds:h,textOptions:p,...m}=n,S=_h(a),v=k.useMemo(()=>({Scribble:_N,ShapeIndicators:eye,CollaboratorScribble:_N,SelectionForeground:Zme,Handles:Fme,Overlays:Kme,Spinner:DE,LoadingScreen:QCe,...S}),[S]),y=$l(l),w=k.useMemo(()=>up("type",y,vK),[y]),C=$l(c),T=k.useMemo(()=>up("type",C,yH),[C]),E=$l(u),_=k.useMemo(()=>up("id",ePe,E),[E]),A=$l(s??lg),O=$l(o??s0),D=k.useMemo(()=>({addFontsFromNode:DH,...p,tipTapConfig:{extensions:Kg,...p==null?void 0:p.tipTapConfig}}),[p]),F=k.useMemo(()=>[...A,...O],[A,O]),U=xwe(m.assetUrls);return w.find(Y=>Y.type==="embed")&&h&&t0.setEmbedDefinitions(h),g.jsx(pse,{initialState:"select",...m,components:v,shapeUtils:w,bindingUtils:T,tools:_,textOptions:D,assetUrls:U,children:g.jsxs(XCe,{...m,components:v,mediaMimeTypes:F,children:[g.jsx(nPe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:A,acceptedVideoMimeTypes:O,onMount:i}),e]})})}function nPe({maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,onMount:s}){const o=ne(),i=sl(),a=Ke();X$(()=>{const u=[];return u.push(Bve(o)),o.fonts.requestFonts(axe),xxe(o,{maxImageDimension:n,maxAssetSize:e,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r,toasts:i,msg:a}),u.push(o.store.props.onMount(o)),u.push(s==null?void 0:s(o)),()=>{u.forEach(h=>h==null?void 0:h())}});const{Canvas:l}=Ft(),{ContextMenu:c}=vc();return c?g.jsx(c,{}):l?g.jsx(l,{}):null}const rPe={tipTapConfig:{extensions:Kg},addFontsFromNode:DH};k.memo(function(e){const[t,r]=k.useState(null),[s,o]=k.useState(null),i=$l(e.shapeUtils??[]),a=k.useMemo(()=>up("type",i,vK),[i]),l=$l(e.bindingUtils??[]),c=k.useMemo(()=>up("type",l,yH),[l]),u=bse({snapshot:e.snapshot,shapeUtils:a}),{pageId:h,bounds:p,scale:m,pixelRatio:S,background:v,padding:y,darkMode:w,preserveAspectRatio:C,format:T="svg",licenseKey:E,assetUrls:_,textOptions:A=rPe}=e;return k.useLayoutEffect(()=>{if(!s||!u)return;let O=!1;const D=document.createElement("div");s.appendChild(D),s.classList.add("tl-container","tl-theme__light");const F=new ke({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>D,licenseKey:E,fontAssetUrls:_==null?void 0:_.fonts,textOptions:A});h&&F.setCurrentPage(h);const U=F.getCurrentPageShapeIds();async function V(){const Y=await F.toImage([...U],{bounds:p,scale:m,background:v,padding:y,darkMode:w,preserveAspectRatio:C,format:T});if(!Y||O)return;const j=URL.createObjectURL(Y.blob);r(j),F.dispose()}return V(),()=>{O=!0}},[T,s,u,a,c,h,p,m,v,y,w,C,E,S,_,A]),k.useEffect(()=>()=>{t&&URL.revokeObjectURL(t)},[t]),g.jsx("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:t&&g.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})})});k.memo(function({children:e}){const t=Ke(),r=Ur(),s=k.useRef(null);rl(s);const o=e??g.jsx(Dbe,{});return r<vn.MOBILE?null:g.jsx("div",{ref:s,className:"tlui-help-menu",children:g.jsxs(W_,{id:"help menu",children:[g.jsx(V_,{children:g.jsx(ht,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:g.jsx(lt,{icon:"question-mark",small:!0})})}),g.jsx(G_,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:g.jsx(as,{type:"menu",sourceId:"help-menu",children:o})})]})})});const sPe=1,oPe=mt({schemaVersion:Nr(1),storeVersion:Wy,recordVersions:LS(it,mt({version:Wy,subTypeVersions:LS(it,Wy).optional(),subTypeKey:it.optional()}))}),iPe=mt({schemaVersion:Nr(2),sequences:LS(it,Wy)}),aPe=mt({tldrawFileFormatVersion:LX,schema:NX("schemaVersion",{1:oPe,2:iPe}),records:Gn(mt({id:it,typeName:it}).allowUnknownProperties())});function lPe(n){var e;try{return!!((e=n.document)!=null&&e.version)}catch{return!1}}function cPe({json:n,schema:e}){let t;try{t=aPe.validate(JSON.parse(n))}catch(o){try{if(t=JSON.parse(n),lPe(t))return Gr.err({type:"v1File",data:t})}catch{}return Gr.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>sPe)return Gr.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r,s;try{const o=uPe(t.records);s=Object.fromEntries(o.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:s,schema:t.schema})}catch(o){return Gr.err({type:"invalidRecords",cause:o})}if(r.type==="error")return Gr.err({type:"migrationFailed",reason:r.reason});try{return Gr.ok(zp({snapshot:{store:s,schema:t.schema},schema:e}))}catch(o){return Gr.err({type:"invalidRecords",cause:o})}}function uPe(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))}lc("tldraw","3.13.1","esm");function dPe(){const[n,e]=k.useState();function t(r){globalThis.editor=r,n===void 0?fetch("/tldr-data").then(async s=>{if(!s.ok){console.log(`No tldr data to load from local endpoint (${s.status})`);return}return s.text()}).then(s=>{if(s===void 0)return;const o=cPe({json:s,schema:r.store.schema});o.ok?(console.log("Loaded tldr file from local endpoint"),e(o.value)):console.error(`Couldn't parse tldr file: ${String(o.error.type)}`)}).catch(s=>{console.error("Couldn't fetch data:",s)}):(r.zoomToFit(),r.menus.clearOpenMenus())}return g.jsx("div",{style:{inset:0,position:"fixed"},children:g.jsx(tPe,{assetUrls:NG(),onMount:t,store:n})})}LG.createRoot(document.querySelector("#root")).render(g.jsx(We.StrictMode,{children:g.jsx(dPe,{})}));