@kitschpatrol/tldraw-cli 4.6.6 → 4.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,327 @@
1
+ var ZL=Object.defineProperty;var QL=(e,n,t)=>n in e?ZL(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var g=(e,n,t)=>QL(e,typeof n!="symbol"?n+"":n,t);function JL(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 lE={exports:{}},Tf={},cE={exports:{}},xe={};/**
2
+ * @license React
3
+ * react.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var Cu=Symbol.for("react.element"),e$=Symbol.for("react.portal"),t$=Symbol.for("react.fragment"),n$=Symbol.for("react.strict_mode"),r$=Symbol.for("react.profiler"),o$=Symbol.for("react.provider"),s$=Symbol.for("react.context"),i$=Symbol.for("react.forward_ref"),a$=Symbol.for("react.suspense"),l$=Symbol.for("react.memo"),c$=Symbol.for("react.lazy"),kb=Symbol.iterator;function u$(e){return e===null||typeof e!="object"?null:(e=kb&&e[kb]||e["@@iterator"],typeof e=="function"?e:null)}var uE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},dE=Object.assign,hE={};function Il(e,n,t){this.props=e,this.context=n,this.refs=hE,this.updater=t||uE}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 pE(){}pE.prototype=Il.prototype;function tx(e,n,t){this.props=e,this.context=n,this.refs=hE,this.updater=t||uE}var nx=tx.prototype=new pE;nx.constructor=tx;dE(nx,Il.prototype);nx.isPureReactComponent=!0;var _b=Array.isArray,fE=Object.prototype.hasOwnProperty,rx={current:null},gE={key:!0,ref:!0,__self:!0,__source:!0};function mE(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)fE.call(n,r)&&!gE.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:Cu,type:e,key:s,ref:i,props:o,_owner:rx.current}}function d$(e,n){return{$$typeof:Cu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function ox(e){return typeof e=="object"&&e!==null&&e.$$typeof===Cu}function h$(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var Tb=/\/+/g;function Gg(e,n){return typeof e=="object"&&e!==null&&e.key!=null?h$(""+e.key):n.toString(36)}function ph(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 Cu:case e$:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+Gg(i,0):r,_b(o)?(t="",e!=null&&(t=e.replace(Tb,"$&/")+"/"),ph(o,n,t,"",function(c){return c})):o!=null&&(ox(o)&&(o=d$(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(Tb,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",_b(e))for(var a=0;a<e.length;a++){s=e[a];var l=r+Gg(s,a);i+=ph(s,n,t,l,o)}else if(l=u$(e),typeof l=="function")for(e=l.call(e),a=0;!(s=e.next()).done;)s=s.value,l=r+Gg(s,a++),i+=ph(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 ld(e,n,t){if(e==null)return e;var r=[],o=0;return ph(e,r,"","",function(s){return n.call(t,s,o++)}),r}function p$(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 Sn={current:null},fh={transition:null},f$={ReactCurrentDispatcher:Sn,ReactCurrentBatchConfig:fh,ReactCurrentOwner:rx};function yE(){throw Error("act(...) is not supported in production builds of React.")}xe.Children={map:ld,forEach:function(e,n,t){ld(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return ld(e,function(){n++}),n},toArray:function(e){return ld(e,function(n){return n})||[]},only:function(e){if(!ox(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};xe.Component=Il;xe.Fragment=t$;xe.Profiler=r$;xe.PureComponent=tx;xe.StrictMode=n$;xe.Suspense=a$;xe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=f$;xe.act=yE;xe.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=dE({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=rx.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in n)fE.call(n,l)&&!gE.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:Cu,type:e.type,key:o,ref:s,props:r,_owner:i}};xe.createContext=function(e){return e={$$typeof:s$,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:o$,_context:e},e.Consumer=e};xe.createElement=mE;xe.createFactory=function(e){var n=mE.bind(null,e);return n.type=e,n};xe.createRef=function(){return{current:null}};xe.forwardRef=function(e){return{$$typeof:i$,render:e}};xe.isValidElement=ox;xe.lazy=function(e){return{$$typeof:c$,_payload:{_status:-1,_result:e},_init:p$}};xe.memo=function(e,n){return{$$typeof:l$,type:e,compare:n===void 0?null:n}};xe.startTransition=function(e){var n=fh.transition;fh.transition={};try{e()}finally{fh.transition=n}};xe.unstable_act=yE;xe.useCallback=function(e,n){return Sn.current.useCallback(e,n)};xe.useContext=function(e){return Sn.current.useContext(e)};xe.useDebugValue=function(){};xe.useDeferredValue=function(e){return Sn.current.useDeferredValue(e)};xe.useEffect=function(e,n){return Sn.current.useEffect(e,n)};xe.useId=function(){return Sn.current.useId()};xe.useImperativeHandle=function(e,n,t){return Sn.current.useImperativeHandle(e,n,t)};xe.useInsertionEffect=function(e,n){return Sn.current.useInsertionEffect(e,n)};xe.useLayoutEffect=function(e,n){return Sn.current.useLayoutEffect(e,n)};xe.useMemo=function(e,n){return Sn.current.useMemo(e,n)};xe.useReducer=function(e,n,t){return Sn.current.useReducer(e,n,t)};xe.useRef=function(e){return Sn.current.useRef(e)};xe.useState=function(e){return Sn.current.useState(e)};xe.useSyncExternalStore=function(e,n,t){return Sn.current.useSyncExternalStore(e,n,t)};xe.useTransition=function(){return Sn.current.useTransition()};xe.version="18.3.1";cE.exports=xe;var P=cE.exports;const we=ei(P),g$=JL({__proto__:null,default:we},[P]);/**
10
+ * @license React
11
+ * react-jsx-runtime.production.min.js
12
+ *
13
+ * Copyright (c) Facebook, Inc. and its affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var m$=P,y$=Symbol.for("react.element"),S$=Symbol.for("react.fragment"),v$=Object.prototype.hasOwnProperty,x$=m$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,w$={key:!0,ref:!0,__self:!0,__source:!0};function SE(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)v$.call(n,r)&&!w$.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:y$,type:e,key:s,ref:i,props:o,_owner:x$.current}}Tf.Fragment=S$;Tf.jsx=SE;Tf.jsxs=SE;lE.exports=Tf;var d=lE.exports;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 b$(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)}}}var Gl=function(e){return e&&e.Math===Math&&e},Bn=Gl(typeof globalThis=="object"&&globalThis)||Gl(typeof window=="object"&&window)||Gl(typeof self=="object"&&self)||Gl(typeof sn=="object"&&sn)||Gl(typeof sn=="object"&&sn)||function(){return this}()||Function("return this")(),sx={},vn=function(e){try{return!!e()}catch{return!0}},P$=vn,ti=!P$(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),C$=vn,Mf=!C$(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),I$=Mf,cd=Function.prototype.call,ss=I$?cd.bind(cd):function(){return cd.apply(cd,arguments)},vE={},xE={}.propertyIsEnumerable,wE=Object.getOwnPropertyDescriptor,E$=wE&&!xE.call({1:2},1);vE.f=E$?function(n){var t=wE(this,n);return!!t&&t.enumerable}:xE;var bE=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},PE=Mf,CE=Function.prototype,Qy=CE.call,k$=PE&&CE.bind.bind(Qy,Qy),Dt=PE?k$:function(e){return function(){return Qy.apply(e,arguments)}},IE=Dt,_$=IE({}.toString),T$=IE("".slice),El=function(e){return T$(_$(e),8,-1)},M$=Dt,A$=vn,j$=El,Vg=Object,O$=M$("".split),D$=A$(function(){return!Vg("z").propertyIsEnumerable(0)})?function(e){return j$(e)==="String"?O$(e,""):Vg(e)}:Vg,Af=function(e){return e==null},R$=Af,L$=TypeError,kl=function(e){if(R$(e))throw new L$("Can't call method on "+e);return e},$$=D$,F$=kl,jf=function(e){return $$(F$(e))},Yg=typeof document=="object"&&document.all,xn=typeof Yg>"u"&&Yg!==void 0?function(e){return typeof e=="function"||e===Yg}:function(e){return typeof e=="function"},N$=xn,ta=function(e){return typeof e=="object"?e!==null:N$(e)},Xg=Bn,z$=xn,B$=function(e){return z$(e)?e:void 0},Of=function(e,n){return arguments.length<2?B$(Xg[e]):Xg[e]&&Xg[e][n]},U$=Dt,EE=U$({}.isPrototypeOf),H$=typeof navigator<"u"&&String(navigator.userAgent)||"",kE=Bn,qg=H$,Mb=kE.process,Ab=kE.Deno,jb=Mb&&Mb.versions||Ab&&Ab.version,Ob=jb&&jb.v8,$r,mp;Ob&&($r=Ob.split("."),mp=$r[0]>0&&$r[0]<4?1:+($r[0]+$r[1]));!mp&&qg&&($r=qg.match(/Edge\/(\d+)/),(!$r||$r[1]>=74)&&($r=qg.match(/Chrome\/(\d+)/),$r&&(mp=+$r[1])));var K$=mp,Db=K$,W$=vn,G$=Bn,V$=G$.String,_E=!!Object.getOwnPropertySymbols&&!W$(function(){var e=Symbol("symbol detection");return!V$(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&Db&&Db<41}),Y$=_E,TE=Y$&&!Symbol.sham&&typeof Symbol.iterator=="symbol",X$=Of,q$=xn,Z$=EE,Q$=TE,J$=Object,ME=Q$?function(e){return typeof e=="symbol"}:function(e){var n=X$("Symbol");return q$(n)&&Z$(n.prototype,J$(e))},eF=String,tF=function(e){try{return eF(e)}catch{return"Object"}},nF=xn,rF=tF,oF=TypeError,ix=function(e){if(nF(e))return e;throw new oF(rF(e)+" is not a function")},sF=ix,iF=Af,ax=function(e,n){var t=e[n];return iF(t)?void 0:sF(t)},Zg=ss,Qg=xn,Jg=ta,aF=TypeError,lF=function(e,n){var t,r;if(n==="string"&&Qg(t=e.toString)&&!Jg(r=Zg(t,e))||Qg(t=e.valueOf)&&!Jg(r=Zg(t,e))||n!=="string"&&Qg(t=e.toString)&&!Jg(r=Zg(t,e)))return r;throw new aF("Can't convert object to primitive value")},AE={exports:{}},Rb=Bn,cF=Object.defineProperty,lx=function(e,n){try{cF(Rb,e,{value:n,configurable:!0,writable:!0})}catch{Rb[e]=n}return n},uF=Bn,dF=lx,Lb="__core-js_shared__",$b=AE.exports=uF[Lb]||dF(Lb,{});($b.versions||($b.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 cx=AE.exports,Fb=cx,ux=function(e,n){return Fb[e]||(Fb[e]=n||{})},hF=kl,pF=Object,Iu=function(e){return pF(hF(e))},fF=Dt,gF=Iu,mF=fF({}.hasOwnProperty),ni=Object.hasOwn||function(n,t){return mF(gF(n),t)},yF=Dt,SF=0,vF=Math.random(),xF=yF(1 .toString),jE=function(e){return"Symbol("+(e===void 0?"":e)+")_"+xF(++SF+vF,36)},wF=Bn,bF=ux,Nb=ni,PF=jE,CF=_E,IF=TE,Ea=wF.Symbol,em=bF("wks"),EF=IF?Ea.for||Ea:Ea&&Ea.withoutSetter||PF,is=function(e){return Nb(em,e)||(em[e]=CF&&Nb(Ea,e)?Ea[e]:EF("Symbol."+e)),em[e]},kF=ss,zb=ta,Bb=ME,_F=ax,TF=lF,MF=is,AF=TypeError,jF=MF("toPrimitive"),OF=function(e,n){if(!zb(e)||Bb(e))return e;var t=_F(e,jF),r;if(t){if(n===void 0&&(n="default"),r=kF(t,e,n),!zb(r)||Bb(r))return r;throw new AF("Can't convert object to primitive value")}return n===void 0&&(n="number"),TF(e,n)},DF=OF,RF=ME,OE=function(e){var n=DF(e,"string");return RF(n)?n:n+""},LF=Bn,Ub=ta,Jy=LF.document,$F=Ub(Jy)&&Ub(Jy.createElement),DE=function(e){return $F?Jy.createElement(e):{}},FF=ti,NF=vn,zF=DE,RE=!FF&&!NF(function(){return Object.defineProperty(zF("div"),"a",{get:function(){return 7}}).a!==7}),BF=ti,UF=ss,HF=vE,KF=bE,WF=jf,GF=OE,VF=ni,YF=RE,Hb=Object.getOwnPropertyDescriptor;sx.f=BF?Hb:function(n,t){if(n=WF(n),t=GF(t),YF)try{return Hb(n,t)}catch{}if(VF(n,t))return KF(!UF(HF.f,n,t),n[t])};var _l={},XF=ti,qF=vn,LE=XF&&qF(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),ZF=ta,QF=String,JF=TypeError,na=function(e){if(ZF(e))return e;throw new JF(QF(e)+" is not an object")},eN=ti,tN=RE,nN=LE,ud=na,Kb=OE,rN=TypeError,tm=Object.defineProperty,oN=Object.getOwnPropertyDescriptor,nm="enumerable",rm="configurable",om="writable";_l.f=eN?nN?function(n,t,r){if(ud(n),t=Kb(t),ud(r),typeof n=="function"&&t==="prototype"&&"value"in r&&om in r&&!r[om]){var o=oN(n,t);o&&o[om]&&(n[t]=r.value,r={configurable:rm in r?r[rm]:o[rm],enumerable:nm in r?r[nm]:o[nm],writable:!1})}return tm(n,t,r)}:tm:function(n,t,r){if(ud(n),t=Kb(t),ud(r),tN)try{return tm(n,t,r)}catch{}if("get"in r||"set"in r)throw new rN("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var sN=ti,iN=_l,aN=bE,dx=sN?function(e,n,t){return iN.f(e,n,aN(1,t))}:function(e,n,t){return e[n]=t,e},$E={exports:{}},eS=ti,lN=ni,FE=Function.prototype,cN=eS&&Object.getOwnPropertyDescriptor,hx=lN(FE,"name"),uN=hx&&(function(){}).name==="something",dN=hx&&(!eS||eS&&cN(FE,"name").configurable),hN={EXISTS:hx,PROPER:uN,CONFIGURABLE:dN},pN=Dt,fN=xn,tS=cx,gN=pN(Function.toString);fN(tS.inspectSource)||(tS.inspectSource=function(e){return gN(e)});var NE=tS.inspectSource,mN=Bn,yN=xn,Wb=mN.WeakMap,SN=yN(Wb)&&/native code/.test(String(Wb)),vN=ux,xN=jE,Gb=vN("keys"),zE=function(e){return Gb[e]||(Gb[e]=xN(e))},px={},wN=SN,BE=Bn,bN=ta,PN=dx,sm=ni,im=cx,CN=zE,IN=px,Vb="Object already initialized",nS=BE.TypeError,EN=BE.WeakMap,yp,Kc,Sp,kN=function(e){return Sp(e)?Kc(e):yp(e,{})},_N=function(e){return function(n){var t;if(!bN(n)||(t=Kc(n)).type!==e)throw new nS("Incompatible receiver, "+e+" required");return t}};if(wN||im.state){var eo=im.state||(im.state=new EN);eo.get=eo.get,eo.has=eo.has,eo.set=eo.set,yp=function(e,n){if(eo.has(e))throw new nS(Vb);return n.facade=e,eo.set(e,n),n},Kc=function(e){return eo.get(e)||{}},Sp=function(e){return eo.has(e)}}else{var da=CN("state");IN[da]=!0,yp=function(e,n){if(sm(e,da))throw new nS(Vb);return n.facade=e,PN(e,da,n),n},Kc=function(e){return sm(e,da)?e[da]:{}},Sp=function(e){return sm(e,da)}}var UE={set:yp,get:Kc,has:Sp,enforce:kN,getterFor:_N},fx=Dt,TN=vn,MN=xn,dd=ni,rS=ti,AN=hN.CONFIGURABLE,jN=NE,HE=UE,ON=HE.enforce,DN=HE.get,Yb=String,gh=Object.defineProperty,RN=fx("".slice),LN=fx("".replace),$N=fx([].join),FN=rS&&!TN(function(){return gh(function(){},"length",{value:8}).length!==8}),NN=String(String).split("String"),zN=$E.exports=function(e,n,t){RN(Yb(n),0,7)==="Symbol("&&(n="["+LN(Yb(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!dd(e,"name")||AN&&e.name!==n)&&(rS?gh(e,"name",{value:n,configurable:!0}):e.name=n),FN&&t&&dd(t,"arity")&&e.length!==t.arity&&gh(e,"length",{value:t.arity});try{t&&dd(t,"constructor")&&t.constructor?rS&&gh(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=ON(e);return dd(r,"source")||(r.source=$N(NN,typeof n=="string"?n:"")),e};Function.prototype.toString=zN(function(){return MN(this)&&DN(this).source||jN(this)},"toString");var BN=$E.exports,UN=xn,HN=_l,KN=BN,WN=lx,KE=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(UN(t)&&KN(t,s,r),r.global)o?e[n]=t:WN(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:HN.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},WE={},GN=Math.ceil,VN=Math.floor,YN=Math.trunc||function(n){var t=+n;return(t>0?VN:GN)(t)},XN=YN,ra=function(e){var n=+e;return n!==n||n===0?0:XN(n)},qN=ra,ZN=Math.max,QN=Math.min,JN=function(e,n){var t=qN(e);return t<0?ZN(t+n,0):QN(t,n)},ez=ra,tz=Math.min,GE=function(e){var n=ez(e);return n>0?tz(n,9007199254740991):0},nz=GE,Eu=function(e){return nz(e.length)},rz=jf,oz=JN,sz=Eu,Xb=function(e){return function(n,t,r){var o=rz(n),s=sz(o);if(s===0)return!e&&-1;var i=oz(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}},iz={includes:Xb(!0),indexOf:Xb(!1)},az=Dt,am=ni,lz=jf,cz=iz.indexOf,uz=px,qb=az([].push),VE=function(e,n){var t=lz(e),r=0,o=[],s;for(s in t)!am(uz,s)&&am(t,s)&&qb(o,s);for(;n.length>r;)am(t,s=n[r++])&&(~cz(o,s)||qb(o,s));return o},gx=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],dz=VE,hz=gx,pz=hz.concat("length","prototype");WE.f=Object.getOwnPropertyNames||function(n){return dz(n,pz)};var YE={};YE.f=Object.getOwnPropertySymbols;var fz=Of,gz=Dt,mz=WE,yz=YE,Sz=na,vz=gz([].concat),xz=fz("Reflect","ownKeys")||function(n){var t=mz.f(Sz(n)),r=yz.f;return r?vz(t,r(n)):t},Zb=ni,wz=xz,bz=sx,Pz=_l,Cz=function(e,n,t){for(var r=wz(n),o=Pz.f,s=bz.f,i=0;i<r.length;i++){var a=r[i];!Zb(e,a)&&!(t&&Zb(t,a))&&o(e,a,s(n,a))}},Iz=vn,Ez=xn,kz=/#|\.prototype\./,ku=function(e,n){var t=Tz[_z(e)];return t===Az?!0:t===Mz?!1:Ez(n)?Iz(n):!!n},_z=ku.normalize=function(e){return String(e).replace(kz,".").toLowerCase()},Tz=ku.data={},Mz=ku.NATIVE="N",Az=ku.POLYFILL="P",jz=ku,hd=Bn,Oz=sx.f,Dz=dx,Rz=KE,Lz=lx,$z=Cz,Fz=jz,Tl=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,l,c,u;if(r?i=hd:o?i=hd[t]||Lz(t,{}):i=hd[t]&&hd[t].prototype,i)for(a in n){if(c=n[a],e.dontCallGetSet?(u=Oz(i,a),l=u&&u.value):l=i[a],s=Fz(r?a:t+(o?".":"#")+a,e.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;$z(c,l)}(e.sham||l&&l.sham)&&Dz(c,"sham",!0),Rz(i,a,c,e)}},XE={},Nz=VE,zz=gx,Bz=Object.keys||function(n){return Nz(n,zz)},Uz=ti,Hz=LE,Kz=_l,Wz=na,Gz=jf,Vz=Bz;XE.f=Uz&&!Hz?Object.defineProperties:function(n,t){Wz(n);for(var r=Gz(t),o=Vz(t),s=o.length,i=0,a;s>i;)Kz.f(n,a=o[i++],r[a]);return n};var Yz=Of,Xz=Yz("document","documentElement"),qz=na,Zz=XE,Qb=gx,Qz=px,Jz=Xz,e3=DE,t3=zE,Jb=">",e1="<",oS="prototype",sS="script",qE=t3("IE_PROTO"),lm=function(){},ZE=function(e){return e1+sS+Jb+e+e1+"/"+sS+Jb},t1=function(e){e.write(ZE("")),e.close();var n=e.parentWindow.Object;return e=null,n},n3=function(){var e=e3("iframe"),n="java"+sS+":",t;return e.style.display="none",Jz.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(ZE("document.F=Object")),t.close(),t.F},pd,mh=function(){try{pd=new ActiveXObject("htmlfile")}catch{}mh=typeof document<"u"?document.domain&&pd?t1(pd):n3():t1(pd);for(var e=Qb.length;e--;)delete mh[oS][Qb[e]];return mh()};Qz[qE]=!0;var QE=Object.create||function(n,t){var r;return n!==null?(lm[oS]=qz(n),r=new lm,lm[oS]=null,r[qE]=n):r=mh(),t===void 0?r:Zz.f(r,t)},r3=is,o3=QE,s3=_l.f,iS=r3("unscopables"),aS=Array.prototype;aS[iS]===void 0&&s3(aS,iS,{configurable:!0,value:o3(null)});var mx=function(e){aS[iS][e]=!0},i3=Tl,a3=Iu,l3=Eu,c3=ra,u3=mx;i3({target:"Array",proto:!0},{at:function(n){var t=a3(this),r=l3(t),o=c3(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});u3("at");var d3=Bn,h3=Dt,_u=function(e,n){return h3(d3[e].prototype[n])},p3=_u;p3("Array","at");var f3=El,JE=Array.isArray||function(n){return f3(n)==="Array"},g3=TypeError,m3=9007199254740991,y3=function(e){if(e>m3)throw g3("Maximum allowed index exceeded");return e},S3=El,v3=Dt,x3=function(e){if(S3(e)==="Function")return v3(e)},n1=x3,w3=ix,b3=Mf,P3=n1(n1.bind),C3=function(e,n){return w3(e),n===void 0?e:b3?P3(e,n):function(){return e.apply(n,arguments)}},I3=JE,E3=Eu,k3=y3,_3=C3,ek=function(e,n,t,r,o,s,i,a){for(var l=o,c=0,u=i?_3(i,a):!1,h,p;c<r;)c in t&&(h=u?u(t[c],c,n):t[c],s>0&&I3(h)?(p=E3(h),l=ek(e,n,h,p,l,s-1)-1):(k3(l+1),e[l]=h),l++),c++;return l},tk=ek,T3=is,M3=T3("toStringTag"),nk={};nk[M3]="z";var A3=String(nk)==="[object z]",j3=A3,O3=xn,yh=El,D3=is,R3=D3("toStringTag"),L3=Object,$3=yh(function(){return arguments}())==="Arguments",F3=function(e,n){try{return e[n]}catch{}},rk=j3?yh:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=F3(n=L3(e),R3))=="string"?t:$3?yh(n):(r=yh(n))==="Object"&&O3(n.callee)?"Arguments":r},N3=Dt,z3=vn,ok=xn,B3=rk,U3=Of,H3=NE,sk=function(){},ik=U3("Reflect","construct"),yx=/^\s*(?:class|function)\b/,K3=N3(yx.exec),W3=!yx.test(sk),Vl=function(n){if(!ok(n))return!1;try{return ik(sk,[],n),!0}catch{return!1}},ak=function(n){if(!ok(n))return!1;switch(B3(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return W3||!!K3(yx,H3(n))}catch{return!0}};ak.sham=!0;var G3=!ik||z3(function(){var e;return Vl(Vl.call)||!Vl(Object)||!Vl(function(){e=!0})||e})?ak:Vl,r1=JE,V3=G3,Y3=ta,X3=is,q3=X3("species"),o1=Array,Z3=function(e){var n;return r1(e)&&(n=e.constructor,V3(n)&&(n===o1||r1(n.prototype))?n=void 0:Y3(n)&&(n=n[q3],n===null&&(n=void 0))),n===void 0?o1:n},Q3=Z3,lk=function(e,n){return new(Q3(e))(n===0?0:n)},J3=Tl,eB=tk,tB=ix,nB=Iu,rB=Eu,oB=lk;J3({target:"Array",proto:!0},{flatMap:function(n){var t=nB(this),r=rB(t),o;return tB(n),o=oB(t,0),o.length=eB(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var sB=mx;sB("flatMap");var iB=_u;iB("Array","flatMap");var aB=Tl,lB=tk,cB=Iu,uB=Eu,dB=ra,hB=lk;aB({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=cB(this),r=uB(t),o=hB(t,0);return o.length=lB(o,t,t,r,0,n===void 0?1:dB(n)),o}});var pB=mx;pB("flat");var fB=_u;fB("Array","flat");var gB=rk,mB=String,Tu=function(e){if(gB(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return mB(e)},yB=Tl,SB=Dt,vB=kl,xB=ra,wB=Tu,bB=vn,PB=SB("".charAt),CB=bB(function(){return"𠮷".at(-2)!=="\uD842"});yB({target:"String",proto:!0,forced:CB},{at:function(n){var t=wB(vB(this)),r=t.length,o=xB(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:PB(t,s)}});var IB=_u;IB("String","at");var EB=na,ck=function(){var e=EB(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},Sx=vn,kB=Bn,vx=kB.RegExp,xx=Sx(function(){var e=vx("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),_B=xx||Sx(function(){return!vx("a","y").sticky}),TB=xx||Sx(function(){var e=vx("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),MB={BROKEN_CARET:TB,MISSED_STICKY:_B,UNSUPPORTED_Y:xx},AB=vn,jB=Bn,OB=jB.RegExp,DB=AB(function(){var e=OB(".","s");return!(e.dotAll&&e.test(`
18
+ `)&&e.flags==="s")}),RB=vn,LB=Bn,$B=LB.RegExp,FB=RB(function(){var e=$B("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),ka=ss,Df=Dt,NB=Tu,zB=ck,BB=MB,UB=ux,HB=QE,KB=UE.get,WB=DB,GB=FB,VB=UB("native-string-replace",String.prototype.replace),vp=RegExp.prototype.exec,lS=vp,YB=Df("".charAt),XB=Df("".indexOf),qB=Df("".replace),cm=Df("".slice),cS=function(){var e=/a/,n=/b*/g;return ka(vp,e,"a"),ka(vp,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),uk=BB.BROKEN_CARET,uS=/()??/.exec("")[1]!==void 0,ZB=cS||uS||uk||WB||GB;ZB&&(lS=function(n){var t=this,r=KB(t),o=NB(n),s=r.raw,i,a,l,c,u,h,p;if(s)return s.lastIndex=t.lastIndex,i=ka(lS,s,o),t.lastIndex=s.lastIndex,i;var f=r.groups,y=uk&&t.sticky,m=ka(zB,t),x=t.source,S=0,v=o;if(y&&(m=qB(m,"y",""),XB(m,"g")===-1&&(m+="g"),v=cm(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&YB(o,t.lastIndex-1)!==`
19
+ `)&&(x="(?: "+x+")",v=" "+v,S++),a=new RegExp("^(?:"+x+")",m)),uS&&(a=new RegExp("^"+x+"$(?!\\s)",m)),cS&&(l=t.lastIndex),c=ka(vp,y?a:t,v),y?c?(c.input=cm(c.input,S),c[0]=cm(c[0],S),c.index=t.lastIndex,t.lastIndex+=c[0].length):t.lastIndex=0:cS&&c&&(t.lastIndex=t.global?c.index+c[0].length:l),uS&&c&&c.length>1&&ka(VB,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&f)for(c.groups=h=HB(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var wx=lS,QB=Tl,s1=wx;QB({target:"RegExp",proto:!0,forced:/./.exec!==s1},{exec:s1});var JB=Mf,dk=Function.prototype,i1=dk.apply,a1=dk.call,e5=typeof Reflect=="object"&&Reflect.apply||(JB?a1.bind(i1):function(){return a1.apply(i1,arguments)}),l1=ss,c1=KE,t5=wx,u1=vn,hk=is,n5=dx,r5=hk("species"),um=RegExp.prototype,o5=function(e,n,t,r){var o=hk(e),s=!u1(function(){var c={};return c[o]=function(){return 7},""[e](c)!==7}),i=s&&!u1(function(){var c=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[r5]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return c=!0,null},u[o](""),!c});if(!s||!i||t){var a=/./[o],l=n(o,""[e],function(c,u,h,p,f){var y=u.exec;return y===t5||y===um.exec?s&&!f?{done:!0,value:l1(a,u,h,p)}:{done:!0,value:l1(c,h,u,p)}:{done:!1}});c1(String.prototype,e,l[0]),c1(um,o,l[1])}r&&n5(um[o],"sham",!0)},bx=Dt,s5=ra,i5=Tu,a5=kl,l5=bx("".charAt),d1=bx("".charCodeAt),c5=bx("".slice),h1=function(e){return function(n,t){var r=i5(a5(n)),o=s5(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=d1(r,o),i<55296||i>56319||o+1===s||(a=d1(r,o+1))<56320||a>57343?e?l5(r,o):i:e?c5(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},u5={codeAt:h1(!1),charAt:h1(!0)},d5=u5.charAt,h5=function(e,n,t){return n+(t?d5(e,n).length:1)},Px=Dt,p5=Iu,f5=Math.floor,dm=Px("".charAt),g5=Px("".replace),hm=Px("".slice),m5=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,y5=/\$([$&'`]|\d{1,2})/g,pk=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,l=y5;return o!==void 0&&(o=p5(o),l=m5),g5(s,l,function(c,u){var h;switch(dm(u,0)){case"$":return"$";case"&":return e;case"`":return hm(n,0,t);case"'":return hm(n,i);case"<":h=o[hm(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=f5(p/10);return f===0?c:f<=a?r[f-1]===void 0?dm(u,1):r[f-1]+dm(u,1):c}h=r[p-1]}return h===void 0?"":h})},p1=ss,S5=na,v5=xn,x5=El,w5=wx,b5=TypeError,P5=function(e,n){var t=e.exec;if(v5(t)){var r=p1(t,e,n);return r!==null&&S5(r),r}if(x5(e)==="RegExp")return p1(w5,e,n);throw new b5("RegExp#exec called on incompatible receiver")},C5=e5,f1=ss,Rf=Dt,I5=o5,E5=vn,k5=na,_5=xn,T5=Af,M5=ra,A5=GE,ha=Tu,j5=kl,O5=h5,D5=ax,R5=pk,L5=P5,$5=is,dS=$5("replace"),F5=Math.max,N5=Math.min,z5=Rf([].concat),pm=Rf([].push),g1=Rf("".indexOf),m1=Rf("".slice),B5=function(e){return e===void 0?e:String(e)},U5=function(){return"a".replace(/./,"$0")==="$0"}(),y1=function(){return/./[dS]?/./[dS]("a","$0")==="":!1}(),H5=!E5(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});I5("replace",function(e,n,t){var r=y1?"$":"$0";return[function(s,i){var a=j5(this),l=T5(s)?void 0:D5(s,dS);return l?f1(l,s,a,i):f1(n,ha(a),s,i)},function(o,s){var i=k5(this),a=ha(o);if(typeof s=="string"&&g1(s,r)===-1&&g1(s,"$<")===-1){var l=t(n,i,a,s);if(l.done)return l.value}var c=_5(s);c||(s=ha(s));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=L5(i,a),!(f===null||(pm(p,f),!u));){var y=ha(f[0]);y===""&&(i.lastIndex=O5(a,A5(i.lastIndex),h))}for(var m="",x=0,S=0;S<p.length;S++){f=p[S];for(var v=ha(f[0]),b=F5(N5(M5(f.index),a.length),0),E=[],k,C=1;C<f.length;C++)pm(E,B5(f[C]));var I=f.groups;if(c){var T=z5([v],E,b,a);I!==void 0&&pm(T,I),k=ha(C5(s,void 0,T))}else k=R5(v,a,b,E,I,s);b>=x&&(m+=m1(a,x,b)+k,x=b+v.length)}return m+m1(a,x)}]},!H5||!U5||y1);var K5=ta,W5=El,G5=is,V5=G5("match"),Y5=function(e){var n;return K5(e)&&((n=e[V5])!==void 0?!!n:W5(e)==="RegExp")},X5=ss,q5=ni,Z5=EE,Q5=ck,S1=RegExp.prototype,J5=function(e){var n=e.flags;return n===void 0&&!("flags"in S1)&&!q5(e,"flags")&&Z5(S1,e)?X5(Q5,e):n},eU=Tl,tU=ss,Cx=Dt,v1=kl,nU=xn,rU=Af,oU=Y5,Yl=Tu,sU=ax,iU=J5,aU=pk,lU=is,cU=lU("replace"),uU=TypeError,fm=Cx("".indexOf);Cx("".replace);var x1=Cx("".slice),dU=Math.max;eU({target:"String",proto:!0},{replaceAll:function(n,t){var r=v1(this),o,s,i,a,l,c,u,h,p,f=0,y=0,m="";if(!rU(n)){if(o=oU(n),o&&(s=Yl(v1(iU(n))),!~fm(s,"g")))throw new uU("`.replaceAll` does not allow non-global regexes");if(i=sU(n,cU),i)return tU(i,n,r,t)}for(a=Yl(r),l=Yl(n),c=nU(t),c||(t=Yl(t)),u=l.length,h=dU(1,u),f=fm(a,l);f!==-1;)p=c?Yl(t(l,f,a)):aU(l,a,f,[],void 0,t),m+=x1(a,y,f)+p,y=f+u,f=f+h>a.length?-1:fm(a,l,f+h);return y<a.length&&(m+=x1(a,y)),m}});var hU=_u;hU("String","replaceAll");class Sh{constructor(n){g(this,"nextValue");g(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 fk="Expected a function",w1=NaN,pU="[object Symbol]",fU=/^\s+|\s+$/g,gU=/^[-+]0x[0-9a-f]+$/i,mU=/^0b[01]+$/i,yU=/^0o[0-7]+$/i,SU=parseInt,vU=typeof sn=="object"&&sn&&sn.Object===Object&&sn,xU=typeof self=="object"&&self&&self.Object===Object&&self,wU=vU||xU||Function("return this")(),bU=Object.prototype,PU=bU.toString,CU=Math.max,IU=Math.min,gm=function(){return wU.Date.now()};function EU(e,n,t){var r,o,s,i,a,l,c=0,u=!1,h=!1,p=!0;if(typeof e!="function")throw new TypeError(fk);n=b1(n)||0,xp(t)&&(u=!!t.leading,h="maxWait"in t,s=h?CU(b1(t.maxWait)||0,n):s,p="trailing"in t?!!t.trailing:p);function f(C){var I=r,T=o;return r=o=void 0,c=C,i=e.apply(T,I),i}function y(C){return c=C,a=setTimeout(S,n),u?f(C):i}function m(C){var I=C-l,T=C-c,O=n-I;return h?IU(O,s-T):O}function x(C){var I=C-l,T=C-c;return l===void 0||I>=n||I<0||h&&T>=s}function S(){var C=gm();if(x(C))return v(C);a=setTimeout(S,m(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(gm())}function k(){var C=gm(),I=x(C);if(r=arguments,o=this,l=C,I){if(a===void 0)return y(l);if(h)return a=setTimeout(S,n),f(l)}return a===void 0&&(a=setTimeout(S,n)),i}return k.cancel=b,k.flush=E,k}function kU(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(fk);return xp(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),EU(e,n,{leading:r,maxWait:n,trailing:o})}function xp(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function _U(e){return!!e&&typeof e=="object"}function TU(e){return typeof e=="symbol"||_U(e)&&PU.call(e)==pU}function b1(e){if(typeof e=="number")return e;if(TU(e))return w1;if(xp(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=xp(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(fU,"");var t=mU.test(e);return t||yU.test(e)?SU(e.slice(2),t?2:8):gU.test(e)?w1:+e}var MU=kU;const gk=ei(MU);var AU=200,Ix="__lodash_hash_undefined__",jU=1/0,OU="[object Function]",DU="[object GeneratorFunction]",RU=/[\\^$.*+?()[\]{}|]/g,LU=/^\[object .+?Constructor\]$/,$U=typeof sn=="object"&&sn&&sn.Object===Object&&sn,FU=typeof self=="object"&&self&&self.Object===Object&&self,Ex=$U||FU||Function("return this")();function NU(e,n){var t=e?e.length:0;return!!t&&BU(e,n,0)>-1}function zU(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 BU(e,n,t){if(n!==n)return zU(e,UU,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function UU(e){return e!==e}function HU(e,n){return e.has(n)}function KU(e,n){return e==null?void 0:e[n]}function WU(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function mk(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var GU=Array.prototype,VU=Function.prototype,yk=Object.prototype,mm=Ex["__core-js_shared__"],P1=function(){var e=/[^.]+$/.exec(mm&&mm.keys&&mm.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Sk=VU.toString,kx=yk.hasOwnProperty,YU=yk.toString,XU=RegExp("^"+Sk.call(kx).replace(RU,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),qU=GU.splice,ZU=_x(Ex,"Map"),ym=_x(Ex,"Set"),Wc=_x(Object,"create");function Li(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 QU(){this.__data__=Wc?Wc(null):{}}function JU(e){return this.has(e)&&delete this.__data__[e]}function e4(e){var n=this.__data__;if(Wc){var t=n[e];return t===Ix?void 0:t}return kx.call(n,e)?n[e]:void 0}function t4(e){var n=this.__data__;return Wc?n[e]!==void 0:kx.call(n,e)}function n4(e,n){var t=this.__data__;return t[e]=Wc&&n===void 0?Ix:n,this}Li.prototype.clear=QU;Li.prototype.delete=JU;Li.prototype.get=e4;Li.prototype.has=t4;Li.prototype.set=n4;function Ml(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 r4(){this.__data__=[]}function o4(e){var n=this.__data__,t=Lf(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():qU.call(n,t,1),!0}function s4(e){var n=this.__data__,t=Lf(n,e);return t<0?void 0:n[t][1]}function i4(e){return Lf(this.__data__,e)>-1}function a4(e,n){var t=this.__data__,r=Lf(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}Ml.prototype.clear=r4;Ml.prototype.delete=o4;Ml.prototype.get=s4;Ml.prototype.has=i4;Ml.prototype.set=a4;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 l4(){this.__data__={hash:new Li,map:new(ZU||Ml),string:new Li}}function c4(e){return $f(this,e).delete(e)}function u4(e){return $f(this,e).get(e)}function d4(e){return $f(this,e).has(e)}function h4(e,n){return $f(this,e).set(e,n),this}Al.prototype.clear=l4;Al.prototype.delete=c4;Al.prototype.get=u4;Al.prototype.has=d4;Al.prototype.set=h4;function wp(e){var n=-1,t=e?e.length:0;for(this.__data__=new Al;++n<t;)this.add(e[n])}function p4(e){return this.__data__.set(e,Ix),this}function f4(e){return this.__data__.has(e)}wp.prototype.add=wp.prototype.push=p4;wp.prototype.has=f4;function Lf(e,n){for(var t=e.length;t--;)if(b4(e[t][0],n))return t;return-1}function g4(e){if(!vk(e)||v4(e))return!1;var n=P4(e)||WU(e)?XU:LU;return n.test(x4(e))}function m4(e,n,t){var r=-1,o=NU,s=e.length,i=!0,a=[],l=a;if(s>=AU){var c=y4(e);if(c)return mk(c);i=!1,o=HU,l=new wp}else l=a;e:for(;++r<s;){var u=e[r],h=u;if(u=u!==0?u:0,i&&h===h){for(var p=l.length;p--;)if(l[p]===h)continue e;a.push(u)}else o(l,h,t)||(l!==a&&l.push(h),a.push(u))}return a}var y4=ym&&1/mk(new ym([,-0]))[1]==jU?function(e){return new ym(e)}:C4;function $f(e,n){var t=e.__data__;return S4(n)?t[typeof n=="string"?"string":"hash"]:t.map}function _x(e,n){var t=KU(e,n);return g4(t)?t:void 0}function S4(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function v4(e){return!!P1&&P1 in e}function x4(e){if(e!=null){try{return Sk.call(e)}catch{}try{return e+""}catch{}}return""}function w4(e){return e&&e.length?m4(e):[]}function b4(e,n){return e===n||e!==e&&n!==n}function P4(e){var n=vk(e)?YU.call(e):"";return n==OU||n==DU}function vk(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function C4(){}var I4=w4;const E4=ei(I4),mc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},k4=mc.Good;class xk{constructor(){g(this,"startTime",0);g(this,"name","");g(this,"frames",0);g(this,"started",!1);g(this,"frame",null);g(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?mc.Good:t>30?mc.Mid:mc.Poor,o=r===mc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${k4};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 Tx(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 _4(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 T4(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 qo{constructor(){g(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}}function wk(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const bp=()=>{},gn={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=wk((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),Sr=wk((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function bk(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 C1=new WeakMap;function Mx(e,n){if(typeof e!="object"||e===null)return;let t=C1.get(e);t||(t={tags:{},extras:{}},C1.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}async function So(e,n){return window.fetch(e,{referrerPolicy:"strict-origin-when-cross-origin",...n})}const il=(e,n)=>{const t=new window.Image(e,n);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Ai{static async dataUrlToArrayBuffer(n){return So(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 hS(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function M4(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+""}/*!
20
+ * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
21
+ * Copyright (c) Philip van Heemstra
22
+ */function A4(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 u=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,y=0,m=0,x="";e:for(;y<s.length;){const S=y+c,v=s.subarray(y,S),b=h.decode(v,{stream:!0}),E=x+b;let k,C=-1;for(;(k=i.exec(E))!==null;){C=k.index-x.length,f=m+C;break e}y=S,m+=b.length;const I=C>-1?C+u:b.length-u;x=b.slice(I)}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 j4=e=>new Uint8Array(e)[3]===44;/*!
23
+ * MIT License
24
+ * Modified code originally from <https://github.com/qzb/is-animated>
25
+ * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
26
+ */function I1(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function O4(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function D4(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!O4(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+=I1(n,o+1)+1;break;case 33:o+=2,o+=I1(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}let pS=[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"&&(pS=new Int32Array(pS));/*!
27
+ * MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
28
+ * Copyright: 2014 Alex Gorbatchev
29
+ * Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
30
+ */const R4=(e,n)=>{let t=~~n^-1;for(let r=0;r<e.length;r++)t=pS[(t^e[r])&255]^t>>>8;return t^-1},E1=4,k1=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+E1+k1;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+E1+k1}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 u=2835.5;c.setInt32(8,u*t),c.setInt32(12,u*t),c.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));c.setInt32(17,R4(h));const p=n.buffer.slice(0,o),f=n.buffer.slice(o+s);return new Blob([p,l,f],r)}}/*!
31
+ * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
32
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
33
+ */function L4(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function $4(e){const n=new Uint8Array(e);return!L4(n)||!n||n.length<21?!1:(n[20]>>1&1)===1}const Pk=Object.freeze(["image/svg+xml"]),Ck=Object.freeze(["image/jpeg","image/png","image/webp"]),Ik=Object.freeze(["image/gif","image/apng","image/avif"]),Ax=Object.freeze([...Ck,...Pk,...Ik]),Ek=Object.freeze(["video/mp4","video/webm","video/quicktime"]),F4=[...Ax,...Ek].join(",");class lo{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=il();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 lo.usingObjectURL(n,async t=>{const r=await lo.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await lo.usingObjectURL(n,lo.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"?D4(await n.arrayBuffer()):n.type==="image/avif"?j4(await n.arrayBuffer()):n.type==="image/webp"?$4(await n.arrayBuffer()):n.type==="image/apng"?A4(await n.arrayBuffer()):!1}static isAnimatedImageType(n){return Ik.includes(n||"")}static isStaticImageType(n){return Ck.includes(n||"")}static isVectorImageType(n){return Pk.includes(n||"")}static isImageType(n){return Ax.includes(n)}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function fd(e,n,t){return e+(n-e)*t}function Vr(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 al(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 po(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function jn(e,n){if(po(e,n))return e[n]}function _1(e){return Object.keys(e)}function gt(e){return Object.values(e)}function Ln(e){return Object.entries(e)}function kk(e){return Object.fromEntries(e)}function _c(e,n){const t={};let r=!1;for(const[o,s]of Ln(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function Mu(e,n){const t={};for(const[r,o]of Ln(e)){const s=n(r,o);t[r]=s}return t}function _k(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",Tk="a0",Mk="A00000000000000000000000000";function Ak(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 jk(e){if(e.length!==Ak(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function T1(e){if(e===void 0)throw Error("n is undefined")}function M1(e){jk(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 N4(e){jk(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 _a(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)+_a(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)+_a(e.slice(1),void 0)}function yc(e){const n=Ak(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function fS(e){if(e===Mk)throw new Error("invalid index: "+e);const n=yc(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function pa(e,n){if(e!==void 0&&fS(e),n!==void 0&&fS(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return Tk;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=yc(n),l=n.slice(a.length);if(a===Mk)return a+_a("",l);if(a<n)return a;const c=N4(a);return T1(c),c}if(n===void 0){const a=yc(e),l=e.slice(a.length),c=M1(a);return c===void 0?a+_a(l,void 0):c}const t=yc(e),r=e.slice(t.length),o=yc(n),s=n.slice(o.length);if(t===o)return t+_a(r,s);const i=M1(t);return T1(i),i<n?i:t+_a(r,void 0)}function Ks(e,n,t){if(t===0)return[];if(t===1)return[pa(e,n)];if(n===void 0){let s=pa(e,n);const i=[s];for(let a=0;a<t-1;a++)s=pa(s,n),i.push(s);return i}if(e===void 0){let s=pa(e,n);const i=[s];for(let a=0;a<t-1;a++)s=pa(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=pa(e,n);return[...Ks(e,o,r),o,...Ks(o,n,t-r-1)]}const z4=Tk;function B4(e){fS(e)}function ll(e,n,t){return Ks(e,n,t)}function Sm(e,n){return Ks(e,void 0,n)}function Gc(e,n){return Ks(e,n,1)[0]}function No(e){return Ks(e,void 0,1)[0]}function U4(e){return Ks(void 0,e,1)[0]}function Vc(e,n="a1"){return[n,...Ks(n,void 0,e)]}function on(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function H4(e,n){return e.id>n.id?1:-1}function Ff(e){try{return localStorage.getItem(e)}catch{return null}}function Nf(e,n){try{localStorage.setItem(e,n)}catch{}}function K4(){try{localStorage.clear()}catch{}}function Ok(e){try{return sessionStorage.getItem(e)}catch{return null}}function jx(e,n){try{sessionStorage.setItem(e,n)}catch{}}function Dk(e){try{sessionStorage.removeItem(e)}catch{}}function W4(){try{sessionStorage.clear()}catch{}}const G4=()=>typeof process<"u"&&!1,Ta=[],V4=60,vh=Math.ceil(1e3/V4);let Xl,vm=0,gS=0;const Y4=()=>{const e=Ta.splice(0,Ta.length);for(const n of e)n()};function Rk(){if(Xl)return;const e=Date.now(),n=e-gS;if(vm+n<vh){Xl=requestAnimationFrame(()=>{Xl=void 0,Rk()});return}Xl=requestAnimationFrame(()=>{Xl=void 0,gS=e,vm=Math.min(vm+n-vh,vh*10),Y4()})}let A1=!1;function Lk(e){return G4()?(e(),()=>{}):(Ta.includes(e)||(Ta.push(e),A1||(A1=!0,gS=Date.now()-vh-1),Rk()),()=>{const n=Ta.indexOf(e);n>-1&&Ta.splice(n,1)})}class X4{constructor(){g(this,"timeouts",[]);g(this,"intervals",[]);g(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 q4(e){return e!==null}function Z4(){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 $k=Z4(),rt=$k[0];$k[1];const Q4=Object.getPrototypeOf(rt({}));let Au=(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 zf{constructor(n,t){g(this,"createDefaultProperties");g(this,"validator");g(this,"ephemeralKeys");g(this,"ephemeralKeySet");g(this,"scope");g(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 Ln(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??Au())}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 zf(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 Io(e,n){return new zf(e,{createDefaultProperties:()=>({}),validator:n.validator,scope:n.scope,ephemeralKeys:n.ephemeralKeys})}function Pp(){return{added:{},updated:{},removed:{}}}function mS(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 Fk(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function Ox(e){const n={added:{},removed:{},updated:{}};return Tc(n,e),n}function Tc(e,n){for(const t of n){for(const[r,o]of Ln(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 Ln(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 Ln(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 Nk(e){return e&&typeof e=="object"&&"parents"in e}function zk(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 Cp=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&Nk(e))for(let t=0,r=e.parents.length;t<r;t++)Cp(e.parents[t],e)},Dx=(e,n)=>{if(e.children.add(n)&&Nk(e))for(let t=0,r=e.parents.length;t<r;t++)Dx(e.parents[t],e)};function Bk(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function ri(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const Wo=ri("empty_array",()=>Object.freeze([])),j1=8;class Ip{constructor(){g(this,"arraySize",0);g(this,"array",Array(j1));g(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<j1?(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 er=Symbol.for("com.tldraw.state/RESET_VALUE");class Uk{constructor(n){g(this,"index",0);g(this,"buffer");this.capacity=n,this.buffer=new Array(n)}pushEntry(n,t,r){if(r!==void 0){if(r===er){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 er;const[l,c]=a;if(s===0&&n>=c)return[];if(l<=n&&n<c){const u=s+1,h=new Array(u);for(let p=0;p<u;p++)h[p]=o[(i+p)%r][2];return h}}return er}}class J4{constructor(n,t){g(this,"offset",0);g(this,"maybeRemoved");this.below=n,this.child=t}}const tt=ri("capture",()=>({stack:null}));function gd(e){const n=tt.stack;tt.stack=null;try{return e()}finally{tt.stack=n}}function Hk(e){tt.stack=new J4(tt.stack,e),e.parentSet.clear()}function Kk(){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)||Cp(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)||Cp(t,e.child)}}function Ep(e){if(tt.stack){if(tt.stack.child.parentSet.has(e))return;if(tt.stack.child.parentSet.add(e),tt.stack.child.isActivelyListening&&Dx(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 ks=-1;class e8{constructor(n,t,r){g(this,"_isActivelyListening",!1);g(this,"lastTraversedEpoch",ks);g(this,"lastReactedEpoch",ks);g(this,"_scheduleCount",0);g(this,"parentSet",new Ip);g(this,"parentEpochs",[]);g(this,"parents",[]);g(this,"_scheduleEffect");g(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!==kn()){if(this.parents.length&&!zk(this)){this.lastReactedEpoch=kn();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++)Dx(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)Cp(this.parents[n],this)}execute(){try{Hk(this);const n=kn(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=n,t}finally{Kk()}}}const jl=ri("EffectScheduler",()=>e8);function oa(e,n,t){const r=new jl(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function t8(e,n,t){const r=new jl(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 n8{constructor(n){g(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){this.isRoot?Wk(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=ri("transactions",()=>({globalEpoch:ks+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:ks+1}));function r8(){return ze.reactionEpoch}function kn(){return ze.globalEpoch}function o8(){return ze.globalIsReacting}function Rx(e,n){n.lastTraversedEpoch!==ze.globalEpoch&&(n.lastTraversedEpoch=ze.globalEpoch,n instanceof jl?e.add(n):n.children.visit(t=>Rx(e,t)))}function Wk(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=>Rx(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 s8(e,n){if(ze.globalIsReacting){const t=ze.cleanupReactors??(ze.cleanupReactors=new Set);e.children.visit(r=>Rx(t,r))}else ze.currentTransaction?ze.currentTransaction.initialAtomValues.has(e)||ze.currentTransaction.initialAtomValues.set(e,n):Wk([e])}function i8(){ze.globalEpoch++}function a8(e){const n=new n8(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 js(e){return ze.currentTransaction?e():a8(e)}class l8{constructor(n,t,r){g(this,"isEqual");g(this,"computeDiff");g(this,"lastChangedEpoch",kn());g(this,"children",new Ip);g(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new Uk(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(n){return this.current}get(){return Ep(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??Bk(this.current,n))return this.current;i8(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,kn(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,kn()))??er),this.lastChangedEpoch=kn();const r=this.current;return this.current=n,s8(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return Ep(this),n>=this.lastChangedEpoch?Wo:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??er}}const c8=ri("Atom",()=>l8);function Mt(e,n,t){return new c8(e,n,t)}let O1=!1;function u8(){O1||(O1=!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.
34
+
35
+ // Before
36
+ @computed
37
+ get foo() {
38
+ return 'foo'
39
+ }
40
+
41
+ // After
42
+ @computed
43
+ getFoo() {
44
+ return 'foo'
45
+ }
46
+ `))}const Sc=Symbol.for("com.tldraw.state/UNINITIALIZED"),ji=e=>e===Sc,yS=ri("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function vc(e,n){return new yS(e,n)}class d8{constructor(n,t,r){g(this,"lastChangedEpoch",ks);g(this,"lastTraversedEpoch",ks);g(this,"lastCheckedEpoch",ks);g(this,"parentSet",new Ip);g(this,"parents",[]);g(this,"parentEpochs",[]);g(this,"children",new Ip);g(this,"historyBuffer");g(this,"state",Sc);g(this,"error",null);g(this,"computeDiff");g(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new Uk(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??Bk}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(n){var o;const t=this.lastChangedEpoch===ks,r=kn();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&o8()&&this.lastTraversedEpoch<r8()||!zk(this)))if(this.lastCheckedEpoch=r,this.error){if(n)return this.state;throw this.error.thrownValue}else return this.state;try{Hk(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof yS?s.value:s,a=this.state===Sc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof yS?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,kn(),l??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,kn()))??er)}this.lastChangedEpoch=kn(),this.state=i}return this.error=null,this.lastCheckedEpoch=kn(),this.state}catch(s){if(this.state!==Sc&&(this.state=Sc,this.lastChangedEpoch=kn()),this.lastCheckedEpoch=kn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!n)throw s;return this.state}finally{Kk()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Ep(this)}}getDiffSince(n){var t;return this.__unsafe__getWithoutCapture(!0),Ep(this),n>=this.lastChangedEpoch?Wo:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??er}}const Lx=ri("Computed",()=>d8);function h8(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 Lx(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[f8]=!0,r}function D1(e={},n,t,r){return r.get?(u8(),p8(e,n,t,r)):h8(e,n,t,r)}function p8(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 Lx(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const f8="@@__isComputedMethod__@@";function V(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>D1(e,n,t,r)}else return typeof arguments[0]=="string"?new Lx(arguments[0],arguments[1],arguments[2]):D1(void 0,arguments[0],arguments[1],arguments[2])}const Gk=1,g8=ri("apiVersion",()=>Gk);if(g8!==Gk)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function Bf(e,n){const t=we.useRef(n);t.current=n;const[r,o,s]=we.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new jl(`useStateTracking(${e})`,()=>{var u;return(u=t.current)==null?void 0:u.call(t)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[e]);return we.useSyncExternalStore(o,s,s),we.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const R1={apply(e,n,t){return Bf(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},m8=Symbol.for("react.memo"),y8=Symbol.for("react.forward_ref");function lr(e){let n=null;const t=e.$$typeof;return t===m8&&(e=e.type,n=e.compare),t===y8?P.memo(P.forwardRef(new Proxy(e.render,R1))):P.memo(new Proxy(e,R1),n)}function S8(){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 Os(e,n,t=Wo){P.useEffect(()=>{const r=new jl(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=>oa(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return P.useSyncExternalStore(s,i,i)}finally{r.current=!1}}var kp={exports:{}};kp.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]",u="[object Boolean]",h="[object Date]",p="[object Error]",f="[object Function]",y="[object GeneratorFunction]",m="[object Map]",x="[object Number]",S="[object Null]",v="[object Object]",b="[object Promise]",E="[object Proxy]",k="[object RegExp]",C="[object Set]",I="[object String]",T="[object Symbol]",O="[object Undefined]",_="[object WeakMap]",M="[object ArrayBuffer]",L="[object DataView]",j="[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[j]=ae[R]=ae[F]=ae[W]=ae[K]=ae[z]=ae[U]=ae[X]=ae[J]=!0,ae[a]=ae[l]=ae[M]=ae[u]=ae[L]=ae[h]=ae[p]=ae[f]=ae[m]=ae[x]=ae[v]=ae[k]=ae[C]=ae[I]=ae[_]=!1;var Ue=typeof sn=="object"&&sn&&sn.Object===Object&&sn,je=typeof self=="object"&&self&&self.Object===Object&&self,et=Ue||je||Function("return this")(),Ae=n&&!n.nodeType&&n,at=Ae&&!0&&e&&!e.nodeType&&e,Ne=at&&at.exports===Ae,Gn=Ne&&Ue.process,Rt=function(){try{return Gn&&Gn.binding&&Gn.binding("util")}catch{}}(),Cn=Rt&&Rt.isTypedArray;function St(A,$){for(var Y=-1,ee=A==null?0:A.length,Xe=0,fe=[];++Y<ee;){var ft=A[Y];$(ft,Y,A)&&(fe[Xe++]=ft)}return fe}function Xt(A,$){for(var Y=-1,ee=$.length,Xe=A.length;++Y<ee;)A[Xe+Y]=$[Y];return A}function _o(A,$){for(var Y=-1,ee=A==null?0:A.length;++Y<ee;)if($(A[Y],Y,A))return!0;return!1}function Bl(A,$){for(var Y=-1,ee=Array(A);++Y<A;)ee[Y]=$(Y);return ee}function ps(A){return function($){return A($)}}function GR(A,$){return A.has($)}function VR(A,$){return A==null?void 0:A[$]}function YR(A){var $=-1,Y=Array(A.size);return A.forEach(function(ee,Xe){Y[++$]=[Xe,ee]}),Y}function XR(A,$){return function(Y){return A($(Y))}}function qR(A){var $=-1,Y=Array(A.size);return A.forEach(function(ee){Y[++$]=ee}),Y}var ZR=Array.prototype,QR=Function.prototype,ed=Object.prototype,Ng=et["__core-js_shared__"],cb=QR.toString,Jr=ed.hasOwnProperty,ub=function(){var A=/[^.]+$/.exec(Ng&&Ng.keys&&Ng.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),db=ed.toString,JR=RegExp("^"+cb.call(Jr).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),hb=Ne?et.Buffer:void 0,td=et.Symbol,pb=et.Uint8Array,fb=ed.propertyIsEnumerable,eL=ZR.splice,fi=td?td.toStringTag:void 0,gb=Object.getOwnPropertySymbols,tL=hb?hb.isBuffer:void 0,nL=XR(Object.keys,Object),zg=ua(et,"DataView"),Ul=ua(et,"Map"),Bg=ua(et,"Promise"),Ug=ua(et,"Set"),Hg=ua(et,"WeakMap"),Hl=ua(Object,"create"),rL=yi(zg),oL=yi(Ul),sL=yi(Bg),iL=yi(Ug),aL=yi(Hg),mb=td?td.prototype:void 0,Kg=mb?mb.valueOf:void 0;function gi(A){var $=-1,Y=A==null?0:A.length;for(this.clear();++$<Y;){var ee=A[$];this.set(ee[0],ee[1])}}function lL(){this.__data__=Hl?Hl(null):{},this.size=0}function cL(A){var $=this.has(A)&&delete this.__data__[A];return this.size-=$?1:0,$}function uL(A){var $=this.__data__;if(Hl){var Y=$[A];return Y===r?void 0:Y}return Jr.call($,A)?$[A]:void 0}function dL(A){var $=this.__data__;return Hl?$[A]!==void 0:Jr.call($,A)}function hL(A,$){var Y=this.__data__;return this.size+=this.has(A)?0:1,Y[A]=Hl&&$===void 0?r:$,this}gi.prototype.clear=lL,gi.prototype.delete=cL,gi.prototype.get=uL,gi.prototype.has=dL,gi.prototype.set=hL;function To(A){var $=-1,Y=A==null?0:A.length;for(this.clear();++$<Y;){var ee=A[$];this.set(ee[0],ee[1])}}function pL(){this.__data__=[],this.size=0}function fL(A){var $=this.__data__,Y=rd($,A);if(Y<0)return!1;var ee=$.length-1;return Y==ee?$.pop():eL.call($,Y,1),--this.size,!0}function gL(A){var $=this.__data__,Y=rd($,A);return Y<0?void 0:$[Y][1]}function mL(A){return rd(this.__data__,A)>-1}function yL(A,$){var Y=this.__data__,ee=rd(Y,A);return ee<0?(++this.size,Y.push([A,$])):Y[ee][1]=$,this}To.prototype.clear=pL,To.prototype.delete=fL,To.prototype.get=gL,To.prototype.has=mL,To.prototype.set=yL;function mi(A){var $=-1,Y=A==null?0:A.length;for(this.clear();++$<Y;){var ee=A[$];this.set(ee[0],ee[1])}}function SL(){this.size=0,this.__data__={hash:new gi,map:new(Ul||To),string:new gi}}function vL(A){var $=od(this,A).delete(A);return this.size-=$?1:0,$}function xL(A){return od(this,A).get(A)}function wL(A){return od(this,A).has(A)}function bL(A,$){var Y=od(this,A),ee=Y.size;return Y.set(A,$),this.size+=Y.size==ee?0:1,this}mi.prototype.clear=SL,mi.prototype.delete=vL,mi.prototype.get=xL,mi.prototype.has=wL,mi.prototype.set=bL;function nd(A){var $=-1,Y=A==null?0:A.length;for(this.__data__=new mi;++$<Y;)this.add(A[$])}function PL(A){return this.__data__.set(A,r),this}function CL(A){return this.__data__.has(A)}nd.prototype.add=nd.prototype.push=PL,nd.prototype.has=CL;function fs(A){var $=this.__data__=new To(A);this.size=$.size}function IL(){this.__data__=new To,this.size=0}function EL(A){var $=this.__data__,Y=$.delete(A);return this.size=$.size,Y}function kL(A){return this.__data__.get(A)}function _L(A){return this.__data__.has(A)}function TL(A,$){var Y=this.__data__;if(Y instanceof To){var ee=Y.__data__;if(!Ul||ee.length<t-1)return ee.push([A,$]),this.size=++Y.size,this;Y=this.__data__=new mi(ee)}return Y.set(A,$),this.size=Y.size,this}fs.prototype.clear=IL,fs.prototype.delete=EL,fs.prototype.get=kL,fs.prototype.has=_L,fs.prototype.set=TL;function ML(A,$){var Y=sd(A),ee=!Y&&WL(A),Xe=!Y&&!ee&&Wg(A),fe=!Y&&!ee&&!Xe&&Ib(A),ft=Y||ee||Xe||fe,kt=ft?Bl(A.length,String):[],Lt=kt.length;for(var lt in A)Jr.call(A,lt)&&!(ft&&(lt=="length"||Xe&&(lt=="offset"||lt=="parent")||fe&&(lt=="buffer"||lt=="byteLength"||lt=="byteOffset")||zL(lt,Lt)))&&kt.push(lt);return kt}function rd(A,$){for(var Y=A.length;Y--;)if(wb(A[Y][0],$))return Y;return-1}function AL(A,$,Y){var ee=$(A);return sd(A)?ee:Xt(ee,Y(A))}function Kl(A){return A==null?A===void 0?O:S:fi&&fi in Object(A)?FL(A):KL(A)}function yb(A){return Wl(A)&&Kl(A)==a}function Sb(A,$,Y,ee,Xe){return A===$?!0:A==null||$==null||!Wl(A)&&!Wl($)?A!==A&&$!==$:jL(A,$,Y,ee,Sb,Xe)}function jL(A,$,Y,ee,Xe,fe){var ft=sd(A),kt=sd($),Lt=ft?l:gs(A),lt=kt?l:gs($);Lt=Lt==a?v:Lt,lt=lt==a?v:lt;var Vn=Lt==v,Ar=lt==v,qt=Lt==lt;if(qt&&Wg(A)){if(!Wg($))return!1;ft=!0,Vn=!1}if(qt&&!Vn)return fe||(fe=new fs),ft||Ib(A)?vb(A,$,Y,ee,Xe,fe):LL(A,$,Lt,Y,ee,Xe,fe);if(!(Y&o)){var pr=Vn&&Jr.call(A,"__wrapped__"),fr=Ar&&Jr.call($,"__wrapped__");if(pr||fr){var ms=pr?A.value():A,Mo=fr?$.value():$;return fe||(fe=new fs),Xe(ms,Mo,Y,ee,fe)}}return qt?(fe||(fe=new fs),$L(A,$,Y,ee,Xe,fe)):!1}function OL(A){if(!Cb(A)||UL(A))return!1;var $=bb(A)?JR:ye;return $.test(yi(A))}function DL(A){return Wl(A)&&Pb(A.length)&&!!ae[Kl(A)]}function RL(A){if(!HL(A))return nL(A);var $=[];for(var Y in Object(A))Jr.call(A,Y)&&Y!="constructor"&&$.push(Y);return $}function vb(A,$,Y,ee,Xe,fe){var ft=Y&o,kt=A.length,Lt=$.length;if(kt!=Lt&&!(ft&&Lt>kt))return!1;var lt=fe.get(A);if(lt&&fe.get($))return lt==$;var Vn=-1,Ar=!0,qt=Y&s?new nd:void 0;for(fe.set(A,$),fe.set($,A);++Vn<kt;){var pr=A[Vn],fr=$[Vn];if(ee)var ms=ft?ee(fr,pr,Vn,$,A,fe):ee(pr,fr,Vn,A,$,fe);if(ms!==void 0){if(ms)continue;Ar=!1;break}if(qt){if(!_o($,function(Mo,Si){if(!GR(qt,Si)&&(pr===Mo||Xe(pr,Mo,Y,ee,fe)))return qt.push(Si)})){Ar=!1;break}}else if(!(pr===fr||Xe(pr,fr,Y,ee,fe))){Ar=!1;break}}return fe.delete(A),fe.delete($),Ar}function LL(A,$,Y,ee,Xe,fe,ft){switch(Y){case L:if(A.byteLength!=$.byteLength||A.byteOffset!=$.byteOffset)return!1;A=A.buffer,$=$.buffer;case M:return!(A.byteLength!=$.byteLength||!fe(new pb(A),new pb($)));case u:case h:case x:return wb(+A,+$);case p:return A.name==$.name&&A.message==$.message;case k:case I:return A==$+"";case m:var kt=YR;case C:var Lt=ee&o;if(kt||(kt=qR),A.size!=$.size&&!Lt)return!1;var lt=ft.get(A);if(lt)return lt==$;ee|=s,ft.set(A,$);var Vn=vb(kt(A),kt($),ee,Xe,fe,ft);return ft.delete(A),Vn;case T:if(Kg)return Kg.call(A)==Kg.call($)}return!1}function $L(A,$,Y,ee,Xe,fe){var ft=Y&o,kt=xb(A),Lt=kt.length,lt=xb($),Vn=lt.length;if(Lt!=Vn&&!ft)return!1;for(var Ar=Lt;Ar--;){var qt=kt[Ar];if(!(ft?qt in $:Jr.call($,qt)))return!1}var pr=fe.get(A);if(pr&&fe.get($))return pr==$;var fr=!0;fe.set(A,$),fe.set($,A);for(var ms=ft;++Ar<Lt;){qt=kt[Ar];var Mo=A[qt],Si=$[qt];if(ee)var Eb=ft?ee(Si,Mo,qt,$,A,fe):ee(Mo,Si,qt,A,$,fe);if(!(Eb===void 0?Mo===Si||Xe(Mo,Si,Y,ee,fe):Eb)){fr=!1;break}ms||(ms=qt=="constructor")}if(fr&&!ms){var id=A.constructor,ad=$.constructor;id!=ad&&"constructor"in A&&"constructor"in $&&!(typeof id=="function"&&id instanceof id&&typeof ad=="function"&&ad instanceof ad)&&(fr=!1)}return fe.delete(A),fe.delete($),fr}function xb(A){return AL(A,YL,NL)}function od(A,$){var Y=A.__data__;return BL($)?Y[typeof $=="string"?"string":"hash"]:Y.map}function ua(A,$){var Y=VR(A,$);return OL(Y)?Y:void 0}function FL(A){var $=Jr.call(A,fi),Y=A[fi];try{A[fi]=void 0;var ee=!0}catch{}var Xe=db.call(A);return ee&&($?A[fi]=Y:delete A[fi]),Xe}var NL=gb?function(A){return A==null?[]:(A=Object(A),St(gb(A),function($){return fb.call(A,$)}))}:XL,gs=Kl;(zg&&gs(new zg(new ArrayBuffer(1)))!=L||Ul&&gs(new Ul)!=m||Bg&&gs(Bg.resolve())!=b||Ug&&gs(new Ug)!=C||Hg&&gs(new Hg)!=_)&&(gs=function(A){var $=Kl(A),Y=$==v?A.constructor:void 0,ee=Y?yi(Y):"";if(ee)switch(ee){case rL:return L;case oL:return m;case sL:return b;case iL:return C;case aL:return _}return $});function zL(A,$){return $=$??i,!!$&&(typeof A=="number"||Me.test(A))&&A>-1&&A%1==0&&A<$}function BL(A){var $=typeof A;return $=="string"||$=="number"||$=="symbol"||$=="boolean"?A!=="__proto__":A===null}function UL(A){return!!ub&&ub in A}function HL(A){var $=A&&A.constructor,Y=typeof $=="function"&&$.prototype||ed;return A===Y}function KL(A){return db.call(A)}function yi(A){if(A!=null){try{return cb.call(A)}catch{}try{return A+""}catch{}}return""}function wb(A,$){return A===$||A!==A&&$!==$}var WL=yb(function(){return arguments}())?yb:function(A){return Wl(A)&&Jr.call(A,"callee")&&!fb.call(A,"callee")},sd=Array.isArray;function GL(A){return A!=null&&Pb(A.length)&&!bb(A)}var Wg=tL||qL;function VL(A,$){return Sb(A,$)}function bb(A){if(!Cb(A))return!1;var $=Kl(A);return $==f||$==y||$==c||$==E}function Pb(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function Cb(A){var $=typeof A;return A!=null&&($=="object"||$=="function")}function Wl(A){return A!=null&&typeof A=="object"}var Ib=Cn?ps(Cn):DL;function YL(A){return GL(A)?ML(A):RL(A)}function XL(){return[]}function qL(){return!1}e.exports=VL})(kp,kp.exports);var v8=kp.exports;const x8=ei(v8);function w8(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 b8(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 L1(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 $1(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 w8(Object.values(r))}class P8{constructor(n,t){g(this,"indexCache",new Map);g(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(ji(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===er)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of s){for(const h of gt(u.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(u.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(u.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?vc(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(ji(s))return o();const a=r.getDiffSince(i);if(a===er)return o();const l=new Map,c=(f,y)=>{let m=l.get(f);m||(m=new Sh(s.get(f)??new Set)),m.add(y),l.set(f,m)},u=(f,y)=>{let m=l.get(f);m||(m=new Sh(s.get(f)??new Set)),m.remove(y),l.set(f,m)};for(const f of a){for(const y of gt(f.added))if(y.typeName===n){const m=y[t];c(m,y.id)}for(const[y,m]of gt(f.updated))if(m.typeName===n){const x=y[t],S=m[t];x!==S&&(u(x,m.id),c(S,m.id))}for(const y of gt(f.removed))if(y.typeName===n){const m=y[t];u(m,y.id)}}let h,p;for(const[f,y]of l){const m=y.get();m&&(h||(h=new Map(s)),p||(p=new Map),m.value.size===0?h.delete(f):h.set(f,m.value),p.set(f,m.diff))}return h&&p?vc(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 u=c.get();return u.typeName===n?u.id:[]})):$1(this,n,l)},i=l=>{const c=s(),u=b8(l,c);return u?vc(c,u):l},a=V("ids_query:"+r,t,{isEqual:x8});return V("query:"+r,(l,c)=>{const u=a.get();if(ji(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===er)return i(l);const p=new Sh(l);for(const y of h){for(const m of gt(y.added))m.typeName===n&&L1(u,m)&&p.add(m.id);for(const[m,x]of gt(y.updated))x.typeName===n&&(L1(u,x)?p.add(x.id):p.remove(x.id));for(const m of gt(y.removed))m.typeName===n&&p.remove(m.id)}const f=p.get();return f?vc(f.value,f.diff):l},{historyLength:50})}exec(n,t){const r=$1(this,n,t);if(r.size===0)return Wo;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class C8{constructor(n){g(this,"_beforeCreateHandlers",{});g(this,"_afterCreateHandlers",{});g(this,"_beforeChangeHandlers",{});g(this,"_afterChangeHandlers",{});g(this,"_beforeDeleteHandlers",{});g(this,"_afterDeleteHandlers",{});g(this,"_operationCompleteHandlers",[]);g(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 $x{constructor(n){g(this,"id");g(this,"atoms",Mt("store_atoms",{}));g(this,"history",Mt("history",0,{historyLength:1e3}));g(this,"query",new P8(this.atoms,this.history));g(this,"listeners",new Set);g(this,"historyAccumulator",new E8);g(this,"historyReactor");g(this,"cancelHistoryReactor",()=>{});g(this,"schema");g(this,"props");g(this,"scopedTypes");g(this,"sideEffects",new C8(this));g(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 u=0,h=n.length;u<h;u++){a=n[u];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 m=p.__unsafe__getWithoutCapture();r[a.id]=[f,m],this.addDiffForAfterEvent(f,m)}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:{}})})});g(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})})});g(this,"get",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.get()});g(this,"unsafeGetWithoutCapture",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.__unsafe__getWithoutCapture()});g(this,"serialize",(n="document")=>{const t={};for(const[r,o]of Ln(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});g(this,"allRecords",()=>gt(this.atoms.get()).map(n=>n.get()));g(this,"clear",()=>{this.remove(_1(this.atoms.get()))});g(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())])});g(this,"has",n=>!!this.atoms.get()[n]);g(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()}});g(this,"isMergingRemoteChanges",!1);g(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,js(n)}finally{this.isMergingRemoteChanges=!1}});g(this,"createComputedCache",(n,t,r)=>{const o=new qo;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()}}});g(this,"createSelectedComputedCache",(n,t,r)=>{const o=new qo;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()}}});g(this,"_integrityChecker");g(this,"_isPossiblyCorrupted",!1);g(this,"pendingAfterEvents",null);g(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:o}=n;this.id=o??Au(),this.schema=r,this.props=n.props,t&&this.atoms.set(kk(Ln(t).map(([s,i])=>[s,Mt("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=t8("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=Lk(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:_c(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:_c(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:_c(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 js(n),Ox(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 u=null;for(const[h,p]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(p,jn(c,h))||(u||(u={...c}),u[h]=p);u&&o.push(u)}else o.push(a)}const s=_1(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 js(()=>{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 I8(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:Ox(o.map(s=>s.changes))}))}class E8{constructor(){g(this,"_history",[]);g(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=I8(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function k8(e,n,t){const r=new qo;return{get(o,s){return r.get(o,()=>(o instanceof $x?o:o.store).createComputedCache(e,l=>n(o,l),t)).get(s)}}}function _8(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 Ya({sequence:e,sequenceId:n,retroactive:t=!0}){const r={sequenceId:n,retroactive:t,sequence:_8(e)};return Vk(r),r}function Un(e,n){return Object.fromEntries(Ln(n).map(([t,r])=>[t,`${e}/${r}`]))}function cr(e){const n=e.sequenceId;return Ya({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 T8(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}=_p(s.id),l=n.get(`${a}/${i-1}`);if(l&&o(l),s.dependsOn)for(const c of s.dependsOn){const u=n.get(c);u&&o(u)}n.delete(s.id),r.push(s)}for(const s of n.values())o(s);return r}function _p(e){const[n,t]=e.split("/");return{sequenceId:n,version:parseInt(t)}}function F1(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 Vk(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;F1(e.sequence[0].id,e.sequenceId);let n=_p(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;F1(r,e.sequenceId);const o=_p(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 xs=(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))(xs||{});function M8(e){if(e.schemaVersion>2||e.schemaVersion<1)return gn.err("Bad schema version");if(e.schemaVersion===2)return gn.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 gn.ok(n)}class Fx{constructor(n,t){g(this,"migrations",{});g(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}`),Vk(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=T8(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 Fx(n,t??{})}validateRecord(n,t,r,o){try{const s=jn(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=M8(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 gn.ok([]);const s=new Set;for(const i of o){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)s.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return gn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))s.add(u.id)}return gn.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:xs.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"?xs.TargetVersionTooOld:xs.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:xs.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:xs.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:xs.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:xs.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?_p(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=jn(this.types,n);return st(t,"record type does not exists"),t}}function A8(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 be extends Error{constructor(t,r=[]){const o=A8(r),s=t.split(`
47
+ `).map((i,a)=>a===0?i:` ${i}`).join(`
48
+ `);super(r?`At ${o}: ${s}`:s);g(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function $n(e,n){try{return n()}catch(t){throw t instanceof be?new be(t.rawMessage,[e,...t.path]):new be(t.toString(),[e])}}function Ws(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 $8(this)}optional(){return Xk(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=>($n(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class j8 extends wn{constructor(n){super(t=>{const r=N1.validate(t);for(let o=0;o<r.length;o++)$n(o,()=>n.validate(r[o]));return r},(t,r)=>{if(!n.validateUsingKnownGoodVersion)return this.validate(r);const o=N1.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,$n(i,()=>n.validate(a));continue}if(Object.is(t[i],a))continue;const l=$n(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 be("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new be("Expected an array with length greater than 1")})}}class Tp extends wn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new be(`Expected object, got ${Ws(r)}`);for(const[o,s]of Object.entries(n))$n(o,()=>{s.validate(jn(r,o))});if(!t){for(const o of Object.keys(r))if(!po(n,o))throw new be("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new be(`Expected object, got ${Ws(o)}`);let s=!1;for(const[i,a]of Object.entries(n)){const l=jn(r,i),c=jn(o,i);if(Object.is(l,c))continue;const u=$n(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(s=!0)}if(!t){for(const i of Object.keys(o))if(!po(n,i))throw new be("Unexpected property",[i])}for(const i of Object.keys(r))if(!po(o,i)){s=!0;break}return s?o:r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new Tp(this.config,!0)}extend(n){return new Tp({...this.config,...n})}}class Uf 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):$n(`(${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):jn(s,n)!==jn(i,n)?$n(`(${n} = ${l})`,()=>a.validate(i)):$n(`(${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 be(`Expected an object, got ${Ws(n)}`,[])}getMatchingSchemaAndVariant(n){const t=jn(n,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new be(`Expected a string for key "${this.key}", got ${Ws(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new be(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:po(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(n){return new Uf(this.key,this.config,n,this.useNumberKeys)}}class O8 extends wn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new be(`Expected object, got ${Ws(r)}`);for(const[o,s]of Object.entries(r))$n(o,()=>{n.validate(o),t.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new be(`Expected object, got ${Ws(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!po(r,i)){s=!0,$n(i,()=>{n.validate(i),t.validate(a)});continue}const l=jn(r,i),c=a;if(Object.is(l,c))continue;const u=$n(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,c):t.validate(c));Object.is(u,l)||(s=!0)}for(const i of Object.keys(r))if(!po(o,i)){s=!0;break}return s?o:r}),this.keyValidator=n,this.valueValidator=t}}function Nx(e){return new wn(n=>{if(typeof n!==e)throw new be(`Expected ${e}, got ${Ws(n)}`);return n})}const D8=new wn(e=>e),pe=Nx("string"),de=Nx("number").check(e=>{if(Number.isNaN(e))throw new be("Expected a number, got NaN");if(!Number.isFinite(e))throw new be(`Expected a finite number, got ${e}`)}),Mp=de.check(e=>{if(e<0)throw new be(`Expected a positive number, got ${e}`)}),Ct=de.check(e=>{if(e<=0)throw new be(`Expected a non-zero positive number, got ${e}`)}),Yk=de.check(e=>{if(!Number.isInteger(e))throw new be(`Expected an integer, got ${e}`)}),xh=Yk.check(e=>{if(e<0)throw new be(`Expected a positive integer, got ${e}`)}),R8=Yk.check(e=>{if(e<=0)throw new be(`Expected a non-zero positive integer, got ${e}`)}),Se=Nx("boolean");function ln(e){return new wn(n=>{if(n!==e)throw new be(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const N1=new wn(e=>{if(!Array.isArray(e))throw new be(`Expected an array, got ${Ws(e)}`);return e});function zt(e){return new j8(e)}function ve(e){return new Tp(e)}function SS(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===Q4)}function vS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(vS):SS(e)?Object.values(e).every(vS):!1}const Bt=new wn(e=>{if(vS(e))return e;throw new be(`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(SS(e)&&SS(n)){let t=!1;for(const r of Object.keys(n)){if(!po(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(!po(n,r)){t=!0;break}return t?n:e}else return Bt.validate(n)});function Ap(e,n){return new O8(e,n)}function zx(e,n){return new Uf(e,n,(t,r)=>{throw new be(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function L8(e,n){return new Uf(e,n,(t,r)=>{throw new be(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function Eo(e,n){return new wn(t=>$n(e,()=>n.validate(t)),(t,r)=>$n(e,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(t,r):n.validate(r)))}function Hf(e){return new wn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new be(`Expected ${t}, got ${n}`)}return n})}function Xk(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 $8(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 Kf(...e){return Hf(new Set(e))}function Bx(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new be(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new be(`Expected a valid url, got ${JSON.stringify(e)}`)}}const F8=new Set(["http:","https:","mailto:"]),sr=pe.check(e=>{if(e==="")return;const n=Bx(e);if(!F8.has(n.protocol.toLowerCase()))throw new be(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),N8=new Set(["http:","https:","data:","asset:"]),$i=pe.check(e=>{if(e==="")return;const n=Bx(e);if(!N8.has(n.protocol.toLowerCase()))throw new be(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)});pe.check(e=>{if(e==="")return;if(!Bx(e).protocol.toLowerCase().match(/^https?:$/))throw new be(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)});const Ux=pe.refine(e=>{try{return B4(e),e}catch{throw new be(`Expected an index key, got ${JSON.stringify(e)}`)}});function tr(e){return pe.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const Wf=tr("asset");function Hx(e,n){return ve({id:Wf,typeName:ln("asset"),type:ln(e),props:n,meta:Bt})}const Fi=ve({x:de,y:de,z:de.optional()}),Mc=ve({x:de,y:de,w:de,h:de}),qk=de.check(e=>{if(e<0||e>1)throw new be("Opacity must be between 0 and 1")}),z8=pe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),yr=tr("shape");function B8(e,n,t){return ve({id:yr,typeName:ln("shape"),x:de,y:de,rotation:de,index:Ux,parentId:z8,type:ln(e),isLocked:Se,opacity:qk,props:n?ve(n):Bt,meta:t?ve(t):Bt})}const U8=tr("binding");function H8(e,n,t){return ve({id:U8,typeName:ln("binding"),type:ln(e),fromId:yr,toId:yr,props:n?ve(n):Bt,meta:t?ve(t):Bt})}Un("com.tldraw.binding",{});cr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Oi(e){return`binding:${Au()}`}function K8(e){return Io("binding",{scope:"document",validator:Eo("binding",zx("type",Mu(e,(n,{props:t,meta:r})=>H8(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=D8}=t;return new Yt(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new W8(n,r,o)}setDefaultValue(n){this.defaultValue=n}validate(n){return this.type.validate(n)}validateUsingKnownGoodVersion(n,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(n,t):this.validate(t)}}class W8 extends Yt{constructor(n,t,r){super(n,t,Kf(...r)),this.values=r}}const md=Un("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),G8=cr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:md.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:md.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:md.AddMeta,up:e=>{e.meta={}}},{id:md.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function Ma(e){return e?e.typeName==="shape":!1}function _n(e){return e?e.startsWith("shape:"):!1}function $e(e){return`shape:${e??Au()}`}function Zk(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 Yr(e,n){return Mu(n,(t,r)=>`com.tldraw.shape.${e}/${r}`)}function V8(e){return Io("shape",{scope:"document",validator:Eo("shape",zx("type",Mu(e,(n,{props:t,meta:r})=>B8(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function z1(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} ${zf} migrations. Expected '${s}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o?t.push(Ya({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?Qk(e,r,i):i)})):t.push(Ya({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(Ya({sequenceId:s,retroactive:!1,sequence:[]}))}return t}function Qk(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 Jk=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],jp={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 as(e){return e.isDarkMode?jp.darkMode:jp.lightMode}const ir=Yt.defineEnum("tldraw:color",{defaultValue:"black",values:Jk}),e_=Yt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:Jk}),Ni=Yt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),zi=Yt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),vo=Yt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),t_={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},xo=Yt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),n_=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Op=Yt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:n_}),Dp=Yt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:n_}),r_={labelColor:e_,color:ir,fill:zi,dash:Ni,size:xo,arrowheadStart:Op,arrowheadEnd:Dp,font:vo,start:Fi,end:Fi,bend:de,text:pe,labelPosition:de,scale:Ct},Pa=Yr("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function yd(e){return Qk("shape","arrow",e)}const o_=Ya({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[yd({id:Pa.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),yd({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)}}),yd({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=Oi(),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=Oi(),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}}},yd({id:Pa.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}})]}),s_={terminal:Kf("start","end"),normalizedAnchor:Fi,isExact:Se,isPrecise:Se},i_={sequence:[{dependsOn:[Pa.ExtractBindings]}]},Y8=Eo("camera",ve({typeName:ln("camera"),id:tr("camera"),x:de,y:de,z:de,meta:Bt})),X8=Un("com.tldraw.camera",{AddMeta:1}),q8=cr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:X8.AddMeta,up:e=>{e.meta={}}}]}),co=Io("camera",{validator:Y8,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),Z8=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"]),a_=Hf(Z8),Q8=ve({type:a_,rotation:de}),J8=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),e6=Hf(J8),t6=new Set(["starting","paused","active","stopping"]),l_=ve({id:pe,points:zt(Fi),size:Mp,color:e6,opacity:de,state:Hf(t6),delay:de,shrink:de,taper:Se}),Yc=tr("page"),n6=Eo("page",ve({typeName:ln("page"),id:Yc,name:pe,index:Ux,meta:Bt})),r6=Un("com.tldraw.page",{AddMeta:1}),o6=cr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:r6.AddMeta,up:e=>{e.meta={}}}]}),Zo=Io("page",{validator:n6,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function En(e){return Zo.isId(e)}const s6={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},c_=e=>e?_c(e,n=>s6[n]):null;tr("instance");function i6(e){const n={};for(const[r,o]of e)n[r]=Xk(o);const t=Eo("instance",ve({typeName:ln("instance"),id:tr("instance"),currentPageId:Yc,followingUserId:pe.nullable(),brush:Mc.nullable(),opacityForNextShape:qk,stylesForNextShape:ve(n),cursor:Q8,scribbles:zt(l_),isFocusMode:Se,isDebugMode:Se,isToolLocked:Se,exportBackground:Se,screenBounds:Mc,insets:zt(Se),zoomBrush:Mc.nullable(),isPenMode:Se,isGridMode:Se,chatMessage:pe,isChatting:Se,highlightedUserIds:zt(pe),isFocused:Se,devicePixelRatio:de,isCoarsePointer:Se,isHoveringCanvas:Se.nullable(),openMenus:zt(pe),isChangingStyle:Se,isReadonly:Se,meta:Bt,duplicateProps:ve({shapeIds:zt(tr("shape")),offset:ve({x:de,y:de})}).nullable()}));return Io("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=Un("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}),a6=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})}]}),mn="instance:instance",l6=Eo("instance_page_state",ve({typeName:ln("instance_page_state"),id:tr("instance_page_state"),pageId:Yc,selectedShapeIds:zt(yr),hintingShapeIds:zt(yr),erasingShapeIds:zt(yr),hoveredShapeId:yr.nullable(),editingShapeId:yr.nullable(),croppingShapeId:yr.nullable(),focusedGroupId:yr.nullable(),meta:Bt})),ql=Un("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),c6=cr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:ql.AddCroppingId,up(e){e.croppingShapeId=null}},{id:ql.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:ql.AddMeta,up:e=>{e.meta={}}},{id:ql.RenameProperties,up:e=>{},down:e=>{}},{id:ql.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}}]}),Nr=Io("instance_page_state",{validator:l6,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:{}})),u6=Eo("pointer",ve({typeName:ln("pointer"),id:tr("pointer"),x:de,y:de,lastActivityTimestamp:de,meta:Bt})),d6=Un("com.tldraw.pointer",{AddMeta:1}),h6=cr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:d6.AddMeta,up:e=>{e.meta={}}}]}),Kx=Io("pointer",{validator:u6,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Rp=Kx.createId("pointer"),p6=Eo("instance_presence",ve({typeName:ln("instance_presence"),id:tr("instance_presence"),userId:pe,userName:pe,lastActivityTimestamp:de,followingUserId:pe.nullable(),cursor:ve({x:de,y:de,type:a_,rotation:de}),color:pe,camera:ve({x:de,y:de,z:de}),screenBounds:Mc,selectedShapeIds:zt(tr("shape")),currentPageId:tr("page"),brush:Mc.nullable(),scribbles:zt(l_),chatMessage:pe,meta:Bt})),Zl=Un("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),f6=cr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Zl.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:Zl.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:Zl.AddChatMessage,up:e=>{e.chatMessage=""}},{id:Zl.AddMeta,up:e=>{e.meta={}}},{id:Zl.RenameSelectedShapeIds,up:e=>{}}]}),g6=Io("instance_presence",{validator:p6,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:{}})),m6=Eo("document",ve({typeName:ln("document"),id:ln("document:document"),gridSize:de,name:pe,meta:Bt})),B1=Un("com.tldraw.document",{AddName:1,AddMeta:2}),y6=cr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:B1.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:B1.AddMeta,up:e=>{e.meta={}}}]}),Wx=Io("document",{validator:m6,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),xS=Wx.createId("document");function S6(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function U1(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const v6=({error:e,phase:n,record:t,recordBefore:r})=>{throw Mx(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?U1(rt(r)):void 0,recordAfter:U1(rt(t))}}),e};function x6(){return[Zo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function w6(e){const n=e.query.ids("page"),t=()=>{if(!e.has(xS))return e.put([Wx.create({id:xS,name:e.props.defaultName})]),t();if(!e.has(Rp))return e.put([Kx.create({id:Rp})]),t();const r=n.get();if(r.size===0)return e.put(x6()),t();const o=()=>[...r].map(l=>e.get(l)).sort(S6)[0].id,s=e.get(mn);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:mn,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const l of r){const c=Nr.createId(l);e.has(c)||i.add(c);const u=co.createId(l);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(l=>Nr.create({id:l,pageId:Nr.parseId(l)}))),a.size>0&&e.put([...a].map(l=>co.create({id:l})))};return t}const b6=Hx("bookmark",ve({title:pe,description:pe,image:pe,favicon:pe,src:$i.nullable()})),H1=Un("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),P6=cr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:H1.MakeUrlsValid,up:e=>{$i.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:H1.AddFavicon,up:e=>{$i.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),C6=Hx("image",ve({w:de,h:de,fileSize:de,name:pe,isAnimated:Se,mimeType:pe.nullable(),src:$i.nullable()})),Sd=Un("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),I6=cr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:Sd.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Sd.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:Sd.MakeUrlsValid,up:e=>{$i.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:Sd.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),E6=Hx("video",ve({w:de,h:de,fileSize:de,name:pe,isAnimated:Se,mimeType:pe.nullable(),src:$i.nullable()})),vd=Un("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),k6=cr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:vd.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:vd.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:vd.MakeUrlsValid,up:e=>{$i.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:vd.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),_6=Eo("asset",zx("type",{image:C6,video:E6,bookmark:b6})),T6=Un("com.tldraw.asset",{AddMeta:1}),M6=cr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:T6.AddMeta,up:e=>{e.meta={}}}]}),Ci=Io("asset",{validator:_6,scope:"document"}).withDefaultProperties(()=>({meta:{}})),u_={w:Ct,h:Ct,assetId:Wf.nullable(),url:sr},K1=Yr("bookmark",{NullAssetId:1,MakeUrlsValid:2}),d_={sequence:[{id:K1.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:"retired"},{id:K1.MakeUrlsValid,up:e=>{sr.isValid(e.url)||(e.url="")},down:e=>{}}]},h_=ve({type:Kf("free","straight"),points:zt(Fi)}),p_={color:ir,fill:zi,dash:Ni,size:xo,segments:zt(h_),isComplete:Se,isClosed:Se,isPen:Se,scale:Ct},W1=Yr("draw",{AddInPen:1,AddScale:2}),f_={sequence:[{id:W1.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:W1.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]};var A6={};const G1=/(^\/r\/[^/]+\/?$)/,Oe=e=>{try{return new URL(e)}catch{return}},ju=[{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(G1))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(G1))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=${A6.NEXT_PUBLIC_GC_API_KEY}&center=${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","")}}],j6={"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},g_={w:Ct,h:Ct,url:pe},xd=Yr("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),m_={sequence:[{id:xd.GenOriginalUrlInEmbed,up:e=>{try{const n=e.url,t=new URL(n).host.replace("www.","");let r;for(const o of ju)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:xd.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:xd.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:xd.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},y_={w:Ct,h:Ct,name:pe},S_={sequence:[]},Lp=Yt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),$p=Yt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),zr=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"]}),v_={geo:zr,labelColor:e_,color:ir,fill:zi,dash:Ni,size:xo,font:vo,align:Lp,verticalAlign:$p,url:sr,w:Ct,h:Ct,growY:Mp,text:pe,scale:Ct},Ao=Yr("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),x_={sequence:[{id:Ao.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Ao.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:Ao.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:Ao.AddCheckBox,up:e=>{},down:"retired"},{id:Ao.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:Ao.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:Ao.AddCloud,up:e=>{},down:"retired"},{id:Ao.MakeUrlsValid,up:e=>{sr.isValid(e.url)||(e.url="")},down:e=>{}},{id:Ao.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},w_={},b_={sequence:[]},P_={color:ir,size:xo,segments:zt(h_),isComplete:Se,isPen:Se,scale:Ct},O6=Yr("highlight",{AddScale:1}),C_={sequence:[{id:O6.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},D6=ve({topLeft:Fi,bottomRight:Fi}),I_={w:Ct,h:Ct,playing:Se,url:sr,assetId:Wf.nullable(),crop:D6.nullable(),flipX:Se,flipY:Se},wd=Yr("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),E_={sequence:[{id:wd.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:wd.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:wd.MakeUrlsValid,up:e=>{sr.isValid(e.url)||(e.url="")},down:e=>{}},{id:wd.AddFlipProps,up:e=>{e.flipX=!1,e.flipY=!1},down:e=>{delete e.flipX,delete e.flipY}}]},Fp=Yt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),R6=ve({id:pe,index:Ux,x:de,y:de}),k_={color:ir,dash:Ni,size:xo,spline:Fp,points:Ap(pe,R6),scale:Ct},Ql=Yr("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),__={sequence:[{id:Ql.AddSnapHandles,up:e=>{for(const n of Object.values(e.handles))n.canSnap=!0},down:"retired"},{id:Ql.RemoveExtraHandleProps,up:e=>{e.handles=kk(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:Ql.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=Vc(e.points.length);e.handles=Object.fromEntries(e.points.map((t,r)=>[n[r],{x:t.x,y:t.y}])),delete e.points}},{id:Ql.PointIndexIds,up:e=>{const n=Vc(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:Ql.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},T_={color:ir,size:xo,font:vo,fontSizeAdjustment:Mp,align:Lp,verticalAlign:$p,growY:Mp,url:sr,text:pe,scale:Ct},xi=Yr("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),M_={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=>{sr.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}}]},wS=Yt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),A_={color:ir,size:xo,font:vo,textAlign:wS,w:Ct,text:pe,scale:Ct,autoSize:Se},V1=Yr("text",{RemoveJustify:1,AddTextAlign:2}),j_={sequence:[{id:V1.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:V1.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},O_={w:Ct,h:Ct,time:de,playing:Se,url:sr,assetId:Wf.nullable()},Y1=Yr("video",{AddUrlProp:1,MakeUrlsValid:2}),D_={sequence:[{id:Y1.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Y1.MakeUrlsValid,up:e=>{sr.isValid(e.url)||(e.url="")},down:e=>{}}]},bd=Un("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),L6=Ya({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:bd.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[n,t]of Ln(e))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete e[n]}},{id:bd.AddInstancePresenceType,scope:"store",up(e){}},{id:bd.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[n,t]of Ln(e))t.typeName.match(/^(user|user_presence)$/)&&delete e[n]}},{id:bd.RemoveUserDocument,scope:"store",up:e=>{for(const[n,t]of Ln(e))t.typeName.match("user_document")&&delete e[n]}}]}),$6={arrow:{migrations:o_,props:r_},bookmark:{migrations:d_,props:u_},draw:{migrations:f_,props:p_},embed:{migrations:m_,props:g_},frame:{migrations:S_,props:y_},geo:{migrations:x_,props:v_},group:{migrations:b_,props:w_},highlight:{migrations:C_,props:P_},image:{migrations:E_,props:I_},line:{migrations:__,props:k_},note:{migrations:M_,props:T_},text:{migrations:j_,props:A_},video:{migrations:D_,props:O_}},F6={arrow:{migrations:i_,props:s_}};function N6({shapes:e=$6,bindings:n=F6,migrations:t}={}){const r=new Map;for(const a of gt(e))for(const l of Zk(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=V8(e),s=K8(n),i=i6(r);return Fx.create({asset:Ci,binding:s,camera:co,document:Wx,instance:i,instance_page_state:Nr,page:Zo,instance_presence:g6,pointer:Kx,shape:o},{migrations:[L6,M6,q8,y6,a6,c6,o6,f6,h6,G8,P6,I6,k6,...z1("shape",e),...z1("binding",n),...t??[]],onValidationFailure:v6,createIntegrityChecker:w6})}const Xc=[{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 z6(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return B6(e)}function B6(e){for(const n of e){const t=U6(n);if(t)return t}return"en"}const X1={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function U6(e){const n=Xc.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Xc.find(s=>s.locale===t);if(o)return o.locale}return t in X1?X1[t]:null}var R_={exports:{}};/*!
49
+ Copyright (c) 2018 Jed Watson.
50
+ Licensed under the MIT License (MIT), see
51
+ http://jedwatson.github.io/classnames
52
+ */(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})()})(R_);var H6=R_.exports;const ce=ei(H6),K6={error:null};class L_ extends P.Component{constructor(){super(...arguments);g(this,"state",K6)}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 d.jsx(r,{error:t})}return this.props.children}}function qc({children:e,fallback:n,...t}){return n===null?e:d.jsx(L_,{fallback:n,...t,children:e})}const Gf=P.createContext(null);function B(){const e=we.useContext(Gf);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function W6(){return d.jsx("div",{className:"tl-background"})}function Ol(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 At={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(zo(n.x),zo(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=At.easeInQuad(s/(r-1)),a=w.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-G6(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 G6=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 ke=Math.PI,Ge=ke/2,Re=ke*2,V6=Math.sin;function _t(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function Pd(e,n=1e10){return e?Math.round(e*n)/n:0}function Ds(e,n,t=1e-6){return Math.abs(e-n)<=t}function $_(e,n){const t=Math.pow(e-n,2)/Math.pow(e+n,2);return ke*(e+n)*(1+3*t/(10+Math.sqrt(4-3*t)))}function Rs(e){return e=e%Re,e<0?e=e+Re:e===0&&(e=0),e}function Ou(e,n){return e=Rs(e),n=Rs(n),e>n&&(n+=Re),n-e}function F_(e,n){return Re-Ou(e,n)}function wh(e,n){const t=(n-e)%Re;return 2*t%Re-t}function bS(e){return(Re+e)%Re}function Np(e,n){const t=Re/n;let r=Math.floor((bS(e)+t/2)/t)*t%Re;return r<ke&&(r+=Re),r>ke&&(r-=Re),r}function N_(e,n){return e===n||Ds(e%(Math.PI/2)-n%(Math.PI/2),0)}function Y6(e){return e*ke/180}function X6(e){return e*180/ke}function Bi(e,n,t){return new w(e.x,e.y).add(w.FromAngle(t,n))}function xm(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 y=0;y<t;y++){const m=Re/t,x=-Ge+y*m,S=r+r*Math.cos(x),v=o+o*Math.sin(x);S<i&&(i=S),v<l&&(l=v),S>a&&(a=S),v>c&&(c=v),s.push(new w(S,v))}const u=a-i,h=c-l,p=e-u,f=n-h;if(p!==0||f!==0)for(let y=0;y<s.length;y++){const m=s[y];m.x=(m.x-i)/u*e,m.y=(m.y-l)/h*n}return s}function Jl(e,n,t,r){return e<r&&t<n}function Dr(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function q1(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function nr(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&&q1(r,o,e)>0&&(t+=1):o.y<=e.y&&q1(r,o,e)<0&&(t-=1)}return t!==0}function N(e){return Math.round(e*1e4)/1e4}function zo(e){return Math.round(e*100)/100}const Z1=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function Cs(e,n,t){return t<0?Ou(e,n):F_(e,n)}function PS(e,n,t,r){let o;if(Math.abs(e)>ke){o=wh(n,r);const s=wh(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=wh(n,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function q6(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 Gx(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 Z6(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=Ou(i,a);for(let c=0;c<o;c++){const u=c/(o-1),h=i+l*u,p=Bi(t,r,h);s.push(p)}return s}const wm=({brush:e,color:n,opacity:t,className:r})=>{const o=P.useRef(null);Ol(o,e.x,e.y);const s=N(Math.max(1,e.w)),i=N(Math.max(1,e.h));return d.jsx("svg",{className:"tl-overlays__item",ref:o,children:n?d.jsxs("g",{className:"tl-brush",opacity:t,children:[d.jsx("rect",{width:s,height:i,fill:n,opacity:.75}),d.jsx("rect",{width:s,height:i,fill:"none",stroke:n,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},Q1={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},J1={onResolveAsset:async e=>(e==null?void 0:e.props.src)||""},bm={duration:0,easing:At.easeInOutCubic},eP={CAMERA_MOVE:-10},Q6=["top","right","bottom","left"],tP=0,Vx=2,Cd=1,nP=5,J6=128;var Pm={};const eH={},z_=In("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),xt={logPreventDefaults:In("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:In("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:In("logElementRemoves",{defaults:{all:!1}}),debugSvg:In("debugSvg",{defaults:{all:!1}}),showFps:In("showFps",{defaults:{all:!1}}),measurePerformance:In("measurePerformance",{defaults:{all:!1}}),throwToBlob:In("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:In("reconnectOnPing",{defaults:{all:!1}}),debugCursors:In("debugCursors",{defaults:{all:!1}}),forceSrgb:In("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:In("debugGeometry",{defaults:{all:!1}}),hideShapes:In("hideShapes",{defaults:{all:!1}}),editOnType:In("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;oa("element removal logging",()=>{xt.logElementRemoves.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function In(e,{defaults:n,shouldStoreForSession:t=!0}){return tH({name:e,defaults:n,shouldStoreForSession:t})}function tH(e){const n=rH(e),t=e.shouldStoreForSession?nH(e.name):null,r=Mt(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&oa(`debug:${e.name}`,()=>{const o=r.get();o===n?Dk(`tldraw_debug:${e.name}`):jx(`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 nH(e){try{return JSON.parse(Ok(`tldraw_debug:${e}`)??"null")}catch{return null}}function Cm(e){try{return e()}catch{return null}}function rH(e){switch(Cm(()=>Pm.TLDRAW_ENV)??Cm(()=>Pm.VERCEL_PUBLIC_TLDRAW_ENV)??Cm(()=>Pm.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 zp(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return zp(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ee(e){e.preventDefault(),xt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Du(e,n){if(e.setPointerCapture(n.pointerId),xt.logPointerCaptures.get()){const t=z_.get();t.set(e,(t.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,n)}}function Ru(e,n){if(e.hasPointerCapture(n.pointerId)&&(e.releasePointerCapture(n.pointerId),xt.logPointerCaptures.get())){const t=z_.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 Ht=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 oH(){const e=B();return P.useMemo(function(){let r,o;function s(m){if(!m.isKilled){if(m.button===Vx){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...On(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(Du(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...On(m)}))}}function i(m){m.isKilled||m.clientX===r&&m.clientY===o||(r=m.clientX,o=m.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...On(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,Ru(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...On(m)}))}function l(m){if(m.isKilled||e.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const x=m.pointerType==="mouse"||m.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!0:null})}function c(m){if(m.isKilled||e.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const x=m.pointerType==="mouse"||m.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!1:null})}function u(m){m.isKilled=!0,Ee(m)}function h(m){m.isKilled=!0,m.target instanceof HTMLElement&&m.target.tagName!=="A"&&m.target.tagName!=="TEXTAREA"&&!(e.getEditingShape()&&m.target.className.includes("tl-text-content"))&&Ee(m)}function p(m){Ee(m)}async function f(m){var S,v;if(Ee(m),!((v=(S=m.dataTransfer)==null?void 0:S.files)!=null&&v.length))return;const x=Array.from(m.dataTransfer.files);await e.putExternalContent({type:"files",files:x,point:e.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function y(m){Ht(m)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:y}},[e])}function sH(){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 B_=P.createContext(null);function iH({container:e,children:n}){return d.jsx(B_.Provider,{value:e,children:n})}function un(){return Sr(P.useContext(B_),"useContainer used outside of <Tldraw />")}function aH(){const e=B(),n=un(),t=G("isFocused",()=>e.getIsFocused(),[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"))&&!Id()&&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(Id()||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(Id()||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,Id()||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 u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+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 lH=["input","select","button","textarea"];function Id(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||lH.indexOf(e.tagName.toLowerCase())>-1))}const cH=["textarea","input"];function uH(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(cH.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 dH(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 rP(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function oP(e,n,t,r=.15){return r===0?dH(e,n,t):e<n?-rP(n-e,t-n,r)+n:e>t?+rP(e-t,t-n,r)+t:e}function hH(e,[n,t],[r,o]){const[[s,i],[a,l]]=e;return[oP(n,s,i,r),oP(t,a,l,o)]}function pH(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 fH(e){var n=pH(e,"string");return typeof n=="symbol"?n:String(n)}function tn(e,n,t){return n=fH(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function sP(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?sP(Object(t),!0).forEach(function(r){tn(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):sP(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const U_={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 iP(e){return e?e[0].toUpperCase()+e.slice(1):""}const gH=["enter","leave"];function mH(e=!1,n){return e&&!gH.includes(n)}function yH(e,n="",t=!1){const r=U_[e],o=r&&r[n]||n;return"on"+iP(e)+iP(o)+(mH(t,o)?"Capture":"")}const SH=["gotpointercapture","lostpointercapture"];function vH(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=SH.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function xH(e,n=""){const t=U_[e],r=t&&t[n]||n;return e+r}function H_(e){return"touches"in e}function wH(e){return H_(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function bH(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 CS(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 PH(e){return bH(e).map(n=>n.identifier)}function aP(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return CS(t,r)}const lP=40,cP=800;function K_(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=lP,t*=lP):r===2&&(n*=cP,t*=cP),[n,t]}function CH(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 Bp(e,...n){return typeof e=="function"?e(...n):e}function IH(){}function EH(...e){return e.length===0?IH:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function uP(e,n){return Object.assign({},n,e||{})}const kH=32;class W_{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?Bp(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,CH(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:u,values:h}=t;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),t.intentional=u[0]!==!1||u[1]!==!1,!t.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[C,I]=h;p[0]=u[0]!==!1?C-u[0]:0,p[1]=u[1]!==!1?I-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(p);const f=t.offset,y=t._active&&!t._blocked||t.active;y&&(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=Bp(r.bounds,t)),this.setup&&this.setup()),t.movement=p,this.computeOffset()));const[m,x]=t.offset,[[S,v],[b,E]]=t._bounds;t.overflow=[m<S?-1:m>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 k=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=hH(t._bounds,t.offset,k),t.delta=Ut.sub(t.offset,f),this.computeMovement(),y&&(!t.last||s>kH)){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 _H([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 TH extends W_{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[wH(n)]:r.axisThreshold;t.axis=_H(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 MH=e=>e,dP=.15,G_={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[dP,dP];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||MH},threshold(e){return Ut.toVector(e,0)}},AH=0,Lu=ut(ut({},G_),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=AH){return e},bounds(e={}){if(typeof e=="function")return s=>Lu.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]]}}),$u=typeof window<"u"&&window.document&&window.document.createElement;function V_(){return $u&&"ontouchstart"in window}function jH(){return V_()||$u&&window.navigator.maxTouchPoints>1}function OH(){return $u&&"onpointerdown"in window}function DH(){return $u&&"exitPointerLock"in window.document}function RH(){try{return"constructor"in GestureEvent}catch{return!1}}const vr={isBrowser:$u,gesture:RH(),touch:V_(),touchscreen:jH(),pointer:OH(),pointerLock:DH()},LH=250,$H=180,FH=.5,NH=50,zH=250,BH=10,hP={mouse:0,touch:0,pen:8};ut(ut({},Lu),{},{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?LH: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=FH,distance:n=NH,duration:t=zH}={}){return{velocity:this.transform(Ut.toVector(e)),distance:this.transform(Ut.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return $H;case!1:return 0;default:return e}},axisThreshold(e){return e?ut(ut({},hP),e):hP},keyboardDisplacement(e=BH){return e}});function Y_(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 UH=30,HH=100;class KH extends W_{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)*UH-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=aP(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=CS(...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=aP(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=CS(...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=[-K_(n)[1]/HH*r.offset[0],0],Ut.addTo(r._movement,r._delta),Y_(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 WH=ut(ut({},G_),{},{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=uP(Bp(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=uP(Bp(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({},Lu),{},{mouseOnly:(e=!0)=>e});class GH extends TH{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=K_(n),Ut.addTo(t._movement,t._delta),Y_(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 VH=Lu;ut(ut({},Lu),{},{mouseOnly:(e=!0)=>e});const Yx=new Map,IS=new Map;function YH(e){Yx.set(e.key,e.engine),IS.set(e.key,e.resolver)}const XH={key:"pinch",engine:KH,resolver:WH},qH={key:"wheel",engine:GH,resolver:VH};function ZH(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 QH(e,n){if(e==null)return{};var t=ZH(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 JH={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}},e9=["target","eventOptions","window","enabled","transform"];function bh(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]=bh(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function t9(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=QH(r,e9);if(t.shared=bh({target:o,eventOptions:s,window:i,enabled:a,transform:l},JH),n){const u=IS.get(n);t[n]=bh(ut({shared:t.shared},c),u)}else for(const u in c){const h=IS.get(u);h&&(t[u]=bh(ut({shared:t.shared},c[u]),h))}return t}class X_{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=xH(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ut(ut({},l),s);n.addEventListener(a,o,c);const u=()=>{n.removeEventListener(a,o,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class n9{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 r9{constructor(n){tn(this,"gestures",new Set),tn(this,"_targetEventStore",new X_(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}}),o9(this,n)}setEventIds(n){if(H_(n))return this.touchIds=new Set(PH(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=t9(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=pP(r,a.eventOptions,!!o);if(a.enabled){const c=Yx.get(i);new c(this,n,i).bind(l)}}const s=pP(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]=EH(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=vH(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function fa(e,n){e.gestures.add(n),e.gestureEventStores[n]=new X_(e,n),e.gestureTimeoutStores[n]=new n9}function o9(e,n){n.drag&&fa(e,"drag"),n.wheel&&fa(e,"wheel"),n.scroll&&fa(e,"scroll"),n.move&&fa(e,"move"),n.pinch&&fa(e,"pinch"),n.hover&&fa(e,"hover")}const pP=(e,n,t)=>(r,o,s,i={},a=!1)=>{var l,c;const u=(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:yH(r,o,u);t&&h&&(p+="Passive"),e[p]=e[p]||[],e[p].push(s)},s9=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function i9(e){const n={},t={},r=new Set;for(let o in e)s9.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function ga(e,n,t,r,o,s){if(!e.has(t)||!Yx.has(r))return;const i=t+"Start",a=t+"End",l=c=>{let u;return c.first&&i in n&&n[i](c),t in n&&(u=n[t](c)),c.last&&a in n&&n[a](c),u};o[r]=l,s[r]=s[r]||{}}function a9(e,n){const[t,r,o]=i9(e),s={};return ga(o,t,"onDrag","drag",s,n),ga(o,t,"onWheel","wheel",s,n),ga(o,t,"onScroll","scroll",s,n),ga(o,t,"onPinch","pinch",s,n),ga(o,t,"onMove","move",s,n),ga(o,t,"onHover","hover",s,n),{handlers:s,config:n,nativeHandlers:r}}function l9(e,n={},t,r){const o=we.useMemo(()=>new r9(e),[]);if(o.applyHandlers(e,r),o.applyConfig(n,t),we.useEffect(o.effect.bind(o)),we.useEffect(()=>o.clean.bind(o),[]),n.target===void 0)return o.bind.bind(o)}function c9(e){return e.forEach(YH),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=a9(t,r||{});return l9(o,i,void 0,s)}}const fP=10,u9=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function q_(e){let{deltaY:n,deltaX:t}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(n)>fP?fP*Math.sign(n):n)/100:e.shiftKey&&!u9&&(t=n,n=0),{x:-t,y:-n,z:-r}}const d9=c9([qH,XH]);let ma;const h9=e=>ma===void 0?(ma=e,!1):e-ma>120&&e-ma<160?(ma=e,!0):(ma=e,!1);function p9(e){const n=B(),t=P.useMemo(()=>{let r="not sure";const o=({event:m})=>{if(!n.getInstanceState().isFocused||(r="not sure",h9(Date.now())))return;const x=n.getEditingShapeId();if(x){const b=n.getShape(x);if(b&&n.getShapeUtil(b).canScroll(b)){const k=n.getShapePageBounds(x);if(k!=null&&k.containsPoint(n.inputs.currentPagePoint))return}}Ee(m),Ht(m);const S=q_(m);if(S.x===0&&S.y===0)return;const v={type:"wheel",name:"wheel",delta:S,point:new w(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey};n.dispatch(v)};let s=1,i=1,a=1,l=0;const c=new w,u=new w,h=m=>{const x=e.current;r="not sure";const{event:S,origin:v,da:b}=m;S instanceof WheelEvent||(S.target===x||x!=null&&x.contains(S.target))&&(u.x=v[0],u.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:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey}))},p=m=>{if(m&&(r="zooming"),r==="zooming")return;const x=Math.abs(l-s),S=w.Dist(c,u);switch(r){case"not sure":{x>24?r="zooming":S>16&&(r="panning");break}case"panning":{x>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:h,onPinchEnd:m=>{const x=e.current,{event:S,origin:v,offset:b}=m;if(S instanceof WheelEvent||!(S.target===x||x!=null&&x.contains(S.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:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey})})},onPinch:m=>{const x=e.current,{event:S,origin:v,offset:b,da:E}=m;if(S instanceof WheelEvent||!(S.target===x||x!=null&&x.contains(S.target)))return;const k=m.type==="gesturechange"||m.type==="gestureend";l=E[0];const C=v[0]-u.x,I=v[1]-u.y;switch(u.x=v[0],u.y=v[1],p(k),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:I},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:C,y:I},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}}}}},[n,e]);d9(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function Im(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function f9(e,n){const t=B();return P.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=zp(l.currentTarget);Du(c,l);const{shape:u,handle:h}=Im(t,e,n);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:u,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:u}=Im(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...On(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=zp(l.currentTarget);Ru(c,l);const{shape:u,handle:h}=Im(t,e,n);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...On(l)})}}},[t,e,n])}const Qe=class Qe{constructor(n=0,t=0,r=0,o=0){g(this,"x",0);g(this,"y",0);g(this,"w",0);g(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=Pd(this.x),this.y=Pd(this.y),this.w=Pd(this.w),this.h=Pd(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:u,maxY:h}=this;switch(n){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{u+=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=(u-l)/(i-o),f=(h-c)/(a-s),y=p<0,m=f<0;if(y){const x=u;u=l,l=x}if(m){const x=h;h=c,c=x}this.minX=l,this.minY=c,this.width=Math.abs(u-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:u,minY:h,maxX:p,maxY:f}=n;switch(t){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(t){case"top":case"top_left":case"top_right":{h+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const y=(p-u)/(l-i),m=(f-h)/(c-a),x=y<0,S=m<0;if(s){const b=(l-i)/(c-a),E=Math.abs(p-u),k=Math.abs(f-h),C=E*(m<0?1:-1)*(1/b),I=k*(y<0?1:-1)*b,T=b<E/k;switch(t){case"top_left":{T?h=f+C:u=p+I;break}case"top_right":{T?h=f+C:p=u-I;break}case"bottom_right":{T?f=h-C:p=u-I;break}case"bottom_left":{T?f=h-C:u=p+I;break}case"bottom":case"top":{const O=(u+p)/2,_=k*b;u=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=u,u=b}if(S){const b=f;f=h,h=b}const v=new Qe(u,h,Math.abs(p-u),Math.abs(f-h));return{box:v,scaleX:+(v.width/n.width*(y>0?1:-1)).toFixed(5),scaleY:+(v.height/n.height*(m>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))}};g(Qe,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),g(Qe,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),g(Qe,"Includes",(n,t)=>Qe.Collides(n,t)||Qe.Contains(n,t)),g(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)),g(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)}),g(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 g9(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 m9(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 y9(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function S9(e){const n=B();P.useLayoutEffect(()=>{let t=new Z;function r(){const c=e.current;if(!c)return null;const u=c.getBoundingClientRect(),h=new Z(u.left||u.x,u.top||u.y,Math.max(u.width,1),Math.max(u.height,1));t.equals(h)||(n.updateViewportScreenBounds(h),t=h)}r();const o=gk(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=v9(a),l.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),l==null||l.removeEventListener("scroll",o),o.cancel()}},[n,e])}/*!
53
+ * Author: excalidraw
54
+ * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
55
+ * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
56
+ */const v9=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){g(this,"a",1);g(this,"b",0);g(this,"c",0);g(this,"d",1);g(this,"e",0);g(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=Ge+Math.acos(n.b/r)*(n.d>0?-1:1)}else t=0;return bS(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=Ge+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:bS(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)}};g(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 Z_(e,n){return n===0?e:Z_(n,e%n)}function Q_(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/Z_(r,t)}class oi{constructor(n){g(this,"isFilled",!1);g(this,"isClosed",!0);g(this,"isLabel",!1);g(this,"debugColor");g(this,"ignore");g(this,"_vertices");g(this,"_bounds");g(this,"_area");g(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)&&nr(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)&&nr(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&&nr(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 Kr extends oi{constructor(t){super({...t,isClosed:!0,isFilled:!1});g(this,"children",[]);g(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],u=i.dist(c),h=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/u);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 x9(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 w9=lr(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=B();x9(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return d.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 u=o.getShapeGeometry(c),h=o.getShapePageTransform(c),p=o.getPointInShapeSpace(c,a),f=u.nearestPoint(p),y=u.distanceToPoint(p,!0),m=Math.abs(y)*s,x=y<0,{vertices:S}=u;return d.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&d.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:d.jsx(J_,{geometry:u})}),t&&S.map((v,b)=>d.jsx("circle",{cx:v.x,cy:v.y,r:2/s,fill:`hsl(${al(b,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${b}`)),r&&m<150&&d.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-m/150,stroke:x?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function J_({geometry:e}){return e instanceof Kr?d.jsx(d.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>d.jsx(J_,{geometry:n},t))}):d.jsx("path",{d:e.toSimpleSvgPath()})}function eT(e){return E4(e)}function b9(){const e=B(),n=S8("userIds",()=>eT(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 tT(e){const n=B();return G(`latestPresence:${e}`,()=>n.getCollaborators().find(r=>r.userId===e),[n,e])??null}const P9=lr(function(){return b9().map(t=>d.jsx(C9,{collaboratorId:t},t))}),C9=lr(function({collaboratorId:n}){const t=B(),r=tT(n),o=E9(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 d.jsx(I9,{latestPresence:r})}),I9=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:u,chatMessage:h,brush:p,scribbles:f,selectedShapeIds:y,userName:m,cursor:x,color:S}=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 d.jsxs(d.Fragment,{children:[p&&r?d.jsx(r,{className:"tl-collaborator__brush",brush:p,color:S,opacity:.1},u+"_brush"):null,v&&s?d.jsx(s,{className:"tl-collaborator__cursor",point:x,color:S,zoom:l,name:m!=="New User"?m:null,chatMessage:h},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:x,color:S,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&f.length?d.jsx(d.Fragment,{children:f.map(b=>d.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:S,zoom:l,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&y.map(b=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:S,opacity:.5},u+"_"+b))]})});function gP(e,n){return n>e.options.collaboratorInactiveTimeoutMs?"inactive":n>e.options.collaboratorIdleTimeoutMs?"idle":"active"}function E9(e,n){const t=P.useRef((n==null?void 0:n.lastActivityTimestamp)??-1),[r,o]=P.useState(()=>gP(e,Date.now()-t.current));return P.useEffect(()=>{const s=e.timers.setInterval(()=>{o(gP(e,Date.now()-t.current))},e.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[e]),n&&(t.current=n.lastActivityTimestamp),r}const nT=P.memo(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const l=B(),{ShapeErrorFallback:c}=it(),u=P.useRef(null),h=P.useRef(null),p=P.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Os("set shape stuff",()=>{const m=l.getShape(n);if(!m)return;const x=p.current,S=l.getShapeClipPath(n)??"none";S!==x.clipPath&&(Jt(u.current,"clip-path",S),Jt(h.current,"clip-path",S),x.clipPath=S);const v=l.getShapePageTransform(n),b=oe.toCssString(v),E=l.getShapeGeometry(m).bounds;b!==x.transform&&(Jt(u.current,"transform",b),Jt(h.current,"transform",b),x.transform=b);const k=E.w%a,C=E.h%a,I=k===0?E.w:E.w+(a-k),T=C===0?E.h:E.h+(a-C);(I!==x.width||T!==x.height)&&(Jt(u.current,"width",Math.max(I,a)+"px"),Jt(u.current,"height",Math.max(T,a)+"px"),Jt(h.current,"width",Math.max(I,a)+"px"),Jt(h.current,"height",Math.max(T,a)+"px"),x.width=I,x.height=T)},[l]),Os("set opacity and z-index",()=>{const m=u.current,x=h.current;Jt(m,"opacity",i),Jt(x,"opacity",i),Jt(m,"z-index",o),Jt(x,"z-index",s)},[i,o,s]),Os("set display",()=>{if(!l.getShape(n))return;const S=l.getCulledShapes().has(n);S!==p.current.isCulled&&(Jt(u.current,"display",S?"none":"block"),Jt(h.current,"display",S?"none":"block"),p.current.isCulled=S)},[l]);const f=P.useCallback(m=>l.annotateError(m,{origin:"shape",willCrashApp:!1}),[l]);if(!t)return null;const y="fill"in t.props&&t.props.fill!=="none";return d.jsxs(d.Fragment,{children:[r.backgroundComponent&&d.jsx("div",{ref:h,className:"tl-shape tl-shape-background","data-shape-type":t.type,draggable:!1,children:d.jsx(qc,{fallback:c,onError:f,children:d.jsx(_9,{shape:t,util:r})})}),d.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":y,draggable:!1,children:d.jsx(qc,{fallback:c,onError:f,children:d.jsx(k9,{shape:t,util:r})})})]})}),k9=P.memo(function({shape:n,util:t}){return Bf("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),_9=P.memo(function({shape:n,util:t}){return Bf("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 T9({className:e}){const n=B(),{Background:t,SvgDefs:r,ShapeIndicators:o}=it(),s=P.useRef(null),i=P.useRef(null),a=P.useRef(null),l=un();S9(s),aH(),sH(),p9(s),uH(s);const c=P.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Os("position layers",function(){const{x:v,y:b,z:E}=n.getCamera();if(c.current.allowTextOutline&&n.environment.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&E<n.options.textShadowLod!==c.current.lodDisableTextOutline){const I=E<n.options.textShadowLod;l.style.setProperty("--tl-text-outline",I?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=I}const k=E>=1?al(E,[1,8],[.125,.5],!0):al(E,[.1,1],[-2,.125],!0),C=`scale(${N(E)}) translate(${N(v+k)}px,${N(b+k)}px)`;Jt(i.current,"transform",C),Jt(a.current,"transform",C)},[n,l]);const u=oH(),h=G("shapeSvgDefs",()=>{const S=new Map;for(const v of gt(n.shapeUtils)){if(!v)return;const b=v.getCanvasSvgDefs();for(const{key:E,component:k}of b)S.has(E)||S.set(E,d.jsx(k,{},E))}return[...S.values()]},[n]),p=G("debug_shapes",()=>xt.hideShapes.get(),[xt]),f=G("debug_svg",()=>xt.debugSvg.get(),[xt]),y=G("debug_geometry",()=>xt.debugGeometry.get(),[xt]),m=G("isEditingAnything",()=>n.getEditingShapeId()!==null,[n]),x=G("isSelectingAnything",()=>!!n.getSelectedShapeIds().length,[n]);return d.jsxs(d.Fragment,{children:[d.jsxs("div",{ref:s,draggable:!1,"data-iseditinganything":m,"data-isselectinganything":x,className:ce("tl-canvas",e),"data-testid":"canvas",...u,children:[d.jsx("svg",{className:"tl-svg-context",children:d.jsxs("defs",{children:[h,d.jsx(H9,{}),d.jsx(K9,{}),r&&d.jsx(r,{})]})}),t&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(t,{})}),d.jsx(A9,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(Y9,{}),d.jsx(V9,{}),p?null:f?d.jsx(N9,{}):d.jsx(B9,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[y?d.jsx(w9,{}):null,d.jsx(L9,{}),d.jsx(O9,{}),d.jsx(j9,{}),d.jsx(D9,{}),o&&d.jsx(o,{}),d.jsx(U9,{}),d.jsx(R9,{}),d.jsx(G9,{}),d.jsx(P9,{})]})}),d.jsx(X9,{})]}),d.jsx(M9,{})]})}function M9(){const{InFrontOfTheCanvas:e}=it();return e?d.jsx(e,{}):null}function A9(){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?d.jsx(i,{x:t,y:r,z:o,size:n}):null}function j9(){const e=B(),n=G("scribbles",()=>e.getInstanceState().scribbles,[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=it();return r&&n.length?n.map(o=>d.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:t},o.id)):null}function O9(){const e=B(),n=G("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=it();return t&&n?d.jsx(t,{className:"tl-user-brush",brush:n}):null}function D9(){const e=B(),n=G("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=it();return t&&n?d.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function R9(){const e=B(),n=G("snapLines",()=>e.snaps.getIndicators(),[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=it();return r&&n.length>0?n.map(o=>d.jsx(r,{className:"tl-user-snapline",line:o,zoom:t},o.id)):null}function L9(){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?d.jsx($9,{shapeId:n}):null}function $9({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(u=>u!==c&&u.type==="vertex"&&w.Dist(c,u)<l)).sort(c=>c.type==="vertex"?1:-1)},[n,r,o,e]);return!t||!i||!s?null:d.jsx(t,{children:d.jsx("g",{transform:oe.toCssString(s),children:i.map(a=>d.jsx(F9,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function F9({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=f9(e,n.id),{Handle:s}=it();return s?d.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:d.jsx(s,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function N9(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>Q_(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return n.map(r=>d.jsxs(P.Fragment,{children:[d.jsx(nT,{...r,dprMultiple:t}),d.jsx(W9,{id:r.id})]},r.id+"_fragment"))}function z9(){const e=B(),n=P.useRef(new Set);return Os("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 B9(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>Q_(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return d.jsxs(d.Fragment,{children:[n.map(r=>d.jsx(nT,{...r,dprMultiple:t},r.id+"_shape")),e.environment.isSafari&&d.jsx(z9,{})]})}function U9(){const e=B(),{ShapeIndicator:n}=it(),t=G("hinting shape ids",()=>Tx(e.getHintingShapeIds()),[e]);return!t.length||!n?null:t.map(r=>d.jsx(n,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function H9(){return d.jsxs("g",{id:"cursor",children:[d.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),d.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function K9(){return d.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function W9({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=oa("shape to svg",async()=>{const a=Math.random();s=a;const c=n.isShapeOfType(e,"frame")?0:10;let u=n.getShapePageBounds(e);if(!u)return;u=u.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:u})});return()=>{s=null,i()}},[n,e,o]),!o||!t?null:d.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 G9(){const e=B(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=it();return!t||!r?null:d.jsx(r,{bounds:t,rotation:n})}function V9(){const e=B(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=it();return!t||!r?null:d.jsx(r,{bounds:t,rotation:n})}function Y9(){const{OnTheCanvas:e}=it();return e?d.jsx(e,{}):null}function X9(){const e=B(),n=G("camera state",()=>e.getCameraState(),[e]);return d.jsx("div",{className:ce("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":n==="idle"})})}function q9({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1}){const i=P.useRef(null);return Ol(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)),d.jsxs("svg",{ref:i,className:ce("tl-overlays__item",e),children:[d.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const mP=P.memo(function({className:n,zoom:t,point:r,color:o,name:s,chatMessage:i}){const a=P.useRef(null);return Ol(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t),r?d.jsxs("div",{ref:a,className:ce("tl-overlays__item",n),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:"#cursor",color:o})}),i?d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function Z9({x:e,y:n,z:t,size:r}){const o=B(),{gridSteps:s}=o.options;return d.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("defs",{children:s.map(({min:i,mid:a,step:l},c)=>{const u=l*r*t,h=.5+e*t,p=.5+n*t,f=h>0?h%u:u+h%u,y=p>0?p%u:u+p%u,m=t<a?al(t,[i,a],[0,1]):1;return d.jsx("pattern",{id:`grid-${l}`,width:u,height:u,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:f,cy:y,r:1,opacity:m})},`grid-pattern-${c}`)})}),s.map(({step:i},a)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${i})`},`grid-rect-${a}`))]})}function Q9({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=Q6.indexOf(e.id);return d.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,t),children:[d.jsx("circle",{className:"tl-handle__bg",r:s}),d.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 d.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,t),children:[d.jsx("circle",{className:"tl-handle__bg",r:s}),d.jsx("circle",{className:"tl-handle__fg",r:i})]})}const J9=({children:e})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),e7=()=>{const{Spinner:e}=it();return d.jsx(Qw,{children:e?d.jsx(e,{}):null})};function Xx(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 yP({scribble:e,zoom:n,color:t,opacity:r,className:o}){return e.points.length?d.jsx("svg",{className:o&&ce("tl-overlays__item",o),children:d.jsx("path",{className:"tl-scribble",d:Xx(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null}function rT({bounds:e,rotation:n}){const t=P.useRef(null);return Ol(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]),d.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function t7({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 Ol(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(),d.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsx("rect",{className:ce("tl-selection__fg__outline"),width:N(e.width),height:N(e.height)})})}const n7=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),r7=({shape:e,util:n})=>Bf("Indicator: "+e.type,()=>n.indicator(n.editor.store.unsafeGetWithoutCapture(e.id))),o7=({editor:e,id:n})=>{const t=G("shape for indicator",()=>e.store.get(n),[e,n]),{ShapeIndicatorErrorFallback:r}=it();return!t||t.isLocked?null:d.jsx(qc,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(r7,{shape:t,util:e.getShapeUtil(t)},t.id)})},SP=P.memo(function({shapeId:n,className:t,color:r,hidden:o,opacity:s}){const i=B(),a=P.useRef(null);return Os("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]),d.jsx("svg",{ref:a,className:ce("tl-overlays__item",t),children:d.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:d.jsx(o7,{editor:i,id:n})})})}),s7=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),oT=P.memo(function(){const n=B(),t=P.useRef(new Set),r=G("should display selected ids",()=>{const i=t.current,a=new Set;if(n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!n.getInstanceState().isChangingStyle){const l=n.getSelectedShapeIds();for(const c of l)a.add(c);if(n.isInAny("select.idle","select.editing_shape")){const c=n.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const u=n.getHoveredShapeId();u&&a.add(u)}}}if(i.size!==a.size)return t.current=a,a;for(const l of a)if(!i.has(l))return t.current=a,a;return i},[n]),o=G("rendering shapes",()=>n.getRenderingShapes(),[n]),{ShapeIndicator:s}=it();return s?o.map(({id:i})=>d.jsx(s,{shapeId:i,hidden:!r.has(i)},i+"_indicator")):null});function i7({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,u,h;return a?(l=r,c=s,u=o,h=i):(l=r,c=i,u=o,h=s),d.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[d.jsx("line",{x1:l,y1:c,x2:u,y2:h}),e.map((p,f)=>d.jsx("g",{transform:`translate(${p.x},${p.y})`,children:d.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},f))]})}function a7({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=Dr(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=Dr(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 d.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:l,endEdge:c},u)=>d.jsx(P.Fragment,{children:i?d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),d.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),d.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),d.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),d.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),d.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),d.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},u))})}function l7({className:e,line:n,zoom:t}){return d.jsx("svg",{className:ce("tl-overlays__item",e),children:n.type==="points"?d.jsx(i7,{...n,zoom:t}):n.type==="gaps"?d.jsx(a7,{...n,zoom:t}):null})}function qx(){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const c7=()=>null;function sT(e,n){const t=P.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Ac(e){return sT(e,T4)}function Zx(e){return sT(e,_k)}const iT=P.createContext(null);function u7({overrides:e={},children:n}){const t=Zx(e),r=P.useMemo(()=>({Background:W6,SvgDefs:c7,Brush:wm,ZoomBrush:wm,CollaboratorBrush:wm,Cursor:mP,CollaboratorCursor:mP,CollaboratorHint:q9,CollaboratorShapeIndicator:SP,Grid:Z9,Scribble:yP,SnapIndicator:l7,Handles:J9,Handle:Q9,CollaboratorScribble:yP,ErrorFallback:lT,ShapeErrorFallback:n7,ShapeIndicatorErrorFallback:s7,Spinner:qx,SelectionBackground:rT,SelectionForeground:t7,ShapeIndicators:oT,ShapeIndicator:SP,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:T9,LoadingScreen:e7,...t}),[t]);return d.jsx(iT.Provider,{value:r,children:n})}function it(){const e=P.useContext(iT);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const Qx={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 aT(){Qx.hardReset()}function d7(){Qx.refreshPage()}const h7="https://github.com/tldraw/tldraw/issues/new",lT=({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 u=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,y]=P.useState(null);P.useLayoutEffect(()=>{var k;p!==null&&y(p);let b=(k=t.current)==null?void 0:k.parentElement,E=!1;for(;b;){if(b.classList.contains("tl-theme__dark")||b.classList.contains("tl-theme__light")){E=!0;break}b=b.parentElement}if(E){y(null);return}y(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),P.useEffect(()=>{if(s){const b=n==null?void 0:n.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(b)}},[s,n]);const m=()=>{const b=document.createElement("textarea");b.value=h??u,document.body.appendChild(b),b.select(),document.execCommand("copy"),b.remove(),i(!0)},x=()=>{d7()},S=async()=>{aT()},v=new URL(h7);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
57
+
58
+ \`\`\`js
59
+ ${h??u}
60
+ \`\`\`
61
+
62
+ My browser: ${navigator.userAgent}`),d.jsxs("div",{ref:t,className:ce("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[d.jsx("div",{className:"tl-error-boundary__overlay"}),n&&d.jsx(L_,{onError:bp,fallback:()=>null,children:d.jsx(Gf.Provider,{value:n,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:ce("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something's gone wrong."}),d.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",d.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&d.jsxs(d.Fragment,{children:["Message:",d.jsx("h4",{children:d.jsx("code",{children:u})}),"Stack trace:",d.jsxs("div",{className:"tl-error-boundary__content__error",children:[d.jsx("pre",{children:d.jsx("code",{children:h??u})}),d.jsx("button",{onClick:m,children:s?"Copied!":"Copy"})]})]}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),d.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[d.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),d.jsx("button",{className:"tl-error-boundary__refresh",onClick:x,children:"Refresh Page"})]})]})]})})]})};function ot(){return Au()}const cT="TLDRAW_USER_DATA_v3",uT=ve({id:pe,name:pe.nullable().optional(),locale:pe.nullable().optional(),color:pe.nullable().optional(),colorScheme:Kf("light","dark","system").optional(),animationSpeed:de.nullable().optional(),edgeScrollSpeed:de.nullable().optional(),isSnapMode:Se.nullable().optional(),isWrapMode:Se.nullable().optional(),isDynamicSizeMode:Se.nullable().optional(),isPasteAtCursorMode:Se.nullable().optional()}),Do={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},Jx=Math.max(...Object.values(Do));function p7(e){e.version<Do.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<Do.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<Do.MakeFieldsNullable,e.version<Do.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<Do.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version<Do.AllowSystemColorScheme&&(e.user.isDarkMode===!0?e.user.colorScheme="dark":e.user.isDarkMode===!1&&(e.user.colorScheme="light"),delete e.user.isDarkMode),e.version<Do.AddDynamicSizeMode&&(e.user.isDynamicSizeMode=!1),e.version<Do.AddPasteAtCursor&&(e.user.isPasteAtCursorMode=!1),e.version=Jx}const vP=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function f7(){return vP[Math.floor(Math.random()*vP.length)]}function g7(){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 jo=Object.freeze({name:"New User",locale:z6(),color:f7(),edgeScrollSpeed:1,animationSpeed:g7()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1});function Em(){return{id:ot()}}function dT(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return Em();const n=rt(e);p7(n);try{return uT.validate(n.user)}catch{return Em()}}function m7(){const e=JSON.parse(Ff(cT)||"null")??null;return dT(e)}const Zc=Mt("globalUserData",null);function y7(){Nf(cT,JSON.stringify({version:Jx,user:Zc.get()}))}function S7(e){uT.validate(e),Zc.set(e),y7(),x7()}const v7=typeof process<"u"&&!1,Xa=typeof BroadcastChannel<"u"&&!v7?new BroadcastChannel("tldraw-user-sync"):null;Xa==null||Xa.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===pT&&(n==null?void 0:n.origin)!==hT()&&Zc.set(dT(n.data))});let km=null;function hT(){return km===null&&(km=ot()),km}const pT="tldraw-user-preferences-change";function x7(){Xa==null||Xa.postMessage({type:pT,origin:hT(),data:{user:fT(),version:Jx}})}function fT(){let e=Zc.get();return e||(e=m7(),Zc.set(e)),e}function gT(e={}){return{derivePresenceState:e.derivePresenceState??(()=>V("presence",()=>null)),userPreferences:e.userPreferences??V("userPreferences",()=>fT()),setUserPreferences:e.setUserPreferences??S7}}var mT={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,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,h||l,p),y=t?t+c:c;return l._events[y]?l._events[y].fn?l._events[y]=[l._events[y],f]:l._events[y].push(f):(l._events[y]=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=[],u,h;if(this._eventsCount===0)return c;for(h in u=this._events)n.call(u,h)&&c.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=t?t+c:c,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,f=h.length,y=new Array(f);p<f;p++)y[p]=h[p].fn;return y},a.prototype.listenerCount=function(c){var u=t?t+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,p,f,y){var m=t?t+c:c;if(!this._events[m])return!1;var x=this._events[m],S=arguments.length,v,b;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),S){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,u),!0;case 3:return x.fn.call(x.context,u,h),!0;case 4:return x.fn.call(x.context,u,h,p),!0;case 5:return x.fn.call(x.context,u,h,p,f),!0;case 6:return x.fn.call(x.context,u,h,p,f,y),!0}for(b=1,v=new Array(S-1);b<S;b++)v[b-1]=arguments[b];x.fn.apply(x.context,v)}else{var E=x.length,k;for(b=0;b<E;b++)switch(x[b].once&&this.removeListener(c,x[b].fn,void 0,!0),S){case 1:x[b].fn.call(x[b].context);break;case 2:x[b].fn.call(x[b].context,u);break;case 3:x[b].fn.call(x[b].context,u,h);break;case 4:x[b].fn.call(x[b].context,u,h,p);break;default:if(!v)for(k=1,v=new Array(S-1);k<S;k++)v[k-1]=arguments[k];x[b].fn.apply(x[b].context,v)}}return!0},a.prototype.on=function(c,u,h){return s(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return s(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,p){var f=t?t+c:c;if(!this._events[f])return this;if(!u)return i(this,f),this;var y=this._events[f];if(y.fn)y.fn===u&&(!p||y.once)&&(!h||y.context===h)&&i(this,f);else{for(var m=0,x=[],S=y.length;m<S;m++)(y[m].fn!==u||p&&!y[m].once||h&&y[m].context!==h)&&x.push(y[m]);x.length?this._events[f]=x.length===1?x[0]:x:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=t?t+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,e.exports=a})(mT);var w7=mT.exports;const b7=ei(w7);var yT={exports:{}},ur={},ST={exports:{}},vT={};/**
63
+ * @license React
64
+ * scheduler.production.min.js
65
+ *
66
+ * Copyright (c) Facebook, Inc. and its affiliates.
67
+ *
68
+ * This source code is licensed under the MIT license found in the
69
+ * LICENSE file in the root directory of this source tree.
70
+ */(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,je=z[Ue];if(0>o(ae,X))Ue<le&&0>o(je,ae)?(z[J]=je,z[Ue]=X,J=Ue):(z[J]=ae,z[Me]=X,J=Me);else if(Ue<le&&0>o(je,X))z[J]=je,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=[],u=1,h=null,p=3,f=!1,y=!1,m=!1,x=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function b(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(m=!1,b(z),!y)if(t(l)!==null)y=!0,W(k);else{var U=t(c);U!==null&&K(E,U.startTime-z)}}function k(z,U){y=!1,m&&(m=!1,S(T),T=-1),f=!0;var X=p;try{for(b(U),h=t(l);h!==null&&(!(h.expirationTime>U)||z&&!M());){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,I=null,T=-1,O=5,_=-1;function M(){return!(e.unstable_now()-_<O)}function L(){if(I!==null){var z=e.unstable_now();_=z;var U=!0;try{U=I(!0,z)}finally{U?j():(C=!1,I=null)}}else C=!1}var j;if(typeof v=="function")j=function(){v(L)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,F=R.port2;R.port1.onmessage=L,j=function(){F.postMessage(null)}}else j=function(){x(L,0)};function W(z){I=z,C||(C=!0,j())}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(){y||f||(y=!0,W(k))},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:u++,callback:U,priorityLevel:z,startTime:X,expirationTime:le,sortIndex:-1},X>J?(z.sortIndex=X,n(c,z),t(l)===null&&z===t(c)&&(m?(S(T),T=-1):m=!0,K(E,X-J))):(z.sortIndex=le,n(l,z),y||f||(y=!0,W(k))),z},e.unstable_shouldYield=M,e.unstable_wrapCallback=function(z){var U=p;return function(){var X=p;p=U;try{return z.apply(this,arguments)}finally{p=X}}}})(vT);ST.exports=vT;var P7=ST.exports;/**
71
+ * @license React
72
+ * react-dom.production.min.js
73
+ *
74
+ * Copyright (c) Facebook, Inc. and its affiliates.
75
+ *
76
+ * This source code is licensed under the MIT license found in the
77
+ * LICENSE file in the root directory of this source tree.
78
+ */var C7=P,ar=P7;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 xT=new Set,Qc={};function sa(e,n){cl(e,n),cl(e+"Capture",n)}function cl(e,n){for(Qc[e]=n,e=0;e<n.length;e++)xT.add(n[e])}var Qo=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ES=Object.prototype.hasOwnProperty,I7=/^[: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]*$/,xP={},wP={};function E7(e){return ES.call(wP,e)?!0:ES.call(xP,e)?!1:I7.test(e)?wP[e]=!0:(xP[e]=!0,!1)}function k7(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 _7(e,n,t,r){if(n===null||typeof n>"u"||k7(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 bn(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 bn(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 bn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Gt[e]=new bn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Gt[e]=new bn(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 bn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Gt[e]=new bn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Gt[e]=new bn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Gt[e]=new bn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Gt[e]=new bn(e,5,!1,e.toLowerCase(),null,!1,!1)});var ew=/[\-:]([a-z])/g;function tw(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(ew,tw);Gt[n]=new bn(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(ew,tw);Gt[n]=new bn(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(ew,tw);Gt[n]=new bn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Gt[e]=new bn(e,1,!1,e.toLowerCase(),null,!1,!1)});Gt.xlinkHref=new bn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Gt[e]=new bn(e,1,!1,e.toLowerCase(),null,!0,!0)});function nw(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")&&(_7(n,t,o,r)&&(t=null),r||o===null?E7(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 ls=C7.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Ed=Symbol.for("react.element"),Aa=Symbol.for("react.portal"),ja=Symbol.for("react.fragment"),rw=Symbol.for("react.strict_mode"),kS=Symbol.for("react.profiler"),wT=Symbol.for("react.provider"),bT=Symbol.for("react.context"),ow=Symbol.for("react.forward_ref"),_S=Symbol.for("react.suspense"),TS=Symbol.for("react.suspense_list"),sw=Symbol.for("react.memo"),bs=Symbol.for("react.lazy"),PT=Symbol.for("react.offscreen"),bP=Symbol.iterator;function ec(e){return e===null||typeof e!="object"?null:(e=bP&&e[bP]||e["@@iterator"],typeof e=="function"?e:null)}var pt=Object.assign,_m;function xc(e){if(_m===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);_m=n&&n[1]||""}return`
79
+ `+_m+e}var Tm=!1;function Mm(e,n){if(!e||Tm)return"";Tm=!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(`
80
+ `),s=r.stack.split(`
81
+ `),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=`
82
+ `+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{Tm=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?xc(e):""}function T7(e){switch(e.tag){case 5:return xc(e.type);case 16:return xc("Lazy");case 13:return xc("Suspense");case 19:return xc("SuspenseList");case 0:case 2:case 15:return e=Mm(e.type,!1),e;case 11:return e=Mm(e.type.render,!1),e;case 1:return e=Mm(e.type,!0),e;default:return""}}function MS(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 ja:return"Fragment";case Aa:return"Portal";case kS:return"Profiler";case rw:return"StrictMode";case _S:return"Suspense";case TS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case bT:return(e.displayName||"Context")+".Consumer";case wT:return(e._context.displayName||"Context")+".Provider";case ow:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case sw:return n=e.displayName||null,n!==null?n:MS(e.type)||"Memo";case bs:n=e._payload,e=e._init;try{return MS(e(n))}catch{}}return null}function M7(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 MS(n);case 8:return n===rw?"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 Gs(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function CT(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function A7(e){var n=CT(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 kd(e){e._valueTracker||(e._valueTracker=A7(e))}function IT(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=CT(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function Up(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 AS(e,n){var t=n.checked;return pt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function PP(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Gs(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 ET(e,n){n=n.checked,n!=null&&nw(e,"checked",n,!1)}function jS(e,n){ET(e,n);var t=Gs(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")?OS(e,n.type,t):n.hasOwnProperty("defaultValue")&&OS(e,n.type,Gs(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function CP(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 OS(e,n,t){(n!=="number"||Up(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var wc=Array.isArray;function qa(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=""+Gs(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 DS(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return pt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function IP(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(wc(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Gs(t)}}function kT(e,n){var t=Gs(n.value),r=Gs(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 EP(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function _T(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 RS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?_T(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var _d,TT=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(_d=_d||document.createElement("div"),_d.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=_d.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Jc(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var jc={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},j7=["Webkit","ms","Moz","O"];Object.keys(jc).forEach(function(e){j7.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),jc[n]=jc[e]})});function MT(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||jc.hasOwnProperty(e)&&jc[e]?(""+n).trim():n+"px"}function AT(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=MT(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var O7=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(O7[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 $S(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 FS=null;function iw(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var NS=null,Za=null,Qa=null;function kP(e){if(e=zu(e)){if(typeof NS!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Zf(n),NS(e.stateNode,e.type,n))}}function jT(e){Za?Qa?Qa.push(e):Qa=[e]:Za=e}function OT(){if(Za){var e=Za,n=Qa;if(Qa=Za=null,kP(e),n)for(e=0;e<n.length;e++)kP(n[e])}}function DT(e,n){return e(n)}function RT(){}var Am=!1;function LT(e,n,t){if(Am)return e(n,t);Am=!0;try{return DT(e,n,t)}finally{Am=!1,(Za!==null||Qa!==null)&&(RT(),OT())}}function eu(e,n){var t=e.stateNode;if(t===null)return null;var r=Zf(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 zS=!1;if(Qo)try{var tc={};Object.defineProperty(tc,"passive",{get:function(){zS=!0}}),window.addEventListener("test",tc,tc),window.removeEventListener("test",tc,tc)}catch{zS=!1}function D7(e,n,t,r,o,s,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{n.apply(t,c)}catch(u){this.onError(u)}}var Oc=!1,Hp=null,Kp=!1,BS=null,R7={onError:function(e){Oc=!0,Hp=e}};function L7(e,n,t,r,o,s,i,a,l){Oc=!1,Hp=null,D7.apply(R7,arguments)}function $7(e,n,t,r,o,s,i,a,l){if(L7.apply(this,arguments),Oc){if(Oc){var c=Hp;Oc=!1,Hp=null}else throw Error(q(198));Kp||(Kp=!0,BS=c)}}function ia(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 $T(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 _P(e){if(ia(e)!==e)throw Error(q(188))}function F7(e){var n=e.alternate;if(!n){if(n=ia(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 _P(o),e;if(s===r)return _P(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 FT(e){return e=F7(e),e!==null?NT(e):null}function NT(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=NT(e);if(n!==null)return n;e=e.sibling}return null}var zT=ar.unstable_scheduleCallback,TP=ar.unstable_cancelCallback,N7=ar.unstable_shouldYield,z7=ar.unstable_requestPaint,wt=ar.unstable_now,B7=ar.unstable_getCurrentPriorityLevel,aw=ar.unstable_ImmediatePriority,BT=ar.unstable_UserBlockingPriority,Wp=ar.unstable_NormalPriority,U7=ar.unstable_LowPriority,UT=ar.unstable_IdlePriority,Vf=null,fo=null;function H7(e){if(fo&&typeof fo.onCommitFiberRoot=="function")try{fo.onCommitFiberRoot(Vf,e,void 0,(e.current.flags&128)===128)}catch{}}var Br=Math.clz32?Math.clz32:G7,K7=Math.log,W7=Math.LN2;function G7(e){return e>>>=0,e===0?32:31-(K7(e)/W7|0)|0}var Td=64,Md=4194304;function bc(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 Gp(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=bc(a):(s&=i,s!==0&&(r=bc(s)))}else i=t&~o,i!==0?r=bc(i):s!==0&&(r=bc(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-Br(n),o=1<<t,r|=e[t],n&=~o;return r}function V7(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 Y7(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-Br(s),a=1<<i,l=o[i];l===-1?(!(a&t)||a&r)&&(o[i]=V7(a,n)):l<=n&&(e.expiredLanes|=a),s&=~a}}function US(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function HT(){var e=Td;return Td<<=1,!(Td&4194240)&&(Td=64),e}function jm(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function Fu(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Br(n),e[n]=t}function X7(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-Br(t),s=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~s}}function lw(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-Br(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var Fe=0;function KT(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var WT,cw,GT,VT,YT,HS=!1,Ad=[],Ls=null,$s=null,Fs=null,tu=new Map,nu=new Map,Is=[],q7="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 MP(e,n){switch(e){case"focusin":case"focusout":Ls=null;break;case"dragenter":case"dragleave":$s=null;break;case"mouseover":case"mouseout":Fs=null;break;case"pointerover":case"pointerout":tu.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":nu.delete(n.pointerId)}}function nc(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=zu(n),n!==null&&cw(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function Z7(e,n,t,r,o){switch(n){case"focusin":return Ls=nc(Ls,e,n,t,r,o),!0;case"dragenter":return $s=nc($s,e,n,t,r,o),!0;case"mouseover":return Fs=nc(Fs,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return tu.set(s,nc(tu.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,nu.set(s,nc(nu.get(s)||null,e,n,t,r,o)),!0}return!1}function XT(e){var n=Ii(e.target);if(n!==null){var t=ia(n);if(t!==null){if(n=t.tag,n===13){if(n=$T(t),n!==null){e.blockedOn=n,YT(e.priority,function(){GT(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 Ph(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=KS(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);FS=r,t.target.dispatchEvent(r),FS=null}else return n=zu(t),n!==null&&cw(n),e.blockedOn=t,!1;n.shift()}return!0}function AP(e,n,t){Ph(e)&&t.delete(n)}function Q7(){HS=!1,Ls!==null&&Ph(Ls)&&(Ls=null),$s!==null&&Ph($s)&&($s=null),Fs!==null&&Ph(Fs)&&(Fs=null),tu.forEach(AP),nu.forEach(AP)}function rc(e,n){e.blockedOn===n&&(e.blockedOn=null,HS||(HS=!0,ar.unstable_scheduleCallback(ar.unstable_NormalPriority,Q7)))}function ru(e){function n(o){return rc(o,e)}if(0<Ad.length){rc(Ad[0],e);for(var t=1;t<Ad.length;t++){var r=Ad[t];r.blockedOn===e&&(r.blockedOn=null)}}for(Ls!==null&&rc(Ls,e),$s!==null&&rc($s,e),Fs!==null&&rc(Fs,e),tu.forEach(n),nu.forEach(n),t=0;t<Is.length;t++)r=Is[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<Is.length&&(t=Is[0],t.blockedOn===null);)XT(t),t.blockedOn===null&&Is.shift()}var Ja=ls.ReactCurrentBatchConfig,Vp=!0;function J7(e,n,t,r){var o=Fe,s=Ja.transition;Ja.transition=null;try{Fe=1,uw(e,n,t,r)}finally{Fe=o,Ja.transition=s}}function eK(e,n,t,r){var o=Fe,s=Ja.transition;Ja.transition=null;try{Fe=4,uw(e,n,t,r)}finally{Fe=o,Ja.transition=s}}function uw(e,n,t,r){if(Vp){var o=KS(e,n,t,r);if(o===null)Um(e,n,r,Yp,t),MP(e,r);else if(Z7(o,e,n,t,r))r.stopPropagation();else if(MP(e,r),n&4&&-1<q7.indexOf(e)){for(;o!==null;){var s=zu(o);if(s!==null&&WT(s),s=KS(e,n,t,r),s===null&&Um(e,n,r,Yp,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else Um(e,n,r,null,t)}}var Yp=null;function KS(e,n,t,r){if(Yp=null,e=iw(r),e=Ii(e),e!==null)if(n=ia(e),n===null)e=null;else if(t=n.tag,t===13){if(e=$T(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 Yp=e,null}function qT(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(B7()){case aw:return 1;case BT:return 4;case Wp:case U7:return 16;case UT:return 536870912;default:return 16}default:return 16}}var _s=null,dw=null,Ch=null;function ZT(){if(Ch)return Ch;var e,n=dw,t=n.length,r,o="value"in _s?_s.value:_s.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 Ch=o.slice(e,1<r?1-r:void 0)}function Ih(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 jd(){return!0}function jP(){return!1}function dr(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)?jd:jP,this.isPropagationStopped=jP,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=jd)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=jd)},persist:function(){},isPersistent:jd}),n}var Dl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},hw=dr(Dl),Nu=pt({},Dl,{view:0,detail:0}),tK=dr(Nu),Om,Dm,oc,Yf=pt({},Nu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:pw,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!==oc&&(oc&&e.type==="mousemove"?(Om=e.screenX-oc.screenX,Dm=e.screenY-oc.screenY):Dm=Om=0,oc=e),Om)},movementY:function(e){return"movementY"in e?e.movementY:Dm}}),OP=dr(Yf),nK=pt({},Yf,{dataTransfer:0}),rK=dr(nK),oK=pt({},Nu,{relatedTarget:0}),Rm=dr(oK),sK=pt({},Dl,{animationName:0,elapsedTime:0,pseudoElement:0}),iK=dr(sK),aK=pt({},Dl,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),lK=dr(aK),cK=pt({},Dl,{data:0}),DP=dr(cK),uK={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},dK={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"},hK={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function pK(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=hK[e])?!!n[e]:!1}function pw(){return pK}var fK=pt({},Nu,{key:function(e){if(e.key){var n=uK[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Ih(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?dK[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:pw,charCode:function(e){return e.type==="keypress"?Ih(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Ih(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),gK=dr(fK),mK=pt({},Yf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),RP=dr(mK),yK=pt({},Nu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:pw}),SK=dr(yK),vK=pt({},Dl,{propertyName:0,elapsedTime:0,pseudoElement:0}),xK=dr(vK),wK=pt({},Yf,{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}),bK=dr(wK),PK=[9,13,27,32],fw=Qo&&"CompositionEvent"in window,Dc=null;Qo&&"documentMode"in document&&(Dc=document.documentMode);var CK=Qo&&"TextEvent"in window&&!Dc,QT=Qo&&(!fw||Dc&&8<Dc&&11>=Dc),LP=" ",$P=!1;function JT(e,n){switch(e){case"keyup":return PK.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function eM(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Oa=!1;function IK(e,n){switch(e){case"compositionend":return eM(n);case"keypress":return n.which!==32?null:($P=!0,LP);case"textInput":return e=n.data,e===LP&&$P?null:e;default:return null}}function EK(e,n){if(Oa)return e==="compositionend"||!fw&&JT(e,n)?(e=ZT(),Ch=dw=_s=null,Oa=!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 QT&&n.locale!=="ko"?null:n.data;default:return null}}var kK={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 FP(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!kK[e.type]:n==="textarea"}function tM(e,n,t,r){jT(r),n=Xp(n,"onChange"),0<n.length&&(t=new hw("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var Rc=null,ou=null;function _K(e){hM(e,0)}function Xf(e){var n=La(e);if(IT(n))return e}function TK(e,n){if(e==="change")return n}var nM=!1;if(Qo){var Lm;if(Qo){var $m="oninput"in document;if(!$m){var NP=document.createElement("div");NP.setAttribute("oninput","return;"),$m=typeof NP.oninput=="function"}Lm=$m}else Lm=!1;nM=Lm&&(!document.documentMode||9<document.documentMode)}function zP(){Rc&&(Rc.detachEvent("onpropertychange",rM),ou=Rc=null)}function rM(e){if(e.propertyName==="value"&&Xf(ou)){var n=[];tM(n,ou,e,iw(e)),LT(_K,n)}}function MK(e,n,t){e==="focusin"?(zP(),Rc=n,ou=t,Rc.attachEvent("onpropertychange",rM)):e==="focusout"&&zP()}function AK(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Xf(ou)}function jK(e,n){if(e==="click")return Xf(n)}function OK(e,n){if(e==="input"||e==="change")return Xf(n)}function DK(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Wr=typeof Object.is=="function"?Object.is:DK;function su(e,n){if(Wr(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(!ES.call(n,o)||!Wr(e[o],n[o]))return!1}return!0}function BP(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function UP(e,n){var t=BP(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=BP(t)}}function oM(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?oM(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function sM(){for(var e=window,n=Up();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=Up(e.document)}return n}function gw(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 RK(e){var n=sM(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&oM(t.ownerDocument.documentElement,t)){if(r!==null&&gw(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=UP(t,s);var i=UP(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 LK=Qo&&"documentMode"in document&&11>=document.documentMode,Da=null,WS=null,Lc=null,GS=!1;function HP(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;GS||Da==null||Da!==Up(r)||(r=Da,"selectionStart"in r&&gw(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}),Lc&&su(Lc,r)||(Lc=r,r=Xp(WS,"onSelect"),0<r.length&&(n=new hw("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=Da)))}function Od(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var Ra={animationend:Od("Animation","AnimationEnd"),animationiteration:Od("Animation","AnimationIteration"),animationstart:Od("Animation","AnimationStart"),transitionend:Od("Transition","TransitionEnd")},Fm={},iM={};Qo&&(iM=document.createElement("div").style,"AnimationEvent"in window||(delete Ra.animationend.animation,delete Ra.animationiteration.animation,delete Ra.animationstart.animation),"TransitionEvent"in window||delete Ra.transitionend.transition);function qf(e){if(Fm[e])return Fm[e];if(!Ra[e])return e;var n=Ra[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in iM)return Fm[e]=n[t];return e}var aM=qf("animationend"),lM=qf("animationiteration"),cM=qf("animationstart"),uM=qf("transitionend"),dM=new Map,KP="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 si(e,n){dM.set(e,n),sa(n,[e])}for(var Nm=0;Nm<KP.length;Nm++){var zm=KP[Nm],$K=zm.toLowerCase(),FK=zm[0].toUpperCase()+zm.slice(1);si($K,"on"+FK)}si(aM,"onAnimationEnd");si(lM,"onAnimationIteration");si(cM,"onAnimationStart");si("dblclick","onDoubleClick");si("focusin","onFocus");si("focusout","onBlur");si(uM,"onTransitionEnd");cl("onMouseEnter",["mouseout","mouseover"]);cl("onMouseLeave",["mouseout","mouseover"]);cl("onPointerEnter",["pointerout","pointerover"]);cl("onPointerLeave",["pointerout","pointerover"]);sa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));sa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));sa("onBeforeInput",["compositionend","keypress","textInput","paste"]);sa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Pc="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(" "),NK=new Set("cancel close invalid load scroll toggle".split(" ").concat(Pc));function WP(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,$7(r,n,void 0,e),e.currentTarget=null}function hM(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;WP(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;WP(o,a,c),s=l}}}if(Kp)throw e=BS,Kp=!1,BS=null,e}function Ze(e,n){var t=n[ZS];t===void 0&&(t=n[ZS]=new Set);var r=e+"__bubble";t.has(r)||(pM(n,e,2,!1),t.add(r))}function Bm(e,n,t){var r=0;n&&(r|=4),pM(t,e,r,n)}var Dd="_reactListening"+Math.random().toString(36).slice(2);function iu(e){if(!e[Dd]){e[Dd]=!0,xT.forEach(function(t){t!=="selectionchange"&&(NK.has(t)||Bm(t,!1,e),Bm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[Dd]||(n[Dd]=!0,Bm("selectionchange",!1,n))}}function pM(e,n,t,r){switch(qT(n)){case 1:var o=J7;break;case 4:o=eK;break;default:o=uw}t=o.bind(null,n,t,e),o=void 0,!zS||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 Um(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=Ii(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}LT(function(){var c=s,u=iw(t),h=[];e:{var p=dM.get(e);if(p!==void 0){var f=hw,y=e;switch(e){case"keypress":if(Ih(t)===0)break e;case"keydown":case"keyup":f=gK;break;case"focusin":y="focus",f=Rm;break;case"focusout":y="blur",f=Rm;break;case"beforeblur":case"afterblur":f=Rm;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=OP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=rK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=SK;break;case aM:case lM:case cM:f=iK;break;case uM:f=xK;break;case"scroll":f=tK;break;case"wheel":f=bK;break;case"copy":case"cut":case"paste":f=lK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=RP}var m=(n&4)!==0,x=!m&&e==="scroll",S=m?p!==null?p+"Capture":null:p;m=[];for(var v=c,b;v!==null;){b=v;var E=b.stateNode;if(b.tag===5&&E!==null&&(b=E,S!==null&&(E=eu(v,S),E!=null&&m.push(au(v,E,b)))),x)break;v=v.return}0<m.length&&(p=new f(p,y,null,t,u),h.push({event:p,listeners:m}))}}if(!(n&7)){e:{if(p=e==="mouseover"||e==="pointerover",f=e==="mouseout"||e==="pointerout",p&&t!==FS&&(y=t.relatedTarget||t.fromElement)&&(Ii(y)||y[Jo]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(y=t.relatedTarget||t.toElement,f=c,y=y?Ii(y):null,y!==null&&(x=ia(y),y!==x||y.tag!==5&&y.tag!==6)&&(y=null)):(f=null,y=c),f!==y)){if(m=OP,E="onMouseLeave",S="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(m=RP,E="onPointerLeave",S="onPointerEnter",v="pointer"),x=f==null?p:La(f),b=y==null?p:La(y),p=new m(E,v+"leave",f,t,u),p.target=x,p.relatedTarget=b,E=null,Ii(u)===c&&(m=new m(S,v+"enter",y,t,u),m.target=b,m.relatedTarget=x,E=m),x=E,f&&y)t:{for(m=f,S=y,v=0,b=m;b;b=ya(b))v++;for(b=0,E=S;E;E=ya(E))b++;for(;0<v-b;)m=ya(m),v--;for(;0<b-v;)S=ya(S),b--;for(;v--;){if(m===S||S!==null&&m===S.alternate)break t;m=ya(m),S=ya(S)}m=null}else m=null;f!==null&&GP(h,p,f,m,!1),y!==null&&x!==null&&GP(h,x,y,m,!0)}}e:{if(p=c?La(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var k=TK;else if(FP(p))if(nM)k=OK;else{k=AK;var C=MK}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(k=jK);if(k&&(k=k(e,c))){tM(h,k,t,u);break e}C&&C(e,p,c),e==="focusout"&&(C=p._wrapperState)&&C.controlled&&p.type==="number"&&OS(p,"number",p.value)}switch(C=c?La(c):window,e){case"focusin":(FP(C)||C.contentEditable==="true")&&(Da=C,WS=c,Lc=null);break;case"focusout":Lc=WS=Da=null;break;case"mousedown":GS=!0;break;case"contextmenu":case"mouseup":case"dragend":GS=!1,HP(h,t,u);break;case"selectionchange":if(LK)break;case"keydown":case"keyup":HP(h,t,u)}var I;if(fw)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 Oa?JT(e,t)&&(T="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(T="onCompositionStart");T&&(QT&&t.locale!=="ko"&&(Oa||T!=="onCompositionStart"?T==="onCompositionEnd"&&Oa&&(I=ZT()):(_s=u,dw="value"in _s?_s.value:_s.textContent,Oa=!0)),C=Xp(c,T),0<C.length&&(T=new DP(T,e,null,t,u),h.push({event:T,listeners:C}),I?T.data=I:(I=eM(t),I!==null&&(T.data=I)))),(I=CK?IK(e,t):EK(e,t))&&(c=Xp(c,"onBeforeInput"),0<c.length&&(u=new DP("onBeforeInput","beforeinput",null,t,u),h.push({event:u,listeners:c}),u.data=I))}hM(h,n)})}function au(e,n,t){return{instance:e,listener:n,currentTarget:t}}function Xp(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=eu(e,t),s!=null&&r.unshift(au(e,s,o)),s=eu(e,n),s!=null&&r.push(au(e,s,o))),e=e.return}return r}function ya(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function GP(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=eu(t,s),l!=null&&i.unshift(au(t,l,a))):o||(l=eu(t,s),l!=null&&i.push(au(t,l,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var zK=/\r\n?/g,BK=/\u0000|\uFFFD/g;function VP(e){return(typeof e=="string"?e:""+e).replace(zK,`
83
+ `).replace(BK,"")}function Rd(e,n,t){if(n=VP(n),VP(e)!==n&&t)throw Error(q(425))}function qp(){}var VS=null,YS=null;function XS(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 qS=typeof setTimeout=="function"?setTimeout:void 0,UK=typeof clearTimeout=="function"?clearTimeout:void 0,YP=typeof Promise=="function"?Promise:void 0,HK=typeof queueMicrotask=="function"?queueMicrotask:typeof YP<"u"?function(e){return YP.resolve(null).then(e).catch(KK)}:qS;function KK(e){setTimeout(function(){throw e})}function Hm(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),ru(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);ru(n)}function Ns(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 XP(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 Rl=Math.random().toString(36).slice(2),io="__reactFiber$"+Rl,lu="__reactProps$"+Rl,Jo="__reactContainer$"+Rl,ZS="__reactEvents$"+Rl,WK="__reactListeners$"+Rl,GK="__reactHandles$"+Rl;function Ii(e){var n=e[io];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Jo]||t[io]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=XP(e);e!==null;){if(t=e[io])return t;e=XP(e)}return n}e=t,t=e.parentNode}return null}function zu(e){return e=e[io]||e[Jo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function La(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Zf(e){return e[lu]||null}var QS=[],$a=-1;function ii(e){return{current:e}}function Je(e){0>$a||(e.current=QS[$a],QS[$a]=null,$a--)}function Ve(e,n){$a++,QS[$a]=e.current,e.current=n}var Vs={},cn=ii(Vs),Fn=ii(!1),Ui=Vs;function ul(e,n){var t=e.type.contextTypes;if(!t)return Vs;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 Nn(e){return e=e.childContextTypes,e!=null}function Zp(){Je(Fn),Je(cn)}function qP(e,n,t){if(cn.current!==Vs)throw Error(q(168));Ve(cn,n),Ve(Fn,t)}function fM(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,M7(e)||"Unknown",o));return pt({},t,r)}function Qp(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Vs,Ui=cn.current,Ve(cn,e),Ve(Fn,Fn.current),!0}function ZP(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=fM(e,n,Ui),r.__reactInternalMemoizedMergedChildContext=e,Je(Fn),Je(cn),Ve(cn,e)):Je(Fn),Ve(Fn,t)}var Fo=null,Qf=!1,Km=!1;function gM(e){Fo===null?Fo=[e]:Fo.push(e)}function VK(e){Qf=!0,gM(e)}function ai(){if(!Km&&Fo!==null){Km=!0;var e=0,n=Fe;try{var t=Fo;for(Fe=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}Fo=null,Qf=!1}catch(o){throw Fo!==null&&(Fo=Fo.slice(e+1)),zT(aw,ai),o}finally{Fe=n,Km=!1}}return null}var Fa=[],Na=0,Jp=null,ef=0,xr=[],wr=0,Hi=null,Bo=1,Uo="";function wi(e,n){Fa[Na++]=ef,Fa[Na++]=Jp,Jp=e,ef=n}function mM(e,n,t){xr[wr++]=Bo,xr[wr++]=Uo,xr[wr++]=Hi,Hi=e;var r=Bo;e=Uo;var o=32-Br(r)-1;r&=~(1<<o),t+=1;var s=32-Br(n)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Bo=1<<32-Br(n)+o|t<<o|r,Uo=s+e}else Bo=1<<s|t<<o|r,Uo=e}function mw(e){e.return!==null&&(wi(e,1),mM(e,1,0))}function yw(e){for(;e===Jp;)Jp=Fa[--Na],Fa[Na]=null,ef=Fa[--Na],Fa[Na]=null;for(;e===Hi;)Hi=xr[--wr],xr[wr]=null,Uo=xr[--wr],xr[wr]=null,Bo=xr[--wr],xr[wr]=null}var rr=null,Jn=null,nt=!1,Fr=null;function yM(e,n){var t=br(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 QP(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,rr=e,Jn=Ns(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,rr=e,Jn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=Hi!==null?{id:Bo,overflow:Uo}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=br(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,rr=e,Jn=null,!0):!1;default:return!1}}function JS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function ev(e){if(nt){var n=Jn;if(n){var t=n;if(!QP(e,n)){if(JS(e))throw Error(q(418));n=Ns(t.nextSibling);var r=rr;n&&QP(e,n)?yM(r,t):(e.flags=e.flags&-4097|2,nt=!1,rr=e)}}else{if(JS(e))throw Error(q(418));e.flags=e.flags&-4097|2,nt=!1,rr=e}}}function JP(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;rr=e}function Ld(e){if(e!==rr)return!1;if(!nt)return JP(e),nt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!XS(e.type,e.memoizedProps)),n&&(n=Jn)){if(JS(e))throw SM(),Error(q(418));for(;n;)yM(e,n),n=Ns(n.nextSibling)}if(JP(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){Jn=Ns(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}Jn=null}}else Jn=rr?Ns(e.stateNode.nextSibling):null;return!0}function SM(){for(var e=Jn;e;)e=Ns(e.nextSibling)}function dl(){Jn=rr=null,nt=!1}function Sw(e){Fr===null?Fr=[e]:Fr.push(e)}var YK=ls.ReactCurrentBatchConfig;function sc(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 $d(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function eC(e){var n=e._init;return n(e._payload)}function vM(e){function n(S,v){if(e){var b=S.deletions;b===null?(S.deletions=[v],S.flags|=16):b.push(v)}}function t(S,v){if(!e)return null;for(;v!==null;)n(S,v),v=v.sibling;return null}function r(S,v){for(S=new Map;v!==null;)v.key!==null?S.set(v.key,v):S.set(v.index,v),v=v.sibling;return S}function o(S,v){return S=Hs(S,v),S.index=0,S.sibling=null,S}function s(S,v,b){return S.index=b,e?(b=S.alternate,b!==null?(b=b.index,b<v?(S.flags|=2,v):b):(S.flags|=2,v)):(S.flags|=1048576,v)}function i(S){return e&&S.alternate===null&&(S.flags|=2),S}function a(S,v,b,E){return v===null||v.tag!==6?(v=Zm(b,S.mode,E),v.return=S,v):(v=o(v,b),v.return=S,v)}function l(S,v,b,E){var k=b.type;return k===ja?u(S,v,b.props.children,E,b.key):v!==null&&(v.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===bs&&eC(k)===v.type)?(E=o(v,b.props),E.ref=sc(S,v,b),E.return=S,E):(E=jh(b.type,b.key,b.props,null,S.mode,E),E.ref=sc(S,v,b),E.return=S,E)}function c(S,v,b,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==b.containerInfo||v.stateNode.implementation!==b.implementation?(v=Qm(b,S.mode,E),v.return=S,v):(v=o(v,b.children||[]),v.return=S,v)}function u(S,v,b,E,k){return v===null||v.tag!==7?(v=Ri(b,S.mode,E,k),v.return=S,v):(v=o(v,b),v.return=S,v)}function h(S,v,b){if(typeof v=="string"&&v!==""||typeof v=="number")return v=Zm(""+v,S.mode,b),v.return=S,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case Ed:return b=jh(v.type,v.key,v.props,null,S.mode,b),b.ref=sc(S,null,v),b.return=S,b;case Aa:return v=Qm(v,S.mode,b),v.return=S,v;case bs:var E=v._init;return h(S,E(v._payload),b)}if(wc(v)||ec(v))return v=Ri(v,S.mode,b,null),v.return=S,v;$d(S,v)}return null}function p(S,v,b,E){var k=v!==null?v.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return k!==null?null:a(S,v,""+b,E);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case Ed:return b.key===k?l(S,v,b,E):null;case Aa:return b.key===k?c(S,v,b,E):null;case bs:return k=b._init,p(S,v,k(b._payload),E)}if(wc(b)||ec(b))return k!==null?null:u(S,v,b,E,null);$d(S,b)}return null}function f(S,v,b,E,k){if(typeof E=="string"&&E!==""||typeof E=="number")return S=S.get(b)||null,a(v,S,""+E,k);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case Ed:return S=S.get(E.key===null?b:E.key)||null,l(v,S,E,k);case Aa:return S=S.get(E.key===null?b:E.key)||null,c(v,S,E,k);case bs:var C=E._init;return f(S,v,b,C(E._payload),k)}if(wc(E)||ec(E))return S=S.get(b)||null,u(v,S,E,k,null);$d(v,E)}return null}function y(S,v,b,E){for(var k=null,C=null,I=v,T=v=0,O=null;I!==null&&T<b.length;T++){I.index>T?(O=I,I=null):O=I.sibling;var _=p(S,I,b[T],E);if(_===null){I===null&&(I=O);break}e&&I&&_.alternate===null&&n(S,I),v=s(_,v,T),C===null?k=_:C.sibling=_,C=_,I=O}if(T===b.length)return t(S,I),nt&&wi(S,T),k;if(I===null){for(;T<b.length;T++)I=h(S,b[T],E),I!==null&&(v=s(I,v,T),C===null?k=I:C.sibling=I,C=I);return nt&&wi(S,T),k}for(I=r(S,I);T<b.length;T++)O=f(I,S,T,b[T],E),O!==null&&(e&&O.alternate!==null&&I.delete(O.key===null?T:O.key),v=s(O,v,T),C===null?k=O:C.sibling=O,C=O);return e&&I.forEach(function(M){return n(S,M)}),nt&&wi(S,T),k}function m(S,v,b,E){var k=ec(b);if(typeof k!="function")throw Error(q(150));if(b=k.call(b),b==null)throw Error(q(151));for(var C=k=null,I=v,T=v=0,O=null,_=b.next();I!==null&&!_.done;T++,_=b.next()){I.index>T?(O=I,I=null):O=I.sibling;var M=p(S,I,_.value,E);if(M===null){I===null&&(I=O);break}e&&I&&M.alternate===null&&n(S,I),v=s(M,v,T),C===null?k=M:C.sibling=M,C=M,I=O}if(_.done)return t(S,I),nt&&wi(S,T),k;if(I===null){for(;!_.done;T++,_=b.next())_=h(S,_.value,E),_!==null&&(v=s(_,v,T),C===null?k=_:C.sibling=_,C=_);return nt&&wi(S,T),k}for(I=r(S,I);!_.done;T++,_=b.next())_=f(I,S,T,_.value,E),_!==null&&(e&&_.alternate!==null&&I.delete(_.key===null?T:_.key),v=s(_,v,T),C===null?k=_:C.sibling=_,C=_);return e&&I.forEach(function(L){return n(S,L)}),nt&&wi(S,T),k}function x(S,v,b,E){if(typeof b=="object"&&b!==null&&b.type===ja&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case Ed:e:{for(var k=b.key,C=v;C!==null;){if(C.key===k){if(k=b.type,k===ja){if(C.tag===7){t(S,C.sibling),v=o(C,b.props.children),v.return=S,S=v;break e}}else if(C.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===bs&&eC(k)===C.type){t(S,C.sibling),v=o(C,b.props),v.ref=sc(S,C,b),v.return=S,S=v;break e}t(S,C);break}else n(S,C);C=C.sibling}b.type===ja?(v=Ri(b.props.children,S.mode,E,b.key),v.return=S,S=v):(E=jh(b.type,b.key,b.props,null,S.mode,E),E.ref=sc(S,v,b),E.return=S,S=E)}return i(S);case Aa: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(S,v.sibling),v=o(v,b.children||[]),v.return=S,S=v;break e}else{t(S,v);break}else n(S,v);v=v.sibling}v=Qm(b,S.mode,E),v.return=S,S=v}return i(S);case bs:return C=b._init,x(S,v,C(b._payload),E)}if(wc(b))return y(S,v,b,E);if(ec(b))return m(S,v,b,E);$d(S,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,v!==null&&v.tag===6?(t(S,v.sibling),v=o(v,b),v.return=S,S=v):(t(S,v),v=Zm(b,S.mode,E),v.return=S,S=v),i(S)):t(S,v)}return x}var hl=vM(!0),xM=vM(!1),tf=ii(null),nf=null,za=null,vw=null;function xw(){vw=za=nf=null}function ww(e){var n=tf.current;Je(tf),e._currentValue=n}function tv(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 el(e,n){nf=e,vw=za=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(Dn=!0),e.firstContext=null)}function Er(e){var n=e._currentValue;if(vw!==e)if(e={context:e,memoizedValue:n,next:null},za===null){if(nf===null)throw Error(q(308));za=e,nf.dependencies={lanes:0,firstContext:e}}else za=za.next=e;return n}var Ei=null;function bw(e){Ei===null?Ei=[e]:Ei.push(e)}function wM(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,bw(n)):(t.next=o.next,o.next=t),n.interleaved=t,es(e,r)}function es(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 Ps=!1;function Pw(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function bM(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 Go(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function zs(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,_e&2){var o=r.pending;return o===null?n.next=n:(n.next=o.next,o.next=n),r.pending=n,es(e,t)}return o=r.interleaved,o===null?(n.next=n,bw(r)):(n.next=o.next,o.next=n),r.interleaved=n,es(e,t)}function Eh(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,lw(e,t)}}function tC(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 rf(e,n,t,r){var o=e.updateQueue;Ps=!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 u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=c:a.next=c,u.lastBaseUpdate=l))}if(s!==null){var h=o.baseState;i=0,u=c=l=null,a=s;do{var p=a.lane,f=a.eventTime;if((r&p)===p){u!==null&&(u=u.next={eventTime:f,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var y=e,m=a;switch(p=n,f=t,m.tag){case 1:if(y=m.payload,typeof y=="function"){h=y.call(f,h,p);break e}h=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=m.payload,p=typeof y=="function"?y.call(f,h,p):y,p==null)break e;h=pt({},h,p);break e;case 2:Ps=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,p=o.effects,p===null?o.effects=[a]:p.push(a))}else f={eventTime:f,lane:p,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(c=u=f,l=h):u=u.next=f,i|=p;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;p=a,a=p.next,p.next=null,o.lastBaseUpdate=p,o.shared.pending=null}}while(!0);if(u===null&&(l=h),o.baseState=l,o.firstBaseUpdate=c,o.lastBaseUpdate=u,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);Wi|=i,e.lanes=i,e.memoizedState=h}}function nC(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 Bu={},go=ii(Bu),cu=ii(Bu),uu=ii(Bu);function ki(e){if(e===Bu)throw Error(q(174));return e}function Cw(e,n){switch(Ve(uu,n),Ve(cu,e),Ve(go,Bu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:RS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=RS(n,e)}Je(go),Ve(go,n)}function pl(){Je(go),Je(cu),Je(uu)}function PM(e){ki(uu.current);var n=ki(go.current),t=RS(n,e.type);n!==t&&(Ve(cu,e),Ve(go,t))}function Iw(e){cu.current===e&&(Je(go),Je(cu))}var ct=ii(0);function of(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 Wm=[];function Ew(){for(var e=0;e<Wm.length;e++)Wm[e]._workInProgressVersionPrimary=null;Wm.length=0}var kh=ls.ReactCurrentDispatcher,Gm=ls.ReactCurrentBatchConfig,Ki=0,ht=null,It=null,Tt=null,sf=!1,$c=!1,du=0,XK=0;function Zt(){throw Error(q(321))}function kw(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Wr(e[t],n[t]))return!1;return!0}function _w(e,n,t,r,o,s){if(Ki=s,ht=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,kh.current=e===null||e.memoizedState===null?JK:eW,e=t(r,o),$c){s=0;do{if($c=!1,du=0,25<=s)throw Error(q(301));s+=1,Tt=It=null,n.updateQueue=null,kh.current=tW,e=t(r,o)}while($c)}if(kh.current=af,n=It!==null&&It.next!==null,Ki=0,Tt=It=ht=null,sf=!1,n)throw Error(q(300));return e}function Tw(){var e=du!==0;return du=0,e}function no(){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 kr(){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 hu(e,n){return typeof n=="function"?n(e):n}function Vm(e){var n=kr(),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 u=c.lane;if((Ki&u)===u)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:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=h,i=r):l=l.next=h,ht.lanes|=u,Wi|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Wr(r,n.memoizedState)||(Dn=!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,Wi|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function Ym(e){var n=kr(),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);Wr(s,n.memoizedState)||(Dn=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function CM(){}function IM(e,n){var t=ht,r=kr(),o=n(),s=!Wr(r.memoizedState,o);if(s&&(r.memoizedState=o,Dn=!0),r=r.queue,Mw(_M.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||Tt!==null&&Tt.memoizedState.tag&1){if(t.flags|=2048,pu(9,kM.bind(null,t,r,o,n),void 0,null),Ot===null)throw Error(q(349));Ki&30||EM(t,n,o)}return o}function EM(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 kM(e,n,t,r){n.value=t,n.getSnapshot=r,TM(n)&&MM(e)}function _M(e,n,t){return t(function(){TM(n)&&MM(e)})}function TM(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Wr(e,t)}catch{return!0}}function MM(e){var n=es(e,1);n!==null&&Ur(n,e,1,-1)}function rC(e){var n=no();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:hu,lastRenderedState:e},n.queue=e,e=e.dispatch=QK.bind(null,ht,e),[n.memoizedState,e]}function pu(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 AM(){return kr().memoizedState}function _h(e,n,t,r){var o=no();ht.flags|=e,o.memoizedState=pu(1|n,t,void 0,r===void 0?null:r)}function Jf(e,n,t,r){var o=kr();r=r===void 0?null:r;var s=void 0;if(It!==null){var i=It.memoizedState;if(s=i.destroy,r!==null&&kw(r,i.deps)){o.memoizedState=pu(n,t,s,r);return}}ht.flags|=e,o.memoizedState=pu(1|n,t,s,r)}function oC(e,n){return _h(8390656,8,e,n)}function Mw(e,n){return Jf(2048,8,e,n)}function jM(e,n){return Jf(4,2,e,n)}function OM(e,n){return Jf(4,4,e,n)}function DM(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 RM(e,n,t){return t=t!=null?t.concat([e]):null,Jf(4,4,DM.bind(null,n,e),t)}function Aw(){}function LM(e,n){var t=kr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&kw(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function $M(e,n){var t=kr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&kw(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function FM(e,n,t){return Ki&21?(Wr(t,n)||(t=HT(),ht.lanes|=t,Wi|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,Dn=!0),e.memoizedState=t)}function qK(e,n){var t=Fe;Fe=t!==0&&4>t?t:4,e(!0);var r=Gm.transition;Gm.transition={};try{e(!1),n()}finally{Fe=t,Gm.transition=r}}function NM(){return kr().memoizedState}function ZK(e,n,t){var r=Us(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},zM(e))BM(n,t);else if(t=wM(e,n,t,r),t!==null){var o=yn();Ur(t,e,r,o),UM(t,n,r)}}function QK(e,n,t){var r=Us(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(zM(e))BM(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,Wr(a,i)){var l=n.interleaved;l===null?(o.next=o,bw(n)):(o.next=l.next,l.next=o),n.interleaved=o;return}}catch{}finally{}t=wM(e,n,o,r),t!==null&&(o=yn(),Ur(t,e,r,o),UM(t,n,r))}}function zM(e){var n=e.alternate;return e===ht||n!==null&&n===ht}function BM(e,n){$c=sf=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function UM(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,lw(e,t)}}var af={readContext:Er,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},JK={readContext:Er,useCallback:function(e,n){return no().memoizedState=[e,n===void 0?null:n],e},useContext:Er,useEffect:oC,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,_h(4194308,4,DM.bind(null,n,e),t)},useLayoutEffect:function(e,n){return _h(4194308,4,e,n)},useInsertionEffect:function(e,n){return _h(4,2,e,n)},useMemo:function(e,n){var t=no();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=no();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=ZK.bind(null,ht,e),[r.memoizedState,e]},useRef:function(e){var n=no();return e={current:e},n.memoizedState=e},useState:rC,useDebugValue:Aw,useDeferredValue:function(e){return no().memoizedState=e},useTransition:function(){var e=rC(!1),n=e[0];return e=qK.bind(null,e[1]),no().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=ht,o=no();if(nt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),Ot===null)throw Error(q(349));Ki&30||EM(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,oC(_M.bind(null,r,s,e),[e]),r.flags|=2048,pu(9,kM.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=no(),n=Ot.identifierPrefix;if(nt){var t=Uo,r=Bo;t=(r&~(1<<32-Br(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=du++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=XK++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},eW={readContext:Er,useCallback:LM,useContext:Er,useEffect:Mw,useImperativeHandle:RM,useInsertionEffect:jM,useLayoutEffect:OM,useMemo:$M,useReducer:Vm,useRef:AM,useState:function(){return Vm(hu)},useDebugValue:Aw,useDeferredValue:function(e){var n=kr();return FM(n,It.memoizedState,e)},useTransition:function(){var e=Vm(hu)[0],n=kr().memoizedState;return[e,n]},useMutableSource:CM,useSyncExternalStore:IM,useId:NM,unstable_isNewReconciler:!1},tW={readContext:Er,useCallback:LM,useContext:Er,useEffect:Mw,useImperativeHandle:RM,useInsertionEffect:jM,useLayoutEffect:OM,useMemo:$M,useReducer:Ym,useRef:AM,useState:function(){return Ym(hu)},useDebugValue:Aw,useDeferredValue:function(e){var n=kr();return It===null?n.memoizedState=e:FM(n,It.memoizedState,e)},useTransition:function(){var e=Ym(hu)[0],n=kr().memoizedState;return[e,n]},useMutableSource:CM,useSyncExternalStore:IM,useId:NM,unstable_isNewReconciler:!1};function Or(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 nv(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 eg={isMounted:function(e){return(e=e._reactInternals)?ia(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=yn(),o=Us(e),s=Go(r,o);s.payload=n,t!=null&&(s.callback=t),n=zs(e,s,o),n!==null&&(Ur(n,e,o,r),Eh(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=yn(),o=Us(e),s=Go(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=zs(e,s,o),n!==null&&(Ur(n,e,o,r),Eh(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=yn(),r=Us(e),o=Go(t,r);o.tag=2,n!=null&&(o.callback=n),n=zs(e,o,r),n!==null&&(Ur(n,e,r,t),Eh(n,e,r))}};function sC(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?!su(t,r)||!su(o,s):!0}function HM(e,n,t){var r=!1,o=Vs,s=n.contextType;return typeof s=="object"&&s!==null?s=Er(s):(o=Nn(n)?Ui:cn.current,r=n.contextTypes,s=(r=r!=null)?ul(e,o):Vs),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=eg,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function iC(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&&eg.enqueueReplaceState(n,n.state,null)}function rv(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs={},Pw(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=Er(s):(s=Nn(n)?Ui:cn.current,o.context=ul(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(nv(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&&eg.enqueueReplaceState(o,o.state,null),rf(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function fl(e,n){try{var t="",r=n;do t+=T7(r),r=r.return;while(r);var o=t}catch(s){o=`
84
+ Error generating stack: `+s.message+`
85
+ `+s.stack}return{value:e,source:n,stack:o,digest:null}}function Xm(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function ov(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var nW=typeof WeakMap=="function"?WeakMap:Map;function KM(e,n,t){t=Go(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){cf||(cf=!0,fv=r),ov(e,n)},t}function WM(e,n,t){t=Go(-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(){ov(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){ov(e,n),typeof r!="function"&&(Bs===null?Bs=new Set([this]):Bs.add(this));var i=n.stack;this.componentDidCatch(n.value,{componentStack:i!==null?i:""})}),t}function aC(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new nW;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=mW.bind(null,e,n,t),n.then(e,e))}function lC(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 cC(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=Go(-1,1),n.tag=2,zs(t,n,1))),t.lanes|=1),e)}var rW=ls.ReactCurrentOwner,Dn=!1;function fn(e,n,t,r){n.child=e===null?xM(n,null,t,r):hl(n,e.child,t,r)}function uC(e,n,t,r,o){t=t.render;var s=n.ref;return el(n,o),r=_w(e,n,t,r,s,o),t=Tw(),e!==null&&!Dn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,ts(e,n,o)):(nt&&t&&mw(n),n.flags|=1,fn(e,n,r,o),n.child)}function dC(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!Nw(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,GM(e,n,s,r,o)):(e=jh(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:su,t(i,r)&&e.ref===n.ref)return ts(e,n,o)}return n.flags|=1,e=Hs(s,r),e.ref=n.ref,e.return=n,n.child=e}function GM(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(su(s,r)&&e.ref===n.ref)if(Dn=!1,n.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(Dn=!0);else return n.lanes=e.lanes,ts(e,n,o)}return sv(e,n,t,r,o)}function VM(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},Ve(Ua,qn),qn|=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,Ve(Ua,qn),qn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ve(Ua,qn),qn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ve(Ua,qn),qn|=r;return fn(e,n,o,t),n.child}function YM(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function sv(e,n,t,r,o){var s=Nn(t)?Ui:cn.current;return s=ul(n,s),el(n,o),t=_w(e,n,t,r,s,o),r=Tw(),e!==null&&!Dn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,ts(e,n,o)):(nt&&r&&mw(n),n.flags|=1,fn(e,n,t,o),n.child)}function hC(e,n,t,r,o){if(Nn(t)){var s=!0;Qp(n)}else s=!1;if(el(n,o),n.stateNode===null)Th(e,n),HM(n,t,r),rv(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=Er(c):(c=Nn(t)?Ui:cn.current,c=ul(n,c));var u=t.getDerivedStateFromProps,h=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";h||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&iC(n,i,r,c),Ps=!1;var p=n.memoizedState;i.state=p,rf(n,r,i,o),l=n.memoizedState,a!==r||p!==l||Fn.current||Ps?(typeof u=="function"&&(nv(n,t,u,r),l=n.memoizedState),(a=Ps||sC(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,bM(e,n),a=n.memoizedProps,c=n.type===n.elementType?a:Or(n.type,a),i.props=c,h=n.pendingProps,p=i.context,l=t.contextType,typeof l=="object"&&l!==null?l=Er(l):(l=Nn(t)?Ui:cn.current,l=ul(n,l));var f=t.getDerivedStateFromProps;(u=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==h||p!==l)&&iC(n,i,r,l),Ps=!1,p=n.memoizedState,i.state=p,rf(n,r,i,o);var y=n.memoizedState;a!==h||p!==y||Fn.current||Ps?(typeof f=="function"&&(nv(n,t,f,r),y=n.memoizedState),(c=Ps||sC(n,t,c,r,p,y,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,y,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,y,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=y),i.props=r,i.state=y,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 iv(e,n,t,r,s,o)}function iv(e,n,t,r,o,s){YM(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&ZP(n,t,!1),ts(e,n,s);r=n.stateNode,rW.current=n;var a=i&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&i?(n.child=hl(n,e.child,null,s),n.child=hl(n,null,a,s)):fn(e,n,a,s),n.memoizedState=r.state,o&&ZP(n,t,!0),n.child}function XM(e){var n=e.stateNode;n.pendingContext?qP(e,n.pendingContext,n.pendingContext!==n.context):n.context&&qP(e,n.context,!1),Cw(e,n.containerInfo)}function pC(e,n,t,r,o){return dl(),Sw(o),n.flags|=256,fn(e,n,t,r),n.child}var av={dehydrated:null,treeContext:null,retryLane:0};function lv(e){return{baseLanes:e,cachePool:null,transitions:null}}function qM(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),Ve(ct,o&1),e===null)return ev(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=rg(i,r,0,null),e=Ri(e,r,t,null),s.return=n,e.return=n,s.sibling=e,n.child=s,n.child.memoizedState=lv(t),n.memoizedState=av,e):jw(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return oW(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=Hs(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Hs(a,s):(s=Ri(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?lv(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=av,r}return s=e.child,e=s.sibling,r=Hs(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 jw(e,n){return n=rg({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Fd(e,n,t,r){return r!==null&&Sw(r),hl(n,e.child,null,t),e=jw(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function oW(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=Xm(Error(q(422))),Fd(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=rg({mode:"visible",children:r.children},o,0,null),s=Ri(s,o,i,null),s.flags|=2,r.return=n,s.return=n,r.sibling=s,n.child=r,n.mode&1&&hl(n,e.child,null,i),n.child.memoizedState=lv(i),n.memoizedState=av,s);if(!(n.mode&1))return Fd(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=Xm(s,r,void 0),Fd(e,n,i,r)}if(a=(i&e.childLanes)!==0,Dn||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,es(e,o),Ur(r,e,o,-1))}return Fw(),r=Xm(Error(q(421))),Fd(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=yW.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,Jn=Ns(o.nextSibling),rr=n,nt=!0,Fr=null,e!==null&&(xr[wr++]=Bo,xr[wr++]=Uo,xr[wr++]=Hi,Bo=e.id,Uo=e.overflow,Hi=n),n=jw(n,r.children),n.flags|=4096,n)}function fC(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),tv(e.return,n,t)}function qm(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 ZM(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&&fC(e,t,n);else if(e.tag===19)fC(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(Ve(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&&of(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),qm(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&&of(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}qm(n,!0,t,null,s);break;case"together":qm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Th(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function ts(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),Wi|=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=Hs(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=Hs(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function sW(e,n,t){switch(n.tag){case 3:XM(n),dl();break;case 5:PM(n);break;case 1:Nn(n.type)&&Qp(n);break;case 4:Cw(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ve(tf,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ve(ct,ct.current&1),n.flags|=128,null):t&n.child.childLanes?qM(e,n,t):(Ve(ct,ct.current&1),e=ts(e,n,t),e!==null?e.sibling:null);Ve(ct,ct.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return ZM(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ve(ct,ct.current),r)break;return null;case 22:case 23:return n.lanes=0,VM(e,n,t)}return ts(e,n,t)}var QM,cv,JM,e2;QM=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}};cv=function(){};JM=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,ki(go.current);var s=null;switch(t){case"input":o=AS(e,o),r=AS(e,r),s=[];break;case"select":o=pt({},o,{value:void 0}),r=pt({},r,{value:void 0}),s=[];break;case"textarea":o=DS(e,o),r=DS(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=qp)}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"&&(Qc.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"&&(Qc.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)}};e2=function(e,n,t,r){t!==r&&(n.flags|=4)};function ic(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 iW(e,n,t){var r=n.pendingProps;switch(yw(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 Nn(n.type)&&Zp(),Qt(n),null;case 3:return r=n.stateNode,pl(),Je(Fn),Je(cn),Ew(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Ld(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Fr!==null&&(yv(Fr),Fr=null))),cv(e,n),Qt(n),null;case 5:Iw(n);var o=ki(uu.current);if(t=n.type,e!==null&&n.stateNode!=null)JM(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=ki(go.current),Ld(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[io]=n,r[lu]=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<Pc.length;o++)Ze(Pc[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":PP(r,s),Ze("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Ze("invalid",r);break;case"textarea":IP(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&&Rd(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Rd(r.textContent,a,e),o=["children",""+a]):Qc.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Ze("scroll",r)}switch(t){case"input":kd(r),CP(r,s,!0);break;case"textarea":kd(r),EP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=qp)}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=_T(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[io]=n,e[lu]=r,QM(e,n,!1,!1),n.stateNode=e;e:{switch(i=$S(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<Pc.length;o++)Ze(Pc[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":PP(e,r),o=AS(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":IP(e,r),o=DS(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"?AT(e,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&TT(e,l)):s==="children"?typeof l=="string"?(t!=="textarea"||l!=="")&&Jc(e,l):typeof l=="number"&&Jc(e,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Qc.hasOwnProperty(s)?l!=null&&s==="onScroll"&&Ze("scroll",e):l!=null&&nw(e,s,l,i))}switch(t){case"input":kd(e),CP(e,r,!1);break;case"textarea":kd(e),EP(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Gs(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?qa(e,!!r.multiple,s,!1):r.defaultValue!=null&&qa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=qp)}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)e2(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=ki(uu.current),ki(go.current),Ld(n)){if(r=n.stateNode,t=n.memoizedProps,r[io]=n,(s=r.nodeValue!==t)&&(e=rr,e!==null))switch(e.tag){case 3:Rd(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Rd(r.nodeValue,t,(e.mode&1)!==0)}s&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[io]=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&&Jn!==null&&n.mode&1&&!(n.flags&128))SM(),dl(),n.flags|=98560,s=!1;else if(s=Ld(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[io]=n}else dl(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Qt(n),s=!1}else Fr!==null&&(yv(Fr),Fr=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):Fw())),n.updateQueue!==null&&(n.flags|=4),Qt(n),null);case 4:return pl(),cv(e,n),e===null&&iu(n.stateNode.containerInfo),Qt(n),null;case 10:return ww(n.type._context),Qt(n),null;case 17:return Nn(n.type)&&Zp(),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)ic(s,!1);else{if(Et!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=of(e),i!==null){for(n.flags|=128,ic(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 Ve(ct,ct.current&1|2),n.child}e=e.sibling}s.tail!==null&&wt()>gl&&(n.flags|=128,r=!0,ic(s,!1),n.lanes=4194304)}else{if(!r)if(e=of(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),ic(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!nt)return Qt(n),null}else 2*wt()-s.renderingStartTime>gl&&t!==1073741824&&(n.flags|=128,r=!0,ic(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=wt(),n.sibling=null,t=ct.current,Ve(ct,r?t&1|2:t&1),n):(Qt(n),null);case 22:case 23:return $w(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?qn&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 aW(e,n){switch(yw(n),n.tag){case 1:return Nn(n.type)&&Zp(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return pl(),Je(Fn),Je(cn),Ew(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return Iw(n),null;case 13:if(Je(ct),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));dl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Je(ct),null;case 4:return pl(),null;case 10:return ww(n.type._context),null;case 22:case 23:return $w(),null;case 24:return null;default:return null}}var Nd=!1,rn=!1,lW=typeof WeakSet=="function"?WeakSet:Set,te=null;function Ba(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 uv(e,n,t){try{t()}catch(r){mt(e,n,r)}}var gC=!1;function cW(e,n){if(VS=Vp,e=sM(),gw(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,u=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&&++u===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(YS={focusedElem:e,selectionRange:t},Vp=!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 y=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var m=y.memoizedProps,x=y.memoizedState,S=n.stateNode,v=S.getSnapshotBeforeUpdate(n.elementType===n.type?m:Or(n.type,m),x);S.__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 y=gC,gC=!1,y}function Fc(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&&uv(n,t,s)}o=o.next}while(o!==r)}}function tg(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 dv(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 t2(e){var n=e.alternate;n!==null&&(e.alternate=null,t2(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[io],delete n[lu],delete n[ZS],delete n[WK],delete n[GK])),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 n2(e){return e.tag===5||e.tag===3||e.tag===4}function mC(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||n2(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 hv(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=qp));else if(r!==4&&(e=e.child,e!==null))for(hv(e,n,t),e=e.sibling;e!==null;)hv(e,n,t),e=e.sibling}function pv(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(pv(e,n,t),e=e.sibling;e!==null;)pv(e,n,t),e=e.sibling}var $t=null,Rr=!1;function ys(e,n,t){for(t=t.child;t!==null;)r2(e,n,t),t=t.sibling}function r2(e,n,t){if(fo&&typeof fo.onCommitFiberUnmount=="function")try{fo.onCommitFiberUnmount(Vf,t)}catch{}switch(t.tag){case 5:rn||Ba(t,n);case 6:var r=$t,o=Rr;$t=null,ys(e,n,t),$t=r,Rr=o,$t!==null&&(Rr?(e=$t,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):$t.removeChild(t.stateNode));break;case 18:$t!==null&&(Rr?(e=$t,t=t.stateNode,e.nodeType===8?Hm(e.parentNode,t):e.nodeType===1&&Hm(e,t),ru(e)):Hm($t,t.stateNode));break;case 4:r=$t,o=Rr,$t=t.stateNode.containerInfo,Rr=!0,ys(e,n,t),$t=r,Rr=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)&&uv(t,n,i),o=o.next}while(o!==r)}ys(e,n,t);break;case 1:if(!rn&&(Ba(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)}ys(e,n,t);break;case 21:ys(e,n,t);break;case 22:t.mode&1?(rn=(r=rn)||t.memoizedState!==null,ys(e,n,t),rn=r):ys(e,n,t);break;default:ys(e,n,t)}}function yC(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new lW),n.forEach(function(r){var o=SW.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function jr(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,Rr=!1;break e;case 3:$t=a.stateNode.containerInfo,Rr=!0;break e;case 4:$t=a.stateNode.containerInfo,Rr=!0;break e}a=a.return}if($t===null)throw Error(q(160));r2(s,i,o),$t=null,Rr=!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;)o2(n,e),n=n.sibling}function o2(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(jr(n,e),to(e),r&4){try{Fc(3,e,e.return),tg(3,e)}catch(m){mt(e,e.return,m)}try{Fc(5,e,e.return)}catch(m){mt(e,e.return,m)}}break;case 1:jr(n,e),to(e),r&512&&t!==null&&Ba(t,t.return);break;case 5:if(jr(n,e),to(e),r&512&&t!==null&&Ba(t,t.return),e.flags&32){var o=e.stateNode;try{Jc(o,"")}catch(m){mt(e,e.return,m)}}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&&ET(o,s),$S(a,i);var c=$S(a,s);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?AT(o,h):u==="dangerouslySetInnerHTML"?TT(o,h):u==="children"?Jc(o,h):nw(o,u,h,c)}switch(a){case"input":jS(o,s);break;case"textarea":kT(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?qa(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?qa(o,!!s.multiple,s.defaultValue,!0):qa(o,!!s.multiple,s.multiple?[]:"",!1))}o[lu]=s}catch(m){mt(e,e.return,m)}}break;case 6:if(jr(n,e),to(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(m){mt(e,e.return,m)}}break;case 3:if(jr(n,e),to(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{ru(n.containerInfo)}catch(m){mt(e,e.return,m)}break;case 4:jr(n,e),to(e);break;case 13:jr(n,e),to(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(Rw=wt())),r&4&&yC(e);break;case 22:if(u=t!==null&&t.memoizedState!==null,e.mode&1?(rn=(c=rn)||u,jr(n,e),rn=c):jr(n,e),to(e),r&8192){if(c=e.memoizedState!==null,(e.stateNode.isHidden=c)&&!u&&e.mode&1)for(te=e,u=e.child;u!==null;){for(h=te=u;te!==null;){switch(p=te,f=p.child,p.tag){case 0:case 11:case 14:case 15:Fc(4,p,p.return);break;case 1:Ba(p,p.return);var y=p.stateNode;if(typeof y.componentWillUnmount=="function"){r=p,t=p.return;try{n=r,y.props=n.memoizedProps,y.state=n.memoizedState,y.componentWillUnmount()}catch(m){mt(r,t,m)}}break;case 5:Ba(p,p.return);break;case 22:if(p.memoizedState!==null){vC(h);continue}}f!==null?(f.return=p,te=f):vC(h)}u=u.sibling}e:for(u=null,h=e;;){if(h.tag===5){if(u===null){u=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=MT("display",i))}catch(m){mt(e,e.return,m)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(m){mt(e,e.return,m)}}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;u===h&&(u=null),h=h.return}u===h&&(u=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:jr(n,e),to(e),r&4&&yC(e);break;case 21:break;default:jr(n,e),to(e)}}function to(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(n2(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&&(Jc(o,""),r.flags&=-33);var s=mC(e);pv(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=mC(e);hv(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 uW(e,n,t){te=e,s2(e)}function s2(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||Nd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||rn;a=Nd;var c=rn;if(Nd=i,(rn=l)&&!c)for(te=o;te!==null;)i=te,l=i.child,i.tag===22&&i.memoizedState!==null?xC(o):l!==null?(l.return=i,te=l):xC(o);for(;s!==null;)te=s,s2(s),s=s.sibling;te=o,Nd=a,rn=c}SC(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,te=s):SC(e)}}function SC(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||tg(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:Or(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&nC(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}nC(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 u=c.memoizedState;if(u!==null){var h=u.dehydrated;h!==null&&ru(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}rn||n.flags&512&&dv(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 vC(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 xC(e){for(;te!==null;){var n=te;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{tg(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{dv(n)}catch(l){mt(n,s,l)}break;case 5:var i=n.return;try{dv(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 dW=Math.ceil,lf=ls.ReactCurrentDispatcher,Ow=ls.ReactCurrentOwner,Cr=ls.ReactCurrentBatchConfig,_e=0,Ot=null,Pt=null,Kt=0,qn=0,Ua=ii(0),Et=0,fu=null,Wi=0,ng=0,Dw=0,Nc=null,Mn=null,Rw=0,gl=1/0,Lo=null,cf=!1,fv=null,Bs=null,zd=!1,Ts=null,uf=0,zc=0,gv=null,Mh=-1,Ah=0;function yn(){return _e&6?wt():Mh!==-1?Mh:Mh=wt()}function Us(e){return e.mode&1?_e&2&&Kt!==0?Kt&-Kt:YK.transition!==null?(Ah===0&&(Ah=HT()),Ah):(e=Fe,e!==0||(e=window.event,e=e===void 0?16:qT(e.type)),e):1}function Ur(e,n,t,r){if(50<zc)throw zc=0,gv=null,Error(q(185));Fu(e,t,r),(!(_e&2)||e!==Ot)&&(e===Ot&&(!(_e&2)&&(ng|=t),Et===4&&Es(e,Kt)),zn(e,r),t===1&&_e===0&&!(n.mode&1)&&(gl=wt()+500,Qf&&ai()))}function zn(e,n){var t=e.callbackNode;Y7(e,n);var r=Gp(e,e===Ot?Kt:0);if(r===0)t!==null&&TP(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&TP(t),n===1)e.tag===0?VK(wC.bind(null,e)):gM(wC.bind(null,e)),HK(function(){!(_e&6)&&ai()}),t=null;else{switch(KT(r)){case 1:t=aw;break;case 4:t=BT;break;case 16:t=Wp;break;case 536870912:t=UT;break;default:t=Wp}t=p2(t,i2.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function i2(e,n){if(Mh=-1,Ah=0,_e&6)throw Error(q(327));var t=e.callbackNode;if(tl()&&e.callbackNode!==t)return null;var r=Gp(e,e===Ot?Kt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=df(e,r);else{n=r;var o=_e;_e|=2;var s=l2();(Ot!==e||Kt!==n)&&(Lo=null,gl=wt()+500,Di(e,n));do try{fW();break}catch(a){a2(e,a)}while(!0);xw(),lf.current=s,_e=o,Pt!==null?n=0:(Ot=null,Kt=0,n=Et)}if(n!==0){if(n===2&&(o=US(e),o!==0&&(r=o,n=mv(e,o))),n===1)throw t=fu,Di(e,0),Es(e,r),zn(e,wt()),t;if(n===6)Es(e,r);else{if(o=e.current.alternate,!(r&30)&&!hW(o)&&(n=df(e,r),n===2&&(s=US(e),s!==0&&(r=s,n=mv(e,s))),n===1))throw t=fu,Di(e,0),Es(e,r),zn(e,wt()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:bi(e,Mn,Lo);break;case 3:if(Es(e,r),(r&130023424)===r&&(n=Rw+500-wt(),10<n)){if(Gp(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){yn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=qS(bi.bind(null,e,Mn,Lo),n);break}bi(e,Mn,Lo);break;case 4:if(Es(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var i=31-Br(r);s=1<<i,i=n[i],i>o&&(o=i),r&=~s}if(r=o,r=wt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*dW(r/1960))-r,10<r){e.timeoutHandle=qS(bi.bind(null,e,Mn,Lo),r);break}bi(e,Mn,Lo);break;case 5:bi(e,Mn,Lo);break;default:throw Error(q(329))}}}return zn(e,wt()),e.callbackNode===t?i2.bind(null,e):null}function mv(e,n){var t=Nc;return e.current.memoizedState.isDehydrated&&(Di(e,n).flags|=256),e=df(e,n),e!==2&&(n=Mn,Mn=t,n!==null&&yv(n)),e}function yv(e){Mn===null?Mn=e:Mn.push.apply(Mn,e)}function hW(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(!Wr(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 Es(e,n){for(n&=~Dw,n&=~ng,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-Br(n),r=1<<t;e[t]=-1,n&=~r}}function wC(e){if(_e&6)throw Error(q(327));tl();var n=Gp(e,0);if(!(n&1))return zn(e,wt()),null;var t=df(e,n);if(e.tag!==0&&t===2){var r=US(e);r!==0&&(n=r,t=mv(e,r))}if(t===1)throw t=fu,Di(e,0),Es(e,n),zn(e,wt()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,bi(e,Mn,Lo),zn(e,wt()),null}function Lw(e,n){var t=_e;_e|=1;try{return e(n)}finally{_e=t,_e===0&&(gl=wt()+500,Qf&&ai())}}function Gi(e){Ts!==null&&Ts.tag===0&&!(_e&6)&&tl();var n=_e;_e|=1;var t=Cr.transition,r=Fe;try{if(Cr.transition=null,Fe=1,e)return e()}finally{Fe=r,Cr.transition=t,_e=n,!(_e&6)&&ai()}}function $w(){qn=Ua.current,Je(Ua)}function Di(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,UK(t)),Pt!==null)for(t=Pt.return;t!==null;){var r=t;switch(yw(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Zp();break;case 3:pl(),Je(Fn),Je(cn),Ew();break;case 5:Iw(r);break;case 4:pl();break;case 13:Je(ct);break;case 19:Je(ct);break;case 10:ww(r.type._context);break;case 22:case 23:$w()}t=t.return}if(Ot=e,Pt=e=Hs(e.current,null),Kt=qn=n,Et=0,fu=null,Dw=ng=Wi=0,Mn=Nc=null,Ei!==null){for(n=0;n<Ei.length;n++)if(t=Ei[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}Ei=null}return e}function a2(e,n){do{var t=Pt;try{if(xw(),kh.current=af,sf){for(var r=ht.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}sf=!1}if(Ki=0,Tt=It=ht=null,$c=!1,du=0,Ow.current=null,t===null||t.return===null){Et=1,fu=n,Pt=null;break}e:{var s=e,i=t.return,a=t,l=n;if(n=Kt,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,u=a,h=u.tag;if(!(u.mode&1)&&(h===0||h===11||h===15)){var p=u.alternate;p?(u.updateQueue=p.updateQueue,u.memoizedState=p.memoizedState,u.lanes=p.lanes):(u.updateQueue=null,u.memoizedState=null)}var f=lC(i);if(f!==null){f.flags&=-257,cC(f,i,a,s,n),f.mode&1&&aC(s,c,n),n=f,l=c;var y=n.updateQueue;if(y===null){var m=new Set;m.add(l),n.updateQueue=m}else y.add(l);break e}else{if(!(n&1)){aC(s,c,n),Fw();break e}l=Error(q(426))}}else if(nt&&a.mode&1){var x=lC(i);if(x!==null){!(x.flags&65536)&&(x.flags|=256),cC(x,i,a,s,n),Sw(fl(l,a));break e}}s=l=fl(l,a),Et!==4&&(Et=2),Nc===null?Nc=[s]:Nc.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var S=KM(s,l,n);tC(s,S);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"&&(Bs===null||!Bs.has(b)))){s.flags|=65536,n&=-n,s.lanes|=n;var E=WM(s,a,n);tC(s,E);break e}}s=s.return}while(s!==null)}u2(t)}catch(k){n=k,Pt===t&&t!==null&&(Pt=t=t.return);continue}break}while(!0)}function l2(){var e=lf.current;return lf.current=af,e===null?af:e}function Fw(){(Et===0||Et===3||Et===2)&&(Et=4),Ot===null||!(Wi&268435455)&&!(ng&268435455)||Es(Ot,Kt)}function df(e,n){var t=_e;_e|=2;var r=l2();(Ot!==e||Kt!==n)&&(Lo=null,Di(e,n));do try{pW();break}catch(o){a2(e,o)}while(!0);if(xw(),_e=t,lf.current=r,Pt!==null)throw Error(q(261));return Ot=null,Kt=0,Et}function pW(){for(;Pt!==null;)c2(Pt)}function fW(){for(;Pt!==null&&!N7();)c2(Pt)}function c2(e){var n=h2(e.alternate,e,qn);e.memoizedProps=e.pendingProps,n===null?u2(e):Pt=n,Ow.current=null}function u2(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=aW(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=iW(t,n,qn),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=Cr.transition;try{Cr.transition=null,Fe=1,gW(e,n,t,r)}finally{Cr.transition=o,Fe=r}return null}function gW(e,n,t,r){do tl();while(Ts!==null);if(_e&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(X7(e,s),e===Ot&&(Pt=Ot=null,Kt=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||zd||(zd=!0,p2(Wp,function(){return tl(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=Cr.transition,Cr.transition=null;var i=Fe;Fe=1;var a=_e;_e|=4,Ow.current=null,cW(e,t),o2(t,e),RK(YS),Vp=!!VS,YS=VS=null,e.current=t,uW(t),z7(),_e=a,Fe=i,Cr.transition=s}else e.current=t;if(zd&&(zd=!1,Ts=e,uf=o),s=e.pendingLanes,s===0&&(Bs=null),H7(t.stateNode),zn(e,wt()),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(cf)throw cf=!1,e=fv,fv=null,e;return uf&1&&e.tag!==0&&tl(),s=e.pendingLanes,s&1?e===gv?zc++:(zc=0,gv=e):zc=0,ai(),null}function tl(){if(Ts!==null){var e=KT(uf),n=Cr.transition,t=Fe;try{if(Cr.transition=null,Fe=16>e?16:e,Ts===null)var r=!1;else{if(e=Ts,Ts=null,uf=0,_e&6)throw Error(q(331));var o=_e;for(_e|=4,te=e.current;te!==null;){var s=te,i=s.child;if(te.flags&16){var a=s.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(te=c;te!==null;){var u=te;switch(u.tag){case 0:case 11:case 15:Fc(8,u,s)}var h=u.child;if(h!==null)h.return=u,te=h;else for(;te!==null;){u=te;var p=u.sibling,f=u.return;if(t2(u),u===c){te=null;break}if(p!==null){p.return=f,te=p;break}te=f}}}var y=s.alternate;if(y!==null){var m=y.child;if(m!==null){y.child=null;do{var x=m.sibling;m.sibling=null,m=x}while(m!==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:Fc(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,te=S;break e}te=s.return}}var v=e.current;for(te=v;te!==null;){i=te;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,te=b;else e:for(i=v;te!==null;){if(a=te,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:tg(9,a)}}catch(k){mt(a,a.return,k)}if(a===i){te=null;break e}var E=a.sibling;if(E!==null){E.return=a.return,te=E;break e}te=a.return}}if(_e=o,ai(),fo&&typeof fo.onPostCommitFiberRoot=="function")try{fo.onPostCommitFiberRoot(Vf,e)}catch{}r=!0}return r}finally{Fe=t,Cr.transition=n}}return!1}function bC(e,n,t){n=fl(t,n),n=KM(e,n,1),e=zs(e,n,1),n=yn(),e!==null&&(Fu(e,1,n),zn(e,n))}function mt(e,n,t){if(e.tag===3)bC(e,e,t);else for(;n!==null;){if(n.tag===3){bC(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Bs===null||!Bs.has(r))){e=fl(t,e),e=WM(n,e,1),n=zs(n,e,1),e=yn(),n!==null&&(Fu(n,1,e),zn(n,e));break}}n=n.return}}function mW(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=yn(),e.pingedLanes|=e.suspendedLanes&t,Ot===e&&(Kt&t)===t&&(Et===4||Et===3&&(Kt&130023424)===Kt&&500>wt()-Rw?Di(e,0):Dw|=t),zn(e,n)}function d2(e,n){n===0&&(e.mode&1?(n=Md,Md<<=1,!(Md&130023424)&&(Md=4194304)):n=1);var t=yn();e=es(e,n),e!==null&&(Fu(e,n,t),zn(e,t))}function yW(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),d2(e,t)}function SW(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),d2(e,t)}var h2;h2=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||Fn.current)Dn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return Dn=!1,sW(e,n,t);Dn=!!(e.flags&131072)}else Dn=!1,nt&&n.flags&1048576&&mM(n,ef,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Th(e,n),e=n.pendingProps;var o=ul(n,cn.current);el(n,t),o=_w(null,n,r,e,o,t);var s=Tw();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,Nn(r)?(s=!0,Qp(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,Pw(n),o.updater=eg,n.stateNode=o,o._reactInternals=n,rv(n,r,e,t),n=iv(null,n,r,!0,s,t)):(n.tag=0,nt&&s&&mw(n),fn(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(Th(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=xW(r),e=Or(r,e),o){case 0:n=sv(null,n,r,e,t);break e;case 1:n=hC(null,n,r,e,t);break e;case 11:n=uC(null,n,r,e,t);break e;case 14:n=dC(null,n,r,Or(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:Or(r,o),sv(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Or(r,o),hC(e,n,r,o,t);case 3:e:{if(XM(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,bM(e,n),rf(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=fl(Error(q(423)),n),n=pC(e,n,r,t,o);break e}else if(r!==o){o=fl(Error(q(424)),n),n=pC(e,n,r,t,o);break e}else for(Jn=Ns(n.stateNode.containerInfo.firstChild),rr=n,nt=!0,Fr=null,t=xM(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(dl(),r===o){n=ts(e,n,t);break e}fn(e,n,r,t)}n=n.child}return n;case 5:return PM(n),e===null&&ev(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,XS(r,o)?i=null:s!==null&&XS(r,s)&&(n.flags|=32),YM(e,n),fn(e,n,i,t),n.child;case 6:return e===null&&ev(n),null;case 13:return qM(e,n,t);case 4:return Cw(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=hl(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:Or(r,o),uC(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,Ve(tf,r._currentValue),r._currentValue=i,s!==null)if(Wr(s.value,i)){if(s.children===o.children&&!Fn.current){n=ts(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=Go(-1,t&-t),l.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var u=c.pending;u===null?l.next=l:(l.next=u.next,u.next=l),c.pending=l}}s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),tv(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),tv(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,el(n,t),o=Er(o),r=r(o),n.flags|=1,fn(e,n,r,t),n.child;case 14:return r=n.type,o=Or(r,n.pendingProps),o=Or(r.type,o),dC(e,n,r,o,t);case 15:return GM(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Or(r,o),Th(e,n),n.tag=1,Nn(r)?(e=!0,Qp(n)):e=!1,el(n,t),HM(n,r,o),rv(n,r,o,t),iv(null,n,r,!0,e,t);case 19:return ZM(e,n,t);case 22:return VM(e,n,t)}throw Error(q(156,n.tag))};function p2(e,n){return zT(e,n)}function vW(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 br(e,n,t,r){return new vW(e,n,t,r)}function Nw(e){return e=e.prototype,!(!e||!e.isReactComponent)}function xW(e){if(typeof e=="function")return Nw(e)?1:0;if(e!=null){if(e=e.$$typeof,e===ow)return 11;if(e===sw)return 14}return 2}function Hs(e,n){var t=e.alternate;return t===null?(t=br(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 jh(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")Nw(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case ja:return Ri(t.children,o,s,n);case rw:i=8,o|=8;break;case kS:return e=br(12,t,n,o|2),e.elementType=kS,e.lanes=s,e;case _S:return e=br(13,t,n,o),e.elementType=_S,e.lanes=s,e;case TS:return e=br(19,t,n,o),e.elementType=TS,e.lanes=s,e;case PT:return rg(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case wT:i=10;break e;case bT:i=9;break e;case ow:i=11;break e;case sw:i=14;break e;case bs:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=br(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function Ri(e,n,t,r){return e=br(7,e,r,n),e.lanes=t,e}function rg(e,n,t,r){return e=br(22,e,r,n),e.elementType=PT,e.lanes=t,e.stateNode={isHidden:!1},e}function Zm(e,n,t){return e=br(6,e,null,n),e.lanes=t,e}function Qm(e,n,t){return n=br(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function wW(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=jm(0),this.expirationTimes=jm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=jm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function zw(e,n,t,r,o,s,i,a,l){return e=new wW(e,n,t,a,l),n===1?(n=1,s===!0&&(n|=8)):n=0,s=br(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},Pw(s),e}function bW(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Aa,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function f2(e){if(!e)return Vs;e=e._reactInternals;e:{if(ia(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(Nn(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(Nn(t))return fM(e,t,n)}return n}function g2(e,n,t,r,o,s,i,a,l){return e=zw(t,r,!0,e,o,s,i,a,l),e.context=f2(null),t=e.current,r=yn(),o=Us(t),s=Go(r,o),s.callback=n??null,zs(t,s,o),e.current.lanes=o,Fu(e,o,r),zn(e,r),e}function og(e,n,t,r){var o=n.current,s=yn(),i=Us(o);return t=f2(t),n.context===null?n.context=t:n.pendingContext=t,n=Go(s,i),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=zs(o,n,i),e!==null&&(Ur(e,o,i,s),Eh(e,o,i)),i}function hf(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 PC(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function Bw(e,n){PC(e,n),(e=e.alternate)&&PC(e,n)}function PW(){return null}var m2=typeof reportError=="function"?reportError:function(e){console.error(e)};function Uw(e){this._internalRoot=e}sg.prototype.render=Uw.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));og(e,n,null,null)};sg.prototype.unmount=Uw.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Gi(function(){og(null,e,null,null)}),n[Jo]=null}};function sg(e){this._internalRoot=e}sg.prototype.unstable_scheduleHydration=function(e){if(e){var n=VT();e={blockedOn:null,target:e,priority:n};for(var t=0;t<Is.length&&n!==0&&n<Is[t].priority;t++);Is.splice(t,0,e),t===0&&XT(e)}};function Hw(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function ig(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function CC(){}function CW(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=hf(i);s.call(c)}}var i=g2(n,r,e,0,null,!1,!1,"",CC);return e._reactRootContainer=i,e[Jo]=i.current,iu(e.nodeType===8?e.parentNode:e),Gi(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=hf(l);a.call(c)}}var l=zw(e,0,!1,null,null,!1,!1,"",CC);return e._reactRootContainer=l,e[Jo]=l.current,iu(e.nodeType===8?e.parentNode:e),Gi(function(){og(n,l,t,r)}),l}function ag(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=hf(i);a.call(l)}}og(n,i,e,o)}else i=CW(t,n,e,o,r);return hf(i)}WT=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=bc(n.pendingLanes);t!==0&&(lw(n,t|1),zn(n,wt()),!(_e&6)&&(gl=wt()+500,ai()))}break;case 13:Gi(function(){var r=es(e,1);if(r!==null){var o=yn();Ur(r,e,1,o)}}),Bw(e,1)}};cw=function(e){if(e.tag===13){var n=es(e,134217728);if(n!==null){var t=yn();Ur(n,e,134217728,t)}Bw(e,134217728)}};GT=function(e){if(e.tag===13){var n=Us(e),t=es(e,n);if(t!==null){var r=yn();Ur(t,e,n,r)}Bw(e,n)}};VT=function(){return Fe};YT=function(e,n){var t=Fe;try{return Fe=e,n()}finally{Fe=t}};NS=function(e,n,t){switch(n){case"input":if(jS(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=Zf(r);if(!o)throw Error(q(90));IT(r),jS(r,o)}}}break;case"textarea":kT(e,t);break;case"select":n=t.value,n!=null&&qa(e,!!t.multiple,n,!1)}};DT=Lw;RT=Gi;var IW={usingClientEntryPoint:!1,Events:[zu,La,Zf,jT,OT,Lw]},ac={findFiberByHostInstance:Ii,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},EW={bundleType:ac.bundleType,version:ac.version,rendererPackageName:ac.rendererPackageName,rendererConfig:ac.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ls.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=FT(e),e===null?null:e.stateNode},findFiberByHostInstance:ac.findFiberByHostInstance||PW,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 Bd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Bd.isDisabled&&Bd.supportsFiber)try{Vf=Bd.inject(EW),fo=Bd}catch{}}ur.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=IW;ur.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Hw(n))throw Error(q(200));return bW(e,n,null,t)};ur.createRoot=function(e,n){if(!Hw(e))throw Error(q(299));var t=!1,r="",o=m2;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=zw(e,1,!1,null,null,t,!1,r,o),e[Jo]=n.current,iu(e.nodeType===8?e.parentNode:e),new Uw(n)};ur.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=FT(n),e=e===null?null:e.stateNode,e};ur.flushSync=function(e){return Gi(e)};ur.hydrate=function(e,n,t){if(!ig(n))throw Error(q(200));return ag(null,e,n,!0,t)};ur.hydrateRoot=function(e,n,t){if(!Hw(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=m2;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=g2(n,null,e,1,t??null,o,!1,s,i),e[Jo]=n.current,iu(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 sg(n)};ur.render=function(e,n,t){if(!ig(n))throw Error(q(200));return ag(null,e,n,!1,t)};ur.unmountComponentAtNode=function(e){if(!ig(e))throw Error(q(40));return e._reactRootContainer?(Gi(function(){ag(null,null,e,!1,function(){e._reactRootContainer=null,e[Jo]=null})}),!0):!1};ur.unstable_batchedUpdates=Lw;ur.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!ig(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return ag(e,n,t,!1,r)};ur.version="18.3.1-next-f1338f8080-20240426";function y2(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(y2)}catch(e){console.error(e)}}y2(),yT.exports=ur;var aa=yT.exports;const kW=ei(aa);var Sv={},S2,IC=aa;S2=Sv.createRoot=IC.createRoot,Sv.hydrateRoot=IC.hydrateRoot;const nl="TLDRAW_TAB_ID_v2",mo=globalThis.window;function _W(){return mo?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(mo.navigator.platform)||mo.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const pf=mo?mo[nl]??Ok(nl)??"TLDRAW_INSTANCE_STATE_V1_"+ot():"<error>";mo&&(mo[nl]=pf,_W()?jx(nl,pf):Dk(nl));mo==null||mo.addEventListener("beforeunload",()=>{jx(nl,pf)});const v2={Initial:0},lg=Math.max(...Object.values(v2));function TW(e){e.version<v2.Initial,e.version=lg}const x2=ve({version:de,currentPageId:Yc,isFocusMode:Se,exportBackground:Se,isDebugMode:Se,isToolLocked:Se,isGridMode:Se,pageStates:zt(ve({pageId:Yc,camera:ve({x:de,y:de,z:de}),selectedShapeIds:zt(yr),focusedGroupId:yr.nullable()}))});function MW(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!==lg&&(e=rt(e),TW(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(mn);if(!t)return null;const r=[...n.get()];return{version:lg,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(Nr.createId(o)),i=e.get(co.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=MW(n);if(!t)return;const r=e.schema.types.instance.create({id:mn,...c_(e.get(mn)),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([co.create({id:co.createId(s.pageId),x:s.camera.x,y:s.camera.y,z:s.camera.z}),Nr.create({id:Nr.createId(s.pageId),pageId:s.pageId,selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId})]);e.put([r]),e.ensureStoreIsUsable()})}function AW(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!==mn)[0];if(!t)return null;const r={version:lg,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:_c(o.value,(s,{typeName:i})=>e.scopedTypes.document.has(i))}}else t=n;const r=c_(e.get(mn));e.atomic(()=>{t.document&&e.loadStoreSnapshot(t.document),r&&e.update(mn,o=>({...o,...r})),t.session&&b2(e,t.session)})}const jW=new qo;function OW(e){const t=jW.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 d.jsx("svg",{...t,className:ce("tl-svg-container",n),children:e})}function Kw(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,u=i*s-a*o,h=l*s-c*o,p=a*l-i*c;if(u===0||h===0||p===0)return null;if(p!==0){const f=u/p,y=h/p;if(0<=f&&f<=1&&0<=y&&y<=1)return w.AddXY(e,f*l,f*c)}return null}function Uu(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),u=(-s-l)/(2*o);if((c<0||c>1)&&(u<0||u>1))return null;const h=[];return 0<=c&&c<=1&&h.push(w.Lrp(e,n,c)),0<=u&&u<=1&&h.push(w.Lrp(e,n,u)),h.length===0?null:h}function DW(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=Kw(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function Ww(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=Kw(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function RW(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 vv(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=Uu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function EC(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=Uu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function Ud(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function Gw(e,n,t,r){return Ud(e,t,r)!==Ud(n,t,r)&&Ud(e,n,t)!==Ud(e,n,r)}function kC(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],nr(r,n)){const c=Jm(r);t.has(c)||t.set(c,r)}for(let a=0,l=n.length;a<l;a++)if(r=n[a],nr(r,e)){const c=Jm(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,u=n.length;c<u;c++){s=n[c],i=n[(c+1)%n.length];const h=Kw(r,o,s,i);if(h!==null){const p=Jm(h);t.has(p)||t.set(p,h)}}}return t.size===0?null:LW([...t.values()])}function Jm(e){return`${e.x},${e.y}`}function LW(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],Gw(t,r,o,s))return!0}return!1}function $W(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],Gw(t,r,o,s))return!0}return!1}class Ho extends oi{constructor(t){super({...t,isClosed:!1,isFilled:!1});g(this,"start");g(this,"end");g(this,"d");g(this,"u");g(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 Gw(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 oi{constructor(t){super({isClosed:!1,isFilled:!1,...t});g(this,"points");g(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 Ho({start:s,end:i}))}this.isClosed&&this._segments.push(new Ho({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 ns 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)]});g(this,"x");g(this,"y");g(this,"w");g(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 Hr{constructor(n){g(this,"canSnap",()=>!0);g(this,"canScroll",()=>!1);g(this,"canEdit",()=>!1);g(this,"canResize",()=>!0);g(this,"canEditInReadOnly",()=>!1);g(this,"canCrop",()=>!1);g(this,"canBeLaidOut",()=>!0);g(this,"hideResizeHandles",()=>!1);g(this,"hideRotateHandle",()=>!1);g(this,"hideSelectionBoundsBg",()=>!1);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"isAspectRatioLocked",()=>!1);g(this,"onBeforeCreate");g(this,"onBeforeUpdate");g(this,"onDragShapesOver");g(this,"onDragShapesOut");g(this,"onDropShapesOver");g(this,"onResizeStart");g(this,"onResize");g(this,"onResizeEnd");g(this,"onTranslateStart");g(this,"onTranslate");g(this,"onTranslateEnd");g(this,"onHandleDrag");g(this,"onRotateStart");g(this,"onRotate");g(this,"onRotateEnd");g(this,"onBindingChange");g(this,"onChildrenChange");g(this,"onDoubleClickHandle");g(this,"onDoubleClickEdge");g(this,"onDoubleClick");g(this,"onClick");g(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{}}}g(Hr,"props"),g(Hr,"migrations"),g(Hr,"type");function FW(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,u=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)),u=Math.floor(e/c/(2*h)),u-=u%o,u<3&&l==="dashed"?e/n<5?(c=e,u=1,p=0):(c=e*.333,p=e*.333):(u=Math.max(u,3),c=e/u/(2*h),r?(f=c/2,p=(e-u*c)/u):p=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}function _C({bounds:e,className:n}){const t=B(),r=G("zoom level",()=>t.getZoomLevel(),[t]);return d.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=FW(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return d.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class Oh extends Hr{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"canBind",()=>!1);g(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 ns({width:1,height:1,isFilled:!1}):new Kr({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 d.jsx(Ys,{id:t.id,children:d.jsx(_C,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return d.jsx(_C,{className:"",bounds:r})}}g(Oh,"type","group"),g(Oh,"props",w_),g(Oh,"migrations",b_);const E2=[Oh],NW=new Set(E2.map(e=>e.type));function k2(e){const n=[...E2],t=new Set;for(const r of e){if(NW.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 zW={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 TC(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 BW{constructor(n){g(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(!TC(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!TC(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 xv extends BW{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 UW(e,n,t){return So(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function HW(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 Hd(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})=>KW(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>WW(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>GW(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>VW(s,i,o));break}}return o}function KW(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=ll(o,s,e.size);t.push(...Array.from(e.values()).sort(on).map((a,l)=>({...a,index:i[l]})))}}function WW(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=ll(o,s,e.size);t.push(...Array.from(e.values()).sort(on).map((a,l)=>({...a,index:i[l]})))}}function GW(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;ll(n[i].index,(s=n[i+1])==null?void 0:s.index,i-l).forEach((c,u)=>t.push({...n[l+u],index:c})),o={name:"skipping"};break}}}}function VW(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;ll((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 Dh({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:l})=>{const c=_n(a.parentId)?n.getShapePageTransform(a.parentId):oe.Identity(),u=w.RotWith(l,o,e),h=oe.applyToPoint(oe.Inverse(c),u),p=Rs(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 y=(h=c.onRotateStart)==null?void 0:h.call(c,a);y&&i.push(y)}const u=(p=c.onRotate)==null?void 0:p.call(c,a,l);if(u&&i.push(u),r==="end"||r==="one-off"){const y=(f=c.onRotateEnd)==null?void 0:f.call(c,a,l);y&&i.push(y)}}),i.length>0&&n.updateShapes(i)}const YW=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,u=i.get(l);u?u.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return V("arrowBindingsIndex",(s,i)=>{if(ji(s))return o();const a=s,l=t.getDiffSince(i);if(l===er)return o();let c;function u(f){c??(c=new Map(a));const y=c.get(f.fromId),m=y==null?void 0:y.filter(v=>v.id!==f.id);m!=null&&m.length?c.set(f.fromId,m):c.delete(f.fromId);const x=c.get(f.toId),S=x==null?void 0:x.filter(v=>v.id!==f.id);S!=null&&S.length?c.set(f.toId,S):c.delete(f.toId)}function h(f){c??(c=new Map(a));let y=c.get(f);return y?y===a.get(f)&&(y=y.slice(0),c.set(f,y)):(y=[],c.set(f,y)),y}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const y of gt(f.added))p(y);for(const[y,m]of gt(f.updated))u(y),p(m);for(const y of gt(f.removed))u(y)}return c??a})};function XW(e,n,t){const r=e.getShapeMaskedPageBounds(n);return r===void 0?!0:!t.includes(r)}const qW=e=>{function n(t){const r=t.getCurrentPageShapeIds(),o=t.getViewportPageBounds(),s=new Set;return r.forEach(i=>{XW(t,i,o)&&s.add(i)}),s}return V("getCulledShapes",t=>{if(ji(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})},ZW=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(ji(o))return r();const i=t.getDiffSince(s);if(i===er)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 u;for(let h=0,p=i.length;h<p;h++){u=i[h];for(const f of Object.values(u.added))Ma(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,y]of Object.values(u.updated))if(Ma(y)&&Ma(f)){if(f.parentId!==y.parentId)l(f.parentId),l(y.parentId),a[f.parentId].splice(a[f.parentId].indexOf(y.id),1),a[y.parentId].push(y.id),c.add(a[y.parentId]);else if(f.index!==y.index){l(y.parentId);const m=a[y.parentId].indexOf(y.id);a[y.parentId][m]=y.id,c.add(a[y.parentId])}}for(const f of Object.values(u.removed))Ma(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})},ey=(e,n,t)=>{for(;!En(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},QW=(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=>ey(e,s,e.get(i))))}return V("_shapeIdsInCurrentPage",(s,i)=>{if(ji(s))return o();const a=n();if(a!==r)return o();const l=e.history.getDiffSince(i);if(l===er)return o();const c=new Sh(s);for(const h of l){for(const p of Object.values(h.added))Ma(p)&&ey(e,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))Ma(f)&&(ey(e,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))_n(p)&&c.remove(p)}const u=c.get();return u?vc(u.value,u.diff):s})},T2=P.createContext(null);function JW({context:e,editor:n,children:t}){return d.jsx(Gf.Provider,{value:n,children:d.jsx(T2.Provider,{value:e,children:t})})}function M2(){const e=P.useContext(T2);return e?{isDarkMode:e.isDarkMode}:null}async function eG(e,n,t={}){var k,C;const r=typeof n[0]=="string"?n:n.map(I=>I.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=as({isDarkMode:l}),u=e.getShapeAndDescendantIds(r),h=e.getUnorderedRenderingShapes(!1).filter(({id:I})=>u.has(I));let p=null;if(t.bounds)p=t.bounds;else for(const{id:I}of h){const T=e.getShapeMaskedPageBounds(I);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 y=p.width*o,m=p.height*o;try{(C=(k=document.body).focus)==null||C.call(k)}catch{}const x=[],S=new Map,v={isDarkMode:l,addExportDef:I=>{if(S.has(I.key))return;const T=(async()=>{const O=await I.getElement();O&&x.push(d.jsx(P.Fragment,{children:O},x.length))})();S.set(I.key,T)}},b=(await Promise.all(h.map(async({id:I,opacity:T,index:O,backgroundIndex:_})=>{var z,U;if(I===f)return[];const M=e.getShape(I);if(e.isShapeOfType(M,"group"))return[];const L=e.getShapeUtil(M);let j=await((z=L.toSvg)==null?void 0:z.call(L,M,v)),R=await((U=L.toBackgroundSvg)==null?void 0:U.call(L,M,v));if(!j&&!R){const X=e.getShapePageBounds(M);j=d.jsx("rect",{width:X.w,height:X.h,fill:c.solid,stroke:c.grey.pattern,strokeWidth:1})}let F=e.getShapePageTransform(M).toCssString();"scale"in M.props&&M.props.scale!==1&&(F=`${F} scale(${M.props.scale}, ${M.props.scale})`),j&&(j=d.jsx("g",{transform:F,opacity:T,children:j},M.id)),R&&(R=d.jsx("g",{transform:F,opacity:T,children:R},`bg_${M.id}`));const W=e.getShapeMask(M.id);if(W){const X=`mask_${M.id.replace(":","_")}`;x.push(d.jsx("clipPath",{id:X,children:d.jsx("path",{d:`M${W.map(({x:J,y:le})=>`${J},${le}`).join("L")}Z`})},x.length)),j&&(j=d.jsx("g",{clipPath:`url(#${X})`,children:j},M.id)),R&&(R=d.jsx("g",{clipPath:`url(#${X})`,children:R},`bg_${M.id}`))}const K=[];return j&&K.push({zIndex:O,element:j}),R&&K.push({zIndex:_,element:R}),K}))).flat();return await Promise.all(S.values()),{jsx:d.jsx(JW,{editor:e,context:v,children:d.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:y,height:m,viewBox:`${p.minX} ${p.minY} ${p.width} ${p.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?f?c.solid:c.background:"transparent"},children:[d.jsx("defs",{children:x}),b.sort((I,T)=>I.zIndex-T.zIndex).map(({element:I})=>I)]})}),width:y,height:m}}const tG=40;class nG{constructor(n){g(this,"_clickId","");g(this,"_clickTimeout");g(this,"_clickScreenPoint");g(this,"_previousScreenPoint");g(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)});g(this,"_clickState","idle");g(this,"lastPointerInfo",{});g(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)>tG**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});g(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});this.editor=n}get clickState(){return this._clickState}}class rG{constructor(n){g(this,"_isEdgeScrolling",!1);g(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?At.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,u=n+l,h=o?0:a,p=s?t:t-a;return c<h?Math.min(1,(h-c)/a):u>p?-Math.min(1,(u-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(),u=this.getEdgeProximityFactors(t,o.w,s,c,a),h=this.getEdgeProximityFactors(r,o.h,s,i,l);return{x:u,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:u,y:h,z:p}=t.getCamera();t.setCamera(new w(u+l,h+c,p))}}class oG{constructor(n){g(this,"isSafari");g(this,"isIos");g(this,"isChromeForIos");g(this,"isFirefox");g(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 sG{constructor(n,t){g(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 aG}class iG{constructor(){g(this,"length",0);g(this,"head",null);g(this,"tail",this)}push(n){return new Vw(n,this)}toArray(){return Wo}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const aG=new iG;class Vw{constructor(n,t){g(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Vw(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 lG{constructor(n){g(this,"store");g(this,"dispose");g(this,"state","recording");g(this,"pendingDiff",new uG);g(this,"stacks",Mt("HistoryManager.stacks",{undos:lc(),redos:lc()},{isEqual:(n,t)=>n.undos===t.undos&&n.redos===t.redos}));g(this,"annotateError");g(this,"onBatchComplete",()=>{});g(this,"_isInBatch",!1);g(this,"batch",(n,t)=>{const r=this.state;r!=="paused"&&(t!=null&&t.history)&&(this.state=cG[t.history]);try{if(this._isInBatch)return n(),this;this._isInBatch=!0;try{js(()=>{n(),this.onBatchComplete()})}catch(o){throw this.annotateError(o),o}finally{this._isInBatch=!1}return this}finally{this.state=r}});g(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=Fk(a),c=mS(a);n&&!l&&(i=i.push({type:"diff",diff:a}));let u=!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){u=!0;break}}if(!u)e:for(;s.head;){const h=s.head;switch(s=s.tail,n&&(i=i.push(h)),h.type){case"diff":Tc(c,[mS(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});g(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));g(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=Pp();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")Tc(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});g(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));g(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));g(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=Pp();return Tc(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:t.push({type:"diff",diff:o}),redos:i})),this});g(this,"mark",(n=ot())=>(js(()=>{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??bp,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 cG={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class uG{constructor(){g(this,"diff",Pp());g(this,"isEmptyAtom",Mt("PendingDiff.isEmpty",!0))}clear(){const n=this.diff;return this.diff=Pp(),this.isEmptyAtom.set(!0),n}isEmpty(){return this.isEmptyAtom.get()}apply(n){Tc(this.diff,[n]),this.isEmptyAtom.set(Fk(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class dG{constructor(n){g(this,"scribbleItems",new Map);g(this,"state","paused");g(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});g(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});g(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});g(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 hG=Object.defineProperty,pG=Object.getOwnPropertyDescriptor,cg=(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 ue=e=>Math.round(e*10**8)/10**8;function Ro(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)&&Dr(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=Ro(e,l,t,r,Dr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function fG(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 Hu{constructor(n){g(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&&Jl(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:Dr(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&&Jl(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:Dr(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,S;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,u=[],h=[],p=new w(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const f=new w(n==="x"?0:((x=u[0])==null?void 0:x.nudge)??0,n==="y"?0:((S=h[0])==null?void 0:S.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(v=>{v.x+=f.x,v.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const y=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...m,...y]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var I,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 u=r;l<0&&(u=m9(u)),c<0&&(u=g9(u)),s&&(a.center=n.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=MC(u,a),y=this.getSnappablePoints(),m=[],x=[],S=new w(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:x,otherNodeSnapPoints:y,selectionSnapPoints:f});const v=new w(h?0:((I=m[0])==null?void 0:I.nudge)??0,p?0:((T=x[0])==null?void 0:T.nudge)??0);if(o&&y9(u)&&v.len()!==0){const O=m.length&&x.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":m.length?"x":"y",_=n.aspectRatio;O==="x"?(x.length=0,v.y=v.x/_,(u==="bottom_left"||u==="top_right")&&(v.y=-v.y)):(m.length=0,v.x=v.y*_,(u==="bottom_left"||u==="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 k=MC("any",E);m.length=0,x.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:x,otherNodeSnapPoints:y,selectionSnapPoints:k});const C=this.getPointSnapLines({nearestSnapsX:m,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),u=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(u)<=ue(r.y)&&(ue(u)<ue(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!Jl(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 S={type:"gap_center",gap:a,nudge:c},v=r.find(({type:E})=>E==="gap_center"),b=v&&Dr(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&b?r[r.indexOf(v)]=S:(!v||!b)&&r.push(S)}const 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 y=a.endNode.pageBounds.maxX+a.length,m=n.minX,x=y-m;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(!Jl(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 S={type:"gap_center",gap:a,nudge:c},v=o.find(({type:E})=>E==="gap_center"),b=v&&Jl(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&b?o[o.indexOf(v)]=S:(!v||!b)&&o.push(S);continue}const 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 y=a.endNode.pageBounds.maxY+a.length,m=n.minY,x=y-m;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:Tx(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:u,startNode:h,endNode:p,length:f,endEdge:y}}=l;switch(l.type){case"gap_center":{const m=(f-n.width)/2,x=Dr(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:[...Ro(s,h.id,m,"backward",x),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:y},...Ro(s,p.id,m,"forward",x)]});break}case"gap_duplicate":{const m=Dr(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(x=>x.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:y},...Ro(s,p.id,f,"forward",m)]:[...Ro(s,h.id,f,"backward",m),{startEdge:u,endEdge:y},{startEdge:y.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:u,startNode:h,endNode:p,length:f,endEdge:y}}=l;switch(l.type){case"gap_center":{const m=(f-n.height)/2,x=Dr(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:[...Ro(o,h.id,m,"backward",x),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:y},...Ro(o,l.gap.endNode.id,m,"forward",x)]});break}case"gap_duplicate":{const m=Dr(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(x=>x.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:y},...Ro(o,p.id,f,"forward",m)]:[...Ro(o,h.id,f,"backward",m),{startEdge:u,endEdge:y},{startEdge:y.map(x=>x.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return fG(a),a}}cg([V],Hu.prototype,"getSnapPointsCache");cg([V],Hu.prototype,"getSnappablePoints");cg([V],Hu.prototype,"getSnappableGapNodes");cg([V],Hu.prototype,"getVisibleGaps");function MC(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 gG=Object.defineProperty,mG=Object.getOwnPropertyDescriptor,yG=(e,n,t,r)=>{for(var o=mG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&gG(n,t,o),o};const SG=()=>null,vG=()=>[];class A2{constructor(n){g(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??SG,getSelfSnapPoints:r.getSelfSnapPoints??vG}})}*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:u}of this.iterateSnapOutlines(n,t)){const h=Sr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=u.nearestPoint(p),y=h.applyToPoint(f);w.DistMin(r,y,a)&&(a=w.Dist(r,y),l=y)}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}}yG([V],A2.prototype,"getSnapGeometryCache");var xG=Object.defineProperty,wG=Object.getOwnPropertyDescriptor,Yw=(e,n,t,r)=>{for(var o=wG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&xG(n,t,o),o};class ug{constructor(n){g(this,"shapeBounds");g(this,"handles");g(this,"_snapIndicators",Mt("snapLines",void 0));this.editor=n,this.shapeBounds=new Hu(this),this.handles=new A2(this)}getIndicators(){return this._snapIndicators.get()??Wo}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(_n(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())}}Yw([V],ug.prototype,"getSnapThreshold");Yw([V],ug.prototype,"getSnappableShapes");Yw([V],ug.prototype,"getCurrentCommonAncestor");const bG=/\r?\n|\r/g;function AC(e){return e.replace(bG,`
86
+ `).split(`
87
+ `).map(n=>n||" ").join(`
88
+ `)}const PG={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},CG=/\s/;class IG{constructor(n){g(this,"baseElm");g(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,u=null,h=null,p=0,f=0,y=!1;for(const m of n.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const x of m.textContent??""){a.setStart(l,c),a.setEnd(l,c+x.length);const S=a.getClientRects(),v=S[S.length-1],b=v.top+i,E=v.left+s,k=v.right+s,C=E<f,I=CG.test(x);if(I!==h||b!==p||!u){if(u){if(t&&b!==p){y=!0;break}r.push(u)}u={box:{x:E,y:b,w:v.width,h:v.height},text:x},f=E}else C&&(u.box.x=E),u.box.w=C?u.box.w+v.width:k-u.box.x,u.text+=x;x===`
89
+ `&&(f=0),h=I,p=b,c+=x.length}return u&&r.push(u),{spans:r,didTruncate:y}}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",PG[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 u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}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-u),y:p.box.y,w:u,h:p.box.h}}),h}return r.remove(),a}}const jC=(typeof process<"u",Lk);class EG{constructor(n){g(this,"cancelRaf");g(this,"isPaused",!0);g(this,"now",0);g(this,"start",()=>{var n;this.isPaused=!1,(n=this.cancelRaf)==null||n.call(this),this.cancelRaf=jC(this.tick),this.now=Date.now()});g(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=jC(this.tick)});g(this,"dispose",()=>{var n;this.isPaused=!0,(n=this.cancelRaf)==null||n.call(this)});g(this,"prevPoint",new w);g(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 kG=Object.defineProperty,_G=Object.getOwnPropertyDescriptor,Tr=(e,n,t,r)=>{for(var o=_G(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&kG(n,t,o),o};class hr{constructor(n,t){g(this,"systemColorScheme",Mt("systemColorScheme","light"));g(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??jo.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??jo.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??jo.name}getLocale(){return this.user.userPreferences.get().locale??jo.locale}getColor(){return this.user.userPreferences.get().color??jo.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??jo.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??jo.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??jo.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??jo.isPasteAtCursorMode}}Tr([V],hr.prototype,"getUserPreferences");Tr([V],hr.prototype,"getIsDarkMode");Tr([V],hr.prototype,"getEdgeScrollSpeed");Tr([V],hr.prototype,"getAnimationSpeed");Tr([V],hr.prototype,"getId");Tr([V],hr.prototype,"getName");Tr([V],hr.prototype,"getLocale");Tr([V],hr.prototype,"getColor");Tr([V],hr.prototype,"getIsSnapMode");Tr([V],hr.prototype,"getIsWrapMode");Tr([V],hr.prototype,"getIsDynamicResizeMode");Tr([V],hr.prototype,"getIsPasteAtCursorMode");const TG={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"},MG=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class se{constructor(n,t){g(this,"performanceTracker");g(this,"id");g(this,"type");g(this,"shapeType");g(this,"initial");g(this,"children");g(this,"parent");g(this,"_path");g(this,"_current");g(this,"_isActive");g(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});g(this,"handleEvent",n=>{var o;const t=TG[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)});g(this,"enter",(n,t)=>{var r;if(xt.measurePerformance.get()&&MG.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)}});g(this,"exit",(n,t)=>{var r,o;xt.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)});g(this,"_currentToolIdMask",Mt("curent tool id mask",void 0));g(this,"onWheel");g(this,"onPointerDown");g(this,"onPointerMove");g(this,"onLongPress");g(this,"onPointerUp");g(this,"onDoubleClick");g(this,"onTripleClick");g(this,"onQuadrupleClick");g(this,"onRightClick");g(this,"onMiddleClick");g(this,"onKeyDown");g(this,"onKeyUp");g(this,"onKeyRepeat");g(this,"onCancel");g(this,"onComplete");g(this,"onInterrupt");g(this,"onTick");g(this,"onEnter");g(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 xk}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)}}g(se,"id"),g(se,"initial"),g(se,"children");class Rh extends se{constructor(){super(...arguments);g(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}}})}}g(Rh,"id","root"),g(Rh,"initial",""),g(Rh,"children",()=>[]);var AG=Object.defineProperty,jG=Object.getOwnPropertyDescriptor,ne=(e,n,t,r)=>{for(var o=jG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&AG(n,t,o),o};class Q extends b7{constructor({store:t,user:r,shapeUtils:o,bindingUtils:s,tools:i,getContainer:a,cameraOptions:l,assetOptions:c,initialState:u,autoFocus:h,inferDarkMode:p,options:f}){super();g(this,"options");g(this,"store");g(this,"root");g(this,"disposables",new Set);g(this,"isDisposed",!1);g(this,"_tickManager");g(this,"snaps");g(this,"timers");g(this,"user");g(this,"textMeasure");g(this,"environment");g(this,"scribbles");g(this,"sideEffects");g(this,"edgeScrollManager");g(this,"focusManager");g(this,"getContainer");g(this,"shapeUtils");g(this,"styleProps");g(this,"bindingUtils");g(this,"history");g(this,"_crashingError",null);g(this,"_updateInstanceState",(t,r)=>{this.batch(()=>{this.store.put([{...this.getInstanceState(),...t}])},r)});g(this,"_isChangingStyleTimeout",-1);g(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}}),this));g(this,"_updateCurrentPageState",(t,r)=>{this.batch(()=>{this.store.update(t.id??this.getCurrentPageState().id,o=>({...o,...t}))},{history:"ignore",...r})});g(this,"_cameraOptions",Mt("camera options",Q1));g(this,"_viewportAnimation",null);g(this,"_willSetInitialBounds",!0);g(this,"_isLockedOnFollowingUser",Mt("isLockedOnFollowingUser",!1));g(this,"_cameraState",Mt("camera state","idle"));g(this,"_cameraStateTimeoutRemaining",0);g(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))});g(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});g(this,"_currentPageShapeIds");g(this,"_assetOptions",Mt("asset options",J1));g(this,"_parentIdsToChildIds");g(this,"animatingShapes",new Map);g(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 u=t[l];u&&(o=this.getShape(u.id),o&&(s=Oo(o,u),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)})});g(this,"externalAssetContentHandlers",{file:null,url:null});g(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});g(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});g(this,"_clickManager",new nG(this));g(this,"_prevCursor","default");g(this,"_shiftKeyTimeout",-1);g(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"})});g(this,"_altKeyTimeout",-1);g(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"})});g(this,"_ctrlKeyTimeout",-1);g(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"})});g(this,"_restoreToolId","select");g(this,"_pinchStart",1);g(this,"_didPinch",!1);g(this,"_selectedShapeIdsAtPointerDown",[]);g(this,"_longPressTimeout",-1);g(this,"capturedPointerId",null);g(this,"performanceTracker");g(this,"performanceTrackerTimeout",-1);g(this,"dispatch",t=>(this._pendingEventsForNextTick.push(t),t.type==="pointer"&&t.name==="pointer_move"||t.type==="wheel"||t.type==="pinch"||this._flushEventsForTick(0),this));g(this,"_pendingEventsForNextTick",[]);g(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(mn),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:u=1},delta:{x:h,y:p}}=t,{x:f,y}=w.SubXY(t.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:m,y:x,z:S}=gd(()=>this.getCamera()),{panSpeed:v,zoomSpeed:b}=c;this._setCamera(new w(m+h*v/S-f/S+f/(u*b),x+p*v/S-y/S+y/(u*b),u*b),{immediate:!0});return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:u}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,u.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(u)}));return}}}case"wheel":{if(c.isLocked)return;if(this._updateInputsFromEvent(t),!this.getIsMenuOpen()){const{panSpeed:u,zoomSpeed:h,wheelBehavior:p}=c;if(p!=="none"){this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:f,y,z:m}=gd(()=>this.getCamera()),{x,y:S,z:v=0}=t.delta;let b=p;switch(r.ctrlKey&&(b=p==="pan"?"zoom":"pan"),b){case"zoom":{const{x:E,y:k}=this.inputs.currentScreenPoint;let C=v;p==="zoom"&&(Math.abs(S)>10?C=10*Math.sign(S)/100:C=S/100);const I=m+(C??0)*h*m;this._setCamera(new w(f+(E/I-E)-(E/m-E),y+(k/I-k)-(k/m-k),I),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new w(f+x*u/m,y+S*u/m,m),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(t);const{isPen:u}=t,{isPenMode:h}=a;switch(t.name){case"pointer_down":{if(h&&!u)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===tP&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,!h&&u&&this.updateInstanceState({isPenMode:!0}),t.button===nP?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===Cd&&(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(!u&&h)return;const{x:p,y:f,z:y}=gd(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:m,previousScreenPoint:x}=this.inputs,{panSpeed:S}=c,v=w.Sub(m,x);this.setCamera(new w(p+v.x*S/y,f+v.y*S/y,y),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&w.Dist2(s,i)*this.getZoomLevel()>(a.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/y&&(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&&!u)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 tP:{this.setCursor({type:"grab",rotation:0});break}case Cd: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===nP&&(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(Cd)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(t.type==="pointer"){t.button===Cd?t.name="middle_click":t.button===Vx&&(t.name="right_click");const{isPenMode:u}=this.store.unsafeGetWithoutCapture(mn);if(t.isPen===u){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={...zW,...f},this.store=t,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new lG({store:t,annotateError:_=>{this.annotateError(_,{origin:"history.batch",willCrashApp:!0}),this.crash(_)}}),this.snaps=new ug(this),this.timers=new X4,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...Q1,...l}),this._assetOptions.set({...J1,...c}),this.user=new hr(r??gT(),p??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new IG(this),this._tickManager=new EG(this);class y extends Rh{}g(y,"initial",u??""),this.root=new y(this),this.root.children={};const m=k2(o),x={},S={},v=new Map;for(const _ of m){const M=new _(this);x[_.type]=M;const L=Zk(_.props??{});S[_.type]=L;for(const j of L.keys())if(!v.has(j.id))v.set(j.id,j);else if(v.get(j.id)!==j)throw Error(`Multiple style props with id "${j.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=x,this.styleProps=S;const b=C2(s),E={};for(const _ of b){const M=new _(this);E[_.type]=M}this.bindingUtils=E;for(const _ of[...i]){if(po(this.root.children,_.id))throw Error(`Can't override tool with id "${_.id}"`);this.root.children[_.id]=new _(this,this.root)}this.environment=new oG(this),this.scribbles=new dG(this);const k=(_,M)=>{let L=null;const j=_.selectedShapeIds.filter(W=>!M.has(W));j.length!==_.selectedShapeIds.length&&(L||(L={..._}),L.selectedShapeIds=j);const R=_.erasingShapeIds.filter(W=>!M.has(W));R.length!==_.erasingShapeIds.length&&(L||(L={..._}),L.erasingShapeIds=R),_.hoveredShapeId&&M.has(_.hoveredShapeId)&&(L||(L={..._}),L.hoveredShapeId=null),_.editingShapeId&&M.has(_.editingShapeId)&&(L||(L={..._}),L.editingShapeId=null);const F=_.hintingShapeIds.filter(W=>!M.has(W));return F.length!==_.hintingShapeIds.length&&(L||(L={..._}),L.hintingShapeIds=F),_.focusedGroupId&&M.has(_.focusedGroupId)&&(L||(L={..._}),L.focusedGroupId=null),L};this.sideEffects=this.store.sideEffects;let C=new Map;const I=new Set,T=new Set;let O=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var _,M,L,j;I.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);(M=W.onOperationComplete)==null||M.call(W)}}if(C.size){const R=C;C=new Map;for(const F of R.values())(j=(L=this.getBindingUtil(F.binding)).onAfterDelete)==null||j.call(L,F)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(_,M)=>{var L,j,R,F;for(const W of this.getBindingsInvolvingShape(M))O.add(W.type),W.fromId===M.id&&((j=(L=this.getBindingUtil(W)).onAfterChangeFromShape)==null||j.call(L,{binding:W,shapeBefore:_,shapeAfter:M})),W.toId===M.id&&((F=(R=this.getBindingUtil(W)).onAfterChangeToShape)==null||F.call(R,{binding:W,shapeBefore:_,shapeAfter:M}));if(_.parentId!==M.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(M.id),this.visitDescendants(M.id,W)}if(_.parentId!==M.parentId&&En(M.parentId)){const W=new Set([_.id]);this.visitDescendants(_.id,K=>{W.add(K)});for(const K of this.getPageStates()){if(K.pageId===M.parentId)continue;const z=k(K,W);z&&this.store.put([z])}}_.parentId&&_n(_.parentId)&&T.add(_.parentId),M.parentId!==_.parentId&&_n(M.parentId)&&T.add(M.parentId)},beforeDelete:_=>{var R,F,W,K;if(I.has(_.id))return;_.parentId&&_n(_.parentId)&&T.add(_.parentId),I.add(_.id);const M=[];for(const z of this.getBindingsInvolvingShape(_)){O.add(z.type),M.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:_}))}M.length&&this.deleteBindings(M);const L=new Set([_.id]),j=me(this.getPageStates().map(z=>k(z,L)));j.length&&this.store.put(j)}},binding:{beforeCreate:_=>{var L,j;const M=(j=(L=this.getBindingUtil(_)).onBeforeCreate)==null?void 0:j.call(L,{binding:_});return M||_},afterCreate:_=>{var M,L;O.add(_.type),(L=(M=this.getBindingUtil(_)).onAfterCreate)==null||L.call(M,{binding:_})},beforeChange:(_,M)=>{var j,R;const L=(R=(j=this.getBindingUtil(M)).onBeforeChange)==null?void 0:R.call(j,{bindingBefore:_,bindingAfter:M});return L||M},afterChange:(_,M)=>{var L,j;O.add(M.type),(j=(L=this.getBindingUtil(M)).onAfterChange)==null||j.call(L,{bindingBefore:_,bindingAfter:M})},beforeDelete:_=>{var M,L;(L=(M=this.getBindingUtil(_)).onBeforeDelete)==null||L.call(M,{binding:_})},afterDelete:_=>{var M,L;(L=(M=this.getBindingUtil(_)).onAfterDelete)==null||L.call(M,{binding:_}),O.add(_.type)}},page:{afterCreate:_=>{const M=co.createId(_.id),L=Nr.createId(_.id);this.store.has(M)||this.store.put([co.create({id:M})]),this.store.has(L)||this.store.put([Nr.create({id:L,pageId:_.id})])},afterDelete:(_,M)=>{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}]):M==="user"&&this.store.ensureStoreIsUsable()}const L=co.createId(_.id),j=Nr.createId(_.id);this.store.remove([L,j])}},instance:{afterChange:(_,M,L)=>{var j;if(!this.store.has(M.currentPageId)){const R=this.store.has(_.currentPageId)?_.currentPageId:(j=this.getPages()[0])==null?void 0:j.id;R?this.store.update(M.id,F=>({...F,currentPageId:R})):L==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(_,M)=>{if((_==null?void 0:_.selectedShapeIds)!==(M==null?void 0:M.selectedShapeIds)){const L=M.selectedShapeIds.filter(R=>{var W,K;let F=(W=this.getShape(R))==null?void 0:W.parentId;for(;_n(F);){if(M.selectedShapeIds.includes(F))return!1;F=(K=this.getShape(F))==null?void 0:K.parentId}return!0});let j=null;if(L.length>0){const R=this.findCommonAncestor(me(L.map(F=>this.getShape(F))),F=>this.isShapeOfType(F,"group"));R&&(j=R)}else M!=null&&M.focusedGroupId&&(j=M.focusedGroupId);(L.length!==M.selectedShapeIds.length||j!==M.focusedGroupId)&&this.store.put([{...M,selectedShapeIds:L,focusedGroupId:j??null}])}}}})),this._currentPageShapeIds=QW(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=ZW(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:[]})}),u&&this.root.children[u]===void 0)throw Error(`No state found for initialState "${u}".`);this.root.enter(void 0,"initial"),this.edgeScrollManager=new rG(this),this.focusManager=new sG(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 xk}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=jn(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=jn(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 Mx(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(xS)}updateDocumentSettings(t){return this.history.ignore(()=>{this.store.put([{...this.getDocumentSettings(),...t}])}),this}getInstanceState(){return this.store.get(mn)}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 Nr.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:Tx(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}_unsafe_getCameraId(){return co.createId(this.getCurrentPageId())}getCamera(){const t=this.store.get(this._unsafe_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),u=this.getViewportScreenBounds().clone(),h=u.width/u.height;return u.width=c.width,u.height=u.width/h,u.height<c.height&&(u.height=c.height,u.width=u.height*h),u.center=c.center,u}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}=DC(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}=DC(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],u=Nt(l.zoomSteps),h=this.getViewportScreenBounds();if(l.constraints){const{constraints:p}=l,f=Math.min(p.padding.y,h.w/2),y=Math.min(p.padding.x,h.h/2),m=Z.From(l.constraints.bounds),x=(h.w-y*2)/m.w,S=(h.h-f*2)/m.h,v=this.getBaseZoom(),b=u*v,E=c*v;if(r!=null&&r.reset&&(a=this.getInitialZoom()),a<E||a>b){const{x:j,y:R,z:F}=o,W=-j+h.w/F/2,K=-R+h.h/F/2;a=_t(a,E,b);const z=-j+h.w/a/2,U=-R+h.h/a/2;s=j+z-W,i=R+U-K}const k=y/a-m.x,C=f/a-m.y,I=(h.w-y*2)/a-m.w,T=(h.h-f*2)/a-m.h,O=k+I*p.origin.x,_=C+T*p.origin.y,M=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(M){case"fixed":{s=O;break}case"contain":{a<x?s=O:s=_t(s,k+I,k);break}case"inside":{a<x?s=_t(s,k,(h.w-y)/a-m.w):s=_t(s,k+I,k);break}case"outside":{s=_t(s,y/a-m.w,(h.w-y)/a);break}case"free":break;default:throw an(M)}switch(L){case"fixed":{i=_;break}case"contain":{a<S?i=_:i=_t(i,C+T,C);break}case"inside":{a<S?i=_t(i,C,(h.h-f)/a-m.h):i=_t(i,C+T,C);break}case"outside":{i=_t(i,f/a-m.h,(h.h-f)/a);break}case"free":break;default:throw an(L)}}}else if(a>u||a<c){const{x:p,y:f,z:y}=o;a=_t(a,c,u),s=p+(-p+h.w/a/2)-(-p+h.w/y/2),i=f+(-f+h.h/a/2)-(-f+h.h/y/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:u}=this.inputs,{screenBounds:h}=this.store.unsafeGetWithoutCapture(mn);if(c.x/a-s!==u.x||c.y/a-i!==u.y){const p={type:"pointer",target:"canvas",name:"pointer_move",point:w.AddXY(c,h.x,h.y),pointerId:eP.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:u,y:h}=t;let p=1;if(s){const f=this.getInitialZoom();c!==f&&(p=f)}return this.setCamera(new w(a+(u/p-u)-(u/c-u),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 u=1;u<a.length;u++){const h=a[u-1]*l,p=a[u]*l;if(!(p-i<=(p-h)/2)){c=p;break}}this.setCamera(new 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 u=o.length-1;u>0;u--){const h=o[u-1]*s,p=o[u]*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(J6,s.width*.28),a=this.getBaseZoom(),l=o.zoomSteps[0],c=Nt(o.zoomSteps);let u=_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&&(u=Math.min(r.targetZoom,u)),this.setCamera(new w(-t.x+(s.width-t.w*u)/2/u,-t.y+(s.height-t.h*u)/2/u,u),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),u=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(-u,-h,this.getViewportScreenBounds().width/(p-u)),{force:!0})}_animateToViewport(t,r={animation:bm}){const{animation:o,...s}=r;if(!o)return;const{duration:i=0,easing:a=At.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",u),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=h=>{const{x:p,y:f,z:y}=this.getCamera(),m=w.Mul(i,l*h/y);l*=1-s,l<a?c():this._setCamera(new w(p+m.x,f+m.y,y))};return this.on("tick",u),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,!Ds(document.body.scrollWidth,t.maxX,1),!Ds(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(mn),{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(mn),{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]):Wo}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 js(()=>{this.updateInstanceState({followingUserId:t},{history:"ignore"});const i=oa("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 u=this.user.getAnimationSpeed();if(u===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),y=Math.abs(h.minY-p.minY)+Math.abs(h.maxY-p.maxY);if(f<this.options.followChaseViewportSnap&&y<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const m=_t(u*.5,.1,.8),x=new Z(fd(p.minX,h.minX,m),fd(p.minY,h.minY,m),fd(p.width,h.width,m),fd(p.height,h.height,m)),S=new w(-x.x,-x.y,this.getViewportScreenBounds().width/x.width);this.stopCameraAnimation(),this._setCamera(S)};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,u,h)=>{const p=this.getShape(c);if(!p)return;u*=p.opacity;let f=!1;const y=this.getShapeUtil(p);t&&(f=!h&&i.includes(c),f&&(u*=.32)),r.push({id:c,shape:p,util:y,index:o,backgroundIndex:s,opacity:u}),o+=1,s+=1;const m=this.getSortedChildIdsForParent(c);if(!m.length)return;let x=null;y.providesBackgroundForChildren(p)&&(x=s,s=o,o+=this.options.maxShapesPerPage);for(const S of m)a(S,u,h||f);x!==null&&(s=x)},l=t?[this.getCurrentPage()]:this.getPages();for(const c of l)for(const u of this.getSortedChildIdsForParent(c.id))a(u,1,!1);return r}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(H4)}_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=HW(t.name??"Page 1",r.map(a=>a.name));let s=t.index;(!s||r.some(a=>a.index===s))&&(s=No(r[r.length-1].index));const i=Zo.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=Zo.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 u;const l=this.getPages(),c=Gc(s.index,(u=l[l.indexOf(s)+1])==null?void 0:u.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,u=this.getInstanceState().devicePixelRatio;return await this._assetOptions.get().onResolveAsset(o,{screenScale:s||1,steppedScreenScale:l,dpr:u,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(En(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||En(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(En(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=kC(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=kC(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(En(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(En(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(u=>u.id),s=me(o.map(u=>this.getShape(u)));if(s.length===1){const u=s[0].parentId;return En(u)?void 0:r?(c=this.findShapeAncestor(s[0],r))==null?void 0:c.id:u}const[i,...a]=s;let l=this.getShapeParent(i);for(;l;){if(r&&!r(l)){l=this.getShapeParent(l);continue}if(a.every(u=>this.hasAncestor(u,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 qW(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:u=!1,hitFrameInside:h=!1}=r;let p=1/0,f=null,y=1/0,m=null;const x=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(S=>{if(S.isLocked&&!l||this.isShapeOfType(S,"group"))return!1;const v=this.getShapeMask(S);return v&&!nr(t,v)?!1:i?i(S):!0});for(let S=x.length-1;S>=0;S--){const v=x[S],b=this.getShapeGeometry(v),E=b instanceof Kr,k=this.getPointInShapeSpace(v,t);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const I of b.children)if(I.isLabel&&I.isPointInBounds(k))return v}if(this.isShapeOfType(v,"frame")){const I=b.distanceToPoint(k,u);if(Math.abs(I)<=a)return m||v;if(b.hitTestPoint(k,0,!0))return m||f||(h?v:void 0);continue}let C;if(E){let I=1/0;for(const T of b.children){if(T.isLabel&&!c)continue;const O=T.distanceToPoint(k,u);O<I&&(I=O)}C=I}else a===0&&(b.bounds.w<1||b.bounds.h<1)||b.bounds.containsPoint(k,a)?C=b.distanceToPoint(k,u):C=1/0;if(b.isClosed){if(C<=a){if(b.isFilled||E&&b.children[0].isFilled)return m||v;if(this.getShapePageBounds(v).contains(s))continue;if(Math.abs(C)<a)Math.abs(C)<y&&(y=Math.abs(C),m=v);else if(!m){const{area:I}=b;I<p&&(p=I,f=v)}}}else if(C<this.options.hitTestMargin/o)return v}return m||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&&!nr(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(En(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++)j2(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(_n(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||!_n(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 En(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(y=>y.id);if(s.length===0)return this;const i=[],a=En(r)?oe.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const u=me(this.getSortedChildIdsForParent(r).map(y=>this.getShape(y)));if(o){const y=u.find(m=>m.index===o);if(y){const m=u[u.indexOf(y)+1];m?c=ll(o,m.index,s.length):c=Sm(o,s.length)}else{const m=u.sort(on).find(x=>x.index>o);m?c=ll(o,m.index,s.length):c=Sm(o,s.length)}}else{const y=u.length&&u[u.length-1];c=y?Sm(y.index,s.length):Vc(s.length)}const h=a.clone().invert(),p=me(s.map(y=>this.getShape(y))),f=p.filter(y=>y.isLocked);f.length&&this.updateShapes(f.map(({id:y,type:m})=>({id:y,type:m,isLocked:!1})));for(let y=0;y<p.length;y++){const m=p[y],x=this.getShapePageTransform(m);if(!x)continue;const S=x.point();if(!S)continue;const v=h.applyToPoint(S),b=x.rotation()-l;i.push({id:m.id,type:m.type,parentId:r,x:v.x,y:v.y,rotation:b,index:c[y],isLocked:m.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 No(s.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o||Wo}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=YW(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)??Wo;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??Oi(),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=Oo(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?(Dh({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=Oo(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=Oo(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=Oo(o,((a=s.onTranslate)==null?void 0:a.call(s,t,o))??void 0),o=Oo(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:u}=OC(this,i,p=>{const f=[];for(const m of p){const x=this.getBinding(m);if(!x)continue;const S=Oi();f.push({...x,id:S,fromId:Sr(l.get(x.fromId)),toId:Sr(l.get(x.toId))})}const y=[];for(const m of a){const x=Sr(l.get(m)),S=this.getShape(m);if(!S)continue;let v=0,b=0;if(r&&s.has(m)){const _=this.getShapeParentTransform(S),M=new w(r.x,r.y).rot(-_.rotation());v=M.x,b=M.y}const E=S.parentId,k=this.getSortedChildIdsForParent(E),C=k.indexOf(S.id),I=k[C+1],T=I?this.getShape(I):null,O=T?Gc(S.index,T.index):No(S.index);y.push({...S,id:x,x:S.x+v,y:S.y+b,index:O,parentId:l.get(S.parentId)??S.parentId})}return{shapesToCreate:y,bindingsToCreate:f}});if(c.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Kd(this);return}if(this.createShapes(c),this.createBindings(u),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 Kd(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=Hd(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Hd(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Hd(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Hd(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,u,h,p;r==="horizontal"?(c="x",u="minX",h="maxX",p="width"):(c="y",u="minY",h="maxY",p="height");let f;if(o===0){const x=[];i.sort((v,b)=>l[v.id][u]-l[b.id][u]);for(let v=0;v<a-1;v++){const b=i[v],E=i[v+1],k=l[b.id],I=l[E.id][u]-k[h],T=x.find(O=>O.gap===I);T?T.count++:x.push({gap:I,count:1})}let S=0;x.forEach(v=>{v.count>S&&(S=v.count,f=v.gap)}),S===1&&(f=Math.max(0,x.reduce((v,b)=>v+b.gap*b.count,0)/(a-1)))}else f=o;const y=[];let m=l[i[0].id][h];return i.forEach((x,S)=>{var C,I;if(S===0)return;const v={x:0,y:0};v[c]=m+f-l[x.id][c];const b=this.getShapeParent(x),E=b?w.Rot(v,-this.getShapePageTransform(b).decompose().rotation):v,k=(I=(C=this.getShapeUtil(x)).onTranslateStart)==null?void 0:I.call(C,x);y.push(k?{...k,[c]:x[c]+E[c]}:{id:x.id,type:x.type,[c]:x[c]+E[c]}),m+=l[x.id][p]+f}),this.updateShapes(y),this}packShapes(t,r){var I,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,u=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(),u+=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(u/.95)),p),y=[new Z(h.x,h.y,f,1/0)];let m=0,x=0,S,v;for(let O=0;O<s.length;O++){l=s[O],c=a[l.id];for(let _=y.length-1;_>=0;_--)if(S=y[_],!(c.width>S.width||c.height>S.height)){c.x=S.x,c.y=S.y,x=Math.max(x,c.maxY),m=Math.max(m,c.maxX),c.width===S.width&&c.height===S.height?(v=y.pop(),_<y.length&&(y[_]=v)):c.height===S.height?(S.x+=c.width+r,S.width-=c.width+r):c.width===S.width?(S.y+=c.height+r,S.height-=c.height+r):(y.push(new Z(S.x+(c.width+r),S.y,S.width-(c.width+r),c.height)),S.y+=c.height+r,S.height-=c.height+r);break}}const b=Z.Common(Object.values(a)),E=w.Sub(h.center,b.center);let k;const C=[];for(let O=0;O<s.length;O++){l=s[O],c=i[l.id],k=a[l.id];const _=w.Sub(k.point,c.point).add(E),M=this.getShapeParentTransform(l);M&&_.rot(-M.rotation());const L={id:l.id,type:l.type,x:l.x+_.x,y:l.y+_.y},j=(T=(I=this.getShapeUtil(l)).onTranslateStart)==null?void 0:T.call(I,{...l,...L});j?C.push({...L,...j}):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 u=i[c.id];if(!u)return;const h={x:0,y:0};switch(r){case"top":{h.y=a.minY-u.minY;break}case"center-vertical":{h.y=a.midY-u.minY-u.height/2;break}case"bottom":{h.y=a.maxY-u.minY-u.height;break}case"left":{h.x=a.minX-u.minX;break}case"center-horizontal":{h.x=a.midX-u.minX-u.width/2;break}case"right":{h.x=a.maxX-u.minX-u.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,u,h,p;r==="horizontal"?(l="x",c="minX",u="maxX",h="midX",p="width"):(l="y",c="minY",u="maxY",h="midY",p="height");const f=[],y=i.sort((b,E)=>a[b.id][c]-a[E.id][c])[0],m=i.sort((b,E)=>a[E.id][u]-a[b.id][u])[0],x=a[y.id][h],S=(a[m.id][h]-x)/(s-1),v=x+S;return i.filter(b=>b!==y&&b!==m).sort((b,E)=>a[b.id][h]-a[E.id][h]).forEach((b,E)=>{const k={x:0,y:0};k[l]=v+S*E-a[b.id][p]/2-a[b.id][l];const C=this.getShapeParent(b),I=C?w.Rot(k,-this.getShapePageTransform(C).rotation()):k;f.push(this.getChangesToTranslateShape(b,w.Add(b,I)))}),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),y=this.getShapeParentTransform(c);y&&f.rot(-y.rotation());const{x:m,y:x}=w.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:m,y:x}]);const S=new w(1,l.height/p.height);this.resizeShape(c.id,S,{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 u=i[c.id],h=a[c.id];if(this.getShapePageTransform(c).rotation()%Re)continue;const f=new w(l.minX-h.minX,0),y=this.getShapeParentTransform(c);y&&f.rot(-y.rotation());const{x:m,y:x}=w.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:m,y:x}]);const S=new w(l.width/h.width,1);this.resizeShape(c.id,S,{initialBounds:u,scaleOrigin:new w(l.minX,h.center.y),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}}return this}resizeShape(t,r,o={}){var y,m,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??((y=this.getShapePageBounds(s))==null?void 0:y.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 u=o.scaleAxisRotation??c,h=o.initialBounds??this.getShapeGeometry(s).bounds;if(!h)return this;const p=o.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!N_(c,u))return this._resizeUnalignedShape(s,r,{...o,initialBounds:h,scaleOrigin:a,scaleAxisRotation:u,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 S=this._scalePagePoint(oe.applyToPoint(l,new w(0,0)),a,r,u),v=this.getPointInParentSpace(i.id,S),b=new w(r.x,r.y),E=Ds((c-u)%Math.PI,0);b.x=E?r.x:r.y,b.y=E?r.y:r.x;const k=oe.applyToPoint(l,new w),{x:C,y:I}=this.getPointInParentSpace(i.id,k);let T=i;o.skipStartAndEndCallbacks||(T=Oo(i,((m=f.onResizeStart)==null?void 0:m.call(f,i))??void 0)),T=Oo(T,{id:s,type:i.type,x:v.x,y:v.y,...f.onResize({...i,x:C,y:I},{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=Oo(T,((x=f.onResizeEnd)==null?void 0:x.call(f,i,T))??void 0)),this.updateShapes([T])}else{const S=oe.applyToPoint(l,h.center),v=this._scalePagePoint(S,a,r,u),b=this.getPointInParentSpace(i.id,S),E=this.getPointInParentSpace(i.id,v),k=w.Sub(E,b);this.updateShapes([{id:s,type:i.type,x:i.x+k.x,y:i.y+k.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:S}=oe.Decompose(o.initialPageTransform);S-=2*S,this.updateShapes([{id:t,type:s,rotation:S}])}const a=oe.applyToPoint(o.initialPageTransform,o.initialBounds.center),l=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),c=this.getShapePageBounds(t),u=this.getShapePageTransform(t),h=c.center,p=u.point();if(!h||!p)return this;const f=w.Sub(l,h),y=w.Add(p,f),{x:m,y:x}=this.getPointInParentSpace(t,y);return this.updateShapes([{id:t,type:s,x:m,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 Kd(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(y=>y.id===f.parentId))){let y=this.getFocusedGroupId();for(let x=i.length-1;x>=0;x--){const S=i[x];if(this.getShapeUtil(S).canReceiveNewChildrenOfType(S,f.type)&&this.isPointInShape(S,{x:f.x??0,y:f.y??0},{margin:0,hitInside:!0})){y=S.id;break}}const m=f.parentId;if(y===f.id&&(y=s),y!==m&&(f={...f},f.parentId=y,_n(y))){const x=this.getPointInShapeSpace(this.getShape(y),{x:f.x??0,y:f.y??0});f.x=x.x,f.y=x.y,f.rotation=-this.getShapePageTransform(y).rotation()+(f.rotation??0)}}return f}),l=new Map,c=[],{opacityForNextShape:u}=this.getInstanceState();for(const f of a){const y=this.getShapeUtil(f);let m=f.index;if(!m){const b=f.parentId??s;l.has(b)||l.set(b,this.getHighestIndexForParent(b)),m=l.get(b),l.set(b,No(m))}const x=y.getDefaultProps();for(const[b,E]of this.styleProps[f.type])x[E]=this.getStyleForNextShape(b);let S=this.store.schema.types.shape.create({...f,index:m,opacity:f.opacity??u,parentId:f.parentId??s,props:"props"in f?{...x,...f.props}:x});if(S.index===void 0)throw Error("no index!");const v=(p=(h=this.getShapeUtil(S)).onBeforeCreate)==null?void 0:p.call(h,S);v&&(S=v),c.push(S)}c.forEach(f=>{f.meta={...this.getInitialMetaForShape(f),...f.meta}}),this.store.put(c)})}animateShape(t,r={animation:bm}){return this.animateShapes([t],r)}animateShapes(t,r={animation:bm}){if(!r.animation)return this;const{duration:o=500,easing:s=At.linear}=r.animation,i=ot();let a=o,l;const c=[];let u,h;for(let y=0,m=t.length;y<m;y++){if(u=t[y],!u)continue;h={partial:u,values:[]};const x=this.getShape(u.id);if(x){for(const S of["x","y","rotation"])u[S]!==void 0&&x[S]!==u[S]&&h.values.push({prop:S,from:x[S],to:u[S]});c.push(h),this.animatingShapes.set(x.id,i)}}let p;const f=y=>{if(a-=y,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:m}=this,x=[];let S;for(let v=0,b=c.length;v<b;v++)p=c[v],S=m.get(p.partial.id),S===i&&x.push({id:p.partial.id,type:p.partial.type,...p.values.reduce((E,{prop:k,from:C,to:I})=>(E[k]=C+(I-C)*l,E),{})});this._updateShapes(x)};return this.on("tick",f),this}groupShapes(t,r={}){var m;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:u,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),y=(m=f[f.length-1])==null?void 0:m.index;return this.batch(()=>{this.createShapes([{id:o,type:"group",parentId:p,index:y,x:u,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,u=a.length;c<u;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,jn(t.props,s))}_getSelectionSharedStyles(){const t=this.getSelectedShapes(),r=new xv;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 jn(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const t=this.root.getCurrent(),r=new xv;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 u={id:a.id,type:a.type,props:{[c]:r}};s.push({util:l,originalShape:a,updatePartial:u})}}};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 OC(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 y=this.getShapePageTransform(p.id),m=y.point();l.push({...p,x:m.x,y:m.y,rotation:y.rotation(),parentId:this.getCurrentPageId()}),a.push(p.id)}else l.push(p)}const c=[],u=new Set;for(const h of l){if(!("assetId"in h.props))continue;const p=h.props.assetId;if(!p||u.has(p))continue;u.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 Ai.blobToDataUrl(await So(l).then(c=>c.blob())),r.push(a)}else r.push(o)})),t.assets=r,t}putContentOntoCurrentPage(t,r={}){var M,L;if(this.getInstanceState().isReadonly)return this;if(!t.schema)throw Error(`Could not put content:
90
+ 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,u=[],h=[],p=[],f={store:{...Object.fromEntries(t.assets.map(j=>[j.id,j])),...Object.fromEntries(t.shapes.map(j=>[j.id,j])),...Object.fromEntries(((M=t.bindings)==null?void 0:M.map(j=>[j.id,j]))??[])},schema:t.schema},y=this.store.schema.migrateStoreSnapshot(f);if(y.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(y.value))switch(j.typeName){case"asset":{u.push(j);break}case"shape":{h.push(j);break}case"binding":{p.push(j);break}}const m=new Map(s?h.map(j=>[j.id,j.id]):h.map(j=>[j.id,$e()])),x=new Map(s?p.map(j=>[j.id,j.id]):p.map(j=>[j.id,Oi()]));let S=this.getCurrentPageId(),v=1/0,b=[];for(const j of this.getSelectedShapes()){if(v===0)break;const R=this.isShapeOfType(j,"frame"),F=this.getShapeAncestors(j);R&&F.push(j);const W=R?F.length+1:F.length;if(W<v)v=W,b=F,S=R?j.id:j.parentId;else if(W===v){if(b.length!==F.length)throw Error(`Ancestors: ${b.length} !== ${F.length}`);if(b.length===0){S=l;break}else{S=l;for(let K=0;K<b.length&&F[K]===b[K];K++)S=F[K].id}}}let E=!1;if(!En(S)){const j=this.getShape(S);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))S=l;else if(c.length===1){const R=h.find(F=>F.id===c[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(R,"frame")&&R.props.w===(j==null?void 0:j.props.w)&&R.props.h===(j==null?void 0:j.props.h)&&(E=!0)}}else S=l}E||(E=m.has(S)),E&&(S=this.getShape(S).parentId);let k=this.getHighestIndexForParent(S);const C=[],I=h.map(j=>{const R=m.get(j.id),F={...j,id:R};return c.includes(j.id)&&(F.parentId=l,C.push(F)),m.has(F.parentId)?F.parentId=m.get(j.parentId):(c.push(F.id),F.index=k,k=No(k)),F});if(I.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Kd(this),this;const T=p.map(j=>({...j,id:Sr(x.get(j.id)),fromId:Sr(m.get(j.fromId)),toId:Sr(m.get(j.toId))})),O=[],_=[];for(const j of u)this.store.has(j.id)||((j.type==="image"||j.type==="video")&&((L=j.props.src)!=null&&L.startsWith("data:image"))&&(_.push(rt(j)),j.props.src=null),O.push(j));return Promise.allSettled(_.map(async j=>{const R=await UW(j.props.src,j.props.name,j.props.mimeType??"image/png"),F=await this.getAssetForExternalContent({type:"file",file:R});if(!F){this.deleteAssets([j.id]);return}this.updateAssets([{...F,id:j.id}])})),this.batch(()=>{O.length>0&&this.createAssets(O),this.createShapes(I),this.createBindings(T),o&&this.select(...C.map(K=>K.id)),S!==l&&this.reparentShapes(C.map(K=>K.id),S);const j=I.map(K=>this.getShape(K.id)),R=Z.Common(j.map(K=>this.getShapePageBounds(K)));if(a===void 0)if(En(S)){const K=this.getViewportPageBounds();i||K.includes(Z.From(R))?a=R.center:a=K.center}else{const K=this.getShape(S);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 eG(this,t,r);if(!o)return;const s=document.createDocumentFragment(),i=S2(s);aa.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(mn),{x:c,y:u,z:h}=gd(()=>this.getCamera()),p=t.point.x-l.x,f=t.point.y-l.y,y=t.point.z??.5;o.setTo(i),s.setTo(a),i.set(p,f);const m=p/h-c,x=f/h-u;isFinite(m)&&isFinite(x)&&a.set(m,x,y),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 S;this.store.put([{id:Rp,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===eP.CAMERA_MOVE?((S=this.store.unsafeGetWithoutCapture(Rp))==null?void 0:S.lastActivityTimestamp)??this._tickManager.now:this._tickManager.now,meta:{}}])})}cancel(){return this.dispatch({type:"misc",name:"cancel"}),this}interrupt(){return this.dispatch({type:"misc",name:"interrupt"}),this}complete(){return this.dispatch({type:"misc",name:"complete"}),this}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 OW(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){xt.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,"_unsafe_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 Kd(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:e.options.maxShapesPerPage})}function Oo(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 j2(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++)j2(e,o[s],t)}function OC(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 u=n.has(c.fromId),h=n.has(c.toId);if(u&&h){s.add(c.id);continue}(!u||!h)&&i.add(c.id)}e.deleteBindings([...i],{isolateShapes:!0});try{r=gn.ok(t(s))}catch(a){r=gn.err(a)}});e.store.applyDiff(mS(o))}),r.ok)return r.value;throw r.error}function DC(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 Ku(){const e=B(),n=M2();return G("isDarkMode",()=>(n==null?void 0:n.isDarkMode)??e.user.getIsDarkMode(),[n,e])}const RC="<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'/>",LC="<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'/>",Wd='<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 Ss(e,n,t,r,o,s=16,i=16){const a=(-t-n)*(ke/180),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,h=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${h}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${n+t} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const OG=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],DG={none:()=>"none","ew-resize":(e,n,t)=>Ss(LC,e,0,n,t),"ns-resize":(e,n,t)=>Ss(LC,e,90,n,t),"nesw-resize":(e,n,t)=>Ss(RC,e,0,n,t),"nwse-resize":(e,n,t)=>Ss(RC,e,90,n,t),"nwse-rotate":(e,n,t)=>Ss(Wd,e,0,n,t),"nesw-rotate":(e,n,t)=>Ss(Wd,e,90,n,t),"senw-rotate":(e,n,t)=>Ss(Wd,e,180,n,t),"swne-rotate":(e,n,t)=>Ss(Wd,e,270,n,t)};function Yn(e,n=0,t="black"){return DG[e](X6(n),!1,t)}function RG(){const e=B(),n=un(),t=Ku();Os("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(OG.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Yn(r,o,t?"white":"black"))},[e,n,t])}function LG(){const e=B(),n=un(),t=Ku(),r=G(xt.forceSrgb);we.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 Xw(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 $G(){const[e,n]=P.useState(0);P.useEffect(()=>n(t=>t+1),[])}function FG(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
91
+
92
+ Keep seeing this message?
93
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
94
+ • If your hard disk is full, try clearing up some space and then reload the page.`)}function NG(){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.
95
+
96
+ Keep seeing this message?
97
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const zG=(e,n)=>n.some(t=>e instanceof t);let $C,FC;function BG(){return $C||($C=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function UG(){return FC||(FC=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const O2=new WeakMap,wv=new WeakMap,D2=new WeakMap,ty=new WeakMap,qw=new WeakMap;function HG(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(Vo(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(()=>{}),qw.set(n,e),n}function KG(e){if(wv.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)});wv.set(e,n)}let bv={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return wv.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 Vo(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 WG(e){bv=e(bv)}function GG(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(ny(this),n,...t);return D2.set(r,n.sort?n.sort():[n]),Vo(r)}:UG().includes(e)?function(...n){return e.apply(ny(this),n),Vo(O2.get(this))}:function(...n){return Vo(e.apply(ny(this),n))}}function VG(e){return typeof e=="function"?GG(e):(e instanceof IDBTransaction&&KG(e),zG(e,BG())?new Proxy(e,bv):e)}function Vo(e){if(e instanceof IDBRequest)return HG(e);if(ty.has(e))return ty.get(e);const n=VG(e);return n!==e&&(ty.set(e,n),qw.set(n,e)),n}const ny=e=>qw.get(e);function R2(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=Vo(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Vo(i.result),l.oldVersion,l.newVersion,Vo(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 YG(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),Vo(t).then(()=>{})}const XG=["get","getKey","getAll","getAllKeys","count"],qG=["put","add","delete","clear"],ry=new Map;function NC(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(ry.get(n))return ry.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=qG.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||XG.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 ry.set(n,s),s}WG(e=>({...e,get:(n,t,r)=>NC(n,t)||e.get(n,t,r),has:(n,t)=>!!NC(n,t)||e.has(n,t)}));const dg="TLDRAW_DOCUMENT_v2",L2="TLDRAW_DB_NAME_INDEX_v2",Le={Records:"records",Schema:"schema",SessionState:"session_state"};async function hg(e,n){tV(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 ZG({persistenceKey:e,sessionId:n,didCancel:t}){const r=dg+e;if(Zw().includes(r))return await eV({persistenceKey:e,didCancel:t}),await hg(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((y,m)=>y.updatedAt-m.updatedAt).pop())==null?void 0:p.snapshot);const u={records:await i.getAll(),schema:await a.get(Le.Schema),sessionStateSnapshot:c};if(t!=null&&t()){s.abort();return}return await s.done,u})}async function QG({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=dg+e;await hg(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),u=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(u.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 JG({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=dg+e;await hg(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),u=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(u.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 eV({persistenceKey:e,didCancel:n}){await hg(dg+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 Zw(){const e=JSON.parse(Ff(L2)||"[]")??[];return Array.isArray(e)?e:[]}function tV(e){const n=new Set(Zw());n.add(e),Nf(L2,JSON.stringify([...n]))}const nV=350,rV=1e4,zC=Symbol("UPDATE_INSTANCE_STATE"),oV=e=>e;class sV{constructor(n){g(this,"onmessage")}postMessage(n){}close(){}}const iV=typeof BroadcastChannel>"u"?sV:BroadcastChannel;class aV{constructor(n,{persistenceKey:t,sessionId:r=pf,onLoad:o,onLoadError:s},i=new iV(`tldraw-tab-sync-${t}`)){g(this,"disposables",new Set);g(this,"diffQueue",[]);g(this,"didDispose",!1);g(this,"shouldDoFullDBWrite",!0);g(this,"isReloading",!1);g(this,"persistenceKey");g(this,"sessionId");g(this,"serializedSchema");g(this,"isDebugging",!1);g(this,"documentTypes");g(this,"$sessionStateSnapshot");g(this,"initTime",Date.now());g(this,"isPersisting",!1);g(this,"didLastWriteError",!1);g(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(oV({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(zC),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 ZG({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),NG(),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??AW(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"),js(()=>{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?rV:nV))}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 JG({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=Ox(n.filter(r=>r!==zC));await QG({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),FG(),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:N6({shapes:"shapeUtils"in r&&r.shapeUtils?BC(k2(r.shapeUtils)):void 0,bindings:"bindingUtils"in r&&r.bindingUtils?BC(C2(r.bindingUtils)):void 0,migrations:"migrations"in r?r.migrations:void 0});return new $x({id:t,schema:o,initialData:e,props:{defaultName:n}})}function BC(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function UC(e){const n=$2(e);return e.snapshot&&P2(n,e.snapshot),{store:n,opts:e}}function F2(e){const[n,t]=P.useState(()=>UC(e));if(!_k(n.opts,e)){const r=UC(e);return t(r),r.store}return n.store}function lV({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(u=>(u==null?void 0:u.id)===i?{id:i,storeWithStatus:c}:u)},l=new aV(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 cV(){const e=B(),n=un();P.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=bk(t,100),o=new jl("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[e,n])}const uV=[],dV=[],hV=[],pV=P.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=we.useState(null),l=P.useMemo(()=>o??gT(),[o]),c=(t==null?void 0:t.ErrorFallback)===void 0?lT:t==null?void 0:t.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??uV,bindingUtils:s.bindingUtils??dV,tools:s.tools??hV,components:t};return d.jsx("div",{ref:a,draggable:!1,className:ce("tl-container tl-theme__light",r),onPointerDown:Ht,tabIndex:-1,children:d.jsx(qc,{fallback:c,onError:h=>Mx(h,{tags:{origin:"react.tldraw-before-app"}}),children:i&&d.jsx(iH,{container:i,children:d.jsx(u7,{overrides:t,children:n?n instanceof $x?d.jsx(z2,{...u,store:n,user:l}):d.jsx(N2,{...u,store:n,user:l}):d.jsx(fV,{...u,store:n,user:l})})})})})});function fV(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l}=e,c=lV({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:n,snapshot:t});return d.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?d.jsx(s,{}):null}return d.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:u,assetOptions:h,options:p}){const{ErrorFallback:f}=it(),y=un(),m=P.useRef(null),[x,S]=P.useState(null),v=m.current;x!==v&&S(v);const b=P.useRef({autoFocus:l,inferDarkMode:c,initialState:a,cameraOptions:u});P.useLayoutEffect(()=>{b.current={autoFocus:l,inferDarkMode:c,initialState:a,cameraOptions:u}},[l,c,a,u]),P.useLayoutEffect(()=>{const{autoFocus:C,inferDarkMode:I,initialState:T,cameraOptions:O}=b.current,_=new Q({store:t,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>y,user:i,initialState:T,autoFocus:C,inferDarkMode:I,cameraOptions:O,assetOptions:h,options:p});return m.current=_,S(_),()=>{_.dispose()}},[h,s,y,p,o,t,r,i]),P.useLayoutEffect(()=>{v&&u&&v.setCameraOptions(u)},[v,u]);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:k}=it();return v?d.jsx(qc,{fallback:f,onError:C=>v.annotateError(C,{origin:"react.tldraw",willCrashApp:!0}),children:E?d.jsx(mV,{crashingError:E}):d.jsx(Gf.Provider,{value:v,children:d.jsx(gV,{onMount:e,children:n??(k?d.jsx(k,{}):null)})})}):null}function gV({children:e,onMount:n}){return cV(),RG(),LG(),$G(),yV(n),e}function mV({crashingError:e}){throw e}function Qw({children:e}){return d.jsx("div",{className:"tl-loading",children:e})}function B2({children:e}){return d.jsx("div",{className:"tl-loading",children:e})}function yV(e){const n=B(),t=Xw(r=>{let o;return r.history.ignore(()=>{o=e==null?void 0:e(r),r.emit("mount")}),window.tldrawReady=!0,o});we.useLayoutEffect(()=>{if(n)return t==null?void 0:t(n)},[n,t])}function Vi({children:e,className:n="",...t}){return d.jsx("div",{...t,className:ce("tl-html-container",n),children:e})}class Lh{constructor(n){this.editor=n}}g(Lh,"props"),g(Lh,"migrations"),g(Lh,"type");function Jw(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=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:y,y:m}=f.rot(e.rotation).add(r);return{...e,x:y,y:m,props:{w:Math.min(l,h),h:Math.min(u,p)}}}class $l extends Hr{constructor(){super(...arguments);g(this,"onResize",(t,r)=>Jw(t,r))}getGeometry(t){return new ns({width:t.props.w,height:t.props.h,isFilled:!0})}getHandleSnapGeometry(t){return{points:this.getGeometry(t).bounds.cornersAndCenter}}}var jy;let SV=(jy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(jy,"id","idle"),jy);var Oy;let vV=(Oy=class extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"wasFocusedOnEnter",!1);g(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});g(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})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(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 u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),i*=u,a*=u,l.mul(u));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=u),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")}},g(Oy,"id","pointing"),Oy);class $h extends se{constructor(){super(...arguments);g(this,"onCreate")}}g($h,"id","box"),g($h,"initial","idle"),g($h,"children",()=>[SV,vV]);function pg(e){const n=B();return G("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function xV(){return P.useId().replace(/:/g,"_")}function ro(e){const n=B();return P.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===Vx){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...On(c)});return}if(c.button!==0)return;const u=zp(c.currentTarget);function h(){u.removeEventListener("pointerup",h),Ru(u,c)}Du(u,c),u.addEventListener("pointerup",h),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...On(c)}),Ht(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 wV=20,bV=8;function e0(e,n=wV){return Math.max(bV,Math.ceil(e/n))}class Ha extends oi{constructor(t){super({...t,isFilled:!1,isClosed:!1});g(this,"_center");g(this,"radius");g(this,"start");g(this,"end");g(this,"largeArcFlag");g(this,"sweepFlag");g(this,"measure");g(this,"angleStart");g(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=q6(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,u=PS(o,a,i,r.angle(t));if(u<=0)return l;if(u>=1)return c;const h=r.clone().add(t.clone().sub(r).uni().mul(s));let p,f=1/0,y;for(const m of[l,c,h])y=w.Dist2(t,m),y<f&&(p=m,f=y);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=Uu(t,r,o,s);return c===null?!1:c.some(u=>{const h=PS(i,a,l,o.angle(u));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 u=l/c*r,h=i+u;a.push(Bi(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 oi{constructor(t){super({isClosed:!0,...t});g(this,"_center");g(this,"radius");g(this,"x");g(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(Bi(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 Uu(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]});g(this,"a");g(this,"b");g(this,"c");g(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 PV extends oi{constructor(t){super({...t,isClosed:!1,isFilled:!1});g(this,"points");g(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],u=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-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),y=c;this._segments.push(new nn({start:h,cp1:p,cp2:f,end:y}))}}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 CV extends oi{constructor(t){super({...t,isClosed:!0});g(this,"w");g(this,"h");g(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 Ho({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=ke*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),l=e0(a),c=Re/l,u=Math.cos(c),h=Math.sin(c);let p=0,f=1,y=0,m=1;const x=Array(l);for(let S=0;S<l;S++)x[S]=new w(o+o*f,s+s*p),y=h*f+u*p,m=u*f-h*p,p=y,f=m;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 $_(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 IV extends oi{constructor(t){super({...t,isClosed:!0});g(this,"w");g(this,"h");g(this,"a");g(this,"b");g(this,"c");g(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 Ho({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 Ho({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 Ho({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 Ho({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:u}=this;for(const h of[a,l,c,u])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?(ke*(r/2)+(t-r))*2:(ke*(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 EV({shouldReload:e=!0}={}){W4(),await Promise.all(Zw().map(n=>YG(n))),K4(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=EV);function kV(e,n="_blank"){Qx.openWindow(e,n)}const U2="TLDRAW_ASSET_STORE_v1",H2="TLDRAW_DB_NAME_INDEX_v2",ml={Assets:"assets"};async function K2(e,n){AV(e);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 _V({persistenceKey:e,assetId:n}){const t=U2+e;return await K2(t,async r=>await r.transaction([ml.Assets],"readwrite").objectStore(ml.Assets).get(n))}async function TV({persistenceKey:e,assetId:n,blob:t}){const r=U2+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 MV(){const e=JSON.parse(Ff(H2)||"[]")??[];return Array.isArray(e)?e:[]}function AV(e){const n=new Set(MV());n.add(e),Nf(H2,JSON.stringify([...n]))}function jV({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])?d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:OV}=Math,rl=OV+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 u=e[0].vector,h=e[0].point,p=h,f=h,y=p,m=!1,x;for(let S=0;S<e.length;S++){x=e[S];const{point:v,vector:b}=e[S],E=x.vector.dpr(u),k=(S<e.length-1?e[S+1]:e[S]).vector,C=S<e.length-1?k.dpr(x.vector):1,I=E<0&&!m,T=C!==null&&C<.2;if(I||T){if(C>-.62&&i-x.runningLength>x.radius){const _=u.clone().mul(x.radius);u.clone().cpr(k)<0?(f=w.Add(v,_),y=w.Sub(v,_)):(f=w.Sub(v,_),y=w.Add(v,_)),l.push(f),c.push(y)}else{const _=u.clone().mul(x.radius).per(),M=w.Sub(x.input,_);for(let L=1/13,j=0;j<1;j+=L)f=w.RotWith(M,x.input,rl*j),l.push(f),y=w.RotWith(M,x.input,rl+rl*-j),c.push(y)}h=f,p=y,T&&(m=!0);continue}if(m=!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(k,b,C).per().mul(x.radius);f=w.Sub(v,O),(S<=1||w.Dist2(h,f)>a)&&(l.push(f),h=f),y=w.Add(v,O),(S<=1||w.Dist2(p,y)>a)&&(c.push(y),p=y),u=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],u=c.runningLength,h=r.taper===!1?0:r.taper===!0?Math.max(t,u):r.taper,p=o.taper===!1?0:o.taper===!0?Math.max(t,u):o.taper,{left:f,right:y}=W2(e,n),m=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(m,w.Sub(m,x).uni().per().mul(-l.radius)),k=[];for(let C=1/13,I=C;I<=1;I+=C)k.push(w.RotWith(E,m,rl*2*I));return k}const S=[];if(!(h||p&&e.length===1))if(i)for(let E=1/8,k=E;k<=1;k+=E){const C=w.RotWith(y[0],m,rl*k);S.push(C)}else{const E=w.Sub(f[0],y[0]),k=w.Mul(E,.5),C=w.Mul(E,.51);S.push(w.Sub(m,k),w.Sub(m,C),w.Add(m,C),w.Add(m,k))}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 k=1/29,C=k;C<1;C+=k)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,y.reverse(),S)}const DV=.025,RV=.01;function wo(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 S=i[0];for(;S&&!(S.z>=DV);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=RV);)i.pop(),S=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 u=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 S=i[1];i=i.slice(0,-1);for(let v=1;v<5;v++){const b=w.Lrp(i[0],S,v/4);b.z=(i[0].z+(S.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],y,m;u&&t>0&&i.push(i[i.length-1].clone());for(let S=1,v=i.length;S<v;S++)y=!s||n.last&&S===v-1?i[S].clone():i[S].clone().lrp(f.point,1-s),!f.point.equals(y)&&(m=w.Dist(y,f.point),p+=m,!(S<4&&p<r)&&(f={input:i[S],point:y,pressure:o?.5:i[S].z,vector:w.Sub(f.point,y).uni(),distance:m,runningLength:p,radius:1},h.push(f)));if((x=h[1])!=null&&x.vector&&(h[0].vector=h[1].vector.clone()),p<1){const S=Math.max(.5,...h.map(v=>v.pressure));h.forEach(v=>v.pressure=S)}return h}const{min:vs}=Math,oy=.275;function fg(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=x=>x,start:i={},end:a={}}=n,{easing:l=At.easeOutQuad}=i,{easing:c=At.easeOutCubic}=a,u=e[e.length-1].runningLength;let h,p=e[0].pressure,f;if(!o&&u<t){const x=e.reduce((S,v)=>Math.max(S,v.pressure),.5);return e.forEach(S=>{S.pressure=x,S.radius=t*s(.5-r*(.5-S.pressure))}),e}else{let x;for(let S=0,v=e.length;S<v&&(f=e[S],!(f.runningLength>t*5));S++){const b=vs(1,f.distance/t);if(o){const E=vs(1,1-b);x=vs(1,p+(E-p)*(b*oy))}else x=vs(1,p+(f.pressure-p)*.5);p=p+(x-p)*.5}for(let S=0;S<e.length;S++){if(f=e[S],r){let{pressure:v}=f;const b=vs(1,f.distance/t);if(o){const E=vs(1,1-b);v=vs(1,p+(E-p)*(b*oy))}else v=vs(1,p+(v-p)*(b*oy));f.radius=t*s(.5-r*(.5-v)),p=v}else f.radius=t/2;h===void 0&&(h=f.radius)}}const y=i.taper===!1?0:i.taper===!0?Math.max(t,u):i.taper,m=a.taper===!1?0:a.taper===!0?Math.max(t,u):a.taper;if(y||m)for(let x=0;x<e.length;x++){f=e[x];const{runningLength:S}=f,v=S<y?l(S/y):1,b=u-S<m?c((u-S)/m):1;f.radius=Math.max(.01,f.radius*Math.min(v,b))}return e}function LV(e,n={}){return n0(fg(wo(e,n),n),n)}function HC({scribble:e,zoom:n,color:t,opacity:r,className:o}){if(!e.points.length)return null;const s=LV(e.points,{size:e.size/n,start:{taper:e.taper,easing:At.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=Xx(s);return d.jsx("svg",{className:o&&ce("tl-overlays__item",o),children:d.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})}const $V=({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])?d.jsx(rT,{bounds:e,rotation:n}):null};function cs(){const e=B();return G("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function FV({size:e,width:n,height:t,hideAlternateHandles:r}){const o=N(e/3),s=o/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
98
+ ${N(0-s)},${N(e)}
99
+ ${N(0-s)},${N(0-s)}
100
+ ${N(e)},${N(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),d.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"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
101
+ ${N(n-e)},${N(0-s)}
102
+ ${N(n+s)},${N(0-s)}
103
+ ${N(n+s)},${N(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),d.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"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
104
+ ${N(n+s)},${N(t-e)}
105
+ ${N(n+s)},${N(t+s)}
106
+ ${N(n-e)},${N(t+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),d.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"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
107
+ ${N(0+e)},${N(t+s)}
108
+ ${N(0-s)},${N(t+s)}
109
+ ${N(0-s)},${N(t-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),d.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 NV=lr(function({bounds:n,rotation:t}){const r=B(),o=P.useRef(null),s=cs(),i=ro("top"),a=ro("right"),l=ro("bottom"),c=ro("left"),u=ro("top_left"),h=ro("top_right"),p=ro("bottom_right"),f=ro("bottom_left"),y=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,x=r.getOnlySelectedShape(),S=x&&r.isShapeOrAncestorLocked(x),v=x?r.getShapeUtil(x).expandSelectionOutlinePx(x):0;if(Ol(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,k=n.width,C=n.height,I=8/b,T=k<I*2,O=C<I*2,_=k<I*4,M=C<I*4,L=k<I*5,j=C<I*5,R=m?1.75:1,F=6/b*R,W=(_?F/2:F)*(R*.75),K=(M?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=!m&&!(T||O)&&(J||X)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!S,ye=m&&(!_||!M)&&(J||X)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!S,Me=J&&(x?r.getShapeUtil(x).canResize(x)&&!r.getShapeUtil(x).hideResizeHandles(x):!0)&&!X&&!S,ae=T||O,Ue=T&&O,je=L||j,et=Me||X,Ae=!le,at=!J||!ye,Ne=!J||!et,Gn=!J||!et||ae,Rt=!J||!et||ae,Cn=!J||!et||Ue&&!X;let St=!0,Xt=!0;if(X)St=je,Xt=je;else if(Me){St=ae||Ue||m;const ps=m&&x&&x.type==="text";Xt=St&&!ps}const _o=Math.min(24/b,C-K*3),Bl=J&&m&&x&&r.isShapeOfType(x,"text")&&_o*b>=4;return d.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsxs("g",{ref:o,children:[U&&d.jsx("rect",{className:"tl-selection__fg__outline",width:N(k),height:N(C)}),d.jsx(Gd,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:F,corner:"top_left_rotate",cursor:y?Yn("nwse-rotate",t):void 0,isHidden:Ae}),d.jsx(Gd,{"data-testid":"selection.rotate.top-right",cx:k+F*3,cy:0,targetSize:F,corner:"top_right_rotate",cursor:y?Yn("nesw-rotate",t):void 0,isHidden:Ae}),d.jsx(Gd,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:C+F*3,targetSize:F,corner:"bottom_left_rotate",cursor:y?Yn("swne-rotate",t):void 0,isHidden:Ae}),d.jsx(Gd,{"data-testid":"selection.rotate.bottom-right",cx:k+F*3,cy:C+F*3,targetSize:F,corner:"bottom_right_rotate",cursor:y?Yn("senw-rotate",t):void 0,isHidden:Ae}),d.jsx(BV,{"data-testid":"selection.rotate.mobile",cx:_?-F*1.5:k/2,cy:_?C/2:-F*1.5,size:I,isHidden:at}),d.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-(M?K*2:K)),width:N(k),height:N(Math.max(1,K*2)),style:y?{cursor:Yn("ns-resize",t)}:void 0,...i}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Xt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(k-(_?0:W)),y:0,height:N(C),width:N(Math.max(1,W*2)),style:y?{cursor:Yn("ew-resize",t)}:void 0,...a}),d.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-(M?0:K)),width:N(k),height:N(Math.max(1,K*2)),style:y?{cursor:Yn("ns-resize",t)}:void 0,...l}),d.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:y?{cursor:Yn("ew-resize",t)}:void 0,...c}),d.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-(M?K*2:K*1.5)),width:N(W*3),height:N(K*3),style:y?{cursor:Yn("nwse-resize",t)}:void 0,...u}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Gn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(k-(_?0:W*1.5)),y:N(0-(M?K*2:K*1.5)),width:N(W*3),height:N(K*3),style:y?{cursor:Yn("nesw-resize",t)}:void 0,...h}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Cn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(k-(_?W:W*1.5)),y:N(C-(M?K:K*1.5)),width:N(W*3),height:N(K*3),style:y?{cursor:Yn("nwse-resize",t)}:void 0,...p}),d.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-(M?0:K*1.5)),width:N(W*3),height:N(K*3),style:y?{cursor:Yn("nesw-resize",t)}:void 0,...f}),Me&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:ce("tl-corner-handle",{"tl-hidden":Ne}),"aria-label":"top_left handle",x:N(0-I/2),y:N(0-I/2),width:N(I),height:N(I)}),d.jsx("rect",{"data-testid":"selection.resize.top-right",className:ce("tl-corner-handle",{"tl-hidden":Gn}),"aria-label":"top_right handle",x:N(k-I/2),y:N(0-I/2),width:N(I),height:N(I)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ce("tl-corner-handle",{"tl-hidden":Cn}),"aria-label":"bottom_right handle",x:N(k-I/2),y:N(C-I/2),width:N(I),height:N(I)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ce("tl-corner-handle",{"tl-hidden":Rt}),"aria-label":"bottom_left handle",x:N(0-I/2),y:N(C-I/2),width:N(I),height:N(I)})]}),Bl&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:N(0-I/4),y:N(C/2-_o/2),rx:I/4,width:N(I/2),height:N(_o)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:I/4,x:N(k-I/4),y:N(C/2-_o/2),width:N(I/2),height:N(_o)})]}),X&&d.jsx(FV,{size:I,width:k,height:C,hideAlternateHandles:je})]})})}),Gd=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=ro(o);return d.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})},zV=Math.sqrt(Math.PI),BV=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=ro("mobile_rotate"),a=B(),l=G("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return d.jsxs("g",{children:[d.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}),d.jsx("circle",{className:ce("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/zV})]})};function UV(){const e=B();return G("is in a valid select state",()=>e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle"),[e])?d.jsx(oT,{}):null}function Pv(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(),u=ff(e,n,"start"),h=ff(e,n,"end"),p=e.getShapePageTransform(n);KC(a,s.start,p,h),KC(i,s.end,p,u);let f=0,y=0,m=0,x=0,S=Wa*n.props.scale;const v=u&&h&&u.shape===h.shape,b=u&&h?r0(e,u.shape.id,h.shape.id):"safe";b==="safe"&&u&&h&&!v&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.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),k=w.Len(E)?E.uni():w.From(E),C=!w.Equals(k,c);v||(b!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=Ms[n.props.size]/2+("size"in u.shape.props?Ms[u.shape.props.size]/2:0),f=(gf+m)*n.props.scale,S+=m*n.props.scale),b!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(x=Ms[n.props.size]/2+("size"in h.shape.props?Ms[h.shape.props.size]/2:0),y=(gf+x)*n.props.scale,S+=x*n.props.scale));const I=i.clone().add(k.clone().mul(f*(C?-1:1))),T=a.clone().sub(k.clone().mul(y*(C?-1:1)));w.DistMin(I,T,S)&&(f!==0&&y!==0?(f*=-1.5,y*=-1.5):f!==0?f*=-1:y!==0&&(y*=-1)),i.add(k.clone().mul(f*(C?-1:1))),a.sub(k.clone().mul(y*(C?-1:1))),C?(u&&h&&a.setTo(w.Add(i,k.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 KC(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,u=(l?Ww:DW)(i,a,r.outline);let h;if(u!==null&&(h=u.sort((y,m)=>w.Dist2(y,i)-w.Dist2(m,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 HV(e,n,t){const{arrowheadEnd:r,arrowheadStart:o}=n.props,s=n.props.bend;if(Math.abs(s)>Math.abs(n.props.bend*(YV*n.props.scale)))return Pv(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),u=w.Add(a,c.per().mul(-s)),h=ff(e,n,"start"),p=ff(e,n,"end"),f=i.start.clone(),y=i.end.clone(),m=u.clone();if(w.Equals(f,y))return{bindings:t,isStraight:!0,start:{handle:f,point:f,arrowhead:n.props.arrowheadStart},end:{handle:y,point:y,arrowhead:n.props.arrowheadEnd},middle:m,isValid:!1,length:0};const x=n.props.bend<0,S=x?Ou:F_,v=WC(f,y,m),b=w.Angle(v.center,f),E=w.Angle(v.center,y),k=S(b,E);if(v.length===0||v.size===0||!Z1(v.length)||!Z1(v.size))return Pv(e,n,t);const C=f.clone(),I=y.clone(),T=m.clone(),O=e.getShapePageTransform(n);let _=0,M=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,I),ye=oe.Inverse(h.transform),Me=oe.applyToPoint(ye,X),ae=oe.applyToPoint(ye,J),Ue=oe.applyToPoint(ye,le),{isClosed:je}=h,et=je?vv:EC;let Ae,at=et(ae,v.radius,h.outline);if(at){const Ne=ae.angle(Me),Gn=ae.angle(Ue),Rt=S(Ne,Gn);at=at.filter(St=>S(Ne,ae.angle(St))<=Rt);const Cn=Rt*.25;at.sort(je?(St,Xt)=>Math.abs(S(Ne,ae.angle(St))-Cn)<Math.abs(S(Ne,ae.angle(Xt))-Cn)?-1:1:(St,Xt)=>S(Ne,ae.angle(St))<S(Ne,ae.angle(Xt))?-1:1),Ae=at[0]??(je?void 0:Me)}else Ae=je?void 0:Me;if(Ae&&(C.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(h.transform,Ae))),h.didIntersect=!0,o!=="none")){const Ne=Ms[n.props.size]/2+("size"in h.shape.props?Ms[h.shape.props.size]/2:0);_=(gf+Ne)*n.props.scale,L+=Ne*n.props.scale}}if(p&&!p.isExact){const X=oe.applyToPoint(O,C),J=oe.applyToPoint(O,I),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),je=p.isClosed,et=je?vv:EC;let Ae,at=et(ae,v.radius,p.outline);if(at){const Ne=ae.angle(Me),Gn=ae.angle(Ue),Rt=S(Ne,Gn),Cn=Rt*.75;at=at.filter(St=>S(Ne,ae.angle(St))<=Rt),at.sort(je?(St,Xt)=>Math.abs(S(Ne,ae.angle(St))-Cn)<Math.abs(S(Ne,ae.angle(Xt))-Cn)?-1:1:(St,Xt)=>S(Ne,ae.angle(St))<S(Ne,ae.angle(Xt))?-1:1),at[0]?Ae=at[0]:Ae=je?void 0:Ue}else Ae=je?void 0:Ue;if(Ae&&(I.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(p.transform,Ae))),p.didIntersect=!0,r!=="none")){const Ne=Ms[n.props.size]/2+("size"in p.shape.props?Ms[p.shape.props.size]/2:0);M=(gf+Ne)*n.props.scale,L+=Ne*n.props.scale}}let j=w.Angle(v.center,C),R=w.Angle(v.center,I),F=S(j,R),W=F*v.radius;const K=C.clone(),z=I.clone();if(_!==0&&K.setTo(v.center).add(w.FromAngle(j+F*(_/W*(x?1:-1))).mul(v.radius)),M!==0&&z.setTo(v.center).add(w.FromAngle(R+F*(M/W*(x?-1:1))).mul(v.radius)),w.DistMin(K,z,L)&&(_!==0&&M!==0?(_*=-1.5,M*=-1.5):_!==0?_*=-2:M!==0&&(M*=-2)),_!==0&&C.setTo(v.center).add(w.FromAngle(j+F*(_/W*(x?1:-1))).mul(v.radius)),M!==0&&I.setTo(v.center).add(w.FromAngle(R+F*(M/W*(x?-1:1))).mul(v.radius)),h&&p&&!h.isExact&&!p.isExact){j=w.Angle(v.center,C),R=w.Angle(v.center,I),F=S(j,R),W=F*v.radius;const X=r0(e,h.shape.id,p.shape.id);X==="double-bound"&&W<30?(C.setTo(f),I.setTo(y),T.setTo(m)):X==="safe"&&(h&&!h.didIntersect&&C.setTo(f),(p&&!p.didIntersect||S(b,j)>S(b,R))&&I.setTo(v.center).add(w.FromAngle(j+F*(Math.min(.9,Wa*n.props.scale/W)*(x?1:-1))).mul(v.radius)))}KV(v.center,v.radius,C,I,T,k,x),C.equals(I)&&(C.setTo(T.clone().addXY(1,1)),I.setTo(T.clone().subXY(1,1))),f.setTo(C),y.setTo(I),m.setTo(T);const U=WC(f,y,m);return{bindings:t,isStraight:!1,start:{point:f,handle:i.start,arrowhead:n.props.arrowheadStart},end:{point:y,handle:i.end,arrowhead:n.props.arrowheadEnd},middle:m,handleArc:v,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function WC(e,n,t){const r=Gx(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,u=+(ke>c),h=(Re-c)*(s?1:-1),p=h*o;return{center:r,radius:o,size:h,length:p,largeArcFlag:u,sweepFlag:s}}function KV(e,n,t,r,o,s,i){const a=w.Angle(e,t),l=w.Angle(e,r);let c=Ou(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,ke);const u=r.clone();r.setTo(t),t.setTo(u)}}const WV=8;function GV(e){return Math.abs(e.props.bend)<WV*e.props.scale}function ff(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 Kr?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function GC(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 An(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 VV=k8("arrow info",(e,n)=>{const t=An(e,n);return GV(n)?Pv(e,n,t):HV(e,n,t)});function uo(e,n){const t=typeof n=="string"?n:n.id;return VV.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?GC(e,r,t.start,o==="double-bound"||o==="start-contains-end"):w.From(n.props.start),i=t.end?GC(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 Fh(e,n,t){const r=e.getBindingsFromShape(n,"arrow").filter(o=>o.props.terminal===t);e.deleteBindings(r)}const Wa=10,gf=10,YV=10,Ms={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 Nh extends Lh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:n}){sy(this.editor,this.editor.getShape(n.fromId))}onAfterChange({bindingAfter:n}){sy(this.editor,this.editor.getShape(n.fromId))}onAfterChangeFromShape({shapeAfter:n}){sy(this.editor,n)}onAfterChangeToShape({binding:n}){G2(this.editor,n.fromId)}onBeforeIsolateFromShape({binding:n}){const t=this.editor.getShape(n.fromId);t&&mf({editor:this.editor,arrow:t,terminal:n.props.terminal})}}g(Nh,"type","arrow"),g(Nh,"props",s_),g(Nh,"migrations",i_);function G2(e,n){var x;const t=e.getShape(n);if(!t)return;const r=An(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 S=(x=i||a)==null?void 0:x.parentId;S&&S===t.parentId?c=t.parentId:c=l}else return;c&&c!==t.parentId&&e.reparentShapes([n],c);const u=e.getShape(n);if(!u)throw Error("no reparented arrow");const h=e.getShapeNearestSibling(u,i),p=e.getShapeNearestSibling(u,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 y;const m=e.getSortedChildIdsForParent(f.parentId).map(S=>e.getShape(S)).filter(S=>S.index>f.index);if(m.length){const S=m.find(v=>v.type!=="arrow");if(u.index>f.index&&(!S||u.index<S.index))return;y=Gc(f.index,m[0].index)}else y=No(f.index);y!==u.index&&e.updateShapes([{id:n,type:"arrow",index:y}])}function sy(e,n){const t=An(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)&&mf({editor:e,arrow:n,terminal:r,unbind:!0})}G2(e,n.id)}function mf({editor:e,arrow:n,terminal:t,unbind:r=!1,useHandle:o=!1}){const s=uo(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 u=t==="start"?i:s.start.handle,h=t==="end"?a:s.end.handle,p=w.Med(u,h),f=w.Sub(u,h).per().uni().mul(s.handleArc.radius*2*Math.sign(n.props.bend)),y=Uu(s.handleArc.center,w.Add(p,f),s.handleArc.center,s.handleArc.radius);st((y==null?void 0:y.length)===1);const m=w.Dist(p,y[0])*Math.sign(n.props.bend);Ds(m,c.props.bend)||(c.props.bend=m)}e.updateShape(c),r&&Fh(e,n,t)}const V2=[Nh],Wt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},jt={s:2,m:3.5,l:5,xl:10},yl={s:18,m:24,l:36,xl:44},Yo={s:18,m:22,l:26,xl:32},XV={s:18,m:20,l:24,xl:28},yo={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},qV=20,ZV=4.25,Lr=16;/*!
110
+ * canvas-size
111
+ * v1.2.6
112
+ * https://github.com/jhildenbiddle/canvas-size
113
+ * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
114
+ * MIT license
115
+ */function QV(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(u){c=!0,o=u}finally{try{if(!l&&t.return!=null&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function VC(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 Xn(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?VC(Object(t),!0).forEach(function(r){JV(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):VC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function JV(e,n,t){return n=lY(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function eY(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 tY(e,n){if(e==null)return{};var t=eY(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 YC(e,n){return rY(e)||QV(e,n)||Y2(e,n)||iY()}function Vd(e){return nY(e)||oY(e)||Y2(e)||sY()}function nY(e){if(Array.isArray(e))return Cv(e)}function rY(e){if(Array.isArray(e))return e}function oY(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 Cv(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 Cv(e,n)}}function Cv(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 sY(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
116
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function iY(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
117
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function aY(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 lY(e){var n=aY(e,"string");return typeof n=="symbol"?n:String(n)}function Bc(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"),u=l.getContext("2d");u&&(u.fillRect.apply(u,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&&Bc(e)):h?e.onSuccess(t,r,p):(e.onError(t,r,p),e.sizes.length&&Bc(e)),h}var iy={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]},cY=["onError","onSuccess"],Ga={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},uc={};function ay(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(u){var h=n||t?u:1,p=n||r?u: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 Yd(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=tY(e,cY),a=null;if(!n)return!1;if(e.useWorker&&t){var l=`
118
+ var canvasTest = `.concat(Bc.toString(),`;
119
+ onmessage = function(e) {
120
+ canvasTest(e.data);
121
+ };
122
+ `),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(h){var p=h.data,f=p.width,y=p.height,m=p.benchmark,x=p.isTestPass;x?(uc[r].onSuccess(f,y,m),delete uc[r]):uc[r].onError(f,y,m)}}if(e.usePromise)return new Promise(function(h,p){var f=Xn(Xn({},e),{},{onError:function(S,v,b){var E;if(e.sizes.length===0)E=!0;else{var k=e.sizes.slice(-1),C=YC(k,1),I=YC(C[0],2),T=I[0],O=I[1];E=S===T&&v===O}o(S,v,b),E&&p({width:S,height:v,benchmark:b})},onSuccess:function(S,v,b){s(S,v,b),h({width:S,height:v,benchmark:b})}});if(a){var y=f.onError,m=f.onSuccess;uc[r]={onError:y,onSuccess:m},a.postMessage(i)}else Bc(f)});if(a)uc[r]={onError:o,onSuccess:s},a.postMessage(i);else return Bc(e)}var ly={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ay({width:n.max,height:n.max,min:n.min,step:n.step,sizes:Vd(iy.area)}),r=Xn(Xn(Xn({},Ga),n),{},{sizes:t});return Yd(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ay({width:1,height:n.max,min:n.min,step:n.step,sizes:Vd(iy.height)}),r=Xn(Xn(Xn({},Ga),n),{},{sizes:t});return Yd(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ay({width:n.max,height:1,min:n.min,step:n.step,sizes:Vd(iy.width)}),r=Xn(Xn(Xn({},Ga),n),{},{sizes:t});return Yd(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Xn(Xn({},Ga),n);return t.sizes=Vd(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),Yd(t)}};let cy=null;function uY(){return cy||(cy=dY()),cy}async function dY(){const e=await ly.maxWidth({usePromise:!0}),n=await ly.maxHeight({usePromise:!0}),t=await ly.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const XC=8192,hY=4096*4096;async function pY(e,n){if(e<=XC&&n<=XC&&e*n<=hY)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await uY(),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 fY(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 gY(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function mY(e){const n=new URL(e).host.replace("www.","");for(const t of ju)if(X2(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const yY=e=>e.split("*").map(n=>gY(n)).join(".+"),X2=(e,n)=>!!e.find(t=>{const r=new RegExp(yY(t));return n.match(r)});function SY(e){const n=new URL(e).host.replace("www.","");for(const t of ju)if(X2(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function q2(e){return SY(e)??mY(e)}function As(e){try{return q2(e)}catch(n){console.error(n)}}/*!
123
+ * MIT License
124
+ * Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
125
+ * Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
126
+ */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(`
127
+ `,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(`
128
+ `,t-1)+1,c=n.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${Va}`),h=u.length-c.length;n.setSelectionRange(l,r-1),pn.insert(n,u),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(`
129
+ `,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 u=/\t| {1,2}/.exec(o.slice(s,t)),h=u?u[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=Xd(n)??0,s=Xd(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(`
130
+ `,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${Va}`).length-u.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=Xd(n)??0,s=Xd(n)??0,i=r.lastIndexOf(`
131
+ `,o-1)+1,a=pn.findLineEnd(r,s),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=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-u))}}static normalizeText(n){return n.replace(pn.fixNewLines,`
132
+ `)}static normalizeTextForDom(n){return n.replace(pn.fixNewLines,`
133
+ `).split(`
134
+ `).map(t=>t||" ").join(`
135
+ `)}};g(pn,"fixNewLines",/\r?\n|\r/g);let Sl=pn;function Xd(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 vY=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function Z2(e){return vY.test(e)}function xY(e){return e.replace(/\t/g,Va)}function wY(e){const n=e.split(`
136
+ `);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(`
137
+ `)}function bY(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function PY(e){return bY(wY(xY(e)))}function CY(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 u=l;const h=r.includes(u.type),p=o.includes(u.type);!h&&!p&&s.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),st(h||p,`File type not allowed: ${u.type}`),u.size>t&&s.addToast({title:i("assets.files.size-too-big"),severity:"error"}),st(u.size<=t,`File size too big: ${(u.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),u.type==="video/quicktime"&&(u=new Blob([u],{type:"video/mp4"}));let f=h?await lo.getImageSize(u):await lo.getVideoSize(u);const y=await lo.isAnimated(u)||p,m=await M4(await u.arrayBuffer());if(isFinite(n)){const v=fY(f,{w:n,h:n});f!==v&&lo.isStaticImageType(u.type)&&(f=v)}const x=Ci.createId(m),S={id:x,type:h?"image":"video",typeName:"asset",props:{name:c,src:"",w:f.w,h:f.h,fileSize:u.size,mimeType:u.type,isAnimated:y}};return a?(S.props.src=x,await TV({persistenceKey:a,assetId:x,blob:u})):S.props.src=await Ai.blobToDataUrl(u),Ci.create(S)}),e.registerExternalAssetHandler("url",async({url:l})=>{var u,h,p,f,y;let c;try{const x=await(await So(l,{method:"GET",mode:"no-cors"})).text(),S=new DOMParser().parseFromString(x,"text/html");c={image:((u=S.head.querySelector('meta[property="og:image"]'))==null?void 0:u.getAttribute("content"))??"",favicon:((h=S.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:h.getAttribute("href"))??((p=S.head.querySelector('link[rel="icon"]'))==null?void 0:p.getAttribute("href"))??"",title:((f=S.head.querySelector('meta[property="og:title"]'))==null?void 0:f.getAttribute("content"))??l,description:((y=S.head.querySelector('meta[property="og:description"]'))==null?void 0:y.getAttribute("content"))??""},c.image.startsWith("http")||(c.image=new URL(c.image,l).href),c.favicon.startsWith("http")||(c.favicon=new URL(c.favicon,l).href)}catch(m){console.error(m),s.addToast({title:i("assets.url.failed"),severity:"error"}),c={image:"",favicon:"",title:"",description:""}}return{id:Ci.createId(hS(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 u=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 m=h.getBoundingClientRect();document.body.removeChild(h),p=m.width,f=m.height}const y=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});if(!y)throw Error("Could not create an asset");qC(e,[y],u)}),e.registerExternalContentHandler("embed",({point:l,url:c,embed:u})=>{const h=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),{width:p,height:f}=u,y=$e(),m={id:y,type:"embed",x:h.x-(p||450)/2,y:h.y-(f||450)/2,props:{w:p,h:f,url:c}};e.createShapes([m]).select(y)}),e.registerExternalContentHandler("files",async({point:l,files:c})=>{const u=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=new w(u.x,u.y),p=[];await Promise.all(c.map(async(f,y)=>{if(f.size>t)return s.addToast({title:i("assets.files.size-too-big"),severity:"error"}),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 s.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),console.warn(`${f.name} not loaded - Extension not allowed.`),null;try{const m=await e.getAssetForExternalContent({type:"file",file:f});if(!m)throw Error("Could not create an asset");p[y]=m}catch(m){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(m),null}})),qC(e,me(p),h)}),e.registerExternalContentHandler("text",async({point:l,text:c})=>{const u=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=e.getShapeUtil("text").getDefaultProps(),p=PY(c),f=e.getOnlySelectedShape();if(f&&"text"in f.props){e.updateShapes([{id:f.id,type:f.type,props:{text:p}}]);return}let y,m,x,S="middle";const v=p.split(`
138
+ `).length>1,b=Z2(p);v&&(S=v?b?"end":"start":"middle");const E=e.textMeasure.measureText(p,{...Wt,fontFamily:yo[h.font],fontSize:yl[h.size],maxWidth:null}),k=Math.min(v?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(E.w>k){const C=e.textMeasure.measureText(p,{...Wt,fontFamily:yo[h.font],fontSize:yl[h.size],maxWidth:k});y=C.w,m=C.h,x=!1,S=b?"end":"start"}else y=E.w,m=E.h,x=!0;u.y-m/2<e.getViewportPageBounds().minY+40&&(u.y=e.getViewportPageBounds().minY+40+m/2),e.createShapes([{id:$e(),type:"text",x:u.x-y/2,y:u.y-m/2,props:{text:p,textAlign:S,autoSize:x,w:y}}])}),e.registerExternalContentHandler("url",async({point:l,url:c})=>{const u=As(c);if(u)return e.putExternalContent({type:"embed",url:u.url,point:l,embed:u.definition});const h=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),p=Ci.createId(hS(c)),f=IY(e,c,h);let y=e.getAsset(p),m=!1;if(!y){m=!0;try{const x=await e.getAssetForExternalContent({type:"url",url:c});if(!x)throw Error("Could not create an asset");y=x}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{m&&e.createAssets([y]),e.updateShapes([{id:f.id,type:f.type,props:{assetId:y.id}}])})})}async function qC(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 IY(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 EY=new qo,kY=e=>async n=>!n||!n.props.src?null:e&&n.props.src.startsWith("asset:")?await EY.get(n,async()=>await _Y(e,n.id)):n.type==="video"?n.props.src:n.type!=="image"?null:n.props.src;async function _Y(e,n){const t=await _V({assetId:n,persistenceKey:e});return t?URL.createObjectURL(t):null}var Dy;let TY=(Dy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")});g(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}))}})}},g(Dy,"id","idle"),Dy);var Ry;let MY=(Ry=class extends se{constructor(){super(...arguments);g(this,"shape");g(this,"markId","");g(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()});g(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});g(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"})}});g(this,"onPointerUp",()=>{this.cancel()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()});g(this,"preciseTimeout",-1);g(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u;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=(u=i.onHandleDrag)==null?void 0:u.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(u=>u.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"),u=(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});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},g(Ry,"id","pointing"),Ry);class zh extends se{constructor(){super(...arguments);g(this,"shapeType","arrow")}}g(zh,"id","arrow"),g(zh,"initial","idle"),g(zh,"children",()=>[TY,MY]);class o0 extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"initialShape");g(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");g(this,"util",this.editor.getShapeUtil(this.shapeType));g(this,"isPen",!1);g(this,"isPenOrStylus",!1);g(this,"segmentMode","free");g(this,"didJustShiftClickToExtendPreviousShapeLine",!1);g(this,"pagePointWhereCurrentSegmentChanged",{});g(this,"pagePointWhereNextSegmentChanged",null);g(this,"lastRecordedPoint",{});g(this,"mergeNextPoint",!1);g(this,"currentLineLength",0);g(this,"canDraw",!1);g(this,"markId",null);g(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()});g(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())});g(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()});g(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()});g(this,"onExit",()=>{this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())})}canClose(){return this.shapeType!=="highlight"}getIsClosed(t,r,o){if(!this.canClose())return!1;const s=jt[r],i=t[0].points[0],a=t[t.length-1],l=a.points[a.points.length-1];return i!==l&&this.currentLineLength>s*4*o&&w.DistMin(i,l,s*2*o)}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:u,y:h}=this.editor.getPointInShapeSpace(a,t).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+s.toFixed(2)},{x:u,y:h,z:+s.toFixed(2)}]},f=oe.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const y=[...a.props.segments,p];this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(y));const m={id:a.id,type:this.shapeType,props:{segments:y}};this.canClose()&&(m.props.isClosed=this.getIsClosed(y,a.props.size,a.props.scale)),this.editor.updateShapes([m]);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,scale:i}}=t,a=this.editor.getShape(o);if(!a)return;const{segments:l}=a.props,{x:c,y:u,z:h}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),p=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,f={x:c,y:u,z:p};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:y}=this;if(y===null)throw Error("We should have a point where the segment changed");if(w.Dist2(y,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const x=Nt(l);if(!x)throw Error("Expected a previous segment!");const S=Nt(x.points);if(!S)throw Error("Expected a previous last point!");let v;const b=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(x.type==="straight"){this.currentLineLength+=w.Dist(S,b),v={type:"straight",points:[{...S},b]};const k=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(k,S)}else v={type:"straight",points:[b,f]};const E={id:o,type:this.shapeType,props:{segments:[...l,v]}};this.canClose()&&(E.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([E])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:y}=this;if(y===null)throw Error("We should have a point where the segment changed");if(w.Dist2(y,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const x=l.slice(),S=x[x.length-1],v=Nt(S.points);if(!v)throw Error("No previous point!");const b={type:"free",points:[...w.PointsBetween(v,f,6).map(C=>({x:zo(C.x),y:zo(C.y),z:zo(C.z)}))]},E=[...x,b];this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(E));const k={id:o,type:this.shapeType,props:{segments:E}};this.canClose()&&(k.props.isClosed=this.getIsClosed(E,s,i)),this.editor.updateShapes([k])}break}case"straight":{const y=l.slice(),m=y[y.length-1],{pagePointWhereCurrentSegmentChanged:x}=this,{ctrlKey:S,currentPagePoint:v}=this.editor.inputs;if(!x)throw Error("We should have a point where the segment changed");let b,E=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(E=!S,this.didJustShiftClickToExtendPreviousShapeLine=!1):E=!S;let k=this.editor.getPointInShapeSpace(a,v).toFixed().toJson(),C=!1,I;if((this.editor.user.getIsSnapMode()?!S:S)&&y.length>2){let _,M=8/this.editor.getZoomLevel();for(let L=0,j=l.length-2;L<j;L++){const R=l[L];if(!R)break;if(R.type==="free")continue;const F=R.points[0],W=Nt(R.points);if(!(F&&W))continue;const K=w.NearestPointOnLineSegment(F,W,k);if(w.DistMin(K,k,M)){_=K.toFixed().toJson(),M=w.Dist(K,k),I=R;break}}_&&(C=!0,k=_)}if(C&&I){const _=this.editor.getShapePageTransform(a),M=I.points[0],L=Nt(I.points);if(!L)throw Error("Expected a last point!");const j=oe.applyToPoint(_,M),R=oe.applyToPoint(_,L),F=oe.applyToPoint(_,k);this.editor.snaps.setIndicators([{id:ot(),type:"points",points:[j,F,R]}])}else{if(this.editor.snaps.clearIndicators(),E){const _=w.Angle(x,v),L=Np(_,24)-_;b=w.RotWith(v,x,L)}else b=v;k=this.editor.getPointInShapeSpace(a,b).toFixed().toJson()}this.currentLineLength+=w.Dist(m.points[0],k),y[y.length-1]={...m,type:"straight",points:[m.points[0],k]};const O={id:o,type:this.shapeType,props:{segments:y}};this.canClose()&&(O.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([O]);break}case"free":{const y=l.slice(),m=y[y.length-1],x=[...m.points];if(x.length&&this.mergeNextPoint){const{z:v}=x[x.length-1];x[x.length-1]={x:f.x,y:f.y,z:v?Math.max(v,f.z):f.z}}else this.currentLineLength+=w.Dist(x[x.length-1],f),x.push(f);y[y.length-1]={...m,points:x},this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(y));const S={id:o,type:this.shapeType,props:{segments:y}};if(this.canClose()&&(S.props.isClosed=this.getIsClosed(y,s,i)),this.editor.updateShapes([S]),x.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const v=$e(),b=this.editor.getShape(o).props;this.editor.createShapes([{id:v,type:this.shapeType,x:zo(r.currentPagePoint.x),y:zo(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:b.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(h*1.25).toFixed():.5}]}]}}]),this.initialShape=rt(this.editor.getShape(v)),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)}}g(o0,"id","drawing");var Ly;let J2=(Ly=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("drawing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Ly,"id","idle"),Ly);class Bh extends se{constructor(){super(...arguments);g(this,"shapeType","draw");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Bh,"id","draw"),g(Bh,"initial","idle"),g(Bh,"children",()=>[J2,o0]);class Iv extends $h{constructor(){super(...arguments);g(this,"shapeType","frame");g(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)&&AY(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")})}}g(Iv,"id","frame"),g(Iv,"initial","idle");function AY(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var $y;let jY=($y=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(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}))}});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g($y,"id","idle"),$y);var Fy;let OY=(Fy=class extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onPointerUp",()=>{this.complete()});g(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(zr),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"})}});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(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(zr),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(zr),scale:o,...i}}]);const a=this.editor.getShape(r);if(!a)return;const{w:l,h:c}=a.props,u=new w(l/2,c/2).mul(o),h=this.editor.getShapeParentTransform(a);h&&u.rot(-h.rotation()),this.editor.select(r),this.editor.updateShape({id:a.id,type:"geo",x:a.x-u.x,y:a.y-u.y,props:{geo:this.editor.getStyleForNextShape(zr),w:l*o,h:c*o}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},g(Fy,"id","pointing"),Fy);class Uh extends se{constructor(){super(...arguments);g(this,"shapeType","geo")}}g(Uh,"id","geo"),g(Uh,"initial","idle"),g(Uh,"children",()=>[jY,OY]);class Hh extends se{constructor(){super(...arguments);g(this,"shapeType","highlight");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Hh,"id","highlight"),g(Hh,"initial","idle"),g(Hh,"children",()=>[J2,o0]);var Ny;let DY=(Ny=class extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"onEnter",t=>{this.shapeId=t.shapeId,this.editor.setCursor({type:"cross",rotation:0})});g(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Ny,"id","idle"),Ny);const ZC=2;var zy;let RY=(zy=class extends se{constructor(){super(...arguments);g(this,"shape",{});g(this,"markId");g(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],u=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new w(this.shape.x,this.shape.y)),h=w.Sub(o,u).addXY(.1,.1),p=rt(this.shape.props.points);if(w.DistMin(l,c,ZC)||w.DistMin(h,l,ZC))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=No(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)}});g(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"})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(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()}},g(zy,"id","pointing"),zy);class Kh extends se{constructor(){super(...arguments);g(this,"shapeType","line")}}g(Kh,"id","line"),g(Kh,"initial","idle"),g(Kh,"children",()=>[DY,RY]);var By;let LY=(By=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(By,"id","idle"),By);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=eA(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 eA(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 u=e.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:p}=e.getShapeGeometry(l);if(!h.some(f=>nr(f,u))){if(p){if(I2(u,h))continue}else if($W(u,h))continue;a.push(l)}}return a}function yf(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}),tA(e)}const $Y=16;function tA(e){const n=e.getSelectionPageBounds(),t=e.getViewportPageBounds();if(n&&!t.contains(n)){const r=n.clone().expandBy($Y/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,FY=0,Be=200,gg=new w(Be/2,Be/2),nA=10,NY=[[["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 zY(e){if(e===1)return NY;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 rA(e,n,t,r,o){return Object.fromEntries(zY(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 oA(e,n,t,r){const o=new Set(e.getSelectedShapeIds()),s=(Be+_i+r)**2,i=new Map,a=[];for(const u of e.getCurrentPageShapes()){if(!e.isShapeOfType(u,"note")||t!==u.props.scale||o.has(u.id))continue;const h=e.getShapePageTransform(u.id);n===h.rotation()&&(i.set(u,e.getShapePageBounds(u).center),a.push(...Object.values(rA(h.point(),n,u.props.growY,r,t))))}const l=a.length;let c;for(const[u,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(w.Dist2(h,c)>s||e.isPointInShape(u,c)&&(a[p]=void 0));return me(a)}function sA(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 u=e.getShapePageBounds(c);if(u&&w.Dist2(u.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 u=e.getPointInParentSpace(c,w.Sub(t,w.Rot(gg.clone().mul(c.props.scale),r)));e.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=e.getShape(l)}return tA(e),s}var Uy;let BY=(Uy=class extends se{constructor(){super(...arguments);g(this,"dragged",!1);g(this,"info",{});g(this,"wasFocusedOnEnter",!1);g(this,"markId","");g(this,"shape",{});g(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=QC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=JC(this.editor,r,o)}});g(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=$e(),o=this.editor.inputs.originPagePoint.clone(),s=QC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=JC(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")}})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(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)}},g(Uy,"id","pointing"),Uy);function QC(e,n,t){let r=nA/e.getZoomLevel(),o;for(const s of oA(e,0,t,0)){const i=w.Sub(n,s),a=i.len();a<r&&(r=a,o=i)}return o}function JC(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 Wh extends se{constructor(){super(...arguments);g(this,"shapeType","note")}}g(Wh,"id","note"),g(Wh,"initial","idle"),g(Wh,"children",()=>[LY,BY]);function UY(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 Ko=gk(UY,32);var Hy;let HY=(Hy=class extends se{constructor(){super(...arguments);g(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Ko(this.editor)}});g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onExit",()=>{Ko.cancel()});g(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}))}});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Hy,"id","idle"),Hy);var Ky;let KY=(Ky=class extends se{constructor(){super(...arguments);g(this,"shape");g(this,"markId","");g(this,"onExit",()=>{this.editor.setHintingShapes([])});g(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")}})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.cancel()});g(this,"onCancel",()=>{this.cancel()});g(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,_n(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}},g(Ky,"id","pointing"),Ky);class Gh extends se{constructor(){super(...arguments);g(this,"shapeType","text")}}g(Gh,"id","text"),g(Gh,"initial","idle"),g(Gh,"children",()=>[HY,KY]);const WY=[Gh,Bh,Uh,Wh,Kh,Iv,zh,Hh];function Mr(){return as({isDarkMode:Ku()})}function vl(e){return{key:`${vo.id}:${e}`,getElement:async()=>{const n=GY(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await So(t)).blob(),s=await Ai.blobToDataUrl(o),i=r.replace(t,s);return d.jsx("style",{children:i})}}}function GY(e){const n=t_[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function s0(e){return{key:`${vo.id}:${e}`,getElement:async()=>e!=="pattern"?null:d.jsx(VY,{})}}function VY(){const e=Mr(),n=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:"hash_pattern_mask",children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:n*1,y1:n*3,x2:n*3,y2:n*1}),d.jsx("line",{x1:n*5,y1:n*7,x2:n*7,y2:n*5}),d.jsx("line",{x1:n*9,y1:n*11,x2:n*11,y2:n*9})]})]}),d.jsx("pattern",{id:Sf(1,e.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function i0(){return{key:`${vo.id}:pattern`,component:ZY}}const Cc=8,eI=(e,n,t)=>new Promise((r,o)=>{const s=Cc*n*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?jp.darkMode.solid:jp.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=u=>u*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(u=>{!u||xt.throwToBlob.get()?o():r(u)})}),tI=(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 uy=null;function YY(){return uy||(uy={white:tI([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:tI([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),uy}function iA(e){return Math.ceil(Math.log2(Math.max(1,e)))}function Sf(e,n){const t=iA(e);return`tldraw_hash_pattern_${n}_${t}`}function aA(e){const n=[],r=iA(e);for(let o=0;o<=r;o++)n.push(Math.pow(2,o));return n}function XY(e){const n=YY();return aA(e).flatMap(t=>[{zoom:t,url:n.white,theme:"light"},{zoom:t,url:n.black,theme:"dark"}])}function qY(){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(()=>XY(t));return P.useEffect(()=>{const l=Promise.all(aA(t).flatMap(u=>[eI(n,u,!1).then(h=>({zoom:u,theme:"light",url:URL.createObjectURL(h)})),eI(n,u,!0).then(h=>({zoom:u,theme:"dark",url:URL.createObjectURL(h)}))]));let c=!1;return l.then(u=>{c||(i(u),o(!0))}),()=>{c=!0,o(!1),l.then(u=>{for(const{url:h}of u)URL.revokeObjectURL(h)})}},[n,t]),{defs:d.jsx(d.Fragment,{children:s.map(l=>{const c=Sf(l.zoom,l.theme);return d.jsx("pattern",{id:c,width:Cc,height:Cc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:l.url,width:Cc,height:Cc})},c)})}),isReady:r}}function ZY(){const e=B(),n=P.useRef(null),{defs:t,isReady:r}=qY();return P.useEffect(()=>{if(r&&e.environment.isSafari){const o=lA(n.current);o&&e.timers.requestAnimationFrame(()=>{o.style.display="none",e.timers.requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),d.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function lA(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?lA(e.parentElement):null}const en=we.memo(function({theme:n,d:t,color:r,fill:o,scale:s}){switch(o){case"none":return null;case"solid":return d.jsx("path",{fill:n[r].semi,d:t});case"semi":return d.jsx("path",{fill:n.solid,d:t});case"fill":return d.jsx("path",{fill:n[r].fill,d:t});case"pattern":return d.jsx(QY,{theme:n,color:r,fill:o,d:t,scale:s})}});function QY({d:e,color:n,theme:t}){const r=B(),o=M2(),s=G("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:t[n].pattern,d:e}),d.jsx("path",{fill:o?`url(#${Sf(1,t.id)})`:i?t[n].semi:`url(#${Sf(s,t.id)})`,d:e})]})}function JY(e){return e.replace(/\s/g," ")}function Ev(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:u}of n)a!==null&&u.y>a&&l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
139
+ `},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:JY(c)},l.length)),a=u.y;return d.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 eX(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 tX(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function mg({fontSize:e,font:n,align:t,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=B(),u=Mr(),h={fontSize:e,fontFamily:t_[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=eX(t,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const y=Ev(c,p,h);let m=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,m=Ev(c,p,h)),d.jsxs(d.Fragment,{children:[m,y]})}const nX=P.forwardRef(function({isEditing:n,text:t,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return d.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:Ht,onContextMenu:n?Ht:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:Ee})});function rX(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 u({shapeId:h}){var p;h===e&&((p=o.current)==null||p.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,e,s]),P.useEffect(()=>{var u,h,p,f;s&&(document.activeElement!==o.current&&((u=o.current)==null||u.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(u=>{if(r.getEditingShapeId()===e)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&r.complete();break}}},[r,e]),l=P.useCallback(u=>{if(r.getEditingShapeId()!==e)return;let h=Sl.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,Va);if(p!==h){const f=u.currentTarget.selectionStart;u.currentTarget.value=p,u.currentTarget.selectionStart=f+(p.length-h.length),u.currentTarget.selectionEnd=f+(p.length-h.length),h=p}r.updateShape({id:e,type:n,props:{text:h}})},[r,e,n]),c=P.useCallback(u=>{r.dispatch({...On(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Ht(u)},[r,e]);return{rInput:o,handleFocus:bp,handleBlur:bp,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Ht,isEmpty:t.trim().length===0,isEditing:s,isEditingAnything:i}}const yg=we.memo(function({id:n,type:t,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:y,style:m,textWidth:x,textHeight:S}){const{rInput:v,isEmpty:b,isEditing:E,isEditingAnything:k,...C}=rX(n,t,r),[I,T]=P.useState(r);P.useEffect(()=>{E||T(r)},[E,r]);const O=Sl.normalizeTextForDom(r),_=O.length>0,M=tX(l);if(!E&&!_)return null;const L=y||"tl-text";return d.jsx("div",{className:`${L}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!b,"data-isediting":E,"data-iseditinganything":k,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||M?"center":l,alignItems:c==="middle"?"center":c,padding:p,...m},children:d.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:S?Math.ceil(S):void 0},children:[d.jsx("div",{className:`${L} tl-text tl-text-content`,dir:"auto",children:O.split(`
140
+ `).map((j,R)=>d.jsx("div",{dir:"auto",children:j},R))}),(k||h)&&d.jsx(nX,{ref:v,text:r,isEditing:E,...C,handleKeyDown:f??C.handleKeyDown},I)]})})});function oo(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,u=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)),u=Math.floor(e/c/(2*h)),u-=u%o,u<3&&l==="dashed"?e/n<4?(c=e,u=1,p=0):(c=e*(1/3),p=e*(1/3)):(c=e/u/(2*h),r?(f=c/2,p=(e-u*c)/u):p=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}const nI=new WeakMap;function a0(e,n){const t=nI.get(n);if(t)return t;const r=uo(e,n);let o=0,s=0;const i=r.isStraight?new Ho({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=kv(n),{w:u,h}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:yo[n.props.font],fontSize:c,maxWidth:null});if(o=u,s=h,l.width>l.height){o=Math.max(Math.min(u,64),Math.min(l.width-64,u));const{w:p,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:yo[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:yo[n.props.font],fontSize:c,maxWidth:o});o=p,s=f}}const a=new w(o,s).addScalar(ZV*2*n.props.scale);return nI.set(n,a),a}function cA(e){const n=jt[e.props.size];return(qV+(n-jt.s)*2+(n===jt.xl?20:0))*e.props.scale}function oX(e,n,t){const r=a0(e,n),o=cA(n),s=w.Nudge(t.start.point,t.end.point,o),i=w.Nudge(t.end.point,t.start.point,o),a=Ww(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 u=s.add(w.Sub(t.middle,l)),h=i.add(w.Sub(t.middle,c)),p=w.Dist(t.start.point,u)/t.length,f=w.Dist(t.start.point,h)/t.length;return{start:p,end:f}}function sX(e,n,t){const r=a0(e,n),o=cA(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=Bi(t.bodyArc.center,t.bodyArc.radius,a),u=Bi(t.bodyArc.center,t.bodyArc.radius,l),h=[],p=rI(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=rI(t.bodyArc.center,t.bodyArc.radius,a,l,s,Z.FromCenter(u,r).corners);h.push(new vt({points:Z.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const I of[...p??[],...f??[],c,u])h.push(new t0({x:I.x-3,y:I.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const y=(p&&oI(t.start.point,p))??t.middle,m=(f&&oI(t.end.point,f))??t.middle,x=w.Angle(t.bodyArc.center,t.start.point),S=w.Angle(t.bodyArc.center,t.end.point),v=w.Angle(t.bodyArc.center,y),b=w.Angle(t.bodyArc.center,m);if(Cs(x,v,s)>Cs(x,b,s))return{start:.5,end:.5,dbg:h};const E=Cs(x,S,s),k=Cs(x,v,s)/E,C=Cs(x,b,s)/E;return{start:k,end:C,dbg:h}}function Vh(e,n){let t;const r=[],o=uo(e,n),s=!!o.bindings.start,i=!!o.bindings.end,a=o.start.arrowhead!=="none",l=o.end.arrowhead!=="none";if(o.isStraight){const u=oX(e,n,o);let h=_t(n.props.labelPosition,a||s?u.start:0,l||i?u.end:1);h=h>=.48&&h<=.52?.5:h,t=w.Lrp(o.start.point,o.end.point,h)}else{const u=sX(e,n,o);u.dbg&&r.push(...u.dbg);let h=_t(n.props.labelPosition,a||s?u.start:0,l||i?u.end:1);h=h>=.48&&h<=.52?.5:h;const p=iX(w.Angle(o.bodyArc.center,o.start.point),w.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),h);t=Bi(o.bodyArc.center,o.bodyArc.radius,p)}const c=a0(e,n);return{box:Z.FromCenter(t,c),debugGeom:r}}function rI(e,n,t,r,o,s){const i=vv(e,n,s),a=Cs(t,r,o);return i==null?void 0:i.filter(l=>{const c=Cs(t,w.Angle(e,l),o);return c>=0&&c<=a})}function oI(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 iX(e,n,t,r){const o=Cs(e,n,t);return e+o*r*t*-1}function kv(e){return XV[e.props.size]*e.props.scale}function aX(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=RW(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 lX({point:e,int:n}){const t=w.RotWith(n,e,ke/6),r=w.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function cX({point:e,int:n}){const t=w.RotWith(n,e,ke/6),r=w.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function uX({point:e,int:n}){const t=w.Sub(n,e).div(2),r=w.Add(e,w.Rot(t,Ge)),o=w.Sub(e,w.Rot(t,Ge));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function dX({point:e,int:n}){const t=w.Lrp(e,n,.45),r=w.Dist(t,e);return`M ${t.x-r},${t.y}
141
+ a ${r},${r} 0 1,0 ${r*2},0
142
+ a ${r},${r} 0 1,0 -${r*2},0 `}function hX({point:e,int:n}){const t=w.Lrp(e,n,.75),r=w.RotWith(t,e,ke/4),o=w.RotWith(t,e,-ke/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 pX({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,Ge)),s=w.Sub(n,w.Rot(r,Ge)),i=w.Add(t,w.Rot(r,Ge)),a=w.Sub(t,w.Rot(r,Ge));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function fX({int:e,point:n}){const t=w.Sub(e,n).div(2),r=w.Add(n,w.Rot(t,Ge)),o=w.Sub(n,w.Rot(t,Ge));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function vf(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=aX(e,n,t);if(o){switch(r){case"bar":return fX(o);case"square":return pX(o);case"diamond":return hX(o);case"dot":return dX(o);case"inverted":return uX(o);case"arrow":return lX(o);case"triangle":return cX(o)}return""}}function gX(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 uA(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 dA(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function mX(e){return dA(e.start.handle,e.end.handle)}function hA(e){return dA(e.start.point,e.end.point)}let yX=0;class Yh extends Hr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"canSnap",()=>!1);g(this,"hideResizeHandles",()=>!0);g(this,"hideRotateHandle",()=>!0);g(this,"hideSelectionBoundsBg",()=>!0);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"canBeLaidOut",t=>{const r=An(this.editor,t);return!r.start&&!r.end});g(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const s=r.id,i=An(this.editor,t);if(s==="middle"){const{start:C,end:I}=Ka(this.editor,t,i),T=w.Sub(I,C),O=w.Per(T),_=w.Med(I,C),M=w.Sub(_,O),L=w.Add(_,O),j=w.NearestPointOnLineSegment(M,L,r,!1);let R=w.Dist(j,_);return w.Clockwise(j,I,_)&&(R*=-1),{id:t.id,type:t.type,props:{bend:R}}}const a={id:t.id,type:"arrow",props:{}},l=i[s],u=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return Fh(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 Fh(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),y=Z.ZeroFix(f.bounds),x=this.editor.getShapePageTransform(a.id).applyToPoint(r),S=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),u&&p.id===u.toId&&u.props.isPrecise&&(v=!0));const b={x:(S.x-y.minX)/y.width,y:(S.y-y.minY)/y.height};v&&w.Dist(S,y.center)<Math.max(4,Math.min(Math.min(y.width,y.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 k=An(this.editor,t);return k.start&&k.end&&k.start.toId===k.end.toId&&w.Equals(k.start.props.normalizedAnchor,k.end.props.normalizedAnchor)&&cc(this.editor,t,k.end.toId,{...k.end.props,normalizedAnchor:{x:k.end.props.normalizedAnchor.x+.05,y:k.end.props.normalizedAnchor.y}}),a});g(this,"onTranslateStart",t=>{const r=An(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)))){iI.set(t,{pagePosition:s.applyToPoint(t),terminalBindings:Mu(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(mf({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&mf({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}})}}});g(this,"onTranslate",(t,r)=>{const o=iI.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:u=>!u.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:u,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const u=Z.ZeroFix(this.editor.getShapeGeometry(c).bounds),h=this.editor.getPointInShapeSpace(c,l),p={x:(h.x-u.minX)/u.width,y:(h.y-u.minY)/u.height};cc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else Fh(this.editor,r,a.binding.props.terminal)}});g(this,"_resizeInitialBindings",new qo);g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(t,()=>An(this.editor,t)),a=Ka(this.editor,t,i),{start:l,end:c}=rt(t.props);let{bend:u}=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,y=i!=null&&i.end?w.From(i.end.props.normalizedAnchor):null;return o<0&&s>=0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.x=1-f.x),y&&(y.x=1-y.x)):o>=0&&s<0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.y=1-f.y),y&&(y.y=1-y.y)):o>=0&&s>=0?u!==0&&(u*=Math.max(h,p)):o<0&&s<0&&(u!==0&&(u*=Math.max(h,p)),f&&(f.x=1-f.x,f.y=1-f.y),y&&(y.x=1-y.x,y.y=1-y.y)),i.start&&f&&cc(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&y&&cc(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:y.toJson()}),{props:{start:l,end:c,bend:u}}});g(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"}}}});g(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=uo(this.editor,t),o=[],s=r.isStraight?new Ho({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=Vh(this.editor,t);o.push(...a.debugGeom),i=new ns({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Kr({children:[...i?[s,i]:[s],...o]})}getHandles(t){const r=uo(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=Mr(),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=uo(this.editor,t);if(!(i!=null&&i.isValid))return null;const a=Vh(this.editor,t),l=t.id===this.editor.getOnlySelectedShapeId(),u=this.editor.getEditingShapeId()===t.id||t.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(Ys,{id:t.id,style:{minWidth:50,minHeight:50},children:d.jsx(sI,{shape:t,shouldDisplayHandles:s&&(o==null?void 0:o.id)===t.id})}),u&&d.jsx(yg,{id:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:kv(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=pg(t.id),o=uo(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 u=jt[t.props.size]*t.props.scale,h=o.start.arrowhead&&vf(o,"start",u),p=o.end.arrowhead&&vf(o,"end",u),f=o.isStraight?hA(o):uA(o),y=h&&o.start.arrowhead!=="arrow"||p&&o.end.arrowhead!=="arrow"||!!c,m=(t.id+"_clip").replace(":","_");return r&&c?d.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}):d.jsxs("g",{children:[y&&d.jsx("defs",{children:d.jsxs("mask",{id:m,children:[d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.w+200,height:l.h+200,fill:"white"}),c&&d.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&&d.jsx("path",{d:h,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&d.jsx("path",{d:p,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{...y?{mask:`url(#${m})`}:void 0,children:[y&&d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.width+200,height:l.height+200,opacity:0}),d.jsx("path",{d:f})]}),h&&d.jsx("path",{d:h}),p&&d.jsx("path",{d:p}),c&&d.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=as(r),s=1/t.props.scale;return d.jsxs("g",{transform:`scale(${s})`,children:[d.jsx(sI,{shape:t,shouldDisplayHandles:!1}),d.jsx(mg,{fontSize:kv(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:o[t.props.labelColor].solid,bounds:Vh(this.editor,t).box,padding:4*t.props.scale})]})}getCanvasSvgDefs(){return[i0(),{key:"arrow:dot",component:vX},{key:"arrow:cross",component:xX}]}}g(Yh,"type","arrow"),g(Yh,"props",r_),g(Yh,"migrations",o_);function SX(e,n){const t=uo(e,n);return t.isStraight?w.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const sI=lr(function({shape:n,shouldDisplayHandles:t}){const r=B(),o=Mr(),s=uo(r,n),i=Z.ZeroFix(r.getShapeGeometry(n).bounds),a=An(r,n),l=we.useMemo(()=>r.environment.isSafari?yX+=1:0,[n]);if(!(s!=null&&s.isValid))return null;const c=jt[n.props.size]*n.props.scale,u=s.start.arrowhead&&vf(s,"start",c),h=s.end.arrowhead&&vf(s,"end",c),p=s.isStraight?hA(s):uA(s);let f=null;if(t){const E=2/r.getZoomLevel(),{strokeDasharray:k,strokeDashoffset:C}=oo(SX(r,n),E,{end:"skip",start:"skip",lengthRatio:2.5});f=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?mX(s):gX(s),strokeDasharray:k,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:y,strokeDashoffset:m}=oo(s.isStraight?s.length:Math.abs(s.bodyArc.length),c,{style:n.props.dash}),x=Vh(r,n),S=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),v=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),b=(n.id+"_clip_"+l).replace(":","_");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsxs("mask",{id:b,children:[d.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()&&d.jsx("rect",{x:x.box.x,y:x.box.y,width:x.box.w,height:x.box.h,fill:"black",rx:4,ry:4}),u&&S&&d.jsx("path",{d:u,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),h&&v&&d.jsx("path",{d:h,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{fill:"none",stroke:o[n.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[f,d.jsxs("g",{mask:`url(#${b})`,children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:p,strokeDasharray:y,strokeDashoffset:m})]}),u&&S&&n.props.fill!=="none"&&d.jsx(en,{theme:o,d:u,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),h&&v&&n.props.fill!=="none"&&d.jsx(en,{theme:o,d:h,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),u&&d.jsx("path",{d:u}),h&&d.jsx("path",{d:h})]})]})}),iI=new WeakMap;function vX(){return d.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:d.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function xX(){return d.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[d.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),d.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const aI="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 d.jsx("a",{className:ce("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Ht,onPointerUp:Ht,title:e,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${aI}") center 100% / 100% no-repeat`,WebkitMask:`url("${aI}") center 100% / 100% no-repeat`}})})}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",wX=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function l0(e){return wX.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,l=new w(r,o),{x:c,y:u}=l.rot(-e);return`${c}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}const bX=300,pA=320,PX=46,CX=101;class Xh extends $l{constructor(){super(...arguments);g(this,"canResize",()=>!1);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"onBeforeCreate",t=>cI(this.editor,t));g(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(sr.isValid(r.props.url))EX(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}};if(t.props.assetId!==r.props.assetId)return cI(this.editor,r)})}getDefaultProps(){return{url:"",w:bX,h:pA,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),s=IX(t);return d.jsx(Vi,{children:d.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:l0(o),maxHeight:t.props.h},children:[(!r||r.props.image)&&d.jsxs("div",{className:"tl-bookmark__image_container",children:[r?d.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)||""}):d.jsx("div",{className:"tl-bookmark__placeholder"}),(r==null?void 0:r.props.image)&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[r!=null&&r.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:r.props.title}):null,r!=null&&r.props.description&&(r!=null&&r.props.image)?d.jsx("p",{className:"tl-bookmark__description",children:r.props.description}):null,d.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ht,onPointerUp:Ht,onClick:Ht,children:[r!=null&&r.props.favicon?d.jsx("img",{className:"tl-bookmark__favicon",src:r==null?void 0:r.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",alt:`favicon of ${s}`}):d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${lI}") center 100% / 100% no-repeat`,WebkitMask:`url("${lI}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:s})]})]})]})})}indicator(t){return d.jsx("rect",{width:N(t.props.w),height:N(t.props.h),rx:"6",ry:"6"})}}g(Xh,"type","bookmark"),g(Xh,"props",u_),g(Xh,"migrations",d_);function cI(e,n){const t=n.props.assetId?e.getAsset(n.props.assetId):null;let r=pA;return t&&(t.props.image||(t.props.title?r=CX:r=PX)),{...n,props:{...n.props,h:r}}}const IX=e=>{try{return new URL(e.props.url).hostname.replace(/^www\./,"")}catch{return e.props.url}};function EX(e,n){const{url:t}=n.props,r=Ci.createId(hS(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}}]),kX(e,n))}const kX=bk(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 _X(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=wo(e,n);fg(i,n);const a=TX(i);let l="";for(const c of a)l+=AX(c,n);return l}function TX(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,u=e.length;c<u-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(dy(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(dy(t)),t=[a];continue}}return t.push(e[e.length-1]),n.push(dy(t)),n}function dy(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 MX(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 AX(e,n={}){if(e.length===0)return"";if(e.length===1)return MX(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 jX=e=>e*.65+V6(e*ke/2)*.35,OX=e=>({size:e,thinning:.5,streamline:al(e,[9,16],[.64,.74],!0),smoothing:.62,easing:At.easeOutSine,simulatePressure:!0}),DX=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:jX}),uI=e=>({size:e,thinning:0,streamline:al(e,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:At.linear}),RX=e=>({size:e,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:At.linear});function c0({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:At.easeOutSine,last:n}}function _v(e,n,t,r){const o=e.isComplete||t;return r?e.isPen?{...RX(n),last:o}:{...uI(n),last:o}:e.dash==="draw"?e.isPen?{...DX(n),last:o}:{...OX(n),last:o}:{...uI(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 LX(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class qh extends Hr{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>hy(t));g(this,"hideRotateHandle",t=>hy(t));g(this,"hideSelectionBoundsFg",t=>hy(t));g(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:u})=>({x:zo(o*l),y:zo(s*c),z:u}))});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=(jt[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=wo(r,_v(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 d.jsx(Ys,{id:t.id,children:d.jsx(dI,{shape:t,zoomLevel:this.editor.getZoomLevel()})})}indicator(t){var h;const r=wl(t.props.segments);let o=(jt[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+=Vr(t.id)()*(o/6));const a=t.props.isComplete||((h=Nt(t.props.segments))==null?void 0:h.type)==="straight",l=_v(t.props,o,a,!0),c=wo(r,l),u=c.length>1?Yi(c,t.props.isClosed):fA(r[0],o);return d.jsx("path",{d:u})}toSvg(t,r){r.addExportDef(s0(t.props.fill));const o=1/t.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(dI,{shape:t,zoomLevel:1})})}getCanvasSvgDefs(){return[i0()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return jt[t.props.size]*r/2*t.props.scale}}g(qh,"type","draw"),g(qh,"props",p_),g(qh,"migrations",f_);function fA(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 hy(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function dI({shape:e,zoomLevel:n}){var h;const t=Mr(),r=wl(e.props.segments),o=e.props.isComplete||((h=Nt(e.props.segments))==null?void 0:h.type)==="straight";let s=(jt[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+=Vr(e.id)()*(s/6));const a=_v(e.props,s,o,i);if(!i&&e.props.dash==="draw")return d.jsxs(d.Fragment,{children:[e.props.isClosed&&e.props.fill&&r.length>1?d.jsx(en,{d:Yi(wo(r,a),e.props.isClosed),theme:t,color:e.props.color,fill:e.props.isClosed?e.props.fill:"none",scale:e.props.scale}):null,d.jsx("path",{d:_X(r,a),strokeLinecap:"round",fill:t[e.props.color].solid})]});const l=wo(r,a),c=l.length<2,u=c?fA(r[0],0):Yi(l,e.props.isClosed);return d.jsxs(d.Fragment,{children:[d.jsx(en,{d:u,theme:t,color:e.props.color,fill:c||e.props.isClosed?e.props.fill:"none",scale:e.props.scale}),d.jsx("path",{d:u,strokeLinecap:"round",fill:c?t[e.props.color].solid:"none",stroke:t[e.props.color].solid,strokeWidth:s,strokeDasharray:c?"none":LX(e,s),strokeDashoffset:"0"})]})}function $X(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=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:y,y:m}=f.rot(e.rotation).add(r);return{x:y,y:m,props:{w:Math.min(l,h),h:Math.min(u,p)}}}const FX=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class Zh extends $l{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",t=>!this.canResize(t));g(this,"canEdit",()=>!0);g(this,"canResize",t=>{var r,o;return!!((o=(r=As(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});g(this,"canEditInReadOnly",()=>!0);g(this,"isAspectRatioLocked",t=>{const r=As(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});g(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=As(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 $X(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=pg(t.id),a=P.useMemo(()=>q2(s),[s]),l=G("is hovering",()=>{const{editingShapeId:f,hoveredShapeId:y}=this.editor.getCurrentPageState();if(f&&y!==f){const m=this.editor.getShape(f);if(m&&this.editor.isShapeOfType(m,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(t).rotation(),u=i||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const f=a.url.split("/").pop();if(!f)throw Error("No gist id!");return d.jsx(Vi,{className:"tl-embed-container",id:t.id,children:d.jsx(NX,{id:f,width:N(r),height:N(o),isInteractive:u,pageRotation:c})})}const p=FX({...j6,...(a==null?void 0:a.definition.overridePermissions)??{}});return d.jsx(Vi,{className:"tl-embed-container",id:t.id,children:a!=null&&a.definition?d.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:u?"auto":"none",zIndex:u?"":"-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(()=>As(t.props.url),[t.props.url]);return d.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})}}g(Zh,"type","embed"),g(Zh,"props",g_),g(Zh,"migrations",m_);function NX({id:e,file:n,isInteractive:t,width:r,height:o,style:s,pageRotation:i}){return d.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:`
143
+ <html>
144
+ <head>
145
+ <base target="_blank">
146
+ </head>
147
+ <body>
148
+ <script src=${`https://gist.github.com/${e}.js${n?`?file=${n}`:""}`}><\/script>
149
+ <style type="text/css">
150
+ * { margin: 0px; }
151
+ table { height: 100%; background-color: red; }
152
+ .gist { background-color: none; height: 100%; }
153
+ .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
154
+ </style>
155
+ </body>
156
+ </html>`})}const zX=P.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=B(),s=P.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Ht(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=P.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==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 u=c.props.name,h=l.currentTarget.value;u!==h&&o.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,o]);return d.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[d.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}),gA(n,"Frame")+"​"]})}),BX=function({id:n,name:t,width:r,height:o}){const s=B(),i=G("shape rotation",()=>Rs(s.getShapePageTransform(n).rotation()),[s,n]),a=pg(n),l=P.useRef(null),c=P.useCallback(y=>{const m=On(y);y.preventDefault(),s.getEditingShapeId()!==n&&s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...m})},[s,n]);P.useEffect(()=>{const y=l.current;y&&a&&(y.focus(),y.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 d.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:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(zX,{ref:l,id:n,name:t,isEditing:a})})})};function gA(e,n){return e.match(/^\s*$/)?n:e}class Qh extends $l{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"canReceiveNewChildrenOfType",(t,r)=>!t.isLocked);g(this,"canDropShapes",(t,r)=>!t.isLocked);g(this,"onDragShapesOver",(t,r)=>{r.every(o=>o.parentId===t.id)||this.editor.reparentShapes(r,t.id)});g(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())});g(this,"onResize",(t,r)=>Jw(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new ns({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=Mr(),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 d.jsxs(d.Fragment,{children:[d.jsx(Ys,{children:d.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:d.jsx(BX,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t,r){const o=as({isDarkMode:r.isDarkMode}),a=((Rs(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 u={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(gA(t.props.name,"Frame")+"​",u),p=h[0],f=Nt(h),y=f.box.w+f.box.x-p.box.x,m=Ev(this.editor,h,{offsetY:-u.height-2,...u});return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:t.props.w,height:t.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:c,children:[d.jsx("rect",{x:-8,y:-u.height-4,width:y+16,height:u.height,fill:o.background,rx:4,ry:4}),m]})]})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return d.jsx("rect",{width:N(r.width),height:N(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}g(Qh,"type","frame"),g(Qh,"props",y_),g(Qh,"migrations",S_);function hI(e,n){return e>n?(ke*(n/2)+(e-n))*2:(ke*(e/2)+(n-e))*2}function mA(e,n){return u0(e,n).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function UX(e,n,t,r){const o=e/4,s=n/4,i=Vr(r),a=t*.75,l=v=>v.addXY(i()*a,i()*a),c=new w(e/2,n),u=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)),y=l(new w(0,s*1.2)),m=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:u}),new nn({start:u,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:y}),new nn({start:y,cp1:new w(0,-s*.32),cp2:new w(o*1.85,-s*.32),end:m}),new nn({start:m,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 HX(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function KX(e,n,t,r){const o=Vr(e),s=n/2,i=t/2,a=$_(s,i),l=[],c=Re*o(),u=Re+Ge/2+Math.abs(o())*Ge,h=Math.max(16,a/10);for(let p=0;p<h;p++){const f=p/(h-1),y=c+f*u,m=Math.cos(y),x=Math.sin(y);l.push(new w(s*m+n*.5+.05*o(),i*x+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?At.easeInOutSine(f):At.easeInExpo(f)))/2)))}return wo(l,HX(r))}function WX(e,n,t,r){return Yi(KX(e,n,t,r))}function Tv(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 Mv(e,n,t,r,o){const s=[],i=Vr(e);let a=n[0],l;const c=n.length;for(let u=0,h=c*o;u<h;u++){l=w.AddXY(n[(u+1)%c],i()*t,i()*t);const p=w.Sub(l,a),f=w.Len(p),y=w.Div(p,f).mul(Math.min(f/4,r));s.push(w.Add(a,y),w.Add(l,y.neg()),l),a=l}return s}function GX(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:-ke/2},{type:"straight",start:new w(e-r,n),delta:new w(-1,0)},{type:"arc",center:new w(r,r),startAngle:ke/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:ke}];let l=0;const c=[];for(let u=0;u<t;u++){const h=a[0];h.type==="straight"?c.push(w.Add(h.start,w.Mul(h.delta,l))):c.push(Bi(h.center,r,h.startAngle+l/r)),l+=i;let p=h.type==="straight"?o:ke*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?o:ke*r}return c}const VX={s:50,m:70,l:100,xl:130},YX=.2;function Sg(e,n,t,r){const o=Vr(t),s=hI(e,n),i=Math.max(Math.ceil(s/VX[r]),6,Math.ceil(s/Math.min(e,n))),a=s/i*YX,l=Math.max(e-a*2,1),c=Math.max(n-a*2,1),h=hI(l,c)/i,p=(e-l)/2,f=(n-c)/2,y=GX(l,c,i).map(b=>b.addXY(p,f)),m=e<20?0:a*.3,x=n<20?0:a*.3,S=y.slice(0);for(let b=0;b<Math.floor(i/2);b++)S[b]=w.AddXY(S[b],o()*m,o()*x),S[i-b-1]=w.AddXY(S[i-b-1],o()*m,o()*x);const v=[];for(let b=0;b<S.length;b++){const E=b===S.length-1?0:b+1,k=S[b],C=S[E],I=y[b],T=y[E],O=w.Dist(I,T),_=h-O,L=w.Dist(k,C)/O,j=(Math.max(p,f)+_)*L,R=w.Lrp(I,T,.5).add(w.Sub(T,I).uni().per().mul(j));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=Gx(k,C,R),W=w.Dist(F||w.Average([k,C]),k);v.push({leftPoint:k,rightPoint:C,arcPoint:R,center:F,radius:W})}return v}function XX(e,n,t,r){const o=[],s=Sg(e,n,t,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of s)o.push(...Z6(l,c,i,a,10));return o}function Av(e,n,t,r){const o=Sg(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 u=w.Clockwise(i,a,c)?"0":"1";s+=` A${N(l)},${N(l)} 0 ${u},1 ${a.toFixed()}`}return s+=" Z",s}const qX={s:.5,m:.7,l:.9,xl:1.6};function ZX(e,n,t,r){const o=Vr(t),s=qX[r],i=Sg(e,n,t,r),c=i.reduce((f,y)=>f+w.Dist2(y.leftPoint,y.rightPoint),0)/i.length>(s*15)**2?f=>f.addXY(o()*s*2,o()*s*2):f=>f;let u=`M${i[0].leftPoint.toFixed()}`,h=c(i[0].leftPoint),p=`M${h.toFixed()}`;for(const{leftPoint:f,center:y,rightPoint:m,radius:x,arcPoint:S}of i){if(y===null){u+=` L${m.toFixed()}`;const I=c(m);p+=` L${I.toFixed()}`,h=I;continue}const v=w.Clockwise(f,m,y)?"0":"1";u+=` A${N(x)},${N(x)} 0 ${v},1 ${m.toFixed()}`;const b=c(m),E=c(S),k=Gx(h,b,E);if(!Number.isFinite(k.x)||!Number.isFinite(k.y)){p+=` L${b.toFixed()}`,h=b;continue}const C=Math.abs(w.Dist(k,h));p+=` A${N(C)},${N(C)} 0 ${v},1 ${b.toFixed()}`,h=b}return u+p+" Z"}function jv(e,n){switch(e.geo){case"x-box":return QX(e.w,e.h,n,e.dash);case"check-box":return JX(e.w,e.h);default:return}}function QX(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 JX(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 pI({shape:e,shouldScale:n}){const t=n?e.props.scale:1,r=B(),o=Mr(),{id:s,props:i}=e,{w:a,color:l,fill:c,dash:u,growY:h,size:p}=i,f=jt[p]*t,y=i.h+h;switch(i.geo){case"cloud":if(u==="solid"){const m=Av(a,y,s,p);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("path",{d:m,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else if(u==="draw"){const m=ZX(a,y,s,p);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("path",{d:m,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else{const m=Av(a,y,s,p),x=Sg(a,y,s,p);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("g",{strokeWidth:f,stroke:o[l].solid,fill:"none",pointerEvents:"all",children:x.map(({leftPoint:S,rightPoint:v,center:b,radius:E},k)=>{const C=b?E*Rs(Rs(w.Angle(b,v))-Rs(w.Angle(b,S))):w.Dist(S,v),{strokeDasharray:I,strokeDashoffset:T}=oo(C,f,{style:u,start:"outset",end:"outset"});return d.jsx("path",{d:b?`M${S.x},${S.y}A${E},${E},0,0,1,${v.x},${v.y}`:`M${S.x},${S.y}L${v.x},${v.y}`,strokeDasharray:I,strokeDashoffset:T},k)})})]})}case"ellipse":{const m=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=m.getSvgPathData(!0);if(u==="dashed"||u==="dotted"){const S=m.length,{strokeDasharray:v,strokeDashoffset:b}=oo(S<64?S*2:S,f,{style:u,snap:4,closed:!0});return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),d.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 d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),d.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}}case"oval":{const m=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=m.getSvgPathData(!0);if(u==="dashed"||u==="dotted"){const S=m.getLength(),{strokeDasharray:v,strokeDashoffset:b}=oo(S<64?S*2:S,f,{style:u,snap:4,start:"outset",end:"outset",closed:!0});return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),d.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:v,strokeDashoffset:b})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),d.jsx("path",{d:x,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}case"heart":if(u==="dashed"||u==="dotted"||u==="solid"){const m=mA(a,y),x=u0(a,y);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),x.map((S,v)=>{const{strokeDasharray:b,strokeDashoffset:E}=oo(S.length,f,{style:u,snap:1,start:"outset",end:"outset",closed:!0});return d.jsx("path",{d:S.getSvgPathData(),strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:b,strokeDashoffset:E,pointerEvents:"all"},`curve_${v}`)})]})}else{const m=UX(a,y,f,e.id);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("path",{d:m,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}default:{const m=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=m instanceof Kr?m.children[0].vertices:m.vertices,S=jv(e.props,f);if(u==="solid"){let v="M"+x[0]+"L"+x.slice(1)+"Z";if(S)for(const[b,E]of S)v+=`M${b.x},${b.y}L${E.x},${E.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),d.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else if(u==="dashed"||u==="dotted"){const v="M"+x[0]+"L"+x.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),d.jsxs("g",{strokeWidth:f,stroke:o[l].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(x.length)).map((b,E)=>{const k=w.ToFixed(x[E]),C=w.ToFixed(x[(E+1)%x.length]),I=w.Dist(k,C),{strokeDasharray:T,strokeDashoffset:O}=oo(I,f,{style:u,start:"outset",end:"outset"});return d.jsx("line",{x1:k.x,y1:k.y,x2:C.x,y2:C.y,strokeDasharray:T,strokeDashoffset:O},E)}),S&&S.map(([b,E],k)=>{const C=w.Dist(b,E),{strokeDasharray:I,strokeDashoffset:T}=oo(C,f,{style:u,start:"skip",end:"skip",snap:u==="dotted"?4:void 0});return d.jsx("path",{d:`M${b.x},${b.y}L${E.x},${E.y}`,stroke:o[l].solid,strokeWidth:f,fill:"none",strokeDasharray:I,strokeDashoffset:T},`line_fg_${k}`)})]})]})}else if(u==="draw"){let v=Tv(Mv(s,x,f/3,f*2,2));if(S)for(const[E,k]of S)v+=`M${E.toFixed()}L${k.toFixed()}`;const b=Tv(Mv(s,x,0,f*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:b,color:l,fill:c,scale:t}),d.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}}}}const gr=17*3;class Jh extends $l{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(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()}}])});g(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,u=0,h=0;if(t.props.text.trim()){let m=Math.max(Math.abs(l),gr),x=Math.max(Math.abs(c),gr);m<gr&&x===gr&&(m=gr),m===gr&&x<gr&&(x=gr);const S=qd(this.editor,{...t,props:{...t.props,w:m,h:x}}),v=Math.max(Math.abs(l),S.w)*Math.sign(l),b=Math.max(Math.abs(c),S.h)*Math.sign(c);u=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?u:-u),i<0&&(p.y+=c),(r==="top"||r==="top_left"||r==="top_right")&&(p.y+=i<0?h:-h);const{x:f,y}=p.rot(t.rotation).add(o);return{x:f,y,props:{w:Math.max(Math.abs(l),1),h:Math.max(Math.abs(c),1),growY:0}}});g(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=qd(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}}});g(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=qd(this.editor,r),c=l.w,u=l.h;if(!o&&s&&s.length===1){let p=Math.max(i,c),f=Math.max(a,u);return t.props.w<gr&&t.props.h<gr&&(p=Math.max(p,gr),f=Math.max(f,gr),p=Math.max(p,f),f=Math.max(p,f)),{...r,props:{...r.props,w:p,h:f,growY:0}}}let h=null;if(u>a?h=u-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}}});g(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=jt[t.props.size]*t.props.scale,l=t.props.fill!=="none";let c;switch(t.props.geo){case"cloud":{c=new vt({points:XX(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:xm(r,o,5),isFilled:l});break}case"hexagon":{c=new vt({points:xm(r,o,6),isFilled:l});break}case"octagon":{c=new vt({points:xm(r,o,8),isFilled:l});break}case"ellipse":{c=new CV({width:r,height:o,isFilled:l});break}case"oval":{c=new IV({width:r,height:o,isFilled:l});break}case"star":{const v=Re/5/2,b=Math.floor(5/4)*2,E=5*2-b,k=0,C=Math.floor(5/2)*2,I=Math.cos(-Ge+b*v)*r/2,T=Math.cos(-Ge+E*v)*r/2,O=Math.sin(-Ge+k*v)*o/2,_=Math.sin(-Ge+C*v)*o/2,M=r-Math.abs(I-T),L=o-Math.abs(_-O),j=r/2+T-(r/2-I),R=o/2+O-(o/2-_),F=1,W=(r-j)/2,K=(o-R)/2,z=(r+M)/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=-Ge+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 S=Math.min(r*.38,o*.38);c=new vt({points:[new w(S,0),new w(r,0),new w(r-S,o),new w(0,o)],isFilled:l});break}case"rhombus-2":{const S=Math.min(r*.38,o*.38);c=new vt({points:[new w(0,0),new w(r-S,0),new w(r,o),new w(S,o)],isFilled:l});break}case"trapezoid":{const S=Math.min(r*.38,o*.38);c=new vt({points:[new w(S,0),new w(r-S,0),new w(r,o),new w(0,o)],isFilled:l});break}case"arrow-right":{const S=Math.min(r,o)*.38,v=o*.16;c=new vt({points:[new w(0,v),new w(r-S,v),new w(r-S,0),new w(r,o/2),new w(r-S,o),new w(r-S,o-v),new w(0,o-v)],isFilled:l});break}case"arrow-left":{const S=Math.min(r,o)*.38,v=o*.16;c=new vt({points:[new w(S,0),new w(S,v),new w(r,v),new w(r,o-v),new w(S,o-v),new w(S,o),new w(0,o/2)],isFilled:l});break}case"arrow-up":{const S=r*.16,v=Math.min(r,o)*.38;c=new vt({points:[new w(r/2,0),new w(r,v),new w(r-S,v),new w(r-S,o),new w(S,o),new w(S,v),new w(0,v)],isFilled:l});break}case"arrow-down":{const S=r*.16,v=Math.min(r,o)*.38;c=new vt({points:[new w(S,0),new w(r-S,0),new w(r-S,o-v),new w(r,o-v),new w(r/2,o),new w(0,o-v),new w(S,o-v)],isFilled:l});break}case"check-box":case"x-box":case"rectangle":{c=new ns({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 u=qd(this.editor,t),h=Math.min(100,r/2),p=Math.min(Yo[t.props.size]*t.props.scale*Wt.lineHeight+Lr*2,o/2),f=Math.min(r,Math.max(u.w,Math.min(h,Math.max(1,r-8)))),y=Math.min(o,Math.max(u.h,Math.min(p,Math.max(1,r-8)))),m=jv(t.props,a),x=m?m.map(S=>new Ll({points:S})):[];return new Kr({children:[c,new ns({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-y:(o-y)/2,width:f,height:y,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:u,text:h}=s,p=t.id===this.editor.getOnlySelectedShapeId(),f=Mr(),m=this.editor.getEditingShapeId()!==null||t.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(Ys,{id:r,children:d.jsx(pI,{shape:t,shouldScale:!0})}),m&&d.jsx(Vi,{style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:d.jsx(yg,{id:r,type:o,font:a,fontSize:Yo[u]*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&&d.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=jt[i],c=this.editor.getShapeGeometry(t);switch(o.geo){case"ellipse":return o.dash==="draw"?d.jsx("path",{d:WX(r,s,a,l)}):d.jsx("path",{d:c.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:mA(s,a)});case"oval":return d.jsx("path",{d:c.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:Av(s,a,r,i)});default:{const u=this.editor.getShapeGeometry(t),h=u instanceof Kr?u.children[0].vertices:u.vertices;let p;if(o.dash==="draw"){const y=Mv(r,h,0,l*2*t.props.scale,1);p=Tv(y)}else p="M"+h[0]+"L"+h.slice(1)+"Z";const f=jv(t.props,l);if(f)for(const[y,m]of f)p+=`M${y.x},${y.y}L${m.x},${m.y}`;return d.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=as(r),l=new Z(0,0,s.w,s.h+s.growY);i=d.jsx(mg,{fontSize:Yo[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:a[s.labelColor].solid,bounds:l,padding:16})}return d.jsxs(d.Fragment,{children:[d.jsx(pI,{shouldScale:!1,shape:o}),i]})}getCanvasSvgDefs(){return[i0()]}}g(Jh,"type","geo"),g(Jh,"props",v_),g(Jh,"migrations",x_);function qd(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Wt,fontFamily:yo[n.props.font],fontSize:Yo[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:yo[n.props.font],fontSize:Yo[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-Lr*2))});return{w:s.w+Lr*2,h:s.h+Lr*2}}function eq(){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(xt.forceSrgb)||!e?"srgb":"p3"}const fI=.35,gI=.82;class ep extends Hr{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>Zd(t));g(this,"hideRotateHandle",t=>Zd(t));g(this,"hideSelectionBoundsFg",t=>Zd(t));g(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:u})=>({x:o*l,y:s*c,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=Pi(t);if(Zd(t))return new t0({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=mI(t,r,!0),i=c0({strokeWidth:s,showAsComplete:!0});return fg(o,i),new vt({points:n0(o,i),isFilled:!0})}component(t){const r=py(this.editor,t),o=Pi(t);return d.jsx(Ys,{id:t.id,children:d.jsx(Qd,{shape:t,forceSolid:r,strokeWidth:o,opacity:fI})})}backgroundComponent(t){const r=py(this.editor,t),o=Pi(t);return d.jsx(Ys,{id:t.id,children:d.jsx(Qd,{shape:t,forceSolid:r,strokeWidth:o,opacity:gI})})}indicator(t){const r=py(this.editor,t),o=Pi(t),{strokePoints:s,sw:i}=mI(t,o,r),a=wl(t.props.segments);let l;return s.length<2?l=nq(a[0],i):l=Yi(s,!1),d.jsx("path",{d:l})}toSvg(t){const r=Pi(t),o=r<1.5,s=1/t.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(Qd,{forceSolid:o,strokeWidth:r,shape:t,opacity:fI})})}toBackgroundSvg(t){const r=Pi(t),o=r<1.5,s=1/t.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(Qd,{forceSolid:o,strokeWidth:r,shape:t,opacity:gI})})}}g(ep,"type","highlight"),g(ep,"props",P_),g(ep,"migrations",C_);function tq(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 nq(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 mI(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+=Vr(e.id)()*(n/6));const i=c0({strokeWidth:s,showAsComplete:o});return{strokePoints:wo(r,i),sw:s}}function Pi(e){return yl[e.props.size]*1.12*e.props.scale}function Zd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function Qd({strokeWidth:e,forceSolid:n,shape:t,opacity:r}){var p;const o=Mr(),s=wl(t.props.segments);let i=e;!n&&!t.props.isPen&&s.length===1&&(i+=Vr(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=wo(s,a),c=l.length>1?Yi(l,!1):tq(t.props.segments[0].points[0]),u=eq(),h=o[t.props.color].highlight[u];return d.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function py(e,n){return G("forceSolid",()=>{const t=Pi(n),r=e.getZoomLevel();return t/r<1.5},[e])}function yA(){return d.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:[d.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),d.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),d.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function SA(e,n,t){const r=B(),[o,s]=P.useState(null),i=n?r.getAsset(n):null,l=r.getCulledShapes().has(e),c=P.useRef(!1);P.useEffect(()=>{o&&(c.current=!0)},[o]);const u=i&&"w"in i.props?t/i.props.w:1,h=G("zoom level",()=>r.getZoomLevel()*u,[r,u]);return P.useEffect(()=>{if(l)return;let p=!1;const f=r.timers.setTimeout(async()=>{const y=await r.resolveAssetUrl(n,{screenScale:h});p||s(y)},c.current?500:0);return()=>{clearTimeout(f),p=!0}},[n,i==null?void 0:i.props.src,l,h,r]),{asset:i,url:o}}function vA(){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 rq(e){const t=await(await So(e)).blob();return Ai.blobToDataUrl(t)}class tp extends $l{constructor(){super(...arguments);g(this,"isAspectRatioLocked",()=>!0);g(this,"canCrop",()=>!0);g(this,"onResize",(t,r)=>{let o=Jw(t,r);const{flipX:s,flipY:i}=r.initialShape.props;return o={...o,props:{...o.props,flipX:r.scaleX<0!==s,flipY:r.scaleY<0!==i}},o});g(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}}])});g(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,flipX:!1,flipY:!1}}isAnimated(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;return r?"mimeType"in r.props&&lo.isAnimatedImageType(r==null?void 0:r.props.mimeType)||"isAnimated"in r.props&&r.props.isAnimated:!1}component(t){var m;const r=this.editor.getCroppingShapeId()===t.id,o=vA(),[s,i]=P.useState(""),[a,l]=P.useState(""),c=t.id===this.editor.getOnlySelectedShapeId(),{asset:u,url:h}=SA(t.id,t.props.assetId,t.props.w);if(P.useEffect(()=>{if(h){let x=!1;const S=il();return S.onload=()=>{x||l(h)},S.src=h,()=>{x=!0}}},[h,t]),P.useEffect(()=>{if(h&&this.isAnimated(t)){let x=!1;const S=il();return S.onload=()=>{if(x)return;const v=document.createElement("canvas");v.width=S.width,v.height=S.height;const b=v.getContext("2d");b&&(b.drawImage(S,0,0),i(v.toDataURL()),l(h))},S.crossOrigin="anonymous",S.src=h,()=>{x=!0}}},[o,h,t]),(u==null?void 0:u.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const p=c&&r&&this.editor.isIn("select.crop"),f=o&&(((m=u==null?void 0:u.props.mimeType)==null?void 0:m.includes("video"))||this.isAnimated(t)),y=yI(t);return u!=null&&u.props.src?a?d.jsxs(d.Fragment,{children:[p&&d.jsx("div",{style:y,children:d.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})}),d.jsxs(Vi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h},children:[d.jsxs("div",{className:"tl-image-container",style:y,children:[d.jsx("img",{className:ce("tl-image",{"tl-flip-x":t.props.flipX&&!t.props.flipY,"tl-flip-y":t.props.flipY&&!t.props.flipX,"tl-flip-xy":t.props.flipY&&t.props.flipX}),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&&d.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):null:d.jsxs(Vi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h,color:"var(--color-text-3)",backgroundColor:u?"transparent":"var(--color-low)",border:u?"none":"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:"tl-image-container",style:y,children:u?null:d.jsx(yA,{})}),"url"in t.props&&t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return this.editor.getCroppingShapeId()===t.id?null:d.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 rq(o)||"");const s=yI(t),i=t.props.crop;if(s.transform&&i){const{transform:a,width:l,height:c}=s,u=(i.bottomRight.x-i.topLeft.x)*l,h=(i.bottomRight.y-i.topLeft.y)*c,p=[new w(0,0),new w(u,0),new w(u,h),new w(0,h)],f=`cropClipPath_${t.id.replace(":","_")}`;return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:f,children:d.jsx("polygon",{points:p.map(y=>`${y.x},${y.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${f})`,children:d.jsx("image",{href:o,width:l,height:c,style:{transform:a}})})]})}else return d.jsx("image",{href:o,width:t.props.w,height:t.props.h})}}g(tp,"type","image"),g(tp,"props",I_),g(tp,"migrations",E_);function yI(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 xA(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function wA(e,n,t){const r=n.vertices,o=xA(t);return wo(r,o)}function oq(e,n,t){const r=xA(t);return n0(fg(wA(e,n,t),r),r)}function sq(e,n,t){const r=oq(e,n,t);return Xx(r)}function iq(e,n,t){if(e.props.dash==="draw"){const r=wA(e,n,t);return Yi(r)}return n.getSvgPathData()}function bA(e,n,t){let r=`M ${Ie(n[0])}L`,o=`M ${Ie(n[0])}L`;const s=t/3,i=t*2,a=Vr(e);let l=n[0],c,u=n[0],h;const p=n.length;for(let f=0,y=p-1;f<y;f++){c=n[f+1],h=w.AddXY(n[f+1],a()*s,a()*s);const m=w.Sub(c,l),x=w.Len(m),S=w.Div(m,x).mul(Math.min(x/4,i)),v=w.Add(l,S),b=w.Add(c,S.neg()),E=w.Sub(h,u),k=w.Len(E),C=w.Div(E,k).mul(Math.min(k/4,i)),I=w.Add(u,C),T=w.Add(h,C.neg());f===y-1?(r+=`${Ie(v)}L ${Ie(c)}`,o+=`${Ie(I)}L ${Ie(h)}`):(r+=`${Ie(v)}L ${Ie(b)}Q ${Ie(c)}`,o+=`${Ie(I)}L ${Ie(T)}Q ${Ie(h)}`,l=c,u=h)}return[r,r+o]}const aq=new qo;class np extends Hr{constructor(){super(...arguments);g(this,"hideResizeHandles",()=>!0);g(this,"hideRotateHandle",()=>!0);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"hideSelectionBoundsBg",()=>!0);g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r;return{props:{points:Mu(t.props.points,(i,{id:a,index:l,x:c,y:u})=>({id:a,index:l,x:c*o,y:u*s}))}}});g(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]=Vc(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 Ic(t)}getHandles(t){return aq.get(t.props,()=>{const r=Ic(t),o=Ov(t),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=Gc(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 d.jsx(Ys,{id:t.id,children:d.jsx(SI,{shape:t})})}indicator(t){const r=jt[t.props.size]*t.props.scale,o=Ic(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]=bA(t.id,a,r);i=l}}else i=iq(t,o,r);return d.jsx("path",{d:i})}toSvg(t){return d.jsx(SI,{shouldScale:!0,shape:t})}getHandleSnapGeometry(t){const r=Ov(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=Ic(t).segments.filter((a,l)=>l!==s-1&&l!==s);return i.length?new Kr({children:i}):null}}}}g(np,"type","line"),g(np,"props",k_),g(np,"migrations",__);function Ov(e){return Object.values(e.props.points).sort(on)}function Ic(e){const n=Ov(e).map(w.From);switch(e.props.spline){case"cubic":return new PV({points:n});case"line":return new Ll({points:n})}}function SI({shape:e,shouldScale:n=!1}){const t=Mr(),r=Ic(e),{dash:o,color:s,size:i}=e.props,a=1/e.props.scale,l=n?a:1,c=jt[i]*e.props.scale;if(e.props.spline==="line"){if(o==="solid"){const u=r.points,h="M"+u[0]+"L"+u.slice(1);return d.jsx("path",{d:h,stroke:t[s].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:t[s].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((u,h)=>{const{strokeDasharray:p,strokeDashoffset:f}=oo(u.length,c,{style:o,start:h>0?"outset":"none",end:h<r.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:p,strokeDashoffset:f,d:u.getSvgPathData(!0),fill:"none"},h)})});if(o==="draw"){const u=r.points,[h,p]=bA(e.id,u,c);return d.jsx("path",{d:p,stroke:t[s].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}}if(e.props.spline==="cubic"){const u=r.getSvgPathData();if(o==="solid")return d.jsx("path",{strokeWidth:c,stroke:t[s].solid,fill:"none",d:u,transform:`scale(${l})`});if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:t[s].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((h,p)=>{const{strokeDasharray:f,strokeDashoffset:y}=oo(h.length,c,{style:o,start:p>0?"outset":"none",end:p<r.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:f,strokeDashoffset:y,d:h.getSvgPathData(),fill:"none"},p)})});if(o==="draw")return d.jsx("path",{d:sq(e,r,c),strokeWidth:1,stroke:t[s].solid,fill:t[s].solid,transform:`scale(${l})`})}}const PA=P.createContext(null);function lq({assetUrls:e,children:n}){return P.useEffect(()=>{for(const t of Object.values(e.icons)){const r=il();r.src=t,r.decode()}for(const t of Object.values(e.embedIcons)){const r=il();r.src=t,r.decode()}},[e]),d.jsx(PA.Provider,{value:e,children:n})}function d0(){const e=P.useContext(PA);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const Dv={"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.paste-error-title":"Pasting failed","action.paste-error-description":"Could not paste due to missing clipboard permissions. Please enable the permissions and try again.","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-paste-at-cursor.menu":"Paste at cursor","action.toggle-paste-at-cursor":"Toggle paste at cursor","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.size-too-big":"File size is too big","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.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..."},cq=new Set(["ar","fa","he","ur","ku"]),Sa={locale:"en",label:"English",messages:Dv,dir:"ltr"};async function uq(e,n){if(!(await So(n.translations.en)).ok)return console.warn("No main translations found."),Sa;if(e==="en")return Sa;const r=Xc.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),Sa;const s=await(await So(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:cq.has(r.locale)?"rtl":"ltr",messages:{...Sa.messages,...s}}}const CA=P.createContext(null);function IA(){const e=P.useContext(CA);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const dq=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:{...Dv,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:Dv});return P.useEffect(()=>{let l=!1;async function c(){const u=await uq(o,s);u&&!l&&(n&&n[o]?a({...u,messages:{...u.messages,...n[o]}}):a(u))}return c(),()=>{l=!0}},[s,o,n]),d.jsx(CA.Provider,{value:i,children:t})});function Te(){const e=IA();return P.useCallback(function(t){return e.messages[t]??t},[e])}class rp extends Hr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"hideResizeHandles",()=>!0);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"onBeforeCreate",t=>vI(this.editor,t));g(this,"onBeforeUpdate",(t,r)=>{if(!(t.props.text===r.props.text&&t.props.font===r.props.font&&t.props.size===r.props.size))return vI(this.editor,r)});g(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}=EA(this.editor,t),{scale:s}=t.props,i=r*s,a=o*s,l=Be*s,c=Jd(t);return new Kr({children:[new ns({width:l,height:c,isFilled:!0}),new ns({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=Jd(t),a=Be*r,l=FY/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:u,verticalAlign:h,fontSizeAdjustment:p}}=t,f=fq(r),y=Mr(),m=Be*s,x=Jd(t),S=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 d.jsxs(d.Fragment,{children:[d.jsx("div",{id:r,className:"tl-note__container",style:{width:m,height:x,backgroundColor:y[i].note.fill,borderBottom:v?`${3*s}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:v?"none":gq(t.id,S,s)},children:d.jsx(yg,{id:r,type:o,font:a,fontSize:(p||Yo[l])*s,lineHeight:Wt.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:b,labelColor:y[i].note.text,wrap:!0,padding:16*s,onKeyDown:f})}),"url"in t.props&&t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{scale:r}=t.props;return d.jsx("rect",{rx:r,width:N(Be*r),height:N(Jd(t))})}toSvg(t,r){r.addExportDef(vl(t.props.font)),t.props.text&&r.addExportDef(vl(t.props.font));const o=as({isDarkMode:r.isDarkMode}),s=mq(t);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:Be-10,height:s.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:Be,height:s.h,fill:o[t.props.color].note.fill}),d.jsx(mg,{fontSize:t.props.fontSizeAdjustment||Yo[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})]})}}g(rp,"type","note"),g(rp,"props",T_),g(rp,"migrations",M_);function vI(e,n){const{labelHeight:t,fontSizeAdjustment:r}=EA(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 hq(e,n){const{text:t}=n.props;if(!t)return{labelHeight:Yo[n.props.size]*Wt.lineHeight+Lr*2,labelWidth:100,fontSizeAdjustment:0};const r=Yo[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:yo[n.props.font],fontSize:o,maxWidth:Be-Lr*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Lr*2,a=c.w+Lr*2,o<=14){const u=e.textMeasure.measureText(t,{...Wt,fontFamily:yo[n.props.font],fontSize:o,maxWidth:Be-Lr*2-l});i=u.h+Lr*2,a=u.w+Lr*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const pq=new qo;function EA(e,n){return pq.get(n,()=>hq(e,n))}function fq(e){const n=B(),t=IA();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)),u=(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(u).add(gg.clone().mul(o.props.scale)).rot(l).add(a.point()),p=sA(n,o,h,l);p&&(n.mark("editing adjacent shape"),yf(n,p,!0))}},[e,n,t.dir])}function Jd(e){return(Be+e.props.growY)*e.props.scale}function gq(e,n,t){const r=Vr(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),
157
+ 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)}),
158
+ 0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function mq(e){return new Z(0,0,Be,Be+e.props.growY)}function yq(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 Sq=new qo;class op extends Hr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"isAspectRatioLocked",()=>!0);g(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,...yq(t,r)};{const c=Math.max(1,Math.abs(s.width*a)),{x:u,y:h}=a<0?w.Sub(o,w.FromAngle(t.rotation).mul(c)):o;return{id:t.id,type:t.type,x:u,y:h,props:{w:c/i.props.scale,autoSize:!1}}}});g(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()}}])});g(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=xI(this.editor,r.props),l=i.width*t.props.scale,c=i.height*t.props.scale,u=a.width*r.props.scale,h=a.height*r.props.scale;let p;switch(r.props.textAlign){case"middle":{p=new w((u-l)/2,s?0:(h-c)/2);break}case"end":{p=new w(u-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}=r;return{...r,x:f-p.x,y:y-p.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(t){return Sq.get(t.props,r=>xI(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:s}=this.getMinDimensions(t);return new ns({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:u,height:h}=this.getMinDimensions(t),p=t.id===this.editor.getOnlySelectedShapeId(),f=Mr(),y=vq(r);return d.jsx(yg,{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:u,textHeight:h,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0,onKeyDown:y})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=B();return t.props.autoSize&&o.getEditingShapeId()===t.id?null:d.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=as(r);return d.jsx(mg,{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})}}g(op,"type","text"),g(op,"props",A_),g(op,"migrations",j_);function xI(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)),u=e.textMeasure.measureText(r,{...Wt,fontFamily:yo[t],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function vq(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 sp extends $l{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(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}=SA(t.id,t.props.assetId,t.props.w),{time:a,playing:l}=t.props,c=pg(t.id),u=vA(),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]),y=P.useCallback(v=>{const b=v.currentTarget;b&&c&&r.updateShapes([{type:"video",id:t.id,props:{time:b.currentTime}}])},[c,t.id,r]),[m,x]=P.useState(!1),S=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&&(m&&!c&&a!==v.currentTime&&(v.currentTime=a),c&&document.activeElement!==v&&v.focus())},[c,m,a]),P.useEffect(()=>{if(u){const v=h.current;if(!v)return;v.pause(),v.currentTime=0}},[h,u]),d.jsxs(d.Fragment,{children:[d.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:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?i?d.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:y,onLoadedData:S,hidden:!m,children:d.jsx("source",{src:i})}):null:d.jsx(yA,{})})})}),"url"in t.props&&t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(t){return d.jsx("rect",{width:N(t.props.w),height:N(t.props.h)})}toSvg(t){return d.jsx("image",{href:xq(t.id),width:t.props.w,height:t.props.h})}}g(sp,"type","video"),g(sp,"props",O_),g(sp,"migrations",D_);function xq(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 kA=[op,Xh,qh,Jh,rp,np,Qh,Yh,ep,Zh,tp,sp];function wq(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 _A extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"scribbleId","id");g(this,"markId","");g(this,"excludedShapeIds",new Set);g(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()});g(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(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),u=this.editor.options.hitTestMargin/s;for(const h of i){if(t.isShapeOfType(h,"group"))continue;const p=t.getShapeMask(h.id);if(p&&!nr(a,p))continue;const f=t.getShapeGeometry(h),y=t.getShapePageTransform(h);if(!f||!y)continue;const m=y.clone().invert(),x=m.applyToPoint(l),S=m.applyToPoint(a),{bounds:v}=f;v.minX-u>Math.max(x.x,S.x)||v.minY-u>Math.max(x.y,S.y)||v.maxX+u<Math.min(x.x,S.x)||v.maxY+u<Math.min(x.y,S.y)||f.hitTestLineSegment(x,S,u)&&c.add(t.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:t}=this;t.deleteShapes(t.getCurrentPageState().erasingShapeIds),t.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:t}=this;t.setErasingShapes([]),t.bailToMark(this.markId),this.parent.transition("idle",this.info)}}g(_A,"id","erasing");var Wy;let bq=(Wy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Wy,"id","idle"),Wy);var Gy;let Pq=(Gy=class extends se{constructor(){super(...arguments);g(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 u=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(u,"frame")&&s.size>i)break;s.add(u.id)}}this.editor.setErasingShapes([...s])});g(this,"onLongPress",t=>{this.startErasing(t)});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startErasing(t)});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(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")}},g(Gy,"id","pointing"),Gy);class ip extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(ip,"id","eraser"),g(ip,"initial","idle"),g(ip,"children",()=>[bq,Pq,_A]);class TA extends se{constructor(){super(...arguments);g(this,"initialCamera",new w);g(this,"onEnter",()=>{this.initialCamera=w.From(this.editor.getCamera()),this.update()});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.parent.transition("idle")});g(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")}}g(TA,"id","dragging");var Vy;let Cq=(Vy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Vy,"id","idle"),Vy);var Yy;let Iq=(Yy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})});g(this,"onLongPress",()=>{this.startDragging()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startDragging()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.complete()})}startDragging(){this.parent.transition("dragging")}complete(){this.parent.transition("idle")}},g(Yy,"id","pointing"),Yy);class ap extends se{constructor(){super(...arguments);g(this,"onDoubleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{animation:{duration:220,easing:At.easeOutQuint}})}});g(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:At.easeOutQuint}})}});g(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:At.easeOutQuint}}):this.editor.resetZoom(o,{animation:{duration:320,easing:At.easeOutQuint}})}})}}g(ap,"id","hand"),g(ap,"initial","idle"),g(ap,"children",()=>[Cq,Iq,TA]);var Xy;let Eq=(Xy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},g(Xy,"id","idle"),Xy);class MA extends se{constructor(){super(...arguments);g(this,"scribbleId","id");g(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()});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.pushPointToScribble()});g(this,"onPointerUp",()=>{this.complete()});g(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}g(MA,"id","lasering");class lp extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(lp,"id","laser"),g(lp,"initial","idle"),g(lp,"children",()=>[Eq,MA]);class AA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"initialSelectedShapeIds",[]);g(this,"excludedShapeIds",new Set);g(this,"isWrapMode",!1);g(this,"initialStartShape",null);g(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()});g(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});g(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});g(this,"onPointerMove",()=>{this.hitTestShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",t=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",t)});g(this,"onKeyDown",t=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()});g(this,"onKeyUp",()=>{this.hitTestShapes()});g(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:[]),u=o?!l:l,h=Z.FromPoints([s,i]),{corners:p}=h;let f,y,m,x,S,v;const b=t.getCurrentPageShapes(),E=t.getCurrentPageId();e:for(let I=0,T=b.length;I<T;I++){if(m=b[I],r.has(m.id)||c.has(m.id)||(x=t.getShapePageBounds(m),!x))continue e;if(h.contains(x)){this.handleHit(m,i,E,c,p);continue e}if(u||t.isShapeOfType(m,"frame"))continue e;if(h.collides(x)){if(S=t.getShapePageTransform(m),!S)continue e;v=S.clone().invert().applyToPoints(p);const O=t.getShapeGeometry(m);t:for(let _=0;_<4;_++)if(f=v[_],y=v[(_+1)%4],O.hitTestLineSegment(f,y,0)){this.handleHit(m,i,E,c,p);break t}}}t.getInstanceState().isCoarsePointer;const k=t.getInstanceState().brush;(!k||!h.equals(k))&&t.updateInstanceState({brush:{...h.toJson()}});const C=t.getSelectedShapeIds();(C.length!==c.size||C.some(I=>!c.has(I)))&&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)&&!nr(r,l)||s.add(a.id)}}g(AA,"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 jA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t,this.updateCursor()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startResizing()});g(this,"onLongPress",()=>{this.startResizing()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(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")}}g(jA,"id","pointing_resize_handle");const mr=8;class h0 extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","");g(this,"snapshot",{});g(this,"onEnter",t=>{this.info=t,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(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(),u=rt(c),h=new w(t.x,t.y),p=new w(0,0),f=1/(c.bottomRight.x-c.topLeft.x)*s.w,y=1/(c.bottomRight.y-c.topLeft.y)*s.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(y<mr)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/y,y*(u.bottomRight.y-u.topLeft.y)<mr?(u.topLeft.y=u.bottomRight.y-mr/y,p.y=(u.topLeft.y-c.topLeft.y)*y):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-c.topLeft.y)*y):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(y<mr)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/y),y*(u.bottomRight.y-u.topLeft.y)<mr&&(u.bottomRight.y=u.topLeft.y+mr/y);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<mr)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<mr?(u.topLeft.x=u.bottomRight.x-mr/f,p.x=(u.topLeft.x-c.topLeft.x)*f):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-c.topLeft.x)*f):p.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(f<mr)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<mr&&(u.bottomRight.x=u.topLeft.x+mr/f);break}}if(!m)return;h.add(p.rot(t.rotation));const x={id:t.id,type:t.type,x:h.x,y:h.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*f,h:(u.bottomRight.y-u.topLeft.y)*y}};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}}}g(h0,"id","cropping");function p0(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 OA(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 qy;let kq=(qy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const t=this.editor.getOnlySelectedShape();t&&this.editor.setCroppingShape(t.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});g(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=p0(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}}}});g(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)}});g(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});g(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});g(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=OA(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},g(qy,"id","idle"),qy);class DA extends se{constructor(){super(...arguments);g(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",t)});g(this,"onPointerUp",t=>{this.editor.setCurrentTool("select.crop.idle",t)})}}g(DA,"id","pointing_crop");class f0 extends se{constructor(){super(...arguments);g(this,"info",{});g(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)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});g(this,"onLongPress",()=>{this.startCropping()});g(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(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"))}}g(f0,"id","pointing_crop_handle");class RA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","translating crop");g(this,"snapshot",{});g(this,"onEnter",t=>{this.info=t,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onKeyDown",t=>{switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}});g(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=OA(this.editor,t,s);i&&this.editor.updateShapes([i])}}g(RA,"id","translating_crop");class cp extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onEnter",()=>{this.didCancel=!1,this.markId=this.editor.history.mark()});g(this,"didCancel",!1);g(this,"onExit",()=>{this.didCancel?this.editor.bailToMark(this.markId):this.editor.history.squashToMark(this.markId)});g(this,"onCancel",()=>{this.didCancel=!0})}}g(cp,"id","crop"),g(cp,"initial","idle"),g(cp,"children",()=>[kq,RA,DA,f0,h0]);class LA extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"initialHandle",{});g(this,"initialAdjacentHandle",null);g(this,"initialPagePoint",{});g(this,"markId","");g(this,"initialPageTransform");g(this,"initialPageRotation");g(this,"info",{});g(this,"isPrecise",!1);g(this,"isPreciseId",null);g(this,"pointingId",null);g(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(u=>u.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=An(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)});g(this,"exactTimeout",-1);g(this,"onPointerMove",()=>{this.update()});g(this,"onKeyDown",()=>{this.update()});g(this,"onKeyUp",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.update(),this.complete()});g(this,"onCancel",()=>{this.cancel()});g(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 I;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:u,inputs:{currentPagePoint:h,shiftKey:p,ctrlKey:f,altKey:y,pointerVelocity:m}}=t,x=this.info.shape,S=t.getShape(r);if(!S)return;const v=t.getShapeUtil(S);let b=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const T=w.Angle(a,b),_=Np(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(S.id))throw Error("Expected a page transform");const O=u.handles.snapHandle({currentShapeId:r,handle:E});O&&(O.nudge.rot(-t.getShapeParentTransform(S).rotation()),b.add(O.nudge),E={...s,x:b.x,y:b.y})}const k=(I=v.onHandleDrag)==null?void 0:I.call(v,S,{handle:E,isPrecise:this.isPrecise||y,initial:x}),C={id:S.id,type:S.type,...k};if(s.type==="vertex"&&this.editor.isShapeOfType(S,"arrow")){const T=An(t,S)[s.id];T?l[0]!==T.toId&&(t.setHintingShapes([T.toId]),this.pointingId=T.toId,this.isPrecise=m.len()<.5||y,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())}k&&t.updateShapes([C])}}g(LA,"id","dragging_handle");function $A(e){return e.isLabel?[e]:e instanceof Kr?e.children.filter(n=>n.isLabel):[]}class FA extends se{constructor(){super(...arguments);g(this,"hitShapeForPointerUp",null);g(this,"onEnter",()=>{const t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Ko(this.editor),this.editor.select(t)});g(this,"onExit",()=>{var s;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null),Ko.cancel();const r=this.editor.getShape(t),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r)});g(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":{Ko(this.editor);return}}});g(this,"onPointerDown",t=>{switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=p0(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=$A(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),this.parent.transition("idle",t));else{this.parent.transition("pointing_shape",t);return}return}break}}this.parent.transition("idle",t),this.editor.root.handleEvent(t)});g(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),Ko(this.editor)}});g(this,"onComplete",t=>{this.parent.transition("idle",t)});g(this,"onCancel",t=>{this.parent.transition("idle",t)})}}g(FA,"id","editing_shape");function wI(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function xf(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(_n(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const _q=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Zy;let Tq=(Zy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Ko(this.editor),this.editor.setCursor({type:"default",rotation:0})});g(this,"onExit",()=>{Ko.cancel()});g(this,"onPointerMove",()=>{Ko(this.editor)});g(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&wI(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=p0(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))&&bI(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}}});g(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")){xf(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){xf(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),u=(i=c.onDoubleClickHandle)==null?void 0:i.call(c,a,l);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}}});g(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))&&bI(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.findShapeAncestor(s,i=>r.includes(i.id))&&(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});g(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});g(this,"onKeyDown",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(xt.editOnType.get()&&!_q.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}}});g(this,"onKeyRepeat",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});g(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}wI(this.editor)&&this.parent.transition("crop",t);break}}});g(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"),yf(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&&nr(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*jq:i:o?Mq:Aq,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))}},g(Zy,"id","idle"),Zy);const Mq=10,Aq=1,jq=5;function bI(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?nr(n,t.corners.map(o=>w.RotWith(o,t.point,r))):t.containsPoint(n)}class NA extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"markId","");g(this,"wasAlreadySelected",!1);g(this,"didDrag",!1);g(this,"info",{});g(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])});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});g(this,"_labelDragOffset",new w(0,0));g(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;if(!t)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=uo(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 u=w.Dist(o.start.point,o.end.point);c=1-w.Dist(o.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:p,angleStart:f}=s.children[0];c=PS(h,f,p,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})});g(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")))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(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")}}g(NA,"id","pointing_arrow_label");class zA extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{const{inputs:t}=this.editor;t.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",t)});g(this,"onPointerUp",()=>{xf(this.editor),this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}g(zA,"id","pointing_canvas");class BA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const o=An(this.editor,r)[t.handle.id];o&&this.editor.setHintingShapes([o.toId])}this.editor.setCursor({type:"grabbing",rotation:0})});g(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerUp",()=>{const{shape:t,handle:r}=this.info;if(this.editor.isShapeOfType(t,"note")){const{editor:o}=this,s=PI(o,t,r,!1);if(s){yf(o,s,!0);return}}this.parent.transition("idle",this.info)});g(this,"onPointerMove",()=>{const{editor:t}=this;t.inputs.isDragging&&this.startDraggingHandle()});g(this,"onLongPress",()=>{this.startDraggingHandle()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(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=PI(t,r,o,!0);if(s){const i=t.getPointInParentSpace(s,t.inputs.originPagePoint).sub(w.Rot(gg.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:()=>{yf(t,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}g(BA,"id","pointing_handle");function PI(e,n,t,r){const o=e.getShapePageTransform(n.id),s=o.point(),i=o.rotation(),l=rA(s,i,n.props.growY,0,n.props.scale)[t.index];if(l)return sA(e,n,l,i,r)}class UA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.updateCursor()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startRotating()});g(this,"onLongPress",()=>{this.startRotating()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(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")}}g(UA,"id","pointing_rotate_handle");class HA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerUp",t=>{xf(this.editor),this.parent.transition("idle",t)});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});g(this,"onLongPress",t=>{this.startTranslating(t)});g(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}});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",t)}cancel(){this.parent.transition("idle")}}g(HA,"id","pointing_selection");class KA extends se{constructor(){super(...arguments);g(this,"hitShape",{});g(this,"hitShapeForPointerUp",{});g(this,"isDoubleClick",!1);g(this,"didSelectOnEnter",!1);g(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),u=this.editor.findShapeAncestor(c,h=>r.includes(h.id));if(this.editor.getShapeUtil(t.shape).onClick||c.id===s||r.includes(c.id)||u||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]))});g(this,"onPointerUp",t=>{var u;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=(u=h.onClick)==null?void 0:u.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=$A(p),y=f.length===1?f[0]:void 0;if(y){const m=this.editor.getPointInShapeSpace(c,i);if(y.bounds.containsPoint(m,0)&&y.hitTestPoint(m)){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(y=>y.id===f)),h.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",t)});g(this,"onDoubleClick",()=>{this.isDoubleClick=!0});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});g(this,"onLongPress",t=>{this.startTranslating(t)});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||(this.editor.focus(),this.parent.transition("translating",t))}cancel(){this.parent.transition("idle")}}g(KA,"id","pointing_shape");class WA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","");g(this,"didHoldCommand",!1);g(this,"creationCursorOffset",{x:0,y:0});g(this,"snapshot",{});g(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()});g(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onKeyDown",()=>{this.updateShapes()});g(this,"onKeyUp",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()});g(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 y=this.editor.getShape(f);if(y&&(l.set(y.id,this._createShapeSnapshot(y)),this.editor.isShapeOfType(y,"frame")))return!1})}});const u=![...l.values()].some(h=>!N_(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});g(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:u}=this.snapshot;let h=r||!u;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),y=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:T}=this.editor.getDocumentSettings();f.snapToGrid(T)}const m=this.info.handle,x=CI(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ge===0){const{nudge:T}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:w.Sub(f,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:CI(m,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(y,v).rot(-c),k=w.DivV(b,E);Number.isFinite(k.x)||(k.x=1),Number.isFinite(k.y)||(k.y=1);const C=m==="top"||m==="bottom",I=m==="left"||m==="right";h?I?k.y=Math.abs(k.x):C?k.x=Math.abs(k.y):Math.abs(k.x)>Math.abs(k.y)?k.y=Math.abs(k.x)*(k.y<0?-1:1):k.x=Math.abs(k.y)*(k.x<0?-1:1):(C&&(k.x=1),I&&(k.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:k.x<0,isFlippedY:k.y<0,rotation:c});for(const T of s.keys()){const O=s.get(T);this.editor.resizeShape(T,k,{initialShape:O.shape,initialBounds:O.bounds,initialPageTransform:O.pageTransform,dragHandle:m,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,M=this.editor.getShape(T);if(!(_&&M))continue;const L=M.x-_.x,j=M.y-_.y,R=new w(L,j).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)}}g(WA,"id","resizing");const fy=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function CI(e,n){n=n%Re;const t=Math.round(n/(ke/4)),r=fy.indexOf(e);return fy[(r+t)%fy.length]}const II=Math.PI/180;class GA extends se{constructor(){super(...arguments);g(this,"snapshot",{});g(this,"info",{});g(this,"markId","");g(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});Dh({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})});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});g(this,"onPointerMove",()=>{this.update()});g(this,"onKeyDown",()=>{this.update()});g(this,"onKeyUp",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"update",()=>{const t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Dh({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:bl[this.info.handle],rotation:t+this.snapshot.initialSelectionRotation})});g(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});g(this,"complete",()=>{Dh({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 u=o.center.clone().rotWith(o.point,r).angle(i)-a;let h=l+u;if(s)h=Np(h,24);else if(t&&(h=Math.round(h/II)*II,this.editor.getInstanceState().isCoarsePointer)){const p=Np(h,4),f=wh(h,p);Math.abs(f)<Y6(5)&&(h=p)}return h-l}}g(GA,"id","rotating");class VA extends se{constructor(){super(...arguments);g(this,"hits",new Set);g(this,"size",0);g(this,"scribbleId","id");g(this,"initialSelectedShapeIds",new Set);g(this,"newlySelectedShapeIds",new Set);g(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})});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});g(this,"onPointerUp",()=>{this.complete()});g(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});g(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(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:u}=this;t&&this.pushPointToScribble();const h=o;let p,f,y,m;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 k=r.getShapePageTransform(p);if(!f||!k)continue;const C=k.clone().invert();y=C.applyToPoint(a),m=C.applyToPoint(l);const{bounds:I}=f;if(!(I.minX-x>Math.max(y.x,m.x)||I.minY-x>Math.max(y.y,m.y)||I.maxX+x<Math.min(y.x,m.x)||I.maxY+x<Math.min(y.y,m.y))&&f.hitTestLineSegment(y,m,x)){const T=this.editor.getOutermostSelectableShape(p),O=this.editor.getShapeMask(T.id);if(O&&Ww(a,l,O)!==null&&!nr(l,O))continue;c.add(T.id)}}const S=r.getSelectedShapeIds(),v=new Set(s?[...c,...u]:[...c]);(S.length!==v.size||S.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")}}g(VA,"id","scribble_brushing");const Oq=20,Dq=100;class Rq{constructor(n){g(this,"prevDroppingShapeId",null);g(this,"droppingNodeTimer",null);g(this,"first",!0);g(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,Oq,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(n,Dq,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,u,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&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,t)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,a,t)),this.hintParents(t),r==null||r(),this.prevDroppingShapeId=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&&eA(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 YA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"selectionSnapshot",{});g(this,"snapshot",{});g(this,"markId","");g(this,"isCloning",!1);g(this,"isCreating",!1);g(this,"onCreate",()=>{});g(this,"dragAndDropManager",new Rq(this.editor));g(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=EI(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});g(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()});g(this,"onTick",({elapsed:t})=>{const{editor:r}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),r.edgeScrollManager.updateEdgeScrolling(t)});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});g(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(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=En(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=EI(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),Lq({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)}}g(YA,"id","translating");function EI(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 y=e.getShapePageTransform(p),m=y.point(),x=y.rotation();t.push(m);const S=Zo.isId(f.parentId)?null:oe.Inverse(e.getShapePageTransform(f.parentId));return{shape:f,pagePoint:m,pageRotation:x,parentTransform:S}})),s=e.getOnlySelectedShape();let i=[];if(s)i=e.snaps.shapeBounds.getSnapPoints(s.id);else{const p=e.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((f,y)=>({id:"selection:"+y,x:f.x,y:f.y})))}let a,l;const{originPagePoint:c}=e.inputs,u=o.filter(p=>e.isShapeOfType(p.shape,"note")&&e.isPointInShape(p.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const p=e.getCurrentPageShapesSorted();l=(h=u.map(f=>({snapshot:f,index:p.findIndex(y=>y.id===f.shape.id)})).sort((f,y)=>y.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=oA(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 Lq({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,u=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,S=r.pagePoint.clone().add(h).add(gg.clone().mul(x).rot(r.pageRotation));let v=nA/e.getZoomLevel(),b=new w(0,0);for(const E of o){const k=w.Sub(S,E),C=k.len();C<v&&(v=C,b=k)}h.sub(b)}const y=w.Add(l,h);c&&!t.ctrlKey&&y.snapToGrid(u);const m=w.Sub(y,l);e.updateShapes(me(a.map(({shape:x,pagePoint:S,parentTransform:v})=>{const b=w.Add(S,m),E=v?oe.applyToPoint(v,b):b;return{id:x.id,type:x.type,x:E.x,y:E.y}})))}class up extends se{constructor(){super(...arguments);g(this,"reactor");g(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})});g(this,"onEnter",()=>{this.reactor=oa("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(t){typeof process<"u",console.error(t)}})});g(this,"onExit",()=>{var t;(t=this.reactor)==null||t.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}g(up,"id","select"),g(up,"initial","idle"),g(up,"children",()=>[cp,h0,Tq,zA,KA,YA,AA,VA,f0,HA,jA,FA,WA,GA,UA,NA,BA,LA]);class XA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}g(XA,"id","idle");class qA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerUp",()=>{this.complete()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});g(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)}}g(qA,"id","pointing");class ZA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"zoomBrush",new Z);g(this,"onEnter",t=>{this.info=t,this.update()});g(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(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)}}g(ZA,"id","zoom_brushing");class dp extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.updateCursor()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onKeyDown",()=>{this.updateCursor()});g(this,"onKeyUp",t=>{this.updateCursor(),t.code==="KeyZ"&&this.complete()});g(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})}}g(dp,"id","zoom"),g(dp,"initial","idle"),g(dp,"children",()=>[XA,ZA,qA]);const $q=[ip,ap,lp,dp,up];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 Fq(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function vg(...e){return n=>e.forEach(t=>Fq(t,n))}function Ye(...e){return P.useCallback(vg(...e),e)}function Nq(e,n){const t=P.createContext(n);function r(s){const{children:i,...a}=s,l=P.useMemo(()=>a,Object.values(a));return d.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 ko(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,...y}=h,m=(p==null?void 0:p[e][l])||a,x=P.useMemo(()=>y,Object.values(y));return d.jsx(m.Provider,{value:x,children:f})}function u(h,p){const f=(p==null?void 0:p[e][l])||a,y=P.useContext(f);if(y)return y;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,u]}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,zq(o,...n)]}function zq(...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:()=>{},Bq=g$.useId||(()=>{}),Uq=0;function Xo(e){const[n,t]=P.useState(Bq());return Xs(()=>{e||t(r=>r??String(Uq++))},[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]=Hq({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 Hq({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(Wq);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 d.jsx(Rv,{...r,ref:n,children:P.isValidElement(i)?P.cloneElement(i,void 0,a):null})}return d.jsx(Rv,{...r,ref:n,children:t})});Xi.displayName="Slot";var Rv=P.forwardRef((e,n)=>{const{children:t,...r}=e;if(P.isValidElement(t)){const o=Vq(t);return P.cloneElement(t,{...Gq(r,t.props),ref:n?vg(n,o):o})}return P.Children.count(t)>1?P.Children.only(null):null});Rv.displayName="SlotClone";var Kq=({children:e})=>d.jsx(d.Fragment,{children:e});function Wq(e){return P.isValidElement(e)&&e.type===Kq}function Gq(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 Vq(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 Yq=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ce=Yq.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),d.jsx(a,{...i,ref:o})});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function g0(e,n){e&&aa.flushSync(()=>e.dispatchEvent(n))}function Xq(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 qq="DismissableLayer",Lv="dismissableLayer.update",Zq="dismissableLayer.pointerDownOutside",Qq="dismissableLayer.focusOutside",kI,QA=P.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Wu=P.forwardRef((e,n)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=P.useContext(QA),[u,h]=P.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=P.useState({}),y=Ye(n,I=>h(I)),m=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=m.indexOf(x),v=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,E=v>=S,k=eZ(I=>{const T=I.target,O=[...c.branches].some(_=>_.contains(T));!E||O||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),C=tZ(I=>{const T=I.target;[...c.branches].some(_=>_.contains(T))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return Xq(I=>{v===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),P.useEffect(()=>{if(u)return t&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(kI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),_I(),()=>{t&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=kI)}},[u,p,t,c]),P.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),_I())},[u,c]),P.useEffect(()=>{const I=()=>f({});return document.addEventListener(Lv,I),()=>document.removeEventListener(Lv,I)},[]),d.jsx(Ce.div,{...l,ref:y,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,k.onPointerDownCapture)})});Wu.displayName=qq;var Jq="DismissableLayerBranch",JA=P.forwardRef((e,n)=>{const t=P.useContext(QA),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]),d.jsx(Ce.div,{...e,ref:o})});JA.displayName=Jq;function eZ(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(){ej(Zq,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 tZ(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&&ej(Qq,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 _I(){const e=new CustomEvent(Lv);document.dispatchEvent(e)}function ej(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?g0(o,s):o.dispatchEvent(s)}var nZ=Wu,rZ=JA,gy="focusScope.autoFocusOnMount",my="focusScope.autoFocusOnUnmount",TI={bubbles:!1,cancelable:!0},oZ="FocusScope",xg=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),u=Vt(s),h=P.useRef(null),p=Ye(n,m=>l(m)),f=P.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;P.useEffect(()=>{if(r){let m=function(b){if(f.paused||!a)return;const E=b.target;a.contains(E)?h.current=E:ws(h.current,{select:!0})},x=function(b){if(f.paused||!a)return;const E=b.relatedTarget;E!==null&&(a.contains(E)||ws(h.current,{select:!0}))},S=function(b){if(document.activeElement===document.body)for(const k of b)k.removedNodes.length>0&&ws(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",x);const v=new MutationObserver(S);return a&&v.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",x),v.disconnect()}}},[r,a,f.paused]),P.useEffect(()=>{if(a){AI.add(f);const m=document.activeElement;if(!a.contains(m)){const S=new CustomEvent(gy,TI);a.addEventListener(gy,c),a.dispatchEvent(S),S.defaultPrevented||(sZ(uZ(tj(a)),{select:!0}),document.activeElement===m&&ws(a))}return()=>{a.removeEventListener(gy,c),setTimeout(()=>{const S=new CustomEvent(my,TI);a.addEventListener(my,u),a.dispatchEvent(S),S.defaultPrevented||ws(m??document.body,{select:!0}),a.removeEventListener(my,u),AI.remove(f)},0)}}},[a,c,u,f]);const y=P.useCallback(m=>{if(!t&&!r||f.paused)return;const x=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,S=document.activeElement;if(x&&S){const v=m.currentTarget,[b,E]=iZ(v);b&&E?!m.shiftKey&&S===E?(m.preventDefault(),t&&ws(b,{select:!0})):m.shiftKey&&S===b&&(m.preventDefault(),t&&ws(E,{select:!0})):S===v&&m.preventDefault()}},[t,r,f.paused]);return d.jsx(Ce.div,{tabIndex:-1,...i,ref:p,onKeyDown:y})});xg.displayName=oZ;function sZ(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(ws(r,{select:n}),document.activeElement!==t)return}function iZ(e){const n=tj(e),t=MI(n,e),r=MI(n.reverse(),e);return[t,r]}function tj(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 MI(e,n){for(const t of e)if(!aZ(t,{upTo:n}))return t}function aZ(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 lZ(e){return e instanceof HTMLInputElement&&"select"in e}function ws(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&lZ(e)&&n&&e.select()}}var AI=cZ();function cZ(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=jI(e,n),e.unshift(n)},remove(n){var t;e=jI(e,n),(t=e[0])==null||t.resume()}}}function jI(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function uZ(e){return e.filter(n=>n.tagName!=="A")}var dZ="Portal",Gu=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?kW.createPortal(d.jsx(Ce.div,{...r,ref:n}),i):null});Gu.displayName=dZ;function hZ(e,n){return P.useReducer((t,r)=>n[t][r]??t,e)}var Xr=e=>{const{present:n,children:t}=e,r=pZ(n),o=typeof t=="function"?t({present:r.isPresent}):P.Children.only(t),s=Ye(r.ref,fZ(o));return typeof t=="function"||r.isPresent?P.cloneElement(o,{ref:s}):null};Xr.displayName="Presence";function pZ(e){const[n,t]=P.useState(),r=P.useRef({}),o=P.useRef(e),s=P.useRef("none"),i=e?"mounted":"unmounted",[a,l]=hZ(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return P.useEffect(()=>{const c=eh(r.current);s.current=a==="mounted"?c:"none"},[a]),Xs(()=>{const c=r.current,u=o.current;if(u!==e){const p=s.current,f=eh(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&p!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Xs(()=>{if(n){const c=h=>{const f=eh(r.current).includes(h.animationName);h.target===n&&f&&aa.flushSync(()=>l("ANIMATION_END"))},u=h=>{h.target===n&&(s.current=eh(r.current))};return n.addEventListener("animationstart",u),n.addEventListener("animationcancel",c),n.addEventListener("animationend",c),()=>{n.removeEventListener("animationstart",u),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 eh(e){return(e==null?void 0:e.animationName)||"none"}function fZ(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 yy=0;function m0(){P.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??OI()),document.body.insertAdjacentElement("beforeend",e[1]??OI()),yy++,()=>{yy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(n=>n.remove()),yy--}},[])}function OI(){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 ao=function(){return ao=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},ao.apply(this,arguments)};function nj(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 gZ(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 hp="right-scroll-bar-position",pp="width-before-scroll-bar",mZ="with-scroll-bars-hidden",yZ="--removed-body-scroll-bar-size";function Sy(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function SZ(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 vZ=typeof window<"u"?P.useLayoutEffect:P.useEffect,DI=new WeakMap;function xZ(e,n){var t=SZ(null,function(r){return e.forEach(function(o){return Sy(o,r)})});return vZ(function(){var r=DI.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||Sy(a,null)}),s.forEach(function(a){o.has(a)||Sy(a,i)})}DI.set(t,e)},[e]),t}function wZ(e){return e}function bZ(e,n){n===void 0&&(n=wZ);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 u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),t={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),t}}}};return o}function PZ(e){e===void 0&&(e={});var n=bZ(null);return n.options=ao({async:!0,ssr:!1},e),n}var rj=function(e){var n=e.sideCar,t=nj(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,ao({},t))};rj.isSideCarExport=!0;function CZ(e,n){return e.useMedium(n),rj}var oj=PZ(),vy=function(){},wg=P.forwardRef(function(e,n){var t=P.useRef(null),r=P.useState({onScrollCapture:vy,onWheelCapture:vy,onTouchMoveCapture:vy}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,h=e.shards,p=e.sideCar,f=e.noIsolation,y=e.inert,m=e.allowPinchZoom,x=e.as,S=x===void 0?"div":x,v=e.gapMode,b=nj(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=p,k=xZ([t,n]),C=ao(ao({},b),o);return P.createElement(P.Fragment,null,u&&P.createElement(E,{sideCar:oj,removeScrollBar:c,shards:h,noIsolation:f,inert:y,setCallbacks:s,allowPinchZoom:!!m,lockRef:t,gapMode:v}),i?P.cloneElement(P.Children.only(a),ao(ao({},C),{ref:k})):P.createElement(S,ao({},C,{className:l,ref:k}),a))});wg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};wg.classNames={fullWidth:pp,zeroRight:hp};var IZ=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function EZ(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=IZ();return n&&e.setAttribute("nonce",n),e}function kZ(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function _Z(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var TZ=function(){var e=0,n=null;return{add:function(t){e==0&&(n=EZ())&&(kZ(n,t),_Z(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},MZ=function(){var e=TZ();return function(n,t){P.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},sj=function(){var e=MZ(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},AZ={left:0,top:0,right:0,gap:0},xy=function(e){return parseInt(e||"",10)||0},jZ=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[xy(t),xy(r),xy(o)]},OZ=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return AZ;var n=jZ(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])}},DZ=sj(),ol="data-scroll-locked",RZ=function(e,n,t,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return t===void 0&&(t="margin"),`
159
+ .`.concat(mZ,` {
160
+ overflow: hidden `).concat(r,`;
161
+ padding-right: `).concat(a,"px ").concat(r,`;
162
+ }
163
+ body[`).concat(ol,`] {
164
+ overflow: hidden `).concat(r,`;
165
+ overscroll-behavior: contain;
166
+ `).concat([n&&"position: relative ".concat(r,";"),t==="margin"&&`
167
+ padding-left: `.concat(o,`px;
168
+ padding-top: `).concat(s,`px;
169
+ padding-right: `).concat(i,`px;
170
+ margin-left:0;
171
+ margin-top:0;
172
+ margin-right: `).concat(a,"px ").concat(r,`;
173
+ `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
174
+ }
175
+
176
+ .`).concat(hp,` {
177
+ right: `).concat(a,"px ").concat(r,`;
178
+ }
179
+
180
+ .`).concat(pp,` {
181
+ margin-right: `).concat(a,"px ").concat(r,`;
182
+ }
183
+
184
+ .`).concat(hp," .").concat(hp,` {
185
+ right: 0 `).concat(r,`;
186
+ }
187
+
188
+ .`).concat(pp," .").concat(pp,` {
189
+ margin-right: 0 `).concat(r,`;
190
+ }
191
+
192
+ body[`).concat(ol,`] {
193
+ `).concat(yZ,": ").concat(a,`px;
194
+ }
195
+ `)},RI=function(){var e=parseInt(document.body.getAttribute(ol)||"0",10);return isFinite(e)?e:0},LZ=function(){P.useEffect(function(){return document.body.setAttribute(ol,(RI()+1).toString()),function(){var e=RI()-1;e<=0?document.body.removeAttribute(ol):document.body.setAttribute(ol,e.toString())}},[])},$Z=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;LZ();var s=P.useMemo(function(){return OZ(o)},[o]);return P.createElement(DZ,{styles:RZ(s,!n,o,t?"":"!important")})},$v=!1;if(typeof window<"u")try{var th=Object.defineProperty({},"passive",{get:function(){return $v=!0,!0}});window.addEventListener("test",th,th),window.removeEventListener("test",th,th)}catch{$v=!1}var va=$v?{passive:!1}:!1,FZ=function(e){return e.tagName==="TEXTAREA"},ij=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!FZ(e)&&t[n]==="visible")},NZ=function(e){return ij(e,"overflowY")},zZ=function(e){return ij(e,"overflowX")},LI=function(e,n){var t=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=aj(e,r);if(o){var s=lj(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},BZ=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},UZ=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},aj=function(e,n){return e==="v"?NZ(n):zZ(n)},lj=function(e,n){return e==="v"?BZ(n):UZ(n)},HZ=function(e,n){return e==="h"&&n==="rtl"?-1:1},KZ=function(e,n,t,r,o){var s=HZ(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,l=n.contains(a),c=!1,u=i>0,h=0,p=0;do{var f=lj(e,a),y=f[0],m=f[1],x=f[2],S=m-x-s*y;(y||S)&&aj(e,a)&&(h+=S,p+=y),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(n.contains(a)||n===a));return(u&&(Math.abs(h)<1||!o)||!u&&(Math.abs(p)<1||!o))&&(c=!0),c},nh=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},$I=function(e){return[e.deltaX,e.deltaY]},FI=function(e){return e&&"current"in e?e.current:e},WZ=function(e,n){return e[0]===n[0]&&e[1]===n[1]},GZ=function(e){return`
196
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
197
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
198
+ `)},VZ=0,xa=[];function YZ(e){var n=P.useRef([]),t=P.useRef([0,0]),r=P.useRef(),o=P.useState(VZ++)[0],s=P.useState(sj)[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 m=gZ([e.lockRef.current],(e.shards||[]).map(FI),!0).filter(Boolean);return m.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=P.useCallback(function(m,x){if("touches"in m&&m.touches.length===2)return!i.current.allowPinchZoom;var S=nh(m),v=t.current,b="deltaX"in m?m.deltaX:v[0]-S[0],E="deltaY"in m?m.deltaY:v[1]-S[1],k,C=m.target,I=Math.abs(b)>Math.abs(E)?"h":"v";if("touches"in m&&I==="h"&&C.type==="range")return!1;var T=LI(I,C);if(!T)return!0;if(T?k=I:(k=I==="v"?"h":"v",T=LI(I,C)),!T)return!1;if(!r.current&&"changedTouches"in m&&(b||E)&&(r.current=k),!k)return!0;var O=r.current||k;return KZ(O,x,m,O==="h"?b:E,!0)},[]),l=P.useCallback(function(m){var x=m;if(!(!xa.length||xa[xa.length-1]!==s)){var S="deltaY"in x?$I(x):nh(x),v=n.current.filter(function(k){return k.name===x.type&&(k.target===x.target||x.target===k.shadowParent)&&WZ(k.delta,S)})[0];if(v&&v.should){x.cancelable&&x.preventDefault();return}if(!v){var b=(i.current.shards||[]).map(FI).filter(Boolean).filter(function(k){return k.contains(x.target)}),E=b.length>0?a(x,b[0]):!i.current.noIsolation;E&&x.cancelable&&x.preventDefault()}}},[]),c=P.useCallback(function(m,x,S,v){var b={name:m,delta:x,target:S,should:v,shadowParent:XZ(S)};n.current.push(b),setTimeout(function(){n.current=n.current.filter(function(E){return E!==b})},1)},[]),u=P.useCallback(function(m){t.current=nh(m),r.current=void 0},[]),h=P.useCallback(function(m){c(m.type,$I(m),m.target,a(m,e.lockRef.current))},[]),p=P.useCallback(function(m){c(m.type,nh(m),m.target,a(m,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",u,va),function(){xa=xa.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,va),document.removeEventListener("touchmove",l,va),document.removeEventListener("touchstart",u,va)}},[]);var f=e.removeScrollBar,y=e.inert;return P.createElement(P.Fragment,null,y?P.createElement(s,{styles:GZ(o)}):null,f?P.createElement($Z,{gapMode:e.gapMode}):null)}function XZ(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const qZ=CZ(oj,YZ);var bg=P.forwardRef(function(e,n){return P.createElement(wg,ao({},e,{ref:n,sideCar:qZ}))});bg.classNames=wg.classNames;var ZZ=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},wa=new WeakMap,rh=new WeakMap,oh={},wy=0,cj=function(e){return e&&(e.host||cj(e.parentNode))},QZ=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=cj(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})},JZ=function(e,n,t,r){var o=QZ(n,Array.isArray(e)?e:[e]);oh[t]||(oh[t]=new WeakMap);var s=oh[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 u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(p){if(a.has(p))u(p);else try{var f=p.getAttribute(r),y=f!==null&&f!=="false",m=(wa.get(p)||0)+1,x=(s.get(p)||0)+1;wa.set(p,m),s.set(p,x),i.push(p),m===1&&y&&rh.set(p,!0),x===1&&p.setAttribute(t,"true"),y||p.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",p,S)}})};return u(n),a.clear(),wy++,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||(rh.has(h)||h.removeAttribute(r),rh.delete(h)),f||h.removeAttribute(t)}),wy--,wy||(wa=new WeakMap,wa=new WeakMap,rh=new WeakMap,oh={})}},y0=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=ZZ(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),JZ(r,o,t,"aria-hidden")):function(){return null}},S0="Dialog",[uj,qie]=ko(S0),[eQ,qr]=uj(S0),dj=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,u]=li({prop:r,defaultProp:o,onChange:s});return d.jsx(eQ,{scope:n,triggerRef:a,contentRef:l,contentId:Xo(),titleId:Xo(),descriptionId:Xo(),open:c,onOpenChange:u,onOpenToggle:P.useCallback(()=>u(h=>!h),[u]),modal:i,children:t})};dj.displayName=S0;var hj="DialogTrigger",tQ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(hj,t),s=Ye(n,o.triggerRef);return d.jsx(Ce.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":w0(o.open),...r,ref:s,onClick:re(e.onClick,o.onOpenToggle)})});tQ.displayName=hj;var v0="DialogPortal",[nQ,pj]=uj(v0,{forceMount:void 0}),fj=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=qr(v0,n);return d.jsx(nQ,{scope:n,forceMount:t,children:P.Children.map(r,i=>d.jsx(Xr,{present:t||s.open,children:d.jsx(Gu,{asChild:!0,container:o,children:i})}))})};fj.displayName=v0;var wf="DialogOverlay",gj=P.forwardRef((e,n)=>{const t=pj(wf,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=qr(wf,e.__scopeDialog);return s.modal?d.jsx(Xr,{present:r||s.open,children:d.jsx(rQ,{...o,ref:n})}):null});gj.displayName=wf;var rQ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(wf,t);return d.jsx(bg,{as:Xi,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ce.div,{"data-state":w0(o.open),...r,ref:n,style:{pointerEvents:"auto",...r.style}})})}),qi="DialogContent",mj=P.forwardRef((e,n)=>{const t=pj(qi,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=qr(qi,e.__scopeDialog);return d.jsx(Xr,{present:r||s.open,children:s.modal?d.jsx(oQ,{...o,ref:n}):d.jsx(sQ,{...o,ref:n})})});mj.displayName=qi;var oQ=P.forwardRef((e,n)=>{const t=qr(qi,e.__scopeDialog),r=P.useRef(null),o=Ye(n,t.contentRef,r);return P.useEffect(()=>{const s=r.current;if(s)return y0(s)},[]),d.jsx(yj,{...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())})}),sQ=P.forwardRef((e,n)=>{const t=qr(qi,e.__scopeDialog),r=P.useRef(!1),o=P.useRef(!1);return d.jsx(yj,{...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()}})}),yj=P.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=qr(qi,t),l=P.useRef(null),c=Ye(n,l);return m0(),d.jsxs(d.Fragment,{children:[d.jsx(xg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Wu,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":w0(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(aQ,{titleId:a.titleId}),d.jsx(cQ,{contentRef:l,descriptionId:a.descriptionId})]})]})}),x0="DialogTitle",Sj=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(x0,t);return d.jsx(Ce.h2,{id:o.titleId,...r,ref:n})});Sj.displayName=x0;var vj="DialogDescription",iQ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(vj,t);return d.jsx(Ce.p,{id:o.descriptionId,...r,ref:n})});iQ.displayName=vj;var xj="DialogClose",wj=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(xj,t);return d.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,()=>o.onOpenChange(!1))})});wj.displayName=xj;function w0(e){return e?"open":"closed"}var bj="DialogTitleWarning",[Zie,Pj]=Nq(bj,{contentName:qi,titleName:x0,docsSlug:"dialog"}),aQ=({titleId:e})=>{const n=Pj(bj),t=`\`${n.contentName}\` requires a \`${n.titleName}\` for the component to be accessible for screen reader users.
199
+
200
+ If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
201
+
202
+ 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},lQ="DialogDescriptionWarning",cQ=({contentRef:e,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Pj(lQ).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},uQ=dj,dQ=fj,hQ=gj,pQ=mj;const Cj=()=>{},Ij=P.createContext(null);function fQ({onEvent:e,children:n}){return d.jsx(Ij.Provider,{value:e??Cj,children:n})}function Zr(){return P.useContext(Ij)??Cj}const Ej=P.createContext(null);function gQ({children:e}){const n=B(),t=Zr(),[r,o]=P.useState([]),s=P.useCallback(c=>{const u=c.id??ot();return o(h=>[...h.filter(p=>p.id!==c.id),{...c,id:u}]),t("open-menu",{source:"dialog",id:u}),n.addOpenMenu(u),u},[n,t]),i=P.useCallback((c,u)=>(o(h=>h.map(p=>p.id===c?{...p,...u}:p)),t("open-menu",{source:"dialog",id:c}),n.addOpenMenu(c),c),[n,t]),a=P.useCallback(c=>(o(u=>u.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(u=>{var h;(h=u.onClose)==null||h.call(u),t("close-menu",{source:"dialog",id:u.id}),n.deleteOpenMenu(u.id)}),[]))},[n,t]);return d.jsx(Ej.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function la(){const e=P.useContext(Ej);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const mQ=({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 d.jsx(uQ,{onOpenChange:s,defaultOpen:!0,children:d.jsx(dQ,{container:o,children:d.jsx(hQ,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:d.jsx(pQ,{dir:"ltr",className:"tlui-dialog__content",children:d.jsx(n,{onClose:()=>s(!1)})})})})})};function yQ(){const{dialogs:e}=la();return e.map(n=>d.jsx(mQ,{...n},n.id))}const SQ=we.memo(yQ);function vQ(){const e=B(),n=G("follow",()=>e.getInstanceState().followingUserId,[e]);return n?d.jsx(xQ,{userId:n}):null}function xQ({userId:e}){const n=tT(e);return n?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function Pg(e){const n=e+"CollectionProvider",[t,r]=ko(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:y,children:m}=f,x=we.useRef(null),S=we.useRef(new Map).current;return d.jsx(o,{scope:y,itemMap:S,collectionRef:x,children:m})};i.displayName=n;const a=e+"CollectionSlot",l=we.forwardRef((f,y)=>{const{scope:m,children:x}=f,S=s(a,m),v=Ye(y,S.collectionRef);return d.jsx(Xi,{ref:v,children:x})});l.displayName=a;const c=e+"CollectionItemSlot",u="data-radix-collection-item",h=we.forwardRef((f,y)=>{const{scope:m,children:x,...S}=f,v=we.useRef(null),b=Ye(y,v),E=s(c,m);return we.useEffect(()=>(E.itemMap.set(v,{ref:v,...S}),()=>void E.itemMap.delete(v))),d.jsx(Xi,{[u]:"",ref:b,children:x})});h.displayName=c;function p(f){const y=s(e+"CollectionConsumer",f);return we.useCallback(()=>{const x=y.collectionRef.current;if(!x)return[];const S=Array.from(x.querySelectorAll(`[${u}]`));return Array.from(y.itemMap.values()).sort((E,k)=>S.indexOf(E.ref.current)-S.indexOf(k.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var wQ="VisuallyHidden",b0=P.forwardRef((e,n)=>d.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}}));b0.displayName=wQ;var P0="ToastProvider",[C0,bQ,PQ]=Pg("Toast"),[kj,Qie]=ko("Toast",[PQ]),[CQ,Cg]=kj(P0),_j=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,u]=P.useState(0),h=P.useRef(!1),p=P.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${P0}\`. Expected non-empty \`string\`.`),d.jsx(C0.Provider,{scope:n,children:d.jsx(CQ,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:P.useCallback(()=>u(f=>f+1),[]),onToastRemove:P.useCallback(()=>u(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:p,children:i})})};_j.displayName=P0;var Tj="ToastViewport",IQ=["F8"],Fv="toast.viewportPause",Nv="toast.viewportResume",Mj=P.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=IQ,label:o="Notifications ({hotkey})",...s}=e,i=Cg(Tj,t),a=bQ(t),l=P.useRef(null),c=P.useRef(null),u=P.useRef(null),h=P.useRef(null),p=Ye(n,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=i.toastCount>0;P.useEffect(()=>{const x=S=>{var b;r.every(E=>S[E]||S.code===E)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),P.useEffect(()=>{const x=l.current,S=h.current;if(y&&x&&S){const v=()=>{if(!i.isClosePausedRef.current){const C=new CustomEvent(Fv);S.dispatchEvent(C),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const C=new CustomEvent(Nv);S.dispatchEvent(C),i.isClosePausedRef.current=!1}},E=C=>{!x.contains(C.relatedTarget)&&b()},k=()=>{x.contains(document.activeElement)||b()};return x.addEventListener("focusin",v),x.addEventListener("focusout",E),x.addEventListener("pointermove",v),x.addEventListener("pointerleave",k),window.addEventListener("blur",v),window.addEventListener("focus",b),()=>{x.removeEventListener("focusin",v),x.removeEventListener("focusout",E),x.removeEventListener("pointermove",v),x.removeEventListener("pointerleave",k),window.removeEventListener("blur",v),window.removeEventListener("focus",b)}}},[y,i.isClosePausedRef]);const m=P.useCallback(({tabbingDirection:x})=>{const v=a().map(b=>{const E=b.ref.current,k=[E,...FQ(E)];return x==="forwards"?k:k.reverse()});return(x==="forwards"?v.reverse():v).flat()},[a]);return P.useEffect(()=>{const x=h.current;if(x){const S=v=>{var k,C,I;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){(k=c.current)==null||k.focus();return}const L=m({tabbingDirection:O?"backwards":"forwards"}),j=L.findIndex(R=>R===T);by(L.slice(j+1))?v.preventDefault():O?(C=c.current)==null||C.focus():(I=u.current)==null||I.focus()}};return x.addEventListener("keydown",S),()=>x.removeEventListener("keydown",S)}},[a,m]),d.jsxs(rZ,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:y?void 0:"none"},children:[y&&d.jsx(zv,{ref:c,onFocusFromOutsideViewport:()=>{const x=m({tabbingDirection:"forwards"});by(x)}}),d.jsx(C0.Slot,{scope:t,children:d.jsx(Ce.ol,{tabIndex:-1,...s,ref:p})}),y&&d.jsx(zv,{ref:u,onFocusFromOutsideViewport:()=>{const x=m({tabbingDirection:"backwards"});by(x)}})]})});Mj.displayName=Tj;var Aj="ToastFocusProxy",zv=P.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=Cg(Aj,t);return d.jsx(b0,{"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()}})});zv.displayName=Aj;var Ig="Toast",EQ="toast.swipeStart",kQ="toast.swipeMove",_Q="toast.swipeCancel",TQ="toast.swipeEnd",jj=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 d.jsx(Xr,{present:t||a,children:d.jsx(jQ,{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:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:re(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:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});jj.displayName=Ig;var[MQ,AQ]=kj(Ig,{onClose(){}}),jQ=P.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:f,...y}=e,m=Cg(Ig,t),[x,S]=P.useState(null),v=Ye(n,R=>S(R)),b=P.useRef(null),E=P.useRef(null),k=o||m.duration,C=P.useRef(0),I=P.useRef(k),T=P.useRef(0),{onToastAdd:O,onToastRemove:_}=m,M=Vt(()=>{var F;(x==null?void 0:x.contains(document.activeElement))&&((F=m.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(M,R))},[M]);P.useEffect(()=>{const R=m.viewport;if(R){const F=()=>{L(I.current),c==null||c()},W=()=>{const K=new Date().getTime()-C.current;I.current=I.current-K,window.clearTimeout(T.current),l==null||l()};return R.addEventListener(Fv,W),R.addEventListener(Nv,F),()=>{R.removeEventListener(Fv,W),R.removeEventListener(Nv,F)}}},[m.viewport,k,l,c,L]),P.useEffect(()=>{s&&!m.isClosePausedRef.current&&L(k)},[s,k,m.isClosePausedRef,L]),P.useEffect(()=>(O(),()=>_()),[O,_]);const j=P.useMemo(()=>x?Nj(x):null,[x]);return m.viewport?d.jsxs(d.Fragment,{children:[j&&d.jsx(OQ,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:j}),d.jsx(MQ,{scope:t,onClose:M,children:aa.createPortal(d.jsx(C0.ItemSlot,{scope:t,children:d.jsx(nZ,{asChild:!0,onEscapeKeyDown:re(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||M(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ce.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":m.swipeDirection,...y,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||(m.isFocusedToastEscapeKeyDownRef.current=!0,M()))}),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(m.swipeDirection),U=["left","up"].includes(m.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,sh(kQ,h,Me,{discrete:!1})):NI(ye,m.swipeDirection,le)?(E.current=ye,sh(EQ,u,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};NI(F,m.swipeDirection,m.swipeThreshold)?sh(TQ,f,z,{discrete:!0}):sh(_Q,p,z,{discrete:!0}),K.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),OQ=e=>{const{__scopeToast:n,children:t,...r}=e,o=Cg(Ig,n),[s,i]=P.useState(!1),[a,l]=P.useState(!1);return LQ(()=>i(!0)),P.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(Gu,{asChild:!0,children:d.jsx(b0,{...r,children:s&&d.jsxs(d.Fragment,{children:[o.label," ",t]})})})},DQ="ToastTitle",Oj=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return d.jsx(Ce.div,{...r,ref:n})});Oj.displayName=DQ;var RQ="ToastDescription",Dj=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return d.jsx(Ce.div,{...r,ref:n})});Dj.displayName=RQ;var Rj="ToastAction",Lj=P.forwardRef((e,n)=>{const{altText:t,...r}=e;return t.trim()?d.jsx(Fj,{altText:t,asChild:!0,children:d.jsx(I0,{...r,ref:n})}):(console.error(`Invalid prop \`altText\` supplied to \`${Rj}\`. Expected non-empty \`string\`.`),null)});Lj.displayName=Rj;var $j="ToastClose",I0=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=AQ($j,t);return d.jsx(Fj,{asChild:!0,children:d.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,o.onClose)})})});I0.displayName=$j;var Fj=P.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return d.jsx(Ce.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:n})});function Nj(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),$Q(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(...Nj(r))}}),n}function sh(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?g0(o,s):o.dispatchEvent(s)}var NI=(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 LQ(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 $Q(e){return e.nodeType===e.ELEMENT_NODE}function FQ(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 by(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}var NQ=jj,zQ=Oj,BQ=Dj,UQ=Lj,zI=I0;const zj=P.createContext(null);function HQ({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 d.jsx(_j,{children:d.jsx(zj.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})})}function Qr(){const e=P.useContext(zj);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 d.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 d.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"?d.jsx("div",{className:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":n},s)}):d.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}})}),KQ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function WQ({toast:e}){const{removeToast:n}=Qr(),t=Te(),r=i=>{i||n(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&KQ[e.severity];return d.jsxs(NQ,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(qs,{icon:s})}),d.jsxs("div",{className:"tlui-toast__main",children:[d.jsxs("div",{className:"tlui-toast__content",children:[e.title&&d.jsx(zQ,{className:"tlui-toast__title",children:e.title}),e.description&&d.jsx(BQ,{className:"tlui-toast__description",children:e.description})]}),e.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>d.jsx(UQ,{altText:i.label,asChild:!0,onClick:i.onClick,children:d.jsx(he,{type:i.type,children:d.jsx(bt,{children:i.label})})},a)),d.jsx(zI,{asChild:!0,children:d.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:d.jsx(bt,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&d.jsx(zI,{asChild:!0,children:d.jsx(he,{type:"normal",className:"tlui-toast__close",children:d.jsx(bt,{children:e.closeLabel??t("toast.close")})})})]})}function GQ(){const{toasts:e}=Qr();return e.map(n=>d.jsx(WQ,{toast:n},n.id))}const VQ=P.memo(GQ);function YQ(){const e=B(),{toasts:n}=Qr(),[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?d.jsx(Mj,{className:"tlui-toast__viewport"}):null}function Pe({icon:e,small:n,invertIcon:t}){return d.jsx(qs,{className:"tlui-button__icon",icon:e,small:n,invertIcon:t})}const Py=[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 XQ="2.4.0-canary.922dd416b17f",qQ="https://cdn.tldraw.com";function Ti(){return`${qQ}/${XQ}`}let Bv={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 Bj(e){return P.useMemo(()=>e?{fonts:{...Bv.fonts,...e==null?void 0:e.fonts}}:Bv,[e])}const ZQ=["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={...Bv,icons:Object.fromEntries(ZQ.map(e=>[e,`${Ti()}/icons/icon/${e}.svg`])),translations:Object.fromEntries(Xc.map(e=>[e.locale,`${Ti()}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(ju.map(e=>[e.type,`${Ti()}/embed-icons/${e.type}.png`]))};function QQ(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 Eg({className:e,children:n}){return d.jsx("div",{className:ce("tlui-dialog__header",e),children:n})}function kg({className:e,children:n}){return d.jsx(Sj,{dir:"ltr",className:ce("tlui-dialog__header__title",e),children:n})}function _g(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(wj,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(he,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:d.jsx(Pe,{small:!0,icon:"cross-2"})})})})}function gu({className:e,children:n,style:t}){return d.jsx("div",{className:ce("tlui-dialog__body",e),style:t,children:n})}function E0({className:e,children:n}){return d.jsx("div",{className:ce("tlui-dialog__footer",e),children:n})}const k0=P.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:p,onBlur:f,shouldManuallyMaintainScrollPositionWhenFocused:y=!1,children:m,value:x},S){const v=B(),b=P.useRef(null);P.useImperativeHandle(S,()=>b.current);const E=Te(),k=P.useRef(a??""),C=P.useRef(a??""),[I,T]=P.useState(!1),O=P.useCallback(j=>{T(!0);const R=j.currentTarget;C.current=R.value,v.timers.requestAnimationFrame(()=>{s&&R.select()}),p==null||p()},[s,p,v.timers]),_=P.useCallback(j=>{const R=j.currentTarget.value;C.current=R,u==null||u(R)},[u]),M=P.useCallback(j=>{switch(j.key){case"Enter":{j.currentTarget.blur(),Ht(j),c==null||c(j.currentTarget.value);break}case"Escape":{j.currentTarget.value=k.current,j.currentTarget.blur(),Ht(j),h==null||h(j.currentTarget.value);break}}},[c,h]),L=P.useCallback(j=>{T(!1);const R=j.currentTarget.value;f==null||f(R)},[f]);return P.useEffect(()=>{if(!v.environment.isIos)return;const j=window.visualViewport;if(I&&y&&j){const R=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return j.addEventListener("resize",R),j.addEventListener("scroll",R),v.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{j.removeEventListener("resize",R),j.removeEventListener("scroll",R)}}},[v,I,y]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,t&&d.jsx("label",{children:E(t)}),o&&d.jsx(qs,{icon:o,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:ce("tlui-input",n),type:"text",defaultValue:a,onKeyUp:M,onChange:_,onFocus:O,onBlur:L,autoFocus:i,placeholder:l,value:x}),r&&d.jsx(qs,{icon:r,small:!!t})]})}),Uj=lr(function({onClose:n}){const t=B(),r=Te(),o=d0(),[s,i]=P.useState(null),[a,l]=P.useState(""),[c,u]=P.useState(null),[h,p]=P.useState(!1),f=P.useRef(-1);return d.jsxs(d.Fragment,{children:[d.jsxs(Eg,{children:[d.jsx(kg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),d.jsx(_g,{})]}),s?d.jsxs(d.Fragment,{children:[d.jsxs(gu,{className:"tlui-embed-dialog__enter",children:[d.jsx(k0,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:y=>{l(y);const m=As(y);u(m&&m.definition.type===s.type?m:null),p(!1),clearTimeout(f.current),f.current=t.timers.setTimeout(()=>p(!m),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(qs,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(E0,{className:"tlui-dialog__footer__actions",children:[d.jsx(he,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(bt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(he,{type:"normal",onClick:n,children:d.jsx(bt,{children:r("embed-dialog.cancel")})}),d.jsx(he,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:c.definition}),n())},children:d.jsx(bt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(gu,{className:"tlui-embed-dialog__list",children:ju.map(y=>d.jsxs(he,{type:"menu",onClick:()=>i(y),children:[d.jsx(bt,{children:y.title}),d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})]},y.type))})})]})});function Hj(){const e=B(),n=P.useRef();return P.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept=F4,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 Kj=P.createContext(null);function JQ({overrides:e,children:n}){const t=B(),r=Zr(),{addDialog:o}=la(),s=Hj(),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"})}},...[...zr.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){t.batch(()=>{t.setStyleForNextShapes(zr,c),t.setCurrentTool("geo"),r("select-tool",{source:u,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:Uj}),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 d.jsx(Kj.Provider,{value:i,children:n})}function Tg(){const e=P.useContext(Kj);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const Wj=we.createContext(null);function eJ({forceMobile:e=!1,children:n}){const t=B(),r=G("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?yt.MOBILE_SM:Py.length-1;for(let i=0;i<s;i++)if(o>Py[i]&&o<=Py[i+1])return i;return s},[t]);return d.jsx(Wj.Provider,{value:r,children:n})}function Hn(){const e=P.useContext(Wj);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function tJ(){const{addToast:e,removeToast:n,clearToasts:t}=Qr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=la(),l=Hn()<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 nJ(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of Ln(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 Gj(e){return P.useMemo(()=>e,e)}function rJ(e){const n=Gj(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 Ln(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function oJ(e){const n=tJ(),t=Gj(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>nJ(t,n),[t,n])}function sJ(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 iJ=50;function aJ(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 y=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(y.vertices)})),{padding:a=iJ}=t,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,h=a-i.minY;if(u===0&&h===0&&r.props.w===l&&r.props.h===c)return;const p=new w(u,h).rot(r.rotation);e.batch(()=>{const f=o.map(y=>{const m=e.getShape(y);return{id:m.id,type:m.type,x:m.x+u,y:m.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 BI(e){return sr.isValid(e)?{isValid:!0,hasProtocol:!0}:sr.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const lJ=lr(function({onClose:n}){const r=B().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(cJ,{onClose:n,selectedShape:r}):null}),cJ=lr(function({onClose:n,selectedShape:t}){const r=B(),o=Te(),s=P.useRef(null);P.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[r]);const i=P.useRef(t.props.url),[a,l]=P.useState(()=>{const y=BI(t.props.url),m=y.isValid===!0?y.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=P.useCallback(y=>{const m=y.replace(/https?:\/\/(https?:\/\/)/,(v,b)=>b),x=BI(m),S=x.isValid===!0?x.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:S,valid:x.isValid})},[]),u=P.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),n())},[r,n]),h=P.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),n())},[r,n,a]),p=P.useCallback(()=>{n()},[n]);if(!t)return n(),null;const f=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(Eg,{children:[d.jsx(kg,{children:o("edit-link-dialog.title")}),d.jsx(_g,{})]}),d.jsx(gu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(k0,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:p}),d.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),d.jsxs(E0,{className:"tlui-dialog__footer__actions",children:[d.jsx(he,{type:"normal",onClick:p,onTouchEnd:p,children:d.jsx(bt,{children:o("edit-link-dialog.cancel")})}),f?d.jsx(he,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(bt,{children:o("edit-link-dialog.clear")})}):d.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(bt,{children:o("edit-link-dialog.save")})})]})]})});var _0={exports:{}};_0.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 u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var f=c.charCodeAt(h);u[h*2]=f>>>8,u[h*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(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,u){if(l==null)return"";var h,p,f={},y={},m="",x="",S="",v=2,b=3,E=2,k=[],C=0,I=0,T;for(T=0;T<l.length;T+=1)if(m=l.charAt(T),Object.prototype.hasOwnProperty.call(f,m)||(f[m]=b++,y[m]=!0),x=S+m,Object.prototype.hasOwnProperty.call(f,x))S=x;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(h=0;h<E;h++)C=C<<1,I==c-1?(I=0,k.push(u(C)),C=0):I++;for(p=S.charCodeAt(0),h=0;h<8;h++)C=C<<1|p&1,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=p>>1}else{for(p=1,h=0;h<E;h++)C=C<<1|p,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=0;for(p=S.charCodeAt(0),h=0;h<16;h++)C=C<<1|p&1,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete y[S]}else for(p=f[S],h=0;h<E;h++)C=C<<1|p&1,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++),f[x]=b++,S=String(m)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(h=0;h<E;h++)C=C<<1,I==c-1?(I=0,k.push(u(C)),C=0):I++;for(p=S.charCodeAt(0),h=0;h<8;h++)C=C<<1|p&1,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=p>>1}else{for(p=1,h=0;h<E;h++)C=C<<1|p,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=0;for(p=S.charCodeAt(0),h=0;h<16;h++)C=C<<1|p&1,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete y[S]}else for(p=f[S],h=0;h<E;h++)C=C<<1|p&1,I==c-1?(I=0,k.push(u(C)),C=0):I++,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,I==c-1?(I=0,k.push(u(C)),C=0):I++,p=p>>1;for(;;)if(C=C<<1,I==c-1){k.push(u(C));break}else I++;return k.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],p=4,f=4,y=3,m="",x=[],S,v,b,E,k,C,I,T={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)h[S]=S;for(b=0,k=Math.pow(2,2),C=1;C!=k;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;switch(b){case 0:for(b=0,k=Math.pow(2,8),C=1;C!=k;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;I=t(b);break;case 1:for(b=0,k=Math.pow(2,16),C=1;C!=k;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;I=t(b);break;case 2:return""}for(h[3]=I,v=I,x.push(I);;){if(T.index>l)return"";for(b=0,k=Math.pow(2,y),C=1;C!=k;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;switch(I=b){case 0:for(b=0,k=Math.pow(2,8),C=1;C!=k;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;h[f++]=t(b),I=f-1,p--;break;case 1:for(b=0,k=Math.pow(2,16),C=1;C!=k;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;h[f++]=t(b),I=f-1,p--;break;case 2:return x.join("")}if(p==0&&(p=Math.pow(2,y),y++),h[I])m=h[I];else if(I===f)m=v+v.charAt(0);else return null;x.push(m),h[f++]=v+m.charAt(0),p--,v=m,p==0&&(p=Math.pow(2,y),y++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(_0);var uJ=_0.exports;const Vj=ei(uJ);async function dJ(e,n,t){var S,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,u=[],h=new Set;r.forEach(E=>{if(c.set(E.id,$e()),E.boundElements!==null)for(const k of E.boundElements)k.type==="text"&&h.add(k.id)});let p=z4;for(const E of r){if(h.has(E.id))continue;const k=c.get(E.id),C={id:k,typeName:"shape",parentId:l,index:p,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:hJ(E.opacity),meta:{}};switch(E.angle!==0&&a.set(k,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(S=i.get(E.groupIds[0]))==null||S.push(k):i.set(E.groupIds[0],[k]):u.push(k),E.type){case"rectangle":case"ellipse":case"diamond":{let I="",T="middle";if(E.boundElements!==null){for(const _ of E.boundElements)if(_.type==="text"){const M=r.find(L=>L.id===_.id);M&&(I=M.text,T=SJ[M.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:ih[E.strokeWidth]??"draw",color:hc[O]??"black",text:I,align:T,dash:ah(E),fill:wJ(E)}});break}case"freedraw":{s.shapes.push({...C,type:"draw",props:{dash:ah(E),size:ih[E.strokeWidth],color:hc[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([I,T,O=.5])=>({x:I,y:T,z:O}))}]}});break}case"line":{if(E.points.slice().length<2)break;const T=Vc(E.points.length);s.shapes.push({...C,type:"line",props:{dash:ah(E),size:ih[E.strokeWidth],color:hc[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([O,_],M)=>{const L=T[M];return[L,{id:L,index:L,x:O,y:_}]}))}}});break}case"arrow":{let I="";if(E.boundElements!==null){for(const L of E.boundElements)if(L.type==="text"){const j=r.find(R=>R.id===L.id);j&&(I=j.text)}}const T=E.points[0],O=E.points[E.points.length-1],_=c.get((v=E.startBinding)==null?void 0:v.elementId),M=c.get((b=E.endBinding)==null?void 0:b.elementId);s.shapes.push({...C,type:"arrow",props:{text:I,bend:xJ(E,T,O),dash:ah(E),size:ih[E.strokeWidth]??"m",color:hc[E.strokeColor]??"black",start:{x:T[0],y:T[1]},end:{x:O[0],y:O[1]},arrowheadEnd:UI[E.endArrowhead]??"none",arrowheadStart:UI[E.startArrowhead]??"none"}}),_&&s.bindings.push({id:Oi(),typeName:"binding",type:"arrow",fromId:k,toId:_,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),M&&s.bindings.push({id:Oi(),typeName:"binding",type:"arrow",fromId:k,toId:M,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:I,scale:T}=fJ(E.fontSize);s.shapes.push({...C,type:"text",props:{size:I,scale:T,font:gJ[E.fontFamily]??"draw",color:hc[E.strokeColor]??"black",text:E.text,textAlign:vJ[E.textAlign]}});break}case"image":{const I=o[E.fileId];if(!I)break;const T=Ci.createId();s.assets.push({id:T,typeName:"asset",type:"image",props:{w:E.width,h:E.height,fileSize:I.size,name:E.id??"Untitled",isAnimated:!1,mimeType:I.mimeType,src:I.dataURL},meta:{}}),s.shapes.push({...C,type:"image",props:{w:E.width,h:E.height,assetId:T}})}}p=No(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 k=e.getShape(E[0]);k!=null&&k.parentId&&_n(k.parentId)&&u.push(k.parentId)}for(const[E,k]of a)e.select(E),e.rotateShapesBy([E],k);const y=me(u.map(E=>e.getShape(E))),m=Z.Common(y.map(E=>e.getShapePageBounds(E))),x=e.getViewportPageBounds().center;e.updateShapes(y.map(E=>{const k={x:(E.x??0)-(m.x+m.w/2),y:(E.y??0)-(m.y+m.h/2)};return{id:E.id,type:E.type,x:x.x+k.x,y:x.y+k.y}})),e.setSelectedShapes(u)}const hJ=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},ih={1:"s",2:"m",3:"l",4:"xl"},pJ={16:"s",20:"m",28:"l",36:"xl"};function fJ(e){const n=pJ[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 gJ={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"},mJ={solid:"draw",dashed:"dashed",dotted:"dotted"},yJ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},SJ={left:"start",center:"middle",right:"end"},vJ={left:"start",center:"middle",right:"end"},UI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function xJ(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),u=w.Sub(c,l),h=w.Add(c,l),p=w.NearestPointOnLineSegment(u,h,i,!1);r=w.Dist(p,c),w.Clockwise(p,s,c)&&(r*=-1)}return r}const ah=e=>{let n=mJ[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},wJ=e=>e.backgroundColor==="transparent"?"none":yJ[e.fillStyle]??"solid";async function Yj(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await So(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 bJ(e,n,t){const r=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(n,{point:t,select:!0});const o=e.getSelectionPageBounds();r&&o&&(r!=null&&r.collides(o))&&(e.updateInstanceState({isChangingStyle:!0}),e.timers.setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))}async function Uv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await So(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),Yj(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 PJ(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const CJ=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},IJ=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 eT(n)},EJ=e=>/^<svg/.test(e),kJ=["input","select","textarea"];function Cy(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||kJ.indexOf(n.tagName.toLowerCase())>-1)}const _J=e=>e.types.find(n=>n.match(/^image\//)),Iy=(e,n,t,r)=>{const o=IJ(n);if(o)for(const s of o)Uv(e,s,t);else CJ(n)?Uv(e,n,t):EJ(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}))},TJ=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}}qj(e,r,t)},Xj=async(e,n,t)=>{const r=[];for(const o of n){if(_J(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 Ai.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Ai.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Ai.blobToText(s)})()})}return await qj(e,r,t)};async function qj(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 Yj(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 u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=Vj.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"){bJ(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){dJ(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");Iy(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){Iy(e,PJ(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Uv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){Iy(e,s.data,t,o);return}}const bf=async e=>{var r;const n=await e.resolveAssetsInContent(e.getContentFromCurrentPage(e.getSelectedShapeIds()));if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=Vj.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(q4);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 MJ(){const e=B(),n=Zr(),t=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await bf(e),n("copy",{source:i}))},[e,n]),r=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await bf(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?(Xj(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 AJ(){const e=B(),n=Zr(),t=G("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!t)return;const r=async l=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Cy(e)||(Ee(l),await bf(e),n("copy",{source:"kbd"}))};async function o(l){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Cy(e)||(Ee(l),await bf(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){Ht(l);return}if(e.getEditingShapeId()!==null||Cy(e))return;let c,u=!1;e.inputs.shiftKey&&(u=!0),e.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=e.inputs.currentPagePoint),l.clipboardData&&!e.inputs.shiftKey?TJ(e,l.clipboardData,c):navigator.clipboard.read().then(h=>{Array.isArray(h)&&h[0]instanceof ClipboardItem&&Xj(e,h,c)}),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 Zj(e,n,t){const{type:r,quality:o,scale:s,width:i,height:a}=t;let[l,c]=await pY(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,h=URL.createObjectURL(new Blob([n],{type:"image/svg+xml"})),p=await new Promise(y=>{const m=il();m.crossOrigin="anonymous",m.onload=async()=>{e.environment.isSafari&&await new Promise(v=>e.timers.setTimeout(v,250));const x=document.createElement("canvas"),S=x.getContext("2d");x.width=l,x.height=c,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(m,0,0,l,c),URL.revokeObjectURL(h),y(x)},m.onerror=()=>{y(null)},m.src=h});if(!p)return null;const f=await new Promise(y=>p.toBlob(m=>{(!m||xt.throwToBlob.get())&&y(null),y(m)},"image/"+r,o));if(!f)return null;if(r==="png"){const y=new DataView(await f.arrayBuffer());return so.setPhysChunk(y,u,{type:"image/"+r})}else return f}async function Qj(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 Hv(e,n,t,r={}){var o;switch(t){case"svg":return(o=await Qj(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 Jj({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await Hv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Hv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await Qj(e,n,r);if(!o)throw new Error("Could not construct image.");const s=await Zj(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 jJ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function OJ(e,n,t,r={}){return{blobPromise:Jj({editor:e,ids:n,format:t,opts:r}),mimeType:jJ[t]}}function DJ(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}=OJ(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 RJ(async()=>Hv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:an(t)}}async function RJ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}function LJ(){const e=B(),{addToast:n}=Qr(),t=Te();return P.useCallback((r,o="svg")=>{DJ(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 $J(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${HI()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${HI()}`}r+=`.${t}`;const s=await Jj({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});FJ(i)}function HI(){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 FJ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function NJ(){const e=B(),{addToast:n}=Qr(),t=Te();return P.useCallback((r,o="png",s)=>{$J(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 zJ(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 u=!1;for(const h of o)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||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"}),u=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return js(()=>{for(const a of o){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=e.findCommonAncestor(u)??e.getCurrentPageId();if(!h)continue;let p="a1";for(const S of u)if(S.parentId===h){S.index>p&&(p=S.index);break}let f,y,m;if(_n(h)){const S=e.getShape(h);if(!S)continue;const v=e.getPointInShapeSpace(S,{x:c.x,y:c.y});m=e.getShapePageTransform(h).rotation(),v.sub(new w(s,s).rot(-m)),f=v.x,y=v.y}else f=c.x-s,y=c.y-s,m=0;e.deleteShapes(u),e.createAssets([{...l,id:l.id}]);const x=$e();e.createShape({id:x,type:"image",index:p,parentId:h,x:f,y,rotation:-m,props:{assetId:l.id,w:c.w+s*2,h:c.h+s*2}}),i.push(x)}}),i}function BJ(){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=(S,v)=>{S&&(S.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),S&&document.body.contains(S)&&document.body.removeChild(S)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${ot()}`;o.className=a,s.innerHTML=`
203
+ .${a} {
204
+ display: none;
205
+ }
206
+
207
+ .${a} svg {
208
+ max-width: 100%;
209
+ height: 100%;
210
+ display: block;
211
+ }
212
+
213
+ @media print {
214
+ html, body {
215
+ min-height: 100%;
216
+ height: 100%;
217
+ margin: 0;
218
+ }
219
+
220
+ body {
221
+ position: relative;
222
+ }
223
+
224
+ body > * {
225
+ display: none;
226
+ }
227
+
228
+ .tldraw__editor {
229
+ display: none;
230
+ }
231
+
232
+ .${a} {
233
+ display: block !important;
234
+ background: white;
235
+ min-height: 100%;
236
+ height: 100%;
237
+ max-width: 100%;
238
+ }
239
+
240
+ .${a}__item {
241
+ padding: 10mm;
242
+ display: flex;
243
+ min-height: 100%;
244
+ flex-direction: column;
245
+ page-break-after: always;
246
+ position: relative;
247
+ overflow: hidden;
248
+ height: 100%;
249
+ }
250
+
251
+ .${a}__item__main {
252
+ flex: 1;
253
+ display: flex;
254
+ align-items: center;
255
+ justify-content: center;
256
+ max-height: 100%;
257
+ }
258
+
259
+ .${a}__item__header {
260
+ display: none;
261
+ }
262
+
263
+ .${a}__item__footer {
264
+ display: none;
265
+ text-align: right;
266
+ }
267
+
268
+ .${a}__item__footer__hide {
269
+ display: none;
270
+ }
271
+
272
+
273
+ }
274
+
275
+ `;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 u(S,v,b){try{o.innerHTML+=`<div class="${a}__item">
276
+ <div class="${a}__item__header">
277
+ ${S.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
278
+ </div>
279
+ <div class="${a}__item__main">
280
+ ${b}
281
+ </div>
282
+ <div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
283
+ ${v??""}
284
+ </div>
285
+ </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(),y=e.getPages(),x={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvgString(p,x);if(S){const v=y.find(b=>b.id===f);u(`tldraw — ${v==null?void 0:v.name}`,null,S.svg),h()}}else{const S=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(S.id),x);v&&(u(`tldraw — ${S.name}`,null,v.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const eO=P.createContext(null);function UJ(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 HJ({overrides:e,children:n}){const t=B(),{addDialog:r,clearDialogs:o}=la(),{clearToasts:s,addToast:i}=Qr(),a=Te(),l=Hj(),c=BJ(),{cut:u,copy:h,paste:p}=MJ(),f=LJ(),y=NJ(),m=a("document.default-name"),x=Zr(),S=P.useMemo(()=>{function v(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function b(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const k=UJ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(C){b()&&(v()||(x("edit-link",{source:C}),t.mark("edit-link"),r({component:lJ})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(C){x("insert-embed",{source:C}),r({component:Uj})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(C){x("insert-media",{source:C}),l()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(C){x("undo",{source:C}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(C){x("redo",{source:C}),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(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("export-as",{format:"svg",source:C}),y(I,"svg",ba(t,m)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("export-as",{format:"png",source:C}),y(I,"png",ba(t,m)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("export-as",{format:"json",source:C}),y(I,"json",ba(t,m)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("export-all-as",{format:"svg",source:C}),y(Array.from(t.getCurrentPageShapeIds()),"svg",ba(t,m)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(C){const I=Array.from(t.getCurrentPageShapeIds().values());I.length!==0&&(x("export-all-as",{format:"png",source:C}),y(I,"png",ba(t,m)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(C){const I=Array.from(t.getCurrentPageShapeIds().values());I.length!==0&&(x("export-all-as",{format:"json",source:C}),y(I,"json",ba(t,m)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("copy-as",{format:"svg",source:C}),f(I,"svg"))}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("copy-as",{format:"png",source:C}),f(I,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(x("copy-as",{format:"json",source:C}),f(I,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(C){if(!b()||v())return;x("toggle-auto-size",{source:C}),t.mark("toggling auto size");const I=t.getSelectedShapes().filter(T=>t.isShapeOfType(T,"text")&&T.props.autoSize===!1);t.updateShapes(I.map(T=>({id:T.id,type:T.type,props:{...T.props,w:8,autoSize:!0}}))),Ke(t,I.map(T=>T.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(C){x("open-embed-link",{source:C});const I=t.getSelectedShapeIds(),T="No embed shapes selected";if(I.length!==1){console.error(T);return}const O=t.getShape(I[0]);if(!O||!t.isShapeOfType(O,"embed")){console.error(T);return}kV(O.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(C){var I,T;if(((I=t.root.getCurrent())==null?void 0:I.id)!=="zoom"&&(x("zoom-tool",{source:C}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const O=t.root.getCurrent();O&&((T=O.getCurrent())==null?void 0:T.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:O.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(C){b()&&(v()||t.batch(()=>{x("convert-to-bookmark",{source:C});const I=t.getSelectedShapes(),T=[],O=[];for(const _ of I){if(!_||!t.isShapeOfType(_,"embed")||!_.props.url)continue;const M=new w(_.x,_.y);M.rot(-_.rotation),M.add(new w(_.props.w/2-300/2,_.props.h/2-320/2)),M.rot(_.rotation);const L={id:$e(),type:"bookmark",rotation:_.rotation,x:M.x,y:M.y,opacity:1,props:{url:_.props.url}};T.push(L),O.push(_.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(O),t.createShapes(T)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(C){b()&&(v()||(x("convert-to-embed",{source:C}),t.batch(()=>{const I=t.getSelectedShapeIds(),T=me(I.map(M=>t.getShape(M))),O=[],_=[];for(const M of T){if(!t.isShapeOfType(M,"bookmark"))continue;const{url:L}=M.props,j=As(M.props.url);if(!j||!j.definition)continue;const{width:R,height:F}=j.definition,W=new w(M.x,M.y);W.rot(-M.rotation),W.add(new w(M.props.w/2-R/2,M.props.h/2-F/2)),W.rot(M.rotation);const K={id:$e(),type:"embed",x:W.x,y:W.y,rotation:M.rotation,props:{url:L,w:R,h:F}};O.push(K),_.push(M.id)}t.mark("convert shapes to embed"),t.deleteShapes(_),t.createShapes(O)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(C){if(!b()||v())return;x("duplicate-shapes",{source:C});const I=t.getInstanceState();let T,O;if(I.duplicateProps)T=I.duplicateProps.shapeIds,O=I.duplicateProps.offset;else{T=t.getSelectedShapeIds();const _=Z.Common(me(T.map(M=>t.getShapePageBounds(M))));O=t.getCameraOptions().isLocked?{x:t.options.adjacentShapeMargin,y:t.options.adjacentShapeMargin}:{x:_.width+t.options.adjacentShapeMargin,y:0}}t.mark("duplicate shapes"),t.duplicateShapes(T,O),I.duplicateProps&&t.updateInstanceState({duplicateProps:{...I.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(C){b()&&(v()||(x("ungroup-shapes",{source:C}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(C){if(!b()||v())return;x("group-shapes",{source:C});const I=t.getOnlySelectedShape();I&&t.isShapeOfType(I,"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(C){if(!b())return;x("remove-frame",{source:C});const I=t.getSelectedShapes();I.length>0&&I.every(T=>t.isShapeOfType(T,"frame"))&&(t.mark("remove-frame"),sJ(t,I.map(T=>T.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(C){if(!b())return;x("fit-frame-to-content",{source:C});const I=t.getOnlySelectedShape();I&&t.isShapeOfType(I,"frame")&&(t.mark("fit-frame-to-content"),aJ(t,I.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(C){if(!b()||v())return;x("align-shapes",{operation:"left",source:C}),t.mark("align left");const I=t.getSelectedShapeIds();t.alignShapes(I,"left"),Ke(t,I)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(C){if(!b()||v())return;x("align-shapes",{operation:"center-horizontal",source:C}),t.mark("align center horizontal");const I=t.getSelectedShapeIds();t.alignShapes(I,"center-horizontal"),Ke(t,I)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(C){if(!b()||v())return;x("align-shapes",{operation:"right",source:C}),t.mark("align right");const I=t.getSelectedShapeIds();t.alignShapes(I,"right"),Ke(t,I)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(C){if(!b()||v())return;x("align-shapes",{operation:"center-vertical",source:C}),t.mark("align center vertical");const I=t.getSelectedShapeIds();t.alignShapes(I,"center-vertical"),Ke(t,I)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(C){if(!b()||v())return;x("align-shapes",{operation:"top",source:C}),t.mark("align top");const I=t.getSelectedShapeIds();t.alignShapes(I,"top"),Ke(t,I)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(C){if(!b()||v())return;x("align-shapes",{operation:"bottom",source:C}),t.mark("align bottom");const I=t.getSelectedShapeIds();t.alignShapes(I,"bottom"),Ke(t,I)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(C){if(!b()||v())return;x("distribute-shapes",{operation:"horizontal",source:C}),t.mark("distribute horizontal");const I=t.getSelectedShapeIds();t.distributeShapes(I,"horizontal"),Ke(t,I)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(C){if(!b()||v())return;x("distribute-shapes",{operation:"vertical",source:C}),t.mark("distribute vertical");const I=t.getSelectedShapeIds();t.distributeShapes(I,"vertical"),Ke(t,I)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(C){if(!b()||v())return;x("stretch-shapes",{operation:"horizontal",source:C}),t.mark("stretch horizontal");const I=t.getSelectedShapeIds();t.stretchShapes(I,"horizontal"),Ke(t,I)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(C){if(!b()||v())return;x("stretch-shapes",{operation:"vertical",source:C}),t.mark("stretch vertical");const I=t.getSelectedShapeIds();t.stretchShapes(I,"vertical"),Ke(t,I)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(C){if(!b()||v())return;x("flip-shapes",{operation:"horizontal",source:C}),t.mark("flip horizontal");const I=t.getSelectedShapeIds();t.flipShapes(I,"horizontal"),Ke(t,I)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(C){if(!b()||v())return;x("flip-shapes",{operation:"vertical",source:C}),t.mark("flip vertical");const I=t.getSelectedShapeIds();t.flipShapes(I,"vertical"),Ke(t,I)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(C){if(!b()||v())return;x("pack-shapes",{source:C}),t.mark("pack");const I=t.getSelectedShapeIds();t.packShapes(I,t.options.adjacentShapeMargin),Ke(t,I)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(C){if(!b()||v())return;x("stack-shapes",{operation:"vertical",source:C}),t.mark("stack-vertical");const I=t.getSelectedShapeIds();t.stackShapes(I,"vertical",16),Ke(t,I)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(C){if(!b()||v())return;x("stack-shapes",{operation:"horizontal",source:C}),t.mark("stack-horizontal");const I=t.getSelectedShapeIds();t.stackShapes(I,"horizontal",16),Ke(t,I)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(C){b()&&(v()||(x("reorder-shapes",{operation:"toFront",source:C}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(C){b()&&(v()||(x("reorder-shapes",{operation:"forward",source:C}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(C){b()&&(v()||(x("reorder-shapes",{operation:"backward",source:C}),t.mark("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(C){b()&&(v()||(x("reorder-shapes",{operation:"toBack",source:C}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(C){b()&&(v()||(t.mark("cut"),u(C)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(C){b()&&(v()||h(C))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(C){var I;(I=navigator.clipboard)==null||I.read().then(T=>{p(T,C,C==="context-menu"?t.inputs.currentPagePoint:void 0)}).catch(()=>{i({title:a("action.paste-error-title"),description:a("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(C){t.batch(()=>{v()||(x("select-all-shapes",{source:C}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(C){b()&&(v()||(x("select-none-shapes",{source:C}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(C){b()&&(v()||(x("delete-shapes",{source:C}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(C){if(!b()||v())return;x("rotate-cw",{source:C}),t.mark("rotate-cw");const I=t.getSelectionRotation()%(Ge/2),T=Ds(I,0)||Ds(I,Ge/2),O=t.getSelectedShapeIds();t.rotateShapesBy(O,Ge/2-(T?0:I)),Ke(t,O)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(C){if(!b()||v())return;x("rotate-ccw",{source:C}),t.mark("rotate-ccw");const I=t.getSelectionRotation()%(Ge/2),T=Ds(I,0),O=t.getSelectedShapeIds();t.rotateShapesBy(O,T?-(Ge/2):-I),Ke(t,O)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(C){x("zoom-in",{source:C}),t.zoomIn(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(C){x("zoom-out",{source:C}),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(C){x("reset-zoom",{source:C}),t.resetZoom(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(C){x("zoom-to-fit",{source:C}),t.zoomToFit({animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(C){b()&&(v()||(x("zoom-to-selection",{source:C}),t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(C){x("toggle-snap-mode",{source:C}),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(C){const I=t.user.getIsDarkMode()?"light":"dark";x("color-scheme",{source:C,value:I}),t.user.updateUserPreferences({colorScheme:I})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(C){x("toggle-wrap-mode",{source:C}),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(C){x("toggle-dynamic-size-mode",{source:C}),t.user.updateUserPreferences({isDynamicSizeMode:!t.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-paste-at-cursor",label:{default:"action.toggle-paste-at-cursor",menu:"action.toggle-paste-at-cursor.menu"},readonlyOk:!1,onSelect(C){x("toggle-paste-at-cursor",{source:C}),t.user.updateUserPreferences({isPasteAtCursorMode:!t.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(C){x("toggle-reduce-motion",{source:C}),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(C){x("toggle-edge-scrolling",{source:C}),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(C){x("toggle-transparent",{source:C}),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(C){x("toggle-tool-lock",{source:C}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(C){x("unlock-all",{source:C});const I=[];for(const T of t.getCurrentPageShapes())T.isLocked&&I.push({id:T.id,type:T.type,isLocked:!1});I.length>0&&t.updateShapes(I)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(C){t.timers.requestAnimationFrame(()=>{t.batch(()=>{x("toggle-focus-mode",{source:C}),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(C){x("toggle-grid-mode",{source:C}),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(C){x("toggle-debug-mode",{source:C}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(C){x("print",{source:C}),c()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(C){x("exit-pen-mode",{source:C}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(C){x("stop-following",{source:C}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(C){x("zoom-to-content",{source:C});const I=t.getSelectionPageBounds()??t.getCurrentPageBounds();I&&t.zoomToBounds(I,{targetZoom:Math.min(1,t.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(C){t.mark("locking"),x("toggle-lock",{source:C}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(C){const I=Zo.createId(),T=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:a("page-menu.new-page-initial-name"),id:I}),t.moveShapesToPage(T,I)}),x("new-page",{source:C})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(C){const I=ir;t.batch(()=>{t.mark("change-color"),t.isIn("select")&&t.setStyleForSelectedShapes(I,"white"),t.setStyleForNextShapes(I,"white")}),x("set-style",{source:C,id:I.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(C){const I=zi;t.batch(()=>{t.mark("change-fill"),t.isIn("select")&&t.setStyleForSelectedShapes(I,"fill"),t.setStyleForNextShapes(I,"fill")}),x("set-style",{source:C,id:I.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async C=>{const I=t.getSelectedShapeIds();if(I.length===0)return;t.mark("flattening to image"),x("flatten-to-image",{source:C});const T=await zJ(t,I,t.options.flattenImageBoundsExpand);T!=null&&T.length&&t.setSelectedShapes(T)}}]);return e?e(t,k,void 0):k},[t,x,e,r,i,l,y,f,u,h,p,o,s,c,a,m]);return d.jsx(eO.Provider,{value:S,children:n})}function ie(){const e=P.useContext(eO);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function mu(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const KJ=["top","right","bottom","left"],ho=Math.min,Zn=Math.max,Pf=Math.round,lh=Math.floor,Zs=e=>({x:e,y:e}),WJ={left:"right",right:"left",bottom:"top",top:"bottom"},GJ={start:"end",end:"start"};function Kv(e,n,t){return Zn(e,ho(n,t))}function rs(e,n){return typeof e=="function"?e(n):e}function os(e){return e.split("-")[0]}function Fl(e){return e.split("-")[1]}function T0(e){return e==="x"?"y":"x"}function M0(e){return e==="y"?"height":"width"}function Qs(e){return["top","bottom"].includes(os(e))?"y":"x"}function A0(e){return T0(Qs(e))}function VJ(e,n,t){t===void 0&&(t=!1);const r=Fl(e),o=A0(e),s=M0(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=Cf(i)),[i,Cf(i)]}function YJ(e){const n=Cf(e);return[Wv(e),n,Wv(n)]}function Wv(e){return e.replace(/start|end/g,n=>GJ[n])}function XJ(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 qJ(e,n,t,r){const o=Fl(e);let s=XJ(os(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(Wv)))),s}function Cf(e){return e.replace(/left|right|bottom|top/g,n=>WJ[n])}function ZJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function tO(e){return typeof e!="number"?ZJ(e):{top:e,right:e,bottom:e,left:e}}function If(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 KI(e,n,t){let{reference:r,floating:o}=e;const s=Qs(n),i=A0(n),a=M0(i),l=os(n),c=s==="y",u=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:u,y:r.y-o.height};break;case"bottom":f={x:u,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y: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 QJ=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:u,y:h}=KI(c,r,l),p=r,f={},y=0;for(let m=0;m<a.length;m++){const{name:x,fn:S}=a[m],{x:v,y:b,data:E,reset:k}=await S({x:u,y:h,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:n}});u=v??u,h=b??h,f={...f,[x]:{...f[x],...E}},k&&y<=50&&(y++,typeof k=="object"&&(k.placement&&(p=k.placement),k.rects&&(c=k.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):k.rects),{x:u,y:h}=KI(c,p,l)),m=-1)}return{x:u,y:h,placement:p,strategy:o,middlewareData:f}};async function yu(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:u="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=rs(n,e),y=tO(f),x=a[p?h==="floating"?"reference":"floating":h],S=If(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:u,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},k=If(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:b,strategy:l}):v);return{top:(S.top-k.top+y.top)/E.y,bottom:(k.bottom-S.bottom+y.bottom)/E.y,left:(S.left-k.left+y.left)/E.x,right:(k.right-S.right+y.right)/E.x}}const JJ=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:u=0}=rs(e,n)||{};if(c==null)return{};const h=tO(u),p={x:t,y:r},f=A0(o),y=M0(f),m=await i.getDimensions(c),x=f==="y",S=x?"top":"left",v=x?"bottom":"right",b=x?"clientHeight":"clientWidth",E=s.reference[y]+s.reference[f]-p[f]-s.floating[y],k=p[f]-s.reference[f],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=C?C[b]:0;(!I||!await(i.isElement==null?void 0:i.isElement(C)))&&(I=a.floating[b]||s.floating[y]);const T=E/2-k/2,O=I/2-m[y]/2-1,_=ho(h[S],O),M=ho(h[v],O),L=_,j=I-m[y]-M,R=I/2-m[y]/2+T,F=Kv(L,R,j),W=!l.arrow&&Fl(o)!=null&&R!==F&&s.reference[y]/2-(R<L?_:M)-m[y]/2<0,K=W?R<L?R-L:R-j:0;return{[f]:p[f]+K,data:{[f]:F,centerOffset:R-F-K,...W&&{alignmentOffset:K}},reset:W}}}),eee=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:u=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:m=!0,...x}=rs(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const S=os(o),v=Qs(a),b=os(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=p||(b||!m?[Cf(a)]:YJ(a)),C=y!=="none";!p&&C&&k.push(...qJ(a,m,y,E));const I=[a,...k],T=await yu(n,x),O=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&O.push(T[S]),h){const R=VJ(o,i,E);O.push(T[R[0]],T[R[1]])}if(_=[..._,{placement:o,overflows:O}],!O.every(R=>R<=0)){var M,L;const R=(((M=s.flip)==null?void 0:M.index)||0)+1,F=I[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 j;const K=(j=_.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:j[0];K&&(W=K);break}case"initialPlacement":W=a;break}if(o!==W)return{reset:{placement:W}}}return{}}}};function WI(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function GI(e){return KJ.some(n=>e[n]>=0)}const tee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=rs(e,n);switch(r){case"referenceHidden":{const s=await yu(n,{...o,elementContext:"reference"}),i=WI(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:GI(i)}}}case"escaped":{const s=await yu(n,{...o,altBoundary:!0}),i=WI(s,t.floating);return{data:{escapedOffsets:i,escaped:GI(i)}}}default:return{}}}}};async function nee(e,n){const{placement:t,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=os(t),a=Fl(t),l=Qs(t)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,h=rs(n,e);let{mainAxis:p,crossAxis:f,alignmentAxis:y}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...h};return a&&typeof y=="number"&&(f=a==="end"?y*-1:y),l?{x:f*u,y:p*c}:{x:p*c,y:f*u}}const ree=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 nee(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}}}}},oee=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:S,y:v}=x;return{x:S,y:v}}},...l}=rs(e,n),c={x:t,y:r},u=await yu(n,l),h=Qs(os(o)),p=T0(h);let f=c[p],y=c[h];if(s){const x=p==="y"?"top":"left",S=p==="y"?"bottom":"right",v=f+u[x],b=f-u[S];f=Kv(v,f,b)}if(i){const x=h==="y"?"top":"left",S=h==="y"?"bottom":"right",v=y+u[x],b=y-u[S];y=Kv(v,y,b)}const m=a.fn({...n,[p]:f,[h]:y});return{...m,data:{x:m.x-t,y:m.y-r}}}}},see=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}=rs(e,n),u={x:t,y:r},h=Qs(o),p=T0(h);let f=u[p],y=u[h];const m=rs(a,n),x=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=p==="y"?"height":"width",E=s.reference[p]-s.floating[b]+x.mainAxis,k=s.reference[p]+s.reference[b]-x.mainAxis;f<E?f=E:f>k&&(f=k)}if(c){var S,v;const b=p==="y"?"width":"height",E=["top","left"].includes(os(o)),k=s.reference[h]-s.floating[b]+(E&&((S=i.offset)==null?void 0:S[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);y<k?y=k:y>C&&(y=C)}return{[p]:f,[h]:y}}}},iee=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}=rs(e,n),l=await yu(n,a),c=os(t),u=Fl(t),h=Qs(t)==="y",{width:p,height:f}=r.floating;let y,m;c==="top"||c==="bottom"?(y=c,m=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(m=c,y=u==="end"?"top":"bottom");const x=f-l.top-l.bottom,S=p-l.left-l.right,v=ho(f-l[y],x),b=ho(p-l[m],S),E=!n.middlewareData.shift;let k=v,C=b;if(h?C=u||E?ho(b,S):S:k=u||E?ho(v,x):x,E&&!u){const T=Zn(l.left,0),O=Zn(l.right,0),_=Zn(l.top,0),M=Zn(l.bottom,0);h?C=p-2*(T!==0||O!==0?T+O:Zn(l.left,l.right)):k=f-2*(_!==0||M!==0?_+M:Zn(l.top,l.bottom))}await i({...n,availableWidth:C,availableHeight:k});const I=await o.getDimensions(s.floating);return p!==I.width||f!==I.height?{reset:{rects:!0}}:{}}}};function Nl(e){return nO(e)?(e.nodeName||"").toLowerCase():"#document"}function or(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function us(e){var n;return(n=(nO(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function nO(e){return e instanceof Node||e instanceof or(e).Node}function bo(e){return e instanceof Element||e instanceof or(e).Element}function Po(e){return e instanceof HTMLElement||e instanceof or(e).HTMLElement}function VI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof or(e).ShadowRoot}function Vu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=Gr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function aee(e){return["table","td","th"].includes(Nl(e))}function Mg(e){return[":popover-open",":modal"].some(n=>{try{return e.matches(n)}catch{return!1}})}function j0(e){const n=O0(),t=Gr(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 lee(e){let n=Js(e);for(;Po(n)&&!Pl(n);){if(Mg(n))return null;if(j0(n))return n;n=Js(n)}return null}function O0(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Pl(e){return["html","body","#document"].includes(Nl(e))}function Gr(e){return or(e).getComputedStyle(e)}function Ag(e){return bo(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||VI(e)&&e.host||us(e);return VI(n)?n.host:n}function rO(e){const n=Js(e);return Pl(n)?e.ownerDocument?e.ownerDocument.body:e.body:Po(n)&&Vu(n)?n:rO(n)}function Su(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=rO(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=or(o);return s?n.concat(i,i.visualViewport||[],Vu(o)?o:[],i.frameElement&&t?Su(i.frameElement):[]):n.concat(o,Su(o,[],t))}function oO(e){const n=Gr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=Po(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=Pf(t)!==s||Pf(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function D0(e){return bo(e)?e:e.contextElement}function sl(e){const n=D0(e);if(!Po(n))return Zs(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=oO(n);let i=(s?Pf(t.width):t.width)/r,a=(s?Pf(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const cee=Zs(0);function sO(e){const n=or(e);return!O0()||!n.visualViewport?cee:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function uee(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==or(e)?!1:n}function Zi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=D0(e);let i=Zs(1);n&&(r?bo(r)&&(i=sl(r)):i=sl(e));const a=uee(s,t,r)?sO(s):Zs(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,h=o.height/i.y;if(s){const p=or(s),f=r&&bo(r)?or(r):r;let y=p,m=y.frameElement;for(;m&&r&&f!==y;){const x=sl(m),S=m.getBoundingClientRect(),v=Gr(m),b=S.left+(m.clientLeft+parseFloat(v.paddingLeft))*x.x,E=S.top+(m.clientTop+parseFloat(v.paddingTop))*x.y;l*=x.x,c*=x.y,u*=x.x,h*=x.y,l+=b,c+=E,y=or(m),m=y.frameElement}}return If({width:u,height:h,x:l,y:c})}function dee(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=us(r),a=n?Mg(n.floating):!1;if(r===i||a&&s)return t;let l={scrollLeft:0,scrollTop:0},c=Zs(1);const u=Zs(0),h=Po(r);if((h||!h&&!s)&&((Nl(r)!=="body"||Vu(i))&&(l=Ag(r)),Po(r))){const p=Zi(r);c=sl(r),u.x=p.x+r.clientLeft,u.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+u.x,y:t.y*c.y-l.scrollTop*c.y+u.y}}function hee(e){return Array.from(e.getClientRects())}function iO(e){return Zi(us(e)).left+Ag(e).scrollLeft}function pee(e){const n=us(e),t=Ag(e),r=e.ownerDocument.body,o=Zn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=Zn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+iO(e);const a=-t.scrollTop;return Gr(r).direction==="rtl"&&(i+=Zn(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function fee(e,n){const t=or(e),r=us(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=O0();(!c||c&&n==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function gee(e,n){const t=Zi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=Po(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 YI(e,n,t){let r;if(n==="viewport")r=fee(e,t);else if(n==="document")r=pee(us(e));else if(bo(n))r=gee(n,t);else{const o=sO(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return If(r)}function aO(e,n){const t=Js(e);return t===n||!bo(t)||Pl(t)?!1:Gr(t).position==="fixed"||aO(t,n)}function mee(e,n){const t=n.get(e);if(t)return t;let r=Su(e,[],!1).filter(a=>bo(a)&&Nl(a)!=="body"),o=null;const s=Gr(e).position==="fixed";let i=s?Js(e):e;for(;bo(i)&&!Pl(i);){const a=Gr(i),l=j0(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Vu(i)&&!l&&aO(e,i))?r=r.filter(u=>u!==i):o=a,i=Js(i)}return n.set(e,r),r}function yee(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?Mg(n)?[]:mee(n,this._c):[].concat(t),r],a=i[0],l=i.reduce((c,u)=>{const h=YI(n,u,o);return c.top=Zn(h.top,c.top),c.right=ho(h.right,c.right),c.bottom=ho(h.bottom,c.bottom),c.left=Zn(h.left,c.left),c},YI(n,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function See(e){const{width:n,height:t}=oO(e);return{width:n,height:t}}function vee(e,n,t){const r=Po(n),o=us(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"||Vu(o))&&(a=Ag(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=iO(o));const c=i.left+a.scrollLeft-l.x,u=i.top+a.scrollTop-l.y;return{x:c,y:u,width:i.width,height:i.height}}function Ey(e){return Gr(e).position==="static"}function XI(e,n){return!Po(e)||Gr(e).position==="fixed"?null:n?n(e):e.offsetParent}function lO(e,n){const t=or(e);if(Mg(e))return t;if(!Po(e)){let o=Js(e);for(;o&&!Pl(o);){if(bo(o)&&!Ey(o))return o;o=Js(o)}return t}let r=XI(e,n);for(;r&&aee(r)&&Ey(r);)r=XI(r,n);return r&&Pl(r)&&Ey(r)&&!j0(r)?t:r||lee(e)||t}const xee=async function(e){const n=this.getOffsetParent||lO,t=this.getDimensions,r=await t(e.floating);return{reference:vee(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function wee(e){return Gr(e).direction==="rtl"}const bee={convertOffsetParentRelativeRectToViewportRelativeRect:dee,getDocumentElement:us,getClippingRect:yee,getOffsetParent:lO,getElementRects:xee,getClientRects:hee,getDimensions:See,getScale:sl,isElement:bo,isRTL:wee};function Pee(e,n){let t=null,r;const o=us(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:u,width:h,height:p}=e.getBoundingClientRect();if(a||n(),!h||!p)return;const f=lh(u),y=lh(o.clientWidth-(c+h)),m=lh(o.clientHeight-(u+p)),x=lh(c),v={rootMargin:-f+"px "+-y+"px "+-m+"px "+-x+"px",threshold:Zn(0,ho(1,l))||1};let b=!0;function E(k){const C=k[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 Cee(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=D0(e),u=o||s?[...c?Su(c):[],...Su(n)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",t,{passive:!0}),s&&S.addEventListener("resize",t)});const h=c&&a?Pee(c,t):null;let p=-1,f=null;i&&(f=new ResizeObserver(S=>{let[v]=S;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 y,m=l?Zi(e):null;l&&x();function x(){const S=Zi(e);m&&(S.x!==m.x||S.y!==m.y||S.width!==m.width||S.height!==m.height)&&t(),m=S,y=requestAnimationFrame(x)}return t(),()=>{var S;u.forEach(v=>{o&&v.removeEventListener("scroll",t),s&&v.removeEventListener("resize",t)}),h==null||h(),(S=f)==null||S.disconnect(),f=null,l&&cancelAnimationFrame(y)}}const Iee=ree,Eee=oee,kee=eee,_ee=iee,Tee=tee,qI=JJ,Mee=see,Aee=(e,n,t)=>{const r=new Map,o={platform:bee,...t},s={...o.platform,_c:r};return QJ(e,n,{...o,platform:s})};var fp=typeof document<"u"?P.useLayoutEffect:P.useEffect;function Ef(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(!Ef(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)&&!Ef(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function cO(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function ZI(e,n){const t=cO(e);return Math.round(n*t)/t}function QI(e){const n=P.useRef(e);return fp(()=>{n.current=e}),n}function jee(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,[u,h]=P.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[p,f]=P.useState(r);Ef(p,r)||f(r);const[y,m]=P.useState(null),[x,S]=P.useState(null),v=P.useCallback(K=>{K!==C.current&&(C.current=K,m(K))},[]),b=P.useCallback(K=>{K!==I.current&&(I.current=K,S(K))},[]),E=s||y,k=i||x,C=P.useRef(null),I=P.useRef(null),T=P.useRef(u),O=l!=null,_=QI(l),M=QI(o),L=P.useCallback(()=>{if(!C.current||!I.current)return;const K={placement:n,strategy:t,middleware:p};M.current&&(K.platform=M.current),Aee(C.current,I.current,K).then(z=>{const U={...z,isPositioned:!0};j.current&&!Ef(T.current,U)&&(T.current=U,aa.flushSync(()=>{h(U)}))})},[p,n,t,M]);fp(()=>{c===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,h(K=>({...K,isPositioned:!1})))},[c]);const j=P.useRef(!1);fp(()=>(j.current=!0,()=>{j.current=!1}),[]),fp(()=>{if(E&&(C.current=E),k&&(I.current=k),E&&k){if(_.current)return _.current(E,k,L);L()}},[E,k,L,_,O]);const R=P.useMemo(()=>({reference:C,floating:I,setReference:v,setFloating:b}),[v,b]),F=P.useMemo(()=>({reference:E,floating:k}),[E,k]),W=P.useMemo(()=>{const K={position:t,left:0,top:0};if(!F.floating)return K;const z=ZI(F.floating,u.x),U=ZI(F.floating,u.y);return a?{...K,transform:"translate("+z+"px, "+U+"px)",...cO(F.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:z,top:U}},[t,a,F.floating,u.x,u.y]);return P.useMemo(()=>({...u,update:L,refs:R,elements:F,floatingStyles:W}),[u,L,R,F,W])}const Oee=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?qI({element:r.current,padding:o}).fn(t):{}:r?qI({element:r,padding:o}).fn(t):{}}}},Dee=(e,n)=>({...Iee(e),options:[e,n]}),Ree=(e,n)=>({...Eee(e),options:[e,n]}),Lee=(e,n)=>({...Mee(e),options:[e,n]}),$ee=(e,n)=>({...kee(e),options:[e,n]}),Fee=(e,n)=>({..._ee(e),options:[e,n]}),Nee=(e,n)=>({...Tee(e),options:[e,n]}),zee=(e,n)=>({...Oee(e),options:[e,n]});var Bee="Arrow",uO=P.forwardRef((e,n)=>{const{children:t,width:r=10,height:o=5,...s}=e;return d.jsx(Ce.svg,{...s,ref:n,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?t:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});uO.displayName=Bee;var Uee=uO;function dO(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 R0="Popper",[hO,jg]=ko(R0),[Hee,pO]=hO(R0),fO=e=>{const{__scopePopper:n,children:t}=e,[r,o]=P.useState(null);return d.jsx(Hee,{scope:n,anchor:r,onAnchorChange:o,children:t})};fO.displayName=R0;var gO="PopperAnchor",mO=P.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=pO(gO,t),i=P.useRef(null),a=Ye(n,i);return P.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ce.div,{...o,ref:a})});mO.displayName=gO;var L0="PopperContent",[Kee,Wee]=hO(L0),yO=P.forwardRef((e,n)=>{var je,et,Ae,at,Ne,Gn;const{__scopePopper:t,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:f="optimized",onPlaced:y,...m}=e,x=pO(L0,t),[S,v]=P.useState(null),b=Ye(n,Rt=>v(Rt)),[E,k]=P.useState(null),C=dO(E),I=(C==null?void 0:C.width)??0,T=(C==null?void 0:C.height)??0,O=r+(s!=="center"?"-"+s:""),_=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},M=Array.isArray(c)?c:[c],L=M.length>0,j={padding:_,boundary:M.filter(Vee),altBoundary:L},{refs:R,floatingStyles:F,placement:W,isPositioned:K,middlewareData:z}=jee({strategy:"fixed",placement:O,whileElementsMounted:(...Rt)=>Cee(...Rt,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[Dee({mainAxis:o+T,alignmentAxis:i}),l&&Ree({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Lee():void 0,...j}),l&&$ee({...j}),Fee({...j,apply:({elements:Rt,rects:Cn,availableWidth:St,availableHeight:Xt})=>{const{width:_o,height:Bl}=Cn.reference,ps=Rt.floating.style;ps.setProperty("--radix-popper-available-width",`${St}px`),ps.setProperty("--radix-popper-available-height",`${Xt}px`),ps.setProperty("--radix-popper-anchor-width",`${_o}px`),ps.setProperty("--radix-popper-anchor-height",`${Bl}px`)}}),E&&zee({element:E,padding:a}),Yee({arrowWidth:I,arrowHeight:T}),p&&Nee({strategy:"referenceHidden",...j})]}),[U,X]=xO(W),J=Vt(y);Xs(()=>{K&&(J==null||J())},[K,J]);const le=(je=z.arrow)==null?void 0:je.x,ye=(et=z.arrow)==null?void 0:et.y,Me=((Ae=z.arrow)==null?void 0:Ae.centerOffset)!==0,[ae,Ue]=P.useState();return Xs(()=>{S&&Ue(window.getComputedStyle(S).zIndex)},[S]),d.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(" "),...((Gn=z.hide)==null?void 0:Gn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(Kee,{scope:t,placedSide:U,onArrowChange:k,arrowX:le,arrowY:ye,shouldHideArrow:Me,children:d.jsx(Ce.div,{"data-side":U,"data-align":X,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});yO.displayName=L0;var SO="PopperArrow",Gee={top:"bottom",right:"left",bottom:"top",left:"right"},vO=P.forwardRef(function(n,t){const{__scopePopper:r,...o}=n,s=Wee(SO,r),i=Gee[s.placedSide];return d.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:d.jsx(Uee,{...o,ref:t,style:{...o.style,display:"block"}})})});vO.displayName=SO;function Vee(e){return e!==null}var Yee=e=>({name:"transformOrigin",options:e,fn(n){var x,S,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,u]=xO(t),h={start:"0%",center:"50%",end:"100%"}[u],p=(((S=o.arrow)==null?void 0:S.x)??0)+a/2,f=(((v=o.arrow)==null?void 0:v.y)??0)+l/2;let y="",m="";return c==="bottom"?(y=i?h:`${p}px`,m=`${-l}px`):c==="top"?(y=i?h:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(y=`${-l}px`,m=i?h:`${f}px`):c==="left"&&(y=`${r.floating.width+l}px`,m=i?h:`${f}px`),{data:{x:y,y:m}}}});function xO(e){const[n,t="center"]=e.split("-");return[n,t]}var $0=fO,F0=mO,wO=yO,bO=vO,N0="Popover",[PO,Jie]=ko(N0,[jg]),Yu=jg(),[Xee,ci]=PO(N0),CO=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Yu(n),l=P.useRef(null),[c,u]=P.useState(!1),[h=!1,p]=li({prop:r,defaultProp:o,onChange:s});return d.jsx($0,{...a,children:d.jsx(Xee,{scope:n,contentId:Xo(),triggerRef:l,open:h,onOpenChange:p,onOpenToggle:P.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:c,onCustomAnchorAdd:P.useCallback(()=>u(!0),[]),onCustomAnchorRemove:P.useCallback(()=>u(!1),[]),modal:i,children:t})})};CO.displayName=N0;var IO="PopoverAnchor",qee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(IO,t),s=Yu(t),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return P.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(F0,{...s,...r,ref:n})});qee.displayName=IO;var EO="PopoverTrigger",kO=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(EO,t),s=Yu(t),i=Ye(n,o.triggerRef),a=d.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:d.jsx(F0,{asChild:!0,...s,children:a})});kO.displayName=EO;var z0="PopoverPortal",[Zee,Qee]=PO(z0,{forceMount:void 0}),_O=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=ci(z0,n);return d.jsx(Zee,{scope:n,forceMount:t,children:d.jsx(Xr,{present:t||s.open,children:d.jsx(Gu,{asChild:!0,container:o,children:r})})})};_O.displayName=z0;var Cl="PopoverContent",TO=P.forwardRef((e,n)=>{const t=Qee(Cl,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=ci(Cl,e.__scopePopover);return d.jsx(Xr,{present:r||s.open,children:s.modal?d.jsx(Jee,{...o,ref:n}):d.jsx(ete,{...o,ref:n})})});TO.displayName=Cl;var Jee=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 y0(i)},[]),d.jsx(bg,{as:Xi,allowPinchZoom:!0,children:d.jsx(MO,{...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})})})}),ete=P.forwardRef((e,n)=>{const t=ci(Cl,e.__scopePopover),r=P.useRef(!1),o=P.useRef(!1);return d.jsx(MO,{...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()}})}),MO=P.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=e,p=ci(Cl,t),f=Yu(t);return m0(),d.jsx(xg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Wu,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(wO,{"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)"}})})})}),AO="PopoverClose",tte=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(AO,t);return d.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,()=>o.onOpenChange(!1))})});tte.displayName=AO;var nte="PopoverArrow",rte=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Yu(t);return d.jsx(bO,{...o,...r,ref:n})});rte.displayName=nte;function jO(e){return e?"open":"closed"}var ote=CO,ste=kO,ite=_O,ate=TO;function ui(e,n){const t=B(),r=P.useRef(!1),o=Zr(),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 B0({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=ui(e,t);return d.jsx(ote,{onOpenChange:s,open:r||o,children:d.jsx("div",{className:"tlui-popover",children:n})})}function U0({children:e}){return d.jsx(ste,{asChild:!0,dir:"ltr",children:e})}function H0({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=un();return d.jsx(ite,{container:s,children:d.jsx(ate,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const OO=P.createContext(null);function Og(){const e=P.useContext(OO);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function _r({type:e,sourceId:n,children:t}){return d.jsx(OO.Provider,{value:{type:e,sourceId:n},children:t})}function lte(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const o=An(e,r);if(o.start||o.end)return!1}return!0})}const DO=()=>{const e=B();return G("threeStackableItems",()=>lte(e).length>2,[e])},ds=()=>{const e=B();return G("isInSelectState",()=>e.isIn("select"),[e])},RO=()=>{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=An(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])},LO=()=>{const e=B();return G("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},cte=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function $O(e,n){const t=B();return G("selectedShapes",()=>t.getSelectedShapes().length>=e,[t,e,n])}function Pn(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 ute(){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 FO(){const e=B();return G("hasLinkShapeSelected",()=>{const n=e.getOnlySelectedShape();return!!(n&&n.type!=="embed"&&"url"in n.props&&!n.isLocked)},[e])}function dte(){const e=B();return G("onlyFlippableShape",()=>{const n=e.getOnlySelectedShape();return n&&(e.isShapeOfType(n,"group")||e.isShapeOfType(n,"image")||e.isShapeOfType(n,"arrow")||e.isShapeOfType(n,"line")||e.isShapeOfType(n,"draw"))},[e])}function NO(){const e=B();return G("useCanRedo",()=>e.getCanRedo(),[e])}function zO(){const e=B();return G("useCanUndo",()=>e.getCanUndo(),[e])}var hte=P.createContext(void 0);function K0(e){const n=P.useContext(hte);return e||n||"ltr"}var ky="rovingFocusGroup.onEntryFocus",pte={bubbles:!1,cancelable:!0},Dg="RovingFocusGroup",[Gv,BO,fte]=Pg(Dg),[gte,UO]=ko(Dg,[fte]),[mte,yte]=gte(Dg),HO=P.forwardRef((e,n)=>d.jsx(Gv.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(Gv.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(Ste,{...e,ref:n})})}));HO.displayName=Dg;var Ste=P.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=e,p=P.useRef(null),f=Ye(n,p),y=K0(s),[m=null,x]=li({prop:i,defaultProp:a,onChange:l}),[S,v]=P.useState(!1),b=Vt(c),E=BO(t),k=P.useRef(!1),[C,I]=P.useState(0);return P.useEffect(()=>{const T=p.current;if(T)return T.addEventListener(ky,b),()=>T.removeEventListener(ky,b)},[b]),d.jsx(mte,{scope:t,orientation:r,dir:y,loop:o,currentTabStopId:m,onItemFocus:P.useCallback(T=>x(T),[x]),onItemShiftTab:P.useCallback(()=>v(!0),[]),onFocusableItemAdd:P.useCallback(()=>I(T=>T+1),[]),onFocusableItemRemove:P.useCallback(()=>I(T=>T-1),[]),children:d.jsx(Ce.div,{tabIndex:S||C===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...e.style},onMouseDown:re(e.onMouseDown,()=>{k.current=!0}),onFocus:re(e.onFocus,T=>{const O=!k.current;if(T.target===T.currentTarget&&O&&!S){const _=new CustomEvent(ky,pte);if(T.currentTarget.dispatchEvent(_),!_.defaultPrevented){const M=E().filter(W=>W.focusable),L=M.find(W=>W.active),j=M.find(W=>W.id===m),F=[L,j,...M].filter(Boolean).map(W=>W.ref.current);GO(F,u)}}k.current=!1}),onBlur:re(e.onBlur,()=>v(!1))})})}),KO="RovingFocusGroupItem",WO=P.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Xo(),l=s||a,c=yte(KO,t),u=c.currentTabStopId===l,h=BO(t),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return P.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx(Gv.ItemSlot,{scope:t,id:l,focusable:r,active:o,children:d.jsx(Ce.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:n,onMouseDown:re(e.onMouseDown,y=>{r?c.onItemFocus(l):y.preventDefault()}),onFocus:re(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:re(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){c.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const m=wte(y,c.orientation,c.dir);if(m!==void 0){if(y.metaKey||y.ctrlKey||y.altKey||y.shiftKey)return;y.preventDefault();let S=h().filter(v=>v.focusable).map(v=>v.ref.current);if(m==="last")S.reverse();else if(m==="prev"||m==="next"){m==="prev"&&S.reverse();const v=S.indexOf(y.currentTarget);S=c.loop?bte(S,v+1):S.slice(v+1)}setTimeout(()=>GO(S))}})})})});WO.displayName=KO;var vte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function xte(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function wte(e,n,t){const r=xte(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return vte[r]}function GO(e,n=!1){const t=document.activeElement;for(const r of e)if(r===t||(r.focus({preventScroll:n}),document.activeElement!==t))return}function bte(e,n){return e.map((t,r)=>e[(n+r)%e.length])}var Pte=HO,Cte=WO,Vv=["Enter"," "],Ite=["ArrowDown","PageUp","Home"],VO=["ArrowUp","PageDown","End"],Ete=[...Ite,...VO],kte={ltr:[...Vv,"ArrowRight"],rtl:[...Vv,"ArrowLeft"]},_te={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xu="Menu",[vu,Tte,Mte]=Pg(Xu),[ca,Rg]=ko(Xu,[Mte,jg,UO]),qu=jg(),YO=UO(),[XO,di]=ca(Xu),[Ate,Zu]=ca(Xu),qO=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=qu(n),[l,c]=P.useState(null),u=P.useRef(!1),h=Vt(s),p=K0(o);return P.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),d.jsx($0,{...a,children:d.jsx(XO,{scope:n,open:t,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(Ate,{scope:n,onClose:P.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};qO.displayName=Xu;var jte="MenuAnchor",W0=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=qu(t);return d.jsx(F0,{...o,...r,ref:n})});W0.displayName=jte;var G0="MenuPortal",[Ote,ZO]=ca(G0,{forceMount:void 0}),QO=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=di(G0,n);return d.jsx(Ote,{scope:n,forceMount:t,children:d.jsx(Xr,{present:t||s.open,children:d.jsx(Gu,{asChild:!0,container:o,children:r})})})};QO.displayName=G0;var Ir="MenuContent",[Dte,V0]=ca(Ir),JO=P.forwardRef((e,n)=>{const t=ZO(Ir,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=di(Ir,e.__scopeMenu),i=Zu(Ir,e.__scopeMenu);return d.jsx(vu.Provider,{scope:e.__scopeMenu,children:d.jsx(Xr,{present:r||s.open,children:d.jsx(vu.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(Rte,{...o,ref:n}):d.jsx(Lte,{...o,ref:n})})})})}),Rte=P.forwardRef((e,n)=>{const t=di(Ir,e.__scopeMenu),r=P.useRef(null),o=Ye(n,r);return P.useEffect(()=>{const s=r.current;if(s)return y0(s)},[]),d.jsx(Y0,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:re(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),Lte=P.forwardRef((e,n)=>{const t=di(Ir,e.__scopeMenu);return d.jsx(Y0,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),Y0=P.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,disableOutsideScroll:y,...m}=e,x=di(Ir,t),S=Zu(Ir,t),v=qu(t),b=YO(t),E=Tte(t),[k,C]=P.useState(null),I=P.useRef(null),T=Ye(n,I,x.onContentChange),O=P.useRef(0),_=P.useRef(""),M=P.useRef(0),L=P.useRef(null),j=P.useRef("right"),R=P.useRef(0),F=y?bg:P.Fragment,W=y?{as:Xi,allowPinchZoom:!0}:void 0,K=U=>{var je,et;const X=_.current+U,J=E().filter(Ae=>!Ae.disabled),le=document.activeElement,ye=(je=J.find(Ae=>Ae.ref.current===le))==null?void 0:je.textValue,Me=J.map(Ae=>Ae.textValue),ae=Yte(Me,X,ye),Ue=(et=J.find(Ae=>Ae.textValue===ae))==null?void 0:et.ref.current;(function Ae(at){_.current=at,window.clearTimeout(O.current),at!==""&&(O.current=window.setTimeout(()=>Ae(""),1e3))})(X),Ue&&setTimeout(()=>Ue.focus())};P.useEffect(()=>()=>window.clearTimeout(O.current),[]),m0();const z=P.useCallback(U=>{var J,le;return j.current===((J=L.current)==null?void 0:J.side)&&qte(U,(le=L.current)==null?void 0:le.area)},[]);return d.jsx(Dte,{scope:t,searchRef:_,onItemEnter:P.useCallback(U=>{z(U)&&U.preventDefault()},[z]),onItemLeave:P.useCallback(U=>{var X;z(U)||((X=I.current)==null||X.focus(),C(null))},[z]),onTriggerLeave:P.useCallback(U=>{z(U)&&U.preventDefault()},[z]),pointerGraceTimerRef:M,onPointerGraceIntentChange:P.useCallback(U=>{L.current=U},[]),children:d.jsx(F,{...W,children:d.jsx(xg,{asChild:!0,trapped:o,onMountAutoFocus:re(s,U=>{var X;U.preventDefault(),(X=I.current)==null||X.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Wu,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(Pte,{asChild:!0,...b,dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:re(l,U=>{S.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(wO,{role:"menu","aria-orientation":"vertical","data-state":mD(x.open),"data-radix-menu-content":"",dir:S.dir,...v,...m,ref:T,style:{outline:"none",...m.style},onKeyDown:re(m.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=I.current;if(U.target!==Me||!Ete.includes(U.key))return;U.preventDefault();const Ue=E().filter(je=>!je.disabled).map(je=>je.ref.current);VO.includes(U.key)&&Ue.reverse(),Gte(Ue)}),onBlur:re(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(O.current),_.current="")}),onPointerMove:re(e.onPointerMove,xu(U=>{const X=U.target,J=R.current!==U.clientX;if(U.currentTarget.contains(X)&&J){const le=U.clientX>R.current?"right":"left";j.current=le,R.current=U.clientX}}))})})})})})})});JO.displayName=Ir;var $te="MenuGroup",X0=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return d.jsx(Ce.div,{role:"group",...r,ref:n})});X0.displayName=$te;var Fte="MenuLabel",eD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return d.jsx(Ce.div,{...r,ref:n})});eD.displayName=Fte;var kf="MenuItem",JI="menu.itemSelect",Lg=P.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=P.useRef(null),i=Zu(kf,e.__scopeMenu),a=V0(kf,e.__scopeMenu),l=Ye(n,s),c=P.useRef(!1),u=()=>{const h=s.current;if(!t&&h){const p=new CustomEvent(JI,{bubbles:!0,cancelable:!0});h.addEventListener(JI,f=>r==null?void 0:r(f),{once:!0}),g0(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(tD,{...o,ref:l,disabled:t,onClick:re(e.onClick,u),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===" "||Vv.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Lg.displayName=kf;var tD=P.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=V0(kf,t),a=YO(t),l=P.useRef(null),c=Ye(n,l),[u,h]=P.useState(!1),[p,f]=P.useState("");return P.useEffect(()=>{const y=l.current;y&&f((y.textContent??"").trim())},[s.children]),d.jsx(vu.ItemSlot,{scope:t,disabled:r,textValue:o??p,children:d.jsx(Cte,{asChild:!0,...a,focusable:!r,children:d.jsx(Ce.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:re(e.onPointerMove,xu(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:re(e.onPointerLeave,xu(y=>i.onItemLeave(y))),onFocus:re(e.onFocus,()=>h(!0)),onBlur:re(e.onBlur,()=>h(!1))})})})}),Nte="MenuCheckboxItem",nD=P.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return d.jsx(aD,{scope:e.__scopeMenu,checked:t,children:d.jsx(Lg,{role:"menuitemcheckbox","aria-checked":_f(t)?"mixed":t,...o,ref:n,"data-state":Q0(t),onSelect:re(o.onSelect,()=>r==null?void 0:r(_f(t)?!0:!t),{checkForDefaultPrevented:!1})})})});nD.displayName=Nte;var rD="MenuRadioGroup",[zte,Bte]=ca(rD,{value:void 0,onValueChange:()=>{}}),oD=P.forwardRef((e,n)=>{const{value:t,onValueChange:r,...o}=e,s=Vt(r);return d.jsx(zte,{scope:e.__scopeMenu,value:t,onValueChange:s,children:d.jsx(X0,{...o,ref:n})})});oD.displayName=rD;var sD="MenuRadioItem",iD=P.forwardRef((e,n)=>{const{value:t,...r}=e,o=Bte(sD,e.__scopeMenu),s=t===o.value;return d.jsx(aD,{scope:e.__scopeMenu,checked:s,children:d.jsx(Lg,{role:"menuitemradio","aria-checked":s,...r,ref:n,"data-state":Q0(s),onSelect:re(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,t)},{checkForDefaultPrevented:!1})})})});iD.displayName=sD;var q0="MenuItemIndicator",[aD,Ute]=ca(q0,{checked:!1}),lD=P.forwardRef((e,n)=>{const{__scopeMenu:t,forceMount:r,...o}=e,s=Ute(q0,t);return d.jsx(Xr,{present:r||_f(s.checked)||s.checked===!0,children:d.jsx(Ce.span,{...o,ref:n,"data-state":Q0(s.checked)})})});lD.displayName=q0;var Hte="MenuSeparator",cD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return d.jsx(Ce.div,{role:"separator","aria-orientation":"horizontal",...r,ref:n})});cD.displayName=Hte;var Kte="MenuArrow",uD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=qu(t);return d.jsx(bO,{...o,...r,ref:n})});uD.displayName=Kte;var Z0="MenuSub",[Wte,dD]=ca(Z0),hD=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=di(Z0,n),i=qu(n),[a,l]=P.useState(null),[c,u]=P.useState(null),h=Vt(o);return P.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),d.jsx($0,{...i,children:d.jsx(XO,{scope:n,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(Wte,{scope:n,contentId:Xo(),triggerId:Xo(),trigger:a,onTriggerChange:l,children:t})})})};hD.displayName=Z0;var Ec="MenuSubTrigger",pD=P.forwardRef((e,n)=>{const t=di(Ec,e.__scopeMenu),r=Zu(Ec,e.__scopeMenu),o=dD(Ec,e.__scopeMenu),s=V0(Ec,e.__scopeMenu),i=P.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=P.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return P.useEffect(()=>u,[u]),P.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),d.jsx(W0,{asChild:!0,...c,children:d.jsx(tD,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":mD(t.open),...e,ref:vg(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,xu(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:re(e.onPointerLeave,xu(h=>{var f,y;u();const p=(f=t.content)==null?void 0:f.getBoundingClientRect();if(p){const m=(y=t.content)==null?void 0:y.dataset.side,x=m==="right",S=x?-5:5,v=p[x?"left":"right"],b=p[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+S,y:h.clientY},{x:v,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x:v,y:p.bottom}],side:m}),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===" "||kte[r.dir].includes(h.key)&&(t.onOpenChange(!0),(f=t.content)==null||f.focus(),h.preventDefault())})})})});pD.displayName=Ec;var fD="MenuSubContent",gD=P.forwardRef((e,n)=>{const t=ZO(Ir,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=di(Ir,e.__scopeMenu),i=Zu(Ir,e.__scopeMenu),a=dD(fD,e.__scopeMenu),l=P.useRef(null),c=Ye(n,l);return d.jsx(vu.Provider,{scope:e.__scopeMenu,children:d.jsx(Xr,{present:r||s.open,children:d.jsx(vu.Slot,{scope:e.__scopeMenu,children:d.jsx(Y0,{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:u=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:re(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:re(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:re(e.onKeyDown,u=>{var f;const h=u.currentTarget.contains(u.target),p=_te[i.dir].includes(u.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});gD.displayName=fD;function mD(e){return e?"open":"closed"}function _f(e){return e==="indeterminate"}function Q0(e){return _f(e)?"indeterminate":e?"checked":"unchecked"}function Gte(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function Vte(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function Yte(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=Vte(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 Xte(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,u=n[i].y;l>r!=u>r&&t<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function qte(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return Xte(t,n)}function xu(e){return n=>n.pointerType==="mouse"?e(n):void 0}var yD=qO,SD=W0,vD=QO,xD=JO,wD=X0,bD=eD,PD=Lg,CD=nD,ID=oD,ED=iD,kD=lD,_D=cD,TD=uD,MD=hD,AD=pD,jD=gD,J0="ContextMenu",[Zte,eae]=ko(J0,[Rg]),dn=Rg(),[Qte,OD]=Zte(J0),DD=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),u=P.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(Qte,{scope:n,open:i,onOpenChange:u,modal:s,children:d.jsx(yD,{...l,dir:o,open:i,onOpenChange:u,modal:s,children:t})})};DD.displayName=J0;var RD="ContextMenuTrigger",LD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=OD(RD,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),u=P.useCallback(()=>window.clearTimeout(c.current),[]),h=p=>{a.current={x:p.clientX,y:p.clientY},s.onOpenChange(!0)};return P.useEffect(()=>u,[u]),P.useEffect(()=>void(r&&u()),[r,u]),d.jsxs(d.Fragment,{children:[d.jsx(SD,{...i,virtualRef:l}),d.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=>{u(),h(p),p.preventDefault()}),onPointerDown:r?e.onPointerDown:re(e.onPointerDown,ch(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?e.onPointerMove:re(e.onPointerMove,ch(u)),onPointerCancel:r?e.onPointerCancel:re(e.onPointerCancel,ch(u)),onPointerUp:r?e.onPointerUp:re(e.onPointerUp,ch(u))})]})});LD.displayName=RD;var Jte="ContextMenuPortal",eb=e=>{const{__scopeContextMenu:n,...t}=e,r=dn(n);return d.jsx(vD,{...r,...t})};eb.displayName=Jte;var $D="ContextMenuContent",FD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=OD($D,t),s=dn(t),i=P.useRef(!1);return d.jsx(xD,{...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)"}})});FD.displayName=$D;var ene="ContextMenuGroup",ND=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(wD,{...o,...r,ref:n})});ND.displayName=ene;var tne="ContextMenuLabel",nne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(bD,{...o,...r,ref:n})});nne.displayName=tne;var rne="ContextMenuItem",zD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(PD,{...o,...r,ref:n})});zD.displayName=rne;var one="ContextMenuCheckboxItem",BD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(CD,{...o,...r,ref:n})});BD.displayName=one;var sne="ContextMenuRadioGroup",ine=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(ID,{...o,...r,ref:n})});ine.displayName=sne;var ane="ContextMenuRadioItem",lne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(ED,{...o,...r,ref:n})});lne.displayName=ane;var cne="ContextMenuItemIndicator",une=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(kD,{...o,...r,ref:n})});une.displayName=cne;var dne="ContextMenuSeparator",hne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(_D,{...o,...r,ref:n})});hne.displayName=dne;var pne="ContextMenuArrow",fne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(TD,{...o,...r,ref:n})});fne.displayName=pne;var gne="ContextMenuSub",UD=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 d.jsx(MD,{...i,open:a,onOpenChange:l,children:t})};UD.displayName=gne;var mne="ContextMenuSubTrigger",HD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(AD,{...o,...r,ref:n})});HD.displayName=mne;var yne="ContextMenuSubContent",KD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(jD,{...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)"}})});KD.displayName=yne;function ch(e){return n=>n.pointerType!=="mouse"?e(n):void 0}var Sne=DD,vne=LD,xne=eb,wne=FD,bne=BD;const WD=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Pne=WD?"⌘":"Ctrl",Cne=WD?"⌥":"Alt";function GD(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,Pne).replace(/\?/g,Cne).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Yv(e){return"— "+GD(e).join(" ")}function Ine(e){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}var tb="DropdownMenu",[Ene,tae]=ko(tb,[Rg]),hn=Rg(),[kne,VD]=Ene(tb),YD=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),[u=!1,h]=li({prop:o,defaultProp:s,onChange:i});return d.jsx(kne,{scope:n,triggerId:Xo(),triggerRef:c,contentId:Xo(),open:u,onOpenChange:h,onOpenToggle:P.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx(yD,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:t})})};YD.displayName=tb;var XD="DropdownMenuTrigger",qD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=VD(XD,t),i=hn(t);return d.jsx(SD,{asChild:!0,...i,children:d.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:vg(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())})})})});qD.displayName=XD;var _ne="DropdownMenuPortal",ZD=e=>{const{__scopeDropdownMenu:n,...t}=e,r=hn(n);return d.jsx(vD,{...r,...t})};ZD.displayName=_ne;var QD="DropdownMenuContent",JD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=VD(QD,t),s=hn(t),i=P.useRef(!1);return d.jsx(xD,{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,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});JD.displayName=QD;var Tne="DropdownMenuGroup",eR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(wD,{...o,...r,ref:n})});eR.displayName=Tne;var Mne="DropdownMenuLabel",Ane=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(bD,{...o,...r,ref:n})});Ane.displayName=Mne;var jne="DropdownMenuItem",tR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(PD,{...o,...r,ref:n})});tR.displayName=jne;var One="DropdownMenuCheckboxItem",nR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(CD,{...o,...r,ref:n})});nR.displayName=One;var Dne="DropdownMenuRadioGroup",Rne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(ID,{...o,...r,ref:n})});Rne.displayName=Dne;var Lne="DropdownMenuRadioItem",$ne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(ED,{...o,...r,ref:n})});$ne.displayName=Lne;var Fne="DropdownMenuItemIndicator",Nne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(kD,{...o,...r,ref:n})});Nne.displayName=Fne;var zne="DropdownMenuSeparator",Bne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(_D,{...o,...r,ref:n})});Bne.displayName=zne;var Une="DropdownMenuArrow",Hne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(TD,{...o,...r,ref:n})});Hne.displayName=Une;var Kne=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 d.jsx(MD,{...i,open:a,onOpenChange:l,children:t})},Wne="DropdownMenuSubTrigger",rR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(AD,{...o,...r,ref:n})});rR.displayName=Wne;var Gne="DropdownMenuSubContent",oR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(jD,{...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)"}})});oR.displayName=Gne;var nb=YD,rb=qD,$g=ZD,ob=JD,Vne=eR,Yne=tR,Xne=nR,qne=Kne,Zne=rR,Qne=oR;function Qi({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=ui(e);return d.jsx(nb,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function Ji({children:e,...n}){return d.jsx(rb,{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 d.jsx($g,{container:s,children:d.jsx(ob,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function Jne({id:e,children:n}){const[t,r]=ui(e);return d.jsx(qne,{open:t,onOpenChange:r,children:n})}function ere({id:e,label:n,title:t,disabled:r}){return d.jsx(Zne,{dir:"ltr",asChild:!0,disabled:r,children:d.jsxs(he,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[d.jsx(bt,{children:n}),d.jsx(Pe,{icon:"chevron-right",small:!0})]})})}function tre({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=un();return d.jsx($g,{container:s,children:d.jsx(Qne,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function nre({children:e}){return d.jsx(Vne,{dir:"ltr",className:"tlui-menu__group",children:e})}function wu({noClose:e,children:n}){return d.jsx(Yne,{dir:"ltr",asChild:!0,onClick:e?Ee:void 0,children:n})}function Uc({children:e,visibleOnMobileLayout:n=!1}){const t=Hn();return!n&&t<yt.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:GD(e).map((r,o)=>d.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:u,sourceId:h}=Og(),p=Te(),[f,y]=P.useState(!1);if(cs()&&!t)return null;const x=mu(s,u),S=o?Yv(o):void 0,v=x?p(x):void 0,b=v&&S?`${v} ${S}`:v;switch(u){case"menu":return d.jsx(wu,{children:d.jsxs(he,{type:"menu","data-testid":`${h}.${r}`,disabled:e,title:b,onClick:E=>{l&&Ee(E),f?y(!1):a(h)},children:[d.jsx(bt,{children:v}),o&&d.jsx(Uc,{children:o})]})});case"context-menu":return e?null:d.jsxs(zD,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:E=>{l&&Ee(E),f?y(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&d.jsx(Uc,{children:o}),n&&d.jsx(Ine,{})]});case"panel":return d.jsxs(he,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:e,onClick:()=>a(h),children:[d.jsx(bt,{children:v}),i&&d.jsx(Pe,{icon:i})]});case"small-icons":case"icons":return d.jsx(he,{"data-testid":`${h}.${r}`,type:"icon",title:b,disabled:e,onClick:()=>a(h),children:d.jsx(Pe,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return o?d.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${h}.${r}`,children:[d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(Uc,{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 d.jsxs(he,{type:"low",onClick:()=>a(h),children:[d.jsx(Pe,{icon:i}),d.jsx(bt,{children:v})]});case"toolbar":return d.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:d.jsx(Pe,{icon:i})});case"toolbar-overflow":return d.jsx(wu,{"aria-label":s,children:d.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:d.jsx(Pe,{icon:i})})});default:throw an(u)}}function rre(){return d.jsxs(d.Fragment,{children:[d.jsx(ore,{}),d.jsx(sre,{}),d.jsx(ire,{}),d.jsx(are,{}),d.jsx(lre,{}),d.jsx(dre,{}),d.jsx(hre,{}),d.jsx(pre,{})]})}function ore(){const e=ie(),n=Pn(2),t=ds(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["align-left"],disabled:!r}),d.jsx(H,{...e["align-center-horizontal"],disabled:!r}),d.jsx(H,{...e["align-right"],disabled:!r}),d.jsx(H,{...e["stretch-horizontal"],disabled:!r}),d.jsx(H,{...e["align-top"],disabled:!r}),d.jsx(H,{...e["align-center-vertical"],disabled:!r}),d.jsx(H,{...e["align-bottom"],disabled:!r}),d.jsx(H,{...e["stretch-vertical"],disabled:!r})]})}function sre(){const e=ie(),n=Pn(3),t=ds(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["distribute-horizontal"],disabled:!r}),d.jsx(H,{...e["distribute-vertical"],disabled:!r})]})}function ire(){const e=ie(),n=DO(),t=ds(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["stack-horizontal"],disabled:!r}),d.jsx(H,{...e["stack-vertical"],disabled:!r})]})}function are(){const e=ie(),n=Pn(1),t=ds(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["send-to-back"],disabled:!r}),d.jsx(H,{...e["send-backward"],disabled:!r}),d.jsx(H,{...e["bring-forward"],disabled:!r}),d.jsx(H,{...e["bring-to-front"],disabled:!r})]})}function lre(){return Hn()<yt.TABLET_SM?d.jsx(cre,{}):d.jsx(ure,{})}function cre(){const e=ie(),n=B(),t=G("zoom is 1",()=>n.getZoomLevel()===1,[n]);return d.jsx(H,{...e["zoom-to-100"],disabled:t})}function ure(){const e=ie(),n=Pn(1),t=ds(),r=n&&t;return d.jsx(H,{...e["rotate-ccw"],disabled:!r})}function dre(){const e=ie(),n=Pn(1),t=ds(),r=n&&t;return d.jsx(H,{...e["rotate-cw"],disabled:!r})}function hre(){const e=ie(),n=FO(),t=ds(),r=n&&t;return d.jsx(H,{...e["edit-link"],disabled:!r})}function pre(){const e=RO(),n=LO();return e?d.jsx(eE,{}):n?d.jsx(fre,{}):d.jsx(eE,{})}function eE(){const e=ie(),n=Pn(2),t=ds(),r=n&&t;return d.jsx(H,{...e.group,disabled:!r})}function fre(){const e=ie();return d.jsx(H,{...e.ungroup})}const gre=P.memo(function({children:n}){const t=Te(),r=Hn(),o=cs(),s=B(),i=G("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??d.jsx(rre,{});if(!(o&&!i))return d.jsxs(B0,{id:"actions-menu",children:[d.jsx(U0,{children:d.jsx(he,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:d.jsx(Pe,{icon:"dots-vertical",small:!0})})}),d.jsx(H0,{side:r>=yt.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(_r,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function Kn({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=Og(),u=cs(),h=Te();if(u&&!r)return null;const p=mu(t,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(Xne,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:y=>{o==null||o(c),Ee(y)},disabled:i,checked:a,children:[d.jsx(qs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),n&&d.jsx(Uc,{children:n})]});case"context-menu":return d.jsxs(bne,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:y=>{o(c),Ee(y)},disabled:i,checked:a,children:[d.jsx(qs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),n&&d.jsx(Uc,{children:n})]},e);default:return null}}function ge({id:e,label:n,children:t}){const{type:r,sourceId:o}=Og(),s=Te(),i=mu(n,r),a=i?s(i):void 0;switch(r){case"panel":return d.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return d.jsx(nre,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return d.jsx(ND,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return d.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[d.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),d.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function Wn({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=Og(),a=un(),l=Te(),c=t?typeof t=="string"?t:t[s]??t.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return d.jsxs(Jne,{id:`${i}-sub.${e}`,children:[d.jsx(ere,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:n,label:u,title:u}),d.jsx(tre,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:d.jsxs(mre,{id:`${i}-sub.${e}`,children:[d.jsx(HD,{dir:"ltr",disabled:n,asChild:!0,children:d.jsxs(he,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(bt,{children:u}),d.jsx(Pe,{icon:"chevron-right",small:!0})]})}),d.jsx(eb,{container:a,children:d.jsx(KD,{"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 mre({id:e,children:n}){const[t,r]=ui(e);return d.jsx(UD,{open:t,onOpenChange:r,children:n})}function sR(){const e=ie();return ute()?d.jsx(H,{...e["toggle-auto-size"]}):null}function iR(){const e=ie();return FO()?d.jsx(H,{...e["edit-link"]}):null}function yre(){const e=ie();return Pn(1)?d.jsx(H,{...e.duplicate}):null}function aR(){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])?d.jsx(H,{...e["flatten-to-image"]}):null}function lR(){const e=ie();return RO()?d.jsx(H,{...e.group}):null}function cR(){const e=ie();return LO()?d.jsx(H,{...e.ungroup}):null}function uR(){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])?d.jsx(H,{...n["remove-frame"]}):null}function dR(){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])?d.jsx(H,{...n["fit-frame-to-content"]}):null}function hR(){const e=B(),n=ie();return G("selected shapes",()=>e.getSelectedShapes().length>0,[e])?d.jsx(H,{...n["toggle-lock"]}):null}function sb(){const e=ie(),n=B(),t=G("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return d.jsx(Kn,{...e["toggle-transparent"],checked:t,toggle:!0})}function Sre(){const e=B(),n=ie(),t=G("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return d.jsx(H,{...n["unlock-all"],disabled:!t})}function pR(){const e=B(),n=G("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=ie();return d.jsx(H,{...t["zoom-to-100"],noClose:!0,disabled:n})}function fR(){const e=B(),n=G("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=ie();return d.jsx(H,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function gR(){const e=B(),n=G("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=ie();return d.jsx(H,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function mR(){return d.jsxs(ge,{id:"clipboard",children:[d.jsx(xre,{}),d.jsx(wre,{}),d.jsx(bre,{}),d.jsx(yre,{}),d.jsx(Pre,{})]})}function vre(){var r;const e=B(),n=ie(),t=G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return d.jsxs(Wn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[d.jsxs(ge,{id:"copy-as-group",children:[d.jsx(H,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&d.jsx(H,{...n["copy-as-png"]}),d.jsx(H,{...n["copy-as-json"]})]}),d.jsx(ge,{id:"copy-as-bg",children:d.jsx(sb,{})})]})}function xre(){const e=ie(),n=Pn(1);return d.jsx(H,{...e.cut,disabled:!n})}function wre(){const e=ie(),n=$O(1);return d.jsx(H,{...e.copy,disabled:!n})}function bre(){const e=ie(),n=cte;return d.jsx(H,{...e.paste,disabled:!n})}function yR(){const e=B(),n=ie();return G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?d.jsxs(ge,{id:"conversions",children:[d.jsx(vre,{}),d.jsxs(Wn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(ge,{id:"export-as-group",children:[d.jsx(H,{...n["export-as-svg"]}),d.jsx(H,{...n["export-as-png"]}),d.jsx(H,{...n["export-as-json"]})]}),d.jsx(ge,{id:"export-as-bg",children:d.jsx(sb,{})})]})]}):null}function SR(){const e=ie(),n=B(),t=G("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return d.jsx(H,{...e["select-all"],disabled:!t})}function Pre(){const e=ie(),n=Pn(1);return d.jsx(H,{...e.delete,disabled:!n})}function Cre(){return $O(1)?d.jsxs(Wn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(lR,{}),d.jsx(cR,{}),d.jsx(aR,{}),d.jsx(iR,{}),d.jsx(dR,{}),d.jsx(uR,{}),d.jsx(xR,{}),d.jsx(vR,{}),d.jsx(sR,{}),d.jsx(hR,{})]}):null}function Ire(){const e=Pn(2),n=dte(),t=ie();return e||n?d.jsxs(Wn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&d.jsxs(ge,{id:"align",children:[d.jsx(H,{...t["align-left"]}),d.jsx(H,{...t["align-center-horizontal"]}),d.jsx(H,{...t["align-right"]}),d.jsx(H,{...t["align-top"]}),d.jsx(H,{...t["align-center-vertical"]}),d.jsx(H,{...t["align-bottom"]})]}),d.jsx(Ere,{}),e&&d.jsxs(ge,{id:"stretch",children:[d.jsx(H,{...t["stretch-horizontal"]}),d.jsx(H,{...t["stretch-vertical"]})]}),(e||n)&&d.jsxs(ge,{id:"flip",children:[d.jsx(H,{...t["flip-horizontal"]}),d.jsx(H,{...t["flip-vertical"]})]}),d.jsx(kre,{})]}):null}function Ere(){const e=ie();return Pn(3)?d.jsxs(ge,{id:"distribute",children:[d.jsx(H,{...e["distribute-horizontal"]}),d.jsx(H,{...e["distribute-vertical"]})]}):null}function kre(){const e=ie(),n=Pn(2),t=DO();return n?d.jsxs(ge,{id:"order",children:[d.jsx(H,{...e.pack}),t&&d.jsx(H,{...e["stack-horizontal"]}),t&&d.jsx(H,{...e["stack-vertical"]})]}):null}function _re(){const e=ie();return Pn(1)?d.jsx(Wn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ge,{id:"reorder",children:[d.jsx(H,{...e["bring-to-front"]}),d.jsx(H,{...e["bring-forward"]}),d.jsx(H,{...e["send-backward"]}),d.jsx(H,{...e["send-to-back"]})]})}):null}function Tre(){const e=B(),n=G("pages",()=>e.getPages(),[e]),t=G("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Qr(),o=ie(),s=Zr();return Pn(1)?d.jsxs(Wn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ge,{id:"pages",children:n.map(a=>d.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))}),d.jsx(ge,{id:"new-page",children:d.jsx(H,{...o["new-page"]})})]}):null}function vR(){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])?d.jsx(H,{...n["convert-to-bookmark"]}):null}function xR(){const e=B(),n=ie();return G("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&As(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?d.jsx(H,{...n["convert-to-embed"]}):null}function Mre(){const e=ie(),n=B(),t=G("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return d.jsx(Kn,{...e["toggle-snap-mode"],checked:t})}function Are(){const e=ie(),n=B(),t=G("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return d.jsx(Kn,{...e["toggle-tool-lock"],checked:t})}function jre(){const e=ie(),n=B(),t=G("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return d.jsx(Kn,{...e["toggle-grid"],checked:t})}function Ore(){const e=ie(),n=B(),t=G("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return d.jsx(Kn,{...e["toggle-wrap-mode"],checked:t})}function Dre(){const e=ie(),n=B(),t=G("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return d.jsx(Kn,{...e["toggle-focus-mode"],checked:t})}function Rre(){const e=ie(),n=B(),t=G("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return d.jsx(Kn,{...e["toggle-edge-scrolling"],checked:t===1})}function Lre(){const e=ie(),n=B(),t=G("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return d.jsx(Kn,{...e["toggle-reduce-motion"],checked:t===0})}function $re(){const e=ie(),n=B(),t=G("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return d.jsx(Kn,{...e["toggle-debug-mode"],checked:t})}function Fre(){const e=ie(),n=B(),t=G("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return d.jsx(Kn,{...e["toggle-dynamic-size-mode"],checked:t})}function Nre(){const e=ie(),n=B(),t=G("paste at cursor",()=>n.user.getIsPasteAtCursorMode(),[n]);return d.jsx(Kn,{...e["toggle-paste-at-cursor"],checked:t})}function zre(){const e=B();return G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?d.jsxs(d.Fragment,{children:[d.jsxs(ge,{id:"modify",children:[d.jsx(Cre,{}),d.jsx(Ire,{}),d.jsx(_re,{}),d.jsx(Tre,{})]}),d.jsx(mR,{}),d.jsx(yR,{}),d.jsx(ge,{id:"select-all",children:d.jsx(SR,{})})]}):null}const Bre=P.memo(function({children:n}){const t=B(),{Canvas:r}=it(),o=P.useCallback(c=>{if(c){if(t.getInstanceState().isCoarsePointer){const u=t.getSelectedShapes(),{inputs:{currentPagePoint:h}}=t,p=t.getShapesAtPoint(h);if(!t.getSelectedShapes().length||!p.some(f=>u.includes(f))){const f=p.filter(y=>t.isShapeOrAncestorLocked(y));f.length&&t.select(...f.map(y=>y.id))}}}else{const u=t.getOnlySelectedShape();u&&t.isShapeOrAncestorLocked(u)&&t.setSelectedShapes([])}},[t]),s=un(),[i,a]=ui("context menu",o),l=n??d.jsx(zre,{});return d.jsxs(Sne,{dir:"ltr",onOpenChange:a,modal:!1,children:[d.jsx(vne,{onContextMenu:void 0,dir:"ltr",children:r?d.jsx(r,{}):null}),i&&d.jsx(xne,{container:s,children:d.jsx(wne,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ee,children:d.jsx(_r,{type:"context-menu",sourceId:"context-menu",children:l})})})]})});function Xv({checked:e}){return d.jsx(qs,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function Ure(){const e=B(),{addToast:n}=Qr(),{addDialog:t}=la(),[r,o]=we.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ge,{id:"items",children:[d.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"}),d.jsx(H,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>d.jsx(Wre,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),d.jsx(H,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>Gre(e,100)}),d.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})(),d.jsx(H,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),d.jsx(H,{id:"hard-reset",onSelect:aT,label:"Hard reset"})]}),d.jsxs(ge,{id:"flags",children:[d.jsx(Hre,{}),d.jsx(Kre,{})]})]})}function Hre(){const e=Object.values(xt);return e.length?d.jsx(Wn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ge,{id:"debug flags",children:e.map(n=>d.jsx(wR,{flag:n},n.name))})}):null}function Kre(){const e=Object.values(eH);return e.length?d.jsx(Wn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ge,{id:"feature flags",children:e.map(n=>d.jsx(wR,{flag:n},n.name))})}):null}function Wre({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=we.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(Eg,{children:[d.jsx(kg,{children:e}),d.jsx(_g,{})]}),d.jsx(gu,{style:{maxWidth:350},children:n}),d.jsxs(E0,{className:"tlui-dialog__footer__actions",children:[o&&d.jsxs(he,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(Xv,{checked:a}),d.jsx(bt,{children:"Don’t show again"})]}),d.jsx(he,{type:"normal",onClick:s,children:d.jsx(bt,{children:t})}),d.jsx(he,{type:"primary",onClick:async()=>i(),children:d.jsx(bt,{children:r})})]})]})}const wR=lr(function({flag:n,onChange:t}){const r=n.get();return d.jsx(Kn,{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 tE=0;function Gre(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)tE++,t[o]={id:$e("box"+tE),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function Vre({children:e}){const n=e??d.jsx(Ure,{});return d.jsxs(Qi,{id:"debug",children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon",title:"Debug menu",children:d.jsx(Pe,{icon:"dots-horizontal"})})}),d.jsx(ea,{side:"top",align:"end",alignOffset:0,children:d.jsx(_r,{type:"menu",sourceId:"debug-panel",children:n})})]})}const Yre=P.memo(function(){const{DebugMenu:n}=pi();return d.jsxs("div",{className:"tlui-debug-panel",children:[d.jsx(qre,{}),d.jsx(Zre,{}),n&&d.jsx(n,{})]})});function Xre(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 qre=lr(function(){Xre();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 d.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function Zre(){const e=B(),n=G("show_fps",()=>xt.showFps.get(),[xt]),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 u(){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(u)}return u(),()=>{cancelAnimationFrame(s)}},[n,e]),n?d.jsx("div",{ref:t}):null}function bR(){const e=B(),n=Zr(),t=G("locale",()=>e.user.getLocale(),[e]);return d.jsx(Wn,{id:"help menu language",label:"menu.language",children:d.jsx(ge,{id:"languages",children:Xc.map(({locale:r,label:o})=>d.jsx(Kn,{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 Qre(){return d.jsxs(d.Fragment,{children:[d.jsx(bR,{}),d.jsx(Jre,{})]})}function Jre(){const{KeyboardShortcutsDialog:e}=pi(),{addDialog:n}=la();return e?d.jsx(H,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const eoe=P.memo(function({children:n}){const t=Te(),r=Hn(),o=n??d.jsx(Qre,{});return r<yt.MOBILE?null:d.jsx("div",{className:"tlui-help-menu",children:d.jsxs(Qi,{id:"help menu",children:[d.jsx(Ji,{children:d.jsx(he,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(Pe,{icon:"question-mark",small:!0})})}),d.jsx(ea,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(_r,{type:"menu",sourceId:"help-menu",children:o})})]})})});function toe(){const e=B(),n=ie(),[t,r]=P.useState(!1),o=P.useRef(!1);return Os("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?d.jsx(H,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function noe(){const e=B(),n=ie();return G("is pen mode",()=>e.getInstanceState().isPenMode,[e])?d.jsx(H,{...n["exit-pen-mode"]}):null}function roe(){const e=B(),n=ie();return G("is following user",()=>!!e.getInstanceState().followingUserId,[e])?d.jsx(H,{...n["stop-following"]}):null}function ooe(){return d.jsxs(d.Fragment,{children:[d.jsx(noe,{}),d.jsx(toe,{}),d.jsx(roe,{})]})}function soe({children:e}){const n=e??d.jsx(ooe,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(_r,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}function ioe(){const e=ie(),n=Tg();return d.jsxs(d.Fragment,{children:[d.jsxs(ge,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(H,{...e["toggle-tool-lock"]}),d.jsx(H,{...e["insert-media"]}),d.jsx(H,{...n.select}),d.jsx(H,{...n.draw}),d.jsx(H,{...n.eraser}),d.jsx(H,{...n.hand}),d.jsx(H,{...n.rectangle}),d.jsx(H,{...n.ellipse}),d.jsx(H,{...n.arrow}),d.jsx(H,{...n.line}),d.jsx(H,{...n.text}),d.jsx(H,{...n.frame}),d.jsx(H,{...n.note}),d.jsx(H,{...n.laser})]}),d.jsxs(ge,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(H,{...e["toggle-dark-mode"]}),d.jsx(H,{...e["toggle-focus-mode"]}),d.jsx(H,{...e["toggle-grid"]})]}),d.jsxs(ge,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(H,{...e.undo}),d.jsx(H,{...e.redo}),d.jsx(H,{...e.cut}),d.jsx(H,{...e.copy}),d.jsx(H,{...e.paste}),d.jsx(H,{...e["select-all"]}),d.jsx(H,{...e.delete}),d.jsx(H,{...e.duplicate})]}),d.jsxs(ge,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(H,{...e["zoom-in"]}),d.jsx(H,{...e["zoom-out"]}),d.jsx(H,{...e["zoom-to-100"]}),d.jsx(H,{...e["zoom-to-fit"]}),d.jsx(H,{...e["zoom-to-selection"]})]}),d.jsxs(ge,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(H,{...e["bring-to-front"]}),d.jsx(H,{...e["bring-forward"]}),d.jsx(H,{...e["send-backward"]}),d.jsx(H,{...e["send-to-back"]}),d.jsx(H,{...e.group}),d.jsx(H,{...e.ungroup}),d.jsx(H,{...e["flip-horizontal"]}),d.jsx(H,{...e["flip-vertical"]}),d.jsx(H,{...e["align-top"]}),d.jsx(H,{...e["align-center-vertical"]}),d.jsx(H,{...e["align-bottom"]}),d.jsx(H,{...e["align-left"]}),d.jsx(H,{...e["align-center-horizontal"]}),d.jsx(H,{...e["align-right"]})]})]})}const aoe=P.memo(function({children:n}){const t=Te(),r=Hn(),o=n??d.jsx(ioe,{});return d.jsxs(d.Fragment,{children:[d.jsxs(Eg,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(kg,{children:t("shortcuts-dialog.title")}),d.jsx(_g,{})]}),d.jsx(gu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=yt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=yt.TABLET}),children:d.jsx(_r,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})}),loe=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function coe(){const e=B(),n=Zr(),t=G("colorScheme",()=>e.user.getUserPreferences().colorScheme,[e]);return d.jsx(Wn,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(ge,{id:"languages",children:loe.map(({colorScheme:r,label:o})=>d.jsx(Kn,{id:`color-scheme-${r}`,label:o,checked:r===t,onSelect:()=>{e.user.updateUserPreferences({colorScheme:r}),n("color-scheme",{source:"menu",value:r})}},r))})})}function uoe(){return d.jsxs(d.Fragment,{children:[d.jsx(hoe,{}),d.jsx(moe,{}),d.jsx(doe,{}),d.jsx(yoe,{}),d.jsx(Soe,{})]})}function doe(){const e=ie();return d.jsxs(Wn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(ge,{id:"export-all-as-group",children:[d.jsx(H,{...e["export-all-as-svg"]}),d.jsx(H,{...e["export-all-as-png"]}),d.jsx(H,{...e["export-all-as-json"]})]}),d.jsx(ge,{id:"export-all-as-bg",children:d.jsx(sb,{})})]})}function hoe(){const e=B(),n=G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return d.jsxs(Wn,{id:"edit",label:"menu.edit",disabled:!n,children:[d.jsx(goe,{}),d.jsx(mR,{}),d.jsx(yR,{}),d.jsx(poe,{}),d.jsx(foe,{}),d.jsx(ge,{id:"select-all",children:d.jsx(SR,{})})]})}function poe(){return d.jsxs(ge,{id:"misc",children:[d.jsx(lR,{}),d.jsx(cR,{}),d.jsx(iR,{}),d.jsx(sR,{}),d.jsx(uR,{}),d.jsx(dR,{}),d.jsx(xR,{}),d.jsx(vR,{}),d.jsx(aR,{})]})}function foe(){return d.jsxs(ge,{id:"lock",children:[d.jsx(hR,{}),d.jsx(Sre,{})]})}function goe(){const e=ie(),n=zO(),t=NO();return d.jsxs(ge,{id:"undo-redo",children:[d.jsx(H,{...e.undo,disabled:!n}),d.jsx(H,{...e.redo,disabled:!t})]})}function moe(){const e=ie();return d.jsx(Wn,{id:"view",label:"menu.view",children:d.jsxs(ge,{id:"view-actions",children:[d.jsx(H,{...e["zoom-in"]}),d.jsx(H,{...e["zoom-out"]}),d.jsx(pR,{}),d.jsx(fR,{}),d.jsx(gR,{})]})})}function yoe(){const e=ie();return d.jsxs(ge,{id:"extras",children:[d.jsx(H,{...e["insert-embed"]}),d.jsx(H,{...e["insert-media"]})]})}function Soe(){return d.jsx(ge,{id:"preferences",children:d.jsxs(Wn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ge,{id:"preferences-actions",children:[d.jsx(Mre,{}),d.jsx(Are,{}),d.jsx(jre,{}),d.jsx(Ore,{}),d.jsx(Dre,{}),d.jsx(Rre,{}),d.jsx(Lre,{}),d.jsx(Fre,{}),d.jsx(Nre,{}),d.jsx($re,{})]}),d.jsx(ge,{id:"color-scheme",children:d.jsx(coe,{})}),d.jsx(ge,{id:"language",children:d.jsx(bR,{})})]})})}const voe=P.memo(function({children:n}){const t=un(),[r,o]=ui("main menu"),s=Te(),i=n??d.jsx(uoe,{});return d.jsxs(nb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(rb,{asChild:!0,dir:"ltr",children:d.jsx(he,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:d.jsx(Pe,{icon:"menu",small:!0})})}),d.jsx($g,{container:t,children:d.jsx(ob,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(_r,{type:"menu",sourceId:"main-menu",children:i})})})]})}),xoe=P.memo(function(){const n=Hn(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=pi();return!t&&!s&&n<6?null:d.jsx("div",{className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&d.jsx(t,{}),s&&d.jsx(s,{}),n<6?null:d.jsxs(d.Fragment,{children:[r&&d.jsx(r,{}),o&&d.jsx(o,{})]})]})})}),_y={};function pc(e){if(_y[e])return _y[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 _y[e]=a,a}const gp=10,PR=4*6*gp+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 woe(e,n,t){const r=gp;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:gp*4}),gp*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:ke,endAngle:ke*1.5}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,new w(o.w,0)),radius:t,startAngle:ke*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:Ge}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,new w(0,o.h)),radius:t,startAngle:Ge,endAngle:ke}),PR}function boe(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
286
+ precision mediump float;
287
+
288
+ in vec2 shapeVertexPosition;
289
+
290
+ uniform vec4 canvasPageBounds;
291
+
292
+ // taken (with thanks) from
293
+ // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
294
+ void main() {
295
+ // convert the position from pixels to 0.0 to 1.0
296
+ vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
297
+
298
+ // convert from 0->1 to 0->2
299
+ vec2 zeroToTwo = zeroToOne * 2.0;
300
+
301
+ // convert from 0->2 to -1->+1 (clipspace)
302
+ vec2 clipSpace = zeroToTwo - 1.0;
303
+
304
+ gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
305
+ }`,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
306
+ precision mediump float;
307
+
308
+ uniform vec4 fillColor;
309
+ out vec4 outputColor;
310
+
311
+ void main() {
312
+ outputColor = fillColor;
313
+ }`,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:uh(n,1024),unselectedShapes:uh(n,4096),viewport:uh(n,PR),collaborators:uh(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 uh(e,n){const t=e.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(n)}}function nE(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 Poe=Object.defineProperty,Coe=Object.getOwnPropertyDescriptor,hi=(e,n,t,r)=>{for(var o=Coe(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&Poe(n,t,o),o};class hs{constructor(n,t,r){g(this,"disposables",[]);g(this,"close",()=>this.disposables.forEach(n=>n()));g(this,"gl");g(this,"shapeGeometryCache");g(this,"colors");g(this,"id",ot());g(this,"canvasBoundingClientRect",Mt("canvasBoundingClientRect",new Z));g(this,"originPagePoint",new w);g(this,"originPageCenter",new w);g(this,"isInViewport",!1);g(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)});g(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,u=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,f=c.maxY+i.height/2,y=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),x=Math.max(0,p+i.height-l),S=Math.max(0,-(f-i.height-l));a+=(y-m)/2,l+=(x-S)/2,a=_t(a,u,h),l=_t(l,p,f)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new w(a,l)});g(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 u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const p=h.length;r.has(u)?(nE(this.gl.selectedShapes,s,h),s+=p):(nE(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=boe(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(),oa("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=woe(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],hs.prototype,"getDpr");hi([V],hs.prototype,"getContentPageBounds");hi([V],hs.prototype,"getContentScreenBounds");hi([V],hs.prototype,"getCanvasSize");hi([V],hs.prototype,"getCanvasClientPosition");hi([V],hs.prototype,"getCanvasPageBounds");hi([V],hs.prototype,"getZoom");hi([V],hs.prototype,"getCanvasPageBoundsArray");function Ioe(){const e=B(),n=un(),t=P.useRef(null),r=P.useRef(!1),o=P.useRef();P.useEffect(()=>{try{const u=new hs(e,t.current,n);return o.current=u,o.current.close}catch(u){e.annotateError(u,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw u})}},[e,n]);const s=P.useCallback(u=>{if(!e.getCurrentPageShapeIds().size||!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=o.current.minimapScreenPointToPagePoint(u.clientX,u.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(u=>{if(!o.current)return;const h=u.currentTarget;if(Du(h,u),!e.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const p=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=e.getViewportPageBounds(),y=o.current.getContentPageBounds();if(new Z(y.x-f.width/2,y.y-f.height/2,y.width+f.width,y.height+f.height).containsPoint(p)&&!f.containsPoint(p)){o.current.isInViewport=f.containsPoint(p);const S=w.Sub(f.center,f.point),v=w.Add(p,S);o.current.originPagePoint.setTo(v),o.current.originPageCenter.setTo(p),e.centerOnPoint(p,{animation:{duration:e.options.animationMediumMs}})}else{const S=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=f.containsPoint(S),o.current.originPagePoint.setTo(S),o.current.originPageCenter.setTo(f.center)}function x(S){h&&Ru(h,S),r.current=!1,document.body.removeEventListener("pointerup",x)}document.body.addEventListener("pointerup",x)},[e]),a=P.useCallback(u=>{if(!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(o.current.isInViewport){const m=o.current.originPagePoint.clone().sub(o.current.originPageCenter);e.centerOnPoint(w.Sub(h,m));return}e.centerOnPoint(h)}const p=o.current.getMinimapPagePoint(u.clientX,u.clientY),f=e.pageToScreen(p),y={type:"pointer",target:"canvas",name:"pointer_move",...On(u),point:f,isPen:e.getInstanceState().isPenMode};e.dispatch(y)},[e]),l=P.useCallback(u=>{const h=q_(u);e.dispatch({type:"wheel",name:"wheel",delta:h,point:new w(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey})},[e]),c=Ku();return P.useEffect(()=>{e.timers.setTimeout(()=>{var u,h;(u=o.current)==null||u.updateColors(),(h=o.current)==null||h.render()})},[c,e]),d.jsx("div",{className:"tlui-minimap",children:d.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:s,onPointerMove:a,onPointerDown:i,onWheel:l})})}function Eoe(e,n){const[t,r]=we.useState(n);we.useLayoutEffect(()=>{const s=Ff(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=we.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return Nf(e,JSON.stringify(a)),a})},[e]);return[t,o]}const koe=P.memo(function(){const n=ie(),t=Te(),r=Hn(),[o,s]=Eoe("minimap",!0),i=P.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=pi();return r<yt.MOBILE?null:d.jsxs("div",{className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<yt.TABLET?d.jsx(a,{}):o?d.jsxs(d.Fragment,{children:[a&&d.jsx(a,{}),l&&d.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(he,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(mu(n["zoom-out"].label))} ${Yv(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:d.jsx(Pe,{icon:"minus"})}),a&&d.jsx(a,{}),d.jsx(he,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(mu(n["zoom-in"].label))} ${Yv(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:d.jsx(Pe,{icon:"plus"})}),l&&d.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=yt.TABLET&&!o&&d.jsx(l,{})]})}),_oe=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 d.jsx(k0,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:n,onValueChange:a,onFocus:i,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},qv=(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=No(i.index):!i&&a?o=U4(s[0].index):o=Gc(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},rE=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=Zo.createId();s.duplicatePage(r.id,p)},[s,r]),c=P.useCallback(()=>{qv(s,r.id,n,n-1)},[s,r,n]),u=P.useCallback(()=>{qv(s,r.id,n,n+1)},[s,r,n]),h=P.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return d.jsxs(Qi,{id:`page item submenu ${n}`,children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(Pe,{icon:"dots-vertical"})})}),d.jsx(ea,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(_r,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ge,{id:"modify",children:[o&&d.jsx(H,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),d.jsx(H,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:a.length>=s.options.maxPages}),n>0&&d.jsx(H,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),n<t-1&&d.jsx(H,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),t>1&&d.jsx(ge,{id:"delete",children:d.jsx(H,{id:"delete",onSelect:h,label:"page-menu.submenu.delete"})})]})})]})}),Toe=P.memo(function(){const n=B(),t=Te(),r=Hn(),o=P.useCallback(()=>x(!1),[]),[s,i]=ui("page-menu",o),a=36,l=P.useRef(null),c=G("pages",()=>n.getPages(),[n]),u=G("currentPage",()=>n.getCurrentPage(),[n]),h=G("currentPageId",()=>n.getCurrentPageId(),[n]),p=cs(),f=G("maxPageCountReached",()=>n.getPages().length>=n.options.maxPages,[n]),y=G("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[m,x]=P.useState(!1),S=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((_,M)=>[_.id,{y:M*a,offsetY:0,isSelected:!1}])));P.useLayoutEffect(()=>{E(Object.fromEntries(c.map((_,M)=>[_.id,{y:M*a,offsetY:0,isSelected:!1}])))},[a,c]),P.useEffect(()=>{s&&n.timers.requestAnimationFrame(()=>{const _=document.querySelector(`[data-testid="page-menu-item-${h}"]`);if(_){const M=l.current;if(!M)return;const L=_.offsetTop,j=M.scrollTop;L<j&&M.scrollTo({top:L});const R=L+a,F=M.scrollTop+M.offsetHeight;R>F&&M.scrollTo({top:R-M.offsetHeight})}})},[a,h,s,n]);const k=P.useCallback(_=>{const{clientY:M,currentTarget:L}=_,{dataset:{id:j,index:R}}=L;if(!j||!R)return;const F=v.current;Du(_.currentTarget,_),F.status="pointing",F.pointing={id:j,index:+R};const K=b[j].y;F.startY=M,F.startIndex=Math.max(0,Math.min(Math.round(K/a),c.length-1))},[a,c.length,b]),C=P.useCallback(_=>{const M=v.current;if(M.status==="pointing"){const{clientY:L}=_,j=L-M.startY;Math.abs(j)>5&&(M.status="dragging")}if(M.status==="dragging"){const{clientY:L}=_,j=L-M.startY,R=b[M.pointing.id],{startIndex:F,pointing:W}=M,K=R.y+j,z=Math.max(0,Math.min(Math.round(K/a),c.length-1)),U={...b};if(U[W.id]={y:R.y,offsetY:j,isSelected:!0},z!==M.dragIndex){M.dragIndex=z;for(let X=0;X<c.length;X++){const J=c[X];if(J.id===M.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]),I=P.useCallback(_=>{const M=v.current;if(M.status==="dragging"){const{id:L,index:j}=M.pointing;qv(n,L,j,M.dragIndex)}Ru(_.currentTarget,_),M.status="idle"},[n]),T=P.useCallback(_=>{const M=v.current;_.key==="Escape"&&(M.status==="dragging"&&E(Object.fromEntries(c.map((L,j)=>[L.id,{y:j*a,offsetY:0,isSelected:!1}]))),M.status="idle")},[a,c]),O=P.useCallback(()=>{p||n.batch(()=>{n.mark("creating page");const _=Zo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:_}),n.setCurrentPage(_),x(!0)})},[n,t,p]);return d.jsxs(B0,{id:"pages",onOpenChange:i,open:s,children:[d.jsx(U0,{"data-testid":"main.page-menu",children:d.jsxs(he,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:u.name}),d.jsx(Pe,{icon:"chevron-down",small:!0})]})}),d.jsx(H0,{side:"bottom",align:"start",sideOffset:6,children:d.jsxs("div",{className:"tlui-page-menu__wrapper",children:[d.jsxs("div",{className:"tlui-page-menu__header",children:[d.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!p&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(he,{type:"icon","data-testid":"page-menu.edit",title:t(m?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:d.jsx(Pe,{icon:m?"check":"edit"})}),d.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:d.jsx(Pe,{icon:"plus"})})]})]}),d.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((_,M)=>{const L=b[_.id]??{position:M*40,offsetY:0};return m?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:_.id===u.id?888:M,transform:`translate(0px, ${L.y+L.offsetY}px)`},children:[d.jsx(he,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:k,onPointerUp:I,onPointerMove:C,onKeyDown:T,"data-id":_.id,"data-index":M,children:d.jsx(Pe,{icon:"drag-handle-dots"})}),r<yt.TABLET_SM&&y?d.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const j=window.prompt("Rename page",_.name);j&&j!==_.name&&n.renamePage(_.id,j)},onDoubleClick:S,children:[d.jsx(Xv,{checked:_.id===u.id}),d.jsx(bt,{children:_.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:d.jsx(_oe,{id:_.id,name:_.name,isCurrentPage:_.id===u.id})}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":m,children:d.jsx(rE,{index:M,item:_,listSize:c.length})})]},_.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(_.id),onDoubleClick:S,title:t("page-menu.go-to-page"),children:[d.jsx(Xv,{checked:_.id===u.id}),d.jsx(bt,{children:_.name})]}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(rE,{index:M,item:_,listSize:c.length,onRename:()=>{if(n.environment.isIos){const j=window.prompt("Rename page",_.name);j&&j!==_.name&&n.renamePage(_.id,j)}else n.batch(()=>{x(!0),n.setCurrentPage(_.id)})}})})]},_.id)})})]})})]})});function Moe(){const e=ie(),n=B(),t=zO(),r=NO(),o=Pn(1),s=cs(),i=G("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]),a=ds(),l=o&&a;if(!(s&&!i))return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e.undo,disabled:!t}),d.jsx(H,{...e.redo,disabled:!r}),d.jsx(H,{...e.delete,disabled:!l}),d.jsx(H,{...e.duplicate,disabled:!l})]})}const Aoe=P.memo(function({children:n}){const t=n??d.jsx(Moe,{});return d.jsx(_r,{type:"small-icons",sourceId:"quick-actions",children:t})}),joe=Object.freeze([ir,Ni,zi,xo]);function CR(e=joe){const n=B();return G("getRelevantStyles",()=>{var s;const t=new xv(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 Pr={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(),u=Te(),h=P.useRef(!1),p=P.useRef(null),{handleButtonClick:f,handleButtonPointerDown:y,handleButtonPointerEnter:m,handleButtonPointerUp:x}=P.useMemo(()=>{const S=()=>{h.current=!1,window.removeEventListener("pointerup",S);const C=p.current;C&&["TEXTAREA","INPUT"].includes(C.nodeName)&&C.focus(),p.current=null};return{handleButtonClick:C=>{const{id:I}=C.currentTarget.dataset;i.type==="shared"&&i.value===I||(c.mark("point picker item"),a(s,I))},handleButtonPointerDown:C=>{const{id:I}=C.currentTarget.dataset;c.mark("point picker item"),a(s,I),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",S)},handleButtonPointerEnter:C=>{if(!h.current)return;const{id:I}=C.currentTarget.dataset;a(s,I)},handleButtonPointerUp:C=>{const{id:I}=C.currentTarget.dataset;i.type==="shared"&&i.value===I||a(s,I)}}},[i,c,a,s]);return d.jsx("div",{"data-testid":`style.${t}`,className:ce("tlui-buttons__grid"),children:r.map(S=>d.jsx(he,{type:"icon","data-id":S.value,"data-testid":`style.${t}.${S.value}`,"aria-label":S.value,"data-state":i.type==="shared"&&i.value===S.value?"hinted":void 0,title:o+" — "+u(`${t}-style.${S.value}`),className:ce("tlui-button-grid__button"),style:s===ir?{color:l[S.value].solid}:void 0,onPointerEnter:m,onPointerDown:y,onPointerUp:x,onClick:f,children:d.jsx(Pe,{icon:S.icon})},S.value))})});function IR(e,[n,t]){return Math.min(t,Math.max(n,e))}function Ooe(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 ER=["PageUp","PageDown"],kR=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],_R={"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",[Zv,Doe,Roe]=Pg(zl),[TR,nae]=ko(zl,[Roe]),[Loe,Fg]=TR(zl),MR=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:u,onValueChange:h=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...y}=e,m=P.useRef(new Set),x=P.useRef(0),v=i==="horizontal"?$oe:Foe,[b=[],E]=li({prop:u,defaultProp:c,onChange:_=>{var L;(L=[...m.current][x.current])==null||L.focus(),h(_)}}),k=P.useRef(b);function C(_){const M=Hoe(b,_);O(_,M)}function I(_){O(_,x.current)}function T(){const _=k.current[x.current];b[x.current]!==_&&p(b)}function O(_,M,{commit:L}={commit:!1}){const j=Voe(s),R=Yoe(Math.round((_-r)/s)*s+r,j),F=IR(R,[r,o]);E((W=[])=>{const K=Boe(W,F,M);if(Goe(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 d.jsx(Loe,{scope:e.__scopeSlider,name:t,disabled:a,min:r,max:o,valueIndexToChangeRef:x,thumbs:m.current,values:b,orientation:i,children:d.jsx(Zv.Provider,{scope:e.__scopeSlider,children:d.jsx(Zv.Slot,{scope:e.__scopeSlider,children:d.jsx(v,{"aria-disabled":a,"data-disabled":a?"":void 0,...y,ref:n,onPointerDown:re(y.onPointerDown,()=>{a||(k.current=b)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:C,onSlideMove:a?void 0:I,onSlideEnd:a?void 0:T,onHomeKeyDown:()=>!a&&O(r,0,{commit:!0}),onEndKeyDown:()=>!a&&O(o,b.length-1,{commit:!0}),onStepKeyDown:({event:_,direction:M})=>{if(!a){const R=ER.includes(_.key)||_.shiftKey&&kR.includes(_.key)?10:1,F=x.current,W=b[F],K=s*R*M;O(W+K,F,{commit:!0})}}})})})})});MR.displayName=zl;var[AR,jR]=TR(zl,{startEdge:"left",endEdge:"right",size:"width",direction:1}),$oe=P.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[h,p]=P.useState(null),f=Ye(n,b=>p(b)),y=P.useRef(),m=K0(o),x=m==="ltr",S=x&&!s||!x&&s;function v(b){const E=y.current||h.getBoundingClientRect(),k=[0,E.width],I=ib(k,S?[t,r]:[r,t]);return y.current=E,I(b-E.left)}return d.jsx(AR,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width",children:d.jsx(OR,{dir:m,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const E=v(b.clientX);i==null||i(E)},onSlideMove:b=>{const E=v(b.clientX);a==null||a(E)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:b=>{const k=_R[S?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:k?-1:1})}})})}),Foe=P.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=P.useRef(null),h=Ye(n,u),p=P.useRef(),f=!o;function y(m){const x=p.current||u.current.getBoundingClientRect(),S=[0,x.height],b=ib(S,f?[r,t]:[t,r]);return p.current=x,b(m-x.top)}return d.jsx(AR,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(OR,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const x=y(m.clientY);s==null||s(x)},onSlideMove:m=>{const x=y(m.clientY);i==null||i(x)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:m=>{const S=_R[f?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:S?-1:1})}})})}),OR=P.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=Fg(zl,t);return d.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()):ER.concat(kR).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:re(e.onPointerDown,h=>{const p=h.target;p.setPointerCapture(h.pointerId),h.preventDefault(),u.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))})})}),DR="SliderTrack",RR=P.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Fg(DR,t);return d.jsx(Ce.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:n})});RR.displayName=DR;var Qv="SliderRange",LR=P.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Fg(Qv,t),s=jR(Qv,t),i=P.useRef(null),a=Ye(n,i),l=o.values.length,c=o.values.map(p=>FR(p,o.min,o.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ce.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:h+"%"}})});LR.displayName=Qv;var Jv="SliderThumb",$R=P.forwardRef((e,n)=>{const t=Doe(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 d.jsx(Noe,{...e,ref:s,index:i})}),Noe=P.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,name:o,...s}=e,i=Fg(Jv,t),a=jR(Jv,t),[l,c]=P.useState(null),u=Ye(n,v=>c(v)),h=l?!!l.closest("form"):!0,p=dO(l),f=i.values[r],y=f===void 0?0:FR(f,i.min,i.max),m=Uoe(r,i.values.length),x=p==null?void 0:p[a.size],S=x?Koe(x,y,a.direction):0;return P.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${y}% + ${S}px)`},children:[d.jsx(Zv.ItemSlot,{scope:e.__scopeSlider,children:d.jsx(Ce.span,{role:"slider","aria-label":e["aria-label"]||m,"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:u,style:f===void 0?{display:"none"}:e.style,onFocus:re(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(zoe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),value:f},r)]})});$R.displayName=Jv;var zoe=e=>{const{value:n,...t}=e,r=P.useRef(null),o=Ooe(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]),d.jsx("input",{style:{display:"none"},...t,ref:r,defaultValue:n})};function Boe(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function FR(e,n,t){const s=100/(t-n)*(e-n);return IR(s,[0,100])}function Uoe(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function Hoe(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 Koe(e,n,t){const r=e/2,s=ib([0,50],[0,r]);return(r-s(n)*t)*t}function Woe(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function Goe(e,n){if(n>0){const t=Woe(e);return Math.min(...t)>=n}return!0}function ib(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 Voe(e){return(String(e).split(".")[1]||"").length}function Yoe(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}var Xoe=MR,qoe=RR,Zoe=LR,Qoe=$R;const Joe=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]),u=P.useCallback(()=>{a.mark("click slider")},[a]),h=P.useCallback(()=>{o&&i(o)},[o,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(Xoe,{"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:u,onValueChange:c,onPointerUp:h,title:t+" — "+l(s),children:[d.jsx(qoe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&d.jsx(Zoe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&d.jsx(Qoe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function ese({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const p=Te(),f=P.useMemo(()=>{var m;return((m=s.find(x=>c.type==="shared"&&c.value===x.value))==null?void 0:m.icon)??"mixed"},[s,c]),y=P.useMemo(()=>{var m;return((m=i.find(x=>u.type==="shared"&&u.value===x.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:p(e),className:"tlui-style-panel__double-select-picker-label",children:p(e)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(Qi,{id:`style panel ${n} A`,children:[d.jsx(Ji,{children:d.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:d.jsx(Pe,{icon:f,small:!0,invertIcon:!0})})}),d.jsx(ea,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map((m,x)=>d.jsx(wu,{"data-testid":`style.${n}.${m.value}`,children:d.jsx(he,{type:"icon",onClick:()=>h(a,m.value),title:`${p(r)} — ${p(`${n}-style.${m.value}`)}`,children:d.jsx(Pe,{icon:m.icon,invertIcon:!0})},m.value)},x))})})]}),d.jsxs(Qi,{id:`style panel ${t}`,children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon","data-testid":`style.${t}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${u.value}`)),children:d.jsx(Pe,{icon:y,small:!0})})}),d.jsx(ea,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(wu,{children:d.jsx(he,{type:"icon",title:`${p(o)} — ${p(`${t}-style.${m.value}`)}`,"data-testid":`style.${t}.${m.value}`,onClick:()=>h(l,m.value),children:d.jsx(Pe,{icon:m.icon})})},m.value))})})]})]})]})}const tse=P.memo(ese);function nse({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Te(),c=B(),u=P.useMemo(()=>{var f;return(f=o.find(y=>i.type==="shared"&&y.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 d.jsxs(Qi,{id:`style panel ${e}`,children:[d.jsx(Ji,{children:d.jsxs(he,{type:s,"data-testid":`style.${t}`,title:h,children:[d.jsx(bt,{children:p}),d.jsx(Pe,{icon:u??"mixed"})]})}),d.jsx(ea,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>d.jsx(wu,{children:d.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:d.jsx(Pe,{icon:f.icon})})},f.value))})})]})}const ab=P.memo(nse);function rse({styles:e}){const n=Ku();if(!e)return null;const t=e.get(zr),r=e.get(Dp),o=e.get(Op),s=e.get(Fp),i=e.get(vo),a=t===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,h=as({isDarkMode:n});return d.jsxs(d.Fragment,{children:[d.jsx(ose,{theme:h,styles:e}),!u&&d.jsx(sse,{theme:h,styles:e}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(ise,{styles:e}),d.jsx(lse,{styles:e}),d.jsx(ase,{styles:e})]})]})}function Qu(){const e=B(),n=Zr();return we.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 ose({styles:e,theme:n}){const t=Te(),r=B(),o=Qu(),s=e.get(ir),i=e.get(zi),a=e.get(Ni),l=e.get(xo),c=i!==void 0||a!==void 0||l!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:d.jsx(Mi,{title:t("style-panel.color"),uiType:"color",style:ir,items:Pr.color,value:s,onValueChange:o,theme:n}),d.jsx(cse,{})]}),c&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:d.jsx(Mi,{title:t("style-panel.fill"),uiType:"fill",style:zi,items:Pr.fill,value:i,onValueChange:o,theme:n}),a===void 0?null:d.jsx(Mi,{title:t("style-panel.dash"),uiType:"dash",style:Ni,items:Pr.dash,value:a,onValueChange:o,theme:n}),l===void 0?null:d.jsx(Mi,{title:t("style-panel.size"),uiType:"size",style:xo,items:Pr.size,value:l,onValueChange:(u,h)=>{o(u,h);const p=r.getSelectedShapeIds();p.length>0&&Ke(r,p)},theme:n})]})]})}function sse({theme:e,styles:n}){const t=Te(),r=Qu(),o=n.get(vo),s=n.get(wS),i=n.get(Lp),a=n.get($p);return o===void 0&&i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:d.jsx(Mi,{title:t("style-panel.font"),uiType:"font",style:vo,items:Pr.font,value:o,onValueChange:r,theme:e}),s===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Mi,{title:t("style-panel.align"),uiType:"align",style:wS,items:Pr.textAlign,value:s,onValueChange:r,theme:e}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(Pe,{icon:"vertical-align-middle"})})})]}),i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Mi,{title:t("style-panel.align"),uiType:"align",style:Lp,items:Pr.horizontalAlign,value:i,onValueChange:r,theme:e}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?d.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(Pe,{icon:"vertical-align-middle"})}):d.jsx(ab,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:$p,items:Pr.verticalAlign,value:a,onValueChange:r})})]})]})}function ise({styles:e}){const n=Qu(),t=e.get(zr);return t===void 0?null:d.jsx(ab,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:zr,items:Pr.geo,value:t,onValueChange:n})}function ase({styles:e}){const n=Qu(),t=e.get(Fp);return t===void 0?null:d.jsx(ab,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:Fp,items:Pr.spline,value:t,onValueChange:n})}function lse({styles:e}){const n=Qu(),t=e.get(Dp),r=e.get(Op);return!t||!r?null:d.jsx(tse,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Op,itemsA:Pr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Dp,itemsB:Pr.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const fc=[.1,.25,.5,.75,1];function cse(){const e=B(),n=G("opacity",()=>e.getSharedOpacity(),[e]),t=Zr(),r=Te(),o=we.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(_4(fc,i=>Math.abs(i-n.value)));return d.jsx(Joe,{"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 use=P.memo(function({isMobile:n,children:t}){const r=B(),o=CR(),s=P.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1})},[r,n]),i=t??d.jsx(rse,{styles:o});return d.jsx("div",{className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})});function dse(){const e=B(),n=Te(),t=CR(),r=t==null?void 0:t.get(ir),o=as({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?d.jsxs(B0,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(U0,{children:d.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:d.jsx(Pe,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),d.jsx(H0,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function hse(){return d.jsxs(d.Fragment,{children:[d.jsx(fse,{}),d.jsx(gse,{}),d.jsx(mse,{}),d.jsx(yse,{}),d.jsx(Sse,{}),d.jsx(vse,{}),d.jsx(xse,{}),d.jsx(wse,{}),d.jsx(bse,{}),d.jsx(Pse,{}),d.jsx(Ise,{}),d.jsx(Cse,{}),d.jsx(_se,{}),d.jsx(Ase,{}),d.jsx(Ese,{}),d.jsx(Mse,{}),d.jsx(Tse,{}),d.jsx(kse,{}),d.jsx(jse,{}),d.jsx(Ose,{}),d.jsx(Dse,{}),d.jsx(Rse,{}),d.jsx(Lse,{}),d.jsx($se,{}),d.jsx(Fse,{}),d.jsx(Nse,{}),d.jsx(Bse,{}),d.jsx(zse,{})]})}function pse(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(zr);return t?o==="geo"&&s===t:o===e.id},[n,e.id,t])}function He({tool:e}){const n=Tg(),t=pse(n[e]);return d.jsx(H,{...n[e],isSelected:t})}function fse(){return d.jsx(He,{tool:"select"})}function gse(){return d.jsx(He,{tool:"hand"})}function mse(){return d.jsx(He,{tool:"draw"})}function yse(){return d.jsx(He,{tool:"eraser"})}function Sse(){return d.jsx(He,{tool:"arrow"})}function vse(){return d.jsx(He,{tool:"text"})}function xse(){return d.jsx(He,{tool:"note"})}function wse(){const e=Tg();return d.jsx(H,{...e.asset})}function bse(){return d.jsx(He,{tool:"rectangle"})}function Pse(){return d.jsx(He,{tool:"ellipse"})}function Cse(){return d.jsx(He,{tool:"diamond"})}function Ise(){return d.jsx(He,{tool:"triangle"})}function Ese(){return d.jsx(He,{tool:"rhombus"})}function kse(){return d.jsx(He,{tool:"heart"})}function _se(){return d.jsx(He,{tool:"hexagon"})}function Tse(){return d.jsx(He,{tool:"cloud"})}function Mse(){return d.jsx(He,{tool:"star"})}function Ase(){return d.jsx(He,{tool:"oval"})}function jse(){return d.jsx(He,{tool:"x-box"})}function Ose(){return d.jsx(He,{tool:"check-box"})}function Dse(){return d.jsx(He,{tool:"arrow-left"})}function Rse(){return d.jsx(He,{tool:"arrow-up"})}function Lse(){return d.jsx(He,{tool:"arrow-down"})}function $se(){return d.jsx(He,{tool:"arrow-right"})}function Fse(){return d.jsx(He,{tool:"line"})}function Nse(){return d.jsx(He,{tool:"highlight"})}function zse(){return d.jsx(He,{tool:"frame"})}function Bse(){return d.jsx(He,{tool:"laser"})}const Ty=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function My(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 NR(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 zR(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 Use(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 bu={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":Ty?173:189,"=":Ty?61:187,";":Ty?59:186,"'":222,"[":219,"]":221,"\\":220},Co={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},ex={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++)bu["f".concat(e)]=111+e;let We=[],Hc=null,BR="all";const $o=new Map,Ju=e=>bu[e.toLowerCase()]||Co[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Hse=e=>Object.keys(bu).find(n=>bu[n]===e),Kse=e=>Object.keys(Co).find(n=>Co[n]===e);function UR(e){BR=e||"all"}function Pu(){return BR||"all"}function Wse(){return We.slice(0)}function Gse(){return We.map(e=>Hse(e)||Kse(e)||String.fromCharCode(e))}function Vse(){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=>Ju(a))})})}),e}function Yse(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 Xse(e){return typeof e=="string"&&(e=Ju(e)),We.indexOf(e)!==-1}function qse(e,n){let t,r;e||(e=Pu());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 lb(a)}):r++;Pu()===e&&UR(n||"all")}function Zse(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 Co)Co[r]===n&&(Rn[r]=!1)}}function HR(e){if(typeof e>"u")Object.keys(dt).forEach(o=>{Array.isArray(dt[o])&&dt[o].forEach(s=>dh(s)),delete dt[o]}),lb(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&dh(o)});else if(typeof e=="object")e.key&&dh(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=""),dh({key:e,scope:o,method:s,splitKey:"+"})}}const dh=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;zR(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Ju(c);if(!dt[u])return;t||(t=Pu());const h=l>1?NR(Co,a):[],p=[];dt[u]=dt[u].filter(f=>{const m=(r?f.method===r:!0)&&f.scope===t&&Use(f.mods,h);return m&&p.push(f.element),!m}),p.forEach(f=>lb(f))})};function oE(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 sE(e,n){const t=dt["*"];let r=e.keyCode||e.which||e.charCode;if(!Rn.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=ex[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 Co)Co[a]===r&&(Rn[a]=!0);if(!t)return}for(const a in Ft)Object.prototype.hasOwnProperty.call(Ft,a)&&(Ft[a]=e[ex[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=Pu();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)&&oE(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,u=l.key.split(c),h=[];for(let p=0;p<u.length;p++)h.push(Ju(u[p]));h.sort().join("")===We.sort().join("")&&oE(e,l,o,n)}}function Rn(e,n,t){We=[];const r=zR(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",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"&&(u=n.splitKey),n.single===!0&&(p=!0)),typeof n=="string"&&(s=n),p&&HR(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=NR(Co,e)),e=e[e.length-1],e=e==="*"?"*":Ju(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:u,element:i});if(typeof i<"u"&&window){if(!$o.has(i)){const f=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return sE(m,i)},y=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;sE(m,i),Zse(m)};$o.set(i,{keydownListener:f,keyupListenr:y,capture:h}),My(i,"keydown",f,h),My(i,"keyup",y,h)}if(!Hc){const f=()=>{We=[]};Hc={listener:f,capture:h},My(window,"focus",f,h)}}}function Qse(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 lb(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}=$o.get(e)||{};r&&o&&(gc(e,"keyup",o,s),gc(e,"keydown",r,s),$o.delete(e))}if((n.length<=0||$o.size<=0)&&(Object.keys($o).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=$o.get(o)||{};s&&i&&(gc(o,"keyup",i,a),gc(o,"keydown",s,a),$o.delete(o))}),$o.clear(),Object.keys(dt).forEach(o=>delete dt[o]),Hc)){const{listener:o,capture:s}=Hc;gc(window,"focus",o,s),Hc=null}}const Ay={getPressedKeyString:Gse,setScope:UR,getScope:Pu,deleteScope:qse,getPressedKeyCodes:Wse,getAllKeyCodes:Vse,isPressed:Xse,filter:Yse,trigger:Qse,unbind:HR,keyMap:bu,modifier:Co,modifierMap:ex};for(const e in Ay)Object.prototype.hasOwnProperty.call(Ay,e)&&(Rn[e]=Ay[e]);if(typeof window<"u"){const e=window.hotkeys;Rn.noConflict=n=>(n&&window.hotkeys===Rn&&(window.hotkeys=e),Rn),window.hotkeys=Rn}const iE=["copy","cut","paste","asset"];function Jse(){const e=B(),n=cs(),t=ie(),r=Tg(),o=G("is focused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!o)return;const s=new Array,i=(l,c)=>{Rn(l,{element:document.body},c),s.push(()=>{Rn.unbind(l,c)})},a=(l,c)=>{Rn(l,{element:document.body,keyup:!0,keydown:!1},c),s.push(()=>{Rn.unbind(l,c)})};for(const l of Object.values(t))l.kbd&&(n&&!l.readonlyOk||iE.includes(l.id)||i(aE(l.kbd),c=>{kc(e)||(Ee(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&e.getInstanceState().isReadonly||iE.includes(l.id)||i(aE(l.kbd),c=>{kc(e)||(Ee(c),l.onSelect("kbd"))});return i(",",l=>{if(kc(e)||e.inputs.keys.has("Comma"))return;Ee(l),e.focus(),e.inputs.keys.add("Comma");const{x:c,y:u,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:c,y:u,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(kc(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{s.forEach(l=>l())}},[t,r,n,e,o])}function aE(e){return eie(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 eie(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 kc(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const tie=P.createContext(!1);function nie({children:e}){const n=B(),t=xV(),r=Hn(),o=Te(),s=Math.min(8,5+r),[i,a]=P.useState(0),l=P.useRef(null),[c,u]=P.useState(null),h=P.useMemo(()=>{const f=c?`:not([data-value="${c}"])`:"";return`
314
+ #${t}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
315
+ display: none;
316
+ }
317
+ #${t}_more > *:nth-child(-n + ${s}) {
318
+ display: none;
319
+ }
320
+ `},[c,t,s]),p=Xw(()=>{if(!l.current)return;const f=Array.from(l.current.children);a(f.length),f.findIndex(x=>x.getAttribute("data-value")===c)<=s&&u(null);const m=Array.from(l.current.children).findIndex(x=>x.getAttribute("aria-checked")==="true");m!==-1&&m>=s&&u(f[m].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[y,m]of f)Rn(y,x=>{var b;if(kc(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))[m];v&&v.click()});return()=>{Rn.unbind("1,2,3,4,5,6,7,8,9,0")}},[n]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<yt.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${t}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(_r,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s+1&&d.jsx(tie.Provider,{value:!0,children:d.jsxs(Qi,{id:"toolbar overflow",modal:!1,children:[d.jsx(Ji,{children:d.jsx(he,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(Pe,{icon:"chevron-up"})})}),d.jsx(ea,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:d.jsx(_r,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const rie=["select","hand","draw","eraser","text","zoom","laser","highlight"];function oie({activeToolId:e}){const n=B(),t=Hn(),r=Te(),o=G("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||rie.includes(e)?null:d.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:d.jsx(Pe,{icon:o?"lock":"unlock",small:!0})})}const sie=P.memo(function({children:n}){const t=B(),r=Hn(),o=cs(),s=G("current tool id",()=>t.getCurrentToolId(),[t]),{ActionsMenu:i,QuickActions:a}=pi();return d.jsx("div",{className:"tlui-toolbar",children:d.jsxs("div",{className:"tlui-toolbar__inner",children:[d.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&d.jsxs("div",{className:"tlui-toolbar__extras",children:[r<yt.TABLET&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&d.jsx(a,{}),i&&d.jsx(i,{})]}),d.jsx(oie,{activeToolId:s})]}),d.jsx(nie,{children:n??d.jsx(hse,{})})]}),r<yt.TABLET_SM&&!o&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(dse,{})})]})})});function iie(){const e=ie();return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["zoom-in"],noClose:!0}),d.jsx(H,{...e["zoom-out"],noClose:!0}),d.jsx(pR,{}),d.jsx(fR,{}),d.jsx(gR,{})]})}const aie=P.memo(function({children:n}){const t=un(),[r,o]=ui("zoom menu"),s=n??d.jsx(iie,{});return d.jsxs(nb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(rb,{asChild:!0,dir:"ltr",children:d.jsx(lie,{})}),d.jsx($g,{container:t,children:d.jsx(ob,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(_r,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),lie=P.forwardRef(function(n,t){const r=B(),o=Hn(),s=G("zoom",()=>r.getZoomLevel(),[r]),i=Te(),a=P.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.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:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),KR=P.createContext(null);function cie({overrides:e={},children:n}){const t=Zx(e);return d.jsx(KR.Provider,{value:P.useMemo(()=>({ContextMenu:Bre,ActionsMenu:gre,HelpMenu:eoe,ZoomMenu:aie,MainMenu:voe,Minimap:Ioe,StylePanel:use,PageMenu:Toe,NavigationPanel:koe,Toolbar:sie,KeyboardShortcutsDialog:aoe,QuickActions:Aoe,HelperButtons:soe,DebugPanel:Yre,DebugMenu:Vre,MenuPanel:xoe,...t}),[t]),children:n})}function pi(){const e=P.useContext(KR);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function uie({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return d.jsx(lq,{assetUrls:QQ(t),children:d.jsx(dq,{overrides:rJ(e),children:d.jsx(fQ,{onEvent:r,children:d.jsx(HQ,{children:d.jsx(gQ,{children:d.jsx(eJ,{forceMobile:o,children:d.jsx(cie,{overrides:n,children:d.jsx(die,{overrides:e,children:s})})})})})})})})}function die({overrides:e,children:n}){const t=oJ(e);return d.jsx(HJ,{overrides:t.actions,children:d.jsx(JQ,{overrides:t.tools,children:n})})}function hie(){const e=B(),{addToast:n}=Qr();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 pie=we.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return d.jsx(uie,{...s,components:o,children:d.jsx(fie,{hideUi:r,renderDebugMenuItems:n,children:t})})}),fie=we.memo(function({children:n,hideUi:t,...r}){return d.jsxs(d.Fragment,{children:[n,t?null:d.jsx(gie,{...r})]})}),gie=we.memo(function(){const n=B(),t=Te(),r=Hn(),o=cs(),s=G("focus",()=>n.getInstanceState().isFocusMode,[n]),i=G("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:p,NavigationPanel:f,HelperButtons:y,DebugPanel:m}=pi();Jse(),AJ(),hie();const{"toggle-focus-mode":x}=ie();return d.jsxs("div",{className:ce("tlui-layout",{"tlui-layout__mobile":r<yt.TABLET_SM}),"data-breakpoint":r,children:[s?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(he,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>x.onSelect("menu"),children:d.jsx(Pe,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),y&&d.jsx(y,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=yt.TABLET_SM&&!o&&d.jsx(u,{})]})]}),d.jsxs("div",{className:"tlui-layout__bottom",children:[d.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&d.jsx(f,{}),h&&d.jsx(h,{}),p&&d.jsx(p,{})]}),i&&m&&d.jsx(m,{})]})]}),d.jsx(VQ,{}),d.jsx(SQ,{}),d.jsx(YQ,{}),d.jsx(vQ,{})]})});async function mie(e,n){const{url:t,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=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=`
321
+ @font-face {
322
+ font-family: ${p.family};
323
+ font-stretch: ${p.stretch};
324
+ font-weight: ${p.weight};
325
+ font-style: ${p.style};
326
+ src: url("${t}") format("${u}")
327
+ }`,p}const hh=(e,n)=>{const[t,r]=P.useState(2);return P.useEffect(()=>{let o=!1;return r(2),mie(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function yie(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 WR(e){const n=P.useMemo(()=>yie(e),[e]),t=[hh("tldraw_draw",n.draw),hh("tldraw_serif",n.serif),hh("tldraw_sans",n.sansSerif),hh("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Sie(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],...h}=e,p=Zx(a),f=P.useMemo(()=>({Scribble:HC,ShapeIndicators:UV,CollaboratorScribble:HC,SelectionForeground:NV,SelectionBackground:$V,Handles:jV,...p}),[p]),y=Ac(l),m=P.useMemo(()=>[...kA,...y],[y]),x=Ac(c),S=P.useMemo(()=>[...V2,...x],[x]),v=Ac(u),b=P.useMemo(()=>[...$q,...WY,...v],[v]),E="persistenceKey"in h?h.persistenceKey:void 0,k=Bj(h.assetUrls),C=P.useMemo(()=>({onResolveAsset:kY(E),...h.assetOptions}),[E,h.assetOptions]),{done:I,error:T}=WR(k);return T?d.jsx(B2,{children:"Could not load assets. Please refresh the page."}):I?d.jsx(pV,{initialState:"select",...h,components:f,shapeUtils:m,bindingUtils:S,tools:b,assetOptions:C,children:d.jsxs(pie,{...h,components:f,children:[d.jsx(vie,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,persistenceKey:E,onMount:i}),n]})}):d.jsx(Qw,{children:d.jsx(qx,{})})}function vie({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=Ax,acceptedVideoMimeTypes:r=Ek,onMount:o,persistenceKey:s}){const i=B(),a=Qr(),l=Te(),c=Xw(p=>{const f=[];return f.push(...wq(p)),CY(p,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:a,msg:l},s),f.push(o==null?void 0:o(p)),()=>{f.forEach(y=>y==null?void 0:y())}});P.useLayoutEffect(()=>{if(i)return c==null?void 0:c(i)},[i,c]);const{Canvas:u}=it(),{ContextMenu:h}=pi();return h?d.jsx(h,{}):u?d.jsx(u,{}):null}P.memo(function(n){const[t,r]=P.useState(null),[o,s]=P.useState(null),i=Ac(n.shapeUtils??[]),a=P.useMemo(()=>[...kA,...i],[i]),l=Ac(n.bindingUtils??[]),c=P.useMemo(()=>[...V2,...l],[l]),u=F2({snapshot:n.snapshot,shapeUtils:a}),h=Bj(),{done:p,error:f}=WR(h),{pageId:y,bounds:m,scale:x,background:S,padding:v,darkMode:b,preserveAspectRatio:E,format:k="svg"}=n;return P.useLayoutEffect(()=>{if(!o||!u||!p)return;let C=!1;const I=document.createElement("div");o.appendChild(I),o.classList.add("tl-container","tl-theme__light");const T=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>I});y&&T.setCurrentPage(y);const O=T.getCurrentPageShapeIds();async function _(){const M=await T.getSvgString([...O],{bounds:m,scale:x,background:S,padding:v,darkMode:b,preserveAspectRatio:E});if(M&&!C){if(k==="svg"){if(!C){const L=new Blob([M.svg],{type:"image/svg+xml"}),j=URL.createObjectURL(L);r(j)}}else if(k==="png"){const L=await Zj(T,M.svg,{type:k,quality:1,scale:2,width:M.width,height:M.height});if(L&&!C){const j=URL.createObjectURL(L);r(j)}}}T.dispose()}return _(),()=>{C=!0}},[k,o,u,a,c,y,m,x,S,v,b,E,p,f]),f?d.jsx(B2,{children:"Could not load assets."}):p?d.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&d.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):d.jsx(Qw,{children:d.jsx(qx,{})})});const xie=1,wie=ve({schemaVersion:ln(1),storeVersion:xh,recordVersions:Ap(pe,ve({version:xh,subTypeVersions:Ap(pe,xh).optional(),subTypeKey:pe.optional()}))}),bie=ve({schemaVersion:ln(2),sequences:Ap(pe,xh)}),Pie=ve({tldrawFileFormatVersion:R8,schema:L8("schemaVersion",{1:wie,2:bie}),records:zt(ve({id:pe,typeName:pe}).allowUnknownProperties())});function Cie(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function Iie({json:e,schema:n}){let t;try{t=Pie.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),Cie(t))return gn.err({type:"v1File",data:t})}catch{}return gn.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>xie)return gn.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=Eie(t.records),s=Object.fromEntries(o.map(i=>[i.id,i]));r=n.migrateStoreSnapshot({store:s,schema:t.schema})}catch(o){return gn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return gn.err({type:"migrationFailed",reason:r.reason});try{return gn.ok($2({initialData:r.value,schema:n}))}catch(o){return gn.err({type:"invalidRecords",cause:o})}}function Eie(e){const n=new Set;for(const t of e)t.typeName==="shape"&&"assetId"in t.props&&t.props.assetId&&n.add(t.props.assetId);return e.filter(t=>t.typeName!=="asset"||n.has(t.id))}function kie(){const[e,n]=P.useState();function t(r){window.editor=r,e===void 0?fetch("/tldr-data").then(async o=>{if(!o.ok){console.log(`No tldr data to load from local endpoint (${o.status})`);return}return o.text()}).then(o=>{if(o===void 0)return;const s=Iie({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),n(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.zoomToFit(),r.clearOpenMenus())}return d.jsx("div",{style:{inset:0,position:"fixed"},children:d.jsx(Sie,{assetUrls:b$(),onMount:t,store:e})})}Sv.createRoot(document.querySelector("#root")).render(d.jsx(we.StrictMode,{children:d.jsx(kie,{})}));