You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

345 lines
1.0 MiB

var RO=Object.defineProperty;var LO=(e,t,n)=>t in e?RO(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>(LO(e,typeof t!="symbol"?t+"":t,n),n);function FO(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const o in r)if(o!=="default"&&!(o in e)){const s=Object.getOwnPropertyDescriptor(r,o);s&&Object.defineProperty(e,o,s.get?s:{enumerable:!0,get:()=>r[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const s of o)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(o){const s={};return o.integrity&&(s.integrity=o.integrity),o.referrerPolicy&&(s.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?s.credentials="include":o.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(o){if(o.ep)return;o.ep=!0;const s=n(o);fetch(o.href,s)}})();var tn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function pc(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var SI={exports:{}},ff={},vI={exports:{}},xe={};/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Cu=Symbol.for("react.element"),NO=Symbol.for("react.portal"),zO=Symbol.for("react.fragment"),BO=Symbol.for("react.strict_mode"),UO=Symbol.for("react.profiler"),HO=Symbol.for("react.provider"),KO=Symbol.for("react.context"),WO=Symbol.for("react.forward_ref"),VO=Symbol.for("react.suspense"),GO=Symbol.for("react.memo"),YO=Symbol.for("react.lazy"),Nw=Symbol.iterator;function XO(e){return e===null||typeof e!="object"?null:(e=Nw&&e[Nw]||e["@@iterator"],typeof e=="function"?e:null)}var xI={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},wI=Object.assign,bI={};function fc(e,t,n){this.props=e,this.context=t,this.refs=bI,this.updater=n||xI}fc.prototype.isReactComponent={};fc.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=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,e,t,"setState")};fc.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function PI(){}PI.prototype=fc.prototype;function Lv(e,t,n){this.props=e,this.context=t,this.refs=bI,this.updater=n||xI}var Fv=Lv.prototype=new PI;Fv.constructor=Lv;wI(Fv,fc.prototype);Fv.isPureReactComponent=!0;var zw=Array.isArray,CI=Object.prototype.hasOwnProperty,Nv={current:null},II={key:!0,ref:!0,__self:!0,__source:!0};function EI(e,t,n){var r,o={},s=null,i=null;if(t!=null)for(r in t.ref!==void 0&&(i=t.ref),t.key!==void 0&&(s=""+t.key),t)CI.call(t,r)&&!II.hasOwnProperty(r)&&(o[r]=t[r]);var a=arguments.length-2;if(a===1)o.children=n;else if(1<a){for(var c=Array(a),l=0;l<a;l++)c[l]=arguments[l+2];o.children=c}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Cu,type:e,key:s,ref:i,props:o,_owner:Nv.current}}function qO(e,t){return{$$typeof:Cu,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function zv(e){return typeof e=="object"&&e!==null&&e.$$typeof===Cu}function ZO(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(n){return t[n]})}var Bw=/\/+/g;function $g(e,t){return typeof e=="object"&&e!==null&&e.key!=null?ZO(""+e.key):t.toString(36)}function nh(e,t,n,r,o){var s=typeof e;(s==="undefined"||s==="boolean")&&(e=null);var i=!1;if(e===null)i=!0;else switch(s){case"string":case"number":i=!0;break;case"object":switch(e.$$typeof){case Cu:case NO:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+$g(i,0):r,zw(o)?(n="",e!=null&&(n=e.replace(Bw,"$&/")+"/"),nh(o,t,n,"",function(l){return l})):o!=null&&(zv(o)&&(o=qO(o,n+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(Bw,"$&/")+"/")+e)),t.push(o)),1;if(i=0,r=r===""?".":r+":",zw(e))for(var a=0;a<e.length;a++){s=e[a];var c=r+$g(s,a);i+=nh(s,t,n,c,o)}else if(c=XO(e),typeof c=="function")for(e=c.call(e),a=0;!(s=e.next()).done;)s=s.value,c=r+$g(s,a++),i+=nh(s,t,n,c,o);else if(s==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return i}function td(e,t,n){if(e==null)return e;var r=[],o=0;return nh(e,r,"","",function(s){return t.call(n,s,o++)}),r}function QO(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(n){(e._status===0||e._status===-1)&&(e._status=1,e._result=n)},function(n){(e._status===0||e._status===-1)&&(e._status=2,e._result=n)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var mn={current:null},rh={transition:null},JO={ReactCurrentDispatcher:mn,ReactCurrentBatchConfig:rh,ReactCurrentOwner:Nv};function _I(){throw Error("act(...) is not supported in production builds of React.")}xe.Children={map:td,forEach:function(e,t,n){td(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return td(e,function(){t++}),t},toArray:function(e){return td(e,function(t){return t})||[]},only:function(e){if(!zv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};xe.Component=fc;xe.Fragment=zO;xe.Profiler=UO;xe.PureComponent=Lv;xe.StrictMode=BO;xe.Suspense=VO;xe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=JO;xe.act=_I;xe.cloneElement=function(e,t,n){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=wI({},e.props),o=e.key,s=e.ref,i=e._owner;if(t!=null){if(t.ref!==void 0&&(s=t.ref,i=Nv.current),t.key!==void 0&&(o=""+t.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(c in t)CI.call(t,c)&&!II.hasOwnProperty(c)&&(r[c]=t[c]===void 0&&a!==void 0?a[c]:t[c])}var c=arguments.length-2;if(c===1)r.children=n;else if(1<c){a=Array(c);for(var l=0;l<c;l++)a[l]=arguments[l+2];r.children=a}return{$$typeof:Cu,type:e.type,key:o,ref:s,props:r,_owner:i}};xe.createContext=function(e){return e={$$typeof:KO,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:HO,_context:e},e.Consumer=e};xe.createElement=EI;xe.createFactory=function(e){var t=EI.bind(null,e);return t.type=e,t};xe.createRef=function(){return{current:null}};xe.forwardRef=function(e){return{$$typeof:WO,render:e}};xe.isValidElement=zv;xe.lazy=function(e){return{$$typeof:YO,_payload:{_status:-1,_result:e},_init:QO}};xe.memo=function(e,t){return{$$typeof:GO,type:e,compare:t===void 0?null:t}};xe.startTransition=function(e){var t=rh.transition;rh.transition={};try{e()}finally{rh.transition=t}};xe.unstable_act=_I;xe.useCallback=function(e,t){return mn.current.useCallback(e,t)};xe.useContext=function(e){return mn.current.useContext(e)};xe.useDebugValue=function(){};xe.useDeferredValue=function(e){return mn.current.useDeferredValue(e)};xe.useEffect=function(e,t){return mn.current.useEffect(e,t)};xe.useId=function(){return mn.current.useId()};xe.useImperativeHandle=function(e,t,n){return mn.current.useImperativeHandle(e,t,n)};xe.useInsertionEffect=function(e,t){return mn.current.useInsertionEffect(e,t)};xe.useLayoutEffect=function(e,t){return mn.current.useLayoutEffect(e,t)};xe.useMemo=function(e,t){return mn.current.useMemo(e,t)};xe.useReducer=function(e,t,n){return mn.current.useReducer(e,t,n)};xe.useRef=function(e){return mn.current.useRef(e)};xe.useState=function(e){return mn.current.useState(e)};xe.useSyncExternalStore=function(e,t,n){return mn.current.useSyncExternalStore(e,t,n)};xe.useTransition=function(){return mn.current.useTransition()};xe.version="18.3.1";vI.exports=xe;var x=vI.exports;const Se=pc(x),eD=FO({__proto__:null,default:Se},[x]);/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var tD=x,nD=Symbol.for("react.element"),rD=Symbol.for("react.fragment"),oD=Object.prototype.hasOwnProperty,sD=tD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,iD={key:!0,ref:!0,__self:!0,__source:!0};function kI(e,t,n){var r,o={},s=null,i=null;n!==void 0&&(s=""+n),t.key!==void 0&&(s=""+t.key),t.ref!==void 0&&(i=t.ref);for(r in t)oD.call(t,r)&&!iD.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)o[r]===void 0&&(o[r]=t[r]);return{$$typeof:nD,type:e,key:s,ref:i,props:o,_owner:sD.current}}ff.Fragment=rD;ff.jsx=kI;ff.jsxs=kI;SI.exports=ff;var h=SI.exports,Ry={},TI={exports:{}},nr={},$I={exports:{}},MI={};/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/(function(e){function t(H,U){var W=H.length;H.push(U);e:for(;0<W;){var Z=W-1>>>1,le=H[Z];if(0<o(le,U))H[Z]=U,H[W]=le,W=Z;else break e}}function n(H){return H.length===0?null:H[0]}function r(H){if(H.length===0)return null;var U=H[0],W=H.pop();if(W!==U){H[0]=W;e:for(var Z=0,le=H.length,be=le>>>1;Z<be;){var Me=2*(Z+1)-1,ae=H[Me],Ae=Me+1,Re=H[Ae];if(0>o(ae,W))Ae<le&&0>o(Re,ae)?(H[Z]=Re,H[Ae]=W,Z=Ae):(H[Z]=ae,H[Me]=W,Z=Me);else if(Ae<le&&0>o(Re,W))H[Z]=Re,H[Ae]=W,Z=Ae;else break e}}return U}function o(H,U){var W=H.sortIndex-U.sortIndex;return W!==0?W:H.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var c=[],l=[],u=1,d=null,p=3,f=!1,y=!1,g=!1,w=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function b(H){for(var U=n(l);U!==null;){if(U.callback===null)r(l);else if(U.startTime<=H)r(l),U.sortIndex=U.expirationTime,t(c,U);else break;U=n(l)}}function E(H){if(g=!1,b(H),!y)if(n(c)!==null)y=!0,q(C);else{var U=n(l);U!==null&&Q(E,U.startTime-H)}}function C(H,U){y=!1,g&&(g=!1,S(k),k=-1),f=!0;var W=p;try{for(b(U),d=n(c);d!==null&&(!(d.expirationTime>U)||H&&!O());){var Z=d.callback;if(typeof Z=="function"){d.callback=null,p=d.priorityLevel;var le=Z(d.expirationTime<=U);U=e.unstable_now(),typeof le=="function"?d.callback=le:d===n(c)&&r(c),b(U)}else r(c);d=n(c)}if(d!==null)var be=!0;else{var Me=n(l);Me!==null&&Q(E,Me.startTime-U),be=!1}return be}finally{d=null,p=W,f=!1}}var I=!1,_=null,k=-1,$=5,T=-1;function O(){return!(e.unstable_now()-T<$)}function N(){if(_!==null){var H=e.unstable_now();T=H;var U=!0;try{U=_(!0,H)}finally{U?F():(I=!1,_=null)}}else I=!1}var F;if(typeof v=="function")F=function(){v(N)};else if(typeof MessageChannel<"u"){var L=new MessageChannel,B=L.port2;L.port1.onmessage=N,F=function(){B.postMessage(null)}}else F=function(){w(N,0)};function q(H){_=H,I||(I=!0,F())}function Q(H,U){k=w(function(){H(e.unstable_now())},U)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(H){H.callback=null},e.unstable_continueExecution=function(){y||f||(y=!0,q(C))},e.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<H?Math.floor(1e3/H):5},e.unstable_getCurrentPriorityLevel=function(){return p},e.unstable_getFirstCallbackNode=function(){return n(c)},e.unstable_next=function(H){switch(p){case 1:case 2:case 3:var U=3;break;default:U=p}var W=p;p=U;try{return H()}finally{p=W}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(H,U){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var W=p;p=H;try{return U()}finally{p=W}},e.unstable_scheduleCallback=function(H,U,W){var Z=e.unstable_now();switch(typeof W=="object"&&W!==null?(W=W.delay,W=typeof W=="number"&&0<W?Z+W:Z):W=Z,H){case 1:var le=-1;break;case 2:le=250;break;case 5:le=1073741823;break;case 4:le=1e4;break;default:le=5e3}return le=W+le,H={id:u++,callback:U,priorityLevel:H,startTime:W,expirationTime:le,sortIndex:-1},W>Z?(H.sortIndex=W,t(l,H),n(c)===null&&H===n(l)&&(g?(S(k),k=-1):g=!0,Q(E,W-Z))):(H.sortIndex=le,t(c,H),y||f||(y=!0,q(C))),H},e.unstable_shouldYield=O,e.unstable_wrapCallback=function(H){var U=p;return function(){var W=p;p=U;try{return H.apply(this,arguments)}finally{p=W}}}})(MI);$I.exports=MI;var aD=$I.exports;/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var cD=x,Jn=aD;function Y(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n<arguments.length;n++)t+="&args[]="+encodeURIComponent(arguments[n]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var AI=new Set,Ll={};function zi(e,t){Za(e,t),Za(e+"Capture",t)}function Za(e,t){for(Ll[e]=t,e=0;e<t.length;e++)AI.add(t[e])}var No=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ly=Object.prototype.hasOwnProperty,lD=/^[: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]*$/,Uw={},Hw={};function uD(e){return Ly.call(Hw,e)?!0:Ly.call(Uw,e)?!1:lD.test(e)?Hw[e]=!0:(Uw[e]=!0,!1)}function dD(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function hD(e,t,n,r){if(t===null||typeof t>"u"||dD(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function yn(e,t,n,r,o,s,i){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=s,this.removeEmptyString=i}var Kt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Kt[e]=new yn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Kt[t]=new yn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Kt[e]=new yn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Kt[e]=new yn(e,2,!1,e,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(e){Kt[e]=new yn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Kt[e]=new yn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Kt[e]=new yn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Kt[e]=new yn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Kt[e]=new yn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Bv=/[\-:]([a-z])/g;function Uv(e){return e[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(e){var t=e.replace(Bv,Uv);Kt[t]=new yn(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(Bv,Uv);Kt[t]=new yn(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(Bv,Uv);Kt[t]=new yn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Kt[e]=new yn(e,1,!1,e.toLowerCase(),null,!1,!1)});Kt.xlinkHref=new yn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Kt[e]=new yn(e,1,!1,e.toLowerCase(),null,!0,!0)});function Hv(e,t,n,r){var o=Kt.hasOwnProperty(t)?Kt[t]:null;(o!==null?o.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(hD(t,n,o,r)&&(n=null),r||o===null?uD(t)&&(n===null?e.removeAttribute(t):e.setAttribute(t,""+n)):o.mustUseProperty?e[o.propertyName]=n===null?o.type===3?!1:"":n:(t=o.attributeName,r=o.attributeNamespace,n===null?e.removeAttribute(t):(o=o.type,n=o===3||o===4&&n===!0?"":""+n,r?e.setAttributeNS(r,t,n):e.setAttribute(t,n))))}var Xo=cD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,nd=Symbol.for("react.element"),ma=Symbol.for("react.portal"),ya=Symbol.for("react.fragment"),Kv=Symbol.for("react.strict_mode"),Fy=Symbol.for("react.profiler"),jI=Symbol.for("react.provider"),OI=Symbol.for("react.context"),Wv=Symbol.for("react.forward_ref"),Ny=Symbol.for("react.suspense"),zy=Symbol.for("react.suspense_list"),Vv=Symbol.for("react.memo"),gs=Symbol.for("react.lazy"),DI=Symbol.for("react.offscreen"),Kw=Symbol.iterator;function Fc(e){return e===null||typeof e!="object"?null:(e=Kw&&e[Kw]||e["@@iterator"],typeof e=="function"?e:null)}var ut=Object.assign,Mg;function ll(e){if(Mg===void 0)try{throw Error()}catch(n){var t=n.stack.trim().match(/\n( *(at )?)/);Mg=t&&t[1]||""}return`
`+Mg+e}var Ag=!1;function jg(e,t){if(!e||Ag)return"";Ag=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(t,[])}catch(l){var r=l}Reflect.construct(e,[],t)}else{try{t.call()}catch(l){r=l}e.call(t.prototype)}else{try{throw Error()}catch(l){r=l}e()}}catch(l){if(l&&r&&typeof l.stack=="string"){for(var o=l.stack.split(`
`),s=r.stack.split(`
`),i=o.length-1,a=s.length-1;1<=i&&0<=a&&o[i]!==s[a];)a--;for(;1<=i&&0<=a;i--,a--)if(o[i]!==s[a]){if(i!==1||a!==1)do if(i--,a--,0>a||o[i]!==s[a]){var c=`
`+o[i].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=i&&0<=a);break}}}finally{Ag=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?ll(e):""}function pD(e){switch(e.tag){case 5:return ll(e.type);case 16:return ll("Lazy");case 13:return ll("Suspense");case 19:return ll("SuspenseList");case 0:case 2:case 15:return e=jg(e.type,!1),e;case 11:return e=jg(e.type.render,!1),e;case 1:return e=jg(e.type,!0),e;default:return""}}function By(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case ya:return"Fragment";case ma:return"Portal";case Fy:return"Profiler";case Kv:return"StrictMode";case Ny:return"Suspense";case zy:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case OI:return(e.displayName||"Context")+".Consumer";case jI:return(e._context.displayName||"Context")+".Provider";case Wv:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Vv:return t=e.displayName||null,t!==null?t:By(e.type)||"Memo";case gs:t=e._payload,e=e._init;try{return By(e(t))}catch{}}return null}function fD(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return By(t);case 8:return t===Kv?"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 t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Ds(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function RI(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function gD(e){var t=RI(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var o=n.get,s=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return o.call(this)},set:function(i){r=""+i,s.call(this,i)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function rd(e){e._valueTracker||(e._valueTracker=gD(e))}function LI(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=RI(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function op(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Uy(e,t){var n=t.checked;return ut({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Ww(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Ds(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function FI(e,t){t=t.checked,t!=null&&Hv(e,"checked",t,!1)}function Hy(e,t){FI(e,t);var n=Ds(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Ky(e,t.type,n):t.hasOwnProperty("defaultValue")&&Ky(e,t.type,Ds(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Vw(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Ky(e,t,n){(t!=="number"||op(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var ul=Array.isArray;function La(e,t,n,r){if(e=e.options,t){t={};for(var o=0;o<n.length;o++)t["$"+n[o]]=!0;for(n=0;n<e.length;n++)o=t.hasOwnProperty("$"+e[n].value),e[n].selected!==o&&(e[n].selected=o),o&&r&&(e[n].defaultSelected=!0)}else{for(n=""+Ds(n),t=null,o=0;o<e.length;o++){if(e[o].value===n){e[o].selected=!0,r&&(e[o].defaultSelected=!0);return}t!==null||e[o].disabled||(t=e[o])}t!==null&&(t.selected=!0)}}function Wy(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(Y(91));return ut({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Gw(e,t){var n=t.value;if(n==null){if(n=t.children,t=t.defaultValue,n!=null){if(t!=null)throw Error(Y(92));if(ul(n)){if(1<n.length)throw Error(Y(93));n=n[0]}t=n}t==null&&(t=""),n=t}e._wrapperState={initialValue:Ds(n)}}function NI(e,t){var n=Ds(t.value),r=Ds(t.defaultValue);n!=null&&(n=""+n,n!==e.value&&(e.value=n),t.defaultValue==null&&e.defaultValue!==n&&(e.defaultValue=n)),r!=null&&(e.defaultValue=""+r)}function Yw(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function zI(e){switch(e){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 Vy(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?zI(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var od,BI=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(t,n,r,o){MSApp.execUnsafeLocalFunction(function(){return e(t,n,r,o)})}:e}(function(e,t){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=t;else{for(od=od||document.createElement("div"),od.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=od.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Fl(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var vl={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},mD=["Webkit","ms","Moz","O"];Object.keys(vl).forEach(function(e){mD.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),vl[t]=vl[e]})});function UI(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||vl.hasOwnProperty(e)&&vl[e]?(""+t).trim():t+"px"}function HI(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=UI(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,o):e[n]=o}}var yD=ut({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 Gy(e,t){if(t){if(yD[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(Y(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(Y(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(Y(61))}if(t.style!=null&&typeof t.style!="object")throw Error(Y(62))}}function Yy(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){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 Xy=null;function Gv(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var qy=null,Fa=null,Na=null;function Xw(e){if(e=_u(e)){if(typeof qy!="function")throw Error(Y(280));var t=e.stateNode;t&&(t=vf(t),qy(e.stateNode,e.type,t))}}function KI(e){Fa?Na?Na.push(e):Na=[e]:Fa=e}function WI(){if(Fa){var e=Fa,t=Na;if(Na=Fa=null,Xw(e),t)for(e=0;e<t.length;e++)Xw(t[e])}}function VI(e,t){return e(t)}function GI(){}var Og=!1;function YI(e,t,n){if(Og)return e(t,n);Og=!0;try{return VI(e,t,n)}finally{Og=!1,(Fa!==null||Na!==null)&&(GI(),WI())}}function Nl(e,t){var n=e.stateNode;if(n===null)return null;var r=vf(n);if(r===null)return null;n=r[t];e:switch(t){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(n&&typeof n!="function")throw Error(Y(231,t,typeof n));return n}var Zy=!1;if(No)try{var Nc={};Object.defineProperty(Nc,"passive",{get:function(){Zy=!0}}),window.addEventListener("test",Nc,Nc),window.removeEventListener("test",Nc,Nc)}catch{Zy=!1}function SD(e,t,n,r,o,s,i,a,c){var l=Array.prototype.slice.call(arguments,3);try{t.apply(n,l)}catch(u){this.onError(u)}}var xl=!1,sp=null,ip=!1,Qy=null,vD={onError:function(e){xl=!0,sp=e}};function xD(e,t,n,r,o,s,i,a,c){xl=!1,sp=null,SD.apply(vD,arguments)}function wD(e,t,n,r,o,s,i,a,c){if(xD.apply(this,arguments),xl){if(xl){var l=sp;xl=!1,sp=null}else throw Error(Y(198));ip||(ip=!0,Qy=l)}}function Bi(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function XI(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function qw(e){if(Bi(e)!==e)throw Error(Y(188))}function bD(e){var t=e.alternate;if(!t){if(t=Bi(e),t===null)throw Error(Y(188));return t!==e?null:e}for(var n=e,r=t;;){var o=n.return;if(o===null)break;var s=o.alternate;if(s===null){if(r=o.return,r!==null){n=r;continue}break}if(o.child===s.child){for(s=o.child;s;){if(s===n)return qw(o),e;if(s===r)return qw(o),t;s=s.sibling}throw Error(Y(188))}if(n.return!==r.return)n=o,r=s;else{for(var i=!1,a=o.child;a;){if(a===n){i=!0,n=o,r=s;break}if(a===r){i=!0,r=o,n=s;break}a=a.sibling}if(!i){for(a=s.child;a;){if(a===n){i=!0,n=s,r=o;break}if(a===r){i=!0,r=s,n=o;break}a=a.sibling}if(!i)throw Error(Y(189))}}if(n.alternate!==r)throw Error(Y(190))}if(n.tag!==3)throw Error(Y(188));return n.stateNode.current===n?e:t}function qI(e){return e=bD(e),e!==null?ZI(e):null}function ZI(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=ZI(e);if(t!==null)return t;e=e.sibling}return null}var QI=Jn.unstable_scheduleCallback,Zw=Jn.unstable_cancelCallback,PD=Jn.unstable_shouldYield,CD=Jn.unstable_requestPaint,St=Jn.unstable_now,ID=Jn.unstable_getCurrentPriorityLevel,Yv=Jn.unstable_ImmediatePriority,JI=Jn.unstable_UserBlockingPriority,ap=Jn.unstable_NormalPriority,ED=Jn.unstable_LowPriority,eE=Jn.unstable_IdlePriority,gf=null,to=null;function _D(e){if(to&&typeof to.onCommitFiberRoot=="function")try{to.onCommitFiberRoot(gf,e,void 0,(e.current.flags&128)===128)}catch{}}var Dr=Math.clz32?Math.clz32:$D,kD=Math.log,TD=Math.LN2;function $D(e){return e>>>=0,e===0?32:31-(kD(e)/TD|0)|0}var sd=64,id=4194304;function dl(e){switch(e&-e){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 e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function cp(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,o=e.suspendedLanes,s=e.pingedLanes,i=n&268435455;if(i!==0){var a=i&~o;a!==0?r=dl(a):(s&=i,s!==0&&(r=dl(s)))}else i=n&~o,i!==0?r=dl(i):s!==0&&(r=dl(s));if(r===0)return 0;if(t!==0&&t!==r&&!(t&o)&&(o=r&-r,s=t&-t,o>=s||o===16&&(s&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)n=31-Dr(t),o=1<<n,r|=e[n],t&=~o;return r}function MD(e,t){switch(e){case 1:case 2:case 4:return t+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 t+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 AD(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-Dr(s),a=1<<i,c=o[i];c===-1?(!(a&n)||a&r)&&(o[i]=MD(a,t)):c<=t&&(e.expiredLanes|=a),s&=~a}}function Jy(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function tE(){var e=sd;return sd<<=1,!(sd&4194240)&&(sd=64),e}function Dg(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function Iu(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Dr(t),e[t]=n}function jD(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<n;){var o=31-Dr(n),s=1<<o;t[o]=0,r[o]=-1,e[o]=-1,n&=~s}}function Xv(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-Dr(n),o=1<<r;o&t|e[r]&t&&(e[r]|=t),n&=~o}}var Fe=0;function nE(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var rE,qv,oE,sE,iE,eS=!1,ad=[],Is=null,Es=null,_s=null,zl=new Map,Bl=new Map,ys=[],OD="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 Qw(e,t){switch(e){case"focusin":case"focusout":Is=null;break;case"dragenter":case"dragleave":Es=null;break;case"mouseover":case"mouseout":_s=null;break;case"pointerover":case"pointerout":zl.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":Bl.delete(t.pointerId)}}function zc(e,t,n,r,o,s){return e===null||e.nativeEvent!==s?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:s,targetContainers:[o]},t!==null&&(t=_u(t),t!==null&&qv(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,o!==null&&t.indexOf(o)===-1&&t.push(o),e)}function DD(e,t,n,r,o){switch(t){case"focusin":return Is=zc(Is,e,t,n,r,o),!0;case"dragenter":return Es=zc(Es,e,t,n,r,o),!0;case"mouseover":return _s=zc(_s,e,t,n,r,o),!0;case"pointerover":var s=o.pointerId;return zl.set(s,zc(zl.get(s)||null,e,t,n,r,o)),!0;case"gotpointercapture":return s=o.pointerId,Bl.set(s,zc(Bl.get(s)||null,e,t,n,r,o)),!0}return!1}function aE(e){var t=pi(e.target);if(t!==null){var n=Bi(t);if(n!==null){if(t=n.tag,t===13){if(t=XI(n),t!==null){e.blockedOn=t,iE(e.priority,function(){oE(n)});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function oh(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=tS(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);Xy=r,n.target.dispatchEvent(r),Xy=null}else return t=_u(n),t!==null&&qv(t),e.blockedOn=n,!1;t.shift()}return!0}function Jw(e,t,n){oh(e)&&n.delete(t)}function RD(){eS=!1,Is!==null&&oh(Is)&&(Is=null),Es!==null&&oh(Es)&&(Es=null),_s!==null&&oh(_s)&&(_s=null),zl.forEach(Jw),Bl.forEach(Jw)}function Bc(e,t){e.blockedOn===t&&(e.blockedOn=null,eS||(eS=!0,Jn.unstable_scheduleCallback(Jn.unstable_NormalPriority,RD)))}function Ul(e){function t(o){return Bc(o,e)}if(0<ad.length){Bc(ad[0],e);for(var n=1;n<ad.length;n++){var r=ad[n];r.blockedOn===e&&(r.blockedOn=null)}}for(Is!==null&&Bc(Is,e),Es!==null&&Bc(Es,e),_s!==null&&Bc(_s,e),zl.forEach(t),Bl.forEach(t),n=0;n<ys.length;n++)r=ys[n],r.blockedOn===e&&(r.blockedOn=null);for(;0<ys.length&&(n=ys[0],n.blockedOn===null);)aE(n),n.blockedOn===null&&ys.shift()}var za=Xo.ReactCurrentBatchConfig,lp=!0;function LD(e,t,n,r){var o=Fe,s=za.transition;za.transition=null;try{Fe=1,Zv(e,t,n,r)}finally{Fe=o,za.transition=s}}function FD(e,t,n,r){var o=Fe,s=za.transition;za.transition=null;try{Fe=4,Zv(e,t,n,r)}finally{Fe=o,za.transition=s}}function Zv(e,t,n,r){if(lp){var o=tS(e,t,n,r);if(o===null)Wg(e,t,r,up,n),Qw(e,r);else if(DD(o,e,t,n,r))r.stopPropagation();else if(Qw(e,r),t&4&&-1<OD.indexOf(e)){for(;o!==null;){var s=_u(o);if(s!==null&&rE(s),s=tS(e,t,n,r),s===null&&Wg(e,t,r,up,n),s===o)break;o=s}o!==null&&r.stopPropagation()}else Wg(e,t,r,null,n)}}var up=null;function tS(e,t,n,r){if(up=null,e=Gv(r),e=pi(e),e!==null)if(t=Bi(e),t===null)e=null;else if(n=t.tag,n===13){if(e=XI(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null);return up=e,null}function cE(e){switch(e){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(ID()){case Yv:return 1;case JI:return 4;case ap:case ED:return 16;case eE:return 536870912;default:return 16}default:return 16}}var ws=null,Qv=null,sh=null;function lE(){if(sh)return sh;var e,t=Qv,n=t.length,r,o="value"in ws?ws.value:ws.textContent,s=o.length;for(e=0;e<n&&t[e]===o[e];e++);var i=n-e;for(r=1;r<=i&&t[n-r]===o[s-r];r++);return sh=o.slice(e,1<r?1-r:void 0)}function ih(e){var t=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function cd(){return!0}function eb(){return!1}function rr(e){function t(n,r,o,s,i){this._reactName=n,this._targetInst=o,this.type=r,this.nativeEvent=s,this.target=i,this.currentTarget=null;for(var a in e)e.hasOwnProperty(a)&&(n=e[a],this[a]=n?n(s):s[a]);return this.isDefaultPrevented=(s.defaultPrevented!=null?s.defaultPrevented:s.returnValue===!1)?cd:eb,this.isPropagationStopped=eb,this}return ut(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var n=this.nativeEvent;n&&(n.preventDefault?n.preventDefault():typeof n.returnValue!="unknown"&&(n.returnValue=!1),this.isDefaultPrevented=cd)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=cd)},persist:function(){},isPersistent:cd}),t}var gc={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Jv=rr(gc),Eu=ut({},gc,{view:0,detail:0}),ND=rr(Eu),Rg,Lg,Uc,mf=ut({},Eu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:e0,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return"movementX"in e?e.movementX:(e!==Uc&&(Uc&&e.type==="mousemove"?(Rg=e.screenX-Uc.screenX,Lg=e.screenY-Uc.screenY):Lg=Rg=0,Uc=e),Rg)},movementY:function(e){return"movementY"in e?e.movementY:Lg}}),tb=rr(mf),zD=ut({},mf,{dataTransfer:0}),BD=rr(zD),UD=ut({},Eu,{relatedTarget:0}),Fg=rr(UD),HD=ut({},gc,{animationName:0,elapsedTime:0,pseudoElement:0}),KD=rr(HD),WD=ut({},gc,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),VD=rr(WD),GD=ut({},gc,{data:0}),nb=rr(GD),YD={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},XD={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"},qD={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function ZD(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=qD[e])?!!t[e]:!1}function e0(){return ZD}var QD=ut({},Eu,{key:function(e){if(e.key){var t=YD[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=ih(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?XD[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:e0,charCode:function(e){return e.type==="keypress"?ih(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?ih(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),JD=rr(QD),eR=ut({},mf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),rb=rr(eR),tR=ut({},Eu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:e0}),nR=rr(tR),rR=ut({},gc,{propertyName:0,elapsedTime:0,pseudoElement:0}),oR=rr(rR),sR=ut({},mf,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),iR=rr(sR),aR=[9,13,27,32],t0=No&&"CompositionEvent"in window,wl=null;No&&"documentMode"in document&&(wl=document.documentMode);var cR=No&&"TextEvent"in window&&!wl,uE=No&&(!t0||wl&&8<wl&&11>=wl),ob=" ",sb=!1;function dE(e,t){switch(e){case"keyup":return aR.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function hE(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Sa=!1;function lR(e,t){switch(e){case"compositionend":return hE(t);case"keypress":return t.which!==32?null:(sb=!0,ob);case"textInput":return e=t.data,e===ob&&sb?null:e;default:return null}}function uR(e,t){if(Sa)return e==="compositionend"||!t0&&dE(e,t)?(e=lE(),sh=Qv=ws=null,Sa=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case"compositionend":return uE&&t.locale!=="ko"?null:t.data;default:return null}}var dR={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 ib(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!dR[e.type]:t==="textarea"}function pE(e,t,n,r){KI(r),t=dp(t,"onChange"),0<t.length&&(n=new Jv("onChange","change",null,n,r),e.push({event:n,listeners:t}))}var bl=null,Hl=null;function hR(e){CE(e,0)}function yf(e){var t=wa(e);if(LI(t))return e}function pR(e,t){if(e==="change")return t}var fE=!1;if(No){var Ng;if(No){var zg="oninput"in document;if(!zg){var ab=document.createElement("div");ab.setAttribute("oninput","return;"),zg=typeof ab.oninput=="function"}Ng=zg}else Ng=!1;fE=Ng&&(!document.documentMode||9<document.documentMode)}function cb(){bl&&(bl.detachEvent("onpropertychange",gE),Hl=bl=null)}function gE(e){if(e.propertyName==="value"&&yf(Hl)){var t=[];pE(t,Hl,e,Gv(e)),YI(hR,t)}}function fR(e,t,n){e==="focusin"?(cb(),bl=t,Hl=n,bl.attachEvent("onpropertychange",gE)):e==="focusout"&&cb()}function gR(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return yf(Hl)}function mR(e,t){if(e==="click")return yf(t)}function yR(e,t){if(e==="input"||e==="change")return yf(t)}function SR(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var zr=typeof Object.is=="function"?Object.is:SR;function Kl(e,t){if(zr(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var o=n[r];if(!Ly.call(t,o)||!zr(e[o],t[o]))return!1}return!0}function lb(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function ub(e,t){var n=lb(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=lb(n)}}function mE(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?mE(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function yE(){for(var e=window,t=op();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=op(e.document)}return t}function n0(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function vR(e){var t=yE(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&mE(n.ownerDocument.documentElement,n)){if(r!==null&&n0(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var o=n.textContent.length,s=Math.min(r.start,o);r=r.end===void 0?s:Math.min(r.end,o),!e.extend&&s>r&&(o=r,r=s,s=o),o=ub(n,s);var i=ub(n,r);o&&i&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(t=t.createRange(),t.setStart(o.node,o.offset),e.removeAllRanges(),s>r?(e.addRange(t),e.extend(i.node,i.offset)):(t.setEnd(i.node,i.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n<t.length;n++)e=t[n],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var xR=No&&"documentMode"in document&&11>=document.documentMode,va=null,nS=null,Pl=null,rS=!1;function db(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;rS||va==null||va!==op(r)||(r=va,"selectionStart"in r&&n0(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Pl&&Kl(Pl,r)||(Pl=r,r=dp(nS,"onSelect"),0<r.length&&(t=new Jv("onSelect","select",null,t,n),e.push({event:t,listeners:r}),t.target=va)))}function ld(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n["Webkit"+e]="webkit"+t,n["Moz"+e]="moz"+t,n}var xa={animationend:ld("Animation","AnimationEnd"),animationiteration:ld("Animation","AnimationIteration"),animationstart:ld("Animation","AnimationStart"),transitionend:ld("Transition","TransitionEnd")},Bg={},SE={};No&&(SE=document.createElement("div").style,"AnimationEvent"in window||(delete xa.animationend.animation,delete xa.animationiteration.animation,delete xa.animationstart.animation),"TransitionEvent"in window||delete xa.transitionend.transition);function Sf(e){if(Bg[e])return Bg[e];if(!xa[e])return e;var t=xa[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in SE)return Bg[e]=t[n];return e}var vE=Sf("animationend"),xE=Sf("animationiteration"),wE=Sf("animationstart"),bE=Sf("transitionend"),PE=new Map,hb="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 Ks(e,t){PE.set(e,t),zi(t,[e])}for(var Ug=0;Ug<hb.length;Ug++){var Hg=hb[Ug],wR=Hg.toLowerCase(),bR=Hg[0].toUpperCase()+Hg.slice(1);Ks(wR,"on"+bR)}Ks(vE,"onAnimationEnd");Ks(xE,"onAnimationIteration");Ks(wE,"onAnimationStart");Ks("dblclick","onDoubleClick");Ks("focusin","onFocus");Ks("focusout","onBlur");Ks(bE,"onTransitionEnd");Za("onMouseEnter",["mouseout","mouseover"]);Za("onMouseLeave",["mouseout","mouseover"]);Za("onPointerEnter",["pointerout","pointerover"]);Za("onPointerLeave",["pointerout","pointerover"]);zi("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));zi("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));zi("onBeforeInput",["compositionend","keypress","textInput","paste"]);zi("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));zi("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));zi("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var hl="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(" "),PR=new Set("cancel close invalid load scroll toggle".split(" ").concat(hl));function pb(e,t,n){var r=e.type||"unknown-event";e.currentTarget=n,wD(r,t,void 0,e),e.currentTarget=null}function CE(e,t){t=(t&4)!==0;for(var n=0;n<e.length;n++){var r=e[n],o=r.event;r=r.listeners;e:{var s=void 0;if(t)for(var i=r.length-1;0<=i;i--){var a=r[i],c=a.instance,l=a.currentTarget;if(a=a.listener,c!==s&&o.isPropagationStopped())break e;pb(o,a,l),s=c}else for(i=0;i<r.length;i++){if(a=r[i],c=a.instance,l=a.currentTarget,a=a.listener,c!==s&&o.isPropagationStopped())break e;pb(o,a,l),s=c}}}if(ip)throw e=Qy,ip=!1,Qy=null,e}function Qe(e,t){var n=t[cS];n===void 0&&(n=t[cS]=new Set);var r=e+"__bubble";n.has(r)||(IE(t,e,2,!1),n.add(r))}function Kg(e,t,n){var r=0;t&&(r|=4),IE(n,e,r,t)}var ud="_reactListening"+Math.random().toString(36).slice(2);function Wl(e){if(!e[ud]){e[ud]=!0,AI.forEach(function(n){n!=="selectionchange"&&(PR.has(n)||Kg(n,!1,e),Kg(n,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[ud]||(t[ud]=!0,Kg("selectionchange",!1,t))}}function IE(e,t,n,r){switch(cE(t)){case 1:var o=LD;break;case 4:o=FD;break;default:o=Zv}n=o.bind(null,t,n,e),o=void 0,!Zy||t!=="touchstart"&&t!=="touchmove"&&t!=="wheel"||(o=!0),r?o!==void 0?e.addEventListener(t,n,{capture:!0,passive:o}):e.addEventListener(t,n,!0):o!==void 0?e.addEventListener(t,n,{passive:o}):e.addEventListener(t,n,!1)}function Wg(e,t,n,r,o){var s=r;if(!(t&1)&&!(t&2)&&r!==null)e:for(;;){if(r===null)return;var i=r.tag;if(i===3||i===4){var a=r.stateNode.containerInfo;if(a===o||a.nodeType===8&&a.parentNode===o)break;if(i===4)for(i=r.return;i!==null;){var c=i.tag;if((c===3||c===4)&&(c=i.stateNode.containerInfo,c===o||c.nodeType===8&&c.parentNode===o))return;i=i.return}for(;a!==null;){if(i=pi(a),i===null)return;if(c=i.tag,c===5||c===6){r=s=i;continue e}a=a.parentNode}}r=r.return}YI(function(){var l=s,u=Gv(n),d=[];e:{var p=PE.get(e);if(p!==void 0){var f=Jv,y=e;switch(e){case"keypress":if(ih(n)===0)break e;case"keydown":case"keyup":f=JD;break;case"focusin":y="focus",f=Fg;break;case"focusout":y="blur",f=Fg;break;case"beforeblur":case"afterblur":f=Fg;break;case"click":if(n.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":f=tb;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=BD;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=nR;break;case vE:case xE:case wE:f=KD;break;case bE:f=oR;break;case"scroll":f=ND;break;case"wheel":f=iR;break;case"copy":case"cut":case"paste":f=VD;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=rb}var g=(t&4)!==0,w=!g&&e==="scroll",S=g?p!==null?p+"Capture":null:p;g=[];for(var v=l,b;v!==null;){b=v;var E=b.stateNode;if(b.tag===5&&E!==null&&(b=E,S!==null&&(E=Nl(v,S),E!=null&&g.push(Vl(v,E,b)))),w)break;v=v.return}0<g.length&&(p=new f(p,y,null,n,u),d.push({event:p,listeners:g}))}}if(!(t&7)){e:{if(p=e==="mouseover"||e==="pointerover",f=e==="mouseout"||e==="pointerout",p&&n!==Xy&&(y=n.relatedTarget||n.fromElement)&&(pi(y)||y[zo]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(y=n.relatedTarget||n.toElement,f=l,y=y?pi(y):null,y!==null&&(w=Bi(y),y!==w||y.tag!==5&&y.tag!==6)&&(y=null)):(f=null,y=l),f!==y)){if(g=tb,E="onMouseLeave",S="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(g=rb,E="onPointerLeave",S="onPointerEnter",v="pointer"),w=f==null?p:wa(f),b=y==null?p:wa(y),p=new g(E,v+"leave",f,n,u),p.target=w,p.relatedTarget=b,E=null,pi(u)===l&&(g=new g(S,v+"enter",y,n,u),g.target=b,g.relatedTarget=w,E=g),w=E,f&&y)t:{for(g=f,S=y,v=0,b=g;b;b=Qi(b))v++;for(b=0,E=S;E;E=Qi(E))b++;for(;0<v-b;)g=Qi(g),v--;for(;0<b-v;)S=Qi(S),b--;for(;v--;){if(g===S||S!==null&&g===S.alternate)break t;g=Qi(g),S=Qi(S)}g=null}else g=null;f!==null&&fb(d,p,f,g,!1),y!==null&&w!==null&&fb(d,w,y,g,!0)}}e:{if(p=l?wa(l):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var C=pR;else if(ib(p))if(fE)C=yR;else{C=gR;var I=fR}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(C=mR);if(C&&(C=C(e,l))){pE(d,C,n,u);break e}I&&I(e,p,l),e==="focusout"&&(I=p._wrapperState)&&I.controlled&&p.type==="number"&&Ky(p,"number",p.value)}switch(I=l?wa(l):window,e){case"focusin":(ib(I)||I.contentEditable==="true")&&(va=I,nS=l,Pl=null);break;case"focusout":Pl=nS=va=null;break;case"mousedown":rS=!0;break;case"contextmenu":case"mouseup":case"dragend":rS=!1,db(d,n,u);break;case"selectionchange":if(xR)break;case"keydown":case"keyup":db(d,n,u)}var _;if(t0)e:{switch(e){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else Sa?dE(e,n)&&(k="onCompositionEnd"):e==="keydown"&&n.keyCode===229&&(k="onCompositionStart");k&&(uE&&n.locale!=="ko"&&(Sa||k!=="onCompositionStart"?k==="onCompositionEnd"&&Sa&&(_=lE()):(ws=u,Qv="value"in ws?ws.value:ws.textContent,Sa=!0)),I=dp(l,k),0<I.length&&(k=new nb(k,e,null,n,u),d.push({event:k,listeners:I}),_?k.data=_:(_=hE(n),_!==null&&(k.data=_)))),(_=cR?lR(e,n):uR(e,n))&&(l=dp(l,"onBeforeInput"),0<l.length&&(u=new nb("onBeforeInput","beforeinput",null,n,u),d.push({event:u,listeners:l}),u.data=_))}CE(d,t)})}function Vl(e,t,n){return{instance:e,listener:t,currentTarget:n}}function dp(e,t){for(var n=t+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=Nl(e,n),s!=null&&r.unshift(Vl(e,s,o)),s=Nl(e,t),s!=null&&r.push(Vl(e,s,o))),e=e.return}return r}function Qi(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function fb(e,t,n,r,o){for(var s=t._reactName,i=[];n!==null&&n!==r;){var a=n,c=a.alternate,l=a.stateNode;if(c!==null&&c===r)break;a.tag===5&&l!==null&&(a=l,o?(c=Nl(n,s),c!=null&&i.unshift(Vl(n,c,a))):o||(c=Nl(n,s),c!=null&&i.push(Vl(n,c,a)))),n=n.return}i.length!==0&&e.push({event:t,listeners:i})}var CR=/\r\n?/g,IR=/\u0000|\uFFFD/g;function gb(e){return(typeof e=="string"?e:""+e).replace(CR,`
`).replace(IR,"")}function dd(e,t,n){if(t=gb(t),gb(e)!==t&&n)throw Error(Y(425))}function hp(){}var oS=null,sS=null;function iS(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var aS=typeof setTimeout=="function"?setTimeout:void 0,ER=typeof clearTimeout=="function"?clearTimeout:void 0,mb=typeof Promise=="function"?Promise:void 0,_R=typeof queueMicrotask=="function"?queueMicrotask:typeof mb<"u"?function(e){return mb.resolve(null).then(e).catch(kR)}:aS;function kR(e){setTimeout(function(){throw e})}function Vg(e,t){var n=t,r=0;do{var o=n.nextSibling;if(e.removeChild(n),o&&o.nodeType===8)if(n=o.data,n==="/$"){if(r===0){e.removeChild(o),Ul(t);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=o}while(n);Ul(t)}function ks(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?")break;if(t==="/$")return null}}return e}function yb(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n==="$"||n==="$!"||n==="$?"){if(t===0)return e;t--}else n==="/$"&&t++}e=e.previousSibling}return null}var mc=Math.random().toString(36).slice(2),qr="__reactFiber$"+mc,Gl="__reactProps$"+mc,zo="__reactContainer$"+mc,cS="__reactEvents$"+mc,TR="__reactListeners$"+mc,$R="__reactHandles$"+mc;function pi(e){var t=e[qr];if(t)return t;for(var n=e.parentNode;n;){if(t=n[zo]||n[qr]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=yb(e);e!==null;){if(n=e[qr])return n;e=yb(e)}return t}e=n,n=e.parentNode}return null}function _u(e){return e=e[qr]||e[zo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function wa(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(Y(33))}function vf(e){return e[Gl]||null}var lS=[],ba=-1;function Ws(e){return{current:e}}function tt(e){0>ba||(e.current=lS[ba],lS[ba]=null,ba--)}function Ge(e,t){ba++,lS[ba]=e.current,e.current=t}var Rs={},rn=Ws(Rs),Tn=Ws(!1),Ci=Rs;function Qa(e,t){var n=e.type.contextTypes;if(!n)return Rs;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var o={},s;for(s in n)o[s]=t[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=o),o}function $n(e){return e=e.childContextTypes,e!=null}function pp(){tt(Tn),tt(rn)}function Sb(e,t,n){if(rn.current!==Rs)throw Error(Y(168));Ge(rn,t),Ge(Tn,n)}function EE(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var o in r)if(!(o in t))throw Error(Y(108,fD(e)||"Unknown",o));return ut({},n,r)}function fp(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Rs,Ci=rn.current,Ge(rn,e),Ge(Tn,Tn.current),!0}function vb(e,t,n){var r=e.stateNode;if(!r)throw Error(Y(169));n?(e=EE(e,t,Ci),r.__reactInternalMemoizedMergedChildContext=e,tt(Tn),tt(rn),Ge(rn,e)):tt(Tn),Ge(Tn,n)}var To=null,xf=!1,Gg=!1;function _E(e){To===null?To=[e]:To.push(e)}function MR(e){xf=!0,_E(e)}function Vs(){if(!Gg&&To!==null){Gg=!0;var e=0,t=Fe;try{var n=To;for(Fe=1;e<n.length;e++){var r=n[e];do r=r(!0);while(r!==null)}To=null,xf=!1}catch(o){throw To!==null&&(To=To.slice(e+1)),QI(Yv,Vs),o}finally{Fe=t,Gg=!1}}return null}var Pa=[],Ca=0,gp=null,mp=0,dr=[],hr=0,Ii=null,Mo=1,Ao="";function ui(e,t){Pa[Ca++]=mp,Pa[Ca++]=gp,gp=e,mp=t}function kE(e,t,n){dr[hr++]=Mo,dr[hr++]=Ao,dr[hr++]=Ii,Ii=e;var r=Mo;e=Ao;var o=32-Dr(r)-1;r&=~(1<<o),n+=1;var s=32-Dr(t)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Mo=1<<32-Dr(t)+o|n<<o|r,Ao=s+e}else Mo=1<<s|n<<o|r,Ao=e}function r0(e){e.return!==null&&(ui(e,1),kE(e,1,0))}function o0(e){for(;e===gp;)gp=Pa[--Ca],Pa[Ca]=null,mp=Pa[--Ca],Pa[Ca]=null;for(;e===Ii;)Ii=dr[--hr],dr[hr]=null,Ao=dr[--hr],dr[hr]=null,Mo=dr[--hr],dr[hr]=null}var Xn=null,Yn=null,rt=!1,$r=null;function TE(e,t){var n=fr(5,null,null,0);n.elementType="DELETED",n.stateNode=t,n.return=e,t=e.deletions,t===null?(e.deletions=[n],e.flags|=16):t.push(n)}function xb(e,t){switch(e.tag){case 5:var n=e.type;return t=t.nodeType!==1||n.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,Xn=e,Yn=ks(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,Xn=e,Yn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(n=Ii!==null?{id:Mo,overflow:Ao}:null,e.memoizedState={dehydrated:t,treeContext:n,retryLane:1073741824},n=fr(18,null,null,0),n.stateNode=t,n.return=e,e.child=n,Xn=e,Yn=null,!0):!1;default:return!1}}function uS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function dS(e){if(rt){var t=Yn;if(t){var n=t;if(!xb(e,t)){if(uS(e))throw Error(Y(418));t=ks(n.nextSibling);var r=Xn;t&&xb(e,t)?TE(r,n):(e.flags=e.flags&-4097|2,rt=!1,Xn=e)}}else{if(uS(e))throw Error(Y(418));e.flags=e.flags&-4097|2,rt=!1,Xn=e}}}function wb(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Xn=e}function hd(e){if(e!==Xn)return!1;if(!rt)return wb(e),rt=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!iS(e.type,e.memoizedProps)),t&&(t=Yn)){if(uS(e))throw $E(),Error(Y(418));for(;t;)TE(e,t),t=ks(t.nextSibling)}if(wb(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(Y(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var n=e.data;if(n==="/$"){if(t===0){Yn=ks(e.nextSibling);break e}t--}else n!=="$"&&n!=="$!"&&n!=="$?"||t++}e=e.nextSibling}Yn=null}}else Yn=Xn?ks(e.stateNode.nextSibling):null;return!0}function $E(){for(var e=Yn;e;)e=ks(e.nextSibling)}function Ja(){Yn=Xn=null,rt=!1}function s0(e){$r===null?$r=[e]:$r.push(e)}var AR=Xo.ReactCurrentBatchConfig;function Hc(e,t,n){if(e=n.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(n._owner){if(n=n._owner,n){if(n.tag!==1)throw Error(Y(309));var r=n.stateNode}if(!r)throw Error(Y(147,e));var o=r,s=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===s?t.ref:(t=function(i){var a=o.refs;i===null?delete a[s]:a[s]=i},t._stringRef=s,t)}if(typeof e!="string")throw Error(Y(284));if(!n._owner)throw Error(Y(290,e))}return e}function pd(e,t){throw e=Object.prototype.toString.call(t),Error(Y(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function bb(e){var t=e._init;return t(e._payload)}function ME(e){function t(S,v){if(e){var b=S.deletions;b===null?(S.deletions=[v],S.flags|=16):b.push(v)}}function n(S,v){if(!e)return null;for(;v!==null;)t(S,v),v=v.sibling;return null}function r(S,v){for(S=new Map;v!==null;)v.key!==null?S.set(v.key,v):S.set(v.index,v),v=v.sibling;return S}function o(S,v){return S=As(S,v),S.index=0,S.sibling=null,S}function s(S,v,b){return S.index=b,e?(b=S.alternate,b!==null?(b=b.index,b<v?(S.flags|=2,v):b):(S.flags|=2,v)):(S.flags|=1048576,v)}function i(S){return e&&S.alternate===null&&(S.flags|=2),S}function a(S,v,b,E){return v===null||v.tag!==6?(v=em(b,S.mode,E),v.return=S,v):(v=o(v,b),v.return=S,v)}function c(S,v,b,E){var C=b.type;return C===ya?u(S,v,b.props.children,E,b.key):v!==null&&(v.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===gs&&bb(C)===v.type)?(E=o(v,b.props),E.ref=Hc(S,v,b),E.return=S,E):(E=ph(b.type,b.key,b.props,null,S.mode,E),E.ref=Hc(S,v,b),E.return=S,E)}function l(S,v,b,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==b.containerInfo||v.stateNode.implementation!==b.implementation?(v=tm(b,S.mode,E),v.return=S,v):(v=o(v,b.children||[]),v.return=S,v)}function u(S,v,b,E,C){return v===null||v.tag!==7?(v=bi(b,S.mode,E,C),v.return=S,v):(v=o(v,b),v.return=S,v)}function d(S,v,b){if(typeof v=="string"&&v!==""||typeof v=="number")return v=em(""+v,S.mode,b),v.return=S,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case nd:return b=ph(v.type,v.key,v.props,null,S.mode,b),b.ref=Hc(S,null,v),b.return=S,b;case ma:return v=tm(v,S.mode,b),v.return=S,v;case gs:var E=v._init;return d(S,E(v._payload),b)}if(ul(v)||Fc(v))return v=bi(v,S.mode,b,null),v.return=S,v;pd(S,v)}return null}function p(S,v,b,E){var C=v!==null?v.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return C!==null?null:a(S,v,""+b,E);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case nd:return b.key===C?c(S,v,b,E):null;case ma:return b.key===C?l(S,v,b,E):null;case gs:return C=b._init,p(S,v,C(b._payload),E)}if(ul(b)||Fc(b))return C!==null?null:u(S,v,b,E,null);pd(S,b)}return null}function f(S,v,b,E,C){if(typeof E=="string"&&E!==""||typeof E=="number")return S=S.get(b)||null,a(v,S,""+E,C);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case nd:return S=S.get(E.key===null?b:E.key)||null,c(v,S,E,C);case ma:return S=S.get(E.key===null?b:E.key)||null,l(v,S,E,C);case gs:var I=E._init;return f(S,v,b,I(E._payload),C)}if(ul(E)||Fc(E))return S=S.get(b)||null,u(v,S,E,C,null);pd(v,E)}return null}function y(S,v,b,E){for(var C=null,I=null,_=v,k=v=0,$=null;_!==null&&k<b.length;k++){_.index>k?($=_,_=null):$=_.sibling;var T=p(S,_,b[k],E);if(T===null){_===null&&(_=$);break}e&&_&&T.alternate===null&&t(S,_),v=s(T,v,k),I===null?C=T:I.sibling=T,I=T,_=$}if(k===b.length)return n(S,_),rt&&ui(S,k),C;if(_===null){for(;k<b.length;k++)_=d(S,b[k],E),_!==null&&(v=s(_,v,k),I===null?C=_:I.sibling=_,I=_);return rt&&ui(S,k),C}for(_=r(S,_);k<b.length;k++)$=f(_,S,k,b[k],E),$!==null&&(e&&$.alternate!==null&&_.delete($.key===null?k:$.key),v=s($,v,k),I===null?C=$:I.sibling=$,I=$);return e&&_.forEach(function(O){return t(S,O)}),rt&&ui(S,k),C}function g(S,v,b,E){var C=Fc(b);if(typeof C!="function")throw Error(Y(150));if(b=C.call(b),b==null)throw Error(Y(151));for(var I=C=null,_=v,k=v=0,$=null,T=b.next();_!==null&&!T.done;k++,T=b.next()){_.index>k?($=_,_=null):$=_.sibling;var O=p(S,_,T.value,E);if(O===null){_===null&&(_=$);break}e&&_&&O.alternate===null&&t(S,_),v=s(O,v,k),I===null?C=O:I.sibling=O,I=O,_=$}if(T.done)return n(S,_),rt&&ui(S,k),C;if(_===null){for(;!T.done;k++,T=b.next())T=d(S,T.value,E),T!==null&&(v=s(T,v,k),I===null?C=T:I.sibling=T,I=T);return rt&&ui(S,k),C}for(_=r(S,_);!T.done;k++,T=b.next())T=f(_,S,k,T.value,E),T!==null&&(e&&T.alternate!==null&&_.delete(T.key===null?k:T.key),v=s(T,v,k),I===null?C=T:I.sibling=T,I=T);return e&&_.forEach(function(N){return t(S,N)}),rt&&ui(S,k),C}function w(S,v,b,E){if(typeof b=="object"&&b!==null&&b.type===ya&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case nd:e:{for(var C=b.key,I=v;I!==null;){if(I.key===C){if(C=b.type,C===ya){if(I.tag===7){n(S,I.sibling),v=o(I,b.props.children),v.return=S,S=v;break e}}else if(I.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===gs&&bb(C)===I.type){n(S,I.sibling),v=o(I,b.props),v.ref=Hc(S,I,b),v.return=S,S=v;break e}n(S,I);break}else t(S,I);I=I.sibling}b.type===ya?(v=bi(b.props.children,S.mode,E,b.key),v.return=S,S=v):(E=ph(b.type,b.key,b.props,null,S.mode,E),E.ref=Hc(S,v,b),E.return=S,S=E)}return i(S);case ma:e:{for(I=b.key;v!==null;){if(v.key===I)if(v.tag===4&&v.stateNode.containerInfo===b.containerInfo&&v.stateNode.implementation===b.implementation){n(S,v.sibling),v=o(v,b.children||[]),v.return=S,S=v;break e}else{n(S,v);break}else t(S,v);v=v.sibling}v=tm(b,S.mode,E),v.return=S,S=v}return i(S);case gs:return I=b._init,w(S,v,I(b._payload),E)}if(ul(b))return y(S,v,b,E);if(Fc(b))return g(S,v,b,E);pd(S,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,v!==null&&v.tag===6?(n(S,v.sibling),v=o(v,b),v.return=S,S=v):(n(S,v),v=em(b,S.mode,E),v.return=S,S=v),i(S)):n(S,v)}return w}var ec=ME(!0),AE=ME(!1),yp=Ws(null),Sp=null,Ia=null,i0=null;function a0(){i0=Ia=Sp=null}function c0(e){var t=yp.current;tt(yp),e._currentValue=t}function hS(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function Ba(e,t){Sp=e,i0=Ia=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(En=!0),e.firstContext=null)}function yr(e){var t=e._currentValue;if(i0!==e)if(e={context:e,memoizedValue:t,next:null},Ia===null){if(Sp===null)throw Error(Y(308));Ia=e,Sp.dependencies={lanes:0,firstContext:e}}else Ia=Ia.next=e;return t}var fi=null;function l0(e){fi===null?fi=[e]:fi.push(e)}function jE(e,t,n,r){var o=t.interleaved;return o===null?(n.next=n,l0(t)):(n.next=o.next,o.next=n),t.interleaved=n,Bo(e,r)}function Bo(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var ms=!1;function u0(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function OE(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Oo(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Ts(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,_e&2){var o=r.pending;return o===null?t.next=t:(t.next=o.next,o.next=t),r.pending=t,Bo(e,n)}return o=r.interleaved,o===null?(t.next=t,l0(r)):(t.next=o.next,o.next=t),r.interleaved=t,Bo(e,n)}function ah(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Xv(e,n)}}function Pb(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var o=null,s=null;if(n=n.firstBaseUpdate,n!==null){do{var i={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};s===null?o=s=i:s=s.next=i,n=n.next}while(n!==null);s===null?o=s=t:s=s.next=t}else o=s=t;n={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:s,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function vp(e,t,n,r){var o=e.updateQueue;ms=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var c=a,l=c.next;c.next=null,i===null?s=l:i.next=l,i=c;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=l:a.next=l,u.lastBaseUpdate=c))}if(s!==null){var d=o.baseState;i=0,u=l=c=null,a=s;do{var p=a.lane,f=a.eventTime;if((r&p)===p){u!==null&&(u=u.next={eventTime:f,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var y=e,g=a;switch(p=t,f=n,g.tag){case 1:if(y=g.payload,typeof y=="function"){d=y.call(f,d,p);break e}d=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=g.payload,p=typeof y=="function"?y.call(f,d,p):y,p==null)break e;d=ut({},d,p);break e;case 2:ms=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,p=o.effects,p===null?o.effects=[a]:p.push(a))}else f={eventTime:f,lane:p,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(l=u=f,c=d):u=u.next=f,i|=p;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;p=a,a=p.next,p.next=null,o.lastBaseUpdate=p,o.shared.pending=null}}while(!0);if(u===null&&(c=d),o.baseState=c,o.firstBaseUpdate=l,o.lastBaseUpdate=u,t=o.shared.interleaved,t!==null){o=t;do i|=o.lane,o=o.next;while(o!==t)}else s===null&&(o.shared.lanes=0);_i|=i,e.lanes=i,e.memoizedState=d}}function Cb(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],o=r.callback;if(o!==null){if(r.callback=null,r=n,typeof o!="function")throw Error(Y(191,o));o.call(r)}}}var ku={},no=Ws(ku),Yl=Ws(ku),Xl=Ws(ku);function gi(e){if(e===ku)throw Error(Y(174));return e}function d0(e,t){switch(Ge(Xl,t),Ge(Yl,e),Ge(no,ku),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Vy(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Vy(t,e)}tt(no),Ge(no,t)}function tc(){tt(no),tt(Yl),tt(Xl)}function DE(e){gi(Xl.current);var t=gi(no.current),n=Vy(t,e.type);t!==n&&(Ge(Yl,e),Ge(no,n))}function h0(e){Yl.current===e&&(tt(no),tt(Yl))}var it=Ws(0);function xp(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var Yg=[];function p0(){for(var e=0;e<Yg.length;e++)Yg[e]._workInProgressVersionPrimary=null;Yg.length=0}var ch=Xo.ReactCurrentDispatcher,Xg=Xo.ReactCurrentBatchConfig,Ei=0,lt=null,It=null,Tt=null,wp=!1,Cl=!1,ql=0,jR=0;function Vt(){throw Error(Y(321))}function f0(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!zr(e[n],t[n]))return!1;return!0}function g0(e,t,n,r,o,s){if(Ei=s,lt=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,ch.current=e===null||e.memoizedState===null?LR:FR,e=n(r,o),Cl){s=0;do{if(Cl=!1,ql=0,25<=s)throw Error(Y(301));s+=1,Tt=It=null,t.updateQueue=null,ch.current=NR,e=n(r,o)}while(Cl)}if(ch.current=bp,t=It!==null&&It.next!==null,Ei=0,Tt=It=lt=null,wp=!1,t)throw Error(Y(300));return e}function m0(){var e=ql!==0;return ql=0,e}function Yr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Tt===null?lt.memoizedState=Tt=e:Tt=Tt.next=e,Tt}function Sr(){if(It===null){var e=lt.alternate;e=e!==null?e.memoizedState:null}else e=It.next;var t=Tt===null?lt.memoizedState:Tt.next;if(t!==null)Tt=t,It=e;else{if(e===null)throw Error(Y(310));It=e,e={memoizedState:It.memoizedState,baseState:It.baseState,baseQueue:It.baseQueue,queue:It.queue,next:null},Tt===null?lt.memoizedState=Tt=e:Tt=Tt.next=e}return Tt}function Zl(e,t){return typeof t=="function"?t(e):t}function qg(e){var t=Sr(),n=t.queue;if(n===null)throw Error(Y(311));n.lastRenderedReducer=e;var r=It,o=r.baseQueue,s=n.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,n.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,c=null,l=s;do{var u=l.lane;if((Ei&u)===u)c!==null&&(c=c.next={lane:0,action:l.action,hasEagerState:l.hasEagerState,eagerState:l.eagerState,next:null}),r=l.hasEagerState?l.eagerState:e(r,l.action);else{var d={lane:u,action:l.action,hasEagerState:l.hasEagerState,eagerState:l.eagerState,next:null};c===null?(a=c=d,i=r):c=c.next=d,lt.lanes|=u,_i|=u}l=l.next}while(l!==null&&l!==s);c===null?i=r:c.next=a,zr(r,t.memoizedState)||(En=!0),t.memoizedState=r,t.baseState=i,t.baseQueue=c,n.lastRenderedState=r}if(e=n.interleaved,e!==null){o=e;do s=o.lane,lt.lanes|=s,_i|=s,o=o.next;while(o!==e)}else o===null&&(n.lanes=0);return[t.memoizedState,n.dispatch]}function Zg(e){var t=Sr(),n=t.queue;if(n===null)throw Error(Y(311));n.lastRenderedReducer=e;var r=n.dispatch,o=n.pending,s=t.memoizedState;if(o!==null){n.pending=null;var i=o=o.next;do s=e(s,i.action),i=i.next;while(i!==o);zr(s,t.memoizedState)||(En=!0),t.memoizedState=s,t.baseQueue===null&&(t.baseState=s),n.lastRenderedState=s}return[s,r]}function RE(){}function LE(e,t){var n=lt,r=Sr(),o=t(),s=!zr(r.memoizedState,o);if(s&&(r.memoizedState=o,En=!0),r=r.queue,y0(zE.bind(null,n,r,e),[e]),r.getSnapshot!==t||s||Tt!==null&&Tt.memoizedState.tag&1){if(n.flags|=2048,Ql(9,NE.bind(null,n,r,o,t),void 0,null),At===null)throw Error(Y(349));Ei&30||FE(n,t,o)}return o}function FE(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=lt.updateQueue,t===null?(t={lastEffect:null,stores:null},lt.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function NE(e,t,n,r){t.value=n,t.getSnapshot=r,BE(t)&&UE(e)}function zE(e,t,n){return n(function(){BE(t)&&UE(e)})}function BE(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!zr(e,n)}catch{return!0}}function UE(e){var t=Bo(e,1);t!==null&&Rr(t,e,1,-1)}function Ib(e){var t=Yr();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Zl,lastRenderedState:e},t.queue=e,e=e.dispatch=RR.bind(null,lt,e),[t.memoizedState,e]}function Ql(e,t,n,r){return e={tag:e,create:t,destroy:n,deps:r,next:null},t=lt.updateQueue,t===null?(t={lastEffect:null,stores:null},lt.updateQueue=t,t.lastEffect=e.next=e):(n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e)),e}function HE(){return Sr().memoizedState}function lh(e,t,n,r){var o=Yr();lt.flags|=e,o.memoizedState=Ql(1|t,n,void 0,r===void 0?null:r)}function wf(e,t,n,r){var o=Sr();r=r===void 0?null:r;var s=void 0;if(It!==null){var i=It.memoizedState;if(s=i.destroy,r!==null&&f0(r,i.deps)){o.memoizedState=Ql(t,n,s,r);return}}lt.flags|=e,o.memoizedState=Ql(1|t,n,s,r)}function Eb(e,t){return lh(8390656,8,e,t)}function y0(e,t){return wf(2048,8,e,t)}function KE(e,t){return wf(4,2,e,t)}function WE(e,t){return wf(4,4,e,t)}function VE(e,t){if(typeof t=="function")return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function GE(e,t,n){return n=n!=null?n.concat([e]):null,wf(4,4,VE.bind(null,t,e),n)}function S0(){}function YE(e,t){var n=Sr();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&f0(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function XE(e,t){var n=Sr();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&f0(t,r[1])?r[0]:(e=e(),n.memoizedState=[e,t],e)}function qE(e,t,n){return Ei&21?(zr(n,t)||(n=tE(),lt.lanes|=n,_i|=n,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,En=!0),e.memoizedState=n)}function OR(e,t){var n=Fe;Fe=n!==0&&4>n?n:4,e(!0);var r=Xg.transition;Xg.transition={};try{e(!1),t()}finally{Fe=n,Xg.transition=r}}function ZE(){return Sr().memoizedState}function DR(e,t,n){var r=Ms(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},QE(e))JE(t,n);else if(n=jE(e,t,n,r),n!==null){var o=gn();Rr(n,e,r,o),e_(n,t,r)}}function RR(e,t,n){var r=Ms(e),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(QE(e))JE(t,o);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=t.lastRenderedReducer,s!==null))try{var i=t.lastRenderedState,a=s(i,n);if(o.hasEagerState=!0,o.eagerState=a,zr(a,i)){var c=t.interleaved;c===null?(o.next=o,l0(t)):(o.next=c.next,c.next=o),t.interleaved=o;return}}catch{}finally{}n=jE(e,t,o,r),n!==null&&(o=gn(),Rr(n,e,r,o),e_(n,t,r))}}function QE(e){var t=e.alternate;return e===lt||t!==null&&t===lt}function JE(e,t){Cl=wp=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function e_(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Xv(e,n)}}var bp={readContext:yr,useCallback:Vt,useContext:Vt,useEffect:Vt,useImperativeHandle:Vt,useInsertionEffect:Vt,useLayoutEffect:Vt,useMemo:Vt,useReducer:Vt,useRef:Vt,useState:Vt,useDebugValue:Vt,useDeferredValue:Vt,useTransition:Vt,useMutableSource:Vt,useSyncExternalStore:Vt,useId:Vt,unstable_isNewReconciler:!1},LR={readContext:yr,useCallback:function(e,t){return Yr().memoizedState=[e,t===void 0?null:t],e},useContext:yr,useEffect:Eb,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,lh(4194308,4,VE.bind(null,t,e),n)},useLayoutEffect:function(e,t){return lh(4194308,4,e,t)},useInsertionEffect:function(e,t){return lh(4,2,e,t)},useMemo:function(e,t){var n=Yr();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Yr();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=DR.bind(null,lt,e),[r.memoizedState,e]},useRef:function(e){var t=Yr();return e={current:e},t.memoizedState=e},useState:Ib,useDebugValue:S0,useDeferredValue:function(e){return Yr().memoizedState=e},useTransition:function(){var e=Ib(!1),t=e[0];return e=OR.bind(null,e[1]),Yr().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=lt,o=Yr();if(rt){if(n===void 0)throw Error(Y(407));n=n()}else{if(n=t(),At===null)throw Error(Y(349));Ei&30||FE(r,t,n)}o.memoizedState=n;var s={value:n,getSnapshot:t};return o.queue=s,Eb(zE.bind(null,r,s,e),[e]),r.flags|=2048,Ql(9,NE.bind(null,r,s,n,t),void 0,null),n},useId:function(){var e=Yr(),t=At.identifierPrefix;if(rt){var n=Ao,r=Mo;n=(r&~(1<<32-Dr(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=ql++,0<n&&(t+="H"+n.toString(32)),t+=":"}else n=jR++,t=":"+t+"r"+n.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},FR={readContext:yr,useCallback:YE,useContext:yr,useEffect:y0,useImperativeHandle:GE,useInsertionEffect:KE,useLayoutEffect:WE,useMemo:XE,useReducer:qg,useRef:HE,useState:function(){return qg(Zl)},useDebugValue:S0,useDeferredValue:function(e){var t=Sr();return qE(t,It.memoizedState,e)},useTransition:function(){var e=qg(Zl)[0],t=Sr().memoizedState;return[e,t]},useMutableSource:RE,useSyncExternalStore:LE,useId:ZE,unstable_isNewReconciler:!1},NR={readContext:yr,useCallback:YE,useContext:yr,useEffect:y0,useImperativeHandle:GE,useInsertionEffect:KE,useLayoutEffect:WE,useMemo:XE,useReducer:Zg,useRef:HE,useState:function(){return Zg(Zl)},useDebugValue:S0,useDeferredValue:function(e){var t=Sr();return It===null?t.memoizedState=e:qE(t,It.memoizedState,e)},useTransition:function(){var e=Zg(Zl)[0],t=Sr().memoizedState;return[e,t]},useMutableSource:RE,useSyncExternalStore:LE,useId:ZE,unstable_isNewReconciler:!1};function Ir(e,t){if(e&&e.defaultProps){t=ut({},t),e=e.defaultProps;for(var n in e)t[n]===void 0&&(t[n]=e[n]);return t}return t}function pS(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:ut({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var bf={isMounted:function(e){return(e=e._reactInternals)?Bi(e)===e:!1},enqueueSetState:function(e,t,n){e=e._reactInternals;var r=gn(),o=Ms(e),s=Oo(r,o);s.payload=t,n!=null&&(s.callback=n),t=Ts(e,s,o),t!==null&&(Rr(t,e,o,r),ah(t,e,o))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=gn(),o=Ms(e),s=Oo(r,o);s.tag=1,s.payload=t,n!=null&&(s.callback=n),t=Ts(e,s,o),t!==null&&(Rr(t,e,o,r),ah(t,e,o))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=gn(),r=Ms(e),o=Oo(n,r);o.tag=2,t!=null&&(o.callback=t),t=Ts(e,o,r),t!==null&&(Rr(t,e,r,n),ah(t,e,r))}};function _b(e,t,n,r,o,s,i){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,s,i):t.prototype&&t.prototype.isPureReactComponent?!Kl(n,r)||!Kl(o,s):!0}function t_(e,t,n){var r=!1,o=Rs,s=t.contextType;return typeof s=="object"&&s!==null?s=yr(s):(o=$n(t)?Ci:rn.current,r=t.contextTypes,s=(r=r!=null)?Qa(e,o):Rs),t=new t(n,s),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=bf,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),t}function kb(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps=="function"&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps=="function"&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&bf.enqueueReplaceState(t,t.state,null)}function fS(e,t,n,r){var o=e.stateNode;o.props=n,o.state=e.memoizedState,o.refs={},u0(e);var s=t.contextType;typeof s=="object"&&s!==null?o.context=yr(s):(s=$n(t)?Ci:rn.current,o.context=Qa(e,s)),o.state=e.memoizedState,s=t.getDerivedStateFromProps,typeof s=="function"&&(pS(e,t,s,n),o.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof o.getSnapshotBeforeUpdate=="function"||typeof o.UNSAFE_componentWillMount!="function"&&typeof o.componentWillMount!="function"||(t=o.state,typeof o.componentWillMount=="function"&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount=="function"&&o.UNSAFE_componentWillMount(),t!==o.state&&bf.enqueueReplaceState(o,o.state,null),vp(e,n,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function nc(e,t){try{var n="",r=t;do n+=pD(r),r=r.return;while(r);var o=n}catch(s){o=`
Error generating stack: `+s.message+`
`+s.stack}return{value:e,source:t,stack:o,digest:null}}function Qg(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function gS(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var zR=typeof WeakMap=="function"?WeakMap:Map;function n_(e,t,n){n=Oo(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){Cp||(Cp=!0,IS=r),gS(e,t)},n}function r_(e,t,n){n=Oo(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var o=t.value;n.payload=function(){return r(o)},n.callback=function(){gS(e,t)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){gS(e,t),typeof r!="function"&&($s===null?$s=new Set([this]):$s.add(this));var i=t.stack;this.componentDidCatch(t.value,{componentStack:i!==null?i:""})}),n}function Tb(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new zR;var o=new Set;r.set(t,o)}else o=r.get(t),o===void 0&&(o=new Set,r.set(t,o));o.has(n)||(o.add(n),e=e3.bind(null,e,t,n),t.then(e,e))}function $b(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function Mb(e,t,n,r,o){return e.mode&1?(e.flags|=65536,e.lanes=o,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=Oo(-1,1),t.tag=2,Ts(n,t,1))),n.lanes|=1),e)}var BR=Xo.ReactCurrentOwner,En=!1;function un(e,t,n,r){t.child=e===null?AE(t,null,n,r):ec(t,e.child,n,r)}function Ab(e,t,n,r,o){n=n.render;var s=t.ref;return Ba(t,o),r=g0(e,t,n,r,s,o),n=m0(),e!==null&&!En?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~o,Uo(e,t,o)):(rt&&n&&r0(t),t.flags|=1,un(e,t,r,o),t.child)}function jb(e,t,n,r,o){if(e===null){var s=n.type;return typeof s=="function"&&!E0(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=s,o_(e,t,s,r,o)):(e=ph(n.type,null,r,t,t.mode,o),e.ref=t.ref,e.return=t,t.child=e)}if(s=e.child,!(e.lanes&o)){var i=s.memoizedProps;if(n=n.compare,n=n!==null?n:Kl,n(i,r)&&e.ref===t.ref)return Uo(e,t,o)}return t.flags|=1,e=As(s,r),e.ref=t.ref,e.return=t,t.child=e}function o_(e,t,n,r,o){if(e!==null){var s=e.memoizedProps;if(Kl(s,r)&&e.ref===t.ref)if(En=!1,t.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(En=!0);else return t.lanes=e.lanes,Uo(e,t,o)}return mS(e,t,n,r,o)}function s_(e,t,n){var r=t.pendingProps,o=r.children,s=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ge(_a,Hn),Hn|=n;else{if(!(n&1073741824))return e=s!==null?s.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,Ge(_a,Hn),Hn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,Ge(_a,Hn),Hn|=r}else s!==null?(r=s.baseLanes|n,t.memoizedState=null):r=n,Ge(_a,Hn),Hn|=r;return un(e,t,o,n),t.child}function i_(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function mS(e,t,n,r,o){var s=$n(n)?Ci:rn.current;return s=Qa(t,s),Ba(t,o),n=g0(e,t,n,r,s,o),r=m0(),e!==null&&!En?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~o,Uo(e,t,o)):(rt&&r&&r0(t),t.flags|=1,un(e,t,n,o),t.child)}function Ob(e,t,n,r,o){if($n(n)){var s=!0;fp(t)}else s=!1;if(Ba(t,o),t.stateNode===null)uh(e,t),t_(t,n,r),fS(t,n,r,o),r=!0;else if(e===null){var i=t.stateNode,a=t.memoizedProps;i.props=a;var c=i.context,l=n.contextType;typeof l=="object"&&l!==null?l=yr(l):(l=$n(n)?Ci:rn.current,l=Qa(t,l));var u=n.getDerivedStateFromProps,d=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";d||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||c!==l)&&kb(t,i,r,l),ms=!1;var p=t.memoizedState;i.state=p,vp(t,r,i,o),c=t.memoizedState,a!==r||p!==c||Tn.current||ms?(typeof u=="function"&&(pS(t,n,u,r),c=t.memoizedState),(a=ms||_b(t,n,a,r,p,c,l))?(d||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(t.flags|=4194308)):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),i.props=r,i.state=c,i.context=l,r=a):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{i=t.stateNode,OE(e,t),a=t.memoizedProps,l=t.type===t.elementType?a:Ir(t.type,a),i.props=l,d=t.pendingProps,p=i.context,c=n.contextType,typeof c=="object"&&c!==null?c=yr(c):(c=$n(n)?Ci:rn.current,c=Qa(t,c));var f=n.getDerivedStateFromProps;(u=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==d||p!==c)&&kb(t,i,r,c),ms=!1,p=t.memoizedState,i.state=p,vp(t,r,i,o);var y=t.memoizedState;a!==d||p!==y||Tn.current||ms?(typeof f=="function"&&(pS(t,n,f,r),y=t.memoizedState),(l=ms||_b(t,n,l,r,p,y,c)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,y,c),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,y,c)),typeof i.componentDidUpdate=="function"&&(t.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=y),i.props=r,i.state=y,i.context=c,r=l):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),r=!1)}return yS(e,t,n,r,s,o)}function yS(e,t,n,r,o,s){i_(e,t);var i=(t.flags&128)!==0;if(!r&&!i)return o&&vb(t,n,!1),Uo(e,t,s);r=t.stateNode,BR.current=t;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&i?(t.child=ec(t,e.child,null,s),t.child=ec(t,null,a,s)):un(e,t,a,s),t.memoizedState=r.state,o&&vb(t,n,!0),t.child}function a_(e){var t=e.stateNode;t.pendingContext?Sb(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Sb(e,t.context,!1),d0(e,t.containerInfo)}function Db(e,t,n,r,o){return Ja(),s0(o),t.flags|=256,un(e,t,n,r),t.child}var SS={dehydrated:null,treeContext:null,retryLane:0};function vS(e){return{baseLanes:e,cachePool:null,transitions:null}}function c_(e,t,n){var r=t.pendingProps,o=it.current,s=!1,i=(t.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(s=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ge(it,o&1),e===null)return dS(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(i=r.children,e=r.fallback,s?(r=t.mode,s=t.child,i={mode:"hidden",children:i},!(r&1)&&s!==null?(s.childLanes=0,s.pendingProps=i):s=If(i,r,0,null),e=bi(e,r,n,null),s.return=t,e.return=t,s.sibling=e,t.child=s,t.child.memoizedState=vS(n),t.memoizedState=SS,e):v0(t,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return UR(e,t,i,r,a,o,n);if(s){s=r.fallback,i=t.mode,o=e.child,a=o.sibling;var c={mode:"hidden",children:r.children};return!(i&1)&&t.child!==o?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=As(o,c),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=As(a,s):(s=bi(s,i,n,null),s.flags|=2),s.return=t,r.return=t,r.sibling=s,t.child=r,r=s,s=t.child,i=e.child.memoizedState,i=i===null?vS(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~n,t.memoizedState=SS,r}return s=e.child,e=s.sibling,r=As(s,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function v0(e,t){return t=If({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function fd(e,t,n,r){return r!==null&&s0(r),ec(t,e.child,null,n),e=v0(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function UR(e,t,n,r,o,s,i){if(n)return t.flags&256?(t.flags&=-257,r=Qg(Error(Y(422))),fd(e,t,i,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(s=r.fallback,o=t.mode,r=If({mode:"visible",children:r.children},o,0,null),s=bi(s,o,i,null),s.flags|=2,r.return=t,s.return=t,r.sibling=s,t.child=r,t.mode&1&&ec(t,e.child,null,i),t.child.memoizedState=vS(i),t.memoizedState=SS,s);if(!(t.mode&1))return fd(e,t,i,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var a=r.dgst;return r=a,s=Error(Y(419)),r=Qg(s,r,void 0),fd(e,t,i,r)}if(a=(i&e.childLanes)!==0,En||a){if(r=At,r!==null){switch(i&-i){case 4:o=2;break;case 16:o=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:o=32;break;case 536870912:o=268435456;break;default:o=0}o=o&(r.suspendedLanes|i)?0:o,o!==0&&o!==s.retryLane&&(s.retryLane=o,Bo(e,o),Rr(r,e,o,-1))}return I0(),r=Qg(Error(Y(421))),fd(e,t,i,r)}return o.data==="$?"?(t.flags|=128,t.child=e.child,t=t3.bind(null,e),o._reactRetry=t,null):(e=s.treeContext,Yn=ks(o.nextSibling),Xn=t,rt=!0,$r=null,e!==null&&(dr[hr++]=Mo,dr[hr++]=Ao,dr[hr++]=Ii,Mo=e.id,Ao=e.overflow,Ii=t),t=v0(t,r.children),t.flags|=4096,t)}function Rb(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),hS(e.return,t,n)}function Jg(e,t,n,r,o){var s=e.memoizedState;s===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:o}:(s.isBackwards=t,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=n,s.tailMode=o)}function l_(e,t,n){var r=t.pendingProps,o=r.revealOrder,s=r.tail;if(un(e,t,r.children,n),r=it.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Rb(e,n,t);else if(e.tag===19)Rb(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Ge(it,r),!(t.mode&1))t.memoizedState=null;else switch(o){case"forwards":for(n=t.child,o=null;n!==null;)e=n.alternate,e!==null&&xp(e)===null&&(o=n),n=n.sibling;n=o,n===null?(o=t.child,t.child=null):(o=n.sibling,n.sibling=null),Jg(t,!1,o,n,s);break;case"backwards":for(n=null,o=t.child,t.child=null;o!==null;){if(e=o.alternate,e!==null&&xp(e)===null){t.child=o;break}e=o.sibling,o.sibling=n,n=o,o=e}Jg(t,!0,n,null,s);break;case"together":Jg(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function uh(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Uo(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),_i|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(Y(153));if(t.child!==null){for(e=t.child,n=As(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=As(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function HR(e,t,n){switch(t.tag){case 3:a_(t),Ja();break;case 5:DE(t);break;case 1:$n(t.type)&&fp(t);break;case 4:d0(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,o=t.memoizedProps.value;Ge(yp,r._currentValue),r._currentValue=o;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(Ge(it,it.current&1),t.flags|=128,null):n&t.child.childLanes?c_(e,t,n):(Ge(it,it.current&1),e=Uo(e,t,n),e!==null?e.sibling:null);Ge(it,it.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return l_(e,t,n);t.flags|=128}if(o=t.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ge(it,it.current),r)break;return null;case 22:case 23:return t.lanes=0,s_(e,t,n)}return Uo(e,t,n)}var u_,xS,d_,h_;u_=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};xS=function(){};d_=function(e,t,n,r){var o=e.memoizedProps;if(o!==r){e=t.stateNode,gi(no.current);var s=null;switch(n){case"input":o=Uy(e,o),r=Uy(e,r),s=[];break;case"select":o=ut({},o,{value:void 0}),r=ut({},r,{value:void 0}),s=[];break;case"textarea":o=Wy(e,o),r=Wy(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=hp)}Gy(n,r);var i;n=null;for(l in o)if(!r.hasOwnProperty(l)&&o.hasOwnProperty(l)&&o[l]!=null)if(l==="style"){var a=o[l];for(i in a)a.hasOwnProperty(i)&&(n||(n={}),n[i]="")}else l!=="dangerouslySetInnerHTML"&&l!=="children"&&l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&l!=="autoFocus"&&(Ll.hasOwnProperty(l)?s||(s=[]):(s=s||[]).push(l,null));for(l in r){var c=r[l];if(a=o!=null?o[l]:void 0,r.hasOwnProperty(l)&&c!==a&&(c!=null||a!=null))if(l==="style")if(a){for(i in a)!a.hasOwnProperty(i)||c&&c.hasOwnProperty(i)||(n||(n={}),n[i]="");for(i in c)c.hasOwnProperty(i)&&a[i]!==c[i]&&(n||(n={}),n[i]=c[i])}else n||(s||(s=[]),s.push(l,n)),n=c;else l==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,a=a?a.__html:void 0,c!=null&&a!==c&&(s=s||[]).push(l,c)):l==="children"?typeof c!="string"&&typeof c!="number"||(s=s||[]).push(l,""+c):l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&(Ll.hasOwnProperty(l)?(c!=null&&l==="onScroll"&&Qe("scroll",e),s||a===c||(s=[])):(s=s||[]).push(l,c))}n&&(s=s||[]).push("style",n);var l=s;(t.updateQueue=l)&&(t.flags|=4)}};h_=function(e,t,n,r){n!==r&&(t.flags|=4)};function Kc(e,t){if(!rt)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Gt(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var o=e.child;o!==null;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags&14680064,r|=o.flags&14680064,o.return=e,o=o.sibling;else for(o=e.child;o!==null;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags,r|=o.flags,o.return=e,o=o.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function KR(e,t,n){var r=t.pendingProps;switch(o0(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Gt(t),null;case 1:return $n(t.type)&&pp(),Gt(t),null;case 3:return r=t.stateNode,tc(),tt(Tn),tt(rn),p0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(hd(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,$r!==null&&(kS($r),$r=null))),xS(e,t),Gt(t),null;case 5:h0(t);var o=gi(Xl.current);if(n=t.type,e!==null&&t.stateNode!=null)d_(e,t,n,r,o),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(Y(166));return Gt(t),null}if(e=gi(no.current),hd(t)){r=t.stateNode,n=t.type;var s=t.memoizedProps;switch(r[qr]=t,r[Gl]=s,e=(t.mode&1)!==0,n){case"dialog":Qe("cancel",r),Qe("close",r);break;case"iframe":case"object":case"embed":Qe("load",r);break;case"video":case"audio":for(o=0;o<hl.length;o++)Qe(hl[o],r);break;case"source":Qe("error",r);break;case"img":case"image":case"link":Qe("error",r),Qe("load",r);break;case"details":Qe("toggle",r);break;case"input":Ww(r,s),Qe("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Qe("invalid",r);break;case"textarea":Gw(r,s),Qe("invalid",r)}Gy(n,s),o=null;for(var i in s)if(s.hasOwnProperty(i)){var a=s[i];i==="children"?typeof a=="string"?r.textContent!==a&&(s.suppressHydrationWarning!==!0&&dd(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&dd(r.textContent,a,e),o=["children",""+a]):Ll.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Qe("scroll",r)}switch(n){case"input":rd(r),Vw(r,s,!0);break;case"textarea":rd(r),Yw(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=hp)}r=o,t.updateQueue=r,r!==null&&(t.flags|=4)}else{i=o.nodeType===9?o:o.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=zI(n)),e==="http://www.w3.org/1999/xhtml"?n==="script"?(e=i.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(n,{is:r.is}):(e=i.createElement(n),n==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,n),e[qr]=t,e[Gl]=r,u_(e,t,!1,!1),t.stateNode=e;e:{switch(i=Yy(n,r),n){case"dialog":Qe("cancel",e),Qe("close",e),o=r;break;case"iframe":case"object":case"embed":Qe("load",e),o=r;break;case"video":case"audio":for(o=0;o<hl.length;o++)Qe(hl[o],e);o=r;break;case"source":Qe("error",e),o=r;break;case"img":case"image":case"link":Qe("error",e),Qe("load",e),o=r;break;case"details":Qe("toggle",e),o=r;break;case"input":Ww(e,r),o=Uy(e,r),Qe("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=ut({},r,{value:void 0}),Qe("invalid",e);break;case"textarea":Gw(e,r),o=Wy(e,r),Qe("invalid",e);break;default:o=r}Gy(n,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var c=a[s];s==="style"?HI(e,c):s==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&BI(e,c)):s==="children"?typeof c=="string"?(n!=="textarea"||c!=="")&&Fl(e,c):typeof c=="number"&&Fl(e,""+c):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Ll.hasOwnProperty(s)?c!=null&&s==="onScroll"&&Qe("scroll",e):c!=null&&Hv(e,s,c,i))}switch(n){case"input":rd(e),Vw(e,r,!1);break;case"textarea":rd(e),Yw(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Ds(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?La(e,!!r.multiple,s,!1):r.defaultValue!=null&&La(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=hp)}switch(n){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return Gt(t),null;case 6:if(e&&t.stateNode!=null)h_(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(Y(166));if(n=gi(Xl.current),gi(no.current),hd(t)){if(r=t.stateNode,n=t.memoizedProps,r[qr]=t,(s=r.nodeValue!==n)&&(e=Xn,e!==null))switch(e.tag){case 3:dd(r.nodeValue,n,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&dd(r.nodeValue,n,(e.mode&1)!==0)}s&&(t.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[qr]=t,t.stateNode=r}return Gt(t),null;case 13:if(tt(it),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(rt&&Yn!==null&&t.mode&1&&!(t.flags&128))$E(),Ja(),t.flags|=98560,s=!1;else if(s=hd(t),r!==null&&r.dehydrated!==null){if(e===null){if(!s)throw Error(Y(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(Y(317));s[qr]=t}else Ja(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Gt(t),s=!1}else $r!==null&&(kS($r),$r=null),s=!0;if(!s)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||it.current&1?Et===0&&(Et=3):I0())),t.updateQueue!==null&&(t.flags|=4),Gt(t),null);case 4:return tc(),xS(e,t),e===null&&Wl(t.stateNode.containerInfo),Gt(t),null;case 10:return c0(t.type._context),Gt(t),null;case 17:return $n(t.type)&&pp(),Gt(t),null;case 19:if(tt(it),s=t.memoizedState,s===null)return Gt(t),null;if(r=(t.flags&128)!==0,i=s.rendering,i===null)if(r)Kc(s,!1);else{if(Et!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(i=xp(e),i!==null){for(t.flags|=128,Kc(s,!1),r=i.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=n,n=t.child;n!==null;)s=n,e=r,s.flags&=14680066,i=s.alternate,i===null?(s.childLanes=0,s.lanes=e,s.child=null,s.subtreeFlags=0,s.memoizedProps=null,s.memoizedState=null,s.updateQueue=null,s.dependencies=null,s.stateNode=null):(s.childLanes=i.childLanes,s.lanes=i.lanes,s.child=i.child,s.subtreeFlags=0,s.deletions=null,s.memoizedProps=i.memoizedProps,s.memoizedState=i.memoizedState,s.updateQueue=i.updateQueue,s.type=i.type,e=i.dependencies,s.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),n=n.sibling;return Ge(it,it.current&1|2),t.child}e=e.sibling}s.tail!==null&&St()>rc&&(t.flags|=128,r=!0,Kc(s,!1),t.lanes=4194304)}else{if(!r)if(e=xp(i),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Kc(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!rt)return Gt(t),null}else 2*St()-s.renderingStartTime>rc&&n!==1073741824&&(t.flags|=128,r=!0,Kc(s,!1),t.lanes=4194304);s.isBackwards?(i.sibling=t.child,t.child=i):(n=s.last,n!==null?n.sibling=i:t.child=i,s.last=i)}return s.tail!==null?(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=St(),t.sibling=null,n=it.current,Ge(it,r?n&1|2:n&1),t):(Gt(t),null);case 22:case 23:return C0(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Hn&1073741824&&(Gt(t),t.subtreeFlags&6&&(t.flags|=8192)):Gt(t),null;case 24:return null;case 25:return null}throw Error(Y(156,t.tag))}function WR(e,t){switch(o0(t),t.tag){case 1:return $n(t.type)&&pp(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return tc(),tt(Tn),tt(rn),p0(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return h0(t),null;case 13:if(tt(it),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(Y(340));Ja()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return tt(it),null;case 4:return tc(),null;case 10:return c0(t.type._context),null;case 22:case 23:return C0(),null;case 24:return null;default:return null}}var gd=!1,Qt=!1,VR=typeof WeakSet=="function"?WeakSet:Set,te=null;function Ea(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ft(e,t,r)}else n.current=null}function wS(e,t,n){try{n()}catch(r){ft(e,t,r)}}var Lb=!1;function GR(e,t){if(oS=lp,e=yE(),n0(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var i=0,a=-1,c=-1,l=0,u=0,d=e,p=null;t:for(;;){for(var f;d!==n||o!==0&&d.nodeType!==3||(a=i+o),d!==s||r!==0&&d.nodeType!==3||(c=i+r),d.nodeType===3&&(i+=d.nodeValue.length),(f=d.firstChild)!==null;)p=d,d=f;for(;;){if(d===e)break t;if(p===n&&++l===o&&(a=i),p===s&&++u===r&&(c=i),(f=d.nextSibling)!==null)break;d=p,p=d.parentNode}d=f}n=a===-1||c===-1?null:{start:a,end:c}}else n=null}n=n||{start:0,end:0}}else n=null;for(sS={focusedElem:e,selectionRange:n},lp=!1,te=t;te!==null;)if(t=te,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,te=e;else for(;te!==null;){t=te;try{var y=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var g=y.memoizedProps,w=y.memoizedState,S=t.stateNode,v=S.getSnapshotBeforeUpdate(t.elementType===t.type?g:Ir(t.type,g),w);S.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var b=t.stateNode.containerInfo;b.nodeType===1?b.textContent="":b.nodeType===9&&b.documentElement&&b.removeChild(b.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Y(163))}}catch(E){ft(t,t.return,E)}if(e=t.sibling,e!==null){e.return=t.return,te=e;break}te=t.return}return y=Lb,Lb=!1,y}function Il(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var o=r=r.next;do{if((o.tag&e)===e){var s=o.destroy;o.destroy=void 0,s!==void 0&&wS(t,n,s)}o=o.next}while(o!==r)}}function Pf(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function bS(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function p_(e){var t=e.alternate;t!==null&&(e.alternate=null,p_(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[qr],delete t[Gl],delete t[cS],delete t[TR],delete t[$R])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function f_(e){return e.tag===5||e.tag===3||e.tag===4}function Fb(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||f_(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function PS(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=hp));else if(r!==4&&(e=e.child,e!==null))for(PS(e,t,n),e=e.sibling;e!==null;)PS(e,t,n),e=e.sibling}function CS(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(CS(e,t,n),e=e.sibling;e!==null;)CS(e,t,n),e=e.sibling}var Rt=null,Er=!1;function ls(e,t,n){for(n=n.child;n!==null;)g_(e,t,n),n=n.sibling}function g_(e,t,n){if(to&&typeof to.onCommitFiberUnmount=="function")try{to.onCommitFiberUnmount(gf,n)}catch{}switch(n.tag){case 5:Qt||Ea(n,t);case 6:var r=Rt,o=Er;Rt=null,ls(e,t,n),Rt=r,Er=o,Rt!==null&&(Er?(e=Rt,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Rt.removeChild(n.stateNode));break;case 18:Rt!==null&&(Er?(e=Rt,n=n.stateNode,e.nodeType===8?Vg(e.parentNode,n):e.nodeType===1&&Vg(e,n),Ul(e)):Vg(Rt,n.stateNode));break;case 4:r=Rt,o=Er,Rt=n.stateNode.containerInfo,Er=!0,ls(e,t,n),Rt=r,Er=o;break;case 0:case 11:case 14:case 15:if(!Qt&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var s=o,i=s.destroy;s=s.tag,i!==void 0&&(s&2||s&4)&&wS(n,t,i),o=o.next}while(o!==r)}ls(e,t,n);break;case 1:if(!Qt&&(Ea(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){ft(n,t,a)}ls(e,t,n);break;case 21:ls(e,t,n);break;case 22:n.mode&1?(Qt=(r=Qt)||n.memoizedState!==null,ls(e,t,n),Qt=r):ls(e,t,n);break;default:ls(e,t,n)}}function Nb(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new VR),t.forEach(function(r){var o=n3.bind(null,e,r);n.has(r)||(n.add(r),r.then(o,o))})}}function Cr(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var o=n[r];try{var s=e,i=t,a=i;e:for(;a!==null;){switch(a.tag){case 5:Rt=a.stateNode,Er=!1;break e;case 3:Rt=a.stateNode.containerInfo,Er=!0;break e;case 4:Rt=a.stateNode.containerInfo,Er=!0;break e}a=a.return}if(Rt===null)throw Error(Y(160));g_(s,i,o),Rt=null,Er=!1;var c=o.alternate;c!==null&&(c.return=null),o.return=null}catch(l){ft(o,t,l)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)m_(t,e),t=t.sibling}function m_(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Cr(t,e),Vr(e),r&4){try{Il(3,e,e.return),Pf(3,e)}catch(g){ft(e,e.return,g)}try{Il(5,e,e.return)}catch(g){ft(e,e.return,g)}}break;case 1:Cr(t,e),Vr(e),r&512&&n!==null&&Ea(n,n.return);break;case 5:if(Cr(t,e),Vr(e),r&512&&n!==null&&Ea(n,n.return),e.flags&32){var o=e.stateNode;try{Fl(o,"")}catch(g){ft(e,e.return,g)}}if(r&4&&(o=e.stateNode,o!=null)){var s=e.memoizedProps,i=n!==null?n.memoizedProps:s,a=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&FI(o,s),Yy(a,i);var l=Yy(a,s);for(i=0;i<c.length;i+=2){var u=c[i],d=c[i+1];u==="style"?HI(o,d):u==="dangerouslySetInnerHTML"?BI(o,d):u==="children"?Fl(o,d):Hv(o,u,d,l)}switch(a){case"input":Hy(o,s);break;case"textarea":NI(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?La(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?La(o,!!s.multiple,s.defaultValue,!0):La(o,!!s.multiple,s.multiple?[]:"",!1))}o[Gl]=s}catch(g){ft(e,e.return,g)}}break;case 6:if(Cr(t,e),Vr(e),r&4){if(e.stateNode===null)throw Error(Y(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(g){ft(e,e.return,g)}}break;case 3:if(Cr(t,e),Vr(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{Ul(t.containerInfo)}catch(g){ft(e,e.return,g)}break;case 4:Cr(t,e),Vr(e);break;case 13:Cr(t,e),Vr(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(b0=St())),r&4&&Nb(e);break;case 22:if(u=n!==null&&n.memoizedState!==null,e.mode&1?(Qt=(l=Qt)||u,Cr(t,e),Qt=l):Cr(t,e),Vr(e),r&8192){if(l=e.memoizedState!==null,(e.stateNode.isHidden=l)&&!u&&e.mode&1)for(te=e,u=e.child;u!==null;){for(d=te=u;te!==null;){switch(p=te,f=p.child,p.tag){case 0:case 11:case 14:case 15:Il(4,p,p.return);break;case 1:Ea(p,p.return);var y=p.stateNode;if(typeof y.componentWillUnmount=="function"){r=p,n=p.return;try{t=r,y.props=t.memoizedProps,y.state=t.memoizedState,y.componentWillUnmount()}catch(g){ft(r,n,g)}}break;case 5:Ea(p,p.return);break;case 22:if(p.memoizedState!==null){Bb(d);continue}}f!==null?(f.return=p,te=f):Bb(d)}u=u.sibling}e:for(u=null,d=e;;){if(d.tag===5){if(u===null){u=d;try{o=d.stateNode,l?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=d.stateNode,c=d.memoizedProps.style,i=c!=null&&c.hasOwnProperty("display")?c.display:null,a.style.display=UI("display",i))}catch(g){ft(e,e.return,g)}}}else if(d.tag===6){if(u===null)try{d.stateNode.nodeValue=l?"":d.memoizedProps}catch(g){ft(e,e.return,g)}}else if((d.tag!==22&&d.tag!==23||d.memoizedState===null||d===e)&&d.child!==null){d.child.return=d,d=d.child;continue}if(d===e)break e;for(;d.sibling===null;){if(d.return===null||d.return===e)break e;u===d&&(u=null),d=d.return}u===d&&(u=null),d.sibling.return=d.return,d=d.sibling}}break;case 19:Cr(t,e),Vr(e),r&4&&Nb(e);break;case 21:break;default:Cr(t,e),Vr(e)}}function Vr(e){var t=e.flags;if(t&2){try{e:{for(var n=e.return;n!==null;){if(f_(n)){var r=n;break e}n=n.return}throw Error(Y(160))}switch(r.tag){case 5:var o=r.stateNode;r.flags&32&&(Fl(o,""),r.flags&=-33);var s=Fb(e);CS(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=Fb(e);PS(e,a,i);break;default:throw Error(Y(161))}}catch(c){ft(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function YR(e,t,n){te=e,y_(e)}function y_(e,t,n){for(var r=(e.mode&1)!==0;te!==null;){var o=te,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||gd;if(!i){var a=o.alternate,c=a!==null&&a.memoizedState!==null||Qt;a=gd;var l=Qt;if(gd=i,(Qt=c)&&!l)for(te=o;te!==null;)i=te,c=i.child,i.tag===22&&i.memoizedState!==null?Ub(o):c!==null?(c.return=i,te=c):Ub(o);for(;s!==null;)te=s,y_(s),s=s.sibling;te=o,gd=a,Qt=l}zb(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,te=s):zb(e)}}function zb(e){for(;te!==null;){var t=te;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:Qt||Pf(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!Qt)if(n===null)r.componentDidMount();else{var o=t.elementType===t.type?n.memoizedProps:Ir(t.type,n.memoizedProps);r.componentDidUpdate(o,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=t.updateQueue;s!==null&&Cb(t,s,r);break;case 3:var i=t.updateQueue;if(i!==null){if(n=null,t.child!==null)switch(t.child.tag){case 5:n=t.child.stateNode;break;case 1:n=t.child.stateNode}Cb(t,i,n)}break;case 5:var a=t.stateNode;if(n===null&&t.flags&4){n=a;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&n.focus();break;case"img":c.src&&(n.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var l=t.alternate;if(l!==null){var u=l.memoizedState;if(u!==null){var d=u.dehydrated;d!==null&&Ul(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Y(163))}Qt||t.flags&512&&bS(t)}catch(p){ft(t,t.return,p)}}if(t===e){te=null;break}if(n=t.sibling,n!==null){n.return=t.return,te=n;break}te=t.return}}function Bb(e){for(;te!==null;){var t=te;if(t===e){te=null;break}var n=t.sibling;if(n!==null){n.return=t.return,te=n;break}te=t.return}}function Ub(e){for(;te!==null;){var t=te;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{Pf(4,t)}catch(c){ft(t,n,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var o=t.return;try{r.componentDidMount()}catch(c){ft(t,o,c)}}var s=t.return;try{bS(t)}catch(c){ft(t,s,c)}break;case 5:var i=t.return;try{bS(t)}catch(c){ft(t,i,c)}}}catch(c){ft(t,t.return,c)}if(t===e){te=null;break}var a=t.sibling;if(a!==null){a.return=t.return,te=a;break}te=t.return}}var XR=Math.ceil,Pp=Xo.ReactCurrentDispatcher,x0=Xo.ReactCurrentOwner,gr=Xo.ReactCurrentBatchConfig,_e=0,At=null,Ct=null,Bt=0,Hn=0,_a=Ws(0),Et=0,Jl=null,_i=0,Cf=0,w0=0,El=null,Pn=null,b0=0,rc=1/0,_o=null,Cp=!1,IS=null,$s=null,md=!1,bs=null,Ip=0,_l=0,ES=null,dh=-1,hh=0;function gn(){return _e&6?St():dh!==-1?dh:dh=St()}function Ms(e){return e.mode&1?_e&2&&Bt!==0?Bt&-Bt:AR.transition!==null?(hh===0&&(hh=tE()),hh):(e=Fe,e!==0||(e=window.event,e=e===void 0?16:cE(e.type)),e):1}function Rr(e,t,n,r){if(50<_l)throw _l=0,ES=null,Error(Y(185));Iu(e,n,r),(!(_e&2)||e!==At)&&(e===At&&(!(_e&2)&&(Cf|=n),Et===4&&Ss(e,Bt)),Mn(e,r),n===1&&_e===0&&!(t.mode&1)&&(rc=St()+500,xf&&Vs()))}function Mn(e,t){var n=e.callbackNode;AD(e,t);var r=cp(e,e===At?Bt:0);if(r===0)n!==null&&Zw(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&Zw(n),t===1)e.tag===0?MR(Hb.bind(null,e)):_E(Hb.bind(null,e)),_R(function(){!(_e&6)&&Vs()}),n=null;else{switch(nE(r)){case 1:n=Yv;break;case 4:n=JI;break;case 16:n=ap;break;case 536870912:n=eE;break;default:n=ap}n=I_(n,S_.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function S_(e,t){if(dh=-1,hh=0,_e&6)throw Error(Y(327));var n=e.callbackNode;if(Ua()&&e.callbackNode!==n)return null;var r=cp(e,e===At?Bt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Ep(e,r);else{t=r;var o=_e;_e|=2;var s=x_();(At!==e||Bt!==t)&&(_o=null,rc=St()+500,wi(e,t));do try{QR();break}catch(a){v_(e,a)}while(!0);a0(),Pp.current=s,_e=o,Ct!==null?t=0:(At=null,Bt=0,t=Et)}if(t!==0){if(t===2&&(o=Jy(e),o!==0&&(r=o,t=_S(e,o))),t===1)throw n=Jl,wi(e,0),Ss(e,r),Mn(e,St()),n;if(t===6)Ss(e,r);else{if(o=e.current.alternate,!(r&30)&&!qR(o)&&(t=Ep(e,r),t===2&&(s=Jy(e),s!==0&&(r=s,t=_S(e,s))),t===1))throw n=Jl,wi(e,0),Ss(e,r),Mn(e,St()),n;switch(e.finishedWork=o,e.finishedLanes=r,t){case 0:case 1:throw Error(Y(345));case 2:di(e,Pn,_o);break;case 3:if(Ss(e,r),(r&130023424)===r&&(t=b0+500-St(),10<t)){if(cp(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){gn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=aS(di.bind(null,e,Pn,_o),t);break}di(e,Pn,_o);break;case 4:if(Ss(e,r),(r&4194240)===r)break;for(t=e.eventTimes,o=-1;0<r;){var i=31-Dr(r);s=1<<i,i=t[i],i>o&&(o=i),r&=~s}if(r=o,r=St()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*XR(r/1960))-r,10<r){e.timeoutHandle=aS(di.bind(null,e,Pn,_o),r);break}di(e,Pn,_o);break;case 5:di(e,Pn,_o);break;default:throw Error(Y(329))}}}return Mn(e,St()),e.callbackNode===n?S_.bind(null,e):null}function _S(e,t){var n=El;return e.current.memoizedState.isDehydrated&&(wi(e,t).flags|=256),e=Ep(e,t),e!==2&&(t=Pn,Pn=n,t!==null&&kS(t)),e}function kS(e){Pn===null?Pn=e:Pn.push.apply(Pn,e)}function qR(e){for(var t=e;;){if(t.flags&16384){var n=t.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var o=n[r],s=o.getSnapshot;o=o.value;try{if(!zr(s(),o))return!1}catch{return!1}}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function Ss(e,t){for(t&=~w0,t&=~Cf,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-Dr(t),r=1<<n;e[n]=-1,t&=~r}}function Hb(e){if(_e&6)throw Error(Y(327));Ua();var t=cp(e,0);if(!(t&1))return Mn(e,St()),null;var n=Ep(e,t);if(e.tag!==0&&n===2){var r=Jy(e);r!==0&&(t=r,n=_S(e,r))}if(n===1)throw n=Jl,wi(e,0),Ss(e,t),Mn(e,St()),n;if(n===6)throw Error(Y(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,di(e,Pn,_o),Mn(e,St()),null}function P0(e,t){var n=_e;_e|=1;try{return e(t)}finally{_e=n,_e===0&&(rc=St()+500,xf&&Vs())}}function ki(e){bs!==null&&bs.tag===0&&!(_e&6)&&Ua();var t=_e;_e|=1;var n=gr.transition,r=Fe;try{if(gr.transition=null,Fe=1,e)return e()}finally{Fe=r,gr.transition=n,_e=t,!(_e&6)&&Vs()}}function C0(){Hn=_a.current,tt(_a)}function wi(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,ER(n)),Ct!==null)for(n=Ct.return;n!==null;){var r=n;switch(o0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&pp();break;case 3:tc(),tt(Tn),tt(rn),p0();break;case 5:h0(r);break;case 4:tc();break;case 13:tt(it);break;case 19:tt(it);break;case 10:c0(r.type._context);break;case 22:case 23:C0()}n=n.return}if(At=e,Ct=e=As(e.current,null),Bt=Hn=t,Et=0,Jl=null,w0=Cf=_i=0,Pn=El=null,fi!==null){for(t=0;t<fi.length;t++)if(n=fi[t],r=n.interleaved,r!==null){n.interleaved=null;var o=r.next,s=n.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}n.pending=r}fi=null}return e}function v_(e,t){do{var n=Ct;try{if(a0(),ch.current=bp,wp){for(var r=lt.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}wp=!1}if(Ei=0,Tt=It=lt=null,Cl=!1,ql=0,x0.current=null,n===null||n.return===null){Et=1,Jl=t,Ct=null;break}e:{var s=e,i=n.return,a=n,c=t;if(t=Bt,a.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var l=c,u=a,d=u.tag;if(!(u.mode&1)&&(d===0||d===11||d===15)){var p=u.alternate;p?(u.updateQueue=p.updateQueue,u.memoizedState=p.memoizedState,u.lanes=p.lanes):(u.updateQueue=null,u.memoizedState=null)}var f=$b(i);if(f!==null){f.flags&=-257,Mb(f,i,a,s,t),f.mode&1&&Tb(s,l,t),t=f,c=l;var y=t.updateQueue;if(y===null){var g=new Set;g.add(c),t.updateQueue=g}else y.add(c);break e}else{if(!(t&1)){Tb(s,l,t),I0();break e}c=Error(Y(426))}}else if(rt&&a.mode&1){var w=$b(i);if(w!==null){!(w.flags&65536)&&(w.flags|=256),Mb(w,i,a,s,t),s0(nc(c,a));break e}}s=c=nc(c,a),Et!==4&&(Et=2),El===null?El=[s]:El.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,t&=-t,s.lanes|=t;var S=n_(s,c,t);Pb(s,S);break e;case 1:a=c;var v=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof v.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&($s===null||!$s.has(b)))){s.flags|=65536,t&=-t,s.lanes|=t;var E=r_(s,a,t);Pb(s,E);break e}}s=s.return}while(s!==null)}b_(n)}catch(C){t=C,Ct===n&&n!==null&&(Ct=n=n.return);continue}break}while(!0)}function x_(){var e=Pp.current;return Pp.current=bp,e===null?bp:e}function I0(){(Et===0||Et===3||Et===2)&&(Et=4),At===null||!(_i&268435455)&&!(Cf&268435455)||Ss(At,Bt)}function Ep(e,t){var n=_e;_e|=2;var r=x_();(At!==e||Bt!==t)&&(_o=null,wi(e,t));do try{ZR();break}catch(o){v_(e,o)}while(!0);if(a0(),_e=n,Pp.current=r,Ct!==null)throw Error(Y(261));return At=null,Bt=0,Et}function ZR(){for(;Ct!==null;)w_(Ct)}function QR(){for(;Ct!==null&&!PD();)w_(Ct)}function w_(e){var t=C_(e.alternate,e,Hn);e.memoizedProps=e.pendingProps,t===null?b_(e):Ct=t,x0.current=null}function b_(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=WR(n,t),n!==null){n.flags&=32767,Ct=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Et=6,Ct=null;return}}else if(n=KR(n,t,Hn),n!==null){Ct=n;return}if(t=t.sibling,t!==null){Ct=t;return}Ct=t=e}while(t!==null);Et===0&&(Et=5)}function di(e,t,n){var r=Fe,o=gr.transition;try{gr.transition=null,Fe=1,JR(e,t,n,r)}finally{gr.transition=o,Fe=r}return null}function JR(e,t,n,r){do Ua();while(bs!==null);if(_e&6)throw Error(Y(327));n=e.finishedWork;var o=e.finishedLanes;if(n===null)return null;if(e.finishedWork=null,e.finishedLanes=0,n===e.current)throw Error(Y(177));e.callbackNode=null,e.callbackPriority=0;var s=n.lanes|n.childLanes;if(jD(e,s),e===At&&(Ct=At=null,Bt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||md||(md=!0,I_(ap,function(){return Ua(),null})),s=(n.flags&15990)!==0,n.subtreeFlags&15990||s){s=gr.transition,gr.transition=null;var i=Fe;Fe=1;var a=_e;_e|=4,x0.current=null,GR(e,n),m_(n,e),vR(sS),lp=!!oS,sS=oS=null,e.current=n,YR(n),CD(),_e=a,Fe=i,gr.transition=s}else e.current=n;if(md&&(md=!1,bs=e,Ip=o),s=e.pendingLanes,s===0&&($s=null),_D(n.stateNode),Mn(e,St()),t!==null)for(r=e.onRecoverableError,n=0;n<t.length;n++)o=t[n],r(o.value,{componentStack:o.stack,digest:o.digest});if(Cp)throw Cp=!1,e=IS,IS=null,e;return Ip&1&&e.tag!==0&&Ua(),s=e.pendingLanes,s&1?e===ES?_l++:(_l=0,ES=e):_l=0,Vs(),null}function Ua(){if(bs!==null){var e=nE(Ip),t=gr.transition,n=Fe;try{if(gr.transition=null,Fe=16>e?16:e,bs===null)var r=!1;else{if(e=bs,bs=null,Ip=0,_e&6)throw Error(Y(331));var o=_e;for(_e|=4,te=e.current;te!==null;){var s=te,i=s.child;if(te.flags&16){var a=s.deletions;if(a!==null){for(var c=0;c<a.length;c++){var l=a[c];for(te=l;te!==null;){var u=te;switch(u.tag){case 0:case 11:case 15:Il(8,u,s)}var d=u.child;if(d!==null)d.return=u,te=d;else for(;te!==null;){u=te;var p=u.sibling,f=u.return;if(p_(u),u===l){te=null;break}if(p!==null){p.return=f,te=p;break}te=f}}}var y=s.alternate;if(y!==null){var g=y.child;if(g!==null){y.child=null;do{var w=g.sibling;g.sibling=null,g=w}while(g!==null)}}te=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,te=i;else e:for(;te!==null;){if(s=te,s.flags&2048)switch(s.tag){case 0:case 11:case 15:Il(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,te=S;break e}te=s.return}}var v=e.current;for(te=v;te!==null;){i=te;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,te=b;else e:for(i=v;te!==null;){if(a=te,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:Pf(9,a)}}catch(C){ft(a,a.return,C)}if(a===i){te=null;break e}var E=a.sibling;if(E!==null){E.return=a.return,te=E;break e}te=a.return}}if(_e=o,Vs(),to&&typeof to.onPostCommitFiberRoot=="function")try{to.onPostCommitFiberRoot(gf,e)}catch{}r=!0}return r}finally{Fe=n,gr.transition=t}}return!1}function Kb(e,t,n){t=nc(n,t),t=n_(e,t,1),e=Ts(e,t,1),t=gn(),e!==null&&(Iu(e,1,t),Mn(e,t))}function ft(e,t,n){if(e.tag===3)Kb(e,e,n);else for(;t!==null;){if(t.tag===3){Kb(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&($s===null||!$s.has(r))){e=nc(n,e),e=r_(t,e,1),t=Ts(t,e,1),e=gn(),t!==null&&(Iu(t,1,e),Mn(t,e));break}}t=t.return}}function e3(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=gn(),e.pingedLanes|=e.suspendedLanes&n,At===e&&(Bt&n)===n&&(Et===4||Et===3&&(Bt&130023424)===Bt&&500>St()-b0?wi(e,0):w0|=n),Mn(e,t)}function P_(e,t){t===0&&(e.mode&1?(t=id,id<<=1,!(id&130023424)&&(id=4194304)):t=1);var n=gn();e=Bo(e,t),e!==null&&(Iu(e,t,n),Mn(e,n))}function t3(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),P_(e,n)}function n3(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,o=e.memoizedState;o!==null&&(n=o.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(Y(314))}r!==null&&r.delete(t),P_(e,n)}var C_;C_=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Tn.current)En=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return En=!1,HR(e,t,n);En=!!(e.flags&131072)}else En=!1,rt&&t.flags&1048576&&kE(t,mp,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;uh(e,t),e=t.pendingProps;var o=Qa(t,rn.current);Ba(t,n),o=g0(null,t,r,e,o,n);var s=m0();return t.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,$n(r)?(s=!0,fp(t)):s=!1,t.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,u0(t),o.updater=bf,t.stateNode=o,o._reactInternals=t,fS(t,r,e,n),t=yS(null,t,r,!0,s,n)):(t.tag=0,rt&&s&&r0(t),un(null,t,o,n),t=t.child),t;case 16:r=t.elementType;e:{switch(uh(e,t),e=t.pendingProps,o=r._init,r=o(r._payload),t.type=r,o=t.tag=o3(r),e=Ir(r,e),o){case 0:t=mS(null,t,r,e,n);break e;case 1:t=Ob(null,t,r,e,n);break e;case 11:t=Ab(null,t,r,e,n);break e;case 14:t=jb(null,t,r,Ir(r.type,e),n);break e}throw Error(Y(306,r,""))}return t;case 0:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Ir(r,o),mS(e,t,r,o,n);case 1:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Ir(r,o),Ob(e,t,r,o,n);case 3:e:{if(a_(t),e===null)throw Error(Y(387));r=t.pendingProps,s=t.memoizedState,o=s.element,OE(e,t),vp(t,r,null,n);var i=t.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},t.updateQueue.baseState=s,t.memoizedState=s,t.flags&256){o=nc(Error(Y(423)),t),t=Db(e,t,r,n,o);break e}else if(r!==o){o=nc(Error(Y(424)),t),t=Db(e,t,r,n,o);break e}else for(Yn=ks(t.stateNode.containerInfo.firstChild),Xn=t,rt=!0,$r=null,n=AE(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Ja(),r===o){t=Uo(e,t,n);break e}un(e,t,r,n)}t=t.child}return t;case 5:return DE(t),e===null&&dS(t),r=t.type,o=t.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,iS(r,o)?i=null:s!==null&&iS(r,s)&&(t.flags|=32),i_(e,t),un(e,t,i,n),t.child;case 6:return e===null&&dS(t),null;case 13:return c_(e,t,n);case 4:return d0(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=ec(t,null,r,n):un(e,t,r,n),t.child;case 11:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Ir(r,o),Ab(e,t,r,o,n);case 7:return un(e,t,t.pendingProps,n),t.child;case 8:return un(e,t,t.pendingProps.children,n),t.child;case 12:return un(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,o=t.pendingProps,s=t.memoizedProps,i=o.value,Ge(yp,r._currentValue),r._currentValue=i,s!==null)if(zr(s.value,i)){if(s.children===o.children&&!Tn.current){t=Uo(e,t,n);break e}}else for(s=t.child,s!==null&&(s.return=t);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var c=a.firstContext;c!==null;){if(c.context===r){if(s.tag===1){c=Oo(-1,n&-n),c.tag=2;var l=s.updateQueue;if(l!==null){l=l.shared;var u=l.pending;u===null?c.next=c:(c.next=u.next,u.next=c),l.pending=c}}s.lanes|=n,c=s.alternate,c!==null&&(c.lanes|=n),hS(s.return,n,t),a.lanes|=n;break}c=c.next}}else if(s.tag===10)i=s.type===t.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(Y(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),hS(i,n,t),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===t){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}un(e,t,o.children,n),t=t.child}return t;case 9:return o=t.type,r=t.pendingProps.children,Ba(t,n),o=yr(o),r=r(o),t.flags|=1,un(e,t,r,n),t.child;case 14:return r=t.type,o=Ir(r,t.pendingProps),o=Ir(r.type,o),jb(e,t,r,o,n);case 15:return o_(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Ir(r,o),uh(e,t),t.tag=1,$n(r)?(e=!0,fp(t)):e=!1,Ba(t,n),t_(t,r,o),fS(t,r,o,n),yS(null,t,r,!0,e,n);case 19:return l_(e,t,n);case 22:return s_(e,t,n)}throw Error(Y(156,t.tag))};function I_(e,t){return QI(e,t)}function r3(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function fr(e,t,n,r){return new r3(e,t,n,r)}function E0(e){return e=e.prototype,!(!e||!e.isReactComponent)}function o3(e){if(typeof e=="function")return E0(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Wv)return 11;if(e===Vv)return 14}return 2}function As(e,t){var n=e.alternate;return n===null?(n=fr(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function ph(e,t,n,r,o,s){var i=2;if(r=e,typeof e=="function")E0(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case ya:return bi(n.children,o,s,t);case Kv:i=8,o|=8;break;case Fy:return e=fr(12,n,t,o|2),e.elementType=Fy,e.lanes=s,e;case Ny:return e=fr(13,n,t,o),e.elementType=Ny,e.lanes=s,e;case zy:return e=fr(19,n,t,o),e.elementType=zy,e.lanes=s,e;case DI:return If(n,o,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case jI:i=10;break e;case OI:i=9;break e;case Wv:i=11;break e;case Vv:i=14;break e;case gs:i=16,r=null;break e}throw Error(Y(130,e==null?e:typeof e,""))}return t=fr(i,n,t,o),t.elementType=e,t.type=r,t.lanes=s,t}function bi(e,t,n,r){return e=fr(7,e,r,t),e.lanes=n,e}function If(e,t,n,r){return e=fr(22,e,r,t),e.elementType=DI,e.lanes=n,e.stateNode={isHidden:!1},e}function em(e,t,n){return e=fr(6,e,null,t),e.lanes=n,e}function tm(e,t,n){return t=fr(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function s3(e,t,n,r,o){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Dg(0),this.expirationTimes=Dg(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Dg(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function _0(e,t,n,r,o,s,i,a,c){return e=new s3(e,t,n,a,c),t===1?(t=1,s===!0&&(t|=8)):t=0,s=fr(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},u0(s),e}function i3(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:ma,key:r==null?null:""+r,children:e,containerInfo:t,implementation:n}}function E_(e){if(!e)return Rs;e=e._reactInternals;e:{if(Bi(e)!==e||e.tag!==1)throw Error(Y(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if($n(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(Y(171))}if(e.tag===1){var n=e.type;if($n(n))return EE(e,n,t)}return t}function __(e,t,n,r,o,s,i,a,c){return e=_0(n,r,!0,e,o,s,i,a,c),e.context=E_(null),n=e.current,r=gn(),o=Ms(n),s=Oo(r,o),s.callback=t??null,Ts(n,s,o),e.current.lanes=o,Iu(e,o,r),Mn(e,r),e}function Ef(e,t,n,r){var o=t.current,s=gn(),i=Ms(o);return n=E_(n),t.context===null?t.context=n:t.pendingContext=n,t=Oo(s,i),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=Ts(o,t,i),e!==null&&(Rr(e,o,i,s),ah(e,o,i)),i}function _p(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function Wb(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function k0(e,t){Wb(e,t),(e=e.alternate)&&Wb(e,t)}function a3(){return null}var k_=typeof reportError=="function"?reportError:function(e){console.error(e)};function T0(e){this._internalRoot=e}_f.prototype.render=T0.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(Y(409));Ef(e,t,null,null)};_f.prototype.unmount=T0.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;ki(function(){Ef(null,e,null,null)}),t[zo]=null}};function _f(e){this._internalRoot=e}_f.prototype.unstable_scheduleHydration=function(e){if(e){var t=sE();e={blockedOn:null,target:e,priority:t};for(var n=0;n<ys.length&&t!==0&&t<ys[n].priority;n++);ys.splice(n,0,e),n===0&&aE(e)}};function $0(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function kf(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Vb(){}function c3(e,t,n,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var l=_p(i);s.call(l)}}var i=__(t,r,e,0,null,!1,!1,"",Vb);return e._reactRootContainer=i,e[zo]=i.current,Wl(e.nodeType===8?e.parentNode:e),ki(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var l=_p(c);a.call(l)}}var c=_0(e,0,!1,null,null,!1,!1,"",Vb);return e._reactRootContainer=c,e[zo]=c.current,Wl(e.nodeType===8?e.parentNode:e),ki(function(){Ef(t,c,n,r)}),c}function Tf(e,t,n,r,o){var s=n._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var c=_p(i);a.call(c)}}Ef(t,i,e,o)}else i=c3(n,t,e,o,r);return _p(i)}rE=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=dl(t.pendingLanes);n!==0&&(Xv(t,n|1),Mn(t,St()),!(_e&6)&&(rc=St()+500,Vs()))}break;case 13:ki(function(){var r=Bo(e,1);if(r!==null){var o=gn();Rr(r,e,1,o)}}),k0(e,1)}};qv=function(e){if(e.tag===13){var t=Bo(e,134217728);if(t!==null){var n=gn();Rr(t,e,134217728,n)}k0(e,134217728)}};oE=function(e){if(e.tag===13){var t=Ms(e),n=Bo(e,t);if(n!==null){var r=gn();Rr(n,e,t,r)}k0(e,t)}};sE=function(){return Fe};iE=function(e,t){var n=Fe;try{return Fe=e,t()}finally{Fe=n}};qy=function(e,t,n){switch(t){case"input":if(Hy(e,n),t=n.name,n.type==="radio"&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var o=vf(r);if(!o)throw Error(Y(90));LI(r),Hy(r,o)}}}break;case"textarea":NI(e,n);break;case"select":t=n.value,t!=null&&La(e,!!n.multiple,t,!1)}};VI=P0;GI=ki;var l3={usingClientEntryPoint:!1,Events:[_u,wa,vf,KI,WI,P0]},Wc={findFiberByHostInstance:pi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},u3={bundleType:Wc.bundleType,version:Wc.version,rendererPackageName:Wc.rendererPackageName,rendererConfig:Wc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Xo.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=qI(e),e===null?null:e.stateNode},findFiberByHostInstance:Wc.findFiberByHostInstance||a3,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 yd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!yd.isDisabled&&yd.supportsFiber)try{gf=yd.inject(u3),to=yd}catch{}}nr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=l3;nr.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!$0(t))throw Error(Y(200));return i3(e,t,null,n)};nr.createRoot=function(e,t){if(!$0(e))throw Error(Y(299));var n=!1,r="",o=k_;return t!=null&&(t.unstable_strictMode===!0&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(o=t.onRecoverableError)),t=_0(e,1,!1,null,null,n,!1,r,o),e[zo]=t.current,Wl(e.nodeType===8?e.parentNode:e),new T0(t)};nr.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(Y(188)):(e=Object.keys(e).join(","),Error(Y(268,e)));return e=qI(t),e=e===null?null:e.stateNode,e};nr.flushSync=function(e){return ki(e)};nr.hydrate=function(e,t,n){if(!kf(t))throw Error(Y(200));return Tf(null,e,t,!0,n)};nr.hydrateRoot=function(e,t,n){if(!$0(e))throw Error(Y(405));var r=n!=null&&n.hydratedSources||null,o=!1,s="",i=k_;if(n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(s=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),t=__(t,null,e,1,n??null,o,!1,s,i),e[zo]=t.current,Wl(e),r)for(e=0;e<r.length;e++)n=r[e],o=n._getVersion,o=o(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,o]:t.mutableSourceEagerHydrationData.push(n,o);return new _f(t)};nr.render=function(e,t,n){if(!kf(t))throw Error(Y(200));return Tf(null,e,t,!1,n)};nr.unmountComponentAtNode=function(e){if(!kf(e))throw Error(Y(40));return e._reactRootContainer?(ki(function(){Tf(null,null,e,!1,function(){e._reactRootContainer=null,e[zo]=null})}),!0):!1};nr.unstable_batchedUpdates=P0;nr.unstable_renderSubtreeIntoContainer=function(e,t,n,r){if(!kf(n))throw Error(Y(200));if(e==null||e._reactInternals===void 0)throw Error(Y(38));return Tf(e,t,n,!1,r)};nr.version="18.3.1-next-f1338f8080-20240426";function T_(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(T_)}catch(e){console.error(e)}}T_(),TI.exports=nr;var Ui=TI.exports;const d3=pc(Ui);var $_,Gb=Ui;$_=Ry.createRoot=Gb.createRoot,Ry.hydrateRoot=Gb.hydrateRoot;async function h3(e,t){const{url:n,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:c,variant:l,format:u}=t,d={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:c,variant:l},p=new FontFace(e,`url(${n})`,d);return await p.load(),document.fonts.add(p),p.$$_url=n,p.$$_fontface=`
@font-face {
font-family: ${p.family};
font-stretch: ${p.stretch};
font-weight: ${p.weight};
font-style: ${p.style};
src: url("${n}") format("${u}")
}`,p}function M_(e){return e&&typeof e=="object"&&"parents"in e}function A_(e){for(let t=0,n=e.parents.length;t<n;t++)if(e.parents[t].__unsafe__getWithoutCapture(!0),e.parents[t].lastChangedEpoch!==e.parentEpochs[t])return!0;return!1}const kp=(e,t)=>{if(e.children.remove(t)&&e.children.isEmpty&&M_(e))for(let n=0,r=e.parents.length;n<r;n++)kp(e.parents[n],e)},M0=(e,t)=>{if(e.children.add(t)&&M_(e))for(let n=0,r=e.parents.length;n<r;n++)M0(e.parents[n],e)};function j_(e,t){return e===t||Object.is(e,t)||!!(e&&t&&typeof e.equals=="function"&&e.equals(t))}function Gs(e,t){const n=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[n]??(r[n]=t()),r[n]}const Do=Gs("empty_array",()=>Object.freeze([])),Yb=8;class Tp{constructor(){m(this,"arraySize",0);m(this,"array",Array(Yb));m(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(t){if(this.array)return this.array.indexOf(t)!==-1?!1:this.arraySize<Yb?(this.array[this.arraySize]=t,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(t),!0);if(this.set)return this.set.has(t)?!1:(this.set.add(t),!0);throw new Error("no set or array")}remove(t){if(this.array){const n=this.array.indexOf(t);return n===-1?!1:(this.array[n]=void 0,this.arraySize--,n!==this.arraySize&&(this.array[n]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(t)?(this.set.delete(t),!0):!1;throw new Error("no set or array")}visit(t){if(this.array){for(let n=0;n<this.arraySize;n++){const r=this.array[n];typeof r<"u"&&t(r)}return}if(this.set){this.set.forEach(t);return}throw new Error("no set or array")}has(t){return this.array?this.array.indexOf(t)!==-1:this.set.has(t)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}const qn=Symbol.for("com.tldraw.state/RESET_VALUE");class O_{constructor(t){m(this,"index",0);m(this,"buffer");this.capacity=t,this.buffer=new Array(t)}pushEntry(t,n,r){if(r!==void 0){if(r===qn){this.clear();return}this.buffer[this.index]=[t,n,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(t){const{index:n,capacity:r,buffer:o}=this;for(let s=0;s<r;s++){const i=(n-1+r-s)%r,a=o[i];if(!a)return qn;const[c,l]=a;if(s===0&&t>=l)return[];if(c<=t&&t<l){const u=s+1,d=new Array(u);for(let p=0;p<u;p++)d[p]=o[(i+p)%r][2];return d}}return qn}}class p3{constructor(t,n){m(this,"offset",0);m(this,"maybeRemoved");this.below=t,this.child=n}}const yt=Gs("capture",()=>({stack:null}));function D_(e){yt.stack=new p3(yt.stack,e),e.parentSet.clear()}function R_(){const e=yt.stack;if(yt.stack=e.below,e.offset<e.child.parents.length){for(let t=e.offset;t<e.child.parents.length;t++){const n=e.child.parents[t];e.child.parentSet.has(n)||kp(n,e.child)}e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset}if(e.maybeRemoved)for(let t=0;t<e.maybeRemoved.length;t++){const n=e.maybeRemoved[t];e.child.parentSet.has(n)||kp(n,e.child)}}function $p(e){if(yt.stack){if(yt.stack.child.parentSet.has(e))return;if(yt.stack.child.parentSet.add(e),yt.stack.child.isActivelyListening&&M0(e,yt.stack.child),yt.stack.offset<yt.stack.child.parents.length){const n=yt.stack.child.parents[yt.stack.offset];n!==e&&(yt.stack.maybeRemoved?yt.stack.maybeRemoved.push(n):yt.stack.maybeRemoved=[n])}yt.stack.child.parents[yt.stack.offset]=e,yt.stack.child.parentEpochs[yt.stack.offset]=e.lastChangedEpoch,yt.stack.offset++}}const mi=-1;class f3{constructor(t,n,r){m(this,"_isActivelyListening",!1);m(this,"lastTraversedEpoch",mi);m(this,"lastReactedEpoch",mi);m(this,"_scheduleCount",0);m(this,"parentSet",new Tp);m(this,"parentEpochs",[]);m(this,"parents",[]);m(this,"_scheduleEffect");m(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=t,this.runEffect=n,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==dn()){if(this.parents.length&&!A_(this)){this.lastReactedEpoch=dn();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let t=0,n=this.parents.length;t<n;t++)M0(this.parents[t],this)}detach(){this._isActivelyListening=!1;for(let t=0,n=this.parents.length;t<n;t++)kp(this.parents[t],this)}execute(){try{D_(this);const t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=dn(),t}finally{R_()}}}const yc=Gs("EffectScheduler",()=>f3);function Sc(e,t,n){const r=new yc(e,t,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function g3(e,t,n){const r=new yc(e,t,n);return{scheduler:r,start:o=>{const s=(o==null?void 0:o.force)??!1;r.attach(),s?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class m3{constructor(t){m(this,"initialAtomValues",new Map);this.parent=t}get isRoot(){return this.parent===null}commit(){if(this.isRoot){const t=this.initialAtomValues;this.initialAtomValues=new Map,L_(t.keys())}else this.initialAtomValues.forEach((t,n)=>{this.parent.initialAtomValues.has(n)||this.parent.initialAtomValues.set(n,t)})}abort(){Jt.globalEpoch++,this.initialAtomValues.forEach((t,n)=>{var r;n.set(t),(r=n.historyBuffer)==null||r.clear()}),this.commit()}}const Jt=Gs("transactions",()=>({globalEpoch:mi+1,globalIsReacting:!1,currentTransaction:null}));function dn(){return Jt.globalEpoch}function L_(e){if(Jt.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{Jt.globalIsReacting=!0;const t=new Set,n=r=>{r.lastTraversedEpoch!==Jt.globalEpoch&&(r.lastTraversedEpoch=Jt.globalEpoch,r instanceof yc?t.add(r):r.children.visit(n))};for(const r of e)r.children.visit(n);for(const r of t)r.maybeScheduleEffect()}finally{Jt.globalIsReacting=!1}}function y3(e,t){Jt.currentTransaction?Jt.currentTransaction.initialAtomValues.has(e)||Jt.currentTransaction.initialAtomValues.set(e,t):L_([e])}function S3(){Jt.globalEpoch++}function v3(e){const t=new m3(Jt.currentTransaction);Jt.currentTransaction=t;try{let n=!1;const r=e(()=>n=!0);return n?t.abort():t.commit(),r}catch(n){throw t.abort(),n}finally{Jt.currentTransaction=Jt.currentTransaction.parent}}function Mr(e){return Jt.currentTransaction?e():v3(e)}class x3{constructor(t,n,r){m(this,"isEqual");m(this,"computeDiff");m(this,"lastChangedEpoch",dn());m(this,"children",new Tp);m(this,"historyBuffer");this.name=t,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new O_(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(t){return this.current}get(){return $p(this),this.current}set(t,n){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,t))??j_(this.current,t))return this.current;S3(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,dn(),n??((s=this.computeDiff)==null?void 0:s.call(this,this.current,t,this.lastChangedEpoch,dn()))??qn),this.lastChangedEpoch=dn();const r=this.current;return this.current=t,y3(this,r),t}update(t){return this.set(t(this.current))}getDiffSince(t){var n;return $p(this),t>=this.lastChangedEpoch?Do:((n=this.historyBuffer)==null?void 0:n.getChangesSince(t))??qn}}const w3=Gs("Atom",()=>x3);function fn(e,t,n){return new w3(e,t,n)}let Xb=!1;function b3(){Xb||(Xb=!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.
// Before
@computed
get foo() {
return 'foo'
}
// After
@computed
getFoo() {
return 'foo'
}
`))}const pl=Symbol.for("com.tldraw.state/UNINITIALIZED"),Pi=e=>e===pl,TS=Gs("WithDiff",()=>class{constructor(t,n){this.value=t,this.diff=n}});function fl(e,t){return new TS(e,t)}class P3{constructor(t,n,r){m(this,"lastChangedEpoch",mi);m(this,"lastTraversedEpoch",mi);m(this,"lastCheckedEpoch",mi);m(this,"parentSet",new Tp);m(this,"parents",[]);m(this,"parentEpochs",[]);m(this,"children",new Tp);m(this,"historyBuffer");m(this,"state",pl);m(this,"error",null);m(this,"computeDiff");m(this,"isEqual");this.name=t,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new O_(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??j_}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(t){var r;if(!(this.lastChangedEpoch===mi)&&(this.lastCheckedEpoch===dn()||!A_(this)))if(this.lastCheckedEpoch=dn(),this.error){if(t)return this.state;throw this.error.thrownValue}else return this.state;try{D_(this);const o=this.derive(this.state,this.lastCheckedEpoch),s=o instanceof TS?o.value:o,i=this.state===pl;if(i||!this.isEqual(s,this.state)){if(this.historyBuffer&&!i){const a=o instanceof TS?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,dn(),a??((r=this.computeDiff)==null?void 0:r.call(this,this.state,s,this.lastCheckedEpoch,dn()))??qn)}this.lastChangedEpoch=dn(),this.state=s}return this.error=null,this.lastCheckedEpoch=dn(),this.state}catch(o){if(this.state!==pl&&(this.state=pl,this.lastChangedEpoch=dn()),this.lastCheckedEpoch=dn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!t)throw o;return this.state}finally{R_()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{$p(this)}}getDiffSince(t){var n;return this.__unsafe__getWithoutCapture(!0),$p(this),t>=this.lastChangedEpoch?Do:((n=this.historyBuffer)==null?void 0:n.getChangesSince(t))??qn}}const A0=Gs("Computed",()=>P3);function C3(e={},t,n,r){const o=r.value,s=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[s];return i||(i=new A0(n,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[E3]=!0,r}function qb(e={},t,n,r){return r.get?(b3(),I3(e,t,n,r)):C3(e,t,n,r)}function I3(e={},t,n,r){const o=r.get,s=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[s];return i||(i=new A0(n,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const E3="@@__isComputedMethod__@@";function V(){if(arguments.length===1){const e=arguments[0];return(t,n,r)=>qb(e,t,n,r)}else return typeof arguments[0]=="string"?new A0(arguments[0],arguments[1],arguments[2]):qb(void 0,arguments[0],arguments[1],arguments[2])}const F_=1,_3=Gs("apiVersion",()=>F_);if(_3!==F_)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function $f(e,t){const n=Se.useRef(t);n.current=t;const[r,o,s]=Se.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),c=new yc(`useStateTracking(${e})`,()=>{var u;return(u=n.current)==null?void 0:u.call(n)},{scheduleEffect(){i==null||i()}});return[c,a,()=>c.scheduleCount]},[e]);return Se.useSyncExternalStore(o,s,s),Se.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const Zb={apply(e,t,n){return $f(e.displayName??e.name??"tracked(???)",()=>e.apply(t,n))}},k3=Symbol.for("react.memo"),T3=Symbol.for("react.forward_ref");function or(e){let t=null;const n=e.$$typeof;return n===k3&&(e=e.type,t=e.compare),n===T3?x.memo(x.forwardRef(new Proxy(e.render,Zb))):x.memo(new Proxy(e,Zb),t)}function $3(){const e=arguments[0],t=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return x.useMemo(()=>V(`useComputed(${e})`,t,n),r)}function js(e,t,n=Do){x.useEffect(()=>{const r=new yc(e,t);return r.attach(),r.execute(),()=>{r.detach()}},n)}function K(){const e=arguments,t=e.length===3?e[2]:[e[0]],n=e.length===3?e[0]:`useValue(${e[0].name})`,r=x.useRef(!0);r.current=!0;const o=x.useMemo(()=>e.length===1?e[0]:V(n,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),t);try{const{subscribe:s,getSnapshot:i}=x.useMemo(()=>({subscribe:a=>Sc(`useValue(${n})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return x.useSyncExternalStore(s,i,i)}finally{r.current=!1}}class fh{constructor(t){m(this,"nextValue");m(this,"diff");this.previousValue=t}get(){var r,o,s,i;const t=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,n=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(t===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(t,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(t),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(t):((o=this.diff).added??(o.added=new Set),this.diff.added.add(t))}add(t){var o,s,i;const n=this.previousValue.has(t);if(n)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(t))?this._add(t,n):void 0;(i=this.nextValue)!=null&&i.has(t)||this._add(t,n)}_remove(t,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(t),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(t)):(o=this.diff.added)==null||o.delete(t)}remove(t){var o,s,i,a;const n=this.previousValue.has(t);if(!n)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(t))?this._remove(t,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(t)||this._remove(t,n)}}function Mp(e,t){const n=[];e:for(const r of e){for(const o of n)if(t?t(r,o):r===o)continue e;n.push(r)}return n}function fe(e){return e.filter(t=>t!=null)}function Wn(e){return e[e.length-1]}function M3(e,t){let n,r=1/0;for(const o of e){const s=t(o);s<r&&(n=o,r=s)}return n}function A3(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function N_(e,t){let n,r;return function(...o){return n||(n=!0,setTimeout(()=>n=!1,t),r=e(...o)),r}}function z_(e){const t=(...n)=>{try{return e(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,t),r}};return t}const Ha={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function qo(e,t){const n=t&&e&&typeof e=="object"&&t in e?e[t]:e;throw new Error(`Unknown switch case ${n}`)}const _t=z_((e,t)=>{if(!e)throw new Error(t||"Assertion Error")}),yi=z_((e,t)=>{if(e==null)throw new Error(t??"value must be defined");return e});function B_(e,t){let n;const r=(...o)=>(n||(n={},n.promise=new Promise((s,i)=>{n.resolve=s,n.reject=i})),clearTimeout(n.timeout),n.latestArgs=o,n.timeout=setTimeout(()=>{const s=n;n=void 0;try{s.resolve(e(...s.latestArgs))}catch(i){s.reject(i)}},t),n.promise);return r.cancel=()=>{n&&clearTimeout(n.timeout)},r}const Qb=new WeakMap;function j0(e,t){if(typeof e!="object"||e===null)return;let n=Qb.get(e);n||(n={tags:{},extras:{}},Qb.set(e,n)),t.tags&&(n.tags={...n.tags,...t.tags}),t.extras&&(n.extras={...n.extras,...t.extras})}class Ka{static async dataUrlToArrayBuffer(t){return fetch(t).then(function(n){return n.arrayBuffer()})}static async blobToDataUrl(t){return await new Promise((n,r)=>{if(t){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsDataURL(t)}})}static async blobToText(t){return await new Promise((n,r)=>{if(t){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsText(t)}})}}function $S(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t+""}function j3(e){const t=new DataView(e);let n=0;for(let r=0;r<t.byteLength;r++)n=(n<<5)-n+t.getUint8(r),n|=0;return n+""}let MS=[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"&&(MS=new Int32Array(MS));const O3=(e,t)=>{let n=~~t^-1;for(let r=0;r<e.length;r++)n=MS[(n^e[r])&255]^n>>>8;return n^-1},Jb=4,e1=4;class Zr{static isPng(t,n){return t.getUint8(n+0)===137&&t.getUint8(n+1)===80&&t.getUint8(n+2)===78&&t.getUint8(n+3)===71&&t.getUint8(n+4)===13&&t.getUint8(n+5)===10&&t.getUint8(n+6)===26&&t.getUint8(n+7)===10}static getChunkType(t,n){return[String.fromCharCode(t.getUint8(n)),String.fromCharCode(t.getUint8(n+1)),String.fromCharCode(t.getUint8(n+2)),String.fromCharCode(t.getUint8(n+3))].join("")}static readChunks(t,n=0){const r={};if(!Zr.isPng(t,n))throw new Error("Not a PNG");for(n+=8;n<=t.buffer.byteLength;){const o=n,s=t.getInt32(n);n+=4;const i=Zr.getChunkType(t,n);if(i==="IDAT"&&r[i]){n+=s+Jb+e1;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:n+4,size:s},n+=s+Jb+e1}return r}static parsePhys(t,n){return{ppux:t.getUint32(n),ppuy:t.getUint32(n+4),unit:t.getUint8(n+4)}}static findChunk(t,n){return Zr.readChunks(t)[n]}static setPhysChunk(t,n=1,r){let o=46,s=0;const i=Zr.findChunk(t,"pHYs");i&&(o=i.start,s=i.size);const a=Zr.findChunk(t,"IDAT");a&&(o=a.start,s=0);const c=new ArrayBuffer(21),l=new DataView(c);l.setUint32(0,9),l.setUint8(4,112),l.setUint8(5,72),l.setUint8(6,89),l.setUint8(7,115);const u=2835.5;l.setInt32(8,u*n),l.setInt32(12,u*n),l.setInt8(16,1);const d=new Uint8Array(c.slice(4,17));l.setInt32(17,O3(d));const p=t.buffer.slice(0,o),f=t.buffer.slice(o+s);return new Blob([p,c,f],r)}}class jo{static loadVideo(t){return new Promise((n,r)=>{const o=document.createElement("video");o.onloadeddata=()=>n(o),o.onerror=s=>{console.error(s),r(new Error("Could not load video"))},o.crossOrigin="anonymous",o.src=t})}static loadImage(t){return new Promise((n,r)=>{const o=new Image;o.onload=()=>n(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.src=t})}static async getVideoSize(t){return jo.usingObjectURL(t,async n=>{const r=await jo.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(t){const n=await jo.usingObjectURL(t,jo.loadImage);try{if(t.type==="image/png"){const r=new DataView(await t.arrayBuffer());if(Zr.isPng(r,0)){const o=Zr.findChunk(r,"pHYs");if(o){const s=Zr.parsePhys(r,o.dataOffset);if(s.unit===0&&s.ppux===s.ppuy){const i=Math.max(s.ppux/2834.5,1);return{w:Math.round(n.naturalWidth/i),h:Math.round(n.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:n.naturalWidth,h:n.naturalHeight}}return{w:n.naturalWidth,h:n.naturalHeight}}static async usingObjectURL(t,n){const r=URL.createObjectURL(t);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function Ys(e=""){let t=0,n=0,r=0,o=0;function s(){const i=t^t<<11;return t=n,n=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)t^=e.charCodeAt(i)|0,s();return s}function Ap(e,t,n,r=!1){const[o,s]=t,[i,a]=n,c=i+(e-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(c,a),i):Math.max(Math.min(c,i),a):c}function ro(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Lr(e,t){if(ro(e,t))return e[t]}function t1(e){return Object.keys(e)}function bt(e){return Object.values(e)}function An(e){return Object.entries(e)}function O0(e){return Object.fromEntries(e)}function nm(e,t){const n={};let r=!1;for(const[o,s]of An(e))t(o,s)?n[o]=s:r=!0;return r?n:e}function Mf(e,t){const n={};for(const[r,o]of An(e)){const s=t(r,o);n[r]=s}return n}function U_(e,t){if(e===t)return!0;const n=new Set(Object.keys(e)),r=new Set(Object.keys(t));if(n.size!==r.size)return!1;for(const o of n)if(!r.has(o)||!Object.is(e[o],t[o]))return!1;return!0}const Gn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",H_="a0",K_="A00000000000000000000000000";function W_(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("Invalid index key head: "+e)}function V_(e){if(e.length!==W_(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function n1(e){if(e===void 0)throw Error("n is undefined")}function r1(e){V_(e);const[t,...n]=e.split("");let r=!0;for(let o=n.length-1;r&&o>=0;o--){const s=Gn.indexOf(n[o])+1;s===Gn.length?n[o]="0":(n[o]=Gn.charAt(s),r=!1)}if(r){if(t==="Z")return"a0";if(t==="z")return;const o=String.fromCharCode(t.charCodeAt(0)+1);return o>"a"?n.push("0"):n.pop(),o+n.join("")}else return t+n.join("")}function D3(e){V_(e);const[t,...n]=e.split("");let r=!0;for(let o=n.length-1;r&&o>=0;o--){const s=Gn.indexOf(n[o])-1;s===-1?n[o]=Gn.slice(-1):(n[o]=Gn.charAt(s),r=!1)}if(r){if(t==="a")return"Z"+Gn.slice(-1);if(t==="A")return;const o=String.fromCharCode(t.charCodeAt(0)-1);return o<"Z"?n.push(Gn.slice(-1)):n.pop(),o+n.join("")}else return t+n.join("")}function ka(e,t){if(t!==void 0&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)==="0"||t&&t.slice(-1)==="0")throw new Error("trailing zero");if(t){let o=0;for(;(e.charAt(o)||"0")===t.charAt(o);)o++;if(o>0)return t.slice(0,o)+ka(e.slice(o),t.slice(o))}const n=e?Gn.indexOf(e.charAt(0)):0,r=t!==void 0?Gn.indexOf(t.charAt(0)):Gn.length;if(r-n>1){const o=Math.round(.5*(n+r));return Gn.charAt(o)}else return t&&t.length>1?t.slice(0,1):Gn.charAt(n)+ka(e.slice(1),void 0)}function gl(e){const t=W_(e.charAt(0));if(t>e.length)throw new Error("invalid index: "+e);return e.slice(0,t)}function AS(e){if(e===K_)throw new Error("invalid index: "+e);const t=gl(e);if(e.slice(t.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function Ji(e,t){if(e!==void 0&&AS(e),t!==void 0&&AS(t),e!==void 0&&t!==void 0&&e>=t)throw new Error(e+" >= "+t);if(e===void 0&&t===void 0)return H_;if(e===void 0){if(t===void 0)throw Error("b is undefined");const a=gl(t),c=t.slice(a.length);if(a===K_)return a+ka("",c);if(a<t)return a;const l=D3(a);return n1(l),l}if(t===void 0){const a=gl(e),c=e.slice(a.length),l=r1(a);return l===void 0?a+ka(c,void 0):l}const n=gl(e),r=e.slice(n.length),o=gl(t),s=t.slice(o.length);if(n===o)return n+ka(r,s);const i=r1(n);return n1(i),i<t?i:n+ka(r,void 0)}function Ls(e,t,n){if(n===0)return[];if(n===1)return[Ji(e,t)];if(t===void 0){let s=Ji(e,t);const i=[s];for(let a=0;a<n-1;a++)s=Ji(s,t),i.push(s);return i}if(e===void 0){let s=Ji(e,t);const i=[s];for(let a=0;a<n-1;a++)s=Ji(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(n/2),o=Ji(e,t);return[...Ls(e,o,r),o,...Ls(o,t,n-r-1)]}const R3=H_;function L3(e){AS(e)}function oc(e,t,n){return Ls(e,t,n)}function rm(e,t){return Ls(e,void 0,t)}function kl(e,t){return Ls(e,t,1)[0]}function $o(e){return Ls(e,void 0,1)[0]}function F3(e){return Ls(void 0,e,1)[0]}function eu(e,t="a1"){return[t,...Ls(t,void 0,e)]}function en(e,t){return e.index<t.index?-1:e.index>t.index?1:0}function N3(e,t){return e.id>t.id?1:-1}function D0(e){try{return localStorage.getItem(e)}catch{return null}}function R0(e,t){try{localStorage.setItem(e,t)}catch{}}function z3(){try{localStorage.clear()}catch{}}function G_(e){try{return sessionStorage.getItem(e)}catch{return null}}function L0(e,t){try{sessionStorage.setItem(e,t)}catch{}}function Y_(e){try{sessionStorage.removeItem(e)}catch{}}function B3(){try{sessionStorage.clear()}catch{}}const U3=()=>typeof process<"u"&&!1,Ta=[],H3=60,gh=Math.ceil(1e3/H3);let Vc,om=0,jS=0;const K3=()=>{const e=Ta.splice(0,Ta.length);for(const t of e)t()};function X_(){if(Vc)return;const e=Date.now(),t=e-jS;if(om+t<gh){Vc=requestAnimationFrame(()=>{Vc=void 0,X_()});return}Vc=requestAnimationFrame(()=>{Vc=void 0,jS=e,om=Math.min(om+t-gh,gh*10),K3()})}let o1=!1;function q_(e){return U3()?(e(),()=>{}):(Ta.includes(e)||(Ta.push(e),o1||(o1=!0,jS=Date.now()-gh-1),X_()),()=>{const t=Ta.indexOf(e);t>-1&&Ta.splice(t,1)})}function W3(e){return e!==null}function V3(){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]:[e=>e&&JSON.parse(JSON.stringify(e)),!1]}const Z_=V3(),Ye=Z_[0];Z_[1];const G3=Object.getPrototypeOf(Ye({}));let Q_=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");class F0{constructor(t,n){m(this,"createDefaultProperties");m(this,"validator");m(this,"scope");m(this,"isInstance",t=>(t==null?void 0:t.typeName)===this.typeName);this.typeName=t,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:r=>r},this.scope=n.scope??"document"}create(t){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,o]of Object.entries(t))o!==void 0&&(n[r]=o);return n.typeName=this.typeName,n}clone(t){return{...Ye(t),id:this.createId()}}createId(t){return this.typeName+":"+(t??Q_())}createCustomId(t){return this.typeName+":"+t}parseId(t){if(!this.isId(t))throw new Error(`ID "${t}" is not a valid ID for type "${this.typeName}"`);return t.slice(this.typeName.length+1)}isId(t){if(!t)return!1;for(let n=0;n<this.typeName.length;n++)if(t[n]!==this.typeName[n])return!1;return t[this.typeName.length]===":"}withDefaultProperties(t){return new F0(this.typeName,{createDefaultProperties:t,validator:this.validator,scope:this.scope})}validate(t,n){return n&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(n,t):this.validator.validate(t)}}function Zo(e,t){return new F0(e,{createDefaultProperties:()=>({}),validator:t.validator,scope:t.scope})}class s1{constructor(){m(this,"items",new WeakMap)}get(t,n){return this.items.has(t)||this.items.set(t,n(t)),this.items.get(t)}}var jp={exports:{}};jp.exports;(function(e,t){var n=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",c="[object Array]",l="[object AsyncFunction]",u="[object Boolean]",d="[object Date]",p="[object Error]",f="[object Function]",y="[object GeneratorFunction]",g="[object Map]",w="[object Number]",S="[object Null]",v="[object Object]",b="[object Promise]",E="[object Proxy]",C="[object RegExp]",I="[object Set]",_="[object String]",k="[object Symbol]",$="[object Undefined]",T="[object WeakMap]",O="[object ArrayBuffer]",N="[object DataView]",F="[object Float32Array]",L="[object Float64Array]",B="[object Int8Array]",q="[object Int16Array]",Q="[object Int32Array]",H="[object Uint8Array]",U="[object Uint8ClampedArray]",W="[object Uint16Array]",Z="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,be=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,ae={};ae[F]=ae[L]=ae[B]=ae[q]=ae[Q]=ae[H]=ae[U]=ae[W]=ae[Z]=!0,ae[a]=ae[c]=ae[O]=ae[u]=ae[N]=ae[d]=ae[p]=ae[f]=ae[g]=ae[w]=ae[v]=ae[C]=ae[I]=ae[_]=ae[T]=!1;var Ae=typeof tn=="object"&&tn&&tn.Object===Object&&tn,Re=typeof self=="object"&&self&&self.Object===Object&&self,ot=Ae||Re||Function("return this")(),Ie=t&&!t.nodeType&&t,ht=Ie&&!0&&e&&!e.nodeType&&e,He=ht&&ht.exports===Ie,ir=He&&Ae.process,Ln=function(){try{return ir&&ir.binding&&ir.binding("util")}catch{}}(),Fn=Ln&&Ln.isTypedArray;function qe(M,D){for(var G=-1,ee=M==null?0:M.length,Ze=0,me=[];++G<ee;){var pt=M[G];D(pt,G,M)&&(me[Ze++]=pt)}return me}function Ot(M,D){for(var G=-1,ee=D.length,Ze=M.length;++G<ee;)M[Ze+G]=D[G];return M}function wo(M,D){for(var G=-1,ee=M==null?0:M.length;++G<ee;)if(D(M[G],G,M))return!0;return!1}function Ac(M,D){for(var G=-1,ee=Array(M);++G<M;)ee[G]=D(G);return ee}function jc(M){return function(D){return M(D)}}function bg(M,D){return M.has(D)}function qi(M,D){return M==null?void 0:M[D]}function jj(M){var D=-1,G=Array(M.size);return M.forEach(function(ee,Ze){G[++D]=[Ze,ee]}),G}function Oj(M,D){return function(G){return M(D(G))}}function Dj(M){var D=-1,G=Array(M.size);return M.forEach(function(ee){G[++D]=ee}),G}var Rj=Array.prototype,Lj=Function.prototype,Gu=Object.prototype,Pg=ot["__core-js_shared__"],ww=Lj.toString,Wr=Gu.hasOwnProperty,bw=function(){var M=/[^.]+$/.exec(Pg&&Pg.keys&&Pg.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),Pw=Gu.toString,Fj=RegExp("^"+ww.call(Wr).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Cw=He?ot.Buffer:void 0,Yu=ot.Symbol,Iw=ot.Uint8Array,Ew=Gu.propertyIsEnumerable,Nj=Rj.splice,ni=Yu?Yu.toStringTag:void 0,_w=Object.getOwnPropertySymbols,zj=Cw?Cw.isBuffer:void 0,Bj=Oj(Object.keys,Object),Cg=Zi(ot,"DataView"),Oc=Zi(ot,"Map"),Ig=Zi(ot,"Promise"),Eg=Zi(ot,"Set"),_g=Zi(ot,"WeakMap"),Dc=Zi(Object,"create"),Uj=si(Cg),Hj=si(Oc),Kj=si(Ig),Wj=si(Eg),Vj=si(_g),kw=Yu?Yu.prototype:void 0,kg=kw?kw.valueOf:void 0;function ri(M){var D=-1,G=M==null?0:M.length;for(this.clear();++D<G;){var ee=M[D];this.set(ee[0],ee[1])}}function Gj(){this.__data__=Dc?Dc(null):{},this.size=0}function Yj(M){var D=this.has(M)&&delete this.__data__[M];return this.size-=D?1:0,D}function Xj(M){var D=this.__data__;if(Dc){var G=D[M];return G===r?void 0:G}return Wr.call(D,M)?D[M]:void 0}function qj(M){var D=this.__data__;return Dc?D[M]!==void 0:Wr.call(D,M)}function Zj(M,D){var G=this.__data__;return this.size+=this.has(M)?0:1,G[M]=Dc&&D===void 0?r:D,this}ri.prototype.clear=Gj,ri.prototype.delete=Yj,ri.prototype.get=Xj,ri.prototype.has=qj,ri.prototype.set=Zj;function bo(M){var D=-1,G=M==null?0:M.length;for(this.clear();++D<G;){var ee=M[D];this.set(ee[0],ee[1])}}function Qj(){this.__data__=[],this.size=0}function Jj(M){var D=this.__data__,G=qu(D,M);if(G<0)return!1;var ee=D.length-1;return G==ee?D.pop():Nj.call(D,G,1),--this.size,!0}function eO(M){var D=this.__data__,G=qu(D,M);return G<0?void 0:D[G][1]}function tO(M){return qu(this.__data__,M)>-1}function nO(M,D){var G=this.__data__,ee=qu(G,M);return ee<0?(++this.size,G.push([M,D])):G[ee][1]=D,this}bo.prototype.clear=Qj,bo.prototype.delete=Jj,bo.prototype.get=eO,bo.prototype.has=tO,bo.prototype.set=nO;function oi(M){var D=-1,G=M==null?0:M.length;for(this.clear();++D<G;){var ee=M[D];this.set(ee[0],ee[1])}}function rO(){this.size=0,this.__data__={hash:new ri,map:new(Oc||bo),string:new ri}}function oO(M){var D=Zu(this,M).delete(M);return this.size-=D?1:0,D}function sO(M){return Zu(this,M).get(M)}function iO(M){return Zu(this,M).has(M)}function aO(M,D){var G=Zu(this,M),ee=G.size;return G.set(M,D),this.size+=G.size==ee?0:1,this}oi.prototype.clear=rO,oi.prototype.delete=oO,oi.prototype.get=sO,oi.prototype.has=iO,oi.prototype.set=aO;function Xu(M){var D=-1,G=M==null?0:M.length;for(this.__data__=new oi;++D<G;)this.add(M[D])}function cO(M){return this.__data__.set(M,r),this}function lO(M){return this.__data__.has(M)}Xu.prototype.add=Xu.prototype.push=cO,Xu.prototype.has=lO;function is(M){var D=this.__data__=new bo(M);this.size=D.size}function uO(){this.__data__=new bo,this.size=0}function dO(M){var D=this.__data__,G=D.delete(M);return this.size=D.size,G}function hO(M){return this.__data__.get(M)}function pO(M){return this.__data__.has(M)}function fO(M,D){var G=this.__data__;if(G instanceof bo){var ee=G.__data__;if(!Oc||ee.length<n-1)return ee.push([M,D]),this.size=++G.size,this;G=this.__data__=new oi(ee)}return G.set(M,D),this.size=G.size,this}is.prototype.clear=uO,is.prototype.delete=dO,is.prototype.get=hO,is.prototype.has=pO,is.prototype.set=fO;function gO(M,D){var G=Qu(M),ee=!G&&$O(M),Ze=!G&&!ee&&Tg(M),me=!G&&!ee&&!Ze&&Lw(M),pt=G||ee||Ze||me,kt=pt?Ac(M.length,String):[],Dt=kt.length;for(var st in M)Wr.call(M,st)&&!(pt&&(st=="length"||Ze&&(st=="offset"||st=="parent")||me&&(st=="buffer"||st=="byteLength"||st=="byteOffset")||IO(st,Dt)))&&kt.push(st);return kt}function qu(M,D){for(var G=M.length;G--;)if(jw(M[G][0],D))return G;return-1}function mO(M,D,G){var ee=D(M);return Qu(M)?ee:Ot(ee,G(M))}function Rc(M){return M==null?M===void 0?$:S:ni&&ni in Object(M)?PO(M):TO(M)}function Tw(M){return Lc(M)&&Rc(M)==a}function $w(M,D,G,ee,Ze){return M===D?!0:M==null||D==null||!Lc(M)&&!Lc(D)?M!==M&&D!==D:yO(M,D,G,ee,$w,Ze)}function yO(M,D,G,ee,Ze,me){var pt=Qu(M),kt=Qu(D),Dt=pt?c:as(M),st=kt?c:as(D);Dt=Dt==a?v:Dt,st=st==a?v:st;var Nn=Dt==v,Pr=st==v,Wt=Dt==st;if(Wt&&Tg(M)){if(!Tg(D))return!1;pt=!0,Nn=!1}if(Wt&&!Nn)return me||(me=new is),pt||Lw(M)?Mw(M,D,G,ee,Ze,me):wO(M,D,Dt,G,ee,Ze,me);if(!(G&o)){var ar=Nn&&Wr.call(M,"__wrapped__"),cr=Pr&&Wr.call(D,"__wrapped__");if(ar||cr){var cs=ar?M.value():M,Po=cr?D.value():D;return me||(me=new is),Ze(cs,Po,G,ee,me)}}return Wt?(me||(me=new is),bO(M,D,G,ee,Ze,me)):!1}function SO(M){if(!Rw(M)||_O(M))return!1;var D=Ow(M)?Fj:be;return D.test(si(M))}function vO(M){return Lc(M)&&Dw(M.length)&&!!ae[Rc(M)]}function xO(M){if(!kO(M))return Bj(M);var D=[];for(var G in Object(M))Wr.call(M,G)&&G!="constructor"&&D.push(G);return D}function Mw(M,D,G,ee,Ze,me){var pt=G&o,kt=M.length,Dt=D.length;if(kt!=Dt&&!(pt&&Dt>kt))return!1;var st=me.get(M);if(st&&me.get(D))return st==D;var Nn=-1,Pr=!0,Wt=G&s?new Xu:void 0;for(me.set(M,D),me.set(D,M);++Nn<kt;){var ar=M[Nn],cr=D[Nn];if(ee)var cs=pt?ee(cr,ar,Nn,D,M,me):ee(ar,cr,Nn,M,D,me);if(cs!==void 0){if(cs)continue;Pr=!1;break}if(Wt){if(!wo(D,function(Po,ii){if(!bg(Wt,ii)&&(ar===Po||Ze(ar,Po,G,ee,me)))return Wt.push(ii)})){Pr=!1;break}}else if(!(ar===cr||Ze(ar,cr,G,ee,me))){Pr=!1;break}}return me.delete(M),me.delete(D),Pr}function wO(M,D,G,ee,Ze,me,pt){switch(G){case N:if(M.byteLength!=D.byteLength||M.byteOffset!=D.byteOffset)return!1;M=M.buffer,D=D.buffer;case O:return!(M.byteLength!=D.byteLength||!me(new Iw(M),new Iw(D)));case u:case d:case w:return jw(+M,+D);case p:return M.name==D.name&&M.message==D.message;case C:case _:return M==D+"";case g:var kt=jj;case I:var Dt=ee&o;if(kt||(kt=Dj),M.size!=D.size&&!Dt)return!1;var st=pt.get(M);if(st)return st==D;ee|=s,pt.set(M,D);var Nn=Mw(kt(M),kt(D),ee,Ze,me,pt);return pt.delete(M),Nn;case k:if(kg)return kg.call(M)==kg.call(D)}return!1}function bO(M,D,G,ee,Ze,me){var pt=G&o,kt=Aw(M),Dt=kt.length,st=Aw(D),Nn=st.length;if(Dt!=Nn&&!pt)return!1;for(var Pr=Dt;Pr--;){var Wt=kt[Pr];if(!(pt?Wt in D:Wr.call(D,Wt)))return!1}var ar=me.get(M);if(ar&&me.get(D))return ar==D;var cr=!0;me.set(M,D),me.set(D,M);for(var cs=pt;++Pr<Dt;){Wt=kt[Pr];var Po=M[Wt],ii=D[Wt];if(ee)var Fw=pt?ee(ii,Po,Wt,D,M,me):ee(Po,ii,Wt,M,D,me);if(!(Fw===void 0?Po===ii||Ze(Po,ii,G,ee,me):Fw)){cr=!1;break}cs||(cs=Wt=="constructor")}if(cr&&!cs){var Ju=M.constructor,ed=D.constructor;Ju!=ed&&"constructor"in M&&"constructor"in D&&!(typeof Ju=="function"&&Ju instanceof Ju&&typeof ed=="function"&&ed instanceof ed)&&(cr=!1)}return me.delete(M),me.delete(D),cr}function Aw(M){return mO(M,jO,CO)}function Zu(M,D){var G=M.__data__;return EO(D)?G[typeof D=="string"?"string":"hash"]:G.map}function Zi(M,D){var G=qi(M,D);return SO(G)?G:void 0}function PO(M){var D=Wr.call(M,ni),G=M[ni];try{M[ni]=void 0;var ee=!0}catch{}var Ze=Pw.call(M);return ee&&(D?M[ni]=G:delete M[ni]),Ze}var CO=_w?function(M){return M==null?[]:(M=Object(M),qe(_w(M),function(D){return Ew.call(M,D)}))}:OO,as=Rc;(Cg&&as(new Cg(new ArrayBuffer(1)))!=N||Oc&&as(new Oc)!=g||Ig&&as(Ig.resolve())!=b||Eg&&as(new Eg)!=I||_g&&as(new _g)!=T)&&(as=function(M){var D=Rc(M),G=D==v?M.constructor:void 0,ee=G?si(G):"";if(ee)switch(ee){case Uj:return N;case Hj:return g;case Kj:return b;case Wj:return I;case Vj:return T}return D});function IO(M,D){return D=D??i,!!D&&(typeof M=="number"||Me.test(M))&&M>-1&&M%1==0&&M<D}function EO(M){var D=typeof M;return D=="string"||D=="number"||D=="symbol"||D=="boolean"?M!=="__proto__":M===null}function _O(M){return!!bw&&bw in M}function kO(M){var D=M&&M.constructor,G=typeof D=="function"&&D.prototype||Gu;return M===G}function TO(M){return Pw.call(M)}function si(M){if(M!=null){try{return ww.call(M)}catch{}try{return M+""}catch{}}return""}function jw(M,D){return M===D||M!==M&&D!==D}var $O=Tw(function(){return arguments}())?Tw:function(M){return Lc(M)&&Wr.call(M,"callee")&&!Ew.call(M,"callee")},Qu=Array.isArray;function MO(M){return M!=null&&Dw(M.length)&&!Ow(M)}var Tg=zj||DO;function AO(M,D){return $w(M,D)}function Ow(M){if(!Rw(M))return!1;var D=Rc(M);return D==f||D==y||D==l||D==E}function Dw(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=i}function Rw(M){var D=typeof M;return M!=null&&(D=="object"||D=="function")}function Lc(M){return M!=null&&typeof M=="object"}var Lw=Fn?jc(Fn):vO;function jO(M){return MO(M)?gO(M):xO(M)}function OO(){return[]}function DO(){return!1}e.exports=AO})(jp,jp.exports);var Y3=jp.exports;const X3=pc(Y3);function q3(e){if(e.length===0)return new Set;const t=e[0],n=e.slice(1),r=new Set;for(const o of t)n.every(s=>s.has(o))&&r.add(o);return r}function Z3(e,t){const n={};for(const r of t)e.has(r)||(n.added??(n.added=new Set),n.added.add(r));for(const r of e)t.has(r)||(n.removed??(n.removed=new Set),n.removed.add(r));return n.added||n.removed?n:void 0}function i1(e,t){for(const[n,r]of Object.entries(e)){const o=r,s=t[n];if("eq"in o&&s!==o.eq||"neq"in o&&s===o.neq||"gt"in o&&(typeof s!="number"||s<=o.gt))return!1}return!0}function a1(e,t,n){const r=Object.fromEntries(Object.keys(n).map(o=>[o,new Set]));for(const[o,s]of Object.entries(n))if("eq"in s){const a=e.index(t,o).get().get(s.eq);if(a)for(const c of a)r[o].add(c)}else if("neq"in s){const i=e.index(t,o);for(const[a,c]of i.get())if(a!==s.neq)for(const l of c)r[o].add(l)}else if("gt"in s){const i=e.index(t,o);for(const[a,c]of i.get())if(a>s.gt)for(const l of c)r[o].add(l)}return q3(Object.values(r))}class Q3{constructor(t,n){m(this,"indexCache",new Map);m(this,"historyCache",new Map);this.atoms=t,this.history=n}filterHistory(t){if(this.historyCache.has(t))return this.historyCache.get(t);const n=V("filterHistory:"+t,(r,o)=>{if(Pi(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===qn)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,c=0,l=0;for(const u of s){for(const d of bt(u.added))if(d.typeName===t)if(i.removed[d.id]){const p=i.removed[d.id];delete i.removed[d.id],c--,p!==d&&(i.updated[d.id]=[p,d],l++)}else i.added[d.id]=d,a++;for(const[d,p]of bt(u.updated))p.typeName===t&&(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]=[d,p],l++));for(const d of bt(u.removed))d.typeName===t&&(i.added[d.id]?(delete i.added[d.id],a--):i.updated[d.id]?(i.removed[d.id]=i.updated[d.id][0],delete i.updated[d.id],l--,c++):(i.removed[d.id]=d,c++))}return a||c||l?fl(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(t,n),n}index(t,n){const r=t+":"+n;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(t,n);return this.indexCache.set(r,o),o}__uncached_createIndex(t,n){const r=this.filterHistory(t),o=()=>{r.get();const s=new Map;for(const i of bt(this.atoms.get())){const a=i.get();if(a.typeName===t){const c=a[n];s.has(c)||s.set(c,new Set),s.get(c).add(a.id)}}return s};return V("index:"+t+":"+n,(s,i)=>{if(Pi(s))return o();const a=r.getDiffSince(i);if(a===qn)return o();const c=new Map,l=(f,y)=>{let g=c.get(f);g||(g=new fh(s.get(f)??new Set)),g.add(y),c.set(f,g)},u=(f,y)=>{let g=c.get(f);g||(g=new fh(s.get(f)??new Set)),g.remove(y),c.set(f,g)};for(const f of a){for(const y of bt(f.added))if(y.typeName===t){const g=y[n];l(g,y.id)}for(const[y,g]of bt(f.updated))if(g.typeName===t){const w=y[n],S=g[n];w!==S&&(u(w,g.id),l(S,g.id))}for(const y of bt(f.removed))if(y.typeName===t){const g=y[n];u(g,y.id)}}let d,p;for(const[f,y]of c){const g=y.get();g&&(d||(d=new Map(s)),p||(p=new Map),g.value.size===0?d.delete(f):d.set(f,g.value),p.set(f,g.diff))}return d&&p?fl(d,p):s},{historyLength:100})}record(t,n=()=>({}),r="record:"+t+(n?":"+n.toString():"")){const o=this.ids(t,n,r);return V(r,()=>{var s;for(const i of o.get())return(s=this.atoms.get()[i])==null?void 0:s.get()})}records(t,n=()=>({}),r="records:"+t+(n?":"+n.toString():"")){const o=this.ids(t,n,"ids:"+r);return V(r,()=>[...o.get()].map(s=>{const i=this.atoms.get()[s];if(!i)throw new Error("no atom found for record id: "+s);return i.get()}))}ids(t,n=()=>({}),r="ids:"+t+(n?":"+n.toString():"")){const o=this.filterHistory(t),s=()=>{o.get();const c=n();return Object.keys(c).length===0?new Set(bt(this.atoms.get()).flatMap(l=>{const u=l.get();return u.typeName===t?u.id:[]})):a1(this,t,c)},i=c=>{const l=s(),u=Z3(c,l);return u?fl(l,u):c},a=V("ids_query:"+r,n,{isEqual:X3});return V("query:"+r,(c,l)=>{const u=a.get();if(Pi(c))return s();if(l<a.lastChangedEpoch)return i(c);const d=o.getDiffSince(l);if(d===qn)return i(c);const p=new fh(c);for(const y of d){for(const g of bt(y.added))g.typeName===t&&i1(u,g)&&p.add(g.id);for(const[g,w]of bt(y.updated))w.typeName===t&&(i1(u,w)?p.add(w.id):p.remove(w.id));for(const g of bt(y.removed))g.typeName===t&&p.remove(g.id)}const f=p.get();return f?fl(f.value,f.diff):c},{historyLength:50})}exec(t,n){const r=a1(this,t,n);if(r.size===0)return Do;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class J_{constructor(t){m(this,"id",Q_());m(this,"atoms",fn("store_atoms",{}));m(this,"history",fn("history",0,{historyLength:1e3}));m(this,"query",new Q3(this.atoms,this.history));m(this,"listeners",new Set);m(this,"historyAccumulator",new eL);m(this,"historyReactor");m(this,"schema");m(this,"props");m(this,"scopedTypes");m(this,"onBeforeCreate");m(this,"onAfterCreate");m(this,"onBeforeChange");m(this,"onAfterChange");m(this,"onBeforeDelete");m(this,"onAfterDelete");m(this,"_runCallbacks",!0);m(this,"put",(t,n)=>{Mr(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,c=!1;const l=this.onBeforeCreate&&this._runCallbacks?this.onBeforeCreate:null,u=this.onBeforeChange&&this._runCallbacks?this.onBeforeChange:null,d=this.isMergingRemoteChanges?"remote":"user";for(let p=0,f=t.length;p<f;p++){a=t[p];const y=(i??s)[a.id];if(y){const g=y.__unsafe__getWithoutCapture();if(u&&(a=u(g,a,d)),this.schema.validateRecord(this,a,n??"updateRecord",g)===g)continue;y.set(a),c=!0,r[a.id]=[g,y.__unsafe__getWithoutCapture()]}else l&&(a=l(a,d)),c=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),o[a.id]=a,i||(i={...s}),i[a.id]=fn("atom:"+a.id,a)}if(i&&this.atoms.set(i),!!c&&(this.updateHistory({added:o,updated:r,removed:{}}),this._runCallbacks)){const{onAfterCreate:p,onAfterChange:f}=this;p&&Object.values(o).forEach(y=>{p(y,d)}),f&&Object.values(r).forEach(([y,g])=>{f(y,g,d)})}})});m(this,"remove",t=>{Mr(()=>{const n=[],r=this.isMergingRemoteChanges?"remote":"user";if(this.onBeforeDelete&&this._runCallbacks)for(const s of t){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.onBeforeDelete(i.get(),r)===!1&&n.push(s)}let o;if(this.atoms.update(s=>{let i;for(const a of t)n.includes(a)||a in s&&(i||(i={...s}),o||(o={}),delete i[a],o[a]=s[a].get());return i??s}),!!o&&(this.updateHistory({added:{},updated:{},removed:o}),this.onAfterDelete&&this._runCallbacks)){let s;for(let i=0,a=t.length;i<a;i++)s=o[t[i]],s&&this.onAfterDelete(s,r)}})});m(this,"get",t=>{var n;return(n=this.atoms.get()[t])==null?void 0:n.get()});m(this,"unsafeGetWithoutCapture",t=>{var n;return(n=this.atoms.get()[t])==null?void 0:n.__unsafe__getWithoutCapture()});m(this,"serialize",(t="document")=>{const n={};for(const[r,o]of An(this.atoms.get())){const s=o.get();(t==="all"||this.scopedTypes[t].has(s.typeName))&&(n[r]=s)}return n});m(this,"allRecords",()=>bt(this.atoms.get()).map(t=>t.get()));m(this,"clear",()=>{this.remove(t1(this.atoms.get()))});m(this,"update",(t,n)=>{const r=this.atoms.get()[t];if(!r){console.error(`Record ${t} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])});m(this,"has",t=>!!this.atoms.get()[t]);m(this,"listen",(t,n)=>{this._flushHistory();const r={onHistory:t,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.listeners.add(r),this.historyReactor.scheduler.isActivelyListening||this.historyReactor.start(),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}});m(this,"isMergingRemoteChanges",!1);m(this,"mergeRemoteChanges",t=>{if(this.isMergingRemoteChanges)return t();try{this.isMergingRemoteChanges=!0,Mr(t)}finally{this.isMergingRemoteChanges=!1}});m(this,"createComputedCache",(t,n,r)=>{const o=new s1;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?V(i.name+":equals",()=>i.get(),{isEqual:r}):i;return V(t+":"+s,()=>n(a.get()))}).get()}}});m(this,"createSelectedComputedCache",(t,n,r)=>{const o=new s1;return{get:s=>{const i=this.atoms.get()[s];if(!i)return;const a=V(t+":"+s+":selector",()=>n(i.get()));return o.get(i,()=>V(t+":"+s,()=>r(a.get()))).get()}}});m(this,"getRecordType",t=>{const n=this.schema.types[t.typeName];if(!n)throw new Error(`Record type ${t.typeName} not found`);return n});m(this,"_integrityChecker");m(this,"_isPossiblyCorrupted",!1);const{initialData:n,schema:r}=t;this.schema=r,this.props=t.props,n&&this.atoms.set(O0(An(n).map(([o,s])=>[o,fn("atom:"+o,this.schema.validateRecord(this,s,"initialize",null))]))),this.historyReactor=g3("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>q_(o)}),this.scopedTypes={document:new Set(bt(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(bt(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(bt(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const t=this.historyAccumulator.flush();for(const{changes:n,source:r}of t){let o=null,s=null,i=null;for(const{onHistory:a,filters:c}of this.listeners)if(!(c.source!=="all"&&c.source!==r))if(c.scope!=="all")if(c.scope==="document"){if(s??(s=this.filterChangesByScope(n,"document")),!s)continue;a({changes:s,source:r})}else if(c.scope==="session"){if(o??(o=this.filterChangesByScope(n,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(n,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:n,source:r})}}}filterChangesByScope(t,n){const r={added:nm(t.added,(o,s)=>this.scopedTypes[n].has(s.typeName)),updated:nm(t.updated,(o,s)=>this.scopedTypes[n].has(s[1].typeName)),removed:nm(t.removed,(o,s)=>this.scopedTypes[n].has(s.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(t){this.historyAccumulator.add({changes:t,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,t)}validate(t){this.allRecords().forEach(n=>this.schema.validateRecord(this,n,t,null))}getSnapshot(t="document"){return{store:this.serialize(t),schema:this.schema.serialize()}}migrateSnapshot(t){const n=this.schema.migrateStoreSnapshot(t);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);return{store:n.value,schema:this.schema.serialize()}}loadSnapshot(t){const n=this.schema.migrateStoreSnapshot(t);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);const r=this._runCallbacks;try{this._runCallbacks=!1,Mr(()=>{this.clear(),this.put(Object.values(n.value)),this.ensureStoreIsUsable()})}finally{this._runCallbacks=r}}extractingChanges(t){const n=[],r=this.historyAccumulator.intercepting(o=>n.push(o.changes));try{return Mr(t),Af(n)}finally{r()}}applyDiff(t,n=!0){const r=this._runCallbacks;try{this._runCallbacks=n,Mr(()=>{const o=bt(t.added).concat(bt(t.updated).map(([i,a])=>a)),s=t1(t.removed);o.length&&this.put(o),s.length&&this.remove(s)})}finally{this._runCallbacks=r}}ensureStoreIsUsable(){var t;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(t=this._integrityChecker)==null||t.call(this)}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}}function Af(e){const t={added:{},removed:{},updated:{}};for(const n of e){for(const[r,o]of An(n.added))if(t.removed[r]){const s=t.removed[r];delete t.removed[r],s!==o&&(t.updated[r]=[s,o])}else t.added[r]=o;for(const[r,[o,s]]of An(n.updated)){if(t.added[r]){t.added[r]=s,delete t.updated[r],delete t.removed[r];continue}if(t.updated[r]){t.updated[r]=[t.updated[r][0],s],delete t.removed[r];continue}t.updated[r]=n.updated[r],delete t.removed[r]}for(const[r,o]of An(n.removed))t.added[r]?delete t.added[r]:t.updated[r]?(t.removed[r]=t.updated[r][0],delete t.updated[r]):t.removed[r]=o}return t}function J3(e){if(e.length===0)return[];const t=[];let n=[e[0]],r;for(let o=1,s=e.length;o<s;o++)r=e[o],n[0].source!==r.source&&(t.push(n),n=[]),n.push(r);return t.push(n),t.map(o=>({source:o[0].source,changes:Af(o.map(s=>s.changes))}))}class eL{constructor(){m(this,"_history",[]);m(this,"_interceptors",new Set)}intercepting(t){return this._interceptors.add(t),()=>{this._interceptors.delete(t)}}add(t){this._history.push(t);for(const n of this._interceptors)n(t)}flush(){const t=J3(this._history);return this._history=[],t}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function tL(e){const t=[];for(let n=e.length-1;n>=0;n--){const r=e[n];if("id"in r)t.unshift(r);else{const o=r.dependsOn,s=t[0];s&&(t[0]={...s,dependsOn:o.concat(s.dependsOn??[])})}}return t}function Tl({sequence:e,sequenceId:t,retroactive:n=!0}){const r={sequenceId:t,retroactive:n,sequence:tL(e)};return ek(r),r}function sr(e,t){return Object.fromEntries(An(t).map(([n,r])=>[n,`${e}/${r}`]))}function xr(e){const t=e.sequenceId;return Tl({sequenceId:t,retroactive:e.retroactive??!0,sequence:e.sequence.map(n=>"id"in n?{...n,scope:"record",filter:r=>{var o,s;return r.typeName===e.recordType&&(((o=n.filter)==null?void 0:o.call(n,r))??!0)&&(((s=e.filter)==null?void 0:s.call(e,r))??!0)}}:n)})}function nL(e){const t=new Map(e.map(s=>[s.id,s])),n=new Set,r=[];function o(s){_t(!n.has(s.id),`Circular dependency in migrations: ${s.id}`),n.add(s.id);const{version:i,sequenceId:a}=Op(s.id),c=t.get(`${a}/${i-1}`);if(c&&o(c),s.dependsOn)for(const l of s.dependsOn){const u=t.get(l);u&&o(u)}t.delete(s.id),r.push(s)}for(const s of t.values())o(s);return r}function Op(e){const[t,n]=e.split("/");return{sequenceId:t,version:parseInt(n)}}function c1(e,t){t&&_t(e.startsWith(t+"/"),`Every migration in sequence '${t}' must have an id starting with '${t}/'. Got invalid id: '${e}'`),_t(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function ek(e){if(_t(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),_t(e.sequenceId.length,"sequenceId must be a non-empty string"),e.sequence.length===0)return;c1(e.sequence[0].id,e.sequenceId);let t=Op(e.sequence[0].id).version;_t(t===1,`Expected the first migrationId to be '${e.sequenceId}/1' but got '${e.sequence[0].id}'`);for(let n=1;n<e.sequence.length;n++){const r=e.sequence[n].id;c1(r,e.sequenceId);const o=Op(r).version;_t(o===t+1,`Migration id numbers must increase in increments of 1, expected ${e.sequenceId}/${t+1} but got '${e.sequence[n].id}'`),t=o}}var ps=(e=>(e.IncompatibleSubtype="incompatible-subtype",e.UnknownType="unknown-type",e.TargetVersionTooNew="target-version-too-new",e.TargetVersionTooOld="target-version-too-old",e.MigrationError="migration-error",e.UnrecognizedSubtype="unrecognized-subtype",e))(ps||{});function rL(e){if(e.schemaVersion>2||e.schemaVersion<1)return Ha.err("Bad schema version");if(e.schemaVersion===2)return Ha.ok(e);const t={schemaVersion:2,sequences:{}};for(const[n,r]of Object.entries(e.recordVersions))if(t.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(const[o,s]of Object.entries(r.subTypeVersions))t.sequences[`com.tldraw.${n}.${o}`]=s;return Ha.ok(t)}class N0{constructor(t,n){m(this,"migrations",{});m(this,"sortedMigrations");var o;this.types=t,this.options=n;for(const s of n.migrations??[])_t(!this.migrations[s.sequenceId],`Duplicate migration sequenceId ${s.sequenceId}`),ek(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=nL(r);for(const s of this.sortedMigrations)if((o=s.dependsOn)!=null&&o.length)for(const i of s.dependsOn){const a=r.find(c=>c.id===i);_t(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(t,n){return new N0(t,n??{})}validateRecord(t,n,r,o){try{const s=Lr(this.types,n.typeName);if(!s)throw new Error(`Missing definition for record type ${n.typeName}`);return s.validate(n,o??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:t,record:n,phase:r,recordBefore:o,error:s});throw s}}getMigrationsSince(t){const n=rL(t);if(!n.ok)return n;const r=n.value,o=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&&o.add(i);if(o.size===0)return Ha.ok([]);const s=new Set;for(const i of o){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)s.add(u.id);continue}const c=`${i}/${a}`,l=this.migrations[i].sequence.findIndex(u=>u.id===c);if(l===-1)return Ha.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(l+1))s.add(u.id)}return Ha.ok(this.sortedMigrations.filter(({id:i})=>s.has(i)))}migratePersistedRecord(t,n,r="up"){const o=this.getMigrationsSince(n);if(!o.ok)return console.error("Error migrating record",o.error),{type:"error",reason:ps.MigrationError};let s=o.value;if(s.length===0)return{type:"success",value:t};if(s.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?ps.TargetVersionTooOld:ps.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:ps.TargetVersionTooOld};s=s.slice().reverse()}t=Ye(t);try{for(const i of s){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(t):!0))continue;const c=i[r](t);c&&(t=Ye(c))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:ps.MigrationError}}return{type:"success",value:t}}migrateStoreSnapshot(t){let{store:n}=t;const r=this.getMigrationsSince(t.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:ps.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:n};n=Ye(n);try{for(const s of o)if(s.scope==="record")for(const[i,a]of Object.entries(n)){if(!(s.filter?s.filter(a):!0))continue;const l=s.up(a);l&&(n[i]=Ye(l))}else if(s.scope==="store"){const i=s.up(n);i&&(n=Ye(i))}else qo(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:ps.MigrationError}}return{type:"success",value:n}}createIntegrityChecker(t){var n,r;return((r=(n=this.options).createIntegrityChecker)==null?void 0:r.call(n,t))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:t,sequence:n})=>[t,n.length?Op(n.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:t})=>[t,0]))}}}function oL(e){if(!e.length)return null;let t="";for(const n of e)typeof n=="number"?t+=`.${n}`:n.startsWith("(")?t.endsWith(")")?t=`${t.slice(0,-1)}, ${n.slice(1)}`:t+=n:t+=`.${n}`;return t=t.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),t.startsWith(".")?t.slice(1):t}class Ce extends Error{constructor(n,r=[]){const o=oL(r),s=n.split(`
`).map((i,a)=>a===0?i:` ${i}`).join(`
`);super(r?`At ${o}: ${s}`:s);m(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function jn(e,t){try{return t()}catch(n){throw n instanceof Ce?new Ce(n.rawMessage,[e,...n.path]):new Ce(n.toString(),[e])}}function Fs(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const t=typeof e;switch(t){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${t}`;case"object":return`an ${t}`;case"undefined":return"undefined";default:qo(t)}}class Sn{constructor(t,n){this.validationFn=t,this.validateUsingKnownGoodVersionFn=n}validate(t){return this.validationFn(t)}validateUsingKnownGoodVersion(t,n){return Object.is(t,n)?t:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(t,n):this.validate(n)}isValid(t){try{return this.validate(t),!0}catch{return!1}}nullable(){return uL(this)}optional(){return nk(this)}refine(t){return new Sn(n=>t(this.validate(n)),(n,r)=>{const o=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,o)?n:t(o)})}check(t,n){return typeof t=="string"?this.refine(r=>(jn(`(check ${t})`,()=>n(r)),r)):this.refine(r=>(t(r),r))}}class sL extends Sn{constructor(t){super(n=>{const r=l1.validate(n);for(let o=0;o<r.length;o++)jn(o,()=>t.validate(r[o]));return r},(n,r)=>{if(!t.validateUsingKnownGoodVersion)return this.validate(r);const o=l1.validate(r);let s=n.length!==o.length;for(let i=0;i<o.length;i++){const a=o[i];if(i>=n.length){s=!0,jn(i,()=>t.validate(a));continue}if(Object.is(n[i],a))continue;const c=jn(i,()=>t.validateUsingKnownGoodVersion(n[i],a));Object.is(c,n[i])||(s=!0)}return s?r:n}),this.itemValidator=t}nonEmpty(){return this.check(t=>{if(t.length===0)throw new Ce("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(t=>{if(t.length<=1)throw new Ce("Expected an array with length greater than 1")})}}class Dp extends Sn{constructor(t,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Fs(r)}`);for(const[o,s]of Object.entries(t))jn(o,()=>{s.validate(Lr(r,o))});if(!n){for(const o of Object.keys(r))if(!ro(t,o))throw new Ce("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Fs(o)}`);let s=!1;for(const[i,a]of Object.entries(t)){const c=Lr(r,i),l=Lr(o,i);if(Object.is(c,l))continue;const u=jn(i,()=>{const d=a;return d.validateUsingKnownGoodVersion?d.validateUsingKnownGoodVersion(c,l):d.validate(l)});Object.is(u,c)||(s=!0)}if(!n){for(const i of Object.keys(o))if(!ro(t,i))throw new Ce("Unexpected property",[i])}for(const i of Object.keys(r))if(!ro(o,i)){s=!0;break}return s?o:r}),this.config=t,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new Dp(this.config,!0)}extend(t){return new Dp({...this.config,...t})}}class jf extends Sn{constructor(t,n,r,o){super(s=>{this.expectObject(s);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(s);return i===void 0?this.unknownValueValidation(s,a):jn(`(${t} = ${a})`,()=>i.validate(s))},(s,i)=>{this.expectObject(i),this.expectObject(s);const{matchingSchema:a,variant:c}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,c):Lr(s,t)!==Lr(i,t)?jn(`(${t} = ${c})`,()=>a.validate(i)):jn(`(${t} = ${c})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(s,i):a.validate(i))}),this.key=t,this.config=n,this.unknownValueValidation=r,this.useNumberKeys=o}expectObject(t){if(typeof t!="object"||t===null)throw new Ce(`Expected an object, got ${Fs(t)}`,[])}getMatchingSchemaAndVariant(t){const n=Lr(t,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Ce(`Expected a string for key "${this.key}", got ${Fs(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Ce(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:ro(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(t){return new jf(this.key,this.config,t,this.useNumberKeys)}}class iL extends Sn{constructor(t,n){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Fs(r)}`);for(const[o,s]of Object.entries(r))jn(o,()=>{t.validate(o),n.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Fs(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!ro(r,i)){s=!0,jn(i,()=>{t.validate(i),n.validate(a)});continue}const c=Lr(r,i),l=a;if(Object.is(c,l))continue;const u=jn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(c,l):n.validate(l));Object.is(u,c)||(s=!0)}for(const i of Object.keys(r))if(!ro(o,i)){s=!0;break}return s?o:r}),this.keyValidator=t,this.valueValidator=n}}function z0(e){return new Sn(t=>{if(typeof t!==e)throw new Ce(`Expected ${e}, got ${Fs(t)}`);return t})}const aL=new Sn(e=>e),ge=z0("string"),he=z0("number").check(e=>{if(Number.isNaN(e))throw new Ce("Expected a number, got NaN");if(!Number.isFinite(e))throw new Ce(`Expected a finite number, got ${e}`)}),Rp=he.check(e=>{if(e<0)throw new Ce(`Expected a positive number, got ${e}`)}),On=he.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive number, got ${e}`)}),tk=he.check(e=>{if(!Number.isInteger(e))throw new Ce(`Expected an integer, got ${e}`)}),mh=tk.check(e=>{if(e<0)throw new Ce(`Expected a positive integer, got ${e}`)}),cL=tk.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive integer, got ${e}`)}),we=z0("boolean");function on(e){return new Sn(t=>{if(t!==e)throw new Ce(`Expected ${e}, got ${JSON.stringify(t)}`);return e})}const l1=new Sn(e=>{if(!Array.isArray(e))throw new Ce(`Expected an array, got ${Fs(e)}`);return e});function Nt(e){return new sL(e)}function ve(e){return new Dp(e)}function OS(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===G3)}function DS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(DS):OS(e)?Object.values(e).every(DS):!1}const pn=new Sn(e=>{if(DS(e))return e;throw new Ce(`Expected json serializable value, got ${typeof e}`)},(e,t)=>{if(Array.isArray(e)&&Array.isArray(t)){let n=e.length!==t.length;for(let r=0;r<t.length;r++){if(r>=e.length){n=!0,pn.validate(t[r]);continue}const o=e[r],s=t[r];if(Object.is(o,s))continue;const i=pn.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}return n?t:e}else if(OS(e)&&OS(t)){let n=!1;for(const r of Object.keys(t)){if(!ro(e,r)){n=!0,pn.validate(t[r]);continue}const o=e[r],s=t[r];if(Object.is(o,s))continue;const i=pn.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}for(const r of Object.keys(e))if(!ro(t,r)){n=!0;break}return n?t:e}else return pn.validate(t)});function Lp(e,t){return new iL(e,t)}function B0(e,t){return new jf(e,t,(n,r)=>{throw new Ce(`Expected one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function lL(e,t){return new jf(e,t,(n,r)=>{throw new Ce(`Expected one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function Qo(e,t){return new Sn(n=>jn(e,()=>t.validate(n)),(n,r)=>jn(e,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(n,r):t.validate(r)))}function Of(e){return new Sn(t=>{if(!e.has(t)){const n=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Ce(`Expected ${n}, got ${t}`)}return t})}function nk(e){return new Sn(t=>{if(t!==void 0)return e.validate(t)},(t,n)=>{if(!(t===void 0&&n===void 0)&&n!==void 0)return e.validateUsingKnownGoodVersion&&t!==void 0?e.validateUsingKnownGoodVersion(t,n):e.validate(n)})}function uL(e){return new Sn(t=>t===null?null:e.validate(t),(t,n)=>n===null?null:e.validateUsingKnownGoodVersion&&t!==null?e.validateUsingKnownGoodVersion(t,n):e.validate(n))}function rk(...e){return Of(new Set(e))}function ok(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Ce(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Ce(`Expected a valid url, got ${JSON.stringify(e)}`)}}const dL=new Set(["http:","https:","mailto:"]),er=ge.check(e=>{if(e==="")return;const t=ok(e);if(!dL.has(t.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),hL=new Set(["http:","https:","data:"]),vc=ge.check(e=>{if(e==="")return;const t=ok(e);if(!hL.has(t.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),U0=ge.refine(e=>{try{return L3(e),e}catch{throw new Ce(`Expected an index key, got ${JSON.stringify(e)}`)}});function mr(e){return ge.refine(t=>{if(!t.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return t})}const Df=mr("asset");function H0(e,t){return ve({id:Df,typeName:on("asset"),type:on(e),props:t,meta:pn})}const pL=Qo("camera",ve({typeName:on("camera"),id:mr("camera"),x:he,y:he,z:he,meta:pn})),fL=sr("com.tldraw.camera",{AddMeta:1}),gL=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:fL.AddMeta,up:e=>{e.meta={}}}]}),hn=Zo("camera",{validator:pL,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),tu=ve({x:he,y:he,z:he.optional()}),$l=ve({x:he,y:he,w:he,h:he}),mL=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"]),sk=Of(mL),yL=ve({type:sk,rotation:he}),ik=he.check(e=>{if(e<0||e>1)throw new Ce("Opacity must be between 0 and 1")}),SL=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),vL=Of(SL),xL=new Set(["starting","paused","active","stopping"]),ak=ve({id:ge,points:Nt(tu),size:Rp,color:vL,opacity:he,state:Of(xL),delay:he,shrink:he,taper:we}),nu=mr("page"),wL=Qo("page",ve({typeName:on("page"),id:nu,name:ge,index:U0,meta:pn})),bL=sr("com.tldraw.page",{AddMeta:1}),PL=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:bL.AddMeta,up:e=>{e.meta={}}}]}),Ho=Zo("page",{validator:wL,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function bn(e){return Ho.isId(e)}mr("instance");function CL(e){const t={};for(const[r,o]of e)t[r]=nk(o);const n=Qo("instance",ve({typeName:on("instance"),id:mr("instance"),currentPageId:nu,followingUserId:ge.nullable(),brush:$l.nullable(),opacityForNextShape:ik,stylesForNextShape:ve(t),cursor:yL,scribbles:Nt(ak),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:$l,insets:Nt(we),zoomBrush:$l.nullable(),isPenMode:we,isGridMode:we,chatMessage:ge,isChatting:we,highlightedUserIds:Nt(ge),canMoveCamera:we,isFocused:we,devicePixelRatio:he,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Nt(ge),isChangingStyle:we,isReadonly:we,meta:pn,duplicateProps:ve({shapeIds:Nt(mr("shape")),offset:ve({x:he,y:he})}).nullable()}));return Zo("instance",{validator:n,scope:"session"}).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:[],canMoveCamera:!0,isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const nt=sr("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}),IL=xr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:nt.AddTransparentExportBgs,up:e=>({...e,exportBackground:!0})},{id:nt.RemoveDialog,up:({dialog:e,...t})=>t},{id:nt.AddToolLockMode,up:e=>({...e,isToolLocked:!1})},{id:nt.RemoveExtraPropsForNextShape,up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:Object.fromEntries(Object.entries(e).filter(([n])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(n)))})},{id:nt.AddLabelColor,up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:{...e,labelColor:"black"}})},{id:nt.AddFollowingUserId,up:e=>({...e,followingUserId:null})},{id:nt.RemoveAlignJustify,up:e=>{let t=e.propsForNextShape.align;return t==="justify"&&(t="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:t}}}},{id:nt.AddZoom,up:e=>({...e,zoomBrush:null})},{id:nt.AddVerticalAlign,up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}})},{id:nt.AddScribbleDelay,up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e}},{id:nt.RemoveUserId,up:({userId:e,...t})=>t},{id:nt.AddIsPenModeAndIsGridMode,up:e=>({...e,isPenMode:!1,isGridMode:!1})},{id:nt.HoistOpacity,up:({propsForNextShape:{opacity:e,...t},...n})=>({...n,opacityForNextShape:Number(e??"1"),propsForNextShape:t})},{id:nt.AddChat,up:e=>({...e,chatMessage:"",isChatting:!1})},{id:nt.AddHighlightedUserIds,up:e=>({...e,highlightedUserIds:[]})},{id:nt.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:e,...t})=>({...t,stylesForNextShape:{}})},{id:nt.AddMeta,up:e=>({...e,meta:{}})},{id:nt.RemoveCursorColor,up:e=>{const{color:t,...n}=e.cursor;return{...e,cursor:n}}},{id:nt.AddLonelyProperties,up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:nt.ReadOnlyReadonly,up:({isReadOnly:e,...t})=>({...t,isReadonly:e})},{id:nt.AddHoveringCanvas,up:e=>({...e,isHoveringCanvas:null})},{id:nt.AddScribbles,up:({scribble:e,...t})=>({...t,scribbles:[]})},{id:nt.AddInset,up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...t})=>({...t})},{id:nt.AddDuplicateProps,up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...t})=>({...t})}]}),In="instance:instance",EL=ge.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),_r=mr("shape");function _L(e,t,n){return ve({id:_r,typeName:on("shape"),x:he,y:he,rotation:he,index:U0,parentId:EL,type:on(e),isLocked:we,opacity:ik,props:t?ve(t):pn,meta:n?ve(n):pn})}const kL=Qo("instance_page_state",ve({typeName:on("instance_page_state"),id:mr("instance_page_state"),pageId:nu,selectedShapeIds:Nt(_r),hintingShapeIds:Nt(_r),erasingShapeIds:Nt(_r),hoveredShapeId:_r.nullable(),editingShapeId:_r.nullable(),croppingShapeId:_r.nullable(),focusedGroupId:_r.nullable(),meta:pn})),Gc=sr("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),TL=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Gc.AddCroppingId,up(e){e.croppingShapeId=null}},{id:Gc.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:Gc.AddMeta,up:e=>{e.meta={}}},{id:Gc.RenameProperties,up:e=>{},down:e=>{}},{id:Gc.RenamePropertiesAgain,up:e=>{e.selectedShapeIds=e.selectedIds,delete e.selectedIds,e.hintingShapeIds=e.hintingIds,delete e.hintingIds,e.erasingShapeIds=e.erasingIds,delete e.erasingIds,e.hoveredShapeId=e.hoveredId,delete e.hoveredId,e.editingShapeId=e.editingId,delete e.editingId,e.croppingShapeId=e.croppingShapeId??e.croppingId??null,delete e.croppingId,e.focusedGroupId=e.focusLayerId,delete e.focusLayerId},down:e=>{e.selectedIds=e.selectedShapeIds,delete e.selectedShapeIds,e.hintingIds=e.hintingShapeIds,delete e.hintingShapeIds,e.erasingIds=e.erasingShapeIds,delete e.erasingShapeIds,e.hoveredId=e.hoveredShapeId,delete e.hoveredShapeId,e.editingId=e.editingShapeId,delete e.editingShapeId,e.croppingId=e.croppingShapeId,delete e.croppingShapeId,e.focusLayerId=e.focusedGroupId,delete e.focusedGroupId}}]}),Zt=Zo("instance_page_state",{validator:kL,scope:"session"}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),$L=Qo("pointer",ve({typeName:on("pointer"),id:mr("pointer"),x:he,y:he,lastActivityTimestamp:he,meta:pn})),ML=sr("com.tldraw.pointer",{AddMeta:1}),AL=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:ML.AddMeta,up:e=>{e.meta={}}}]}),K0=Zo("pointer",{validator:$L,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Fp=K0.createId("pointer"),jL=Qo("instance_presence",ve({typeName:on("instance_presence"),id:mr("instance_presence"),userId:ge,userName:ge,lastActivityTimestamp:he,followingUserId:ge.nullable(),cursor:ve({x:he,y:he,type:sk,rotation:he}),color:ge,camera:ve({x:he,y:he,z:he}),screenBounds:$l,selectedShapeIds:Nt(mr("shape")),currentPageId:mr("page"),brush:$l.nullable(),scribbles:Nt(ak),chatMessage:ge,meta:pn})),Yc=sr("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),OL=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Yc.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:Yc.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:Yc.AddChatMessage,up:e=>{e.chatMessage=""}},{id:Yc.AddMeta,up:e=>{e.meta={}}},{id:Yc.RenameSelectedShapeIds,up:e=>{}}]}),DL=Zo("instance_presence",{validator:jL,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:0,followingUserId:null,color:"#FF0000",camera:{x:0,y:0,z:1},cursor:{x:0,y:0,type:"default",rotation:0},screenBounds:{x:0,y:0,w:1,h:1},selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),RL=Qo("document",ve({typeName:on("document"),id:on("document:document"),gridSize:he,name:ge,meta:pn})),u1=sr("com.tldraw.document",{AddName:1,AddMeta:2}),LL=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:u1.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:u1.AddMeta,up:e=>{e.meta={}}}]}),W0=Zo("document",{validator:RL,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),RS=W0.createId("document");function FL(e,t){return e.index<t.index?-1:e.index>t.index?1:0}function d1(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const NL=({error:e,phase:t,record:n,recordBefore:r})=>{throw j0(e,{tags:{origin:"store.validateRecord",storePhase:t,isExistingValidationIssue:t==="initialize"},extras:{recordBefore:r?d1(Ye(r)):void 0,recordAfter:d1(Ye(n))}}),e};function zL(){return[Ho.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function BL(e){const t=e.query.ids("page"),n=()=>{if(!e.has(RS))return e.put([W0.create({id:RS,name:e.props.defaultName})]),n();if(!e.has(Fp))return e.put([K0.create({id:Fp})]),n();const r=t.get();if(r.size===0)return e.put(zL()),n();const o=()=>[...r].map(c=>e.get(c)).sort(FL)[0].id,s=e.get(In);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),n()}else return e.put([e.schema.types.instance.create({id:In,currentPageId:o(),exportBackground:!0})]),n();const i=new Set,a=new Set;for(const c of r){const l=Zt.createId(c);e.has(l)||i.add(l);const u=hn.createId(c);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(c=>Zt.create({id:c,pageId:Zt.parseId(c)}))),a.size>0&&e.put([...a].map(c=>hn.create({id:c})))};return n}const UL=H0("bookmark",ve({title:ge,description:ge,image:ge,src:vc.nullable()})),HL=sr("com.tldraw.asset.bookmark",{MakeUrlsValid:1}),KL=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:HL.MakeUrlsValid,up:e=>{vc.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),WL=H0("image",ve({w:he,h:he,name:ge,isAnimated:we,mimeType:ge.nullable(),src:vc.nullable()})),sm=sr("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3}),VL=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:sm.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:sm.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:sm.MakeUrlsValid,up:e=>{vc.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),GL=H0("video",ve({w:he,h:he,name:ge,isAnimated:we,mimeType:ge.nullable(),src:vc.nullable()})),im=sr("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3}),YL=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:im.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:im.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:im.MakeUrlsValid,up:e=>{vc.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),XL=Qo("asset",B0("type",{image:WL,video:GL,bookmark:UL})),qL=sr("com.tldraw.asset",{AddMeta:1}),ZL=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:qL.AddMeta,up:e=>{e.meta={}}}]}),Si=Zo("asset",{validator:XL,scope:"document"}).withDefaultProperties(()=>({meta:{}}));let QL=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");class an{constructor(t,n,r){this.id=t,this.defaultValue=n,this.type=r}static define(t,n){const{defaultValue:r,type:o=aL}=n;return new an(t,r,o)}static defineEnum(t,n){const{defaultValue:r,values:o}=n;return new JL(t,r,o)}validate(t){return this.type.validate(t)}validateUsingKnownGoodVersion(t,n){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(t,n):this.validate(n)}}class JL extends an{constructor(t,n,r){super(t,n,rk(...r)),this.values=r}}const Sd=sr("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),e5=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:Sd.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:Sd.HoistOpacity,up:e=>{e.opacity=Number(e.props.opacity??"1"),delete e.props.opacity},down:e=>{const t=e.opacity;delete e.opacity,e.props.opacity=t<.175?"0.1":t<.375?"0.25":t<.625?"0.5":t<.875?"0.75":"1"}},{id:Sd.AddMeta,up:e=>{e.meta={}}},{id:Sd.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function $a(e){return e?e.typeName==="shape":!1}function Kn(e){return e?e.startsWith("shape:"):!1}function Be(e){return`shape:${e??QL()}`}function ck(e){const t=new Map;for(const[n,r]of Object.entries(e))if(r instanceof an){if(t.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);t.set(r,n)}return t}const gt="retired";function fo(e,t){return Mf(t,(n,r)=>`com.tldraw.shape.${e}/${r}`)}function t5(e){const t=[];for(const[n,{migrations:r}]of Object.entries(e)){const o=`com.tldraw.shape.${n}`;r?"sequenceId"in r?(_t(o===r.sequenceId,`sequenceId mismatch for ${n} shape migrations. Expected '${o}', got '${r.sequenceId}'`),t.push(r)):"sequence"in r?t.push(Tl({sequenceId:o,retroactive:!1,sequence:r.sequence.map(s=>"id"in s?{id:s.id,scope:"record",filter:i=>i.typeName==="shape"&&i.type===n,dependsOn:s.dependsOn,up:i=>{const a=s.up(i.props);a&&(i.props=a)},down:typeof s.down=="function"?i=>{const a=s.down(i.props);a&&(i.props=a)}:void 0}:s)})):t.push(Tl({sequenceId:o,retroactive:!1,sequence:Object.keys(r.migrators).map(s=>Number(s)).sort((s,i)=>s-i).map(s=>({id:`${o}/${s}`,scope:"record",filter:i=>i.typeName==="shape"&&i.type===n,up:i=>{const a=r.migrators[s].up(i);if(a)return a},down:i=>{const a=r.migrators[s].down(i);if(a)return a}}))})):t.push(Tl({sequenceId:o,retroactive:!1,sequence:[]}))}return t}function n5(e){return Zo("shape",{scope:"document",validator:Qo("shape",B0("type",Mf(e,(t,{props:n,meta:r})=>_L(t,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}const lk=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Np={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",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",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",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",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",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",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",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",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",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",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",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",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",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",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",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",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",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",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",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",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function Jo(e){return e.isDarkMode?Np.darkMode:Np.lightMode}const tr=an.defineEnum("tldraw:color",{defaultValue:"black",values:lk}),uk=an.defineEnum("tldraw:labelColor",{defaultValue:"black",values:lk}),Ti=an.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),sc=an.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern"]}),ao=an.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),dk={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},co=an.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),hk=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],zp=an.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:hk}),Bp=an.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:hk}),h1=B0("type",{binding:ve({type:on("binding"),boundShapeId:_r,normalizedAnchor:tu,isExact:we,isPrecise:we}),point:ve({type:on("point"),x:he,y:he})}),pk={labelColor:uk,color:tr,fill:sc,dash:Ti,size:co,arrowheadStart:zp,arrowheadEnd:Bp,font:ao,start:h1,end:h1,bend:he,text:ge,labelPosition:he},am=fo("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3}),fk={sequence:[{id:am.AddLabelColor,up:e=>{e.labelColor="black"},down:gt},{id:am.AddIsPrecise,up:({start:e,end:t})=>{e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5)),t.type==="binding"&&(t.isPrecise=!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5))},down:({start:e,end:t})=>{e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise),t.type==="binding"&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise)}},{id:am.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}]},gk={w:On,h:On,assetId:Df.nullable(),url:er},p1=fo("bookmark",{NullAssetId:1,MakeUrlsValid:2}),mk={sequence:[{id:p1.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:gt},{id:p1.MakeUrlsValid,up:e=>{er.isValid(e.url)||(e.url="")},down:e=>{}}]},yk=ve({type:rk("free","straight"),points:Nt(tu)}),Sk={color:tr,fill:sc,dash:Ti,size:co,segments:Nt(yk),isComplete:we,isClosed:we,isPen:we},r5=fo("draw",{AddInPen:1}),vk={sequence:[{id:r5.AddInPen,up:e=>{const{points:t}=e.segments[0];if(t.length===0){e.isPen=!1;return}let n=!(t[0].z===0||t[0].z===.5);t[1]&&(n=n&&!(t[1].z===0||t[1].z===.5)),e.isPen=n},down:gt}]};var o5={};const f1=/(^\/r\/[^/]+\/?$)/,Ne=e=>{try{return new URL(e)}catch{return}},Tu=[{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:e=>{const t=Ne(e);if(t&&t.pathname.match(f1))return e},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(f1))return e}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!e.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${e}`},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/embed\/?$/)){const n=t.searchParams.get("url");if(n)return n}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.includes("/maps/")){const t=e.match(/@(.*),(.*),(.*)z/);let n;if(t){const[,r,o,s]=t;n=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${o5.NEXT_PUBLIC_GC_API_KEY}&center=${r},${o}&zoom=${s}`}else n="";return n}},fromEmbedUrl:e=>{const t=Ne(e);if(!t)return;if(t.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&t.searchParams.has("center")&&t.searchParams.get("zoom")){const r=t.searchParams.get("zoom"),[o,s]=t.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${s},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e),n=t&&t.pathname.match(/\/v\/([^/]+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:e=>{const t=Ne(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e),n=t&&t.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:e=>{const t=Ne(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:e=>{const t=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,n=e.match(t);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:e=>{const t=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=e.match(t);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:e=>{const t=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,n=e.match(t);if(n){const[r,o]=n;return`https://scratch.mit.edu/projects/embed/${o}`}},fromEmbedUrl:e=>{const t=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=e.match(t);if(n){const[r,o]=n;return`https://scratch.mit.edu/projects/${o}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0},isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=Ne(e);if(!t)return;const n=t.hostname.replace(/^www./,"");if(n==="youtu.be")return`https://www.youtube.com/embed/${t.pathname.split("/").filter(Boolean)[0]}`;if((n==="youtube.com"||n==="m.youtube.com")&&t.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${t.searchParams.get("v")}`},fromEmbedUrl:e=>{const t=Ne(e);if(!t)return;if(t.hostname.replace(/^www./,"")==="youtube.com"){const r=t.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",toEmbedUrl:e=>{const t=Ne(e),n=t==null?void 0:t.searchParams.get("cid");if(t!=null&&t.pathname.match(/\/calendar\/u\/0/)&&n){t.pathname="/calendar/embed";const r=Array.from(t.searchParams.keys());for(const o of r)t.searchParams.delete(o);return t.searchParams.set("src",n),t.href}},fromEmbedUrl:e=>{const t=Ne(e),n=t==null?void 0:t.searchParams.get("src");if(t!=null&&t.pathname.match(/\/calendar\/embed/)&&n){t.pathname="/calendar/u/0";const r=Array.from(t.searchParams.keys());for(const o of r)t.searchParams.delete(o);return t.searchParams.set("cid",n),t.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e);if(t!=null&&t.pathname.match(/^\/presentation/)&&(t!=null&&t.pathname.match(/\/pub\/?$/))){t.pathname=t.pathname.replace(/\/pub$/,"/embed");const n=Array.from(t.searchParams.keys());for(const r of n)t.searchParams.delete(r);return t.href}},fromEmbedUrl:e=>{const t=Ne(e);if(t!=null&&t.pathname.match(/^\/presentation/)&&(t!=null&&t.pathname.match(/\/embed\/?$/))){t.pathname=t.pathname.replace(/\/embed$/,"/pub");const n=Array.from(t.searchParams.keys());for(const r of n)t.searchParams.delete(r);return t.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/)&&t.searchParams.has("embed"))return t.searchParams.delete("embed"),t.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/map\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/embed\/map\//))return t.pathname=t.pathname.replace(/^\/embed/,""),t.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/(artist|album)\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/embed\/(artist|album)\//))return t.origin+t.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=Ne(e);if(t&&t.hostname==="vimeo.com"&&t.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+t.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.hostname==="player.vimeo.com"){const n=t.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=Ne(e);if(t&&t.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.hash.match(/#room=/))return e}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}/embed${t.pathname}?cell=*`;if(t&&t.pathname.match(/^\/d\/([^/]+)\/?$/)){const n=t.pathname.replace(/^\/d/,"");return`${t.origin}/embed${n}?cell=*`}},fromEmbedUrl:e=>{const t=Ne(e);if(t&&t.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}${t.pathname.replace("/embed","")}#cell-*`;if(t&&t.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${t.origin}${t.pathname.replace("/embed","/d")}#cell-*`}}],s5={"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},xk={w:On,h:On,url:ge},vd=fo("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),wk={sequence:[{id:vd.GenOriginalUrlInEmbed,up:e=>{try{const t=e.url,n=new URL(t).host.replace("www.","");let r;for(const o of Tu)if(o.hostnames.includes(n))try{r=o.fromEmbedUrl(t)}catch(s){console.warn(s)}e.tmpOldUrl=e.url,e.url=r??""}catch{e.url="",e.tmpOldUrl=e.url}},down:gt},{id:vd.RemoveDoesResize,up:e=>{delete e.doesResize},down:gt},{id:vd.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:gt},{id:vd.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:gt}]},bk={w:On,h:On,name:ge},Pk={sequence:[]},ru=an.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Up=an.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),oo=an.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"]}),Ck={geo:oo,labelColor:uk,color:tr,fill:sc,dash:Ti,size:co,font:ao,align:ru,verticalAlign:Up,url:er,w:On,h:On,growY:Rp,text:ge},us=fo("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8}),Ik={sequence:[{id:us.AddUrlProp,up:e=>{e.url=""},down:gt},{id:us.AddLabelColor,up:e=>{e.labelColor="black"},down:gt},{id:us.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:gt},{id:us.AddCheckBox,up:e=>{},down:gt},{id:us.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:gt},{id:us.MigrateLegacyAlign,up:e=>{let t;switch(e.align){case"start":t="start-legacy";break;case"end":t="end-legacy";break;default:t="middle-legacy";break}e.align=t},down:gt},{id:us.AddCloud,up:e=>{},down:gt},{id:us.MakeUrlsValid,up:e=>{er.isValid(e.url)||(e.url="")},down:e=>{}}]},Ek={},_k={sequence:[]},kk={color:tr,size:co,segments:Nt(yk),isComplete:we,isPen:we},Tk={sequence:[]},i5=ve({topLeft:tu,bottomRight:tu}),$k={w:On,h:On,playing:we,url:er,assetId:Df.nullable(),crop:i5.nullable()},cm=fo("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3}),Mk={sequence:[{id:cm.AddUrlProp,up:e=>{e.url=""},down:gt},{id:cm.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:cm.MakeUrlsValid,up:e=>{er.isValid(e.url)||(e.url="")},down:e=>{}}]},Hp=an.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),a5=ve({id:ge,index:U0,x:he,y:he}),Ak={color:tr,dash:Ti,size:co,spline:Hp,points:Lp(ge,a5)},xd=fo("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4}),jk={sequence:[{id:xd.AddSnapHandles,up:e=>{for(const t of Object.values(e.handles))t.canSnap=!0},down:gt},{id:xd.RemoveExtraHandleProps,up:e=>{e.handles=O0(Object.values(e.handles).map(t=>[t.index,{x:t.x,y:t.y}]))},down:e=>{const t=Object.entries(e.handles).map(([n,r])=>({index:n,...r})).sort(en);e.handles=Object.fromEntries(t.map((n,r)=>{const o=r===0?"start":r===t.length-1?"end":`handle:${n.index}`;return[o,{id:o,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}},{id:xd.HandlesToPoints,up:e=>{const t=Object.entries(e.handles).map(([n,{x:r,y:o}])=>({x:r,y:o,index:n})).sort(en);e.points=t.map(({x:n,y:r})=>({x:n,y:r})),delete e.handles},down:e=>{const t=eu(e.points.length);e.handles=Object.fromEntries(e.points.map((n,r)=>[t[r],{x:n.x,y:n.y}])),delete e.points}},{id:xd.PointIndexIds,up:e=>{const t=eu(e.points.length);e.points=Object.fromEntries(e.points.map((n,r)=>{const o=t[r];return[o,{id:o,index:o,x:n.x,y:n.y}]}))},down:e=>{const t=Object.values(e.points).sort(en);e.points=t.map(({x:n,y:r})=>({x:n,y:r}))}}]},Ok={color:tr,size:co,font:ao,fontSizeAdjustment:Rp,align:ru,verticalAlign:Up,growY:Rp,url:er,text:ge},ea=fo("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6}),Dk={sequence:[{id:ea.AddUrlProp,up:e=>{e.url=""},down:gt},{id:ea.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:gt},{id:ea.MigrateLegacyAlign,up:e=>{switch(e.align){case"start":e.align="start-legacy";return;case"end":e.align="end-legacy";return;default:e.align="middle-legacy";return}},down:gt},{id:ea.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:gt},{id:ea.MakeUrlsValid,up:e=>{er.isValid(e.url)||(e.url="")},down:e=>{}},{id:ea.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}}]},Rk={color:tr,size:co,font:ao,align:ru,w:On,text:ge,scale:On,autoSize:we},c5=fo("text",{RemoveJustify:1}),Lk={sequence:[{id:c5.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:gt}]},Fk={w:On,h:On,time:he,playing:we,url:er,assetId:Df.nullable()},g1=fo("video",{AddUrlProp:1,MakeUrlsValid:2}),Nk={sequence:[{id:g1.AddUrlProp,up:e=>{e.url=""},down:gt},{id:g1.MakeUrlsValid,up:e=>{er.isValid(e.url)||(e.url="")},down:e=>{}}]},wd=sr("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),l5=Tl({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:wd.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[t,n]of An(e))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete e[t]}},{id:wd.AddInstancePresenceType,scope:"store",up(e){}},{id:wd.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[t,n]of An(e))n.typeName.match(/^(user|user_presence)$/)&&delete e[t]}},{id:wd.RemoveUserDocument,scope:"store",up:e=>{for(const[t,n]of An(e))n.typeName.match("user_document")&&delete e[t]}}]}),u5={arrow:{migrations:fk,props:pk},bookmark:{migrations:mk,props:gk},draw:{migrations:vk,props:Sk},embed:{migrations:wk,props:xk},frame:{migrations:Pk,props:bk},geo:{migrations:Ik,props:Ck},group:{migrations:_k,props:Ek},highlight:{migrations:Tk,props:kk},image:{migrations:Mk,props:$k},line:{migrations:jk,props:Ak},note:{migrations:Dk,props:Ok},text:{migrations:Lk,props:Rk},video:{migrations:Nk,props:Fk}};function d5({shapes:e=u5,migrations:t}={}){const n=new Map;for(const s of bt(e))for(const i of ck(s.props??{}).keys()){if(n.has(i.id)&&n.get(i.id)!==i)throw new Error(`Multiple StyleProp instances with the same id: ${i.id}`);n.set(i.id,i)}const r=n5(e),o=CL(n);return N0.create({asset:Si,camera:hn,document:W0,instance:o,instance_page_state:Zt,page:Ho,instance_presence:DL,pointer:K0,shape:r},{migrations:[l5,ZL,gL,LL,IL,TL,PL,OL,AL,e5,KL,VL,YL,...t5(e),...t??[]],onValidationFailure:NL,createIntegrityChecker:BL})}const ou=[{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"he",label:"עברית"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ku",label:"کوردی"},{locale:"ne",label:"नेपाली"},{locale:"hi-in",label:"हिन्दी"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"my",label:"မြန်မာစာ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function h5(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return p5(e)}function p5(e){for(const t of e){const n=f5(t);if(n)return n}return"en"}const m1={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function f5(e){const t=ou.find(o=>o.locale===e.toLowerCase());if(t)return t.locale;const[n,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=ou.find(s=>s.locale===n);if(o)return o.locale}return n in m1?m1[n]:null}var zk={exports:{}};/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/(function(e){(function(){var t={}.hasOwnProperty;function n(){for(var s="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(s=o(s,r(a)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return n.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var i="";for(var a in s)t.call(s,a)&&s[a]&&(i=o(i,a));return i}function o(s,i){return i?s?s+" "+i:s+i:s}e.exports?(n.default=n,e.exports=n):window.classNames=n})()})(zk);var g5=zk.exports;const ue=pc(g5),m5={error:null};class Bk extends x.Component{constructor(){super(...arguments);m(this,"state",m5)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,o;(o=(r=this.props).onError)==null||o.call(r,n)}render(){const{error:n}=this.state;if(n!==null){const{fallback:r}=this.props;return h.jsx(r,{error:n})}return this.props.children}}function su({children:e,fallback:t,...n}){return t===null?h.jsx(h.Fragment,{children:e}):h.jsx(Bk,{fallback:t,...n,children:e})}const Rf=Se.createContext({});function z(){return Se.useContext(Rf)}function y5(){return h.jsx("div",{className:"tl-background"})}function xc(e,t,n,r,o,s){x.useLayoutEffect(()=>{const i=e.current;if(!i||t===void 0)return;let a=`translate(${t}px, ${n}px)`;r!==void 0&&(a+=` scale(${r})`),o!==void 0&&(a+=` rotate(${o}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),i.style.transform=a})}const nn={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>--e*e*e+1,easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1- --e*e*e*e,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-8*--e*e*e*e,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1+--e*e*e*e*e,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e<=0?0:Math.pow(2,10*e-10),easeOutExpo:e=>e>=1?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>e<=0?0:e>=1?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2};class P{constructor(t=0,n=0,r=1){this.x=t,this.y=n,this.z=r}get pressure(){return this.z}set(t=this.x,n=this.y,r=this.z){return this.x=t,this.y=n,this.z=r,this}setTo({x:t=0,y:n=0,z:r=1}){return this.x=t,this.y=n,this.z=r,this}rot(t){if(t===0)return this;const{x:n,y:r}=this,o=Math.sin(t),s=Math.cos(t);return this.x=n*s-r*o,this.y=n*o+r*s,this}rotWith(t,n){if(n===0)return this;const r=this.x-t.x,o=this.y-t.y,s=Math.sin(n),i=Math.cos(n);return this.x=t.x+(r*i-o*s),this.y=t.y+(r*s+o*i),this}clone(){const{x:t,y:n,z:r}=this;return new P(t,n,r)}sub(t){return this.x-=t.x,this.y-=t.y,this}subXY(t,n){return this.x-=t,this.y-=n,this}subScalar(t){return this.x-=t,this.y-=t,this}add(t){return this.x+=t.x,this.y+=t.y,this}addXY(t,n){return this.x+=t,this.y+=n,this}addScalar(t){return this.x+=t,this.y+=t,this}clamp(t,n){return this.x=Math.max(this.x,t),this.y=Math.max(this.y,t),n!==void 0&&(this.x=Math.min(this.x,n),this.y=Math.min(this.y,n)),this}div(t){return this.x/=t,this.y/=t,this}divV(t){return this.x/=t.x,this.y/=t.y,this}mul(t){return this.x*=t,this.y*=t,this}mulV(t){return this.x*=t.x,this.y*=t.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(t,n){const r=P.Tan(t,this);return this.add(r.mul(n))}neg(){return this.x*=-1,this.y*=-1,this}cross(t){return this.x=this.y*t.z-this.z*t.y,this.y=this.z*t.x-this.x*t.z,this}dpr(t){return P.Dpr(this,t)}cpr(t){return P.Cpr(this,t)}len2(){return P.Len2(this)}len(){return P.Len(this)}pry(t){return P.Pry(this,t)}per(){const{x:t,y:n}=this;return this.x=n,this.y=-t,this}uni(){return P.Uni(this)}tan(t){return P.Tan(this,t)}dist(t){return P.Dist(this,t)}distanceToLineSegment(t,n){return P.DistanceToLineSegment(t,n,this)}slope(t){return P.Slope(this,t)}snapToGrid(t){return this.x=Math.round(this.x/t)*t,this.y=Math.round(this.y/t)*t,this}angle(t){return P.Angle(this,t)}toAngle(){return P.ToAngle(this)}lrp(t,n){return this.x=this.x+(t.x-this.x)*n,this.y=this.y+(t.y-this.y)*n,this}equals(t){return P.Equals(this,t)}equalsXY(t,n){return P.EqualsXY(this,t,n)}norm(){const t=this.len();return this.x=t===0?0:this.x/t,this.y=t===0?0:this.y/t,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(t,n){return new P(t.x+n.x,t.y+n.y)}static AddXY(t,n,r){return new P(t.x+n,t.y+r)}static Sub(t,n){return new P(t.x-n.x,t.y-n.y)}static SubXY(t,n,r){return new P(t.x-n,t.y-r)}static AddScalar(t,n){return new P(t.x+n,t.y+n)}static SubScalar(t,n){return new P(t.x-n,t.y-n)}static Div(t,n){return new P(t.x/n,t.y/n)}static Mul(t,n){return new P(t.x*n,t.y*n)}static DivV(t,n){return new P(t.x/n.x,t.y/n.y)}static MulV(t,n){return new P(t.x*n.x,t.y*n.y)}static Neg(t){return new P(-t.x,-t.y)}static Per(t){return new P(t.y,-t.x)}static Abs(t){return new P(Math.abs(t.x),Math.abs(t.y))}static Dist(t,n){return((t.y-n.y)**2+(t.x-n.x)**2)**.5}static DistMin(t,n,r){return(t.x-n.x)*(t.x-n.x)+(t.y-n.y)*(t.y-n.y)<r**2}static Dist2(t,n){return(t.x-n.x)*(t.x-n.x)+(t.y-n.y)*(t.y-n.y)}static Dpr(t,n){return t.x*n.x+t.y*n.y}static Cross(t,n){return new P(t.y*n.z-t.z*n.y,t.z*n.x-t.x*n.z)}static Cpr(t,n){return t.x*n.y-n.x*t.y}static Len2(t){return t.x*t.x+t.y*t.y}static Len(t){return(t.x*t.x+t.y*t.y)**.5}static Pry(t,n){return P.Dpr(t,n)/P.Len(n)}static Uni(t){return P.Div(t,P.Len(t))}static Tan(t,n){return P.Uni(P.Sub(t,n))}static Min(t,n){return new P(Math.min(t.x,n.x),Math.min(t.y,n.y))}static Max(t,n){return new P(Math.max(t.x,n.x),Math.max(t.y,n.y))}static From({x:t,y:n,z:r=1}){return new P(t,n,r)}static FromArray(t){return new P(t[0],t[1])}static Rot(t,n=0){const r=Math.sin(n),o=Math.cos(n);return new P(t.x*o-t.y*r,t.x*r+t.y*o)}static RotWith(t,n,r){const o=t.x-n.x,s=t.y-n.y,i=Math.sin(r),a=Math.cos(r);return new P(n.x+(o*a-s*i),n.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(t,n,r){return P.Mul(n,P.Sub(r,t).pry(n)).add(t)}static NearestPointOnLineSegment(t,n,r,o=!0){if(P.Equals(t,r)||P.Equals(n,r))return P.From(r);const s=P.Tan(n,t),i=P.Add(t,P.Mul(s,P.Sub(r,t).pry(s)));if(o){if(i.x<Math.min(t.x,n.x))return P.Cast(t.x<n.x?t:n);if(i.x>Math.max(t.x,n.x))return P.Cast(t.x>n.x?t:n);if(i.y<Math.min(t.y,n.y))return P.Cast(t.y<n.y?t:n);if(i.y>Math.max(t.y,n.y))return P.Cast(t.y>n.y?t:n)}return i}static DistanceToLineThroughPoint(t,n,r){return P.Dist(r,P.NearestPointOnLineThroughPoint(t,n,r))}static DistanceToLineSegment(t,n,r,o=!0){return P.Dist(r,P.NearestPointOnLineSegment(t,n,r,o))}static Snap(t,n=1){return new P(Math.round(t.x/n)*n,Math.round(t.y/n)*n)}static Cast(t){return t instanceof P?t:P.From(t)}static Slope(t,n){return t.x===n.y?NaN:(t.y-n.y)/(t.x-n.x)}static IsNaN(t){return isNaN(t.x)||isNaN(t.y)}static Angle(t,n){return Math.atan2(n.y-t.y,n.x-t.x)}static Lrp(t,n,r){return P.Sub(n,t).mul(r).add(t)}static Med(t,n){return new P((t.x+n.x)/2,(t.y+n.y)/2)}static Equals(t,n){return Math.abs(t.x-n.x)<1e-4&&Math.abs(t.y-n.y)<1e-4}static EqualsXY(t,n,r){return t.x===n&&t.y===r}static Clockwise(t,n,r){return(r.x-t.x)*(n.y-t.y)-(n.x-t.x)*(r.y-t.y)<0}static Rescale(t,n){const r=P.Len(t);return new P(n*t.x/r,n*t.y/r)}static ScaleWithOrigin(t,n,r){return P.Sub(t,r).mul(n).add(r)}static ToFixed(t,n=2){return new P(+t.x.toFixed(n),+t.y.toFixed(n),+t.z.toFixed(n))}static Nudge(t,n,r){return P.Add(t,P.Tan(n,t).mul(r))}static ToString(t){return`${t.x}, ${t.y}`}static ToAngle(t){let n=Math.atan2(t.y,t.x);return n<0&&(n+=Math.PI*2),n}static FromAngle(t,n=1){return new P(Math.cos(t)*n,Math.sin(t)*n)}static ToArray(t){return[t.x,t.y,t.z]}static ToJson(t){const{x:n,y:r,z:o}=t;return{x:n,y:r,z:o}}static Average(t){const n=t.length,r=new P(0,0);if(n===0)return r;for(let o=0;o<n;o++)r.add(t[o]);return r.div(n)}static Clamp(t,n,r){return r===void 0?new P(Math.min(Math.max(t.x,n)),Math.min(Math.max(t.y,n))):new P(Math.min(Math.max(t.x,n),r),Math.min(Math.max(t.y,n),r))}static PointsBetween(t,n,r=6){const o=[];for(let s=0;s<r;s++){const i=nn.easeInQuad(s/(r-1)),a=P.Lrp(t,n,i);a.z=Math.min(1,.5+Math.abs(.5-S5(i))*.65),o.push(a)}return o}static SnapToGrid(t,n=8){return new P(Math.round(t.x/n)*n,Math.round(t.y/n)*n)}}const S5=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ft(e){return`${j(e.x)},${j(e.y)} `}function Cn(e,t){return`${j((e.x+t.x)/2)},${j((e.y+t.y)/2)} `}const Pe=Math.PI,ze=Pe/2,Oe=Pe*2,v5=Math.sin;function Ns(e,t,n){return Math.max(t,typeof n<"u"?Math.min(e,n):e)}function bd(e,t=1e10){return e?Math.round(e*t)/t:0}function Ml(e,t,n=1e-6){return Math.abs(e-t)<=n}function Kp(e,t){const n=Math.pow(e-t,2)/Math.pow(e+t,2);return Pe*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function Os(e){return e=e%Oe,e<0?e=e+Oe:e===0&&(e=0),e}function $u(e,t){return e=Os(e),t=Os(t),e>t&&(t+=Oe),t-e}function Uk(e,t){return Oe-$u(e,t)}function yh(e,t){const n=(t-e)%Oe;return 2*n%Oe-n}function LS(e){return(Oe+e)%Oe}function Wp(e,t){const n=Oe/t;let r=Math.floor((LS(e)+n/2)/n)*n%Oe;return r<Pe&&(r+=Oe),r>Pe&&(r-=Oe),r}function Hk(e,t){return e===t||Ml(e%(Math.PI/2)-t%(Math.PI/2),0)}function x5(e){return e*Pe/180}function w5(e){return e*180/Pe}function $i(e,t,n){return new P(e.x,e.y).add(P.FromAngle(n,t))}function lm(e,t,n){const r=e/2,o=t/2,s=[];let i=1/0,a=-1/0,c=1/0,l=-1/0;for(let y=0;y<n;y++){const g=Oe/n,w=-ze+y*g,S=r+r*Math.cos(w),v=o+o*Math.sin(w);S<i&&(i=S),v<c&&(c=v),S>a&&(a=S),v>l&&(l=v),s.push(new P(S,v))}const u=a-i,d=l-c,p=e-u,f=t-d;if(p!==0||f!==0)for(let y=0;y<s.length;y++){const g=s[y];g.x=(g.x-i)/u*e,g.y=(g.y-c)/d*t}return s}function Xc(e,t,n,r){return e<r&&n<t}function kr(e,t,n,r){const o=Math.max(e,n),s=Math.min(t,r);return o<=s?[o,s]:null}function y1(e,t,n){return(t.x-e.x)*(n.y-e.y)-(n.x-e.x)*(t.y-e.y)}function Zn(e,t){let n=0,r,o;for(let s=0;s<t.length;s++){if(r=t[s],r.x===e.x&&r.y===e.y||(o=t[(s+1)%t.length],P.Dist(e,r)+P.Dist(e,o)===P.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&y1(r,o,e)>0&&(n+=1):o.y<=e.y&&y1(r,o,e)<0&&(n-=1)}return n!==0}function j(e){return Math.round(e*1e4)/1e4}function Vp(e){return Math.round(e*100)/100}const S1=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function vs(e,t,n){return n<0?$u(e,t):Uk(e,t)}function FS(e,t,n,r){let o;if(Math.abs(e)>Pe){o=yh(t,r);const s=yh(r,n);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=yh(t,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function b5(e,t,n,r){const o=2*((t-e)%Oe)%Oe-(t-e)%Oe;return r?(Oe-Math.abs(o))*(n?1:-1):o}const Pd=({brush:e,color:t,opacity:n,className:r})=>{const o=x.useRef(null);xc(o,e.x,e.y);const s=j(Math.max(1,e.w)),i=j(Math.max(1,e.h));return h.jsx("svg",{className:"tl-overlays__item",ref:o,children:t?h.jsxs("g",{className:"tl-brush",opacity:n,children:[h.jsx("rect",{width:s,height:i,fill:t,opacity:.75}),h.jsx("rect",{width:s,height:i,fill:"none",stroke:t,opacity:.1})]}):h.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},Io=2e3,Gp=40,Qr=320,ta=[.1,.25,.5,1,2,4,8],qc=.1,xs=8,P5=.5,C5=.1,I5=.2,E5=.005,_5=.05,k5=450,T5=200,NS=36,iu=16,$5=32,ic={};for(let e=1;e<=Math.ceil(xs);e++)ic[e+"_dark"]=`hash_pattern_zoom_${e}_dark`,ic[e+"_light"]=`hash_pattern_zoom_${e}_light`;const M5={duration:0,easing:nn.easeInOutCubic},Sh=.09,v1=[{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}],A5=6e4,Kk=3e3,j5=1200,x1={CAMERA_MOVE:-10},O5=64,Ko=8,D5=20,R5=8,L5=12,Wk=20,Vk=12,F5=["top","right","bottom","left"],N5=500,w1=.35;var um={};const z5={},Gk=zn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),$t={logPreventDefaults:zn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:zn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:zn("logElementRemoves",{defaults:{all:!1}}),debugSvg:zn("debugSvg",{defaults:{all:!1}}),showFps:zn("showFps",{defaults:{all:!1}}),throwToBlob:zn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:zn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:zn("debugCursors",{defaults:{all:!1}}),forceSrgb:zn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:zn("debugGeometry",{defaults:{all:!1}}),hideShapes:zn("hideShapes",{defaults:{all:!1}}),editOnType:zn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;Sc("element removal logging",()=>{$t.logElementRemoves.get()?Element.prototype.removeChild=function(t){return console.warn("[tldraw] removing child:",t),e.call(this,t)}:Element.prototype.removeChild=e})}function zn(e,{defaults:t,shouldStoreForSession:n=!0}){return B5({name:e,defaults:t,shouldStoreForSession:n})}function B5(e){const t=H5(e),n=e.shouldStoreForSession?U5(e.name):null,r=fn(`debug:${e.name}`,n??t);return typeof window<"u"&&(e.shouldStoreForSession&&Sc(`debug:${e.name}`,()=>{const o=r.get();o===t?Y_(`tldraw_debug:${e.name}`):L0(`tldraw_debug:${e.name}`,JSON.stringify(o))}),Object.defineProperty(window,`tldraw${e.name.replace(/^[a-z]/,o=>o.toUpperCase())}`,{get(){return r.get()},set(o){r.set(o)},configurable:!0})),Object.assign(r,e)}function U5(e){try{return JSON.parse(G_(`tldraw_debug:${e}`)??"null")}catch{return null}}function dm(e){try{return e()}catch{return null}}function H5(e){switch(dm(()=>um.TLDRAW_ENV)??dm(()=>um.VERCEL_PUBLIC_TLDRAW_ENV)??dm(()=>um.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return e.defaults.production??e.defaults.all;case"preview":case"staging":return e.defaults.staging??e.defaults.all;default:return e.defaults.development??e.defaults.all}}function Yp(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return Yp(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ee(e){e.preventDefault(),$t.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Mu(e,t){if(e.setPointerCapture(t.pointerId),$t.logPointerCaptures.get()){const n=Gk.get();n.set(e,(n.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,t)}}function Au(e,t){if(e.hasPointerCapture(t.pointerId)&&(e.releasePointerCapture(t.pointerId),$t.logPointerCaptures.get())){const n=Gk.get();n.get(e)===1?n.delete(e):n.has(e)?n.set(e,n.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,t)}}const Ut=e=>e.stopPropagation(),Yt=(e,t,n)=>{e&&e.style.setProperty(t,n)};function _n(e){return e.isKilled=!0,{point:{x:e.clientX,y:e.clientY,z:e.pressure},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,pointerId:e.pointerId,button:e.button,isPen:e.pointerType==="pen"}}function K5(){const e=z();return x.useMemo(function(){let r,o;function s(g){if(!g.isKilled){if(g.button===2){e.dispatch({type:"pointer",target:"canvas",name:"right_click",..._n(g)});return}g.button!==0&&g.button!==1&&g.button!==5||(Mu(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",..._n(g)}),e.getOpenMenus().length>0&&(e.updateInstanceState({openMenus:[]}),document.body.click(),e.getContainer().focus()))}}function i(g){g.isKilled||g.clientX===r&&g.clientY===o||(r=g.clientX,o=g.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",..._n(g)}))}function a(g){g.isKilled||g.button!==0&&g.button!==1&&g.button!==2&&g.button!==5||(r=g.clientX,o=g.clientY,Au(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",..._n(g)}))}function c(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const w=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!0:null})}function l(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const w=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!1:null})}function u(g){g.isKilled=!0,document.body.click(),Ee(g)}function d(g){g.isKilled=!0,g.target.tagName!=="A"&&g.target.tagName!=="TEXTAREA"&&!(e.getEditingShape()&&g.target.className.includes("tl-text-content"))&&Ee(g)}function p(g){Ee(g)}async function f(g){var S,v;if(Ee(g),!((v=(S=g.dataTransfer)==null?void 0:S.files)!=null&&v.length))return;const w=Array.from(g.dataTransfer.files);await e.putExternalContent({type:"files",files:w,point:e.screenToPage({x:g.clientX,y:g.clientY}),ignoreParent:!1})}function y(g){Ut(g)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:c,onPointerLeave:l,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:d,onClick:y}},[e])}function W5(){const e=z();x.useEffect(()=>{if(e.environment.isFirefox&&!e.environment.isAndroid&&!e.environment.isIos){e.updateInstanceState({isCoarsePointer:!1});return}if(window.matchMedia){const t=window.matchMedia("(pointer: coarse)"),n=()=>{e.updateInstanceState({isCoarsePointer:!!t.matches})};if(n(),t)return t.addEventListener("change",n),()=>t.removeEventListener("change",n)}},[e])}const Yk=x.createContext(null);function V5({container:e,children:t}){return h.jsx(Yk.Provider,{value:e,children:t})}function cn(){return yi(x.useContext(Yk),"useContainer used outside of <Tldraw />")}function G5(){const e=z(),t=cn(),n=K("isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=c=>{c.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},e.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[e]),x.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!Cd()&&Ee(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Ee(a);return}break}case"Tab":{if(Cd()||e.getIsMenuOpen())return;break}case",":return;case"Escape":{if((e.getEditingShape()||e.getSelectedShapeIds().length>0)&&a.preventDefault(),e.getOpenMenus().length>0)return;e.inputs.keys.has("Escape")||(e.inputs.keys.add("Escape"),e.cancel(),t.focus());return}default:if(Cd()||e.getIsMenuOpen())return}const c={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(c)},o=a=>{if(a.isKilled||(a.isKilled=!0,Cd()||e.getIsMenuOpen())||a.key===",")return;const c={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(c)};function s(a){var c,l;if(t.contains(a.target)){const u=a.touches[0].pageX,d=a.touches[0].radiusX||0;(u-d<10||u+d>e.getViewportScreenBounds().width-10)&&(((c=a.target)==null?void 0:c.tagName)==="BUTTON"&&((l=a.target)==null||l.click()),Ee(a))}}const i=a=>{t.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ee(a)};return t.addEventListener("touchstart",s,{passive:!1}),t.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ee),document.addEventListener("gesturechange",Ee),document.addEventListener("gestureend",Ee),t.addEventListener("keydown",r),t.addEventListener("keyup",o),()=>{t.removeEventListener("touchstart",s),t.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ee),document.removeEventListener("gesturechange",Ee),document.removeEventListener("gestureend",Ee),t.removeEventListener("keydown",r),t.removeEventListener("keyup",o)}},[e,t,n])}const Y5=["input","select","button","textarea"];function Cd(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||Y5.indexOf(e.tagName.toLowerCase())>-1))}const X5=["textarea","input"];function q5(e){const t=z();x.useEffect(()=>{const n=e.current;if(!n)return;const r=o=>{var s;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:i}=o;if(X5.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||t.isIn("select.editing_shape"))return;Ee(o)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[t,e])}function Z5(e,t,n){return Math.max(t,Math.min(e,n))}const zt={toVector(e,t){return e===void 0&&(e=t),Array.isArray(e)?e:[e,e]},add(e,t){return[e[0]+t[0],e[1]+t[1]]},sub(e,t){return[e[0]-t[0],e[1]-t[1]]},addTo(e,t){e[0]+=t[0],e[1]+=t[1]},subTo(e,t){e[0]-=t[0],e[1]-=t[1]}};function b1(e,t,n){return t===0||Math.abs(t)===1/0?Math.pow(e,n*5):e*t*n/(t+n*e)}function P1(e,t,n,r=.15){return r===0?Z5(e,t,n):e<t?-b1(t-e,n-t,r)+t:e>n?+b1(e-n,n-t,r)+n:e}function Q5(e,[t,n],[r,o]){const[[s,i],[a,c]]=e;return[P1(t,s,i,r),P1(n,a,c,o)]}function J5(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function e6(e){var t=J5(e,"string");return typeof t=="symbol"?t:String(t)}function qt(e,t,n){return t=e6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function at(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?C1(Object(n),!0).forEach(function(r){qt(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C1(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}const Xk={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 I1(e){return e?e[0].toUpperCase()+e.slice(1):""}const t6=["enter","leave"];function n6(e=!1,t){return e&&!t6.includes(t)}function r6(e,t="",n=!1){const r=Xk[e],o=r&&r[t]||t;return"on"+I1(e)+I1(o)+(n6(n,o)?"Capture":"")}const o6=["gotpointercapture","lostpointercapture"];function s6(e){let t=e.substring(2).toLowerCase();const n=!!~t.indexOf("passive");n&&(t=t.replace("passive",""));const r=o6.includes(t)?"capturecapture":"capture",o=!!~t.indexOf(r);return o&&(t=t.replace("capture","")),{device:t,capture:o,passive:n}}function i6(e,t=""){const n=Xk[e],r=n&&n[t]||t;return e+r}function qk(e){return"touches"in e}function a6(e){return qk(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function c6(e){return Array.from(e.touches).filter(t=>{var n,r;return t.target===e.currentTarget||((n=e.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,t.target))})}function zS(e,t){try{const n=t.clientX-e.clientX,r=t.clientY-e.clientY,o=(t.clientX+e.clientX)/2,s=(t.clientY+e.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[o,s]}}catch{}return null}function l6(e){return c6(e).map(t=>t.identifier)}function E1(e,t){const[n,r]=Array.from(e.touches).filter(o=>t.includes(o.identifier));return zS(n,r)}const _1=40,k1=800;function Zk(e){let{deltaX:t,deltaY:n,deltaMode:r}=e;return r===1?(t*=_1,n*=_1):r===2&&(t*=k1,n*=k1),[t,n]}function u6(e){const t={};if("buttons"in e&&(t.buttons=e.buttons),"shiftKey"in e){const{shiftKey:n,altKey:r,metaKey:o,ctrlKey:s}=e;Object.assign(t,{shiftKey:n,altKey:r,metaKey:o,ctrlKey:s})}return t}function Xp(e,...t){return typeof e=="function"?e(...t):e}function d6(){}function h6(...e){return e.length===0?d6:e.length===1?e[0]:function(){let t;for(const n of e)t=n.apply(this,arguments)||t;return t}}function T1(e,t){return Object.assign({},t,e||{})}const p6=32;class Qk{constructor(t,n,r){this.ctrl=t,this.args=n,this.key=r,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(t){this.ctrl.state[this.key]=t}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:t,shared:n,ingKey:r,args:o}=this;n[r]=t._active=t.active=t._blocked=t._force=!1,t._step=[!1,!1],t.intentional=!1,t._movement=[0,0],t._distance=[0,0],t._direction=[0,0],t._delta=[0,0],t._bounds=[[-1/0,1/0],[-1/0,1/0]],t.args=o,t.axis=void 0,t.memo=void 0,t.elapsedTime=t.timeDelta=0,t.direction=[0,0],t.distance=[0,0],t.overflow=[0,0],t._movementBound=[!1,!1],t.velocity=[0,0],t.movement=[0,0],t.delta=[0,0],t.timeStamp=0}start(t){const n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=t.target,n.currentTarget=t.currentTarget,n.lastOffset=r.from?Xp(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=t.timeStamp)}computeValues(t){const n=this.state;n._values=t,n.values=this.config.transform(t)}computeInitial(){const t=this.state;t._initial=t._values,t.initial=t.values}compute(t){const{state:n,config:r,shared:o}=this;n.args=this.args;let s=0;if(t&&(n.event=t,r.preventDefault&&t.cancelable&&n.event.preventDefault(),n.type=t.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,u6(t)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=t.timeStamp-n.timeStamp,n.timeStamp=t.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const I=n._delta.map(Math.abs);zt.addTo(n._distance,I)}this.axisIntent&&this.axisIntent(t);const[i,a]=n._movement,[c,l]=r.threshold,{_step:u,values:d}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=c&&d[0]),u[1]===!1&&(u[1]=Math.abs(a)>=l&&d[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=c&&Math.sign(i)*c),u[1]===!1&&(u[1]=Math.abs(a)>=l&&Math.sign(a)*l)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[I,_]=d;p[0]=u[0]!==!1?I-u[0]:0,p[1]=u[1]!==!1?_-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(p);const f=n.offset,y=n._active&&!n._blocked||n.active;y&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=o[this.ingKey]=n._active,t&&(n.first&&("bounds"in r&&(n._bounds=Xp(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[g,w]=n.offset,[[S,v],[b,E]]=n._bounds;n.overflow=[g<S?-1:g>v?1:0,w<b?-1:w>E?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const C=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=Q5(n._bounds,n.offset,C),n.delta=zt.sub(n.offset,f),this.computeMovement(),y&&(!n.last||s>p6)){n.delta=zt.sub(n.offset,f);const I=n.delta.map(Math.abs);zt.addTo(n.distance,I),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&s>0&&(n.velocity=[I[0]/s,I[1]/s],n.timeDelta=s)}}emit(){const t=this.state,n=this.shared,r=this.config;if(t._active||this.clean(),(t._blocked||!t.intentional)&&!t._force&&!r.triggerAllEvents)return;const o=this.handler(at(at(at({},n),t),{},{[this.aliasKey]:t.values}));o!==void 0&&(t.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function f6([e,t],n){const r=Math.abs(e),o=Math.abs(t);if(r>o&&r>n)return"x";if(o>r&&o>n)return"y"}class g6 extends Qk{constructor(...t){super(...t),qt(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=zt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=zt.sub(this.state.offset,this.state.lastOffset)}axisIntent(t){const n=this.state,r=this.config;if(!n.axis&&t){const o=typeof r.axisThreshold=="object"?r.axisThreshold[a6(t)]:r.axisThreshold;n.axis=f6(n._movement,o)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.axis}restrictToAxis(t){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":t[1]=0;break;case"y":t[0]=0;break}}}const m6=e=>e,$1=.15,Jk={enabled(e=!0){return e},eventOptions(e,t,n){return at(at({},n.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[$1,$1];case!1:return[0,0];default:return zt.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return zt.toVector(e)},transform(e,t,n){const r=e||n.shared.transform;return this.hasCustomTransform=!!r,r||m6},threshold(e){return zt.toVector(e,0)}},y6=0,ju=at(at({},Jk),{},{axis(e,t,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(e=y6){return e},bounds(e={}){if(typeof e=="function")return s=>ju.bounds(e(s));if("current"in e)return()=>e.current;if(typeof HTMLElement=="function"&&e instanceof HTMLElement)return e;const{left:t=-1/0,right:n=1/0,top:r=-1/0,bottom:o=1/0}=e;return[[t,n],[r,o]]}}),Ou=typeof window<"u"&&window.document&&window.document.createElement;function e2(){return Ou&&"ontouchstart"in window}function S6(){return e2()||Ou&&window.navigator.maxTouchPoints>1}function v6(){return Ou&&"onpointerdown"in window}function x6(){return Ou&&"exitPointerLock"in window.document}function w6(){try{return"constructor"in GestureEvent}catch{return!1}}const pr={isBrowser:Ou,gesture:w6(),touch:e2(),touchscreen:S6(),pointer:v6(),pointerLock:x6()},b6=250,P6=180,C6=.5,I6=50,E6=250,_6=10,M1={mouse:0,touch:0,pen:8};at(at({},ju),{},{device(e,t,{pointer:{touch:n=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&pr.pointerLock,pr.touch&&n?"touch":this.pointerLock?"mouse":pr.pointer&&!o?"pointer":pr.touch?"touch":"mouse"},preventScrollAxis(e,t,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&e?b6:void 0,!(!pr.touchscreen||n===!1))return e||(n!==void 0?"y":void 0)},pointerCapture(e,t,{pointer:{capture:n=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&n},threshold(e,t,{filterTaps:n=!1,tapsThreshold:r=3,axis:o=void 0}){const s=zt.toVector(e,n?r:o?1:0);return this.filterTaps=n,this.tapsThreshold=r,s},swipe({velocity:e=C6,distance:t=I6,duration:n=E6}={}){return{velocity:this.transform(zt.toVector(e)),distance:this.transform(zt.toVector(t)),duration:n}},delay(e=0){switch(e){case!0:return P6;case!1:return 0;default:return e}},axisThreshold(e){return e?at(at({},M1),e):M1},keyboardDisplacement(e=_6){return e}});function t2(e){const[t,n]=e.overflow,[r,o]=e._delta,[s,i]=e._direction;(t<0&&r>0&&s<0||t>0&&r<0&&s>0)&&(e._movement[0]=e._movementBound[0]),(n<0&&o>0&&i<0||n>0&&o<0&&i>0)&&(e._movement[1]=e._movementBound[1])}const k6=30,T6=100;class $6 extends Qk{constructor(...t){super(...t),qt(this,"ingKey","pinching"),qt(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const t=this.state;t._touchIds=[],t.canceled=!1,t.cancel=this.cancel.bind(this),t.turns=0}computeOffset(){const{type:t,movement:n,lastOffset:r}=this.state;t==="wheel"?this.state.offset=zt.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:t,lastOffset:n}=this.state;this.state.movement=[t[0]/n[0],t[1]-n[1]]}axisIntent(){const t=this.state,[n,r]=t._movement;if(!t.axis){const o=Math.abs(n)*k6-Math.abs(r);o<0?t.axis="angle":o>0&&(t.axis="scale")}}restrictToAxis(t){this.config.lockDirection&&(this.state.axis==="scale"?t[1]=0:this.state.axis==="angle"&&(t[0]=0))}cancel(){const t=this.state;t.canceled||setTimeout(()=>{t.canceled=!0,t._active=!1,this.compute(),this.emit()},0)}touchStart(t){this.ctrl.setEventIds(t);const n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(t),n._touchIds=Array.from(r).slice(0,2);const o=E1(t,n._touchIds);o&&this.pinchStart(t,o)}pointerStart(t){if(t.buttons!=null&&t.buttons%2!==1)return;this.ctrl.setEventIds(t),t.target.setPointerCapture(t.pointerId);const n=this.state,r=n._pointerEvents,o=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>o.has(i))||(r.size<2&&r.set(t.pointerId,t),n._pointerEvents.size<2))return;this.start(t);const s=zS(...Array.from(r.values()));s&&this.pinchStart(t,s)}pinchStart(t,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(t),this.emit()}touchMove(t){if(!this.state._active)return;const n=E1(t,this.state._touchIds);n&&this.pinchMove(t,n)}pointerMove(t){const n=this.state._pointerEvents;if(n.has(t.pointerId)&&n.set(t.pointerId,t),!this.state._active)return;const r=zS(...Array.from(n.values()));r&&this.pinchMove(t,r)}pinchMove(t,n){const r=this.state,o=r._values[1],s=n.angle-o;let i=0;Math.abs(s)>270&&(i+=Math.sign(s)),this.computeValues([n.distance,n.angle-360*i]),r.origin=n.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(t),this.emit()}touchEnd(t){this.ctrl.setEventIds(t),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(t),this.emit())}pointerEnd(t){const n=this.state;this.ctrl.setEventIds(t);try{t.target.releasePointerCapture(t.pointerId)}catch{}n._pointerEvents.has(t.pointerId)&&n._pointerEvents.delete(t.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(t),this.emit())}gestureStart(t){t.cancelable&&t.preventDefault();const n=this.state;n._active||(this.start(t),this.computeValues([t.scale,t.rotation]),n.origin=[t.clientX,t.clientY],this.compute(t),this.emit())}gestureMove(t){if(t.cancelable&&t.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([t.scale,t.rotation]),n.origin=[t.clientX,t.clientY];const r=n._movement;n._movement=[t.scale-1,t.rotation],n._delta=zt.sub(n._movement,r),this.compute(t),this.emit()}gestureEnd(t){this.state._active&&(this.state._active=!1,this.compute(t),this.emit())}wheel(t){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>t[r]):!t[n])||(this.state._active?this.wheelChange(t):this.wheelStart(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(t){this.start(t),this.wheelChange(t)}wheelChange(t){"uv"in t||t.cancelable&&t.preventDefault();const r=this.state;r._delta=[-Zk(t)[1]/T6*r.offset[0],0],zt.addTo(r._movement,r._delta),t2(r),this.state.origin=[t.clientX,t.clientY],this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){const n=this.config.device;n&&(t(n,"start",this[n+"Start"].bind(this)),t(n,"change",this[n+"Move"].bind(this)),t(n,"end",this[n+"End"].bind(this)),t(n,"cancel",this[n+"End"].bind(this)),t("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&t("wheel","",this.wheel.bind(this),{passive:!1})}}const M6=at(at({},Jk),{},{device(e,t,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!pr.touch&&pr.gesture)return"gesture";if(pr.touch&&r)return"touch";if(pr.touchscreen){if(pr.pointer)return"pointer";if(pr.touch)return"touch"}},bounds(e,t,{scaleBounds:n={},angleBounds:r={}}){const o=i=>{const a=T1(Xp(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=T1(Xp(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[o(),s()]:i=>[o(i),s(i)]},threshold(e,t,n){return this.lockDirection=n.axis==="lock",zt.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});at(at({},ju),{},{mouseOnly:(e=!0)=>e});class A6 extends g6{constructor(...t){super(...t),qt(this,"ingKey","wheeling")}wheel(t){this.state._active||this.start(t),this.wheelChange(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(t){const n=this.state;n._delta=Zk(t),zt.addTo(n._movement,n._delta),t2(n),this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){t("wheel","",this.wheel.bind(this))}}const j6=ju;at(at({},ju),{},{mouseOnly:(e=!0)=>e});const V0=new Map,BS=new Map;function O6(e){V0.set(e.key,e.engine),BS.set(e.key,e.resolver)}const D6={key:"pinch",engine:$6,resolver:M6},R6={key:"wheel",engine:A6,resolver:j6};function L6(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function F6(e,t){if(e==null)return{};var n=L6(e,t),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}const N6={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=pr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:t=!1}={}){return{passive:e,capture:t}},transform(e){return e}},z6=["target","eventOptions","window","enabled","transform"];function vh(e={},t){const n={};for(const[r,o]of Object.entries(t))switch(typeof o){case"function":n[r]=o.call(n,e[r],r,e);break;case"object":n[r]=vh(e[r],o);break;case"boolean":o&&(n[r]=e[r]);break}return n}function B6(e,t,n={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:c}=r,l=F6(r,z6);if(n.shared=vh({target:o,eventOptions:s,window:i,enabled:a,transform:c},N6),t){const u=BS.get(t);n[t]=vh(at({shared:n.shared},l),u)}else for(const u in l){const d=BS.get(u);d&&(n[u]=vh(at({shared:n.shared},l[u]),d))}return n}class n2{constructor(t,n){qt(this,"_listeners",new Set),this._ctrl=t,this._gestureKey=n}add(t,n,r,o,s){const i=this._listeners,a=i6(n,r),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},l=at(at({},c),s);t.addEventListener(a,o,l);const u=()=>{t.removeEventListener(a,o,l),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(t=>t()),this._listeners.clear()}}class U6{constructor(){qt(this,"_timeouts",new Map)}add(t,n,r=140,...o){this.remove(t),this._timeouts.set(t,window.setTimeout(n,r,...o))}remove(t){const n=this._timeouts.get(t);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(t=>void window.clearTimeout(t)),this._timeouts.clear()}}class H6{constructor(t){qt(this,"gestures",new Set),qt(this,"_targetEventStore",new n2(this)),qt(this,"gestureEventStores",{}),qt(this,"gestureTimeoutStores",{}),qt(this,"handlers",{}),qt(this,"config",{}),qt(this,"pointerIds",new Set),qt(this,"touchIds",new Set),qt(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),K6(this,t)}setEventIds(t){if(qk(t))return this.touchIds=new Set(l6(t)),this.touchIds;if("pointerId"in t)return t.type==="pointerup"||t.type==="pointercancel"?this.pointerIds.delete(t.pointerId):t.type==="pointerdown"&&this.pointerIds.add(t.pointerId),this.pointerIds}applyHandlers(t,n){this.handlers=t,this.nativeHandlers=n}applyConfig(t,n){this.config=B6(t,n,this.config)}clean(){this._targetEventStore.clean();for(const t of this.gestures)this.gestureEventStores[t].clean(),this.gestureTimeoutStores[t].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...t){const n=this.config.shared,r={};let o;if(!(n.target&&(o=n.target(),!o))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],c=A1(r,a.eventOptions,!!o);if(a.enabled){const l=V0.get(i);new l(this,t,i).bind(c)}}const s=A1(r,n.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](at(at({},this.state.shared),{},{event:a,args:t})),void 0,!0)}for(const s in r)r[s]=h6(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:c}=s6(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:c})}}}}function na(e,t){e.gestures.add(t),e.gestureEventStores[t]=new n2(e,t),e.gestureTimeoutStores[t]=new U6}function K6(e,t){t.drag&&na(e,"drag"),t.wheel&&na(e,"wheel"),t.scroll&&na(e,"scroll"),t.move&&na(e,"move"),t.pinch&&na(e,"pinch"),t.hover&&na(e,"hover")}const A1=(e,t,n)=>(r,o,s,i={},a=!1)=>{var c,l;const u=(c=i.capture)!==null&&c!==void 0?c:t.capture,d=(l=i.passive)!==null&&l!==void 0?l:t.passive;let p=a?r:r6(r,o,u);n&&d&&(p+="Passive"),e[p]=e[p]||[],e[p].push(s)},W6=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function V6(e){const t={},n={},r=new Set;for(let o in e)W6.test(o)?(r.add(RegExp.lastMatch),n[o]=e[o]):t[o]=e[o];return[n,t,r]}function ra(e,t,n,r,o,s){if(!e.has(n)||!V0.has(r))return;const i=n+"Start",a=n+"End",c=l=>{let u;return l.first&&i in t&&t[i](l),n in t&&(u=t[n](l)),l.last&&a in t&&t[a](l),u};o[r]=c,s[r]=s[r]||{}}function G6(e,t){const[n,r,o]=V6(e),s={};return ra(o,n,"onDrag","drag",s,t),ra(o,n,"onWheel","wheel",s,t),ra(o,n,"onScroll","scroll",s,t),ra(o,n,"onPinch","pinch",s,t),ra(o,n,"onMove","move",s,t),ra(o,n,"onHover","hover",s,t),{handlers:s,config:t,nativeHandlers:r}}function Y6(e,t={},n,r){const o=Se.useMemo(()=>new H6(e),[]);if(o.applyHandlers(e,r),o.applyConfig(t,n),Se.useEffect(o.effect.bind(o)),Se.useEffect(()=>o.clean.bind(o),[]),t.target===void 0)return o.bind.bind(o)}function X6(e){return e.forEach(O6),function(n,r){const{handlers:o,nativeHandlers:s,config:i}=G6(n,r||{});return Y6(o,i,void 0,s)}}const j1=10,q6=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function r2(e){let{deltaY:t,deltaX:n}=e,r=0;if(e.ctrlKey||e.altKey||e.metaKey){const o=Math.sign(e.deltaY),s=Math.abs(e.deltaY);let i=t;s>j1&&(i=j1*o),r=i/100}else e.shiftKey&&!q6&&(n=t,t=0);return{x:-n,y:-t,z:-r}}const Z6=X6([R6,D6]);let oa;const Q6=e=>oa===void 0?(oa=e,!1):e-oa>120&&e-oa<160?(oa=e,!0):(oa=e,!1);function J6(e){const t=z(),n=x.useMemo(()=>{let r="not sure";const o=({event:g})=>{if(!t.getInstanceState().isFocused||(r="not sure",Q6(Date.now())))return;const w=t.getEditingShapeId();if(w){const b=t.getShape(w);if(b&&t.getShapeUtil(b).canScroll(b)){const C=t.getShapePageBounds(w);if(C!=null&&C.containsPoint(t.inputs.currentPagePoint))return}}Ee(g),Ut(g);const S=r2(g);if(S.x===0&&S.y===0)return;const v={type:"wheel",name:"wheel",delta:S,point:new P(g.clientX,g.clientY),shiftKey:g.shiftKey,altKey:g.altKey,ctrlKey:g.metaKey||g.ctrlKey};t.dispatch(v)};let s=1,i=1,a=1,c=0;const l=new P,u=new P,d=g=>{const w=e.current;r="not sure";const{event:S,origin:v,da:b}=g;S instanceof WheelEvent||(S.target===w||w!=null&&w.contains(S.target))&&(u.x=v[0],u.y=v[1],l.x=v[0],l.y=v[1],s=b[0],i=t.getZoomLevel(),t.dispatch({type:"pinch",name:"pinch_start",point:{x:v[0],y:v[1],z:t.getZoomLevel()},delta:{x:0,y:0},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey}))},p=g=>{if(g&&(r="zooming"),r==="zooming")return;const w=Math.abs(c-s),S=P.Dist(l,u);switch(r){case"not sure":{w>24?r="zooming":S>16&&(r="panning");break}case"panning":{w>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:d,onPinchEnd:g=>{const w=e.current,{event:S,origin:v,offset:b}=g;if(S instanceof WheelEvent||!(S.target===w||w!=null&&w.contains(S.target)))return;const E=b[0];r="not sure",requestAnimationFrame(()=>{t.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:E},delta:{x:v[0],y:v[1]},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey})})},onPinch:g=>{const w=e.current,{event:S,origin:v,offset:b,da:E}=g;if(S instanceof WheelEvent||!(S.target===w||w!=null&&w.contains(S.target)))return;const C=g.type==="gesturechange"||g.type==="gestureend";c=E[0];const I=v[0]-u.x,_=v[1]-u.y;switch(u.x=v[0],u.y=v[1],p(C),r){case"zooming":{a=b[0],t.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:I,y:_},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}case"panning":{t.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:I,y:_},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}}}}},[t,e]);Z6(n,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[t.getZoomLevel(),0],scaleBounds:()=>({from:t.getZoomLevel(),max:8,min:.05})}})}function hm(e,t,n){const r=e.getShape(t),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===n)}}function eF(e,t){const n=z();return x.useMemo(()=>{const r=c=>{if(c.isKilled)return;const l=Yp(c.currentTarget);Mu(l,c);const{shape:u,handle:d}=hm(n,e,t);d&&n.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_down",..._n(c)})};let o,s;return{onPointerDown:r,onPointerMove:c=>{if(c.isKilled||c.clientX===o&&c.clientY===s)return;o=c.clientX,s=c.clientY;const{shape:l,handle:u}=hm(n,e,t);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:l,name:"pointer_move",..._n(c)})},onPointerUp:c=>{if(c.isKilled)return;const l=Yp(c.currentTarget);Au(l,c);const{shape:u,handle:d}=hm(n,e,t);d&&n.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_up",..._n(c)})}}},[n,e,t])}var o2="Expected a function",O1=NaN,tF="[object Symbol]",nF=/^\s+|\s+$/g,rF=/^[-+]0x[0-9a-f]+$/i,oF=/^0b[01]+$/i,sF=/^0o[0-7]+$/i,iF=parseInt,aF=typeof tn=="object"&&tn&&tn.Object===Object&&tn,cF=typeof self=="object"&&self&&self.Object===Object&&self,lF=aF||cF||Function("return this")(),uF=Object.prototype,dF=uF.toString,hF=Math.max,pF=Math.min,pm=function(){return lF.Date.now()};function fF(e,t,n){var r,o,s,i,a,c,l=0,u=!1,d=!1,p=!0;if(typeof e!="function")throw new TypeError(o2);t=D1(t)||0,qp(n)&&(u=!!n.leading,d="maxWait"in n,s=d?hF(D1(n.maxWait)||0,t):s,p="trailing"in n?!!n.trailing:p);function f(I){var _=r,k=o;return r=o=void 0,l=I,i=e.apply(k,_),i}function y(I){return l=I,a=setTimeout(S,t),u?f(I):i}function g(I){var _=I-c,k=I-l,$=t-_;return d?pF($,s-k):$}function w(I){var _=I-c,k=I-l;return c===void 0||_>=t||_<0||d&&k>=s}function S(){var I=pm();if(w(I))return v(I);a=setTimeout(S,g(I))}function v(I){return a=void 0,p&&r?f(I):(r=o=void 0,i)}function b(){a!==void 0&&clearTimeout(a),l=0,r=c=o=a=void 0}function E(){return a===void 0?i:v(pm())}function C(){var I=pm(),_=w(I);if(r=arguments,o=this,c=I,_){if(a===void 0)return y(c);if(d)return a=setTimeout(S,t),f(c)}return a===void 0&&(a=setTimeout(S,t)),i}return C.cancel=b,C.flush=E,C}function gF(e,t,n){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(o2);return qp(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),fF(e,t,{leading:r,maxWait:t,trailing:o})}function qp(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function mF(e){return!!e&&typeof e=="object"}function yF(e){return typeof e=="symbol"||mF(e)&&dF.call(e)==tF}function D1(e){if(typeof e=="number")return e;if(yF(e))return O1;if(qp(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=qp(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(nF,"");var n=oF.test(e);return n||sF.test(e)?iF(e.slice(2),n?2:8):rF.test(e)?O1:+e}var SF=gF;const vF=pc(SF),Je=class Je{constructor(t=0,n=0,r=0,o=0){m(this,"x",0);m(this,"y",0);m(this,"w",0);m(this,"h",0);this.x=t,this.y=n,this.w=r,this.h=o}get point(){return new P(this.x,this.y)}set point(t){this.x=t.x,this.y=t.y}get minX(){return this.x}set minX(t){this.x=t}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(t){this.y=t}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get width(){return this.w}set width(t){this.w=t}get height(){return this.h}set height(t){this.h=t}get aspectRatio(){return this.width/this.height}get center(){return new P(this.midX,this.midY)}set center(t){this.minX=t.x-this.width/2,this.minY=t.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:t}=this;return[[t[0],t[1]],[t[1],t[2]],[t[2],t[3]],[t[3],t[0]]]}get size(){return new P(this.w,this.h)}toFixed(){return this.x=bd(this.x),this.y=bd(this.y),this.w=bd(this.w),this.h=bd(this.h),this}setTo(t){return this.x=t.x,this.y=t.y,this.w=t.w,this.h=t.h,this}set(t=0,n=0,r=0,o=0){return this.x=t,this.y=n,this.w=r,this.h=o,this}expand(t){const n=Math.min(this.minX,t.minX),r=Math.min(this.minY,t.minY),o=Math.max(this.maxX,t.maxX),s=Math.max(this.maxY,t.maxY);return this.x=n,this.y=r,this.w=o-n,this.h=s-r,this}expandBy(t){return this.x-=t,this.y-=t,this.w+=t*2,this.h+=t*2,this}scale(t){return this.x/=t,this.y/=t,this.w/=t,this.h/=t,this}clone(){const{x:t,y:n,w:r,h:o}=this;return new Je(t,n,r,o)}translate(t){return this.x+=t.x,this.y+=t.y,this}snapToGrid(t){const n=Math.round(this.minX/t)*t,r=Math.round(this.minY/t)*t,o=Math.round(this.maxX/t)*t,s=Math.round(this.maxY/t)*t;this.minX=n,this.minY=r,this.width=Math.max(1,o-n),this.height=Math.max(1,s-r)}collides(t){return Je.Collides(this,t)}contains(t){return Je.Contains(this,t)}includes(t){return Je.Includes(this,t)}containsPoint(t,n=0){return Je.ContainsPoint(this,t,n)}getHandlePoint(t){switch(t){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(t,n,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:c,minY:l,maxX:u,maxY:d}=this;switch(t){case"left":case"top_left":case"bottom_left":{c+=n;break}case"right":case"top_right":case"bottom_right":{u+=n;break}}switch(t){case"top":case"top_left":case"top_right":{l+=r;break}case"bottom":case"bottom_left":case"bottom_right":{d+=r;break}}const p=(u-c)/(i-o),f=(d-l)/(a-s),y=p<0,g=f<0;if(y){const w=u;u=c,c=w}if(g){const w=d;d=l,l=w}this.minX=c,this.minY=l,this.width=Math.abs(u-c),this.height=Math.abs(d-l)}union(t){const n=Math.min(this.minX,t.x),r=Math.min(this.minY,t.y),o=Math.max(this.maxX,t.w+t.x),s=Math.max(this.maxY,t.h+t.y);return this.x=n,this.y=r,this.width=o-n,this.height=s-r,this}static From(t){return new Je(t.x,t.y,t.w,t.h)}static FromCenter(t,n){return new Je(t.x-n.x/2,t.y-n.y/2,n.x,n.y)}static FromPoints(t){if(t.length===0)return new Je;let n=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,c=t.length;a<c;a++)i=t[a],n=Math.min(i.x,n),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new Je(n,r,o-n,s-r)}static Expand(t,n){const r=Math.min(n.minX,t.minX),o=Math.min(n.minY,t.minY),s=Math.max(n.maxX,t.maxX),i=Math.max(n.maxY,t.maxY);return new Je(r,o,s-r,i-o)}static ExpandBy(t,n){return new Je(t.minX-n,t.minY-n,t.width+n*2,t.height+n*2)}static Resize(t,n,r,o,s=!1){const{minX:i,minY:a,maxX:c,maxY:l}=t;let{minX:u,minY:d,maxX:p,maxY:f}=t;switch(n){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(n){case"top":case"top_left":case"top_right":{d+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const y=(p-u)/(c-i),g=(f-d)/(l-a),w=y<0,S=g<0;if(s){const b=(c-i)/(l-a),E=Math.abs(p-u),C=Math.abs(f-d),I=E*(g<0?1:-1)*(1/b),_=C*(y<0?1:-1)*b,k=b<E/C;switch(n){case"top_left":{k?d=f+I:u=p+_;break}case"top_right":{k?d=f+I:p=u-_;break}case"bottom_right":{k?f=d-I:p=u-_;break}case"bottom_left":{k?f=d-I:u=p+_;break}case"bottom":case"top":{const $=(u+p)/2,T=C*b;u=$-T/2,p=$+T/2;break}case"left":case"right":{const $=(d+f)/2,T=E/b;d=$-T/2,f=$+T/2;break}}}if(w){const b=p;p=u,u=b}if(S){const b=f;f=d,d=b}const v=new Je(u,d,Math.abs(p-u),Math.abs(f-d));return{box:v,scaleX:+(v.width/t.width*(y>0?1:-1)).toFixed(5),scaleY:+(v.height/t.height*(g>0?1:-1)).toFixed(5)}}equals(t){return Je.Equals(this,t)}static Equals(t,n){return n.x===t.x&&n.y===t.y&&n.w===t.w&&n.h===t.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(t){return new Je(t.x,t.y,Math.max(1,t.w),Math.max(1,t.h))}};m(Je,"Collides",(t,n)=>!(t.maxX<n.minX||t.minX>n.maxX||t.maxY<n.minY||t.minY>n.maxY)),m(Je,"Contains",(t,n)=>t.minX<n.minX&&t.minY<n.minY&&t.maxY>n.maxY&&t.maxX>n.maxX),m(Je,"Includes",(t,n)=>Je.Collides(t,n)||Je.Contains(t,n)),m(Je,"ContainsPoint",(t,n,r=0)=>!(n.x<t.minX-r||n.y<t.minY-r||n.x>t.maxX+r||n.y>t.maxY+r)),m(Je,"Common",t=>{let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<t.length;i++){const a=t[i];n=Math.min(n,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new Je(n,r,o-n,s-r)}),m(Je,"Sides",(t,n=0)=>{const{corners:r}=t;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let ne=Je;function xF(e){switch(e){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 e}}function wF(e){switch(e){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 e}}function bF(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function PF(e){const t=z();x.useLayoutEffect(()=>{let n=new ne;function r(){const l=e.current;if(!l)return null;const u=l.getBoundingClientRect(),d=new ne(u.left||u.x,u.top||u.y,Math.max(u.width,1),Math.max(u.height,1));n.equals(d)||(t.updateViewportScreenBounds(d),n=d)}r();const o=vF(r,200,{trailing:!0}),s=setInterval(o,1e3);window.addEventListener("resize",o);const i=new ResizeObserver(l=>{l[0].contentRect&&o()}),a=e.current;let c=null;return a&&(i.observe(a),c=CF(a),c.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),c==null||c.removeEventListener("scroll",o)}},[t,e])}/*!
* Author: excalidraw
* MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
* https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
*/const CF=e=>{let t=e.parentElement;for(;t;){if(t===document.body)return document;const{overflowY:n}=window.getComputedStyle(t);if(t.scrollHeight>t.clientHeight&&(n==="auto"||n==="scroll"||n==="overlay"))return t;t=t.parentElement}return document},je=class je{constructor(t,n,r,o,s,i){m(this,"a",1);m(this,"b",0);m(this,"c",0);m(this,"d",1);m(this,"e",0);m(this,"f",0);this.a=t,this.b=n,this.c=r,this.d=o,this.e=s,this.f=i}equals(t){return this===t||this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(t){const n=t,{a:r,b:o,c:s,d:i,e:a,f:c}=this;return this.a=r*n.a+s*n.b,this.c=r*n.c+s*n.d,this.e=r*n.e+s*n.f+a,this.b=o*n.a+i*n.b,this.d=o*n.c+i*n.d,this.f=o*n.e+i*n.f+c,this}rotate(t,n,r){return t===0?this:n===void 0?this.multiply(je.Rotate(t)):this.translate(n,r).multiply(je.Rotate(t)).translate(-n,-r)}translate(t,n){return this.multiply(je.Translate(t,n))}scale(t,n){return this.multiply(je.Scale(t,n))}invert(){const{a:t,b:n,c:r,d:o,e:s,f:i}=this,a=t*o-n*r;return this.a=o/a,this.b=n/-a,this.c=r/-a,this.d=t/a,this.e=(o*s-r*i)/-a,this.f=(n*s-t*i)/a,this}applyToPoint(t){return je.applyToPoint(this,t)}applyToPoints(t){return je.applyToPoints(this,t)}rotation(){return je.Rotation(this)}point(){return je.Point(this)}decomposed(){return je.Decompose(this)}toCssString(){return je.toCssString(this)}setTo(t){return Object.assign(this,t),this}decompose(){return je.Decompose(this)}clone(){return new je(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new je(1,0,0,1,0,0)}static Translate(t,n){return new je(1,0,0,1,t,n)}static Rotate(t,n,r){if(t===0)return je.Identity();const o=Math.cos(t),s=Math.sin(t),i=new je(o,s,-s,o,0,0);return n===void 0?i:je.Compose(je.Translate(n,r),i,je.Translate(-n,-r))}static Multiply(t,n){return{a:t.a*n.a+t.c*n.b,c:t.a*n.c+t.c*n.d,e:t.a*n.e+t.c*n.f+t.e,b:t.b*n.a+t.d*n.b,d:t.b*n.c+t.d*n.d,f:t.b*n.e+t.d*n.f+t.f}}static Inverse(t){const n=t.a*t.d-t.b*t.c;return{a:t.d/n,b:t.b/-n,c:t.c/-n,d:t.a/n,e:(t.d*t.e-t.c*t.f)/-n,f:(t.b*t.e-t.a*t.f)/n}}static Absolute(t){const n=t.a*t.d-t.b*t.c;return{a:t.d/n,b:t.b/-n,c:t.c/-n,d:t.a/n,e:(t.d*t.e-t.c*t.f)/n,f:(t.b*t.e-t.a*t.f)/-n}}static Compose(...t){const n=je.Identity();for(let r=0,o=t.length;r<o;r++)n.multiply(t[r]);return n}static Point(t){return new P(t.e,t.f)}static Rotation(t){let n;if(t.a!==0||t.c!==0){const r=(t.a*t.a+t.c*t.c)**.5;n=Math.acos(t.a/r)*(t.c>0?-1:1)}else if(t.b!==0||t.d!==0){const r=(t.b*t.b+t.d*t.d)**.5;n=ze+Math.acos(t.b/r)*(t.d>0?-1:1)}else n=0;return LS(n)}static Decompose(t){let n,r,o;if(t.a!==0||t.c!==0){const s=(t.a*t.a+t.c*t.c)**.5;n=s,r=(t.a*t.d-t.b*t.c)/s,o=Math.acos(t.a/s)*(t.c>0?-1:1)}else if(t.b!==0||t.d!==0){const s=(t.b*t.b+t.d*t.d)**.5;n=(t.a*t.d-t.b*t.c)/s,r=s,o=ze+Math.acos(t.b/s)*(t.d>0?-1:1)}else n=0,r=0,o=0;return{x:t.e,y:t.f,scaleX:n,scaleY:r,rotation:LS(o)}}static Smooth(t,n=1e10){return t.a=Math.round(t.a*n)/n,t.b=Math.round(t.b*n)/n,t.c=Math.round(t.c*n)/n,t.d=Math.round(t.d*n)/n,t.e=Math.round(t.e*n)/n,t.f=Math.round(t.f*n)/n,t}static toCssString(t){return`matrix(${j(t.a)}, ${j(t.b)}, ${j(t.c)}, ${j(t.d)}, ${j(t.e)}, ${j(t.f)})`}static applyToPoint(t,n){return new P(t.a*n.x+t.c*n.y+t.e,t.b*n.x+t.d*n.y+t.f,n.z)}static applyToXY(t,n,r){return[t.a*n+t.c*r+t.e,t.b*n+t.d*r+t.f]}static applyToPoints(t,n){return n.map(r=>new P(t.a*r.x+t.c*r.y+t.e,t.b*r.x+t.d*r.y+t.f,r.z))}static applyToBounds(t,n){return new ne(t.e+n.minX,t.f+n.minY,n.width,n.height)}static From(t){return new je(t.a,t.b,t.c,t.d,t.e,t.f)}static Cast(t){return t instanceof je?t:je.From(t)}};m(je,"Scale",(t,n,r,o)=>{const s=new je(t,0,0,n,0,0);return r===void 0?s:je.Compose(je.Translate(r,o),s,je.Translate(-r,-o))});let oe=je;function s2(e,t){return t===0?e:s2(t,e%t)}function i2(e){const t=e.toString().split(".")[1];if(!t)return 1;const n=Math.pow(10,t.length),r=parseInt(t,10);return n/s2(r,n)}class Hi{constructor(t){m(this,"isFilled",!1);m(this,"isClosed",!0);m(this,"isLabel",!1);m(this,"debugColor");m(this,"ignore");m(this,"_vertices");m(this,"_bounds");m(this,"_area");this.isFilled=t.isFilled,this.isClosed=t.isClosed,this.isLabel=t.isLabel??!1,this.debugColor=t.debugColor,this.ignore=t.ignore}hitTestPoint(t,n=0,r=!1){return this.isClosed&&(this.isFilled||r)&&Zn(t,this.vertices)?!0:P.Dist2(t,this.nearestPoint(t))<=n*n}distanceToPoint(t,n=!1){return t.dist(this.nearestPoint(t))*(this.isClosed&&(this.isFilled||n)&&Zn(t,this.vertices)?-1:1)}distanceToLineSegment(t,n){if(t.equals(n))return this.distanceToPoint(t);const{vertices:r}=this;let o,s=1/0,i,a,c;for(let l=0;l<r.length;l++)a=r[l],c=P.NearestPointOnLineSegment(t,n,a,!0),i=P.Dist2(a,c),i<s&&(s=i,o=c);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Zn(o,this.vertices)?-s:s}hitTestLineSegment(t,n,r=0){return this.distanceToLineSegment(t,n)<=r}nearestPointOnLineSegment(t,n){const{vertices:r}=this;let o,s=1/0,i,a,c;for(let l=0;l<r.length;l++)a=r[l],c=P.NearestPointOnLineSegment(t,n,a,!0),i=P.Dist2(a,c),i<s&&(s=i,o=c);if(!o)throw Error("nearest point not found");return o}isPointInBounds(t,n=0){const{bounds:r}=this;return!(t.x<r.minX-n||t.y<r.minY-n||t.x>r.maxX+n||t.y>r.maxY+n)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return ne.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:t}=this;let n=0;for(let r=0,o=t.length;r<o;r++){const s=t[r],i=t[(r+1)%o];n+=s.x*i.y-i.x*s.y}return n/2}toSimpleSvgPath(){let t="";const{vertices:n}=this,r=n.length;if(r===0)return t;t+=`M${n[0].x},${n[0].y}`;for(let o=1;o<r;o++)t+=`L${n[o].x},${n[o].y}`;return this.isClosed&&(t+="Z"),t}}class Br extends Hi{constructor(n){super({...n,isClosed:!0,isFilled:!1});m(this,"children",[]);m(this,"ignoredChildren",[]);for(const r of n.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(n=>!n.isLabel).flatMap(n=>n.vertices)}nearestPoint(n){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");let i,a;for(const c of s)i=c.nearestPoint(n),a=P.Dist2(i,n),a<r&&(r=a,o=i);if(!o)throw Error("nearest point not found");return o}distanceToPoint(n,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(n,r||s>0)))}hitTestPoint(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(n,r,o))}hitTestLineSegment(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(n,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let n="";for(const o of this.children)n+=o.toSimpleSvgPath();const r=ne.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],c=i.dist(a),l=r[(o+1)%s],u=i.dist(l),d=i.clone().lrp(a,4/c),p=i,f=i.clone().lrp(l,4/u);n+=`M${d.x},${d.y} L${p.x},${p.y} L${f.x},${f.y} `}return n}}function IF(e=!0){const[t,n]=x.useState(0),r=z();x.useEffect(()=>{if(!e)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const EF=or(function({showStroke:t=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const o=z();IF(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return h.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(c=>{const l=o.getShape(c.id);if(l.type==="group")return null;const u=o.getShapeGeometry(l),d=o.getShapePageTransform(l),p=o.getPointInShapeSpace(l,a),f=u.nearestPoint(p),y=u.distanceToPoint(p,!0),g=Math.abs(y)*s,w=y<0,{vertices:S}=u;return h.jsxs("g",{transform:d.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[t&&h.jsx(a2,{geometry:u}),n&&S.map((v,b)=>h.jsx("circle",{cx:v.x,cy:v.y,r:"2",fill:`hsl(${Ap(b,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:"1"},`v${b}`)),r&&g<150&&h.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-g/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:"2"})]},c.id+"_outline")})})});function a2({geometry:e}){return e instanceof Br?h.jsx(h.Fragment,{children:[...e.children,...e.ignoredChildren].map((t,n)=>h.jsx(a2,{geometry:t},n))}):h.jsx("path",{stroke:e.debugColor??"red",strokeWidth:"2",fill:"none",opacity:"1",d:e.toSimpleSvgPath()})}var _F=200,G0="__lodash_hash_undefined__",kF=1/0,TF="[object Function]",$F="[object GeneratorFunction]",MF=/[\\^$.*+?()[\]{}|]/g,AF=/^\[object .+?Constructor\]$/,jF=typeof tn=="object"&&tn&&tn.Object===Object&&tn,OF=typeof self=="object"&&self&&self.Object===Object&&self,Y0=jF||OF||Function("return this")();function DF(e,t){var n=e?e.length:0;return!!n&&LF(e,t,0)>-1}function RF(e,t,n,r){for(var o=e.length,s=n+-1;++s<o;)if(t(e[s],s,e))return s;return-1}function LF(e,t,n){if(t!==t)return RF(e,FF,n);for(var r=n-1,o=e.length;++r<o;)if(e[r]===t)return r;return-1}function FF(e){return e!==e}function NF(e,t){return e.has(t)}function zF(e,t){return e==null?void 0:e[t]}function BF(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch{}return t}function c2(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}var UF=Array.prototype,HF=Function.prototype,l2=Object.prototype,fm=Y0["__core-js_shared__"],R1=function(){var e=/[^.]+$/.exec(fm&&fm.keys&&fm.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),u2=HF.toString,X0=l2.hasOwnProperty,KF=l2.toString,WF=RegExp("^"+u2.call(X0).replace(MF,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),VF=UF.splice,GF=q0(Y0,"Map"),gm=q0(Y0,"Set"),au=q0(Object,"create");function Mi(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function YF(){this.__data__=au?au(null):{}}function XF(e){return this.has(e)&&delete this.__data__[e]}function qF(e){var t=this.__data__;if(au){var n=t[e];return n===G0?void 0:n}return X0.call(t,e)?t[e]:void 0}function ZF(e){var t=this.__data__;return au?t[e]!==void 0:X0.call(t,e)}function QF(e,t){var n=this.__data__;return n[e]=au&&t===void 0?G0:t,this}Mi.prototype.clear=YF;Mi.prototype.delete=XF;Mi.prototype.get=qF;Mi.prototype.has=ZF;Mi.prototype.set=QF;function wc(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function JF(){this.__data__=[]}function eN(e){var t=this.__data__,n=Lf(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():VF.call(t,n,1),!0}function tN(e){var t=this.__data__,n=Lf(t,e);return n<0?void 0:t[n][1]}function nN(e){return Lf(this.__data__,e)>-1}function rN(e,t){var n=this.__data__,r=Lf(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}wc.prototype.clear=JF;wc.prototype.delete=eN;wc.prototype.get=tN;wc.prototype.has=nN;wc.prototype.set=rN;function bc(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function oN(){this.__data__={hash:new Mi,map:new(GF||wc),string:new Mi}}function sN(e){return Ff(this,e).delete(e)}function iN(e){return Ff(this,e).get(e)}function aN(e){return Ff(this,e).has(e)}function cN(e,t){return Ff(this,e).set(e,t),this}bc.prototype.clear=oN;bc.prototype.delete=sN;bc.prototype.get=iN;bc.prototype.has=aN;bc.prototype.set=cN;function Zp(e){var t=-1,n=e?e.length:0;for(this.__data__=new bc;++t<n;)this.add(e[t])}function lN(e){return this.__data__.set(e,G0),this}function uN(e){return this.__data__.has(e)}Zp.prototype.add=Zp.prototype.push=lN;Zp.prototype.has=uN;function Lf(e,t){for(var n=e.length;n--;)if(SN(e[n][0],t))return n;return-1}function dN(e){if(!d2(e)||gN(e))return!1;var t=vN(e)||BF(e)?WF:AF;return t.test(mN(e))}function hN(e,t,n){var r=-1,o=DF,s=e.length,i=!0,a=[],c=a;if(s>=_F){var l=pN(e);if(l)return c2(l);i=!1,o=NF,c=new Zp}else c=a;e:for(;++r<s;){var u=e[r],d=u;if(u=u!==0?u:0,i&&d===d){for(var p=c.length;p--;)if(c[p]===d)continue e;a.push(u)}else o(c,d,n)||(c!==a&&c.push(d),a.push(u))}return a}var pN=gm&&1/c2(new gm([,-0]))[1]==kF?function(e){return new gm(e)}:xN;function Ff(e,t){var n=e.__data__;return fN(t)?n[typeof t=="string"?"string":"hash"]:n.map}function q0(e,t){var n=zF(e,t);return dN(n)?n:void 0}function fN(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function gN(e){return!!R1&&R1 in e}function mN(e){if(e!=null){try{return u2.call(e)}catch{}try{return e+""}catch{}}return""}function yN(e){return e&&e.length?hN(e):[]}function SN(e,t){return e===t||e!==e&&t!==t}function vN(e){var t=d2(e)?KF.call(e):"";return t==TF||t==$F}function d2(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function xN(){}var wN=yN;const bN=pc(wN);function h2(e){return bN(e)}function PN(){const e=z(),t=$3("userIds",()=>h2(e.getCollaborators().map(n=>n.userId)).sort(),{isEqual:(n,r)=>{var o;return n.join(",")===((o=r.join)==null?void 0:o.call(r,","))}},[e]);return K(t)}function p2(e){const t=z();return K(`latestPresence:${e}`,()=>t.getCollaborators().find(r=>r.userId===e),[t])??null}const CN=or(function(){const t=PN();return h.jsx(h.Fragment,{children:t.map(n=>h.jsx(IN,{collaboratorId:n},n))})}),IN=or(function({collaboratorId:t}){const n=z(),r=p2(t),o=_N(r);if(!(r&&r.currentPageId===n.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:s,highlightedUserIds:i}=n.getInstanceState();if(!(s===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=n.getInstanceState();if(r.followingUserId===n.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return h.jsx(EN,{latestPresence:r})}),EN=or(function({latestPresence:t}){const n=z(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=dt(),c=n.getZoomLevel(),l=n.getViewportPageBounds(),{userId:u,chatMessage:d,brush:p,scribbles:f,selectedShapeIds:y,userName:g,cursor:w,color:S}=t,v=!(w.x<l.minX-12/c||w.y<l.minY-16/c||w.x>l.maxX-12/c||w.y>l.maxY-16/c);return h.jsxs(h.Fragment,{children:[p&&r?h.jsx(r,{className:"tl-collaborator__brush",brush:p,color:S,opacity:.1},u+"_brush"):null,v&&s?h.jsx(s,{className:"tl-collaborator__cursor",point:w,color:S,zoom:c,name:g!=="New User"?g:null,chatMessage:d},u+"_cursor"):i?h.jsx(i,{className:"tl-collaborator__cursor-hint",point:w,color:S,zoom:c,viewport:l},u+"_cursor_hint"):null,o&&f.length?h.jsx(h.Fragment,{children:f.map(b=>h.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:S,zoom:c,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&y.map(b=>h.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:S,opacity:.5},u+"_"+b))]})});function L1(e){return e>A5?"inactive":e>Kk?"idle":"active"}function _N(e){const t=x.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[n,r]=x.useState(()=>L1(Date.now()-t.current));return x.useEffect(()=>{const o=setInterval(()=>{r(L1(Date.now()-t.current))},j5);return()=>clearInterval(o)},[]),e&&(t.current=e.lastActivityTimestamp),n}const f2=x.memo(function({id:t,shape:n,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const c=z(),{ShapeErrorFallback:l}=dt(),u=x.useRef(null),d=x.useRef(null),p=x.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});js("set shape stuff",()=>{const g=c.getShape(t);if(!g)return;const w=p.current,S=c.getShapeClipPath(t)??"none";S!==w.clipPath&&(Yt(u.current,"clip-path",S),Yt(d.current,"clip-path",S),w.clipPath=S);const v=c.getShapePageTransform(t),b=oe.toCssString(v),E=c.getShapeGeometry(g).bounds;b!==w.transform&&(Yt(u.current,"transform",b),Yt(d.current,"transform",b),w.transform=b);const C=E.w%a,I=E.h%a,_=C===0?E.w:E.w+(a-C),k=I===0?E.h:E.h+(a-I);(_!==w.width||k!==w.height)&&(Yt(u.current,"width",Math.max(_,a)+"px"),Yt(u.current,"height",Math.max(k,a)+"px"),Yt(d.current,"width",Math.max(_,a)+"px"),Yt(d.current,"height",Math.max(k,a)+"px"),w.width=_,w.height=k)},[c]),js("set opacity and z-index",()=>{const g=u.current,w=d.current;Yt(g,"opacity",i),Yt(w,"opacity",i),Yt(g,"z-index",o),Yt(w,"z-index",s)},[i,o,s]),js("set display",()=>{if(!c.getShape(t))return;const S=c.getCulledShapes().has(t);S!==p.current.isCulled&&(Yt(u.current,"display",S?"none":"block"),Yt(d.current,"display",S?"none":"block"),p.current.isCulled=S)},[c]);const f=x.useCallback(g=>c.annotateError(g,{origin:"shape",willCrashApp:!1}),[c]);if(!n)return null;const y="fill"in n.props&&n.props.fill!=="none";return h.jsxs(h.Fragment,{children:[r.backgroundComponent&&h.jsx("div",{ref:d,className:"tl-shape tl-shape-background","data-shape-type":n.type,draggable:!1,children:h.jsx(su,{fallback:l,onError:f,children:h.jsx(TN,{shape:n,util:r})})}),h.jsx("div",{ref:u,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":y,draggable:!1,children:h.jsx(su,{fallback:l,onError:f,children:h.jsx(kN,{shape:n,util:r})})})]})}),kN=x.memo(function({shape:t,util:n}){return $f("InnerShape:"+t.type,()=>n.component(t))},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta),TN=x.memo(function({shape:t,util:n}){return $f("InnerShape:"+t.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,t)})},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta);function $N({className:e}){const t=z(),{Background:n,SvgDefs:r}=dt(),o=x.useRef(null),s=x.useRef(null),i=x.useRef(null),a=cn();PF(o),G5(),W5(),J6(o),q5(o);const c=x.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});js("position layers",function(){const{x:S,y:v,z:b}=t.getCamera();if(c.current.allowTextOutline&&t.environment.isSafari&&(a.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&b<w1!==c.current.lodDisableTextOutline){const I=b<w1;a.style.setProperty("--tl-text-outline",I?"none":`0 var(--b) 0 var(--color-background), 0 var(--a) 0 var(--color-background),
var(--b) var(--b) 0 var(--color-background), var(--a) var(--b) 0 var(--color-background),
var(--a) var(--a) 0 var(--color-background), var(--b) var(--a) 0 var(--color-background)`),c.current.lodDisableTextOutline=I}const E=b>=1?Ap(b,[1,8],[.125,.5],!0):Ap(b,[.1,1],[-2,.125],!0),C=`scale(${j(b)}) translate(${j(S+E)}px,${j(v+E)}px)`;Yt(s.current,"transform",C),Yt(i.current,"transform",C)},[t,a]);const l=K5(),u=K("shapeSvgDefs",()=>{const w=new Map;for(const S of bt(t.shapeUtils)){if(!S)return;const v=S.getCanvasSvgDefs();for(const{key:b,component:E}of v)w.has(b)||w.set(b,h.jsx(E,{},b))}return[...w.values()]},[t]),d=K("debug_shapes",()=>$t.hideShapes.get(),[$t]),p=K("debug_svg",()=>$t.debugSvg.get(),[$t]),f=K("debug_geometry",()=>$t.debugGeometry.get(),[$t]),y=K("isEditingAnything",()=>t.getEditingShapeId()!==null,[t]),g=K("isSelectingAnything",()=>!!t.getSelectedShapeIds().length,[t]);return h.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":y,"data-isselectinganything":g,className:ue("tl-canvas",e),"data-testid":"canvas",...l,children:[h.jsx("svg",{className:"tl-svg-context",children:h.jsxs("defs",{children:[u,h.jsx(KN,{}),h.jsx(WN,{}),r&&h.jsx(r,{})]})}),n&&h.jsx("div",{className:"tl-background__wrapper",children:h.jsx(n,{})}),h.jsx(MN,{}),h.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[h.jsx(XN,{}),h.jsx(YN,{}),d?null:p?h.jsx(NN,{}):h.jsx(BN,{})]}),h.jsxs("div",{className:"tl-overlays",children:[h.jsxs("div",{ref:i,className:"tl-html-layer",children:[f?h.jsx(EF,{}):null,h.jsx(RN,{}),h.jsx(jN,{}),h.jsx(AN,{}),h.jsx(ON,{}),h.jsx(UN,{}),h.jsx(HN,{}),h.jsx(DN,{}),h.jsx(GN,{}),h.jsx(CN,{})]}),h.jsx(qN,{})]}),h.jsx(ZN,{})]})}function MN(){const e=z(),t=K("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:n,y:r,z:o}=K("camera",()=>e.getCamera(),[e]),s=K("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=dt();return i&&s?h.jsx(i,{x:n,y:r,z:o,size:t}):null}function AN(){const e=z(),t=K("scribbles",()=>e.getInstanceState().scribbles,[e]),n=K("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=dt();return r&&t.length?h.jsx(h.Fragment,{children:t.map(o=>h.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:n},o.id))}):null}function jN(){const e=z(),t=K("brush",()=>e.getInstanceState().brush,[e]),{Brush:n}=dt();return n&&t?h.jsx(n,{className:"tl-user-brush",brush:t}):null}function ON(){const e=z(),t=K("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:n}=dt();return n&&t?h.jsx(n,{className:"tl-user-brush tl-zoom-brush",brush:t}):null}function DN(){const e=z(),t=K("snapLines",()=>e.snaps.getIndicators(),[e]),n=K("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=dt();return r&&t.length>0?h.jsx(h.Fragment,{children:t.map(o=>h.jsx(r,{className:"tl-user-snapline",line:o,zoom:n},o.id))}):null}function RN(){const e=z(),t=K("handles shapeIdWithHandles",()=>{const{isReadonly:n,isChangingStyle:r}=e.getInstanceState();if(n||r)return!1;const o=e.getOnlySelectedShape();return!o||!e.getShapeHandles(o)?!1:o.id},[e]);return t?h.jsx(LN,{shapeId:t}):null}function LN({shapeId:e}){const t=z(),{Handles:n}=dt(),r=K("zoomLevel",()=>t.getZoomLevel(),[t]),o=K("coarse pointer",()=>t.getInstanceState().isCoarsePointer,[t]),s=K("handles transform",()=>t.getShapePageTransform(e),[t,e]),i=K("handles",()=>{const a=t.getShapeHandles(e);if(!a)return null;const c=(o?Wk:Vk)/r*2;return a.filter(l=>l.type!=="virtual"||!a.some(u=>u!==l&&u.type==="vertex"&&P.Dist(l,u)<c)).sort(l=>l.type==="vertex"?1:-1)},[t,r,o,e]);return!n||!i||!s?null:h.jsx(n,{children:h.jsx("g",{transform:oe.toCssString(s),children:i.map(a=>h.jsx(FN,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function FN({shapeId:e,handle:t,zoom:n,isCoarse:r}){const o=eF(e,t.id),{Handle:s}=dt();return s?h.jsx("g",{"aria-label":"handle",transform:`translate(${t.x}, ${t.y})`,...o,children:h.jsx(s,{shapeId:e,handle:t,zoom:n,isCoarse:r})}):null}function NN(){const e=z(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=K("dpr multiple",()=>i2(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsx(h.Fragment,{children:t.map(r=>h.jsxs(x.Fragment,{children:[h.jsx(f2,{...r,dprMultiple:n}),h.jsx(VN,{id:r.id})]},r.id+"_fragment"))})}function zN(){const e=z(),t=x.useRef(new Set);return js("reflow for culled shapes",()=>{const n=e.getCulledShapes();if(t.current.size===n.size&&[...n].every(o=>t.current.has(o)))return;t.current=n;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[e]),null}function BN(){const e=z(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=K("dpr multiple",()=>i2(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsxs(h.Fragment,{children:[t.map(r=>h.jsx(f2,{...r,dprMultiple:n},r.id+"_shape")),e.environment.isSafari&&h.jsx(zN,{})]})}function UN(){const e=z(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=x.useRef(new Set),r=K("should display selected ids",()=>{const s=n.current,i=new Set;if(e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!e.getInstanceState().isChangingStyle){const a=e.getSelectedShapeIds();for(const c of a)i.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const l=e.getHoveredShapeId();l&&i.add(l)}}}if(s.size!==i.size)return n.current=i,i;for(const a of i)if(!s.has(a))return n.current=i,i;return s},[e]),{ShapeIndicator:o}=dt();return o?h.jsx(h.Fragment,{children:t.map(({id:s})=>h.jsx(o,{shapeId:s,hidden:!r.has(s)},s+"_indicator"))}):null}function HN(){const e=z(),{ShapeIndicator:t}=dt(),n=K("hinting shape ids",()=>Mp(e.getHintingShapeIds()),[e]);return!n.length||!t?null:h.jsx(h.Fragment,{children:n.map(r=>h.jsx(t,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))})}function KN(){return h.jsxs("g",{id:"cursor",children:[h.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),h.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function WN(){return h.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function VN({id:e}){const t=z(),[n,r]=x.useState(null),o=K("is in root",()=>{const s=t.getShape(e);return(s==null?void 0:s.parentId)===t.getCurrentPageId()},[t,e]);return x.useEffect(()=>{if(!o)return;let s=null;const i=Sc("shape to svg",async()=>{const a=Math.random();s=a;const l=t.isShapeOfType(e,"frame")?0:10;let u=t.getShapePageBounds(e);if(!u)return;u=u.clone().expandBy(l);const d=await t.getSvgString([e],{padding:l,background:t.getInstanceState().exportBackground});if(s!==a||!d)return;const p=`data:image/svg+xml;utf8,${encodeURIComponent(d.svg)}`;r({src:p,bounds:u})});return()=>{s=null,i()}},[t,e,o]),!o||!n?null:h.jsx("img",{src:n.src,width:n.bounds.width,height:n.bounds.height,style:{position:"absolute",top:0,left:0,transform:`translate(${n.bounds.x}px, ${n.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function GN(){const e=z(),t=K("selection rotation",()=>e.getSelectionRotation(),[e]),n=K("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=dt();return!n||!r?null:h.jsx(r,{bounds:n,rotation:t})}function YN(){const e=z(),t=K("selection rotation",()=>e.getSelectionRotation(),[e]),n=K("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=dt();return!n||!r?null:h.jsx(r,{bounds:n,rotation:t})}function XN(){const{OnTheCanvas:e}=dt();return e?h.jsx(e,{}):null}function qN(){const{InFrontOfTheCanvas:e}=dt();return e?h.jsx(e,{}):null}function ZN(){const e=z(),t=K("camera state",()=>e.getCameraState(),[e]);return h.jsx("div",{className:ue("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":t==="idle"})})}function QN({className:e,zoom:t,point:n,color:r,viewport:o,opacity:s=1}){const i=x.useRef(null);return xc(i,Ns(n.x,o.minX+5/t,o.maxX-5/t),Ns(n.y,o.minY+5/t,o.maxY-5/t),1/t,P.Angle(o.center,n)),h.jsxs("svg",{ref:i,className:ue("tl-overlays__item",e),children:[h.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),h.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const F1=x.memo(function({className:t,zoom:n,point:r,color:o,name:s,chatMessage:i}){const a=x.useRef(null);return xc(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n),r?h.jsxs("div",{ref:a,className:ue("tl-overlays__item",t),children:[h.jsx("svg",{className:"tl-cursor",children:h.jsx("use",{href:"#cursor",color:o})}),i?h.jsxs(h.Fragment,{children:[s&&h.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),h.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&h.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function JN({x:e,y:t,z:n,size:r}){return h.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("defs",{children:v1.map(({min:o,mid:s,step:i},a)=>{const c=i*r*n,l=.5+e*n,u=.5+t*n,d=l>0?l%c:c+l%c,p=u>0?u%c:c+u%c,f=n<s?Ap(n,[o,s],[0,1]):1;return h.jsx("pattern",{id:`grid-${i}`,width:c,height:c,patternUnits:"userSpaceOnUse",children:h.jsx("circle",{className:"tl-grid-dot",cx:d,cy:p,r:1,opacity:f})},`grid-pattern-${a}`)})}),v1.map(({step:o},s)=>h.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${o})`},`grid-rect-${s}`))]})}function e4({handle:e,isCoarse:t,className:n,zoom:r}){const o=(t?Wk:Vk)/r;if(e.type==="clone"){const i=3/Math.max(r,.35),a=`M0,${-i} A${i},${i} 0 0,1 0,${i}`,c=F5.indexOf(e.id);return h.jsxs("g",{className:ue(`tl-handle tl-handle__${e.type}`,n),children:[h.jsx("circle",{className:"tl-handle__bg",r:o}),h.jsx("path",{className:"tl-handle__fg",d:a,transform:`rotate(${-90+90*c})`})]})}const s=(e.type==="create"&&t?3:4)/Math.max(r,.35);return h.jsxs("g",{className:ue(`tl-handle tl-handle__${e.type}`,n),children:[h.jsx("circle",{className:"tl-handle__bg",r:o}),h.jsx("circle",{className:"tl-handle__fg",r:s})]})}const t4=({children:e})=>h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e});function Z0(e,t=!0){const n=e.length;if(n<2)return"";let r=e[0],o=e[1];if(n===2)return`M${Ft(r)}L${Ft(o)}`;let s="";for(let i=2,a=n-1;i<a;i++)r=e[i],o=e[i+1],s+=Cn(r,o);return t?`M${Cn(e[0],e[1])}Q${Ft(e[1])}${Cn(e[1],e[2])}T${s}${Cn(e[n-1],e[0])}${Cn(e[0],e[1])}Z`:`M${Ft(e[0])}Q${Ft(e[1])}${Cn(e[1],e[2])}${e.length>3?"T":""}${s}L${Ft(e[n-1])}`}function N1({scribble:e,zoom:t,color:n,opacity:r,className:o}){return e.points.length?h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:Z0(e.points,!1),stroke:n??`var(--color-${e.color})`,fill:"none",strokeWidth:8/t,opacity:r??e.opacity})}):null}function g2({bounds:e,rotation:t}){const n=x.useRef(null);return xc(n,e.x,e.y,1,t),x.useLayoutEffect(()=>{const r=n.current;r&&(r.style.width=j(Math.max(1,e.width))+"px",r.style.height=j(Math.max(1,e.height))+"px")},[e.width,e.height]),h.jsx("div",{ref:n,className:"tl-selection__bg",draggable:!1})}function n4({bounds:e,rotation:t}){const n=z(),r=x.useRef(null),o=K("only selected shape",()=>n.getOnlySelectedShape(),[n]),s=o?n.getShapeUtil(o).expandSelectionOutlinePx(o):0;return xc(r,e==null?void 0:e.x,e==null?void 0:e.y,1,t,{x:-s,y:-s}),e=e.clone().expandBy(s).zeroFix(),h.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsx("rect",{className:ue("tl-selection__fg__outline"),width:j(e.width),height:j(e.height)})})}const r4=()=>h.jsx("div",{className:"tl-shape-error-boundary"}),o4=({shape:e,util:t})=>$f("Indicator: "+e.type,()=>t.indicator(e)),s4=({editor:e,id:t})=>{const n=K("shape for indicator",()=>e.store.get(t),[e,t]),{ShapeIndicatorErrorFallback:r}=dt();return!n||n.isLocked?null:h.jsx(su,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:h.jsx(o4,{shape:n,util:e.getShapeUtil(n)},n.id)})},z1=x.memo(function({shapeId:t,className:n,color:r,hidden:o,opacity:s}){const i=z(),a=x.useRef(null);return js("indicator transform",()=>{const c=a.current;if(!c)return;const l=i.getShapePageTransform(t);l&&c.style.setProperty("transform",l.toCssString())},[i,t]),x.useLayoutEffect(()=>{const c=a.current;c&&c.style.setProperty("display",o?"none":"block")},[o]),h.jsx("svg",{ref:a,className:ue("tl-overlays__item",n),children:h.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:h.jsx(s4,{editor:i,id:t})})})}),i4=()=>h.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function a4({points:e,zoom:t}){const n=2.5/t,r=e.reduce((p,f)=>Math.min(p,f.x),1/0),o=e.reduce((p,f)=>Math.max(p,f.x),-1/0),s=e.reduce((p,f)=>Math.min(p,f.y),1/0),i=e.reduce((p,f)=>Math.max(p,f.y),-1/0),a=e.some(p=>p.x===r&&p.y===s);let c,l,u,d;return a?(c=r,l=s,u=o,d=i):(c=r,l=i,u=o,d=s),h.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[h.jsx("line",{x1:c,y1:l,x2:u,y2:d}),e.map((p,f)=>h.jsx("g",{transform:`translate(${p.x},${p.y})`,children:h.jsx("path",{className:"tl-snap-point",d:`M ${-n},${-n} L ${n},${n} M ${-n},${n} L ${n},${-n}`})},f))]})}function c4({gaps:e,direction:t,zoom:n}){const r=3.5/n;let o=[-1/0,1/0],s=null;const i=t==="horizontal";for(const c of e){if(s=kr(o[0],o[1],i?c.startEdge[0].y:c.startEdge[0].x,i?c.startEdge[1].y:c.startEdge[1].x),s)o=s;else continue;if(s=kr(o[0],o[1],i?c.endEdge[0].y:c.endEdge[0].x,i?c.endEdge[1].y:c.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return h.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:c,endEdge:l},u)=>h.jsx(x.Fragment,{children:i?h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),h.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),h.jsx("line",{x1:c[0].x,y1:a,x2:l[0].x,y2:a}),h.jsx("line",{x1:(c[0].x+l[0].x)/2,y1:a-r,x2:(c[0].x+l[0].x)/2,y2:a+r})]}):h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),h.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),h.jsx("line",{x1:a,y1:c[0].y,x2:a,y2:l[0].y}),h.jsx("line",{x1:a-r,y1:(c[0].y+l[0].y)/2,x2:a+r,y2:(c[0].y+l[0].y)/2})]})},u))})}function l4({className:e,line:t,zoom:n}){return h.jsx("svg",{className:ue("tl-overlays__item",e),children:t.type==="points"?h.jsx(a4,{...t,zoom:n}):t.type==="gaps"?h.jsx(c4,{...t,zoom:n}):null})}function u4(){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"var(--color-text-1)"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"var(--color-text-1)",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const d4=()=>null;function m2(e,t){const n=x.useRef(e);return t(e,n.current)?n.current:(n.current=e,e)}function US(e){return m2(e,A3)}function Q0(e){return m2(e,U_)}const y2=x.createContext({});function h4({overrides:e={},children:t}){const n=Q0(e);return h.jsx(y2.Provider,{value:x.useMemo(()=>({Background:y5,SvgDefs:d4,Brush:Pd,ZoomBrush:Pd,ScreenshotBrush:Pd,CollaboratorBrush:Pd,Cursor:F1,CollaboratorCursor:F1,CollaboratorHint:QN,CollaboratorShapeIndicator:z1,Grid:JN,Scribble:N1,SnapIndicator:l4,Handles:t4,Handle:e4,CollaboratorScribble:N1,ErrorFallback:v2,ShapeErrorFallback:r4,ShapeIndicatorErrorFallback:i4,Spinner:u4,SelectionBackground:g2,SelectionForeground:n4,ShapeIndicator:z1,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:$N,...n}),[n]),children:t})}function dt(){return x.useContext(y2)}const J0={openWindow:(e,t)=>window.open(e,t,"noopener noreferrer"),refreshPage:()=>window.location.reload(),hardReset:async()=>{var e;return await((e=window.__tldraw__hardReset)==null?void 0:e.call(window))}};function S2(){J0.hardReset()}function p4(){J0.refreshPage()}const f4="https://github.com/tldraw/tldraw/issues/new";function g4(){}const v2=({error:e,editor:t})=>{const n=x.useRef(null),[r,o]=x.useState(!1),[s,i]=x.useState(!1),[a,c]=x.useState(!1),{Canvas:l}=dt(),u=e instanceof Error?e.message:String(e),d=e instanceof Error?e.stack:null,p=K("isDarkMode",()=>{try{if(t)return t.user.getIsDarkMode()}catch{}return null},[t]),[f,y]=x.useState(null);x.useLayoutEffect(()=>{var C;p!==null&&y(p);let b=(C=n.current)==null?void 0:C.parentElement,E=!1;for(;b;){if(b.classList.contains("tl-theme__dark")||b.classList.contains("tl-theme__light")){E=!0;break}b=b.parentElement}if(E){y(null);return}y(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),x.useEffect(()=>{if(s){const b=setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(b)}},[s]);const g=()=>{const b=document.createElement("textarea");b.value=d??u,document.body.appendChild(b),b.select(),document.execCommand("copy"),b.remove(),i(!0)},w=()=>{p4()},S=async()=>{S2()},v=new URL(f4);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
\`\`\`js
${d??u}
\`\`\`
My browser: ${navigator.userAgent}`),h.jsxs("div",{ref:n,className:ue("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[h.jsx("div",{className:"tl-error-boundary__overlay"}),t&&h.jsx(Bk,{onError:g4,fallback:()=>null,children:h.jsx(Rf.Provider,{value:t,children:h.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:l?h.jsx(l,{}):null})})}),h.jsx("div",{className:ue("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Are you sure?"}),h.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>c(!1),children:"Cancel"}),h.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Something's gone wrong."}),h.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",h.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",h.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&h.jsxs(h.Fragment,{children:["Message:",h.jsx("h4",{children:h.jsx("code",{children:u})}),"Stack trace:",h.jsxs("div",{className:"tl-error-boundary__content__error",children:[h.jsx("pre",{children:h.jsx("code",{children:d??u})}),h.jsx("button",{onClick:g,children:s?"Copied!":"Copy"})]})]}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),h.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[h.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>c(!0),children:"Reset data"}),h.jsx("button",{className:"tl-error-boundary__refresh",onClick:w,children:"Refresh Page"})]})]})]})})]})};let m4=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");function et(){return m4()}const x2="TLDRAW_USER_DATA_v3",w2=ve({id:ge,name:ge.nullable().optional(),locale:ge.nullable().optional(),color:ge.nullable().optional(),isDarkMode:we.nullable().optional(),animationSpeed:he.nullable().optional(),edgeScrollSpeed:he.nullable().optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional()}),pa={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5},ex=Math.max(...Object.values(pa));function y4(e){e.version<pa.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<pa.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<pa.MakeFieldsNullable,e.version<pa.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<pa.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version=ex}const B1=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function S4(){return B1[Math.floor(Math.random()*B1.length)]}function v4(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-color-scheme: dark)"))==null?void 0:t.matches)??!1}function x4(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:t.matches)??!1}const ai=Object.freeze({name:"New User",locale:h5(),color:S4(),isDarkMode:!1,edgeScrollSpeed:1,animationSpeed:x4()?0:1,isSnapMode:!1,isWrapMode:!1});function mm(){return{id:et()}}function b2(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return mm();const t=Ye(e);y4(t);try{return w2.validate(t.user)}catch{return mm()}}function w4(){const e=JSON.parse(D0(x2)||"null")??null;return b2(e)}const cu=fn("globalUserData",null);function b4(){R0(x2,JSON.stringify({version:ex,user:cu.get()}))}function P4(e){w2.validate(e),cu.set(e),b4(),I4()}const C4=typeof process<"u"&&!1,Wa=typeof BroadcastChannel<"u"&&!C4?new BroadcastChannel("tldraw-user-sync"):null;Wa==null||Wa.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)===C2&&(t==null?void 0:t.origin)!==P2()&&cu.set(b2(t.data))});let ym=null;function P2(){return ym===null&&(ym=et()),ym}const C2="tldraw-user-preferences-change";function I4(){Wa==null||Wa.postMessage({type:C2,origin:P2(),data:{user:I2(),version:ex}})}function I2(){let e=cu.get();return e||(e=w4(),cu.set(e)),e}function E2(e={}){return{derivePresenceState:e.derivePresenceState??(()=>V("presence",()=>null)),userPreferences:e.userPreferences??V("userPreferences",()=>I2()),setUserPreferences:e.setUserPreferences??P4}}var _2={exports:{}};(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function o(c,l,u){this.fn=c,this.context=l,this.once=u||!1}function s(c,l,u,d,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,d||c,p),y=n?n+l:l;return c._events[y]?c._events[y].fn?c._events[y]=[c._events[y],f]:c._events[y].push(f):(c._events[y]=f,c._eventsCount++),c}function i(c,l){--c._eventsCount===0?c._events=new r:delete c._events[l]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],u,d;if(this._eventsCount===0)return l;for(d in u=this._events)t.call(u,d)&&l.push(n?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(u)):l},a.prototype.listeners=function(l){var u=n?n+l:l,d=this._events[u];if(!d)return[];if(d.fn)return[d.fn];for(var p=0,f=d.length,y=new Array(f);p<f;p++)y[p]=d[p].fn;return y},a.prototype.listenerCount=function(l){var u=n?n+l:l,d=this._events[u];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,u,d,p,f,y){var g=n?n+l:l;if(!this._events[g])return!1;var w=this._events[g],S=arguments.length,v,b;if(w.fn){switch(w.once&&this.removeListener(l,w.fn,void 0,!0),S){case 1:return w.fn.call(w.context),!0;case 2:return w.fn.call(w.context,u),!0;case 3:return w.fn.call(w.context,u,d),!0;case 4:return w.fn.call(w.context,u,d,p),!0;case 5:return w.fn.call(w.context,u,d,p,f),!0;case 6:return w.fn.call(w.context,u,d,p,f,y),!0}for(b=1,v=new Array(S-1);b<S;b++)v[b-1]=arguments[b];w.fn.apply(w.context,v)}else{var E=w.length,C;for(b=0;b<E;b++)switch(w[b].once&&this.removeListener(l,w[b].fn,void 0,!0),S){case 1:w[b].fn.call(w[b].context);break;case 2:w[b].fn.call(w[b].context,u);break;case 3:w[b].fn.call(w[b].context,u,d);break;case 4:w[b].fn.call(w[b].context,u,d,p);break;default:if(!v)for(C=1,v=new Array(S-1);C<S;C++)v[C-1]=arguments[C];w[b].fn.apply(w[b].context,v)}}return!0},a.prototype.on=function(l,u,d){return s(this,l,u,d,!1)},a.prototype.once=function(l,u,d){return s(this,l,u,d,!0)},a.prototype.removeListener=function(l,u,d,p){var f=n?n+l:l;if(!this._events[f])return this;if(!u)return i(this,f),this;var y=this._events[f];if(y.fn)y.fn===u&&(!p||y.once)&&(!d||y.context===d)&&i(this,f);else{for(var g=0,w=[],S=y.length;g<S;g++)(y[g].fn!==u||p&&!y[g].once||d&&y[g].context!==d)&&w.push(y[g]);w.length?this._events[f]=w.length===1?w[0]:w:i(this,f)}return this},a.prototype.removeAllListeners=function(l){var u;return l?(u=n?n+l:l,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a})(_2);var E4=_2.exports;function zs({children:e,className:t="",...n}){return h.jsx("svg",{...n,className:ue("tl-svg-container",t),children:e})}function tx(e,t,n,r){const o=e.x-n.x,s=e.y-n.y,i=r.x-n.x,a=r.y-n.y,c=t.x-e.x,l=t.y-e.y,u=i*s-a*o,d=c*s-l*o,p=a*c-i*l;if(u===0||d===0||p===0)return null;if(p!==0){const f=u/p,y=d/p;if(0<=f&&f<=1&&0<=y&&y<=1)return P.AddXY(e,f*c,f*l)}return null}function Nf(e,t,n,r){const o=(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y),s=2*((t.x-e.x)*(e.x-n.x)+(t.y-e.y)*(e.y-n.y)),i=n.x*n.x+n.y*n.y+e.x*e.x+e.y*e.y-2*(n.x*e.x+n.y*e.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const c=Math.sqrt(a),l=(-s+c)/(2*o),u=(-s-c)/(2*o);if((l<0||l>1)&&(u<0||u>1))return null;const d=[];return 0<=l&&l<=1&&d.push(P.Lrp(e,t,l)),0<=u&&u<=1&&d.push(P.Lrp(e,t,u)),d.length===0?null:d}function _4(e,t,n){const r=[];let o;for(let s=0,i=n.length-1;s<i;s++)o=tx(e,t,n[s],n[s+1]),o&&r.push(o);return r.length===0?null:r}function nx(e,t,n){const r=[];let o;for(let s=1,i=n.length;s<i+1;s++)o=tx(e,t,n[s-1],n[s%n.length]),o&&r.push(o);return r.length===0?null:r}function k4(e,t,n,r){let o=n.x-e.x,s=n.y-e.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+t*t)/(2*i),c=Math.sqrt(t*t-a*a);return o/=i,s/=i,[new P(e.x+o*a-s*c,e.y+s*a+o*c),new P(e.x+o*a+s*c,e.y+s*a-o*c)]}function HS(e,t,n){const r=[];let o,s,i;for(let a=0,c=n.length;a<c;a++)o=n[a],s=n[(a+1)%n.length],i=Nf(o,s,e,t),i&&r.push(...i);return r.length===0?null:r}function U1(e,t,n){const r=[];let o,s,i;for(let a=1,c=n.length;a<c;a++)o=n[a-1],s=n[a],i=Nf(o,s,e,t),i&&r.push(...i);return r.length===0?null:r}function Id(e,t,n){return(n.y-e.y)*(t.x-e.x)>(t.y-e.y)*(n.x-e.x)}function rx(e,t,n,r){return Id(e,n,r)!==Id(t,n,r)&&Id(e,t,n)!==Id(e,t,r)}function H1(e,t){const n=new Map;let r,o,s,i;for(let a=0,c=e.length;a<c;a++)if(r=e[a],Zn(r,t)){const l=Sm(r);n.has(l)||n.set(l,r)}for(let a=0,c=t.length;a<c;a++)if(r=t[a],Zn(r,e)){const l=Sm(r);n.has(l)||n.set(l,r)}for(let a=0,c=e.length;a<c;a++){r=e[a],o=e[(a+1)%e.length];for(let l=0,u=t.length;l<u;l++){s=t[l],i=t[(l+1)%t.length];const d=tx(r,o,s,i);if(d!==null){const p=Sm(d);n.has(p)||n.set(p,d)}}}return n.size===0?null:T4([...n.values()])}function Sm(e){return`${e.x},${e.y}`}function T4(e){const t=P.Average(e);return e.sort((n,r)=>P.Angle(t,n)-P.Angle(t,r))}function k2(e,t){let n,r,o,s;for(let i=0,a=e.length;i<a;i++){n=e[i],r=e[(i+1)%a];for(let c=0,l=t.length;c<l;c++)if(o=t[c],s=t[(c+1)%l],rx(n,r,o,s))return!0}return!1}function $4(e,t){let n,r,o,s;for(let i=0,a=e.length;i<a;i++){n=e[i],r=e[(i+1)%a];for(let c=1,l=t.length;c<l;c++)if(o=t[c-1],s=t[c],rx(n,r,o,s))return!0}return!1}class lu extends Hi{constructor(n){super({...n,isClosed:!1,isFilled:!1});m(this,"start");m(this,"end");m(this,"d");m(this,"u");m(this,"ul");m(this,"_length");const{start:r,end:o}=n;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}get length(){return this._length?this._length:this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(n){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=P.Sub(n,r).dpr(s)/i,c=r.x+s.x*a;if(c<Math.min(r.x,o.x))return r.x<o.x?r:o;if(c>Math.max(r.x,o.x))return r.x>o.x?r:o;const l=r.y+s.y*a;return l<Math.min(r.y,o.y)?r.y<o.y?r:o:l>Math.max(r.y,o.y)?r.y>o.y?r:o:new P(c,l)}hitTestLineSegment(n,r,o=0){return rx(n,r,this.start,this.end)||this.distanceToLineSegment(n,r)<=o}}class Ki extends Hi{constructor(n){super({isClosed:!1,isFilled:!1,...n});m(this,"points");m(this,"_segments");m(this,"_length");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:n}=this;for(let r=0,o=n.length-1;r<o;r++){const s=n[r],i=n[r+1];this._segments.push(new lu({start:s,end:i}))}this.isClosed&&this._segments.push(new lu({start:n[n.length-1],end:n[0]}))}return this._segments}get length(){return this._length||(this._length=this.segments.reduce((n,r)=>n+r.length,0)),this._length}getVertices(){return this.points}nearestPoint(n){const{segments:r}=this;let o=this.points[0],s=1/0,i,a;for(let c=0;c<r.length;c++)i=r[c].nearestPoint(n),a=P.Dist2(i,n),a<s&&(o=i,s=a);if(!o)throw Error("nearest point not found");return o}hitTestLineSegment(n,r,o=0){const{segments:s}=this;for(let i=0,a=s.length;i<a;i++)if(s[i].hitTestLineSegment(n,r,o))return!0;return!1}}class wt extends Ki{constructor(t){super({...t}),this.isClosed=!0}}class Wo extends wt{constructor(n){const{x:r=0,y:o=0,width:s,height:i}=n;super({...n,points:[new P(r,o),new P(r+s,o),new P(r+s,o+i),new P(r,o+i)]});m(this,"x");m(this,"y");m(this,"w");m(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new ne(this.x,this.y,this.w,this.h)}}class Fr{constructor(t){m(this,"canSnap",()=>!0);m(this,"canScroll",()=>!1);m(this,"canBind",(t,n)=>!0);m(this,"canEdit",()=>!1);m(this,"canResize",()=>!0);m(this,"canEditInReadOnly",()=>!1);m(this,"canCrop",()=>!1);m(this,"hideResizeHandles",()=>!1);m(this,"hideRotateHandle",()=>!1);m(this,"hideSelectionBoundsBg",()=>!1);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"isAspectRatioLocked",()=>!1);m(this,"onBeforeCreate");m(this,"onBeforeUpdate");m(this,"onDragShapesOver");m(this,"onDragShapesOut");m(this,"onDropShapesOver");m(this,"onResizeStart");m(this,"onResize");m(this,"onResizeEnd");m(this,"onTranslateStart");m(this,"onTranslate");m(this,"onTranslateEnd");m(this,"onHandleDrag");m(this,"onRotateStart");m(this,"onRotate");m(this,"onRotateEnd");m(this,"onBindingChange");m(this,"onChildrenChange");m(this,"onDoubleClickHandle");m(this,"onDoubleClickEdge");m(this,"onDoubleClick");m(this,"onClick");m(this,"onEditEnd");this.editor=t}providesBackgroundForChildren(t){return!1}canReceiveNewChildrenOfType(t,n){return!1}canDropShapes(t,n){return!1}expandSelectionOutlinePx(t){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(t){return{}}getHandleSnapGeometry(t){return{}}}m(Fr,"props"),m(Fr,"migrations"),m(Fr,"type");function M4(e,t,n={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:c="dashed"}=n;let l=0,u=0,d=1,p=0,f=0;switch(c){case"dashed":{d=1,l=Math.min(t*a,e/4);break}case"dotted":{d=100,l=t/d;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=l/2,f+=l/2):s==="skip"&&(e-=l,f-=l),i==="outset"?e+=l/2:i==="skip"&&(e-=l)),u=Math.floor(e/l/(2*d)),u-=u%o,u<3&&c==="dashed"?e/t<5?(l=e,u=1,p=0):(l=e*.333,p=e*.333):(u=Math.max(u,3),l=e/u/(2*d),r?(f=l/2,p=(e-u*l)/u):p=(e-u*l)/Math.max(1,u-1)),{strokeDasharray:[l,p].join(" "),strokeDashoffset:f.toString()}}function K1({bounds:e,className:t}){const n=z(),r=K("zoom level",()=>n.getZoomLevel(),[n]);return h.jsx("g",{className:t,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=M4(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return h.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class xh extends Fr{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"canBind",()=>!1);m(this,"onChildrenChange",n=>{const r=this.editor.getSortedChildIdsForParent(n.id);if(r.length===0){this.editor.getCurrentPageState().focusedGroupId===n.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([n.id]);return}else if(r.length===1){this.editor.getCurrentPageState().focusedGroupId===n.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(r,n.parentId),this.editor.deleteShapes([n.id]);return}})}getDefaultProps(){return{}}getGeometry(n){const r=this.editor.getSortedChildIdsForParent(n.id);return r.length===0?new Wo({width:1,height:1,isFilled:!1}):new Br({children:r.map(o=>{const s=this.editor.getShape(o),i=this.editor.getShapeGeometry(o),a=this.editor.getShapeLocalTransform(s).applyToPoints(i.vertices);return i.isClosed?new wt({points:a,isFilled:!0}):new Ki({points:a})})})}component(n){const r=this.editor.getErasingShapeIds().includes(n.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(c=>c!==n.id&&this.editor.isShapeOfType(this.editor.getShape(c),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==n.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(n).bounds;return h.jsx(zs,{id:n.id,children:h.jsx(K1,{className:"tl-group",bounds:a})})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds;return h.jsx(K1,{className:"",bounds:r})}}m(xh,"type","group"),m(xh,"props",Ek),m(xh,"migrations",_k);const T2=[xh],A4=new Set(T2.map(e=>e.type));function $2(e){const t=[...T2],n=new Set;for(const r of e){if(A4.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(n.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}function W1(e,t){if(!t)return!1;switch(e.type){case"mixed":return t.type==="mixed";case"shared":return t.type==="shared"&&e.value===t.value;default:throw qo(e)}}class j4{constructor(t){m(this,"map");this.map=new Map(t)}get(t){return this.map.get(t)}getAsKnownValue(t){const n=this.get(t);if(n&&n.type!=="mixed")return n.value}get size(){return this.map.size}equals(t){if(this.size!==t.size)return!1;const n=new Set;for(const[r,o]of this){if(!W1(o,t.get(r)))return!1;n.add(r)}for(const[r,o]of t)if(!n.has(r)&&!W1(o,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 KS extends j4{set(t,n){this.map.set(t,n)}applyValue(t,n){const r=this.get(t);if(!r){this.set(t,{type:"shared",value:n});return}switch(r.type){case"mixed":return;case"shared":r.value!==n&&this.set(t,{type:"mixed"});return;default:qo(r,"type")}}}class zf{constructor(){m(this,"items",new WeakMap)}get(t,n){return this.items.has(t)||this.items.set(t,n(t)),this.items.get(t)}access(t){return this.items.get(t)}set(t,n){this.items.set(t,n)}has(t){return this.items.has(t)}invalidate(t){this.items.delete(t)}bust(){this.items=new WeakMap}}function O4(e,t,n){return fetch(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],t,{type:n})})}function D4(e,t){var o;let n=e;const r=new Set(t);for(;r.has(n);)n=(o=/^.*(\d+)$/.exec(n))!=null&&o[1]?n.replace(/(\d+)(?=\D?)$/,s=>(+s+1).toString()):`${n} 1`;return n}function Ed(e,t,n){if(n.length===0)return[];const r=new Map;for(const s of fe(n.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:fe(e.getSortedChildIdsForParent(i).map(a=>e.getShape(a))),moving:new Set}),r.get(i).moving.add(s)}const o=[];switch(t){case"toBack":{r.forEach(({moving:s,children:i})=>R4(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>L4(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>F4(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>N4(s,i,o));break}}return o}function R4(e,t,n){const r=t.length;if(e.size===r)return;let o,s;for(let i=0;i<r;i++){const a=t[i];if(e.has(a))o=a.index,e.delete(a);else{s=a.index;break}}if(e.size!==0){const i=oc(o,s,e.size);n.push(...Array.from(e.values()).sort(en).map((a,c)=>({...a,index:i[c]})))}}function L4(e,t,n){const r=t.length;if(e.size===r)return;let o,s;for(let i=r-1;i>-1;i--){const a=t[i];if(e.has(a))s=a.index,e.delete(a);else{o=a.index;break}}if(e.size!==0){const i=oc(o,s,e.size);n.push(...Array.from(e.values()).sort(en).map((a,c)=>({...a,index:i[c]})))}}function F4(e,t,n){var s;const r=t.length;if(e.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(t[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:c}=o;oc(t[i].index,(s=t[i+1])==null?void 0:s.index,i-c).forEach((l,u)=>n.push({...t[c+u],index:l})),o={name:"skipping"};break}}}}function N4(e,t,n){var s;const r=t.length;if(e.size===r)return;let o={name:"skipping"};for(let i=r-1;i>-1;i--){const a=e.has(t[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;oc((s=t[i-1])==null?void 0:s.index,t[i].index,o.selectIndex-i).forEach((c,l)=>{n.push({...t[i+l+1],index:c})}),o={name:"skipping"};break}}}}function M2({editor:e}){const t=e.getSelectedShapes(),n=e.getSelectionRotation(),r=e.getSelectionRotatedPageBounds(),{inputs:{originPagePoint:o}}=e;if(!r)return null;const s=r.center.clone().rotWith(r.point,n);return{selectionPageCenter:s,initialCursorAngle:s.angle(o),initialSelectionRotation:n,shapeSnapshots:t.map(i=>({shape:Ye(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function wh({delta:e,editor:t,snapshot:n,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=n;t.updateShapes(s.map(({shape:a,initialPagePoint:c})=>{const l=Kn(a.parentId)?t.getShapePageTransform(a.parentId):oe.Identity(),u=P.RotWith(c,o,e),d=oe.applyToPoint(oe.Inverse(l),u),p=Os(a.rotation+e);return{id:a.id,type:a.type,x:d.x,y:d.y,rotation:p}}));const i=[];s.forEach(({shape:a})=>{var d,p,f;const c=t.getShape(a.id);if(!c)return;const l=t.getShapeUtil(a);if(r==="start"||r==="one-off"){const y=(d=l.onRotateStart)==null?void 0:d.call(l,a);y&&i.push(y)}const u=(p=l.onRotate)==null?void 0:p.call(l,a,c);if(u&&i.push(u),r==="end"||r==="one-off"){const y=(f=l.onRotateEnd)==null?void 0:f.call(l,a,c);y&&i.push(y)}}),i.length>0&&t.updateShapes(i)}const z4=e=>{const{store:t}=e,n=t.query.filterHistory("shape"),r=t.query.records("shape",()=>({type:{eq:"arrow"}}));function o(){const s=r.get(),i={};for(const a of s){const{start:c,end:l}=a.props;if(c.type==="binding"){const u=i[c.boundShapeId];u?u.push({arrowId:a.id,handleId:"start"}):i[c.boundShapeId]=[{arrowId:a.id,handleId:"start"}]}if(l.type==="binding"){const u=i[l.boundShapeId];u?u.push({arrowId:a.id,handleId:"end"}):i[l.boundShapeId]=[{arrowId:a.id,handleId:"end"}]}}return i}return V("arrowBindingsIndex",(s,i)=>{if(Pi(s))return o();const a=s,c=n.getDiffSince(i);if(c===qn)return o();let l;function u(f){l||(l={...a}),l[f]?l[f]===a[f]&&(l[f]=[...l[f]]):l[f]=[]}function d(f,y,g){u(f),l[f]=l[f].filter(w=>w.arrowId!==y||w.handleId!==g),l[f].length===0&&delete l[f]}function p(f,y,g){u(f),l[f].push({arrowId:y,handleId:g})}for(const f of c){for(const y of Object.values(f.added))if(e.isShapeOfType(y,"arrow")){const{start:g,end:w}=y.props;g.type==="binding"&&p(g.boundShapeId,y.id,"start"),w.type==="binding"&&p(w.boundShapeId,y.id,"end")}for(const[y,g]of Object.values(f.updated))if(!(!e.isShapeOfType(y,"arrow")||!e.isShapeOfType(g,"arrow")))for(const w of["start","end"]){const S=y.props[w],v=g.props[w];S.type==="binding"&&v.type==="point"?d(S.boundShapeId,y.id,w):S.type==="point"&&v.type==="binding"?p(v.boundShapeId,g.id,w):S.type==="binding"&&v.type==="binding"&&S.boundShapeId!==v.boundShapeId&&(d(S.boundShapeId,y.id,w),p(v.boundShapeId,g.id,w))}for(const y of Object.values(f.removed))if(e.isShapeOfType(y,"arrow")){const{start:g,end:w}=y.props;g.type==="binding"&&d(g.boundShapeId,y.id,"start"),w.type==="binding"&&d(w.boundShapeId,y.id,"end")}}return l??a})};function B4(e,t,n){const r=e.getShapeMaskedPageBounds(t);return r===void 0?!0:!n.includes(r)}const U4=e=>{const t=Number.isFinite(e.renderingBoundsMargin);function n(r){const o=r.getCurrentPageShapeIds(),s=r.getViewportPageBounds(),i=new Set;return o.forEach(a=>{B4(r,a,s)&&i.add(a)}),i}return V("getCulledShapes",r=>{if(!t)return new Set;if(Pi(r))return n(e);const o=n(e);if(r.size!==o.size)return o;for(const s of r)if(!o.has(s))return o;return r})},H4=e=>{const t=e.query.ids("shape"),n=e.query.filterHistory("shape");function r(){const o={},s=t.get(),i=Array(s.size);return s.forEach(a=>i.push(e.get(a))),i.sort(en),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return V("parentsToChildrenWithIndexes",(o,s)=>{if(Pi(o))return r();const i=n.getDiffSince(s);if(i===qn)return r();if(i.length===0)return o;let a=null;const c=d=>{a||(a={...o}),a[d]?a[d]===o[d]&&(a[d]=[...a[d]]):a[d]=[]},l=new Set;let u;for(let d=0,p=i.length;d<p;d++){u=i[d];for(const f of Object.values(u.added))$a(f)&&(c(f.parentId),a[f.parentId].push(f.id),l.add(a[f.parentId]));for(const[f,y]of Object.values(u.updated))if($a(y)&&$a(f)){if(f.parentId!==y.parentId)c(f.parentId),c(y.parentId),a[f.parentId].splice(a[f.parentId].indexOf(y.id),1),a[y.parentId].push(y.id),l.add(a[y.parentId]);else if(f.index!==y.index){c(y.parentId);const g=a[y.parentId].indexOf(y.id);a[y.parentId][g]=y.id,l.add(a[y.parentId])}}for(const f of Object.values(u.removed))$a(f)&&(c(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const d of l){const p=fe(d.map(f=>e.get(f)));p.sort(en),d.splice(0,d.length,...p.map(f=>f.id))}return a??o})},vm=(e,t,n)=>{for(;!bn(n.parentId);){const r=e.get(n.parentId);if(!r)return!1;n=r}return n.parentId===t},K4=(e,t)=>{const n=e.query.ids("shape");let r=null;function o(){const s=t();return r=s,new Set([...n.get()].filter(i=>vm(e,s,e.get(i))))}return V("_shapeIdsInCurrentPage",(s,i)=>{if(Pi(s))return o();const a=t();if(a!==r)return o();const c=e.history.getDiffSince(i);if(c===qn)return o();const l=new fh(s);for(const d of c){for(const p of Object.values(d.added))$a(p)&&vm(e,a,p)&&l.add(p.id);for(const[p,f]of Object.values(d.updated))$a(f)&&(vm(e,a,f)?l.add(f.id):l.remove(f.id));for(const p of Object.keys(d.removed))Kn(p)&&l.remove(p)}const u=l.get();return u?fl(u.value,u.diff):s})},A2=x.createContext(null);function W4({context:e,editor:t,children:n}){return h.jsx(Rf.Provider,{value:t,children:h.jsx(A2.Provider,{value:e,children:n})})}function j2(){const e=x.useContext(A2);return e?{isDarkMode:e.isDarkMode}:null}async function V4(e,t,n={}){var C,I;const r=typeof t[0]=="string"?t:t.map(_=>_.id);if(r.length===0)return;if(!window.document)throw Error("No document");const{scale:o=1,background:s=!1,padding:i=$5,preserveAspectRatio:a=!1}=n,c=n.darkMode??e.user.getIsDarkMode(),l=Jo({isDarkMode:c}),u=e.getShapeAndDescendantIds(r),d=e.getUnorderedRenderingShapes(!1).filter(({id:_})=>u.has(_));let p=null;if(n.bounds)p=n.bounds;else for(const{id:_}of d){const k=e.getShapeMaskedPageBounds(_);k&&(p?p.union(k):p=k.clone())}if(!p)return;const f=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;f||p.expandBy(i);const y=p.width*o,g=p.height*o;try{(I=(C=document.body).focus)==null||I.call(C)}catch{}const w=[],S=new Map,v={isDarkMode:c,addExportDef:_=>{if(S.has(_.key))return;const k=(async()=>{const $=await _.getElement();$&&w.push(h.jsx(x.Fragment,{children:$},w.length))})();S.set(_.key,k)}},b=(await Promise.all(d.map(async({id:_,opacity:k,index:$,backgroundIndex:T})=>{var H,U;if(_===f)return[];const O=e.getShape(_);if(e.isShapeOfType(O,"group"))return[];const N=e.getShapeUtil(O);let F=await((H=N.toSvg)==null?void 0:H.call(N,O,v)),L=await((U=N.toBackgroundSvg)==null?void 0:U.call(N,O,v));if(!F&&!L){const W=e.getShapePageBounds(O);F=h.jsx("rect",{width:W.w,height:W.h,fill:l.solid,stroke:l.grey.pattern,strokeWidth:1})}let B=e.getShapePageTransform(O).toCssString();"scale"in O.props&&O.props.scale!==1&&(B=`${B} scale(${O.props.scale}, ${O.props.scale})`),F&&(F=h.jsx("g",{transform:B,opacity:k,children:F},O.id)),L&&(L=h.jsx("g",{transform:B,opacity:k,children:L},`bg_${O.id}`));const q=e.getShapeMask(O.id);if(q){const W=`mask_${O.id.replace(":","_")}`;w.push(h.jsx("clipPath",{id:W,children:h.jsx("path",{d:`M${q.map(({x:Z,y:le})=>`${Z},${le}`).join("L")}Z`})},w.length)),F&&(F=h.jsx("g",{clipPath:`url(#${W})`,children:F},O.id)),L&&(L=h.jsx("g",{clipPath:`url(#${W})`,children:L},`bg_${O.id}`))}const Q=[];return F&&Q.push({zIndex:$,element:F}),L&&Q.push({zIndex:T,element:L}),Q}))).flat();return await Promise.all(S.values()),{jsx:h.jsx(W4,{editor:e,context:v,children:h.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:y,height:g,viewBox:`${p.minX} ${p.minY} ${p.width} ${p.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?f?l.solid:l.background:"transparent"},children:[h.jsx("defs",{children:w}),b.sort((_,k)=>_.zIndex-k.zIndex).map(({element:_})=>_)]})}),width:y,height:g}}const G4=40;class Y4{constructor(t){m(this,"_clickId","");m(this,"_clickTimeout");m(this,"_clickScreenPoint");m(this,"_previousScreenPoint");m(this,"_getClickTimeout",(t,n=et())=>{this._clickId=n,clearTimeout(this._clickTimeout),this._clickTimeout=setTimeout(()=>{if(this._clickState===t&&this._clickId===n){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},t==="idle"||t==="pendingDouble"?k5:T5)});m(this,"_clickState","idle");m(this,"lastPointerInfo",{});m(this,"transformPointerDownEvent",t=>{if(!this._clickState)return t;switch(this._clickScreenPoint=P.From(t.point),this._previousScreenPoint&&this._previousScreenPoint.dist(this._clickScreenPoint)>G4&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=t,this._clickState){case"idle":return this._clickState="pendingDouble",this._clickTimeout=this._getClickTimeout(this._clickState),t;case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"quadruple_click",phase:"down"};case"pendingOverflow":return this._clickState="overflow",this._clickTimeout=this._getClickTimeout(this._clickState),t;default:return this._clickTimeout=this._getClickTimeout(this._clickState),t}});m(this,"transformPointerUpEvent",t=>{if(!this._clickState)return t;switch(this._clickScreenPoint=P.From(t.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"};default:return t}});m(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});m(this,"handleMove",()=>{this._clickState!=="idle"&&this._clickScreenPoint&&P.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?NS:iu)&&this.cancelDoubleClickTimeout()});this.editor=t}get clickState(){return this._clickState}}class X4{constructor(t){m(this,"isSafari");m(this,"isIos");m(this,"isChromeForIos");m(this,"isFirefox");m(this,"isAndroid");this.editor=t,typeof window<"u"&&"navigator"in window?(this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),this.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),this.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),this.isFirefox=/firefox/i.test(navigator.userAgent),this.isAndroid=/android/i.test(navigator.userAgent)):(this.isSafari=!1,this.isIos=!1,this.isChromeForIos=!1,this.isFirefox=!1,this.isAndroid=!1)}}function ci(e){return Z4}class q4{constructor(){m(this,"length",0);m(this,"head",null);m(this,"tail",this)}push(t){return new ox(t,this)}toArray(){return Do}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const Z4=new q4;class ox{constructor(t,n){m(this,"length");this.head=t,this.tail=n,this.length=n.length+1}push(t){return new ox(t,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let t=this;return{next(){if(t.length){const n=t.head;return t=t.tail,{value:n,done:!1}}else return{value:void 0,done:!0}}}}}class Q4{constructor(t,n){m(this,"_undos",fn("HistoryManager.undos",ci()));m(this,"_redos",fn("HistoryManager.redos",ci()));m(this,"_batchDepth",0);m(this,"onBatchComplete",()=>{});m(this,"_commands",{});m(this,"createCommand",(t,n,r)=>{if(this._commands[t])throw new Error(`Duplicate command: ${t}`);this._commands[t]=r;const o=(...s)=>{if(!this._batchDepth)return this.batch(()=>o(...s)),this.ctx;const i=n(...s);if(!i)return this.ctx;const{data:a,ephemeral:c,squashing:l,preservesRedoStack:u}=i;if(this.ignoringUpdates((d,p)=>(r.do(a),{undos:d,redos:p})),!c){const d=this._undos.get().head;l&&d&&d.type==="command"&&d.name===t&&d.preservesRedoStack===u?this._undos.update(p=>p.tail.push({...d,data:r.squash(d.data,a)})):this._undos.update(p=>p.push({type:"command",name:t,data:a,preservesRedoStack:u})),i.preservesRedoStack||this._redos.set(ci()),this.ctx.emit("change-history",{reason:"push"})}return this.ctx};return o});m(this,"batch",t=>{try{this._batchDepth++,this._batchDepth===1?Mr(()=>{const n=this._undos.get().head;t(),n!==this._undos.get().head&&this.onBatchComplete()}):t()}catch(n){throw this.annotateError(n),n}finally{this._batchDepth--}return this});m(this,"ignoringUpdates",t=>{let n=this._undos.get(),r=this._redos.get();this._undos.set(ci()),this._redos.set(ci());try{({undos:n,redos:r}=Mr(()=>t(n,r)))}finally{this._undos.set(n),this._redos.set(r)}});m(this,"_undo",({pushToRedoStack:t,toMark:n=void 0})=>(this.ignoringUpdates((r,o)=>{var s;if(r.length===0)return{undos:r,redos:o};for(;((s=r.head)==null?void 0:s.type)==="STOP";){const i=r.head;if(r=r.tail,t&&(o=o.push(i)),i.id===n)return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o}}if(r.length===0)return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o};for(;r.head;){const i=r.head;if(r=r.tail,t&&(o=o.push(i)),i.type==="STOP"){if(i.onUndo&&(!n||i.id===n))return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o}}else this._commands[i.name].undo(i.data)}return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o}}),this));m(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));m(this,"redo",()=>(this.ignoringUpdates((t,n)=>{var r;if(n.length===0)return{undos:t,redos:n};for(;((r=n.head)==null?void 0:r.type)==="STOP";)t=t.push(n.head),n=n.tail;if(n.length===0)return this.ctx.emit("change-history",{reason:"redo"}),{undos:t,redos:n};for(;n.head;){const o=n.head;if(t=t.push(n.head),n=n.tail,o.type==="STOP"){if(o.onRedo)break}else{const s=this._commands[o.name];s.redo?s.redo(o.data):s.do(o.data)}}return this.ctx.emit("change-history",{reason:"redo"}),{undos:t,redos:n}}),this));m(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));m(this,"bailToMark",t=>(this._undo({pushToRedoStack:!1,toMark:t}),this));m(this,"mark",(t=et(),n=!0,r=!0)=>{const o=this._undos.get().head;return o&&o.type==="STOP"&&o.id===t&&o.onUndo===n&&o.onRedo===r?o.id:(this._undos.update(s=>s.push({type:"STOP",id:t,onUndo:n,onRedo:r})),this.ctx.emit("mark-history",{id:t}),t)});this.ctx=t,this.annotateError=n}getNumUndos(){return this._undos.get().length}getNumRedos(){return this._redos.get().length}clear(){this._undos.set(ci()),this._redos.set(ci())}}class J4{constructor(t){m(this,"scribbleItems",new Map);m(this,"state","paused");m(this,"addScribble",(t,n=et())=>{const r={id:n,scribble:{id:n,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...t,state:"starting"},timeoutMs:0,delayRemaining:t.delay??0,prev:null,next:null};return this.scribbleItems.set(n,r),r});m(this,"stop",t=>{const n=this.scribbleItems.get(t);if(!n)throw Error(`Scribble with id ${t} not found`);return n.delayRemaining=Math.min(n.delayRemaining,200),n.scribble.state="stopping",n});m(this,"addPoint",(t,n,r)=>{const o=this.scribbleItems.get(t);if(!o)throw Error(`Scribble with id ${t} not found`);const{prev:s}=o,i={x:n,y:r,z:.5};return(!s||P.Dist(s,i)>=1)&&(o.next=i),o});m(this,"tick",t=>{this.scribbleItems.size!==0&&this.editor.batch(()=>{this.scribbleItems.forEach(n=>{if(n.scribble.state==="starting"){const{next:c,prev:l}=n;c&&c!==l&&(n.prev=c,n.scribble.points.push(c)),n.scribble.points.length>8&&(n.scribble.state="active");return}n.delayRemaining>0&&(n.delayRemaining=Math.max(0,n.delayRemaining-t)),n.timeoutMs+=t,n.timeoutMs>=16&&(n.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=n;switch(a.state){case"active":{i&&i!==s?(n.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():n.delayRemaining=a.delay);break}case"stopping":{if(n.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(n.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:n})=>({...n,points:[...n.points]})).slice(-5)})})});this.editor=t}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}}class ez{constructor(t){m(this,"_beforeCreateHandlers",{});m(this,"_afterCreateHandlers",{});m(this,"_beforeChangeHandlers",{});m(this,"_afterChangeHandlers",{});m(this,"_beforeDeleteHandlers",{});m(this,"_afterDeleteHandlers",{});m(this,"_batchCompleteHandlers",[]);this.editor=t,t.store.onBeforeCreate=(r,o)=>{const s=this._beforeCreateHandlers[r.typeName];if(s){let i=r;for(const a of s)i=a(i,o);return i}return r},t.store.onAfterCreate=(r,o)=>{const s=this._afterCreateHandlers[r.typeName];if(s)for(const i of s)i(r,o)},t.store.onBeforeChange=(r,o,s)=>{const i=this._beforeChangeHandlers[o.typeName];if(i){let a=o;for(const c of i)a=c(r,a,s);return a}return o};let n=0;t.store.onAfterChange=(r,o,s)=>{if(n++,n>1e3)console.error("[CleanupManager.onAfterChange] Maximum update depth exceeded, bailing out.");else{const i=this._afterChangeHandlers[o.typeName];if(i)for(const a of i)a(r,o,s)}n--},t.store.onBeforeDelete=(r,o)=>{const s=this._beforeDeleteHandlers[r.typeName];if(s){for(const i of s)if(i(r,o)===!1)return!1}},t.store.onAfterDelete=(r,o)=>{const s=this._afterDeleteHandlers[r.typeName];if(s)for(const i of s)i(r,o)},t.history.onBatchComplete=()=>{this._batchCompleteHandlers.forEach(r=>r())}}registerBeforeCreateHandler(t,n){return this._beforeCreateHandlers[t]||(this._beforeCreateHandlers[t]=[]),this._beforeCreateHandlers[t].push(n),()=>li(this._beforeCreateHandlers[t],n)}registerAfterCreateHandler(t,n){return this._afterCreateHandlers[t]||(this._afterCreateHandlers[t]=[]),this._afterCreateHandlers[t].push(n),()=>li(this._afterCreateHandlers[t],n)}registerBeforeChangeHandler(t,n){return this._beforeChangeHandlers[t]||(this._beforeChangeHandlers[t]=[]),this._beforeChangeHandlers[t].push(n),()=>li(this._beforeChangeHandlers[t],n)}registerAfterChangeHandler(t,n){return this._afterChangeHandlers[t]||(this._afterChangeHandlers[t]=[]),this._afterChangeHandlers[t].push(n),()=>li(this._afterChangeHandlers[t],n)}registerBeforeDeleteHandler(t,n){return this._beforeDeleteHandlers[t]||(this._beforeDeleteHandlers[t]=[]),this._beforeDeleteHandlers[t].push(n),()=>li(this._beforeDeleteHandlers[t],n)}registerAfterDeleteHandler(t,n){return this._afterDeleteHandlers[t]||(this._afterDeleteHandlers[t]=[]),this._afterDeleteHandlers[t].push(n),()=>li(this._afterDeleteHandlers[t],n)}registerBatchCompleteHandler(t){return this._batchCompleteHandlers.push(t),()=>li(this._batchCompleteHandlers,t)}}function li(e,t){const n=e.indexOf(t);n>=0&&e.splice(n,1)}var tz=Object.defineProperty,nz=Object.getOwnPropertyDescriptor,Bf=(e,t,n,r)=>{for(var o=nz(t,n),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(t,n,o)||o);return o&&tz(t,n,o),o};const de=e=>Math.round(e*10**8)/10**8;function Eo(e,t,n,r,o){const s=e.filter(a=>(r==="forward"?a.startNode.id===t:a.endNode.id===t)&&de(a.length)===de(n)&&kr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const c=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(c)){i.add(c);const l=Eo(e,c,n,r,kr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...l)}}),s}function rz(e){e.sort((t,n)=>n.gaps.length-t.gaps.length);for(let t=e.length-1;t>0;t--){const n=e[t];for(let r=t-1;r>=0;r--){const o=e[r];if(o.direction===n.direction&&n.gaps.every(s=>o.gaps.some(i=>de(s.startEdge[0].x)===de(i.startEdge[0].x)&&de(s.startEdge[0].y)===de(i.startEdge[0].y)&&de(s.startEdge[1].x)===de(i.startEdge[1].x)&&de(s.startEdge[1].y)===de(i.startEdge[1].y))&&o.gaps.some(i=>de(s.endEdge[0].x)===de(i.endEdge[0].x)&&de(s.endEdge[0].y)===de(i.endEdge[0].y)&&de(s.endEdge[1].x)===de(i.endEdge[1].x)&&de(s.endEdge[1].y)===de(i.endEdge[1].y)))){e.splice(t,1);break}}}}class Du{constructor(t){m(this,"editor");this.manager=t,this.editor=t.editor}getSnapPointsCache(){const{editor:t}=this;return t.store.createComputedCache("snapPoints",n=>{const r=t.getShapePageTransform(n.id);if(!r)return;const s=t.getShapeUtil(n).getBoundsSnapGeometry(n).points??t.getShapeGeometry(n).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:c,y:l}=oe.applyToPoint(r,i);return{x:c,y:l,id:`${n.id}:${a}`}})})}getSnapPoints(t){return this.getSnapPointsCache().get(t)??[]}getSnappablePoints(){const t=this.getSnapPointsCache(),n=this.manager.getSnappableShapes(),r=[];for(const o of n){const s=t.get(o);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),t=>({id:t,pageBounds:yi(this.editor.getShapePageBounds(t))}))}getVisibleGaps(){const t=[],n=[];let r,o;const s=this.getSnappableGapNodes().sort((a,c)=>a.pageBounds.minX-c.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let c=a+1;c<s.length;c++)o=s[c],r.pageBounds.maxX<o.pageBounds.minX&&Xc(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&t.push({startNode:r,endNode:o,startEdge:[new P(r.pageBounds.maxX,r.pageBounds.minY),new P(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new P(o.pageBounds.minX,o.pageBounds.minY),new P(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:kr(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,c)=>a.pageBounds.minY-c.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let c=a+1;c<i.length;c++)o=i[c],r.pageBounds.maxY<o.pageBounds.minY&&Xc(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&n.push({startNode:r,endNode:o,startEdge:[new P(r.pageBounds.minX,r.pageBounds.maxY),new P(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new P(o.pageBounds.minX,o.pageBounds.minY),new P(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:kr(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:t,vertical:n}}snapTranslateShapes({lockedAxis:t,initialSelectionPageBounds:n,initialSelectionSnapPoints:r,dragDelta:o}){var w,S;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(o),c=r.map(({x:v,y:b},E)=>({id:"selection:"+E,x:v+o.x,y:b+o.y})),l=i,u=[],d=[],p=new P(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:l,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:p});const f=new P(t==="x"?0:((w=u[0])==null?void 0:w.nudge)??0,t==="y"?0:((S=d[0])==null?void 0:S.nudge)??0);p.x=0,p.y=0,u.length=0,d.length=0,c.forEach(v=>{v.x+=f.x,v.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:l,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:p});const y=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:d}),g=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d});return this.manager.setIndicators([...g,...y]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:t,dragDelta:n,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var _,k;const i=this.manager.getSnapThreshold(),{box:a,scaleX:c,scaleY:l}=ne.Resize(t,r,s?n.x*2:n.x,s?n.y*2:n.y,o);let u=r;c<0&&(u=wF(u)),l<0&&(u=xF(u)),s&&(a.center=t.center);const d=u==="top"||u==="bottom",p=u==="left"||u==="right",f=V1(u,a),y=this.getSnappablePoints(),g=[],w=[],S=new P(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:g,nearestSnapsY:w,otherNodeSnapPoints:y,selectionSnapPoints:f});const v=new P(d?0:((_=g[0])==null?void 0:_.nudge)??0,p?0:((k=w[0])==null?void 0:k.nudge)??0);if(o&&bF(u)&&v.len()!==0){const $=g.length&&w.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":g.length?"x":"y",T=t.aspectRatio;$==="x"?(w.length=0,v.y=v.x/T,(u==="bottom_left"||u==="top_right")&&(v.y=-v.y)):(g.length=0,v.x=v.y*T,(u==="bottom_left"||u==="top_right")&&(v.x=-v.x))}const b=P.Add(n,v),{box:E}=ne.Resize(t,r,s?b.x*2:b.x,s?b.y*2:b.y,o);s&&(E.center=t.center);const C=V1("any",E);g.length=0,w.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:g,nearestSnapsY:w,otherNodeSnapPoints:y,selectionSnapPoints:C});const I=this.getPointSnapLines({nearestSnapsX:g,nearestSnapsY:w});return this.manager.setIndicators([...I]),{nudge:v}}collectPointSnaps({selectionSnapPoints:t,otherNodeSnapPoints:n,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of t)for(const a of n){const c=P.Sub(i,a),l=Math.abs(c.x),u=Math.abs(c.y);de(l)<=de(r.x)&&(de(l)<de(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=l),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:t,minOffset:n,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!Xc(a.breadthIntersection[0],a.breadthIntersection[1],t.minY,t.maxY))continue;const l=a.startEdge[0].x+a.length/2-t.center.x;if(a.length>t.width&&de(Math.abs(l))<=de(n.x)){de(Math.abs(l))<de(n.x)&&(r.length=0),n.x=Math.abs(l);const S={type:"gap_center",gap:a,nudge:l},v=r.find(({type:E})=>E==="gap_center"),b=v&&kr(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&b?r[r.indexOf(v)]=S:(!v||!b)&&r.push(S)}const d=a.startNode.pageBounds.minX-a.length,p=t.maxX,f=d-p;de(Math.abs(f))<=de(n.x)&&(de(Math.abs(f))<de(n.x)&&(r.length=0),n.x=Math.abs(f),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:f}));const y=a.endNode.pageBounds.maxX+a.length,g=t.minX,w=y-g;de(Math.abs(w))<=de(n.x)&&(de(Math.abs(w))<de(n.x)&&(r.length=0),n.x=Math.abs(w),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:w}))}for(const a of i){if(!Xc(a.breadthIntersection[0],a.breadthIntersection[1],t.minX,t.maxX))continue;const l=a.startEdge[0].y+a.length/2-t.center.y;if(a.length>t.height&&de(Math.abs(l))<=de(n.y)){de(Math.abs(l))<de(n.y)&&(o.length=0),n.y=Math.abs(l);const S={type:"gap_center",gap:a,nudge:l},v=o.find(({type:E})=>E==="gap_center"),b=v&&Xc(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&b?o[o.indexOf(v)]=S:(!v||!b)&&o.push(S);continue}const d=a.startNode.pageBounds.minY-a.length,p=t.maxY,f=d-p;de(Math.abs(f))<=de(n.y)&&(de(Math.abs(f))<de(n.y)&&(o.length=0),n.y=Math.abs(f),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:f}));const y=a.endNode.pageBounds.maxY+a.length,g=t.minY,w=y-g;de(Math.abs(w))<=de(n.y)&&(de(Math.abs(w))<de(n.y)&&(o.length=0),n.y=Math.abs(w),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:w}))}}getPointSnapLines({nearestSnapsX:t,nearestSnapsY:n}){const r={},o={};if(t.length>0){for(const s of t)if(s.type==="points"){const i=de(s.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(s.points)}}if(n.length>0){for(const s of n)if(s.type==="points"){const i=de(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:et(),type:"points",points:Mp(s.map(i=>P.From(i.otherPoint)).concat(s.map(i=>P.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:t,nearestSnapsX:n,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:t.sides[0],right:t.sides[1],bottom:[t.corners[3],t.corners[2]],left:[t.corners[0],t.corners[3]]},a=[];if(n.length>0)for(const c of n){if(c.type==="points")continue;const{gap:{breadthIntersection:l,startEdge:u,startNode:d,endNode:p,length:f,endEdge:y}}=c;switch(c.type){case"gap_center":{const g=(f-t.width)/2,w=kr(l[0],l[1],t.minY,t.maxY);a.push({type:"gaps",direction:"horizontal",id:et(),gaps:[...Eo(s,d.id,g,"backward",w),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:y},...Eo(s,p.id,g,"forward",w)]});break}case"gap_duplicate":{const g=kr(l[0],l[1],t.minY,t.maxY);a.push({type:"gaps",direction:"horizontal",id:et(),gaps:c.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(w=>w.clone().addXY(-d.pageBounds.width,0))},{startEdge:u,endEdge:y},...Eo(s,p.id,f,"forward",g)]:[...Eo(s,d.id,f,"backward",g),{startEdge:u,endEdge:y},{startEdge:y.map(w=>w.clone().addXY(c.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const c of r){if(c.type==="points")continue;const{gap:{breadthIntersection:l,startEdge:u,startNode:d,endNode:p,length:f,endEdge:y}}=c;switch(c.type){case"gap_center":{const g=(f-t.height)/2,w=kr(l[0],l[1],t.minX,t.maxX);a.push({type:"gaps",direction:"vertical",id:et(),gaps:[...Eo(o,d.id,g,"backward",w),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:y},...Eo(o,c.gap.endNode.id,g,"forward",w)]});break}case"gap_duplicate":{const g=kr(l[0],l[1],t.minX,t.maxX);a.push({type:"gaps",direction:"vertical",id:et(),gaps:c.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(w=>w.clone().addXY(0,-d.pageBounds.height))},{startEdge:u,endEdge:y},...Eo(o,p.id,f,"forward",g)]:[...Eo(o,d.id,f,"backward",g),{startEdge:u,endEdge:y},{startEdge:y.map(w=>w.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return rz(a),a}}Bf([V],Du.prototype,"getSnapPointsCache");Bf([V],Du.prototype,"getSnappablePoints");Bf([V],Du.prototype,"getSnappableGapNodes");Bf([V],Du.prototype,"getVisibleGaps");function V1(e,t){const{minX:n,maxX:r,minY:o,maxY:s}=t,i=[];switch(e){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:n,y:o})}switch(e){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:o})}switch(e){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:s})}switch(e){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:n,y:s})}return i}var oz=Object.defineProperty,sz=Object.getOwnPropertyDescriptor,iz=(e,t,n,r)=>{for(var o=sz(t,n),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(t,n,o)||o);return o&&oz(t,n,o),o};const az=()=>null,cz=()=>[];class O2{constructor(t){m(this,"editor");this.manager=t,this.editor=t.editor}getSnapGeometryCache(){const{editor:t}=this;return t.store.createComputedCache("handle snap geometry",n=>{const r=t.getShapeUtil(n).getHandleSnapGeometry(n);return{outline:r.outline===void 0?t.getShapeGeometry(n):r.outline,points:r.points??[],getSelfSnapOutline:r.getSelfSnapOutline??az,getSelfSnapPoints:r.getSelfSnapPoints??cz}})}*iterateSnapPointsInPageSpace(t,n){var o,s;const r=(o=this.getSnapGeometryCache().get(t))==null?void 0:o.getSelfSnapPoints(n);if(r&&r.length){const i=yi(this.editor.getShapePageTransform(t));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===t)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.points;if(!a||!a.length)continue;const c=yi(this.editor.getShapePageTransform(i));for(const l of a)yield c.applyToPoint(l)}}*iterateSnapOutlines(t,n){var o,s;const r=(o=this.getSnapGeometryCache().get(t))==null?void 0:o.getSelfSnapOutline(n);r&&(yield{shapeId:t,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===t)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:t,handle:n,handleInPageSpace:r}){const o=this.manager.getSnapThreshold();let s=o,i=null;for(const l of this.iterateSnapPointsInPageSpace(t,n))P.DistMin(r,l,s)&&(s=P.Dist(r,l),i=l);if(i)return i;let a=o,c=null;for(const{shapeId:l,outline:u}of this.iterateSnapOutlines(t,n)){const d=yi(this.editor.getShapePageTransform(l)),p=this.editor.getPointInShapeSpace(l,r),f=u.nearestPoint(p),y=d.applyToPoint(f);P.DistMin(r,y,a)&&(a=P.Dist(r,y),c=y)}return c||null}snapHandle({currentShapeId:t,handle:n}){const o=yi(this.editor.getShapePageTransform(t)).applyToPoint(n),s=this.getHandleSnapPosition({currentShapeId:t,handle:n,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:et(),type:"points",points:[s]}]),{nudge:P.Sub(s,o)}):null}}iz([V],O2.prototype,"getSnapGeometryCache");var lz=Object.defineProperty,uz=Object.getOwnPropertyDescriptor,sx=(e,t,n,r)=>{for(var o=uz(t,n),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(t,n,o)||o);return o&&lz(t,n,o),o};class Uf{constructor(t){m(this,"shapeBounds");m(this,"handles");m(this,"_snapIndicators",fn("snapLines",void 0));this.editor=t,this.shapeBounds=new Du(this),this.handles=new O2(this)}getIndicators(){return this._snapIndicators.get()??Do}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(t){this._snapIndicators.set(t)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:t}=this,n=t.getRenderingBounds(),r=t.getSelectedShapeIds(),o=new Set,s=i=>{if(Kn(i)){const c=t.getShape(i);c&&t.isShapeOfType(c,"frame")&&o.add(i)}const a=t.getSortedChildIdsForParent(i);for(const c of a){if(r.includes(c))continue;const l=t.getShape(c);if(!l||!t.getShapeUtil(l).canSnap(l))continue;const d=t.getShapePageBounds(c);if(d&&n.includes(d)){if(t.isShapeOfType(l,"group")){s(c);continue}o.add(c)}}};return s(this.getCurrentCommonAncestor()??t.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}sx([V],Uf.prototype,"getSnapThreshold");sx([V],Uf.prototype,"getSnappableShapes");sx([V],Uf.prototype,"getCurrentCommonAncestor");const dz=/\r?\n|\r/g;function G1(e){return e.replace(dz,`
`).split(`
`).map(t=>t||" ").join(`
`)}const hz={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},pz=/\s/;class fz{constructor(t){m(this,"baseElm");m(this,"measureText",(t,n)=>{var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","ltr"),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-style",n.fontStyle),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("font-size",n.fontSize+"px"),r.style.setProperty("line-height",n.lineHeight*n.fontSize+"px"),r.style.setProperty("max-width",n.maxWidth===null?null:n.maxWidth+"px"),r.style.setProperty("min-width",n.minWidth===null?null:n.minWidth+"px"),r.style.setProperty("padding",n.padding),r.style.setProperty("overflow-wrap",n.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=G1(t);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}});var o;this.editor=t;const n=this.editor.getContainer();(o=n.querySelector("#tldraw_text_measure"))==null||o.remove();const r=document.createElement("div");r.id="tldraw_text_measure",r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,n.appendChild(r),this.baseElm=r}measureElementTextNodeSpans(t,{shouldTruncateToFirstLine:n=!1}={}){const r=[],o=t.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,c=t.childNodes[0];let l=0,u=null,d=null,p=0,f=!1;for(const y of t.childNodes)if(y.nodeType===Node.TEXT_NODE)for(const g of y.textContent??""){a.setStart(c,l),a.setEnd(c,l+g.length);const w=a.getClientRects(),S=w[w.length-1],v=S.top+i,b=S.left+s,E=S.right+s,C=pz.test(g);if(C!==d||v!==p||!u){if(u){if(n&&v!==p){f=!0;break}r.push(u)}u={box:{x:b,y:v,w:S.width,h:S.height},text:g}}else u.box.w=E-u.box.x,u.text+=g;d=C,p=v,l+=g.length}return u&&r.push(u),{spans:r,didTruncate:f}}measureTextSpans(t,n){var l;if(t==="")return[];const r=(l=this.baseElm)==null?void 0:l.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(n.width-n.padding*2);r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("dir","ltr"),r.style.setProperty("font-size",`${n.fontSize}px`),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("line-height",`${n.lineHeight*n.fontSize}px`),r.style.setProperty("text-align",hz[n.textAlign]);const s=n.overflow==="truncate-ellipsis"||n.overflow==="truncate-clip";s&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=G1(t);r.textContent=i;const{spans:a,didTruncate:c}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(n.overflow==="truncate-ellipsis"&&c){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const d=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=d[d.length-1];return d.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,n.width-n.padding-u),y:p.box.y,w:u,h:p.box.h}}),d}return r.remove(),a}}const Y1=(typeof process<"u",q_);class gz{constructor(t){m(this,"cancelRaf");m(this,"isPaused",!0);m(this,"now",0);m(this,"start",()=>{var t;this.isPaused=!1,(t=this.cancelRaf)==null||t.call(this),this.cancelRaf=Y1(this.tick),this.now=Date.now()});m(this,"tick",()=>{if(this.isPaused)return;const t=Date.now(),n=t-this.now;this.now=t,this.updatePointerVelocity(n),this.editor.emit("frame",n),this.editor.emit("tick",n),this.cancelRaf=Y1(this.tick)});m(this,"dispose",()=>{var t;this.isPaused=!0,(t=this.cancelRaf)==null||t.call(this)});m(this,"prevPoint",new P);m(this,"updatePointerVelocity",t=>{const{prevPoint:n,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(t===0)return;const s=P.Sub(r,n);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new P(0,0),c=o.clone().lrp(a.mul(i/t),.5);Math.abs(c.x)<.01&&(c.x=0),Math.abs(c.y)<.01&&(c.y=0),o.equals(c)||(this.editor.inputs.pointerVelocity=c)});this.editor=t,this.editor.disposables.add(this.dispose),this.start()}}var mz=Object.defineProperty,yz=Object.getOwnPropertyDescriptor,go=(e,t,n,r)=>{for(var o=yz(t,n),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(t,n,o)||o);return o&&mz(t,n,o),o};class Hr{constructor(t,n){m(this,"updateUserPreferences",t=>{this.user.setUserPreferences({...this.user.userPreferences.get(),...t})});this.user=t,this.inferDarkMode=n}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode()}}getIsDarkMode(){return this.user.userPreferences.get().isDarkMode??(this.inferDarkMode?v4():!1)}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??ai.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??ai.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??ai.name}getLocale(){return this.user.userPreferences.get().locale??ai.locale}getColor(){return this.user.userPreferences.get().color??ai.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??ai.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??ai.isWrapMode}}go([V],Hr.prototype,"getUserPreferences");go([V],Hr.prototype,"getIsDarkMode");go([V],Hr.prototype,"getEdgeScrollSpeed");go([V],Hr.prototype,"getAnimationSpeed");go([V],Hr.prototype,"getId");go([V],Hr.prototype,"getName");go([V],Hr.prototype,"getLocale");go([V],Hr.prototype,"getColor");go([V],Hr.prototype,"getIsSnapMode");go([V],Hr.prototype,"getIsWrapMode");function Zc(e){return Math.abs(e.props.bend)<8}function Qp(e,t){if(t.type==="point")return;const n=e.getShape(t.boundShapeId),r=e.getShapePageTransform(n),o=e.getShapeGeometry(n),s=o instanceof Br?o.children[0].vertices:o.vertices;return{shape:n,transform:r,isClosed:o.isClosed,isExact:t.isExact,didIntersect:!1,outline:s}}function X1(e,t,n,r){if(n.type==="point")return P.From(n);const o=e.getShape(n.boundShapeId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=P.Add(s,P.MulV(n.isPrecise||r?n.normalizedAnchor:{x:.5,y:.5},i)),c=oe.applyToPoint(e.getShapePageTransform(o),a);return oe.applyToPoint(oe.Inverse(t),c)}else return new P(0,0)}function jr(e,t){const n=e.getShapePageTransform(t);let r,o;t.props.start.type==="binding"&&t.props.end.type==="binding"&&(r=t.props.start.boundShapeId,o=t.props.end.boundShapeId);const s=ix(e,r,o),i=X1(e,n,t.props.start,s==="double-bound"||s==="start-contains-end"),a=X1(e,n,t.props.end,s==="double-bound"||s==="end-contains-start");return{start:i,end:a}}const Ma=10,Jp=10,Sz=10,Ps={s:2,m:3.5,l:5,xl:10};function ix(e,t,n){if(!t||!n)return"safe";if(t===n)return"double-bound";const r=e.getShapePageBounds(t),o=e.getShapePageBounds(n);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}function Al(e,t){const{start:n,end:r,arrowheadStart:o,arrowheadEnd:s}=t.props,i=jr(e,t),a=i.start.clone(),c=i.end.clone(),l=P.Med(a,c);if(P.Equals(a,c))return{isStraight:!0,start:{handle:a,point:a,arrowhead:t.props.arrowheadStart},end:{handle:c,point:c,arrowhead:t.props.arrowheadEnd},middle:l,isValid:!1,length:0};const u=P.Sub(c,a).uni(),d=Qp(e,n),p=Qp(e,r),f=e.getShapePageTransform(t);q1(c,i.start,f,p),q1(a,i.end,f,d);let y=0,g=0,w=0,S=0,v=Ma;const b=d&&p&&d.shape===p.shape,E=d&&p?ix(e,d.shape.id,p.shape.id):"safe";E==="safe"&&d&&p&&!b&&!d.isExact&&!p.isExact&&(p.didIntersect&&!d.didIntersect?d.isClosed&&a.setTo(c.clone().add(u.clone().mul(Ma))):p.didIntersect||p.isClosed&&c.setTo(a.clone().sub(u.clone().mul(Ma))));const C=P.Sub(c,a),I=P.Len(C)?C.uni():P.From(C),_=!P.Equals(I,u);b||(E!=="start-contains-end"&&d&&o!=="none"&&!d.isExact&&(w=Ps[t.props.size]/2+("size"in d.shape.props?Ps[d.shape.props.size]/2:0),y=Jp+w,v+=w),E!=="end-contains-start"&&p&&s!=="none"&&!p.isExact&&(S=Ps[t.props.size]/2+("size"in p.shape.props?Ps[p.shape.props.size]/2:0),g=Jp+S,v+=S));const k=a.clone().add(I.clone().mul(y*(_?-1:1))),$=c.clone().sub(I.clone().mul(g*(_?-1:1)));P.DistMin(k,$,v)&&(y!==0&&g!==0?(y*=-1.5,g*=-1.5):y!==0?y*=-1:g!==0&&(g*=-1)),a.add(I.clone().mul(y*(_?-1:1))),c.sub(I.clone().mul(g*(_?-1:1))),_?(d&&p&&c.setTo(P.Add(a,I.clone().mul(-Ma))),l.setTo(P.Med(i.start,i.end))):l.setTo(P.Med(a,c));const T=P.Dist(a,c);return{isStraight:!0,start:{handle:i.start,point:a,arrowhead:t.props.arrowheadStart},end:{handle:i.end,point:c,arrowhead:t.props.arrowheadEnd},middle:l,isValid:T>0,length:T}}function q1(e,t,n,r){if(r===void 0||r.isExact)return;const o=oe.applyToPoint(n,t),s=oe.applyToPoint(n,e),i=oe.applyToPoint(oe.Inverse(r.transform),o),a=oe.applyToPoint(oe.Inverse(r.transform),s),c=r.isClosed,u=(c?nx:_4)(i,a,r.outline);let d;if(u!==null&&(d=u.sort((y,g)=>P.Dist2(y,i)-P.Dist2(g,i))[0]??(c?void 0:a)),d===void 0)return;const p=oe.applyToPoint(r.transform,d),f=oe.applyToPoint(oe.Inverse(n),p);e.setTo(f),r.didIntersect=!0}function xm(e,t,n=0){const{arrowheadEnd:r,arrowheadStart:o}=t.props,s=t.props.bend+n;if(Math.abs(s)>Math.abs(t.props.bend*Sz))return Al(e,t);const i=jr(e,t),a=P.Med(i.start,i.end),c=P.Sub(i.end,i.start),l=P.Len(c)?c.uni():P.From(c),u=P.Add(a,l.per().mul(-s)),d=Qp(e,t.props.start),p=Qp(e,t.props.end),f=i.start.clone(),y=i.end.clone(),g=u.clone();if(P.Equals(f,y))return{isStraight:!0,start:{handle:f,point:f,arrowhead:t.props.arrowheadStart},end:{handle:y,point:y,arrowhead:t.props.arrowheadEnd},middle:g,isValid:!1,length:0};const w=t.props.bend<0,S=w?$u:Uk,v=Z1(f,y,g),b=P.Angle(v.center,f),E=P.Angle(v.center,y),C=S(b,E);if(v.length===0||v.size===0||!S1(v.length)||!S1(v.size))return Al(e,t);const I=f.clone(),_=y.clone(),k=g.clone(),$=e.getShapePageTransform(t);let T=0,O=0,N=Ma;if(d&&!d.isExact){const W=oe.applyToPoint($,I),Z=oe.applyToPoint($,v.center),le=oe.applyToPoint($,_),be=oe.Inverse(d.transform),Me=oe.applyToPoint(be,W),ae=oe.applyToPoint(be,Z),Ae=oe.applyToPoint(be,le),{isClosed:Re}=d,ot=Re?HS:U1;let Ie,ht=ot(ae,v.radius,d.outline);if(ht){const He=ae.angle(Me),ir=ae.angle(Ae),Ln=S(He,ir);ht=ht.filter(qe=>S(He,ae.angle(qe))<=Ln);const Fn=Ln*.25;ht.sort(Re?(qe,Ot)=>Math.abs(S(He,ae.angle(qe))-Fn)<Math.abs(S(He,ae.angle(Ot))-Fn)?-1:1:(qe,Ot)=>S(He,ae.angle(qe))<S(He,ae.angle(Ot))?-1:1),Ie=ht[0]??(Re?void 0:Me)}else Ie=Re?void 0:Me;if(Ie&&(I.setTo(e.getPointInShapeSpace(t,oe.applyToPoint(d.transform,Ie))),d.didIntersect=!0,o!=="none")){const He=Ps[t.props.size]/2+("size"in d.shape.props?Ps[d.shape.props.size]/2:0);T=Jp+He,N+=He}}if(p&&!p.isExact){const W=oe.applyToPoint($,I),Z=oe.applyToPoint($,_),le=oe.applyToPoint($,v.center),be=oe.Inverse(p.transform),Me=oe.applyToPoint(be,W),ae=oe.applyToPoint(be,le),Ae=oe.applyToPoint(be,Z),Re=p.isClosed,ot=Re?HS:U1;let Ie,ht=ot(ae,v.radius,p.outline);if(ht){const He=ae.angle(Me),ir=ae.angle(Ae),Ln=S(He,ir),Fn=Ln*.75;ht=ht.filter(qe=>S(He,ae.angle(qe))<=Ln),ht.sort(Re?(qe,Ot)=>Math.abs(S(He,ae.angle(qe))-Fn)<Math.abs(S(He,ae.angle(Ot))-Fn)?-1:1:(qe,Ot)=>S(He,ae.angle(qe))<S(He,ae.angle(Ot))?-1:1),ht[0]?Ie=ht[0]:Ie=Re?void 0:Ae}else Ie=Re?void 0:Ae;if(Ie&&(_.setTo(e.getPointInShapeSpace(t,oe.applyToPoint(p.transform,Ie))),p.didIntersect=!0,r!=="none")){const He=Ps[t.props.size]/2+("size"in p.shape.props?Ps[p.shape.props.size]/2:0);O=Jp+He,N+=He}}let F=P.Angle(v.center,I),L=P.Angle(v.center,_),B=S(F,L),q=B*v.radius;const Q=I.clone(),H=_.clone();if(T!==0){const W=T/q*(w?1:-1),Z=P.FromAngle(F+B*W);Q.setTo(v.center).add(Z.mul(v.radius))}if(O!==0){const W=O/q*(w?-1:1),Z=P.FromAngle(L+B*W);H.setTo(v.center).add(Z.mul(v.radius))}if(P.DistMin(Q,H,N)&&(T!==0&&O!==0?(T*=-1.5,O*=-1.5):T!==0?T*=-2:O!==0&&(O*=-2)),T!==0){const W=T/q*(w?1:-1),Z=P.FromAngle(F+B*W);I.setTo(v.center).add(Z.mul(v.radius))}if(O!==0){const W=O/q*(w?-1:1),Z=P.FromAngle(L+B*W);_.setTo(v.center).add(Z.mul(v.radius))}if(d&&p&&!d.isExact&&!p.isExact){F=P.Angle(v.center,I),L=P.Angle(v.center,_),B=S(F,L),q=B*v.radius;const W=ix(e,d.shape.id,p.shape.id);if(W==="double-bound"&&q<30)I.setTo(f),_.setTo(y),k.setTo(g);else if(W==="safe"&&(d&&!d.didIntersect&&I.setTo(f),p&&!p.didIntersect||S(b,F)>S(b,L))){const Z=Math.min(.9,Ma/q)*(w?1:-1),le=P.FromAngle(F+B*Z);_.setTo(v.center).add(le.mul(v.radius))}}vz(v.center,v.radius,I,_,k,C,w),I.equals(_)&&(I.setTo(k.clone().addXY(1,1)),_.setTo(k.clone().subXY(1,1))),f.setTo(I),y.setTo(_),g.setTo(k);const U=Z1(f,y,g);return{isStraight:!1,start:{point:f,handle:i.start,arrowhead:t.props.arrowheadStart},end:{point:y,handle:i.end,arrowhead:t.props.arrowheadEnd},middle:g,handleArc:v,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function Z1(e,t,n){const r=-2*(e.x*(t.y-n.y)-e.y*(t.x-n.x)+t.x*n.y-n.x*t.y),o={x:((e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y)+(n.x*n.x+n.y*n.y)*(t.y-e.y))/r,y:((e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x)+(n.x*n.x+n.y*n.y)*(e.x-t.x))/r},s=P.Dist(o,e),i=+P.Clockwise(e,n,t),a=((e.y-t.y)**2+(e.x-t.x)**2)**.5,c=((t.y-n.y)**2+(t.x-n.x)**2)**.5,l=((n.y-e.y)**2+(n.x-e.x)**2)**.5,u=Math.acos((c*c+l*l-a*a)/(2*c*l))*2,d=+(Pe>u),p=(Oe-u)*(i?1:-1),f=p*s;return{center:o,radius:s,size:p,length:f,largeArcFlag:d,sweepFlag:i}}function vz(e,t,n,r,o,s,i){const a=P.Angle(e,n),c=P.Angle(e,r);let l=$u(a,c);i||(l=Oe-l);const u=.5*(i?1:-1),d=P.FromAngle(a+l*u);if(o.setTo(e).add(d.mul(t)),l>s){o.rotWith(e,Pe);const p=r.clone();r.setTo(n),n.setTo(p)}}const xz={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"};class se{constructor(t,n){m(this,"id");m(this,"type");m(this,"shapeType");m(this,"initial");m(this,"children");m(this,"parent");m(this,"_path");m(this,"_current");m(this,"_isActive");m(this,"transition",(t,n={})=>{var s;const r=t.split(".");let o=this;for(let i=0;i<r.length;i++){const a=r[i],c=o.getCurrent(),l=(s=o.children)==null?void 0:s[a];if(!l)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((c==null?void 0:c.id)!==l.id&&(c==null||c.exit(n,a),o._current.set(l),l.enter(n,(c==null?void 0:c.id)||"initial"),!l.getIsActive()))break;o=l}return this});m(this,"handleEvent",t=>{var o;const n=xz[t.name],r=this._current.__unsafe__getWithoutCapture();(o=this[n])==null||o.call(this,t),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(t)});m(this,"enter",(t,n)=>{var r;if(this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,t,n),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(t,n)}});m(this,"exit",(t,n)=>{var r,o;this._isActive.set(!1),(r=this.onExit)==null||r.call(this,t,n),this.getIsActive()||(o=this.getCurrent())==null||o.exit(t,n)});m(this,"_currentToolIdMask",fn("curent tool id mask",void 0));m(this,"onWheel");m(this,"onPointerDown");m(this,"onPointerMove");m(this,"onLongPress");m(this,"onPointerUp");m(this,"onDoubleClick");m(this,"onTripleClick");m(this,"onQuadrupleClick");m(this,"onRightClick");m(this,"onMiddleClick");m(this,"onKeyDown");m(this,"onKeyUp");m(this,"onKeyRepeat");m(this,"onCancel");m(this,"onComplete");m(this,"onInterrupt");m(this,"onTick");m(this,"onEnter");m(this,"onExit");this.editor=t;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=fn("toolIsActive"+this.id,!1),this._current=fn("toolState"+this.id,void 0),this._path=V("toolPath"+this.id,()=>{const i=this.getCurrent();return this.id+(i?`.${i.getPath()}`:"")}),this.parent=n??{},this.parent?o&&s?(this.type="branch",this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&s&&(this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])))}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(t){this._currentToolIdMask.set(t)}}m(se,"id"),m(se,"initial"),m(se,"children");class bh extends se{constructor(){super(...arguments);m(this,"onKeyDown",n=>{var r;switch(n.code){case"KeyZ":{if(!(n.shiftKey||n.ctrlKey)){const o=this.getCurrent();o&&((r=o.getCurrent())==null?void 0:r.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...n,onInteractionEnd:o.id})}break}}})}}m(bh,"id","root"),m(bh,"initial",""),m(bh,"children",()=>[]);var wz=Object.defineProperty,bz=Object.getOwnPropertyDescriptor,re=(e,t,n,r)=>{for(var o=bz(t,n),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(t,n,o)||o);return o&&wz(t,n,o),o};class J extends E4.EventEmitter{constructor({store:n,user:r,shapeUtils:o,tools:s,getContainer:i,initialState:a,inferDarkMode:c}){super();m(this,"store");m(this,"root");m(this,"disposables",new Set);m(this,"_tickManager");m(this,"snaps");m(this,"user");m(this,"textMeasure");m(this,"environment");m(this,"scribbles");m(this,"getContainer");m(this,"sideEffects");m(this,"shapeUtils");m(this,"styleProps");m(this,"history",new Q4(this,n=>{this.annotateError(n,{origin:"history.batch",willCrashApp:!0}),this.crash(n)}));m(this,"_crashingError",null);m(this,"_updateInstanceState",this.history.createCommand("updateInstanceState",(n,r)=>{const o=this.store.get(this.getInstanceState().id),s={...o,...n};return{data:{prev:o,next:s},ephemeral:!1,squashing:!1,...r}},{do:({next:n})=>{this.store.put([n])},undo:({prev:n})=>{this.store.put([n])},squash({prev:n},{next:r}){return{prev:n,next:r}}}));m(this,"_isChangingStyleTimeout",-1);m(this,"setCursor",n=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...n}},{ephemeral:!0}),this));m(this,"_setInstancePageState",this.history.createCommand("setInstancePageState",(n,r)=>({data:{prev:this.store.get(n.id??this.getCurrentPageState().id),partial:n},...r}),{do:({prev:n,partial:r})=>{this.store.update(n.id,o=>({...o,...r}))},undo:({prev:n})=>{this.store.update(n.id,()=>n)}}));m(this,"_setSelectedShapes",this.history.createCommand("setSelectedShapes",(n,r)=>{const{selectedShapeIds:o}=this.getCurrentPageState(),s=new Set(o);return n.length===s.size&&n.every(i=>s.has(i))?null:{data:{selectedShapeIds:n,prevSelectedShapeIds:o},preservesRedoStack:!0,...r}},{do:({selectedShapeIds:n})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:n}])},undo:({prevSelectedShapeIds:n})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:n}])},squash({prevSelectedShapeIds:n},{selectedShapeIds:r}){return{selectedShapeIds:r,prevSelectedShapeIds:n}}}));m(this,"_setFocusedGroupId",this.history.createCommand("setFocusedGroupId",n=>{const r=this.getCurrentPageState().focusedGroupId;if(r!==n)return{data:{prev:r,next:n},preservesRedoStack:!0,squashing:!0}},{do:({next:n})=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},undo:({prev:n})=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},squash({prev:n},{next:r}){return{prev:n,next:r}}}));m(this,"_viewportAnimation",null);m(this,"_willSetInitialBounds",!0);m(this,"_wasInset",!1);m(this,"_cameraState",fn("camera state","idle"));m(this,"_cameraStateTimeoutRemaining",0);m(this,"_lastUpdateRenderingBoundsTimestamp",Date.now());m(this,"_decayCameraStateTimeout",n=>{this._cameraStateTimeoutRemaining-=n,this._cameraStateTimeoutRemaining<=0&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"),this.updateRenderingBounds())});m(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=O5;const n=Date.now();this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._lastUpdateRenderingBoundsTimestamp=n,this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});m(this,"_renderingBounds",fn("rendering viewport",new ne));m(this,"renderingBoundsMargin",100);m(this,"_currentPageShapeIds");m(this,"_setCurrentPageId",this.history.createCommand("setCurrentPage",(n,r)=>{if(!this.store.has(n)){console.error("Tried to set the current page id to a page that doesn't exist.");return}return this.stopFollowingUser(),{data:{toId:n,fromId:this.getCurrentPageId()},squashing:!0,preservesRedoStack:!0,...r}},{do:({toId:n})=>{if(this.store.has(n)){if(!this.getPageStates().find(r=>r.pageId===n)){const r=hn.create({id:hn.createId(n)});this.store.put([r,Zt.create({id:Zt.createId(n),pageId:n})])}this.store.put([{...this.getInstanceState(),currentPageId:n}]),this.updateRenderingBounds()}},undo:({fromId:n})=>{this.store.has(n)&&(this.store.put([{...this.getInstanceState(),currentPageId:n}]),this.updateRenderingBounds())},squash:({fromId:n},{toId:r})=>({toId:r,fromId:n})}));m(this,"_updatePage",this.history.createCommand("updatePage",(n,r)=>{if(this.getInstanceState().isReadonly)return null;const o=this.getPage(n.id);return o?{data:{prev:o,partial:n},...r}:null},{do:({partial:n})=>{this.store.update(n.id,r=>({...r,...n}))},undo:({prev:n,partial:r})=>{this.store.update(r.id,()=>n)},squash(n,r){return{prev:{...n.prev,...r.prev},partial:r.partial}}}));m(this,"_createPage",this.history.createCommand("createPage",n=>{if(this.getInstanceState().isReadonly||this.getPages().length>=Gp)return null;const r=this.getPages(),o=D4(n.name??"Page 1",r.map(l=>l.name));let s=n.index;(!s||r.some(l=>l.index===s))&&(s=$o(r[r.length-1].index));const i=Ho.create({meta:{},...n,name:o,index:s}),a=hn.create({id:hn.createId(i.id)}),c=Zt.create({id:Zt.createId(i.id),pageId:i.id});return{data:{newPage:i,newTabPageState:c,newCamera:a}}},{do:({newPage:n,newTabPageState:r,newCamera:o})=>{this.store.put([n,o,r])},undo:({newPage:n,newTabPageState:r,newCamera:o})=>{this.getPages().length!==1&&this.store.remove([r.id,n.id,o.id])}}));m(this,"_deletePage",this.history.createCommand("delete_page",n=>{if(this.getInstanceState().isReadonly)return null;const r=this.getPages();if(r.length===1)return null;const o=this.getPage(n),s=this.getPageStates().filter(i=>i.pageId===n);if(!o)return null;if(n===this.getCurrentPageId()){const i=r.findIndex(c=>c.id===n),a=r[i-1]??r[i+1];this.setCurrentPage(a.id)}return{data:{id:n,deletedPage:o,deletedPageStates:s}}},{do:({deletedPage:n,deletedPageStates:r})=>{const o=this.getPages();if(o.length!==1){if(n.id===this.getCurrentPageId()){const s=o.findIndex(a=>a.id===n.id),i=o[s-1]??o[s+1];this.setCurrentPage(i.id)}this.store.remove(r.map(s=>s.id)),this.store.remove([n.id]),this.updateRenderingBounds()}},undo:({deletedPage:n,deletedPageStates:r})=>{this.store.put([n]),this.store.put(r),this.updateRenderingBounds()}}));m(this,"_createAssets",this.history.createCommand("createAssets",n=>this.getInstanceState().isReadonly||n.length<=0?null:{data:{assets:n}},{do:({assets:n})=>{this.store.put(n)},undo:({assets:n})=>{this.store.remove(n.map(r=>r.id))}}));m(this,"_updateAssets",this.history.createCommand("updateAssets",n=>this.getInstanceState().isReadonly||n.length<=0?void 0:{data:{snapshots:{},assets:n}},{do:({assets:n,snapshots:r})=>{this.store.put(n.map(o=>{const s=this.store.get(o.id);return r[o.id]=s,{...s,...o}}))},undo:({snapshots:n})=>{this.store.put(Object.values(n))}}));m(this,"_deleteAssets",this.history.createCommand("deleteAssets",n=>{if(this.getInstanceState().isReadonly||n.length<=0)return;const r=fe(n.map(o=>this.store.get(o)));return{data:{ids:n,prev:r}}},{do:({ids:n})=>{this.store.remove(n)},undo:({prev:n})=>{this.store.put(n)}}));m(this,"_parentIdsToChildIds");m(this,"_childIdsCache",new zf);m(this,"_createShapes",this.history.createCommand("createShapes",n=>{if(this.getInstanceState().isReadonly||n.length<=0)return null;const r=this.getCurrentPageShapeIds();if(n.length+r.size>Io){_d(this);return}return n.length===0?null:{data:{currentPageId:this.getCurrentPageId(),partials:n.map(s=>s.id?s:{...s,id:Be()})}}},{do:({partials:n})=>{var a,c;const r=this.getFocusedGroupId(),o=this.getCurrentPageShapesSorted();n=n.map(l=>{if(!l.parentId||!(this.store.has(l.parentId)||n.some(u=>u.id===l.parentId))){let u=this.getFocusedGroupId();for(let p=o.length-1;p>=0;p--){const f=o[p];if(this.getShapeUtil(f).canReceiveNewChildrenOfType(f,l.type)&&this.isPointInShape(f,{x:l.x??0,y:l.y??0},{margin:0,hitInside:!0})){u=f.id;break}}const d=l.parentId;if(u===l.id&&(u=r),u!==d&&(l={...l},l.parentId=u,Kn(u))){const p=this.getPointInShapeSpace(this.getShape(u),{x:l.x??0,y:l.y??0});l.x=p.x,l.y=p.y,l.rotation=-this.getShapePageTransform(u).rotation()+(l.rotation??0)}}return l});const s=new Map,i=[];for(const l of n){const u=this.getShapeUtil(l);let d=l.index;if(!d){const g=l.parentId??r;s.has(g)||s.set(g,this.getHighestIndexForParent(g)),d=s.get(g),s.set(g,$o(d))}const p=u.getDefaultProps();for(const[g,w]of this.styleProps[l.type])p[w]=this.getStyleForNextShape(g);let f=this.store.schema.types.shape.create({...l,index:d,opacity:l.opacity??this.getInstanceState().opacityForNextShape,parentId:l.parentId??r,props:"props"in l?{...p,...l.props}:p});if(f.index===void 0)throw Error("no index!");const y=(c=(a=this.getShapeUtil(f)).onBeforeCreate)==null?void 0:c.call(a,f);y&&(f=y),i.push(f)}i.forEach(l=>{l.meta={...this.getInitialMetaForShape(l),...l.meta}}),this.store.put(i)},undo:({partials:n})=>{this.store.remove(n.map(r=>r.id))}}));m(this,"animatingShapes",new Map);m(this,"_updateShapes",this.history.createCommand("updateShapes",(n,r)=>{if(this.getInstanceState().isReadonly)return null;const o={},s={};let i,a;for(let c=0,l=n.length;c<l;c++){const u=n[c];u&&(i=this.getShape(u.id),i&&(a=Qc(i,u),a!==i&&(o[i.id]=i,s[i.id]=a)))}return{data:{snapshots:o,updates:s},...r}},{do:({updates:n})=>{this.store.put(bt(n).map(r=>{var s,i;const o=this.store.get(r.id);if(o){const a=(i=(s=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:i.call(s,o,r);if(a)return a}return r}))},undo:({snapshots:n})=>{this.store.put(Object.values(n))},squash(n,r){return{snapshots:{...r.snapshots,...n.snapshots},updates:{...n.updates,...r.updates}}}}));m(this,"_deleteShapes",this.history.createCommand("delete_shapes",n=>{if(this.getInstanceState().isReadonly||n.length===0)return null;const r=[...this.getCurrentPageState().selectedShapeIds],o=new Set(n);for(const l of n)this.visitDescendants(l,u=>{o.add(u)});const s=[...o],i=this._getArrowBindingsIndex().get(),a=fe(s.flatMap(l=>{const u=this.getShape(l),d=i[l];return d&&d.length>0?d.map(({arrowId:p})=>this.getShape(p)).concat(u):u})),c=r.filter(l=>!o.has(l));return{data:{deletedIds:s,snapshots:a,prevSelectedShapeIds:r,postSelectedShapeIds:c}}},{do:({deletedIds:n,postSelectedShapeIds:r})=>{this.store.remove(n),this.store.update(this.getCurrentPageState().id,o=>({...o,selectedShapeIds:r}))},undo:({snapshots:n,prevSelectedShapeIds:r})=>{this.store.put(n),this.store.update(this.getCurrentPageState().id,o=>({...o,selectedShapeIds:r}))}}));m(this,"externalAssetContentHandlers",{file:null,url:null});m(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});m(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,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,pointerVelocity:new P});m(this,"_clickManager",new Y4(this));m(this,"_prevCursor","default");m(this,"_shiftKeyTimeout",-1);m(this,"_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,code:"ShiftLeft"})});m(this,"_altKeyTimeout",-1);m(this,"_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,code:"AltLeft"})});m(this,"_ctrlKeyTimeout",-1);m(this,"_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,code:"ControlLeft"})});m(this,"_restoreToolId","select");m(this,"_pinchStart",1);m(this,"_didPinch",!1);m(this,"_selectedShapeIdsAtPointerDown",[]);m(this,"_longPressTimeout",-1);m(this,"capturedPointerId",null);m(this,"dispatch",n=>(this._pendingEventsForNextTick.push(n),n.type==="pointer"&&n.name==="pointer_move"||n.type==="wheel"||n.type==="pinch"||this._flushEventsForTick(0),this));m(this,"_pendingEventsForNextTick",[]);m(this,"_flushEventForTick",n=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=n;if(n.type==="misc"){(n.name==="cancel"||n.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}}))),this.root.handleEvent(n);return}n.shiftKey?(clearInterval(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!n.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=setTimeout(this._setShiftKeyTimeout,150)),n.altKey?(clearInterval(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!n.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=setTimeout(this._setAltKeyTimeout,150)),n.ctrlKey?(clearInterval(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!n.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,originScreenPoint:i,currentPagePoint:a,currentScreenPoint:c}=r;switch(r.isPointing||(r.isDragging=!1),o){case"pinch":{if(!this.getInstanceState().canMoveCamera)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(n),n.name){case"pinch_start":{if(r.isPinching)return;r.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds()),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:l=1},delta:{x:u,y:d}}=n,{screenBounds:p}=this.store.unsafeGetWithoutCapture(In),{x:f,y}=P.SubXY(n.point,p.x,p.y),{x:g,y:w,z:S}=this.getCamera(),v=Math.min(xs,Math.max(qc,l));this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this._setCamera({x:g+u/S-f/S+f/v,y:w+d/S-y/S+y/v,z:v},!0);return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:l}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown,{squashing:!0}),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,this.once("tick",()=>{this._didPinch||this.setSelectedShapes(l,{squashing:!0})}));return}}}case"wheel":{if(!this.getInstanceState().canMoveCamera)return;if(this._updateInputsFromEvent(n),!this.getIsMenuOpen()){if(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),r.ctrlKey){const{x:p,y:f}=this.inputs.currentScreenPoint,{x:y,y:g,z:w}=this.getCamera(),S=Math.min(xs,Math.max(qc,w+(n.delta.z??0)*w));this._setCamera({x:y+(p/S-p)-(p/w-p),y:g+(f/S-f)-(f/w-f),z:S},!0);return}const{x:l,y:u,z:d}=this.getCamera();this._setCamera({x:l+n.delta.x/d,y:u+n.delta.y/d,z:d},!0),!r.isDragging&&r.isPointing&&P.Dist2(s,a)>(this.getInstanceState().isCoarsePointer?NS:iu)/this.getZoomLevel()&&(clearTimeout(this._longPressTimeout),r.isDragging=!0)}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(n);const{isPen:l}=n;switch(n.name){case"pointer_down":{if(this.clearOpenMenus(),this._longPressTimeout=setTimeout(()=>{this.dispatch({...n,name:"long_press"})},N5),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),n.button===0&&(this.capturedPointerId=n.pointerId),r.buttons.add(n.button),r.isPointing=!0,r.isDragging=!1,this.getInstanceState().isPenMode){if(!l)return}else l&&this.updateInstanceState({isPenMode:!0});if(n.button===5?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):n.button===1&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;i.setTo(c),s.setTo(a);break}case"pointer_move":{if(!l&&this.getInstanceState().isPenMode)return;if(this.inputs.isPanning&&this.inputs.isPointing){clearTimeout(this._longPressTimeout);const{currentScreenPoint:u,previousScreenPoint:d}=this.inputs;this.pan(P.Sub(u,d));return}!r.isDragging&&r.isPointing&&P.Dist2(s,a)>(this.getInstanceState().isCoarsePointer?NS:iu)/this.getZoomLevel()&&(clearTimeout(this._longPressTimeout),r.isDragging=!0);break}case"pointer_up":{if(r.buttons.delete(n.button),r.isPointing=!1,r.isDragging=!1,this.getIsMenuOpen()||!l&&this.getInstanceState().isPenMode)return;this.capturedPointerId===n.pointerId&&(this.capturedPointerId=null,n.button=0),r.isPanning?n.button===1?this.inputs.keys.has(" ")?(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:Sh}),this.setCursor({type:"grab",rotation:0})):(r.isPanning=!1,this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:Sh}),this.setCursor({type:this._prevCursor,rotation:0})):n.button===0&&(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:Sh}),this.setCursor({type:"grab",rotation:0})):n.button===5&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(n.key==="ShiftRight"&&(n.key="ShiftLeft"),n.key==="AltRight"&&(n.key="AltLeft"),n.code==="ControlRight"&&(n.code="ControlLeft"),n.name){case"key_down":{r.keys.add(n.code),!n.ctrlKey&&n.code==="Space"&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0}));break}case"key_up":{r.keys.delete(n.code),n.code==="Space"&&!this.inputs.buttons.has(1)&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}));break}}break}}if(n.type==="pointer"&&(n.button===1?n.name="middle_click":n.button===2&&(n.name="right_click"),n.isPen===this.getInstanceState().isPenMode))switch(n.name){case"pointer_down":{const l=this._clickManager.transformPointerDownEvent(n);if(n.name!==l.name){this.root.handleEvent(n),this.emit("event",n),this.root.handleEvent(l),this.emit("event",l);return}break}case"pointer_up":{clearTimeout(this._longPressTimeout);const l=this._clickManager.transformPointerUpEvent(n);if(n.name!==l.name){this.root.handleEvent(n),this.emit("event",n),this.root.handleEvent(l),this.emit("event",l);return}break}case"pointer_move":{this._clickManager.handleMove();break}}return this.root.handleEvent(n),this.emit("event",n),this});this.store=n,this.snaps=new Uf(this),this.user=new Hr(r??E2(),c??!1),this.getContainer=i??(()=>document.body),this.textMeasure=new fz(this),this._tickManager=new gz(this);class l extends bh{}m(l,"initial",a??""),this.root=new l(this),this.root.children={};const u=$2(o),d={},p={},f=new Map;for(const b of u){const E=new b(this);d[b.type]=E;const C=ck(b.props??{});p[b.type]=C;for(const I of C.keys())if(!f.has(I.id))f.set(I.id,I);else if(f.get(I.id)!==I)throw Error(`Multiple style props with id "${I.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=d,this.styleProps=p;for(const b of[...s]){if(ro(this.root.children,b.id))throw Error(`Can't override tool with id "${b.id}"`);this.root.children[b.id]=new b(this,this.root)}this.environment=new X4(this),this.scribbles=new J4(this);const y=new Set,g=b=>{var Q;const E=this.getShape(b);if(!E)return;const{start:C,end:I}=E.props,_=C.type==="binding"?this.getShape(C.boundShapeId):void 0,k=I.type==="binding"?this.getShape(I.boundShapeId):void 0,$=this.getAncestorPageId(E);if(!$)return;let T;if(_&&k)T=this.findCommonAncestor([_,k])??$;else if(_||k){const H=(Q=_||k)==null?void 0:Q.parentId;H&&H===E.parentId?T=E.parentId:T=$}else return;T&&T!==E.parentId&&this.reparentShapes([b],T);const O=this.getShape(b);if(!O)throw Error("no reparented arrow");const N=this.getShapeNearestSibling(O,_),F=this.getShapeNearestSibling(O,k);let L;if(N&&F)L=N.index>F.index?N:F;else if(N&&!F)L=N;else if(F&&!N)L=F;else return;let B;const q=this.getSortedChildIdsForParent(L.parentId).map(H=>this.getShape(H)).filter(H=>H.index>L.index);if(q.length){const H=q.find(U=>U.type!=="arrow");if(O.index>L.index&&(!H||O.index<H.index))return;B=kl(L.index,q[0].index)}else B=$o(L.index);B!==O.index&&this.updateShapes([{id:b,type:"arrow",index:B}])},w=(b,E)=>{const{x:C,y:I}=jr(this,b)[E];this.store.put([{...b,props:{...b.props,[E]:{type:"point",x:C,y:I}}}])},S=b=>{for(const E of["start","end"]){const C=b.props[E];if(C.type!=="binding")continue;const I=this.getShape(C.boundShapeId),_=this.getAncestorPageId(b)===this.getAncestorPageId(I);(!I||!_)&&w(b,E)}g(b.id)},v=(b,E)=>{let C=null;const I=b.selectedShapeIds.filter($=>!E.has($));I.length!==b.selectedShapeIds.length&&(C||(C={...b}),C.selectedShapeIds=I);const _=b.erasingShapeIds.filter($=>!E.has($));_.length!==b.erasingShapeIds.length&&(C||(C={...b}),C.erasingShapeIds=_),b.hoveredShapeId&&E.has(b.hoveredShapeId)&&(C||(C={...b}),C.hoveredShapeId=null),b.editingShapeId&&E.has(b.editingShapeId)&&(C||(C={...b}),C.editingShapeId=null);const k=b.hintingShapeIds.filter($=>!E.has($));return k.length!==b.hintingShapeIds.length&&(C||(C={...b}),C.hintingShapeIds=k),b.focusedGroupId&&E.has(b.focusedGroupId)&&(C||(C={...b}),C.focusedGroupId=null),C};if(this.sideEffects=new ez(this),this.sideEffects.registerBatchCompleteHandler(()=>{var b;for(const E of y){y.delete(E);const C=this.getShape(E);if(!C)continue;const I=this.getShapeUtil(C),_=(b=I.onChildrenChange)==null?void 0:b.call(I,C);_!=null&&_.length&&this.updateShapes(_,{squashing:!0})}this.emit("update")}),this.sideEffects.registerBeforeDeleteHandler("shape",b=>{b.parentId&&Kn(b.parentId)&&y.add(b.parentId);const E=this._getArrowBindingsIndex().get()[b.id];if(E!=null&&E.length)for(const{arrowId:_,handleId:k}of E){const $=this.getShape(_);$&&w($,k)}const C=new Set([b.id]),I=fe(this.getPageStates().map(_=>v(_,C)));I.length&&this.store.put(I)}),this.sideEffects.registerBeforeDeleteHandler("page",b=>{var _;if(this.getInstanceState().currentPageId!==b.id)return;const E=(_=this.getPages().find(k=>k.id!==b.id))==null?void 0:_.id;if(!E)return;this.store.put([{...this.getInstanceState(),currentPageId:E}]);const C=hn.createId(b.id),I=Zt.createId(b.id);this.store.remove([C,I])}),this.sideEffects.registerAfterChangeHandler("shape",(b,E)=>{if(this.isShapeOfType(E,"arrow")&&S(E),b.parentId!==E.parentId){const C=I=>{const _=this._getArrowBindingsIndex().get()[I];if(_!=null&&_.length)for(const k of _)g(k.arrowId)};C(E.id),this.visitDescendants(E.id,C)}if(b.parentId!==E.parentId&&bn(E.parentId)){const C=new Set([b.id]);this.visitDescendants(b.id,I=>{C.add(I)});for(const I of this.getPageStates()){if(I.pageId===E.parentId)continue;const _=v(I,C);_&&this.store.put([_])}}b.parentId&&Kn(b.parentId)&&y.add(b.parentId),E.parentId!==b.parentId&&Kn(E.parentId)&&y.add(E.parentId)}),this.sideEffects.registerAfterChangeHandler("instance_page_state",(b,E)=>{if((b==null?void 0:b.selectedShapeIds)!==(E==null?void 0:E.selectedShapeIds)){const C=E.selectedShapeIds.filter(_=>{var $,T;let k=($=this.getShape(_))==null?void 0:$.parentId;for(;Kn(k);){if(E.selectedShapeIds.includes(k))return!1;k=(T=this.getShape(k))==null?void 0:T.parentId}return!0});let I=null;if(C.length>0){const _=this.findCommonAncestor(fe(C.map(k=>this.getShape(k))),k=>this.isShapeOfType(k,"group"));_&&(I=_)}else E!=null&&E.focusedGroupId&&(I=E.focusedGroupId);(C.length!==E.selectedShapeIds.length||I!==E.focusedGroupId)&&this.store.put([{...E,selectedShapeIds:C,focusedGroupId:I??null}])}}),this.sideEffects.registerAfterCreateHandler("shape",b=>{this.isShapeOfType(b,"arrow")&&S(b)}),this.sideEffects.registerAfterCreateHandler("page",b=>{const E=hn.createId(b.id),C=Zt.createId(b.id);this.store.has(E)||this.store.put([hn.create({id:E})]),this.store.has(C)||this.store.put([Zt.create({id:C,pageId:b.id})])}),this._currentPageShapeIds=K4(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=H4(this.store),this.disposables.add(this.store.listen(b=>{this.emit("change",b)})),this.store.ensureStoreIsUsable(),this._setInstancePageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]},{ephemeral:!0}),a&&this.root.children[a]===void 0)throw Error(`No state found for initialState "${a}".`);this.root.enter(void 0,"initial"),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.updateRenderingBounds(),this.on("tick",this._flushEventsForTick),requestAnimationFrame(()=>{this._tickManager.start()})}dispose(){this.disposables.forEach(n=>n()),this.disposables.clear()}getShapeUtil(n){const r=typeof n=="string"?n:n.type,o=Lr(this.shapeUtils,r);return _t(o,`No shape util found for type "${r}"`),o}undo(){return this._flushEventsForTick(0),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(n,r,o){return this.history.mark(n,r,o),this}bail(){return this.history.bail(),this}bailToMark(n){return this.history.bailToMark(n),this}batch(n){return this.history.batch(n),this}_getArrowBindingsIndex(){return z4(this)}getArrowsBoundTo(n){return this._getArrowBindingsIndex().get()[n]||Do}getArrowInfoCache(){return this.store.createComputedCache("arrow infoCache",n=>Zc(n)?Al(this,n):xm(this,n))}getArrowInfo(n){const r=typeof n=="string"?n:n.id;return this.getArrowInfoCache().get(r)}annotateError(n,{origin:r,willCrashApp:o,tags:s,extras:i}){const a=this.createErrorAnnotations(r,o);return j0(n,{tags:{...a.tags,...s},extras:{...a.extras,...i}}),o&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(n,r){try{const o=this.getEditingShapeId();return{tags:{origin:n,willCrashApp:r},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:o?this.getShape(o):void 0,inputs:this.inputs}}}catch{return{tags:{origin:n,willCrashApp:r},extras:{}}}}getCrashingError(){return this._crashingError}crash(n){return this._crashingError=n,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:n}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(n){const r=n.split(".").reverse();let o=this.root;for(;r.length>0;){const s=r.pop();if(!s)return!0;const i=o.getCurrent();if((i==null?void 0:i.id)===s){if(r.length===0)return!0;o=i;continue}else return!1}return!1}isInAny(...n){return n.some(r=>this.isIn(r))}setCurrentTool(n,r={}){return this.root.transition(n,r),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const n=this.getCurrentTool();return n?n.getCurrentToolIdMask()??n.id:""}getStateDescendant(n){var s;const r=n.split(".").reverse();let o=this.root;for(;r.length>0;){const i=r.pop();if(!i)return o;const a=(s=o.children)==null?void 0:s[i];if(!a)return;o=a}return o}getDocumentSettings(){return this.store.get(RS)}updateDocumentSettings(n){return this.store.put([{...this.getDocumentSettings(),...n}]),this}getInstanceState(){return this.store.get(In)}updateInstanceState(n,r){return this._updateInstanceState(n,{ephemeral:!0,squashing:!0,...r}),n.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),n.isChangingStyle===!0&&(this._isChangingStyleTimeout=setTimeout(()=>{this.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},2e3))),this}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(n){const r=new Set(this.getOpenMenus());return r.has(n)||(r.add(n),this.updateInstanceState({openMenus:[...r]})),this}deleteOpenMenu(n){const r=new Set(this.getOpenMenus());return r.has(n)&&(r.delete(n),this.updateInstanceState({openMenus:[...r]})),this}clearOpenMenus(){return this.getOpenMenus().length&&this.updateInstanceState({openMenus:[]}),this}getIsMenuOpen(){return this.getOpenMenus().length>0}getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return Zt.createId(this.getCurrentPageId())}updateCurrentPageState(n,r){return this._setInstancePageState(n,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:n}=this.getCurrentPageState();return fe(n.map(r=>this.store.get(r)))}setSelectedShapes(n,r){const o=n.map(s=>typeof s=="string"?s:s.id);return this._setSelectedShapes(o,r),this}select(...n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);return this.setSelectedShapes(r),this}deselect(...n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=this.getSelectedShapeIds();return o.length>0&&r.length>0&&this.setSelectedShapes(o.filter(s=>!r.includes(s))),this}selectAll(){const n=this.getSortedChildIdsForParent(this.getCurrentPageId());return n.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(n)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var n;return((n=this.getOnlySelectedShape())==null?void 0:n.id)??null}getOnlySelectedShape(){const n=this.getSelectedShapes();return n.length===1?n[0]:null}getSelectionPageBounds(){const n=this.getCurrentPageState().selectedShapeIds;return n.length===0?null:ne.Common(fe(n.map(r=>this.getShapePageBounds(r))))}getSelectionRotation(){const n=this.getSelectedShapeIds();let r=!1,o=0;for(let s=0,i=n.length;s<i;s++){const a=this.getShapePageTransform(n[s]);if(a)if(r){if(a.rotation()!==o)return 0}else r=!0,o=a.rotation()}return o}getSelectionRotatedPageBounds(){const n=this.getSelectedShapeIds();if(n.length===0)return;const r=this.getSelectionRotation();if(r===0)return this.getSelectionPageBounds();if(n.length===1){const s=this.getShapeGeometry(n[0]).bounds.clone(),i=this.getShapePageTransform(n[0]);return s.point=i.applyToPoint(s.point),s}const o=ne.FromPoints(this.getSelectedShapeIds().flatMap(s=>{const i=this.getShapePageTransform(s);return i?i.applyToPoints(this.getShapeGeometry(s).bounds.corners):[]}).map(s=>s.rot(-r)));return o.point=o.point.rot(r),o}getSelectionRotatedScreenBounds(){const n=this.getSelectionRotatedPageBounds();if(!n)return;const{x:r,y:o}=this.pageToScreen(n.point),s=this.getZoomLevel();return new ne(r,o,n.width*s,n.height*s)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const n=this.getFocusedGroupId();return n?this.getShape(n):void 0}setFocusedGroup(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==null){const o=this.getShape(r);if(!o)throw Error(`Editor.setFocusedGroup: Shape with id ${r} does not exist`);if(!this.isShapeOfType(o,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${o.type}`)}return r===this.getFocusedGroupId()?this:(this._setFocusedGroupId(r),this)}popFocusedGroupId(){const n=this.getFocusedGroup();if(n){const r=this.findShapeAncestor(n,o=>this.isShapeOfType(o,"group"));this.setFocusedGroup((r==null?void 0:r.id)??null),this.select(n.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const n=this.getEditingShapeId();return n?this.getShape(n):void 0}setEditingShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==this.getEditingShapeId()){if(r){const o=this.getShape(r);if(o&&this.getShapeUtil(o).canEdit(o))return this._setInstancePageState({editingShapeId:r}),this}this._setInstancePageState({editingShapeId:null})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const n=this.getHoveredShapeId();return n?this.getShape(n):void 0}setHoveredShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;return r===this.getHoveredShapeId()?this:(this.updateCurrentPageState({hoveredShapeId:r},{ephemeral:!0}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const n=this.getHintingShapeIds();return fe(n.map(r=>this.getShape(r)))}setHintingShapes(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:Mp(r)},{ephemeral:!0}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const n=this.getErasingShapeIds();return fe(n.map(r=>this.getShape(r)))}setErasingShapes(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id);r.sort();const o=this.getErasingShapeIds();if(r.length===o.length){for(let s=0;s<r.length;s++)if(r[s]!==o[s]){this._setInstancePageState({erasingShapeIds:r},{ephemeral:!0});break}}else this._setInstancePageState({erasingShapeIds:r},{ephemeral:!0});return this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==this.getCroppingShapeId())if(!r)this.updateCurrentPageState({croppingShapeId:null});else{const o=this.getShape(r),s=this.getShapeUtil(o);o&&s.canCrop(o)&&this.updateCurrentPageState({croppingShapeId:r})}return this}getCameraId(){return hn.createId(this.getCurrentPageId())}getCamera(){return this.store.get(this.getCameraId())}getZoomLevel(){return this.getCamera().z}_setCamera(n,r=!1){const o=this.getCamera();return o.x===n.x&&o.y===n.y&&o.z===n.z?this:(this.batch(()=>{const s={...o,...n};this.store.put([s]);const{currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:c}=this.store.unsafeGetWithoutCapture(In);if(i.x/s.z-s.x!==a.x||i.y/s.z-s.y!==a.y){const l={type:"pointer",target:"canvas",name:"pointer_move",point:P.AddXY(i,c.x,c.y),pointerId:x1.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1};r?this._flushEventForTick(l):this.dispatch(l)}this._tickCameraState()}),this)}setCamera(n,r){const o=Number.isFinite(n.x)?n.x:0,s=Number.isFinite(n.y)?n.y:0,i=Number.isFinite(n.z)?n.z:this.getZoomLevel();if(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),r){const{width:a,height:c}=this.getViewportScreenBounds();return this._animateToViewport(new ne(-o,-s,a/i,c/i),r)}else this._setCamera({x:o,y:s,z:i});return this}centerOnPoint(n,r){if(!this.getInstanceState().canMoveCamera)return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera({x:-(n.x-o/2),y:-(n.y-s/2),z:this.getCamera().z},r),this}zoomToContent(n={duration:220}){const r=this.getSelectionPageBounds()??this.getCurrentPageBounds();return r&&this.zoomToBounds(r,{targetZoom:Math.min(1,this.getZoomLevel()),...n}),this}zoomToFit(n){if(!this.getInstanceState().canMoveCamera)return this;const r=[...this.getCurrentPageShapeIds()];if(r.length<=0)return this;const o=ne.Common(fe(r.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(o,n),this}resetZoom(n=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera(),{x:a,y:c}=n;return this.setCamera({x:o+(a/1-a)-(a/i-a),y:s+(c/1-c)-(c/i-c),z:1},r),this}zoomIn(n=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();let a=xs;for(let u=1;u<ta.length;u++){const d=ta[u-1],p=ta[u];if(!(p-i<=(p-d)/2)){a=p;break}}const{x:c,y:l}=n;return this.setCamera({x:o+(c/a-c)-(c/i-c),y:s+(l/a-l)-(l/i-l),z:a},r),this}zoomOut(n=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();let a=qc;for(let u=ta.length-1;u>0;u--){const d=ta[u-1],p=ta[u];if(!(p-i>=(p-d)/2)){a=d;break}}const{x:c,y:l}=n;return this.setCamera({x:o+(c/a-c)-(c/i-c),y:s+(l/a-l)-(l/i-l),z:a},r),this}zoomToSelection(n){if(!this.getInstanceState().canMoveCamera)return this;const r=this.getSelectionPageBounds();return r?(this.zoomToBounds(r,{targetZoom:Math.max(1,this.getZoomLevel()),...n}),this):this}panZoomIntoView(n,r){if(!this.getInstanceState().canMoveCamera)return this;if(n.length<=0)return this;const o=ne.Common(fe(n.map(i=>this.getShapePageBounds(i)))),s=this.getViewportPageBounds();if(s.h<o.h||s.w<o.w)return this.zoomToBounds(o,{targetZoom:this.getCamera().z,...r}),this;{const i=this.getViewportPageBounds().clone().expandBy(-32/this.getZoomLevel());let a=0,c=0;i.maxY<o.maxY?c=i.maxY-o.maxY:i.minY>o.minY&&(c=i.minY-o.minY),i.maxX<o.maxX?a=i.maxX-o.maxX:i.minX>o.minX&&(a=i.minX-o.minX);const l=this.getCamera();this.setCamera({x:l.x+a,y:l.y+c,z:l.z},r)}return this}zoomToBounds(n,r){if(!this.getInstanceState().canMoveCamera)return this;const o=this.getViewportScreenBounds(),s=(r==null?void 0:r.inset)??Math.min(256,o.width*.28);let i=Ns(Math.min((o.width-s)/n.width,(o.height-s)/n.height),qc,xs);return(r==null?void 0:r.targetZoom)!==void 0&&(i=Math.min(r.targetZoom,i)),this.setCamera({x:-n.minX+(o.width-n.width*i)/2/i,y:-n.minY+(o.height-n.height*i)/2/i,z:i},r),this}pan(n,r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();return this.setCamera({x:o+n.x/i,y:s+n.y/i,z:i},r),this._flushEventsForTick(0),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(n){if(!this._viewportAnimation)return;const r=()=>{this.removeListener("tick",this._animateViewport),this.removeListener("stop-camera-animation",r),this._viewportAnimation=null};this.once("stop-camera-animation",r),this._viewportAnimation.elapsed+=n;const{elapsed:o,easing:s,duration:i,start:a,end:c}=this._viewportAnimation;if(o>i){this._setCamera({x:-c.x,y:-c.y,z:this.getViewportScreenBounds().width/c.width}),r();return}const l=i-o,u=s(1-l/i),d=a.minX+(c.minX-a.minX)*u,p=a.minY+(c.minY-a.minY)*u,f=a.maxX+(c.maxX-a.maxX)*u;this._setCamera({x:-d,y:-p,z:this.getViewportScreenBounds().width/(f-d)})}_animateToViewport(n,r={}){const{duration:o=0,easing:s=nn.easeInOutCubic}=r,i=this.user.getAnimationSpeed(),a=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),o===0||i===0?this._setCamera({x:-n.x,y:-n.y,z:this.getViewportScreenBounds().width/n.width}):(this._viewportAnimation={elapsed:0,duration:o/i,easing:s,start:a.clone(),end:n.clone()},this.addListener("tick",this._animateViewport),this)}slideCamera(n={}){if(!this.getInstanceState().canMoveCamera)return this;if(this.stopCameraAnimation(),this.user.getAnimationSpeed()===0)return this;const{speed:o,friction:s,direction:i,speedThreshold:a=.01}=n;let c=Math.min(o,1);const l=()=>{this.removeListener("tick",u),this.removeListener("stop-camera-animation",l)};this.once("stop-camera-animation",l);const u=d=>{const{x:p,y:f,z:y}=this.getCamera(),g=P.Mul(i,c*d/y);c*=1-s,c<a?l():this._setCamera({x:p+g.x,y:f+g.y,z:y})};return this.addListener("tick",u),this}animateToUser(n){const r=this.getCollaborators().find(o=>o.userId===n);return r?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const o=r.currentPageId===this.getCurrentPageId();o||this.setCurrentPage(r.currentPageId);const s=o?{duration:500}:void 0;this.centerOnPoint(r.cursor,s);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,n]}),setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],c=a.indexOf(n);c<0||(a.splice(c,1),this.updateInstanceState({highlightedUserIds:a}))},Kk)}),this):this}animateToShape(n,r=M5){if(!this.getInstanceState().canMoveCamera)return this;const o=this.getViewportScreenBounds().clone().expandBy(-32),s=o.width/o.height,i=this.getShapePageBounds(n);if(!i)return this;const a=i.width/i.height,c=i.clone(),l=i.width/o.width;return c.width+=(o.minX+o.maxX)*l,c.height+=(o.minY+o.maxY)*l,c.x-=o.minX*l,c.y-=o.minY*l,a>s?(c.height=i.width/s,c.y-=(c.height-i.height)/2):(c.width=i.height*s,c.x-=(c.width-i.width)/2),this._animateToViewport(c,r)}updateViewportScreenBounds(n,r=!1){n.width=Math.max(n.width,1),n.height=Math.max(n.height,1);const o=[n.minY!==0,document.body.scrollWidth!==n.maxX,document.body.scrollHeight!==n.maxY,n.minX!==0],s=n.equals(this.getViewportScreenBounds()),{_willSetInitialBounds:i}=this;if(s)this._willSetInitialBounds=!1;else if(i)this._willSetInitialBounds=!1,this.updateInstanceState({screenBounds:n.toJson(),insets:o},{squashing:!0,ephemeral:!0});else if(r&&!this.getInstanceState().followingUserId){const a=this.getViewportPageCenter();this.updateInstanceState({screenBounds:n.toJson(),insets:o},{squashing:!0,ephemeral:!0}),this.centerOnPoint(a)}else this.updateInstanceState({screenBounds:n.toJson(),insets:o},{squashing:!0,ephemeral:!0});return this._tickCameraState(),this.updateRenderingBounds(),this}getViewportScreenBounds(){const{x:n,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new ne(n,r,o,s)}getViewportScreenCenter(){const n=this.getViewportScreenBounds();return new P(n.midX-n.minX,n.midY-n.minY)}getViewportPageBounds(){const{w:n,h:r}=this.getViewportScreenBounds(),{x:o,y:s,z:i}=this.getCamera();return new ne(-o,-s,n/i,r/i)}getViewportPageCenter(){return this.getViewportPageBounds().center}screenToPage(n){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(In),{x:o,y:s,z:i=1}=this.getCamera();return{x:(n.x-r.x)/i-o,y:(n.y-r.y)/i-s,z:n.z??.5}}pageToScreen(n){const r=this.getViewportScreenBounds(),{x:o,y:s,z:i=1}=this.getCamera();return{x:(n.x+o)*i+r.x,y:(n.y+s)*i+r.y,z:n.z??.5}}pageToViewport(n){const{x:r,y:o,z:s=1}=this.getCamera();return{x:(n.x+r)*s,y:(n.y+o)*s,z:n.z??.5}}_getCollaboratorsQuery(){return this.store.query.records("instance_presence",()=>({userId:{neq:this.user.getId()}}))}getCollaborators(){const n=this._getCollaboratorsQuery().get();return n.length?[...new Set(n.map(o=>o.userId))].sort().map(o=>n.filter(i=>i.userId===o).sort((i,a)=>a.lastActivityTimestamp-i.lastActivityTimestamp)[0]):Do}getCollaboratorsOnCurrentPage(){const n=this.getCurrentPageId();return this.getCollaborators().filter(r=>r.currentPageId===n)}startFollowingUser(n){const r=this._getCollaboratorsQuery().get().filter(c=>c.userId===n),o=this.user.getId();if(o||console.warn("You should set the userId for the current instance before following a user"),r.some(c=>c.followingUserId===o))return this;Mr(()=>{this.stopFollowingUser(),this.updateInstanceState({followingUserId:n},{ephemeral:!0})});const s=()=>{this.removeListener("frame",a),this.removeListener("stop-following",s)};let i=!1;const a=()=>{const c=[...r].sort((F,L)=>F.lastActivityTimestamp-L.lastActivityTimestamp).pop();if(!c){this.stopFollowingUser();return}const l=c.currentPageId===this.getCurrentPageId(),u=l?P5:1;if(!l){this.stopFollowingUser(),this.setCurrentPage(c.currentPageId),this.startFollowingUser(n);return}const{center:d,width:p,height:f}=this.getViewportPageBounds(),y=ne.From(c.screenBounds),g=y.width/c.camera.z,w=y.height/c.camera.z,S=new P(g/2-c.camera.x,w/2-c.camera.y),v=c.followingUserId===o,b=p+(g-p)*u,E=f+(w-f)*u,C=v?f/E:Math.min(p/b,f/E),I=Ns(this.getCamera().z*C,qc,xs),_=this.getViewportScreenBounds().w/I,k=this.getViewportScreenBounds().h/I,$=S.sub(d),T=P.Add(d,P.Mul($,u)),O=P.Sub(T,d).len(),N=Math.abs(I-this.getCamera().z);if(O<C5&&N<E5){i=!0;return}i&&O<I5&&N<_5||(i=!1,this.stopCameraAnimation(),this._setCamera({x:-(T.x-_/2),y:-(T.y-k/2),z:I}))};return this.once("stop-following",s),this.addListener("frame",a),this}stopFollowingUser(){return this.updateInstanceState({followingUserId:null},{ephemeral:!0}),this.emit("stop-following"),this}getCameraState(){return this._cameraState.get()}getUnorderedRenderingShapes(n){const r=[];let o=Io*2,s=Io;const i=this.getErasingShapeIds(),a=(l,u,d)=>{const p=this.getShape(l);if(!p)return;u*=p.opacity;let f=!1;const y=this.getShapeUtil(p);n&&(f=!d&&i.includes(l),f&&(u*=.32)),r.push({id:l,shape:p,util:y,index:o,backgroundIndex:s,opacity:u}),o+=1,s+=1;const g=this.getSortedChildIdsForParent(l);if(!g.length)return;let w=null;y.providesBackgroundForChildren(p)&&(w=s,s=o,o+=Io);for(const S of g)a(S,u,d||f);w!==null&&(s=w)},c=n?[this.getCurrentPage()]:this.getPages();for(const l of c)for(const u of this.getSortedChildIdsForParent(l.id))a(u,1,!1);return r}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(N3)}getRenderingBounds(){return this._renderingBounds.get()}updateRenderingBounds(){const n=this.getViewportPageBounds();return n.equals(this._renderingBounds.__unsafe__getWithoutCapture())?this:(this._renderingBounds.set(n.clone()),this)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(en)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(n){return this.store.get(typeof n=="string"?n:n.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getCurrentPageShapeIdsSorted(){return Array.from(this.getCurrentPageShapeIds()).sort()}getPageShapeIds(n){const r=typeof n=="string"?n:n.id,o=this.store.query.exec("shape",{parentId:{eq:r}});return this.getShapeAndDescendantIds(o.map(s=>s.id))}setCurrentPage(n,r){const o=typeof n=="string"?n:n.id;return this._setCurrentPageId(o,r),this}updatePage(n,r){return this._updatePage(n,r),this}createPage(n){return this._createPage(n),this}deletePage(n){const r=typeof n=="string"?n:n.id;return this._deletePage(r),this}duplicatePage(n,r=Ho.createId()){if(this.getPages().length>=Gp)return this;const o=typeof n=="string"?n:n.id,s=this.getPage(o);if(!s)return this;const i={...this.getCamera()},a=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.batch(()=>{var u;const c=this.getPages(),l=kl(s.index,(u=c[c.indexOf(s)+1])==null?void 0:u.index);if(this.createPage({name:s.name+" Copy",id:r,index:l}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(n,r,o){const s=typeof n=="string"?n:n.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:s,name:r},o),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(n){return this._createAssets(n),this}updateAssets(n){return this._updateAssets(n),this}deleteAssets(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);return this._deleteAssets(r),this}getAsset(n){return this.store.get(typeof n=="string"?n:n.id)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",n=>this.getShapeUtil(n).getGeometry(n),(n,r)=>n.props===r.props)}getShapeGeometry(n){return this._getShapeGeometryCache().get(typeof n=="string"?n:n.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",n=>{var r,o;return(o=(r=this.getShapeUtil(n)).getHandles)==null?void 0:o.call(r,n)})}getShapeHandles(n){return this._getShapeHandlesCache().get(typeof n=="string"?n:n.id)}getShapeLocalTransform(n){const r=typeof n=="string"?n:n.id,o=this.getShape(r);if(!o)throw Error("Editor.getTransform: shape not found");return oe.Identity().translate(o.x,o.y).rotate(o.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",n=>{if(bn(n.parentId))return this.getShapeLocalTransform(n);const r=this._getShapePageTransformCache().get(n.parentId)??oe.Identity();return oe.Compose(r,this.getShapeLocalTransform(n))})}getShapeParentTransform(n){const r=typeof n=="string"?n:n.id,o=this.getShape(r);return!o||bn(o.parentId)?oe.Identity():this._getShapePageTransformCache().get(o.parentId)??oe.Identity()}getShapePageTransform(n){const r=typeof n=="string"?n:n.id;return this._getShapePageTransformCache().get(r)??oe.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",n=>{const r=this._getShapePageTransformCache().get(n.id);return r?ne.FromPoints(oe.applyToPoints(r,this.getShapeGeometry(n).vertices)):new ne})}getShapePageBounds(n){return this._getShapePageBoundsCache().get(typeof n=="string"?n:n.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",n=>{const r=this._getShapeMaskCache().get(n.id);if(!r)return;if(r.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const o=this._getShapePageTransformCache().get(n.id);return o?`polygon(${oe.applyToPoints(oe.Inverse(o),r).map(i=>`${i.x}px ${i.y}px`).join(",")})`:void 0})}getShapeClipPath(n){return this._getShapeClipPathCache().get(typeof n=="string"?n:n.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",n=>{if(bn(n.parentId))return;const r=this.getShapeAncestors(n.id).filter(s=>this.isShapeOfType(s,"frame"));return r.length===0?void 0:r.map(s=>this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)).reduce((s,i)=>{if(!(i&&s))return;const a=H1(s,i);return a?a.map(P.Cast):[]})})}getShapeMask(n){return this._getShapeMaskCache().get(typeof n=="string"?n:n.id)}getShapeMaskedPageBounds(n){return typeof n!="string"&&(n=n.id),this._getShapeMaskedPageBoundsCache().get(n)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",n=>{const r=this._getShapePageBoundsCache().get(n.id);if(!r)return;const o=this._getShapeMaskCache().get(n.id);if(o){if(o.length===0)return;const{corners:s}=r;if(s.every((a,c)=>a&&P.Equals(a,o[c])))return r.clone();const i=H1(o,s);return i?ne.FromPoints(i):void 0}return r})}getShapeAncestors(n,r=[]){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return r;const i=s.parentId;if(bn(i))return r.reverse(),r;const a=this.store.get(i);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(n,r){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return;const i=s.parentId;if(bn(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(n,r){const o=typeof n=="string"?n:n==null?void 0:n.id,s=o&&this.getShape(o);return s?s.parentId===r?!0:this.hasAncestor(this.getShapeParent(s),r):!1}findCommonAncestor(n,r){var l;if(n.length===0)return;const o=typeof n[0]=="string"?n:n.map(u=>u.id),s=fe(o.map(u=>this.getShape(u)));if(s.length===1){const u=s[0].parentId;return bn(u)?void 0:r?(l=this.findShapeAncestor(s[0],r))==null?void 0:l.id:u}const[i,...a]=s;let c=this.getShapeParent(i);for(;c;){if(r&&!r(c)){c=this.getShapeParent(c);continue}if(a.every(u=>this.hasAncestor(u,c.id)))return c.id;c=this.getShapeParent(c)}}isShapeOrAncestorLocked(n){const r=typeof n=="string"?this.getShape(n):n;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}_notVisibleShapes(){return U4(this)}getCulledShapes(){const n=this._notVisibleShapes().get(),r=this.getSelectedShapeIds(),o=this.getEditingShapeId(),s=new Set(n);return o&&s.delete(o),r.forEach(i=>{s.delete(i)}),s}getCurrentPageBounds(){let n;return this.getCurrentPageShapeIdsSorted().forEach(r=>{const o=this.getShapeMaskedPageBounds(r);o&&(n?n=n.expand(o):n=o.clone())}),n}getSelectedShapeAtPoint(n){const r=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(o=>o.type!=="group"&&r.includes(o.id)).reverse().find(o=>this.isPointInShape(o,n,{hitInside:!0,margin:0}))}getShapeAtPoint(n,r={}){const o=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:i,margin:a=0,hitLabels:c=!1,hitInside:l=!1,hitFrameInside:u=!1}=r;let d=1/0,p=null,f=1/0,y=null;const g=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(w=>{if(this.isShapeOfType(w,"group"))return!1;const S=this.getShapeMask(w);return S&&!Zn(n,S)?!1:i?i(w):!0});for(let w=g.length-1;w>=0;w--){const S=g[w],v=this.getShapeGeometry(S),b=v instanceof Br,E=this.getPointInShapeSpace(S,n);if((this.isShapeOfType(S,"arrow")||this.isShapeOfType(S,"geo")&&S.props.fill==="none")&&S.props.text.trim()){for(const I of v.children)if(I.isLabel&&I.isPointInBounds(E))return S}if(this.isShapeOfType(S,"frame")){const I=v.distanceToPoint(E,l);if(Math.abs(I)<=a)return y||S;if(v.hitTestPoint(E,0,!0))return y||p||(u?S:void 0);continue}let C;if(b){let I=1/0;for(const _ of v.children){if(_.isLabel&&!c)continue;const k=_.distanceToPoint(E,l);k<I&&(I=k)}C=I}else a===0&&(v.bounds.w<1||v.bounds.h<1)||v.bounds.containsPoint(E,a)?C=v.distanceToPoint(E,l):C=1/0;if(v.isClosed){if(C<=a){if(v.isFilled||b&&v.children[0].isFilled)return y||S;if(this.getShapePageBounds(S).contains(s))continue;if(Math.abs(C)<a)Math.abs(C)<f&&(f=Math.abs(C),y=S);else if(!y){const{area:I}=v;I<d&&(d=I,p=S)}}}else if(C<Ko/o)return S}return y||p||void 0}getShapesAtPoint(n,r={}){return this.getCurrentPageShapes().filter(o=>this.isPointInShape(o,n,r))}isPointInShape(n,r,o={}){const{hitInside:s=!1,margin:i=0}=o,a=typeof n=="string"?n:n.id,c=this.getShapeMask(a);return c&&!Zn(r,c)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(n,r),i,s)}getPointInShapeSpace(n,r){const o=typeof n=="string"?n:n.id;return this._getShapePageTransformCache().get(o).clone().invert().applyToPoint(r)}getPointInParentSpace(n,r){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return new P(0,0);if(bn(s.parentId))return P.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):P.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),n=>this.store.get(n))}getCurrentPageShapesSorted(){const n=[],r=this.getSortedChildIdsForParent(this.getCurrentPageId());for(let o=0,s=r.length;o<s;o++)D2(this,r[o],n);return n}getCurrentPageRenderingShapesSorted(){const n=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:r})=>!n.has(r))}isShapeOfType(n,r){const o=typeof n=="string"?this.getShape(n):n;return o?o.type===r:!1}getShape(n){const r=typeof n=="string"?n:n.id;if(Kn(r))return this.store.get(r)}getShapeParent(n){const r=typeof n=="string"?n:n==null?void 0:n.id;if(!r)return;const o=this.getShape(r);if(!(o===void 0||!Kn(o.parentId)))return this.store.get(o.parentId)}getShapeNearestSibling(n,r){return r?r.parentId===n.parentId?r:this.findShapeAncestor(r,s=>s.parentId===n.parentId):void 0}isShapeInPage(n,r=this.getCurrentPageId()){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return!1;let i=!1;if(s.parentId===r)i=!0;else{let a=this.getShape(s.parentId);e:for(;a;){if(a.parentId===r){i=!0;break e}a=this.getShape(a.parentId)}}return i}getAncestorPageId(n){const r=typeof n=="string"?n:n==null?void 0:n.id,o=r&&this.getShape(r);if(o)return bn(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(n,r,o){const s=typeof n[0]=="string"?n:n.map(y=>y.id);if(s.length===0)return this;const i=[],a=bn(r)?oe.Identity():this.getShapePageTransform(r),c=a.rotation();let l=[];const u=fe(this.getSortedChildIdsForParent(r).map(y=>this.getShape(y)));if(o){const y=u.find(g=>g.index===o);if(y){const g=u[u.indexOf(y)+1];g?l=oc(o,g.index,s.length):l=rm(o,s.length)}else{const g=u.sort(en).find(w=>w.index>o);g?l=oc(o,g.index,s.length):l=rm(o,s.length)}}else{const y=u.length&&u[u.length-1];l=y?rm(y.index,s.length):eu(s.length)}const d=a.clone().invert(),p=fe(s.map(y=>this.getShape(y))),f=p.filter(y=>y.isLocked);f.length&&this.updateShapes(f.map(({id:y,type:g})=>({id:y,type:g,isLocked:!1})));for(let y=0;y<p.length;y++){const g=p[y],w=this.getShapePageTransform(g);if(!w)continue;const S=w.point();if(!S)continue;const v=d.applyToPoint(S),b=w.rotation()-c;i.push({id:g.id,type:g.type,parentId:r,x:v.x,y:v.y,rotation:b,index:l[y],isLocked:g.isLocked})}return this.updateShapes(i),this}getHighestIndexForParent(n){const r=typeof n=="string"?n:n.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const s=this.getShape(o[o.length-1]);return $o(s.index)}getSortedChildIdsForParent(n){const r=typeof n=="string"?n:n.id,o=this._parentIdsToChildIds.get()[r];return o?this._childIdsCache.get(o,()=>o):Do}visitDescendants(n,r){const o=typeof n=="string"?n:n.id,s=this.getSortedChildIdsForParent(o);for(const i of s)r(i)!==!1&&this.visitDescendants(i,r);return this}getShapeAndDescendantIds(n){const r=new Set,o=[...n];for(;o.length>0;){const s=o.pop();if(!s)break;if(!r.has(s)){r.add(s);for(const i of this.getSortedChildIdsForParent(s))o.push(i)}}return r}getDroppingOverShape(n,r=[]){const o=this.getCurrentPageShapesSorted();for(let s=o.length-1;s>=0;s--){const i=o[s];if(this.getSelectedShapeIds().includes(i.id)||!this.getShapeUtil(i).canDropShapes(i,r)||r.find(c=>c.id===i.id||this.hasAncestor(i,c.id)))continue;const a=this.getShapeMaskedPageBounds(i.id);if(a&&a.containsPoint(n)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,n),0,!0))return i}}getOutermostSelectableShape(n,r){const o=typeof n=="string"?n:n.id,s=this.getShape(o);let i=s,a=s;const c=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(c==null?void 0:c.id)!==a.id&&!this.hasAncestor(c,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((c==null?void 0:c.id)===a.id)break;a=this.getShapeParent(a)}return i}rotateShapesBy(n,r){if((typeof n[0]=="string"?n:n.map(i=>i.id)).length<=0)return this;const s=M2({editor:this});return s?(wh({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(n,r){var i,a,c;let o=n;const s=this.getShapeUtil(n);return o=Qc(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=Qc(o,{id:n.id,type:n.type,x:r.x,y:r.y}),o=Qc(o,((a=s.onTranslate)==null?void 0:a.call(s,n,o))??void 0),o=Qc(o,((c=s.onTranslateEnd)==null?void 0:c.call(s,n,o))??void 0),o}nudgeShapes(n,r,o){const s=typeof n[0]=="string"?n:n.map(a=>a.id);if(s.length<=0)return this;const i=[];for(const a of s){const c=this.getShape(a),l=P.From(r),u=this.getShapeParentTransform(c);u&&l.rot(-u.rotation()),i.push(this.getChangesToTranslateShape(c,l.add(c)))}return this.updateShapes(i,{squashing:!0,...o}),this}duplicateShapes(n,r){const o=typeof n[0]=="string"?n:n.map(u=>u.id);if(o.length<=0)return this;const s=new Set(o),i=[],a=[...o];for(;a.length>0;){const u=a.pop();if(!u)break;i.push(u),this.getSortedChildIdsForParent(u).forEach(d=>a.push(d))}i.reverse();const c=new Map(i.map(u=>[u,Be()])),l=fe(i.map(u=>{const d=this.getShape(u);if(!d)return null;const p=c.get(u);let f=0,y=0;if(r&&s.has(u)){const I=this.getShapeParentTransform(d),_=new P(r.x,r.y).rot(-I.rotation());f=_.x,y=_.y}const g=d.parentId??this.getCurrentPageId(),w=this.getSortedChildIdsForParent(g),S=w.indexOf(d.id),v=w[S+1],b=v?this.getShape(v):null,E=b?kl(d.index,b.index):$o(d.index);let C=Ye(d);if(this.isShapeOfType(d,"arrow")&&this.isShapeOfType(C,"arrow")){const I=this.getArrowInfo(d);let _,k;if(d.props.start.type==="binding"&&(_=c.get(d.props.start.boundShapeId),!_))if(I!=null&&I.isValid){const{x:T,y:O}=I.start.point;C.props.start={type:"point",x:T,y:O}}else{const{start:T}=jr(this,d);C.props.start={type:"point",x:T.x,y:T.y}}if(d.props.end.type==="binding"&&(k=c.get(d.props.end.boundShapeId),!k))if(I!=null&&I.isValid){const{x:T,y:O}=I.end.point;C.props.end={type:"point",x:T,y:O}}else{const{end:T}=jr(this,d);C.props.start={type:"point",x:T.x,y:T.y}}const $=Zc(C)?Al(this,C):xm(this,C);if(I!=null&&I.isValid&&($!=null&&$.isValid)&&!Zc(d)){const T=P.Med(I.start.handle,I.end.handle),O=P.Dist(I.middle,T),N=P.Dist($.middle,T);C.props.bend<0?C.props.bend+=N-O:C.props.bend-=N-O}C.props.start.type==="binding"&&_&&(C.props.start.boundShapeId=_),C.props.end.type==="binding"&&k&&(C.props.end.boundShapeId=k)}return C={...C,id:p,x:d.x+f,y:d.y+y,index:E},C}));return l.forEach(u=>{Kn(u.parentId)&&c.has(u.parentId)&&(u.parentId=c.get(u.parentId))}),this.history.batch(()=>{const u=l.length+this.getCurrentPageShapeIds().size>Io;u&&_d(this);const d=u?l.slice(0,Io-this.getCurrentPageShapeIds().size):l,p=d.map(f=>f.id);if(this.createShapes(d),this.setSelectedShapes(p),r!==void 0){const f=this.getSelectionPageBounds(),y=this.getViewportPageBounds();f&&!y.contains(f)&&this.centerOnPoint(f.center,{duration:Qr})}}),this}moveShapesToPage(n,r){const o=typeof n[0]=="string"?n:n.map(c=>c.id);if(o.length===0)return this;if(this.getInstanceState().isReadonly)return this;const s=this.getCurrentPageId();if(r===s)return this;if(!this.store.has(r))return this;const i=this.getContentFromCurrentPage(o);if(!i)return this;if(this.getPageShapeIds(r).size+i.shapes.length>Io)return _d(this,r),this;const a=this.getCamera().z;return this.history.batch(()=>{this.deleteShapes(o),this.setCurrentPage(r),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(i,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:a}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(n){const r=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly||r.length===0)return this;let o=!0,s=!0;const i=[];for(const a of r){const c=this.getShape(a);c&&(i.push(c),c.isLocked?s=!1:o=!1)}return this.batch(()=>{s?(this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):o?this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Ed(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Ed(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Ed(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Ed(this,"toFront",r);return o&&this.updateShapes(o),this}flipShapes(n,r){const o=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;let s=fe(o.map(a=>this.getShape(a)));if(!s.length)return this;s=fe(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(c=>this.getShape(c)):a).flat());const i=ne.Common(fe(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const c=this.getShapeGeometry(a).bounds,l=this.getShapePageTransform(a.id);l&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:c,initialPageTransform:l,initialShape:a,mode:"scale_shape",scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(n,r,o){const s=typeof n[0]=="string"?n:n.map(w=>w.id);if(this.getInstanceState().isReadonly)return this;const i=fe(s.map(w=>this.getShape(w)).filter(w=>!(!w||this.isShapeOfType(w,"arrow")&&(w.props.start.type==="binding"||w.props.end.type==="binding")))),a=i.length;if(o===0&&a<3||a<2)return this;const c=Object.fromEntries(i.map(w=>[w.id,this.getShapePageBounds(w)]));let l,u,d,p;r==="horizontal"?(l="x",u="minX",d="maxX",p="width"):(l="y",u="minY",d="maxY",p="height");let f;if(o===0){const w=[];i.sort((v,b)=>c[v.id][u]-c[b.id][u]);for(let v=0;v<a-1;v++){const b=i[v],E=i[v+1],C=c[b.id],_=c[E.id][u]-C[d],k=w.find($=>$.gap===_);k?k.count++:w.push({gap:_,count:1})}let S=0;w.forEach(v=>{v.count>S&&(S=v.count,f=v.gap)}),S===1&&(f=Math.max(0,w.reduce((v,b)=>v+b.gap*b.count,0)/(a-1)))}else f=o;const y=[];let g=c[i[0].id][d];return i.forEach((w,S)=>{var I,_;if(S===0)return;const v={x:0,y:0};v[l]=g+f-c[w.id][l];const b=this.getShapeParent(w),E=b?P.Rot(v,-this.getShapePageTransform(b).decompose().rotation):v,C=(_=(I=this.getShapeUtil(w)).onTranslateStart)==null?void 0:_.call(I,w);y.push(C?{...C,[l]:w[l]+E[l]}:{id:w.id,type:w.type,[l]:w[l]+E[l]}),g+=c[w.id][p]+f}),this.updateShapes(y),this}packShapes(n,r){var _,k;const o=typeof n[0]=="string"?n:n.map($=>$.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=fe(o.map($=>this.getShape($)).filter($=>!(!$||this.isShapeOfType($,"arrow")&&($.props.start.type==="binding"||$.props.end.type==="binding")))),i={},a={};let c,l,u=0;for(let $=0;$<s.length;$++)c=s[$],l=this.getShapePageBounds(c),i[c.id]=l,a[c.id]=l.clone(),u+=l.width*l.height;const d=ne.Common(fe(Object.values(i))),p=d.width;s.sort(($,T)=>i[T.id].height-i[$.id].height);const f=Math.max(Math.ceil(Math.sqrt(u/.95)),p),y=[new ne(d.x,d.y,f,1/0)];let g=0,w=0,S,v;for(let $=0;$<s.length;$++){c=s[$],l=a[c.id];for(let T=y.length-1;T>=0;T--)if(S=y[T],!(l.width>S.width||l.height>S.height)){l.x=S.x,l.y=S.y,w=Math.max(w,l.maxY),g=Math.max(g,l.maxX),l.width===S.width&&l.height===S.height?(v=y.pop(),T<y.length&&(y[T]=v)):l.height===S.height?(S.x+=l.width+r,S.width-=l.width+r):l.width===S.width?(S.y+=l.height+r,S.height-=l.height+r):(y.push(new ne(S.x+(l.width+r),S.y,S.width-(l.width+r),l.height)),S.y+=l.height+r,S.height-=l.height+r);break}}const b=ne.Common(Object.values(a)),E=P.Sub(d.center,b.center);let C;const I=[];for(let $=0;$<s.length;$++){c=s[$],l=i[c.id],C=a[c.id];const T=P.Sub(C.point,l.point).add(E),O=this.getShapeParentTransform(c);O&&T.rot(-O.rotation());const N={id:c.id,type:c.type,x:c.x+T.x,y:c.y+T.y},F=(k=(_=this.getShapeUtil(c)).onTranslateStart)==null?void 0:k.call(_,{...c,...N});F?I.push({...N,...F}):I.push(N)}return I.length&&this.updateShapes(I),this}alignShapes(n,r){const o=typeof n[0]=="string"?n:n.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=fe(o.map(l=>this.getShape(l))),i=Object.fromEntries(s.map(l=>[l.id,this.getShapePageBounds(l)])),a=ne.Common(fe(Object.values(i))),c=[];return s.forEach(l=>{const u=i[l.id];if(!u)return;const d={x:0,y:0};switch(r){case"top":{d.y=a.minY-u.minY;break}case"center-vertical":{d.y=a.midY-u.minY-u.height/2;break}case"bottom":{d.y=a.maxY-u.minY-u.height;break}case"left":{d.x=a.minX-u.minX;break}case"center-horizontal":{d.x=a.midX-u.minX-u.width/2;break}case"right":{d.x=a.maxX-u.minX-u.width;break}}const p=this.getShapeParent(l),f=p?P.Rot(d,-this.getShapePageTransform(p).decompose().rotation):d;c.push(this.getChangesToTranslateShape(l,P.Add(l,f)))}),this.updateShapes(c),this}distributeShapes(n,r){const o=typeof n[0]=="string"?n:n.map(b=>b.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=fe(o.map(b=>this.getShape(b))),a=Object.fromEntries(i.map(b=>[b.id,this.getShapePageBounds(b)]));let c,l,u,d,p;r==="horizontal"?(c="x",l="minX",u="maxX",d="midX",p="width"):(c="y",l="minY",u="maxY",d="midY",p="height");const f=[],y=i.sort((b,E)=>a[b.id][l]-a[E.id][l])[0],g=i.sort((b,E)=>a[E.id][u]-a[b.id][u])[0],w=a[y.id][d],S=(a[g.id][d]-w)/(s-1),v=w+S;return i.filter(b=>b!==y&&b!==g).sort((b,E)=>a[b.id][d]-a[E.id][d]).forEach((b,E)=>{const C={x:0,y:0};C[c]=v+S*E-a[b.id][p]/2-a[b.id][c];const I=this.getShapeParent(b),_=I?P.Rot(C,-this.getShapePageTransform(I).rotation()):C;f.push(this.getChangesToTranslateShape(b,P.Add(b,_)))}),this.updateShapes(f),this}stretchShapes(n,r){const o=typeof n[0]=="string"?n:n.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=fe(o.map(l=>this.getShape(l))),i=Object.fromEntries(o.map(l=>[l,this.getShapeGeometry(l).bounds])),a=Object.fromEntries(o.map(l=>[l,this.getShapePageBounds(l)])),c=ne.Common(fe(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const l of s){if(this.getShapePageTransform(l).rotation()%Oe)continue;const d=i[l.id],p=a[l.id],f=new P(0,c.minY-p.minY),y=this.getShapeParentTransform(l);y&&f.rot(-y.rotation());const{x:g,y:w}=P.Add(f,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:w}],{squashing:!0});const S=new P(1,c.height/p.height);this.resizeShape(l.id,S,{initialBounds:d,scaleOrigin:new P(p.center.x,c.minY),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const l of s){const u=i[l.id],d=a[l.id];if(this.getShapePageTransform(l).rotation()%Oe)continue;const f=new P(c.minX-d.minX,0),y=this.getShapeParentTransform(l);y&&f.rot(-y.rotation());const{x:g,y:w}=P.Add(f,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:w}],{squashing:!0});const S=new P(c.width/d.width,1);this.resizeShape(l.id,S,{initialBounds:u,scaleOrigin:new P(c.minX,d.center.y),scaleAxisRotation:0})}});break}}return this}resizeShape(n,r,o={}){var f;const s=typeof n=="string"?n:n.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new P(1,r.y)),Number.isFinite(r.y)||(r=new P(r.x,1));const i=o.initialShape??this.getShape(s);if(!i)return this;const a=o.scaleOrigin??((f=this.getShapePageBounds(s))==null?void 0:f.center);if(!a)return this;const c=o.initialPageTransform?oe.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!c)return this;const l=c.rotation();if(l==null)return this;const u=o.scaleAxisRotation??l,d=o.initialBounds??this.getShapeGeometry(s).bounds;if(!d)return this;if(!Hk(l,u))return this._resizeUnalignedShape(s,r,{...o,initialBounds:d,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:c,initialShape:i});const p=this.getShapeUtil(i);if(p.isAspectRatioLocked(i)&&(Math.abs(r.x)>Math.abs(r.y)?r=new P(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new P(Math.sign(r.x)*Math.abs(r.y),r.y)),p.onResize&&p.canResize(i)){const y=this._scalePagePoint(oe.applyToPoint(c,new P(0,0)),a,r,u),g=this.getPointInParentSpace(i.id,y),w=new P(r.x,r.y),S=Ml((l-u)%Math.PI,0);w.x=S?r.x:r.y,w.y=S?r.y:r.x;const v=oe.applyToPoint(c,new P),{x:b,y:E}=this.getPointInParentSpace(i.id,v);this.updateShapes([{id:s,type:i.type,x:g.x,y:g.y,...p.onResize({...i,x:b,y:E},{newPoint:g,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:w.x,scaleY:w.y,initialBounds:d,initialShape:i})}],{squashing:!0})}else{const y=oe.applyToPoint(c,d.center),g=this._scalePagePoint(y,a,r,u),w=this.getPointInParentSpace(i.id,y),S=this.getPointInParentSpace(i.id,g),v=P.Sub(S,w);this.updateShapes([{id:s,type:i.type,x:i.x+v.x,y:i.y+v.y}],{squashing:!0})}return this}_scalePagePoint(n,r,o,s){const i=P.RotWith(n,r,-s).sub(r),a=P.MulV(i,o);return P.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(n,r,o){const{type:s}=o.initialShape,i=new P(r.x,r.y);if(Math.abs(r.x)>Math.abs(r.y)?i.x=Math.sign(r.x)*Math.abs(r.y):i.y=Math.sign(r.y)*Math.abs(r.x),this.resizeShape(n,i,{initialShape:o.initialShape,initialBounds:o.initialBounds}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:S}=oe.Decompose(o.initialPageTransform);S-=2*S,this.updateShapes([{id:n,type:s,rotation:S}],{squashing:!0})}const a=oe.applyToPoint(o.initialPageTransform,o.initialBounds.center),c=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),l=this.getShapePageBounds(n),u=this.getShapePageTransform(n),d=l.center,p=u.point();if(!d||!p)return this;const f=P.Sub(c,d),y=P.Add(p,f),{x:g,y:w}=this.getPointInParentSpace(n,y);return this.updateShapes([{id:n,type:s,x:g,y:w}],{squashing:!0}),this}getInitialMetaForShape(n){return{}}createShape(n){return this._createShapes([n]),this}createShapes(n){if(!Array.isArray(n))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");return this._createShapes(n),this}animateShape(n,r){return this.animateShapes([n],r)}animateShapes(n,r={}){const{duration:o=500,easing:s=nn.linear}=r,i=et();let a=o,c;const l=[];let u,d;for(let y=0,g=n.length;y<g;y++){if(u=n[y],!u)continue;d={partial:u,values:[]};const w=this.getShape(u.id);if(w){for(const S of["x","y","rotation"])u[S]!==void 0&&w[S]!==u[S]&&d.values.push({prop:S,from:w[S],to:u[S]});l.push(d),this.animatingShapes.set(w.id,i)}}let p;const f=y=>{if(a-=y,a<0){const{animatingShapes:v}=this,b=n.filter(E=>E&&v.get(E.id)===i);b.length&&this.updateShapes(b,{squashing:!1}),this.removeListener("tick",f);return}c=s(1-a/o);const{animatingShapes:g}=this,w=[];let S;for(let v=0,b=l.length;v<b;v++)p=l[v],S=g.get(p.partial.id),S===i&&w.push({id:p.partial.id,type:p.partial.type,...p.values.reduce((E,{prop:C,from:I,to:_})=>(E[C]=I+(_-I)*c,E),{})});this._updateShapes(w,{squashing:!0})};return this.addListener("tick",f),this}groupShapes(n,r=Be()){var f;if(!Array.isArray(n))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const o=typeof n[0]=="string"?n:n.map(y=>y.id);if(o.length<=1)return this;const s=fe(this._getUnlockedShapeIds(o).map(y=>this.getShape(y))),i=s.sort(en).map(y=>y.id),a=ne.Common(fe(s.map(y=>this.getShapePageBounds(y)))),{x:c,y:l}=a.point,u=this.findCommonAncestor(s)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const d=s.filter(y=>y.parentId===u).sort(en),p=(f=d[d.length-1])==null?void 0:f.index;return this.batch(()=>{this.createShapes([{id:r,type:"group",parentId:u,index:p,x:c,y:l,opacity:1,props:{}}]),this.reparentShapes(i,r),this.select(r)}),this}ungroupShapes(n){const r=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const o=new Set,s=fe(r.map(a=>this.getShape(a))),i=[];return s.forEach(a=>{this.isShapeOfType(a,"group")?i.push(a):o.add(a.id)}),i.length===0?this:(this.batch(()=>{let a;for(let c=0,l=i.length;c<l;c++){a=i[c];const u=this.getSortedChildIdsForParent(a.id);for(let d=0,p=u.length;d<p;d++)o.add(u[d]);this.reparentShapes(u,a.parentId,a.index)}this.deleteShapes(i.map(c=>c.id)),this.select(...o)}),this)}updateShape(n,r){return this.updateShapes([n],r),this}updateShapes(n,r){const o=Array(n.length);for(let s=0,i=n.length;s<i;s++){const a=n[s];if(!a)continue;const c=this.getShape(a.id);c&&(this.isShapeOrAncestorLocked(c)&&!Object.hasOwn(a,"isLocked")||(this.animatingShapes.delete(a.id),o.push(a)))}return this._updateShapes(o,r),this}_getUnlockedShapeIds(n){return n.filter(r=>{var o;return!((o=this.getShape(r))!=null&&o.isLocked)})}deleteShapes(n){if(!Array.isArray(n))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");return this._deleteShapes(this._getUnlockedShapeIds(typeof n[0]=="string"?n:n.map(r=>r.id))),this}deleteShape(n){return this.deleteShapes([typeof n=="string"?n:n.id]),this}_extractSharedStyles(n,r){if(this.isShapeOfType(n,"group")){const o=this._parentIdsToChildIds.get()[n.id];if(!o)return;for(let s=0,i=o.length;s<i;s++)this._extractSharedStyles(this.getShape(o[s]),r)}else for(const[o,s]of this.styleProps[n.type])r.applyValue(o,Lr(n.props,s))}_getSelectionSharedStyles(){const n=this.getSelectedShapes(),r=new KS;for(const o of n)this._extractSharedStyles(o,r);return r}getStyleForNextShape(n){const r=this.getInstanceState().stylesForNextShape[n.id];return r===void 0?n.defaultValue:r}getShapeStyleIfExists(n,r){const o=this.styleProps[n.type].get(r);if(o!==void 0)return Lr(n.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const n=this.root.getCurrent(),r=new KS;if(!n)return r;if(n.shapeType)for(const o of this.styleProps[n.shapeType].keys())r.applyValue(o,this.getStyleForNextShape(o));return r}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const n=[],r=s=>{const i=this.getShape(s);if(i)if(this.isShapeOfType(i,"group"))for(const a of this.getSortedChildIdsForParent(i.id))r(a);else n.push(i)};for(const s of this.getSelectedShapeIds())r(s);let o=null;for(const s of n)if(o===null)o=s.opacity;else if(o!==s.opacity)return{type:"mixed"};if(o!==null)return{type:"shared",value:o}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(n,r){return this.updateInstanceState({opacityForNextShape:n},r),this}setOpacityForSelectedShapes(n,r){const o=this.getSelectedShapes();if(o.length>0){const s=[],i=a=>{if(this.isShapeOfType(a,"group")){const c=this.getSortedChildIdsForParent(a);for(const l of c)i(this.getShape(l))}else s.push(a)};for(const a of o)i(a);this.updateShapes(s.map(a=>({id:a.id,type:a.type,opacity:n})),r)}return this}setStyleForNextShapes(n,r,o){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[n.id]:r}},o),this}setStyleForSelectedShapes(n,r,o){const s=this.getSelectedShapes();if(s.length>0){const i=[],a=c=>{if(this.isShapeOfType(c,"group")){const l=this.getSortedChildIdsForParent(c.id);for(const u of l)a(this.getShape(u))}else{const l=this.getShapeUtil(c),u=this.styleProps[c.type].get(n);if(u){const d={id:c.id,type:c.type,props:{[u]:r}};i.push({util:l,originalShape:c,updatePartial:d})}}};for(const c of s)a(c);this.updateShapes(i.map(({updatePartial:c})=>c),o)}return this}registerExternalAssetHandler(n,r){return this.externalAssetContentHandlers[n]=r,this}async getAssetForExternalContent(n){var r,o;return await((o=(r=this.externalAssetContentHandlers)[n.type])==null?void 0:o.call(r,n))}registerExternalContentHandler(n,r){return this.externalContentHandlers[n]=r,this}async putExternalContent(n){var r,o;return(o=(r=this.externalContentHandlers)[n.type])==null?void 0:o.call(r,n)}getContentFromCurrentPage(n){const r=typeof n[0]=="string"?n:n.map(c=>c.id);if(!r||r.length===0)return;const o={};let s=Mp(r.map(c=>this.getShape(c)).sort(en).flatMap(c=>{const l=[c];return this.visitDescendants(c.id,u=>{l.push(this.getShape(u))}),l}));s=s.map(c=>{if(o[c.id]=this.getShapePageTransform(c.id),c=Ye(c),this.isShapeOfType(c,"arrow")){const l=c.props.start.type==="binding"?c.props.start.boundShapeId:void 0,u=c.props.end.type==="binding"?c.props.end.boundShapeId:void 0,d=this.getArrowInfo(c);if(c.props.start.type==="binding"&&!s.some(f=>f.id===l))if(d!=null&&d.isValid){const{x:f,y}=d.start.point;c.props.start={type:"point",x:f,y}}else{const{start:f}=jr(this,c);c.props.start={type:"point",x:f.x,y:f.y}}if(c.props.end.type==="binding"&&!s.some(f=>f.id===u))if(d!=null&&d.isValid){const{x:f,y}=d.end.point;c.props.end={type:"point",x:f,y}}else{const{end:f}=jr(this,c);c.props.end={type:"point",x:f.x,y:f.y}}const p=Zc(c)?Al(this,c):xm(this,c);if(d!=null&&d.isValid&&(p!=null&&p.isValid)&&!Zc(c)){const f=P.Med(d.start.handle,d.end.handle),y=P.Dist(d.middle,f),g=P.Dist(p.middle,f);c.props.bend<0?c.props.bend+=g-y:c.props.bend-=g-y}return c}return c});const i=[];s.forEach(c=>{if(s.find(l=>l.id===c.parentId)===void 0){const l=this.getShapePageTransform(c.id),u=l.point(),d=l.rotation();c.x=u.x,c.y=u.y,c.rotation=d,c.parentId=this.getCurrentPageId(),i.push(c.id)}});const a=new Set;return s.forEach(c=>{"assetId"in c.props&&c.props.assetId!==null&&a.add(c.props.assetId)}),{shapes:s,rootShapeIds:i,schema:this.store.schema.serialize(),assets:fe(Array.from(a).map(c=>this.getAsset(c)))}}putContentOntoCurrentPage(n,r={}){var k;if(this.getInstanceState().isReadonly)return this;if(!n.schema)throw Error(`Could not put content:
content is missing a schema.`);const{select:o=!1,preserveIds:s=!1,preservePosition:i=!1}=r;let{point:a=void 0}=r;const c=this.getCurrentPageId(),{rootShapeIds:l}=n,u=[],d=[],p={store:{...Object.fromEntries(n.assets.map($=>[$.id,$])),...Object.fromEntries(n.shapes.map($=>[$.id,$]))},schema:n.schema},f=this.store.schema.migrateStoreSnapshot(p);if(f.type==="error")throw Error("Could not put content: could not migrate content");for(const $ of Object.values(f.value))switch($.typeName){case"asset":{u.push($);break}case"shape":{d.push($);break}}const y=new Map(d.map($=>[$.id,Be()]));let g=this.getCurrentPageId(),w=1/0,S=[];for(const $ of this.getSelectedShapes()){if(w===0)break;const T=this.isShapeOfType($,"frame"),O=this.getShapeAncestors($);T&&O.push($);const N=T?O.length+1:O.length;if(N<w)w=N,S=O,g=T?$.id:$.parentId;else if(N===w){if(S.length!==O.length)throw Error(`Ancestors: ${S.length} !== ${O.length}`);if(S.length===0){g=c;break}else{g=c;for(let F=0;F<S.length&&O[F]===S[F];F++)g=O[F].id}}}let v=!1;if(!bn(g)){const $=this.getShape(g);if($){if(!this.getViewportPageBounds().includes(this.getShapePageBounds($)))g=c;else if(l.length===1){const T=d.find(O=>O.id===l[0]);this.isShapeOfType($,"frame")&&this.isShapeOfType(T,"frame")&&T.props.w===($==null?void 0:$.props.w)&&T.props.h===($==null?void 0:$.props.h)&&(v=!0)}}else g=c}v||(v=y.has(g)),v&&(g=this.getShape(g).parentId);let b=this.getHighestIndexForParent(g);const E=[],C=d.map($=>{let T;if(s)T=Ye($),y.set($.id,$.id);else{const O=y.get($.id);T=Ye({...$,id:O})}if(l.includes($.id)&&(T.parentId=c,E.push(T)),y.has(T.parentId)?T.parentId=y.get($.parentId):(l.push(T.id),T.index=b,b=$o(b)),this.isShapeOfType(T,"arrow")){if(T.props.start.type==="binding"){const O=y.get(T.props.start.boundShapeId);T.props.start=O?{...T.props.start,boundShapeId:O}:{type:"point",x:0,y:0}}if(T.props.end.type==="binding"){const O=y.get(T.props.end.boundShapeId);T.props.end=O?{...T.props.end,boundShapeId:O}:{type:"point",x:0,y:0}}}return T});if(C.length+this.getCurrentPageShapeIds().size>Io)return _d(this),this;const I=[],_=[];for(const $ of u)this.store.has($.id)||(($.type==="image"||$.type==="video")&&((k=$.props.src)!=null&&k.startsWith("data:image"))&&(_.push(Ye($)),$.props.src=null),I.push($));return Promise.allSettled(_.map(async $=>{const T=await O4($.props.src,$.props.name,$.props.mimeType??"image/png"),O=await this.getAssetForExternalContent({type:"file",file:T});if(!O){this.deleteAssets([$.id]);return}this.updateAssets([{...O,id:$.id}])})),this.batch(()=>{I.length>0&&this.createAssets(I),this.createShapes(C),o&&this.select(...E.map(F=>F.id)),g!==c&&this.reparentShapes(E.map(F=>F.id),g);const $=C.map(F=>this.getShape(F.id)),T=ne.Common($.map(F=>this.getShapePageBounds(F)));if(a===void 0)if(bn(g)){const F=this.getViewportPageBounds();i||F.includes(ne.From(T))?a=T.center:a=F.center}else{const F=this.getShape(g);a=oe.applyToPoint(this.getShapePageTransform(F),this.getShapeGeometry(F).bounds.center)}if(E.length===1){const F=E[0];if(this.isShapeOfType(F,"frame"))for(;this.getShapesAtPoint(a).some(L=>this.isShapeOfType(L,"frame")&&L.props.w===F.props.w&&L.props.h===F.props.h);)a.x+=T.w+16}const O=ne.Common(fe(E.map(({id:F})=>this.getShapePageBounds(F)))).center,N=P.Sub(a,O);this.updateShapes(E.map(({id:F})=>{const L=this.getShape(F),B=this.getShapeParentTransform(F).decompose().rotation,q=P.Rot(N,-B);return{id:L.id,type:L.type,x:L.x+q.x,y:L.y+q.y}}))}),this}async getSvgElement(n,r={}){const o=await V4(this,n,r);if(!o)return;const s=document.createDocumentFragment(),i=$_(s);Ui.flushSync(()=>{i.render(o.jsx)});const a=s.firstElementChild;return _t(a instanceof SVGSVGElement,"Expected an SVG element"),i.unmount(),{svg:a,width:o.width,height:o.height}}async getSvgString(n,r={}){const o=await this.getSvgElement(n,r);return o?{svg:new XMLSerializer().serializeToString(o.svg),width:o.width,height:o.height}:void 0}async getSvg(n,r={}){const o=await this.getSvgElement(n,r);if(o)return o.svg}_updateInputsFromEvent(n){var S;const{pointerVelocity:r,previousScreenPoint:o,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:c}=this.store.unsafeGetWithoutCapture(In),{x:l,y:u,z:d}=this.store.unsafeGetWithoutCapture(this.getCameraId()),p=n.point.x-c.x,f=n.point.y-c.y,y=n.point.z??.5;o.setTo(i),s.setTo(a),i.set(p,f);const g=p/d-l,w=f/d-u;isFinite(g)&&isFinite(w)&&a.set(g,w,y),this.inputs.isPen=n.type==="pointer"&&n.isPen,(n.name==="pointer_down"||this.inputs.isPinching)&&r.set(0,0),this.store.put([{id:Fp,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:n.type==="pointer"&&n.pointerId===x1.CAMERA_MOVE?((S=this.store.unsafeGetWithoutCapture(Fp))==null?void 0:S.lastActivityTimestamp)??this._tickManager.now:this._tickManager.now,meta:{}}])}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}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_flushEventsForTick(n){this.batch(()=>{if(this._pendingEventsForNextTick.length>0){const r=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const o of r)this._flushEventForTick(o)}n>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:n}),this.scribbles.tick(n)})}}re([V],J.prototype,"getCanUndo");re([V],J.prototype,"getCanRedo");re([V],J.prototype,"_getArrowBindingsIndex");re([V],J.prototype,"getArrowInfoCache");re([V],J.prototype,"getPath");re([V],J.prototype,"getCurrentTool");re([V],J.prototype,"getCurrentToolId");re([V],J.prototype,"getDocumentSettings");re([V],J.prototype,"getInstanceState");re([V],J.prototype,"getOpenMenus");re([V],J.prototype,"getIsMenuOpen");re([V],J.prototype,"getPageStates");re([V],J.prototype,"_getPageStatesQuery");re([V],J.prototype,"getCurrentPageState");re([V],J.prototype,"_getCurrentPageStateId");re([V],J.prototype,"getSelectedShapeIds");re([V],J.prototype,"getSelectedShapes");re([V],J.prototype,"getOnlySelectedShapeId");re([V],J.prototype,"getOnlySelectedShape");re([V],J.prototype,"getSelectionPageBounds");re([V],J.prototype,"getSelectionRotation");re([V],J.prototype,"getSelectionRotatedPageBounds");re([V],J.prototype,"getSelectionRotatedScreenBounds");re([V],J.prototype,"getFocusedGroupId");re([V],J.prototype,"getFocusedGroup");re([V],J.prototype,"getEditingShapeId");re([V],J.prototype,"getEditingShape");re([V],J.prototype,"getHoveredShapeId");re([V],J.prototype,"getHoveredShape");re([V],J.prototype,"getHintingShapeIds");re([V],J.prototype,"getHintingShape");re([V],J.prototype,"getErasingShapeIds");re([V],J.prototype,"getErasingShapes");re([V],J.prototype,"getCameraId");re([V],J.prototype,"getCamera");re([V],J.prototype,"getZoomLevel");re([V],J.prototype,"getViewportScreenBounds");re([V],J.prototype,"getViewportScreenCenter");re([V],J.prototype,"getViewportPageBounds");re([V],J.prototype,"getViewportPageCenter");re([V],J.prototype,"_getCollaboratorsQuery");re([V],J.prototype,"getCollaborators");re([V],J.prototype,"getCollaboratorsOnCurrentPage");re([V],J.prototype,"getRenderingShapes");re([V],J.prototype,"_getAllPagesQuery");re([V],J.prototype,"getPages");re([V],J.prototype,"getCurrentPageId");re([V],J.prototype,"getCurrentPageShapeIdsSorted");re([V],J.prototype,"_getAllAssetsQuery");re([V],J.prototype,"_getShapeGeometryCache");re([V],J.prototype,"_getShapeHandlesCache");re([V],J.prototype,"_getShapePageTransformCache");re([V],J.prototype,"_getShapePageBoundsCache");re([V],J.prototype,"_getShapeClipPathCache");re([V],J.prototype,"_getShapeMaskCache");re([V],J.prototype,"_getShapeMaskedPageBoundsCache");re([V],J.prototype,"_notVisibleShapes");re([V],J.prototype,"getCulledShapes");re([V],J.prototype,"getCurrentPageBounds");re([V],J.prototype,"getCurrentPageShapes");re([V],J.prototype,"getCurrentPageShapesSorted");re([V],J.prototype,"getCurrentPageRenderingShapesSorted");re([V],J.prototype,"_getSelectionSharedStyles");re([V({isEqual:(e,t)=>e.equals(t)})],J.prototype,"getSharedStyles");re([V],J.prototype,"getSharedOpacity");function _d(e,t=e.getCurrentPageId()){const n=e.getPage(t).name;e.emit("max-shapes",{name:n,pageId:t,count:Io})}function Qc(e,t){if(!t)return e;let n=null;const r=Object.entries(t);for(let o=0,s=r.length;o<s;o++){const[i,a]=r[o];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==e[i]){if(n||(n={...e}),i==="props"||i==="meta"){n[i]={...e[i]};for(const[c,l]of Object.entries(a))l!==void 0&&(n[i][c]=l);continue}n[i]=a}}return n||e}function D2(e,t,n){const r=e.getShape(t);if(!r)return;n.push(r);const o=e.getSortedChildIdsForParent(t);for(let s=0,i=o.length;s<i;s++)D2(e,o[s],n)}function Ru(){const e=z(),t=j2();return K("isDarkMode",()=>(t==null?void 0:t.isDarkMode)??e.user.getIsDarkMode(),[t,e])}const Q1="<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'/>",J1="<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'/>",kd='<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 ds(e,t,n,r,o,s=16,i=16){const a=(-n-t)*(Pe/180),c=Math.sin(a),l=Math.cos(a),u=1*l-1*c,d=1*c+1*l;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: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${d}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${t+n} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const Pz=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],Cz={none:()=>"none","ew-resize":(e,t,n)=>ds(J1,e,0,t,n),"ns-resize":(e,t,n)=>ds(J1,e,90,t,n),"nesw-resize":(e,t,n)=>ds(Q1,e,0,t,n),"nwse-resize":(e,t,n)=>ds(Q1,e,90,t,n),"nwse-rotate":(e,t,n)=>ds(kd,e,0,t,n),"nesw-rotate":(e,t,n)=>ds(kd,e,90,t,n),"senw-rotate":(e,t,n)=>ds(kd,e,180,t,n),"swne-rotate":(e,t,n)=>ds(kd,e,270,t,n)};function Bn(e,t=0,n="black"){return Cz[e](w5(t),!1,n)}function Iz(){const e=z(),t=cn(),n=Ru();js("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(Pz.includes(r)){t.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}t.style.setProperty("--tl-cursor",Bn(r,o,n?"white":"black"))},[e,t,n])}function Ez(){const e=z(),t=cn(),n=Ru(),r=K($t.forceSrgb);Se.useEffect(()=>{n?(t.setAttribute("data-color-mode","dark"),t.classList.remove("tl-theme__light"),t.classList.add("tl-theme__dark")):(t.setAttribute("data-color-mode","light"),t.classList.remove("tl-theme__dark"),t.classList.add("tl-theme__light")),r?t.classList.add("tl-theme__force-sRGB"):t.classList.remove("tl-theme__force-sRGB")},[e,t,r,n])}function ax(e){const t=x.useRef();return x.useLayoutEffect(()=>{t.current=e}),x.useDebugValue(e),x.useCallback((...n)=>{const r=t.current;return _t(r,"fn does not exist"),r(...n)},[])}function _z(e){const t=z(),n=cn();x.useLayoutEffect(()=>{e?(t.getInstanceState().isFocused||t.updateInstanceState({isFocused:!0}),t.getContainer().focus()):t.getInstanceState().isFocused&&t.updateInstanceState({isFocused:!1})},[t,n,e])}function kz(){const[e,t]=x.useState(0);x.useEffect(()=>t(n=>n+1),[])}const Va="TLDRAW_TAB_ID_v2",so=globalThis.window;function Tz(){return so?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(so.navigator.platform)||so.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const ef=so?so[Va]??G_(Va)??"TLDRAW_INSTANCE_STATE_V1_"+et():"<error>";so&&(so[Va]=ef,Tz()?L0(Va,ef):Y_(Va));so==null||so.addEventListener("beforeunload",()=>{L0(Va,ef)});const R2={Initial:0},Hf=Math.max(...Object.values(R2));function $z(e){e.version<R2.Initial,e.version=Hf}const L2=ve({version:he,currentPageId:nu,isFocusMode:we,exportBackground:we,isDebugMode:we,isToolLocked:we,isGridMode:we,pageStates:Nt(ve({pageId:nu,camera:ve({x:he,y:he,z:he}),selectedShapeIds:Nt(_r),focusedGroupId:_r.nullable()}))});function Mz(e){if(!e||typeof e!="object")return console.warn("Invalid instance state"),null;if(!("version"in e)||typeof e.version!="number")return console.warn("No version in instance state"),null;e.version!==Hf&&(e=Ye(e),$z(e));try{return L2.validate(e)}catch(t){return console.warn(t),null}}function Az(e){const t=e.query.ids("page");return V("sessionStateSnapshot",()=>{const n=e.get(In);if(!n)return null;const r=[...t.get()];return{version:Hf,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(o=>{const s=e.get(Zt.createId(o)),i=e.get(hn.createId(o));return{pageId:o,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:(s==null?void 0:s.selectedShapeIds)??[],focusedGroupId:(s==null?void 0:s.focusedGroupId)??null}})}})}function jz(e,t){const n=Mz(t);if(!n)return;const r=e.allRecords().filter(i=>i.typeName==="instance_page_state"||i.typeName==="camera"),o={added:{},updated:{},removed:{...O0(r.map(i=>[i.id,i]))}};e.has(In)&&(o.removed[In]=e.get(In));const s={removed:{},updated:{},added:{[In]:e.schema.types.instance.create({id:In,currentPageId:n.currentPageId,isDebugMode:n.isDebugMode,isFocusMode:n.isFocusMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,exportBackground:n.exportBackground})}};for(const i of n.pageStates){const a=hn.createId(i.pageId),c=Zt.createId(i.pageId);s.added[a]=hn.create({id:hn.createId(i.pageId),x:i.camera.x,y:i.camera.y,z:i.camera.z}),s.added[c]=Zt.create({id:Zt.createId(i.pageId),pageId:i.pageId,selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId})}Mr(()=>{e.applyDiff(Af([o,s])),e.ensureStoreIsUsable()})}function Oz(e){var o;const t=[];for(const s of Object.values(e))(o=s.typeName)!=null&&o.match(/^(instance.*|pointer|camera)$/)&&t.push(s);const n=t.filter(s=>s.typeName==="instance"&&s.id!==In)[0];if(!n)return null;const r={version:Hf,currentPageId:n.currentPageId,exportBackground:!!n.exportBackground,isFocusMode:!!n.isFocusMode,isDebugMode:!!n.isDebugMode,isToolLocked:!!n.isToolLocked,isGridMode:!1,pageStates:t.filter(s=>s.typeName==="instance_page_state"&&s.instanceId===n.id).map(s=>{const i=e[s.cameraId]??{x:0,y:0,z:1};return{pageId:s.pageId,camera:{x:i.x,y:i.y,z:i.z},selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId}})};try{return L2.validate(r),r}catch{return null}}function Dz(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
Keep seeing this message?
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
• If your hard disk is full, try clearing up some space and then reload the page.`)}function Rz(){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.
Keep seeing this message?
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const Lz=(e,t)=>t.some(n=>e instanceof n);let eP,tP;function Fz(){return eP||(eP=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Nz(){return tP||(tP=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const F2=new WeakMap,WS=new WeakMap,N2=new WeakMap,wm=new WeakMap,cx=new WeakMap;function zz(e){const t=new Promise((n,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{n(Ro(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return t.then(n=>{n instanceof IDBCursor&&F2.set(n,e)}).catch(()=>{}),cx.set(t,e),t}function Bz(e){if(WS.has(e))return;const t=new Promise((n,r)=>{const o=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{n(),o()},i=()=>{r(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});WS.set(e,t)}let VS={get(e,t,n){if(e instanceof IDBTransaction){if(t==="done")return WS.get(e);if(t==="objectStoreNames")return e.objectStoreNames||N2.get(e);if(t==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Ro(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function Uz(e){VS=e(VS)}function Hz(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...n){const r=e.call(bm(this),t,...n);return N2.set(r,t.sort?t.sort():[t]),Ro(r)}:Nz().includes(e)?function(...t){return e.apply(bm(this),t),Ro(F2.get(this))}:function(...t){return Ro(e.apply(bm(this),t))}}function Kz(e){return typeof e=="function"?Hz(e):(e instanceof IDBTransaction&&Bz(e),Lz(e,Fz())?new Proxy(e,VS):e)}function Ro(e){if(e instanceof IDBRequest)return zz(e);if(wm.has(e))return wm.get(e);const t=Kz(e);return t!==e&&(wm.set(e,t),cx.set(t,e)),t}const bm=e=>cx.get(e);function Wz(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,t),a=Ro(i);return r&&i.addEventListener("upgradeneeded",c=>{r(Ro(i.result),c.oldVersion,c.newVersion,Ro(i.transaction),c)}),n&&i.addEventListener("blocked",c=>n(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",l=>o(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}function Vz(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",r=>t(r.oldVersion,r)),Ro(n).then(()=>{})}const Gz=["get","getKey","getAll","getAllKeys","count"],Yz=["put","add","delete","clear"],Pm=new Map;function nP(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(Pm.get(t))return Pm.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=Yz.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||Gz.includes(n)))return;const s=async function(i,...a){const c=this.transaction(i,o?"readwrite":"readonly");let l=c.store;return r&&(l=l.index(a.shift())),(await Promise.all([l[n](...a),o&&c.done]))[0]};return Pm.set(t,s),s}Uz(e=>({...e,get:(t,n,r)=>nP(t,n)||e.get(t,n,r),has:(t,n)=>!!nP(t,n)||e.has(t,n)}));const Kf="TLDRAW_DOCUMENT_v2",z2="TLDRAW_DB_NAME_INDEX_v2",Le={Records:"records",Schema:"schema",SessionState:"session_state"};async function Wf(e,t){Jz(e);const n=await Wz(e,3,{upgrade(r){r.objectStoreNames.contains(Le.Records)||r.createObjectStore(Le.Records),r.objectStoreNames.contains(Le.Schema)||r.createObjectStore(Le.Schema),r.objectStoreNames.contains(Le.SessionState)||r.createObjectStore(Le.SessionState)}});try{return await t(n)}finally{n.close()}}async function Xz({persistenceKey:e,sessionId:t,didCancel:n}){const r=Kf+e;if(lx().includes(r))return await Qz({persistenceKey:e,didCancel:n}),await Wf(r,async o=>{var d,p;if(n!=null&&n())return;const s=o.transaction([Le.Records,Le.Schema,Le.SessionState],"readonly"),i=s.objectStore(Le.Records),a=s.objectStore(Le.Schema),c=s.objectStore(Le.SessionState);let l=t?(d=await c.get(t))==null?void 0:d.snapshot:null;l||(l=(p=(await c.getAll()).sort((y,g)=>y.updatedAt-g.updatedAt).pop())==null?void 0:p.snapshot);const u={records:await i.getAll(),schema:await a.get(Le.Schema),sessionStateSnapshot:l};if(n!=null&&n()){s.abort();return}return await s.done,u})}async function qz({persistenceKey:e,schema:t,changes:n,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=Kf+e;await Wf(i,async a=>{const c=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),l=c.objectStore(Le.Records),u=c.objectStore(Le.Schema),d=c.objectStore(Le.SessionState);for(const[p,f]of Object.entries(n.added))await l.put(f,p);for(const[p,f]of Object.values(n.updated))await l.put(f,f.id);for(const p of Object.keys(n.removed))await l.delete(p);if(u.put(t.serialize(),Le.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return c.abort();await c.done})}async function Zz({persistenceKey:e,schema:t,snapshot:n,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=Kf+e;await Wf(i,async a=>{const c=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),l=c.objectStore(Le.Records),u=c.objectStore(Le.Schema),d=c.objectStore(Le.SessionState);await l.clear();for(const[p,f]of Object.entries(n))await l.put(f,p);if(u.put(t.serialize(),Le.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return c.abort();await c.done})}async function Qz({persistenceKey:e,didCancel:t}){await Wf(Kf+e,async n=>{const r=n.transaction([Le.SessionState],"readwrite"),o=r.objectStore(Le.SessionState),s=(await o.getAll()).sort((a,c)=>a.updatedAt-c.updatedAt);if(s.length<10){await r.done;return}const i=s.slice(0,s.length-10);for(const{id:a}of i)await o.delete(a);if(t!=null&&t())return r.abort();await r.done})}function lx(){const e=JSON.parse(D0(z2)||"[]")??[];return Array.isArray(e)?e:[]}function Jz(e){const t=new Set(lx());t.add(e),R0(z2,JSON.stringify([...t]))}const e8=350,t8=1e4,rP=Symbol("UPDATE_INSTANCE_STATE"),n8=e=>e;class r8{constructor(t){m(this,"onmessage")}postMessage(t){}close(){}}const o8=typeof BroadcastChannel>"u"?r8:BroadcastChannel;class s8{constructor(t,{persistenceKey:n,sessionId:r=ef,onLoad:o,onLoadError:s},i=new o8(`tldraw-tab-sync-${n}`)){m(this,"disposables",new Set);m(this,"diffQueue",[]);m(this,"didDispose",!1);m(this,"shouldDoFullDBWrite",!0);m(this,"isReloading",!1);m(this,"persistenceKey");m(this,"sessionId");m(this,"serializedSchema");m(this,"isDebugging",!1);m(this,"documentTypes");m(this,"$sessionStateSnapshot");m(this,"initTime",Date.now());m(this,"isPersisting",!1);m(this,"didLastWriteError",!1);m(this,"scheduledPersistTimeout",null);this.store=t,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=Az(this.store),this.disposables.add(t.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(n8({type:"diff",storeId:this.store.id,changes:a,schema:this.serializedSchema})),this.schedulePersist()},{source:"user",scope:"document"})),this.disposables.add(t.listen(()=>{this.diffQueue.push(rP),this.schedulePersist()},{scope:"session"})),this.connect(o,s),this.documentTypes=new Set(Object.values(this.store.schema.types).filter(a=>a.scope==="document").map(a=>a.typeName))}debug(...t){this.isDebugging&&console.debug(...t)}async connect(t,n){this.debug("connecting");let r;try{r=await Xz({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){n(o),Rz(),typeof window<"u"&&window.location.reload();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const o=Object.fromEntries(r.records.map(a=>[a.id,a])),s=r.sessionStateSnapshot??Oz(o),i=this.store.schema.migrateStoreSnapshot({store:o,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),n(new Error(`Failed to migrate store: ${i.reason}`));return}this.store.mergeRemoteChanges(()=>{this.store.put(Object.values(i.value).filter(a=>this.documentTypes.has(a.typeName)),"initialize")}),s&&jz(this.store,s)}this.channel.onmessage=({data:o})=>{var a,c;this.debug("got message",o);const s=o,i=this.store.schema.getMigrationsSince(s.schema);if(i.ok){if(i.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}}else{if(Date.now()-this.initTime<5e3){n(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(c=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||c.call(a);return}s.type==="diff"&&(this.debug("applying diff"),Mr(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(s.changes),this.store.ensureStoreIsUsable()})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),t(this)}catch(o){if(this.debug("error loading data from store",o),this.didDispose)return;n(o);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(t=>t())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?t8:e8))}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(){_t(!this.isPersisting,"persist already in progress"),this.isPersisting=!0,this.debug("doPersist start");const t=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await Zz({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const n=Af(t.filter(r=>r!==rP));await qz({persistenceKey:this.persistenceKey,changes:n,schema:this.store.schema,didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(n){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",n),Dz(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function B2({initialData:e,defaultName:t="",...n}){const r="schema"in n&&n.schema?n.schema:d5({shapes:i8($2("shapeUtils"in n&&n.shapeUtils?n.shapeUtils:[])),migrations:"migrations"in n?n.migrations:[]});return new J_({schema:r,initialData:e,props:{defaultName:t}})}function i8(e){return Object.fromEntries(e.map(t=>[t.type,{props:t.props,migrations:t.migrations}]))}function oP(e){const t=B2(e);return e.snapshot&&t.loadSnapshot(e.snapshot),{store:t,opts:e}}function U2(e){const[t,n]=x.useState(()=>oP(e));if(!U_(t.opts,e)){const r=oP(e);return n(r),r.store}return t.store}function a8({persistenceKey:e,sessionId:t,...n}){const[r,o]=x.useState(null),s=U2(n);return x.useEffect(()=>{const i=et();if(!e){o({id:i,storeWithStatus:{status:"not-synced",store:s}});return}o({id:i,storeWithStatus:{status:"loading"}});const a=l=>{o(u=>(u==null?void 0:u.id)===i?{id:i,storeWithStatus:l}:u)},c=new s8(s,{sessionId:t,persistenceKey:e,onLoad(){a({store:s,status:"synced-local"})},onLoadError(l){a({status:"error",error:l})}});return()=>{o(l=>(l==null?void 0:l.id)===i?null:l),c.close()}},[e,s,t]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}let H2=!1;if(typeof window<"u"){const e=window.navigator.userAgent,t=!!e.match(/iPad/i)||!!e.match(/iPhone/i),n=!!e.match(/WebKit/i);H2=t&&n&&!e.match(/CriOS/i)}function c8(){const e=z();x.useEffect(()=>{if(!H2)return;function t(n){(n.target instanceof HTMLInputElement&&n.target.type==="text"||n.target instanceof HTMLTextAreaElement)&&e.complete()}return document.addEventListener("focusout",t),()=>document.removeEventListener("focusout",t)},[e])}function l8(){const e=z(),t=cn();x.useEffect(()=>{const n=s=>t.style.setProperty("--tl-zoom",s.toString()),r=B_(n,100),o=new yc("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?n(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach()}},[e,t])}const u8=[],d8=[],h8=x.memo(function({store:t,components:n,className:r,user:o,...s}){const[i,a]=Se.useState(null),c=x.useMemo(()=>o??E2(),[o]),l=(n==null?void 0:n.ErrorFallback)===void 0?v2:n==null?void 0:n.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??u8,tools:s.tools??d8,components:n};return h.jsx("div",{ref:a,draggable:!1,className:ue("tl-container tl-theme__light",r),onPointerDown:Ut,tabIndex:-1,children:h.jsx(su,{fallback:l,onError:d=>j0(d,{tags:{origin:"react.tldraw-before-app"}}),children:i&&h.jsx(V5,{container:i,children:h.jsx(h4,{overrides:n,children:t?t instanceof J_?h.jsx(W2,{...u,store:t,user:c}):h.jsx(K2,{...u,store:t,user:c}):h.jsx(p8,{...u,store:t,user:c})})})})})});function p8(e){const{defaultName:t,snapshot:n,initialData:r,shapeUtils:o,persistenceKey:s,sessionId:i,user:a}=e,c=a8({shapeUtils:o,initialData:r,persistenceKey:s,sessionId:i,defaultName:t,snapshot:n});return h.jsx(K2,{...e,store:c,user:a})}const K2=x.memo(function({store:t,user:n,...r}){const o=cn();x.useLayoutEffect(()=>{n.userPreferences.get().isDarkMode&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,n]);const{LoadingScreen:s}=dt();switch(t.status){case"error":throw t.error;case"loading":return s?h.jsx(s,{}):null}return h.jsx(W2,{...r,store:t.store,user:n})});function W2({onMount:e,children:t,store:n,tools:r,shapeUtils:o,user:s,initialState:i,autoFocus:a=!0,inferDarkMode:c}){const{ErrorFallback:l}=dt(),u=cn(),[d,p]=x.useState(null);x.useLayoutEffect(()=>{const g=new J({store:n,shapeUtils:o,tools:r,getContainer:()=>u,user:s,initialState:i,inferDarkMode:c});return p(g),()=>{g.dispose()}},[u,o,r,n,s,i,c]);const f=x.useSyncExternalStore(x.useCallback(g=>d?(d.on("crash",g),()=>d.off("crash",g)):()=>{},[d]),()=>(d==null?void 0:d.getCrashingError())??null),{Canvas:y}=dt();return d?h.jsx(su,{fallback:l,onError:g=>d.annotateError(g,{origin:"react.tldraw",willCrashApp:!0}),children:f?h.jsx(g8,{crashingError:f}):h.jsx(Rf.Provider,{value:d,children:h.jsx(f8,{autoFocus:a,onMount:e,children:t??(y?h.jsx(y,{}):null)})})}):null}function f8({children:e,onMount:t,autoFocus:n}){return l8(),Iz(),Ez(),c8(),kz(),_z(n),m8(t),h.jsx(h.Fragment,{children:e})}function g8({crashingError:e}){throw e}function V2({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function G2({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function m8(e){const t=z(),n=ax(r=>{const o=e==null?void 0:e(r);return r.emit("mount"),window.tldrawReady=!0,o});Se.useLayoutEffect(()=>{if(t)return n==null?void 0:n(t)},[t,n])}function Ai({children:e,className:t="",...n}){return h.jsx("div",{...n,className:ue("tl-html-container",t),children:e})}function Y2(e,t,n={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=t,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:u=1/0}=n;let d=e.props.w*s,p=e.props.h*i;const f=new P(0,0);if(d>0){if(d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=d-a;break}case"top":case"bottom":{f.x=(d-a)/2;break}default:f.x=0}d=a}}else if(f.x=d,d=-d,d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-d;break}default:f.x=-a}d=a}if(p>0){if(p<l){switch(o){case"top_left":case"top":case"top_right":{f.y=p-l;break}case"right":case"left":{f.y=(p-l)/2;break}default:f.y=0}p=l}}else if(f.y=p,p=-p,p<l){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-l}p=l}const{x:y,y:g}=f.rot(e.rotation).add(r);return{x:y,y:g,props:{w:Math.min(c,d),h:Math.min(u,p)}}}class Pc extends Fr{constructor(){super(...arguments);m(this,"onResize",(n,r)=>Y2(n,r))}getGeometry(n){return new Wo({width:n.props.w,height:n.props.h,isFilled:!0})}getHandleSnapGeometry(n){return{points:this.getGeometry(n).bounds.cornersAndCenter}}}var my;let y8=(my=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(my,"id","idle"),my);var yy;let S8=(yy=class extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"wasFocusedOnEnter",!1);m(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=Be();this.markId=`creating:${s}`,this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(s),this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:this.parent.onCreate})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:n}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;this.editor.mark(this.markId);const r=this.parent.shapeType,o=Be();this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:r,x:n.x,y:n.y}]);const s=this.editor.getShape(o),{w:i,h:a}=this.editor.getShapeUtil(s).getDefaultProps(),c=new P(i/2,a/2),l=this.editor.getShapeParentTransform(s);l&&c.rot(-l.rotation()),this.editor.updateShapes([{id:o,type:r,x:s.x-c.x,y:s.y-c.y}]),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},m(yy,"id","pointing"),yy);class Ph extends se{constructor(){super(...arguments);m(this,"onCreate")}}m(Ph,"id","box"),m(Ph,"initial","idle"),m(Ph,"children",()=>[y8,S8]);function Vf(e){const t=z();return K("isEditing",()=>t.getEditingShapeId()===e,[t,e])}function v8(){return x.useId().replace(/:/g,"_")}function Xr(e){const t=z();return x.useMemo(function(){const o=l=>{if(l.isKilled)return;if(l.button===2){t.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",..._n(l)});return}if(l.button!==0)return;const u=Yp(l.currentTarget);function d(){u.removeEventListener("pointerup",d),Au(u,l)}Mu(u,l),u.addEventListener("pointerup",d),t.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,..._n(l)}),Ut(l)};let s,i;function a(l){l.isKilled||l.button===0&&(l.clientX===s&&l.clientY===i||(s=l.clientX,i=l.clientY,t.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,..._n(l)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:l=>{l.isKilled||l.button===0&&t.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,..._n(l)})}}},[t,e])}const x8=20,w8=8;function ux(e,t=x8){return Math.max(w8,Math.ceil(e/t))}class X2 extends Hi{constructor(n){super({...n,isFilled:!1,isClosed:!1});m(this,"_center");m(this,"radius");m(this,"start");m(this,"end");m(this,"measure");m(this,"length");m(this,"angleStart");m(this,"angleEnd");const{center:r,radius:o,sweepFlag:s,largeArcFlag:i,start:a,end:c}=n;if(a.equals(c))throw Error("Arc must have different start and end points.");this.angleStart=P.Angle(r,a),this.angleEnd=P.Angle(r,c),this.measure=b5(this.angleStart,this.angleEnd,s,i),this.length=this.measure*o,this.start=a,this.end=c,this._center=r,this.radius=o}nearestPoint(n){const{_center:r,measure:o,radius:s,angleEnd:i,angleStart:a,start:c,end:l}=this,u=FS(o,a,i,r.angle(n));if(u<=0)return c;if(u>=1)return l;const d=r.clone().add(n.clone().sub(r).uni().mul(s));let p,f=1/0,y;for(const g of[c,l,d])y=P.Dist2(n,g),y<f&&(p=g,f=y);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(n,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:c}=this,l=Nf(n,r,o,s);return l===null?!1:l.some(u=>{const d=FS(i,a,c,o.angle(u));return d>=0&&d<=1})}getVertices(){const{_center:n,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let c=0,l=ux(Math.abs(o));c<l+1;c++){const u=c/l*r,d=i+u;a.push($i(n,s,d))}return a}}class dx extends Hi{constructor(n){super({isClosed:!0,...n});m(this,"_center");m(this,"radius");m(this,"x");m(this,"y");this.config=n;const{x:r=0,y:o=0,radius:s}=n;this.x=r,this.y=o,this._center=new P(s+r,s+o),this.radius=s}getBounds(){return new ne(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,o=Oe*r,s=[];for(let i=0,a=ux(o);i<a;i++){const c=i/a*Oe;s.push($i(n,r,c))}return s}nearestPoint(n){const{_center:r,radius:o}=this;return r.equals(n)?P.AddXY(r,o,0):r.clone().add(n.clone().sub(r).uni().mul(o))}hitTestLineSegment(n,r,o=0){const{_center:s,radius:i}=this;return Nf(n,r,s,i+o)!==null}}class b8 extends Ki{constructor(n){const{start:r,cp1:o,cp2:s,end:i}=n;super({...n,points:[r,i]});m(this,"a");m(this,"b");m(this,"c");m(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const n=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,c=10;a<=c;a++){const l=a/c;n.push(new P((1-l)*(1-l)*(1-l)*r.x+3*((1-l)*(1-l))*l*o.x+3*(1-l)*(l*l)*s.x+l*l*l*i.x,(1-l)*(1-l)*(1-l)*r.y+3*((1-l)*(1-l))*l*o.y+3*(1-l)*(l*l)*s.y+l*l*l*i.y))}return n}midPoint(){return P8(this,.5)}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(n),s=P.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}}function P8(e,t){const{a:n,b:r,c:o,d:s}=e;return new P((1-t)*(1-t)*(1-t)*n.x+3*((1-t)*(1-t))*t*r.x+3*(1-t)*(t*t)*o.x+t*t*t*s.x,(1-t)*(1-t)*(1-t)*n.y+3*((1-t)*(1-t))*t*r.y+3*(1-t)*(t*t)*o.y+t*t*t*s.y)}class C8 extends Hi{constructor(n){super({...n,isClosed:!1,isFilled:!1});m(this,"points");m(this,"_segments");m(this,"_length");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?n[0]:n[i-1],c=n[i],l=n[i+1],u=i===o?l:n[i+2],d=c,p=i===0?a:new P(c.x+(l.x-a.x)/6*s,c.y+(l.y-a.y)/6*s),f=i===o?l:new P(l.x-(u.x-c.x)/6*s,l.y-(u.y-c.y)/6*s),y=l;this._segments.push(new b8({start:d,cp1:p,cp2:f,end:y}))}}return this._segments}get length(){return this._length||(this._length=this.segments.reduce((n,r)=>n+r.length,0)),this._length}getVertices(){const n=this.segments.reduce((r,o)=>r.concat(o.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(n),s=P.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(o=>o.hitTestLineSegment(n,r))}}class q2 extends Hi{constructor(n){super({...n,isClosed:!0});m(this,"w");m(this,"h");m(this,"_edges");this.config=n;const{width:r,height:o}=n;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];this._edges.push(new lu({start:s,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),o=n/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=Pe*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),c=ux(a),l=Oe/c,u=Math.cos(l),d=Math.sin(l);let p=0,f=1,y=0,g=1;const w=Array(c);for(let S=0;S<c;S++)w[S]=new P(o+o*f,s+s*p),y=d*f+u*p,g=u*f-d*p,p=y,f=g;return w}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(n),s=P.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(o=>o.hitTestLineSegment(n,r))}getBounds(){return new ne(0,0,this.w,this.h)}}const Co=18;class I8 extends q2{constructor(t){super({...t}),this.config=t}getVertices(){const t=Math.max(1,this.w),n=Math.max(1,this.h),r=t/2,o=n/2,s=Array(Co);let i,a;if(n>t)for(let c=0;c<Co-1;c++)i=-Pe+Pe*c/(Co-2),a=Pe*c/(Co-2),s[c]=new P(r+r*Math.cos(i),r+r*Math.sin(i)),s[c+(Co-1)]=new P(r+r*Math.cos(a),n-r+r*Math.sin(a));else for(let c=0;c<Co-1;c++)i=-ze+Pe*c/(Co-2),a=ze+Pe*-c/(Co-2),s[c]=new P(t-o+o*Math.cos(i),n-o+o*Math.sin(i)),s[c+(Co-1)]=new P(o-o*Math.cos(a),n-o+o*Math.sin(a));return s}}function sP(e,t,n,r,o){const s=R5,i=n?L5:0,a=e-i,c=e+i,l=r?0:s,u=o?t:t-s;return a<l?Math.min(1,(l-a)/s):c>u?-Math.min(1,(c-u)/s):0}function hx(e){if(!e.inputs.isDragging||e.inputs.isPanning||!e.getInstanceState().canMoveCamera)return;const{inputs:{currentScreenPoint:{x:t,y:n}}}=e,r=e.getZoomLevel(),o=e.getViewportScreenBounds(),s=o.w<1e3?.612:1,i=o.h<1e3?.612:1,{isCoarsePointer:a,insets:[c,l,u,d]}=e.getInstanceState(),p=sP(t,o.w,a,d,l),f=sP(n,o.h,a,c,u);if(p===0&&f===0)return;const y=e.user.getEdgeScrollSpeed()*D5,g=y*p*s/r,w=y*f*i/r,S=e.getCamera();e.setCamera({x:S.x+g,y:S.y+w})}async function E8({shouldReload:e=!0}={}){B3(),await Promise.all(lx().map(t=>Vz(t))),z3(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=E8);function _8(e,t="_blank"){J0.openWindow(e,t)}var Jc=function(e){return e&&e.Math===Math&&e},Dn=Jc(typeof globalThis=="object"&&globalThis)||Jc(typeof window=="object"&&window)||Jc(typeof self=="object"&&self)||Jc(typeof tn=="object"&&tn)||Jc(typeof tn=="object"&&tn)||function(){return this}()||Function("return this")(),px={},vn=function(e){try{return!!e()}catch{return!0}},k8=vn,Xs=!k8(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),T8=vn,Gf=!T8(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),$8=Gf,Td=Function.prototype.call,es=$8?Td.bind(Td):function(){return Td.apply(Td,arguments)},Z2={},Q2={}.propertyIsEnumerable,J2=Object.getOwnPropertyDescriptor,M8=J2&&!Q2.call({1:2},1);Z2.f=M8?function(t){var n=J2(this,t);return!!n&&n.enumerable}:Q2;var eT=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},tT=Gf,nT=Function.prototype,GS=nT.call,A8=tT&&nT.bind.bind(GS,GS),jt=tT?A8:function(e){return function(){return GS.apply(e,arguments)}},rT=jt,j8=rT({}.toString),O8=rT("".slice),Cc=function(e){return O8(j8(e),8,-1)},D8=jt,R8=vn,L8=Cc,Cm=Object,F8=D8("".split),N8=R8(function(){return!Cm("z").propertyIsEnumerable(0)})?function(e){return L8(e)==="String"?F8(e,""):Cm(e)}:Cm,Yf=function(e){return e==null},z8=Yf,B8=TypeError,Ic=function(e){if(z8(e))throw new B8("Can't call method on "+e);return e},U8=N8,H8=Ic,Xf=function(e){return U8(H8(e))},Im=typeof document=="object"&&document.all,xn=typeof Im>"u"&&Im!==void 0?function(e){return typeof e=="function"||e===Im}:function(e){return typeof e=="function"},K8=xn,Wi=function(e){return typeof e=="object"?e!==null:K8(e)},Em=Dn,W8=xn,V8=function(e){return W8(e)?e:void 0},qf=function(e,t){return arguments.length<2?V8(Em[e]):Em[e]&&Em[e][t]},G8=jt,oT=G8({}.isPrototypeOf),Y8=typeof navigator<"u"&&String(navigator.userAgent)||"",sT=Dn,_m=Y8,iP=sT.process,aP=sT.Deno,cP=iP&&iP.versions||aP&&aP.version,lP=cP&&cP.v8,Ar,tf;lP&&(Ar=lP.split("."),tf=Ar[0]>0&&Ar[0]<4?1:+(Ar[0]+Ar[1]));!tf&&_m&&(Ar=_m.match(/Edge\/(\d+)/),(!Ar||Ar[1]>=74)&&(Ar=_m.match(/Chrome\/(\d+)/),Ar&&(tf=+Ar[1])));var X8=tf,uP=X8,q8=vn,Z8=Dn,Q8=Z8.String,iT=!!Object.getOwnPropertySymbols&&!q8(function(){var e=Symbol("symbol detection");return!Q8(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&uP&&uP<41}),J8=iT,aT=J8&&!Symbol.sham&&typeof Symbol.iterator=="symbol",e7=qf,t7=xn,n7=oT,r7=aT,o7=Object,cT=r7?function(e){return typeof e=="symbol"}:function(e){var t=e7("Symbol");return t7(t)&&n7(t.prototype,o7(e))},s7=String,i7=function(e){try{return s7(e)}catch{return"Object"}},a7=xn,c7=i7,l7=TypeError,fx=function(e){if(a7(e))return e;throw new l7(c7(e)+" is not a function")},u7=fx,d7=Yf,gx=function(e,t){var n=e[t];return d7(n)?void 0:u7(n)},km=es,Tm=xn,$m=Wi,h7=TypeError,p7=function(e,t){var n,r;if(t==="string"&&Tm(n=e.toString)&&!$m(r=km(n,e))||Tm(n=e.valueOf)&&!$m(r=km(n,e))||t!=="string"&&Tm(n=e.toString)&&!$m(r=km(n,e)))return r;throw new h7("Can't convert object to primitive value")},lT={exports:{}},dP=Dn,f7=Object.defineProperty,mx=function(e,t){try{f7(dP,e,{value:t,configurable:!0,writable:!0})}catch{dP[e]=t}return t},g7=Dn,m7=mx,hP="__core-js_shared__",pP=lT.exports=g7[hP]||m7(hP,{});(pP.versions||(pP.versions=[])).push({version:"3.37.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.37.1/LICENSE",source:"https://github.com/zloirock/core-js"});var yx=lT.exports,fP=yx,Sx=function(e,t){return fP[e]||(fP[e]=t||{})},y7=Ic,S7=Object,Lu=function(e){return S7(y7(e))},v7=jt,x7=Lu,w7=v7({}.hasOwnProperty),qs=Object.hasOwn||function(t,n){return w7(x7(t),n)},b7=jt,P7=0,C7=Math.random(),I7=b7(1 .toString),uT=function(e){return"Symbol("+(e===void 0?"":e)+")_"+I7(++P7+C7,36)},E7=Dn,_7=Sx,gP=qs,k7=uT,T7=iT,$7=aT,Aa=E7.Symbol,Mm=_7("wks"),M7=$7?Aa.for||Aa:Aa&&Aa.withoutSetter||k7,ts=function(e){return gP(Mm,e)||(Mm[e]=T7&&gP(Aa,e)?Aa[e]:M7("Symbol."+e)),Mm[e]},A7=es,mP=Wi,yP=cT,j7=gx,O7=p7,D7=ts,R7=TypeError,L7=D7("toPrimitive"),F7=function(e,t){if(!mP(e)||yP(e))return e;var n=j7(e,L7),r;if(n){if(t===void 0&&(t="default"),r=A7(n,e,t),!mP(r)||yP(r))return r;throw new R7("Can't convert object to primitive value")}return t===void 0&&(t="number"),O7(e,t)},N7=F7,z7=cT,dT=function(e){var t=N7(e,"string");return z7(t)?t:t+""},B7=Dn,SP=Wi,YS=B7.document,U7=SP(YS)&&SP(YS.createElement),hT=function(e){return U7?YS.createElement(e):{}},H7=Xs,K7=vn,W7=hT,pT=!H7&&!K7(function(){return Object.defineProperty(W7("div"),"a",{get:function(){return 7}}).a!==7}),V7=Xs,G7=es,Y7=Z2,X7=eT,q7=Xf,Z7=dT,Q7=qs,J7=pT,vP=Object.getOwnPropertyDescriptor;px.f=V7?vP:function(t,n){if(t=q7(t),n=Z7(n),J7)try{return vP(t,n)}catch{}if(Q7(t,n))return X7(!G7(Y7.f,t,n),t[n])};var Ec={},eB=Xs,tB=vn,fT=eB&&tB(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),nB=Wi,rB=String,oB=TypeError,Vi=function(e){if(nB(e))return e;throw new oB(rB(e)+" is not an object")},sB=Xs,iB=pT,aB=fT,$d=Vi,xP=dT,cB=TypeError,Am=Object.defineProperty,lB=Object.getOwnPropertyDescriptor,jm="enumerable",Om="configurable",Dm="writable";Ec.f=sB?aB?function(t,n,r){if($d(t),n=xP(n),$d(r),typeof t=="function"&&n==="prototype"&&"value"in r&&Dm in r&&!r[Dm]){var o=lB(t,n);o&&o[Dm]&&(t[n]=r.value,r={configurable:Om in r?r[Om]:o[Om],enumerable:jm in r?r[jm]:o[jm],writable:!1})}return Am(t,n,r)}:Am:function(t,n,r){if($d(t),n=xP(n),$d(r),iB)try{return Am(t,n,r)}catch{}if("get"in r||"set"in r)throw new cB("Accessors not supported");return"value"in r&&(t[n]=r.value),t};var uB=Xs,dB=Ec,hB=eT,vx=uB?function(e,t,n){return dB.f(e,t,hB(1,n))}:function(e,t,n){return e[t]=n,e},gT={exports:{}},XS=Xs,pB=qs,mT=Function.prototype,fB=XS&&Object.getOwnPropertyDescriptor,xx=pB(mT,"name"),gB=xx&&(function(){}).name==="something",mB=xx&&(!XS||XS&&fB(mT,"name").configurable),yB={EXISTS:xx,PROPER:gB,CONFIGURABLE:mB},SB=jt,vB=xn,qS=yx,xB=SB(Function.toString);vB(qS.inspectSource)||(qS.inspectSource=function(e){return xB(e)});var yT=qS.inspectSource,wB=Dn,bB=xn,wP=wB.WeakMap,PB=bB(wP)&&/native code/.test(String(wP)),CB=Sx,IB=uT,bP=CB("keys"),ST=function(e){return bP[e]||(bP[e]=IB(e))},wx={},EB=PB,vT=Dn,_B=Wi,kB=vx,Rm=qs,Lm=yx,TB=ST,$B=wx,PP="Object already initialized",ZS=vT.TypeError,MB=vT.WeakMap,nf,uu,rf,AB=function(e){return rf(e)?uu(e):nf(e,{})},jB=function(e){return function(t){var n;if(!_B(t)||(n=uu(t)).type!==e)throw new ZS("Incompatible receiver, "+e+" required");return n}};if(EB||Lm.state){var Gr=Lm.state||(Lm.state=new MB);Gr.get=Gr.get,Gr.has=Gr.has,Gr.set=Gr.set,nf=function(e,t){if(Gr.has(e))throw new ZS(PP);return t.facade=e,Gr.set(e,t),t},uu=function(e){return Gr.get(e)||{}},rf=function(e){return Gr.has(e)}}else{var sa=TB("state");$B[sa]=!0,nf=function(e,t){if(Rm(e,sa))throw new ZS(PP);return t.facade=e,kB(e,sa,t),t},uu=function(e){return Rm(e,sa)?e[sa]:{}},rf=function(e){return Rm(e,sa)}}var xT={set:nf,get:uu,has:rf,enforce:AB,getterFor:jB},bx=jt,OB=vn,DB=xn,Md=qs,QS=Xs,RB=yB.CONFIGURABLE,LB=yT,wT=xT,FB=wT.enforce,NB=wT.get,CP=String,Ch=Object.defineProperty,zB=bx("".slice),BB=bx("".replace),UB=bx([].join),HB=QS&&!OB(function(){return Ch(function(){},"length",{value:8}).length!==8}),KB=String(String).split("String"),WB=gT.exports=function(e,t,n){zB(CP(t),0,7)==="Symbol("&&(t="["+BB(CP(t),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(t="get "+t),n&&n.setter&&(t="set "+t),(!Md(e,"name")||RB&&e.name!==t)&&(QS?Ch(e,"name",{value:t,configurable:!0}):e.name=t),HB&&n&&Md(n,"arity")&&e.length!==n.arity&&Ch(e,"length",{value:n.arity});try{n&&Md(n,"constructor")&&n.constructor?QS&&Ch(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=FB(e);return Md(r,"source")||(r.source=UB(KB,typeof t=="string"?t:"")),e};Function.prototype.toString=WB(function(){return DB(this)&&NB(this).source||LB(this)},"toString");var VB=gT.exports,GB=xn,YB=Ec,XB=VB,qB=mx,bT=function(e,t,n,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:t;if(GB(n)&&XB(n,s,r),r.global)o?e[t]=n:qB(t,n);else{try{r.unsafe?e[t]&&(o=!0):delete e[t]}catch{}o?e[t]=n:YB.f(e,t,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},PT={},ZB=Math.ceil,QB=Math.floor,JB=Math.trunc||function(t){var n=+t;return(n>0?QB:ZB)(n)},e9=JB,Gi=function(e){var t=+e;return t!==t||t===0?0:e9(t)},t9=Gi,n9=Math.max,r9=Math.min,o9=function(e,t){var n=t9(e);return n<0?n9(n+t,0):r9(n,t)},s9=Gi,i9=Math.min,CT=function(e){var t=s9(e);return t>0?i9(t,9007199254740991):0},a9=CT,Fu=function(e){return a9(e.length)},c9=Xf,l9=o9,u9=Fu,IP=function(e){return function(t,n,r){var o=c9(t),s=u9(o);if(s===0)return!e&&-1;var i=l9(r,s),a;if(e&&n!==n){for(;s>i;)if(a=o[i++],a!==a)return!0}else for(;s>i;i++)if((e||i in o)&&o[i]===n)return e||i||0;return!e&&-1}},d9={includes:IP(!0),indexOf:IP(!1)},h9=jt,Fm=qs,p9=Xf,f9=d9.indexOf,g9=wx,EP=h9([].push),IT=function(e,t){var n=p9(e),r=0,o=[],s;for(s in n)!Fm(g9,s)&&Fm(n,s)&&EP(o,s);for(;t.length>r;)Fm(n,s=t[r++])&&(~f9(o,s)||EP(o,s));return o},Px=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],m9=IT,y9=Px,S9=y9.concat("length","prototype");PT.f=Object.getOwnPropertyNames||function(t){return m9(t,S9)};var ET={};ET.f=Object.getOwnPropertySymbols;var v9=qf,x9=jt,w9=PT,b9=ET,P9=Vi,C9=x9([].concat),I9=v9("Reflect","ownKeys")||function(t){var n=w9.f(P9(t)),r=b9.f;return r?C9(n,r(t)):n},_P=qs,E9=I9,_9=px,k9=Ec,T9=function(e,t,n){for(var r=E9(t),o=k9.f,s=_9.f,i=0;i<r.length;i++){var a=r[i];!_P(e,a)&&!(n&&_P(n,a))&&o(e,a,s(t,a))}},$9=vn,M9=xn,A9=/#|\.prototype\./,Nu=function(e,t){var n=O9[j9(e)];return n===R9?!0:n===D9?!1:M9(t)?$9(t):!!t},j9=Nu.normalize=function(e){return String(e).replace(A9,".").toLowerCase()},O9=Nu.data={},D9=Nu.NATIVE="N",R9=Nu.POLYFILL="P",L9=Nu,Ad=Dn,F9=px.f,N9=vx,z9=bT,B9=mx,U9=T9,H9=L9,_c=function(e,t){var n=e.target,r=e.global,o=e.stat,s,i,a,c,l,u;if(r?i=Ad:o?i=Ad[n]||B9(n,{}):i=Ad[n]&&Ad[n].prototype,i)for(a in t){if(l=t[a],e.dontCallGetSet?(u=F9(i,a),c=u&&u.value):c=i[a],s=H9(r?a:n+(o?".":"#")+a,e.forced),!s&&c!==void 0){if(typeof l==typeof c)continue;U9(l,c)}(e.sham||c&&c.sham)&&N9(l,"sham",!0),z9(i,a,l,e)}},_T={},K9=IT,W9=Px,V9=Object.keys||function(t){return K9(t,W9)},G9=Xs,Y9=fT,X9=Ec,q9=Vi,Z9=Xf,Q9=V9;_T.f=G9&&!Y9?Object.defineProperties:function(t,n){q9(t);for(var r=Z9(n),o=Q9(n),s=o.length,i=0,a;s>i;)X9.f(t,a=o[i++],r[a]);return t};var J9=qf,eU=J9("document","documentElement"),tU=Vi,nU=_T,kP=Px,rU=wx,oU=eU,sU=hT,iU=ST,TP=">",$P="<",JS="prototype",ev="script",kT=iU("IE_PROTO"),Nm=function(){},TT=function(e){return $P+ev+TP+e+$P+"/"+ev+TP},MP=function(e){e.write(TT("")),e.close();var t=e.parentWindow.Object;return e=null,t},aU=function(){var e=sU("iframe"),t="java"+ev+":",n;return e.style.display="none",oU.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(TT("document.F=Object")),n.close(),n.F},jd,Ih=function(){try{jd=new ActiveXObject("htmlfile")}catch{}Ih=typeof document<"u"?document.domain&&jd?MP(jd):aU():MP(jd);for(var e=kP.length;e--;)delete Ih[JS][kP[e]];return Ih()};rU[kT]=!0;var $T=Object.create||function(t,n){var r;return t!==null?(Nm[JS]=tU(t),r=new Nm,Nm[JS]=null,r[kT]=t):r=Ih(),n===void 0?r:nU.f(r,n)},cU=ts,lU=$T,uU=Ec.f,tv=cU("unscopables"),nv=Array.prototype;nv[tv]===void 0&&uU(nv,tv,{configurable:!0,value:lU(null)});var Cx=function(e){nv[tv][e]=!0},dU=_c,hU=Lu,pU=Fu,fU=Gi,gU=Cx;dU({target:"Array",proto:!0},{at:function(t){var n=hU(this),r=pU(n),o=fU(t),s=o>=0?o:r+o;return s<0||s>=r?void 0:n[s]}});gU("at");var mU=Dn,yU=jt,zu=function(e,t){return yU(mU[e].prototype[t])},SU=zu;SU("Array","at");var vU=Cc,MT=Array.isArray||function(t){return vU(t)==="Array"},xU=TypeError,wU=9007199254740991,bU=function(e){if(e>wU)throw xU("Maximum allowed index exceeded");return e},PU=Cc,CU=jt,IU=function(e){if(PU(e)==="Function")return CU(e)},AP=IU,EU=fx,_U=Gf,kU=AP(AP.bind),TU=function(e,t){return EU(e),t===void 0?e:_U?kU(e,t):function(){return e.apply(t,arguments)}},$U=MT,MU=Fu,AU=bU,jU=TU,AT=function(e,t,n,r,o,s,i,a){for(var c=o,l=0,u=i?jU(i,a):!1,d,p;l<r;)l in n&&(d=u?u(n[l],l,t):n[l],s>0&&$U(d)?(p=MU(d),c=AT(e,t,d,p,c,s-1)-1):(AU(c+1),e[c]=d),c++),l++;return c},jT=AT,OU=ts,DU=OU("toStringTag"),OT={};OT[DU]="z";var RU=String(OT)==="[object z]",LU=RU,FU=xn,Eh=Cc,NU=ts,zU=NU("toStringTag"),BU=Object,UU=Eh(function(){return arguments}())==="Arguments",HU=function(e,t){try{return e[t]}catch{}},DT=LU?Eh:function(e){var t,n,r;return e===void 0?"Undefined":e===null?"Null":typeof(n=HU(t=BU(e),zU))=="string"?n:UU?Eh(t):(r=Eh(t))==="Object"&&FU(t.callee)?"Arguments":r},KU=jt,WU=vn,RT=xn,VU=DT,GU=qf,YU=yT,LT=function(){},FT=GU("Reflect","construct"),Ix=/^\s*(?:class|function)\b/,XU=KU(Ix.exec),qU=!Ix.test(LT),el=function(t){if(!RT(t))return!1;try{return FT(LT,[],t),!0}catch{return!1}},NT=function(t){if(!RT(t))return!1;switch(VU(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return qU||!!XU(Ix,YU(t))}catch{return!0}};NT.sham=!0;var ZU=!FT||WU(function(){var e;return el(el.call)||!el(Object)||!el(function(){e=!0})||e})?NT:el,jP=MT,QU=ZU,JU=Wi,eH=ts,tH=eH("species"),OP=Array,nH=function(e){var t;return jP(e)&&(t=e.constructor,QU(t)&&(t===OP||jP(t.prototype))?t=void 0:JU(t)&&(t=t[tH],t===null&&(t=void 0))),t===void 0?OP:t},rH=nH,zT=function(e,t){return new(rH(e))(t===0?0:t)},oH=_c,sH=jT,iH=fx,aH=Lu,cH=Fu,lH=zT;oH({target:"Array",proto:!0},{flatMap:function(t){var n=aH(this),r=cH(n),o;return iH(t),o=lH(n,0),o.length=sH(o,n,n,r,0,1,t,arguments.length>1?arguments[1]:void 0),o}});var uH=Cx;uH("flatMap");var dH=zu;dH("Array","flatMap");var hH=_c,pH=jT,fH=Lu,gH=Fu,mH=Gi,yH=zT;hH({target:"Array",proto:!0},{flat:function(){var t=arguments.length?arguments[0]:void 0,n=fH(this),r=gH(n),o=yH(n,0);return o.length=pH(o,n,n,r,0,t===void 0?1:mH(t)),o}});var SH=Cx;SH("flat");var vH=zu;vH("Array","flat");var xH=DT,wH=String,Bu=function(e){if(xH(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return wH(e)},bH=_c,PH=jt,CH=Ic,IH=Gi,EH=Bu,_H=vn,kH=PH("".charAt),TH=_H(function(){return"𠮷".at(-2)!=="\uD842"});bH({target:"String",proto:!0,forced:TH},{at:function(t){var n=EH(CH(this)),r=n.length,o=IH(t),s=o>=0?o:r+o;return s<0||s>=r?void 0:kH(n,s)}});var $H=zu;$H("String","at");var MH=Vi,BT=function(){var e=MH(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},Ex=vn,AH=Dn,_x=AH.RegExp,kx=Ex(function(){var e=_x("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),jH=kx||Ex(function(){return!_x("a","y").sticky}),OH=kx||Ex(function(){var e=_x("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),DH={BROKEN_CARET:OH,MISSED_STICKY:jH,UNSUPPORTED_Y:kx},RH=vn,LH=Dn,FH=LH.RegExp,NH=RH(function(){var e=FH(".","s");return!(e.dotAll&&e.test(`
`)&&e.flags==="s")}),zH=vn,BH=Dn,UH=BH.RegExp,HH=zH(function(){var e=UH("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),ja=es,Zf=jt,KH=Bu,WH=BT,VH=DH,GH=Sx,YH=$T,XH=xT.get,qH=NH,ZH=HH,QH=GH("native-string-replace",String.prototype.replace),of=RegExp.prototype.exec,rv=of,JH=Zf("".charAt),eK=Zf("".indexOf),tK=Zf("".replace),zm=Zf("".slice),ov=function(){var e=/a/,t=/b*/g;return ja(of,e,"a"),ja(of,t,"a"),e.lastIndex!==0||t.lastIndex!==0}(),UT=VH.BROKEN_CARET,sv=/()??/.exec("")[1]!==void 0,nK=ov||sv||UT||qH||ZH;nK&&(rv=function(t){var n=this,r=XH(n),o=KH(t),s=r.raw,i,a,c,l,u,d,p;if(s)return s.lastIndex=n.lastIndex,i=ja(rv,s,o),n.lastIndex=s.lastIndex,i;var f=r.groups,y=UT&&n.sticky,g=ja(WH,n),w=n.source,S=0,v=o;if(y&&(g=tK(g,"y",""),eK(g,"g")===-1&&(g+="g"),v=zm(o,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&JH(o,n.lastIndex-1)!==`
`)&&(w="(?: "+w+")",v=" "+v,S++),a=new RegExp("^(?:"+w+")",g)),sv&&(a=new RegExp("^"+w+"$(?!\\s)",g)),ov&&(c=n.lastIndex),l=ja(of,y?a:n,v),y?l?(l.input=zm(l.input,S),l[0]=zm(l[0],S),l.index=n.lastIndex,n.lastIndex+=l[0].length):n.lastIndex=0:ov&&l&&(n.lastIndex=n.global?l.index+l[0].length:c),sv&&l&&l.length>1&&ja(QH,l[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(l[u]=void 0)}),l&&f)for(l.groups=d=YH(null),u=0;u<f.length;u++)p=f[u],d[p[0]]=l[p[1]];return l});var Tx=rv,rK=_c,DP=Tx;rK({target:"RegExp",proto:!0,forced:/./.exec!==DP},{exec:DP});var oK=Gf,HT=Function.prototype,RP=HT.apply,LP=HT.call,sK=typeof Reflect=="object"&&Reflect.apply||(oK?LP.bind(RP):function(){return LP.apply(RP,arguments)}),FP=es,NP=bT,iK=Tx,zP=vn,KT=ts,aK=vx,cK=KT("species"),Bm=RegExp.prototype,lK=function(e,t,n,r){var o=KT(e),s=!zP(function(){var l={};return l[o]=function(){return 7},""[e](l)!==7}),i=s&&!zP(function(){var l=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[cK]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return l=!0,null},u[o](""),!l});if(!s||!i||n){var a=/./[o],c=t(o,""[e],function(l,u,d,p,f){var y=u.exec;return y===iK||y===Bm.exec?s&&!f?{done:!0,value:FP(a,u,d,p)}:{done:!0,value:FP(l,d,u,p)}:{done:!1}});NP(String.prototype,e,c[0]),NP(Bm,o,c[1])}r&&aK(Bm[o],"sham",!0)},$x=jt,uK=Gi,dK=Bu,hK=Ic,pK=$x("".charAt),BP=$x("".charCodeAt),fK=$x("".slice),UP=function(e){return function(t,n){var r=dK(hK(t)),o=uK(n),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=BP(r,o),i<55296||i>56319||o+1===s||(a=BP(r,o+1))<56320||a>57343?e?pK(r,o):i:e?fK(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},gK={codeAt:UP(!1),charAt:UP(!0)},mK=gK.charAt,yK=function(e,t,n){return t+(n?mK(e,t).length:1)},Mx=jt,SK=Lu,vK=Math.floor,Um=Mx("".charAt),xK=Mx("".replace),Hm=Mx("".slice),wK=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,bK=/\$([$&'`]|\d{1,2})/g,WT=function(e,t,n,r,o,s){var i=n+e.length,a=r.length,c=bK;return o!==void 0&&(o=SK(o),c=wK),xK(s,c,function(l,u){var d;switch(Um(u,0)){case"$":return"$";case"&":return e;case"`":return Hm(t,0,n);case"'":return Hm(t,i);case"<":d=o[Hm(u,1,-1)];break;default:var p=+u;if(p===0)return l;if(p>a){var f=vK(p/10);return f===0?l:f<=a?r[f-1]===void 0?Um(u,1):r[f-1]+Um(u,1):l}d=r[p-1]}return d===void 0?"":d})},HP=es,PK=Vi,CK=xn,IK=Cc,EK=Tx,_K=TypeError,kK=function(e,t){var n=e.exec;if(CK(n)){var r=HP(n,e,t);return r!==null&&PK(r),r}if(IK(e)==="RegExp")return HP(EK,e,t);throw new _K("RegExp#exec called on incompatible receiver")},TK=sK,KP=es,Qf=jt,$K=lK,MK=vn,AK=Vi,jK=xn,OK=Yf,DK=Gi,RK=CT,ia=Bu,LK=Ic,FK=yK,NK=gx,zK=WT,BK=kK,UK=ts,iv=UK("replace"),HK=Math.max,KK=Math.min,WK=Qf([].concat),Km=Qf([].push),WP=Qf("".indexOf),VP=Qf("".slice),VK=function(e){return e===void 0?e:String(e)},GK=function(){return"a".replace(/./,"$0")==="$0"}(),GP=function(){return/./[iv]?/./[iv]("a","$0")==="":!1}(),YK=!MK(function(){var e=/./;return e.exec=function(){var t=[];return t.groups={a:"7"},t},"".replace(e,"$<a>")!=="7"});$K("replace",function(e,t,n){var r=GP?"$":"$0";return[function(s,i){var a=LK(this),c=OK(s)?void 0:NK(s,iv);return c?KP(c,s,a,i):KP(t,ia(a),s,i)},function(o,s){var i=AK(this),a=ia(o);if(typeof s=="string"&&WP(s,r)===-1&&WP(s,"$<")===-1){var c=n(t,i,a,s);if(c.done)return c.value}var l=jK(s);l||(s=ia(s));var u=i.global,d;u&&(d=i.unicode,i.lastIndex=0);for(var p=[],f;f=BK(i,a),!(f===null||(Km(p,f),!u));){var y=ia(f[0]);y===""&&(i.lastIndex=FK(a,RK(i.lastIndex),d))}for(var g="",w=0,S=0;S<p.length;S++){f=p[S];for(var v=ia(f[0]),b=HK(KK(DK(f.index),a.length),0),E=[],C,I=1;I<f.length;I++)Km(E,VK(f[I]));var _=f.groups;if(l){var k=WK([v],E,b,a);_!==void 0&&Km(k,_),C=ia(TK(s,void 0,k))}else C=zK(v,a,b,E,_,s);b>=w&&(g+=VP(a,w,b)+C,w=b+v.length)}return g+VP(a,w)}]},!YK||!GK||GP);var XK=Wi,qK=Cc,ZK=ts,QK=ZK("match"),JK=function(e){var t;return XK(e)&&((t=e[QK])!==void 0?!!t:qK(e)==="RegExp")},eW=es,tW=qs,nW=oT,rW=BT,YP=RegExp.prototype,oW=function(e){var t=e.flags;return t===void 0&&!("flags"in YP)&&!tW(e,"flags")&&nW(YP,e)?eW(rW,e):t},sW=_c,iW=es,Ax=jt,XP=Ic,aW=xn,cW=Yf,lW=JK,tl=Bu,uW=gx,dW=oW,hW=WT,pW=ts,fW=pW("replace"),gW=TypeError,Wm=Ax("".indexOf);Ax("".replace);var qP=Ax("".slice),mW=Math.max;sW({target:"String",proto:!0},{replaceAll:function(t,n){var r=XP(this),o,s,i,a,c,l,u,d,p,f=0,y=0,g="";if(!cW(t)){if(o=lW(t),o&&(s=tl(XP(dW(t))),!~Wm(s,"g")))throw new gW("`.replaceAll` does not allow non-global regexes");if(i=uW(t,fW),i)return iW(i,t,r,n)}for(a=tl(r),c=tl(t),l=aW(n),l||(n=tl(n)),u=c.length,d=mW(1,u),f=Wm(a,c);f!==-1;)p=l?tl(n(c,f,a)):hW(c,a,f,[],void 0,n),g+=qP(a,y,f)+p,y=f+u,f=f+d>a.length?-1:Wm(a,c,f+d);return y<a.length&&(g+=qP(a,y)),g}});var yW=zu;yW("String","replaceAll");function SW(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>!(!r||e.isShapeOfType(r,"arrow")&&r.props.start.type==="binding"||e.isShapeOfType(r,"arrow")&&r.props.end.type==="binding"))}const VT=()=>{const e=z();return K("threeStackableItems",()=>SW(e).length>2,[e])},GT=()=>{const e=z();return K("allow group",()=>{const t=e.getSelectedShapes();if(t.length<2)return!1;for(const n of t)if(e.isShapeOfType(n,"arrow")){const{start:r,end:o}=n.props;if(r.type==="binding"&&!t.some(s=>s.id===r.boundShapeId)||o.type==="binding"&&!t.some(s=>s.id===o.boundShapeId))return!1}return!0},[e])},YT=()=>{const e=z();return K("allowUngroup",()=>e.getSelectedShapeIds().some(t=>{var n;return((n=e.getShape(t))==null?void 0:n.type)==="group"}),[e])},vW=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function xW(e,t){const n=z();return K("selectedShapes",()=>n.getSelectedShapes().length>=e,[n,e,t])}function wn(e,t){const n=z();return K("selectedShapes",()=>{const r=n.getSelectedShapes().filter(o=>!n.isShapeOrAncestorLocked(o)).length;return e===void 0?r:r>=e},[n])}function wW(){const e=z();return K("showAutoSizeToggle",()=>{const t=e.getSelectedShapes();return t.length===1&&e.isShapeOfType(t[0],"text")&&t[0].props.autoSize===!1},[e])}function XT(){const e=z();return K("hasLinkShapeSelected",()=>{const t=e.getOnlySelectedShape();return!!(t&&t.type!=="embed"&&"url"in t.props&&!t.isLocked)},[e])}function bW(){const e=z();return K("onlyFlippableShape",()=>{const t=e.getOnlySelectedShape();return t&&(e.isShapeOfType(t,"group")||e.isShapeOfType(t,"arrow")||e.isShapeOfType(t,"line")||e.isShapeOfType(t,"draw"))},[e])}function qT(){const e=z();return K("useCanRedo",()=>e.getCanRedo(),[e])}function ZT(){const e=z();return K("useCanUndo",()=>e.getCanUndo(),[e])}function PW({children:e}){const t=z();return K("shouldDisplayHandles",()=>{if(t.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(t.isInAny("select.editing_shape")){const r=t.getOnlySelectedShape();return r&&t.isShapeOfType(r,"note")}return!1},[t])?h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:CW}=Math,Ga=CW+1e-4;function QT(e,t={}){const{size:n=16,smoothing:r=.5}=t;if(e.length===0||n<=0)return{left:[],right:[]};const o=e[0],s=e[e.length-1],i=s.runningLength,a=Math.pow(n*r,2),c=[],l=[];let u=e[0].vector,d=e[0].point,p=d,f=d,y=p,g=!1,w;for(let S=0;S<e.length;S++){w=e[S];const{point:v,vector:b}=e[S],E=w.vector.dpr(u),C=(S<e.length-1?e[S+1]:e[S]).vector,I=S<e.length-1?C.dpr(w.vector):1,_=E<0&&!g,k=I!==null&&I<.2;if(_||k){if(I>-.62&&i-w.runningLength>w.radius){const T=u.clone().mul(w.radius);u.clone().cpr(C)<0?(f=P.Add(v,T),y=P.Sub(v,T)):(f=P.Sub(v,T),y=P.Add(v,T)),c.push(f),l.push(y)}else{const T=u.clone().mul(w.radius).per(),O=P.Sub(w.input,T);for(let N=1/13,F=0;F<1;F+=N)f=P.RotWith(O,w.input,Ga*F),c.push(f),y=P.RotWith(O,w.input,Ga+Ga*-F),l.push(y)}d=f,p=y,k&&(g=!0);continue}if(g=!1,w===o||w===s){const T=P.Per(b).mul(w.radius);c.push(P.Sub(v,T)),l.push(P.Add(v,T));continue}const $=P.Lrp(C,b,I).per().mul(w.radius);f=P.Sub(v,$),(S<=1||P.Dist2(d,f)>a)&&(c.push(f),d=f),y=P.Add(v,$),(S<=1||P.Dist2(p,y)>a)&&(l.push(y),p=y),u=b}return{left:c,right:l}}function jx(e,t={}){const{size:n=16,start:r={},end:o={},last:s=!1}=t,{cap:i=!0}=r,{cap:a=!0}=o;if(e.length===0||n<=0)return[];const c=e[0],l=e[e.length-1],u=l.runningLength,d=r.taper===!1?0:r.taper===!0?Math.max(n,u):r.taper,p=o.taper===!1?0:o.taper===!0?Math.max(n,u):o.taper,{left:f,right:y}=QT(e,t),g=c.point,w=e.length>1?e[e.length-1].point:P.AddXY(c.point,1,1);if(e.length===1&&(!(d||p)||s)){const E=P.Add(g,P.Sub(g,w).uni().per().mul(-c.radius)),C=[];for(let I=1/13,_=I;_<=1;_+=I)C.push(P.RotWith(E,g,Ga*2*_));return C}const S=[];if(!(d||p&&e.length===1))if(i)for(let E=1/8,C=E;C<=1;C+=E){const I=P.RotWith(y[0],g,Ga*C);S.push(I)}else{const E=P.Sub(f[0],y[0]),C=P.Mul(E,.5),I=P.Mul(E,.51);S.push(P.Sub(g,C),P.Sub(g,I),P.Add(g,I),P.Add(g,C))}const v=[],b=l.vector.clone().per().neg();if(p||d&&e.length===1)v.push(w);else if(a){const E=P.Add(w,P.Mul(b,l.radius));for(let C=1/29,I=C;I<1;I+=C)v.push(P.RotWith(E,w,Ga*3*I))}else v.push(P.Add(w,P.Mul(b,l.radius)),P.Add(w,P.Mul(b,l.radius*.99)),P.Sub(w,P.Mul(b,l.radius*.99)),P.Sub(w,P.Mul(b,l.radius)));return f.concat(v,y.reverse(),S)}const IW=.025,EW=.01;function lo(e,t={}){var w;const{streamline:n=.5,size:r=16,simulatePressure:o=!1}=t;if(e.length===0)return[];const s=.15+(1-n)*.85;let i=e.map(P.From),a=0;if(!o){let S=i[0];for(;S&&!(S.z>=IW);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=EW);)i.pop(),S=i[i.length-1]}if(i.length===0)return[{point:P.From(e[0]),input:P.From(e[0]),pressure:o?.5:.15,vector:new P(1,1),distance:0,runningLength:0,radius:1}];let c=i[1];for(;c&&!(P.Dist2(c,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,c.z),i.splice(1,1),c=i[1];const l=i.pop();for(c=i[i.length-1];c&&!(P.Dist2(c,l)>(r/3)**2);)i.pop(),c=i[i.length-1],a++;i.push(l);const u=t.last||!t.simulatePressure||i.length>1&&P.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&t.simulatePressure){const S=i[1];i=i.slice(0,-1);for(let v=1;v<5;v++){const b=P.Lrp(i[0],S,v/4);b.z=(i[0].z+(S.z-i[0].z))*v/4,i.push(b)}}const d=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new P(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=d[0],y,g;u&&n>0&&i.push(i[i.length-1].clone());for(let S=1,v=i.length;S<v;S++)y=!s||t.last&&S===v-1?i[S].clone():i[S].clone().lrp(f.point,1-s),!f.point.equals(y)&&(g=P.Dist(y,f.point),p+=g,!(S<4&&p<r)&&(f={input:i[S],point:y,pressure:o?.5:i[S].z,vector:P.Sub(f.point,y).uni(),distance:g,runningLength:p,radius:1},d.push(f)));if((w=d[1])!=null&&w.vector&&(d[0].vector=d[1].vector.clone()),p<1){const S=Math.max(.5,...d.map(v=>v.pressure));d.forEach(v=>v.pressure=S)}return d}const{min:hs}=Math,Vm=.275;function Jf(e,t){const{size:n=16,thinning:r=.5,simulatePressure:o=!0,easing:s=w=>w,start:i={},end:a={}}=t,{easing:c=nn.easeOutQuad}=i,{easing:l=nn.easeOutCubic}=a,u=e[e.length-1].runningLength;let d,p=e[0].pressure,f;if(!o&&u<n){const w=e.reduce((S,v)=>Math.max(S,v.pressure),.5);return e.forEach(S=>{S.pressure=w,S.radius=n*s(.5-r*(.5-S.pressure))}),e}else{let w;for(let S=0,v=e.length;S<v&&(f=e[S],!(f.runningLength>n*5));S++){const b=hs(1,f.distance/n);if(o){const E=hs(1,1-b);w=hs(1,p+(E-p)*(b*Vm))}else w=hs(1,p+(f.pressure-p)*.5);p=p+(w-p)*.5}for(let S=0;S<e.length;S++){if(f=e[S],r){let{pressure:v}=f;const b=hs(1,f.distance/n);if(o){const E=hs(1,1-b);v=hs(1,p+(E-p)*(b*Vm))}else v=hs(1,p+(v-p)*(b*Vm));f.radius=n*s(.5-r*(.5-v)),p=v}else f.radius=n/2;d===void 0&&(d=f.radius)}}const y=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,g=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(y||g)for(let w=0;w<e.length;w++){f=e[w];const{runningLength:S}=f,v=S<y?c(S/y):1,b=u-S<g?l((u-S)/g):1;f.radius=Math.max(.01,f.radius*Math.min(v,b))}return e}function _W(e,t={}){return jx(Jf(lo(e,t),t),t)}function ZP({scribble:e,zoom:t,color:n,opacity:r,className:o}){if(!e.points.length)return null;const s=_W(e.points,{size:e.size/t,start:{taper:e.taper,easing:nn.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=e.size/t/2,{x:c,y:l}=e.points[e.points.length-1];i=`M ${c-a},${l} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=Z0(s);return h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:i,fill:n??`var(--color-${e.color})`,opacity:r??e.opacity})})}const kW=({bounds:e,rotation:t})=>{const n=z();return K("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?h.jsx(g2,{bounds:e,rotation:t}):null};function ns(){const e=z();return K("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function TW({size:e,width:t,height:n,hideAlternateHandles:r}){const o=j(e/3),s=o/2;return h.jsxs("svg",{className:"tl-overlays__item",children:[h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
${j(0-s)},${j(e)}
${j(0-s)},${j(0-s)}
${j(e)},${j(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:j(t/2-e),y1:j(0-s),x2:j(t/2+e),y2:j(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
${j(t-e)},${j(0-s)}
${j(t+s)},${j(0-s)}
${j(t+s)},${j(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:j(t+s),y1:j(n/2-e),x2:j(t+s),y2:j(n/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
${j(t+s)},${j(n-e)}
${j(t+s)},${j(n+s)}
${j(t-e)},${j(n+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:j(t/2-e),y1:j(n+s),x2:j(t/2+e),y2:j(n+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
${j(0+e)},${j(n+s)}
${j(0-s)},${j(n+s)}
${j(0-s)},${j(n-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:j(0-s),y1:j(n/2-e),x2:j(0-s),y2:j(n/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const $W=or(function({bounds:t,rotation:n}){const r=z(),o=x.useRef(null),s=ns(),i=Xr("top"),a=Xr("right"),c=Xr("bottom"),l=Xr("left"),u=Xr("top_left"),d=Xr("top_right"),p=Xr("bottom_right"),f=Xr("bottom_left"),y=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",g=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),S=w&&r.isShapeOrAncestorLocked(w),v=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0;if(xc(o,t==null?void 0:t.x,t==null?void 0:t.y,1,r.getSelectionRotation(),{x:-v,y:-v}),!t)return null;t=t.clone().expandBy(v).zeroFix();const b=r.getZoomLevel(),E=r.getInstanceState().isChangingStyle,C=t.width,I=t.height,_=8/b,k=C<_*2,$=I<_*2,T=C<_*4,O=I<_*4,N=C<_*5,F=I<_*5,L=g?1.75:1,B=6/b*L,q=(T?B/2:B)*(L*.75),Q=(O?B/2:B)*(L*.75),H=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!E;let U=H&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.pointing_resize_handle","select.pointing_crop_handle")||H&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&U&&r.environment.isFirefox&&r.isShapeOfType(w,"embed")&&(U=!1);const W=r.isInAny("select.pointing_crop_handle","select.crop.idle","select.crop.pointing_crop")&&!E&&!s,Z=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!E&&!s,le=!g&&!(k||$)&&(Z||W)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!S,be=g&&(!T||!O)&&(Z||W)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!S,Me=Z&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!W&&!S,ae=k||$,Ae=k&&$,Re=N||F,ot=Me||W,Ie=!le,ht=!Z||!be,He=!Z||!ot,ir=!Z||!ot||ae,Ln=!Z||!ot||ae,Fn=!Z||!ot||Ae&&!W;let qe=!0,Ot=!0;if(W)qe=Re,Ot=Re;else if(Me){qe=ae||Ae||g;const jc=g&&w&&w.type==="text";Ot=qe&&!jc}const wo=Math.min(24/b,I-Q*3),Ac=Z&&g&&w&&r.isShapeOfType(w,"text")&&wo*b>=4;return h.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsxs("g",{ref:o,children:[U&&h.jsx("rect",{className:"tl-selection__fg__outline",width:j(C),height:j(I)}),h.jsx(Od,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:B,corner:"top_left_rotate",cursor:y?Bn("nwse-rotate",n):void 0,isHidden:Ie}),h.jsx(Od,{"data-testid":"selection.rotate.top-right",cx:C+B*3,cy:0,targetSize:B,corner:"top_right_rotate",cursor:y?Bn("nesw-rotate",n):void 0,isHidden:Ie}),h.jsx(Od,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:I+B*3,targetSize:B,corner:"bottom_left_rotate",cursor:y?Bn("swne-rotate",n):void 0,isHidden:Ie}),h.jsx(Od,{"data-testid":"selection.rotate.bottom-right",cx:C+B*3,cy:I+B*3,targetSize:B,corner:"bottom_right_rotate",cursor:y?Bn("senw-rotate",n):void 0,isHidden:Ie}),h.jsx(AW,{"data-testid":"selection.rotate.mobile",cx:T?-B*1.5:C/2,cy:T?I/2:-B*1.5,size:_,isHidden:ht}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:j(0-(O?Q*2:Q)),width:j(C),height:j(Math.max(1,Q*2)),style:y?{cursor:Bn("ns-resize",n)}:void 0,...i}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Ot}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:j(C-(T?0:q)),y:0,height:j(I),width:j(Math.max(1,q*2)),style:y?{cursor:Bn("ew-resize",n)}:void 0,...a}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:j(I-(O?0:Q)),width:j(C),height:j(Math.max(1,Q*2)),style:y?{cursor:Bn("ns-resize",n)}:void 0,...c}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Ot}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:j(0-(T?q*2:q)),y:0,height:j(I),width:j(Math.max(1,q*2)),style:y?{cursor:Bn("ew-resize",n)}:void 0,...l}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":He}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:j(0-(T?q*2:q*1.5)),y:j(0-(O?Q*2:Q*1.5)),width:j(q*3),height:j(Q*3),style:y?{cursor:Bn("nwse-resize",n)}:void 0,...u}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":ir}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:j(C-(T?0:q*1.5)),y:j(0-(O?Q*2:Q*1.5)),width:j(q*3),height:j(Q*3),style:y?{cursor:Bn("nesw-resize",n)}:void 0,...d}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Fn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:j(C-(T?q:q*1.5)),y:j(I-(O?Q:Q*1.5)),width:j(q*3),height:j(Q*3),style:y?{cursor:Bn("nwse-resize",n)}:void 0,...p}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Ln}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:j(0-(T?q*3:q*1.5)),y:j(I-(O?0:Q*1.5)),width:j(q*3),height:j(Q*3),style:y?{cursor:Bn("nesw-resize",n)}:void 0,...f}),Me&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.resize.top-left",className:ue("tl-corner-handle",{"tl-hidden":He}),"aria-label":"top_left handle",x:j(0-_/2),y:j(0-_/2),width:j(_),height:j(_)}),h.jsx("rect",{"data-testid":"selection.resize.top-right",className:ue("tl-corner-handle",{"tl-hidden":ir}),"aria-label":"top_right handle",x:j(C-_/2),y:j(0-_/2),width:j(_),height:j(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ue("tl-corner-handle",{"tl-hidden":Fn}),"aria-label":"bottom_right handle",x:j(C-_/2),y:j(I-_/2),width:j(_),height:j(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ue("tl-corner-handle",{"tl-hidden":Ln}),"aria-label":"bottom_left handle",x:j(0-_/2),y:j(I-_/2),width:j(_),height:j(_)})]}),Ac&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:j(0-_/4),y:j(I/2-wo/2),rx:_/4,width:j(_/2),height:j(wo)}),h.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:_/4,x:j(C-_/4),y:j(I/2-wo/2),width:j(_/2),height:j(wo)})]}),W&&h.jsx(TW,{size:_,width:C,height:I,hideAlternateHandles:Re})]})})}),Od=function({cx:t,cy:n,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const c=Xr(o);return h.jsx("rect",{className:ue("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:j(t-r*3),y:j(n-r*3),width:j(Math.max(1,r*3)),height:j(Math.max(1,r*3)),cursor:s,...c})},MW=Math.sqrt(Math.PI),AW=function({cx:t,cy:n,size:r,isHidden:o,"data-testid":s}){const i=Xr("mobile_rotate"),a=z(),c=K("zoom level",()=>a.getZoomLevel(),[a]),l=Math.max(14*(1/c),20/Math.max(1,c));return h.jsxs("g",{children:[h.jsx("circle",{"data-testid":s,pointerEvents:"all",className:ue("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:t,cy:n,r:l,...i}),h.jsx("circle",{className:ue("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:t,cy:n,r:r/MW})]})},Ht={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},Mt={s:2,m:3.5,l:5,xl:10},ac={s:18,m:24,l:36,xl:44},Lo={s:18,m:22,l:26,xl:32},hi={s:18,m:20,l:24,xl:28},io={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},jW=20,OW=4.25,Tr=16;/*!
* canvas-size
* v1.2.6
* https://github.com/jhildenbiddle/canvas-size
* (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
* MIT license
*/function DW(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,o,s,i,a=[],c=!0,l=!1;try{if(s=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=s.call(n)).done)&&(a.push(r.value),a.length!==t);c=!0);}catch(u){l=!0,o=u}finally{try{if(!c&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(l)throw o}}return a}}function QP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function Un(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?QP(Object(n),!0).forEach(function(r){RW(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):QP(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function RW(e,t,n){return t=WW(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function LW(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function FW(e,t){if(e==null)return{};var n=LW(e,t),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function JP(e,t){return zW(e)||DW(e,t)||JT(e,t)||HW()}function Dd(e){return NW(e)||BW(e)||JT(e)||UW()}function NW(e){if(Array.isArray(e))return av(e)}function zW(e){if(Array.isArray(e))return e}function BW(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function JT(e,t){if(e){if(typeof e=="string")return av(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return av(e,t)}}function av(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function UW(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function HW(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function KW(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function WW(e){var t=KW(e,"string");return typeof t=="symbol"?t:String(t)}function jl(e){var t=e.sizes.shift(),n=Math.max(Math.ceil(t[0]),1),r=Math.max(Math.ceil(t[1]),1),o=[n-1,r-1,1,1],s=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,c;i?(a=new OffscreenCanvas(1,1),c=new OffscreenCanvas(n,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,c=document.createElement("canvas"),c.width=n,c.height=r);var l=a.getContext("2d"),u=c.getContext("2d");u&&(u.fillRect.apply(u,o),l.drawImage(c,n-1,r-1,1,1,0,0,1,1));var d=l&&l.getImageData(0,0,1,1).data[3]!==0,p=Date.now()-s;return[a,c].forEach(function(f){f.height=0,f.width=0}),i?(postMessage({width:n,height:r,benchmark:p,isTestPass:d}),!d&&e.sizes.length&&jl(e)):d?e.onSuccess(n,r,p):(e.onError(n,r,p),e.sizes.length&&jl(e)),d}var Gm={area:[16384,14188,11402,11180,10836,8192,4096,1],height:[8388607,65535,32767,16384,8192,4096,1],width:[4194303,65535,32767,16384,8192,4096,1]},VW=["onError","onSuccess"],Oa={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},nl={};function Ym(e){var t=e.width===e.height,n=e.height===1,r=e.width===1,o=[];if(!e.width||!e.height)e.sizes.forEach(function(u){var d=t||n?u:1,p=t||r?u:1;o.push([d,p])});else for(var s=e.min||Oa.min,i=e.step||Oa.step,a=Math.max(e.width,e.height);a>=s;){var c=t||n?a:1,l=t||r?a:1;o.push([c,l]),a-=i}return o}function Rd(e){var t=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=FW(e,VW),a=null;if(!t)return!1;if(e.useWorker&&n){var c=`
var canvasTest = `.concat(jl.toString(),`;
onmessage = function(e) {
canvasTest(e.data);
};
`),l=new Blob([c],{type:"application/javascript"}),u=URL.createObjectURL(l);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(d){var p=d.data,f=p.width,y=p.height,g=p.benchmark,w=p.isTestPass;w?(nl[r].onSuccess(f,y,g),delete nl[r]):nl[r].onError(f,y,g)}}if(e.usePromise)return new Promise(function(d,p){var f=Un(Un({},e),{},{onError:function(S,v,b){var E;if(e.sizes.length===0)E=!0;else{var C=e.sizes.slice(-1),I=JP(C,1),_=JP(I[0],2),k=_[0],$=_[1];E=S===k&&v===$}o(S,v,b),E&&p({width:S,height:v,benchmark:b})},onSuccess:function(S,v,b){s(S,v,b),d({width:S,height:v,benchmark:b})}});if(a){var y=f.onError,g=f.onSuccess;nl[r]={onError:y,onSuccess:g},a.postMessage(i)}else jl(f)});if(a)nl[r]={onError:o,onSuccess:s},a.postMessage(i);else return jl(e)}var Xm={maxArea:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=Ym({width:t.max,height:t.max,min:t.min,step:t.step,sizes:Dd(Gm.area)}),r=Un(Un(Un({},Oa),t),{},{sizes:n});return Rd(r)},maxHeight:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=Ym({width:1,height:t.max,min:t.min,step:t.step,sizes:Dd(Gm.height)}),r=Un(Un(Un({},Oa),t),{},{sizes:n});return Rd(r)},maxWidth:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=Ym({width:t.max,height:1,min:t.min,step:t.step,sizes:Dd(Gm.width)}),r=Un(Un(Un({},Oa),t),{},{sizes:n});return Rd(r)},test:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=Un(Un({},Oa),t);return n.sizes=Dd(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),Rd(n)}};let qm=null;function GW(){return qm||(qm=YW()),qm}async function YW(){const e=await Xm.maxWidth({usePromise:!0}),t=await Xm.maxHeight({usePromise:!0}),n=await Xm.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:t.height,maxArea:n.width*n.height}}const eC=8192,XW=4096*4096;async function e$(e,t){if(e<=eC&&t<=eC&&e*t<=XW)return[e,t];const{maxWidth:n,maxHeight:r,maxArea:o}=await GW(),s=e/t;if(e>n&&(e=n,t=e/s),t>r&&(t=r,e=t*s),e*t>o){const i=Math.sqrt(o/(e*t));e*=i,t*=i}return[e,t]}/*!
* MIT License
* Modified code originally from <https://github.com/qzb/is-animated>
* Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
*/function tC(e,t){let n=0;for(;e[t+n];)n+=e[t+n]+1;return n+1}function qW(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function ZW(e){const t=new Uint8Array(e);let n,r,o=0,s=0;if(!qW(e))return!1;for(n=t[10]&128,r=t[10]&7,o+=6,o+=7,o+=n?3*Math.pow(2,r+1):0;s<2&&o<t.length;)switch(t[o]){case 44:s+=1,n=t[o+9]&128,r=t[o+9]&7,o+=10,o+=n?3*Math.pow(2,r+1):0,o+=tC(t,o+1)+1;break;case 33:o+=2,o+=tC(t,o);break;case 59:o=t.length;break;default:o=t.length;break}return s>1}function QW(e,t){const n=e.w/t.w,r=e.h/t.h;return n<=1&&r<=1?e:n>r?{w:e.w/n,h:e.h/n}:{w:e.w/r,h:e.h/r}}async function JW(e,t,n,r={}){const o=await jo.usingObjectURL(e,jo.loadImage),{type:s=e.type,quality:i=.92}=r,[a,c]=await e$(Math.min(t*2,o.naturalWidth),Math.min(n*2,o.naturalHeight)),l=document.createElement("canvas");l.width=a,l.height=c;const u=yi(l.getContext("2d",{willReadFrequently:!0}),"Could not get canvas context");return u.imageSmoothingEnabled=!0,u.imageSmoothingQuality="high",u.drawImage(o,0,0,a,c),new Promise((d,p)=>{l.toBlob(f=>{f?d(f):p(new Error("Could not resize image"))},s,i)})}async function eV(e){return ZW(await e.arrayBuffer())}function tV(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function nV(e){const t=new URL(e).host.replace("www.","");for(const n of Tu)if(t$(n.hostnames,t)){const r=n.fromEmbedUrl(e);if(r)return{definition:n,url:r,embedUrl:e}}}const rV=e=>e.split("*").map(t=>tV(t)).join(".+"),t$=(e,t)=>!!e.find(n=>{const r=new RegExp(rV(n));return t.match(r)});function oV(e){const t=new URL(e).host.replace("www.","");for(const n of Tu)if(t$(n.hostnames,t)){const r=n.toEmbedUrl(e);if(r)return{definition:n,embedUrl:r,url:e}}}function n$(e){return oV(e)??nV(e)}function Cs(e){try{return n$(e)}catch(t){console.error(t)}}/*!
* MIT License
* Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
* Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
*/const Da=" ",ln=class ln{static insertTextFirefox(t,n){t.setRangeText(n,t.selectionStart||0,t.selectionEnd||0,"end"),t.dispatchEvent(new InputEvent("input",{data:n,inputType:"insertText",isComposing:!1}))}static insert(t,n){const r=t.ownerDocument,o=r.activeElement;o!==t&&t.focus(),r.execCommand("insertText",!1,n)||ln.insertTextFirefox(t,n),o===r.body?t.blur():o instanceof HTMLElement&&o!==t&&o.focus()}static set(t,n){t.select(),ln.insert(t,n)}static getSelection(t){const{selectionStart:n,selectionEnd:r}=t;return t.value.slice(n||void 0,r||void 0)}static wrapSelection(t,n,r){const{selectionStart:o,selectionEnd:s}=t,i=ln.getSelection(t);ln.insert(t,n+i+(r??n)),t.selectionStart=(o||0)+n.length,t.selectionEnd=(s||0)+n.length}static replace(t,n,r){let o=0;t.value.replace(n,(...s)=>{const i=o+s[s.length-2],a=s[0].length;t.selectionStart=i,t.selectionEnd=i+a;const c=typeof r=="string"?r:r(...s);return ln.insert(t,c),t.selectionStart=i,o+=c.length-a,c})}static findLineEnd(t,n){const r=t.lastIndexOf(`
`,n-1)+1;return t.charAt(r)!==" "?n:r+1}static indent(t){var a;const{selectionStart:n,selectionEnd:r,value:o}=t,s=o.slice(n,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const c=o.lastIndexOf(`
`,n-1)+1,l=t.value.slice(c,r-1),u=l.replace(/^|\n/g,`$&${Da}`),d=u.length-l.length;t.setSelectionRange(c,r-1),ln.insert(t,u),t.setSelectionRange(n+1,r+d)}else ln.insert(t,Da)}static unindent(t){const{selectionStart:n,selectionEnd:r,value:o}=t,s=o.lastIndexOf(`
`,n-1)+1,i=ln.findLineEnd(o,r),a=t.value.slice(s,i),c=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),l=a.length-c.length;t.setSelectionRange(s,i),ln.insert(t,c);const u=/\t| {1,2}/.exec(o.slice(s,n)),d=u?u[0].length:0,p=n-d;t.setSelectionRange(n-d,Math.max(p,r-l))}static indentCE(t){var c;const n=window.getSelection(),r=t.innerText,o=Ld(t)??0,s=Ld(t)??0,i=r.slice(o,s),a=(c=/\n/g.exec(i))==null?void 0:c.length;if(a&&a>0){const l=r.lastIndexOf(`
`,o-1)+1,u=r.slice(l,s-1),p=u.replace(/^|\n/g,`$&${Da}`).length-u.length;n&&n.setBaseAndExtent(t,o+1,t,s+p)}else{const l=window.getSelection();t.innerText=r.slice(0,o)+Da+r.slice(o),l==null||l.setBaseAndExtent(t,o+1,t,o+2)}}static unindentCE(t){const n=window.getSelection(),r=t.innerText,o=Ld(t)??0,s=Ld(t)??0,i=r.lastIndexOf(`
`,o-1)+1,a=ln.findLineEnd(r,s),c=r.slice(i,a),l=c.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=c.length-l.length;if(n){n.setBaseAndExtent(t,i,t,a);const d=/\t| {1,2}/.exec(r.slice(i,o)),p=d?d[0].length:0,f=o-p;n.setBaseAndExtent(t,o-p,t,Math.max(f,s-u))}}static normalizeText(t){return t.replace(ln.fixNewLines,`
`)}static normalizeTextForDom(t){return t.replace(ln.fixNewLines,`
`).split(`
`).map(n=>n||" ").join(`
`)}};m(ln,"fixNewLines",/\r?\n|\r/g);let cc=ln;function Ld(e){if(typeof window.getSelection>"u")return;const t=window.getSelection();if(!t)return;let n=0;if(t.rangeCount!==0){const r=t.getRangeAt(0),o=r.cloneRange();o.selectNodeContents(e),o.setEnd(r.endContainer,r.endOffset),n=o.toString().length}return n}const sV=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function r$(e){return sV.test(e)}function iV(e){return e.replace(/\t/g,Da)}function aV(e){const t=e.split(`
`);for(;t[0]&&t[0].trim().length===0;)t.shift();let n=1/0;for(const r of t)if(r.trim().length>0){const o=r.length-r.trimStart().length;n=Math.min(n,o)}return t.map(r=>r.slice(n)).join(`
`)}function cV(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function lV(e){return cV(aV(iV(e)))}const Ol=(e,t)=>e.length<=t?e:e.substring(0,t-3)+"...";function uV(e,{maxImageDimension:t,maxAssetSize:n,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i}){e.registerExternalAssetHandler("file",async({file:a})=>{const c=a.name;let l=a;const u=r.includes(l.type),d=o.includes(l.type);_t(u||d,`File type not allowed: ${l.type}`),_t(l.size<=n,`File size too big: ${(l.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`),l.type==="video/quicktime"&&(l=new Blob([l],{type:"video/mp4"}));let p=u?await jo.getImageSize(l):await jo.getVideoSize(l);const f=l.type==="image/gif"?await eV(l):d,y=await j3(await l.arrayBuffer());if(isFinite(t)){const S=QW(p,{w:t,h:t});p!==S&&(l.type==="image/jpeg"||l.type==="image/png")&&(p=S)}(l.type==="image/jpeg"||l.type==="image/png")&&(l=await JW(l,p.w,p.h,{type:l.type,quality:.92}));const g=Si.createId(y);return Si.create({id:g,type:u?"image":"video",typeName:"asset",props:{name:c,src:await Ka.blobToDataUrl(l),w:p.w,h:p.h,mimeType:l.type,isAnimated:f}})}),e.registerExternalAssetHandler("url",async({url:a})=>{var l,u,d;let c;try{const f=await(await fetch(a,{method:"GET",mode:"no-cors"})).text(),y=new DOMParser().parseFromString(f,"text/html");c={image:((l=y.head.querySelector('meta[property="og:image"]'))==null?void 0:l.getAttribute("content"))??"",title:((u=y.head.querySelector('meta[property="og:title"]'))==null?void 0:u.getAttribute("content"))??Ol(a,32),description:((d=y.head.querySelector('meta[property="og:description"]'))==null?void 0:d.getAttribute("content"))??""}}catch(p){console.error(p),s.addToast({title:i("assets.url.failed"),severity:"error"}),c={image:"",title:Ol(a,32),description:""}}return{id:Si.createId($S(a)),typeName:"asset",type:"bookmark",props:{src:a,description:c.description,image:c.image,title:c.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:a,text:c})=>{const l=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),u=new DOMParser().parseFromString(c,"image/svg+xml").querySelector("svg");if(!u)throw new Error("No <svg/> element present");let d=parseFloat(u.getAttribute("width")||"0"),p=parseFloat(u.getAttribute("height")||"0");if(!(d&&p)){document.body.appendChild(u);const y=u.getBoundingClientRect();document.body.removeChild(u),d=y.width,p=y.height}const f=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});if(!f)throw Error("Could not create an asset");nC(e,[f],l)}),e.registerExternalContentHandler("embed",({point:a,url:c,embed:l})=>{const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),{width:d,height:p}=l,f=Be(),y={id:f,type:"embed",x:u.x-(d||450)/2,y:u.y-(p||450)/2,props:{w:d,h:p,url:c}};e.createShapes([y]).select(f)}),e.registerExternalContentHandler("files",async({point:a,files:c})=>{const l=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),u=new P(l.x,l.y),d=[];await Promise.all(c.map(async(p,f)=>{if(p.size>n)return console.warn(`File size too big: ${(p.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`),null;if(!p.type)throw new Error("No mime type");if(!r.concat(o).includes(p.type))return console.warn(`${p.name} not loaded - Extension not allowed.`),null;try{const y=await e.getAssetForExternalContent({type:"file",file:p});if(!y)throw Error("Could not create an asset");d[f]=y}catch(y){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(y),null}})),nC(e,fe(d),u)}),e.registerExternalContentHandler("text",async({point:a,text:c})=>{const l=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),u=e.getShapeUtil("text").getDefaultProps(),d=lV(c),p=e.getOnlySelectedShape();if(p&&"text"in p.props){e.updateShapes([{id:p.id,type:p.type,props:{text:d}}]);return}let f,y,g,w="middle";const S=d.split(`
`).length>1,v=r$(d);S&&(w=S?v?"end":"start":"middle");const b=e.textMeasure.measureText(d,{...Ht,fontFamily:io[u.font],fontSize:ac[u.size],maxWidth:null}),E=Math.min(S?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(b.w>E){const C=e.textMeasure.measureText(d,{...Ht,fontFamily:io[u.font],fontSize:ac[u.size],maxWidth:E});f=C.w,y=C.h,g=!1,w=v?"end":"start"}else f=b.w,y=b.h,g=!0;l.y-y/2<e.getViewportPageBounds().minY+40&&(l.y=e.getViewportPageBounds().minY+40+y/2),e.createShapes([{id:Be(),type:"text",x:l.x-f/2,y:l.y-y/2,props:{text:d,align:w,autoSize:g,w:f}}])}),e.registerExternalContentHandler("url",async({point:a,url:c})=>{const l=Cs(c);if(l)return e.putExternalContent({type:"embed",url:l.url,point:a,embed:l.definition});const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),d=Si.createId($S(c)),p=dV(e,c,u);let f=e.getAsset(d),y=!1;if(!f){y=!0;try{const g=await e.getAssetForExternalContent({type:"url",url:c});if(!g)throw Error("Could not create an asset");f=g}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{y&&e.createAssets([f]),e.updateShapes([{id:p.id,type:p.type,props:{assetId:f.id}}])})})}async function nC(e,t,n){if(!t.length)return[];const r=P.From(n),o=[];for(const s of t)switch(s.type){case"bookmark":{o.push({id:Be(),type:"bookmark",x:r.x-150,y:r.y-160,opacity:1,props:{assetId:s.id,url:s.props.src}}),r.x+=300;break}case"image":{o.push({id:Be(),type:"image",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w;break}case"video":o.push({id:Be(),type:"video",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w}return e.batch(()=>{const s=t.filter(i=>!e.getAsset(i.id));s.length&&e.createAssets(s),e.createShapes(o).select(...o.map(i=>i.id)),o$(e,n)}),o.map(s=>s.id)}function o$(e,t){const n=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const o=r.center.sub(t);e.updateShapes(e.getSelectedShapes().map(s=>{const i=e.getShapeParentTransform(s).decompose().rotation,a=P.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!n.contains(r)&&e.zoomToSelection()}function dV(e,t,n){const r={id:Be(),type:"bookmark",x:n.x-150,y:n.y-160,opacity:1,props:{assetId:null,url:t}};return e.batch(()=>{e.createShapes([r]).select(r.id),o$(e,n)}),e.getShape(r.id)}var Sy;let hV=(Sy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")});m(this,"onKeyUp",n=>{var r;if(n.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const o=this.editor.getOnlySelectedShape();o&&this.editor.getShapeUtil(o).canEdit(o)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(o.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...n,target:"shape",shape:o}))}})}},m(Sy,"id","idle"),Sy);var vy;let pV=(vy=class extends se{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onEnter",()=>{this.didTimeout=!1;const n=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.getShapeUtil(r).canBind(r),margin:0,hitInside:!0,renderingOnly:!0});n?this.editor.setHintingShapes([n.id]):this.createArrowShape(),this.startPreciseTimeout()});m(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});m(this,"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:this.editor.getShapeHandles(this.shape).find(n=>n.id==="end"),isCreating:!0,onInteractionEnd:"arrow"})}});m(this,"onPointerUp",()=>{this.cancel()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()});m(this,"preciseTimeout",-1);m(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u,d;const{originPagePoint:n}=this.editor.inputs,r=Be();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"arrow",x:n.x,y:n.y}]);const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=s.find(p=>p.id==="start"),l=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...c,x:0,y:0},isPrecise:!0,initial:a});if(l){const p=(d=l.props)==null?void 0:d.start;(p==null?void 0:p.type)==="binding"&&this.editor.setHintingShapes([p.boundShapeId]),this.editor.updateShapes([l],{squashing:!0})}this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,i,a;const n=this.shape;if(!n)throw Error("expected shape");const r=this.editor.getShapeHandles(n);if(!r)throw Error("expected handles for arrow");const o={...n,props:{...n.props,end:{...n.props.end,x:0,y:0}}};{const c=this.editor.getShapeUtil("arrow"),l=this.shape,u=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint),d=r.find(f=>f.id==="end"),p=(s=c.onHandleDrag)==null?void 0:s.call(c,o,{handle:{...d,x:u.x,y:u.y},isPrecise:!1,initial:l});if(p){const f=(i=p.props)==null?void 0:i.end;(f==null?void 0:f.type)==="binding"&&this.editor.setHintingShapes([f.boundShapeId]),this.editor.updateShapes([p],{squashing:!0})}}{const c=this.editor.getShapeUtil("arrow"),l=this.shape,u=r.find(p=>p.id==="start"),d=(a=c.onHandleDrag)==null?void 0:a.call(c,o,{handle:{...u,x:0,y:0},isPrecise:this.didTimeout,initial:l});d&&this.editor.updateShapes([d],{squashing:!0})}this.shape=this.editor.getShape(n.id)}startPreciseTimeout(){this.preciseTimeout=window.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},m(vy,"id","pointing"),vy);class _h extends se{constructor(){super(...arguments);m(this,"shapeType","arrow")}}m(_h,"id","arrow"),m(_h,"initial","idle"),m(_h,"children",()=>[hV,pV]);class Ox extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"initialShape");m(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");m(this,"util",this.editor.getShapeUtil(this.shapeType));m(this,"isPen",!1);m(this,"segmentMode","free");m(this,"didJustShiftClickToExtendPreviousShapeLine",!1);m(this,"pagePointWhereCurrentSegmentChanged",{});m(this,"pagePointWhereNextSegmentChanged",null);m(this,"lastRecordedPoint",{});m(this,"mergeNextPoint",!1);m(this,"currentLineLength",0);m(this,"canDraw",!1);m(this,"markId",null);m(this,"onEnter",n=>{this.markId=null,this.info=n,this.canDraw=!this.editor.getIsMenuOpen(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()});m(this,"onPointerMove",()=>{const{inputs:n}=this.editor;if(this.isPen!==n.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&n.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(n.isPen?P.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())});m(this,"onKeyDown",n=>{if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()});m(this,"onKeyUp",n=>{if(n.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()});m(this,"onExit",()=>{this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())})}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r){if(!this.canClose())return!1;const o=Mt[r],s=n[0].points[0],i=n[n.length-1],a=i.points[i.points.length-1];return s!==a&&this.currentLineLength>o*4&&P.DistMin(s,a,o*2)}startShape(){const{inputs:{originPagePoint:n,isPen:r}}=this.editor;this.markId="draw start "+et(),this.editor.mark(this.markId),this.isPen=r;const o=this.isPen?this.info.point.z*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=n.clone(),this.initialShape){const i=this.editor.getShape(this.initialShape.id);if(i&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const a=Wn(i.props.segments);if(!a)throw Error("Expected a previous segment!");const c=Wn(a.points);if(!c)throw Error("Expected a previous point!");const{x:l,y:u}=this.editor.getPointInShapeSpace(i,n).toFixed(),d=this.isPen?this.info.point.z*1.25:.5,p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+d.toFixed(2)},{x:l,y:u,z:+d.toFixed(2)}]},f=oe.applyToPoint(this.editor.getShapePageTransform(i.id),c);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const y=[...i.props.segments,p];this.currentLineLength<Mt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(y));const g={id:i.id,type:this.shapeType,props:{segments:y}};this.canClose()&&(g.props.isClosed=this.getIsClosed(y,i.props.size)),this.editor.updateShapes([g]);return}}this.pagePointWhereCurrentSegmentChanged=n.clone();const s=Be();this.editor.createShapes([{id:s,type:this.shapeType,x:n.x,y:n.y,props:{isPen:this.isPen,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+o.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(s)}updateDrawingShape(){const{initialShape:n}=this,{inputs:r}=this.editor;if(!n)return;const{id:o,props:{size:s}}=n,i=this.editor.getShape(o);if(!i)return;const{segments:a}=i.props,{x:c,y:l,z:u}=this.editor.getPointInShapeSpace(i,r.currentPagePoint).toFixed(),d={x:c,y:l,z:this.isPen?+(u*1.25).toFixed(2):.5};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(P.Dist2(p,r.currentPagePoint)>iu){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const y=Wn(a);if(!y)throw Error("Expected a previous segment!");const g=Wn(y.points);if(!g)throw Error("Expected a previous last point!");let w;const S=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(y.type==="straight"){this.currentLineLength+=P.Dist(g,S),w={type:"straight",points:[{...g},S]};const b=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(b,g)}else w={type:"straight",points:[S,d]};const v={id:o,type:this.shapeType,props:{segments:[...a,w]}};this.canClose()&&(v.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([v],{squashing:!0})}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(P.Dist2(p,r.currentPagePoint)>iu){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const y=a.slice(),g=y[y.length-1],w=Wn(g.points);if(!w)throw Error("No previous point!");const S={type:"free",points:[...P.PointsBetween(w,d,6).map(E=>E.toFixed().toJson())]},v=[...y,S];this.currentLineLength<Mt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(v));const b={id:o,type:this.shapeType,props:{segments:v}};this.canClose()&&(b.props.isClosed=this.getIsClosed(v,s)),this.editor.updateShapes([b],{squashing:!0})}break}case"straight":{const p=a.slice(),f=p[p.length-1],{pagePointWhereCurrentSegmentChanged:y}=this,{ctrlKey:g,currentPagePoint:w}=this.editor.inputs;if(!y)throw Error("We should have a point where the segment changed");let S,v=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(v=!g,this.didJustShiftClickToExtendPreviousShapeLine=!1):v=!g;let b=this.editor.getPointInShapeSpace(i,w).toFixed().toJson(),E=!1,C;if((this.editor.user.getIsSnapMode()?!g:g)&&p.length>2){let k,$=8/this.editor.getZoomLevel();for(let T=0,O=a.length-2;T<O;T++){const N=a[T];if(!N)break;if(N.type==="free")continue;const F=N.points[0],L=Wn(N.points);if(!(F&&L))continue;const B=P.NearestPointOnLineSegment(F,L,b);if(P.DistMin(B,b,$)){k=B.toFixed().toJson(),$=P.Dist(B,b),C=N;break}}k&&(E=!0,b=k)}if(E&&C){const k=this.editor.getShapePageTransform(i),$=C.points[0],T=Wn(C.points);if(!T)throw Error("Expected a last point!");const O=oe.applyToPoint(k,$),N=oe.applyToPoint(k,T),F=oe.applyToPoint(k,b);this.editor.snaps.setIndicators([{id:et(),type:"points",points:[O,F,N]}])}else{if(this.editor.snaps.clearIndicators(),v){const k=P.Angle(y,w),T=Wp(k,24)-k;S=P.RotWith(w,y,T)}else S=w;b=this.editor.getPointInShapeSpace(i,S).toFixed().toJson()}this.currentLineLength+=P.Dist(f.points[0],b),p[p.length-1]={...f,type:"straight",points:[f.points[0],b]};const _={id:o,type:this.shapeType,props:{segments:p}};this.canClose()&&(_.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([_],{squashing:!0});break}case"free":{const p=a.slice(),f=p[p.length-1],y=[...f.points];if(y.length&&this.mergeNextPoint){const{z:w}=y[y.length-1];y[y.length-1]={x:d.x,y:d.y,z:w?Math.max(w,d.z):d.z}}else this.currentLineLength+=P.Dist(y[y.length-1],d),y.push(d);p[p.length-1]={...f,points:y},this.currentLineLength<Mt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(p));const g={id:o,type:this.shapeType,props:{segments:p}};if(this.canClose()&&(g.props.isClosed=this.getIsClosed(p,s)),this.editor.updateShapes([g],{squashing:!0}),y.length>500){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const w=Be();this.editor.createShapes([{id:w,type:this.shapeType,x:Vp(r.currentPagePoint.x),y:Vp(r.currentPagePoint.y),props:{isPen:this.isPen,segments:[{type:"free",points:[{x:0,y:0,z:this.isPen?+(u*1.25).toFixed():.5}]}]}}]),this.initialShape=Ye(this.editor.getShape(w)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(n){let r=0;for(const o of n)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=P.Dist2(a,i)}return Math.sqrt(r)}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:n}=this;n&&(this.editor.updateShapes([{id:n.id,type:n.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}m(Ox,"id","drawing");var xy;let s$=(xy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("drawing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(xy,"id","idle"),xy);class kh extends se{constructor(){super(...arguments);m(this,"shapeType","draw");m(this,"onExit",()=>{const n=this.children.drawing;n.initialShape=void 0})}}m(kh,"id","draw"),m(kh,"initial","idle"),m(kh,"children",()=>[s$,Ox]);class cv extends Ph{constructor(){super(...arguments);m(this,"shapeType","frame");m(this,"onCreate",n=>{if(!n)return;const r=this.editor.getShapePageBounds(n),o=[],s=this.editor.getShapeAncestors(n).map(i=>i.id);this.editor.getSortedChildIdsForParent(n.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===n.id||a.isLocked)return;const c=this.editor.getShapePageBounds(a);c&&r.contains(c)&&fV(a,s,n)&&o.push(a.id)}),this.editor.reparentShapes(o,n.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}m(cv,"id","frame"),m(cv,"initial","idle");function fV(e,t,n){return t.includes(e.id)?!1:e.parentId===n.parentId}var wy;let gV=(wy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onKeyUp",n=>{var r;if(n.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const o=this.editor.getOnlySelectedShape();o&&this.editor.getShapeUtil(o).canEdit(o)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(o.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...n,target:"shape",shape:o}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(wy,"id","idle"),wy);var by;let mV=(by=class extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=Be();this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"geo",x:r.x,y:r.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(oo)}}]).select(o).setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:n}=this.editor.inputs,r=Be();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"geo",x:n.x,y:n.y,props:{geo:this.editor.getStyleForNextShape(oo),w:1,h:1}}]);const o=this.editor.getShape(r);if(!o)return;const s=o.props.geo==="star"?new ne(0,0,200,190):o.props.geo==="cloud"?new ne(0,0,300,180):new ne(0,0,200,200),i=s.center,a=this.editor.getShapeParentTransform(o);a&&i.rot(-a.rotation()),this.editor.select(r),this.editor.updateShapes([{id:o.id,type:"geo",x:o.x-i.x,y:o.y-i.y,props:{geo:this.editor.getStyleForNextShape(oo),w:s.width,h:s.height}}]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},m(by,"id","pointing"),by);class Th extends se{constructor(){super(...arguments);m(this,"shapeType","geo")}}m(Th,"id","geo"),m(Th,"initial","idle"),m(Th,"children",()=>[gV,mV]);class $h extends se{constructor(){super(...arguments);m(this,"shapeType","highlight");m(this,"onExit",()=>{const n=this.children.drawing;n.initialShape=void 0})}}m($h,"id","highlight"),m($h,"initial","idle"),m($h,"children",()=>[s$,Ox]);var Py;let yV=(Py=class extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"onEnter",n=>{this.shapeId=n.shapeId,this.editor.setCursor({type:"cross",rotation:0})});m(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Py,"id","idle"),Py);const rC=2;var Cy;let SV=(Cy=class extends se{constructor(){super(...arguments);m(this,"shape",{});m(this,"markId");m(this,"onEnter",n=>{const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=n.shapeId&&this.editor.getShape(n.shapeId);if(s&&r.shiftKey){this.markId=`creating:${s.id}`,this.editor.mark(this.markId),this.shape=s;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(f=>f.type==="vertex").sort(en),c=a[a.length-1],l=a[a.length-2],u=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new P(this.shape.x,this.shape.y)),d=P.Sub(o,u).addXY(.1,.1),p=Ye(this.shape.props.points);if(P.DistMin(c,l,rC)||P.DistMin(d,c,rC))p[c.id]={id:c.id,index:c.index,x:d.x,y:d.y};else{const f=$o(c.index);p[f]={id:f,index:f,x:d.x,y:d.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=Be();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});m(this,"onPointerMove",()=>{if(this.shape&&this.editor.inputs.isDragging){const n=this.editor.getShapeHandles(this.shape);if(!n)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Wn(n);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"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()}},m(Cy,"id","pointing"),Cy);class Mh extends se{constructor(){super(...arguments);m(this,"shapeType","line")}}m(Mh,"id","line"),m(Mh,"initial","idle"),m(Mh,"children",()=>[yV,SV]);var Iy;let vV=(Iy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Iy,"id","idle"),Iy);function We(e,t){var o;const n=new Set;for(const s of t){const i=e.getShape(s);if(!i)continue;e.getShapeUtil(i).onDragShapesOut&&n.add(i);const a=e.getShape(i.parentId);a&&e.getShapeUtil(a).onDragShapesOut&&n.add(a)}const r=new Map;for(const s of n){const i=i$(e,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=e.getShapeUtil(s),c=fe(i.map(l=>e.getShape(l)));(o=a.onDragShapesOut)==null||o.call(a,s,c)}}function i$(e,t){const n=e.getSortedChildIdsForParent(t.id);if(n.length===0)return[];const r=e.getShapePageBounds(t);if(!r)return[];let o,s,i;const a=[];for(const c of n){const l=e.getShapePageBounds(c);if(!l)continue;if(!r.includes(l)){a.push(c);continue}o??(o=e.getShapeGeometry(t)),s??(s=e.getShapePageTransform(t)),i??(i=s.applyToPoints(o.vertices));const u=e.getShapePageTransform(c).clone().invert().applyToPoints(i),{vertices:d,isClosed:p}=e.getShapeGeometry(c);if(!d.some(f=>Zn(f,u))){if(p){if(k2(u,d))continue}else if($4(u,d))continue;a.push(c)}}return a}function sf(e,t,n=!1){e.select(t),e.setEditingShape(t),e.setCurrentTool("select.editing_shape",{target:"shape",shape:t}),n&&e.emit("select-all-text",{shapeId:t.id}),a$(e)}const xV=16;function a$(e){const t=e.getSelectionPageBounds(),n=e.getViewportPageBounds();if(t&&!n.contains(t)){const r=t.clone().expandBy(xV/e.getZoomLevel()).expand(n),o=n.clone().translate({x:(r.center.x-n.center.x)*2,y:(r.center.y-n.center.y)*2});e.zoomToBounds(o,{duration:Qr,inset:0})}}const vi=20,wV=0,Te=200,Dx={x:Te/2,y:Te/2},c$=10,bV={a1:new P(Te*.5,Te*-.5-vi),a2:new P(Te*1.5+vi,Te*.5),a3:new P(Te*.5,Te*1.5+vi),a4:new P(Te*-.5-vi,Te*.5)};function l$(e,t,n,r){return Object.fromEntries(Object.entries(bV).map(([o,s],i)=>{const a=s.clone();return i===0&&r?a.y-=r:i===2&&n&&(a.y+=n),[o,a.rot(t).add(e)]}))}function u$(e,t,n){const r=new Set(e.getSelectedShapeIds()),o=(Te+vi+n)**2,s=new Map,i=[];for(const l of e.getCurrentPageShapes()){if(!e.isShapeOfType(l,"note")||r.has(l.id))continue;const u=e.getShapePageTransform(l.id);t===u.rotation()&&(s.set(l,e.getShapePageBounds(l).center),i.push(...Object.values(l$(u.point(),t,l.props.growY,n))))}const a=i.length;let c;for(const[l,u]of s)for(let d=0;d<a;d++)c=i[d],c&&(P.Dist2(u,c)>o||e.isPointInShape(l,c)&&(i[d]=void 0));return fe(i)}function d$(e,t,n,r,o=!1){let s;const i=e.getCurrentPageShapesSorted(),a=Te+vi**2;for(let c=i.length-1;c>=0;c--){const l=i[c];if(l.type==="note"&&l.id!==t.id){const u=e.getShapePageBounds(l);if(u&&P.Dist2(u.center,n)<a&&e.isPointInShape(l,n)){s=l;break}}}if(e.complete(),!s||o){e.mark("creating note shape");const c=Be();e.createShape({id:c,type:"note",x:n.x,y:n.y,rotation:r,opacity:t.opacity,props:{...t.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const l=e.getShape(c),u=e.getPointInParentSpace(l,P.Sub(n,P.Rot(Dx,r)));e.updateShape({id:c,type:"note",x:u.x,y:u.y}),s=e.getShape(c)}return a$(e),s}var Ey;let PV=(Ey=class extends se{constructor(){super(...arguments);m(this,"dragged",!1);m(this,"info",{});m(this,"wasFocusedOnEnter",!1);m(this,"markId","");m(this,"shape",{});m(this,"onEnter",()=>{const{editor:n}=this;if(this.wasFocusedOnEnter=!n.getIsMenuOpen(),this.wasFocusedOnEnter){const r=Be();this.markId=`creating:${r}`,n.mark(this.markId);const o=this.editor.inputs.originPagePoint.clone(),s=oC(this.editor,o);s&&o.sub(s),this.shape=sC(this.editor,r,o)}});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=Be(),o=this.editor.inputs.originPagePoint.clone(),s=oC(this.editor,o);s&&o.sub(s),this.shape=sC(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()})}complete(){this.wasFocusedOnEnter&&(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)}},m(Ey,"id","pointing"),Ey);function oC(e,t){let n=c$/e.getZoomLevel(),r;for(const o of u$(e,0,0)){const s=P.Sub(t,o),i=s.len();i<n&&(n=i,r=s)}return r}function sC(e,t,n){e.createShape({id:t,type:"note",x:n.x,y:n.y}).select(t);const r=e.getShape(t),o=e.getShapeGeometry(r).bounds;return e.updateShapes([{id:t,type:"note",x:r.x-o.width/2,y:r.y-o.height/2}]),e.getShape(t)}class Ah extends se{constructor(){super(...arguments);m(this,"shapeType","note")}}m(Ah,"id","note"),m(Ah,"initial","idle"),m(Ah,"children",()=>[vV,PV]);function CV(e){const t=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:Ko/e.getZoomLevel(),renderingOnly:!0});if(!t)return e.setHoveredShape(null);let n;const r=e.getOutermostSelectableShape(t);return r===t||r.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(r.id)?n=t:n=r,e.setHoveredShape(n.id)}const Ya=N_(CV,32);var _y;let IV=(_y=class extends se{constructor(){super(...arguments);m(this,"onPointerMove",n=>{switch(n.target){case"shape":case"canvas":Ya(this.editor)}});m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onKeyDown",n=>{var r;if(n.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const o=this.editor.getOnlySelectedShape();o&&this.editor.getShapeUtil(o).canEdit(o)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(o.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...n,target:"shape",shape:o}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(_y,"id","idle"),_y);var ky;let EV=(ky=class extends se{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onExit",()=>{this.editor.setHintingShapes([])});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,o=Be();if(this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:!1,w:20}}]),this.editor.select(o),this.shape=this.editor.getShape(o),!this.shape)return;const{shape:s}=this;this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"text",onCreate:()=>{this.editor.setEditingShape(s.id),this.editor.setCurrentTool("select.editing_shape")}})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.cancel()});m(this,"onCancel",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){var s;this.editor.mark("creating text shape");const n=Be(),{x:r,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:o,props:{text:"",autoSize:!0}}]).select(n),this.editor.setEditingShape(n),this.editor.setCurrentTool("select"),(s=this.editor.root.getCurrent())==null||s.transition("editing_shape")}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}},m(ky,"id","pointing"),ky);class jh extends se{constructor(){super(...arguments);m(this,"shapeType","text")}}m(jh,"id","text"),m(jh,"initial","idle"),m(jh,"children",()=>[IV,EV]);const _V=[jh,kh,Th,Ah,Mh,cv,_h,$h];function xt(){return Jo({isDarkMode:Ru()})}const Pt=Se.memo(function({theme:t,d:n,color:r,fill:o}){switch(o){case"none":return null;case"solid":return h.jsx("path",{fill:t[r].semi,d:n});case"semi":return h.jsx("path",{fill:t.solid,d:n});case"pattern":return h.jsx(kV,{theme:t,color:r,fill:o,d:n})}}),kV=function({d:t,color:n,theme:r}){const o=z(),s=j2(),i=K("zoomLevel",()=>o.getZoomLevel(),[o]),a=Math.ceil(i),c=o.getZoomLevel()<=.18;return h.jsxs(h.Fragment,{children:[h.jsx("path",{fill:r[n].pattern,d:t}),h.jsx("path",{fill:s?`url(#${ic[`1_${r.id}`]})`:c?r[n].semi:`url(#${ic[`${a}_${r.id}`]})`,d:t})]})};function TV(e){return e.replace(/\s/g," ")}function lv(e,t,n){const{padding:r=0}=n;if(t.length===0)return null;const o=ne.From(t[0].box);for(const{box:l}of t)o.union(l);const s=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-o.height:(Math.ceil(n.height)-o.height)/2);let a=null;const c=[];for(const{text:l,box:u}of t)a!==null&&u.y>a&&c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
`},c.length)),c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,children:TV(l)},c.length)),a=u.y;return h.jsx("text",{fontSize:n.fontSize,fontFamily:n.fontFamily,fontStyle:n.fontFamily,fontWeight:n.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:n.stroke,strokeWidth:n.strokeWidth,fill:n.fill,children:c})}function $V(e,t,n,r){if((e==="start-legacy"||e==="end-legacy")&&n.length!==0){const o=ne.From(n[0].box);for(const{box:s}of n)o.union(s);if(e==="start-legacy")return(r-2*t-o.width)/2;if(e==="end-legacy")return-(r-2*t-o.width)/2}}function MV(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function eg({fontSize:e,font:t,align:n,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:c=!0}){const l=z(),u=xt(),d={fontSize:e,fontFamily:dk[t],textAlign:n,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Ht.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:s,stroke:void 0,strokeWidth:void 0},p=l.textMeasure.measureTextSpans(o,d),f=$V(n,a,p,i.width);f&&(d.offsetX=f),d.offsetX+=i.x,d.offsetY+=i.y;const y=lv(l,p,d);let g=null;return c&&(d.fill=u.background,d.stroke=u.background,d.strokeWidth=2,g=lv(l,p,d)),h.jsxs(h.Fragment,{children:[g,y]})}function lc(e){return{key:`${ao.id}:${e}`,getElement:async()=>{const t=AV(e);if(!t)return null;const n=t.$$_url,r=t.$$_fontface;if(!n||!r)return null;const o=await(await fetch(n)).blob(),s=await Ka.blobToDataUrl(o),i=r.replace(n,s);return h.jsx("style",{children:i})}}}function AV(e){const t=dk[e];for(const n of document.fonts)if(t.includes(n.family))return n;return null}function Rx(e){return{key:`${ao.id}:${e}`,getElement:async()=>e!=="pattern"?null:h.jsx(jV,{})}}function jV(){const e=xt(),t=8/12;return h.jsxs(h.Fragment,{children:[h.jsxs("mask",{id:"hash_pattern_mask",children:[h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),h.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[h.jsx("line",{x1:t*1,y1:t*3,x2:t*3,y2:t*1}),h.jsx("line",{x1:t*5,y1:t*7,x2:t*7,y2:t*5}),h.jsx("line",{x1:t*9,y1:t*11,x2:t*11,y2:t*9})]})]}),h.jsx("pattern",{id:ic[`1_${e.id}`],width:"8",height:"8",patternUnits:"userSpaceOnUse",children:h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function Lx(){return{key:`${ao.id}:pattern`,component:RV}}const ml=8,iC=(e,t,n)=>new Promise((r,o)=>{const s=ml*t*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?"#212529":"#f8f9fa",a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*t*e;const c=8/12,l=u=>u*t*e;a.beginPath(),a.moveTo(l(c*1),l(c*3)),a.lineTo(l(c*3),l(c*1)),a.moveTo(l(c*5),l(c*7)),a.lineTo(l(c*7),l(c*5)),a.moveTo(l(c*9),l(c*11)),a.lineTo(l(c*11),l(c*9)),a.stroke(),i.toBlob(u=>{!u||$t.throwToBlob.get()?o():r(u)})}),aC=(e,t)=>{const n=document.createElement("canvas");n.width=e[0],n.height=e[1];const r=n.getContext("2d");return r?(t(r),n.toDataURL()):""},OV=()=>{const e=[];for(let t=1;t<=Math.ceil(xs);t++){const n=aC([1,1],o=>{o.fillStyle=Np.lightMode.black.semi,o.fillRect(0,0,1,1)}),r=aC([1,1],o=>{o.fillStyle=Np.darkMode.black.semi,o.fillRect(0,0,1,1)});e.push({zoom:t,url:n,darkMode:!1}),e.push({zoom:t,url:r,darkMode:!0})}return e};function DV(){const t=z().getInstanceState().devicePixelRatio,[n,r]=x.useState(!1),o=x.useMemo(()=>OV(),[]),[s,i]=x.useState(o);return x.useEffect(()=>{const c=[];for(let u=1;u<=Math.ceil(xs);u++)c.push(iC(t,u,!1).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!1}))),c.push(iC(t,u,!0).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!0})));let l=!1;return Promise.all(c).then(u=>{l||(i(u),r(!0))}),()=>{l=!0,r(!1)}},[t]),{defs:h.jsx(h.Fragment,{children:s.map(c=>{const l=c.zoom+(c.darkMode?"_dark":"_light");return h.jsx("pattern",{id:ic[l],width:ml,height:ml,patternUnits:"userSpaceOnUse",children:h.jsx("image",{href:c.url,width:ml,height:ml})},l)})}),isReady:n}}function RV(){const e=z(),t=x.useRef(null),{defs:n,isReady:r}=DV();return x.useEffect(()=>{if(r&&e.environment.isSafari){const o=h$(t.current);o&&requestAnimationFrame(()=>{o.style.display="none",requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),h.jsx("g",{ref:t,"data-testid":r?"ready-pattern-fill-defs":void 0,children:n})}function h$(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?h$(e.parentElement):null}function Vo(e,t,n={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:c="dashed"}=n;let l=0,u=0,d=1,p=0,f=0;switch(c){case"dashed":{d=1,l=Math.min(t*a,e/4);break}case"dotted":{d=100,l=t/d;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=l/2,f+=l/2):s==="skip"&&(e-=l,f-=l),i==="outset"?e+=l/2:i==="skip"&&(e-=l)),u=Math.floor(e/l/(2*d)),u-=u%o,u<3&&c==="dashed"?e/t<5?(l=e,u=1,p=0):(l=e*.333,p=e*.333):(u=Math.max(u,3),l=e/u/(2*d),r?(f=l/2,p=(e-u*l)/u):p=(e-u*l)/Math.max(1,u-1)),{strokeDasharray:[l,p].join(" "),strokeDashoffset:f.toString()}}const cC=new WeakMap;function Fx(e,t){const n=cC.get(t);if(n)return n;const r=e.getArrowInfo(t);let o=0,s=0;const i=r.isStraight?new lu({start:P.From(r.start.point),end:P.From(r.end.point)}):new X2({center:P.Cast(r.handleArc.center),radius:r.handleArc.radius,start:P.Cast(r.start.point),end:P.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(t.props.text.trim()){const c=i.bounds,{w:l,h:u}=e.textMeasure.measureText(t.props.text,{...Ht,fontFamily:io[t.props.font],fontSize:hi[t.props.size],maxWidth:null});if(o=l,s=u,c.width>c.height){o=Math.max(Math.min(l,64),Math.min(c.width-64,l));const{w:d,h:p}=e.textMeasure.measureText(t.props.text,{...Ht,fontFamily:io[t.props.font],fontSize:hi[t.props.size],maxWidth:o});o=d,s=p}if(o>16*hi[t.props.size]){o=16*hi[t.props.size];const{w:d,h:p}=e.textMeasure.measureText(t.props.text,{...Ht,fontFamily:io[t.props.font],fontSize:hi[t.props.size],maxWidth:o});o=d,s=p}}const a=new P(o,s).addScalar(OW*2);return cC.set(t,a),a}function p$(e,t){const n=Mt[t.props.size];return jW+(n-Mt.s)*2+(n===Mt.xl?20:0)}function LV(e,t,n){const r=Fx(e,t),o=p$(e,t),s=P.Nudge(n.start.point,n.end.point,o),i=P.Nudge(n.end.point,n.start.point,o),a=nx(s,i,ne.FromCenter(n.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[c,l]=a;P.Dist2(c,s)>P.Dist2(l,s)&&([l,c]=a);const u=s.add(P.Sub(n.middle,c)),d=i.add(P.Sub(n.middle,l)),p=P.Dist(n.start.point,u)/n.length,f=P.Dist(n.start.point,d)/n.length;return{start:p,end:f}}function FV(e,t,n){const r=Fx(e,t),o=p$(e,t),s=Math.sign(t.props.bend),i=o/n.handleArc.radius*s,a=P.Angle(n.bodyArc.center,n.start.point)-i,c=P.Angle(n.bodyArc.center,n.end.point)+i,l=$i(n.bodyArc.center,n.bodyArc.radius,a),u=$i(n.bodyArc.center,n.bodyArc.radius,c),d=[],p=lC(n.bodyArc.center,n.bodyArc.radius,a,c,s,ne.FromCenter(l,r).corners);d.push(new wt({points:ne.FromCenter(l,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=lC(n.bodyArc.center,n.bodyArc.radius,a,c,s,ne.FromCenter(u,r).corners);d.push(new wt({points:ne.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const _ of[...p??[],...f??[],l,u])d.push(new dx({x:_.x-3,y:_.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const y=(p&&uC(n.start.point,p))??n.middle,g=(f&&uC(n.end.point,f))??n.middle,w=P.Angle(n.bodyArc.center,n.start.point),S=P.Angle(n.bodyArc.center,n.end.point),v=P.Angle(n.bodyArc.center,y),b=P.Angle(n.bodyArc.center,g);if(vs(w,v,s)>vs(w,b,s))return{start:.5,end:.5,dbg:d};const E=vs(w,S,s),C=vs(w,v,s)/E,I=vs(w,b,s)/E;return{start:C,end:I,dbg:d}}function Oh(e,t){let n;const r=[],o=e.getArrowInfo(t),s=t.props.start.type==="binding",i=t.props.end.type==="binding",a=o.start.arrowhead!=="none",c=o.end.arrowhead!=="none";if(o.isStraight){const u=LV(e,t,o);let d=Ns(t.props.labelPosition,a||s?u.start:0,c||i?u.end:1);d=d>=.48&&d<=.52?.5:d,n=P.Lrp(o.start.point,o.end.point,d)}else{const u=FV(e,t,o);u.dbg&&r.push(...u.dbg);let d=Ns(t.props.labelPosition,a||s?u.start:0,c||i?u.end:1);d=d>=.48&&d<=.52?.5:d;const p=NV(P.Angle(o.bodyArc.center,o.start.point),P.Angle(o.bodyArc.center,o.end.point),Math.sign(t.props.bend),d);n=$i(o.bodyArc.center,o.bodyArc.radius,p)}const l=Fx(e,t);return{box:ne.FromCenter(n,l),debugGeom:r}}function lC(e,t,n,r,o,s){const i=HS(e,t,s),a=vs(n,r,o);return i==null?void 0:i.filter(c=>{const l=vs(n,P.Angle(e,c),o);return l>=0&&l<=a})}function uC(e,t){let n=null,r=-1/0;for(const o of t){const s=P.Dist2(e,o);s>r&&(n=o,r=s)}return n}function NV(e,t,n,r){const o=vs(e,t,n);return e+o*r*n*-1}function zV(e,t,n){const r=t==="end"?e.end.point:e.start.point,o=t==="end"?e.start.point:e.end.point,s=e.isStraight?P.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,n*3),n);let a;if(e.isStraight)a=P.Nudge(r,o,i);else{const c=k4(r,i,e.handleArc.center,e.handleArc.radius);a=t==="end"?e.handleArc.sweepFlag?c[0]:c[1]:e.handleArc.sweepFlag?c[1]:c[0]}return P.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function BV({point:e,int:t}){const n=P.RotWith(t,e,Pe/6),r=P.RotWith(t,e,-Pe/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function UV({point:e,int:t}){const n=P.RotWith(t,e,Pe/6),r=P.RotWith(t,e,-Pe/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function HV({point:e,int:t}){const n=P.Sub(t,e).div(2),r=P.Add(e,P.Rot(n,ze)),o=P.Sub(e,P.Rot(n,ze));return`M ${r.x} ${r.y} L ${t.x} ${t.y} L ${o.x} ${o.y} Z`}function KV({point:e,int:t}){const n=P.Lrp(e,t,.45),r=P.Dist(n,e);return`M ${n.x-r},${n.y}
a ${r},${r} 0 1,0 ${r*2},0
a ${r},${r} 0 1,0 -${r*2},0 `}function WV({point:e,int:t}){const n=P.Lrp(e,t,.75),r=P.RotWith(n,e,Pe/4),o=P.RotWith(n,e,-Pe/4),s=P.Lrp(r,o,.5);return s.add(P.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function VV({int:e,point:t}){const n=P.Lrp(t,e,.85),r=P.Sub(n,t).div(2),o=P.Add(t,P.Rot(r,ze)),s=P.Sub(t,P.Rot(r,ze)),i=P.Add(n,P.Rot(r,ze)),a=P.Sub(n,P.Rot(r,ze));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function GV({int:e,point:t}){const n=P.Sub(e,t).div(2),r=P.Add(t,P.Rot(n,ze)),o=P.Sub(t,P.Rot(n,ze));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function af(e,t,n){const r=t==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=zV(e,t,n);if(o){switch(r){case"bar":return GV(o);case"square":return VV(o);case"diamond":return WV(o);case"dot":return KV(o);case"inverted":return HV(o);case"arrow":return BV(o);case"triangle":return UV(o)}return""}}function YV(e){const{start:t,end:n,handleArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${t.handle.x},${t.handle.y} A${r} ${r} 0 ${o} ${s} ${n.handle.x},${n.handle.y}`}function f$(e){const{start:t,end:n,bodyArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${t.point.x},${t.point.y} A${r} ${r} 0 ${o} ${s} ${n.point.x},${n.point.y}`}function g$(e,t){return`M${e.x},${e.y}L${t.x},${t.y}`}function XV(e){return g$(e.start.handle,e.end.handle)}function m$(e){return g$(e.start.point,e.end.point)}const qV=x.forwardRef(function({isEditing:t,text:n,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:c},l){return h.jsx("textarea",{ref:l,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!t,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",datatype:"wysiwyg",defaultValue:n,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:Ut,onContextMenu:t?Ut:void 0,onPointerDown:a,onDoubleClick:c,onDragStart:Ee})});function ZV(e,t,n){const r=z(),o=x.useRef(null),s=x.useRef(),i=K("isEditing",()=>r.getEditingShapeId()===e,[r]),a=K("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);x.useEffect(()=>{function p({shapeId:f}){requestAnimationFrame(()=>{if(f===e){const y=o.current;y&&(document.activeElement!==y&&y.focus(),y.select())}})}return r.on("select-all-text",p),()=>{r.off("select-all-text",p)}},[r,e]),x.useEffect(()=>{if(!i)return;const p=o.current;if(!p)return;document.activeElement!==p?(p.focus(),r.getInstanceState().isCoarsePointer&&p.select()):r.environment.isSafari&&(p.blur(),p.focus());function f(){var g,w;const y=(g=window.getSelection)==null?void 0:g.call(window);if(y&&y.type!=="None"){const S=[];for(let v=0;v<y.rangeCount;v++)S.push((w=y.getRangeAt)==null?void 0:w.call(y,v));s.current=S}}return document.addEventListener("selectionchange",f),()=>{document.removeEventListener("selectionchange",f)}},[r,i]);const c=x.useCallback(()=>{const p=s.current;requestAnimationFrame(()=>{var g;const f=o.current,y=r.getEditingShapeId();if(y){if(f&&y===e&&(f.focus(),p&&p.length)){const w=window.getSelection();w&&p.forEach(S=>w.addRange(S))}}else(g=window.getSelection())==null||g.removeAllRanges()})},[r,e]),l=x.useCallback(p=>{if(r.getEditingShapeId()===e)switch(p.key){case"Enter":{(p.ctrlKey||p.metaKey)&&r.complete();break}}},[r,e]),u=x.useCallback(p=>{if(r.getEditingShapeId()!==e)return;let f=cc.normalizeText(p.currentTarget.value);const y=f.replace(/\t/g,Da);if(y!==f){const g=p.currentTarget.selectionStart;p.currentTarget.value=y,p.currentTarget.selectionStart=g+(y.length-f.length),p.currentTarget.selectionEnd=g+(y.length-f.length),f=y}r.updateShape({id:e,type:t,props:{text:f}})},[r,e,t]),d=x.useCallback(p=>{r.dispatch({..._n(p),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Ut(p)},[r,e]);return{rInput:o,handleFocus:QV,handleBlur:c,handleKeyDown:l,handleChange:u,handleInputPointerDown:d,handleDoubleClick:Ut,isEmpty:n.trim().length===0,isEditing:i,isEditingAnything:a}}function QV(){}const tg=Se.memo(function({id:t,type:n,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:c,verticalAlign:l,wrap:u,isSelected:d,onKeyDown:p,classNamePrefix:f,style:y,textWidth:g,textHeight:w}){const{rInput:S,isEmpty:v,isEditing:b,isEditingAnything:E,...C}=ZV(t,n,r),[I,_]=x.useState(r);x.useEffect(()=>{b||_(r)},[b,r]);const k=cc.normalizeTextForDom(r),$=k.length>0,T=MV(c);if(!b&&!$)return null;const O=f||"tl-text";return h.jsx("div",{className:`${O}-label tl-text-wrapper`,"data-font":s,"data-align":c,"data-hastext":!v,"data-isediting":b,"data-iseditinganything":E,"data-textwrap":!!u,"data-isselected":d,style:{justifyContent:c==="middle"||T?"center":c,alignItems:l==="middle"?"center":l,...y},children:h.jsxs("div",{className:`${O}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:i*a+"px",minHeight:a+32,minWidth:g||0,color:o,width:g,height:w},children:[h.jsx("div",{className:`${O} tl-text tl-text-content`,dir:"ltr",children:k}),(E||d)&&h.jsx(qV,{ref:S,text:r,isEditing:b,...C,handleKeyDown:p??C.handleKeyDown},I)]})})}),JV=x.memo(function({id:t,text:n,size:r,font:o,position:s,width:i,isSelected:a,labelColor:c}){const l=xt();return h.jsx(tg,{id:t,classNamePrefix:"tl-arrow",type:"arrow",font:o,fontSize:hi[r],lineHeight:Ht.lineHeight,align:"middle",verticalAlign:"middle",text:n,labelColor:l[c].solid,textWidth:i,isSelected:a,style:{transform:`translate(${s.x}px, ${s.y}px)`}})});let eG=0;class Dh extends Fr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"canBind",()=>!1);m(this,"canSnap",()=>!1);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"onHandleDrag",(n,{handle:r,isPrecise:o})=>{const s=r.id;if(s==="middle"){const{start:w,end:S}=jr(this.editor,n),v=P.Sub(S,w),b=P.Per(v),E=P.Med(S,w),C=P.Sub(E,b),I=P.Add(E,b),_=P.NearestPointOnLineSegment(C,I,r,!1);let k=P.Dist(_,E);return P.Clockwise(_,S,E)&&(k*=-1),{id:n.id,type:n.type,props:{bend:k}}}const i=Ye(n);if(this.editor.inputs.ctrlKey)return i.props[s]={type:"point",x:r.x,y:r.y},i;const a=this.editor.getShapePageTransform(n.id).applyToPoint(r),c=this.editor.getShapeAtPoint(a,{hitInside:!0,hitFrameInside:!0,margin:0,filter:w=>!w.isLocked&&this.editor.getShapeUtil(w).canBind(w)});if(!c)return i.props[s]={type:"point",x:r.x,y:r.y},i;const l=this.editor.getShapeGeometry(c),u=ne.ZeroFix(l.bounds),p=this.editor.getShapePageTransform(i.id).applyToPoint(r),f=this.editor.getPointInShapeSpace(c,p);let y=o;if(!y){const w=i.props[s];(w.type==="point"||w.type==="binding"&&c.id!==w.boundShapeId)&&(y=this.editor.inputs.pointerVelocity.len()<.5)}if(!o){l.isClosed||(y=!0);const w=i.props[s==="start"?"end":"start"];w.type==="binding"&&c.id===w.boundShapeId&&w.isPrecise&&(y=!0)}const g={x:(f.x-u.minX)/u.width,y:(f.y-u.minY)/u.height};return y&&P.Dist(f,u.center)<Math.max(4,Math.min(Math.min(u.width,u.height)*.15,16))/this.editor.getZoomLevel()&&(g.x=.5,g.y=.5),i.props[s]={type:"binding",boundShapeId:c.id,normalizedAnchor:g,isPrecise:y,isExact:this.editor.inputs.altKey},i.props.start.type==="binding"&&i.props.end.type==="binding"&&i.props.start.boundShapeId===i.props.end.boundShapeId&&P.Equals(i.props.start.normalizedAnchor,i.props.end.normalizedAnchor)&&(i.props.end.normalizedAnchor.x+=.05),i});m(this,"onTranslateStart",n=>{const r=n.props.start.type==="binding"?n.props.start.boundShapeId:null,o=n.props.end.type==="binding"?n.props.end.boundShapeId:null,s=jr(this.editor,n),i=this.editor.getShapePageTransform(n.id),a=this.editor.getSelectedShapeIds(),c=new Set;r&&(c.add(r),this.editor.getShapeAncestors(r).forEach(u=>c.add(u.id))),o&&(c.add(o),this.editor.getShapeAncestors(o).forEach(u=>c.add(u.id)));for(const u of a)if(c.has(u))return;let l=n;hC.set(n,{pagePosition:i.applyToPoint(n),terminalBindings:Mf(s,(u,d)=>{const p=n.props[u];return p.type!=="binding"?null:{binding:p,shapePosition:d,pagePosition:i.applyToPoint(d)}})});for(const u of["start","end"]){const d=n.props[u];d.type==="binding"&&(l={...n,props:{...n.props,[u]:{...d,isPrecise:!0}}})}return l});m(this,"onTranslate",(n,r)=>{const o=hC.get(n);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=P.Sub(s.applyToPoint(r),o.pagePosition);let a=r;for(const[c,l]of An(o.terminalBindings)){if(!l)continue;const u=P.Add(l.pagePosition,P.Mul(i,.5)),d=this.editor.getShapeAtPoint(u,{hitInside:!0,hitFrameInside:!0,margin:0,filter:p=>!p.isLocked&&this.editor.getShapeUtil(p).canBind(p)});if((d==null?void 0:d.id)===l.binding.boundShapeId){const p=ne.ZeroFix(this.editor.getShapeGeometry(d).bounds),f=this.editor.getPointInShapeSpace(d,u),y={x:(f.x-p.minX)/p.width,y:(f.y-p.minY)/p.height};a={...a,props:{...a.props,[c]:{...l.binding,isPrecise:!0,normalizedAnchor:y}}}}else a={...a,props:{...a.props,[c]:{type:"point",x:l.shapePosition.x,y:l.shapePosition.y}}}}return a});m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r,i=jr(this.editor,n),{start:a,end:c}=Ye(n.props);let{bend:l}=n.props;a.type==="point"&&(a.x=i.start.x*o,a.y=i.start.y*s),c.type==="point"&&(c.x=i.end.x*o,c.y=i.end.y*s);const u=Math.abs(o),d=Math.abs(s);return o<0&&s>=0?(l!==0&&(l*=-1,l*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.x=1-a.normalizedAnchor.x),c.type==="binding"&&(c.normalizedAnchor.x=1-c.normalizedAnchor.x)):o>=0&&s<0?(l!==0&&(l*=-1,l*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.y=1-a.normalizedAnchor.y),c.type==="binding"&&(c.normalizedAnchor.y=1-c.normalizedAnchor.y)):o>=0&&s>=0?l!==0&&(l*=Math.max(u,d)):o<0&&s<0&&(l!==0&&(l*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.x=1-a.normalizedAnchor.x,a.normalizedAnchor.y=1-a.normalizedAnchor.y),c.type==="binding"&&(c.normalizedAnchor.x=1-c.normalizedAnchor.x,c.normalizedAnchor.y=1-c.normalizedAnchor.y)),{props:{start:a,end:c,bend:l}}});m(this,"onDoubleClickHandle",(n,r)=>{switch(r.id){case"start":return{id:n.id,type:n.type,props:{...n.props,arrowheadStart:n.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:n.id,type:n.type,props:{...n.props,arrowheadEnd:n.props.arrowheadEnd==="none"?"arrow":"none"}}}});m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{type:"point",x:0,y:0},end:{type:"point",x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw"}}getGeometry(n){const r=this.editor.getArrowInfo(n),o=[],s=r.isStraight?new lu({start:P.From(r.start.point),end:P.From(r.end.point)}):new X2({center:P.Cast(r.handleArc.center),radius:r.handleArc.radius,start:P.Cast(r.start.point),end:P.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(n.props.text.trim()){const a=Oh(this.editor,n);o.push(...a.debugGeom),i=new Wo({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Br({children:[...i?[s,i]:[s],...o]})}getHandles(n){const r=this.editor.getArrowInfo(n);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y,canBind:!0},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y,canBind:!1},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y,canBind:!0}].filter(Boolean)}component(n){const r=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,s=this.editor.getArrowInfo(n);if(!(s!=null&&s.isValid))return null;const i=Oh(this.editor,n),a=n.id===this.editor.getOnlySelectedShapeId(),l=this.editor.getEditingShapeId()===n.id||n.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(zs,{id:n.id,style:{minWidth:50,minHeight:50},children:h.jsx(dC,{shape:n,shouldDisplayHandles:o&&r===n})}),l&&h.jsx(JV,{id:n.id,text:n.props.text,font:n.props.font,size:n.props.size,position:i.box.center,width:i.box.w,isSelected:a,labelColor:n.props.labelColor})]})}indicator(n){const{start:r,end:o}=jr(this.editor,n),s=this.editor.getArrowInfo(n),i=this.editor.getShapeGeometry(n),a=i.bounds,c=n.props.text.trim()?i.children[1]:null,l=Vf(n.id);if(!s||P.Equals(r,o))return null;const u=Mt[n.props.size],d=s.start.arrowhead&&af(s,"start",u),p=s.end.arrowhead&&af(s,"end",u),f=s.isStraight?m$(s):f$(s),y=d&&s.start.arrowhead!=="arrow"||p&&s.end.arrowhead!=="arrow"||!!c,g=(n.id+"_clip").replace(":","_");return l&&c?h.jsx("rect",{x:j(c.x),y:j(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5}):h.jsxs("g",{children:[y&&h.jsx("defs",{children:h.jsxs("mask",{id:g,children:[h.jsx("rect",{x:a.minX-100,y:a.minY-100,width:a.w+200,height:a.h+200,fill:"white"}),c&&h.jsx("rect",{x:j(c.x),y:j(c.y),width:c.w,height:c.h,fill:"black",rx:3.5,ry:3.5}),d&&h.jsx("path",{d,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&h.jsx("path",{d:p,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{...y?{mask:`url(#${g})`}:void 0,children:[y&&h.jsx("rect",{x:a.minX-100,y:a.minY-100,width:a.width+200,height:a.height+200,opacity:0}),h.jsx("path",{d:f})]}),d&&h.jsx("path",{d}),p&&h.jsx("path",{d:p}),c&&h.jsx("rect",{x:j(c.x),y:j(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5})]})}toSvg(n,r){r.addExportDef(Rx(n.props.fill)),n.props.text&&r.addExportDef(lc(n.props.font));const o=Jo(r);return h.jsxs(h.Fragment,{children:[h.jsx(dC,{shape:n,shouldDisplayHandles:!1}),h.jsx(eg,{fontSize:hi[n.props.size],font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:o[n.props.labelColor].solid,bounds:Oh(this.editor,n).box,padding:4})]})}getCanvasSvgDefs(){return[Lx(),{key:"arrow:dot",component:nG},{key:"arrow:cross",component:rG}]}}m(Dh,"type","arrow"),m(Dh,"props",pk),m(Dh,"migrations",fk);function tG(e,t){const n=e.getArrowInfo(t);return n.isStraight?P.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const dC=or(function({shape:t,shouldDisplayHandles:n}){const r=z(),o=xt(),s=r.getArrowInfo(t),i=ne.ZeroFix(r.getShapeGeometry(t).bounds),a=Se.useMemo(()=>r.environment.isSafari?eG+=1:0,[t]);if(!(s!=null&&s.isValid))return null;const c=Mt[t.props.size],l=s.start.arrowhead&&af(s,"start",c),u=s.end.arrowhead&&af(s,"end",c),d=s.isStraight?m$(s):f$(s);let p=null;if(n){const{strokeDasharray:E,strokeDashoffset:C}=Vo(tG(r,t),2,{end:"skip",start:"skip",lengthRatio:2.5});p=t.props.start.type==="binding"||t.props.end.type==="binding"?h.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?XV(s):YV(s),strokeDasharray:E,strokeDashoffset:C,strokeWidth:2,markerStart:t.props.start.type==="binding"?t.props.start.isExact?"":t.props.start.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:t.props.end.type==="binding"?t.props.end.isExact?"":t.props.end.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:f,strokeDashoffset:y}=Vo(s.isStraight?s.length:Math.abs(s.bodyArc.length),c,{style:t.props.dash}),g=Oh(r,t),w=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),S=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),v=(t.id+"_clip_"+a).replace(":","_");return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsxs("mask",{id:v,children:[h.jsx("rect",{x:j(-100+i.minX),y:j(-100+i.minY),width:j(i.width+200),height:j(i.height+200),fill:"white"}),t.props.text.trim()&&h.jsx("rect",{x:g.box.x,y:g.box.y,width:g.box.w,height:g.box.h,fill:"black",rx:4,ry:4}),l&&w&&h.jsx("path",{d:l,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),u&&S&&h.jsx("path",{d:u,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{fill:"none",stroke:o[t.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[p,h.jsxs("g",{mask:`url(#${v})`,children:[h.jsx("rect",{x:j(i.minX-100),y:j(i.minY-100),width:j(i.width+200),height:j(i.height+200),opacity:0}),h.jsx("path",{d,strokeDasharray:f,strokeDashoffset:y})]}),l&&w&&t.props.fill!=="none"&&h.jsx(Pt,{theme:o,d:l,color:t.props.color,fill:t.props.fill}),u&&S&&t.props.fill!=="none"&&h.jsx(Pt,{theme:o,d:u,color:t.props.color,fill:t.props.fill}),l&&h.jsx("path",{d:l}),u&&h.jsx("path",{d:u})]})]})}),hC=new WeakMap;function nG(){return h.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:h.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function rG(){return h.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[h.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),h.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const pC="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 uc({url:e,zoomLevel:t}){return h.jsx("a",{className:ue("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Ut,onPointerUp:Ut,title:e,draggable:!1,children:h.jsx("div",{className:"tl-hyperlink-button__icon",style:{mask:`url("${pC}") center 100% / 100% no-repeat`,WebkitMask:`url("${pC}") center 100% / 100% no-repeat`}})})}const oG=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Nx(e){return oG.map(n=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=n,c=new P(r,o),{x:l,y:u}=c.rot(-e);return`${l}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}class Rh extends Pc{constructor(){super(...arguments);m(this,"canResize",()=>!1);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"onBeforeCreate",n=>{fC(this.editor,n)});m(this,"onBeforeUpdate",(n,r)=>{if(n.props.url!==r.props.url)if(er.isValid(r.props.url))fC(this.editor,r);else return{...r,props:{...r.props,url:n.props.url}}})}getDefaultProps(){return{url:"",w:300,h:320,assetId:null}}component(n){const r=n.props.assetId?this.editor.getAsset(n.props.assetId):null,o=this.editor.getShapePageTransform(n).rotation(),s=sG(n);return h.jsx(Ai,{children:h.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:Nx(o)},children:[h.jsxs("div",{className:"tl-bookmark__image_container",children:[r!=null&&r.props.image?h.jsx("img",{className:"tl-bookmark__image",draggable:!1,src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):h.jsx("div",{className:"tl-bookmark__placeholder"}),h.jsx(uc,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]}),h.jsxs("div",{className:"tl-bookmark__copy_container",children:[(r==null?void 0:r.props.title)&&h.jsx("h2",{className:"tl-bookmark__heading",children:Ol((r==null?void 0:r.props.title)||"",54)}),(r==null?void 0:r.props.description)&&h.jsx("p",{className:"tl-bookmark__description",children:Ol((r==null?void 0:r.props.description)||"",128)}),h.jsx("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ut,onPointerUp:Ut,onClick:Ut,children:Ol(s,45)})]})]})})}indicator(n){return h.jsx("rect",{width:j(n.props.w),height:j(n.props.h),rx:"6",ry:"6"})}}m(Rh,"type","bookmark"),m(Rh,"props",gk),m(Rh,"migrations",mk);const sG=e=>{try{const t=new URL(e.props.url),n=t.pathname.replace(/\/*$/,"");return`${t.hostname}${n}`}catch{return e.props.url}};function fC(e,t){const{url:n}=t.props,r=Si.createId($S(n));e.getAsset(r)?t.props.assetId!==r&&e.updateShapes([{id:t.id,type:t.type,props:{assetId:r}}]):(e.updateShapes([{id:t.id,type:t.type,props:{assetId:null}}]),iG(e,t))}const iG=B_(async(e,t)=>{const{url:n}=t.props,r=await e.getAssetForExternalContent({type:"url",url:n});r&&e.batch(()=>{e.createAssets([r]),e.updateShapes([{id:t.id,type:t.type,props:{assetId:r.id}}])})},500);function ji(e,t=!1){const n=e.length;if(n<2)return"";let r=e[0].point,o=e[1].point;if(n===2)return`M${Ft(r)}L${Ft(o)}`;let s="";for(let i=2,a=n-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=Cn(r,o);return t?`M${Cn(e[0].point,e[1].point)}Q${Ft(e[1].point)}${Cn(e[1].point,e[2].point)}T${s}${Cn(e[n-1].point,e[0].point)}${Cn(e[0].point,e[1].point)}Z`:`M${Ft(e[0].point)}Q${Ft(e[1].point)}${Cn(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Ft(e[n-1].point)}`}function aG(e,t={}){const{start:n={},end:r={}}=t,{cap:o=!0}=n,{cap:s=!0}=r;_t(!n.taper&&!r.taper,"cap taper not supported here"),_t(!n.easing&&!r.easing,"cap easing not supported here"),_t(o&&s,"cap must be true");const i=lo(e,t);Jf(i,t);const a=cG(i);let c="";for(const l of a)c+=uG(l,t);return c}function cG(e){if(e.length<=2)return[e];const t=[];let n=[e[0]],r=P.Sub(e[1].point,e[0].point).uni(),o,s,i,a,c;for(let l=1,u=e.length;l<u-1;l++){if(i=e[l-1],a=e[l],c=e[l+1],o=P.Sub(c.point,a.point).uni(),s=P.Dpr(r,o),r=o,s<-.8){const d={...a,point:a.input};n.push(d),t.push(Zm(n)),n=[d];continue}if(n.push(a),!(s>.7)&&(P.Dist2(i.point,a.point)+P.Dist2(a.point,c.point))/((i.radius+a.radius+c.radius)/3)**2<1.5){n.push(a),t.push(Zm(n)),n=[a];continue}}return n.push(e[e.length-1]),t.push(Zm(n)),t}function Zm(e){const t=e[0];let n;for(;e.length>2&&(n=e[1],P.Dist2(t.point,n.point)<((t.radius+n.radius)/2*.5)**2);)e.splice(1,1);const r=e[e.length-1];let o;for(;e.length>2&&(o=e[e.length-2],P.Dist2(r.point,o.point)<((r.radius+o.radius)/2*.5)**2);)e.splice(e.length-2,1);return e.length>1&&(e[0]={...e[0],vector:P.Sub(e[0].point,e[1].point).uni()},e[e.length-1]={...e[e.length-1],vector:P.Sub(e[e.length-2].point,e[e.length-1].point).uni()}),e}function lG(e,t,n){return"M "+e+" "+t+" m -"+n+", 0 a "+n+","+n+" 0 1,1 "+n*2+",0 a "+n+","+n+" 0 1,1 -"+n*2+",0"}function uG(e,t={}){if(e.length===0)return"";if(e.length===1)return lG(e[0].point.x,e[0].point.y,e[0].radius);const{left:n,right:r}=QT(e,t);r.reverse();let o=`M${Ft(n[0])}T`;for(let s=1;s<n.length;s++)o+=Cn(n[s-1],n[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),c=P.Add(s.point,P.Mul(a,i)),l=P.Add(s.point,P.Mul(a,-i));o+=`${Ft(c)}A${j(i)},${j(i)} 0 0 1 ${Ft(l)}T`}for(let s=1;s<r.length;s++)o+=Cn(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),c=P.Add(s.point,P.Mul(a,i)),l=P.Add(s.point,P.Mul(a,-i));o+=`${Ft(c)}A${j(i)},${j(i)} 0 0 1 ${Ft(l)}Z`}return o}function du(){const e=z();return K("zoom",()=>e.getZoomLevel()<.35,[e])}const dG=e=>e*.65+v5(e*Pe/2)*.35,hG=e=>({size:1+e,thinning:.5,streamline:.62+(1+e)/8*.06,smoothing:.62,easing:nn.easeOutSine,simulatePressure:!0}),pG=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:dG}),gC=e=>({size:1+e,thinning:0,streamline:.62+(1+e)/8*.06,smoothing:.62,simulatePressure:!1,easing:nn.linear});function uv({strokeWidth:e,showAsComplete:t}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:nn.easeOutSine,last:t}}function dv(e,t,n,r){return{...r?gC(t):e.dash==="draw"?e.isPen?pG(t):hG(t):gC(t),last:e.isComplete||n}}function hu(e){const t=[];for(const n of e)if(n.type==="free"||n.points.length<2)t.push(...n.points.map(P.Cast));else{const r=Math.max(4,Math.floor(P.Dist(n.points[0],n.points[1])/16));t.push(...P.PointsBetween(n.points[0],n.points[1],r))}return t}function fG(e,t){return{draw:"none",solid:"none",dotted:`0.1 ${t*2}`,dashed:`${t*2} ${t*2}`}[e.props.dash]}class Lh extends Fr{constructor(){super(...arguments);m(this,"hideResizeHandles",n=>Qm(n));m(this,"hideRotateHandle",n=>Qm(n));m(this,"hideSelectionBoundsFg",n=>Qm(n));m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of n.props.segments)i.push({...a,points:a.points.map(({x:c,y:l,z:u})=>({x:Vp(o*c),y:Vp(s*l),z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1}}getGeometry(n){const r=hu(n.props.segments),o=Mt[n.props.size];if(n.props.segments.length===1){const i=ne.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new dx({x:-o,y:-o,radius:o,isFilled:!0})}const s=lo(r,dv(n.props,o,!0,!0)).map(i=>i.point);return n.props.isClosed?new wt({points:s,isFilled:n.props.fill!=="none"}):new Ki({points:s})}component(n){return h.jsx(zs,{id:n.id,children:h.jsx(mC,{shape:n,forceSolid:du()})})}indicator(n){var d;const r=du(),o=Mt[n.props.size],s=hu(n.props.segments);let i=o;!r&&!n.props.isPen&&n.props.dash==="draw"&&s.length===1&&(i+=Ys(n.id)()*(o/6));const a=n.props.isComplete||((d=Wn(n.props.segments))==null?void 0:d.type)==="straight",c=dv(n.props,i,a,!0),l=lo(s,c),u=l.length>1?ji(l,n.props.isClosed):y$(s[0],i);return h.jsx("path",{d:u})}toSvg(n,r){return r.addExportDef(Rx(n.props.fill)),h.jsx(mC,{shape:n,forceSolid:!1})}getCanvasSvgDefs(){return[Lx()]}expandSelectionOutlinePx(n){const r=n.props.dash==="draw"?1.6:1;return Mt[n.props.size]*r/2}}m(Lh,"type","draw"),m(Lh,"props",Sk),m(Lh,"migrations",vk);function y$(e,t){const n=(t+1)*.5;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function Qm(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function mC({shape:e,forceSolid:t}){var d;const n=xt(),r=Mt[e.props.size],o=hu(e.props.segments),s=e.props.isComplete||((d=Wn(e.props.segments))==null?void 0:d.type)==="straight";let i=r;!t&&!e.props.isPen&&e.props.dash==="draw"&&o.length===1&&(i+=Ys(e.id)()*(r/6));const a=dv(e.props,i,s,t);if(!t&&e.props.dash==="draw")return h.jsxs(h.Fragment,{children:[e.props.isClosed&&e.props.fill&&o.length>1?h.jsx(Pt,{theme:n,fill:e.props.isClosed?e.props.fill:"none",color:e.props.color,d:ji(lo(o,a),e.props.isClosed)}):null,h.jsx("path",{d:aG(o,a),strokeLinecap:"round",fill:n[e.props.color].solid})]});const c=lo(o,a),l=c.length<2,u=l?y$(o[0],0):ji(c,e.props.isClosed);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:n,color:e.props.color,fill:l||e.props.isClosed?e.props.fill:"none",d:u}),h.jsx("path",{d:u,strokeLinecap:"round",fill:l?n[e.props.color].solid:"none",stroke:n[e.props.color].solid,strokeWidth:r,strokeDasharray:l?"none":fG(e,r),strokeDashoffset:"0"})]})}function gG(e,t,n={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=t,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:u=1/0}=n;let d=e.props.w*s,p=e.props.h*i;const f=new P(0,0);if(d>0){if(d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=d-a;break}case"top":case"bottom":{f.x=(d-a)/2;break}default:f.x=0}d=a}}else if(f.x=d,d=-d,d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-d;break}default:f.x=-a}d=a}if(p>0){if(p<l){switch(o){case"top_left":case"top":case"top_right":{f.y=p-l;break}case"right":case"left":{f.y=(p-l)/2;break}default:f.y=0}p=l}}else if(f.y=p,p=-p,p<l){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-l}p=l}const{x:y,y:g}=f.rot(e.rotation).add(r);return{x:y,y:g,props:{w:Math.min(c,d),h:Math.min(u,p)}}}const mG=e=>Object.entries(e).filter(([t,n])=>n).map(([t])=>t).join(" ");class Fh extends Pc{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",n=>!this.canResize(n));m(this,"canEdit",()=>!0);m(this,"canResize",n=>{var r,o;return!!((o=(r=Cs(n.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});m(this,"canEditInReadOnly",()=>!0);m(this,"isAspectRatioLocked",n=>{const r=Cs(n.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});m(this,"onResize",(n,r)=>{const o=this.isAspectRatioLocked(n),s=Cs(n.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const c=n.props.w/n.props.h;c>1?i*=c:a/=c}return gG(n,r,{minWidth:i,minHeight:a})})}getDefaultProps(){return{w:300,h:300,url:""}}component(n){const{w:r,h:o,url:s}=n.props,i=Vf(n.id),a=x.useMemo(()=>n$(s),[s]),c=K("is hovering",()=>{const{editingShapeId:p,hoveredShapeId:f}=this.editor.getCurrentPageState();if(p&&f!==p){const y=this.editor.getShape(p);if(y&&this.editor.isShapeOfType(y,"embed"))return!0}return!1},[]),l=this.editor.getShapePageTransform(n).rotation(),u=i||c;if((a==null?void 0:a.definition.type)==="github_gist"){const p=a.url.split("/").pop();if(!p)throw Error("No gist id!");return h.jsx(Ai,{className:"tl-embed-container",id:n.id,children:h.jsx(yG,{id:p,width:j(r),height:j(o),isInteractive:u,pageRotation:l})})}const d=mG({...s5,...(a==null?void 0:a.definition.overridePermissions)??{}});return h.jsx(Ai,{className:"tl-embed-container",id:n.id,children:a!=null&&a.definition?h.jsx("iframe",{className:"tl-embed",sandbox:d,src:a.embedUrl,width:j(r),height:j(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:Nx(l),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(n){const r=x.useMemo(()=>Cs(n.props.url),[n.props.url]);return h.jsx("rect",{width:j(n.props.w),height:j(n.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}m(Fh,"type","embed"),m(Fh,"props",xk),m(Fh,"migrations",wk);function yG({id:e,file:t,isInteractive:n,width:r,height:o,style:s,pageRotation:i}){return h.jsx("iframe",{className:"tl-embed",draggable:!1,width:j(r),height:j(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:n?"all":"none",zIndex:n?"":"-1",boxShadow:Nx(i)},srcDoc:`
<html>
<head>
<base target="_blank">
</head>
<body>
<script src=${`https://gist.github.com/${e}.js${t?`?file=${t}`:""}`}><\/script>
<style type="text/css">
* { margin: 0px; }
table { height: 100%; background-color: red; }
.gist { background-color: none; height: 100%; }
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
</style>
</body>
</html>`})}const SG=x.forwardRef(({id:e,name:t,isEditing:n},r)=>{const o=z(),s=x.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(Ut(c),c.currentTarget.blur(),o.setEditingShape(null))},[o]),i=x.useCallback(c=>{const l=o.getShape(e);if(!l)return;const u=l.props.name,d=c.currentTarget.value.trim();u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}],{squashing:!0})},[e,o]),a=x.useCallback(c=>{const l=o.getShape(e);if(!l)return;const u=l.props.name,d=c.currentTarget.value;u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}],{squashing:!0})},[e,o]);return h.jsxs("div",{className:`tl-frame-label ${n?"tl-frame-label__editing":""}`,children:[h.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:n?void 0:"none"},value:t,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),S$(t,"Frame")+"​"]})}),vG=function({id:t,name:n,width:r,height:o}){const s=z(),i=K("shape rotation",()=>Os(s.getShapePageTransform(t).rotation()),[s,t]),a=Vf(t),c=x.useRef(null),l=x.useCallback(y=>{const g=_n(y);s.getEditingShapeId()!==t&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(t),...g}),y.preventDefault())},[s,t]);x.useEffect(()=>{const y=c.current;y&&a&&(y.focus(),y.select(),requestAnimationFrame(()=>{document.activeElement!==y&&(y.focus(),y.select())}))},[c,a]);const d=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(d)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${j(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${j(r)}px, ${j(o)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${j(o)}px) rotate(270deg)`;break}return h.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(p==="top"||p==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${f} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:l,children:h.jsx("div",{className:"tl-frame-heading-hit-area",children:h.jsx(SG,{ref:c,id:t,name:n,isEditing:a})})})};function S$(e,t){return e.match(/^\s*$/)?t:e}class Nh extends Pc{constructor(){super(...arguments);m(this,"canBind",()=>!0);m(this,"canEdit",()=>!0);m(this,"canReceiveNewChildrenOfType",(n,r)=>!n.isLocked);m(this,"canDropShapes",(n,r)=>!n.isLocked);m(this,"onDragShapesOver",(n,r)=>{r.every(o=>o.parentId===n.id)||this.editor.reparentShapes(r,n.id)});m(this,"onDragShapesOut",(n,r)=>{const o=this.editor.getShape(n.parentId);o&&this.editor.isShapeOfType(o,"group")?this.editor.reparentShapes(r,o.id):this.editor.reparentShapes(r,this.editor.getCurrentPageId())});m(this,"onResize",(n,r)=>Y2(n,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(n){return new Wo({width:n.props.w,height:n.props.h,isFilled:!1})}component(n){const r=this.editor.getShapeGeometry(n).bounds,o=xt(),s=K("is creating this shape",()=>{const i=this.editor.getStateDescendant("select.resizing");if(!i||!i.getIsActive())return!1;const a=i==null?void 0:i.info;return a?a.isCreating&&this.editor.getOnlySelectedShapeId()===n.id:!1},[n.id]);return h.jsxs(h.Fragment,{children:[h.jsx(zs,{children:h.jsx("rect",{className:ue("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:h.jsx(vG,{id:n.id,name:n.props.name,width:r.width,height:r.height})]})}toSvg(n,r){const o=Jo({isDarkMode:r.isDarkMode}),a=((Os(this.editor.getShapePageTransform(n.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,c=Math.floor(a);let l;switch(c){case 0:l="";break;case 3:l=`translate(${j(n.props.w)}, 0) rotate(90)`;break;case 2:l=`translate(${j(n.props.w)}, ${j(n.props.h)}) rotate(180)`;break;case 1:l=`translate(0, ${j(n.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const u={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:n.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle"},d=this.editor.textMeasure.measureTextSpans(S$(n.props.name,"Frame")+"​",u),p=d[0],f=Wn(d),y=f.box.w+f.box.x-p.box.x,g=lv(this.editor,d,{offsetY:-u.height-2,...u});return h.jsxs(h.Fragment,{children:[h.jsx("rect",{width:n.props.w,height:n.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),h.jsxs("g",{transform:l,children:[h.jsx("rect",{x:-8,y:-u.height-4,width:y+16,height:u.height,fill:o.background,rx:4,ry:4}),g]})]})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds;return h.jsx("rect",{width:j(r.width),height:j(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}m(Nh,"type","frame"),m(Nh,"props",bk),m(Nh,"migrations",Pk);function Xt(e){return`${j(e.x)},${j(e.y)} `}function v$(e=""){let t=0,n=0,r=0,o=0;function s(){const i=t^t<<11;return t=n,n=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)t^=e.charCodeAt(i)|0,s();return s}function hv(e){let t="M";const n=e.length;let r,o,s;for(let i=0,a=n;i<a;i+=3)r=e[i],o=e[i+1],s=e[i+2],t+=`${Xt(r)}L${Xt(o)}Q${Xt(s)}`;return t+=`${Xt(e[0])}`,t}function pv(e,t,n,r,o){const s=[],i=v$(e);let a=t[0],c;const l=t.length;for(let u=0,d=l*o;u<d;u++){c=P.AddXY(t[(u+1)%l],i()*n,i()*n);const p=P.Sub(c,a),f=P.Len(p),y=P.Div(p,f).mul(Math.min(f/4,r));s.push(P.Add(a,y),P.Add(c,y.neg()),c),a=c}return s}function x$(e,t,n){let r=`M ${Xt(t[0])}L`,o=`M ${Xt(t[0])}L`;const s=n/3,i=n*2,a=v$(e);let c=t[0],l,u=t[0],d;const p=t.length;for(let f=0,y=p-1;f<y;f++){l=t[f+1],d=P.AddXY(t[f+1],a()*s,a()*s);const g=P.Sub(l,c),w=P.Len(g),S=P.Div(g,w).mul(Math.min(w/4,i)),v=P.Add(c,S),b=P.Add(l,S.neg()),E=P.Sub(d,u),C=P.Len(E),I=P.Div(E,C).mul(Math.min(C/4,i)),_=P.Add(u,I),k=P.Add(d,I.neg());f===y-1?(r+=`${Xt(v)}L ${Xt(l)}`,o+=`${Xt(_)}L ${Xt(d)}`):(r+=`${Xt(v)}L ${Xt(b)}Q ${Xt(l)}`,o+=`${Xt(_)}L ${Xt(k)}Q ${Xt(d)}`,c=l,u=d)}return[r,r+o]}function yC(e,t){const n=Math.min(e,t)/2,r=Math.max(e,t)-n*2;return Math.PI*(n*2)+2*r}function xG(e,t,n){const r=Math.min(e,t)/2,o=Math.max(e,t)-r*2,i=(Math.PI*(r*2)+2*o)/n,a=e>t?[{type:"straight",start:new P(r,0),delta:new P(1,0)},{type:"arc",center:new P(e-r,r),startAngle:-Pe/2},{type:"straight",start:new P(e-r,t),delta:new P(-1,0)},{type:"arc",center:new P(r,r),startAngle:Pe/2}]:[{type:"straight",start:new P(e,r),delta:new P(0,1)},{type:"arc",center:new P(r,t-r),startAngle:0},{type:"straight",start:new P(0,t-r),delta:new P(0,-1)},{type:"arc",center:new P(r,r),startAngle:Pe}];let c=0;const l=[];for(let u=0;u<n;u++){const d=a[0];d.type==="straight"?l.push(P.Add(d.start,P.Mul(d.delta,c))):l.push($i(d.center,r,d.startAngle+c/r)),c+=i;let p=d.type==="straight"?o:Pe*r;for(;c>p;)c-=p,a.push(a.shift()),p=a[0].type==="straight"?o:Pe*r}return l}const wG=(e,t,n,r,o)=>{switch(e){case"s":return t;case"m":return n;case"l":return r;case"xl":return o}};function ng(e,t,n,r){const o=Ys(n),s=yC(e,t),i=Math.max(Math.ceil(s/wG(r,50,70,100,130)),6,Math.ceil(s/Math.min(e,t))),a=s/i*.2,c=Math.max(e-a*2,1),l=Math.max(t-a*2,1),u=(e-c)/2,d=(t-l)/2,p=yC(c,l)/i,f=xG(c,l,i).map(v=>v.addXY(u,d)),y=e<20?0:a*.3,g=t<20?0:a*.3,w=f.slice(0);for(let v=0;v<Math.floor(i/2);v++)w[v]=P.AddXY(w[v],o()*y,o()*g),w[i-v-1]=P.AddXY(w[i-v-1],o()*y,o()*g);const S=[];for(let v=0;v<w.length;v++){const b=v===w.length-1?0:v+1,E=w[v],C=w[b],I=f[v],_=f[b],k=P.Average([I,_]),$=P.Angle(I,_)-Math.PI/2,T=P.Dist(I,_),O=p-T,F=P.Dist(E,C)/T,L=(Math.max(u,d)+O)*F,B=P.Add(k,P.FromAngle($,L));B.x<0?B.x=0:B.x>e&&(B.x=e),B.y<0?B.y=0:B.y>t&&(B.y=t);const q=w$(E,C,B),Q=P.Dist(q||P.Average([E,C]),E);S.push({leftPoint:E,rightPoint:C,arcPoint:B,center:q,radius:Q})}return S}function w$(e,t,n){const r=e.x*(t.y-n.y)-e.y*(t.x-n.x)+t.x*n.y-n.x*t.y,o=(e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y)+(n.x*n.x+n.y*n.y)*(t.y-e.y),s=(e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x)+(n.x*n.x+n.y*n.y)*(e.x-t.x),i=-o/(2*r),a=-s/(2*r);return!Number.isFinite(i)||!Number.isFinite(a)?null:new P(i,a)}function bG(e,t,n,r){const o=[],s=ng(e,t,n,r);for(const{center:i,radius:a,leftPoint:c,rightPoint:l}of s)o.push(...CG(c,l,i,a,10));return o}function zx(e,t,n,r){const o=ng(e,t,n,r);let s=`M${j(o[0].leftPoint.x)},${j(o[0].leftPoint.y)}`;for(const{leftPoint:i,rightPoint:a,radius:c,center:l}of o){if(l===null){s+=` L${j(a.x)},${j(a.y)}`;continue}const u=b$(i,a,l)?"0":"1";s+=` A${j(c)},${j(c)} 0 ${u},1 ${j(a.x)},${j(a.y)}`}return s+=" Z",s}function PG(e,t,n,r){const o=Ys(n),s=r==="s"?.5:r==="m"?.7:r==="l"?.9:1.6,i=y=>y+o()*s*2,a=ng(e,t,n,r),u=a.reduce((y,g)=>y+P.Dist2(g.leftPoint,g.rightPoint),0)/a.length>(s*15)**2?y=>new P(i(y.x),i(y.y)):y=>y;let d=`M${j(a[0].leftPoint.x)},${j(a[0].leftPoint.y)}`,p=u(a[0].leftPoint),f=`M${j(p.x)},${j(p.y)}`;for(const{leftPoint:y,center:g,rightPoint:w,radius:S,arcPoint:v}of a){if(g===null){d+=` L${j(w.x)},${j(w.y)}`;const k=u(w);f+=` L${j(k.x)},${j(k.y)}`,p=k;continue}const b=b$(y,w,g)?"0":"1";d+=` A${j(S)},${j(S)} 0 ${b},1 ${j(w.x)},${j(w.y)}`;const E=u(w),C=u(v),I=w$(p,E,C);if(!I){f+=` L${j(E.x)},${j(E.y)}`,p=E;continue}const _=Math.abs(P.Dist(I,p));f+=` A${j(_)},${j(_)} 0 ${b},1 ${j(E.x)},${j(E.y)}`,p=E}return d+f+" Z"}function CG(e,t,n,r,o){if(n===null)return[P.From(e),P.From(t)];const s=[],i=P.Angle(n,e),a=P.Angle(n,t),c=$u(i,a);for(let l=0;l<o;l++){const u=l/(o-1),d=i+c*u,p=$i(n,r,d);s.push(p)}return s}function b$(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)>0}function IG(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function EG(e,t,n,r){const o=Ys(e),s=t/2,i=n/2,a=Kp(s,i),c=[],l=Oe*o(),u=Oe+ze/2+Math.abs(o())*ze,d=Math.max(16,a/10);for(let p=0;p<d;p++){const f=p/(d-1),y=l+f*u,g=Math.cos(y),w=Math.sin(y);c.push(new P(s*g+t*.5+.05*o(),i*w+n/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?nn.easeInOutSine(f):nn.easeInExpo(f)))/2)))}return lo(c,IG(r))}function _G(e,t,n,r){return ji(EG(e,t,n,r))}function fv(e,t){switch(e.geo){case"x-box":return kG(e.w,e.h,t,e.dash);case"check-box":return TG(e.w,e.h);default:return}}function kG(e,t,n,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new P(0,0),new P(e/2,t/2)],[new P(e,t),new P(e/2,t/2)],[new P(0,t),new P(e/2,t/2)],[new P(e,0),new P(e/2,t/2)]];const s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(t,a));return[[new P(s(n*o),i(n*o)),new P(s(e-n*o),i(t-n*o))],[new P(s(n*o),i(t-n*o)),new P(s(e-n*o),i(n*o))]]}function TG(e,t){const n=Math.min(e,t)*.82,r=(e-n)/2,o=(t-n)/2,s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(t,a));return[[new P(s(r+n*.25),i(o+n*.52)),new P(s(r+n*.45),i(o+n*.82))],[new P(s(r+n*.45),i(o+n*.82)),new P(s(r+n*.82),i(o+n*.22))]]}const $G=x.memo(function({dash:t,fill:n,color:r,strokeWidth:o,w:s,h:i,id:a,size:c}){const l=xt(),u=zx(s,i,a,c),d=ng(s,i,a,c);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:l,d:u,fill:n,color:r}),h.jsx("g",{strokeWidth:o,stroke:l[r].solid,fill:"none",pointerEvents:"all",children:d.map(({leftPoint:p,rightPoint:f,center:y,radius:g},w)=>{const S=y?g*Os(Os(P.Angle(y,f))-Os(P.Angle(y,p))):P.Dist(p,f),{strokeDasharray:v,strokeDashoffset:b}=Vo(S,o,{style:t,start:"outset",end:"outset"});return h.jsx("path",{d:y?`M${p.x},${p.y}A${g},${g},0,0,1,${f.x},${f.y}`:`M${p.x},${p.y}L${f.x},${f.y}`,strokeDasharray:v,strokeDashoffset:b},w)})})]})}),MG=x.memo(function({w:t,h:n,strokeWidth:r,dash:o,color:s,fill:i}){const a=xt(),c=t/2,l=n/2,u=Math.max(0,c),d=Math.max(0,l),p=Kp(u,d),{strokeDasharray:f,strokeDashoffset:y}=Vo(p<64?p*2:p,r,{style:o,snap:4,closed:!0}),g=`M${c-u},${l}a${u},${d},0,1,1,${u*2},0a${u},${d},0,1,1,-${u*2},0`;return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:a,d:g,color:s,fill:i}),h.jsx("path",{d:g,strokeWidth:r,width:j(t),height:j(n),fill:"none",stroke:a[s].solid,strokeDasharray:f,strokeDashoffset:y,pointerEvents:"all"})]})});function AG(e,t){if(t>e){const r=e/2;return`
M0,${r}
a${r},${r},0,1,1,${r*2},0
L${e},${t-r}
a${r},${r},0,1,1,-${r*2},0
Z`}const n=t/2;return`
M${n},0
L${e-n},0
a${n},${n},0,1,1,0,${n*2}
L${n},${t}
a${n},${n},0,1,1,0,${-n*2}
Z`}function jG(e,t){if(e>t){const r=t/2;return Kp(r,r)+(e-r*2)*2}const n=e/2;return Kp(n,n)+(t-n*2)*2}const OG=x.memo(function({w:t,h:n,strokeWidth:r,dash:o,color:s,fill:i}){const a=xt(),c=AG(t,n),l=jG(t,n),{strokeDasharray:u,strokeDashoffset:d}=Vo(l<64?l*2:l,r,{style:o,snap:4,start:"outset",end:"outset",closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:a,d:c,color:s,fill:i}),h.jsx("path",{d:c,strokeWidth:r,width:j(t),height:j(n),fill:"none",stroke:a[s].solid,strokeDasharray:u,strokeDashoffset:d,pointerEvents:"all"})]})}),DG=x.memo(function({dash:t,fill:n,color:r,strokeWidth:o,outline:s,lines:i}){const a=xt(),c="M"+s[0]+"L"+s.slice(1)+"Z";return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:a,d:c,fill:n,color:r}),h.jsxs("g",{strokeWidth:o,stroke:a[r].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(s.length)).map((l,u)=>{const d=s[u],p=s[(u+1)%s.length],f=P.Dist(d,p),{strokeDasharray:y,strokeDashoffset:g}=Vo(f,o,{style:t,start:"outset",end:"outset"});return h.jsx("line",{x1:d.x,y1:d.y,x2:p.x,y2:p.y,strokeDasharray:y,strokeDashoffset:g},u)}),i&&i.map(([l,u],d)=>{const p=P.Dist(l,u),{strokeDasharray:f,strokeDashoffset:y}=Vo(p,o,{style:t,start:"skip",end:"outset",snap:t==="dotted"?4:void 0});return h.jsx("path",{d:`M${l.x},${l.y}L${u.x},${u.y}`,stroke:a[r].solid,strokeWidth:o,fill:"none",strokeDasharray:f,strokeDashoffset:y},`line_fg_${d}`)})]})]})}),RG=x.memo(function({fill:t,color:n,strokeWidth:r,w:o,h:s,id:i,size:a}){const c=xt(),l=PG(o,s,i,a);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:c,d:l,fill:t,color:n}),h.jsx("path",{d:l,stroke:c[n].solid,strokeWidth:r,fill:"none"})]})}),LG=x.memo(function({id:t,outline:n,lines:r,fill:o,color:s,strokeWidth:i}){const a=xt(),c=pv(t,n,i/3,i*2,2);let l=hv(c);if(r)for(const[p,f]of r)l+=`M${p.x},${p.y}L${f.x},${f.y}`;const u=pv(t,n,0,i*2,1),d=hv(u);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d,fill:o,color:s,theme:a}),h.jsx("path",{d:l,stroke:a[s].solid,strokeWidth:i,fill:"none"})]})}),FG=x.memo(function({fill:t,color:n,strokeWidth:r,w:o,h:s,id:i,size:a}){const c=xt(),l=zx(o,s,i,a);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:c,d:l,fill:t,color:n}),h.jsx("path",{d:l,stroke:c[n].solid,strokeWidth:r,fill:"none"})]})}),SC=x.memo(function({w:t,h:n,strokeWidth:r,fill:o,color:s}){const i=xt(),a=t/2,c=n/2,l=Math.max(0,a),u=Math.max(0,c),d=`M${a-l},${c}a${l},${u},0,1,1,${l*2},0a${l},${u},0,1,1,-${l*2},0`;return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d,color:s,fill:o,theme:i}),h.jsx("path",{d,stroke:i[s].solid,strokeWidth:r,fill:"none"})]})}),vC=x.memo(function({w:t,h:n,strokeWidth:r,fill:o,color:s}){const i=xt(),a=P$(t,n);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,color:s,fill:o,theme:i}),h.jsx("path",{d:a,stroke:i[s].solid,strokeWidth:r,fill:"none"})]})});function P$(e,t){let n;if(t>e){const r=e/2;n=`
M0,${r}
a${r},${r},0,1,1,${r*2},0
L${e},${t-r}
a${r},${r},0,1,1,-${r*2},0
Z`}else{const r=t/2;n=`
M${r},0
L${e-r},0
a${r},${r},0,1,1,0,${r*2}
L${r},${t}
a${r},${r},0,1,1,0,${-r*2}
Z`}return n}const NG=x.memo(function({outline:t,lines:n,fill:r,color:o,strokeWidth:s}){const i=xt();let a="M"+t[0]+"L"+t.slice(1)+"Z";if(n)for(const[c,l]of n)a+=`M${c.x},${c.y}L${l.x},${l.y}`;return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:r,color:o,theme:i}),h.jsx("path",{d:a,stroke:i[o].solid,strokeWidth:s,fill:"none"})]})});function xC({shape:e}){const t=z(),{id:n,props:r}=e,{w:o,color:s,fill:i,dash:a,growY:c,size:l}=r,u=Mt[l],d=r.h+c;switch(r.geo){case"cloud":{if(a==="solid")return h.jsx(FG,{color:s,fill:i,strokeWidth:u,w:o,h:d,id:n,size:l});if(a==="dashed"||a==="dotted")return h.jsx($G,{color:s,fill:i,strokeWidth:u,w:o,h:d,id:n,size:l,dash:a});if(a==="draw")return h.jsx(RG,{color:s,fill:i,strokeWidth:u,w:o,h:d,id:n,size:l});break}case"ellipse":{if(a==="solid")return h.jsx(SC,{strokeWidth:u,w:o,h:d,color:s,fill:i});if(a==="dashed"||a==="dotted")return h.jsx(MG,{id:n,strokeWidth:u,w:o,h:d,dash:a,color:s,fill:i});if(a==="draw")return h.jsx(SC,{strokeWidth:u,w:o,h:d,color:s,fill:i});break}case"oval":{if(a==="solid")return h.jsx(vC,{strokeWidth:u,w:o,h:d,color:s,fill:i});if(a==="dashed"||a==="dotted")return h.jsx(OG,{id:n,strokeWidth:u,w:o,h:d,dash:a,color:s,fill:i});if(a==="draw")return h.jsx(vC,{strokeWidth:u,w:o,h:d,color:s,fill:i});break}default:{const p=t.getShapeGeometry(e),f=p instanceof Br?p.children[0].vertices:p.vertices,y=fv(e.props,u);if(a==="solid")return h.jsx(NG,{fill:i,color:s,strokeWidth:u,outline:f,lines:y});if(a==="dashed"||a==="dotted")return h.jsx(DG,{dash:a,fill:i,color:s,strokeWidth:u,outline:f,lines:y});if(a==="draw")return h.jsx(LG,{id:n,fill:i,color:s,strokeWidth:u,outline:f,lines:y})}}}const lr=17*3;class zh extends Pc{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});m(this,"onResize",(n,{handle:r,newPoint:o,scaleX:s,scaleY:i,initialShape:a})=>{let c=a.props.w*s,l=(a.props.h+a.props.growY)*i,u=0,d=0;if(n.props.text.trim()){let g=Math.max(Math.abs(c),lr),w=Math.max(Math.abs(l),lr);g<lr&&w===lr&&(g=lr),g===lr&&w<lr&&(w=lr);const S=Fd(this.editor,{...n,props:{...n.props,w:g,h:w}}),v=Math.max(Math.abs(c),S.w)*Math.sign(c),b=Math.max(Math.abs(l),S.h)*Math.sign(l);u=Math.abs(v)-Math.abs(c),d=Math.abs(b)-Math.abs(l),c=v,l=b}const p=new P(0,0);s<0&&(p.x+=c),(r==="left"||r==="top_left"||r==="bottom_left")&&(p.x+=s<0?u:-u),i<0&&(p.y+=l),(r==="top"||r==="top_left"||r==="top_right")&&(p.y+=i<0?d:-d);const{x:f,y}=p.rot(n.rotation).add(o);return{x:f,y,props:{w:Math.max(Math.abs(c),1),h:Math.max(Math.abs(l),1),growY:0}}});m(this,"onBeforeCreate",n=>{if(!n.props.text)return n.props.growY?{...n,props:{...n.props,growY:0}}:void 0;const r=n.props.h,o=Fd(this.editor,n).h;let s=null;if(o>r?s=o-r:n.props.growY&&(s=0),s!==null)return{...n,props:{...n.props,growY:s}}});m(this,"onBeforeUpdate",(n,r)=>{const o=n.props.text,s=r.props.text;if(o===s&&n.props.font===r.props.font&&n.props.size===r.props.size)return;if(o&&!s)return{...r,props:{...r.props,growY:0}};const i=n.props.w,a=n.props.h,c=Fd(this.editor,r),l=c.w,u=c.h;if(!o&&s&&s.length===1){let p=Math.max(i,l),f=Math.max(a,u);return n.props.w<lr&&n.props.h<lr&&(p=Math.max(p,lr),f=Math.max(f,lr),p=Math.max(p,f),f=Math.max(p,f)),{...r,props:{...r.props,w:p,h:f,growY:0}}}let d=null;if(u>a?d=u-a:n.props.growY&&(d=0),d!==null)return{...r,props:{...r.props,growY:d,w:Math.max(r.props.w,l)}};if(l>n.props.w)return{...r,props:{...r.props,w:l}}});m(this,"onDoubleClick",n=>{if(this.editor.inputs.altKey)switch(n.props.geo){case"rectangle":return{...n,props:{geo:"check-box"}};case"check-box":return{...n,props:{geo:"rectangle"}}}})}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:""}}getGeometry(n){const r=Math.max(1,n.props.w),o=Math.max(1,n.props.h+n.props.growY),s=r/2,i=o/2,a=Mt[n.props.size],c=n.props.fill!=="none";let l;switch(n.props.geo){case"cloud":{l=new wt({points:bG(r,o,n.id,n.props.size),isFilled:c});break}case"triangle":{l=new wt({points:[new P(s,0),new P(r,o),new P(0,o)],isFilled:c});break}case"diamond":{l=new wt({points:[new P(s,0),new P(r,i),new P(s,o),new P(0,i)],isFilled:c});break}case"pentagon":{l=new wt({points:lm(r,o,5),isFilled:c});break}case"hexagon":{l=new wt({points:lm(r,o,6),isFilled:c});break}case"octagon":{l=new wt({points:lm(r,o,8),isFilled:c});break}case"ellipse":{l=new q2({width:r,height:o,isFilled:c});break}case"oval":{l=new I8({width:r,height:o,isFilled:c});break}case"star":{const v=Oe/5/2,b=Math.floor(5/4)*2,E=5*2-b,C=0,I=Math.floor(5/2)*2,_=Math.cos(-ze+b*v)*r/2,k=Math.cos(-ze+E*v)*r/2,$=Math.sin(-ze+C*v)*o/2,T=Math.sin(-ze+I*v)*o/2,O=r-Math.abs(_-k),N=o-Math.abs(T-$),F=r/2+k-(r/2-_),L=o/2+$-(o/2-T),B=1,q=(r-F)/2,Q=(o-L)/2,H=(r+O)/2,U=(o+N)/2,W=H*B/2,Z=U*B/2;l=new wt({points:Array.from(Array(5*2)).map((le,be)=>{const Me=-ze+be*v;return new P(q+(be%2?W:H)*Math.cos(Me),Q+(be%2?Z:U)*Math.sin(Me))}),isFilled:c});break}case"rhombus":{const S=Math.min(r*.38,o*.38);l=new wt({points:[new P(S,0),new P(r,0),new P(r-S,o),new P(0,o)],isFilled:c});break}case"rhombus-2":{const S=Math.min(r*.38,o*.38);l=new wt({points:[new P(0,0),new P(r-S,0),new P(r,o),new P(S,o)],isFilled:c});break}case"trapezoid":{const S=Math.min(r*.38,o*.38);l=new wt({points:[new P(S,0),new P(r-S,0),new P(r,o),new P(0,o)],isFilled:c});break}case"arrow-right":{const S=Math.min(r,o)*.38,v=o*.16;l=new wt({points:[new P(0,v),new P(r-S,v),new P(r-S,0),new P(r,o/2),new P(r-S,o),new P(r-S,o-v),new P(0,o-v)],isFilled:c});break}case"arrow-left":{const S=Math.min(r,o)*.38,v=o*.16;l=new wt({points:[new P(S,0),new P(S,v),new P(r,v),new P(r,o-v),new P(S,o-v),new P(S,o),new P(0,o/2)],isFilled:c});break}case"arrow-up":{const S=r*.16,v=Math.min(r,o)*.38;l=new wt({points:[new P(r/2,0),new P(r,v),new P(r-S,v),new P(r-S,o),new P(S,o),new P(S,v),new P(0,v)],isFilled:c});break}case"arrow-down":{const S=r*.16,v=Math.min(r,o)*.38;l=new wt({points:[new P(S,0),new P(r-S,0),new P(r-S,o-v),new P(r,o-v),new P(r/2,o),new P(0,o-v),new P(S,o-v)],isFilled:c});break}case"check-box":case"x-box":case"rectangle":{l=new Wo({width:r,height:o,isFilled:c});break}}const u=Fd(this.editor,n),d=Math.min(100,r/2),p=Math.min(r,Math.max(u.w,Math.min(d,Math.max(1,r-8)))),f=Math.min(Lo[n.props.size]*Ht.lineHeight+Tr*2,o/2),y=Math.min(o,Math.max(u.h,Math.min(f,Math.max(1,r-8)))),g=fv(n.props,a),w=g?g.map(S=>new Ki({points:S})):[];return new Br({children:[l,new Wo({x:n.props.align==="start"?0:n.props.align==="end"?r-p:(r-p)/2,y:n.props.verticalAlign==="start"?0:n.props.verticalAlign==="end"?o-y:(o-y)/2,width:p,height:y,isFilled:!0,isLabel:!0}),...w]})}getHandleSnapGeometry(n){const r=this.getGeometry(n),o=r.children[0];switch(n.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:o,points:[...o.getVertices(),r.bounds.center]};case"cloud":case"ellipse":case"oval":return{outline:o,points:[r.bounds.center]};default:qo(n.props.geo)}}component(n){const{id:r,type:o,props:s}=n,{fill:i,font:a,align:c,verticalAlign:l,size:u,text:d}=s,p=n.id===this.editor.getOnlySelectedShapeId(),f=xt(),g=this.editor.getEditingShapeId()!==null||n.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(zs,{id:r,children:h.jsx(xC,{shape:n})}),g&&h.jsx(Ai,{style:{overflow:"hidden",width:n.props.w,height:n.props.h+s.growY},children:h.jsx(tg,{id:r,type:o,font:a,fontSize:Lo[u],lineHeight:Ht.lineHeight,fill:i,align:c,verticalAlign:l,text:d,isSelected:p,labelColor:f[s.labelColor].solid,wrap:!0})}),n.props.url&&h.jsx(uc,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){const{id:r,props:o}=n,{w:s,size:i}=o,a=o.h+o.growY,c=Mt[i];switch(o.geo){case"ellipse":return o.dash==="draw"?h.jsx("path",{d:_G(r,s,a,c)}):h.jsx("ellipse",{cx:s/2,cy:a/2,rx:s/2,ry:a/2});case"oval":return h.jsx("path",{d:P$(s,a)});case"cloud":return h.jsx("path",{d:zx(s,a,r,i)});default:{const l=this.editor.getShapeGeometry(n),u=l instanceof Br?l.children[0].vertices:l.vertices;let d;if(o.dash==="draw"){const f=pv(r,u,0,c*2,1);d=hv(f)}else d="M"+u[0]+"L"+u.slice(1)+"Z";const p=fv(n.props,c);if(p)for(const[f,y]of p)d+=`M${f.x},${f.y}L${y.x},${y.y}`;return h.jsx("path",{d})}}}toSvg(n,r){const{props:o}=n;r.addExportDef(Rx(n.props.fill));let s;if(o.text){r.addExportDef(lc(n.props.font));const i=Jo(r),a=this.editor.getShapeGeometry(n).bounds;s=h.jsx(eg,{fontSize:Lo[o.size],font:o.font,align:o.align,verticalAlign:o.verticalAlign,text:o.text,labelColor:i[o.labelColor].solid,bounds:a})}return h.jsxs(h.Fragment,{children:[h.jsx(xC,{shape:n}),s]})}getCanvasSvgDefs(){return[Lx()]}}m(zh,"type","geo"),m(zh,"props",Ck),m(zh,"migrations",Ik);function Fd(e,t){const n=t.props.text;if(!n)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Ht,fontFamily:io[t.props.font],fontSize:Lo[t.props.size],maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(n,{...Ht,fontFamily:io[t.props.font],fontSize:Lo[t.props.size],minWidth:r.w,maxWidth:Math.max(0,Math.ceil(r.w+o[t.props.size]),Math.ceil(t.props.w-Tr*2))});return{w:s.w+Tr*2,h:s.h+Tr*2}}function zG(){const[e,t]=x.useState(!1);return x.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");t(r&&o.matches);const s=()=>t(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),K($t.forceSrgb)||!e?"srgb":"p3"}const wC=.35,bC=.82;class Bh extends Fr{constructor(){super(...arguments);m(this,"hideResizeHandles",n=>zd(n));m(this,"hideRotateHandle",n=>zd(n));m(this,"hideSelectionBoundsFg",n=>zd(n));m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of n.props.segments)i.push({...a,points:a.points.map(({x:c,y:l,z:u})=>({x:o*c,y:s*l,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1}}getGeometry(n){const r=aa(n);if(zd(n))return new dx({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=C$(n,r,!0),i=uv({strokeWidth:s,showAsComplete:!0});return Jf(o,i),new wt({points:jx(o,i),isFilled:!0})}component(n){return h.jsx(zs,{id:n.id,style:{opacity:wC},children:h.jsx(Nd,{strokeWidth:aa(n),shape:n})})}backgroundComponent(n){return h.jsx(zs,{id:n.id,style:{opacity:bC},children:h.jsx(Nd,{strokeWidth:aa(n),shape:n})})}indicator(n){var d;const r=du(),o=aa(n),s=hu(n.props.segments);let i=o;!r&&!n.props.isPen&&s.length===1&&(i+=Ys(n.id)()*(o/6));const a=n.props.isComplete||((d=Wn(n.props.segments))==null?void 0:d.type)==="straight",c=uv({strokeWidth:o,showAsComplete:a}),l=lo(s,c);let u;return l.length<2?u=UG(s[0],i):u=ji(l,!1),h.jsx("path",{d:u})}toSvg(n){return h.jsx(Nd,{strokeWidth:aa(n),shape:n,opacity:wC})}toBackgroundSvg(n){return h.jsx(Nd,{strokeWidth:aa(n),shape:n,opacity:bC})}}m(Bh,"type","highlight"),m(Bh,"props",kk),m(Bh,"migrations",Tk);function BG(e){return`M ${e.x} ${e.y} m -${.1}, 0 a ${.1},${.1} 0 1,0 ${.1*2},0 a ${.1},${.1} 0 1,0 -${.1*2},0`}function UG(e,t){const n=t/2;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function C$(e,t,n){var c;const r=hu(e.props.segments),o=e.props.isComplete||((c=Wn(e.props.segments))==null?void 0:c.type)==="straight";let s=t;!n&&!e.props.isPen&&r.length===1&&(s+=Ys(e.id)()*(t/6));const i=uv({strokeWidth:s,showAsComplete:o});return{strokePoints:lo(r,i),sw:s}}function HG(e,t,n){const{strokePoints:r,sw:o}=C$(e,t,n);return{solidStrokePath:r.length>1?ji(r,!1):BG(e.props.segments[0].points[0]),sw:o}}function Nd({strokeWidth:e,shape:t,opacity:n}){const r=xt(),o=du(),{solidStrokePath:s,sw:i}=HG(t,e,o),a=zG(),c=r[t.props.color].highlight[a];return h.jsx("path",{d:s,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:c,strokeWidth:i,opacity:n})}function aa(e){return ac[e.props.size]*1.12}function zd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function I$(){return h.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:[h.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),h.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),h.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function E$(){const[e,t]=x.useState(!1);return x.useEffect(()=>{const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{t(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}async function KG(e){const n=await(await fetch(e)).blob();return Ka.blobToDataUrl(n)}class Uh extends Pc{constructor(){super(...arguments);m(this,"isAspectRatioLocked",()=>!0);m(this,"canCrop",()=>!0);m(this,"onDoubleClick",n=>{const r=n.props.assetId?this.editor.getAsset(n.props.assetId):void 0;!r||!(r.props.src&&"mimeType"in r.props&&r.props.mimeType==="image/gif")||this.editor.updateShapes([{type:"image",id:n.id,props:{playing:!n.props.playing}}])});m(this,"onDoubleClickEdge",n=>{const r=n.props;if(!r||this.editor.getCroppingShapeId()!==n.id)return;const o=Ye(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},s=1/(o.bottomRight.x-o.topLeft.x)*n.props.w,i=1/(o.bottomRight.y-o.topLeft.y)*n.props.h,a=new P(o.topLeft.x*s,o.topLeft.y*i).rot(n.rotation),c={id:n.id,type:n.type,x:n.x-a.x,y:n.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([c])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}component(n){var p,f;const r=this.editor.getCroppingShapeId()===n.id,o=E$(),[s,i]=x.useState(""),a=n.props.assetId?this.editor.getAsset(n.props.assetId):void 0,c=n.id===this.editor.getOnlySelectedShapeId();if(x.useEffect(()=>{if(a!=null&&a.props.src&&"mimeType"in a.props&&(a==null?void 0:a.props.mimeType)==="image/gif"){let y=!1;const g=a.props.src;if(!g)return;const w=new Image;return w.onload=()=>{if(y)return;const S=document.createElement("canvas");S.width=w.width,S.height=w.height;const v=S.getContext("2d");v&&(v.drawImage(w,0,0),i(S.toDataURL()))},w.crossOrigin="anonymous",w.src=g,()=>{y=!0}}},[o,a==null?void 0:a.props]),(a==null?void 0:a.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const l=c&&r&&this.editor.isInAny("select.crop","select.cropping","select.pointing_crop_handle"),u=o&&(((p=a==null?void 0:a.props.mimeType)==null?void 0:p.includes("video"))||((f=a==null?void 0:a.props.mimeType)==null?void 0:f.includes("gif"))),d=PC(n);return a!=null&&a.props.src?h.jsxs(h.Fragment,{children:[l&&h.jsx("div",{style:d,children:h.jsx("div",{className:"tl-image",style:{opacity:.1,backgroundImage:`url(${!n.props.playing||u?s:a.props.src})`},draggable:!1})}),h.jsxs(Ai,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h},children:[h.jsxs("div",{className:"tl-image-container",style:d,children:[h.jsx("div",{className:"tl-image",style:{backgroundImage:`url(${!n.props.playing||u?s:a.props.src})`},draggable:!1}),a.props.isAnimated&&!n.props.playing&&h.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),")",n.props.url&&h.jsx(uc,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):h.jsxs(Ai,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h,color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:[h.jsx("div",{className:"tl-image-container",style:d,children:a?null:h.jsx(I$,{})}),")","url"in n.props&&n.props.url&&h.jsx(uc,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){return this.editor.getCroppingShapeId()===n.id?null:h.jsx("rect",{width:j(n.props.w),height:j(n.props.h)})}async toSvg(n){const r=n.props.assetId?this.editor.getAsset(n.props.assetId):null;if(!r)return null;let o=(r==null?void 0:r.props.src)||"";(o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await KG(o)||"");const s=PC(n),i=n.props.crop;if(s.transform&&i){const{transform:a,width:c,height:l}=s,u=(i.bottomRight.x-i.topLeft.x)*c,d=(i.bottomRight.y-i.topLeft.y)*l,p=[new P(0,0),new P(u,0),new P(u,d),new P(0,d)],f=`cropClipPath_${n.id.replace(":","_")}`;return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsx("clipPath",{id:f,children:h.jsx("polygon",{points:p.map(y=>`${y.x},${y.y}`).join(" ")})})}),h.jsx("g",{clipPath:"url(#{cropClipId})",children:h.jsx("image",{href:o,width:c,height:l,style:{transform:a}})})]})}else return h.jsx("image",{href:o,width:n.props.w,height:n.props.h})}}m(Uh,"type","image"),m(Uh,"props",$k),m(Uh,"migrations",Mk);function PC(e){const t=e.props.crop,n=t==null?void 0:t.topLeft;if(!n)return{width:e.props.w,height:e.props.h};const r=1/(t.bottomRight.x-t.topLeft.x)*e.props.w,o=1/(t.bottomRight.y-t.topLeft.y)*e.props.h,s=-n.x*r,i=-n.y*o;return{transform:`translate(${s}px, ${i}px)`,width:r,height:o}}function _$(e,t){const{start:n,end:r}=e;return t?`M${j(n.x)},${j(n.y)} L${j(r.x)},${j(r.y)} `:`${j(r.x)},${j(r.y)} `}function k$(e,t){const{a:n,b:r,c:o,d:s}=e;return P.Equals(n,s)?"":`${t?`M${j(n.x)},${j(n.y)}`:""}C${j(r.x)},${j(r.y)} ${j(o.x)},${j(o.y)} ${j(s.x)},${j(s.y)}`}function WG(e,t){let n=e.segments.reduce((r,o,s)=>r+k$(o,s===0),"");return t&&(n+="Z"),n}function VG(e,t){let n=e.segments.reduce((r,o,s)=>r+_$(o,s===0),"");return t&&(n+="Z"),n}function T$(e,t=!1){return e instanceof Ki?VG(e,t):WG(e,t)}function $$(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function M$(e,t,n){const r=t.vertices,o=$$(n);return lo(r,o)}function GG(e,t,n){const r=$$(n);return jx(Jf(M$(e,t,n),r),r)}function YG(e,t,n){const r=GG(e,t,n);return Z0(r)}function XG(e,t,n){if(e.props.dash==="draw"){const r=M$(e,t,n);return ji(r)}return T$(t)}const qG=new zf;class Hh extends Fr{constructor(){super(...arguments);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r;return{props:{points:Mf(n.props.points,(i,{id:a,index:c,x:l,y:u})=>({id:a,index:c,x:l*o,y:u*s}))}}});m(this,"onHandleDrag",(n,{handle:r})=>{if(r.type==="vertex")return{...n,props:{...n.props,points:{...n.props.points,[r.id]:{id:r.id,index:r.index,x:r.x,y:r.y}}}}})}getDefaultProps(){const[n,r]=eu(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[n]:{id:n,index:n,x:0,y:0},[r]:{id:r,index:r,x:.1,y:.1}}}}getGeometry(n){return yl(n)}getHandles(n){return qG.get(n.props,()=>{const r=yl(n),o=gv(n),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=kl(o[i].index,o[i+1].index),l=r.segments[i].midPoint();s.push({id:a,type:"create",index:a,x:l.x,y:l.y,canSnap:!0})}return s.sort(en)})}component(n){return h.jsx(zs,{id:n.id,children:h.jsx(CC,{shape:n})})}indicator(n){const r=Mt[n.props.size],o=yl(n),{dash:s}=n.props;let i;if(n.props.spline==="line"){const a=o.points;if(s==="solid"||s==="dotted"||s==="dashed")i="M"+a[0]+"L"+a.slice(1);else{const[c]=x$(n.id,a,r);i=c}}else i=XG(n,o,r);return h.jsx("path",{d:i})}toSvg(n){return h.jsx(CC,{shape:n})}getHandleSnapGeometry(n){const r=gv(n);return{points:r,getSelfSnapPoints:o=>{const s=this.getHandles(n).filter(i=>i.type==="vertex").findIndex(i=>i.id===o.id);return r.filter((i,a)=>Math.abs(a-s)>1).map(P.From)},getSelfSnapOutline:o=>{const s=this.getHandles(n).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),i=yl(n).segments.filter((a,c)=>c!==s-1&&c!==s);return i.length?new Br({children:i}):null}}}}m(Hh,"type","line"),m(Hh,"props",Ak),m(Hh,"migrations",jk);function gv(e){return Object.values(e.props.points).sort(en)}function yl(e){const t=gv(e).map(P.From);switch(e.props.spline){case"cubic":return new C8({points:t});case"line":return new Ki({points:t})}}function CC({shape:e}){const t=xt(),n=yl(e),r=Mt[e.props.size],{dash:o,color:s}=e.props;if(e.props.spline==="line"){if(o==="solid"){const i=n.points,a="M"+i[0]+"L"+i.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:"none",color:s,theme:t}),h.jsx("path",{d:a,stroke:t[s].solid,strokeWidth:r,fill:"none"})]})}if(o==="dashed"||o==="dotted"){const i=n.points,a="M"+i[0]+"L"+i.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:"none",color:s,theme:t}),h.jsx("g",{stroke:t[s].solid,strokeWidth:r,children:n.segments.map((c,l)=>{const{strokeDasharray:u,strokeDashoffset:d}=Vo(c.length,r,{style:o,start:l>0?"outset":"none",end:l<n.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:u,strokeDashoffset:d,d:_$(c,!0),fill:"none"},l)})})]})}if(o==="draw"){const i=n.points,[a,c]=x$(e.id,i,r);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:"none",color:s,theme:t}),h.jsx("path",{d:c,stroke:t[s].solid,strokeWidth:r,fill:"none"})]})}}if(e.props.spline==="cubic"){const i=T$(n);if(o==="solid")return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:i,fill:"none",color:s,theme:t}),h.jsx("path",{strokeWidth:r,stroke:t[s].solid,fill:"none",d:i})]});if(o==="dashed"||o==="dotted")return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:i,fill:"none",color:s,theme:t}),h.jsx("g",{stroke:t[s].solid,strokeWidth:r,children:n.segments.map((a,c)=>{const{strokeDasharray:l,strokeDashoffset:u}=Vo(a.length,r,{style:o,start:c>0?"outset":"none",end:c<n.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:l,strokeDashoffset:u,d:k$(a,!0),fill:"none"},c)})})]});if(o==="draw")return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:i,fill:"none",color:s,theme:t}),h.jsx("path",{d:YG(e,n,r),strokeWidth:1,stroke:t[s].solid,fill:t[s].solid})]})}}const A$=x.createContext(null);function ZG({assetUrls:e,children:t}){return x.useEffect(()=>{for(const n of Object.values(e.icons)){const r=new Image;r.src=n,r.decode()}for(const n of Object.values(e.embedIcons)){const r=new Image;r.src=n,r.decode()}},[e]),h.jsx(A$.Provider,{value:e,children:t})}function Bx(){const e=x.useContext(A$);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const mv={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.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.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-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-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","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.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","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","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","menu.title":"Menu","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.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy share link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy read-only 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 view (but not edit) 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.","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},QG=new Set(["ar","fa","he","ur","ku"]),ca={locale:"en",label:"English",messages:mv,dir:"ltr"};async function JG(e,t){if(!(await fetch(t.translations.en)).ok)return console.warn("No main translations found."),ca;if(e==="en")return ca;const r=ou.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),ca;const s=await(await fetch(t.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),ca;const i=[];for(const a in ca.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:QG.has(r.locale)?"rtl":"ltr",messages:{...ca.messages,...s}}}const j$=x.createContext({}),O$=()=>x.useContext(j$),eY=or(function({overrides:t,children:n}){const o=z().user.getLocale(),s=Bx(),[i,a]=x.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...mv,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:mv});return x.useEffect(()=>{let c=!1;async function l(){const u=await JG(o,s);u&&!c&&(t&&t[o]?a({...u,messages:{...u.messages,...t[o]}}):a(u))}return l(),()=>{c=!0}},[s,o,t]),h.jsx(j$.Provider,{value:i,children:n})});function $e(){const e=O$();return x.useCallback(function(n){return e.messages[n]??n},[e])}class Kh extends Fr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"hideResizeHandles",()=>!0);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"onBeforeCreate",n=>IC(this.editor,n));m(this,"onBeforeUpdate",(n,r)=>{if(!(n.props.text===r.props.text&&n.props.font===r.props.font&&n.props.size===r.props.size))return IC(this.editor,r)});m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:""}}getGeometry(n){const r=Bd(n),{labelHeight:o,labelWidth:s}=D$(this.editor,n);return new Br({children:[new Wo({width:Te,height:r,isFilled:!0}),new Wo({x:n.props.align==="start"?0:n.props.align==="end"?Te-s:(Te-s)/2,y:n.props.verticalAlign==="start"?0:n.props.verticalAlign==="end"?r-o:(r-o)/2,width:s,height:o,isFilled:!0,isLabel:!0})]})}getHandles(n){const r=this.editor.getZoomLevel(),o=wV/r,s=Bd(n),i=this.editor.getInstanceState().isCoarsePointer;return r<.25||i?[]:r<.5?[{id:"bottom",index:"a3",type:"clone",x:Te/2,y:s+o}]:[{id:"top",index:"a1",type:"clone",x:Te/2,y:-o},{id:"right",index:"a2",type:"clone",x:Te+o,y:s/2},{id:"bottom",index:"a3",type:"clone",x:Te/2,y:s+o},{id:"left",index:"a4",type:"clone",x:-o,y:s/2}]}component(n){const{id:r,type:o,props:{color:s,font:i,size:a,align:c,text:l,verticalAlign:u,fontSizeAdjustment:d}}=n,p=rY(r),f=xt(),y=Bd(n),g=K("shape rotation",()=>{var v;return((v=this.editor.getShapePageTransform(r))==null?void 0:v.rotation())??0},[this.editor]),w=du(),S=n.id===this.editor.getOnlySelectedShapeId();return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:r,className:"tl-note__container",style:{width:Te,height:y,backgroundColor:f[s].note.fill,borderBottom:w?"3px solid rgb(15, 23, 31, .2)":"none",boxShadow:w?"none":oY(n.id,g)},children:h.jsx(tg,{id:r,type:o,font:i,fontSize:d||Lo[a],lineHeight:Ht.lineHeight,align:c,verticalAlign:u,text:l,isNote:!0,isSelected:S,labelColor:f[s].note.text,wrap:!0,onKeyDown:p})}),"url"in n.props&&n.props.url&&h.jsx(uc,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){return h.jsx("rect",{rx:"1",width:j(Te),height:j(Bd(n))})}toSvg(n,r){r.addExportDef(lc(n.props.font)),n.props.text&&r.addExportDef(lc(n.props.font));const o=Jo({isDarkMode:r.isDarkMode}),s=this.editor.getShapeGeometry(n).bounds;return h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:5,y:5,rx:1,width:Te-10,height:s.h,fill:"rgba(0,0,0,.1)"}),h.jsx("rect",{rx:1,width:Te,height:s.h,fill:o[n.props.color].note.fill}),h.jsx(eg,{fontSize:n.props.fontSizeAdjustment||Lo[n.props.size],font:n.props.font,align:n.props.align,verticalAlign:n.props.verticalAlign,text:n.props.text,labelColor:o[n.props.color].note.text,bounds:s,stroke:!1})]})}}m(Kh,"type","note"),m(Kh,"props",Ok),m(Kh,"migrations",Dk);function IC(e,t){const{labelHeight:n,fontSizeAdjustment:r}=D$(e,t),o=Math.max(0,n-Te);if(o!==t.props.growY||r!==t.props.fontSizeAdjustment)return{...t,props:{...t.props,growY:o,fontSizeAdjustment:r}}}function tY(e,t){const n=t.props.text;if(!n)return{labelHeight:Lo[t.props.size]*Ht.lineHeight+Tr*2,labelWidth:100,fontSizeAdjustment:0};const r=Lo[t.props.size];let o=0,s=0,i=Te,a=Te;const c=1;do{o=Math.min(r,r-s);const l=e.textMeasure.measureText(n,{...Ht,fontFamily:io[t.props.font],fontSize:o,maxWidth:Te-Tr*2-c,disableOverflowWrapBreaking:!0});if(i=l.h+Tr*2,a=l.w+Tr*2,o<=14){const u=e.textMeasure.measureText(n,{...Ht,fontFamily:io[t.props.font],fontSize:o,maxWidth:Te-Tr*2-c});i=u.h+Tr*2,a=u.w+Tr*2;break}if(l.scrollWidth.toFixed(0)===l.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const nY=new zf;function D$(e,t){return nY.get(t,()=>tY(e,t))}function rY(e){const t=z(),n=O$();return x.useCallback(r=>{const o=t.getShape(e);if(!o)return;const s=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(s||i){r.preventDefault();const a=t.getShapePageTransform(e),c=a.rotation(),l=!!(n.dir==="rtl"||r$(o.props.text)),u=Te+vi+(i&&!r.shiftKey?o.props.growY:0),d=new P(s?r.shiftKey!=l?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(Dx).rot(c).add(a.point()),p=d$(t,o,d,c);p&&(t.mark("editing adjacent shape"),sf(t,p,!0))}},[e,t,n.dir])}function Bd(e){return Te+e.props.growY}function oY(e,t){const n=Ys(e),r=Math.abs(n())+.5,o=Math.cos(t);return`0px ${5-r}px 5px -5px rgba(15, 23, 31, .6),
0px ${(4+r*7)*Math.max(0,o)}px ${6+r*7}px -${4+r*6}px rgba(15, 23, 31, ${(.3+r*.1).toFixed(2)}),
0px 48px 10px -10px inset rgba(15, 23, 44, ${((.022+n()*.005)*((1+o)/2)).toFixed(2)})`}function sY(e,{initialBounds:t,scaleX:n,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new P(0,0);n<0&&(i.x=-(t.width*s)),r<0&&(i.y=-(t.height*s));const{x:a,y:c}=P.Add(o,i.rot(e.rotation));return{x:a,y:c,props:{scale:s*e.props.scale}}}const iY=new zf;class Wh extends Fr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0);m(this,"onResize",(n,r)=>{const{initialBounds:o,initialShape:s,scaleX:i,handle:a}=r;if(r.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:n.id,type:n.type,...sY(n,r)};{const c=o.width;let l=c*i;const u=new P(0,0);l=Math.max(1,Math.abs(l)),a==="left"?(u.x=c-l,i<0&&(u.x+=l)):i<0&&(u.x-=l);const{x:d,y:p}=u.rot(n.rotation).add(s);return{id:n.id,type:n.type,x:d,y:p,props:{w:l/s.props.scale,autoSize:!1}}}});m(this,"onBeforeCreate",n=>{if(!n.props.autoSize||n.props.text.trim())return;const r=this.getMinDimensions(n);return{...n,x:n.x-r.width/2,y:n.y-r.height/2}});m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n,i=n.props.text.trimEnd();i.length===0?this.editor.deleteShapes([n.id]):i!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});m(this,"onBeforeUpdate",(n,r)=>{if(!r.props.autoSize)return;const o=n.props.size!==r.props.size||n.props.align!==r.props.align||n.props.font!==r.props.font||n.props.scale!==1&&r.props.scale===1,s=n.props.text!==r.props.text;if(!o&&!s)return;const i=this.getMinDimensions(n),a=EC(this.editor,r.props),c=i.width*n.props.scale,l=i.height*n.props.scale,u=a.width*r.props.scale,d=a.height*r.props.scale;let p;switch(r.props.align){case"middle":{p=new P((u-c)/2,s?0:(d-l)/2);break}case"end":{p=new P(u-c,s?0:(d-l)/2);break}default:{if(s)break;p=new P(0,(d-l)/2);break}}if(p){p.rot(r.rotation);const{x:f,y}=r;return{...r,x:f-p.x,y:y-p.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}});m(this,"onDoubleClickEdge",n=>{if(!n.props.autoSize)return{id:n.id,type:n.type,props:{autoSize:!0}};if(n.props.scale!==1)return{id:n.id,type:n.type,props:{scale:1}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",align:"middle",autoSize:!0,scale:1}}getMinDimensions(n){return iY.get(n.props,r=>EC(this.editor,r))}getGeometry(n){const{scale:r}=n.props,{width:o,height:s}=this.getMinDimensions(n);return new Wo({width:o*r,height:s*r,isFilled:!0,isLabel:!0})}component(n){const{id:r,props:{font:o,size:s,text:i,color:a,scale:c,align:l}}=n,{width:u,height:d}=this.getMinDimensions(n),p=n.id===this.editor.getOnlySelectedShapeId(),f=xt(),y=aY(r);return h.jsx(tg,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:ac[s],lineHeight:Ht.lineHeight,align:l,verticalAlign:"middle",text:i,labelColor:f[a].solid,isSelected:p,textWidth:u,textHeight:d,style:{transform:`scale(${c})`,transformOrigin:"top left"},wrap:!0,onKeyDown:y})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds,o=z();return n.props.autoSize&&o.getEditingShapeId()===n.id?null:h.jsx("rect",{width:j(r.width),height:j(r.height)})}toSvg(n,r){r.addExportDef(lc(n.props.font)),n.props.text&&r.addExportDef(lc(n.props.font));const o=this.editor.getShapeGeometry(n).bounds,s=o.width/(n.props.scale??1),i=o.height/(n.props.scale??1),a=Jo(r);return h.jsx(eg,{fontSize:ac[n.props.size],font:n.props.font,align:n.props.align,verticalAlign:"middle",text:n.props.text,labelColor:a[n.props.color].solid,bounds:new ne(0,0,s,i),padding:0})}}m(Wh,"type","text"),m(Wh,"props",Rk),m(Wh,"migrations",Lk);function EC(e,t){const{font:n,text:r,autoSize:o,size:s,w:i}=t,a=o?16:Math.max(16,i),c=ac[s],l=o?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...Ht,fontFamily:io[n],fontSize:c,maxWidth:l});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(c,u.h)}}function aY(e){const t=z();return x.useCallback(n=>{if(t.getEditingShapeId()===e)switch(n.key){case"Enter":{(n.ctrlKey||n.metaKey)&&t.complete();break}case"Tab":{Ee(n),n.shiftKey?cc.unindent(n.currentTarget):cc.indent(n.currentTarget);break}}},[t,e])}class Vh extends Pc{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(n){const{editor:r}=this,o=r.getShapeGeometry(n).bounds.w*r.getZoomLevel()>=110,s=n.props.assetId?r.getAsset(n.props.assetId):null,{time:i,playing:a}=n.props,c=Vf(n.id),l=E$(),u=x.useRef(null),d=x.useCallback(S=>{const v=S.currentTarget;v&&r.updateShapes([{type:"video",id:n.id,props:{playing:!0,time:v.currentTime}}])},[n.id,r]),p=x.useCallback(S=>{const v=S.currentTarget;v&&r.updateShapes([{type:"video",id:n.id,props:{playing:!1,time:v.currentTime}}])},[n.id,r]),f=x.useCallback(S=>{const v=S.currentTarget;v&&c&&r.updateShapes([{type:"video",id:n.id,props:{time:v.currentTime}}])},[c,n.id,r]),[y,g]=x.useState(!1),w=x.useCallback(S=>{const v=S.currentTarget;v&&(i!==v.currentTime&&(v.currentTime=i),a||v.pause(),g(!0))},[a,i]);return x.useEffect(()=>{const S=u.current;S&&(y&&!c&&i!==S.currentTime&&(S.currentTime=i),c&&document.activeElement!==S&&S.focus())},[c,y,i]),x.useEffect(()=>{if(l){const S=u.current;if(!S)return;S.pause(),S.currentTime=0}},[u,l]),h.jsxs(h.Fragment,{children:[h.jsx(Ai,{id:n.id,style:{color:"var(--color-text-3)",backgroundColor:s?"transparent":"var(--color-low)",border:s?"none":"1px solid var(--color-low-border)"},children:h.jsx("div",{className:"tl-counter-scaled",children:h.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?h.jsx("video",{ref:u,style:c?{pointerEvents:"all"}:void 0,className:`tl-video tl-video-shape-${n.id.split(":")[1]}`,width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:c&&o,onPlay:d,onPause:p,onTimeUpdate:f,onLoadedData:w,hidden:!y,children:h.jsx("source",{src:s.props.src})}):h.jsx(I$,{})})})}),"url"in n.props&&n.props.url&&h.jsx(uc,{url:n.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(n){return h.jsx("rect",{width:j(n.props.w),height:j(n.props.h)})}toSvg(n){return h.jsx("image",{href:cY(n.id),width:n.props.w,height:n.props.h})}}m(Vh,"type","video"),m(Vh,"props",Fk),m(Vh,"migrations",Nk);function cY(e){const t=e.split(":")[1],n=document.querySelector(`.tl-video-shape-${t}`);if(n){const r=document.createElement("canvas");return r.width=n.videoWidth,r.height=n.videoHeight,r.getContext("2d").drawImage(n,0,0),r.toDataURL("image/png")}else throw new Error("Video with not found when attempting serialization.")}const Ux=[Wh,Rh,Lh,zh,Kh,Hh,Nh,Dh,Bh,Fh,Uh,Vh];function lY(e){return[e.sideEffects.registerAfterChangeHandler("instance",(t,n)=>{t.isFocused!==n.isFocused&&(n.isFocused?e.getContainer().focus():(e.complete(),e.getContainer().blur()))}),e.sideEffects.registerAfterChangeHandler("instance_page_state",(t,n)=>{if(t.croppingShapeId!==n.croppingShapeId){const r=e.isInAny("select.crop","select.pointing_crop_handle","select.cropping");!t.croppingShapeId&&n.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):t.croppingShapeId&&!n.croppingShapeId&&r&&e.setCurrentTool("select.idle")}t.editingShapeId!==n.editingShapeId&&(!t.editingShapeId&&n.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):t.editingShapeId&&!n.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))})]}class R$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"scribbleId","id");m(this,"markId","");m(this,"excludedShapeIds",new Set);m(this,"onEnter",n=>{this.markId="erase scribble begin",this.editor.mark(this.markId),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>{if(this.editor.isShapeOrAncestorLocked(s))return!0;if(this.editor.isShapeOfType(s,"group")||this.editor.isShapeOfType(s,"frame")){const i=this.editor.getPointInShapeSpace(s,r);return this.editor.getShapeGeometry(s).bounds.containsPoint(i)}return!1}).map(s=>s.id));const o=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=o.id,this.update()});m(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}update(){const{editor:n,excludedShapeIds:r}=this,o=n.getErasingShapeIds(),s=n.getZoomLevel(),i=n.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:c}}=n;this.pushPointToScribble();const l=new Set(o),u=Ko/s;for(const d of i){if(n.isShapeOfType(d,"group"))continue;const p=n.getShapeMask(d.id);if(p&&!Zn(a,p))continue;const f=n.getShapeGeometry(d),y=n.getShapePageTransform(d);if(!f||!y)continue;const g=y.clone().invert(),w=g.applyToPoint(c),S=g.applyToPoint(a),{bounds:v}=f;v.minX-u>Math.max(w.x,S.x)||v.minY-u>Math.max(w.y,S.y)||v.maxX+u<Math.min(w.x,S.x)||v.maxY+u<Math.min(w.y,S.y)||f.hitTestLineSegment(w,S,u)&&l.add(n.getOutermostSelectableShape(d).id)}this.editor.setErasingShapes([...l].filter(d=>!r.has(d)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),n.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.setErasingShapes([]),n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}m(R$,"id","erasing");var Ty;let uY=(Ty=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ty,"id","idle"),Ty);var $y;let dY=($y=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{const n=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:o}}=this.editor,s=new Set,i=s.size;for(let a=r.length,c=a-1;c>=0;c--){const l=r[c];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,o,{hitInside:!1,margin:Ko/n})){const u=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(u,"frame")&&s.size>i)break;s.add(u.id)}}this.editor.setErasingShapes([...s])});m(this,"onLongPress",n=>{this.startErasing(n)});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startErasing(n)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}startErasing(n){this.parent.transition("erasing",n)}complete(){const n=this.editor.getErasingShapeIds();n.length&&(this.editor.mark("erase end"),this.editor.deleteShapes(n)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},m($y,"id","pointing"),$y);class Gh extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(Gh,"id","eraser"),m(Gh,"initial","idle"),m(Gh,"children",()=>[uY,dY,R$]);class L$ extends se{constructor(){super(...arguments);m(this,"initialCamera",new P);m(this,"onEnter",()=>{this.initialCamera=P.From(this.editor.getCamera()),this.update()});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.parent.transition("idle")});m(this,"onComplete",()=>{this.complete()})}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=P.Sub(o,s).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r,friction:Sh}),this.parent.transition("idle")}}m(L$,"id","dragging");var My;let hY=(My=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(My,"id","idle"),My);var Ay;let pY=(Ay=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});m(this,"onLongPress",()=>{this.startDragging()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startDragging()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.complete()})}startDragging(){this.parent.transition("dragging")}complete(){this.parent.transition("idle")}},m(Ay,"id","pointing"),Ay);class Yh extends se{constructor(){super(...arguments);m(this,"onDoubleClick",n=>{if(n.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{duration:220,easing:nn.easeOutQuint})}});m(this,"onTripleClick",n=>{if(n.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{duration:320,easing:nn.easeOutQuint})}});m(this,"onQuadrupleClick",n=>{if(n.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:o}}=this.editor;r===1?this.editor.zoomToFit({duration:400,easing:nn.easeOutQuint}):this.editor.resetZoom(o,{duration:320,easing:nn.easeOutQuint})}})}}m(Yh,"id","hand"),m(Yh,"initial","idle"),m(Yh,"children",()=>[hY,pY,L$]);var jy;let fY=(jy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("lasering",n)})}},m(jy,"id","idle"),jy);class F$ extends se{constructor(){super(...arguments);m(this,"scribbleId","id");m(this,"onEnter",()=>{const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:1200,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.pushPointToScribble()});m(this,"onPointerUp",()=>{this.complete()});m(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}m(F$,"id","lasering");class Xh extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(Xh,"id","laser"),m(Xh,"initial","idle"),m(Xh,"children",()=>[fY,F$]);class N$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"initialSelectedShapeIds",[]);m(this,"excludedShapeIds",new Set);m(this,"isWrapMode",!1);m(this,"initialStartShape",null);m(this,"onEnter",n=>{const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",n);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.hitTestShapes()});m(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});m(this,"onTick",()=>{hx(this.editor)});m(this,"onPointerMove",()=>{this.hitTestShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",n=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds,{squashing:!0}),this.parent.transition("idle",n)});m(this,"onKeyDown",n=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()});m(this,"onKeyUp",()=>{this.hitTestShapes()});m(this,"onInterrupt",()=>{this.editor.updateInstanceState({brush:null})})}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:c}}=n,l=new Set(a?this.initialSelectedShapeIds:[]),u=o?!c:c,d=ne.FromPoints([s,i]),{corners:p}=d;let f,y,g,w,S,v;const b=n.getCurrentPageShapes(),E=n.getCurrentPageId();e:for(let _=0,k=b.length;_<k;_++){if(g=b[_],r.has(g.id)||l.has(g.id)||(w=n.getShapePageBounds(g),!w))continue e;if(d.contains(w)){this.handleHit(g,i,E,l,p);continue e}if(u||n.isShapeOfType(g,"frame"))continue e;if(d.collides(w)){if(S=n.getShapePageTransform(g),!S)continue e;v=S.clone().invert().applyToPoints(p);const $=n.getShapeGeometry(g);t:for(let T=0;T<4;T++)if(f=v[T],y=v[(T+1)%4],$.hitTestLineSegment(f,y,0)){this.handleHit(g,i,E,l,p);break t}}}n.getInstanceState().isCoarsePointer;const C=n.getInstanceState().brush;(!C||!d.equals(C))&&n.updateInstanceState({brush:{...d.toJson()}});const I=n.getSelectedShapeIds();(I.length!==l.size||I.some(_=>!l.has(_)))&&n.setSelectedShapes(Array.from(l),{squashing:!0})}handleHit(n,r,o,s,i){if(n.parentId===o){s.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),c=this.editor.getShapeMask(a.id);c&&!k2(c,i)&&!Zn(r,c)||s.add(a.id)}}m(N$,"id","brushing");function Hx(e,t=!1){const n=e.getZoomLevel(),{inputs:{currentPagePoint:r}}=e;return e.getShapeAtPoint(r,{hitInside:!1,hitLabels:t,margin:Ko/n,renderingOnly:!0})??e.getSelectedShapeAtPoint(r)}function z$(e,t,n){if(!t)throw Error("Needs to translate a cropped shape!");const{crop:r}=t.props;if(!r)return;const o=e.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;o==="x"?n.x=0:o==="y"&&(n.y=0),n.rot(-t.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*t.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*t.props.h,a=r.bottomRight.y-r.topLeft.y,c=r.bottomRight.x-r.topLeft.x,l=Ye(r);return l.topLeft.x=Math.min(1-c,Math.max(0,l.topLeft.x-n.x/s)),l.topLeft.y=Math.min(1-a,Math.max(0,l.topLeft.y-n.y/i)),l.bottomRight.x=l.topLeft.x+c,l.bottomRight.y=l.topLeft.y+a,{id:t.id,type:t.type,props:{crop:l}}}var Oy;let gY=(Oy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0});const n=this.editor.getOnlySelectedShape();this.editor.on("change-history",this.cleanupCroppingState),n&&(this.editor.mark("crop"),this.editor.setCroppingShape(n.id))});m(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.off("change-history",this.cleanupCroppingState)});m(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});m(this,"onPointerDown",n=>{var r;if(!this.editor.getIsMenuOpen()){if(n.ctrlKey){this.cancel(),this.editor.root.handleEvent(n);return}switch(n.target){case"canvas":{const o=Hx(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...n,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(n);break}case"shape":{if(n.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",n);return}else(r=this.editor.getShapeUtil(n.shape))!=null&&r.canCrop(n.shape)?(this.editor.setCroppingShape(n.shape.id),this.editor.setSelectedShapes([n.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",n)):(this.cancel(),this.editor.root.handleEvent(n));break}case"selection":{switch(n.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",{...n,onInteractionEnd:"select.crop"});break}case"top":case"right":case"bottom":case"left":{this.editor.setCurrentTool("select.pointing_crop_handle",{...n,onInteractionEnd:"select.crop"});break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.pointing_crop_handle",{...n,onInteractionEnd:"select.crop"});break}default:this.cancel()}break}}}});m(this,"onDoubleClick",n=>{var i;if(this.editor.inputs.shiftKey||n.phase!=="up")return;const r=this.editor.getCroppingShapeId();if(!r)return;const o=this.editor.getShape(r);if(!o)return;const s=this.editor.getShapeUtil(o);s&&n.target==="selection"&&((i=s.onDoubleClickEdge)==null||i.call(s,o))});m(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});m(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});m(this,"onKeyUp",n=>{switch(n.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}});m(this,"cleanupCroppingState",()=>{this.editor.getCroppingShapeId()||this.editor.setCurrentTool("select.idle",{})})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(n=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new P(0,0);if(r.has("ArrowLeft")&&(s.x+=1),r.has("ArrowRight")&&(s.x-=1),r.has("ArrowUp")&&(s.y+=1),r.has("ArrowDown")&&(s.y-=1),s.equals(new P(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=z$(this.editor,i,s);a&&(n||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},m(Oy,"id","idle"),Oy);class B$ extends se{constructor(){super(...arguments);m(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",n)});m(this,"onPointerUp",n=>{this.editor.setCurrentTool("select.crop.idle",n)})}}m(B$,"id","pointing_crop");class U$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","translating crop");m(this,"snapshot",{});m(this,"onEnter",n=>{this.info=n,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});m(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onKeyDown",n=>{switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}});m(this,"onKeyUp",n=>{switch(n.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}})}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const n=this.snapshot.shape;if(!n)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=z$(this.editor,n,s);i&&this.editor.updateShapes([i],{squashing:!0})}}m(U$,"id","translating_crop");class qh extends se{}m(qh,"id","crop"),m(qh,"initial","idle"),m(qh,"children",()=>[gY,U$,B$]);const ur=8,dc={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 H$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n,this.updateCursor()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startResizing()});m(this,"onLongPress",()=>{this.startResizing()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const n=this.editor.getSelectedShapes(),r=dc[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:n.length===1?this.editor.getSelectionRotation():0}})}startResizing(){this.editor.getInstanceState().isReadonly||this.parent.transition("resizing",this.info)}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")}}m(H$,"id","pointing_resize_handle");class K$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"snapshot",{});m(this,"onEnter",n=>{this.info=n,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=dc[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:this.editor.getSelectionRotation()}})}updateShapes(){const{shape:n,cursorHandleOffset:r}=this.snapshot;if(!n||!this.editor.getShapeUtil("image"))return;const s=n.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),c=i.clone().sub(a).rot(-n.rotation),l=s.crop??this.getDefaultCrop(),u=Ye(l),d=new P(n.x,n.y),p=new P(0,0),f=1/(l.bottomRight.x-l.topLeft.x)*s.w,y=1/(l.bottomRight.y-l.topLeft.y)*s.h;let g=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(y<ur)break;g=!0,u.topLeft.y=u.topLeft.y+c.y/y,y*(u.bottomRight.y-u.topLeft.y)<ur?(u.topLeft.y=u.bottomRight.y-ur/y,p.y=(u.topLeft.y-l.topLeft.y)*y):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-l.topLeft.y)*y):p.y=c.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(y<ur)break;g=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+c.y/y),y*(u.bottomRight.y-u.topLeft.y)<ur&&(u.bottomRight.y=u.topLeft.y+ur/y);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<ur)break;g=!0,u.topLeft.x=u.topLeft.x+c.x/f,f*(u.bottomRight.x-u.topLeft.x)<ur?(u.topLeft.x=u.bottomRight.x-ur/f,p.x=(u.topLeft.x-l.topLeft.x)*f):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-l.topLeft.x)*f):p.x=c.x;break}case"right":case"top_right":case"bottom_right":{if(f<ur)break;g=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+c.x/f),f*(u.bottomRight.x-u.topLeft.x)<ur&&(u.bottomRight.x=u.topLeft.x+ur/f);break}}if(!g)return;d.add(p.rot(n.rotation));const w={id:n.id,type:n.type,x:d.x,y:d.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*f,h:(u.bottomRight.y-u.topLeft.y)*y}};this.editor.updateShapes([w],{squashing:!0}),this.updateCursor()}complete(){this.updateShapes(),We(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}createSnapshot(){const n=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=P.RotWith(s.getHandlePoint(this.info.handle),s.point,n),a=P.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}m(K$,"id","cropping");class W$ extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"initialHandle",{});m(this,"initialAdjacentHandle",null);m(this,"initialPagePoint",{});m(this,"markId","");m(this,"initialPageTransform");m(this,"initialPageRotation");m(this,"info",{});m(this,"isPrecise",!1);m(this,"isPreciseId",null);m(this,"pointingId",null);m(this,"onEnter",n=>{const{shape:r,isCreating:o,handle:s}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId=o?`creating:${r.id}`:"dragging handle",o||this.editor.mark(this.markId),this.initialHandle=Ye(s),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[s.index]:{id:s.index,index:s.index,x:s.x,y:s.y}}}});const l=this.editor.getShapeHandles(r).find(u=>u.index===s.index);this.initialHandle=Ye(l)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.updateInstanceState({cursor:{type:o?"cross":"grabbing",rotation:0}},{ephemeral:!0});const i=this.editor.getShapeHandles(r).sort(en),a=i.findIndex(c=>c.id===n.handle.id);this.initialAdjacentHandle=null;for(let c=a+1;c<i.length;c++){const l=i[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==n.handle.id){this.initialAdjacentHandle=l;break}}if(!this.initialAdjacentHandle)for(let c=i.length-1;c>=0;c--){const l=i[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==n.handle.id){this.initialAdjacentHandle=l;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=r.props[n.handle.id];this.isPrecise=!1,(c==null?void 0:c.type)==="binding"?(this.editor.setHintingShapes([c.boundShapeId]),this.isPrecise=c.isPrecise,this.isPrecise?this.isPreciseId=c.boundShapeId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)});m(this,"exactTimeout",-1);m(this,"onPointerMove",()=>{this.update()});m(this,"onKeyDown",()=>{this.update()});m(this,"onKeyUp",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.update(),this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=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)}complete(){this.editor.snaps.clearIndicators(),We(this.editor,[this.shapeId]);const{onInteractionEnd:n}=this.info;if(this.editor.getInstanceState().isToolLocked&&n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:n}=this.info;if(n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var _;const{editor:n,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,c=this.editor.getHintingShapeIds(),l=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:d,shiftKey:p,ctrlKey:f,altKey:y,pointerVelocity:g}}=n,w=this.info.shape,S=n.getShape(r);if(!S)return;const v=n.getShapeUtil(S);let b=d.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const k=P.Angle(a,b),T=Wp(k,24)-k;b=P.RotWith(b,a,T)}n.snaps.clearIndicators();let E={...s,x:b.x,y:b.y};if(s.canSnap&&(l?!f:f)){if(!n.getShapePageTransform(S.id))throw Error("Expected a page transform");const $=u.handles.snapHandle({currentShapeId:r,handle:E});$&&($.nudge.rot(-n.getShapeParentTransform(S).rotation()),b.add($.nudge),E={...s,x:b.x,y:b.y})}const C=(_=v.onHandleDrag)==null?void 0:_.call(v,S,{handle:E,isPrecise:this.isPrecise||y,initial:w}),I={...S,...C};if(s.canBind){const k=I.props[s.id];(k==null?void 0:k.type)==="binding"?c[0]!==k.boundShapeId&&(n.setHintingShapes([k.boundShapeId]),this.pointingId=k.boundShapeId,this.isPrecise=g.len()<.5||y,this.isPreciseId=this.isPrecise?k.boundShapeId:null,this.resetExactTimeout()):c.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([I],{squashing:!0})}}m(W$,"id","dragging_handle");function V$(e){return e.isLabel?[e]:e instanceof Br?e.children.filter(t=>t.isLabel):[]}class G$ extends se{constructor(){super(...arguments);m(this,"hitShapeForPointerUp",null);m(this,"onEnter",()=>{const n=this.editor.getEditingShape();if(!n)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Ya(this.editor),this.editor.select(n)});m(this,"onExit",()=>{var s;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null);const r=this.editor.getShape(n),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r)});m(this,"onPointerMove",n=>{if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",n),this.hitShapeForPointerUp=null;return}switch(n.target){case"shape":case"canvas":{Ya(this.editor);return}}});m(this,"onPointerDown",n=>{switch(this.hitShapeForPointerUp=null,n.target){case"canvas":{const r=Hx(this.editor,!0);if(r){this.onPointerDown({...n,shape:r,target:"shape"});return}break}case"shape":{const{shape:r}=n,o=this.editor.getEditingShape();if(!o)throw Error("Expected an editing shape!");const s=this.editor.getShapeUtil(r).getGeometry(r),i=V$(s),a=i.length===1?i[0]:void 0,c=this.editor.isShapeOfType(o,"text")&&o.props.text.trim()==="";if(a&&!c){const l=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(l,0)&&a.hitTestPoint(l)){if(r.id===o.id)return;this.hitShapeForPointerUp=r,this.editor.mark("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===o.id)this.editor.isShapeOfType(r,"frame")&&this.editor.setEditingShape(null);else{this.parent.transition("pointing_shape",n);return}return}break}}this.parent.transition("idle",n),this.editor.root.handleEvent(n)});m(this,"onPointerUp",n=>{const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const o=this.editor.getShapeUtil(r);if(this.editor.getInstanceState().isReadonly&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),Ya(this.editor)});m(this,"onComplete",n=>{this.parent.transition("idle",n)});m(this,"onCancel",n=>{this.parent.transition("idle",n)})}}m(G$,"id","editing_shape");function _C(e){const t=e.getOnlySelectedShape();return!!(t&&!e.isShapeOrAncestorLocked(t)&&e.getShapeUtil(t).canCrop(t))}function cf(e){const t=e.getSelectedShapeIds(),{shiftKey:n,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin:Ko/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(s){const i=e.getOutermostSelectableShape(s);if(n&&!r)e.cancelDoubleClick(),t.includes(i.id)?(e.mark("deselecting shape"),e.deselect(i)):(e.mark("shift selecting shape"),e.setSelectedShapes([...t,i.id]));else{let a;i===s||i.id===e.getFocusedGroupId()||t.includes(i.id)?a=s:a=i,a&&!t.includes(a.id)&&(e.mark("selecting shape"),e.select(a.id))}}else{if(n)return;{t.length>0&&(e.mark("selecting none"),e.selectNone());const i=e.getFocusedGroupId();if(Kn(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const mY=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Dy;let yY=(Dy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Ya(this.editor),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerMove",()=>{Ya(this.editor)});m(this,"onPointerDown",n=>{if(this.editor.getIsMenuOpen())return;const r=n.ctrlKey&&_C(this.editor);if(n.ctrlKey&&!r){if(n.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(n.shape)){this.parent.transition("pointing_shape",n);return}this.parent.transition("brushing",n);return}switch(n.target){case"canvas":{const o=Hx(this.editor);if(o&&!o.isLocked){this.onPointerDown({...n,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&kC(this.editor,a)){this.onPointerDown({...n,target:"selection"});return}this.parent.transition("pointing_canvas",n);break}case"shape":{const{shape:o}=n;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",n);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",n);break}this.parent.transition("pointing_shape",n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",n):this.parent.transition("pointing_handle",n);break}case"selection":{switch(n.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",n);break}case"top":case"right":case"bottom":case"left":{r?this.parent.transition("pointing_crop_handle",n):this.parent.transition("pointing_resize_handle",n);break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("pointing_crop_handle",n):this.parent.transition("pointing_resize_handle",n);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...n,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",n)}}break}}});m(this,"onDoubleClick",n=>{var r,o,s,i;if(!(this.editor.inputs.shiftKey||n.phase!=="up"))switch(n.target){case"canvas":{const a=this.editor.getHoveredShape(),c=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:Ko/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(c){if(this.editor.isShapeOfType(c,"group")){cf(this.editor);return}else{const u=this.editor.getShape(c.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(l&&u.id===l)){cf(this.editor);return}}this.onDoubleClick({...n,shape:c,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(n);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const c=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(n.handle==="right"||n.handle==="left"||n.handle==="top"||n.handle==="bottom"){const l=(r=c.onDoubleClickEdge)==null?void 0:r.call(c,a);if(l){this.editor.mark("double click edge"),this.editor.updateShapes([l]),We(this.editor,[a.id]);return}}if(c.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",n);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}break}case"shape":{const{shape:a}=n,c=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(c.onDoubleClick){const l=(o=c.onDoubleClick)==null?void 0:o.call(c,a);if(l){this.editor.updateShapes([l]);return}else if(c.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((s=n.shape)==null?void 0:s.id),this.parent.transition("crop",n);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,n,!0):this.handleDoubleClickOnCanvas(n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:c}=n,l=this.editor.getShapeUtil(a),u=(i=l.onDoubleClickHandle)==null?void 0:i.call(l,a,c);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}}});m(this,"onRightClick",n=>{switch(n.target){case"canvas":{const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:Ko/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...n,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&kC(this.editor,a)){this.onRightClick({...n,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=n,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));r.includes(s.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});m(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});m(this,"onKeyDown",n=>{switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if($t.editOnType.get()&&!mY.includes(n.key)&&!n.altKey&&!n.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...n,target:"shape",shape:r},!0);return}}});m(this,"onKeyRepeat",n=>{switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});m(this,"onKeyUp",n=>{switch(n.code){case"Enter":{const r=this.editor.getSelectedShapes();if(r.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(r.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const o=this.editor.getOnlySelectedShape();if(o&&this.shouldStartEditingShape(o)){this.startEditingShape(o,{...n,target:"shape",shape:o},!0);return}_C(this.editor)&&this.parent.transition("crop",n);break}}});m(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}shouldStartEditingShape(n=this.editor.getOnlySelectedShape()){return!n||this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||!this.canInteractWithShapeInReadOnly(n)?!1:this.editor.getShapeUtil(n).canEdit(n)}startEditingShape(n,r,o){this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||(this.editor.mark("editing shape"),sf(this.editor,n,o),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(n){if(!n)return!1;const r=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(n,"arrow")){const o=this.editor.getShapeGeometry(n).children[1];if(o&&Zn(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(n){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=Be(),{x:o,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:o,y:s,props:{text:"",autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",n))}nudgeSelectedShapes(n=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new P(0,0);if(r.has("ArrowLeft")&&(s.x-=1),r.has("ArrowRight")&&(s.x+=1),r.has("ArrowUp")&&(s.y-=1),r.has("ArrowDown")&&(s.y+=1),s.equals(new P(0,0)))return;n||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*xY:i:o?SY:vY,c=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(c,s.mul(a)),We(this.editor,c)}canInteractWithShapeInReadOnly(n){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(n).canEditInReadOnly(n))}},m(Dy,"id","idle"),Dy);const SY=10,vY=1,xY=5;function kC(e,t){const n=e.getSelectionRotatedPageBounds();if(!n)return!1;const r=e.getSelectionRotation();return r?Zn(t,n.corners.map(o=>P.RotWith(o,n.point,r))):n.containsPoint(t)}class Y$ extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"markId","");m(this,"wasAlreadySelected",!1);m(this,"didDrag",!1);m(this,"info",{});m(this,"onEnter",n=>{const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const s=this.editor.getShapeGeometry(r).children[1];if(!s)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=P.Sub(s.center,a),this.markId="label-drag start",this.editor.mark(this.markId),this.editor.setSelectedShapes([this.shapeId])});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"_labelDragOffset",new P(0,0));m(this,"onPointerMove",()=>{const{isDragging:n}=this.editor.inputs;if(!n)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=this.editor.getArrowInfo(r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),c=i.nearestPoint(P.Add(a,this._labelDragOffset));let l;if(o.isStraight){const u=P.Dist(o.start.point,o.end.point);l=1-P.Dist(o.end.point,c)/u}else{const{_center:u,measure:d,angleEnd:p,angleStart:f}=s.children[0];l=FS(d,f,p,u.angle(c))}isNaN(l)&&(l=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:l}},{squashing:!0})});m(this,"onPointerUp",()=>{const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}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")}}m(Y$,"id","pointing_arrow_label");class X$ extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{const{inputs:n}=this.editor;n.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",n)});m(this,"onPointerUp",()=>{cf(this.editor),this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}m(X$,"id","pointing_canvas");class q$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=dc[this.info.handle];this.editor.updateInstanceState({cursor:{type:o,rotation:this.editor.getSelectionRotation()}}),this.editor.setCroppingShape(r.id)});m(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});m(this,"onLongPress",()=>{this.startCropping()});m(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}}m(q$,"id","pointing_crop_handle");class Z$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const o=r.props[n.handle.id];(o==null?void 0:o.type)==="binding"&&this.editor.setHintingShapes([o.boundShapeId])}this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});m(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerUp",()=>{const{shape:n,handle:r}=this.info;if(this.editor.isShapeOfType(n,"note")){const{editor:o}=this,s=TC(o,n,r,!1);if(s){sf(o,s,!0);return}}this.parent.transition("idle",this.info)});m(this,"onPointerMove",()=>{const{editor:n}=this;n.inputs.isDragging&&this.startDraggingHandle()});m(this,"onLongPress",()=>{this.startDraggingHandle()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startDraggingHandle(){const{editor:n}=this;if(n.getInstanceState().isReadonly)return;const{shape:r,handle:o}=this.info;if(n.isShapeOfType(r,"note")){const s=TC(n,r,o,!0);if(s){const i=n.getPointInParentSpace(s,n.inputs.originPagePoint).sub(P.Rot(Dx,s.rotation));n.updateShape({...s,x:i.x,y:i.y}),n.setHoveredShape(s.id).select(s.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(s),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{sf(n,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}m(Z$,"id","pointing_handle");function TC(e,t,n,r){const o=e.getShapePageTransform(t.id),s=o.point(),i=o.rotation(),c=l$(s,i,t.props.growY,0)[n.index];if(c)return d$(e,t,c,i,r)}class Q$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startRotating()});m(this,"onLongPress",()=>{this.startRotating()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.updateInstanceState({cursor:{type:dc[this.info.handle],rotation:this.editor.getSelectionRotation()}})}startRotating(){this.editor.getInstanceState().isReadonly||this.parent.transition("rotating",this.info)}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")}}m(Q$,"id","pointing_rotate_handle");class J$ extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n});m(this,"onPointerUp",n=>{cf(this.editor),this.parent.transition("idle",n)});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startTranslating(n)});m(this,"onLongPress",n=>{this.startTranslating(n)});m(this,"onDoubleClick",n=>{var s,i;const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(o){this.parent.transition("idle"),(i=(s=this.parent).onDoubleClick)==null||i.call(s,{...n,target:"shape",shape:this.editor.getShape(o)});return}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(n){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",n)}cancel(){this.parent.transition("idle")}}m(J$,"id","pointing_selection");class eM extends se{constructor(){super(...arguments);m(this,"hitShape",{});m(this,"hitShapeForPointerUp",{});m(this,"isDoubleClick",!1);m(this,"didSelectOnEnter",!1);m(this,"onEnter",n=>{const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:c}}=this.editor;this.hitShape=n.shape,this.isDoubleClick=!1;const l=this.editor.getOutermostSelectableShape(n.shape),u=this.editor.findShapeAncestor(l,d=>r.includes(d.id));if(this.editor.getShapeUtil(n.shape).onClick||l.id===s||r.includes(l.id)||u||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=l;return}this.didSelectOnEnter=!0,a&&!c?(this.editor.cancelDoubleClick(),r.includes(l.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,l.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([l.id]))});m(this,"onPointerUp",n=>{var u;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,c=this.editor.getShapeAtPoint(i,{margin:Ko/s,hitInside:!0,renderingOnly:!0})??this.hitShape,l=c?this.editor.getOutermostSelectableShape(c):this.hitShapeForPointerUp;if(l){const d=this.editor.getShapeUtil(l);if(d.onClick){const p=(u=d.onClick)==null?void 0:u.call(d,l);if(p){this.editor.mark("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",n);return}}if(l.id===o){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",n);return}}if(!this.didSelectOnEnter){const d=this.editor.getOutermostSelectableShape(c,p=>!r.includes(p.id));if(r.includes(d.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(l);else if(r.includes(l.id)){if(r.length===1){const p=this.editor.getShapeUtil(l).getGeometry(l),f=V$(p),y=f.length===1?f[0]:void 0;if(y){const g=this.editor.getPointInShapeSpace(l,i);if(y.bounds.containsPoint(g,0)&&y.hitTestPoint(g)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(l.id);const w=this.editor.getShapeUtil(l);this.editor.getInstanceState().isReadonly&&!w.canEditInReadOnly(l)||(this.editor.setEditingShape(l.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:l.id}))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(l.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(l);else if(a){const p=this.editor.getShapeAncestors(d);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(f=>!p.find(y=>y.id===f)),d.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([d.id])}this.parent.transition("idle",n)});m(this,"onDoubleClick",()=>{this.isDoubleClick=!0});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startTranslating(n)});m(this,"onLongPress",n=>{this.startTranslating(n)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(n){this.editor.getInstanceState().isReadonly||(this.editor.getContainer().focus(),this.parent.transition("translating",n))}cancel(){this.parent.transition("idle")}}m(eM,"id","pointing_shape");class tM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"didHoldCommand",!1);m(this,"creationCursorOffset",{x:0,y:0});m(this,"snapshot",{});m(this,"onEnter",n=>{const{isCreating:r=!1,creationCursorOffset:o={x:0,y:0}}=n;this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),r?(this.markId=`creating:${this.editor.getOnlySelectedShape().id}`,this.editor.updateInstanceState({cursor:{type:"cross",rotation:0}},{ephemeral:!0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});m(this,"onTick",()=>{hx(this.editor)});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onKeyDown",()=>{this.updateShapes()});m(this,"onKeyUp",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.snaps.clearIndicators()});m(this,"_createSnapshot",()=>{const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=P.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=P.Sub(o,i),c=new Map,l=[];n.forEach(d=>{const p=this.editor.getShape(d);if(p){if(p.type==="frame"&&l.push({id:d,children:fe(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),c.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&n.length===1)return;this.editor.visitDescendants(p.id,f=>{const y=this.editor.getShape(f);if(y&&(c.set(y.id,this._createShapeSnapshot(y)),this.editor.isShapeOfType(y,"frame")))return!1})}});const u=![...c.values()].some(d=>!Hk(d.pageRotation,r)||d.isAspectRatioLocked);return{shapeSnapshots:c,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:l}});m(this,"_createShapeSnapshot",n=>{const r=this.editor.getShapePageTransform(n),o=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:oe.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(n)}})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(We(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(n=this.info).onCreate)==null||r.call(n,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:o})=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onResizeStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:o})=>{var c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onResizeEnd)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:n,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:c,selectionRotation:l,canShapesDeform:u}=this.snapshot,d=r||!u,{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),y=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:k}=this.editor.getDocumentSettings();f.snapToGrid(k)}const g=this.info.handle,w=$C(g,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&l%ze===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:P.Sub(f,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:$C(g,l),isAspectRatioLocked:d,isResizingFromCenter:n});f.add(k)}const v=P.RotWith(n?i.center:i.getHandlePoint(w),i.point,l),b=P.Sub(f,v).rot(-l),E=P.Sub(y,v).rot(-l),C=P.DivV(b,E);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const I=g==="top"||g==="bottom",_=g==="left"||g==="right";d?_?C.y=Math.abs(C.x):I?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(I&&(C.x=1),_&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:g,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:l});for(const k of s.keys()){const $=s.get(k);this.editor.resizeShape(k,C,{initialShape:$.shape,initialBounds:$.bounds,initialPageTransform:$.pageTransform,dragHandle:g,mode:c.length===1&&k===c[0]?"resize_bounds":"scale_shape",scaleOrigin:v,scaleAxisRotation:l})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:$}of o){if(!$.length)continue;const T=s.get(k).shape,O=this.editor.getShape(k);if(!(T&&O))continue;const N=O.x-T.x,F=O.y-T.y,L=new P(N,F).rot(-T.rotation);if(L.x!==0||L.y!==0)for(const B of $)this.editor.updateShape({id:B.id,type:B.type,x:B.x-L.x,y:B.y-L.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of o)if(k.length)for(const $ of k)this.editor.updateShape({id:$.id,type:$.type,x:$.x,y:$.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}}m(tM,"id","resizing");const Jm=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function $C(e,t){t=t%Oe;const n=Math.round(t/(Pe/4)),r=Jm.indexOf(e);return Jm[(r+n)%Jm.length]}const MC=Math.PI/180;class nM extends se{constructor(){super(...arguments);m(this,"snapshot",{});m(this,"info",{});m(this,"markId","");m(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=M2({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});wh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.updateInstanceState({cursor:{type:dc[this.info.handle],rotation:o+this.snapshot.initialSelectionRotation}})});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});m(this,"onPointerMove",()=>{this.update()});m(this,"onKeyDown",()=>{this.update()});m(this,"onKeyUp",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"update",()=>{const n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});wh({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.updateInstanceState({cursor:{type:dc[this.info.handle],rotation:n+this.snapshot.initialSelectionRotation}})});m(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});m(this,"complete",()=>{wh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),We(this.editor,this.snapshot.shapeSnapshots.map(n=>n.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)})}_getRotationFromPointerPosition({snapToNearestDegree:n}){const r=this.editor.getSelectionRotation(),o=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:s,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:c}=this.snapshot;if(!o)return c;const u=o.center.clone().rotWith(o.point,r).angle(i)-a;let d=c+u;if(s)d=Wp(d,24);else if(n&&(d=Math.round(d/MC)*MC,this.editor.getInstanceState().isCoarsePointer)){const p=Wp(d,4),f=yh(d,p);Math.abs(f)<x5(5)&&(d=p)}return d-c}}m(nM,"id","rotating");class rM extends se{constructor(){super(...arguments);m(this,"hits",new Set);m(this,"size",0);m(this,"scribbleId","id");m(this,"initialSelectedShapeIds",new Set);m(this,"newlySelectedShapeIds",new Set);m(this,"onEnter",()=>{this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const n=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=n.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});m(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)})}updateScribbleSelection(n){const{editor:r}=this,o=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:c}}=this.editor,{newlySelectedShapeIds:l,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const d=o;let p,f,y,g;const w=0;for(let b=0,E=d.length;b<E;b++){if(p=d[b],r.isShapeOfType(p,"group")||l.has(p.id)||r.isShapeOrAncestorLocked(p)||(f=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&f.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const C=r.getShapePageTransform(p);if(!f||!C)continue;const I=C.clone().invert();y=I.applyToPoint(a),g=I.applyToPoint(c);const{bounds:_}=f;if(!(_.minX-w>Math.max(y.x,g.x)||_.minY-w>Math.max(y.y,g.y)||_.maxX+w<Math.min(y.x,g.x)||_.maxY+w<Math.min(y.y,g.y))&&f.hitTestLineSegment(y,g,w)){const k=this.editor.getOutermostSelectableShape(p),$=this.editor.getShapeMask(k.id);if($&&nx(a,c,$)!==null&&!Zn(c,$))continue;l.add(k.id)}}const S=r.getSelectedShapeIds(),v=new Set(s?[...l,...u]:[...l]);(S.length!==v.size||S.some(b=>!v.has(b)))&&this.editor.setSelectedShapes(Array.from(v),{squashing:!0})}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds],{squashing:!0}),this.parent.transition("idle")}}m(rM,"id","scribble_brushing");const wY=20,bY=100;class PY{constructor(t){m(this,"prevDroppingShapeId",null);m(this,"droppingNodeTimer",null);m(this,"first",!0);m(this,"dispose",()=>{this.clear()});this.editor=t,t.disposables.add(this.dispose)}updateDroppingNode(t,n){var r;this.first&&(this.editor.setHintingShapes(t.map(o=>this.editor.findShapeAncestor(o,s=>s.type!=="group")).filter(o=>o)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,t))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(t,wY,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearInterval(this.droppingNodeTimer),this.setDragTimer(t,bY,n))}setDragTimer(t,n,r){this.droppingNodeTimer=setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,t,r)}),this.droppingNodeTimer=null},n)}handleDrag(t,n,r){var c,l,u,d,p;n=fe(n.map(f=>this.editor.getShape(f.id)));const o=((c=this.editor.getDroppingOverShape(t,n))==null?void 0:c.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);i&&((u=(l=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(l,i,n)),a&&((p=(d=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(d,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=o}hintParents(t){const n=new Map;for(const o of t){const s=this.editor.findShapeAncestor(o,i=>i.type!=="group");s&&(n.has(s.id)||n.set(s.id,[]),n.get(s.id).push(o.id))}const r=[];for(const[o,s]of n){const i=this.editor.getShape(o);i&&i$(this.editor,i).length<s.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(t){var r,o;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,t),n){const s=this.editor.getShape(n);if(!s)return;(o=(r=this.editor.getShapeUtil(s)).onDropShapesOver)==null||o.call(r,s,t)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearInterval(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class oM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"selectionSnapshot",{});m(this,"snapshot",{});m(this,"markId","");m(this,"isCloning",!1);m(this,"isCreating",!1);m(this,"onCreate",()=>{});m(this,"dragAndDropManager",new PY(this.editor));m(this,"onEnter",n=>{const{isCreating:r=!1,onCreate:o=()=>{}}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.isCreating=r,this.onCreate=o,r?this.markId=`creating:${this.editor.getOnlySelectedShape().id}`:(this.markId="translating",this.editor.mark(this.markId)),this.isCloning=!1,this.info=n,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=AC(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()});m(this,"onTick",()=>{this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),hx(this.editor)});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});m(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"updateParentTransforms",()=>{const{editor:n,snapshot:{shapeSnapshots:r}}=this;r.forEach(o=>{const s=n.getShape(o.shape.id);if(!s)return null;const i=bn(s.parentId)?null:oe.Inverse(n.getShapePageTransform(s.parentId));o.parentTransform=i})})}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=AC(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){var n;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),We(this.editor,this.snapshot.movingShapes.map(r=>r.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(n=this.onCreate)==null||n.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:n}=this.snapshot,r=[];n.forEach(o=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onTranslateStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:n}=this.snapshot;if(this.isCloning&&n.length>0){const o=P.Average(n.map(i=>this.editor.getShapePageTransform(i.id).point())),s=P.Sub(o,this.selectionSnapshot.averagePagePoint);P.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:n.map(i=>i.id),offset:{x:s.x,y:s.y}}})}const r=[];n.forEach(o=>{var c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onTranslateEnd)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}handleChange(){const{movingShapes:n}=this.snapshot,r=[];n.forEach(o=>{var c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onTranslate)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:n}=this;this.dragAndDropManager.updateDroppingNode(n.movingShapes,this.updateParentTransforms),CY({editor:this.editor,snapshot:n}),this.handleChange()}}m(oM,"id","translating");function AC(e){var d;const t=[],n=[],r=e.getSelectedShapeIds(),o=fe(r.map(p=>{const f=e.getShape(p);if(!f)return null;t.push(f);const y=e.getShapePageTransform(p),g=y.point(),w=y.rotation();n.push(g);const S=Ho.isId(f.parentId)?null:oe.Inverse(e.getShapePageTransform(f.parentId));return{shape:f,pagePoint:g,pageRotation:w,parentTransform:S}})),s=e.getOnlySelectedShape();let i=[];if(s)i=e.snaps.shapeBounds.getSnapPoints(s.id);else{const p=e.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((f,y)=>({id:"selection:"+y,x:f.x,y:f.y})))}let a,c;const{originPagePoint:l}=e.inputs,u=o.filter(p=>e.isShapeOfType(p.shape,"note")&&e.isPointInShape(p.shape,l));if(u.length!==0)if(u.length===1)c=u[0];else{const p=e.getCurrentPageShapesSorted();c=(d=u.map(f=>({snapshot:f,index:p.findIndex(y=>y.id===f.shape.id)})).sort((f,y)=>y.index-f.index)[0])==null?void 0:d.snapshot}return c&&(a=u$(e,c.pageRotation,c.shape.props.growY??0)),{averagePagePoint:P.Average(n),movingShapes:t,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:c}}function CY({editor:e,snapshot:t}){const{inputs:n}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:c}=t,l=e.getInstanceState().isGridMode,u=e.getDocumentSettings().gridSize,d=P.Sub(n.currentPagePoint,n.originPagePoint),p=e.inputs.shiftKey?Math.abs(d.x)<Math.abs(d.y)?"x":"y":null;if(p==="x"?d.x=0:p==="y"&&(d.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:w}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:d,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});d.add(w)}else if(r&&o){let w=c$/e.getZoomLevel(),S=new P(0,0);const v=P.Add(P.Add(r.pagePoint,d),new P(Te/2,Te/2).rot(r.pageRotation));for(const b of o){const E=P.Sub(v,b),C=E.len();C<w&&(w=C,S=E)}d.sub(S)}const y=P.Add(c,d);l&&!n.ctrlKey&&y.snapToGrid(u);const g=P.Sub(y,c);e.updateShapes(fe(a.map(({shape:w,pagePoint:S,parentTransform:v})=>{const b=P.Add(S,g),E=v?oe.applyToPoint(v,b):b;return{id:w.id,type:w.type,x:E.x,y:E.y}})),{squashing:!0})}class Zh extends se{constructor(){super(...arguments);m(this,"reactor");m(this,"cleanUpDuplicateProps",()=>{const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);n.length===o.size&&n.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})});m(this,"onEnter",()=>{this.reactor=Sc("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){typeof process<"u",console.error(n)}})});m(this,"onExit",()=>{var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}m(Zh,"id","select"),m(Zh,"initial","idle"),m(Zh,"children",()=>[qh,K$,yY,X$,eM,oM,N$,rM,q$,J$,H$,G$,tM,nM,Q$,Y$,Z$,W$]);class sM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n});m(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}m(sM,"id","idle");class iM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n});m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});m(this,"onCancel",()=>{this.cancel()})}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{duration:220}):this.editor.zoomIn(n,{duration:220}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}m(iM,"id","pointing");class aM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"zoomBrush",new ne);m(this,"onEnter",n=>{this.info=n,this.update()});m(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(ne.FromPoints([n,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:n}=this,r=8/this.editor.getZoomLevel();if(n.width<r&&n.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{duration:220}):this.editor.zoomIn(o,{duration:220})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:o,duration:220})}this.parent.transition("idle",this.info)}}m(aM,"id","zoom_brushing");class Qh extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onKeyDown",()=>{this.updateCursor()});m(this,"onKeyUp",n=>{this.updateCursor(),n.code==="KeyZ"&&this.complete()});m(this,"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.updateInstanceState({cursor:{type:"zoom-out",rotation:0}},{ephemeral:!0}):this.editor.updateInstanceState({cursor:{type:"zoom-in",rotation:0}},{ephemeral:!0})}}m(Qh,"id","zoom"),m(Qh,"initial","idle"),m(Qh,"children",()=>[sM,aM,iM]);const IY=[Gh,Yh,Xh,Qh,Zh];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(null,arguments)}function ie(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function EY(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function rg(...e){return t=>e.forEach(n=>EY(n,t))}function Xe(...e){return x.useCallback(rg(...e),e)}function mo(e,t=[]){let n=[];function r(s,i){const a=x.createContext(i),c=n.length;n=[...n,i];function l(d){const{scope:p,children:f,...y}=d,g=(p==null?void 0:p[e][c])||a,w=x.useMemo(()=>y,Object.values(y));return x.createElement(g.Provider,{value:w},f)}function u(d,p){const f=(p==null?void 0:p[e][c])||a,y=x.useContext(f);if(y)return y;if(i!==void 0)return i;throw new Error(`\`${d}\` must be used within \`${s}\``)}return l.displayName=s+"Provider",[l,u]}const o=()=>{const s=n.map(i=>x.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,_Y(o,...t)]}function _Y(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:c,scopeName:l})=>{const d=c(s)[`__scope${l}`];return{...a,...d}},{});return x.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}const Oi=x.forwardRef((e,t)=>{const{children:n,...r}=e,o=x.Children.toArray(n),s=o.find(TY);if(s){const i=s.props.children,a=o.map(c=>c===s?x.Children.count(i)>1?x.Children.only(null):x.isValidElement(i)?i.props.children:null:c);return x.createElement(yv,X({},r,{ref:t}),x.isValidElement(i)?x.cloneElement(i,void 0,a):null)}return x.createElement(yv,X({},r,{ref:t}),n)});Oi.displayName="Slot";const yv=x.forwardRef((e,t)=>{const{children:n,...r}=e;return x.isValidElement(n)?x.cloneElement(n,{...$Y(r,n.props),ref:t?rg(t,n.ref):n.ref}):x.Children.count(n)>1?x.Children.only(null):null});yv.displayName="SlotClone";const kY=({children:e})=>x.createElement(x.Fragment,null,e);function TY(e){return x.isValidElement(e)&&e.type===kY}function $Y(e,t){const n={...t};for(const r in t){const o=e[r],s=t[r];/^on[A-Z]/.test(r)?o&&s?n[r]=(...a)=>{s(...a),o(...a)}:o&&(n[r]=o):r==="style"?n[r]={...o,...s}:r==="className"&&(n[r]=[o,s].filter(Boolean).join(" "))}return{...e,...n}}function og(e){const t=e+"CollectionProvider",[n,r]=mo(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:y,children:g}=f,w=Se.useRef(null),S=Se.useRef(new Map).current;return Se.createElement(o,{scope:y,itemMap:S,collectionRef:w},g)},a=e+"CollectionSlot",c=Se.forwardRef((f,y)=>{const{scope:g,children:w}=f,S=s(a,g),v=Xe(y,S.collectionRef);return Se.createElement(Oi,{ref:v},w)}),l=e+"CollectionItemSlot",u="data-radix-collection-item",d=Se.forwardRef((f,y)=>{const{scope:g,children:w,...S}=f,v=Se.useRef(null),b=Xe(y,v),E=s(l,g);return Se.useEffect(()=>(E.itemMap.set(v,{ref:v,...S}),()=>void E.itemMap.delete(v))),Se.createElement(Oi,{[u]:"",ref:b},w)});function p(f){const y=s(e+"CollectionConsumer",f);return Se.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${u}]`));return Array.from(y.itemMap.values()).sort((E,C)=>S.indexOf(E.ref.current)-S.indexOf(C.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:d},p,r]}const MY=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ke=MY.reduce((e,t)=>{const n=x.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?Oi:t;return x.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),x.createElement(a,X({},i,{ref:o}))});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Kx(e,t){e&&Ui.flushSync(()=>e.dispatchEvent(t))}function sn(e){const t=x.useRef(e);return x.useEffect(()=>{t.current=e}),x.useMemo(()=>(...n)=>{var r;return(r=t.current)===null||r===void 0?void 0:r.call(t,...n)},[])}function AY(e,t=globalThis==null?void 0:globalThis.document){const n=sn(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r),()=>t.removeEventListener("keydown",r)},[n,t])}const Sv="dismissableLayer.update",jY="dismissableLayer.pointerDownOutside",OY="dismissableLayer.focusOutside";let jC;const cM=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),sg=x.forwardRef((e,t)=>{var n;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:a,onDismiss:c,...l}=e,u=x.useContext(cM),[d,p]=x.useState(null),f=(n=d==null?void 0:d.ownerDocument)!==null&&n!==void 0?n:globalThis==null?void 0:globalThis.document,[,y]=x.useState({}),g=Xe(t,k=>p(k)),w=Array.from(u.layers),[S]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=w.indexOf(S),b=d?w.indexOf(d):-1,E=u.layersWithOutsidePointerEventsDisabled.size>0,C=b>=v,I=RY(k=>{const $=k.target,T=[...u.branches].some(O=>O.contains($));!C||T||(s==null||s(k),a==null||a(k),k.defaultPrevented||c==null||c())},f),_=LY(k=>{const $=k.target;[...u.branches].some(O=>O.contains($))||(i==null||i(k),a==null||a(k),k.defaultPrevented||c==null||c())},f);return AY(k=>{b===u.layers.size-1&&(o==null||o(k),!k.defaultPrevented&&c&&(k.preventDefault(),c()))},f),x.useEffect(()=>{if(d)return r&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(jC=f.body.style.pointerEvents,f.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),OC(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=jC)}},[d,f,r,u]),x.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),OC())},[d,u]),x.useEffect(()=>{const k=()=>y({});return document.addEventListener(Sv,k),()=>document.removeEventListener(Sv,k)},[]),x.createElement(Ke.div,X({},l,{ref:g,style:{pointerEvents:E?C?"auto":"none":void 0,...e.style},onFocusCapture:ie(e.onFocusCapture,_.onFocusCapture),onBlurCapture:ie(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:ie(e.onPointerDownCapture,I.onPointerDownCapture)}))}),DY=x.forwardRef((e,t)=>{const n=x.useContext(cM),r=x.useRef(null),o=Xe(t,r);return x.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),x.createElement(Ke.div,X({},e,{ref:o}))});function RY(e,t=globalThis==null?void 0:globalThis.document){const n=sn(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let u=function(){lM(jY,n,l,{discrete:!0})};var c=u;const l={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=u,t.addEventListener("click",o.current,{once:!0})):u()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function LY(e,t=globalThis==null?void 0:globalThis.document){const n=sn(e),r=x.useRef(!1);return x.useEffect(()=>{const o=s=>{s.target&&!r.current&&lM(OY,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function OC(){const e=new CustomEvent(Sv);document.dispatchEvent(e)}function lM(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Kx(o,s):o.dispatchEvent(s)}const FY=sg,NY=DY,ig=x.forwardRef((e,t)=>{var n;const{container:r=globalThis==null||(n=globalThis.document)===null||n===void 0?void 0:n.body,...o}=e;return r?d3.createPortal(x.createElement(Ke.div,X({},o,{ref:t})),r):null}),Di=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{};function zY(e,t){return x.useReducer((n,r)=>{const o=t[n][r];return o??n},e)}const yo=e=>{const{present:t,children:n}=e,r=BY(t),o=typeof n=="function"?n({present:r.isPresent}):x.Children.only(n),s=Xe(r.ref,o.ref);return typeof n=="function"||r.isPresent?x.cloneElement(o,{ref:s}):null};yo.displayName="Presence";function BY(e){const[t,n]=x.useState(),r=x.useRef({}),o=x.useRef(e),s=x.useRef("none"),i=e?"mounted":"unmounted",[a,c]=zY(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const l=Ud(r.current);s.current=a==="mounted"?l:"none"},[a]),Di(()=>{const l=r.current,u=o.current;if(u!==e){const p=s.current,f=Ud(l);e?c("MOUNT"):f==="none"||(l==null?void 0:l.display)==="none"?c("UNMOUNT"):c(u&&p!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),Di(()=>{if(t){const l=d=>{const f=Ud(r.current).includes(d.animationName);d.target===t&&f&&Ui.flushSync(()=>c("ANIMATION_END"))},u=d=>{d.target===t&&(s.current=Ud(r.current))};return t.addEventListener("animationstart",u),t.addEventListener("animationcancel",l),t.addEventListener("animationend",l),()=>{t.removeEventListener("animationstart",u),t.removeEventListener("animationcancel",l),t.removeEventListener("animationend",l)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:x.useCallback(l=>{l&&(r.current=getComputedStyle(l)),n(l)},[])}}function Ud(e){return(e==null?void 0:e.animationName)||"none"}function Zs({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,o]=UY({defaultProp:t,onChange:n}),s=e!==void 0,i=s?e:r,a=sn(n),c=x.useCallback(l=>{if(s){const d=typeof l=="function"?l(e):l;d!==e&&a(d)}else o(l)},[s,e,o,a]);return[i,c]}function UY({defaultProp:e,onChange:t}){const n=x.useState(e),[r]=n,o=x.useRef(r),s=sn(t);return x.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),n}const uM=x.forwardRef((e,t)=>x.createElement(Ke.span,X({},e,{ref:t,style:{position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal",...e.style}}))),dM="ToastProvider",[Wx,HY,KY]=og("Toast"),[hM,Poe]=mo("Toast",[KY]),[WY,ag]=hM(dM),pM=e=>{const{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,c]=x.useState(null),[l,u]=x.useState(0),d=x.useRef(!1),p=x.useRef(!1);return x.createElement(Wx.Provider,{scope:t},x.createElement(WY,{scope:t,label:n,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:l,viewport:a,onViewportChange:c,onToastAdd:x.useCallback(()=>u(f=>f+1),[]),onToastRemove:x.useCallback(()=>u(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:d,isClosePausedRef:p},i))};pM.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const t=`Invalid prop \`label\` supplied to \`${dM}\`. Expected non-empty \`string\`.`;return new Error(t)}return null}};const VY="ToastViewport",GY=["F8"],vv="toast.viewportPause",xv="toast.viewportResume",YY=x.forwardRef((e,t)=>{const{__scopeToast:n,hotkey:r=GY,label:o="Notifications ({hotkey})",...s}=e,i=ag(VY,n),a=HY(n),c=x.useRef(null),l=x.useRef(null),u=x.useRef(null),d=x.useRef(null),p=Xe(t,d,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=i.toastCount>0;x.useEffect(()=>{const w=S=>{var v;r.every(E=>S[E]||S.code===E)&&((v=d.current)===null||v===void 0||v.focus())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[r]),x.useEffect(()=>{const w=c.current,S=d.current;if(y&&w&&S){const v=()=>{if(!i.isClosePausedRef.current){const I=new CustomEvent(vv);S.dispatchEvent(I),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const I=new CustomEvent(xv);S.dispatchEvent(I),i.isClosePausedRef.current=!1}},E=I=>{!w.contains(I.relatedTarget)&&b()},C=()=>{w.contains(document.activeElement)||b()};return w.addEventListener("focusin",v),w.addEventListener("focusout",E),w.addEventListener("pointermove",v),w.addEventListener("pointerleave",C),window.addEventListener("blur",v),window.addEventListener("focus",b),()=>{w.removeEventListener("focusin",v),w.removeEventListener("focusout",E),w.removeEventListener("pointermove",v),w.removeEventListener("pointerleave",C),window.removeEventListener("blur",v),window.removeEventListener("focus",b)}}},[y,i.isClosePausedRef]);const g=x.useCallback(({tabbingDirection:w})=>{const v=a().map(b=>{const E=b.ref.current,C=[E,...uX(E)];return w==="forwards"?C:C.reverse()});return(w==="forwards"?v.reverse():v).flat()},[a]);return x.useEffect(()=>{const w=d.current;if(w){const S=v=>{const b=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!b){const k=document.activeElement,$=v.shiftKey;if(v.target===w&&$){var C;(C=l.current)===null||C===void 0||C.focus();return}const N=g({tabbingDirection:$?"backwards":"forwards"}),F=N.findIndex(L=>L===k);if(ey(N.slice(F+1)))v.preventDefault();else{var I,_;$?(I=l.current)===null||I===void 0||I.focus():(_=u.current)===null||_===void 0||_.focus()}}};return w.addEventListener("keydown",S),()=>w.removeEventListener("keydown",S)}},[a,g]),x.createElement(NY,{ref:c,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:y?void 0:"none"}},y&&x.createElement(DC,{ref:l,onFocusFromOutsideViewport:()=>{const w=g({tabbingDirection:"forwards"});ey(w)}}),x.createElement(Wx.Slot,{scope:n},x.createElement(Ke.ol,X({tabIndex:-1},s,{ref:p}))),y&&x.createElement(DC,{ref:u,onFocusFromOutsideViewport:()=>{const w=g({tabbingDirection:"backwards"});ey(w)}}))}),XY="ToastFocusProxy",DC=x.forwardRef((e,t)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=e,s=ag(XY,n);return x.createElement(uM,X({"aria-hidden":!0,tabIndex:0},o,{ref:t,style:{position:"fixed"},onFocus:i=>{var a;const c=i.relatedTarget;!((a=s.viewport)!==null&&a!==void 0&&a.contains(c))&&r()}}))}),cg="Toast",qY="toast.swipeStart",ZY="toast.swipeMove",QY="toast.swipeCancel",JY="toast.swipeEnd",eX=x.forwardRef((e,t)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,c]=Zs({prop:r,defaultProp:o,onChange:s});return x.createElement(yo,{present:n||a},x.createElement(fM,X({open:a},i,{ref:t,onClose:()=>c(!1),onPause:sn(e.onPause),onResume:sn(e.onResume),onSwipeStart:ie(e.onSwipeStart,l=>{l.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ie(e.onSwipeMove,l=>{const{x:u,y:d}=l.detail.delta;l.currentTarget.setAttribute("data-swipe","move"),l.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),l.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${d}px`)}),onSwipeCancel:ie(e.onSwipeCancel,l=>{l.currentTarget.setAttribute("data-swipe","cancel"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),l.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:ie(e.onSwipeEnd,l=>{const{x:u,y:d}=l.detail.delta;l.currentTarget.setAttribute("data-swipe","end"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),l.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),l.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${d}px`),c(!1)})})))}),[tX,nX]=hM(cg,{onClose(){}}),fM=x.forwardRef((e,t)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:c,onResume:l,onSwipeStart:u,onSwipeMove:d,onSwipeCancel:p,onSwipeEnd:f,...y}=e,g=ag(cg,n),[w,S]=x.useState(null),v=Xe(t,L=>S(L)),b=x.useRef(null),E=x.useRef(null),C=o||g.duration,I=x.useRef(0),_=x.useRef(C),k=x.useRef(0),{onToastAdd:$,onToastRemove:T}=g,O=sn(()=>{var L;(w==null?void 0:w.contains(document.activeElement))&&((L=g.viewport)===null||L===void 0||L.focus()),i()}),N=x.useCallback(L=>{!L||L===1/0||(window.clearTimeout(k.current),I.current=new Date().getTime(),k.current=window.setTimeout(O,L))},[O]);x.useEffect(()=>{const L=g.viewport;if(L){const B=()=>{N(_.current),l==null||l()},q=()=>{const Q=new Date().getTime()-I.current;_.current=_.current-Q,window.clearTimeout(k.current),c==null||c()};return L.addEventListener(vv,q),L.addEventListener(xv,B),()=>{L.removeEventListener(vv,q),L.removeEventListener(xv,B)}}},[g.viewport,C,c,l,N]),x.useEffect(()=>{s&&!g.isClosePausedRef.current&&N(C)},[s,C,g.isClosePausedRef,N]),x.useEffect(()=>($(),()=>T()),[$,T]);const F=x.useMemo(()=>w?SM(w):null,[w]);return g.viewport?x.createElement(x.Fragment,null,F&&x.createElement(rX,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},F),x.createElement(tX,{scope:n,onClose:O},Ui.createPortal(x.createElement(Wx.ItemSlot,{scope:n},x.createElement(FY,{asChild:!0,onEscapeKeyDown:ie(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||O(),g.isFocusedToastEscapeKeyDownRef.current=!1})},x.createElement(Ke.li,X({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection},y,{ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:ie(e.onKeyDown,L=>{L.key==="Escape"&&(a==null||a(L.nativeEvent),L.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,O()))}),onPointerDown:ie(e.onPointerDown,L=>{L.button===0&&(b.current={x:L.clientX,y:L.clientY})}),onPointerMove:ie(e.onPointerMove,L=>{if(!b.current)return;const B=L.clientX-b.current.x,q=L.clientY-b.current.y,Q=!!E.current,H=["left","right"].includes(g.swipeDirection),U=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,W=H?U(0,B):0,Z=H?0:U(0,q),le=L.pointerType==="touch"?10:2,be={x:W,y:Z},Me={originalEvent:L,delta:be};Q?(E.current=be,Hd(ZY,d,Me,{discrete:!1})):RC(be,g.swipeDirection,le)?(E.current=be,Hd(qY,u,Me,{discrete:!1}),L.target.setPointerCapture(L.pointerId)):(Math.abs(B)>le||Math.abs(q)>le)&&(b.current=null)}),onPointerUp:ie(e.onPointerUp,L=>{const B=E.current,q=L.target;if(q.hasPointerCapture(L.pointerId)&&q.releasePointerCapture(L.pointerId),E.current=null,b.current=null,B){const Q=L.currentTarget,H={originalEvent:L,delta:B};RC(B,g.swipeDirection,g.swipeThreshold)?Hd(JY,f,H,{discrete:!0}):Hd(QY,p,H,{discrete:!0}),Q.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})))),g.viewport))):null});fM.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const t=`Invalid prop \`type\` supplied to \`${cg}\`. Expected \`foreground | background\`.`;return new Error(t)}return null}};const rX=e=>{const{__scopeToast:t,children:n,...r}=e,o=ag(cg,t),[s,i]=x.useState(!1),[a,c]=x.useState(!1);return cX(()=>i(!0)),x.useEffect(()=>{const l=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(l)},[]),a?null:x.createElement(ig,{asChild:!0},x.createElement(uM,r,s&&x.createElement(x.Fragment,null,o.label," ",n)))},oX=x.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return x.createElement(Ke.div,X({},r,{ref:t}))}),sX=x.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return x.createElement(Ke.div,X({},r,{ref:t}))}),iX="ToastAction",gM=x.forwardRef((e,t)=>{const{altText:n,...r}=e;return n?x.createElement(yM,{altText:n,asChild:!0},x.createElement(mM,X({},r,{ref:t}))):null});gM.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${iX}\``)}};const aX="ToastClose",mM=x.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e,o=nX(aX,n);return x.createElement(yM,{asChild:!0},x.createElement(Ke.button,X({type:"button"},r,{ref:t,onClick:ie(e.onClick,o.onClose)})))}),yM=x.forwardRef((e,t)=>{const{__scopeToast:n,altText:r,...o}=e;return x.createElement(Ke.div,X({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0},o,{ref:t}))});function SM(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),lX(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&t.push(i)}else t.push(...SM(r))}}),t}function Hd(e,t,n,{discrete:r}){const o=n.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Kx(o,s):o.dispatchEvent(s)}const RC=(e,t,n=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return t==="left"||t==="right"?s&&r>n:!s&&o>n};function cX(e=()=>{}){const t=sn(e);Di(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[t])}function lX(e){return e.nodeType===e.ELEMENT_NODE}function uX(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function ey(e){const t=document.activeElement;return e.some(n=>n===t?!0:(n.focus(),document.activeElement!==t))}const dX=eX,hX=oX,pX=sX,fX=gM,LC=mM,gX=eD.useId||(()=>{});let mX=0;function Fo(e){const[t,n]=x.useState(gX());return Di(()=>{e||n(r=>r??String(mX++))},[e]),e||(t?`radix-${t}`:"")}const ty="focusScope.autoFocusOnMount",ny="focusScope.autoFocusOnUnmount",FC={bubbles:!1,cancelable:!0},Vx=x.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=x.useState(null),l=sn(o),u=sn(s),d=x.useRef(null),p=Xe(t,g=>c(g)),f=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let v=function(I){if(f.paused||!a)return;const _=I.target;a.contains(_)?d.current=_:fs(d.current,{select:!0})},b=function(I){if(f.paused||!a)return;const _=I.relatedTarget;_!==null&&(a.contains(_)||fs(d.current,{select:!0}))},E=function(I){if(document.activeElement===document.body)for(const k of I)k.removedNodes.length>0&&fs(a)};var g=v,w=b,S=E;document.addEventListener("focusin",v),document.addEventListener("focusout",b);const C=new MutationObserver(E);return a&&C.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",b),C.disconnect()}}},[r,a,f.paused]),x.useEffect(()=>{if(a){zC.add(f);const g=document.activeElement;if(!a.contains(g)){const S=new CustomEvent(ty,FC);a.addEventListener(ty,l),a.dispatchEvent(S),S.defaultPrevented||(yX(bX(vM(a)),{select:!0}),document.activeElement===g&&fs(a))}return()=>{a.removeEventListener(ty,l),setTimeout(()=>{const S=new CustomEvent(ny,FC);a.addEventListener(ny,u),a.dispatchEvent(S),S.defaultPrevented||fs(g??document.body,{select:!0}),a.removeEventListener(ny,u),zC.remove(f)},0)}}},[a,l,u,f]);const y=x.useCallback(g=>{if(!n&&!r||f.paused)return;const w=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,S=document.activeElement;if(w&&S){const v=g.currentTarget,[b,E]=SX(v);b&&E?!g.shiftKey&&S===E?(g.preventDefault(),n&&fs(b,{select:!0})):g.shiftKey&&S===b&&(g.preventDefault(),n&&fs(E,{select:!0})):S===v&&g.preventDefault()}},[n,r,f.paused]);return x.createElement(Ke.div,X({tabIndex:-1},i,{ref:p,onKeyDown:y}))});function yX(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(fs(r,{select:t}),document.activeElement!==n)return}function SX(e){const t=vM(e),n=NC(t,e),r=NC(t.reverse(),e);return[n,r]}function vM(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function NC(e,t){for(const n of e)if(!vX(n,{upTo:t}))return n}function vX(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function xX(e){return e instanceof HTMLInputElement&&"select"in e}function fs(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&xX(e)&&t&&e.select()}}const zC=wX();function wX(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=BC(e,t),e.unshift(t)},remove(t){var n;e=BC(e,t),(n=e[0])===null||n===void 0||n.resume()}}}function BC(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function bX(e){return e.filter(t=>t.tagName!=="A")}let ry=0;function Gx(){x.useEffect(()=>{var e,t;const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",(e=n[0])!==null&&e!==void 0?e:UC()),document.body.insertAdjacentElement("beforeend",(t=n[1])!==null&&t!==void 0?t:UC()),ry++,()=>{ry===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),ry--}},[])}function UC(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",e}var Jr=function(){return Jr=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Jr.apply(this,arguments)};function xM(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function PX(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}var Jh="right-scroll-bar-position",ep="width-before-scroll-bar",CX="with-scroll-bars-hidden",IX="--removed-body-scroll-bar-size";function oy(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function EX(e,t){var n=x.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var _X=typeof window<"u"?x.useLayoutEffect:x.useEffect,HC=new WeakMap;function kX(e,t){var n=EX(null,function(r){return e.forEach(function(o){return oy(o,r)})});return _X(function(){var r=HC.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||oy(a,null)}),s.forEach(function(a){o.has(a)||oy(a,i)})}HC.set(n,e)},[e]),n}function TX(e){return e}function $X(e,t){t===void 0&&(t=TX);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var c=function(){var u=i;i=[],u.forEach(s)},l=function(){return Promise.resolve().then(c)};l(),n={push:function(u){i.push(u),l()},filter:function(u){return i=i.filter(u),n}}}};return o}function MX(e){e===void 0&&(e={});var t=$X(null);return t.options=Jr({async:!0,ssr:!1},e),t}var wM=function(e){var t=e.sideCar,n=xM(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return x.createElement(r,Jr({},n))};wM.isSideCarExport=!0;function AX(e,t){return e.useMedium(t),wM}var bM=MX(),sy=function(){},lg=x.forwardRef(function(e,t){var n=x.useRef(null),r=x.useState({onScrollCapture:sy,onWheelCapture:sy,onTouchMoveCapture:sy}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,p=e.sideCar,f=e.noIsolation,y=e.inert,g=e.allowPinchZoom,w=e.as,S=w===void 0?"div":w,v=xM(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),b=p,E=kX([n,t]),C=Jr(Jr({},v),o);return x.createElement(x.Fragment,null,u&&x.createElement(b,{sideCar:bM,removeScrollBar:l,shards:d,noIsolation:f,inert:y,setCallbacks:s,allowPinchZoom:!!g,lockRef:n}),i?x.cloneElement(x.Children.only(a),Jr(Jr({},C),{ref:E})):x.createElement(S,Jr({},C,{className:c,ref:E}),a))});lg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};lg.classNames={fullWidth:ep,zeroRight:Jh};var jX=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function OX(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=jX();return t&&e.setAttribute("nonce",t),e}function DX(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function RX(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var LX=function(){var e=0,t=null;return{add:function(n){e==0&&(t=OX())&&(DX(t,n),RX(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},FX=function(){var e=LX();return function(t,n){x.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},PM=function(){var e=FX(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},NX={left:0,top:0,right:0,gap:0},iy=function(e){return parseInt(e||"",10)||0},zX=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[iy(n),iy(r),iy(o)]},BX=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return NX;var t=zX(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},UX=PM(),Xa="data-scroll-locked",HX=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
.`.concat(CX,` {
overflow: hidden `).concat(r,`;
padding-right: `).concat(a,"px ").concat(r,`;
}
body[`).concat(Xa,`] {
overflow: hidden `).concat(r,`;
overscroll-behavior: contain;
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
padding-left: `.concat(o,`px;
padding-top: `).concat(s,`px;
padding-right: `).concat(i,`px;
margin-left:0;
margin-top:0;
margin-right: `).concat(a,"px ").concat(r,`;
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
}
.`).concat(Jh,` {
right: `).concat(a,"px ").concat(r,`;
}
.`).concat(ep,` {
margin-right: `).concat(a,"px ").concat(r,`;
}
.`).concat(Jh," .").concat(Jh,` {
right: 0 `).concat(r,`;
}
.`).concat(ep," .").concat(ep,` {
margin-right: 0 `).concat(r,`;
}
body[`).concat(Xa,`] {
`).concat(IX,": ").concat(a,`px;
}
`)},KC=function(){var e=parseInt(document.body.getAttribute(Xa)||"0",10);return isFinite(e)?e:0},KX=function(){x.useEffect(function(){return document.body.setAttribute(Xa,(KC()+1).toString()),function(){var e=KC()-1;e<=0?document.body.removeAttribute(Xa):document.body.setAttribute(Xa,e.toString())}},[])},WX=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;KX();var s=x.useMemo(function(){return BX(o)},[o]);return x.createElement(UX,{styles:HX(s,!t,o,n?"":"!important")})},wv=!1;if(typeof window<"u")try{var Kd=Object.defineProperty({},"passive",{get:function(){return wv=!0,!0}});window.addEventListener("test",Kd,Kd),window.removeEventListener("test",Kd,Kd)}catch{wv=!1}var la=wv?{passive:!1}:!1,VX=function(e){return e.tagName==="TEXTAREA"},CM=function(e,t){var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!VX(e)&&n[t]==="visible")},GX=function(e){return CM(e,"overflowY")},YX=function(e){return CM(e,"overflowX")},WC=function(e,t){var n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var r=IM(e,n);if(r){var o=EM(e,n),s=o[1],i=o[2];if(s>i)return!0}n=n.parentNode}while(n&&n!==document.body);return!1},XX=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},qX=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},IM=function(e,t){return e==="v"?GX(t):YX(t)},EM=function(e,t){return e==="v"?XX(t):qX(t)},ZX=function(e,t){return e==="h"&&t==="rtl"?-1:1},QX=function(e,t,n,r,o){var s=ZX(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,c=t.contains(a),l=!1,u=i>0,d=0,p=0;do{var f=EM(e,a),y=f[0],g=f[1],w=f[2],S=g-w-s*y;(y||S)&&IM(e,a)&&(d+=S,p+=y),a=a.parentNode}while(!c&&a!==document.body||c&&(t.contains(a)||t===a));return(u&&(d===0||!o)||!u&&(p===0||!o))&&(l=!0),l},Wd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},VC=function(e){return[e.deltaX,e.deltaY]},GC=function(e){return e&&"current"in e?e.current:e},JX=function(e,t){return e[0]===t[0]&&e[1]===t[1]},eq=function(e){return`
.block-interactivity-`.concat(e,` {pointer-events: none;}
.allow-interactivity-`).concat(e,` {pointer-events: all;}
`)},tq=0,ua=[];function nq(e){var t=x.useRef([]),n=x.useRef([0,0]),r=x.useRef(),o=x.useState(tq++)[0],s=x.useState(function(){return PM()})[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=PX([e.lockRef.current],(e.shards||[]).map(GC),!0).filter(Boolean);return g.forEach(function(w){return w.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(g,w){if("touches"in g&&g.touches.length===2)return!i.current.allowPinchZoom;var S=Wd(g),v=n.current,b="deltaX"in g?g.deltaX:v[0]-S[0],E="deltaY"in g?g.deltaY:v[1]-S[1],C,I=g.target,_=Math.abs(b)>Math.abs(E)?"h":"v";if("touches"in g&&_==="h"&&I.type==="range")return!1;var k=WC(_,I);if(!k)return!0;if(k?C=_:(C=_==="v"?"h":"v",k=WC(_,I)),!k)return!1;if(!r.current&&"changedTouches"in g&&(b||E)&&(r.current=C),!C)return!0;var $=r.current||C;return QX($,w,g,$==="h"?b:E,!0)},[]),c=x.useCallback(function(g){var w=g;if(!(!ua.length||ua[ua.length-1]!==s)){var S="deltaY"in w?VC(w):Wd(w),v=t.current.filter(function(C){return C.name===w.type&&C.target===w.target&&JX(C.delta,S)})[0];if(v&&v.should){w.cancelable&&w.preventDefault();return}if(!v){var b=(i.current.shards||[]).map(GC).filter(Boolean).filter(function(C){return C.contains(w.target)}),E=b.length>0?a(w,b[0]):!i.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),l=x.useCallback(function(g,w,S,v){var b={name:g,delta:w,target:S,should:v};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(E){return E!==b})},1)},[]),u=x.useCallback(function(g){n.current=Wd(g),r.current=void 0},[]),d=x.useCallback(function(g){l(g.type,VC(g),g.target,a(g,e.lockRef.current))},[]),p=x.useCallback(function(g){l(g.type,Wd(g),g.target,a(g,e.lockRef.current))},[]);x.useEffect(function(){return ua.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:p}),document.addEventListener("wheel",c,la),document.addEventListener("touchmove",c,la),document.addEventListener("touchstart",u,la),function(){ua=ua.filter(function(g){return g!==s}),document.removeEventListener("wheel",c,la),document.removeEventListener("touchmove",c,la),document.removeEventListener("touchstart",u,la)}},[]);var f=e.removeScrollBar,y=e.inert;return x.createElement(x.Fragment,null,y?x.createElement(s,{styles:eq(o)}):null,f?x.createElement(WX,{gapMode:"margin"}):null)}const rq=AX(bM,nq);var ug=x.forwardRef(function(e,t){return x.createElement(lg,Jr({},e,{ref:t,sideCar:rq}))});ug.classNames=lg.classNames;var oq=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},da=new WeakMap,Vd=new WeakMap,Gd={},ay=0,_M=function(e){return e&&(e.host||_M(e.parentNode))},sq=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=_M(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},iq=function(e,t,n,r){var o=sq(t,Array.isArray(e)?e:[e]);Gd[n]||(Gd[n]=new WeakMap);var s=Gd[n],i=[],a=new Set,c=new Set(o),l=function(d){!d||a.has(d)||(a.add(d),l(d.parentNode))};o.forEach(l);var u=function(d){!d||c.has(d)||Array.prototype.forEach.call(d.children,function(p){if(a.has(p))u(p);else try{var f=p.getAttribute(r),y=f!==null&&f!=="false",g=(da.get(p)||0)+1,w=(s.get(p)||0)+1;da.set(p,g),s.set(p,w),i.push(p),g===1&&y&&Vd.set(p,!0),w===1&&p.setAttribute(n,"true"),y||p.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",p,S)}})};return u(t),a.clear(),ay++,function(){i.forEach(function(d){var p=da.get(d)-1,f=s.get(d)-1;da.set(d,p),s.set(d,f),p||(Vd.has(d)||d.removeAttribute(r),Vd.delete(d)),f||d.removeAttribute(n)}),ay--,ay||(da=new WeakMap,da=new WeakMap,Vd=new WeakMap,Gd={})}},Yx=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=oq(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),iq(r,o,n,"aria-hidden")):function(){return null}};const kM="Dialog",[TM,Coe]=mo(kM),[aq,rs]=TM(kM),cq=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),c=x.useRef(null),[l=!1,u]=Zs({prop:r,defaultProp:o,onChange:s});return x.createElement(aq,{scope:t,triggerRef:a,contentRef:c,contentId:Fo(),titleId:Fo(),descriptionId:Fo(),open:l,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(d=>!d),[u]),modal:i},n)},$M="DialogPortal",[lq,MM]=TM($M,{forceMount:void 0}),uq=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=rs($M,t);return x.createElement(lq,{scope:t,forceMount:n},x.Children.map(r,i=>x.createElement(yo,{present:n||s.open},x.createElement(ig,{asChild:!0,container:o},i))))},bv="DialogOverlay",dq=x.forwardRef((e,t)=>{const n=MM(bv,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=rs(bv,e.__scopeDialog);return s.modal?x.createElement(yo,{present:r||s.open},x.createElement(hq,X({},o,{ref:t}))):null}),hq=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=rs(bv,n);return x.createElement(ug,{as:Oi,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(Ke.div,X({"data-state":jM(o.open)},r,{ref:t,style:{pointerEvents:"auto",...r.style}})))}),pu="DialogContent",pq=x.forwardRef((e,t)=>{const n=MM(pu,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=rs(pu,e.__scopeDialog);return x.createElement(yo,{present:r||s.open},s.modal?x.createElement(fq,X({},o,{ref:t})):x.createElement(gq,X({},o,{ref:t})))}),fq=x.forwardRef((e,t)=>{const n=rs(pu,e.__scopeDialog),r=x.useRef(null),o=Xe(t,n.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return Yx(s)},[]),x.createElement(AM,X({},e,{ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ie(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:ie(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault())}))}),gq=x.forwardRef((e,t)=>{const n=rs(pu,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(AM,X({},e,{ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=n.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=s.target;((a=n.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),AM=x.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=rs(pu,n),c=x.useRef(null),l=Xe(t,c);return Gx(),x.createElement(x.Fragment,null,x.createElement(Vx,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(sg,X({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":jM(a.open)},i,{ref:l,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),mq="DialogTitle",yq=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=rs(mq,n);return x.createElement(Ke.h2,X({id:o.titleId},r,{ref:t}))});const Sq="DialogClose",vq=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=rs(Sq,n);return x.createElement(Ke.button,X({type:"button"},r,{ref:t,onClick:ie(e.onClick,()=>o.onOpenChange(!1))}))});function jM(e){return e?"open":"closed"}const xq=cq,wq=uq,bq=dq,Pq=pq,OM=()=>{},DM=x.createContext({});function Cq({onEvent:e,children:t}){return h.jsx(DM.Provider,{value:e??OM,children:t})}function So(){return x.useContext(DM)??OM}const RM=x.createContext({});function Iq({children:e}){const t=z(),n=So(),[r,o]=x.useState([]),s=x.useCallback(l=>{const u=l.id??et();return o(d=>[...d.filter(p=>p.id!==l.id),{...l,id:u}]),n("open-menu",{source:"dialog",id:u}),t.addOpenMenu(u),u},[t,n]),i=x.useCallback((l,u)=>(o(d=>d.map(p=>p.id===l?{...p,...u}:p)),n("open-menu",{source:"dialog",id:l}),t.addOpenMenu(l),l),[t,n]),a=x.useCallback(l=>(o(u=>u.filter(d=>{var p;return d.id===l?((p=d.onClose)==null||p.call(d),!1):!0})),n("close-menu",{source:"dialog",id:l}),t.deleteOpenMenu(l),l),[t,n]),c=x.useCallback(()=>{o(l=>(l.forEach(u=>{var d;(d=u.onClose)==null||d.call(u),n("close-menu",{source:"dialog",id:u.id}),t.deleteOpenMenu(u.id)}),[]))},[t,n]);return h.jsx(RM.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:c,updateDialog:i},children:e})}function Yi(){const e=x.useContext(RM);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const Eq=({id:e,component:t,onClose:n})=>{const{removeDialog:r}=Yi(),o=cn(),s=x.useCallback(i=>{if(!i){if(n)try{n()}catch(a){console.warn(a)}r(e)}},[e,n,r]);return h.jsx(xq,{onOpenChange:s,defaultOpen:!0,children:h.jsx(wq,{container:o,children:h.jsx(bq,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:h.jsx(Pq,{dir:"ltr",className:"tlui-dialog__content",children:h.jsx(t,{onClose:()=>s(!1)})})})})})};function _q(){const{dialogs:e}=Yi();return h.jsx(h.Fragment,{children:e.map(t=>h.jsx(Eq,{...t},t.id))})}const kq=Se.memo(_q);function Tq(){const e=z(),t=K("follow",()=>e.getInstanceState().followingUserId,[e]);return t?h.jsx($q,{userId:t}):null}function $q({userId:e}){const t=p2(e);return t?h.jsx("div",{className:"tlui-following-indicator",style:{borderColor:t.color}}):null}const LM=x.createContext({});function Mq({children:e}){const[t,n]=x.useState([]),r=x.useCallback(i=>{const a=i.id??et();return n(c=>[...c.filter(l=>l.id!==i.id),{...i,id:a}]),a},[]),o=x.useCallback(i=>(n(a=>a.filter(c=>c.id!==i)),i),[]),s=x.useCallback(()=>{n(()=>[])},[]);return h.jsx(LM.Provider,{value:{toasts:t,addToast:r,removeToast:o,clearToasts:s},children:e})}function Kr(){const e=x.useContext(LM);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const pe=x.forwardRef(function({children:t,disabled:n,type:r,...o},s){const i=z(),a=s==null?void 0:s.current;return n&&a===document.activeElement&&i.getContainer().focus(),h.jsx("button",{ref:s,type:"button",draggable:!1,disabled:n,...o,className:ue("tlui-button",`tlui-button__${r}`,o.className),children:t})});function vt({children:e}){return h.jsx("span",{className:"tlui-button__label",children:e})}const Bs=x.memo(function({small:t,invertIcon:n,icon:r,color:o,className:s,...i}){const a=Bx(),c=a.icons[r]??a.icons["question-mark-circle"],l=x.useRef(null);return x.useLayoutEffect(()=>{c||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),l!=null&&l.current&&(l.current.style.webkitMask=`url(${c}) center 100% / 100% no-repeat`)},[l,c,r]),h.jsx("div",{...i,ref:l,className:ue("tlui-icon",{"tlui-icon__small":t},s),style:{color:o,mask:`url(${c}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})}),Aq={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function jq({toast:e}){const{removeToast:t}=Kr(),n=$e(),r=i=>{i||t(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&Aq[e.severity];return h.jsxs(dX,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&h.jsx("div",{className:"tlui-toast__icon",children:h.jsx(Bs,{icon:s})}),h.jsxs("div",{className:"tlui-toast__main",children:[h.jsxs("div",{className:"tlui-toast__content",children:[e.title&&h.jsx(hX,{className:"tlui-toast__title",children:e.title}),e.description&&h.jsx(pX,{className:"tlui-toast__description",children:e.description})]}),e.actions&&h.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>h.jsx(fX,{altText:i.label,asChild:!0,onClick:i.onClick,children:h.jsx(pe,{type:i.type,children:h.jsx(vt,{children:i.label})})},a)),h.jsx(LC,{asChild:!0,children:h.jsx(pe,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:h.jsx(vt,{children:e.closeLabel??n("toast.close")})})})]})]}),!o&&h.jsx(LC,{asChild:!0,children:h.jsx(pe,{type:"normal",className:"tlui-toast__close",children:h.jsx(vt,{children:e.closeLabel??n("toast.close")})})})]})}function Oq(){const{toasts:e}=Kr();return h.jsx(h.Fragment,{children:e.map(t=>h.jsx(jq,{toast:t},t.id))})}const Dq=x.memo(Oq);function Rq(){const{toasts:e}=Kr(),[t,n]=x.useState(!1);return x.useEffect(()=>{let r=!1;return e.length?n(!0):setTimeout(()=>{r||n(!1)},1e3),()=>{r=!0}},[e.length,n]),t?h.jsx(YY,{className:"tlui-toast__viewport"}):null}function ke({icon:e,small:t,invertIcon:n}){return h.jsx(Bs,{className:"tlui-button__icon",icon:e,small:t,invertIcon:n})}const cy=[0,390,428,468,580,640,840,1023];var mt=(e=>(e[e.ZERO=0]="ZERO",e[e.MOBILE_XXS=1]="MOBILE_XXS",e[e.MOBILE_XS=2]="MOBILE_XS",e[e.MOBILE_SM=3]="MOBILE_SM",e[e.MOBILE=4]="MOBILE",e[e.TABLET_SM=5]="TABLET_SM",e[e.TABLET=6]="TABLET",e[e.DESKTOP=7]="DESKTOP",e))(mt||{});const xi="2.1.4";let Pv={fonts:{draw:`https://unpkg.com/@tldraw/assets@${xi}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${xi}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${xi}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${xi}/fonts/IBMPlexMono-Medium.woff2`}};function FM(e){return x.useMemo(()=>e?{fonts:{...Pv.fonts,...e==null?void 0:e.fonts}}:Pv,[e])}const Lq=["align-bottom-center","align-bottom-left","align-bottom-right","align-bottom","align-center-center","align-center-horizontal","align-center-left","align-center-right","align-center-vertical","align-left","align-right","align-top-center","align-top-left","align-top-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","aspect-ratio","avatar","blob","bring-forward","bring-to-front","check-circle","check","checkbox-checked","checkbox-empty","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","collab","color","comment","cross-2","cross-circle","cross","dash-dashed","dash-dotted","dash-draw","dash-solid","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","error","external-link","file","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-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","hidden","image","info-circle","leading","link","lock-small","lock","menu","minus","mixed","pack","page","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","ruler","search","send-backward","send-to-back","settings-horizontal","settings-vertical-1","settings-vertical","share-1","share-2","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","status-online","stretch-horizontal","stretch-vertical","text-align-center","text-align-justify","text-align-left","text-align-right","tool-arrow","tool-embed","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-text","trash","triangle-down","triangle-up","twitter","undo","ungroup","unlock-small","unlock","vertical-align-center","vertical-align-end","vertical-align-start","visible","warning-triangle","zoom-in","zoom-out"];let rl={...Pv,icons:Object.fromEntries(Lq.map(e=>[e,`https://unpkg.com/@tldraw/assets@${xi}/icons/icon/${e}.svg`])),translations:Object.fromEntries(ou.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${xi}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Tu.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${xi}/embed-icons/${e.type}.png`]))};function Fq(e){return e?{fonts:Object.assign({...rl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...rl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...rl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...rl.translations},{...e==null?void 0:e.translations})}:rl}function dg({className:e,children:t}){return h.jsx("div",{className:ue("tlui-dialog__header",e),children:t})}function hg({className:e,children:t}){return h.jsx(yq,{dir:"ltr",className:ue("tlui-dialog__header__title",e),children:t})}function pg(){return h.jsx("div",{className:"tlui-dialog__header__close",children:h.jsx(vq,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:h.jsx(pe,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:h.jsx(ke,{small:!0,icon:"cross-2"})})})})}function fu({className:e,children:t,style:n}){return h.jsx("div",{className:ue("tlui-dialog__body",e),style:n,children:t})}function Xx({className:e,children:t}){return h.jsx("div",{className:ue("tlui-dialog__footer",e),children:t})}const qx=x.forwardRef(function({className:t,label:n,icon:r,iconLeft:o,autoselect:s=!1,autofocus:i=!1,defaultValue:a,placeholder:c,onComplete:l,onValueChange:u,onCancel:d,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:f=!1,children:y,value:g},w){const S=z(),v=x.useRef(null);x.useImperativeHandle(w,()=>v.current);const b=$e(),E=x.useRef(a??""),C=x.useRef(a??""),[I,_]=x.useState(!1),k=x.useCallback(N=>{_(!0);const F=N.currentTarget;C.current=F.value,requestAnimationFrame(()=>{s&&F.select()})},[s]),$=x.useCallback(N=>{const F=N.currentTarget.value;C.current=F,u==null||u(F)},[u]),T=x.useCallback(N=>{switch(N.key){case"Enter":{N.currentTarget.blur(),Ut(N),l==null||l(N.currentTarget.value);break}case"Escape":{N.currentTarget.value=E.current,N.currentTarget.blur(),Ut(N),d==null||d(N.currentTarget.value);break}}},[l,d]),O=x.useCallback(N=>{_(!1);const F=N.currentTarget.value;p==null||p(F)},[p]);return x.useEffect(()=>{if(!S.environment.isIos)return;const N=window.visualViewport;if(I&&f&&N){const F=()=>{var L;(L=v.current)==null||L.scrollIntoView({block:"center"})};return N.addEventListener("resize",F),N.addEventListener("scroll",F),requestAnimationFrame(()=>{var L;(L=v.current)==null||L.scrollIntoView({block:"center"})}),()=>{N.removeEventListener("resize",F),N.removeEventListener("scroll",F)}}},[S,I,f]),h.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,n&&h.jsx("label",{children:b(n)}),o&&h.jsx(Bs,{icon:o,className:"tlui-icon-left",small:!0}),h.jsx("input",{ref:v,className:ue("tlui-input",t),type:"text",defaultValue:a,onKeyUp:T,onChange:$,onFocus:k,onBlur:O,autoFocus:i,placeholder:c,value:g}),r&&h.jsx(Bs,{icon:r,small:!!n})]})}),NM=or(function({onClose:t}){const n=z(),r=$e(),o=Bx(),[s,i]=x.useState(null),[a,c]=x.useState(""),[l,u]=x.useState(null),[d,p]=x.useState(!1),f=x.useRef(-1);return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{children:[h.jsx(hg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),h.jsx(pg,{})]}),s?h.jsxs(h.Fragment,{children:[h.jsxs(fu,{className:"tlui-embed-dialog__enter",children:[h.jsx(qx,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autofocus:!0,onValueChange:y=>{c(y);const g=Cs(y);u(g&&g.definition.type===s.type?g:null),p(!1),clearTimeout(f.current),f.current=setTimeout(()=>p(!g),320)}}),a===""?h.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[h.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&h.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",h.jsx(Bs,{icon:"external-link",small:!0})]})]}):h.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),h.jsxs(Xx,{className:"tlui-dialog__footer__actions",children:[h.jsx(pe,{type:"normal",onClick:()=>{i(null),u(null),c("")},children:h.jsx(vt,{children:r("embed-dialog.back")})}),h.jsx("div",{className:"tlui-embed__spacer"}),h.jsx(pe,{type:"normal",onClick:t,children:h.jsx(vt,{children:r("embed-dialog.cancel")})}),h.jsx(pe,{type:"primary",disabled:!l,onClick:()=>{l&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageCenter(),embed:l.definition}),t())},children:h.jsx(vt,{children:r("embed-dialog.create")})})]})]}):h.jsx(h.Fragment,{children:h.jsx(fu,{className:"tlui-embed-dialog__list",children:Tu.map(y=>h.jsxs(pe,{type:"menu",onClick:()=>i(y),children:[h.jsx(vt,{children:y.title}),h.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})]},y.type))})})]})});function zM(){const e=z(),t=x.useRef();return x.useEffect(()=>{const n=window.document.createElement("input");n.type="file",n.accept="image/jpeg,image/png,image/gif,image/svg+xml,video/mp4,video/quicktime",n.multiple=!0,t.current=n;async function r(o){const s=o.target.files;!s||s.length===0||(await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),n.value="")}return n.addEventListener("change",r),()=>{t.current=void 0,n.removeEventListener("change",r)}},[e]),x.useCallback(()=>{var n;(n=t.current)==null||n.click()},[t])}const BM=x.createContext({});function Nq({overrides:e,children:t}){const n=z(),r=So(),{addDialog:o}=Yi(),s=zM(),i=x.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(l){n.setCurrentTool("select"),r("select-tool",{source:l,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(l){n.setCurrentTool("hand"),r("select-tool",{source:l,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(l){n.setCurrentTool("eraser"),r("select-tool",{source:l,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(l){n.setCurrentTool("draw"),r("select-tool",{source:l,id:"draw"})}},...[...oo.values].map(l=>({id:l,label:`tool.${l}`,meta:{geo:l},kbd:l==="rectangle"?"r":l==="ellipse"?"o":void 0,icon:"geo-"+l,onSelect(u){n.batch(()=>{n.updateInstanceState({stylesForNextShape:{...n.getInstanceState().stylesForNextShape,[oo.id]:l}},{ephemeral:!0}),n.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${l}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(l){n.setCurrentTool("arrow"),r("select-tool",{source:l,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(l){n.setCurrentTool("line"),r("select-tool",{source:l,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(l){n.setCurrentTool("frame"),r("select-tool",{source:l,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(l){n.setCurrentTool("text"),r("select-tool",{source:l,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(l){s(),r("select-tool",{source:l,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(l){n.setCurrentTool("note"),r("select-tool",{source:l,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(l){n.setCurrentTool("laser"),r("select-tool",{source:l,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"tool-embed",onSelect(l){o({component:NM}),r("select-tool",{source:l,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(l){n.setCurrentTool("highlight"),r("select-tool",{source:l,id:"highlight"})}}];a.push();const c=Object.fromEntries(a.map(l=>[l.id,l]));return e?e(n,c,{insertMedia:s}):c},[e,n,r,s,o]);return h.jsx(BM.Provider,{value:i,children:t})}function De(){const e=x.useContext(BM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const UM=Se.createContext(0);function zq({forceMobile:e=!1,children:t}){const n=z(),r=K("breakpoint",()=>{const{width:o}=n.getViewportScreenBounds(),s=e?mt.MOBILE_SM:cy.length-1;for(let i=0;i<s;i++)if(o>cy[i]&&o<=cy[i+1])return i;return s},[n]);return h.jsx(UM.Provider,{value:r,children:t})}function Rn(){return x.useContext(UM)}function Bq(){const{addToast:e,removeToast:t,clearToasts:n}=Kr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=Yi(),c=Rn()<mt.TABLET_SM,l=$e();return x.useMemo(()=>({addToast:e,removeToast:t,clearToasts:n,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:l,isMobile:c}),[r,e,o,n,l,s,t,i,c])}function Uq(e,t){const n={};for(const r of e)if(r.translations)for(const[o,s]of An(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,t));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...t,...s}));return o},translations:n}}function HM(e){return x.useMemo(()=>e,e)}function Hq(e){const t=HM(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const n={};for(const r of t)if(r.translations)for(const[o,s]of An(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return n},[t])}function Kq(e){const t=Bq(),n=HM(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>Uq(n,t),[n,t])}function Wq(e,t){const n=fe(t.map(o=>e.getShape(o)).filter(o=>o&&e.isShapeOfType(o,"frame")));if(!n.length)return;const r=[];e.batch(()=>{n.map(o=>{const s=e.getSortedChildIdsForParent(o.id);s.length&&(e.reparentShapes(s,o.parentId,o.index),r.push(...s))}),e.setSelectedShapes(r),e.deleteShapes(t)})}const Vq=50;function Gq(e,t,n={}){const r=e.getShape(t);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=fe(o.map(f=>e.getShape(f)));if(!s.length)return;const i=ne.FromPoints(s.flatMap(f=>{const y=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(y.vertices)})),{padding:a=Vq}=n,c=i.w+2*a,l=i.h+2*a,u=a-i.minX,d=a-i.minY;if(u===0&&d===0&&r.props.w===c&&r.props.h===l)return;const p=new P(u,d).rot(r.rotation);e.batch(()=>{const f=o.map(y=>{const g=e.getShape(y);return{id:g.id,type:g.type,x:g.x+u,y:g.y+d}});f.push({id:r.id,type:r.type,x:r.x-p.x,y:r.y-p.y,props:{w:c,h:l}}),e.updateShapes(f)})}function YC(e){return er.isValid(e)?{isValid:!0,hasProtocol:!0}:er.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Yq=or(function({onClose:t}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?h.jsx(Xq,{onClose:t,selectedShape:r}):null}),Xq=or(function({onClose:t,selectedShape:n}){const r=z(),o=$e(),s=x.useRef(null);x.useEffect(()=>{requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[]);const i=x.useRef(n.props.url),[a,c]=x.useState(()=>{const y=YC(n.props.url),g=y.isValid===!0?y.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:g,safe:g,valid:!0}}),l=x.useCallback(y=>{const g=y.replace(/https?:\/\/(https?:\/\/)/,(v,b)=>b),w=YC(g),S=w.isValid===!0?w.hasProtocol?g:"https://"+g:"https://";c({actual:g,safe:S,valid:w.isValid})},[]),u=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),t())},[r,t]),d=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),t())},[r,t,a]),p=x.useCallback(()=>{t()},[t]);if(!n)return t(),null;const f=i.current&&!a.valid;return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{children:[h.jsx(hg,{children:o("edit-link-dialog.title")}),h.jsx(pg,{})]}),h.jsx(fu,{children:h.jsxs("div",{className:"tlui-edit-link-dialog",children:[h.jsx(qx,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autofocus:!0,value:a.actual,onValueChange:l,onComplete:d,onCancel:p}),h.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),h.jsxs(Xx,{className:"tlui-dialog__footer__actions",children:[h.jsx(pe,{type:"normal",onClick:p,onTouchEnd:p,children:h.jsx(vt,{children:o("edit-link-dialog.cancel")})}),f?h.jsx(pe,{type:"danger",onTouchEnd:u,onClick:u,children:h.jsx(vt,{children:o("edit-link-dialog.clear")})}):h.jsx(pe,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:h.jsx(vt,{children:o("edit-link-dialog.save")})})]})]})});var Zx={exports:{}};Zx.exports;(function(e){var t=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(c,l){if(!s[c]){s[c]={};for(var u=0;u<c.length;u++)s[c][c.charAt(u)]=u}return s[c][l]}var a={compressToBase64:function(c){if(c==null)return"";var l=a._compress(c,6,function(u){return r.charAt(u)});switch(l.length%4){default:case 0:return l;case 1:return l+"===";case 2:return l+"==";case 3:return l+"="}},decompressFromBase64:function(c){return c==null?"":c==""?null:a._decompress(c.length,32,function(l){return i(r,c.charAt(l))})},compressToUTF16:function(c){return c==null?"":a._compress(c,15,function(l){return n(l+32)})+" "},decompressFromUTF16:function(c){return c==null?"":c==""?null:a._decompress(c.length,16384,function(l){return c.charCodeAt(l)-32})},compressToUint8Array:function(c){for(var l=a.compress(c),u=new Uint8Array(l.length*2),d=0,p=l.length;d<p;d++){var f=l.charCodeAt(d);u[d*2]=f>>>8,u[d*2+1]=f%256}return u},decompressFromUint8Array:function(c){if(c==null)return a.decompress(c);for(var l=new Array(c.length/2),u=0,d=l.length;u<d;u++)l[u]=c[u*2]*256+c[u*2+1];var p=[];return l.forEach(function(f){p.push(n(f))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(c){return c==null?"":a._compress(c,6,function(l){return o.charAt(l)})},decompressFromEncodedURIComponent:function(c){return c==null?"":c==""?null:(c=c.replace(/ /g,"+"),a._decompress(c.length,32,function(l){return i(o,c.charAt(l))}))},compress:function(c){return a._compress(c,16,function(l){return n(l)})},_compress:function(c,l,u){if(c==null)return"";var d,p,f={},y={},g="",w="",S="",v=2,b=3,E=2,C=[],I=0,_=0,k;for(k=0;k<c.length;k+=1)if(g=c.charAt(k),Object.prototype.hasOwnProperty.call(f,g)||(f[g]=b++,y[g]=!0),w=S+g,Object.prototype.hasOwnProperty.call(f,w))S=w;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<E;d++)I=I<<1,_==l-1?(_=0,C.push(u(I)),I=0):_++;for(p=S.charCodeAt(0),d=0;d<8;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1}else{for(p=1,d=0;d<E;d++)I=I<<1|p,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=0;for(p=S.charCodeAt(0),d=0;d<16;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete y[S]}else for(p=f[S],d=0;d<E;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++),f[w]=b++,S=String(g)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<E;d++)I=I<<1,_==l-1?(_=0,C.push(u(I)),I=0):_++;for(p=S.charCodeAt(0),d=0;d<8;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1}else{for(p=1,d=0;d<E;d++)I=I<<1|p,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=0;for(p=S.charCodeAt(0),d=0;d<16;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete y[S]}else for(p=f[S],d=0;d<E;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++)}for(p=2,d=0;d<E;d++)I=I<<1|p&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,p=p>>1;for(;;)if(I=I<<1,_==l-1){C.push(u(I));break}else _++;return C.join("")},decompress:function(c){return c==null?"":c==""?null:a._decompress(c.length,32768,function(l){return c.charCodeAt(l)})},_decompress:function(c,l,u){var d=[],p=4,f=4,y=3,g="",w=[],S,v,b,E,C,I,_,k={val:u(0),position:l,index:1};for(S=0;S<3;S+=1)d[S]=S;for(b=0,C=Math.pow(2,2),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),b|=(E>0?1:0)*I,I<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),b|=(E>0?1:0)*I,I<<=1;_=n(b);break;case 1:for(b=0,C=Math.pow(2,16),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),b|=(E>0?1:0)*I,I<<=1;_=n(b);break;case 2:return""}for(d[3]=_,v=_,w.push(_);;){if(k.index>c)return"";for(b=0,C=Math.pow(2,y),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),b|=(E>0?1:0)*I,I<<=1;switch(_=b){case 0:for(b=0,C=Math.pow(2,8),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),b|=(E>0?1:0)*I,I<<=1;d[f++]=n(b),_=f-1,p--;break;case 1:for(b=0,C=Math.pow(2,16),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),b|=(E>0?1:0)*I,I<<=1;d[f++]=n(b),_=f-1,p--;break;case 2:return w.join("")}if(p==0&&(p=Math.pow(2,y),y++),d[_])g=d[_];else if(_===f)g=v+v.charAt(0);else return null;w.push(g),d[f++]=v+g.charAt(0),p--,v=g,p==0&&(p=Math.pow(2,y),y++)}}};return a}();e!=null?e.exports=t:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return t})})(Zx);var KM=Zx.exports;async function qq(e,t,n){var S,v,b;const{elements:r,files:o}=t,s={shapes:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,c=e.getCurrentPageId(),l=new Map,u=[],d=new Set;r.forEach(E=>{if(l.set(E.id,Be()),E.boundElements!==null)for(const C of E.boundElements)C.type==="text"&&d.add(C.id)});let p=R3;for(const E of r){if(d.has(E.id))continue;const C=l.get(E.id),I={id:C,typeName:"shape",parentId:c,index:p,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:Zq(E.opacity),meta:{}};switch(E.angle!==0&&a.set(C,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(S=i.get(E.groupIds[0]))==null||S.push(C):i.set(E.groupIds[0],[C]):u.push(C),E.type){case"rectangle":case"ellipse":case"diamond":{let _="",k="middle";if(E.boundElements!==null){for(const T of E.boundElements)if(T.type==="text"){const O=r.find(N=>N.id===T.id);O&&(_=O.text,k=XC[O.textAlign])}}const $=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;s.shapes.push({...I,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:Yd[E.strokeWidth]??"draw",color:ol[$]??"black",text:_,align:k,dash:Xd(E),fill:oZ(E)}});break}case"freedraw":{s.shapes.push({...I,type:"draw",props:{dash:Xd(E),size:Yd[E.strokeWidth],color:ol[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([_,k,$=.5])=>({x:_,y:k,z:$}))}]}});break}case"line":{const _=E.points[0],k=E.points[E.points.length-1],$=eu(E.points.length);s.shapes.push({...I,type:"line",props:{dash:Xd(E),size:Yd[E.strokeWidth],color:ol[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",handles:{start:{id:"start",type:"vertex",index:$[0],x:_[0],y:_[1]},end:{id:"end",type:"vertex",index:$[$.length-1],x:k[0],y:k[1]},...Object.fromEntries(E.points.slice(1,-1).map(([T,O],N)=>{const F=et();return[F,{id:F,type:"vertex",index:$[N+1],x:T,y:O}]}))}}});break}case"arrow":{let _="";if(E.boundElements!==null){for(const N of E.boundElements)if(N.type==="text"){const F=r.find(L=>L.id===N.id);F&&(_=F.text)}}const k=E.points[0],$=E.points[E.points.length-1],T=l.get((v=E.startBinding)==null?void 0:v.elementId),O=l.get((b=E.endBinding)==null?void 0:b.elementId);s.shapes.push({...I,type:"arrow",props:{text:_,bend:rZ(E,k,$),dash:Xd(E),size:Yd[E.strokeWidth]??"m",color:ol[E.strokeColor]??"black",start:T?{type:"binding",boundShapeId:T,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:k[0],y:k[1]},end:O?{type:"binding",boundShapeId:O,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:$[0],y:$[1]},arrowheadEnd:qC[E.endArrowhead]??"none",arrowheadStart:qC[E.startArrowhead]??"none"}});break}case"text":{const{size:_,scale:k}=Jq(E.fontSize);s.shapes.push({...I,type:"text",props:{size:_,scale:k,font:eZ[E.fontFamily]??"draw",color:ol[E.strokeColor]??"black",text:E.text,align:XC[E.textAlign]}});break}case"image":{const _=o[E.fileId];if(!_)break;const k=Si.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:E.width,h:E.height,name:E.id??"Untitled",isAnimated:!1,mimeType:_.mimeType,src:_.dataURL},meta:{}}),s.shapes.push({...I,type:"image",props:{w:E.width,h:E.height,assetId:k}})}}p=$o(p)}const f=n??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:f,select:!1,preserveIds:!0});for(const E of i.values())if(E.length>1){e.groupShapes(E);const C=e.getShape(E[0]);C!=null&&C.parentId&&Kn(C.parentId)&&u.push(C.parentId)}for(const[E,C]of a)e.select(E),e.rotateShapesBy([E],C);const y=fe(u.map(E=>e.getShape(E))),g=ne.Common(y.map(E=>e.getShapePageBounds(E))),w=e.getViewportPageBounds().center;e.updateShapes(y.map(E=>{const C={x:(E.x??0)-(g.x+g.w/2),y:(E.y??0)-(g.y+g.h/2)};return{id:E.id,type:E.type,x:w.x+C.x,y:w.y+C.y}})),e.setSelectedShapes(u)}const Zq=e=>{const t=e/100;return t<.2?.1:t<.4?.25:t<.6?.5:t<.8?.75:1},Yd={1:"s",2:"m",3:"l",4:"xl"},Qq={16:"s",20:"m",28:"l",36:"xl"};function Jq(e){const t=Qq[e];return t?{size:t,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}const eZ={1:"draw",2:"sans",3:"mono"},ol={"#ffffff":"grey","#000000":"black","#343a40":"black","#495057":"grey","#c92a2a":"red","#a61e4d":"light-red","#862e9c":"violet","#5f3dc4":"light-violet","#364fc7":"blue","#1864ab":"light-blue","#0b7285":"light-green","#087f5b":"light-green","#2b8a3e":"green","#5c940d":"light-green","#e67700":"yellow","#d9480f":"orange","#ced4da":"grey","#868e96":"grey","#fa5252":"light-red","#e64980":"red","#be4bdb":"light-violet","#7950f2":"violet","#4c6ef5":"blue","#228be6":"light-blue","#15aabf":"light-green","#12b886":"green","#40c057":"green","#82c91e":"light-green","#fab005":"yellow","#fd7e14":"orange","#212529":"grey"},tZ={solid:"draw",dashed:"dashed",dotted:"dotted"},nZ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},XC={left:"start",center:"middle",right:"end"},qC={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function rZ(e,t,n){let r=0;if(e.points.length>2){const o=new P(t[0],t[1]),s=new P(n[0],n[1]),i=new P(e.points[1][0],e.points[1][1]),a=P.Sub(s,o),c=P.Per(a),l=P.Med(s,o),u=P.Sub(l,c),d=P.Add(l,c),p=P.NearestPointOnLineSegment(u,d,i,!1);r=P.Dist(p,l),P.Clockwise(p,s,l)&&(r*=-1)}return r}const Xd=e=>{let t=tZ[e.strokeStyle]??"draw";return t==="draw"&&e.roughness===0&&(t="solid"),t},oZ=e=>e.backgroundColor==="transparent"?"none":nZ[e.fillStyle]??"solid";async function WM(e,t,n,r){const s=(await Promise.all(t.map(async i=>await(await fetch(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r}),t.forEach(i=>URL.revokeObjectURL(i))}function sZ(e,t,n){const r=n??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(t,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0}),setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},150))}async function Cv(e,t,n,r){var o;try{if(new URL(t).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await fetch(t,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),WM(e,[t]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:n,url:t,sources:r})}function iZ(e){const t=document.implementation.createHTMLDocument("");return t.documentElement.innerHTML=e.trim(),t.body.textContent||t.body.innerText||""}const aZ=e=>{try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}},cZ=e=>{const t=e.split(/[\n\s]/);for(const n of t)try{const r=new URL(n);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return h2(t)},lZ=e=>/^<svg/.test(e),uZ=["input","select","textarea"];function tp(e){const{activeElement:t}=document;return e.getIsMenuOpen()||t&&(t.getAttribute("contenteditable")||uZ.indexOf(t.tagName.toLowerCase())>-1)}const dZ=e=>e.types.find(t=>t.match(/^image\//)),ly=(e,t,n,r)=>{const o=cZ(t);if(o)for(const s of o)Cv(e,s,n);else aZ(t)?Cv(e,t,n):lZ(t)?(e.mark("paste"),e.putExternalContent({type:"svg-text",text:t,point:n,sources:r})):(e.mark("paste"),e.putExternalContent({type:"text",text:t,point:n,sources:r}))},hZ=async(e,t,n)=>{if(e.getEditingShapeId()!==null)return;if(!t)throw Error("No clipboard data");const r=[];for(const o of Object.values(t.items))switch(o.kind){case"file":{r.push({type:"file",source:new Promise(s=>s(o.getAsFile()))});break}case"string":{o.type==="text/html"?r.push({type:"html",source:new Promise(s=>o.getAsString(s))}):o.type==="text/plain"?r.push({type:"text",source:new Promise(s=>o.getAsString(s))}):r.push({type:o.type,source:new Promise(s=>o.getAsString(s))});break}}GM(e,r,n)},VM=async(e,t,n)=>{const r=[];for(const o of t){if(dZ(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const s=await o.getType("text/html");return await Ka.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Ka.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Ka.blobToText(s)})()})}return await GM(e,r,n)};async function GM(e,t,n){const r=t.filter(s=>(s.type==="file"||s.type==="blob")&&s.source!==null);if(r.length){const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await WM(e,i,n)}const o=await Promise.all(t.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(c=>{var u;const l=(u=c.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:u[1];if(l)try{const d=KM.decompressFromBase64(l);if(d===null){i({type:"error",data:d,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(d);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:l,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:c,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:c,subtype:"url"});return}try{const d=JSON.parse(c);if(d.type==="excalidraw/clipboard"){i({type:"excalidraw",data:d});return}else{i({type:"text",data:c,subtype:"json"});return}}catch{i({type:"text",data:c,subtype:"text"});return}}i({type:"error",data:c,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){sZ(e,s.data,n);return}for(const s of o)if(s.type==="excalidraw"){qq(e,s.data,n);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(l=>l.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const l=a.firstElementChild.getAttribute("href");ly(e,l,n,o);return}if(!o.some(l=>l.type==="text"&&l.subtype!=="html")&&s.data.trim()){ly(e,iZ(s.data),n,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Cv(e,s.data,n,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){ly(e,s.data,n,o);return}}const lf=e=>{var r;const t=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!t){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=KM.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:t}));if(!(typeof navigator>"u")){const o=t.shapes.map(s=>e.isShapeOfType(s,"text")||e.isShapeOfType(s,"geo")||e.isShapeOfType(s,"arrow")?s.props.text:e.isShapeOfType(s,"bookmark")||e.isShapeOfType(s,"embed")?s.props.url:null).filter(W3);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<tldraw>${n}</tldraw>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${n}</tldraw>`)}};function pZ(){const e=z(),t=So(),n=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(lf(e),t("copy",{source:i}))},[e,t]),r=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(lf(e),e.deleteShapes(e.getSelectedShapeIds()),t("cut",{source:i}))},[e,t]),o=x.useCallback(async function(i,a,c){e.getEditingShapeId()!==null||tp(e)||(Array.isArray(i)&&i[0]instanceof ClipboardItem?(VM(e,i,c),t("paste",{source:"menu"})):navigator.clipboard.read().then(l=>{o(l,a,c)}))},[e,t]);return{copy:n,cut:r,paste:o}}function fZ(){const e=z(),t=So(),n=K("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!n)return;const r=c=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||tp(e)||(Ee(c),lf(e),t("copy",{source:"kbd"}))};function o(c){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||tp(e)||(Ee(c),lf(e),e.deleteShapes(e.getSelectedShapeIds()),t("cut",{source:"kbd"}))}let s=!1;const i=c=>{c.button===1&&(s=!0,requestAnimationFrame(()=>{s=!1}))},a=c=>{if(s){Ut(c);return}e.getEditingShapeId()!==null||tp(e)||(c.clipboardData&&!e.inputs.shiftKey?hZ(e,c.clipboardData):navigator.clipboard.read().then(l=>{Array.isArray(l)&&l[0]instanceof ClipboardItem&&VM(e,l,e.inputs.currentPagePoint)}),Ee(c),t("paste",{source:"kbd"}))};return document.addEventListener("copy",r),document.addEventListener("cut",o),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[e,t,n])}async function YM(e,t,n){const{type:r,quality:o,scale:s,width:i,height:a}=n;let[c,l]=await e$(i*s,a*s);c=Math.floor(c),l=Math.floor(l);const u=c/i,d=URL.createObjectURL(new Blob([e],{type:"image/svg+xml"})),p=await new Promise(y=>{const g=new Image;g.crossOrigin="anonymous",g.onload=async()=>{t&&await new Promise(v=>setTimeout(v,250));const w=document.createElement("canvas"),S=w.getContext("2d");w.width=c,w.height=l,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(g,0,0,c,l),URL.revokeObjectURL(d),y(w)},g.onerror=()=>{y(null)},g.src=d});if(!p)return null;const f=await new Promise(y=>p.toBlob(g=>{(!g||$t.throwToBlob.get())&&y(null),y(g)},"image/"+r,o));if(!f)return null;if(r==="png"){const y=new DataView(await f.arrayBuffer());return Zr.setPhysChunk(y,u,{type:"image/"+r})}else return f}async function XM(e,t,n){const r=await e.getSvgString(t!=null&&t.length?t:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function Iv(e,t,n,r={}){var o;switch(n){case"svg":return(o=await XM(e,t,r))==null?void 0:o.svg;case"json":{const s=e.getContentFromCurrentPage(t);return JSON.stringify(s)}default:qo(n)}}async function qM({editor:e,ids:t,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await Iv(e,t,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Iv(e,t,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await XM(e,t,r);if(!o)throw new Error("Could not construct image.");const s=await YM(o.svg,e.environment.isSafari,{type:n,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:qo(n)}}const gZ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function mZ(e,t,n,r={}){return{blobPromise:qM({editor:e,ids:t,format:n,opts:r}),mimeType:gZ[n]}}function yZ(e,t,n="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=mZ(e,t,n,r);return window.navigator.clipboard.write([new ClipboardItem({[s]:o})]).catch(i=>(console.error(i),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[s]:a})]))))}switch(n){case"json":case"svg":return SZ(async()=>Iv(e,t,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:qo(n)}}async function SZ(e){var t,n;await((n=(t=navigator.clipboard)==null?void 0:t.writeText)==null?void 0:n.call(t,await e()))}function vZ(){const e=z(),{addToast:t}=Kr(),n=$e();return x.useCallback((r,o="svg")=>{yZ(e,r,o).catch(()=>{t({id:"copy-fail",severity:"warning",title:n("toast.error.copy-fail.title"),description:n("toast.error.copy-fail.desc")})})},[e,t,n])}async function xZ(e,t,n="png",r,o={}){if(!r&&(r=`shapes at ${ZC()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${ZC()}`}r+=`.${n}`;const s=await qM({editor:e,ids:t,format:n,opts:o}),i=new File([s],r,{type:s.type});wZ(i)}function ZC(){const e=new Date,t=String(e.getFullYear()).slice(2),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return`${t}-${n}-${r} ${o}.${s}.${i}`}function wZ(e){const t=document.createElement("a"),n=URL.createObjectURL(e);t.href=n,t.download=e.name,t.click(),URL.revokeObjectURL(n)}function bZ(){const e=z(),{addToast:t}=Kr(),n=$e();return x.useCallback((r,o="png",s)=>{xZ(e,r,o,s,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),t({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[e,t,n])}function PZ(){const e=z(),t=x.useRef(null),n=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,v)=>{S&&(S.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),S&&document.body.contains(S)&&document.body.removeChild(S)};i(t.current,n.current),t.current=o,n.current=s;const a=`tl-print-surface-${et()}`;o.className=a,s.innerHTML=`
.${a} {
display: none;
}
.${a} svg {
max-width: 100%;
height: 100%;
display: block;
}
@media print {
html, body {
min-height: 100%;
height: 100%;
margin: 0;
}
body {
position: relative;
}
body > * {
display: none;
}
.tldraw__editor {
display: none;
}
.${a} {
display: block !important;
background: white;
min-height: 100%;
height: 100%;
max-width: 100%;
}
.${a}__item {
padding: 10mm;
display: flex;
min-height: 100%;
flex-direction: column;
page-break-after: always;
position: relative;
overflow: hidden;
height: 100%;
}
.${a}__item__main {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
max-height: 100%;
}
.${a}__item__header {
display: none;
}
.${a}__item__footer {
display: none;
text-align: right;
}
.${a}__item__footer__hide {
display: none;
}
}
`;const c=()=>{document.head.appendChild(s),document.body.appendChild(o)},l=()=>{e.once("change-history",()=>{i(o,s)})};window.addEventListener("beforeprint",c),window.addEventListener("afterprint",l);function u(S,v,b){try{o.innerHTML+=`<div class="${a}__item">
<div class="${a}__item__header">
${S.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
</div>
<div class="${a}__item__main">
${b}
</div>
<div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
${v??""}
</div>
</div>`}catch(E){console.error(E)}}function d(){e.environment.isChromeForIos?(c(),window.print()):e.environment.isSafari?(c(),document.execCommand("print",!1)):window.print()}const p=e.getSelectedShapeIds(),f=e.getCurrentPageId(),y=e.getPages(),w={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvgString(p,w);if(S){const v=y.find(b=>b.id===f);u(`tldraw — ${v==null?void 0:v.name}`,null,S.svg),d()}}else{const S=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(S.id),w);v&&(u(`tldraw — ${S.name}`,null,v.svg),d())}window.removeEventListener("beforeprint",c),window.removeEventListener("afterprint",l)},[e])}const ZM=x.createContext({});function CZ(e){return Object.fromEntries(e.map(t=>[t.id,t]))}function ha(e,t){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||t}function IZ({overrides:e,children:t}){const n=z(),{addDialog:r,clearDialogs:o}=Yi(),{clearToasts:s}=Kr(),i=$e(),a=zM(),c=PZ(),{cut:l,copy:u,paste:d}=pZ(),p=vZ(),f=bZ(),y=i("document.default-name"),g=So(),w=x.useMemo(()=>{function S(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function v(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const E=CZ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(C){v()&&(S()||(g("edit-link",{source:C}),n.mark("edit-link"),r({component:Yq})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(C){g("insert-embed",{source:C}),r({component:NM})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(C){g("insert-media",{source:C}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(C){g("undo",{source:C}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(C){g("redo",{source:C}),n.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("export-as",{format:"svg",source:C}),f(I,"svg",ha(n,y)))}},{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(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("export-as",{format:"png",source:C}),f(I,"png",ha(n,y)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("export-as",{format:"json",source:C}),f(I,"json",ha(n,y)))}},{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(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("export-all-as",{format:"svg",source:C}),f(Array.from(n.getCurrentPageShapeIds()),"svg",ha(n,y)))}},{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(C){const I=Array.from(n.getCurrentPageShapeIds().values());I.length!==0&&(g("export-all-as",{format:"png",source:C}),f(I,"png",ha(n,y)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(C){const I=Array.from(n.getCurrentPageShapeIds().values());I.length!==0&&(g("export-all-as",{format:"json",source:C}),f(I,"json",ha(n,y)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("copy-as",{format:"svg",source:C}),p(I,"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(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("copy-as",{format:"png",source:C}),p(I,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(C){let I=n.getSelectedShapeIds();I.length===0&&(I=Array.from(n.getCurrentPageShapeIds().values())),I.length!==0&&(g("copy-as",{format:"json",source:C}),p(I,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(C){if(!v()||S())return;g("toggle-auto-size",{source:C}),n.mark("toggling auto size");const I=n.getSelectedShapes().filter(_=>n.isShapeOfType(_,"text")&&_.props.autoSize===!1);n.updateShapes(I.map(_=>({id:_.id,type:_.type,props:{..._.props,w:8,autoSize:!0}}))),We(n,I.map(_=>_.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(C){g("open-embed-link",{source:C});const I=n.getSelectedShapeIds(),_="No embed shapes selected";if(I.length!==1){console.error(_);return}const k=n.getShape(I[0]);if(!k||!n.isShapeOfType(k,"embed")){console.error(_);return}_8(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(C){var I,_;if(((I=n.root.getCurrent())==null?void 0:I.id)!=="zoom"&&(g("zoom-tool",{source:C}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const k=n.root.getCurrent();k&&((_=k.getCurrent())==null?void 0:_.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(C){v()&&(S()||n.batch(()=>{g("convert-to-bookmark",{source:C});const I=n.getSelectedShapes(),_=[],k=[];for(const $ of I){if(!$||!n.isShapeOfType($,"embed")||!$.props.url)continue;const T=new P($.x,$.y);T.rot(-$.rotation),T.add(new P($.props.w/2-300/2,$.props.h/2-320/2)),T.rot($.rotation);const O={id:Be(),type:"bookmark",rotation:$.rotation,x:T.x,y:T.y,opacity:1,props:{url:$.props.url}};_.push(O),k.push($.id)}n.mark("convert shapes to bookmark"),n.deleteShapes(k),n.createShapes(_)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(C){v()&&(S()||(g("convert-to-embed",{source:C}),n.batch(()=>{const I=n.getSelectedShapeIds(),_=fe(I.map(T=>n.getShape(T))),k=[],$=[];for(const T of _){if(!n.isShapeOfType(T,"bookmark"))continue;const{url:O}=T.props,N=Cs(T.props.url);if(!N||!N.definition)continue;const{width:F,height:L}=N.definition,B=new P(T.x,T.y);B.rot(-T.rotation),B.add(new P(T.props.w/2-F/2,T.props.h/2-L/2)),B.rot(T.rotation);const q={id:Be(),type:"embed",x:B.x,y:B.y,rotation:T.rotation,props:{url:O,w:F,h:L}};k.push(q),$.push(T.id)}n.mark("convert shapes to embed"),n.deleteShapes($),n.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(C){if(!v()||S())return;g("duplicate-shapes",{source:C});const I=n.getInstanceState();let _,k;if(I.duplicateProps)_=I.duplicateProps.shapeIds,k=I.duplicateProps.offset;else{_=n.getSelectedShapeIds();const $=ne.Common(fe(_.map(T=>n.getShapePageBounds(T))));k=I.canMoveCamera?{x:$.width+20,y:0}:{x:20,y:20}}n.mark("duplicate shapes"),n.duplicateShapes(_,k),I.duplicateProps&&n.updateInstanceState({duplicateProps:{...I.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(C){v()&&(S()||(g("ungroup-shapes",{source:C}),n.mark("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(C){if(!v()||S())return;g("group-shapes",{source:C});const I=n.getOnlySelectedShape();I&&n.isShapeOfType(I,"group")?(n.mark("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())):(n.mark("group"),n.groupShapes(n.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(C){if(!v())return;g("remove-frame",{source:C});const I=n.getSelectedShapes();I.length>0&&I.every(_=>n.isShapeOfType(_,"frame"))&&(n.mark("remove-frame"),Wq(n,I.map(_=>_.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(C){if(!v())return;g("fit-frame-to-content",{source:C});const I=n.getOnlySelectedShape();I&&n.isShapeOfType(I,"frame")&&(n.mark("fit-frame-to-content"),Gq(n,I.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(C){if(!v()||S())return;g("align-shapes",{operation:"left",source:C}),n.mark("align left");const I=n.getSelectedShapeIds();n.alignShapes(I,"left"),We(n,I)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(C){if(!v()||S())return;g("align-shapes",{operation:"center-horizontal",source:C}),n.mark("align center horizontal");const I=n.getSelectedShapeIds();n.alignShapes(I,"center-horizontal"),We(n,I)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(C){if(!v()||S())return;g("align-shapes",{operation:"right",source:C}),n.mark("align right");const I=n.getSelectedShapeIds();n.alignShapes(I,"right"),We(n,I)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(C){if(!v()||S())return;g("align-shapes",{operation:"center-vertical",source:C}),n.mark("align center vertical");const I=n.getSelectedShapeIds();n.alignShapes(I,"center-vertical"),We(n,I)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(C){if(!v()||S())return;g("align-shapes",{operation:"top",source:C}),n.mark("align top");const I=n.getSelectedShapeIds();n.alignShapes(I,"top"),We(n,I)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(C){if(!v()||S())return;g("align-shapes",{operation:"bottom",source:C}),n.mark("align bottom");const I=n.getSelectedShapeIds();n.alignShapes(I,"bottom"),We(n,I)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(C){if(!v()||S())return;g("distribute-shapes",{operation:"horizontal",source:C}),n.mark("distribute horizontal");const I=n.getSelectedShapeIds();n.distributeShapes(I,"horizontal"),We(n,I)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(C){if(!v()||S())return;g("distribute-shapes",{operation:"vertical",source:C}),n.mark("distribute vertical");const I=n.getSelectedShapeIds();n.distributeShapes(I,"vertical"),We(n,I)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(C){if(!v()||S())return;g("stretch-shapes",{operation:"horizontal",source:C}),n.mark("stretch horizontal");const I=n.getSelectedShapeIds();n.stretchShapes(I,"horizontal"),We(n,I)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(C){if(!v()||S())return;g("stretch-shapes",{operation:"vertical",source:C}),n.mark("stretch vertical");const I=n.getSelectedShapeIds();n.stretchShapes(I,"vertical"),We(n,I)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(C){if(!v()||S())return;g("flip-shapes",{operation:"horizontal",source:C}),n.mark("flip horizontal");const I=n.getSelectedShapeIds();n.flipShapes(I,"horizontal"),We(n,I)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(C){if(!v()||S())return;g("flip-shapes",{operation:"vertical",source:C}),n.mark("flip vertical");const I=n.getSelectedShapeIds();n.flipShapes(I,"vertical"),We(n,I)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(C){if(!v()||S())return;g("pack-shapes",{source:C}),n.mark("pack");const I=n.getSelectedShapeIds();n.packShapes(I,16),We(n,I)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(C){if(!v()||S())return;g("stack-shapes",{operation:"vertical",source:C}),n.mark("stack-vertical");const I=n.getSelectedShapeIds();n.stackShapes(I,"vertical",16),We(n,I)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(C){if(!v()||S())return;g("stack-shapes",{operation:"horizontal",source:C}),n.mark("stack-horizontal");const I=n.getSelectedShapeIds();n.stackShapes(I,"horizontal",16),We(n,I)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(C){v()&&(S()||(g("reorder-shapes",{operation:"toFront",source:C}),n.mark("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(C){v()&&(S()||(g("reorder-shapes",{operation:"forward",source:C}),n.mark("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(C){v()&&(S()||(g("reorder-shapes",{operation:"backward",source:C}),n.mark("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(C){v()&&(S()||(g("reorder-shapes",{operation:"toBack",source:C}),n.mark("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(C){v()&&(S()||(n.mark("cut"),l(C)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(C){v()&&(S()||u(C))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(C){var I;(I=navigator.clipboard)==null||I.read().then(_=>{d(_,C,C==="context-menu"?n.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(C){n.batch(()=>{S()||(g("select-all-shapes",{source:C}),n.mark("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(C){v()&&(S()||(g("select-none-shapes",{source:C}),n.mark("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(C){v()&&(S()||(g("delete-shapes",{source:C}),n.mark("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(C){if(!v()||S())return;g("rotate-cw",{source:C}),n.mark("rotate-cw");const I=n.getSelectionRotation()%(ze/2),_=Ml(I,0)||Ml(I,ze/2),k=n.getSelectedShapeIds();n.rotateShapesBy(k,ze/2-(_?0:I)),We(n,k)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(C){if(!v()||S())return;g("rotate-ccw",{source:C}),n.mark("rotate-ccw");const I=n.getSelectionRotation()%(ze/2),_=Ml(I,0),k=n.getSelectedShapeIds();n.rotateShapesBy(k,_?-(ze/2):-I),We(n,k)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(C){g("zoom-in",{source:C}),n.zoomIn(n.getViewportScreenCenter(),{duration:Qr})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(C){g("zoom-out",{source:C}),n.zoomOut(n.getViewportScreenCenter(),{duration:Qr})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(C){g("reset-zoom",{source:C}),n.resetZoom(n.getViewportScreenCenter(),{duration:Qr})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(C){g("zoom-to-fit",{source:C}),n.zoomToFit({duration:Qr})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(C){v()&&(S()||(g("zoom-to-selection",{source:C}),n.zoomToSelection({duration:Qr})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(C){g("toggle-snap-mode",{source:C}),n.user.updateUserPreferences({isSnapMode:!n.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(C){g("toggle-dark-mode",{source:C}),n.user.updateUserPreferences({isDarkMode:!n.user.getIsDarkMode()})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(C){g("toggle-wrap-mode",{source:C}),n.user.updateUserPreferences({isWrapMode:!n.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(C){g("toggle-reduce-motion",{source:C}),n.user.updateUserPreferences({animationSpeed:n.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(C){g("toggle-edge-scrolling",{source:C}),n.user.updateUserPreferences({edgeScrollSpeed:n.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(C){g("toggle-transparent",{source:C}),n.updateInstanceState({exportBackground:!n.getInstanceState().exportBackground},{ephemeral:!0})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(C){g("toggle-tool-lock",{source:C}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(C){g("unlock-all",{source:C});const I=[];for(const _ of n.getCurrentPageShapes())_.isLocked&&I.push({id:_.id,type:_.type,isLocked:!1});I.length>0&&n.updateShapes(I)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(C){requestAnimationFrame(()=>{n.batch(()=>{g("toggle-focus-mode",{source:C}),o(),s(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(C){g("toggle-grid-mode",{source:C}),n.updateInstanceState({isGridMode:!n.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(C){g("toggle-debug-mode",{source:C}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(C){g("print",{source:C}),c()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(C){g("exit-pen-mode",{source:C}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(C){g("stop-following",{source:C}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(C){g("zoom-to-content",{source:C}),n.zoomToContent()}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(C){n.mark("locking"),g("toggle-lock",{source:C}),n.toggleLock(n.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(C){const I=Ho.createId(),_=n.getSelectedShapeIds();n.batch(()=>{n.mark("move_shapes_to_page"),n.createPage({name:i("page-menu.new-page-initial-name"),id:I}),n.moveShapesToPage(_,I)}),g("new-page",{source:C})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(C){const I=tr;n.batch(()=>{n.mark("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(I,"white",{squashing:!1}),n.setStyleForNextShapes(I,"white",{squashing:!1}),n.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),g("set-style",{source:C,id:I.id,value:"white"})}}]);return e?e(n,E,void 0):E},[n,g,e,r,a,f,p,l,u,d,o,s,c,i,y]);return h.jsx(ZM.Provider,{value:w,children:t})}function ce(){const e=x.useContext(ZM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function gu(e,t){return e?typeof e=="string"?e:t?e[t]??e.default:void 0:void 0}const EZ=["top","right","bottom","left"],eo=Math.min,Vn=Math.max,uf=Math.round,qd=Math.floor,Us=e=>({x:e,y:e}),_Z={left:"right",right:"left",bottom:"top",top:"bottom"},kZ={start:"end",end:"start"};function Ev(e,t,n){return Vn(e,eo(t,n))}function Go(e,t){return typeof e=="function"?e(t):e}function Yo(e){return e.split("-")[0]}function kc(e){return e.split("-")[1]}function Qx(e){return e==="x"?"y":"x"}function Jx(e){return e==="y"?"height":"width"}function Tc(e){return["top","bottom"].includes(Yo(e))?"y":"x"}function ew(e){return Qx(Tc(e))}function TZ(e,t,n){n===void 0&&(n=!1);const r=kc(e),o=ew(e),s=Jx(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=df(i)),[i,df(i)]}function $Z(e){const t=df(e);return[_v(e),t,_v(t)]}function _v(e){return e.replace(/start|end/g,t=>kZ[t])}function MZ(e,t,n){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(e){case"top":case"bottom":return n?t?o:r:t?r:o;case"left":case"right":return t?s:i;default:return[]}}function AZ(e,t,n,r){const o=kc(e);let s=MZ(Yo(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(_v)))),s}function df(e){return e.replace(/left|right|bottom|top/g,t=>_Z[t])}function jZ(e){return{top:0,right:0,bottom:0,left:0,...e}}function QM(e){return typeof e!="number"?jZ(e):{top:e,right:e,bottom:e,left:e}}function hf(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function QC(e,t,n){let{reference:r,floating:o}=e;const s=Tc(t),i=ew(t),a=Jx(i),c=Yo(t),l=s==="y",u=r.x+r.width/2-o.width/2,d=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let f;switch(c){case"top":f={x:u,y:r.y-o.height};break;case"bottom":f={x:u,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:d};break;case"left":f={x:r.x-o.width,y:d};break;default:f={x:r.x,y:r.y}}switch(kc(t)){case"start":f[i]-=p*(n&&l?-1:1);break;case"end":f[i]+=p*(n&&l?-1:1);break}return f}const OZ=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(t));let l=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:d}=QC(l,r,c),p=r,f={},y=0;for(let g=0;g<a.length;g++){const{name:w,fn:S}=a[g],{x:v,y:b,data:E,reset:C}=await S({x:u,y:d,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:l,platform:i,elements:{reference:e,floating:t}});u=v??u,d=b??d,f={...f,[w]:{...f[w],...E}},C&&y<=50&&(y++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(l=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:u,y:d}=QC(l,p,c)),g=-1)}return{x:u,y:d,placement:p,strategy:o,middlewareData:f}};async function mu(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:p=!1,padding:f=0}=Go(t,e),y=QM(f),w=a[p?d==="floating"?"reference":"floating":d],S=hf(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(w)))==null||n?w:w.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:l,rootBoundary:u,strategy:c})),v=d==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},C=hf(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:b,strategy:c}):v);return{top:(S.top-C.top+y.top)/E.y,bottom:(C.bottom-S.bottom+y.bottom)/E.y,left:(S.left-C.left+y.left)/E.x,right:(C.right-S.right+y.right)/E.x}}const DZ=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=t,{element:l,padding:u=0}=Go(e,t)||{};if(l==null)return{};const d=QM(u),p={x:n,y:r},f=ew(o),y=Jx(f),g=await i.getDimensions(l),w=f==="y",S=w?"top":"left",v=w?"bottom":"right",b=w?"clientHeight":"clientWidth",E=s.reference[y]+s.reference[f]-p[f]-s.floating[y],C=p[f]-s.reference[f],I=await(i.getOffsetParent==null?void 0:i.getOffsetParent(l));let _=I?I[b]:0;(!_||!await(i.isElement==null?void 0:i.isElement(I)))&&(_=a.floating[b]||s.floating[y]);const k=E/2-C/2,$=_/2-g[y]/2-1,T=eo(d[S],$),O=eo(d[v],$),N=T,F=_-g[y]-O,L=_/2-g[y]/2+k,B=Ev(N,L,F),q=!c.arrow&&kc(o)!=null&&L!==B&&s.reference[y]/2-(L<N?T:O)-g[y]/2<0,Q=q?L<N?L-N:L-F:0;return{[f]:p[f]+Q,data:{[f]:B,centerOffset:L-B-Q,...q&&{alignmentOffset:Q}},reset:q}}}),RZ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:c,elements:l}=t,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:g=!0,...w}=Go(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const S=Yo(o),v=Yo(a)===a,b=await(c.isRTL==null?void 0:c.isRTL(l.floating)),E=p||(v||!g?[df(a)]:$Z(a));!p&&y!=="none"&&E.push(...AZ(a,g,y,b));const C=[a,...E],I=await mu(t,w),_=[];let k=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&_.push(I[S]),d){const N=TZ(o,i,b);_.push(I[N[0]],I[N[1]])}if(k=[...k,{placement:o,overflows:_}],!_.every(N=>N<=0)){var $,T;const N=((($=s.flip)==null?void 0:$.index)||0)+1,F=C[N];if(F)return{data:{index:N,overflows:k},reset:{placement:F}};let L=(T=k.filter(B=>B.overflows[0]<=0).sort((B,q)=>B.overflows[1]-q.overflows[1])[0])==null?void 0:T.placement;if(!L)switch(f){case"bestFit":{var O;const B=(O=k.map(q=>[q.placement,q.overflows.filter(Q=>Q>0).reduce((Q,H)=>Q+H,0)]).sort((q,Q)=>q[1]-Q[1])[0])==null?void 0:O[0];B&&(L=B);break}case"initialPlacement":L=a;break}if(o!==L)return{reset:{placement:L}}}return{}}}};function JC(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function eI(e){return EZ.some(t=>e[t]>=0)}const LZ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Go(e,t);switch(r){case"referenceHidden":{const s=await mu(t,{...o,elementContext:"reference"}),i=JC(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:eI(i)}}}case"escaped":{const s=await mu(t,{...o,altBoundary:!0}),i=JC(s,n.floating);return{data:{escapedOffsets:i,escaped:eI(i)}}}default:return{}}}}};async function FZ(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Yo(n),a=kc(n),c=Tc(n)==="y",l=["left","top"].includes(i)?-1:1,u=s&&c?-1:1,d=Go(t,e);let{mainAxis:p,crossAxis:f,alignmentAxis:y}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...d};return a&&typeof y=="number"&&(f=a==="end"?y*-1:y),c?{x:f*u,y:p*l}:{x:p*l,y:f*u}}const NZ=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,c=await FZ(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},zZ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:w=>{let{x:S,y:v}=w;return{x:S,y:v}}},...c}=Go(e,t),l={x:n,y:r},u=await mu(t,c),d=Tc(Yo(o)),p=Qx(d);let f=l[p],y=l[d];if(s){const w=p==="y"?"top":"left",S=p==="y"?"bottom":"right",v=f+u[w],b=f-u[S];f=Ev(v,f,b)}if(i){const w=d==="y"?"top":"left",S=d==="y"?"bottom":"right",v=y+u[w],b=y-u[S];y=Ev(v,y,b)}const g=a.fn({...t,[p]:f,[d]:y});return{...g,data:{x:g.x-n,y:g.y-r}}}}},BZ=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:c=!0,crossAxis:l=!0}=Go(e,t),u={x:n,y:r},d=Tc(o),p=Qx(d);let f=u[p],y=u[d];const g=Go(a,t),w=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(c){const b=p==="y"?"height":"width",E=s.reference[p]-s.floating[b]+w.mainAxis,C=s.reference[p]+s.reference[b]-w.mainAxis;f<E?f=E:f>C&&(f=C)}if(l){var S,v;const b=p==="y"?"width":"height",E=["top","left"].includes(Yo(o)),C=s.reference[d]-s.floating[b]+(E&&((S=i.offset)==null?void 0:S[d])||0)+(E?0:w.crossAxis),I=s.reference[d]+s.reference[b]+(E?0:((v=i.offset)==null?void 0:v[d])||0)-(E?w.crossAxis:0);y<C?y=C:y>I&&(y=I)}return{[p]:f,[d]:y}}}},UZ=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:o,elements:s}=t,{apply:i=()=>{},...a}=Go(e,t),c=await mu(t,a),l=Yo(n),u=kc(n),d=Tc(n)==="y",{width:p,height:f}=r.floating;let y,g;l==="top"||l==="bottom"?(y=l,g=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(g=l,y=u==="end"?"top":"bottom");const w=f-c.top-c.bottom,S=p-c.left-c.right,v=eo(f-c[y],w),b=eo(p-c[g],S),E=!t.middlewareData.shift;let C=v,I=b;if(d?I=u||E?eo(b,S):S:C=u||E?eo(v,w):w,E&&!u){const k=Vn(c.left,0),$=Vn(c.right,0),T=Vn(c.top,0),O=Vn(c.bottom,0);d?I=p-2*(k!==0||$!==0?k+$:Vn(c.left,c.right)):C=f-2*(T!==0||O!==0?T+O:Vn(c.top,c.bottom))}await i({...t,availableWidth:I,availableHeight:C});const _=await o.getDimensions(s.floating);return p!==_.width||f!==_.height?{reset:{rects:!0}}:{}}}};function $c(e){return JM(e)?(e.nodeName||"").toLowerCase():"#document"}function Qn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function os(e){var t;return(t=(JM(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function JM(e){return e instanceof Node||e instanceof Qn(e).Node}function uo(e){return e instanceof Element||e instanceof Qn(e).Element}function ho(e){return e instanceof HTMLElement||e instanceof Qn(e).HTMLElement}function tI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Qn(e).ShadowRoot}function Uu(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Ur(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!["inline","contents"].includes(o)}function HZ(e){return["table","td","th"].includes($c(e))}function tw(e){const t=nw(),n=Ur(e);return n.transform!=="none"||n.perspective!=="none"||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function KZ(e){let t=Hs(e);for(;ho(t)&&!hc(t);){if(tw(t))return t;t=Hs(t)}return null}function nw(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function hc(e){return["html","body","#document"].includes($c(e))}function Ur(e){return Qn(e).getComputedStyle(e)}function fg(e){return uo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Hs(e){if($c(e)==="html")return e;const t=e.assignedSlot||e.parentNode||tI(e)&&e.host||os(e);return tI(t)?t.host:t}function eA(e){const t=Hs(e);return hc(t)?e.ownerDocument?e.ownerDocument.body:e.body:ho(t)&&Uu(t)?t:eA(t)}function yu(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=eA(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Qn(o);return s?t.concat(i,i.visualViewport||[],Uu(o)?o:[],i.frameElement&&n?yu(i.frameElement):[]):t.concat(o,yu(o,[],n))}function tA(e){const t=Ur(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=ho(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=uf(n)!==s||uf(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function rw(e){return uo(e)?e:e.contextElement}function qa(e){const t=rw(e);if(!ho(t))return Us(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=tA(t);let i=(s?uf(n.width):n.width)/r,a=(s?uf(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const WZ=Us(0);function nA(e){const t=Qn(e);return!nw()||!t.visualViewport?WZ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function VZ(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Qn(e)?!1:t}function Ri(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=rw(e);let i=Us(1);t&&(r?uo(r)&&(i=qa(r)):i=qa(e));const a=VZ(s,n,r)?nA(s):Us(0);let c=(o.left+a.x)/i.x,l=(o.top+a.y)/i.y,u=o.width/i.x,d=o.height/i.y;if(s){const p=Qn(s),f=r&&uo(r)?Qn(r):r;let y=p,g=y.frameElement;for(;g&&r&&f!==y;){const w=qa(g),S=g.getBoundingClientRect(),v=Ur(g),b=S.left+(g.clientLeft+parseFloat(v.paddingLeft))*w.x,E=S.top+(g.clientTop+parseFloat(v.paddingTop))*w.y;c*=w.x,l*=w.y,u*=w.x,d*=w.y,c+=b,l+=E,y=Qn(g),g=y.frameElement}}return hf({width:u,height:d,x:c,y:l})}const GZ=[":popover-open",":modal"];function ow(e){return GZ.some(t=>{try{return e.matches(t)}catch{return!1}})}function YZ(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=os(r),a=t?ow(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},l=Us(1);const u=Us(0),d=ho(r);if((d||!d&&!s)&&(($c(r)!=="body"||Uu(i))&&(c=fg(r)),ho(r))){const p=Ri(r);l=qa(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x,y:n.y*l.y-c.scrollTop*l.y+u.y}}function XZ(e){return Array.from(e.getClientRects())}function rA(e){return Ri(os(e)).left+fg(e).scrollLeft}function qZ(e){const t=os(e),n=fg(e),r=e.ownerDocument.body,o=Vn(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Vn(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+rA(e);const a=-n.scrollTop;return Ur(r).direction==="rtl"&&(i+=Vn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function ZZ(e,t){const n=Qn(e),r=os(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const l=nw();(!l||l&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}function QZ(e,t){const n=Ri(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=ho(e)?qa(e):Us(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,l=r*s.y;return{width:i,height:a,x:c,y:l}}function nI(e,t,n){let r;if(t==="viewport")r=ZZ(e,n);else if(t==="document")r=qZ(os(e));else if(uo(t))r=QZ(t,n);else{const o=nA(e);r={...t,x:t.x-o.x,y:t.y-o.y}}return hf(r)}function oA(e,t){const n=Hs(e);return n===t||!uo(n)||hc(n)?!1:Ur(n).position==="fixed"||oA(n,t)}function JZ(e,t){const n=t.get(e);if(n)return n;let r=yu(e,[],!1).filter(a=>uo(a)&&$c(a)!=="body"),o=null;const s=Ur(e).position==="fixed";let i=s?Hs(e):e;for(;uo(i)&&!hc(i);){const a=Ur(i),c=tw(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Uu(i)&&!c&&oA(e,i))?r=r.filter(u=>u!==i):o=a,i=Hs(i)}return t.set(e,r),r}function eQ(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?ow(t)?[]:JZ(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((l,u)=>{const d=nI(t,u,o);return l.top=Vn(d.top,l.top),l.right=eo(d.right,l.right),l.bottom=eo(d.bottom,l.bottom),l.left=Vn(d.left,l.left),l},nI(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function tQ(e){const{width:t,height:n}=tA(e);return{width:t,height:n}}function nQ(e,t,n){const r=ho(t),o=os(t),s=n==="fixed",i=Ri(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=Us(0);if(r||!r&&!s)if(($c(t)!=="body"||Uu(o))&&(a=fg(t)),r){const d=Ri(t,!0,s,t);c.x=d.x+t.clientLeft,c.y=d.y+t.clientTop}else o&&(c.x=rA(o));const l=i.left+a.scrollLeft-c.x,u=i.top+a.scrollTop-c.y;return{x:l,y:u,width:i.width,height:i.height}}function uy(e){return Ur(e).position==="static"}function rI(e,t){return!ho(e)||Ur(e).position==="fixed"?null:t?t(e):e.offsetParent}function sA(e,t){const n=Qn(e);if(ow(e))return n;if(!ho(e)){let o=Hs(e);for(;o&&!hc(o);){if(uo(o)&&!uy(o))return o;o=Hs(o)}return n}let r=rI(e,t);for(;r&&HZ(r)&&uy(r);)r=rI(r,t);return r&&hc(r)&&uy(r)&&!tw(r)?n:r||KZ(e)||n}const rQ=async function(e){const t=this.getOffsetParent||sA,n=this.getDimensions,r=await n(e.floating);return{reference:nQ(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function oQ(e){return Ur(e).direction==="rtl"}const sQ={convertOffsetParentRelativeRectToViewportRelativeRect:YZ,getDocumentElement:os,getClippingRect:eQ,getOffsetParent:sA,getElementRects:rQ,getClientRects:XZ,getDimensions:tQ,getScale:qa,isElement:uo,isRTL:oQ};function iQ(e,t){let n=null,r;const o=os(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const{left:l,top:u,width:d,height:p}=e.getBoundingClientRect();if(a||t(),!d||!p)return;const f=qd(u),y=qd(o.clientWidth-(l+d)),g=qd(o.clientHeight-(u+p)),w=qd(l),v={rootMargin:-f+"px "+-y+"px "+-g+"px "+-w+"px",threshold:Vn(0,eo(1,c))||1};let b=!0;function E(C){const I=C[0].intersectionRatio;if(I!==c){if(!b)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}b=!1}try{n=new IntersectionObserver(E,{...v,root:o.ownerDocument})}catch{n=new IntersectionObserver(E,v)}n.observe(e)}return i(!0),s}function aQ(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,l=rw(e),u=o||s?[...l?yu(l):[],...yu(t)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",n,{passive:!0}),s&&S.addEventListener("resize",n)});const d=l&&a?iQ(l,n):null;let p=-1,f=null;i&&(f=new ResizeObserver(S=>{let[v]=S;v&&v.target===l&&f&&(f.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=f)==null||b.observe(t)})),n()}),l&&!c&&f.observe(l),f.observe(t));let y,g=c?Ri(e):null;c&&w();function w(){const S=Ri(e);g&&(S.x!==g.x||S.y!==g.y||S.width!==g.width||S.height!==g.height)&&n(),g=S,y=requestAnimationFrame(w)}return n(),()=>{var S;u.forEach(v=>{o&&v.removeEventListener("scroll",n),s&&v.removeEventListener("resize",n)}),d==null||d(),(S=f)==null||S.disconnect(),f=null,c&&cancelAnimationFrame(y)}}const cQ=NZ,lQ=zZ,uQ=RZ,dQ=UZ,hQ=LZ,oI=DZ,pQ=BZ,fQ=(e,t,n)=>{const r=new Map,o={platform:sQ,...n},s={...o.platform,_c:r};return OZ(e,t,{...o,platform:s})};var np=typeof document<"u"?x.useLayoutEffect:x.useEffect;function pf(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!pf(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!pf(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function iA(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function sI(e,t){const n=iA(e);return Math.round(t*n)/n}function iI(e){const t=x.useRef(e);return np(()=>{t.current=e}),t}function gQ(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:c,open:l}=e,[u,d]=x.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,f]=x.useState(r);pf(p,r)||f(r);const[y,g]=x.useState(null),[w,S]=x.useState(null),v=x.useCallback(Q=>{Q!==I.current&&(I.current=Q,g(Q))},[]),b=x.useCallback(Q=>{Q!==_.current&&(_.current=Q,S(Q))},[]),E=s||y,C=i||w,I=x.useRef(null),_=x.useRef(null),k=x.useRef(u),$=c!=null,T=iI(c),O=iI(o),N=x.useCallback(()=>{if(!I.current||!_.current)return;const Q={placement:t,strategy:n,middleware:p};O.current&&(Q.platform=O.current),fQ(I.current,_.current,Q).then(H=>{const U={...H,isPositioned:!0};F.current&&!pf(k.current,U)&&(k.current=U,Ui.flushSync(()=>{d(U)}))})},[p,t,n,O]);np(()=>{l===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,d(Q=>({...Q,isPositioned:!1})))},[l]);const F=x.useRef(!1);np(()=>(F.current=!0,()=>{F.current=!1}),[]),np(()=>{if(E&&(I.current=E),C&&(_.current=C),E&&C){if(T.current)return T.current(E,C,N);N()}},[E,C,N,T,$]);const L=x.useMemo(()=>({reference:I,floating:_,setReference:v,setFloating:b}),[v,b]),B=x.useMemo(()=>({reference:E,floating:C}),[E,C]),q=x.useMemo(()=>{const Q={position:n,left:0,top:0};if(!B.floating)return Q;const H=sI(B.floating,u.x),U=sI(B.floating,u.y);return a?{...Q,transform:"translate("+H+"px, "+U+"px)",...iA(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:U}},[n,a,B.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:N,refs:L,elements:B,floatingStyles:q}),[u,N,L,B,q])}const mQ=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?oI({element:r.current,padding:o}).fn(n):{}:r?oI({element:r,padding:o}).fn(n):{}}}},yQ=(e,t)=>({...cQ(e),options:[e,t]}),SQ=(e,t)=>({...lQ(e),options:[e,t]}),vQ=(e,t)=>({...pQ(e),options:[e,t]}),xQ=(e,t)=>({...uQ(e),options:[e,t]}),wQ=(e,t)=>({...dQ(e),options:[e,t]}),bQ=(e,t)=>({...hQ(e),options:[e,t]}),PQ=(e,t)=>({...mQ(e),options:[e,t]});function aA(e){const[t,n]=x.useState(void 0);return Di(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const c=s.borderBoxSize,l=Array.isArray(c)?c[0]:c;i=l.inlineSize,a=l.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const cA="Popper",[lA,gg]=mo(cA),[CQ,uA]=lA(cA),IQ=e=>{const{__scopePopper:t,children:n}=e,[r,o]=x.useState(null);return x.createElement(CQ,{scope:t,anchor:r,onAnchorChange:o},n)},EQ="PopperAnchor",_Q=x.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=uA(EQ,n),i=x.useRef(null),a=Xe(t,i);return x.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:x.createElement(Ke.div,X({},o,{ref:a}))}),dA="PopperContent",[kQ,Ioe]=lA(dA),TQ=x.forwardRef((e,t)=>{var n,r,o,s,i,a,c,l;const{__scopePopper:u,side:d="bottom",sideOffset:p=0,align:f="center",alignOffset:y=0,arrowPadding:g=0,avoidCollisions:w=!0,collisionBoundary:S=[],collisionPadding:v=0,sticky:b="partial",hideWhenDetached:E=!1,updatePositionStrategy:C="optimized",onPlaced:I,..._}=e,k=uA(dA,u),[$,T]=x.useState(null),O=Xe(t,qe=>T(qe)),[N,F]=x.useState(null),L=aA(N),B=(n=L==null?void 0:L.width)!==null&&n!==void 0?n:0,q=(r=L==null?void 0:L.height)!==null&&r!==void 0?r:0,Q=d+(f!=="center"?"-"+f:""),H=typeof v=="number"?v:{top:0,right:0,bottom:0,left:0,...v},U=Array.isArray(S)?S:[S],W=U.length>0,Z={padding:H,boundary:U.filter($Q),altBoundary:W},{refs:le,floatingStyles:be,placement:Me,isPositioned:ae,middlewareData:Ae}=gQ({strategy:"fixed",placement:Q,whileElementsMounted:(...qe)=>aQ(...qe,{animationFrame:C==="always"}),elements:{reference:k.anchor},middleware:[yQ({mainAxis:p+q,alignmentAxis:y}),w&&SQ({mainAxis:!0,crossAxis:!1,limiter:b==="partial"?vQ():void 0,...Z}),w&&xQ({...Z}),wQ({...Z,apply:({elements:qe,rects:Ot,availableWidth:wo,availableHeight:Ac})=>{const{width:jc,height:bg}=Ot.reference,qi=qe.floating.style;qi.setProperty("--radix-popper-available-width",`${wo}px`),qi.setProperty("--radix-popper-available-height",`${Ac}px`),qi.setProperty("--radix-popper-anchor-width",`${jc}px`),qi.setProperty("--radix-popper-anchor-height",`${bg}px`)}}),N&&PQ({element:N,padding:g}),MQ({arrowWidth:B,arrowHeight:q}),E&&bQ({strategy:"referenceHidden",...Z})]}),[Re,ot]=hA(Me),Ie=sn(I);Di(()=>{ae&&(Ie==null||Ie())},[ae,Ie]);const ht=(o=Ae.arrow)===null||o===void 0?void 0:o.x,He=(s=Ae.arrow)===null||s===void 0?void 0:s.y,ir=((i=Ae.arrow)===null||i===void 0?void 0:i.centerOffset)!==0,[Ln,Fn]=x.useState();return Di(()=>{$&&Fn(window.getComputedStyle($).zIndex)},[$]),x.createElement("div",{ref:le.setFloating,"data-radix-popper-content-wrapper":"",style:{...be,transform:ae?be.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ln,"--radix-popper-transform-origin":[(a=Ae.transformOrigin)===null||a===void 0?void 0:a.x,(c=Ae.transformOrigin)===null||c===void 0?void 0:c.y].join(" ")},dir:e.dir},x.createElement(kQ,{scope:u,placedSide:Re,onArrowChange:F,arrowX:ht,arrowY:He,shouldHideArrow:ir},x.createElement(Ke.div,X({"data-side":Re,"data-align":ot},_,{ref:O,style:{..._.style,animation:ae?void 0:"none",opacity:(l=Ae.hide)!==null&&l!==void 0&&l.referenceHidden?0:void 0}}))))});function $Q(e){return e!==null}const MQ=e=>({name:"transformOrigin",options:e,fn(t){var n,r,o,s,i;const{placement:a,rects:c,middlewareData:l}=t,d=((n=l.arrow)===null||n===void 0?void 0:n.centerOffset)!==0,p=d?0:e.arrowWidth,f=d?0:e.arrowHeight,[y,g]=hA(a),w={start:"0%",center:"50%",end:"100%"}[g],S=((r=(o=l.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+p/2,v=((s=(i=l.arrow)===null||i===void 0?void 0:i.y)!==null&&s!==void 0?s:0)+f/2;let b="",E="";return y==="bottom"?(b=d?w:`${S}px`,E=`${-f}px`):y==="top"?(b=d?w:`${S}px`,E=`${c.floating.height+f}px`):y==="right"?(b=`${-f}px`,E=d?w:`${v}px`):y==="left"&&(b=`${c.floating.width+f}px`,E=d?w:`${v}px`),{data:{x:b,y:E}}}});function hA(e){const[t,n="center"]=e.split("-");return[t,n]}const sw=IQ,pA=_Q,fA=TQ,gA="Popover",[mA,Eoe]=mo(gA,[gg]),iw=gg(),[AQ,Mc]=mA(gA),jQ=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=iw(t),c=x.useRef(null),[l,u]=x.useState(!1),[d=!1,p]=Zs({prop:r,defaultProp:o,onChange:s});return x.createElement(sw,a,x.createElement(AQ,{scope:t,contentId:Fo(),triggerRef:c,open:d,onOpenChange:p,onOpenToggle:x.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:l,onCustomAnchorAdd:x.useCallback(()=>u(!0),[]),onCustomAnchorRemove:x.useCallback(()=>u(!1),[]),modal:i},n))},OQ="PopoverTrigger",DQ=x.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,o=Mc(OQ,n),s=iw(n),i=Xe(t,o.triggerRef),a=x.createElement(Ke.button,X({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":vA(o.open)},r,{ref:i,onClick:ie(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(pA,X({asChild:!0},s),a)}),yA="PopoverPortal",[RQ,LQ]=mA(yA,{forceMount:void 0}),FQ=e=>{const{__scopePopover:t,forceMount:n,children:r,container:o}=e,s=Mc(yA,t);return x.createElement(RQ,{scope:t,forceMount:n},x.createElement(yo,{present:n||s.open},x.createElement(ig,{asChild:!0,container:o},r)))},Su="PopoverContent",NQ=x.forwardRef((e,t)=>{const n=LQ(Su,e.__scopePopover),{forceMount:r=n.forceMount,...o}=e,s=Mc(Su,e.__scopePopover);return x.createElement(yo,{present:r||s.open},s.modal?x.createElement(zQ,X({},o,{ref:t})):x.createElement(BQ,X({},o,{ref:t})))}),zQ=x.forwardRef((e,t)=>{const n=Mc(Su,e.__scopePopover),r=x.useRef(null),o=Xe(t,r),s=x.useRef(!1);return x.useEffect(()=>{const i=r.current;if(i)return Yx(i)},[]),x.createElement(ug,{as:Oi,allowPinchZoom:!0},x.createElement(SA,X({},e,{ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ie(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=n.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:ie(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,l=a.button===2||c;s.current=l},{checkForDefaultPrevented:!1}),onFocusOutside:ie(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),BQ=x.forwardRef((e,t)=>{const n=Mc(Su,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(SA,X({},e,{ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=n.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=s.target;((a=n.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),SA=x.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,p=Mc(Su,n),f=iw(n);return Gx(),x.createElement(Vx,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(sg,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>p.onOpenChange(!1)},x.createElement(fA,X({"data-state":vA(p.open),role:"dialog",id:p.contentId},f,d,{ref:t,style:{...d.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)"}}))))});function vA(e){return e?"open":"closed"}const UQ=jQ,HQ=DQ,KQ=FQ,WQ=NQ;function Qs(e,t){const n=z(),r=x.useRef(!1),o=So(),s=x.useCallback(a=>{r.current=a,n.batch(()=>{a?(n.complete(),n.addOpenMenu(e)):n.updateInstanceState({openMenus:n.getOpenMenus().filter(c=>!c.startsWith(e))}),t==null||t(a)})},[n,e,t]),i=K("is menu open",()=>n.getOpenMenus().includes(e),[n,e]);return x.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),n.addOpenMenu(e)),()=>{r.current&&(n.deleteOpenMenu(e),n.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),n.deleteOpenMenu(a))}),r.current=!1)}),[n,e,o]),[i,s]}function aw({id:e,children:t,onOpenChange:n,open:r}){const[o,s]=Qs(e,n);return h.jsx(UQ,{onOpenChange:s,open:r||o,children:h.jsx("div",{className:"tlui-popover",children:t})})}function cw({children:e}){return h.jsx(HQ,{asChild:!0,dir:"ltr",children:e})}function lw({side:e,children:t,align:n="center",sideOffset:r=8,alignOffset:o=0}){const s=cn();return h.jsx(KQ,{container:s,children:h.jsx(WQ,{className:"tlui-popover__content",side:e,sideOffset:r,align:n,alignOffset:o,dir:"ltr",children:t})})}const xA=x.createContext({type:"menu",sourceId:"main-menu"});function mg(){return x.useContext(xA)}function vr({type:e,sourceId:t,children:n}){return h.jsx(xA.Provider,{value:{type:e,sourceId:t},children:n})}const VQ=x.createContext(void 0);function uw(e){const t=x.useContext(VQ);return e||t||"ltr"}const dy="rovingFocusGroup.onEntryFocus",GQ={bubbles:!1,cancelable:!0},dw="RovingFocusGroup",[kv,wA,YQ]=og(dw),[XQ,bA]=mo(dw,[YQ]),[qQ,ZQ]=XQ(dw),QQ=x.forwardRef((e,t)=>x.createElement(kv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(kv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(JQ,X({},e,{ref:t}))))),JQ=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:l,...u}=e,d=x.useRef(null),p=Xe(t,d),f=uw(s),[y=null,g]=Zs({prop:i,defaultProp:a,onChange:c}),[w,S]=x.useState(!1),v=sn(l),b=wA(n),E=x.useRef(!1),[C,I]=x.useState(0);return x.useEffect(()=>{const _=d.current;if(_)return _.addEventListener(dy,v),()=>_.removeEventListener(dy,v)},[v]),x.createElement(qQ,{scope:n,orientation:r,dir:f,loop:o,currentTabStopId:y,onItemFocus:x.useCallback(_=>g(_),[g]),onItemShiftTab:x.useCallback(()=>S(!0),[]),onFocusableItemAdd:x.useCallback(()=>I(_=>_+1),[]),onFocusableItemRemove:x.useCallback(()=>I(_=>_-1),[])},x.createElement(Ke.div,X({tabIndex:w||C===0?-1:0,"data-orientation":r},u,{ref:p,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{E.current=!0}),onFocus:ie(e.onFocus,_=>{const k=!E.current;if(_.target===_.currentTarget&&k&&!w){const $=new CustomEvent(dy,GQ);if(_.currentTarget.dispatchEvent($),!$.defaultPrevented){const T=b().filter(B=>B.focusable),O=T.find(B=>B.active),N=T.find(B=>B.id===y),L=[O,N,...T].filter(Boolean).map(B=>B.ref.current);PA(L)}}E.current=!1}),onBlur:ie(e.onBlur,()=>S(!1))})))}),eJ="RovingFocusGroupItem",tJ=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Fo(),c=s||a,l=ZQ(eJ,n),u=l.currentTabStopId===c,d=wA(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=l;return x.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),x.createElement(kv.ItemSlot,{scope:n,id:c,focusable:r,active:o},x.createElement(Ke.span,X({tabIndex:u?0:-1,"data-orientation":l.orientation},i,{ref:t,onMouseDown:ie(e.onMouseDown,y=>{r?l.onItemFocus(c):y.preventDefault()}),onFocus:ie(e.onFocus,()=>l.onItemFocus(c)),onKeyDown:ie(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){l.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=oJ(y,l.orientation,l.dir);if(g!==void 0){y.preventDefault();let S=d().filter(v=>v.focusable).map(v=>v.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const v=S.indexOf(y.currentTarget);S=l.loop?sJ(S,v+1):S.slice(v+1)}setTimeout(()=>PA(S))}})})))}),nJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function rJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function oJ(e,t,n){const r=rJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return nJ[r]}function PA(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function sJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}const iJ=QQ,aJ=tJ,Tv=["Enter"," "],cJ=["ArrowDown","PageUp","Home"],CA=["ArrowUp","PageDown","End"],lJ=[...cJ,...CA],uJ={ltr:[...Tv,"ArrowRight"],rtl:[...Tv,"ArrowLeft"]},dJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},yg="Menu",[vu,hJ,pJ]=og(yg),[Xi,Sg]=mo(yg,[pJ,gg,bA]),vg=gg(),IA=bA(),[EA,Js]=Xi(yg),[fJ,Hu]=Xi(yg),gJ=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=vg(t),[c,l]=x.useState(null),u=x.useRef(!1),d=sn(s),p=uw(o);return x.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),x.createElement(sw,a,x.createElement(EA,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l},x.createElement(fJ,{scope:t,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:p,modal:i},r)))},_A=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=vg(n);return x.createElement(pA,X({},o,r,{ref:t}))}),kA="MenuPortal",[mJ,TA]=Xi(kA,{forceMount:void 0}),yJ=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Js(kA,t);return x.createElement(mJ,{scope:t,forceMount:n},x.createElement(yo,{present:n||s.open},x.createElement(ig,{asChild:!0,container:o},r)))},Nr="MenuContent",[SJ,hw]=Xi(Nr),vJ=x.forwardRef((e,t)=>{const n=TA(Nr,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Js(Nr,e.__scopeMenu),i=Hu(Nr,e.__scopeMenu);return x.createElement(vu.Provider,{scope:e.__scopeMenu},x.createElement(yo,{present:r||s.open},x.createElement(vu.Slot,{scope:e.__scopeMenu},i.modal?x.createElement(xJ,X({},o,{ref:t})):x.createElement(wJ,X({},o,{ref:t})))))}),xJ=x.forwardRef((e,t)=>{const n=Js(Nr,e.__scopeMenu),r=x.useRef(null),o=Xe(t,r);return x.useEffect(()=>{const s=r.current;if(s)return Yx(s)},[]),x.createElement(pw,X({},e,{ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)}))}),wJ=x.forwardRef((e,t)=>{const n=Js(Nr,e.__scopeMenu);return x.createElement(pw,X({},e,{ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)}))}),pw=x.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:p,onDismiss:f,disableOutsideScroll:y,...g}=e,w=Js(Nr,n),S=Hu(Nr,n),v=vg(n),b=IA(n),E=hJ(n),[C,I]=x.useState(null),_=x.useRef(null),k=Xe(t,_,w.onContentChange),$=x.useRef(0),T=x.useRef(""),O=x.useRef(0),N=x.useRef(null),F=x.useRef("right"),L=x.useRef(0),B=y?ug:x.Fragment,q=y?{as:Oi,allowPinchZoom:!0}:void 0,Q=U=>{var W,Z;const le=T.current+U,be=E().filter(Ie=>!Ie.disabled),Me=document.activeElement,ae=(W=be.find(Ie=>Ie.ref.current===Me))===null||W===void 0?void 0:W.textValue,Ae=be.map(Ie=>Ie.textValue),Re=DJ(Ae,le,ae),ot=(Z=be.find(Ie=>Ie.textValue===Re))===null||Z===void 0?void 0:Z.ref.current;(function Ie(ht){T.current=ht,window.clearTimeout($.current),ht!==""&&($.current=window.setTimeout(()=>Ie(""),1e3))})(le),ot&&setTimeout(()=>ot.focus())};x.useEffect(()=>()=>window.clearTimeout($.current),[]),Gx();const H=x.useCallback(U=>{var W,Z;return F.current===((W=N.current)===null||W===void 0?void 0:W.side)&&LJ(U,(Z=N.current)===null||Z===void 0?void 0:Z.area)},[]);return x.createElement(SJ,{scope:n,searchRef:T,onItemEnter:x.useCallback(U=>{H(U)&&U.preventDefault()},[H]),onItemLeave:x.useCallback(U=>{var W;H(U)||((W=_.current)===null||W===void 0||W.focus(),I(null))},[H]),onTriggerLeave:x.useCallback(U=>{H(U)&&U.preventDefault()},[H]),pointerGraceTimerRef:O,onPointerGraceIntentChange:x.useCallback(U=>{N.current=U},[])},x.createElement(B,q,x.createElement(Vx,{asChild:!0,trapped:o,onMountAutoFocus:ie(s,U=>{var W;U.preventDefault(),(W=_.current)===null||W===void 0||W.focus()}),onUnmountAutoFocus:i},x.createElement(sg,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:p,onDismiss:f},x.createElement(iJ,X({asChild:!0},b,{dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:I,onEntryFocus:ie(c,U=>{S.isUsingKeyboardRef.current||U.preventDefault()})}),x.createElement(fA,X({role:"menu","aria-orientation":"vertical","data-state":OA(w.open),"data-radix-menu-content":"",dir:S.dir},v,g,{ref:k,style:{outline:"none",...g.style},onKeyDown:ie(g.onKeyDown,U=>{const Z=U.target.closest("[data-radix-menu-content]")===U.currentTarget,le=U.ctrlKey||U.altKey||U.metaKey,be=U.key.length===1;Z&&(U.key==="Tab"&&U.preventDefault(),!le&&be&&Q(U.key));const Me=_.current;if(U.target!==Me||!lJ.includes(U.key))return;U.preventDefault();const Ae=E().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);CA.includes(U.key)&&Ae.reverse(),jJ(Ae)}),onBlur:ie(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout($.current),T.current="")}),onPointerMove:ie(e.onPointerMove,xu(U=>{const W=U.target,Z=L.current!==U.clientX;if(U.currentTarget.contains(W)&&Z){const le=U.clientX>L.current?"right":"left";F.current=le,L.current=U.clientX}}))})))))))}),bJ=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return x.createElement(Ke.div,X({role:"group"},r,{ref:t}))}),$v="MenuItem",aI="menu.itemSelect",$A=x.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=x.useRef(null),i=Hu($v,e.__scopeMenu),a=hw($v,e.__scopeMenu),c=Xe(t,s),l=x.useRef(!1),u=()=>{const d=s.current;if(!n&&d){const p=new CustomEvent(aI,{bubbles:!0,cancelable:!0});d.addEventListener(aI,f=>r==null?void 0:r(f),{once:!0}),Kx(d,p),p.defaultPrevented?l.current=!1:i.onClose()}};return x.createElement(MA,X({},o,{ref:c,disabled:n,onClick:ie(e.onClick,u),onPointerDown:d=>{var p;(p=e.onPointerDown)===null||p===void 0||p.call(e,d),l.current=!0},onPointerUp:ie(e.onPointerUp,d=>{var p;l.current||(p=d.currentTarget)===null||p===void 0||p.click()}),onKeyDown:ie(e.onKeyDown,d=>{const p=a.searchRef.current!=="";n||p&&d.key===" "||Tv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),MA=x.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=hw($v,n),a=IA(n),c=x.useRef(null),l=Xe(t,c),[u,d]=x.useState(!1),[p,f]=x.useState("");return x.useEffect(()=>{const y=c.current;if(y){var g;f(((g=y.textContent)!==null&&g!==void 0?g:"").trim())}},[s.children]),x.createElement(vu.ItemSlot,{scope:n,disabled:r,textValue:o??p},x.createElement(aJ,X({asChild:!0},a,{focusable:!r}),x.createElement(Ke.div,X({role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:l,onPointerMove:ie(e.onPointerMove,xu(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus())})),onPointerLeave:ie(e.onPointerLeave,xu(y=>i.onItemLeave(y))),onFocus:ie(e.onFocus,()=>d(!0)),onBlur:ie(e.onBlur,()=>d(!1))}))))}),PJ=x.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return x.createElement(EJ,{scope:e.__scopeMenu,checked:n},x.createElement($A,X({role:"menuitemcheckbox","aria-checked":Mv(n)?"mixed":n},o,{ref:t,"data-state":AJ(n),onSelect:ie(o.onSelect,()=>r==null?void 0:r(Mv(n)?!0:!n),{checkForDefaultPrevented:!1})})))}),CJ="MenuRadioGroup";Xi(CJ,{value:void 0,onValueChange:()=>{}});const IJ="MenuItemIndicator",[EJ,_oe]=Xi(IJ,{checked:!1}),AA="MenuSub",[_J,jA]=Xi(AA),kJ=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:o}=e,s=Js(AA,t),i=vg(t),[a,c]=x.useState(null),[l,u]=x.useState(null),d=sn(o);return x.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),x.createElement(sw,i,x.createElement(EA,{scope:t,open:r,onOpenChange:d,content:l,onContentChange:u},x.createElement(_J,{scope:t,contentId:Fo(),triggerId:Fo(),trigger:a,onTriggerChange:c},n)))},Zd="MenuSubTrigger",TJ=x.forwardRef((e,t)=>{const n=Js(Zd,e.__scopeMenu),r=Hu(Zd,e.__scopeMenu),o=jA(Zd,e.__scopeMenu),s=hw(Zd,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,l={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),c(null)}},[a,c]),x.createElement(_A,X({asChild:!0},l),x.createElement(MA,X({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":OA(n.open)},e,{ref:rg(t,o.onTriggerChange),onClick:d=>{var p;(p=e.onClick)===null||p===void 0||p.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ie(e.onPointerMove,xu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:ie(e.onPointerLeave,xu(d=>{var p;u();const f=(p=n.content)===null||p===void 0?void 0:p.getBoundingClientRect();if(f){var y;const g=(y=n.content)===null||y===void 0?void 0:y.dataset.side,w=g==="right",S=w?-5:5,v=f[w?"left":"right"],b=f[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+S,y:d.clientY},{x:v,y:f.top},{x:b,y:f.top},{x:b,y:f.bottom},{x:v,y:f.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ie(e.onKeyDown,d=>{const p=s.searchRef.current!=="";if(!(e.disabled||p&&d.key===" ")&&uJ[r.dir].includes(d.key)){var f;n.onOpenChange(!0),(f=n.content)===null||f===void 0||f.focus(),d.preventDefault()}})})))}),$J="MenuSubContent",MJ=x.forwardRef((e,t)=>{const n=TA(Nr,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Js(Nr,e.__scopeMenu),i=Hu(Nr,e.__scopeMenu),a=jA($J,e.__scopeMenu),c=x.useRef(null),l=Xe(t,c);return x.createElement(vu.Provider,{scope:e.__scopeMenu},x.createElement(yo,{present:r||s.open},x.createElement(vu.Slot,{scope:e.__scopeMenu},x.createElement(pw,X({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:l,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;i.isUsingKeyboardRef.current&&((d=c.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ie(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ie(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ie(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),p=dJ[i.dir].includes(u.key);if(d&&p){var f;s.onOpenChange(!1),(f=a.trigger)===null||f===void 0||f.focus(),u.preventDefault()}})})))))});function OA(e){return e?"open":"closed"}function Mv(e){return e==="indeterminate"}function AJ(e){return Mv(e)?"indeterminate":e?"checked":"unchecked"}function jJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function OJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function DJ(e,t,n){const o=t.length>1&&Array.from(t).every(l=>l===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=OJ(e,Math.max(s,0));o.length===1&&(i=i.filter(l=>l!==n));const c=i.find(l=>l.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function RJ(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s].x,c=t[s].y,l=t[i].x,u=t[i].y;c>r!=u>r&&n<(l-a)*(r-c)/(u-c)+a&&(o=!o)}return o}function LJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return RJ(n,t)}function xu(e){return t=>t.pointerType==="mouse"?e(t):void 0}const DA=gJ,RA=_A,LA=yJ,FA=vJ,NA=bJ,zA=$A,BA=PJ,UA=kJ,HA=TJ,KA=MJ,WA="ContextMenu",[FJ,koe]=mo(WA,[Sg]),vo=Sg(),[NJ,VA]=FJ(WA),zJ=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=x.useState(!1),c=vo(t),l=sn(r),u=x.useCallback(d=>{a(d),l(d)},[l]);return x.createElement(NJ,{scope:t,open:i,onOpenChange:u,modal:s},x.createElement(DA,X({},c,{dir:o,open:i,onOpenChange:u,modal:s}),n))},BJ="ContextMenuTrigger",UJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...o}=e,s=VA(BJ,n),i=vo(n),a=x.useRef({x:0,y:0}),c=x.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),l=x.useRef(0),u=x.useCallback(()=>window.clearTimeout(l.current),[]),d=p=>{a.current={x:p.clientX,y:p.clientY},s.onOpenChange(!0)};return x.useEffect(()=>u,[u]),x.useEffect(()=>void(r&&u()),[r,u]),x.createElement(x.Fragment,null,x.createElement(RA,X({},i,{virtualRef:c})),x.createElement(Ke.span,X({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:ie(e.onContextMenu,p=>{u(),d(p),p.preventDefault()}),onPointerDown:r?e.onPointerDown:ie(e.onPointerDown,Qd(p=>{u(),l.current=window.setTimeout(()=>d(p),700)})),onPointerMove:r?e.onPointerMove:ie(e.onPointerMove,Qd(u)),onPointerCancel:r?e.onPointerCancel:ie(e.onPointerCancel,Qd(u)),onPointerUp:r?e.onPointerUp:ie(e.onPointerUp,Qd(u))})))}),GA=e=>{const{__scopeContextMenu:t,...n}=e,r=vo(t);return x.createElement(LA,X({},r,n))},HJ="ContextMenuContent",KJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=VA(HJ,n),s=vo(n),i=x.useRef(!1);return x.createElement(FA,X({},s,r,{ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var c;(c=e.onCloseAutoFocus)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var c;(c=e.onInteractOutside)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.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)"}}))}),WJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=vo(n);return x.createElement(NA,X({},o,r,{ref:t}))}),VJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=vo(n);return x.createElement(zA,X({},o,r,{ref:t}))}),GJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=vo(n);return x.createElement(BA,X({},o,r,{ref:t}))}),YJ=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,open:o,defaultOpen:s}=e,i=vo(t),[a,c]=Zs({prop:o,defaultProp:s,onChange:r});return x.createElement(UA,X({},i,{open:a,onOpenChange:c}),n)},XJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=vo(n);return x.createElement(HA,X({},o,r,{ref:t}))}),qJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=vo(n);return x.createElement(KA,X({},o,r,{ref:t,style:{...e.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)"}}))});function Qd(e){return t=>t.pointerType!=="mouse"?e(t):void 0}const ZJ=zJ,QJ=UJ,JJ=GA,eee=KJ,tee=GJ,YA=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,nee=YA?"⌘":"Ctrl",ree=YA?"⌥":"Alt";function XA(e){return e.split(",")[0].split("").map(t=>{const n=t.replace(/\$/g,nee).replace(/\?/g,ree).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function Av(e){return"— "+XA(e).join(" ")}function oee(e){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const qA="DropdownMenu",[see,Toe]=mo(qA,[Sg]),xo=Sg(),[iee,ZA]=see(qA),aee=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=xo(t),l=x.useRef(null),[u=!1,d]=Zs({prop:o,defaultProp:s,onChange:i});return x.createElement(iee,{scope:t,triggerId:Fo(),triggerRef:l,contentId:Fo(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(p=>!p),[d]),modal:a},x.createElement(DA,X({},c,{open:u,onOpenChange:d,dir:r,modal:a}),n))},cee="DropdownMenuTrigger",lee=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=ZA(cee,n),i=xo(n);return x.createElement(RA,X({asChild:!0},i),x.createElement(Ke.button,X({type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r},o,{ref:rg(t,s.triggerRef),onPointerDown:ie(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ie(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),uee=e=>{const{__scopeDropdownMenu:t,...n}=e,r=xo(t);return x.createElement(LA,X({},r,n))},dee="DropdownMenuContent",hee=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=ZA(dee,n),s=xo(n),i=x.useRef(!1);return x.createElement(FA,X({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:t,onCloseAutoFocus:ie(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)===null||c===void 0||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ie(e.onInteractOutside,a=>{const c=a.detail.originalEvent,l=c.button===0&&c.ctrlKey===!0,u=c.button===2||l;(!o.modal||u)&&(i.current=!0)}),style:{...e.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)"}}))}),pee=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xo(n);return x.createElement(NA,X({},o,r,{ref:t}))}),fee=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xo(n);return x.createElement(zA,X({},o,r,{ref:t}))}),gee=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xo(n);return x.createElement(BA,X({},o,r,{ref:t}))}),mee=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:o,defaultOpen:s}=e,i=xo(t),[a=!1,c]=Zs({prop:r,defaultProp:s,onChange:o});return x.createElement(UA,X({},i,{open:a,onOpenChange:c}),n)},yee=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xo(n);return x.createElement(HA,X({},o,r,{ref:t}))}),See=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xo(n);return x.createElement(KA,X({},o,r,{ref:t,style:{...e.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)"}}))}),fw=aee,gw=lee,xg=uee,mw=hee,vee=pee,xee=fee,wee=gee,bee=mee,Pee=yee,Cee=See;function Li({id:e,children:t,modal:n=!1,debugOpen:r=!1}){const[o,s]=Qs(e);return h.jsx(fw,{open:r||o,dir:"ltr",modal:n,onOpenChange:s,children:t})}function Fi({children:e,...t}){return h.jsx(gw,{dir:"ltr",asChild:!0,onTouchEnd:n=>Ee(n),...t,children:e})}function Ni({side:e="bottom",align:t="start",sideOffset:n=8,alignOffset:r=8,children:o}){const s=cn();return h.jsx(xg,{container:s,children:h.jsx(mw,{className:"tlui-menu",side:e,sideOffset:n,align:t,alignOffset:r,collisionPadding:4,children:o})})}function Iee({id:e,children:t}){const[n,r]=Qs(e);return h.jsx(bee,{open:n,onOpenChange:r,children:t})}function Eee({id:e,label:t,title:n,disabled:r}){return h.jsx(Pee,{dir:"ltr",asChild:!0,disabled:r,children:h.jsxs(pe,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[h.jsx(vt,{children:t}),h.jsx(ke,{icon:"chevron-right",small:!0})]})})}function _ee({id:e,alignOffset:t=-1,sideOffset:n=-4,size:r="small",children:o}){const s=cn();return h.jsx(xg,{container:s,children:h.jsx(Cee,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:t,sideOffset:n,collisionPadding:4,"data-size":r,children:o})})}function kee({children:e}){return h.jsx(vee,{dir:"ltr",className:"tlui-menu__group",children:e})}function wu({noClose:e,children:t}){return h.jsx(xee,{dir:"ltr",asChild:!0,onClick:e?Ee:void 0,children:t})}function Dl({children:e,visibleOnMobileLayout:t=!1}){const n=Rn();return!t&&n<mt.MOBILE?null:h.jsx("kbd",{className:"tlui-kbd",children:XA(e).map((r,o)=>h.jsx("span",{children:r},o))})}function R({disabled:e=!1,spinner:t=!1,readonlyOk:n=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:c,isSelected:l}){const{type:u,sourceId:d}=mg(),p=$e(),[f,y]=x.useState(!1);if(ns()&&!n)return null;const w=gu(s,u),S=o?Av(o):void 0,v=w?p(w):void 0,b=v&&S?`${v} ${S}`:v;switch(u){case"menu":return h.jsx(wu,{children:h.jsxs(pe,{type:"menu","data-testid":`${d}.${r}`,disabled:e,title:b,onClick:E=>{c&&Ee(E),f?y(!1):a(d)},children:[h.jsx(vt,{children:v}),o&&h.jsx(Dl,{children:o})]})});case"context-menu":return e?null:h.jsxs(VJ,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${d}.${r}`,onSelect:E=>{c&&Ee(E),f?y(!1):a(d)},children:[h.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&h.jsx(Dl,{children:o}),t&&h.jsx(oee,{})]});case"panel":return h.jsxs(pe,{"data-testid":`${d}.${r}`,type:"menu",title:b,disabled:e,onClick:()=>a(d),children:[h.jsx(vt,{children:v}),i&&h.jsx(ke,{icon:i})]});case"small-icons":case"icons":return h.jsx(pe,{"data-testid":`${d}.${r}`,type:"icon",title:b,disabled:e,onClick:()=>a(d),children:h.jsx(ke,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return o?h.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${d}.${r}`,children:[h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:h.jsx(Dl,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return h.jsxs(pe,{type:"low",onClick:()=>a(d),children:[h.jsx(ke,{icon:i}),h.jsx(vt,{children:v})]});case"toolbar":return h.jsx(pe,{type:"tool","data-testid":`tools.${r}`,"aria-label":w,"data-value":r,onClick:()=>a("toolbar"),title:b,onTouchStart:E=>{Ee(E),a("toolbar")},role:"radio","aria-checked":l?"true":"false",children:h.jsx(ke,{icon:i})});case"toolbar-overflow":return h.jsx(wu,{"aria-label":s,children:h.jsx(pe,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:b,role:"radio","aria-checked":l?"true":"false","data-value":r,children:h.jsx(ke,{icon:i})})});default:throw qo(u)}}function Tee(){return h.jsxs(h.Fragment,{children:[h.jsx($ee,{}),h.jsx(Mee,{}),h.jsx(Aee,{}),h.jsx(jee,{}),h.jsx(Oee,{}),h.jsx(Lee,{}),h.jsx(Fee,{}),h.jsx(Nee,{})]})}function $ee(){const e=ce(),t=wn(2);return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["align-left"],disabled:!t}),h.jsx(R,{...e["align-center-horizontal"],disabled:!t}),h.jsx(R,{...e["align-right"],disabled:!t}),h.jsx(R,{...e["stretch-horizontal"],disabled:!t}),h.jsx(R,{...e["align-top"],disabled:!t}),h.jsx(R,{...e["align-center-vertical"],disabled:!t}),h.jsx(R,{...e["align-bottom"],disabled:!t}),h.jsx(R,{...e["stretch-vertical"],disabled:!t})]})}function Mee(){const e=ce(),t=wn(3);return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["distribute-horizontal"],disabled:!t}),h.jsx(R,{...e["distribute-vertical"],disabled:!t})]})}function Aee(){const e=ce(),t=VT();return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["stack-horizontal"],disabled:!t}),h.jsx(R,{...e["stack-vertical"],disabled:!t})]})}function jee(){const e=ce(),t=wn(1);return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["send-to-back"],disabled:!t}),h.jsx(R,{...e["send-backward"],disabled:!t}),h.jsx(R,{...e["bring-forward"],disabled:!t}),h.jsx(R,{...e["bring-to-front"],disabled:!t})]})}function Oee(){return Rn()<mt.TABLET_SM?h.jsx(Dee,{}):h.jsx(Ree,{})}function Dee(){const e=ce(),t=z(),n=K("zoom is 1",()=>t.getZoomLevel()===1,[t]);return h.jsx(R,{...e["zoom-to-100"],disabled:n})}function Ree(){const e=ce(),t=wn(1);return h.jsx(R,{...e["rotate-ccw"],disabled:!t})}function Lee(){const e=ce(),t=wn(1);return h.jsx(R,{...e["rotate-cw"],disabled:!t})}function Fee(){const e=ce(),t=XT();return h.jsx(R,{...e["edit-link"],disabled:!t})}function Nee(){const e=GT(),t=YT();return e?h.jsx(cI,{}):t?h.jsx(zee,{}):h.jsx(cI,{})}function cI(){const e=ce(),t=wn(2);return h.jsx(R,{...e.group,disabled:!t})}function zee(){const e=ce();return h.jsx(R,{...e.ungroup})}const Bee=x.memo(function({children:t}){const n=$e(),r=Rn(),o=ns(),s=z(),i=K("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=t??h.jsx(Tee,{});if(!(o&&!i))return h.jsxs(aw,{id:"actions-menu",children:[h.jsx(cw,{children:h.jsx(pe,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:h.jsx(ke,{icon:"dots-vertical",small:!0})})}),h.jsx(lw,{side:r>=mt.TABLET?"bottom":"top",sideOffset:6,children:h.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:h.jsx(vr,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function wr({id:e,kbd:t,label:n,readonlyOk:r,onSelect:o,disabled:s=!1,checked:i=!1}){const{type:a,sourceId:c}=mg(),l=ns(),u=$e();if(l&&!r)return null;const d=gu(n,a),p=d?u(d):void 0;switch(a){case"menu":return h.jsxs(wee,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:p,onSelect:f=>{o==null||o(c),Ee(f)},disabled:s,checked:i,children:[h.jsx(Bs,{small:!0,icon:i?"check":"checkbox-empty"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),t&&h.jsx(Dl,{children:t})]});case"context-menu":return h.jsxs(tee,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:p,onSelect:f=>{o(c),Ee(f)},disabled:s,checked:i,children:[h.jsx(Bs,{small:!0,icon:i?"check":"checkbox-empty"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),t&&h.jsx(Dl,{children:t})]},e);default:return null}}function ye({id:e,label:t,children:n}){const{type:r,sourceId:o}=mg(),s=$e(),i=gu(t,r),a=i?s(i):void 0;switch(r){case"panel":return h.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:n});case"menu":return h.jsx(kee,{"data-testid":`${o}-group.${e}`,children:n});case"context-menu":return h.jsx(WJ,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:n});case"keyboard-shortcuts":return h.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[h.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),h.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:n})]});default:return n}}function br({id:e,disabled:t=!1,label:n,size:r="small",children:o}){const{type:s,sourceId:i}=mg(),a=cn(),c=$e(),l=n?typeof n=="string"?n:n[s]??n.default:void 0,u=l?c(l):void 0;switch(s){case"menu":return h.jsxs(Iee,{id:`${i}-sub.${e}`,children:[h.jsx(Eee,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:t,label:u,title:u}),h.jsx(_ee,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return t?null:h.jsxs(Uee,{id:`${i}-sub.${e}`,children:[h.jsx(XJ,{dir:"ltr",disabled:t,asChild:!0,children:h.jsxs(pe,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[h.jsx(vt,{children:u}),h.jsx(ke,{icon:"chevron-right",small:!0})]})}),h.jsx(GA,{container:a,children:h.jsx(qJ,{"data-testid":`${i}-sub-content.${e}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function Uee({id:e,children:t}){const[n,r]=Qs(e);return h.jsx(YJ,{open:n,onOpenChange:r,children:t})}function QA(){const e=ce();return wW()?h.jsx(R,{...e["toggle-auto-size"]}):null}function JA(){const e=ce();return XT()?h.jsx(R,{...e["edit-link"]}):null}function Hee(){const e=ce();return wn(1)?h.jsx(R,{...e.duplicate}):null}function ej(){const e=ce();return GT()?h.jsx(R,{...e.group}):null}function tj(){const e=ce();return YT()?h.jsx(R,{...e.ungroup}):null}function nj(){const e=z(),t=ce();return K("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?h.jsx(R,{...t["remove-frame"]}):null}function rj(){const e=z(),t=ce();return K("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?h.jsx(R,{...t["fit-frame-to-content"]}):null}function oj(){const e=z(),t=ce();return K("selected shapes",()=>e.getSelectedShapes().length>0,[e])?h.jsx(R,{...t["toggle-lock"]}):null}function yw(){const e=ce(),t=z(),n=K("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return h.jsx(wr,{...e["toggle-transparent"],checked:n})}function Kee(){const e=z(),t=ce(),n=K("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsx(R,{...t["unlock-all"],disabled:!n})}function sj(){const e=z(),t=K("zoomed to 100",()=>e.getZoomLevel()===1,[e]),n=ce();return h.jsx(R,{...n["zoom-to-100"],noClose:!0,disabled:t})}function ij(){const e=z(),t=K("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),n=ce();return h.jsx(R,{...n["zoom-to-fit"],disabled:!t,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function aj(){const e=z(),t=K("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),n=ce();return h.jsx(R,{...n["zoom-to-selection"],disabled:!t,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function cj(){return h.jsxs(ye,{id:"clipboard",children:[h.jsx(Vee,{}),h.jsx(Gee,{}),h.jsx(Yee,{}),h.jsx(Hee,{}),h.jsx(Xee,{})]})}function Wee(){var r;const e=z(),t=ce(),n=K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsxs(br,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!n,children:[h.jsxs(ye,{id:"copy-as-group",children:[h.jsx(R,{...t["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&h.jsx(R,{...t["copy-as-png"]}),h.jsx(R,{...t["copy-as-json"]})]}),h.jsx(ye,{id:"copy-as-bg",children:h.jsx(yw,{})})]})}function Vee(){const e=ce(),t=wn(1);return h.jsx(R,{...e.cut,disabled:!t})}function Gee(){const e=ce(),t=xW(1);return h.jsx(R,{...e.copy,disabled:!t})}function Yee(){const e=ce(),t=vW;return h.jsx(R,{...e.paste,disabled:!t})}function lj(){const e=z(),t=ce();return K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?h.jsxs(ye,{id:"conversions",children:[h.jsx(Wee,{}),h.jsxs(br,{id:"export-as",label:"context-menu.export-as",size:"small",children:[h.jsxs(ye,{id:"export-as-group",children:[h.jsx(R,{...t["export-as-svg"]}),h.jsx(R,{...t["export-as-png"]}),h.jsx(R,{...t["export-as-json"]})]}),h.jsx(ye,{id:"export-as-bg",children:h.jsx(yw,{})})]})]}):null}function uj(){const e=ce(),t=z(),n=K("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return h.jsx(R,{...e["select-all"],disabled:!n})}function Xee(){const e=ce(),t=wn(1);return h.jsx(R,{...e.delete,disabled:!t})}function qee(){const e=wn(2),t=bW(),n=ce();return e||t?h.jsxs(br,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&h.jsxs(ye,{id:"align",children:[h.jsx(R,{...n["align-left"]}),h.jsx(R,{...n["align-center-horizontal"]}),h.jsx(R,{...n["align-right"]}),h.jsx(R,{...n["align-top"]}),h.jsx(R,{...n["align-center-vertical"]}),h.jsx(R,{...n["align-bottom"]})]}),h.jsx(Zee,{}),e&&h.jsxs(ye,{id:"stretch",children:[h.jsx(R,{...n["stretch-horizontal"]}),h.jsx(R,{...n["stretch-vertical"]})]}),(e||t)&&h.jsxs(ye,{id:"flip",children:[h.jsx(R,{...n["flip-horizontal"]}),h.jsx(R,{...n["flip-vertical"]})]}),h.jsx(Qee,{})]}):null}function Zee(){const e=ce();return wn(3)?h.jsxs(ye,{id:"distribute",children:[h.jsx(R,{...e["distribute-horizontal"]}),h.jsx(R,{...e["distribute-vertical"]})]}):null}function Qee(){const e=ce(),t=wn(2),n=VT();return t?h.jsxs(ye,{id:"order",children:[h.jsx(R,{...e.pack}),n&&h.jsx(R,{...e["stack-horizontal"]}),n&&h.jsx(R,{...e["stack-vertical"]})]}):null}function Jee(){const e=ce();return wn(1)?h.jsx(br,{id:"reorder",label:"context-menu.reorder",size:"small",children:h.jsxs(ye,{id:"reorder",children:[h.jsx(R,{...e["bring-to-front"]}),h.jsx(R,{...e["bring-forward"]}),h.jsx(R,{...e["send-backward"]}),h.jsx(R,{...e["send-to-back"]})]})}):null}function ete(){const e=z(),t=K("pages",()=>e.getPages(),[e]),n=K("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Kr(),o=ce(),s=So();return wn(1)?h.jsxs(br,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[h.jsx(ye,{id:"pages",children:t.map(a=>h.jsx(R,{id:a.id,disabled:n===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const c=e.getPage(a.id);c&&r({title:"Changed Page",description:`Moved to ${c.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(n)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),h.jsx(ye,{id:"new-page",children:h.jsx(R,{...o["new-page"]})})]}):null}function dj(){const e=z(),t=ce();return K("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(R,{...t["convert-to-bookmark"]}):null}function hj(){const e=z(),t=ce();return K("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&Cs(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(R,{...t["convert-to-embed"]}):null}function tte(){const e=ce(),t=z(),n=K("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return h.jsx(wr,{...e["toggle-snap-mode"],checked:n})}function nte(){const e=ce(),t=z(),n=K("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return h.jsx(wr,{...e["toggle-tool-lock"],checked:n})}function rte(){const e=ce(),t=z(),n=K("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return h.jsx(wr,{...e["toggle-grid"],checked:n})}function ote(){const e=ce(),t=z(),n=K("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return h.jsx(wr,{...e["toggle-wrap-mode"],checked:n})}function ste(){const e=ce(),t=z(),n=K("isDarkMode",()=>t.user.getIsDarkMode(),[t]);return h.jsx(wr,{...e["toggle-dark-mode"],checked:n})}function ite(){const e=ce(),t=z(),n=K("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return h.jsx(wr,{...e["toggle-focus-mode"],checked:n})}function ate(){const e=ce(),t=z(),n=K("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return h.jsx(wr,{...e["toggle-edge-scrolling"],checked:n===1})}function cte(){const e=ce(),t=z(),n=K("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return h.jsx(wr,{...e["toggle-reduce-motion"],checked:n===0})}function lte(){const e=ce(),t=z(),n=K("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return h.jsx(wr,{...e["toggle-debug-mode"],checked:n})}function ute(){const e=z();return K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?h.jsxs(h.Fragment,{children:[h.jsxs(ye,{id:"misc",children:[h.jsx(ej,{}),h.jsx(tj,{}),h.jsx(JA,{}),h.jsx(QA,{}),h.jsx(nj,{}),h.jsx(rj,{}),h.jsx(hj,{}),h.jsx(dj,{}),h.jsx(oj,{})]}),h.jsxs(ye,{id:"modify",children:[h.jsx(qee,{}),h.jsx(Jee,{}),h.jsx(ete,{})]}),h.jsx(cj,{}),h.jsx(lj,{}),h.jsx(ye,{id:"select-all",children:h.jsx(uj,{})})]}):null}const dte=x.memo(function({children:t}){const n=z(),{Canvas:r}=dt(),o=x.useCallback(l=>{if(l){if(n.getInstanceState().isCoarsePointer){const u=n.getSelectedShapes(),{inputs:{currentPagePoint:d}}=n,p=n.getShapesAtPoint(d);if(!n.getSelectedShapes().length||!p.some(f=>u.includes(f))){const f=p.filter(y=>n.isShapeOrAncestorLocked(y));f.length&&n.select(...f.map(y=>y.id))}}}else{const u=n.getOnlySelectedShape();u&&n.isShapeOrAncestorLocked(u)&&n.setSelectedShapes([])}},[n]),s=cn(),[i,a]=Qs("context menu",o),c=t??h.jsx(ute,{});return h.jsxs(ZJ,{dir:"ltr",onOpenChange:a,modal:!1,children:[h.jsx(QJ,{onContextMenu:void 0,dir:"ltr",children:r?h.jsx(r,{}):null}),i&&h.jsx(JJ,{container:s,children:h.jsx(eee,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ee,children:h.jsx(vr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})});function jv({checked:e}){return h.jsx(Bs,{icon:e?"check":"checkbox-empty",className:"tlui-button__icon",small:!0})}function hte(){const e=z(),{addToast:t}=Kr(),{addDialog:n}=Yi(),[r,o]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(ye,{id:"items",children:[h.jsx(R,{id:"add-toast",onSelect:()=>{t({id:et(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),t({id:et(),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:()=>{}}]}),t({id:et(),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:()=>{}}]}),t({id:et(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),h.jsx(R,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:s})=>h.jsx(gte,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),h.jsx(R,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>mte(e,100)}),h.jsx(R,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const s=e.getSelectedShapes(),i=s.length===0?e.getRenderingShapes():s;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})(),h.jsx(R,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),h.jsx(R,{id:"hard-reset",onSelect:S2,label:"Hard reset"})]}),h.jsxs(ye,{id:"flags",children:[h.jsx(pte,{}),h.jsx(fte,{})]})]})}function pte(){const e=Object.values($t);return e.length?h.jsx(br,{id:"debug flags",label:"Debug Flags",children:h.jsx(ye,{id:"debug flags",children:e.map(t=>h.jsx(pj,{flag:t},t.name))})}):null}function fte(){const e=Object.values(z5);return e.length?h.jsx(br,{id:"feature flags",label:"Feature Flags",children:h.jsx(ye,{id:"feature flags",children:e.map(t=>h.jsx(pj,{flag:t},t.name))})}):null}function gte({title:e="title",body:t="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,c]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{children:[h.jsx(hg,{children:e}),h.jsx(pg,{})]}),h.jsx(fu,{style:{maxWidth:350},children:t}),h.jsxs(Xx,{className:"tlui-dialog__footer__actions",children:[o&&h.jsxs(pe,{type:"normal",onClick:()=>c(!a),style:{marginRight:"auto"},children:[h.jsx(jv,{checked:a}),h.jsx(vt,{children:"Don't show again"})]}),h.jsx(pe,{type:"normal",onClick:s,children:h.jsx(vt,{children:n})}),h.jsx(pe,{type:"primary",onClick:async()=>i(),children:h.jsx(vt,{children:r})})]})]})}const pj=or(function({flag:t,onChange:n}){const r=t.get();return h.jsx(wr,{id:t.name,title:t.name,label:t.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{t.set(!r),n==null||n(!r)}})});let lI=0;function mte(e,t){const n=Array(t),r=Math.floor(Math.sqrt(t));for(let o=0;o<t;o++)lI++,n[o]={id:Be("box"+lI),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(n).setSelectedShapes(n.map(o=>o.id))})}function yte({children:e}){const t=e??h.jsx(hte,{});return h.jsxs(Li,{id:"debug",children:[h.jsx(Fi,{children:h.jsx(pe,{type:"icon",title:"Debug menu",children:h.jsx(ke,{icon:"dots-horizontal"})})}),h.jsx(Ni,{side:"top",align:"end",alignOffset:0,children:h.jsx(vr,{type:"menu",sourceId:"debug-panel",children:t})})]})}const Ste=x.memo(function(){const{DebugMenu:t}=ti();return h.jsxs("div",{className:"tlui-debug-panel",children:[h.jsx(xte,{}),h.jsx(wte,{}),t&&h.jsx(t,{})]})});function vte(e=!0){const[t,n]=x.useState(0),r=z();x.useEffect(()=>{if(!e)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const xte=or(function(){vte();const t=z(),n=t.getPath(),r=t.getHoveredShape(),o=t.getOnlySelectedShape(),s=n==="select.idle"||!n.includes("select.")?r:o,i=s&&n.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${P.ToFixed(t.getPointInShapeSpace(s,t.inputs.currentPagePoint),0)}]`:"",a=n.startsWith("select.")&&!n.includes(".idle")?` / [${P.ToFixed(t.inputs.originPagePoint,0)}] → [${P.ToFixed(t.inputs.currentPagePoint,0)}] = ${P.Dist(t.inputs.originPagePoint,t.inputs.currentPagePoint).toFixed(0)}`:"";return h.jsx("div",{className:"tlui-debug-panel__current-state",children:`${n}${i}${a}`})});function wte(){const e=K("show_fps",()=>$t.showFps.get(),[$t]),t=x.useRef(null);return x.useEffect(()=>{if(!e)return;const n=250;let r=0,o=!1,s=performance.now(),i=0,a=0,c=!1;function l(){if(!o){if(a++,i=performance.now()-s,i>n){const u=Math.round(a*(n/i)*(1e3/n));u>r&&(r=u);const d=r*.75;(u<d&&!c||u>=d&&c)&&(c=!c),t.current.innerHTML=`FPS ${u.toString()}`,t.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),i-=n,a=0,s=performance.now()}requestAnimationFrame(l)}}return l(),()=>{o=!0}},[e]),e?h.jsx("div",{ref:t}):null}function fj(){const e=z(),t=So(),n=K("locale",()=>e.user.getLocale(),[e]);return h.jsx(br,{id:"help menu language",label:"menu.language",children:h.jsx(ye,{id:"languages",children:ou.map(({locale:r,label:o})=>h.jsx(wr,{id:`language-${r}`,title:r,label:o,checked:r===n,onSelect:()=>{e.user.updateUserPreferences({locale:r}),t("change-language",{source:"menu",locale:r})}},r))})})}function bte(){return h.jsxs(h.Fragment,{children:[h.jsx(fj,{}),h.jsx(Pte,{})]})}function Pte(){const{KeyboardShortcutsDialog:e}=ti(),{addDialog:t}=Yi();return e?h.jsx(R,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{t({component:e})}}):null}const Cte=x.memo(function({children:t}){const n=$e(),r=Rn(),o=t??h.jsx(bte,{});return r<mt.MOBILE?null:h.jsx("div",{className:"tlui-help-menu",children:h.jsxs(Li,{id:"help menu",children:[h.jsx(Fi,{children:h.jsx(pe,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:h.jsx(ke,{icon:"question-mark",small:!0})})}),h.jsx(Ni,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:h.jsx(vr,{type:"menu",sourceId:"help-menu",children:o})})]})})});function Ite(){const e=z(),t=ce(),[n,r]=x.useState(!1),o=x.useRef(!1);return js("toggle showback to content",()=>{const s=o.current,i=e.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===e.getCulledShapes().size),s!==a&&(r(a),o.current=a)},[e]),n?h.jsx(R,{...t["back-to-content"],onSelect:()=>{t["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Ete(){const e=z(),t=ce();return K("is pen mode",()=>e.getInstanceState().isPenMode,[e])?h.jsx(R,{...t["exit-pen-mode"]}):null}function _te(){const e=z(),t=ce();return K("is following user",()=>!!e.getInstanceState().followingUserId,[e])?h.jsx(R,{...t["stop-following"]}):null}function kte(){return h.jsxs(h.Fragment,{children:[h.jsx(Ete,{}),h.jsx(Ite,{}),h.jsx(_te,{})]})}function Tte({children:e}){const t=e??h.jsx(kte,{});return h.jsx("div",{className:"tlui-helper-buttons",children:h.jsx(vr,{type:"helper-buttons",sourceId:"helper-buttons",children:t})})}function $te(){const e=ce(),t=De();return h.jsxs(h.Fragment,{children:[h.jsxs(ye,{label:"shortcuts-dialog.tools",id:"tools",children:[h.jsx(R,{...e["toggle-tool-lock"]}),h.jsx(R,{...e["insert-media"]}),h.jsx(R,{...t.select}),h.jsx(R,{...t.draw}),h.jsx(R,{...t.eraser}),h.jsx(R,{...t.hand}),h.jsx(R,{...t.rectangle}),h.jsx(R,{...t.ellipse}),h.jsx(R,{...t.arrow}),h.jsx(R,{...t.line}),h.jsx(R,{...t.text}),h.jsx(R,{...t.frame}),h.jsx(R,{...t.note}),h.jsx(R,{...t.laser})]}),h.jsxs(ye,{label:"shortcuts-dialog.preferences",id:"preferences",children:[h.jsx(R,{...e["toggle-dark-mode"]}),h.jsx(R,{...e["toggle-focus-mode"]}),h.jsx(R,{...e["toggle-grid"]})]}),h.jsxs(ye,{label:"shortcuts-dialog.edit",id:"edit",children:[h.jsx(R,{...e.undo}),h.jsx(R,{...e.redo}),h.jsx(R,{...e.cut}),h.jsx(R,{...e.copy}),h.jsx(R,{...e.paste}),h.jsx(R,{...e["select-all"]}),h.jsx(R,{...e.delete}),h.jsx(R,{...e.duplicate})]}),h.jsxs(ye,{label:"shortcuts-dialog.view",id:"view",children:[h.jsx(R,{...e["zoom-in"]}),h.jsx(R,{...e["zoom-out"]}),h.jsx(R,{...e["zoom-to-100"]}),h.jsx(R,{...e["zoom-to-fit"]}),h.jsx(R,{...e["zoom-to-selection"]})]}),h.jsxs(ye,{label:"shortcuts-dialog.transform",id:"transform",children:[h.jsx(R,{...e["bring-to-front"]}),h.jsx(R,{...e["bring-forward"]}),h.jsx(R,{...e["send-backward"]}),h.jsx(R,{...e["send-to-back"]}),h.jsx(R,{...e.group}),h.jsx(R,{...e.ungroup}),h.jsx(R,{...e["flip-horizontal"]}),h.jsx(R,{...e["flip-vertical"]}),h.jsx(R,{...e["align-top"]}),h.jsx(R,{...e["align-center-vertical"]}),h.jsx(R,{...e["align-bottom"]}),h.jsx(R,{...e["align-left"]}),h.jsx(R,{...e["align-center-horizontal"]}),h.jsx(R,{...e["align-right"]})]})]})}const Mte=x.memo(function({children:t}){const n=$e(),r=Rn(),o=t??h.jsx($te,{});return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{className:"tlui-shortcuts-dialog__header",children:[h.jsx(hg,{children:n("shortcuts-dialog.title")}),h.jsx(pg,{})]}),h.jsx(fu,{className:ue("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=mt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=mt.TABLET}),children:h.jsx(vr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),h.jsx("div",{className:"tlui-dialog__scrim"})]})});function Ate(){return h.jsxs(h.Fragment,{children:[h.jsx(Ote,{}),h.jsx(Fte,{}),h.jsx(jte,{}),h.jsx(Nte,{}),h.jsx(zte,{})]})}function jte(){const e=ce();return h.jsxs(br,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[h.jsxs(ye,{id:"export-all-as-group",children:[h.jsx(R,{...e["export-all-as-svg"]}),h.jsx(R,{...e["export-all-as-png"]}),h.jsx(R,{...e["export-all-as-json"]})]}),h.jsx(ye,{id:"export-all-as-bg",children:h.jsx(yw,{})})]})}function Ote(){const e=z(),t=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return h.jsxs(br,{id:"edit",label:"menu.edit",disabled:!t,children:[h.jsx(Lte,{}),h.jsx(cj,{}),h.jsx(lj,{}),h.jsx(Dte,{}),h.jsx(Rte,{}),h.jsx(ye,{id:"select-all",children:h.jsx(uj,{})})]})}function Dte(){return h.jsxs(ye,{id:"misc",children:[h.jsx(ej,{}),h.jsx(tj,{}),h.jsx(JA,{}),h.jsx(QA,{}),h.jsx(nj,{}),h.jsx(rj,{}),h.jsx(hj,{}),h.jsx(dj,{})]})}function Rte(){return h.jsxs(ye,{id:"lock",children:[h.jsx(oj,{}),h.jsx(Kee,{})]})}function Lte(){const e=ce(),t=ZT(),n=qT();return h.jsxs(ye,{id:"undo-redo",children:[h.jsx(R,{...e.undo,disabled:!t}),h.jsx(R,{...e.redo,disabled:!n})]})}function Fte(){const e=ce();return h.jsx(br,{id:"view",label:"menu.view",children:h.jsxs(ye,{id:"view-actions",children:[h.jsx(R,{...e["zoom-in"]}),h.jsx(R,{...e["zoom-out"]}),h.jsx(sj,{}),h.jsx(ij,{}),h.jsx(aj,{})]})})}function Nte(){const e=ce();return h.jsxs(ye,{id:"extras",children:[h.jsx(R,{...e["insert-embed"]}),h.jsx(R,{...e["insert-media"]})]})}function zte(){return h.jsx(ye,{id:"preferences",children:h.jsxs(br,{id:"preferences",label:"menu.preferences",children:[h.jsxs(ye,{id:"preferences-actions",children:[h.jsx(tte,{}),h.jsx(nte,{}),h.jsx(rte,{}),h.jsx(ote,{}),h.jsx(ste,{}),h.jsx(ite,{}),h.jsx(ate,{}),h.jsx(cte,{}),h.jsx(lte,{})]}),h.jsx(ye,{id:"language",children:h.jsx(fj,{})})]})})}const Bte=x.memo(function({children:t}){const n=cn(),[r,o]=Qs("main menu"),s=$e(),i=t??h.jsx(Ate,{});return h.jsxs(fw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(gw,{asChild:!0,dir:"ltr",children:h.jsx(pe,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:h.jsx(ke,{icon:"menu",small:!0})})}),h.jsx(xg,{container:n,children:h.jsx(mw,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:h.jsx(vr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),Ute=x.memo(function(){const t=Rn(),{MainMenu:n,QuickActions:r,ActionsMenu:o,PageMenu:s}=ti();return!n&&!s&&t<6?null:h.jsx("div",{className:"tlui-menu-zone",children:h.jsxs("div",{className:"tlui-buttons__horizontal",children:[n&&h.jsx(n,{}),s&&h.jsx(s,{}),t<6?null:h.jsxs(h.Fragment,{children:[r&&h.jsx(r,{}),o&&h.jsx(o,{})]})]})})}),hy={};function sl(e){if(hy[e])return hy[e];const n=document.createElement("canvas").getContext("2d");n.fillStyle=e,n.fillRect(0,0,1,1);const[r,o,s,i]=n.getImageData(0,0,1,1).data,a=new Float32Array([r/255,o/255,s/255,i/255]);return hy[e]=a,a}const rp=10,gj=4*6*rp+12+4*12;function fa(e,{center:t,radius:n,numArcSegments:r=20,startAngle:o=0,endAngle:s=Oe,offset:i=0}){const a=(s-o)/r;let c=i;for(let l=o;l<s;l+=a)e[c++]=t.x,e[c++]=t.y,e[c++]=t.x+Math.cos(l)*n,e[c++]=t.y+Math.sin(l)*n,e[c++]=t.x+Math.cos(l+a)*n,e[c++]=t.y+Math.sin(l+a)*n;return e}function ga(e,t,n,r,o,s){e[t++]=n,e[t++]=r,e[t++]=n,e[t++]=r+s,e[t++]=n+o,e[t++]=r,e[t++]=n+o,e[t++]=r,e[t++]=n,e[t++]=r+s,e[t++]=n+o,e[t++]=r+s}function Hte(e,t,n){const r=rp;n=Math.min(n,Math.min(t.w,t.h)/2);const o=ne.ExpandBy(t,-n);if(o.w<=0||o.h<=0)return fa(e,{center:t.center,radius:n,numArcSegments:rp*4}),rp*4*6;let s=0;return ga(e,s,o.minX,o.minY,o.w,o.h),s+=12,ga(e,s,o.minX,t.minY,o.w,n),s+=12,ga(e,s,o.maxX,o.minY,n,o.h),s+=12,ga(e,s,o.minX,o.maxY,o.w,n),s+=12,ga(e,s,t.minX,o.minY,n,o.h),s+=12,fa(e,{numArcSegments:r,offset:s,center:o.point,radius:n,startAngle:Pe,endAngle:Pe*1.5}),s+=r*6,fa(e,{numArcSegments:r,offset:s,center:P.Add(o.point,new P(o.w,0)),radius:n,startAngle:Pe*1.5,endAngle:Oe}),s+=r*6,fa(e,{numArcSegments:r,offset:s,center:P.Add(o.point,o.size),radius:n,startAngle:0,endAngle:ze}),s+=r*6,fa(e,{numArcSegments:r,offset:s,center:P.Add(o.point,new P(0,o.h)),radius:n,startAngle:ze,endAngle:Pe}),gj}function Kte(e){if(!e)throw new Error("Canvas element not found");const t=e.getContext("webgl2",{premultipliedAlpha:!1});if(!t)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
precision mediump float;
in vec2 shapeVertexPosition;
uniform vec4 canvasPageBounds;
// taken (with thanks) from
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
void main() {
// convert the position from pixels to 0.0 to 1.0
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
// convert from 0->1 to 0->2
vec2 zeroToTwo = zeroToOne * 2.0;
// convert from 0->2 to -1->+1 (clipspace)
vec2 clipSpace = zeroToTwo - 1.0;
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
}`,r=t.createShader(t.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const o=`#version 300 es
precision mediump float;
uniform vec4 fillColor;
out vec4 outputColor;
void main() {
outputColor = fillColor;
}`,s=t.createShader(t.FRAGMENT_SHADER);if(!s)throw new Error("Failed to create fragment shader");if(t.shaderSource(s,o),t.compileShader(s),!t.getShaderParameter(s,t.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=t.createProgram();if(!i)throw new Error("Failed to create program");if(t.attachShader(i,r),t.attachShader(i,s),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS))throw new Error("Failed to link program");t.useProgram(i);const a=t.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");t.enableVertexAttribArray(a);const c=t.getUniformLocation(i,"canvasPageBounds"),l=t.getUniformLocation(i,"fillColor");if(!t.createBuffer())throw new Error("Failed to create buffer");if(!t.createBuffer())throw new Error("Failed to create buffer");return{context:t,selectedShapes:Jd(t,1024),unselectedShapes:Jd(t,4096),viewport:Jd(t,gj),collaborators:Jd(t,1024),prepareTriangles(p,f){t.bindBuffer(t.ARRAY_BUFFER,p.buffer),t.bufferData(t.ARRAY_BUFFER,p.vertices,t.STATIC_DRAW,0,f),t.enableVertexAttribArray(a),t.vertexAttribPointer(a,2,t.FLOAT,!1,0,0)},drawTrianglesTransparently(p){t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.drawArrays(t.TRIANGLES,0,p/2),t.disable(t.BLEND)},drawTriangles(p){t.drawArrays(t.TRIANGLES,0,p/2)},setFillColor(p){t.uniform4fv(l,p)},setCanvasPageBounds(p){t.uniform4fv(c,p)}}}function Jd(e,t){const n=e.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(t)}}function uI(e,t,n){let r=e.vertices.length;for(;r<t+n.length;)r*=2;if(r!=e.vertices.length){const o=new Float32Array(r);o.set(e.vertices),e.vertices=o}e.vertices.set(n,t)}var Wte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,ei=(e,t,n,r)=>{for(var o=Vte(t,n),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(t,n,o)||o);return o&&Wte(t,n,o),o};class ss{constructor(t,n){m(this,"disposables",[]);m(this,"close",()=>this.disposables.forEach(t=>t()));m(this,"gl");m(this,"shapeGeometryCache");m(this,"colors");m(this,"id",et());m(this,"canvasBoundingClientRect",fn("canvasBoundingClientRect",new ne));m(this,"originPagePoint",new P);m(this,"originPageCenter",new P);m(this,"isInViewport",!1);m(this,"getMinimapPagePoint",(t,n)=>{const r=this.getCanvasPageBounds(),o=this.getCanvasScreenBounds();let s=t-o.x,i=n-o.y;return s*=r.width/o.width,i*=r.height/o.height,s+=r.minX,i+=r.minY,new P(s,i,1)});m(this,"minimapScreenPointToPagePoint",(t,n,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:c}=this.getMinimapPagePoint(t,n);if(o){const l=this.editor.getCurrentPageBounds()??new ne,u=i,d=l.minX-u.width/2,p=l.maxX+u.width/2,f=l.minY-u.height/2,y=l.maxY+u.height/2,g=Math.max(0,d+u.width-a),w=Math.max(0,-(p-u.width-a)),S=Math.max(0,f+u.height-c),v=Math.max(0,-(y-u.height-c)),b=Math.max(0,g-w),E=Math.max(0,w-g),C=Math.max(0,S-v),I=Math.max(0,v-S);b&&b>E?a+=b/2:E&&(a-=E/2),C&&C>I?c+=C/2:I&&(c-=I/2),a=Ns(a,d,p),c=Ns(c,f,y)}if(r){const{originPagePoint:l}=this,u=Math.abs(a-l.x),d=Math.abs(c-l.y);u>d?c=l.y:a=l.x}return new P(a,c)});m(this,"render",()=>{const t=this.gl.context,n=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=n.x,this.elem.height=n.y,t.viewport(0,0,n.x,n.y),t.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),t.clear(t.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),o=this.colors;let s=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let c=0,l=a.length;c<l;c++){const u=a[c],d=this.shapeGeometryCache.get(u);if(!d)continue;const p=d.length;r.has(u)?(uI(this.gl.selectedShapes,s,d),s+=p):(uI(this.gl.unselectedShapes,i,d),i+=p)}this.drawShapes(this.gl.unselectedShapes,i,o.shapeFill),this.drawShapes(this.gl.selectedShapes,s,o.selectFill),this.drawViewport(),this.drawCollaborators()});this.editor=t,this.elem=n,this.gl=Kte(n),this.shapeGeometryCache=t.store.createComputedCache("webgl-geometry",r=>{const o=t.getShapeMaskedPageBounds(r.id);if(!o)return null;const s=new Float32Array(12);return ga(s,0,o.x,o.y,o.w,o.h),s}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),Sc("minimap render",this.render))}_getColors(){const t=getComputedStyle(this.editor.getContainer());return{shapeFill:sl(t.getPropertyValue("--color-text-3").trim()),selectFill:sl(t.getPropertyValue("--color-selected").trim()),viewportFill:sl(t.getPropertyValue("--color-muted-1").trim()),background:sl(t.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const t=this.editor.getViewportPageBounds(),n=this.editor.getCurrentPageBounds();return n?ne.Expand(n,t):t}getContentScreenBounds(){const t=this.getContentPageBounds(),n=this.editor.pageToScreen(t.point),r=this.editor.pageToScreen(new P(t.maxX,t.maxY));return new ne(n.x,n.y,r.x-n.x,r.y-n.y)}_getCanvasBoundingRect(){const{x:t,y:n,width:r,height:o}=this.elem.getBoundingClientRect();return new ne(t,n,r,o)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const t=new ResizeObserver(()=>{const n=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(n)});return t.observe(this.elem),()=>t.disconnect()}getCanvasSize(){const t=this.canvasBoundingClientRect.get(),n=this.getDpr();return new P(t.width*n,t.height*n)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const t=this.getCanvasScreenBounds(),n=this.getContentPageBounds(),r=t.width/t.height;let o=n.width,s=o/r;s<n.height&&(s=n.height,o=s*r);const i=new ne(0,0,o,s);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:t,y:n,w:r,h:o}=this.getCanvasPageBounds();return new Float32Array([t,n,r,o])}drawShapes(t,n,r){this.gl.prepareTriangles(t,n),this.gl.setFillColor(r),this.gl.drawTriangles(n)}drawViewport(){const t=this.editor.getViewportPageBounds(),n=Hte(this.gl.viewport.vertices,t,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,n),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(n)}drawCollaborators(){const t=this.editor.getCollaboratorsOnCurrentPage();if(!t.length)return;const n=20,r=n*6,o=r*t.length;this.gl.collaborators.vertices.length<o&&(this.gl.collaborators.vertices=new Float32Array(o));const s=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:c}of t)fa(s,{center:P.From(c),radius:3*a,offset:i,numArcSegments:n}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,o),i=0;for(const{color:c}of t)this.gl.setFillColor(sl(c)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}ei([V],ss.prototype,"getDpr");ei([V],ss.prototype,"getContentPageBounds");ei([V],ss.prototype,"getContentScreenBounds");ei([V],ss.prototype,"getCanvasSize");ei([V],ss.prototype,"getCanvasClientPosition");ei([V],ss.prototype,"getCanvasPageBounds");ei([V],ss.prototype,"getZoom");ei([V],ss.prototype,"getCanvasPageBoundsArray");function Gte(){const e=z(),t=x.useRef(null),n=x.useRef(!1),r=x.useRef();x.useEffect(()=>{const l=new ss(e,t.current);return r.current=l,r.current.close},[e]);const o=x.useCallback(l=>{if(!e.getCurrentPageShapeIds().size||!r.current)return;const u=r.current.minimapScreenPointToPagePoint(l.clientX,l.clientY,!1,!1),d=r.current.minimapScreenPointToPagePoint(l.clientX,l.clientY,!1,!0);r.current.originPagePoint.setTo(d),r.current.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(u,{duration:Qr})},[e]),s=x.useCallback(l=>{if(!r.current)return;const u=l.currentTarget;if(Mu(u,l),!e.getCurrentPageShapeIds().size)return;n.current=!0,r.current.isInViewport=!1;const d=r.current.minimapScreenPointToPagePoint(l.clientX,l.clientY,!1,!1),p=r.current.minimapScreenPointToPagePoint(l.clientX,l.clientY,!1,!0),f=e.getViewportPageBounds();if(r.current.isInViewport=f.containsPoint(p),r.current.isInViewport)r.current.originPagePoint.setTo(p),r.current.originPageCenter.setTo(f.center);else{const g=P.Sub(f.center,f.point),w=P.Add(d,g);r.current.originPagePoint.setTo(w),r.current.originPageCenter.setTo(d),e.centerOnPoint(d,{duration:Qr})}function y(g){u&&Au(u,g),n.current=!1,document.body.removeEventListener("pointerup",y)}document.body.addEventListener("pointerup",y)},[e]),i=x.useCallback(l=>{if(!r.current)return;const u=r.current.minimapScreenPointToPagePoint(l.clientX,l.clientY,l.shiftKey,!0);if(n.current){if(r.current.isInViewport){const y=r.current.originPagePoint.clone().sub(r.current.originPageCenter);e.centerOnPoint(P.Sub(u,y));return}e.centerOnPoint(u)}const d=r.current.getMinimapPagePoint(l.clientX,l.clientY),p=e.pageToScreen(d),f={type:"pointer",target:"canvas",name:"pointer_move",..._n(l),point:p,isPen:e.getInstanceState().isPenMode};e.dispatch(f)},[e]),a=x.useCallback(l=>{const u=r2(l);e.dispatch({type:"wheel",name:"wheel",delta:u,point:new P(l.clientX,l.clientY),shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey})},[e]),c=Ru();return x.useEffect(()=>{setTimeout(()=>{var l,u;(l=r.current)==null||l.updateColors(),(u=r.current)==null||u.render()})},[c]),h.jsx("div",{className:"tlui-minimap",children:h.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:o,onPointerMove:i,onPointerDown:s,onWheel:a})})}function Yte(e,t){const[n,r]=Se.useState(t);Se.useLayoutEffect(()=>{const s=D0(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=Se.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return R0(e,JSON.stringify(a)),a})},[e]);return[n,o]}const Xte=x.memo(function(){const t=ce(),n=$e(),r=Rn(),[o,s]=Yte("minimap",!0),i=x.useCallback(()=>{s(l=>!l)},[s]),{ZoomMenu:a,Minimap:c}=ti();return r<mt.MOBILE?null:h.jsxs("div",{className:"tlui-navigation-panel",children:[h.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<mt.TABLET?h.jsx(a,{}):o?h.jsxs(h.Fragment,{children:[a&&h.jsx(a,{}),c&&h.jsx(pe,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(ke,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):h.jsxs(h.Fragment,{children:[h.jsx(pe,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(gu(t["zoom-out"].label))} ${Av(t["zoom-out"].kbd)}`,onClick:()=>t["zoom-out"].onSelect("navigation-zone"),children:h.jsx(ke,{icon:"minus"})}),a&&h.jsx(a,{}),h.jsx(pe,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(gu(t["zoom-in"].label))} ${Av(t["zoom-in"].kbd)}`,onClick:()=>t["zoom-in"].onSelect("navigation-zone"),children:h.jsx(ke,{icon:"plus"})}),c&&h.jsx(pe,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(ke,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=mt.TABLET&&!o&&h.jsx(c,{})]})}),qte=function({name:t,id:n,isCurrentPage:r}){const o=z(),s=x.useRef(null),i=x.useCallback(c=>{o.renamePage(n,c||"New Page",{ephemeral:!0})},[o,n]),a=x.useCallback(c=>{o.mark("rename page"),o.renamePage(n,c||"New Page",{ephemeral:!1})},[o,n]);return h.jsx(qx,{className:"tlui-page-menu__item__input",ref:c=>s.current=c,defaultValue:t,onValueChange:i,onComplete:a,onCancel:a,shouldManuallyMaintainScrollPositionWhenFocused:!0,autofocus:r,autoselect:!0})},Ov=(e,t,n,r)=>{let o;const s=e.getPages(),i=n>r?s[r-1]:s[r],a=n>r?s[r]:s[r+1];i&&!a?o=$o(i.index):!i&&a?o=F3(s[0].index):o=kl(i.index,a.index),o!==s[n].index&&(e.mark("moving page"),e.updatePage({id:t,index:o}))},dI=or(function({index:t,listSize:n,item:r,onRename:o}){const s=z(),i=$e(),a=s.getPages(),c=x.useCallback(()=>{s.mark("creating page");const p=Ho.createId();s.duplicatePage(r.id,p)},[s,r]),l=x.useCallback(()=>{Ov(s,r.id,t,t-1)},[s,r,t]),u=x.useCallback(()=>{Ov(s,r.id,t,t+1)},[s,r,t]),d=x.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return h.jsxs(Li,{id:`page item submenu ${t}`,children:[h.jsx(Fi,{children:h.jsx(pe,{type:"icon",title:i("page-menu.submenu.title"),children:h.jsx(ke,{icon:"dots-vertical"})})}),h.jsx(Ni,{alignOffset:0,side:"right",sideOffset:-4,children:h.jsxs(vr,{type:"menu",sourceId:"page-menu",children:[h.jsxs(ye,{id:"modify",children:[o&&h.jsx(R,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),h.jsx(R,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=Gp}),t>0&&h.jsx(R,{id:"move-up",onSelect:l,label:"page-menu.submenu.move-up"}),t<n-1&&h.jsx(R,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),n>1&&h.jsx(ye,{id:"delete",children:h.jsx(R,{id:"delete",onSelect:d,label:"page-menu.submenu.delete"})})]})})]})}),Zte=x.memo(function(){const t=z(),n=$e(),r=Rn(),o=x.useCallback(()=>w(!1),[]),[s,i]=Qs("page-menu",o),a=36,c=x.useRef(null),l=K("pages",()=>t.getPages(),[t]),u=K("currentPage",()=>t.getCurrentPage(),[t]),d=K("currentPageId",()=>t.getCurrentPageId(),[t]),p=ns(),f=K("maxPageCountReached",()=>t.getPages().length>=Gp,[t]),y=K("isCoarsePointer",()=>t.getInstanceState().isCoarsePointer,[t]),[g,w]=x.useState(!1),S=x.useCallback(()=>{p||w(T=>!T)},[p]),v=x.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[b,E]=x.useState(Object.fromEntries(l.map((T,O)=>[T.id,{y:O*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{E(Object.fromEntries(l.map((T,O)=>[T.id,{y:O*a,offsetY:0,isSelected:!1}])))},[a,l]),x.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const O=c.current;if(!O)return;const N=T.offsetTop,F=O.scrollTop;N<F&&O.scrollTo({top:N});const L=N+a,B=O.scrollTop+O.offsetHeight;L>B&&O.scrollTo({top:L-O.offsetHeight})}})},[a,d,s]);const C=x.useCallback(T=>{const{clientY:O,currentTarget:N}=T,{dataset:{id:F,index:L}}=N;if(!F||!L)return;const B=v.current;Mu(T.currentTarget,T),B.status="pointing",B.pointing={id:F,index:+L};const Q=b[F].y;B.startY=O,B.startIndex=Math.max(0,Math.min(Math.round(Q/a),l.length-1))},[a,l.length,b]),I=x.useCallback(T=>{const O=v.current;if(O.status==="pointing"){const{clientY:N}=T,F=N-O.startY;Math.abs(F)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:N}=T,F=N-O.startY,L=b[O.pointing.id],{startIndex:B,pointing:q}=O,Q=L.y+F,H=Math.max(0,Math.min(Math.round(Q/a),l.length-1)),U={...b};if(U[q.id]={y:L.y,offsetY:F,isSelected:!0},H!==O.dragIndex){O.dragIndex=H;for(let W=0;W<l.length;W++){const Z=l[W];if(Z.id===O.pointing.id)continue;let{y:le}=U[Z.id];H===B?le=W*a:H<B?H<=W&&W<B?le=(W+1)*a:le=W*a:H>B&&(H>=W&&W>B?le=(W-1)*a:le=W*a),le!==U[Z.id].y&&(U[Z.id]={y:le,offsetY:0,isSelected:!0})}}E(U)}},[a,l,b]),_=x.useCallback(T=>{const O=v.current;if(O.status==="dragging"){const{id:N,index:F}=O.pointing;Ov(t,N,F,O.dragIndex)}Au(T.currentTarget,T),O.status="idle"},[t]),k=x.useCallback(T=>{const O=v.current;T.key==="Escape"&&(O.status==="dragging"&&E(Object.fromEntries(l.map((N,F)=>[N.id,{y:F*a,offsetY:0,isSelected:!1}]))),O.status="idle")},[a,l]),$=x.useCallback(()=>{p||t.batch(()=>{t.mark("creating page");const T=Ho.createId();t.createPage({name:n("page-menu.new-page-initial-name"),id:T}),t.setCurrentPage(T),w(!0)})},[t,n,p]);return h.jsxs(aw,{id:"pages",onOpenChange:i,open:s,children:[h.jsx(cw,{"data-testid":"main.page-menu",children:h.jsxs(pe,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[h.jsx("div",{className:"tlui-page-menu__name",children:u.name}),h.jsx(ke,{icon:"chevron-down",small:!0})]})}),h.jsx(lw,{side:"bottom",align:"start",sideOffset:6,children:h.jsxs("div",{className:"tlui-page-menu__wrapper",children:[h.jsxs("div",{className:"tlui-page-menu__header",children:[h.jsx("div",{className:"tlui-page-menu__header__title",children:n("page-menu.title")}),!p&&h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsx(pe,{type:"icon","data-testid":"page-menu.edit",title:n(g?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:h.jsx(ke,{icon:g?"check":"edit"})}),h.jsx(pe,{type:"icon","data-testid":"page-menu.create",title:n(f?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:f,onClick:$,children:h.jsx(ke,{icon:"plus"})})]})]}),h.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*l.length+4},ref:c,children:l.map((T,O)=>{const N=b[T.id]??{position:O*40,offsetY:0};return g?h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===u.id?888:O,transform:`translate(0px, ${N.y+N.offsetY}px)`},children:[h.jsx(pe,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:C,onPointerUp:_,onPointerMove:I,onKeyDown:k,"data-id":T.id,"data-index":O,children:h.jsx(ke,{icon:"drag-handle-dots"})}),r<mt.TABLET_SM&&y?h.jsxs(pe,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const F=window.prompt("Rename page",T.name);F&&F!==T.name&&t.renamePage(T.id,F)},onDoubleClick:S,children:[h.jsx(jv,{checked:T.id===u.id}),h.jsx(vt,{children:T.name})]}):h.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:h.jsx(qte,{id:T.id,name:T.name,isCurrentPage:T.id===u.id})}),!p&&h.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":g,children:h.jsx(dI,{index:O,item:T,listSize:l.length})})]},T.id+"_editing"):h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[h.jsxs(pe,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>t.setCurrentPage(T.id),onDoubleClick:S,title:n("page-menu.go-to-page"),children:[h.jsx(jv,{checked:T.id===u.id}),h.jsx(vt,{children:T.name})]}),!p&&h.jsx("div",{className:"tlui-page_menu__item__submenu",children:h.jsx(dI,{index:O,item:T,listSize:l.length,onRename:()=>{if(t.environment.isIos){const F=window.prompt("Rename page",T.name);F&&F!==T.name&&t.renamePage(T.id,F)}else t.batch(()=>{w(!0),t.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function Qte(){const e=ce(),t=z(),n=ZT(),r=qT(),o=wn(1),s=ns(),i=K("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]);if(!(s&&!i))return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e.undo,disabled:!n}),h.jsx(R,{...e.redo,disabled:!r}),h.jsx(R,{...e.delete,disabled:!o}),h.jsx(R,{...e.duplicate,disabled:!o})]})}const Jte=x.memo(function({children:t}){const n=t??h.jsx(Qte,{});return h.jsx(vr,{type:"small-icons",sourceId:"quick-actions",children:n})}),ene=Object.freeze([tr,Ti,sc,co]);function mj(e=ene){const t=z();return K("getRelevantStyles",()=>{var s;const n=new KS(t.getSharedStyles()),r=!!((s=t.root.getCurrent())!=null&&s.shapeType),o=t.isIn("select")&&t.getSelectedShapeIds().length>0;if(n.size===0&&t.isIn("select")&&t.getSelectedShapeIds().length===0)for(const i of e)n.applyValue(i,t.getStyleForNextShape(i));return r||o||n.size>0?n:null},[t])}const Or={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"}],horizontalAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-center"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"cloud",icon:"geo-cloud"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"star",icon:"geo-star"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"}],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"}]};function tne(e){const{uiType:t,items:n,title:r,style:o,value:s,onValueChange:i,theme:a}=e,c=z(),l=$e(),u=x.useRef(!1),{handleButtonClick:d,handleButtonPointerDown:p,handleButtonPointerEnter:f,handleButtonPointerUp:y}=x.useMemo(()=>{const g=()=>{u.current=!1,window.removeEventListener("pointerup",g)};return{handleButtonClick:E=>{const{id:C}=E.currentTarget.dataset;s.type==="shared"&&s.value===C||(c.mark("point picker item"),i(o,C,!1))},handleButtonPointerDown:E=>{const{id:C}=E.currentTarget.dataset;c.mark("point picker item"),i(o,C,!0),u.current=!0,window.addEventListener("pointerup",g)},handleButtonPointerEnter:E=>{if(!u.current)return;const{id:C}=E.currentTarget.dataset;i(o,C,!0)},handleButtonPointerUp:E=>{const{id:C}=E.currentTarget.dataset;s.type==="shared"&&s.value===C||i(o,C,!1)}}},[s,c,i,o]);return h.jsx("div",{"data-testid":`style.${t}`,className:ue("tlui-buttons__grid"),children:n.map(g=>h.jsx(pe,{type:"icon","data-id":g.value,"data-testid":`style.${t}.${g.value}`,"aria-label":g.value,"data-state":s.type==="shared"&&s.value===g.value?"hinted":void 0,title:r+" — "+l(`${t}-style.${g.value}`),className:ue("tlui-button-grid__button"),style:o===tr?{color:a[g.value].solid}:void 0,onPointerEnter:f,onPointerDown:p,onPointerUp:y,onClick:d,children:h.jsx(ke,{icon:g.icon})},g.value))})}const Ra=x.memo(tne);function yj(e,[t,n]){return Math.min(n,Math.max(t,e))}function nne(e){const t=x.useRef({value:e,previous:e});return x.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}const Sj=["PageUp","PageDown"],vj=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],xj={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Ku="Slider",[Dv,rne,one]=og(Ku),[wj,$oe]=mo(Ku,[one]),[sne,wg]=wj(Ku),ine=x.forwardRef((e,t)=>{const{name:n,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:l=[r],value:u,onValueChange:d=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...y}=e,[g,w]=x.useState(null),S=Xe(t,L=>w(L)),v=x.useRef(new Set),b=x.useRef(0),E=i==="horizontal",C=g?!!g.closest("form"):!0,I=E?ane:cne,[_=[],k]=Zs({prop:u,defaultProp:l,onChange:L=>{var B;(B=[...v.current][b.current])===null||B===void 0||B.focus(),d(L)}}),$=x.useRef(_);function T(L){const B=yne(_,L);F(L,B)}function O(L){F(L,b.current)}function N(){const L=$.current[b.current];_[b.current]!==L&&p(_)}function F(L,B,{commit:q}={commit:!1}){const Q=wne(s),H=bne(Math.round((L-r)/s)*s+r,Q),U=yj(H,[r,o]);k((W=[])=>{const Z=gne(W,U,B);if(xne(Z,c*s)){b.current=Z.indexOf(U);const le=String(Z)!==String(W);return le&&q&&p(Z),le?Z:W}else return W})}return x.createElement(sne,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:b,thumbs:v.current,values:_,orientation:i},x.createElement(Dv.Provider,{scope:e.__scopeSlider},x.createElement(Dv.Slot,{scope:e.__scopeSlider},x.createElement(I,X({"aria-disabled":a,"data-disabled":a?"":void 0},y,{ref:S,onPointerDown:ie(y.onPointerDown,()=>{a||($.current=_)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:T,onSlideMove:a?void 0:O,onSlideEnd:a?void 0:N,onHomeKeyDown:()=>!a&&F(r,0,{commit:!0}),onEndKeyDown:()=>!a&&F(o,_.length-1,{commit:!0}),onStepKeyDown:({event:L,direction:B})=>{if(!a){const H=Sj.includes(L.key)||L.shiftKey&&vj.includes(L.key)?10:1,U=b.current,W=_[U],Z=s*H*B;F(W+Z,U,{commit:!0})}}})))),C&&_.map((L,B)=>x.createElement(fne,{key:B,name:n?n+(_.length>1?"[]":""):void 0,value:L})))}),[bj,Pj]=wj(Ku,{startEdge:"left",endEdge:"right",size:"width",direction:1}),ane=x.forwardRef((e,t)=>{const{min:n,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:c,onStepKeyDown:l,...u}=e,[d,p]=x.useState(null),f=Xe(t,b=>p(b)),y=x.useRef(),g=uw(o),w=g==="ltr",S=w&&!s||!w&&s;function v(b){const E=y.current||d.getBoundingClientRect(),C=[0,E.width],_=Sw(C,S?[n,r]:[r,n]);return y.current=E,_(b-E.left)}return x.createElement(bj,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width"},x.createElement(Cj,X({dir:g,"data-orientation":"horizontal"},u,{ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const E=v(b.clientX);i==null||i(E)},onSlideMove:b=>{const E=v(b.clientX);a==null||a(E)},onSlideEnd:()=>{y.current=void 0,c==null||c()},onStepKeyDown:b=>{const C=xj[S?"from-left":"from-right"].includes(b.key);l==null||l({event:b,direction:C?-1:1})}})))}),cne=x.forwardRef((e,t)=>{const{min:n,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:c,...l}=e,u=x.useRef(null),d=Xe(t,u),p=x.useRef(),f=!o;function y(g){const w=p.current||u.current.getBoundingClientRect(),S=[0,w.height],b=Sw(S,f?[r,n]:[n,r]);return p.current=w,b(g-w.top)}return x.createElement(bj,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1},x.createElement(Cj,X({"data-orientation":"vertical"},l,{ref:d,style:{...l.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const w=y(g.clientY);s==null||s(w)},onSlideMove:g=>{const w=y(g.clientY);i==null||i(w)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:g=>{const S=xj[f?"from-bottom":"from-top"].includes(g.key);c==null||c({event:g,direction:S?-1:1})}})))}),Cj=x.forwardRef((e,t)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:c,...l}=e,u=wg(Ku,n);return x.createElement(Ke.span,X({},l,{ref:t,onKeyDown:ie(e.onKeyDown,d=>{d.key==="Home"?(i(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):Sj.concat(vj).includes(d.key)&&(c(d),d.preventDefault())}),onPointerDown:ie(e.onPointerDown,d=>{const p=d.target;p.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(p)?p.focus():r(d)}),onPointerMove:ie(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:ie(e.onPointerUp,d=>{const p=d.target;p.hasPointerCapture(d.pointerId)&&(p.releasePointerCapture(d.pointerId),s(d))})}))}),lne="SliderTrack",une=x.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=wg(lne,n);return x.createElement(Ke.span,X({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:t}))}),hI="SliderRange",dne=x.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=wg(hI,n),s=Pj(hI,n),i=x.useRef(null),a=Xe(t,i),c=o.values.length,l=o.values.map(p=>Ij(p,o.min,o.max)),u=c>1?Math.min(...l):0,d=100-Math.max(...l);return x.createElement(Ke.span,X({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:d+"%"}}))}),pI="SliderThumb",hne=x.forwardRef((e,t)=>{const n=rne(e.__scopeSlider),[r,o]=x.useState(null),s=Xe(t,a=>o(a)),i=x.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return x.createElement(pne,X({},e,{ref:s,index:i}))}),pne=x.forwardRef((e,t)=>{const{__scopeSlider:n,index:r,...o}=e,s=wg(pI,n),i=Pj(pI,n),[a,c]=x.useState(null),l=Xe(t,w=>c(w)),u=aA(a),d=s.values[r],p=d===void 0?0:Ij(d,s.min,s.max),f=mne(r,s.values.length),y=u==null?void 0:u[i.size],g=y?Sne(y,p,i.direction):0;return x.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${p}% + ${g}px)`}},x.createElement(Dv.ItemSlot,{scope:e.__scopeSlider},x.createElement(Ke.span,X({role:"slider","aria-label":e["aria-label"]||f,"aria-valuemin":s.min,"aria-valuenow":d,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:l,style:d===void 0?{display:"none"}:e.style,onFocus:ie(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),fne=e=>{const{value:t,...n}=e,r=x.useRef(null),o=nne(t);return x.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==t&&c){const l=new Event("input",{bubbles:!0});c.call(s,t),s.dispatchEvent(l)}},[o,t]),x.createElement("input",X({style:{display:"none"}},n,{ref:r,defaultValue:t}))};function gne(e=[],t,n){const r=[...e];return r[n]=t,r.sort((o,s)=>o-s)}function Ij(e,t,n){const s=100/(n-t)*(e-t);return yj(s,[0,100])}function mne(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function yne(e,t){if(e.length===1)return 0;const n=e.map(o=>Math.abs(o-t)),r=Math.min(...n);return n.indexOf(r)}function Sne(e,t,n){const r=e/2,s=Sw([0,50],[0,r]);return(r-s(t)*n)*n}function vne(e){return e.slice(0,-1).map((t,n)=>e[n+1]-t)}function xne(e,t){if(t>0){const n=vne(e);return Math.min(...n)>=t}return!0}function Sw(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function wne(e){return(String(e).split(".")[1]||"").length}function bne(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}const Pne=ine,Cne=une,Ine=dne,Ene=hne,_ne=x.memo(function(t){const{title:n,steps:r,value:o,label:s,onValueChange:i}=t,a=z(),c=$e(),l=x.useCallback(p=>{i(p[0],!0)},[i]),u=x.useCallback(()=>{a.mark("click slider")},[a]),d=x.useCallback(()=>{o&&i(o,!1)},[o,i]);return h.jsx("div",{className:"tlui-slider__container",children:h.jsxs(Pne,{"data-testid":t["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:l,onPointerUp:d,title:n+" — "+c(s),children:[h.jsx(Cne,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&h.jsx(Ine,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&h.jsx(Ene,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function kne({label:e,uiTypeA:t,uiTypeB:n,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:c,valueA:l,valueB:u,onValueChange:d}){const p=$e(),f=x.useMemo(()=>{var g;return((g=s.find(w=>l.type==="shared"&&l.value===w.value))==null?void 0:g.icon)??"mixed"},[s,l]),y=x.useMemo(()=>{var g;return((g=i.find(w=>u.type==="shared"&&u.value===w.value))==null?void 0:g.icon)??"mixed"},[i,u]);return l===void 0&&u===void 0?null:h.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[h.jsx("div",{title:p(e),className:"tlui-style-panel__double-select-picker-label",children:p(e)}),h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsxs(Li,{id:`style panel ${t} A`,children:[h.jsx(Fi,{children:h.jsx(pe,{type:"icon","data-testid":`style.${t}`,title:p(r)+" — "+(l===null||l.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${l.value}`)),children:h.jsx(ke,{icon:f,small:!0,invertIcon:!0})})}),h.jsx(Ni,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:h.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,w)=>h.jsx(wu,{"data-testid":`style.${t}.${g.value}`,children:h.jsx(pe,{type:"icon",onClick:()=>d(a,g.value,!1),title:`${p(r)} — ${p(`${t}-style.${g.value}`)}`,children:h.jsx(ke,{icon:g.icon,invertIcon:!0})},g.value)},w))})})]}),h.jsxs(Li,{id:`style panel ${n}`,children:[h.jsx(Fi,{children:h.jsx(pe,{type:"icon","data-testid":`style.${n}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${n}-style.${u.value}`)),children:h.jsx(ke,{icon:y,small:!0})})}),h.jsx(Ni,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:h.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>h.jsx(wu,{children:h.jsx(pe,{type:"icon",title:`${p(o)} — ${p(`${n}-style.${g.value}`)}`,"data-testid":`style.${n}.${g.value}`,onClick:()=>d(c,g.value,!1),children:h.jsx(ke,{icon:g.icon})})},g.value))})})]})]})]})}const Tne=x.memo(kne);function $ne({id:e,label:t,uiType:n,style:r,items:o,type:s,value:i,onValueChange:a}){const c=$e(),l=z(),u=x.useMemo(()=>{var f;return(f=o.find(y=>i.type==="shared"&&y.value===i.value))==null?void 0:f.icon},[o,i]),d=i.type==="mixed"?c("style-panel.mixed"):c(`${n}-style.${i.value}`),p=t?c(t):"";return h.jsxs(Li,{id:`style panel ${e}`,children:[h.jsx(Fi,{children:h.jsxs(pe,{type:s,"data-testid":`style.${n}`,title:d,children:[h.jsx(vt,{children:p}),h.jsx(ke,{icon:u??"mixed"})]})}),h.jsx(Ni,{side:"left",align:"center",alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>h.jsx(wu,{children:h.jsx(pe,{type:"icon","data-testid":`style.${n}.${f.value}`,title:c(`${n}-style.${f.value}`),onClick:()=>{l.mark("select style dropdown item"),a(r,f.value,!1)},children:h.jsx(ke,{icon:f.icon})})},f.value))})})]})}const vw=x.memo($ne);function Mne({styles:e}){const t=Ru();if(!e)return null;const n=e.get(oo),r=e.get(Bp),o=e.get(zp),s=e.get(Hp),i=e.get(ao),a=n===void 0,c=r===void 0&&o===void 0,l=s===void 0,u=i===void 0,d=Jo({isDarkMode:t});return h.jsxs(h.Fragment,{children:[h.jsx(Ane,{theme:d,styles:e}),!u&&h.jsx(jne,{theme:d,styles:e}),!(a&&c&&l)&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[h.jsx(One,{styles:e}),h.jsx(Rne,{styles:e}),h.jsx(Dne,{styles:e})]})]})}function Wu(){const e=z(),t=So();return Se.useMemo(()=>function(r,o,s){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,o,{squashing:s}),e.setStyleForNextShapes(r,o,{squashing:s}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),t("set-style",{source:"style-panel",id:r.id,value:o})},[e,t])}function Ane({styles:e,theme:t}){const n=$e(),r=z(),o=Wu(),s=e.get(tr),i=e.get(sc),a=e.get(Ti),c=e.get(co),l=i!==void 0||a!==void 0||c!==void 0;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:h.jsx(Ra,{title:n("style-panel.color"),uiType:"color",style:tr,items:Or.color,value:s,onValueChange:o,theme:t}),h.jsx(Lne,{})]}),l&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:h.jsx(Ra,{title:n("style-panel.fill"),uiType:"fill",style:sc,items:Or.fill,value:i,onValueChange:o,theme:t}),a===void 0?null:h.jsx(Ra,{title:n("style-panel.dash"),uiType:"dash",style:Ti,items:Or.dash,value:a,onValueChange:o,theme:t}),c===void 0?null:h.jsx(Ra,{title:n("style-panel.size"),uiType:"size",style:co,items:Or.size,value:c,onValueChange:(u,d,p)=>{o(u,d,p);const f=r.getSelectedShapeIds();f.length>0&&We(r,f)},theme:t})]})]})}function jne({theme:e,styles:t}){const n=$e(),r=Wu(),o=t.get(ao),s=t.get(ru),i=t.get(Up);return o===void 0&&s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:h.jsx(Ra,{title:n("style-panel.font"),uiType:"font",style:ao,items:Or.font,value:o,onValueChange:r,theme:e}),s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(Ra,{title:n("style-panel.align"),uiType:"align",style:ru,items:Or.horizontalAlign,value:s,onValueChange:r,theme:e}),h.jsx("div",{className:"tlui-style-panel__row__extra-button",children:i===void 0?h.jsx(pe,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:h.jsx(ke,{icon:"vertical-align-center"})}):h.jsx(vw,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:Up,items:Or.verticalAlign,value:i,onValueChange:r})})]})]})}function One({styles:e}){const t=Wu(),n=e.get(oo);return n===void 0?null:h.jsx(vw,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:oo,items:Or.geo,value:n,onValueChange:t})}function Dne({styles:e}){const t=Wu(),n=e.get(Hp);return n===void 0?null:h.jsx(vw,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:Hp,items:Or.spline,value:n,onValueChange:t})}function Rne({styles:e}){const t=Wu(),n=e.get(Bp),r=e.get(zp);return!n||!r?null:h.jsx(Tne,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:zp,itemsA:Or.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Bp,itemsB:Or.arrowheadEnd,valueB:n,onValueChange:t,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const il=[.1,.25,.5,.75,1];function Lne(){const e=z(),t=K("opacity",()=>e.getSharedOpacity(),[e]),n=So(),r=$e(),o=Se.useCallback((i,a)=>{const c=il[i];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(c,{squashing:a}),e.setOpacityForNextShapes(c,{squashing:a}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),n("set-style",{source:"style-panel",id:"opacity",value:i})},[e,n]);if(t===void 0)return null;const s=t.type==="mixed"?-1:il.indexOf(M3(il,i=>Math.abs(i-t.value)));return h.jsx(_ne,{"data-testid":"style.opacity",value:s>=0?s:il.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:o,steps:il.length-1,title:r("style-panel.opacity")})}const Fne=x.memo(function({isMobile:t,children:n}){const r=z(),o=mj(),s=x.useCallback(()=>{t||r.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[r,t]),i=n??h.jsx(Mne,{styles:o});return h.jsx("div",{className:ue("tlui-style-panel",{"tlui-style-panel__wrapper":!t}),"data-ismobile":t,onPointerLeave:s,children:i})});function Nne(){const e=z(),t=$e(),n=mj(),r=n==null?void 0:n.get(tr),o=Jo({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=K("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(l=>{l||e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[e]),{StylePanel:c}=ti();return c?h.jsxs(aw,{id:"mobile style menu",onOpenChange:a,children:[h.jsx(cw,{children:h.jsx(pe,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:t("style-panel.title"),disabled:i,children:h.jsx(ke,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),h.jsx(lw,{side:"top",align:"end",children:c&&h.jsx(c,{isMobile:!0})})]}):null}function zne(){return h.jsxs(h.Fragment,{children:[h.jsx(Bne,{}),h.jsx(Une,{}),h.jsx(Hne,{}),h.jsx(Kne,{}),h.jsx(Wne,{}),h.jsx(Vne,{}),h.jsx(Gne,{}),h.jsx(Yne,{}),h.jsx(Xne,{}),h.jsx(qne,{}),h.jsx(Zne,{}),h.jsx(Qne,{}),h.jsx(Jne,{}),h.jsx(ere,{}),h.jsx(tre,{}),h.jsx(nre,{}),h.jsx(rre,{}),h.jsx(ore,{}),h.jsx(sre,{}),h.jsx(ire,{}),h.jsx(are,{}),h.jsx(cre,{}),h.jsx(lre,{}),h.jsx(ure,{}),h.jsx(dre,{}),h.jsx(hre,{}),h.jsx(pre,{}),h.jsx(fre,{})]})}function Ue(e){var r;const t=z(),n=(r=e.meta)==null?void 0:r.geo;return K("is tool selected",()=>{const o=t.getCurrentToolId(),s=t.getSharedStyles().getAsKnownValue(oo);return n?o==="geo"&&s===n:o===e.id},[t,e.id,n])}function Bne(){const e=De(),t=Ue(e.select);return h.jsx(R,{...e.select,isSelected:t})}function Une(){const e=De(),t=Ue(e.hand);return h.jsx(R,{...e.hand,isSelected:t})}function Hne(){const e=De(),t=Ue(e.draw);return h.jsx(R,{...e.draw,isSelected:t})}function Kne(){const e=De(),t=Ue(e.eraser);return h.jsx(R,{...e.eraser,isSelected:t})}function Wne(){const e=De(),t=Ue(e.arrow);return h.jsx(R,{...e.arrow,isSelected:t})}function Vne(){const e=De(),t=Ue(e.text);return h.jsx(R,{...e.text,isSelected:t})}function Gne(){const e=De(),t=Ue(e.note);return h.jsx(R,{...e.note,isSelected:t})}function Yne(){const e=De(),t=Ue(e.asset);return h.jsx(R,{...e.asset,isSelected:t})}function Xne(){const e=De(),t=Ue(e.rectangle);return h.jsx(R,{...e.rectangle,isSelected:t})}function qne(){const e=De(),t=Ue(e.ellipse);return h.jsx(R,{...e.ellipse,isSelected:t})}function Zne(){const e=De(),t=Ue(e.diamond);return h.jsx(R,{...e.diamond,isSelected:t})}function Qne(){const e=De(),t=Ue(e.triangle);return h.jsx(R,{...e.triangle,isSelected:t})}function Jne(){const e=De(),t=Ue(e.trapezoid);return h.jsx(R,{...e.trapezoid,isSelected:t})}function ere(){const e=De(),t=Ue(e.rhombus);return h.jsx(R,{...e.rhombus,isSelected:t})}function tre(){const e=De(),t=Ue(e.hexagon);return h.jsx(R,{...e.hexagon,isSelected:t})}function nre(){const e=De(),t=Ue(e.cloud);return h.jsx(R,{...e.cloud,isSelected:t})}function rre(){const e=De(),t=Ue(e.star);return h.jsx(R,{...e.star,isSelected:t})}function ore(){const e=De(),t=Ue(e.oval);return h.jsx(R,{...e.oval,isSelected:t})}function sre(){const e=De(),t=Ue(e["x-box"]);return h.jsx(R,{...e["x-box"],isSelected:t})}function ire(){const e=De(),t=Ue(e["check-box"]);return h.jsx(R,{...e["check-box"],isSelected:t})}function are(){const e=De(),t=Ue(e["arrow-left"]);return h.jsx(R,{...e["arrow-left"],isSelected:t})}function cre(){const e=De(),t=Ue(e["arrow-up"]);return h.jsx(R,{...e["arrow-up"],isSelected:t})}function lre(){const e=De(),t=Ue(e["arrow-down"]);return h.jsx(R,{...e["arrow-down"],isSelected:t})}function ure(){const e=De(),t=Ue(e["arrow-right"]);return h.jsx(R,{...e["arrow-right"],isSelected:t})}function dre(){const e=De(),t=Ue(e.line);return h.jsx(R,{...e.line,isSelected:t})}function hre(){const e=De(),t=Ue(e.highlight);return h.jsx(R,{...e.highlight,isSelected:t})}function pre(){const e=De(),t=Ue(e.frame);return h.jsx(R,{...e.frame,isSelected:t})}function fre(){const e=De(),t=Ue(e.laser);return h.jsx(R,{...e.laser,isSelected:t})}const py=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function fy(e,t,n,r){e.addEventListener?e.addEventListener(t,n,r):e.attachEvent&&e.attachEvent("on".concat(t),n)}function al(e,t,n,r){e.removeEventListener?e.removeEventListener(t,n,r):e.detachEvent&&e.detachEvent("on".concat(t),n)}function Ej(e,t){const n=t.slice(0,t.length-1);for(let r=0;r<n.length;r++)n[r]=e[n[r].toLowerCase()];return n}function _j(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function gre(e,t){const n=e.length>=t.length?e:t,r=e.length>=t.length?t:e;let o=!0;for(let s=0;s<n.length;s++)r.indexOf(n[s])===-1&&(o=!1);return o}const bu={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,"-":py?173:189,"=":py?61:187,";":py?59:186,"'":222,"[":219,"]":221,"\\":220},po={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Rv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Lt={16:!1,18:!1,17:!1,91:!1},ct={};for(let e=1;e<20;e++)bu["f".concat(e)]=111+e;let Ve=[],Rl=null,kj="all";const ko=new Map,Vu=e=>bu[e.toLowerCase()]||po[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),mre=e=>Object.keys(bu).find(t=>bu[t]===e),yre=e=>Object.keys(po).find(t=>po[t]===e);function Tj(e){kj=e||"all"}function Pu(){return kj||"all"}function Sre(){return Ve.slice(0)}function vre(){return Ve.map(e=>mre(e)||yre(e)||String.fromCharCode(e))}function xre(){const e=[];return Object.keys(ct).forEach(t=>{ct[t].forEach(n=>{let{key:r,scope:o,mods:s,shortcut:i}=n;e.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>Vu(a))})})}),e}function wre(e){const t=e.target||e.srcElement,{tagName:n}=t;let r=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(r=!1),r}function bre(e){return typeof e=="string"&&(e=Vu(e)),Ve.indexOf(e)!==-1}function Pre(e,t){let n,r;e||(e=Pu());for(const o in ct)if(Object.prototype.hasOwnProperty.call(ct,o))for(n=ct[o],r=0;r<n.length;)n[r].scope===e?n.splice(r,1).forEach(i=>{let{element:a}=i;return xw(a)}):r++;Pu()===e&&Tj(t||"all")}function Cre(e){let t=e.keyCode||e.which||e.charCode;const n=Ve.indexOf(t);if(n>=0&&Ve.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&Ve.splice(0,Ve.length),(t===93||t===224)&&(t=91),t in Lt){Lt[t]=!1;for(const r in po)po[r]===t&&(kn[r]=!1)}}function $j(e){if(typeof e>"u")Object.keys(ct).forEach(o=>{Array.isArray(ct[o])&&ct[o].forEach(s=>eh(s)),delete ct[o]}),xw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&eh(o)});else if(typeof e=="object")e.key&&eh(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];let[o,s]=n;typeof o=="function"&&(s=o,o=""),eh({key:e,scope:o,method:s,splitKey:"+"})}}const eh=e=>{let{key:t,scope:n,method:r,splitKey:o="+"}=e;_j(t).forEach(i=>{const a=i.split(o),c=a.length,l=a[c-1],u=l==="*"?"*":Vu(l);if(!ct[u])return;n||(n=Pu());const d=c>1?Ej(po,a):[],p=[];ct[u]=ct[u].filter(f=>{const g=(r?f.method===r:!0)&&f.scope===n&&gre(f.mods,d);return g&&p.push(f.element),!g}),p.forEach(f=>xw(f))})};function fI(e,t,n,r){if(t.element!==r)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const s in Lt)Object.prototype.hasOwnProperty.call(Lt,s)&&(!Lt[s]&&t.mods.indexOf(+s)>-1||Lt[s]&&t.mods.indexOf(+s)===-1)&&(o=!1);(t.mods.length===0&&!Lt[16]&&!Lt[18]&&!Lt[17]&&!Lt[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(Ve),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function gI(e,t){const n=ct["*"];let r=e.keyCode||e.which||e.charCode;if(!kn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),Ve.indexOf(r)===-1&&r!==229&&Ve.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const c=Rv[a];e[a]&&Ve.indexOf(c)===-1?Ve.push(c):!e[a]&&Ve.indexOf(c)>-1?Ve.splice(Ve.indexOf(c),1):a==="metaKey"&&e[a]&&Ve.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(Ve=Ve.slice(Ve.indexOf(c))))}),r in Lt){Lt[r]=!0;for(const a in po)po[a]===r&&(kn[a]=!0);if(!n)return}for(const a in Lt)Object.prototype.hasOwnProperty.call(Lt,a)&&(Lt[a]=e[Rv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Ve.indexOf(17)===-1&&Ve.push(17),Ve.indexOf(18)===-1&&Ve.push(18),Lt[17]=!0,Lt[18]=!0);const o=Pu();if(n)for(let a=0;a<n.length;a++)n[a].scope===o&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&fI(e,n[a],o,t);if(!(r in ct))return;const s=ct[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const c=s[a],{splitKey:l}=c,u=c.key.split(l),d=[];for(let p=0;p<u.length;p++)d.push(Vu(u[p]));d.sort().join("")===Ve.sort().join("")&&fI(e,c,o,t)}}function kn(e,t,n){Ve=[];const r=_j(e);let o=[],s="all",i=document,a=0,c=!1,l=!0,u="+",d=!1,p=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(s=t.scope),t.element&&(i=t.element),t.keyup&&(c=t.keyup),t.keydown!==void 0&&(l=t.keydown),t.capture!==void 0&&(d=t.capture),typeof t.splitKey=="string"&&(u=t.splitKey),t.single===!0&&(p=!0)),typeof t=="string"&&(s=t),p&&$j(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=Ej(po,e)),e=e[e.length-1],e=e==="*"?"*":Vu(e),e in ct||(ct[e]=[]),ct[e].push({keyup:c,keydown:l,scope:s,mods:o,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!ko.has(i)){const f=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return gI(g,i)},y=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;gI(g,i),Cre(g)};ko.set(i,{keydownListener:f,keyupListenr:y,capture:d}),fy(i,"keydown",f,d),fy(i,"keyup",y,d)}if(!Rl){const f=()=>{Ve=[]};Rl={listener:f,capture:d},fy(window,"focus",f,d)}}}function Ire(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ct).forEach(n=>{ct[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function xw(e){const t=Object.values(ct).flat();if(t.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=ko.get(e)||{};r&&o&&(al(e,"keyup",o,s),al(e,"keydown",r,s),ko.delete(e))}if((t.length<=0||ko.size<=0)&&(Object.keys(ko).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=ko.get(o)||{};s&&i&&(al(o,"keyup",i,a),al(o,"keydown",s,a),ko.delete(o))}),ko.clear(),Object.keys(ct).forEach(o=>delete ct[o]),Rl)){const{listener:o,capture:s}=Rl;al(window,"focus",o,s),Rl=null}}const gy={getPressedKeyString:vre,setScope:Tj,getScope:Pu,deleteScope:Pre,getPressedKeyCodes:Sre,getAllKeyCodes:xre,isPressed:bre,filter:wre,trigger:Ire,unbind:$j,keyMap:bu,modifier:po,modifierMap:Rv};for(const e in gy)Object.prototype.hasOwnProperty.call(gy,e)&&(kn[e]=gy[e]);if(typeof window<"u"){const e=window.hotkeys;kn.noConflict=t=>(t&&window.hotkeys===kn&&(window.hotkeys=e),kn),window.hotkeys=kn}const mI=["copy","cut","paste","asset"];function Ere(){const e=z(),t=ns(),n=ce(),r=De(),o=K("is focused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!o)return;const s=e.getContainer();kn.setScope(e.store.id);const i=(c,l)=>{kn(c,{element:document.body,scope:e.store.id},l)},a=(c,l)=>{kn(c,{element:document.body,keyup:!0,keydown:!1,scope:e.store.id},l)};for(const c of Object.values(n))c.kbd&&(t&&!c.readonlyOk||mI.includes(c.id)||i(yI(c.kbd),l=>{Sl(e)||(Ee(l),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&e.getInstanceState().isReadonly||mI.includes(c.id)||i(yI(c.kbd),l=>{Sl(e)||(Ee(l),c.onSelect("kbd"))});return i(",",c=>{if(Sl(e)||e.inputs.keys.has("Comma"))return;Ee(c),s.focus(),e.inputs.keys.add("Comma");const{x:l,y:u,z:d}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:l,y:u,z:d},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),a(",",c=>{if(Sl(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:l,y:u,z:d}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:l,y:u,z:d},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{kn.deleteScope(e.store.id)}},[n,r,t,e,o])}function yI(e){return _re(e).map(t=>{let n="";const r=t.split("");return r.length===1?n=r[0]:r[0]==="!"?n=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?n=`alt+shift+${r[2]}`:n=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?n=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?n=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:n=`cmd+${r[1]},ctrl+${r[1]}`:n=t,n}).join(",")}function _re(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function Sl(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const kre=x.createContext(!1);function Tre({children:e}){const t=z(),n=v8(),r=Rn(),o=$e(),s=Math.min(8,5+r),[i,a]=x.useState(0),c=x.useRef(null),[l,u]=x.useState(null),d=x.useMemo(()=>{const f=[],y=[];l?f.push(`[data-value="${l}"]`):f.push(`:nth-child(${s+1})`);for(let g=0;g<s;g++)f.push(`:nth-child(${g+1})`),y.push(`:nth-child(${g+1})`);return`
#${n}_main > *:not(${f.join(", ")}) {
display: none;
}
${y.map(g=>`#${n}_more > *${g}`).join(", ")} {
display: none;
}
`},[l,n,s]),p=ax(()=>{if(!c.current)return;const f=Array.from(c.current.children);a(f.length),f.findIndex(w=>w.getAttribute("data-value")===l)<=s&&u(null);const g=Array.from(c.current.children).findIndex(w=>w.getAttribute("aria-checked")==="true");g!==-1&&g>=s&&u(f[g].getAttribute("data-value"))});return x.useLayoutEffect(()=>{p()}),x.useLayoutEffect(()=>{if(!c.current)return;const f=new MutationObserver(p);return f.observe(c.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{f.disconnect()}},[p]),x.useEffect(()=>{const f=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[y,g]of f)kn(y,w=>{var b;if(Sl(t))return;Ee(w);const v=Array.from(((b=c.current)==null?void 0:b.children)??[]).filter(E=>!(E instanceof HTMLElement)||E.tagName.toLowerCase()!=="button"?!1:!!(E.offsetWidth||E.offsetHeight))[g];v&&v.click()});return()=>{kn.unbind("1,2,3,4,5,6,7,8,9,0")}},[t]),h.jsxs(h.Fragment,{children:[h.jsx("style",{children:d}),h.jsxs("div",{className:ue("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<mt.TABLET_SM}),role:"radiogroup",children:[h.jsx("div",{id:`${n}_main`,ref:c,className:"tlui-toolbar__tools__list",children:h.jsx(vr,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s&&h.jsx(kre.Provider,{value:!0,children:h.jsxs(Li,{id:"toolbar overflow",modal:!1,children:[h.jsx(Fi,{children:h.jsx(pe,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:h.jsx(ke,{icon:"chevron-up"})})}),h.jsx(Ni,{side:"top",align:"center",children:h.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:h.jsx(vr,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const $re=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Mre({activeToolId:e}){const t=z(),n=Rn(),r=$e(),o=K("is tool locked",()=>t.getInstanceState().isToolLocked,[t]);return!e||$re.includes(e)?null:h.jsx(pe,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ue("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<mt.TABLET_SM}),onClick:()=>t.updateInstanceState({isToolLocked:!o}),children:h.jsx(ke,{icon:o?"lock":"unlock",small:!0})})}const Are=x.memo(function({children:t}){const n=z(),r=Rn(),o=ns(),s=K("current tool id",()=>n.getCurrentToolId(),[n]),{ActionsMenu:i,QuickActions:a}=ti();return h.jsx("div",{className:"tlui-toolbar",children:h.jsxs("div",{className:"tlui-toolbar__inner",children:[h.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&h.jsxs("div",{className:"tlui-toolbar__extras",children:[r<mt.TABLET&&h.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&h.jsx(a,{}),i&&h.jsx(i,{})]}),h.jsx(Mre,{activeToolId:s})]}),h.jsx(Tre,{children:t??h.jsx(zne,{})})]}),r<mt.TABLET_SM&&!o&&h.jsx("div",{className:"tlui-toolbar__tools",children:h.jsx(Nne,{})})]})})});function jre(){const e=ce();return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["zoom-in"],noClose:!0}),h.jsx(R,{...e["zoom-out"],noClose:!0}),h.jsx(sj,{}),h.jsx(ij,{}),h.jsx(aj,{})]})}const Ore=x.memo(function({children:t}){const n=cn(),[r,o]=Qs("zoom menu"),s=t??h.jsx(jre,{});return h.jsxs(fw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(gw,{asChild:!0,dir:"ltr",children:h.jsx(Dre,{})}),h.jsx(xg,{container:n,children:h.jsx(mw,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:h.jsx(vr,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),Dre=x.forwardRef(function(t,n){const r=z(),o=Rn(),s=K("zoom",()=>r.getZoomLevel(),[r]),i=$e(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{duration:Qr})},[r]);return h.jsx(pe,{ref:n,...t,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<mt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<mt.MOBILE?"zoom-in":void 0,children:o<mt.MOBILE?null:h.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),Mj=x.createContext({});function Rre({overrides:e={},children:t}){const n=Q0(e);return h.jsx(Mj.Provider,{value:x.useMemo(()=>({ContextMenu:dte,ActionsMenu:Bee,HelpMenu:Cte,ZoomMenu:Ore,MainMenu:Bte,Minimap:Gte,StylePanel:Fne,PageMenu:Zte,NavigationPanel:Xte,Toolbar:Are,KeyboardShortcutsDialog:Mte,QuickActions:Jte,HelperButtons:Tte,DebugPanel:Ste,DebugMenu:yte,MenuPanel:Ute,...n}),[n]),children:t})}function ti(){return x.useContext(Mj)}function Lre({overrides:e,components:t,assetUrls:n,onUiEvent:r,forceMobile:o,children:s}){return h.jsx(ZG,{assetUrls:Fq(n),children:h.jsx(eY,{overrides:Hq(e),children:h.jsx(Cq,{onEvent:r,children:h.jsx(Mq,{children:h.jsx(Iq,{children:h.jsx(zq,{forceMobile:o,children:h.jsx(Rre,{overrides:t,children:h.jsx(Fre,{overrides:e,children:s})})})})})})})})}function Fre({overrides:e,children:t}){const n=Kq(e);return h.jsx(IZ,{overrides:n.actions,children:h.jsx(Nq,{overrides:n.tools,children:t})})}function Nre(){const e=z(),{addToast:t}=Kr();x.useEffect(()=>{function n({name:r,count:o}){t({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${o}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return e.addListener("max-shapes",n),()=>{e.removeListener("max-shapes",n)}},[e,t])}const zre=Se.memo(function({renderDebugMenuItems:t,children:n,hideUi:r,components:o,...s}){return h.jsx(Lre,{...s,components:o,children:h.jsx(Bre,{hideUi:r,renderDebugMenuItems:t,children:n})})}),Bre=Se.memo(function({children:t,hideUi:n,...r}){return h.jsxs(h.Fragment,{children:[t,n?null:h.jsx(Ure,{...r})]})}),Ure=Se.memo(function(){const t=z(),n=$e(),r=Rn(),o=ns(),s=K("focus",()=>t.getInstanceState().isFocusMode,[t]),i=K("debug",()=>t.getInstanceState().isDebugMode,[t]),{SharePanel:a,TopPanel:c,MenuPanel:l,StylePanel:u,Toolbar:d,HelpMenu:p,NavigationPanel:f,HelperButtons:y,DebugPanel:g}=ti();Ere(),fZ(),Nre();const{"toggle-focus-mode":w}=ce();return h.jsx(pM,{children:h.jsxs("div",{className:ue("tlui-layout",{"tlui-layout__mobile":r<mt.TABLET_SM}),"data-breakpoint":r,children:[s?h.jsx("div",{className:"tlui-layout__top",children:h.jsx(pe,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>w.onSelect("menu"),children:h.jsx(ke,{icon:"dot"})})}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"tlui-layout__top",children:[h.jsxs("div",{className:"tlui-layout__top__left",children:[l&&h.jsx(l,{}),y&&h.jsx(y,{})]}),h.jsx("div",{className:"tlui-layout__top__center",children:c&&h.jsx(c,{})}),h.jsxs("div",{className:"tlui-layout__top__right",children:[a&&h.jsx(a,{}),u&&r>=mt.TABLET_SM&&!o&&h.jsx(u,{})]})]}),h.jsxs("div",{className:"tlui-layout__bottom",children:[h.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&h.jsx(f,{}),d&&h.jsx(d,{}),p&&h.jsx(p,{})]}),i&&g&&h.jsx(g,{})]})]}),h.jsx(Dq,{}),h.jsx(kq,{}),h.jsx(Rq,{}),h.jsx(Tq,{})]})})}),th=(e,t)=>{const[n,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),h3(e,t).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,t]),n};function Hre(e){return{draw:{url:e.fonts.draw,format:e.fonts.draw.split(".").pop()},serif:{url:e.fonts.serif,format:e.fonts.serif.split(".").pop()},sansSerif:{url:e.fonts.sansSerif,format:e.fonts.sansSerif.split(".").pop()},monospace:{url:e.fonts.monospace,format:e.fonts.monospace.split(".").pop()}}}function Aj(e){const t=x.useMemo(()=>Hre(e),[e]),n=[th("tldraw_draw",t.draw),th("tldraw_serif",t.serif),th("tldraw_sans",t.sansSerif),th("tldraw_mono",t.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function Kre(e){const{children:t,maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:c=[],tools:l=[],...u}=e,d=Q0(a),p=x.useMemo(()=>({Scribble:ZP,CollaboratorScribble:ZP,SelectionForeground:$W,SelectionBackground:kW,Handles:PW,...d}),[d]),f=US(c),y=x.useMemo(()=>[...Ux,...f],[f]),g=US(l),w=x.useMemo(()=>[...IY,..._V,...g],[g]),S=FM(u.assetUrls),{done:v,error:b}=Aj(S);return b?h.jsx(G2,{children:"Could not load assets. Please refresh the page."}):v?h.jsx(h8,{initialState:"select",...u,components:p,shapeUtils:y,tools:w,children:h.jsxs(zre,{...u,components:p,children:[h.jsx(Gre,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),t]})}):h.jsx(V2,{children:"Loading assets..."})}const Wre=Object.freeze(["image/jpeg","image/png","image/gif","image/svg+xml"]),Vre=Object.freeze(["video/mp4","video/quicktime"]);function Gre({maxImageDimension:e=1e3,maxAssetSize:t=10*1024*1024,acceptedImageMimeTypes:n=Wre,acceptedVideoMimeTypes:r=Vre,onMount:o}){const s=z(),i=Kr(),a=$e(),c=ax(d=>{const p=[];return p.push(...lY(d)),uV(d,{maxImageDimension:e,maxAssetSize:t,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),p.push(o==null?void 0:o(d)),()=>{p.forEach(f=>f==null?void 0:f())}});x.useLayoutEffect(()=>{if(s)return c==null?void 0:c(s)},[s,c]);const{Canvas:l}=dt(),{ContextMenu:u}=ti();return u?h.jsx(u,{}):l?h.jsx(l,{}):null}x.memo(function(t){const[n,r]=x.useState(null),[o,s]=x.useState(null),i=US(t.shapeUtils??[]),a=x.useMemo(()=>[...Ux,...i],[i]),c=U2({snapshot:t.snapshot,shapeUtils:a}),l=FM(),{done:u,error:d}=Aj(l),{pageId:p,bounds:f,scale:y,background:g,padding:w,darkMode:S,preserveAspectRatio:v,format:b="svg"}=t;return x.useLayoutEffect(()=>{if(!o||!c||!u)return;let E=!1;const C=document.createElement("div");o.appendChild(C),o.classList.add("tl-container","tl-theme__light");const I=new J({store:c,shapeUtils:a??[],tools:[],getContainer:()=>C});p&&I.setCurrentPage(p);const _=I.getCurrentPageShapeIds();async function k(){const $=await I.getSvgString([..._],{bounds:f,scale:y,background:g,padding:w,darkMode:S,preserveAspectRatio:v});if($&&!E){if(b==="svg"){if(!E){const T=new Blob([$.svg],{type:"image/svg+xml"}),O=URL.createObjectURL(T);r(O)}}else if(b==="png"){const T=await YM($.svg,I.environment.isSafari,{type:b,quality:1,scale:2,width:$.width,height:$.height});if(T&&!E){const O=URL.createObjectURL(T);r(O)}}}I.dispose()}return k(),()=>{E=!0}},[b,o,c,a,p,f,y,g,w,S,v,u,d]),d?h.jsx(G2,{children:"Could not load assets."}):u?h.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:n&&h.jsx("img",{src:n,style:{width:"100%",height:"100%"}})}):h.jsx(V2,{children:"Loading assets..."})});const Yre=ve({schemaVersion:on(1),storeVersion:mh,recordVersions:Lp(ge,ve({version:mh,subTypeVersions:Lp(ge,mh).optional(),subTypeKey:ge.optional()}))}),Xre=ve({schemaVersion:on(2),sequences:Lp(ge,mh)});ve({tldrawFileFormatVersion:cL,schema:lL("schemaVersion",{1:Yre,2:Xre}),records:Nt(ve({id:ge,typeName:ge}).allowUnknownProperties())});function A(e,t={}){const n=typeof e=="string"?e:e.src;if(typeof t=="function")return t(n);const{baseUrl:r=""}=t;return n.startsWith("data:")||n.match(/^https?:\/\//)?n:`${r.replace(/\/$/,"")}/${n.replace(/^\.?\//,"")}`}function qre(e){return{fonts:{monospace:A("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:A("./fonts/IBMPlexSans-Medium.woff2",e),serif:A("./fonts/IBMPlexSerif-Medium.woff2",e),draw:A("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom-center":A("./icons/icon/align-bottom-center.svg",e),"align-bottom-left":A("./icons/icon/align-bottom-left.svg",e),"align-bottom-right":A("./icons/icon/align-bottom-right.svg",e),"align-bottom":A("./icons/icon/align-bottom.svg",e),"align-center-center":A("./icons/icon/align-center-center.svg",e),"align-center-horizontal":A("./icons/icon/align-center-horizontal.svg",e),"align-center-left":A("./icons/icon/align-center-left.svg",e),"align-center-right":A("./icons/icon/align-center-right.svg",e),"align-center-vertical":A("./icons/icon/align-center-vertical.svg",e),"align-left":A("./icons/icon/align-left.svg",e),"align-right":A("./icons/icon/align-right.svg",e),"align-top-center":A("./icons/icon/align-top-center.svg",e),"align-top-left":A("./icons/icon/align-top-left.svg",e),"align-top-right":A("./icons/icon/align-top-right.svg",e),"align-top":A("./icons/icon/align-top.svg",e),"arrow-left":A("./icons/icon/arrow-left.svg",e),"arrowhead-arrow":A("./icons/icon/arrowhead-arrow.svg",e),"arrowhead-bar":A("./icons/icon/arrowhead-bar.svg",e),"arrowhead-diamond":A("./icons/icon/arrowhead-diamond.svg",e),"arrowhead-dot":A("./icons/icon/arrowhead-dot.svg",e),"arrowhead-none":A("./icons/icon/arrowhead-none.svg",e),"arrowhead-square":A("./icons/icon/arrowhead-square.svg",e),"arrowhead-triangle-inverted":A("./icons/icon/arrowhead-triangle-inverted.svg",e),"arrowhead-triangle":A("./icons/icon/arrowhead-triangle.svg",e),"aspect-ratio":A("./icons/icon/aspect-ratio.svg",e),avatar:A("./icons/icon/avatar.svg",e),blob:A("./icons/icon/blob.svg",e),"bring-forward":A("./icons/icon/bring-forward.svg",e),"bring-to-front":A("./icons/icon/bring-to-front.svg",e),"check-circle":A("./icons/icon/check-circle.svg",e),check:A("./icons/icon/check.svg",e),"checkbox-checked":A("./icons/icon/checkbox-checked.svg",e),"checkbox-empty":A("./icons/icon/checkbox-empty.svg",e),"chevron-down":A("./icons/icon/chevron-down.svg",e),"chevron-left":A("./icons/icon/chevron-left.svg",e),"chevron-right":A("./icons/icon/chevron-right.svg",e),"chevron-up":A("./icons/icon/chevron-up.svg",e),"chevrons-ne":A("./icons/icon/chevrons-ne.svg",e),"chevrons-sw":A("./icons/icon/chevrons-sw.svg",e),"clipboard-copied":A("./icons/icon/clipboard-copied.svg",e),"clipboard-copy":A("./icons/icon/clipboard-copy.svg",e),code:A("./icons/icon/code.svg",e),collab:A("./icons/icon/collab.svg",e),color:A("./icons/icon/color.svg",e),comment:A("./icons/icon/comment.svg",e),"cross-2":A("./icons/icon/cross-2.svg",e),"cross-circle":A("./icons/icon/cross-circle.svg",e),cross:A("./icons/icon/cross.svg",e),"dash-dashed":A("./icons/icon/dash-dashed.svg",e),"dash-dotted":A("./icons/icon/dash-dotted.svg",e),"dash-draw":A("./icons/icon/dash-draw.svg",e),"dash-solid":A("./icons/icon/dash-solid.svg",e),discord:A("./icons/icon/discord.svg",e),"distribute-horizontal":A("./icons/icon/distribute-horizontal.svg",e),"distribute-vertical":A("./icons/icon/distribute-vertical.svg",e),dot:A("./icons/icon/dot.svg",e),"dots-horizontal":A("./icons/icon/dots-horizontal.svg",e),"dots-vertical":A("./icons/icon/dots-vertical.svg",e),"drag-handle-dots":A("./icons/icon/drag-handle-dots.svg",e),duplicate:A("./icons/icon/duplicate.svg",e),edit:A("./icons/icon/edit.svg",e),error:A("./icons/icon/error.svg",e),"external-link":A("./icons/icon/external-link.svg",e),file:A("./icons/icon/file.svg",e),"fill-none":A("./icons/icon/fill-none.svg",e),"fill-pattern":A("./icons/icon/fill-pattern.svg",e),"fill-semi":A("./icons/icon/fill-semi.svg",e),"fill-solid":A("./icons/icon/fill-solid.svg",e),follow:A("./icons/icon/follow.svg",e),following:A("./icons/icon/following.svg",e),"font-draw":A("./icons/icon/font-draw.svg",e),"font-mono":A("./icons/icon/font-mono.svg",e),"font-sans":A("./icons/icon/font-sans.svg",e),"font-serif":A("./icons/icon/font-serif.svg",e),"geo-arrow-down":A("./icons/icon/geo-arrow-down.svg",e),"geo-arrow-left":A("./icons/icon/geo-arrow-left.svg",e),"geo-arrow-right":A("./icons/icon/geo-arrow-right.svg",e),"geo-arrow-up":A("./icons/icon/geo-arrow-up.svg",e),"geo-check-box":A("./icons/icon/geo-check-box.svg",e),"geo-cloud":A("./icons/icon/geo-cloud.svg",e),"geo-diamond":A("./icons/icon/geo-diamond.svg",e),"geo-ellipse":A("./icons/icon/geo-ellipse.svg",e),"geo-hexagon":A("./icons/icon/geo-hexagon.svg",e),"geo-octagon":A("./icons/icon/geo-octagon.svg",e),"geo-oval":A("./icons/icon/geo-oval.svg",e),"geo-pentagon":A("./icons/icon/geo-pentagon.svg",e),"geo-rectangle":A("./icons/icon/geo-rectangle.svg",e),"geo-rhombus-2":A("./icons/icon/geo-rhombus-2.svg",e),"geo-rhombus":A("./icons/icon/geo-rhombus.svg",e),"geo-star":A("./icons/icon/geo-star.svg",e),"geo-trapezoid":A("./icons/icon/geo-trapezoid.svg",e),"geo-triangle":A("./icons/icon/geo-triangle.svg",e),"geo-x-box":A("./icons/icon/geo-x-box.svg",e),github:A("./icons/icon/github.svg",e),group:A("./icons/icon/group.svg",e),hidden:A("./icons/icon/hidden.svg",e),image:A("./icons/icon/image.svg",e),"info-circle":A("./icons/icon/info-circle.svg",e),leading:A("./icons/icon/leading.svg",e),link:A("./icons/icon/link.svg",e),"lock-small":A("./icons/icon/lock-small.svg",e),lock:A("./icons/icon/lock.svg",e),menu:A("./icons/icon/menu.svg",e),minus:A("./icons/icon/minus.svg",e),mixed:A("./icons/icon/mixed.svg",e),pack:A("./icons/icon/pack.svg",e),page:A("./icons/icon/page.svg",e),plus:A("./icons/icon/plus.svg",e),"question-mark-circle":A("./icons/icon/question-mark-circle.svg",e),"question-mark":A("./icons/icon/question-mark.svg",e),redo:A("./icons/icon/redo.svg",e),"reset-zoom":A("./icons/icon/reset-zoom.svg",e),"rotate-ccw":A("./icons/icon/rotate-ccw.svg",e),"rotate-cw":A("./icons/icon/rotate-cw.svg",e),ruler:A("./icons/icon/ruler.svg",e),search:A("./icons/icon/search.svg",e),"send-backward":A("./icons/icon/send-backward.svg",e),"send-to-back":A("./icons/icon/send-to-back.svg",e),"settings-horizontal":A("./icons/icon/settings-horizontal.svg",e),"settings-vertical-1":A("./icons/icon/settings-vertical-1.svg",e),"settings-vertical":A("./icons/icon/settings-vertical.svg",e),"share-1":A("./icons/icon/share-1.svg",e),"share-2":A("./icons/icon/share-2.svg",e),"size-extra-large":A("./icons/icon/size-extra-large.svg",e),"size-large":A("./icons/icon/size-large.svg",e),"size-medium":A("./icons/icon/size-medium.svg",e),"size-small":A("./icons/icon/size-small.svg",e),"spline-cubic":A("./icons/icon/spline-cubic.svg",e),"spline-line":A("./icons/icon/spline-line.svg",e),"stack-horizontal":A("./icons/icon/stack-horizontal.svg",e),"stack-vertical":A("./icons/icon/stack-vertical.svg",e),"status-offline":A("./icons/icon/status-offline.svg",e),"status-online":A("./icons/icon/status-online.svg",e),"stretch-horizontal":A("./icons/icon/stretch-horizontal.svg",e),"stretch-vertical":A("./icons/icon/stretch-vertical.svg",e),"text-align-center":A("./icons/icon/text-align-center.svg",e),"text-align-justify":A("./icons/icon/text-align-justify.svg",e),"text-align-left":A("./icons/icon/text-align-left.svg",e),"text-align-right":A("./icons/icon/text-align-right.svg",e),"tool-arrow":A("./icons/icon/tool-arrow.svg",e),"tool-embed":A("./icons/icon/tool-embed.svg",e),"tool-eraser":A("./icons/icon/tool-eraser.svg",e),"tool-frame":A("./icons/icon/tool-frame.svg",e),"tool-hand":A("./icons/icon/tool-hand.svg",e),"tool-highlight":A("./icons/icon/tool-highlight.svg",e),"tool-laser":A("./icons/icon/tool-laser.svg",e),"tool-line":A("./icons/icon/tool-line.svg",e),"tool-media":A("./icons/icon/tool-media.svg",e),"tool-note":A("./icons/icon/tool-note.svg",e),"tool-pencil":A("./icons/icon/tool-pencil.svg",e),"tool-pointer":A("./icons/icon/tool-pointer.svg",e),"tool-text":A("./icons/icon/tool-text.svg",e),trash:A("./icons/icon/trash.svg",e),"triangle-down":A("./icons/icon/triangle-down.svg",e),"triangle-up":A("./icons/icon/triangle-up.svg",e),twitter:A("./icons/icon/twitter.svg",e),undo:A("./icons/icon/undo.svg",e),ungroup:A("./icons/icon/ungroup.svg",e),"unlock-small":A("./icons/icon/unlock-small.svg",e),unlock:A("./icons/icon/unlock.svg",e),"vertical-align-center":A("./icons/icon/vertical-align-center.svg",e),"vertical-align-end":A("./icons/icon/vertical-align-end.svg",e),"vertical-align-start":A("./icons/icon/vertical-align-start.svg",e),visible:A("./icons/icon/visible.svg",e),"warning-triangle":A("./icons/icon/warning-triangle.svg",e),"zoom-in":A("./icons/icon/zoom-in.svg",e),"zoom-out":A("./icons/icon/zoom-out.svg",e)},translations:{ar:A("./translations/ar.json",e),ca:A("./translations/ca.json",e),cs:A("./translations/cs.json",e),da:A("./translations/da.json",e),de:A("./translations/de.json",e),en:A("./translations/en.json",e),es:A("./translations/es.json",e),fa:A("./translations/fa.json",e),fi:A("./translations/fi.json",e),fr:A("./translations/fr.json",e),gl:A("./translations/gl.json",e),he:A("./translations/he.json",e),"hi-in":A("./translations/hi-in.json",e),hr:A("./translations/hr.json",e),hu:A("./translations/hu.json",e),it:A("./translations/it.json",e),ja:A("./translations/ja.json",e),"ko-kr":A("./translations/ko-kr.json",e),ku:A("./translations/ku.json",e),languages:A("./translations/languages.json",e),main:A("./translations/main.json",e),my:A("./translations/my.json",e),ne:A("./translations/ne.json",e),no:A("./translations/no.json",e),pl:A("./translations/pl.json",e),"pt-br":A("./translations/pt-br.json",e),"pt-pt":A("./translations/pt-pt.json",e),ro:A("./translations/ro.json",e),ru:A("./translations/ru.json",e),sl:A("./translations/sl.json",e),sv:A("./translations/sv.json",e),te:A("./translations/te.json",e),th:A("./translations/th.json",e),tr:A("./translations/tr.json",e),uk:A("./translations/uk.json",e),vi:A("./translations/vi.json",e),"zh-cn":A("./translations/zh-cn.json",e),"zh-tw":A("./translations/zh-tw.json",e)},embedIcons:{codepen:A("./embed-icons/codepen.png",e),codesandbox:A("./embed-icons/codesandbox.png",e),excalidraw:A("./embed-icons/excalidraw.png",e),felt:A("./embed-icons/felt.png",e),figma:A("./embed-icons/figma.png",e),github_gist:A("./embed-icons/github_gist.png",e),google_calendar:A("./embed-icons/google_calendar.png",e),google_maps:A("./embed-icons/google_maps.png",e),google_slides:A("./embed-icons/google_slides.png",e),observable:A("./embed-icons/observable.png",e),replit:A("./embed-icons/replit.png",e),scratch:A("./embed-icons/scratch.png",e),spotify:A("./embed-icons/spotify.png",e),tldraw:A("./embed-icons/tldraw.png",e),val_town:A("./embed-icons/val_town.png",e),vimeo:A("./embed-icons/vimeo.png",e),youtube:A("./embed-icons/youtube.png",e)}}}const Zre=({onSave:e})=>{const t=()=>{e&&e()};return h.jsx("button",{type:"button",className:"bg-transparent border border-gray-300 mr-3 rounded-lg p-1 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-600",onClick:t,children:h.jsx("img",{src:"/save.svg",alt:"Save",className:"w-6 h-6 inline-block align-middle"})})};function Qre(e){if(e===""||e.trim()==="")return!1;try{return btoa(atob(e))==e}catch{return!1}}function Jre(e){const t=e.length%4===0?0:4-e.length%4;e+="=".repeat(t);const n=atob(e),r=new Uint8Array(n.length);for(let o=0;o<n.length;o++)r[o]=n.charCodeAt(o);return new TextDecoder("utf-8").decode(r)}const cl="PERSISTENCE_KEY";function eoe(){const e=qre({baseUrl:"./static/"});localStorage.removeItem(cl);const[t]=x.useState(()=>B2({shapeUtils:Ux})),[n,r]=x.useState({status:"loading"}),[o,s]=x.useState(!1),[i,a]=x.useState("未命名白板"),c=p=>{a(p.target.value)},l=()=>{s(!0)},u=()=>{i.trim()===""?alert("请输入标题!"):s(!1)};x.useLayoutEffect(()=>{r({status:"loading"});const p=localStorage.getItem(cl);if(p)try{const g=JSON.parse(p);t.loadSnapshot(g),r({status:"ready"})}catch(g){r({status:"error",error:g.message})}else r({status:"ready"});const f=g=>{const w=g.data;if(w.type==="start"&&w.title){const S=w.title.substring(0,w.title.lastIndexOf("."));S&&a(S)}if(w.type==="init"){const S=w.data;if(!S||!S.title)return;const v=S.title.substring(0,S.title.lastIndexOf("."));a(v),S.content&&(typeof S.content=="string"&&Qre(S.content)&&(S.content=Jre(S.content),S.content=JSON.parse(S.content)),t.loadSnapshot(S.content),localStorage.setItem(cl,JSON.stringify(S.content)))}};window.addEventListener("load",()=>{window.parent.postMessage({type:"initSuccess"},"*"),window.addEventListener("message",f)});const y=t.listen(N_(()=>{const g=t.getSnapshot();localStorage.setItem(cl,JSON.stringify(g))},200));return()=>{y(),window.removeEventListener("unload",f)}},[t]);const d=()=>{const p=localStorage.getItem(cl)||"{}",f={title:i,content:JSON.parse(p)},y={data:JSON.stringify(f),type:"exportBaiban"};console.log(y),window.parent.postMessage(y,"*")};return n.status==="loading"?h.jsx("div",{className:"tldraw__editor",children:h.jsx("h2",{children:"Loading..."})}):n.status==="error"?h.jsxs("div",{className:"tldraw__editor",children:[h.jsx("h2",{children:"Error!"}),h.jsx("p",{children:n.error})]}):h.jsxs("div",{className:"tldraw__editor",children:[h.jsxs("div",{style:{position:"absolute",zIndex:2e3,top:3,left:"calc(50% - 90px)",display:"flex",alignItems:"center"},children:[h.jsx(Zre,{onSave:()=>d()}),h.jsx("div",{className:"flex items-center bottom-12 right-4 space-x-2",children:o?h.jsx("input",{type:"text",value:i,onChange:c,onBlur:u,className:`
bg-gray-100
border
border-gray-200
rounded-lg
py-1.5
px-3
w-64
focus:outline-none
focus:border-slate-500
`,style:{height:"38px"}}):h.jsx("span",{onClick:l,className:"cursor-pointer select-none text-gray-400 hover:text-gray-600 transition duration-200 ease-in-out mt-2",children:i})})]}),h.jsx(Kre,{assetUrls:e,persistenceKey:"my-persistence-key",store:t})]})}Ry.createRoot(document.getElementById("root")).render(h.jsx(Se.StrictMode,{children:h.jsx(eoe,{})}));