mirror of https://gitee.com/godoos/godoos.git
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.
337 lines
1.0 MiB
337 lines
1.0 MiB
var XL=Object.defineProperty;var qL=(e,n,t)=>n in e?XL(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var m=(e,n,t)=>qL(e,typeof n!="symbol"?n+"":n,t);function ZL(e,n){for(var t=0;t<n.length;t++){const r=n[t];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 n=document.createElement("link").relList;if(n&&n.supports&&n.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 t(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=t(o);fetch(o.href,s)}})();var sn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var cE={exports:{}},_f={},uE={exports:{}},ve={};/**
|
|
* @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 Iu=Symbol.for("react.element"),QL=Symbol.for("react.portal"),JL=Symbol.for("react.fragment"),e$=Symbol.for("react.strict_mode"),t$=Symbol.for("react.profiler"),n$=Symbol.for("react.provider"),r$=Symbol.for("react.context"),o$=Symbol.for("react.forward_ref"),s$=Symbol.for("react.suspense"),i$=Symbol.for("react.memo"),a$=Symbol.for("react.lazy"),_b=Symbol.iterator;function l$(e){return e===null||typeof e!="object"?null:(e=_b&&e[_b]||e["@@iterator"],typeof e=="function"?e:null)}var dE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},hE=Object.assign,pE={};function Il(e,n,t){this.props=e,this.context=n,this.refs=pE,this.updater=t||dE}Il.prototype.isReactComponent={};Il.prototype.setState=function(e,n){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,n,"setState")};Il.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function fE(){}fE.prototype=Il.prototype;function ex(e,n,t){this.props=e,this.context=n,this.refs=pE,this.updater=t||dE}var tx=ex.prototype=new fE;tx.constructor=ex;hE(tx,Il.prototype);tx.isPureReactComponent=!0;var Tb=Array.isArray,gE=Object.prototype.hasOwnProperty,nx={current:null},mE={key:!0,ref:!0,__self:!0,__source:!0};function yE(e,n,t){var r,o={},s=null,i=null;if(n!=null)for(r in n.ref!==void 0&&(i=n.ref),n.key!==void 0&&(s=""+n.key),n)gE.call(n,r)&&!mE.hasOwnProperty(r)&&(o[r]=n[r]);var a=arguments.length-2;if(a===1)o.children=t;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];o.children=l}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Iu,type:e,key:s,ref:i,props:o,_owner:nx.current}}function c$(e,n){return{$$typeof:Iu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function rx(e){return typeof e=="object"&&e!==null&&e.$$typeof===Iu}function u$(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var Mb=/\/+/g;function Hg(e,n){return typeof e=="object"&&e!==null&&e.key!=null?u$(""+e.key):n.toString(36)}function hh(e,n,t,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 Iu:case QL:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+Hg(i,0):r,Tb(o)?(t="",e!=null&&(t=e.replace(Mb,"$&/")+"/"),hh(o,n,t,"",function(c){return c})):o!=null&&(rx(o)&&(o=c$(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(Mb,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",Tb(e))for(var a=0;a<e.length;a++){s=e[a];var l=r+Hg(s,a);i+=hh(s,n,t,l,o)}else if(l=l$(e),typeof l=="function")for(e=l.call(e),a=0;!(s=e.next()).done;)s=s.value,l=r+Hg(s,a++),i+=hh(s,n,t,l,o);else if(s==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return i}function cd(e,n,t){if(e==null)return e;var r=[],o=0;return hh(e,r,"","",function(s){return n.call(t,s,o++)}),r}function d$(e){if(e._status===-1){var n=e._result;n=n(),n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var yn={current:null},ph={transition:null},h$={ReactCurrentDispatcher:yn,ReactCurrentBatchConfig:ph,ReactCurrentOwner:nx};function SE(){throw Error("act(...) is not supported in production builds of React.")}ve.Children={map:cd,forEach:function(e,n,t){cd(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return cd(e,function(){n++}),n},toArray:function(e){return cd(e,function(n){return n})||[]},only:function(e){if(!rx(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};ve.Component=Il;ve.Fragment=JL;ve.Profiler=t$;ve.PureComponent=ex;ve.StrictMode=e$;ve.Suspense=s$;ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=h$;ve.act=SE;ve.cloneElement=function(e,n,t){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=hE({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=nx.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in n)gE.call(n,l)&&!mE.hasOwnProperty(l)&&(r[l]=n[l]===void 0&&a!==void 0?a[l]:n[l])}var l=arguments.length-2;if(l===1)r.children=t;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:Iu,type:e.type,key:o,ref:s,props:r,_owner:i}};ve.createContext=function(e){return e={$$typeof:r$,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:n$,_context:e},e.Consumer=e};ve.createElement=yE;ve.createFactory=function(e){var n=yE.bind(null,e);return n.type=e,n};ve.createRef=function(){return{current:null}};ve.forwardRef=function(e){return{$$typeof:o$,render:e}};ve.isValidElement=rx;ve.lazy=function(e){return{$$typeof:a$,_payload:{_status:-1,_result:e},_init:d$}};ve.memo=function(e,n){return{$$typeof:i$,type:e,compare:n===void 0?null:n}};ve.startTransition=function(e){var n=ph.transition;ph.transition={};try{e()}finally{ph.transition=n}};ve.unstable_act=SE;ve.useCallback=function(e,n){return yn.current.useCallback(e,n)};ve.useContext=function(e){return yn.current.useContext(e)};ve.useDebugValue=function(){};ve.useDeferredValue=function(e){return yn.current.useDeferredValue(e)};ve.useEffect=function(e,n){return yn.current.useEffect(e,n)};ve.useId=function(){return yn.current.useId()};ve.useImperativeHandle=function(e,n,t){return yn.current.useImperativeHandle(e,n,t)};ve.useInsertionEffect=function(e,n){return yn.current.useInsertionEffect(e,n)};ve.useLayoutEffect=function(e,n){return yn.current.useLayoutEffect(e,n)};ve.useMemo=function(e,n){return yn.current.useMemo(e,n)};ve.useReducer=function(e,n,t){return yn.current.useReducer(e,n,t)};ve.useRef=function(e){return yn.current.useRef(e)};ve.useState=function(e){return yn.current.useState(e)};ve.useSyncExternalStore=function(e,n,t){return yn.current.useSyncExternalStore(e,n,t)};ve.useTransition=function(){return yn.current.useTransition()};ve.version="18.3.1";uE.exports=ve;var P=uE.exports;const xe=ei(P),p$=ZL({__proto__:null,default:xe},[P]);/**
|
|
* @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 f$=P,g$=Symbol.for("react.element"),m$=Symbol.for("react.fragment"),y$=Object.prototype.hasOwnProperty,S$=f$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,v$={key:!0,ref:!0,__self:!0,__source:!0};function vE(e,n,t){var r,o={},s=null,i=null;t!==void 0&&(s=""+t),n.key!==void 0&&(s=""+n.key),n.ref!==void 0&&(i=n.ref);for(r in n)y$.call(n,r)&&!v$.hasOwnProperty(r)&&(o[r]=n[r]);if(e&&e.defaultProps)for(r in n=e.defaultProps,n)o[r]===void 0&&(o[r]=n[r]);return{$$typeof:g$,type:e,key:s,ref:i,props:o,_owner:S$.current}}_f.Fragment=m$;_f.jsx=vE;_f.jsxs=vE;cE.exports=_f;var u=cE.exports,Zy={},xE={exports:{}},ir={},wE={exports:{}},bE={};/**
|
|
* @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 n(z,U){var X=z.length;z.push(U);e:for(;0<X;){var J=X-1>>>1,le=z[J];if(0<o(le,U))z[J]=U,z[X]=le,X=J;else break e}}function t(z){return z.length===0?null:z[0]}function r(z){if(z.length===0)return null;var U=z[0],X=z.pop();if(X!==U){z[0]=X;e:for(var J=0,le=z.length,ye=le>>>1;J<ye;){var Me=2*(J+1)-1,ae=z[Me],Ue=Me+1,Ae=z[Ue];if(0>o(ae,X))Ue<le&&0>o(Ae,ae)?(z[J]=Ae,z[Ue]=X,J=Ue):(z[J]=ae,z[Me]=X,J=Me);else if(Ue<le&&0>o(Ae,X))z[J]=Ae,z[Ue]=X,J=Ue;else break e}}return U}function o(z,U){var X=z.sortIndex-U.sortIndex;return X!==0?X:z.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 l=[],c=[],d=1,h=null,p=3,f=!1,S=!1,g=!1,x=typeof setTimeout=="function"?setTimeout:null,y=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(z){for(var U=t(c);U!==null;){if(U.callback===null)r(c);else if(U.startTime<=z)r(c),U.sortIndex=U.expirationTime,n(l,U);else break;U=t(c)}}function E(z){if(g=!1,b(z),!S)if(t(l)!==null)S=!0,W(I);else{var U=t(c);U!==null&&K(E,U.startTime-z)}}function I(z,U){S=!1,g&&(g=!1,y(T),T=-1),f=!0;var X=p;try{for(b(U),h=t(l);h!==null&&(!(h.expirationTime>U)||z&&!j());){var J=h.callback;if(typeof J=="function"){h.callback=null,p=h.priorityLevel;var le=J(h.expirationTime<=U);U=e.unstable_now(),typeof le=="function"?h.callback=le:h===t(l)&&r(l),b(U)}else r(l);h=t(l)}if(h!==null)var ye=!0;else{var Me=t(c);Me!==null&&K(E,Me.startTime-U),ye=!1}return ye}finally{h=null,p=X,f=!1}}var C=!1,k=null,T=-1,O=5,_=-1;function j(){return!(e.unstable_now()-_<O)}function L(){if(k!==null){var z=e.unstable_now();_=z;var U=!0;try{U=k(!0,z)}finally{U?A():(C=!1,k=null)}}else C=!1}var A;if(typeof v=="function")A=function(){v(L)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,F=R.port2;R.port1.onmessage=L,A=function(){F.postMessage(null)}}else A=function(){x(L,0)};function W(z){k=z,C||(C=!0,A())}function K(z,U){T=x(function(){z(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(z){z.callback=null},e.unstable_continueExecution=function(){S||f||(S=!0,W(I))},e.unstable_forceFrameRate=function(z){0>z||125<z?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):O=0<z?Math.floor(1e3/z):5},e.unstable_getCurrentPriorityLevel=function(){return p},e.unstable_getFirstCallbackNode=function(){return t(l)},e.unstable_next=function(z){switch(p){case 1:case 2:case 3:var U=3;break;default:U=p}var X=p;p=U;try{return z()}finally{p=X}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(z,U){switch(z){case 1:case 2:case 3:case 4:case 5:break;default:z=3}var X=p;p=z;try{return U()}finally{p=X}},e.unstable_scheduleCallback=function(z,U,X){var J=e.unstable_now();switch(typeof X=="object"&&X!==null?(X=X.delay,X=typeof X=="number"&&0<X?J+X:J):X=J,z){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=X+le,z={id:d++,callback:U,priorityLevel:z,startTime:X,expirationTime:le,sortIndex:-1},X>J?(z.sortIndex=X,n(c,z),t(l)===null&&z===t(c)&&(g?(y(T),T=-1):g=!0,K(E,X-J))):(z.sortIndex=le,n(l,z),S||f||(S=!0,W(I))),z},e.unstable_shouldYield=j,e.unstable_wrapCallback=function(z){var U=p;return function(){var X=p;p=U;try{return z.apply(this,arguments)}finally{p=X}}}})(bE);wE.exports=bE;var x$=wE.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 w$=P,rr=x$;function q(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,t=1;t<arguments.length;t++)n+="&args[]="+encodeURIComponent(arguments[t]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var PE=new Set,Wc={};function ta(e,n){il(e,n),il(e+"Capture",n)}function il(e,n){for(Wc[e]=n,e=0;e<n.length;e++)PE.add(n[e])}var Vo=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Qy=Object.prototype.hasOwnProperty,b$=/^[: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]*$/,jb={},Ab={};function P$(e){return Qy.call(Ab,e)?!0:Qy.call(jb,e)?!1:b$.test(e)?Ab[e]=!0:(jb[e]=!0,!1)}function C$(e,n,t,r){if(t!==null&&t.type===0)return!1;switch(typeof n){case"function":case"symbol":return!0;case"boolean":return r?!1:t!==null?!t.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function I$(e,n,t,r){if(n===null||typeof n>"u"||C$(e,n,t,r))return!0;if(r)return!1;if(t!==null)switch(t.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function Sn(e,n,t,r,o,s,i){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=t,this.propertyName=e,this.type=n,this.sanitizeURL=s,this.removeEmptyString=i}var Gt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Gt[e]=new Sn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Gt[n]=new Sn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Gt[e]=new Sn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Gt[e]=new Sn(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){Gt[e]=new Sn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Gt[e]=new Sn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Gt[e]=new Sn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Gt[e]=new Sn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Gt[e]=new Sn(e,5,!1,e.toLowerCase(),null,!1,!1)});var ox=/[\-:]([a-z])/g;function sx(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 n=e.replace(ox,sx);Gt[n]=new Sn(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(ox,sx);Gt[n]=new Sn(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(ox,sx);Gt[n]=new Sn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Gt[e]=new Sn(e,1,!1,e.toLowerCase(),null,!1,!1)});Gt.xlinkHref=new Sn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Gt[e]=new Sn(e,1,!1,e.toLowerCase(),null,!0,!0)});function ix(e,n,t,r){var o=Gt.hasOwnProperty(n)?Gt[n]:null;(o!==null?o.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(I$(n,t,o,r)&&(t=null),r||o===null?P$(n)&&(t===null?e.removeAttribute(n):e.setAttribute(n,""+t)):o.mustUseProperty?e[o.propertyName]=t===null?o.type===3?!1:"":t:(n=o.attributeName,r=o.attributeNamespace,t===null?e.removeAttribute(n):(o=o.type,t=o===3||o===4&&t===!0?"":""+t,r?e.setAttributeNS(r,n,t):e.setAttribute(n,t))))}var ns=w$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ud=Symbol.for("react.element"),Ea=Symbol.for("react.portal"),ka=Symbol.for("react.fragment"),ax=Symbol.for("react.strict_mode"),Jy=Symbol.for("react.profiler"),CE=Symbol.for("react.provider"),IE=Symbol.for("react.context"),lx=Symbol.for("react.forward_ref"),eS=Symbol.for("react.suspense"),tS=Symbol.for("react.suspense_list"),cx=Symbol.for("react.memo"),ws=Symbol.for("react.lazy"),EE=Symbol.for("react.offscreen"),Ob=Symbol.iterator;function Gl(e){return e===null||typeof e!="object"?null:(e=Ob&&e[Ob]||e["@@iterator"],typeof e=="function"?e:null)}var pt=Object.assign,Kg;function yc(e){if(Kg===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);Kg=n&&n[1]||""}return`
|
|
`+Kg+e}var Wg=!1;function Gg(e,n){if(!e||Wg)return"";Wg=!0;var t=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(c){var r=c}Reflect.construct(e,[],n)}else{try{n.call()}catch(c){r=c}e.call(n.prototype)}else{try{throw Error()}catch(c){r=c}e()}}catch(c){if(c&&r&&typeof c.stack=="string"){for(var o=c.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 l=`
|
|
`+o[i].replace(" at new "," at ");return e.displayName&&l.includes("<anonymous>")&&(l=l.replace("<anonymous>",e.displayName)),l}while(1<=i&&0<=a);break}}}finally{Wg=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?yc(e):""}function E$(e){switch(e.tag){case 5:return yc(e.type);case 16:return yc("Lazy");case 13:return yc("Suspense");case 19:return yc("SuspenseList");case 0:case 2:case 15:return e=Gg(e.type,!1),e;case 11:return e=Gg(e.type.render,!1),e;case 1:return e=Gg(e.type,!0),e;default:return""}}function nS(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 ka:return"Fragment";case Ea:return"Portal";case Jy:return"Profiler";case ax:return"StrictMode";case eS:return"Suspense";case tS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case IE:return(e.displayName||"Context")+".Consumer";case CE:return(e._context.displayName||"Context")+".Provider";case lx:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case cx:return n=e.displayName||null,n!==null?n:nS(e.type)||"Memo";case ws:n=e._payload,e=e._init;try{return nS(e(n))}catch{}}return null}function k$(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return nS(n);case 8:return n===ax?"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 n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function Ks(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function kE(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function _$(e){var n=kE(e)?"checked":"value",t=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),r=""+e[n];if(!e.hasOwnProperty(n)&&typeof t<"u"&&typeof t.get=="function"&&typeof t.set=="function"){var o=t.get,s=t.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return o.call(this)},set:function(i){r=""+i,s.call(this,i)}}),Object.defineProperty(e,n,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function dd(e){e._valueTracker||(e._valueTracker=_$(e))}function _E(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=kE(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function gp(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 rS(e,n){var t=n.checked;return pt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function Db(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Ks(n.value!=null?n.value:t),e._wrapperState={initialChecked:r,initialValue:t,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function TE(e,n){n=n.checked,n!=null&&ix(e,"checked",n,!1)}function oS(e,n){TE(e,n);var t=Ks(n.value),r=n.type;if(t!=null)r==="number"?(t===0&&e.value===""||e.value!=t)&&(e.value=""+t):e.value!==""+t&&(e.value=""+t);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?sS(e,n.type,t):n.hasOwnProperty("defaultValue")&&sS(e,n.type,Ks(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function Rb(e,n,t){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var r=n.type;if(!(r!=="submit"&&r!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,t||n===e.value||(e.value=n),e.defaultValue=n}t=e.name,t!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,t!==""&&(e.name=t)}function sS(e,n,t){(n!=="number"||gp(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var Sc=Array.isArray;function Ya(e,n,t,r){if(e=e.options,n){n={};for(var o=0;o<t.length;o++)n["$"+t[o]]=!0;for(t=0;t<e.length;t++)o=n.hasOwnProperty("$"+e[t].value),e[t].selected!==o&&(e[t].selected=o),o&&r&&(e[t].defaultSelected=!0)}else{for(t=""+Ks(t),n=null,o=0;o<e.length;o++){if(e[o].value===t){e[o].selected=!0,r&&(e[o].defaultSelected=!0);return}n!==null||e[o].disabled||(n=e[o])}n!==null&&(n.selected=!0)}}function iS(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return pt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Lb(e,n){var t=n.value;if(t==null){if(t=n.children,n=n.defaultValue,t!=null){if(n!=null)throw Error(q(92));if(Sc(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Ks(t)}}function ME(e,n){var t=Ks(n.value),r=Ks(n.defaultValue);t!=null&&(t=""+t,t!==e.value&&(e.value=t),n.defaultValue==null&&e.defaultValue!==t&&(e.defaultValue=t)),r!=null&&(e.defaultValue=""+r)}function $b(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function jE(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 aS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?jE(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var hd,AE=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(n,t,r,o){MSApp.execUnsafeLocalFunction(function(){return e(n,t,r,o)})}:e}(function(e,n){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=n;else{for(hd=hd||document.createElement("div"),hd.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=hd.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Gc(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var Tc={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},T$=["Webkit","ms","Moz","O"];Object.keys(Tc).forEach(function(e){T$.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),Tc[n]=Tc[e]})});function OE(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||Tc.hasOwnProperty(e)&&Tc[e]?(""+n).trim():n+"px"}function DE(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=OE(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var M$=pt({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 lS(e,n){if(n){if(M$[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(q(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(q(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(q(61))}if(n.style!=null&&typeof n.style!="object")throw Error(q(62))}}function cS(e,n){if(e.indexOf("-")===-1)return typeof n.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 uS=null;function ux(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var dS=null,Xa=null,qa=null;function Fb(e){if(e=_u(e)){if(typeof dS!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Of(n),dS(e.stateNode,e.type,n))}}function RE(e){Xa?qa?qa.push(e):qa=[e]:Xa=e}function LE(){if(Xa){var e=Xa,n=qa;if(qa=Xa=null,Fb(e),n)for(e=0;e<n.length;e++)Fb(n[e])}}function $E(e,n){return e(n)}function FE(){}var Vg=!1;function NE(e,n,t){if(Vg)return e(n,t);Vg=!0;try{return $E(e,n,t)}finally{Vg=!1,(Xa!==null||qa!==null)&&(FE(),LE())}}function Vc(e,n){var t=e.stateNode;if(t===null)return null;var r=Of(t);if(r===null)return null;t=r[n];e:switch(n){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(t&&typeof t!="function")throw Error(q(231,n,typeof t));return t}var hS=!1;if(Vo)try{var Vl={};Object.defineProperty(Vl,"passive",{get:function(){hS=!0}}),window.addEventListener("test",Vl,Vl),window.removeEventListener("test",Vl,Vl)}catch{hS=!1}function j$(e,n,t,r,o,s,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{n.apply(t,c)}catch(d){this.onError(d)}}var Mc=!1,mp=null,yp=!1,pS=null,A$={onError:function(e){Mc=!0,mp=e}};function O$(e,n,t,r,o,s,i,a,l){Mc=!1,mp=null,j$.apply(A$,arguments)}function D$(e,n,t,r,o,s,i,a,l){if(O$.apply(this,arguments),Mc){if(Mc){var c=mp;Mc=!1,mp=null}else throw Error(q(198));yp||(yp=!0,pS=c)}}function na(e){var n=e,t=e;if(e.alternate)for(;n.return;)n=n.return;else{e=n;do n=e,n.flags&4098&&(t=n.return),e=n.return;while(e)}return n.tag===3?t:null}function zE(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function Nb(e){if(na(e)!==e)throw Error(q(188))}function R$(e){var n=e.alternate;if(!n){if(n=na(e),n===null)throw Error(q(188));return n!==e?null:e}for(var t=e,r=n;;){var o=t.return;if(o===null)break;var s=o.alternate;if(s===null){if(r=o.return,r!==null){t=r;continue}break}if(o.child===s.child){for(s=o.child;s;){if(s===t)return Nb(o),e;if(s===r)return Nb(o),n;s=s.sibling}throw Error(q(188))}if(t.return!==r.return)t=o,r=s;else{for(var i=!1,a=o.child;a;){if(a===t){i=!0,t=o,r=s;break}if(a===r){i=!0,r=o,t=s;break}a=a.sibling}if(!i){for(a=s.child;a;){if(a===t){i=!0,t=s,r=o;break}if(a===r){i=!0,r=s,t=o;break}a=a.sibling}if(!i)throw Error(q(189))}}if(t.alternate!==r)throw Error(q(190))}if(t.tag!==3)throw Error(q(188));return t.stateNode.current===t?e:n}function BE(e){return e=R$(e),e!==null?UE(e):null}function UE(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=UE(e);if(n!==null)return n;e=e.sibling}return null}var HE=rr.unstable_scheduleCallback,zb=rr.unstable_cancelCallback,L$=rr.unstable_shouldYield,$$=rr.unstable_requestPaint,xt=rr.unstable_now,F$=rr.unstable_getCurrentPriorityLevel,dx=rr.unstable_ImmediatePriority,KE=rr.unstable_UserBlockingPriority,Sp=rr.unstable_NormalPriority,N$=rr.unstable_LowPriority,WE=rr.unstable_IdlePriority,Tf=null,ho=null;function z$(e){if(ho&&typeof ho.onCommitFiberRoot=="function")try{ho.onCommitFiberRoot(Tf,e,void 0,(e.current.flags&128)===128)}catch{}}var Nr=Math.clz32?Math.clz32:H$,B$=Math.log,U$=Math.LN2;function H$(e){return e>>>=0,e===0?32:31-(B$(e)/U$|0)|0}var pd=64,fd=4194304;function vc(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 vp(e,n){var t=e.pendingLanes;if(t===0)return 0;var r=0,o=e.suspendedLanes,s=e.pingedLanes,i=t&268435455;if(i!==0){var a=i&~o;a!==0?r=vc(a):(s&=i,s!==0&&(r=vc(s)))}else i=t&~o,i!==0?r=vc(i):s!==0&&(r=vc(s));if(r===0)return 0;if(n!==0&&n!==r&&!(n&o)&&(o=r&-r,s=n&-n,o>=s||o===16&&(s&4194240)!==0))return n;if(r&4&&(r|=t&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=r;0<n;)t=31-Nr(n),o=1<<t,r|=e[t],n&=~o;return r}function K$(e,n){switch(e){case 1:case 2:case 4:return n+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 n+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 W$(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-Nr(s),a=1<<i,l=o[i];l===-1?(!(a&t)||a&r)&&(o[i]=K$(a,n)):l<=n&&(e.expiredLanes|=a),s&=~a}}function fS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function GE(){var e=pd;return pd<<=1,!(pd&4194240)&&(pd=64),e}function Yg(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function Eu(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Nr(n),e[n]=t}function G$(e,n){var t=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<t;){var o=31-Nr(t),s=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~s}}function hx(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-Nr(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var Fe=0;function VE(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var YE,px,XE,qE,ZE,gS=!1,gd=[],js=null,As=null,Os=null,Yc=new Map,Xc=new Map,Ps=[],V$="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 Bb(e,n){switch(e){case"focusin":case"focusout":js=null;break;case"dragenter":case"dragleave":As=null;break;case"mouseover":case"mouseout":Os=null;break;case"pointerover":case"pointerout":Yc.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Xc.delete(n.pointerId)}}function Yl(e,n,t,r,o,s){return e===null||e.nativeEvent!==s?(e={blockedOn:n,domEventName:t,eventSystemFlags:r,nativeEvent:s,targetContainers:[o]},n!==null&&(n=_u(n),n!==null&&px(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function Y$(e,n,t,r,o){switch(n){case"focusin":return js=Yl(js,e,n,t,r,o),!0;case"dragenter":return As=Yl(As,e,n,t,r,o),!0;case"mouseover":return Os=Yl(Os,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return Yc.set(s,Yl(Yc.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,Xc.set(s,Yl(Xc.get(s)||null,e,n,t,r,o)),!0}return!1}function QE(e){var n=Ci(e.target);if(n!==null){var t=na(n);if(t!==null){if(n=t.tag,n===13){if(n=zE(t),n!==null){e.blockedOn=n,ZE(e.priority,function(){XE(t)});return}}else if(n===3&&t.stateNode.current.memoizedState.isDehydrated){e.blockedOn=t.tag===3?t.stateNode.containerInfo:null;return}}}e.blockedOn=null}function fh(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=mS(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);uS=r,t.target.dispatchEvent(r),uS=null}else return n=_u(t),n!==null&&px(n),e.blockedOn=t,!1;n.shift()}return!0}function Ub(e,n,t){fh(e)&&t.delete(n)}function X$(){gS=!1,js!==null&&fh(js)&&(js=null),As!==null&&fh(As)&&(As=null),Os!==null&&fh(Os)&&(Os=null),Yc.forEach(Ub),Xc.forEach(Ub)}function Xl(e,n){e.blockedOn===n&&(e.blockedOn=null,gS||(gS=!0,rr.unstable_scheduleCallback(rr.unstable_NormalPriority,X$)))}function qc(e){function n(o){return Xl(o,e)}if(0<gd.length){Xl(gd[0],e);for(var t=1;t<gd.length;t++){var r=gd[t];r.blockedOn===e&&(r.blockedOn=null)}}for(js!==null&&Xl(js,e),As!==null&&Xl(As,e),Os!==null&&Xl(Os,e),Yc.forEach(n),Xc.forEach(n),t=0;t<Ps.length;t++)r=Ps[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<Ps.length&&(t=Ps[0],t.blockedOn===null);)QE(t),t.blockedOn===null&&Ps.shift()}var Za=ns.ReactCurrentBatchConfig,xp=!0;function q$(e,n,t,r){var o=Fe,s=Za.transition;Za.transition=null;try{Fe=1,fx(e,n,t,r)}finally{Fe=o,Za.transition=s}}function Z$(e,n,t,r){var o=Fe,s=Za.transition;Za.transition=null;try{Fe=4,fx(e,n,t,r)}finally{Fe=o,Za.transition=s}}function fx(e,n,t,r){if(xp){var o=mS(e,n,t,r);if(o===null)om(e,n,r,wp,t),Bb(e,r);else if(Y$(o,e,n,t,r))r.stopPropagation();else if(Bb(e,r),n&4&&-1<V$.indexOf(e)){for(;o!==null;){var s=_u(o);if(s!==null&&YE(s),s=mS(e,n,t,r),s===null&&om(e,n,r,wp,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else om(e,n,r,null,t)}}var wp=null;function mS(e,n,t,r){if(wp=null,e=ux(r),e=Ci(e),e!==null)if(n=na(e),n===null)e=null;else if(t=n.tag,t===13){if(e=zE(n),e!==null)return e;e=null}else if(t===3){if(n.stateNode.current.memoizedState.isDehydrated)return n.tag===3?n.stateNode.containerInfo:null;e=null}else n!==e&&(e=null);return wp=e,null}function JE(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(F$()){case dx:return 1;case KE:return 4;case Sp:case N$:return 16;case WE:return 536870912;default:return 16}default:return 16}}var Es=null,gx=null,gh=null;function ek(){if(gh)return gh;var e,n=gx,t=n.length,r,o="value"in Es?Es.value:Es.textContent,s=o.length;for(e=0;e<t&&n[e]===o[e];e++);var i=t-e;for(r=1;r<=i&&n[t-r]===o[s-r];r++);return gh=o.slice(e,1<r?1-r:void 0)}function mh(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function md(){return!0}function Hb(){return!1}function ar(e){function n(t,r,o,s,i){this._reactName=t,this._targetInst=o,this.type=r,this.nativeEvent=s,this.target=i,this.currentTarget=null;for(var a in e)e.hasOwnProperty(a)&&(t=e[a],this[a]=t?t(s):s[a]);return this.isDefaultPrevented=(s.defaultPrevented!=null?s.defaultPrevented:s.returnValue===!1)?md:Hb,this.isPropagationStopped=Hb,this}return pt(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var t=this.nativeEvent;t&&(t.preventDefault?t.preventDefault():typeof t.returnValue!="unknown"&&(t.returnValue=!1),this.isDefaultPrevented=md)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=md)},persist:function(){},isPersistent:md}),n}var El={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},mx=ar(El),ku=pt({},El,{view:0,detail:0}),Q$=ar(ku),Xg,qg,ql,Mf=pt({},ku,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:yx,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!==ql&&(ql&&e.type==="mousemove"?(Xg=e.screenX-ql.screenX,qg=e.screenY-ql.screenY):qg=Xg=0,ql=e),Xg)},movementY:function(e){return"movementY"in e?e.movementY:qg}}),Kb=ar(Mf),J$=pt({},Mf,{dataTransfer:0}),eF=ar(J$),tF=pt({},ku,{relatedTarget:0}),Zg=ar(tF),nF=pt({},El,{animationName:0,elapsedTime:0,pseudoElement:0}),rF=ar(nF),oF=pt({},El,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),sF=ar(oF),iF=pt({},El,{data:0}),Wb=ar(iF),aF={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},lF={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"},cF={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function uF(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=cF[e])?!!n[e]:!1}function yx(){return uF}var dF=pt({},ku,{key:function(e){if(e.key){var n=aF[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=mh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?lF[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:yx,charCode:function(e){return e.type==="keypress"?mh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?mh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),hF=ar(dF),pF=pt({},Mf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Gb=ar(pF),fF=pt({},ku,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:yx}),gF=ar(fF),mF=pt({},El,{propertyName:0,elapsedTime:0,pseudoElement:0}),yF=ar(mF),SF=pt({},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}),vF=ar(SF),xF=[9,13,27,32],Sx=Vo&&"CompositionEvent"in window,jc=null;Vo&&"documentMode"in document&&(jc=document.documentMode);var wF=Vo&&"TextEvent"in window&&!jc,tk=Vo&&(!Sx||jc&&8<jc&&11>=jc),Vb=" ",Yb=!1;function nk(e,n){switch(e){case"keyup":return xF.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function rk(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var _a=!1;function bF(e,n){switch(e){case"compositionend":return rk(n);case"keypress":return n.which!==32?null:(Yb=!0,Vb);case"textInput":return e=n.data,e===Vb&&Yb?null:e;default:return null}}function PF(e,n){if(_a)return e==="compositionend"||!Sx&&nk(e,n)?(e=ek(),gh=gx=Es=null,_a=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1<n.char.length)return n.char;if(n.which)return String.fromCharCode(n.which)}return null;case"compositionend":return tk&&n.locale!=="ko"?null:n.data;default:return null}}var CF={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 Xb(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!CF[e.type]:n==="textarea"}function ok(e,n,t,r){RE(r),n=bp(n,"onChange"),0<n.length&&(t=new mx("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var Ac=null,Zc=null;function IF(e){gk(e,0)}function jf(e){var n=ja(e);if(_E(n))return e}function EF(e,n){if(e==="change")return n}var sk=!1;if(Vo){var Qg;if(Vo){var Jg="oninput"in document;if(!Jg){var qb=document.createElement("div");qb.setAttribute("oninput","return;"),Jg=typeof qb.oninput=="function"}Qg=Jg}else Qg=!1;sk=Qg&&(!document.documentMode||9<document.documentMode)}function Zb(){Ac&&(Ac.detachEvent("onpropertychange",ik),Zc=Ac=null)}function ik(e){if(e.propertyName==="value"&&jf(Zc)){var n=[];ok(n,Zc,e,ux(e)),NE(IF,n)}}function kF(e,n,t){e==="focusin"?(Zb(),Ac=n,Zc=t,Ac.attachEvent("onpropertychange",ik)):e==="focusout"&&Zb()}function _F(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return jf(Zc)}function TF(e,n){if(e==="click")return jf(n)}function MF(e,n){if(e==="input"||e==="change")return jf(n)}function jF(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Ur=typeof Object.is=="function"?Object.is:jF;function Qc(e,n){if(Ur(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var t=Object.keys(e),r=Object.keys(n);if(t.length!==r.length)return!1;for(r=0;r<t.length;r++){var o=t[r];if(!Qy.call(n,o)||!Ur(e[o],n[o]))return!1}return!0}function Qb(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Jb(e,n){var t=Qb(e);e=0;for(var r;t;){if(t.nodeType===3){if(r=e+t.textContent.length,e<=n&&r>=n)return{node:t,offset:n-e};e=r}e:{for(;t;){if(t.nextSibling){t=t.nextSibling;break e}t=t.parentNode}t=void 0}t=Qb(t)}}function ak(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?ak(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function lk(){for(var e=window,n=gp();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=gp(e.document)}return n}function vx(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function AF(e){var n=lk(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&ak(t.ownerDocument.documentElement,t)){if(r!==null&&vx(t)){if(n=r.start,e=r.end,e===void 0&&(e=n),"selectionStart"in t)t.selectionStart=n,t.selectionEnd=Math.min(e,t.value.length);else if(e=(n=t.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var o=t.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=Jb(t,s);var i=Jb(t,r);o&&i&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(n=n.createRange(),n.setStart(o.node,o.offset),e.removeAllRanges(),s>r?(e.addRange(n),e.extend(i.node,i.offset)):(n.setEnd(i.node,i.offset),e.addRange(n)))}}for(n=[],e=t;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof t.focus=="function"&&t.focus(),t=0;t<n.length;t++)e=n[t],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var OF=Vo&&"documentMode"in document&&11>=document.documentMode,Ta=null,yS=null,Oc=null,SS=!1;function e1(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;SS||Ta==null||Ta!==gp(r)||(r=Ta,"selectionStart"in r&&vx(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}),Oc&&Qc(Oc,r)||(Oc=r,r=bp(yS,"onSelect"),0<r.length&&(n=new mx("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=Ta)))}function yd(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var Ma={animationend:yd("Animation","AnimationEnd"),animationiteration:yd("Animation","AnimationIteration"),animationstart:yd("Animation","AnimationStart"),transitionend:yd("Transition","TransitionEnd")},em={},ck={};Vo&&(ck=document.createElement("div").style,"AnimationEvent"in window||(delete Ma.animationend.animation,delete Ma.animationiteration.animation,delete Ma.animationstart.animation),"TransitionEvent"in window||delete Ma.transitionend.transition);function Af(e){if(em[e])return em[e];if(!Ma[e])return e;var n=Ma[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in ck)return em[e]=n[t];return e}var uk=Af("animationend"),dk=Af("animationiteration"),hk=Af("animationstart"),pk=Af("transitionend"),fk=new Map,t1="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 ti(e,n){fk.set(e,n),ta(n,[e])}for(var tm=0;tm<t1.length;tm++){var nm=t1[tm],DF=nm.toLowerCase(),RF=nm[0].toUpperCase()+nm.slice(1);ti(DF,"on"+RF)}ti(uk,"onAnimationEnd");ti(dk,"onAnimationIteration");ti(hk,"onAnimationStart");ti("dblclick","onDoubleClick");ti("focusin","onFocus");ti("focusout","onBlur");ti(pk,"onTransitionEnd");il("onMouseEnter",["mouseout","mouseover"]);il("onMouseLeave",["mouseout","mouseover"]);il("onPointerEnter",["pointerout","pointerover"]);il("onPointerLeave",["pointerout","pointerover"]);ta("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));ta("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));ta("onBeforeInput",["compositionend","keypress","textInput","paste"]);ta("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));ta("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));ta("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var xc="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(" "),LF=new Set("cancel close invalid load scroll toggle".split(" ").concat(xc));function n1(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,D$(r,n,void 0,e),e.currentTarget=null}function gk(e,n){n=(n&4)!==0;for(var t=0;t<e.length;t++){var r=e[t],o=r.event;r=r.listeners;e:{var s=void 0;if(n)for(var i=r.length-1;0<=i;i--){var a=r[i],l=a.instance,c=a.currentTarget;if(a=a.listener,l!==s&&o.isPropagationStopped())break e;n1(o,a,c),s=l}else for(i=0;i<r.length;i++){if(a=r[i],l=a.instance,c=a.currentTarget,a=a.listener,l!==s&&o.isPropagationStopped())break e;n1(o,a,c),s=l}}}if(yp)throw e=pS,yp=!1,pS=null,e}function Ze(e,n){var t=n[PS];t===void 0&&(t=n[PS]=new Set);var r=e+"__bubble";t.has(r)||(mk(n,e,2,!1),t.add(r))}function rm(e,n,t){var r=0;n&&(r|=4),mk(t,e,r,n)}var Sd="_reactListening"+Math.random().toString(36).slice(2);function Jc(e){if(!e[Sd]){e[Sd]=!0,PE.forEach(function(t){t!=="selectionchange"&&(LF.has(t)||rm(t,!1,e),rm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[Sd]||(n[Sd]=!0,rm("selectionchange",!1,n))}}function mk(e,n,t,r){switch(JE(n)){case 1:var o=q$;break;case 4:o=Z$;break;default:o=fx}t=o.bind(null,n,t,e),o=void 0,!hS||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(o=!0),r?o!==void 0?e.addEventListener(n,t,{capture:!0,passive:o}):e.addEventListener(n,t,!0):o!==void 0?e.addEventListener(n,t,{passive:o}):e.addEventListener(n,t,!1)}function om(e,n,t,r,o){var s=r;if(!(n&1)&&!(n&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 l=i.tag;if((l===3||l===4)&&(l=i.stateNode.containerInfo,l===o||l.nodeType===8&&l.parentNode===o))return;i=i.return}for(;a!==null;){if(i=Ci(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}NE(function(){var c=s,d=ux(t),h=[];e:{var p=fk.get(e);if(p!==void 0){var f=mx,S=e;switch(e){case"keypress":if(mh(t)===0)break e;case"keydown":case"keyup":f=hF;break;case"focusin":S="focus",f=Zg;break;case"focusout":S="blur",f=Zg;break;case"beforeblur":case"afterblur":f=Zg;break;case"click":if(t.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":f=Kb;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=eF;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=gF;break;case uk:case dk:case hk:f=rF;break;case pk:f=yF;break;case"scroll":f=Q$;break;case"wheel":f=vF;break;case"copy":case"cut":case"paste":f=sF;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=Gb}var g=(n&4)!==0,x=!g&&e==="scroll",y=g?p!==null?p+"Capture":null:p;g=[];for(var v=c,b;v!==null;){b=v;var E=b.stateNode;if(b.tag===5&&E!==null&&(b=E,y!==null&&(E=Vc(v,y),E!=null&&g.push(eu(v,E,b)))),x)break;v=v.return}0<g.length&&(p=new f(p,S,null,t,d),h.push({event:p,listeners:g}))}}if(!(n&7)){e:{if(p=e==="mouseover"||e==="pointerover",f=e==="mouseout"||e==="pointerout",p&&t!==uS&&(S=t.relatedTarget||t.fromElement)&&(Ci(S)||S[Yo]))break e;if((f||p)&&(p=d.window===d?d:(p=d.ownerDocument)?p.defaultView||p.parentWindow:window,f?(S=t.relatedTarget||t.toElement,f=c,S=S?Ci(S):null,S!==null&&(x=na(S),S!==x||S.tag!==5&&S.tag!==6)&&(S=null)):(f=null,S=c),f!==S)){if(g=Kb,E="onMouseLeave",y="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(g=Gb,E="onPointerLeave",y="onPointerEnter",v="pointer"),x=f==null?p:ja(f),b=S==null?p:ja(S),p=new g(E,v+"leave",f,t,d),p.target=x,p.relatedTarget=b,E=null,Ci(d)===c&&(g=new g(y,v+"enter",S,t,d),g.target=b,g.relatedTarget=x,E=g),x=E,f&&S)t:{for(g=f,y=S,v=0,b=g;b;b=da(b))v++;for(b=0,E=y;E;E=da(E))b++;for(;0<v-b;)g=da(g),v--;for(;0<b-v;)y=da(y),b--;for(;v--;){if(g===y||y!==null&&g===y.alternate)break t;g=da(g),y=da(y)}g=null}else g=null;f!==null&&r1(h,p,f,g,!1),S!==null&&x!==null&&r1(h,x,S,g,!0)}}e:{if(p=c?ja(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var I=EF;else if(Xb(p))if(sk)I=MF;else{I=_F;var C=kF}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(I=TF);if(I&&(I=I(e,c))){ok(h,I,t,d);break e}C&&C(e,p,c),e==="focusout"&&(C=p._wrapperState)&&C.controlled&&p.type==="number"&&sS(p,"number",p.value)}switch(C=c?ja(c):window,e){case"focusin":(Xb(C)||C.contentEditable==="true")&&(Ta=C,yS=c,Oc=null);break;case"focusout":Oc=yS=Ta=null;break;case"mousedown":SS=!0;break;case"contextmenu":case"mouseup":case"dragend":SS=!1,e1(h,t,d);break;case"selectionchange":if(OF)break;case"keydown":case"keyup":e1(h,t,d)}var k;if(Sx)e:{switch(e){case"compositionstart":var T="onCompositionStart";break e;case"compositionend":T="onCompositionEnd";break e;case"compositionupdate":T="onCompositionUpdate";break e}T=void 0}else _a?nk(e,t)&&(T="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(T="onCompositionStart");T&&(tk&&t.locale!=="ko"&&(_a||T!=="onCompositionStart"?T==="onCompositionEnd"&&_a&&(k=ek()):(Es=d,gx="value"in Es?Es.value:Es.textContent,_a=!0)),C=bp(c,T),0<C.length&&(T=new Wb(T,e,null,t,d),h.push({event:T,listeners:C}),k?T.data=k:(k=rk(t),k!==null&&(T.data=k)))),(k=wF?bF(e,t):PF(e,t))&&(c=bp(c,"onBeforeInput"),0<c.length&&(d=new Wb("onBeforeInput","beforeinput",null,t,d),h.push({event:d,listeners:c}),d.data=k))}gk(h,n)})}function eu(e,n,t){return{instance:e,listener:n,currentTarget:t}}function bp(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=Vc(e,t),s!=null&&r.unshift(eu(e,s,o)),s=Vc(e,n),s!=null&&r.push(eu(e,s,o))),e=e.return}return r}function da(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function r1(e,n,t,r,o){for(var s=n._reactName,i=[];t!==null&&t!==r;){var a=t,l=a.alternate,c=a.stateNode;if(l!==null&&l===r)break;a.tag===5&&c!==null&&(a=c,o?(l=Vc(t,s),l!=null&&i.unshift(eu(t,l,a))):o||(l=Vc(t,s),l!=null&&i.push(eu(t,l,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var $F=/\r\n?/g,FF=/\u0000|\uFFFD/g;function o1(e){return(typeof e=="string"?e:""+e).replace($F,`
|
|
`).replace(FF,"")}function vd(e,n,t){if(n=o1(n),o1(e)!==n&&t)throw Error(q(425))}function Pp(){}var vS=null,xS=null;function wS(e,n){return e==="textarea"||e==="noscript"||typeof n.children=="string"||typeof n.children=="number"||typeof n.dangerouslySetInnerHTML=="object"&&n.dangerouslySetInnerHTML!==null&&n.dangerouslySetInnerHTML.__html!=null}var bS=typeof setTimeout=="function"?setTimeout:void 0,NF=typeof clearTimeout=="function"?clearTimeout:void 0,s1=typeof Promise=="function"?Promise:void 0,zF=typeof queueMicrotask=="function"?queueMicrotask:typeof s1<"u"?function(e){return s1.resolve(null).then(e).catch(BF)}:bS;function BF(e){setTimeout(function(){throw e})}function sm(e,n){var t=n,r=0;do{var o=t.nextSibling;if(e.removeChild(t),o&&o.nodeType===8)if(t=o.data,t==="/$"){if(r===0){e.removeChild(o),qc(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);qc(n)}function Ds(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function i1(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var t=e.data;if(t==="$"||t==="$!"||t==="$?"){if(n===0)return e;n--}else t==="/$"&&n++}e=e.previousSibling}return null}var kl=Math.random().toString(36).slice(2),oo="__reactFiber$"+kl,tu="__reactProps$"+kl,Yo="__reactContainer$"+kl,PS="__reactEvents$"+kl,UF="__reactListeners$"+kl,HF="__reactHandles$"+kl;function Ci(e){var n=e[oo];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Yo]||t[oo]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=i1(e);e!==null;){if(t=e[oo])return t;e=i1(e)}return n}e=t,t=e.parentNode}return null}function _u(e){return e=e[oo]||e[Yo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function ja(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Of(e){return e[tu]||null}var CS=[],Aa=-1;function ni(e){return{current:e}}function Je(e){0>Aa||(e.current=CS[Aa],CS[Aa]=null,Aa--)}function Ge(e,n){Aa++,CS[Aa]=e.current,e.current=n}var Ws={},ln=ni(Ws),Rn=ni(!1),Li=Ws;function al(e,n){var t=e.type.contextTypes;if(!t)return Ws;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var o={},s;for(s in t)o[s]=n[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=o),o}function Ln(e){return e=e.childContextTypes,e!=null}function Cp(){Je(Rn),Je(ln)}function a1(e,n,t){if(ln.current!==Ws)throw Error(q(168));Ge(ln,n),Ge(Rn,t)}function yk(e,n,t){var r=e.stateNode;if(n=n.childContextTypes,typeof r.getChildContext!="function")return t;r=r.getChildContext();for(var o in r)if(!(o in n))throw Error(q(108,k$(e)||"Unknown",o));return pt({},t,r)}function Ip(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ws,Li=ln.current,Ge(ln,e),Ge(Rn,Rn.current),!0}function l1(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=yk(e,n,Li),r.__reactInternalMemoizedMergedChildContext=e,Je(Rn),Je(ln),Ge(ln,e)):Je(Rn),Ge(Rn,t)}var Ro=null,Df=!1,im=!1;function Sk(e){Ro===null?Ro=[e]:Ro.push(e)}function KF(e){Df=!0,Sk(e)}function ri(){if(!im&&Ro!==null){im=!0;var e=0,n=Fe;try{var t=Ro;for(Fe=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}Ro=null,Df=!1}catch(o){throw Ro!==null&&(Ro=Ro.slice(e+1)),HE(dx,ri),o}finally{Fe=n,im=!1}}return null}var Oa=[],Da=0,Ep=null,kp=0,mr=[],yr=0,$i=null,Fo=1,No="";function wi(e,n){Oa[Da++]=kp,Oa[Da++]=Ep,Ep=e,kp=n}function vk(e,n,t){mr[yr++]=Fo,mr[yr++]=No,mr[yr++]=$i,$i=e;var r=Fo;e=No;var o=32-Nr(r)-1;r&=~(1<<o),t+=1;var s=32-Nr(n)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Fo=1<<32-Nr(n)+o|t<<o|r,No=s+e}else Fo=1<<s|t<<o|r,No=e}function xx(e){e.return!==null&&(wi(e,1),vk(e,1,0))}function wx(e){for(;e===Ep;)Ep=Oa[--Da],Oa[Da]=null,kp=Oa[--Da],Oa[Da]=null;for(;e===$i;)$i=mr[--yr],mr[yr]=null,No=mr[--yr],mr[yr]=null,Fo=mr[--yr],mr[yr]=null}var Qn=null,Zn=null,nt=!1,Rr=null;function xk(e,n){var t=xr(5,null,null,0);t.elementType="DELETED",t.stateNode=n,t.return=e,n=e.deletions,n===null?(e.deletions=[t],e.flags|=16):n.push(t)}function c1(e,n){switch(e.tag){case 5:var t=e.type;return n=n.nodeType!==1||t.toLowerCase()!==n.nodeName.toLowerCase()?null:n,n!==null?(e.stateNode=n,Qn=e,Zn=Ds(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,Qn=e,Zn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=$i!==null?{id:Fo,overflow:No}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=xr(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,Qn=e,Zn=null,!0):!1;default:return!1}}function IS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function ES(e){if(nt){var n=Zn;if(n){var t=n;if(!c1(e,n)){if(IS(e))throw Error(q(418));n=Ds(t.nextSibling);var r=Qn;n&&c1(e,n)?xk(r,t):(e.flags=e.flags&-4097|2,nt=!1,Qn=e)}}else{if(IS(e))throw Error(q(418));e.flags=e.flags&-4097|2,nt=!1,Qn=e}}}function u1(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Qn=e}function xd(e){if(e!==Qn)return!1;if(!nt)return u1(e),nt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!wS(e.type,e.memoizedProps)),n&&(n=Zn)){if(IS(e))throw wk(),Error(q(418));for(;n;)xk(e,n),n=Ds(n.nextSibling)}if(u1(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(q(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var t=e.data;if(t==="/$"){if(n===0){Zn=Ds(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}Zn=null}}else Zn=Qn?Ds(e.stateNode.nextSibling):null;return!0}function wk(){for(var e=Zn;e;)e=Ds(e.nextSibling)}function ll(){Zn=Qn=null,nt=!1}function bx(e){Rr===null?Rr=[e]:Rr.push(e)}var WF=ns.ReactCurrentBatchConfig;function Zl(e,n,t){if(e=t.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(t._owner){if(t=t._owner,t){if(t.tag!==1)throw Error(q(309));var r=t.stateNode}if(!r)throw Error(q(147,e));var o=r,s=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===s?n.ref:(n=function(i){var a=o.refs;i===null?delete a[s]:a[s]=i},n._stringRef=s,n)}if(typeof e!="string")throw Error(q(284));if(!t._owner)throw Error(q(290,e))}return e}function wd(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function d1(e){var n=e._init;return n(e._payload)}function bk(e){function n(y,v){if(e){var b=y.deletions;b===null?(y.deletions=[v],y.flags|=16):b.push(v)}}function t(y,v){if(!e)return null;for(;v!==null;)n(y,v),v=v.sibling;return null}function r(y,v){for(y=new Map;v!==null;)v.key!==null?y.set(v.key,v):y.set(v.index,v),v=v.sibling;return y}function o(y,v){return y=Fs(y,v),y.index=0,y.sibling=null,y}function s(y,v,b){return y.index=b,e?(b=y.alternate,b!==null?(b=b.index,b<v?(y.flags|=2,v):b):(y.flags|=2,v)):(y.flags|=1048576,v)}function i(y){return e&&y.alternate===null&&(y.flags|=2),y}function a(y,v,b,E){return v===null||v.tag!==6?(v=pm(b,y.mode,E),v.return=y,v):(v=o(v,b),v.return=y,v)}function l(y,v,b,E){var I=b.type;return I===ka?d(y,v,b.props.children,E,b.key):v!==null&&(v.elementType===I||typeof I=="object"&&I!==null&&I.$$typeof===ws&&d1(I)===v.type)?(E=o(v,b.props),E.ref=Zl(y,v,b),E.return=y,E):(E=Ph(b.type,b.key,b.props,null,y.mode,E),E.ref=Zl(y,v,b),E.return=y,E)}function c(y,v,b,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==b.containerInfo||v.stateNode.implementation!==b.implementation?(v=fm(b,y.mode,E),v.return=y,v):(v=o(v,b.children||[]),v.return=y,v)}function d(y,v,b,E,I){return v===null||v.tag!==7?(v=Ai(b,y.mode,E,I),v.return=y,v):(v=o(v,b),v.return=y,v)}function h(y,v,b){if(typeof v=="string"&&v!==""||typeof v=="number")return v=pm(""+v,y.mode,b),v.return=y,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case ud:return b=Ph(v.type,v.key,v.props,null,y.mode,b),b.ref=Zl(y,null,v),b.return=y,b;case Ea:return v=fm(v,y.mode,b),v.return=y,v;case ws:var E=v._init;return h(y,E(v._payload),b)}if(Sc(v)||Gl(v))return v=Ai(v,y.mode,b,null),v.return=y,v;wd(y,v)}return null}function p(y,v,b,E){var I=v!==null?v.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return I!==null?null:a(y,v,""+b,E);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case ud:return b.key===I?l(y,v,b,E):null;case Ea:return b.key===I?c(y,v,b,E):null;case ws:return I=b._init,p(y,v,I(b._payload),E)}if(Sc(b)||Gl(b))return I!==null?null:d(y,v,b,E,null);wd(y,b)}return null}function f(y,v,b,E,I){if(typeof E=="string"&&E!==""||typeof E=="number")return y=y.get(b)||null,a(v,y,""+E,I);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case ud:return y=y.get(E.key===null?b:E.key)||null,l(v,y,E,I);case Ea:return y=y.get(E.key===null?b:E.key)||null,c(v,y,E,I);case ws:var C=E._init;return f(y,v,b,C(E._payload),I)}if(Sc(E)||Gl(E))return y=y.get(b)||null,d(v,y,E,I,null);wd(v,E)}return null}function S(y,v,b,E){for(var I=null,C=null,k=v,T=v=0,O=null;k!==null&&T<b.length;T++){k.index>T?(O=k,k=null):O=k.sibling;var _=p(y,k,b[T],E);if(_===null){k===null&&(k=O);break}e&&k&&_.alternate===null&&n(y,k),v=s(_,v,T),C===null?I=_:C.sibling=_,C=_,k=O}if(T===b.length)return t(y,k),nt&&wi(y,T),I;if(k===null){for(;T<b.length;T++)k=h(y,b[T],E),k!==null&&(v=s(k,v,T),C===null?I=k:C.sibling=k,C=k);return nt&&wi(y,T),I}for(k=r(y,k);T<b.length;T++)O=f(k,y,T,b[T],E),O!==null&&(e&&O.alternate!==null&&k.delete(O.key===null?T:O.key),v=s(O,v,T),C===null?I=O:C.sibling=O,C=O);return e&&k.forEach(function(j){return n(y,j)}),nt&&wi(y,T),I}function g(y,v,b,E){var I=Gl(b);if(typeof I!="function")throw Error(q(150));if(b=I.call(b),b==null)throw Error(q(151));for(var C=I=null,k=v,T=v=0,O=null,_=b.next();k!==null&&!_.done;T++,_=b.next()){k.index>T?(O=k,k=null):O=k.sibling;var j=p(y,k,_.value,E);if(j===null){k===null&&(k=O);break}e&&k&&j.alternate===null&&n(y,k),v=s(j,v,T),C===null?I=j:C.sibling=j,C=j,k=O}if(_.done)return t(y,k),nt&&wi(y,T),I;if(k===null){for(;!_.done;T++,_=b.next())_=h(y,_.value,E),_!==null&&(v=s(_,v,T),C===null?I=_:C.sibling=_,C=_);return nt&&wi(y,T),I}for(k=r(y,k);!_.done;T++,_=b.next())_=f(k,y,T,_.value,E),_!==null&&(e&&_.alternate!==null&&k.delete(_.key===null?T:_.key),v=s(_,v,T),C===null?I=_:C.sibling=_,C=_);return e&&k.forEach(function(L){return n(y,L)}),nt&&wi(y,T),I}function x(y,v,b,E){if(typeof b=="object"&&b!==null&&b.type===ka&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case ud:e:{for(var I=b.key,C=v;C!==null;){if(C.key===I){if(I=b.type,I===ka){if(C.tag===7){t(y,C.sibling),v=o(C,b.props.children),v.return=y,y=v;break e}}else if(C.elementType===I||typeof I=="object"&&I!==null&&I.$$typeof===ws&&d1(I)===C.type){t(y,C.sibling),v=o(C,b.props),v.ref=Zl(y,C,b),v.return=y,y=v;break e}t(y,C);break}else n(y,C);C=C.sibling}b.type===ka?(v=Ai(b.props.children,y.mode,E,b.key),v.return=y,y=v):(E=Ph(b.type,b.key,b.props,null,y.mode,E),E.ref=Zl(y,v,b),E.return=y,y=E)}return i(y);case Ea:e:{for(C=b.key;v!==null;){if(v.key===C)if(v.tag===4&&v.stateNode.containerInfo===b.containerInfo&&v.stateNode.implementation===b.implementation){t(y,v.sibling),v=o(v,b.children||[]),v.return=y,y=v;break e}else{t(y,v);break}else n(y,v);v=v.sibling}v=fm(b,y.mode,E),v.return=y,y=v}return i(y);case ws:return C=b._init,x(y,v,C(b._payload),E)}if(Sc(b))return S(y,v,b,E);if(Gl(b))return g(y,v,b,E);wd(y,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,v!==null&&v.tag===6?(t(y,v.sibling),v=o(v,b),v.return=y,y=v):(t(y,v),v=pm(b,y.mode,E),v.return=y,y=v),i(y)):t(y,v)}return x}var cl=bk(!0),Pk=bk(!1),_p=ni(null),Tp=null,Ra=null,Px=null;function Cx(){Px=Ra=Tp=null}function Ix(e){var n=_p.current;Je(_p),e._currentValue=n}function kS(e,n,t){for(;e!==null;){var r=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,r!==null&&(r.childLanes|=n)):r!==null&&(r.childLanes&n)!==n&&(r.childLanes|=n),e===t)break;e=e.return}}function Qa(e,n){Tp=e,Px=Ra=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(jn=!0),e.firstContext=null)}function Cr(e){var n=e._currentValue;if(Px!==e)if(e={context:e,memoizedValue:n,next:null},Ra===null){if(Tp===null)throw Error(q(308));Ra=e,Tp.dependencies={lanes:0,firstContext:e}}else Ra=Ra.next=e;return n}var Ii=null;function Ex(e){Ii===null?Ii=[e]:Ii.push(e)}function Ck(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,Ex(n)):(t.next=o.next,o.next=t),n.interleaved=t,Xo(e,r)}function Xo(e,n){e.lanes|=n;var t=e.alternate;for(t!==null&&(t.lanes|=n),t=e,e=e.return;e!==null;)e.childLanes|=n,t=e.alternate,t!==null&&(t.childLanes|=n),t=e,e=e.return;return t.tag===3?t.stateNode:null}var bs=!1;function kx(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Ik(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Uo(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Rs(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,ke&2){var o=r.pending;return o===null?n.next=n:(n.next=o.next,o.next=n),r.pending=n,Xo(e,t)}return o=r.interleaved,o===null?(n.next=n,Ex(r)):(n.next=o.next,o.next=n),r.interleaved=n,Xo(e,t)}function yh(e,n,t){if(n=n.updateQueue,n!==null&&(n=n.shared,(t&4194240)!==0)){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,hx(e,t)}}function h1(e,n){var t=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,t===r)){var o=null,s=null;if(t=t.firstBaseUpdate,t!==null){do{var i={eventTime:t.eventTime,lane:t.lane,tag:t.tag,payload:t.payload,callback:t.callback,next:null};s===null?o=s=i:s=s.next=i,t=t.next}while(t!==null);s===null?o=s=n:s=s.next=n}else o=s=n;t={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:s,shared:r.shared,effects:r.effects},e.updateQueue=t;return}e=t.lastBaseUpdate,e===null?t.firstBaseUpdate=n:e.next=n,t.lastBaseUpdate=n}function Mp(e,n,t,r){var o=e.updateQueue;bs=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var l=a,c=l.next;l.next=null,i===null?s=c:i.next=c,i=l;var d=e.alternate;d!==null&&(d=d.updateQueue,a=d.lastBaseUpdate,a!==i&&(a===null?d.firstBaseUpdate=c:a.next=c,d.lastBaseUpdate=l))}if(s!==null){var h=o.baseState;i=0,d=c=l=null,a=s;do{var p=a.lane,f=a.eventTime;if((r&p)===p){d!==null&&(d=d.next={eventTime:f,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var S=e,g=a;switch(p=n,f=t,g.tag){case 1:if(S=g.payload,typeof S=="function"){h=S.call(f,h,p);break e}h=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=g.payload,p=typeof S=="function"?S.call(f,h,p):S,p==null)break e;h=pt({},h,p);break e;case 2:bs=!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},d===null?(c=d=f,l=h):d=d.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(d===null&&(l=h),o.baseState=l,o.firstBaseUpdate=c,o.lastBaseUpdate=d,n=o.shared.interleaved,n!==null){o=n;do i|=o.lane,o=o.next;while(o!==n)}else s===null&&(o.shared.lanes=0);Ni|=i,e.lanes=i,e.memoizedState=h}}function p1(e,n,t){if(e=n.effects,n.effects=null,e!==null)for(n=0;n<e.length;n++){var r=e[n],o=r.callback;if(o!==null){if(r.callback=null,r=t,typeof o!="function")throw Error(q(191,o));o.call(r)}}}var Tu={},po=ni(Tu),nu=ni(Tu),ru=ni(Tu);function Ei(e){if(e===Tu)throw Error(q(174));return e}function _x(e,n){switch(Ge(ru,n),Ge(nu,e),Ge(po,Tu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:aS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=aS(n,e)}Je(po),Ge(po,n)}function ul(){Je(po),Je(nu),Je(ru)}function Ek(e){Ei(ru.current);var n=Ei(po.current),t=aS(n,e.type);n!==t&&(Ge(nu,e),Ge(po,t))}function Tx(e){nu.current===e&&(Je(po),Je(nu))}var ct=ni(0);function jp(e){for(var n=e;n!==null;){if(n.tag===13){var t=n.memoizedState;if(t!==null&&(t=t.dehydrated,t===null||t.data==="$?"||t.data==="$!"))return n}else if(n.tag===19&&n.memoizedProps.revealOrder!==void 0){if(n.flags&128)return n}else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return null;n=n.return}n.sibling.return=n.return,n=n.sibling}return null}var am=[];function Mx(){for(var e=0;e<am.length;e++)am[e]._workInProgressVersionPrimary=null;am.length=0}var Sh=ns.ReactCurrentDispatcher,lm=ns.ReactCurrentBatchConfig,Fi=0,ht=null,It=null,Tt=null,Ap=!1,Dc=!1,ou=0,GF=0;function Zt(){throw Error(q(321))}function jx(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Ur(e[t],n[t]))return!1;return!0}function Ax(e,n,t,r,o,s){if(Fi=s,ht=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Sh.current=e===null||e.memoizedState===null?qF:ZF,e=t(r,o),Dc){s=0;do{if(Dc=!1,ou=0,25<=s)throw Error(q(301));s+=1,Tt=It=null,n.updateQueue=null,Sh.current=QF,e=t(r,o)}while(Dc)}if(Sh.current=Op,n=It!==null&&It.next!==null,Fi=0,Tt=It=ht=null,Ap=!1,n)throw Error(q(300));return e}function Ox(){var e=ou!==0;return ou=0,e}function to(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Tt===null?ht.memoizedState=Tt=e:Tt=Tt.next=e,Tt}function Ir(){if(It===null){var e=ht.alternate;e=e!==null?e.memoizedState:null}else e=It.next;var n=Tt===null?ht.memoizedState:Tt.next;if(n!==null)Tt=n,It=e;else{if(e===null)throw Error(q(310));It=e,e={memoizedState:It.memoizedState,baseState:It.baseState,baseQueue:It.baseQueue,queue:It.queue,next:null},Tt===null?ht.memoizedState=Tt=e:Tt=Tt.next=e}return Tt}function su(e,n){return typeof n=="function"?n(e):n}function cm(e){var n=Ir(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=It,o=r.baseQueue,s=t.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,t.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,l=null,c=s;do{var d=c.lane;if((Fi&d)===d)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:e(r,c.action);else{var h={lane:d,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=h,i=r):l=l.next=h,ht.lanes|=d,Ni|=d}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Ur(r,n.memoizedState)||(jn=!0),n.memoizedState=r,n.baseState=i,n.baseQueue=l,t.lastRenderedState=r}if(e=t.interleaved,e!==null){o=e;do s=o.lane,ht.lanes|=s,Ni|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function um(e){var n=Ir(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=t.dispatch,o=t.pending,s=n.memoizedState;if(o!==null){t.pending=null;var i=o=o.next;do s=e(s,i.action),i=i.next;while(i!==o);Ur(s,n.memoizedState)||(jn=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function kk(){}function _k(e,n){var t=ht,r=Ir(),o=n(),s=!Ur(r.memoizedState,o);if(s&&(r.memoizedState=o,jn=!0),r=r.queue,Dx(jk.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||Tt!==null&&Tt.memoizedState.tag&1){if(t.flags|=2048,iu(9,Mk.bind(null,t,r,o,n),void 0,null),Ot===null)throw Error(q(349));Fi&30||Tk(t,n,o)}return o}function Tk(e,n,t){e.flags|=16384,e={getSnapshot:n,value:t},n=ht.updateQueue,n===null?(n={lastEffect:null,stores:null},ht.updateQueue=n,n.stores=[e]):(t=n.stores,t===null?n.stores=[e]:t.push(e))}function Mk(e,n,t,r){n.value=t,n.getSnapshot=r,Ak(n)&&Ok(e)}function jk(e,n,t){return t(function(){Ak(n)&&Ok(e)})}function Ak(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Ur(e,t)}catch{return!0}}function Ok(e){var n=Xo(e,1);n!==null&&zr(n,e,1,-1)}function f1(e){var n=to();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:su,lastRenderedState:e},n.queue=e,e=e.dispatch=XF.bind(null,ht,e),[n.memoizedState,e]}function iu(e,n,t,r){return e={tag:e,create:n,destroy:t,deps:r,next:null},n=ht.updateQueue,n===null?(n={lastEffect:null,stores:null},ht.updateQueue=n,n.lastEffect=e.next=e):(t=n.lastEffect,t===null?n.lastEffect=e.next=e:(r=t.next,t.next=e,e.next=r,n.lastEffect=e)),e}function Dk(){return Ir().memoizedState}function vh(e,n,t,r){var o=to();ht.flags|=e,o.memoizedState=iu(1|n,t,void 0,r===void 0?null:r)}function Rf(e,n,t,r){var o=Ir();r=r===void 0?null:r;var s=void 0;if(It!==null){var i=It.memoizedState;if(s=i.destroy,r!==null&&jx(r,i.deps)){o.memoizedState=iu(n,t,s,r);return}}ht.flags|=e,o.memoizedState=iu(1|n,t,s,r)}function g1(e,n){return vh(8390656,8,e,n)}function Dx(e,n){return Rf(2048,8,e,n)}function Rk(e,n){return Rf(4,2,e,n)}function Lk(e,n){return Rf(4,4,e,n)}function $k(e,n){if(typeof n=="function")return e=e(),n(e),function(){n(null)};if(n!=null)return e=e(),n.current=e,function(){n.current=null}}function Fk(e,n,t){return t=t!=null?t.concat([e]):null,Rf(4,4,$k.bind(null,n,e),t)}function Rx(){}function Nk(e,n){var t=Ir();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&jx(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function zk(e,n){var t=Ir();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&jx(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function Bk(e,n,t){return Fi&21?(Ur(t,n)||(t=GE(),ht.lanes|=t,Ni|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,jn=!0),e.memoizedState=t)}function VF(e,n){var t=Fe;Fe=t!==0&&4>t?t:4,e(!0);var r=lm.transition;lm.transition={};try{e(!1),n()}finally{Fe=t,lm.transition=r}}function Uk(){return Ir().memoizedState}function YF(e,n,t){var r=$s(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},Hk(e))Kk(n,t);else if(t=Ck(e,n,t,r),t!==null){var o=mn();zr(t,e,r,o),Wk(t,n,r)}}function XF(e,n,t){var r=$s(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(Hk(e))Kk(n,o);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=n.lastRenderedReducer,s!==null))try{var i=n.lastRenderedState,a=s(i,t);if(o.hasEagerState=!0,o.eagerState=a,Ur(a,i)){var l=n.interleaved;l===null?(o.next=o,Ex(n)):(o.next=l.next,l.next=o),n.interleaved=o;return}}catch{}finally{}t=Ck(e,n,o,r),t!==null&&(o=mn(),zr(t,e,r,o),Wk(t,n,r))}}function Hk(e){var n=e.alternate;return e===ht||n!==null&&n===ht}function Kk(e,n){Dc=Ap=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function Wk(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,hx(e,t)}}var Op={readContext:Cr,useCallback:Zt,useContext:Zt,useEffect:Zt,useImperativeHandle:Zt,useInsertionEffect:Zt,useLayoutEffect:Zt,useMemo:Zt,useReducer:Zt,useRef:Zt,useState:Zt,useDebugValue:Zt,useDeferredValue:Zt,useTransition:Zt,useMutableSource:Zt,useSyncExternalStore:Zt,useId:Zt,unstable_isNewReconciler:!1},qF={readContext:Cr,useCallback:function(e,n){return to().memoizedState=[e,n===void 0?null:n],e},useContext:Cr,useEffect:g1,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,vh(4194308,4,$k.bind(null,n,e),t)},useLayoutEffect:function(e,n){return vh(4194308,4,e,n)},useInsertionEffect:function(e,n){return vh(4,2,e,n)},useMemo:function(e,n){var t=to();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=to();return n=t!==void 0?t(n):n,r.memoizedState=r.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},r.queue=e,e=e.dispatch=YF.bind(null,ht,e),[r.memoizedState,e]},useRef:function(e){var n=to();return e={current:e},n.memoizedState=e},useState:f1,useDebugValue:Rx,useDeferredValue:function(e){return to().memoizedState=e},useTransition:function(){var e=f1(!1),n=e[0];return e=VF.bind(null,e[1]),to().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=ht,o=to();if(nt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),Ot===null)throw Error(q(349));Fi&30||Tk(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,g1(jk.bind(null,r,s,e),[e]),r.flags|=2048,iu(9,Mk.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=to(),n=Ot.identifierPrefix;if(nt){var t=No,r=Fo;t=(r&~(1<<32-Nr(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=ou++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=GF++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},ZF={readContext:Cr,useCallback:Nk,useContext:Cr,useEffect:Dx,useImperativeHandle:Fk,useInsertionEffect:Rk,useLayoutEffect:Lk,useMemo:zk,useReducer:cm,useRef:Dk,useState:function(){return cm(su)},useDebugValue:Rx,useDeferredValue:function(e){var n=Ir();return Bk(n,It.memoizedState,e)},useTransition:function(){var e=cm(su)[0],n=Ir().memoizedState;return[e,n]},useMutableSource:kk,useSyncExternalStore:_k,useId:Uk,unstable_isNewReconciler:!1},QF={readContext:Cr,useCallback:Nk,useContext:Cr,useEffect:Dx,useImperativeHandle:Fk,useInsertionEffect:Rk,useLayoutEffect:Lk,useMemo:zk,useReducer:um,useRef:Dk,useState:function(){return um(su)},useDebugValue:Rx,useDeferredValue:function(e){var n=Ir();return It===null?n.memoizedState=e:Bk(n,It.memoizedState,e)},useTransition:function(){var e=um(su)[0],n=Ir().memoizedState;return[e,n]},useMutableSource:kk,useSyncExternalStore:_k,useId:Uk,unstable_isNewReconciler:!1};function jr(e,n){if(e&&e.defaultProps){n=pt({},n),e=e.defaultProps;for(var t in e)n[t]===void 0&&(n[t]=e[t]);return n}return n}function _S(e,n,t,r){n=e.memoizedState,t=t(r,n),t=t==null?n:pt({},n,t),e.memoizedState=t,e.lanes===0&&(e.updateQueue.baseState=t)}var Lf={isMounted:function(e){return(e=e._reactInternals)?na(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=mn(),o=$s(e),s=Uo(r,o);s.payload=n,t!=null&&(s.callback=t),n=Rs(e,s,o),n!==null&&(zr(n,e,o,r),yh(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=mn(),o=$s(e),s=Uo(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=Rs(e,s,o),n!==null&&(zr(n,e,o,r),yh(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=mn(),r=$s(e),o=Uo(t,r);o.tag=2,n!=null&&(o.callback=n),n=Rs(e,o,r),n!==null&&(zr(n,e,r,t),yh(n,e,r))}};function m1(e,n,t,r,o,s,i){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,s,i):n.prototype&&n.prototype.isPureReactComponent?!Qc(t,r)||!Qc(o,s):!0}function Gk(e,n,t){var r=!1,o=Ws,s=n.contextType;return typeof s=="object"&&s!==null?s=Cr(s):(o=Ln(n)?Li:ln.current,r=n.contextTypes,s=(r=r!=null)?al(e,o):Ws),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Lf,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function y1(e,n,t,r){e=n.state,typeof n.componentWillReceiveProps=="function"&&n.componentWillReceiveProps(t,r),typeof n.UNSAFE_componentWillReceiveProps=="function"&&n.UNSAFE_componentWillReceiveProps(t,r),n.state!==e&&Lf.enqueueReplaceState(n,n.state,null)}function TS(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs={},kx(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=Cr(s):(s=Ln(n)?Li:ln.current,o.context=al(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(_S(e,n,s,t),o.state=e.memoizedState),typeof n.getDerivedStateFromProps=="function"||typeof o.getSnapshotBeforeUpdate=="function"||typeof o.UNSAFE_componentWillMount!="function"&&typeof o.componentWillMount!="function"||(n=o.state,typeof o.componentWillMount=="function"&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount=="function"&&o.UNSAFE_componentWillMount(),n!==o.state&&Lf.enqueueReplaceState(o,o.state,null),Mp(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function dl(e,n){try{var t="",r=n;do t+=E$(r),r=r.return;while(r);var o=t}catch(s){o=`
|
|
Error generating stack: `+s.message+`
|
|
`+s.stack}return{value:e,source:n,stack:o,digest:null}}function dm(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function MS(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var JF=typeof WeakMap=="function"?WeakMap:Map;function Vk(e,n,t){t=Uo(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){Rp||(Rp=!0,zS=r),MS(e,n)},t}function Yk(e,n,t){t=Uo(-1,t),t.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var o=n.value;t.payload=function(){return r(o)},t.callback=function(){MS(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){MS(e,n),typeof r!="function"&&(Ls===null?Ls=new Set([this]):Ls.add(this));var i=n.stack;this.componentDidCatch(n.value,{componentStack:i!==null?i:""})}),t}function S1(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new JF;var o=new Set;r.set(n,o)}else o=r.get(n),o===void 0&&(o=new Set,r.set(n,o));o.has(t)||(o.add(t),e=pN.bind(null,e,n,t),n.then(e,e))}function v1(e){do{var n;if((n=e.tag===13)&&(n=e.memoizedState,n=n!==null?n.dehydrated!==null:!0),n)return e;e=e.return}while(e!==null);return null}function x1(e,n,t,r,o){return e.mode&1?(e.flags|=65536,e.lanes=o,e):(e===n?e.flags|=65536:(e.flags|=128,t.flags|=131072,t.flags&=-52805,t.tag===1&&(t.alternate===null?t.tag=17:(n=Uo(-1,1),n.tag=2,Rs(t,n,1))),t.lanes|=1),e)}var eN=ns.ReactCurrentOwner,jn=!1;function fn(e,n,t,r){n.child=e===null?Pk(n,null,t,r):cl(n,e.child,t,r)}function w1(e,n,t,r,o){t=t.render;var s=n.ref;return Qa(n,o),r=Ax(e,n,t,r,s,o),t=Ox(),e!==null&&!jn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,qo(e,n,o)):(nt&&t&&xx(n),n.flags|=1,fn(e,n,r,o),n.child)}function b1(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!Hx(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,Xk(e,n,s,r,o)):(e=Ph(t.type,null,r,n,n.mode,o),e.ref=n.ref,e.return=n,n.child=e)}if(s=e.child,!(e.lanes&o)){var i=s.memoizedProps;if(t=t.compare,t=t!==null?t:Qc,t(i,r)&&e.ref===n.ref)return qo(e,n,o)}return n.flags|=1,e=Fs(s,r),e.ref=n.ref,e.return=n,n.child=e}function Xk(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(Qc(s,r)&&e.ref===n.ref)if(jn=!1,n.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(jn=!0);else return n.lanes=e.lanes,qo(e,n,o)}return jS(e,n,t,r,o)}function qk(e,n,t){var r=n.pendingProps,o=r.children,s=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ge($a,Yn),Yn|=t;else{if(!(t&1073741824))return e=s!==null?s.baseLanes|t:t,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Ge($a,Yn),Yn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ge($a,Yn),Yn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ge($a,Yn),Yn|=r;return fn(e,n,o,t),n.child}function Zk(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function jS(e,n,t,r,o){var s=Ln(t)?Li:ln.current;return s=al(n,s),Qa(n,o),t=Ax(e,n,t,r,s,o),r=Ox(),e!==null&&!jn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,qo(e,n,o)):(nt&&r&&xx(n),n.flags|=1,fn(e,n,t,o),n.child)}function P1(e,n,t,r,o){if(Ln(t)){var s=!0;Ip(n)}else s=!1;if(Qa(n,o),n.stateNode===null)xh(e,n),Gk(n,t,r),TS(n,t,r,o),r=!0;else if(e===null){var i=n.stateNode,a=n.memoizedProps;i.props=a;var l=i.context,c=t.contextType;typeof c=="object"&&c!==null?c=Cr(c):(c=Ln(t)?Li:ln.current,c=al(n,c));var d=t.getDerivedStateFromProps,h=typeof d=="function"||typeof i.getSnapshotBeforeUpdate=="function";h||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&y1(n,i,r,c),bs=!1;var p=n.memoizedState;i.state=p,Mp(n,r,i,o),l=n.memoizedState,a!==r||p!==l||Rn.current||bs?(typeof d=="function"&&(_S(n,t,d,r),l=n.memoizedState),(a=bs||m1(n,t,a,r,p,l,c))?(h||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"&&(n.flags|=4194308)):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=l),i.props=r,i.state=l,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{i=n.stateNode,Ik(e,n),a=n.memoizedProps,c=n.type===n.elementType?a:jr(n.type,a),i.props=c,h=n.pendingProps,p=i.context,l=t.contextType,typeof l=="object"&&l!==null?l=Cr(l):(l=Ln(t)?Li:ln.current,l=al(n,l));var f=t.getDerivedStateFromProps;(d=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==h||p!==l)&&y1(n,i,r,l),bs=!1,p=n.memoizedState,i.state=p,Mp(n,r,i,o);var S=n.memoizedState;a!==h||p!==S||Rn.current||bs?(typeof f=="function"&&(_S(n,t,f,r),S=n.memoizedState),(c=bs||m1(n,t,c,r,p,S,l)||!1)?(d||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,S,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,S,l)),typeof i.componentDidUpdate=="function"&&(n.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=S),i.props=r,i.state=S,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=1024),r=!1)}return AS(e,n,t,r,s,o)}function AS(e,n,t,r,o,s){Zk(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&l1(n,t,!1),qo(e,n,s);r=n.stateNode,eN.current=n;var a=i&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&i?(n.child=cl(n,e.child,null,s),n.child=cl(n,null,a,s)):fn(e,n,a,s),n.memoizedState=r.state,o&&l1(n,t,!0),n.child}function Qk(e){var n=e.stateNode;n.pendingContext?a1(e,n.pendingContext,n.pendingContext!==n.context):n.context&&a1(e,n.context,!1),_x(e,n.containerInfo)}function C1(e,n,t,r,o){return ll(),bx(o),n.flags|=256,fn(e,n,t,r),n.child}var OS={dehydrated:null,treeContext:null,retryLane:0};function DS(e){return{baseLanes:e,cachePool:null,transitions:null}}function Jk(e,n,t){var r=n.pendingProps,o=ct.current,s=!1,i=(n.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(s=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ge(ct,o&1),e===null)return ES(n),e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(n.mode&1?e.data==="$!"?n.lanes=8:n.lanes=1073741824:n.lanes=1,null):(i=r.children,e=r.fallback,s?(r=n.mode,s=n.child,i={mode:"hidden",children:i},!(r&1)&&s!==null?(s.childLanes=0,s.pendingProps=i):s=Nf(i,r,0,null),e=Ai(e,r,t,null),s.return=n,e.return=n,s.sibling=e,n.child=s,n.child.memoizedState=DS(t),n.memoizedState=OS,e):Lx(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return tN(e,n,i,r,a,o,t);if(s){s=r.fallback,i=n.mode,o=e.child,a=o.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&n.child!==o?(r=n.child,r.childLanes=0,r.pendingProps=l,n.deletions=null):(r=Fs(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Fs(a,s):(s=Ai(s,i,t,null),s.flags|=2),s.return=n,r.return=n,r.sibling=s,n.child=r,r=s,s=n.child,i=e.child.memoizedState,i=i===null?DS(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=OS,r}return s=e.child,e=s.sibling,r=Fs(s,{mode:"visible",children:r.children}),!(n.mode&1)&&(r.lanes=t),r.return=n,r.sibling=null,e!==null&&(t=n.deletions,t===null?(n.deletions=[e],n.flags|=16):t.push(e)),n.child=r,n.memoizedState=null,r}function Lx(e,n){return n=Nf({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function bd(e,n,t,r){return r!==null&&bx(r),cl(n,e.child,null,t),e=Lx(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function tN(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=dm(Error(q(422))),bd(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=Nf({mode:"visible",children:r.children},o,0,null),s=Ai(s,o,i,null),s.flags|=2,r.return=n,s.return=n,r.sibling=s,n.child=r,n.mode&1&&cl(n,e.child,null,i),n.child.memoizedState=DS(i),n.memoizedState=OS,s);if(!(n.mode&1))return bd(e,n,i,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var a=r.dgst;return r=a,s=Error(q(419)),r=dm(s,r,void 0),bd(e,n,i,r)}if(a=(i&e.childLanes)!==0,jn||a){if(r=Ot,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,Xo(e,o),zr(r,e,o,-1))}return Ux(),r=dm(Error(q(421))),bd(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=fN.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,Zn=Ds(o.nextSibling),Qn=n,nt=!0,Rr=null,e!==null&&(mr[yr++]=Fo,mr[yr++]=No,mr[yr++]=$i,Fo=e.id,No=e.overflow,$i=n),n=Lx(n,r.children),n.flags|=4096,n)}function I1(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),kS(e.return,n,t)}function hm(e,n,t,r,o){var s=e.memoizedState;s===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:t,tailMode:o}:(s.isBackwards=n,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=t,s.tailMode=o)}function e_(e,n,t){var r=n.pendingProps,o=r.revealOrder,s=r.tail;if(fn(e,n,r.children,t),r=ct.current,r&2)r=r&1|2,n.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&I1(e,t,n);else if(e.tag===19)I1(e,t,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Ge(ct,r),!(n.mode&1))n.memoizedState=null;else switch(o){case"forwards":for(t=n.child,o=null;t!==null;)e=t.alternate,e!==null&&jp(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),hm(n,!1,o,t,s);break;case"backwards":for(t=null,o=n.child,n.child=null;o!==null;){if(e=o.alternate,e!==null&&jp(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}hm(n,!0,t,null,s);break;case"together":hm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function xh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function qo(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),Ni|=n.lanes,!(t&n.childLanes))return null;if(e!==null&&n.child!==e.child)throw Error(q(153));if(n.child!==null){for(e=n.child,t=Fs(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=Fs(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function nN(e,n,t){switch(n.tag){case 3:Qk(n),ll();break;case 5:Ek(n);break;case 1:Ln(n.type)&&Ip(n);break;case 4:_x(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ge(_p,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ge(ct,ct.current&1),n.flags|=128,null):t&n.child.childLanes?Jk(e,n,t):(Ge(ct,ct.current&1),e=qo(e,n,t),e!==null?e.sibling:null);Ge(ct,ct.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return e_(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ge(ct,ct.current),r)break;return null;case 22:case 23:return n.lanes=0,qk(e,n,t)}return qo(e,n,t)}var t_,RS,n_,r_;t_=function(e,n){for(var t=n.child;t!==null;){if(t.tag===5||t.tag===6)e.appendChild(t.stateNode);else if(t.tag!==4&&t.child!==null){t.child.return=t,t=t.child;continue}if(t===n)break;for(;t.sibling===null;){if(t.return===null||t.return===n)return;t=t.return}t.sibling.return=t.return,t=t.sibling}};RS=function(){};n_=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,Ei(po.current);var s=null;switch(t){case"input":o=rS(e,o),r=rS(e,r),s=[];break;case"select":o=pt({},o,{value:void 0}),r=pt({},r,{value:void 0}),s=[];break;case"textarea":o=iS(e,o),r=iS(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Pp)}lS(t,r);var i;t=null;for(c in o)if(!r.hasOwnProperty(c)&&o.hasOwnProperty(c)&&o[c]!=null)if(c==="style"){var a=o[c];for(i in a)a.hasOwnProperty(i)&&(t||(t={}),t[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Wc.hasOwnProperty(c)?s||(s=[]):(s=s||[]).push(c,null));for(c in r){var l=r[c];if(a=o!=null?o[c]:void 0,r.hasOwnProperty(c)&&l!==a&&(l!=null||a!=null))if(c==="style")if(a){for(i in a)!a.hasOwnProperty(i)||l&&l.hasOwnProperty(i)||(t||(t={}),t[i]="");for(i in l)l.hasOwnProperty(i)&&a[i]!==l[i]&&(t||(t={}),t[i]=l[i])}else t||(s||(s=[]),s.push(c,t)),t=l;else c==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,a=a?a.__html:void 0,l!=null&&a!==l&&(s=s||[]).push(c,l)):c==="children"?typeof l!="string"&&typeof l!="number"||(s=s||[]).push(c,""+l):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(Wc.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&Ze("scroll",e),s||a===l||(s=[])):(s=s||[]).push(c,l))}t&&(s=s||[]).push("style",t);var c=s;(n.updateQueue=c)&&(n.flags|=4)}};r_=function(e,n,t,r){t!==r&&(n.flags|=4)};function Ql(e,n){if(!nt)switch(e.tailMode){case"hidden":n=e.tail;for(var t=null;n!==null;)n.alternate!==null&&(t=n),n=n.sibling;t===null?e.tail=null:t.sibling=null;break;case"collapsed":t=e.tail;for(var r=null;t!==null;)t.alternate!==null&&(r=t),t=t.sibling;r===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Qt(e){var n=e.alternate!==null&&e.alternate.child===e.child,t=0,r=0;if(n)for(var o=e.child;o!==null;)t|=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;)t|=o.lanes|o.childLanes,r|=o.subtreeFlags,r|=o.flags,o.return=e,o=o.sibling;return e.subtreeFlags|=r,e.childLanes=t,n}function rN(e,n,t){var r=n.pendingProps;switch(wx(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Qt(n),null;case 1:return Ln(n.type)&&Cp(),Qt(n),null;case 3:return r=n.stateNode,ul(),Je(Rn),Je(ln),Mx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(xd(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Rr!==null&&(HS(Rr),Rr=null))),RS(e,n),Qt(n),null;case 5:Tx(n);var o=Ei(ru.current);if(t=n.type,e!==null&&n.stateNode!=null)n_(e,n,t,r,o),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!r){if(n.stateNode===null)throw Error(q(166));return Qt(n),null}if(e=Ei(po.current),xd(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[oo]=n,r[tu]=s,e=(n.mode&1)!==0,t){case"dialog":Ze("cancel",r),Ze("close",r);break;case"iframe":case"object":case"embed":Ze("load",r);break;case"video":case"audio":for(o=0;o<xc.length;o++)Ze(xc[o],r);break;case"source":Ze("error",r);break;case"img":case"image":case"link":Ze("error",r),Ze("load",r);break;case"details":Ze("toggle",r);break;case"input":Db(r,s),Ze("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Ze("invalid",r);break;case"textarea":Lb(r,s),Ze("invalid",r)}lS(t,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&&vd(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&vd(r.textContent,a,e),o=["children",""+a]):Wc.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Ze("scroll",r)}switch(t){case"input":dd(r),Rb(r,s,!0);break;case"textarea":dd(r),$b(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Pp)}r=o,n.updateQueue=r,r!==null&&(n.flags|=4)}else{i=o.nodeType===9?o:o.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=jE(t)),e==="http://www.w3.org/1999/xhtml"?t==="script"?(e=i.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(t,{is:r.is}):(e=i.createElement(t),t==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,t),e[oo]=n,e[tu]=r,t_(e,n,!1,!1),n.stateNode=e;e:{switch(i=cS(t,r),t){case"dialog":Ze("cancel",e),Ze("close",e),o=r;break;case"iframe":case"object":case"embed":Ze("load",e),o=r;break;case"video":case"audio":for(o=0;o<xc.length;o++)Ze(xc[o],e);o=r;break;case"source":Ze("error",e),o=r;break;case"img":case"image":case"link":Ze("error",e),Ze("load",e),o=r;break;case"details":Ze("toggle",e),o=r;break;case"input":Db(e,r),o=rS(e,r),Ze("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=pt({},r,{value:void 0}),Ze("invalid",e);break;case"textarea":Lb(e,r),o=iS(e,r),Ze("invalid",e);break;default:o=r}lS(t,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?DE(e,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&AE(e,l)):s==="children"?typeof l=="string"?(t!=="textarea"||l!=="")&&Gc(e,l):typeof l=="number"&&Gc(e,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Wc.hasOwnProperty(s)?l!=null&&s==="onScroll"&&Ze("scroll",e):l!=null&&ix(e,s,l,i))}switch(t){case"input":dd(e),Rb(e,r,!1);break;case"textarea":dd(e),$b(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Ks(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?Ya(e,!!r.multiple,s,!1):r.defaultValue!=null&&Ya(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Pp)}switch(t){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return Qt(n),null;case 6:if(e&&n.stateNode!=null)r_(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=Ei(ru.current),Ei(po.current),xd(n)){if(r=n.stateNode,t=n.memoizedProps,r[oo]=n,(s=r.nodeValue!==t)&&(e=Qn,e!==null))switch(e.tag){case 3:vd(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&vd(r.nodeValue,t,(e.mode&1)!==0)}s&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[oo]=n,n.stateNode=r}return Qt(n),null;case 13:if(Je(ct),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(nt&&Zn!==null&&n.mode&1&&!(n.flags&128))wk(),ll(),n.flags|=98560,s=!1;else if(s=xd(n),r!==null&&r.dehydrated!==null){if(e===null){if(!s)throw Error(q(318));if(s=n.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(q(317));s[oo]=n}else ll(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Qt(n),s=!1}else Rr!==null&&(HS(Rr),Rr=null),s=!0;if(!s)return n.flags&65536?n:null}return n.flags&128?(n.lanes=t,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||ct.current&1?Et===0&&(Et=3):Ux())),n.updateQueue!==null&&(n.flags|=4),Qt(n),null);case 4:return ul(),RS(e,n),e===null&&Jc(n.stateNode.containerInfo),Qt(n),null;case 10:return Ix(n.type._context),Qt(n),null;case 17:return Ln(n.type)&&Cp(),Qt(n),null;case 19:if(Je(ct),s=n.memoizedState,s===null)return Qt(n),null;if(r=(n.flags&128)!==0,i=s.rendering,i===null)if(r)Ql(s,!1);else{if(Et!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=jp(e),i!==null){for(n.flags|=128,Ql(s,!1),r=i.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=t,t=n.child;t!==null;)s=t,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}),t=t.sibling;return Ge(ct,ct.current&1|2),n.child}e=e.sibling}s.tail!==null&&xt()>hl&&(n.flags|=128,r=!0,Ql(s,!1),n.lanes=4194304)}else{if(!r)if(e=jp(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),Ql(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!nt)return Qt(n),null}else 2*xt()-s.renderingStartTime>hl&&t!==1073741824&&(n.flags|=128,r=!0,Ql(s,!1),n.lanes=4194304);s.isBackwards?(i.sibling=n.child,n.child=i):(t=s.last,t!==null?t.sibling=i:n.child=i,s.last=i)}return s.tail!==null?(n=s.tail,s.rendering=n,s.tail=n.sibling,s.renderingStartTime=xt(),n.sibling=null,t=ct.current,Ge(ct,r?t&1|2:t&1),n):(Qt(n),null);case 22:case 23:return Bx(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Yn&1073741824&&(Qt(n),n.subtreeFlags&6&&(n.flags|=8192)):Qt(n),null;case 24:return null;case 25:return null}throw Error(q(156,n.tag))}function oN(e,n){switch(wx(n),n.tag){case 1:return Ln(n.type)&&Cp(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return ul(),Je(Rn),Je(ln),Mx(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return Tx(n),null;case 13:if(Je(ct),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));ll()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Je(ct),null;case 4:return ul(),null;case 10:return Ix(n.type._context),null;case 22:case 23:return Bx(),null;case 24:return null;default:return null}}var Pd=!1,rn=!1,sN=typeof WeakSet=="function"?WeakSet:Set,te=null;function La(e,n){var t=e.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){mt(e,n,r)}else t.current=null}function LS(e,n,t){try{t()}catch(r){mt(e,n,r)}}var E1=!1;function iN(e,n){if(vS=xp,e=lk(),vx(e)){if("selectionStart"in e)var t={start:e.selectionStart,end:e.selectionEnd};else e:{t=(t=e.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{t.nodeType,s.nodeType}catch{t=null;break e}var i=0,a=-1,l=-1,c=0,d=0,h=e,p=null;t:for(;;){for(var f;h!==t||o!==0&&h.nodeType!==3||(a=i+o),h!==s||r!==0&&h.nodeType!==3||(l=i+r),h.nodeType===3&&(i+=h.nodeValue.length),(f=h.firstChild)!==null;)p=h,h=f;for(;;){if(h===e)break t;if(p===t&&++c===o&&(a=i),p===s&&++d===r&&(l=i),(f=h.nextSibling)!==null)break;h=p,p=h.parentNode}h=f}t=a===-1||l===-1?null:{start:a,end:l}}else t=null}t=t||{start:0,end:0}}else t=null;for(xS={focusedElem:e,selectionRange:t},xp=!1,te=n;te!==null;)if(n=te,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,te=e;else for(;te!==null;){n=te;try{var S=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var g=S.memoizedProps,x=S.memoizedState,y=n.stateNode,v=y.getSnapshotBeforeUpdate(n.elementType===n.type?g:jr(n.type,g),x);y.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var b=n.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(q(163))}}catch(E){mt(n,n.return,E)}if(e=n.sibling,e!==null){e.return=n.return,te=e;break}te=n.return}return S=E1,E1=!1,S}function Rc(e,n,t){var r=n.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&&LS(n,t,s)}o=o.next}while(o!==r)}}function $f(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var t=n=n.next;do{if((t.tag&e)===e){var r=t.create;t.destroy=r()}t=t.next}while(t!==n)}}function $S(e){var n=e.ref;if(n!==null){var t=e.stateNode;switch(e.tag){case 5:e=t;break;default:e=t}typeof n=="function"?n(e):n.current=e}}function o_(e){var n=e.alternate;n!==null&&(e.alternate=null,o_(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[oo],delete n[tu],delete n[PS],delete n[UF],delete n[HF])),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 s_(e){return e.tag===5||e.tag===3||e.tag===4}function k1(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||s_(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 FS(e,n,t){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?t.nodeType===8?t.parentNode.insertBefore(e,n):t.insertBefore(e,n):(t.nodeType===8?(n=t.parentNode,n.insertBefore(e,t)):(n=t,n.appendChild(e)),t=t._reactRootContainer,t!=null||n.onclick!==null||(n.onclick=Pp));else if(r!==4&&(e=e.child,e!==null))for(FS(e,n,t),e=e.sibling;e!==null;)FS(e,n,t),e=e.sibling}function NS(e,n,t){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?t.insertBefore(e,n):t.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(NS(e,n,t),e=e.sibling;e!==null;)NS(e,n,t),e=e.sibling}var $t=null,Ar=!1;function fs(e,n,t){for(t=t.child;t!==null;)i_(e,n,t),t=t.sibling}function i_(e,n,t){if(ho&&typeof ho.onCommitFiberUnmount=="function")try{ho.onCommitFiberUnmount(Tf,t)}catch{}switch(t.tag){case 5:rn||La(t,n);case 6:var r=$t,o=Ar;$t=null,fs(e,n,t),$t=r,Ar=o,$t!==null&&(Ar?(e=$t,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):$t.removeChild(t.stateNode));break;case 18:$t!==null&&(Ar?(e=$t,t=t.stateNode,e.nodeType===8?sm(e.parentNode,t):e.nodeType===1&&sm(e,t),qc(e)):sm($t,t.stateNode));break;case 4:r=$t,o=Ar,$t=t.stateNode.containerInfo,Ar=!0,fs(e,n,t),$t=r,Ar=o;break;case 0:case 11:case 14:case 15:if(!rn&&(r=t.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)&&LS(t,n,i),o=o.next}while(o!==r)}fs(e,n,t);break;case 1:if(!rn&&(La(t,n),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(a){mt(t,n,a)}fs(e,n,t);break;case 21:fs(e,n,t);break;case 22:t.mode&1?(rn=(r=rn)||t.memoizedState!==null,fs(e,n,t),rn=r):fs(e,n,t);break;default:fs(e,n,t)}}function _1(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new sN),n.forEach(function(r){var o=gN.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function Mr(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var s=e,i=n,a=i;e:for(;a!==null;){switch(a.tag){case 5:$t=a.stateNode,Ar=!1;break e;case 3:$t=a.stateNode.containerInfo,Ar=!0;break e;case 4:$t=a.stateNode.containerInfo,Ar=!0;break e}a=a.return}if($t===null)throw Error(q(160));i_(s,i,o),$t=null,Ar=!1;var l=o.alternate;l!==null&&(l.return=null),o.return=null}catch(c){mt(o,n,c)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)a_(n,e),n=n.sibling}function a_(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Mr(n,e),Jr(e),r&4){try{Rc(3,e,e.return),$f(3,e)}catch(g){mt(e,e.return,g)}try{Rc(5,e,e.return)}catch(g){mt(e,e.return,g)}}break;case 1:Mr(n,e),Jr(e),r&512&&t!==null&&La(t,t.return);break;case 5:if(Mr(n,e),Jr(e),r&512&&t!==null&&La(t,t.return),e.flags&32){var o=e.stateNode;try{Gc(o,"")}catch(g){mt(e,e.return,g)}}if(r&4&&(o=e.stateNode,o!=null)){var s=e.memoizedProps,i=t!==null?t.memoizedProps:s,a=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&TE(o,s),cS(a,i);var c=cS(a,s);for(i=0;i<l.length;i+=2){var d=l[i],h=l[i+1];d==="style"?DE(o,h):d==="dangerouslySetInnerHTML"?AE(o,h):d==="children"?Gc(o,h):ix(o,d,h,c)}switch(a){case"input":oS(o,s);break;case"textarea":ME(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?Ya(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?Ya(o,!!s.multiple,s.defaultValue,!0):Ya(o,!!s.multiple,s.multiple?[]:"",!1))}o[tu]=s}catch(g){mt(e,e.return,g)}}break;case 6:if(Mr(n,e),Jr(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(g){mt(e,e.return,g)}}break;case 3:if(Mr(n,e),Jr(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{qc(n.containerInfo)}catch(g){mt(e,e.return,g)}break;case 4:Mr(n,e),Jr(e);break;case 13:Mr(n,e),Jr(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(Nx=xt())),r&4&&_1(e);break;case 22:if(d=t!==null&&t.memoizedState!==null,e.mode&1?(rn=(c=rn)||d,Mr(n,e),rn=c):Mr(n,e),Jr(e),r&8192){if(c=e.memoizedState!==null,(e.stateNode.isHidden=c)&&!d&&e.mode&1)for(te=e,d=e.child;d!==null;){for(h=te=d;te!==null;){switch(p=te,f=p.child,p.tag){case 0:case 11:case 14:case 15:Rc(4,p,p.return);break;case 1:La(p,p.return);var S=p.stateNode;if(typeof S.componentWillUnmount=="function"){r=p,t=p.return;try{n=r,S.props=n.memoizedProps,S.state=n.memoizedState,S.componentWillUnmount()}catch(g){mt(r,t,g)}}break;case 5:La(p,p.return);break;case 22:if(p.memoizedState!==null){M1(h);continue}}f!==null?(f.return=p,te=f):M1(h)}d=d.sibling}e:for(d=null,h=e;;){if(h.tag===5){if(d===null){d=h;try{o=h.stateNode,c?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=h.stateNode,l=h.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=OE("display",i))}catch(g){mt(e,e.return,g)}}}else if(h.tag===6){if(d===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(g){mt(e,e.return,g)}}else if((h.tag!==22&&h.tag!==23||h.memoizedState===null||h===e)&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===e)break e;for(;h.sibling===null;){if(h.return===null||h.return===e)break e;d===h&&(d=null),h=h.return}d===h&&(d=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:Mr(n,e),Jr(e),r&4&&_1(e);break;case 21:break;default:Mr(n,e),Jr(e)}}function Jr(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(s_(t)){var r=t;break e}t=t.return}throw Error(q(160))}switch(r.tag){case 5:var o=r.stateNode;r.flags&32&&(Gc(o,""),r.flags&=-33);var s=k1(e);NS(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=k1(e);FS(e,a,i);break;default:throw Error(q(161))}}catch(l){mt(e,e.return,l)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function aN(e,n,t){te=e,l_(e)}function l_(e,n,t){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||Pd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||rn;a=Pd;var c=rn;if(Pd=i,(rn=l)&&!c)for(te=o;te!==null;)i=te,l=i.child,i.tag===22&&i.memoizedState!==null?j1(o):l!==null?(l.return=i,te=l):j1(o);for(;s!==null;)te=s,l_(s),s=s.sibling;te=o,Pd=a,rn=c}T1(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,te=s):T1(e)}}function T1(e){for(;te!==null;){var n=te;if(n.flags&8772){var t=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:rn||$f(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!rn)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:jr(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&p1(n,s,r);break;case 3:var i=n.updateQueue;if(i!==null){if(t=null,n.child!==null)switch(n.child.tag){case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}p1(n,i,t)}break;case 5:var a=n.stateNode;if(t===null&&n.flags&4){t=a;var l=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&t.focus();break;case"img":l.src&&(t.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var c=n.alternate;if(c!==null){var d=c.memoizedState;if(d!==null){var h=d.dehydrated;h!==null&&qc(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}rn||n.flags&512&&$S(n)}catch(p){mt(n,n.return,p)}}if(n===e){te=null;break}if(t=n.sibling,t!==null){t.return=n.return,te=t;break}te=n.return}}function M1(e){for(;te!==null;){var n=te;if(n===e){te=null;break}var t=n.sibling;if(t!==null){t.return=n.return,te=t;break}te=n.return}}function j1(e){for(;te!==null;){var n=te;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{$f(4,n)}catch(l){mt(n,t,l)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var o=n.return;try{r.componentDidMount()}catch(l){mt(n,o,l)}}var s=n.return;try{$S(n)}catch(l){mt(n,s,l)}break;case 5:var i=n.return;try{$S(n)}catch(l){mt(n,i,l)}}}catch(l){mt(n,n.return,l)}if(n===e){te=null;break}var a=n.sibling;if(a!==null){a.return=n.return,te=a;break}te=n.return}}var lN=Math.ceil,Dp=ns.ReactCurrentDispatcher,$x=ns.ReactCurrentOwner,br=ns.ReactCurrentBatchConfig,ke=0,Ot=null,Pt=null,Ht=0,Yn=0,$a=ni(0),Et=0,au=null,Ni=0,Ff=0,Fx=0,Lc=null,_n=null,Nx=0,hl=1/0,Oo=null,Rp=!1,zS=null,Ls=null,Cd=!1,ks=null,Lp=0,$c=0,BS=null,wh=-1,bh=0;function mn(){return ke&6?xt():wh!==-1?wh:wh=xt()}function $s(e){return e.mode&1?ke&2&&Ht!==0?Ht&-Ht:WF.transition!==null?(bh===0&&(bh=GE()),bh):(e=Fe,e!==0||(e=window.event,e=e===void 0?16:JE(e.type)),e):1}function zr(e,n,t,r){if(50<$c)throw $c=0,BS=null,Error(q(185));Eu(e,t,r),(!(ke&2)||e!==Ot)&&(e===Ot&&(!(ke&2)&&(Ff|=t),Et===4&&Cs(e,Ht)),$n(e,r),t===1&&ke===0&&!(n.mode&1)&&(hl=xt()+500,Df&&ri()))}function $n(e,n){var t=e.callbackNode;W$(e,n);var r=vp(e,e===Ot?Ht:0);if(r===0)t!==null&&zb(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&zb(t),n===1)e.tag===0?KF(A1.bind(null,e)):Sk(A1.bind(null,e)),zF(function(){!(ke&6)&&ri()}),t=null;else{switch(VE(r)){case 1:t=dx;break;case 4:t=KE;break;case 16:t=Sp;break;case 536870912:t=WE;break;default:t=Sp}t=m_(t,c_.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function c_(e,n){if(wh=-1,bh=0,ke&6)throw Error(q(327));var t=e.callbackNode;if(Ja()&&e.callbackNode!==t)return null;var r=vp(e,e===Ot?Ht:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=$p(e,r);else{n=r;var o=ke;ke|=2;var s=d_();(Ot!==e||Ht!==n)&&(Oo=null,hl=xt()+500,ji(e,n));do try{dN();break}catch(a){u_(e,a)}while(!0);Cx(),Dp.current=s,ke=o,Pt!==null?n=0:(Ot=null,Ht=0,n=Et)}if(n!==0){if(n===2&&(o=fS(e),o!==0&&(r=o,n=US(e,o))),n===1)throw t=au,ji(e,0),Cs(e,r),$n(e,xt()),t;if(n===6)Cs(e,r);else{if(o=e.current.alternate,!(r&30)&&!cN(o)&&(n=$p(e,r),n===2&&(s=fS(e),s!==0&&(r=s,n=US(e,s))),n===1))throw t=au,ji(e,0),Cs(e,r),$n(e,xt()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:bi(e,_n,Oo);break;case 3:if(Cs(e,r),(r&130023424)===r&&(n=Nx+500-xt(),10<n)){if(vp(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){mn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=bS(bi.bind(null,e,_n,Oo),n);break}bi(e,_n,Oo);break;case 4:if(Cs(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var i=31-Nr(r);s=1<<i,i=n[i],i>o&&(o=i),r&=~s}if(r=o,r=xt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*lN(r/1960))-r,10<r){e.timeoutHandle=bS(bi.bind(null,e,_n,Oo),r);break}bi(e,_n,Oo);break;case 5:bi(e,_n,Oo);break;default:throw Error(q(329))}}}return $n(e,xt()),e.callbackNode===t?c_.bind(null,e):null}function US(e,n){var t=Lc;return e.current.memoizedState.isDehydrated&&(ji(e,n).flags|=256),e=$p(e,n),e!==2&&(n=_n,_n=t,n!==null&&HS(n)),e}function HS(e){_n===null?_n=e:_n.push.apply(_n,e)}function cN(e){for(var n=e;;){if(n.flags&16384){var t=n.updateQueue;if(t!==null&&(t=t.stores,t!==null))for(var r=0;r<t.length;r++){var o=t[r],s=o.getSnapshot;o=o.value;try{if(!Ur(s(),o))return!1}catch{return!1}}}if(t=n.child,n.subtreeFlags&16384&&t!==null)t.return=n,n=t;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Cs(e,n){for(n&=~Fx,n&=~Ff,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-Nr(n),r=1<<t;e[t]=-1,n&=~r}}function A1(e){if(ke&6)throw Error(q(327));Ja();var n=vp(e,0);if(!(n&1))return $n(e,xt()),null;var t=$p(e,n);if(e.tag!==0&&t===2){var r=fS(e);r!==0&&(n=r,t=US(e,r))}if(t===1)throw t=au,ji(e,0),Cs(e,n),$n(e,xt()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,bi(e,_n,Oo),$n(e,xt()),null}function zx(e,n){var t=ke;ke|=1;try{return e(n)}finally{ke=t,ke===0&&(hl=xt()+500,Df&&ri())}}function zi(e){ks!==null&&ks.tag===0&&!(ke&6)&&Ja();var n=ke;ke|=1;var t=br.transition,r=Fe;try{if(br.transition=null,Fe=1,e)return e()}finally{Fe=r,br.transition=t,ke=n,!(ke&6)&&ri()}}function Bx(){Yn=$a.current,Je($a)}function ji(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,NF(t)),Pt!==null)for(t=Pt.return;t!==null;){var r=t;switch(wx(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Cp();break;case 3:ul(),Je(Rn),Je(ln),Mx();break;case 5:Tx(r);break;case 4:ul();break;case 13:Je(ct);break;case 19:Je(ct);break;case 10:Ix(r.type._context);break;case 22:case 23:Bx()}t=t.return}if(Ot=e,Pt=e=Fs(e.current,null),Ht=Yn=n,Et=0,au=null,Fx=Ff=Ni=0,_n=Lc=null,Ii!==null){for(n=0;n<Ii.length;n++)if(t=Ii[n],r=t.interleaved,r!==null){t.interleaved=null;var o=r.next,s=t.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}t.pending=r}Ii=null}return e}function u_(e,n){do{var t=Pt;try{if(Cx(),Sh.current=Op,Ap){for(var r=ht.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Ap=!1}if(Fi=0,Tt=It=ht=null,Dc=!1,ou=0,$x.current=null,t===null||t.return===null){Et=1,au=n,Pt=null;break}e:{var s=e,i=t.return,a=t,l=n;if(n=Ht,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,d=a,h=d.tag;if(!(d.mode&1)&&(h===0||h===11||h===15)){var p=d.alternate;p?(d.updateQueue=p.updateQueue,d.memoizedState=p.memoizedState,d.lanes=p.lanes):(d.updateQueue=null,d.memoizedState=null)}var f=v1(i);if(f!==null){f.flags&=-257,x1(f,i,a,s,n),f.mode&1&&S1(s,c,n),n=f,l=c;var S=n.updateQueue;if(S===null){var g=new Set;g.add(l),n.updateQueue=g}else S.add(l);break e}else{if(!(n&1)){S1(s,c,n),Ux();break e}l=Error(q(426))}}else if(nt&&a.mode&1){var x=v1(i);if(x!==null){!(x.flags&65536)&&(x.flags|=256),x1(x,i,a,s,n),bx(dl(l,a));break e}}s=l=dl(l,a),Et!==4&&(Et=2),Lc===null?Lc=[s]:Lc.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var y=Vk(s,l,n);h1(s,y);break e;case 1:a=l;var v=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof v.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(Ls===null||!Ls.has(b)))){s.flags|=65536,n&=-n,s.lanes|=n;var E=Yk(s,a,n);h1(s,E);break e}}s=s.return}while(s!==null)}p_(t)}catch(I){n=I,Pt===t&&t!==null&&(Pt=t=t.return);continue}break}while(!0)}function d_(){var e=Dp.current;return Dp.current=Op,e===null?Op:e}function Ux(){(Et===0||Et===3||Et===2)&&(Et=4),Ot===null||!(Ni&268435455)&&!(Ff&268435455)||Cs(Ot,Ht)}function $p(e,n){var t=ke;ke|=2;var r=d_();(Ot!==e||Ht!==n)&&(Oo=null,ji(e,n));do try{uN();break}catch(o){u_(e,o)}while(!0);if(Cx(),ke=t,Dp.current=r,Pt!==null)throw Error(q(261));return Ot=null,Ht=0,Et}function uN(){for(;Pt!==null;)h_(Pt)}function dN(){for(;Pt!==null&&!L$();)h_(Pt)}function h_(e){var n=g_(e.alternate,e,Yn);e.memoizedProps=e.pendingProps,n===null?p_(e):Pt=n,$x.current=null}function p_(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=oN(t,n),t!==null){t.flags&=32767,Pt=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Et=6,Pt=null;return}}else if(t=rN(t,n,Yn),t!==null){Pt=t;return}if(n=n.sibling,n!==null){Pt=n;return}Pt=n=e}while(n!==null);Et===0&&(Et=5)}function bi(e,n,t){var r=Fe,o=br.transition;try{br.transition=null,Fe=1,hN(e,n,t,r)}finally{br.transition=o,Fe=r}return null}function hN(e,n,t,r){do Ja();while(ks!==null);if(ke&6)throw Error(q(327));t=e.finishedWork;var o=e.finishedLanes;if(t===null)return null;if(e.finishedWork=null,e.finishedLanes=0,t===e.current)throw Error(q(177));e.callbackNode=null,e.callbackPriority=0;var s=t.lanes|t.childLanes;if(G$(e,s),e===Ot&&(Pt=Ot=null,Ht=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||Cd||(Cd=!0,m_(Sp,function(){return Ja(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=br.transition,br.transition=null;var i=Fe;Fe=1;var a=ke;ke|=4,$x.current=null,iN(e,t),a_(t,e),AF(xS),xp=!!vS,xS=vS=null,e.current=t,aN(t),$$(),ke=a,Fe=i,br.transition=s}else e.current=t;if(Cd&&(Cd=!1,ks=e,Lp=o),s=e.pendingLanes,s===0&&(Ls=null),z$(t.stateNode),$n(e,xt()),n!==null)for(r=e.onRecoverableError,t=0;t<n.length;t++)o=n[t],r(o.value,{componentStack:o.stack,digest:o.digest});if(Rp)throw Rp=!1,e=zS,zS=null,e;return Lp&1&&e.tag!==0&&Ja(),s=e.pendingLanes,s&1?e===BS?$c++:($c=0,BS=e):$c=0,ri(),null}function Ja(){if(ks!==null){var e=VE(Lp),n=br.transition,t=Fe;try{if(br.transition=null,Fe=16>e?16:e,ks===null)var r=!1;else{if(e=ks,ks=null,Lp=0,ke&6)throw Error(q(331));var o=ke;for(ke|=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 l=0;l<a.length;l++){var c=a[l];for(te=c;te!==null;){var d=te;switch(d.tag){case 0:case 11:case 15:Rc(8,d,s)}var h=d.child;if(h!==null)h.return=d,te=h;else for(;te!==null;){d=te;var p=d.sibling,f=d.return;if(o_(d),d===c){te=null;break}if(p!==null){p.return=f,te=p;break}te=f}}}var S=s.alternate;if(S!==null){var g=S.child;if(g!==null){S.child=null;do{var x=g.sibling;g.sibling=null,g=x}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:Rc(9,s,s.return)}var y=s.sibling;if(y!==null){y.return=s.return,te=y;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:$f(9,a)}}catch(I){mt(a,a.return,I)}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(ke=o,ri(),ho&&typeof ho.onPostCommitFiberRoot=="function")try{ho.onPostCommitFiberRoot(Tf,e)}catch{}r=!0}return r}finally{Fe=t,br.transition=n}}return!1}function O1(e,n,t){n=dl(t,n),n=Vk(e,n,1),e=Rs(e,n,1),n=mn(),e!==null&&(Eu(e,1,n),$n(e,n))}function mt(e,n,t){if(e.tag===3)O1(e,e,t);else for(;n!==null;){if(n.tag===3){O1(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Ls===null||!Ls.has(r))){e=dl(t,e),e=Yk(n,e,1),n=Rs(n,e,1),e=mn(),n!==null&&(Eu(n,1,e),$n(n,e));break}}n=n.return}}function pN(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=mn(),e.pingedLanes|=e.suspendedLanes&t,Ot===e&&(Ht&t)===t&&(Et===4||Et===3&&(Ht&130023424)===Ht&&500>xt()-Nx?ji(e,0):Fx|=t),$n(e,n)}function f_(e,n){n===0&&(e.mode&1?(n=fd,fd<<=1,!(fd&130023424)&&(fd=4194304)):n=1);var t=mn();e=Xo(e,n),e!==null&&(Eu(e,n,t),$n(e,t))}function fN(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),f_(e,t)}function gN(e,n){var t=0;switch(e.tag){case 13:var r=e.stateNode,o=e.memoizedState;o!==null&&(t=o.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(q(314))}r!==null&&r.delete(n),f_(e,t)}var g_;g_=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||Rn.current)jn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return jn=!1,nN(e,n,t);jn=!!(e.flags&131072)}else jn=!1,nt&&n.flags&1048576&&vk(n,kp,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;xh(e,n),e=n.pendingProps;var o=al(n,ln.current);Qa(n,t),o=Ax(null,n,r,e,o,t);var s=Ox();return n.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,Ln(r)?(s=!0,Ip(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,kx(n),o.updater=Lf,n.stateNode=o,o._reactInternals=n,TS(n,r,e,t),n=AS(null,n,r,!0,s,t)):(n.tag=0,nt&&s&&xx(n),fn(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(xh(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=yN(r),e=jr(r,e),o){case 0:n=jS(null,n,r,e,t);break e;case 1:n=P1(null,n,r,e,t);break e;case 11:n=w1(null,n,r,e,t);break e;case 14:n=b1(null,n,r,jr(r.type,e),t);break e}throw Error(q(306,r,""))}return n;case 0:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),jS(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),P1(e,n,r,o,t);case 3:e:{if(Qk(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,Ik(e,n),Mp(n,r,null,t);var i=n.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},n.updateQueue.baseState=s,n.memoizedState=s,n.flags&256){o=dl(Error(q(423)),n),n=C1(e,n,r,t,o);break e}else if(r!==o){o=dl(Error(q(424)),n),n=C1(e,n,r,t,o);break e}else for(Zn=Ds(n.stateNode.containerInfo.firstChild),Qn=n,nt=!0,Rr=null,t=Pk(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(ll(),r===o){n=qo(e,n,t);break e}fn(e,n,r,t)}n=n.child}return n;case 5:return Ek(n),e===null&&ES(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,wS(r,o)?i=null:s!==null&&wS(r,s)&&(n.flags|=32),Zk(e,n),fn(e,n,i,t),n.child;case 6:return e===null&&ES(n),null;case 13:return Jk(e,n,t);case 4:return _x(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=cl(n,null,r,t):fn(e,n,r,t),n.child;case 11:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),w1(e,n,r,o,t);case 7:return fn(e,n,n.pendingProps,t),n.child;case 8:return fn(e,n,n.pendingProps.children,t),n.child;case 12:return fn(e,n,n.pendingProps.children,t),n.child;case 10:e:{if(r=n.type._context,o=n.pendingProps,s=n.memoizedProps,i=o.value,Ge(_p,r._currentValue),r._currentValue=i,s!==null)if(Ur(s.value,i)){if(s.children===o.children&&!Rn.current){n=qo(e,n,t);break e}}else for(s=n.child,s!==null&&(s.return=n);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var l=a.firstContext;l!==null;){if(l.context===r){if(s.tag===1){l=Uo(-1,t&-t),l.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var d=c.pending;d===null?l.next=l:(l.next=d.next,d.next=l),c.pending=l}}s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),kS(s.return,t,n),a.lanes|=t;break}l=l.next}}else if(s.tag===10)i=s.type===n.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(q(341));i.lanes|=t,a=i.alternate,a!==null&&(a.lanes|=t),kS(i,t,n),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===n){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}fn(e,n,o.children,t),n=n.child}return n;case 9:return o=n.type,r=n.pendingProps.children,Qa(n,t),o=Cr(o),r=r(o),n.flags|=1,fn(e,n,r,t),n.child;case 14:return r=n.type,o=jr(r,n.pendingProps),o=jr(r.type,o),b1(e,n,r,o,t);case 15:return Xk(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),xh(e,n),n.tag=1,Ln(r)?(e=!0,Ip(n)):e=!1,Qa(n,t),Gk(n,r,o),TS(n,r,o,t),AS(null,n,r,!0,e,t);case 19:return e_(e,n,t);case 22:return qk(e,n,t)}throw Error(q(156,n.tag))};function m_(e,n){return HE(e,n)}function mN(e,n,t,r){this.tag=e,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,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 xr(e,n,t,r){return new mN(e,n,t,r)}function Hx(e){return e=e.prototype,!(!e||!e.isReactComponent)}function yN(e){if(typeof e=="function")return Hx(e)?1:0;if(e!=null){if(e=e.$$typeof,e===lx)return 11;if(e===cx)return 14}return 2}function Fs(e,n){var t=e.alternate;return t===null?(t=xr(e.tag,n,e.key,e.mode),t.elementType=e.elementType,t.type=e.type,t.stateNode=e.stateNode,t.alternate=e,e.alternate=t):(t.pendingProps=n,t.type=e.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=e.flags&14680064,t.childLanes=e.childLanes,t.lanes=e.lanes,t.child=e.child,t.memoizedProps=e.memoizedProps,t.memoizedState=e.memoizedState,t.updateQueue=e.updateQueue,n=e.dependencies,t.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},t.sibling=e.sibling,t.index=e.index,t.ref=e.ref,t}function Ph(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")Hx(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case ka:return Ai(t.children,o,s,n);case ax:i=8,o|=8;break;case Jy:return e=xr(12,t,n,o|2),e.elementType=Jy,e.lanes=s,e;case eS:return e=xr(13,t,n,o),e.elementType=eS,e.lanes=s,e;case tS:return e=xr(19,t,n,o),e.elementType=tS,e.lanes=s,e;case EE:return Nf(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case CE:i=10;break e;case IE:i=9;break e;case lx:i=11;break e;case cx:i=14;break e;case ws:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=xr(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function Ai(e,n,t,r){return e=xr(7,e,r,n),e.lanes=t,e}function Nf(e,n,t,r){return e=xr(22,e,r,n),e.elementType=EE,e.lanes=t,e.stateNode={isHidden:!1},e}function pm(e,n,t){return e=xr(6,e,null,n),e.lanes=t,e}function fm(e,n,t){return n=xr(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function SN(e,n,t,r,o){this.tag=n,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=Yg(0),this.expirationTimes=Yg(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Yg(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function Kx(e,n,t,r,o,s,i,a,l){return e=new SN(e,n,t,a,l),n===1?(n=1,s===!0&&(n|=8)):n=0,s=xr(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},kx(s),e}function vN(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Ea,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function y_(e){if(!e)return Ws;e=e._reactInternals;e:{if(na(e)!==e||e.tag!==1)throw Error(q(170));var n=e;do{switch(n.tag){case 3:n=n.stateNode.context;break e;case 1:if(Ln(n.type)){n=n.stateNode.__reactInternalMemoizedMergedChildContext;break e}}n=n.return}while(n!==null);throw Error(q(171))}if(e.tag===1){var t=e.type;if(Ln(t))return yk(e,t,n)}return n}function S_(e,n,t,r,o,s,i,a,l){return e=Kx(t,r,!0,e,o,s,i,a,l),e.context=y_(null),t=e.current,r=mn(),o=$s(t),s=Uo(r,o),s.callback=n??null,Rs(t,s,o),e.current.lanes=o,Eu(e,o,r),$n(e,r),e}function zf(e,n,t,r){var o=n.current,s=mn(),i=$s(o);return t=y_(t),n.context===null?n.context=t:n.pendingContext=t,n=Uo(s,i),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Rs(o,n,i),e!==null&&(zr(e,o,i,s),yh(e,o,i)),i}function Fp(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 D1(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function Wx(e,n){D1(e,n),(e=e.alternate)&&D1(e,n)}function xN(){return null}var v_=typeof reportError=="function"?reportError:function(e){console.error(e)};function Gx(e){this._internalRoot=e}Bf.prototype.render=Gx.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));zf(e,n,null,null)};Bf.prototype.unmount=Gx.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;zi(function(){zf(null,e,null,null)}),n[Yo]=null}};function Bf(e){this._internalRoot=e}Bf.prototype.unstable_scheduleHydration=function(e){if(e){var n=qE();e={blockedOn:null,target:e,priority:n};for(var t=0;t<Ps.length&&n!==0&&n<Ps[t].priority;t++);Ps.splice(t,0,e),t===0&&QE(e)}};function Vx(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Uf(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function R1(){}function wN(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=Fp(i);s.call(c)}}var i=S_(n,r,e,0,null,!1,!1,"",R1);return e._reactRootContainer=i,e[Yo]=i.current,Jc(e.nodeType===8?e.parentNode:e),zi(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=Fp(l);a.call(c)}}var l=Kx(e,0,!1,null,null,!1,!1,"",R1);return e._reactRootContainer=l,e[Yo]=l.current,Jc(e.nodeType===8?e.parentNode:e),zi(function(){zf(n,l,t,r)}),l}function Hf(e,n,t,r,o){var s=t._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var l=Fp(i);a.call(l)}}zf(n,i,e,o)}else i=wN(t,n,e,o,r);return Fp(i)}YE=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=vc(n.pendingLanes);t!==0&&(hx(n,t|1),$n(n,xt()),!(ke&6)&&(hl=xt()+500,ri()))}break;case 13:zi(function(){var r=Xo(e,1);if(r!==null){var o=mn();zr(r,e,1,o)}}),Wx(e,1)}};px=function(e){if(e.tag===13){var n=Xo(e,134217728);if(n!==null){var t=mn();zr(n,e,134217728,t)}Wx(e,134217728)}};XE=function(e){if(e.tag===13){var n=$s(e),t=Xo(e,n);if(t!==null){var r=mn();zr(t,e,n,r)}Wx(e,n)}};qE=function(){return Fe};ZE=function(e,n){var t=Fe;try{return Fe=e,n()}finally{Fe=t}};dS=function(e,n,t){switch(n){case"input":if(oS(e,t),n=t.name,t.type==="radio"&&n!=null){for(t=e;t.parentNode;)t=t.parentNode;for(t=t.querySelectorAll("input[name="+JSON.stringify(""+n)+'][type="radio"]'),n=0;n<t.length;n++){var r=t[n];if(r!==e&&r.form===e.form){var o=Of(r);if(!o)throw Error(q(90));_E(r),oS(r,o)}}}break;case"textarea":ME(e,t);break;case"select":n=t.value,n!=null&&Ya(e,!!t.multiple,n,!1)}};$E=zx;FE=zi;var bN={usingClientEntryPoint:!1,Events:[_u,ja,Of,RE,LE,zx]},Jl={findFiberByHostInstance:Ci,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},PN={bundleType:Jl.bundleType,version:Jl.version,rendererPackageName:Jl.rendererPackageName,rendererConfig:Jl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ns.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=BE(e),e===null?null:e.stateNode},findFiberByHostInstance:Jl.findFiberByHostInstance||xN,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 Id=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Id.isDisabled&&Id.supportsFiber)try{Tf=Id.inject(PN),ho=Id}catch{}}ir.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=bN;ir.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Vx(n))throw Error(q(200));return vN(e,n,null,t)};ir.createRoot=function(e,n){if(!Vx(e))throw Error(q(299));var t=!1,r="",o=v_;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=Kx(e,1,!1,null,null,t,!1,r,o),e[Yo]=n.current,Jc(e.nodeType===8?e.parentNode:e),new Gx(n)};ir.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(q(188)):(e=Object.keys(e).join(","),Error(q(268,e)));return e=BE(n),e=e===null?null:e.stateNode,e};ir.flushSync=function(e){return zi(e)};ir.hydrate=function(e,n,t){if(!Uf(n))throw Error(q(200));return Hf(null,e,n,!0,t)};ir.hydrateRoot=function(e,n,t){if(!Vx(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=v_;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=S_(n,null,e,1,t??null,o,!1,s,i),e[Yo]=n.current,Jc(e),r)for(e=0;e<r.length;e++)t=r[e],o=t._getVersion,o=o(t._source),n.mutableSourceEagerHydrationData==null?n.mutableSourceEagerHydrationData=[t,o]:n.mutableSourceEagerHydrationData.push(t,o);return new Bf(n)};ir.render=function(e,n,t){if(!Uf(n))throw Error(q(200));return Hf(null,e,n,!1,t)};ir.unmountComponentAtNode=function(e){if(!Uf(e))throw Error(q(40));return e._reactRootContainer?(zi(function(){Hf(null,null,e,!1,function(){e._reactRootContainer=null,e[Yo]=null})}),!0):!1};ir.unstable_batchedUpdates=zx;ir.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!Uf(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return Hf(e,n,t,!1,r)};ir.version="18.3.1-next-f1338f8080-20240426";function x_(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(x_)}catch(e){console.error(e)}}x_(),xE.exports=ir;var ra=xE.exports;const CN=ei(ra);var w_,L1=ra;w_=Zy.createRoot=L1.createRoot,Zy.hydrateRoot=L1.hydrateRoot;var ec=function(e){return e&&e.Math===Math&&e},zn=ec(typeof globalThis=="object"&&globalThis)||ec(typeof window=="object"&&window)||ec(typeof self=="object"&&self)||ec(typeof sn=="object"&&sn)||ec(typeof sn=="object"&&sn)||function(){return this}()||Function("return this")(),Yx={},vn=function(e){try{return!!e()}catch{return!0}},IN=vn,oi=!IN(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),EN=vn,Kf=!EN(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),kN=Kf,Ed=Function.prototype.call,rs=kN?Ed.bind(Ed):function(){return Ed.apply(Ed,arguments)},b_={},P_={}.propertyIsEnumerable,C_=Object.getOwnPropertyDescriptor,_N=C_&&!P_.call({1:2},1);b_.f=_N?function(n){var t=C_(this,n);return!!t&&t.enumerable}:P_;var I_=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},E_=Kf,k_=Function.prototype,KS=k_.call,TN=E_&&k_.bind.bind(KS,KS),Dt=E_?TN:function(e){return function(){return KS.apply(e,arguments)}},__=Dt,MN=__({}.toString),jN=__("".slice),_l=function(e){return jN(MN(e),8,-1)},AN=Dt,ON=vn,DN=_l,gm=Object,RN=AN("".split),LN=ON(function(){return!gm("z").propertyIsEnumerable(0)})?function(e){return DN(e)==="String"?RN(e,""):gm(e)}:gm,Wf=function(e){return e==null},$N=Wf,FN=TypeError,Tl=function(e){if($N(e))throw new FN("Can't call method on "+e);return e},NN=LN,zN=Tl,Gf=function(e){return NN(zN(e))},mm=typeof document=="object"&&document.all,xn=typeof mm>"u"&&mm!==void 0?function(e){return typeof e=="function"||e===mm}:function(e){return typeof e=="function"},BN=xn,oa=function(e){return typeof e=="object"?e!==null:BN(e)},ym=zn,UN=xn,HN=function(e){return UN(e)?e:void 0},Vf=function(e,n){return arguments.length<2?HN(ym[e]):ym[e]&&ym[e][n]},KN=Dt,T_=KN({}.isPrototypeOf),WN=typeof navigator<"u"&&String(navigator.userAgent)||"",M_=zn,Sm=WN,$1=M_.process,F1=M_.Deno,N1=$1&&$1.versions||F1&&F1.version,z1=N1&&N1.v8,Lr,Np;z1&&(Lr=z1.split("."),Np=Lr[0]>0&&Lr[0]<4?1:+(Lr[0]+Lr[1]));!Np&&Sm&&(Lr=Sm.match(/Edge\/(\d+)/),(!Lr||Lr[1]>=74)&&(Lr=Sm.match(/Chrome\/(\d+)/),Lr&&(Np=+Lr[1])));var GN=Np,B1=GN,VN=vn,YN=zn,XN=YN.String,j_=!!Object.getOwnPropertySymbols&&!VN(function(){var e=Symbol("symbol detection");return!XN(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&B1&&B1<41}),qN=j_,A_=qN&&!Symbol.sham&&typeof Symbol.iterator=="symbol",ZN=Vf,QN=xn,JN=T_,ez=A_,tz=Object,O_=ez?function(e){return typeof e=="symbol"}:function(e){var n=ZN("Symbol");return QN(n)&&JN(n.prototype,tz(e))},nz=String,rz=function(e){try{return nz(e)}catch{return"Object"}},oz=xn,sz=rz,iz=TypeError,Xx=function(e){if(oz(e))return e;throw new iz(sz(e)+" is not a function")},az=Xx,lz=Wf,qx=function(e,n){var t=e[n];return lz(t)?void 0:az(t)},vm=rs,xm=xn,wm=oa,cz=TypeError,uz=function(e,n){var t,r;if(n==="string"&&xm(t=e.toString)&&!wm(r=vm(t,e))||xm(t=e.valueOf)&&!wm(r=vm(t,e))||n!=="string"&&xm(t=e.toString)&&!wm(r=vm(t,e)))return r;throw new cz("Can't convert object to primitive value")},D_={exports:{}},U1=zn,dz=Object.defineProperty,Zx=function(e,n){try{dz(U1,e,{value:n,configurable:!0,writable:!0})}catch{U1[e]=n}return n},hz=zn,pz=Zx,H1="__core-js_shared__",K1=D_.exports=hz[H1]||pz(H1,{});(K1.versions||(K1.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 Qx=D_.exports,W1=Qx,Jx=function(e,n){return W1[e]||(W1[e]=n||{})},fz=Tl,gz=Object,Mu=function(e){return gz(fz(e))},mz=Dt,yz=Mu,Sz=mz({}.hasOwnProperty),si=Object.hasOwn||function(n,t){return Sz(yz(n),t)},vz=Dt,xz=0,wz=Math.random(),bz=vz(1 .toString),R_=function(e){return"Symbol("+(e===void 0?"":e)+")_"+bz(++xz+wz,36)},Pz=zn,Cz=Jx,G1=si,Iz=R_,Ez=j_,kz=A_,Fa=Pz.Symbol,bm=Cz("wks"),_z=kz?Fa.for||Fa:Fa&&Fa.withoutSetter||Iz,os=function(e){return G1(bm,e)||(bm[e]=Ez&&G1(Fa,e)?Fa[e]:_z("Symbol."+e)),bm[e]},Tz=rs,V1=oa,Y1=O_,Mz=qx,jz=uz,Az=os,Oz=TypeError,Dz=Az("toPrimitive"),Rz=function(e,n){if(!V1(e)||Y1(e))return e;var t=Mz(e,Dz),r;if(t){if(n===void 0&&(n="default"),r=Tz(t,e,n),!V1(r)||Y1(r))return r;throw new Oz("Can't convert object to primitive value")}return n===void 0&&(n="number"),jz(e,n)},Lz=Rz,$z=O_,L_=function(e){var n=Lz(e,"string");return $z(n)?n:n+""},Fz=zn,X1=oa,WS=Fz.document,Nz=X1(WS)&&X1(WS.createElement),$_=function(e){return Nz?WS.createElement(e):{}},zz=oi,Bz=vn,Uz=$_,F_=!zz&&!Bz(function(){return Object.defineProperty(Uz("div"),"a",{get:function(){return 7}}).a!==7}),Hz=oi,Kz=rs,Wz=b_,Gz=I_,Vz=Gf,Yz=L_,Xz=si,qz=F_,q1=Object.getOwnPropertyDescriptor;Yx.f=Hz?q1:function(n,t){if(n=Vz(n),t=Yz(t),qz)try{return q1(n,t)}catch{}if(Xz(n,t))return Gz(!Kz(Wz.f,n,t),n[t])};var Ml={},Zz=oi,Qz=vn,N_=Zz&&Qz(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),Jz=oa,e3=String,t3=TypeError,sa=function(e){if(Jz(e))return e;throw new t3(e3(e)+" is not an object")},n3=oi,r3=F_,o3=N_,kd=sa,Z1=L_,s3=TypeError,Pm=Object.defineProperty,i3=Object.getOwnPropertyDescriptor,Cm="enumerable",Im="configurable",Em="writable";Ml.f=n3?o3?function(n,t,r){if(kd(n),t=Z1(t),kd(r),typeof n=="function"&&t==="prototype"&&"value"in r&&Em in r&&!r[Em]){var o=i3(n,t);o&&o[Em]&&(n[t]=r.value,r={configurable:Im in r?r[Im]:o[Im],enumerable:Cm in r?r[Cm]:o[Cm],writable:!1})}return Pm(n,t,r)}:Pm:function(n,t,r){if(kd(n),t=Z1(t),kd(r),r3)try{return Pm(n,t,r)}catch{}if("get"in r||"set"in r)throw new s3("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var a3=oi,l3=Ml,c3=I_,ew=a3?function(e,n,t){return l3.f(e,n,c3(1,t))}:function(e,n,t){return e[n]=t,e},z_={exports:{}},GS=oi,u3=si,B_=Function.prototype,d3=GS&&Object.getOwnPropertyDescriptor,tw=u3(B_,"name"),h3=tw&&(function(){}).name==="something",p3=tw&&(!GS||GS&&d3(B_,"name").configurable),f3={EXISTS:tw,PROPER:h3,CONFIGURABLE:p3},g3=Dt,m3=xn,VS=Qx,y3=g3(Function.toString);m3(VS.inspectSource)||(VS.inspectSource=function(e){return y3(e)});var U_=VS.inspectSource,S3=zn,v3=xn,Q1=S3.WeakMap,x3=v3(Q1)&&/native code/.test(String(Q1)),w3=Jx,b3=R_,J1=w3("keys"),H_=function(e){return J1[e]||(J1[e]=b3(e))},nw={},P3=x3,K_=zn,C3=oa,I3=ew,km=si,_m=Qx,E3=H_,k3=nw,eP="Object already initialized",YS=K_.TypeError,_3=K_.WeakMap,zp,lu,Bp,T3=function(e){return Bp(e)?lu(e):zp(e,{})},M3=function(e){return function(n){var t;if(!C3(n)||(t=lu(n)).type!==e)throw new YS("Incompatible receiver, "+e+" required");return t}};if(P3||_m.state){var eo=_m.state||(_m.state=new _3);eo.get=eo.get,eo.has=eo.has,eo.set=eo.set,zp=function(e,n){if(eo.has(e))throw new YS(eP);return n.facade=e,eo.set(e,n),n},lu=function(e){return eo.get(e)||{}},Bp=function(e){return eo.has(e)}}else{var ha=E3("state");k3[ha]=!0,zp=function(e,n){if(km(e,ha))throw new YS(eP);return n.facade=e,I3(e,ha,n),n},lu=function(e){return km(e,ha)?e[ha]:{}},Bp=function(e){return km(e,ha)}}var W_={set:zp,get:lu,has:Bp,enforce:T3,getterFor:M3},rw=Dt,j3=vn,A3=xn,_d=si,XS=oi,O3=f3.CONFIGURABLE,D3=U_,G_=W_,R3=G_.enforce,L3=G_.get,tP=String,Ch=Object.defineProperty,$3=rw("".slice),F3=rw("".replace),N3=rw([].join),z3=XS&&!j3(function(){return Ch(function(){},"length",{value:8}).length!==8}),B3=String(String).split("String"),U3=z_.exports=function(e,n,t){$3(tP(n),0,7)==="Symbol("&&(n="["+F3(tP(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!_d(e,"name")||O3&&e.name!==n)&&(XS?Ch(e,"name",{value:n,configurable:!0}):e.name=n),z3&&t&&_d(t,"arity")&&e.length!==t.arity&&Ch(e,"length",{value:t.arity});try{t&&_d(t,"constructor")&&t.constructor?XS&&Ch(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=R3(e);return _d(r,"source")||(r.source=N3(B3,typeof n=="string"?n:"")),e};Function.prototype.toString=U3(function(){return A3(this)&&L3(this).source||D3(this)},"toString");var H3=z_.exports,K3=xn,W3=Ml,G3=H3,V3=Zx,V_=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(K3(t)&&G3(t,s,r),r.global)o?e[n]=t:V3(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:W3.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},Y_={},Y3=Math.ceil,X3=Math.floor,q3=Math.trunc||function(n){var t=+n;return(t>0?X3:Y3)(t)},Z3=q3,ia=function(e){var n=+e;return n!==n||n===0?0:Z3(n)},Q3=ia,J3=Math.max,eB=Math.min,tB=function(e,n){var t=Q3(e);return t<0?J3(t+n,0):eB(t,n)},nB=ia,rB=Math.min,X_=function(e){var n=nB(e);return n>0?rB(n,9007199254740991):0},oB=X_,ju=function(e){return oB(e.length)},sB=Gf,iB=tB,aB=ju,nP=function(e){return function(n,t,r){var o=sB(n),s=aB(o);if(s===0)return!e&&-1;var i=iB(r,s),a;if(e&&t!==t){for(;s>i;)if(a=o[i++],a!==a)return!0}else for(;s>i;i++)if((e||i in o)&&o[i]===t)return e||i||0;return!e&&-1}},lB={includes:nP(!0),indexOf:nP(!1)},cB=Dt,Tm=si,uB=Gf,dB=lB.indexOf,hB=nw,rP=cB([].push),q_=function(e,n){var t=uB(e),r=0,o=[],s;for(s in t)!Tm(hB,s)&&Tm(t,s)&&rP(o,s);for(;n.length>r;)Tm(t,s=n[r++])&&(~dB(o,s)||rP(o,s));return o},ow=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],pB=q_,fB=ow,gB=fB.concat("length","prototype");Y_.f=Object.getOwnPropertyNames||function(n){return pB(n,gB)};var Z_={};Z_.f=Object.getOwnPropertySymbols;var mB=Vf,yB=Dt,SB=Y_,vB=Z_,xB=sa,wB=yB([].concat),bB=mB("Reflect","ownKeys")||function(n){var t=SB.f(xB(n)),r=vB.f;return r?wB(t,r(n)):t},oP=si,PB=bB,CB=Yx,IB=Ml,EB=function(e,n,t){for(var r=PB(n),o=IB.f,s=CB.f,i=0;i<r.length;i++){var a=r[i];!oP(e,a)&&!(t&&oP(t,a))&&o(e,a,s(n,a))}},kB=vn,_B=xn,TB=/#|\.prototype\./,Au=function(e,n){var t=jB[MB(e)];return t===OB?!0:t===AB?!1:_B(n)?kB(n):!!n},MB=Au.normalize=function(e){return String(e).replace(TB,".").toLowerCase()},jB=Au.data={},AB=Au.NATIVE="N",OB=Au.POLYFILL="P",DB=Au,Td=zn,RB=Yx.f,LB=ew,$B=V_,FB=Zx,NB=EB,zB=DB,jl=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,l,c,d;if(r?i=Td:o?i=Td[t]||FB(t,{}):i=Td[t]&&Td[t].prototype,i)for(a in n){if(c=n[a],e.dontCallGetSet?(d=RB(i,a),l=d&&d.value):l=i[a],s=zB(r?a:t+(o?".":"#")+a,e.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;NB(c,l)}(e.sham||l&&l.sham)&&LB(c,"sham",!0),$B(i,a,c,e)}},Q_={},BB=q_,UB=ow,HB=Object.keys||function(n){return BB(n,UB)},KB=oi,WB=N_,GB=Ml,VB=sa,YB=Gf,XB=HB;Q_.f=KB&&!WB?Object.defineProperties:function(n,t){VB(n);for(var r=YB(t),o=XB(t),s=o.length,i=0,a;s>i;)GB.f(n,a=o[i++],r[a]);return n};var qB=Vf,ZB=qB("document","documentElement"),QB=sa,JB=Q_,sP=ow,e5=nw,t5=ZB,n5=$_,r5=H_,iP=">",aP="<",qS="prototype",ZS="script",J_=r5("IE_PROTO"),Mm=function(){},eT=function(e){return aP+ZS+iP+e+aP+"/"+ZS+iP},lP=function(e){e.write(eT("")),e.close();var n=e.parentWindow.Object;return e=null,n},o5=function(){var e=n5("iframe"),n="java"+ZS+":",t;return e.style.display="none",t5.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(eT("document.F=Object")),t.close(),t.F},Md,Ih=function(){try{Md=new ActiveXObject("htmlfile")}catch{}Ih=typeof document<"u"?document.domain&&Md?lP(Md):o5():lP(Md);for(var e=sP.length;e--;)delete Ih[qS][sP[e]];return Ih()};e5[J_]=!0;var tT=Object.create||function(n,t){var r;return n!==null?(Mm[qS]=QB(n),r=new Mm,Mm[qS]=null,r[J_]=n):r=Ih(),t===void 0?r:JB.f(r,t)},s5=os,i5=tT,a5=Ml.f,QS=s5("unscopables"),JS=Array.prototype;JS[QS]===void 0&&a5(JS,QS,{configurable:!0,value:i5(null)});var sw=function(e){JS[QS][e]=!0},l5=jl,c5=Mu,u5=ju,d5=ia,h5=sw;l5({target:"Array",proto:!0},{at:function(n){var t=c5(this),r=u5(t),o=d5(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});h5("at");var p5=zn,f5=Dt,Ou=function(e,n){return f5(p5[e].prototype[n])},g5=Ou;g5("Array","at");var m5=_l,nT=Array.isArray||function(n){return m5(n)==="Array"},y5=TypeError,S5=9007199254740991,v5=function(e){if(e>S5)throw y5("Maximum allowed index exceeded");return e},x5=_l,w5=Dt,b5=function(e){if(x5(e)==="Function")return w5(e)},cP=b5,P5=Xx,C5=Kf,I5=cP(cP.bind),E5=function(e,n){return P5(e),n===void 0?e:C5?I5(e,n):function(){return e.apply(n,arguments)}},k5=nT,_5=ju,T5=v5,M5=E5,rT=function(e,n,t,r,o,s,i,a){for(var l=o,c=0,d=i?M5(i,a):!1,h,p;c<r;)c in t&&(h=d?d(t[c],c,n):t[c],s>0&&k5(h)?(p=_5(h),l=rT(e,n,h,p,l,s-1)-1):(T5(l+1),e[l]=h),l++),c++;return l},oT=rT,j5=os,A5=j5("toStringTag"),sT={};sT[A5]="z";var O5=String(sT)==="[object z]",D5=O5,R5=xn,Eh=_l,L5=os,$5=L5("toStringTag"),F5=Object,N5=Eh(function(){return arguments}())==="Arguments",z5=function(e,n){try{return e[n]}catch{}},iT=D5?Eh:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=z5(n=F5(e),$5))=="string"?t:N5?Eh(n):(r=Eh(n))==="Object"&&R5(n.callee)?"Arguments":r},B5=Dt,U5=vn,aT=xn,H5=iT,K5=Vf,W5=U_,lT=function(){},cT=K5("Reflect","construct"),iw=/^\s*(?:class|function)\b/,G5=B5(iw.exec),V5=!iw.test(lT),tc=function(n){if(!aT(n))return!1;try{return cT(lT,[],n),!0}catch{return!1}},uT=function(n){if(!aT(n))return!1;switch(H5(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return V5||!!G5(iw,W5(n))}catch{return!0}};uT.sham=!0;var Y5=!cT||U5(function(){var e;return tc(tc.call)||!tc(Object)||!tc(function(){e=!0})||e})?uT:tc,uP=nT,X5=Y5,q5=oa,Z5=os,Q5=Z5("species"),dP=Array,J5=function(e){var n;return uP(e)&&(n=e.constructor,X5(n)&&(n===dP||uP(n.prototype))?n=void 0:q5(n)&&(n=n[Q5],n===null&&(n=void 0))),n===void 0?dP:n},eU=J5,dT=function(e,n){return new(eU(e))(n===0?0:n)},tU=jl,nU=oT,rU=Xx,oU=Mu,sU=ju,iU=dT;tU({target:"Array",proto:!0},{flatMap:function(n){var t=oU(this),r=sU(t),o;return rU(n),o=iU(t,0),o.length=nU(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var aU=sw;aU("flatMap");var lU=Ou;lU("Array","flatMap");var cU=jl,uU=oT,dU=Mu,hU=ju,pU=ia,fU=dT;cU({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=dU(this),r=hU(t),o=fU(t,0);return o.length=uU(o,t,t,r,0,n===void 0?1:pU(n)),o}});var gU=sw;gU("flat");var mU=Ou;mU("Array","flat");var yU=iT,SU=String,Du=function(e){if(yU(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return SU(e)},vU=jl,xU=Dt,wU=Tl,bU=ia,PU=Du,CU=vn,IU=xU("".charAt),EU=CU(function(){return"𠮷".at(-2)!=="\uD842"});vU({target:"String",proto:!0,forced:EU},{at:function(n){var t=PU(wU(this)),r=t.length,o=bU(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:IU(t,s)}});var kU=Ou;kU("String","at");var _U=sa,hT=function(){var e=_U(this),n="";return e.hasIndices&&(n+="d"),e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),e.dotAll&&(n+="s"),e.unicode&&(n+="u"),e.unicodeSets&&(n+="v"),e.sticky&&(n+="y"),n},aw=vn,TU=zn,lw=TU.RegExp,cw=aw(function(){var e=lw("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),MU=cw||aw(function(){return!lw("a","y").sticky}),jU=cw||aw(function(){var e=lw("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),AU={BROKEN_CARET:jU,MISSED_STICKY:MU,UNSUPPORTED_Y:cw},OU=vn,DU=zn,RU=DU.RegExp,LU=OU(function(){var e=RU(".","s");return!(e.dotAll&&e.test(`
|
|
`)&&e.flags==="s")}),$U=vn,FU=zn,NU=FU.RegExp,zU=$U(function(){var e=NU("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),Na=rs,Yf=Dt,BU=Du,UU=hT,HU=AU,KU=Jx,WU=tT,GU=W_.get,VU=LU,YU=zU,XU=KU("native-string-replace",String.prototype.replace),Up=RegExp.prototype.exec,ev=Up,qU=Yf("".charAt),ZU=Yf("".indexOf),QU=Yf("".replace),jm=Yf("".slice),tv=function(){var e=/a/,n=/b*/g;return Na(Up,e,"a"),Na(Up,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),pT=HU.BROKEN_CARET,nv=/()??/.exec("")[1]!==void 0,JU=tv||nv||pT||VU||YU;JU&&(ev=function(n){var t=this,r=GU(t),o=BU(n),s=r.raw,i,a,l,c,d,h,p;if(s)return s.lastIndex=t.lastIndex,i=Na(ev,s,o),t.lastIndex=s.lastIndex,i;var f=r.groups,S=pT&&t.sticky,g=Na(UU,t),x=t.source,y=0,v=o;if(S&&(g=QU(g,"y",""),ZU(g,"g")===-1&&(g+="g"),v=jm(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&qU(o,t.lastIndex-1)!==`
|
|
`)&&(x="(?: "+x+")",v=" "+v,y++),a=new RegExp("^(?:"+x+")",g)),nv&&(a=new RegExp("^"+x+"$(?!\\s)",g)),tv&&(l=t.lastIndex),c=Na(Up,S?a:t,v),S?c?(c.input=jm(c.input,y),c[0]=jm(c[0],y),c.index=t.lastIndex,t.lastIndex+=c[0].length):t.lastIndex=0:tv&&c&&(t.lastIndex=t.global?c.index+c[0].length:l),nv&&c&&c.length>1&&Na(XU,c[0],a,function(){for(d=1;d<arguments.length-2;d++)arguments[d]===void 0&&(c[d]=void 0)}),c&&f)for(c.groups=h=WU(null),d=0;d<f.length;d++)p=f[d],h[p[0]]=c[p[1]];return c});var uw=ev,e4=jl,hP=uw;e4({target:"RegExp",proto:!0,forced:/./.exec!==hP},{exec:hP});var t4=Kf,fT=Function.prototype,pP=fT.apply,fP=fT.call,n4=typeof Reflect=="object"&&Reflect.apply||(t4?fP.bind(pP):function(){return fP.apply(pP,arguments)}),gP=rs,mP=V_,r4=uw,yP=vn,gT=os,o4=ew,s4=gT("species"),Am=RegExp.prototype,i4=function(e,n,t,r){var o=gT(e),s=!yP(function(){var c={};return c[o]=function(){return 7},""[e](c)!==7}),i=s&&!yP(function(){var c=!1,d=/a/;return e==="split"&&(d={},d.constructor={},d.constructor[s4]=function(){return d},d.flags="",d[o]=/./[o]),d.exec=function(){return c=!0,null},d[o](""),!c});if(!s||!i||t){var a=/./[o],l=n(o,""[e],function(c,d,h,p,f){var S=d.exec;return S===r4||S===Am.exec?s&&!f?{done:!0,value:gP(a,d,h,p)}:{done:!0,value:gP(c,h,d,p)}:{done:!1}});mP(String.prototype,e,l[0]),mP(Am,o,l[1])}r&&o4(Am[o],"sham",!0)},dw=Dt,a4=ia,l4=Du,c4=Tl,u4=dw("".charAt),SP=dw("".charCodeAt),d4=dw("".slice),vP=function(e){return function(n,t){var r=l4(c4(n)),o=a4(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=SP(r,o),i<55296||i>56319||o+1===s||(a=SP(r,o+1))<56320||a>57343?e?u4(r,o):i:e?d4(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},h4={codeAt:vP(!1),charAt:vP(!0)},p4=h4.charAt,f4=function(e,n,t){return n+(t?p4(e,n).length:1)},hw=Dt,g4=Mu,m4=Math.floor,Om=hw("".charAt),y4=hw("".replace),Dm=hw("".slice),S4=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,v4=/\$([$&'`]|\d{1,2})/g,mT=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,l=v4;return o!==void 0&&(o=g4(o),l=S4),y4(s,l,function(c,d){var h;switch(Om(d,0)){case"$":return"$";case"&":return e;case"`":return Dm(n,0,t);case"'":return Dm(n,i);case"<":h=o[Dm(d,1,-1)];break;default:var p=+d;if(p===0)return c;if(p>a){var f=m4(p/10);return f===0?c:f<=a?r[f-1]===void 0?Om(d,1):r[f-1]+Om(d,1):c}h=r[p-1]}return h===void 0?"":h})},xP=rs,x4=sa,w4=xn,b4=_l,P4=uw,C4=TypeError,I4=function(e,n){var t=e.exec;if(w4(t)){var r=xP(t,e,n);return r!==null&&x4(r),r}if(b4(e)==="RegExp")return xP(P4,e,n);throw new C4("RegExp#exec called on incompatible receiver")},E4=n4,wP=rs,Xf=Dt,k4=i4,_4=vn,T4=sa,M4=xn,j4=Wf,A4=ia,O4=X_,pa=Du,D4=Tl,R4=f4,L4=qx,$4=mT,F4=I4,N4=os,rv=N4("replace"),z4=Math.max,B4=Math.min,U4=Xf([].concat),Rm=Xf([].push),bP=Xf("".indexOf),PP=Xf("".slice),H4=function(e){return e===void 0?e:String(e)},K4=function(){return"a".replace(/./,"$0")==="$0"}(),CP=function(){return/./[rv]?/./[rv]("a","$0")==="":!1}(),W4=!_4(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});k4("replace",function(e,n,t){var r=CP?"$":"$0";return[function(s,i){var a=D4(this),l=j4(s)?void 0:L4(s,rv);return l?wP(l,s,a,i):wP(n,pa(a),s,i)},function(o,s){var i=T4(this),a=pa(o);if(typeof s=="string"&&bP(s,r)===-1&&bP(s,"$<")===-1){var l=t(n,i,a,s);if(l.done)return l.value}var c=M4(s);c||(s=pa(s));var d=i.global,h;d&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=F4(i,a),!(f===null||(Rm(p,f),!d));){var S=pa(f[0]);S===""&&(i.lastIndex=R4(a,O4(i.lastIndex),h))}for(var g="",x=0,y=0;y<p.length;y++){f=p[y];for(var v=pa(f[0]),b=z4(B4(A4(f.index),a.length),0),E=[],I,C=1;C<f.length;C++)Rm(E,H4(f[C]));var k=f.groups;if(c){var T=U4([v],E,b,a);k!==void 0&&Rm(T,k),I=pa(E4(s,void 0,T))}else I=$4(v,a,b,E,k,s);b>=x&&(g+=PP(a,x,b)+I,x=b+v.length)}return g+PP(a,x)}]},!W4||!K4||CP);var G4=oa,V4=_l,Y4=os,X4=Y4("match"),q4=function(e){var n;return G4(e)&&((n=e[X4])!==void 0?!!n:V4(e)==="RegExp")},Z4=rs,Q4=si,J4=T_,e8=hT,IP=RegExp.prototype,t8=function(e){var n=e.flags;return n===void 0&&!("flags"in IP)&&!Q4(e,"flags")&&J4(IP,e)?Z4(e8,e):n},n8=jl,r8=rs,pw=Dt,EP=Tl,o8=xn,s8=Wf,i8=q4,nc=Du,a8=qx,l8=t8,c8=mT,u8=os,d8=u8("replace"),h8=TypeError,Lm=pw("".indexOf);pw("".replace);var kP=pw("".slice),p8=Math.max;n8({target:"String",proto:!0},{replaceAll:function(n,t){var r=EP(this),o,s,i,a,l,c,d,h,p,f=0,S=0,g="";if(!s8(n)){if(o=i8(n),o&&(s=nc(EP(l8(n))),!~Lm(s,"g")))throw new h8("`.replaceAll` does not allow non-global regexes");if(i=a8(n,d8),i)return r8(i,n,r,t)}for(a=nc(r),l=nc(n),c=o8(t),c||(t=nc(t)),d=l.length,h=p8(1,d),f=Lm(a,l);f!==-1;)p=c?nc(t(l,f,a)):c8(l,a,f,[],void 0,t),g+=kP(a,S,f)+p,S=f+d,f=f+h>a.length?-1:Lm(a,l,f+h);return S<a.length&&(g+=kP(a,S)),g}});var f8=Ou;f8("String","replaceAll");class kh{constructor(n){m(this,"nextValue");m(this,"diff");this.previousValue=n}get(){var r,o,s,i;const n=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,t=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(n===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(n),this.diff??(this.diff={}),t?(r=this.diff.removed)==null||r.delete(n):((o=this.diff).added??(o.added=new Set),this.diff.added.add(n))}add(n){var o,s,i;const t=this.previousValue.has(n);if(t)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(n))?this._add(n,t):void 0;(i=this.nextValue)!=null&&i.has(n)||this._add(n,t)}_remove(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(n),this.diff??(this.diff={}),t?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(n)):(o=this.diff.added)==null||o.delete(n)}remove(n){var o,s,i,a;const t=this.previousValue.has(n);if(!t)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(n))?this._remove(n,t):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(n)||this._remove(n,t)}}var yT="Expected a function",_P=NaN,g8="[object Symbol]",m8=/^\s+|\s+$/g,y8=/^[-+]0x[0-9a-f]+$/i,S8=/^0b[01]+$/i,v8=/^0o[0-7]+$/i,x8=parseInt,w8=typeof sn=="object"&&sn&&sn.Object===Object&&sn,b8=typeof self=="object"&&self&&self.Object===Object&&self,P8=w8||b8||Function("return this")(),C8=Object.prototype,I8=C8.toString,E8=Math.max,k8=Math.min,$m=function(){return P8.Date.now()};function _8(e,n,t){var r,o,s,i,a,l,c=0,d=!1,h=!1,p=!0;if(typeof e!="function")throw new TypeError(yT);n=TP(n)||0,Hp(t)&&(d=!!t.leading,h="maxWait"in t,s=h?E8(TP(t.maxWait)||0,n):s,p="trailing"in t?!!t.trailing:p);function f(C){var k=r,T=o;return r=o=void 0,c=C,i=e.apply(T,k),i}function S(C){return c=C,a=setTimeout(y,n),d?f(C):i}function g(C){var k=C-l,T=C-c,O=n-k;return h?k8(O,s-T):O}function x(C){var k=C-l,T=C-c;return l===void 0||k>=n||k<0||h&&T>=s}function y(){var C=$m();if(x(C))return v(C);a=setTimeout(y,g(C))}function v(C){return a=void 0,p&&r?f(C):(r=o=void 0,i)}function b(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function E(){return a===void 0?i:v($m())}function I(){var C=$m(),k=x(C);if(r=arguments,o=this,l=C,k){if(a===void 0)return S(l);if(h)return a=setTimeout(y,n),f(l)}return a===void 0&&(a=setTimeout(y,n)),i}return I.cancel=b,I.flush=E,I}function T8(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(yT);return Hp(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),_8(e,n,{leading:r,maxWait:n,trailing:o})}function Hp(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function M8(e){return!!e&&typeof e=="object"}function j8(e){return typeof e=="symbol"||M8(e)&&I8.call(e)==g8}function TP(e){if(typeof e=="number")return e;if(j8(e))return _P;if(Hp(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=Hp(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(m8,"");var t=S8.test(e);return t||v8.test(e)?x8(e.slice(2),t?2:8):y8.test(e)?_P:+e}var A8=T8;const fw=ei(A8);var O8=200,gw="__lodash_hash_undefined__",D8=1/0,R8="[object Function]",L8="[object GeneratorFunction]",$8=/[\\^$.*+?()[\]{}|]/g,F8=/^\[object .+?Constructor\]$/,N8=typeof sn=="object"&&sn&&sn.Object===Object&&sn,z8=typeof self=="object"&&self&&self.Object===Object&&self,mw=N8||z8||Function("return this")();function B8(e,n){var t=e?e.length:0;return!!t&&H8(e,n,0)>-1}function U8(e,n,t,r){for(var o=e.length,s=t+-1;++s<o;)if(n(e[s],s,e))return s;return-1}function H8(e,n,t){if(n!==n)return U8(e,K8,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function K8(e){return e!==e}function W8(e,n){return e.has(n)}function G8(e,n){return e==null?void 0:e[n]}function V8(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function ST(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var Y8=Array.prototype,X8=Function.prototype,vT=Object.prototype,Fm=mw["__core-js_shared__"],MP=function(){var e=/[^.]+$/.exec(Fm&&Fm.keys&&Fm.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),xT=X8.toString,yw=vT.hasOwnProperty,q8=vT.toString,Z8=RegExp("^"+xT.call(yw).replace($8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Q8=Y8.splice,J8=Sw(mw,"Map"),Nm=Sw(mw,"Set"),cu=Sw(Object,"create");function Bi(e){var n=-1,t=e?e.length:0;for(this.clear();++n<t;){var r=e[n];this.set(r[0],r[1])}}function e6(){this.__data__=cu?cu(null):{}}function t6(e){return this.has(e)&&delete this.__data__[e]}function n6(e){var n=this.__data__;if(cu){var t=n[e];return t===gw?void 0:t}return yw.call(n,e)?n[e]:void 0}function r6(e){var n=this.__data__;return cu?n[e]!==void 0:yw.call(n,e)}function o6(e,n){var t=this.__data__;return t[e]=cu&&n===void 0?gw:n,this}Bi.prototype.clear=e6;Bi.prototype.delete=t6;Bi.prototype.get=n6;Bi.prototype.has=r6;Bi.prototype.set=o6;function Al(e){var n=-1,t=e?e.length:0;for(this.clear();++n<t;){var r=e[n];this.set(r[0],r[1])}}function s6(){this.__data__=[]}function i6(e){var n=this.__data__,t=qf(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():Q8.call(n,t,1),!0}function a6(e){var n=this.__data__,t=qf(n,e);return t<0?void 0:n[t][1]}function l6(e){return qf(this.__data__,e)>-1}function c6(e,n){var t=this.__data__,r=qf(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}Al.prototype.clear=s6;Al.prototype.delete=i6;Al.prototype.get=a6;Al.prototype.has=l6;Al.prototype.set=c6;function Ol(e){var n=-1,t=e?e.length:0;for(this.clear();++n<t;){var r=e[n];this.set(r[0],r[1])}}function u6(){this.__data__={hash:new Bi,map:new(J8||Al),string:new Bi}}function d6(e){return Zf(this,e).delete(e)}function h6(e){return Zf(this,e).get(e)}function p6(e){return Zf(this,e).has(e)}function f6(e,n){return Zf(this,e).set(e,n),this}Ol.prototype.clear=u6;Ol.prototype.delete=d6;Ol.prototype.get=h6;Ol.prototype.has=p6;Ol.prototype.set=f6;function Kp(e){var n=-1,t=e?e.length:0;for(this.__data__=new Ol;++n<t;)this.add(e[n])}function g6(e){return this.__data__.set(e,gw),this}function m6(e){return this.__data__.has(e)}Kp.prototype.add=Kp.prototype.push=g6;Kp.prototype.has=m6;function qf(e,n){for(var t=e.length;t--;)if(C6(e[t][0],n))return t;return-1}function y6(e){if(!wT(e)||w6(e))return!1;var n=I6(e)||V8(e)?Z8:F8;return n.test(b6(e))}function S6(e,n,t){var r=-1,o=B8,s=e.length,i=!0,a=[],l=a;if(s>=O8){var c=v6(e);if(c)return ST(c);i=!1,o=W8,l=new Kp}else l=a;e:for(;++r<s;){var d=e[r],h=d;if(d=d!==0?d:0,i&&h===h){for(var p=l.length;p--;)if(l[p]===h)continue e;a.push(d)}else o(l,h,t)||(l!==a&&l.push(h),a.push(d))}return a}var v6=Nm&&1/ST(new Nm([,-0]))[1]==D8?function(e){return new Nm(e)}:E6;function Zf(e,n){var t=e.__data__;return x6(n)?t[typeof n=="string"?"string":"hash"]:t.map}function Sw(e,n){var t=G8(e,n);return y6(t)?t:void 0}function x6(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function w6(e){return!!MP&&MP in e}function b6(e){if(e!=null){try{return xT.call(e)}catch{}try{return e+""}catch{}}return""}function P6(e){return e&&e.length?S6(e):[]}function C6(e,n){return e===n||e!==e&&n!==n}function I6(e){var n=wT(e)?q8.call(e):"";return n==R8||n==L8}function wT(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function E6(){}var k6=P6;const _6=ei(k6),wc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},T6=wc.Good;class bT{constructor(){m(this,"startTime",0);m(this,"name","");m(this,"frames",0);m(this,"started",!1);m(this,"frame",null);m(this,"recordFrame",()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))})}start(n){this.name=n,this.frames=0,this.started=!0,this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,this.frame!==null&&cancelAnimationFrame(this.frame);const n=(performance.now()-this.startTime)/1e3,t=n===0?0:Math.floor(this.frames/n),r=t>55?wc.Good:t>30?wc.Mid:wc.Poor,o=r===wc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${T6};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${o};`,"font-weight: normal")}isStarted(){return this.started}}function vw(e,n){const t=[];e:for(const r of e){for(const o of t)if(n?n(r,o):r===o)continue e;t.push(r)}return t}function me(e){return e.filter(n=>n!=null)}function Nt(e){return e[e.length-1]}function M6(e,n){let t,r=1/0;for(const o of e){const s=n(o);s<r&&(t=o,r=s)}return t}function j6(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return!1;return!0}class Zo{constructor(){m(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}}function PT(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const Wp=()=>{},Ns={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function an(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const st=PT((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),Sr=PT((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function CT(e,n){let t;const r=(...o)=>(t||(t={},t.promise=new Promise((s,i)=>{t.resolve=s,t.reject=i})),clearTimeout(t.timeout),t.latestArgs=o,t.timeout=setTimeout(()=>{const s=t;t=void 0;try{s.resolve(e(...s.latestArgs))}catch(i){s.reject(i)}},n),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const jP=new WeakMap;function xw(e,n){if(typeof e!="object"||e===null)return;let t=jP.get(e);t||(t={tags:{},extras:{}},jP.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}async function yo(e,n){return window.fetch(e,{referrerPolicy:"strict-origin-when-cross-origin",...n})}const pl=(e,n)=>{const t=new window.Image(e,n);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Oi{static async dataUrlToArrayBuffer(n){return yo(n).then(function(t){return t.arrayBuffer()})}static async blobToDataUrl(n){return await new Promise((t,r)=>{if(n){const o=new FileReader;o.onload=()=>t(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsDataURL(n)}})}static async blobToText(n){return await new Promise((t,r)=>{if(n){const o=new FileReader;o.onload=()=>t(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsText(n)}})}}function ov(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function A6(e){const n=new DataView(e);let t=0;for(let r=0;r<n.byteLength;r++)t=(t<<5)-t+n.getUint8(r),t|=0;return t+""}/*!
|
|
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
* Copyright (c) Philip van Heemstra
|
|
*/function O6(e){const n=new Uint8Array(e);if(!n||!(typeof Buffer<"u"&&Buffer.isBuffer(n)||n instanceof Uint8Array)||n.length<16||!(n[0]===137&&n[1]===80&&n[2]===78&&n[3]===71&&n[4]===13&&n[5]===10&&n[6]===26&&n[7]===10))return!1;function r(s,i,a,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const d=i.source.length,h=new TextDecoder,p=s.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;s=s.subarray(a,l);let f=-1,S=0,g=0,x="";e:for(;S<s.length;){const y=S+c,v=s.subarray(S,y),b=h.decode(v,{stream:!0}),E=x+b;let I,C=-1;for(;(I=i.exec(E))!==null;){C=I.index-x.length,f=g+C;break e}S=y,g+=b.length;const k=C>-1?C+d:b.length-d;x=b.slice(k)}return f>=0&&(f+=a>=0?a:p+a),f}const o=r(n,"IDAT",12);return o>=12?r(n,"acTL",8,o)>=8:!1}const D6=e=>new Uint8Array(e)[3]===44;/*!
|
|
* 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 AP(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function R6(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function L6(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!R6(e))return!1;for(t=n[10]&128,r=n[10]&7,o+=6,o+=7,o+=t?3*Math.pow(2,r+1):0;s<2&&o<n.length;)switch(n[o]){case 44:s+=1,t=n[o+9]&128,r=n[o+9]&7,o+=10,o+=t?3*Math.pow(2,r+1):0,o+=AP(n,o+1)+1;break;case 33:o+=2,o+=AP(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}let sv=[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"&&(sv=new Int32Array(sv));/*!
|
|
* MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
|
|
* Copyright: 2014 Alex Gorbatchev
|
|
* Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
|
|
*/const $6=(e,n)=>{let t=~~n^-1;for(let r=0;r<e.length;r++)t=sv[(t^e[r])&255]^t>>>8;return t^-1},OP=4,DP=4;class so{static isPng(n,t){return n.getUint8(t+0)===137&&n.getUint8(t+1)===80&&n.getUint8(t+2)===78&&n.getUint8(t+3)===71&&n.getUint8(t+4)===13&&n.getUint8(t+5)===10&&n.getUint8(t+6)===26&&n.getUint8(t+7)===10}static getChunkType(n,t){return[String.fromCharCode(n.getUint8(t)),String.fromCharCode(n.getUint8(t+1)),String.fromCharCode(n.getUint8(t+2)),String.fromCharCode(n.getUint8(t+3))].join("")}static readChunks(n,t=0){const r={};if(!so.isPng(n,t))throw new Error("Not a PNG");for(t+=8;t<=n.buffer.byteLength;){const o=t,s=n.getInt32(t);t+=4;const i=so.getChunkType(n,t);if(i==="IDAT"&&r[i]){t+=s+OP+DP;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+OP+DP}return r}static parsePhys(n,t){return{ppux:n.getUint32(t),ppuy:n.getUint32(t+4),unit:n.getUint8(t+4)}}static findChunk(n,t){return so.readChunks(n)[t]}static setPhysChunk(n,t=1,r){let o=46,s=0;const i=so.findChunk(n,"pHYs");i&&(o=i.start,s=i.size);const a=so.findChunk(n,"IDAT");a&&(o=a.start,s=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const d=2835.5;c.setInt32(8,d*t),c.setInt32(12,d*t),c.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));c.setInt32(17,$6(h));const p=n.buffer.slice(0,o),f=n.buffer.slice(o+s);return new Blob([p,l,f],r)}}/*!
|
|
* MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
|
|
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
*/function F6(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function N6(e){const n=new Uint8Array(e);return!F6(n)||!n||n.length<21?!1:(n[20]>>1&1)===1}const IT=Object.freeze(["image/svg+xml"]),ET=Object.freeze(["image/jpeg","image/png","image/webp"]),kT=Object.freeze(["image/gif","image/apng","image/avif"]),ww=Object.freeze([...ET,...IT,...kT]),_T=Object.freeze(["video/mp4","video/webm","video/quicktime"]),z6=[...ww,..._T].join(",");class ao{static loadVideo(n){return new Promise((t,r)=>{const o=document.createElement("video");o.onloadeddata=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load video"))},o.crossOrigin="anonymous",o.src=n})}static loadImage(n){return new Promise((t,r)=>{const o=pl();o.onload=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.referrerPolicy="strict-origin-when-cross-origin",o.src=n})}static async getVideoSize(n){return ao.usingObjectURL(n,async t=>{const r=await ao.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await ao.usingObjectURL(n,ao.loadImage);try{if(n.type==="image/png"){const r=new DataView(await n.arrayBuffer());if(so.isPng(r,0)){const o=so.findChunk(r,"pHYs");if(o){const s=so.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(t.naturalWidth/i),h:Math.round(t.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:t.naturalWidth,h:t.naturalHeight}}return{w:t.naturalWidth,h:t.naturalHeight}}static async isAnimated(n){return n.type==="image/gif"?L6(await n.arrayBuffer()):n.type==="image/avif"?D6(await n.arrayBuffer()):n.type==="image/webp"?N6(await n.arrayBuffer()):n.type==="image/apng"?O6(await n.arrayBuffer()):!1}static isAnimatedImageType(n){return kT.includes(n||"")}static isStaticImageType(n){return ET.includes(n||"")}static isVectorImageType(n){return IT.includes(n||"")}static isImageType(n){return ww.includes(n)}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function jd(e,n,t){return e+(n-e)*t}function Wr(e=""){let n=0,t=0,r=0,o=0;function s(){const i=n^n<<11;return n=t,t=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)n^=e.charCodeAt(i)|0,s();return s}function fl(e,n,t,r=!1){const[o,s]=n,[i,a]=t,l=i+(e-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function fo(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function An(e,n){if(fo(e,n))return e[n]}function RP(e){return Object.keys(e)}function gt(e){return Object.values(e)}function Fn(e){return Object.entries(e)}function TT(e){return Object.fromEntries(e)}function Fc(e,n){const t={};let r=!1;for(const[o,s]of Fn(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function Ru(e,n){const t={};for(const[r,o]of Fn(e)){const s=n(r,o);t[r]=s}return t}function MT(e,n){if(e===n)return!0;const t=new Set(Object.keys(e)),r=new Set(Object.keys(n));if(t.size!==r.size)return!1;for(const o of t)if(!r.has(o)||!Object.is(e[o],n[o]))return!1;return!0}const qn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",jT="a0",AT="A00000000000000000000000000";function OT(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 DT(e){if(e.length!==OT(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function LP(e){if(e===void 0)throw Error("n is undefined")}function $P(e){DT(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=qn.indexOf(t[o])+1;s===qn.length?t[o]="0":(t[o]=qn.charAt(s),r=!1)}if(r){if(n==="Z")return"a0";if(n==="z")return;const o=String.fromCharCode(n.charCodeAt(0)+1);return o>"a"?t.push("0"):t.pop(),o+t.join("")}else return n+t.join("")}function B6(e){DT(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=qn.indexOf(t[o])-1;s===-1?t[o]=qn.slice(-1):(t[o]=qn.charAt(s),r=!1)}if(r){if(n==="a")return"Z"+qn.slice(-1);if(n==="A")return;const o=String.fromCharCode(n.charCodeAt(0)-1);return o<"Z"?t.push(qn.slice(-1)):t.pop(),o+t.join("")}else return n+t.join("")}function za(e,n){if(n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e.slice(-1)==="0"||n&&n.slice(-1)==="0")throw new Error("trailing zero");if(n){let o=0;for(;(e.charAt(o)||"0")===n.charAt(o);)o++;if(o>0)return n.slice(0,o)+za(e.slice(o),n.slice(o))}const t=e?qn.indexOf(e.charAt(0)):0,r=n!==void 0?qn.indexOf(n.charAt(0)):qn.length;if(r-t>1){const o=Math.round(.5*(t+r));return qn.charAt(o)}else return n&&n.length>1?n.slice(0,1):qn.charAt(t)+za(e.slice(1),void 0)}function bc(e){const n=OT(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function iv(e){if(e===AT)throw new Error("invalid index: "+e);const n=bc(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function fa(e,n){if(e!==void 0&&iv(e),n!==void 0&&iv(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return jT;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=bc(n),l=n.slice(a.length);if(a===AT)return a+za("",l);if(a<n)return a;const c=B6(a);return LP(c),c}if(n===void 0){const a=bc(e),l=e.slice(a.length),c=$P(a);return c===void 0?a+za(l,void 0):c}const t=bc(e),r=e.slice(t.length),o=bc(n),s=n.slice(o.length);if(t===o)return t+za(r,s);const i=$P(t);return LP(i),i<n?i:t+za(r,void 0)}function Gs(e,n,t){if(t===0)return[];if(t===1)return[fa(e,n)];if(n===void 0){let s=fa(e,n);const i=[s];for(let a=0;a<t-1;a++)s=fa(s,n),i.push(s);return i}if(e===void 0){let s=fa(e,n);const i=[s];for(let a=0;a<t-1;a++)s=fa(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=fa(e,n);return[...Gs(e,o,r),o,...Gs(o,n,t-r-1)]}const U6=jT;function H6(e){iv(e)}function gl(e,n,t){return Gs(e,n,t)}function zm(e,n){return Gs(e,void 0,n)}function uu(e,n){return Gs(e,n,1)[0]}function Lo(e){return Gs(e,void 0,1)[0]}function K6(e){return Gs(void 0,e,1)[0]}function du(e,n="a1"){return[n,...Gs(n,void 0,e)]}function on(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function W6(e,n){return e.id>n.id?1:-1}function bw(e){try{return localStorage.getItem(e)}catch{return null}}function Pw(e,n){try{localStorage.setItem(e,n)}catch{}}function G6(){try{localStorage.clear()}catch{}}function RT(e){try{return sessionStorage.getItem(e)}catch{return null}}function Cw(e,n){try{sessionStorage.setItem(e,n)}catch{}}function LT(e){try{sessionStorage.removeItem(e)}catch{}}function V6(){try{sessionStorage.clear()}catch{}}const Y6=()=>typeof process<"u"&&!1,Ba=[],X6=60,_h=Math.ceil(1e3/X6);let rc,Bm=0,av=0;const q6=()=>{const e=Ba.splice(0,Ba.length);for(const n of e)n()};function $T(){if(rc)return;const e=Date.now(),n=e-av;if(Bm+n<_h){rc=requestAnimationFrame(()=>{rc=void 0,$T()});return}rc=requestAnimationFrame(()=>{rc=void 0,av=e,Bm=Math.min(Bm+n-_h,_h*10),q6()})}let FP=!1;function FT(e){return Y6()?(e(),()=>{}):(Ba.includes(e)||(Ba.push(e),FP||(FP=!0,av=Date.now()-_h-1),$T()),()=>{const n=Ba.indexOf(e);n>-1&&Ba.splice(n,1)})}class Z6{constructor(){m(this,"timeouts",[]);m(this,"intervals",[]);m(this,"rafs",[])}setTimeout(n,t,...r){const o=window.setTimeout(n,t,r);return this.timeouts.push(o),o}setInterval(n,t,...r){const o=window.setInterval(n,t,r);return this.intervals.push(o),o}requestAnimationFrame(n){const t=window.requestAnimationFrame(n);return this.rafs.push(t),t}dispose(){this.timeouts.forEach(n=>clearTimeout(n)),this.intervals.forEach(n=>clearInterval(n)),this.rafs.forEach(n=>cancelAnimationFrame(n)),this.timeouts.length=0,this.intervals.length=0,this.rafs.length=0}}function Q6(e){return e!==null}function J6(){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 NT=J6(),rt=NT[0];NT[1];const eH=Object.getPrototypeOf(rt({}));let Lu=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((n,t)=>(t&=63,t<36?n+=t.toString(36):t<62?n+=(t-26).toString(36).toUpperCase():t>62?n+="-":n+="_",n),"");class Qf{constructor(n,t){m(this,"createDefaultProperties");m(this,"validator");m(this,"ephemeralKeys");m(this,"ephemeralKeySet");m(this,"scope");m(this,"isInstance",n=>(n==null?void 0:n.typeName)===this.typeName);this.typeName=n,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:o=>o},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const r=new Set;if(t.ephemeralKeys)for(const[o,s]of Fn(t.ephemeralKeys))s&&r.add(o);this.ephemeralKeySet=r}create(n){const t={...this.createDefaultProperties(),id:this.createId()};for(const[r,o]of Object.entries(n))o!==void 0&&(t[r]=o);return t.typeName=this.typeName,t}clone(n){return{...rt(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??Lu())}createCustomId(n){return this.typeName+":"+n}parseId(n){if(!this.isId(n))throw new Error(`ID "${n}" is not a valid ID for type "${this.typeName}"`);return n.slice(this.typeName.length+1)}isId(n){if(!n)return!1;for(let t=0;t<this.typeName.length;t++)if(n[t]!==this.typeName[t])return!1;return n[this.typeName.length]===":"}withDefaultProperties(n){return new Qf(this.typeName,{createDefaultProperties:n,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(n,t){return t&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(t,n):this.validator.validate(n)}}function Co(e,n){return new Qf(e,{createDefaultProperties:()=>({}),validator:n.validator,scope:n.scope,ephemeralKeys:n.ephemeralKeys})}function Gp(){return{added:{},updated:{},removed:{}}}function lv(e){const n={added:e.removed,removed:e.added,updated:{}};for(const[t,r]of Object.values(e.updated))n.updated[t.id]=[r,t];return n}function zT(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function Iw(e){const n={added:{},removed:{},updated:{}};return Nc(n,e),n}function Nc(e,n){for(const t of n){for(const[r,o]of Fn(t.added))if(e.removed[r]){const s=e.removed[r];delete e.removed[r],s!==o&&(e.updated[r]=[s,o])}else e.added[r]=o;for(const[r,[o,s]]of Fn(t.updated)){if(e.added[r]){e.added[r]=s,delete e.updated[r],delete e.removed[r];continue}if(e.updated[r]){e.updated[r]=[e.updated[r][0],s],delete e.removed[r];continue}e.updated[r]=t.updated[r],delete e.removed[r]}for(const[r,o]of Fn(t.removed))e.added[r]?delete e.added[r]:e.updated[r]?(e.removed[r]=e.updated[r][0],delete e.updated[r]):e.removed[r]=o}}function BT(e){return e&&typeof e=="object"&&"parents"in e}function UT(e){for(let n=0,t=e.parents.length;n<t;n++)if(e.parents[n].__unsafe__getWithoutCapture(!0),e.parents[n].lastChangedEpoch!==e.parentEpochs[n])return!0;return!1}const Vp=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&BT(e))for(let t=0,r=e.parents.length;t<r;t++)Vp(e.parents[t],e)},Ew=(e,n)=>{if(e.children.add(n)&&BT(e))for(let t=0,r=e.parents.length;t<r;t++)Ew(e.parents[t],e)};function HT(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function ii(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const Ho=ii("empty_array",()=>Object.freeze([])),NP=8;class Yp{constructor(){m(this,"arraySize",0);m(this,"array",Array(NP));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(n){if(this.array)return this.array.indexOf(n)!==-1?!1:this.arraySize<NP?(this.array[this.arraySize]=n,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(n),!0);if(this.set)return this.set.has(n)?!1:(this.set.add(n),!0);throw new Error("no set or array")}remove(n){if(this.array){const t=this.array.indexOf(n);return t===-1?!1:(this.array[t]=void 0,this.arraySize--,t!==this.arraySize&&(this.array[t]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(n)?(this.set.delete(n),!0):!1;throw new Error("no set or array")}visit(n){if(this.array){for(let t=0;t<this.arraySize;t++){const r=this.array[t];typeof r<"u"&&n(r)}return}if(this.set){this.set.forEach(n);return}throw new Error("no set or array")}has(n){return this.array?this.array.indexOf(n)!==-1:this.set.has(n)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}const Jn=Symbol.for("com.tldraw.state/RESET_VALUE");class KT{constructor(n){m(this,"index",0);m(this,"buffer");this.capacity=n,this.buffer=new Array(n)}pushEntry(n,t,r){if(r!==void 0){if(r===Jn){this.clear();return}this.buffer[this.index]=[n,t,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(n){const{index:t,capacity:r,buffer:o}=this;for(let s=0;s<r;s++){const i=(t-1+r-s)%r,a=o[i];if(!a)return Jn;const[l,c]=a;if(s===0&&n>=c)return[];if(l<=n&&n<c){const d=s+1,h=new Array(d);for(let p=0;p<d;p++)h[p]=o[(i+p)%r][2];return h}}return Jn}}class tH{constructor(n,t){m(this,"offset",0);m(this,"maybeRemoved");this.below=n,this.child=t}}const tt=ii("capture",()=>({stack:null}));function Um(e){const n=tt.stack;tt.stack=null;try{return e()}finally{tt.stack=n}}function WT(e){tt.stack=new tH(tt.stack,e),e.parentSet.clear()}function GT(){const e=tt.stack;if(tt.stack=e.below,e.offset<e.child.parents.length){for(let n=e.offset;n<e.child.parents.length;n++){const t=e.child.parents[n];e.child.parentSet.has(t)||Vp(t,e.child)}e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset}if(e.maybeRemoved)for(let n=0;n<e.maybeRemoved.length;n++){const t=e.maybeRemoved[n];e.child.parentSet.has(t)||Vp(t,e.child)}}function Xp(e){if(tt.stack){if(tt.stack.child.parentSet.has(e))return;if(tt.stack.child.parentSet.add(e),tt.stack.child.isActivelyListening&&Ew(e,tt.stack.child),tt.stack.offset<tt.stack.child.parents.length){const t=tt.stack.child.parents[tt.stack.offset];t!==e&&(tt.stack.maybeRemoved?tt.stack.maybeRemoved.push(t):tt.stack.maybeRemoved=[t])}tt.stack.child.parents[tt.stack.offset]=e,tt.stack.child.parentEpochs[tt.stack.offset]=e.lastChangedEpoch,tt.stack.offset++}}const _s=-1;class nH{constructor(n,t,r){m(this,"_isActivelyListening",!1);m(this,"lastTraversedEpoch",_s);m(this,"lastReactedEpoch",_s);m(this,"_scheduleCount",0);m(this,"parentSet",new Yp);m(this,"parentEpochs",[]);m(this,"parents",[]);m(this,"_scheduleEffect");m(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=n,this.runEffect=t,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==En()){if(this.parents.length&&!UT(this)){this.lastReactedEpoch=En();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let n=0,t=this.parents.length;n<t;n++)Ew(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)Vp(this.parents[n],this)}execute(){try{WT(this);const n=En(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=n,t}finally{GT()}}}const Dl=ii("EffectScheduler",()=>nH);function aa(e,n,t){const r=new Dl(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function rH(e,n,t){const r=new Dl(e,n,t);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 oH{constructor(n){m(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){this.isRoot?VT(this.initialAtomValues.keys()):this.initialAtomValues.forEach((n,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,n)})}abort(){ze.globalEpoch++,this.initialAtomValues.forEach((n,t)=>{var r;t.set(n),(r=t.historyBuffer)==null||r.clear()}),this.commit()}}const ze=ii("transactions",()=>({globalEpoch:_s+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:_s+1}));function sH(){return ze.reactionEpoch}function En(){return ze.globalEpoch}function iH(){return ze.globalIsReacting}function kw(e,n){n.lastTraversedEpoch!==ze.globalEpoch&&(n.lastTraversedEpoch=ze.globalEpoch,n instanceof Dl?e.add(n):n.children.visit(t=>kw(e,t)))}function VT(e){var n;if(ze.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{ze.globalIsReacting=!0,ze.reactionEpoch=ze.globalEpoch;const t=new Set;for(const o of e)o.children.visit(s=>kw(t,s));for(const o of t)o.maybeScheduleEffect();let r=0;for(;(n=ze.cleanupReactors)!=null&&n.size;){if(r++>1e3)throw new Error("Reaction update depth limit exceeded");const o=ze.cleanupReactors;ze.cleanupReactors=null;for(const s of o)s.maybeScheduleEffect()}}finally{ze.cleanupReactors=null,ze.globalIsReacting=!1}}function aH(e,n){if(ze.globalIsReacting){const t=ze.cleanupReactors??(ze.cleanupReactors=new Set);e.children.visit(r=>kw(t,r))}else ze.currentTransaction?ze.currentTransaction.initialAtomValues.has(e)||ze.currentTransaction.initialAtomValues.set(e,n):VT([e])}function lH(){ze.globalEpoch++}function cH(e){const n=new oH(ze.currentTransaction);ze.currentTransaction=n;try{let t,r=!1;try{t=e(()=>r=!0)}catch(o){throw n.abort(),o}return r?n.abort():n.commit(),t}finally{ze.currentTransaction=ze.currentTransaction.parent}}function zs(e){return ze.currentTransaction?e():cH(e)}class uH{constructor(n,t,r){m(this,"isEqual");m(this,"computeDiff");m(this,"lastChangedEpoch",En());m(this,"children",new Yp);m(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new KT(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(n){return this.current}get(){return Xp(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??HT(this.current,n))return this.current;lH(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,En(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,En()))??Jn),this.lastChangedEpoch=En();const r=this.current;return this.current=n,aH(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return Xp(this),n>=this.lastChangedEpoch?Ho:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Jn}}const dH=ii("Atom",()=>uH);function Mt(e,n,t){return new dH(e,n,t)}let zP=!1;function hH(){zP||(zP=!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 Pc=Symbol.for("com.tldraw.state/UNINITIALIZED"),Di=e=>e===Pc,cv=ii("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function Cc(e,n){return new cv(e,n)}class pH{constructor(n,t,r){m(this,"lastChangedEpoch",_s);m(this,"lastTraversedEpoch",_s);m(this,"lastCheckedEpoch",_s);m(this,"parentSet",new Yp);m(this,"parents",[]);m(this,"parentEpochs",[]);m(this,"children",new Yp);m(this,"historyBuffer");m(this,"state",Pc);m(this,"error",null);m(this,"computeDiff");m(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new KT(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??HT}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(n){var o;const t=this.lastChangedEpoch===_s,r=En();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&iH()&&this.lastTraversedEpoch<sH()||!UT(this)))if(this.lastCheckedEpoch=r,this.error){if(n)return this.state;throw this.error.thrownValue}else return this.state;try{WT(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof cv?s.value:s,a=this.state===Pc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof cv?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,En(),l??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,En()))??Jn)}this.lastChangedEpoch=En(),this.state=i}return this.error=null,this.lastCheckedEpoch=En(),this.state}catch(s){if(this.state!==Pc&&(this.state=Pc,this.lastChangedEpoch=En()),this.lastCheckedEpoch=En(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!n)throw s;return this.state}finally{GT()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Xp(this)}}getDiffSince(n){var t;return this.__unsafe__getWithoutCapture(!0),Xp(this),n>=this.lastChangedEpoch?Ho:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Jn}}const _w=ii("Computed",()=>pH);function fH(e={},n,t,r){const o=r.value,s=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let i=this[s];return i||(i=new _w(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[mH]=!0,r}function BP(e={},n,t,r){return r.get?(hH(),gH(e,n,t,r)):fH(e,n,t,r)}function gH(e={},n,t,r){const o=r.get,s=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let i=this[s];return i||(i=new _w(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const mH="@@__isComputedMethod__@@";function V(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>BP(e,n,t,r)}else return typeof arguments[0]=="string"?new _w(arguments[0],arguments[1],arguments[2]):BP(void 0,arguments[0],arguments[1],arguments[2])}const YT=1,yH=ii("apiVersion",()=>YT);if(yH!==YT)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function Jf(e,n){const t=xe.useRef(n);t.current=n;const[r,o,s]=xe.useMemo(()=>{let i=null;const a=d=>(i=d,()=>{i=null}),l=new Dl(`useStateTracking(${e})`,()=>{var d;return(d=t.current)==null?void 0:d.call(t)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[e]);return xe.useSyncExternalStore(o,s,s),xe.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const UP={apply(e,n,t){return Jf(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},SH=Symbol.for("react.memo"),vH=Symbol.for("react.forward_ref");function lr(e){let n=null;const t=e.$$typeof;return t===SH&&(e=e.type,n=e.compare),t===vH?P.memo(P.forwardRef(new Proxy(e.render,UP))):P.memo(new Proxy(e,UP),n)}function xH(){const e=arguments[0],n=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return P.useMemo(()=>V(`useComputed(${e})`,n,t),r)}function Bs(e,n,t=Ho){P.useEffect(()=>{const r=new Dl(e,n);return r.attach(),r.execute(),()=>{r.detach()}},t)}function G(){const e=arguments,n=e.length===3?e[2]:[e[0]],t=e.length===3?e[0]:`useValue(${e[0].name})`,r=P.useRef(!0);r.current=!0;const o=P.useMemo(()=>e.length===1?e[0]:V(t,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),n);try{const{subscribe:s,getSnapshot:i}=P.useMemo(()=>({subscribe:a=>aa(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return P.useSyncExternalStore(s,i,i)}finally{r.current=!1}}var qp={exports:{}};qp.exports;(function(e,n){var t=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",d="[object Boolean]",h="[object Date]",p="[object Error]",f="[object Function]",S="[object GeneratorFunction]",g="[object Map]",x="[object Number]",y="[object Null]",v="[object Object]",b="[object Promise]",E="[object Proxy]",I="[object RegExp]",C="[object Set]",k="[object String]",T="[object Symbol]",O="[object Undefined]",_="[object WeakMap]",j="[object ArrayBuffer]",L="[object DataView]",A="[object Float32Array]",R="[object Float64Array]",F="[object Int8Array]",W="[object Int16Array]",K="[object Int32Array]",z="[object Uint8Array]",U="[object Uint8ClampedArray]",X="[object Uint16Array]",J="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,ye=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,ae={};ae[A]=ae[R]=ae[F]=ae[W]=ae[K]=ae[z]=ae[U]=ae[X]=ae[J]=!0,ae[a]=ae[l]=ae[j]=ae[d]=ae[L]=ae[h]=ae[p]=ae[f]=ae[g]=ae[x]=ae[v]=ae[I]=ae[C]=ae[k]=ae[_]=!1;var Ue=typeof sn=="object"&&sn&&sn.Object===Object&&sn,Ae=typeof self=="object"&&self&&self.Object===Object&&self,et=Ue||Ae||Function("return this")(),je=n&&!n.nodeType&&n,at=je&&!0&&e&&!e.nodeType&&e,Ne=at&&at.exports===je,Kn=Ne&&Ue.process,Rt=function(){try{return Kn&&Kn.binding&&Kn.binding("util")}catch{}}(),Pn=Rt&&Rt.isTypedArray;function St(M,$){for(var Y=-1,ee=M==null?0:M.length,Xe=0,fe=[];++Y<ee;){var ft=M[Y];$(ft,Y,M)&&(fe[Xe++]=ft)}return fe}function Xt(M,$){for(var Y=-1,ee=$.length,Xe=M.length;++Y<ee;)M[Xe+Y]=$[Y];return M}function ko(M,$){for(var Y=-1,ee=M==null?0:M.length;++Y<ee;)if($(M[Y],Y,M))return!0;return!1}function Bl(M,$){for(var Y=-1,ee=Array(M);++Y<M;)ee[Y]=$(Y);return ee}function us(M){return function($){return M($)}}function KR(M,$){return M.has($)}function WR(M,$){return M==null?void 0:M[$]}function GR(M){var $=-1,Y=Array(M.size);return M.forEach(function(ee,Xe){Y[++$]=[Xe,ee]}),Y}function VR(M,$){return function(Y){return M($(Y))}}function YR(M){var $=-1,Y=Array(M.size);return M.forEach(function(ee){Y[++$]=ee}),Y}var XR=Array.prototype,qR=Function.prototype,td=Object.prototype,Lg=et["__core-js_shared__"],ub=qR.toString,Qr=td.hasOwnProperty,db=function(){var M=/[^.]+$/.exec(Lg&&Lg.keys&&Lg.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),hb=td.toString,ZR=RegExp("^"+ub.call(Qr).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),pb=Ne?et.Buffer:void 0,nd=et.Symbol,fb=et.Uint8Array,gb=td.propertyIsEnumerable,QR=XR.splice,fi=nd?nd.toStringTag:void 0,mb=Object.getOwnPropertySymbols,JR=pb?pb.isBuffer:void 0,eL=VR(Object.keys,Object),$g=ua(et,"DataView"),Ul=ua(et,"Map"),Fg=ua(et,"Promise"),Ng=ua(et,"Set"),zg=ua(et,"WeakMap"),Hl=ua(Object,"create"),tL=yi($g),nL=yi(Ul),rL=yi(Fg),oL=yi(Ng),sL=yi(zg),yb=nd?nd.prototype:void 0,Bg=yb?yb.valueOf:void 0;function gi(M){var $=-1,Y=M==null?0:M.length;for(this.clear();++$<Y;){var ee=M[$];this.set(ee[0],ee[1])}}function iL(){this.__data__=Hl?Hl(null):{},this.size=0}function aL(M){var $=this.has(M)&&delete this.__data__[M];return this.size-=$?1:0,$}function lL(M){var $=this.__data__;if(Hl){var Y=$[M];return Y===r?void 0:Y}return Qr.call($,M)?$[M]:void 0}function cL(M){var $=this.__data__;return Hl?$[M]!==void 0:Qr.call($,M)}function uL(M,$){var Y=this.__data__;return this.size+=this.has(M)?0:1,Y[M]=Hl&&$===void 0?r:$,this}gi.prototype.clear=iL,gi.prototype.delete=aL,gi.prototype.get=lL,gi.prototype.has=cL,gi.prototype.set=uL;function _o(M){var $=-1,Y=M==null?0:M.length;for(this.clear();++$<Y;){var ee=M[$];this.set(ee[0],ee[1])}}function dL(){this.__data__=[],this.size=0}function hL(M){var $=this.__data__,Y=od($,M);if(Y<0)return!1;var ee=$.length-1;return Y==ee?$.pop():QR.call($,Y,1),--this.size,!0}function pL(M){var $=this.__data__,Y=od($,M);return Y<0?void 0:$[Y][1]}function fL(M){return od(this.__data__,M)>-1}function gL(M,$){var Y=this.__data__,ee=od(Y,M);return ee<0?(++this.size,Y.push([M,$])):Y[ee][1]=$,this}_o.prototype.clear=dL,_o.prototype.delete=hL,_o.prototype.get=pL,_o.prototype.has=fL,_o.prototype.set=gL;function mi(M){var $=-1,Y=M==null?0:M.length;for(this.clear();++$<Y;){var ee=M[$];this.set(ee[0],ee[1])}}function mL(){this.size=0,this.__data__={hash:new gi,map:new(Ul||_o),string:new gi}}function yL(M){var $=sd(this,M).delete(M);return this.size-=$?1:0,$}function SL(M){return sd(this,M).get(M)}function vL(M){return sd(this,M).has(M)}function xL(M,$){var Y=sd(this,M),ee=Y.size;return Y.set(M,$),this.size+=Y.size==ee?0:1,this}mi.prototype.clear=mL,mi.prototype.delete=yL,mi.prototype.get=SL,mi.prototype.has=vL,mi.prototype.set=xL;function rd(M){var $=-1,Y=M==null?0:M.length;for(this.__data__=new mi;++$<Y;)this.add(M[$])}function wL(M){return this.__data__.set(M,r),this}function bL(M){return this.__data__.has(M)}rd.prototype.add=rd.prototype.push=wL,rd.prototype.has=bL;function ds(M){var $=this.__data__=new _o(M);this.size=$.size}function PL(){this.__data__=new _o,this.size=0}function CL(M){var $=this.__data__,Y=$.delete(M);return this.size=$.size,Y}function IL(M){return this.__data__.get(M)}function EL(M){return this.__data__.has(M)}function kL(M,$){var Y=this.__data__;if(Y instanceof _o){var ee=Y.__data__;if(!Ul||ee.length<t-1)return ee.push([M,$]),this.size=++Y.size,this;Y=this.__data__=new mi(ee)}return Y.set(M,$),this.size=Y.size,this}ds.prototype.clear=PL,ds.prototype.delete=CL,ds.prototype.get=IL,ds.prototype.has=EL,ds.prototype.set=kL;function _L(M,$){var Y=id(M),ee=!Y&&HL(M),Xe=!Y&&!ee&&Ug(M),fe=!Y&&!ee&&!Xe&&Eb(M),ft=Y||ee||Xe||fe,kt=ft?Bl(M.length,String):[],Lt=kt.length;for(var lt in M)Qr.call(M,lt)&&!(ft&&(lt=="length"||Xe&&(lt=="offset"||lt=="parent")||fe&&(lt=="buffer"||lt=="byteLength"||lt=="byteOffset")||FL(lt,Lt)))&&kt.push(lt);return kt}function od(M,$){for(var Y=M.length;Y--;)if(bb(M[Y][0],$))return Y;return-1}function TL(M,$,Y){var ee=$(M);return id(M)?ee:Xt(ee,Y(M))}function Kl(M){return M==null?M===void 0?O:y:fi&&fi in Object(M)?LL(M):UL(M)}function Sb(M){return Wl(M)&&Kl(M)==a}function vb(M,$,Y,ee,Xe){return M===$?!0:M==null||$==null||!Wl(M)&&!Wl($)?M!==M&&$!==$:ML(M,$,Y,ee,vb,Xe)}function ML(M,$,Y,ee,Xe,fe){var ft=id(M),kt=id($),Lt=ft?l:hs(M),lt=kt?l:hs($);Lt=Lt==a?v:Lt,lt=lt==a?v:lt;var Wn=Lt==v,Tr=lt==v,qt=Lt==lt;if(qt&&Ug(M)){if(!Ug($))return!1;ft=!0,Wn=!1}if(qt&&!Wn)return fe||(fe=new ds),ft||Eb(M)?xb(M,$,Y,ee,Xe,fe):DL(M,$,Lt,Y,ee,Xe,fe);if(!(Y&o)){var dr=Wn&&Qr.call(M,"__wrapped__"),hr=Tr&&Qr.call($,"__wrapped__");if(dr||hr){var ps=dr?M.value():M,To=hr?$.value():$;return fe||(fe=new ds),Xe(ps,To,Y,ee,fe)}}return qt?(fe||(fe=new ds),RL(M,$,Y,ee,Xe,fe)):!1}function jL(M){if(!Ib(M)||zL(M))return!1;var $=Pb(M)?ZR:ye;return $.test(yi(M))}function AL(M){return Wl(M)&&Cb(M.length)&&!!ae[Kl(M)]}function OL(M){if(!BL(M))return eL(M);var $=[];for(var Y in Object(M))Qr.call(M,Y)&&Y!="constructor"&&$.push(Y);return $}function xb(M,$,Y,ee,Xe,fe){var ft=Y&o,kt=M.length,Lt=$.length;if(kt!=Lt&&!(ft&&Lt>kt))return!1;var lt=fe.get(M);if(lt&&fe.get($))return lt==$;var Wn=-1,Tr=!0,qt=Y&s?new rd:void 0;for(fe.set(M,$),fe.set($,M);++Wn<kt;){var dr=M[Wn],hr=$[Wn];if(ee)var ps=ft?ee(hr,dr,Wn,$,M,fe):ee(dr,hr,Wn,M,$,fe);if(ps!==void 0){if(ps)continue;Tr=!1;break}if(qt){if(!ko($,function(To,Si){if(!KR(qt,Si)&&(dr===To||Xe(dr,To,Y,ee,fe)))return qt.push(Si)})){Tr=!1;break}}else if(!(dr===hr||Xe(dr,hr,Y,ee,fe))){Tr=!1;break}}return fe.delete(M),fe.delete($),Tr}function DL(M,$,Y,ee,Xe,fe,ft){switch(Y){case L:if(M.byteLength!=$.byteLength||M.byteOffset!=$.byteOffset)return!1;M=M.buffer,$=$.buffer;case j:return!(M.byteLength!=$.byteLength||!fe(new fb(M),new fb($)));case d:case h:case x:return bb(+M,+$);case p:return M.name==$.name&&M.message==$.message;case I:case k:return M==$+"";case g:var kt=GR;case C:var Lt=ee&o;if(kt||(kt=YR),M.size!=$.size&&!Lt)return!1;var lt=ft.get(M);if(lt)return lt==$;ee|=s,ft.set(M,$);var Wn=xb(kt(M),kt($),ee,Xe,fe,ft);return ft.delete(M),Wn;case T:if(Bg)return Bg.call(M)==Bg.call($)}return!1}function RL(M,$,Y,ee,Xe,fe){var ft=Y&o,kt=wb(M),Lt=kt.length,lt=wb($),Wn=lt.length;if(Lt!=Wn&&!ft)return!1;for(var Tr=Lt;Tr--;){var qt=kt[Tr];if(!(ft?qt in $:Qr.call($,qt)))return!1}var dr=fe.get(M);if(dr&&fe.get($))return dr==$;var hr=!0;fe.set(M,$),fe.set($,M);for(var ps=ft;++Tr<Lt;){qt=kt[Tr];var To=M[qt],Si=$[qt];if(ee)var kb=ft?ee(Si,To,qt,$,M,fe):ee(To,Si,qt,M,$,fe);if(!(kb===void 0?To===Si||Xe(To,Si,Y,ee,fe):kb)){hr=!1;break}ps||(ps=qt=="constructor")}if(hr&&!ps){var ad=M.constructor,ld=$.constructor;ad!=ld&&"constructor"in M&&"constructor"in $&&!(typeof ad=="function"&&ad instanceof ad&&typeof ld=="function"&&ld instanceof ld)&&(hr=!1)}return fe.delete(M),fe.delete($),hr}function wb(M){return TL(M,GL,$L)}function sd(M,$){var Y=M.__data__;return NL($)?Y[typeof $=="string"?"string":"hash"]:Y.map}function ua(M,$){var Y=WR(M,$);return jL(Y)?Y:void 0}function LL(M){var $=Qr.call(M,fi),Y=M[fi];try{M[fi]=void 0;var ee=!0}catch{}var Xe=hb.call(M);return ee&&($?M[fi]=Y:delete M[fi]),Xe}var $L=mb?function(M){return M==null?[]:(M=Object(M),St(mb(M),function($){return gb.call(M,$)}))}:VL,hs=Kl;($g&&hs(new $g(new ArrayBuffer(1)))!=L||Ul&&hs(new Ul)!=g||Fg&&hs(Fg.resolve())!=b||Ng&&hs(new Ng)!=C||zg&&hs(new zg)!=_)&&(hs=function(M){var $=Kl(M),Y=$==v?M.constructor:void 0,ee=Y?yi(Y):"";if(ee)switch(ee){case tL:return L;case nL:return g;case rL:return b;case oL:return C;case sL:return _}return $});function FL(M,$){return $=$??i,!!$&&(typeof M=="number"||Me.test(M))&&M>-1&&M%1==0&&M<$}function NL(M){var $=typeof M;return $=="string"||$=="number"||$=="symbol"||$=="boolean"?M!=="__proto__":M===null}function zL(M){return!!db&&db in M}function BL(M){var $=M&&M.constructor,Y=typeof $=="function"&&$.prototype||td;return M===Y}function UL(M){return hb.call(M)}function yi(M){if(M!=null){try{return ub.call(M)}catch{}try{return M+""}catch{}}return""}function bb(M,$){return M===$||M!==M&&$!==$}var HL=Sb(function(){return arguments}())?Sb:function(M){return Wl(M)&&Qr.call(M,"callee")&&!gb.call(M,"callee")},id=Array.isArray;function KL(M){return M!=null&&Cb(M.length)&&!Pb(M)}var Ug=JR||YL;function WL(M,$){return vb(M,$)}function Pb(M){if(!Ib(M))return!1;var $=Kl(M);return $==f||$==S||$==c||$==E}function Cb(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=i}function Ib(M){var $=typeof M;return M!=null&&($=="object"||$=="function")}function Wl(M){return M!=null&&typeof M=="object"}var Eb=Pn?us(Pn):AL;function GL(M){return KL(M)?_L(M):OL(M)}function VL(){return[]}function YL(){return!1}e.exports=WL})(qp,qp.exports);var wH=qp.exports;const bH=ei(wH);function PH(e){if(e.length===0)return new Set;const n=e[0],t=e.slice(1),r=new Set;for(const o of n)t.every(s=>s.has(o))&&r.add(o);return r}function CH(e,n){const t={};for(const r of n)e.has(r)||(t.added??(t.added=new Set),t.added.add(r));for(const r of e)n.has(r)||(t.removed??(t.removed=new Set),t.removed.add(r));return t.added||t.removed?t:void 0}function HP(e,n){for(const[t,r]of Object.entries(e)){const o=r,s=n[t];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 KP(e,n,t){const r=Object.fromEntries(Object.keys(t).map(o=>[o,new Set]));for(const[o,s]of Object.entries(t))if("eq"in s){const a=e.index(n,o).get().get(s.eq);if(a)for(const l of a)r[o].add(l)}else if("neq"in s){const i=e.index(n,o);for(const[a,l]of i.get())if(a!==s.neq)for(const c of l)r[o].add(c)}else if("gt"in s){const i=e.index(n,o);for(const[a,l]of i.get())if(a>s.gt)for(const c of l)r[o].add(c)}return PH(Object.values(r))}class IH{constructor(n,t){m(this,"indexCache",new Map);m(this,"historyCache",new Map);this.atoms=n,this.history=t}filterHistory(n){if(this.historyCache.has(n))return this.historyCache.get(n);const t=V("filterHistory:"+n,(r,o)=>{if(Di(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Jn)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const d of s){for(const h of gt(d.added))if(h.typeName===n)if(i.removed[h.id]){const p=i.removed[h.id];delete i.removed[h.id],l--,p!==h&&(i.updated[h.id]=[p,h],c++)}else i.added[h.id]=h,a++;for(const[h,p]of gt(d.updated))p.typeName===n&&(i.added[p.id]?i.added[p.id]=p:i.updated[p.id]?i.updated[p.id]=[i.updated[p.id][0],p]:(i.updated[p.id]=[h,p],c++));for(const h of gt(d.removed))h.typeName===n&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?Cc(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(n,t),t}index(n,t){const r=n+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(n,t);return this.indexCache.set(r,o),o}__uncached_createIndex(n,t){const r=this.filterHistory(n),o=()=>{r.get();const s=new Map;for(const i of gt(this.atoms.get())){const a=i.get();if(a.typeName===n){const l=a[t];s.has(l)||s.set(l,new Set),s.get(l).add(a.id)}}return s};return V("index:"+n+":"+t,(s,i)=>{if(Di(s))return o();const a=r.getDiffSince(i);if(a===Jn)return o();const l=new Map,c=(f,S)=>{let g=l.get(f);g||(g=new kh(s.get(f)??new Set)),g.add(S),l.set(f,g)},d=(f,S)=>{let g=l.get(f);g||(g=new kh(s.get(f)??new Set)),g.remove(S),l.set(f,g)};for(const f of a){for(const S of gt(f.added))if(S.typeName===n){const g=S[t];c(g,S.id)}for(const[S,g]of gt(f.updated))if(g.typeName===n){const x=S[t],y=g[t];x!==y&&(d(x,g.id),c(y,g.id))}for(const S of gt(f.removed))if(S.typeName===n){const g=S[t];d(g,S.id)}}let h,p;for(const[f,S]of l){const g=S.get();g&&(h||(h=new Map(s)),p||(p=new Map),g.value.size===0?h.delete(f):h.set(f,g.value),p.set(f,g.diff))}return h&&p?Cc(h,p):s},{historyLength:100})}record(n,t=()=>({}),r="record:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,r);return V(r,()=>{var s;for(const i of o.get())return(s=this.atoms.get()[i])==null?void 0:s.get()})}records(n,t=()=>({}),r="records:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,"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(n,t=()=>({}),r="ids:"+n+(t?":"+t.toString():"")){const o=this.filterHistory(n),s=()=>{o.get();const l=t();return Object.keys(l).length===0?new Set(gt(this.atoms.get()).flatMap(c=>{const d=c.get();return d.typeName===n?d.id:[]})):KP(this,n,l)},i=l=>{const c=s(),d=CH(l,c);return d?Cc(c,d):l},a=V("ids_query:"+r,t,{isEqual:bH});return V("query:"+r,(l,c)=>{const d=a.get();if(Di(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===Jn)return i(l);const p=new kh(l);for(const S of h){for(const g of gt(S.added))g.typeName===n&&HP(d,g)&&p.add(g.id);for(const[g,x]of gt(S.updated))x.typeName===n&&(HP(d,x)?p.add(x.id):p.remove(x.id));for(const g of gt(S.removed))g.typeName===n&&p.remove(g.id)}const f=p.get();return f?Cc(f.value,f.diff):l},{historyLength:50})}exec(n,t){const r=KP(this,n,t);if(r.size===0)return Ho;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class EH{constructor(n){m(this,"_beforeCreateHandlers",{});m(this,"_afterCreateHandlers",{});m(this,"_beforeChangeHandlers",{});m(this,"_afterChangeHandlers",{});m(this,"_beforeDeleteHandlers",{});m(this,"_afterDeleteHandlers",{});m(this,"_operationCompleteHandlers",[]);m(this,"_isEnabled",!0);this.store=n}isEnabled(){return this._isEnabled}setIsEnabled(n){this._isEnabled=n}handleBeforeCreate(n,t){if(!this._isEnabled)return n;const r=this._beforeCreateHandlers[n.typeName];if(r){let o=n;for(const s of r)o=s(o,t);return o}return n}handleAfterCreate(n,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[n.typeName];if(r)for(const o of r)o(n,t)}handleBeforeChange(n,t,r){if(!this._isEnabled)return t;const o=this._beforeChangeHandlers[t.typeName];if(o){let s=t;for(const i of o)s=i(n,s,r);return s}return t}handleAfterChange(n,t,r){if(!this._isEnabled)return;const o=this._afterChangeHandlers[t.typeName];if(o)for(const s of o)s(n,t,r)}handleBeforeDelete(n,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[n.typeName];if(r){for(const o of r)if(o(n,t)===!1)return!1}return!0}handleAfterDelete(n,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[n.typeName];if(r)for(const o of r)o(n,t)}handleOperationComplete(n){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(n)}register(n){const t=[];for(const[r,o]of Object.entries(n))o!=null&&o.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,o.beforeCreate)),o!=null&&o.afterCreate&&t.push(this.registerAfterCreateHandler(r,o.afterCreate)),o!=null&&o.beforeChange&&t.push(this.registerBeforeChangeHandler(r,o.beforeChange)),o!=null&&o.afterChange&&t.push(this.registerAfterChangeHandler(r,o.afterChange)),o!=null&&o.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,o.beforeDelete)),o!=null&&o.afterDelete&&t.push(this.registerAfterDeleteHandler(r,o.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(n,t){return this._beforeCreateHandlers[n]||(this._beforeCreateHandlers[n]=[]),this._beforeCreateHandlers[n].push(t),()=>vi(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>vi(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>vi(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>vi(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>vi(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>vi(this._afterDeleteHandlers[n],t)}registerOperationCompleteHandler(n){return this._operationCompleteHandlers.push(n),()=>vi(this._operationCompleteHandlers,n)}}function vi(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}class Tw{constructor(n){m(this,"id");m(this,"atoms",Mt("store_atoms",{}));m(this,"history",Mt("history",0,{historyLength:1e3}));m(this,"query",new IH(this.atoms,this.history));m(this,"listeners",new Set);m(this,"historyAccumulator",new _H);m(this,"historyReactor");m(this,"cancelHistoryReactor",()=>{});m(this,"schema");m(this,"props");m(this,"scopedTypes");m(this,"sideEffects",new EH(this));m(this,"put",(n,t)=>{this.atomic(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.isMergingRemoteChanges?"remote":"user";for(let d=0,h=n.length;d<h;d++){a=n[d];const p=(i??s)[a.id];if(p){const f=p.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(f,a,c),this.schema.validateRecord(this,a,t??"updateRecord",f)===f)continue;p.set(a),l=!0;const g=p.__unsafe__getWithoutCapture();r[a.id]=[f,g],this.addDiffForAfterEvent(f,g)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,t??"createRecord",null),o[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...s}),i[a.id]=Mt("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:o,updated:r,removed:{}})})});m(this,"remove",n=>{this.atomic(()=>{const t=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const s of n){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&t.add(s)}let o;this.atoms.update(s=>{let i;for(const a of n){if(t.has(a)||!(a in s))continue;i||(i={...s}),o||(o={}),delete i[a];const l=s[a].get();o[a]=l,this.addDiffForAfterEvent(l,null)}return i??s}),o&&this.updateHistory({added:{},updated:{},removed:o})})});m(this,"get",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.get()});m(this,"unsafeGetWithoutCapture",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.__unsafe__getWithoutCapture()});m(this,"serialize",(n="document")=>{const t={};for(const[r,o]of Fn(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});m(this,"allRecords",()=>gt(this.atoms.get()).map(n=>n.get()));m(this,"clear",()=>{this.remove(RP(this.atoms.get()))});m(this,"update",(n,t)=>{const r=this.atoms.get()[n];if(!r){console.error(`Record ${n} not found. This is probably an error`);return}this.put([t(r.__unsafe__getWithoutCapture())])});m(this,"has",n=>!!this.atoms.get()[n]);m(this,"listen",(n,t)=>{this._flushHistory();const r={onHistory:n,filters:{source:(t==null?void 0:t.source)??"all",scope:(t==null?void 0:t.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",n=>{if(this.isMergingRemoteChanges)return n();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,zs(n)}finally{this.isMergingRemoteChanges=!1}});m(this,"createComputedCache",(n,t,r)=>{const o=new Zo;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(n+":"+s,()=>t(a.get()))}).get()}}});m(this,"createSelectedComputedCache",(n,t,r)=>{const o=new Zo;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=V(n+":"+s+":selector",()=>t(i.get()));return V(n+":"+s,()=>r(a.get()))}).get()}}});m(this,"_integrityChecker");m(this,"_isPossiblyCorrupted",!1);m(this,"pendingAfterEvents",null);m(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:o}=n;this.id=o??Lu(),this.schema=r,this.props=n.props,t&&this.atoms.set(TT(Fn(t).map(([s,i])=>[s,Mt("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=rH("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=FT(s)}),this.scopedTypes={document:new Set(gt(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(gt(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(gt(this.schema.types).filter(s=>s.scope==="presence").map(s=>s.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const n=this.historyAccumulator.flush();for(const{changes:t,source:r}of n){let o=null,s=null,i=null;for(const{onHistory:a,filters:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(s??(s=this.filterChangesByScope(t,"document")),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(o??(o=this.filterChangesByScope(t,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(t,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(n,t){const r={added:Fc(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:Fc(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:Fc(n.removed,(o,s)=>this.scopedTypes[t].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(n){this.historyAccumulator.add({changes:n,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,n)}validate(n){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,n,null))}getStoreSnapshot(n="document"){return{store:this.serialize(n),schema:this.schema.serialize()}}getSnapshot(n="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(n)}migrateSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(n){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(n)}extractingChanges(n){const t=[],r=this.historyAccumulator.addInterceptor(o=>t.push(o.changes));try{return zs(n),Iw(t)}finally{r()}}applyDiff(n,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=gt(n.added);for(const[i,a]of gt(n.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){o.push(a);continue}let d=null;for(const[h,p]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(p,An(c,h))||(d||(d={...c}),d[h]=p);d&&o.push(d)}else o.push(a)}const s=RP(n.removed);o.length&&this.put(o),s.length&&this.remove(s)},t)}ensureStoreIsUsable(){this.atomic(()=>{var n;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(n=this._integrityChecker)==null||n.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(n,t){if(st(this.pendingAfterEvents,"must be in event operation"),n===t||(n&&t&&st(n.id===t.id),!n&&!t))return;const r=(n||t).id,o=this.pendingAfterEvents.get(r);o?o.after=t:this.pendingAfterEvents.set(r,{before:n,after:t})}flushAtomicCallbacks(){let n=0;const t=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(n++,n>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:o,after:s}of r.values())o&&s?this.sideEffects.handleAfterChange(o,s,t):o&&!s?this.sideEffects.handleAfterDelete(o,t):!o&&s&&this.sideEffects.handleAfterCreate(s,t);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(t)}}}atomic(n,t=!0){return zs(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),n();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t??r),this._isInAtomicOp=!0;try{const o=n();return this.flushAtomicCallbacks(),o}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1}})}addHistoryInterceptor(n){return this.historyAccumulator.addInterceptor(t=>n(t,this.isMergingRemoteChanges?"remote":"user"))}}function kH(e){if(e.length===0)return[];const n=[];let t=[e[0]],r;for(let o=1,s=e.length;o<s;o++)r=e[o],t[0].source!==r.source&&(n.push(t),t=[]),t.push(r);return n.push(t),n.map(o=>({source:o[0].source,changes:Iw(o.map(s=>s.changes))}))}class _H{constructor(){m(this,"_history",[]);m(this,"_interceptors",new Set)}addInterceptor(n){return this._interceptors.add(n),()=>{this._interceptors.delete(n)}}add(n){this._history.push(n);for(const t of this._interceptors)t(n)}flush(){const n=kH(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function TH(e,n,t){const r=new Zo;return{get(o,s){return r.get(o,()=>(o instanceof Tw?o:o.store).createComputedCache(e,l=>n(o,l),t)).get(s)}}}function MH(e){const n=[];for(let t=e.length-1;t>=0;t--){const r=e[t];if("id"in r)n.unshift(r);else{const o=r.dependsOn,s=n[0];s&&(n[0]={...s,dependsOn:o.concat(s.dependsOn??[])})}}return n}function el({sequence:e,sequenceId:n,retroactive:t=!0}){const r={sequenceId:n,retroactive:t,sequence:MH(e)};return XT(r),r}function Bn(e,n){return Object.fromEntries(Fn(n).map(([t,r])=>[t,`${e}/${r}`]))}function cr(e){const n=e.sequenceId;return el({sequenceId:n,retroactive:e.retroactive??!0,sequence:e.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>{var o,s;return r.typeName===e.recordType&&(((o=t.filter)==null?void 0:o.call(t,r))??!0)&&(((s=e.filter)==null?void 0:s.call(e,r))??!0)}}:t)})}function jH(e){const n=new Map(e.map(s=>[s.id,s])),t=new Set,r=[];function o(s){st(!t.has(s.id),`Circular dependency in migrations: ${s.id}`),t.add(s.id);const{version:i,sequenceId:a}=Zp(s.id),l=n.get(`${a}/${i-1}`);if(l&&o(l),s.dependsOn)for(const c of s.dependsOn){const d=n.get(c);d&&o(d)}n.delete(s.id),r.push(s)}for(const s of n.values())o(s);return r}function Zp(e){const[n,t]=e.split("/");return{sequenceId:n,version:parseInt(t)}}function WP(e,n){n&&st(e.startsWith(n+"/"),`Every migration in sequence '${n}' must have an id starting with '${n}/'. Got invalid id: '${e}'`),st(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function XT(e){if(st(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),st(e.sequenceId.length,"sequenceId must be a non-empty string"),e.sequence.length===0)return;WP(e.sequence[0].id,e.sequenceId);let n=Zp(e.sequence[0].id).version;st(n===1,`Expected the first migrationId to be '${e.sequenceId}/1' but got '${e.sequence[0].id}'`);for(let t=1;t<e.sequence.length;t++){const r=e.sequence[t].id;WP(r,e.sequenceId);const o=Zp(r).version;st(o===n+1,`Migration id numbers must increase in increments of 1, expected ${e.sequenceId}/${n+1} but got '${e.sequence[t].id}'`),n=o}}var Ss=(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))(Ss||{});function AH(e){if(e.schemaVersion>2||e.schemaVersion<1)return Ns.err("Bad schema version");if(e.schemaVersion===2)return Ns.ok(e);const n={schemaVersion:2,sequences:{}};for(const[t,r]of Object.entries(e.recordVersions))if(n.sequences[`com.tldraw.${t}`]=r.version,"subTypeKey"in r)for(const[o,s]of Object.entries(r.subTypeVersions))n.sequences[`com.tldraw.${t}.${o}`]=s;return Ns.ok(n)}class Mw{constructor(n,t){m(this,"migrations",{});m(this,"sortedMigrations");var o;this.types=n,this.options=t;for(const s of t.migrations??[])st(!this.migrations[s.sequenceId],`Duplicate migration sequenceId ${s.sequenceId}`),XT(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=jH(r);for(const s of this.sortedMigrations)if((o=s.dependsOn)!=null&&o.length)for(const i of s.dependsOn){const a=r.find(l=>l.id===i);st(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(n,t){return new Mw(n,t??{})}validateRecord(n,t,r,o){try{const s=An(this.types,t.typeName);if(!s)throw new Error(`Missing definition for record type ${t.typeName}`);return s.validate(t,o??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:n,record:t,phase:r,recordBefore:o,error:s});throw s}}getMigrationsSince(n){const t=AH(n);if(!t.ok)return t;const r=t.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 Ns.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 d of this.migrations[i].sequence)s.add(d.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(d=>d.id===l);if(c===-1)return Ns.err("Incompatible schema?");for(const d of this.migrations[i].sequence.slice(c+1))s.add(d.id)}return Ns.ok(this.sortedMigrations.filter(({id:i})=>s.has(i)))}migratePersistedRecord(n,t,r="up"){const o=this.getMigrationsSince(t);if(!o.ok)return console.error("Error migrating record",o.error),{type:"error",reason:Ss.MigrationError};let s=o.value;if(s.length===0)return{type:"success",value:n};if(s.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?Ss.TargetVersionTooOld:Ss.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:Ss.TargetVersionTooOld};s=s.slice().reverse()}n=rt(n);try{for(const i of s){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(n):!0))continue;const l=i[r](n);l&&(n=rt(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Ss.MigrationError}}return{type:"success",value:n}}migrateStoreSnapshot(n){let{store:t}=n;const r=this.getMigrationsSince(n.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:Ss.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:t};t=rt(t);try{for(const s of o)if(s.scope==="record")for(const[i,a]of Object.entries(t)){if(!(s.filter?s.filter(a):!0))continue;const c=s.up(a);c&&(t[i]=rt(c))}else if(s.scope==="store"){const i=s.up(t);i&&(t=rt(i))}else an(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:Ss.MigrationError}}return{type:"success",value:t}}createIntegrityChecker(n){var t,r;return((r=(t=this.options).createIntegrityChecker)==null?void 0:r.call(t,n))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:n,sequence:t})=>[n,t.length?Zp(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:n})=>[n,0]))}}getType(n){const t=An(this.types,n);return st(t,"record type does not exists"),t}}function OH(e){if(!e.length)return null;let n="";for(const t of e)typeof t=="number"?n+=`.${t}`:t.startsWith("(")?n.endsWith(")")?n=`${n.slice(0,-1)}, ${t.slice(1)}`:n+=t:n+=`.${t}`;return n=n.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),n.startsWith(".")?n.slice(1):n}class Pe extends Error{constructor(t,r=[]){const o=OH(r),s=t.split(`
|
|
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
`);super(r?`At ${o}: ${s}`:s);m(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Nn(e,n){try{return n()}catch(t){throw t instanceof Pe?new Pe(t.rawMessage,[e,...t.path]):new Pe(t.toString(),[e])}}function Vs(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const n=typeof e;switch(n){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${n}`;case"object":return`an ${n}`;case"undefined":return"undefined";default:an(n)}}class wn{constructor(n,t){this.validationFn=n,this.validateUsingKnownGoodVersionFn=t}validate(n){return this.validationFn(n)}validateUsingKnownGoodVersion(n,t){return Object.is(n,t)?n:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(n,t):this.validate(t)}isValid(n){try{return this.validate(n),!0}catch{return!1}}nullable(){return NH(this)}optional(){return ZT(this)}refine(n){return new wn(t=>n(this.validate(t)),(t,r)=>{const o=this.validateUsingKnownGoodVersion(t,r);return Object.is(t,o)?t:n(o)})}check(n,t){return typeof n=="string"?this.refine(r=>(Nn(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class DH extends wn{constructor(n){super(t=>{const r=GP.validate(t);for(let o=0;o<r.length;o++)Nn(o,()=>n.validate(r[o]));return r},(t,r)=>{if(!n.validateUsingKnownGoodVersion)return this.validate(r);const o=GP.validate(r);let s=t.length!==o.length;for(let i=0;i<o.length;i++){const a=o[i];if(i>=t.length){s=!0,Nn(i,()=>n.validate(a));continue}if(Object.is(t[i],a))continue;const l=Nn(i,()=>n.validateUsingKnownGoodVersion(t[i],a));Object.is(l,t[i])||(s=!0)}return s?r:t}),this.itemValidator=n}nonEmpty(){return this.check(n=>{if(n.length===0)throw new Pe("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new Pe("Expected an array with length greater than 1")})}}class Qp extends wn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Pe(`Expected object, got ${Vs(r)}`);for(const[o,s]of Object.entries(n))Nn(o,()=>{s.validate(An(r,o))});if(!t){for(const o of Object.keys(r))if(!fo(n,o))throw new Pe("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Pe(`Expected object, got ${Vs(o)}`);let s=!1;for(const[i,a]of Object.entries(n)){const l=An(r,i),c=An(o,i);if(Object.is(l,c))continue;const d=Nn(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(d,l)||(s=!0)}if(!t){for(const i of Object.keys(o))if(!fo(n,i))throw new Pe("Unexpected property",[i])}for(const i of Object.keys(r))if(!fo(o,i)){s=!0;break}return s?o:r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new Qp(this.config,!0)}extend(n){return new Qp({...this.config,...n})}}class eg extends wn{constructor(n,t,r,o){super(s=>{this.expectObject(s);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(s);return i===void 0?this.unknownValueValidation(s,a):Nn(`(${n} = ${a})`,()=>i.validate(s))},(s,i)=>{this.expectObject(i),this.expectObject(s);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):An(s,n)!==An(i,n)?Nn(`(${n} = ${l})`,()=>a.validate(i)):Nn(`(${n} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(s,i):a.validate(i))}),this.key=n,this.config=t,this.unknownValueValidation=r,this.useNumberKeys=o}expectObject(n){if(typeof n!="object"||n===null)throw new Pe(`Expected an object, got ${Vs(n)}`,[])}getMatchingSchemaAndVariant(n){const t=An(n,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new Pe(`Expected a string for key "${this.key}", got ${Vs(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new Pe(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:fo(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(n){return new eg(this.key,this.config,n,this.useNumberKeys)}}class RH extends wn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Pe(`Expected object, got ${Vs(r)}`);for(const[o,s]of Object.entries(r))Nn(o,()=>{n.validate(o),t.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Pe(`Expected object, got ${Vs(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!fo(r,i)){s=!0,Nn(i,()=>{n.validate(i),t.validate(a)});continue}const l=An(r,i),c=a;if(Object.is(l,c))continue;const d=Nn(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,c):t.validate(c));Object.is(d,l)||(s=!0)}for(const i of Object.keys(r))if(!fo(o,i)){s=!0;break}return s?o:r}),this.keyValidator=n,this.valueValidator=t}}function jw(e){return new wn(n=>{if(typeof n!==e)throw new Pe(`Expected ${e}, got ${Vs(n)}`);return n})}const LH=new wn(e=>e),pe=jw("string"),de=jw("number").check(e=>{if(Number.isNaN(e))throw new Pe("Expected a number, got NaN");if(!Number.isFinite(e))throw new Pe(`Expected a finite number, got ${e}`)}),Jp=de.check(e=>{if(e<0)throw new Pe(`Expected a positive number, got ${e}`)}),Ct=de.check(e=>{if(e<=0)throw new Pe(`Expected a non-zero positive number, got ${e}`)}),qT=de.check(e=>{if(!Number.isInteger(e))throw new Pe(`Expected an integer, got ${e}`)}),Th=qT.check(e=>{if(e<0)throw new Pe(`Expected a positive integer, got ${e}`)}),$H=qT.check(e=>{if(e<=0)throw new Pe(`Expected a non-zero positive integer, got ${e}`)}),we=jw("boolean");function cn(e){return new wn(n=>{if(n!==e)throw new Pe(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const GP=new wn(e=>{if(!Array.isArray(e))throw new Pe(`Expected an array, got ${Vs(e)}`);return e});function zt(e){return new DH(e)}function Se(e){return new Qp(e)}function uv(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===eH)}function dv(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(dv):uv(e)?Object.values(e).every(dv):!1}const Bt=new wn(e=>{if(dv(e))return e;throw new Pe(`Expected json serializable value, got ${typeof e}`)},(e,n)=>{if(Array.isArray(e)&&Array.isArray(n)){let t=e.length!==n.length;for(let r=0;r<n.length;r++){if(r>=e.length){t=!0,Bt.validate(n[r]);continue}const o=e[r],s=n[r];if(Object.is(o,s))continue;const i=Bt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(t=!0)}return t?n:e}else if(uv(e)&&uv(n)){let t=!1;for(const r of Object.keys(n)){if(!fo(e,r)){t=!0,Bt.validate(n[r]);continue}const o=e[r],s=n[r];if(Object.is(o,s))continue;const i=Bt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(t=!0)}for(const r of Object.keys(e))if(!fo(n,r)){t=!0;break}return t?n:e}else return Bt.validate(n)});function ef(e,n){return new RH(e,n)}function Aw(e,n){return new eg(e,n,(t,r)=>{throw new Pe(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function FH(e,n){return new eg(e,n,(t,r)=>{throw new Pe(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function Io(e,n){return new wn(t=>Nn(e,()=>n.validate(t)),(t,r)=>Nn(e,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(t,r):n.validate(r)))}function tg(e){return new wn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Pe(`Expected ${t}, got ${n}`)}return n})}function ZT(e){return new wn(n=>{if(n!==void 0)return e.validate(n)},(n,t)=>{if(!(n===void 0&&t===void 0)&&t!==void 0)return e.validateUsingKnownGoodVersion&&n!==void 0?e.validateUsingKnownGoodVersion(n,t):e.validate(t)})}function NH(e){return new wn(n=>n===null?null:e.validate(n),(n,t)=>t===null?null:e.validateUsingKnownGoodVersion&&n!==null?e.validateUsingKnownGoodVersion(n,t):e.validate(t))}function ng(...e){return tg(new Set(e))}function QT(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Pe(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Pe(`Expected a valid url, got ${JSON.stringify(e)}`)}}const zH=new Set(["http:","https:","mailto:"]),or=pe.check(e=>{if(e==="")return;const n=QT(e);if(!zH.has(n.protocol.toLowerCase()))throw new Pe(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),BH=new Set(["http:","https:","data:","asset:"]),Ui=pe.check(e=>{if(e==="")return;const n=QT(e);if(!BH.has(n.protocol.toLowerCase()))throw new Pe(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),Ow=pe.refine(e=>{try{return H6(e),e}catch{throw new Pe(`Expected an index key, got ${JSON.stringify(e)}`)}});function er(e){return pe.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const rg=er("asset");function Dw(e,n){return Se({id:rg,typeName:cn("asset"),type:cn(e),props:n,meta:Bt})}const Hi=Se({x:de,y:de,z:de.optional()}),zc=Se({x:de,y:de,w:de,h:de}),JT=de.check(e=>{if(e<0||e>1)throw new Pe("Opacity must be between 0 and 1")}),UH=pe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),gr=er("shape");function HH(e,n,t){return Se({id:gr,typeName:cn("shape"),x:de,y:de,rotation:de,index:Ow,parentId:UH,type:cn(e),isLocked:we,opacity:JT,props:n?Se(n):Bt,meta:t?Se(t):Bt})}const KH=er("binding");function WH(e,n,t){return Se({id:KH,typeName:cn("binding"),type:cn(e),fromId:gr,toId:gr,props:n?Se(n):Bt,meta:t?Se(t):Bt})}Bn("com.tldraw.binding",{});cr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Ri(e){return`binding:${Lu()}`}function GH(e){return Co("binding",{scope:"document",validator:Io("binding",Aw("type",Ru(e,(n,{props:t,meta:r})=>WH(n,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class Yt{constructor(n,t,r){this.id=n,this.defaultValue=t,this.type=r}static define(n,t){const{defaultValue:r,type:o=LH}=t;return new Yt(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new VH(n,r,o)}validate(n){return this.type.validate(n)}validateUsingKnownGoodVersion(n,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(n,t):this.validate(t)}}class VH extends Yt{constructor(n,t,r){super(n,t,ng(...r)),this.values=r}}const Ad=Bn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),YH=cr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:Ad.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:Ad.HoistOpacity,up:e=>{e.opacity=Number(e.props.opacity??"1"),delete e.props.opacity},down:e=>{const n=e.opacity;delete e.opacity,e.props.opacity=n<.175?"0.1":n<.375?"0.25":n<.625?"0.5":n<.875?"0.75":"1"}},{id:Ad.AddMeta,up:e=>{e.meta={}}},{id:Ad.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function Ua(e){return e?e.typeName==="shape":!1}function kn(e){return e?e.startsWith("shape:"):!1}function $e(e){return`shape:${e??Lu()}`}function eM(e){const n=new Map;for(const[t,r]of Object.entries(e))if(r instanceof Yt){if(n.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);n.set(r,t)}return n}function Gr(e,n){return Ru(n,(t,r)=>`com.tldraw.shape.${e}/${r}`)}function XH(e){return Co("shape",{scope:"document",validator:Io("shape",Aw("type",Ru(e,(n,{props:t,meta:r})=>HH(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function VP(e,n){const t=[];for(const[r,{migrations:o}]of Object.entries(n)){const s=`com.tldraw.${e}.${r}`;o?"sequenceId"in o?(st(s===o.sequenceId,`sequenceId mismatch for ${r} ${Qf} migrations. Expected '${s}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o?t.push(el({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?tM(e,r,i):i)})):t.push(el({sequenceId:s,retroactive:!1,sequence:Object.keys(o.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${s}/${i}`,scope:"record",filter:a=>a.typeName===e&&a.type===r,up:a=>{const l=o.migrators[i].up(a);if(l)return l},down:a=>{const l=o.migrators[i].down(a);if(l)return l}}))})):t.push(el({sequenceId:s,retroactive:!1,sequence:[]}))}return t}function tM(e,n,t){return{id:t.id,dependsOn:t.dependsOn,scope:"record",filter:r=>r.typeName===e&&r.type===n,up:r=>{const o=t.up(r.props);o&&(r.props=o)},down:typeof t.down=="function"?r=>{const o=t.down(r.props);o&&(r.props=o)}:void 0}}const nM=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],tf={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",fill:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",fill:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",fill:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",fill:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",fill:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",fill:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",fill:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",fill:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",fill:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",fill:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",fill:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",fill:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function ss(e){return e.isDarkMode?tf.darkMode:tf.lightMode}const sr=Yt.defineEnum("tldraw:color",{defaultValue:"black",values:nM}),rM=Yt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:nM}),Ki=Yt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Wi=Yt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),So=Yt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),oM={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},vo=Yt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),sM=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],nf=Yt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:sM}),rf=Yt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:sM}),iM={labelColor:rM,color:sr,fill:Wi,dash:Ki,size:vo,arrowheadStart:nf,arrowheadEnd:rf,font:So,start:Hi,end:Hi,bend:de,text:pe,labelPosition:de,scale:Ct},Pa=Gr("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function Od(e){return tM("shape","arrow",e)}const aM=el({sequenceId:"com.tldraw.shape.arrow",sequence:[Od({id:Pa.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),Od({id:Pa.AddIsPrecise,up:({start:e,end:n})=>{e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5)),n.type==="binding"&&(n.isPrecise=!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5))},down:({start:e,end:n})=>{e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise),n.type==="binding"&&(n.isPrecise||(n.normalizedAnchor={x:.5,y:.5}),delete n.isPrecise)}}),Od({id:Pa.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:Pa.ExtractBindings,scope:"store",up:e=>{const n=Object.values(e).filter(t=>t.typeName==="shape"&&t.type==="arrow");for(const t of n){const{start:r,end:o}=t.props;if(r.type==="binding"){const s=Ri(),i={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};e[s]=i,t.props.start={x:0,y:0}}else delete t.props.start.type;if(o.type==="binding"){const s=Ri(),i={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:o.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:o.normalizedAnchor,isExact:o.isExact,isPrecise:o.isPrecise}};e[s]=i,t.props.end={x:0,y:0}}else delete t.props.end.type}}},Od({id:Pa.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}})]}),lM={terminal:ng("start","end"),normalizedAnchor:Hi,isExact:we,isPrecise:we},cM={sequence:[{dependsOn:[Pa.ExtractBindings]}]},qH=Io("camera",Se({typeName:cn("camera"),id:er("camera"),x:de,y:de,z:de,meta:Bt})),ZH=Bn("com.tldraw.camera",{AddMeta:1}),QH=cr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:ZH.AddMeta,up:e=>{e.meta={}}}]}),lo=Co("camera",{validator:qH,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),JH=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"]),uM=tg(JH),e9=Se({type:uM,rotation:de}),t9=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),n9=tg(t9),r9=new Set(["starting","paused","active","stopping"]),dM=Se({id:pe,points:zt(Hi),size:Jp,color:n9,opacity:de,state:tg(r9),delay:de,shrink:de,taper:we}),hu=er("page"),o9=Io("page",Se({typeName:cn("page"),id:hu,name:pe,index:Ow,meta:Bt})),s9=Bn("com.tldraw.page",{AddMeta:1}),i9=cr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:s9.AddMeta,up:e=>{e.meta={}}}]}),Qo=Co("page",{validator:o9,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function In(e){return Qo.isId(e)}const a9={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1},hM=e=>e?Fc(e,n=>a9[n]):null;er("instance");function l9(e){const n={};for(const[r,o]of e)n[r]=ZT(o);const t=Io("instance",Se({typeName:cn("instance"),id:er("instance"),currentPageId:hu,followingUserId:pe.nullable(),brush:zc.nullable(),opacityForNextShape:JT,stylesForNextShape:Se(n),cursor:e9,scribbles:zt(dM),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:zc,insets:zt(we),zoomBrush:zc.nullable(),isPenMode:we,isGridMode:we,chatMessage:pe,isChatting:we,highlightedUserIds:zt(pe),isFocused:we,devicePixelRatio:de,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:zt(pe),isChangingStyle:we,isReadonly:we,meta:Bt,duplicateProps:Se({shapeIds:zt(er("shape")),offset:Se({x:de,y:de})}).nullable()}));return Co("instance",{validator:t,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const qe=Bn("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25}),c9=cr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:qe.AddTransparentExportBgs,up:e=>({...e,exportBackground:!0})},{id:qe.RemoveDialog,up:({dialog:e,...n})=>n},{id:qe.AddToolLockMode,up:e=>({...e,isToolLocked:!1})},{id:qe.RemoveExtraPropsForNextShape,up:({propsForNextShape:e,...n})=>({...n,propsForNextShape:Object.fromEntries(Object.entries(e).filter(([t])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(t)))})},{id:qe.AddLabelColor,up:({propsForNextShape:e,...n})=>({...n,propsForNextShape:{...e,labelColor:"black"}})},{id:qe.AddFollowingUserId,up:e=>({...e,followingUserId:null})},{id:qe.RemoveAlignJustify,up:e=>{let n=e.propsForNextShape.align;return n==="justify"&&(n="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:n}}}},{id:qe.AddZoom,up:e=>({...e,zoomBrush:null})},{id:qe.AddVerticalAlign,up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}})},{id:qe.AddScribbleDelay,up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e}},{id:qe.RemoveUserId,up:({userId:e,...n})=>n},{id:qe.AddIsPenModeAndIsGridMode,up:e=>({...e,isPenMode:!1,isGridMode:!1})},{id:qe.HoistOpacity,up:({propsForNextShape:{opacity:e,...n},...t})=>({...t,opacityForNextShape:Number(e??"1"),propsForNextShape:n})},{id:qe.AddChat,up:e=>({...e,chatMessage:"",isChatting:!1})},{id:qe.AddHighlightedUserIds,up:e=>({...e,highlightedUserIds:[]})},{id:qe.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:e,...n})=>({...n,stylesForNextShape:{}})},{id:qe.AddMeta,up:e=>({...e,meta:{}})},{id:qe.RemoveCursorColor,up:e=>{const{color:n,...t}=e.cursor;return{...e,cursor:t}}},{id:qe.AddLonelyProperties,up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:qe.ReadOnlyReadonly,up:({isReadOnly:e,...n})=>({...n,isReadonly:e})},{id:qe.AddHoveringCanvas,up:e=>({...e,isHoveringCanvas:null})},{id:qe.AddScribbles,up:({scribble:e,...n})=>({...n,scribbles:[]})},{id:qe.AddInset,up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...n})=>({...n})},{id:qe.AddDuplicateProps,up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...n})=>({...n})},{id:qe.RemoveCanMoveCamera,up:({canMoveCamera:e,...n})=>({...n}),down:e=>({...e,canMoveCamera:!0})}]}),gn="instance:instance",u9=Io("instance_page_state",Se({typeName:cn("instance_page_state"),id:er("instance_page_state"),pageId:hu,selectedShapeIds:zt(gr),hintingShapeIds:zt(gr),erasingShapeIds:zt(gr),hoveredShapeId:gr.nullable(),editingShapeId:gr.nullable(),croppingShapeId:gr.nullable(),focusedGroupId:gr.nullable(),meta:Bt})),oc=Bn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),d9=cr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:oc.AddCroppingId,up(e){e.croppingShapeId=null}},{id:oc.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:oc.AddMeta,up:e=>{e.meta={}}},{id:oc.RenameProperties,up:e=>{},down:e=>{}},{id:oc.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}}]}),$r=Co("instance_page_state",{validator:u9,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!1,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),h9=Io("pointer",Se({typeName:cn("pointer"),id:er("pointer"),x:de,y:de,lastActivityTimestamp:de,meta:Bt})),p9=Bn("com.tldraw.pointer",{AddMeta:1}),f9=cr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:p9.AddMeta,up:e=>{e.meta={}}}]}),Rw=Co("pointer",{validator:h9,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),of=Rw.createId("pointer"),g9=Io("instance_presence",Se({typeName:cn("instance_presence"),id:er("instance_presence"),userId:pe,userName:pe,lastActivityTimestamp:de,followingUserId:pe.nullable(),cursor:Se({x:de,y:de,type:uM,rotation:de}),color:pe,camera:Se({x:de,y:de,z:de}),screenBounds:zc,selectedShapeIds:zt(er("shape")),currentPageId:er("page"),brush:zc.nullable(),scribbles:zt(dM),chatMessage:pe,meta:Bt})),sc=Bn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),m9=cr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:sc.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:sc.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:sc.AddChatMessage,up:e=>{e.chatMessage=""}},{id:sc.AddMeta,up:e=>{e.meta={}}},{id:sc.RenameSelectedShapeIds,up:e=>{}}]}),y9=Co("instance_presence",{validator:g9,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:{}})),S9=Io("document",Se({typeName:cn("document"),id:cn("document:document"),gridSize:de,name:pe,meta:Bt})),YP=Bn("com.tldraw.document",{AddName:1,AddMeta:2}),v9=cr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:YP.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:YP.AddMeta,up:e=>{e.meta={}}}]}),Lw=Co("document",{validator:S9,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),hv=Lw.createId("document");function x9(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function XP(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const w9=({error:e,phase:n,record:t,recordBefore:r})=>{throw xw(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?XP(rt(r)):void 0,recordAfter:XP(rt(t))}}),e};function b9(){return[Qo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function P9(e){const n=e.query.ids("page"),t=()=>{if(!e.has(hv))return e.put([Lw.create({id:hv,name:e.props.defaultName})]),t();if(!e.has(of))return e.put([Rw.create({id:of})]),t();const r=n.get();if(r.size===0)return e.put(b9()),t();const o=()=>[...r].map(l=>e.get(l)).sort(x9)[0].id,s=e.get(gn);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:gn,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const l of r){const c=$r.createId(l);e.has(c)||i.add(c);const d=lo.createId(l);e.has(d)||a.add(d)}i.size>0&&e.put([...i].map(l=>$r.create({id:l,pageId:$r.parseId(l)}))),a.size>0&&e.put([...a].map(l=>lo.create({id:l})))};return t}const C9=Dw("bookmark",Se({title:pe,description:pe,image:pe,favicon:pe,src:Ui.nullable()})),qP=Bn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),I9=cr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:qP.MakeUrlsValid,up:e=>{Ui.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:qP.AddFavicon,up:e=>{Ui.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),E9=Dw("image",Se({w:de,h:de,fileSize:de,name:pe,isAnimated:we,mimeType:pe.nullable(),src:Ui.nullable()})),Dd=Bn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),k9=cr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:Dd.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Dd.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:Dd.MakeUrlsValid,up:e=>{Ui.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:Dd.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),_9=Dw("video",Se({w:de,h:de,fileSize:de,name:pe,isAnimated:we,mimeType:pe.nullable(),src:Ui.nullable()})),Rd=Bn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),T9=cr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:Rd.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Rd.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:Rd.MakeUrlsValid,up:e=>{Ui.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:Rd.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),M9=Io("asset",Aw("type",{image:E9,video:_9,bookmark:C9})),j9=Bn("com.tldraw.asset",{AddMeta:1}),A9=cr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:j9.AddMeta,up:e=>{e.meta={}}}]}),ki=Co("asset",{validator:M9,scope:"document"}).withDefaultProperties(()=>({meta:{}})),pM={w:Ct,h:Ct,assetId:rg.nullable(),url:or},ZP=Gr("bookmark",{NullAssetId:1,MakeUrlsValid:2}),fM={sequence:[{id:ZP.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:"retired"},{id:ZP.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}}]},gM=Se({type:ng("free","straight"),points:zt(Hi)}),mM={color:sr,fill:Wi,dash:Ki,size:vo,segments:zt(gM),isComplete:we,isClosed:we,isPen:we,scale:Ct},QP=Gr("draw",{AddInPen:1,AddScale:2}),yM={sequence:[{id:QP.AddInPen,up:e=>{const{points:n}=e.segments[0];if(n.length===0){e.isPen=!1;return}let t=!(n[0].z===0||n[0].z===.5);n[1]&&(t=t&&!(n[1].z===0||n[1].z===.5)),e.isPen=t},down:"retired"},{id:QP.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]};var O9={};const JP=/(^\/r\/[^/]+\/?$)/,Oe=e=>{try{return new URL(e)}catch{return}},$u=[{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 n=Oe(e);if(n&&n.pathname.match(JP))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(JP))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 n=Oe(e);if(n&&n.pathname.match(/^\/embed\/?$/)){const t=n.searchParams.get("url");if(t)return t}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:e=>{if(e.includes("/maps/")){const n=e.match(/@(.*),(.*),(.*)z/);let t;if(n){const[,r,o,s]=n;t=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${O9.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${o}&zoom=${s}`}else t="";return t}},fromEmbedUrl:e=>{const n=Oe(e);if(!n)return;if(n.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&n.searchParams.has("center")&&n.searchParams.get("zoom")){const r=n.searchParams.get("zoom"),[o,s]=n.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 n=Oe(e),t=n&&n.pathname.match(/\/v\/(.+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:e=>{const n=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,t=e.match(n);if(t){const[r,o]=t;return`https://scratch.mit.edu/projects/embed/${o}`}},fromEmbedUrl:e=>{const n=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o]=t;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,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Oe(e);if(!n)return;const t=n.hostname.replace(/^www./,"");if(t==="youtu.be")return`https://www.youtube.com/embed/${n.pathname.split("/").filter(Boolean)[0]}`;if((t==="youtube.com"||t==="m.youtube.com")&&n.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${n.searchParams.get("v")}`},fromEmbedUrl:e=>{const n=Oe(e);if(!n)return;if(n.hostname.replace(/^www./,"")==="youtube.com"){const r=n.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:e=>{const n=Oe(e),t=n==null?void 0:n.searchParams.get("cid");if(n!=null&&n.pathname.match(/\/calendar\/u\/0/)&&t){n.pathname="/calendar/embed";const r=Array.from(n.searchParams.keys());for(const o of r)n.searchParams.delete(o);return n.searchParams.set("src",t),n.href}},fromEmbedUrl:e=>{const n=Oe(e),t=n==null?void 0:n.searchParams.get("src");if(n!=null&&n.pathname.match(/\/calendar\/embed/)&&t){n.pathname="/calendar/u/0";const r=Array.from(n.searchParams.keys());for(const o of r)n.searchParams.delete(o);return n.searchParams.set("cid",t),n.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:e=>{const n=Oe(e);if(n!=null&&n.pathname.match(/^\/presentation/)&&(n!=null&&n.pathname.match(/\/pub\/?$/))){n.pathname=n.pathname.replace(/\/pub$/,"/embed");const t=Array.from(n.searchParams.keys());for(const r of t)n.searchParams.delete(r);return n.href}},fromEmbedUrl:e=>{const n=Oe(e);if(n!=null&&n.pathname.match(/^\/presentation/)&&(n!=null&&n.pathname.match(/\/embed\/?$/))){n.pathname=n.pathname.replace(/\/embed$/,"/pub");const t=Array.from(n.searchParams.keys());for(const r of t)n.searchParams.delete(r);return n.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.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 n=Oe(e);if(n&&n.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/\/@([^/]+)\/([^/]+)/)&&n.searchParams.has("embed"))return n.searchParams.delete("embed"),n.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/map\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/map\//))return n.pathname=n.pathname.replace(/^\/embed/,""),n.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/(artist|album)\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/(artist|album)\//))return n.origin+n.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="vimeo.com"&&n.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+n.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="player.vimeo.com"){const t=n.pathname.match(/^\/video\/([^/]+)\/?$/);if(t)return"https://vimeo.com/"+t[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.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 n=Oe(e);if(n&&n.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${n.origin}/embed${n.pathname}?cell=*`;if(n&&n.pathname.match(/^\/d\/([^/]+)\/?$/)){const t=n.pathname.replace(/^\/d/,"");return`${n.origin}/embed${t}?cell=*`}},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${n.origin}${n.pathname.replace("/embed","")}#cell-*`;if(n&&n.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${n.origin}${n.pathname.replace("/embed","/d")}#cell-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="www.desmos.com"&&n.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&n.search===""&&n.hash==="")return`${e}?embed`},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="www.desmos.com"&&n.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&n.search==="?embed"&&n.hash==="")return e.replace("?embed","")}}],D9={"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},SM={w:Ct,h:Ct,url:pe},Ld=Gr("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),vM={sequence:[{id:Ld.GenOriginalUrlInEmbed,up:e=>{try{const n=e.url,t=new URL(n).host.replace("www.","");let r;for(const o of $u)if(o.hostnames.includes(t))try{r=o.fromEmbedUrl(n)}catch(s){console.warn(s)}e.tmpOldUrl=e.url,e.url=r??""}catch{e.url="",e.tmpOldUrl=e.url}},down:"retired"},{id:Ld.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:Ld.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:Ld.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},xM={w:Ct,h:Ct,name:pe},wM={sequence:[]},sf=Yt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),af=Yt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Fr=Yt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),bM={geo:Fr,labelColor:rM,color:sr,fill:Wi,dash:Ki,size:vo,font:So,align:sf,verticalAlign:af,url:or,w:Ct,h:Ct,growY:Jp,text:pe,scale:Ct},Mo=Gr("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),PM={sequence:[{id:Mo.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Mo.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:Mo.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:Mo.AddCheckBox,up:e=>{},down:"retired"},{id:Mo.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:Mo.MigrateLegacyAlign,up:e=>{let n;switch(e.align){case"start":n="start-legacy";break;case"end":n="end-legacy";break;default:n="middle-legacy";break}e.align=n},down:"retired"},{id:Mo.AddCloud,up:e=>{},down:"retired"},{id:Mo.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}},{id:Mo.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},CM={},IM={sequence:[]},EM={color:sr,size:vo,segments:zt(gM),isComplete:we,isPen:we,scale:Ct},R9=Gr("highlight",{AddScale:1}),kM={sequence:[{id:R9.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},L9=Se({topLeft:Hi,bottomRight:Hi}),_M={w:Ct,h:Ct,playing:we,url:or,assetId:rg.nullable(),crop:L9.nullable()},Hm=Gr("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3}),TM={sequence:[{id:Hm.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Hm.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:Hm.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}}]},lf=Yt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),$9=Se({id:pe,index:Ow,x:de,y:de}),MM={color:sr,dash:Ki,size:vo,spline:lf,points:ef(pe,$9),scale:Ct},ic=Gr("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),jM={sequence:[{id:ic.AddSnapHandles,up:e=>{for(const n of Object.values(e.handles))n.canSnap=!0},down:"retired"},{id:ic.RemoveExtraHandleProps,up:e=>{e.handles=TT(Object.values(e.handles).map(n=>[n.index,{x:n.x,y:n.y}]))},down:e=>{const n=Object.entries(e.handles).map(([t,r])=>({index:t,...r})).sort(on);e.handles=Object.fromEntries(n.map((t,r)=>{const o=r===0?"start":r===n.length-1?"end":`handle:${t.index}`;return[o,{id:o,type:"vertex",canBind:!1,canSnap:!0,index:t.index,x:t.x,y:t.y}]}))}},{id:ic.HandlesToPoints,up:e=>{const n=Object.entries(e.handles).map(([t,{x:r,y:o}])=>({x:r,y:o,index:t})).sort(on);e.points=n.map(({x:t,y:r})=>({x:t,y:r})),delete e.handles},down:e=>{const n=du(e.points.length);e.handles=Object.fromEntries(e.points.map((t,r)=>[n[r],{x:t.x,y:t.y}])),delete e.points}},{id:ic.PointIndexIds,up:e=>{const n=du(e.points.length);e.points=Object.fromEntries(e.points.map((t,r)=>{const o=n[r];return[o,{id:o,index:o,x:t.x,y:t.y}]}))},down:e=>{const n=Object.values(e.points).sort(on);e.points=n.map(({x:t,y:r})=>({x:t,y:r}))}},{id:ic.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},AM={color:sr,size:vo,font:So,fontSizeAdjustment:Jp,align:sf,verticalAlign:af,growY:Jp,url:or,text:pe,scale:Ct},xi=Gr("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),OM={sequence:[{id:xi.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:xi.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:xi.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:"retired"},{id:xi.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:xi.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}},{id:xi.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}},{id:xi.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},pv=Yt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),DM={color:sr,size:vo,font:So,textAlign:pv,w:Ct,text:pe,scale:Ct,autoSize:we},eC=Gr("text",{RemoveJustify:1,AddTextAlign:2}),RM={sequence:[{id:eC.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:eC.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},LM={w:Ct,h:Ct,time:de,playing:we,url:or,assetId:rg.nullable()},tC=Gr("video",{AddUrlProp:1,MakeUrlsValid:2}),$M={sequence:[{id:tC.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:tC.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}}]},$d=Bn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),F9=el({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:$d.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[n,t]of Fn(e))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete e[n]}},{id:$d.AddInstancePresenceType,scope:"store",up(e){}},{id:$d.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[n,t]of Fn(e))t.typeName.match(/^(user|user_presence)$/)&&delete e[n]}},{id:$d.RemoveUserDocument,scope:"store",up:e=>{for(const[n,t]of Fn(e))t.typeName.match("user_document")&&delete e[n]}}]}),N9={arrow:{migrations:aM,props:iM},bookmark:{migrations:fM,props:pM},draw:{migrations:yM,props:mM},embed:{migrations:vM,props:SM},frame:{migrations:wM,props:xM},geo:{migrations:PM,props:bM},group:{migrations:IM,props:CM},highlight:{migrations:kM,props:EM},image:{migrations:TM,props:_M},line:{migrations:jM,props:MM},note:{migrations:OM,props:AM},text:{migrations:RM,props:DM},video:{migrations:$M,props:LM}},z9={arrow:{migrations:cM,props:lM}};function B9({shapes:e=N9,bindings:n=z9,migrations:t}={}){const r=new Map;for(const a of gt(e))for(const l of eM(a.props??{}).keys()){if(r.has(l.id)&&r.get(l.id)!==l)throw new Error(`Multiple StyleProp instances with the same id: ${l.id}`);r.set(l.id,l)}const o=XH(e),s=GH(n),i=l9(r);return Mw.create({asset:ki,binding:s,camera:lo,document:Lw,instance:i,instance_page_state:$r,page:Qo,instance_presence:y9,pointer:Rw,shape:o},{migrations:[F9,A9,QH,v9,c9,d9,i9,m9,f9,YH,I9,k9,T9,...VP("shape",e),...VP("binding",n),...t??[]],onValidationFailure:w9,createIntegrityChecker:P9})}const pu=[{locale:"id",label:"Bahasa Indonesia"},{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 U9(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return H9(e)}function H9(e){for(const n of e){const t=K9(n);if(t)return t}return"en"}const nC={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function K9(e){const n=pu.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=pu.find(s=>s.locale===t);if(o)return o.locale}return t in nC?nC[t]:null}var FM={exports:{}};/*!
|
|
Copyright (c) 2018 Jed Watson.
|
|
Licensed under the MIT License (MIT), see
|
|
http://jedwatson.github.io/classnames
|
|
*/(function(e){(function(){var n={}.hasOwnProperty;function t(){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 t.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)n.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?(t.default=t,e.exports=t):window.classNames=t})()})(FM);var W9=FM.exports;const ce=ei(W9),G9={error:null};class NM extends P.Component{constructor(){super(...arguments);m(this,"state",G9)}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,o;(o=(r=this.props).onError)==null||o.call(r,t)}render(){const{error:t}=this.state;if(t!==null){const{fallback:r}=this.props;return u.jsx(r,{error:t})}return this.props.children}}function fu({children:e,fallback:n,...t}){return n===null?u.jsx(u.Fragment,{children:e}):u.jsx(NM,{fallback:n,...t,children:e})}const og=xe.createContext(null);function B(){const e=xe.useContext(og);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function V9(){return u.jsx("div",{className:"tl-background"})}function Rl(e,n,t,r,o,s){P.useLayoutEffect(()=>{const i=e.current;if(!i||n===void 0)return;let a=`translate(${n}px, ${t}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 jt={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 w{constructor(n=0,t=0,r=1){this.x=n,this.y=t,this.z=r}get pressure(){return this.z}set(n=this.x,t=this.y,r=this.z){return this.x=n,this.y=t,this.z=r,this}setTo({x:n=0,y:t=0,z:r=1}){return this.x=n,this.y=t,this.z=r,this}rot(n){if(n===0)return this;const{x:t,y:r}=this,o=Math.sin(n),s=Math.cos(n);return this.x=t*s-r*o,this.y=t*o+r*s,this}rotWith(n,t){if(t===0)return this;const r=this.x-n.x,o=this.y-n.y,s=Math.sin(t),i=Math.cos(t);return this.x=n.x+(r*i-o*s),this.y=n.y+(r*s+o*i),this}clone(){const{x:n,y:t,z:r}=this;return new w(n,t,r)}sub(n){return this.x-=n.x,this.y-=n.y,this}subXY(n,t){return this.x-=n,this.y-=t,this}subScalar(n){return this.x-=n,this.y-=n,this}add(n){return this.x+=n.x,this.y+=n.y,this}addXY(n,t){return this.x+=n,this.y+=t,this}addScalar(n){return this.x+=n,this.y+=n,this}clamp(n,t){return this.x=Math.max(this.x,n),this.y=Math.max(this.y,n),t!==void 0&&(this.x=Math.min(this.x,t),this.y=Math.min(this.y,t)),this}div(n){return this.x/=n,this.y/=n,this}divV(n){return this.x/=n.x,this.y/=n.y,this}mul(n){return this.x*=n,this.y*=n,this}mulV(n){return this.x*=n.x,this.y*=n.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(n,t){const r=w.Tan(n,this);return this.add(r.mul(t))}neg(){return this.x*=-1,this.y*=-1,this}cross(n){return this.x=this.y*n.z-this.z*n.y,this.y=this.z*n.x-this.x*n.z,this}dpr(n){return w.Dpr(this,n)}cpr(n){return w.Cpr(this,n)}len2(){return w.Len2(this)}len(){return w.Len(this)}pry(n){return w.Pry(this,n)}per(){const{x:n,y:t}=this;return this.x=t,this.y=-n,this}uni(){return w.Uni(this)}tan(n){return w.Tan(this,n)}dist(n){return w.Dist(this,n)}distanceToLineSegment(n,t){return w.DistanceToLineSegment(n,t,this)}slope(n){return w.Slope(this,n)}snapToGrid(n){return this.x=Math.round(this.x/n)*n,this.y=Math.round(this.y/n)*n,this}angle(n){return w.Angle(this,n)}toAngle(){return w.ToAngle(this)}lrp(n,t){return this.x=this.x+(n.x-this.x)*t,this.y=this.y+(n.y-this.y)*t,this}equals(n){return w.Equals(this,n)}equalsXY(n,t){return w.EqualsXY(this,n,t)}norm(){const n=this.len();return this.x=n===0?0:this.x/n,this.y=n===0?0:this.y/n,this}toFixed(){return w.ToFixed(this)}toString(){return w.ToString(w.ToFixed(this))}toJson(){return w.ToJson(this)}toArray(){return w.ToArray(this)}static Add(n,t){return new w(n.x+t.x,n.y+t.y)}static AddXY(n,t,r){return new w(n.x+t,n.y+r)}static Sub(n,t){return new w(n.x-t.x,n.y-t.y)}static SubXY(n,t,r){return new w(n.x-t,n.y-r)}static AddScalar(n,t){return new w(n.x+t,n.y+t)}static SubScalar(n,t){return new w(n.x-t,n.y-t)}static Div(n,t){return new w(n.x/t,n.y/t)}static Mul(n,t){return new w(n.x*t,n.y*t)}static DivV(n,t){return new w(n.x/t.x,n.y/t.y)}static MulV(n,t){return new w(n.x*t.x,n.y*t.y)}static Neg(n){return new w(-n.x,-n.y)}static Per(n){return new w(n.y,-n.x)}static Abs(n){return new w(Math.abs(n.x),Math.abs(n.y))}static Dist(n,t){return((n.y-t.y)**2+(n.x-t.x)**2)**.5}static DistMin(n,t,r){return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)<r**2}static Dist2(n,t){return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)}static Dpr(n,t){return n.x*t.x+n.y*t.y}static Cross(n,t){return new w(n.y*t.z-n.z*t.y,n.z*t.x-n.x*t.z)}static Cpr(n,t){return n.x*t.y-t.x*n.y}static Len2(n){return n.x*n.x+n.y*n.y}static Len(n){return(n.x*n.x+n.y*n.y)**.5}static Pry(n,t){return w.Dpr(n,t)/w.Len(t)}static Uni(n){return w.Div(n,w.Len(n))}static Tan(n,t){return w.Uni(w.Sub(n,t))}static Min(n,t){return new w(Math.min(n.x,t.x),Math.min(n.y,t.y))}static Max(n,t){return new w(Math.max(n.x,t.x),Math.max(n.y,t.y))}static From({x:n,y:t,z:r=1}){return new w(n,t,r)}static FromArray(n){return new w(n[0],n[1])}static Rot(n,t=0){const r=Math.sin(t),o=Math.cos(t);return new w(n.x*o-n.y*r,n.x*r+n.y*o)}static RotWith(n,t,r){const o=n.x-t.x,s=n.y-t.y,i=Math.sin(r),a=Math.cos(r);return new w(t.x+(o*a-s*i),t.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(n,t,r){return w.Mul(t,w.Sub(r,n).pry(t)).add(n)}static NearestPointOnLineSegment(n,t,r,o=!0){if(w.Equals(n,r)||w.Equals(t,r))return w.From(r);const s=w.Tan(t,n),i=w.Add(n,w.Mul(s,w.Sub(r,n).pry(s)));if(o){if(i.x<Math.min(n.x,t.x))return w.Cast(n.x<t.x?n:t);if(i.x>Math.max(n.x,t.x))return w.Cast(n.x>t.x?n:t);if(i.y<Math.min(n.y,t.y))return w.Cast(n.y<t.y?n:t);if(i.y>Math.max(n.y,t.y))return w.Cast(n.y>t.y?n:t)}return i}static DistanceToLineThroughPoint(n,t,r){return w.Dist(r,w.NearestPointOnLineThroughPoint(n,t,r))}static DistanceToLineSegment(n,t,r,o=!0){return w.Dist(r,w.NearestPointOnLineSegment(n,t,r,o))}static Snap(n,t=1){return new w(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}static Cast(n){return n instanceof w?n:w.From(n)}static Slope(n,t){return n.x===t.y?NaN:(n.y-t.y)/(n.x-t.x)}static IsNaN(n){return isNaN(n.x)||isNaN(n.y)}static Angle(n,t){return Math.atan2(t.y-n.y,t.x-n.x)}static Lrp(n,t,r){return w.Sub(t,n).mul(r).add(n)}static Med(n,t){return new w((n.x+t.x)/2,(n.y+t.y)/2)}static Equals(n,t){return Math.abs(n.x-t.x)<1e-4&&Math.abs(n.y-t.y)<1e-4}static EqualsXY(n,t,r){return n.x===t&&n.y===r}static Clockwise(n,t,r){return(r.x-n.x)*(t.y-n.y)-(t.x-n.x)*(r.y-n.y)<0}static Rescale(n,t){const r=w.Len(n);return new w(t*n.x/r,t*n.y/r)}static ScaleWithOrigin(n,t,r){return w.Sub(n,r).mul(t).add(r)}static ToFixed(n){return new w($o(n.x),$o(n.y))}static ToInt(n){return new w(parseInt(n.x.toFixed(0)),parseInt(n.y.toFixed(0)),parseInt((n.z??0).toFixed(0)))}static ToCss(n){return`${n.x},${n.y}`}static Nudge(n,t,r){return w.Add(n,w.Tan(t,n).mul(r))}static ToString(n){return`${n.x}, ${n.y}`}static ToAngle(n){let t=Math.atan2(n.y,n.x);return t<0&&(t+=Math.PI*2),t}static FromAngle(n,t=1){return new w(Math.cos(n)*t,Math.sin(n)*t)}static ToArray(n){return[n.x,n.y,n.z]}static ToJson(n){const{x:t,y:r,z:o}=n;return{x:t,y:r,z:o}}static Average(n){const t=n.length,r=new w(0,0);if(t===0)return r;for(let o=0;o<t;o++)r.add(n[o]);return r.div(t)}static Clamp(n,t,r){return r===void 0?new w(Math.min(Math.max(n.x,t)),Math.min(Math.max(n.y,t))):new w(Math.min(Math.max(n.x,t),r),Math.min(Math.max(n.y,t),r))}static PointsBetween(n,t,r=6){const o=[];for(let s=0;s<r;s++){const i=jt.easeInQuad(s/(r-1)),a=w.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-Y9(i))*.65),o.push(a)}return o}static SnapToGrid(n,t=8){return new w(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}}const Y9=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ie(e){return`${N(e.x)},${N(e.y)} `}function Tn(e,n){return`${N((e.x+n.x)/2)},${N((e.y+n.y)/2)} `}const _e=Math.PI,Ve=_e/2,Re=_e*2,X9=Math.sin;function _t(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function Fd(e,n=1e10){return e?Math.round(e*n)/n:0}function Us(e,n,t=1e-6){return Math.abs(e-n)<=t}function zM(e,n){const t=Math.pow(e-n,2)/Math.pow(e+n,2);return _e*(e+n)*(1+3*t/(10+Math.sqrt(4-3*t)))}function Hs(e){return e=e%Re,e<0?e=e+Re:e===0&&(e=0),e}function Fu(e,n){return e=Hs(e),n=Hs(n),e>n&&(n+=Re),n-e}function BM(e,n){return Re-Fu(e,n)}function Mh(e,n){const t=(n-e)%Re;return 2*t%Re-t}function fv(e){return(Re+e)%Re}function cf(e,n){const t=Re/n;let r=Math.floor((fv(e)+t/2)/t)*t%Re;return r<_e&&(r+=Re),r>_e&&(r-=Re),r}function UM(e,n){return e===n||Us(e%(Math.PI/2)-n%(Math.PI/2),0)}function q9(e){return e*_e/180}function Z9(e){return e*180/_e}function Gi(e,n,t){return new w(e.x,e.y).add(w.FromAngle(t,n))}function Km(e,n,t){const r=e/2,o=n/2,s=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let S=0;S<t;S++){const g=Re/t,x=-Ve+S*g,y=r+r*Math.cos(x),v=o+o*Math.sin(x);y<i&&(i=y),v<l&&(l=v),y>a&&(a=y),v>c&&(c=v),s.push(new w(y,v))}const d=a-i,h=c-l,p=e-d,f=n-h;if(p!==0||f!==0)for(let S=0;S<s.length;S++){const g=s[S];g.x=(g.x-i)/d*e,g.y=(g.y-l)/h*n}return s}function ac(e,n,t,r){return e<r&&t<n}function Or(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function rC(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function tr(e,n){let t=0,r,o;for(let s=0;s<n.length;s++){if(r=n[s],r.x===e.x&&r.y===e.y||(o=n[(s+1)%n.length],w.Dist(e,r)+w.Dist(e,o)===w.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&rC(r,o,e)>0&&(t+=1):o.y<=e.y&&rC(r,o,e)<0&&(t-=1)}return t!==0}function N(e){return Math.round(e*1e4)/1e4}function $o(e){return Math.round(e*100)/100}const oC=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function Is(e,n,t){return t<0?Fu(e,n):BM(e,n)}function gv(e,n,t,r){let o;if(Math.abs(e)>_e){o=Mh(n,r);const s=Mh(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=Mh(n,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function Q9(e,n,t,r){const o=2*((n-e)%Re)%Re-(n-e)%Re;return r?(Re-Math.abs(o))*(t?1:-1):o}function $w(e,n,t){const r=-2*(e.x*(n.y-t.y)-e.y*(n.x-t.x)+n.x*t.y-t.x*n.y);return new w(((e.x*e.x+e.y*e.y)*(t.y-n.y)+(n.x*n.x+n.y*n.y)*(e.y-t.y)+(t.x*t.x+t.y*t.y)*(n.y-e.y))/r,((e.x*e.x+e.y*e.y)*(n.x-t.x)+(n.x*n.x+n.y*n.y)*(t.x-e.x)+(t.x*t.x+t.y*t.y)*(e.x-n.x))/r)}function J9(e,n,t,r,o){if(t===null)return[w.From(e),w.From(n)];const s=[],i=w.Angle(t,e),a=w.Angle(t,n),l=Fu(i,a);for(let c=0;c<o;c++){const d=c/(o-1),h=i+l*d,p=Gi(t,r,h);s.push(p)}return s}const Wm=({brush:e,color:n,opacity:t,className:r})=>{const o=P.useRef(null);Rl(o,e.x,e.y);const s=N(Math.max(1,e.w)),i=N(Math.max(1,e.h));return u.jsx("svg",{className:"tl-overlays__item",ref:o,children:n?u.jsxs("g",{className:"tl-brush",opacity:t,children:[u.jsx("rect",{width:s,height:i,fill:n,opacity:.75}),u.jsx("rect",{width:s,height:i,fill:"none",stroke:n,opacity:.1})]}):u.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},sC={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},iC={onResolveAsset:async e=>(e==null?void 0:e.props.src)||""},Gm={duration:0,easing:jt.easeInOutCubic},aC={CAMERA_MOVE:-10},e7=["top","right","bottom","left"],lC=0,Fw=2,Nd=1,cC=5,t7=128;var Vm={};const n7={},HM=Cn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),wt={logPreventDefaults:Cn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Cn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Cn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Cn("debugSvg",{defaults:{all:!1}}),showFps:Cn("showFps",{defaults:{all:!1}}),measurePerformance:Cn("measurePerformance",{defaults:{all:!1}}),throwToBlob:Cn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Cn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Cn("debugCursors",{defaults:{all:!1}}),forceSrgb:Cn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Cn("debugGeometry",{defaults:{all:!1}}),hideShapes:Cn("hideShapes",{defaults:{all:!1}}),editOnType:Cn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;aa("element removal logging",()=>{wt.logElementRemoves.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function Cn(e,{defaults:n,shouldStoreForSession:t=!0}){return r7({name:e,defaults:n,shouldStoreForSession:t})}function r7(e){const n=s7(e),t=e.shouldStoreForSession?o7(e.name):null,r=Mt(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&aa(`debug:${e.name}`,()=>{const o=r.get();o===n?LT(`tldraw_debug:${e.name}`):Cw(`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 o7(e){try{return JSON.parse(RT(`tldraw_debug:${e}`)??"null")}catch{return null}}function Ym(e){try{return e()}catch{return null}}function s7(e){switch(Ym(()=>Vm.TLDRAW_ENV)??Ym(()=>Vm.VERCEL_PUBLIC_TLDRAW_ENV)??Ym(()=>Vm.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 uf(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return uf(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ee(e){e.preventDefault(),wt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Nu(e,n){if(e.setPointerCapture(n.pointerId),wt.logPointerCaptures.get()){const t=HM.get();t.set(e,(t.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,n)}}function zu(e,n){if(e.hasPointerCapture(n.pointerId)&&(e.releasePointerCapture(n.pointerId),wt.logPointerCaptures.get())){const t=HM.get();t.get(e)===1?t.delete(e):t.has(e)?t.set(e,t.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,n)}}const Kt=e=>e.stopPropagation(),Jt=(e,n,t)=>{e&&e.style.setProperty(n,t)};function On(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 i7(){const e=B();return P.useMemo(function(){let r,o;function s(g){if(!g.isKilled){if(g.button===Fw){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...On(g)});return}g.button!==0&&g.button!==1&&g.button!==5||(Nu(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...On(g)}))}}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",...On(g)}))}function a(g){g.isKilled||g.button!==0&&g.button!==1&&g.button!==2&&g.button!==5||(r=g.clientX,o=g.clientY,zu(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...On(g)}))}function l(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const x=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!0:null})}function c(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const x=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!1:null})}function d(g){g.isKilled=!0,Ee(g)}function h(g){g.isKilled=!0,g.target instanceof HTMLElement&&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 y,v;if(Ee(g),!((v=(y=g.dataTransfer)==null?void 0:y.files)!=null&&v.length))return;const x=Array.from(g.dataTransfer.files);await e.putExternalContent({type:"files",files:x,point:e.screenToPage({x:g.clientX,y:g.clientY}),ignoreParent:!1})}function S(g){Kt(g)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:d,onTouchEnd:h,onClick:S}},[e])}function a7(){const e=B();P.useEffect(()=>{let n=e.getInstanceState().isCoarsePointer;const t=i=>{const a=i.pointerType!=="mouse";n!==a&&(n=a,e.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",t,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),o=e.environment.isFirefox&&!e.environment.isAndroid&&!e.environment.isIos,s=()=>{const i=o?!1:r.matches;n===i&&(n=i,e.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",s),s()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",s)}},[e])}const KM=P.createContext(null);function l7({container:e,children:n}){return u.jsx(KM.Provider,{value:e,children:n})}function un(){return Sr(P.useContext(KM),"useContainer used outside of <Tldraw />")}function c7(){const e=B(),n=un(),t=G("isFocused",()=>e.getInstanceState().isFocused,[e]);P.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=l=>{l.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]),P.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!zd()&&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(zd()||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(),e.focus());return}default:if(zd()||e.getIsMenuOpen())return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)},o=a=>{if(a.isKilled||(a.isKilled=!0,zd()||e.getIsMenuOpen())||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)};function s(a){var l,c;if(n.contains(a.target)){const d=a.touches[0].pageX,h=a.touches[0].radiusX||0;(d-h<10||d+h>e.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),Ee(a))}}const i=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ee(a)};return n.addEventListener("touchstart",s,{passive:!1}),n.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ee),document.addEventListener("gesturechange",Ee),document.addEventListener("gestureend",Ee),n.addEventListener("keydown",r),n.addEventListener("keyup",o),()=>{n.removeEventListener("touchstart",s),n.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ee),document.removeEventListener("gesturechange",Ee),document.removeEventListener("gestureend",Ee),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const u7=["input","select","button","textarea"];function zd(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||u7.indexOf(e.tagName.toLowerCase())>-1))}const d7=["textarea","input"];function h7(e){const n=B();P.useEffect(()=>{const t=e.current;if(!t)return;const r=o=>{var s;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:i}=o;if(d7.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||n.isIn("select.editing_shape"))return;Ee(o)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[n,e])}function p7(e,n,t){return Math.max(n,Math.min(e,t))}const Ut={toVector(e,n){return e===void 0&&(e=n),Array.isArray(e)?e:[e,e]},add(e,n){return[e[0]+n[0],e[1]+n[1]]},sub(e,n){return[e[0]-n[0],e[1]-n[1]]},addTo(e,n){e[0]+=n[0],e[1]+=n[1]},subTo(e,n){e[0]-=n[0],e[1]-=n[1]}};function uC(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function dC(e,n,t,r=.15){return r===0?p7(e,n,t):e<n?-uC(n-e,t-n,r)+n:e>t?+uC(e-t,t-n,r)+t:e}function f7(e,[n,t],[r,o]){const[[s,i],[a,l]]=e;return[dC(n,s,i,r),dC(t,a,l,o)]}function g7(e,n){if(typeof e!="object"||e===null)return e;var t=e[Symbol.toPrimitive];if(t!==void 0){var r=t.call(e,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(e)}function m7(e){var n=g7(e,"string");return typeof n=="symbol"?n:String(n)}function tn(e,n,t){return n=m7(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function hC(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),t.push.apply(t,r)}return t}function ut(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?hC(Object(t),!0).forEach(function(r){tn(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):hC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const WM={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 pC(e){return e?e[0].toUpperCase()+e.slice(1):""}const y7=["enter","leave"];function S7(e=!1,n){return e&&!y7.includes(n)}function v7(e,n="",t=!1){const r=WM[e],o=r&&r[n]||n;return"on"+pC(e)+pC(o)+(S7(t,o)?"Capture":"")}const x7=["gotpointercapture","lostpointercapture"];function w7(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=x7.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function b7(e,n=""){const t=WM[e],r=t&&t[n]||n;return e+r}function GM(e){return"touches"in e}function P7(e){return GM(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function C7(e){return Array.from(e.touches).filter(n=>{var t,r;return n.target===e.currentTarget||((t=e.currentTarget)===null||t===void 0||(r=t.contains)===null||r===void 0?void 0:r.call(t,n.target))})}function mv(e,n){try{const t=n.clientX-e.clientX,r=n.clientY-e.clientY,o=(n.clientX+e.clientX)/2,s=(n.clientY+e.clientY)/2,i=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:i,origin:[o,s]}}catch{}return null}function I7(e){return C7(e).map(n=>n.identifier)}function fC(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return mv(t,r)}const gC=40,mC=800;function VM(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=gC,t*=gC):r===2&&(n*=mC,t*=mC),[n,t]}function E7(e){const n={};if("buttons"in e&&(n.buttons=e.buttons),"shiftKey"in e){const{shiftKey:t,altKey:r,metaKey:o,ctrlKey:s}=e;Object.assign(n,{shiftKey:t,altKey:r,metaKey:o,ctrlKey:s})}return n}function df(e,...n){return typeof e=="function"?e(...n):e}function k7(){}function _7(...e){return e.length===0?k7:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function yC(e,n){return Object.assign({},n,e||{})}const T7=32;class YM{constructor(n,t,r){this.ctrl=n,this.args=t,this.key=r,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(n){this.ctrl.state[this.key]=n}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:n,shared:t,ingKey:r,args:o}=this;t[r]=n._active=n.active=n._blocked=n._force=!1,n._step=[!1,!1],n.intentional=!1,n._movement=[0,0],n._distance=[0,0],n._direction=[0,0],n._delta=[0,0],n._bounds=[[-1/0,1/0],[-1/0,1/0]],n.args=o,n.axis=void 0,n.memo=void 0,n.elapsedTime=n.timeDelta=0,n.direction=[0,0],n.distance=[0,0],n.overflow=[0,0],n._movementBound=[!1,!1],n.velocity=[0,0],n.movement=[0,0],n.delta=[0,0],n.timeStamp=0}start(n){const t=this.state,r=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=n.target,t.currentTarget=n.currentTarget,t.lastOffset=r.from?df(r.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=n.timeStamp)}computeValues(n){const t=this.state;t._values=n,t.values=this.config.transform(n)}computeInitial(){const n=this.state;n._initial=n._values,n.initial=n.values}compute(n){const{state:t,config:r,shared:o}=this;t.args=this.args;let s=0;if(n&&(t.event=n,r.preventDefault&&n.cancelable&&t.event.preventDefault(),t.type=n.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,E7(n)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=n.timeStamp-t.timeStamp,t.timeStamp=n.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const C=t._delta.map(Math.abs);Ut.addTo(t._distance,C)}this.axisIntent&&this.axisIntent(n);const[i,a]=t._movement,[l,c]=r.threshold,{_step:d,values:h}=t;if(r.hasCustomTransform?(d[0]===!1&&(d[0]=Math.abs(i)>=l&&h[0]),d[1]===!1&&(d[1]=Math.abs(a)>=c&&h[1])):(d[0]===!1&&(d[0]=Math.abs(i)>=l&&Math.sign(i)*l),d[1]===!1&&(d[1]=Math.abs(a)>=c&&Math.sign(a)*c)),t.intentional=d[0]!==!1||d[1]!==!1,!t.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[C,k]=h;p[0]=d[0]!==!1?C-d[0]:0,p[1]=d[1]!==!1?k-d[1]:0}else p[0]=d[0]!==!1?i-d[0]:0,p[1]=d[1]!==!1?a-d[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(p);const f=t.offset,S=t._active&&!t._blocked||t.active;S&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=o[this.ingKey]=t._active,n&&(t.first&&("bounds"in r&&(t._bounds=df(r.bounds,t)),this.setup&&this.setup()),t.movement=p,this.computeOffset()));const[g,x]=t.offset,[[y,v],[b,E]]=t._bounds;t.overflow=[g<y?-1:g>v?1:0,x<b?-1:x>E?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const I=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=f7(t._bounds,t.offset,I),t.delta=Ut.sub(t.offset,f),this.computeMovement(),S&&(!t.last||s>T7)){t.delta=Ut.sub(t.offset,f);const C=t.delta.map(Math.abs);Ut.addTo(t.distance,C),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&s>0&&(t.velocity=[C[0]/s,C[1]/s],t.timeDelta=s)}}emit(){const n=this.state,t=this.shared,r=this.config;if(n._active||this.clean(),(n._blocked||!n.intentional)&&!n._force&&!r.triggerAllEvents)return;const o=this.handler(ut(ut(ut({},t),n),{},{[this.aliasKey]:n.values}));o!==void 0&&(n.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function M7([e,n],t){const r=Math.abs(e),o=Math.abs(n);if(r>o&&r>t)return"x";if(o>r&&o>t)return"y"}class j7 extends YM{constructor(...n){super(...n),tn(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=Ut.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Ut.sub(this.state.offset,this.state.lastOffset)}axisIntent(n){const t=this.state,r=this.config;if(!t.axis&&n){const o=typeof r.axisThreshold=="object"?r.axisThreshold[P7(n)]:r.axisThreshold;t.axis=M7(t._movement,o)}t._blocked=(r.lockDirection||!!r.axis)&&!t.axis||!!r.axis&&r.axis!==t.axis}restrictToAxis(n){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":n[1]=0;break;case"y":n[0]=0;break}}}const A7=e=>e,SC=.15,XM={enabled(e=!0){return e},eventOptions(e,n,t){return ut(ut({},t.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[SC,SC];case!1:return[0,0];default:return Ut.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return Ut.toVector(e)},transform(e,n,t){const r=e||t.shared.transform;return this.hasCustomTransform=!!r,r||A7},threshold(e){return Ut.toVector(e,0)}},O7=0,Bu=ut(ut({},XM),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=O7){return e},bounds(e={}){if(typeof e=="function")return s=>Bu.bounds(e(s));if("current"in e)return()=>e.current;if(typeof HTMLElement=="function"&&e instanceof HTMLElement)return e;const{left:n=-1/0,right:t=1/0,top:r=-1/0,bottom:o=1/0}=e;return[[n,t],[r,o]]}}),Uu=typeof window<"u"&&window.document&&window.document.createElement;function qM(){return Uu&&"ontouchstart"in window}function D7(){return qM()||Uu&&window.navigator.maxTouchPoints>1}function R7(){return Uu&&"onpointerdown"in window}function L7(){return Uu&&"exitPointerLock"in window.document}function $7(){try{return"constructor"in GestureEvent}catch{return!1}}const vr={isBrowser:Uu,gesture:$7(),touch:qM(),touchscreen:D7(),pointer:R7(),pointerLock:L7()},F7=250,N7=180,z7=.5,B7=50,U7=250,H7=10,vC={mouse:0,touch:0,pen:8};ut(ut({},Bu),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&vr.pointerLock,vr.touch&&t?"touch":this.pointerLock?"mouse":vr.pointer&&!o?"pointer":vr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?F7:void 0,!(!vr.touchscreen||t===!1))return e||(t!==void 0?"y":void 0)},pointerCapture(e,n,{pointer:{capture:t=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&t},threshold(e,n,{filterTaps:t=!1,tapsThreshold:r=3,axis:o=void 0}){const s=Ut.toVector(e,t?r:o?1:0);return this.filterTaps=t,this.tapsThreshold=r,s},swipe({velocity:e=z7,distance:n=B7,duration:t=U7}={}){return{velocity:this.transform(Ut.toVector(e)),distance:this.transform(Ut.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return N7;case!1:return 0;default:return e}},axisThreshold(e){return e?ut(ut({},vC),e):vC},keyboardDisplacement(e=H7){return e}});function ZM(e){const[n,t]=e.overflow,[r,o]=e._delta,[s,i]=e._direction;(n<0&&r>0&&s<0||n>0&&r<0&&s>0)&&(e._movement[0]=e._movementBound[0]),(t<0&&o>0&&i<0||t>0&&o<0&&i>0)&&(e._movement[1]=e._movementBound[1])}const K7=30,W7=100;class G7 extends YM{constructor(...n){super(...n),tn(this,"ingKey","pinching"),tn(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const n=this.state;n._touchIds=[],n.canceled=!1,n.cancel=this.cancel.bind(this),n.turns=0}computeOffset(){const{type:n,movement:t,lastOffset:r}=this.state;n==="wheel"?this.state.offset=Ut.add(t,r):this.state.offset=[(1+t[0])*r[0],t[1]+r[1]]}computeMovement(){const{offset:n,lastOffset:t}=this.state;this.state.movement=[n[0]/t[0],n[1]-t[1]]}axisIntent(){const n=this.state,[t,r]=n._movement;if(!n.axis){const o=Math.abs(t)*K7-Math.abs(r);o<0?n.axis="angle":o>0&&(n.axis="scale")}}restrictToAxis(n){this.config.lockDirection&&(this.state.axis==="scale"?n[1]=0:this.state.axis==="angle"&&(n[0]=0))}cancel(){const n=this.state;n.canceled||setTimeout(()=>{n.canceled=!0,n._active=!1,this.compute(),this.emit()},0)}touchStart(n){this.ctrl.setEventIds(n);const t=this.state,r=this.ctrl.touchIds;if(t._active&&t._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(n),t._touchIds=Array.from(r).slice(0,2);const o=fC(n,t._touchIds);o&&this.pinchStart(n,o)}pointerStart(n){if(n.buttons!=null&&n.buttons%2!==1)return;this.ctrl.setEventIds(n),n.target.setPointerCapture(n.pointerId);const t=this.state,r=t._pointerEvents,o=this.ctrl.pointerIds;if(t._active&&Array.from(r.keys()).every(i=>o.has(i))||(r.size<2&&r.set(n.pointerId,n),t._pointerEvents.size<2))return;this.start(n);const s=mv(...Array.from(r.values()));s&&this.pinchStart(n,s)}pinchStart(n,t){const r=this.state;r.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(n),this.emit()}touchMove(n){if(!this.state._active)return;const t=fC(n,this.state._touchIds);t&&this.pinchMove(n,t)}pointerMove(n){const t=this.state._pointerEvents;if(t.has(n.pointerId)&&t.set(n.pointerId,n),!this.state._active)return;const r=mv(...Array.from(t.values()));r&&this.pinchMove(n,r)}pinchMove(n,t){const r=this.state,o=r._values[1],s=t.angle-o;let i=0;Math.abs(s)>270&&(i+=Math.sign(s)),this.computeValues([t.distance,t.angle-360*i]),r.origin=t.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(n),this.emit()}touchEnd(n){this.ctrl.setEventIds(n),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(n),this.emit())}pointerEnd(n){const t=this.state;this.ctrl.setEventIds(n);try{n.target.releasePointerCapture(n.pointerId)}catch{}t._pointerEvents.has(n.pointerId)&&t._pointerEvents.delete(n.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(n),this.emit())}gestureStart(n){n.cancelable&&n.preventDefault();const t=this.state;t._active||(this.start(n),this.computeValues([n.scale,n.rotation]),t.origin=[n.clientX,n.clientY],this.compute(n),this.emit())}gestureMove(n){if(n.cancelable&&n.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([n.scale,n.rotation]),t.origin=[n.clientX,n.clientY];const r=t._movement;t._movement=[n.scale-1,n.rotation],t._delta=Ut.sub(t._movement,r),this.compute(n),this.emit()}gestureEnd(n){this.state._active&&(this.state._active=!1,this.compute(n),this.emit())}wheel(n){const t=this.config.modifierKey;t&&(Array.isArray(t)?!t.find(r=>n[r]):!n[t])||(this.state._active?this.wheelChange(n):this.wheelStart(n),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(n){this.start(n),this.wheelChange(n)}wheelChange(n){"uv"in n||n.cancelable&&n.preventDefault();const r=this.state;r._delta=[-VM(n)[1]/W7*r.offset[0],0],Ut.addTo(r._movement,r._delta),ZM(r),this.state.origin=[n.clientX,n.clientY],this.compute(n),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(n){const t=this.config.device;t&&(n(t,"start",this[t+"Start"].bind(this)),n(t,"change",this[t+"Move"].bind(this)),n(t,"end",this[t+"End"].bind(this)),n(t,"cancel",this[t+"End"].bind(this)),n("lostPointerCapture","",this[t+"End"].bind(this))),this.config.pinchOnWheel&&n("wheel","",this.wheel.bind(this),{passive:!1})}}const V7=ut(ut({},XM),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!vr.touch&&vr.gesture)return"gesture";if(vr.touch&&r)return"touch";if(vr.touchscreen){if(vr.pointer)return"pointer";if(vr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=i=>{const a=yC(df(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=yC(df(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[o(),s()]:i=>[o(i),s(i)]},threshold(e,n,t){return this.lockDirection=t.axis==="lock",Ut.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});ut(ut({},Bu),{},{mouseOnly:(e=!0)=>e});class Y7 extends j7{constructor(...n){super(...n),tn(this,"ingKey","wheeling")}wheel(n){this.state._active||this.start(n),this.wheelChange(n),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(n){const t=this.state;t._delta=VM(n),Ut.addTo(t._movement,t._delta),ZM(t),this.compute(n),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(n){n("wheel","",this.wheel.bind(this))}}const X7=Bu;ut(ut({},Bu),{},{mouseOnly:(e=!0)=>e});const Nw=new Map,yv=new Map;function q7(e){Nw.set(e.key,e.engine),yv.set(e.key,e.resolver)}const Z7={key:"pinch",engine:G7,resolver:V7},Q7={key:"wheel",engine:Y7,resolver:X7};function J7(e,n){if(e==null)return{};var t={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(n.indexOf(o)>=0)&&(t[o]=e[o]);return t}function eK(e,n){if(e==null)return{};var t=J7(e,n),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r])}return t}const tK={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=vr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},nK=["target","eventOptions","window","enabled","transform"];function jh(e={},n){const t={};for(const[r,o]of Object.entries(n))switch(typeof o){case"function":t[r]=o.call(t,e[r],r,e);break;case"object":t[r]=jh(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function rK(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=eK(r,nK);if(t.shared=jh({target:o,eventOptions:s,window:i,enabled:a,transform:l},tK),n){const d=yv.get(n);t[n]=jh(ut({shared:t.shared},c),d)}else for(const d in c){const h=yv.get(d);h&&(t[d]=jh(ut({shared:t.shared},c[d]),h))}return t}class QM{constructor(n,t){tn(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,s){const i=this._listeners,a=b7(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ut(ut({},l),s);n.addEventListener(a,o,c);const d=()=>{n.removeEventListener(a,o,c),i.delete(d)};return i.add(d),d}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class oK{constructor(){tn(this,"_timeouts",new Map)}add(n,t,r=140,...o){this.remove(n),this._timeouts.set(n,window.setTimeout(t,r,...o))}remove(n){const t=this._timeouts.get(n);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(n=>void window.clearTimeout(n)),this._timeouts.clear()}}class sK{constructor(n){tn(this,"gestures",new Set),tn(this,"_targetEventStore",new QM(this)),tn(this,"gestureEventStores",{}),tn(this,"gestureTimeoutStores",{}),tn(this,"handlers",{}),tn(this,"config",{}),tn(this,"pointerIds",new Set),tn(this,"touchIds",new Set),tn(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),iK(this,n)}setEventIds(n){if(GM(n))return this.touchIds=new Set(I7(n)),this.touchIds;if("pointerId"in n)return n.type==="pointerup"||n.type==="pointercancel"?this.pointerIds.delete(n.pointerId):n.type==="pointerdown"&&this.pointerIds.add(n.pointerId),this.pointerIds}applyHandlers(n,t){this.handlers=n,this.nativeHandlers=t}applyConfig(n,t){this.config=rK(n,t,this.config)}clean(){this._targetEventStore.clean();for(const n of this.gestures)this.gestureEventStores[n].clean(),this.gestureTimeoutStores[n].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...n){const t=this.config.shared,r={};let o;if(!(t.target&&(o=t.target(),!o))){if(t.enabled){for(const i of this.gestures){const a=this.config[i],l=xC(r,a.eventOptions,!!o);if(a.enabled){const c=Nw.get(i);new c(this,n,i).bind(l)}}const s=xC(r,t.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](ut(ut({},this.state.shared),{},{event:a,args:n})),void 0,!0)}for(const s in r)r[s]=_7(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=w7(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function ga(e,n){e.gestures.add(n),e.gestureEventStores[n]=new QM(e,n),e.gestureTimeoutStores[n]=new oK}function iK(e,n){n.drag&&ga(e,"drag"),n.wheel&&ga(e,"wheel"),n.scroll&&ga(e,"scroll"),n.move&&ga(e,"move"),n.pinch&&ga(e,"pinch"),n.hover&&ga(e,"hover")}const xC=(e,n,t)=>(r,o,s,i={},a=!1)=>{var l,c;const d=(l=i.capture)!==null&&l!==void 0?l:n.capture,h=(c=i.passive)!==null&&c!==void 0?c:n.passive;let p=a?r:v7(r,o,d);t&&h&&(p+="Passive"),e[p]=e[p]||[],e[p].push(s)},aK=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function lK(e){const n={},t={},r=new Set;for(let o in e)aK.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function ma(e,n,t,r,o,s){if(!e.has(t)||!Nw.has(r))return;const i=t+"Start",a=t+"End",l=c=>{let d;return c.first&&i in n&&n[i](c),t in n&&(d=n[t](c)),c.last&&a in n&&n[a](c),d};o[r]=l,s[r]=s[r]||{}}function cK(e,n){const[t,r,o]=lK(e),s={};return ma(o,t,"onDrag","drag",s,n),ma(o,t,"onWheel","wheel",s,n),ma(o,t,"onScroll","scroll",s,n),ma(o,t,"onPinch","pinch",s,n),ma(o,t,"onMove","move",s,n),ma(o,t,"onHover","hover",s,n),{handlers:s,config:n,nativeHandlers:r}}function uK(e,n={},t,r){const o=xe.useMemo(()=>new sK(e),[]);if(o.applyHandlers(e,r),o.applyConfig(n,t),xe.useEffect(o.effect.bind(o)),xe.useEffect(()=>o.clean.bind(o),[]),n.target===void 0)return o.bind.bind(o)}function dK(e){return e.forEach(q7),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=cK(t,r||{});return uK(o,i,void 0,s)}}const wC=10,hK=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function JM(e){let{deltaY:n,deltaX:t}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(n)>wC?wC*Math.sign(n):n)/100:e.shiftKey&&!hK&&(t=n,n=0),{x:-t,y:-n,z:-r}}const pK=dK([Q7,Z7]);let ya;const fK=e=>ya===void 0?(ya=e,!1):e-ya>120&&e-ya<160?(ya=e,!0):(ya=e,!1);function gK(e){const n=B(),t=P.useMemo(()=>{let r="not sure";const o=({event:g})=>{if(!n.getInstanceState().isFocused||(r="not sure",fK(Date.now())))return;const x=n.getEditingShapeId();if(x){const b=n.getShape(x);if(b&&n.getShapeUtil(b).canScroll(b)){const I=n.getShapePageBounds(x);if(I!=null&&I.containsPoint(n.inputs.currentPagePoint))return}}Ee(g),Kt(g);const y=JM(g);if(y.x===0&&y.y===0)return;const v={type:"wheel",name:"wheel",delta:y,point:new w(g.clientX,g.clientY),shiftKey:g.shiftKey,altKey:g.altKey,ctrlKey:g.metaKey||g.ctrlKey};n.dispatch(v)};let s=1,i=1,a=1,l=0;const c=new w,d=new w,h=g=>{const x=e.current;r="not sure";const{event:y,origin:v,da:b}=g;y instanceof WheelEvent||(y.target===x||x!=null&&x.contains(y.target))&&(d.x=v[0],d.y=v[1],c.x=v[0],c.y=v[1],s=b[0],i=n.getZoomLevel(),n.dispatch({type:"pinch",name:"pinch_start",point:{x:v[0],y:v[1],z:n.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey}))},p=g=>{if(g&&(r="zooming"),r==="zooming")return;const x=Math.abs(l-s),y=w.Dist(c,d);switch(r){case"not sure":{x>24?r="zooming":y>16&&(r="panning");break}case"panning":{x>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:h,onPinchEnd:g=>{const x=e.current,{event:y,origin:v,offset:b}=g;if(y instanceof WheelEvent||!(y.target===x||x!=null&&x.contains(y.target)))return;const E=b[0];r="not sure",n.timers.requestAnimationFrame(()=>{n.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:E},delta:{x:v[0],y:v[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey})})},onPinch:g=>{const x=e.current,{event:y,origin:v,offset:b,da:E}=g;if(y instanceof WheelEvent||!(y.target===x||x!=null&&x.contains(y.target)))return;const I=g.type==="gesturechange"||g.type==="gestureend";l=E[0];const C=v[0]-d.x,k=v[1]-d.y;switch(d.x=v[0],d.y=v[1],p(I),r){case"zooming":{a=b[0],n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:C,y:k},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:C,y:k},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}}}}},[n,e]);pK(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function Xm(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function mK(e,n){const t=B();return P.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=uf(l.currentTarget);Nu(c,l);const{shape:d,handle:h}=Xm(t,e,n);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:d,name:"pointer_down",...On(l)})};let o,s;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===o&&l.clientY===s)return;o=l.clientX,s=l.clientY;const{shape:c,handle:d}=Xm(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:c,name:"pointer_move",...On(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=uf(l.currentTarget);zu(c,l);const{shape:d,handle:h}=Xm(t,e,n);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:d,name:"pointer_up",...On(l)})}}},[t,e,n])}const Qe=class Qe{constructor(n=0,t=0,r=0,o=0){m(this,"x",0);m(this,"y",0);m(this,"w",0);m(this,"h",0);this.x=n,this.y=t,this.w=r,this.h=o}get point(){return new w(this.x,this.y)}set point(n){this.x=n.x,this.y=n.y}get minX(){return this.x}set minX(n){this.x=n}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(n){this.y=n}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get width(){return this.w}set width(n){this.w=n}get height(){return this.h}set height(n){this.h=n}get aspectRatio(){return this.width/this.height}get center(){return new w(this.midX,this.midY)}set center(n){this.minX=n.x-this.width/2,this.minY=n.y-this.height/2}get corners(){return[new w(this.minX,this.minY),new w(this.maxX,this.minY),new w(this.maxX,this.maxY),new w(this.minX,this.maxY)]}get cornersAndCenter(){return[new w(this.minX,this.minY),new w(this.maxX,this.minY),new w(this.maxX,this.maxY),new w(this.minX,this.maxY),this.center]}get sides(){const{corners:n}=this;return[[n[0],n[1]],[n[1],n[2]],[n[2],n[3]],[n[3],n[0]]]}get size(){return new w(this.w,this.h)}toFixed(){return this.x=Fd(this.x),this.y=Fd(this.y),this.w=Fd(this.w),this.h=Fd(this.h),this}setTo(n){return this.x=n.x,this.y=n.y,this.w=n.w,this.h=n.h,this}set(n=0,t=0,r=0,o=0){return this.x=n,this.y=t,this.w=r,this.h=o,this}expand(n){const t=Math.min(this.minX,n.minX),r=Math.min(this.minY,n.minY),o=Math.max(this.maxX,n.maxX),s=Math.max(this.maxY,n.maxY);return this.x=t,this.y=r,this.w=o-t,this.h=s-r,this}expandBy(n){return this.x-=n,this.y-=n,this.w+=n*2,this.h+=n*2,this}scale(n){return this.x/=n,this.y/=n,this.w/=n,this.h/=n,this}clone(){const{x:n,y:t,w:r,h:o}=this;return new Qe(n,t,r,o)}translate(n){return this.x+=n.x,this.y+=n.y,this}snapToGrid(n){const t=Math.round(this.minX/n)*n,r=Math.round(this.minY/n)*n,o=Math.round(this.maxX/n)*n,s=Math.round(this.maxY/n)*n;this.minX=t,this.minY=r,this.width=Math.max(1,o-t),this.height=Math.max(1,s-r)}collides(n){return Qe.Collides(this,n)}contains(n){return Qe.Contains(this,n)}includes(n){return Qe.Includes(this,n)}containsPoint(n,t=0){return Qe.ContainsPoint(this,n,t)}getHandlePoint(n){switch(n){case"top_left":return new w(this.minX,this.minY);case"top_right":return new w(this.maxX,this.minY);case"bottom_left":return new w(this.minX,this.maxY);case"bottom_right":return new w(this.maxX,this.maxY);case"top":return new w(this.midX,this.minY);case"right":return new w(this.maxX,this.midY);case"bottom":return new w(this.midX,this.maxY);case"left":return new w(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(n,t,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:d,maxY:h}=this;switch(n){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{d+=t;break}}switch(n){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const p=(d-l)/(i-o),f=(h-c)/(a-s),S=p<0,g=f<0;if(S){const x=d;d=l,l=x}if(g){const x=h;h=c,c=x}this.minX=l,this.minY=c,this.width=Math.abs(d-l),this.height=Math.abs(h-c)}union(n){const t=Math.min(this.minX,n.x),r=Math.min(this.minY,n.y),o=Math.max(this.maxX,n.w+n.x),s=Math.max(this.maxY,n.h+n.y);return this.x=t,this.y=r,this.width=o-t,this.height=s-r,this}static From(n){return new Qe(n.x,n.y,n.w,n.h)}static FromCenter(n,t){return new Qe(n.x-t.x/2,n.y-t.y/2,t.x,t.y)}static FromPoints(n){if(n.length===0)return new Qe;let t=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,l=n.length;a<l;a++)i=n[a],t=Math.min(i.x,t),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new Qe(t,r,o-t,s-r)}static Expand(n,t){const r=Math.min(t.minX,n.minX),o=Math.min(t.minY,n.minY),s=Math.max(t.maxX,n.maxX),i=Math.max(t.maxY,n.maxY);return new Qe(r,o,s-r,i-o)}static ExpandBy(n,t){return new Qe(n.minX-t,n.minY-t,n.width+t*2,n.height+t*2)}static Resize(n,t,r,o,s=!1){const{minX:i,minY:a,maxX:l,maxY:c}=n;let{minX:d,minY:h,maxX:p,maxY:f}=n;switch(t){case"left":case"top_left":case"bottom_left":{d+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(t){case"top":case"top_left":case"top_right":{h+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const S=(p-d)/(l-i),g=(f-h)/(c-a),x=S<0,y=g<0;if(s){const b=(l-i)/(c-a),E=Math.abs(p-d),I=Math.abs(f-h),C=E*(g<0?1:-1)*(1/b),k=I*(S<0?1:-1)*b,T=b<E/I;switch(t){case"top_left":{T?h=f+C:d=p+k;break}case"top_right":{T?h=f+C:p=d-k;break}case"bottom_right":{T?f=h-C:p=d-k;break}case"bottom_left":{T?f=h-C:d=p+k;break}case"bottom":case"top":{const O=(d+p)/2,_=I*b;d=O-_/2,p=O+_/2;break}case"left":case"right":{const O=(h+f)/2,_=E/b;h=O-_/2,f=O+_/2;break}}}if(x){const b=p;p=d,d=b}if(y){const b=f;f=h,h=b}const v=new Qe(d,h,Math.abs(p-d),Math.abs(f-h));return{box:v,scaleX:+(v.width/n.width*(S>0?1:-1)).toFixed(5),scaleY:+(v.height/n.height*(g>0?1:-1)).toFixed(5)}}equals(n){return Qe.Equals(this,n)}static Equals(n,t){return t.x===n.x&&t.y===n.y&&t.w===n.w&&t.h===n.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(n){return new Qe(n.x,n.y,Math.max(1,n.w),Math.max(1,n.h))}};m(Qe,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),m(Qe,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),m(Qe,"Includes",(n,t)=>Qe.Collides(n,t)||Qe.Contains(n,t)),m(Qe,"ContainsPoint",(n,t,r=0)=>!(t.x<n.minX-r||t.y<n.minY-r||t.x>n.maxX+r||t.y>n.maxY+r)),m(Qe,"Common",n=>{let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<n.length;i++){const a=n[i];t=Math.min(t,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new Qe(t,r,o-t,s-r)}),m(Qe,"Sides",(n,t=0)=>{const{corners:r}=n;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let Z=Qe;function yK(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 SK(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 vK(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function xK(e){const n=B();P.useLayoutEffect(()=>{let t=new Z;function r(){const c=e.current;if(!c)return null;const d=c.getBoundingClientRect(),h=new Z(d.left||d.x,d.top||d.y,Math.max(d.width,1),Math.max(d.height,1));t.equals(h)||(n.updateViewportScreenBounds(h),t=h)}r();const o=fw(r,200,{trailing:!0}),s=n.timers.setInterval(o,1e3);window.addEventListener("resize",o);const i=new ResizeObserver(c=>{c[0].contentRect&&o()}),a=e.current;let l=null;return a&&(i.observe(a),l=wK(a),l.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),l==null||l.removeEventListener("scroll",o),o.cancel()}},[n,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 wK=e=>{let n=e.parentElement;for(;n;){if(n===document.body)return document;const{overflowY:t}=window.getComputedStyle(n);if(n.scrollHeight>n.clientHeight&&(t==="auto"||t==="scroll"||t==="overlay"))return n;n=n.parentElement}return document},De=class De{constructor(n,t,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=n,this.b=t,this.c=r,this.d=o,this.e=s,this.f=i}equals(n){return this===n||this.a===n.a&&this.b===n.b&&this.c===n.c&&this.d===n.d&&this.e===n.e&&this.f===n.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(n){const t=n,{a:r,b:o,c:s,d:i,e:a,f:l}=this;return this.a=r*t.a+s*t.b,this.c=r*t.c+s*t.d,this.e=r*t.e+s*t.f+a,this.b=o*t.a+i*t.b,this.d=o*t.c+i*t.d,this.f=o*t.e+i*t.f+l,this}rotate(n,t,r){return n===0?this:t===void 0?this.multiply(De.Rotate(n)):this.translate(t,r).multiply(De.Rotate(n)).translate(-t,-r)}translate(n,t){return this.multiply(De.Translate(n,t))}scale(n,t){return this.multiply(De.Scale(n,t))}invert(){const{a:n,b:t,c:r,d:o,e:s,f:i}=this,a=n*o-t*r;return this.a=o/a,this.b=t/-a,this.c=r/-a,this.d=n/a,this.e=(o*s-r*i)/-a,this.f=(t*s-n*i)/a,this}applyToPoint(n){return De.applyToPoint(this,n)}applyToPoints(n){return De.applyToPoints(this,n)}rotation(){return De.Rotation(this)}point(){return De.Point(this)}decomposed(){return De.Decompose(this)}toCssString(){return De.toCssString(this)}setTo(n){return Object.assign(this,n),this}decompose(){return De.Decompose(this)}clone(){return new De(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new De(1,0,0,1,0,0)}static Translate(n,t){return new De(1,0,0,1,n,t)}static Rotate(n,t,r){if(n===0)return De.Identity();const o=Math.cos(n),s=Math.sin(n),i=new De(o,s,-s,o,0,0);return t===void 0?i:De.Compose(De.Translate(t,r),i,De.Translate(-t,-r))}static Multiply(n,t){return{a:n.a*t.a+n.c*t.b,c:n.a*t.c+n.c*t.d,e:n.a*t.e+n.c*t.f+n.e,b:n.b*t.a+n.d*t.b,d:n.b*t.c+n.d*t.d,f:n.b*t.e+n.d*t.f+n.f}}static Inverse(n){const t=n.a*n.d-n.b*n.c;return{a:n.d/t,b:n.b/-t,c:n.c/-t,d:n.a/t,e:(n.d*n.e-n.c*n.f)/-t,f:(n.b*n.e-n.a*n.f)/t}}static Absolute(n){const t=n.a*n.d-n.b*n.c;return{a:n.d/t,b:n.b/-t,c:n.c/-t,d:n.a/t,e:(n.d*n.e-n.c*n.f)/t,f:(n.b*n.e-n.a*n.f)/-t}}static Compose(...n){const t=De.Identity();for(let r=0,o=n.length;r<o;r++)t.multiply(n[r]);return t}static Point(n){return new w(n.e,n.f)}static Rotation(n){let t;if(n.a!==0||n.c!==0){const r=(n.a*n.a+n.c*n.c)**.5;t=Math.acos(n.a/r)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const r=(n.b*n.b+n.d*n.d)**.5;t=Ve+Math.acos(n.b/r)*(n.d>0?-1:1)}else t=0;return fv(t)}static Decompose(n){let t,r,o;if(n.a!==0||n.c!==0){const s=(n.a*n.a+n.c*n.c)**.5;t=s,r=(n.a*n.d-n.b*n.c)/s,o=Math.acos(n.a/s)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const s=(n.b*n.b+n.d*n.d)**.5;t=(n.a*n.d-n.b*n.c)/s,r=s,o=Ve+Math.acos(n.b/s)*(n.d>0?-1:1)}else t=0,r=0,o=0;return{x:n.e,y:n.f,scaleX:t,scaleY:r,rotation:fv(o)}}static Smooth(n,t=1e10){return n.a=Math.round(n.a*t)/t,n.b=Math.round(n.b*t)/t,n.c=Math.round(n.c*t)/t,n.d=Math.round(n.d*t)/t,n.e=Math.round(n.e*t)/t,n.f=Math.round(n.f*t)/t,n}static toCssString(n){return`matrix(${N(n.a)}, ${N(n.b)}, ${N(n.c)}, ${N(n.d)}, ${N(n.e)}, ${N(n.f)})`}static applyToPoint(n,t){return new w(n.a*t.x+n.c*t.y+n.e,n.b*t.x+n.d*t.y+n.f,t.z)}static applyToXY(n,t,r){return[n.a*t+n.c*r+n.e,n.b*t+n.d*r+n.f]}static applyToPoints(n,t){return t.map(r=>new w(n.a*r.x+n.c*r.y+n.e,n.b*r.x+n.d*r.y+n.f,r.z))}static applyToBounds(n,t){return new Z(n.e+t.minX,n.f+t.minY,t.width,t.height)}static From(n){return new De(n.a,n.b,n.c,n.d,n.e,n.f)}static Cast(n){return n instanceof De?n:De.From(n)}};m(De,"Scale",(n,t,r,o)=>{const s=new De(n,0,0,t,0,0);return r===void 0?s:De.Compose(De.Translate(r,o),s,De.Translate(-r,-o))});let oe=De;function e2(e,n){return n===0?e:e2(n,e%n)}function t2(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/e2(r,t)}class ai{constructor(n){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");m(this,"_length");this.isFilled=n.isFilled,this.isClosed=n.isClosed,this.isLabel=n.isLabel??!1,this.debugColor=n.debugColor,this.ignore=n.ignore}hitTestPoint(n,t=0,r=!1){return this.isClosed&&(this.isFilled||r)&&tr(n,this.vertices)?!0:w.Dist2(n,this.nearestPoint(n))<=t*t}distanceToPoint(n,t=!1){return n.dist(this.nearestPoint(n))*(this.isClosed&&(this.isFilled||t)&&tr(n,this.vertices)?-1:1)}distanceToLineSegment(n,t){if(n.equals(t))return this.distanceToPoint(n);const{vertices:r}=this;let o,s=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=w.NearestPointOnLineSegment(n,t,a,!0),i=w.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&tr(o,this.vertices)?-s:s}hitTestLineSegment(n,t,r=0){return this.distanceToLineSegment(n,t)<=r}nearestPointOnLineSegment(n,t){const{vertices:r}=this;let o,s=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=w.NearestPointOnLineSegment(n,t,a,!0),i=w.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return o}isPointInBounds(n,t=0){const{bounds:r}=this;return!(n.x<r.minX-t||n.y<r.minY-t||n.x>r.maxX+t||n.y>r.maxY+t)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return Z.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:n}=this;let t=0;for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];t+=s.x*i.y-i.x*s.y}return t/2}toSimpleSvgPath(){let n="";const{vertices:t}=this,r=t.length;if(r===0)return n;n+=`M${t[0].x},${t[0].y}`;for(let o=1;o<r;o++)n+=`L${t[o].x},${t[o].y}`;return this.isClosed&&(n+="Z"),n}get length(){return this._length?this._length:(this._length=this.getLength(),this._length)}getLength(){const{vertices:n}=this;let t,r=n[0],o=0;for(let s=1;s<n.length;s++)t=n[s],o+=w.Dist2(r,t),r=t;return Math.sqrt(o)}}class Hr extends ai{constructor(t){super({...t,isClosed:!0,isFilled:!1});m(this,"children",[]);m(this,"ignoredChildren",[]);for(const r of t.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(t=>!t.isLabel).flatMap(t=>t.vertices)}nearestPoint(t){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");let i,a;for(const l of s)i=l.nearestPoint(t),a=w.Dist2(i,t),a<r&&(r=a,o=i);if(!o)throw Error("nearest point not found");return o}distanceToPoint(t,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(t,r||s>0)))}hitTestPoint(t,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(t,r,o))}hitTestLineSegment(t,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(t,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let t="";for(const o of this.children)t+=o.toSimpleSvgPath();const r=Z.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],l=i.dist(a),c=r[(o+1)%s],d=i.dist(c),h=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/d);t+=`M${h.x},${h.y} L${p.x},${p.y} L${f.x},${f.y} `}return t}getLength(){return this.children.reduce((t,r)=>r.isLabel?t:t+r.length,0)}getSvgPathData(){return this.children.map((t,r)=>t.isLabel?"":t.getSvgPathData(r===0)).join(" ")}}function bK(e=!0){const[n,t]=P.useState(0),r=B();P.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const PK=lr(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=B();bK(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return u.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=o.getShape(l.id);if(c.type==="group")return null;const d=o.getShapeGeometry(c),h=o.getShapePageTransform(c),p=o.getPointInShapeSpace(c,a),f=d.nearestPoint(p),S=d.distanceToPoint(p,!0),g=Math.abs(S)*s,x=S<0,{vertices:y}=d;return u.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&u.jsx("g",{stroke:d.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:u.jsx(n2,{geometry:d})}),t&&y.map((v,b)=>u.jsx("circle",{cx:v.x,cy:v.y,r:2/s,fill:`hsl(${fl(b,[0,y.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${b}`)),r&&g<150&&u.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-g/150,stroke:x?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function n2({geometry:e}){return e instanceof Hr?u.jsx(u.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>u.jsx(n2,{geometry:n},t))}):u.jsx("path",{d:e.toSimpleSvgPath()})}function r2(e){return _6(e)}function CK(){const e=B(),n=xH("userIds",()=>r2(e.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>{var o;return t.join(",")===((o=r.join)==null?void 0:o.call(r,","))}},[e]);return G(n)}function o2(e){const n=B();return G(`latestPresence:${e}`,()=>n.getCollaborators().find(r=>r.userId===e),[n,e])??null}const IK=lr(function(){const n=CK();return u.jsx(u.Fragment,{children:n.map(t=>u.jsx(EK,{collaboratorId:t},t))})}),EK=lr(function({collaboratorId:n}){const t=B(),r=o2(n),o=_K(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:s,highlightedUserIds:i}=t.getInstanceState();if(!(s===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return u.jsx(kK,{latestPresence:r})}),kK=lr(function({latestPresence:n}){const t=B(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=it(),l=t.getZoomLevel(),c=t.getViewportPageBounds(),{userId:d,chatMessage:h,brush:p,scribbles:f,selectedShapeIds:S,userName:g,cursor:x,color:y}=n,v=!(x.x<c.minX-12/l||x.y<c.minY-16/l||x.x>c.maxX-12/l||x.y>c.maxY-16/l);return u.jsxs(u.Fragment,{children:[p&&r?u.jsx(r,{className:"tl-collaborator__brush",brush:p,color:y,opacity:.1},d+"_brush"):null,v&&s?u.jsx(s,{className:"tl-collaborator__cursor",point:x,color:y,zoom:l,name:g!=="New User"?g:null,chatMessage:h},d+"_cursor"):i?u.jsx(i,{className:"tl-collaborator__cursor-hint",point:x,color:y,zoom:l,viewport:c},d+"_cursor_hint"):null,o&&f.length?u.jsx(u.Fragment,{children:f.map(b=>u.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:y,zoom:l,opacity:b.color==="laser"?.5:.1},d+"_scribble_"+b.id))}):null,a&&S.map(b=>u.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:y,opacity:.5},d+"_"+b))]})});function bC(e,n){return n>e.options.collaboratorInactiveTimeoutMs?"inactive":n>e.options.collaboratorIdleTimeoutMs?"idle":"active"}function _K(e,n){const t=P.useRef((n==null?void 0:n.lastActivityTimestamp)??-1),[r,o]=P.useState(()=>bC(e,Date.now()-t.current));return P.useEffect(()=>{const s=e.timers.setInterval(()=>{o(bC(e,Date.now()-t.current))},e.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[e]),n&&(t.current=n.lastActivityTimestamp),r}const s2=P.memo(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const l=B(),{ShapeErrorFallback:c}=it(),d=P.useRef(null),h=P.useRef(null),p=P.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Bs("set shape stuff",()=>{const g=l.getShape(n);if(!g)return;const x=p.current,y=l.getShapeClipPath(n)??"none";y!==x.clipPath&&(Jt(d.current,"clip-path",y),Jt(h.current,"clip-path",y),x.clipPath=y);const v=l.getShapePageTransform(n),b=oe.toCssString(v),E=l.getShapeGeometry(g).bounds;b!==x.transform&&(Jt(d.current,"transform",b),Jt(h.current,"transform",b),x.transform=b);const I=E.w%a,C=E.h%a,k=I===0?E.w:E.w+(a-I),T=C===0?E.h:E.h+(a-C);(k!==x.width||T!==x.height)&&(Jt(d.current,"width",Math.max(k,a)+"px"),Jt(d.current,"height",Math.max(T,a)+"px"),Jt(h.current,"width",Math.max(k,a)+"px"),Jt(h.current,"height",Math.max(T,a)+"px"),x.width=k,x.height=T)},[l]),Bs("set opacity and z-index",()=>{const g=d.current,x=h.current;Jt(g,"opacity",i),Jt(x,"opacity",i),Jt(g,"z-index",o),Jt(x,"z-index",s)},[i,o,s]),Bs("set display",()=>{if(!l.getShape(n))return;const y=l.getCulledShapes().has(n);y!==p.current.isCulled&&(Jt(d.current,"display",y?"none":"block"),Jt(h.current,"display",y?"none":"block"),p.current.isCulled=y)},[l]);const f=P.useCallback(g=>l.annotateError(g,{origin:"shape",willCrashApp:!1}),[l]);if(!t)return null;const S="fill"in t.props&&t.props.fill!=="none";return u.jsxs(u.Fragment,{children:[r.backgroundComponent&&u.jsx("div",{ref:h,className:"tl-shape tl-shape-background","data-shape-type":t.type,draggable:!1,children:u.jsx(fu,{fallback:c,onError:f,children:u.jsx(MK,{shape:t,util:r})})}),u.jsx("div",{ref:d,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":S,draggable:!1,children:u.jsx(fu,{fallback:c,onError:f,children:u.jsx(TK,{shape:t,util:r})})})]})}),TK=P.memo(function({shape:n,util:t}){return Jf("InnerShape:"+n.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(n.id)))},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta),MK=P.memo(function({shape:n,util:t}){return Jf("InnerShape:"+n.type,()=>{var r;return(r=t.backgroundComponent)==null?void 0:r.call(t,t.editor.store.unsafeGetWithoutCapture(n.id))})},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta);function jK({className:e}){const n=B(),{Background:t,SvgDefs:r}=it(),o=P.useRef(null),s=P.useRef(null),i=P.useRef(null),a=un();xK(o),c7(),a7(),gK(o),h7(o);const l=P.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Bs("position layers",function(){const{x:y,y:v,z:b}=n.getCamera();if(l.current.allowTextOutline&&n.environment.isSafari&&(a.style.setProperty("--tl-text-outline","none"),l.current.allowTextOutline=!1),l.current.allowTextOutline&&b<n.options.textShadowLod!==l.current.lodDisableTextOutline){const C=b<n.options.textShadowLod;a.style.setProperty("--tl-text-outline",C?"none":"var(--tl-text-outline-reference)"),l.current.lodDisableTextOutline=C}const E=b>=1?fl(b,[1,8],[.125,.5],!0):fl(b,[.1,1],[-2,.125],!0),I=`scale(${N(b)}) translate(${N(y+E)}px,${N(v+E)}px)`;Jt(s.current,"transform",I),Jt(i.current,"transform",I)},[n,a]);const c=i7(),d=G("shapeSvgDefs",()=>{const x=new Map;for(const y of gt(n.shapeUtils)){if(!y)return;const v=y.getCanvasSvgDefs();for(const{key:b,component:E}of v)x.has(b)||x.set(b,u.jsx(E,{},b))}return[...x.values()]},[n]),h=G("debug_shapes",()=>wt.hideShapes.get(),[wt]),p=G("debug_svg",()=>wt.debugSvg.get(),[wt]),f=G("debug_geometry",()=>wt.debugGeometry.get(),[wt]),S=G("isEditingAnything",()=>n.getEditingShapeId()!==null,[n]),g=G("isSelectingAnything",()=>!!n.getSelectedShapeIds().length,[n]);return u.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":S,"data-isselectinganything":g,className:ce("tl-canvas",e),"data-testid":"canvas",...c,children:[u.jsx("svg",{className:"tl-svg-context",children:u.jsxs("defs",{children:[d,u.jsx(WK,{}),u.jsx(GK,{}),r&&u.jsx(r,{})]})}),t&&u.jsx("div",{className:"tl-background__wrapper",children:u.jsx(t,{})}),u.jsx(AK,{}),u.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[u.jsx(qK,{}),u.jsx(XK,{}),h?null:p?u.jsx(zK,{}):u.jsx(UK,{})]}),u.jsx("div",{className:"tl-overlays",children:u.jsxs("div",{ref:i,className:"tl-html-layer",children:[f?u.jsx(PK,{}):null,u.jsx($K,{}),u.jsx(DK,{}),u.jsx(OK,{}),u.jsx(RK,{}),u.jsx(HK,{}),u.jsx(KK,{}),u.jsx(LK,{}),u.jsx(YK,{}),u.jsx(IK,{})]})}),u.jsx(ZK,{})]})}function AK(){const e=B(),n=G("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=G("camera",()=>e.getCamera(),[e]),s=G("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=it();return i&&s?u.jsx(i,{x:t,y:r,z:o,size:n}):null}function OK(){const e=B(),n=G("scribbles",()=>e.getInstanceState().scribbles,[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=it();return r&&n.length?u.jsx(u.Fragment,{children:n.map(o=>u.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:t},o.id))}):null}function DK(){const e=B(),n=G("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=it();return t&&n?u.jsx(t,{className:"tl-user-brush",brush:n}):null}function RK(){const e=B(),n=G("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=it();return t&&n?u.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function LK(){const e=B(),n=G("snapLines",()=>e.snaps.getIndicators(),[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=it();return r&&n.length>0?u.jsx(u.Fragment,{children:n.map(o=>u.jsx(r,{className:"tl-user-snapline",line:o,zoom:t},o.id))}):null}function $K(){const e=B(),n=G("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=e.getInstanceState();if(t||r)return!1;const o=e.getOnlySelectedShape();return!o||!e.getShapeHandles(o)?!1:o.id},[e]);return n?u.jsx(FK,{shapeId:n}):null}function FK({shapeId:e}){const n=B(),{Handles:t}=it(),r=G("zoomLevel",()=>n.getZoomLevel(),[n]),o=G("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),s=G("handles transform",()=>n.getShapePageTransform(e),[n,e]),i=G("handles",()=>{const a=n.getShapeHandles(e);if(!a)return null;const l=(o?n.options.coarseHandleRadius:n.options.handleRadius)/r*2;return a.filter(c=>c.type!=="virtual"||!a.some(d=>d!==c&&d.type==="vertex"&&w.Dist(c,d)<l)).sort(c=>c.type==="vertex"?1:-1)},[n,r,o,e]);return!t||!i||!s?null:u.jsx(t,{children:u.jsx("g",{transform:oe.toCssString(s),children:i.map(a=>u.jsx(NK,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function NK({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=mK(e,n.id),{Handle:s}=it();return s?u.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:u.jsx(s,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function zK(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>t2(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return u.jsx(u.Fragment,{children:n.map(r=>u.jsxs(P.Fragment,{children:[u.jsx(s2,{...r,dprMultiple:t}),u.jsx(VK,{id:r.id})]},r.id+"_fragment"))})}function BK(){const e=B(),n=P.useRef(new Set);return Bs("reflow for culled shapes",()=>{const t=e.getCulledShapes();if(n.current.size===t.size&&[...t].every(o=>n.current.has(o)))return;n.current=t;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[e]),null}function UK(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>t2(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return u.jsxs(u.Fragment,{children:[n.map(r=>u.jsx(s2,{...r,dprMultiple:t},r.id+"_shape")),e.environment.isSafari&&u.jsx(BK,{})]})}function HK(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=P.useRef(new Set),r=G("should display selected ids",()=>{const s=t.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 l of a)i.add(l);if(e.isInAny("select.idle","select.editing_shape")){const l=e.getInstanceState();if(l.isHoveringCanvas&&!l.isCoarsePointer){const c=e.getHoveredShapeId();c&&i.add(c)}}}if(s.size!==i.size)return t.current=i,i;for(const a of i)if(!s.has(a))return t.current=i,i;return s},[e]),{ShapeIndicator:o}=it();return o?u.jsx(u.Fragment,{children:n.map(({id:s})=>u.jsx(o,{shapeId:s,hidden:!r.has(s)},s+"_indicator"))}):null}function KK(){const e=B(),{ShapeIndicator:n}=it(),t=G("hinting shape ids",()=>vw(e.getHintingShapeIds()),[e]);return!t.length||!n?null:u.jsx(u.Fragment,{children:t.map(r=>u.jsx(n,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))})}function WK(){return u.jsxs("g",{id:"cursor",children:[u.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[u.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),u.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),u.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[u.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),u.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),u.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[u.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),u.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function GK(){return u.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function VK({id:e}){const n=B(),[t,r]=P.useState(null),o=G("is in root",()=>{const s=n.getShape(e);return(s==null?void 0:s.parentId)===n.getCurrentPageId()},[n,e]);return P.useEffect(()=>{if(!o)return;let s=null;const i=aa("shape to svg",async()=>{const a=Math.random();s=a;const c=n.isShapeOfType(e,"frame")?0:10;let d=n.getShapePageBounds(e);if(!d)return;d=d.clone().expandBy(c);const h=await n.getSvgString([e],{padding:c,background:n.getInstanceState().exportBackground});if(s!==a||!h)return;const p=`data:image/svg+xml;utf8,${encodeURIComponent(h.svg)}`;r({src:p,bounds:d})});return()=>{s=null,i()}},[n,e,o]),!o||!t?null:u.jsx("img",{src:t.src,width:t.bounds.width,height:t.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${t.bounds.x}px, ${t.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function YK(){const e=B(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=it();return!t||!r?null:u.jsx(r,{bounds:t,rotation:n})}function XK(){const e=B(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=it();return!t||!r?null:u.jsx(r,{bounds:t,rotation:n})}function qK(){const{OnTheCanvas:e}=it();return e?u.jsx(e,{}):null}function ZK(){const e=B(),n=G("camera state",()=>e.getCameraState(),[e]);return u.jsx("div",{className:ce("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":n==="idle"})})}function QK({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1}){const i=P.useRef(null);return Rl(i,_t(t.x,o.minX+5/n,o.maxX-5/n),_t(t.y,o.minY+5/n,o.maxY-5/n),1/n,w.Angle(o.center,t)),u.jsxs("svg",{ref:i,className:ce("tl-overlays__item",e),children:[u.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),u.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const PC=P.memo(function({className:n,zoom:t,point:r,color:o,name:s,chatMessage:i}){const a=P.useRef(null);return Rl(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t),r?u.jsxs("div",{ref:a,className:ce("tl-overlays__item",n),children:[u.jsx("svg",{className:"tl-cursor",children:u.jsx("use",{href:"#cursor",color:o})}),i?u.jsxs(u.Fragment,{children:[s&&u.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),u.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&u.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function JK({x:e,y:n,z:t,size:r}){const o=B(),{gridSteps:s}=o.options;return u.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[u.jsx("defs",{children:s.map(({min:i,mid:a,step:l},c)=>{const d=l*r*t,h=.5+e*t,p=.5+n*t,f=h>0?h%d:d+h%d,S=p>0?p%d:d+p%d,g=t<a?fl(t,[i,a],[0,1]):1;return u.jsx("pattern",{id:`grid-${l}`,width:d,height:d,patternUnits:"userSpaceOnUse",children:u.jsx("circle",{className:"tl-grid-dot",cx:f,cy:S,r:1,opacity:g})},`grid-pattern-${c}`)})}),s.map(({step:i},a)=>u.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${i})`},`grid-rect-${a}`))]})}function eW({handle:e,isCoarse:n,className:t,zoom:r}){const o=B(),s=(n?o.options.coarseHandleRadius:o.options.handleRadius)/r;if(e.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,c=e7.indexOf(e.id);return u.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,t),children:[u.jsx("circle",{className:"tl-handle__bg",r:s}),u.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*c})`})]})}const i=(e.type==="create"&&n?3:4)/Math.max(r,.25);return u.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,t),children:[u.jsx("circle",{className:"tl-handle__bg",r:s}),u.jsx("circle",{className:"tl-handle__fg",r:i})]})}const tW=({children:e})=>u.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),nW=()=>{const{Spinner:e}=it();return u.jsx(Jw,{children:e?u.jsx(e,{}):null})};function zw(e,n=!0){const t=e.length;if(t<2)return"";let r=e[0],o=e[1];if(t===2)return`M${Ie(r)}L${Ie(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i],o=e[i+1],s+=Tn(r,o);return n?`M${Tn(e[0],e[1])}Q${Ie(e[1])}${Tn(e[1],e[2])}T${s}${Tn(e[t-1],e[0])}${Tn(e[0],e[1])}Z`:`M${Ie(e[0])}Q${Ie(e[1])}${Tn(e[1],e[2])}${e.length>3?"T":""}${s}L${Ie(e[t-1])}`}function CC({scribble:e,zoom:n,color:t,opacity:r,className:o}){return e.points.length?u.jsx("svg",{className:o&&ce("tl-overlays__item",o),children:u.jsx("path",{className:"tl-scribble",d:zw(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null}function i2({bounds:e,rotation:n}){const t=P.useRef(null);return Rl(t,e.x,e.y,1,n),P.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=N(Math.max(1,e.width))+"px",r.style.height=N(Math.max(1,e.height))+"px")},[e.width,e.height]),u.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function rW({bounds:e,rotation:n}){const t=B(),r=P.useRef(null),o=G("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Rl(r,e==null?void 0:e.x,e==null?void 0:e.y,1,n,{x:-s,y:-s}),e=e.clone().expandBy(s).zeroFix(),u.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:u.jsx("rect",{className:ce("tl-selection__fg__outline"),width:N(e.width),height:N(e.height)})})}const oW=()=>u.jsx("div",{className:"tl-shape-error-boundary"}),sW=({shape:e,util:n})=>Jf("Indicator: "+e.type,()=>n.indicator(n.editor.store.unsafeGetWithoutCapture(e.id))),iW=({editor:e,id:n})=>{const t=G("shape for indicator",()=>e.store.get(n),[e,n]),{ShapeIndicatorErrorFallback:r}=it();return!t||t.isLocked?null:u.jsx(fu,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:u.jsx(sW,{shape:t,util:e.getShapeUtil(t)},t.id)})},IC=P.memo(function({shapeId:n,className:t,color:r,hidden:o,opacity:s}){const i=B(),a=P.useRef(null);return Bs("indicator transform",()=>{const l=a.current;if(!l)return;const c=i.getShapePageTransform(n);c&&l.style.setProperty("transform",c.toCssString())},[i,n]),P.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",o?"none":"block")},[o]),u.jsx("svg",{ref:a,className:ce("tl-overlays__item",t),children:u.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:u.jsx(iW,{editor:i,id:n})})})}),aW=()=>u.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function lW({points:e,zoom:n}){const t=2.5/n,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 l,c,d,h;return a?(l=r,c=s,d=o,h=i):(l=r,c=i,d=o,h=s),u.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[u.jsx("line",{x1:l,y1:c,x2:d,y2:h}),e.map((p,f)=>u.jsx("g",{transform:`translate(${p.x},${p.y})`,children:u.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},f))]})}function cW({gaps:e,direction:n,zoom:t}){const r=3.5/t;let o=[-1/0,1/0],s=null;const i=n==="horizontal";for(const l of e){if(s=Or(o[0],o[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),s)o=s;else continue;if(s=Or(o[0],o[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return u.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:l,endEdge:c},d)=>u.jsx(P.Fragment,{children:i?u.jsxs(u.Fragment,{children:[u.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),u.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),u.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),u.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):u.jsxs(u.Fragment,{children:[u.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),u.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),u.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),u.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},d))})}function uW({className:e,line:n,zoom:t}){return u.jsx("svg",{className:ce("tl-overlays__item",e),children:n.type==="points"?u.jsx(lW,{...n,zoom:t}):n.type==="gaps"?u.jsx(cW,{...n,zoom:t}):null})}function Bw(){return u.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:u.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[u.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),u.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:u.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const dW=()=>null;function a2(e,n){const t=P.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Bc(e){return a2(e,j6)}function Uw(e){return a2(e,MT)}const l2=P.createContext(null);function hW({overrides:e={},children:n}){const t=Uw(e);return u.jsx(l2.Provider,{value:P.useMemo(()=>({Background:V9,SvgDefs:dW,Brush:Wm,ZoomBrush:Wm,CollaboratorBrush:Wm,Cursor:PC,CollaboratorCursor:PC,CollaboratorHint:QK,CollaboratorShapeIndicator:IC,Grid:JK,Scribble:CC,SnapIndicator:uW,Handles:tW,Handle:eW,CollaboratorScribble:CC,ErrorFallback:u2,ShapeErrorFallback:oW,ShapeIndicatorErrorFallback:aW,Spinner:Bw,SelectionBackground:i2,SelectionForeground:rW,ShapeIndicator:IC,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:jK,LoadingScreen:nW,...t}),[t]),children:n})}function it(){const e=P.useContext(l2);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const Hw={openWindow:(e,n)=>window.open(e,n,"noopener noreferrer"),refreshPage:()=>window.location.reload(),hardReset:async()=>{var e;return await((e=window.__tldraw__hardReset)==null?void 0:e.call(window))}};function c2(){Hw.hardReset()}function pW(){Hw.refreshPage()}const fW="https://github.com/tldraw/tldraw/issues/new",u2=({error:e,editor:n})=>{const t=P.useRef(null),[r,o]=P.useState(!1),[s,i]=P.useState(!1),[a,l]=P.useState(!1);let c=null;try{c=it().Canvas??null}catch{}const d=e instanceof Error?e.message:String(e),h=e instanceof Error?e.stack:null,p=G("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[f,S]=P.useState(null);P.useLayoutEffect(()=>{var I;p!==null&&S(p);let b=(I=t.current)==null?void 0:I.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){S(null);return}S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),P.useEffect(()=>{if(s){const b=n==null?void 0:n.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(b)}},[s,n]);const g=()=>{const b=document.createElement("textarea");b.value=h??d,document.body.appendChild(b),b.select(),document.execCommand("copy"),b.remove(),i(!0)},x=()=>{pW()},y=async()=>{c2()},v=new URL(fW);return v.searchParams.set("title",d),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
|
|
\`\`\`js
|
|
${h??d}
|
|
\`\`\`
|
|
|
|
My browser: ${navigator.userAgent}`),u.jsxs("div",{ref:t,className:ce("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[u.jsx("div",{className:"tl-error-boundary__overlay"}),n&&u.jsx(NM,{onError:Wp,fallback:()=>null,children:u.jsx(og.Provider,{value:n,children:u.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?u.jsx(c,{}):null})})}),u.jsx("div",{className:ce("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?u.jsxs(u.Fragment,{children:[u.jsx("h2",{children:"Are you sure?"}),u.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),u.jsxs("div",{className:"tl-error-boundary__content__actions",children:[u.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),u.jsx("button",{className:"tl-error-boundary__reset",onClick:y,children:"Reset data"})]})]}):u.jsxs(u.Fragment,{children:[u.jsx("h2",{children:"Something's gone wrong."}),u.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",u.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",u.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&u.jsxs(u.Fragment,{children:["Message:",u.jsx("h4",{children:u.jsx("code",{children:d})}),"Stack trace:",u.jsxs("div",{className:"tl-error-boundary__content__error",children:[u.jsx("pre",{children:u.jsx("code",{children:h??d})}),u.jsx("button",{onClick:g,children:s?"Copied!":"Copy"})]})]}),u.jsxs("div",{className:"tl-error-boundary__content__actions",children:[u.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),u.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[u.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),u.jsx("button",{className:"tl-error-boundary__refresh",onClick:x,children:"Refresh Page"})]})]})]})})]})};function ot(){return Lu()}const d2="TLDRAW_USER_DATA_v3",h2=Se({id:pe,name:pe.nullable().optional(),locale:pe.nullable().optional(),color:pe.nullable().optional(),colorScheme:ng("light","dark","system").optional(),animationSpeed:de.nullable().optional(),edgeScrollSpeed:de.nullable().optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional(),isDynamicSizeMode:we.nullable().optional()}),vs={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7},Kw=Math.max(...Object.values(vs));function gW(e){e.version<vs.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<vs.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<vs.MakeFieldsNullable,e.version<vs.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<vs.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version<vs.AllowSystemColorScheme&&(e.user.isDarkMode===!0?e.user.colorScheme="dark":e.user.isDarkMode===!1&&(e.user.colorScheme="light"),delete e.user.isDarkMode),e.version<vs.AddDynamicSizeMode&&(e.user.isDynamicSizeMode=!1),e.version=Kw}const EC=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function mW(){return EC[Math.floor(Math.random()*EC.length)]}function yW(){var e,n;return typeof window>"u"?!1:((n=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:n.matches)??!1}const gs=Object.freeze({name:"New User",locale:U9(),color:mW(),edgeScrollSpeed:1,animationSpeed:yW()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1});function qm(){return{id:ot()}}function p2(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return qm();const n=rt(e);gW(n);try{return h2.validate(n.user)}catch{return qm()}}function SW(){const e=JSON.parse(bw(d2)||"null")??null;return p2(e)}const gu=Mt("globalUserData",null);function vW(){Pw(d2,JSON.stringify({version:Kw,user:gu.get()}))}function xW(e){h2.validate(e),gu.set(e),vW(),bW()}const wW=typeof process<"u"&&!1,tl=typeof BroadcastChannel<"u"&&!wW?new BroadcastChannel("tldraw-user-sync"):null;tl==null||tl.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===g2&&(n==null?void 0:n.origin)!==f2()&&gu.set(p2(n.data))});let Zm=null;function f2(){return Zm===null&&(Zm=ot()),Zm}const g2="tldraw-user-preferences-change";function bW(){tl==null||tl.postMessage({type:g2,origin:f2(),data:{user:m2(),version:Kw}})}function m2(){let e=gu.get();return e||(e=SW(),gu.set(e)),e}function y2(e={}){return{derivePresenceState:e.derivePresenceState??(()=>V("presence",()=>null)),userPreferences:e.userPreferences??V("userPreferences",()=>m2()),setUserPreferences:e.setUserPreferences??xW}}var S2={exports:{}};(function(e){var n=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function o(l,c,d){this.fn=l,this.context=c,this.once=d||!1}function s(l,c,d,h,p){if(typeof d!="function")throw new TypeError("The listener must be a function");var f=new o(d,h||l,p),S=t?t+c:c;return l._events[S]?l._events[S].fn?l._events[S]=[l._events[S],f]:l._events[S].push(f):(l._events[S]=f,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],d,h;if(this._eventsCount===0)return c;for(h in d=this._events)n.call(d,h)&&c.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(d)):c},a.prototype.listeners=function(c){var d=t?t+c:c,h=this._events[d];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,f=h.length,S=new Array(f);p<f;p++)S[p]=h[p].fn;return S},a.prototype.listenerCount=function(c){var d=t?t+c:c,h=this._events[d];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,d,h,p,f,S){var g=t?t+c:c;if(!this._events[g])return!1;var x=this._events[g],y=arguments.length,v,b;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),y){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,d),!0;case 3:return x.fn.call(x.context,d,h),!0;case 4:return x.fn.call(x.context,d,h,p),!0;case 5:return x.fn.call(x.context,d,h,p,f),!0;case 6:return x.fn.call(x.context,d,h,p,f,S),!0}for(b=1,v=new Array(y-1);b<y;b++)v[b-1]=arguments[b];x.fn.apply(x.context,v)}else{var E=x.length,I;for(b=0;b<E;b++)switch(x[b].once&&this.removeListener(c,x[b].fn,void 0,!0),y){case 1:x[b].fn.call(x[b].context);break;case 2:x[b].fn.call(x[b].context,d);break;case 3:x[b].fn.call(x[b].context,d,h);break;case 4:x[b].fn.call(x[b].context,d,h,p);break;default:if(!v)for(I=1,v=new Array(y-1);I<y;I++)v[I-1]=arguments[I];x[b].fn.apply(x[b].context,v)}}return!0},a.prototype.on=function(c,d,h){return s(this,c,d,h,!1)},a.prototype.once=function(c,d,h){return s(this,c,d,h,!0)},a.prototype.removeListener=function(c,d,h,p){var f=t?t+c:c;if(!this._events[f])return this;if(!d)return i(this,f),this;var S=this._events[f];if(S.fn)S.fn===d&&(!p||S.once)&&(!h||S.context===h)&&i(this,f);else{for(var g=0,x=[],y=S.length;g<y;g++)(S[g].fn!==d||p&&!S[g].once||h&&S[g].context!==h)&&x.push(S[g]);x.length?this._events[f]=x.length===1?x[0]:x:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var d;return c?(d=t?t+c:c,this._events[d]&&i(this,d)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,e.exports=a})(S2);var PW=S2.exports;const CW=ei(PW),nl="TLDRAW_TAB_ID_v2",go=globalThis.window;function IW(){return go?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(go.navigator.platform)||go.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const hf=go?go[nl]??RT(nl)??"TLDRAW_INSTANCE_STATE_V1_"+ot():"<error>";go&&(go[nl]=hf,IW()?Cw(nl,hf):LT(nl));go==null||go.addEventListener("beforeunload",()=>{Cw(nl,hf)});const v2={Initial:0},sg=Math.max(...Object.values(v2));function EW(e){e.version<v2.Initial,e.version=sg}const x2=Se({version:de,currentPageId:hu,isFocusMode:we,exportBackground:we,isDebugMode:we,isToolLocked:we,isGridMode:we,pageStates:zt(Se({pageId:hu,camera:Se({x:de,y:de,z:de}),selectedShapeIds:zt(gr),focusedGroupId:gr.nullable()}))});function kW(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!==sg&&(e=rt(e),EW(e));try{return x2.validate(e)}catch(n){return console.warn(n),null}}function w2(e){const n=e.query.ids("page");return V("sessionStateSnapshot",()=>{const t=e.get(gn);if(!t)return null;const r=[...n.get()];return{version:sg,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(o=>{const s=e.get($r.createId(o)),i=e.get(lo.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 b2(e,n){const t=kW(n);if(!t)return;const r=e.schema.types.instance.create({id:gn,...hM(e.get(gn)),currentPageId:t.currentPageId,isDebugMode:t.isDebugMode,isFocusMode:t.isFocusMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,exportBackground:t.exportBackground}),o=e.allRecords().filter(s=>s.typeName==="instance_page_state"||s.typeName==="camera");e.atomic(()=>{e.remove(o.map(s=>s.id));for(const s of t.pageStates)e.put([lo.create({id:lo.createId(s.pageId),x:s.camera.x,y:s.camera.y,z:s.camera.z}),$r.create({id:$r.createId(s.pageId),pageId:s.pageId,selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId})]);e.put([r]),e.ensureStoreIsUsable()})}function _W(e){var o;const n=[];for(const s of Object.values(e))(o=s.typeName)!=null&&o.match(/^(instance.*|pointer|camera)$/)&&n.push(s);const t=n.filter(s=>s.typeName==="instance"&&s.id!==gn)[0];if(!t)return null;const r={version:sg,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:n.filter(s=>s.typeName==="instance_page_state"&&s.instanceId===t.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 x2.validate(r),r}catch{return null}}function P2(e,n){let t={};if("store"in n){const o=e.schema.migrateStoreSnapshot(n);if(o.type!=="success")throw new Error("Failed to migrate store snapshot: "+o.reason);t.document={schema:e.schema.serialize(),store:Fc(o.value,(s,{typeName:i})=>e.scopedTypes.document.has(i))}}else t=n;const r=hM(e.get(gn));e.atomic(()=>{t.document&&e.loadStoreSnapshot(t.document),r&&e.update(gn,o=>({...o,...r})),t.session&&b2(e,t.session)})}const TW=new Zo;function MW(e){const t=TW.get(e,w2).get();if(!t)throw new Error("Session state is not ready yet");return{document:e.getStoreSnapshot(),session:t}}function C2(e){const n=[],t=new Set;for(const r of e){if(t.has(r.type))throw new Error(`Binding type "${r.type}" is defined more than once`);n.push(r),t.add(r.type)}return n}function Ys({children:e,className:n="",...t}){return u.jsx("svg",{...t,className:ce("tl-svg-container",n),children:e})}function Ww(e,n,t,r){const o=e.x-t.x,s=e.y-t.y,i=r.x-t.x,a=r.y-t.y,l=n.x-e.x,c=n.y-e.y,d=i*s-a*o,h=l*s-c*o,p=a*l-i*c;if(d===0||h===0||p===0)return null;if(p!==0){const f=d/p,S=h/p;if(0<=f&&f<=1&&0<=S&&S<=1)return w.AddXY(e,f*l,f*c)}return null}function Hu(e,n,t,r){const o=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),s=2*((n.x-e.x)*(e.x-t.x)+(n.y-e.y)*(e.y-t.y)),i=t.x*t.x+t.y*t.y+e.x*e.x+e.y*e.y-2*(t.x*e.x+t.y*e.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-s+l)/(2*o),d=(-s-l)/(2*o);if((c<0||c>1)&&(d<0||d>1))return null;const h=[];return 0<=c&&c<=1&&h.push(w.Lrp(e,n,c)),0<=d&&d<=1&&h.push(w.Lrp(e,n,d)),h.length===0?null:h}function jW(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=Ww(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function Gw(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=Ww(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function AW(e,n,t,r){let o=t.x-e.x,s=t.y-e.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+n*n)/(2*i),l=Math.sqrt(n*n-a*a);return o/=i,s/=i,[new w(e.x+o*a-s*l,e.y+s*a+o*l),new w(e.x+o*a+s*l,e.y+s*a-o*l)]}function Sv(e,n,t){const r=[];let o,s,i;for(let a=0,l=t.length;a<l;a++)o=t[a],s=t[(a+1)%t.length],i=Hu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function kC(e,n,t){const r=[];let o,s,i;for(let a=1,l=t.length;a<l;a++)o=t[a-1],s=t[a],i=Hu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function Bd(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function Vw(e,n,t,r){return Bd(e,t,r)!==Bd(n,t,r)&&Bd(e,n,t)!==Bd(e,n,r)}function _C(e,n){const t=new Map;let r,o,s,i;for(let a=0,l=e.length;a<l;a++)if(r=e[a],tr(r,n)){const c=Qm(r);t.has(c)||t.set(c,r)}for(let a=0,l=n.length;a<l;a++)if(r=n[a],tr(r,e)){const c=Qm(r);t.has(c)||t.set(c,r)}for(let a=0,l=e.length;a<l;a++){r=e[a],o=e[(a+1)%e.length];for(let c=0,d=n.length;c<d;c++){s=n[c],i=n[(c+1)%n.length];const h=Ww(r,o,s,i);if(h!==null){const p=Qm(h);t.has(p)||t.set(p,h)}}}return t.size===0?null:OW([...t.values()])}function Qm(e){return`${e.x},${e.y}`}function OW(e){const n=w.Average(e);return e.sort((t,r)=>w.Angle(n,t)-w.Angle(n,r))}function I2(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let l=0,c=n.length;l<c;l++)if(o=n[l],s=n[(l+1)%c],Vw(t,r,o,s))return!0}return!1}function DW(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let l=1,c=n.length;l<c;l++)if(o=n[l-1],s=n[l],Vw(t,r,o,s))return!0}return!1}class zo extends ai{constructor(t){super({...t,isClosed:!1,isFilled:!1});m(this,"start");m(this,"end");m(this,"d");m(this,"u");m(this,"ul");const{start:r,end:o}=t;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}getLength(){return this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(t){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=w.Sub(t,r).dpr(s)/i,l=r.x+s.x*a;if(l<Math.min(r.x,o.x))return r.x<o.x?r:o;if(l>Math.max(r.x,o.x))return r.x>o.x?r:o;const c=r.y+s.y*a;return c<Math.min(r.y,o.y)?r.y<o.y?r:o:c>Math.max(r.y,o.y)?r.y>o.y?r:o:new w(l,c)}hitTestLineSegment(t,r,o=0){return Vw(t,r,this.start,this.end)||this.distanceToLineSegment(t,r)<=o}getSvgPathData(t=!0){const{start:r,end:o}=this;return`${t?`M${r.toFixed()}`:""} L${o.toFixed()}`}}class Ll extends ai{constructor(t){super({isClosed:!1,isFilled:!1,...t});m(this,"points");m(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:t}=this;for(let r=0,o=t.length-1;r<o;r++){const s=t[r],i=t[r+1];this._segments.push(new zo({start:s,end:i}))}this.isClosed&&this._segments.push(new zo({start:t[t.length-1],end:t[0]}))}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){return this.points}nearestPoint(t){const{segments:r}=this;let o=this.points[0],s=1/0,i,a;for(let l=0;l<r.length;l++)i=r[l].nearestPoint(t),a=w.Dist2(i,t),a<s&&(o=i,s=a);if(!o)throw Error("nearest point not found");return o}hitTestLineSegment(t,r,o=0){const{segments:s}=this;for(let i=0,a=s.length;i<a;i++)if(s[i].hitTestLineSegment(t,r,o))return!0;return!1}getSvgPathData(){const{vertices:t}=this;return t.length<2?"":t.reduce((r,o,s)=>s===0?`M ${o.x} ${o.y}`:`${r} L ${o.x} ${o.y}`,"")}}class vt extends Ll{constructor(n){super({...n}),this.isClosed=!0}}class Jo extends vt{constructor(t){const{x:r=0,y:o=0,width:s,height:i}=t;super({...t,points:[new w(r,o),new w(r+s,o),new w(r+s,o+i),new w(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 Z(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:o,h:s}=this;return`M${t},${r} h${o} v${s} h-${o}z`}}class Br{constructor(n){m(this,"canSnap",()=>!0);m(this,"canScroll",()=>!1);m(this,"canEdit",()=>!1);m(this,"canResize",()=>!0);m(this,"canEditInReadOnly",()=>!1);m(this,"canCrop",()=>!1);m(this,"canBeLaidOut",()=>!0);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=n}canBind(n){return!0}providesBackgroundForChildren(n){return!1}canReceiveNewChildrenOfType(n,t){return!1}canDropShapes(n,t){return!1}expandSelectionOutlinePx(n){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(n){return{}}getHandleSnapGeometry(n){return{}}}m(Br,"props"),m(Br,"migrations"),m(Br,"type");function RW(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=t;let c=0,d=0,h=1,p=0,f=0;switch(l){case"dashed":{h=1,c=Math.min(n*a,e/4);break}case"dotted":{h=100,c=n/h;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=c/2,f+=c/2):s==="skip"&&(e-=c,f-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),d=Math.floor(e/c/(2*h)),d-=d%o,d<3&&l==="dashed"?e/n<5?(c=e,d=1,p=0):(c=e*.333,p=e*.333):(d=Math.max(d,3),c=e/d/(2*h),r?(f=c/2,p=(e-d*c)/d):p=(e-d*c)/Math.max(1,d-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}function TC({bounds:e,className:n}){const t=B(),r=G("zoom level",()=>t.getZoomLevel(),[t]);return u.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=RW(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return u.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class Ah extends Br{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"canBind",()=>!1);m(this,"onChildrenChange",t=>{const r=this.editor.getSortedChildIdsForParent(t.id);if(r.length===0){this.editor.getCurrentPageState().focusedGroupId===t.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([t.id]);return}else if(r.length===1){this.editor.getCurrentPageState().focusedGroupId===t.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(r,t.parentId),this.editor.deleteShapes([t.id]);return}})}getDefaultProps(){return{}}getGeometry(t){const r=this.editor.getSortedChildIdsForParent(t.id);return r.length===0?new Jo({width:1,height:1,isFilled:!1}):new Hr({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 vt({points:a,isFilled:!0}):new Ll({points:a})})})}component(t){const r=this.editor.getErasingShapeIds().includes(t.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(l=>l!==t.id&&this.editor.isShapeOfType(this.editor.getShape(l),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==t.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(t).bounds;return u.jsx(Ys,{id:t.id,children:u.jsx(TC,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return u.jsx(TC,{className:"",bounds:r})}}m(Ah,"type","group"),m(Ah,"props",CM),m(Ah,"migrations",IM);const E2=[Ah],LW=new Set(E2.map(e=>e.type));function k2(e){const n=[...E2],t=new Set;for(const r of e){if(LW.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(t.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);n.push(r),t.add(r.type)}return n}const $W={maxShapesPerPage:4e3,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,maxPointsPerDrawShape:500,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:8,edgeScrollDelay:200,edgeScrollEaseDuration:200,edgeScrollSpeed:25,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10,flattenImageBoundsExpand:64,flattenImageBoundsPadding:16};function MC(e,n){if(!n)return!1;switch(e.type){case"mixed":return n.type==="mixed";case"shared":return n.type==="shared"&&e.value===n.value;default:throw an(e)}}class FW{constructor(n){m(this,"map");this.map=new Map(n)}get(n){return this.map.get(n)}getAsKnownValue(n){const t=this.get(n);if(t&&t.type!=="mixed")return t.value}get size(){return this.map.size}equals(n){if(this.size!==n.size)return!1;const t=new Set;for(const[r,o]of this){if(!MC(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!MC(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 vv extends FW{set(n,t){this.map.set(n,t)}applyValue(n,t){const r=this.get(n);if(!r){this.set(n,{type:"shared",value:t});return}switch(r.type){case"mixed":return;case"shared":r.value!==t&&this.set(n,{type:"mixed"});return;default:an(r,"type")}}}function NW(e,n,t){return yo(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function zW(e,n){var o;let t=e;const r=new Set(n);for(;r.has(t);)t=(o=/^.*(\d+)$/.exec(t))!=null&&o[1]?t.replace(/(\d+)(?=\D?)$/,s=>(+s+1).toString()):`${t} 1`;return t}function Ud(e,n,t){if(t.length===0)return[];const r=new Map;for(const s of me(t.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:me(e.getSortedChildIdsForParent(i).map(a=>e.getShape(a))),moving:new Set}),r.get(i).moving.add(s)}const o=[];switch(n){case"toBack":{r.forEach(({moving:s,children:i})=>BW(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>UW(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>HW(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>KW(s,i,o));break}}return o}function BW(e,n,t){const r=n.length;if(e.size===r)return;let o,s;for(let i=0;i<r;i++){const a=n[i];if(e.has(a))o=a.index,e.delete(a);else{s=a.index;break}}if(e.size!==0){const i=gl(o,s,e.size);t.push(...Array.from(e.values()).sort(on).map((a,l)=>({...a,index:i[l]})))}}function UW(e,n,t){const r=n.length;if(e.size===r)return;let o,s;for(let i=r-1;i>-1;i--){const a=n[i];if(e.has(a))s=a.index,e.delete(a);else{o=a.index;break}}if(e.size!==0){const i=gl(o,s,e.size);t.push(...Array.from(e.values()).sort(on).map((a,l)=>({...a,index:i[l]})))}}function HW(e,n,t){var s;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(n[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=o;gl(n[i].index,(s=n[i+1])==null?void 0:s.index,i-l).forEach((c,d)=>t.push({...n[l+d],index:c})),o={name:"skipping"};break}}}}function KW(e,n,t){var s;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let i=r-1;i>-1;i--){const a=e.has(n[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;gl((s=n[i-1])==null?void 0:s.index,n[i].index,o.selectIndex-i).forEach((l,c)=>{t.push({...n[i+c+1],index:l})}),o={name:"skipping"};break}}}}function _2({editor:e}){const n=e.getSelectedShapes(),t=e.getSelectionRotation(),r=e.getSelectionRotatedPageBounds(),{inputs:{originPagePoint:o}}=e;if(!r)return null;const s=r.center.clone().rotWith(r.point,t);return{selectionPageCenter:s,initialCursorAngle:s.angle(o),initialSelectionRotation:t,shapeSnapshots:n.map(i=>({shape:rt(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function Oh({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:l})=>{const c=kn(a.parentId)?n.getShapePageTransform(a.parentId):oe.Identity(),d=w.RotWith(l,o,e),h=oe.applyToPoint(oe.Inverse(c),d),p=Hs(a.rotation+e);return{id:a.id,type:a.type,x:h.x,y:h.y,rotation:p}}));const i=[];s.forEach(({shape:a})=>{var h,p,f;const l=n.getShape(a.id);if(!l)return;const c=n.getShapeUtil(a);if(r==="start"||r==="one-off"){const S=(h=c.onRotateStart)==null?void 0:h.call(c,a);S&&i.push(S)}const d=(p=c.onRotate)==null?void 0:p.call(c,a,l);if(d&&i.push(d),r==="end"||r==="one-off"){const S=(f=c.onRotateEnd)==null?void 0:f.call(c,a,l);S&&i.push(S)}}),i.length>0&&n.updateShapes(i)}const WW=e=>{const{store:n}=e,t=n.query.filterHistory("binding"),r=n.query.records("binding");function o(){const s=r.get(),i=new Map;for(const a of s){const{fromId:l,toId:c}=a,d=i.get(l);d?d.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return V("arrowBindingsIndex",(s,i)=>{if(Di(s))return o();const a=s,l=t.getDiffSince(i);if(l===Jn)return o();let c;function d(f){c??(c=new Map(a));const S=c.get(f.fromId),g=S==null?void 0:S.filter(v=>v.id!==f.id);g!=null&&g.length?c.set(f.fromId,g):c.delete(f.fromId);const x=c.get(f.toId),y=x==null?void 0:x.filter(v=>v.id!==f.id);y!=null&&y.length?c.set(f.toId,y):c.delete(f.toId)}function h(f){c??(c=new Map(a));let S=c.get(f);return S?S===a.get(f)&&(S=S.slice(0),c.set(f,S)):(S=[],c.set(f,S)),S}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const S of gt(f.added))p(S);for(const[S,g]of gt(f.updated))d(S),p(g);for(const S of gt(f.removed))d(S)}return c??a})};function GW(e,n,t){const r=e.getShapeMaskedPageBounds(n);return r===void 0?!0:!t.includes(r)}const VW=e=>{function n(t){const r=t.getCurrentPageShapeIds(),o=t.getViewportPageBounds(),s=new Set;return r.forEach(i=>{GW(t,i,o)&&s.add(i)}),s}return V("getCulledShapes",t=>{if(Di(t))return n(e);const r=n(e);if(t.size!==r.size)return r;for(const o of t)if(!r.has(o))return r;return t})},YW=e=>{const n=e.query.ids("shape"),t=e.query.filterHistory("shape");function r(){const o={},s=n.get(),i=Array(s.size);return s.forEach(a=>i.push(e.get(a))),i.sort(on),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return V("parentsToChildrenWithIndexes",(o,s)=>{if(Di(o))return r();const i=t.getDiffSince(s);if(i===Jn)return r();if(i.length===0)return o;let a=null;const l=h=>{a||(a={...o}),a[h]?a[h]===o[h]&&(a[h]=[...a[h]]):a[h]=[]},c=new Set;let d;for(let h=0,p=i.length;h<p;h++){d=i[h];for(const f of Object.values(d.added))Ua(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,S]of Object.values(d.updated))if(Ua(S)&&Ua(f)){if(f.parentId!==S.parentId)l(f.parentId),l(S.parentId),a[f.parentId].splice(a[f.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),c.add(a[S.parentId]);else if(f.index!==S.index){l(S.parentId);const g=a[S.parentId].indexOf(S.id);a[S.parentId][g]=S.id,c.add(a[S.parentId])}}for(const f of Object.values(d.removed))Ua(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const h of c){const p=me(h.map(f=>e.get(f)));p.sort(on),h.splice(0,h.length,...p.map(f=>f.id))}return a??o})},Jm=(e,n,t)=>{for(;!In(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},XW=(e,n)=>{const t=e.query.ids("shape");let r=null;function o(){const s=n();return r=s,new Set([...t.get()].filter(i=>Jm(e,s,e.get(i))))}return V("_shapeIdsInCurrentPage",(s,i)=>{if(Di(s))return o();const a=n();if(a!==r)return o();const l=e.history.getDiffSince(i);if(l===Jn)return o();const c=new kh(s);for(const h of l){for(const p of Object.values(h.added))Ua(p)&&Jm(e,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))Ua(f)&&(Jm(e,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))kn(p)&&c.remove(p)}const d=c.get();return d?Cc(d.value,d.diff):s})},T2=P.createContext(null);function qW({context:e,editor:n,children:t}){return u.jsx(og.Provider,{value:n,children:u.jsx(T2.Provider,{value:e,children:t})})}function M2(){const e=P.useContext(T2);return e?{isDarkMode:e.isDarkMode}:null}async function ZW(e,n,t={}){var I,C;const r=typeof n[0]=="string"?n:n.map(k=>k.id);if(r.length===0)return;if(!window.document)throw Error("No document");const{scale:o=1,background:s=!1,padding:i=e.options.defaultSvgPadding,preserveAspectRatio:a=!1}=t,l=t.darkMode??e.user.getIsDarkMode(),c=ss({isDarkMode:l}),d=e.getShapeAndDescendantIds(r),h=e.getUnorderedRenderingShapes(!1).filter(({id:k})=>d.has(k));let p=null;if(t.bounds)p=t.bounds;else for(const{id:k}of h){const T=e.getShapeMaskedPageBounds(k);T&&(p?p.union(T):p=T.clone())}if(!p)return;const f=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;f||p.expandBy(i);const S=p.width*o,g=p.height*o;try{(C=(I=document.body).focus)==null||C.call(I)}catch{}const x=[],y=new Map,v={isDarkMode:l,addExportDef:k=>{if(y.has(k.key))return;const T=(async()=>{const O=await k.getElement();O&&x.push(u.jsx(P.Fragment,{children:O},x.length))})();y.set(k.key,T)}},b=(await Promise.all(h.map(async({id:k,opacity:T,index:O,backgroundIndex:_})=>{var z,U;if(k===f)return[];const j=e.getShape(k);if(e.isShapeOfType(j,"group"))return[];const L=e.getShapeUtil(j);let A=await((z=L.toSvg)==null?void 0:z.call(L,j,v)),R=await((U=L.toBackgroundSvg)==null?void 0:U.call(L,j,v));if(!A&&!R){const X=e.getShapePageBounds(j);A=u.jsx("rect",{width:X.w,height:X.h,fill:c.solid,stroke:c.grey.pattern,strokeWidth:1})}let F=e.getShapePageTransform(j).toCssString();"scale"in j.props&&j.props.scale!==1&&(F=`${F} scale(${j.props.scale}, ${j.props.scale})`),A&&(A=u.jsx("g",{transform:F,opacity:T,children:A},j.id)),R&&(R=u.jsx("g",{transform:F,opacity:T,children:R},`bg_${j.id}`));const W=e.getShapeMask(j.id);if(W){const X=`mask_${j.id.replace(":","_")}`;x.push(u.jsx("clipPath",{id:X,children:u.jsx("path",{d:`M${W.map(({x:J,y:le})=>`${J},${le}`).join("L")}Z`})},x.length)),A&&(A=u.jsx("g",{clipPath:`url(#${X})`,children:A},j.id)),R&&(R=u.jsx("g",{clipPath:`url(#${X})`,children:R},`bg_${j.id}`))}const K=[];return A&&K.push({zIndex:O,element:A}),R&&K.push({zIndex:_,element:R}),K}))).flat();return await Promise.all(y.values()),{jsx:u.jsx(qW,{editor:e,context:v,children:u.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:S,height:g,viewBox:`${p.minX} ${p.minY} ${p.width} ${p.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?f?c.solid:c.background:"transparent"},children:[u.jsx("defs",{children:x}),b.sort((k,T)=>k.zIndex-T.zIndex).map(({element:k})=>k)]})}),width:S,height:g}}const QW=40;class JW{constructor(n){m(this,"_clickId","");m(this,"_clickTimeout");m(this,"_clickScreenPoint");m(this,"_previousScreenPoint");m(this,"_getClickTimeout",(n,t=ot())=>{this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===n&&this._clickId===t){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},n==="idle"||n==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)});m(this,"_clickState","idle");m(this,"lastPointerInfo",{});m(this,"handlePointerEvent",n=>{switch(n.name){case"pointer_down":{if(!this._clickState)return n;switch(this._clickScreenPoint=w.From(n.point),this._previousScreenPoint&&w.Dist2(this._previousScreenPoint,this._clickScreenPoint)>QW**2&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=n,this._clickState){case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...n,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...n,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...n,type:"click",name:"quadruple_click",phase:"down"};case"idle":{this._clickState="pendingDouble";break}case"pendingOverflow":{this._clickState="overflow";break}}return this._clickTimeout=this._getClickTimeout(this._clickState),n}case"pointer_up":{if(!this._clickState)return n;switch(this._clickScreenPoint=w.From(n.point),this._clickState){case"pendingTriple":return{...this.lastPointerInfo,type:"click",name:"double_click",phase:"up"};case"pendingQuadruple":return{...this.lastPointerInfo,type:"click",name:"triple_click",phase:"up"};case"pendingOverflow":return{...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"up"}}return n}case"pointer_move":return this._clickState!=="idle"&&this._clickScreenPoint&&w.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),n}return n});m(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});this.editor=n}get clickState(){return this._clickState}}class eG{constructor(n){m(this,"_isEdgeScrolling",!1);m(this,"_edgeScrollDuration",-1);this.editor=n}updateEdgeScrolling(n){const{editor:t}=this,r=this.getEdgeScroll();if(r.x===0&&r.y===0)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=n,this._edgeScrollDuration>t.options.edgeScrollDelay){const o=t.options.edgeScrollEaseDuration>0?jt.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*o,y:r.y*o})}}getEdgeProximityFactors(n,t,r,o,s){const{editor:i}=this,a=i.options.edgeScrollDistance,l=r?i.options.coarsePointerWidth:0,c=n-l,d=n+l,h=o?0:a,p=s?t:t-a;return c<h?Math.min(1,(h-c)/a):d>p?-Math.min(1,(d-p)/a):0}getEdgeScroll(){const{editor:n}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=n,o=n.getViewportScreenBounds(),{isCoarsePointer:s,insets:[i,a,l,c]}=n.getInstanceState(),d=this.getEdgeProximityFactors(t,o.w,s,c,a),h=this.getEdgeProximityFactors(r,o.h,s,i,l);return{x:d,y:h}}moveCameraWhenCloseToEdge(n){const{editor:t}=this;if(!t.inputs.isDragging||t.inputs.isPanning||t.getCameraOptions().isLocked||n.x===0&&n.y===0)return;const r=t.getViewportScreenBounds(),o=r.w<1e3?.612:1,s=r.h<1e3?.612:1,i=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,l=a*n.x*o/i,c=a*n.y*s/i,{x:d,y:h,z:p}=t.getCamera();t.setCamera(new w(d+l,h+c,p))}}class tG{constructor(n){m(this,"isSafari");m(this,"isIos");m(this,"isChromeForIos");m(this,"isFirefox");m(this,"isAndroid");this.editor=n,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)}}class nG{constructor(n,t){m(this,"disposeSideEffectListener");this.editor=n,this.disposeSideEffectListener=n.sideEffects.registerAfterChangeHandler("instance",(o,s)=>{o.isFocused!==s.isFocused&&(s.isFocused?this.focus():this.blur(),this.updateContainerClass())});const r=n.getInstanceState().isFocused;t!==r&&n.updateInstanceState({isFocused:!!t}),this.updateContainerClass()}updateContainerClass(){const n=this.editor.getContainer();this.editor.getInstanceState().isFocused?n.classList.add("tl-container__focused"):n.classList.remove("tl-container__focused")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var n;(n=this.disposeSideEffectListener)==null||n.call(this)}}function lc(e){return oG}class rG{constructor(){m(this,"length",0);m(this,"head",null);m(this,"tail",this)}push(n){return new Yw(n,this)}toArray(){return Ho}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const oG=new rG;class Yw{constructor(n,t){m(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Yw(n,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let n=this;return{next(){if(n.length){const t=n.head;return n=n.tail,{value:t,done:!1}}else return{value:void 0,done:!0}}}}}class sG{constructor(n){m(this,"store");m(this,"dispose");m(this,"state","recording");m(this,"pendingDiff",new aG);m(this,"stacks",Mt("HistoryManager.stacks",{undos:lc(),redos:lc()},{isEqual:(n,t)=>n.undos===t.undos&&n.redos===t.redos}));m(this,"annotateError");m(this,"onBatchComplete",()=>{});m(this,"_isInBatch",!1);m(this,"batch",(n,t)=>{const r=this.state;r!=="paused"&&(t!=null&&t.history)&&(this.state=iG[t.history]);try{if(this._isInBatch)return n(),this;this._isInBatch=!0;try{zs(()=>{n(),this.onBatchComplete()})}catch(o){throw this.annotateError(o),o}finally{this._isInBatch=!1}return this}finally{this.state=r}});m(this,"_undo",({pushToRedoStack:n,toMark:t=void 0})=>{var o;const r=this.state;this.state="paused";try{let{undos:s,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),l=zT(a),c=lv(a);n&&!l&&(i=i.push({type:"diff",diff:a}));let d=!1;if(l)for(;((o=s.head)==null?void 0:o.type)==="stop";){const h=s.head;if(s=s.tail,n&&(i=i.push(h)),h.id===t){d=!0;break}}if(!d)e:for(;s.head;){const h=s.head;switch(s=s.tail,n&&(i=i.push(h)),h.type){case"diff":Nc(c,[lv(h.diff)]);break;case"stop":if(!t||h.id===t)break e;break;default:an(h)}}this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:s,redos:i})}finally{this.state=r}return this});m(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));m(this,"redo",()=>{var t;const n=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:o}=this.stacks.get();if(o.length===0)return this;for(;((t=o.head)==null?void 0:t.type)==="stop";)r=r.push(o.head),o=o.tail;const s=Gp();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")Nc(s,[i.diff]);else break}this.store.applyDiff(s,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:o})}finally{this.state=n}return this});m(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));m(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));m(this,"squashToMark",n=>{var s;let t=this.stacks.get().undos;const r=[];for(;t.head&&!(t.head.type==="stop"&&t.head.id===n);)t.head.type==="diff"&&r.push(t.head.diff),t=t.tail;if(!t.head||((s=t.head)==null?void 0:s.id)!==n)return console.error("Could not find mark to squash to: ",n),this;if(r.length===0)return this;const o=Gp();return Nc(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:t.push({type:"diff",diff:o}),redos:i})),this});m(this,"mark",(n=ot())=>(zs(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:n}),redos:r}))}),n));this.store=n.store,this.annotateError=n.annotateError??Wp,this.dispose=this.store.addHistoryInterceptor((t,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(t.changes),this.stacks.update(({undos:o})=>({undos:o,redos:lc()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:an(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;const n=this.pendingDiff.clear();this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"diff",diff:n}),redos:r}))}getNumUndos(){return this.stacks.get().undos.length+(this.pendingDiff.isEmpty()?0:1)}getNumRedos(){return this.stacks.get().redos.length}ignore(n){return this.batch(n,{history:"ignore"})}clear(){this.stacks.set({undos:lc(),redos:lc()}),this.pendingDiff.clear()}debug(){const{undos:n,redos:t}=this.stacks.get();return{undos:n.toArray(),redos:t.toArray(),pendingDiff:this.pendingDiff.debug(),state:this.state}}}const iG={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class aG{constructor(){m(this,"diff",Gp());m(this,"isEmptyAtom",Mt("PendingDiff.isEmpty",!0))}clear(){const n=this.diff;return this.diff=Gp(),this.isEmptyAtom.set(!0),n}isEmpty(){return this.isEmptyAtom.get()}apply(n){Nc(this.diff,[n]),this.isEmptyAtom.set(zT(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class lG{constructor(n){m(this,"scribbleItems",new Map);m(this,"state","paused");m(this,"addScribble",(n,t=ot())=>{const r={id:t,scribble:{id:t,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...n,state:"starting"},timeoutMs:0,delayRemaining:n.delay??0,prev:null,next:null};return this.scribbleItems.set(t,r),r});m(this,"stop",n=>{const t=this.scribbleItems.get(n);if(!t)throw Error(`Scribble with id ${n} not found`);return t.delayRemaining=Math.min(t.delayRemaining,200),t.scribble.state="stopping",t});m(this,"addPoint",(n,t,r)=>{const o=this.scribbleItems.get(n);if(!o)throw Error(`Scribble with id ${n} not found`);const{prev:s}=o,i={x:t,y:r,z:.5};return(!s||w.Dist(s,i)>=1)&&(o.next=i),o});m(this,"tick",n=>{this.scribbleItems.size!==0&&this.editor.batch(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:l,prev:c}=t;l&&l!==c&&(t.prev=l,t.scribble.points.push(l)),t.scribble.points.length>8&&(t.scribble.state="active");return}t.delayRemaining>0&&(t.delayRemaining=Math.max(0,t.delayRemaining-n)),t.timeoutMs+=n,t.timeoutMs>=16&&(t.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=t;switch(a.state){case"active":{i&&i!==s?(t.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(t.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:t})=>({...t,points:[...t.points]})).slice(-5)})})});this.editor=n}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}}var cG=Object.defineProperty,uG=Object.getOwnPropertyDescriptor,ig=(e,n,t,r)=>{for(var o=uG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&cG(n,t,o),o};const ue=e=>Math.round(e*10**8)/10**8;function Ao(e,n,t,r,o){const s=e.filter(a=>(r==="forward"?a.startNode.id===n:a.endNode.id===n)&&ue(a.length)===ue(t)&&Or(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=Ao(e,l,t,r,Or(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function dG(e){e.sort((n,t)=>t.gaps.length-n.gaps.length);for(let n=e.length-1;n>0;n--){const t=e[n];for(let r=n-1;r>=0;r--){const o=e[r];if(o.direction===t.direction&&t.gaps.every(s=>o.gaps.some(i=>ue(s.startEdge[0].x)===ue(i.startEdge[0].x)&&ue(s.startEdge[0].y)===ue(i.startEdge[0].y)&&ue(s.startEdge[1].x)===ue(i.startEdge[1].x)&&ue(s.startEdge[1].y)===ue(i.startEdge[1].y))&&o.gaps.some(i=>ue(s.endEdge[0].x)===ue(i.endEdge[0].x)&&ue(s.endEdge[0].y)===ue(i.endEdge[0].y)&&ue(s.endEdge[1].x)===ue(i.endEdge[1].x)&&ue(s.endEdge[1].y)===ue(i.endEdge[1].y)))){e.splice(n,1);break}}}}class Ku{constructor(n){m(this,"editor");this.manager=n,this.editor=n.editor}getSnapPointsCache(){const{editor:n}=this;return n.store.createComputedCache("snapPoints",t=>{const r=n.getShapePageTransform(t.id);if(!r)return;const s=n.getShapeUtil(t).getBoundsSnapGeometry(t).points??n.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:l,y:c}=oe.applyToPoint(r,i);return{x:l,y:c,id:`${t.id}:${a}`}})})}getSnapPoints(n){return this.getSnapPointsCache().get(n)??[]}getSnappablePoints(){const n=this.getSnapPointsCache(),t=this.manager.getSnappableShapes(),r=[];for(const o of t){const s=n.get(o);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),n=>({id:n,pageBounds:Sr(this.editor.getShapePageBounds(n))}))}getVisibleGaps(){const n=[],t=[];let r,o;const s=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let l=a+1;l<s.length;l++)o=s[l],r.pageBounds.maxX<o.pageBounds.minX&&ac(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&n.push({startNode:r,endNode:o,startEdge:[new w(r.pageBounds.maxX,r.pageBounds.minY),new w(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new w(o.pageBounds.minX,o.pageBounds.minY),new w(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Or(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)o=i[l],r.pageBounds.maxY<o.pageBounds.minY&&ac(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&t.push({startNode:r,endNode:o,startEdge:[new w(r.pageBounds.minX,r.pageBounds.maxY),new w(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new w(o.pageBounds.minX,o.pageBounds.minY),new w(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Or(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:n,vertical:t}}snapTranslateShapes({lockedAxis:n,initialSelectionPageBounds:t,initialSelectionSnapPoints:r,dragDelta:o}){var x,y;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(o),l=r.map(({x:v,y:b},E)=>({id:"selection:"+E,x:v+o.x,y:b+o.y})),c=i,d=[],h=[],p=new w(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:d,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:h,minOffset:p});const f=new w(n==="x"?0:((x=d[0])==null?void 0:x.nudge)??0,n==="y"?0:((y=h[0])==null?void 0:y.nudge)??0);p.x=0,p.y=0,d.length=0,h.length=0,l.forEach(v=>{v.x+=f.x,v.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:d,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:h,minOffset:p});const S=this.getPointSnapLines({nearestSnapsX:d,nearestSnapsY:h}),g=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:h});return this.manager.setIndicators([...g,...S]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var k,T;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=Z.Resize(n,r,s?t.x*2:t.x,s?t.y*2:t.y,o);let d=r;l<0&&(d=SK(d)),c<0&&(d=yK(d)),s&&(a.center=n.center);const h=d==="top"||d==="bottom",p=d==="left"||d==="right",f=jC(d,a),S=this.getSnappablePoints(),g=[],x=[],y=new w(i,i);this.collectPointSnaps({minOffset:y,nearestSnapsX:g,nearestSnapsY:x,otherNodeSnapPoints:S,selectionSnapPoints:f});const v=new w(h?0:((k=g[0])==null?void 0:k.nudge)??0,p?0:((T=x[0])==null?void 0:T.nudge)??0);if(o&&vK(d)&&v.len()!==0){const O=g.length&&x.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":g.length?"x":"y",_=n.aspectRatio;O==="x"?(x.length=0,v.y=v.x/_,(d==="bottom_left"||d==="top_right")&&(v.y=-v.y)):(g.length=0,v.x=v.y*_,(d==="bottom_left"||d==="top_right")&&(v.x=-v.x))}const b=w.Add(t,v),{box:E}=Z.Resize(n,r,s?b.x*2:b.x,s?b.y*2:b.y,o);s&&(E.center=n.center);const I=jC("any",E);g.length=0,x.length=0,y.x=0,y.y=0,this.collectPointSnaps({minOffset:y,nearestSnapsX:g,nearestSnapsY:x,otherNodeSnapPoints:S,selectionSnapPoints:I});const C=this.getPointSnapLines({nearestSnapsX:g,nearestSnapsY:x});return this.manager.setIndicators([...C]),{nudge:v}}collectPointSnaps({selectionSnapPoints:n,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of n)for(const a of t){const l=w.Sub(i,a),c=Math.abs(l.x),d=Math.abs(l.y);ue(c)<=ue(r.x)&&(ue(c)<ue(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),ue(d)<=ue(r.y)&&(ue(d)<ue(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=d)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!ac(a.breadthIntersection[0],a.breadthIntersection[1],n.minY,n.maxY))continue;const c=a.startEdge[0].x+a.length/2-n.center.x;if(a.length>n.width&&ue(Math.abs(c))<=ue(t.x)){ue(Math.abs(c))<ue(t.x)&&(r.length=0),t.x=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},v=r.find(({type:E})=>E==="gap_center"),b=v&&Or(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)]=y:(!v||!b)&&r.push(y)}const h=a.startNode.pageBounds.minX-a.length,p=n.maxX,f=h-p;ue(Math.abs(f))<=ue(t.x)&&(ue(Math.abs(f))<ue(t.x)&&(r.length=0),t.x=Math.abs(f),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:f}));const S=a.endNode.pageBounds.maxX+a.length,g=n.minX,x=S-g;ue(Math.abs(x))<=ue(t.x)&&(ue(Math.abs(x))<ue(t.x)&&(r.length=0),t.x=Math.abs(x),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:x}))}for(const a of i){if(!ac(a.breadthIntersection[0],a.breadthIntersection[1],n.minX,n.maxX))continue;const c=a.startEdge[0].y+a.length/2-n.center.y;if(a.length>n.height&&ue(Math.abs(c))<=ue(t.y)){ue(Math.abs(c))<ue(t.y)&&(o.length=0),t.y=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},v=o.find(({type:E})=>E==="gap_center"),b=v&&ac(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)]=y:(!v||!b)&&o.push(y);continue}const h=a.startNode.pageBounds.minY-a.length,p=n.maxY,f=h-p;ue(Math.abs(f))<=ue(t.y)&&(ue(Math.abs(f))<ue(t.y)&&(o.length=0),t.y=Math.abs(f),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:f}));const S=a.endNode.pageBounds.maxY+a.length,g=n.minY,x=S-g;ue(Math.abs(x))<=ue(t.y)&&(ue(Math.abs(x))<ue(t.y)&&(o.length=0),t.y=Math.abs(x),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:x}))}}getPointSnapLines({nearestSnapsX:n,nearestSnapsY:t}){const r={},o={};if(n.length>0){for(const s of n)if(s.type==="points"){const i=ue(s.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(s.points)}}if(t.length>0){for(const s of t)if(s.type==="points"){const i=ue(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:ot(),type:"points",points:vw(s.map(i=>w.From(i.otherPoint)).concat(s.map(i=>w.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:n,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:n.sides[0],right:n.sides[1],bottom:[n.corners[3],n.corners[2]],left:[n.corners[0],n.corners[3]]},a=[];if(t.length>0)for(const l of t){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:d,startNode:h,endNode:p,length:f,endEdge:S}}=l;switch(l.type){case"gap_center":{const g=(f-n.width)/2,x=Or(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:[...Ao(s,h.id,g,"backward",x),{startEdge:d,endEdge:i.left},{startEdge:i.right,endEdge:S},...Ao(s,p.id,g,"forward",x)]});break}case"gap_duplicate":{const g=Or(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:d.map(x=>x.clone().addXY(-h.pageBounds.width,0))},{startEdge:d,endEdge:S},...Ao(s,p.id,f,"forward",g)]:[...Ao(s,h.id,f,"backward",g),{startEdge:d,endEdge:S},{startEdge:S.map(x=>x.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:d,startNode:h,endNode:p,length:f,endEdge:S}}=l;switch(l.type){case"gap_center":{const g=(f-n.height)/2,x=Or(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:[...Ao(o,h.id,g,"backward",x),{startEdge:d,endEdge:i.top},{startEdge:i.bottom,endEdge:S},...Ao(o,l.gap.endNode.id,g,"forward",x)]});break}case"gap_duplicate":{const g=Or(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:d.map(x=>x.clone().addXY(0,-h.pageBounds.height))},{startEdge:d,endEdge:S},...Ao(o,p.id,f,"forward",g)]:[...Ao(o,h.id,f,"backward",g),{startEdge:d,endEdge:S},{startEdge:S.map(x=>x.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return dG(a),a}}ig([V],Ku.prototype,"getSnapPointsCache");ig([V],Ku.prototype,"getSnappablePoints");ig([V],Ku.prototype,"getSnappableGapNodes");ig([V],Ku.prototype,"getVisibleGaps");function jC(e,n){const{minX:t,maxX:r,minY:o,maxY:s}=n,i=[];switch(e){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:t,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:t,y:s})}return i}var hG=Object.defineProperty,pG=Object.getOwnPropertyDescriptor,fG=(e,n,t,r)=>{for(var o=pG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&hG(n,t,o),o};const gG=()=>null,mG=()=>[];class j2{constructor(n){m(this,"editor");this.manager=n,this.editor=n.editor}getSnapGeometryCache(){const{editor:n}=this;return n.store.createComputedCache("handle snap geometry",t=>{const r=n.getShapeUtil(t).getHandleSnapGeometry(t);return{outline:r.outline===void 0?n.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:r.getSelfSnapOutline??gG,getSelfSnapPoints:r.getSelfSnapPoints??mG}})}*iterateSnapPointsInPageSpace(n,t){var o,s;const r=(o=this.getSnapGeometryCache().get(n))==null?void 0:o.getSelfSnapPoints(t);if(r&&r.length){const i=Sr(this.editor.getShapePageTransform(n));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===n)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.points;if(!a||!a.length)continue;const l=Sr(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(n,t){var o,s;const r=(o=this.getSnapGeometryCache().get(n))==null?void 0:o.getSelfSnapOutline(t);r&&(yield{shapeId:n,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===n)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:r}){const o=this.manager.getSnapThreshold();let s=o,i=null;for(const c of this.iterateSnapPointsInPageSpace(n,t))w.DistMin(r,c,s)&&(s=w.Dist(r,c),i=c);if(i)return i;let a=o,l=null;for(const{shapeId:c,outline:d}of this.iterateSnapOutlines(n,t)){const h=Sr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=d.nearestPoint(p),S=h.applyToPoint(f);w.DistMin(r,S,a)&&(a=w.Dist(r,S),l=S)}return l||null}snapHandle({currentShapeId:n,handle:t}){const o=Sr(this.editor.getShapePageTransform(n)).applyToPoint(t),s=this.getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:ot(),type:"points",points:[s]}]),{nudge:w.Sub(s,o)}):null}}fG([V],j2.prototype,"getSnapGeometryCache");var yG=Object.defineProperty,SG=Object.getOwnPropertyDescriptor,Xw=(e,n,t,r)=>{for(var o=SG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&yG(n,t,o),o};class ag{constructor(n){m(this,"shapeBounds");m(this,"handles");m(this,"_snapIndicators",Mt("snapLines",void 0));this.editor=n,this.shapeBounds=new Ku(this),this.handles=new j2(this)}getIndicators(){return this._snapIndicators.get()??Ho}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(n){this._snapIndicators.set(n)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:n}=this,t=n.getViewportPageBounds(),r=n.getSelectedShapeIds(),o=new Set,s=i=>{if(kn(i)){const l=n.getShape(i);l&&n.isShapeOfType(l,"frame")&&o.add(i)}const a=n.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=n.getShape(l);if(!c||!n.getShapeUtil(c).canSnap(c))continue;const h=n.getShapePageBounds(l);if(h&&t.includes(h)){if(n.isShapeOfType(c,"group")){s(l);continue}o.add(l)}}};return s(this.getCurrentCommonAncestor()??n.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Xw([V],ag.prototype,"getSnapThreshold");Xw([V],ag.prototype,"getSnappableShapes");Xw([V],ag.prototype,"getCurrentCommonAncestor");const vG=/\r?\n|\r/g;function AC(e){return e.replace(vG,`
|
|
`).split(`
|
|
`).map(n=>n||" ").join(`
|
|
`)}const xG={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},wG=/\s/;class bG{constructor(n){m(this,"baseElm");m(this,"measureText",(n,t)=>{var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",t.fontFamily),r.style.setProperty("font-style",t.fontStyle),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("font-size",t.fontSize+"px"),r.style.setProperty("line-height",t.lineHeight*t.fontSize+"px"),r.style.setProperty("max-width",t.maxWidth===null?null:t.maxWidth+"px"),r.style.setProperty("min-width",t.minWidth===null?null:t.minWidth+"px"),r.style.setProperty("padding",t.padding),r.style.setProperty("overflow-wrap",t.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=AC(n);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}});this.editor=n;const t=this.editor.getContainer(),r=document.createElement("div");r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,t.appendChild(r),this.baseElm=r,n.disposables.add(()=>{r.remove()})}measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:t=!1}={}){const r=[],o=n.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,l=n.childNodes[0];let c=0,d=null,h=null,p=0,f=0,S=!1;for(const g of n.childNodes)if(g.nodeType===Node.TEXT_NODE)for(const x of g.textContent??""){a.setStart(l,c),a.setEnd(l,c+x.length);const y=a.getClientRects(),v=y[y.length-1],b=v.top+i,E=v.left+s,I=v.right+s,C=E<f,k=wG.test(x);if(k!==h||b!==p||!d){if(d){if(t&&b!==p){S=!0;break}r.push(d)}d={box:{x:E,y:b,w:v.width,h:v.height},text:x},f=E}else C&&(d.box.x=E),d.box.w=C?d.box.w+v.width:I-d.box.x,d.text+=x;x===`
|
|
`&&(f=0),h=k,p=b,c+=x.length}return d&&r.push(d),{spans:r,didTruncate:S}}measureTextSpans(n,t){var c;if(n==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(t.width-t.padding*2);r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("font-size",`${t.fontSize}px`),r.style.setProperty("font-family",t.fontFamily),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("line-height",`${t.lineHeight*t.fontSize}px`),r.style.setProperty("text-align",xG[t.textAlign]);const s=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";s&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=AC(n);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(t.overflow==="truncate-ellipsis"&&l){r.textContent="…";const d=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-d}px`),r.textContent=i;const h=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=h[h.length-1];return h.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,t.width-t.padding-d),y:p.box.y,w:d,h:p.box.h}}),h}return r.remove(),a}}const OC=(typeof process<"u",FT);class PG{constructor(n){m(this,"cancelRaf");m(this,"isPaused",!0);m(this,"now",0);m(this,"start",()=>{var n;this.isPaused=!1,(n=this.cancelRaf)==null||n.call(this),this.cancelRaf=OC(this.tick),this.now=Date.now()});m(this,"tick",()=>{if(this.isPaused)return;const n=Date.now(),t=n-this.now;this.now=n,this.updatePointerVelocity(t),this.editor.emit("frame",t),this.editor.emit("tick",t),this.cancelRaf=OC(this.tick)});m(this,"dispose",()=>{var n;this.isPaused=!0,(n=this.cancelRaf)==null||n.call(this)});m(this,"prevPoint",new w);m(this,"updatePointerVelocity",n=>{const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(n===0)return;const s=w.Sub(r,t);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new w(0,0),l=o.clone().lrp(a.mul(i/n),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),o.equals(l)||(this.editor.inputs.pointerVelocity=l)});this.editor=n,this.editor.disposables.add(this.dispose),this.start()}}var CG=Object.defineProperty,IG=Object.getOwnPropertyDescriptor,Vr=(e,n,t,r)=>{for(var o=IG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&CG(n,t,o),o};class kr{constructor(n,t){m(this,"systemColorScheme",Mt("systemColorScheme","light"));m(this,"updateUserPreferences",n=>{this.user.setUserPreferences({...this.user.userPreferences.get(),...n})});var r;if(this.user=n,this.inferDarkMode=t,window){const o=(r=window.matchMedia)==null?void 0:r.call(window,"(prefers-color-scheme: dark)");o!=null&&o.matches&&this.systemColorScheme.set("dark"),o==null||o.addEventListener("change",s=>{s.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")})}}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??gs.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??gs.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??gs.name}getLocale(){return this.user.userPreferences.get().locale??gs.locale}getColor(){return this.user.userPreferences.get().color??gs.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??gs.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??gs.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??gs.isDynamicSizeMode}}Vr([V],kr.prototype,"getUserPreferences");Vr([V],kr.prototype,"getIsDarkMode");Vr([V],kr.prototype,"getEdgeScrollSpeed");Vr([V],kr.prototype,"getAnimationSpeed");Vr([V],kr.prototype,"getId");Vr([V],kr.prototype,"getName");Vr([V],kr.prototype,"getLocale");Vr([V],kr.prototype,"getColor");Vr([V],kr.prototype,"getIsSnapMode");Vr([V],kr.prototype,"getIsWrapMode");Vr([V],kr.prototype,"getIsDynamicResizeMode");const EG={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"},kG=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class se{constructor(n,t){m(this,"performanceTracker");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",(n,t={})=>{var s;const r=n.split(".");let o=this;for(let i=0;i<r.length;i++){const a=r[i],l=o.getCurrent(),c=(s=o.children)==null?void 0:s[a];if(!c)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(t,a),o._current.set(c),c.enter(t,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;o=c}return this});m(this,"handleEvent",n=>{var o;const t=EG[n.name],r=this._current.__unsafe__getWithoutCapture();(o=this[t])==null||o.call(this,n),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(n)});m(this,"enter",(n,t)=>{var r;if(wt.measurePerformance.get()&&kG.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,n,t),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(n,t)}});m(this,"exit",(n,t)=>{var r,o;wt.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,n,t),this.getIsActive()||(o=this.getCurrent())==null||o.exit(n,t)});m(this,"_currentToolIdMask",Mt("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=n;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=Mt("toolIsActive"+this.id,!1),this._current=Mt("toolState"+this.id,void 0),this._path=V("toolPath"+this.id,()=>{const i=this.getCurrent();return this.id+(i?`.${i.getPath()}`:"")}),this.parent=t??{},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]))),this.performanceTracker=new bT}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(n){this._currentToolIdMask.set(n)}}m(se,"id"),m(se,"initial"),m(se,"children");class Dh extends se{constructor(){super(...arguments);m(this,"onKeyDown",t=>{var r;switch(t.code){case"KeyZ":{if(!(t.shiftKey||t.ctrlKey)){const o=this.getCurrent();o&&((r=o.getCurrent())==null?void 0:r.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...t,onInteractionEnd:o.id})}break}}})}}m(Dh,"id","root"),m(Dh,"initial",""),m(Dh,"children",()=>[]);var _G=Object.defineProperty,TG=Object.getOwnPropertyDescriptor,ne=(e,n,t,r)=>{for(var o=TG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&_G(n,t,o),o};class Q extends CW{constructor({store:t,user:r,shapeUtils:o,bindingUtils:s,tools:i,getContainer:a,cameraOptions:l,assetOptions:c,initialState:d,autoFocus:h,inferDarkMode:p,options:f}){super();m(this,"options");m(this,"store");m(this,"root");m(this,"disposables",new Set);m(this,"isDisposed",!1);m(this,"_tickManager");m(this,"snaps");m(this,"timers");m(this,"user");m(this,"textMeasure");m(this,"environment");m(this,"scribbles");m(this,"sideEffects");m(this,"edgeScrollManager");m(this,"focusManager");m(this,"getContainer");m(this,"shapeUtils");m(this,"styleProps");m(this,"bindingUtils");m(this,"history");m(this,"_crashingError",null);m(this,"_updateInstanceState",(t,r)=>{this.batch(()=>{this.store.put([{...this.getInstanceState(),...t}])},r)});m(this,"_isChangingStyleTimeout",-1);m(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}}),this));m(this,"_updateCurrentPageState",(t,r)=>{this.batch(()=>{this.store.update(t.id??this.getCurrentPageState().id,o=>({...o,...t}))},{history:"ignore",...r})});m(this,"_cameraOptions",Mt("camera options",sC));m(this,"_viewportAnimation",null);m(this,"_willSetInitialBounds",!0);m(this,"_isLockedOnFollowingUser",Mt("isLockedOnFollowingUser",!1));m(this,"_cameraState",Mt("camera state","idle"));m(this,"_cameraStateTimeoutRemaining",0);m(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))});m(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});m(this,"_currentPageShapeIds");m(this,"_assetOptions",Mt("asset options",iC));m(this,"_parentIdsToChildIds");m(this,"animatingShapes",new Map);m(this,"_updateShapes",t=>{this.getInstanceState().isReadonly||this.batch(()=>{var i,a;const r=[];let o,s;for(let l=0,c=t.length;l<c;l++){const d=t[l];d&&(o=this.getShape(d.id),o&&(s=jo(o,d),s!==o&&(s=((a=(i=this.getShapeUtil(o)).onBeforeUpdate)==null?void 0:a.call(i,o,s))??s,r.push(s))))}this.store.put(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 w,originScreenPoint:new w,previousPagePoint:new w,previousScreenPoint:new w,currentPagePoint:new w,currentScreenPoint:new w,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 w});m(this,"_clickManager",new JW(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,"performanceTracker");m(this,"performanceTrackerTimeout",-1);m(this,"dispatch",t=>(this._pendingEventsForNextTick.push(t),t.type==="pointer"&&t.name==="pointer_move"||t.type==="wheel"||t.type==="pinch"||this._flushEventsForTick(0),this));m(this,"_pendingEventsForNextTick",[]);m(this,"_flushEventForTick",t=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=t;if(t.type==="misc"){(t.name==="cancel"||t.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(t);return}t.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!t.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),t.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!t.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),t.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!t.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,currentPagePoint:i}=r;r.isPointing||(r.isDragging=!1);const a=this.store.unsafeGetWithoutCapture(gn),l=this.store.get(this._getCurrentPageStateId()),c=this._cameraOptions.__unsafe__getWithoutCapture();switch(o){case"pinch":{if(c.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(t),t.name){case"pinch_start":{if(r.isPinching)return;r.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=[...l.selectedShapeIds]),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:d=1},delta:{x:h,y:p}}=t,{x:f,y:S}=w.SubXY(t.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:g,y:x,z:y}=Um(()=>this.getCamera()),{panSpeed:v,zoomSpeed:b}=c;this._setCamera(new w(g+h*v/y-f/y+f/(d*b),x+p*v/y-S/y+S/(d*b),d*b),{immediate:!0});return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:d}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,d.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(d)}));return}}}case"wheel":{if(c.isLocked)return;if(this._updateInputsFromEvent(t),!this.getIsMenuOpen()){const{panSpeed:d,zoomSpeed:h,wheelBehavior:p}=c;if(p!=="none"){this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:f,y:S,z:g}=Um(()=>this.getCamera()),{x,y,z:v=0}=t.delta;let b=p;switch(r.ctrlKey&&(b=p==="pan"?"zoom":"pan"),b){case"zoom":{const{x:E,y:I}=this.inputs.currentScreenPoint;let C=v;p==="zoom"&&(Math.abs(y)>10?C=10*Math.sign(y)/100:C=y/100);const k=g+(C??0)*h*g;this._setCamera(new w(f+(E/k-E)-(E/g-E),S+(I/k-I)-(I/g-I),k),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new w(f+x*d/g,S+y*d/g,g),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(t);const{isPen:d}=t,{isPenMode:h}=a;switch(t.name){case"pointer_down":{if(h&&!d)return;if(this.clearOpenMenus(),this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{this.dispatch({...t,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),t.button===lC&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,!h&&d&&this.updateInstanceState({isPenMode:!0}),t.button===cC?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===Nd&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!d&&h)return;const{x:p,y:f,z:S}=Um(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:g,previousScreenPoint:x}=this.inputs,{panSpeed:y}=c,v=w.Sub(g,x);this.setCamera(new w(p+v.x*y/S,f+v.y*y/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&w.Dist2(s,i)*this.getZoomLevel()>(a.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/S&&(r.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(r.isDragging=!1,r.isPointing=!1,clearTimeout(this._longPressTimeout),r.buttons.delete(t.button),this.getIsMenuOpen()||a.isPenMode&&!d)return;if(this.capturedPointerId===t.pointerId&&(this.capturedPointerId=null,t.button=0),r.isPanning){r.keys.has("Space")||(r.isPanning=!1);const p=this.inputs.pointerVelocity,f=Math.min(2,p.len());switch(t.button){case lC:{this.setCursor({type:"grab",rotation:0});break}case Nd:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}f>0&&this.slideCamera({speed:f,direction:p})}else t.button===cC&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(t.key==="ShiftRight"&&(t.key="ShiftLeft"),t.key==="AltRight"&&(t.key="AltLeft"),t.code==="ControlRight"&&(t.code="ControlLeft"),t.name){case"key_down":{r.keys.add(t.code),t.code==="Space"&&!t.ctrlKey&&(this.inputs.isPanning||(this._prevCursor=a.cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0}));break}case"key_up":{r.keys.delete(t.code),t.code==="Space"&&(this.inputs.buttons.has(Nd)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(t.type==="pointer"){t.button===Nd?t.name="middle_click":t.button===Fw&&(t.name="right_click");const{isPenMode:d}=this.store.unsafeGetWithoutCapture(gn);if(t.isPen===d){const h=this._clickManager.handlePointerEvent(t);if(t.name!==h.name){this.root.handleEvent(t),this.emit("event",t),this.root.handleEvent(h),this.emit("event",h);return}}}return this.root.handleEvent(t),this.emit("event",t),this});this.options={...$W,...f},this.store=t,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new sG({store:t,annotateError:_=>{this.annotateError(_,{origin:"history.batch",willCrashApp:!0}),this.crash(_)}}),this.snaps=new ag(this),this.timers=new Z6,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...sC,...l}),this._assetOptions.set({...iC,...c}),this.user=new kr(r??y2(),p??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new bG(this),this._tickManager=new PG(this);class S extends Dh{}m(S,"initial",d??""),this.root=new S(this),this.root.children={};const g=k2(o),x={},y={},v=new Map;for(const _ of g){const j=new _(this);x[_.type]=j;const L=eM(_.props??{});y[_.type]=L;for(const A of L.keys())if(!v.has(A.id))v.set(A.id,A);else if(v.get(A.id)!==A)throw Error(`Multiple style props with id "${A.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=x,this.styleProps=y;const b=C2(s),E={};for(const _ of b){const j=new _(this);E[_.type]=j}this.bindingUtils=E;for(const _ of[...i]){if(fo(this.root.children,_.id))throw Error(`Can't override tool with id "${_.id}"`);this.root.children[_.id]=new _(this,this.root)}this.environment=new tG(this),this.scribbles=new lG(this);const I=(_,j)=>{let L=null;const A=_.selectedShapeIds.filter(W=>!j.has(W));A.length!==_.selectedShapeIds.length&&(L||(L={..._}),L.selectedShapeIds=A);const R=_.erasingShapeIds.filter(W=>!j.has(W));R.length!==_.erasingShapeIds.length&&(L||(L={..._}),L.erasingShapeIds=R),_.hoveredShapeId&&j.has(_.hoveredShapeId)&&(L||(L={..._}),L.hoveredShapeId=null),_.editingShapeId&&j.has(_.editingShapeId)&&(L||(L={..._}),L.editingShapeId=null);const F=_.hintingShapeIds.filter(W=>!j.has(W));return F.length!==_.hintingShapeIds.length&&(L||(L={..._}),L.hintingShapeIds=F),_.focusedGroupId&&j.has(_.focusedGroupId)&&(L||(L={..._}),L.focusedGroupId=null),L};this.sideEffects=this.store.sideEffects;let C=new Map;const k=new Set,T=new Set;let O=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var _,j,L,A;k.clear();for(const R of T){T.delete(R);const F=this.getShape(R);if(!F)continue;const W=this.getShapeUtil(F),K=(_=W.onChildrenChange)==null?void 0:_.call(W,F);K!=null&&K.length&&this.updateShapes(K)}if(O.size){const R=O;O=new Set;for(const F of R){const W=this.getBindingUtil(F);(j=W.onOperationComplete)==null||j.call(W)}}if(C.size){const R=C;C=new Map;for(const F of R.values())(A=(L=this.getBindingUtil(F.binding)).onAfterDelete)==null||A.call(L,F)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(_,j)=>{var L,A,R,F;for(const W of this.getBindingsInvolvingShape(j))O.add(W.type),W.fromId===j.id&&((A=(L=this.getBindingUtil(W)).onAfterChangeFromShape)==null||A.call(L,{binding:W,shapeBefore:_,shapeAfter:j})),W.toId===j.id&&((F=(R=this.getBindingUtil(W)).onAfterChangeToShape)==null||F.call(R,{binding:W,shapeBefore:_,shapeAfter:j}));if(_.parentId!==j.parentId){const W=K=>{var U,X,J,le;const z=this.getShape(K);if(z)for(const ye of this.getBindingsInvolvingShape(z))O.add(ye.type),ye.fromId===z.id&&((X=(U=this.getBindingUtil(ye)).onAfterChangeFromShape)==null||X.call(U,{binding:ye,shapeBefore:z,shapeAfter:z})),ye.toId===z.id&&((le=(J=this.getBindingUtil(ye)).onAfterChangeToShape)==null||le.call(J,{binding:ye,shapeBefore:z,shapeAfter:z}))};W(j.id),this.visitDescendants(j.id,W)}if(_.parentId!==j.parentId&&In(j.parentId)){const W=new Set([_.id]);this.visitDescendants(_.id,K=>{W.add(K)});for(const K of this.getPageStates()){if(K.pageId===j.parentId)continue;const z=I(K,W);z&&this.store.put([z])}}_.parentId&&kn(_.parentId)&&T.add(_.parentId),j.parentId!==_.parentId&&kn(j.parentId)&&T.add(j.parentId)},beforeDelete:_=>{var R,F,W,K;if(k.has(_.id))return;_.parentId&&kn(_.parentId)&&T.add(_.parentId),k.add(_.id);const j=[];for(const z of this.getBindingsInvolvingShape(_)){O.add(z.type),j.push(z.id);const U=this.getBindingUtil(z);z.fromId===_.id?((R=U.onBeforeIsolateToShape)==null||R.call(U,{binding:z,removedShape:_}),(F=U.onBeforeDeleteFromShape)==null||F.call(U,{binding:z,shape:_})):((W=U.onBeforeIsolateFromShape)==null||W.call(U,{binding:z,removedShape:_}),(K=U.onBeforeDeleteToShape)==null||K.call(U,{binding:z,shape:_}))}j.length&&this.deleteBindings(j);const L=new Set([_.id]),A=me(this.getPageStates().map(z=>I(z,L)));A.length&&this.store.put(A)}},binding:{beforeCreate:_=>{var L,A;const j=(A=(L=this.getBindingUtil(_)).onBeforeCreate)==null?void 0:A.call(L,{binding:_});return j||_},afterCreate:_=>{var j,L;O.add(_.type),(L=(j=this.getBindingUtil(_)).onAfterCreate)==null||L.call(j,{binding:_})},beforeChange:(_,j)=>{var A,R;const L=(R=(A=this.getBindingUtil(j)).onBeforeChange)==null?void 0:R.call(A,{bindingBefore:_,bindingAfter:j});return L||j},afterChange:(_,j)=>{var L,A;O.add(j.type),(A=(L=this.getBindingUtil(j)).onAfterChange)==null||A.call(L,{bindingBefore:_,bindingAfter:j})},beforeDelete:_=>{var j,L;(L=(j=this.getBindingUtil(_)).onBeforeDelete)==null||L.call(j,{binding:_})},afterDelete:_=>{var j,L;(L=(j=this.getBindingUtil(_)).onAfterDelete)==null||L.call(j,{binding:_}),O.add(_.type)}},page:{afterCreate:_=>{const j=lo.createId(_.id),L=$r.createId(_.id);this.store.has(j)||this.store.put([lo.create({id:j})]),this.store.has(L)||this.store.put([$r.create({id:L,pageId:_.id})])},afterDelete:(_,j)=>{var R,F;if(((R=this.getInstanceState())==null?void 0:R.currentPageId)===_.id){const W=(F=this.getPages().find(K=>K.id!==_.id))==null?void 0:F.id;W?this.store.put([{...this.getInstanceState(),currentPageId:W}]):j==="user"&&this.store.ensureStoreIsUsable()}const L=lo.createId(_.id),A=$r.createId(_.id);this.store.remove([L,A])}},instance:{afterChange:(_,j,L)=>{var A;if(!this.store.has(j.currentPageId)){const R=this.store.has(_.currentPageId)?_.currentPageId:(A=this.getPages()[0])==null?void 0:A.id;R?this.store.update(j.id,F=>({...F,currentPageId:R})):L==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(_,j)=>{if((_==null?void 0:_.selectedShapeIds)!==(j==null?void 0:j.selectedShapeIds)){const L=j.selectedShapeIds.filter(R=>{var W,K;let F=(W=this.getShape(R))==null?void 0:W.parentId;for(;kn(F);){if(j.selectedShapeIds.includes(F))return!1;F=(K=this.getShape(F))==null?void 0:K.parentId}return!0});let A=null;if(L.length>0){const R=this.findCommonAncestor(me(L.map(F=>this.getShape(F))),F=>this.isShapeOfType(F,"group"));R&&(A=R)}else j!=null&&j.focusedGroupId&&(A=j.focusedGroupId);(L.length!==j.selectedShapeIds.length||A!==j.focusedGroupId)&&this.store.put([{...j,selectedShapeIds:L,focusedGroupId:A??null}])}}}})),this._currentPageShapeIds=XW(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=YW(this.store),this.disposables.add(this.store.listen(_=>{this.emit("change",_)})),this.disposables.add(this.history.dispose),this.history.ignore(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})}),d&&this.root.children[d]===void 0)throw Error(`No state found for initialState "${d}".`);this.root.enter(void 0,"initial"),this.edgeScrollManager=new eG(this),this.focusManager=new nG(this,h),this.disposables.add(this.focusManager.dispose.bind(this.focusManager)),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.on("tick",this._flushEventsForTick),this.timers.requestAnimationFrame(()=>{this._tickManager.start()}),this.performanceTracker=new bT}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=An(this.shapeUtils,r);return st(o,`No shape util found for type "${r}"`),o}getBindingUtil(t){const r=typeof t=="string"?t:t.type,o=An(this.bindingUtils,r);return st(o,`No binding util found for type "${r}"`),o}undo(){return this._flushEventsForTick(0),this.complete(),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.complete(),this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(t){return this.history.mark(t),this}bail(){return this.history.bail(),this}bailToMark(t){return this.history.bailToMark(t),this}batch(t,r){return this.history.batch(t,r),this}annotateError(t,{origin:r,willCrashApp:o,tags:s,extras:i}){const a=this.createErrorAnnotations(r,o);return xw(t,{tags:{...a.tags,...s},extras:{...a.extras,...i}}),o&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(t,r){try{const o=this.getEditingShapeId();return{tags:{origin:t,willCrashApp:r},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:o?this.getShape(o):void 0,inputs:this.inputs}}}catch{return{tags:{origin:t,willCrashApp:r},extras:{}}}}getCrashingError(){return this._crashingError}crash(t){return this._crashingError=t,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:t}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(t){const r=t.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(...t){return t.some(r=>this.isIn(r))}setCurrentTool(t,r={}){return this.root.transition(t,r),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const t=this.getCurrentTool();return t?t.getCurrentToolIdMask()??t.id:""}getStateDescendant(t){var s;const r=t.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(hv)}updateDocumentSettings(t){return this.history.ignore(()=>{this.store.put([{...this.getDocumentSettings(),...t}])}),this}getInstanceState(){return this.store.get(gn)}updateInstanceState(t,r){return this._updateInstanceState(t,{history:"ignore",...r}),t.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),t.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},2e3))),this}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(t){const r=new Set(this.getOpenMenus());return r.has(t)||(r.add(t),this.updateInstanceState({openMenus:[...r]})),this}deleteOpenMenu(t){const r=new Set(this.getOpenMenus());return r.has(t)&&(r.delete(t),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 $r.createId(this.getCurrentPageId())}updateCurrentPageState(t,r){return this._updateCurrentPageState(t,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:t}=this.getCurrentPageState();return me(t.map(r=>this.store.get(r)))}setSelectedShapes(t){return this.batch(()=>{const r=t.map(i=>typeof i=="string"?i:i.id),{selectedShapeIds:o}=this.getCurrentPageState(),s=new Set(o);if(r.length===s.size&&r.every(i=>s.has(i)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:r}])},{history:"record-preserveRedoStack"})}isAncestorSelected(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null,o=this.getShape(r);if(!o)return!1;const s=this.getSelectedShapeIds();return!!this.findShapeAncestor(o,i=>s.includes(i.id))}select(...t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.setSelectedShapes(r),this}deselect(...t){const r=typeof t[0]=="string"?t:t.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 t=this.getSortedChildIdsForParent(this.getCurrentPageId());return t.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(t)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var t;return((t=this.getOnlySelectedShape())==null?void 0:t.id)??null}getOnlySelectedShape(){const t=this.getSelectedShapes();return t.length===1?t[0]:null}getSelectionPageBounds(){const t=this.getCurrentPageState().selectedShapeIds;return t.length===0?null:Z.Common(me(t.map(r=>this.getShapePageBounds(r))))}getSelectionRotation(){const t=this.getSelectedShapeIds();let r=!1,o=0;for(let s=0,i=t.length;s<i;s++){const a=this.getShapePageTransform(t[s]);if(a)if(r){if(a.rotation()!==o)return 0}else r=!0,o=a.rotation()}return o}getSelectionRotatedPageBounds(){const t=this.getSelectedShapeIds();if(t.length===0)return;const r=this.getSelectionRotation();if(r===0)return this.getSelectionPageBounds();if(t.length===1){const s=this.getShapeGeometry(t[0]).bounds.clone(),i=this.getShapePageTransform(t[0]);return s.point=i.applyToPoint(s.point),s}const o=Z.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 t=this.getSelectionRotatedPageBounds();if(!t)return;const{x:r,y:o}=this.pageToScreen(t.point),s=this.getZoomLevel();return new Z(r,o,t.width*s,t.height*s)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const t=this.getFocusedGroupId();return t?this.getShape(t):void 0}setFocusedGroup(t){const r=typeof t=="string"?t:(t==null?void 0:t.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.batch(()=>{this.store.update(this.getCurrentPageState().id,o=>({...o,focusedGroupId:r}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const t=this.getFocusedGroup();if(t){const r=this.findShapeAncestor(t,o=>this.isShapeOfType(o,"group"));this.setFocusedGroup((r==null?void 0:r.id)??null),this.select(t.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const t=this.getEditingShapeId();return t?this.getShape(t):void 0}setEditingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==this.getEditingShapeId()){if(r){const o=this.getShape(r);if(o&&this.getShapeUtil(o).canEdit(o))return this._updateCurrentPageState({editingShapeId:r}),this}this._updateCurrentPageState({editingShapeId:null})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const t=this.getHoveredShapeId();return t?this.getShape(t):void 0}setHoveredShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;return r===this.getHoveredShapeId()?this:(this.updateCurrentPageState({hoveredShapeId:r},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const t=this.getHintingShapeIds();return me(t.map(r=>this.getShape(r)))}setHintingShapes(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:vw(r)},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const t=this.getErasingShapeIds();return me(t.map(r=>this.getShape(r)))}setErasingShapes(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id);r.sort();const o=this.getErasingShapeIds();return this.history.ignore(()=>{if(r.length===o.length){for(let s=0;s<r.length;s++)if(r[s]!==o[s]){this._updateCurrentPageState({erasingShapeIds:r});break}}else this._updateCurrentPageState({erasingShapeIds:r})}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.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 lo.createId(this.getCurrentPageId())}getCamera(){const t=this.store.get(this.getCameraId());if(this._isLockedOnFollowingUser.get()){const r=this.getCameraForFollowing();if(r)return{...t,...r}}return t}getViewportPageBoundsForFollowing(){const t=this.getInstanceState().followingUserId;if(!t)return null;const r=this.getCollaborators().find(p=>p.userId===t);if(!r)return null;const{w:o,h:s}=r.screenBounds,{x:i,y:a,z:l}=r.camera,c=new Z(-i,-a,o/l,s/l),d=this.getViewportScreenBounds().clone(),h=d.width/d.height;return d.width=c.width,d.height=d.width/h,d.height<c.height&&(d.height=c.height,d.width=d.height*h),d.center=c.center,d}getCameraForFollowing(){const t=this.getViewportPageBoundsForFollowing();return t?{x:-t.x,y:-t.y,z:this.getViewportScreenBounds().w/t.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.initialZoom==="default")return 1;const{zx:r,zy:o}=RC(this,t);switch(t.constraints.initialZoom){case"fit-min":return Math.max(r,o);case"fit-max":return Math.min(r,o);case"fit-x":return r;case"fit-y":return o;case"fit-min-100":return Math.min(1,Math.max(r,o));case"fit-max-100":return Math.min(1,Math.min(r,o));case"fit-x-100":return Math.min(1,r);case"fit-y-100":return Math.min(1,o);default:throw an(t.constraints.initialZoom)}}getBaseZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.baseZoom==="default")return 1;const{zx:r,zy:o}=RC(this,t);switch(t.constraints.baseZoom){case"fit-min":return Math.max(r,o);case"fit-max":return Math.min(r,o);case"fit-x":return r;case"fit-y":return o;case"fit-min-100":return Math.min(1,Math.max(r,o));case"fit-max-100":return Math.min(1,Math.min(r,o));case"fit-x-100":return Math.min(1,r);case"fit-y-100":return Math.min(1,o);default:throw an(t.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(t){var o;const r=rt({...this._cameraOptions.__unsafe__getWithoutCapture(),...t});return((o=r.zoomSteps)==null?void 0:o.length)<1&&(r.zoomSteps=[1]),this._cameraOptions.set(r),this}getConstrainedCamera(t,r){const o=this.getCamera();let{x:s,y:i,z:a=o.z}=t;if(!(r!=null&&r.force)){const l=this.getCameraOptions(),c=l.zoomSteps[0],d=Nt(l.zoomSteps),h=this.getViewportScreenBounds();if(l.constraints){const{constraints:p}=l,f=Math.min(p.padding.y,h.w/2),S=Math.min(p.padding.x,h.h/2),g=Z.From(l.constraints.bounds),x=(h.w-S*2)/g.w,y=(h.h-f*2)/g.h,v=this.getBaseZoom(),b=d*v,E=c*v;if(r!=null&&r.reset&&(a=this.getInitialZoom()),a<E||a>b){const{x:A,y:R,z:F}=o,W=-A+h.w/F/2,K=-R+h.h/F/2;a=_t(a,E,b);const z=-A+h.w/a/2,U=-R+h.h/a/2;s=A+z-W,i=R+U-K}const I=S/a-g.x,C=f/a-g.y,k=(h.w-S*2)/a-g.w,T=(h.h-f*2)/a-g.h,O=I+k*p.origin.x,_=C+T*p.origin.y,j=typeof p.behavior=="string"?p.behavior:p.behavior.x,L=typeof p.behavior=="string"?p.behavior:p.behavior.y;if(r!=null&&r.reset)s=O,i=_;else{switch(j){case"fixed":{s=O;break}case"contain":{a<x?s=O:s=_t(s,I+k,I);break}case"inside":{a<x?s=_t(s,I,(h.w-S)/a-g.w):s=_t(s,I+k,I);break}case"outside":{s=_t(s,S/a-g.w,(h.w-S)/a);break}case"free":break;default:throw an(j)}switch(L){case"fixed":{i=_;break}case"contain":{a<y?i=_:i=_t(i,C+T,C);break}case"inside":{a<y?i=_t(i,C,(h.h-f)/a-g.h):i=_t(i,C+T,C);break}case"outside":{i=_t(i,f/a-g.h,(h.h-f)/a);break}case"free":break;default:throw an(L)}}}else if(a>d||a<c){const{x:p,y:f,z:S}=o;a=_t(a,c,d),s=p+(-p+h.w/a/2)-(-p+h.w/S/2),i=f+(-f+h.h/a/2)-(-f+h.h/S/2)}}return{x:s,y:i,z:a}}_setCamera(t,r){const o=this.getCamera(),{x:s,y:i,z:a}=this.getConstrainedCamera(t,r);return o.x===s&&o.y===i&&o.z===a?this:(this.batch(()=>{const l={...o,x:s,y:i,z:a};this.history.ignore(()=>{this.store.put([l])});const{currentScreenPoint:c,currentPagePoint:d}=this.inputs,{screenBounds:h}=this.store.unsafeGetWithoutCapture(gn);if(c.x/a-s!==d.x||c.y/a-i!==d.y){const p={type:"pointer",target:"canvas",name:"pointer_move",point:w.AddXY(c,h.x,h.y),pointerId:aC.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1};r!=null&&r.immediate?this._flushEventForTick(p):this.dispatch(p)}this._tickCameraState()}),this)}setCamera(t,r){const{isLocked:o}=this._cameraOptions.__unsafe__getWithoutCapture();if(o&&!(r!=null&&r.force))return this;this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser();const s=w.Cast(t);Number.isFinite(s.x)||(s.x=0),Number.isFinite(s.y)||(s.y=0),(s.z===void 0||!Number.isFinite(s.z))&&(t.z=this.getZoomLevel());const i=this.getConstrainedCamera(s,r);if(r!=null&&r.animation){const{width:a,height:l}=this.getViewportScreenBounds();this._animateToViewport(new Z(-i.x,-i.y,a/i.z,l/i.z),r)}else this._setCamera(i,{...r,force:!0});return this}centerOnPoint(t,r){if(this.getCameraOptions().isLocked)return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera(new w(-(t.x-o/2),-(t.y-s/2),this.getCamera().z),r),this}zoomToFit(t){const r=[...this.getCurrentPageShapeIds()];if(r.length<=0)return this;const o=Z.Common(me(r.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(o,t),this}resetZoom(t=this.getViewportScreenCenter(),r){const{isLocked:o,constraints:s}=this.getCameraOptions();if(o)return this;const i=this.getCamera(),{x:a,y:l,z:c}=i,{x:d,y:h}=t;let p=1;if(s){const f=this.getInitialZoom();c!==f&&(p=f)}return this.setCamera(new w(a+(d/p-d)-(d/c-d),l+(h/p-h)-(h/c-h),p),r),this}zoomIn(t=this.getViewportScreenCenter(),r){if(this.getCameraOptions().isLocked)return this;const{x:o,y:s,z:i}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const l=this.getBaseZoom();let c=Nt(a)*l;for(let d=1;d<a.length;d++){const h=a[d-1]*l,p=a[d]*l;if(!(p-i<=(p-h)/2)){c=p;break}}this.setCamera(new w(o+(t.x/c-t.x)-(t.x/i-t.x),s+(t.y/c-t.y)-(t.y/i-t.y),c),r)}return this}zoomOut(t=this.getViewportScreenCenter(),r){if(this.getCameraOptions().isLocked)return this;const{zoomSteps:o}=this.getCameraOptions();if(o!==null&&o.length>1){const s=this.getBaseZoom(),{x:i,y:a,z:l}=this.getCamera();let c=o[0]*s;for(let d=o.length-1;d>0;d--){const h=o[d-1]*s,p=o[d]*s;if(!(p-l>=(p-h)/2)){c=h;break}}this.setCamera(new w(i+(t.x/c-t.x)-(t.x/l-t.x),a+(t.y/c-t.y)-(t.y/l-t.y),c),r)}return this}zoomToSelection(t){if(this.getCameraOptions().isLocked)return this;const r=this.getSelectionPageBounds();return r&&this.zoomToBounds(r,{targetZoom:Math.max(1,this.getZoomLevel()),...t}),this}zoomToBounds(t,r){const o=this._cameraOptions.__unsafe__getWithoutCapture();if(o.isLocked)return this;const s=this.getViewportScreenBounds(),i=(r==null?void 0:r.inset)??Math.min(t7,s.width*.28),a=this.getBaseZoom(),l=o.zoomSteps[0],c=Nt(o.zoomSteps);let d=_t(Math.min((s.width-i)/t.w,(s.height-i)/t.h),l*a,c*a);return(r==null?void 0:r.targetZoom)!==void 0&&(d=Math.min(r.targetZoom,d)),this.setCamera(new w(-t.x+(s.width-t.w*d)/2/d,-t.y+(s.height-t.h*d)/2/d,d),r),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(t){if(!this._viewportAnimation)return;this._viewportAnimation.elapsed+=t;const{elapsed:r,easing:o,duration:s,start:i,end:a}=this._viewportAnimation;if(r>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new w(-a.x,-a.y,this.getViewportScreenBounds().width/a.width));return}const l=s-r,c=o(1-l/s),d=i.minX+(a.minX-i.minX)*c,h=i.minY+(a.minY-i.minY)*c,p=i.maxX+(a.maxX-i.maxX)*c;this._setCamera(new w(-d,-h,this.getViewportScreenBounds().width/(p-d)),{force:!0})}_animateToViewport(t,r={animation:Gm}){const{animation:o,...s}=r;if(!o)return;const{duration:i=0,easing:a=jt.easeInOutCubic}=o,l=this.user.getAnimationSpeed(),c=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||l===0?this._setCamera(new w(-t.x,-t.y,this.getViewportScreenBounds().width/t.width),{...s}):(this._viewportAnimation={elapsed:0,duration:i/l,easing:a,start:c.clone(),end:t.clone()},this.once("stop-camera-animation",()=>{this.off("tick",this._animateViewport),this._viewportAnimation=null}),this.on("tick",this._animateViewport),this)}slideCamera(t={}){if(this.getCameraOptions().isLocked)return this;if(this.user.getAnimationSpeed()===0)return this;this.stopCameraAnimation();const{speed:o,friction:s=this.options.cameraSlideFriction,direction:i,speedThreshold:a=.01}=t;let l=Math.min(o,1);const c=()=>{this.off("tick",d),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const d=h=>{const{x:p,y:f,z:S}=this.getCamera(),g=w.Mul(i,l*h/S);l*=1-s,l<a?c():this._setCamera(new w(p+g.x,f+g.y,S))};return this.on("tick",d),this}zoomToUser(t,r={animation:{duration:500}}){const o=this.getCollaborators().find(s=>s.userId===t);return o?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const s=o.currentPageId===this.getCurrentPageId();s||this.setCurrentPage(o.currentPageId),r&&r.animation&&!s&&(r.animation=void 0),this.centerOnPoint(o.cursor,r);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,t]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],l=a.indexOf(t);l<0||(a.splice(l,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(t,r=!1){t.width=Math.max(t.width,1),t.height=Math.max(t.height,1);const o=[t.minY!==0,!Us(document.body.scrollWidth,t.maxX,1),!Us(document.body.scrollHeight,t.maxY,1),t.minX!==0],{screenBounds:s,insets:i}=this.getInstanceState();if(t.equals(s)&&o.every((l,c)=>l===i[c]))return this;const{_willSetInitialBounds:a}=this;if(this._willSetInitialBounds=!1,a)this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.setCamera(this.getCamera());else if(r&&!this.getInstanceState().followingUserId){const l=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.centerOnPoint(l)}else this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this._setCamera(w.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:t,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new Z(t,r,o,s)}getViewportScreenCenter(){const t=this.getViewportScreenBounds();return new w(t.midX-t.minX,t.midY-t.minY)}getViewportPageBounds(){const{w:t,h:r}=this.getViewportScreenBounds(),{x:o,y:s,z:i}=this.getCamera();return new Z(-o,-s,t/i,r/i)}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(gn),{x:o,y:s,z:i=1}=this.getCamera();return new w((t.x-r.x)/i-o,(t.y-r.y)/i-s,t.z??.5)}pageToScreen(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(gn),{x:o,y:s,z:i=1}=this.getCamera();return new w((t.x+o)*i+r.x,(t.y+s)*i+r.y,t.z??.5)}pageToViewport(t){const{x:r,y:o,z:s=1}=this.getCamera();return new w((t.x+r)*s,(t.y+o)*s,t.z??.5)}_getCollaboratorsQuery(){return this.store.query.records("instance_presence",()=>({userId:{neq:this.user.getId()}}))}getCollaborators(){const t=this._getCollaboratorsQuery().get();return t.length?[...new Set(t.map(o=>o.userId))].sort().map(o=>t.filter(i=>i.userId===o).sort((i,a)=>a.lastActivityTimestamp-i.lastActivityTimestamp)[0]):Ho}getCollaboratorsOnCurrentPage(){const t=this.getCurrentPageId();return this.getCollaborators().filter(r=>r.currentPageId===t)}startFollowingUser(t){this.stopFollowingUser();const r=this._getCollaboratorsQuery().get().filter(i=>i.userId===t);if(!r.length)return console.warn("User not found"),this;const o=this.user.getId();if(o||console.warn("You should set the userId for the current instance before following a user"),r.some(i=>i.followingUserId===o))return this;const s=V("latestLeaderPresence",()=>this.getCollaborators().find(i=>i.userId===t));return zs(()=>{this.updateInstanceState({followingUserId:t},{history:"ignore"});const i=aa("update current page",()=>{const c=s.get();if(!c){this.stopFollowingUser();return}c.currentPageId!==this.getCurrentPageId()&&this.getPage(c.currentPageId)&&this.history.ignore(()=>{this.store.put([{...this.getInstanceState(),currentPageId:c.currentPageId}]),this._isLockedOnFollowingUser.set(!0)})}),a=()=>{i(),this._isLockedOnFollowingUser.set(!1),this.off("frame",l),this.off("stop-following",a)},l=()=>{if(!s.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const d=this.user.getAnimationSpeed();if(d===0){this._isLockedOnFollowingUser.set(!0);return}const h=this.getViewportPageBoundsForFollowing();if(!h){this.stopFollowingUser();return}const p=this.getViewportPageBounds(),f=Math.abs(h.minX-p.minX)+Math.abs(h.maxX-p.maxX),S=Math.abs(h.minY-p.minY)+Math.abs(h.maxY-p.maxY);if(f<this.options.followChaseViewportSnap&&S<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const g=_t(d*.5,.1,.8),x=new Z(jd(p.minX,h.minX,g),jd(p.minY,h.minY,g),jd(p.width,h.width,g),jd(p.height,h.height,g)),y=new w(-x.x,-x.y,this.getViewportScreenBounds().width/x.width);this.stopCameraAnimation(),this._setCamera(y)};this.once("stop-following",a),this.addListener("frame",l),l()}),this}stopFollowingUser(){return this.history.ignore(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")}),this}getUnorderedRenderingShapes(t){const r=[];let o=this.options.maxShapesPerPage*2,s=this.options.maxShapesPerPage;const i=this.getErasingShapeIds(),a=(c,d,h)=>{const p=this.getShape(c);if(!p)return;d*=p.opacity;let f=!1;const S=this.getShapeUtil(p);t&&(f=!h&&i.includes(c),f&&(d*=.32)),r.push({id:c,shape:p,util:S,index:o,backgroundIndex:s,opacity:d}),o+=1,s+=1;const g=this.getSortedChildIdsForParent(c);if(!g.length)return;let x=null;S.providesBackgroundForChildren(p)&&(x=s,s=o,o+=this.options.maxShapesPerPage);for(const y of g)a(y,d,h||f);x!==null&&(s=x)},l=t?[this.getCurrentPage()]:this.getPages();for(const c of l)for(const d of this.getSortedChildIdsForParent(c.id))a(d,1,!1);return r}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(W6)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(on)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(t){return this.store.get(typeof t=="string"?t:t.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getCurrentPageShapeIdsSorted(){return Array.from(this.getCurrentPageShapeIds()).sort()}getPageShapeIds(t){const r=typeof t=="string"?t:t.id,o=this.store.query.exec("shape",{parentId:{eq:r}});return this.getShapeAndDescendantIds(o.map(s=>s.id))}setCurrentPage(t){const r=typeof t=="string"?t:t.id;return this.store.has(r)?(this.stopFollowingUser(),this.complete(),this.batch(()=>this.store.put([{...this.getInstanceState(),currentPageId:r}]),{history:"record-preserveRedoStack"})):(console.error("Tried to set the current page id to a page that doesn't exist."),this)}updatePage(t){return this.getInstanceState().isReadonly?this:this.getPage(t.id)?this.batch(()=>this.store.update(t.id,o=>({...o,...t}))):this}createPage(t){return this.history.batch(()=>{if(this.getInstanceState().isReadonly||this.getPages().length>=this.options.maxPages)return;const r=this.getPages(),o=zW(t.name??"Page 1",r.map(a=>a.name));let s=t.index;(!s||r.some(a=>a.index===s))&&(s=Lo(r[r.length-1].index));const i=Qo.create({meta:{},...t,name:o,index:s});this.store.put([i])}),this}deletePage(t){const r=typeof t=="string"?t:t.id;return this.batch(()=>{if(this.getInstanceState().isReadonly)return;const o=this.getPages();if(o.length===1)return;const s=this.getPage(r);if(s){if(r===this.getCurrentPageId()){const i=o.findIndex(l=>l.id===r),a=o[i-1]??o[i+1];this.setCurrentPage(a.id)}this.store.remove([s.id])}}),this}duplicatePage(t,r=Qo.createId()){if(this.getPages().length>=this.options.maxPages)return this;const o=typeof t=="string"?t:t.id,s=this.getPage(o);if(!s)return this;const i={...this.getCamera()},a=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.batch(()=>{var d;const l=this.getPages(),c=uu(s.index,(d=l[l.indexOf(s)+1])==null?void 0:d.index);if(this.createPage({name:s.name+" Copy",id:r,index:c}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(t,r){const o=typeof t=="string"?t:t.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:o,name:r}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:(this.history.ignore(()=>this.store.put(t)),this)}updateAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:(this.history.ignore(()=>{this.store.put(t.map(r=>({...this.store.get(r.id),...r})))}),this)}deleteAssets(t){if(this.getInstanceState().isReadonly)return this;const r=typeof t[0]=="string"?t:t.map(o=>o.id);return r.length<=0?this:(this.history.ignore(()=>this.store.remove(r)),this)}getAsset(t){return this.store.get(typeof t=="string"?t:t.id)}async resolveAssetUrl(t,r){if(!t)return"";const o=this.getAsset(t);if(!o)return"";const{screenScale:s,shouldResolveToOriginalImage:i}=r,l=Math.max(.125,(h=>Math.pow(2,Math.ceil(Math.log2(h))))(s||1)),c="connection"in navigator?navigator.connection.effectiveType:null,d=this.getInstanceState().devicePixelRatio;return await this._assetOptions.get().onResolveAsset(o,{screenScale:s||1,steppedScreenScale:l,dpr:d,networkEffectiveType:c,shouldResolveToOriginalImage:i})}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",t=>this.getShapeUtil(t).getGeometry(t),(t,r)=>t.props===r.props)}getShapeGeometry(t){return this._getShapeGeometryCache().get(typeof t=="string"?t:t.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",t=>{var r,o;return(o=(r=this.getShapeUtil(t)).getHandles)==null?void 0:o.call(r,t)})}getShapeHandles(t){return this._getShapeHandlesCache().get(typeof t=="string"?t:t.id)}getShapeLocalTransform(t){const r=typeof t=="string"?t:t.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",t=>{if(In(t.parentId))return this.getShapeLocalTransform(t);const r=this._getShapePageTransformCache().get(t.parentId)??oe.Identity();return oe.Compose(r,this.getShapeLocalTransform(t))})}getShapeParentTransform(t){const r=typeof t=="string"?t:t.id,o=this.getShape(r);return!o||In(o.parentId)?oe.Identity():this._getShapePageTransformCache().get(o.parentId)??oe.Identity()}getShapePageTransform(t){const r=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(r)??oe.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",t=>{const r=this._getShapePageTransformCache().get(t.id);return r?Z.FromPoints(oe.applyToPoints(r,this.getShapeGeometry(t).vertices)):new Z})}getShapePageBounds(t){return this._getShapePageBoundsCache().get(typeof t=="string"?t:t.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",t=>{const r=this._getShapeMaskCache().get(t.id);if(!r)return;if(r.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const o=this._getShapePageTransformCache().get(t.id);return o?`polygon(${oe.applyToPoints(oe.Inverse(o),r).map(i=>`${i.x}px ${i.y}px`).join(",")})`:void 0})}getShapeClipPath(t){return this._getShapeClipPathCache().get(typeof t=="string"?t:t.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",t=>{if(In(t.parentId))return;const r=this.getShapeAncestors(t.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=_C(s,i);return a?a.map(w.Cast):[]})})}getShapeMask(t){return this._getShapeMaskCache().get(typeof t=="string"?t:t.id)}getShapeMaskedPageBounds(t){return typeof t!="string"&&(t=t.id),this._getShapeMaskedPageBoundsCache().get(t)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",t=>{const r=this._getShapePageBoundsCache().get(t.id);if(!r)return;const o=this._getShapeMaskCache().get(t.id);if(o){if(o.length===0)return;const{corners:s}=r;if(s.every((a,l)=>a&&w.Equals(a,o[l])))return r.clone();const i=_C(o,s);return i?Z.FromPoints(i):void 0}return r})}getShapeAncestors(t,r=[]){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return r;const i=s.parentId;if(In(i))return r.reverse(),r;const a=this.store.get(i);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return;const i=s.parentId;if(In(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(t,r){const o=typeof t=="string"?t:t==null?void 0:t.id,s=o&&this.getShape(o);return s?s.parentId===r?!0:this.hasAncestor(this.getShapeParent(s),r):!1}findCommonAncestor(t,r){var c;if(t.length===0)return;const o=typeof t[0]=="string"?t:t.map(d=>d.id),s=me(o.map(d=>this.getShape(d)));if(s.length===1){const d=s[0].parentId;return In(d)?void 0:r?(c=this.findShapeAncestor(s[0],r))==null?void 0:c.id:d}const[i,...a]=s;let l=this.getShapeParent(i);for(;l;){if(r&&!r(l)){l=this.getShapeParent(l);continue}if(a.every(d=>this.hasAncestor(d,l.id)))return l.id;l=this.getShapeParent(l)}}isShapeOrAncestorLocked(t){const r=typeof t=="string"?this.getShape(t):t;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}_notVisibleShapes(){return VW(this)}getCulledShapes(){const t=this._notVisibleShapes().get(),r=this.getSelectedShapeIds(),o=this.getEditingShapeId(),s=new Set(t);return o&&s.delete(o),r.forEach(i=>{s.delete(i)}),s}getCurrentPageBounds(){let t;return this.getCurrentPageShapeIdsSorted().forEach(r=>{const o=this.getShapeMaskedPageBounds(r);o&&(t?t=t.expand(o):t=o.clone())}),t}getSelectedShapeAtPoint(t){const r=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(o=>o.type!=="group"&&r.includes(o.id)).reverse().find(o=>this.isPointInShape(o,t,{hitInside:!0,margin:0}))}getShapeAtPoint(t,r={}){const o=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:i,margin:a=0,hitLocked:l=!1,hitLabels:c=!1,hitInside:d=!1,hitFrameInside:h=!1}=r;let p=1/0,f=null,S=1/0,g=null;const x=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(y=>{if(y.isLocked&&!l||this.isShapeOfType(y,"group"))return!1;const v=this.getShapeMask(y);return v&&!tr(t,v)?!1:i?i(y):!0});for(let y=x.length-1;y>=0;y--){const v=x[y],b=this.getShapeGeometry(v),E=b instanceof Hr,I=this.getPointInShapeSpace(v,t);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const k of b.children)if(k.isLabel&&k.isPointInBounds(I))return v}if(this.isShapeOfType(v,"frame")){const k=b.distanceToPoint(I,d);if(Math.abs(k)<=a)return g||v;if(b.hitTestPoint(I,0,!0))return g||f||(h?v:void 0);continue}let C;if(E){let k=1/0;for(const T of b.children){if(T.isLabel&&!c)continue;const O=T.distanceToPoint(I,d);O<k&&(k=O)}C=k}else a===0&&(b.bounds.w<1||b.bounds.h<1)||b.bounds.containsPoint(I,a)?C=b.distanceToPoint(I,d):C=1/0;if(b.isClosed){if(C<=a){if(b.isFilled||E&&b.children[0].isFilled)return g||v;if(this.getShapePageBounds(v).contains(s))continue;if(Math.abs(C)<a)Math.abs(C)<S&&(S=Math.abs(C),g=v);else if(!g){const{area:k}=b;k<p&&(p=k,f=v)}}}else if(C<this.options.hitTestMargin/o)return v}return g||f||void 0}getShapesAtPoint(t,r={}){return this.getCurrentPageShapes().filter(o=>this.isPointInShape(o,t,r))}isPointInShape(t,r,o={}){const{hitInside:s=!1,margin:i=0}=o,a=typeof t=="string"?t:t.id,l=this.getShapeMask(a);return l&&!tr(r,l)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(t,r),i,s)}getPointInShapeSpace(t,r){const o=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(o).clone().invert().applyToPoint(r)}getPointInParentSpace(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return new w(0,0);if(In(s.parentId))return w.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):w.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),t=>this.store.get(t))}getCurrentPageShapesSorted(){const t=[],r=this.getSortedChildIdsForParent(this.getCurrentPageId());for(let o=0,s=r.length;o<s;o++)A2(this,r[o],t);return t}getCurrentPageRenderingShapesSorted(){const t=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:r})=>!t.has(r))}isShapeOfType(t,r){const o=typeof t=="string"?this.getShape(t):t;return o?o.type===r:!1}getShape(t){const r=typeof t=="string"?t:t.id;if(kn(r))return this.store.get(r)}getShapeParent(t){const r=typeof t=="string"?t:t==null?void 0:t.id;if(!r)return;const o=this.getShape(r);if(!(o===void 0||!kn(o.parentId)))return this.store.get(o.parentId)}getShapeNearestSibling(t,r){return r?r.parentId===t.parentId?r:this.findShapeAncestor(r,s=>s.parentId===t.parentId):void 0}isShapeInPage(t,r=this.getCurrentPageId()){const o=typeof t=="string"?t:t.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(t){const r=typeof t=="string"?t:t==null?void 0:t.id,o=r&&this.getShape(r);if(o)return In(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(S=>S.id);if(s.length===0)return this;const i=[],a=In(r)?oe.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const d=me(this.getSortedChildIdsForParent(r).map(S=>this.getShape(S)));if(o){const S=d.find(g=>g.index===o);if(S){const g=d[d.indexOf(S)+1];g?c=gl(o,g.index,s.length):c=zm(o,s.length)}else{const g=d.sort(on).find(x=>x.index>o);g?c=gl(o,g.index,s.length):c=zm(o,s.length)}}else{const S=d.length&&d[d.length-1];c=S?zm(S.index,s.length):du(s.length)}const h=a.clone().invert(),p=me(s.map(S=>this.getShape(S))),f=p.filter(S=>S.isLocked);f.length&&this.updateShapes(f.map(({id:S,type:g})=>({id:S,type:g,isLocked:!1})));for(let S=0;S<p.length;S++){const g=p[S],x=this.getShapePageTransform(g);if(!x)continue;const y=x.point();if(!y)continue;const v=h.applyToPoint(y),b=x.rotation()-l;i.push({id:g.id,type:g.type,parentId:r,x:v.x,y:v.y,rotation:b,index:c[S],isLocked:g.isLocked})}return this.updateShapes(i),this}getHighestIndexForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const s=this.getShape(o[o.length-1]);return Lo(s.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o||Ho}visitDescendants(t,r){const o=typeof t=="string"?t:t.id,s=this.getSortedChildIdsForParent(o);for(const i of s)r(i)!==!1&&this.visitDescendants(i,r);return this}getShapeAndDescendantIds(t){const r=new Set;for(const o of t.map(s=>this.getShape(s)).sort(on))r.add(o.id),this.visitDescendants(o,s=>{r.add(s)});return r}getDroppingOverShape(t,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(l=>l.id===i.id||this.hasAncestor(i,l.id)))continue;const a=this.getShapeMaskedPageBounds(i.id);if(a&&a.containsPoint(t)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,t),0,!0))return i}}getOutermostSelectableShape(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);let i=s,a=s;const l=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(l==null?void 0:l.id)!==a.id&&!this.hasAncestor(l,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((l==null?void 0:l.id)===a.id)break;a=this.getShapeParent(a)}return i}_getBindingsIndexCache(){const t=WW(this);return this.store.createComputedCache("bindingsIndex",r=>t.get().get(r.id))}getBinding(t){return this.store.get(t)}getBindingsFromShape(t,r){const o=typeof t=="string"?t:t.id;return this.getBindingsInvolvingShape(o).filter(s=>s.fromId===o&&s.type===r)}getBindingsToShape(t,r){const o=typeof t=="string"?t:t.id;return this.getBindingsInvolvingShape(o).filter(s=>s.toId===o&&s.type===r)}getBindingsInvolvingShape(t,r){const o=typeof t=="string"?t:t.id,s=this._getBindingsIndexCache().get(o)??Ho;return r?s.filter(i=>i.type===r):s}createBindings(t){const r=[];for(const o of t){const s=this.getShape(o.fromId),i=this.getShape(o.toId);if(!s||!i||!this.canBindShapes({fromShape:s,toShape:i,binding:o}))continue;const l=this.getBindingUtil(o.type).getDefaultProps(),c=this.store.schema.types.binding.create({...o,id:o.id??Ri(),props:{...l,...o.props}});r.push(c)}return this.store.put(r),this}createBinding(t){return this.createBindings([t])}updateBindings(t){const r=[];for(const o of t){if(!o)continue;const s=this.getBinding(o.id);if(!s)continue;const i=jo(s,o);if(i===s)continue;const a=this.getShape(i.fromId),l=this.getShape(i.toId);!a||!l||this.canBindShapes({fromShape:a,toShape:l,binding:i})&&r.push(i)}return this.store.put(r),this}updateBinding(t){return this.updateBindings([t])}deleteBindings(t,{isolateShapes:r=!1}={}){const o=t.map(s=>typeof s=="string"?s:s.id);return r?this.store.atomic(()=>{var s,i;for(const a of o){const l=this.getBinding(a);if(!l)continue;const c=this.getBindingUtil(l);(s=c.onBeforeIsolateFromShape)==null||s.call(c,{binding:l,removedShape:this.getShape(l.toId)}),(i=c.onBeforeIsolateToShape)==null||i.call(c,{binding:l,removedShape:this.getShape(l.fromId)}),this.store.remove([a])}}):this.store.remove(o),this}deleteBinding(t,r){return this.deleteBindings([t],r)}canBindShapes({fromShape:t,toShape:r,binding:o}){const s=typeof t=="string"?t:t.type,i=typeof r=="string"?r:r.type,a=typeof o=="string"?o:o.type,l={fromShapeType:s,toShapeType:i,bindingType:a};return s===i?this.getShapeUtil(s).canBind(l):this.getShapeUtil(s).canBind(l)&&this.getShapeUtil(i).canBind(l)}rotateShapesBy(t,r){if((typeof t[0]=="string"?t:t.map(i=>i.id)).length<=0)return this;const s=_2({editor:this});return s?(Oh({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(t,r){var i,a,l;let o=t;const s=this.getShapeUtil(t);return o=jo(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=jo(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=jo(o,((a=s.onTranslate)==null?void 0:a.call(s,t,o))??void 0),o=jo(o,((l=s.onTranslateEnd)==null?void 0:l.call(s,t,o))??void 0),o}nudgeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(i=>i.id);if(o.length<=0)return this;const s=[];for(const i of o){const a=this.getShape(i),l=w.From(r),c=this.getShapeParentTransform(a);c&&l.rot(-c.rotation()),s.push(this.getChangesToTranslateShape(a,l.add(a)))}return this.updateShapes(s),this}duplicateShapes(t,r){return this.history.batch(()=>{const o=typeof t[0]=="string"?t:t.map(p=>p.id);if(o.length<=0)return this;const s=new Set(o),i=this.getShapeAndDescendantIds(o),a=[...i].reverse(),l=new Map;for(const p of i)l.set(p,$e());const{shapesToCreate:c,bindingsToCreate:d}=DC(this,i,p=>{const f=[];for(const g of p){const x=this.getBinding(g);if(!x)continue;const y=Ri();f.push({...x,id:y,fromId:Sr(l.get(x.fromId)),toId:Sr(l.get(x.toId))})}const S=[];for(const g of a){const x=Sr(l.get(g)),y=this.getShape(g);if(!y)continue;let v=0,b=0;if(r&&s.has(g)){const _=this.getShapeParentTransform(y),j=new w(r.x,r.y).rot(-_.rotation());v=j.x,b=j.y}const E=y.parentId,I=this.getSortedChildIdsForParent(E),C=I.indexOf(y.id),k=I[C+1],T=k?this.getShape(k):null,O=T?uu(y.index,T.index):Lo(y.index);S.push({...y,id:x,x:y.x+v,y:y.y+b,index:O,parentId:l.get(y.parentId)??y.parentId})}return{shapesToCreate:S,bindingsToCreate:f}});if(c.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Hd(this);return}if(this.createShapes(c),this.createBindings(d),this.setSelectedShapes(me(o.map(p=>l.get(p)))),r!==void 0){const p=this.getSelectionPageBounds(),f=this.getViewportPageBounds();p&&!f.contains(p)&&this.centerOnPoint(p.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.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>this.options.maxShapesPerPage)return Hd(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(t){const r=typeof t[0]=="string"?t:t.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 l=this.getShape(a);l&&(i.push(l),l.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(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Ud(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Ud(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Ud(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Ud(this,"toFront",r);return o&&this.updateShapes(o),this}flipShapes(t,r){const o=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;let s=me(o.map(a=>this.getShape(a)));if(!s.length)return this;s=me(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(l=>this.getShape(l)):a).flat());const i=Z.Common(me(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const l=this.getShapeGeometry(a).bounds,c=this.getShapePageTransform(a.id);c&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:l,initialPageTransform:c,initialShape:a,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(a).isAspectRatioLocked(a),scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(x=>x.id);if(this.getInstanceState().isReadonly)return this;const i=s.map(x=>this.getShape(x)).filter(x=>x?this.getShapeUtil(x).canBeLaidOut(x):!1),a=i.length;if(o===0&&a<3||a<2)return this;const l=Object.fromEntries(i.map(x=>[x.id,this.getShapePageBounds(x)]));let c,d,h,p;r==="horizontal"?(c="x",d="minX",h="maxX",p="width"):(c="y",d="minY",h="maxY",p="height");let f;if(o===0){const x=[];i.sort((v,b)=>l[v.id][d]-l[b.id][d]);for(let v=0;v<a-1;v++){const b=i[v],E=i[v+1],I=l[b.id],k=l[E.id][d]-I[h],T=x.find(O=>O.gap===k);T?T.count++:x.push({gap:k,count:1})}let y=0;x.forEach(v=>{v.count>y&&(y=v.count,f=v.gap)}),y===1&&(f=Math.max(0,x.reduce((v,b)=>v+b.gap*b.count,0)/(a-1)))}else f=o;const S=[];let g=l[i[0].id][h];return i.forEach((x,y)=>{var C,k;if(y===0)return;const v={x:0,y:0};v[c]=g+f-l[x.id][c];const b=this.getShapeParent(x),E=b?w.Rot(v,-this.getShapePageTransform(b).decompose().rotation):v,I=(k=(C=this.getShapeUtil(x)).onTranslateStart)==null?void 0:k.call(C,x);S.push(I?{...I,[c]:x[c]+E[c]}:{id:x.id,type:x.type,[c]:x[c]+E[c]}),g+=l[x.id][p]+f}),this.updateShapes(S),this}packShapes(t,r){var k,T;const o=typeof t[0]=="string"?t:t.map(O=>O.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=o.map(O=>this.getShape(O)).filter(O=>O?this.getShapeUtil(O).canBeLaidOut(O):!1),i={},a={};let l,c,d=0;for(let O=0;O<s.length;O++)l=s[O],c=this.getShapePageBounds(l),i[l.id]=c,a[l.id]=c.clone(),d+=c.width*c.height;const h=Z.Common(me(Object.values(i))),p=h.width;s.sort((O,_)=>i[_.id].height-i[O.id].height);const f=Math.max(Math.ceil(Math.sqrt(d/.95)),p),S=[new Z(h.x,h.y,f,1/0)];let g=0,x=0,y,v;for(let O=0;O<s.length;O++){l=s[O],c=a[l.id];for(let _=S.length-1;_>=0;_--)if(y=S[_],!(c.width>y.width||c.height>y.height)){c.x=y.x,c.y=y.y,x=Math.max(x,c.maxY),g=Math.max(g,c.maxX),c.width===y.width&&c.height===y.height?(v=S.pop(),_<S.length&&(S[_]=v)):c.height===y.height?(y.x+=c.width+r,y.width-=c.width+r):c.width===y.width?(y.y+=c.height+r,y.height-=c.height+r):(S.push(new Z(y.x+(c.width+r),y.y,y.width-(c.width+r),c.height)),y.y+=c.height+r,y.height-=c.height+r);break}}const b=Z.Common(Object.values(a)),E=w.Sub(h.center,b.center);let I;const C=[];for(let O=0;O<s.length;O++){l=s[O],c=i[l.id],I=a[l.id];const _=w.Sub(I.point,c.point).add(E),j=this.getShapeParentTransform(l);j&&_.rot(-j.rotation());const L={id:l.id,type:l.type,x:l.x+_.x,y:l.y+_.y},A=(T=(k=this.getShapeUtil(l)).onTranslateStart)==null?void 0:T.call(k,{...l,...L});A?C.push({...L,...A}):C.push(L)}return C.length&&this.updateShapes(C),this}alignShapes(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=me(o.map(c=>this.getShape(c))),i=Object.fromEntries(s.map(c=>[c.id,this.getShapePageBounds(c)])),a=Z.Common(me(Object.values(i))),l=[];return s.forEach(c=>{const d=i[c.id];if(!d)return;const h={x:0,y:0};switch(r){case"top":{h.y=a.minY-d.minY;break}case"center-vertical":{h.y=a.midY-d.minY-d.height/2;break}case"bottom":{h.y=a.maxY-d.minY-d.height;break}case"left":{h.x=a.minX-d.minX;break}case"center-horizontal":{h.x=a.midX-d.minX-d.width/2;break}case"right":{h.x=a.maxX-d.minX-d.width;break}}const p=this.getShapeParent(c),f=p?w.Rot(h,-this.getShapePageTransform(p).decompose().rotation):h;l.push(this.getChangesToTranslateShape(c,w.Add(c,f)))}),this.updateShapes(l),this}distributeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(b=>b.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=me(o.map(b=>this.getShape(b))),a=Object.fromEntries(i.map(b=>[b.id,this.getShapePageBounds(b)]));let l,c,d,h,p;r==="horizontal"?(l="x",c="minX",d="maxX",h="midX",p="width"):(l="y",c="minY",d="maxY",h="midY",p="height");const f=[],S=i.sort((b,E)=>a[b.id][c]-a[E.id][c])[0],g=i.sort((b,E)=>a[E.id][d]-a[b.id][d])[0],x=a[S.id][h],y=(a[g.id][h]-x)/(s-1),v=x+y;return i.filter(b=>b!==S&&b!==g).sort((b,E)=>a[b.id][h]-a[E.id][h]).forEach((b,E)=>{const I={x:0,y:0};I[l]=v+y*E-a[b.id][p]/2-a[b.id][l];const C=this.getShapeParent(b),k=C?w.Rot(I,-this.getShapePageTransform(C).rotation()):I;f.push(this.getChangesToTranslateShape(b,w.Add(b,k)))}),this.updateShapes(f),this}stretchShapes(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=me(o.map(c=>this.getShape(c))),i=Object.fromEntries(o.map(c=>[c,this.getShapeGeometry(c).bounds])),a=Object.fromEntries(o.map(c=>[c,this.getShapePageBounds(c)])),l=Z.Common(me(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const c of s){if(this.getShapePageTransform(c).rotation()%Re)continue;const h=i[c.id],p=a[c.id],f=new w(0,l.minY-p.minY),S=this.getShapeParentTransform(c);S&&f.rot(-S.rotation());const{x:g,y:x}=w.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:g,y:x}]);const y=new w(1,l.height/p.height);this.resizeShape(c.id,y,{initialBounds:h,scaleOrigin:new w(p.center.x,l.minY),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const c of s){const d=i[c.id],h=a[c.id];if(this.getShapePageTransform(c).rotation()%Re)continue;const f=new w(l.minX-h.minX,0),S=this.getShapeParentTransform(c);S&&f.rot(-S.rotation());const{x:g,y:x}=w.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:g,y:x}]);const y=new w(l.width/h.width,1);this.resizeShape(c.id,y,{initialBounds:d,scaleOrigin:new w(l.minX,h.center.y),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}}return this}resizeShape(t,r,o={}){var S,g,x;const s=typeof t=="string"?t:t.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new w(1,r.y)),Number.isFinite(r.y)||(r=new w(r.x,1));const i=o.initialShape??this.getShape(s);if(!i)return this;const a=o.scaleOrigin??((S=this.getShapePageBounds(s))==null?void 0:S.center);if(!a)return this;const l=o.initialPageTransform?oe.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!l)return this;const c=l.rotation();if(c==null)return this;const d=o.scaleAxisRotation??c,h=o.initialBounds??this.getShapeGeometry(s).bounds;if(!h)return this;const p=o.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!UM(c,d))return this._resizeUnalignedShape(s,r,{...o,initialBounds:h,scaleOrigin:a,scaleAxisRotation:d,initialPageTransform:l,isAspectRatioLocked:p,initialShape:i});const f=this.getShapeUtil(i);if(p&&(Math.abs(r.x)>Math.abs(r.y)?r=new w(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new w(Math.sign(r.x)*Math.abs(r.y),r.y)),f.onResize&&f.canResize(i)){const y=this._scalePagePoint(oe.applyToPoint(l,new w(0,0)),a,r,d),v=this.getPointInParentSpace(i.id,y),b=new w(r.x,r.y),E=Us((c-d)%Math.PI,0);b.x=E?r.x:r.y,b.y=E?r.y:r.x;const I=oe.applyToPoint(l,new w),{x:C,y:k}=this.getPointInParentSpace(i.id,I);let T=i;o.skipStartAndEndCallbacks||(T=jo(i,((g=f.onResizeStart)==null?void 0:g.call(f,i))??void 0)),T=jo(T,{id:s,type:i.type,x:v.x,y:v.y,...f.onResize({...i,x:C,y:k},{newPoint:v,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:b.x,scaleY:b.y,initialBounds:h,initialShape:i})}),o.skipStartAndEndCallbacks||(T=jo(T,((x=f.onResizeEnd)==null?void 0:x.call(f,i,T))??void 0)),this.updateShapes([T])}else{const y=oe.applyToPoint(l,h.center),v=this._scalePagePoint(y,a,r,d),b=this.getPointInParentSpace(i.id,y),E=this.getPointInParentSpace(i.id,v),I=w.Sub(E,b);this.updateShapes([{id:s,type:i.type,x:i.x+I.x,y:i.y+I.y}])}return this}_scalePagePoint(t,r,o,s){const i=w.RotWith(t,r,-s).sub(r),a=w.MulV(i,o);return w.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(t,r,o){const{type:s}=o.initialShape,i=new w(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(t,i,{initialShape:o.initialShape,initialBounds:o.initialBounds,isAspectRatioLocked:o.isAspectRatioLocked}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:y}=oe.Decompose(o.initialPageTransform);y-=2*y,this.updateShapes([{id:t,type:s,rotation:y}])}const a=oe.applyToPoint(o.initialPageTransform,o.initialBounds.center),l=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),c=this.getShapePageBounds(t),d=this.getShapePageTransform(t),h=c.center,p=d.point();if(!h||!p)return this;const f=w.Sub(l,h),S=w.Add(p,f),{x:g,y:x}=this.getPointInParentSpace(t,S);return this.updateShapes([{id:t,type:s,x:g,y:x}]),this}getInitialMetaForShape(t){return{}}createShape(t){return this.createShapes([t]),this}createShapes(t){if(!Array.isArray(t))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getInstanceState().isReadonly)return this;if(t.length<=0)return this;const r=this.getCurrentPageShapeIds();if(t.length+r.size>this.options.maxShapesPerPage)return Hd(this),this;const s=this.getFocusedGroupId();return this.batch(()=>{var h,p;const i=this.getCurrentPageShapesSorted(),a=t.map(f=>{if(f.id||(f={id:$e(),...f}),!f.parentId||!(this.store.has(f.parentId)||t.some(S=>S.id===f.parentId))){let S=this.getFocusedGroupId();for(let x=i.length-1;x>=0;x--){const y=i[x];if(this.getShapeUtil(y).canReceiveNewChildrenOfType(y,f.type)&&this.isPointInShape(y,{x:f.x??0,y:f.y??0},{margin:0,hitInside:!0})){S=y.id;break}}const g=f.parentId;if(S===f.id&&(S=s),S!==g&&(f={...f},f.parentId=S,kn(S))){const x=this.getPointInShapeSpace(this.getShape(S),{x:f.x??0,y:f.y??0});f.x=x.x,f.y=x.y,f.rotation=-this.getShapePageTransform(S).rotation()+(f.rotation??0)}}return f}),l=new Map,c=[],{opacityForNextShape:d}=this.getInstanceState();for(const f of a){const S=this.getShapeUtil(f);let g=f.index;if(!g){const b=f.parentId??s;l.has(b)||l.set(b,this.getHighestIndexForParent(b)),g=l.get(b),l.set(b,Lo(g))}const x=S.getDefaultProps();for(const[b,E]of this.styleProps[f.type])x[E]=this.getStyleForNextShape(b);let y=this.store.schema.types.shape.create({...f,index:g,opacity:f.opacity??d,parentId:f.parentId??s,props:"props"in f?{...x,...f.props}:x});if(y.index===void 0)throw Error("no index!");const v=(p=(h=this.getShapeUtil(y)).onBeforeCreate)==null?void 0:p.call(h,y);v&&(y=v),c.push(y)}c.forEach(f=>{f.meta={...this.getInitialMetaForShape(f),...f.meta}}),this.store.put(c)})}animateShape(t,r={animation:Gm}){return this.animateShapes([t],r)}animateShapes(t,r={animation:Gm}){if(!r.animation)return this;const{duration:o=500,easing:s=jt.linear}=r.animation,i=ot();let a=o,l;const c=[];let d,h;for(let S=0,g=t.length;S<g;S++){if(d=t[S],!d)continue;h={partial:d,values:[]};const x=this.getShape(d.id);if(x){for(const y of["x","y","rotation"])d[y]!==void 0&&x[y]!==d[y]&&h.values.push({prop:y,from:x[y],to:d[y]});c.push(h),this.animatingShapes.set(x.id,i)}}let p;const f=S=>{if(a-=S,a<0){const{animatingShapes:v}=this,b=t.filter(E=>E&&v.get(E.id)===i);b.length&&this.updateShapes(b),this.off("tick",f);return}l=s(1-a/o);const{animatingShapes:g}=this,x=[];let y;for(let v=0,b=c.length;v<b;v++)p=c[v],y=g.get(p.partial.id),y===i&&x.push({id:p.partial.id,type:p.partial.type,...p.values.reduce((E,{prop:I,from:C,to:k})=>(E[I]=C+(k-C)*l,E),{})});this._updateShapes(x)};return this.on("tick",f),this}groupShapes(t,r={}){var g;const{groupId:o=$e(),select:s=!0}=r;if(!Array.isArray(t))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const i=typeof t[0]=="string"?t:t.map(x=>x.id);if(i.length<=1)return this;const a=me(this._getUnlockedShapeIds(i).map(x=>this.getShape(x))),l=a.sort(on).map(x=>x.id),c=Z.Common(me(a.map(x=>this.getShapePageBounds(x)))),{x:d,y:h}=c.point,p=this.findCommonAncestor(a)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const f=a.filter(x=>x.parentId===p).sort(on),S=(g=f[f.length-1])==null?void 0:g.index;return this.batch(()=>{this.createShapes([{id:o,type:"group",parentId:p,index:S,x:d,y:h,opacity:1,props:{}}]),this.reparentShapes(l,o),s&&this.select(o)}),this}ungroupShapes(t,r={}){const{select:o=!0}=r,s=typeof t[0]=="string"?t:t.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(s.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const i=new Set,a=[];return me(s.map(l=>this.getShape(l))).forEach(l=>{this.isShapeOfType(l,"group")?a.push(l):i.add(l.id)}),a.length===0?this:(this.batch(()=>{let l;for(let c=0,d=a.length;c<d;c++){l=a[c];const h=this.getSortedChildIdsForParent(l.id);for(let p=0,f=h.length;p<f;p++)i.add(h[p]);this.reparentShapes(h,l.parentId,l.index)}this.deleteShapes(a.map(c=>c.id)),o&&this.select(...i)}),this)}updateShape(t){return this.updateShapes([t]),this}updateShapes(t){const r=Array(t.length);for(let o=0,s=t.length;o<s;o++){const i=t[o];if(!i)continue;const a=this.getShape(i.id);a&&(this.isShapeOrAncestorLocked(a)&&!Object.hasOwn(i,"isLocked")||(this.animatingShapes.delete(i.id),r.push(i)))}return this._updateShapes(r),this}_getUnlockedShapeIds(t){return t.filter(r=>{var o;return!((o=this.getShape(r))!=null&&o.isLocked)})}deleteShapes(t){if(!Array.isArray(t))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");const r=this._getUnlockedShapeIds(typeof t[0]=="string"?t:t.map(i=>i.id));if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;const o=new Set(r);for(const i of r)this.visitDescendants(i,a=>{o.add(a)});const s=[...o];return this.batch(()=>this.store.remove(s))}deleteShape(t){return this.deleteShapes([typeof t=="string"?t:t.id]),this}_extractSharedStyles(t,r){if(this.isShapeOfType(t,"group")){const o=this._parentIdsToChildIds.get()[t.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[t.type])r.applyValue(o,An(t.props,s))}_getSelectionSharedStyles(){const t=this.getSelectedShapes(),r=new vv;for(const o of t)this._extractSharedStyles(o,r);return r}getStyleForNextShape(t){const r=this.getInstanceState().stylesForNextShape[t.id];return r===void 0?t.defaultValue:r}getShapeStyleIfExists(t,r){const o=this.styleProps[t.type].get(r);if(o!==void 0)return An(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const t=this.root.getCurrent(),r=new vv;if(!t)return r;if(t.shapeType)for(const o of this.styleProps[t.shapeType].keys())r.applyValue(o,this.getStyleForNextShape(o));return r}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const t=[],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 t.push(i)};for(const s of this.getSelectedShapeIds())r(s);let o=null;for(const s of t)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(t,r){return this.updateInstanceState({opacityForNextShape:t},r),this}setOpacityForSelectedShapes(t){const r=this.getSelectedShapes();if(r.length>0){const o=[],s=i=>{if(this.isShapeOfType(i,"group")){const a=this.getSortedChildIdsForParent(i);for(const l of a)s(this.getShape(l))}else o.push(i)};for(const i of r)s(i);this.updateShapes(o.map(i=>({id:i.id,type:i.type,opacity:t})))}return this}setStyleForNextShapes(t,r,o){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[t.id]:r}},o),this}setStyleForSelectedShapes(t,r){const o=this.getSelectedShapes();if(o.length>0){const s=[],i=a=>{if(this.isShapeOfType(a,"group")){const l=this.getSortedChildIdsForParent(a.id);for(const c of l)i(this.getShape(c))}else{const l=this.getShapeUtil(a),c=this.styleProps[a.type].get(t);if(c){const d={id:a.id,type:a.type,props:{[c]:r}};s.push({util:l,originalShape:a,updatePartial:d})}}};for(const a of o)i(a);this.updateShapes(s.map(({updatePartial:a})=>a))}return this}registerExternalAssetHandler(t,r){return this.externalAssetContentHandlers[t]=r,this}async getAssetForExternalContent(t){var r,o;return await((o=(r=this.externalAssetContentHandlers)[t.type])==null?void 0:o.call(r,t))}hasExternalAssetHandler(t){return!!this.externalAssetContentHandlers[t]}registerExternalContentHandler(t,r){return this.externalContentHandlers[t]=r,this}async putExternalContent(t){var r,o;return(o=(r=this.externalContentHandlers)[t.type])==null?void 0:o.call(r,t)}getContentFromCurrentPage(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id);if(!r||r.length===0)return;const o=this.getShapeAndDescendantIds(r);return DC(this,o,s=>{const i=[];for(const h of s){const p=this.getBinding(h);p&&i.push(p)}const a=[],l=[];for(const h of o){const p=this.getShape(h);if(!p)continue;if(!o.has(p.parentId)){const S=this.getShapePageTransform(p.id),g=S.point();l.push({...p,x:g.x,y:g.y,rotation:S.rotation(),parentId:this.getCurrentPageId()}),a.push(p.id)}else l.push(p)}const c=[],d=new Set;for(const h of l){if(!("assetId"in h.props))continue;const p=h.props.assetId;if(!p||d.has(p))continue;d.add(p);const f=this.getAsset(p);f&&c.push(f)}return{schema:this.store.schema.serialize(),shapes:l,rootShapeIds:a,bindings:i,assets:c}})}async resolveAssetsInContent(t){if(!t)return;const r=[];return await Promise.allSettled(t.assets.map(async o=>{var s,i;if((o.type==="image"||o.type==="video")&&!((s=o.props.src)!=null&&s.startsWith("data:image"))&&!((i=o.props.src)!=null&&i.startsWith("http"))){const a=rt(o),l=await this._assetOptions.get().onResolveAsset(o,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginalImage:!0});a.props.src=await Oi.blobToDataUrl(await yo(l).then(c=>c.blob())),r.push(a)}else r.push(o)})),t.assets=r,t}putContentOntoCurrentPage(t,r={}){var j,L;if(this.getInstanceState().isReadonly)return this;if(!t.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 l=this.getCurrentPageId(),{rootShapeIds:c}=t,d=[],h=[],p=[],f={store:{...Object.fromEntries(t.assets.map(A=>[A.id,A])),...Object.fromEntries(t.shapes.map(A=>[A.id,A])),...Object.fromEntries(((j=t.bindings)==null?void 0:j.map(A=>[A.id,A]))??[])},schema:t.schema},S=this.store.schema.migrateStoreSnapshot(f);if(S.type==="error")throw Error("Could not put content: could not migrate content");for(const A of Object.values(S.value))switch(A.typeName){case"asset":{d.push(A);break}case"shape":{h.push(A);break}case"binding":{p.push(A);break}}const g=new Map(s?h.map(A=>[A.id,A.id]):h.map(A=>[A.id,$e()])),x=new Map(s?p.map(A=>[A.id,A.id]):p.map(A=>[A.id,Ri()]));let y=this.getCurrentPageId(),v=1/0,b=[];for(const A of this.getSelectedShapes()){if(v===0)break;const R=this.isShapeOfType(A,"frame"),F=this.getShapeAncestors(A);R&&F.push(A);const W=R?F.length+1:F.length;if(W<v)v=W,b=F,y=R?A.id:A.parentId;else if(W===v){if(b.length!==F.length)throw Error(`Ancestors: ${b.length} !== ${F.length}`);if(b.length===0){y=l;break}else{y=l;for(let K=0;K<b.length&&F[K]===b[K];K++)y=F[K].id}}}let E=!1;if(!In(y)){const A=this.getShape(y);if(A){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(A)))y=l;else if(c.length===1){const R=h.find(F=>F.id===c[0]);this.isShapeOfType(A,"frame")&&this.isShapeOfType(R,"frame")&&R.props.w===(A==null?void 0:A.props.w)&&R.props.h===(A==null?void 0:A.props.h)&&(E=!0)}}else y=l}E||(E=g.has(y)),E&&(y=this.getShape(y).parentId);let I=this.getHighestIndexForParent(y);const C=[],k=h.map(A=>{const R=g.get(A.id),F={...A,id:R};return c.includes(A.id)&&(F.parentId=l,C.push(F)),g.has(F.parentId)?F.parentId=g.get(A.parentId):(c.push(F.id),F.index=I,I=Lo(I)),F});if(k.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Hd(this),this;const T=p.map(A=>({...A,id:Sr(x.get(A.id)),fromId:Sr(g.get(A.fromId)),toId:Sr(g.get(A.toId))})),O=[],_=[];for(const A of d)this.store.has(A.id)||((A.type==="image"||A.type==="video")&&((L=A.props.src)!=null&&L.startsWith("data:image"))&&(_.push(rt(A)),A.props.src=null),O.push(A));return Promise.allSettled(_.map(async A=>{const R=await NW(A.props.src,A.props.name,A.props.mimeType??"image/png"),F=await this.getAssetForExternalContent({type:"file",file:R});if(!F){this.deleteAssets([A.id]);return}this.updateAssets([{...F,id:A.id}])})),this.batch(()=>{O.length>0&&this.createAssets(O),this.createShapes(k),this.createBindings(T),o&&this.select(...C.map(K=>K.id)),y!==l&&this.reparentShapes(C.map(K=>K.id),y);const A=k.map(K=>this.getShape(K.id)),R=Z.Common(A.map(K=>this.getShapePageBounds(K)));if(a===void 0)if(In(y)){const K=this.getViewportPageBounds();i||K.includes(Z.From(R))?a=R.center:a=K.center}else{const K=this.getShape(y);a=oe.applyToPoint(this.getShapePageTransform(K),this.getShapeGeometry(K).bounds.center)}if(C.length===1){const K=C[0];if(this.isShapeOfType(K,"frame"))for(;this.getShapesAtPoint(a).some(z=>this.isShapeOfType(z,"frame")&&z.props.w===K.props.w&&z.props.h===K.props.h);)a.x+=R.w+16}const F=Z.Common(me(C.map(({id:K})=>this.getShapePageBounds(K)))).center,W=w.Sub(a,F);this.updateShapes(C.map(({id:K})=>{const z=this.getShape(K),U=this.getShapeParentTransform(K).decompose().rotation,X=w.Rot(W,-U);return{id:z.id,type:z.type,x:z.x+X.x,y:z.y+X.y}}))}),this}async getSvgElement(t,r={}){const o=await ZW(this,t,r);if(!o)return;const s=document.createDocumentFragment(),i=w_(s);ra.flushSync(()=>{i.render(o.jsx)});const a=s.firstElementChild;return st(a instanceof SVGSVGElement,"Expected an SVG element"),i.unmount(),{svg:a,width:o.width,height:o.height}}async getSvgString(t,r={}){const o=await this.getSvgElement(t,r);return o?{svg:new XMLSerializer().serializeToString(o.svg),width:o.width,height:o.height}:void 0}async getSvg(t,r={}){const o=await this.getSvgElement(t,r);if(o)return o.svg}_updateInputsFromEvent(t){const{pointerVelocity:r,previousScreenPoint:o,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:l}=this.store.unsafeGetWithoutCapture(gn),{x:c,y:d,z:h}=this.store.unsafeGetWithoutCapture(this.getCameraId()),p=t.point.x-l.x,f=t.point.y-l.y,S=t.point.z??.5;o.setTo(i),s.setTo(a),i.set(p,f);const g=p/h-c,x=f/h-d;isFinite(g)&&isFinite(x)&&a.set(g,x,S),this.inputs.isPen=t.type==="pointer"&&t.isPen,(t.name==="pointer_down"||this.inputs.isPinching)&&(r.set(0,0),this.inputs.originScreenPoint.setTo(i),this.inputs.originPagePoint.setTo(a)),this.history.ignore(()=>{var y;this.store.put([{id:of,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===aC.CAMERA_MOVE?((y=this.store.unsafeGetWithoutCapture(of))==null?void 0:y.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}focus({focusContainer:t=!0}={}){return t&&this.focusManager.focus(),this.updateInstanceState({isFocused:!0}),this}blur({blurContainer:t=!0}={}){return this.getIsFocused()?(t?this.focusManager.blur():this.complete(),this.updateInstanceState({isFocused:!1}),this):this}getIsFocused(){return this.getInstanceState().isFocused}getSnapshot(){return MW(this.store)}loadSnapshot(t){return P2(this.store,t),this}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_flushEventsForTick(t){this.batch(()=>{if(this._pendingEventsForNextTick.length>0){const r=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const o of r)this._flushEventForTick(o)}t>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:t}),this.scribbles.tick(t)})}maybeTrackPerformance(t){wt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(t),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}ne([V],Q.prototype,"getCanUndo");ne([V],Q.prototype,"getCanRedo");ne([V],Q.prototype,"getPath");ne([V],Q.prototype,"getCurrentTool");ne([V],Q.prototype,"getCurrentToolId");ne([V],Q.prototype,"getDocumentSettings");ne([V],Q.prototype,"getInstanceState");ne([V],Q.prototype,"getOpenMenus");ne([V],Q.prototype,"getIsMenuOpen");ne([V],Q.prototype,"getPageStates");ne([V],Q.prototype,"_getPageStatesQuery");ne([V],Q.prototype,"getCurrentPageState");ne([V],Q.prototype,"_getCurrentPageStateId");ne([V],Q.prototype,"getSelectedShapeIds");ne([V],Q.prototype,"getSelectedShapes");ne([V],Q.prototype,"getOnlySelectedShapeId");ne([V],Q.prototype,"getOnlySelectedShape");ne([V],Q.prototype,"getSelectionPageBounds");ne([V],Q.prototype,"getSelectionRotation");ne([V],Q.prototype,"getSelectionRotatedPageBounds");ne([V],Q.prototype,"getSelectionRotatedScreenBounds");ne([V],Q.prototype,"getFocusedGroupId");ne([V],Q.prototype,"getFocusedGroup");ne([V],Q.prototype,"getEditingShapeId");ne([V],Q.prototype,"getEditingShape");ne([V],Q.prototype,"getHoveredShapeId");ne([V],Q.prototype,"getHoveredShape");ne([V],Q.prototype,"getHintingShapeIds");ne([V],Q.prototype,"getHintingShape");ne([V],Q.prototype,"getErasingShapeIds");ne([V],Q.prototype,"getErasingShapes");ne([V],Q.prototype,"getCameraId");ne([V],Q.prototype,"getCamera");ne([V],Q.prototype,"getViewportPageBoundsForFollowing");ne([V],Q.prototype,"getCameraForFollowing");ne([V],Q.prototype,"getZoomLevel");ne([V],Q.prototype,"getViewportScreenBounds");ne([V],Q.prototype,"getViewportScreenCenter");ne([V],Q.prototype,"getViewportPageBounds");ne([V],Q.prototype,"_getCollaboratorsQuery");ne([V],Q.prototype,"getCollaborators");ne([V],Q.prototype,"getCollaboratorsOnCurrentPage");ne([V],Q.prototype,"getRenderingShapes");ne([V],Q.prototype,"_getAllPagesQuery");ne([V],Q.prototype,"getPages");ne([V],Q.prototype,"getCurrentPageId");ne([V],Q.prototype,"getCurrentPageShapeIdsSorted");ne([V],Q.prototype,"_getAllAssetsQuery");ne([V],Q.prototype,"_getShapeGeometryCache");ne([V],Q.prototype,"_getShapeHandlesCache");ne([V],Q.prototype,"_getShapePageTransformCache");ne([V],Q.prototype,"_getShapePageBoundsCache");ne([V],Q.prototype,"_getShapeClipPathCache");ne([V],Q.prototype,"_getShapeMaskCache");ne([V],Q.prototype,"_getShapeMaskedPageBoundsCache");ne([V],Q.prototype,"_notVisibleShapes");ne([V],Q.prototype,"getCulledShapes");ne([V],Q.prototype,"getCurrentPageBounds");ne([V],Q.prototype,"getCurrentPageShapes");ne([V],Q.prototype,"getCurrentPageShapesSorted");ne([V],Q.prototype,"getCurrentPageRenderingShapesSorted");ne([V],Q.prototype,"_getBindingsIndexCache");ne([V],Q.prototype,"_getSelectionSharedStyles");ne([V({isEqual:(e,n)=>e.equals(n)})],Q.prototype,"getSharedStyles");ne([V],Q.prototype,"getSharedOpacity");ne([V],Q.prototype,"getIsFocused");function Hd(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:e.options.maxShapesPerPage})}function jo(e,n){if(!n)return e;let t=null;const r=Object.entries(n);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(t||(t={...e}),i==="props"||i==="meta"){t[i]={...e[i]};for(const[l,c]of Object.entries(a))c!==void 0&&(t[i][l]=c);continue}t[i]=a}}return t||e}function A2(e,n,t){const r=e.getShape(n);if(!r)return;t.push(r);const o=e.getSortedChildIdsForParent(n);for(let s=0,i=o.length;s<i;s++)A2(e,o[s],t)}function DC(e,n,t){let r;if(e.history.ignore(()=>{const o=e.store.extractingChanges(()=>{const s=new Set,i=new Set;for(const a of n)if(e.getShape(a))for(const c of e.getBindingsInvolvingShape(a)){const d=n.has(c.fromId),h=n.has(c.toId);if(d&&h){s.add(c.id);continue}(!d||!h)&&i.add(c.id)}e.deleteBindings([...i],{isolateShapes:!0});try{r=Ns.ok(t(s))}catch(a){r=Ns.err(a)}});e.store.applyDiff(lv(o))}),r.ok)return r.value;throw r.error}function RC(e,n){if(!n.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=n.constraints,o=e.getViewportScreenBounds(),s=Z.From(n.constraints.bounds),i=(o.w-t*2)/s.w,a=(o.h-r*2)/s.h;return{zx:i,zy:a}}function Wu(){const e=B(),n=M2();return G("isDarkMode",()=>(n==null?void 0:n.isDarkMode)??e.user.getIsDarkMode(),[n,e])}const LC="<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'/>",$C="<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 ms(e,n,t,r,o,s=16,i=16){const a=(-t-n)*(_e/180),l=Math.sin(a),c=Math.cos(a),d=1*c-1*l,h=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${d}' dy='${h}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${n+t} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const MG=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],jG={none:()=>"none","ew-resize":(e,n,t)=>ms($C,e,0,n,t),"ns-resize":(e,n,t)=>ms($C,e,90,n,t),"nesw-resize":(e,n,t)=>ms(LC,e,0,n,t),"nwse-resize":(e,n,t)=>ms(LC,e,90,n,t),"nwse-rotate":(e,n,t)=>ms(Kd,e,0,n,t),"nesw-rotate":(e,n,t)=>ms(Kd,e,90,n,t),"senw-rotate":(e,n,t)=>ms(Kd,e,180,n,t),"swne-rotate":(e,n,t)=>ms(Kd,e,270,n,t)};function Gn(e,n=0,t="black"){return jG[e](Z9(n),!1,t)}function AG(){const e=B(),n=un(),t=Wu();Bs("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(MG.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Gn(r,o,t?"white":"black"))},[e,n,t])}function OG(){const e=B(),n=un(),t=Wu(),r=G(wt.forceSrgb);xe.useEffect(()=>{t?(n.setAttribute("data-color-mode","dark"),n.classList.remove("tl-theme__light"),n.classList.add("tl-theme__dark")):(n.setAttribute("data-color-mode","light"),n.classList.remove("tl-theme__dark"),n.classList.add("tl-theme__light")),r?n.classList.add("tl-theme__force-sRGB"):n.classList.remove("tl-theme__force-sRGB")},[e,n,r,t])}function qw(e){const n=P.useRef();return P.useLayoutEffect(()=>{n.current=e}),P.useDebugValue(e),P.useCallback((...t)=>{const r=n.current;return st(r,"fn does not exist"),r(...t)},[])}function DG(){const[e,n]=P.useState(0);P.useEffect(()=>n(t=>t+1),[])}function RG(){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 LG(){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 $G=(e,n)=>n.some(t=>e instanceof t);let FC,NC;function FG(){return FC||(FC=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function NG(){return NC||(NC=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const O2=new WeakMap,xv=new WeakMap,D2=new WeakMap,ey=new WeakMap,Zw=new WeakMap;function zG(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(Ko(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return n.then(t=>{t instanceof IDBCursor&&O2.set(t,e)}).catch(()=>{}),Zw.set(n,e),n}function BG(e){if(xv.has(e))return;const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{t(),o()},i=()=>{r(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});xv.set(e,n)}let wv={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return xv.get(e);if(n==="objectStoreNames")return e.objectStoreNames||D2.get(e);if(n==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Ko(e[n])},set(e,n,t){return e[n]=t,!0},has(e,n){return e instanceof IDBTransaction&&(n==="done"||n==="store")?!0:n in e}};function UG(e){wv=e(wv)}function HG(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(ty(this),n,...t);return D2.set(r,n.sort?n.sort():[n]),Ko(r)}:NG().includes(e)?function(...n){return e.apply(ty(this),n),Ko(O2.get(this))}:function(...n){return Ko(e.apply(ty(this),n))}}function KG(e){return typeof e=="function"?HG(e):(e instanceof IDBTransaction&&BG(e),$G(e,FG())?new Proxy(e,wv):e)}function Ko(e){if(e instanceof IDBRequest)return zG(e);if(ey.has(e))return ey.get(e);const n=KG(e);return n!==e&&(ey.set(e,n),Zw.set(n,e)),n}const ty=e=>Zw.get(e);function R2(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=Ko(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Ko(i.result),l.oldVersion,l.newVersion,Ko(i.transaction),l)}),t&&i.addEventListener("blocked",l=>t(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),o&&l.addEventListener("versionchange",c=>o(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function WG(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),Ko(t).then(()=>{})}const GG=["get","getKey","getAll","getAllKeys","count"],VG=["put","add","delete","clear"],ny=new Map;function zC(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(ny.get(n))return ny.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=VG.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||GG.includes(t)))return;const s=async function(i,...a){const l=this.transaction(i,o?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[t](...a),o&&l.done]))[0]};return ny.set(n,s),s}UG(e=>({...e,get:(n,t,r)=>zC(n,t)||e.get(n,t,r),has:(n,t)=>!!zC(n,t)||e.has(n,t)}));const lg="TLDRAW_DOCUMENT_v2",L2="TLDRAW_DB_NAME_INDEX_v2",Le={Records:"records",Schema:"schema",SessionState:"session_state"};async function cg(e,n){QG(e);const t=await R2(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 n(t)}finally{t.close()}}async function YG({persistenceKey:e,sessionId:n,didCancel:t}){const r=lg+e;if(Qw().includes(r))return await ZG({persistenceKey:e,didCancel:t}),await cg(r,async o=>{var h,p;if(t!=null&&t())return;const s=o.transaction([Le.Records,Le.Schema,Le.SessionState],"readonly"),i=s.objectStore(Le.Records),a=s.objectStore(Le.Schema),l=s.objectStore(Le.SessionState);let c=n?(h=await l.get(n))==null?void 0:h.snapshot:null;c||(c=(p=(await l.getAll()).sort((S,g)=>S.updatedAt-g.updatedAt).pop())==null?void 0:p.snapshot);const d={records:await i.getAll(),schema:await a.get(Le.Schema),sessionStateSnapshot:c};if(t!=null&&t()){s.abort();return}return await s.done,d})}async function XG({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=lg+e;await cg(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),d=l.objectStore(Le.Schema),h=l.objectStore(Le.SessionState);for(const[p,f]of Object.entries(t.added))await c.put(f,p);for(const[p,f]of Object.values(t.updated))await c.put(f,f.id);for(const p of Object.keys(t.removed))await c.delete(p);if(d.put(n.serialize(),Le.Schema),o&&r?h.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function qG({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=lg+e;await cg(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),d=l.objectStore(Le.Schema),h=l.objectStore(Le.SessionState);await c.clear();for(const[p,f]of Object.entries(t))await c.put(f,p);if(d.put(n.serialize(),Le.Schema),o&&r?h.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function ZG({persistenceKey:e,didCancel:n}){await cg(lg+e,async t=>{const r=t.transaction([Le.SessionState],"readwrite"),o=r.objectStore(Le.SessionState),s=(await o.getAll()).sort((a,l)=>a.updatedAt-l.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(n!=null&&n())return r.abort();await r.done})}function Qw(){const e=JSON.parse(bw(L2)||"[]")??[];return Array.isArray(e)?e:[]}function QG(e){const n=new Set(Qw());n.add(e),Pw(L2,JSON.stringify([...n]))}const JG=350,eV=1e4,BC=Symbol("UPDATE_INSTANCE_STATE"),tV=e=>e;class nV{constructor(n){m(this,"onmessage")}postMessage(n){}close(){}}const rV=typeof BroadcastChannel>"u"?nV:BroadcastChannel;class oV{constructor(n,{persistenceKey:t,sessionId:r=hf,onLoad:o,onLoadError:s},i=new rV(`tldraw-tab-sync-${t}`)){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=n,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=w2(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(tV({type:"diff",storeId:this.store.id,changes:a,schema:this.serializedSchema})),this.schedulePersist()},{source:"user",scope:"document"})),this.disposables.add(n.listen(()=>{this.diffQueue.push(BC),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(...n){this.isDebugging&&console.debug(...n)}async connect(n,t){this.debug("connecting");let r;try{r=await YG({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),LG(),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??_W(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),t(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&&b2(this.store,s)}this.channel.onmessage=({data:o})=>{var a,l;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){t(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}s.type==="diff"&&(this.debug("applying diff"),zs(()=>{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()}),n(this)}catch(o){if(this.debug("error loading data from store",o),this.didDispose)return;t(o);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(n=>n())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?eV:JG))}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(){st(!this.isPersisting,"persist already in progress"),this.isPersisting=!0,this.debug("doPersist start");const n=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await qG({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=Iw(n.filter(r=>r!==BC));await XG({persistenceKey:this.persistenceKey,changes:t,schema:this.store.schema,didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(t){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",t),RG(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function $2({initialData:e,defaultName:n="",id:t,...r}={}){const o="schema"in r&&r.schema?r.schema:B9({shapes:"shapeUtils"in r&&r.shapeUtils?UC(k2(r.shapeUtils)):void 0,bindings:"bindingUtils"in r&&r.bindingUtils?UC(C2(r.bindingUtils)):void 0,migrations:"migrations"in r?r.migrations:void 0});return new Tw({id:t,schema:o,initialData:e,props:{defaultName:n}})}function UC(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function HC(e){const n=$2(e);return e.snapshot&&P2(n,e.snapshot),{store:n,opts:e}}function F2(e){const[n,t]=P.useState(()=>HC(e));if(!MT(n.opts,e)){const r=HC(e);return t(r),r.store}return n.store}function sV({persistenceKey:e,sessionId:n,...t}){const[r,o]=P.useState(null),s=F2(t);return P.useEffect(()=>{const i=ot();if(!e){o({id:i,storeWithStatus:{status:"not-synced",store:s}});return}o({id:i,storeWithStatus:{status:"loading"}});const a=c=>{o(d=>(d==null?void 0:d.id)===i?{id:i,storeWithStatus:c}:d)},l=new oV(s,{sessionId:n,persistenceKey:e,onLoad(){a({store:s,status:"synced-local"})},onLoadError(c){a({status:"error",error:c})}});return()=>{o(c=>(c==null?void 0:c.id)===i?null:c),l.close()}},[e,s,n]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}function iV(){const e=B(),n=un();P.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=CT(t,100),o=new Dl("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[e,n])}const aV=[],lV=[],cV=[],uV=P.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=xe.useState(null),l=P.useMemo(()=>o??y2(),[o]),c=(t==null?void 0:t.ErrorFallback)===void 0?u2:t==null?void 0:t.ErrorFallback,d={...s,shapeUtils:s.shapeUtils??aV,bindingUtils:s.bindingUtils??lV,tools:s.tools??cV,components:t};return u.jsx("div",{ref:a,draggable:!1,className:ce("tl-container tl-theme__light",r),onPointerDown:Kt,tabIndex:-1,children:u.jsx(fu,{fallback:c,onError:h=>xw(h,{tags:{origin:"react.tldraw-before-app"}}),children:i&&u.jsx(l7,{container:i,children:u.jsx(hW,{overrides:t,children:n?n instanceof Tw?u.jsx(z2,{...d,store:n,user:l}):u.jsx(N2,{...d,store:n,user:l}):u.jsx(dV,{...d,store:n,user:l})})})})})});function dV(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l}=e,c=sV({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:n,snapshot:t});return u.jsx(N2,{...e,store:c,user:l})}const N2=P.memo(function({store:n,user:t,...r}){const o=un();P.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,t]);const{LoadingScreen:s}=it();switch(n.status){case"error":throw n.error;case"loading":return s?u.jsx(s,{}):null}return u.jsx(z2,{...r,store:n.store,user:t})});function z2({onMount:e,children:n,store:t,tools:r,shapeUtils:o,bindingUtils:s,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:d,assetOptions:h,options:p}){const{ErrorFallback:f}=it(),S=un(),g=P.useRef(null),[x,y]=P.useState(null),v=g.current;x!==v&&y(v);const[b]=P.useState(l);P.useLayoutEffect(()=>{const C=new Q({store:t,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>S,user:i,initialState:a,autoFocus:b,inferDarkMode:c,cameraOptions:d,assetOptions:h,options:p});return g.current=C,y(C),()=>{C.dispose()}},[S,o,s,r,t,i,a,b,c,d,h,p]);const E=P.useSyncExternalStore(P.useCallback(C=>v?(v.on("crash",C),()=>v.off("crash",C)):()=>{},[v]),()=>(v==null?void 0:v.getCrashingError())??null),{Canvas:I}=it();return v?u.jsx(fu,{fallback:f,onError:C=>v.annotateError(C,{origin:"react.tldraw",willCrashApp:!0}),children:E?u.jsx(pV,{crashingError:E}):u.jsx(og.Provider,{value:v,children:u.jsx(hV,{onMount:e,children:n??(I?u.jsx(I,{}):null)})})}):null}function hV({children:e,onMount:n}){return iV(),AG(),OG(),DG(),fV(n),u.jsx(u.Fragment,{children:e})}function pV({crashingError:e}){throw e}function Jw({children:e}){return u.jsx("div",{className:"tl-loading",children:e})}function B2({children:e}){return u.jsx("div",{className:"tl-loading",children:e})}function fV(e){const n=B(),t=qw(r=>{let o;return r.history.ignore(()=>{o=e==null?void 0:e(r),r.emit("mount")}),window.tldrawReady=!0,o});xe.useLayoutEffect(()=>{if(n)return t==null?void 0:t(n)},[n,t])}function Vi({children:e,className:n="",...t}){return u.jsx("div",{...t,className:ce("tl-html-container",n),children:e})}class Rh{constructor(n){this.editor=n}}m(Rh,"props"),m(Rh,"migrations"),m(Rh,"type");function U2(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:d=1/0}=t;let h=e.props.w*s,p=e.props.h*i;const f=new w(0,0);if(h>0){if(h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:S,y:g}=f.rot(e.rotation).add(r);return{x:S,y:g,props:{w:Math.min(l,h),h:Math.min(d,p)}}}class $l extends Br{constructor(){super(...arguments);m(this,"onResize",(t,r)=>U2(t,r))}getGeometry(t){return new Jo({width:t.props.w,height:t.props.h,isFilled:!0})}getHandleSnapGeometry(t){return{points:this.getGeometry(t).bounds.cornersAndCenter}}}var jy;let gV=(jy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(jy,"id","idle"),jy);var Ay;let mV=(Ay=class extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"wasFocusedOnEnter",!1);m(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=$e();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",{...t,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:t}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;this.editor.mark(this.markId);const r=this.parent.shapeType,o=$e();this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:r,x:t.x,y:t.y}]);const s=this.editor.getShape(o);if(!s){this.cancel();return}let{w:i,h:a}=s.props;const l=new w(i/2,a/2),c=this.editor.getShapeParentTransform(s);c&&l.rot(-c.rotation());let d=1;this.editor.user.getIsDynamicResizeMode()&&(d=1/this.editor.getZoomLevel(),i*=d,a*=d,l.mul(d));const h=rt(s);h.x=s.x-l.x,h.y=s.y-l.y,h.props.w=i,h.props.h=a,"scale"in s.props&&(h.props.scale=d),this.editor.updateShape(h),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},m(Ay,"id","pointing"),Ay);class Lh extends se{constructor(){super(...arguments);m(this,"onCreate")}}m(Lh,"id","box"),m(Lh,"initial","idle"),m(Lh,"children",()=>[gV,mV]);function ug(e){const n=B();return G("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function yV(){return P.useId().replace(/:/g,"_")}function no(e){const n=B();return P.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===Fw){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...On(c)});return}if(c.button!==0)return;const d=uf(c.currentTarget);function h(){d.removeEventListener("pointerup",h),zu(d,c)}Nu(d,c),d.addEventListener("pointerup",h),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...On(c)}),Kt(c)};let s,i;function a(c){c.isKilled||c.button===0&&(c.clientX===s&&c.clientY===i||(s=c.clientX,i=c.clientY,n.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...On(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...On(c)})}}},[n,e])}const SV=20,vV=8;function e0(e,n=SV){return Math.max(vV,Math.ceil(e/n))}class Ha extends ai{constructor(t){super({...t,isFilled:!1,isClosed:!1});m(this,"_center");m(this,"radius");m(this,"start");m(this,"end");m(this,"largeArcFlag");m(this,"sweepFlag");m(this,"measure");m(this,"angleStart");m(this,"angleEnd");const{center:r,sweepFlag:o,largeArcFlag:s,start:i,end:a}=t;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=w.Angle(r,i),this.angleEnd=w.Angle(r,a),this.radius=w.Dist(r,i),this.measure=Q9(this.angleStart,this.angleEnd,o,s),this.start=i,this.end=a,this.sweepFlag=o,this.largeArcFlag=s,this._center=r}nearestPoint(t){const{_center:r,measure:o,radius:s,angleEnd:i,angleStart:a,start:l,end:c}=this,d=gv(o,a,i,r.angle(t));if(d<=0)return l;if(d>=1)return c;const h=r.clone().add(t.clone().sub(r).uni().mul(s));let p,f=1/0,S;for(const g of[l,c,h])S=w.Dist2(t,g),S<f&&(p=g,f=S);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(t,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:l}=this,c=Hu(t,r,o,s);return c===null?!1:c.some(d=>{const h=gv(i,a,l,o.angle(d));return h>=0&&h<=1})}getVertices(){const{_center:t,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let l=0,c=e0(Math.abs(o));l<c+1;l++){const d=l/c*r,h=i+d;a.push(Gi(t,s,h))}return a}getSvgPathData(t=!0){const{start:r,end:o,radius:s,largeArcFlag:i,sweepFlag:a}=this;return`${t?`M${r.toFixed()}`:""} A${s} ${s} 0 ${i} ${a} ${o.toFixed()}`}getLength(){return this.measure*this.radius}}class t0 extends ai{constructor(t){super({isClosed:!0,...t});m(this,"_center");m(this,"radius");m(this,"x");m(this,"y");this.config=t;const{x:r=0,y:o=0,radius:s}=t;this.x=r,this.y=o,this._center=new w(s+r,s+o),this.radius=s}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,o=Re*r,s=[];for(let i=0,a=e0(o);i<a;i++){const l=i/a*Re;s.push(Gi(t,r,l))}return s}nearestPoint(t){const{_center:r,radius:o}=this;return r.equals(t)?w.AddXY(r,o,0):r.clone().add(t.clone().sub(r).uni().mul(o))}hitTestLineSegment(t,r,o=0){const{_center:s,radius:i}=this;return Hu(t,r,s,i+o)!==null}getSvgPathData(){const{_center:t,radius:r}=this;return`M${t.x+r},${t.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class nn extends Ll{constructor(t){const{start:r,cp1:o,cp2:s,end:i}=t;super({...t,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 t=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;t.push(new w((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*o.x+3*(1-c)*(c*c)*s.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*o.y+3*(1-c)*(c*c)*s.y+c*c*c*i.y))}return t}midPoint(){return nn.GetAtT(this,.5)}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(t),s=w.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}getSvgPathData(t=!0){const{a:r,b:o,c:s,d:i}=this;return`${t?`M ${r.toFixed()} `:""} C${o.toFixed()} ${s.toFixed()} ${i.toFixed()}`}static GetAtT(t,r){const{a:o,b:s,c:i,d:a}=t;return new w((1-r)*(1-r)*(1-r)*o.x+3*((1-r)*(1-r))*r*s.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*o.y+3*((1-r)*(1-r))*r*s.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(t=32){let r,o=this.a,s=0;for(let i=1;i<=t;i++)r=nn.GetAtT(this,i/t),s+=w.Dist(o,r),o=r;return s}}class xV extends ai{constructor(t){super({...t,isClosed:!1,isFilled:!1});m(this,"points");m(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:t}=this,r=t.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?t[0]:t[i-1],l=t[i],c=t[i+1],d=i===o?c:t[i+2],h=l,p=i===0?a:new w(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),f=i===o?c:new w(c.x-(d.x-l.x)/6*s,c.y-(d.y-l.y)/6*s),S=c;this._segments.push(new nn({start:h,cp1:p,cp2:f,end:S}))}}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){const t=this.segments.reduce((r,o)=>r.concat(o.vertices),[]);return t.push(this.points[this.points.length-1]),t}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(t),s=w.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.segments.some(o=>o.hitTestLineSegment(t,r))}getSvgPathData(){let t=this.segments.reduce((r,o,s)=>r+o.getSvgPathData(s===0),"");return this.isClosed&&(t+="Z"),t}}class wV extends ai{constructor(t){super({...t,isClosed:!0});m(this,"w");m(this,"h");m(this,"_edges");this.config=t;const{width:r,height:o}=t;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:t}=this;this._edges=[];for(let r=0,o=t.length;r<o;r++){const s=t[r],i=t[(r+1)%o];this._edges.push(new zo({start:s,end:i}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),o=t/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=_e*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),l=e0(a),c=Re/l,d=Math.cos(c),h=Math.sin(c);let p=0,f=1,S=0,g=1;const x=Array(l);for(let y=0;y<l;y++)x[y]=new w(o+o*f,s+s*p),S=h*f+d*p,g=d*f-h*p,p=S,f=g;return x}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(t),s=w.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.edges.some(o=>o.hitTestLineSegment(t,r))}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{w:t,h:r}=this,o=t/2,s=r/2,i=Math.max(0,o),a=Math.max(0,s);return zM(i,a)}getSvgPathData(t=!1){const{w:r,h:o}=this,s=r/2,i=o/2,a=Math.max(0,s),l=Math.max(0,i);return`${t?`M${s-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class bV extends ai{constructor(t){super({...t,isClosed:!0});m(this,"w");m(this,"h");m(this,"a");m(this,"b");m(this,"c");m(this,"d");this.config=t;const{width:r,height:o}=t;if(this.w=r,this.h=o,o>r){const s=r/2;this.a=new Ha({start:new w(0,s),end:new w(r,s),center:new w(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new zo({start:new w(r,s),end:new w(r,o-s)}),this.c=new Ha({start:new w(r,o-s),end:new w(0,o-s),center:new w(r/2,o-s),sweepFlag:1,largeArcFlag:1}),this.d=new zo({start:new w(0,o-s),end:new w(0,s)})}else{const s=o/2;this.a=new Ha({start:new w(s,o),end:new w(s,0),center:new w(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new zo({start:new w(s,0),end:new w(r-s,0)}),this.c=new Ha({start:new w(r-s,0),end:new w(r-s,o),center:new w(r-s,s),sweepFlag:1,largeArcFlag:1}),this.d=new zo({start:new w(r-s,o),end:new w(s,o)})}}nearestPoint(t){let r,o=1/0,s,i;const{a,b:l,c,d}=this;for(const h of[a,l,c,d])i=h.nearestPoint(t),s=w.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){const{a:o,b:s,c:i,d:a}=this;return[o,s,i,a].some(l=>l.hitTestLineSegment(t,r))}getVertices(){const{a:t,b:r,c:o,d:s}=this;return[t,r,o,s].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{h:t,w:r}=this;return t>r?(_e*(r/2)+(t-r))*2:(_e*(t/2)+(r-t))*2}getSvgPathData(){const{a:t,b:r,c:o,d:s}=this;return[t,r,o,s].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function PV({shouldReload:e=!0}={}){V6(),await Promise.all(Qw().map(n=>WG(n))),G6(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=PV);function CV(e,n="_blank"){Hw.openWindow(e,n)}const H2="TLDRAW_ASSET_STORE_v1",ml={Assets:"assets"};async function K2(e,n){const t=await R2(e,1,{upgrade(r){r.objectStoreNames.contains(ml.Assets)||r.createObjectStore(ml.Assets)}});try{return await n(t)}finally{t.close()}}async function IV({persistenceKey:e,assetId:n}){const t=H2+e;return await K2(t,async r=>await r.transaction([ml.Assets],"readwrite").objectStore(ml.Assets).get(n))}async function EV({persistenceKey:e,assetId:n,blob:t}){const r=H2+e;await K2(r,async o=>{const s=o.transaction([ml.Assets],"readwrite");await s.objectStore(ml.Assets).put(t,n),await s.done})}function kV({children:e}){const n=B();return G("shouldDisplayHandles",()=>{if(n.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(n.isInAny("select.editing_shape")){const r=n.getOnlySelectedShape();return r&&n.isShapeOfType(r,"note")}return!1},[n])?u.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:_V}=Math,rl=_V+1e-4;function W2(e,n={}){const{size:t=16,smoothing:r=.5}=n;if(e.length===0||t<=0)return{left:[],right:[]};const o=e[0],s=e[e.length-1],i=s.runningLength,a=Math.pow(t*r,2),l=[],c=[];let d=e[0].vector,h=e[0].point,p=h,f=h,S=p,g=!1,x;for(let y=0;y<e.length;y++){x=e[y];const{point:v,vector:b}=e[y],E=x.vector.dpr(d),I=(y<e.length-1?e[y+1]:e[y]).vector,C=y<e.length-1?I.dpr(x.vector):1,k=E<0&&!g,T=C!==null&&C<.2;if(k||T){if(C>-.62&&i-x.runningLength>x.radius){const _=d.clone().mul(x.radius);d.clone().cpr(I)<0?(f=w.Add(v,_),S=w.Sub(v,_)):(f=w.Sub(v,_),S=w.Add(v,_)),l.push(f),c.push(S)}else{const _=d.clone().mul(x.radius).per(),j=w.Sub(x.input,_);for(let L=1/13,A=0;A<1;A+=L)f=w.RotWith(j,x.input,rl*A),l.push(f),S=w.RotWith(j,x.input,rl+rl*-A),c.push(S)}h=f,p=S,T&&(g=!0);continue}if(g=!1,x===o||x===s){const _=w.Per(b).mul(x.radius);l.push(w.Sub(v,_)),c.push(w.Add(v,_));continue}const O=w.Lrp(I,b,C).per().mul(x.radius);f=w.Sub(v,O),(y<=1||w.Dist2(h,f)>a)&&(l.push(f),h=f),S=w.Add(v,O),(y<=1||w.Dist2(p,S)>a)&&(c.push(S),p=S),d=b}return{left:l,right:c}}function n0(e,n={}){const{size:t=16,start:r={},end:o={},last:s=!1}=n,{cap:i=!0}=r,{cap:a=!0}=o;if(e.length===0||t<=0)return[];const l=e[0],c=e[e.length-1],d=c.runningLength,h=r.taper===!1?0:r.taper===!0?Math.max(t,d):r.taper,p=o.taper===!1?0:o.taper===!0?Math.max(t,d):o.taper,{left:f,right:S}=W2(e,n),g=l.point,x=e.length>1?e[e.length-1].point:w.AddXY(l.point,1,1);if(e.length===1&&(!(h||p)||s)){const E=w.Add(g,w.Sub(g,x).uni().per().mul(-l.radius)),I=[];for(let C=1/13,k=C;k<=1;k+=C)I.push(w.RotWith(E,g,rl*2*k));return I}const y=[];if(!(h||p&&e.length===1))if(i)for(let E=1/8,I=E;I<=1;I+=E){const C=w.RotWith(S[0],g,rl*I);y.push(C)}else{const E=w.Sub(f[0],S[0]),I=w.Mul(E,.5),C=w.Mul(E,.51);y.push(w.Sub(g,I),w.Sub(g,C),w.Add(g,C),w.Add(g,I))}const v=[],b=c.vector.clone().per().neg();if(p||h&&e.length===1)v.push(x);else if(a){const E=w.Add(x,w.Mul(b,c.radius));for(let I=1/29,C=I;C<1;C+=I)v.push(w.RotWith(E,x,rl*3*C))}else v.push(w.Add(x,w.Mul(b,c.radius)),w.Add(x,w.Mul(b,c.radius*.99)),w.Sub(x,w.Mul(b,c.radius*.99)),w.Sub(x,w.Mul(b,c.radius)));return f.concat(v,S.reverse(),y)}const TV=.025,MV=.01;function xo(e,n={}){var x;const{streamline:t=.5,size:r=16,simulatePressure:o=!1}=n;if(e.length===0)return[];const s=.15+(1-t)*.85;let i=e.map(w.From),a=0;if(!o){let y=i[0];for(;y&&!(y.z>=TV);)i.shift(),y=i[0]}if(!o){let y=i[i.length-1];for(;y&&!(y.z>=MV);)i.pop(),y=i[i.length-1]}if(i.length===0)return[{point:w.From(e[0]),input:w.From(e[0]),pressure:o?.5:.15,vector:new w(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(w.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(w.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const d=n.last||!n.simulatePressure||i.length>1&&w.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&n.simulatePressure){const y=i[1];i=i.slice(0,-1);for(let v=1;v<5;v++){const b=w.Lrp(i[0],y,v/4);b.z=(i[0].z+(y.z-i[0].z))*v/4,i.push(b)}}const h=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new w(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=h[0],S,g;d&&t>0&&i.push(i[i.length-1].clone());for(let y=1,v=i.length;y<v;y++)S=!s||n.last&&y===v-1?i[y].clone():i[y].clone().lrp(f.point,1-s),!f.point.equals(S)&&(g=w.Dist(S,f.point),p+=g,!(y<4&&p<r)&&(f={input:i[y],point:S,pressure:o?.5:i[y].z,vector:w.Sub(f.point,S).uni(),distance:g,runningLength:p,radius:1},h.push(f)));if((x=h[1])!=null&&x.vector&&(h[0].vector=h[1].vector.clone()),p<1){const y=Math.max(.5,...h.map(v=>v.pressure));h.forEach(v=>v.pressure=y)}return h}const{min:ys}=Math,ry=.275;function dg(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=x=>x,start:i={},end:a={}}=n,{easing:l=jt.easeOutQuad}=i,{easing:c=jt.easeOutCubic}=a,d=e[e.length-1].runningLength;let h,p=e[0].pressure,f;if(!o&&d<t){const x=e.reduce((y,v)=>Math.max(y,v.pressure),.5);return e.forEach(y=>{y.pressure=x,y.radius=t*s(.5-r*(.5-y.pressure))}),e}else{let x;for(let y=0,v=e.length;y<v&&(f=e[y],!(f.runningLength>t*5));y++){const b=ys(1,f.distance/t);if(o){const E=ys(1,1-b);x=ys(1,p+(E-p)*(b*ry))}else x=ys(1,p+(f.pressure-p)*.5);p=p+(x-p)*.5}for(let y=0;y<e.length;y++){if(f=e[y],r){let{pressure:v}=f;const b=ys(1,f.distance/t);if(o){const E=ys(1,1-b);v=ys(1,p+(E-p)*(b*ry))}else v=ys(1,p+(v-p)*(b*ry));f.radius=t*s(.5-r*(.5-v)),p=v}else f.radius=t/2;h===void 0&&(h=f.radius)}}const S=i.taper===!1?0:i.taper===!0?Math.max(t,d):i.taper,g=a.taper===!1?0:a.taper===!0?Math.max(t,d):a.taper;if(S||g)for(let x=0;x<e.length;x++){f=e[x];const{runningLength:y}=f,v=y<S?l(y/S):1,b=d-y<g?c((d-y)/g):1;f.radius=Math.max(.01,f.radius*Math.min(v,b))}return e}function jV(e,n={}){return n0(dg(xo(e,n),n),n)}function KC({scribble:e,zoom:n,color:t,opacity:r,className:o}){if(!e.points.length)return null;const s=jV(e.points,{size:e.size/n,start:{taper:e.taper,easing:jt.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=e.size/n/2,{x:l,y:c}=e.points[e.points.length-1];i=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=zw(s);return u.jsx("svg",{className:o&&ce("tl-overlays__item",o),children:u.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})}const AV=({bounds:e,rotation:n})=>{const t=B();return G("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?u.jsx(i2,{bounds:e,rotation:n}):null};function is(){const e=B();return G("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function OV({size:e,width:n,height:t,hideAlternateHandles:r}){const o=N(e/3),s=o/2;return u.jsxs("svg",{className:"tl-overlays__item",children:[u.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
${N(0-s)},${N(e)}
|
|
${N(0-s)},${N(0-s)}
|
|
${N(e)},${N(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),u.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(n/2-e),y1:N(0-s),x2:N(n/2+e),y2:N(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),u.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
${N(n-e)},${N(0-s)}
|
|
${N(n+s)},${N(0-s)}
|
|
${N(n+s)},${N(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),u.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(n+s),y1:N(t/2-e),x2:N(n+s),y2:N(t/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),u.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
${N(n+s)},${N(t-e)}
|
|
${N(n+s)},${N(t+s)}
|
|
${N(n-e)},${N(t+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),u.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(n/2-e),y1:N(t+s),x2:N(n/2+e),y2:N(t+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),u.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
${N(0+e)},${N(t+s)}
|
|
${N(0-s)},${N(t+s)}
|
|
${N(0-s)},${N(t-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),u.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(0-s),y1:N(t/2-e),x2:N(0-s),y2:N(t/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const DV=lr(function({bounds:n,rotation:t}){const r=B(),o=P.useRef(null),s=is(),i=no("top"),a=no("right"),l=no("bottom"),c=no("left"),d=no("top_left"),h=no("top_right"),p=no("bottom_right"),f=no("bottom_left"),S=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",g=r.getInstanceState().isCoarsePointer,x=r.getOnlySelectedShape(),y=x&&r.isShapeOrAncestorLocked(x),v=x?r.getShapeUtil(x).expandSelectionOutlinePx(x):0;if(Rl(o,n==null?void 0:n.x,n==null?void 0:n.y,1,r.getSelectionRotation(),{x:-v,y:-v}),!n)return null;n=n.clone().expandBy(v).zeroFix();const b=r.getZoomLevel(),E=r.getInstanceState().isChangingStyle,I=n.width,C=n.height,k=8/b,T=I<k*2,O=C<k*2,_=I<k*4,j=C<k*4,L=I<k*5,A=C<k*5,R=g?1.75:1,F=6/b*R,W=(_?F/2:F)*(R*.75),K=(j?F/2:F)*(R*.75),z=(x?!r.getShapeUtil(x).hideSelectionBoundsFg(x):!0)&&!E;let U=z&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle","select.pointing_resize_handle")||z&&r.isIn("select.resizing")&&x&&r.isShapeOfType(x,"text");x&&U&&r.environment.isFirefox&&r.isShapeOfType(x,"embed")&&(U=!1);const X=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!E&&!s,J=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!E&&!s,le=!g&&!(T||O)&&(J||X)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!y,ye=g&&(!_||!j)&&(J||X)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!y,Me=J&&(x?r.getShapeUtil(x).canResize(x)&&!r.getShapeUtil(x).hideResizeHandles(x):!0)&&!X&&!y,ae=T||O,Ue=T&&O,Ae=L||A,et=Me||X,je=!le,at=!J||!ye,Ne=!J||!et,Kn=!J||!et||ae,Rt=!J||!et||ae,Pn=!J||!et||Ue&&!X;let St=!0,Xt=!0;if(X)St=Ae,Xt=Ae;else if(Me){St=ae||Ue||g;const us=g&&x&&x.type==="text";Xt=St&&!us}const ko=Math.min(24/b,C-K*3),Bl=J&&g&&x&&r.isShapeOfType(x,"text")&&ko*b>=4;return u.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:u.jsxs("g",{ref:o,children:[U&&u.jsx("rect",{className:"tl-selection__fg__outline",width:N(I),height:N(C)}),u.jsx(Wd,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:F,corner:"top_left_rotate",cursor:S?Gn("nwse-rotate",t):void 0,isHidden:je}),u.jsx(Wd,{"data-testid":"selection.rotate.top-right",cx:I+F*3,cy:0,targetSize:F,corner:"top_right_rotate",cursor:S?Gn("nesw-rotate",t):void 0,isHidden:je}),u.jsx(Wd,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:C+F*3,targetSize:F,corner:"bottom_left_rotate",cursor:S?Gn("swne-rotate",t):void 0,isHidden:je}),u.jsx(Wd,{"data-testid":"selection.rotate.bottom-right",cx:I+F*3,cy:C+F*3,targetSize:F,corner:"bottom_right_rotate",cursor:S?Gn("senw-rotate",t):void 0,isHidden:je}),u.jsx(LV,{"data-testid":"selection.rotate.mobile",cx:_?-F*1.5:I/2,cy:_?C/2:-F*1.5,size:k,isHidden:at}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":St}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:N(0-(j?K*2:K)),width:N(I),height:N(Math.max(1,K*2)),style:S?{cursor:Gn("ns-resize",t)}:void 0,...i}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Xt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(I-(_?0:W)),y:0,height:N(C),width:N(Math.max(1,W*2)),style:S?{cursor:Gn("ew-resize",t)}:void 0,...a}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":St}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:N(C-(j?0:K)),width:N(I),height:N(Math.max(1,K*2)),style:S?{cursor:Gn("ns-resize",t)}:void 0,...l}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Xt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:N(0-(_?W*2:W)),y:0,height:N(C),width:N(Math.max(1,W*2)),style:S?{cursor:Gn("ew-resize",t)}:void 0,...c}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Ne}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(_?W*2:W*1.5)),y:N(0-(j?K*2:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Gn("nwse-resize",t)}:void 0,...d}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Kn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(I-(_?0:W*1.5)),y:N(0-(j?K*2:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Gn("nesw-resize",t)}:void 0,...h}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Pn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(I-(_?W:W*1.5)),y:N(C-(j?K:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Gn("nwse-resize",t)}:void 0,...p}),u.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Rt}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:N(0-(_?W*3:W*1.5)),y:N(C-(j?0:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Gn("nesw-resize",t)}:void 0,...f}),Me&&u.jsxs(u.Fragment,{children:[u.jsx("rect",{"data-testid":"selection.resize.top-left",className:ce("tl-corner-handle",{"tl-hidden":Ne}),"aria-label":"top_left handle",x:N(0-k/2),y:N(0-k/2),width:N(k),height:N(k)}),u.jsx("rect",{"data-testid":"selection.resize.top-right",className:ce("tl-corner-handle",{"tl-hidden":Kn}),"aria-label":"top_right handle",x:N(I-k/2),y:N(0-k/2),width:N(k),height:N(k)}),u.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ce("tl-corner-handle",{"tl-hidden":Pn}),"aria-label":"bottom_right handle",x:N(I-k/2),y:N(C-k/2),width:N(k),height:N(k)}),u.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ce("tl-corner-handle",{"tl-hidden":Rt}),"aria-label":"bottom_left handle",x:N(0-k/2),y:N(C-k/2),width:N(k),height:N(k)})]}),Bl&&u.jsxs(u.Fragment,{children:[u.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:N(0-k/4),y:N(C/2-ko/2),rx:k/4,width:N(k/2),height:N(ko)}),u.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:k/4,x:N(I-k/4),y:N(C/2-ko/2),width:N(k/2),height:N(ko)})]}),X&&u.jsx(OV,{size:k,width:I,height:C,hideAlternateHandles:Ae})]})})}),Wd=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=no(o);return u.jsx("rect",{className:ce("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:N(n-r*3),y:N(t-r*3),width:N(Math.max(1,r*3)),height:N(Math.max(1,r*3)),cursor:s,...l})},RV=Math.sqrt(Math.PI),LV=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=no("mobile_rotate"),a=B(),l=G("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return u.jsxs("g",{children:[u.jsx("circle",{"data-testid":s,pointerEvents:"all",className:ce("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:c,...i}),u.jsx("circle",{className:ce("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/RV})]})};function bv(e,n,t){const{arrowheadStart:r,arrowheadEnd:o}=n.props,s=Ka(e,n,t),i=s.start.clone(),a=s.end.clone(),l=w.Med(i,a);if(w.Equals(i,a))return{bindings:t,isStraight:!0,start:{handle:i,point:i,arrowhead:n.props.arrowheadStart},end:{handle:a,point:a,arrowhead:n.props.arrowheadEnd},middle:l,isValid:!1,length:0};const c=w.Sub(a,i).uni(),d=pf(e,n,"start"),h=pf(e,n,"end"),p=e.getShapePageTransform(n);WC(a,s.start,p,h),WC(i,s.end,p,d);let f=0,S=0,g=0,x=0,y=Wa*n.props.scale;const v=d&&h&&d.shape===h.shape,b=d&&h?r0(e,d.shape.id,h.shape.id):"safe";b==="safe"&&d&&h&&!v&&!d.isExact&&!h.isExact&&(h.didIntersect&&!d.didIntersect?d.isClosed&&i.setTo(a.clone().add(c.clone().mul(Wa*n.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(Wa*n.props.scale))));const E=w.Sub(a,i),I=w.Len(E)?E.uni():w.From(E),C=!w.Equals(I,c);v||(b!=="start-contains-end"&&d&&r!=="none"&&!d.isExact&&(g=Ts[n.props.size]/2+("size"in d.shape.props?Ts[d.shape.props.size]/2:0),f=(ff+g)*n.props.scale,y+=g*n.props.scale),b!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(x=Ts[n.props.size]/2+("size"in h.shape.props?Ts[h.shape.props.size]/2:0),S=(ff+x)*n.props.scale,y+=x*n.props.scale));const k=i.clone().add(I.clone().mul(f*(C?-1:1))),T=a.clone().sub(I.clone().mul(S*(C?-1:1)));w.DistMin(k,T,y)&&(f!==0&&S!==0?(f*=-1.5,S*=-1.5):f!==0?f*=-1:S!==0&&(S*=-1)),i.add(I.clone().mul(f*(C?-1:1))),a.sub(I.clone().mul(S*(C?-1:1))),C?(d&&h&&a.setTo(w.Add(i,I.clone().mul(-Wa*n.props.scale))),l.setTo(w.Med(s.start,s.end))):l.setTo(w.Med(i,a));const O=w.Dist(i,a);return{bindings:t,isStraight:!0,start:{handle:s.start,point:i,arrowhead:n.props.arrowheadStart},end:{handle:s.end,point:a,arrowhead:n.props.arrowheadEnd},middle:l,isValid:O>0,length:O}}function WC(e,n,t,r){if(r===void 0||r.isExact)return;const o=oe.applyToPoint(t,n),s=oe.applyToPoint(t,e),i=oe.applyToPoint(oe.Inverse(r.transform),o),a=oe.applyToPoint(oe.Inverse(r.transform),s),l=r.isClosed,d=(l?Gw:jW)(i,a,r.outline);let h;if(d!==null&&(h=d.sort((S,g)=>w.Dist2(S,i)-w.Dist2(g,i))[0]??(l?void 0:a)),h===void 0)return;const p=oe.applyToPoint(r.transform,h),f=oe.applyToPoint(oe.Inverse(t),p);e.setTo(f),r.didIntersect=!0}function $V(e,n,t){const{arrowheadEnd:r,arrowheadStart:o}=n.props,s=n.props.bend;if(Math.abs(s)>Math.abs(n.props.bend*(UV*n.props.scale)))return bv(e,n,t);const i=Ka(e,n,t),a=w.Med(i.start,i.end),l=w.Sub(i.end,i.start),c=w.Len(l)?l.uni():w.From(l),d=w.Add(a,c.per().mul(-s)),h=pf(e,n,"start"),p=pf(e,n,"end"),f=i.start.clone(),S=i.end.clone(),g=d.clone();if(w.Equals(f,S))return{bindings:t,isStraight:!0,start:{handle:f,point:f,arrowhead:n.props.arrowheadStart},end:{handle:S,point:S,arrowhead:n.props.arrowheadEnd},middle:g,isValid:!1,length:0};const x=n.props.bend<0,y=x?Fu:BM,v=GC(f,S,g),b=w.Angle(v.center,f),E=w.Angle(v.center,S),I=y(b,E);if(v.length===0||v.size===0||!oC(v.length)||!oC(v.size))return bv(e,n,t);const C=f.clone(),k=S.clone(),T=g.clone(),O=e.getShapePageTransform(n);let _=0,j=0,L=Wa*n.props.scale;if(h&&!h.isExact){const X=oe.applyToPoint(O,C),J=oe.applyToPoint(O,v.center),le=oe.applyToPoint(O,k),ye=oe.Inverse(h.transform),Me=oe.applyToPoint(ye,X),ae=oe.applyToPoint(ye,J),Ue=oe.applyToPoint(ye,le),{isClosed:Ae}=h,et=Ae?Sv:kC;let je,at=et(ae,v.radius,h.outline);if(at){const Ne=ae.angle(Me),Kn=ae.angle(Ue),Rt=y(Ne,Kn);at=at.filter(St=>y(Ne,ae.angle(St))<=Rt);const Pn=Rt*.25;at.sort(Ae?(St,Xt)=>Math.abs(y(Ne,ae.angle(St))-Pn)<Math.abs(y(Ne,ae.angle(Xt))-Pn)?-1:1:(St,Xt)=>y(Ne,ae.angle(St))<y(Ne,ae.angle(Xt))?-1:1),je=at[0]??(Ae?void 0:Me)}else je=Ae?void 0:Me;if(je&&(C.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(h.transform,je))),h.didIntersect=!0,o!=="none")){const Ne=Ts[n.props.size]/2+("size"in h.shape.props?Ts[h.shape.props.size]/2:0);_=(ff+Ne)*n.props.scale,L+=Ne*n.props.scale}}if(p&&!p.isExact){const X=oe.applyToPoint(O,C),J=oe.applyToPoint(O,k),le=oe.applyToPoint(O,v.center),ye=oe.Inverse(p.transform),Me=oe.applyToPoint(ye,X),ae=oe.applyToPoint(ye,le),Ue=oe.applyToPoint(ye,J),Ae=p.isClosed,et=Ae?Sv:kC;let je,at=et(ae,v.radius,p.outline);if(at){const Ne=ae.angle(Me),Kn=ae.angle(Ue),Rt=y(Ne,Kn),Pn=Rt*.75;at=at.filter(St=>y(Ne,ae.angle(St))<=Rt),at.sort(Ae?(St,Xt)=>Math.abs(y(Ne,ae.angle(St))-Pn)<Math.abs(y(Ne,ae.angle(Xt))-Pn)?-1:1:(St,Xt)=>y(Ne,ae.angle(St))<y(Ne,ae.angle(Xt))?-1:1),at[0]?je=at[0]:je=Ae?void 0:Ue}else je=Ae?void 0:Ue;if(je&&(k.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(p.transform,je))),p.didIntersect=!0,r!=="none")){const Ne=Ts[n.props.size]/2+("size"in p.shape.props?Ts[p.shape.props.size]/2:0);j=(ff+Ne)*n.props.scale,L+=Ne*n.props.scale}}let A=w.Angle(v.center,C),R=w.Angle(v.center,k),F=y(A,R),W=F*v.radius;const K=C.clone(),z=k.clone();if(_!==0&&K.setTo(v.center).add(w.FromAngle(A+F*(_/W*(x?1:-1))).mul(v.radius)),j!==0&&z.setTo(v.center).add(w.FromAngle(R+F*(j/W*(x?-1:1))).mul(v.radius)),w.DistMin(K,z,L)&&(_!==0&&j!==0?(_*=-1.5,j*=-1.5):_!==0?_*=-2:j!==0&&(j*=-2)),_!==0&&C.setTo(v.center).add(w.FromAngle(A+F*(_/W*(x?1:-1))).mul(v.radius)),j!==0&&k.setTo(v.center).add(w.FromAngle(R+F*(j/W*(x?-1:1))).mul(v.radius)),h&&p&&!h.isExact&&!p.isExact){A=w.Angle(v.center,C),R=w.Angle(v.center,k),F=y(A,R),W=F*v.radius;const X=r0(e,h.shape.id,p.shape.id);X==="double-bound"&&W<30?(C.setTo(f),k.setTo(S),T.setTo(g)):X==="safe"&&(h&&!h.didIntersect&&C.setTo(f),(p&&!p.didIntersect||y(b,A)>y(b,R))&&k.setTo(v.center).add(w.FromAngle(A+F*(Math.min(.9,Wa*n.props.scale/W)*(x?1:-1))).mul(v.radius)))}FV(v.center,v.radius,C,k,T,I,x),C.equals(k)&&(C.setTo(T.clone().addXY(1,1)),k.setTo(T.clone().subXY(1,1))),f.setTo(C),S.setTo(k),g.setTo(T);const U=GC(f,S,g);return{bindings:t,isStraight:!1,start:{point:f,handle:i.start,arrowhead:n.props.arrowheadStart},end:{point:S,handle:i.end,arrowhead:n.props.arrowheadEnd},middle:g,handleArc:v,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function GC(e,n,t){const r=$w(e,n,t),o=w.Dist(r,e),s=+w.Clockwise(e,t,n),i=((e.y-n.y)**2+(e.x-n.x)**2)**.5,a=((n.y-t.y)**2+(n.x-t.x)**2)**.5,l=((t.y-e.y)**2+(t.x-e.x)**2)**.5,c=Math.acos((a*a+l*l-i*i)/(2*a*l))*2,d=+(_e>c),h=(Re-c)*(s?1:-1),p=h*o;return{center:r,radius:o,size:h,length:p,largeArcFlag:d,sweepFlag:s}}function FV(e,n,t,r,o,s,i){const a=w.Angle(e,t),l=w.Angle(e,r);let c=Fu(a,l);if(i||(c=Re-c),o.setTo(e).add(w.FromAngle(a+c*(.5*(i?1:-1))).mul(n)),c>s){o.rotWith(e,_e);const d=r.clone();r.setTo(t),t.setTo(d)}}const NV=8;function zV(e){return Math.abs(e.props.bend)<NV*e.props.scale}function pf(e,n,t){const r=e.getBindingsFromShape(n,"arrow").find(l=>l.props.terminal===t);if(!r)return;const o=e.getShape(r.toId);if(!o)return;const s=e.getShapePageTransform(o),i=e.getShapeGeometry(o),a=i instanceof Hr?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function VC(e,n,t,r){const o=e.getShape(t.toId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=w.Add(s,w.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},i)),l=oe.applyToPoint(e.getShapePageTransform(o),a);return oe.applyToPoint(oe.Inverse(n),l)}else return new w(0,0)}function Mn(e,n){const t=e.getBindingsFromShape(n,"arrow");return{start:t.find(r=>r.props.terminal==="start"),end:t.find(r=>r.props.terminal==="end")}}const BV=TH("arrow info",(e,n)=>{const t=Mn(e,n);return zV(n)?bv(e,n,t):$V(e,n,t)});function co(e,n){const t=typeof n=="string"?n:n.id;return BV.get(e,t)}function Ka(e,n,t){var a,l;const r=e.getShapePageTransform(n),o=r0(e,(a=t.start)==null?void 0:a.toId,(l=t.end)==null?void 0:l.toId),s=t.start?VC(e,r,t.start,o==="double-bound"||o==="start-contains-end"):w.From(n.props.start),i=t.end?VC(e,r,t.end,o==="double-bound"||o==="end-contains-start"):w.From(n.props.end);return{start:s,end:i}}function cc(e,n,t,r){const o=typeof n=="string"?n:n.id,s=typeof t=="string"?t:t.id,i=e.getBindingsFromShape(o,"arrow").filter(l=>l.props.terminal===r.terminal);i.length>1&&e.deleteBindings(i.slice(1));const a=i[0];a?e.updateBinding({...a,toId:s,props:r}):e.createBinding({type:"arrow",fromId:o,toId:s,props:r})}function $h(e,n,t){const r=e.getBindingsFromShape(n,"arrow").filter(o=>o.props.terminal===t);e.deleteBindings(r)}const Wa=10,ff=10,UV=10,Ts={s:2,m:3.5,l:5,xl:10};function r0(e,n,t){if(!n||!t)return"safe";if(n===t)return"double-bound";const r=e.getShapePageBounds(n),o=e.getShapePageBounds(t);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}class Fh extends Rh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:n}){oy(this.editor,this.editor.getShape(n.fromId))}onAfterChange({bindingAfter:n}){oy(this.editor,this.editor.getShape(n.fromId))}onAfterChangeFromShape({shapeAfter:n}){oy(this.editor,n)}onAfterChangeToShape({binding:n}){G2(this.editor,n.fromId)}onBeforeIsolateFromShape({binding:n}){const t=this.editor.getShape(n.fromId);t&&gf({editor:this.editor,arrow:t,terminal:n.props.terminal})}}m(Fh,"type","arrow"),m(Fh,"props",lM),m(Fh,"migrations",cM);function G2(e,n){var x;const t=e.getShape(n);if(!t)return;const r=Mn(e,t),{start:o,end:s}=r,i=o?e.getShape(o.toId):void 0,a=s?e.getShape(s.toId):void 0,l=e.getAncestorPageId(t);if(!l)return;let c;if(i&&a)c=e.findCommonAncestor([i,a])??l;else if(i||a){const y=(x=i||a)==null?void 0:x.parentId;y&&y===t.parentId?c=t.parentId:c=l}else return;c&&c!==t.parentId&&e.reparentShapes([n],c);const d=e.getShape(n);if(!d)throw Error("no reparented arrow");const h=e.getShapeNearestSibling(d,i),p=e.getShapeNearestSibling(d,a);let f;if(h&&p)f=h.index>p.index?h:p;else if(h&&!p)f=h;else if(p&&!h)f=p;else return;let S;const g=e.getSortedChildIdsForParent(f.parentId).map(y=>e.getShape(y)).filter(y=>y.index>f.index);if(g.length){const y=g.find(v=>v.type!=="arrow");if(d.index>f.index&&(!y||d.index<y.index))return;S=uu(f.index,g[0].index)}else S=Lo(f.index);S!==d.index&&e.updateShapes([{id:n,type:"arrow",index:S}])}function oy(e,n){const t=Mn(e,n);for(const r of["start","end"]){const o=t[r];if(!o)continue;const s=e.getShape(o.toId),i=e.getAncestorPageId(n)===e.getAncestorPageId(s);(!s||!i)&&gf({editor:e,arrow:n,terminal:r,unbind:!0})}G2(e,n.id)}function gf({editor:e,arrow:n,terminal:t,unbind:r=!1,useHandle:o=!1}){const s=co(e,n);if(!s)throw new Error("expected arrow info");const i=o?s.start.handle:s.start.point,a=o?s.end.handle:s.end.point,l=t==="start"?i:a,c={id:n.id,type:"arrow",props:{[t]:{x:l.x,y:l.y},bend:n.props.bend}};if(!s.isStraight){const d=t==="start"?i:s.start.handle,h=t==="end"?a:s.end.handle,p=w.Med(d,h),f=w.Sub(d,h).per().uni().mul(s.handleArc.radius*2*Math.sign(n.props.bend)),S=Hu(s.handleArc.center,w.Add(p,f),s.handleArc.center,s.handleArc.radius);st((S==null?void 0:S.length)===1);const g=w.Dist(p,S[0])*Math.sign(n.props.bend);Us(g,c.props.bend)||(c.props.bend=g)}e.updateShape(c),r&&$h(e,n,t)}const V2=[Fh],Wt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},At={s:2,m:3.5,l:5,xl:10},yl={s:18,m:24,l:36,xl:44},Wo={s:18,m:22,l:26,xl:32},HV={s:18,m:20,l:24,xl:28},mo={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},KV=20,WV=4.25,Dr=16;/*!
|
|
* canvas-size
|
|
* v1.2.6
|
|
* https://github.com/jhildenbiddle/canvas-size
|
|
* (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
|
|
* MIT license
|
|
*/function GV(e,n){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var r,o,s,i,a=[],l=!0,c=!1;try{if(s=(t=t.call(e)).next,n===0){if(Object(t)!==t)return;l=!1}else for(;!(l=(r=s.call(t)).done)&&(a.push(r.value),a.length!==n);l=!0);}catch(d){c=!0,o=d}finally{try{if(!l&&t.return!=null&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function YC(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),t.push.apply(t,r)}return t}function Vn(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?YC(Object(t),!0).forEach(function(r){VV(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):YC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function VV(e,n,t){return n=nY(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function YV(e,n){if(e==null)return{};var t={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(n.indexOf(o)>=0)&&(t[o]=e[o]);return t}function XV(e,n){if(e==null)return{};var t=YV(e,n),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r])}return t}function XC(e,n){return ZV(e)||GV(e,n)||Y2(e,n)||eY()}function Gd(e){return qV(e)||QV(e)||Y2(e)||JV()}function qV(e){if(Array.isArray(e))return Pv(e)}function ZV(e){if(Array.isArray(e))return e}function QV(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Y2(e,n){if(e){if(typeof e=="string")return Pv(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor&&(t=e.constructor.name),t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Pv(e,n)}}function Pv(e,n){(n==null||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function JV(){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 eY(){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 tY(e,n){if(typeof e!="object"||e===null)return e;var t=e[Symbol.toPrimitive];if(t!==void 0){var r=t.call(e,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(e)}function nY(e){var n=tY(e,"string");return typeof n=="symbol"?n:String(n)}function Uc(e){var n=e.sizes.shift(),t=Math.max(Math.ceil(n[0]),1),r=Math.max(Math.ceil(n[1]),1),o=[t-1,r-1,1,1],s=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,l;i?(a=new OffscreenCanvas(1,1),l=new OffscreenCanvas(t,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,l=document.createElement("canvas"),l.width=t,l.height=r);var c=a.getContext("2d"),d=l.getContext("2d");d&&(d.fillRect.apply(d,o),c.drawImage(l,t-1,r-1,1,1,0,0,1,1));var h=c&&c.getImageData(0,0,1,1).data[3]!==0,p=Date.now()-s;return[a,l].forEach(function(f){f.height=0,f.width=0}),i?(postMessage({width:t,height:r,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&Uc(e)):h?e.onSuccess(t,r,p):(e.onError(t,r,p),e.sizes.length&&Uc(e)),h}var sy={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]},rY=["onError","onSuccess"],Ga={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},uc={};function iy(e){var n=e.width===e.height,t=e.height===1,r=e.width===1,o=[];if(!e.width||!e.height)e.sizes.forEach(function(d){var h=n||t?d:1,p=n||r?d:1;o.push([h,p])});else for(var s=e.min||Ga.min,i=e.step||Ga.step,a=Math.max(e.width,e.height);a>=s;){var l=n||t?a:1,c=n||r?a:1;o.push([l,c]),a-=i}return o}function Vd(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=XV(e,rY),a=null;if(!n)return!1;if(e.useWorker&&t){var l=`
|
|
var canvasTest = `.concat(Uc.toString(),`;
|
|
onmessage = function(e) {
|
|
canvasTest(e.data);
|
|
};
|
|
`),c=new Blob([l],{type:"application/javascript"}),d=URL.createObjectURL(c);a=new Worker(d),URL.revokeObjectURL(d),a.onmessage=function(h){var p=h.data,f=p.width,S=p.height,g=p.benchmark,x=p.isTestPass;x?(uc[r].onSuccess(f,S,g),delete uc[r]):uc[r].onError(f,S,g)}}if(e.usePromise)return new Promise(function(h,p){var f=Vn(Vn({},e),{},{onError:function(y,v,b){var E;if(e.sizes.length===0)E=!0;else{var I=e.sizes.slice(-1),C=XC(I,1),k=XC(C[0],2),T=k[0],O=k[1];E=y===T&&v===O}o(y,v,b),E&&p({width:y,height:v,benchmark:b})},onSuccess:function(y,v,b){s(y,v,b),h({width:y,height:v,benchmark:b})}});if(a){var S=f.onError,g=f.onSuccess;uc[r]={onError:S,onSuccess:g},a.postMessage(i)}else Uc(f)});if(a)uc[r]={onError:o,onSuccess:s},a.postMessage(i);else return Uc(e)}var ay={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=iy({width:n.max,height:n.max,min:n.min,step:n.step,sizes:Gd(sy.area)}),r=Vn(Vn(Vn({},Ga),n),{},{sizes:t});return Vd(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=iy({width:1,height:n.max,min:n.min,step:n.step,sizes:Gd(sy.height)}),r=Vn(Vn(Vn({},Ga),n),{},{sizes:t});return Vd(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=iy({width:n.max,height:1,min:n.min,step:n.step,sizes:Gd(sy.width)}),r=Vn(Vn(Vn({},Ga),n),{},{sizes:t});return Vd(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Vn(Vn({},Ga),n);return t.sizes=Gd(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),Vd(t)}};let ly=null;function oY(){return ly||(ly=sY()),ly}async function sY(){const e=await ay.maxWidth({usePromise:!0}),n=await ay.maxHeight({usePromise:!0}),t=await ay.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const qC=8192,iY=4096*4096;async function aY(e,n){if(e<=qC&&n<=qC&&e*n<=iY)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await oY(),s=e/n;if(e>t&&(e=t,n=e/s),n>r&&(n=r,e=n*s),e*n>o){const i=Math.sqrt(o/(e*n));e*=i,n*=i}return[e,n]}function lY(e,n){const t=e.w/n.w,r=e.h/n.h;return t<=1&&r<=1?e:t>r?{w:e.w/t,h:e.h/t}:{w:e.w/r,h:e.h/r}}function cY(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function uY(e){const n=new URL(e).host.replace("www.","");for(const t of $u)if(X2(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const dY=e=>e.split("*").map(n=>cY(n)).join(".+"),X2=(e,n)=>!!e.find(t=>{const r=new RegExp(dY(t));return n.match(r)});function hY(e){const n=new URL(e).host.replace("www.","");for(const t of $u)if(X2(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function q2(e){return hY(e)??uY(e)}function Ms(e){try{return q2(e)}catch(n){console.error(n)}}/*!
|
|
* 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 Va=" ",pn=class pn{static insertTextFirefox(n,t){n.setRangeText(t,n.selectionStart||0,n.selectionEnd||0,"end"),n.dispatchEvent(new InputEvent("input",{data:t,inputType:"insertText",isComposing:!1}))}static insert(n,t){const r=n.ownerDocument,o=r.activeElement;o!==n&&n.focus(),r.execCommand("insertText",!1,t)||pn.insertTextFirefox(n,t),o===r.body?n.blur():o instanceof HTMLElement&&o!==n&&o.focus()}static set(n,t){n.select(),pn.insert(n,t)}static getSelection(n){const{selectionStart:t,selectionEnd:r}=n;return n.value.slice(t||void 0,r||void 0)}static wrapSelection(n,t,r){const{selectionStart:o,selectionEnd:s}=n,i=pn.getSelection(n);pn.insert(n,t+i+(r??t)),n.selectionStart=(o||0)+t.length,n.selectionEnd=(s||0)+t.length}static replace(n,t,r){let o=0;n.value.replace(t,(...s)=>{const i=o+s[s.length-2],a=s[0].length;n.selectionStart=i,n.selectionEnd=i+a;const l=typeof r=="string"?r:r(...s);return pn.insert(n,l),n.selectionStart=i,o+=l.length-a,l})}static findLineEnd(n,t){const r=n.lastIndexOf(`
|
|
`,t-1)+1;return n.charAt(r)!==" "?t:r+1}static indent(n){var a;const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.slice(t,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const l=o.lastIndexOf(`
|
|
`,t-1)+1,c=n.value.slice(l,r-1),d=c.replace(/^|\n/g,`$&${Va}`),h=d.length-c.length;n.setSelectionRange(l,r-1),pn.insert(n,d),n.setSelectionRange(t+1,r+h)}else pn.insert(n,Va)}static unindent(n){const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.lastIndexOf(`
|
|
`,t-1)+1,i=pn.findLineEnd(o,r),a=n.value.slice(s,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;n.setSelectionRange(s,i),pn.insert(n,l);const d=/\t| {1,2}/.exec(o.slice(s,t)),h=d?d[0].length:0,p=t-h;n.setSelectionRange(t-h,Math.max(p,r-c))}static indentCE(n){var l;const t=window.getSelection(),r=n.innerText,o=Yd(n)??0,s=Yd(n)??0,i=r.slice(o,s),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
|
|
`,o-1)+1,d=r.slice(c,s-1),p=d.replace(/^|\n/g,`$&${Va}`).length-d.length;t&&t.setBaseAndExtent(n,o+1,n,s+p)}else{const c=window.getSelection();n.innerText=r.slice(0,o)+Va+r.slice(o),c==null||c.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=Yd(n)??0,s=Yd(n)??0,i=r.lastIndexOf(`
|
|
`,o-1)+1,a=pn.findLineEnd(r,s),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),d=l.length-c.length;if(t){t.setBaseAndExtent(n,i,n,a);const h=/\t| {1,2}/.exec(r.slice(i,o)),p=h?h[0].length:0,f=o-p;t.setBaseAndExtent(n,o-p,n,Math.max(f,s-d))}}static normalizeText(n){return n.replace(pn.fixNewLines,`
|
|
`)}static normalizeTextForDom(n){return n.replace(pn.fixNewLines,`
|
|
`).split(`
|
|
`).map(t=>t||" ").join(`
|
|
`)}};m(pn,"fixNewLines",/\r?\n|\r/g);let Sl=pn;function Yd(e){if(typeof window.getSelection>"u")return;const n=window.getSelection();if(!n)return;let t=0;if(n.rangeCount!==0){const r=n.getRangeAt(0),o=r.cloneRange();o.selectNodeContents(e),o.setEnd(r.endContainer,r.endOffset),t=o.toString().length}return t}const pY=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function Z2(e){return pY.test(e)}function fY(e){return e.replace(/\t/g,Va)}function gY(e){const n=e.split(`
|
|
`);for(;n[0]&&n[0].trim().length===0;)n.shift();let t=1/0;for(const r of n)if(r.trim().length>0){const o=r.length-r.trimStart().length;t=Math.min(t,o)}return n.map(r=>r.slice(t)).join(`
|
|
`)}function mY(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function yY(e){return mY(gY(fY(e)))}function SY(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i},a){e.registerExternalAssetHandler("file",async({file:l})=>{const c=l.name;let d=l;const h=r.includes(d.type),p=o.includes(d.type);st(h||p,`File type not allowed: ${d.type}`),st(d.size<=t,`File size too big: ${(d.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),d.type==="video/quicktime"&&(d=new Blob([d],{type:"video/mp4"}));let f=h?await ao.getImageSize(d):await ao.getVideoSize(d);const S=await ao.isAnimated(d)||p,g=await A6(await d.arrayBuffer());if(isFinite(n)){const v=lY(f,{w:n,h:n});f!==v&&ao.isStaticImageType(d.type)&&(f=v)}const x=ki.createId(g),y={id:x,type:h?"image":"video",typeName:"asset",props:{name:c,src:"",w:f.w,h:f.h,fileSize:d.size,mimeType:d.type,isAnimated:S}};return a?(y.props.src=x,await EV({persistenceKey:a,assetId:x,blob:d})):y.props.src=await Oi.blobToDataUrl(d),ki.create(y)}),e.registerExternalAssetHandler("url",async({url:l})=>{var d,h,p,f,S;let c;try{const x=await(await yo(l,{method:"GET",mode:"no-cors"})).text(),y=new DOMParser().parseFromString(x,"text/html");c={image:((d=y.head.querySelector('meta[property="og:image"]'))==null?void 0:d.getAttribute("content"))??"",favicon:((h=y.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:h.getAttribute("href"))??((p=y.head.querySelector('link[rel="icon"]'))==null?void 0:p.getAttribute("href"))??"",title:((f=y.head.querySelector('meta[property="og:title"]'))==null?void 0:f.getAttribute("content"))??l,description:((S=y.head.querySelector('meta[property="og:description"]'))==null?void 0:S.getAttribute("content"))??""},c.image.startsWith("/")&&(c.image=new URL(c.image,l).href),c.favicon.startsWith("/")&&(c.favicon=new URL(c.favicon,l).href)}catch(g){console.error(g),s.addToast({title:i("assets.url.failed"),severity:"error"}),c={image:"",favicon:"",title:"",description:""}}return{id:ki.createId(ov(l)),typeName:"asset",type:"bookmark",props:{src:l,description:c.description,image:c.image,favicon:c.favicon,title:c.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:l,text:c})=>{const d=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=new DOMParser().parseFromString(c,"image/svg+xml").querySelector("svg");if(!h)throw new Error("No <svg/> element present");let p=parseFloat(h.getAttribute("width")||"0"),f=parseFloat(h.getAttribute("height")||"0");if(!(p&&f)){document.body.appendChild(h);const g=h.getBoundingClientRect();document.body.removeChild(h),p=g.width,f=g.height}const S=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});if(!S)throw Error("Could not create an asset");ZC(e,[S],d)}),e.registerExternalContentHandler("embed",({point:l,url:c,embed:d})=>{const h=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),{width:p,height:f}=d,S=$e(),g={id:S,type:"embed",x:h.x-(p||450)/2,y:h.y-(f||450)/2,props:{w:p,h:f,url:c}};e.createShapes([g]).select(S)}),e.registerExternalContentHandler("files",async({point:l,files:c})=>{const d=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=new w(d.x,d.y),p=[];await Promise.all(c.map(async(f,S)=>{if(f.size>t)return console.warn(`File size too big: ${(f.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),null;if(!f.type)throw new Error("No mime type");if(!r.concat(o).includes(f.type))return console.warn(`${f.name} not loaded - Extension not allowed.`),null;try{const g=await e.getAssetForExternalContent({type:"file",file:f});if(!g)throw Error("Could not create an asset");p[S]=g}catch(g){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(g),null}})),ZC(e,me(p),h)}),e.registerExternalContentHandler("text",async({point:l,text:c})=>{const d=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=e.getShapeUtil("text").getDefaultProps(),p=yY(c),f=e.getOnlySelectedShape();if(f&&"text"in f.props){e.updateShapes([{id:f.id,type:f.type,props:{text:p}}]);return}let S,g,x,y="middle";const v=p.split(`
|
|
`).length>1,b=Z2(p);v&&(y=v?b?"end":"start":"middle");const E=e.textMeasure.measureText(p,{...Wt,fontFamily:mo[h.font],fontSize:yl[h.size],maxWidth:null}),I=Math.min(v?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(E.w>I){const C=e.textMeasure.measureText(p,{...Wt,fontFamily:mo[h.font],fontSize:yl[h.size],maxWidth:I});S=C.w,g=C.h,x=!1,y=b?"end":"start"}else S=E.w,g=E.h,x=!0;d.y-g/2<e.getViewportPageBounds().minY+40&&(d.y=e.getViewportPageBounds().minY+40+g/2),e.createShapes([{id:$e(),type:"text",x:d.x-S/2,y:d.y-g/2,props:{text:p,textAlign:y,autoSize:x,w:S}}])}),e.registerExternalContentHandler("url",async({point:l,url:c})=>{const d=Ms(c);if(d)return e.putExternalContent({type:"embed",url:d.url,point:l,embed:d.definition});const h=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),p=ki.createId(ov(c)),f=vY(e,c,h);let S=e.getAsset(p),g=!1;if(!S){g=!0;try{const x=await e.getAssetForExternalContent({type:"url",url:c});if(!x)throw Error("Could not create an asset");S=x}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{g&&e.createAssets([S]),e.updateShapes([{id:f.id,type:f.type,props:{assetId:S.id}}])})})}async function ZC(e,n,t){if(!n.length)return[];const r=w.From(t),o=[];for(let s=0;s<n.length;s++){const i=n[s];switch(i.type){case"bookmark":{o.push({id:$e(),type:"bookmark",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,url:i.props.src}}),r.x+=300;break}case"image":{o.push({id:$e(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":o.push({id:$e(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}}return e.batch(()=>{const s=n.filter(i=>!e.getAsset(i.id));s.length&&e.createAssets(s),e.createShapes(o).select(...o.map(i=>i.id)),Q2(e,t)}),o.map(s=>s.id)}function Q2(e,n){const t=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const o=r.center.sub(n);e.updateShapes(e.getSelectedShapes().map(s=>{const i=e.getShapeParentTransform(s).decompose().rotation,a=w.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!t.contains(r)&&e.zoomToSelection()}function vY(e,n,t){const r={id:$e(),type:"bookmark",x:t.x-150,y:t.y-160,opacity:1,props:{assetId:null,url:n}};return e.batch(()=>{e.createShapes([r]).select(r.id),Q2(e,t)}),e.getShape(r.id)}const xY=new Zo,wY=e=>async n=>!n||!n.props.src?null:e&&n.props.src.startsWith("asset:")?await xY.get(n,async()=>await bY(e,n.id)):n.type==="video"?n.props.src:n.type!=="image"?null:n.props.src;async function bY(e,n){const t=await IV({assetId:n,persistenceKey:e});return t?URL.createObjectURL(t):null}var Oy;let PY=(Oy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")});m(this,"onKeyUp",t=>{var r;if(t.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",{...t,target:"shape",shape:o}))}})}},m(Oy,"id","idle"),Oy);var Dy;let CY=(Dy=class extends se{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onEnter",()=>{this.didTimeout=!1;const t=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});t?this.editor.setHintingShapes([t.id]):this.createArrowShape(),this.startPreciseTimeout()});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:{id:"end",type:"vertex",index:"a3",x:0,y:0},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 d;const{originPagePoint:t}=this.editor.inputs,r=$e();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShape({id:r,type:"arrow",x:t.x,y:t.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=s.find(h=>h.id==="start"),c=(d=i.onHandleDrag)==null?void 0:d.call(i,o,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});c&&this.editor.updateShapes([c]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var o,s;const t=this.shape;if(!t)throw Error("expected shape");const r=this.editor.getShapeHandles(t);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=r.find(d=>d.id==="start"),c=(o=i.onHandleDrag)==null?void 0:o.call(i,t,{handle:{...l,x:0,y:0},isPrecise:this.didTimeout,initial:a});c&&this.editor.updateShapes([c])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),c=r.find(h=>h.id==="end"),d=(s=i.onHandleDrag)==null?void 0:s.call(i,this.editor.getShape(t),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});d&&this.editor.updateShapes([d])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},m(Dy,"id","pointing"),Dy);class Nh extends se{constructor(){super(...arguments);m(this,"shapeType","arrow")}}m(Nh,"id","arrow"),m(Nh,"initial","idle"),m(Nh,"children",()=>[PY,CY]);class o0 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,"isPenOrStylus",!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",t=>{this.markId=null,this.info=t,this.canDraw=!this.editor.getIsMenuOpen(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()});m(this,"onPointerMove",()=>{const{inputs:t}=this.editor;if(this.isPen&&!t.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&t.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(this.isPenOrStylus?w.Dist(t.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=t.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())});m(this,"onKeyDown",t=>{if(t.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()});m(this,"onKeyUp",t=>{if(t.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()});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(t,r){if(!this.canClose())return!1;const o=At[r],s=t[0].points[0],i=t[t.length-1],a=i.points[i.points.length-1];return s!==a&&this.currentLineLength>o*4&&w.DistMin(s,a,o*2)}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+ot(),this.editor.mark(this.markId);const{z:o=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||o>0&&o<.5||o>.5&&o<1;const s=this.isPenOrStylus?o*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=t.clone(),this.initialShape){const a=this.editor.getShape(this.initialShape.id);if(a&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const l=Nt(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=Nt(l.points);if(!c)throw Error("Expected a previous point!");const{x:d,y:h}=this.editor.getPointInShapeSpace(a,t).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+s.toFixed(2)},{x:d,y:h,z:+s.toFixed(2)}]},f=oe.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,p];this.currentLineLength<At[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const g={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(g.props.isClosed=this.getIsClosed(S,a.props.size)),this.editor.updateShapes([g]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const i=$e();this.editor.createShapes([{id:i,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+s.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:o,props:{size:s}}=t,i=this.editor.getShape(o);if(!i)return;const{segments:a}=i.props,{x:l,y:c,z:d}=this.editor.getPointInShapeSpace(i,r.currentPagePoint).toFixed(),h=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,p={x:l,y:c,z:h};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:f}=this;if(f===null)throw Error("We should have a point where the segment changed");if(w.Dist2(f,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const g=Nt(a);if(!g)throw Error("Expected a previous segment!");const x=Nt(g.points);if(!x)throw Error("Expected a previous last point!");let y;const v=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(g.type==="straight"){this.currentLineLength+=w.Dist(x,v),y={type:"straight",points:[{...x},v]};const E=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(E,x)}else y={type:"straight",points:[v,p]};const b={id:o,type:this.shapeType,props:{segments:[...a,y]}};this.canClose()&&(b.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([b])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:f}=this;if(f===null)throw Error("We should have a point where the segment changed");if(w.Dist2(f,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const g=a.slice(),x=g[g.length-1],y=Nt(x.points);if(!y)throw Error("No previous point!");const v={type:"free",points:[...w.PointsBetween(y,p,6).map(I=>({x:$o(I.x),y:$o(I.y),z:$o(I.z)}))]},b=[...g,v];this.currentLineLength<At[i.props.size]*4&&(this.currentLineLength=this.getLineLength(b));const E={id:o,type:this.shapeType,props:{segments:b}};this.canClose()&&(E.props.isClosed=this.getIsClosed(b,s)),this.editor.updateShapes([E])}break}case"straight":{const f=a.slice(),S=f[f.length-1],{pagePointWhereCurrentSegmentChanged:g}=this,{ctrlKey:x,currentPagePoint:y}=this.editor.inputs;if(!g)throw Error("We should have a point where the segment changed");let v,b=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(b=!x,this.didJustShiftClickToExtendPreviousShapeLine=!1):b=!x;let E=this.editor.getPointInShapeSpace(i,y).toFixed().toJson(),I=!1,C;if((this.editor.user.getIsSnapMode()?!x:x)&&f.length>2){let O,_=8/this.editor.getZoomLevel();for(let j=0,L=a.length-2;j<L;j++){const A=a[j];if(!A)break;if(A.type==="free")continue;const R=A.points[0],F=Nt(A.points);if(!(R&&F))continue;const W=w.NearestPointOnLineSegment(R,F,E);if(w.DistMin(W,E,_)){O=W.toFixed().toJson(),_=w.Dist(W,E),C=A;break}}O&&(I=!0,E=O)}if(I&&C){const O=this.editor.getShapePageTransform(i),_=C.points[0],j=Nt(C.points);if(!j)throw Error("Expected a last point!");const L=oe.applyToPoint(O,_),A=oe.applyToPoint(O,j),R=oe.applyToPoint(O,E);this.editor.snaps.setIndicators([{id:ot(),type:"points",points:[L,R,A]}])}else{if(this.editor.snaps.clearIndicators(),b){const O=w.Angle(g,y),j=cf(O,24)-O;v=w.RotWith(y,g,j)}else v=y;E=this.editor.getPointInShapeSpace(i,v).toFixed().toJson()}this.currentLineLength+=w.Dist(S.points[0],E),f[f.length-1]={...S,type:"straight",points:[S.points[0],E]};const T={id:o,type:this.shapeType,props:{segments:f}};this.canClose()&&(T.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([T]);break}case"free":{const f=a.slice(),S=f[f.length-1],g=[...S.points];if(g.length&&this.mergeNextPoint){const{z:y}=g[g.length-1];g[g.length-1]={x:p.x,y:p.y,z:y?Math.max(y,p.z):p.z}}else this.currentLineLength+=w.Dist(g[g.length-1],p),g.push(p);f[f.length-1]={...S,points:g},this.currentLineLength<At[i.props.size]*4&&(this.currentLineLength=this.getLineLength(f));const x={id:o,type:this.shapeType,props:{segments:f}};if(this.canClose()&&(x.props.isClosed=this.getIsClosed(f,s)),this.editor.updateShapes([x]),g.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const y=$e(),v=this.editor.getShape(o).props;this.editor.createShapes([{id:y,type:this.shapeType,x:$o(r.currentPagePoint.x),y:$o(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:v.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(d*1.25).toFixed():.5}]}]}}]),this.initialShape=rt(this.editor.getShape(y)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(t){let r=0;for(const o of t)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=w.Dist2(a,i)}return Math.sqrt(r)}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:t}=this;t&&(this.editor.updateShapes([{id:t.id,type:t.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}m(o0,"id","drawing");var Ry;let J2=(Ry=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("drawing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ry,"id","idle"),Ry);class zh extends se{constructor(){super(...arguments);m(this,"shapeType","draw");m(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}m(zh,"id","draw"),m(zh,"initial","idle"),m(zh,"children",()=>[J2,o0]);class Cv extends Lh{constructor(){super(...arguments);m(this,"shapeType","frame");m(this,"onCreate",t=>{if(!t)return;const r=this.editor.getShapePageBounds(t),o=[],s=this.editor.getShapeAncestors(t).map(i=>i.id);this.editor.getSortedChildIdsForParent(t.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===t.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&IY(a,s,t)&&o.push(a.id)}),this.editor.reparentShapes(o,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}m(Cv,"id","frame"),m(Cv,"initial","idle");function IY(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var Ly;let EY=(Ly=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onKeyUp",t=>{var r;if(t.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",{...t,target:"shape",shape:o}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ly,"id","idle"),Ly);var $y;let kY=($y=class extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=$e();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(Fr),scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]).select(o).setCurrentTool("select.resizing",{...t,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:t}=this.editor.inputs,r=$e();this.markId=`creating:${r}`,this.editor.mark(this.markId);const o=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(Fr),i=s==="star"?{w:200,h:190}:s==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:r,type:"geo",x:t.x,y:t.y,props:{geo:this.editor.getStyleForNextShape(Fr),scale:o,...i}}]);const a=this.editor.getShape(r);if(!a)return;const{w:l,h:c}=a.props,d=new w(l/2,c/2).mul(o),h=this.editor.getShapeParentTransform(a);h&&d.rot(-h.rotation()),this.editor.select(r),this.editor.updateShape({id:a.id,type:"geo",x:a.x-d.x,y:a.y-d.y,props:{geo:this.editor.getStyleForNextShape(Fr),w:l*o,h:c*o}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},m($y,"id","pointing"),$y);class Bh extends se{constructor(){super(...arguments);m(this,"shapeType","geo")}}m(Bh,"id","geo"),m(Bh,"initial","idle"),m(Bh,"children",()=>[EY,kY]);class Uh extends se{constructor(){super(...arguments);m(this,"shapeType","highlight");m(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}m(Uh,"id","highlight"),m(Uh,"initial","idle"),m(Uh,"children",()=>[J2,o0]);var Fy;let _Y=(Fy=class extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"onEnter",t=>{this.shapeId=t.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(Fy,"id","idle"),Fy);const QC=2;var Ny;let TY=(Ny=class extends se{constructor(){super(...arguments);m(this,"shape",{});m(this,"markId");m(this,"onEnter",t=>{const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=t.shapeId&&this.editor.getShape(t.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(on),l=a[a.length-1],c=a[a.length-2],d=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new w(this.shape.x,this.shape.y)),h=w.Sub(o,d).addXY(.1,.1),p=rt(this.shape.props.points);if(w.DistMin(l,c,QC)||w.DistMin(h,l,QC))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=Lo(l.index);p[f]={id:f,index:f,x:h.x,y:h.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=$e();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});m(this,"onPointerMove",()=>{if(this.shape&&this.editor.inputs.isDragging){const t=this.editor.getShapeHandles(this.shape);if(!t)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Nt(t);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(Ny,"id","pointing"),Ny);class Hh extends se{constructor(){super(...arguments);m(this,"shapeType","line")}}m(Hh,"id","line"),m(Hh,"initial","idle"),m(Hh,"children",()=>[_Y,TY]);var zy;let MY=(zy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(zy,"id","idle"),zy);function Ke(e,n){var o;const t=new Set;for(const s of n){const i=e.getShape(s);if(!i)continue;e.getShapeUtil(i).onDragShapesOut&&t.add(i);const a=e.getShape(i.parentId);a&&e.getShapeUtil(a).onDragShapesOut&&t.add(a)}const r=new Map;for(const s of t){const i=ej(e,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=e.getShapeUtil(s),l=me(i.map(c=>e.getShape(c)));(o=a.onDragShapesOut)==null||o.call(a,s,l)}}function ej(e,n){const t=e.getSortedChildIdsForParent(n.id);if(t.length===0)return[];const r=e.getShapePageBounds(n);if(!r)return[];let o,s,i;const a=[];for(const l of t){const c=e.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}o??(o=e.getShapeGeometry(n)),s??(s=e.getShapePageTransform(n)),i??(i=s.applyToPoints(o.vertices));const d=e.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:p}=e.getShapeGeometry(l);if(!h.some(f=>tr(f,d))){if(p){if(I2(d,h))continue}else if(DW(d,h))continue;a.push(l)}}return a}function mf(e,n,t=!1){e.select(n),e.setEditingShape(n),e.setCurrentTool("select.editing_shape",{target:"shape",shape:n}),t&&e.emit("select-all-text",{shapeId:n.id}),tj(e)}const jY=16;function tj(e){const n=e.getSelectionPageBounds(),t=e.getViewportPageBounds();if(n&&!t.contains(n)){const r=n.clone().expandBy(jY/e.getZoomLevel()).expand(t),o=t.clone().translate({x:(r.center.x-t.center.x)*2,y:(r.center.y-t.center.y)*2});e.zoomToBounds(o,{animation:{duration:e.options.animationMediumMs},inset:0})}}const _i=20,AY=0,Be=200,hg=new w(Be/2,Be/2),nj=10,OY=[[["a1"],new w(Be*.5,Be*-.5-_i)],[["a2"],new w(Be*1.5+_i,Be*.5)],[["a3"],new w(Be*.5,Be*1.5+_i)],[["a4"],new w(Be*-.5-_i,Be*.5)]];function DY(e){if(e===1)return OY;const n=Be*e,t=_i*e;return[[["a1"],new w(n*.5,n*-.5-t)],[["a2"],new w(n*1.5+t,n*.5)],[["a3"],new w(n*.5,n*1.5+t)],[["a4"],new w(n*-.5-t,n*.5)]]}function rj(e,n,t,r,o){return Object.fromEntries(DY(o).map(([s,i],a)=>{const l=i.clone();return a===0&&r?l.y-=r:a===2&&t&&(l.y+=t),[s,l.rot(n).add(e)]}))}function oj(e,n,t,r){const o=new Set(e.getSelectedShapeIds()),s=(Be+_i+r)**2,i=new Map,a=[];for(const d of e.getCurrentPageShapes()){if(!e.isShapeOfType(d,"note")||t!==d.props.scale||o.has(d.id))continue;const h=e.getShapePageTransform(d.id);n===h.rotation()&&(i.set(d,e.getShapePageBounds(d).center),a.push(...Object.values(rj(h.point(),n,d.props.growY,r,t))))}const l=a.length;let c;for(const[d,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(w.Dist2(h,c)>s||e.isPointInShape(d,c)&&(a[p]=void 0));return me(a)}function sj(e,n,t,r,o=!1){let s;const i=e.getCurrentPageShapesSorted(),a=(Be+_i**2)**n.props.scale;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==n.id){const d=e.getShapePageBounds(c);if(d&&w.Dist2(d.center,t)<a&&e.isPointInShape(c,t)){s=c;break}}}if(e.complete(),!s||o){e.mark("creating note shape");const l=$e();e.createShape({id:l,type:"note",x:t.x,y:t.y,rotation:r,opacity:n.opacity,props:{...n.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const c=e.getShape(l);if(!c)return;const d=e.getPointInParentSpace(c,w.Sub(t,w.Rot(hg.clone().mul(c.props.scale),r)));e.updateShape({id:l,type:"note",x:d.x,y:d.y}),s=e.getShape(l)}return tj(e),s}var By;let RY=(By=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:t}=this;if(this.wasFocusedOnEnter=!t.getIsMenuOpen(),this.wasFocusedOnEnter){const r=$e();this.markId=`creating:${r}`,t.mark(this.markId);const o=this.editor.inputs.originPagePoint.clone(),s=JC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=eI(this.editor,r,o)}});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=$e(),o=this.editor.inputs.originPagePoint.clone(),s=JC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=eI(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...t,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(By,"id","pointing"),By);function JC(e,n,t){let r=nj/e.getZoomLevel(),o;for(const s of oj(e,0,t,0)){const i=w.Sub(n,s),a=i.len();a<r&&(r=a,o=i)}return o}function eI(e,n,t){e.createShape({id:n,type:"note",x:t.x,y:t.y,props:{scale:e.user.getIsDynamicResizeMode()?1/e.getZoomLevel():1}}).select(n);const r=e.getShape(n),o=e.getShapeGeometry(r).bounds;return e.updateShapes([{id:n,type:"note",x:r.x-o.width/2,y:r.y-o.height/2}]),e.getShape(n)}class Kh extends se{constructor(){super(...arguments);m(this,"shapeType","note")}}m(Kh,"id","note"),m(Kh,"initial","idle"),m(Kh,"children",()=>[MY,RY]);function LY(e){const n=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),renderingOnly:!0});if(!n)return e.setHoveredShape(null);let t;const r=e.getOutermostSelectableShape(n);return r===n||r.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(r.id)?t=n:t=r,e.setHoveredShape(t.id)}const Bo=fw(LY,32);var Uy;let $Y=(Uy=class extends se{constructor(){super(...arguments);m(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Bo(this.editor)}});m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onExit",()=>{Bo.cancel()});m(this,"onKeyDown",t=>{var r;if(t.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",{...t,target:"shape",shape:o}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Uy,"id","idle"),Uy);var Hy;let FY=(Hy=class extends se{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onExit",()=>{this.editor.setHintingShapes([])});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,o=$e();this.markId=`creating:${o}`,this.editor.mark(this.markId);const s=this.createTextShape(o,r,!1);if(!s){this.cancel();return}this.shape=this.editor.getShape(s),this.editor.select(o),this.editor.setCurrentTool("select.resizing",{...t,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:18,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 t=$e(),{currentPagePoint:r}=this.editor.inputs;this.createTextShape(t,r,!0)&&(this.editor.select(t),this.editor.setEditingShape(t),this.editor.setCurrentTool("select"),(s=this.editor.root.getCurrent())==null||s.transition("editing_shape"))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(t,r,o){this.editor.createShape({id:t,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:o,w:20,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const s=this.editor.getShape(t);if(!s){this.cancel();return}const i=this.editor.getShapePageBounds(s),a=new w;if(o)switch(s.props.textAlign){case"start":{a.x=0;break}case"middle":{a.x=-i.width/2;break}case"end":{a.x=-i.width;break}}else a.x=0;if(a.y=-i.height/2,kn(s.parentId)){const l=this.editor.getShapeParentTransform(s);a.rot(-l.rotation())}return this.editor.updateShape({...s,x:s.x+a.x,y:s.y+a.y}),s}},m(Hy,"id","pointing"),Hy);class Wh extends se{constructor(){super(...arguments);m(this,"shapeType","text")}}m(Wh,"id","text"),m(Wh,"initial","idle"),m(Wh,"children",()=>[$Y,FY]);const NY=[Wh,zh,Bh,Kh,Hh,Cv,Nh,Uh];function _r(){return ss({isDarkMode:Wu()})}function vl(e){return{key:`${So.id}:${e}`,getElement:async()=>{const n=zY(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await yo(t)).blob(),s=await Oi.blobToDataUrl(o),i=r.replace(t,s);return u.jsx("style",{children:i})}}}function zY(e){const n=oM[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function s0(e){return{key:`${So.id}:${e}`,getElement:async()=>e!=="pattern"?null:u.jsx(BY,{})}}function BY(){const e=_r(),n=8/12;return u.jsxs(u.Fragment,{children:[u.jsxs("mask",{id:"hash_pattern_mask",children:[u.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),u.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[u.jsx("line",{x1:n*1,y1:n*3,x2:n*3,y2:n*1}),u.jsx("line",{x1:n*5,y1:n*7,x2:n*7,y2:n*5}),u.jsx("line",{x1:n*9,y1:n*11,x2:n*11,y2:n*9})]})]}),u.jsx("pattern",{id:yf(1,e.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:u.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function i0(){return{key:`${So.id}:pattern`,component:WY}}const Ic=8,tI=(e,n,t)=>new Promise((r,o)=>{const s=Ic*n*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?tf.darkMode.solid:tf.lightMode.solid,a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*n*e;const l=8/12,c=d=>d*n*e;a.beginPath(),a.moveTo(c(l*1),c(l*3)),a.lineTo(c(l*3),c(l*1)),a.moveTo(c(l*5),c(l*7)),a.lineTo(c(l*7),c(l*5)),a.moveTo(c(l*9),c(l*11)),a.lineTo(c(l*11),c(l*9)),a.stroke(),i.toBlob(d=>{!d||wt.throwToBlob.get()?o():r(d)})}),nI=(e,n)=>{const t=document.createElement("canvas");t.width=e[0],t.height=e[1];const r=t.getContext("2d");return r?(n(r),t.toDataURL()):""};let cy=null;function UY(){return cy||(cy={white:nI([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:nI([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),cy}function ij(e){return Math.ceil(Math.log2(Math.max(1,e)))}function yf(e,n){const t=ij(e);return`tldraw_hash_pattern_${n}_${t}`}function aj(e){const n=[],r=ij(e);for(let o=0;o<=r;o++)n.push(Math.pow(2,o));return n}function HY(e){const n=UY();return aj(e).flatMap(t=>[{zoom:t,url:n.white,theme:"light"},{zoom:t,url:n.black,theme:"dark"}])}function KY(){const e=B(),n=G("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),t=G("maxZoom",()=>Math.ceil(Nt(e.getCameraOptions().zoomSteps)),[e]),[r,o]=P.useState(!1),[s,i]=P.useState(()=>HY(t));return P.useEffect(()=>{const l=Promise.all(aj(t).flatMap(d=>[tI(n,d,!1).then(h=>({zoom:d,theme:"light",url:URL.createObjectURL(h)})),tI(n,d,!0).then(h=>({zoom:d,theme:"dark",url:URL.createObjectURL(h)}))]));let c=!1;return l.then(d=>{c||(i(d),o(!0))}),()=>{c=!0,o(!1),l.then(d=>{for(const{url:h}of d)URL.revokeObjectURL(h)})}},[n,t]),{defs:u.jsx(u.Fragment,{children:s.map(l=>{const c=yf(l.zoom,l.theme);return u.jsx("pattern",{id:c,width:Ic,height:Ic,patternUnits:"userSpaceOnUse",children:u.jsx("image",{href:l.url,width:Ic,height:Ic})},c)})}),isReady:r}}function WY(){const e=B(),n=P.useRef(null),{defs:t,isReady:r}=KY();return P.useEffect(()=>{if(r&&e.environment.isSafari){const o=lj(n.current);o&&e.timers.requestAnimationFrame(()=>{o.style.display="none",e.timers.requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),u.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function lj(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?lj(e.parentElement):null}const en=xe.memo(function({theme:n,d:t,color:r,fill:o,scale:s}){switch(o){case"none":return null;case"solid":return u.jsx("path",{fill:n[r].semi,d:t});case"semi":return u.jsx("path",{fill:n.solid,d:t});case"fill":return u.jsx("path",{fill:n[r].fill,d:t});case"pattern":return u.jsx(GY,{theme:n,color:r,fill:o,d:t,scale:s})}});function GY({d:e,color:n,theme:t}){const r=B(),o=M2(),s=G("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return u.jsxs(u.Fragment,{children:[u.jsx("path",{fill:t[n].pattern,d:e}),u.jsx("path",{fill:o?`url(#${yf(1,t.id)})`:i?t[n].semi:`url(#${yf(s,t.id)})`,d:e})]})}function VY(e){return e.replace(/\s/g," ")}function Iv(e,n,t){const{padding:r=0}=t;if(n.length===0)return null;const o=Z.From(n[0].box);for(const{box:c}of n)o.union(c);const s=r+(t.offsetX??0),i=(t.offsetY??0)+t.fontSize/2+(t.verticalTextAlign==="start"?r:t.verticalTextAlign==="end"?t.height-r-o.height:(Math.ceil(t.height)-o.height)/2);let a=null;const l=[];for(const{text:c,box:d}of n)a!==null&&d.y>a&&l.push(u.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:d.y+i,children:`
|
|
`},l.length)),l.push(u.jsx("tspan",{alignmentBaseline:"mathematical",x:d.x+s,y:d.y+i,unicodeBidi:"plaintext",children:VY(c)},l.length)),a=d.y;return u.jsx("text",{fontSize:t.fontSize,fontFamily:t.fontFamily,fontStyle:t.fontFamily,fontWeight:t.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,children:l})}function YY(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=Z.From(t[0].box);for(const{box:s}of t)o.union(s);if(e==="start-legacy")return(r-2*n-o.width)/2;if(e==="end-legacy")return-(r-2*n-o.width)/2}}function XY(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function pg({fontSize:e,font:n,align:t,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=B(),d=_r(),h={fontSize:e,fontFamily:oM[n],textAlign:t,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Wt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:s,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(o,h),f=YY(t,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const S=Iv(c,p,h);let g=null;return l&&(h.fill=d.background,h.stroke=d.background,h.strokeWidth=2,g=Iv(c,p,h)),u.jsxs(u.Fragment,{children:[g,S]})}const qY=P.forwardRef(function({isEditing:n,text:t,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return u.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!n,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:t,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:Kt,onContextMenu:n?Kt:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:Ee})});function ZY(e,n,t){const r=B(),o=P.useRef(null),s=G("isEditing",()=>r.getEditingShapeId()===e,[r]),i=G("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);P.useEffect(()=>{function d({shapeId:h}){var p;h===e&&((p=o.current)==null||p.select())}return r.on("select-all-text",d),()=>{r.off("select-all-text",d)}},[r,e,s]),P.useEffect(()=>{var d,h,p,f;s&&(document.activeElement!==o.current&&((d=o.current)==null||d.focus()),r.getInstanceState().isCoarsePointer&&((h=o.current)==null||h.select()),r.environment.isSafari&&((p=o.current)==null||p.blur(),(f=o.current)==null||f.focus()))},[r,s]);const a=P.useCallback(d=>{if(r.getEditingShapeId()===e)switch(d.key){case"Enter":{(d.ctrlKey||d.metaKey)&&r.complete();break}}},[r,e]),l=P.useCallback(d=>{if(r.getEditingShapeId()!==e)return;let h=Sl.normalizeText(d.currentTarget.value);const p=h.replace(/\t/g,Va);if(p!==h){const f=d.currentTarget.selectionStart;d.currentTarget.value=p,d.currentTarget.selectionStart=f+(p.length-h.length),d.currentTarget.selectionEnd=f+(p.length-h.length),h=p}r.updateShape({id:e,type:n,props:{text:h}})},[r,e,n]),c=P.useCallback(d=>{r.dispatch({...On(d),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Kt(d)},[r,e]);return{rInput:o,handleFocus:Wp,handleBlur:Wp,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Kt,isEmpty:t.trim().length===0,isEditing:s,isEditingAnything:i}}const fg=xe.memo(function({id:n,type:t,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:d,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:S,style:g,textWidth:x,textHeight:y}){const{rInput:v,isEmpty:b,isEditing:E,isEditingAnything:I,...C}=ZY(n,t,r),[k,T]=P.useState(r);P.useEffect(()=>{E||T(r)},[E,r]);const O=Sl.normalizeTextForDom(r),_=O.length>0,j=XY(l);if(!E&&!_)return null;const L=S||"tl-text";return u.jsx("div",{className:`${L}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!b,"data-isediting":E,"data-iseditinganything":I,"data-textwrap":!!d,"data-isselected":h,style:{justifyContent:l==="middle"||j?"center":l,alignItems:c==="middle"?"center":c,padding:p,...g},children:u.jsxs("div",{className:`${L}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(x||0),color:o,width:x?Math.ceil(x):void 0,height:y?Math.ceil(y):void 0},children:[u.jsx("div",{className:`${L} tl-text tl-text-content`,dir:"auto",children:O.split(`
|
|
`).map((A,R)=>u.jsx("div",{dir:"auto",children:A},R))}),(I||h)&&u.jsx(qY,{ref:v,text:r,isEditing:E,...C,handleKeyDown:f??C.handleKeyDown},k)]})})});function ro(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=t;let c=0,d=0,h=1,p=0,f=0;switch(l){case"dashed":{h=1,c=Math.min(n*a,e/4);break}case"dotted":{h=100,c=n/h;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=c/2,f+=c/2):s==="skip"&&(e-=c,f-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),d=Math.floor(e/c/(2*h)),d-=d%o,d<3&&l==="dashed"?e/n<4?(c=e,d=1,p=0):(c=e*(1/3),p=e*(1/3)):(c=e/d/(2*h),r?(f=c/2,p=(e-d*c)/d):p=(e-d*c)/Math.max(1,d-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}const rI=new WeakMap;function a0(e,n){const t=rI.get(n);if(t)return t;const r=co(e,n);let o=0,s=0;const i=r.isStraight?new zo({start:w.From(r.start.point),end:w.From(r.end.point)}):new Ha({center:w.Cast(r.handleArc.center),start:w.Cast(r.start.point),end:w.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(n.props.text.trim()){const l=i.bounds,c=Ev(n),{w:d,h}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:mo[n.props.font],fontSize:c,maxWidth:null});if(o=d,s=h,l.width>l.height){o=Math.max(Math.min(d,64),Math.min(l.width-64,d));const{w:p,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:mo[n.props.font],fontSize:c,maxWidth:o});o=p,s=f}if(o>16*c){o=16*c;const{w:p,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:mo[n.props.font],fontSize:c,maxWidth:o});o=p,s=f}}const a=new w(o,s).addScalar(WV*2*n.props.scale);return rI.set(n,a),a}function cj(e){const n=At[e.props.size];return(KV+(n-At.s)*2+(n===At.xl?20:0))*e.props.scale}function QY(e,n,t){const r=a0(e,n),o=cj(n),s=w.Nudge(t.start.point,t.end.point,o),i=w.Nudge(t.end.point,t.start.point,o),a=Gw(s,i,Z.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;w.Dist2(l,s)>w.Dist2(c,s)&&([c,l]=a);const d=s.add(w.Sub(t.middle,l)),h=i.add(w.Sub(t.middle,c)),p=w.Dist(t.start.point,d)/t.length,f=w.Dist(t.start.point,h)/t.length;return{start:p,end:f}}function JY(e,n,t){const r=a0(e,n),o=cj(n),s=Math.sign(n.props.bend),i=o/t.handleArc.radius*s,a=w.Angle(t.bodyArc.center,t.start.point)-i,l=w.Angle(t.bodyArc.center,t.end.point)+i,c=Gi(t.bodyArc.center,t.bodyArc.radius,a),d=Gi(t.bodyArc.center,t.bodyArc.radius,l),h=[],p=oI(t.bodyArc.center,t.bodyArc.radius,a,l,s,Z.FromCenter(c,r).corners);h.push(new vt({points:Z.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=oI(t.bodyArc.center,t.bodyArc.radius,a,l,s,Z.FromCenter(d,r).corners);h.push(new vt({points:Z.FromCenter(d,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const k of[...p??[],...f??[],c,d])h.push(new t0({x:k.x-3,y:k.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const S=(p&&sI(t.start.point,p))??t.middle,g=(f&&sI(t.end.point,f))??t.middle,x=w.Angle(t.bodyArc.center,t.start.point),y=w.Angle(t.bodyArc.center,t.end.point),v=w.Angle(t.bodyArc.center,S),b=w.Angle(t.bodyArc.center,g);if(Is(x,v,s)>Is(x,b,s))return{start:.5,end:.5,dbg:h};const E=Is(x,y,s),I=Is(x,v,s)/E,C=Is(x,b,s)/E;return{start:I,end:C,dbg:h}}function Gh(e,n){let t;const r=[],o=co(e,n),s=!!o.bindings.start,i=!!o.bindings.end,a=o.start.arrowhead!=="none",l=o.end.arrowhead!=="none";if(o.isStraight){const d=QY(e,n,o);let h=_t(n.props.labelPosition,a||s?d.start:0,l||i?d.end:1);h=h>=.48&&h<=.52?.5:h,t=w.Lrp(o.start.point,o.end.point,h)}else{const d=JY(e,n,o);d.dbg&&r.push(...d.dbg);let h=_t(n.props.labelPosition,a||s?d.start:0,l||i?d.end:1);h=h>=.48&&h<=.52?.5:h;const p=eX(w.Angle(o.bodyArc.center,o.start.point),w.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),h);t=Gi(o.bodyArc.center,o.bodyArc.radius,p)}const c=a0(e,n);return{box:Z.FromCenter(t,c),debugGeom:r}}function oI(e,n,t,r,o,s){const i=Sv(e,n,s),a=Is(t,r,o);return i==null?void 0:i.filter(l=>{const c=Is(t,w.Angle(e,l),o);return c>=0&&c<=a})}function sI(e,n){let t=null,r=-1/0;for(const o of n){const s=w.Dist2(e,o);s>r&&(t=o,r=s)}return t}function eX(e,n,t,r){const o=Is(e,n,t);return e+o*r*t*-1}function Ev(e){return HV[e.props.size]*e.props.scale}function tX(e,n,t){const r=n==="end"?e.end.point:e.start.point,o=n==="end"?e.start.point:e.end.point,s=e.isStraight?w.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,t*3),t);let a;if(e.isStraight)a=w.Nudge(r,o,i);else{const l=AW(r,i,e.handleArc.center,e.handleArc.radius);a=n==="end"?e.handleArc.sweepFlag?l[0]:l[1]:e.handleArc.sweepFlag?l[1]:l[0]}return w.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function nX({point:e,int:n}){const t=w.RotWith(n,e,_e/6),r=w.RotWith(n,e,-_e/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function rX({point:e,int:n}){const t=w.RotWith(n,e,_e/6),r=w.RotWith(n,e,-_e/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function oX({point:e,int:n}){const t=w.Sub(n,e).div(2),r=w.Add(e,w.Rot(t,Ve)),o=w.Sub(e,w.Rot(t,Ve));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function sX({point:e,int:n}){const t=w.Lrp(e,n,.45),r=w.Dist(t,e);return`M ${t.x-r},${t.y}
|
|
a ${r},${r} 0 1,0 ${r*2},0
|
|
a ${r},${r} 0 1,0 -${r*2},0 `}function iX({point:e,int:n}){const t=w.Lrp(e,n,.75),r=w.RotWith(t,e,_e/4),o=w.RotWith(t,e,-_e/4),s=w.Lrp(r,o,.5);return s.add(w.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function aX({int:e,point:n}){const t=w.Lrp(n,e,.85),r=w.Sub(t,n).div(2),o=w.Add(n,w.Rot(r,Ve)),s=w.Sub(n,w.Rot(r,Ve)),i=w.Add(t,w.Rot(r,Ve)),a=w.Sub(t,w.Rot(r,Ve));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function lX({int:e,point:n}){const t=w.Sub(e,n).div(2),r=w.Add(n,w.Rot(t,Ve)),o=w.Sub(n,w.Rot(t,Ve));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function Sf(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=tX(e,n,t);if(o){switch(r){case"bar":return lX(o);case"square":return aX(o);case"diamond":return iX(o);case"dot":return sX(o);case"inverted":return oX(o);case"arrow":return nX(o);case"triangle":return rX(o)}return""}}function cX(e){const{start:n,end:t,handleArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${n.handle.x},${n.handle.y} A${r} ${r} 0 ${o} ${s} ${t.handle.x},${t.handle.y}`}function uj(e){const{start:n,end:t,bodyArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${n.point.x},${n.point.y} A${r} ${r} 0 ${o} ${s} ${t.point.x},${t.point.y}`}function dj(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function uX(e){return dj(e.start.handle,e.end.handle)}function hj(e){return dj(e.start.point,e.end.point)}let dX=0;class Vh extends Br{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"canSnap",()=>!1);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"canBeLaidOut",t=>{const r=Mn(this.editor,t);return!r.start&&!r.end});m(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const s=r.id,i=Mn(this.editor,t);if(s==="middle"){const{start:C,end:k}=Ka(this.editor,t,i),T=w.Sub(k,C),O=w.Per(T),_=w.Med(k,C),j=w.Sub(_,O),L=w.Add(_,O),A=w.NearestPointOnLineSegment(j,L,r,!1);let R=w.Dist(A,_);return w.Clockwise(A,k,_)&&(R*=-1),{id:t.id,type:t.type,props:{bend:R}}}const a={id:t.id,type:"arrow",props:{}},l=i[s],d=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return $h(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const h=this.editor.getShapePageTransform(t.id).applyToPoint(r),p=this.editor.getShapeAtPoint(h,{hitInside:!0,hitFrameInside:!0,margin:0,filter:C=>!C.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:C,binding:"arrow"})});if(!p)return $h(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),S=Z.ZeroFix(f.bounds),x=this.editor.getShapePageTransform(a.id).applyToPoint(r),y=this.editor.getPointInShapeSpace(p,x);let v=o;v||(!l||l&&p.id!==l.toId)&&(v=this.editor.inputs.pointerVelocity.len()<.5),o||(f.isClosed||(v=!0),d&&p.id===d.toId&&d.props.isPrecise&&(v=!0));const b={x:(y.x-S.minX)/S.width,y:(y.y-S.minY)/S.height};v&&w.Dist(y,S.center)<Math.max(4,Math.min(Math.min(S.width,S.height)*.15,16))/this.editor.getZoomLevel()&&(b.x=.5,b.y=.5);const E={terminal:s,normalizedAnchor:b,isPrecise:v,isExact:this.editor.inputs.altKey};cc(this.editor,t,p.id,E),this.editor.setHintingShapes([p.id]);const I=Mn(this.editor,t);return I.start&&I.end&&I.start.toId===I.end.toId&&w.Equals(I.start.props.normalizedAnchor,I.end.props.normalizedAnchor)&&cc(this.editor,t,I.end.toId,{...I.end.props,normalizedAnchor:{x:I.end.props.normalizedAnchor.x+.05,y:I.end.props.normalizedAnchor.y}}),a});m(this,"onTranslateStart",t=>{const r=Mn(this.editor,t),o=Ka(this.editor,t,r),s=this.editor.getShapePageTransform(t.id),i=this.editor.getSelectedShapeIds();if(!(r.start&&(i.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(i.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){aI.set(t,{pagePosition:s.applyToPoint(t),terminalBindings:Ru(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(gf({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&gf({editor:this.editor,arrow:t,terminal:"end",useHandle:!0});for(const a of["start","end"]){const l=r[a];l&&this.editor.updateBinding({...l,props:{...l.props,isPrecise:!0}})}}});m(this,"onTranslate",(t,r)=>{const o=aI.get(t);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=w.Sub(s.applyToPoint(r),o.pagePosition);for(const a of Object.values(o.terminalBindings)){if(!a)continue;const l=w.Add(a.pagePosition,w.Mul(i,.5)),c=this.editor.getShapeAtPoint(l,{hitInside:!0,hitFrameInside:!0,margin:0,filter:d=>!d.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:d,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const d=Z.ZeroFix(this.editor.getShapeGeometry(c).bounds),h=this.editor.getPointInShapeSpace(c,l),p={x:(h.x-d.minX)/d.width,y:(h.y-d.minY)/d.height};cc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else $h(this.editor,r,a.binding.props.terminal)}});m(this,"_resizeInitialBindings",new Zo);m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(t,()=>Mn(this.editor,t)),a=Ka(this.editor,t,i),{start:l,end:c}=rt(t.props);let{bend:d}=t.props;i.start||(l.x=a.start.x*o,l.y=a.start.y*s),i.end||(c.x=a.end.x*o,c.y=a.end.y*s);const h=Math.abs(o),p=Math.abs(s),f=i!=null&&i.start?w.From(i.start.props.normalizedAnchor):null,S=i!=null&&i.end?w.From(i.end.props.normalizedAnchor):null;return o<0&&s>=0?(d!==0&&(d*=-1,d*=Math.max(h,p)),f&&(f.x=1-f.x),S&&(S.x=1-S.x)):o>=0&&s<0?(d!==0&&(d*=-1,d*=Math.max(h,p)),f&&(f.y=1-f.y),S&&(S.y=1-S.y)):o>=0&&s>=0?d!==0&&(d*=Math.max(h,p)):o<0&&s<0&&(d!==0&&(d*=Math.max(h,p)),f&&(f.x=1-f.x,f.y=1-f.y),S&&(S.x=1-S.x,S.y=1-S.y)),i.start&&f&&cc(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&S&&cc(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:S.toJson()}),{props:{start:l,end:c,bend:d}}});m(this,"onDoubleClickHandle",(t,r)=>{switch(r.id){case"start":return{id:t.id,type:t.type,props:{...t.props,arrowheadStart:t.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:t.id,type:t.type,props:{...t.props,arrowheadEnd:t.props.arrowheadEnd==="none"?"arrow":"none"}}}});m(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}canBind({toShapeType:t}){return t!=="arrow"}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw",scale:1}}getGeometry(t){const r=co(this.editor,t),o=[],s=r.isStraight?new zo({start:w.From(r.start.point),end:w.From(r.end.point)}):new Ha({center:w.Cast(r.handleArc.center),start:w.Cast(r.start.point),end:w.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(t.props.text.trim()){const a=Gh(this.editor,t);o.push(...a.debugGeom),i=new Jo({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Hr({children:[...i?[s,i]:[s],...o]})}getHandles(t){const r=co(this.editor,t);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y}].filter(Boolean)}component(t){const r=_r(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,i=co(this.editor,t);if(!(i!=null&&i.isValid))return null;const a=Gh(this.editor,t),l=t.id===this.editor.getOnlySelectedShapeId(),d=this.editor.getEditingShapeId()===t.id||t.props.text;return u.jsxs(u.Fragment,{children:[u.jsx(Ys,{id:t.id,style:{minWidth:50,minHeight:50},children:u.jsx(iI,{shape:t,shouldDisplayHandles:s&&(o==null?void 0:o.id)===t.id})}),d&&u.jsx(fg,{id:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:Ev(t),lineHeight:Wt.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w,isSelected:l,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(t){const r=ug(t.id),o=co(this.editor,t);if(!o)return null;const{start:s,end:i}=Ka(this.editor,t,o==null?void 0:o.bindings),a=this.editor.getShapeGeometry(t),l=a.bounds,c=t.props.text.trim()?a.children[1]:null;if(w.Equals(s,i))return null;const d=At[t.props.size]*t.props.scale,h=o.start.arrowhead&&Sf(o,"start",d),p=o.end.arrowhead&&Sf(o,"end",d),f=o.isStraight?hj(o):uj(o),S=h&&o.start.arrowhead!=="arrow"||p&&o.end.arrowhead!=="arrow"||!!c,g=(t.id+"_clip").replace(":","_");return r&&c?u.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5*t.props.scale,ry:3.5*t.props.scale}):u.jsxs("g",{children:[S&&u.jsx("defs",{children:u.jsxs("mask",{id:g,children:[u.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.w+200,height:l.h+200,fill:"white"}),c&&u.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,fill:"black",rx:3.5*t.props.scale,ry:3.5*t.props.scale}),h&&u.jsx("path",{d:h,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&u.jsx("path",{d:p,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),u.jsxs("g",{...S?{mask:`url(#${g})`}:void 0,children:[S&&u.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.width+200,height:l.height+200,opacity:0}),u.jsx("path",{d:f})]}),h&&u.jsx("path",{d:h}),p&&u.jsx("path",{d:p}),c&&u.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5})]})}toSvg(t,r){r.addExportDef(s0(t.props.fill)),t.props.text&&r.addExportDef(vl(t.props.font));const o=ss(r),s=1/t.props.scale;return u.jsxs("g",{transform:`scale(${s})`,children:[u.jsx(iI,{shape:t,shouldDisplayHandles:!1}),u.jsx(pg,{fontSize:Ev(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:o[t.props.labelColor].solid,bounds:Gh(this.editor,t).box,padding:4*t.props.scale})]})}getCanvasSvgDefs(){return[i0(),{key:"arrow:dot",component:pX},{key:"arrow:cross",component:fX}]}}m(Vh,"type","arrow"),m(Vh,"props",iM),m(Vh,"migrations",aM);function hX(e,n){const t=co(e,n);return t.isStraight?w.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const iI=lr(function({shape:n,shouldDisplayHandles:t}){const r=B(),o=_r(),s=co(r,n),i=Z.ZeroFix(r.getShapeGeometry(n).bounds),a=Mn(r,n),l=xe.useMemo(()=>r.environment.isSafari?dX+=1:0,[n]);if(!(s!=null&&s.isValid))return null;const c=At[n.props.size]*n.props.scale,d=s.start.arrowhead&&Sf(s,"start",c),h=s.end.arrowhead&&Sf(s,"end",c),p=s.isStraight?hj(s):uj(s);let f=null;if(t){const E=2/r.getZoomLevel(),{strokeDasharray:I,strokeDashoffset:C}=ro(hX(r,n),E,{end:"skip",start:"skip",lengthRatio:2.5});f=a.start||a.end?u.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?uX(s):cX(s),strokeDasharray:I,strokeDashoffset:C,strokeWidth:E,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:S,strokeDashoffset:g}=ro(s.isStraight?s.length:Math.abs(s.bodyArc.length),c,{style:n.props.dash}),x=Gh(r,n),y=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),v=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),b=(n.id+"_clip_"+l).replace(":","_");return u.jsxs(u.Fragment,{children:[u.jsx("defs",{children:u.jsxs("mask",{id:b,children:[u.jsx("rect",{x:N(-100+i.minX),y:N(-100+i.minY),width:N(i.width+200),height:N(i.height+200),fill:"white"}),n.props.text.trim()&&u.jsx("rect",{x:x.box.x,y:x.box.y,width:x.box.w,height:x.box.h,fill:"black",rx:4,ry:4}),d&&y&&u.jsx("path",{d,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),h&&v&&u.jsx("path",{d:h,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),u.jsxs("g",{fill:"none",stroke:o[n.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[f,u.jsxs("g",{mask:`url(#${b})`,children:[u.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),u.jsx("path",{d:p,strokeDasharray:S,strokeDashoffset:g})]}),d&&y&&n.props.fill!=="none"&&u.jsx(en,{theme:o,d,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),h&&v&&n.props.fill!=="none"&&u.jsx(en,{theme:o,d:h,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),d&&u.jsx("path",{d}),h&&u.jsx("path",{d:h})]})]})}),aI=new WeakMap;function pX(){return u.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:u.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function fX(){return u.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[u.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),u.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const lI="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 xl({url:e,zoomLevel:n}){return u.jsx("a",{className:ce("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Kt,onPointerUp:Kt,title:e,draggable:!1,children:u.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${lI}") center 100% / 100% no-repeat`,WebkitMask:`url("${lI}") center 100% / 100% no-repeat`}})})}const cI="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",gX=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function l0(e){return gX.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,l=new w(r,o),{x:c,y:d}=l.rot(-e);return`${c}px ${d}px ${s}px ${i}px ${a}`}).join(", ")}const mX=300,pj=320,yX=46,SX=101;class Yh extends $l{constructor(){super(...arguments);m(this,"canResize",()=>!1);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"onBeforeCreate",t=>uI(this.editor,t));m(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(or.isValid(r.props.url))xX(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}};if(t.props.assetId!==r.props.assetId)return uI(this.editor,r)})}getDefaultProps(){return{url:"",w:mX,h:pj,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),s=vX(t);return u.jsx(Vi,{children:u.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:l0(o)},children:[(!r||r.props.image)&&u.jsxs("div",{className:"tl-bookmark__image_container",children:[r?u.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):u.jsx("div",{className:"tl-bookmark__placeholder"}),(r==null?void 0:r.props.image)&&u.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),u.jsxs("div",{className:"tl-bookmark__copy_container",children:[r!=null&&r.props.title?u.jsx("h2",{className:"tl-bookmark__heading",children:r.props.title}):null,r!=null&&r.props.description&&(r!=null&&r.props.image)?u.jsx("p",{className:"tl-bookmark__description",children:r.props.description}):null,u.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Kt,onPointerUp:Kt,onClick:Kt,children:[r!=null&&r.props.favicon?u.jsx("img",{className:"tl-bookmark__favicon",src:r==null?void 0:r.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",alt:`favicon of ${s}`}):u.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${cI}") center 100% / 100% no-repeat`,WebkitMask:`url("${cI}") center 100% / 100% no-repeat`}}),u.jsx("span",{children:s})]})]})]})})}indicator(t){return u.jsx("rect",{width:N(t.props.w),height:N(t.props.h),rx:"6",ry:"6"})}}m(Yh,"type","bookmark"),m(Yh,"props",pM),m(Yh,"migrations",fM);function uI(e,n){const t=n.props.assetId?e.getAsset(n.props.assetId):null;let r=pj;return t&&(t.props.image||(t.props.title?r=SX:r=yX)),{...n,props:{...n.props,h:r}}}const vX=e=>{try{return new URL(e.props.url).hostname.replace(/^www\./,"")}catch{return e.props.url}};function xX(e,n){const{url:t}=n.props,r=ki.createId(ov(t));e.getAsset(r)?n.props.assetId!==r&&e.updateShapes([{id:n.id,type:n.type,props:{assetId:r}}]):(e.updateShapes([{id:n.id,type:n.type,props:{assetId:null}}]),wX(e,n))}const wX=CT(async(e,n)=>{if(e.isDisposed)return;const{url:t}=n.props,r=await e.getAssetForExternalContent({type:"url",url:t});r&&e.batch(()=>{e.createAssets([r]),e.updateShapes([{id:n.id,type:n.type,props:{assetId:r.id}}])})},500);function Yi(e,n=!1){const t=e.length;if(t<2)return"";let r=e[0].point,o=e[1].point;if(t===2)return`M${Ie(r)}L${Ie(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=Tn(r,o);return n?`M${Tn(e[0].point,e[1].point)}Q${Ie(e[1].point)}${Tn(e[1].point,e[2].point)}T${s}${Tn(e[t-1].point,e[0].point)}${Tn(e[0].point,e[1].point)}Z`:`M${Ie(e[0].point)}Q${Ie(e[1].point)}${Tn(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Ie(e[t-1].point)}`}function bX(e,n={}){const{start:t={},end:r={}}=n,{cap:o=!0}=t,{cap:s=!0}=r;st(!t.taper&&!r.taper,"cap taper not supported here"),st(!t.easing&&!r.easing,"cap easing not supported here"),st(o&&s,"cap must be true");const i=xo(e,n);dg(i,n);const a=PX(i);let l="";for(const c of a)l+=IX(c,n);return l}function PX(e){if(e.length<=2)return[e];const n=[];let t=[e[0]],r=w.Sub(e[1].point,e[0].point).uni(),o,s,i,a,l;for(let c=1,d=e.length;c<d-1;c++){if(i=e[c-1],a=e[c],l=e[c+1],o=w.Sub(l.point,a.point).uni(),s=w.Dpr(r,o),r=o,s<-.8){const h={...a,point:a.input};t.push(h),n.push(uy(t)),t=[h];continue}if(t.push(a),!(s>.7)&&(w.Dist2(i.point,a.point)+w.Dist2(a.point,l.point))/((i.radius+a.radius+l.radius)/3)**2<1.5){t.push(a),n.push(uy(t)),t=[a];continue}}return t.push(e[e.length-1]),n.push(uy(t)),n}function uy(e){const n=e[0];let t;for(;e.length>2&&(t=e[1],w.Dist2(n.point,t.point)<((n.radius+t.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],w.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:w.Sub(e[0].point,e[1].point).uni()},e[e.length-1]={...e[e.length-1],vector:w.Sub(e[e.length-2].point,e[e.length-1].point).uni()}),e}function CX(e,n,t){return"M "+e+" "+n+" m -"+t+", 0 a "+t+","+t+" 0 1,1 "+t*2+",0 a "+t+","+t+" 0 1,1 -"+t*2+",0"}function IX(e,n={}){if(e.length===0)return"";if(e.length===1)return CX(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=W2(e,n);r.reverse();let o=`M${Ie(t[0])}T`;for(let s=1;s<t.length;s++)o+=Tn(t[s-1],t[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),l=w.Add(s.point,w.Mul(a,i)),c=w.Add(s.point,w.Mul(a,-i));o+=`${Ie(l)}A${N(i)},${N(i)} 0 0 1 ${Ie(c)}T`}for(let s=1;s<r.length;s++)o+=Tn(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),l=w.Add(s.point,w.Mul(a,i)),c=w.Add(s.point,w.Mul(a,-i));o+=`${Ie(l)}A${N(i)},${N(i)} 0 0 1 ${Ie(c)}Z`}return o}const EX=e=>e*.65+X9(e*_e/2)*.35,kX=e=>({size:e,thinning:.5,streamline:fl(e,[9,16],[.64,.74],!0),smoothing:.62,easing:jt.easeOutSine,simulatePressure:!0}),_X=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:EX}),dI=e=>({size:e,thinning:0,streamline:fl(e,[9,16],[.68,.74],!0),smoothing:.62,simulatePressure:!1,easing:jt.linear}),TX=e=>({size:e,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:jt.linear});function c0({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:jt.easeOutSine,last:n}}function kv(e,n,t,r){const o=e.isComplete||t;return r?e.isPen?{...TX(n),last:o}:{...dI(n),last:o}:e.dash==="draw"?e.isPen?{..._X(n),last:o}:{...kX(n),last:o}:{...dI(n),last:o}}function wl(e){const n=[];for(const t of e)if(t.type==="free"||t.points.length<2)n.push(...t.points.map(w.Cast));else{const r=Math.max(4,Math.floor(w.Dist(t.points[0],t.points[1])/16));n.push(...w.PointsBetween(t.points[0],t.points[1],r))}return n}function MX(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class Xh extends Br{constructor(){super(...arguments);m(this,"hideResizeHandles",t=>dy(t));m(this,"hideRotateHandle",t=>dy(t));m(this,"hideSelectionBoundsFg",t=>dy(t));m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:d})=>({x:$o(o*l),y:$o(s*c),z:d}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(t){const r=wl(t.props.segments),o=(At[t.props.size]+1)*t.props.scale;if(t.props.segments.length===1){const i=Z.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new t0({x:-o,y:-o,radius:o,isFilled:!0})}const s=xo(r,kv(t.props,o,t.props.isPen,!0)).map(i=>i.point);return t.props.isClosed?new vt({points:s,isFilled:t.props.fill!=="none"}):new Ll({points:s})}component(t){return u.jsx(Ys,{id:t.id,children:u.jsx(hI,{shape:t,zoomLevel:this.editor.getZoomLevel()})})}indicator(t){var h;const r=wl(t.props.segments);let o=(At[t.props.size]+1)*t.props.scale;const s=this.editor.getZoomLevel();!(s<.5&&s<1.5/o)&&!t.props.isPen&&t.props.dash==="draw"&&r.length===1&&(o+=Wr(t.id)()*(o/6));const a=t.props.isComplete||((h=Nt(t.props.segments))==null?void 0:h.type)==="straight",l=kv(t.props,o,a,!0),c=xo(r,l),d=c.length>1?Yi(c,t.props.isClosed):fj(r[0],o);return u.jsx("path",{d})}toSvg(t,r){r.addExportDef(s0(t.props.fill));const o=1/t.props.scale;return u.jsx("g",{transform:`scale(${o})`,children:u.jsx(hI,{shape:t,zoomLevel:1})})}getCanvasSvgDefs(){return[i0()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return At[t.props.size]*r/2*t.props.scale}}m(Xh,"type","draw"),m(Xh,"props",mM),m(Xh,"migrations",yM);function fj(e,n){const t=(n+1)*.5;return`M ${e.x} ${e.y} m -${t}, 0 a ${t},${t} 0 1,0 ${t*2},0 a ${t},${t} 0 1,0 -${t*2},0`}function dy(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function hI({shape:e,zoomLevel:n}){var h;const t=_r(),r=wl(e.props.segments),o=e.props.isComplete||((h=Nt(e.props.segments))==null?void 0:h.type)==="straight";let s=(At[e.props.size]+1)*e.props.scale;const i=n<.5&&n<1.5/s;!i&&!e.props.isPen&&e.props.dash==="draw"&&r.length===1&&(s+=Wr(e.id)()*(s/6));const a=kv(e.props,s,o,i);if(!i&&e.props.dash==="draw")return u.jsxs(u.Fragment,{children:[e.props.isClosed&&e.props.fill&&r.length>1?u.jsx(en,{d:Yi(xo(r,a),e.props.isClosed),theme:t,color:e.props.color,fill:e.props.isClosed?e.props.fill:"none",scale:e.props.scale}):null,u.jsx("path",{d:bX(r,a),strokeLinecap:"round",fill:t[e.props.color].solid})]});const l=xo(r,a),c=l.length<2,d=c?fj(r[0],0):Yi(l,e.props.isClosed);return u.jsxs(u.Fragment,{children:[u.jsx(en,{d,theme:t,color:e.props.color,fill:c||e.props.isClosed?e.props.fill:"none",scale:e.props.scale}),u.jsx("path",{d,strokeLinecap:"round",fill:c?t[e.props.color].solid:"none",stroke:t[e.props.color].solid,strokeWidth:s,strokeDasharray:c?"none":MX(e,s),strokeDashoffset:"0"})]})}function jX(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:d=1/0}=t;let h=e.props.w*s,p=e.props.h*i;const f=new w(0,0);if(h>0){if(h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:S,y:g}=f.rot(e.rotation).add(r);return{x:S,y:g,props:{w:Math.min(l,h),h:Math.min(d,p)}}}const AX=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class qh extends $l{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",t=>!this.canResize(t));m(this,"canEdit",()=>!0);m(this,"canResize",t=>{var r,o;return!!((o=(r=Ms(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});m(this,"canEditInReadOnly",()=>!0);m(this,"isAspectRatioLocked",t=>{const r=Ms(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});m(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=Ms(t.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const l=t.props.w/t.props.h;l>1?i*=l:a/=l}return jX(t,r,{minWidth:i,minHeight:a})})}getDefaultProps(){return{w:300,h:300,url:""}}component(t){const{w:r,h:o,url:s}=t.props,i=ug(t.id),a=P.useMemo(()=>q2(s),[s]),l=G("is hovering",()=>{const{editingShapeId:f,hoveredShapeId:S}=this.editor.getCurrentPageState();if(f&&S!==f){const g=this.editor.getShape(f);if(g&&this.editor.isShapeOfType(g,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(t).rotation(),d=i||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const f=a.url.split("/").pop();if(!f)throw Error("No gist id!");return u.jsx(Vi,{className:"tl-embed-container",id:t.id,children:u.jsx(OX,{id:f,width:N(r),height:N(o),isInteractive:d,pageRotation:c})})}const p=AX({...D9,...(a==null?void 0:a.definition.overridePermissions)??{}});return u.jsx(Vi,{className:"tl-embed-container",id:t.id,children:a!=null&&a.definition?u.jsx("iframe",{className:"tl-embed",sandbox:p,src:a.embedUrl,width:N(r),height:N(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:d?"auto":"none",zIndex:d?"":"-1",boxShadow:l0(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(t){const r=P.useMemo(()=>Ms(t.props.url),[t.props.url]);return u.jsx("rect",{width:N(t.props.w),height:N(t.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}m(qh,"type","embed"),m(qh,"props",SM),m(qh,"migrations",vM);function OX({id:e,file:n,isInteractive:t,width:r,height:o,style:s,pageRotation:i}){return u.jsx("iframe",{className:"tl-embed",draggable:!1,width:N(r),height:N(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:t?"all":"none",zIndex:t?"":"-1",boxShadow:l0(i)},srcDoc:`
|
|
<html>
|
|
<head>
|
|
<base target="_blank">
|
|
</head>
|
|
<body>
|
|
<script src=${`https://gist.github.com/${e}.js${n?`?file=${n}`:""}`}><\/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 DX=P.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=B(),s=P.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Kt(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=P.useCallback(l=>{const c=o.getShape(e);if(!c)return;const d=c.props.name,h=l.currentTarget.value.trim();d!==h&&o.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,o]),a=P.useCallback(l=>{const c=o.getShape(e);if(!c)return;const d=c.props.name,h=l.currentTarget.value;d!==h&&o.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,o]);return u.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[u.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:t?void 0:"none"},value:n,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),gj(n,"Frame")+""]})}),RX=function({id:n,name:t,width:r,height:o}){const s=B(),i=G("shape rotation",()=>Hs(s.getShapePageTransform(n).rotation()),[s,n]),a=ug(n),l=P.useRef(null),c=P.useCallback(S=>{const g=On(S);s.getEditingShapeId()!==n&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...g}),S.preventDefault())},[s,n]);P.useEffect(()=>{const S=l.current;S&&a&&(S.focus(),S.select())},[l,a]);const h=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(h)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${N(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${N(r)}px, ${N(o)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${N(o)}px) rotate(270deg)`;break}return u.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:c,children:u.jsx("div",{className:"tl-frame-heading-hit-area",children:u.jsx(DX,{ref:l,id:n,name:t,isEditing:a})})})};function gj(e,n){return e.match(/^\s*$/)?n:e}class Zh extends $l{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"canReceiveNewChildrenOfType",(t,r)=>!t.isLocked);m(this,"canDropShapes",(t,r)=>!t.isLocked);m(this,"onDragShapesOver",(t,r)=>{r.every(o=>o.parentId===t.id)||this.editor.reparentShapes(r,t.id)});m(this,"onDragShapesOut",(t,r)=>{const o=this.editor.getShape(t.parentId);o&&this.editor.isShapeOfType(o,"group")?this.editor.reparentShapes(r,o.id):this.editor.reparentShapes(r,this.editor.getCurrentPageId())});m(this,"onResize",(t,r)=>U2(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new Jo({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=_r(),s=G("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()===t.id:!1},[t.id]);return u.jsxs(u.Fragment,{children:[u.jsx(Ys,{children:u.jsx("rect",{className:ce("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:u.jsx(RX,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t,r){const o=ss({isDarkMode:r.isDarkMode}),a=((Hs(this.editor.getShapePageTransform(t.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,l=Math.floor(a);let c;switch(l){case 0:c="";break;case 3:c=`translate(${N(t.props.w)}, 0) rotate(90)`;break;case 2:c=`translate(${N(t.props.w)}, ${N(t.props.h)}) rotate(180)`;break;case 1:c=`translate(0, ${N(t.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const d={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:t.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle"},h=this.editor.textMeasure.measureTextSpans(gj(t.props.name,"Frame")+"",d),p=h[0],f=Nt(h),S=f.box.w+f.box.x-p.box.x,g=Iv(this.editor,h,{offsetY:-d.height-2,...d});return u.jsxs(u.Fragment,{children:[u.jsx("rect",{width:t.props.w,height:t.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),u.jsxs("g",{transform:c,children:[u.jsx("rect",{x:-8,y:-d.height-4,width:S+16,height:d.height,fill:o.background,rx:4,ry:4}),g]})]})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return u.jsx("rect",{width:N(r.width),height:N(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}m(Zh,"type","frame"),m(Zh,"props",xM),m(Zh,"migrations",wM);function pI(e,n){return e>n?(_e*(n/2)+(e-n))*2:(_e*(e/2)+(n-e))*2}function mj(e,n){return u0(e,n).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function LX(e,n,t,r){const o=e/4,s=n/4,i=Wr(r),a=t*.75,l=v=>v.addXY(i()*a,i()*a),c=new w(e/2,n),d=new w(0,s*1.2),h=new w(e/2,s*.9),p=new w(e,s*1.2),f=l(new w(e/2,n)),S=l(new w(0,s*1.2)),g=l(new w(e/2,s*.9)),x=l(new w(e,s*1.2));return[new nn({start:c,cp1:new w(o*1.5,s*3),cp2:new w(0,s*2.5),end:d}),new nn({start:d,cp1:new w(0,-s*.32),cp2:new w(o*1.85,-s*.32),end:h}),new nn({start:h,cp1:new w(o*2.15,-s*.32),cp2:new w(e,-s*.32),end:p}),new nn({start:p,cp1:new w(e,s*2.5),cp2:new w(o*2.5,s*3),end:f}),new nn({start:f,cp1:new w(o*1.5,s*3),cp2:new w(0,s*2.5),end:S}),new nn({start:S,cp1:new w(0,-s*.32),cp2:new w(o*1.85,-s*.32),end:g}),new nn({start:g,cp1:new w(o*2.15,-s*.32),cp2:new w(e,-s*.32),end:x}),new nn({start:x,cp1:new w(e,s*2.5),cp2:new w(o*2.5,s*3),end:c})].map((v,b)=>v.getSvgPathData(b===0)).join(" ")+" Z"}function u0(e,n){const t=e/4,r=n/4;return[new nn({start:new w(e/2,n),cp1:new w(t*1.5,r*3),cp2:new w(0,r*2.5),end:new w(0,r*1.2)}),new nn({start:new w(0,r*1.2),cp1:new w(0,-r*.32),cp2:new w(t*1.85,-r*.32),end:new w(e/2,r*.9)}),new nn({start:new w(e/2,r*.9),cp1:new w(t*2.15,-r*.32),cp2:new w(e,-r*.32),end:new w(e,r*1.2)}),new nn({start:new w(e,r*1.2),cp1:new w(e,r*2.5),cp2:new w(t*2.5,r*3),end:new w(e/2,n)})]}function $X(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function FX(e,n,t,r){const o=Wr(e),s=n/2,i=t/2,a=zM(s,i),l=[],c=Re*o(),d=Re+Ve/2+Math.abs(o())*Ve,h=Math.max(16,a/10);for(let p=0;p<h;p++){const f=p/(h-1),S=c+f*d,g=Math.cos(S),x=Math.sin(S);l.push(new w(s*g+n*.5+.05*o(),i*x+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?jt.easeInOutSine(f):jt.easeInExpo(f)))/2)))}return xo(l,$X(r))}function NX(e,n,t,r){return Yi(FX(e,n,t,r))}function _v(e){let n="M";const t=e.length;let r,o,s;for(let i=0,a=t;i<a;i+=3)r=e[i],o=e[i+1],s=e[i+2],n+=`${Ie(r)}L${Ie(o)}Q${Ie(s)}`;return n+=`${Ie(e[0])}`,n}function Tv(e,n,t,r,o){const s=[],i=Wr(e);let a=n[0],l;const c=n.length;for(let d=0,h=c*o;d<h;d++){l=w.AddXY(n[(d+1)%c],i()*t,i()*t);const p=w.Sub(l,a),f=w.Len(p),S=w.Div(p,f).mul(Math.min(f/4,r));s.push(w.Add(a,S),w.Add(l,S.neg()),l),a=l}return s}function zX(e,n,t){const r=Math.min(e,n)/2,o=Math.max(e,n)-r*2,i=(Math.PI*(r*2)+2*o)/t,a=e>n?[{type:"straight",start:new w(r,0),delta:new w(1,0)},{type:"arc",center:new w(e-r,r),startAngle:-_e/2},{type:"straight",start:new w(e-r,n),delta:new w(-1,0)},{type:"arc",center:new w(r,r),startAngle:_e/2}]:[{type:"straight",start:new w(e,r),delta:new w(0,1)},{type:"arc",center:new w(r,n-r),startAngle:0},{type:"straight",start:new w(0,n-r),delta:new w(0,-1)},{type:"arc",center:new w(r,r),startAngle:_e}];let l=0;const c=[];for(let d=0;d<t;d++){const h=a[0];h.type==="straight"?c.push(w.Add(h.start,w.Mul(h.delta,l))):c.push(Gi(h.center,r,h.startAngle+l/r)),l+=i;let p=h.type==="straight"?o:_e*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?o:_e*r}return c}const BX={s:50,m:70,l:100,xl:130},UX=.2;function gg(e,n,t,r){const o=Wr(t),s=pI(e,n),i=Math.max(Math.ceil(s/BX[r]),6,Math.ceil(s/Math.min(e,n))),a=s/i*UX,l=Math.max(e-a*2,1),c=Math.max(n-a*2,1),h=pI(l,c)/i,p=(e-l)/2,f=(n-c)/2,S=zX(l,c,i).map(b=>b.addXY(p,f)),g=e<20?0:a*.3,x=n<20?0:a*.3,y=S.slice(0);for(let b=0;b<Math.floor(i/2);b++)y[b]=w.AddXY(y[b],o()*g,o()*x),y[i-b-1]=w.AddXY(y[i-b-1],o()*g,o()*x);const v=[];for(let b=0;b<y.length;b++){const E=b===y.length-1?0:b+1,I=y[b],C=y[E],k=S[b],T=S[E],O=w.Dist(k,T),_=h-O,L=w.Dist(I,C)/O,A=(Math.max(p,f)+_)*L,R=w.Lrp(k,T,.5).add(w.Sub(T,k).uni().per().mul(A));R.x<0?R.x=0:R.x>e&&(R.x=e),R.y<0?R.y=0:R.y>n&&(R.y=n);const F=$w(I,C,R),W=w.Dist(F||w.Average([I,C]),I);v.push({leftPoint:I,rightPoint:C,arcPoint:R,center:F,radius:W})}return v}function HX(e,n,t,r){const o=[],s=gg(e,n,t,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of s)o.push(...J9(l,c,i,a,10));return o}function Mv(e,n,t,r){const o=gg(e,n,t,r);let s=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:i,rightPoint:a,radius:l,center:c}of o){if(c===null){s+=` L${a.toFixed()}`;continue}const d=w.Clockwise(i,a,c)?"0":"1";s+=` A${N(l)},${N(l)} 0 ${d},1 ${a.toFixed()}`}return s+=" Z",s}const KX={s:.5,m:.7,l:.9,xl:1.6};function WX(e,n,t,r){const o=Wr(t),s=KX[r],i=gg(e,n,t,r),c=i.reduce((f,S)=>f+w.Dist2(S.leftPoint,S.rightPoint),0)/i.length>(s*15)**2?f=>f.addXY(o()*s*2,o()*s*2):f=>f;let d=`M${i[0].leftPoint.toFixed()}`,h=c(i[0].leftPoint),p=`M${h.toFixed()}`;for(const{leftPoint:f,center:S,rightPoint:g,radius:x,arcPoint:y}of i){if(S===null){d+=` L${g.toFixed()}`;const k=c(g);p+=` L${k.toFixed()}`,h=k;continue}const v=w.Clockwise(f,g,S)?"0":"1";d+=` A${N(x)},${N(x)} 0 ${v},1 ${g.toFixed()}`;const b=c(g),E=c(y),I=$w(h,b,E);if(!Number.isFinite(I.x)||!Number.isFinite(I.y)){p+=` L${b.toFixed()}`,h=b;continue}const C=Math.abs(w.Dist(I,h));p+=` A${N(C)},${N(C)} 0 ${v},1 ${b.toFixed()}`,h=b}return d+p+" Z"}function jv(e,n){switch(e.geo){case"x-box":return GX(e.w,e.h,n,e.dash);case"check-box":return VX(e.w,e.h);default:return}}function GX(e,n,t,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new w(0,0),new w(e/2,n/2)],[new w(e,n),new w(e/2,n/2)],[new w(0,n),new w(e/2,n/2)],[new w(e,0),new w(e/2,n/2)]];const s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(n,a));return[[new w(s(t*o),i(t*o)),new w(s(e-t*o),i(n-t*o))],[new w(s(t*o),i(n-t*o)),new w(s(e-t*o),i(t*o))]]}function VX(e,n){const t=Math.min(e,n)*.82,r=(e-t)/2,o=(n-t)/2,s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(n,a));return[[new w(s(r+t*.25),i(o+t*.52)),new w(s(r+t*.45),i(o+t*.82))],[new w(s(r+t*.45),i(o+t*.82)),new w(s(r+t*.82),i(o+t*.22))]]}function fI({shape:e,shouldScale:n}){const t=n?e.props.scale:1,r=B(),o=_r(),{id:s,props:i}=e,{w:a,color:l,fill:c,dash:d,growY:h,size:p}=i,f=At[p]*t,S=i.h+h;switch(i.geo){case"cloud":if(d==="solid"){const g=Mv(a,S,s,p);return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:g,color:l,fill:c,scale:t}),u.jsx("path",{d:g,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else if(d==="draw"){const g=WX(a,S,s,p);return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:g,color:l,fill:c,scale:t}),u.jsx("path",{d:g,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else{const g=Mv(a,S,s,p),x=gg(a,S,s,p);return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:g,color:l,fill:c,scale:t}),u.jsx("g",{strokeWidth:f,stroke:o[l].solid,fill:"none",pointerEvents:"all",children:x.map(({leftPoint:y,rightPoint:v,center:b,radius:E},I)=>{const C=b?E*Hs(Hs(w.Angle(b,v))-Hs(w.Angle(b,y))):w.Dist(y,v),{strokeDasharray:k,strokeDashoffset:T}=ro(C,f,{style:d,start:"outset",end:"outset"});return u.jsx("path",{d:b?`M${y.x},${y.y}A${E},${E},0,0,1,${v.x},${v.y}`:`M${y.x},${y.y}L${v.x},${v.y}`,strokeDasharray:k,strokeDashoffset:T},I)})})]})}case"ellipse":{const g=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=g.getSvgPathData(!0);if(d==="dashed"||d==="dotted"){const y=g.length,{strokeDasharray:v,strokeDashoffset:b}=ro(y<64?y*2:y,f,{style:d,snap:4,closed:!0});return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),u.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:v,strokeDashoffset:b})]})}else{const v=(n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e)).getSvgPathData(!0);return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),u.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}}case"oval":{const g=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=g.getSvgPathData(!0);if(d==="dashed"||d==="dotted"){const y=g.getLength(),{strokeDasharray:v,strokeDashoffset:b}=ro(y<64?y*2:y,f,{style:d,snap:4,start:"outset",end:"outset",closed:!0});return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),u.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:v,strokeDashoffset:b})]})}else return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),u.jsx("path",{d:x,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}case"heart":if(d==="dashed"||d==="dotted"||d==="solid"){const g=mj(a,S),x=u0(a,S);return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:g,color:l,fill:c,scale:t}),x.map((y,v)=>{const{strokeDasharray:b,strokeDashoffset:E}=ro(y.length,f,{style:d,snap:1,start:"outset",end:"outset",closed:!0});return u.jsx("path",{d:y.getSvgPathData(),strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:b,strokeDashoffset:E,pointerEvents:"all"},`curve_${v}`)})]})}else{const g=LX(a,S,f,e.id);return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:g,color:l,fill:c,scale:t}),u.jsx("path",{d:g,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}default:{const g=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=g instanceof Hr?g.children[0].vertices:g.vertices,y=jv(e.props,f);if(d==="solid"){let v="M"+x[0]+"L"+x.slice(1)+"Z";if(y)for(const[b,E]of y)v+=`M${b.x},${b.y}L${E.x},${E.y}`;return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),u.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else if(d==="dashed"||d==="dotted"){const v="M"+x[0]+"L"+x.slice(1)+"Z";return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),u.jsxs("g",{strokeWidth:f,stroke:o[l].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(x.length)).map((b,E)=>{const I=w.ToFixed(x[E]),C=w.ToFixed(x[(E+1)%x.length]),k=w.Dist(I,C),{strokeDasharray:T,strokeDashoffset:O}=ro(k,f,{style:d,start:"outset",end:"outset"});return u.jsx("line",{x1:I.x,y1:I.y,x2:C.x,y2:C.y,strokeDasharray:T,strokeDashoffset:O},E)}),y&&y.map(([b,E],I)=>{const C=w.Dist(b,E),{strokeDasharray:k,strokeDashoffset:T}=ro(C,f,{style:d,start:"skip",end:"skip",snap:d==="dotted"?4:void 0});return u.jsx("path",{d:`M${b.x},${b.y}L${E.x},${E.y}`,stroke:o[l].solid,strokeWidth:f,fill:"none",strokeDasharray:k,strokeDashoffset:T},`line_fg_${I}`)})]})]})}else if(d==="draw"){let v=_v(Tv(s,x,f/3,f*2,2));if(y)for(const[E,I]of y)v+=`M${E.toFixed()}L${I.toFixed()}`;const b=_v(Tv(s,x,0,f*2,1));return u.jsxs(u.Fragment,{children:[u.jsx(en,{theme:o,d:b,color:l,fill:c,scale:t}),u.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}}}}const pr=17*3;class Qh extends $l{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});m(this,"onResize",(t,{handle:r,newPoint:o,scaleX:s,scaleY:i,initialShape:a})=>{let l=a.props.w*s,c=(a.props.h+a.props.growY)*i,d=0,h=0;if(t.props.text.trim()){let g=Math.max(Math.abs(l),pr),x=Math.max(Math.abs(c),pr);g<pr&&x===pr&&(g=pr),g===pr&&x<pr&&(x=pr);const y=Xd(this.editor,{...t,props:{...t.props,w:g,h:x}}),v=Math.max(Math.abs(l),y.w)*Math.sign(l),b=Math.max(Math.abs(c),y.h)*Math.sign(c);d=Math.abs(v)-Math.abs(l),h=Math.abs(b)-Math.abs(c),l=v,c=b}const p=new w(0,0);s<0&&(p.x+=l),(r==="left"||r==="top_left"||r==="bottom_left")&&(p.x+=s<0?d:-d),i<0&&(p.y+=c),(r==="top"||r==="top_left"||r==="top_right")&&(p.y+=i<0?h:-h);const{x:f,y:S}=p.rot(t.rotation).add(o);return{x:f,y:S,props:{w:Math.max(Math.abs(l),1),h:Math.max(Math.abs(c),1),growY:0}}});m(this,"onBeforeCreate",t=>{if(!t.props.text)return t.props.growY?{...t,props:{...t.props,growY:0}}:void 0;const r=t.props.h,o=Xd(this.editor,t).h;let s=null;if(o>r?s=o-r:t.props.growY&&(s=0),s!==null)return{...t,props:{...t.props,growY:s}}});m(this,"onBeforeUpdate",(t,r)=>{const o=t.props.text,s=r.props.text;if(o===s&&t.props.font===r.props.font&&t.props.size===r.props.size)return;if(o&&!s)return{...r,props:{...r.props,growY:0}};const i=t.props.w,a=t.props.h,l=Xd(this.editor,r),c=l.w,d=l.h;if(!o&&s&&s.length===1){let p=Math.max(i,c),f=Math.max(a,d);return t.props.w<pr&&t.props.h<pr&&(p=Math.max(p,pr),f=Math.max(f,pr),p=Math.max(p,f),f=Math.max(p,f)),{...r,props:{...r.props,w:p,h:f,growY:0}}}let h=null;if(d>a?h=d-a:t.props.growY&&(h=0),h!==null)return{...r,props:{...r.props,growY:h,w:Math.max(r.props.w,c)}};if(c>t.props.w)return{...r,props:{...r.props,w:c}}});m(this,"onDoubleClick",t=>{if(this.editor.inputs.altKey)switch(t.props.geo){case"rectangle":return{...t,props:{geo:"check-box"}};case"check-box":return{...t,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:"",scale:1}}getGeometry(t){const r=Math.max(1,t.props.w),o=Math.max(1,t.props.h+t.props.growY),s=r/2,i=o/2,a=At[t.props.size]*t.props.scale,l=t.props.fill!=="none";let c;switch(t.props.geo){case"cloud":{c=new vt({points:HX(r,o,t.id,t.props.size),isFilled:l});break}case"triangle":{c=new vt({points:[new w(s,0),new w(r,o),new w(0,o)],isFilled:l});break}case"diamond":{c=new vt({points:[new w(s,0),new w(r,i),new w(s,o),new w(0,i)],isFilled:l});break}case"pentagon":{c=new vt({points:Km(r,o,5),isFilled:l});break}case"hexagon":{c=new vt({points:Km(r,o,6),isFilled:l});break}case"octagon":{c=new vt({points:Km(r,o,8),isFilled:l});break}case"ellipse":{c=new wV({width:r,height:o,isFilled:l});break}case"oval":{c=new bV({width:r,height:o,isFilled:l});break}case"star":{const v=Re/5/2,b=Math.floor(5/4)*2,E=5*2-b,I=0,C=Math.floor(5/2)*2,k=Math.cos(-Ve+b*v)*r/2,T=Math.cos(-Ve+E*v)*r/2,O=Math.sin(-Ve+I*v)*o/2,_=Math.sin(-Ve+C*v)*o/2,j=r-Math.abs(k-T),L=o-Math.abs(_-O),A=r/2+T-(r/2-k),R=o/2+O-(o/2-_),F=1,W=(r-A)/2,K=(o-R)/2,z=(r+j)/2,U=(o+L)/2,X=z*F/2,J=U*F/2;c=new vt({points:Array.from(Array(5*2)).map((le,ye)=>{const Me=-Ve+ye*v;return new w(W+(ye%2?X:z)*Math.cos(Me),K+(ye%2?J:U)*Math.sin(Me))}),isFilled:l});break}case"rhombus":{const y=Math.min(r*.38,o*.38);c=new vt({points:[new w(y,0),new w(r,0),new w(r-y,o),new w(0,o)],isFilled:l});break}case"rhombus-2":{const y=Math.min(r*.38,o*.38);c=new vt({points:[new w(0,0),new w(r-y,0),new w(r,o),new w(y,o)],isFilled:l});break}case"trapezoid":{const y=Math.min(r*.38,o*.38);c=new vt({points:[new w(y,0),new w(r-y,0),new w(r,o),new w(0,o)],isFilled:l});break}case"arrow-right":{const y=Math.min(r,o)*.38,v=o*.16;c=new vt({points:[new w(0,v),new w(r-y,v),new w(r-y,0),new w(r,o/2),new w(r-y,o),new w(r-y,o-v),new w(0,o-v)],isFilled:l});break}case"arrow-left":{const y=Math.min(r,o)*.38,v=o*.16;c=new vt({points:[new w(y,0),new w(y,v),new w(r,v),new w(r,o-v),new w(y,o-v),new w(y,o),new w(0,o/2)],isFilled:l});break}case"arrow-up":{const y=r*.16,v=Math.min(r,o)*.38;c=new vt({points:[new w(r/2,0),new w(r,v),new w(r-y,v),new w(r-y,o),new w(y,o),new w(y,v),new w(0,v)],isFilled:l});break}case"arrow-down":{const y=r*.16,v=Math.min(r,o)*.38;c=new vt({points:[new w(y,0),new w(r-y,0),new w(r-y,o-v),new w(r,o-v),new w(r/2,o),new w(0,o-v),new w(y,o-v)],isFilled:l});break}case"check-box":case"x-box":case"rectangle":{c=new Jo({width:r,height:o,isFilled:l});break}case"heart":{const v=u0(r,o).reduce((b,E)=>(b.push(...E.vertices),b),[]);c=new vt({points:v,isFilled:l});break}default:an(t.props.geo)}const d=Xd(this.editor,t),h=Math.min(100,r/2),p=Math.min(Wo[t.props.size]*t.props.scale*Wt.lineHeight+Dr*2,o/2),f=Math.min(r,Math.max(d.w,Math.min(h,Math.max(1,r-8)))),S=Math.min(o,Math.max(d.h,Math.min(p,Math.max(1,r-8)))),g=jv(t.props,a),x=g?g.map(y=>new Ll({points:y})):[];return new Hr({children:[c,new Jo({x:t.props.align==="start"?0:t.props.align==="end"?r-f:(r-f)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?o-S:(o-S)/2,width:f,height:S,isFilled:!0,isLabel:!0}),...x]})}getHandleSnapGeometry(t){const r=this.getGeometry(t),o=r.children[0];switch(t.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"heart":case"oval":return{outline:o,points:[r.bounds.center]};default:an(t.props.geo)}}component(t){const{id:r,type:o,props:s}=t,{fill:i,font:a,align:l,verticalAlign:c,size:d,text:h}=s,p=t.id===this.editor.getOnlySelectedShapeId(),f=_r(),g=this.editor.getEditingShapeId()!==null||t.props.text;return u.jsxs(u.Fragment,{children:[u.jsx(Ys,{id:r,children:u.jsx(fI,{shape:t,shouldScale:!0})}),g&&u.jsx(Vi,{style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:u.jsx(fg,{id:r,type:o,font:a,fontSize:Wo[d]*t.props.scale,lineHeight:Wt.lineHeight,padding:16*t.props.scale,fill:i,align:l,verticalAlign:c,text:h,isSelected:p,labelColor:f[s.labelColor].solid,wrap:!0})}),t.props.url&&u.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{id:r,props:o}=t,{w:s,size:i}=o,a=o.h+o.growY,l=At[i],c=this.editor.getShapeGeometry(t);switch(o.geo){case"ellipse":return o.dash==="draw"?u.jsx("path",{d:NX(r,s,a,l)}):u.jsx("path",{d:c.getSvgPathData(!0)});case"heart":return u.jsx("path",{d:mj(s,a)});case"oval":return u.jsx("path",{d:c.getSvgPathData(!0)});case"cloud":return u.jsx("path",{d:Mv(s,a,r,i)});default:{const d=this.editor.getShapeGeometry(t),h=d instanceof Hr?d.children[0].vertices:d.vertices;let p;if(o.dash==="draw"){const S=Tv(r,h,0,l*2*t.props.scale,1);p=_v(S)}else p="M"+h[0]+"L"+h.slice(1)+"Z";const f=jv(t.props,l);if(f)for(const[S,g]of f)p+=`M${S.x},${S.y}L${g.x},${g.y}`;return u.jsx("path",{d:p})}}}toSvg(t,r){const o={...t,props:{...t.props,w:t.props.w/t.props.scale,h:t.props.h/t.props.scale}},s=o.props;r.addExportDef(s0(s.fill));let i;if(s.text){r.addExportDef(vl(s.font));const a=ss(r),l=new Z(0,0,s.w,s.h+s.growY);i=u.jsx(pg,{fontSize:Wo[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:a[s.labelColor].solid,bounds:l,padding:16})}return u.jsxs(u.Fragment,{children:[u.jsx(fI,{shouldScale:!1,shape:o}),i]})}getCanvasSvgDefs(){return[i0()]}}m(Qh,"type","geo"),m(Qh,"props",bM),m(Qh,"migrations",PM);function Xd(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Wt,fontFamily:mo[n.props.font],fontSize:Wo[n.props.size]*n.props.scale,maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(t,{...Wt,fontFamily:mo[n.props.font],fontSize:Wo[n.props.size]*n.props.scale,minWidth:r.w,maxWidth:Math.max(0,Math.ceil(r.w+o[n.props.size]),Math.ceil(n.props.w-Dr*2))});return{w:s.w+Dr*2,h:s.h+Dr*2}}function YX(){const[e,n]=P.useState(!1);return P.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");n(r&&o.matches);const s=()=>n(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),G(wt.forceSrgb)||!e?"srgb":"p3"}const gI=.35,mI=.82;class Jh extends Br{constructor(){super(...arguments);m(this,"hideResizeHandles",t=>qd(t));m(this,"hideRotateHandle",t=>qd(t));m(this,"hideSelectionBoundsFg",t=>qd(t));m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:d})=>({x:o*l,y:s*c,z:d}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=Pi(t);if(qd(t))return new t0({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=yI(t,r,!0),i=c0({strokeWidth:s,showAsComplete:!0});return dg(o,i),new vt({points:n0(o,i),isFilled:!0})}component(t){const r=hy(this.editor,t),o=Pi(t);return u.jsx(Ys,{id:t.id,children:u.jsx(Zd,{shape:t,forceSolid:r,strokeWidth:o,opacity:gI})})}backgroundComponent(t){const r=hy(this.editor,t),o=Pi(t);return u.jsx(Ys,{id:t.id,children:u.jsx(Zd,{shape:t,forceSolid:r,strokeWidth:o,opacity:mI})})}indicator(t){const r=hy(this.editor,t),o=Pi(t),{strokePoints:s,sw:i}=yI(t,o,r),a=wl(t.props.segments);let l;return s.length<2?l=qX(a[0],i):l=Yi(s,!1),u.jsx("path",{d:l})}toSvg(t){const r=Pi(t),o=r<1.5,s=1/t.props.scale;return u.jsx("g",{transform:`scale(${s})`,children:u.jsx(Zd,{forceSolid:o,strokeWidth:r,shape:t,opacity:gI})})}toBackgroundSvg(t){const r=Pi(t),o=r<1.5,s=1/t.props.scale;return u.jsx("g",{transform:`scale(${s})`,children:u.jsx(Zd,{forceSolid:o,strokeWidth:r,shape:t,opacity:mI})})}}m(Jh,"type","highlight"),m(Jh,"props",EM),m(Jh,"migrations",kM);function XX(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 qX(e,n){const t=n/2;return`M ${e.x} ${e.y} m -${t}, 0 a ${t},${t} 0 1,0 ${t*2},0 a ${t},${t} 0 1,0 -${t*2},0`}function yI(e,n,t){var l;const r=wl(e.props.segments),o=e.props.isComplete||((l=Nt(e.props.segments))==null?void 0:l.type)==="straight";let s=n;!t&&!e.props.isPen&&r.length===1&&(s+=Wr(e.id)()*(n/6));const i=c0({strokeWidth:s,showAsComplete:o});return{strokePoints:xo(r,i),sw:s}}function Pi(e){return yl[e.props.size]*1.12*e.props.scale}function qd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function Zd({strokeWidth:e,forceSolid:n,shape:t,opacity:r}){var p;const o=_r(),s=wl(t.props.segments);let i=e;!n&&!t.props.isPen&&s.length===1&&(i+=Wr(t.id)()*(i/6));const a=c0({strokeWidth:i,showAsComplete:t.props.isComplete||((p=Nt(t.props.segments))==null?void 0:p.type)==="straight"}),l=xo(s,a),c=l.length>1?Yi(l,!1):XX(t.props.segments[0].points[0]),d=YX(),h=o[t.props.color].highlight[d];return u.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function hy(e,n){return G("forceSolid",()=>{const t=Pi(n),r=e.getZoomLevel();return t/r<1.5},[e])}function yj(){return u.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:[u.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),u.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),u.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function Sj(e,n,t){const r=B(),[o,s]=P.useState(null),i=n?r.getAsset(n):null,l=r.getCulledShapes().has(e),c=i&&"w"in i.props?t/i.props.w:1,d=G("zoom level",()=>r.getZoomLevel()*c,[r,c]);return P.useEffect(()=>{if(l)return;let h=!1;const p=r.timers.setTimeout(async()=>{const f=await r.resolveAssetUrl(n,{screenScale:d});h||s(f)},500);return()=>{clearTimeout(p),h=!0}},[n,i==null?void 0:i.props.src,l,d,r]),{asset:i,url:o}}function vj(){const[e,n]=P.useState(!1);return P.useEffect(()=>{const t=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{n(t.matches)};return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),e}async function ZX(e){const t=await(await yo(e)).blob();return Oi.blobToDataUrl(t)}class ep extends $l{constructor(){super(...arguments);m(this,"isAspectRatioLocked",()=>!0);m(this,"canCrop",()=>!0);m(this,"onDoubleClick",t=>{const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;!r||!(r.props.src&&this.isAnimated(t))||this.editor.updateShapes([{type:"image",id:t.id,props:{playing:!t.props.playing}}])});m(this,"onDoubleClickEdge",t=>{const r=t.props;if(!r||this.editor.getCroppingShapeId()!==t.id)return;const o=rt(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},s=1/(o.bottomRight.x-o.topLeft.x)*t.props.w,i=1/(o.bottomRight.y-o.topLeft.y)*t.props.h,a=new w(o.topLeft.x*s,o.topLeft.y*i).rot(t.rotation),l={id:t.id,type:t.type,x:t.x-a.x,y:t.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([l])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}isAnimated(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;return r?"mimeType"in r.props&&ao.isAnimatedImageType(r==null?void 0:r.props.mimeType)||"isAnimated"in r.props&&r.props.isAnimated:!1}component(t){var g;const r=this.editor.getCroppingShapeId()===t.id,o=vj(),[s,i]=P.useState(""),[a,l]=P.useState(""),c=t.id===this.editor.getOnlySelectedShapeId(),{asset:d,url:h}=Sj(t.id,t.props.assetId,t.props.w);if(P.useEffect(()=>{if(h){let x=!1;const y=pl();return y.onload=()=>{x||l(h)},y.src=h,()=>{x=!0}}},[h,t]),P.useEffect(()=>{if(h&&this.isAnimated(t)){let x=!1;const y=pl();return y.onload=()=>{if(x)return;const v=document.createElement("canvas");v.width=y.width,v.height=y.height;const b=v.getContext("2d");b&&(b.drawImage(y,0,0),i(v.toDataURL()),l(h))},y.crossOrigin="anonymous",y.src=h,()=>{x=!0}}},[o,h,t]),(d==null?void 0:d.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const p=c&&r&&this.editor.isIn("select.crop"),f=o&&(((g=d==null?void 0:d.props.mimeType)==null?void 0:g.includes("video"))||this.isAnimated(t)),S=SI(t);return d!=null&&d.props.src?a?u.jsxs(u.Fragment,{children:[p&&u.jsx("div",{style:S,children:u.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(t)?"anonymous":void 0,src:!t.props.playing||f?s:a,referrerPolicy:"strict-origin-when-cross-origin",style:{opacity:.1},draggable:!1})}),u.jsxs(Vi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h},children:[u.jsxs("div",{className:"tl-image-container",style:S,children:[u.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(t)?"anonymous":void 0,src:!t.props.playing||f?s:a,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1}),this.isAnimated(t)&&!t.props.playing&&u.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),t.props.url&&u.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):null:u.jsxs(Vi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h,color:"var(--color-text-3)",backgroundColor:d?"transparent":"var(--color-low)",border:d?"none":"1px solid var(--color-low-border)"},children:[u.jsx("div",{className:"tl-image-container",style:S,children:d?null:u.jsx(yj,{})}),"url"in t.props&&t.props.url&&u.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return this.editor.getCroppingShapeId()===t.id?null:u.jsx("rect",{width:N(t.props.w),height:N(t.props.h)})}async toSvg(t){if(!t.props.assetId||!this.editor.getAsset(t.props.assetId))return null;let o=await this.editor.resolveAssetUrl(t.props.assetId,{shouldResolveToOriginalImage:!0});if(!o)return null;(o.startsWith("blob:")||o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await ZX(o)||"");const s=SI(t),i=t.props.crop;if(s.transform&&i){const{transform:a,width:l,height:c}=s,d=(i.bottomRight.x-i.topLeft.x)*l,h=(i.bottomRight.y-i.topLeft.y)*c,p=[new w(0,0),new w(d,0),new w(d,h),new w(0,h)],f=`cropClipPath_${t.id.replace(":","_")}`;return u.jsxs(u.Fragment,{children:[u.jsx("defs",{children:u.jsx("clipPath",{id:f,children:u.jsx("polygon",{points:p.map(S=>`${S.x},${S.y}`).join(" ")})})}),u.jsx("g",{clipPath:`url(#${f})`,children:u.jsx("image",{href:o,width:l,height:c,style:{transform:a}})})]})}else return u.jsx("image",{href:o,width:t.props.w,height:t.props.h})}}m(ep,"type","image"),m(ep,"props",_M),m(ep,"migrations",TM);function SI(e){const n=e.props.crop,t=n==null?void 0:n.topLeft;if(!t)return{width:e.props.w,height:e.props.h};const r=1/(n.bottomRight.x-n.topLeft.x)*e.props.w,o=1/(n.bottomRight.y-n.topLeft.y)*e.props.h,s=-t.x*r,i=-t.y*o;return{transform:`translate(${s}px, ${i}px)`,width:r,height:o}}function xj(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function wj(e,n,t){const r=n.vertices,o=xj(t);return xo(r,o)}function QX(e,n,t){const r=xj(t);return n0(dg(wj(e,n,t),r),r)}function JX(e,n,t){const r=QX(e,n,t);return zw(r)}function eq(e,n,t){if(e.props.dash==="draw"){const r=wj(e,n,t);return Yi(r)}return n.getSvgPathData()}function bj(e,n,t){let r=`M ${Ie(n[0])}L`,o=`M ${Ie(n[0])}L`;const s=t/3,i=t*2,a=Wr(e);let l=n[0],c,d=n[0],h;const p=n.length;for(let f=0,S=p-1;f<S;f++){c=n[f+1],h=w.AddXY(n[f+1],a()*s,a()*s);const g=w.Sub(c,l),x=w.Len(g),y=w.Div(g,x).mul(Math.min(x/4,i)),v=w.Add(l,y),b=w.Add(c,y.neg()),E=w.Sub(h,d),I=w.Len(E),C=w.Div(E,I).mul(Math.min(I/4,i)),k=w.Add(d,C),T=w.Add(h,C.neg());f===S-1?(r+=`${Ie(v)}L ${Ie(c)}`,o+=`${Ie(k)}L ${Ie(h)}`):(r+=`${Ie(v)}L ${Ie(b)}Q ${Ie(c)}`,o+=`${Ie(k)}L ${Ie(T)}Q ${Ie(h)}`,l=c,d=h)}return[r,r+o]}const tq=new Zo;class tp extends Br{constructor(){super(...arguments);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r;return{props:{points:Ru(t.props.points,(i,{id:a,index:l,x:c,y:d})=>({id:a,index:l,x:c*o,y:d*s}))}}});m(this,"onHandleDrag",(t,{handle:r})=>{if(r.type==="vertex")return{...t,props:{...t.props,points:{...t.props.points,[r.id]:{id:r.id,index:r.index,x:r.x,y:r.y}}}}})}getDefaultProps(){const[t,r]=du(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[t]:{id:t,index:t,x:0,y:0},[r]:{id:r,index:r,x:.1,y:.1}},scale:1}}getGeometry(t){return Ec(t)}getHandles(t){return tq.get(t.props,()=>{const r=Ec(t),o=Av(t),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=uu(o[i].index,o[i+1].index),c=r.segments[i].midPoint();s.push({id:a,type:"create",index:a,x:c.x,y:c.y,canSnap:!0})}return s.sort(on)})}component(t){return u.jsx(Ys,{id:t.id,children:u.jsx(vI,{shape:t})})}indicator(t){const r=At[t.props.size]*t.props.scale,o=Ec(t),{dash:s}=t.props;let i;if(t.props.spline==="line"){const a=o.points;if(s==="solid"||s==="dotted"||s==="dashed")i="M"+a[0]+"L"+a.slice(1);else{const[l]=bj(t.id,a,r);i=l}}else i=eq(t,o,r);return u.jsx("path",{d:i})}toSvg(t){return u.jsx(vI,{shouldScale:!0,shape:t})}getHandleSnapGeometry(t){const r=Av(t);return{points:r,getSelfSnapPoints:o=>{const s=this.getHandles(t).filter(i=>i.type==="vertex").findIndex(i=>i.id===o.id);return r.filter((i,a)=>Math.abs(a-s)>1).map(w.From)},getSelfSnapOutline:o=>{const s=this.getHandles(t).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),i=Ec(t).segments.filter((a,l)=>l!==s-1&&l!==s);return i.length?new Hr({children:i}):null}}}}m(tp,"type","line"),m(tp,"props",MM),m(tp,"migrations",jM);function Av(e){return Object.values(e.props.points).sort(on)}function Ec(e){const n=Av(e).map(w.From);switch(e.props.spline){case"cubic":return new xV({points:n});case"line":return new Ll({points:n})}}function vI({shape:e,shouldScale:n=!1}){const t=_r(),r=Ec(e),{dash:o,color:s,size:i}=e.props,a=1/e.props.scale,l=n?a:1,c=At[i]*e.props.scale;if(e.props.spline==="line"){if(o==="solid"){const d=r.points,h="M"+d[0]+"L"+d.slice(1);return u.jsx("path",{d:h,stroke:t[s].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}if(o==="dashed"||o==="dotted")return u.jsx("g",{stroke:t[s].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((d,h)=>{const{strokeDasharray:p,strokeDashoffset:f}=ro(d.length,c,{style:o,start:h>0?"outset":"none",end:h<r.segments.length-1?"outset":"none"});return u.jsx("path",{strokeDasharray:p,strokeDashoffset:f,d:d.getSvgPathData(!0),fill:"none"},h)})});if(o==="draw"){const d=r.points,[h,p]=bj(e.id,d,c);return u.jsx("path",{d:p,stroke:t[s].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}}if(e.props.spline==="cubic"){const d=r.getSvgPathData();if(o==="solid")return u.jsx("path",{strokeWidth:c,stroke:t[s].solid,fill:"none",d,transform:`scale(${l})`});if(o==="dashed"||o==="dotted")return u.jsx("g",{stroke:t[s].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((h,p)=>{const{strokeDasharray:f,strokeDashoffset:S}=ro(h.length,c,{style:o,start:p>0?"outset":"none",end:p<r.segments.length-1?"outset":"none"});return u.jsx("path",{strokeDasharray:f,strokeDashoffset:S,d:h.getSvgPathData(),fill:"none"},p)})});if(o==="draw")return u.jsx("path",{d:JX(e,r,c),strokeWidth:1,stroke:t[s].solid,fill:t[s].solid,transform:`scale(${l})`})}}const Pj=P.createContext(null);function nq({assetUrls:e,children:n}){return P.useEffect(()=>{for(const t of Object.values(e.icons)){const r=pl();r.src=t,r.decode()}for(const t of Object.values(e.embedIcons)){const r=pl();r.src=t,r.decode()}},[e]),u.jsx(Pj.Provider,{value:e,children:n})}function d0(){const e=P.useContext(Pj);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const Ov={"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.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.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-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","theme.dark":"Dark","theme.light":"Light","theme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","menu.title":"Menu","menu.theme":"Theme","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy editor 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 viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","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..."},rq=new Set(["ar","fa","he","ur","ku"]),Sa={locale:"en",label:"English",messages:Ov,dir:"ltr"};async function oq(e,n){if(!(await yo(n.translations.en)).ok)return console.warn("No main translations found."),Sa;if(e==="en")return Sa;const r=pu.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),Sa;const s=await(await yo(n.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),Sa;const i=[];for(const a in Sa.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:rq.has(r.locale)?"rtl":"ltr",messages:{...Sa.messages,...s}}}const Cj=P.createContext(null);function Ij(){const e=P.useContext(Cj);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const sq=lr(function({overrides:n,children:t}){const o=B().user.getLocale(),s=d0(),[i,a]=P.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...Ov,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:Ov});return P.useEffect(()=>{let l=!1;async function c(){const d=await oq(o,s);d&&!l&&(n&&n[o]?a({...d,messages:{...d.messages,...n[o]}}):a(d))}return c(),()=>{l=!0}},[s,o,n]),u.jsx(Cj.Provider,{value:i,children:t})});function Te(){const e=Ij();return P.useCallback(function(t){return e.messages[t]??t},[e])}class np extends Br{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"hideResizeHandles",()=>!0);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"onBeforeCreate",t=>xI(this.editor,t));m(this,"onBeforeUpdate",(t,r)=>{if(!(t.props.text===r.props.text&&t.props.font===r.props.font&&t.props.size===r.props.size))return xI(this.editor,r)});m(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.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:"",scale:1}}getGeometry(t){const{labelHeight:r,labelWidth:o}=Ej(this.editor,t),{scale:s}=t.props,i=r*s,a=o*s,l=Be*s,c=Qd(t);return new Hr({children:[new Jo({width:l,height:c,isFilled:!0}),new Jo({x:t.props.align==="start"?0:t.props.align==="end"?l-a:(l-a)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?c-i:(c-i)/2,width:a,height:i,isFilled:!0,isLabel:!0})]})}getHandles(t){const{scale:r}=t.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const s=this.editor.getZoomLevel();if(s*r<.25)return[];const i=Qd(t),a=Be*r,l=AY/s*r;return s*r<.5?[{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l}]:[{id:"top",index:"a1",type:"clone",x:a/2,y:-l},{id:"right",index:"a2",type:"clone",x:a+l,y:i/2},{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l},{id:"left",index:"a4",type:"clone",x:-l,y:i/2}]}component(t){const{id:r,type:o,props:{scale:s,color:i,font:a,size:l,align:c,text:d,verticalAlign:h,fontSizeAdjustment:p}}=t,f=lq(r),S=_r(),g=Be*s,x=Qd(t),y=G("shape rotation",()=>{var E;return((E=this.editor.getShapePageTransform(r))==null?void 0:E.rotation())??0},[this.editor]),v=G("zoom",()=>this.editor.getZoomLevel()<.35/s,[s,this.editor]),b=t.id===this.editor.getOnlySelectedShapeId();return u.jsxs(u.Fragment,{children:[u.jsx("div",{id:r,className:"tl-note__container",style:{width:g,height:x,backgroundColor:S[i].note.fill,borderBottom:v?`${3*s}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:v?"none":cq(t.id,y,s)},children:u.jsx(fg,{id:r,type:o,font:a,fontSize:(p||Wo[l])*s,lineHeight:Wt.lineHeight,align:c,verticalAlign:h,text:d,isNote:!0,isSelected:b,labelColor:S[i].note.text,wrap:!0,padding:16*s,onKeyDown:f})}),"url"in t.props&&t.props.url&&u.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{scale:r}=t.props;return u.jsx("rect",{rx:r,width:N(Be*r),height:N(Qd(t))})}toSvg(t,r){r.addExportDef(vl(t.props.font)),t.props.text&&r.addExportDef(vl(t.props.font));const o=ss({isDarkMode:r.isDarkMode}),s=uq(t);return u.jsxs(u.Fragment,{children:[u.jsx("rect",{x:5,y:5,rx:1,width:Be-10,height:s.h,fill:"rgba(0,0,0,.1)"}),u.jsx("rect",{rx:1,width:Be,height:s.h,fill:o[t.props.color].note.fill}),u.jsx(pg,{fontSize:t.props.fontSizeAdjustment||Wo[t.props.size],font:t.props.font,align:t.props.align,verticalAlign:t.props.verticalAlign,text:t.props.text,labelColor:o[t.props.color].note.text,bounds:s,stroke:!1})]})}}m(np,"type","note"),m(np,"props",AM),m(np,"migrations",OM);function xI(e,n){const{labelHeight:t,fontSizeAdjustment:r}=Ej(e,n),o=Math.max(0,t-Be);if(o!==n.props.growY||r!==n.props.fontSizeAdjustment)return{...n,props:{...n.props,growY:o,fontSizeAdjustment:r}}}function iq(e,n){const{text:t}=n.props;if(!t)return{labelHeight:Wo[n.props.size]*Wt.lineHeight+Dr*2,labelWidth:100,fontSizeAdjustment:0};const r=Wo[n.props.size];let o=0,s=0,i=Be,a=Be;const l=1;do{o=Math.min(r,r-s);const c=e.textMeasure.measureText(t,{...Wt,fontFamily:mo[n.props.font],fontSize:o,maxWidth:Be-Dr*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Dr*2,a=c.w+Dr*2,o<=14){const d=e.textMeasure.measureText(t,{...Wt,fontFamily:mo[n.props.font],fontSize:o,maxWidth:Be-Dr*2-l});i=d.h+Dr*2,a=d.w+Dr*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const aq=new Zo;function Ej(e,n){return aq.get(n,()=>iq(e,n))}function lq(e){const n=B(),t=Ij();return P.useCallback(r=>{const o=n.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=n.getShapePageTransform(e),l=a.rotation(),c=!!(t.dir==="rtl"||Z2(o.props.text)),d=(Be+n.options.adjacentShapeMargin+(i&&!r.shiftKey?o.props.growY:0))*o.props.scale,h=new w(s?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(d).add(hg.clone().mul(o.props.scale)).rot(l).add(a.point()),p=sj(n,o,h,l);p&&(n.mark("editing adjacent shape"),mf(n,p,!0))}},[e,n,t.dir])}function Qd(e){return(Be+e.props.growY)*e.props.scale}function cq(e,n,t){const r=Wr(e),o=Math.abs(r())+.5,s=Math.cos(n),i=5*t,a=4*t,l=6*t,c=7*t;return`0px ${i-o}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
0px ${(a+o*c)*Math.max(0,s)}px ${l+o*c}px -${a+o*l}px rgba(15, 23, 31, ${(.3+o*.1).toFixed(2)}),
|
|
0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function uq(e){return new Z(0,0,Be,Be+e.props.growY)}function dq(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),i=new w(0,0);t<0&&(i.x=-(n.width*s)),r<0&&(i.y=-(n.height*s));const{x:a,y:l}=w.Add(o,i.rot(e.rotation));return{x:a,y:l,props:{scale:s*e.props.scale}}}const hq=new Zo;class rp extends Br{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0);m(this,"onResize",(t,r)=>{const{newPoint:o,initialBounds:s,initialShape:i,scaleX:a,handle:l}=r;if(r.mode==="scale_shape"||l!=="right"&&l!=="left")return{id:t.id,type:t.type,...dq(t,r)};{const c=Math.max(1,Math.abs(s.width*a)),{x:d,y:h}=a<0?w.Sub(o,w.FromAngle(t.rotation).mul(c)):o;return{id:t.id,type:t.type,x:d,y:h,props:{w:c/i.props.scale,autoSize:!1}}}});m(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t,i=t.props.text.trimEnd();i.length===0?this.editor.deleteShapes([t.id]):i!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});m(this,"onBeforeUpdate",(t,r)=>{if(!r.props.autoSize)return;const o=t.props.size!==r.props.size||t.props.textAlign!==r.props.textAlign||t.props.font!==r.props.font||t.props.scale!==1&&r.props.scale===1,s=t.props.text!==r.props.text;if(!o&&!s)return;const i=this.getMinDimensions(t),a=wI(this.editor,r.props),l=i.width*t.props.scale,c=i.height*t.props.scale,d=a.width*r.props.scale,h=a.height*r.props.scale;let p;switch(r.props.textAlign){case"middle":{p=new w((d-l)/2,s?0:(h-c)/2);break}case"end":{p=new w(d-l,s?0:(h-c)/2);break}default:{if(s)break;p=new w(0,(h-c)/2);break}}if(p){p.rot(r.rotation);const{x:f,y:S}=r;return{...r,x:f-p.x,y:S-p.y,props:{...r.props,w:d}}}else return{...r,props:{...r.props,w:d}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(t){return hq.get(t.props,r=>wI(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:s}=this.getMinDimensions(t);return new Jo({width:o*r,height:s*r,isFilled:!0,isLabel:!0})}component(t){const{id:r,props:{font:o,size:s,text:i,color:a,scale:l,textAlign:c}}=t,{width:d,height:h}=this.getMinDimensions(t),p=t.id===this.editor.getOnlySelectedShapeId(),f=_r(),S=pq(r);return u.jsx(fg,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:yl[s],lineHeight:Wt.lineHeight,align:c,verticalAlign:"middle",text:i,labelColor:f[a].solid,isSelected:p,textWidth:d,textHeight:h,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0,onKeyDown:S})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=B();return t.props.autoSize&&o.getEditingShapeId()===t.id?null:u.jsx("rect",{width:N(r.width),height:N(r.height)})}toSvg(t,r){r.addExportDef(vl(t.props.font)),t.props.text&&r.addExportDef(vl(t.props.font));const o=this.editor.getShapeGeometry(t).bounds,s=o.width/(t.props.scale??1),i=o.height/(t.props.scale??1),a=ss(r);return u.jsx(pg,{fontSize:yl[t.props.size],font:t.props.font,align:t.props.textAlign,verticalAlign:"middle",text:t.props.text,labelColor:a[t.props.color].solid,bounds:new Z(0,0,s,i),padding:0})}}m(rp,"type","text"),m(rp,"props",DM),m(rp,"migrations",RM);function wI(e,n){const{font:t,text:r,autoSize:o,size:s,w:i}=n,a=o?16:Math.max(16,i),l=yl[s],c=o?null:Math.floor(Math.max(a,i)),d=e.textMeasure.measureText(r,{...Wt,fontFamily:mo[t],fontSize:l,maxWidth:c});return o&&(d.w+=1),{width:Math.max(a,d.w),height:Math.max(l,d.h)}}function pq(e){const n=B();return P.useCallback(t=>{if(n.getEditingShapeId()===e)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&n.complete();break}case"Tab":{Ee(t),t.shiftKey?Sl.unindent(t.currentTarget):Sl.indent(t.currentTarget);break}}},[n,e])}class op extends $l{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(t){const{editor:r}=this,o=r.getShapeGeometry(t).bounds.w*r.getZoomLevel()>=110,{asset:s,url:i}=Sj(t.id,t.props.assetId,t.props.w),{time:a,playing:l}=t.props,c=ug(t.id),d=vj(),h=P.useRef(null),p=P.useCallback(v=>{const b=v.currentTarget;b&&r.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:b.currentTime}}])},[t.id,r]),f=P.useCallback(v=>{const b=v.currentTarget;b&&r.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:b.currentTime}}])},[t.id,r]),S=P.useCallback(v=>{const b=v.currentTarget;b&&c&&r.updateShapes([{type:"video",id:t.id,props:{time:b.currentTime}}])},[c,t.id,r]),[g,x]=P.useState(!1),y=P.useCallback(v=>{const b=v.currentTarget;b&&(a!==b.currentTime&&(b.currentTime=a),l||b.pause(),x(!0))},[l,a]);return P.useEffect(()=>{const v=h.current;v&&(g&&!c&&a!==v.currentTime&&(v.currentTime=a),c&&document.activeElement!==v&&v.focus())},[c,g,a]),P.useEffect(()=>{if(d){const v=h.current;if(!v)return;v.pause(),v.currentTime=0}},[h,d]),u.jsxs(u.Fragment,{children:[u.jsx(Vi,{id:t.id,style:{color:"var(--color-text-3)",backgroundColor:s?"transparent":"var(--color-low)",border:s?"none":"1px solid var(--color-low-border)"},children:u.jsx("div",{className:"tl-counter-scaled",children:u.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?i?u.jsx("video",{ref:h,style:c?{pointerEvents:"all"}:void 0,className:`tl-video tl-video-shape-${t.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:p,onPause:f,onTimeUpdate:S,onLoadedData:y,hidden:!g,children:u.jsx("source",{src:i})}):null:u.jsx(yj,{})})})}),"url"in t.props&&t.props.url&&u.jsx(xl,{url:t.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(t){return u.jsx("rect",{width:N(t.props.w),height:N(t.props.h)})}toSvg(t){return u.jsx("image",{href:fq(t.id),width:t.props.w,height:t.props.h})}}m(op,"type","video"),m(op,"props",LM),m(op,"migrations",$M);function fq(e){const n=e.split(":")[1],t=document.querySelector(`.tl-video-shape-${n}`);if(t){const r=document.createElement("canvas");return r.width=t.videoWidth,r.height=t.videoHeight,r.getContext("2d").drawImage(t,0,0),r.toDataURL("image/png")}else throw new Error("Video with not found when attempting serialization.")}const h0=[rp,Yh,Xh,Qh,np,tp,Zh,Vh,Jh,qh,ep,op];function gq(e){return[e.sideEffects.registerAfterChangeHandler("instance_page_state",(n,t)=>{if(n.croppingShapeId!==t.croppingShapeId){const r=e.isIn("select.crop");!n.croppingShapeId&&t.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):n.croppingShapeId&&!t.croppingShapeId&&r&&e.setCurrentTool("select.idle")}n.editingShapeId!==t.editingShapeId&&(!n.editingShapeId&&t.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):n.editingShapeId&&!t.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))})]}class kj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"scribbleId","id");m(this,"markId","");m(this,"excludedShapeIds",new Set);m(this,"onEnter",t=>{this.markId="erase scribble begin",this.editor.mark(this.markId),this.info=t;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:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,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:t,excludedShapeIds:r}=this,o=t.getErasingShapeIds(),s=t.getZoomLevel(),i=t.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=t;this.pushPointToScribble();const c=new Set(o),d=this.editor.options.hitTestMargin/s;for(const h of i){if(t.isShapeOfType(h,"group"))continue;const p=t.getShapeMask(h.id);if(p&&!tr(a,p))continue;const f=t.getShapeGeometry(h),S=t.getShapePageTransform(h);if(!f||!S)continue;const g=S.clone().invert(),x=g.applyToPoint(l),y=g.applyToPoint(a),{bounds:v}=f;v.minX-d>Math.max(x.x,y.x)||v.minY-d>Math.max(x.y,y.y)||v.maxX+d<Math.min(x.x,y.x)||v.maxY+d<Math.min(x.y,y.y)||f.hitTestLineSegment(x,y,d)&&c.add(t.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:t}=this;t.deleteShapes(t.getCurrentPageState().erasingShapeIds),t.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:t}=this;t.setErasingShapes([]),t.bailToMark(this.markId),this.parent.transition("idle",this.info)}}m(kj,"id","erasing");var Ky;let mq=(Ky=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ky,"id","idle"),Ky);var Wy;let yq=(Wy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{const t=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:o}}=this.editor,s=new Set,i=s.size;for(let a=r.length,l=a-1;l>=0;l--){const c=r[l];if(!(this.editor.isShapeOrAncestorLocked(c)||this.editor.isShapeOfType(c,"group"))&&this.editor.isPointInShape(c,o,{hitInside:!1,margin:this.editor.options.hitTestMargin/t})){const d=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(d,"frame")&&s.size>i)break;s.add(d.id)}}this.editor.setErasingShapes([...s])});m(this,"onLongPress",t=>{this.startErasing(t)});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startErasing(t)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}startErasing(t){this.parent.transition("erasing",t)}complete(){const t=this.editor.getErasingShapeIds();t.length&&(this.editor.mark("erase end"),this.editor.deleteShapes(t)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},m(Wy,"id","pointing"),Wy);class sp extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(sp,"id","eraser"),m(sp,"initial","idle"),m(sp,"children",()=>[mq,yq,kj]);class _j extends se{constructor(){super(...arguments);m(this,"initialCamera",new w);m(this,"onEnter",()=>{this.initialCamera=w.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:t,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=w.Sub(o,s).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(t.clone().add(i))}complete(){const{editor:t}=this,{pointerVelocity:r}=t.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r}),this.parent.transition("idle")}}m(_j,"id","dragging");var Gy;let Sq=(Gy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Gy,"id","idle"),Gy);var Vy;let vq=(Vy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation: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(Vy,"id","pointing"),Vy);class ip extends se{constructor(){super(...arguments);m(this,"onDoubleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{animation:{duration:220,easing:jt.easeOutQuint}})}});m(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:jt.easeOutQuint}})}});m(this,"onQuadrupleClick",t=>{if(t.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:o}}=this.editor;r===1?this.editor.zoomToFit({animation:{duration:400,easing:jt.easeOutQuint}}):this.editor.resetZoom(o,{animation:{duration:320,easing:jt.easeOutQuint}})}})}}m(ip,"id","hand"),m(ip,"initial","idle"),m(ip,"children",()=>[Sq,vq,_j]);var Yy;let xq=(Yy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},m(Yy,"id","idle"),Yy);class Tj extends se{constructor(){super(...arguments);m(this,"scribbleId","id");m(this,"onEnter",()=>{const t=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:1200,shrink:.05,taper:!0});this.scribbleId=t.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:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}m(Tj,"id","lasering");class ap extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(ap,"id","laser"),m(ap,"initial","idle"),m(ap,"children",()=>[xq,Tj]);class Mj 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",t=>{const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",t);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=t,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",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});m(this,"onPointerMove",()=>{this.hitTestShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",t=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",t)});m(this,"onKeyDown",t=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):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:t,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=t,c=new Set(a?this.initialSelectedShapeIds:[]),d=o?!l:l,h=Z.FromPoints([s,i]),{corners:p}=h;let f,S,g,x,y,v;const b=t.getCurrentPageShapes(),E=t.getCurrentPageId();e:for(let k=0,T=b.length;k<T;k++){if(g=b[k],r.has(g.id)||c.has(g.id)||(x=t.getShapePageBounds(g),!x))continue e;if(h.contains(x)){this.handleHit(g,i,E,c,p);continue e}if(d||t.isShapeOfType(g,"frame"))continue e;if(h.collides(x)){if(y=t.getShapePageTransform(g),!y)continue e;v=y.clone().invert().applyToPoints(p);const O=t.getShapeGeometry(g);t:for(let _=0;_<4;_++)if(f=v[_],S=v[(_+1)%4],O.hitTestLineSegment(f,S,0)){this.handleHit(g,i,E,c,p);break t}}}t.getInstanceState().isCoarsePointer;const I=t.getInstanceState().brush;(!I||!h.equals(I))&&t.updateInstanceState({brush:{...h.toJson()}});const C=t.getSelectedShapeIds();(C.length!==c.size||C.some(k=>!c.has(k)))&&t.setSelectedShapes(Array.from(c))}handleHit(t,r,o,s,i){if(t.parentId===o){s.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),l=this.editor.getShapeMask(a.id);l&&!I2(l,i)&&!tr(r,l)||s.add(a.id)}}m(Mj,"id","brushing");const bl={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 jj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t,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 t=this.editor.getSelectedShapes(),r=bl[this.info.handle];this.editor.setCursor({type:r,rotation:t.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(jj,"id","pointing_resize_handle");const fr=8;class p0 extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"snapshot",{});m(this,"onEnter",t=>{this.info=t,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=bl[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t||!this.editor.getShapeUtil("image"))return;const s=t.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),l=i.clone().sub(a).rot(-t.rotation),c=s.crop??this.getDefaultCrop(),d=rt(c),h=new w(t.x,t.y),p=new w(0,0),f=1/(c.bottomRight.x-c.topLeft.x)*s.w,S=1/(c.bottomRight.y-c.topLeft.y)*s.h;let g=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(S<fr)break;g=!0,d.topLeft.y=d.topLeft.y+l.y/S,S*(d.bottomRight.y-d.topLeft.y)<fr?(d.topLeft.y=d.bottomRight.y-fr/S,p.y=(d.topLeft.y-c.topLeft.y)*S):d.topLeft.y<=0?(d.topLeft.y=0,p.y=(d.topLeft.y-c.topLeft.y)*S):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(S<fr)break;g=!0,d.bottomRight.y=Math.min(1,d.bottomRight.y+l.y/S),S*(d.bottomRight.y-d.topLeft.y)<fr&&(d.bottomRight.y=d.topLeft.y+fr/S);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<fr)break;g=!0,d.topLeft.x=d.topLeft.x+l.x/f,f*(d.bottomRight.x-d.topLeft.x)<fr?(d.topLeft.x=d.bottomRight.x-fr/f,p.x=(d.topLeft.x-c.topLeft.x)*f):d.topLeft.x<=0?(d.topLeft.x=0,p.x=(d.topLeft.x-c.topLeft.x)*f):p.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(f<fr)break;g=!0,d.bottomRight.x=Math.min(1,d.bottomRight.x+l.x/f),f*(d.bottomRight.x-d.topLeft.x)<fr&&(d.bottomRight.x=d.topLeft.x+fr/f);break}}if(!g)return;h.add(p.rot(t.rotation));const x={id:t.id,type:t.type,x:h.x,y:h.y,props:{crop:d,w:(d.bottomRight.x-d.topLeft.x)*f,h:(d.bottomRight.y-d.topLeft.y)*S}};this.editor.updateShapes([x]),this.updateCursor()}complete(){this.updateShapes(),Ke(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=w.RotWith(s.getHandlePoint(this.info.handle),s.point,t),a=w.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}m(p0,"id","cropping");function f0(e,n=!1){const t=e.getZoomLevel(),{inputs:{currentPagePoint:r}}=e;return e.getShapeAtPoint(r,{hitInside:!1,hitLabels:n,margin:e.options.hitTestMargin/t,renderingOnly:!0})??e.getSelectedShapeAtPoint(r)}function Aj(e,n,t){if(!n)throw Error("Needs to translate a cropped shape!");const{crop:r}=n.props;if(!r)return;const o=e.inputs.shiftKey?Math.abs(t.x)<Math.abs(t.y)?"x":"y":null;o==="x"?t.x=0:o==="y"&&(t.y=0),t.rot(-n.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*n.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*n.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=rt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-t.x/s)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-t.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:n.id,type:n.type,props:{crop:c}}}var Xy;let wq=(Xy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const t=this.editor.getOnlySelectedShape();t&&this.editor.setCroppingShape(t.id)});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});m(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});m(this,"onPointerDown",t=>{var r;if(!this.editor.getIsMenuOpen()){if(t.ctrlKey){this.cancel(),this.editor.root.handleEvent(t);return}switch(t.target){case"canvas":{const o=f0(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...t,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(t);break}case"shape":{if(t.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",t);return}else(r=this.editor.getShapeUtil(t.shape))!=null&&r.canCrop(t.shape)?(this.editor.setCroppingShape(t.shape.id),this.editor.setSelectedShapes([t.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",t)):(this.cancel(),this.editor.root.handleEvent(t));break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...t,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...t,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}});m(this,"onDoubleClick",t=>{var i;if(this.editor.inputs.shiftKey||t.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);if(s){if(t.target==="selection"){(i=s.onDoubleClickEdge)==null||i.call(s,o);return}this.cancel(),this.editor.root.handleEvent(t)}});m(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});m(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});m(this,"onKeyUp",t=>{switch(t.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new w(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 w(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=Aj(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},m(Xy,"id","idle"),Xy);class Oj extends se{constructor(){super(...arguments);m(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",t)});m(this,"onPointerUp",t=>{this.editor.setCurrentTool("select.crop.idle",t)})}}m(Oj,"id","pointing_crop");class g0 extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=bl[this.info.handle];this.editor.setCursor({type:o,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation: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.editor.setCurrentTool("select.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.editor.setCurrentTool("select.idle"))}}m(g0,"id","pointing_crop_handle");class Dj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","translating crop");m(this,"snapshot",{});m(this,"onEnter",t=>{this.info=t,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onKeyDown",t=>{switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}});m(this,"onKeyUp",t=>{switch(t.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}})}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const t=this.snapshot.shape;if(!t)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=Aj(this.editor,t,s);i&&this.editor.updateShapes([i])}}m(Dj,"id","translating_crop");class lp extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"onEnter",()=>{this.didCancel=!1,this.markId=this.editor.history.mark()});m(this,"didCancel",!1);m(this,"onExit",()=>{this.didCancel?this.editor.bailToMark(this.markId):this.editor.history.squashToMark(this.markId)});m(this,"onCancel",()=>{this.didCancel=!0})}}m(lp,"id","crop"),m(lp,"initial","idle"),m(lp,"children",()=>[wq,Dj,Oj,g0,p0]);class Rj 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",t=>{const{shape:r,isCreating:o,handle:s}=t;if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.shapeId=r.id,this.markId=o?`creating:${r.id}`:"dragging handle",o||this.editor.mark(this.markId),this.initialHandle=rt(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 c=this.editor.getShapeHandles(r).find(d=>d.index===s.index);this.initialHandle=rt(c)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:o?"cross":"grabbing",rotation:0});const i=this.editor.getShapeHandles(r).sort(on),a=i.findIndex(l=>l.id===t.handle.id);this.initialAdjacentHandle=null;for(let l=a+1;l<i.length;l++){const c=i[l];if(c.type==="vertex"&&c.id!=="middle"&&c.id!==t.handle.id){this.initialAdjacentHandle=c;break}}if(!this.initialAdjacentHandle)for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="vertex"&&c.id!=="middle"&&c.id!==t.handle.id){this.initialAdjacentHandle=c;break}}if(this.editor.isShapeOfType(r,"arrow")){const l=Mn(this.editor,r)[t.handle.id];this.isPrecise=!1,l?(this.editor.setHintingShapes([l.toId]),this.isPrecise=l.props.isPrecise,this.isPrecise?this.isPreciseId=l.toId: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.setCursor({type:"default",rotation:0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),Ke(this.editor,[this.shapeId]);const{onInteractionEnd:t}=this.info;if(this.editor.getInstanceState().isToolLocked&&t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:t}=this.info;if(t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var k;const{editor:t,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:d,inputs:{currentPagePoint:h,shiftKey:p,ctrlKey:f,altKey:S,pointerVelocity:g}}=t,x=this.info.shape,y=t.getShape(r);if(!y)return;const v=t.getShapeUtil(y);let b=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const T=w.Angle(a,b),_=cf(T,24)-T;b=w.RotWith(b,a,_)}t.snaps.clearIndicators();let E={...s,x:b.x,y:b.y};if(s.canSnap&&(c?!f:f)){if(!t.getShapePageTransform(y.id))throw Error("Expected a page transform");const O=d.handles.snapHandle({currentShapeId:r,handle:E});O&&(O.nudge.rot(-t.getShapeParentTransform(y).rotation()),b.add(O.nudge),E={...s,x:b.x,y:b.y})}const I=(k=v.onHandleDrag)==null?void 0:k.call(v,y,{handle:E,isPrecise:this.isPrecise||S,initial:x}),C={id:y.id,type:y.type,...I};if(s.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const T=Mn(t,y)[s.id];T?l[0]!==T.toId&&(t.setHintingShapes([T.toId]),this.pointingId=T.toId,this.isPrecise=g.len()<.5||S,this.isPreciseId=this.isPrecise?T.toId:null,this.resetExactTimeout()):l.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}I&&t.updateShapes([C])}}m(Rj,"id","dragging_handle");function Lj(e){return e.isLabel?[e]:e instanceof Hr?e.children.filter(n=>n.isLabel):[]}class $j extends se{constructor(){super(...arguments);m(this,"hitShapeForPointerUp",null);m(this,"onEnter",()=>{const t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Bo(this.editor),this.editor.select(t)});m(this,"onExit",()=>{var s;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null),Bo.cancel();const r=this.editor.getShape(t),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r)});m(this,"onPointerMove",t=>{if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly||this.hitShapeForPointerUp.isLocked)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",t),this.hitShapeForPointerUp=null;return}switch(t.target){case"shape":case"canvas":{Bo(this.editor);return}}});m(this,"onPointerDown",t=>{switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=f0(this.editor,!0);if(r){this.onPointerDown({...t,shape:r,target:"shape"});return}break}case"shape":{const{shape:r}=t,o=this.editor.getEditingShape();if(!o)throw Error("Expected an editing shape!");const s=this.editor.getShapeUtil(r).getGeometry(r),i=Lj(s),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(o,"text")&&o.props.text.trim()==="";if(a&&!l){const c=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(c,0)&&a.hitTestPoint(c)){if(r.id===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",t);return}return}break}}this.parent.transition("idle",t),this.editor.root.handleEvent(t)});m(this,"onPointerUp",t=>{const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const o=this.editor.getShapeUtil(r);if(!r.isLocked){if(this.editor.getInstanceState().isReadonly&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",t);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),Bo(this.editor)}});m(this,"onComplete",t=>{this.parent.transition("idle",t)});m(this,"onCancel",t=>{this.parent.transition("idle",t)})}}m($j,"id","editing_shape");function bI(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function vf(e){const n=e.getSelectedShapeIds(),{shiftKey:t,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(s){const i=e.getOutermostSelectableShape(s);if(t&&!r)e.cancelDoubleClick(),n.includes(i.id)?(e.mark("deselecting shape"),e.deselect(i)):(e.mark("shift selecting shape"),e.setSelectedShapes([...n,i.id]));else{let a;i===s||i.id===e.getFocusedGroupId()||n.includes(i.id)?a=s:a=i,a&&!n.includes(a.id)&&(e.mark("selecting shape"),e.select(a.id))}}else{if(t)return;{n.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 bq=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var qy;let Pq=(qy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Bo(this.editor),this.editor.setCursor({type:"default",rotation:0})});m(this,"onExit",()=>{Bo.cancel()});m(this,"onPointerMove",()=>{Bo(this.editor)});m(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&bI(this.editor);if(t.ctrlKey&&!r){if(t.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(t.shape)){this.parent.transition("pointing_shape",t);return}this.parent.transition("brushing",t);return}switch(t.target){case"canvas":{const o=f0(this.editor);if(o&&!o.isLocked){this.onPointerDown({...t,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))&&PI(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{const{shape:o}=t;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",t);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",t);break}this.parent.transition("pointing_shape",t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",t):this.parent.transition("pointing_handle",t);break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",t);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("crop.pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",t)}}break}}});m(this,"onDoubleClick",t=>{var r,o,s,i;if(!(this.editor.inputs.shiftKey||t.phase!=="up"))switch(t.target){case"canvas":{const a=this.editor.getHoveredShape(),l=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),c=this.editor.getFocusedGroupId();if(l){if(this.editor.isShapeOfType(l,"group")){vf(this.editor);return}else{const d=this.editor.getShape(l.parentId);if(d&&this.editor.isShapeOfType(d,"group")&&!(c&&d.id===c)){vf(this.editor);return}}this.onDoubleClick({...t,shape:l,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(t);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const l=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(t.handle==="right"||t.handle==="left"||t.handle==="top"||t.handle==="bottom"){const c=(r=l.onDoubleClickEdge)==null?void 0:r.call(l,a);if(c){this.editor.mark("double click edge"),this.editor.updateShapes([c]),Ke(this.editor,[a.id]);return}}if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",t);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}break}case"shape":{const{shape:a}=t,l=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(l.onDoubleClick){const c=(o=l.onDoubleClick)==null?void 0:o.call(l,a);if(c){this.editor.updateShapes([c]);return}else if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((s=t.shape)==null?void 0:s.id),this.parent.transition("crop",t);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,t,!0):this.handleDoubleClickOnCanvas(t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:l}=t,c=this.editor.getShapeUtil(a),d=(i=c.onDoubleClickHandle)==null?void 0:i.call(c,a,l);d?this.editor.updateShapes([d]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}}});m(this,"onRightClick",t=>{switch(t.target){case"canvas":{const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...t,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))&&PI(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=t,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",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(wt.editOnType.get()&&!bq.includes(t.key)&&!t.altKey&&!t.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...t,target:"shape",shape:r},!0);return}}});m(this,"onKeyRepeat",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});m(this,"onKeyUp",t=>{switch(t.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,{...t,target:"shape",shape:o},!0);return}bI(this.editor)&&this.parent.transition("crop",t);break}}});m(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}shouldStartEditingShape(t=this.editor.getOnlySelectedShape()){return!t||this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||!this.canInteractWithShapeInReadOnly(t)?!1:this.editor.getShapeUtil(t).canEdit(t)}startEditingShape(t,r,o){this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||(this.editor.mark("editing shape"),mf(this.editor,t,o),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(t){if(!t)return!1;const r=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(t,"arrow")){const o=this.editor.getShapeGeometry(t).children[1];if(o&&tr(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(t){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=$e(),{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",t))}nudgeSelectedShapes(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new w(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 w(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*Eq:i:o?Cq:Iq,l=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(l,s.mul(a)),Ke(this.editor,l)}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},m(qy,"id","idle"),qy);const Cq=10,Iq=1,Eq=5;function PI(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?tr(n,t.corners.map(o=>w.RotWith(o,t.point,r))):t.containsPoint(n)}class Fj 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",t=>{const{shape:r}=t;this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,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=w.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.setCursor({type:"default",rotation:0})});m(this,"_labelDragOffset",new w(0,0));m(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;if(!t)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=co(this.editor,r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(w.Add(a,this._labelDragOffset));let c;if(o.isStraight){const d=w.Dist(o.start.point,o.end.point);c=1-w.Dist(o.end.point,l)/d}else{const{_center:d,measure:h,angleEnd:p,angleStart:f}=s.children[0];c=gv(h,f,p,d.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})});m(this,"onPointerUp",()=>{const t=this.editor.getShape(this.shapeId);t&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(t.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(Fj,"id","pointing_arrow_label");class Nj extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{const{inputs:t}=this.editor;t.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",t)});m(this,"onPointerUp",()=>{vf(this.editor),this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}m(Nj,"id","pointing_canvas");class zj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const o=Mn(this.editor,r)[t.handle.id];o&&this.editor.setHintingShapes([o.toId])}this.editor.setCursor({type:"grabbing",rotation:0})});m(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})});m(this,"onPointerUp",()=>{const{shape:t,handle:r}=this.info;if(this.editor.isShapeOfType(t,"note")){const{editor:o}=this,s=CI(o,t,r,!1);if(s){mf(o,s,!0);return}}this.parent.transition("idle",this.info)});m(this,"onPointerMove",()=>{const{editor:t}=this;t.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:t}=this;if(t.getInstanceState().isReadonly)return;const{shape:r,handle:o}=this.info;if(t.isShapeOfType(r,"note")){const s=CI(t,r,o,!0);if(s){const i=t.getPointInParentSpace(s,t.inputs.originPagePoint).sub(w.Rot(hg.clone().mul(r.props.scale),s.rotation));t.updateShape({...s,x:i.x,y:i.y}),t.setHoveredShape(s.id).select(s.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:t.getShape(s),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{mf(t,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}m(zj,"id","pointing_handle");function CI(e,n,t,r){const o=e.getShapePageTransform(n.id),s=o.point(),i=o.rotation(),l=rj(s,i,n.props.growY,0,n.props.scale)[t.index];if(l)return sj(e,n,l,i,r)}class Bj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation: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.setCursor({type:bl[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(Bj,"id","pointing_rotate_handle");class Uj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t});m(this,"onPointerUp",t=>{vf(this.editor),this.parent.transition("idle",t)});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});m(this,"onLongPress",t=>{this.startTranslating(t)});m(this,"onDoubleClick",t=>{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,{...t,target:"shape",shape:this.editor.getShape(o)});return}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",t)}cancel(){this.parent.transition("idle")}}m(Uj,"id","pointing_selection");class Hj extends se{constructor(){super(...arguments);m(this,"hitShape",{});m(this,"hitShapeForPointerUp",{});m(this,"isDoubleClick",!1);m(this,"didSelectOnEnter",!1);m(this,"onEnter",t=>{const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:l}}=this.editor;this.hitShape=t.shape,this.isDoubleClick=!1;const c=this.editor.getOutermostSelectableShape(t.shape),d=this.editor.findShapeAncestor(c,h=>r.includes(h.id));if(this.editor.getShapeUtil(t.shape).onClick||c.id===s||r.includes(c.id)||d||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=c;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(c.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,c.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([c.id]))});m(this,"onPointerUp",t=>{var d;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/s,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const p=(d=h.onClick)==null?void 0:d.call(h,c);if(p){this.editor.mark("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",t);return}}if(c.id===o){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",t);return}}if(!this.didSelectOnEnter){const h=this.editor.getOutermostSelectableShape(l,p=>!r.includes(p.id));if(r.includes(h.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),f=Lj(p),S=f.length===1?f[0]:void 0;if(S){const g=this.editor.getPointInShapeSpace(c,i);if(S.bounds.containsPoint(g,0)&&S.hitTestPoint(g)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(c.id);const x=this.editor.getShapeUtil(c);this.editor.getInstanceState().isReadonly&&!x.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:c.id}))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(c.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(c);else if(a){const p=this.editor.getShapeAncestors(h);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(f=>!p.find(S=>S.id===f)),h.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",t)});m(this,"onDoubleClick",()=>{this.isDoubleClick=!0});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});m(this,"onLongPress",t=>{this.startTranslating(t)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||(this.editor.focus(),this.parent.transition("translating",t))}cancel(){this.parent.transition("idle")}}m(Hj,"id","pointing_shape");class Kj 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",t=>{const{isCreating:r=!1,creationCursorOffset:o={x:0,y:0}}=t;this.info=t,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),r?(this.markId=`creating:${this.editor.getOnlySelectedShape().id}`,this.editor.setCursor({type:"cross",rotation:0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});m(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});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.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()});m(this,"_createSnapshot",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=w.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=w.Sub(o,i),l=new Map,c=[];t.forEach(h=>{const p=this.editor.getShape(h);if(p){if(p.type==="frame"&&c.push({id:h,children:me(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&t.length===1)return;this.editor.visitDescendants(p.id,f=>{const S=this.editor.getShape(f);if(S&&(l.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const d=![...l.values()].some(h=>!UM(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:d,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});m(this,"_createShapeSnapshot",t=>{const r=this.editor.getShapePageTransform(t),o=this.editor.getShapeUtil(t);return{shape:t,bounds:this.editor.getShapeGeometry(t).bounds,pageTransform:r,pageRotation:oe.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(t)}})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var t,r;if(Ke(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(t=this.info).onCreate)==null||r.call(t,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape: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:t}=this.snapshot,r=[];t.forEach(({shape:o})=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onResizeEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:d}=this.snapshot;let h=r||!d;if(s.size===1){const T=[...s.values()][0];this.editor.isShapeOfType(T.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),S=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:T}=this.editor.getDocumentSettings();f.snapToGrid(T)}const g=this.info.handle,x=II(g,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ve===0){const{nudge:T}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:w.Sub(f,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:II(g,c),isAspectRatioLocked:h,isResizingFromCenter:t});f.add(T)}const v=w.RotWith(t?i.center:i.getHandlePoint(x),i.point,c),b=w.Sub(f,v).rot(-c),E=w.Sub(S,v).rot(-c),I=w.DivV(b,E);Number.isFinite(I.x)||(I.x=1),Number.isFinite(I.y)||(I.y=1);const C=g==="top"||g==="bottom",k=g==="left"||g==="right";h?k?I.y=Math.abs(I.x):C?I.x=Math.abs(I.y):Math.abs(I.x)>Math.abs(I.y)?I.y=Math.abs(I.x)*(I.y<0?-1:1):I.x=Math.abs(I.y)*(I.x<0?-1:1):(C&&(I.x=1),k&&(I.y=1)),this.info.isCreating||this.updateCursor({dragHandle:g,isFlippedX:I.x<0,isFlippedY:I.y<0,rotation:c});for(const T of s.keys()){const O=s.get(T);this.editor.resizeShape(T,I,{initialShape:O.shape,initialBounds:O.bounds,initialPageTransform:O.pageTransform,dragHandle:g,mode:l.length===1&&T===l[0]?"resize_bounds":"scale_shape",scaleOrigin:v,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:T,children:O}of o){if(!O.length)continue;const _=s.get(T).shape,j=this.editor.getShape(T);if(!(_&&j))continue;const L=j.x-_.x,A=j.y-_.y,R=new w(L,A).rot(-_.rotation);if(R.x!==0||R.y!==0)for(const F of O)this.editor.updateShape({id:F.id,type:F.type,x:F.x-R.x,y:F.y-R.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:T}of o)if(T.length)for(const O of T)this.editor.updateShape({id:O.id,type:O.type,x:O.x,y:O.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(t){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(Kj,"id","resizing");const py=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function II(e,n){n=n%Re;const t=Math.round(n/(_e/4)),r=py.indexOf(e);return py[(r+t)%py.length]}const EI=Math.PI/180;class Wj extends se{constructor(){super(...arguments);m(this,"snapshot",{});m(this,"info",{});m(this,"markId","");m(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=_2({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Oh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:bl[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 t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Oh({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:bl[this.info.handle],rotation:t+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",()=>{Oh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ke(this.editor,this.snapshot.shapeSnapshots.map(t=>t.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)})}_getRotationFromPointerPosition({snapToNearestDegree:t}){const r=this.editor.getSelectionRotation(),o=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:s,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:l}=this.snapshot;if(!o)return l;const d=o.center.clone().rotWith(o.point,r).angle(i)-a;let h=l+d;if(s)h=cf(h,24);else if(t&&(h=Math.round(h/EI)*EI,this.editor.getInstanceState().isCoarsePointer)){const p=cf(h,4),f=Mh(h,p);Math.abs(f)<q9(5)&&(h=p)}return h-l}}m(Wj,"id","rotating");class Gj 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 t=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=t.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:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)})}updateScribbleSelection(t){const{editor:r}=this,o=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:d}=this;t&&this.pushPointToScribble();const h=o;let p,f,S,g;const x=0;for(let b=0,E=h.length;b<E;b++){if(p=h[b],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(f=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&f.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const I=r.getShapePageTransform(p);if(!f||!I)continue;const C=I.clone().invert();S=C.applyToPoint(a),g=C.applyToPoint(l);const{bounds:k}=f;if(!(k.minX-x>Math.max(S.x,g.x)||k.minY-x>Math.max(S.y,g.y)||k.maxX+x<Math.min(S.x,g.x)||k.maxY+x<Math.min(S.y,g.y))&&f.hitTestLineSegment(S,g,x)){const T=this.editor.getOutermostSelectableShape(p),O=this.editor.getShapeMask(T.id);if(O&&Gw(a,l,O)!==null&&!tr(l,O))continue;c.add(T.id)}}const y=r.getSelectedShapeIds(),v=new Set(s?[...c,...d]:[...c]);(y.length!==v.size||y.some(b=>!v.has(b)))&&this.editor.setSelectedShapes(Array.from(v))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}m(Gj,"id","scribble_brushing");const kq=20,_q=100;class Tq{constructor(n){m(this,"prevDroppingShapeId",null);m(this,"droppingNodeTimer",null);m(this,"first",!0);m(this,"dispose",()=>{this.clear()});this.editor=n,n.disposables.add(this.dispose)}updateDroppingNode(n,t){var r;this.first&&(this.editor.setHintingShapes(n.map(o=>this.editor.findShapeAncestor(o,s=>s.type!=="group")).filter(o=>o)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,n))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(n,kq,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(n,_q,t))}setDragTimer(n,t,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,n,r)}),this.droppingNodeTimer=null},t)}handleDrag(n,t,r){var l,c,d,h,p;t=me(t.map(f=>this.editor.getShape(f.id)));const o=((l=this.editor.getDroppingOverShape(n,t))==null?void 0:l.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(t);return}const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);i&&((d=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||d.call(c,i,t)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,a,t)),this.hintParents(t),r==null||r(),this.prevDroppingShapeId=o}hintParents(n){const t=new Map;for(const o of n){const s=this.editor.findShapeAncestor(o,i=>i.type!=="group");s&&(t.has(s.id)||t.set(s.id,[]),t.get(s.id).push(o.id))}const r=[];for(const[o,s]of t){const i=this.editor.getShape(o);i&&ej(this.editor,i).length<s.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(n){var r,o;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,n),t){const s=this.editor.getShape(t);if(!s)return;(o=(r=this.editor.getShapeUtil(s)).onDropShapesOver)==null||o.call(r,s,n)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class Vj 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 Tq(this.editor));m(this,"onEnter",t=>{var s;const{isCreating:r=!1,onCreate:o=()=>{}}=t;if(!((s=this.editor.getSelectedShapeIds())!=null&&s.length)){this.parent.transition("idle");return}if(this.info=t,this.parent.setCurrentToolIdMask(t.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=t,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=kI(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",({elapsed:t})=>{const{editor:r}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),r.edgeScrollManager.updateEdgeScrolling(t)});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:t,snapshot:{shapeSnapshots:r}}=this;r.forEach(o=>{const s=t.getShape(o.shape.id);if(!s)return null;const i=In(s.parentId)?null:oe.Inverse(t.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=kI(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 t;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),Ke(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?(t=this.onCreate)==null||t.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:t}=this.snapshot,r=[];t.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:t}=this.snapshot;if(this.isCloning&&t.length>0){const o=w.Average(t.map(i=>this.editor.getShapePageTransform(i.id).point())),s=w.Sub(o,this.selectionSnapshot.averagePagePoint);w.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:t.map(i=>i.id),offset:{x:s.x,y:s.y}}})}const r=[];t.forEach(o=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslateEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:t}=this;this.dragAndDropManager.updateDroppingNode(t.movingShapes,this.updateParentTransforms),Mq({editor:this.editor,snapshot:t});const{movingShapes:r}=t,o=[];r.forEach(s=>{var c;const i=this.editor.getShape(s.id),a=this.editor.getShapeUtil(s),l=(c=a.onTranslate)==null?void 0:c.call(a,s,i);l&&o.push(l)}),o.length>0&&this.editor.updateShapes(o)}}m(Vj,"id","translating");function kI(e){var h;const n=[],t=[],r=e.getSelectedShapeIds(),o=me(r.map(p=>{const f=e.getShape(p);if(!f)return null;n.push(f);const S=e.getShapePageTransform(p),g=S.point(),x=S.rotation();t.push(g);const y=Qo.isId(f.parentId)?null:oe.Inverse(e.getShapePageTransform(f.parentId));return{shape:f,pagePoint:g,pageRotation:x,parentTransform:y}})),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,S)=>({id:"selection:"+S,x:f.x,y:f.y})))}let a,l;const{originPagePoint:c}=e.inputs,d=o.filter(p=>e.isShapeOfType(p.shape,"note")&&e.isPointInShape(p.shape,c));if(d.length!==0)if(d.length===1)l=d[0];else{const p=e.getCurrentPageShapesSorted();l=(h=d.map(f=>({snapshot:f,index:p.findIndex(S=>S.id===f.shape.id)})).sort((f,S)=>S.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=oj(e,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:w.Average(t),movingShapes:n,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function Mq({editor:e,snapshot:n}){const{inputs:t}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=n,c=e.getInstanceState().isGridMode,d=e.getDocumentSettings().gridSize,h=w.Sub(t.currentPagePoint,t.originPagePoint),p=e.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;if(p==="x"?h.x=0:p==="y"&&(h.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:x}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});h.add(x)}else if(r&&o){const{scale:x}=r.shape.props,y=r.pagePoint.clone().add(h).add(hg.clone().mul(x).rot(r.pageRotation));let v=nj/e.getZoomLevel(),b=new w(0,0);for(const E of o){const I=w.Sub(y,E),C=I.len();C<v&&(v=C,b=I)}h.sub(b)}const S=w.Add(l,h);c&&!t.ctrlKey&&S.snapToGrid(d);const g=w.Sub(S,l);e.updateShapes(me(a.map(({shape:x,pagePoint:y,parentTransform:v})=>{const b=w.Add(y,g),E=v?oe.applyToPoint(v,b):b;return{id:x.id,type:x.type,x:E.x,y:E.y}})))}class cp extends se{constructor(){super(...arguments);m(this,"reactor");m(this,"cleanUpDuplicateProps",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);t.length===o.size&&t.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})});m(this,"onEnter",()=>{this.reactor=aa("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(t){typeof process<"u",console.error(t)}})});m(this,"onExit",()=>{var t;(t=this.reactor)==null||t.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}m(cp,"id","select"),m(cp,"initial","idle"),m(cp,"children",()=>[lp,p0,Pq,Nj,Hj,Vj,Mj,Gj,g0,Uj,jj,$j,Kj,Wj,Bj,Fj,zj,Rj]);class Yj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t});m(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}m(Yj,"id","idle");class Xj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t});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:t}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(t,{animation:{duration:220}}):this.editor.zoomIn(t,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}m(Xj,"id","pointing");class qj extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"zoomBrush",new Z);m(this,"onEnter",t=>{this.info=t,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:t,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.FromPoints([t,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:t}=this,r=8/this.editor.getZoomLevel();if(t.width<r&&t.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{animation:{duration:220}}):this.editor.zoomIn(o,{animation:{duration:220}})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(t,{targetZoom:o,animation:{duration:220}})}this.parent.transition("idle",this.info)}}m(qj,"id","zoom_brushing");class up extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onKeyDown",()=>{this.updateCursor()});m(this,"onKeyUp",t=>{this.updateCursor(),t.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.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}m(up,"id","zoom"),m(up,"initial","idle"),m(up,"children",()=>[Yj,qj,Xj]);const jq=[sp,ip,ap,up,cp];function re(e,n,{checkForDefaultPrevented:t=!0}={}){return function(o){if(e==null||e(o),t===!1||!o.defaultPrevented)return n==null?void 0:n(o)}}function Aq(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function mg(...e){return n=>e.forEach(t=>Aq(t,n))}function Ye(...e){return P.useCallback(mg(...e),e)}function Oq(e,n){const t=P.createContext(n);function r(s){const{children:i,...a}=s,l=P.useMemo(()=>a,Object.values(a));return u.jsx(t.Provider,{value:l,children:i})}function o(s){const i=P.useContext(t);if(i)return i;if(n!==void 0)return n;throw new Error(`\`${s}\` must be used within \`${e}\``)}return r.displayName=e+"Provider",[r,o]}function Eo(e,n=[]){let t=[];function r(s,i){const a=P.createContext(i),l=t.length;t=[...t,i];function c(h){const{scope:p,children:f,...S}=h,g=(p==null?void 0:p[e][l])||a,x=P.useMemo(()=>S,Object.values(S));return u.jsx(g.Provider,{value:x,children:f})}function d(h,p){const f=(p==null?void 0:p[e][l])||a,S=P.useContext(f);if(S)return S;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,d]}const o=()=>{const s=t.map(i=>P.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return P.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Dq(o,...n)]}function Dq(...e){const n=e[0];if(e.length===1)return n;const t=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(s)[`__scope${c}`];return{...a,...h}},{});return P.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return t.scopeName=n.scopeName,t}var Xs=globalThis!=null&&globalThis.document?P.useLayoutEffect:()=>{},Rq=p$.useId||(()=>{}),Lq=0;function Go(e){const[n,t]=P.useState(Rq());return Xs(()=>{e||t(r=>r??String(Lq++))},[e]),e||(n?`radix-${n}`:"")}function Vt(e){const n=P.useRef(e);return P.useEffect(()=>{n.current=e}),P.useMemo(()=>(...t)=>{var r;return(r=n.current)==null?void 0:r.call(n,...t)},[])}function li({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=$q({defaultProp:n,onChange:t}),s=e!==void 0,i=s?e:r,a=Vt(t),l=P.useCallback(c=>{if(s){const h=typeof c=="function"?c(e):c;h!==e&&a(h)}else o(c)},[s,e,o,a]);return[i,l]}function $q({defaultProp:e,onChange:n}){const t=P.useState(e),[r]=t,o=P.useRef(r),s=Vt(n);return P.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),t}var Xi=P.forwardRef((e,n)=>{const{children:t,...r}=e,o=P.Children.toArray(t),s=o.find(Nq);if(s){const i=s.props.children,a=o.map(l=>l===s?P.Children.count(i)>1?P.Children.only(null):P.isValidElement(i)?i.props.children:null:l);return u.jsx(Dv,{...r,ref:n,children:P.isValidElement(i)?P.cloneElement(i,void 0,a):null})}return u.jsx(Dv,{...r,ref:n,children:t})});Xi.displayName="Slot";var Dv=P.forwardRef((e,n)=>{const{children:t,...r}=e;if(P.isValidElement(t)){const o=Bq(t);return P.cloneElement(t,{...zq(r,t.props),ref:n?mg(n,o):o})}return P.Children.count(t)>1?P.Children.only(null):null});Dv.displayName="SlotClone";var Fq=({children:e})=>u.jsx(u.Fragment,{children:e});function Nq(e){return P.isValidElement(e)&&e.type===Fq}function zq(e,n){const t={...n};for(const r in n){const o=e[r],s=n[r];/^on[A-Z]/.test(r)?o&&s?t[r]=(...a)=>{s(...a),o(...a)}:o&&(t[r]=o):r==="style"?t[r]={...o,...s}:r==="className"&&(t[r]=[o,s].filter(Boolean).join(" "))}return{...e,...t}}function Bq(e){var r,o;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,t=n&&"isReactWarning"in n&&n.isReactWarning;return t?e.ref:(n=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,t=n&&"isReactWarning"in n&&n.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}var Uq=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ce=Uq.reduce((e,n)=>{const t=P.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?Xi:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),u.jsx(a,{...i,ref:o})});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function m0(e,n){e&&ra.flushSync(()=>e.dispatchEvent(n))}function Hq(e,n=globalThis==null?void 0:globalThis.document){const t=Vt(e);P.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r,{capture:!0}),()=>n.removeEventListener("keydown",r,{capture:!0})},[t,n])}var Kq="DismissableLayer",Rv="dismissableLayer.update",Wq="dismissableLayer.pointerDownOutside",Gq="dismissableLayer.focusOutside",_I,Zj=P.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Gu=P.forwardRef((e,n)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=P.useContext(Zj),[d,h]=P.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=P.useState({}),S=Ye(n,k=>h(k)),g=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),v=d?g.indexOf(d):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,E=v>=y,I=Yq(k=>{const T=k.target,O=[...c.branches].some(_=>_.contains(T));!E||O||(o==null||o(k),i==null||i(k),k.defaultPrevented||a==null||a())},p),C=Xq(k=>{const T=k.target;[...c.branches].some(_=>_.contains(T))||(s==null||s(k),i==null||i(k),k.defaultPrevented||a==null||a())},p);return Hq(k=>{v===c.layers.size-1&&(r==null||r(k),!k.defaultPrevented&&a&&(k.preventDefault(),a()))},p),P.useEffect(()=>{if(d)return t&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(_I=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),TI(),()=>{t&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=_I)}},[d,p,t,c]),P.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),TI())},[d,c]),P.useEffect(()=>{const k=()=>f({});return document.addEventListener(Rv,k),()=>document.removeEventListener(Rv,k)},[]),u.jsx(Ce.div,{...l,ref:S,style:{pointerEvents:b?E?"auto":"none":void 0,...e.style},onFocusCapture:re(e.onFocusCapture,C.onFocusCapture),onBlurCapture:re(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:re(e.onPointerDownCapture,I.onPointerDownCapture)})});Gu.displayName=Kq;var Vq="DismissableLayerBranch",Qj=P.forwardRef((e,n)=>{const t=P.useContext(Zj),r=P.useRef(null),o=Ye(n,r);return P.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),u.jsx(Ce.div,{...e,ref:o})});Qj.displayName=Vq;function Yq(e,n=globalThis==null?void 0:globalThis.document){const t=Vt(e),r=P.useRef(!1),o=P.useRef(()=>{});return P.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){Jj(Wq,t,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=l,n.addEventListener("click",o.current,{once:!0})):l()}else n.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{n.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),n.removeEventListener("pointerdown",s),n.removeEventListener("click",o.current)}},[n,t]),{onPointerDownCapture:()=>r.current=!0}}function Xq(e,n=globalThis==null?void 0:globalThis.document){const t=Vt(e),r=P.useRef(!1);return P.useEffect(()=>{const o=s=>{s.target&&!r.current&&Jj(Gq,t,{originalEvent:s},{discrete:!1})};return n.addEventListener("focusin",o),()=>n.removeEventListener("focusin",o)},[n,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function TI(){const e=new CustomEvent(Rv);document.dispatchEvent(e)}function Jj(e,n,t,{discrete:r}){const o=t.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?m0(o,s):o.dispatchEvent(s)}var qq=Gu,Zq=Qj,fy="focusScope.autoFocusOnMount",gy="focusScope.autoFocusOnUnmount",MI={bubbles:!1,cancelable:!0},Qq="FocusScope",yg=P.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=P.useState(null),c=Vt(o),d=Vt(s),h=P.useRef(null),p=Ye(n,g=>l(g)),f=P.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;P.useEffect(()=>{if(r){let g=function(b){if(f.paused||!a)return;const E=b.target;a.contains(E)?h.current=E:xs(h.current,{select:!0})},x=function(b){if(f.paused||!a)return;const E=b.relatedTarget;E!==null&&(a.contains(E)||xs(h.current,{select:!0}))},y=function(b){if(document.activeElement===document.body)for(const I of b)I.removedNodes.length>0&&xs(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const v=new MutationObserver(y);return a&&v.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),v.disconnect()}}},[r,a,f.paused]),P.useEffect(()=>{if(a){AI.add(f);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(fy,MI);a.addEventListener(fy,c),a.dispatchEvent(y),y.defaultPrevented||(Jq(oZ(eA(a)),{select:!0}),document.activeElement===g&&xs(a))}return()=>{a.removeEventListener(fy,c),setTimeout(()=>{const y=new CustomEvent(gy,MI);a.addEventListener(gy,d),a.dispatchEvent(y),y.defaultPrevented||xs(g??document.body,{select:!0}),a.removeEventListener(gy,d),AI.remove(f)},0)}}},[a,c,d,f]);const S=P.useCallback(g=>{if(!t&&!r||f.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const v=g.currentTarget,[b,E]=eZ(v);b&&E?!g.shiftKey&&y===E?(g.preventDefault(),t&&xs(b,{select:!0})):g.shiftKey&&y===b&&(g.preventDefault(),t&&xs(E,{select:!0})):y===v&&g.preventDefault()}},[t,r,f.paused]);return u.jsx(Ce.div,{tabIndex:-1,...i,ref:p,onKeyDown:S})});yg.displayName=Qq;function Jq(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(xs(r,{select:n}),document.activeElement!==t)return}function eZ(e){const n=eA(e),t=jI(n,e),r=jI(n.reverse(),e);return[t,r]}function eA(e){const n=[],t=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(;t.nextNode();)n.push(t.currentNode);return n}function jI(e,n){for(const t of e)if(!tZ(t,{upTo:n}))return t}function tZ(e,{upTo:n}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(n!==void 0&&e===n)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function nZ(e){return e instanceof HTMLInputElement&&"select"in e}function xs(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&nZ(e)&&n&&e.select()}}var AI=rZ();function rZ(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=OI(e,n),e.unshift(n)},remove(n){var t;e=OI(e,n),(t=e[0])==null||t.resume()}}}function OI(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function oZ(e){return e.filter(n=>n.tagName!=="A")}var sZ="Portal",Vu=P.forwardRef((e,n)=>{var a;const{container:t,...r}=e,[o,s]=P.useState(!1);Xs(()=>s(!0),[]);const i=t||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?CN.createPortal(u.jsx(Ce.div,{...r,ref:n}),i):null});Vu.displayName=sZ;function iZ(e,n){return P.useReducer((t,r)=>n[t][r]??t,e)}var Yr=e=>{const{present:n,children:t}=e,r=aZ(n),o=typeof t=="function"?t({present:r.isPresent}):P.Children.only(t),s=Ye(r.ref,lZ(o));return typeof t=="function"||r.isPresent?P.cloneElement(o,{ref:s}):null};Yr.displayName="Presence";function aZ(e){const[n,t]=P.useState(),r=P.useRef({}),o=P.useRef(e),s=P.useRef("none"),i=e?"mounted":"unmounted",[a,l]=iZ(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return P.useEffect(()=>{const c=Jd(r.current);s.current=a==="mounted"?c:"none"},[a]),Xs(()=>{const c=r.current,d=o.current;if(d!==e){const p=s.current,f=Jd(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(d&&p!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Xs(()=>{if(n){const c=h=>{const f=Jd(r.current).includes(h.animationName);h.target===n&&f&&ra.flushSync(()=>l("ANIMATION_END"))},d=h=>{h.target===n&&(s.current=Jd(r.current))};return n.addEventListener("animationstart",d),n.addEventListener("animationcancel",c),n.addEventListener("animationend",c),()=>{n.removeEventListener("animationstart",d),n.removeEventListener("animationcancel",c),n.removeEventListener("animationend",c)}}else l("ANIMATION_END")},[n,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:P.useCallback(c=>{c&&(r.current=getComputedStyle(c)),t(c)},[])}}function Jd(e){return(e==null?void 0:e.animationName)||"none"}function lZ(e){var r,o;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,t=n&&"isReactWarning"in n&&n.isReactWarning;return t?e.ref:(n=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,t=n&&"isReactWarning"in n&&n.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}var my=0;function y0(){P.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??DI()),document.body.insertAdjacentElement("beforeend",e[1]??DI()),my++,()=>{my===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(n=>n.remove()),my--}},[])}function DI(){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 io=function(){return io=Object.assign||function(n){for(var t,r=1,o=arguments.length;r<o;r++){t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=t[s])}return n},io.apply(this,arguments)};function tA(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]]);return t}function cZ(e,n,t){if(t||arguments.length===2)for(var r=0,o=n.length,s;r<o;r++)(s||!(r in n))&&(s||(s=Array.prototype.slice.call(n,0,r)),s[r]=n[r]);return e.concat(s||Array.prototype.slice.call(n))}var dp="right-scroll-bar-position",hp="width-before-scroll-bar",uZ="with-scroll-bars-hidden",dZ="--removed-body-scroll-bar-size";function yy(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function hZ(e,n){var t=P.useState(function(){return{value:e,callback:n,facade:{get current(){return t.value},set current(r){var o=t.value;o!==r&&(t.value=r,t.callback(r,o))}}}})[0];return t.callback=n,t.facade}var pZ=typeof window<"u"?P.useLayoutEffect:P.useEffect,RI=new WeakMap;function fZ(e,n){var t=hZ(null,function(r){return e.forEach(function(o){return yy(o,r)})});return pZ(function(){var r=RI.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||yy(a,null)}),s.forEach(function(a){o.has(a)||yy(a,i)})}RI.set(t,e)},[e]),t}function gZ(e){return e}function mZ(e,n){n===void 0&&(n=gZ);var t=[],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 t.length?t[t.length-1]:e},useMedium:function(s){var i=n(s,r);return t.push(i),function(){t=t.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;t.length;){var i=t;t=[],i.forEach(s)}t={push:function(a){return s(a)},filter:function(){return t}}},assignMedium:function(s){r=!0;var i=[];if(t.length){var a=t;t=[],a.forEach(s),i=t}var l=function(){var d=i;i=[],d.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),t={push:function(d){i.push(d),c()},filter:function(d){return i=i.filter(d),t}}}};return o}function yZ(e){e===void 0&&(e={});var n=mZ(null);return n.options=io({async:!0,ssr:!1},e),n}var nA=function(e){var n=e.sideCar,t=tA(e,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return P.createElement(r,io({},t))};nA.isSideCarExport=!0;function SZ(e,n){return e.useMedium(n),nA}var rA=yZ(),Sy=function(){},Sg=P.forwardRef(function(e,n){var t=P.useRef(null),r=P.useState({onScrollCapture:Sy,onWheelCapture:Sy,onTouchMoveCapture:Sy}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,d=e.enabled,h=e.shards,p=e.sideCar,f=e.noIsolation,S=e.inert,g=e.allowPinchZoom,x=e.as,y=x===void 0?"div":x,v=e.gapMode,b=tA(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=p,I=fZ([t,n]),C=io(io({},b),o);return P.createElement(P.Fragment,null,d&&P.createElement(E,{sideCar:rA,removeScrollBar:c,shards:h,noIsolation:f,inert:S,setCallbacks:s,allowPinchZoom:!!g,lockRef:t,gapMode:v}),i?P.cloneElement(P.Children.only(a),io(io({},C),{ref:I})):P.createElement(y,io({},C,{className:l,ref:I}),a))});Sg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Sg.classNames={fullWidth:hp,zeroRight:dp};var vZ=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function xZ(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=vZ();return n&&e.setAttribute("nonce",n),e}function wZ(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function bZ(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var PZ=function(){var e=0,n=null;return{add:function(t){e==0&&(n=xZ())&&(wZ(n,t),bZ(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},CZ=function(){var e=PZ();return function(n,t){P.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},oA=function(){var e=CZ(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},IZ={left:0,top:0,right:0,gap:0},vy=function(e){return parseInt(e||"",10)||0},EZ=function(e){var n=window.getComputedStyle(document.body),t=n[e==="padding"?"paddingLeft":"marginLeft"],r=n[e==="padding"?"paddingTop":"marginTop"],o=n[e==="padding"?"paddingRight":"marginRight"];return[vy(t),vy(r),vy(o)]},kZ=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return IZ;var n=EZ(e),t=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-t+n[2]-n[0])}},_Z=oA(),ol="data-scroll-locked",TZ=function(e,n,t,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return t===void 0&&(t="margin"),`
|
|
.`.concat(uZ,` {
|
|
overflow: hidden `).concat(r,`;
|
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
}
|
|
body[`).concat(ol,`] {
|
|
overflow: hidden `).concat(r,`;
|
|
overscroll-behavior: contain;
|
|
`).concat([n&&"position: relative ".concat(r,";"),t==="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,`;
|
|
`),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
}
|
|
|
|
.`).concat(dp,` {
|
|
right: `).concat(a,"px ").concat(r,`;
|
|
}
|
|
|
|
.`).concat(hp,` {
|
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
}
|
|
|
|
.`).concat(dp," .").concat(dp,` {
|
|
right: 0 `).concat(r,`;
|
|
}
|
|
|
|
.`).concat(hp," .").concat(hp,` {
|
|
margin-right: 0 `).concat(r,`;
|
|
}
|
|
|
|
body[`).concat(ol,`] {
|
|
`).concat(dZ,": ").concat(a,`px;
|
|
}
|
|
`)},LI=function(){var e=parseInt(document.body.getAttribute(ol)||"0",10);return isFinite(e)?e:0},MZ=function(){P.useEffect(function(){return document.body.setAttribute(ol,(LI()+1).toString()),function(){var e=LI()-1;e<=0?document.body.removeAttribute(ol):document.body.setAttribute(ol,e.toString())}},[])},jZ=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;MZ();var s=P.useMemo(function(){return kZ(o)},[o]);return P.createElement(_Z,{styles:TZ(s,!n,o,t?"":"!important")})},Lv=!1;if(typeof window<"u")try{var eh=Object.defineProperty({},"passive",{get:function(){return Lv=!0,!0}});window.addEventListener("test",eh,eh),window.removeEventListener("test",eh,eh)}catch{Lv=!1}var va=Lv?{passive:!1}:!1,AZ=function(e){return e.tagName==="TEXTAREA"},sA=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!AZ(e)&&t[n]==="visible")},OZ=function(e){return sA(e,"overflowY")},DZ=function(e){return sA(e,"overflowX")},$I=function(e,n){var t=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=iA(e,r);if(o){var s=aA(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},RZ=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},LZ=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},iA=function(e,n){return e==="v"?OZ(n):DZ(n)},aA=function(e,n){return e==="v"?RZ(n):LZ(n)},$Z=function(e,n){return e==="h"&&n==="rtl"?-1:1},FZ=function(e,n,t,r,o){var s=$Z(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,l=n.contains(a),c=!1,d=i>0,h=0,p=0;do{var f=aA(e,a),S=f[0],g=f[1],x=f[2],y=g-x-s*S;(S||y)&&iA(e,a)&&(h+=y,p+=S),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(n.contains(a)||n===a));return(d&&(Math.abs(h)<1||!o)||!d&&(Math.abs(p)<1||!o))&&(c=!0),c},th=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},FI=function(e){return[e.deltaX,e.deltaY]},NI=function(e){return e&&"current"in e?e.current:e},NZ=function(e,n){return e[0]===n[0]&&e[1]===n[1]},zZ=function(e){return`
|
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
`)},BZ=0,xa=[];function UZ(e){var n=P.useRef([]),t=P.useRef([0,0]),r=P.useRef(),o=P.useState(BZ++)[0],s=P.useState(oA)[0],i=P.useRef(e);P.useEffect(function(){i.current=e},[e]),P.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=cZ([e.lockRef.current],(e.shards||[]).map(NI),!0).filter(Boolean);return g.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=P.useCallback(function(g,x){if("touches"in g&&g.touches.length===2)return!i.current.allowPinchZoom;var y=th(g),v=t.current,b="deltaX"in g?g.deltaX:v[0]-y[0],E="deltaY"in g?g.deltaY:v[1]-y[1],I,C=g.target,k=Math.abs(b)>Math.abs(E)?"h":"v";if("touches"in g&&k==="h"&&C.type==="range")return!1;var T=$I(k,C);if(!T)return!0;if(T?I=k:(I=k==="v"?"h":"v",T=$I(k,C)),!T)return!1;if(!r.current&&"changedTouches"in g&&(b||E)&&(r.current=I),!I)return!0;var O=r.current||I;return FZ(O,x,g,O==="h"?b:E,!0)},[]),l=P.useCallback(function(g){var x=g;if(!(!xa.length||xa[xa.length-1]!==s)){var y="deltaY"in x?FI(x):th(x),v=n.current.filter(function(I){return I.name===x.type&&(I.target===x.target||x.target===I.shadowParent)&&NZ(I.delta,y)})[0];if(v&&v.should){x.cancelable&&x.preventDefault();return}if(!v){var b=(i.current.shards||[]).map(NI).filter(Boolean).filter(function(I){return I.contains(x.target)}),E=b.length>0?a(x,b[0]):!i.current.noIsolation;E&&x.cancelable&&x.preventDefault()}}},[]),c=P.useCallback(function(g,x,y,v){var b={name:g,delta:x,target:y,should:v,shadowParent:HZ(y)};n.current.push(b),setTimeout(function(){n.current=n.current.filter(function(E){return E!==b})},1)},[]),d=P.useCallback(function(g){t.current=th(g),r.current=void 0},[]),h=P.useCallback(function(g){c(g.type,FI(g),g.target,a(g,e.lockRef.current))},[]),p=P.useCallback(function(g){c(g.type,th(g),g.target,a(g,e.lockRef.current))},[]);P.useEffect(function(){return xa.push(s),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,va),document.addEventListener("touchmove",l,va),document.addEventListener("touchstart",d,va),function(){xa=xa.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,va),document.removeEventListener("touchmove",l,va),document.removeEventListener("touchstart",d,va)}},[]);var f=e.removeScrollBar,S=e.inert;return P.createElement(P.Fragment,null,S?P.createElement(s,{styles:zZ(o)}):null,f?P.createElement(jZ,{gapMode:e.gapMode}):null)}function HZ(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const KZ=SZ(rA,UZ);var vg=P.forwardRef(function(e,n){return P.createElement(Sg,io({},e,{ref:n,sideCar:KZ}))});vg.classNames=Sg.classNames;var WZ=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},wa=new WeakMap,nh=new WeakMap,rh={},xy=0,lA=function(e){return e&&(e.host||lA(e.parentNode))},GZ=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=lA(t);return r&&e.contains(r)?r:(console.error("aria-hidden",t,"in not contained inside",e,". Doing nothing"),null)}).filter(function(t){return!!t})},VZ=function(e,n,t,r){var o=GZ(n,Array.isArray(e)?e:[e]);rh[t]||(rh[t]=new WeakMap);var s=rh[t],i=[],a=new Set,l=new Set(o),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};o.forEach(c);var d=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(p){if(a.has(p))d(p);else try{var f=p.getAttribute(r),S=f!==null&&f!=="false",g=(wa.get(p)||0)+1,x=(s.get(p)||0)+1;wa.set(p,g),s.set(p,x),i.push(p),g===1&&S&&nh.set(p,!0),x===1&&p.setAttribute(t,"true"),S||p.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",p,y)}})};return d(n),a.clear(),xy++,function(){i.forEach(function(h){var p=wa.get(h)-1,f=s.get(h)-1;wa.set(h,p),s.set(h,f),p||(nh.has(h)||h.removeAttribute(r),nh.delete(h)),f||h.removeAttribute(t)}),xy--,xy||(wa=new WeakMap,wa=new WeakMap,nh=new WeakMap,rh={})}},S0=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=WZ(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),VZ(r,o,t,"aria-hidden")):function(){return null}},v0="Dialog",[cA,Kie]=Eo(v0),[YZ,Xr]=cA(v0),uA=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=P.useRef(null),l=P.useRef(null),[c=!1,d]=li({prop:r,defaultProp:o,onChange:s});return u.jsx(YZ,{scope:n,triggerRef:a,contentRef:l,contentId:Go(),titleId:Go(),descriptionId:Go(),open:c,onOpenChange:d,onOpenToggle:P.useCallback(()=>d(h=>!h),[d]),modal:i,children:t})};uA.displayName=v0;var dA="DialogTrigger",XZ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Xr(dA,t),s=Ye(n,o.triggerRef);return u.jsx(Ce.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":b0(o.open),...r,ref:s,onClick:re(e.onClick,o.onOpenToggle)})});XZ.displayName=dA;var x0="DialogPortal",[qZ,hA]=cA(x0,{forceMount:void 0}),pA=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=Xr(x0,n);return u.jsx(qZ,{scope:n,forceMount:t,children:P.Children.map(r,i=>u.jsx(Yr,{present:t||s.open,children:u.jsx(Vu,{asChild:!0,container:o,children:i})}))})};pA.displayName=x0;var xf="DialogOverlay",fA=P.forwardRef((e,n)=>{const t=hA(xf,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=Xr(xf,e.__scopeDialog);return s.modal?u.jsx(Yr,{present:r||s.open,children:u.jsx(ZZ,{...o,ref:n})}):null});fA.displayName=xf;var ZZ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Xr(xf,t);return u.jsx(vg,{as:Xi,allowPinchZoom:!0,shards:[o.contentRef],children:u.jsx(Ce.div,{"data-state":b0(o.open),...r,ref:n,style:{pointerEvents:"auto",...r.style}})})}),qi="DialogContent",gA=P.forwardRef((e,n)=>{const t=hA(qi,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=Xr(qi,e.__scopeDialog);return u.jsx(Yr,{present:r||s.open,children:s.modal?u.jsx(QZ,{...o,ref:n}):u.jsx(JZ,{...o,ref:n})})});gA.displayName=qi;var QZ=P.forwardRef((e,n)=>{const t=Xr(qi,e.__scopeDialog),r=P.useRef(null),o=Ye(n,t.contentRef,r);return P.useEffect(()=>{const s=r.current;if(s)return S0(s)},[]),u.jsx(mA,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:re(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)==null||i.focus()}),onPointerDownOutside:re(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:re(e.onFocusOutside,s=>s.preventDefault())})}),JZ=P.forwardRef((e,n)=>{const t=Xr(qi,e.__scopeDialog),r=P.useRef(!1),o=P.useRef(!1);return u.jsx(mA,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=t.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),mA=P.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Xr(qi,t),l=P.useRef(null),c=Ye(n,l);return y0(),u.jsxs(u.Fragment,{children:[u.jsx(yg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Gu,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":b0(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),u.jsxs(u.Fragment,{children:[u.jsx(tQ,{titleId:a.titleId}),u.jsx(rQ,{contentRef:l,descriptionId:a.descriptionId})]})]})}),w0="DialogTitle",yA=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Xr(w0,t);return u.jsx(Ce.h2,{id:o.titleId,...r,ref:n})});yA.displayName=w0;var SA="DialogDescription",eQ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Xr(SA,t);return u.jsx(Ce.p,{id:o.descriptionId,...r,ref:n})});eQ.displayName=SA;var vA="DialogClose",xA=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Xr(vA,t);return u.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,()=>o.onOpenChange(!1))})});xA.displayName=vA;function b0(e){return e?"open":"closed"}var wA="DialogTitleWarning",[Wie,bA]=Oq(wA,{contentName:qi,titleName:w0,docsSlug:"dialog"}),tQ=({titleId:e})=>{const n=bA(wA),t=`\`${n.contentName}\` requires a \`${n.titleName}\` for the component to be accessible for screen reader users.
|
|
|
|
If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
|
|
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return P.useEffect(()=>{e&&(document.getElementById(e)||console.error(t))},[t,e]),null},nQ="DialogDescriptionWarning",rQ=({contentRef:e,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${bA(nQ).contentName}}.`;return P.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,e,n]),null},oQ=uA,sQ=pA,iQ=fA,aQ=gA;const PA=()=>{},CA=P.createContext(null);function lQ({onEvent:e,children:n}){return u.jsx(CA.Provider,{value:e??PA,children:n})}function qr(){return P.useContext(CA)??PA}const IA=P.createContext(null);function cQ({children:e}){const n=B(),t=qr(),[r,o]=P.useState([]),s=P.useCallback(c=>{const d=c.id??ot();return o(h=>[...h.filter(p=>p.id!==c.id),{...c,id:d}]),t("open-menu",{source:"dialog",id:d}),n.addOpenMenu(d),d},[n,t]),i=P.useCallback((c,d)=>(o(h=>h.map(p=>p.id===c?{...p,...d}:p)),t("open-menu",{source:"dialog",id:c}),n.addOpenMenu(c),c),[n,t]),a=P.useCallback(c=>(o(d=>d.filter(h=>{var p;return h.id===c?((p=h.onClose)==null||p.call(h),!1):!0})),t("close-menu",{source:"dialog",id:c}),n.deleteOpenMenu(c),c),[n,t]),l=P.useCallback(()=>{o(c=>(c.forEach(d=>{var h;(h=d.onClose)==null||h.call(d),t("close-menu",{source:"dialog",id:d.id}),n.deleteOpenMenu(d.id)}),[]))},[n,t]);return u.jsx(IA.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function la(){const e=P.useContext(IA);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const uQ=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=la(),o=un(),s=P.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return u.jsx(oQ,{onOpenChange:s,defaultOpen:!0,children:u.jsx(sQ,{container:o,children:u.jsx(iQ,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:u.jsx(aQ,{dir:"ltr",className:"tlui-dialog__content",children:u.jsx(n,{onClose:()=>s(!1)})})})})})};function dQ(){const{dialogs:e}=la();return u.jsx(u.Fragment,{children:e.map(n=>u.jsx(uQ,{...n},n.id))})}const hQ=xe.memo(dQ);function pQ(){const e=B(),n=G("follow",()=>e.getInstanceState().followingUserId,[e]);return n?u.jsx(fQ,{userId:n}):null}function fQ({userId:e}){const n=o2(e);return n?u.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function xg(e){const n=e+"CollectionProvider",[t,r]=Eo(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:S,children:g}=f,x=xe.useRef(null),y=xe.useRef(new Map).current;return u.jsx(o,{scope:S,itemMap:y,collectionRef:x,children:g})};i.displayName=n;const a=e+"CollectionSlot",l=xe.forwardRef((f,S)=>{const{scope:g,children:x}=f,y=s(a,g),v=Ye(S,y.collectionRef);return u.jsx(Xi,{ref:v,children:x})});l.displayName=a;const c=e+"CollectionItemSlot",d="data-radix-collection-item",h=xe.forwardRef((f,S)=>{const{scope:g,children:x,...y}=f,v=xe.useRef(null),b=Ye(S,v),E=s(c,g);return xe.useEffect(()=>(E.itemMap.set(v,{ref:v,...y}),()=>void E.itemMap.delete(v))),u.jsx(Xi,{[d]:"",ref:b,children:x})});h.displayName=c;function p(f){const S=s(e+"CollectionConsumer",f);return xe.useCallback(()=>{const x=S.collectionRef.current;if(!x)return[];const y=Array.from(x.querySelectorAll(`[${d}]`));return Array.from(S.itemMap.values()).sort((E,I)=>y.indexOf(E.ref.current)-y.indexOf(I.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var gQ="VisuallyHidden",P0=P.forwardRef((e,n)=>u.jsx(Ce.span,{...e,ref:n,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}}));P0.displayName=gQ;var C0="ToastProvider",[I0,mQ,yQ]=xg("Toast"),[EA,Gie]=Eo("Toast",[yQ]),[SQ,wg]=EA(C0),kA=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=P.useState(null),[c,d]=P.useState(0),h=P.useRef(!1),p=P.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${C0}\`. Expected non-empty \`string\`.`),u.jsx(I0.Provider,{scope:n,children:u.jsx(SQ,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:P.useCallback(()=>d(f=>f+1),[]),onToastRemove:P.useCallback(()=>d(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:p,children:i})})};kA.displayName=C0;var _A="ToastViewport",vQ=["F8"],$v="toast.viewportPause",Fv="toast.viewportResume",TA=P.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=vQ,label:o="Notifications ({hotkey})",...s}=e,i=wg(_A,t),a=mQ(t),l=P.useRef(null),c=P.useRef(null),d=P.useRef(null),h=P.useRef(null),p=Ye(n,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=i.toastCount>0;P.useEffect(()=>{const x=y=>{var b;r.every(E=>y[E]||y.code===E)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),P.useEffect(()=>{const x=l.current,y=h.current;if(S&&x&&y){const v=()=>{if(!i.isClosePausedRef.current){const C=new CustomEvent($v);y.dispatchEvent(C),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const C=new CustomEvent(Fv);y.dispatchEvent(C),i.isClosePausedRef.current=!1}},E=C=>{!x.contains(C.relatedTarget)&&b()},I=()=>{x.contains(document.activeElement)||b()};return x.addEventListener("focusin",v),x.addEventListener("focusout",E),x.addEventListener("pointermove",v),x.addEventListener("pointerleave",I),window.addEventListener("blur",v),window.addEventListener("focus",b),()=>{x.removeEventListener("focusin",v),x.removeEventListener("focusout",E),x.removeEventListener("pointermove",v),x.removeEventListener("pointerleave",I),window.removeEventListener("blur",v),window.removeEventListener("focus",b)}}},[S,i.isClosePausedRef]);const g=P.useCallback(({tabbingDirection:x})=>{const v=a().map(b=>{const E=b.ref.current,I=[E,...AQ(E)];return x==="forwards"?I:I.reverse()});return(x==="forwards"?v.reverse():v).flat()},[a]);return P.useEffect(()=>{const x=h.current;if(x){const y=v=>{var I,C,k;const b=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!b){const T=document.activeElement,O=v.shiftKey;if(v.target===x&&O){(I=c.current)==null||I.focus();return}const L=g({tabbingDirection:O?"backwards":"forwards"}),A=L.findIndex(R=>R===T);wy(L.slice(A+1))?v.preventDefault():O?(C=c.current)==null||C.focus():(k=d.current)==null||k.focus()}};return x.addEventListener("keydown",y),()=>x.removeEventListener("keydown",y)}},[a,g]),u.jsxs(Zq,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:S?void 0:"none"},children:[S&&u.jsx(Nv,{ref:c,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"forwards"});wy(x)}}),u.jsx(I0.Slot,{scope:t,children:u.jsx(Ce.ol,{tabIndex:-1,...s,ref:p})}),S&&u.jsx(Nv,{ref:d,onFocusFromOutsideViewport:()=>{const x=g({tabbingDirection:"backwards"});wy(x)}})]})});TA.displayName=_A;var MA="ToastFocusProxy",Nv=P.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=wg(MA,t);return u.jsx(P0,{"aria-hidden":!0,tabIndex:0,...o,ref:n,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=s.viewport)!=null&&c.contains(a))&&r()}})});Nv.displayName=MA;var bg="Toast",xQ="toast.swipeStart",wQ="toast.swipeMove",bQ="toast.swipeCancel",PQ="toast.swipeEnd",jA=P.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,l]=li({prop:r,defaultProp:o,onChange:s});return u.jsx(Yr,{present:t||a,children:u.jsx(EQ,{open:a,...i,ref:n,onClose:()=>l(!1),onPause:Vt(e.onPause),onResume:Vt(e.onResume),onSwipeStart:re(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:re(e.onSwipeMove,c=>{const{x:d,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:re(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:re(e.onSwipeEnd,c=>{const{x:d,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${d}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});jA.displayName=bg;var[CQ,IQ]=EA(bg,{onClose(){}}),EQ=P.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:d,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:f,...S}=e,g=wg(bg,t),[x,y]=P.useState(null),v=Ye(n,R=>y(R)),b=P.useRef(null),E=P.useRef(null),I=o||g.duration,C=P.useRef(0),k=P.useRef(I),T=P.useRef(0),{onToastAdd:O,onToastRemove:_}=g,j=Vt(()=>{var F;(x==null?void 0:x.contains(document.activeElement))&&((F=g.viewport)==null||F.focus()),i()}),L=P.useCallback(R=>{!R||R===1/0||(window.clearTimeout(T.current),C.current=new Date().getTime(),T.current=window.setTimeout(j,R))},[j]);P.useEffect(()=>{const R=g.viewport;if(R){const F=()=>{L(k.current),c==null||c()},W=()=>{const K=new Date().getTime()-C.current;k.current=k.current-K,window.clearTimeout(T.current),l==null||l()};return R.addEventListener($v,W),R.addEventListener(Fv,F),()=>{R.removeEventListener($v,W),R.removeEventListener(Fv,F)}}},[g.viewport,I,l,c,L]),P.useEffect(()=>{s&&!g.isClosePausedRef.current&&L(I)},[s,I,g.isClosePausedRef,L]),P.useEffect(()=>(O(),()=>_()),[O,_]);const A=P.useMemo(()=>x?FA(x):null,[x]);return g.viewport?u.jsxs(u.Fragment,{children:[A&&u.jsx(kQ,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:A}),u.jsx(CQ,{scope:t,onClose:j,children:ra.createPortal(u.jsx(I0.ItemSlot,{scope:t,children:u.jsx(qq,{asChild:!0,onEscapeKeyDown:re(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||j(),g.isFocusedToastEscapeKeyDownRef.current=!1}),children:u.jsx(Ce.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection,...S,ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:re(e.onKeyDown,R=>{R.key==="Escape"&&(a==null||a(R.nativeEvent),R.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,j()))}),onPointerDown:re(e.onPointerDown,R=>{R.button===0&&(b.current={x:R.clientX,y:R.clientY})}),onPointerMove:re(e.onPointerMove,R=>{if(!b.current)return;const F=R.clientX-b.current.x,W=R.clientY-b.current.y,K=!!E.current,z=["left","right"].includes(g.swipeDirection),U=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,X=z?U(0,F):0,J=z?0:U(0,W),le=R.pointerType==="touch"?10:2,ye={x:X,y:J},Me={originalEvent:R,delta:ye};K?(E.current=ye,oh(wQ,h,Me,{discrete:!1})):zI(ye,g.swipeDirection,le)?(E.current=ye,oh(xQ,d,Me,{discrete:!1}),R.target.setPointerCapture(R.pointerId)):(Math.abs(F)>le||Math.abs(W)>le)&&(b.current=null)}),onPointerUp:re(e.onPointerUp,R=>{const F=E.current,W=R.target;if(W.hasPointerCapture(R.pointerId)&&W.releasePointerCapture(R.pointerId),E.current=null,b.current=null,F){const K=R.currentTarget,z={originalEvent:R,delta:F};zI(F,g.swipeDirection,g.swipeThreshold)?oh(PQ,f,z,{discrete:!0}):oh(bQ,p,z,{discrete:!0}),K.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})})}),g.viewport)})]}):null}),kQ=e=>{const{__scopeToast:n,children:t,...r}=e,o=wg(bg,n),[s,i]=P.useState(!1),[a,l]=P.useState(!1);return MQ(()=>i(!0)),P.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:u.jsx(Vu,{asChild:!0,children:u.jsx(P0,{...r,children:s&&u.jsxs(u.Fragment,{children:[o.label," ",t]})})})},_Q="ToastTitle",AA=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return u.jsx(Ce.div,{...r,ref:n})});AA.displayName=_Q;var TQ="ToastDescription",OA=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return u.jsx(Ce.div,{...r,ref:n})});OA.displayName=TQ;var DA="ToastAction",RA=P.forwardRef((e,n)=>{const{altText:t,...r}=e;return t.trim()?u.jsx($A,{altText:t,asChild:!0,children:u.jsx(E0,{...r,ref:n})}):(console.error(`Invalid prop \`altText\` supplied to \`${DA}\`. Expected non-empty \`string\`.`),null)});RA.displayName=DA;var LA="ToastClose",E0=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=IQ(LA,t);return u.jsx($A,{asChild:!0,children:u.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,o.onClose)})})});E0.displayName=LA;var $A=P.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return u.jsx(Ce.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:n})});function FA(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),jQ(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&&n.push(i)}else n.push(...FA(r))}}),n}function oh(e,n,t,{discrete:r}){const o=t.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?m0(o,s):o.dispatchEvent(s)}var zI=(e,n,t=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return n==="left"||n==="right"?s&&r>t:!s&&o>t};function MQ(e=()=>{}){const n=Vt(e);Xs(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function jQ(e){return e.nodeType===e.ELEMENT_NODE}function AQ(e){const n=[],t=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(;t.nextNode();)n.push(t.currentNode);return n}function wy(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}var OQ=jA,DQ=AA,RQ=OA,LQ=RA,BI=E0;const NA=P.createContext(null);function $Q({children:e}){const[n,t]=P.useState([]),r=P.useCallback(i=>{const a=i.id??ot();return t(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=P.useCallback(i=>(t(a=>a.filter(l=>l.id!==i)),i),[]),s=P.useCallback(()=>{t(()=>[])},[]);return u.jsx(kA,{children:u.jsx(NA.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})})}function Zr(){const e=P.useContext(NA);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const he=P.forwardRef(function({children:n,disabled:t,type:r,...o},s){return u.jsx("button",{ref:s,type:"button",draggable:!1,disabled:t,...o,className:ce("tlui-button",`tlui-button__${r}`,o.className),children:n})});function bt({children:e}){return u.jsx("span",{className:"tlui-button__label",children:e})}const qs=P.memo(function({small:n,invertIcon:t,icon:r,color:o,className:s,...i}){const a=d0(),l=a.icons[r]??a.icons["question-mark-circle"],c=P.useRef(null);return P.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?u.jsx("div",{className:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":n},s)}):u.jsx("div",{...i,ref:c,className:ce("tlui-icon",{"tlui-icon__small":n},s),style:{color:o,mask:`url(${l}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})}),FQ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function NQ({toast:e}){const{removeToast:n}=Zr(),t=Te(),r=i=>{i||n(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&FQ[e.severity];return u.jsxs(OQ,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&u.jsx("div",{className:"tlui-toast__icon",children:u.jsx(qs,{icon:s})}),u.jsxs("div",{className:"tlui-toast__main",children:[u.jsxs("div",{className:"tlui-toast__content",children:[e.title&&u.jsx(DQ,{className:"tlui-toast__title",children:e.title}),e.description&&u.jsx(RQ,{className:"tlui-toast__description",children:e.description})]}),e.actions&&u.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>u.jsx(LQ,{altText:i.label,asChild:!0,onClick:i.onClick,children:u.jsx(he,{type:i.type,children:u.jsx(bt,{children:i.label})})},a)),u.jsx(BI,{asChild:!0,children:u.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:u.jsx(bt,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&u.jsx(BI,{asChild:!0,children:u.jsx(he,{type:"normal",className:"tlui-toast__close",children:u.jsx(bt,{children:e.closeLabel??t("toast.close")})})})]})}function zQ(){const{toasts:e}=Zr();return u.jsx(u.Fragment,{children:e.map(n=>u.jsx(NQ,{toast:n},n.id))})}const BQ=P.memo(zQ);function UQ(){const e=B(),{toasts:n}=Zr(),[t,r]=P.useState(!1);return P.useEffect(()=>{let o=-1;return n.length?r(!0):o=e.timers.setTimeout(()=>{r(!1)},1e3),()=>{clearTimeout(o)}},[n.length,r,e]),t?u.jsx(TA,{className:"tlui-toast__viewport"}):null}function be({icon:e,small:n,invertIcon:t}){return u.jsx(qs,{className:"tlui-button__icon",icon:e,small:n,invertIcon:t})}const by=[0,390,428,468,580,640,840,1023];var yt=(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))(yt||{});const HQ="2.3.0",KQ="https://cdn.tldraw.com";function Ti(){return`${KQ}/${HQ}`}let zv={fonts:{draw:`${Ti()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Ti()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Ti()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Ti()}/fonts/IBMPlexMono-Medium.woff2`}};function zA(e){return P.useMemo(()=>e?{fonts:{...zv.fonts,...e==null?void 0:e.fonts}}:zv,[e])}const WQ=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bring-forward","bring-to-front","broken","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","color","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","leading","link","lock","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","stretch-horizontal","stretch-vertical","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let dc={...zv,icons:Object.fromEntries(WQ.map(e=>[e,`${Ti()}/icons/icon/${e}.svg`])),translations:Object.fromEntries(pu.map(e=>[e.locale,`${Ti()}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries($u.map(e=>[e.type,`${Ti()}/embed-icons/${e.type}.png`]))};function GQ(e){return e?{fonts:Object.assign({...dc.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...dc.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...dc.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...dc.translations},{...e==null?void 0:e.translations})}:dc}function Pg({className:e,children:n}){return u.jsx("div",{className:ce("tlui-dialog__header",e),children:n})}function Cg({className:e,children:n}){return u.jsx(yA,{dir:"ltr",className:ce("tlui-dialog__header__title",e),children:n})}function Ig(){return u.jsx("div",{className:"tlui-dialog__header__close",children:u.jsx(xA,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:u.jsx(he,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:u.jsx(be,{small:!0,icon:"cross-2"})})})})}function mu({className:e,children:n,style:t}){return u.jsx("div",{className:ce("tlui-dialog__body",e),style:t,children:n})}function k0({className:e,children:n}){return u.jsx("div",{className:ce("tlui-dialog__footer",e),children:n})}const _0=P.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:d,onCancel:h,onFocus:p,onBlur:f,shouldManuallyMaintainScrollPositionWhenFocused:S=!1,children:g,value:x},y){const v=B(),b=P.useRef(null);P.useImperativeHandle(y,()=>b.current);const E=Te(),I=P.useRef(a??""),C=P.useRef(a??""),[k,T]=P.useState(!1),O=P.useCallback(A=>{T(!0);const R=A.currentTarget;C.current=R.value,v.timers.requestAnimationFrame(()=>{s&&R.select()}),p==null||p()},[s,p,v.timers]),_=P.useCallback(A=>{const R=A.currentTarget.value;C.current=R,d==null||d(R)},[d]),j=P.useCallback(A=>{switch(A.key){case"Enter":{A.currentTarget.blur(),Kt(A),c==null||c(A.currentTarget.value);break}case"Escape":{A.currentTarget.value=I.current,A.currentTarget.blur(),Kt(A),h==null||h(A.currentTarget.value);break}}},[c,h]),L=P.useCallback(A=>{T(!1);const R=A.currentTarget.value;f==null||f(R)},[f]);return P.useEffect(()=>{if(!v.environment.isIos)return;const A=window.visualViewport;if(k&&S&&A){const R=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return A.addEventListener("resize",R),A.addEventListener("scroll",R),v.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{A.removeEventListener("resize",R),A.removeEventListener("scroll",R)}}},[v,k,S]),u.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[g,t&&u.jsx("label",{children:E(t)}),o&&u.jsx(qs,{icon:o,className:"tlui-icon-left",small:!0}),u.jsx("input",{ref:b,className:ce("tlui-input",n),type:"text",defaultValue:a,onKeyUp:j,onChange:_,onFocus:O,onBlur:L,autoFocus:i,placeholder:l,value:x}),r&&u.jsx(qs,{icon:r,small:!!t})]})}),BA=lr(function({onClose:n}){const t=B(),r=Te(),o=d0(),[s,i]=P.useState(null),[a,l]=P.useState(""),[c,d]=P.useState(null),[h,p]=P.useState(!1),f=P.useRef(-1);return u.jsxs(u.Fragment,{children:[u.jsxs(Pg,{children:[u.jsx(Cg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),u.jsx(Ig,{})]}),s?u.jsxs(u.Fragment,{children:[u.jsxs(mu,{className:"tlui-embed-dialog__enter",children:[u.jsx(_0,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:S=>{l(S);const g=Ms(S);d(g&&g.definition.type===s.type?g:null),p(!1),clearTimeout(f.current),f.current=t.timers.setTimeout(()=>p(!g),320)}}),a===""?u.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[u.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&u.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",u.jsx(qs,{icon:"external-link",small:!0})]})]}):u.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),u.jsxs(k0,{className:"tlui-dialog__footer__actions",children:[u.jsx(he,{type:"normal",onClick:()=>{i(null),d(null),l("")},children:u.jsx(bt,{children:r("embed-dialog.back")})}),u.jsx("div",{className:"tlui-embed__spacer"}),u.jsx(he,{type:"normal",onClick:n,children:u.jsx(bt,{children:r("embed-dialog.cancel")})}),u.jsx(he,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:c.definition}),n())},children:u.jsx(bt,{children:r("embed-dialog.create")})})]})]}):u.jsx(u.Fragment,{children:u.jsx(mu,{className:"tlui-embed-dialog__list",children:$u.map(S=>u.jsxs(he,{type:"menu",onClick:()=>i(S),children:[u.jsx(bt,{children:S.title}),u.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[S.type]})`}})]},S.type))})})]})});function UA(){const e=B(),n=P.useRef();return P.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept=z6,t.multiple=!0,n.current=t;async function r(o){const s=o.target.files;!s||s.length===0||(e.mark("insert media"),await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),t.value="")}return t.addEventListener("change",r),()=>{n.current=void 0,t.removeEventListener("change",r)}},[e]),P.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}const HA=P.createContext(null);function VQ({overrides:e,children:n}){const t=B(),r=qr(),{addDialog:o}=la(),s=UA(),i=P.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){t.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){t.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){t.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){t.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...Fr.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(d){t.batch(()=>{t.setStyleForNextShapes(Fr,c),t.setCurrentTool("geo"),r("select-tool",{source:d,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){t.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){t.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){t.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){t.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){t.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){t.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(c){o({component:BA}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){t.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];a.push();const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(t,l,{insertMedia:s}):l},[e,t,r,s,o]);return u.jsx(HA.Provider,{value:i,children:n})}function Eg(){const e=P.useContext(HA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const KA=xe.createContext(null);function YQ({forceMobile:e=!1,children:n}){const t=B(),r=G("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?yt.MOBILE_SM:by.length-1;for(let i=0;i<s;i++)if(o>by[i]&&o<=by[i+1])return i;return s},[t]);return u.jsx(KA.Provider,{value:r,children:n})}function Un(){const e=P.useContext(KA);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function XQ(){const{addToast:e,removeToast:n,clearToasts:t}=Zr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=la(),l=Un()<yt.TABLET_SM,c=Te();return P.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,e,o,t,c,s,n,i,l])}function qQ(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of Fn(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,n));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...n,...s}));return o},translations:t}}function WA(e){return P.useMemo(()=>e,e)}function ZQ(e){const n=WA(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of Fn(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function QQ(e){const n=XQ(),t=WA(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>qQ(t,n),[t,n])}function JQ(e,n){const t=me(n.map(o=>e.getShape(o)).filter(o=>o&&e.isShapeOfType(o,"frame")));if(!t.length)return;const r=[];e.batch(()=>{t.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(n)})}const eJ=50;function tJ(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=me(o.map(f=>e.getShape(f)));if(!s.length)return;const i=Z.FromPoints(s.flatMap(f=>{const S=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(S.vertices)})),{padding:a=eJ}=t,l=i.w+2*a,c=i.h+2*a,d=a-i.minX,h=a-i.minY;if(d===0&&h===0&&r.props.w===l&&r.props.h===c)return;const p=new w(d,h).rot(r.rotation);e.batch(()=>{const f=o.map(S=>{const g=e.getShape(S);return{id:g.id,type:g.type,x:g.x+d,y:g.y+h}});f.push({id:r.id,type:r.type,x:r.x-p.x,y:r.y-p.y,props:{w:l,h:c}}),e.updateShapes(f)})}function UI(e){return or.isValid(e)?{isValid:!0,hasProtocol:!0}:or.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const nJ=lr(function({onClose:n}){const r=B().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?u.jsx(rJ,{onClose:n,selectedShape:r}):null}),rJ=lr(function({onClose:n,selectedShape:t}){const r=B(),o=Te(),s=P.useRef(null);P.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=s.current)==null?void 0:S.focus()})},[r]);const i=P.useRef(t.props.url),[a,l]=P.useState(()=>{const S=UI(t.props.url),g=S.isValid===!0?S.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:g,safe:g,valid:!0}}),c=P.useCallback(S=>{const g=S.replace(/https?:\/\/(https?:\/\/)/,(v,b)=>b),x=UI(g),y=x.isValid===!0?x.hasProtocol?g:"https://"+g:"https://";l({actual:g,safe:y,valid:x.isValid})},[]),d=P.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),n())},[r,n]),h=P.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(S&&"url"in S.props&&S.props.url!==a.safe&&r.updateShapes([{id:S.id,type:S.type,props:{url:a.safe}}]),n())},[r,n,a]),p=P.useCallback(()=>{n()},[n]);if(!t)return n(),null;const f=i.current&&!a.valid;return u.jsxs(u.Fragment,{children:[u.jsxs(Pg,{children:[u.jsx(Cg,{children:o("edit-link-dialog.title")}),u.jsx(Ig,{})]}),u.jsx(mu,{children:u.jsxs("div",{className:"tlui-edit-link-dialog",children:[u.jsx(_0,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:p}),u.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),u.jsxs(k0,{className:"tlui-dialog__footer__actions",children:[u.jsx(he,{type:"normal",onClick:p,onTouchEnd:p,children:u.jsx(bt,{children:o("edit-link-dialog.cancel")})}),f?u.jsx(he,{type:"danger",onTouchEnd:d,onClick:d,children:u.jsx(bt,{children:o("edit-link-dialog.clear")})}):u.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:u.jsx(bt,{children:o("edit-link-dialog.save")})})]})]})});var T0={exports:{}};T0.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var d=0;d<l.length;d++)s[l][l.charAt(d)]=d}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(d){return r.charAt(d)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),d=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var f=c.charCodeAt(h);d[h*2]=f>>>8,d[h*2+1]=f%256}return d},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),d=0,h=c.length;d<h;d++)c[d]=l[d*2]*256+l[d*2+1];var p=[];return c.forEach(function(f){p.push(t(f))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,d){if(l==null)return"";var h,p,f={},S={},g="",x="",y="",v=2,b=3,E=2,I=[],C=0,k=0,T;for(T=0;T<l.length;T+=1)if(g=l.charAt(T),Object.prototype.hasOwnProperty.call(f,g)||(f[g]=b++,S[g]=!0),x=y+g,Object.prototype.hasOwnProperty.call(f,x))y=x;else{if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(h=0;h<E;h++)C=C<<1,k==c-1?(k=0,I.push(d(C)),C=0):k++;for(p=y.charCodeAt(0),h=0;h<8;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1}else{for(p=1,h=0;h<E;h++)C=C<<1|p,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=0;for(p=y.charCodeAt(0),h=0;h<16;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete S[y]}else for(p=f[y],h=0;h<E;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++),f[x]=b++,y=String(g)}if(y!==""){if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(h=0;h<E;h++)C=C<<1,k==c-1?(k=0,I.push(d(C)),C=0):k++;for(p=y.charCodeAt(0),h=0;h<8;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1}else{for(p=1,h=0;h<E;h++)C=C<<1|p,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=0;for(p=y.charCodeAt(0),h=0;h<16;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete S[y]}else for(p=f[y],h=0;h<E;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++)}for(p=2,h=0;h<E;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(d(C)),C=0):k++,p=p>>1;for(;;)if(C=C<<1,k==c-1){I.push(d(C));break}else k++;return I.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,d){var h=[],p=4,f=4,S=3,g="",x=[],y,v,b,E,I,C,k,T={val:d(0),position:c,index:1};for(y=0;y<3;y+=1)h[y]=y;for(b=0,I=Math.pow(2,2),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=d(T.index++)),b|=(E>0?1:0)*C,C<<=1;switch(b){case 0:for(b=0,I=Math.pow(2,8),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=d(T.index++)),b|=(E>0?1:0)*C,C<<=1;k=t(b);break;case 1:for(b=0,I=Math.pow(2,16),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=d(T.index++)),b|=(E>0?1:0)*C,C<<=1;k=t(b);break;case 2:return""}for(h[3]=k,v=k,x.push(k);;){if(T.index>l)return"";for(b=0,I=Math.pow(2,S),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=d(T.index++)),b|=(E>0?1:0)*C,C<<=1;switch(k=b){case 0:for(b=0,I=Math.pow(2,8),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=d(T.index++)),b|=(E>0?1:0)*C,C<<=1;h[f++]=t(b),k=f-1,p--;break;case 1:for(b=0,I=Math.pow(2,16),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=d(T.index++)),b|=(E>0?1:0)*C,C<<=1;h[f++]=t(b),k=f-1,p--;break;case 2:return x.join("")}if(p==0&&(p=Math.pow(2,S),S++),h[k])g=h[k];else if(k===f)g=v+v.charAt(0);else return null;x.push(g),h[f++]=v+g.charAt(0),p--,v=g,p==0&&(p=Math.pow(2,S),S++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(T0);var oJ=T0.exports;const GA=ei(oJ);async function sJ(e,n,t){var y,v,b;const{elements:r,files:o}=n,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,d=[],h=new Set;r.forEach(E=>{if(c.set(E.id,$e()),E.boundElements!==null)for(const I of E.boundElements)I.type==="text"&&h.add(I.id)});let p=U6;for(const E of r){if(h.has(E.id))continue;const I=c.get(E.id),C={id:I,typeName:"shape",parentId:l,index:p,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:iJ(E.opacity),meta:{}};switch(E.angle!==0&&a.set(I,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(y=i.get(E.groupIds[0]))==null||y.push(I):i.set(E.groupIds[0],[I]):d.push(I),E.type){case"rectangle":case"ellipse":case"diamond":{let k="",T="middle";if(E.boundElements!==null){for(const _ of E.boundElements)if(_.type==="text"){const j=r.find(L=>L.id===_.id);j&&(k=j.text,T=hJ[j.textAlign])}}const O=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;s.shapes.push({...C,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:sh[E.strokeWidth]??"draw",color:hc[O]??"black",text:k,align:T,dash:ih(E),fill:gJ(E)}});break}case"freedraw":{s.shapes.push({...C,type:"draw",props:{dash:ih(E),size:sh[E.strokeWidth],color:hc[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([k,T,O=.5])=>({x:k,y:T,z:O}))}]}});break}case"line":{if(E.points.slice().length<2)break;const T=du(E.points.length);s.shapes.push({...C,type:"line",props:{dash:ih(E),size:sh[E.strokeWidth],color:hc[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([O,_],j)=>{const L=T[j];return[L,{id:L,index:L,x:O,y:_}]}))}}});break}case"arrow":{let k="";if(E.boundElements!==null){for(const L of E.boundElements)if(L.type==="text"){const A=r.find(R=>R.id===L.id);A&&(k=A.text)}}const T=E.points[0],O=E.points[E.points.length-1],_=c.get((v=E.startBinding)==null?void 0:v.elementId),j=c.get((b=E.endBinding)==null?void 0:b.elementId);s.shapes.push({...C,type:"arrow",props:{text:k,bend:fJ(E,T,O),dash:ih(E),size:sh[E.strokeWidth]??"m",color:hc[E.strokeColor]??"black",start:{x:T[0],y:T[1]},end:{x:O[0],y:O[1]},arrowheadEnd:HI[E.endArrowhead]??"none",arrowheadStart:HI[E.startArrowhead]??"none"}}),_&&s.bindings.push({id:Ri(),typeName:"binding",type:"arrow",fromId:I,toId:_,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),j&&s.bindings.push({id:Ri(),typeName:"binding",type:"arrow",fromId:I,toId:j,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:k,scale:T}=lJ(E.fontSize);s.shapes.push({...C,type:"text",props:{size:k,scale:T,font:cJ[E.fontFamily]??"draw",color:hc[E.strokeColor]??"black",text:E.text,textAlign:pJ[E.textAlign]}});break}case"image":{const k=o[E.fileId];if(!k)break;const T=ki.createId();s.assets.push({id:T,typeName:"asset",type:"image",props:{w:E.width,h:E.height,fileSize:k.size,name:E.id??"Untitled",isAnimated:!1,mimeType:k.mimeType,src:k.dataURL},meta:{}}),s.shapes.push({...C,type:"image",props:{w:E.width,h:E.height,assetId:T}})}}p=Lo(p)}const f=t??(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 I=e.getShape(E[0]);I!=null&&I.parentId&&kn(I.parentId)&&d.push(I.parentId)}for(const[E,I]of a)e.select(E),e.rotateShapesBy([E],I);const S=me(d.map(E=>e.getShape(E))),g=Z.Common(S.map(E=>e.getShapePageBounds(E))),x=e.getViewportPageBounds().center;e.updateShapes(S.map(E=>{const I={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:x.x+I.x,y:x.y+I.y}})),e.setSelectedShapes(d)}const iJ=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},sh={1:"s",2:"m",3:"l",4:"xl"},aJ={16:"s",20:"m",28:"l",36:"xl"};function lJ(e){const n=aJ[e];return n?{size:n,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}const cJ={1:"draw",2:"sans",3:"mono"},hc={"#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"},uJ={solid:"draw",dashed:"dashed",dotted:"dotted"},dJ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},hJ={left:"start",center:"middle",right:"end"},pJ={left:"start",center:"middle",right:"end"},HI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function fJ(e,n,t){let r=0;if(e.points.length>2){const o=new w(n[0],n[1]),s=new w(t[0],t[1]),i=new w(e.points[1][0],e.points[1][1]),a=w.Sub(s,o),l=w.Per(a),c=w.Med(s,o),d=w.Sub(c,l),h=w.Add(c,l),p=w.NearestPointOnLineSegment(d,h,i,!1);r=w.Dist(p,c),w.Clockwise(p,s,c)&&(r*=-1)}return r}const ih=e=>{let n=uJ[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},gJ=e=>e.backgroundColor==="transparent"?"none":dJ[e.fillStyle]??"solid";async function VA(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await yo(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r}),n.forEach(i=>URL.revokeObjectURL(i))}function mJ(e,n,t){const r=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(n,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0}),e.timers.setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))}async function Bv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await yo(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),VA(e,[n]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:t,url:n,sources:r})}function yJ(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const SJ=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},vJ=e=>{const n=e.split(/[\n\s]/);for(const t of n)try{const r=new URL(t);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return r2(n)},xJ=e=>/^<svg/.test(e),wJ=["input","select","textarea"];function Py(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||wJ.indexOf(n.tagName.toLowerCase())>-1)}const bJ=e=>e.types.find(n=>n.match(/^image\//)),Cy=(e,n,t,r)=>{const o=vJ(n);if(o)for(const s of o)Bv(e,s,t);else SJ(n)?Bv(e,n,t):xJ(n)?(e.mark("paste"),e.putExternalContent({type:"svg-text",text:n,point:t,sources:r})):(e.mark("paste"),e.putExternalContent({type:"text",text:n,point:t,sources:r}))},PJ=async(e,n,t)=>{if(e.getEditingShapeId()!==null)return;if(!n)throw Error("No clipboard data");const r=[];for(const o of Object.values(n.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}}XA(e,r,t)},YA=async(e,n,t)=>{const r=[];for(const o of n){if(bJ(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 Oi.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Oi.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Oi.blobToText(s)})()})}return await XA(e,r,t)};async function XA(e,n,t){const r=n.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 VA(e,i,t)}const o=await Promise.all(n.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(l=>{var d;const c=(d=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:d[1];if(c)try{const h=GA.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(h);if(p.type!=="application/tldraw"&&i({type:"error",data:p,reason:`found tldraw data comment but JSON was of a different type: ${p.type}`}),typeof p.data=="string"){i({type:"error",data:p,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:p.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){mJ(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){sJ(e,s.data,t);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(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");Cy(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){Cy(e,yJ(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Bv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){Cy(e,s.data,t,o);return}}const wf=async e=>{var r;const n=await e.resolveAssetsInContent(e.getContentFromCurrentPage(e.getSelectedShapeIds()));if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=GA.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:n}));if(!(typeof navigator>"u")){const o=n.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(Q6);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<div data-tldraw>${t}</div>`],{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(`<div data-tldraw>${t}</div>`)}};function CJ(){const e=B(),n=qr(),t=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await wf(e),n("copy",{source:i}))},[e,n]),r=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await wf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=P.useCallback(async function(i,a,l){e.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(YA(e,i,l),n("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[e,n]);return{copy:t,cut:r,paste:o}}function IJ(){const e=B(),n=qr(),t=G("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!t)return;const r=async l=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Py(e)||(Ee(l),await wf(e),n("copy",{source:"kbd"}))};async function o(l){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Py(e)||(Ee(l),await wf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,e.timers.requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){Kt(l);return}e.getEditingShapeId()!==null||Py(e)||(l.clipboardData&&!e.inputs.shiftKey?PJ(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&YA(e,c,e.inputs.currentPagePoint)}),Ee(l),n("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,n,t])}async function qA(e,n,t){const{type:r,quality:o,scale:s,width:i,height:a}=t;let[l,c]=await aY(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const d=l/i,h=URL.createObjectURL(new Blob([n],{type:"image/svg+xml"})),p=await new Promise(S=>{const g=pl();g.crossOrigin="anonymous",g.onload=async()=>{e.environment.isSafari&&await new Promise(v=>e.timers.setTimeout(v,250));const x=document.createElement("canvas"),y=x.getContext("2d");x.width=l,x.height=c,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(g,0,0,l,c),URL.revokeObjectURL(h),S(x)},g.onerror=()=>{S(null)},g.src=h});if(!p)return null;const f=await new Promise(S=>p.toBlob(g=>{(!g||wt.throwToBlob.get())&&S(null),S(g)},"image/"+r,o));if(!f)return null;if(r==="png"){const S=new DataView(await f.arrayBuffer());return so.setPhysChunk(S,d,{type:"image/"+r})}else return f}async function ZA(e,n,t){const r=await e.getSvgString(n!=null&&n.length?n:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...t});if(!r)throw new Error("Could not construct SVG.");return r}async function Uv(e,n,t,r={}){var o;switch(t){case"svg":return(o=await ZA(e,n,r))==null?void 0:o.svg;case"json":{const s=await e.resolveAssetsInContent(e.getContentFromCurrentPage(n));return JSON.stringify(s)}default:an(t)}}async function QA({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await Uv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Uv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await ZA(e,n,r);if(!o)throw new Error("Could not construct image.");const s=await qA(e,o.svg,{type:t,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:an(t)}}const EJ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function kJ(e,n,t,r={}){return{blobPromise:QA({editor:e,ids:n,format:t,opts:r}),mimeType:EJ[t]}}function _J(e,n,t="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=kJ(e,n,t,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(t){case"json":case"svg":return TJ(async()=>Uv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:an(t)}}async function TJ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}function MJ(){const e=B(),{addToast:n}=Zr(),t=Te();return P.useCallback((r,o="svg")=>{_J(e,r,o).catch(()=>{n({id:"copy-fail",severity:"warning",title:t("toast.error.copy-fail.title"),description:t("toast.error.copy-fail.desc")})})},[e,n,t])}async function jJ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${KI()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${KI()}`}r+=`.${t}`;const s=await QA({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});AJ(i)}function KI(){const e=new Date,n=String(e.getFullYear()).slice(2),t=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`${n}-${t}-${r} ${o}.${s}.${i}`}function AJ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function OJ(){const e=B(),{addToast:n}=Zr(),t=Te();return P.useCallback((r,o="png",s)=>{jJ(e,r,o,s,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),n({id:"export-fail",title:t("toast.error.export-fail.title"),description:t("toast.error.export-fail.desc"),severity:"error"})})},[e,n,t])}async function DJ(e,n,t){const r=me(n.map(a=>{const l=e.getShape(a);if(!(!l||e.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||e.isShapeOfType(a,"image"))return}const o=[];if(t!==void 0){const a=r.map(l=>({shape:l,bounds:e.getShapeMaskedPageBounds(l).clone().expandBy(t)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){o[0]={shapes:[c.shape],bounds:c.bounds};continue}let d=!1;for(const h of o)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),d=!0;break}d||o.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>e.getShapeMaskedPageBounds(l)));o.push({shapes:r,bounds:a})}const s=e.options.flattenImageBoundsPadding;for(const a of o){t!==void 0&&a.bounds.expandBy(-t);const l=await e.getSvgString(a.shapes,{padding:s});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),d=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});d&&(a.asset=d)}const i=[];return zs(()=>{for(const a of o){const{asset:l,bounds:c,shapes:d}=a;if(!l)continue;const h=e.findCommonAncestor(d)??e.getCurrentPageId();if(!h)continue;let p="a1";for(const y of d)if(y.parentId===h){y.index>p&&(p=y.index);break}let f,S,g;if(kn(h)){const y=e.getShape(h);if(!y)continue;const v=e.getPointInShapeSpace(y,{x:c.x,y:c.y});g=e.getShapePageTransform(h).rotation(),v.sub(new w(s,s).rot(-g)),f=v.x,S=v.y}else f=c.x-s,S=c.y-s,g=0;e.deleteShapes(d),e.createAssets([{...l,id:l.id}]);const x=$e();e.createShape({id:x,type:"image",index:p,parentId:h,x:f,y:S,rotation:-g,props:{assetId:l.id,w:c.w+s*2,h:c.h+s*2}}),i.push(x)}}),i}function RJ(){const e=B(),n=P.useRef(null),t=P.useRef(null);return P.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(y,v)=>{y&&(y.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),y&&document.body.contains(y)&&document.body.removeChild(y)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${ot()}`;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 l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{e.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function d(y,v,b){try{o.innerHTML+=`<div class="${a}__item">
|
|
<div class="${a}__item__header">
|
|
${y.replace(/</g,"<").replace(/>/g,">")}
|
|
</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 h(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=e.getSelectedShapeIds(),f=e.getCurrentPageId(),S=e.getPages(),x={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const y=await e.getSvgString(p,x);if(y){const v=S.find(b=>b.id===f);d(`tldraw — ${v==null?void 0:v.name}`,null,y.svg),h()}}else{const y=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(y.id),x);v&&(d(`tldraw — ${y.name}`,null,v.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const JA=P.createContext(null);function LJ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function ba(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function $J({overrides:e,children:n}){const t=B(),{addDialog:r,clearDialogs:o}=la(),{clearToasts:s}=Zr(),i=Te(),a=UA(),l=RJ(),{cut:c,copy:d,paste:h}=CJ(),p=MJ(),f=OJ(),S=i("document.default-name"),g=qr(),x=P.useMemo(()=>{function y(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function v(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const E=LJ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(I){v()&&(y()||(g("edit-link",{source:I}),t.mark("edit-link"),r({component:nJ})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(I){g("insert-embed",{source:I}),r({component:BA})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(I){g("insert-media",{source:I}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(I){g("undo",{source:I}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(I){g("redo",{source:I}),t.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-as",{format:"svg",source:I}),f(C,"svg",ba(t,S)))}},{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(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-as",{format:"png",source:I}),f(C,"png",ba(t,S)))}},{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(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-as",{format:"json",source:I}),f(C,"json",ba(t,S)))}},{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(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-all-as",{format:"svg",source:I}),f(Array.from(t.getCurrentPageShapeIds()),"svg",ba(t,S)))}},{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(I){const C=Array.from(t.getCurrentPageShapeIds().values());C.length!==0&&(g("export-all-as",{format:"png",source:I}),f(C,"png",ba(t,S)))}},{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(I){const C=Array.from(t.getCurrentPageShapeIds().values());C.length!==0&&(g("export-all-as",{format:"json",source:I}),f(C,"json",ba(t,S)))}},{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(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("copy-as",{format:"svg",source:I}),p(C,"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(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("copy-as",{format:"png",source:I}),p(C,"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(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("copy-as",{format:"json",source:I}),p(C,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(I){if(!v()||y())return;g("toggle-auto-size",{source:I}),t.mark("toggling auto size");const C=t.getSelectedShapes().filter(k=>t.isShapeOfType(k,"text")&&k.props.autoSize===!1);t.updateShapes(C.map(k=>({id:k.id,type:k.type,props:{...k.props,w:8,autoSize:!0}}))),Ke(t,C.map(k=>k.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(I){g("open-embed-link",{source:I});const C=t.getSelectedShapeIds(),k="No embed shapes selected";if(C.length!==1){console.error(k);return}const T=t.getShape(C[0]);if(!T||!t.isShapeOfType(T,"embed")){console.error(k);return}CV(T.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(I){var C,k;if(((C=t.root.getCurrent())==null?void 0:C.id)!=="zoom"&&(g("zoom-tool",{source:I}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const T=t.root.getCurrent();T&&((k=T.getCurrent())==null?void 0:k.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:T.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(I){v()&&(y()||t.batch(()=>{g("convert-to-bookmark",{source:I});const C=t.getSelectedShapes(),k=[],T=[];for(const O of C){if(!O||!t.isShapeOfType(O,"embed")||!O.props.url)continue;const _=new w(O.x,O.y);_.rot(-O.rotation),_.add(new w(O.props.w/2-300/2,O.props.h/2-320/2)),_.rot(O.rotation);const j={id:$e(),type:"bookmark",rotation:O.rotation,x:_.x,y:_.y,opacity:1,props:{url:O.props.url}};k.push(j),T.push(O.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(T),t.createShapes(k)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(I){v()&&(y()||(g("convert-to-embed",{source:I}),t.batch(()=>{const C=t.getSelectedShapeIds(),k=me(C.map(_=>t.getShape(_))),T=[],O=[];for(const _ of k){if(!t.isShapeOfType(_,"bookmark"))continue;const{url:j}=_.props,L=Ms(_.props.url);if(!L||!L.definition)continue;const{width:A,height:R}=L.definition,F=new w(_.x,_.y);F.rot(-_.rotation),F.add(new w(_.props.w/2-A/2,_.props.h/2-R/2)),F.rot(_.rotation);const W={id:$e(),type:"embed",x:F.x,y:F.y,rotation:_.rotation,props:{url:j,w:A,h:R}};T.push(W),O.push(_.id)}t.mark("convert shapes to embed"),t.deleteShapes(O),t.createShapes(T)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(I){if(!v()||y())return;g("duplicate-shapes",{source:I});const C=t.getInstanceState();let k,T;if(C.duplicateProps)k=C.duplicateProps.shapeIds,T=C.duplicateProps.offset;else{k=t.getSelectedShapeIds();const O=Z.Common(me(k.map(_=>t.getShapePageBounds(_))));T=t.getCameraOptions().isLocked?{x:20,y:20}:{x:O.width+20,y:0}}t.mark("duplicate shapes"),t.duplicateShapes(k,T),C.duplicateProps&&t.updateInstanceState({duplicateProps:{...C.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(I){v()&&(y()||(g("ungroup-shapes",{source:I}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(I){if(!v()||y())return;g("group-shapes",{source:I});const C=t.getOnlySelectedShape();C&&t.isShapeOfType(C,"group")?(t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())):(t.mark("group"),t.groupShapes(t.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(I){if(!v())return;g("remove-frame",{source:I});const C=t.getSelectedShapes();C.length>0&&C.every(k=>t.isShapeOfType(k,"frame"))&&(t.mark("remove-frame"),JQ(t,C.map(k=>k.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(I){if(!v())return;g("fit-frame-to-content",{source:I});const C=t.getOnlySelectedShape();C&&t.isShapeOfType(C,"frame")&&(t.mark("fit-frame-to-content"),tJ(t,C.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"left",source:I}),t.mark("align left");const C=t.getSelectedShapeIds();t.alignShapes(C,"left"),Ke(t,C)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"center-horizontal",source:I}),t.mark("align center horizontal");const C=t.getSelectedShapeIds();t.alignShapes(C,"center-horizontal"),Ke(t,C)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"right",source:I}),t.mark("align right");const C=t.getSelectedShapeIds();t.alignShapes(C,"right"),Ke(t,C)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"center-vertical",source:I}),t.mark("align center vertical");const C=t.getSelectedShapeIds();t.alignShapes(C,"center-vertical"),Ke(t,C)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"top",source:I}),t.mark("align top");const C=t.getSelectedShapeIds();t.alignShapes(C,"top"),Ke(t,C)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"bottom",source:I}),t.mark("align bottom");const C=t.getSelectedShapeIds();t.alignShapes(C,"bottom"),Ke(t,C)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(I){if(!v()||y())return;g("distribute-shapes",{operation:"horizontal",source:I}),t.mark("distribute horizontal");const C=t.getSelectedShapeIds();t.distributeShapes(C,"horizontal"),Ke(t,C)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(I){if(!v()||y())return;g("distribute-shapes",{operation:"vertical",source:I}),t.mark("distribute vertical");const C=t.getSelectedShapeIds();t.distributeShapes(C,"vertical"),Ke(t,C)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(I){if(!v()||y())return;g("stretch-shapes",{operation:"horizontal",source:I}),t.mark("stretch horizontal");const C=t.getSelectedShapeIds();t.stretchShapes(C,"horizontal"),Ke(t,C)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(I){if(!v()||y())return;g("stretch-shapes",{operation:"vertical",source:I}),t.mark("stretch vertical");const C=t.getSelectedShapeIds();t.stretchShapes(C,"vertical"),Ke(t,C)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(I){if(!v()||y())return;g("flip-shapes",{operation:"horizontal",source:I}),t.mark("flip horizontal");const C=t.getSelectedShapeIds();t.flipShapes(C,"horizontal"),Ke(t,C)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(I){if(!v()||y())return;g("flip-shapes",{operation:"vertical",source:I}),t.mark("flip vertical");const C=t.getSelectedShapeIds();t.flipShapes(C,"vertical"),Ke(t,C)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(I){if(!v()||y())return;g("pack-shapes",{source:I}),t.mark("pack");const C=t.getSelectedShapeIds();t.packShapes(C,t.options.adjacentShapeMargin),Ke(t,C)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(I){if(!v()||y())return;g("stack-shapes",{operation:"vertical",source:I}),t.mark("stack-vertical");const C=t.getSelectedShapeIds();t.stackShapes(C,"vertical",16),Ke(t,C)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(I){if(!v()||y())return;g("stack-shapes",{operation:"horizontal",source:I}),t.mark("stack-horizontal");const C=t.getSelectedShapeIds();t.stackShapes(C,"horizontal",16),Ke(t,C)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"toFront",source:I}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"forward",source:I}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"backward",source:I}),t.mark("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"toBack",source:I}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(I){v()&&(y()||(t.mark("cut"),c(I)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(I){v()&&(y()||d(I))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(I){var C;(C=navigator.clipboard)==null||C.read().then(k=>{h(k,I,I==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(I){t.batch(()=>{y()||(g("select-all-shapes",{source:I}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(I){v()&&(y()||(g("select-none-shapes",{source:I}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(I){v()&&(y()||(g("delete-shapes",{source:I}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(I){if(!v()||y())return;g("rotate-cw",{source:I}),t.mark("rotate-cw");const C=t.getSelectionRotation()%(Ve/2),k=Us(C,0)||Us(C,Ve/2),T=t.getSelectedShapeIds();t.rotateShapesBy(T,Ve/2-(k?0:C)),Ke(t,T)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(I){if(!v()||y())return;g("rotate-ccw",{source:I}),t.mark("rotate-ccw");const C=t.getSelectionRotation()%(Ve/2),k=Us(C,0),T=t.getSelectedShapeIds();t.rotateShapesBy(T,k?-(Ve/2):-C),Ke(t,T)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(I){g("zoom-in",{source:I}),t.zoomIn(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(I){g("zoom-out",{source:I}),t.zoomOut(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(I){g("reset-zoom",{source:I}),t.resetZoom(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(I){g("zoom-to-fit",{source:I}),t.zoomToFit({animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(I){v()&&(y()||(g("zoom-to-selection",{source:I}),t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(I){g("toggle-snap-mode",{source:I}),t.user.updateUserPreferences({isSnapMode:!t.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(I){const C=t.user.getIsDarkMode()?"light":"dark";g("color-scheme",{source:I,value:C}),t.user.updateUserPreferences({colorScheme:C})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(I){g("toggle-wrap-mode",{source:I}),t.user.updateUserPreferences({isWrapMode:!t.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(I){g("toggle-dynamic-size-mode",{source:I}),t.user.updateUserPreferences({isDynamicSizeMode:!t.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(I){g("toggle-reduce-motion",{source:I}),t.user.updateUserPreferences({animationSpeed:t.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(I){g("toggle-edge-scrolling",{source:I}),t.user.updateUserPreferences({edgeScrollSpeed:t.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(I){g("toggle-transparent",{source:I}),t.updateInstanceState({exportBackground:!t.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(I){g("toggle-tool-lock",{source:I}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(I){g("unlock-all",{source:I});const C=[];for(const k of t.getCurrentPageShapes())k.isLocked&&C.push({id:k.id,type:k.type,isLocked:!1});C.length>0&&t.updateShapes(C)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(I){t.timers.requestAnimationFrame(()=>{t.batch(()=>{g("toggle-focus-mode",{source:I}),o(),s(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(I){g("toggle-grid-mode",{source:I}),t.updateInstanceState({isGridMode:!t.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(I){g("toggle-debug-mode",{source:I}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(I){g("print",{source:I}),l()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(I){g("exit-pen-mode",{source:I}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(I){g("stop-following",{source:I}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(I){g("zoom-to-content",{source:I});const C=t.getSelectionPageBounds()??t.getCurrentPageBounds();C&&t.zoomToBounds(C,{targetZoom:Math.min(1,t.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(I){t.mark("locking"),g("toggle-lock",{source:I}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(I){const C=Qo.createId(),k=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:i("page-menu.new-page-initial-name"),id:C}),t.moveShapesToPage(k,C)}),g("new-page",{source:I})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(I){const C=sr;t.batch(()=>{t.mark("change-color"),t.isIn("select")&&t.setStyleForSelectedShapes(C,"white"),t.setStyleForNextShapes(C,"white")}),g("set-style",{source:I,id:C.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(I){const C=Wi;t.batch(()=>{t.mark("change-fill"),t.isIn("select")&&t.setStyleForSelectedShapes(C,"fill"),t.setStyleForNextShapes(C,"fill")}),g("set-style",{source:I,id:C.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async I=>{const C=t.getSelectedShapeIds();if(C.length===0)return;t.mark("flattening to image"),g("flatten-to-image",{source:I});const k=await DJ(t,C,t.options.flattenImageBoundsExpand);k!=null&&k.length&&t.setSelectedShapes(k)}}]);return e?e(t,E,void 0):E},[t,g,e,r,a,f,p,c,d,h,o,s,l,i,S]);return u.jsx(JA.Provider,{value:x,children:n})}function ie(){const e=P.useContext(JA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function yu(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const FJ=["top","right","bottom","left"],uo=Math.min,Xn=Math.max,bf=Math.round,ah=Math.floor,Zs=e=>({x:e,y:e}),NJ={left:"right",right:"left",bottom:"top",top:"bottom"},zJ={start:"end",end:"start"};function Hv(e,n,t){return Xn(e,uo(n,t))}function es(e,n){return typeof e=="function"?e(n):e}function ts(e){return e.split("-")[0]}function Fl(e){return e.split("-")[1]}function M0(e){return e==="x"?"y":"x"}function j0(e){return e==="y"?"height":"width"}function Qs(e){return["top","bottom"].includes(ts(e))?"y":"x"}function A0(e){return M0(Qs(e))}function BJ(e,n,t){t===void 0&&(t=!1);const r=Fl(e),o=A0(e),s=j0(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=Pf(i)),[i,Pf(i)]}function UJ(e){const n=Pf(e);return[Kv(e),n,Kv(n)]}function Kv(e){return e.replace(/start|end/g,n=>zJ[n])}function HJ(e,n,t){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(e){case"top":case"bottom":return t?n?o:r:n?r:o;case"left":case"right":return n?s:i;default:return[]}}function KJ(e,n,t,r){const o=Fl(e);let s=HJ(ts(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(Kv)))),s}function Pf(e){return e.replace(/left|right|bottom|top/g,n=>NJ[n])}function WJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function eO(e){return typeof e!="number"?WJ(e):{top:e,right:e,bottom:e,left:e}}function Cf(e){const{x:n,y:t,width:r,height:o}=e;return{width:r,height:o,top:t,left:n,right:n+r,bottom:t+o,x:n,y:t}}function WI(e,n,t){let{reference:r,floating:o}=e;const s=Qs(n),i=A0(n),a=j0(i),l=ts(n),c=s==="y",d=r.x+r.width/2-o.width/2,h=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:d,y:r.y-o.height};break;case"bottom":f={x:d,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:h};break;case"left":f={x:r.x-o.width,y:h};break;default:f={x:r.x,y:r.y}}switch(Fl(n)){case"start":f[i]-=p*(t&&c?-1:1);break;case"end":f[i]+=p*(t&&c?-1:1);break}return f}const GJ=async(e,n,t)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=t,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(n));let c=await i.getElementRects({reference:e,floating:n,strategy:o}),{x:d,y:h}=WI(c,r,l),p=r,f={},S=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:v,y:b,data:E,reset:I}=await y({x:d,y:h,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:n}});d=v??d,h=b??h,f={...f,[x]:{...f[x],...E}},I&&S<=50&&(S++,typeof I=="object"&&(I.placement&&(p=I.placement),I.rects&&(c=I.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):I.rects),{x:d,y:h}=WI(c,p,l)),g=-1)}return{x:d,y:h,placement:p,strategy:o,middlewareData:f}};async function Su(e,n){var t;n===void 0&&(n={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=es(n,e),S=eO(f),x=a[p?h==="floating"?"reference":"floating":h],y=Cf(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(x)))==null||t?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:d,strategy:l})),v=h==="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},I=Cf(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:b,strategy:l}):v);return{top:(y.top-I.top+S.top)/E.y,bottom:(I.bottom-y.bottom+S.bottom)/E.y,left:(y.left-I.left+S.left)/E.x,right:(I.right-y.right+S.right)/E.x}}const VJ=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=n,{element:c,padding:d=0}=es(e,n)||{};if(c==null)return{};const h=eO(d),p={x:t,y:r},f=A0(o),S=j0(f),g=await i.getDimensions(c),x=f==="y",y=x?"top":"left",v=x?"bottom":"right",b=x?"clientHeight":"clientWidth",E=s.reference[S]+s.reference[f]-p[f]-s.floating[S],I=p[f]-s.reference[f],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let k=C?C[b]:0;(!k||!await(i.isElement==null?void 0:i.isElement(C)))&&(k=a.floating[b]||s.floating[S]);const T=E/2-I/2,O=k/2-g[S]/2-1,_=uo(h[y],O),j=uo(h[v],O),L=_,A=k-g[S]-j,R=k/2-g[S]/2+T,F=Hv(L,R,A),W=!l.arrow&&Fl(o)!=null&&R!==F&&s.reference[S]/2-(R<L?_:j)-g[S]/2<0,K=W?R<L?R-L:R-A:0;return{[f]:p[f]+K,data:{[f]:F,centerOffset:R-F-K,...W&&{alignmentOffset:K}},reset:W}}}),YJ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var t,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=n,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:g=!0,...x}=es(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const y=ts(o),v=Qs(a),b=ts(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(c.floating)),I=p||(b||!g?[Pf(a)]:UJ(a)),C=S!=="none";!p&&C&&I.push(...KJ(a,g,S,E));const k=[a,...I],T=await Su(n,x),O=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&O.push(T[y]),h){const R=BJ(o,i,E);O.push(T[R[0]],T[R[1]])}if(_=[..._,{placement:o,overflows:O}],!O.every(R=>R<=0)){var j,L;const R=(((j=s.flip)==null?void 0:j.index)||0)+1,F=k[R];if(F)return{data:{index:R,overflows:_},reset:{placement:F}};let W=(L=_.filter(K=>K.overflows[0]<=0).sort((K,z)=>K.overflows[1]-z.overflows[1])[0])==null?void 0:L.placement;if(!W)switch(f){case"bestFit":{var A;const K=(A=_.filter(z=>{if(C){const U=Qs(z.placement);return U===v||U==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(U=>U>0).reduce((U,X)=>U+X,0)]).sort((z,U)=>z[1]-U[1])[0])==null?void 0:A[0];K&&(W=K);break}case"initialPlacement":W=a;break}if(o!==W)return{reset:{placement:W}}}return{}}}};function GI(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function VI(e){return FJ.some(n=>e[n]>=0)}const XJ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=es(e,n);switch(r){case"referenceHidden":{const s=await Su(n,{...o,elementContext:"reference"}),i=GI(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:VI(i)}}}case"escaped":{const s=await Su(n,{...o,altBoundary:!0}),i=GI(s,t.floating);return{data:{escapedOffsets:i,escaped:VI(i)}}}default:return{}}}}};async function qJ(e,n){const{placement:t,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=ts(t),a=Fl(t),l=Qs(t)==="y",c=["left","top"].includes(i)?-1:1,d=s&&l?-1:1,h=es(n,e);let{mainAxis:p,crossAxis:f,alignmentAxis:S}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...h};return a&&typeof S=="number"&&(f=a==="end"?S*-1:S),l?{x:f*d,y:p*c}:{x:p*c,y:f*d}}const ZJ=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var t,r;const{x:o,y:s,placement:i,middlewareData:a}=n,l=await qJ(n,e);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},QJ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:t,y:r,placement:o}=n,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:x=>{let{x:y,y:v}=x;return{x:y,y:v}}},...l}=es(e,n),c={x:t,y:r},d=await Su(n,l),h=Qs(ts(o)),p=M0(h);let f=c[p],S=c[h];if(s){const x=p==="y"?"top":"left",y=p==="y"?"bottom":"right",v=f+d[x],b=f-d[y];f=Hv(v,f,b)}if(i){const x=h==="y"?"top":"left",y=h==="y"?"bottom":"right",v=S+d[x],b=S-d[y];S=Hv(v,S,b)}const g=a.fn({...n,[p]:f,[h]:S});return{...g,data:{x:g.x-t,y:g.y-r}}}}},JJ=function(e){return e===void 0&&(e={}),{options:e,fn(n){const{x:t,y:r,placement:o,rects:s,middlewareData:i}=n,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=es(e,n),d={x:t,y:r},h=Qs(o),p=M0(h);let f=d[p],S=d[h];const g=es(a,n),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const b=p==="y"?"height":"width",E=s.reference[p]-s.floating[b]+x.mainAxis,I=s.reference[p]+s.reference[b]-x.mainAxis;f<E?f=E:f>I&&(f=I)}if(c){var y,v;const b=p==="y"?"width":"height",E=["top","left"].includes(ts(o)),I=s.reference[h]-s.floating[b]+(E&&((y=i.offset)==null?void 0:y[h])||0)+(E?0:x.crossAxis),C=s.reference[h]+s.reference[b]+(E?0:((v=i.offset)==null?void 0:v[h])||0)-(E?x.crossAxis:0);S<I?S=I:S>C&&(S=C)}return{[p]:f,[h]:S}}}},eee=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:t,rects:r,platform:o,elements:s}=n,{apply:i=()=>{},...a}=es(e,n),l=await Su(n,a),c=ts(t),d=Fl(t),h=Qs(t)==="y",{width:p,height:f}=r.floating;let S,g;c==="top"||c==="bottom"?(S=c,g=d===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(g=c,S=d==="end"?"top":"bottom");const x=f-l.top-l.bottom,y=p-l.left-l.right,v=uo(f-l[S],x),b=uo(p-l[g],y),E=!n.middlewareData.shift;let I=v,C=b;if(h?C=d||E?uo(b,y):y:I=d||E?uo(v,x):x,E&&!d){const T=Xn(l.left,0),O=Xn(l.right,0),_=Xn(l.top,0),j=Xn(l.bottom,0);h?C=p-2*(T!==0||O!==0?T+O:Xn(l.left,l.right)):I=f-2*(_!==0||j!==0?_+j:Xn(l.top,l.bottom))}await i({...n,availableWidth:C,availableHeight:I});const k=await o.getDimensions(s.floating);return p!==k.width||f!==k.height?{reset:{rects:!0}}:{}}}};function Nl(e){return tO(e)?(e.nodeName||"").toLowerCase():"#document"}function nr(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function as(e){var n;return(n=(tO(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function tO(e){return e instanceof Node||e instanceof nr(e).Node}function wo(e){return e instanceof Element||e instanceof nr(e).Element}function bo(e){return e instanceof HTMLElement||e instanceof nr(e).HTMLElement}function YI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof nr(e).ShadowRoot}function Yu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=Kr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function tee(e){return["table","td","th"].includes(Nl(e))}function kg(e){return[":popover-open",":modal"].some(n=>{try{return e.matches(n)}catch{return!1}})}function O0(e){const n=D0(),t=Kr(e);return t.transform!=="none"||t.perspective!=="none"||(t.containerType?t.containerType!=="normal":!1)||!n&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!n&&(t.filter?t.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(t.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(t.contain||"").includes(r))}function nee(e){let n=Js(e);for(;bo(n)&&!Pl(n);){if(kg(n))return null;if(O0(n))return n;n=Js(n)}return null}function D0(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Pl(e){return["html","body","#document"].includes(Nl(e))}function Kr(e){return nr(e).getComputedStyle(e)}function _g(e){return wo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Js(e){if(Nl(e)==="html")return e;const n=e.assignedSlot||e.parentNode||YI(e)&&e.host||as(e);return YI(n)?n.host:n}function nO(e){const n=Js(e);return Pl(n)?e.ownerDocument?e.ownerDocument.body:e.body:bo(n)&&Yu(n)?n:nO(n)}function vu(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=nO(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=nr(o);return s?n.concat(i,i.visualViewport||[],Yu(o)?o:[],i.frameElement&&t?vu(i.frameElement):[]):n.concat(o,vu(o,[],t))}function rO(e){const n=Kr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=bo(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=bf(t)!==s||bf(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function R0(e){return wo(e)?e:e.contextElement}function sl(e){const n=R0(e);if(!bo(n))return Zs(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=rO(n);let i=(s?bf(t.width):t.width)/r,a=(s?bf(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ree=Zs(0);function oO(e){const n=nr(e);return!D0()||!n.visualViewport?ree:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function oee(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==nr(e)?!1:n}function Zi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=R0(e);let i=Zs(1);n&&(r?wo(r)&&(i=sl(r)):i=sl(e));const a=oee(s,t,r)?oO(s):Zs(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,d=o.width/i.x,h=o.height/i.y;if(s){const p=nr(s),f=r&&wo(r)?nr(r):r;let S=p,g=S.frameElement;for(;g&&r&&f!==S;){const x=sl(g),y=g.getBoundingClientRect(),v=Kr(g),b=y.left+(g.clientLeft+parseFloat(v.paddingLeft))*x.x,E=y.top+(g.clientTop+parseFloat(v.paddingTop))*x.y;l*=x.x,c*=x.y,d*=x.x,h*=x.y,l+=b,c+=E,S=nr(g),g=S.frameElement}}return Cf({width:d,height:h,x:l,y:c})}function see(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=as(r),a=n?kg(n.floating):!1;if(r===i||a&&s)return t;let l={scrollLeft:0,scrollTop:0},c=Zs(1);const d=Zs(0),h=bo(r);if((h||!h&&!s)&&((Nl(r)!=="body"||Yu(i))&&(l=_g(r)),bo(r))){const p=Zi(r);c=sl(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-l.scrollLeft*c.x+d.x,y:t.y*c.y-l.scrollTop*c.y+d.y}}function iee(e){return Array.from(e.getClientRects())}function sO(e){return Zi(as(e)).left+_g(e).scrollLeft}function aee(e){const n=as(e),t=_g(e),r=e.ownerDocument.body,o=Xn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=Xn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+sO(e);const a=-t.scrollTop;return Kr(r).direction==="rtl"&&(i+=Xn(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function lee(e,n){const t=nr(e),r=as(e),o=t.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const c=D0();(!c||c&&n==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function cee(e,n){const t=Zi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=bo(e)?sl(e):Zs(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function XI(e,n,t){let r;if(n==="viewport")r=lee(e,t);else if(n==="document")r=aee(as(e));else if(wo(n))r=cee(n,t);else{const o=oO(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return Cf(r)}function iO(e,n){const t=Js(e);return t===n||!wo(t)||Pl(t)?!1:Kr(t).position==="fixed"||iO(t,n)}function uee(e,n){const t=n.get(e);if(t)return t;let r=vu(e,[],!1).filter(a=>wo(a)&&Nl(a)!=="body"),o=null;const s=Kr(e).position==="fixed";let i=s?Js(e):e;for(;wo(i)&&!Pl(i);){const a=Kr(i),l=O0(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Yu(i)&&!l&&iO(e,i))?r=r.filter(d=>d!==i):o=a,i=Js(i)}return n.set(e,r),r}function dee(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?kg(n)?[]:uee(n,this._c):[].concat(t),r],a=i[0],l=i.reduce((c,d)=>{const h=XI(n,d,o);return c.top=Xn(h.top,c.top),c.right=uo(h.right,c.right),c.bottom=uo(h.bottom,c.bottom),c.left=Xn(h.left,c.left),c},XI(n,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function hee(e){const{width:n,height:t}=rO(e);return{width:n,height:t}}function pee(e,n,t){const r=bo(n),o=as(n),s=t==="fixed",i=Zi(e,!0,s,n);let a={scrollLeft:0,scrollTop:0};const l=Zs(0);if(r||!r&&!s)if((Nl(n)!=="body"||Yu(o))&&(a=_g(n)),r){const h=Zi(n,!0,s,n);l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}else o&&(l.x=sO(o));const c=i.left+a.scrollLeft-l.x,d=i.top+a.scrollTop-l.y;return{x:c,y:d,width:i.width,height:i.height}}function Iy(e){return Kr(e).position==="static"}function qI(e,n){return!bo(e)||Kr(e).position==="fixed"?null:n?n(e):e.offsetParent}function aO(e,n){const t=nr(e);if(kg(e))return t;if(!bo(e)){let o=Js(e);for(;o&&!Pl(o);){if(wo(o)&&!Iy(o))return o;o=Js(o)}return t}let r=qI(e,n);for(;r&&tee(r)&&Iy(r);)r=qI(r,n);return r&&Pl(r)&&Iy(r)&&!O0(r)?t:r||nee(e)||t}const fee=async function(e){const n=this.getOffsetParent||aO,t=this.getDimensions,r=await t(e.floating);return{reference:pee(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function gee(e){return Kr(e).direction==="rtl"}const mee={convertOffsetParentRelativeRectToViewportRelativeRect:see,getDocumentElement:as,getClippingRect:dee,getOffsetParent:aO,getElementRects:fee,getClientRects:iee,getDimensions:hee,getScale:sl,isElement:wo,isRTL:gee};function yee(e,n){let t=null,r;const o=as(e);function s(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const{left:c,top:d,width:h,height:p}=e.getBoundingClientRect();if(a||n(),!h||!p)return;const f=ah(d),S=ah(o.clientWidth-(c+h)),g=ah(o.clientHeight-(d+p)),x=ah(c),v={rootMargin:-f+"px "+-S+"px "+-g+"px "+-x+"px",threshold:Xn(0,uo(1,l))||1};let b=!0;function E(I){const C=I[0].intersectionRatio;if(C!==l){if(!b)return i();C?i(!1,C):r=setTimeout(()=>{i(!1,1e-7)},1e3)}b=!1}try{t=new IntersectionObserver(E,{...v,root:o.ownerDocument})}catch{t=new IntersectionObserver(E,v)}t.observe(e)}return i(!0),s}function See(e,n,t,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=R0(e),d=o||s?[...c?vu(c):[],...vu(n)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",t,{passive:!0}),s&&y.addEventListener("resize",t)});const h=c&&a?yee(c,t):null;let p=-1,f=null;i&&(f=new ResizeObserver(y=>{let[v]=y;v&&v.target===c&&f&&(f.unobserve(n),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=f)==null||b.observe(n)})),t()}),c&&!l&&f.observe(c),f.observe(n));let S,g=l?Zi(e):null;l&&x();function x(){const y=Zi(e);g&&(y.x!==g.x||y.y!==g.y||y.width!==g.width||y.height!==g.height)&&t(),g=y,S=requestAnimationFrame(x)}return t(),()=>{var y;d.forEach(v=>{o&&v.removeEventListener("scroll",t),s&&v.removeEventListener("resize",t)}),h==null||h(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(S)}}const vee=ZJ,xee=QJ,wee=YJ,bee=eee,Pee=XJ,ZI=VJ,Cee=JJ,Iee=(e,n,t)=>{const r=new Map,o={platform:mee,...t},s={...o.platform,_c:r};return GJ(e,n,{...o,platform:s})};var pp=typeof document<"u"?P.useLayoutEffect:P.useEffect;function If(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let t,r,o;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(t=e.length,t!==n.length)return!1;for(r=t;r--!==0;)if(!If(e[r],n[r]))return!1;return!0}if(o=Object.keys(e),t=o.length,t!==Object.keys(n).length)return!1;for(r=t;r--!==0;)if(!{}.hasOwnProperty.call(n,o[r]))return!1;for(r=t;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!If(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function lO(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function QI(e,n){const t=lO(e);return Math.round(n*t)/t}function JI(e){const n=P.useRef(e);return pp(()=>{n.current=e}),n}function Eee(e){e===void 0&&(e={});const{placement:n="bottom",strategy:t="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[d,h]=P.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[p,f]=P.useState(r);If(p,r)||f(r);const[S,g]=P.useState(null),[x,y]=P.useState(null),v=P.useCallback(K=>{K!==C.current&&(C.current=K,g(K))},[]),b=P.useCallback(K=>{K!==k.current&&(k.current=K,y(K))},[]),E=s||S,I=i||x,C=P.useRef(null),k=P.useRef(null),T=P.useRef(d),O=l!=null,_=JI(l),j=JI(o),L=P.useCallback(()=>{if(!C.current||!k.current)return;const K={placement:n,strategy:t,middleware:p};j.current&&(K.platform=j.current),Iee(C.current,k.current,K).then(z=>{const U={...z,isPositioned:!0};A.current&&!If(T.current,U)&&(T.current=U,ra.flushSync(()=>{h(U)}))})},[p,n,t,j]);pp(()=>{c===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,h(K=>({...K,isPositioned:!1})))},[c]);const A=P.useRef(!1);pp(()=>(A.current=!0,()=>{A.current=!1}),[]),pp(()=>{if(E&&(C.current=E),I&&(k.current=I),E&&I){if(_.current)return _.current(E,I,L);L()}},[E,I,L,_,O]);const R=P.useMemo(()=>({reference:C,floating:k,setReference:v,setFloating:b}),[v,b]),F=P.useMemo(()=>({reference:E,floating:I}),[E,I]),W=P.useMemo(()=>{const K={position:t,left:0,top:0};if(!F.floating)return K;const z=QI(F.floating,d.x),U=QI(F.floating,d.y);return a?{...K,transform:"translate("+z+"px, "+U+"px)",...lO(F.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:z,top:U}},[t,a,F.floating,d.x,d.y]);return P.useMemo(()=>({...d,update:L,refs:R,elements:F,floatingStyles:W}),[d,L,R,F,W])}const kee=e=>{function n(t){return{}.hasOwnProperty.call(t,"current")}return{name:"arrow",options:e,fn(t){const{element:r,padding:o}=typeof e=="function"?e(t):e;return r&&n(r)?r.current!=null?ZI({element:r.current,padding:o}).fn(t):{}:r?ZI({element:r,padding:o}).fn(t):{}}}},_ee=(e,n)=>({...vee(e),options:[e,n]}),Tee=(e,n)=>({...xee(e),options:[e,n]}),Mee=(e,n)=>({...Cee(e),options:[e,n]}),jee=(e,n)=>({...wee(e),options:[e,n]}),Aee=(e,n)=>({...bee(e),options:[e,n]}),Oee=(e,n)=>({...Pee(e),options:[e,n]}),Dee=(e,n)=>({...kee(e),options:[e,n]});var Ree="Arrow",cO=P.forwardRef((e,n)=>{const{children:t,width:r=10,height:o=5,...s}=e;return u.jsx(Ce.svg,{...s,ref:n,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?t:u.jsx("polygon",{points:"0,0 30,0 15,10"})})});cO.displayName=Ree;var Lee=cO;function uO(e){const[n,t]=P.useState(void 0);return Xs(()=>{if(e){t({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 l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;t({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else t(void 0)},[e]),n}var L0="Popper",[dO,Tg]=Eo(L0),[$ee,hO]=dO(L0),pO=e=>{const{__scopePopper:n,children:t}=e,[r,o]=P.useState(null);return u.jsx($ee,{scope:n,anchor:r,onAnchorChange:o,children:t})};pO.displayName=L0;var fO="PopperAnchor",gO=P.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=hO(fO,t),i=P.useRef(null),a=Ye(n,i);return P.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:u.jsx(Ce.div,{...o,ref:a})});gO.displayName=fO;var $0="PopperContent",[Fee,Nee]=dO($0),mO=P.forwardRef((e,n)=>{var Ae,et,je,at,Ne,Kn;const{__scopePopper:t,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:f="optimized",onPlaced:S,...g}=e,x=hO($0,t),[y,v]=P.useState(null),b=Ye(n,Rt=>v(Rt)),[E,I]=P.useState(null),C=uO(E),k=(C==null?void 0:C.width)??0,T=(C==null?void 0:C.height)??0,O=r+(s!=="center"?"-"+s:""),_=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},j=Array.isArray(c)?c:[c],L=j.length>0,A={padding:_,boundary:j.filter(Bee),altBoundary:L},{refs:R,floatingStyles:F,placement:W,isPositioned:K,middlewareData:z}=Eee({strategy:"fixed",placement:O,whileElementsMounted:(...Rt)=>See(...Rt,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[_ee({mainAxis:o+T,alignmentAxis:i}),l&&Tee({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Mee():void 0,...A}),l&&jee({...A}),Aee({...A,apply:({elements:Rt,rects:Pn,availableWidth:St,availableHeight:Xt})=>{const{width:ko,height:Bl}=Pn.reference,us=Rt.floating.style;us.setProperty("--radix-popper-available-width",`${St}px`),us.setProperty("--radix-popper-available-height",`${Xt}px`),us.setProperty("--radix-popper-anchor-width",`${ko}px`),us.setProperty("--radix-popper-anchor-height",`${Bl}px`)}}),E&&Dee({element:E,padding:a}),Uee({arrowWidth:k,arrowHeight:T}),p&&Oee({strategy:"referenceHidden",...A})]}),[U,X]=vO(W),J=Vt(S);Xs(()=>{K&&(J==null||J())},[K,J]);const le=(Ae=z.arrow)==null?void 0:Ae.x,ye=(et=z.arrow)==null?void 0:et.y,Me=((je=z.arrow)==null?void 0:je.centerOffset)!==0,[ae,Ue]=P.useState();return Xs(()=>{y&&Ue(window.getComputedStyle(y).zIndex)},[y]),u.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:K?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ae,"--radix-popper-transform-origin":[(at=z.transformOrigin)==null?void 0:at.x,(Ne=z.transformOrigin)==null?void 0:Ne.y].join(" "),...((Kn=z.hide)==null?void 0:Kn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:u.jsx(Fee,{scope:t,placedSide:U,onArrowChange:I,arrowX:le,arrowY:ye,shouldHideArrow:Me,children:u.jsx(Ce.div,{"data-side":U,"data-align":X,...g,ref:b,style:{...g.style,animation:K?void 0:"none"}})})})});mO.displayName=$0;var yO="PopperArrow",zee={top:"bottom",right:"left",bottom:"top",left:"right"},SO=P.forwardRef(function(n,t){const{__scopePopper:r,...o}=n,s=Nee(yO,r),i=zee[s.placedSide];return u.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:u.jsx(Lee,{...o,ref:t,style:{...o.style,display:"block"}})})});SO.displayName=yO;function Bee(e){return e!==null}var Uee=e=>({name:"transformOrigin",options:e,fn(n){var x,y,v;const{placement:t,rects:r,middlewareData:o}=n,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,d]=vO(t),h={start:"0%",center:"50%",end:"100%"}[d],p=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((v=o.arrow)==null?void 0:v.y)??0)+l/2;let S="",g="";return c==="bottom"?(S=i?h:`${p}px`,g=`${-l}px`):c==="top"?(S=i?h:`${p}px`,g=`${r.floating.height+l}px`):c==="right"?(S=`${-l}px`,g=i?h:`${f}px`):c==="left"&&(S=`${r.floating.width+l}px`,g=i?h:`${f}px`),{data:{x:S,y:g}}}});function vO(e){const[n,t="center"]=e.split("-");return[n,t]}var F0=pO,N0=gO,xO=mO,wO=SO,z0="Popover",[bO,Vie]=Eo(z0,[Tg]),Xu=Tg(),[Hee,ci]=bO(z0),PO=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Xu(n),l=P.useRef(null),[c,d]=P.useState(!1),[h=!1,p]=li({prop:r,defaultProp:o,onChange:s});return u.jsx(F0,{...a,children:u.jsx(Hee,{scope:n,contentId:Go(),triggerRef:l,open:h,onOpenChange:p,onOpenToggle:P.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:c,onCustomAnchorAdd:P.useCallback(()=>d(!0),[]),onCustomAnchorRemove:P.useCallback(()=>d(!1),[]),modal:i,children:t})})};PO.displayName=z0;var CO="PopoverAnchor",Kee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(CO,t),s=Xu(t),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return P.useEffect(()=>(i(),()=>a()),[i,a]),u.jsx(N0,{...s,...r,ref:n})});Kee.displayName=CO;var IO="PopoverTrigger",EO=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(IO,t),s=Xu(t),i=Ye(n,o.triggerRef),a=u.jsx(Ce.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":jO(o.open),...r,ref:i,onClick:re(e.onClick,o.onOpenToggle)});return o.hasCustomAnchor?a:u.jsx(N0,{asChild:!0,...s,children:a})});EO.displayName=IO;var B0="PopoverPortal",[Wee,Gee]=bO(B0,{forceMount:void 0}),kO=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=ci(B0,n);return u.jsx(Wee,{scope:n,forceMount:t,children:u.jsx(Yr,{present:t||s.open,children:u.jsx(Vu,{asChild:!0,container:o,children:r})})})};kO.displayName=B0;var Cl="PopoverContent",_O=P.forwardRef((e,n)=>{const t=Gee(Cl,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=ci(Cl,e.__scopePopover);return u.jsx(Yr,{present:r||s.open,children:s.modal?u.jsx(Vee,{...o,ref:n}):u.jsx(Yee,{...o,ref:n})})});_O.displayName=Cl;var Vee=P.forwardRef((e,n)=>{const t=ci(Cl,e.__scopePopover),r=P.useRef(null),o=Ye(n,r),s=P.useRef(!1);return P.useEffect(()=>{const i=r.current;if(i)return S0(i)},[]),u.jsx(vg,{as:Xi,allowPinchZoom:!0,children:u.jsx(TO,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:re(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:re(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:re(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),Yee=P.forwardRef((e,n)=>{const t=ci(Cl,e.__scopePopover),r=P.useRef(!1),o=P.useRef(!1);return u.jsx(TO,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=t.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),TO=P.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:d,...h}=e,p=ci(Cl,t),f=Xu(t);return y0(),u.jsx(yg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:u.jsx(Gu,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:d,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:u.jsx(xO,{"data-state":jO(p.open),role:"dialog",id:p.contentId,...f,...h,ref:n,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),MO="PopoverClose",Xee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(MO,t);return u.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,()=>o.onOpenChange(!1))})});Xee.displayName=MO;var qee="PopoverArrow",Zee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Xu(t);return u.jsx(wO,{...o,...r,ref:n})});Zee.displayName=qee;function jO(e){return e?"open":"closed"}var Qee=PO,Jee=EO,ete=kO,tte=_O;function ui(e,n){const t=B(),r=P.useRef(!1),o=qr(),s=P.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(l=>!l.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=G("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return P.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),t.addOpenMenu(e)),()=>{r.current&&(t.deleteOpenMenu(e),t.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),t.deleteOpenMenu(a))}),r.current=!1)}),[t,e,o]),[i,s]}function U0({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=ui(e,t);return u.jsx(Qee,{onOpenChange:s,open:r||o,children:u.jsx("div",{className:"tlui-popover",children:n})})}function H0({children:e}){return u.jsx(Jee,{asChild:!0,dir:"ltr",children:e})}function K0({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=un();return u.jsx(ete,{container:s,children:u.jsx(tte,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const AO=P.createContext(null);function Mg(){const e=P.useContext(AO);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function Er({type:e,sourceId:n,children:t}){return u.jsx(AO.Provider,{value:{type:e,sourceId:n},children:t})}function nte(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const o=Mn(e,r);if(o.start||o.end)return!1}return!0})}const OO=()=>{const e=B();return G("threeStackableItems",()=>nte(e).length>2,[e])},ls=()=>{const e=B();return G("isInSelectState",()=>e.isIn("select"),[e])},DO=()=>{const e=B();return G("allow group",()=>{const n=e.getSelectedShapes();if(n.length<2)return!1;for(const t of n)if(e.isShapeOfType(t,"arrow")){const r=Mn(e,t);if(r.start&&!n.some(o=>o.id===r.start.toId)||r.end&&!n.some(o=>o.id===r.end.toId))return!1}return!0},[e])},RO=()=>{const e=B();return G("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},rte=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function ote(e,n){const t=B();return G("selectedShapes",()=>t.getSelectedShapes().length>=e,[t,e,n])}function bn(e,n){const t=B();return G("selectedShapes",()=>{const r=t.getSelectedShapes().filter(o=>!t.isShapeOrAncestorLocked(o)).length;return e===void 0?r:r>=e},[t])}function ste(){const e=B();return G("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}function LO(){const e=B();return G("hasLinkShapeSelected",()=>{const n=e.getOnlySelectedShape();return!!(n&&n.type!=="embed"&&"url"in n.props&&!n.isLocked)},[e])}function ite(){const e=B();return G("onlyFlippableShape",()=>{const n=e.getOnlySelectedShape();return n&&(e.isShapeOfType(n,"group")||e.isShapeOfType(n,"arrow")||e.isShapeOfType(n,"line")||e.isShapeOfType(n,"draw"))},[e])}function $O(){const e=B();return G("useCanRedo",()=>e.getCanRedo(),[e])}function FO(){const e=B();return G("useCanUndo",()=>e.getCanUndo(),[e])}var ate=P.createContext(void 0);function W0(e){const n=P.useContext(ate);return e||n||"ltr"}var Ey="rovingFocusGroup.onEntryFocus",lte={bubbles:!1,cancelable:!0},jg="RovingFocusGroup",[Wv,NO,cte]=xg(jg),[ute,zO]=Eo(jg,[cte]),[dte,hte]=ute(jg),BO=P.forwardRef((e,n)=>u.jsx(Wv.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(Wv.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(pte,{...e,ref:n})})}));BO.displayName=jg;var pte=P.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:d=!1,...h}=e,p=P.useRef(null),f=Ye(n,p),S=W0(s),[g=null,x]=li({prop:i,defaultProp:a,onChange:l}),[y,v]=P.useState(!1),b=Vt(c),E=NO(t),I=P.useRef(!1),[C,k]=P.useState(0);return P.useEffect(()=>{const T=p.current;if(T)return T.addEventListener(Ey,b),()=>T.removeEventListener(Ey,b)},[b]),u.jsx(dte,{scope:t,orientation:r,dir:S,loop:o,currentTabStopId:g,onItemFocus:P.useCallback(T=>x(T),[x]),onItemShiftTab:P.useCallback(()=>v(!0),[]),onFocusableItemAdd:P.useCallback(()=>k(T=>T+1),[]),onFocusableItemRemove:P.useCallback(()=>k(T=>T-1),[]),children:u.jsx(Ce.div,{tabIndex:y||C===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...e.style},onMouseDown:re(e.onMouseDown,()=>{I.current=!0}),onFocus:re(e.onFocus,T=>{const O=!I.current;if(T.target===T.currentTarget&&O&&!y){const _=new CustomEvent(Ey,lte);if(T.currentTarget.dispatchEvent(_),!_.defaultPrevented){const j=E().filter(W=>W.focusable),L=j.find(W=>W.active),A=j.find(W=>W.id===g),F=[L,A,...j].filter(Boolean).map(W=>W.ref.current);KO(F,d)}}I.current=!1}),onBlur:re(e.onBlur,()=>v(!1))})})}),UO="RovingFocusGroupItem",HO=P.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Go(),l=s||a,c=hte(UO,t),d=c.currentTabStopId===l,h=NO(t),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return P.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),u.jsx(Wv.ItemSlot,{scope:t,id:l,focusable:r,active:o,children:u.jsx(Ce.span,{tabIndex:d?0:-1,"data-orientation":c.orientation,...i,ref:n,onMouseDown:re(e.onMouseDown,S=>{r?c.onItemFocus(l):S.preventDefault()}),onFocus:re(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:re(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){c.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const g=mte(S,c.orientation,c.dir);if(g!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let y=h().filter(v=>v.focusable).map(v=>v.ref.current);if(g==="last")y.reverse();else if(g==="prev"||g==="next"){g==="prev"&&y.reverse();const v=y.indexOf(S.currentTarget);y=c.loop?yte(y,v+1):y.slice(v+1)}setTimeout(()=>KO(y))}})})})});HO.displayName=UO;var fte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function gte(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function mte(e,n,t){const r=gte(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fte[r]}function KO(e,n=!1){const t=document.activeElement;for(const r of e)if(r===t||(r.focus({preventScroll:n}),document.activeElement!==t))return}function yte(e,n){return e.map((t,r)=>e[(n+r)%e.length])}var Ste=BO,vte=HO,Gv=["Enter"," "],xte=["ArrowDown","PageUp","Home"],WO=["ArrowUp","PageDown","End"],wte=[...xte,...WO],bte={ltr:[...Gv,"ArrowRight"],rtl:[...Gv,"ArrowLeft"]},Pte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},qu="Menu",[xu,Cte,Ite]=xg(qu),[ca,Ag]=Eo(qu,[Ite,Tg,zO]),Zu=Tg(),GO=zO(),[VO,di]=ca(qu),[Ete,Qu]=ca(qu),YO=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Zu(n),[l,c]=P.useState(null),d=P.useRef(!1),h=Vt(s),p=W0(o);return P.useEffect(()=>{const f=()=>{d.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>d.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),u.jsx(F0,{...a,children:u.jsx(VO,{scope:n,open:t,onOpenChange:h,content:l,onContentChange:c,children:u.jsx(Ete,{scope:n,onClose:P.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:d,dir:p,modal:i,children:r})})})};YO.displayName=qu;var kte="MenuAnchor",G0=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=Zu(t);return u.jsx(N0,{...o,...r,ref:n})});G0.displayName=kte;var V0="MenuPortal",[_te,XO]=ca(V0,{forceMount:void 0}),qO=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=di(V0,n);return u.jsx(_te,{scope:n,forceMount:t,children:u.jsx(Yr,{present:t||s.open,children:u.jsx(Vu,{asChild:!0,container:o,children:r})})})};qO.displayName=V0;var Pr="MenuContent",[Tte,Y0]=ca(Pr),ZO=P.forwardRef((e,n)=>{const t=XO(Pr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=di(Pr,e.__scopeMenu),i=Qu(Pr,e.__scopeMenu);return u.jsx(xu.Provider,{scope:e.__scopeMenu,children:u.jsx(Yr,{present:r||s.open,children:u.jsx(xu.Slot,{scope:e.__scopeMenu,children:i.modal?u.jsx(Mte,{...o,ref:n}):u.jsx(jte,{...o,ref:n})})})})}),Mte=P.forwardRef((e,n)=>{const t=di(Pr,e.__scopeMenu),r=P.useRef(null),o=Ye(n,r);return P.useEffect(()=>{const s=r.current;if(s)return S0(s)},[]),u.jsx(X0,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:re(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),jte=P.forwardRef((e,n)=>{const t=di(Pr,e.__scopeMenu);return u.jsx(X0,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),X0=P.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:p,onDismiss:f,disableOutsideScroll:S,...g}=e,x=di(Pr,t),y=Qu(Pr,t),v=Zu(t),b=GO(t),E=Cte(t),[I,C]=P.useState(null),k=P.useRef(null),T=Ye(n,k,x.onContentChange),O=P.useRef(0),_=P.useRef(""),j=P.useRef(0),L=P.useRef(null),A=P.useRef("right"),R=P.useRef(0),F=S?vg:P.Fragment,W=S?{as:Xi,allowPinchZoom:!0}:void 0,K=U=>{var Ae,et;const X=_.current+U,J=E().filter(je=>!je.disabled),le=document.activeElement,ye=(Ae=J.find(je=>je.ref.current===le))==null?void 0:Ae.textValue,Me=J.map(je=>je.textValue),ae=Hte(Me,X,ye),Ue=(et=J.find(je=>je.textValue===ae))==null?void 0:et.ref.current;(function je(at){_.current=at,window.clearTimeout(O.current),at!==""&&(O.current=window.setTimeout(()=>je(""),1e3))})(X),Ue&&setTimeout(()=>Ue.focus())};P.useEffect(()=>()=>window.clearTimeout(O.current),[]),y0();const z=P.useCallback(U=>{var J,le;return A.current===((J=L.current)==null?void 0:J.side)&&Wte(U,(le=L.current)==null?void 0:le.area)},[]);return u.jsx(Tte,{scope:t,searchRef:_,onItemEnter:P.useCallback(U=>{z(U)&&U.preventDefault()},[z]),onItemLeave:P.useCallback(U=>{var X;z(U)||((X=k.current)==null||X.focus(),C(null))},[z]),onTriggerLeave:P.useCallback(U=>{z(U)&&U.preventDefault()},[z]),pointerGraceTimerRef:j,onPointerGraceIntentChange:P.useCallback(U=>{L.current=U},[]),children:u.jsx(F,{...W,children:u.jsx(yg,{asChild:!0,trapped:o,onMountAutoFocus:re(s,U=>{var X;U.preventDefault(),(X=k.current)==null||X.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:u.jsx(Gu,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:u.jsx(Ste,{asChild:!0,...b,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:C,onEntryFocus:re(l,U=>{y.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(xO,{role:"menu","aria-orientation":"vertical","data-state":fD(x.open),"data-radix-menu-content":"",dir:y.dir,...v,...g,ref:T,style:{outline:"none",...g.style},onKeyDown:re(g.onKeyDown,U=>{const J=U.target.closest("[data-radix-menu-content]")===U.currentTarget,le=U.ctrlKey||U.altKey||U.metaKey,ye=U.key.length===1;J&&(U.key==="Tab"&&U.preventDefault(),!le&&ye&&K(U.key));const Me=k.current;if(U.target!==Me||!wte.includes(U.key))return;U.preventDefault();const Ue=E().filter(Ae=>!Ae.disabled).map(Ae=>Ae.ref.current);WO.includes(U.key)&&Ue.reverse(),Bte(Ue)}),onBlur:re(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(O.current),_.current="")}),onPointerMove:re(e.onPointerMove,wu(U=>{const X=U.target,J=R.current!==U.clientX;if(U.currentTarget.contains(X)&&J){const le=U.clientX>R.current?"right":"left";A.current=le,R.current=U.clientX}}))})})})})})})});ZO.displayName=Pr;var Ate="MenuGroup",q0=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return u.jsx(Ce.div,{role:"group",...r,ref:n})});q0.displayName=Ate;var Ote="MenuLabel",QO=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return u.jsx(Ce.div,{...r,ref:n})});QO.displayName=Ote;var Ef="MenuItem",eE="menu.itemSelect",Og=P.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=P.useRef(null),i=Qu(Ef,e.__scopeMenu),a=Y0(Ef,e.__scopeMenu),l=Ye(n,s),c=P.useRef(!1),d=()=>{const h=s.current;if(!t&&h){const p=new CustomEvent(eE,{bubbles:!0,cancelable:!0});h.addEventListener(eE,f=>r==null?void 0:r(f),{once:!0}),m0(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return u.jsx(JO,{...o,ref:l,disabled:t,onClick:re(e.onClick,d),onPointerDown:h=>{var p;(p=e.onPointerDown)==null||p.call(e,h),c.current=!0},onPointerUp:re(e.onPointerUp,h=>{var p;c.current||(p=h.currentTarget)==null||p.click()}),onKeyDown:re(e.onKeyDown,h=>{const p=a.searchRef.current!=="";t||p&&h.key===" "||Gv.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Og.displayName=Ef;var JO=P.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=Y0(Ef,t),a=GO(t),l=P.useRef(null),c=Ye(n,l),[d,h]=P.useState(!1),[p,f]=P.useState("");return P.useEffect(()=>{const S=l.current;S&&f((S.textContent??"").trim())},[s.children]),u.jsx(xu.ItemSlot,{scope:t,disabled:r,textValue:o??p,children:u.jsx(vte,{asChild:!0,...a,focusable:!r,children:u.jsx(Ce.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:re(e.onPointerMove,wu(S=>{r?i.onItemLeave(S):(i.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:re(e.onPointerLeave,wu(S=>i.onItemLeave(S))),onFocus:re(e.onFocus,()=>h(!0)),onBlur:re(e.onBlur,()=>h(!1))})})})}),Dte="MenuCheckboxItem",eD=P.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return u.jsx(sD,{scope:e.__scopeMenu,checked:t,children:u.jsx(Og,{role:"menuitemcheckbox","aria-checked":kf(t)?"mixed":t,...o,ref:n,"data-state":J0(t),onSelect:re(o.onSelect,()=>r==null?void 0:r(kf(t)?!0:!t),{checkForDefaultPrevented:!1})})})});eD.displayName=Dte;var tD="MenuRadioGroup",[Rte,Lte]=ca(tD,{value:void 0,onValueChange:()=>{}}),nD=P.forwardRef((e,n)=>{const{value:t,onValueChange:r,...o}=e,s=Vt(r);return u.jsx(Rte,{scope:e.__scopeMenu,value:t,onValueChange:s,children:u.jsx(q0,{...o,ref:n})})});nD.displayName=tD;var rD="MenuRadioItem",oD=P.forwardRef((e,n)=>{const{value:t,...r}=e,o=Lte(rD,e.__scopeMenu),s=t===o.value;return u.jsx(sD,{scope:e.__scopeMenu,checked:s,children:u.jsx(Og,{role:"menuitemradio","aria-checked":s,...r,ref:n,"data-state":J0(s),onSelect:re(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,t)},{checkForDefaultPrevented:!1})})})});oD.displayName=rD;var Z0="MenuItemIndicator",[sD,$te]=ca(Z0,{checked:!1}),iD=P.forwardRef((e,n)=>{const{__scopeMenu:t,forceMount:r,...o}=e,s=$te(Z0,t);return u.jsx(Yr,{present:r||kf(s.checked)||s.checked===!0,children:u.jsx(Ce.span,{...o,ref:n,"data-state":J0(s.checked)})})});iD.displayName=Z0;var Fte="MenuSeparator",aD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return u.jsx(Ce.div,{role:"separator","aria-orientation":"horizontal",...r,ref:n})});aD.displayName=Fte;var Nte="MenuArrow",lD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=Zu(t);return u.jsx(wO,{...o,...r,ref:n})});lD.displayName=Nte;var Q0="MenuSub",[zte,cD]=ca(Q0),uD=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=di(Q0,n),i=Zu(n),[a,l]=P.useState(null),[c,d]=P.useState(null),h=Vt(o);return P.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),u.jsx(F0,{...i,children:u.jsx(VO,{scope:n,open:r,onOpenChange:h,content:c,onContentChange:d,children:u.jsx(zte,{scope:n,contentId:Go(),triggerId:Go(),trigger:a,onTriggerChange:l,children:t})})})};uD.displayName=Q0;var kc="MenuSubTrigger",dD=P.forwardRef((e,n)=>{const t=di(kc,e.__scopeMenu),r=Qu(kc,e.__scopeMenu),o=cD(kc,e.__scopeMenu),s=Y0(kc,e.__scopeMenu),i=P.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},d=P.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return P.useEffect(()=>d,[d]),P.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),u.jsx(G0,{asChild:!0,...c,children:u.jsx(JO,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":fD(t.open),...e,ref:mg(n,o.onTriggerChange),onClick:h=>{var p;(p=e.onClick)==null||p.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:re(e.onPointerMove,wu(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),d()},100))})),onPointerLeave:re(e.onPointerLeave,wu(h=>{var f,S;d();const p=(f=t.content)==null?void 0:f.getBoundingClientRect();if(p){const g=(S=t.content)==null?void 0:S.dataset.side,x=g==="right",y=x?-5:5,v=p[x?"left":"right"],b=p[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+y,y:h.clientY},{x:v,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x:v,y:p.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:re(e.onKeyDown,h=>{var f;const p=s.searchRef.current!=="";e.disabled||p&&h.key===" "||bte[r.dir].includes(h.key)&&(t.onOpenChange(!0),(f=t.content)==null||f.focus(),h.preventDefault())})})})});dD.displayName=kc;var hD="MenuSubContent",pD=P.forwardRef((e,n)=>{const t=XO(Pr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=di(Pr,e.__scopeMenu),i=Qu(Pr,e.__scopeMenu),a=cD(hD,e.__scopeMenu),l=P.useRef(null),c=Ye(n,l);return u.jsx(xu.Provider,{scope:e.__scopeMenu,children:u.jsx(Yr,{present:r||s.open,children:u.jsx(xu.Slot,{scope:e.__scopeMenu,children:u.jsx(X0,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:re(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:re(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:re(e.onKeyDown,d=>{var f;const h=d.currentTarget.contains(d.target),p=Pte[i.dir].includes(d.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),d.preventDefault())})})})})})});pD.displayName=hD;function fD(e){return e?"open":"closed"}function kf(e){return e==="indeterminate"}function J0(e){return kf(e)?"indeterminate":e?"checked":"unchecked"}function Bte(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function Ute(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function Hte(e,n,t){const o=n.length>1&&Array.from(n).every(c=>c===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=Ute(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==t));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==t?l:void 0}function Kte(e,n){const{x:t,y:r}=e;let o=!1;for(let s=0,i=n.length-1;s<n.length;i=s++){const a=n[s].x,l=n[s].y,c=n[i].x,d=n[i].y;l>r!=d>r&&t<(c-a)*(r-l)/(d-l)+a&&(o=!o)}return o}function Wte(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return Kte(t,n)}function wu(e){return n=>n.pointerType==="mouse"?e(n):void 0}var gD=YO,mD=G0,yD=qO,SD=ZO,vD=q0,xD=QO,wD=Og,bD=eD,PD=nD,CD=oD,ID=iD,ED=aD,kD=lD,_D=uD,TD=dD,MD=pD,eb="ContextMenu",[Gte,Yie]=Eo(eb,[Ag]),dn=Ag(),[Vte,jD]=Gte(eb),AD=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=P.useState(!1),l=dn(n),c=Vt(r),d=P.useCallback(h=>{a(h),c(h)},[c]);return u.jsx(Vte,{scope:n,open:i,onOpenChange:d,modal:s,children:u.jsx(gD,{...l,dir:o,open:i,onOpenChange:d,modal:s,children:t})})};AD.displayName=eb;var OD="ContextMenuTrigger",DD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=jD(OD,t),i=dn(t),a=P.useRef({x:0,y:0}),l=P.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=P.useRef(0),d=P.useCallback(()=>window.clearTimeout(c.current),[]),h=p=>{a.current={x:p.clientX,y:p.clientY},s.onOpenChange(!0)};return P.useEffect(()=>d,[d]),P.useEffect(()=>void(r&&d()),[r,d]),u.jsxs(u.Fragment,{children:[u.jsx(mD,{...i,virtualRef:l}),u.jsx(Ce.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...o,ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:re(e.onContextMenu,p=>{d(),h(p),p.preventDefault()}),onPointerDown:r?e.onPointerDown:re(e.onPointerDown,lh(p=>{d(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?e.onPointerMove:re(e.onPointerMove,lh(d)),onPointerCancel:r?e.onPointerCancel:re(e.onPointerCancel,lh(d)),onPointerUp:r?e.onPointerUp:re(e.onPointerUp,lh(d))})]})});DD.displayName=OD;var Yte="ContextMenuPortal",tb=e=>{const{__scopeContextMenu:n,...t}=e,r=dn(n);return u.jsx(yD,{...r,...t})};tb.displayName=Yte;var RD="ContextMenuContent",LD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=jD(RD,t),s=dn(t),i=P.useRef(!1);return u.jsx(SD,{...s,...r,ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)==null||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)==null||l.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)"}})});LD.displayName=RD;var Xte="ContextMenuGroup",$D=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(vD,{...o,...r,ref:n})});$D.displayName=Xte;var qte="ContextMenuLabel",Zte=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(xD,{...o,...r,ref:n})});Zte.displayName=qte;var Qte="ContextMenuItem",FD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(wD,{...o,...r,ref:n})});FD.displayName=Qte;var Jte="ContextMenuCheckboxItem",ND=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(bD,{...o,...r,ref:n})});ND.displayName=Jte;var ene="ContextMenuRadioGroup",tne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(PD,{...o,...r,ref:n})});tne.displayName=ene;var nne="ContextMenuRadioItem",rne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(CD,{...o,...r,ref:n})});rne.displayName=nne;var one="ContextMenuItemIndicator",sne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(ID,{...o,...r,ref:n})});sne.displayName=one;var ine="ContextMenuSeparator",ane=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(ED,{...o,...r,ref:n})});ane.displayName=ine;var lne="ContextMenuArrow",cne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(kD,{...o,...r,ref:n})});cne.displayName=lne;var une="ContextMenuSub",zD=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=dn(n),[a,l]=li({prop:o,defaultProp:s,onChange:r});return u.jsx(_D,{...i,open:a,onOpenChange:l,children:t})};zD.displayName=une;var dne="ContextMenuSubTrigger",BD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(TD,{...o,...r,ref:n})});BD.displayName=dne;var hne="ContextMenuSubContent",UD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return u.jsx(MD,{...o,...r,ref:n,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)"}})});UD.displayName=hne;function lh(e){return n=>n.pointerType!=="mouse"?e(n):void 0}var pne=AD,fne=DD,gne=tb,mne=LD,yne=ND;const HD=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Sne=HD?"⌘":"Ctrl",vne=HD?"⌥":"Alt";function KD(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,Sne).replace(/\?/g,vne).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Vv(e){return"— "+KD(e).join(" ")}function xne(e){return u.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:u.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[u.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),u.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:u.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}var nb="DropdownMenu",[wne,Xie]=Eo(nb,[Ag]),hn=Ag(),[bne,WD]=wne(nb),GD=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=hn(n),c=P.useRef(null),[d=!1,h]=li({prop:o,defaultProp:s,onChange:i});return u.jsx(bne,{scope:n,triggerId:Go(),triggerRef:c,contentId:Go(),open:d,onOpenChange:h,onOpenToggle:P.useCallback(()=>h(p=>!p),[h]),modal:a,children:u.jsx(gD,{...l,open:d,onOpenChange:h,dir:r,modal:a,children:t})})};GD.displayName=nb;var VD="DropdownMenuTrigger",YD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=WD(VD,t),i=hn(t);return u.jsx(mD,{asChild:!0,...i,children:u.jsx(Ce.button,{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:mg(n,s.triggerRef),onPointerDown:re(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:re(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});YD.displayName=VD;var Pne="DropdownMenuPortal",XD=e=>{const{__scopeDropdownMenu:n,...t}=e,r=hn(n);return u.jsx(yD,{...r,...t})};XD.displayName=Pne;var qD="DropdownMenuContent",ZD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=WD(qD,t),s=hn(t),i=P.useRef(!1);return u.jsx(SD,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:n,onCloseAutoFocus:re(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:re(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,d=l.button===2||c;(!o.modal||d)&&(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)"}})});ZD.displayName=qD;var Cne="DropdownMenuGroup",QD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(vD,{...o,...r,ref:n})});QD.displayName=Cne;var Ine="DropdownMenuLabel",Ene=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(xD,{...o,...r,ref:n})});Ene.displayName=Ine;var kne="DropdownMenuItem",JD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(wD,{...o,...r,ref:n})});JD.displayName=kne;var _ne="DropdownMenuCheckboxItem",eR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(bD,{...o,...r,ref:n})});eR.displayName=_ne;var Tne="DropdownMenuRadioGroup",Mne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(PD,{...o,...r,ref:n})});Mne.displayName=Tne;var jne="DropdownMenuRadioItem",Ane=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(CD,{...o,...r,ref:n})});Ane.displayName=jne;var One="DropdownMenuItemIndicator",Dne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(ID,{...o,...r,ref:n})});Dne.displayName=One;var Rne="DropdownMenuSeparator",Lne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(ED,{...o,...r,ref:n})});Lne.displayName=Rne;var $ne="DropdownMenuArrow",Fne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(kD,{...o,...r,ref:n})});Fne.displayName=$ne;var Nne=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=hn(n),[a=!1,l]=li({prop:r,defaultProp:s,onChange:o});return u.jsx(_D,{...i,open:a,onOpenChange:l,children:t})},zne="DropdownMenuSubTrigger",tR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(TD,{...o,...r,ref:n})});tR.displayName=zne;var Bne="DropdownMenuSubContent",nR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return u.jsx(MD,{...o,...r,ref:n,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)"}})});nR.displayName=Bne;var rb=GD,ob=YD,Dg=XD,sb=ZD,Une=QD,Hne=JD,Kne=eR,Wne=Nne,Gne=tR,Vne=nR;function Qi({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=ui(e);return u.jsx(rb,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function Ji({children:e,...n}){return u.jsx(ob,{dir:"ltr",asChild:!0,onTouchEnd:t=>Ee(t),...n,children:e})}function ea({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=un();return u.jsx(Dg,{container:s,children:u.jsx(sb,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function Yne({id:e,children:n}){const[t,r]=ui(e);return u.jsx(Wne,{open:t,onOpenChange:r,children:n})}function Xne({id:e,label:n,title:t,disabled:r}){return u.jsx(Gne,{dir:"ltr",asChild:!0,disabled:r,children:u.jsxs(he,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[u.jsx(bt,{children:n}),u.jsx(be,{icon:"chevron-right",small:!0})]})})}function qne({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=un();return u.jsx(Dg,{container:s,children:u.jsx(Vne,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function Zne({children:e}){return u.jsx(Une,{dir:"ltr",className:"tlui-menu__group",children:e})}function bu({noClose:e,children:n}){return u.jsx(Hne,{dir:"ltr",asChild:!0,onClick:e?Ee:void 0,children:n})}function Hc({children:e,visibleOnMobileLayout:n=!1}){const t=Un();return!n&&t<yt.MOBILE?null:u.jsx("kbd",{className:"tlui-kbd",children:KD(e).map((r,o)=>u.jsx("span",{children:r},o))})}function H({disabled:e=!1,spinner:n=!1,readonlyOk:t=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:l,isSelected:c}){const{type:d,sourceId:h}=Mg(),p=Te(),[f,S]=P.useState(!1);if(is()&&!t)return null;const x=yu(s,d),y=o?Vv(o):void 0,v=x?p(x):void 0,b=v&&y?`${v} ${y}`:v;switch(d){case"menu":return u.jsx(bu,{children:u.jsxs(he,{type:"menu","data-testid":`${h}.${r}`,disabled:e,title:b,onClick:E=>{l&&Ee(E),f?S(!1):a(h)},children:[u.jsx(bt,{children:v}),o&&u.jsx(Hc,{children:o})]})});case"context-menu":return e?null:u.jsxs(FD,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:E=>{l&&Ee(E),f?S(!1):a(h)},children:[u.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&u.jsx(Hc,{children:o}),n&&u.jsx(xne,{})]});case"panel":return u.jsxs(he,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:e,onClick:()=>a(h),children:[u.jsx(bt,{children:v}),i&&u.jsx(be,{icon:i})]});case"small-icons":case"icons":return u.jsx(he,{"data-testid":`${h}.${r}`,type:"icon",title:b,disabled:e,onClick:()=>a(h),children:u.jsx(be,{icon:i,small:d==="small-icons"})});case"keyboard-shortcuts":return o?u.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${h}.${r}`,children:[u.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),u.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:u.jsx(Hc,{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 u.jsxs(he,{type:"low",onClick:()=>a(h),children:[u.jsx(be,{icon:i}),u.jsx(bt,{children:v})]});case"toolbar":return u.jsx(he,{type:"tool","data-testid":`tools.${r}`,"aria-label":x,"data-value":r,onClick:()=>a("toolbar"),title:b,onTouchStart:E=>{Ee(E),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:u.jsx(be,{icon:i})});case"toolbar-overflow":return u.jsx(bu,{"aria-label":s,children:u.jsx(he,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:b,role:"radio","aria-checked":c?"true":"false","data-value":r,children:u.jsx(be,{icon:i})})});default:throw an(d)}}function Qne(){return u.jsxs(u.Fragment,{children:[u.jsx(Jne,{}),u.jsx(ere,{}),u.jsx(tre,{}),u.jsx(nre,{}),u.jsx(rre,{}),u.jsx(ire,{}),u.jsx(are,{}),u.jsx(lre,{})]})}function Jne(){const e=ie(),n=bn(2),t=ls(),r=n&&t;return u.jsxs(u.Fragment,{children:[u.jsx(H,{...e["align-left"],disabled:!r}),u.jsx(H,{...e["align-center-horizontal"],disabled:!r}),u.jsx(H,{...e["align-right"],disabled:!r}),u.jsx(H,{...e["stretch-horizontal"],disabled:!r}),u.jsx(H,{...e["align-top"],disabled:!r}),u.jsx(H,{...e["align-center-vertical"],disabled:!r}),u.jsx(H,{...e["align-bottom"],disabled:!r}),u.jsx(H,{...e["stretch-vertical"],disabled:!r})]})}function ere(){const e=ie(),n=bn(3),t=ls(),r=n&&t;return u.jsxs(u.Fragment,{children:[u.jsx(H,{...e["distribute-horizontal"],disabled:!r}),u.jsx(H,{...e["distribute-vertical"],disabled:!r})]})}function tre(){const e=ie(),n=OO(),t=ls(),r=n&&t;return u.jsxs(u.Fragment,{children:[u.jsx(H,{...e["stack-horizontal"],disabled:!r}),u.jsx(H,{...e["stack-vertical"],disabled:!r})]})}function nre(){const e=ie(),n=bn(1),t=ls(),r=n&&t;return u.jsxs(u.Fragment,{children:[u.jsx(H,{...e["send-to-back"],disabled:!r}),u.jsx(H,{...e["send-backward"],disabled:!r}),u.jsx(H,{...e["bring-forward"],disabled:!r}),u.jsx(H,{...e["bring-to-front"],disabled:!r})]})}function rre(){return Un()<yt.TABLET_SM?u.jsx(ore,{}):u.jsx(sre,{})}function ore(){const e=ie(),n=B(),t=G("zoom is 1",()=>n.getZoomLevel()===1,[n]);return u.jsx(H,{...e["zoom-to-100"],disabled:t})}function sre(){const e=ie(),n=bn(1),t=ls(),r=n&&t;return u.jsx(H,{...e["rotate-ccw"],disabled:!r})}function ire(){const e=ie(),n=bn(1),t=ls(),r=n&&t;return u.jsx(H,{...e["rotate-cw"],disabled:!r})}function are(){const e=ie(),n=LO(),t=ls(),r=n&&t;return u.jsx(H,{...e["edit-link"],disabled:!r})}function lre(){const e=DO(),n=RO();return e?u.jsx(tE,{}):n?u.jsx(cre,{}):u.jsx(tE,{})}function tE(){const e=ie(),n=bn(2),t=ls(),r=n&&t;return u.jsx(H,{...e.group,disabled:!r})}function cre(){const e=ie();return u.jsx(H,{...e.ungroup})}const ure=P.memo(function({children:n}){const t=Te(),r=Un(),o=is(),s=B(),i=G("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??u.jsx(Qne,{});if(!(o&&!i))return u.jsxs(U0,{id:"actions-menu",children:[u.jsx(H0,{children:u.jsx(he,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:u.jsx(be,{icon:"dots-vertical",small:!0})})}),u.jsx(K0,{side:r>=yt.TABLET?"bottom":"top",sideOffset:6,children:u.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:u.jsx(Er,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function ur({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=Mg(),d=is(),h=Te();if(d&&!r)return null;const p=yu(t,l),f=p?h(p):void 0;switch(l){case"menu":return u.jsxs(Kne,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:S=>{o==null||o(c),Ee(S)},disabled:i,checked:a,children:[u.jsx(qs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&u.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),n&&u.jsx(Hc,{children:n})]});case"context-menu":return u.jsxs(yne,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:S=>{o(c),Ee(S)},disabled:i,checked:a,children:[u.jsx(qs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&u.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),n&&u.jsx(Hc,{children:n})]},e);default:return null}}function ge({id:e,label:n,children:t}){const{type:r,sourceId:o}=Mg(),s=Te(),i=yu(n,r),a=i?s(i):void 0;switch(r){case"panel":return u.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return u.jsx(Zne,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return u.jsx($D,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return u.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[u.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),u.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function Hn({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=Mg(),a=un(),l=Te(),c=t?typeof t=="string"?t:t[s]??t.default:void 0,d=c?l(c):void 0;switch(s){case"menu":return u.jsxs(Yne,{id:`${i}-sub.${e}`,children:[u.jsx(Xne,{id:`${i}-sub.${d?d.toLowerCase()+"-button":""}`,disabled:n,label:d,title:d}),u.jsx(qne,{id:`${i}-sub.${d?d.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:u.jsxs(dre,{id:`${i}-sub.${e}`,children:[u.jsx(BD,{dir:"ltr",disabled:n,asChild:!0,children:u.jsxs(he,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[u.jsx(bt,{children:d}),u.jsx(be,{icon:"chevron-right",small:!0})]})}),u.jsx(tb,{container:a,children:u.jsx(UD,{"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 dre({id:e,children:n}){const[t,r]=ui(e);return u.jsx(zD,{open:t,onOpenChange:r,children:n})}function rR(){const e=ie();return ste()?u.jsx(H,{...e["toggle-auto-size"]}):null}function oR(){const e=ie();return LO()?u.jsx(H,{...e["edit-link"]}):null}function hre(){const e=ie();return bn(1)?u.jsx(H,{...e.duplicate}):null}function sR(){const e=ie(),n=B();return G("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const o=n.getOnlySelectedShape();return!(o&&n.isShapeOfType(o,"image"))},[n])?u.jsx(H,{...e["flatten-to-image"]}):null}function iR(){const e=ie();return DO()?u.jsx(H,{...e.group}):null}function aR(){const e=ie();return RO()?u.jsx(H,{...e.ungroup}):null}function lR(){const e=B(),n=ie();return G("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?u.jsx(H,{...n["remove-frame"]}):null}function cR(){const e=B(),n=ie();return G("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?u.jsx(H,{...n["fit-frame-to-content"]}):null}function uR(){const e=B(),n=ie();return G("selected shapes",()=>e.getSelectedShapes().length>0,[e])?u.jsx(H,{...n["toggle-lock"]}):null}function ib(){const e=ie(),n=B(),t=G("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return u.jsx(ur,{...e["toggle-transparent"],checked:t,toggle:!0})}function pre(){const e=B(),n=ie(),t=G("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return u.jsx(H,{...n["unlock-all"],disabled:!t})}function dR(){const e=B(),n=G("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=ie();return u.jsx(H,{...t["zoom-to-100"],noClose:!0,disabled:n})}function hR(){const e=B(),n=G("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=ie();return u.jsx(H,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function pR(){const e=B(),n=G("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=ie();return u.jsx(H,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function fR(){return u.jsxs(ge,{id:"clipboard",children:[u.jsx(gre,{}),u.jsx(mre,{}),u.jsx(yre,{}),u.jsx(hre,{}),u.jsx(Sre,{})]})}function fre(){var r;const e=B(),n=ie(),t=G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return u.jsxs(Hn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[u.jsxs(ge,{id:"copy-as-group",children:[u.jsx(H,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&u.jsx(H,{...n["copy-as-png"]}),u.jsx(H,{...n["copy-as-json"]})]}),u.jsx(ge,{id:"copy-as-bg",children:u.jsx(ib,{})})]})}function gre(){const e=ie(),n=bn(1);return u.jsx(H,{...e.cut,disabled:!n})}function mre(){const e=ie(),n=ote(1);return u.jsx(H,{...e.copy,disabled:!n})}function yre(){const e=ie(),n=rte;return u.jsx(H,{...e.paste,disabled:!n})}function gR(){const e=B(),n=ie();return G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?u.jsxs(ge,{id:"conversions",children:[u.jsx(fre,{}),u.jsxs(Hn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[u.jsxs(ge,{id:"export-as-group",children:[u.jsx(H,{...n["export-as-svg"]}),u.jsx(H,{...n["export-as-png"]}),u.jsx(H,{...n["export-as-json"]})]}),u.jsx(ge,{id:"export-as-bg",children:u.jsx(ib,{})})]})]}):null}function mR(){const e=ie(),n=B(),t=G("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return u.jsx(H,{...e["select-all"],disabled:!t})}function Sre(){const e=ie(),n=bn(1);return u.jsx(H,{...e.delete,disabled:!n})}function vre(){return u.jsxs(Hn,{id:"edit",label:"context-menu.edit",size:"small",children:[u.jsx(iR,{}),u.jsx(aR,{}),u.jsx(sR,{}),u.jsx(oR,{}),u.jsx(cR,{}),u.jsx(lR,{}),u.jsx(SR,{}),u.jsx(yR,{}),u.jsx(rR,{}),u.jsx(uR,{})]})}function xre(){const e=bn(2),n=ite(),t=ie();return e||n?u.jsxs(Hn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&u.jsxs(ge,{id:"align",children:[u.jsx(H,{...t["align-left"]}),u.jsx(H,{...t["align-center-horizontal"]}),u.jsx(H,{...t["align-right"]}),u.jsx(H,{...t["align-top"]}),u.jsx(H,{...t["align-center-vertical"]}),u.jsx(H,{...t["align-bottom"]})]}),u.jsx(wre,{}),e&&u.jsxs(ge,{id:"stretch",children:[u.jsx(H,{...t["stretch-horizontal"]}),u.jsx(H,{...t["stretch-vertical"]})]}),(e||n)&&u.jsxs(ge,{id:"flip",children:[u.jsx(H,{...t["flip-horizontal"]}),u.jsx(H,{...t["flip-vertical"]})]}),u.jsx(bre,{})]}):null}function wre(){const e=ie();return bn(3)?u.jsxs(ge,{id:"distribute",children:[u.jsx(H,{...e["distribute-horizontal"]}),u.jsx(H,{...e["distribute-vertical"]})]}):null}function bre(){const e=ie(),n=bn(2),t=OO();return n?u.jsxs(ge,{id:"order",children:[u.jsx(H,{...e.pack}),t&&u.jsx(H,{...e["stack-horizontal"]}),t&&u.jsx(H,{...e["stack-vertical"]})]}):null}function Pre(){const e=ie();return bn(1)?u.jsx(Hn,{id:"reorder",label:"context-menu.reorder",size:"small",children:u.jsxs(ge,{id:"reorder",children:[u.jsx(H,{...e["bring-to-front"]}),u.jsx(H,{...e["bring-forward"]}),u.jsx(H,{...e["send-backward"]}),u.jsx(H,{...e["send-to-back"]})]})}):null}function Cre(){const e=B(),n=G("pages",()=>e.getPages(),[e]),t=G("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Zr(),o=ie(),s=qr();return bn(1)?u.jsxs(Hn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[u.jsx(ge,{id:"pages",children:n.map(a=>u.jsx(H,{id:a.id,disabled:t===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const l=e.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),u.jsx(ge,{id:"new-page",children:u.jsx(H,{...o["new-page"]})})]}):null}function yR(){const e=B(),n=ie();return G("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?u.jsx(H,{...n["convert-to-bookmark"]}):null}function SR(){const e=B(),n=ie();return G("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&Ms(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?u.jsx(H,{...n["convert-to-embed"]}):null}function Ire(){const e=ie(),n=B(),t=G("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return u.jsx(ur,{...e["toggle-snap-mode"],checked:t})}function Ere(){const e=ie(),n=B(),t=G("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return u.jsx(ur,{...e["toggle-tool-lock"],checked:t})}function kre(){const e=ie(),n=B(),t=G("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return u.jsx(ur,{...e["toggle-grid"],checked:t})}function _re(){const e=ie(),n=B(),t=G("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return u.jsx(ur,{...e["toggle-wrap-mode"],checked:t})}function Tre(){const e=ie(),n=B(),t=G("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return u.jsx(ur,{...e["toggle-focus-mode"],checked:t})}function Mre(){const e=ie(),n=B(),t=G("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return u.jsx(ur,{...e["toggle-edge-scrolling"],checked:t===1})}function jre(){const e=ie(),n=B(),t=G("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return u.jsx(ur,{...e["toggle-reduce-motion"],checked:t===0})}function Are(){const e=ie(),n=B(),t=G("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return u.jsx(ur,{...e["toggle-debug-mode"],checked:t})}function Ore(){const e=ie(),n=B(),t=G("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return u.jsx(ur,{...e["toggle-dynamic-size-mode"],checked:t})}function Dre(){const e=B();return G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?u.jsxs(u.Fragment,{children:[u.jsxs(ge,{id:"modify",children:[u.jsx(vre,{}),u.jsx(xre,{}),u.jsx(Pre,{}),u.jsx(Cre,{})]}),u.jsx(fR,{}),u.jsx(gR,{}),u.jsx(ge,{id:"select-all",children:u.jsx(mR,{})})]}):null}const Rre=P.memo(function({children:n}){const t=B(),{Canvas:r}=it(),o=P.useCallback(c=>{if(c){if(t.getInstanceState().isCoarsePointer){const d=t.getSelectedShapes(),{inputs:{currentPagePoint:h}}=t,p=t.getShapesAtPoint(h);if(!t.getSelectedShapes().length||!p.some(f=>d.includes(f))){const f=p.filter(S=>t.isShapeOrAncestorLocked(S));f.length&&t.select(...f.map(S=>S.id))}}}else{const d=t.getOnlySelectedShape();d&&t.isShapeOrAncestorLocked(d)&&t.setSelectedShapes([])}},[t]),s=un(),[i,a]=ui("context menu",o),l=n??u.jsx(Dre,{});return u.jsxs(pne,{dir:"ltr",onOpenChange:a,modal:!1,children:[u.jsx(fne,{onContextMenu:void 0,dir:"ltr",children:r?u.jsx(r,{}):null}),i&&u.jsx(gne,{container:s,children:u.jsx(mne,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ee,children:u.jsx(Er,{type:"context-menu",sourceId:"context-menu",children:l})})})]})});function Yv({checked:e}){return u.jsx(qs,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function Lre(){const e=B(),{addToast:n}=Zr(),{addDialog:t}=la(),[r,o]=xe.useState(!1);return u.jsxs(u.Fragment,{children:[u.jsxs(ge,{id:"items",children:[u.jsx(H,{id:"add-toast",onSelect:()=>{n({id:ot(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),n({id:ot(),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:()=>{}}]}),n({id:ot(),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:()=>{}}]}),n({id:ot(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),u.jsx(H,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>u.jsx(Nre,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),u.jsx(H,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>zre(e,100)}),u.jsx(H,{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})(),u.jsx(H,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),u.jsx(H,{id:"hard-reset",onSelect:c2,label:"Hard reset"})]}),u.jsxs(ge,{id:"flags",children:[u.jsx($re,{}),u.jsx(Fre,{})]})]})}function $re(){const e=Object.values(wt);return e.length?u.jsx(Hn,{id:"debug flags",label:"Debug Flags",children:u.jsx(ge,{id:"debug flags",children:e.map(n=>u.jsx(vR,{flag:n},n.name))})}):null}function Fre(){const e=Object.values(n7);return e.length?u.jsx(Hn,{id:"feature flags",label:"Feature Flags",children:u.jsx(ge,{id:"feature flags",children:e.map(n=>u.jsx(vR,{flag:n},n.name))})}):null}function Nre({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=xe.useState(!1);return u.jsxs(u.Fragment,{children:[u.jsxs(Pg,{children:[u.jsx(Cg,{children:e}),u.jsx(Ig,{})]}),u.jsx(mu,{style:{maxWidth:350},children:n}),u.jsxs(k0,{className:"tlui-dialog__footer__actions",children:[o&&u.jsxs(he,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[u.jsx(Yv,{checked:a}),u.jsx(bt,{children:"Don’t show again"})]}),u.jsx(he,{type:"normal",onClick:s,children:u.jsx(bt,{children:t})}),u.jsx(he,{type:"primary",onClick:async()=>i(),children:u.jsx(bt,{children:r})})]})]})}const vR=lr(function({flag:n,onChange:t}){const r=n.get();return u.jsx(ur,{id:n.name,title:n.name,label:n.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{n.set(!r),t==null||t(!r)}})});let nE=0;function zre(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)nE++,t[o]={id:$e("box"+nE),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function Bre({children:e}){const n=e??u.jsx(Lre,{});return u.jsxs(Qi,{id:"debug",children:[u.jsx(Ji,{children:u.jsx(he,{type:"icon",title:"Debug menu",children:u.jsx(be,{icon:"dots-horizontal"})})}),u.jsx(ea,{side:"top",align:"end",alignOffset:0,children:u.jsx(Er,{type:"menu",sourceId:"debug-panel",children:n})})]})}const Ure=P.memo(function(){const{DebugMenu:n}=pi();return u.jsxs("div",{className:"tlui-debug-panel",children:[u.jsx(Kre,{}),u.jsx(Wre,{}),n&&u.jsx(n,{})]})});function Hre(e=!0){const[n,t]=P.useState(0),r=B();P.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const Kre=lr(function(){Hre();const n=B(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),s=t==="select.idle"||!t.includes("select.")?r:o,i=s&&t.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${w.ToInt(n.getPointInShapeSpace(s,n.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${w.ToInt(n.inputs.originPagePoint)}] → [${w.ToInt(n.inputs.currentPagePoint)}] = ${w.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return u.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function Wre(){const e=B(),n=G("show_fps",()=>wt.showFps.get(),[wt]),t=P.useRef(null);return P.useEffect(()=>{if(!n)return;const r=250;let o=0,s=-1,i=performance.now(),a=0,l=0,c=!1;function d(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>o&&(o=h);const p=o*.75;(h<p&&!c||h>=p&&c)&&(c=!c),t.current.innerHTML=`FPS ${h.toString()}`,t.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}s=e.timers.requestAnimationFrame(d)}return d(),()=>{cancelAnimationFrame(s)}},[n,e]),n?u.jsx("div",{ref:t}):null}function xR(){const e=B(),n=qr(),t=G("locale",()=>e.user.getLocale(),[e]);return u.jsx(Hn,{id:"help menu language",label:"menu.language",children:u.jsx(ge,{id:"languages",children:pu.map(({locale:r,label:o})=>u.jsx(ur,{id:`language-${r}`,title:r,label:o,checked:r===t,onSelect:()=>{e.user.updateUserPreferences({locale:r}),n("change-language",{source:"menu",locale:r})}},r))})})}function Gre(){return u.jsxs(u.Fragment,{children:[u.jsx(xR,{}),u.jsx(Vre,{})]})}function Vre(){const{KeyboardShortcutsDialog:e}=pi(),{addDialog:n}=la();return e?u.jsx(H,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const Yre=P.memo(function({children:n}){const t=Te(),r=Un(),o=n??u.jsx(Gre,{});return r<yt.MOBILE?null:u.jsx("div",{className:"tlui-help-menu",children:u.jsxs(Qi,{id:"help menu",children:[u.jsx(Ji,{children:u.jsx(he,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:u.jsx(be,{icon:"question-mark",small:!0})})}),u.jsx(ea,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:u.jsx(Er,{type:"menu",sourceId:"help-menu",children:o})})]})})});function Xre(){const e=B(),n=ie(),[t,r]=P.useState(!1),o=P.useRef(!1);return Bs("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]),t?u.jsx(H,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function qre(){const e=B(),n=ie();return G("is pen mode",()=>e.getInstanceState().isPenMode,[e])?u.jsx(H,{...n["exit-pen-mode"]}):null}function Zre(){const e=B(),n=ie();return G("is following user",()=>!!e.getInstanceState().followingUserId,[e])?u.jsx(H,{...n["stop-following"]}):null}function Qre(){return u.jsxs(u.Fragment,{children:[u.jsx(qre,{}),u.jsx(Xre,{}),u.jsx(Zre,{})]})}function Jre({children:e}){const n=e??u.jsx(Qre,{});return u.jsx("div",{className:"tlui-helper-buttons",children:u.jsx(Er,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}function eoe(){const e=ie(),n=Eg();return u.jsxs(u.Fragment,{children:[u.jsxs(ge,{label:"shortcuts-dialog.tools",id:"tools",children:[u.jsx(H,{...e["toggle-tool-lock"]}),u.jsx(H,{...e["insert-media"]}),u.jsx(H,{...n.select}),u.jsx(H,{...n.draw}),u.jsx(H,{...n.eraser}),u.jsx(H,{...n.hand}),u.jsx(H,{...n.rectangle}),u.jsx(H,{...n.ellipse}),u.jsx(H,{...n.arrow}),u.jsx(H,{...n.line}),u.jsx(H,{...n.text}),u.jsx(H,{...n.frame}),u.jsx(H,{...n.note}),u.jsx(H,{...n.laser})]}),u.jsxs(ge,{label:"shortcuts-dialog.preferences",id:"preferences",children:[u.jsx(H,{...e["toggle-dark-mode"]}),u.jsx(H,{...e["toggle-focus-mode"]}),u.jsx(H,{...e["toggle-grid"]})]}),u.jsxs(ge,{label:"shortcuts-dialog.edit",id:"edit",children:[u.jsx(H,{...e.undo}),u.jsx(H,{...e.redo}),u.jsx(H,{...e.cut}),u.jsx(H,{...e.copy}),u.jsx(H,{...e.paste}),u.jsx(H,{...e["select-all"]}),u.jsx(H,{...e.delete}),u.jsx(H,{...e.duplicate})]}),u.jsxs(ge,{label:"shortcuts-dialog.view",id:"view",children:[u.jsx(H,{...e["zoom-in"]}),u.jsx(H,{...e["zoom-out"]}),u.jsx(H,{...e["zoom-to-100"]}),u.jsx(H,{...e["zoom-to-fit"]}),u.jsx(H,{...e["zoom-to-selection"]})]}),u.jsxs(ge,{label:"shortcuts-dialog.transform",id:"transform",children:[u.jsx(H,{...e["bring-to-front"]}),u.jsx(H,{...e["bring-forward"]}),u.jsx(H,{...e["send-backward"]}),u.jsx(H,{...e["send-to-back"]}),u.jsx(H,{...e.group}),u.jsx(H,{...e.ungroup}),u.jsx(H,{...e["flip-horizontal"]}),u.jsx(H,{...e["flip-vertical"]}),u.jsx(H,{...e["align-top"]}),u.jsx(H,{...e["align-center-vertical"]}),u.jsx(H,{...e["align-bottom"]}),u.jsx(H,{...e["align-left"]}),u.jsx(H,{...e["align-center-horizontal"]}),u.jsx(H,{...e["align-right"]})]})]})}const toe=P.memo(function({children:n}){const t=Te(),r=Un(),o=n??u.jsx(eoe,{});return u.jsxs(u.Fragment,{children:[u.jsxs(Pg,{className:"tlui-shortcuts-dialog__header",children:[u.jsx(Cg,{children:t("shortcuts-dialog.title")}),u.jsx(Ig,{})]}),u.jsx(mu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=yt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=yt.TABLET}),children:u.jsx(Er,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),u.jsx("div",{className:"tlui-dialog__scrim"})]})}),noe=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function roe(){const e=B(),n=qr(),t=G("colorScheme",()=>e.user.getUserPreferences().colorScheme,[e]);return u.jsx(Hn,{id:"help menu color-scheme",label:"menu.theme",children:u.jsx(ge,{id:"languages",children:noe.map(({colorScheme:r,label:o})=>u.jsx(ur,{id:`color-scheme-${r}`,label:o,checked:r===t,onSelect:()=>{e.user.updateUserPreferences({colorScheme:r}),n("color-scheme",{source:"menu",value:r})}},r))})})}function ooe(){return u.jsxs(u.Fragment,{children:[u.jsx(ioe,{}),u.jsx(uoe,{}),u.jsx(soe,{}),u.jsx(doe,{}),u.jsx(hoe,{})]})}function soe(){const e=ie();return u.jsxs(Hn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[u.jsxs(ge,{id:"export-all-as-group",children:[u.jsx(H,{...e["export-all-as-svg"]}),u.jsx(H,{...e["export-all-as-png"]}),u.jsx(H,{...e["export-all-as-json"]})]}),u.jsx(ge,{id:"export-all-as-bg",children:u.jsx(ib,{})})]})}function ioe(){const e=B(),n=G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return u.jsxs(Hn,{id:"edit",label:"menu.edit",disabled:!n,children:[u.jsx(coe,{}),u.jsx(fR,{}),u.jsx(gR,{}),u.jsx(aoe,{}),u.jsx(loe,{}),u.jsx(ge,{id:"select-all",children:u.jsx(mR,{})})]})}function aoe(){return u.jsxs(ge,{id:"misc",children:[u.jsx(iR,{}),u.jsx(aR,{}),u.jsx(oR,{}),u.jsx(rR,{}),u.jsx(lR,{}),u.jsx(cR,{}),u.jsx(SR,{}),u.jsx(yR,{}),u.jsx(sR,{})]})}function loe(){return u.jsxs(ge,{id:"lock",children:[u.jsx(uR,{}),u.jsx(pre,{})]})}function coe(){const e=ie(),n=FO(),t=$O();return u.jsxs(ge,{id:"undo-redo",children:[u.jsx(H,{...e.undo,disabled:!n}),u.jsx(H,{...e.redo,disabled:!t})]})}function uoe(){const e=ie();return u.jsx(Hn,{id:"view",label:"menu.view",children:u.jsxs(ge,{id:"view-actions",children:[u.jsx(H,{...e["zoom-in"]}),u.jsx(H,{...e["zoom-out"]}),u.jsx(dR,{}),u.jsx(hR,{}),u.jsx(pR,{})]})})}function doe(){const e=ie();return u.jsxs(ge,{id:"extras",children:[u.jsx(H,{...e["insert-embed"]}),u.jsx(H,{...e["insert-media"]})]})}function hoe(){return u.jsx(ge,{id:"preferences",children:u.jsxs(Hn,{id:"preferences",label:"menu.preferences",children:[u.jsxs(ge,{id:"preferences-actions",children:[u.jsx(Ire,{}),u.jsx(Ere,{}),u.jsx(kre,{}),u.jsx(_re,{}),u.jsx(Tre,{}),u.jsx(Mre,{}),u.jsx(jre,{}),u.jsx(Ore,{}),u.jsx(Are,{})]}),u.jsx(ge,{id:"color-scheme",children:u.jsx(roe,{})}),u.jsx(ge,{id:"language",children:u.jsx(xR,{})})]})})}const poe=P.memo(function({children:n}){const t=un(),[r,o]=ui("main menu"),s=Te(),i=n??u.jsx(ooe,{});return u.jsxs(rb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[u.jsx(ob,{asChild:!0,dir:"ltr",children:u.jsx(he,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:u.jsx(be,{icon:"menu",small:!0})})}),u.jsx(Dg,{container:t,children:u.jsx(sb,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:u.jsx(Er,{type:"menu",sourceId:"main-menu",children:i})})})]})}),foe=P.memo(function(){const n=Un(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=pi();return!t&&!s&&n<6?null:u.jsx("div",{className:"tlui-menu-zone",children:u.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&u.jsx(t,{}),s&&u.jsx(s,{}),n<6?null:u.jsxs(u.Fragment,{children:[r&&u.jsx(r,{}),o&&u.jsx(o,{})]})]})})}),ky={};function pc(e){if(ky[e])return ky[e];const t=document.createElement("canvas").getContext("2d");t.fillStyle=e,t.fillRect(0,0,1,1);const[r,o,s,i]=t.getImageData(0,0,1,1).data,a=new Float32Array([r/255,o/255,s/255,i/255]);return ky[e]=a,a}const fp=10,wR=4*6*fp+12+4*12;function Ca(e,{center:n,radius:t,numArcSegments:r=20,startAngle:o=0,endAngle:s=Re,offset:i=0}){const a=(s-o)/r;let l=i;for(let c=o;c<s;c+=a)e[l++]=n.x,e[l++]=n.y,e[l++]=n.x+Math.cos(c)*t,e[l++]=n.y+Math.sin(c)*t,e[l++]=n.x+Math.cos(c+a)*t,e[l++]=n.y+Math.sin(c+a)*t;return e}function Ia(e,n,t,r,o,s){e[n++]=t,e[n++]=r,e[n++]=t,e[n++]=r+s,e[n++]=t+o,e[n++]=r,e[n++]=t+o,e[n++]=r,e[n++]=t,e[n++]=r+s,e[n++]=t+o,e[n++]=r+s}function goe(e,n,t){const r=fp;t=Math.min(t,Math.min(n.w,n.h)/2);const o=Z.ExpandBy(n,-t);if(o.w<=0||o.h<=0)return Ca(e,{center:n.center,radius:t,numArcSegments:fp*4}),fp*4*6;let s=0;return Ia(e,s,o.minX,o.minY,o.w,o.h),s+=12,Ia(e,s,o.minX,n.minY,o.w,t),s+=12,Ia(e,s,o.maxX,o.minY,t,o.h),s+=12,Ia(e,s,o.minX,o.maxY,o.w,t),s+=12,Ia(e,s,n.minX,o.minY,t,o.h),s+=12,Ca(e,{numArcSegments:r,offset:s,center:o.point,radius:t,startAngle:_e,endAngle:_e*1.5}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,new w(o.w,0)),radius:t,startAngle:_e*1.5,endAngle:Re}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,o.size),radius:t,startAngle:0,endAngle:Ve}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,new w(0,o.h)),radius:t,startAngle:Ve,endAngle:_e}),wR}function moe(e){if(!e)throw new Error("Canvas element not found");const n=e.getContext("webgl2",{premultipliedAlpha:!1});if(!n)throw new Error("Failed to get webgl2 context");const t=`#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=n.createShader(n.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.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=n.createShader(n.FRAGMENT_SHADER);if(!s)throw new Error("Failed to create fragment shader");if(n.shaderSource(s,o),n.compileShader(s),!n.getShaderParameter(s,n.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=n.createProgram();if(!i)throw new Error("Failed to create program");if(n.attachShader(i,r),n.attachShader(i,s),n.linkProgram(i),!n.getProgramParameter(i,n.LINK_STATUS))throw new Error("Failed to link program");n.useProgram(i);const a=n.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");n.enableVertexAttribArray(a);const l=n.getUniformLocation(i,"canvasPageBounds"),c=n.getUniformLocation(i,"fillColor");if(!n.createBuffer())throw new Error("Failed to create buffer");if(!n.createBuffer())throw new Error("Failed to create buffer");return{context:n,selectedShapes:ch(n,1024),unselectedShapes:ch(n,4096),viewport:ch(n,wR),collaborators:ch(n,1024),prepareTriangles(p,f){n.bindBuffer(n.ARRAY_BUFFER,p.buffer),n.bufferData(n.ARRAY_BUFFER,p.vertices,n.STATIC_DRAW,0,f),n.enableVertexAttribArray(a),n.vertexAttribPointer(a,2,n.FLOAT,!1,0,0)},drawTrianglesTransparently(p){n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.drawArrays(n.TRIANGLES,0,p/2),n.disable(n.BLEND)},drawTriangles(p){n.drawArrays(n.TRIANGLES,0,p/2)},setFillColor(p){n.uniform4fv(c,p)},setCanvasPageBounds(p){n.uniform4fv(l,p)}}}function ch(e,n){const t=e.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(n)}}function rE(e,n,t){let r=e.vertices.length;for(;r<n+t.length;)r*=2;if(r!=e.vertices.length){const o=new Float32Array(r);o.set(e.vertices),e.vertices=o}e.vertices.set(t,n)}var yoe=Object.defineProperty,Soe=Object.getOwnPropertyDescriptor,hi=(e,n,t,r)=>{for(var o=Soe(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&yoe(n,t,o),o};class cs{constructor(n,t,r){m(this,"disposables",[]);m(this,"close",()=>this.disposables.forEach(n=>n()));m(this,"gl");m(this,"shapeGeometryCache");m(this,"colors");m(this,"id",ot());m(this,"canvasBoundingClientRect",Mt("canvasBoundingClientRect",new Z));m(this,"originPagePoint",new w);m(this,"originPageCenter",new w);m(this,"isInViewport",!1);m(this,"getMinimapPagePoint",(n,t)=>{const r=this.getCanvasPageBounds(),o=this.getCanvasScreenBounds();let s=n-o.x,i=t-o.y;return s*=r.width/o.width,i*=r.height/o.height,s+=r.minX,i+=r.minY,new w(s,i,1)});m(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(n,t);if(o){const c=this.editor.getCurrentPageBounds()??new Z,d=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,f=c.maxY+i.height/2,S=Math.max(0,d+i.width-a),g=Math.max(0,-(h-i.width-a)),x=Math.max(0,p+i.height-l),y=Math.max(0,-(f-i.height-l));a+=(S-g)/2,l+=(x-y)/2,a=_t(a,d,h),l=_t(l,p,f)}if(r){const{originPagePoint:c}=this,d=Math.abs(a-c.x),h=Math.abs(l-c.y);d>h?l=c.y:a=c.x}return new w(a,l)});m(this,"render",()=>{const n=this.gl.context,t=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=t.x,this.elem.height=t.y,n.viewport(0,0,t.x,t.y),n.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),n.clear(n.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 l=0,c=a.length;l<c;l++){const d=a[l],h=this.shapeGeometryCache.get(d);if(!h)continue;const p=h.length;r.has(d)?(rE(this.gl.selectedShapes,s,h),s+=p):(rE(this.gl.unselectedShapes,i,h),i+=p)}this.drawShapes(this.gl.unselectedShapes,i,o.shapeFill),this.drawShapes(this.gl.selectedShapes,s,o.selectFill),this.drawViewport(),this.drawCollaborators()});this.editor=n,this.elem=t,this.container=r,this.gl=moe(t),this.shapeGeometryCache=n.store.createComputedCache("webgl-geometry",o=>{const s=n.getShapeMaskedPageBounds(o.id);if(!s)return null;const i=new Float32Array(12);return Ia(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),aa("minimap render",this.render))}_getColors(){const n=getComputedStyle(this.editor.getContainer());return{shapeFill:pc(n.getPropertyValue("--color-text-3").trim()),selectFill:pc(n.getPropertyValue("--color-selected").trim()),viewportFill:pc(n.getPropertyValue("--color-muted-1").trim()),background:pc(n.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const n=this.editor.getViewportPageBounds(),t=this.editor.getCurrentPageBounds();return t?Z.Expand(t,n):n}getContentScreenBounds(){const n=this.getContentPageBounds(),t=this.editor.pageToScreen(n.point),r=this.editor.pageToScreen(new w(n.maxX,n.maxY));return new Z(t.x,t.y,r.x-t.x,r.y-t.y)}_getCanvasBoundingRect(){const{x:n,y:t,width:r,height:o}=this.elem.getBoundingClientRect();return new Z(n,t,r,o)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const n=new ResizeObserver(()=>{const t=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(t)});return n.observe(this.elem),n.observe(this.container),()=>n.disconnect()}getCanvasSize(){const n=this.canvasBoundingClientRect.get(),t=this.getDpr();return new w(n.width*t,n.height*t)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const n=this.getCanvasScreenBounds(),t=this.getContentPageBounds(),r=n.width/n.height;let o=t.width,s=o/r;s<t.height&&(s=t.height,o=s*r);const i=new Z(0,0,o,s);return i.center=t.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:n,y:t,w:r,h:o}=this.getCanvasPageBounds();return new Float32Array([n,t,r,o])}drawShapes(n,t,r){this.gl.prepareTriangles(n,t),this.gl.setFillColor(r),this.gl.drawTriangles(t)}drawViewport(){const n=this.editor.getViewportPageBounds(),t=goe(this.gl.viewport.vertices,n,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,t),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(t),this.editor.environment.isSafari&&(this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t))}drawCollaborators(){const n=this.editor.getCollaboratorsOnCurrentPage();if(!n.length)return;const t=20,r=t*6,o=r*n.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:l}of n)Ca(s,{center:w.From(l),radius:3*a,offset:i,numArcSegments:t}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,o),i=0;for(const{color:l}of n)this.gl.setFillColor(pc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}hi([V],cs.prototype,"getDpr");hi([V],cs.prototype,"getContentPageBounds");hi([V],cs.prototype,"getContentScreenBounds");hi([V],cs.prototype,"getCanvasSize");hi([V],cs.prototype,"getCanvasClientPosition");hi([V],cs.prototype,"getCanvasPageBounds");hi([V],cs.prototype,"getZoom");hi([V],cs.prototype,"getCanvasPageBoundsArray");function voe(){const e=B(),n=un(),t=P.useRef(null),r=P.useRef(!1),o=P.useRef();P.useEffect(()=>{try{const d=new cs(e,t.current,n);return o.current=d,o.current.close}catch(d){e.annotateError(d,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw d})}},[e,n]);const s=P.useCallback(d=>{if(!e.getCurrentPageShapeIds().size||!o.current)return;const h=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),p=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);o.current.originPagePoint.setTo(p),o.current.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(h,{animation:{duration:e.options.animationMediumMs}})},[e]),i=P.useCallback(d=>{if(!o.current)return;const h=d.currentTarget;if(Nu(h,d),!e.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const p=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),f=e.getViewportPageBounds(),S=o.current.getContentPageBounds();if(new Z(S.x-f.width/2,S.y-f.height/2,S.width+f.width,S.height+f.height).containsPoint(p)&&!f.containsPoint(p)){o.current.isInViewport=f.containsPoint(p);const y=w.Sub(f.center,f.point),v=w.Add(p,y);o.current.originPagePoint.setTo(v),o.current.originPageCenter.setTo(p),e.centerOnPoint(p,{animation:{duration:e.options.animationMediumMs}})}else{const y=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);o.current.isInViewport=f.containsPoint(y),o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(f.center)}function x(y){h&&zu(h,y),r.current=!1,document.body.removeEventListener("pointerup",x)}document.body.addEventListener("pointerup",x)},[e]),a=P.useCallback(d=>{if(!o.current)return;const h=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,d.shiftKey,!0);if(r.current){if(o.current.isInViewport){const g=o.current.originPagePoint.clone().sub(o.current.originPageCenter);e.centerOnPoint(w.Sub(h,g));return}e.centerOnPoint(h)}const p=o.current.getMinimapPagePoint(d.clientX,d.clientY),f=e.pageToScreen(p),S={type:"pointer",target:"canvas",name:"pointer_move",...On(d),point:f,isPen:e.getInstanceState().isPenMode};e.dispatch(S)},[e]),l=P.useCallback(d=>{const h=JM(d);e.dispatch({type:"wheel",name:"wheel",delta:h,point:new w(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey})},[e]),c=Wu();return P.useEffect(()=>{e.timers.setTimeout(()=>{var d,h;(d=o.current)==null||d.updateColors(),(h=o.current)==null||h.render()})},[c,e]),u.jsx("div",{className:"tlui-minimap",children:u.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:s,onPointerMove:a,onPointerDown:i,onWheel:l})})}function xoe(e,n){const[t,r]=xe.useState(n);xe.useLayoutEffect(()=>{const s=bw(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=xe.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return Pw(e,JSON.stringify(a)),a})},[e]);return[t,o]}const woe=P.memo(function(){const n=ie(),t=Te(),r=Un(),[o,s]=xoe("minimap",!0),i=P.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=pi();return r<yt.MOBILE?null:u.jsxs("div",{className:"tlui-navigation-panel",children:[u.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<yt.TABLET?u.jsx(a,{}):o?u.jsxs(u.Fragment,{children:[a&&u.jsx(a,{}),l&&u.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:u.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):u.jsxs(u.Fragment,{children:[u.jsx(he,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(yu(n["zoom-out"].label))} ${Vv(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:u.jsx(be,{icon:"minus"})}),a&&u.jsx(a,{}),u.jsx(he,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(yu(n["zoom-in"].label))} ${Vv(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:u.jsx(be,{icon:"plus"})}),l&&u.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:u.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=yt.TABLET&&!o&&u.jsx(l,{})]})}),boe=function({name:n,id:t,isCurrentPage:r}){const o=B(),s=P.useRef(null),i=P.useCallback(()=>{o.mark("rename page")},[o]),a=P.useCallback(l=>{o.renamePage(t,l||"New Page")},[o,t]);return u.jsx(_0,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:n,onValueChange:a,onFocus:i,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},Xv=(e,n,t,r)=>{let o;const s=e.getPages(),i=t>r?s[r-1]:s[r],a=t>r?s[r]:s[r+1];i&&!a?o=Lo(i.index):!i&&a?o=K6(s[0].index):o=uu(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},oE=lr(function({index:n,listSize:t,item:r,onRename:o}){const s=B(),i=Te(),a=s.getPages(),l=P.useCallback(()=>{s.mark("creating page");const p=Qo.createId();s.duplicatePage(r.id,p)},[s,r]),c=P.useCallback(()=>{Xv(s,r.id,n,n-1)},[s,r,n]),d=P.useCallback(()=>{Xv(s,r.id,n,n+1)},[s,r,n]),h=P.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return u.jsxs(Qi,{id:`page item submenu ${n}`,children:[u.jsx(Ji,{children:u.jsx(he,{type:"icon",title:i("page-menu.submenu.title"),children:u.jsx(be,{icon:"dots-vertical"})})}),u.jsx(ea,{alignOffset:0,side:"right",sideOffset:-4,children:u.jsxs(Er,{type:"menu",sourceId:"page-menu",children:[u.jsxs(ge,{id:"modify",children:[o&&u.jsx(H,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),u.jsx(H,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:a.length>=s.options.maxPages}),n>0&&u.jsx(H,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),n<t-1&&u.jsx(H,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:d})]}),t>1&&u.jsx(ge,{id:"delete",children:u.jsx(H,{id:"delete",onSelect:h,label:"page-menu.submenu.delete"})})]})})]})}),Poe=P.memo(function(){const n=B(),t=Te(),r=Un(),o=P.useCallback(()=>x(!1),[]),[s,i]=ui("page-menu",o),a=36,l=P.useRef(null),c=G("pages",()=>n.getPages(),[n]),d=G("currentPage",()=>n.getCurrentPage(),[n]),h=G("currentPageId",()=>n.getCurrentPageId(),[n]),p=is(),f=G("maxPageCountReached",()=>n.getPages().length>=n.options.maxPages,[n]),S=G("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[g,x]=P.useState(!1),y=P.useCallback(()=>{p||x(_=>!_)},[p]),v=P.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[b,E]=P.useState(Object.fromEntries(c.map((_,j)=>[_.id,{y:j*a,offsetY:0,isSelected:!1}])));P.useLayoutEffect(()=>{E(Object.fromEntries(c.map((_,j)=>[_.id,{y:j*a,offsetY:0,isSelected:!1}])))},[a,c]),P.useEffect(()=>{s&&n.timers.requestAnimationFrame(()=>{const _=document.querySelector(`[data-testid="page-menu-item-${h}"]`);if(_){const j=l.current;if(!j)return;const L=_.offsetTop,A=j.scrollTop;L<A&&j.scrollTo({top:L});const R=L+a,F=j.scrollTop+j.offsetHeight;R>F&&j.scrollTo({top:R-j.offsetHeight})}})},[a,h,s,n]);const I=P.useCallback(_=>{const{clientY:j,currentTarget:L}=_,{dataset:{id:A,index:R}}=L;if(!A||!R)return;const F=v.current;Nu(_.currentTarget,_),F.status="pointing",F.pointing={id:A,index:+R};const K=b[A].y;F.startY=j,F.startIndex=Math.max(0,Math.min(Math.round(K/a),c.length-1))},[a,c.length,b]),C=P.useCallback(_=>{const j=v.current;if(j.status==="pointing"){const{clientY:L}=_,A=L-j.startY;Math.abs(A)>5&&(j.status="dragging")}if(j.status==="dragging"){const{clientY:L}=_,A=L-j.startY,R=b[j.pointing.id],{startIndex:F,pointing:W}=j,K=R.y+A,z=Math.max(0,Math.min(Math.round(K/a),c.length-1)),U={...b};if(U[W.id]={y:R.y,offsetY:A,isSelected:!0},z!==j.dragIndex){j.dragIndex=z;for(let X=0;X<c.length;X++){const J=c[X];if(J.id===j.pointing.id)continue;let{y:le}=U[J.id];z===F?le=X*a:z<F?z<=X&&X<F?le=(X+1)*a:le=X*a:z>F&&(z>=X&&X>F?le=(X-1)*a:le=X*a),le!==U[J.id].y&&(U[J.id]={y:le,offsetY:0,isSelected:!0})}}E(U)}},[a,c,b]),k=P.useCallback(_=>{const j=v.current;if(j.status==="dragging"){const{id:L,index:A}=j.pointing;Xv(n,L,A,j.dragIndex)}zu(_.currentTarget,_),j.status="idle"},[n]),T=P.useCallback(_=>{const j=v.current;_.key==="Escape"&&(j.status==="dragging"&&E(Object.fromEntries(c.map((L,A)=>[L.id,{y:A*a,offsetY:0,isSelected:!1}]))),j.status="idle")},[a,c]),O=P.useCallback(()=>{p||n.batch(()=>{n.mark("creating page");const _=Qo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:_}),n.setCurrentPage(_),x(!0)})},[n,t,p]);return u.jsxs(U0,{id:"pages",onOpenChange:i,open:s,children:[u.jsx(H0,{"data-testid":"main.page-menu",children:u.jsxs(he,{type:"menu",title:d.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[u.jsx("div",{className:"tlui-page-menu__name",children:d.name}),u.jsx(be,{icon:"chevron-down",small:!0})]})}),u.jsx(K0,{side:"bottom",align:"start",sideOffset:6,children:u.jsxs("div",{className:"tlui-page-menu__wrapper",children:[u.jsxs("div",{className:"tlui-page-menu__header",children:[u.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!p&&u.jsxs("div",{className:"tlui-buttons__horizontal",children:[u.jsx(he,{type:"icon","data-testid":"page-menu.edit",title:t(g?"page-menu.edit-done":"page-menu.edit-start"),onClick:y,children:u.jsx(be,{icon:g?"check":"edit"})}),u.jsx(he,{type:"icon","data-testid":"page-menu.create",title:t(f?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:f,onClick:O,children:u.jsx(be,{icon:"plus"})})]})]}),u.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*c.length+4},ref:l,children:c.map((_,j)=>{const L=b[_.id]??{position:j*40,offsetY:0};return g?u.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:_.id===d.id?888:j,transform:`translate(0px, ${L.y+L.offsetY}px)`},children:[u.jsx(he,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:I,onPointerUp:k,onPointerMove:C,onKeyDown:T,"data-id":_.id,"data-index":j,children:u.jsx(be,{icon:"drag-handle-dots"})}),r<yt.TABLET_SM&&S?u.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const A=window.prompt("Rename page",_.name);A&&A!==_.name&&n.renamePage(_.id,A)},onDoubleClick:y,children:[u.jsx(Yv,{checked:_.id===d.id}),u.jsx(bt,{children:_.name})]}):u.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:u.jsx(boe,{id:_.id,name:_.name,isCurrentPage:_.id===d.id})}),!p&&u.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":g,children:u.jsx(oE,{index:j,item:_,listSize:c.length})})]},_.id+"_editing"):u.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[u.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(_.id),onDoubleClick:y,title:t("page-menu.go-to-page"),children:[u.jsx(Yv,{checked:_.id===d.id}),u.jsx(bt,{children:_.name})]}),!p&&u.jsx("div",{className:"tlui-page_menu__item__submenu",children:u.jsx(oE,{index:j,item:_,listSize:c.length,onRename:()=>{if(n.environment.isIos){const A=window.prompt("Rename page",_.name);A&&A!==_.name&&n.renamePage(_.id,A)}else n.batch(()=>{x(!0),n.setCurrentPage(_.id)})}})})]},_.id)})})]})})]})});function Coe(){const e=ie(),n=B(),t=FO(),r=$O(),o=bn(1),s=is(),i=G("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]),a=ls(),l=o&&a;if(!(s&&!i))return u.jsxs(u.Fragment,{children:[u.jsx(H,{...e.undo,disabled:!t}),u.jsx(H,{...e.redo,disabled:!r}),u.jsx(H,{...e.delete,disabled:!l}),u.jsx(H,{...e.duplicate,disabled:!l})]})}const Ioe=P.memo(function({children:n}){const t=n??u.jsx(Coe,{});return u.jsx(Er,{type:"small-icons",sourceId:"quick-actions",children:t})}),Eoe=Object.freeze([sr,Ki,Wi,vo]);function bR(e=Eoe){const n=B();return G("getRelevantStyles",()=>{var s;const t=new vv(n.getSharedStyles()),r=!!((s=n.root.getCurrent())!=null&&s.shapeType),o=n.isIn("select")&&n.getSelectedShapeIds().length>0;if(t.size===0&&n.isIn("select")&&n.getSelectedShapeIds().length===0)for(const i of e)t.applyValue(i,n.getStyleForNextShape(i));return r||o||t.size>0?t:null},[n])}const wr={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Mi=P.memo(function(n){const{uiType:t,items:r,title:o,style:s,value:i,onValueChange:a,theme:l}=n,c=B(),d=Te(),h=P.useRef(!1),p=P.useRef(null),{handleButtonClick:f,handleButtonPointerDown:S,handleButtonPointerEnter:g,handleButtonPointerUp:x}=P.useMemo(()=>{const y=()=>{h.current=!1,window.removeEventListener("pointerup",y);const C=p.current;C&&["TEXTAREA","INPUT"].includes(C.nodeName)&&C.focus(),p.current=null};return{handleButtonClick:C=>{const{id:k}=C.currentTarget.dataset;i.type==="shared"&&i.value===k||(c.mark("point picker item"),a(s,k))},handleButtonPointerDown:C=>{const{id:k}=C.currentTarget.dataset;c.mark("point picker item"),a(s,k),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:C=>{if(!h.current)return;const{id:k}=C.currentTarget.dataset;a(s,k)},handleButtonPointerUp:C=>{const{id:k}=C.currentTarget.dataset;i.type==="shared"&&i.value===k||a(s,k)}}},[i,c,a,s]);return u.jsx("div",{"data-testid":`style.${t}`,className:ce("tlui-buttons__grid"),children:r.map(y=>u.jsx(he,{type:"icon","data-id":y.value,"data-testid":`style.${t}.${y.value}`,"aria-label":y.value,"data-state":i.type==="shared"&&i.value===y.value?"hinted":void 0,title:o+" — "+d(`${t}-style.${y.value}`),className:ce("tlui-button-grid__button"),style:s===sr?{color:l[y.value].solid}:void 0,onPointerEnter:g,onPointerDown:S,onPointerUp:x,onClick:f,children:u.jsx(be,{icon:y.icon})},y.value))})});function PR(e,[n,t]){return Math.min(t,Math.max(n,e))}function koe(e){const n=P.useRef({value:e,previous:e});return P.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}var CR=["PageUp","PageDown"],IR=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],ER={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},zl="Slider",[qv,_oe,Toe]=xg(zl),[kR,qie]=Eo(zl,[Toe]),[Moe,Rg]=kR(zl),_R=P.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:d,onValueChange:h=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...S}=e,g=P.useRef(new Set),x=P.useRef(0),v=i==="horizontal"?joe:Aoe,[b=[],E]=li({prop:d,defaultProp:c,onChange:_=>{var L;(L=[...g.current][x.current])==null||L.focus(),h(_)}}),I=P.useRef(b);function C(_){const j=$oe(b,_);O(_,j)}function k(_){O(_,x.current)}function T(){const _=I.current[x.current];b[x.current]!==_&&p(b)}function O(_,j,{commit:L}={commit:!1}){const A=Boe(s),R=Uoe(Math.round((_-r)/s)*s+r,A),F=PR(R,[r,o]);E((W=[])=>{const K=Roe(W,F,j);if(zoe(K,l*s)){x.current=K.indexOf(F);const z=String(K)!==String(W);return z&&L&&p(K),z?K:W}else return W})}return u.jsx(Moe,{scope:e.__scopeSlider,name:t,disabled:a,min:r,max:o,valueIndexToChangeRef:x,thumbs:g.current,values:b,orientation:i,children:u.jsx(qv.Provider,{scope:e.__scopeSlider,children:u.jsx(qv.Slot,{scope:e.__scopeSlider,children:u.jsx(v,{"aria-disabled":a,"data-disabled":a?"":void 0,...S,ref:n,onPointerDown:re(S.onPointerDown,()=>{a||(I.current=b)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:C,onSlideMove:a?void 0:k,onSlideEnd:a?void 0:T,onHomeKeyDown:()=>!a&&O(r,0,{commit:!0}),onEndKeyDown:()=>!a&&O(o,b.length-1,{commit:!0}),onStepKeyDown:({event:_,direction:j})=>{if(!a){const R=CR.includes(_.key)||_.shiftKey&&IR.includes(_.key)?10:1,F=x.current,W=b[F],K=s*R*j;O(W+K,F,{commit:!0})}}})})})})});_R.displayName=zl;var[TR,MR]=kR(zl,{startEdge:"left",endEdge:"right",size:"width",direction:1}),joe=P.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...d}=e,[h,p]=P.useState(null),f=Ye(n,b=>p(b)),S=P.useRef(),g=W0(o),x=g==="ltr",y=x&&!s||!x&&s;function v(b){const E=S.current||h.getBoundingClientRect(),I=[0,E.width],k=ab(I,y?[t,r]:[r,t]);return S.current=E,k(b-E.left)}return u.jsx(TR,{scope:e.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:u.jsx(jR,{dir:g,"data-orientation":"horizontal",...d,ref:f,style:{...d.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:()=>{S.current=void 0,l==null||l()},onStepKeyDown:b=>{const I=ER[y?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:I?-1:1})}})})}),Aoe=P.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,d=P.useRef(null),h=Ye(n,d),p=P.useRef(),f=!o;function S(g){const x=p.current||d.current.getBoundingClientRect(),y=[0,x.height],b=ab(y,f?[r,t]:[t,r]);return p.current=x,b(g-x.top)}return u.jsx(TR,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:u.jsx(jR,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const x=S(g.clientY);s==null||s(x)},onSlideMove:g=>{const x=S(g.clientY);i==null||i(x)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:g=>{const y=ER[f?"from-bottom":"from-top"].includes(g.key);l==null||l({event:g,direction:y?-1:1})}})})}),jR=P.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,d=Rg(zl,t);return u.jsx(Ce.span,{...c,ref:n,onKeyDown:re(e.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):CR.concat(IR).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:re(e.onPointerDown,h=>{const p=h.target;p.setPointerCapture(h.pointerId),h.preventDefault(),d.thumbs.has(p)?p.focus():r(h)}),onPointerMove:re(e.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&o(h)}),onPointerUp:re(e.onPointerUp,h=>{const p=h.target;p.hasPointerCapture(h.pointerId)&&(p.releasePointerCapture(h.pointerId),s(h))})})}),AR="SliderTrack",OR=P.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Rg(AR,t);return u.jsx(Ce.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:n})});OR.displayName=AR;var Zv="SliderRange",DR=P.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Rg(Zv,t),s=MR(Zv,t),i=P.useRef(null),a=Ye(n,i),l=o.values.length,c=o.values.map(p=>LR(p,o.min,o.max)),d=l>1?Math.min(...c):0,h=100-Math.max(...c);return u.jsx(Ce.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...e.style,[s.startEdge]:d+"%",[s.endEdge]:h+"%"}})});DR.displayName=Zv;var Qv="SliderThumb",RR=P.forwardRef((e,n)=>{const t=_oe(e.__scopeSlider),[r,o]=P.useState(null),s=Ye(n,a=>o(a)),i=P.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return u.jsx(Ooe,{...e,ref:s,index:i})}),Ooe=P.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,name:o,...s}=e,i=Rg(Qv,t),a=MR(Qv,t),[l,c]=P.useState(null),d=Ye(n,v=>c(v)),h=l?!!l.closest("form"):!0,p=uO(l),f=i.values[r],S=f===void 0?0:LR(f,i.min,i.max),g=Loe(r,i.values.length),x=p==null?void 0:p[a.size],y=x?Foe(x,S,a.direction):0;return P.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),u.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${S}% + ${y}px)`},children:[u.jsx(qv.ItemSlot,{scope:e.__scopeSlider,children:u.jsx(Ce.span,{role:"slider","aria-label":e["aria-label"]||g,"aria-valuemin":i.min,"aria-valuenow":f,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:d,style:f===void 0?{display:"none"}:e.style,onFocus:re(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&u.jsx(Doe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),value:f},r)]})});RR.displayName=Qv;var Doe=e=>{const{value:n,...t}=e,r=P.useRef(null),o=koe(n);return P.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&l){const c=new Event("input",{bubbles:!0});l.call(s,n),s.dispatchEvent(c)}},[o,n]),u.jsx("input",{style:{display:"none"},...t,ref:r,defaultValue:n})};function Roe(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function LR(e,n,t){const s=100/(t-n)*(e-n);return PR(s,[0,100])}function Loe(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function $oe(e,n){if(e.length===1)return 0;const t=e.map(o=>Math.abs(o-n)),r=Math.min(...t);return t.indexOf(r)}function Foe(e,n,t){const r=e/2,s=ab([0,50],[0,r]);return(r-s(n)*t)*t}function Noe(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function zoe(e,n){if(n>0){const t=Noe(e);return Math.min(...t)>=n}return!0}function ab(e,n){return t=>{if(e[0]===e[1]||n[0]===n[1])return n[0];const r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-e[0])}}function Boe(e){return(String(e).split(".")[1]||"").length}function Uoe(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}var Hoe=_R,Koe=OR,Woe=DR,Goe=RR;const Voe=P.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=B(),l=Te(),c=P.useCallback(p=>{i(p[0])},[i]),d=P.useCallback(()=>{a.mark("click slider")},[a]),h=P.useCallback(()=>{o&&i(o)},[o,i]);return u.jsx("div",{className:"tlui-slider__container",children:u.jsxs(Hoe,{"data-testid":n["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:d,onValueChange:c,onPointerUp:h,title:t+" — "+l(s),children:[u.jsx(Koe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&u.jsx(Woe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&u.jsx(Goe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Yoe({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:d,onValueChange:h}){const p=Te(),f=P.useMemo(()=>{var g;return((g=s.find(x=>c.type==="shared"&&c.value===x.value))==null?void 0:g.icon)??"mixed"},[s,c]),S=P.useMemo(()=>{var g;return((g=i.find(x=>d.type==="shared"&&d.value===x.value))==null?void 0:g.icon)??"mixed"},[i,d]);return c===void 0&&d===void 0?null:u.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[u.jsx("div",{title:p(e),className:"tlui-style-panel__double-select-picker-label",children:p(e)}),u.jsxs("div",{className:"tlui-buttons__horizontal",children:[u.jsxs(Qi,{id:`style panel ${n} A`,children:[u.jsx(Ji,{children:u.jsx(he,{type:"icon","data-testid":`style.${n}`,title:p(r)+" — "+(c===null||c.type==="mixed"?p("style-panel.mixed"):p(`${n}-style.${c.value}`)),children:u.jsx(be,{icon:f,small:!0,invertIcon:!0})})}),u.jsx(ea,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:u.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,x)=>u.jsx(bu,{"data-testid":`style.${n}.${g.value}`,children:u.jsx(he,{type:"icon",onClick:()=>h(a,g.value),title:`${p(r)} — ${p(`${n}-style.${g.value}`)}`,children:u.jsx(be,{icon:g.icon,invertIcon:!0})},g.value)},x))})})]}),u.jsxs(Qi,{id:`style panel ${t}`,children:[u.jsx(Ji,{children:u.jsx(he,{type:"icon","data-testid":`style.${t}`,title:p(o)+" — "+(d===null||d.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${d.value}`)),children:u.jsx(be,{icon:S,small:!0})})}),u.jsx(ea,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:u.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>u.jsx(bu,{children:u.jsx(he,{type:"icon",title:`${p(o)} — ${p(`${t}-style.${g.value}`)}`,"data-testid":`style.${t}.${g.value}`,onClick:()=>h(l,g.value),children:u.jsx(be,{icon:g.icon})})},g.value))})})]})]})]})}const Xoe=P.memo(Yoe);function qoe({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Te(),c=B(),d=P.useMemo(()=>{var f;return(f=o.find(S=>i.type==="shared"&&S.value===i.value))==null?void 0:f.icon},[o,i]),h=i.type==="mixed"?l("style-panel.mixed"):l(`${t}-style.${i.value}`),p=n?l(n):"";return u.jsxs(Qi,{id:`style panel ${e}`,children:[u.jsx(Ji,{children:u.jsxs(he,{type:s,"data-testid":`style.${t}`,title:h,children:[u.jsx(bt,{children:p}),u.jsx(be,{icon:d??"mixed"})]})}),u.jsx(ea,{side:"left",align:"center",alignOffset:0,children:u.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>u.jsx(bu,{children:u.jsx(he,{type:"icon","data-testid":`style.${t}.${f.value}`,title:l(`${t}-style.${f.value}`),onClick:()=>{c.mark("select style dropdown item"),a(r,f.value)},children:u.jsx(be,{icon:f.icon})})},f.value))})})]})}const lb=P.memo(qoe);function Zoe({styles:e}){const n=Wu();if(!e)return null;const t=e.get(Fr),r=e.get(rf),o=e.get(nf),s=e.get(lf),i=e.get(So),a=t===void 0,l=r===void 0&&o===void 0,c=s===void 0,d=i===void 0,h=ss({isDarkMode:n});return u.jsxs(u.Fragment,{children:[u.jsx(Qoe,{theme:h,styles:e}),!d&&u.jsx(Joe,{theme:h,styles:e}),!(a&&l&&c)&&u.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[u.jsx(ese,{styles:e}),u.jsx(nse,{styles:e}),u.jsx(tse,{styles:e})]})]})}function Ju(){const e=B(),n=qr();return xe.useMemo(()=>function(r,o){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,o),e.setStyleForNextShapes(r,o),e.updateInstanceState({isChangingStyle:!0})}),n("set-style",{source:"style-panel",id:r.id,value:o})},[e,n])}function Qoe({styles:e,theme:n}){const t=Te(),r=B(),o=Ju(),s=e.get(sr),i=e.get(Wi),a=e.get(Ki),l=e.get(vo),c=i!==void 0||a!==void 0||l!==void 0;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:u.jsx(Mi,{title:t("style-panel.color"),uiType:"color",style:sr,items:wr.color,value:s,onValueChange:o,theme:n}),u.jsx(rse,{})]}),c&&u.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:u.jsx(Mi,{title:t("style-panel.fill"),uiType:"fill",style:Wi,items:wr.fill,value:i,onValueChange:o,theme:n}),a===void 0?null:u.jsx(Mi,{title:t("style-panel.dash"),uiType:"dash",style:Ki,items:wr.dash,value:a,onValueChange:o,theme:n}),l===void 0?null:u.jsx(Mi,{title:t("style-panel.size"),uiType:"size",style:vo,items:wr.size,value:l,onValueChange:(d,h)=>{o(d,h);const p=r.getSelectedShapeIds();p.length>0&&Ke(r,p)},theme:n})]})]})}function Joe({theme:e,styles:n}){const t=Te(),r=Ju(),o=n.get(So),s=n.get(pv),i=n.get(sf),a=n.get(af);return o===void 0&&i===void 0?null:u.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:u.jsx(Mi,{title:t("style-panel.font"),uiType:"font",style:So,items:wr.font,value:o,onValueChange:r,theme:e}),s===void 0?null:u.jsxs("div",{className:"tlui-style-panel__row",children:[u.jsx(Mi,{title:t("style-panel.align"),uiType:"align",style:pv,items:wr.textAlign,value:s,onValueChange:r,theme:e}),u.jsx("div",{className:"tlui-style-panel__row__extra-button",children:u.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:u.jsx(be,{icon:"vertical-align-middle"})})})]}),i===void 0?null:u.jsxs("div",{className:"tlui-style-panel__row",children:[u.jsx(Mi,{title:t("style-panel.align"),uiType:"align",style:sf,items:wr.horizontalAlign,value:i,onValueChange:r,theme:e}),u.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?u.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:u.jsx(be,{icon:"vertical-align-middle"})}):u.jsx(lb,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:af,items:wr.verticalAlign,value:a,onValueChange:r})})]})]})}function ese({styles:e}){const n=Ju(),t=e.get(Fr);return t===void 0?null:u.jsx(lb,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:Fr,items:wr.geo,value:t,onValueChange:n})}function tse({styles:e}){const n=Ju(),t=e.get(lf);return t===void 0?null:u.jsx(lb,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:lf,items:wr.spline,value:t,onValueChange:n})}function nse({styles:e}){const n=Ju(),t=e.get(rf),r=e.get(nf);return!t||!r?null:u.jsx(Xoe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:nf,itemsA:wr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:rf,itemsB:wr.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const fc=[.1,.25,.5,.75,1];function rse(){const e=B(),n=G("opacity",()=>e.getSharedOpacity(),[e]),t=qr(),r=Te(),o=xe.useCallback(i=>{const a=fc[i];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(a),e.setOpacityForNextShapes(a),e.updateInstanceState({isChangingStyle:!0})}),t("set-style",{source:"style-panel",id:"opacity",value:i})},[e,t]);if(n===void 0)return null;const s=n.type==="mixed"?-1:fc.indexOf(M6(fc,i=>Math.abs(i-n.value)));return u.jsx(Voe,{"data-testid":"style.opacity",value:s>=0?s:fc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:fc.length-1,title:r("style-panel.opacity")})}const ose=P.memo(function({isMobile:n,children:t}){const r=B(),o=bR(),s=P.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1})},[r,n]),i=t??u.jsx(Zoe,{styles:o});return u.jsx("div",{className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})});function sse(){const e=B(),n=Te(),t=bR(),r=t==null?void 0:t.get(sr),o=ss({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=G("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=P.useCallback(c=>{c||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:l}=pi();return l?u.jsxs(U0,{id:"mobile style menu",onOpenChange:a,children:[u.jsx(H0,{children:u.jsx(he,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),disabled:i,children:u.jsx(be,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),u.jsx(K0,{side:"top",align:"end",children:l&&u.jsx(l,{isMobile:!0})})]}):null}function ise(){return u.jsxs(u.Fragment,{children:[u.jsx(lse,{}),u.jsx(cse,{}),u.jsx(use,{}),u.jsx(dse,{}),u.jsx(hse,{}),u.jsx(pse,{}),u.jsx(fse,{}),u.jsx(gse,{}),u.jsx(mse,{}),u.jsx(yse,{}),u.jsx(vse,{}),u.jsx(Sse,{}),u.jsx(bse,{}),u.jsx(Ise,{}),u.jsx(xse,{}),u.jsx(Cse,{}),u.jsx(Pse,{}),u.jsx(wse,{}),u.jsx(Ese,{}),u.jsx(kse,{}),u.jsx(_se,{}),u.jsx(Tse,{}),u.jsx(Mse,{}),u.jsx(jse,{}),u.jsx(Ase,{}),u.jsx(Ose,{}),u.jsx(Rse,{}),u.jsx(Dse,{})]})}function ase(e){var r;const n=B(),t=(r=e.meta)==null?void 0:r.geo;return G("is tool selected",()=>{const o=n.getCurrentToolId(),s=n.getSharedStyles().getAsKnownValue(Fr);return t?o==="geo"&&s===t:o===e.id},[n,e.id,t])}function He({tool:e}){const n=Eg(),t=ase(n[e]);return u.jsx(H,{...n[e],isSelected:t})}function lse(){return u.jsx(He,{tool:"select"})}function cse(){return u.jsx(He,{tool:"hand"})}function use(){return u.jsx(He,{tool:"draw"})}function dse(){return u.jsx(He,{tool:"eraser"})}function hse(){return u.jsx(He,{tool:"arrow"})}function pse(){return u.jsx(He,{tool:"text"})}function fse(){return u.jsx(He,{tool:"note"})}function gse(){const e=Eg();return u.jsx(H,{...e.asset})}function mse(){return u.jsx(He,{tool:"rectangle"})}function yse(){return u.jsx(He,{tool:"ellipse"})}function Sse(){return u.jsx(He,{tool:"diamond"})}function vse(){return u.jsx(He,{tool:"triangle"})}function xse(){return u.jsx(He,{tool:"rhombus"})}function wse(){return u.jsx(He,{tool:"heart"})}function bse(){return u.jsx(He,{tool:"hexagon"})}function Pse(){return u.jsx(He,{tool:"cloud"})}function Cse(){return u.jsx(He,{tool:"star"})}function Ise(){return u.jsx(He,{tool:"oval"})}function Ese(){return u.jsx(He,{tool:"x-box"})}function kse(){return u.jsx(He,{tool:"check-box"})}function _se(){return u.jsx(He,{tool:"arrow-left"})}function Tse(){return u.jsx(He,{tool:"arrow-up"})}function Mse(){return u.jsx(He,{tool:"arrow-down"})}function jse(){return u.jsx(He,{tool:"arrow-right"})}function Ase(){return u.jsx(He,{tool:"line"})}function Ose(){return u.jsx(He,{tool:"highlight"})}function Dse(){return u.jsx(He,{tool:"frame"})}function Rse(){return u.jsx(He,{tool:"laser"})}const _y=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Ty(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function gc(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function $R(e,n){const t=n.slice(0,n.length-1);for(let r=0;r<t.length;r++)t[r]=e[t[r].toLowerCase()];return t}function FR(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const n=e.split(",");let t=n.lastIndexOf("");for(;t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function Lse(e,n){const t=e.length>=n.length?e:n,r=e.length>=n.length?n:e;let o=!0;for(let s=0;s<t.length;s++)r.indexOf(t[s])===-1&&(o=!1);return o}const Pu={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,"-":_y?173:189,"=":_y?61:187,";":_y?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},Jv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Ft={16:!1,18:!1,17:!1,91:!1},dt={};for(let e=1;e<20;e++)Pu["f".concat(e)]=111+e;let We=[],Kc=null,NR="all";const Do=new Map,ed=e=>Pu[e.toLowerCase()]||Po[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),$se=e=>Object.keys(Pu).find(n=>Pu[n]===e),Fse=e=>Object.keys(Po).find(n=>Po[n]===e);function zR(e){NR=e||"all"}function Cu(){return NR||"all"}function Nse(){return We.slice(0)}function zse(){return We.map(e=>$se(e)||Fse(e)||String.fromCharCode(e))}function Bse(){const e=[];return Object.keys(dt).forEach(n=>{dt[n].forEach(t=>{let{key:r,scope:o,mods:s,shortcut:i}=t;e.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>ed(a))})})}),e}function Use(e){const n=e.target||e.srcElement,{tagName:t}=n;let r=!0;const o=t==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(n.type);return(n.isContentEditable||(o||t==="TEXTAREA"||t==="SELECT")&&!n.readOnly)&&(r=!1),r}function Hse(e){return typeof e=="string"&&(e=ed(e)),We.indexOf(e)!==-1}function Kse(e,n){let t,r;e||(e=Cu());for(const o in dt)if(Object.prototype.hasOwnProperty.call(dt,o))for(t=dt[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return cb(a)}):r++;Cu()===e&&zR(n||"all")}function Wse(e){let n=e.keyCode||e.which||e.charCode;const t=We.indexOf(n);if(t>=0&&We.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&We.splice(0,We.length),(n===93||n===224)&&(n=91),n in Ft){Ft[n]=!1;for(const r in Po)Po[r]===n&&(Dn[r]=!1)}}function BR(e){if(typeof e>"u")Object.keys(dt).forEach(o=>{Array.isArray(dt[o])&&dt[o].forEach(s=>uh(s)),delete dt[o]}),cb(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&uh(o)});else if(typeof e=="object")e.key&&uh(e);else if(typeof e=="string"){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];let[o,s]=t;typeof o=="function"&&(s=o,o=""),uh({key:e,scope:o,method:s,splitKey:"+"})}}const uh=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;FR(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],d=c==="*"?"*":ed(c);if(!dt[d])return;t||(t=Cu());const h=l>1?$R(Po,a):[],p=[];dt[d]=dt[d].filter(f=>{const g=(r?f.method===r:!0)&&f.scope===t&&Lse(f.mods,h);return g&&p.push(f.element),!g}),p.forEach(f=>cb(f))})};function sE(e,n,t,r){if(n.element!==r)return;let o;if(n.scope===t||n.scope==="all"){o=n.mods.length>0;for(const s in Ft)Object.prototype.hasOwnProperty.call(Ft,s)&&(!Ft[s]&&n.mods.indexOf(+s)>-1||Ft[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!Ft[16]&&!Ft[18]&&!Ft[17]&&!Ft[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(We),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function iE(e,n){const t=dt["*"];let r=e.keyCode||e.which||e.charCode;if(!Dn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),We.indexOf(r)===-1&&r!==229&&We.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=Jv[a];e[a]&&We.indexOf(l)===-1?We.push(l):!e[a]&&We.indexOf(l)>-1?We.splice(We.indexOf(l),1):a==="metaKey"&&e[a]&&We.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(We=We.slice(We.indexOf(l))))}),r in Ft){Ft[r]=!0;for(const a in Po)Po[a]===r&&(Dn[a]=!0);if(!t)return}for(const a in Ft)Object.prototype.hasOwnProperty.call(Ft,a)&&(Ft[a]=e[Jv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(We.indexOf(17)===-1&&We.push(17),We.indexOf(18)===-1&&We.push(18),Ft[17]=!0,Ft[18]=!0);const o=Cu();if(t)for(let a=0;a<t.length;a++)t[a].scope===o&&(e.type==="keydown"&&t[a].keydown||e.type==="keyup"&&t[a].keyup)&&sE(e,t[a],o,n);if(!(r in dt))return;const s=dt[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 l=s[a],{splitKey:c}=l,d=l.key.split(c),h=[];for(let p=0;p<d.length;p++)h.push(ed(d[p]));h.sort().join("")===We.sort().join("")&&sE(e,l,o,n)}}function Dn(e,n,t){We=[];const r=FR(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,d="+",h=!1,p=!1;for(t===void 0&&typeof n=="function"&&(t=n),Object.prototype.toString.call(n)==="[object Object]"&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(l=n.keyup),n.keydown!==void 0&&(c=n.keydown),n.capture!==void 0&&(h=n.capture),typeof n.splitKey=="string"&&(d=n.splitKey),n.single===!0&&(p=!0)),typeof n=="string"&&(s=n),p&&BR(e,s);a<r.length;a++)e=r[a].split(d),o=[],e.length>1&&(o=$R(Po,e)),e=e[e.length-1],e=e==="*"?"*":ed(e),e in dt||(dt[e]=[]),dt[e].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:d,element:i});if(typeof i<"u"&&window){if(!Do.has(i)){const f=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return iE(g,i)},S=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;iE(g,i),Wse(g)};Do.set(i,{keydownListener:f,keyupListenr:S,capture:h}),Ty(i,"keydown",f,h),Ty(i,"keyup",S,h)}if(!Kc){const f=()=>{We=[]};Kc={listener:f,capture:h},Ty(window,"focus",f,h)}}}function Gse(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(dt).forEach(t=>{dt[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function cb(e){const n=Object.values(dt).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=Do.get(e)||{};r&&o&&(gc(e,"keyup",o,s),gc(e,"keydown",r,s),Do.delete(e))}if((n.length<=0||Do.size<=0)&&(Object.keys(Do).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=Do.get(o)||{};s&&i&&(gc(o,"keyup",i,a),gc(o,"keydown",s,a),Do.delete(o))}),Do.clear(),Object.keys(dt).forEach(o=>delete dt[o]),Kc)){const{listener:o,capture:s}=Kc;gc(window,"focus",o,s),Kc=null}}const My={getPressedKeyString:zse,setScope:zR,getScope:Cu,deleteScope:Kse,getPressedKeyCodes:Nse,getAllKeyCodes:Bse,isPressed:Hse,filter:Use,trigger:Gse,unbind:BR,keyMap:Pu,modifier:Po,modifierMap:Jv};for(const e in My)Object.prototype.hasOwnProperty.call(My,e)&&(Dn[e]=My[e]);if(typeof window<"u"){const e=window.hotkeys;Dn.noConflict=n=>(n&&window.hotkeys===Dn&&(window.hotkeys=e),Dn),window.hotkeys=Dn}const aE=["copy","cut","paste","asset"];function Vse(){const e=B(),n=is(),t=ie(),r=Eg(),o=G("is focused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!o)return;const s=new Array,i=(l,c)=>{Dn(l,{element:document.body},c),s.push(()=>{Dn.unbind(l,c)})},a=(l,c)=>{Dn(l,{element:document.body,keyup:!0,keydown:!1},c),s.push(()=>{Dn.unbind(l,c)})};for(const l of Object.values(t))l.kbd&&(n&&!l.readonlyOk||aE.includes(l.id)||i(lE(l.kbd),c=>{_c(e)||(Ee(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&e.getInstanceState().isReadonly||aE.includes(l.id)||i(lE(l.kbd),c=>{_c(e)||(Ee(c),l.onSelect("kbd"))});return i(",",l=>{if(_c(e)||e.inputs.keys.has("Comma"))return;Ee(l),e.focus(),e.inputs.keys.add("Comma");const{x:c,y:d,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:c,y:d,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),a(",",l=>{if(_c(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:c,y:d,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:d,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{s.forEach(l=>l())}},[t,r,n,e,o])}function lE(e){return Yse(e).map(n=>{let t="";const r=n.split("");return r.length===1?t=r[0]:r[0]==="!"?t=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?t=`alt+shift+${r[2]}`:t=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?t=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?t=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:t=`cmd+${r[1]},ctrl+${r[1]}`:t=n,t}).join(",")}function Yse(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const n=e.split(",");let t=n.lastIndexOf("");for(;t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function _c(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const Xse=P.createContext(!1);function qse({children:e}){const n=B(),t=yV(),r=Un(),o=Te(),s=Math.min(8,5+r),[i,a]=P.useState(0),l=P.useRef(null),[c,d]=P.useState(null),h=P.useMemo(()=>{const f=c?`:not([data-value="${c}"])`:"";return`
|
|
#${t}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
|
|
display: none;
|
|
}
|
|
#${t}_more > *:nth-child(-n + ${s}) {
|
|
display: none;
|
|
}
|
|
`},[c,t,s]),p=qw(()=>{if(!l.current)return;const f=Array.from(l.current.children);a(f.length),f.findIndex(x=>x.getAttribute("data-value")===c)<=s&&d(null);const g=Array.from(l.current.children).findIndex(x=>x.getAttribute("aria-checked")==="true");g!==-1&&g>=s&&d(f[g].getAttribute("data-value"))});return P.useLayoutEffect(()=>{p()}),P.useLayoutEffect(()=>{if(!l.current)return;const f=new MutationObserver(p);return f.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{f.disconnect()}},[p]),P.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[S,g]of f)Dn(S,x=>{var b;if(_c(n))return;Ee(x);const v=Array.from(((b=l.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()=>{Dn.unbind("1,2,3,4,5,6,7,8,9,0")}},[n]),u.jsxs(u.Fragment,{children:[u.jsx("style",{children:h}),u.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<yt.TABLET_SM}),role:"radiogroup",children:[u.jsx("div",{id:`${t}_main`,ref:l,className:"tlui-toolbar__tools__list",children:u.jsx(Er,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s+1&&u.jsx(Xse.Provider,{value:!0,children:u.jsxs(Qi,{id:"toolbar overflow",modal:!1,children:[u.jsx(Ji,{children:u.jsx(he,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:u.jsx(be,{icon:"chevron-up"})})}),u.jsx(ea,{side:"top",align:"center",children:u.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:u.jsx(Er,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const Zse=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Qse({activeToolId:e}){const n=B(),t=Un(),r=Te(),o=G("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||Zse.includes(e)?null:u.jsx(he,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ce("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<yt.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:u.jsx(be,{icon:o?"lock":"unlock",small:!0})})}const Jse=P.memo(function({children:n}){const t=B(),r=Un(),o=is(),s=G("current tool id",()=>t.getCurrentToolId(),[t]),{ActionsMenu:i,QuickActions:a}=pi();return u.jsx("div",{className:"tlui-toolbar",children:u.jsxs("div",{className:"tlui-toolbar__inner",children:[u.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&u.jsxs("div",{className:"tlui-toolbar__extras",children:[r<yt.TABLET&&u.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&u.jsx(a,{}),i&&u.jsx(i,{})]}),u.jsx(Qse,{activeToolId:s})]}),u.jsx(qse,{children:n??u.jsx(ise,{})})]}),r<yt.TABLET_SM&&!o&&u.jsx("div",{className:"tlui-toolbar__tools",children:u.jsx(sse,{})})]})})});function eie(){const e=ie();return u.jsxs(u.Fragment,{children:[u.jsx(H,{...e["zoom-in"],noClose:!0}),u.jsx(H,{...e["zoom-out"],noClose:!0}),u.jsx(dR,{}),u.jsx(hR,{}),u.jsx(pR,{})]})}const tie=P.memo(function({children:n}){const t=un(),[r,o]=ui("zoom menu"),s=n??u.jsx(eie,{});return u.jsxs(rb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[u.jsx(ob,{asChild:!0,dir:"ltr",children:u.jsx(nie,{})}),u.jsx(Dg,{container:t,children:u.jsx(sb,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:u.jsx(Er,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),nie=P.forwardRef(function(n,t){const r=B(),o=Un(),s=G("zoom",()=>r.getZoomLevel(),[r]),i=Te(),a=P.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return u.jsx(he,{ref:t,...n,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<yt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<yt.MOBILE?"zoom-in":void 0,children:o<yt.MOBILE?null:u.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),UR=P.createContext(null);function rie({overrides:e={},children:n}){const t=Uw(e);return u.jsx(UR.Provider,{value:P.useMemo(()=>({ContextMenu:Rre,ActionsMenu:ure,HelpMenu:Yre,ZoomMenu:tie,MainMenu:poe,Minimap:voe,StylePanel:ose,PageMenu:Poe,NavigationPanel:woe,Toolbar:Jse,KeyboardShortcutsDialog:toe,QuickActions:Ioe,HelperButtons:Jre,DebugPanel:Ure,DebugMenu:Bre,MenuPanel:foe,...t}),[t]),children:n})}function pi(){const e=P.useContext(UR);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function oie({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return u.jsx(nq,{assetUrls:GQ(t),children:u.jsx(sq,{overrides:ZQ(e),children:u.jsx(lQ,{onEvent:r,children:u.jsx($Q,{children:u.jsx(cQ,{children:u.jsx(YQ,{forceMobile:o,children:u.jsx(rie,{overrides:n,children:u.jsx(sie,{overrides:e,children:s})})})})})})})})}function sie({overrides:e,children:n}){const t=QQ(e);return u.jsx($J,{overrides:t.actions,children:u.jsx(VQ,{overrides:t.tools,children:n})})}function iie(){const e=B(),{addToast:n}=Zr();P.useEffect(()=>{function t({name:r,count:o}){n({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",t),()=>{e.removeListener("max-shapes",t)}},[e,n])}const aie=xe.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return u.jsx(oie,{...s,components:o,children:u.jsx(lie,{hideUi:r,renderDebugMenuItems:n,children:t})})}),lie=xe.memo(function({children:n,hideUi:t,...r}){return u.jsxs(u.Fragment,{children:[n,t?null:u.jsx(uie,{...r}),u.jsx(cie,{})]})});function cie(){const{InFrontOfTheCanvas:e}=it();return e?u.jsx("div",{className:"tl-front",children:u.jsx(e,{})}):null}const uie=xe.memo(function(){const n=B(),t=Te(),r=Un(),o=is(),s=G("focus",()=>n.getInstanceState().isFocusMode,[n]),i=G("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:d,Toolbar:h,HelpMenu:p,NavigationPanel:f,HelperButtons:S,DebugPanel:g}=pi();Vse(),IJ(),iie();const{"toggle-focus-mode":x}=ie();return u.jsxs("div",{className:ce("tlui-layout",{"tlui-layout__mobile":r<yt.TABLET_SM}),"data-breakpoint":r,children:[s?u.jsx("div",{className:"tlui-layout__top",children:u.jsx(he,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>x.onSelect("menu"),children:u.jsx(be,{icon:"dot"})})}):u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"tlui-layout__top",children:[u.jsxs("div",{className:"tlui-layout__top__left",children:[c&&u.jsx(c,{}),S&&u.jsx(S,{})]}),u.jsx("div",{className:"tlui-layout__top__center",children:l&&u.jsx(l,{})}),u.jsxs("div",{className:"tlui-layout__top__right",children:[a&&u.jsx(a,{}),d&&r>=yt.TABLET_SM&&!o&&u.jsx(d,{})]})]}),u.jsxs("div",{className:"tlui-layout__bottom",children:[u.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&u.jsx(f,{}),h&&u.jsx(h,{}),p&&u.jsx(p,{})]}),i&&g&&u.jsx(g,{})]})]}),u.jsx(BQ,{}),u.jsx(hQ,{}),u.jsx(UQ,{}),u.jsx(pQ,{})]})});async function die(e,n){const{url:t,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:d}=n,h={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(e,`url(${t})`,h);return await p.load(),document.fonts.add(p),p.$$_url=t,p.$$_fontface=`
|
|
@font-face {
|
|
font-family: ${p.family};
|
|
font-stretch: ${p.stretch};
|
|
font-weight: ${p.weight};
|
|
font-style: ${p.style};
|
|
src: url("${t}") format("${d}")
|
|
}`,p}const dh=(e,n)=>{const[t,r]=P.useState(2);return P.useEffect(()=>{let o=!1;return r(2),die(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function hie(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 HR(e){const n=P.useMemo(()=>hie(e),[e]),t=[dh("tldraw_draw",n.draw),dh("tldraw_serif",n.serif),dh("tldraw_sans",n.sansSerif),dh("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function pie(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:d=[],...h}=e,p=Uw(a),f=P.useMemo(()=>({Scribble:KC,CollaboratorScribble:KC,SelectionForeground:DV,SelectionBackground:AV,Handles:kV,...p}),[p]),S=Bc(l),g=P.useMemo(()=>[...h0,...S],[S]),x=Bc(c),y=P.useMemo(()=>[...V2,...x],[x]),v=Bc(d),b=P.useMemo(()=>[...jq,...NY,...v],[v]),E="persistenceKey"in h?h.persistenceKey:void 0,I=zA(h.assetUrls),C=P.useMemo(()=>({onResolveAsset:wY(E),...h.assetOptions}),[E,h.assetOptions]),{done:k,error:T}=HR(I);return T?u.jsx(B2,{children:"Could not load assets. Please refresh the page."}):k?u.jsx(uV,{initialState:"select",...h,components:f,shapeUtils:g,bindingUtils:y,tools:b,assetOptions:C,children:u.jsxs(aie,{...h,components:f,children:[u.jsx(fie,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,persistenceKey:E,onMount:i}),n]})}):u.jsx(Jw,{children:u.jsx(Bw,{})})}function fie({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=ww,acceptedVideoMimeTypes:r=_T,onMount:o,persistenceKey:s}){const i=B(),a=Zr(),l=Te(),c=qw(p=>{const f=[];return f.push(...gq(p)),SY(p,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:a,msg:l},s),f.push(o==null?void 0:o(p)),()=>{f.forEach(S=>S==null?void 0:S())}});P.useLayoutEffect(()=>{if(i)return c==null?void 0:c(i)},[i,c]);const{Canvas:d}=it(),{ContextMenu:h}=pi();return h?u.jsx(h,{}):d?u.jsx(d,{}):null}P.memo(function(n){const[t,r]=P.useState(null),[o,s]=P.useState(null),i=Bc(n.shapeUtils??[]),a=P.useMemo(()=>[...h0,...i],[i]),l=Bc(n.bindingUtils??[]),c=P.useMemo(()=>[...V2,...l],[l]),d=F2({snapshot:n.snapshot,shapeUtils:a}),h=zA(),{done:p,error:f}=HR(h),{pageId:S,bounds:g,scale:x,background:y,padding:v,darkMode:b,preserveAspectRatio:E,format:I="svg"}=n;return P.useLayoutEffect(()=>{if(!o||!d||!p)return;let C=!1;const k=document.createElement("div");o.appendChild(k),o.classList.add("tl-container","tl-theme__light");const T=new Q({store:d,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>k});S&&T.setCurrentPage(S);const O=T.getCurrentPageShapeIds();async function _(){const j=await T.getSvgString([...O],{bounds:g,scale:x,background:y,padding:v,darkMode:b,preserveAspectRatio:E});if(j&&!C){if(I==="svg"){if(!C){const L=new Blob([j.svg],{type:"image/svg+xml"}),A=URL.createObjectURL(L);r(A)}}else if(I==="png"){const L=await qA(T,j.svg,{type:I,quality:1,scale:2,width:j.width,height:j.height});if(L&&!C){const A=URL.createObjectURL(L);r(A)}}}T.dispose()}return _(),()=>{C=!0}},[I,o,d,a,c,S,g,x,y,v,b,E,p,f]),f?u.jsx(B2,{children:"Could not load assets."}):p?u.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&u.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):u.jsx(Jw,{children:u.jsx(Bw,{})})});const gie=Se({schemaVersion:cn(1),storeVersion:Th,recordVersions:ef(pe,Se({version:Th,subTypeVersions:ef(pe,Th).optional(),subTypeKey:pe.optional()}))}),mie=Se({schemaVersion:cn(2),sequences:ef(pe,Th)});Se({tldrawFileFormatVersion:$H,schema:FH("schemaVersion",{1:gie,2:mie}),records:zt(Se({id:pe,typeName:pe}).allowUnknownProperties())});function D(e,n={}){const t=typeof e=="string"?e:e.src;if(typeof n=="function")return n(t);const{baseUrl:r=""}=n;return t.startsWith("data:")||t.match(/^https?:\/\//)?t:`${r.replace(/\/$/,"")}/${t.replace(/^\.?\//,"")}`}function yie(e){return{fonts:{monospace:D("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:D("./fonts/IBMPlexSans-Medium.woff2",e),serif:D("./fonts/IBMPlexSerif-Medium.woff2",e),draw:D("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom":D("./icons/icon/align-bottom.svg",e),"align-center-horizontal":D("./icons/icon/align-center-horizontal.svg",e),"align-center-vertical":D("./icons/icon/align-center-vertical.svg",e),"align-left":D("./icons/icon/align-left.svg",e),"align-right":D("./icons/icon/align-right.svg",e),"align-top":D("./icons/icon/align-top.svg",e),"arrow-left":D("./icons/icon/arrow-left.svg",e),"arrowhead-arrow":D("./icons/icon/arrowhead-arrow.svg",e),"arrowhead-bar":D("./icons/icon/arrowhead-bar.svg",e),"arrowhead-diamond":D("./icons/icon/arrowhead-diamond.svg",e),"arrowhead-dot":D("./icons/icon/arrowhead-dot.svg",e),"arrowhead-none":D("./icons/icon/arrowhead-none.svg",e),"arrowhead-square":D("./icons/icon/arrowhead-square.svg",e),"arrowhead-triangle-inverted":D("./icons/icon/arrowhead-triangle-inverted.svg",e),"arrowhead-triangle":D("./icons/icon/arrowhead-triangle.svg",e),blob:D("./icons/icon/blob.svg",e),"bring-forward":D("./icons/icon/bring-forward.svg",e),"bring-to-front":D("./icons/icon/bring-to-front.svg",e),broken:D("./icons/icon/broken.svg",e),"check-circle":D("./icons/icon/check-circle.svg",e),check:D("./icons/icon/check.svg",e),"chevron-down":D("./icons/icon/chevron-down.svg",e),"chevron-left":D("./icons/icon/chevron-left.svg",e),"chevron-right":D("./icons/icon/chevron-right.svg",e),"chevron-up":D("./icons/icon/chevron-up.svg",e),"chevrons-ne":D("./icons/icon/chevrons-ne.svg",e),"chevrons-sw":D("./icons/icon/chevrons-sw.svg",e),"clipboard-copied":D("./icons/icon/clipboard-copied.svg",e),"clipboard-copy":D("./icons/icon/clipboard-copy.svg",e),color:D("./icons/icon/color.svg",e),"cross-2":D("./icons/icon/cross-2.svg",e),"cross-circle":D("./icons/icon/cross-circle.svg",e),"dash-dashed":D("./icons/icon/dash-dashed.svg",e),"dash-dotted":D("./icons/icon/dash-dotted.svg",e),"dash-draw":D("./icons/icon/dash-draw.svg",e),"dash-solid":D("./icons/icon/dash-solid.svg",e),disconnected:D("./icons/icon/disconnected.svg",e),discord:D("./icons/icon/discord.svg",e),"distribute-horizontal":D("./icons/icon/distribute-horizontal.svg",e),"distribute-vertical":D("./icons/icon/distribute-vertical.svg",e),dot:D("./icons/icon/dot.svg",e),"dots-horizontal":D("./icons/icon/dots-horizontal.svg",e),"dots-vertical":D("./icons/icon/dots-vertical.svg",e),"drag-handle-dots":D("./icons/icon/drag-handle-dots.svg",e),duplicate:D("./icons/icon/duplicate.svg",e),edit:D("./icons/icon/edit.svg",e),"external-link":D("./icons/icon/external-link.svg",e),"fill-fill":D("./icons/icon/fill-fill.svg",e),"fill-none":D("./icons/icon/fill-none.svg",e),"fill-pattern":D("./icons/icon/fill-pattern.svg",e),"fill-semi":D("./icons/icon/fill-semi.svg",e),"fill-solid":D("./icons/icon/fill-solid.svg",e),follow:D("./icons/icon/follow.svg",e),following:D("./icons/icon/following.svg",e),"font-draw":D("./icons/icon/font-draw.svg",e),"font-mono":D("./icons/icon/font-mono.svg",e),"font-sans":D("./icons/icon/font-sans.svg",e),"font-serif":D("./icons/icon/font-serif.svg",e),"geo-arrow-down":D("./icons/icon/geo-arrow-down.svg",e),"geo-arrow-left":D("./icons/icon/geo-arrow-left.svg",e),"geo-arrow-right":D("./icons/icon/geo-arrow-right.svg",e),"geo-arrow-up":D("./icons/icon/geo-arrow-up.svg",e),"geo-check-box":D("./icons/icon/geo-check-box.svg",e),"geo-cloud":D("./icons/icon/geo-cloud.svg",e),"geo-diamond":D("./icons/icon/geo-diamond.svg",e),"geo-ellipse":D("./icons/icon/geo-ellipse.svg",e),"geo-heart":D("./icons/icon/geo-heart.svg",e),"geo-hexagon":D("./icons/icon/geo-hexagon.svg",e),"geo-octagon":D("./icons/icon/geo-octagon.svg",e),"geo-oval":D("./icons/icon/geo-oval.svg",e),"geo-pentagon":D("./icons/icon/geo-pentagon.svg",e),"geo-rectangle":D("./icons/icon/geo-rectangle.svg",e),"geo-rhombus-2":D("./icons/icon/geo-rhombus-2.svg",e),"geo-rhombus":D("./icons/icon/geo-rhombus.svg",e),"geo-star":D("./icons/icon/geo-star.svg",e),"geo-trapezoid":D("./icons/icon/geo-trapezoid.svg",e),"geo-triangle":D("./icons/icon/geo-triangle.svg",e),"geo-x-box":D("./icons/icon/geo-x-box.svg",e),github:D("./icons/icon/github.svg",e),group:D("./icons/icon/group.svg",e),"horizontal-align-end":D("./icons/icon/horizontal-align-end.svg",e),"horizontal-align-middle":D("./icons/icon/horizontal-align-middle.svg",e),"horizontal-align-start":D("./icons/icon/horizontal-align-start.svg",e),"info-circle":D("./icons/icon/info-circle.svg",e),leading:D("./icons/icon/leading.svg",e),link:D("./icons/icon/link.svg",e),lock:D("./icons/icon/lock.svg",e),menu:D("./icons/icon/menu.svg",e),minus:D("./icons/icon/minus.svg",e),mixed:D("./icons/icon/mixed.svg",e),pack:D("./icons/icon/pack.svg",e),plus:D("./icons/icon/plus.svg",e),"question-mark-circle":D("./icons/icon/question-mark-circle.svg",e),"question-mark":D("./icons/icon/question-mark.svg",e),redo:D("./icons/icon/redo.svg",e),"reset-zoom":D("./icons/icon/reset-zoom.svg",e),"rotate-ccw":D("./icons/icon/rotate-ccw.svg",e),"rotate-cw":D("./icons/icon/rotate-cw.svg",e),"send-backward":D("./icons/icon/send-backward.svg",e),"send-to-back":D("./icons/icon/send-to-back.svg",e),"share-1":D("./icons/icon/share-1.svg",e),"size-extra-large":D("./icons/icon/size-extra-large.svg",e),"size-large":D("./icons/icon/size-large.svg",e),"size-medium":D("./icons/icon/size-medium.svg",e),"size-small":D("./icons/icon/size-small.svg",e),"spline-cubic":D("./icons/icon/spline-cubic.svg",e),"spline-line":D("./icons/icon/spline-line.svg",e),"stack-horizontal":D("./icons/icon/stack-horizontal.svg",e),"stack-vertical":D("./icons/icon/stack-vertical.svg",e),"stretch-horizontal":D("./icons/icon/stretch-horizontal.svg",e),"stretch-vertical":D("./icons/icon/stretch-vertical.svg",e),"text-align-center":D("./icons/icon/text-align-center.svg",e),"text-align-left":D("./icons/icon/text-align-left.svg",e),"text-align-right":D("./icons/icon/text-align-right.svg",e),"toggle-off":D("./icons/icon/toggle-off.svg",e),"toggle-on":D("./icons/icon/toggle-on.svg",e),"tool-arrow":D("./icons/icon/tool-arrow.svg",e),"tool-eraser":D("./icons/icon/tool-eraser.svg",e),"tool-frame":D("./icons/icon/tool-frame.svg",e),"tool-hand":D("./icons/icon/tool-hand.svg",e),"tool-highlight":D("./icons/icon/tool-highlight.svg",e),"tool-laser":D("./icons/icon/tool-laser.svg",e),"tool-line":D("./icons/icon/tool-line.svg",e),"tool-media":D("./icons/icon/tool-media.svg",e),"tool-note":D("./icons/icon/tool-note.svg",e),"tool-pencil":D("./icons/icon/tool-pencil.svg",e),"tool-pointer":D("./icons/icon/tool-pointer.svg",e),"tool-screenshot":D("./icons/icon/tool-screenshot.svg",e),"tool-text":D("./icons/icon/tool-text.svg",e),trash:D("./icons/icon/trash.svg",e),twitter:D("./icons/icon/twitter.svg",e),undo:D("./icons/icon/undo.svg",e),ungroup:D("./icons/icon/ungroup.svg",e),unlock:D("./icons/icon/unlock.svg",e),"vertical-align-end":D("./icons/icon/vertical-align-end.svg",e),"vertical-align-middle":D("./icons/icon/vertical-align-middle.svg",e),"vertical-align-start":D("./icons/icon/vertical-align-start.svg",e),"warning-triangle":D("./icons/icon/warning-triangle.svg",e),"zoom-in":D("./icons/icon/zoom-in.svg",e),"zoom-out":D("./icons/icon/zoom-out.svg",e)},translations:{ar:D("./translations/ar.json",e),ca:D("./translations/ca.json",e),cs:D("./translations/cs.json",e),da:D("./translations/da.json",e),de:D("./translations/de.json",e),en:D("./translations/en.json",e),es:D("./translations/es.json",e),fa:D("./translations/fa.json",e),fi:D("./translations/fi.json",e),fr:D("./translations/fr.json",e),gl:D("./translations/gl.json",e),he:D("./translations/he.json",e),"hi-in":D("./translations/hi-in.json",e),hr:D("./translations/hr.json",e),hu:D("./translations/hu.json",e),id:D("./translations/id.json",e),it:D("./translations/it.json",e),ja:D("./translations/ja.json",e),"ko-kr":D("./translations/ko-kr.json",e),ku:D("./translations/ku.json",e),languages:D("./translations/languages.json",e),main:D("./translations/main.json",e),my:D("./translations/my.json",e),ne:D("./translations/ne.json",e),no:D("./translations/no.json",e),pl:D("./translations/pl.json",e),"pt-br":D("./translations/pt-br.json",e),"pt-pt":D("./translations/pt-pt.json",e),ro:D("./translations/ro.json",e),ru:D("./translations/ru.json",e),sl:D("./translations/sl.json",e),sv:D("./translations/sv.json",e),te:D("./translations/te.json",e),th:D("./translations/th.json",e),tr:D("./translations/tr.json",e),uk:D("./translations/uk.json",e),vi:D("./translations/vi.json",e),"zh-cn":D("./translations/zh-cn.json",e),"zh-tw":D("./translations/zh-tw.json",e)},embedIcons:{codepen:D("./embed-icons/codepen.png",e),codesandbox:D("./embed-icons/codesandbox.png",e),desmos:D("./embed-icons/desmos.png",e),excalidraw:D("./embed-icons/excalidraw.png",e),felt:D("./embed-icons/felt.png",e),figma:D("./embed-icons/figma.png",e),github_gist:D("./embed-icons/github_gist.png",e),google_calendar:D("./embed-icons/google_calendar.png",e),google_maps:D("./embed-icons/google_maps.png",e),google_slides:D("./embed-icons/google_slides.png",e),observable:D("./embed-icons/observable.png",e),replit:D("./embed-icons/replit.png",e),scratch:D("./embed-icons/scratch.png",e),spotify:D("./embed-icons/spotify.png",e),tldraw:D("./embed-icons/tldraw.png",e),val_town:D("./embed-icons/val_town.png",e),vimeo:D("./embed-icons/vimeo.png",e),youtube:D("./embed-icons/youtube.png",e)}}}const Sie=({onSave:e})=>{const n=()=>{e&&e()};return u.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:n,children:u.jsx("img",{src:"./save.svg",alt:"Save",className:"w-6 h-6 inline-block align-middle"})})};function vie(e){if(e===""||e.trim()==="")return!1;try{return btoa(atob(e))==e}catch{return!1}}function xie(e){const n=e.length%4===0?0:4-e.length%4;e+="=".repeat(n);const t=atob(e),r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return new TextDecoder("utf-8").decode(r)}const mc="PERSISTENCE_KEY";function wie(){const e=yie({baseUrl:"./static/"});localStorage.removeItem(mc);const[n]=P.useState(()=>$2({shapeUtils:h0})),[t,r]=P.useState({status:"loading"}),[o,s]=P.useState(!1),[i,a]=P.useState("未命名白板"),l=p=>{a(p.target.value)},c=()=>{s(!0)},d=()=>{i.trim()===""?alert("请输入标题!"):s(!1)};P.useLayoutEffect(()=>{r({status:"loading"});const p=localStorage.getItem(mc);if(p)try{const g=JSON.parse(p);n.loadSnapshot(g),r({status:"ready"})}catch(g){r({status:"error",error:g.message})}else r({status:"ready"});const f=g=>{try{const x=g.data;if(x.type==="start"&&x.title){const y=x.title.substring(0,x.title.lastIndexOf("."));y&&a(y)}if(x.type==="init"){const y=x.data;if(!y||!y.title)return;const v=y.title.substring(0,y.title.lastIndexOf("."));a(v),y.content&&(typeof y.content=="string"&&vie(y.content)&&(y.content=xie(y.content),y.content=JSON.parse(y.content)),n.loadSnapshot(y.content),localStorage.setItem(mc,JSON.stringify(y.content)))}}catch(x){console.log(x)}};window.parent.postMessage({type:"initSuccess"},"*"),window.addEventListener("message",f);const S=n.listen(fw(()=>{const g=n.getSnapshot();localStorage.setItem(mc,JSON.stringify(g))},200));return()=>{S(),window.removeEventListener("unload",f)}},[n]);const h=()=>{const p=localStorage.getItem(mc)||"{}",f={title:i,content:JSON.parse(p)};console.log(f);const S={data:JSON.stringify(f),type:"exportBaiban"};window.parent.postMessage(S,"*")};return t.status==="loading"?u.jsx("div",{className:"tldraw__editor",children:u.jsx("h2",{children:"Loading..."})}):t.status==="error"?u.jsxs("div",{className:"tldraw__editor",children:[u.jsx("h2",{children:"Error!"}),u.jsx("p",{children:t.error})]}):u.jsxs("div",{className:"tldraw__editor",children:[u.jsxs("div",{style:{position:"absolute",zIndex:2e3,top:3,left:"calc(50% - 90px)",display:"flex",alignItems:"center"},children:[u.jsx(Sie,{onSave:()=>h()}),u.jsx("div",{className:"flex items-center bottom-12 right-4 space-x-2",children:o?u.jsx("input",{type:"text",value:i,onChange:l,onBlur:d,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"}}):u.jsx("span",{onClick:c,className:"cursor-pointer select-none text-gray-400 hover:text-gray-600 transition duration-200 ease-in-out mt-2",children:i})})]}),u.jsx(pie,{assetUrls:e,persistenceKey:"my-persistence-key",store:n})]})}try{Zy.createRoot(document.getElementById("root")).render(u.jsx(xe.StrictMode,{children:u.jsx(wie,{})}))}catch(e){console.log(e)}
|