@kitschpatrol/tldraw-cli 4.6.1 → 4.6.3

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.
@@ -1,325 +0,0 @@
1
- var dD=Object.defineProperty;var hD=(e,n,t)=>n in e?dD(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var g=(e,n,t)=>(hD(e,typeof n!="symbol"?n+"":n,t),t);function fD(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 rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ys(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var BI={exports:{}},wp={},UI={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"),pD=Symbol.for("react.portal"),gD=Symbol.for("react.fragment"),mD=Symbol.for("react.strict_mode"),yD=Symbol.for("react.profiler"),SD=Symbol.for("react.provider"),vD=Symbol.for("react.context"),xD=Symbol.for("react.forward_ref"),wD=Symbol.for("react.suspense"),bD=Symbol.for("react.memo"),PD=Symbol.for("react.lazy"),rb=Symbol.iterator;function CD(e){return e===null||typeof e!="object"?null:(e=rb&&e[rb]||e["@@iterator"],typeof e=="function"?e:null)}var HI={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},KI=Object.assign,WI={};function Sc(e,n,t){this.props=e,this.context=n,this.refs=WI,this.updater=t||HI}Sc.prototype.isReactComponent={};Sc.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")};Sc.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function GI(){}GI.prototype=Sc.prototype;function qv(e,n,t){this.props=e,this.context=n,this.refs=WI,this.updater=t||HI}var Zv=qv.prototype=new GI;Zv.constructor=qv;KI(Zv,Sc.prototype);Zv.isPureReactComponent=!0;var ob=Array.isArray,VI=Object.prototype.hasOwnProperty,Qv={current:null},YI={key:!0,ref:!0,__self:!0,__source:!0};function XI(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)VI.call(n,r)&&!YI.hasOwnProperty(r)&&(o[r]=n[r]);var a=arguments.length-2;if(a===1)o.children=t;else if(1<a){for(var c=Array(a),l=0;l<a;l++)c[l]=arguments[l+2];o.children=c}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Cu,type:e,key:s,ref:i,props:o,_owner:Qv.current}}function ID(e,n){return{$$typeof:Cu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Jv(e){return typeof e=="object"&&e!==null&&e.$$typeof===Cu}function ED(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var sb=/\/+/g;function Rg(e,n){return typeof e=="object"&&e!==null&&e.key!=null?ED(""+e.key):n.toString(36)}function ah(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 pD:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+Rg(i,0):r,ob(o)?(t="",e!=null&&(t=e.replace(sb,"$&/")+"/"),ah(o,n,t,"",function(l){return l})):o!=null&&(Jv(o)&&(o=ID(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(sb,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",ob(e))for(var a=0;a<e.length;a++){s=e[a];var c=r+Rg(s,a);i+=ah(s,n,t,c,o)}else if(c=CD(e),typeof c=="function")for(e=c.call(e),a=0;!(s=e.next()).done;)s=s.value,c=r+Rg(s,a++),i+=ah(s,n,t,c,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 od(e,n,t){if(e==null)return e;var r=[],o=0;return ah(e,r,"","",function(s){return n.call(t,s,o++)}),r}function _D(e){if(e._status===-1){var n=e._result;n=n(),n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var mn={current:null},ch={transition:null},kD={ReactCurrentDispatcher:mn,ReactCurrentBatchConfig:ch,ReactCurrentOwner:Qv};function qI(){throw Error("act(...) is not supported in production builds of React.")}xe.Children={map:od,forEach:function(e,n,t){od(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return od(e,function(){n++}),n},toArray:function(e){return od(e,function(n){return n})||[]},only:function(e){if(!Jv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};xe.Component=Sc;xe.Fragment=gD;xe.Profiler=yD;xe.PureComponent=qv;xe.StrictMode=mD;xe.Suspense=wD;xe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=kD;xe.act=qI;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=KI({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=Qv.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(c in n)VI.call(n,c)&&!YI.hasOwnProperty(c)&&(r[c]=n[c]===void 0&&a!==void 0?a[c]:n[c])}var c=arguments.length-2;if(c===1)r.children=t;else if(1<c){a=Array(c);for(var l=0;l<c;l++)a[l]=arguments[l+2];r.children=a}return{$$typeof:Cu,type:e.type,key:o,ref:s,props:r,_owner:i}};xe.createContext=function(e){return e={$$typeof:vD,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:SD,_context:e},e.Consumer=e};xe.createElement=XI;xe.createFactory=function(e){var n=XI.bind(null,e);return n.type=e,n};xe.createRef=function(){return{current:null}};xe.forwardRef=function(e){return{$$typeof:xD,render:e}};xe.isValidElement=Jv;xe.lazy=function(e){return{$$typeof:PD,_payload:{_status:-1,_result:e},_init:_D}};xe.memo=function(e,n){return{$$typeof:bD,type:e,compare:n===void 0?null:n}};xe.startTransition=function(e){var n=ch.transition;ch.transition={};try{e()}finally{ch.transition=n}};xe.unstable_act=qI;xe.useCallback=function(e,n){return mn.current.useCallback(e,n)};xe.useContext=function(e){return mn.current.useContext(e)};xe.useDebugValue=function(){};xe.useDeferredValue=function(e){return mn.current.useDeferredValue(e)};xe.useEffect=function(e,n){return mn.current.useEffect(e,n)};xe.useId=function(){return mn.current.useId()};xe.useImperativeHandle=function(e,n,t){return mn.current.useImperativeHandle(e,n,t)};xe.useInsertionEffect=function(e,n){return mn.current.useInsertionEffect(e,n)};xe.useLayoutEffect=function(e,n){return mn.current.useLayoutEffect(e,n)};xe.useMemo=function(e,n){return mn.current.useMemo(e,n)};xe.useReducer=function(e,n,t){return mn.current.useReducer(e,n,t)};xe.useRef=function(e){return mn.current.useRef(e)};xe.useState=function(e){return mn.current.useState(e)};xe.useSyncExternalStore=function(e,n,t){return mn.current.useSyncExternalStore(e,n,t)};xe.useTransition=function(){return mn.current.useTransition()};xe.version="18.3.1";UI.exports=xe;var x=UI.exports;const Se=Ys(x),TD=fD({__proto__:null,default:Se},[x]);/**
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 $D=x,MD=Symbol.for("react.element"),AD=Symbol.for("react.fragment"),jD=Object.prototype.hasOwnProperty,OD=$D.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,DD={key:!0,ref:!0,__self:!0,__source:!0};function ZI(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)jD.call(n,r)&&!DD.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:MD,type:e,key:s,ref:i,props:o,_owner:OD.current}}wp.Fragment=AD;wp.jsx=ZI;wp.jsxs=ZI;BI.exports=wp;var h=BI.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 RD(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-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)}}}async function LD(e,n){const{url:t,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:c,variant:l,format:u}=n,d={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:c,variant:l},f=new FontFace(e,`url(${t})`,d);return await f.load(),document.fonts.add(f),f.$$_url=t,f.$$_fontface=`
18
- @font-face {
19
- font-family: ${f.family};
20
- font-stretch: ${f.stretch};
21
- font-weight: ${f.weight};
22
- font-style: ${f.style};
23
- src: url("${t}") format("${u}")
24
- }`,f}function QI(e){return e&&typeof e=="object"&&"parents"in e}function JI(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 df=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&QI(e))for(let t=0,r=e.parents.length;t<r;t++)df(e.parents[t],e)},e0=(e,n)=>{if(e.children.add(n)&&QI(e))for(let t=0,r=e.parents.length;t<r;t++)e0(e.parents[t],e)};function eE(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function Xs(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const Bo=Xs("empty_array",()=>Object.freeze([])),ib=8;class hf{constructor(){g(this,"arraySize",0);g(this,"array",Array(ib));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<ib?(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 Qn=Symbol.for("com.tldraw.state/RESET_VALUE");class tE{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===Qn){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 Qn;const[c,l]=a;if(s===0&&n>=l)return[];if(c<=n&&n<l){const u=s+1,d=new Array(u);for(let f=0;f<u;f++)d[f]=o[(i+f)%r][2];return d}}return Qn}}class FD{constructor(n,t){g(this,"offset",0);g(this,"maybeRemoved");this.below=n,this.child=t}}const nt=Xs("capture",()=>({stack:null}));function Lg(e){const n=nt.stack;nt.stack=null;try{return e()}finally{nt.stack=n}}function nE(e){nt.stack=new FD(nt.stack,e),e.parentSet.clear()}function rE(){const e=nt.stack;if(nt.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)||df(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)||df(t,e.child)}}function ff(e){if(nt.stack){if(nt.stack.child.parentSet.has(e))return;if(nt.stack.child.parentSet.add(e),nt.stack.child.isActivelyListening&&e0(e,nt.stack.child),nt.stack.offset<nt.stack.child.parents.length){const t=nt.stack.child.parents[nt.stack.offset];t!==e&&(nt.stack.maybeRemoved?nt.stack.maybeRemoved.push(t):nt.stack.maybeRemoved=[t])}nt.stack.child.parents[nt.stack.offset]=e,nt.stack.child.parentEpochs[nt.stack.offset]=e.lastChangedEpoch,nt.stack.offset++}}const Cs=-1;class ND{constructor(n,t,r){g(this,"_isActivelyListening",!1);g(this,"lastTraversedEpoch",Cs);g(this,"lastReactedEpoch",Cs);g(this,"_scheduleCount",0);g(this,"parentSet",new hf);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!==Cn()){if(this.parents.length&&!JI(this)){this.lastReactedEpoch=Cn();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++)e0(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)df(this.parents[n],this)}execute(){try{nE(this);const n=Cn(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=n,t}finally{rE()}}}const vc=Xs("EffectScheduler",()=>ND);function Wi(e,n,t){const r=new vc(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function zD(e,n,t){const r=new vc(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 BD{constructor(n){g(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){this.isRoot?oE(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=Xs("transactions",()=>({globalEpoch:Cs+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Cs+1}));function UD(){return ze.reactionEpoch}function Cn(){return ze.globalEpoch}function HD(){return ze.globalIsReacting}function t0(e,n){n.lastTraversedEpoch!==ze.globalEpoch&&(n.lastTraversedEpoch=ze.globalEpoch,n instanceof vc?e.add(n):n.children.visit(t=>t0(e,t)))}function oE(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=>t0(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 KD(e,n){if(ze.globalIsReacting){const t=ze.cleanupReactors??(ze.cleanupReactors=new Set);e.children.visit(r=>t0(t,r))}else ze.currentTransaction?ze.currentTransaction.initialAtomValues.has(e)||ze.currentTransaction.initialAtomValues.set(e,n):oE([e])}function WD(){ze.globalEpoch++}function GD(e){const n=new BD(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 Ts(e){return ze.currentTransaction?e():GD(e)}class VD{constructor(n,t,r){g(this,"isEqual");g(this,"computeDiff");g(this,"lastChangedEpoch",Cn());g(this,"children",new hf);g(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new tE(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(n){return this.current}get(){return ff(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??eE(this.current,n))return this.current;WD(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Cn(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,Cn()))??Qn),this.lastChangedEpoch=Cn();const r=this.current;return this.current=n,KD(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return ff(this),n>=this.lastChangedEpoch?Bo:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Qn}}const YD=Xs("Atom",()=>VD);function on(e,n,t){return new YD(e,n,t)}let ab=!1;function XD(){ab||(ab=!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.
25
-
26
- // Before
27
- @computed
28
- get foo() {
29
- return 'foo'
30
- }
31
-
32
- // After
33
- @computed
34
- getFoo() {
35
- return 'foo'
36
- }
37
- `))}const dl=Symbol.for("com.tldraw.state/UNINITIALIZED"),Pi=e=>e===dl,Gy=Xs("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function hl(e,n){return new Gy(e,n)}class qD{constructor(n,t,r){g(this,"lastChangedEpoch",Cs);g(this,"lastTraversedEpoch",Cs);g(this,"lastCheckedEpoch",Cs);g(this,"parentSet",new hf);g(this,"parents",[]);g(this,"parentEpochs",[]);g(this,"children",new hf);g(this,"historyBuffer");g(this,"state",dl);g(this,"error",null);g(this,"computeDiff");g(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new tE(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??eE}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(n){var o;const t=this.lastChangedEpoch===Cs,r=Cn();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&HD()&&this.lastTraversedEpoch<UD()||!JI(this)))if(this.lastCheckedEpoch=r,this.error){if(n)return this.state;throw this.error.thrownValue}else return this.state;try{nE(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof Gy?s.value:s,a=this.state===dl;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const c=s instanceof Gy?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Cn(),c??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,Cn()))??Qn)}this.lastChangedEpoch=Cn(),this.state=i}return this.error=null,this.lastCheckedEpoch=Cn(),this.state}catch(s){if(this.state!==dl&&(this.state=dl,this.lastChangedEpoch=Cn()),this.lastCheckedEpoch=Cn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!n)throw s;return this.state}finally{rE()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{ff(this)}}getDiffSince(n){var t;return this.__unsafe__getWithoutCapture(!0),ff(this),n>=this.lastChangedEpoch?Bo:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Qn}}const n0=Xs("Computed",()=>qD);function ZD(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 n0(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[JD]=!0,r}function cb(e={},n,t,r){return r.get?(XD(),QD(e,n,t,r)):ZD(e,n,t,r)}function QD(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 n0(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const JD="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>cb(e,n,t,r)}else return typeof arguments[0]=="string"?new n0(arguments[0],arguments[1],arguments[2]):cb(void 0,arguments[0],arguments[1],arguments[2])}const sE=1,eR=Xs("apiVersion",()=>sE);if(eR!==sE)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function bp(e,n){const t=Se.useRef(n);t.current=n;const[r,o,s]=Se.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),c=new vc(`useStateTracking(${e})`,()=>{var u;return(u=t.current)==null?void 0:u.call(t)},{scheduleEffect(){i==null||i()}});return[c,a,()=>c.scheduleCount]},[e]);return Se.useSyncExternalStore(o,s,s),Se.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const lb={apply(e,n,t){return bp(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},tR=Symbol.for("react.memo"),nR=Symbol.for("react.forward_ref");function ir(e){let n=null;const t=e.$$typeof;return t===tR&&(e=e.type,n=e.compare),t===nR?x.memo(x.forwardRef(new Proxy(e.render,lb))):x.memo(new Proxy(e,lb),n)}function rR(){const e=arguments[0],n=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return x.useMemo(()=>G(`useComputed(${e})`,n,t),r)}function $s(e,n,t=Bo){x.useEffect(()=>{const r=new vc(e,n);return r.attach(),r.execute(),()=>{r.detach()}},t)}function W(){const e=arguments,n=e.length===3?e[2]:[e[0]],t=e.length===3?e[0]:`useValue(${e[0].name})`,r=x.useRef(!0);r.current=!0;const o=x.useMemo(()=>e.length===1?e[0]:G(t,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),n);try{const{subscribe:s,getSnapshot:i}=x.useMemo(()=>({subscribe:a=>Wi(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return x.useSyncExternalStore(s,i,i)}finally{r.current=!1}}class lh{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)}}const fl={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},oR=fl.Good;class iE{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?fl.Good:t>30?fl.Mid:fl.Poor,o=r===fl.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${oR};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 r0(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 ye(e){return e.filter(n=>n!=null)}function Nt(e){return e[e.length-1]}function sR(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 iR(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 _i{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 aR(e,n){let t,r;return function(...o){return t||(t=!0,setTimeout(()=>t=!1,n),r=e(...o)),r}}function aE(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}function cR(){}const pn={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function sn(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const st=aE((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),Vn=aE((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function cE(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 ub=new WeakMap;function o0(e,n){if(typeof e!="object"||e===null)return;let t=ub.get(e);t||(t={tags:{},extras:{}},ub.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}class Ua{static async dataUrlToArrayBuffer(n){return fetch(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 Vy(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function lR(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+""}/*!
38
- * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
39
- * Copyright (c) Philip van Heemstra
40
- */function uR(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,c,l=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,d=new TextDecoder,f=s.length;if(typeof c>"u"&&(c=f),a>=f||c<=0||a>=c)return-1;s=s.subarray(a,c);let p=-1,y=0,m=0,w="";e:for(;y<s.length;){const S=y+l,v=s.subarray(y,S),P=d.decode(v,{stream:!0}),E=w+P;let C,I=-1;for(;(C=i.exec(E))!==null;){I=C.index-w.length,p=m+I;break e}y=S,m+=P.length;const _=I>-1?I+u:P.length-u;w=P.slice(_)}return p>=0&&(p+=a>=0?a:f+a),p}const o=r(n,"IDAT",12);return o>=12?r(n,"acTL",8,o)>=8:!1}const dR=e=>new Uint8Array(e)[3]===44;/*!
41
- * MIT License
42
- * Modified code originally from <https://github.com/qzb/is-animated>
43
- * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
44
- */function db(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function hR(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function fR(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!hR(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+=db(n,o+1)+1;break;case 33:o+=2,o+=db(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}let Yy=[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"&&(Yy=new Int32Array(Yy));/*!
45
- * MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
46
- * Copyright: 2014 Alex Gorbatchev
47
- * Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
48
- */const pR=(e,n)=>{let t=~~n^-1;for(let r=0;r<e.length;r++)t=Yy[(t^e[r])&255]^t>>>8;return t^-1},hb=4,fb=4;class to{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(!to.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=to.getChunkType(n,t);if(i==="IDAT"&&r[i]){t+=s+hb+fb;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+hb+fb}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 to.readChunks(n)[t]}static setPhysChunk(n,t=1,r){let o=46,s=0;const i=to.findChunk(n,"pHYs");i&&(o=i.start,s=i.size);const a=to.findChunk(n,"IDAT");a&&(o=a.start,s=0);const c=new ArrayBuffer(21),l=new DataView(c);l.setUint32(0,9),l.setUint8(4,112),l.setUint8(5,72),l.setUint8(6,89),l.setUint8(7,115);const u=2835.5;l.setInt32(8,u*t),l.setInt32(12,u*t),l.setInt8(16,1);const d=new Uint8Array(c.slice(4,17));l.setInt32(17,pR(d));const f=n.buffer.slice(0,o),p=n.buffer.slice(o+s);return new Blob([f,c,p],r)}}/*!
49
- * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
50
- * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
51
- */function gR(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function mR(e){const n=new Uint8Array(e);return!gR(n)||!n||n.length<21?!1:(n[20]>>1&1)===1}const yR=Object.freeze(["image/svg+xml"]),lE=Object.freeze(["image/jpeg","image/png","image/webp"]),uE=Object.freeze(["image/gif","image/apng","image/avif"]),s0=Object.freeze([...lE,...yR,...uE]),dE=Object.freeze(["video/mp4","video/webm","video/quicktime"]),SR=[...s0,...dE].join(",");class Xn{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=new Image;o.onload=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.src=n})}static async getVideoSize(n){return Xn.usingObjectURL(n,async t=>{const r=await Xn.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await Xn.usingObjectURL(n,Xn.loadImage);try{if(n.type==="image/png"){const r=new DataView(await n.arrayBuffer());if(to.isPng(r,0)){const o=to.findChunk(r,"pHYs");if(o){const s=to.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"?fR(await n.arrayBuffer()):n.type==="image/avif"?dR(await n.arrayBuffer()):n.type==="image/webp"?mR(await n.arrayBuffer()):n.type==="image/apng"?uR(await n.arrayBuffer()):!1}static isAnimatedImageType(n){return uE.includes(n||"")}static isStaticImageType(n){return lE.includes(n||"")}static isImageType(n){return s0.includes(n)}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function sd(e,n,t){return e+(n-e)*t}function Gr(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 pf(e,n,t,r=!1){const[o,s]=n,[i,a]=t,c=i+(e-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(c,a),i):Math.max(Math.min(c,i),a):c}function ao(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function kn(e,n){if(ao(e,n))return e[n]}function pb(e){return Object.keys(e)}function yt(e){return Object.values(e)}function An(e){return Object.entries(e)}function i0(e){return Object.fromEntries(e)}function Fg(e,n){const t={};let r=!1;for(const[o,s]of An(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function Iu(e,n){const t={};for(const[r,o]of An(e)){const s=n(r,o);t[r]=s}return t}function hE(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",fE="a0",pE="A00000000000000000000000000";function gE(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 mE(e){if(e.length!==gE(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function gb(e){if(e===void 0)throw Error("n is undefined")}function mb(e){mE(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 vR(e){mE(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 va(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)+va(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)+va(e.slice(1),void 0)}function pl(e){const n=gE(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function Xy(e){if(e===pE)throw new Error("invalid index: "+e);const n=pl(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function na(e,n){if(e!==void 0&&Xy(e),n!==void 0&&Xy(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return fE;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=pl(n),c=n.slice(a.length);if(a===pE)return a+va("",c);if(a<n)return a;const l=vR(a);return gb(l),l}if(n===void 0){const a=pl(e),c=e.slice(a.length),l=mb(a);return l===void 0?a+va(c,void 0):l}const t=pl(e),r=e.slice(t.length),o=pl(n),s=n.slice(o.length);if(t===o)return t+va(r,s);const i=mb(t);return gb(i),i<n?i:t+va(r,void 0)}function zs(e,n,t){if(t===0)return[];if(t===1)return[na(e,n)];if(n===void 0){let s=na(e,n);const i=[s];for(let a=0;a<t-1;a++)s=na(s,n),i.push(s);return i}if(e===void 0){let s=na(e,n);const i=[s];for(let a=0;a<t-1;a++)s=na(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=na(e,n);return[...zs(e,o,r),o,...zs(o,n,t-r-1)]}const xR=fE;function wR(e){Xy(e)}function nc(e,n,t){return zs(e,n,t)}function Ng(e,n){return zs(e,void 0,n)}function zl(e,n){return zs(e,n,1)[0]}function Lo(e){return zs(e,void 0,1)[0]}function bR(e){return zs(void 0,e,1)[0]}function Bl(e,n="a1"){return[n,...zs(n,void 0,e)]}function nn(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function PR(e,n){return e.id>n.id?1:-1}function a0(e){try{return localStorage.getItem(e)}catch{return null}}function c0(e,n){try{localStorage.setItem(e,n)}catch{}}function CR(){try{localStorage.clear()}catch{}}function yE(e){try{return sessionStorage.getItem(e)}catch{return null}}function l0(e,n){try{sessionStorage.setItem(e,n)}catch{}}function SE(e){try{sessionStorage.removeItem(e)}catch{}}function IR(){try{sessionStorage.clear()}catch{}}const ER=()=>typeof process<"u"&&!1,xa=[],_R=60,uh=Math.ceil(1e3/_R);let Uc,zg=0,qy=0;const kR=()=>{const e=xa.splice(0,xa.length);for(const n of e)n()};function vE(){if(Uc)return;const e=Date.now(),n=e-qy;if(zg+n<uh){Uc=requestAnimationFrame(()=>{Uc=void 0,vE()});return}Uc=requestAnimationFrame(()=>{Uc=void 0,qy=e,zg=Math.min(zg+n-uh,uh*10),kR()})}let yb=!1;function xE(e){return ER()?(e(),()=>{}):(xa.includes(e)||(xa.push(e),yb||(yb=!0,qy=Date.now()-uh-1),vE()),()=>{const n=xa.indexOf(e);n>-1&&xa.splice(n,1)})}function TR(e){return e!==null}function $R(){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 wE=$R(),xt=wE[0];wE[1];const MR=Object.getPrototypeOf(xt({}));let Eu=(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 Pp{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 An(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{...xt(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??Eu())}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 Pp(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 xo(e,n){return new Pp(e,{createDefaultProperties:()=>({}),validator:n.validator,scope:n.scope,ephemeralKeys:n.ephemeralKeys})}function Zy(){return{added:{},updated:{},removed:{}}}function Qy(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 bE(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function Cp(e){const n={added:{},removed:{},updated:{}};return gf(n,e),n}function gf(e,n){for(const t of n){for(const[r,o]of An(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 An(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 An(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}}var mf={exports:{}};mf.exports;(function(e,n){var t=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",c="[object Array]",l="[object AsyncFunction]",u="[object Boolean]",d="[object Date]",f="[object Error]",p="[object Function]",y="[object GeneratorFunction]",m="[object Map]",w="[object Number]",S="[object Null]",v="[object Object]",P="[object Promise]",E="[object Proxy]",C="[object RegExp]",I="[object Set]",_="[object String]",k="[object Symbol]",$="[object Undefined]",T="[object WeakMap]",O="[object ArrayBuffer]",N="[object DataView]",A="[object Float32Array]",j="[object Float64Array]",L="[object Int8Array]",X="[object Int16Array]",V="[object Int32Array]",H="[object Uint8Array]",U="[object Uint8ClampedArray]",K="[object Uint16Array]",Z="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,be=/^\[object .+?Constructor\]$/,Ae=/^(?:0|[1-9]\d*)$/,ae={};ae[A]=ae[j]=ae[L]=ae[X]=ae[V]=ae[H]=ae[U]=ae[K]=ae[Z]=!0,ae[a]=ae[c]=ae[O]=ae[u]=ae[N]=ae[d]=ae[f]=ae[p]=ae[m]=ae[w]=ae[v]=ae[C]=ae[I]=ae[_]=ae[T]=!1;var je=typeof rn=="object"&&rn&&rn.Object===Object&&rn,Le=typeof self=="object"&&self&&self.Object===Object&&self,it=je||Le||Function("return this")(),Ie=n&&!n.nodeType&&n,pt=Ie&&!0&&e&&!e.nodeType&&e,Ue=pt&&pt.exports===Ie,ur=Ue&&je.process,Bn=function(){try{return ur&&ur.binding&&ur.binding("util")}catch{}}(),Un=Bn&&Bn.isTypedArray;function qe(M,R){for(var Y=-1,te=M==null?0:M.length,Ze=0,ge=[];++Y<te;){var gt=M[Y];R(gt,Y,M)&&(ge[Ze++]=gt)}return ge}function Dt(M,R){for(var Y=-1,te=R.length,Ze=M.length;++Y<te;)M[Ze+Y]=R[Y];return M}function To(M,R){for(var Y=-1,te=M==null?0:M.length;++Y<te;)if(R(M[Y],Y,M))return!0;return!1}function Rc(M,R){for(var Y=-1,te=Array(M);++Y<M;)te[Y]=R(Y);return te}function Lc(M){return function(R){return M(R)}}function kg(M,R){return M.has(R)}function ea(M,R){return M==null?void 0:M[R]}function cO(M){var R=-1,Y=Array(M.size);return M.forEach(function(te,Ze){Y[++R]=[Ze,te]}),Y}function lO(M,R){return function(Y){return M(R(Y))}}function uO(M){var R=-1,Y=Array(M.size);return M.forEach(function(te){Y[++R]=te}),Y}var dO=Array.prototype,hO=Function.prototype,qu=Object.prototype,Tg=it["__core-js_shared__"],Nw=hO.toString,Xr=qu.hasOwnProperty,zw=function(){var M=/[^.]+$/.exec(Tg&&Tg.keys&&Tg.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),Bw=qu.toString,fO=RegExp("^"+Nw.call(Xr).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Uw=Ue?it.Buffer:void 0,Zu=it.Symbol,Hw=it.Uint8Array,Kw=qu.propertyIsEnumerable,pO=dO.splice,ai=Zu?Zu.toStringTag:void 0,Ww=Object.getOwnPropertySymbols,gO=Uw?Uw.isBuffer:void 0,mO=lO(Object.keys,Object),$g=ta(it,"DataView"),Fc=ta(it,"Map"),Mg=ta(it,"Promise"),Ag=ta(it,"Set"),jg=ta(it,"WeakMap"),Nc=ta(Object,"create"),yO=ui($g),SO=ui(Fc),vO=ui(Mg),xO=ui(Ag),wO=ui(jg),Gw=Zu?Zu.prototype:void 0,Og=Gw?Gw.valueOf:void 0;function ci(M){var R=-1,Y=M==null?0:M.length;for(this.clear();++R<Y;){var te=M[R];this.set(te[0],te[1])}}function bO(){this.__data__=Nc?Nc(null):{},this.size=0}function PO(M){var R=this.has(M)&&delete this.__data__[M];return this.size-=R?1:0,R}function CO(M){var R=this.__data__;if(Nc){var Y=R[M];return Y===r?void 0:Y}return Xr.call(R,M)?R[M]:void 0}function IO(M){var R=this.__data__;return Nc?R[M]!==void 0:Xr.call(R,M)}function EO(M,R){var Y=this.__data__;return this.size+=this.has(M)?0:1,Y[M]=Nc&&R===void 0?r:R,this}ci.prototype.clear=bO,ci.prototype.delete=PO,ci.prototype.get=CO,ci.prototype.has=IO,ci.prototype.set=EO;function $o(M){var R=-1,Y=M==null?0:M.length;for(this.clear();++R<Y;){var te=M[R];this.set(te[0],te[1])}}function _O(){this.__data__=[],this.size=0}function kO(M){var R=this.__data__,Y=Ju(R,M);if(Y<0)return!1;var te=R.length-1;return Y==te?R.pop():pO.call(R,Y,1),--this.size,!0}function TO(M){var R=this.__data__,Y=Ju(R,M);return Y<0?void 0:R[Y][1]}function $O(M){return Ju(this.__data__,M)>-1}function MO(M,R){var Y=this.__data__,te=Ju(Y,M);return te<0?(++this.size,Y.push([M,R])):Y[te][1]=R,this}$o.prototype.clear=_O,$o.prototype.delete=kO,$o.prototype.get=TO,$o.prototype.has=$O,$o.prototype.set=MO;function li(M){var R=-1,Y=M==null?0:M.length;for(this.clear();++R<Y;){var te=M[R];this.set(te[0],te[1])}}function AO(){this.size=0,this.__data__={hash:new ci,map:new(Fc||$o),string:new ci}}function jO(M){var R=ed(this,M).delete(M);return this.size-=R?1:0,R}function OO(M){return ed(this,M).get(M)}function DO(M){return ed(this,M).has(M)}function RO(M,R){var Y=ed(this,M),te=Y.size;return Y.set(M,R),this.size+=Y.size==te?0:1,this}li.prototype.clear=AO,li.prototype.delete=jO,li.prototype.get=OO,li.prototype.has=DO,li.prototype.set=RO;function Qu(M){var R=-1,Y=M==null?0:M.length;for(this.__data__=new li;++R<Y;)this.add(M[R])}function LO(M){return this.__data__.set(M,r),this}function FO(M){return this.__data__.has(M)}Qu.prototype.add=Qu.prototype.push=LO,Qu.prototype.has=FO;function ls(M){var R=this.__data__=new $o(M);this.size=R.size}function NO(){this.__data__=new $o,this.size=0}function zO(M){var R=this.__data__,Y=R.delete(M);return this.size=R.size,Y}function BO(M){return this.__data__.get(M)}function UO(M){return this.__data__.has(M)}function HO(M,R){var Y=this.__data__;if(Y instanceof $o){var te=Y.__data__;if(!Fc||te.length<t-1)return te.push([M,R]),this.size=++Y.size,this;Y=this.__data__=new li(te)}return Y.set(M,R),this.size=Y.size,this}ls.prototype.clear=NO,ls.prototype.delete=zO,ls.prototype.get=BO,ls.prototype.has=UO,ls.prototype.set=HO;function KO(M,R){var Y=td(M),te=!Y&&sD(M),Ze=!Y&&!te&&Dg(M),ge=!Y&&!te&&!Ze&&tb(M),gt=Y||te||Ze||ge,Tt=gt?Rc(M.length,String):[],Rt=Tt.length;for(var at in M)Xr.call(M,at)&&!(gt&&(at=="length"||Ze&&(at=="offset"||at=="parent")||ge&&(at=="buffer"||at=="byteLength"||at=="byteOffset")||eD(at,Rt)))&&Tt.push(at);return Tt}function Ju(M,R){for(var Y=M.length;Y--;)if(Zw(M[Y][0],R))return Y;return-1}function WO(M,R,Y){var te=R(M);return td(M)?te:Dt(te,Y(M))}function zc(M){return M==null?M===void 0?$:S:ai&&ai in Object(M)?QO(M):oD(M)}function Vw(M){return Bc(M)&&zc(M)==a}function Yw(M,R,Y,te,Ze){return M===R?!0:M==null||R==null||!Bc(M)&&!Bc(R)?M!==M&&R!==R:GO(M,R,Y,te,Yw,Ze)}function GO(M,R,Y,te,Ze,ge){var gt=td(M),Tt=td(R),Rt=gt?c:us(M),at=Tt?c:us(R);Rt=Rt==a?v:Rt,at=at==a?v:at;var Hn=Rt==v,$r=at==v,Yt=Rt==at;if(Yt&&Dg(M)){if(!Dg(R))return!1;gt=!0,Hn=!1}if(Yt&&!Hn)return ge||(ge=new ls),gt||tb(M)?Xw(M,R,Y,te,Ze,ge):qO(M,R,Rt,Y,te,Ze,ge);if(!(Y&o)){var dr=Hn&&Xr.call(M,"__wrapped__"),hr=$r&&Xr.call(R,"__wrapped__");if(dr||hr){var ds=dr?M.value():M,Mo=hr?R.value():R;return ge||(ge=new ls),Ze(ds,Mo,Y,te,ge)}}return Yt?(ge||(ge=new ls),ZO(M,R,Y,te,Ze,ge)):!1}function VO(M){if(!eb(M)||nD(M))return!1;var R=Qw(M)?fO:be;return R.test(ui(M))}function YO(M){return Bc(M)&&Jw(M.length)&&!!ae[zc(M)]}function XO(M){if(!rD(M))return mO(M);var R=[];for(var Y in Object(M))Xr.call(M,Y)&&Y!="constructor"&&R.push(Y);return R}function Xw(M,R,Y,te,Ze,ge){var gt=Y&o,Tt=M.length,Rt=R.length;if(Tt!=Rt&&!(gt&&Rt>Tt))return!1;var at=ge.get(M);if(at&&ge.get(R))return at==R;var Hn=-1,$r=!0,Yt=Y&s?new Qu:void 0;for(ge.set(M,R),ge.set(R,M);++Hn<Tt;){var dr=M[Hn],hr=R[Hn];if(te)var ds=gt?te(hr,dr,Hn,R,M,ge):te(dr,hr,Hn,M,R,ge);if(ds!==void 0){if(ds)continue;$r=!1;break}if(Yt){if(!To(R,function(Mo,di){if(!kg(Yt,di)&&(dr===Mo||Ze(dr,Mo,Y,te,ge)))return Yt.push(di)})){$r=!1;break}}else if(!(dr===hr||Ze(dr,hr,Y,te,ge))){$r=!1;break}}return ge.delete(M),ge.delete(R),$r}function qO(M,R,Y,te,Ze,ge,gt){switch(Y){case N:if(M.byteLength!=R.byteLength||M.byteOffset!=R.byteOffset)return!1;M=M.buffer,R=R.buffer;case O:return!(M.byteLength!=R.byteLength||!ge(new Hw(M),new Hw(R)));case u:case d:case w:return Zw(+M,+R);case f:return M.name==R.name&&M.message==R.message;case C:case _:return M==R+"";case m:var Tt=cO;case I:var Rt=te&o;if(Tt||(Tt=uO),M.size!=R.size&&!Rt)return!1;var at=gt.get(M);if(at)return at==R;te|=s,gt.set(M,R);var Hn=Xw(Tt(M),Tt(R),te,Ze,ge,gt);return gt.delete(M),Hn;case k:if(Og)return Og.call(M)==Og.call(R)}return!1}function ZO(M,R,Y,te,Ze,ge){var gt=Y&o,Tt=qw(M),Rt=Tt.length,at=qw(R),Hn=at.length;if(Rt!=Hn&&!gt)return!1;for(var $r=Rt;$r--;){var Yt=Tt[$r];if(!(gt?Yt in R:Xr.call(R,Yt)))return!1}var dr=ge.get(M);if(dr&&ge.get(R))return dr==R;var hr=!0;ge.set(M,R),ge.set(R,M);for(var ds=gt;++$r<Rt;){Yt=Tt[$r];var Mo=M[Yt],di=R[Yt];if(te)var nb=gt?te(di,Mo,Yt,R,M,ge):te(Mo,di,Yt,M,R,ge);if(!(nb===void 0?Mo===di||Ze(Mo,di,Y,te,ge):nb)){hr=!1;break}ds||(ds=Yt=="constructor")}if(hr&&!ds){var nd=M.constructor,rd=R.constructor;nd!=rd&&"constructor"in M&&"constructor"in R&&!(typeof nd=="function"&&nd instanceof nd&&typeof rd=="function"&&rd instanceof rd)&&(hr=!1)}return ge.delete(M),ge.delete(R),hr}function qw(M){return WO(M,cD,JO)}function ed(M,R){var Y=M.__data__;return tD(R)?Y[typeof R=="string"?"string":"hash"]:Y.map}function ta(M,R){var Y=ea(M,R);return VO(Y)?Y:void 0}function QO(M){var R=Xr.call(M,ai),Y=M[ai];try{M[ai]=void 0;var te=!0}catch{}var Ze=Bw.call(M);return te&&(R?M[ai]=Y:delete M[ai]),Ze}var JO=Ww?function(M){return M==null?[]:(M=Object(M),qe(Ww(M),function(R){return Kw.call(M,R)}))}:lD,us=zc;($g&&us(new $g(new ArrayBuffer(1)))!=N||Fc&&us(new Fc)!=m||Mg&&us(Mg.resolve())!=P||Ag&&us(new Ag)!=I||jg&&us(new jg)!=T)&&(us=function(M){var R=zc(M),Y=R==v?M.constructor:void 0,te=Y?ui(Y):"";if(te)switch(te){case yO:return N;case SO:return m;case vO:return P;case xO:return I;case wO:return T}return R});function eD(M,R){return R=R??i,!!R&&(typeof M=="number"||Ae.test(M))&&M>-1&&M%1==0&&M<R}function tD(M){var R=typeof M;return R=="string"||R=="number"||R=="symbol"||R=="boolean"?M!=="__proto__":M===null}function nD(M){return!!zw&&zw in M}function rD(M){var R=M&&M.constructor,Y=typeof R=="function"&&R.prototype||qu;return M===Y}function oD(M){return Bw.call(M)}function ui(M){if(M!=null){try{return Nw.call(M)}catch{}try{return M+""}catch{}}return""}function Zw(M,R){return M===R||M!==M&&R!==R}var sD=Vw(function(){return arguments}())?Vw:function(M){return Bc(M)&&Xr.call(M,"callee")&&!Kw.call(M,"callee")},td=Array.isArray;function iD(M){return M!=null&&Jw(M.length)&&!Qw(M)}var Dg=gO||uD;function aD(M,R){return Yw(M,R)}function Qw(M){if(!eb(M))return!1;var R=zc(M);return R==p||R==y||R==l||R==E}function Jw(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=i}function eb(M){var R=typeof M;return M!=null&&(R=="object"||R=="function")}function Bc(M){return M!=null&&typeof M=="object"}var tb=Un?Lc(Un):YO;function cD(M){return iD(M)?KO(M):XO(M)}function lD(){return[]}function uD(){return!1}e.exports=aD})(mf,mf.exports);var AR=mf.exports;const jR=Ys(AR);function OR(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 DR(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 Sb(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 vb(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 c of a)r[o].add(c)}else if("neq"in s){const i=e.index(n,o);for(const[a,c]of i.get())if(a!==s.neq)for(const l of c)r[o].add(l)}else if("gt"in s){const i=e.index(n,o);for(const[a,c]of i.get())if(a>s.gt)for(const l of c)r[o].add(l)}return OR(Object.values(r))}class RR{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=G("filterHistory:"+n,(r,o)=>{if(Pi(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Qn)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,c=0,l=0;for(const u of s){for(const d of yt(u.added))if(d.typeName===n)if(i.removed[d.id]){const f=i.removed[d.id];delete i.removed[d.id],c--,f!==d&&(i.updated[d.id]=[f,d],l++)}else i.added[d.id]=d,a++;for(const[d,f]of yt(u.updated))f.typeName===n&&(i.added[f.id]?i.added[f.id]=f:i.updated[f.id]?i.updated[f.id]=[i.updated[f.id][0],f]:(i.updated[f.id]=[d,f],l++));for(const d of yt(u.removed))d.typeName===n&&(i.added[d.id]?(delete i.added[d.id],a--):i.updated[d.id]?(i.removed[d.id]=i.updated[d.id][0],delete i.updated[d.id],l--,c++):(i.removed[d.id]=d,c++))}return a||c||l?hl(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 yt(this.atoms.get())){const a=i.get();if(a.typeName===n){const c=a[t];s.has(c)||s.set(c,new Set),s.get(c).add(a.id)}}return s};return G("index:"+n+":"+t,(s,i)=>{if(Pi(s))return o();const a=r.getDiffSince(i);if(a===Qn)return o();const c=new Map,l=(p,y)=>{let m=c.get(p);m||(m=new lh(s.get(p)??new Set)),m.add(y),c.set(p,m)},u=(p,y)=>{let m=c.get(p);m||(m=new lh(s.get(p)??new Set)),m.remove(y),c.set(p,m)};for(const p of a){for(const y of yt(p.added))if(y.typeName===n){const m=y[t];l(m,y.id)}for(const[y,m]of yt(p.updated))if(m.typeName===n){const w=y[t],S=m[t];w!==S&&(u(w,m.id),l(S,m.id))}for(const y of yt(p.removed))if(y.typeName===n){const m=y[t];u(m,y.id)}}let d,f;for(const[p,y]of c){const m=y.get();m&&(d||(d=new Map(s)),f||(f=new Map),m.value.size===0?d.delete(p):d.set(p,m.value),f.set(p,m.diff))}return d&&f?hl(d,f):s},{historyLength:100})}record(n,t=()=>({}),r="record:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,r);return G(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 G(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 c=t();return Object.keys(c).length===0?new Set(yt(this.atoms.get()).flatMap(l=>{const u=l.get();return u.typeName===n?u.id:[]})):vb(this,n,c)},i=c=>{const l=s(),u=DR(c,l);return u?hl(l,u):c},a=G("ids_query:"+r,t,{isEqual:jR});return G("query:"+r,(c,l)=>{const u=a.get();if(Pi(c))return s();if(l<a.lastChangedEpoch)return i(c);const d=o.getDiffSince(l);if(d===Qn)return i(c);const f=new lh(c);for(const y of d){for(const m of yt(y.added))m.typeName===n&&Sb(u,m)&&f.add(m.id);for(const[m,w]of yt(y.updated))w.typeName===n&&(Sb(u,w)?f.add(w.id):f.remove(w.id));for(const m of yt(y.removed))m.typeName===n&&f.remove(m.id)}const p=f.get();return p?hl(p.value,p.diff):c},{historyLength:50})}exec(n,t){const r=vb(this,n,t);if(r.size===0)return Bo;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class LR{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),()=>hi(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>hi(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>hi(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>hi(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>hi(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>hi(this._afterDeleteHandlers[n],t)}registerOperationCompleteHandler(n){return this._operationCompleteHandlers.push(n),()=>hi(this._operationCompleteHandlers,n)}}function hi(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}class u0{constructor(n){g(this,"id");g(this,"atoms",on("store_atoms",{}));g(this,"history",on("history",0,{historyLength:1e3}));g(this,"query",new RR(this.atoms,this.history));g(this,"listeners",new Set);g(this,"historyAccumulator",new NR);g(this,"historyReactor");g(this,"schema");g(this,"props");g(this,"scopedTypes");g(this,"sideEffects",new LR(this));g(this,"put",(n,t)=>{this.atomic(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,c=!1;const l=this.isMergingRemoteChanges?"remote":"user";for(let u=0,d=n.length;u<d;u++){a=n[u];const f=(i??s)[a.id];if(f){const p=f.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(p,a,l),this.schema.validateRecord(this,a,t??"updateRecord",p)===p)continue;f.set(a),c=!0;const m=f.__unsafe__getWithoutCapture();r[a.id]=[p,m],this.addDiffForAfterEvent(p,m)}else a=this.sideEffects.handleBeforeCreate(a,l),c=!0,a=this.schema.validateRecord(this,a,t??"createRecord",null),o[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...s}),i[a.id]=on("atom:"+a.id,a)}i&&this.atoms.set(i),c&&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 c=s[a].get();o[a]=c,this.addDiffForAfterEvent(c,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 An(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});g(this,"allRecords",()=>yt(this.atoms.get()).map(n=>n.get()));g(this,"clear",()=>{this.remove(pb(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,Ts(n)}finally{this.isMergingRemoteChanges=!1}});g(this,"createComputedCache",(n,t,r)=>{const o=new _i;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(n+":"+s,()=>t(a.get()))}).get()}}});g(this,"createSelectedComputedCache",(n,t,r)=>{const o=new _i;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=G(n+":"+s+":selector",()=>t(i.get()));return G(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??Eu(),this.schema=r,this.props=n.props,t&&this.atoms.set(i0(An(t).map(([s,i])=>[s,on("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=zD("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>xE(s)}),this.scopedTypes={document:new Set(yt(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(yt(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(yt(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:c}of this.listeners)if(!(c.source!=="all"&&c.source!==r))if(c.scope!=="all")if(c.scope==="document"){if(s??(s=this.filterChangesByScope(t,"document")),!s)continue;a({changes:s,source:r})}else if(c.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})}}}filterChangesByScope(n,t){const r={added:Fg(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:Fg(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:Fg(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))}getSnapshot(n="document"){return{store:this.serialize(n),schema:this.schema.serialize()}}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()}}loadSnapshot(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)}}extractingChanges(n){const t=[],r=this.historyAccumulator.addInterceptor(o=>t.push(o.changes));try{return Ts(n),Cp(t)}finally{r()}}applyDiff(n,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=yt(n.added);for(const[i,a]of yt(n.updated)){const c=this.schema.getType(a.typeName);if(r&&c.ephemeralKeySet.size){const l=this.get(a.id);if(!l){o.push(a);continue}let u=null;for(const[d,f]of Object.entries(a))c.ephemeralKeySet.has(d)||Object.is(f,kn(l,d))||(u||(u={...l}),u[d]=f);u&&o.push(u)}else o.push(a)}const s=pb(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 Ts(()=>{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 FR(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:Cp(o.map(s=>s.changes))}))}class NR{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=FR(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function zR(e,n,t){const r=new _i;return{get(o,s){return r.get(o,()=>(o instanceof u0?o:o.store).createComputedCache(e,c=>n(o,c),t)).get(s)}}}function BR(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 Ha({sequence:e,sequenceId:n,retroactive:t=!0}){const r={sequenceId:n,retroactive:t,sequence:BR(e)};return PE(r),r}function Fn(e,n){return Object.fromEntries(An(n).map(([t,r])=>[t,`${e}/${r}`]))}function ar(e){const n=e.sequenceId;return Ha({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 UR(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}=yf(s.id),c=n.get(`${a}/${i-1}`);if(c&&o(c),s.dependsOn)for(const l of s.dependsOn){const u=n.get(l);u&&o(u)}n.delete(s.id),r.push(s)}for(const s of n.values())o(s);return r}function yf(e){const[n,t]=e.split("/");return{sequenceId:n,version:parseInt(t)}}function xb(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 PE(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;xb(e.sequence[0].id,e.sequenceId);let n=yf(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;xb(r,e.sequenceId);const o=yf(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 ms=(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))(ms||{});function HR(e){if(e.schemaVersion>2||e.schemaVersion<1)return pn.err("Bad schema version");if(e.schemaVersion===2)return pn.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 pn.ok(n)}class d0{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}`),PE(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=UR(r);for(const s of this.sortedMigrations)if((o=s.dependsOn)!=null&&o.length)for(const i of s.dependsOn){const a=r.find(c=>c.id===i);st(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(n,t){return new d0(n,t??{})}validateRecord(n,t,r,o){try{const s=kn(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=HR(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 pn.ok([]);const s=new Set;for(const i of o){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)s.add(u.id);continue}const c=`${i}/${a}`,l=this.migrations[i].sequence.findIndex(u=>u.id===c);if(l===-1)return pn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(l+1))s.add(u.id)}return pn.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:ms.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"?ms.TargetVersionTooOld:ms.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:ms.TargetVersionTooOld};s=s.slice().reverse()}n=xt(n);try{for(const i of s){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(n):!0))continue;const c=i[r](n);c&&(n=xt(c))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:ms.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:ms.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:t};t=xt(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 l=s.up(a);l&&(t[i]=xt(l))}else if(s.scope==="store"){const i=s.up(t);i&&(t=xt(i))}else sn(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:ms.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?yf(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=kn(this.types,n);return st(t,"record type does not exists"),t}}function KR(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 Ce extends Error{constructor(t,r=[]){const o=KR(r),s=t.split(`
52
- `).map((i,a)=>a===0?i:` ${i}`).join(`
53
- `);super(r?`At ${o}: ${s}`:s);g(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function jn(e,n){try{return n()}catch(t){throw t instanceof Ce?new Ce(t.rawMessage,[e,...t.path]):new Ce(t.toString(),[e])}}function Bs(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:sn(n)}}class yn{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 qR(this)}optional(){return IE(this)}refine(n){return new yn(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=>(jn(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class WR extends yn{constructor(n){super(t=>{const r=wb.validate(t);for(let o=0;o<r.length;o++)jn(o,()=>n.validate(r[o]));return r},(t,r)=>{if(!n.validateUsingKnownGoodVersion)return this.validate(r);const o=wb.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,jn(i,()=>n.validate(a));continue}if(Object.is(t[i],a))continue;const c=jn(i,()=>n.validateUsingKnownGoodVersion(t[i],a));Object.is(c,t[i])||(s=!0)}return s?r:t}),this.itemValidator=n}nonEmpty(){return this.check(n=>{if(n.length===0)throw new Ce("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new Ce("Expected an array with length greater than 1")})}}class Sf extends yn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Bs(r)}`);for(const[o,s]of Object.entries(n))jn(o,()=>{s.validate(kn(r,o))});if(!t){for(const o of Object.keys(r))if(!ao(n,o))throw new Ce("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Bs(o)}`);let s=!1;for(const[i,a]of Object.entries(n)){const c=kn(r,i),l=kn(o,i);if(Object.is(c,l))continue;const u=jn(i,()=>{const d=a;return d.validateUsingKnownGoodVersion?d.validateUsingKnownGoodVersion(c,l):d.validate(l)});Object.is(u,c)||(s=!0)}if(!t){for(const i of Object.keys(o))if(!ao(n,i))throw new Ce("Unexpected property",[i])}for(const i of Object.keys(r))if(!ao(o,i)){s=!0;break}return s?o:r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new Sf(this.config,!0)}extend(n){return new Sf({...this.config,...n})}}class Ip extends yn{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):jn(`(${n} = ${a})`,()=>i.validate(s))},(s,i)=>{this.expectObject(i),this.expectObject(s);const{matchingSchema:a,variant:c}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,c):kn(s,n)!==kn(i,n)?jn(`(${n} = ${c})`,()=>a.validate(i)):jn(`(${n} = ${c})`,()=>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 Ce(`Expected an object, got ${Bs(n)}`,[])}getMatchingSchemaAndVariant(n){const t=kn(n,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new Ce(`Expected a string for key "${this.key}", got ${Bs(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new Ce(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:ao(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(n){return new Ip(this.key,this.config,n,this.useNumberKeys)}}class GR extends yn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Bs(r)}`);for(const[o,s]of Object.entries(r))jn(o,()=>{n.validate(o),t.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Bs(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!ao(r,i)){s=!0,jn(i,()=>{n.validate(i),t.validate(a)});continue}const c=kn(r,i),l=a;if(Object.is(c,l))continue;const u=jn(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(c,l):t.validate(l));Object.is(u,c)||(s=!0)}for(const i of Object.keys(r))if(!ao(o,i)){s=!0;break}return s?o:r}),this.keyValidator=n,this.valueValidator=t}}function h0(e){return new yn(n=>{if(typeof n!==e)throw new Ce(`Expected ${e}, got ${Bs(n)}`);return n})}const VR=new yn(e=>e),pe=h0("string"),fe=h0("number").check(e=>{if(Number.isNaN(e))throw new Ce("Expected a number, got NaN");if(!Number.isFinite(e))throw new Ce(`Expected a finite number, got ${e}`)}),vf=fe.check(e=>{if(e<0)throw new Ce(`Expected a positive number, got ${e}`)}),Ln=fe.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive number, got ${e}`)}),CE=fe.check(e=>{if(!Number.isInteger(e))throw new Ce(`Expected an integer, got ${e}`)}),dh=CE.check(e=>{if(e<0)throw new Ce(`Expected a positive integer, got ${e}`)}),YR=CE.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive integer, got ${e}`)}),we=h0("boolean");function cn(e){return new yn(n=>{if(n!==e)throw new Ce(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const wb=new yn(e=>{if(!Array.isArray(e))throw new Ce(`Expected an array, got ${Bs(e)}`);return e});function zt(e){return new WR(e)}function ve(e){return new Sf(e)}function Jy(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===MR)}function eS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(eS):Jy(e)?Object.values(e).every(eS):!1}const Bt=new yn(e=>{if(eS(e))return e;throw new Ce(`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(Jy(e)&&Jy(n)){let t=!1;for(const r of Object.keys(n)){if(!ao(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(!ao(n,r)){t=!0;break}return t?n:e}else return Bt.validate(n)});function xf(e,n){return new GR(e,n)}function f0(e,n){return new Ip(e,n,(t,r)=>{throw new Ce(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function XR(e,n){return new Ip(e,n,(t,r)=>{throw new Ce(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function wo(e,n){return new yn(t=>jn(e,()=>n.validate(t)),(t,r)=>jn(e,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(t,r):n.validate(r)))}function Ep(e){return new yn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Ce(`Expected ${t}, got ${n}`)}return n})}function IE(e){return new yn(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 qR(e){return new yn(n=>n===null?null:e.validate(n),(n,t)=>t===null?null:e.validateUsingKnownGoodVersion&&n!==null?e.validateUsingKnownGoodVersion(n,t):e.validate(t))}function p0(...e){return Ep(new Set(e))}function EE(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Ce(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Ce(`Expected a valid url, got ${JSON.stringify(e)}`)}}const ZR=new Set(["http:","https:","mailto:"]),rr=pe.check(e=>{if(e==="")return;const n=EE(e);if(!ZR.has(n.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),QR=new Set(["http:","https:","data:"]),xc=pe.check(e=>{if(e==="")return;const n=EE(e);if(!QR.has(n.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),g0=pe.refine(e=>{try{return wR(e),e}catch{throw new Ce(`Expected an index key, got ${JSON.stringify(e)}`)}});function Jn(e){return pe.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const _p=Jn("asset");function m0(e,n){return ve({id:_p,typeName:cn("asset"),type:cn(e),props:n,meta:Bt})}const ki=ve({x:fe,y:fe,z:fe.optional()}),Pl=ve({x:fe,y:fe,w:fe,h:fe}),_E=fe.check(e=>{if(e<0||e>1)throw new Ce("Opacity must be between 0 and 1")}),JR=pe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),gr=Jn("shape");function e3(e,n,t){return ve({id:gr,typeName:cn("shape"),x:fe,y:fe,rotation:fe,index:g0,parentId:JR,type:cn(e),isLocked:we,opacity:_E,props:n?ve(n):Bt,meta:t?ve(t):Bt})}const t3=Jn("binding");function n3(e,n,t){return ve({id:t3,typeName:cn("binding"),type:cn(e),fromId:gr,toId:gr,props:n?ve(n):Bt,meta:t?ve(t):Bt})}Fn("com.tldraw.binding",{});ar({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Ci(e){return`binding:${Eu()}`}function r3(e){return xo("binding",{scope:"document",validator:wo("binding",f0("type",Iu(e,(n,{props:t,meta:r})=>n3(n,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class Vt{constructor(n,t,r){this.id=n,this.defaultValue=t,this.type=r}static define(n,t){const{defaultValue:r,type:o=VR}=t;return new Vt(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new o3(n,r,o)}validate(n){return this.type.validate(n)}validateUsingKnownGoodVersion(n,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(n,t):this.validate(t)}}class o3 extends Vt{constructor(n,t,r){super(n,t,p0(...r)),this.values=r}}const id=Fn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),s3=ar({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:id.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:id.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:id.AddMeta,up:e=>{e.meta={}}},{id:id.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function wa(e){return e?e.typeName==="shape":!1}function mr(e){return e?e.startsWith("shape:"):!1}function Be(e){return`shape:${e??Eu()}`}function kE(e){const n=new Map;for(const[t,r]of Object.entries(e))if(r instanceof Vt){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 bo(e,n){return Iu(n,(t,r)=>`com.tldraw.shape.${e}/${r}`)}function i3(e){return xo("shape",{scope:"document",validator:wo("shape",f0("type",Iu(e,(n,{props:t,meta:r})=>e3(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}const vt="retired";function bb(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} ${Pp} migrations. Expected '${s}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o?t.push(Ha({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?TE(e,r,i):i)})):t.push(Ha({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 c=o.migrators[i].up(a);if(c)return c},down:a=>{const c=o.migrators[i].down(a);if(c)return c}}))})):t.push(Ha({sequenceId:s,retroactive:!1,sequence:[]}))}return t}function TE(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 $E=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],wf={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function ts(e){return e.isDarkMode?wf.darkMode:wf.lightMode}const or=Vt.defineEnum("tldraw:color",{defaultValue:"black",values:$E}),ME=Vt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:$E}),Ti=Vt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),rc=Vt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern"]}),po=Vt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),AE={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},go=Vt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),jE=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],bf=Vt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:jE}),Pf=Vt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:jE}),OE={labelColor:ME,color:or,fill:rc,dash:Ti,size:go,arrowheadStart:bf,arrowheadEnd:Pf,font:po,start:ki,end:ki,bend:fe,text:pe,labelPosition:fe},gl=bo("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4});function Bg(e){return TE("shape","arrow",e)}const DE=Ha({sequenceId:"com.tldraw.shape.arrow",sequence:[Bg({id:gl.AddLabelColor,up:e=>{e.labelColor="black"},down:vt}),Bg({id:gl.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)}}),Bg({id:gl.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:gl.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=Ci(),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=Ci(),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}}}]}),RE={terminal:p0("start","end"),normalizedAnchor:ki,isExact:we,isPrecise:we},LE={sequence:[{dependsOn:[gl.ExtractBindings]}]},a3=wo("camera",ve({typeName:cn("camera"),id:Jn("camera"),x:fe,y:fe,z:fe,meta:Bt})),c3=Fn("com.tldraw.camera",{AddMeta:1}),l3=ar({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:c3.AddMeta,up:e=>{e.meta={}}}]}),Fr=xo("camera",{validator:a3,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),u3=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"]),FE=Ep(u3),d3=ve({type:FE,rotation:fe}),h3=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),f3=Ep(h3),p3=new Set(["starting","paused","active","stopping"]),NE=ve({id:pe,points:zt(ki),size:vf,color:f3,opacity:fe,state:Ep(p3),delay:fe,shrink:fe,taper:we}),Ul=Jn("page"),g3=wo("page",ve({typeName:cn("page"),id:Ul,name:pe,index:g0,meta:Bt})),m3=Fn("com.tldraw.page",{AddMeta:1}),y3=ar({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:m3.AddMeta,up:e=>{e.meta={}}}]}),Go=xo("page",{validator:g3,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Pn(e){return Go.isId(e)}Jn("instance");function S3(e){const n={};for(const[r,o]of e)n[r]=IE(o);const t=wo("instance",ve({typeName:cn("instance"),id:Jn("instance"),currentPageId:Ul,followingUserId:pe.nullable(),brush:Pl.nullable(),opacityForNextShape:_E,stylesForNextShape:ve(n),cursor:d3,scribbles:zt(NE),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:Pl,insets:zt(we),zoomBrush:Pl.nullable(),isPenMode:we,isGridMode:we,chatMessage:pe,isChatting:we,highlightedUserIds:zt(pe),isFocused:we,devicePixelRatio:fe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:zt(pe),isChangingStyle:we,isReadonly:we,meta:Bt,duplicateProps:ve({shapeIds:zt(Jn("shape")),offset:ve({x:fe,y:fe})}).nullable()}));return xo("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=Fn("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}),v3=ar({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})}]}),en="instance:instance",x3=wo("instance_page_state",ve({typeName:cn("instance_page_state"),id:Jn("instance_page_state"),pageId:Ul,selectedShapeIds:zt(gr),hintingShapeIds:zt(gr),erasingShapeIds:zt(gr),hoveredShapeId:gr.nullable(),editingShapeId:gr.nullable(),croppingShapeId:gr.nullable(),focusedGroupId:gr.nullable(),meta:Bt})),Hc=Fn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),w3=ar({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Hc.AddCroppingId,up(e){e.croppingShapeId=null}},{id:Hc.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:Hc.AddMeta,up:e=>{e.meta={}}},{id:Hc.RenameProperties,up:e=>{},down:e=>{}},{id:Hc.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}}]}),xr=xo("instance_page_state",{validator:x3,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:{}})),b3=wo("pointer",ve({typeName:cn("pointer"),id:Jn("pointer"),x:fe,y:fe,lastActivityTimestamp:fe,meta:Bt})),P3=Fn("com.tldraw.pointer",{AddMeta:1}),C3=ar({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:P3.AddMeta,up:e=>{e.meta={}}}]}),y0=xo("pointer",{validator:b3,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Cf=y0.createId("pointer"),I3=wo("instance_presence",ve({typeName:cn("instance_presence"),id:Jn("instance_presence"),userId:pe,userName:pe,lastActivityTimestamp:fe,followingUserId:pe.nullable(),cursor:ve({x:fe,y:fe,type:FE,rotation:fe}),color:pe,camera:ve({x:fe,y:fe,z:fe}),screenBounds:Pl,selectedShapeIds:zt(Jn("shape")),currentPageId:Jn("page"),brush:Pl.nullable(),scribbles:zt(NE),chatMessage:pe,meta:Bt})),Kc=Fn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),E3=ar({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Kc.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:Kc.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:Kc.AddChatMessage,up:e=>{e.chatMessage=""}},{id:Kc.AddMeta,up:e=>{e.meta={}}},{id:Kc.RenameSelectedShapeIds,up:e=>{}}]}),_3=xo("instance_presence",{validator:I3,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:{}})),k3=wo("document",ve({typeName:cn("document"),id:cn("document:document"),gridSize:fe,name:pe,meta:Bt})),Pb=Fn("com.tldraw.document",{AddName:1,AddMeta:2}),T3=ar({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:Pb.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:Pb.AddMeta,up:e=>{e.meta={}}}]}),S0=xo("document",{validator:k3,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),tS=S0.createId("document");function $3(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function Cb(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const M3=({error:e,phase:n,record:t,recordBefore:r})=>{throw o0(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?Cb(xt(r)):void 0,recordAfter:Cb(xt(t))}}),e};function A3(){return[Go.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function j3(e){const n=e.query.ids("page"),t=()=>{if(!e.has(tS))return e.put([S0.create({id:tS,name:e.props.defaultName})]),t();if(!e.has(Cf))return e.put([y0.create({id:Cf})]),t();const r=n.get();if(r.size===0)return e.put(A3()),t();const o=()=>[...r].map(c=>e.get(c)).sort($3)[0].id,s=e.get(en);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:en,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const c of r){const l=xr.createId(c);e.has(l)||i.add(l);const u=Fr.createId(c);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(c=>xr.create({id:c,pageId:xr.parseId(c)}))),a.size>0&&e.put([...a].map(c=>Fr.create({id:c})))};return t}const O3=m0("bookmark",ve({title:pe,description:pe,image:pe,src:xc.nullable()})),D3=Fn("com.tldraw.asset.bookmark",{MakeUrlsValid:1}),R3=ar({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:D3.MakeUrlsValid,up:e=>{xc.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),L3=m0("image",ve({w:fe,h:fe,name:pe,isAnimated:we,mimeType:pe.nullable(),src:xc.nullable()})),Ug=Fn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3}),F3=ar({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:Ug.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Ug.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:Ug.MakeUrlsValid,up:e=>{xc.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),N3=m0("video",ve({w:fe,h:fe,name:pe,isAnimated:we,mimeType:pe.nullable(),src:xc.nullable()})),Hg=Fn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3}),z3=ar({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:Hg.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Hg.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:Hg.MakeUrlsValid,up:e=>{xc.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),B3=wo("asset",f0("type",{image:L3,video:N3,bookmark:O3})),U3=Fn("com.tldraw.asset",{AddMeta:1}),H3=ar({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:U3.AddMeta,up:e=>{e.meta={}}}]}),yi=xo("asset",{validator:B3,scope:"document"}).withDefaultProperties(()=>({meta:{}})),zE={w:Ln,h:Ln,assetId:_p.nullable(),url:rr},Ib=bo("bookmark",{NullAssetId:1,MakeUrlsValid:2}),BE={sequence:[{id:Ib.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:vt},{id:Ib.MakeUrlsValid,up:e=>{rr.isValid(e.url)||(e.url="")},down:e=>{}}]},UE=ve({type:p0("free","straight"),points:zt(ki)}),HE={color:or,fill:rc,dash:Ti,size:go,segments:zt(UE),isComplete:we,isClosed:we,isPen:we},K3=bo("draw",{AddInPen:1}),KE={sequence:[{id:K3.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:vt}]};var W3={};const Eb=/(^\/r\/[^/]+\/?$)/,Oe=e=>{try{return new URL(e)}catch{return}},_u=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(Eb))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(Eb))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=${W3.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","")}}],G3={"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},WE={w:Ln,h:Ln,url:pe},ad=bo("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),GE={sequence:[{id:ad.GenOriginalUrlInEmbed,up:e=>{try{const n=e.url,t=new URL(n).host.replace("www.","");let r;for(const o of _u)if(o.hostnames.includes(t))try{r=o.fromEmbedUrl(n)}catch(s){console.warn(s)}e.tmpOldUrl=e.url,e.url=r??""}catch{e.url="",e.tmpOldUrl=e.url}},down:vt},{id:ad.RemoveDoesResize,up:e=>{delete e.doesResize},down:vt},{id:ad.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:vt},{id:ad.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:vt}]},VE={w:Ln,h:Ln,name:pe},YE={sequence:[]},If=Vt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Ef=Vt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),co=Vt.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"]}),XE={geo:co,labelColor:ME,color:or,fill:rc,dash:Ti,size:go,font:po,align:If,verticalAlign:Ef,url:rr,w:Ln,h:Ln,growY:vf,text:pe},hs=bo("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8}),qE={sequence:[{id:hs.AddUrlProp,up:e=>{e.url=""},down:vt},{id:hs.AddLabelColor,up:e=>{e.labelColor="black"},down:vt},{id:hs.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:vt},{id:hs.AddCheckBox,up:e=>{},down:vt},{id:hs.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:vt},{id:hs.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:vt},{id:hs.AddCloud,up:e=>{},down:vt},{id:hs.MakeUrlsValid,up:e=>{rr.isValid(e.url)||(e.url="")},down:e=>{}}]},ZE={},QE={sequence:[]},JE={color:or,size:go,segments:zt(UE),isComplete:we,isPen:we},e_={sequence:[]},V3=ve({topLeft:ki,bottomRight:ki}),t_={w:Ln,h:Ln,playing:we,url:rr,assetId:_p.nullable(),crop:V3.nullable()},Kg=bo("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3}),n_={sequence:[{id:Kg.AddUrlProp,up:e=>{e.url=""},down:vt},{id:Kg.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:Kg.MakeUrlsValid,up:e=>{rr.isValid(e.url)||(e.url="")},down:e=>{}}]},_f=Vt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),Y3=ve({id:pe,index:g0,x:fe,y:fe}),r_={color:or,dash:Ti,size:go,spline:_f,points:xf(pe,Y3)},cd=bo("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4}),o_={sequence:[{id:cd.AddSnapHandles,up:e=>{for(const n of Object.values(e.handles))n.canSnap=!0},down:vt},{id:cd.RemoveExtraHandleProps,up:e=>{e.handles=i0(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(nn);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:cd.HandlesToPoints,up:e=>{const n=Object.entries(e.handles).map(([t,{x:r,y:o}])=>({x:r,y:o,index:t})).sort(nn);e.points=n.map(({x:t,y:r})=>({x:t,y:r})),delete e.handles},down:e=>{const n=Bl(e.points.length);e.handles=Object.fromEntries(e.points.map((t,r)=>[n[r],{x:t.x,y:t.y}])),delete e.points}},{id:cd.PointIndexIds,up:e=>{const n=Bl(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(nn);e.points=n.map(({x:t,y:r})=>({x:t,y:r}))}}]},s_={color:or,size:go,font:po,fontSizeAdjustment:vf,align:If,verticalAlign:Ef,growY:vf,url:rr,text:pe},ra=bo("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6}),i_={sequence:[{id:ra.AddUrlProp,up:e=>{e.url=""},down:vt},{id:ra.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:vt},{id:ra.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:vt},{id:ra.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:vt},{id:ra.MakeUrlsValid,up:e=>{rr.isValid(e.url)||(e.url="")},down:e=>{}},{id:ra.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}}]},nS=Vt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),a_={color:or,size:go,font:po,textAlign:nS,w:Ln,text:pe,scale:Ln,autoSize:we},_b=bo("text",{RemoveJustify:1,AddTextAlign:2}),c_={sequence:[{id:_b.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:vt},{id:_b.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},l_={w:Ln,h:Ln,time:fe,playing:we,url:rr,assetId:_p.nullable()},kb=bo("video",{AddUrlProp:1,MakeUrlsValid:2}),u_={sequence:[{id:kb.AddUrlProp,up:e=>{e.url=""},down:vt},{id:kb.MakeUrlsValid,up:e=>{rr.isValid(e.url)||(e.url="")},down:e=>{}}]},ld=Fn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),X3=Ha({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:ld.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[n,t]of An(e))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete e[n]}},{id:ld.AddInstancePresenceType,scope:"store",up(e){}},{id:ld.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[n,t]of An(e))t.typeName.match(/^(user|user_presence)$/)&&delete e[n]}},{id:ld.RemoveUserDocument,scope:"store",up:e=>{for(const[n,t]of An(e))t.typeName.match("user_document")&&delete e[n]}}]}),q3={arrow:{migrations:DE,props:OE},bookmark:{migrations:BE,props:zE},draw:{migrations:KE,props:HE},embed:{migrations:GE,props:WE},frame:{migrations:YE,props:VE},geo:{migrations:qE,props:XE},group:{migrations:QE,props:ZE},highlight:{migrations:e_,props:JE},image:{migrations:n_,props:t_},line:{migrations:o_,props:r_},note:{migrations:i_,props:s_},text:{migrations:c_,props:a_},video:{migrations:u_,props:l_}},Z3={arrow:{migrations:LE,props:RE}};function Q3({shapes:e=q3,bindings:n=Z3,migrations:t}={}){const r=new Map;for(const a of yt(e))for(const c of kE(a.props??{}).keys()){if(r.has(c.id)&&r.get(c.id)!==c)throw new Error(`Multiple StyleProp instances with the same id: ${c.id}`);r.set(c.id,c)}const o=i3(e),s=r3(n),i=S3(r);return d0.create({asset:yi,binding:s,camera:Fr,document:S0,instance:i,instance_page_state:xr,page:Go,instance_presence:_3,pointer:y0,shape:o},{migrations:[X3,H3,l3,T3,v3,w3,y3,E3,C3,s3,R3,F3,z3,...bb("shape",e),...bb("binding",n),...t??[]],onValidationFailure:M3,createIntegrityChecker:j3})}const Hl=[{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 J3(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return eL(e)}function eL(e){for(const n of e){const t=tL(n);if(t)return t}return"en"}const Tb={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function tL(e){const n=Hl.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Hl.find(s=>s.locale===t);if(o)return o.locale}return t in Tb?Tb[t]:null}var d_={exports:{}};/*!
54
- Copyright (c) 2018 Jed Watson.
55
- Licensed under the MIT License (MIT), see
56
- http://jedwatson.github.io/classnames
57
- */(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})()})(d_);var nL=d_.exports;const ue=Ys(nL),rL={error:null};class h_ extends x.Component{constructor(){super(...arguments);g(this,"state",rL)}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 h.jsx(r,{error:t})}return this.props.children}}function Kl({children:e,fallback:n,...t}){return n===null?h.jsx(h.Fragment,{children:e}):h.jsx(h_,{fallback:n,...t,children:e})}const kp=Se.createContext(null);function B(){const e=Se.useContext(kp);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function oL(){return h.jsx("div",{className:"tl-background"})}function wc(e,n,t,r,o,s){x.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 an={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 b{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 b(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=b.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 b.Dpr(this,n)}cpr(n){return b.Cpr(this,n)}len2(){return b.Len2(this)}len(){return b.Len(this)}pry(n){return b.Pry(this,n)}per(){const{x:n,y:t}=this;return this.x=t,this.y=-n,this}uni(){return b.Uni(this)}tan(n){return b.Tan(this,n)}dist(n){return b.Dist(this,n)}distanceToLineSegment(n,t){return b.DistanceToLineSegment(n,t,this)}slope(n){return b.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 b.Angle(this,n)}toAngle(){return b.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 b.Equals(this,n)}equalsXY(n,t){return b.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 b.ToFixed(this)}toString(){return b.ToString(b.ToFixed(this))}toJson(){return b.ToJson(this)}toArray(){return b.ToArray(this)}static Add(n,t){return new b(n.x+t.x,n.y+t.y)}static AddXY(n,t,r){return new b(n.x+t,n.y+r)}static Sub(n,t){return new b(n.x-t.x,n.y-t.y)}static SubXY(n,t,r){return new b(n.x-t,n.y-r)}static AddScalar(n,t){return new b(n.x+t,n.y+t)}static SubScalar(n,t){return new b(n.x-t,n.y-t)}static Div(n,t){return new b(n.x/t,n.y/t)}static Mul(n,t){return new b(n.x*t,n.y*t)}static DivV(n,t){return new b(n.x/t.x,n.y/t.y)}static MulV(n,t){return new b(n.x*t.x,n.y*t.y)}static Neg(n){return new b(-n.x,-n.y)}static Per(n){return new b(n.y,-n.x)}static Abs(n){return new b(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 b(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 b.Dpr(n,t)/b.Len(t)}static Uni(n){return b.Div(n,b.Len(n))}static Tan(n,t){return b.Uni(b.Sub(n,t))}static Min(n,t){return new b(Math.min(n.x,t.x),Math.min(n.y,t.y))}static Max(n,t){return new b(Math.max(n.x,t.x),Math.max(n.y,t.y))}static From({x:n,y:t,z:r=1}){return new b(n,t,r)}static FromArray(n){return new b(n[0],n[1])}static Rot(n,t=0){const r=Math.sin(t),o=Math.cos(t);return new b(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 b(t.x+(o*a-s*i),t.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(n,t,r){return b.Mul(t,b.Sub(r,n).pry(t)).add(n)}static NearestPointOnLineSegment(n,t,r,o=!0){if(b.Equals(n,r)||b.Equals(t,r))return b.From(r);const s=b.Tan(t,n),i=b.Add(n,b.Mul(s,b.Sub(r,n).pry(s)));if(o){if(i.x<Math.min(n.x,t.x))return b.Cast(n.x<t.x?n:t);if(i.x>Math.max(n.x,t.x))return b.Cast(n.x>t.x?n:t);if(i.y<Math.min(n.y,t.y))return b.Cast(n.y<t.y?n:t);if(i.y>Math.max(n.y,t.y))return b.Cast(n.y>t.y?n:t)}return i}static DistanceToLineThroughPoint(n,t,r){return b.Dist(r,b.NearestPointOnLineThroughPoint(n,t,r))}static DistanceToLineSegment(n,t,r,o=!0){return b.Dist(r,b.NearestPointOnLineSegment(n,t,r,o))}static Snap(n,t=1){return new b(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}static Cast(n){return n instanceof b?n:b.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 b.Sub(t,n).mul(r).add(n)}static Med(n,t){return new b((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=b.Len(n);return new b(t*n.x/r,t*n.y/r)}static ScaleWithOrigin(n,t,r){return b.Sub(n,r).mul(t).add(r)}static ToFixed(n){return new b(oc(n.x),oc(n.y))}static ToInt(n){return new b(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 b.Add(n,b.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 b(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 b(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 b(Math.min(Math.max(n.x,t)),Math.min(Math.max(n.y,t))):new b(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=an.easeInQuad(s/(r-1)),a=b.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-sL(i))*.65),o.push(a)}return o}static SnapToGrid(n,t=8){return new b(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}}const sL=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ee(e){return`${F(e.x)},${F(e.y)} `}function In(e,n){return`${F((e.x+n.x)/2)},${F((e.y+n.y)/2)} `}const ke=Math.PI,Ve=ke/2,Re=ke*2,iL=Math.sin;function $t(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function ud(e,n=1e10){return e?Math.round(e*n)/n:0}function Cl(e,n,t=1e-6){return Math.abs(e-n)<=t}function f_(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 Ms(e){return e=e%Re,e<0?e=e+Re:e===0&&(e=0),e}function ku(e,n){return e=Ms(e),n=Ms(n),e>n&&(n+=Re),n-e}function p_(e,n){return Re-ku(e,n)}function hh(e,n){const t=(n-e)%Re;return 2*t%Re-t}function rS(e){return(Re+e)%Re}function kf(e,n){const t=Re/n;let r=Math.floor((rS(e)+t/2)/t)*t%Re;return r<ke&&(r+=Re),r>ke&&(r-=Re),r}function g_(e,n){return e===n||Cl(e%(Math.PI/2)-n%(Math.PI/2),0)}function aL(e){return e*ke/180}function cL(e){return e*180/ke}function $i(e,n,t){return new b(e.x,e.y).add(b.FromAngle(t,n))}function Wg(e,n,t){const r=e/2,o=n/2,s=[];let i=1/0,a=-1/0,c=1/0,l=-1/0;for(let y=0;y<t;y++){const m=Re/t,w=-Ve+y*m,S=r+r*Math.cos(w),v=o+o*Math.sin(w);S<i&&(i=S),v<c&&(c=v),S>a&&(a=S),v>l&&(l=v),s.push(new b(S,v))}const u=a-i,d=l-c,f=e-u,p=n-d;if(f!==0||p!==0)for(let y=0;y<s.length;y++){const m=s[y];m.x=(m.x-i)/u*e,m.y=(m.y-c)/d*n}return s}function Wc(e,n,t,r){return e<r&&t<n}function jr(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function $b(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function er(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],b.Dist(e,r)+b.Dist(e,o)===b.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&$b(r,o,e)>0&&(t+=1):o.y<=e.y&&$b(r,o,e)<0&&(t-=1)}return t!==0}function F(e){return Math.round(e*1e4)/1e4}function oc(e){return Math.round(e*100)/100}const Mb=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function ws(e,n,t){return t<0?ku(e,n):p_(e,n)}function oS(e,n,t,r){let o;if(Math.abs(e)>ke){o=hh(n,r);const s=hh(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=hh(n,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function lL(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 v0(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 b(((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 uL(e,n,t,r,o){if(t===null)return[b.From(e),b.From(n)];const s=[],i=b.Angle(t,e),a=b.Angle(t,n),c=ku(i,a);for(let l=0;l<o;l++){const u=l/(o-1),d=i+c*u,f=$i(t,r,d);s.push(f)}return s}const dd=({brush:e,color:n,opacity:t,className:r})=>{const o=x.useRef(null);wc(o,e.x,e.y);const s=F(Math.max(1,e.w)),i=F(Math.max(1,e.h));return h.jsx("svg",{className:"tl-overlays__item",ref:o,children:n?h.jsxs("g",{className:"tl-brush",opacity:t,children:[h.jsx("rect",{width:s,height:i,fill:n,opacity:.75}),h.jsx("rect",{width:s,height:i,fill:"none",stroke:n,opacity:.1})]}):h.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},ys=4e3,Tf=40,no=320,Ab={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},jb=2,dL=450,hL=200,m_=36,$f=16,fL=32,Gg={duration:0,easing:an.easeInOutCubic},y_=.09,Ob=[{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}],pL=6e4,S_=3e3,gL=1200,Db={CAMERA_MOVE:-10},mL=64,Vo=8,yL=20,SL=8,vL=12,v_=20,x_=12,xL=["top","right","bottom","left"],wL=500,Rb=.35,Lb=0,x0=2,hd=1,Fb=5,bL=128;var Vg={};const PL={},w_=bn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),Pt={logPreventDefaults:bn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:bn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:bn("logElementRemoves",{defaults:{all:!1}}),debugSvg:bn("debugSvg",{defaults:{all:!1}}),showFps:bn("showFps",{defaults:{all:!1}}),measurePerformance:bn("measurePerformance",{defaults:{all:!1}}),throwToBlob:bn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:bn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:bn("debugCursors",{defaults:{all:!1}}),forceSrgb:bn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:bn("debugGeometry",{defaults:{all:!1}}),hideShapes:bn("hideShapes",{defaults:{all:!1}}),editOnType:bn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;Wi("element removal logging",()=>{Pt.logElementRemoves.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function bn(e,{defaults:n,shouldStoreForSession:t=!0}){return CL({name:e,defaults:n,shouldStoreForSession:t})}function CL(e){const n=EL(e),t=e.shouldStoreForSession?IL(e.name):null,r=on(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&Wi(`debug:${e.name}`,()=>{const o=r.get();o===n?SE(`tldraw_debug:${e.name}`):l0(`tldraw_debug:${e.name}`,JSON.stringify(o))}),Object.defineProperty(window,`tldraw${e.name.replace(/^[a-z]/,o=>o.toUpperCase())}`,{get(){return r.get()},set(o){r.set(o)},configurable:!0})),Object.assign(r,e)}function IL(e){try{return JSON.parse(yE(`tldraw_debug:${e}`)??"null")}catch{return null}}function Yg(e){try{return e()}catch{return null}}function EL(e){switch(Yg(()=>Vg.TLDRAW_ENV)??Yg(()=>Vg.VERCEL_PUBLIC_TLDRAW_ENV)??Yg(()=>Vg.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 Mf(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return Mf(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function _e(e){e.preventDefault(),Pt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Tu(e,n){if(e.setPointerCapture(n.pointerId),Pt.logPointerCaptures.get()){const t=w_.get();t.set(e,(t.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,n)}}function $u(e,n){if(e.hasPointerCapture(n.pointerId)&&(e.releasePointerCapture(n.pointerId),Pt.logPointerCaptures.get())){const t=w_.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(),Zt=(e,n,t)=>{e&&e.style.setProperty(n,t)};function Tn(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 _L(){const e=B();return x.useMemo(function(){let r,o;function s(m){if(!m.isKilled){if(m.button===x0){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...Tn(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(Tu(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Tn(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",...Tn(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,$u(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Tn(m)}))}function c(m){if(m.isKilled||e.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const w=m.pointerType==="mouse"||m.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!0:null})}function l(m){if(m.isKilled||e.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const w=m.pointerType==="mouse"||m.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!1:null})}function u(m){m.isKilled=!0,_e(m)}function d(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"))&&_e(m)}function f(m){_e(m)}async function p(m){var S,v;if(_e(m),!((v=(S=m.dataTransfer)==null?void 0:S.files)!=null&&v.length))return;const w=Array.from(m.dataTransfer.files);await e.putExternalContent({type:"files",files:w,point:e.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function y(m){Ht(m)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:c,onPointerLeave:l,onDragOver:f,onDrop:p,onTouchStart:u,onTouchEnd:d,onClick:y}},[e])}function kL(){const e=B();x.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_=x.createContext(null);function TL({container:e,children:n}){return h.jsx(b_.Provider,{value:e,children:n})}function dn(){return Vn(x.useContext(b_),"useContainer used outside of <Tldraw />")}function $L(){const e=B(),n=dn(),t=W("isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=c=>{c.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},e.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[e]),x.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!fd()&&_e(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){_e(a);return}break}case"Tab":{if(fd()||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(fd()||e.getIsMenuOpen())return}const c={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(c)},o=a=>{if(a.isKilled||(a.isKilled=!0,fd()||e.getIsMenuOpen())||a.key===",")return;const c={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(c)};function s(a){var c,l;if(n.contains(a.target)){const u=a.touches[0].pageX,d=a.touches[0].radiusX||0;(u-d<10||u+d>e.getViewportScreenBounds().width-10)&&(((c=a.target)==null?void 0:c.tagName)==="BUTTON"&&((l=a.target)==null||l.click()),_e(a))}}const i=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&_e(a)};return n.addEventListener("touchstart",s,{passive:!1}),n.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",_e),document.addEventListener("gesturechange",_e),document.addEventListener("gestureend",_e),n.addEventListener("keydown",r),n.addEventListener("keyup",o),()=>{n.removeEventListener("touchstart",s),n.removeEventListener("wheel",i),document.removeEventListener("gesturestart",_e),document.removeEventListener("gesturechange",_e),document.removeEventListener("gestureend",_e),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const ML=["input","select","button","textarea"];function fd(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||ML.indexOf(e.tagName.toLowerCase())>-1))}const AL=["textarea","input"];function jL(e){const n=B();x.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(AL.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||n.isIn("select.editing_shape"))return;_e(o)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[n,e])}function OL(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 Nb(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function zb(e,n,t,r=.15){return r===0?OL(e,n,t):e<n?-Nb(n-e,t-n,r)+n:e>t?+Nb(e-t,t-n,r)+t:e}function DL(e,[n,t],[r,o]){const[[s,i],[a,c]]=e;return[zb(n,s,i,r),zb(t,a,c,o)]}function RL(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 LL(e){var n=RL(e,"string");return typeof n=="symbol"?n:String(n)}function Qt(e,n,t){return n=LL(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function Bb(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 lt(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Bb(Object(t),!0).forEach(function(r){Qt(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):Bb(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const P_={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 Ub(e){return e?e[0].toUpperCase()+e.slice(1):""}const FL=["enter","leave"];function NL(e=!1,n){return e&&!FL.includes(n)}function zL(e,n="",t=!1){const r=P_[e],o=r&&r[n]||n;return"on"+Ub(e)+Ub(o)+(NL(t,o)?"Capture":"")}const BL=["gotpointercapture","lostpointercapture"];function UL(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=BL.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function HL(e,n=""){const t=P_[e],r=t&&t[n]||n;return e+r}function C_(e){return"touches"in e}function KL(e){return C_(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function WL(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 sS(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 GL(e){return WL(e).map(n=>n.identifier)}function Hb(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return sS(t,r)}const Kb=40,Wb=800;function I_(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=Kb,t*=Kb):r===2&&(n*=Wb,t*=Wb),[n,t]}function VL(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 Af(e,...n){return typeof e=="function"?e(...n):e}function YL(){}function XL(...e){return e.length===0?YL:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function Gb(e,n){return Object.assign({},n,e||{})}const qL=32;class E_{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?Af(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,VL(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 I=t._delta.map(Math.abs);Ut.addTo(t._distance,I)}this.axisIntent&&this.axisIntent(n);const[i,a]=t._movement,[c,l]=r.threshold,{_step:u,values:d}=t;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=c&&d[0]),u[1]===!1&&(u[1]=Math.abs(a)>=l&&d[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=c&&Math.sign(i)*c),u[1]===!1&&(u[1]=Math.abs(a)>=l&&Math.sign(a)*l)),t.intentional=u[0]!==!1||u[1]!==!1,!t.intentional)return;const f=[0,0];if(r.hasCustomTransform){const[I,_]=d;f[0]=u[0]!==!1?I-u[0]:0,f[1]=u[1]!==!1?_-u[1]:0}else f[0]=u[0]!==!1?i-u[0]:0,f[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(f);const p=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=Af(r.bounds,t)),this.setup&&this.setup()),t.movement=f,this.computeOffset()));const[m,w]=t.offset,[[S,v],[P,E]]=t._bounds;t.overflow=[m<S?-1:m>v?1:0,w<P?-1:w>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 C=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=DL(t._bounds,t.offset,C),t.delta=Ut.sub(t.offset,p),this.computeMovement(),y&&(!t.last||s>qL)){t.delta=Ut.sub(t.offset,p);const I=t.delta.map(Math.abs);Ut.addTo(t.distance,I),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&s>0&&(t.velocity=[I[0]/s,I[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(lt(lt(lt({},t),n),{},{[this.aliasKey]:n.values}));o!==void 0&&(n.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function ZL([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 QL extends E_{constructor(...n){super(...n),Qt(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=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[KL(n)]:r.axisThreshold;t.axis=ZL(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 JL=e=>e,Vb=.15,__={enabled(e=!0){return e},eventOptions(e,n,t){return lt(lt({},t.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[Vb,Vb];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||JL},threshold(e){return Ut.toVector(e,0)}},eF=0,Mu=lt(lt({},__),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=eF){return e},bounds(e={}){if(typeof e=="function")return s=>Mu.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]]}}),Au=typeof window<"u"&&window.document&&window.document.createElement;function k_(){return Au&&"ontouchstart"in window}function tF(){return k_()||Au&&window.navigator.maxTouchPoints>1}function nF(){return Au&&"onpointerdown"in window}function rF(){return Au&&"exitPointerLock"in window.document}function oF(){try{return"constructor"in GestureEvent}catch{return!1}}const yr={isBrowser:Au,gesture:oF(),touch:k_(),touchscreen:tF(),pointer:nF(),pointerLock:rF()},sF=250,iF=180,aF=.5,cF=50,lF=250,uF=10,Yb={mouse:0,touch:0,pen:8};lt(lt({},Mu),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&yr.pointerLock,yr.touch&&t?"touch":this.pointerLock?"mouse":yr.pointer&&!o?"pointer":yr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?sF:void 0,!(!yr.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=aF,distance:n=cF,duration:t=lF}={}){return{velocity:this.transform(Ut.toVector(e)),distance:this.transform(Ut.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return iF;case!1:return 0;default:return e}},axisThreshold(e){return e?lt(lt({},Yb),e):Yb},keyboardDisplacement(e=uF){return e}});function T_(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 dF=30,hF=100;class fF extends E_{constructor(...n){super(...n),Qt(this,"ingKey","pinching"),Qt(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const 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)*dF-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=Hb(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=sS(...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=Hb(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=sS(...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=[-I_(n)[1]/hF*r.offset[0],0],Ut.addTo(r._movement,r._delta),T_(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 pF=lt(lt({},__),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!yr.touch&&yr.gesture)return"gesture";if(yr.touch&&r)return"touch";if(yr.touchscreen){if(yr.pointer)return"pointer";if(yr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=i=>{const a=Gb(Af(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=Gb(Af(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}});lt(lt({},Mu),{},{mouseOnly:(e=!0)=>e});class gF extends QL{constructor(...n){super(...n),Qt(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=I_(n),Ut.addTo(t._movement,t._delta),T_(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 mF=Mu;lt(lt({},Mu),{},{mouseOnly:(e=!0)=>e});const w0=new Map,iS=new Map;function yF(e){w0.set(e.key,e.engine),iS.set(e.key,e.resolver)}const SF={key:"pinch",engine:fF,resolver:pF},vF={key:"wheel",engine:gF,resolver:mF};function xF(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 wF(e,n){if(e==null)return{};var t=xF(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 bF={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=yr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},PF=["target","eventOptions","window","enabled","transform"];function fh(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]=fh(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function CF(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:c}=r,l=wF(r,PF);if(t.shared=fh({target:o,eventOptions:s,window:i,enabled:a,transform:c},bF),n){const u=iS.get(n);t[n]=fh(lt({shared:t.shared},l),u)}else for(const u in l){const d=iS.get(u);d&&(t[u]=fh(lt({shared:t.shared},l[u]),d))}return t}class $_{constructor(n,t){Qt(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,s){const i=this._listeners,a=HL(t,r),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},l=lt(lt({},c),s);n.addEventListener(a,o,l);const u=()=>{n.removeEventListener(a,o,l),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class IF{constructor(){Qt(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 EF{constructor(n){Qt(this,"gestures",new Set),Qt(this,"_targetEventStore",new $_(this)),Qt(this,"gestureEventStores",{}),Qt(this,"gestureTimeoutStores",{}),Qt(this,"handlers",{}),Qt(this,"config",{}),Qt(this,"pointerIds",new Set),Qt(this,"touchIds",new Set),Qt(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),_F(this,n)}setEventIds(n){if(C_(n))return this.touchIds=new Set(GL(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=CF(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],c=Xb(r,a.eventOptions,!!o);if(a.enabled){const l=w0.get(i);new l(this,n,i).bind(c)}}const s=Xb(r,t.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](lt(lt({},this.state.shared),{},{event:a,args:n})),void 0,!0)}for(const s in r)r[s]=XL(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:c}=UL(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:c})}}}}function oa(e,n){e.gestures.add(n),e.gestureEventStores[n]=new $_(e,n),e.gestureTimeoutStores[n]=new IF}function _F(e,n){n.drag&&oa(e,"drag"),n.wheel&&oa(e,"wheel"),n.scroll&&oa(e,"scroll"),n.move&&oa(e,"move"),n.pinch&&oa(e,"pinch"),n.hover&&oa(e,"hover")}const Xb=(e,n,t)=>(r,o,s,i={},a=!1)=>{var c,l;const u=(c=i.capture)!==null&&c!==void 0?c:n.capture,d=(l=i.passive)!==null&&l!==void 0?l:n.passive;let f=a?r:zL(r,o,u);t&&d&&(f+="Passive"),e[f]=e[f]||[],e[f].push(s)},kF=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function TF(e){const n={},t={},r=new Set;for(let o in e)kF.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function sa(e,n,t,r,o,s){if(!e.has(t)||!w0.has(r))return;const i=t+"Start",a=t+"End",c=l=>{let u;return l.first&&i in n&&n[i](l),t in n&&(u=n[t](l)),l.last&&a in n&&n[a](l),u};o[r]=c,s[r]=s[r]||{}}function $F(e,n){const[t,r,o]=TF(e),s={};return sa(o,t,"onDrag","drag",s,n),sa(o,t,"onWheel","wheel",s,n),sa(o,t,"onScroll","scroll",s,n),sa(o,t,"onPinch","pinch",s,n),sa(o,t,"onMove","move",s,n),sa(o,t,"onHover","hover",s,n),{handlers:s,config:n,nativeHandlers:r}}function MF(e,n={},t,r){const o=Se.useMemo(()=>new EF(e),[]);if(o.applyHandlers(e,r),o.applyConfig(n,t),Se.useEffect(o.effect.bind(o)),Se.useEffect(()=>o.clean.bind(o),[]),n.target===void 0)return o.bind.bind(o)}function AF(e){return e.forEach(yF),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=$F(t,r||{});return MF(o,i,void 0,s)}}const qb=10,jF=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function M_(e){let{deltaY:n,deltaX:t}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(n)>qb?qb*Math.sign(n):n)/100:e.shiftKey&&!jF&&(t=n,n=0),{x:-t,y:-n,z:-r}}const OF=AF([vF,SF]);let ia;const DF=e=>ia===void 0?(ia=e,!1):e-ia>120&&e-ia<160?(ia=e,!0):(ia=e,!1);function RF(e){const n=B(),t=x.useMemo(()=>{let r="not sure";const o=({event:m})=>{if(!n.getInstanceState().isFocused||(r="not sure",DF(Date.now())))return;const w=n.getEditingShapeId();if(w){const P=n.getShape(w);if(P&&n.getShapeUtil(P).canScroll(P)){const C=n.getShapePageBounds(w);if(C!=null&&C.containsPoint(n.inputs.currentPagePoint))return}}_e(m),Ht(m);const S=M_(m);if(S.x===0&&S.y===0)return;const v={type:"wheel",name:"wheel",delta:S,point:new b(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,c=0;const l=new b,u=new b,d=m=>{const w=e.current;r="not sure";const{event:S,origin:v,da:P}=m;S instanceof WheelEvent||(S.target===w||w!=null&&w.contains(S.target))&&(u.x=v[0],u.y=v[1],l.x=v[0],l.y=v[1],s=P[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}))},f=m=>{if(m&&(r="zooming"),r==="zooming")return;const w=Math.abs(c-s),S=b.Dist(l,u);switch(r){case"not sure":{w>24?r="zooming":S>16&&(r="panning");break}case"panning":{w>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:d,onPinchEnd:m=>{const w=e.current,{event:S,origin:v,offset:P}=m;if(S instanceof WheelEvent||!(S.target===w||w!=null&&w.contains(S.target)))return;const E=P[0];r="not sure",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 w=e.current,{event:S,origin:v,offset:P,da:E}=m;if(S instanceof WheelEvent||!(S.target===w||w!=null&&w.contains(S.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";c=E[0];const I=v[0]-u.x,_=v[1]-u.y;switch(u.x=v[0],u.y=v[1],f(C),r){case"zooming":{a=P[0],n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:I,y:_},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:I,y:_},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}}}}},[n,e]);OF(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function Xg(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function LF(e,n){const t=B();return x.useMemo(()=>{const r=c=>{if(c.isKilled)return;const l=Mf(c.currentTarget);Tu(l,c);const{shape:u,handle:d}=Xg(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_down",...Tn(c)})};let o,s;return{onPointerDown:r,onPointerMove:c=>{if(c.isKilled||c.clientX===o&&c.clientY===s)return;o=c.clientX,s=c.clientY;const{shape:l,handle:u}=Xg(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:l,name:"pointer_move",...Tn(c)})},onPointerUp:c=>{if(c.isKilled)return;const l=Mf(c.currentTarget);$u(l,c);const{shape:u,handle:d}=Xg(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_up",...Tn(c)})}}},[t,e,n])}var A_="Expected a function",Zb=NaN,FF="[object Symbol]",NF=/^\s+|\s+$/g,zF=/^[-+]0x[0-9a-f]+$/i,BF=/^0b[01]+$/i,UF=/^0o[0-7]+$/i,HF=parseInt,KF=typeof rn=="object"&&rn&&rn.Object===Object&&rn,WF=typeof self=="object"&&self&&self.Object===Object&&self,GF=KF||WF||Function("return this")(),VF=Object.prototype,YF=VF.toString,XF=Math.max,qF=Math.min,qg=function(){return GF.Date.now()};function ZF(e,n,t){var r,o,s,i,a,c,l=0,u=!1,d=!1,f=!0;if(typeof e!="function")throw new TypeError(A_);n=Qb(n)||0,jf(t)&&(u=!!t.leading,d="maxWait"in t,s=d?XF(Qb(t.maxWait)||0,n):s,f="trailing"in t?!!t.trailing:f);function p(I){var _=r,k=o;return r=o=void 0,l=I,i=e.apply(k,_),i}function y(I){return l=I,a=setTimeout(S,n),u?p(I):i}function m(I){var _=I-c,k=I-l,$=n-_;return d?qF($,s-k):$}function w(I){var _=I-c,k=I-l;return c===void 0||_>=n||_<0||d&&k>=s}function S(){var I=qg();if(w(I))return v(I);a=setTimeout(S,m(I))}function v(I){return a=void 0,f&&r?p(I):(r=o=void 0,i)}function P(){a!==void 0&&clearTimeout(a),l=0,r=c=o=a=void 0}function E(){return a===void 0?i:v(qg())}function C(){var I=qg(),_=w(I);if(r=arguments,o=this,c=I,_){if(a===void 0)return y(c);if(d)return a=setTimeout(S,n),p(c)}return a===void 0&&(a=setTimeout(S,n)),i}return C.cancel=P,C.flush=E,C}function QF(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(A_);return jf(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),ZF(e,n,{leading:r,maxWait:n,trailing:o})}function jf(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function JF(e){return!!e&&typeof e=="object"}function e5(e){return typeof e=="symbol"||JF(e)&&YF.call(e)==FF}function Qb(e){if(typeof e=="number")return e;if(e5(e))return Zb;if(jf(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=jf(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(NF,"");var t=BF.test(e);return t||UF.test(e)?HF(e.slice(2),t?2:8):zF.test(e)?Zb:+e}var t5=QF;const n5=Ys(t5),et=class et{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 b(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 b(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 b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY)]}get cornersAndCenter(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(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 b(this.w,this.h)}toFixed(){return this.x=ud(this.x),this.y=ud(this.y),this.w=ud(this.w),this.h=ud(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 et(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 et.Collides(this,n)}contains(n){return et.Contains(this,n)}includes(n){return et.Includes(this,n)}containsPoint(n,t=0){return et.ContainsPoint(this,n,t)}getHandlePoint(n){switch(n){case"top_left":return new b(this.minX,this.minY);case"top_right":return new b(this.maxX,this.minY);case"bottom_left":return new b(this.minX,this.maxY);case"bottom_right":return new b(this.maxX,this.maxY);case"top":return new b(this.midX,this.minY);case"right":return new b(this.maxX,this.midY);case"bottom":return new b(this.midX,this.maxY);case"left":return new b(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:c,minY:l,maxX:u,maxY:d}=this;switch(n){case"left":case"top_left":case"bottom_left":{c+=t;break}case"right":case"top_right":case"bottom_right":{u+=t;break}}switch(n){case"top":case"top_left":case"top_right":{l+=r;break}case"bottom":case"bottom_left":case"bottom_right":{d+=r;break}}const f=(u-c)/(i-o),p=(d-l)/(a-s),y=f<0,m=p<0;if(y){const w=u;u=c,c=w}if(m){const w=d;d=l,l=w}this.minX=c,this.minY=l,this.width=Math.abs(u-c),this.height=Math.abs(d-l)}union(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 et(n.x,n.y,n.w,n.h)}static FromCenter(n,t){return new et(n.x-t.x/2,n.y-t.y/2,t.x,t.y)}static FromPoints(n){if(n.length===0)return new et;let t=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,c=n.length;a<c;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 et(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 et(r,o,s-r,i-o)}static ExpandBy(n,t){return new et(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:c,maxY:l}=n;let{minX:u,minY:d,maxX:f,maxY:p}=n;switch(t){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{f+=r;break}}switch(t){case"top":case"top_left":case"top_right":{d+=o;break}case"bottom":case"bottom_left":case"bottom_right":{p+=o;break}}const y=(f-u)/(c-i),m=(p-d)/(l-a),w=y<0,S=m<0;if(s){const P=(c-i)/(l-a),E=Math.abs(f-u),C=Math.abs(p-d),I=E*(m<0?1:-1)*(1/P),_=C*(y<0?1:-1)*P,k=P<E/C;switch(t){case"top_left":{k?d=p+I:u=f+_;break}case"top_right":{k?d=p+I:f=u-_;break}case"bottom_right":{k?p=d-I:f=u-_;break}case"bottom_left":{k?p=d-I:u=f+_;break}case"bottom":case"top":{const $=(u+f)/2,T=C*P;u=$-T/2,f=$+T/2;break}case"left":case"right":{const $=(d+p)/2,T=E/P;d=$-T/2,p=$+T/2;break}}}if(w){const P=f;f=u,u=P}if(S){const P=p;p=d,d=P}const v=new et(u,d,Math.abs(f-u),Math.abs(p-d));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 et.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 et(n.x,n.y,Math.max(1,n.w),Math.max(1,n.h))}};g(et,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),g(et,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),g(et,"Includes",(n,t)=>et.Collides(n,t)||et.Contains(n,t)),g(et,"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(et,"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 et(t,r,o-t,s-r)}),g(et,"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 J=et;function r5(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 o5(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 s5(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function i5(e){const n=B();x.useLayoutEffect(()=>{let t=new J;function r(){const l=e.current;if(!l)return null;const u=l.getBoundingClientRect(),d=new J(u.left||u.x,u.top||u.y,Math.max(u.width,1),Math.max(u.height,1));t.equals(d)||(n.updateViewportScreenBounds(d),t=d)}r();const o=n5(r,200,{trailing:!0}),s=setInterval(o,1e3);window.addEventListener("resize",o);const i=new ResizeObserver(l=>{l[0].contentRect&&o()}),a=e.current;let c=null;return a&&(i.observe(a),c=a5(a),c.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),c==null||c.removeEventListener("scroll",o)}},[n,e])}/*!
58
- * Author: excalidraw
59
- * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
60
- * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
61
- */const a5=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:c}=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+c,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 b(n.e,n.f)}static Rotation(n){let t;if(n.a!==0||n.c!==0){const r=(n.a*n.a+n.c*n.c)**.5;t=Math.acos(n.a/r)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const r=(n.b*n.b+n.d*n.d)**.5;t=Ve+Math.acos(n.b/r)*(n.d>0?-1:1)}else t=0;return rS(t)}static Decompose(n){let t,r,o;if(n.a!==0||n.c!==0){const s=(n.a*n.a+n.c*n.c)**.5;t=s,r=(n.a*n.d-n.b*n.c)/s,o=Math.acos(n.a/s)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const s=(n.b*n.b+n.d*n.d)**.5;t=(n.a*n.d-n.b*n.c)/s,r=s,o=Ve+Math.acos(n.b/s)*(n.d>0?-1:1)}else t=0,r=0,o=0;return{x:n.e,y:n.f,scaleX:t,scaleY:r,rotation:rS(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(${F(n.a)}, ${F(n.b)}, ${F(n.c)}, ${F(n.d)}, ${F(n.e)}, ${F(n.f)})`}static applyToPoint(n,t){return new b(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 b(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 J(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 j_(e,n){return n===0?e:j_(n,e%n)}function O_(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/j_(r,t)}class qs{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)&&er(n,this.vertices)?!0:b.Dist2(n,this.nearestPoint(n))<=t*t}distanceToPoint(n,t=!1){return n.dist(this.nearestPoint(n))*(this.isClosed&&(this.isFilled||t)&&er(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,c;for(let l=0;l<r.length;l++)a=r[l],c=b.NearestPointOnLineSegment(n,t,a,!0),i=b.Dist2(a,c),i<s&&(s=i,o=c);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&er(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,c;for(let l=0;l<r.length;l++)a=r[l],c=b.NearestPointOnLineSegment(n,t,a,!0),i=b.Dist2(a,c),i<s&&(s=i,o=c);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 J.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+=b.Dist2(r,t),r=t;return Math.sqrt(o)}}class Hr extends qs{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 c of s)i=c.nearestPoint(t),a=b.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=J.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],c=i.dist(a),l=r[(o+1)%s],u=i.dist(l),d=i.clone().lrp(a,4/c),f=i,p=i.clone().lrp(l,4/u);t+=`M${d.x},${d.y} L${f.x},${f.y} L${p.x},${p.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 c5(e=!0){const[n,t]=x.useState(0),r=B();x.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const l5=ir(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=B();c5(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return h.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(c=>{const l=o.getShape(c.id);if(l.type==="group")return null;const u=o.getShapeGeometry(l),d=o.getShapePageTransform(l),f=o.getPointInShapeSpace(l,a),p=u.nearestPoint(f),y=u.distanceToPoint(f,!0),m=Math.abs(y)*s,w=y<0,{vertices:S}=u;return h.jsxs("g",{transform:d.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&h.jsx(D_,{geometry:u}),t&&S.map((v,P)=>h.jsx("circle",{cx:v.x,cy:v.y,r:"2",fill:`hsl(${pf(P,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:"1"},`v${P}`)),r&&m<150&&h.jsx("line",{x1:p.x,y1:p.y,x2:f.x,y2:f.y,opacity:1-m/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:"2"})]},c.id+"_outline")})})});function D_({geometry:e}){return e instanceof Hr?h.jsx(h.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>h.jsx(D_,{geometry:n},t))}):h.jsx("path",{stroke:e.debugColor??"red",strokeWidth:"2",fill:"none",opacity:"1",d:e.toSimpleSvgPath()})}var u5=200,b0="__lodash_hash_undefined__",d5=1/0,h5="[object Function]",f5="[object GeneratorFunction]",p5=/[\\^$.*+?()[\]{}|]/g,g5=/^\[object .+?Constructor\]$/,m5=typeof rn=="object"&&rn&&rn.Object===Object&&rn,y5=typeof self=="object"&&self&&self.Object===Object&&self,P0=m5||y5||Function("return this")();function S5(e,n){var t=e?e.length:0;return!!t&&x5(e,n,0)>-1}function v5(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 x5(e,n,t){if(n!==n)return v5(e,w5,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function w5(e){return e!==e}function b5(e,n){return e.has(n)}function P5(e,n){return e==null?void 0:e[n]}function C5(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function R_(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var I5=Array.prototype,E5=Function.prototype,L_=Object.prototype,Zg=P0["__core-js_shared__"],Jb=function(){var e=/[^.]+$/.exec(Zg&&Zg.keys&&Zg.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),F_=E5.toString,C0=L_.hasOwnProperty,_5=L_.toString,k5=RegExp("^"+F_.call(C0).replace(p5,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T5=I5.splice,$5=I0(P0,"Map"),Qg=I0(P0,"Set"),Wl=I0(Object,"create");function Mi(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 M5(){this.__data__=Wl?Wl(null):{}}function A5(e){return this.has(e)&&delete this.__data__[e]}function j5(e){var n=this.__data__;if(Wl){var t=n[e];return t===b0?void 0:t}return C0.call(n,e)?n[e]:void 0}function O5(e){var n=this.__data__;return Wl?n[e]!==void 0:C0.call(n,e)}function D5(e,n){var t=this.__data__;return t[e]=Wl&&n===void 0?b0:n,this}Mi.prototype.clear=M5;Mi.prototype.delete=A5;Mi.prototype.get=j5;Mi.prototype.has=O5;Mi.prototype.set=D5;function bc(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 R5(){this.__data__=[]}function L5(e){var n=this.__data__,t=Tp(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():T5.call(n,t,1),!0}function F5(e){var n=this.__data__,t=Tp(n,e);return t<0?void 0:n[t][1]}function N5(e){return Tp(this.__data__,e)>-1}function z5(e,n){var t=this.__data__,r=Tp(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}bc.prototype.clear=R5;bc.prototype.delete=L5;bc.prototype.get=F5;bc.prototype.has=N5;bc.prototype.set=z5;function Pc(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 B5(){this.__data__={hash:new Mi,map:new($5||bc),string:new Mi}}function U5(e){return $p(this,e).delete(e)}function H5(e){return $p(this,e).get(e)}function K5(e){return $p(this,e).has(e)}function W5(e,n){return $p(this,e).set(e,n),this}Pc.prototype.clear=B5;Pc.prototype.delete=U5;Pc.prototype.get=H5;Pc.prototype.has=K5;Pc.prototype.set=W5;function Of(e){var n=-1,t=e?e.length:0;for(this.__data__=new Pc;++n<t;)this.add(e[n])}function G5(e){return this.__data__.set(e,b0),this}function V5(e){return this.__data__.has(e)}Of.prototype.add=Of.prototype.push=G5;Of.prototype.has=V5;function Tp(e,n){for(var t=e.length;t--;)if(t6(e[t][0],n))return t;return-1}function Y5(e){if(!N_(e)||Q5(e))return!1;var n=n6(e)||C5(e)?k5:g5;return n.test(J5(e))}function X5(e,n,t){var r=-1,o=S5,s=e.length,i=!0,a=[],c=a;if(s>=u5){var l=q5(e);if(l)return R_(l);i=!1,o=b5,c=new Of}else c=a;e:for(;++r<s;){var u=e[r],d=u;if(u=u!==0?u:0,i&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue e;a.push(u)}else o(c,d,t)||(c!==a&&c.push(d),a.push(u))}return a}var q5=Qg&&1/R_(new Qg([,-0]))[1]==d5?function(e){return new Qg(e)}:r6;function $p(e,n){var t=e.__data__;return Z5(n)?t[typeof n=="string"?"string":"hash"]:t.map}function I0(e,n){var t=P5(e,n);return Y5(t)?t:void 0}function Z5(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function Q5(e){return!!Jb&&Jb in e}function J5(e){if(e!=null){try{return F_.call(e)}catch{}try{return e+""}catch{}}return""}function e6(e){return e&&e.length?X5(e):[]}function t6(e,n){return e===n||e!==e&&n!==n}function n6(e){var n=N_(e)?_5.call(e):"";return n==h5||n==f5}function N_(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function r6(){}var o6=e6;const s6=Ys(o6);function z_(e){return s6(e)}function i6(){const e=B(),n=rR("userIds",()=>z_(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 W(n)}function B_(e){const n=B();return W(`latestPresence:${e}`,()=>n.getCollaborators().find(r=>r.userId===e),[n])??null}const a6=ir(function(){const n=i6();return h.jsx(h.Fragment,{children:n.map(t=>h.jsx(c6,{collaboratorId:t},t))})}),c6=ir(function({collaboratorId:n}){const t=B(),r=B_(n),o=u6(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 h.jsx(l6,{latestPresence:r})}),l6=ir(function({latestPresence:n}){const t=B(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=ht(),c=t.getZoomLevel(),l=t.getViewportPageBounds(),{userId:u,chatMessage:d,brush:f,scribbles:p,selectedShapeIds:y,userName:m,cursor:w,color:S}=n,v=!(w.x<l.minX-12/c||w.y<l.minY-16/c||w.x>l.maxX-12/c||w.y>l.maxY-16/c);return h.jsxs(h.Fragment,{children:[f&&r?h.jsx(r,{className:"tl-collaborator__brush",brush:f,color:S,opacity:.1},u+"_brush"):null,v&&s?h.jsx(s,{className:"tl-collaborator__cursor",point:w,color:S,zoom:c,name:m!=="New User"?m:null,chatMessage:d},u+"_cursor"):i?h.jsx(i,{className:"tl-collaborator__cursor-hint",point:w,color:S,zoom:c,viewport:l},u+"_cursor_hint"):null,o&&p.length?h.jsx(h.Fragment,{children:p.map(P=>h.jsx(o,{className:"tl-collaborator__scribble",scribble:P,color:S,zoom:c,opacity:P.color==="laser"?.5:.1},u+"_scribble_"+P.id))}):null,a&&y.map(P=>h.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:P,color:S,opacity:.5},u+"_"+P))]})});function e1(e){return e>pL?"inactive":e>S_?"idle":"active"}function u6(e){const n=x.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[t,r]=x.useState(()=>e1(Date.now()-n.current));return x.useEffect(()=>{const o=setInterval(()=>{r(e1(Date.now()-n.current))},gL);return()=>clearInterval(o)},[]),e&&(n.current=e.lastActivityTimestamp),t}const U_=x.memo(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const c=B(),{ShapeErrorFallback:l}=ht(),u=x.useRef(null),d=x.useRef(null),f=x.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});$s("set shape stuff",()=>{const m=c.getShape(n);if(!m)return;const w=f.current,S=c.getShapeClipPath(n)??"none";S!==w.clipPath&&(Zt(u.current,"clip-path",S),Zt(d.current,"clip-path",S),w.clipPath=S);const v=c.getShapePageTransform(n),P=oe.toCssString(v),E=c.getShapeGeometry(m).bounds;P!==w.transform&&(Zt(u.current,"transform",P),Zt(d.current,"transform",P),w.transform=P);const C=E.w%a,I=E.h%a,_=C===0?E.w:E.w+(a-C),k=I===0?E.h:E.h+(a-I);(_!==w.width||k!==w.height)&&(Zt(u.current,"width",Math.max(_,a)+"px"),Zt(u.current,"height",Math.max(k,a)+"px"),Zt(d.current,"width",Math.max(_,a)+"px"),Zt(d.current,"height",Math.max(k,a)+"px"),w.width=_,w.height=k)},[c]),$s("set opacity and z-index",()=>{const m=u.current,w=d.current;Zt(m,"opacity",i),Zt(w,"opacity",i),Zt(m,"z-index",o),Zt(w,"z-index",s)},[i,o,s]),$s("set display",()=>{if(!c.getShape(n))return;const S=c.getCulledShapes().has(n);S!==f.current.isCulled&&(Zt(u.current,"display",S?"none":"block"),Zt(d.current,"display",S?"none":"block"),f.current.isCulled=S)},[c]);const p=x.useCallback(m=>c.annotateError(m,{origin:"shape",willCrashApp:!1}),[c]);if(!t)return null;const y="fill"in t.props&&t.props.fill!=="none";return h.jsxs(h.Fragment,{children:[r.backgroundComponent&&h.jsx("div",{ref:d,className:"tl-shape tl-shape-background","data-shape-type":t.type,draggable:!1,children:h.jsx(Kl,{fallback:l,onError:p,children:h.jsx(h6,{shape:t,util:r})})}),h.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":y,draggable:!1,children:h.jsx(Kl,{fallback:l,onError:p,children:h.jsx(d6,{shape:t,util:r})})})]})}),d6=x.memo(function({shape:n,util:t}){return bp("InnerShape:"+n.type,()=>t.component(n))},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta),h6=x.memo(function({shape:n,util:t}){return bp("InnerShape:"+n.type,()=>{var r;return(r=t.backgroundComponent)==null?void 0:r.call(t,n)})},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta);function f6({className:e}){const n=B(),{Background:t,SvgDefs:r}=ht(),o=x.useRef(null),s=x.useRef(null),i=x.useRef(null),a=dn();i5(o),$L(),kL(),RF(o),jL(o);const c=x.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});$s("position layers",function(){const{x:S,y:v,z:P}=n.getCamera();if(c.current.allowTextOutline&&n.environment.isSafari&&(a.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&P<Rb!==c.current.lodDisableTextOutline){const I=P<Rb;a.style.setProperty("--tl-text-outline",I?"none":`0 var(--b) 0 var(--color-background), 0 var(--a) 0 var(--color-background),
62
- var(--b) var(--b) 0 var(--color-background), var(--a) var(--b) 0 var(--color-background),
63
- var(--a) var(--a) 0 var(--color-background), var(--b) var(--a) 0 var(--color-background)`),c.current.lodDisableTextOutline=I}const E=P>=1?pf(P,[1,8],[.125,.5],!0):pf(P,[.1,1],[-2,.125],!0),C=`scale(${F(P)}) translate(${F(S+E)}px,${F(v+E)}px)`;Zt(s.current,"transform",C),Zt(i.current,"transform",C)},[n,a]);const l=_L(),u=W("shapeSvgDefs",()=>{const w=new Map;for(const S of yt(n.shapeUtils)){if(!S)return;const v=S.getCanvasSvgDefs();for(const{key:P,component:E}of v)w.has(P)||w.set(P,h.jsx(E,{},P))}return[...w.values()]},[n]),d=W("debug_shapes",()=>Pt.hideShapes.get(),[Pt]),f=W("debug_svg",()=>Pt.debugSvg.get(),[Pt]),p=W("debug_geometry",()=>Pt.debugGeometry.get(),[Pt]),y=W("isEditingAnything",()=>n.getEditingShapeId()!==null,[n]),m=W("isSelectingAnything",()=>!!n.getSelectedShapeIds().length,[n]);return h.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":y,"data-isselectinganything":m,className:ue("tl-canvas",e),"data-testid":"canvas",...l,children:[h.jsx("svg",{className:"tl-svg-context",children:h.jsxs("defs",{children:[u,h.jsx(_6,{}),h.jsx(k6,{}),r&&h.jsx(r,{})]})}),t&&h.jsx("div",{className:"tl-background__wrapper",children:h.jsx(t,{})}),h.jsx(p6,{}),h.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[h.jsx(A6,{}),h.jsx(M6,{}),d?null:f?h.jsx(b6,{}):h.jsx(C6,{})]}),h.jsx("div",{className:"tl-overlays",children:h.jsxs("div",{ref:i,className:"tl-html-layer",children:[p?h.jsx(l5,{}):null,h.jsx(v6,{}),h.jsx(m6,{}),h.jsx(g6,{}),h.jsx(y6,{}),h.jsx(I6,{}),h.jsx(E6,{}),h.jsx(S6,{}),h.jsx($6,{}),h.jsx(a6,{})]})}),h.jsx(j6,{})]})}function p6(){const e=B(),n=W("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=W("camera",()=>e.getCamera(),[e]),s=W("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=ht();return i&&s?h.jsx(i,{x:t,y:r,z:o,size:n}):null}function g6(){const e=B(),n=W("scribbles",()=>e.getInstanceState().scribbles,[e]),t=W("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=ht();return r&&n.length?h.jsx(h.Fragment,{children:n.map(o=>h.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:t},o.id))}):null}function m6(){const e=B(),n=W("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=ht();return t&&n?h.jsx(t,{className:"tl-user-brush",brush:n}):null}function y6(){const e=B(),n=W("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=ht();return t&&n?h.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function S6(){const e=B(),n=W("snapLines",()=>e.snaps.getIndicators(),[e]),t=W("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=ht();return r&&n.length>0?h.jsx(h.Fragment,{children:n.map(o=>h.jsx(r,{className:"tl-user-snapline",line:o,zoom:t},o.id))}):null}function v6(){const e=B(),n=W("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?h.jsx(x6,{shapeId:n}):null}function x6({shapeId:e}){const n=B(),{Handles:t}=ht(),r=W("zoomLevel",()=>n.getZoomLevel(),[n]),o=W("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),s=W("handles transform",()=>n.getShapePageTransform(e),[n,e]),i=W("handles",()=>{const a=n.getShapeHandles(e);if(!a)return null;const c=(o?v_:x_)/r*2;return a.filter(l=>l.type!=="virtual"||!a.some(u=>u!==l&&u.type==="vertex"&&b.Dist(l,u)<c)).sort(l=>l.type==="vertex"?1:-1)},[n,r,o,e]);return!t||!i||!s?null:h.jsx(t,{children:h.jsx("g",{transform:oe.toCssString(s),children:i.map(a=>h.jsx(w6,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function w6({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=LF(e,n.id),{Handle:s}=ht();return s?h.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:h.jsx(s,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function b6(){const e=B(),n=W("rendering shapes",()=>e.getRenderingShapes(),[e]),t=W("dpr multiple",()=>O_(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsx(h.Fragment,{children:n.map(r=>h.jsxs(x.Fragment,{children:[h.jsx(U_,{...r,dprMultiple:t}),h.jsx(T6,{id:r.id})]},r.id+"_fragment"))})}function P6(){const e=B(),n=x.useRef(new Set);return $s("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 C6(){const e=B(),n=W("rendering shapes",()=>e.getRenderingShapes(),[e]),t=W("dpr multiple",()=>O_(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsxs(h.Fragment,{children:[n.map(r=>h.jsx(U_,{...r,dprMultiple:t},r.id+"_shape")),e.environment.isSafari&&h.jsx(P6,{})]})}function I6(){const e=B(),n=W("rendering shapes",()=>e.getRenderingShapes(),[e]),t=x.useRef(new Set),r=W("should display selected ids",()=>{const s=t.current,i=new Set;if(e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!e.getInstanceState().isChangingStyle){const a=e.getSelectedShapeIds();for(const c of a)i.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const l=e.getHoveredShapeId();l&&i.add(l)}}}if(s.size!==i.size)return t.current=i,i;for(const a of i)if(!s.has(a))return t.current=i,i;return s},[e]),{ShapeIndicator:o}=ht();return o?h.jsx(h.Fragment,{children:n.map(({id:s})=>h.jsx(o,{shapeId:s,hidden:!r.has(s)},s+"_indicator"))}):null}function E6(){const e=B(),{ShapeIndicator:n}=ht(),t=W("hinting shape ids",()=>r0(e.getHintingShapeIds()),[e]);return!t.length||!n?null:h.jsx(h.Fragment,{children:t.map(r=>h.jsx(n,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))})}function _6(){return h.jsxs("g",{id:"cursor",children:[h.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),h.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function k6(){return h.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function T6({id:e}){const n=B(),[t,r]=x.useState(null),o=W("is in root",()=>{const s=n.getShape(e);return(s==null?void 0:s.parentId)===n.getCurrentPageId()},[n,e]);return x.useEffect(()=>{if(!o)return;let s=null;const i=Wi("shape to svg",async()=>{const a=Math.random();s=a;const l=n.isShapeOfType(e,"frame")?0:10;let u=n.getShapePageBounds(e);if(!u)return;u=u.clone().expandBy(l);const d=await n.getSvgString([e],{padding:l,background:n.getInstanceState().exportBackground});if(s!==a||!d)return;const f=`data:image/svg+xml;utf8,${encodeURIComponent(d.svg)}`;r({src:f,bounds:u})});return()=>{s=null,i()}},[n,e,o]),!o||!t?null:h.jsx("img",{src:t.src,width:t.bounds.width,height:t.bounds.height,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 $6(){const e=B(),n=W("selection rotation",()=>e.getSelectionRotation(),[e]),t=W("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=ht();return!t||!r?null:h.jsx(r,{bounds:t,rotation:n})}function M6(){const e=B(),n=W("selection rotation",()=>e.getSelectionRotation(),[e]),t=W("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=ht();return!t||!r?null:h.jsx(r,{bounds:t,rotation:n})}function A6(){const{OnTheCanvas:e}=ht();return e?h.jsx(e,{}):null}function j6(){const e=B(),n=W("camera state",()=>e.getCameraState(),[e]);return h.jsx("div",{className:ue("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":n==="idle"})})}function O6({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1}){const i=x.useRef(null);return wc(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,b.Angle(o.center,t)),h.jsxs("svg",{ref:i,className:ue("tl-overlays__item",e),children:[h.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),h.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const t1=x.memo(function({className:n,zoom:t,point:r,color:o,name:s,chatMessage:i}){const a=x.useRef(null);return wc(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t),r?h.jsxs("div",{ref:a,className:ue("tl-overlays__item",n),children:[h.jsx("svg",{className:"tl-cursor",children:h.jsx("use",{href:"#cursor",color:o})}),i?h.jsxs(h.Fragment,{children:[s&&h.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),h.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&h.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function D6({x:e,y:n,z:t,size:r}){return h.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("defs",{children:Ob.map(({min:o,mid:s,step:i},a)=>{const c=i*r*t,l=.5+e*t,u=.5+n*t,d=l>0?l%c:c+l%c,f=u>0?u%c:c+u%c,p=t<s?pf(t,[o,s],[0,1]):1;return h.jsx("pattern",{id:`grid-${i}`,width:c,height:c,patternUnits:"userSpaceOnUse",children:h.jsx("circle",{className:"tl-grid-dot",cx:d,cy:f,r:1,opacity:p})},`grid-pattern-${a}`)})}),Ob.map(({step:o},s)=>h.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${o})`},`grid-rect-${s}`))]})}function R6({handle:e,isCoarse:n,className:t,zoom:r}){const o=(n?v_:x_)/r;if(e.type==="clone"){const i=3/Math.max(r,.35),a=`M0,${-i} A${i},${i} 0 0,1 0,${i}`,c=xL.indexOf(e.id);return h.jsxs("g",{className:ue(`tl-handle tl-handle__${e.type}`,t),children:[h.jsx("circle",{className:"tl-handle__bg",r:o}),h.jsx("path",{className:"tl-handle__fg",d:a,transform:`rotate(${-90+90*c})`})]})}const s=(e.type==="create"&&n?3:4)/Math.max(r,.35);return h.jsxs("g",{className:ue(`tl-handle tl-handle__${e.type}`,t),children:[h.jsx("circle",{className:"tl-handle__bg",r:o}),h.jsx("circle",{className:"tl-handle__fg",r:s})]})}const L6=({children:e})=>h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e});function E0(e,n=!0){const t=e.length;if(t<2)return"";let r=e[0],o=e[1];if(t===2)return`M${Ee(r)}L${Ee(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i],o=e[i+1],s+=In(r,o);return n?`M${In(e[0],e[1])}Q${Ee(e[1])}${In(e[1],e[2])}T${s}${In(e[t-1],e[0])}${In(e[0],e[1])}Z`:`M${Ee(e[0])}Q${Ee(e[1])}${In(e[1],e[2])}${e.length>3?"T":""}${s}L${Ee(e[t-1])}`}function n1({scribble:e,zoom:n,color:t,opacity:r,className:o}){return e.points.length?h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:E0(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null}function H_({bounds:e,rotation:n}){const t=x.useRef(null);return wc(t,e.x,e.y,1,n),x.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=F(Math.max(1,e.width))+"px",r.style.height=F(Math.max(1,e.height))+"px")},[e.width,e.height]),h.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function F6({bounds:e,rotation:n}){const t=B(),r=x.useRef(null),o=W("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return wc(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(),h.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsx("rect",{className:ue("tl-selection__fg__outline"),width:F(e.width),height:F(e.height)})})}const N6=()=>h.jsx("div",{className:"tl-shape-error-boundary"}),z6=({shape:e,util:n})=>bp("Indicator: "+e.type,()=>n.indicator(e)),B6=({editor:e,id:n})=>{const t=W("shape for indicator",()=>e.store.get(n),[e,n]),{ShapeIndicatorErrorFallback:r}=ht();return!t||t.isLocked?null:h.jsx(Kl,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:h.jsx(z6,{shape:t,util:e.getShapeUtil(t)},t.id)})},r1=x.memo(function({shapeId:n,className:t,color:r,hidden:o,opacity:s}){const i=B(),a=x.useRef(null);return $s("indicator transform",()=>{const c=a.current;if(!c)return;const l=i.getShapePageTransform(n);l&&c.style.setProperty("transform",l.toCssString())},[i,n]),x.useLayoutEffect(()=>{const c=a.current;c&&c.style.setProperty("display",o?"none":"block")},[o]),h.jsx("svg",{ref:a,className:ue("tl-overlays__item",t),children:h.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:h.jsx(B6,{editor:i,id:n})})})}),U6=()=>h.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function H6({points:e,zoom:n}){const t=2.5/n,r=e.reduce((f,p)=>Math.min(f,p.x),1/0),o=e.reduce((f,p)=>Math.max(f,p.x),-1/0),s=e.reduce((f,p)=>Math.min(f,p.y),1/0),i=e.reduce((f,p)=>Math.max(f,p.y),-1/0),a=e.some(f=>f.x===r&&f.y===s);let c,l,u,d;return a?(c=r,l=s,u=o,d=i):(c=r,l=i,u=o,d=s),h.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[h.jsx("line",{x1:c,y1:l,x2:u,y2:d}),e.map((f,p)=>h.jsx("g",{transform:`translate(${f.x},${f.y})`,children:h.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},p))]})}function K6({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 c of e){if(s=jr(o[0],o[1],i?c.startEdge[0].y:c.startEdge[0].x,i?c.startEdge[1].y:c.startEdge[1].x),s)o=s;else continue;if(s=jr(o[0],o[1],i?c.endEdge[0].y:c.endEdge[0].x,i?c.endEdge[1].y:c.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return h.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:c,endEdge:l},u)=>h.jsx(x.Fragment,{children:i?h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),h.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),h.jsx("line",{x1:c[0].x,y1:a,x2:l[0].x,y2:a}),h.jsx("line",{x1:(c[0].x+l[0].x)/2,y1:a-r,x2:(c[0].x+l[0].x)/2,y2:a+r})]}):h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),h.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),h.jsx("line",{x1:a,y1:c[0].y,x2:a,y2:l[0].y}),h.jsx("line",{x1:a-r,y1:(c[0].y+l[0].y)/2,x2:a+r,y2:(c[0].y+l[0].y)/2})]})},u))})}function W6({className:e,line:n,zoom:t}){return h.jsx("svg",{className:ue("tl-overlays__item",e),children:n.type==="points"?h.jsx(H6,{...n,zoom:t}):n.type==="gaps"?h.jsx(K6,{...n,zoom:t}):null})}function G6(){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"var(--color-text-1)"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"var(--color-text-1)",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const V6=()=>null;function K_(e,n){const t=x.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Il(e){return K_(e,iR)}function _0(e){return K_(e,hE)}const W_=x.createContext(null);function Y6({overrides:e={},children:n}){const t=_0(e);return h.jsx(W_.Provider,{value:x.useMemo(()=>({Background:oL,SvgDefs:V6,Brush:dd,ZoomBrush:dd,ScreenshotBrush:dd,CollaboratorBrush:dd,Cursor:t1,CollaboratorCursor:t1,CollaboratorHint:O6,CollaboratorShapeIndicator:r1,Grid:D6,Scribble:n1,SnapIndicator:W6,Handles:L6,Handle:R6,CollaboratorScribble:n1,ErrorFallback:V_,ShapeErrorFallback:N6,ShapeIndicatorErrorFallback:U6,Spinner:G6,SelectionBackground:H_,SelectionForeground:F6,ShapeIndicator:r1,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:f6,...t}),[t]),children:n})}function ht(){const e=x.useContext(W_);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const k0={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 G_(){k0.hardReset()}function X6(){k0.refreshPage()}const q6="https://github.com/tldraw/tldraw/issues/new";function Z6(){}const V_=({error:e,editor:n})=>{const t=x.useRef(null),[r,o]=x.useState(!1),[s,i]=x.useState(!1),[a,c]=x.useState(!1);let l=null;try{l=ht().Canvas??null}catch{}const u=e instanceof Error?e.message:String(e),d=e instanceof Error?e.stack:null,f=W("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[p,y]=x.useState(null);x.useLayoutEffect(()=>{var C;f!==null&&y(f);let P=(C=t.current)==null?void 0:C.parentElement,E=!1;for(;P;){if(P.classList.contains("tl-theme__dark")||P.classList.contains("tl-theme__light")){E=!0;break}P=P.parentElement}if(E){y(null);return}y(window.matchMedia("(prefers-color-scheme: dark)").matches)},[f]),x.useEffect(()=>{if(s){const P=setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(P)}},[s]);const m=()=>{const P=document.createElement("textarea");P.value=d??u,document.body.appendChild(P),P.select(),document.execCommand("copy"),P.remove(),i(!0)},w=()=>{X6()},S=async()=>{G_()},v=new URL(q6);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
64
-
65
- \`\`\`js
66
- ${d??u}
67
- \`\`\`
68
-
69
- My browser: ${navigator.userAgent}`),h.jsxs("div",{ref:t,className:ue("tl-container tl-error-boundary",p===null?"":p?"tl-theme__dark":"tl-theme__light"),children:[h.jsx("div",{className:"tl-error-boundary__overlay"}),n&&h.jsx(h_,{onError:Z6,fallback:()=>null,children:h.jsx(kp.Provider,{value:n,children:h.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:l?h.jsx(l,{}):null})})}),h.jsx("div",{className:ue("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Are you sure?"}),h.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>c(!1),children:"Cancel"}),h.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Something's gone wrong."}),h.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",h.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",h.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&h.jsxs(h.Fragment,{children:["Message:",h.jsx("h4",{children:h.jsx("code",{children:u})}),"Stack trace:",h.jsxs("div",{className:"tl-error-boundary__content__error",children:[h.jsx("pre",{children:h.jsx("code",{children:d??u})}),h.jsx("button",{onClick:m,children:s?"Copied!":"Copy"})]})]}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),h.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[h.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>c(!0),children:"Reset data"}),h.jsx("button",{className:"tl-error-boundary__refresh",onClick:w,children:"Refresh Page"})]})]})]})})]})};function ot(){return Eu()}const Y_="TLDRAW_USER_DATA_v3",X_=ve({id:pe,name:pe.nullable().optional(),locale:pe.nullable().optional(),color:pe.nullable().optional(),isDarkMode:we.nullable().optional(),animationSpeed:fe.nullable().optional(),edgeScrollSpeed:fe.nullable().optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional()}),ma={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5},T0=Math.max(...Object.values(ma));function Q6(e){e.version<ma.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<ma.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<ma.MakeFieldsNullable,e.version<ma.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<ma.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version=T0}const o1=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function J6(){return o1[Math.floor(Math.random()*o1.length)]}function eN(){var e,n;return typeof window>"u"?!1:((n=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-color-scheme: dark)"))==null?void 0:n.matches)??!1}function tN(){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 fi=Object.freeze({name:"New User",locale:J3(),color:J6(),isDarkMode:!1,edgeScrollSpeed:1,animationSpeed:tN()?0:1,isSnapMode:!1,isWrapMode:!1});function Jg(){return{id:ot()}}function q_(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return Jg();const n=xt(e);Q6(n);try{return X_.validate(n.user)}catch{return Jg()}}function nN(){const e=JSON.parse(a0(Y_)||"null")??null;return q_(e)}const Gl=on("globalUserData",null);function rN(){c0(Y_,JSON.stringify({version:T0,user:Gl.get()}))}function oN(e){X_.validate(e),Gl.set(e),rN(),iN()}const sN=typeof process<"u"&&!1,Ka=typeof BroadcastChannel<"u"&&!sN?new BroadcastChannel("tldraw-user-sync"):null;Ka==null||Ka.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===Q_&&(n==null?void 0:n.origin)!==Z_()&&Gl.set(q_(n.data))});let em=null;function Z_(){return em===null&&(em=ot()),em}const Q_="tldraw-user-preferences-change";function iN(){Ka==null||Ka.postMessage({type:Q_,origin:Z_(),data:{user:J_(),version:T0}})}function J_(){let e=Gl.get();return e||(e=nN(),Gl.set(e)),e}function ek(e={}){return{derivePresenceState:e.derivePresenceState??(()=>G("presence",()=>null)),userPreferences:e.userPreferences??G("userPreferences",()=>J_()),setUserPreferences:e.setUserPreferences??oN}}var tk={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(c,l,u){this.fn=c,this.context=l,this.once=u||!1}function s(c,l,u,d,f){if(typeof u!="function")throw new TypeError("The listener must be a function");var p=new o(u,d||c,f),y=t?t+l:l;return c._events[y]?c._events[y].fn?c._events[y]=[c._events[y],p]:c._events[y].push(p):(c._events[y]=p,c._eventsCount++),c}function i(c,l){--c._eventsCount===0?c._events=new r:delete c._events[l]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],u,d;if(this._eventsCount===0)return l;for(d in u=this._events)n.call(u,d)&&l.push(t?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(u)):l},a.prototype.listeners=function(l){var u=t?t+l:l,d=this._events[u];if(!d)return[];if(d.fn)return[d.fn];for(var f=0,p=d.length,y=new Array(p);f<p;f++)y[f]=d[f].fn;return y},a.prototype.listenerCount=function(l){var u=t?t+l:l,d=this._events[u];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,u,d,f,p,y){var m=t?t+l:l;if(!this._events[m])return!1;var w=this._events[m],S=arguments.length,v,P;if(w.fn){switch(w.once&&this.removeListener(l,w.fn,void 0,!0),S){case 1:return w.fn.call(w.context),!0;case 2:return w.fn.call(w.context,u),!0;case 3:return w.fn.call(w.context,u,d),!0;case 4:return w.fn.call(w.context,u,d,f),!0;case 5:return w.fn.call(w.context,u,d,f,p),!0;case 6:return w.fn.call(w.context,u,d,f,p,y),!0}for(P=1,v=new Array(S-1);P<S;P++)v[P-1]=arguments[P];w.fn.apply(w.context,v)}else{var E=w.length,C;for(P=0;P<E;P++)switch(w[P].once&&this.removeListener(l,w[P].fn,void 0,!0),S){case 1:w[P].fn.call(w[P].context);break;case 2:w[P].fn.call(w[P].context,u);break;case 3:w[P].fn.call(w[P].context,u,d);break;case 4:w[P].fn.call(w[P].context,u,d,f);break;default:if(!v)for(C=1,v=new Array(S-1);C<S;C++)v[C-1]=arguments[C];w[P].fn.apply(w[P].context,v)}}return!0},a.prototype.on=function(l,u,d){return s(this,l,u,d,!1)},a.prototype.once=function(l,u,d){return s(this,l,u,d,!0)},a.prototype.removeListener=function(l,u,d,f){var p=t?t+l:l;if(!this._events[p])return this;if(!u)return i(this,p),this;var y=this._events[p];if(y.fn)y.fn===u&&(!f||y.once)&&(!d||y.context===d)&&i(this,p);else{for(var m=0,w=[],S=y.length;m<S;m++)(y[m].fn!==u||f&&!y[m].once||d&&y[m].context!==d)&&w.push(y[m]);w.length?this._events[p]=w.length===1?w[0]:w:i(this,p)}return this},a.prototype.removeAllListeners=function(l){var u;return l?(u=t?t+l:l,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,e.exports=a})(tk);var aN=tk.exports;const cN=Ys(aN);var nk={exports:{}},cr={},rk={exports:{}},ok={};/**
70
- * @license React
71
- * scheduler.production.min.js
72
- *
73
- * Copyright (c) Facebook, Inc. and its affiliates.
74
- *
75
- * This source code is licensed under the MIT license found in the
76
- * LICENSE file in the root directory of this source tree.
77
- */(function(e){function n(H,U){var K=H.length;H.push(U);e:for(;0<K;){var Z=K-1>>>1,le=H[Z];if(0<o(le,U))H[Z]=U,H[K]=le,K=Z;else break e}}function t(H){return H.length===0?null:H[0]}function r(H){if(H.length===0)return null;var U=H[0],K=H.pop();if(K!==U){H[0]=K;e:for(var Z=0,le=H.length,be=le>>>1;Z<be;){var Ae=2*(Z+1)-1,ae=H[Ae],je=Ae+1,Le=H[je];if(0>o(ae,K))je<le&&0>o(Le,ae)?(H[Z]=Le,H[je]=K,Z=je):(H[Z]=ae,H[Ae]=K,Z=Ae);else if(je<le&&0>o(Le,K))H[Z]=Le,H[je]=K,Z=je;else break e}}return U}function o(H,U){var K=H.sortIndex-U.sortIndex;return K!==0?K:H.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var c=[],l=[],u=1,d=null,f=3,p=!1,y=!1,m=!1,w=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function P(H){for(var U=t(l);U!==null;){if(U.callback===null)r(l);else if(U.startTime<=H)r(l),U.sortIndex=U.expirationTime,n(c,U);else break;U=t(l)}}function E(H){if(m=!1,P(H),!y)if(t(c)!==null)y=!0,X(C);else{var U=t(l);U!==null&&V(E,U.startTime-H)}}function C(H,U){y=!1,m&&(m=!1,S(k),k=-1),p=!0;var K=f;try{for(P(U),d=t(c);d!==null&&(!(d.expirationTime>U)||H&&!O());){var Z=d.callback;if(typeof Z=="function"){d.callback=null,f=d.priorityLevel;var le=Z(d.expirationTime<=U);U=e.unstable_now(),typeof le=="function"?d.callback=le:d===t(c)&&r(c),P(U)}else r(c);d=t(c)}if(d!==null)var be=!0;else{var Ae=t(l);Ae!==null&&V(E,Ae.startTime-U),be=!1}return be}finally{d=null,f=K,p=!1}}var I=!1,_=null,k=-1,$=5,T=-1;function O(){return!(e.unstable_now()-T<$)}function N(){if(_!==null){var H=e.unstable_now();T=H;var U=!0;try{U=_(!0,H)}finally{U?A():(I=!1,_=null)}}else I=!1}var A;if(typeof v=="function")A=function(){v(N)};else if(typeof MessageChannel<"u"){var j=new MessageChannel,L=j.port2;j.port1.onmessage=N,A=function(){L.postMessage(null)}}else A=function(){w(N,0)};function X(H){_=H,I||(I=!0,A())}function V(H,U){k=w(function(){H(e.unstable_now())},U)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(H){H.callback=null},e.unstable_continueExecution=function(){y||p||(y=!0,X(C))},e.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<H?Math.floor(1e3/H):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_getFirstCallbackNode=function(){return t(c)},e.unstable_next=function(H){switch(f){case 1:case 2:case 3:var U=3;break;default:U=f}var K=f;f=U;try{return H()}finally{f=K}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(H,U){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var K=f;f=H;try{return U()}finally{f=K}},e.unstable_scheduleCallback=function(H,U,K){var Z=e.unstable_now();switch(typeof K=="object"&&K!==null?(K=K.delay,K=typeof K=="number"&&0<K?Z+K:Z):K=Z,H){case 1:var le=-1;break;case 2:le=250;break;case 5:le=1073741823;break;case 4:le=1e4;break;default:le=5e3}return le=K+le,H={id:u++,callback:U,priorityLevel:H,startTime:K,expirationTime:le,sortIndex:-1},K>Z?(H.sortIndex=K,n(l,H),t(c)===null&&H===t(l)&&(m?(S(k),k=-1):m=!0,V(E,K-Z))):(H.sortIndex=le,n(c,H),y||p||(y=!0,X(C))),H},e.unstable_shouldYield=O,e.unstable_wrapCallback=function(H){var U=f;return function(){var K=f;f=U;try{return H.apply(this,arguments)}finally{f=K}}}})(ok);rk.exports=ok;var lN=rk.exports;/**
78
- * @license React
79
- * react-dom.production.min.js
80
- *
81
- * Copyright (c) Facebook, Inc. and its affiliates.
82
- *
83
- * This source code is licensed under the MIT license found in the
84
- * LICENSE file in the root directory of this source tree.
85
- */var uN=x,sr=lN;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 sk=new Set,Vl={};function Gi(e,n){sc(e,n),sc(e+"Capture",n)}function sc(e,n){for(Vl[e]=n,e=0;e<n.length;e++)sk.add(n[e])}var Yo=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),aS=Object.prototype.hasOwnProperty,dN=/^[: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]*$/,s1={},i1={};function hN(e){return aS.call(i1,e)?!0:aS.call(s1,e)?!1:dN.test(e)?i1[e]=!0:(s1[e]=!0,!1)}function fN(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 pN(e,n,t,r){if(n===null||typeof n>"u"||fN(e,n,t,r))return!0;if(r)return!1;if(t!==null)switch(t.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function Sn(e,n,t,r,o,s,i){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=t,this.propertyName=e,this.type=n,this.sanitizeURL=s,this.removeEmptyString=i}var Gt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Gt[e]=new Sn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Gt[n]=new Sn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Gt[e]=new Sn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Gt[e]=new Sn(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){Gt[e]=new Sn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Gt[e]=new Sn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Gt[e]=new Sn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Gt[e]=new Sn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Gt[e]=new Sn(e,5,!1,e.toLowerCase(),null,!1,!1)});var $0=/[\-:]([a-z])/g;function M0(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($0,M0);Gt[n]=new Sn(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace($0,M0);Gt[n]=new Sn(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace($0,M0);Gt[n]=new Sn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Gt[e]=new Sn(e,1,!1,e.toLowerCase(),null,!1,!1)});Gt.xlinkHref=new Sn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Gt[e]=new Sn(e,1,!1,e.toLowerCase(),null,!0,!0)});function A0(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")&&(pN(n,t,o,r)&&(t=null),r||o===null?hN(n)&&(t===null?e.removeAttribute(n):e.setAttribute(n,""+t)):o.mustUseProperty?e[o.propertyName]=t===null?o.type===3?!1:"":t:(n=o.attributeName,r=o.attributeNamespace,t===null?e.removeAttribute(n):(o=o.type,t=o===3||o===4&&t===!0?"":""+t,r?e.setAttributeNS(r,n,t):e.setAttribute(n,t))))}var ns=uN.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,pd=Symbol.for("react.element"),ba=Symbol.for("react.portal"),Pa=Symbol.for("react.fragment"),j0=Symbol.for("react.strict_mode"),cS=Symbol.for("react.profiler"),ik=Symbol.for("react.provider"),ak=Symbol.for("react.context"),O0=Symbol.for("react.forward_ref"),lS=Symbol.for("react.suspense"),uS=Symbol.for("react.suspense_list"),D0=Symbol.for("react.memo"),vs=Symbol.for("react.lazy"),ck=Symbol.for("react.offscreen"),a1=Symbol.iterator;function Gc(e){return e===null||typeof e!="object"?null:(e=a1&&e[a1]||e["@@iterator"],typeof e=="function"?e:null)}var ft=Object.assign,tm;function ml(e){if(tm===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);tm=n&&n[1]||""}return`
86
- `+tm+e}var nm=!1;function rm(e,n){if(!e||nm)return"";nm=!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(l){var r=l}Reflect.construct(e,[],n)}else{try{n.call()}catch(l){r=l}e.call(n.prototype)}else{try{throw Error()}catch(l){r=l}e()}}catch(l){if(l&&r&&typeof l.stack=="string"){for(var o=l.stack.split(`
87
- `),s=r.stack.split(`
88
- `),i=o.length-1,a=s.length-1;1<=i&&0<=a&&o[i]!==s[a];)a--;for(;1<=i&&0<=a;i--,a--)if(o[i]!==s[a]){if(i!==1||a!==1)do if(i--,a--,0>a||o[i]!==s[a]){var c=`
89
- `+o[i].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=i&&0<=a);break}}}finally{nm=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?ml(e):""}function gN(e){switch(e.tag){case 5:return ml(e.type);case 16:return ml("Lazy");case 13:return ml("Suspense");case 19:return ml("SuspenseList");case 0:case 2:case 15:return e=rm(e.type,!1),e;case 11:return e=rm(e.type.render,!1),e;case 1:return e=rm(e.type,!0),e;default:return""}}function dS(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 Pa:return"Fragment";case ba:return"Portal";case cS:return"Profiler";case j0:return"StrictMode";case lS:return"Suspense";case uS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case ak:return(e.displayName||"Context")+".Consumer";case ik:return(e._context.displayName||"Context")+".Provider";case O0:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case D0:return n=e.displayName||null,n!==null?n:dS(e.type)||"Memo";case vs:n=e._payload,e=e._init;try{return dS(e(n))}catch{}}return null}function mN(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 dS(n);case 8:return n===j0?"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 Us(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function lk(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function yN(e){var n=lk(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 gd(e){e._valueTracker||(e._valueTracker=yN(e))}function uk(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=lk(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function Df(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 hS(e,n){var t=n.checked;return ft({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function c1(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Us(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 dk(e,n){n=n.checked,n!=null&&A0(e,"checked",n,!1)}function fS(e,n){dk(e,n);var t=Us(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")?pS(e,n.type,t):n.hasOwnProperty("defaultValue")&&pS(e,n.type,Us(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function l1(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 pS(e,n,t){(n!=="number"||Df(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var yl=Array.isArray;function Wa(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=""+Us(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 gS(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return ft({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function u1(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(yl(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Us(t)}}function hk(e,n){var t=Us(n.value),r=Us(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 d1(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function fk(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 mS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?fk(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var md,pk=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(md=md||document.createElement("div"),md.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=md.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Yl(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var El={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},SN=["Webkit","ms","Moz","O"];Object.keys(El).forEach(function(e){SN.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),El[n]=El[e]})});function gk(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||El.hasOwnProperty(e)&&El[e]?(""+n).trim():n+"px"}function mk(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=gk(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var vN=ft({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 yS(e,n){if(n){if(vN[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 SS(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 vS=null;function R0(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var xS=null,Ga=null,Va=null;function h1(e){if(e=Du(e)){if(typeof xS!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Dp(n),xS(e.stateNode,e.type,n))}}function yk(e){Ga?Va?Va.push(e):Va=[e]:Ga=e}function Sk(){if(Ga){var e=Ga,n=Va;if(Va=Ga=null,h1(e),n)for(e=0;e<n.length;e++)h1(n[e])}}function vk(e,n){return e(n)}function xk(){}var om=!1;function wk(e,n,t){if(om)return e(n,t);om=!0;try{return vk(e,n,t)}finally{om=!1,(Ga!==null||Va!==null)&&(xk(),Sk())}}function Xl(e,n){var t=e.stateNode;if(t===null)return null;var r=Dp(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 wS=!1;if(Yo)try{var Vc={};Object.defineProperty(Vc,"passive",{get:function(){wS=!0}}),window.addEventListener("test",Vc,Vc),window.removeEventListener("test",Vc,Vc)}catch{wS=!1}function xN(e,n,t,r,o,s,i,a,c){var l=Array.prototype.slice.call(arguments,3);try{n.apply(t,l)}catch(u){this.onError(u)}}var _l=!1,Rf=null,Lf=!1,bS=null,wN={onError:function(e){_l=!0,Rf=e}};function bN(e,n,t,r,o,s,i,a,c){_l=!1,Rf=null,xN.apply(wN,arguments)}function PN(e,n,t,r,o,s,i,a,c){if(bN.apply(this,arguments),_l){if(_l){var l=Rf;_l=!1,Rf=null}else throw Error(q(198));Lf||(Lf=!0,bS=l)}}function Vi(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 bk(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 f1(e){if(Vi(e)!==e)throw Error(q(188))}function CN(e){var n=e.alternate;if(!n){if(n=Vi(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 f1(o),e;if(s===r)return f1(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 Pk(e){return e=CN(e),e!==null?Ck(e):null}function Ck(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=Ck(e);if(n!==null)return n;e=e.sibling}return null}var Ik=sr.unstable_scheduleCallback,p1=sr.unstable_cancelCallback,IN=sr.unstable_shouldYield,EN=sr.unstable_requestPaint,Ct=sr.unstable_now,_N=sr.unstable_getCurrentPriorityLevel,L0=sr.unstable_ImmediatePriority,Ek=sr.unstable_UserBlockingPriority,Ff=sr.unstable_NormalPriority,kN=sr.unstable_LowPriority,_k=sr.unstable_IdlePriority,Mp=null,lo=null;function TN(e){if(lo&&typeof lo.onCommitFiberRoot=="function")try{lo.onCommitFiberRoot(Mp,e,void 0,(e.current.flags&128)===128)}catch{}}var Nr=Math.clz32?Math.clz32:AN,$N=Math.log,MN=Math.LN2;function AN(e){return e>>>=0,e===0?32:31-($N(e)/MN|0)|0}var yd=64,Sd=4194304;function Sl(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 Nf(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=Sl(a):(s&=i,s!==0&&(r=Sl(s)))}else i=t&~o,i!==0?r=Sl(i):s!==0&&(r=Sl(s));if(r===0)return 0;if(n!==0&&n!==r&&!(n&o)&&(o=r&-r,s=n&-n,o>=s||o===16&&(s&4194240)!==0))return n;if(r&4&&(r|=t&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=r;0<n;)t=31-Nr(n),o=1<<t,r|=e[t],n&=~o;return r}function jN(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 ON(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-Nr(s),a=1<<i,c=o[i];c===-1?(!(a&t)||a&r)&&(o[i]=jN(a,n)):c<=n&&(e.expiredLanes|=a),s&=~a}}function PS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function kk(){var e=yd;return yd<<=1,!(yd&4194240)&&(yd=64),e}function sm(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function ju(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Nr(n),e[n]=t}function DN(e,n){var t=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<t;){var o=31-Nr(t),s=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~s}}function F0(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-Nr(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var Ne=0;function Tk(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var $k,N0,Mk,Ak,jk,CS=!1,vd=[],As=null,js=null,Os=null,ql=new Map,Zl=new Map,bs=[],RN="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 g1(e,n){switch(e){case"focusin":case"focusout":As=null;break;case"dragenter":case"dragleave":js=null;break;case"mouseover":case"mouseout":Os=null;break;case"pointerover":case"pointerout":ql.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Zl.delete(n.pointerId)}}function Yc(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=Du(n),n!==null&&N0(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function LN(e,n,t,r,o){switch(n){case"focusin":return As=Yc(As,e,n,t,r,o),!0;case"dragenter":return js=Yc(js,e,n,t,r,o),!0;case"mouseover":return Os=Yc(Os,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return ql.set(s,Yc(ql.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,Zl.set(s,Yc(Zl.get(s)||null,e,n,t,r,o)),!0}return!1}function Ok(e){var n=Si(e.target);if(n!==null){var t=Vi(n);if(t!==null){if(n=t.tag,n===13){if(n=bk(t),n!==null){e.blockedOn=n,jk(e.priority,function(){Mk(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=IS(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);vS=r,t.target.dispatchEvent(r),vS=null}else return n=Du(t),n!==null&&N0(n),e.blockedOn=t,!1;n.shift()}return!0}function m1(e,n,t){ph(e)&&t.delete(n)}function FN(){CS=!1,As!==null&&ph(As)&&(As=null),js!==null&&ph(js)&&(js=null),Os!==null&&ph(Os)&&(Os=null),ql.forEach(m1),Zl.forEach(m1)}function Xc(e,n){e.blockedOn===n&&(e.blockedOn=null,CS||(CS=!0,sr.unstable_scheduleCallback(sr.unstable_NormalPriority,FN)))}function Ql(e){function n(o){return Xc(o,e)}if(0<vd.length){Xc(vd[0],e);for(var t=1;t<vd.length;t++){var r=vd[t];r.blockedOn===e&&(r.blockedOn=null)}}for(As!==null&&Xc(As,e),js!==null&&Xc(js,e),Os!==null&&Xc(Os,e),ql.forEach(n),Zl.forEach(n),t=0;t<bs.length;t++)r=bs[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<bs.length&&(t=bs[0],t.blockedOn===null);)Ok(t),t.blockedOn===null&&bs.shift()}var Ya=ns.ReactCurrentBatchConfig,zf=!0;function NN(e,n,t,r){var o=Ne,s=Ya.transition;Ya.transition=null;try{Ne=1,z0(e,n,t,r)}finally{Ne=o,Ya.transition=s}}function zN(e,n,t,r){var o=Ne,s=Ya.transition;Ya.transition=null;try{Ne=4,z0(e,n,t,r)}finally{Ne=o,Ya.transition=s}}function z0(e,n,t,r){if(zf){var o=IS(e,n,t,r);if(o===null)gm(e,n,r,Bf,t),g1(e,r);else if(LN(o,e,n,t,r))r.stopPropagation();else if(g1(e,r),n&4&&-1<RN.indexOf(e)){for(;o!==null;){var s=Du(o);if(s!==null&&$k(s),s=IS(e,n,t,r),s===null&&gm(e,n,r,Bf,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else gm(e,n,r,null,t)}}var Bf=null;function IS(e,n,t,r){if(Bf=null,e=R0(r),e=Si(e),e!==null)if(n=Vi(e),n===null)e=null;else if(t=n.tag,t===13){if(e=bk(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 Bf=e,null}function Dk(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(_N()){case L0:return 1;case Ek:return 4;case Ff:case kN:return 16;case _k:return 536870912;default:return 16}default:return 16}}var Is=null,B0=null,gh=null;function Rk(){if(gh)return gh;var e,n=B0,t=n.length,r,o="value"in Is?Is.value:Is.textContent,s=o.length;for(e=0;e<t&&n[e]===o[e];e++);var i=t-e;for(r=1;r<=i&&n[t-r]===o[s-r];r++);return gh=o.slice(e,1<r?1-r:void 0)}function mh(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function xd(){return!0}function y1(){return!1}function lr(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)?xd:y1,this.isPropagationStopped=y1,this}return ft(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=xd)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=xd)},persist:function(){},isPersistent:xd}),n}var Cc={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},U0=lr(Cc),Ou=ft({},Cc,{view:0,detail:0}),BN=lr(Ou),im,am,qc,Ap=ft({},Ou,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:H0,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!==qc&&(qc&&e.type==="mousemove"?(im=e.screenX-qc.screenX,am=e.screenY-qc.screenY):am=im=0,qc=e),im)},movementY:function(e){return"movementY"in e?e.movementY:am}}),S1=lr(Ap),UN=ft({},Ap,{dataTransfer:0}),HN=lr(UN),KN=ft({},Ou,{relatedTarget:0}),cm=lr(KN),WN=ft({},Cc,{animationName:0,elapsedTime:0,pseudoElement:0}),GN=lr(WN),VN=ft({},Cc,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),YN=lr(VN),XN=ft({},Cc,{data:0}),v1=lr(XN),qN={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},ZN={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"},QN={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function JN(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=QN[e])?!!n[e]:!1}function H0(){return JN}var e4=ft({},Ou,{key:function(e){if(e.key){var n=qN[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=mh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?ZN[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:H0,charCode:function(e){return e.type==="keypress"?mh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?mh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),t4=lr(e4),n4=ft({},Ap,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),x1=lr(n4),r4=ft({},Ou,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:H0}),o4=lr(r4),s4=ft({},Cc,{propertyName:0,elapsedTime:0,pseudoElement:0}),i4=lr(s4),a4=ft({},Ap,{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}),c4=lr(a4),l4=[9,13,27,32],K0=Yo&&"CompositionEvent"in window,kl=null;Yo&&"documentMode"in document&&(kl=document.documentMode);var u4=Yo&&"TextEvent"in window&&!kl,Lk=Yo&&(!K0||kl&&8<kl&&11>=kl),w1=" ",b1=!1;function Fk(e,n){switch(e){case"keyup":return l4.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Nk(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Ca=!1;function d4(e,n){switch(e){case"compositionend":return Nk(n);case"keypress":return n.which!==32?null:(b1=!0,w1);case"textInput":return e=n.data,e===w1&&b1?null:e;default:return null}}function h4(e,n){if(Ca)return e==="compositionend"||!K0&&Fk(e,n)?(e=Rk(),gh=B0=Is=null,Ca=!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 Lk&&n.locale!=="ko"?null:n.data;default:return null}}var f4={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 P1(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!f4[e.type]:n==="textarea"}function zk(e,n,t,r){yk(r),n=Uf(n,"onChange"),0<n.length&&(t=new U0("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var Tl=null,Jl=null;function p4(e){Zk(e,0)}function jp(e){var n=_a(e);if(uk(n))return e}function g4(e,n){if(e==="change")return n}var Bk=!1;if(Yo){var lm;if(Yo){var um="oninput"in document;if(!um){var C1=document.createElement("div");C1.setAttribute("oninput","return;"),um=typeof C1.oninput=="function"}lm=um}else lm=!1;Bk=lm&&(!document.documentMode||9<document.documentMode)}function I1(){Tl&&(Tl.detachEvent("onpropertychange",Uk),Jl=Tl=null)}function Uk(e){if(e.propertyName==="value"&&jp(Jl)){var n=[];zk(n,Jl,e,R0(e)),wk(p4,n)}}function m4(e,n,t){e==="focusin"?(I1(),Tl=n,Jl=t,Tl.attachEvent("onpropertychange",Uk)):e==="focusout"&&I1()}function y4(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return jp(Jl)}function S4(e,n){if(e==="click")return jp(n)}function v4(e,n){if(e==="input"||e==="change")return jp(n)}function x4(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Kr=typeof Object.is=="function"?Object.is:x4;function eu(e,n){if(Kr(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(!aS.call(n,o)||!Kr(e[o],n[o]))return!1}return!0}function E1(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function _1(e,n){var t=E1(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=E1(t)}}function Hk(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?Hk(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function Kk(){for(var e=window,n=Df();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=Df(e.document)}return n}function W0(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 w4(e){var n=Kk(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&Hk(t.ownerDocument.documentElement,t)){if(r!==null&&W0(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=_1(t,s);var i=_1(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 b4=Yo&&"documentMode"in document&&11>=document.documentMode,Ia=null,ES=null,$l=null,_S=!1;function k1(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;_S||Ia==null||Ia!==Df(r)||(r=Ia,"selectionStart"in r&&W0(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}),$l&&eu($l,r)||($l=r,r=Uf(ES,"onSelect"),0<r.length&&(n=new U0("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=Ia)))}function wd(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var Ea={animationend:wd("Animation","AnimationEnd"),animationiteration:wd("Animation","AnimationIteration"),animationstart:wd("Animation","AnimationStart"),transitionend:wd("Transition","TransitionEnd")},dm={},Wk={};Yo&&(Wk=document.createElement("div").style,"AnimationEvent"in window||(delete Ea.animationend.animation,delete Ea.animationiteration.animation,delete Ea.animationstart.animation),"TransitionEvent"in window||delete Ea.transitionend.transition);function Op(e){if(dm[e])return dm[e];if(!Ea[e])return e;var n=Ea[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in Wk)return dm[e]=n[t];return e}var Gk=Op("animationend"),Vk=Op("animationiteration"),Yk=Op("animationstart"),Xk=Op("transitionend"),qk=new Map,T1="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function Zs(e,n){qk.set(e,n),Gi(n,[e])}for(var hm=0;hm<T1.length;hm++){var fm=T1[hm],P4=fm.toLowerCase(),C4=fm[0].toUpperCase()+fm.slice(1);Zs(P4,"on"+C4)}Zs(Gk,"onAnimationEnd");Zs(Vk,"onAnimationIteration");Zs(Yk,"onAnimationStart");Zs("dblclick","onDoubleClick");Zs("focusin","onFocus");Zs("focusout","onBlur");Zs(Xk,"onTransitionEnd");sc("onMouseEnter",["mouseout","mouseover"]);sc("onMouseLeave",["mouseout","mouseover"]);sc("onPointerEnter",["pointerout","pointerover"]);sc("onPointerLeave",["pointerout","pointerover"]);Gi("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Gi("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Gi("onBeforeInput",["compositionend","keypress","textInput","paste"]);Gi("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Gi("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Gi("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var vl="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(" "),I4=new Set("cancel close invalid load scroll toggle".split(" ").concat(vl));function $1(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,PN(r,n,void 0,e),e.currentTarget=null}function Zk(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],c=a.instance,l=a.currentTarget;if(a=a.listener,c!==s&&o.isPropagationStopped())break e;$1(o,a,l),s=c}else for(i=0;i<r.length;i++){if(a=r[i],c=a.instance,l=a.currentTarget,a=a.listener,c!==s&&o.isPropagationStopped())break e;$1(o,a,l),s=c}}}if(Lf)throw e=bS,Lf=!1,bS=null,e}function Je(e,n){var t=n[AS];t===void 0&&(t=n[AS]=new Set);var r=e+"__bubble";t.has(r)||(Qk(n,e,2,!1),t.add(r))}function pm(e,n,t){var r=0;n&&(r|=4),Qk(t,e,r,n)}var bd="_reactListening"+Math.random().toString(36).slice(2);function tu(e){if(!e[bd]){e[bd]=!0,sk.forEach(function(t){t!=="selectionchange"&&(I4.has(t)||pm(t,!1,e),pm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[bd]||(n[bd]=!0,pm("selectionchange",!1,n))}}function Qk(e,n,t,r){switch(Dk(n)){case 1:var o=NN;break;case 4:o=zN;break;default:o=z0}t=o.bind(null,n,t,e),o=void 0,!wS||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 gm(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 c=i.tag;if((c===3||c===4)&&(c=i.stateNode.containerInfo,c===o||c.nodeType===8&&c.parentNode===o))return;i=i.return}for(;a!==null;){if(i=Si(a),i===null)return;if(c=i.tag,c===5||c===6){r=s=i;continue e}a=a.parentNode}}r=r.return}wk(function(){var l=s,u=R0(t),d=[];e:{var f=qk.get(e);if(f!==void 0){var p=U0,y=e;switch(e){case"keypress":if(mh(t)===0)break e;case"keydown":case"keyup":p=t4;break;case"focusin":y="focus",p=cm;break;case"focusout":y="blur",p=cm;break;case"beforeblur":case"afterblur":p=cm;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":p=S1;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=HN;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=o4;break;case Gk:case Vk:case Yk:p=GN;break;case Xk:p=i4;break;case"scroll":p=BN;break;case"wheel":p=c4;break;case"copy":case"cut":case"paste":p=YN;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=x1}var m=(n&4)!==0,w=!m&&e==="scroll",S=m?f!==null?f+"Capture":null:f;m=[];for(var v=l,P;v!==null;){P=v;var E=P.stateNode;if(P.tag===5&&E!==null&&(P=E,S!==null&&(E=Xl(v,S),E!=null&&m.push(nu(v,E,P)))),w)break;v=v.return}0<m.length&&(f=new p(f,y,null,t,u),d.push({event:f,listeners:m}))}}if(!(n&7)){e:{if(f=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",f&&t!==vS&&(y=t.relatedTarget||t.fromElement)&&(Si(y)||y[Xo]))break e;if((p||f)&&(f=u.window===u?u:(f=u.ownerDocument)?f.defaultView||f.parentWindow:window,p?(y=t.relatedTarget||t.toElement,p=l,y=y?Si(y):null,y!==null&&(w=Vi(y),y!==w||y.tag!==5&&y.tag!==6)&&(y=null)):(p=null,y=l),p!==y)){if(m=S1,E="onMouseLeave",S="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(m=x1,E="onPointerLeave",S="onPointerEnter",v="pointer"),w=p==null?f:_a(p),P=y==null?f:_a(y),f=new m(E,v+"leave",p,t,u),f.target=w,f.relatedTarget=P,E=null,Si(u)===l&&(m=new m(S,v+"enter",y,t,u),m.target=P,m.relatedTarget=w,E=m),w=E,p&&y)t:{for(m=p,S=y,v=0,P=m;P;P=aa(P))v++;for(P=0,E=S;E;E=aa(E))P++;for(;0<v-P;)m=aa(m),v--;for(;0<P-v;)S=aa(S),P--;for(;v--;){if(m===S||S!==null&&m===S.alternate)break t;m=aa(m),S=aa(S)}m=null}else m=null;p!==null&&M1(d,f,p,m,!1),y!==null&&w!==null&&M1(d,w,y,m,!0)}}e:{if(f=l?_a(l):window,p=f.nodeName&&f.nodeName.toLowerCase(),p==="select"||p==="input"&&f.type==="file")var C=g4;else if(P1(f))if(Bk)C=v4;else{C=y4;var I=m4}else(p=f.nodeName)&&p.toLowerCase()==="input"&&(f.type==="checkbox"||f.type==="radio")&&(C=S4);if(C&&(C=C(e,l))){zk(d,C,t,u);break e}I&&I(e,f,l),e==="focusout"&&(I=f._wrapperState)&&I.controlled&&f.type==="number"&&pS(f,"number",f.value)}switch(I=l?_a(l):window,e){case"focusin":(P1(I)||I.contentEditable==="true")&&(Ia=I,ES=l,$l=null);break;case"focusout":$l=ES=Ia=null;break;case"mousedown":_S=!0;break;case"contextmenu":case"mouseup":case"dragend":_S=!1,k1(d,t,u);break;case"selectionchange":if(b4)break;case"keydown":case"keyup":k1(d,t,u)}var _;if(K0)e:{switch(e){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else Ca?Fk(e,t)&&(k="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(k="onCompositionStart");k&&(Lk&&t.locale!=="ko"&&(Ca||k!=="onCompositionStart"?k==="onCompositionEnd"&&Ca&&(_=Rk()):(Is=u,B0="value"in Is?Is.value:Is.textContent,Ca=!0)),I=Uf(l,k),0<I.length&&(k=new v1(k,e,null,t,u),d.push({event:k,listeners:I}),_?k.data=_:(_=Nk(t),_!==null&&(k.data=_)))),(_=u4?d4(e,t):h4(e,t))&&(l=Uf(l,"onBeforeInput"),0<l.length&&(u=new v1("onBeforeInput","beforeinput",null,t,u),d.push({event:u,listeners:l}),u.data=_))}Zk(d,n)})}function nu(e,n,t){return{instance:e,listener:n,currentTarget:t}}function Uf(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=Xl(e,t),s!=null&&r.unshift(nu(e,s,o)),s=Xl(e,n),s!=null&&r.push(nu(e,s,o))),e=e.return}return r}function aa(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function M1(e,n,t,r,o){for(var s=n._reactName,i=[];t!==null&&t!==r;){var a=t,c=a.alternate,l=a.stateNode;if(c!==null&&c===r)break;a.tag===5&&l!==null&&(a=l,o?(c=Xl(t,s),c!=null&&i.unshift(nu(t,c,a))):o||(c=Xl(t,s),c!=null&&i.push(nu(t,c,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var E4=/\r\n?/g,_4=/\u0000|\uFFFD/g;function A1(e){return(typeof e=="string"?e:""+e).replace(E4,`
90
- `).replace(_4,"")}function Pd(e,n,t){if(n=A1(n),A1(e)!==n&&t)throw Error(q(425))}function Hf(){}var kS=null,TS=null;function $S(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 MS=typeof setTimeout=="function"?setTimeout:void 0,k4=typeof clearTimeout=="function"?clearTimeout:void 0,j1=typeof Promise=="function"?Promise:void 0,T4=typeof queueMicrotask=="function"?queueMicrotask:typeof j1<"u"?function(e){return j1.resolve(null).then(e).catch($4)}:MS;function $4(e){setTimeout(function(){throw e})}function mm(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),Ql(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);Ql(n)}function Ds(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function O1(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 Ic=Math.random().toString(36).slice(2),ro="__reactFiber$"+Ic,ru="__reactProps$"+Ic,Xo="__reactContainer$"+Ic,AS="__reactEvents$"+Ic,M4="__reactListeners$"+Ic,A4="__reactHandles$"+Ic;function Si(e){var n=e[ro];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Xo]||t[ro]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=O1(e);e!==null;){if(t=e[ro])return t;e=O1(e)}return n}e=t,t=e.parentNode}return null}function Du(e){return e=e[ro]||e[Xo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function _a(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Dp(e){return e[ru]||null}var jS=[],ka=-1;function Qs(e){return{current:e}}function tt(e){0>ka||(e.current=jS[ka],jS[ka]=null,ka--)}function Ye(e,n){ka++,jS[ka]=e.current,e.current=n}var Hs={},ln=Qs(Hs),On=Qs(!1),Ai=Hs;function ic(e,n){var t=e.type.contextTypes;if(!t)return Hs;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 Dn(e){return e=e.childContextTypes,e!=null}function Kf(){tt(On),tt(ln)}function D1(e,n,t){if(ln.current!==Hs)throw Error(q(168));Ye(ln,n),Ye(On,t)}function Jk(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,mN(e)||"Unknown",o));return ft({},t,r)}function Wf(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Hs,Ai=ln.current,Ye(ln,e),Ye(On,On.current),!0}function R1(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=Jk(e,n,Ai),r.__reactInternalMemoizedMergedChildContext=e,tt(On),tt(ln),Ye(ln,e)):tt(On),Ye(On,t)}var Ro=null,Rp=!1,ym=!1;function eT(e){Ro===null?Ro=[e]:Ro.push(e)}function j4(e){Rp=!0,eT(e)}function Js(){if(!ym&&Ro!==null){ym=!0;var e=0,n=Ne;try{var t=Ro;for(Ne=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}Ro=null,Rp=!1}catch(o){throw Ro!==null&&(Ro=Ro.slice(e+1)),Ik(L0,Js),o}finally{Ne=n,ym=!1}}return null}var Ta=[],$a=0,Gf=null,Vf=0,Sr=[],vr=0,ji=null,Fo=1,No="";function pi(e,n){Ta[$a++]=Vf,Ta[$a++]=Gf,Gf=e,Vf=n}function tT(e,n,t){Sr[vr++]=Fo,Sr[vr++]=No,Sr[vr++]=ji,ji=e;var r=Fo;e=No;var o=32-Nr(r)-1;r&=~(1<<o),t+=1;var s=32-Nr(n)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Fo=1<<32-Nr(n)+o|t<<o|r,No=s+e}else Fo=1<<s|t<<o|r,No=e}function G0(e){e.return!==null&&(pi(e,1),tT(e,1,0))}function V0(e){for(;e===Gf;)Gf=Ta[--$a],Ta[$a]=null,Vf=Ta[--$a],Ta[$a]=null;for(;e===ji;)ji=Sr[--vr],Sr[vr]=null,No=Sr[--vr],Sr[vr]=null,Fo=Sr[--vr],Sr[vr]=null}var tr=null,Zn=null,rt=!1,Rr=null;function nT(e,n){var t=wr(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 L1(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,tr=e,Zn=Ds(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,tr=e,Zn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=ji!==null?{id:Fo,overflow:No}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=wr(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,tr=e,Zn=null,!0):!1;default:return!1}}function OS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function DS(e){if(rt){var n=Zn;if(n){var t=n;if(!L1(e,n)){if(OS(e))throw Error(q(418));n=Ds(t.nextSibling);var r=tr;n&&L1(e,n)?nT(r,t):(e.flags=e.flags&-4097|2,rt=!1,tr=e)}}else{if(OS(e))throw Error(q(418));e.flags=e.flags&-4097|2,rt=!1,tr=e}}}function F1(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;tr=e}function Cd(e){if(e!==tr)return!1;if(!rt)return F1(e),rt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!$S(e.type,e.memoizedProps)),n&&(n=Zn)){if(OS(e))throw rT(),Error(q(418));for(;n;)nT(e,n),n=Ds(n.nextSibling)}if(F1(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(q(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var t=e.data;if(t==="/$"){if(n===0){Zn=Ds(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}Zn=null}}else Zn=tr?Ds(e.stateNode.nextSibling):null;return!0}function rT(){for(var e=Zn;e;)e=Ds(e.nextSibling)}function ac(){Zn=tr=null,rt=!1}function Y0(e){Rr===null?Rr=[e]:Rr.push(e)}var O4=ns.ReactCurrentBatchConfig;function Zc(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 Id(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function N1(e){var n=e._init;return n(e._payload)}function oT(e){function n(S,v){if(e){var P=S.deletions;P===null?(S.deletions=[v],S.flags|=16):P.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=Ns(S,v),S.index=0,S.sibling=null,S}function s(S,v,P){return S.index=P,e?(P=S.alternate,P!==null?(P=P.index,P<v?(S.flags|=2,v):P):(S.flags|=2,v)):(S.flags|=1048576,v)}function i(S){return e&&S.alternate===null&&(S.flags|=2),S}function a(S,v,P,E){return v===null||v.tag!==6?(v=Cm(P,S.mode,E),v.return=S,v):(v=o(v,P),v.return=S,v)}function c(S,v,P,E){var C=P.type;return C===Pa?u(S,v,P.props.children,E,P.key):v!==null&&(v.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===vs&&N1(C)===v.type)?(E=o(v,P.props),E.ref=Zc(S,v,P),E.return=S,E):(E=Ph(P.type,P.key,P.props,null,S.mode,E),E.ref=Zc(S,v,P),E.return=S,E)}function l(S,v,P,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==P.containerInfo||v.stateNode.implementation!==P.implementation?(v=Im(P,S.mode,E),v.return=S,v):(v=o(v,P.children||[]),v.return=S,v)}function u(S,v,P,E,C){return v===null||v.tag!==7?(v=Ei(P,S.mode,E,C),v.return=S,v):(v=o(v,P),v.return=S,v)}function d(S,v,P){if(typeof v=="string"&&v!==""||typeof v=="number")return v=Cm(""+v,S.mode,P),v.return=S,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case pd:return P=Ph(v.type,v.key,v.props,null,S.mode,P),P.ref=Zc(S,null,v),P.return=S,P;case ba:return v=Im(v,S.mode,P),v.return=S,v;case vs:var E=v._init;return d(S,E(v._payload),P)}if(yl(v)||Gc(v))return v=Ei(v,S.mode,P,null),v.return=S,v;Id(S,v)}return null}function f(S,v,P,E){var C=v!==null?v.key:null;if(typeof P=="string"&&P!==""||typeof P=="number")return C!==null?null:a(S,v,""+P,E);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case pd:return P.key===C?c(S,v,P,E):null;case ba:return P.key===C?l(S,v,P,E):null;case vs:return C=P._init,f(S,v,C(P._payload),E)}if(yl(P)||Gc(P))return C!==null?null:u(S,v,P,E,null);Id(S,P)}return null}function p(S,v,P,E,C){if(typeof E=="string"&&E!==""||typeof E=="number")return S=S.get(P)||null,a(v,S,""+E,C);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case pd:return S=S.get(E.key===null?P:E.key)||null,c(v,S,E,C);case ba:return S=S.get(E.key===null?P:E.key)||null,l(v,S,E,C);case vs:var I=E._init;return p(S,v,P,I(E._payload),C)}if(yl(E)||Gc(E))return S=S.get(P)||null,u(v,S,E,C,null);Id(v,E)}return null}function y(S,v,P,E){for(var C=null,I=null,_=v,k=v=0,$=null;_!==null&&k<P.length;k++){_.index>k?($=_,_=null):$=_.sibling;var T=f(S,_,P[k],E);if(T===null){_===null&&(_=$);break}e&&_&&T.alternate===null&&n(S,_),v=s(T,v,k),I===null?C=T:I.sibling=T,I=T,_=$}if(k===P.length)return t(S,_),rt&&pi(S,k),C;if(_===null){for(;k<P.length;k++)_=d(S,P[k],E),_!==null&&(v=s(_,v,k),I===null?C=_:I.sibling=_,I=_);return rt&&pi(S,k),C}for(_=r(S,_);k<P.length;k++)$=p(_,S,k,P[k],E),$!==null&&(e&&$.alternate!==null&&_.delete($.key===null?k:$.key),v=s($,v,k),I===null?C=$:I.sibling=$,I=$);return e&&_.forEach(function(O){return n(S,O)}),rt&&pi(S,k),C}function m(S,v,P,E){var C=Gc(P);if(typeof C!="function")throw Error(q(150));if(P=C.call(P),P==null)throw Error(q(151));for(var I=C=null,_=v,k=v=0,$=null,T=P.next();_!==null&&!T.done;k++,T=P.next()){_.index>k?($=_,_=null):$=_.sibling;var O=f(S,_,T.value,E);if(O===null){_===null&&(_=$);break}e&&_&&O.alternate===null&&n(S,_),v=s(O,v,k),I===null?C=O:I.sibling=O,I=O,_=$}if(T.done)return t(S,_),rt&&pi(S,k),C;if(_===null){for(;!T.done;k++,T=P.next())T=d(S,T.value,E),T!==null&&(v=s(T,v,k),I===null?C=T:I.sibling=T,I=T);return rt&&pi(S,k),C}for(_=r(S,_);!T.done;k++,T=P.next())T=p(_,S,k,T.value,E),T!==null&&(e&&T.alternate!==null&&_.delete(T.key===null?k:T.key),v=s(T,v,k),I===null?C=T:I.sibling=T,I=T);return e&&_.forEach(function(N){return n(S,N)}),rt&&pi(S,k),C}function w(S,v,P,E){if(typeof P=="object"&&P!==null&&P.type===Pa&&P.key===null&&(P=P.props.children),typeof P=="object"&&P!==null){switch(P.$$typeof){case pd:e:{for(var C=P.key,I=v;I!==null;){if(I.key===C){if(C=P.type,C===Pa){if(I.tag===7){t(S,I.sibling),v=o(I,P.props.children),v.return=S,S=v;break e}}else if(I.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===vs&&N1(C)===I.type){t(S,I.sibling),v=o(I,P.props),v.ref=Zc(S,I,P),v.return=S,S=v;break e}t(S,I);break}else n(S,I);I=I.sibling}P.type===Pa?(v=Ei(P.props.children,S.mode,E,P.key),v.return=S,S=v):(E=Ph(P.type,P.key,P.props,null,S.mode,E),E.ref=Zc(S,v,P),E.return=S,S=E)}return i(S);case ba:e:{for(I=P.key;v!==null;){if(v.key===I)if(v.tag===4&&v.stateNode.containerInfo===P.containerInfo&&v.stateNode.implementation===P.implementation){t(S,v.sibling),v=o(v,P.children||[]),v.return=S,S=v;break e}else{t(S,v);break}else n(S,v);v=v.sibling}v=Im(P,S.mode,E),v.return=S,S=v}return i(S);case vs:return I=P._init,w(S,v,I(P._payload),E)}if(yl(P))return y(S,v,P,E);if(Gc(P))return m(S,v,P,E);Id(S,P)}return typeof P=="string"&&P!==""||typeof P=="number"?(P=""+P,v!==null&&v.tag===6?(t(S,v.sibling),v=o(v,P),v.return=S,S=v):(t(S,v),v=Cm(P,S.mode,E),v.return=S,S=v),i(S)):t(S,v)}return w}var cc=oT(!0),sT=oT(!1),Yf=Qs(null),Xf=null,Ma=null,X0=null;function q0(){X0=Ma=Xf=null}function Z0(e){var n=Yf.current;tt(Yf),e._currentValue=n}function RS(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 Xa(e,n){Xf=e,X0=Ma=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&($n=!0),e.firstContext=null)}function Cr(e){var n=e._currentValue;if(X0!==e)if(e={context:e,memoizedValue:n,next:null},Ma===null){if(Xf===null)throw Error(q(308));Ma=e,Xf.dependencies={lanes:0,firstContext:e}}else Ma=Ma.next=e;return n}var vi=null;function Q0(e){vi===null?vi=[e]:vi.push(e)}function iT(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,Q0(n)):(t.next=o.next,o.next=t),n.interleaved=t,qo(e,r)}function qo(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 xs=!1;function J0(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function aT(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Uo(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Rs(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Te&2){var o=r.pending;return o===null?n.next=n:(n.next=o.next,o.next=n),r.pending=n,qo(e,t)}return o=r.interleaved,o===null?(n.next=n,Q0(r)):(n.next=o.next,o.next=n),r.interleaved=n,qo(e,t)}function yh(e,n,t){if(n=n.updateQueue,n!==null&&(n=n.shared,(t&4194240)!==0)){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,F0(e,t)}}function z1(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 qf(e,n,t,r){var o=e.updateQueue;xs=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var c=a,l=c.next;c.next=null,i===null?s=l:i.next=l,i=c;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=l:a.next=l,u.lastBaseUpdate=c))}if(s!==null){var d=o.baseState;i=0,u=l=c=null,a=s;do{var f=a.lane,p=a.eventTime;if((r&f)===f){u!==null&&(u=u.next={eventTime:p,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var y=e,m=a;switch(f=n,p=t,m.tag){case 1:if(y=m.payload,typeof y=="function"){d=y.call(p,d,f);break e}d=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=m.payload,f=typeof y=="function"?y.call(p,d,f):y,f==null)break e;d=ft({},d,f);break e;case 2:xs=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,f=o.effects,f===null?o.effects=[a]:f.push(a))}else p={eventTime:p,lane:f,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(l=u=p,c=d):u=u.next=p,i|=f;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;f=a,a=f.next,f.next=null,o.lastBaseUpdate=f,o.shared.pending=null}}while(!0);if(u===null&&(c=d),o.baseState=c,o.firstBaseUpdate=l,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);Di|=i,e.lanes=i,e.memoizedState=d}}function B1(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 Ru={},uo=Qs(Ru),ou=Qs(Ru),su=Qs(Ru);function xi(e){if(e===Ru)throw Error(q(174));return e}function ex(e,n){switch(Ye(su,n),Ye(ou,e),Ye(uo,Ru),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:mS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=mS(n,e)}tt(uo),Ye(uo,n)}function lc(){tt(uo),tt(ou),tt(su)}function cT(e){xi(su.current);var n=xi(uo.current),t=mS(n,e.type);n!==t&&(Ye(ou,e),Ye(uo,t))}function tx(e){ou.current===e&&(tt(uo),tt(ou))}var ct=Qs(0);function Zf(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 Sm=[];function nx(){for(var e=0;e<Sm.length;e++)Sm[e]._workInProgressVersionPrimary=null;Sm.length=0}var Sh=ns.ReactCurrentDispatcher,vm=ns.ReactCurrentBatchConfig,Oi=0,dt=null,_t=null,Mt=null,Qf=!1,Ml=!1,iu=0,D4=0;function Xt(){throw Error(q(321))}function rx(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Kr(e[t],n[t]))return!1;return!0}function ox(e,n,t,r,o,s){if(Oi=s,dt=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Sh.current=e===null||e.memoizedState===null?N4:z4,e=t(r,o),Ml){s=0;do{if(Ml=!1,iu=0,25<=s)throw Error(q(301));s+=1,Mt=_t=null,n.updateQueue=null,Sh.current=B4,e=t(r,o)}while(Ml)}if(Sh.current=Jf,n=_t!==null&&_t.next!==null,Oi=0,Mt=_t=dt=null,Qf=!1,n)throw Error(q(300));return e}function sx(){var e=iu!==0;return iu=0,e}function Qr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Mt===null?dt.memoizedState=Mt=e:Mt=Mt.next=e,Mt}function Ir(){if(_t===null){var e=dt.alternate;e=e!==null?e.memoizedState:null}else e=_t.next;var n=Mt===null?dt.memoizedState:Mt.next;if(n!==null)Mt=n,_t=e;else{if(e===null)throw Error(q(310));_t=e,e={memoizedState:_t.memoizedState,baseState:_t.baseState,baseQueue:_t.baseQueue,queue:_t.queue,next:null},Mt===null?dt.memoizedState=Mt=e:Mt=Mt.next=e}return Mt}function au(e,n){return typeof n=="function"?n(e):n}function xm(e){var n=Ir(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=_t,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,c=null,l=s;do{var u=l.lane;if((Oi&u)===u)c!==null&&(c=c.next={lane:0,action:l.action,hasEagerState:l.hasEagerState,eagerState:l.eagerState,next:null}),r=l.hasEagerState?l.eagerState:e(r,l.action);else{var d={lane:u,action:l.action,hasEagerState:l.hasEagerState,eagerState:l.eagerState,next:null};c===null?(a=c=d,i=r):c=c.next=d,dt.lanes|=u,Di|=u}l=l.next}while(l!==null&&l!==s);c===null?i=r:c.next=a,Kr(r,n.memoizedState)||($n=!0),n.memoizedState=r,n.baseState=i,n.baseQueue=c,t.lastRenderedState=r}if(e=t.interleaved,e!==null){o=e;do s=o.lane,dt.lanes|=s,Di|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function wm(e){var n=Ir(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=t.dispatch,o=t.pending,s=n.memoizedState;if(o!==null){t.pending=null;var i=o=o.next;do s=e(s,i.action),i=i.next;while(i!==o);Kr(s,n.memoizedState)||($n=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function lT(){}function uT(e,n){var t=dt,r=Ir(),o=n(),s=!Kr(r.memoizedState,o);if(s&&(r.memoizedState=o,$n=!0),r=r.queue,ix(fT.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||Mt!==null&&Mt.memoizedState.tag&1){if(t.flags|=2048,cu(9,hT.bind(null,t,r,o,n),void 0,null),jt===null)throw Error(q(349));Oi&30||dT(t,n,o)}return o}function dT(e,n,t){e.flags|=16384,e={getSnapshot:n,value:t},n=dt.updateQueue,n===null?(n={lastEffect:null,stores:null},dt.updateQueue=n,n.stores=[e]):(t=n.stores,t===null?n.stores=[e]:t.push(e))}function hT(e,n,t,r){n.value=t,n.getSnapshot=r,pT(n)&&gT(e)}function fT(e,n,t){return t(function(){pT(n)&&gT(e)})}function pT(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Kr(e,t)}catch{return!0}}function gT(e){var n=qo(e,1);n!==null&&zr(n,e,1,-1)}function U1(e){var n=Qr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:au,lastRenderedState:e},n.queue=e,e=e.dispatch=F4.bind(null,dt,e),[n.memoizedState,e]}function cu(e,n,t,r){return e={tag:e,create:n,destroy:t,deps:r,next:null},n=dt.updateQueue,n===null?(n={lastEffect:null,stores:null},dt.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 mT(){return Ir().memoizedState}function vh(e,n,t,r){var o=Qr();dt.flags|=e,o.memoizedState=cu(1|n,t,void 0,r===void 0?null:r)}function Lp(e,n,t,r){var o=Ir();r=r===void 0?null:r;var s=void 0;if(_t!==null){var i=_t.memoizedState;if(s=i.destroy,r!==null&&rx(r,i.deps)){o.memoizedState=cu(n,t,s,r);return}}dt.flags|=e,o.memoizedState=cu(1|n,t,s,r)}function H1(e,n){return vh(8390656,8,e,n)}function ix(e,n){return Lp(2048,8,e,n)}function yT(e,n){return Lp(4,2,e,n)}function ST(e,n){return Lp(4,4,e,n)}function vT(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 xT(e,n,t){return t=t!=null?t.concat([e]):null,Lp(4,4,vT.bind(null,n,e),t)}function ax(){}function wT(e,n){var t=Ir();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&rx(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function bT(e,n){var t=Ir();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&rx(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function PT(e,n,t){return Oi&21?(Kr(t,n)||(t=kk(),dt.lanes|=t,Di|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,$n=!0),e.memoizedState=t)}function R4(e,n){var t=Ne;Ne=t!==0&&4>t?t:4,e(!0);var r=vm.transition;vm.transition={};try{e(!1),n()}finally{Ne=t,vm.transition=r}}function CT(){return Ir().memoizedState}function L4(e,n,t){var r=Fs(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},IT(e))ET(n,t);else if(t=iT(e,n,t,r),t!==null){var o=gn();zr(t,e,r,o),_T(t,n,r)}}function F4(e,n,t){var r=Fs(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(IT(e))ET(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,Kr(a,i)){var c=n.interleaved;c===null?(o.next=o,Q0(n)):(o.next=c.next,c.next=o),n.interleaved=o;return}}catch{}finally{}t=iT(e,n,o,r),t!==null&&(o=gn(),zr(t,e,r,o),_T(t,n,r))}}function IT(e){var n=e.alternate;return e===dt||n!==null&&n===dt}function ET(e,n){Ml=Qf=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function _T(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,F0(e,t)}}var Jf={readContext:Cr,useCallback:Xt,useContext:Xt,useEffect:Xt,useImperativeHandle:Xt,useInsertionEffect:Xt,useLayoutEffect:Xt,useMemo:Xt,useReducer:Xt,useRef:Xt,useState:Xt,useDebugValue:Xt,useDeferredValue:Xt,useTransition:Xt,useMutableSource:Xt,useSyncExternalStore:Xt,useId:Xt,unstable_isNewReconciler:!1},N4={readContext:Cr,useCallback:function(e,n){return Qr().memoizedState=[e,n===void 0?null:n],e},useContext:Cr,useEffect:H1,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,vh(4194308,4,vT.bind(null,n,e),t)},useLayoutEffect:function(e,n){return vh(4194308,4,e,n)},useInsertionEffect:function(e,n){return vh(4,2,e,n)},useMemo:function(e,n){var t=Qr();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=Qr();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=L4.bind(null,dt,e),[r.memoizedState,e]},useRef:function(e){var n=Qr();return e={current:e},n.memoizedState=e},useState:U1,useDebugValue:ax,useDeferredValue:function(e){return Qr().memoizedState=e},useTransition:function(){var e=U1(!1),n=e[0];return e=R4.bind(null,e[1]),Qr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=dt,o=Qr();if(rt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),jt===null)throw Error(q(349));Oi&30||dT(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,H1(fT.bind(null,r,s,e),[e]),r.flags|=2048,cu(9,hT.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=Qr(),n=jt.identifierPrefix;if(rt){var t=No,r=Fo;t=(r&~(1<<32-Nr(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=iu++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=D4++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},z4={readContext:Cr,useCallback:wT,useContext:Cr,useEffect:ix,useImperativeHandle:xT,useInsertionEffect:yT,useLayoutEffect:ST,useMemo:bT,useReducer:xm,useRef:mT,useState:function(){return xm(au)},useDebugValue:ax,useDeferredValue:function(e){var n=Ir();return PT(n,_t.memoizedState,e)},useTransition:function(){var e=xm(au)[0],n=Ir().memoizedState;return[e,n]},useMutableSource:lT,useSyncExternalStore:uT,useId:CT,unstable_isNewReconciler:!1},B4={readContext:Cr,useCallback:wT,useContext:Cr,useEffect:ix,useImperativeHandle:xT,useInsertionEffect:yT,useLayoutEffect:ST,useMemo:bT,useReducer:wm,useRef:mT,useState:function(){return wm(au)},useDebugValue:ax,useDeferredValue:function(e){var n=Ir();return _t===null?n.memoizedState=e:PT(n,_t.memoizedState,e)},useTransition:function(){var e=wm(au)[0],n=Ir().memoizedState;return[e,n]},useMutableSource:lT,useSyncExternalStore:uT,useId:CT,unstable_isNewReconciler:!1};function Ar(e,n){if(e&&e.defaultProps){n=ft({},n),e=e.defaultProps;for(var t in e)n[t]===void 0&&(n[t]=e[t]);return n}return n}function LS(e,n,t,r){n=e.memoizedState,t=t(r,n),t=t==null?n:ft({},n,t),e.memoizedState=t,e.lanes===0&&(e.updateQueue.baseState=t)}var Fp={isMounted:function(e){return(e=e._reactInternals)?Vi(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=gn(),o=Fs(e),s=Uo(r,o);s.payload=n,t!=null&&(s.callback=t),n=Rs(e,s,o),n!==null&&(zr(n,e,o,r),yh(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=gn(),o=Fs(e),s=Uo(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=Rs(e,s,o),n!==null&&(zr(n,e,o,r),yh(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=gn(),r=Fs(e),o=Uo(t,r);o.tag=2,n!=null&&(o.callback=n),n=Rs(e,o,r),n!==null&&(zr(n,e,r,t),yh(n,e,r))}};function K1(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?!eu(t,r)||!eu(o,s):!0}function kT(e,n,t){var r=!1,o=Hs,s=n.contextType;return typeof s=="object"&&s!==null?s=Cr(s):(o=Dn(n)?Ai:ln.current,r=n.contextTypes,s=(r=r!=null)?ic(e,o):Hs),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Fp,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function W1(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&&Fp.enqueueReplaceState(n,n.state,null)}function FS(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs={},J0(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=Cr(s):(s=Dn(n)?Ai:ln.current,o.context=ic(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(LS(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&&Fp.enqueueReplaceState(o,o.state,null),qf(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function uc(e,n){try{var t="",r=n;do t+=gN(r),r=r.return;while(r);var o=t}catch(s){o=`
91
- Error generating stack: `+s.message+`
92
- `+s.stack}return{value:e,source:n,stack:o,digest:null}}function bm(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function NS(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var U4=typeof WeakMap=="function"?WeakMap:Map;function TT(e,n,t){t=Uo(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){tp||(tp=!0,XS=r),NS(e,n)},t}function $T(e,n,t){t=Uo(-1,t),t.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var o=n.value;t.payload=function(){return r(o)},t.callback=function(){NS(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){NS(e,n),typeof r!="function"&&(Ls===null?Ls=new Set([this]):Ls.add(this));var i=n.stack;this.componentDidCatch(n.value,{componentStack:i!==null?i:""})}),t}function G1(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new U4;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=nz.bind(null,e,n,t),n.then(e,e))}function V1(e){do{var n;if((n=e.tag===13)&&(n=e.memoizedState,n=n!==null?n.dehydrated!==null:!0),n)return e;e=e.return}while(e!==null);return null}function Y1(e,n,t,r,o){return e.mode&1?(e.flags|=65536,e.lanes=o,e):(e===n?e.flags|=65536:(e.flags|=128,t.flags|=131072,t.flags&=-52805,t.tag===1&&(t.alternate===null?t.tag=17:(n=Uo(-1,1),n.tag=2,Rs(t,n,1))),t.lanes|=1),e)}var H4=ns.ReactCurrentOwner,$n=!1;function fn(e,n,t,r){n.child=e===null?sT(n,null,t,r):cc(n,e.child,t,r)}function X1(e,n,t,r,o){t=t.render;var s=n.ref;return Xa(n,o),r=ox(e,n,t,r,s,o),t=sx(),e!==null&&!$n?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Zo(e,n,o)):(rt&&t&&G0(n),n.flags|=1,fn(e,n,r,o),n.child)}function q1(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!gx(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,MT(e,n,s,r,o)):(e=Ph(t.type,null,r,n,n.mode,o),e.ref=n.ref,e.return=n,n.child=e)}if(s=e.child,!(e.lanes&o)){var i=s.memoizedProps;if(t=t.compare,t=t!==null?t:eu,t(i,r)&&e.ref===n.ref)return Zo(e,n,o)}return n.flags|=1,e=Ns(s,r),e.ref=n.ref,e.return=n,n.child=e}function MT(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(eu(s,r)&&e.ref===n.ref)if($n=!1,n.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&($n=!0);else return n.lanes=e.lanes,Zo(e,n,o)}return zS(e,n,t,r,o)}function AT(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},Ye(ja,Gn),Gn|=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,Ye(ja,Gn),Gn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ye(ja,Gn),Gn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ye(ja,Gn),Gn|=r;return fn(e,n,o,t),n.child}function jT(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function zS(e,n,t,r,o){var s=Dn(t)?Ai:ln.current;return s=ic(n,s),Xa(n,o),t=ox(e,n,t,r,s,o),r=sx(),e!==null&&!$n?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Zo(e,n,o)):(rt&&r&&G0(n),n.flags|=1,fn(e,n,t,o),n.child)}function Z1(e,n,t,r,o){if(Dn(t)){var s=!0;Wf(n)}else s=!1;if(Xa(n,o),n.stateNode===null)xh(e,n),kT(n,t,r),FS(n,t,r,o),r=!0;else if(e===null){var i=n.stateNode,a=n.memoizedProps;i.props=a;var c=i.context,l=t.contextType;typeof l=="object"&&l!==null?l=Cr(l):(l=Dn(t)?Ai:ln.current,l=ic(n,l));var u=t.getDerivedStateFromProps,d=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";d||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||c!==l)&&W1(n,i,r,l),xs=!1;var f=n.memoizedState;i.state=f,qf(n,r,i,o),c=n.memoizedState,a!==r||f!==c||On.current||xs?(typeof u=="function"&&(LS(n,t,u,r),c=n.memoizedState),(a=xs||K1(n,t,a,r,f,c,l))?(d||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(n.flags|=4194308)):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),i.props=r,i.state=c,i.context=l,r=a):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{i=n.stateNode,aT(e,n),a=n.memoizedProps,l=n.type===n.elementType?a:Ar(n.type,a),i.props=l,d=n.pendingProps,f=i.context,c=t.contextType,typeof c=="object"&&c!==null?c=Cr(c):(c=Dn(t)?Ai:ln.current,c=ic(n,c));var p=t.getDerivedStateFromProps;(u=typeof p=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==d||f!==c)&&W1(n,i,r,c),xs=!1,f=n.memoizedState,i.state=f,qf(n,r,i,o);var y=n.memoizedState;a!==d||f!==y||On.current||xs?(typeof p=="function"&&(LS(n,t,p,r),y=n.memoizedState),(l=xs||K1(n,t,l,r,f,y,c)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,y,c),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,y,c)),typeof i.componentDidUpdate=="function"&&(n.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=y),i.props=r,i.state=y,i.context=c,r=l):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),r=!1)}return BS(e,n,t,r,s,o)}function BS(e,n,t,r,o,s){jT(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&R1(n,t,!1),Zo(e,n,s);r=n.stateNode,H4.current=n;var a=i&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&i?(n.child=cc(n,e.child,null,s),n.child=cc(n,null,a,s)):fn(e,n,a,s),n.memoizedState=r.state,o&&R1(n,t,!0),n.child}function OT(e){var n=e.stateNode;n.pendingContext?D1(e,n.pendingContext,n.pendingContext!==n.context):n.context&&D1(e,n.context,!1),ex(e,n.containerInfo)}function Q1(e,n,t,r,o){return ac(),Y0(o),n.flags|=256,fn(e,n,t,r),n.child}var US={dehydrated:null,treeContext:null,retryLane:0};function HS(e){return{baseLanes:e,cachePool:null,transitions:null}}function DT(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),Ye(ct,o&1),e===null)return DS(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=Bp(i,r,0,null),e=Ei(e,r,t,null),s.return=n,e.return=n,s.sibling=e,n.child=s,n.child.memoizedState=HS(t),n.memoizedState=US,e):cx(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return K4(e,n,i,r,a,o,t);if(s){s=r.fallback,i=n.mode,o=e.child,a=o.sibling;var c={mode:"hidden",children:r.children};return!(i&1)&&n.child!==o?(r=n.child,r.childLanes=0,r.pendingProps=c,n.deletions=null):(r=Ns(o,c),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Ns(a,s):(s=Ei(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?HS(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=US,r}return s=e.child,e=s.sibling,r=Ns(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 cx(e,n){return n=Bp({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Ed(e,n,t,r){return r!==null&&Y0(r),cc(n,e.child,null,t),e=cx(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function K4(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=bm(Error(q(422))),Ed(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=Bp({mode:"visible",children:r.children},o,0,null),s=Ei(s,o,i,null),s.flags|=2,r.return=n,s.return=n,r.sibling=s,n.child=r,n.mode&1&&cc(n,e.child,null,i),n.child.memoizedState=HS(i),n.memoizedState=US,s);if(!(n.mode&1))return Ed(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=bm(s,r,void 0),Ed(e,n,i,r)}if(a=(i&e.childLanes)!==0,$n||a){if(r=jt,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,qo(e,o),zr(r,e,o,-1))}return px(),r=bm(Error(q(421))),Ed(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=rz.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,Zn=Ds(o.nextSibling),tr=n,rt=!0,Rr=null,e!==null&&(Sr[vr++]=Fo,Sr[vr++]=No,Sr[vr++]=ji,Fo=e.id,No=e.overflow,ji=n),n=cx(n,r.children),n.flags|=4096,n)}function J1(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),RS(e.return,n,t)}function Pm(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 RT(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&&J1(e,t,n);else if(e.tag===19)J1(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(Ye(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&&Zf(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),Pm(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&&Zf(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}Pm(n,!0,t,null,s);break;case"together":Pm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function xh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function Zo(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),Di|=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=Ns(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=Ns(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function W4(e,n,t){switch(n.tag){case 3:OT(n),ac();break;case 5:cT(n);break;case 1:Dn(n.type)&&Wf(n);break;case 4:ex(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ye(Yf,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ye(ct,ct.current&1),n.flags|=128,null):t&n.child.childLanes?DT(e,n,t):(Ye(ct,ct.current&1),e=Zo(e,n,t),e!==null?e.sibling:null);Ye(ct,ct.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return RT(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ye(ct,ct.current),r)break;return null;case 22:case 23:return n.lanes=0,AT(e,n,t)}return Zo(e,n,t)}var LT,KS,FT,NT;LT=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}};KS=function(){};FT=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,xi(uo.current);var s=null;switch(t){case"input":o=hS(e,o),r=hS(e,r),s=[];break;case"select":o=ft({},o,{value:void 0}),r=ft({},r,{value:void 0}),s=[];break;case"textarea":o=gS(e,o),r=gS(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Hf)}yS(t,r);var i;t=null;for(l in o)if(!r.hasOwnProperty(l)&&o.hasOwnProperty(l)&&o[l]!=null)if(l==="style"){var a=o[l];for(i in a)a.hasOwnProperty(i)&&(t||(t={}),t[i]="")}else l!=="dangerouslySetInnerHTML"&&l!=="children"&&l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&l!=="autoFocus"&&(Vl.hasOwnProperty(l)?s||(s=[]):(s=s||[]).push(l,null));for(l in r){var c=r[l];if(a=o!=null?o[l]:void 0,r.hasOwnProperty(l)&&c!==a&&(c!=null||a!=null))if(l==="style")if(a){for(i in a)!a.hasOwnProperty(i)||c&&c.hasOwnProperty(i)||(t||(t={}),t[i]="");for(i in c)c.hasOwnProperty(i)&&a[i]!==c[i]&&(t||(t={}),t[i]=c[i])}else t||(s||(s=[]),s.push(l,t)),t=c;else l==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,a=a?a.__html:void 0,c!=null&&a!==c&&(s=s||[]).push(l,c)):l==="children"?typeof c!="string"&&typeof c!="number"||(s=s||[]).push(l,""+c):l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&(Vl.hasOwnProperty(l)?(c!=null&&l==="onScroll"&&Je("scroll",e),s||a===c||(s=[])):(s=s||[]).push(l,c))}t&&(s=s||[]).push("style",t);var l=s;(n.updateQueue=l)&&(n.flags|=4)}};NT=function(e,n,t,r){t!==r&&(n.flags|=4)};function Qc(e,n){if(!rt)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 G4(e,n,t){var r=n.pendingProps;switch(V0(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 Dn(n.type)&&Kf(),qt(n),null;case 3:return r=n.stateNode,lc(),tt(On),tt(ln),nx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Cd(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Rr!==null&&(QS(Rr),Rr=null))),KS(e,n),qt(n),null;case 5:tx(n);var o=xi(su.current);if(t=n.type,e!==null&&n.stateNode!=null)FT(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=xi(uo.current),Cd(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[ro]=n,r[ru]=s,e=(n.mode&1)!==0,t){case"dialog":Je("cancel",r),Je("close",r);break;case"iframe":case"object":case"embed":Je("load",r);break;case"video":case"audio":for(o=0;o<vl.length;o++)Je(vl[o],r);break;case"source":Je("error",r);break;case"img":case"image":case"link":Je("error",r),Je("load",r);break;case"details":Je("toggle",r);break;case"input":c1(r,s),Je("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Je("invalid",r);break;case"textarea":u1(r,s),Je("invalid",r)}yS(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&&Pd(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Pd(r.textContent,a,e),o=["children",""+a]):Vl.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Je("scroll",r)}switch(t){case"input":gd(r),l1(r,s,!0);break;case"textarea":gd(r),d1(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Hf)}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=fk(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[ro]=n,e[ru]=r,LT(e,n,!1,!1),n.stateNode=e;e:{switch(i=SS(t,r),t){case"dialog":Je("cancel",e),Je("close",e),o=r;break;case"iframe":case"object":case"embed":Je("load",e),o=r;break;case"video":case"audio":for(o=0;o<vl.length;o++)Je(vl[o],e);o=r;break;case"source":Je("error",e),o=r;break;case"img":case"image":case"link":Je("error",e),Je("load",e),o=r;break;case"details":Je("toggle",e),o=r;break;case"input":c1(e,r),o=hS(e,r),Je("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=ft({},r,{value:void 0}),Je("invalid",e);break;case"textarea":u1(e,r),o=gS(e,r),Je("invalid",e);break;default:o=r}yS(t,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var c=a[s];s==="style"?mk(e,c):s==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&pk(e,c)):s==="children"?typeof c=="string"?(t!=="textarea"||c!=="")&&Yl(e,c):typeof c=="number"&&Yl(e,""+c):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Vl.hasOwnProperty(s)?c!=null&&s==="onScroll"&&Je("scroll",e):c!=null&&A0(e,s,c,i))}switch(t){case"input":gd(e),l1(e,r,!1);break;case"textarea":gd(e),d1(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Us(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?Wa(e,!!r.multiple,s,!1):r.defaultValue!=null&&Wa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Hf)}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)NT(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=xi(su.current),xi(uo.current),Cd(n)){if(r=n.stateNode,t=n.memoizedProps,r[ro]=n,(s=r.nodeValue!==t)&&(e=tr,e!==null))switch(e.tag){case 3:Pd(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Pd(r.nodeValue,t,(e.mode&1)!==0)}s&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[ro]=n,n.stateNode=r}return qt(n),null;case 13:if(tt(ct),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(rt&&Zn!==null&&n.mode&1&&!(n.flags&128))rT(),ac(),n.flags|=98560,s=!1;else if(s=Cd(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[ro]=n}else ac(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;qt(n),s=!1}else Rr!==null&&(QS(Rr),Rr=null),s=!0;if(!s)return n.flags&65536?n:null}return n.flags&128?(n.lanes=t,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||ct.current&1?kt===0&&(kt=3):px())),n.updateQueue!==null&&(n.flags|=4),qt(n),null);case 4:return lc(),KS(e,n),e===null&&tu(n.stateNode.containerInfo),qt(n),null;case 10:return Z0(n.type._context),qt(n),null;case 17:return Dn(n.type)&&Kf(),qt(n),null;case 19:if(tt(ct),s=n.memoizedState,s===null)return qt(n),null;if(r=(n.flags&128)!==0,i=s.rendering,i===null)if(r)Qc(s,!1);else{if(kt!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=Zf(e),i!==null){for(n.flags|=128,Qc(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 Ye(ct,ct.current&1|2),n.child}e=e.sibling}s.tail!==null&&Ct()>dc&&(n.flags|=128,r=!0,Qc(s,!1),n.lanes=4194304)}else{if(!r)if(e=Zf(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),Qc(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!rt)return qt(n),null}else 2*Ct()-s.renderingStartTime>dc&&t!==1073741824&&(n.flags|=128,r=!0,Qc(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=Ct(),n.sibling=null,t=ct.current,Ye(ct,r?t&1|2:t&1),n):(qt(n),null);case 22:case 23:return fx(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Gn&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 V4(e,n){switch(V0(n),n.tag){case 1:return Dn(n.type)&&Kf(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return lc(),tt(On),tt(ln),nx(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return tx(n),null;case 13:if(tt(ct),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));ac()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return tt(ct),null;case 4:return lc(),null;case 10:return Z0(n.type._context),null;case 22:case 23:return fx(),null;case 24:return null;default:return null}}var _d=!1,tn=!1,Y4=typeof WeakSet=="function"?WeakSet:Set,ne=null;function Aa(e,n){var t=e.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){St(e,n,r)}else t.current=null}function WS(e,n,t){try{t()}catch(r){St(e,n,r)}}var eP=!1;function X4(e,n){if(kS=zf,e=Kk(),W0(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,c=-1,l=0,u=0,d=e,f=null;t:for(;;){for(var p;d!==t||o!==0&&d.nodeType!==3||(a=i+o),d!==s||r!==0&&d.nodeType!==3||(c=i+r),d.nodeType===3&&(i+=d.nodeValue.length),(p=d.firstChild)!==null;)f=d,d=p;for(;;){if(d===e)break t;if(f===t&&++l===o&&(a=i),f===s&&++u===r&&(c=i),(p=d.nextSibling)!==null)break;d=f,f=d.parentNode}d=p}t=a===-1||c===-1?null:{start:a,end:c}}else t=null}t=t||{start:0,end:0}}else t=null;for(TS={focusedElem:e,selectionRange:t},zf=!1,ne=n;ne!==null;)if(n=ne,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,ne=e;else for(;ne!==null;){n=ne;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,w=y.memoizedState,S=n.stateNode,v=S.getSnapshotBeforeUpdate(n.elementType===n.type?m:Ar(n.type,m),w);S.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var P=n.stateNode.containerInfo;P.nodeType===1?P.textContent="":P.nodeType===9&&P.documentElement&&P.removeChild(P.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(q(163))}}catch(E){St(n,n.return,E)}if(e=n.sibling,e!==null){e.return=n.return,ne=e;break}ne=n.return}return y=eP,eP=!1,y}function Al(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&&WS(n,t,s)}o=o.next}while(o!==r)}}function Np(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 GS(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 zT(e){var n=e.alternate;n!==null&&(e.alternate=null,zT(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[ro],delete n[ru],delete n[AS],delete n[M4],delete n[A4])),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 BT(e){return e.tag===5||e.tag===3||e.tag===4}function tP(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||BT(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 VS(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=Hf));else if(r!==4&&(e=e.child,e!==null))for(VS(e,n,t),e=e.sibling;e!==null;)VS(e,n,t),e=e.sibling}function YS(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(YS(e,n,t),e=e.sibling;e!==null;)YS(e,n,t),e=e.sibling}var Lt=null,Or=!1;function fs(e,n,t){for(t=t.child;t!==null;)UT(e,n,t),t=t.sibling}function UT(e,n,t){if(lo&&typeof lo.onCommitFiberUnmount=="function")try{lo.onCommitFiberUnmount(Mp,t)}catch{}switch(t.tag){case 5:tn||Aa(t,n);case 6:var r=Lt,o=Or;Lt=null,fs(e,n,t),Lt=r,Or=o,Lt!==null&&(Or?(e=Lt,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):Lt.removeChild(t.stateNode));break;case 18:Lt!==null&&(Or?(e=Lt,t=t.stateNode,e.nodeType===8?mm(e.parentNode,t):e.nodeType===1&&mm(e,t),Ql(e)):mm(Lt,t.stateNode));break;case 4:r=Lt,o=Or,Lt=t.stateNode.containerInfo,Or=!0,fs(e,n,t),Lt=r,Or=o;break;case 0:case 11:case 14:case 15:if(!tn&&(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)&&WS(t,n,i),o=o.next}while(o!==r)}fs(e,n,t);break;case 1:if(!tn&&(Aa(t,n),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(a){St(t,n,a)}fs(e,n,t);break;case 21:fs(e,n,t);break;case 22:t.mode&1?(tn=(r=tn)||t.memoizedState!==null,fs(e,n,t),tn=r):fs(e,n,t);break;default:fs(e,n,t)}}function nP(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new Y4),n.forEach(function(r){var o=oz.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function Mr(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var s=e,i=n,a=i;e:for(;a!==null;){switch(a.tag){case 5:Lt=a.stateNode,Or=!1;break e;case 3:Lt=a.stateNode.containerInfo,Or=!0;break e;case 4:Lt=a.stateNode.containerInfo,Or=!0;break e}a=a.return}if(Lt===null)throw Error(q(160));UT(s,i,o),Lt=null,Or=!1;var c=o.alternate;c!==null&&(c.return=null),o.return=null}catch(l){St(o,n,l)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)HT(n,e),n=n.sibling}function HT(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Mr(n,e),qr(e),r&4){try{Al(3,e,e.return),Np(3,e)}catch(m){St(e,e.return,m)}try{Al(5,e,e.return)}catch(m){St(e,e.return,m)}}break;case 1:Mr(n,e),qr(e),r&512&&t!==null&&Aa(t,t.return);break;case 5:if(Mr(n,e),qr(e),r&512&&t!==null&&Aa(t,t.return),e.flags&32){var o=e.stateNode;try{Yl(o,"")}catch(m){St(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,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&dk(o,s),SS(a,i);var l=SS(a,s);for(i=0;i<c.length;i+=2){var u=c[i],d=c[i+1];u==="style"?mk(o,d):u==="dangerouslySetInnerHTML"?pk(o,d):u==="children"?Yl(o,d):A0(o,u,d,l)}switch(a){case"input":fS(o,s);break;case"textarea":hk(o,s);break;case"select":var f=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var p=s.value;p!=null?Wa(o,!!s.multiple,p,!1):f!==!!s.multiple&&(s.defaultValue!=null?Wa(o,!!s.multiple,s.defaultValue,!0):Wa(o,!!s.multiple,s.multiple?[]:"",!1))}o[ru]=s}catch(m){St(e,e.return,m)}}break;case 6:if(Mr(n,e),qr(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(m){St(e,e.return,m)}}break;case 3:if(Mr(n,e),qr(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{Ql(n.containerInfo)}catch(m){St(e,e.return,m)}break;case 4:Mr(n,e),qr(e);break;case 13:Mr(n,e),qr(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(dx=Ct())),r&4&&nP(e);break;case 22:if(u=t!==null&&t.memoizedState!==null,e.mode&1?(tn=(l=tn)||u,Mr(n,e),tn=l):Mr(n,e),qr(e),r&8192){if(l=e.memoizedState!==null,(e.stateNode.isHidden=l)&&!u&&e.mode&1)for(ne=e,u=e.child;u!==null;){for(d=ne=u;ne!==null;){switch(f=ne,p=f.child,f.tag){case 0:case 11:case 14:case 15:Al(4,f,f.return);break;case 1:Aa(f,f.return);var y=f.stateNode;if(typeof y.componentWillUnmount=="function"){r=f,t=f.return;try{n=r,y.props=n.memoizedProps,y.state=n.memoizedState,y.componentWillUnmount()}catch(m){St(r,t,m)}}break;case 5:Aa(f,f.return);break;case 22:if(f.memoizedState!==null){oP(d);continue}}p!==null?(p.return=f,ne=p):oP(d)}u=u.sibling}e:for(u=null,d=e;;){if(d.tag===5){if(u===null){u=d;try{o=d.stateNode,l?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=d.stateNode,c=d.memoizedProps.style,i=c!=null&&c.hasOwnProperty("display")?c.display:null,a.style.display=gk("display",i))}catch(m){St(e,e.return,m)}}}else if(d.tag===6){if(u===null)try{d.stateNode.nodeValue=l?"":d.memoizedProps}catch(m){St(e,e.return,m)}}else if((d.tag!==22&&d.tag!==23||d.memoizedState===null||d===e)&&d.child!==null){d.child.return=d,d=d.child;continue}if(d===e)break e;for(;d.sibling===null;){if(d.return===null||d.return===e)break e;u===d&&(u=null),d=d.return}u===d&&(u=null),d.sibling.return=d.return,d=d.sibling}}break;case 19:Mr(n,e),qr(e),r&4&&nP(e);break;case 21:break;default:Mr(n,e),qr(e)}}function qr(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(BT(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&&(Yl(o,""),r.flags&=-33);var s=tP(e);YS(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=tP(e);VS(e,a,i);break;default:throw Error(q(161))}}catch(c){St(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function q4(e,n,t){ne=e,KT(e)}function KT(e,n,t){for(var r=(e.mode&1)!==0;ne!==null;){var o=ne,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||_d;if(!i){var a=o.alternate,c=a!==null&&a.memoizedState!==null||tn;a=_d;var l=tn;if(_d=i,(tn=c)&&!l)for(ne=o;ne!==null;)i=ne,c=i.child,i.tag===22&&i.memoizedState!==null?sP(o):c!==null?(c.return=i,ne=c):sP(o);for(;s!==null;)ne=s,KT(s),s=s.sibling;ne=o,_d=a,tn=l}rP(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,ne=s):rP(e)}}function rP(e){for(;ne!==null;){var n=ne;if(n.flags&8772){var t=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:tn||Np(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!tn)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:Ar(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&B1(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}B1(n,i,t)}break;case 5:var a=n.stateNode;if(t===null&&n.flags&4){t=a;var c=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&t.focus();break;case"img":c.src&&(t.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var l=n.alternate;if(l!==null){var u=l.memoizedState;if(u!==null){var d=u.dehydrated;d!==null&&Ql(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}tn||n.flags&512&&GS(n)}catch(f){St(n,n.return,f)}}if(n===e){ne=null;break}if(t=n.sibling,t!==null){t.return=n.return,ne=t;break}ne=n.return}}function oP(e){for(;ne!==null;){var n=ne;if(n===e){ne=null;break}var t=n.sibling;if(t!==null){t.return=n.return,ne=t;break}ne=n.return}}function sP(e){for(;ne!==null;){var n=ne;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{Np(4,n)}catch(c){St(n,t,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var o=n.return;try{r.componentDidMount()}catch(c){St(n,o,c)}}var s=n.return;try{GS(n)}catch(c){St(n,s,c)}break;case 5:var i=n.return;try{GS(n)}catch(c){St(n,i,c)}}}catch(c){St(n,n.return,c)}if(n===e){ne=null;break}var a=n.sibling;if(a!==null){a.return=n.return,ne=a;break}ne=n.return}}var Z4=Math.ceil,ep=ns.ReactCurrentDispatcher,lx=ns.ReactCurrentOwner,Pr=ns.ReactCurrentBatchConfig,Te=0,jt=null,Et=null,Kt=0,Gn=0,ja=Qs(0),kt=0,lu=null,Di=0,zp=0,ux=0,jl=null,En=null,dx=0,dc=1/0,Oo=null,tp=!1,XS=null,Ls=null,kd=!1,Es=null,np=0,Ol=0,qS=null,wh=-1,bh=0;function gn(){return Te&6?Ct():wh!==-1?wh:wh=Ct()}function Fs(e){return e.mode&1?Te&2&&Kt!==0?Kt&-Kt:O4.transition!==null?(bh===0&&(bh=kk()),bh):(e=Ne,e!==0||(e=window.event,e=e===void 0?16:Dk(e.type)),e):1}function zr(e,n,t,r){if(50<Ol)throw Ol=0,qS=null,Error(q(185));ju(e,t,r),(!(Te&2)||e!==jt)&&(e===jt&&(!(Te&2)&&(zp|=t),kt===4&&Ps(e,Kt)),Rn(e,r),t===1&&Te===0&&!(n.mode&1)&&(dc=Ct()+500,Rp&&Js()))}function Rn(e,n){var t=e.callbackNode;ON(e,n);var r=Nf(e,e===jt?Kt:0);if(r===0)t!==null&&p1(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&p1(t),n===1)e.tag===0?j4(iP.bind(null,e)):eT(iP.bind(null,e)),T4(function(){!(Te&6)&&Js()}),t=null;else{switch(Tk(r)){case 1:t=L0;break;case 4:t=Ek;break;case 16:t=Ff;break;case 536870912:t=_k;break;default:t=Ff}t=QT(t,WT.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function WT(e,n){if(wh=-1,bh=0,Te&6)throw Error(q(327));var t=e.callbackNode;if(qa()&&e.callbackNode!==t)return null;var r=Nf(e,e===jt?Kt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=rp(e,r);else{n=r;var o=Te;Te|=2;var s=VT();(jt!==e||Kt!==n)&&(Oo=null,dc=Ct()+500,Ii(e,n));do try{ez();break}catch(a){GT(e,a)}while(!0);q0(),ep.current=s,Te=o,Et!==null?n=0:(jt=null,Kt=0,n=kt)}if(n!==0){if(n===2&&(o=PS(e),o!==0&&(r=o,n=ZS(e,o))),n===1)throw t=lu,Ii(e,0),Ps(e,r),Rn(e,Ct()),t;if(n===6)Ps(e,r);else{if(o=e.current.alternate,!(r&30)&&!Q4(o)&&(n=rp(e,r),n===2&&(s=PS(e),s!==0&&(r=s,n=ZS(e,s))),n===1))throw t=lu,Ii(e,0),Ps(e,r),Rn(e,Ct()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:gi(e,En,Oo);break;case 3:if(Ps(e,r),(r&130023424)===r&&(n=dx+500-Ct(),10<n)){if(Nf(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){gn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=MS(gi.bind(null,e,En,Oo),n);break}gi(e,En,Oo);break;case 4:if(Ps(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var i=31-Nr(r);s=1<<i,i=n[i],i>o&&(o=i),r&=~s}if(r=o,r=Ct()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Z4(r/1960))-r,10<r){e.timeoutHandle=MS(gi.bind(null,e,En,Oo),r);break}gi(e,En,Oo);break;case 5:gi(e,En,Oo);break;default:throw Error(q(329))}}}return Rn(e,Ct()),e.callbackNode===t?WT.bind(null,e):null}function ZS(e,n){var t=jl;return e.current.memoizedState.isDehydrated&&(Ii(e,n).flags|=256),e=rp(e,n),e!==2&&(n=En,En=t,n!==null&&QS(n)),e}function QS(e){En===null?En=e:En.push.apply(En,e)}function Q4(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(!Kr(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 Ps(e,n){for(n&=~ux,n&=~zp,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-Nr(n),r=1<<t;e[t]=-1,n&=~r}}function iP(e){if(Te&6)throw Error(q(327));qa();var n=Nf(e,0);if(!(n&1))return Rn(e,Ct()),null;var t=rp(e,n);if(e.tag!==0&&t===2){var r=PS(e);r!==0&&(n=r,t=ZS(e,r))}if(t===1)throw t=lu,Ii(e,0),Ps(e,n),Rn(e,Ct()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,gi(e,En,Oo),Rn(e,Ct()),null}function hx(e,n){var t=Te;Te|=1;try{return e(n)}finally{Te=t,Te===0&&(dc=Ct()+500,Rp&&Js())}}function Ri(e){Es!==null&&Es.tag===0&&!(Te&6)&&qa();var n=Te;Te|=1;var t=Pr.transition,r=Ne;try{if(Pr.transition=null,Ne=1,e)return e()}finally{Ne=r,Pr.transition=t,Te=n,!(Te&6)&&Js()}}function fx(){Gn=ja.current,tt(ja)}function Ii(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,k4(t)),Et!==null)for(t=Et.return;t!==null;){var r=t;switch(V0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Kf();break;case 3:lc(),tt(On),tt(ln),nx();break;case 5:tx(r);break;case 4:lc();break;case 13:tt(ct);break;case 19:tt(ct);break;case 10:Z0(r.type._context);break;case 22:case 23:fx()}t=t.return}if(jt=e,Et=e=Ns(e.current,null),Kt=Gn=n,kt=0,lu=null,ux=zp=Di=0,En=jl=null,vi!==null){for(n=0;n<vi.length;n++)if(t=vi[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}vi=null}return e}function GT(e,n){do{var t=Et;try{if(q0(),Sh.current=Jf,Qf){for(var r=dt.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Qf=!1}if(Oi=0,Mt=_t=dt=null,Ml=!1,iu=0,lx.current=null,t===null||t.return===null){kt=1,lu=n,Et=null;break}e:{var s=e,i=t.return,a=t,c=n;if(n=Kt,a.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var l=c,u=a,d=u.tag;if(!(u.mode&1)&&(d===0||d===11||d===15)){var f=u.alternate;f?(u.updateQueue=f.updateQueue,u.memoizedState=f.memoizedState,u.lanes=f.lanes):(u.updateQueue=null,u.memoizedState=null)}var p=V1(i);if(p!==null){p.flags&=-257,Y1(p,i,a,s,n),p.mode&1&&G1(s,l,n),n=p,c=l;var y=n.updateQueue;if(y===null){var m=new Set;m.add(c),n.updateQueue=m}else y.add(c);break e}else{if(!(n&1)){G1(s,l,n),px();break e}c=Error(q(426))}}else if(rt&&a.mode&1){var w=V1(i);if(w!==null){!(w.flags&65536)&&(w.flags|=256),Y1(w,i,a,s,n),Y0(uc(c,a));break e}}s=c=uc(c,a),kt!==4&&(kt=2),jl===null?jl=[s]:jl.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var S=TT(s,c,n);z1(s,S);break e;case 1:a=c;var v=s.type,P=s.stateNode;if(!(s.flags&128)&&(typeof v.getDerivedStateFromError=="function"||P!==null&&typeof P.componentDidCatch=="function"&&(Ls===null||!Ls.has(P)))){s.flags|=65536,n&=-n,s.lanes|=n;var E=$T(s,a,n);z1(s,E);break e}}s=s.return}while(s!==null)}XT(t)}catch(C){n=C,Et===t&&t!==null&&(Et=t=t.return);continue}break}while(!0)}function VT(){var e=ep.current;return ep.current=Jf,e===null?Jf:e}function px(){(kt===0||kt===3||kt===2)&&(kt=4),jt===null||!(Di&268435455)&&!(zp&268435455)||Ps(jt,Kt)}function rp(e,n){var t=Te;Te|=2;var r=VT();(jt!==e||Kt!==n)&&(Oo=null,Ii(e,n));do try{J4();break}catch(o){GT(e,o)}while(!0);if(q0(),Te=t,ep.current=r,Et!==null)throw Error(q(261));return jt=null,Kt=0,kt}function J4(){for(;Et!==null;)YT(Et)}function ez(){for(;Et!==null&&!IN();)YT(Et)}function YT(e){var n=ZT(e.alternate,e,Gn);e.memoizedProps=e.pendingProps,n===null?XT(e):Et=n,lx.current=null}function XT(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=V4(t,n),t!==null){t.flags&=32767,Et=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{kt=6,Et=null;return}}else if(t=G4(t,n,Gn),t!==null){Et=t;return}if(n=n.sibling,n!==null){Et=n;return}Et=n=e}while(n!==null);kt===0&&(kt=5)}function gi(e,n,t){var r=Ne,o=Pr.transition;try{Pr.transition=null,Ne=1,tz(e,n,t,r)}finally{Pr.transition=o,Ne=r}return null}function tz(e,n,t,r){do qa();while(Es!==null);if(Te&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(DN(e,s),e===jt&&(Et=jt=null,Kt=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||kd||(kd=!0,QT(Ff,function(){return qa(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=Pr.transition,Pr.transition=null;var i=Ne;Ne=1;var a=Te;Te|=4,lx.current=null,X4(e,t),HT(t,e),w4(TS),zf=!!kS,TS=kS=null,e.current=t,q4(t),EN(),Te=a,Ne=i,Pr.transition=s}else e.current=t;if(kd&&(kd=!1,Es=e,np=o),s=e.pendingLanes,s===0&&(Ls=null),TN(t.stateNode),Rn(e,Ct()),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(tp)throw tp=!1,e=XS,XS=null,e;return np&1&&e.tag!==0&&qa(),s=e.pendingLanes,s&1?e===qS?Ol++:(Ol=0,qS=e):Ol=0,Js(),null}function qa(){if(Es!==null){var e=Tk(np),n=Pr.transition,t=Ne;try{if(Pr.transition=null,Ne=16>e?16:e,Es===null)var r=!1;else{if(e=Es,Es=null,np=0,Te&6)throw Error(q(331));var o=Te;for(Te|=4,ne=e.current;ne!==null;){var s=ne,i=s.child;if(ne.flags&16){var a=s.deletions;if(a!==null){for(var c=0;c<a.length;c++){var l=a[c];for(ne=l;ne!==null;){var u=ne;switch(u.tag){case 0:case 11:case 15:Al(8,u,s)}var d=u.child;if(d!==null)d.return=u,ne=d;else for(;ne!==null;){u=ne;var f=u.sibling,p=u.return;if(zT(u),u===l){ne=null;break}if(f!==null){f.return=p,ne=f;break}ne=p}}}var y=s.alternate;if(y!==null){var m=y.child;if(m!==null){y.child=null;do{var w=m.sibling;m.sibling=null,m=w}while(m!==null)}}ne=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,ne=i;else e:for(;ne!==null;){if(s=ne,s.flags&2048)switch(s.tag){case 0:case 11:case 15:Al(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,ne=S;break e}ne=s.return}}var v=e.current;for(ne=v;ne!==null;){i=ne;var P=i.child;if(i.subtreeFlags&2064&&P!==null)P.return=i,ne=P;else e:for(i=v;ne!==null;){if(a=ne,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:Np(9,a)}}catch(C){St(a,a.return,C)}if(a===i){ne=null;break e}var E=a.sibling;if(E!==null){E.return=a.return,ne=E;break e}ne=a.return}}if(Te=o,Js(),lo&&typeof lo.onPostCommitFiberRoot=="function")try{lo.onPostCommitFiberRoot(Mp,e)}catch{}r=!0}return r}finally{Ne=t,Pr.transition=n}}return!1}function aP(e,n,t){n=uc(t,n),n=TT(e,n,1),e=Rs(e,n,1),n=gn(),e!==null&&(ju(e,1,n),Rn(e,n))}function St(e,n,t){if(e.tag===3)aP(e,e,t);else for(;n!==null;){if(n.tag===3){aP(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Ls===null||!Ls.has(r))){e=uc(t,e),e=$T(n,e,1),n=Rs(n,e,1),e=gn(),n!==null&&(ju(n,1,e),Rn(n,e));break}}n=n.return}}function nz(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=gn(),e.pingedLanes|=e.suspendedLanes&t,jt===e&&(Kt&t)===t&&(kt===4||kt===3&&(Kt&130023424)===Kt&&500>Ct()-dx?Ii(e,0):ux|=t),Rn(e,n)}function qT(e,n){n===0&&(e.mode&1?(n=Sd,Sd<<=1,!(Sd&130023424)&&(Sd=4194304)):n=1);var t=gn();e=qo(e,n),e!==null&&(ju(e,n,t),Rn(e,t))}function rz(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),qT(e,t)}function oz(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),qT(e,t)}var ZT;ZT=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||On.current)$n=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return $n=!1,W4(e,n,t);$n=!!(e.flags&131072)}else $n=!1,rt&&n.flags&1048576&&tT(n,Vf,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;xh(e,n),e=n.pendingProps;var o=ic(n,ln.current);Xa(n,t),o=ox(null,n,r,e,o,t);var s=sx();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,Dn(r)?(s=!0,Wf(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,J0(n),o.updater=Fp,n.stateNode=o,o._reactInternals=n,FS(n,r,e,t),n=BS(null,n,r,!0,s,t)):(n.tag=0,rt&&s&&G0(n),fn(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(xh(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=iz(r),e=Ar(r,e),o){case 0:n=zS(null,n,r,e,t);break e;case 1:n=Z1(null,n,r,e,t);break e;case 11:n=X1(null,n,r,e,t);break e;case 14:n=q1(null,n,r,Ar(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:Ar(r,o),zS(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Ar(r,o),Z1(e,n,r,o,t);case 3:e:{if(OT(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,aT(e,n),qf(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=uc(Error(q(423)),n),n=Q1(e,n,r,t,o);break e}else if(r!==o){o=uc(Error(q(424)),n),n=Q1(e,n,r,t,o);break e}else for(Zn=Ds(n.stateNode.containerInfo.firstChild),tr=n,rt=!0,Rr=null,t=sT(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(ac(),r===o){n=Zo(e,n,t);break e}fn(e,n,r,t)}n=n.child}return n;case 5:return cT(n),e===null&&DS(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,$S(r,o)?i=null:s!==null&&$S(r,s)&&(n.flags|=32),jT(e,n),fn(e,n,i,t),n.child;case 6:return e===null&&DS(n),null;case 13:return DT(e,n,t);case 4:return ex(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=cc(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:Ar(r,o),X1(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,Ye(Yf,r._currentValue),r._currentValue=i,s!==null)if(Kr(s.value,i)){if(s.children===o.children&&!On.current){n=Zo(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 c=a.firstContext;c!==null;){if(c.context===r){if(s.tag===1){c=Uo(-1,t&-t),c.tag=2;var l=s.updateQueue;if(l!==null){l=l.shared;var u=l.pending;u===null?c.next=c:(c.next=u.next,u.next=c),l.pending=c}}s.lanes|=t,c=s.alternate,c!==null&&(c.lanes|=t),RS(s.return,t,n),a.lanes|=t;break}c=c.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),RS(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,Xa(n,t),o=Cr(o),r=r(o),n.flags|=1,fn(e,n,r,t),n.child;case 14:return r=n.type,o=Ar(r,n.pendingProps),o=Ar(r.type,o),q1(e,n,r,o,t);case 15:return MT(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Ar(r,o),xh(e,n),n.tag=1,Dn(r)?(e=!0,Wf(n)):e=!1,Xa(n,t),kT(n,r,o),FS(n,r,o,t),BS(null,n,r,!0,e,t);case 19:return RT(e,n,t);case 22:return AT(e,n,t)}throw Error(q(156,n.tag))};function QT(e,n){return Ik(e,n)}function sz(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 wr(e,n,t,r){return new sz(e,n,t,r)}function gx(e){return e=e.prototype,!(!e||!e.isReactComponent)}function iz(e){if(typeof e=="function")return gx(e)?1:0;if(e!=null){if(e=e.$$typeof,e===O0)return 11;if(e===D0)return 14}return 2}function Ns(e,n){var t=e.alternate;return t===null?(t=wr(e.tag,n,e.key,e.mode),t.elementType=e.elementType,t.type=e.type,t.stateNode=e.stateNode,t.alternate=e,e.alternate=t):(t.pendingProps=n,t.type=e.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=e.flags&14680064,t.childLanes=e.childLanes,t.lanes=e.lanes,t.child=e.child,t.memoizedProps=e.memoizedProps,t.memoizedState=e.memoizedState,t.updateQueue=e.updateQueue,n=e.dependencies,t.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},t.sibling=e.sibling,t.index=e.index,t.ref=e.ref,t}function Ph(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")gx(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case Pa:return Ei(t.children,o,s,n);case j0:i=8,o|=8;break;case cS:return e=wr(12,t,n,o|2),e.elementType=cS,e.lanes=s,e;case lS:return e=wr(13,t,n,o),e.elementType=lS,e.lanes=s,e;case uS:return e=wr(19,t,n,o),e.elementType=uS,e.lanes=s,e;case ck:return Bp(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case ik:i=10;break e;case ak:i=9;break e;case O0:i=11;break e;case D0:i=14;break e;case vs:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=wr(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function Ei(e,n,t,r){return e=wr(7,e,r,n),e.lanes=t,e}function Bp(e,n,t,r){return e=wr(22,e,r,n),e.elementType=ck,e.lanes=t,e.stateNode={isHidden:!1},e}function Cm(e,n,t){return e=wr(6,e,null,n),e.lanes=t,e}function Im(e,n,t){return n=wr(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function az(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=sm(0),this.expirationTimes=sm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=sm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function mx(e,n,t,r,o,s,i,a,c){return e=new az(e,n,t,a,c),n===1?(n=1,s===!0&&(n|=8)):n=0,s=wr(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},J0(s),e}function cz(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:ba,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function JT(e){if(!e)return Hs;e=e._reactInternals;e:{if(Vi(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(Dn(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(Dn(t))return Jk(e,t,n)}return n}function e2(e,n,t,r,o,s,i,a,c){return e=mx(t,r,!0,e,o,s,i,a,c),e.context=JT(null),t=e.current,r=gn(),o=Fs(t),s=Uo(r,o),s.callback=n??null,Rs(t,s,o),e.current.lanes=o,ju(e,o,r),Rn(e,r),e}function Up(e,n,t,r){var o=n.current,s=gn(),i=Fs(o);return t=JT(t),n.context===null?n.context=t:n.pendingContext=t,n=Uo(s,i),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Rs(o,n,i),e!==null&&(zr(e,o,i,s),yh(e,o,i)),i}function op(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 cP(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function yx(e,n){cP(e,n),(e=e.alternate)&&cP(e,n)}function lz(){return null}var t2=typeof reportError=="function"?reportError:function(e){console.error(e)};function Sx(e){this._internalRoot=e}Hp.prototype.render=Sx.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));Up(e,n,null,null)};Hp.prototype.unmount=Sx.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Ri(function(){Up(null,e,null,null)}),n[Xo]=null}};function Hp(e){this._internalRoot=e}Hp.prototype.unstable_scheduleHydration=function(e){if(e){var n=Ak();e={blockedOn:null,target:e,priority:n};for(var t=0;t<bs.length&&n!==0&&n<bs[t].priority;t++);bs.splice(t,0,e),t===0&&Ok(e)}};function vx(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Kp(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function lP(){}function uz(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var l=op(i);s.call(l)}}var i=e2(n,r,e,0,null,!1,!1,"",lP);return e._reactRootContainer=i,e[Xo]=i.current,tu(e.nodeType===8?e.parentNode:e),Ri(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var l=op(c);a.call(l)}}var c=mx(e,0,!1,null,null,!1,!1,"",lP);return e._reactRootContainer=c,e[Xo]=c.current,tu(e.nodeType===8?e.parentNode:e),Ri(function(){Up(n,c,t,r)}),c}function Wp(e,n,t,r,o){var s=t._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var c=op(i);a.call(c)}}Up(n,i,e,o)}else i=uz(t,n,e,o,r);return op(i)}$k=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=Sl(n.pendingLanes);t!==0&&(F0(n,t|1),Rn(n,Ct()),!(Te&6)&&(dc=Ct()+500,Js()))}break;case 13:Ri(function(){var r=qo(e,1);if(r!==null){var o=gn();zr(r,e,1,o)}}),yx(e,1)}};N0=function(e){if(e.tag===13){var n=qo(e,134217728);if(n!==null){var t=gn();zr(n,e,134217728,t)}yx(e,134217728)}};Mk=function(e){if(e.tag===13){var n=Fs(e),t=qo(e,n);if(t!==null){var r=gn();zr(t,e,n,r)}yx(e,n)}};Ak=function(){return Ne};jk=function(e,n){var t=Ne;try{return Ne=e,n()}finally{Ne=t}};xS=function(e,n,t){switch(n){case"input":if(fS(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=Dp(r);if(!o)throw Error(q(90));uk(r),fS(r,o)}}}break;case"textarea":hk(e,t);break;case"select":n=t.value,n!=null&&Wa(e,!!t.multiple,n,!1)}};vk=hx;xk=Ri;var dz={usingClientEntryPoint:!1,Events:[Du,_a,Dp,yk,Sk,hx]},Jc={findFiberByHostInstance:Si,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},hz={bundleType:Jc.bundleType,version:Jc.version,rendererPackageName:Jc.rendererPackageName,rendererConfig:Jc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ns.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=Pk(e),e===null?null:e.stateNode},findFiberByHostInstance:Jc.findFiberByHostInstance||lz,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 Td=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Td.isDisabled&&Td.supportsFiber)try{Mp=Td.inject(hz),lo=Td}catch{}}cr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=dz;cr.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!vx(n))throw Error(q(200));return cz(e,n,null,t)};cr.createRoot=function(e,n){if(!vx(e))throw Error(q(299));var t=!1,r="",o=t2;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=mx(e,1,!1,null,null,t,!1,r,o),e[Xo]=n.current,tu(e.nodeType===8?e.parentNode:e),new Sx(n)};cr.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=Pk(n),e=e===null?null:e.stateNode,e};cr.flushSync=function(e){return Ri(e)};cr.hydrate=function(e,n,t){if(!Kp(n))throw Error(q(200));return Wp(null,e,n,!0,t)};cr.hydrateRoot=function(e,n,t){if(!vx(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=t2;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=e2(n,null,e,1,t??null,o,!1,s,i),e[Xo]=n.current,tu(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 Hp(n)};cr.render=function(e,n,t){if(!Kp(n))throw Error(q(200));return Wp(null,e,n,!1,t)};cr.unmountComponentAtNode=function(e){if(!Kp(e))throw Error(q(40));return e._reactRootContainer?(Ri(function(){Wp(null,null,e,!1,function(){e._reactRootContainer=null,e[Xo]=null})}),!0):!1};cr.unstable_batchedUpdates=hx;cr.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!Kp(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return Wp(e,n,t,!1,r)};cr.version="18.3.1-next-f1338f8080-20240426";function n2(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n2)}catch(e){console.error(e)}}n2(),nk.exports=cr;var Yi=nk.exports;const fz=Ys(Yi);var JS={},r2,uP=Yi;r2=JS.createRoot=uP.createRoot,JS.hydrateRoot=uP.hydrateRoot;function o2(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 Ks({children:e,className:n="",...t}){return h.jsx("svg",{...t,className:ue("tl-svg-container",n),children:e})}function xx(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,c=n.x-e.x,l=n.y-e.y,u=i*s-a*o,d=c*s-l*o,f=a*c-i*l;if(u===0||d===0||f===0)return null;if(f!==0){const p=u/f,y=d/f;if(0<=p&&p<=1&&0<=y&&y<=1)return b.AddXY(e,p*c,p*l)}return null}function Lu(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 c=Math.sqrt(a),l=(-s+c)/(2*o),u=(-s-c)/(2*o);if((l<0||l>1)&&(u<0||u>1))return null;const d=[];return 0<=l&&l<=1&&d.push(b.Lrp(e,n,l)),0<=u&&u<=1&&d.push(b.Lrp(e,n,u)),d.length===0?null:d}function pz(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=xx(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function wx(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=xx(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function gz(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),c=Math.sqrt(n*n-a*a);return o/=i,s/=i,[new b(e.x+o*a-s*c,e.y+s*a+o*c),new b(e.x+o*a+s*c,e.y+s*a-o*c)]}function ev(e,n,t){const r=[];let o,s,i;for(let a=0,c=t.length;a<c;a++)o=t[a],s=t[(a+1)%t.length],i=Lu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function dP(e,n,t){const r=[];let o,s,i;for(let a=1,c=t.length;a<c;a++)o=t[a-1],s=t[a],i=Lu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function $d(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function bx(e,n,t,r){return $d(e,t,r)!==$d(n,t,r)&&$d(e,n,t)!==$d(e,n,r)}function hP(e,n){const t=new Map;let r,o,s,i;for(let a=0,c=e.length;a<c;a++)if(r=e[a],er(r,n)){const l=Em(r);t.has(l)||t.set(l,r)}for(let a=0,c=n.length;a<c;a++)if(r=n[a],er(r,e)){const l=Em(r);t.has(l)||t.set(l,r)}for(let a=0,c=e.length;a<c;a++){r=e[a],o=e[(a+1)%e.length];for(let l=0,u=n.length;l<u;l++){s=n[l],i=n[(l+1)%n.length];const d=xx(r,o,s,i);if(d!==null){const f=Em(d);t.has(f)||t.set(f,d)}}}return t.size===0?null:mz([...t.values()])}function Em(e){return`${e.x},${e.y}`}function mz(e){const n=b.Average(e);return e.sort((t,r)=>b.Angle(n,t)-b.Angle(n,r))}function s2(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 c=0,l=n.length;c<l;c++)if(o=n[c],s=n[(c+1)%l],bx(t,r,o,s))return!0}return!1}function yz(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 c=1,l=n.length;c<l;c++)if(o=n[c-1],s=n[c],bx(t,r,o,s))return!0}return!1}class zo extends qs{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=b.Sub(t,r).dpr(s)/i,c=r.x+s.x*a;if(c<Math.min(r.x,o.x))return r.x<o.x?r:o;if(c>Math.max(r.x,o.x))return r.x>o.x?r:o;const l=r.y+s.y*a;return l<Math.min(r.y,o.y)?r.y<o.y?r:o:l>Math.max(r.y,o.y)?r.y>o.y?r:o:new b(c,l)}hitTestLineSegment(t,r,o=0){return bx(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 Ec extends qs{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 zo({start:s,end:i}))}this.isClosed&&this._segments.push(new zo({start:t[t.length-1],end:t[0]}))}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){return this.points}nearestPoint(t){const{segments:r}=this;let o=this.points[0],s=1/0,i,a;for(let c=0;c<r.length;c++)i=r[c].nearestPoint(t),a=b.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 bt extends Ec{constructor(n){super({...n}),this.isClosed=!0}}class Qo extends bt{constructor(t){const{x:r=0,y:o=0,width:s,height:i}=t;super({...t,points:[new b(r,o),new b(r+s,o),new b(r+s,o+i),new b(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 J(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:o,h:s}=this;return`M${t},${r} h${o} v${s} h-${o}z`}}class Br{constructor(n){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(Br,"props"),g(Br,"migrations"),g(Br,"type");function Sz(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:c="dashed"}=t;let l=0,u=0,d=1,f=0,p=0;switch(c){case"dashed":{d=1,l=Math.min(n*a,e/4);break}case"dotted":{d=100,l=n/d;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=l/2,p+=l/2):s==="skip"&&(e-=l,p-=l),i==="outset"?e+=l/2:i==="skip"&&(e-=l)),u=Math.floor(e/l/(2*d)),u-=u%o,u<3&&c==="dashed"?e/n<5?(l=e,u=1,f=0):(l=e*.333,f=e*.333):(u=Math.max(u,3),l=e/u/(2*d),r?(p=l/2,f=(e-u*l)/u):f=(e-u*l)/Math.max(1,u-1)),{strokeDasharray:[l,f].join(" "),strokeDashoffset:p.toString()}}function fP({bounds:e,className:n}){const t=B(),r=W("zoom level",()=>t.getZoomLevel(),[t]);return h.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=Sz(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return h.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class Ch extends Br{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 Qo({width:1,height:1,isFilled:!1}):new Hr({children:r.map(o=>{const s=this.editor.getShape(o),i=this.editor.getShapeGeometry(o),a=this.editor.getShapeLocalTransform(s).applyToPoints(i.vertices);return i.isClosed?new bt({points:a,isFilled:!0}):new Ec({points:a})})})}component(t){const r=this.editor.getErasingShapeIds().includes(t.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(c=>c!==t.id&&this.editor.isShapeOfType(this.editor.getShape(c),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==t.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(t).bounds;return h.jsx(Ks,{id:t.id,children:h.jsx(fP,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return h.jsx(fP,{className:"",bounds:r})}}g(Ch,"type","group"),g(Ch,"props",ZE),g(Ch,"migrations",QE);const i2=[Ch],vz=new Set(i2.map(e=>e.type));function a2(e){const n=[...i2],t=new Set;for(const r of e){if(vz.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}function pP(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 sn(e)}}class xz{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(!pP(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!pP(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 tv extends xz{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:sn(r,"type")}}}function wz(e,n,t){return fetch(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function bz(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 Md(e,n,t){if(t.length===0)return[];const r=new Map;for(const s of ye(t.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:ye(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})=>Pz(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>Cz(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>Iz(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>Ez(s,i,o));break}}return o}function Pz(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=nc(o,s,e.size);t.push(...Array.from(e.values()).sort(nn).map((a,c)=>({...a,index:i[c]})))}}function Cz(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=nc(o,s,e.size);t.push(...Array.from(e.values()).sort(nn).map((a,c)=>({...a,index:i[c]})))}}function Iz(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:c}=o;nc(n[i].index,(s=n[i+1])==null?void 0:s.index,i-c).forEach((l,u)=>t.push({...n[c+u],index:l})),o={name:"skipping"};break}}}}function Ez(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;nc((s=n[i-1])==null?void 0:s.index,n[i].index,o.selectIndex-i).forEach((c,l)=>{t.push({...n[i+l+1],index:c})}),o={name:"skipping"};break}}}}function c2({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:xt(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function Ih({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:c})=>{const l=mr(a.parentId)?n.getShapePageTransform(a.parentId):oe.Identity(),u=b.RotWith(c,o,e),d=oe.applyToPoint(oe.Inverse(l),u),f=Ms(a.rotation+e);return{id:a.id,type:a.type,x:d.x,y:d.y,rotation:f}}));const i=[];s.forEach(({shape:a})=>{var d,f,p;const c=n.getShape(a.id);if(!c)return;const l=n.getShapeUtil(a);if(r==="start"||r==="one-off"){const y=(d=l.onRotateStart)==null?void 0:d.call(l,a);y&&i.push(y)}const u=(f=l.onRotate)==null?void 0:f.call(l,a,c);if(u&&i.push(u),r==="end"||r==="one-off"){const y=(p=l.onRotateEnd)==null?void 0:p.call(l,a,c);y&&i.push(y)}}),i.length>0&&n.updateShapes(i)}var Dl=(e=>(e.DeletingFromShape="deleting_from_shape",e.DeletingToShape="deleting_to_shape",e.DeletingBinding="deleting_binding",e))(Dl||{});class Eh{constructor(n){this.editor=n}}g(Eh,"props"),g(Eh,"migrations"),g(Eh,"type");const _z=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:c,toId:l}=a,u=i.get(c);u?u.push(a):i.set(c,[a]);const d=i.get(l);d?d.push(a):i.set(l,[a])}return i}return G("arrowBindingsIndex",(s,i)=>{if(Pi(s))return o();const a=s,c=t.getDiffSince(i);if(c===Qn)return o();let l;function u(p){l??(l=new Map(a));const y=a.get(p.fromId),m=y==null?void 0:y.filter(v=>v.id!==p.id);m!=null&&m.length?l.set(p.fromId,m):l.delete(p.fromId);const w=a.get(p.toId),S=w==null?void 0:w.filter(v=>v.id!==p.id);S!=null&&S.length?l.set(p.toId,S):l.delete(p.toId)}function d(p){l??(l=new Map(a));let y=l.get(p);return y?y===a.get(p)&&(y=y.slice(0),l.set(p,y)):(y=[],l.set(p,y)),y}function f(p){d(p.fromId).push(p),d(p.toId).push(p)}for(const p of c){for(const y of yt(p.added))f(y);for(const[y,m]of yt(p.updated))u(y),f(m);for(const y of yt(p.removed))u(y)}return l??a})};function kz(e,n,t){const r=e.getShapeMaskedPageBounds(n);return r===void 0?!0:!t.includes(r)}const Tz=e=>{function n(t){const r=t.getCurrentPageShapeIds(),o=t.getViewportPageBounds(),s=new Set;return r.forEach(i=>{kz(t,i,o)&&s.add(i)}),s}return G("getCulledShapes",t=>{if(Pi(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})},$z=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(nn),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return G("parentsToChildrenWithIndexes",(o,s)=>{if(Pi(o))return r();const i=t.getDiffSince(s);if(i===Qn)return r();if(i.length===0)return o;let a=null;const c=d=>{a||(a={...o}),a[d]?a[d]===o[d]&&(a[d]=[...a[d]]):a[d]=[]},l=new Set;let u;for(let d=0,f=i.length;d<f;d++){u=i[d];for(const p of Object.values(u.added))wa(p)&&(c(p.parentId),a[p.parentId].push(p.id),l.add(a[p.parentId]));for(const[p,y]of Object.values(u.updated))if(wa(y)&&wa(p)){if(p.parentId!==y.parentId)c(p.parentId),c(y.parentId),a[p.parentId].splice(a[p.parentId].indexOf(y.id),1),a[y.parentId].push(y.id),l.add(a[y.parentId]);else if(p.index!==y.index){c(y.parentId);const m=a[y.parentId].indexOf(y.id);a[y.parentId][m]=y.id,l.add(a[y.parentId])}}for(const p of Object.values(u.removed))wa(p)&&(c(p.parentId),a[p.parentId].splice(a[p.parentId].indexOf(p.id),1))}for(const d of l){const f=ye(d.map(p=>e.get(p)));f.sort(nn),d.splice(0,d.length,...f.map(p=>p.id))}return a??o})},_m=(e,n,t)=>{for(;!Pn(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},Mz=(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=>_m(e,s,e.get(i))))}return G("_shapeIdsInCurrentPage",(s,i)=>{if(Pi(s))return o();const a=n();if(a!==r)return o();const c=e.history.getDiffSince(i);if(c===Qn)return o();const l=new lh(s);for(const d of c){for(const f of Object.values(d.added))wa(f)&&_m(e,a,f)&&l.add(f.id);for(const[f,p]of Object.values(d.updated))wa(p)&&(_m(e,a,p)?l.add(p.id):l.remove(p.id));for(const f of Object.keys(d.removed))mr(f)&&l.remove(f)}const u=l.get();return u?hl(u.value,u.diff):s})},l2=x.createContext(null);function Az({context:e,editor:n,children:t}){return h.jsx(kp.Provider,{value:n,children:h.jsx(l2.Provider,{value:e,children:t})})}function u2(){const e=x.useContext(l2);return e?{isDarkMode:e.isDarkMode}:null}async function jz(e,n,t={}){var C,I;const r=typeof n[0]=="string"?n:n.map(_=>_.id);if(r.length===0)return;if(!window.document)throw Error("No document");const{scale:o=1,background:s=!1,padding:i=fL,preserveAspectRatio:a=!1}=t,c=t.darkMode??e.user.getIsDarkMode(),l=ts({isDarkMode:c}),u=e.getShapeAndDescendantIds(r),d=e.getUnorderedRenderingShapes(!1).filter(({id:_})=>u.has(_));let f=null;if(t.bounds)f=t.bounds;else for(const{id:_}of d){const k=e.getShapeMaskedPageBounds(_);k&&(f?f.union(k):f=k.clone())}if(!f)return;const p=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;p||f.expandBy(i);const y=f.width*o,m=f.height*o;try{(I=(C=document.body).focus)==null||I.call(C)}catch{}const w=[],S=new Map,v={isDarkMode:c,addExportDef:_=>{if(S.has(_.key))return;const k=(async()=>{const $=await _.getElement();$&&w.push(h.jsx(x.Fragment,{children:$},w.length))})();S.set(_.key,k)}},P=(await Promise.all(d.map(async({id:_,opacity:k,index:$,backgroundIndex:T})=>{var H,U;if(_===p)return[];const O=e.getShape(_);if(e.isShapeOfType(O,"group"))return[];const N=e.getShapeUtil(O);let A=await((H=N.toSvg)==null?void 0:H.call(N,O,v)),j=await((U=N.toBackgroundSvg)==null?void 0:U.call(N,O,v));if(!A&&!j){const K=e.getShapePageBounds(O);A=h.jsx("rect",{width:K.w,height:K.h,fill:l.solid,stroke:l.grey.pattern,strokeWidth:1})}let L=e.getShapePageTransform(O).toCssString();"scale"in O.props&&O.props.scale!==1&&(L=`${L} scale(${O.props.scale}, ${O.props.scale})`),A&&(A=h.jsx("g",{transform:L,opacity:k,children:A},O.id)),j&&(j=h.jsx("g",{transform:L,opacity:k,children:j},`bg_${O.id}`));const X=e.getShapeMask(O.id);if(X){const K=`mask_${O.id.replace(":","_")}`;w.push(h.jsx("clipPath",{id:K,children:h.jsx("path",{d:`M${X.map(({x:Z,y:le})=>`${Z},${le}`).join("L")}Z`})},w.length)),A&&(A=h.jsx("g",{clipPath:`url(#${K})`,children:A},O.id)),j&&(j=h.jsx("g",{clipPath:`url(#${K})`,children:j},`bg_${O.id}`))}const V=[];return A&&V.push({zIndex:$,element:A}),j&&V.push({zIndex:T,element:j}),V}))).flat();return await Promise.all(S.values()),{jsx:h.jsx(Az,{editor:e,context:v,children:h.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:y,height:m,viewBox:`${f.minX} ${f.minY} ${f.width} ${f.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?p?l.solid:l.background:"transparent"},children:[h.jsx("defs",{children:w}),P.sort((_,k)=>_.zIndex-k.zIndex).map(({element:_})=>_)]})}),width:y,height:m}}const Oz=40;class Dz{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=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"?dL:hL)});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=b.From(n.point),this._previousScreenPoint&&b.Dist2(this._previousScreenPoint,this._clickScreenPoint)>Oz**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=b.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&&b.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?m_:$f)&&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 Rz{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 Lz{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())});const r=n.getInstanceState().isFocused;t!==r&&n.updateInstanceState({isFocused:!!t})}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var n;(n=this.disposeSideEffectListener)==null||n.call(this)}}function el(e){return Nz}class Fz{constructor(){g(this,"length",0);g(this,"head",null);g(this,"tail",this)}push(n){return new Px(n,this)}toArray(){return Bo}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const Nz=new Fz;class Px{constructor(n,t){g(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Px(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 zz{constructor(n){g(this,"store");g(this,"dispose");g(this,"state","recording");g(this,"pendingDiff",new Uz);g(this,"stacks",on("HistoryManager.stacks",{undos:el(),redos:el()},{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=Bz[t.history]);try{if(this._isInBatch)return n(),this;this._isInBatch=!0;try{Ts(()=>{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(),c=bE(a),l=Qy(a);n&&!c&&(i=i.push({type:"diff",diff:a}));let u=!1;if(c)for(;((o=s.head)==null?void 0:o.type)==="stop";){const d=s.head;if(s=s.tail,n&&(i=i.push(d)),d.id===t){u=!0;break}}if(!u)e:for(;s.head;){const d=s.head;switch(s=s.tail,n&&(i=i.push(d)),d.type){case"diff":gf(l,[Qy(d.diff)]);break;case"stop":if(!t||d.id===t)break e;break;default:sn(d)}}this.store.applyDiff(l,{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;for(;((t=o.head)==null?void 0:t.type)==="stop";)r=r.push(o.head),o=o.tail;const s=Zy();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")gf(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,"mark",(n=ot())=>(Ts(()=>{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??cR,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:el()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:sn(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:el(),redos:el()}),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 Bz={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class Uz{constructor(){g(this,"diff",Zy());g(this,"isEmptyAtom",on("PendingDiff.isEmpty",!0))}clear(){const n=this.diff;return this.diff=Zy(),this.isEmptyAtom.set(!0),n}isEmpty(){return this.isEmptyAtom.get()}apply(n){gf(this.diff,[n]),this.isEmptyAtom.set(bE(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class Hz{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||b.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:c,prev:l}=t;c&&c!==l&&(t.prev=c,t.scribble.points.push(c)),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 Kz=Object.defineProperty,Wz=Object.getOwnPropertyDescriptor,Gp=(e,n,t,r)=>{for(var o=Wz(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&Kz(n,t,o),o};const de=e=>Math.round(e*10**8)/10**8;function jo(e,n,t,r,o){const s=e.filter(a=>(r==="forward"?a.startNode.id===n:a.endNode.id===n)&&de(a.length)===de(t)&&jr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const c=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(c)){i.add(c);const l=jo(e,c,t,r,jr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...l)}}),s}function Gz(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=>de(s.startEdge[0].x)===de(i.startEdge[0].x)&&de(s.startEdge[0].y)===de(i.startEdge[0].y)&&de(s.startEdge[1].x)===de(i.startEdge[1].x)&&de(s.startEdge[1].y)===de(i.startEdge[1].y))&&o.gaps.some(i=>de(s.endEdge[0].x)===de(i.endEdge[0].x)&&de(s.endEdge[0].y)===de(i.endEdge[0].y)&&de(s.endEdge[1].x)===de(i.endEdge[1].x)&&de(s.endEdge[1].y)===de(i.endEdge[1].y)))){e.splice(n,1);break}}}}class Fu{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:c,y:l}=oe.applyToPoint(r,i);return{x:c,y:l,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:Vn(this.editor.getShapePageBounds(n))}))}getVisibleGaps(){const n=[],t=[];let r,o;const s=this.getSnappableGapNodes().sort((a,c)=>a.pageBounds.minX-c.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let c=a+1;c<s.length;c++)o=s[c],r.pageBounds.maxX<o.pageBounds.minX&&Wc(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&n.push({startNode:r,endNode:o,startEdge:[new b(r.pageBounds.maxX,r.pageBounds.minY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(o.pageBounds.minX,o.pageBounds.minY),new b(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:jr(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,c)=>a.pageBounds.minY-c.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let c=a+1;c<i.length;c++)o=i[c],r.pageBounds.maxY<o.pageBounds.minY&&Wc(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&t.push({startNode:r,endNode:o,startEdge:[new b(r.pageBounds.minX,r.pageBounds.maxY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(o.pageBounds.minX,o.pageBounds.minY),new b(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:jr(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 w,S;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(o),c=r.map(({x:v,y:P},E)=>({id:"selection:"+E,x:v+o.x,y:P+o.y})),l=i,u=[],d=[],f=new b(s,s);this.collectPointSnaps({minOffset:f,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:l,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:f});const p=new b(n==="x"?0:((w=u[0])==null?void 0:w.nudge)??0,n==="y"?0:((S=d[0])==null?void 0:S.nudge)??0);f.x=0,f.y=0,u.length=0,d.length=0,c.forEach(v=>{v.x+=p.x,v.y+=p.y}),a.translate(p),this.collectPointSnaps({minOffset:f,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:l,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:f});const y=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:d}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d});return this.manager.setIndicators([...m,...y]),{nudge:p}}snapResizeShapes({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var _,k;const i=this.manager.getSnapThreshold(),{box:a,scaleX:c,scaleY:l}=J.Resize(n,r,s?t.x*2:t.x,s?t.y*2:t.y,o);let u=r;c<0&&(u=o5(u)),l<0&&(u=r5(u)),s&&(a.center=n.center);const d=u==="top"||u==="bottom",f=u==="left"||u==="right",p=gP(u,a),y=this.getSnappablePoints(),m=[],w=[],S=new b(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:w,otherNodeSnapPoints:y,selectionSnapPoints:p});const v=new b(d?0:((_=m[0])==null?void 0:_.nudge)??0,f?0:((k=w[0])==null?void 0:k.nudge)??0);if(o&&s5(u)&&v.len()!==0){const $=m.length&&w.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":m.length?"x":"y",T=n.aspectRatio;$==="x"?(w.length=0,v.y=v.x/T,(u==="bottom_left"||u==="top_right")&&(v.y=-v.y)):(m.length=0,v.x=v.y*T,(u==="bottom_left"||u==="top_right")&&(v.x=-v.x))}const P=b.Add(t,v),{box:E}=J.Resize(n,r,s?P.x*2:P.x,s?P.y*2:P.y,o);s&&(E.center=n.center);const C=gP("any",E);m.length=0,w.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:w,otherNodeSnapPoints:y,selectionSnapPoints:C});const I=this.getPointSnapLines({nearestSnapsX:m,nearestSnapsY:w});return this.manager.setIndicators([...I]),{nudge:v}}collectPointSnaps({selectionSnapPoints:n,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of n)for(const a of t){const c=b.Sub(i,a),l=Math.abs(c.x),u=Math.abs(c.y);de(l)<=de(r.x)&&(de(l)<de(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=l),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!Wc(a.breadthIntersection[0],a.breadthIntersection[1],n.minY,n.maxY))continue;const l=a.startEdge[0].x+a.length/2-n.center.x;if(a.length>n.width&&de(Math.abs(l))<=de(t.x)){de(Math.abs(l))<de(t.x)&&(r.length=0),t.x=Math.abs(l);const S={type:"gap_center",gap:a,nudge:l},v=r.find(({type:E})=>E==="gap_center"),P=v&&jr(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&P?r[r.indexOf(v)]=S:(!v||!P)&&r.push(S)}const d=a.startNode.pageBounds.minX-a.length,f=n.maxX,p=d-f;de(Math.abs(p))<=de(t.x)&&(de(Math.abs(p))<de(t.x)&&(r.length=0),t.x=Math.abs(p),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:p}));const y=a.endNode.pageBounds.maxX+a.length,m=n.minX,w=y-m;de(Math.abs(w))<=de(t.x)&&(de(Math.abs(w))<de(t.x)&&(r.length=0),t.x=Math.abs(w),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:w}))}for(const a of i){if(!Wc(a.breadthIntersection[0],a.breadthIntersection[1],n.minX,n.maxX))continue;const l=a.startEdge[0].y+a.length/2-n.center.y;if(a.length>n.height&&de(Math.abs(l))<=de(t.y)){de(Math.abs(l))<de(t.y)&&(o.length=0),t.y=Math.abs(l);const S={type:"gap_center",gap:a,nudge:l},v=o.find(({type:E})=>E==="gap_center"),P=v&&Wc(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&P?o[o.indexOf(v)]=S:(!v||!P)&&o.push(S);continue}const d=a.startNode.pageBounds.minY-a.length,f=n.maxY,p=d-f;de(Math.abs(p))<=de(t.y)&&(de(Math.abs(p))<de(t.y)&&(o.length=0),t.y=Math.abs(p),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:p}));const y=a.endNode.pageBounds.maxY+a.length,m=n.minY,w=y-m;de(Math.abs(w))<=de(t.y)&&(de(Math.abs(w))<de(t.y)&&(o.length=0),t.y=Math.abs(w),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:w}))}}getPointSnapLines({nearestSnapsX:n,nearestSnapsY:t}){const r={},o={};if(n.length>0){for(const s of n)if(s.type==="points"){const i=de(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=de(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:ot(),type:"points",points:r0(s.map(i=>b.From(i.otherPoint)).concat(s.map(i=>b.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 c of t){if(c.type==="points")continue;const{gap:{breadthIntersection:l,startEdge:u,startNode:d,endNode:f,length:p,endEdge:y}}=c;switch(c.type){case"gap_center":{const m=(p-n.width)/2,w=jr(l[0],l[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:[...jo(s,d.id,m,"backward",w),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:y},...jo(s,f.id,m,"forward",w)]});break}case"gap_duplicate":{const m=jr(l[0],l[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:c.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(w=>w.clone().addXY(-d.pageBounds.width,0))},{startEdge:u,endEdge:y},...jo(s,f.id,p,"forward",m)]:[...jo(s,d.id,p,"backward",m),{startEdge:u,endEdge:y},{startEdge:y.map(w=>w.clone().addXY(c.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const c of r){if(c.type==="points")continue;const{gap:{breadthIntersection:l,startEdge:u,startNode:d,endNode:f,length:p,endEdge:y}}=c;switch(c.type){case"gap_center":{const m=(p-n.height)/2,w=jr(l[0],l[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:[...jo(o,d.id,m,"backward",w),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:y},...jo(o,c.gap.endNode.id,m,"forward",w)]});break}case"gap_duplicate":{const m=jr(l[0],l[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:c.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(w=>w.clone().addXY(0,-d.pageBounds.height))},{startEdge:u,endEdge:y},...jo(o,f.id,p,"forward",m)]:[...jo(o,d.id,p,"backward",m),{startEdge:u,endEdge:y},{startEdge:y.map(w=>w.clone().addXY(0,f.pageBounds.height)),endEdge:i.top}]})}break}}return Gz(a),a}}Gp([G],Fu.prototype,"getSnapPointsCache");Gp([G],Fu.prototype,"getSnappablePoints");Gp([G],Fu.prototype,"getSnappableGapNodes");Gp([G],Fu.prototype,"getVisibleGaps");function gP(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 Vz=Object.defineProperty,Yz=Object.getOwnPropertyDescriptor,Xz=(e,n,t,r)=>{for(var o=Yz(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&Vz(n,t,o),o};const qz=()=>null,Zz=()=>[];class d2{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??qz,getSelfSnapPoints:r.getSelfSnapPoints??Zz}})}*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=Vn(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 c=Vn(this.editor.getShapePageTransform(i));for(const l of a)yield c.applyToPoint(l)}}*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 l of this.iterateSnapPointsInPageSpace(n,t))b.DistMin(r,l,s)&&(s=b.Dist(r,l),i=l);if(i)return i;let a=o,c=null;for(const{shapeId:l,outline:u}of this.iterateSnapOutlines(n,t)){const d=Vn(this.editor.getShapePageTransform(l)),f=this.editor.getPointInShapeSpace(l,r),p=u.nearestPoint(f),y=d.applyToPoint(p);b.DistMin(r,y,a)&&(a=b.Dist(r,y),c=y)}return c||null}snapHandle({currentShapeId:n,handle:t}){const o=Vn(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:b.Sub(s,o)}):null}}Xz([G],d2.prototype,"getSnapGeometryCache");var Qz=Object.defineProperty,Jz=Object.getOwnPropertyDescriptor,Cx=(e,n,t,r)=>{for(var o=Jz(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&Qz(n,t,o),o};class Vp{constructor(n){g(this,"shapeBounds");g(this,"handles");g(this,"_snapIndicators",on("snapLines",void 0));this.editor=n,this.shapeBounds=new Fu(this),this.handles=new d2(this)}getIndicators(){return this._snapIndicators.get()??Bo}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(mr(i)){const c=n.getShape(i);c&&n.isShapeOfType(c,"frame")&&o.add(i)}const a=n.getSortedChildIdsForParent(i);for(const c of a){if(r.includes(c))continue;const l=n.getShape(c);if(!l||!n.getShapeUtil(l).canSnap(l))continue;const d=n.getShapePageBounds(c);if(d&&t.includes(d)){if(n.isShapeOfType(l,"group")){s(c);continue}o.add(c)}}};return s(this.getCurrentCommonAncestor()??n.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Cx([G],Vp.prototype,"getSnapThreshold");Cx([G],Vp.prototype,"getSnappableShapes");Cx([G],Vp.prototype,"getCurrentCommonAncestor");const e8=/\r?\n|\r/g;function mP(e){return e.replace(e8,`
93
- `).split(`
94
- `).map(n=>n||" ").join(`
95
- `)}const t8={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},n8=/\s/;class r8{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=mP(n);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}});var o;this.editor=n;const t=this.editor.getContainer();(o=t.querySelector("#tldraw_text_measure"))==null||o.remove();const r=document.createElement("div");r.id="tldraw_text_measure",r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,t.appendChild(r),this.baseElm=r}measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:t=!1}={}){const r=[],o=n.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,c=n.childNodes[0];let l=0,u=null,d=null,f=0,p=0,y=!1;for(const m of n.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const w of m.textContent??""){a.setStart(c,l),a.setEnd(c,l+w.length);const S=a.getClientRects(),v=S[S.length-1],P=v.top+i,E=v.left+s,C=v.right+s,I=E<p,_=n8.test(w);if(_!==d||P!==f||!u){if(u){if(t&&P!==f){y=!0;break}r.push(u)}u={box:{x:E,y:P,w:v.width,h:v.height},text:w},p=E}else I&&(u.box.x=E),u.box.w=I?u.box.w+v.width:C-u.box.x,u.text+=w;w===`
96
- `&&(p=0),d=_,f=P,l+=w.length}return u&&r.push(u),{spans:r,didTruncate:y}}measureTextSpans(n,t){var l;if(n==="")return[];const r=(l=this.baseElm)==null?void 0:l.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",t8[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=mP(n);r.textContent=i;const{spans:a,didTruncate:c}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(t.overflow==="truncate-ellipsis"&&c){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const d=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,f=d[d.length-1];return d.push({text:"…",box:{x:Math.min(f.box.x+f.box.w,t.width-t.padding-u),y:f.box.y,w:u,h:f.box.h}}),d}return r.remove(),a}}const yP=(typeof process<"u",xE);class o8{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=yP(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=yP(this.tick)});g(this,"dispose",()=>{var n;this.isPaused=!0,(n=this.cancelRaf)==null||n.call(this)});g(this,"prevPoint",new b);g(this,"updatePointerVelocity",n=>{const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(n===0)return;const s=b.Sub(r,t);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new b(0,0),c=o.clone().lrp(a.mul(i/n),.5);Math.abs(c.x)<.01&&(c.x=0),Math.abs(c.y)<.01&&(c.y=0),o.equals(c)||(this.editor.inputs.pointerVelocity=c)});this.editor=n,this.editor.disposables.add(this.dispose),this.start()}}var s8=Object.defineProperty,i8=Object.getOwnPropertyDescriptor,Po=(e,n,t,r)=>{for(var o=i8(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&s8(n,t,o),o};class Vr{constructor(n,t){g(this,"updateUserPreferences",n=>{this.user.setUserPreferences({...this.user.userPreferences.get(),...n})});this.user=n,this.inferDarkMode=t}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode()}}getIsDarkMode(){return this.user.userPreferences.get().isDarkMode??(this.inferDarkMode?eN():!1)}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??fi.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??fi.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??fi.name}getLocale(){return this.user.userPreferences.get().locale??fi.locale}getColor(){return this.user.userPreferences.get().color??fi.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??fi.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??fi.isWrapMode}}Po([G],Vr.prototype,"getUserPreferences");Po([G],Vr.prototype,"getIsDarkMode");Po([G],Vr.prototype,"getEdgeScrollSpeed");Po([G],Vr.prototype,"getAnimationSpeed");Po([G],Vr.prototype,"getId");Po([G],Vr.prototype,"getName");Po([G],Vr.prototype,"getLocale");Po([G],Vr.prototype,"getColor");Po([G],Vr.prototype,"getIsSnapMode");Po([G],Vr.prototype,"getIsWrapMode");const a8={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"},c8=["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],c=o.getCurrent(),l=(s=o.children)==null?void 0:s[a];if(!l)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((c==null?void 0:c.id)!==l.id&&(c==null||c.exit(t,a),o._current.set(l),l.enter(t,(c==null?void 0:c.id)||"initial"),!l.getIsActive()))break;o=l}return this});g(this,"handleEvent",n=>{var o;const t=a8[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(Pt.measurePerformance.get()&&c8.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;Pt.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",on("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=on("toolIsActive"+this.id,!1),this._current=on("toolState"+this.id,void 0),this._path=G("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 iE}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 _h 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(_h,"id","root"),g(_h,"initial",""),g(_h,"children",()=>[]);var l8=Object.defineProperty,u8=Object.getOwnPropertyDescriptor,re=(e,n,t,r)=>{for(var o=u8(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&l8(n,t,o),o};class ee extends cN{constructor({store:t,user:r,shapeUtils:o,bindingUtils:s,tools:i,getContainer:a,cameraOptions:c,initialState:l,autoFocus:u,inferDarkMode:d}){super();g(this,"store");g(this,"root");g(this,"disposables",new Set);g(this,"_tickManager");g(this,"snaps");g(this,"user");g(this,"textMeasure");g(this,"environment");g(this,"scribbles");g(this,"sideEffects");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}))},r)});g(this,"_cameraOptions",on("camera options",Ab));g(this,"_viewportAnimation",null);g(this,"_willSetInitialBounds",!0);g(this,"_isLockedOnFollowingUser",on("isLockedOnFollowingUser",!1));g(this,"_cameraState",on("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=mL,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});g(this,"_currentPageShapeIds");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 c=0,l=t.length;c<l;c++){const u=t[c];u&&(o=this.getShape(u.id),o&&(s=Ao(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 b,originScreenPoint:new b,previousPagePoint:new b,previousScreenPoint:new b,currentPagePoint:new b,currentScreenPoint:new b,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 b});g(this,"_clickManager",new Dz(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?(clearInterval(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!t.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=setTimeout(this._setShiftKeyTimeout,150)),t.altKey?(clearInterval(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!t.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=setTimeout(this._setAltKeyTimeout,150)),t.ctrlKey?(clearInterval(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!t.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,currentPagePoint:i}=r;r.isPointing||(r.isDragging=!1);const a=this.store.unsafeGetWithoutCapture(en),c=this.store.get(this._getCurrentPageStateId()),l=this._cameraOptions.__unsafe__getWithoutCapture();switch(o){case"pinch":{if(l.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=[...c.selectedShapeIds]),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:u=1},delta:{x:d,y:f}}=t,{x:p,y}=b.SubXY(t.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:m,y:w,z:S}=Lg(()=>this.getCamera()),{panSpeed:v,zoomSpeed:P}=l;this._setCamera(new b(m+d*v/S-p/S+p/(u*P),w+f*v/S-y/S+y/(u*P),u*P),{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(l.isLocked)return;if(this._updateInputsFromEvent(t),!this.getIsMenuOpen()){const{panSpeed:u,zoomSpeed:d,wheelBehavior:f}=l;if(f!=="none"){this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:p,y,z:m}=Lg(()=>this.getCamera()),{x:w,y:S,z:v=0}=t.delta;let P=f;switch(r.ctrlKey&&(P=f==="pan"?"zoom":"pan"),P){case"zoom":{const{x:E,y:C}=this.inputs.currentScreenPoint;let I=v;f==="zoom"&&(Math.abs(S)>10?I=10*Math.sign(S)/100:I=S/100);const _=m+(I??0)*d*m;this._setCamera(new b(p+(E/_-E)-(E/m-E),y+(C/_-C)-(C/m-C),_),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new b(p+w*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:d}=a;switch(t.name){case"pointer_down":{if(d&&!u)return;if(this.clearOpenMenus(),this.inputs.isPanning||(this._longPressTimeout=setTimeout(()=>{this.dispatch({...t,point:this.inputs.currentScreenPoint,name:"long_press"})},wL)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),t.button===Lb&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,!d&&u&&this.updateInstanceState({isPenMode:!0}),t.button===Fb?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===hd&&(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&&d)return;const{x:f,y:p,z:y}=Lg(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:m,previousScreenPoint:w}=this.inputs,{panSpeed:S}=l,v=b.Sub(m,w);this.setCamera(new b(f+v.x*S/y,p+v.y*S/y,y),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&b.Dist2(s,i)>(a.isCoarsePointer?m_:$f)/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 f=this.inputs.pointerVelocity,p=Math.min(2,f.len());switch(t.button){case Lb:{this.setCursor({type:"grab",rotation:0});break}case hd:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}p>0&&this.slideCamera({speed:p,direction:f,friction:y_})}else t.button===Fb&&(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(hd)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(t.type==="pointer"){t.button===hd?t.name="middle_click":t.button===x0&&(t.name="right_click");const{isPenMode:u}=this.store.unsafeGetWithoutCapture(en);if(t.isPen===u){const d=this._clickManager.handlePointerEvent(t);if(t.name!==d.name){this.root.handleEvent(t),this.emit("event",t),this.root.handleEvent(d),this.emit("event",d);return}}}return this.root.handleEvent(t),this.emit("event",t),this});this.store=t,this.history=new zz({store:t,annotateError:k=>{this.annotateError(k,{origin:"history.batch",willCrashApp:!0}),this.crash(k)}}),this.snaps=new Vp(this),this._cameraOptions.set({...Ab,...c}),this.user=new Vr(r??ek(),d??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new r8(this),this._tickManager=new o8(this);class f extends _h{}g(f,"initial",l??""),this.root=new f(this),this.root.children={};const p=a2(o),y={},m={},w=new Map;for(const k of p){const $=new k(this);y[k.type]=$;const T=kE(k.props??{});m[k.type]=T;for(const O of T.keys())if(!w.has(O.id))w.set(O.id,O);else if(w.get(O.id)!==O)throw Error(`Multiple style props with id "${O.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=y,this.styleProps=m;const S=o2(s),v={};for(const k of S){const $=new k(this);v[k.type]=$}this.bindingUtils=v;for(const k of[...i]){if(ao(this.root.children,k.id))throw Error(`Can't override tool with id "${k.id}"`);this.root.children[k.id]=new k(this,this.root)}this.environment=new Rz(this),this.scribbles=new Hz(this);const P=(k,$)=>{let T=null;const O=k.selectedShapeIds.filter(j=>!$.has(j));O.length!==k.selectedShapeIds.length&&(T||(T={...k}),T.selectedShapeIds=O);const N=k.erasingShapeIds.filter(j=>!$.has(j));N.length!==k.erasingShapeIds.length&&(T||(T={...k}),T.erasingShapeIds=N),k.hoveredShapeId&&$.has(k.hoveredShapeId)&&(T||(T={...k}),T.hoveredShapeId=null),k.editingShapeId&&$.has(k.editingShapeId)&&(T||(T={...k}),T.editingShapeId=null);const A=k.hintingShapeIds.filter(j=>!$.has(j));return A.length!==k.hintingShapeIds.length&&(T||(T={...k}),T.hintingShapeIds=A),k.focusedGroupId&&$.has(k.focusedGroupId)&&(T||(T={...k}),T.focusedGroupId=null),T};this.sideEffects=this.store.sideEffects;let E=new Map;const C=new Set,I=new Set;let _=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var k,$,T,O;C.clear();for(const N of I){I.delete(N);const A=this.getShape(N);if(!A)continue;const j=this.getShapeUtil(A),L=(k=j.onChildrenChange)==null?void 0:k.call(j,A);L!=null&&L.length&&this.updateShapes(L)}if(_.size){const N=_;_=new Set;for(const A of N){const j=this.getBindingUtil(A);($=j.onOperationComplete)==null||$.call(j)}}if(E.size){const N=E;E=new Map;for(const A of N.values())(O=(T=this.getBindingUtil(A.binding)).onAfterUnbind)==null||O.call(T,A)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(k,$)=>{var T,O,N,A;for(const j of this.getBindingsInvolvingShape($))_.add(j.type),j.fromId===$.id&&((O=(T=this.getBindingUtil(j)).onAfterChangeFromShape)==null||O.call(T,{binding:j,shapeBefore:k,shapeAfter:$})),j.toId===$.id&&((A=(N=this.getBindingUtil(j)).onAfterChangeToShape)==null||A.call(N,{binding:j,shapeBefore:k,shapeAfter:$}));if(k.parentId!==$.parentId){const j=L=>{var V,H,U,K;const X=this.getShape(L);if(X)for(const Z of this.getBindingsInvolvingShape(X))_.add(Z.type),Z.fromId===X.id&&((H=(V=this.getBindingUtil(Z)).onAfterChangeFromShape)==null||H.call(V,{binding:Z,shapeBefore:X,shapeAfter:X})),Z.toId===X.id&&((K=(U=this.getBindingUtil(Z)).onAfterChangeToShape)==null||K.call(U,{binding:Z,shapeBefore:X,shapeAfter:X}))};j($.id),this.visitDescendants($.id,j)}if(k.parentId!==$.parentId&&Pn($.parentId)){const j=new Set([k.id]);this.visitDescendants(k.id,L=>{j.add(L)});for(const L of this.getPageStates()){if(L.pageId===$.parentId)continue;const X=P(L,j);X&&this.store.put([X])}}k.parentId&&mr(k.parentId)&&I.add(k.parentId),$.parentId!==k.parentId&&mr($.parentId)&&I.add($.parentId)},beforeDelete:k=>{k.parentId&&mr(k.parentId)&&I.add(k.parentId),C.add(k.id);const $=[];for(const N of this.getBindingsInvolvingShape(k))_.add(N.type),$.push(N.id);this.deleteBindings($);const T=new Set([k.id]),O=ye(this.getPageStates().map(N=>P(N,T)));O.length&&this.store.put(O)}},binding:{beforeCreate:k=>{var T,O;const $=(O=(T=this.getBindingUtil(k)).onBeforeCreate)==null?void 0:O.call(T,{binding:k});return $||k},afterCreate:k=>{var $,T;_.add(k.type),(T=($=this.getBindingUtil(k)).onAfterCreate)==null||T.call($,{binding:k})},beforeChange:(k,$)=>{var O,N;const T=(N=(O=this.getBindingUtil($)).onBeforeChange)==null?void 0:N.call(O,{bindingBefore:k,bindingAfter:$});return T||$},afterChange:(k,$)=>{var T,O;_.add($.type),(O=(T=this.getBindingUtil($)).onAfterChange)==null||O.call(T,{bindingBefore:k,bindingAfter:$})},beforeDelete:k=>{var O,N;const $=this.getBindingUtil(k);if(!$.onBeforeUnbind&&!$.onAfterUnbind||E.has(k.id))return;const T={binding:k,reason:C.has(k.fromId)?Dl.DeletingFromShape:C.has(k.toId)?Dl.DeletingToShape:Dl.DeletingBinding};E.set(k.id,T),(N=(O=this.getBindingUtil(k)).onBeforeUnbind)==null||N.call(O,T)},afterDelete:k=>{_.add(k.type)}},page:{afterCreate:k=>{const $=Fr.createId(k.id),T=xr.createId(k.id);this.store.has($)||this.store.put([Fr.create({id:$})]),this.store.has(T)||this.store.put([xr.create({id:T,pageId:k.id})])},afterDelete:(k,$)=>{var N,A;if(((N=this.getInstanceState())==null?void 0:N.currentPageId)===k.id){const j=(A=this.getPages().find(L=>L.id!==k.id))==null?void 0:A.id;j?this.store.put([{...this.getInstanceState(),currentPageId:j}]):$==="user"&&this.store.ensureStoreIsUsable()}const T=Fr.createId(k.id),O=xr.createId(k.id);this.store.remove([T,O])}},instance:{afterChange:(k,$,T)=>{var O;if(!this.store.has($.currentPageId)){const N=this.store.has(k.currentPageId)?k.currentPageId:(O=this.getPages()[0])==null?void 0:O.id;N?this.store.update($.id,A=>({...A,currentPageId:N})):T==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(k,$)=>{if((k==null?void 0:k.selectedShapeIds)!==($==null?void 0:$.selectedShapeIds)){const T=$.selectedShapeIds.filter(N=>{var j,L;let A=(j=this.getShape(N))==null?void 0:j.parentId;for(;mr(A);){if($.selectedShapeIds.includes(A))return!1;A=(L=this.getShape(A))==null?void 0:L.parentId}return!0});let O=null;if(T.length>0){const N=this.findCommonAncestor(ye(T.map(A=>this.getShape(A))),A=>this.isShapeOfType(A,"group"));N&&(O=N)}else $!=null&&$.focusedGroupId&&(O=$.focusedGroupId);(T.length!==$.selectedShapeIds.length||O!==$.focusedGroupId)&&this.store.put([{...$,selectedShapeIds:T,focusedGroupId:O??null}])}}}})),this._currentPageShapeIds=Mz(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=$z(this.store),this.disposables.add(this.store.listen(k=>{this.emit("change",k)})),this.disposables.add(this.history.dispose),this.history.ignore(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})}),l&&this.root.children[l]===void 0)throw Error(`No state found for initialState "${l}".`);this.root.enter(void 0,"initial"),this.focusManager=new Lz(this,u),this.disposables.add(this.focusManager.dispose.bind(this.focusManager)),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.on("tick",this._flushEventsForTick),requestAnimationFrame(()=>{this._tickManager.start()}),this.performanceTracker=new iE}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear()}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=kn(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=kn(this.bindingUtils,r);return st(o,`No binding util found for type "${r}"`),o}undo(){return this._flushEventsForTick(0),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(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 o0(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(tS)}updateDocumentSettings(t){return this.history.ignore(()=>{this.store.put([{...this.getDocumentSettings(),...t}])}),this}getInstanceState(){return this.store.get(en)}updateInstanceState(t,r){return this._updateInstanceState(t,{history:"ignore",...r}),t.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),t.isChangingStyle===!0&&(this._isChangingStyleTimeout=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 xr.createId(this.getCurrentPageId())}updateCurrentPageState(t,r){return this._updateCurrentPageState(t,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:t}=this.getCurrentPageState();return ye(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:J.Common(ye(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=J.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 J(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}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const t=this.getHintingShapeIds();return ye(t.map(r=>this.getShape(r)))}setHintingShapes(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:r0(r)},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const t=this.getErasingShapeIds();return ye(t.map(r=>this.getShape(r)))}setErasingShapes(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id);r.sort();const o=this.getErasingShapeIds();return this.history.ignore(()=>{if(r.length===o.length){for(let s=0;s<r.length;s++)if(r[s]!==o[s]){this._updateCurrentPageState({erasingShapeIds:r});break}}else this._updateCurrentPageState({erasingShapeIds:r})}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==this.getCroppingShapeId())if(!r)this.updateCurrentPageState({croppingShapeId:null});else{const o=this.getShape(r),s=this.getShapeUtil(o);o&&s.canCrop(o)&&this.updateCurrentPageState({croppingShapeId:r})}return this}getCameraId(){return Fr.createId(this.getCurrentPageId())}getCamera(){const t=this.store.get(this.getCameraId());if(this._isLockedOnFollowingUser.get()){const r=this.getCameraForFollowing();if(r)return{...t,...r}}return t}getViewportPageBoundsForFollowing(){const t=this.getInstanceState().followingUserId;if(!t)return null;const r=this.getCollaborators().find(f=>f.userId===t);if(!r)return null;const{w:o,h:s}=r.screenBounds,{x:i,y:a,z:c}=r.camera,l=new J(-i,-a,o/c,s/c),u=this.getViewportScreenBounds().clone(),d=u.width/u.height;return u.width=l.width,u.height=u.width/d,u.height<l.height&&(u.height=l.height,u.width=u.height*d),u.center=l.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}=vP(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 sn(t.constraints.initialZoom)}}getBaseZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.baseZoom==="default")return 1;const{zx:r,zy:o}=vP(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 sn(t.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(t){var o;const r=xt({...this._cameraOptions.__unsafe__getWithoutCapture(),...t});return((o=r.zoomSteps)==null?void 0:o.length)<1&&(r.zoomSteps=[1]),this._cameraOptions.set(r),this}_setCamera(t,r){const o=this.getCamera();let{x:s,y:i,z:a=o.z}=t;if(!(r!=null&&r.force)){const c=this.getCameraOptions(),l=c.zoomSteps[0],u=Nt(c.zoomSteps),d=this.getViewportScreenBounds();if(c.constraints){const{constraints:f}=c,p=Math.min(f.padding.y,d.w/2),y=Math.min(f.padding.x,d.h/2),m=J.From(c.constraints.bounds),w=(d.w-y*2)/m.w,S=(d.h-p*2)/m.h,v=this.getBaseZoom(),P=u*v,E=l*v;if(r!=null&&r.reset&&(a=this.getInitialZoom()),a<E||a>P){const{x:A,y:j,z:L}=o,X=-A+d.w/L/2,V=-j+d.h/L/2;a=$t(a,E,P);const H=-A+d.w/a/2,U=-j+d.h/a/2;s=A+H-X,i=j+U-V}const C=y/a-m.x,I=p/a-m.y,_=(d.w-y*2)/a-m.w,k=(d.h-p*2)/a-m.h,$=C+_*f.origin.x,T=I+k*f.origin.y,O=typeof f.behavior=="string"?f.behavior:f.behavior.x,N=typeof f.behavior=="string"?f.behavior:f.behavior.y;if(r!=null&&r.reset)s=$,i=T;else{switch(O){case"fixed":{s=$;break}case"contain":{a<w?s=$:s=$t(s,C+_,C);break}case"inside":{a<w?s=$t(s,C,(d.w-y)/a-m.w):s=$t(s,C+_,C);break}case"outside":{s=$t(s,y/a-m.w,(d.w-y)/a);break}case"free":break;default:throw sn(O)}switch(N){case"fixed":{i=T;break}case"contain":{a<S?i=T:i=$t(i,I+k,I);break}case"inside":{a<S?i=$t(i,I,(d.h-p)/a-m.h):i=$t(i,I+k,I);break}case"outside":{i=$t(i,p/a-m.h,(d.h-p)/a);break}case"free":break;default:throw sn(N)}}}else if(a>u||a<l){const{x:f,y:p,z:y}=o;a=$t(a,l,u),s=f+(-f+d.w/a/2)-(-f+d.w/y/2),i=p+(-p+d.h/a/2)-(-p+d.h/y/2)}}return o.x===s&&o.y===i&&o.z===a?this:(this.batch(()=>{const c={...o,x:s,y:i,z:a};this.history.ignore(()=>{this.store.put([c])});const{currentScreenPoint:l,currentPagePoint:u}=this.inputs,{screenBounds:d}=this.store.unsafeGetWithoutCapture(en);if(l.x/a-s!==u.x||l.y/a-i!==u.y){const f={type:"pointer",target:"canvas",name:"pointer_move",point:b.AddXY(l,d.x,d.y),pointerId:Db.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(f):this.dispatch(f)}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=b.Cast(t);if(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()),r!=null&&r.animation){const{width:i,height:a}=this.getViewportScreenBounds();this._animateToViewport(new J(-t.x,-t.y,i/s.z,a/s.z),r)}else this._setCamera(s,r);return this}centerOnPoint(t,r){if(this.getCameraOptions().isLocked)return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera(new b(-(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=J.Common(ye(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:c,z:l}=i,{x:u,y:d}=t;let f=1;if(s){const p=this.getInitialZoom();l!==p&&(f=p)}return this.setCamera(new b(a+(u/f-u)-(u/l-u),c+(d/f-d)-(d/l-d),f),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 c=this.getBaseZoom();let l=Nt(a)*c;for(let u=1;u<a.length;u++){const d=a[u-1]*c,f=a[u]*c;if(!(f-i<=(f-d)/2)){l=f;break}}this.setCamera(new b(o+(t.x/l-t.x)-(t.x/i-t.x),s+(t.y/l-t.y)-(t.y/i-t.y),l),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:c}=this.getCamera();let l=o[0]*s;for(let u=o.length-1;u>0;u--){const d=o[u-1]*s,f=o[u]*s;if(!(f-c>=(f-d)/2)){l=d;break}}this.setCamera(new b(i+(t.x/l-t.x)-(t.x/c-t.x),a+(t.y/l-t.y)-(t.y/c-t.y),l),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(bL,s.width*.28),a=this.getBaseZoom(),c=o.zoomSteps[0],l=Nt(o.zoomSteps);let u=$t(Math.min((s.width-i)/t.w,(s.height-i)/t.h),c*a,l*a);return(r==null?void 0:r.targetZoom)!==void 0&&(u=Math.min(r.targetZoom,u)),this.setCamera(new b(-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 b(-a.x,-a.y,this.getViewportScreenBounds().width/a.width));return}const c=s-r,l=o(1-c/s),u=i.minX+(a.minX-i.minX)*l,d=i.minY+(a.minY-i.minY)*l,f=i.maxX+(a.maxX-i.maxX)*l;this._setCamera(new b(-u,-d,this.getViewportScreenBounds().width/(f-u)),{force:!0})}_animateToViewport(t,r={animation:Gg}){const{animation:o,...s}=r;if(!o)return;const{duration:i=0,easing:a=an.easeInOutCubic}=o,c=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||c===0?this._setCamera(new b(-t.x,-t.y,this.getViewportScreenBounds().width/t.width),{...s}):(this._viewportAnimation={elapsed:0,duration:i/c,easing:a,start:l.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,direction:i,speedThreshold:a=.01}=t;let c=Math.min(o,1);const l=()=>{this.off("tick",u),this.off("stop-camera-animation",l)};this.once("stop-camera-animation",l);const u=d=>{const{x:f,y:p,z:y}=this.getCamera(),m=b.Mul(i,c*d/y);c*=1-s,c<a?l():this._setCamera(new b(f+m.x,p+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]}),setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],c=a.indexOf(t);c<0||(a.splice(c,1),this.updateInstanceState({highlightedUserIds:a}))},S_)}),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,document.body.scrollWidth!==t.maxX,document.body.scrollHeight!==t.maxY,t.minX!==0],s=t.equals(this.getViewportScreenBounds()),{_willSetInitialBounds:i}=this;if(s)this._willSetInitialBounds=!1;else if(i)this._willSetInitialBounds=!1,this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.setCamera(this.getCamera());else if(r&&!this.getInstanceState().followingUserId){const a=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.centerOnPoint(a)}else this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this._setCamera(b.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:t,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new J(t,r,o,s)}getViewportScreenCenter(){const t=this.getViewportScreenBounds();return new b(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 J(-o,-s,t/i,r/i)}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(en),{x:o,y:s,z:i=1}=this.getCamera();return new b((t.x-r.x)/i-o,(t.y-r.y)/i-s,t.z??.5)}pageToScreen(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(en),{x:o,y:s,z:i=1}=this.getCamera();return new b((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 b((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]):Bo}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=G("latestLeaderPresence",()=>this.getCollaborators().find(i=>i.userId===t));return Ts(()=>{this.updateInstanceState({followingUserId:t});const i=Wi("update current page",()=>{const l=s.get();if(!l){this.stopFollowingUser();return}l.currentPageId!==this.getCurrentPageId()&&this.getPage(l.currentPageId)&&this.history.ignore(()=>{this.store.put([{...this.getInstanceState(),currentPageId:l.currentPageId}]),this._isLockedOnFollowingUser.set(!0)})}),a=()=>{i(),this._isLockedOnFollowingUser.set(!1),this.off("frame",c),this.off("stop-following",a)},c=()=>{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 d=this.getViewportPageBoundsForFollowing();if(!d){this.stopFollowingUser();return}const f=this.getViewportPageBounds(),p=Math.abs(d.minX-f.minX)+Math.abs(d.maxX-f.maxX),y=Math.abs(d.minY-f.minY)+Math.abs(d.maxY-f.maxY);if(p<jb&&y<jb){this._isLockedOnFollowingUser.set(!0);return}const m=$t(u*.5,.1,.8),w=new J(sd(f.minX,d.minX,m),sd(f.minY,d.minY,m),sd(f.width,d.width,m),sd(f.height,d.height,m)),S=new b(-w.x,-w.y,this.getViewportScreenBounds().width/w.width);this.stopCameraAnimation(),this._setCamera(S)};this.once("stop-following",a),this.addListener("frame",c),c()}),this}stopFollowingUser(){return this.batch(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")}),this}getUnorderedRenderingShapes(t){const r=[];let o=ys*2,s=ys;const i=this.getErasingShapeIds(),a=(l,u,d)=>{const f=this.getShape(l);if(!f)return;u*=f.opacity;let p=!1;const y=this.getShapeUtil(f);t&&(p=!d&&i.includes(l),p&&(u*=.32)),r.push({id:l,shape:f,util:y,index:o,backgroundIndex:s,opacity:u}),o+=1,s+=1;const m=this.getSortedChildIdsForParent(l);if(!m.length)return;let w=null;y.providesBackgroundForChildren(f)&&(w=s,s=o,o+=ys);for(const S of m)a(S,u,d||p);w!==null&&(s=w)},c=t?[this.getCurrentPage()]:this.getPages();for(const l of c)for(const u of this.getSortedChildIdsForParent(l.id))a(u,1,!1);return r}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(PR)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(nn)}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>=Tf)return;const r=this.getPages(),o=bz(t.name??"Page 1",r.map(a=>a.name));let s=t.index;(!s||r.some(a=>a.index===s))&&(s=Lo(r[r.length-1].index));const i=Go.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(c=>c.id===r),a=o[i-1]??o[i+1];this.setCurrentPage(a.id)}this.store.remove([s.id])}}),this}duplicatePage(t,r=Go.createId()){if(this.getPages().length>=Tf)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 c=this.getPages(),l=zl(s.index,(u=c[c.indexOf(s)+1])==null?void 0:u.index);if(this.createPage({name:s.name+" Copy",id:r,index:l}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(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.batch(()=>this.store.put(t))}updateAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:this.batch(()=>{this.store.put(t.map(r=>({...this.store.get(r.id),...r})))})}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.batch(()=>this.store.remove(r))}getAsset(t){return this.store.get(typeof t=="string"?t:t.id)}_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(Pn(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||Pn(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?J.FromPoints(oe.applyToPoints(r,this.getShapeGeometry(t).vertices)):new J})}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(Pn(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=hP(s,i);return a?a.map(b.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,c)=>a&&b.Equals(a,o[c])))return r.clone();const i=hP(o,s);return i?J.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(Pn(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(Pn(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 l;if(t.length===0)return;const o=typeof t[0]=="string"?t:t.map(u=>u.id),s=ye(o.map(u=>this.getShape(u)));if(s.length===1){const u=s[0].parentId;return Pn(u)?void 0:r?(l=this.findShapeAncestor(s[0],r))==null?void 0:l.id:u}const[i,...a]=s;let c=this.getShapeParent(i);for(;c;){if(r&&!r(c)){c=this.getShapeParent(c);continue}if(a.every(u=>this.hasAncestor(u,c.id)))return c.id;c=this.getShapeParent(c)}}isShapeOrAncestorLocked(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 Tz(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:c=!1,hitLabels:l=!1,hitInside:u=!1,hitFrameInside:d=!1}=r;let f=1/0,p=null,y=1/0,m=null;const w=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(S=>{if(S.isLocked&&!c||this.isShapeOfType(S,"group"))return!1;const v=this.getShapeMask(S);return v&&!er(t,v)?!1:i?i(S):!0});for(let S=w.length-1;S>=0;S--){const v=w[S],P=this.getShapeGeometry(v),E=P instanceof Hr,C=this.getPointInShapeSpace(v,t);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const _ of P.children)if(_.isLabel&&_.isPointInBounds(C))return v}if(this.isShapeOfType(v,"frame")){const _=P.distanceToPoint(C,u);if(Math.abs(_)<=a)return m||v;if(P.hitTestPoint(C,0,!0))return m||p||(d?v:void 0);continue}let I;if(E){let _=1/0;for(const k of P.children){if(k.isLabel&&!l)continue;const $=k.distanceToPoint(C,u);$<_&&(_=$)}I=_}else a===0&&(P.bounds.w<1||P.bounds.h<1)||P.bounds.containsPoint(C,a)?I=P.distanceToPoint(C,u):I=1/0;if(P.isClosed){if(I<=a){if(P.isFilled||E&&P.children[0].isFilled)return m||v;if(this.getShapePageBounds(v).contains(s))continue;if(Math.abs(I)<a)Math.abs(I)<y&&(y=Math.abs(I),m=v);else if(!m){const{area:_}=P;_<f&&(f=_,p=v)}}}else if(I<Vo/o)return v}return m||p||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,c=this.getShapeMask(a);return c&&!er(r,c)?!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 b(0,0);if(Pn(s.parentId))return b.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):b.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++)h2(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(mr(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||!mr(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 Pn(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=Pn(r)?oe.Identity():this.getShapePageTransform(r),c=a.rotation();let l=[];const u=ye(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?l=nc(o,m.index,s.length):l=Ng(o,s.length)}else{const m=u.sort(nn).find(w=>w.index>o);m?l=nc(o,m.index,s.length):l=Ng(o,s.length)}}else{const y=u.length&&u[u.length-1];l=y?Ng(y.index,s.length):Bl(s.length)}const d=a.clone().invert(),f=ye(s.map(y=>this.getShape(y))),p=f.filter(y=>y.isLocked);p.length&&this.updateShapes(p.map(({id:y,type:m})=>({id:y,type:m,isLocked:!1})));for(let y=0;y<f.length;y++){const m=f[y],w=this.getShapePageTransform(m);if(!w)continue;const S=w.point();if(!S)continue;const v=d.applyToPoint(S),P=w.rotation()-c;i.push({id:m.id,type:m.type,parentId:r,x:v.x,y:v.y,rotation:P,index:l[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 Lo(s.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o||Bo}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(nn))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(c=>c.id===i.id||this.hasAncestor(i,c.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 c=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(c==null?void 0:c.id)!==a.id&&!this.hasAncestor(c,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((c==null?void 0:c.id)===a.id)break;a=this.getShapeParent(a)}return i}_getBindingsIndexCache(){const t=_z(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)??Bo;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 c=this.getBindingUtil(o.type).getDefaultProps(),l=this.store.schema.types.binding.create({...o,id:o.id??Ci(),props:{...c,...o.props}});r.push(l)}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=Ao(s,o);if(i===s)continue;const a=this.getShape(i.fromId),c=this.getShape(i.toId);!a||!c||this.canBindShapes({fromShape:a,toShape:c,binding:i})&&r.push(i)}return this.store.put(r),this}updateBinding(t){return this.updateBindings([t])}deleteBindings(t){const r=t.map(o=>typeof o=="string"?o:o.id);return this.store.remove(r),this}deleteBinding(t){return this.deleteBindings([t])}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,c={fromShapeType:s,toShapeType:i,bindingType:a};return s===i?this.getShapeUtil(s).canBind(c):this.getShapeUtil(s).canBind(c)&&this.getShapeUtil(i).canBind(c)}rotateShapesBy(t,r){if((typeof t[0]=="string"?t:t.map(i=>i.id)).length<=0)return this;const s=c2({editor:this});return s?(Ih({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(t,r){var i,a,c;let o=t;const s=this.getShapeUtil(t);return o=Ao(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=Ao(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=Ao(o,((a=s.onTranslate)==null?void 0:a.call(s,t,o))??void 0),o=Ao(o,((c=s.onTranslateEnd)==null?void 0:c.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),c=b.From(r),l=this.getShapeParentTransform(a);l&&c.rot(-l.rotation()),s.push(this.getChangesToTranslateShape(a,c.add(a)))}return this.updateShapes(s),this}duplicateShapes(t,r){return this.history.batch(()=>{const o=typeof t[0]=="string"?t:t.map(f=>f.id);if(o.length<=0)return this;const s=new Set(o),i=this.getShapeAndDescendantIds(o),a=[...i].reverse(),c=new Map;for(const f of i)c.set(f,Be());const{shapesToCreate:l,bindingsToCreate:u}=SP(this,i,f=>{const p=[];for(const m of f){const w=this.getBinding(m);if(!w)continue;const S=Ci();p.push({...w,id:S,fromId:Vn(c.get(w.fromId)),toId:Vn(c.get(w.toId))})}const y=[];for(const m of a){const w=Vn(c.get(m)),S=this.getShape(m);if(!S)continue;let v=0,P=0;if(r&&s.has(m)){const T=this.getShapeParentTransform(S),O=new b(r.x,r.y).rot(-T.rotation());v=O.x,P=O.y}const E=S.parentId,C=this.getSortedChildIdsForParent(E),I=C.indexOf(S.id),_=C[I+1],k=_?this.getShape(_):null,$=k?zl(S.index,k.index):Lo(S.index);y.push({...S,id:w,x:S.x+v,y:S.y+P,index:$,parentId:c.get(S.parentId)??S.parentId})}return{shapesToCreate:y,bindingsToCreate:p}});if(l.length+this.getCurrentPageShapeIds().size>ys){Ad(this);return}if(this.createShapes(l),this.createBindings(u),this.setSelectedShapes(ye(o.map(f=>c.get(f)))),r!==void 0){const f=this.getSelectionPageBounds(),p=this.getViewportPageBounds();f&&!p.contains(f)&&this.centerOnPoint(f.center,{animation:{duration:no}})}}),this}moveShapesToPage(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(o.length===0)return this;if(this.getInstanceState().isReadonly)return this;const s=this.getCurrentPageId();if(r===s)return this;if(!this.store.has(r))return this;const i=this.getContentFromCurrentPage(o);if(!i)return this;if(this.getPageShapeIds(r).size+i.shapes.length>ys)return Ad(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 c=this.getShape(a);c&&(i.push(c),c.isLocked?s=!1:o=!1)}return this.batch(()=>{s?(this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):o?this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Md(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Md(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Md(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Md(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=ye(o.map(a=>this.getShape(a)));if(!s.length)return this;s=ye(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(c=>this.getShape(c)):a).flat());const i=J.Common(ye(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const c=this.getShapeGeometry(a).bounds,l=this.getShapePageTransform(a.id);l&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:c,initialPageTransform:l,initialShape:a,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(a).isAspectRatioLocked(a),scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(w=>w.id);if(this.getInstanceState().isReadonly)return this;const i=s.map(w=>this.getShape(w)).filter(w=>w?this.getShapeUtil(w).canBeLaidOut(w):!1),a=i.length;if(o===0&&a<3||a<2)return this;const c=Object.fromEntries(i.map(w=>[w.id,this.getShapePageBounds(w)]));let l,u,d,f;r==="horizontal"?(l="x",u="minX",d="maxX",f="width"):(l="y",u="minY",d="maxY",f="height");let p;if(o===0){const w=[];i.sort((v,P)=>c[v.id][u]-c[P.id][u]);for(let v=0;v<a-1;v++){const P=i[v],E=i[v+1],C=c[P.id],_=c[E.id][u]-C[d],k=w.find($=>$.gap===_);k?k.count++:w.push({gap:_,count:1})}let S=0;w.forEach(v=>{v.count>S&&(S=v.count,p=v.gap)}),S===1&&(p=Math.max(0,w.reduce((v,P)=>v+P.gap*P.count,0)/(a-1)))}else p=o;const y=[];let m=c[i[0].id][d];return i.forEach((w,S)=>{var I,_;if(S===0)return;const v={x:0,y:0};v[l]=m+p-c[w.id][l];const P=this.getShapeParent(w),E=P?b.Rot(v,-this.getShapePageTransform(P).decompose().rotation):v,C=(_=(I=this.getShapeUtil(w)).onTranslateStart)==null?void 0:_.call(I,w);y.push(C?{...C,[l]:w[l]+E[l]}:{id:w.id,type:w.type,[l]:w[l]+E[l]}),m+=c[w.id][f]+p}),this.updateShapes(y),this}packShapes(t,r){var _,k;const o=typeof t[0]=="string"?t:t.map($=>$.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=o.map($=>this.getShape($)).filter($=>$?this.getShapeUtil($).canBeLaidOut($):!1),i={},a={};let c,l,u=0;for(let $=0;$<s.length;$++)c=s[$],l=this.getShapePageBounds(c),i[c.id]=l,a[c.id]=l.clone(),u+=l.width*l.height;const d=J.Common(ye(Object.values(i))),f=d.width;s.sort(($,T)=>i[T.id].height-i[$.id].height);const p=Math.max(Math.ceil(Math.sqrt(u/.95)),f),y=[new J(d.x,d.y,p,1/0)];let m=0,w=0,S,v;for(let $=0;$<s.length;$++){c=s[$],l=a[c.id];for(let T=y.length-1;T>=0;T--)if(S=y[T],!(l.width>S.width||l.height>S.height)){l.x=S.x,l.y=S.y,w=Math.max(w,l.maxY),m=Math.max(m,l.maxX),l.width===S.width&&l.height===S.height?(v=y.pop(),T<y.length&&(y[T]=v)):l.height===S.height?(S.x+=l.width+r,S.width-=l.width+r):l.width===S.width?(S.y+=l.height+r,S.height-=l.height+r):(y.push(new J(S.x+(l.width+r),S.y,S.width-(l.width+r),l.height)),S.y+=l.height+r,S.height-=l.height+r);break}}const P=J.Common(Object.values(a)),E=b.Sub(d.center,P.center);let C;const I=[];for(let $=0;$<s.length;$++){c=s[$],l=i[c.id],C=a[c.id];const T=b.Sub(C.point,l.point).add(E),O=this.getShapeParentTransform(c);O&&T.rot(-O.rotation());const N={id:c.id,type:c.type,x:c.x+T.x,y:c.y+T.y},A=(k=(_=this.getShapeUtil(c)).onTranslateStart)==null?void 0:k.call(_,{...c,...N});A?I.push({...N,...A}):I.push(N)}return I.length&&this.updateShapes(I),this}alignShapes(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=ye(o.map(l=>this.getShape(l))),i=Object.fromEntries(s.map(l=>[l.id,this.getShapePageBounds(l)])),a=J.Common(ye(Object.values(i))),c=[];return s.forEach(l=>{const u=i[l.id];if(!u)return;const d={x:0,y:0};switch(r){case"top":{d.y=a.minY-u.minY;break}case"center-vertical":{d.y=a.midY-u.minY-u.height/2;break}case"bottom":{d.y=a.maxY-u.minY-u.height;break}case"left":{d.x=a.minX-u.minX;break}case"center-horizontal":{d.x=a.midX-u.minX-u.width/2;break}case"right":{d.x=a.maxX-u.minX-u.width;break}}const f=this.getShapeParent(l),p=f?b.Rot(d,-this.getShapePageTransform(f).decompose().rotation):d;c.push(this.getChangesToTranslateShape(l,b.Add(l,p)))}),this.updateShapes(c),this}distributeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(P=>P.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=ye(o.map(P=>this.getShape(P))),a=Object.fromEntries(i.map(P=>[P.id,this.getShapePageBounds(P)]));let c,l,u,d,f;r==="horizontal"?(c="x",l="minX",u="maxX",d="midX",f="width"):(c="y",l="minY",u="maxY",d="midY",f="height");const p=[],y=i.sort((P,E)=>a[P.id][l]-a[E.id][l])[0],m=i.sort((P,E)=>a[E.id][u]-a[P.id][u])[0],w=a[y.id][d],S=(a[m.id][d]-w)/(s-1),v=w+S;return i.filter(P=>P!==y&&P!==m).sort((P,E)=>a[P.id][d]-a[E.id][d]).forEach((P,E)=>{const C={x:0,y:0};C[c]=v+S*E-a[P.id][f]/2-a[P.id][c];const I=this.getShapeParent(P),_=I?b.Rot(C,-this.getShapePageTransform(I).rotation()):C;p.push(this.getChangesToTranslateShape(P,b.Add(P,_)))}),this.updateShapes(p),this}stretchShapes(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=ye(o.map(l=>this.getShape(l))),i=Object.fromEntries(o.map(l=>[l,this.getShapeGeometry(l).bounds])),a=Object.fromEntries(o.map(l=>[l,this.getShapePageBounds(l)])),c=J.Common(ye(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const l of s){if(this.getShapePageTransform(l).rotation()%Re)continue;const d=i[l.id],f=a[l.id],p=new b(0,c.minY-f.minY),y=this.getShapeParentTransform(l);y&&p.rot(-y.rotation());const{x:m,y:w}=b.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:m,y:w}]);const S=new b(1,c.height/f.height);this.resizeShape(l.id,S,{initialBounds:d,scaleOrigin:new b(f.center.x,c.minY),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const l of s){const u=i[l.id],d=a[l.id];if(this.getShapePageTransform(l).rotation()%Re)continue;const p=new b(c.minX-d.minX,0),y=this.getShapeParentTransform(l);y&&p.rot(-y.rotation());const{x:m,y:w}=b.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:m,y:w}]);const S=new b(c.width/d.width,1);this.resizeShape(l.id,S,{initialBounds:u,scaleOrigin:new b(c.minX,d.center.y),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}}return this}resizeShape(t,r,o={}){var y,m,w;const s=typeof t=="string"?t:t.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new b(1,r.y)),Number.isFinite(r.y)||(r=new b(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 c=o.initialPageTransform?oe.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!c)return this;const l=c.rotation();if(l==null)return this;const u=o.scaleAxisRotation??l,d=o.initialBounds??this.getShapeGeometry(s).bounds;if(!d)return this;const f=o.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!g_(l,u))return this._resizeUnalignedShape(s,r,{...o,initialBounds:d,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:c,isAspectRatioLocked:f,initialShape:i});const p=this.getShapeUtil(i);if(f&&(Math.abs(r.x)>Math.abs(r.y)?r=new b(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new b(Math.sign(r.x)*Math.abs(r.y),r.y)),p.onResize&&p.canResize(i)){const S=this._scalePagePoint(oe.applyToPoint(c,new b(0,0)),a,r,u),v=this.getPointInParentSpace(i.id,S),P=new b(r.x,r.y),E=Cl((l-u)%Math.PI,0);P.x=E?r.x:r.y,P.y=E?r.y:r.x;const C=oe.applyToPoint(c,new b),{x:I,y:_}=this.getPointInParentSpace(i.id,C);let k=i;o.skipStartAndEndCallbacks||(k=Ao(i,((m=p.onResizeStart)==null?void 0:m.call(p,i))??void 0)),k=Ao(k,{id:s,type:i.type,x:v.x,y:v.y,...p.onResize({...i,x:I,y:_},{newPoint:v,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:P.x,scaleY:P.y,initialBounds:d,initialShape:i})}),o.skipStartAndEndCallbacks||(k=Ao(k,((w=p.onResizeEnd)==null?void 0:w.call(p,i,k))??void 0)),this.updateShapes([k])}else{const S=oe.applyToPoint(c,d.center),v=this._scalePagePoint(S,a,r,u),P=this.getPointInParentSpace(i.id,S),E=this.getPointInParentSpace(i.id,v),C=b.Sub(E,P);this.updateShapes([{id:s,type:i.type,x:i.x+C.x,y:i.y+C.y}])}return this}_scalePagePoint(t,r,o,s){const i=b.RotWith(t,r,-s).sub(r),a=b.MulV(i,o);return b.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(t,r,o){const{type:s}=o.initialShape,i=new b(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),c=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),l=this.getShapePageBounds(t),u=this.getShapePageTransform(t),d=l.center,f=u.point();if(!d||!f)return this;const p=b.Sub(c,d),y=b.Add(f,p),{x:m,y:w}=this.getPointInParentSpace(t,y);return this.updateShapes([{id:t,type:s,x:m,y:w}]),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>ys)return Ad(this),this;const s=this.getFocusedGroupId();return this.batch(()=>{var d,f;const i=this.getCurrentPageShapesSorted(),a=t.map(p=>{if(p.id||(p={id:Be(),...p}),!p.parentId||!(this.store.has(p.parentId)||t.some(y=>y.id===p.parentId))){let y=this.getFocusedGroupId();for(let w=i.length-1;w>=0;w--){const S=i[w];if(this.getShapeUtil(S).canReceiveNewChildrenOfType(S,p.type)&&this.isPointInShape(S,{x:p.x??0,y:p.y??0},{margin:0,hitInside:!0})){y=S.id;break}}const m=p.parentId;if(y===p.id&&(y=s),y!==m&&(p={...p},p.parentId=y,mr(y))){const w=this.getPointInShapeSpace(this.getShape(y),{x:p.x??0,y:p.y??0});p.x=w.x,p.y=w.y,p.rotation=-this.getShapePageTransform(y).rotation()+(p.rotation??0)}}return p}),c=new Map,l=[],{opacityForNextShape:u}=this.getInstanceState();for(const p of a){const y=this.getShapeUtil(p);let m=p.index;if(!m){const P=p.parentId??s;c.has(P)||c.set(P,this.getHighestIndexForParent(P)),m=c.get(P),c.set(P,Lo(m))}const w=y.getDefaultProps();for(const[P,E]of this.styleProps[p.type])w[E]=this.getStyleForNextShape(P);let S=this.store.schema.types.shape.create({...p,index:m,opacity:p.opacity??u,parentId:p.parentId??s,props:"props"in p?{...w,...p.props}:w});if(S.index===void 0)throw Error("no index!");const v=(f=(d=this.getShapeUtil(S)).onBeforeCreate)==null?void 0:f.call(d,S);v&&(S=v),l.push(S)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)})}animateShape(t,r={animation:Gg}){return this.animateShapes([t],r)}animateShapes(t,r={animation:Gg}){if(!r.animation)return this;const{duration:o=500,easing:s=an.linear}=r.animation,i=ot();let a=o,c;const l=[];let u,d;for(let y=0,m=t.length;y<m;y++){if(u=t[y],!u)continue;d={partial:u,values:[]};const w=this.getShape(u.id);if(w){for(const S of["x","y","rotation"])u[S]!==void 0&&w[S]!==u[S]&&d.values.push({prop:S,from:w[S],to:u[S]});l.push(d),this.animatingShapes.set(w.id,i)}}let f;const p=y=>{if(a-=y,a<0){const{animatingShapes:v}=this,P=t.filter(E=>E&&v.get(E.id)===i);P.length&&this.updateShapes(P),this.off("tick",p);return}c=s(1-a/o);const{animatingShapes:m}=this,w=[];let S;for(let v=0,P=l.length;v<P;v++)f=l[v],S=m.get(f.partial.id),S===i&&w.push({id:f.partial.id,type:f.partial.type,...f.values.reduce((E,{prop:C,from:I,to:_})=>(E[C]=I+(_-I)*c,E),{})});this._updateShapes(w)};return this.on("tick",p),this}groupShapes(t,r=Be()){var p;if(!Array.isArray(t))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const o=typeof t[0]=="string"?t:t.map(y=>y.id);if(o.length<=1)return this;const s=ye(this._getUnlockedShapeIds(o).map(y=>this.getShape(y))),i=s.sort(nn).map(y=>y.id),a=J.Common(ye(s.map(y=>this.getShapePageBounds(y)))),{x:c,y:l}=a.point,u=this.findCommonAncestor(s)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const d=s.filter(y=>y.parentId===u).sort(nn),f=(p=d[d.length-1])==null?void 0:p.index;return this.batch(()=>{this.createShapes([{id:r,type:"group",parentId:u,index:f,x:c,y:l,opacity:1,props:{}}]),this.reparentShapes(i,r),this.select(r)}),this}ungroupShapes(t){const r=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const o=new Set,s=ye(r.map(a=>this.getShape(a))),i=[];return s.forEach(a=>{this.isShapeOfType(a,"group")?i.push(a):o.add(a.id)}),i.length===0?this:(this.batch(()=>{let a;for(let c=0,l=i.length;c<l;c++){a=i[c];const u=this.getSortedChildIdsForParent(a.id);for(let d=0,f=u.length;d<f;d++)o.add(u[d]);this.reparentShapes(u,a.parentId,a.index)}this.deleteShapes(i.map(c=>c.id)),this.select(...o)}),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,kn(t.props,s))}_getSelectionSharedStyles(){const t=this.getSelectedShapes(),r=new tv;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 kn(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const t=this.root.getCurrent(),r=new tv;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 c of a)s(this.getShape(c))}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 c=this.getSortedChildIdsForParent(a.id);for(const l of c)i(this.getShape(l))}else{const c=this.getShapeUtil(a),l=this.styleProps[a.type].get(t);if(l){const u={id:a.id,type:a.type,props:{[l]:r}};s.push({util:c,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))}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 SP(this,o,s=>{const i=[];for(const d of s){const f=this.getBinding(d);f&&i.push(f)}const a=[],c=[];for(const d of o){const f=this.getShape(d);if(!f)continue;if(!o.has(f.parentId)){const y=this.getShapePageTransform(f.id),m=y.point();c.push({...f,x:m.x,y:m.y,rotation:y.rotation(),parentId:this.getCurrentPageId()}),a.push(f.id)}else c.push(f)}const l=[],u=new Set;for(const d of c){if(!("assetId"in d.props))continue;const f=d.props.assetId;if(!f||u.has(f))continue;u.add(f);const p=this.getAsset(f);p&&l.push(p)}return{schema:this.store.schema.serialize(),shapes:c,rootShapeIds:a,bindings:i,assets:l}})}putContentOntoCurrentPage(t,r={}){var O,N;if(this.getInstanceState().isReadonly)return this;if(!t.schema)throw Error(`Could not put content:
97
- content is missing a schema.`);const{select:o=!1,preserveIds:s=!1,preservePosition:i=!1}=r;let{point:a=void 0}=r;const c=this.getCurrentPageId(),{rootShapeIds:l}=t,u=[],d=[],f=[],p={store:{...Object.fromEntries(t.assets.map(A=>[A.id,A])),...Object.fromEntries(t.shapes.map(A=>[A.id,A])),...Object.fromEntries(((O=t.bindings)==null?void 0:O.map(A=>[A.id,A]))??[])},schema:t.schema},y=this.store.schema.migrateStoreSnapshot(p);if(y.type==="error")throw Error("Could not put content: could not migrate content");for(const A of Object.values(y.value))switch(A.typeName){case"asset":{u.push(A);break}case"shape":{d.push(A);break}case"binding":{f.push(A);break}}const m=new Map(s?d.map(A=>[A.id,A.id]):d.map(A=>[A.id,Be()])),w=new Map(s?f.map(A=>[A.id,A.id]):f.map(A=>[A.id,Ci()]));let S=this.getCurrentPageId(),v=1/0,P=[];for(const A of this.getSelectedShapes()){if(v===0)break;const j=this.isShapeOfType(A,"frame"),L=this.getShapeAncestors(A);j&&L.push(A);const X=j?L.length+1:L.length;if(X<v)v=X,P=L,S=j?A.id:A.parentId;else if(X===v){if(P.length!==L.length)throw Error(`Ancestors: ${P.length} !== ${L.length}`);if(P.length===0){S=c;break}else{S=c;for(let V=0;V<P.length&&L[V]===P[V];V++)S=L[V].id}}}let E=!1;if(!Pn(S)){const A=this.getShape(S);if(A){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(A)))S=c;else if(l.length===1){const j=d.find(L=>L.id===l[0]);this.isShapeOfType(A,"frame")&&this.isShapeOfType(j,"frame")&&j.props.w===(A==null?void 0:A.props.w)&&j.props.h===(A==null?void 0:A.props.h)&&(E=!0)}}else S=c}E||(E=m.has(S)),E&&(S=this.getShape(S).parentId);let C=this.getHighestIndexForParent(S);const I=[],_=d.map(A=>{const j=m.get(A.id),L={...A,id:j};return l.includes(A.id)&&(L.parentId=c,I.push(L)),m.has(L.parentId)?L.parentId=m.get(A.parentId):(l.push(L.id),L.index=C,C=Lo(C)),L});if(_.length+this.getCurrentPageShapeIds().size>ys)return Ad(this),this;const k=f.map(A=>({...A,id:Vn(w.get(A.id)),fromId:Vn(m.get(A.fromId)),toId:Vn(m.get(A.toId))})),$=[],T=[];for(const A of u)this.store.has(A.id)||((A.type==="image"||A.type==="video")&&((N=A.props.src)!=null&&N.startsWith("data:image"))&&(T.push(xt(A)),A.props.src=null),$.push(A));return Promise.allSettled(T.map(async A=>{const j=await wz(A.props.src,A.props.name,A.props.mimeType??"image/png"),L=await this.getAssetForExternalContent({type:"file",file:j});if(!L){this.deleteAssets([A.id]);return}this.updateAssets([{...L,id:A.id}])})),this.batch(()=>{$.length>0&&this.createAssets($),this.createShapes(_),this.createBindings(k),o&&this.select(...I.map(V=>V.id)),S!==c&&this.reparentShapes(I.map(V=>V.id),S);const A=_.map(V=>this.getShape(V.id)),j=J.Common(A.map(V=>this.getShapePageBounds(V)));if(a===void 0)if(Pn(S)){const V=this.getViewportPageBounds();i||V.includes(J.From(j))?a=j.center:a=V.center}else{const V=this.getShape(S);a=oe.applyToPoint(this.getShapePageTransform(V),this.getShapeGeometry(V).bounds.center)}if(I.length===1){const V=I[0];if(this.isShapeOfType(V,"frame"))for(;this.getShapesAtPoint(a).some(H=>this.isShapeOfType(H,"frame")&&H.props.w===V.props.w&&H.props.h===V.props.h);)a.x+=j.w+16}const L=J.Common(ye(I.map(({id:V})=>this.getShapePageBounds(V)))).center,X=b.Sub(a,L);this.updateShapes(I.map(({id:V})=>{const H=this.getShape(V),U=this.getShapeParentTransform(V).decompose().rotation,K=b.Rot(X,-U);return{id:H.id,type:H.type,x:H.x+K.x,y:H.y+K.y}}))}),this}async getSvgElement(t,r={}){const o=await jz(this,t,r);if(!o)return;const s=document.createDocumentFragment(),i=r2(s);Yi.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:c}=this.store.unsafeGetWithoutCapture(en),{x:l,y:u,z:d}=this.store.unsafeGetWithoutCapture(this.getCameraId()),f=t.point.x-c.x,p=t.point.y-c.y,y=t.point.z??.5;o.setTo(i),s.setTo(a),i.set(f,p);const m=f/d-l,w=p/d-u;isFinite(m)&&isFinite(w)&&a.set(m,w,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:Cf,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===Db.CAMERA_MOVE?((S=this.store.unsafeGetWithoutCapture(Cf))==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(){return this.focusManager.focus(),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){Pt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(t),this.performanceTrackerTimeout=setTimeout(()=>{this.performanceTracker.stop()},50))}}re([G],ee.prototype,"getCanUndo");re([G],ee.prototype,"getCanRedo");re([G],ee.prototype,"getPath");re([G],ee.prototype,"getCurrentTool");re([G],ee.prototype,"getCurrentToolId");re([G],ee.prototype,"getDocumentSettings");re([G],ee.prototype,"getInstanceState");re([G],ee.prototype,"getOpenMenus");re([G],ee.prototype,"getIsMenuOpen");re([G],ee.prototype,"getPageStates");re([G],ee.prototype,"_getPageStatesQuery");re([G],ee.prototype,"getCurrentPageState");re([G],ee.prototype,"_getCurrentPageStateId");re([G],ee.prototype,"getSelectedShapeIds");re([G],ee.prototype,"getSelectedShapes");re([G],ee.prototype,"getOnlySelectedShapeId");re([G],ee.prototype,"getOnlySelectedShape");re([G],ee.prototype,"getSelectionPageBounds");re([G],ee.prototype,"getSelectionRotation");re([G],ee.prototype,"getSelectionRotatedPageBounds");re([G],ee.prototype,"getSelectionRotatedScreenBounds");re([G],ee.prototype,"getFocusedGroupId");re([G],ee.prototype,"getFocusedGroup");re([G],ee.prototype,"getEditingShapeId");re([G],ee.prototype,"getEditingShape");re([G],ee.prototype,"getHoveredShapeId");re([G],ee.prototype,"getHoveredShape");re([G],ee.prototype,"getHintingShapeIds");re([G],ee.prototype,"getHintingShape");re([G],ee.prototype,"getErasingShapeIds");re([G],ee.prototype,"getErasingShapes");re([G],ee.prototype,"getCameraId");re([G],ee.prototype,"getCamera");re([G],ee.prototype,"getViewportPageBoundsForFollowing");re([G],ee.prototype,"getCameraForFollowing");re([G],ee.prototype,"getZoomLevel");re([G],ee.prototype,"getViewportScreenBounds");re([G],ee.prototype,"getViewportScreenCenter");re([G],ee.prototype,"getViewportPageBounds");re([G],ee.prototype,"_getCollaboratorsQuery");re([G],ee.prototype,"getCollaborators");re([G],ee.prototype,"getCollaboratorsOnCurrentPage");re([G],ee.prototype,"getRenderingShapes");re([G],ee.prototype,"_getAllPagesQuery");re([G],ee.prototype,"getPages");re([G],ee.prototype,"getCurrentPageId");re([G],ee.prototype,"getCurrentPageShapeIdsSorted");re([G],ee.prototype,"_getAllAssetsQuery");re([G],ee.prototype,"_getShapeGeometryCache");re([G],ee.prototype,"_getShapeHandlesCache");re([G],ee.prototype,"_getShapePageTransformCache");re([G],ee.prototype,"_getShapePageBoundsCache");re([G],ee.prototype,"_getShapeClipPathCache");re([G],ee.prototype,"_getShapeMaskCache");re([G],ee.prototype,"_getShapeMaskedPageBoundsCache");re([G],ee.prototype,"_notVisibleShapes");re([G],ee.prototype,"getCulledShapes");re([G],ee.prototype,"getCurrentPageBounds");re([G],ee.prototype,"getCurrentPageShapes");re([G],ee.prototype,"getCurrentPageShapesSorted");re([G],ee.prototype,"getCurrentPageRenderingShapesSorted");re([G],ee.prototype,"_getBindingsIndexCache");re([G],ee.prototype,"_getSelectionSharedStyles");re([G({isEqual:(e,n)=>e.equals(n)})],ee.prototype,"getSharedStyles");re([G],ee.prototype,"getSharedOpacity");function Ad(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:ys})}function Ao(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[c,l]of Object.entries(a))l!==void 0&&(t[i][c]=l);continue}t[i]=a}}return t||e}function h2(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++)h2(e,o[s],t)}function SP(e,n,t){const r=new Set,o=new Set;for(const i of n)if(e.getShape(i))for(const c of e.getBindingsInvolvingShape(i)){const l=n.has(c.fromId),u=n.has(c.toId);if(l&&u){r.add(c.id);continue}(!l||!u)&&o.add(c.id)}let s;if(e.history.ignore(()=>{const i=e.store.extractingChanges(()=>{e.deleteBindings([...o]);try{s=pn.ok(t(r))}catch(a){s=pn.err(a)}});e.store.applyDiff(Qy(i))}),s.ok)return s.value;throw s.error}function vP(e,n){if(!n.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=n.constraints,o=e.getViewportScreenBounds(),s=J.From(n.constraints.bounds),i=(o.w-t*2)/s.w,a=(o.h-r*2)/s.h;return{zx:i,zy:a}}function Nu(){const e=B(),n=u2();return W("isDarkMode",()=>(n==null?void 0:n.isDarkMode)??e.user.getIsDarkMode(),[n,e])}const xP="<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'/>",wP="<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'/>",jd='<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 ps(e,n,t,r,o,s=16,i=16){const a=(-t-n)*(ke/180),c=Math.sin(a),l=Math.cos(a),u=1*l-1*c,d=1*c+1*l;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${d}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${n+t} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const d8=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],h8={none:()=>"none","ew-resize":(e,n,t)=>ps(wP,e,0,n,t),"ns-resize":(e,n,t)=>ps(wP,e,90,n,t),"nesw-resize":(e,n,t)=>ps(xP,e,0,n,t),"nwse-resize":(e,n,t)=>ps(xP,e,90,n,t),"nwse-rotate":(e,n,t)=>ps(jd,e,0,n,t),"nesw-rotate":(e,n,t)=>ps(jd,e,90,n,t),"senw-rotate":(e,n,t)=>ps(jd,e,180,n,t),"swne-rotate":(e,n,t)=>ps(jd,e,270,n,t)};function Kn(e,n=0,t="black"){return h8[e](cL(n),!1,t)}function f8(){const e=B(),n=dn(),t=Nu();$s("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(d8.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Kn(r,o,t?"white":"black"))},[e,n,t])}function p8(){const e=B(),n=dn(),t=Nu(),r=W(Pt.forceSrgb);Se.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 Ix(e){const n=x.useRef();return x.useLayoutEffect(()=>{n.current=e}),x.useDebugValue(e),x.useCallback((...t)=>{const r=n.current;return st(r,"fn does not exist"),r(...t)},[])}function g8(){const[e,n]=x.useState(0);x.useEffect(()=>n(t=>t+1),[])}const Za="TLDRAW_TAB_ID_v2",ho=globalThis.window;function m8(){return ho?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(ho.navigator.platform)||ho.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const sp=ho?ho[Za]??yE(Za)??"TLDRAW_INSTANCE_STATE_V1_"+ot():"<error>";ho&&(ho[Za]=sp,m8()?l0(Za,sp):SE(Za));ho==null||ho.addEventListener("beforeunload",()=>{l0(Za,sp)});const f2={Initial:0},Yp=Math.max(...Object.values(f2));function y8(e){e.version<f2.Initial,e.version=Yp}const p2=ve({version:fe,currentPageId:Ul,isFocusMode:we,exportBackground:we,isDebugMode:we,isToolLocked:we,isGridMode:we,pageStates:zt(ve({pageId:Ul,camera:ve({x:fe,y:fe,z:fe}),selectedShapeIds:zt(gr),focusedGroupId:gr.nullable()}))});function S8(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!==Yp&&(e=xt(e),y8(e));try{return p2.validate(e)}catch(n){return console.warn(n),null}}function v8(e){const n=e.query.ids("page");return G("sessionStateSnapshot",()=>{const t=e.get(en);if(!t)return null;const r=[...n.get()];return{version:Yp,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(xr.createId(o)),i=e.get(Fr.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 x8(e,n){const t=S8(n);if(!t)return;const r=e.allRecords().filter(i=>i.typeName==="instance_page_state"||i.typeName==="camera"),o={added:{},updated:{},removed:{...i0(r.map(i=>[i.id,i]))}};e.has(en)&&(o.removed[en]=e.get(en));const s={removed:{},updated:{},added:{[en]:e.schema.types.instance.create({id:en,currentPageId:t.currentPageId,isDebugMode:t.isDebugMode,isFocusMode:t.isFocusMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,exportBackground:t.exportBackground})}};for(const i of t.pageStates){const a=Fr.createId(i.pageId),c=xr.createId(i.pageId);s.added[a]=Fr.create({id:Fr.createId(i.pageId),x:i.camera.x,y:i.camera.y,z:i.camera.z}),s.added[c]=xr.create({id:xr.createId(i.pageId),pageId:i.pageId,selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId})}Ts(()=>{e.applyDiff(Cp([o,s])),e.ensureStoreIsUsable()})}function w8(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!==en)[0];if(!t)return null;const r={version:Yp,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 p2.validate(r),r}catch{return null}}function b8(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
98
-
99
- Keep seeing this message?
100
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
101
- • If your hard disk is full, try clearing up some space and then reload the page.`)}function P8(){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.
102
-
103
- Keep seeing this message?
104
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const C8=(e,n)=>n.some(t=>e instanceof t);let bP,PP;function I8(){return bP||(bP=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function E8(){return PP||(PP=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const g2=new WeakMap,nv=new WeakMap,m2=new WeakMap,km=new WeakMap,Ex=new WeakMap;function _8(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(Ho(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return n.then(t=>{t instanceof IDBCursor&&g2.set(t,e)}).catch(()=>{}),Ex.set(n,e),n}function k8(e){if(nv.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)});nv.set(e,n)}let rv={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return nv.get(e);if(n==="objectStoreNames")return e.objectStoreNames||m2.get(e);if(n==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Ho(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 T8(e){rv=e(rv)}function $8(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(Tm(this),n,...t);return m2.set(r,n.sort?n.sort():[n]),Ho(r)}:E8().includes(e)?function(...n){return e.apply(Tm(this),n),Ho(g2.get(this))}:function(...n){return Ho(e.apply(Tm(this),n))}}function M8(e){return typeof e=="function"?$8(e):(e instanceof IDBTransaction&&k8(e),C8(e,I8())?new Proxy(e,rv):e)}function Ho(e){if(e instanceof IDBRequest)return _8(e);if(km.has(e))return km.get(e);const n=M8(e);return n!==e&&(km.set(e,n),Ex.set(n,e)),n}const Tm=e=>Ex.get(e);function A8(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=Ho(i);return r&&i.addEventListener("upgradeneeded",c=>{r(Ho(i.result),c.oldVersion,c.newVersion,Ho(i.transaction),c)}),t&&i.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",l=>o(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}function j8(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),Ho(t).then(()=>{})}const O8=["get","getKey","getAll","getAllKeys","count"],D8=["put","add","delete","clear"],$m=new Map;function CP(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if($m.get(n))return $m.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=D8.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||O8.includes(t)))return;const s=async function(i,...a){const c=this.transaction(i,o?"readwrite":"readonly");let l=c.store;return r&&(l=l.index(a.shift())),(await Promise.all([l[t](...a),o&&c.done]))[0]};return $m.set(n,s),s}T8(e=>({...e,get:(n,t,r)=>CP(n,t)||e.get(n,t,r),has:(n,t)=>!!CP(n,t)||e.has(n,t)}));const Xp="TLDRAW_DOCUMENT_v2",y2="TLDRAW_DB_NAME_INDEX_v2",Fe={Records:"records",Schema:"schema",SessionState:"session_state"};async function qp(e,n){z8(e);const t=await A8(e,3,{upgrade(r){r.objectStoreNames.contains(Fe.Records)||r.createObjectStore(Fe.Records),r.objectStoreNames.contains(Fe.Schema)||r.createObjectStore(Fe.Schema),r.objectStoreNames.contains(Fe.SessionState)||r.createObjectStore(Fe.SessionState)}});try{return await n(t)}finally{t.close()}}async function R8({persistenceKey:e,sessionId:n,didCancel:t}){const r=Xp+e;if(_x().includes(r))return await N8({persistenceKey:e,didCancel:t}),await qp(r,async o=>{var d,f;if(t!=null&&t())return;const s=o.transaction([Fe.Records,Fe.Schema,Fe.SessionState],"readonly"),i=s.objectStore(Fe.Records),a=s.objectStore(Fe.Schema),c=s.objectStore(Fe.SessionState);let l=n?(d=await c.get(n))==null?void 0:d.snapshot:null;l||(l=(f=(await c.getAll()).sort((y,m)=>y.updatedAt-m.updatedAt).pop())==null?void 0:f.snapshot);const u={records:await i.getAll(),schema:await a.get(Fe.Schema),sessionStateSnapshot:l};if(t!=null&&t()){s.abort();return}return await s.done,u})}async function L8({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=Xp+e;await qp(i,async a=>{const c=a.transaction([Fe.Records,Fe.Schema,Fe.SessionState],"readwrite"),l=c.objectStore(Fe.Records),u=c.objectStore(Fe.Schema),d=c.objectStore(Fe.SessionState);for(const[f,p]of Object.entries(t.added))await l.put(p,f);for(const[f,p]of Object.values(t.updated))await l.put(p,p.id);for(const f of Object.keys(t.removed))await l.delete(f);if(u.put(n.serialize(),Fe.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return c.abort();await c.done})}async function F8({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=Xp+e;await qp(i,async a=>{const c=a.transaction([Fe.Records,Fe.Schema,Fe.SessionState],"readwrite"),l=c.objectStore(Fe.Records),u=c.objectStore(Fe.Schema),d=c.objectStore(Fe.SessionState);await l.clear();for(const[f,p]of Object.entries(t))await l.put(p,f);if(u.put(n.serialize(),Fe.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return c.abort();await c.done})}async function N8({persistenceKey:e,didCancel:n}){await qp(Xp+e,async t=>{const r=t.transaction([Fe.SessionState],"readwrite"),o=r.objectStore(Fe.SessionState),s=(await o.getAll()).sort((a,c)=>a.updatedAt-c.updatedAt);if(s.length<10){await r.done;return}const i=s.slice(0,s.length-10);for(const{id:a}of i)await o.delete(a);if(n!=null&&n())return r.abort();await r.done})}function _x(){const e=JSON.parse(a0(y2)||"[]")??[];return Array.isArray(e)?e:[]}function z8(e){const n=new Set(_x());n.add(e),c0(y2,JSON.stringify([...n]))}const B8=350,U8=1e4,IP=Symbol("UPDATE_INSTANCE_STATE"),H8=e=>e;class K8{constructor(n){g(this,"onmessage")}postMessage(n){}close(){}}const W8=typeof BroadcastChannel>"u"?K8:BroadcastChannel;class G8{constructor(n,{persistenceKey:t,sessionId:r=sp,onLoad:o,onLoadError:s},i=new W8(`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=v8(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(H8({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(IP),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 R8({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),P8(),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??w8(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&&x8(this.store,s)}this.channel.onmessage=({data:o})=>{var a,c;this.debug("got message",o);const s=o,i=this.store.schema.getMigrationsSince(s.schema);if(i.ok){if(i.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}}else{if(Date.now()-this.initTime<5e3){t(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(c=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||c.call(a);return}s.type==="diff"&&(this.debug("applying diff"),Ts(()=>{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?U8:B8))}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 F8({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=Cp(n.filter(r=>r!==IP));await L8({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),b8(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function S2({initialData:e,defaultName:n="",id:t,...r}){const o="schema"in r&&r.schema?r.schema:Q3({shapes:EP(a2("shapeUtils"in r&&r.shapeUtils?r.shapeUtils:[])),bindings:EP(o2("bindingUtils"in r&&r.bindingUtils?r.bindingUtils:[])),migrations:"migrations"in r?r.migrations:[]});return new u0({id:t,schema:o,initialData:e,props:{defaultName:n}})}function EP(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function _P(e){const n=S2(e);return e.snapshot&&n.loadSnapshot(e.snapshot),{store:n,opts:e}}function v2(e){const[n,t]=x.useState(()=>_P(e));if(!hE(n.opts,e)){const r=_P(e);return t(r),r.store}return n.store}function V8({persistenceKey:e,sessionId:n,...t}){const[r,o]=x.useState(null),s=v2(t);return x.useEffect(()=>{const i=ot();if(!e){o({id:i,storeWithStatus:{status:"not-synced",store:s}});return}o({id:i,storeWithStatus:{status:"loading"}});const a=l=>{o(u=>(u==null?void 0:u.id)===i?{id:i,storeWithStatus:l}:u)},c=new G8(s,{sessionId:n,persistenceKey:e,onLoad(){a({store:s,status:"synced-local"})},onLoadError(l){a({status:"error",error:l})}});return()=>{o(l=>(l==null?void 0:l.id)===i?null:l),c.close()}},[e,s,n]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}function Y8(){const e=B(),n=dn();x.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=cE(t,100),o=new vc("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach()}},[e,n])}const X8=[],q8=[],Z8=[],Q8=x.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=Se.useState(null),c=x.useMemo(()=>o??ek(),[o]),l=(t==null?void 0:t.ErrorFallback)===void 0?V_:t==null?void 0:t.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??X8,bindingUtils:s.bindingUtils??q8,tools:s.tools??Z8,components:t};return h.jsx("div",{ref:a,draggable:!1,className:ue("tl-container tl-theme__light",r),onPointerDown:Ht,tabIndex:-1,children:h.jsx(Kl,{fallback:l,onError:d=>o0(d,{tags:{origin:"react.tldraw-before-app"}}),children:i&&h.jsx(TL,{container:i,children:h.jsx(Y6,{overrides:t,children:n?n instanceof u0?h.jsx(w2,{...u,store:n,user:c}):h.jsx(x2,{...u,store:n,user:c}):h.jsx(J8,{...u,store:n,user:c})})})})})});function J8(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:c}=e,l=V8({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:n,snapshot:t});return h.jsx(x2,{...e,store:l,user:c})}const x2=x.memo(function({store:n,user:t,...r}){const o=dn();x.useLayoutEffect(()=>{t.userPreferences.get().isDarkMode&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,t]);const{LoadingScreen:s}=ht();switch(n.status){case"error":throw n.error;case"loading":return s?h.jsx(s,{}):null}return h.jsx(w2,{...r,store:n.store,user:t})});function w2({onMount:e,children:n,store:t,tools:r,shapeUtils:o,bindingUtils:s,user:i,initialState:a,autoFocus:c=!0,inferDarkMode:l,cameraOptions:u}){const{ErrorFallback:d}=ht(),f=dn(),[p,y]=x.useState(null),[m]=x.useState(c);x.useLayoutEffect(()=>{const v=new ee({store:t,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>f,user:i,initialState:a,autoFocus:m,inferDarkMode:l,cameraOptions:u});return y(v),()=>{v.dispose()}},[f,o,s,r,t,i,a,m,l,u]);const w=x.useSyncExternalStore(x.useCallback(v=>p?(p.on("crash",v),()=>p.off("crash",v)):()=>{},[p]),()=>(p==null?void 0:p.getCrashingError())??null),{Canvas:S}=ht();return p?h.jsx(Kl,{fallback:d,onError:v=>p.annotateError(v,{origin:"react.tldraw",willCrashApp:!0}),children:w?h.jsx(t7,{crashingError:w}):h.jsx(kp.Provider,{value:p,children:h.jsx(e7,{onMount:e,children:n??(S?h.jsx(S,{}):null)})})}):null}function e7({children:e,onMount:n}){return Y8(),f8(),p8(),g8(),n7(n),h.jsx(h.Fragment,{children:e})}function t7({crashingError:e}){throw e}function b2({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function P2({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function n7(e){const n=B(),t=Ix(r=>{let o;return r.history.ignore(()=>{o=e==null?void 0:e(r),r.emit("mount")}),window.tldrawReady=!0,o});Se.useLayoutEffect(()=>{if(n)return t==null?void 0:t(n)},[n,t])}function Li({children:e,className:n="",...t}){return h.jsx("div",{...t,className:ue("tl-html-container",n),children:e})}function C2(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:u=1/0}=t;let d=e.props.w*s,f=e.props.h*i;const p=new b(0,0);if(d>0){if(d<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=d-a;break}case"top":case"bottom":{p.x=(d-a)/2;break}default:p.x=0}d=a}}else if(p.x=d,d=-d,d<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=-d;break}default:p.x=-a}d=a}if(f>0){if(f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=f-l;break}case"right":case"left":{p.y=(f-l)/2;break}default:p.y=0}f=l}}else if(p.y=f,f=-f,f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-l}f=l}const{x:y,y:m}=p.rot(e.rotation).add(r);return{x:y,y:m,props:{w:Math.min(c,d),h:Math.min(u,f)}}}class _c extends Br{constructor(){super(...arguments);g(this,"onResize",(t,r)=>C2(t,r))}getGeometry(t){return new Qo({width:t.props.w,height:t.props.h,isFilled:!0})}getHandleSnapGeometry(t){return{points:this.getGeometry(t).bounds.cornersAndCenter}}}var Ey;let r7=(Ey=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(Ey,"id","idle"),Ey);var _y;let o7=(_y=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=Be();this.markId=`creating:${s}`,this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(s),this.editor.setCurrentTool("select.resizing",{...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=Be();this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:r,x:t.x,y:t.y}]);const s=this.editor.getShape(o),{w:i,h:a}=this.editor.getShapeUtil(s).getDefaultProps(),c=new b(i/2,a/2),l=this.editor.getShapeParentTransform(s);l&&c.rot(-l.rotation()),this.editor.updateShapes([{id:o,type:r,x:s.x-c.x,y:s.y-c.y}]),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},g(_y,"id","pointing"),_y);class kh extends se{constructor(){super(...arguments);g(this,"onCreate")}}g(kh,"id","box"),g(kh,"initial","idle"),g(kh,"children",()=>[r7,o7]);function Zp(e){const n=B();return W("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function s7(){return x.useId().replace(/:/g,"_")}function Jr(e){const n=B();return x.useMemo(function(){const o=l=>{if(l.isKilled)return;if(l.button===x0){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...Tn(l)});return}if(l.button!==0)return;const u=Mf(l.currentTarget);function d(){u.removeEventListener("pointerup",d),$u(u,l)}Tu(u,l),u.addEventListener("pointerup",d),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...Tn(l)}),Ht(l)};let s,i;function a(l){l.isKilled||l.button===0&&(l.clientX===s&&l.clientY===i||(s=l.clientX,i=l.clientY,n.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...Tn(l)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:l=>{l.isKilled||l.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...Tn(l)})}}},[n,e])}const i7=20,a7=8;function kx(e,n=i7){return Math.max(a7,Math.ceil(e/n))}class Oa extends qs{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=b.Angle(r,i),this.angleEnd=b.Angle(r,a),this.radius=b.Dist(r,i),this.measure=lL(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:c,end:l}=this,u=oS(o,a,i,r.angle(t));if(u<=0)return c;if(u>=1)return l;const d=r.clone().add(t.clone().sub(r).uni().mul(s));let f,p=1/0,y;for(const m of[c,l,d])y=b.Dist2(t,m),y<p&&(f=m,p=y);if(!f)throw Error("nearest point not found");return f}hitTestLineSegment(t,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:c}=this,l=Lu(t,r,o,s);return l===null?!1:l.some(u=>{const d=oS(i,a,c,o.angle(u));return d>=0&&d<=1})}getVertices(){const{_center:t,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let c=0,l=kx(Math.abs(o));c<l+1;c++){const u=c/l*r,d=i+u;a.push($i(t,s,d))}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 Tx extends qs{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 b(s+r,s+o),this.radius=s}getBounds(){return new J(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=kx(o);i<a;i++){const c=i/a*Re;s.push($i(t,r,c))}return s}nearestPoint(t){const{_center:r,radius:o}=this;return r.equals(t)?b.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 Lu(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 Jt extends Ec{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,c=10;a<=c;a++){const l=a/c;t.push(new b((1-l)*(1-l)*(1-l)*r.x+3*((1-l)*(1-l))*l*o.x+3*(1-l)*(l*l)*s.x+l*l*l*i.x,(1-l)*(1-l)*(1-l)*r.y+3*((1-l)*(1-l))*l*o.y+3*(1-l)*(l*l)*s.y+l*l*l*i.y))}return t}midPoint(){return Jt.GetAtT(this,.5)}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(t),s=b.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 b((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=Jt.GetAtT(this,i/t),s+=b.Dist(o,r),o=r;return s}}class c7 extends qs{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],c=t[i],l=t[i+1],u=i===o?l:t[i+2],d=c,f=i===0?a:new b(c.x+(l.x-a.x)/6*s,c.y+(l.y-a.y)/6*s),p=i===o?l:new b(l.x-(u.x-c.x)/6*s,l.y-(u.y-c.y)/6*s),y=l;this._segments.push(new Jt({start:d,cp1:f,cp2:p,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=b.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 l7 extends qs{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 zo({start:s,end:i}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),o=t/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=ke*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),c=kx(a),l=Re/c,u=Math.cos(l),d=Math.sin(l);let f=0,p=1,y=0,m=1;const w=Array(c);for(let S=0;S<c;S++)w[S]=new b(o+o*p,s+s*f),y=d*p+u*f,m=u*p-d*f,f=y,p=m;return w}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(t),s=b.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 J(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 f_(i,a)}getSvgPathData(t=!1){const{w:r,h:o}=this,s=r/2,i=o/2,a=Math.max(0,s),c=Math.max(0,i);return`${t?`M${s-a},${i}`:""} a${a},${c},0,1,1,${a*2},0a${a},${c},0,1,1,-${a*2},0`}}class u7 extends qs{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 Oa({start:new b(0,s),end:new b(r,s),center:new b(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new zo({start:new b(r,s),end:new b(r,o-s)}),this.c=new Oa({start:new b(r,o-s),end:new b(0,o-s),center:new b(r/2,o-s),sweepFlag:1,largeArcFlag:1}),this.d=new zo({start:new b(0,o-s),end:new b(0,s)})}else{const s=o/2;this.a=new Oa({start:new b(s,o),end:new b(s,0),center:new b(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new zo({start:new b(s,0),end:new b(r-s,0)}),this.c=new Oa({start:new b(r-s,0),end:new b(r-s,o),center:new b(r-s,s),sweepFlag:1,largeArcFlag:1}),this.d=new zo({start:new b(r-s,o),end:new b(s,o)})}}nearestPoint(t){let r,o=1/0,s,i;const{a,b:c,c:l,d:u}=this;for(const d of[a,c,l,u])i=d.nearestPoint(t),s=b.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(c=>c.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 J(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"}}function kP(e,n,t,r,o){const s=SL,i=t?vL:0,a=e-i,c=e+i,l=r?0:s,u=o?n:n-s;return a<l?Math.min(1,(l-a)/s):c>u?-Math.min(1,(c-u)/s):0}function $x(e){if(!e.inputs.isDragging||e.inputs.isPanning||e.getCameraOptions().isLocked)return;const{inputs:{currentScreenPoint:{x:n,y:t}}}=e,r=e.getZoomLevel(),o=e.getViewportScreenBounds(),s=o.w<1e3?.612:1,i=o.h<1e3?.612:1,{isCoarsePointer:a,insets:[c,l,u,d]}=e.getInstanceState(),f=kP(n,o.w,a,d,l),p=kP(t,o.h,a,c,u);if(f===0&&p===0)return;const y=e.user.getEdgeScrollSpeed()*yL,m=y*f*s/r,w=y*p*i/r,S=e.getCamera();e.setCamera(new b(S.x+m,S.y+w,S.z))}async function d7({shouldReload:e=!0}={}){IR(),await Promise.all(_x().map(n=>j8(n))),CR(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=d7);function h7(e,n="_blank"){k0.openWindow(e,n)}var tl=function(e){return e&&e.Math===Math&&e},Nn=tl(typeof globalThis=="object"&&globalThis)||tl(typeof window=="object"&&window)||tl(typeof self=="object"&&self)||tl(typeof rn=="object"&&rn)||tl(typeof rn=="object"&&rn)||function(){return this}()||Function("return this")(),Mx={},vn=function(e){try{return!!e()}catch{return!0}},f7=vn,ei=!f7(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),p7=vn,Qp=!p7(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),g7=Qp,Od=Function.prototype.call,rs=g7?Od.bind(Od):function(){return Od.apply(Od,arguments)},I2={},E2={}.propertyIsEnumerable,_2=Object.getOwnPropertyDescriptor,m7=_2&&!E2.call({1:2},1);I2.f=m7?function(n){var t=_2(this,n);return!!t&&t.enumerable}:E2;var k2=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},T2=Qp,$2=Function.prototype,ov=$2.call,y7=T2&&$2.bind.bind(ov,ov),Ot=T2?y7:function(e){return function(){return ov.apply(e,arguments)}},M2=Ot,S7=M2({}.toString),v7=M2("".slice),kc=function(e){return v7(S7(e),8,-1)},x7=Ot,w7=vn,b7=kc,Mm=Object,P7=x7("".split),C7=w7(function(){return!Mm("z").propertyIsEnumerable(0)})?function(e){return b7(e)==="String"?P7(e,""):Mm(e)}:Mm,Jp=function(e){return e==null},I7=Jp,E7=TypeError,Tc=function(e){if(I7(e))throw new E7("Can't call method on "+e);return e},_7=C7,k7=Tc,eg=function(e){return _7(k7(e))},Am=typeof document=="object"&&document.all,xn=typeof Am>"u"&&Am!==void 0?function(e){return typeof e=="function"||e===Am}:function(e){return typeof e=="function"},T7=xn,Xi=function(e){return typeof e=="object"?e!==null:T7(e)},jm=Nn,$7=xn,M7=function(e){return $7(e)?e:void 0},tg=function(e,n){return arguments.length<2?M7(jm[e]):jm[e]&&jm[e][n]},A7=Ot,A2=A7({}.isPrototypeOf),j7=typeof navigator<"u"&&String(navigator.userAgent)||"",j2=Nn,Om=j7,TP=j2.process,$P=j2.Deno,MP=TP&&TP.versions||$P&&$P.version,AP=MP&&MP.v8,Lr,ip;AP&&(Lr=AP.split("."),ip=Lr[0]>0&&Lr[0]<4?1:+(Lr[0]+Lr[1]));!ip&&Om&&(Lr=Om.match(/Edge\/(\d+)/),(!Lr||Lr[1]>=74)&&(Lr=Om.match(/Chrome\/(\d+)/),Lr&&(ip=+Lr[1])));var O7=ip,jP=O7,D7=vn,R7=Nn,L7=R7.String,O2=!!Object.getOwnPropertySymbols&&!D7(function(){var e=Symbol("symbol detection");return!L7(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&jP&&jP<41}),F7=O2,D2=F7&&!Symbol.sham&&typeof Symbol.iterator=="symbol",N7=tg,z7=xn,B7=A2,U7=D2,H7=Object,R2=U7?function(e){return typeof e=="symbol"}:function(e){var n=N7("Symbol");return z7(n)&&B7(n.prototype,H7(e))},K7=String,W7=function(e){try{return K7(e)}catch{return"Object"}},G7=xn,V7=W7,Y7=TypeError,Ax=function(e){if(G7(e))return e;throw new Y7(V7(e)+" is not a function")},X7=Ax,q7=Jp,jx=function(e,n){var t=e[n];return q7(t)?void 0:X7(t)},Dm=rs,Rm=xn,Lm=Xi,Z7=TypeError,Q7=function(e,n){var t,r;if(n==="string"&&Rm(t=e.toString)&&!Lm(r=Dm(t,e))||Rm(t=e.valueOf)&&!Lm(r=Dm(t,e))||n!=="string"&&Rm(t=e.toString)&&!Lm(r=Dm(t,e)))return r;throw new Z7("Can't convert object to primitive value")},L2={exports:{}},OP=Nn,J7=Object.defineProperty,Ox=function(e,n){try{J7(OP,e,{value:n,configurable:!0,writable:!0})}catch{OP[e]=n}return n},eB=Nn,tB=Ox,DP="__core-js_shared__",RP=L2.exports=eB[DP]||tB(DP,{});(RP.versions||(RP.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 Dx=L2.exports,LP=Dx,Rx=function(e,n){return LP[e]||(LP[e]=n||{})},nB=Tc,rB=Object,zu=function(e){return rB(nB(e))},oB=Ot,sB=zu,iB=oB({}.hasOwnProperty),ti=Object.hasOwn||function(n,t){return iB(sB(n),t)},aB=Ot,cB=0,lB=Math.random(),uB=aB(1 .toString),F2=function(e){return"Symbol("+(e===void 0?"":e)+")_"+uB(++cB+lB,36)},dB=Nn,hB=Rx,FP=ti,fB=F2,pB=O2,gB=D2,Da=dB.Symbol,Fm=hB("wks"),mB=gB?Da.for||Da:Da&&Da.withoutSetter||fB,os=function(e){return FP(Fm,e)||(Fm[e]=pB&&FP(Da,e)?Da[e]:mB("Symbol."+e)),Fm[e]},yB=rs,NP=Xi,zP=R2,SB=jx,vB=Q7,xB=os,wB=TypeError,bB=xB("toPrimitive"),PB=function(e,n){if(!NP(e)||zP(e))return e;var t=SB(e,bB),r;if(t){if(n===void 0&&(n="default"),r=yB(t,e,n),!NP(r)||zP(r))return r;throw new wB("Can't convert object to primitive value")}return n===void 0&&(n="number"),vB(e,n)},CB=PB,IB=R2,N2=function(e){var n=CB(e,"string");return IB(n)?n:n+""},EB=Nn,BP=Xi,sv=EB.document,_B=BP(sv)&&BP(sv.createElement),z2=function(e){return _B?sv.createElement(e):{}},kB=ei,TB=vn,$B=z2,B2=!kB&&!TB(function(){return Object.defineProperty($B("div"),"a",{get:function(){return 7}}).a!==7}),MB=ei,AB=rs,jB=I2,OB=k2,DB=eg,RB=N2,LB=ti,FB=B2,UP=Object.getOwnPropertyDescriptor;Mx.f=MB?UP:function(n,t){if(n=DB(n),t=RB(t),FB)try{return UP(n,t)}catch{}if(LB(n,t))return OB(!AB(jB.f,n,t),n[t])};var $c={},NB=ei,zB=vn,U2=NB&&zB(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),BB=Xi,UB=String,HB=TypeError,qi=function(e){if(BB(e))return e;throw new HB(UB(e)+" is not an object")},KB=ei,WB=B2,GB=U2,Dd=qi,HP=N2,VB=TypeError,Nm=Object.defineProperty,YB=Object.getOwnPropertyDescriptor,zm="enumerable",Bm="configurable",Um="writable";$c.f=KB?GB?function(n,t,r){if(Dd(n),t=HP(t),Dd(r),typeof n=="function"&&t==="prototype"&&"value"in r&&Um in r&&!r[Um]){var o=YB(n,t);o&&o[Um]&&(n[t]=r.value,r={configurable:Bm in r?r[Bm]:o[Bm],enumerable:zm in r?r[zm]:o[zm],writable:!1})}return Nm(n,t,r)}:Nm:function(n,t,r){if(Dd(n),t=HP(t),Dd(r),WB)try{return Nm(n,t,r)}catch{}if("get"in r||"set"in r)throw new VB("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var XB=ei,qB=$c,ZB=k2,Lx=XB?function(e,n,t){return qB.f(e,n,ZB(1,t))}:function(e,n,t){return e[n]=t,e},H2={exports:{}},iv=ei,QB=ti,K2=Function.prototype,JB=iv&&Object.getOwnPropertyDescriptor,Fx=QB(K2,"name"),eU=Fx&&(function(){}).name==="something",tU=Fx&&(!iv||iv&&JB(K2,"name").configurable),nU={EXISTS:Fx,PROPER:eU,CONFIGURABLE:tU},rU=Ot,oU=xn,av=Dx,sU=rU(Function.toString);oU(av.inspectSource)||(av.inspectSource=function(e){return sU(e)});var W2=av.inspectSource,iU=Nn,aU=xn,KP=iU.WeakMap,cU=aU(KP)&&/native code/.test(String(KP)),lU=Rx,uU=F2,WP=lU("keys"),G2=function(e){return WP[e]||(WP[e]=uU(e))},Nx={},dU=cU,V2=Nn,hU=Xi,fU=Lx,Hm=ti,Km=Dx,pU=G2,gU=Nx,GP="Object already initialized",cv=V2.TypeError,mU=V2.WeakMap,ap,uu,cp,yU=function(e){return cp(e)?uu(e):ap(e,{})},SU=function(e){return function(n){var t;if(!hU(n)||(t=uu(n)).type!==e)throw new cv("Incompatible receiver, "+e+" required");return t}};if(dU||Km.state){var Zr=Km.state||(Km.state=new mU);Zr.get=Zr.get,Zr.has=Zr.has,Zr.set=Zr.set,ap=function(e,n){if(Zr.has(e))throw new cv(GP);return n.facade=e,Zr.set(e,n),n},uu=function(e){return Zr.get(e)||{}},cp=function(e){return Zr.has(e)}}else{var ca=pU("state");gU[ca]=!0,ap=function(e,n){if(Hm(e,ca))throw new cv(GP);return n.facade=e,fU(e,ca,n),n},uu=function(e){return Hm(e,ca)?e[ca]:{}},cp=function(e){return Hm(e,ca)}}var Y2={set:ap,get:uu,has:cp,enforce:yU,getterFor:SU},zx=Ot,vU=vn,xU=xn,Rd=ti,lv=ei,wU=nU.CONFIGURABLE,bU=W2,X2=Y2,PU=X2.enforce,CU=X2.get,VP=String,Th=Object.defineProperty,IU=zx("".slice),EU=zx("".replace),_U=zx([].join),kU=lv&&!vU(function(){return Th(function(){},"length",{value:8}).length!==8}),TU=String(String).split("String"),$U=H2.exports=function(e,n,t){IU(VP(n),0,7)==="Symbol("&&(n="["+EU(VP(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!Rd(e,"name")||wU&&e.name!==n)&&(lv?Th(e,"name",{value:n,configurable:!0}):e.name=n),kU&&t&&Rd(t,"arity")&&e.length!==t.arity&&Th(e,"length",{value:t.arity});try{t&&Rd(t,"constructor")&&t.constructor?lv&&Th(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=PU(e);return Rd(r,"source")||(r.source=_U(TU,typeof n=="string"?n:"")),e};Function.prototype.toString=$U(function(){return xU(this)&&CU(this).source||bU(this)},"toString");var MU=H2.exports,AU=xn,jU=$c,OU=MU,DU=Ox,q2=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(AU(t)&&OU(t,s,r),r.global)o?e[n]=t:DU(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:jU.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},Z2={},RU=Math.ceil,LU=Math.floor,FU=Math.trunc||function(n){var t=+n;return(t>0?LU:RU)(t)},NU=FU,Zi=function(e){var n=+e;return n!==n||n===0?0:NU(n)},zU=Zi,BU=Math.max,UU=Math.min,HU=function(e,n){var t=zU(e);return t<0?BU(t+n,0):UU(t,n)},KU=Zi,WU=Math.min,Q2=function(e){var n=KU(e);return n>0?WU(n,9007199254740991):0},GU=Q2,Bu=function(e){return GU(e.length)},VU=eg,YU=HU,XU=Bu,YP=function(e){return function(n,t,r){var o=VU(n),s=XU(o);if(s===0)return!e&&-1;var i=YU(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}},qU={includes:YP(!0),indexOf:YP(!1)},ZU=Ot,Wm=ti,QU=eg,JU=qU.indexOf,e9=Nx,XP=ZU([].push),J2=function(e,n){var t=QU(e),r=0,o=[],s;for(s in t)!Wm(e9,s)&&Wm(t,s)&&XP(o,s);for(;n.length>r;)Wm(t,s=n[r++])&&(~JU(o,s)||XP(o,s));return o},Bx=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],t9=J2,n9=Bx,r9=n9.concat("length","prototype");Z2.f=Object.getOwnPropertyNames||function(n){return t9(n,r9)};var e$={};e$.f=Object.getOwnPropertySymbols;var o9=tg,s9=Ot,i9=Z2,a9=e$,c9=qi,l9=s9([].concat),u9=o9("Reflect","ownKeys")||function(n){var t=i9.f(c9(n)),r=a9.f;return r?l9(t,r(n)):t},qP=ti,d9=u9,h9=Mx,f9=$c,p9=function(e,n,t){for(var r=d9(n),o=f9.f,s=h9.f,i=0;i<r.length;i++){var a=r[i];!qP(e,a)&&!(t&&qP(t,a))&&o(e,a,s(n,a))}},g9=vn,m9=xn,y9=/#|\.prototype\./,Uu=function(e,n){var t=v9[S9(e)];return t===w9?!0:t===x9?!1:m9(n)?g9(n):!!n},S9=Uu.normalize=function(e){return String(e).replace(y9,".").toLowerCase()},v9=Uu.data={},x9=Uu.NATIVE="N",w9=Uu.POLYFILL="P",b9=Uu,Ld=Nn,P9=Mx.f,C9=Lx,I9=q2,E9=Ox,_9=p9,k9=b9,Mc=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,c,l,u;if(r?i=Ld:o?i=Ld[t]||E9(t,{}):i=Ld[t]&&Ld[t].prototype,i)for(a in n){if(l=n[a],e.dontCallGetSet?(u=P9(i,a),c=u&&u.value):c=i[a],s=k9(r?a:t+(o?".":"#")+a,e.forced),!s&&c!==void 0){if(typeof l==typeof c)continue;_9(l,c)}(e.sham||c&&c.sham)&&C9(l,"sham",!0),I9(i,a,l,e)}},t$={},T9=J2,$9=Bx,M9=Object.keys||function(n){return T9(n,$9)},A9=ei,j9=U2,O9=$c,D9=qi,R9=eg,L9=M9;t$.f=A9&&!j9?Object.defineProperties:function(n,t){D9(n);for(var r=R9(t),o=L9(t),s=o.length,i=0,a;s>i;)O9.f(n,a=o[i++],r[a]);return n};var F9=tg,N9=F9("document","documentElement"),z9=qi,B9=t$,ZP=Bx,U9=Nx,H9=N9,K9=z2,W9=G2,QP=">",JP="<",uv="prototype",dv="script",n$=W9("IE_PROTO"),Gm=function(){},r$=function(e){return JP+dv+QP+e+JP+"/"+dv+QP},eC=function(e){e.write(r$("")),e.close();var n=e.parentWindow.Object;return e=null,n},G9=function(){var e=K9("iframe"),n="java"+dv+":",t;return e.style.display="none",H9.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(r$("document.F=Object")),t.close(),t.F},Fd,$h=function(){try{Fd=new ActiveXObject("htmlfile")}catch{}$h=typeof document<"u"?document.domain&&Fd?eC(Fd):G9():eC(Fd);for(var e=ZP.length;e--;)delete $h[uv][ZP[e]];return $h()};U9[n$]=!0;var o$=Object.create||function(n,t){var r;return n!==null?(Gm[uv]=z9(n),r=new Gm,Gm[uv]=null,r[n$]=n):r=$h(),t===void 0?r:B9.f(r,t)},V9=os,Y9=o$,X9=$c.f,hv=V9("unscopables"),fv=Array.prototype;fv[hv]===void 0&&X9(fv,hv,{configurable:!0,value:Y9(null)});var Ux=function(e){fv[hv][e]=!0},q9=Mc,Z9=zu,Q9=Bu,J9=Zi,eH=Ux;q9({target:"Array",proto:!0},{at:function(n){var t=Z9(this),r=Q9(t),o=J9(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});eH("at");var tH=Nn,nH=Ot,Hu=function(e,n){return nH(tH[e].prototype[n])},rH=Hu;rH("Array","at");var oH=kc,s$=Array.isArray||function(n){return oH(n)==="Array"},sH=TypeError,iH=9007199254740991,aH=function(e){if(e>iH)throw sH("Maximum allowed index exceeded");return e},cH=kc,lH=Ot,uH=function(e){if(cH(e)==="Function")return lH(e)},tC=uH,dH=Ax,hH=Qp,fH=tC(tC.bind),pH=function(e,n){return dH(e),n===void 0?e:hH?fH(e,n):function(){return e.apply(n,arguments)}},gH=s$,mH=Bu,yH=aH,SH=pH,i$=function(e,n,t,r,o,s,i,a){for(var c=o,l=0,u=i?SH(i,a):!1,d,f;l<r;)l in t&&(d=u?u(t[l],l,n):t[l],s>0&&gH(d)?(f=mH(d),c=i$(e,n,d,f,c,s-1)-1):(yH(c+1),e[c]=d),c++),l++;return c},a$=i$,vH=os,xH=vH("toStringTag"),c$={};c$[xH]="z";var wH=String(c$)==="[object z]",bH=wH,PH=xn,Mh=kc,CH=os,IH=CH("toStringTag"),EH=Object,_H=Mh(function(){return arguments}())==="Arguments",kH=function(e,n){try{return e[n]}catch{}},l$=bH?Mh:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=kH(n=EH(e),IH))=="string"?t:_H?Mh(n):(r=Mh(n))==="Object"&&PH(n.callee)?"Arguments":r},TH=Ot,$H=vn,u$=xn,MH=l$,AH=tg,jH=W2,d$=function(){},h$=AH("Reflect","construct"),Hx=/^\s*(?:class|function)\b/,OH=TH(Hx.exec),DH=!Hx.test(d$),nl=function(n){if(!u$(n))return!1;try{return h$(d$,[],n),!0}catch{return!1}},f$=function(n){if(!u$(n))return!1;switch(MH(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return DH||!!OH(Hx,jH(n))}catch{return!0}};f$.sham=!0;var RH=!h$||$H(function(){var e;return nl(nl.call)||!nl(Object)||!nl(function(){e=!0})||e})?f$:nl,nC=s$,LH=RH,FH=Xi,NH=os,zH=NH("species"),rC=Array,BH=function(e){var n;return nC(e)&&(n=e.constructor,LH(n)&&(n===rC||nC(n.prototype))?n=void 0:FH(n)&&(n=n[zH],n===null&&(n=void 0))),n===void 0?rC:n},UH=BH,p$=function(e,n){return new(UH(e))(n===0?0:n)},HH=Mc,KH=a$,WH=Ax,GH=zu,VH=Bu,YH=p$;HH({target:"Array",proto:!0},{flatMap:function(n){var t=GH(this),r=VH(t),o;return WH(n),o=YH(t,0),o.length=KH(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var XH=Ux;XH("flatMap");var qH=Hu;qH("Array","flatMap");var ZH=Mc,QH=a$,JH=zu,eK=Bu,tK=Zi,nK=p$;ZH({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=JH(this),r=eK(t),o=nK(t,0);return o.length=QH(o,t,t,r,0,n===void 0?1:tK(n)),o}});var rK=Ux;rK("flat");var oK=Hu;oK("Array","flat");var sK=l$,iK=String,Ku=function(e){if(sK(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return iK(e)},aK=Mc,cK=Ot,lK=Tc,uK=Zi,dK=Ku,hK=vn,fK=cK("".charAt),pK=hK(function(){return"𠮷".at(-2)!=="\uD842"});aK({target:"String",proto:!0,forced:pK},{at:function(n){var t=dK(lK(this)),r=t.length,o=uK(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:fK(t,s)}});var gK=Hu;gK("String","at");var mK=qi,g$=function(){var e=mK(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},Kx=vn,yK=Nn,Wx=yK.RegExp,Gx=Kx(function(){var e=Wx("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),SK=Gx||Kx(function(){return!Wx("a","y").sticky}),vK=Gx||Kx(function(){var e=Wx("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),xK={BROKEN_CARET:vK,MISSED_STICKY:SK,UNSUPPORTED_Y:Gx},wK=vn,bK=Nn,PK=bK.RegExp,CK=wK(function(){var e=PK(".","s");return!(e.dotAll&&e.test(`
105
- `)&&e.flags==="s")}),IK=vn,EK=Nn,_K=EK.RegExp,kK=IK(function(){var e=_K("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),Ra=rs,ng=Ot,TK=Ku,$K=g$,MK=xK,AK=Rx,jK=o$,OK=Y2.get,DK=CK,RK=kK,LK=AK("native-string-replace",String.prototype.replace),lp=RegExp.prototype.exec,pv=lp,FK=ng("".charAt),NK=ng("".indexOf),zK=ng("".replace),Vm=ng("".slice),gv=function(){var e=/a/,n=/b*/g;return Ra(lp,e,"a"),Ra(lp,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),m$=MK.BROKEN_CARET,mv=/()??/.exec("")[1]!==void 0,BK=gv||mv||m$||DK||RK;BK&&(pv=function(n){var t=this,r=OK(t),o=TK(n),s=r.raw,i,a,c,l,u,d,f;if(s)return s.lastIndex=t.lastIndex,i=Ra(pv,s,o),t.lastIndex=s.lastIndex,i;var p=r.groups,y=m$&&t.sticky,m=Ra($K,t),w=t.source,S=0,v=o;if(y&&(m=zK(m,"y",""),NK(m,"g")===-1&&(m+="g"),v=Vm(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&FK(o,t.lastIndex-1)!==`
106
- `)&&(w="(?: "+w+")",v=" "+v,S++),a=new RegExp("^(?:"+w+")",m)),mv&&(a=new RegExp("^"+w+"$(?!\\s)",m)),gv&&(c=t.lastIndex),l=Ra(lp,y?a:t,v),y?l?(l.input=Vm(l.input,S),l[0]=Vm(l[0],S),l.index=t.lastIndex,t.lastIndex+=l[0].length):t.lastIndex=0:gv&&l&&(t.lastIndex=t.global?l.index+l[0].length:c),mv&&l&&l.length>1&&Ra(LK,l[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(l[u]=void 0)}),l&&p)for(l.groups=d=jK(null),u=0;u<p.length;u++)f=p[u],d[f[0]]=l[f[1]];return l});var Vx=pv,UK=Mc,oC=Vx;UK({target:"RegExp",proto:!0,forced:/./.exec!==oC},{exec:oC});var HK=Qp,y$=Function.prototype,sC=y$.apply,iC=y$.call,KK=typeof Reflect=="object"&&Reflect.apply||(HK?iC.bind(sC):function(){return iC.apply(sC,arguments)}),aC=rs,cC=q2,WK=Vx,lC=vn,S$=os,GK=Lx,VK=S$("species"),Ym=RegExp.prototype,YK=function(e,n,t,r){var o=S$(e),s=!lC(function(){var l={};return l[o]=function(){return 7},""[e](l)!==7}),i=s&&!lC(function(){var l=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[VK]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return l=!0,null},u[o](""),!l});if(!s||!i||t){var a=/./[o],c=n(o,""[e],function(l,u,d,f,p){var y=u.exec;return y===WK||y===Ym.exec?s&&!p?{done:!0,value:aC(a,u,d,f)}:{done:!0,value:aC(l,d,u,f)}:{done:!1}});cC(String.prototype,e,c[0]),cC(Ym,o,c[1])}r&&GK(Ym[o],"sham",!0)},Yx=Ot,XK=Zi,qK=Ku,ZK=Tc,QK=Yx("".charAt),uC=Yx("".charCodeAt),JK=Yx("".slice),dC=function(e){return function(n,t){var r=qK(ZK(n)),o=XK(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=uC(r,o),i<55296||i>56319||o+1===s||(a=uC(r,o+1))<56320||a>57343?e?QK(r,o):i:e?JK(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},eW={codeAt:dC(!1),charAt:dC(!0)},tW=eW.charAt,nW=function(e,n,t){return n+(t?tW(e,n).length:1)},Xx=Ot,rW=zu,oW=Math.floor,Xm=Xx("".charAt),sW=Xx("".replace),qm=Xx("".slice),iW=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,aW=/\$([$&'`]|\d{1,2})/g,v$=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,c=aW;return o!==void 0&&(o=rW(o),c=iW),sW(s,c,function(l,u){var d;switch(Xm(u,0)){case"$":return"$";case"&":return e;case"`":return qm(n,0,t);case"'":return qm(n,i);case"<":d=o[qm(u,1,-1)];break;default:var f=+u;if(f===0)return l;if(f>a){var p=oW(f/10);return p===0?l:p<=a?r[p-1]===void 0?Xm(u,1):r[p-1]+Xm(u,1):l}d=r[f-1]}return d===void 0?"":d})},hC=rs,cW=qi,lW=xn,uW=kc,dW=Vx,hW=TypeError,fW=function(e,n){var t=e.exec;if(lW(t)){var r=hC(t,e,n);return r!==null&&cW(r),r}if(uW(e)==="RegExp")return hC(dW,e,n);throw new hW("RegExp#exec called on incompatible receiver")},pW=KK,fC=rs,rg=Ot,gW=YK,mW=vn,yW=qi,SW=xn,vW=Jp,xW=Zi,wW=Q2,la=Ku,bW=Tc,PW=nW,CW=jx,IW=v$,EW=fW,_W=os,yv=_W("replace"),kW=Math.max,TW=Math.min,$W=rg([].concat),Zm=rg([].push),pC=rg("".indexOf),gC=rg("".slice),MW=function(e){return e===void 0?e:String(e)},AW=function(){return"a".replace(/./,"$0")==="$0"}(),mC=function(){return/./[yv]?/./[yv]("a","$0")==="":!1}(),jW=!mW(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});gW("replace",function(e,n,t){var r=mC?"$":"$0";return[function(s,i){var a=bW(this),c=vW(s)?void 0:CW(s,yv);return c?fC(c,s,a,i):fC(n,la(a),s,i)},function(o,s){var i=yW(this),a=la(o);if(typeof s=="string"&&pC(s,r)===-1&&pC(s,"$<")===-1){var c=t(n,i,a,s);if(c.done)return c.value}var l=SW(s);l||(s=la(s));var u=i.global,d;u&&(d=i.unicode,i.lastIndex=0);for(var f=[],p;p=EW(i,a),!(p===null||(Zm(f,p),!u));){var y=la(p[0]);y===""&&(i.lastIndex=PW(a,wW(i.lastIndex),d))}for(var m="",w=0,S=0;S<f.length;S++){p=f[S];for(var v=la(p[0]),P=kW(TW(xW(p.index),a.length),0),E=[],C,I=1;I<p.length;I++)Zm(E,MW(p[I]));var _=p.groups;if(l){var k=$W([v],E,P,a);_!==void 0&&Zm(k,_),C=la(pW(s,void 0,k))}else C=IW(v,a,P,E,_,s);P>=w&&(m+=gC(a,w,P)+C,w=P+v.length)}return m+gC(a,w)}]},!jW||!AW||mC);var OW=Xi,DW=kc,RW=os,LW=RW("match"),FW=function(e){var n;return OW(e)&&((n=e[LW])!==void 0?!!n:DW(e)==="RegExp")},NW=rs,zW=ti,BW=A2,UW=g$,yC=RegExp.prototype,HW=function(e){var n=e.flags;return n===void 0&&!("flags"in yC)&&!zW(e,"flags")&&BW(yC,e)?NW(UW,e):n},KW=Mc,WW=rs,qx=Ot,SC=Tc,GW=xn,VW=Jp,YW=FW,rl=Ku,XW=jx,qW=HW,ZW=v$,QW=os,JW=QW("replace"),eG=TypeError,Qm=qx("".indexOf);qx("".replace);var vC=qx("".slice),tG=Math.max;KW({target:"String",proto:!0},{replaceAll:function(n,t){var r=SC(this),o,s,i,a,c,l,u,d,f,p=0,y=0,m="";if(!VW(n)){if(o=YW(n),o&&(s=rl(SC(qW(n))),!~Qm(s,"g")))throw new eG("`.replaceAll` does not allow non-global regexes");if(i=XW(n,JW),i)return WW(i,n,r,t)}for(a=rl(r),c=rl(n),l=GW(t),l||(t=rl(t)),u=c.length,d=tG(1,u),p=Qm(a,c);p!==-1;)f=l?rl(t(c,p,a)):ZW(c,a,p,[],void 0,t),m+=vC(a,y,p)+f,y=p+u,p=p+d>a.length?-1:Qm(a,c,p+d);return y<a.length&&(m+=vC(a,y)),m}});var nG=Hu;nG("String","replaceAll");function Sv(e,n,t){const{arrowheadStart:r,arrowheadEnd:o}=n.props,s=La(e,n,t),i=s.start.clone(),a=s.end.clone(),c=b.Med(i,a);if(b.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:c,isValid:!1,length:0};const l=b.Sub(a,i).uni(),u=up(e,n,"start"),d=up(e,n,"end"),f=e.getShapePageTransform(n);xC(a,s.start,f,d),xC(i,s.end,f,u);let p=0,y=0,m=0,w=0,S=Fa;const v=u&&d&&u.shape===d.shape,P=u&&d?Zx(e,u.shape.id,d.shape.id):"safe";P==="safe"&&u&&d&&!v&&!u.isExact&&!d.isExact&&(d.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(l.clone().mul(Fa))):d.didIntersect||d.isClosed&&a.setTo(i.clone().sub(l.clone().mul(Fa))));const E=b.Sub(a,i),C=b.Len(E)?E.uni():b.From(E),I=!b.Equals(C,l);v||(P!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=_s[n.props.size]/2+("size"in u.shape.props?_s[u.shape.props.size]/2:0),p=dp+m,S+=m),P!=="end-contains-start"&&d&&o!=="none"&&!d.isExact&&(w=_s[n.props.size]/2+("size"in d.shape.props?_s[d.shape.props.size]/2:0),y=dp+w,S+=w));const _=i.clone().add(C.clone().mul(p*(I?-1:1))),k=a.clone().sub(C.clone().mul(y*(I?-1:1)));b.DistMin(_,k,S)&&(p!==0&&y!==0?(p*=-1.5,y*=-1.5):p!==0?p*=-1:y!==0&&(y*=-1)),i.add(C.clone().mul(p*(I?-1:1))),a.sub(C.clone().mul(y*(I?-1:1))),I?(u&&d&&a.setTo(b.Add(i,C.clone().mul(-Fa))),c.setTo(b.Med(s.start,s.end))):c.setTo(b.Med(i,a));const $=b.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:c,isValid:$>0,length:$}}function xC(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),c=r.isClosed,u=(c?wx:pz)(i,a,r.outline);let d;if(u!==null&&(d=u.sort((y,m)=>b.Dist2(y,i)-b.Dist2(m,i))[0]??(c?void 0:a)),d===void 0)return;const f=oe.applyToPoint(r.transform,d),p=oe.applyToPoint(oe.Inverse(t),f);e.setTo(p),r.didIntersect=!0}function rG(e,n,t){const{arrowheadEnd:r,arrowheadStart:o}=n.props,s=n.props.bend;if(Math.abs(s)>Math.abs(n.props.bend*aG))return Sv(e,n,t);const i=La(e,n,t),a=b.Med(i.start,i.end),c=b.Sub(i.end,i.start),l=b.Len(c)?c.uni():b.From(c),u=b.Add(a,l.per().mul(-s)),d=up(e,n,"start"),f=up(e,n,"end"),p=i.start.clone(),y=i.end.clone(),m=u.clone();if(b.Equals(p,y))return{bindings:t,isStraight:!0,start:{handle:p,point:p,arrowhead:n.props.arrowheadStart},end:{handle:y,point:y,arrowhead:n.props.arrowheadEnd},middle:m,isValid:!1,length:0};const w=n.props.bend<0,S=w?ku:p_,v=wC(p,y,m),P=b.Angle(v.center,p),E=b.Angle(v.center,y),C=S(P,E);if(v.length===0||v.size===0||!Mb(v.length)||!Mb(v.size))return Sv(e,n,t);const I=p.clone(),_=y.clone(),k=m.clone(),$=e.getShapePageTransform(n);let T=0,O=0,N=Fa;if(d&&!d.isExact){const K=oe.applyToPoint($,I),Z=oe.applyToPoint($,v.center),le=oe.applyToPoint($,_),be=oe.Inverse(d.transform),Ae=oe.applyToPoint(be,K),ae=oe.applyToPoint(be,Z),je=oe.applyToPoint(be,le),{isClosed:Le}=d,it=Le?ev:dP;let Ie,pt=it(ae,v.radius,d.outline);if(pt){const Ue=ae.angle(Ae),ur=ae.angle(je),Bn=S(Ue,ur);pt=pt.filter(qe=>S(Ue,ae.angle(qe))<=Bn);const Un=Bn*.25;pt.sort(Le?(qe,Dt)=>Math.abs(S(Ue,ae.angle(qe))-Un)<Math.abs(S(Ue,ae.angle(Dt))-Un)?-1:1:(qe,Dt)=>S(Ue,ae.angle(qe))<S(Ue,ae.angle(Dt))?-1:1),Ie=pt[0]??(Le?void 0:Ae)}else Ie=Le?void 0:Ae;if(Ie&&(I.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(d.transform,Ie))),d.didIntersect=!0,o!=="none")){const Ue=_s[n.props.size]/2+("size"in d.shape.props?_s[d.shape.props.size]/2:0);T=dp+Ue,N+=Ue}}if(f&&!f.isExact){const K=oe.applyToPoint($,I),Z=oe.applyToPoint($,_),le=oe.applyToPoint($,v.center),be=oe.Inverse(f.transform),Ae=oe.applyToPoint(be,K),ae=oe.applyToPoint(be,le),je=oe.applyToPoint(be,Z),Le=f.isClosed,it=Le?ev:dP;let Ie,pt=it(ae,v.radius,f.outline);if(pt){const Ue=ae.angle(Ae),ur=ae.angle(je),Bn=S(Ue,ur),Un=Bn*.75;pt=pt.filter(qe=>S(Ue,ae.angle(qe))<=Bn),pt.sort(Le?(qe,Dt)=>Math.abs(S(Ue,ae.angle(qe))-Un)<Math.abs(S(Ue,ae.angle(Dt))-Un)?-1:1:(qe,Dt)=>S(Ue,ae.angle(qe))<S(Ue,ae.angle(Dt))?-1:1),pt[0]?Ie=pt[0]:Ie=Le?void 0:je}else Ie=Le?void 0:je;if(Ie&&(_.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(f.transform,Ie))),f.didIntersect=!0,r!=="none")){const Ue=_s[n.props.size]/2+("size"in f.shape.props?_s[f.shape.props.size]/2:0);O=dp+Ue,N+=Ue}}let A=b.Angle(v.center,I),j=b.Angle(v.center,_),L=S(A,j),X=L*v.radius;const V=I.clone(),H=_.clone();if(T!==0){const K=T/X*(w?1:-1),Z=b.FromAngle(A+L*K);V.setTo(v.center).add(Z.mul(v.radius))}if(O!==0){const K=O/X*(w?-1:1),Z=b.FromAngle(j+L*K);H.setTo(v.center).add(Z.mul(v.radius))}if(b.DistMin(V,H,N)&&(T!==0&&O!==0?(T*=-1.5,O*=-1.5):T!==0?T*=-2:O!==0&&(O*=-2)),T!==0){const K=T/X*(w?1:-1),Z=b.FromAngle(A+L*K);I.setTo(v.center).add(Z.mul(v.radius))}if(O!==0){const K=O/X*(w?-1:1),Z=b.FromAngle(j+L*K);_.setTo(v.center).add(Z.mul(v.radius))}if(d&&f&&!d.isExact&&!f.isExact){A=b.Angle(v.center,I),j=b.Angle(v.center,_),L=S(A,j),X=L*v.radius;const K=Zx(e,d.shape.id,f.shape.id);if(K==="double-bound"&&X<30)I.setTo(p),_.setTo(y),k.setTo(m);else if(K==="safe"&&(d&&!d.didIntersect&&I.setTo(p),f&&!f.didIntersect||S(P,A)>S(P,j))){const Z=Math.min(.9,Fa/X)*(w?1:-1),le=b.FromAngle(A+L*Z);_.setTo(v.center).add(le.mul(v.radius))}}oG(v.center,v.radius,I,_,k,C,w),I.equals(_)&&(I.setTo(k.clone().addXY(1,1)),_.setTo(k.clone().subXY(1,1))),p.setTo(I),y.setTo(_),m.setTo(k);const U=wC(p,y,m);return{bindings:t,isStraight:!1,start:{point:p,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=v0(e,n,t),o=b.Dist(r,e),s=+b.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,c=((t.y-e.y)**2+(t.x-e.x)**2)**.5,l=Math.acos((a*a+c*c-i*i)/(2*a*c))*2,u=+(ke>l),d=(Re-l)*(s?1:-1),f=d*o;return{center:r,radius:o,size:d,length:f,largeArcFlag:u,sweepFlag:s}}function oG(e,n,t,r,o,s,i){const a=b.Angle(e,t),c=b.Angle(e,r);let l=ku(a,c);i||(l=Re-l);const u=.5*(i?1:-1),d=b.FromAngle(a+l*u);if(o.setTo(e).add(d.mul(n)),l>s){o.rotWith(e,ke);const f=r.clone();r.setTo(t),t.setTo(f)}}function sG(e){return Math.abs(e.props.bend)<8}function up(e,n,t){const r=e.getBindingsFromShape(n,"arrow").find(c=>c.props.terminal===t);if(!r)return;const o=e.getShape(r.toId);if(!o)return;const s=e.getShapePageTransform(o),i=e.getShapeGeometry(o),a=i instanceof Hr?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function bC(e,n,t,r){const o=e.getShape(t.toId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=b.Add(s,b.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},i)),c=oe.applyToPoint(e.getShapePageTransform(o),a);return oe.applyToPoint(oe.Inverse(n),c)}else return new b(0,0)}function _n(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 iG=zR("arrow info",(e,n)=>{const t=_n(e,n);return sG(n)?Sv(e,n,t):rG(e,n,t)});function so(e,n){const t=typeof n=="string"?n:n.id;return iG.get(e,t)}function La(e,n,t){var a,c;const r=e.getShapePageTransform(n),o=Zx(e,(a=t.start)==null?void 0:a.toId,(c=t.end)==null?void 0:c.toId),s=t.start?bC(e,r,t.start,o==="double-bound"||o==="start-contains-end"):b.From(n.props.start),i=t.end?bC(e,r,t.end,o==="double-bound"||o==="end-contains-start"):b.From(n.props.end);return{start:s,end:i}}function ol(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(c=>c.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 Ah(e,n,t){const r=e.getBindingsFromShape(n,"arrow").filter(o=>o.props.terminal===t);e.deleteBindings(r)}const Fa=10,dp=10,aG=10,_s={s:2,m:3.5,l:5,xl:10};function Zx(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"}function cG(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const o=_n(e,r);if(o.start||o.end)return!1}return!0})}const x$=()=>{const e=B();return W("threeStackableItems",()=>cG(e).length>2,[e])},w$=()=>{const e=B();return W("allow group",()=>{const n=e.getSelectedShapes();if(n.length<2)return!1;for(const t of n)if(e.isShapeOfType(t,"arrow")){const r=_n(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])},b$=()=>{const e=B();return W("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},lG=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function uG(e,n){const t=B();return W("selectedShapes",()=>t.getSelectedShapes().length>=e,[t,e,n])}function wn(e,n){const t=B();return W("selectedShapes",()=>{const r=t.getSelectedShapes().filter(o=>!t.isShapeOrAncestorLocked(o)).length;return e===void 0?r:r>=e},[t])}function dG(){const e=B();return W("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}function P$(){const e=B();return W("hasLinkShapeSelected",()=>{const n=e.getOnlySelectedShape();return!!(n&&n.type!=="embed"&&"url"in n.props&&!n.isLocked)},[e])}function hG(){const e=B();return W("onlyFlippableShape",()=>{const n=e.getOnlySelectedShape();return n&&(e.isShapeOfType(n,"group")||e.isShapeOfType(n,"arrow")||e.isShapeOfType(n,"line")||e.isShapeOfType(n,"draw"))},[e])}function C$(){const e=B();return W("useCanRedo",()=>e.getCanRedo(),[e])}function I$(){const e=B();return W("useCanUndo",()=>e.getCanUndo(),[e])}function fG({children:e}){const n=B();return W("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])?h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:pG}=Math,Qa=pG+1e-4;function E$(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),c=[],l=[];let u=e[0].vector,d=e[0].point,f=d,p=d,y=f,m=!1,w;for(let S=0;S<e.length;S++){w=e[S];const{point:v,vector:P}=e[S],E=w.vector.dpr(u),C=(S<e.length-1?e[S+1]:e[S]).vector,I=S<e.length-1?C.dpr(w.vector):1,_=E<0&&!m,k=I!==null&&I<.2;if(_||k){if(I>-.62&&i-w.runningLength>w.radius){const T=u.clone().mul(w.radius);u.clone().cpr(C)<0?(p=b.Add(v,T),y=b.Sub(v,T)):(p=b.Sub(v,T),y=b.Add(v,T)),c.push(p),l.push(y)}else{const T=u.clone().mul(w.radius).per(),O=b.Sub(w.input,T);for(let N=1/13,A=0;A<1;A+=N)p=b.RotWith(O,w.input,Qa*A),c.push(p),y=b.RotWith(O,w.input,Qa+Qa*-A),l.push(y)}d=p,f=y,k&&(m=!0);continue}if(m=!1,w===o||w===s){const T=b.Per(P).mul(w.radius);c.push(b.Sub(v,T)),l.push(b.Add(v,T));continue}const $=b.Lrp(C,P,I).per().mul(w.radius);p=b.Sub(v,$),(S<=1||b.Dist2(d,p)>a)&&(c.push(p),d=p),y=b.Add(v,$),(S<=1||b.Dist2(f,y)>a)&&(l.push(y),f=y),u=P}return{left:c,right:l}}function Qx(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 c=e[0],l=e[e.length-1],u=l.runningLength,d=r.taper===!1?0:r.taper===!0?Math.max(t,u):r.taper,f=o.taper===!1?0:o.taper===!0?Math.max(t,u):o.taper,{left:p,right:y}=E$(e,n),m=c.point,w=e.length>1?e[e.length-1].point:b.AddXY(c.point,1,1);if(e.length===1&&(!(d||f)||s)){const E=b.Add(m,b.Sub(m,w).uni().per().mul(-c.radius)),C=[];for(let I=1/13,_=I;_<=1;_+=I)C.push(b.RotWith(E,m,Qa*2*_));return C}const S=[];if(!(d||f&&e.length===1))if(i)for(let E=1/8,C=E;C<=1;C+=E){const I=b.RotWith(y[0],m,Qa*C);S.push(I)}else{const E=b.Sub(p[0],y[0]),C=b.Mul(E,.5),I=b.Mul(E,.51);S.push(b.Sub(m,C),b.Sub(m,I),b.Add(m,I),b.Add(m,C))}const v=[],P=l.vector.clone().per().neg();if(f||d&&e.length===1)v.push(w);else if(a){const E=b.Add(w,b.Mul(P,l.radius));for(let C=1/29,I=C;I<1;I+=C)v.push(b.RotWith(E,w,Qa*3*I))}else v.push(b.Add(w,b.Mul(P,l.radius)),b.Add(w,b.Mul(P,l.radius*.99)),b.Sub(w,b.Mul(P,l.radius*.99)),b.Sub(w,b.Mul(P,l.radius)));return p.concat(v,y.reverse(),S)}const gG=.025,mG=.01;function mo(e,n={}){var w;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(b.From),a=0;if(!o){let S=i[0];for(;S&&!(S.z>=gG);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=mG);)i.pop(),S=i[i.length-1]}if(i.length===0)return[{point:b.From(e[0]),input:b.From(e[0]),pressure:o?.5:.15,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let c=i[1];for(;c&&!(b.Dist2(c,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,c.z),i.splice(1,1),c=i[1];const l=i.pop();for(c=i[i.length-1];c&&!(b.Dist2(c,l)>(r/3)**2);)i.pop(),c=i[i.length-1],a++;i.push(l);const u=n.last||!n.simulatePressure||i.length>1&&b.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 P=b.Lrp(i[0],S,v/4);P.z=(i[0].z+(S.z-i[0].z))*v/4,i.push(P)}}const d=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let f=0,p=d[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(p.point,1-s),!p.point.equals(y)&&(m=b.Dist(y,p.point),f+=m,!(S<4&&f<r)&&(p={input:i[S],point:y,pressure:o?.5:i[S].z,vector:b.Sub(p.point,y).uni(),distance:m,runningLength:f,radius:1},d.push(p)));if((w=d[1])!=null&&w.vector&&(d[0].vector=d[1].vector.clone()),f<1){const S=Math.max(.5,...d.map(v=>v.pressure));d.forEach(v=>v.pressure=S)}return d}const{min:gs}=Math,Jm=.275;function og(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=w=>w,start:i={},end:a={}}=n,{easing:c=an.easeOutQuad}=i,{easing:l=an.easeOutCubic}=a,u=e[e.length-1].runningLength;let d,f=e[0].pressure,p;if(!o&&u<t){const w=e.reduce((S,v)=>Math.max(S,v.pressure),.5);return e.forEach(S=>{S.pressure=w,S.radius=t*s(.5-r*(.5-S.pressure))}),e}else{let w;for(let S=0,v=e.length;S<v&&(p=e[S],!(p.runningLength>t*5));S++){const P=gs(1,p.distance/t);if(o){const E=gs(1,1-P);w=gs(1,f+(E-f)*(P*Jm))}else w=gs(1,f+(p.pressure-f)*.5);f=f+(w-f)*.5}for(let S=0;S<e.length;S++){if(p=e[S],r){let{pressure:v}=p;const P=gs(1,p.distance/t);if(o){const E=gs(1,1-P);v=gs(1,f+(E-f)*(P*Jm))}else v=gs(1,f+(v-f)*(P*Jm));p.radius=t*s(.5-r*(.5-v)),f=v}else p.radius=t/2;d===void 0&&(d=p.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 w=0;w<e.length;w++){p=e[w];const{runningLength:S}=p,v=S<y?c(S/y):1,P=u-S<m?l((u-S)/m):1;p.radius=Math.max(.01,p.radius*Math.min(v,P))}return e}function yG(e,n={}){return Qx(og(mo(e,n),n),n)}function PC({scribble:e,zoom:n,color:t,opacity:r,className:o}){if(!e.points.length)return null;const s=yG(e.points,{size:e.size/n,start:{taper:e.taper,easing:an.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=e.size/n/2,{x:c,y:l}=e.points[e.points.length-1];i=`M ${c-a},${l} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=E0(s);return h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})}const SG=({bounds:e,rotation:n})=>{const t=B();return W("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?h.jsx(H_,{bounds:e,rotation:n}):null};function ss(){const e=B();return W("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function vG({size:e,width:n,height:t,hideAlternateHandles:r}){const o=F(e/3),s=o/2;return h.jsxs("svg",{className:"tl-overlays__item",children:[h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
107
- ${F(0-s)},${F(e)}
108
- ${F(0-s)},${F(0-s)}
109
- ${F(e)},${F(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:F(n/2-e),y1:F(0-s),x2:F(n/2+e),y2:F(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
110
- ${F(n-e)},${F(0-s)}
111
- ${F(n+s)},${F(0-s)}
112
- ${F(n+s)},${F(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:F(n+s),y1:F(t/2-e),x2:F(n+s),y2:F(t/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
113
- ${F(n+s)},${F(t-e)}
114
- ${F(n+s)},${F(t+s)}
115
- ${F(n-e)},${F(t+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:F(n/2-e),y1:F(t+s),x2:F(n/2+e),y2:F(t+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
116
- ${F(0+e)},${F(t+s)}
117
- ${F(0-s)},${F(t+s)}
118
- ${F(0-s)},${F(t-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:F(0-s),y1:F(t/2-e),x2:F(0-s),y2:F(t/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const xG=ir(function({bounds:n,rotation:t}){const r=B(),o=x.useRef(null),s=ss(),i=Jr("top"),a=Jr("right"),c=Jr("bottom"),l=Jr("left"),u=Jr("top_left"),d=Jr("top_right"),f=Jr("bottom_right"),p=Jr("bottom_left"),y=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),S=w&&r.isShapeOrAncestorLocked(w),v=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0;if(wc(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 P=r.getZoomLevel(),E=r.getInstanceState().isChangingStyle,C=n.width,I=n.height,_=8/P,k=C<_*2,$=I<_*2,T=C<_*4,O=I<_*4,N=C<_*5,A=I<_*5,j=m?1.75:1,L=6/P*j,X=(T?L/2:L)*(j*.75),V=(O?L/2:L)*(j*.75),H=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!E;let U=H&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.pointing_resize_handle","select.pointing_crop_handle")||H&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&U&&r.environment.isFirefox&&r.isShapeOfType(w,"embed")&&(U=!1);const K=r.isInAny("select.pointing_crop_handle","select.crop.idle","select.crop.pointing_crop")&&!E&&!s,Z=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!E&&!s,le=!m&&!(k||$)&&(Z||K)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!S,be=m&&(!T||!O)&&(Z||K)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!S,Ae=Z&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!K&&!S,ae=k||$,je=k&&$,Le=N||A,it=Ae||K,Ie=!le,pt=!Z||!be,Ue=!Z||!it,ur=!Z||!it||ae,Bn=!Z||!it||ae,Un=!Z||!it||je&&!K;let qe=!0,Dt=!0;if(K)qe=Le,Dt=Le;else if(Ae){qe=ae||je||m;const Lc=m&&w&&w.type==="text";Dt=qe&&!Lc}const To=Math.min(24/P,I-V*3),Rc=Z&&m&&w&&r.isShapeOfType(w,"text")&&To*P>=4;return h.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsxs("g",{ref:o,children:[U&&h.jsx("rect",{className:"tl-selection__fg__outline",width:F(C),height:F(I)}),h.jsx(Nd,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:L,corner:"top_left_rotate",cursor:y?Kn("nwse-rotate",t):void 0,isHidden:Ie}),h.jsx(Nd,{"data-testid":"selection.rotate.top-right",cx:C+L*3,cy:0,targetSize:L,corner:"top_right_rotate",cursor:y?Kn("nesw-rotate",t):void 0,isHidden:Ie}),h.jsx(Nd,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:I+L*3,targetSize:L,corner:"bottom_left_rotate",cursor:y?Kn("swne-rotate",t):void 0,isHidden:Ie}),h.jsx(Nd,{"data-testid":"selection.rotate.bottom-right",cx:C+L*3,cy:I+L*3,targetSize:L,corner:"bottom_right_rotate",cursor:y?Kn("senw-rotate",t):void 0,isHidden:Ie}),h.jsx(bG,{"data-testid":"selection.rotate.mobile",cx:T?-L*1.5:C/2,cy:T?I/2:-L*1.5,size:_,isHidden:pt}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:F(0-(O?V*2:V)),width:F(C),height:F(Math.max(1,V*2)),style:y?{cursor:Kn("ns-resize",t)}:void 0,...i}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Dt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:F(C-(T?0:X)),y:0,height:F(I),width:F(Math.max(1,X*2)),style:y?{cursor:Kn("ew-resize",t)}:void 0,...a}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:F(I-(O?0:V)),width:F(C),height:F(Math.max(1,V*2)),style:y?{cursor:Kn("ns-resize",t)}:void 0,...c}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Dt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:F(0-(T?X*2:X)),y:0,height:F(I),width:F(Math.max(1,X*2)),style:y?{cursor:Kn("ew-resize",t)}:void 0,...l}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Ue}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:F(0-(T?X*2:X*1.5)),y:F(0-(O?V*2:V*1.5)),width:F(X*3),height:F(V*3),style:y?{cursor:Kn("nwse-resize",t)}:void 0,...u}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":ur}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:F(C-(T?0:X*1.5)),y:F(0-(O?V*2:V*1.5)),width:F(X*3),height:F(V*3),style:y?{cursor:Kn("nesw-resize",t)}:void 0,...d}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Un}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:F(C-(T?X:X*1.5)),y:F(I-(O?V:V*1.5)),width:F(X*3),height:F(V*3),style:y?{cursor:Kn("nwse-resize",t)}:void 0,...f}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Bn}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:F(0-(T?X*3:X*1.5)),y:F(I-(O?0:V*1.5)),width:F(X*3),height:F(V*3),style:y?{cursor:Kn("nesw-resize",t)}:void 0,...p}),Ae&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.resize.top-left",className:ue("tl-corner-handle",{"tl-hidden":Ue}),"aria-label":"top_left handle",x:F(0-_/2),y:F(0-_/2),width:F(_),height:F(_)}),h.jsx("rect",{"data-testid":"selection.resize.top-right",className:ue("tl-corner-handle",{"tl-hidden":ur}),"aria-label":"top_right handle",x:F(C-_/2),y:F(0-_/2),width:F(_),height:F(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ue("tl-corner-handle",{"tl-hidden":Un}),"aria-label":"bottom_right handle",x:F(C-_/2),y:F(I-_/2),width:F(_),height:F(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ue("tl-corner-handle",{"tl-hidden":Bn}),"aria-label":"bottom_left handle",x:F(0-_/2),y:F(I-_/2),width:F(_),height:F(_)})]}),Rc&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:F(0-_/4),y:F(I/2-To/2),rx:_/4,width:F(_/2),height:F(To)}),h.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:_/4,x:F(C-_/4),y:F(I/2-To/2),width:F(_/2),height:F(To)})]}),K&&h.jsx(vG,{size:_,width:C,height:I,hideAlternateHandles:Le})]})})}),Nd=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const c=Jr(o);return h.jsx("rect",{className:ue("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:F(n-r*3),y:F(t-r*3),width:F(Math.max(1,r*3)),height:F(Math.max(1,r*3)),cursor:s,...c})},wG=Math.sqrt(Math.PI),bG=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=Jr("mobile_rotate"),a=B(),c=W("zoom level",()=>a.getZoomLevel(),[a]),l=Math.max(14*(1/c),20/Math.max(1,c));return h.jsxs("g",{children:[h.jsx("circle",{"data-testid":s,pointerEvents:"all",className:ue("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:l,...i}),h.jsx("circle",{className:ue("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/wG})]})};class jh extends Eh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:n}){ey(this.editor,this.editor.getShape(n.fromId))}onAfterChange({bindingAfter:n}){ey(this.editor,this.editor.getShape(n.fromId))}onAfterChangeFromShape({shapeAfter:n}){ey(this.editor,n)}onAfterChangeToShape({binding:n}){_$(this.editor,n.fromId)}onBeforeUnbind({binding:n,reason:t}){if(t===Dl.DeletingFromShape)return;const r=this.editor.getShape(n.fromId);r&&k$(this.editor,r,n.props.terminal)}}g(jh,"type","arrow"),g(jh,"props",RE),g(jh,"migrations",LE);function _$(e,n){var w;const t=e.getShape(n);if(!t)return;const r=_n(e,t),{start:o,end:s}=r,i=o?e.getShape(o.toId):void 0,a=s?e.getShape(s.toId):void 0,c=e.getAncestorPageId(t);if(!c)return;let l;if(i&&a)l=e.findCommonAncestor([i,a])??c;else if(i||a){const S=(w=i||a)==null?void 0:w.parentId;S&&S===t.parentId?l=t.parentId:l=c}else return;l&&l!==t.parentId&&e.reparentShapes([n],l);const u=e.getShape(n);if(!u)throw Error("no reparented arrow");const d=e.getShapeNearestSibling(u,i),f=e.getShapeNearestSibling(u,a);let p;if(d&&f)p=d.index>f.index?d:f;else if(d&&!f)p=d;else if(f&&!d)p=f;else return;let y;const m=e.getSortedChildIdsForParent(p.parentId).map(S=>e.getShape(S)).filter(S=>S.index>p.index);if(m.length){const S=m.find(v=>v.type!=="arrow");if(u.index>p.index&&(!S||u.index<S.index))return;y=zl(p.index,m[0].index)}else y=Lo(p.index);y!==u.index&&e.updateShapes([{id:n,type:"arrow",index:y}])}function ey(e,n){const t=_n(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)&&k$(e,n,r)}_$(e,n.id)}function k$(e,n,t){const r=so(e,n);if(!r)throw new Error("expected arrow info");const o={id:n.id,type:"arrow",props:{[t]:{x:r[t].point.x,y:r[t].point.y},bend:n.props.bend}};if(!r.isStraight){const s=t==="start"?r.start.point:r.start.handle,i=t==="end"?r.end.point:r.end.handle,a=b.Med(s,i),c=b.Sub(s,i).per().uni().mul(r.handleArc.radius*2*Math.sign(n.props.bend)),l=Lu(r.handleArc.center,b.Add(a,c),r.handleArc.center,r.handleArc.radius);st((l==null?void 0:l.length)===1);const u=b.Dist(a,l[0])*Math.sign(n.props.bend);o.props.bend=u}e.updateShape(o),Ah(e,n,t)}const T$=[jh],Wt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},At={s:2,m:3.5,l:5,xl:10},hc={s:18,m:24,l:36,xl:44},Ko={s:18,m:22,l:26,xl:32},mi={s:18,m:20,l:24,xl:28},fo={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},PG=20,CG=4.25,Dr=16;/*!
119
- * canvas-size
120
- * v1.2.6
121
- * https://github.com/jhildenbiddle/canvas-size
122
- * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
123
- * MIT license
124
- */function IG(e,n){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var r,o,s,i,a=[],c=!0,l=!1;try{if(s=(t=t.call(e)).next,n===0){if(Object(t)!==t)return;c=!1}else for(;!(c=(r=s.call(t)).done)&&(a.push(r.value),a.length!==n);c=!0);}catch(u){l=!0,o=u}finally{try{if(!c&&t.return!=null&&(i=t.return(),Object(i)!==i))return}finally{if(l)throw o}}return a}}function CC(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 Wn(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?CC(Object(t),!0).forEach(function(r){EG(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):CC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function EG(e,n,t){return n=DG(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function _G(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 kG(e,n){if(e==null)return{};var t=_G(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 IC(e,n){return $G(e)||IG(e,n)||$$(e,n)||jG()}function zd(e){return TG(e)||MG(e)||$$(e)||AG()}function TG(e){if(Array.isArray(e))return vv(e)}function $G(e){if(Array.isArray(e))return e}function MG(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function $$(e,n){if(e){if(typeof e=="string")return vv(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 vv(e,n)}}function vv(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 AG(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
125
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function jG(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
126
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function OG(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 DG(e){var n=OG(e,"string");return typeof n=="symbol"?n:String(n)}function Rl(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,c;i?(a=new OffscreenCanvas(1,1),c=new OffscreenCanvas(t,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,c=document.createElement("canvas"),c.width=t,c.height=r);var l=a.getContext("2d"),u=c.getContext("2d");u&&(u.fillRect.apply(u,o),l.drawImage(c,t-1,r-1,1,1,0,0,1,1));var d=l&&l.getImageData(0,0,1,1).data[3]!==0,f=Date.now()-s;return[a,c].forEach(function(p){p.height=0,p.width=0}),i?(postMessage({width:t,height:r,benchmark:f,isTestPass:d}),!d&&e.sizes.length&&Rl(e)):d?e.onSuccess(t,r,f):(e.onError(t,r,f),e.sizes.length&&Rl(e)),d}var ty={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]},RG=["onError","onSuccess"],Na={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},sl={};function ny(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 d=n||t?u:1,f=n||r?u:1;o.push([d,f])});else for(var s=e.min||Na.min,i=e.step||Na.step,a=Math.max(e.width,e.height);a>=s;){var c=n||t?a:1,l=n||r?a:1;o.push([c,l]),a-=i}return o}function Bd(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=kG(e,RG),a=null;if(!n)return!1;if(e.useWorker&&t){var c=`
127
- var canvasTest = `.concat(Rl.toString(),`;
128
- onmessage = function(e) {
129
- canvasTest(e.data);
130
- };
131
- `),l=new Blob([c],{type:"application/javascript"}),u=URL.createObjectURL(l);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(d){var f=d.data,p=f.width,y=f.height,m=f.benchmark,w=f.isTestPass;w?(sl[r].onSuccess(p,y,m),delete sl[r]):sl[r].onError(p,y,m)}}if(e.usePromise)return new Promise(function(d,f){var p=Wn(Wn({},e),{},{onError:function(S,v,P){var E;if(e.sizes.length===0)E=!0;else{var C=e.sizes.slice(-1),I=IC(C,1),_=IC(I[0],2),k=_[0],$=_[1];E=S===k&&v===$}o(S,v,P),E&&f({width:S,height:v,benchmark:P})},onSuccess:function(S,v,P){s(S,v,P),d({width:S,height:v,benchmark:P})}});if(a){var y=p.onError,m=p.onSuccess;sl[r]={onError:y,onSuccess:m},a.postMessage(i)}else Rl(p)});if(a)sl[r]={onError:o,onSuccess:s},a.postMessage(i);else return Rl(e)}var ry={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ny({width:n.max,height:n.max,min:n.min,step:n.step,sizes:zd(ty.area)}),r=Wn(Wn(Wn({},Na),n),{},{sizes:t});return Bd(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ny({width:1,height:n.max,min:n.min,step:n.step,sizes:zd(ty.height)}),r=Wn(Wn(Wn({},Na),n),{},{sizes:t});return Bd(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ny({width:n.max,height:1,min:n.min,step:n.step,sizes:zd(ty.width)}),r=Wn(Wn(Wn({},Na),n),{},{sizes:t});return Bd(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Wn(Wn({},Na),n);return t.sizes=zd(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),Bd(t)}};let oy=null;function LG(){return oy||(oy=FG()),oy}async function FG(){const e=await ry.maxWidth({usePromise:!0}),n=await ry.maxHeight({usePromise:!0}),t=await ry.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const EC=8192,NG=4096*4096;async function M$(e,n){if(e<=EC&&n<=EC&&e*n<=NG)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await LG(),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 zG(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}}async function BG(e,n,t,r={}){const o=await Xn.usingObjectURL(e,Xn.loadImage),{type:s=e.type,quality:i=.92}=r,[a,c]=await M$(Math.min(n*2,o.naturalWidth),Math.min(t*2,o.naturalHeight)),l=document.createElement("canvas");l.width=a,l.height=c;const u=Vn(l.getContext("2d",{willReadFrequently:!0}),"Could not get canvas context");return u.imageSmoothingEnabled=!0,u.imageSmoothingQuality="high",u.drawImage(o,0,0,a,c),new Promise((d,f)=>{l.toBlob(p=>{p?d(p):f(new Error("Could not resize image"))},s,i)})}function UG(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function HG(e){const n=new URL(e).host.replace("www.","");for(const t of _u)if(A$(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const KG=e=>e.split("*").map(n=>UG(n)).join(".+"),A$=(e,n)=>!!e.find(t=>{const r=new RegExp(KG(t));return n.match(r)});function WG(e){const n=new URL(e).host.replace("www.","");for(const t of _u)if(A$(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function j$(e){return WG(e)??HG(e)}function ks(e){try{return j$(e)}catch(n){console.error(n)}}/*!
132
- * MIT License
133
- * Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
134
- * Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
135
- */const za=" ",hn=class hn{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)||hn.insertTextFirefox(n,t),o===r.body?n.blur():o instanceof HTMLElement&&o!==n&&o.focus()}static set(n,t){n.select(),hn.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=hn.getSelection(n);hn.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 c=typeof r=="string"?r:r(...s);return hn.insert(n,c),n.selectionStart=i,o+=c.length-a,c})}static findLineEnd(n,t){const r=n.lastIndexOf(`
136
- `,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 c=o.lastIndexOf(`
137
- `,t-1)+1,l=n.value.slice(c,r-1),u=l.replace(/^|\n/g,`$&${za}`),d=u.length-l.length;n.setSelectionRange(c,r-1),hn.insert(n,u),n.setSelectionRange(t+1,r+d)}else hn.insert(n,za)}static unindent(n){const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.lastIndexOf(`
138
- `,t-1)+1,i=hn.findLineEnd(o,r),a=n.value.slice(s,i),c=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),l=a.length-c.length;n.setSelectionRange(s,i),hn.insert(n,c);const u=/\t| {1,2}/.exec(o.slice(s,t)),d=u?u[0].length:0,f=t-d;n.setSelectionRange(t-d,Math.max(f,r-l))}static indentCE(n){var c;const t=window.getSelection(),r=n.innerText,o=Ud(n)??0,s=Ud(n)??0,i=r.slice(o,s),a=(c=/\n/g.exec(i))==null?void 0:c.length;if(a&&a>0){const l=r.lastIndexOf(`
139
- `,o-1)+1,u=r.slice(l,s-1),f=u.replace(/^|\n/g,`$&${za}`).length-u.length;t&&t.setBaseAndExtent(n,o+1,n,s+f)}else{const l=window.getSelection();n.innerText=r.slice(0,o)+za+r.slice(o),l==null||l.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=Ud(n)??0,s=Ud(n)??0,i=r.lastIndexOf(`
140
- `,o-1)+1,a=hn.findLineEnd(r,s),c=r.slice(i,a),l=c.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=c.length-l.length;if(t){t.setBaseAndExtent(n,i,n,a);const d=/\t| {1,2}/.exec(r.slice(i,o)),f=d?d[0].length:0,p=o-f;t.setBaseAndExtent(n,o-f,n,Math.max(p,s-u))}}static normalizeText(n){return n.replace(hn.fixNewLines,`
141
- `)}static normalizeTextForDom(n){return n.replace(hn.fixNewLines,`
142
- `).split(`
143
- `).map(t=>t||" ").join(`
144
- `)}};g(hn,"fixNewLines",/\r?\n|\r/g);let fc=hn;function Ud(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 GG=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function O$(e){return GG.test(e)}function VG(e){return e.replace(/\t/g,za)}function YG(e){const n=e.split(`
145
- `);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(`
146
- `)}function XG(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function qG(e){return XG(YG(VG(e)))}const Ll=(e,n)=>e.length<=n?e:e.substring(0,n-3)+"...";function ZG(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i}){e.registerExternalAssetHandler("file",async({file:a})=>{const c=a.name;let l=a;const u=r.includes(l.type),d=o.includes(l.type);st(u||d,`File type not allowed: ${l.type}`),st(l.size<=t,`File size too big: ${(l.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),l.type==="video/quicktime"&&(l=new Blob([l],{type:"video/mp4"}));let f=u?await Xn.getImageSize(l):await Xn.getVideoSize(l);const p=await Xn.isAnimated(l)||d,y=await lR(await l.arrayBuffer());if(isFinite(n)){const S=zG(f,{w:n,h:n});f!==S&&Xn.isStaticImageType(l.type)&&(f=S)}!p&&Xn.isStaticImageType(l.type)&&(l=await BG(l,f.w,f.h,{type:l.type,quality:.92}));const m=yi.createId(y);return yi.create({id:m,type:u?"image":"video",typeName:"asset",props:{name:c,src:await Ua.blobToDataUrl(l),w:f.w,h:f.h,mimeType:l.type,isAnimated:p}})}),e.registerExternalAssetHandler("url",async({url:a})=>{var l,u,d;let c;try{const p=await(await fetch(a,{method:"GET",mode:"no-cors"})).text(),y=new DOMParser().parseFromString(p,"text/html");c={image:((l=y.head.querySelector('meta[property="og:image"]'))==null?void 0:l.getAttribute("content"))??"",title:((u=y.head.querySelector('meta[property="og:title"]'))==null?void 0:u.getAttribute("content"))??Ll(a,32),description:((d=y.head.querySelector('meta[property="og:description"]'))==null?void 0:d.getAttribute("content"))??""}}catch(f){console.error(f),s.addToast({title:i("assets.url.failed"),severity:"error"}),c={image:"",title:Ll(a,32),description:""}}return{id:yi.createId(Vy(a)),typeName:"asset",type:"bookmark",props:{src:a,description:c.description,image:c.image,title:c.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:a,text:c})=>{const l=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=new DOMParser().parseFromString(c,"image/svg+xml").querySelector("svg");if(!u)throw new Error("No <svg/> element present");let d=parseFloat(u.getAttribute("width")||"0"),f=parseFloat(u.getAttribute("height")||"0");if(!(d&&f)){document.body.appendChild(u);const y=u.getBoundingClientRect();document.body.removeChild(u),d=y.width,f=y.height}const p=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});if(!p)throw Error("Could not create an asset");_C(e,[p],l)}),e.registerExternalContentHandler("embed",({point:a,url:c,embed:l})=>{const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),{width:d,height:f}=l,p=Be(),y={id:p,type:"embed",x:u.x-(d||450)/2,y:u.y-(f||450)/2,props:{w:d,h:f,url:c}};e.createShapes([y]).select(p)}),e.registerExternalContentHandler("files",async({point:a,files:c})=>{const l=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=new b(l.x,l.y),d=[];await Promise.all(c.map(async(f,p)=>{if(f.size>t)return console.warn(`File size too big: ${(f.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),null;if(!f.type)throw new Error("No mime type");if(!r.concat(o).includes(f.type))return console.warn(`${f.name} not loaded - Extension not allowed.`),null;try{const y=await e.getAssetForExternalContent({type:"file",file:f});if(!y)throw Error("Could not create an asset");d[p]=y}catch(y){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(y),null}})),_C(e,ye(d),u)}),e.registerExternalContentHandler("text",async({point:a,text:c})=>{const l=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=e.getShapeUtil("text").getDefaultProps(),d=qG(c),f=e.getOnlySelectedShape();if(f&&"text"in f.props){e.updateShapes([{id:f.id,type:f.type,props:{text:d}}]);return}let p,y,m,w="middle";const S=d.split(`
147
- `).length>1,v=O$(d);S&&(w=S?v?"end":"start":"middle");const P=e.textMeasure.measureText(d,{...Wt,fontFamily:fo[u.font],fontSize:hc[u.size],maxWidth:null}),E=Math.min(S?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(P.w>E){const C=e.textMeasure.measureText(d,{...Wt,fontFamily:fo[u.font],fontSize:hc[u.size],maxWidth:E});p=C.w,y=C.h,m=!1,w=v?"end":"start"}else p=P.w,y=P.h,m=!0;l.y-y/2<e.getViewportPageBounds().minY+40&&(l.y=e.getViewportPageBounds().minY+40+y/2),e.createShapes([{id:Be(),type:"text",x:l.x-p/2,y:l.y-y/2,props:{text:d,textAlign:w,autoSize:m,w:p}}])}),e.registerExternalContentHandler("url",async({point:a,url:c})=>{const l=ks(c);if(l)return e.putExternalContent({type:"embed",url:l.url,point:a,embed:l.definition});const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),d=yi.createId(Vy(c)),f=QG(e,c,u);let p=e.getAsset(d),y=!1;if(!p){y=!0;try{const m=await e.getAssetForExternalContent({type:"url",url:c});if(!m)throw Error("Could not create an asset");p=m}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{y&&e.createAssets([p]),e.updateShapes([{id:f.id,type:f.type,props:{assetId:p.id}}])})})}async function _C(e,n,t){if(!n.length)return[];const r=b.From(t),o=[];for(const s of n)switch(s.type){case"bookmark":{o.push({id:Be(),type:"bookmark",x:r.x-150,y:r.y-160,opacity:1,props:{assetId:s.id,url:s.props.src}}),r.x+=300;break}case"image":{o.push({id:Be(),type:"image",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w;break}case"video":o.push({id:Be(),type:"video",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w}return e.batch(()=>{const s=n.filter(i=>!e.getAsset(i.id));s.length&&e.createAssets(s),e.createShapes(o).select(...o.map(i=>i.id)),D$(e,t)}),o.map(s=>s.id)}function D$(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=b.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 QG(e,n,t){const r={id:Be(),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),D$(e,t)}),e.getShape(r.id)}var ky;let JG=(ky=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(ky,"id","idle"),ky);var Ty;let eV=(Ty=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=Be();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"arrow",x:t.x,y:t.y}]);const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=s.find(d=>d.id==="start"),l=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...c,x:0,y:0},isPrecise:!0,initial:a});l&&this.editor.updateShapes([l]),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,c=r.find(u=>u.id==="start"),l=(o=i.onHandleDrag)==null?void 0:o.call(i,t,{handle:{...c,x:0,y:0},isPrecise:this.didTimeout,initial:a});l&&this.editor.updateShapes([l])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),l=r.find(d=>d.id==="end"),u=(s=i.onHandleDrag)==null?void 0:s.call(i,this.editor.getShape(t),{handle:{...l,x:c.x,y:c.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=window.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},g(Ty,"id","pointing"),Ty);class Oh extends se{constructor(){super(...arguments);g(this,"shapeType","arrow")}}g(Oh,"id","arrow"),g(Oh,"initial","idle"),g(Oh,"children",()=>[JG,eV]);class Jx 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?b.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){if(!this.canClose())return!1;const o=At[r],s=t[0].points[0],i=t[t.length-1],a=i.points[i.points.length-1];return s!==a&&this.currentLineLength>o*4&&b.DistMin(s,a,o*2)}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+ot(),this.editor.mark(this.markId);const o=this.info.point.z===void 0?.5:this.info.point.z;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 c=Nt(a.props.segments);if(!c)throw Error("Expected a previous segment!");const l=Nt(c.points);if(!l)throw Error("Expected a previous point!");const{x:u,y:d}=this.editor.getPointInShapeSpace(a,t).toFixed(),f={type:this.segmentMode,points:[{x:l.x,y:l.y,z:+s.toFixed(2)},{x:u,y:d,z:+s.toFixed(2)}]},p=oe.applyToPoint(this.editor.getShapePageTransform(a.id),l);this.pagePointWhereCurrentSegmentChanged=p,this.pagePointWhereNextSegmentChanged=null;const y=[...a.props.segments,f];this.currentLineLength<At[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)),this.editor.updateShapes([m]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const i=Be();this.editor.createShapes([{id:i,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPenOrStylus,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+s.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:o,props:{size:s}}=t,i=this.editor.getShape(o);if(!i)return;const{segments:a}=i.props,{x:c,y:l,z:u}=this.editor.getPointInShapeSpace(i,r.currentPagePoint).toFixed(),d={x:c,y:l,z:this.isPenOrStylus?+(u*1.25).toFixed(2):.5};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:f}=this;if(f===null)throw Error("We should have a point where the segment changed");if(b.Dist2(f,r.currentPagePoint)>$f){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const y=Nt(a);if(!y)throw Error("Expected a previous segment!");const m=Nt(y.points);if(!m)throw Error("Expected a previous last point!");let w;const S=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(y.type==="straight"){this.currentLineLength+=b.Dist(m,S),w={type:"straight",points:[{...m},S]};const P=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(P,m)}else w={type:"straight",points:[S,d]};const v={id:o,type:this.shapeType,props:{segments:[...a,w]}};this.canClose()&&(v.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([v])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:f}=this;if(f===null)throw Error("We should have a point where the segment changed");if(b.Dist2(f,r.currentPagePoint)>$f){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const y=a.slice(),m=y[y.length-1],w=Nt(m.points);if(!w)throw Error("No previous point!");const S={type:"free",points:[...b.PointsBetween(w,d,6).map(E=>E.toFixed().toJson())]},v=[...y,S];this.currentLineLength<At[i.props.size]*4&&(this.currentLineLength=this.getLineLength(v));const P={id:o,type:this.shapeType,props:{segments:v}};this.canClose()&&(P.props.isClosed=this.getIsClosed(v,s)),this.editor.updateShapes([P])}break}case"straight":{const f=a.slice(),p=f[f.length-1],{pagePointWhereCurrentSegmentChanged:y}=this,{ctrlKey:m,currentPagePoint:w}=this.editor.inputs;if(!y)throw Error("We should have a point where the segment changed");let S,v=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(v=!m,this.didJustShiftClickToExtendPreviousShapeLine=!1):v=!m;let P=this.editor.getPointInShapeSpace(i,w).toFixed().toJson(),E=!1,C;if((this.editor.user.getIsSnapMode()?!m:m)&&f.length>2){let k,$=8/this.editor.getZoomLevel();for(let T=0,O=a.length-2;T<O;T++){const N=a[T];if(!N)break;if(N.type==="free")continue;const A=N.points[0],j=Nt(N.points);if(!(A&&j))continue;const L=b.NearestPointOnLineSegment(A,j,P);if(b.DistMin(L,P,$)){k=L.toFixed().toJson(),$=b.Dist(L,P),C=N;break}}k&&(E=!0,P=k)}if(E&&C){const k=this.editor.getShapePageTransform(i),$=C.points[0],T=Nt(C.points);if(!T)throw Error("Expected a last point!");const O=oe.applyToPoint(k,$),N=oe.applyToPoint(k,T),A=oe.applyToPoint(k,P);this.editor.snaps.setIndicators([{id:ot(),type:"points",points:[O,A,N]}])}else{if(this.editor.snaps.clearIndicators(),v){const k=b.Angle(y,w),T=kf(k,24)-k;S=b.RotWith(w,y,T)}else S=w;P=this.editor.getPointInShapeSpace(i,S).toFixed().toJson()}this.currentLineLength+=b.Dist(p.points[0],P),f[f.length-1]={...p,type:"straight",points:[p.points[0],P]};const _={id:o,type:this.shapeType,props:{segments:f}};this.canClose()&&(_.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([_]);break}case"free":{const f=a.slice(),p=f[f.length-1],y=[...p.points];if(y.length&&this.mergeNextPoint){const{z:w}=y[y.length-1];y[y.length-1]={x:d.x,y:d.y,z:w?Math.max(w,d.z):d.z}}else this.currentLineLength+=b.Dist(y[y.length-1],d),y.push(d);f[f.length-1]={...p,points:y},this.currentLineLength<At[i.props.size]*4&&(this.currentLineLength=this.getLineLength(f));const m={id:o,type:this.shapeType,props:{segments:f}};if(this.canClose()&&(m.props.isClosed=this.getIsClosed(f,s)),this.editor.updateShapes([m]),y.length>500){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const w=Be();this.editor.createShapes([{id:w,type:this.shapeType,x:oc(r.currentPagePoint.x),y:oc(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(u*1.25).toFixed():.5}]}]}}]),this.initialShape=xt(this.editor.getShape(w)),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+=b.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(Jx,"id","drawing");var $y;let R$=($y=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($y,"id","idle"),$y);class Dh extends se{constructor(){super(...arguments);g(this,"shapeType","draw");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Dh,"id","draw"),g(Dh,"initial","idle"),g(Dh,"children",()=>[R$,Jx]);class xv extends kh{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 c=this.editor.getShapePageBounds(a);c&&r.contains(c)&&tV(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(xv,"id","frame"),g(xv,"initial","idle");function tV(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var My;let nV=(My=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(My,"id","idle"),My);var Ay;let rV=(Ay=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=Be();this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"geo",x:r.x,y:r.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(co)}}]).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=Be();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"geo",x:t.x,y:t.y,props:{geo:this.editor.getStyleForNextShape(co),w:1,h:1}}]);const o=this.editor.getShape(r);if(!o)return;const s=o.props.geo==="star"?new J(0,0,200,190):o.props.geo==="cloud"?new J(0,0,300,180):new J(0,0,200,200),i=s.center,a=this.editor.getShapeParentTransform(o);a&&i.rot(-a.rotation()),this.editor.select(r),this.editor.updateShapes([{id:o.id,type:"geo",x:o.x-i.x,y:o.y-i.y,props:{geo:this.editor.getStyleForNextShape(co),w:s.width,h:s.height}}]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},g(Ay,"id","pointing"),Ay);class Rh extends se{constructor(){super(...arguments);g(this,"shapeType","geo")}}g(Rh,"id","geo"),g(Rh,"initial","idle"),g(Rh,"children",()=>[nV,rV]);class Lh extends se{constructor(){super(...arguments);g(this,"shapeType","highlight");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Lh,"id","highlight"),g(Lh,"initial","idle"),g(Lh,"children",()=>[R$,Jx]);var jy;let oV=(jy=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(jy,"id","idle"),jy);const kC=2;var Oy;let sV=(Oy=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(p=>p.type==="vertex").sort(nn),c=a[a.length-1],l=a[a.length-2],u=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new b(this.shape.x,this.shape.y)),d=b.Sub(o,u).addXY(.1,.1),f=xt(this.shape.props.points);if(b.DistMin(c,l,kC)||b.DistMin(d,c,kC))f[c.id]={id:c.id,index:c.index,x:d.x,y:d.y};else{const p=Lo(c.index);f[p]={id:p,index:p,x:d.x,y:d.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:f}}])}else{const i=Be();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});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(Oy,"id","pointing"),Oy);class Fh extends se{constructor(){super(...arguments);g(this,"shapeType","line")}}g(Fh,"id","line"),g(Fh,"initial","idle"),g(Fh,"children",()=>[oV,sV]);var Dy;let iV=(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(Dy,"id","idle"),Dy);function We(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=L$(e,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=e.getShapeUtil(s),c=ye(i.map(l=>e.getShape(l)));(o=a.onDragShapesOut)==null||o.call(a,s,c)}}function L$(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 c of t){const l=e.getShapePageBounds(c);if(!l)continue;if(!r.includes(l)){a.push(c);continue}o??(o=e.getShapeGeometry(n)),s??(s=e.getShapePageTransform(n)),i??(i=s.applyToPoints(o.vertices));const u=e.getShapePageTransform(c).clone().invert().applyToPoints(i),{vertices:d,isClosed:f}=e.getShapeGeometry(c);if(!d.some(p=>er(p,u))){if(f){if(s2(u,d))continue}else if(yz(u,d))continue;a.push(c)}}return a}function hp(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}),F$(e)}const aV=16;function F$(e){const n=e.getSelectionPageBounds(),t=e.getViewportPageBounds();if(n&&!t.contains(n)){const r=n.clone().expandBy(aV/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:no},inset:0})}}const Ba=20,cV=0,$e=200,ew={x:$e/2,y:$e/2},N$=10,lV={a1:new b($e*.5,$e*-.5-Ba),a2:new b($e*1.5+Ba,$e*.5),a3:new b($e*.5,$e*1.5+Ba),a4:new b($e*-.5-Ba,$e*.5)};function z$(e,n,t,r){return Object.fromEntries(Object.entries(lV).map(([o,s],i)=>{const a=s.clone();return i===0&&r?a.y-=r:i===2&&t&&(a.y+=t),[o,a.rot(n).add(e)]}))}function B$(e,n,t){const r=new Set(e.getSelectedShapeIds()),o=($e+Ba+t)**2,s=new Map,i=[];for(const l of e.getCurrentPageShapes()){if(!e.isShapeOfType(l,"note")||r.has(l.id))continue;const u=e.getShapePageTransform(l.id);n===u.rotation()&&(s.set(l,e.getShapePageBounds(l).center),i.push(...Object.values(z$(u.point(),n,l.props.growY,t))))}const a=i.length;let c;for(const[l,u]of s)for(let d=0;d<a;d++)c=i[d],c&&(b.Dist2(u,c)>o||e.isPointInShape(l,c)&&(i[d]=void 0));return ye(i)}function U$(e,n,t,r,o=!1){let s;const i=e.getCurrentPageShapesSorted(),a=$e+Ba**2;for(let c=i.length-1;c>=0;c--){const l=i[c];if(l.type==="note"&&l.id!==n.id){const u=e.getShapePageBounds(l);if(u&&b.Dist2(u.center,t)<a&&e.isPointInShape(l,t)){s=l;break}}}if(e.complete(),!s||o){e.mark("creating note shape");const c=Be();e.createShape({id:c,type:"note",x:t.x,y:t.y,rotation:r,opacity:n.opacity,props:{...n.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const l=e.getShape(c),u=e.getPointInParentSpace(l,b.Sub(t,b.Rot(ew,r)));e.updateShape({id:c,type:"note",x:u.x,y:u.y}),s=e.getShape(c)}return F$(e),s}var Ry;let uV=(Ry=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=Be();this.markId=`creating:${r}`,t.mark(this.markId);const o=this.editor.inputs.originPagePoint.clone(),s=TC(this.editor,o);s&&o.sub(s),this.shape=$C(this.editor,r,o)}});g(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=Be(),o=this.editor.inputs.originPagePoint.clone(),s=TC(this.editor,o);s&&o.sub(s),this.shape=$C(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(Ry,"id","pointing"),Ry);function TC(e,n){let t=N$/e.getZoomLevel(),r;for(const o of B$(e,0,0)){const s=b.Sub(n,o),i=s.len();i<t&&(t=i,r=s)}return r}function $C(e,n,t){e.createShape({id:n,type:"note",x:t.x,y:t.y}).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 Nh extends se{constructor(){super(...arguments);g(this,"shapeType","note")}}g(Nh,"id","note"),g(Nh,"initial","idle"),g(Nh,"children",()=>[iV,uV]);function dV(e){const n=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:Vo/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 Ja=aR(dV,32);var Ly;let hV=(Ly=class extends se{constructor(){super(...arguments);g(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Ja(this.editor)}});g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});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(Ly,"id","idle"),Ly);var Fy;let fV=(Fy=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=Be();if(this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:!1,w:20}}]),this.editor.select(o),this.shape=this.editor.getShape(o),!this.shape)return;const{shape:s}=this;this.editor.setCurrentTool("select.resizing",{...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=Be(),{x:r,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:t,type:"text",x:r,y:o,props:{text:"",autoSize:!0}}]).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)}},g(Fy,"id","pointing"),Fy);class zh extends se{constructor(){super(...arguments);g(this,"shapeType","text")}}g(zh,"id","text"),g(zh,"initial","idle"),g(zh,"children",()=>[hV,fV]);const pV=[zh,Dh,Rh,Nh,Fh,xv,Oh,Lh];function pc(e){return{key:`${po.id}:${e}`,getElement:async()=>{const n=gV(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await fetch(t)).blob(),s=await Ua.blobToDataUrl(o),i=r.replace(t,s);return h.jsx("style",{children:i})}}}function gV(e){const n=AE[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function tw(e){return{key:`${po.id}:${e}`,getElement:async()=>e!=="pattern"?null:h.jsx(mV,{})}}function mV(){const e=_r(),n=8/12;return h.jsxs(h.Fragment,{children:[h.jsxs("mask",{id:"hash_pattern_mask",children:[h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),h.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[h.jsx("line",{x1:n*1,y1:n*3,x2:n*3,y2:n*1}),h.jsx("line",{x1:n*5,y1:n*7,x2:n*7,y2:n*5}),h.jsx("line",{x1:n*9,y1:n*11,x2:n*11,y2:n*9})]})]}),h.jsx("pattern",{id:fp(1,e.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function nw(){return{key:`${po.id}:pattern`,component:xV}}const xl=8,MC=(e,n,t)=>new Promise((r,o)=>{const s=xl*n*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?wf.darkMode.solid:wf.lightMode.solid,a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*n*e;const c=8/12,l=u=>u*n*e;a.beginPath(),a.moveTo(l(c*1),l(c*3)),a.lineTo(l(c*3),l(c*1)),a.moveTo(l(c*5),l(c*7)),a.lineTo(l(c*7),l(c*5)),a.moveTo(l(c*9),l(c*11)),a.lineTo(l(c*11),l(c*9)),a.stroke(),i.toBlob(u=>{!u||Pt.throwToBlob.get()?o():r(u)})}),AC=(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 sy=null;function yV(){return sy||(sy={white:AC([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:AC([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),sy}function H$(e){return Math.ceil(Math.log2(Math.max(1,e)))}function fp(e,n){const t=H$(e);return`tldraw_hash_pattern_${n}_${t}`}function K$(e){const n=[],r=H$(e);for(let o=0;o<=r;o++)n.push(Math.pow(2,o));return n}function SV(e){const n=yV();return K$(e).flatMap(t=>[{zoom:t,url:n.white,theme:"light"},{zoom:t,url:n.black,theme:"dark"}])}function vV(){const e=B(),n=W("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),t=W("maxZoom",()=>Math.ceil(Nt(e.getCameraOptions().zoomSteps)),[e]),[r,o]=x.useState(!1),[s,i]=x.useState(()=>SV(t));return x.useEffect(()=>{const c=Promise.all(K$(t).flatMap(u=>[MC(n,u,!1).then(d=>({zoom:u,theme:"light",url:URL.createObjectURL(d)})),MC(n,u,!0).then(d=>({zoom:u,theme:"dark",url:URL.createObjectURL(d)}))]));let l=!1;return c.then(u=>{l||(i(u),o(!0))}),()=>{l=!0,o(!1),c.then(u=>{for(const{url:d}of u)URL.revokeObjectURL(d)})}},[n,t]),{defs:h.jsx(h.Fragment,{children:s.map(c=>{const l=fp(c.zoom,c.theme);return h.jsx("pattern",{id:l,width:xl,height:xl,patternUnits:"userSpaceOnUse",children:h.jsx("image",{href:c.url,width:xl,height:xl})},l)})}),isReady:r}}function xV(){const e=B(),n=x.useRef(null),{defs:t,isReady:r}=vV();return x.useEffect(()=>{if(r&&e.environment.isSafari){const o=W$(n.current);o&&requestAnimationFrame(()=>{o.style.display="none",requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),h.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function W$(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?W$(e.parentElement):null}function _r(){return ts({isDarkMode:Nu()})}const mt=Se.memo(function({theme:n,d:t,color:r,fill:o}){switch(o){case"none":return null;case"solid":return h.jsx("path",{fill:n[r].semi,d:t});case"semi":return h.jsx("path",{fill:n.solid,d:t});case"pattern":return h.jsx(wV,{theme:n,color:r,fill:o,d:t})}});function wV({d:e,color:n,theme:t}){const r=B(),o=u2(),s=W("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return h.jsxs(h.Fragment,{children:[h.jsx("path",{fill:t[n].pattern,d:e}),h.jsx("path",{fill:o?`url(#${fp(1,t.id)})`:i?t[n].semi:`url(#${fp(s,t.id)})`,d:e})]})}function bV(e){return e.replace(/\s/g," ")}function wv(e,n,t){const{padding:r=0}=t;if(n.length===0)return null;const o=J.From(n[0].box);for(const{box:l}of n)o.union(l);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 c=[];for(const{text:l,box:u}of n)a!==null&&u.y>a&&c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
148
- `},c.length)),c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:bV(l)},c.length)),a=u.y;return h.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:c})}function PV(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=J.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 CV(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function sg({fontSize:e,font:n,align:t,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:c=!0}){const l=B(),u=_r(),d={fontSize:e,fontFamily:AE[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},f=l.textMeasure.measureTextSpans(o,d),p=PV(t,a,f,i.width);p&&(d.offsetX=p),d.offsetX+=i.x,d.offsetY+=i.y;const y=wv(l,f,d);let m=null;return c&&(d.fill=u.background,d.stroke=u.background,d.strokeWidth=2,m=wv(l,f,d)),h.jsxs(h.Fragment,{children:[m,y]})}function eo(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:c="dashed"}=t;let l=0,u=0,d=1,f=0,p=0;switch(c){case"dashed":{d=1,l=Math.min(n*a,e/4);break}case"dotted":{d=100,l=n/d;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=l/2,p+=l/2):s==="skip"&&(e-=l,p-=l),i==="outset"?e+=l/2:i==="skip"&&(e-=l)),u=Math.floor(e/l/(2*d)),u-=u%o,u<3&&c==="dashed"?e/n<4?(l=e,u=1,f=0):(l=e*(1/3),f=e*(1/3)):(l=e/u/(2*d),r?(p=l/2,f=(e-u*l)/u):f=(e-u*l)/Math.max(1,u-1)),{strokeDasharray:[l,f].join(" "),strokeDashoffset:p.toString()}}const jC=new WeakMap;function rw(e,n){const t=jC.get(n);if(t)return t;const r=so(e,n);let o=0,s=0;const i=r.isStraight?new zo({start:b.From(r.start.point),end:b.From(r.end.point)}):new Oa({center:b.Cast(r.handleArc.center),start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(n.props.text.trim()){const c=i.bounds,{w:l,h:u}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:fo[n.props.font],fontSize:mi[n.props.size],maxWidth:null});if(o=l,s=u,c.width>c.height){o=Math.max(Math.min(l,64),Math.min(c.width-64,l));const{w:d,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:fo[n.props.font],fontSize:mi[n.props.size],maxWidth:o});o=d,s=f}if(o>16*mi[n.props.size]){o=16*mi[n.props.size];const{w:d,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:fo[n.props.font],fontSize:mi[n.props.size],maxWidth:o});o=d,s=f}}const a=new b(o,s).addScalar(CG*2);return jC.set(n,a),a}function G$(e,n){const t=At[n.props.size];return PG+(t-At.s)*2+(t===At.xl?20:0)}function IV(e,n,t){const r=rw(e,n),o=G$(e,n),s=b.Nudge(t.start.point,t.end.point,o),i=b.Nudge(t.end.point,t.start.point,o),a=wx(s,i,J.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[c,l]=a;b.Dist2(c,s)>b.Dist2(l,s)&&([l,c]=a);const u=s.add(b.Sub(t.middle,c)),d=i.add(b.Sub(t.middle,l)),f=b.Dist(t.start.point,u)/t.length,p=b.Dist(t.start.point,d)/t.length;return{start:f,end:p}}function EV(e,n,t){const r=rw(e,n),o=G$(e,n),s=Math.sign(n.props.bend),i=o/t.handleArc.radius*s,a=b.Angle(t.bodyArc.center,t.start.point)-i,c=b.Angle(t.bodyArc.center,t.end.point)+i,l=$i(t.bodyArc.center,t.bodyArc.radius,a),u=$i(t.bodyArc.center,t.bodyArc.radius,c),d=[],f=OC(t.bodyArc.center,t.bodyArc.radius,a,c,s,J.FromCenter(l,r).corners);d.push(new bt({points:J.FromCenter(l,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const p=OC(t.bodyArc.center,t.bodyArc.radius,a,c,s,J.FromCenter(u,r).corners);d.push(new bt({points:J.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const _ of[...f??[],...p??[],l,u])d.push(new Tx({x:_.x-3,y:_.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const y=(f&&DC(t.start.point,f))??t.middle,m=(p&&DC(t.end.point,p))??t.middle,w=b.Angle(t.bodyArc.center,t.start.point),S=b.Angle(t.bodyArc.center,t.end.point),v=b.Angle(t.bodyArc.center,y),P=b.Angle(t.bodyArc.center,m);if(ws(w,v,s)>ws(w,P,s))return{start:.5,end:.5,dbg:d};const E=ws(w,S,s),C=ws(w,v,s)/E,I=ws(w,P,s)/E;return{start:C,end:I,dbg:d}}function Bh(e,n){let t;const r=[],o=so(e,n),s=!!o.bindings.start,i=!!o.bindings.end,a=o.start.arrowhead!=="none",c=o.end.arrowhead!=="none";if(o.isStraight){const u=IV(e,n,o);let d=$t(n.props.labelPosition,a||s?u.start:0,c||i?u.end:1);d=d>=.48&&d<=.52?.5:d,t=b.Lrp(o.start.point,o.end.point,d)}else{const u=EV(e,n,o);u.dbg&&r.push(...u.dbg);let d=$t(n.props.labelPosition,a||s?u.start:0,c||i?u.end:1);d=d>=.48&&d<=.52?.5:d;const f=_V(b.Angle(o.bodyArc.center,o.start.point),b.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),d);t=$i(o.bodyArc.center,o.bodyArc.radius,f)}const l=rw(e,n);return{box:J.FromCenter(t,l),debugGeom:r}}function OC(e,n,t,r,o,s){const i=ev(e,n,s),a=ws(t,r,o);return i==null?void 0:i.filter(c=>{const l=ws(t,b.Angle(e,c),o);return l>=0&&l<=a})}function DC(e,n){let t=null,r=-1/0;for(const o of n){const s=b.Dist2(e,o);s>r&&(t=o,r=s)}return t}function _V(e,n,t,r){const o=ws(e,n,t);return e+o*r*t*-1}function kV(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?b.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,t*3),t);let a;if(e.isStraight)a=b.Nudge(r,o,i);else{const c=gz(r,i,e.handleArc.center,e.handleArc.radius);a=n==="end"?e.handleArc.sweepFlag?c[0]:c[1]:e.handleArc.sweepFlag?c[1]:c[0]}return b.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function TV({point:e,int:n}){const t=b.RotWith(n,e,ke/6),r=b.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function $V({point:e,int:n}){const t=b.RotWith(n,e,ke/6),r=b.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function MV({point:e,int:n}){const t=b.Sub(n,e).div(2),r=b.Add(e,b.Rot(t,Ve)),o=b.Sub(e,b.Rot(t,Ve));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function AV({point:e,int:n}){const t=b.Lrp(e,n,.45),r=b.Dist(t,e);return`M ${t.x-r},${t.y}
149
- a ${r},${r} 0 1,0 ${r*2},0
150
- a ${r},${r} 0 1,0 -${r*2},0 `}function jV({point:e,int:n}){const t=b.Lrp(e,n,.75),r=b.RotWith(t,e,ke/4),o=b.RotWith(t,e,-ke/4),s=b.Lrp(r,o,.5);return s.add(b.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function OV({int:e,point:n}){const t=b.Lrp(n,e,.85),r=b.Sub(t,n).div(2),o=b.Add(n,b.Rot(r,Ve)),s=b.Sub(n,b.Rot(r,Ve)),i=b.Add(t,b.Rot(r,Ve)),a=b.Sub(t,b.Rot(r,Ve));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function DV({int:e,point:n}){const t=b.Sub(e,n).div(2),r=b.Add(n,b.Rot(t,Ve)),o=b.Sub(n,b.Rot(t,Ve));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function pp(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=kV(e,n,t);if(o){switch(r){case"bar":return DV(o);case"square":return OV(o);case"diamond":return jV(o);case"dot":return AV(o);case"inverted":return MV(o);case"arrow":return TV(o);case"triangle":return $V(o)}return""}}function RV(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 V$(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 Y$(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function LV(e){return Y$(e.start.handle,e.end.handle)}function X$(e){return Y$(e.start.point,e.end.point)}const FV=x.forwardRef(function({isEditing:n,text:t,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:c},l){return h.jsx("textarea",{ref:l,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!n,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",datatype:"wysiwyg",defaultValue:t,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:Ht,onContextMenu:n?Ht:void 0,onPointerDown:a,onDoubleClick:c,onDragStart:_e})});function NV(e,n,t){const r=B(),o=x.useRef(null),s=W("isEditing",()=>r.getEditingShapeId()===e,[r]),i=W("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);x.useEffect(()=>{function u({shapeId:d}){var f;d===e&&((f=o.current)==null||f.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,e,s]),x.useEffect(()=>{var u,d,f,p;s&&(document.activeElement!==o.current&&((u=o.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((d=o.current)==null||d.select()),r.environment.isSafari&&((f=o.current)==null||f.blur(),(p=o.current)==null||p.focus()))},[r,s]);const a=x.useCallback(u=>{if(r.getEditingShapeId()===e)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&r.complete();break}}},[r,e]),c=x.useCallback(u=>{if(r.getEditingShapeId()!==e)return;let d=fc.normalizeText(u.currentTarget.value);const f=d.replace(/\t/g,za);if(f!==d){const p=u.currentTarget.selectionStart;u.currentTarget.value=f,u.currentTarget.selectionStart=p+(f.length-d.length),u.currentTarget.selectionEnd=p+(f.length-d.length),d=f}r.updateShape({id:e,type:n,props:{text:d}})},[r,e,n]),l=x.useCallback(u=>{r.dispatch({...Tn(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Ht(u)},[r,e]);return{rInput:o,handleFocus:RC,handleBlur:RC,handleKeyDown:a,handleChange:c,handleInputPointerDown:l,handleDoubleClick:Ht,isEmpty:t.trim().length===0,isEditing:s,isEditingAnything:i}}function RC(){}const ig=Se.memo(function({id:n,type:t,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:c,verticalAlign:l,wrap:u,isSelected:d,onKeyDown:f,classNamePrefix:p,style:y,textWidth:m,textHeight:w}){const{rInput:S,isEmpty:v,isEditing:P,isEditingAnything:E,...C}=NV(n,t,r),[I,_]=x.useState(r);x.useEffect(()=>{P||_(r)},[P,r]);const k=fc.normalizeTextForDom(r),$=k.length>0,T=CV(c);if(!P&&!$)return null;const O=p||"tl-text";return h.jsx("div",{className:`${O}-label tl-text-wrapper`,"data-font":s,"data-align":c,"data-hastext":!v,"data-isediting":P,"data-iseditinganything":E,"data-textwrap":!!u,"data-isselected":d,style:{justifyContent:c==="middle"||T?"center":c,alignItems:l==="middle"?"center":l,...y},children:h.jsxs("div",{className:`${O}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:i*a+"px",minHeight:a+32,minWidth:m||0,color:o,width:m,height:w},children:[h.jsx("div",{className:`${O} tl-text tl-text-content`,dir:"auto",children:k.split(`
151
- `).map((N,A)=>h.jsx("div",{dir:"auto",children:N},A))}),(E||d)&&h.jsx(FV,{ref:S,text:r,isEditing:P,...C,handleKeyDown:f??C.handleKeyDown},I)]})})}),zV=x.memo(function({id:n,text:t,size:r,font:o,position:s,width:i,isSelected:a,labelColor:c}){const l=_r();return h.jsx(ig,{id:n,classNamePrefix:"tl-arrow",type:"arrow",font:o,fontSize:mi[r],lineHeight:Wt.lineHeight,align:"middle",verticalAlign:"middle",text:t,labelColor:l[c].solid,textWidth:i,isSelected:a,style:{transform:`translate(${s.x}px, ${s.y}px)`}})});let BV=0;class Uh extends Br{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=_n(this.editor,t);return!r.start&&!r.end});g(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const s=r.id,i=_n(this.editor,t);if(s==="middle"){const{start:I,end:_}=La(this.editor,t,i),k=b.Sub(_,I),$=b.Per(k),T=b.Med(_,I),O=b.Sub(T,$),N=b.Add(T,$),A=b.NearestPointOnLineSegment(O,N,r,!1);let j=b.Dist(A,T);return b.Clockwise(A,_,T)&&(j*=-1),{id:t.id,type:t.type,props:{bend:j}}}const a={id:t.id,type:"arrow",props:{}},c=i[s],u=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return Ah(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const d=this.editor.getShapePageTransform(t.id).applyToPoint(r),f=this.editor.getShapeAtPoint(d,{hitInside:!0,hitFrameInside:!0,margin:0,filter:I=>!I.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:I,binding:"arrow"})});if(!f)return Ah(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const p=this.editor.getShapeGeometry(f),y=J.ZeroFix(p.bounds),w=this.editor.getShapePageTransform(a.id).applyToPoint(r),S=this.editor.getPointInShapeSpace(f,w);let v=o;v||(!c||c&&f.id!==c.toId)&&(v=this.editor.inputs.pointerVelocity.len()<.5),o||(p.isClosed||(v=!0),u&&f.id===u.toId&&u.props.isPrecise&&(v=!0));const P={x:(S.x-y.minX)/y.width,y:(S.y-y.minY)/y.height};v&&b.Dist(S,y.center)<Math.max(4,Math.min(Math.min(y.width,y.height)*.15,16))/this.editor.getZoomLevel()&&(P.x=.5,P.y=.5);const E={terminal:s,normalizedAnchor:P,isPrecise:v,isExact:this.editor.inputs.altKey};ol(this.editor,t,f.id,E),this.editor.setHintingShapes([f.id]);const C=_n(this.editor,t);return C.start&&C.end&&C.start.toId===C.end.toId&&b.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&ol(this.editor,t,C.end.toId,{...C.end.props,normalizedAnchor:{x:C.end.props.normalizedAnchor.x+.05,y:C.end.props.normalizedAnchor.y}}),a});g(this,"onTranslateStart",t=>{const r=_n(this.editor,t),o=La(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)))){FC.set(t,{pagePosition:s.applyToPoint(t),terminalBindings:Iu(o,(a,c)=>{const l=r[a];return l?{binding:l,shapePosition:c,pagePosition:s.applyToPoint(c)}:null})});for(const a of["start","end"]){const c=r[a];c&&this.editor.updateBinding({...c,props:{...c.props,isPrecise:!0}})}}});g(this,"onTranslate",(t,r)=>{const o=FC.get(t);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=b.Sub(s.applyToPoint(r),o.pagePosition);for(const a of Object.values(o.terminalBindings)){if(!a)continue;const c=b.Add(a.pagePosition,b.Mul(i,.5)),l=this.editor.getShapeAtPoint(c,{hitInside:!0,hitFrameInside:!0,margin:0,filter:u=>!u.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:u,binding:"arrow"})});if((l==null?void 0:l.id)===a.binding.toId){const u=J.ZeroFix(this.editor.getShapeGeometry(l).bounds),d=this.editor.getPointInShapeSpace(l,c),f={x:(d.x-u.minX)/u.width,y:(d.y-u.minY)/u.height};ol(this.editor,r,l.id,{...a.binding.props,normalizedAnchor:f,isPrecise:!0})}else Ah(this.editor,r,a.binding.props.terminal)}});g(this,"_resizeInitialBindings",new _i);g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(t,()=>_n(this.editor,t)),a=La(this.editor,t,i),{start:c,end:l}=xt(t.props);let{bend:u}=t.props;i.start||(c.x=a.start.x*o,c.y=a.start.y*s),i.end||(l.x=a.end.x*o,l.y=a.end.y*s);const d=Math.abs(o),f=Math.abs(s),p=i!=null&&i.start?b.From(i.start.props.normalizedAnchor):null,y=i!=null&&i.end?b.From(i.end.props.normalizedAnchor):null;return o<0&&s>=0?(u!==0&&(u*=-1,u*=Math.max(d,f)),p&&(p.x=1-p.x),y&&(y.x=1-y.x)):o>=0&&s<0?(u!==0&&(u*=-1,u*=Math.max(d,f)),p&&(p.y=1-p.y),y&&(y.y=1-y.y)):o>=0&&s>=0?u!==0&&(u*=Math.max(d,f)):o<0&&s<0&&(u!==0&&(u*=Math.max(d,f)),p&&(p.x=1-p.x,p.y=1-p.y),y&&(y.x=1-y.x,y.y=1-y.y)),i.start&&p&&ol(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:p.toJson()}),i.end&&y&&ol(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:y.toJson()}),{props:{start:c,end:l,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"}}getGeometry(t){const r=so(this.editor,t),o=[],s=r.isStraight?new zo({start:b.From(r.start.point),end:b.From(r.end.point)}):new Oa({center:b.Cast(r.handleArc.center),start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(t.props.text.trim()){const a=Bh(this.editor,t);o.push(...a.debugGeom),i=new Qo({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Hr({children:[...i?[s,i]:[s],...o]})}getHandles(t){const r=so(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=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,s=so(this.editor,t);if(!(s!=null&&s.isValid))return null;const i=Bh(this.editor,t),a=t.id===this.editor.getOnlySelectedShapeId(),l=this.editor.getEditingShapeId()===t.id||t.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(Ks,{id:t.id,style:{minWidth:50,minHeight:50},children:h.jsx(LC,{shape:t,shouldDisplayHandles:o&&r===t})}),l&&h.jsx(zV,{id:t.id,text:t.props.text,font:t.props.font,size:t.props.size,position:i.box.center,width:i.box.w,isSelected:a,labelColor:t.props.labelColor})]})}indicator(t){const r=Zp(t.id),o=so(this.editor,t);if(!o)return null;const{start:s,end:i}=La(this.editor,t,o==null?void 0:o.bindings),a=this.editor.getShapeGeometry(t),c=a.bounds,l=t.props.text.trim()?a.children[1]:null;if(b.Equals(s,i))return null;const u=At[t.props.size],d=o.start.arrowhead&&pp(o,"start",u),f=o.end.arrowhead&&pp(o,"end",u),p=o.isStraight?X$(o):V$(o),y=d&&o.start.arrowhead!=="arrow"||f&&o.end.arrowhead!=="arrow"||!!l,m=(t.id+"_clip").replace(":","_");return r&&l?h.jsx("rect",{x:F(l.x),y:F(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5}):h.jsxs("g",{children:[y&&h.jsx("defs",{children:h.jsxs("mask",{id:m,children:[h.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.w+200,height:c.h+200,fill:"white"}),l&&h.jsx("rect",{x:F(l.x),y:F(l.y),width:l.w,height:l.h,fill:"black",rx:3.5,ry:3.5}),d&&h.jsx("path",{d,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),f&&h.jsx("path",{d:f,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{...y?{mask:`url(#${m})`}:void 0,children:[y&&h.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),h.jsx("path",{d:p})]}),d&&h.jsx("path",{d}),f&&h.jsx("path",{d:f}),l&&h.jsx("rect",{x:F(l.x),y:F(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5})]})}toSvg(t,r){r.addExportDef(tw(t.props.fill)),t.props.text&&r.addExportDef(pc(t.props.font));const o=ts(r);return h.jsxs(h.Fragment,{children:[h.jsx(LC,{shape:t,shouldDisplayHandles:!1}),h.jsx(sg,{fontSize:mi[t.props.size],font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:o[t.props.labelColor].solid,bounds:Bh(this.editor,t).box,padding:4})]})}getCanvasSvgDefs(){return[nw(),{key:"arrow:dot",component:HV},{key:"arrow:cross",component:KV}]}}g(Uh,"type","arrow"),g(Uh,"props",OE),g(Uh,"migrations",DE);function UV(e,n){const t=so(e,n);return t.isStraight?b.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const LC=ir(function({shape:n,shouldDisplayHandles:t}){const r=B(),o=_r(),s=so(r,n),i=J.ZeroFix(r.getShapeGeometry(n).bounds),a=_n(r,n),c=Se.useMemo(()=>r.environment.isSafari?BV+=1:0,[n]);if(!(s!=null&&s.isValid))return null;const l=At[n.props.size],u=s.start.arrowhead&&pp(s,"start",l),d=s.end.arrowhead&&pp(s,"end",l),f=s.isStraight?X$(s):V$(s);let p=null;if(t){const{strokeDasharray:C,strokeDashoffset:I}=eo(UV(r,n),2,{end:"skip",start:"skip",lengthRatio:2.5});p=a.start||a.end?h.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?LV(s):RV(s),strokeDasharray:C,strokeDashoffset:I,strokeWidth:2,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}=eo(s.isStraight?s.length:Math.abs(s.bodyArc.length),l,{style:n.props.dash}),w=Bh(r,n),S=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),v=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),P=(n.id+"_clip_"+c).replace(":","_");return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsxs("mask",{id:P,children:[h.jsx("rect",{x:F(-100+i.minX),y:F(-100+i.minY),width:F(i.width+200),height:F(i.height+200),fill:"white"}),n.props.text.trim()&&h.jsx("rect",{x:w.box.x,y:w.box.y,width:w.box.w,height:w.box.h,fill:"black",rx:4,ry:4}),u&&S&&h.jsx("path",{d:u,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),d&&v&&h.jsx("path",{d,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{fill:"none",stroke:o[n.props.color].solid,strokeWidth:l,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[p,h.jsxs("g",{mask:`url(#${P})`,children:[h.jsx("rect",{x:F(i.minX-100),y:F(i.minY-100),width:F(i.width+200),height:F(i.height+200),opacity:0}),h.jsx("path",{d:f,strokeDasharray:y,strokeDashoffset:m})]}),u&&S&&n.props.fill!=="none"&&h.jsx(mt,{theme:o,d:u,color:n.props.color,fill:n.props.fill}),d&&v&&n.props.fill!=="none"&&h.jsx(mt,{theme:o,d,color:n.props.color,fill:n.props.fill}),u&&h.jsx("path",{d:u}),d&&h.jsx("path",{d})]})]})}),FC=new WeakMap;function HV(){return h.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:h.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function KV(){return h.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[h.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),h.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const NC="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 gc({url:e,zoomLevel:n}){return h.jsx("a",{className:ue("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:h.jsx("div",{className:"tl-hyperlink-button__icon",style:{mask:`url("${NC}") center 100% / 100% no-repeat`,WebkitMask:`url("${NC}") center 100% / 100% no-repeat`}})})}const WV=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function ow(e){return WV.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,c=new b(r,o),{x:l,y:u}=c.rot(-e);return`${l}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}class Hh extends _c{constructor(){super(...arguments);g(this,"canResize",()=>!1);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"onBeforeCreate",t=>{zC(this.editor,t)});g(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(rr.isValid(r.props.url))zC(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}}})}getDefaultProps(){return{url:"",w:300,h:320,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),s=GV(t);return h.jsx(Li,{children:h.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:ow(o)},children:[h.jsxs("div",{className:"tl-bookmark__image_container",children:[r!=null&&r.props.image?h.jsx("img",{className:"tl-bookmark__image",draggable:!1,src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):h.jsx("div",{className:"tl-bookmark__placeholder"}),h.jsx(gc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),h.jsxs("div",{className:"tl-bookmark__copy_container",children:[(r==null?void 0:r.props.title)&&h.jsx("h2",{className:"tl-bookmark__heading",children:Ll((r==null?void 0:r.props.title)||"",54)}),(r==null?void 0:r.props.description)&&h.jsx("p",{className:"tl-bookmark__description",children:Ll((r==null?void 0:r.props.description)||"",128)}),h.jsx("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ht,onPointerUp:Ht,onClick:Ht,children:Ll(s,45)})]})]})})}indicator(t){return h.jsx("rect",{width:F(t.props.w),height:F(t.props.h),rx:"6",ry:"6"})}}g(Hh,"type","bookmark"),g(Hh,"props",zE),g(Hh,"migrations",BE);const GV=e=>{try{const n=new URL(e.props.url),t=n.pathname.replace(/\/*$/,"");return`${n.hostname}${t}`}catch{return e.props.url}};function zC(e,n){const{url:t}=n.props,r=yi.createId(Vy(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}}]),VV(e,n))}const VV=cE(async(e,n)=>{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 Fi(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${Ee(r)}L${Ee(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=In(r,o);return n?`M${In(e[0].point,e[1].point)}Q${Ee(e[1].point)}${In(e[1].point,e[2].point)}T${s}${In(e[t-1].point,e[0].point)}${In(e[0].point,e[1].point)}Z`:`M${Ee(e[0].point)}Q${Ee(e[1].point)}${In(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Ee(e[t-1].point)}`}function YV(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=mo(e,n);og(i,n);const a=XV(i);let c="";for(const l of a)c+=ZV(l,n);return c}function XV(e){if(e.length<=2)return[e];const n=[];let t=[e[0]],r=b.Sub(e[1].point,e[0].point).uni(),o,s,i,a,c;for(let l=1,u=e.length;l<u-1;l++){if(i=e[l-1],a=e[l],c=e[l+1],o=b.Sub(c.point,a.point).uni(),s=b.Dpr(r,o),r=o,s<-.8){const d={...a,point:a.input};t.push(d),n.push(iy(t)),t=[d];continue}if(t.push(a),!(s>.7)&&(b.Dist2(i.point,a.point)+b.Dist2(a.point,c.point))/((i.radius+a.radius+c.radius)/3)**2<1.5){t.push(a),n.push(iy(t)),t=[a];continue}}return t.push(e[e.length-1]),n.push(iy(t)),n}function iy(e){const n=e[0];let t;for(;e.length>2&&(t=e[1],b.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],b.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:b.Sub(e[0].point,e[1].point).uni()},e[e.length-1]={...e[e.length-1],vector:b.Sub(e[e.length-2].point,e[e.length-1].point).uni()}),e}function qV(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 ZV(e,n={}){if(e.length===0)return"";if(e.length===1)return qV(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=E$(e,n);r.reverse();let o=`M${Ee(t[0])}T`;for(let s=1;s<t.length;s++)o+=In(t[s-1],t[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),c=b.Add(s.point,b.Mul(a,i)),l=b.Add(s.point,b.Mul(a,-i));o+=`${Ee(c)}A${F(i)},${F(i)} 0 0 1 ${Ee(l)}T`}for(let s=1;s<r.length;s++)o+=In(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),c=b.Add(s.point,b.Mul(a,i)),l=b.Add(s.point,b.Mul(a,-i));o+=`${Ee(c)}A${F(i)},${F(i)} 0 0 1 ${Ee(l)}Z`}return o}function du(){const e=B();return W("zoom",()=>e.getZoomLevel()<.35,[e])}const QV=e=>e*.65+iL(e*ke/2)*.35,JV=e=>({size:1+e,thinning:.5,streamline:.62+(1+e)/8*.06,smoothing:.62,easing:an.easeOutSine,simulatePressure:!0}),eY=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:QV}),BC=e=>({size:1+e,thinning:0,streamline:.62+(1+e)/8*.06,smoothing:.62,simulatePressure:!1,easing:an.linear});function bv({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:an.easeOutSine,last:n}}function Pv(e,n,t,r){return{...r?BC(n):e.dash==="draw"?e.isPen?eY(n):JV(n):BC(n),last:e.isComplete||t}}function hu(e){const n=[];for(const t of e)if(t.type==="free"||t.points.length<2)n.push(...t.points.map(b.Cast));else{const r=Math.max(4,Math.floor(b.Dist(t.points[0],t.points[1])/16));n.push(...b.PointsBetween(t.points[0],t.points[1],r))}return n}function tY(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class Kh extends Br{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>ay(t));g(this,"hideRotateHandle",t=>ay(t));g(this,"hideSelectionBoundsFg",t=>ay(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:c,y:l,z:u})=>({x:oc(o*c),y:oc(s*l),z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1}}getGeometry(t){const r=hu(t.props.segments),o=At[t.props.size];if(t.props.segments.length===1){const i=J.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new Tx({x:-o,y:-o,radius:o,isFilled:!0})}const s=mo(r,Pv(t.props,o,!0,!0)).map(i=>i.point);return t.props.isClosed?new bt({points:s,isFilled:t.props.fill!=="none"}):new Ec({points:s})}component(t){return h.jsx(Ks,{id:t.id,children:h.jsx(UC,{shape:t,forceSolid:du()})})}indicator(t){var d;const r=du(),o=At[t.props.size],s=hu(t.props.segments);let i=o;!r&&!t.props.isPen&&t.props.dash==="draw"&&s.length===1&&(i+=Gr(t.id)()*(o/6));const a=t.props.isComplete||((d=Nt(t.props.segments))==null?void 0:d.type)==="straight",c=Pv(t.props,i,a,!0),l=mo(s,c),u=l.length>1?Fi(l,t.props.isClosed):q$(s[0],i);return h.jsx("path",{d:u})}toSvg(t,r){return r.addExportDef(tw(t.props.fill)),h.jsx(UC,{shape:t,forceSolid:!1})}getCanvasSvgDefs(){return[nw()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return At[t.props.size]*r/2}}g(Kh,"type","draw"),g(Kh,"props",HE),g(Kh,"migrations",KE);function q$(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 ay(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function UC({shape:e,forceSolid:n}){var d;const t=_r(),r=At[e.props.size],o=hu(e.props.segments),s=e.props.isComplete||((d=Nt(e.props.segments))==null?void 0:d.type)==="straight";let i=r;!n&&!e.props.isPen&&e.props.dash==="draw"&&o.length===1&&(i+=Gr(e.id)()*(r/6));const a=Pv(e.props,i,s,n);if(!n&&e.props.dash==="draw")return h.jsxs(h.Fragment,{children:[e.props.isClosed&&e.props.fill&&o.length>1?h.jsx(mt,{theme:t,fill:e.props.isClosed?e.props.fill:"none",color:e.props.color,d:Fi(mo(o,a),e.props.isClosed)}):null,h.jsx("path",{d:YV(o,a),strokeLinecap:"round",fill:t[e.props.color].solid})]});const c=mo(o,a),l=c.length<2,u=l?q$(o[0],0):Fi(c,e.props.isClosed);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,color:e.props.color,fill:l||e.props.isClosed?e.props.fill:"none",d:u}),h.jsx("path",{d:u,strokeLinecap:"round",fill:l?t[e.props.color].solid:"none",stroke:t[e.props.color].solid,strokeWidth:r,strokeDasharray:l?"none":tY(e,r),strokeDashoffset:"0"})]})}function nY(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:u=1/0}=t;let d=e.props.w*s,f=e.props.h*i;const p=new b(0,0);if(d>0){if(d<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=d-a;break}case"top":case"bottom":{p.x=(d-a)/2;break}default:p.x=0}d=a}}else if(p.x=d,d=-d,d<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=-d;break}default:p.x=-a}d=a}if(f>0){if(f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=f-l;break}case"right":case"left":{p.y=(f-l)/2;break}default:p.y=0}f=l}}else if(p.y=f,f=-f,f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-l}f=l}const{x:y,y:m}=p.rot(e.rotation).add(r);return{x:y,y:m,props:{w:Math.min(c,d),h:Math.min(u,f)}}}const rY=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class Wh extends _c{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",t=>!this.canResize(t));g(this,"canEdit",()=>!0);g(this,"canResize",t=>{var r,o;return!!((o=(r=ks(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});g(this,"canEditInReadOnly",()=>!0);g(this,"isAspectRatioLocked",t=>{const r=ks(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});g(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=ks(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 c=t.props.w/t.props.h;c>1?i*=c:a/=c}return nY(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=Zp(t.id),a=x.useMemo(()=>j$(s),[s]),c=W("is hovering",()=>{const{editingShapeId:p,hoveredShapeId:y}=this.editor.getCurrentPageState();if(p&&y!==p){const m=this.editor.getShape(p);if(m&&this.editor.isShapeOfType(m,"embed"))return!0}return!1},[]),l=this.editor.getShapePageTransform(t).rotation(),u=i||c;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 p=a.url.split("/").pop();if(!p)throw Error("No gist id!");return h.jsx(Li,{className:"tl-embed-container",id:t.id,children:h.jsx(oY,{id:p,width:F(r),height:F(o),isInteractive:u,pageRotation:l})})}const f=rY({...G3,...(a==null?void 0:a.definition.overridePermissions)??{}});return h.jsx(Li,{className:"tl-embed-container",id:t.id,children:a!=null&&a.definition?h.jsx("iframe",{className:"tl-embed",sandbox:f,src:a.embedUrl,width:F(r),height:F(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:ow(l),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(t){const r=x.useMemo(()=>ks(t.props.url),[t.props.url]);return h.jsx("rect",{width:F(t.props.w),height:F(t.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}g(Wh,"type","embed"),g(Wh,"props",WE),g(Wh,"migrations",GE);function oY({id:e,file:n,isInteractive:t,width:r,height:o,style:s,pageRotation:i}){return h.jsx("iframe",{className:"tl-embed",draggable:!1,width:F(r),height:F(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:t?"all":"none",zIndex:t?"":"-1",boxShadow:ow(i)},srcDoc:`
152
- <html>
153
- <head>
154
- <base target="_blank">
155
- </head>
156
- <body>
157
- <script src=${`https://gist.github.com/${e}.js${n?`?file=${n}`:""}`}><\/script>
158
- <style type="text/css">
159
- * { margin: 0px; }
160
- table { height: 100%; background-color: red; }
161
- .gist { background-color: none; height: 100%; }
162
- .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
163
- </style>
164
- </body>
165
- </html>`})}const sY=x.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=B(),s=x.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(Ht(c),c.currentTarget.blur(),o.setEditingShape(null))},[o]),i=x.useCallback(c=>{const l=o.getShape(e);if(!l)return;const u=l.props.name,d=c.currentTarget.value.trim();u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}])},[e,o]),a=x.useCallback(c=>{const l=o.getShape(e);if(!l)return;const u=l.props.name,d=c.currentTarget.value;u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}])},[e,o]);return h.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[h.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}),Z$(n,"Frame")+"​"]})}),iY=function({id:n,name:t,width:r,height:o}){const s=B(),i=W("shape rotation",()=>Ms(s.getShapePageTransform(n).rotation()),[s,n]),a=Zp(n),c=x.useRef(null),l=x.useCallback(y=>{const m=Tn(y);s.getEditingShapeId()!==n&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...m}),y.preventDefault())},[s,n]);x.useEffect(()=>{const y=c.current;y&&a&&(y.focus(),y.select())},[c,a]);const d=((i+Math.PI/4)*(2/Math.PI)+4)%4,f=["top","left","bottom","right"][Math.floor(d)];let p;switch(f){case"top":p="";break;case"right":p=`translate(${F(r)}px, 0px) rotate(90deg)`;break;case"bottom":p=`translate(${F(r)}px, ${F(o)}px) rotate(180deg)`;break;case"left":p=`translate(0px, ${F(o)}px) rotate(270deg)`;break}return h.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(f==="top"||f==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${p} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:l,children:h.jsx("div",{className:"tl-frame-heading-hit-area",children:h.jsx(sY,{ref:c,id:n,name:t,isEditing:a})})})};function Z$(e,n){return e.match(/^\s*$/)?n:e}class Gh extends _c{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)=>C2(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new Qo({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=_r(),s=W("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 h.jsxs(h.Fragment,{children:[h.jsx(Ks,{children:h.jsx("rect",{className:ue("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:h.jsx(iY,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t,r){const o=ts({isDarkMode:r.isDarkMode}),a=((Ms(this.editor.getShapePageTransform(t.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,c=Math.floor(a);let l;switch(c){case 0:l="";break;case 3:l=`translate(${F(t.props.w)}, 0) rotate(90)`;break;case 2:l=`translate(${F(t.props.w)}, ${F(t.props.h)}) rotate(180)`;break;case 1:l=`translate(0, ${F(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"},d=this.editor.textMeasure.measureTextSpans(Z$(t.props.name,"Frame")+"​",u),f=d[0],p=Nt(d),y=p.box.w+p.box.x-f.box.x,m=wv(this.editor,d,{offsetY:-u.height-2,...u});return h.jsxs(h.Fragment,{children:[h.jsx("rect",{width:t.props.w,height:t.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),h.jsxs("g",{transform:l,children:[h.jsx("rect",{x:-8,y:-u.height-4,width:y+16,height:u.height,fill:o.background,rx:4,ry:4}),m]})]})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return h.jsx("rect",{width:F(r.width),height:F(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}g(Gh,"type","frame"),g(Gh,"props",VE),g(Gh,"migrations",YE);function HC(e,n){return e>n?(ke*(n/2)+(e-n))*2:(ke*(e/2)+(n-e))*2}function Q$(e,n){return sw(e,n).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function aY(e,n,t,r){const o=e/4,s=n/4,i=Gr(r),a=t*.75,c=v=>v.addXY(i()*a,i()*a),l=new b(e/2,n),u=new b(0,s*1.2),d=new b(e/2,s*.9),f=new b(e,s*1.2),p=c(new b(e/2,n)),y=c(new b(0,s*1.2)),m=c(new b(e/2,s*.9)),w=c(new b(e,s*1.2));return[new Jt({start:l,cp1:new b(o*1.5,s*3),cp2:new b(0,s*2.5),end:u}),new Jt({start:u,cp1:new b(0,-s*.32),cp2:new b(o*1.85,-s*.32),end:d}),new Jt({start:d,cp1:new b(o*2.15,-s*.32),cp2:new b(e,-s*.32),end:f}),new Jt({start:f,cp1:new b(e,s*2.5),cp2:new b(o*2.5,s*3),end:p}),new Jt({start:p,cp1:new b(o*1.5,s*3),cp2:new b(0,s*2.5),end:y}),new Jt({start:y,cp1:new b(0,-s*.32),cp2:new b(o*1.85,-s*.32),end:m}),new Jt({start:m,cp1:new b(o*2.15,-s*.32),cp2:new b(e,-s*.32),end:w}),new Jt({start:w,cp1:new b(e,s*2.5),cp2:new b(o*2.5,s*3),end:l})].map((v,P)=>v.getSvgPathData(P===0)).join(" ")+" Z"}function sw(e,n){const t=e/4,r=n/4;return[new Jt({start:new b(e/2,n),cp1:new b(t*1.5,r*3),cp2:new b(0,r*2.5),end:new b(0,r*1.2)}),new Jt({start:new b(0,r*1.2),cp1:new b(0,-r*.32),cp2:new b(t*1.85,-r*.32),end:new b(e/2,r*.9)}),new Jt({start:new b(e/2,r*.9),cp1:new b(t*2.15,-r*.32),cp2:new b(e,-r*.32),end:new b(e,r*1.2)}),new Jt({start:new b(e,r*1.2),cp1:new b(e,r*2.5),cp2:new b(t*2.5,r*3),end:new b(e/2,n)})]}function cY(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function lY(e,n,t,r){const o=Gr(e),s=n/2,i=t/2,a=f_(s,i),c=[],l=Re*o(),u=Re+Ve/2+Math.abs(o())*Ve,d=Math.max(16,a/10);for(let f=0;f<d;f++){const p=f/(d-1),y=l+p*u,m=Math.cos(y),w=Math.sin(y);c.push(new b(s*m+n*.5+.05*o(),i*w+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?an.easeInOutSine(p):an.easeInExpo(p)))/2)))}return mo(c,cY(r))}function uY(e,n,t,r){return Fi(lY(e,n,t,r))}function Cv(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+=`${Ee(r)}L${Ee(o)}Q${Ee(s)}`;return n+=`${Ee(e[0])}`,n}function Iv(e,n,t,r,o){const s=[],i=Gr(e);let a=n[0],c;const l=n.length;for(let u=0,d=l*o;u<d;u++){c=b.AddXY(n[(u+1)%l],i()*t,i()*t);const f=b.Sub(c,a),p=b.Len(f),y=b.Div(f,p).mul(Math.min(p/4,r));s.push(b.Add(a,y),b.Add(c,y.neg()),c),a=c}return s}function dY(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 b(r,0),delta:new b(1,0)},{type:"arc",center:new b(e-r,r),startAngle:-ke/2},{type:"straight",start:new b(e-r,n),delta:new b(-1,0)},{type:"arc",center:new b(r,r),startAngle:ke/2}]:[{type:"straight",start:new b(e,r),delta:new b(0,1)},{type:"arc",center:new b(r,n-r),startAngle:0},{type:"straight",start:new b(0,n-r),delta:new b(0,-1)},{type:"arc",center:new b(r,r),startAngle:ke}];let c=0;const l=[];for(let u=0;u<t;u++){const d=a[0];d.type==="straight"?l.push(b.Add(d.start,b.Mul(d.delta,c))):l.push($i(d.center,r,d.startAngle+c/r)),c+=i;let f=d.type==="straight"?o:ke*r;for(;c>f;)c-=f,a.push(a.shift()),f=a[0].type==="straight"?o:ke*r}return l}const hY={s:50,m:70,l:100,xl:130},fY=.2;function ag(e,n,t,r){const o=Gr(t),s=HC(e,n),i=Math.max(Math.ceil(s/hY[r]),6,Math.ceil(s/Math.min(e,n))),a=s/i*fY,c=Math.max(e-a*2,1),l=Math.max(n-a*2,1),d=HC(c,l)/i,f=(e-c)/2,p=(n-l)/2,y=dY(c,l,i).map(P=>P.addXY(f,p)),m=e<20?0:a*.3,w=n<20?0:a*.3,S=y.slice(0);for(let P=0;P<Math.floor(i/2);P++)S[P]=b.AddXY(S[P],o()*m,o()*w),S[i-P-1]=b.AddXY(S[i-P-1],o()*m,o()*w);const v=[];for(let P=0;P<S.length;P++){const E=P===S.length-1?0:P+1,C=S[P],I=S[E],_=y[P],k=y[E],$=b.Dist(_,k),T=d-$,N=b.Dist(C,I)/$,A=(Math.max(f,p)+T)*N,j=b.Lrp(_,k,.5).add(b.Sub(k,_).uni().per().mul(A));j.x<0?j.x=0:j.x>e&&(j.x=e),j.y<0?j.y=0:j.y>n&&(j.y=n);const L=v0(C,I,j),X=b.Dist(L||b.Average([C,I]),C);v.push({leftPoint:C,rightPoint:I,arcPoint:j,center:L,radius:X})}return v}function pY(e,n,t,r){const o=[],s=ag(e,n,t,r);for(const{center:i,radius:a,leftPoint:c,rightPoint:l}of s)o.push(...uL(c,l,i,a,10));return o}function Ev(e,n,t,r){const o=ag(e,n,t,r);let s=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:i,rightPoint:a,radius:c,center:l}of o){if(l===null){s+=` L${a.toFixed()}`;continue}const u=b.Clockwise(i,a,l)?"0":"1";s+=` A${F(c)},${F(c)} 0 ${u},1 ${a.toFixed()}`}return s+=" Z",s}const gY={s:.5,m:.7,l:.9,xl:1.6};function mY(e,n,t,r){const o=Gr(t),s=gY[r],i=ag(e,n,t,r),l=i.reduce((p,y)=>p+b.Dist2(y.leftPoint,y.rightPoint),0)/i.length>(s*15)**2?p=>p.addXY(o()*s*2,o()*s*2):p=>p;let u=`M${i[0].leftPoint.toFixed()}`,d=l(i[0].leftPoint),f=`M${d.toFixed()}`;for(const{leftPoint:p,center:y,rightPoint:m,radius:w,arcPoint:S}of i){if(y===null){u+=` L${m.toFixed()}`;const _=l(m);f+=` L${_.toFixed()}`,d=_;continue}const v=b.Clockwise(p,m,y)?"0":"1";u+=` A${F(w)},${F(w)} 0 ${v},1 ${m.toFixed()}`;const P=l(m),E=l(S),C=v0(d,P,E);if(!Number.isFinite(C.x)||!Number.isFinite(C.y)){f+=` L${P.toFixed()}`,d=P;continue}const I=Math.abs(b.Dist(C,d));f+=` A${F(I)},${F(I)} 0 ${v},1 ${P.toFixed()}`,d=P}return u+f+" Z"}function _v(e,n){switch(e.geo){case"x-box":return yY(e.w,e.h,n,e.dash);case"check-box":return SY(e.w,e.h);default:return}}function yY(e,n,t,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new b(0,0),new b(e/2,n/2)],[new b(e,n),new b(e/2,n/2)],[new b(0,n),new b(e/2,n/2)],[new b(e,0),new b(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 b(s(t*o),i(t*o)),new b(s(e-t*o),i(n-t*o))],[new b(s(t*o),i(n-t*o)),new b(s(e-t*o),i(t*o))]]}function SY(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 b(s(r+t*.25),i(o+t*.52)),new b(s(r+t*.45),i(o+t*.82))],[new b(s(r+t*.45),i(o+t*.82)),new b(s(r+t*.82),i(o+t*.22))]]}function KC({shape:e}){const n=B(),t=_r(),{id:r,props:o}=e,{w:s,color:i,fill:a,dash:c,growY:l,size:u}=o,d=At[u],f=o.h+l;switch(o.geo){case"cloud":if(c==="solid"){const p=Ev(s,f,r,u);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:i,fill:a}),h.jsx("path",{d:p,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}else if(c==="draw"){const p=mY(s,f,r,u);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:i,fill:a}),h.jsx("path",{d:p,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}else{const p=Ev(s,f,r,u),y=ag(s,f,r,u);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:i,fill:a}),h.jsx("g",{strokeWidth:d,stroke:t[i].solid,fill:"none",pointerEvents:"all",children:y.map(({leftPoint:m,rightPoint:w,center:S,radius:v},P)=>{const E=S?v*Ms(Ms(b.Angle(S,w))-Ms(b.Angle(S,m))):b.Dist(m,w),{strokeDasharray:C,strokeDashoffset:I}=eo(E,d,{style:c,start:"outset",end:"outset"});return h.jsx("path",{d:S?`M${m.x},${m.y}A${v},${v},0,0,1,${w.x},${w.y}`:`M${m.x},${m.y}L${w.x},${w.y}`,strokeDasharray:C,strokeDashoffset:I},P)})})]})}case"ellipse":{const p=n.getShapeGeometry(e),y=p.getSvgPathData(!0);if(c==="dashed"||c==="dotted"){const m=p.length,{strokeDasharray:w,strokeDashoffset:S}=eo(m<64?m*2:m,d,{style:c,snap:4,closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:y,color:i,fill:a}),h.jsx("path",{d:y,strokeWidth:d,fill:"none",stroke:t[i].solid,strokeDasharray:w,strokeDashoffset:S})]})}else{const w=n.getShapeGeometry(e).getSvgPathData(!0);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:w,color:i,fill:a}),h.jsx("path",{d:w,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}}case"oval":{const p=n.getShapeGeometry(e),y=p.getSvgPathData(!0);if(c==="dashed"||c==="dotted"){const m=p.getLength(),{strokeDasharray:w,strokeDashoffset:S}=eo(m<64?m*2:m,d,{style:c,snap:4,start:"outset",end:"outset",closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:y,color:i,fill:a}),h.jsx("path",{d:y,strokeWidth:d,fill:"none",stroke:t[i].solid,strokeDasharray:w,strokeDashoffset:S})]})}else return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:y,color:i,fill:a}),h.jsx("path",{d:y,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}case"heart":if(c==="dashed"||c==="dotted"){const p=Q$(s,f),y=sw(s,f);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:i,fill:a}),y.map((m,w)=>{const{strokeDasharray:S,strokeDashoffset:v}=eo(m.length,d,{style:c,snap:1,start:"outset",end:"outset",closed:!0});return h.jsx("path",{d:m.getSvgPathData(),strokeWidth:d,fill:"none",stroke:t[i].solid,strokeDasharray:S,strokeDashoffset:v,pointerEvents:"all"},`curve_${w}`)})]})}else{const p=aY(s,f,d,e.id);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:p,color:i,fill:a,theme:t}),h.jsx("path",{d:p,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}default:{const p=n.getShapeGeometry(e),y=p instanceof Hr?p.children[0].vertices:p.vertices,m=_v(e.props,d);if(c==="solid"){let w="M"+y[0]+"L"+y.slice(1)+"Z";if(m)for(const[S,v]of m)w+=`M${S.x},${S.y}L${v.x},${v.y}`;return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:w,color:i,fill:a}),h.jsx("path",{d:w,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}else if(c==="dashed"||c==="dotted"){const w="M"+y[0]+"L"+y.slice(1)+"Z";return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:w,fill:a,color:i}),h.jsxs("g",{strokeWidth:d,stroke:t[i].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(y.length)).map((S,v)=>{const P=b.ToFixed(y[v]),E=b.ToFixed(y[(v+1)%y.length]),C=b.Dist(P,E),{strokeDasharray:I,strokeDashoffset:_}=eo(C,d,{style:c,start:"outset",end:"outset"});return h.jsx("line",{x1:P.x,y1:P.y,x2:E.x,y2:E.y,strokeDasharray:I,strokeDashoffset:_},v)}),m&&m.map(([S,v],P)=>{const E=b.Dist(S,v),{strokeDasharray:C,strokeDashoffset:I}=eo(E,d,{style:c,start:"skip",end:"skip",snap:c==="dotted"?4:void 0});return h.jsx("path",{d:`M${S.x},${S.y}L${v.x},${v.y}`,stroke:t[i].solid,strokeWidth:d,fill:"none",strokeDasharray:C,strokeDashoffset:I},`line_fg_${P}`)})]})]})}else if(c==="draw"){const w=Iv(r,y,d/3,d*2,2);let S=Cv(w);if(m)for(const[E,C]of m)S+=`M${E.toFixed()}L${C.toFixed()}`;const v=Iv(r,y,0,d*2,1),P=Cv(v);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:P,fill:a,color:i,theme:t}),h.jsx("path",{d:S,stroke:t[i].solid,strokeWidth:d,fill:"none"})]})}}}}const fr=17*3;class Vh extends _c{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 c=a.props.w*s,l=(a.props.h+a.props.growY)*i,u=0,d=0;if(t.props.text.trim()){let m=Math.max(Math.abs(c),fr),w=Math.max(Math.abs(l),fr);m<fr&&w===fr&&(m=fr),m===fr&&w<fr&&(w=fr);const S=Hd(this.editor,{...t,props:{...t.props,w:m,h:w}}),v=Math.max(Math.abs(c),S.w)*Math.sign(c),P=Math.max(Math.abs(l),S.h)*Math.sign(l);u=Math.abs(v)-Math.abs(c),d=Math.abs(P)-Math.abs(l),c=v,l=P}const f=new b(0,0);s<0&&(f.x+=c),(r==="left"||r==="top_left"||r==="bottom_left")&&(f.x+=s<0?u:-u),i<0&&(f.y+=l),(r==="top"||r==="top_left"||r==="top_right")&&(f.y+=i<0?d:-d);const{x:p,y}=f.rot(t.rotation).add(o);return{x:p,y,props:{w:Math.max(Math.abs(c),1),h:Math.max(Math.abs(l),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=Hd(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,c=Hd(this.editor,r),l=c.w,u=c.h;if(!o&&s&&s.length===1){let f=Math.max(i,l),p=Math.max(a,u);return t.props.w<fr&&t.props.h<fr&&(f=Math.max(f,fr),p=Math.max(p,fr),f=Math.max(f,p),p=Math.max(f,p)),{...r,props:{...r.props,w:f,h:p,growY:0}}}let d=null;if(u>a?d=u-a:t.props.growY&&(d=0),d!==null)return{...r,props:{...r.props,growY:d,w:Math.max(r.props.w,l)}};if(l>t.props.w)return{...r,props:{...r.props,w:l}}});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:""}}getGeometry(t){const r=Math.max(1,t.props.w),o=Math.max(1,t.props.h+t.props.growY),s=r/2,i=o/2,a=At[t.props.size],c=t.props.fill!=="none";let l;switch(t.props.geo){case"cloud":{l=new bt({points:pY(r,o,t.id,t.props.size),isFilled:c});break}case"triangle":{l=new bt({points:[new b(s,0),new b(r,o),new b(0,o)],isFilled:c});break}case"diamond":{l=new bt({points:[new b(s,0),new b(r,i),new b(s,o),new b(0,i)],isFilled:c});break}case"pentagon":{l=new bt({points:Wg(r,o,5),isFilled:c});break}case"hexagon":{l=new bt({points:Wg(r,o,6),isFilled:c});break}case"octagon":{l=new bt({points:Wg(r,o,8),isFilled:c});break}case"ellipse":{l=new l7({width:r,height:o,isFilled:c});break}case"oval":{l=new u7({width:r,height:o,isFilled:c});break}case"star":{const v=Re/5/2,P=Math.floor(5/4)*2,E=5*2-P,C=0,I=Math.floor(5/2)*2,_=Math.cos(-Ve+P*v)*r/2,k=Math.cos(-Ve+E*v)*r/2,$=Math.sin(-Ve+C*v)*o/2,T=Math.sin(-Ve+I*v)*o/2,O=r-Math.abs(_-k),N=o-Math.abs(T-$),A=r/2+k-(r/2-_),j=o/2+$-(o/2-T),L=1,X=(r-A)/2,V=(o-j)/2,H=(r+O)/2,U=(o+N)/2,K=H*L/2,Z=U*L/2;l=new bt({points:Array.from(Array(5*2)).map((le,be)=>{const Ae=-Ve+be*v;return new b(X+(be%2?K:H)*Math.cos(Ae),V+(be%2?Z:U)*Math.sin(Ae))}),isFilled:c});break}case"rhombus":{const S=Math.min(r*.38,o*.38);l=new bt({points:[new b(S,0),new b(r,0),new b(r-S,o),new b(0,o)],isFilled:c});break}case"rhombus-2":{const S=Math.min(r*.38,o*.38);l=new bt({points:[new b(0,0),new b(r-S,0),new b(r,o),new b(S,o)],isFilled:c});break}case"trapezoid":{const S=Math.min(r*.38,o*.38);l=new bt({points:[new b(S,0),new b(r-S,0),new b(r,o),new b(0,o)],isFilled:c});break}case"arrow-right":{const S=Math.min(r,o)*.38,v=o*.16;l=new bt({points:[new b(0,v),new b(r-S,v),new b(r-S,0),new b(r,o/2),new b(r-S,o),new b(r-S,o-v),new b(0,o-v)],isFilled:c});break}case"arrow-left":{const S=Math.min(r,o)*.38,v=o*.16;l=new bt({points:[new b(S,0),new b(S,v),new b(r,v),new b(r,o-v),new b(S,o-v),new b(S,o),new b(0,o/2)],isFilled:c});break}case"arrow-up":{const S=r*.16,v=Math.min(r,o)*.38;l=new bt({points:[new b(r/2,0),new b(r,v),new b(r-S,v),new b(r-S,o),new b(S,o),new b(S,v),new b(0,v)],isFilled:c});break}case"arrow-down":{const S=r*.16,v=Math.min(r,o)*.38;l=new bt({points:[new b(S,0),new b(r-S,0),new b(r-S,o-v),new b(r,o-v),new b(r/2,o),new b(0,o-v),new b(S,o-v)],isFilled:c});break}case"check-box":case"x-box":case"rectangle":{l=new Qo({width:r,height:o,isFilled:c});break}case"heart":{const v=sw(r,o).reduce((P,E)=>(P.push(...E.vertices),P),[]);l=new bt({points:v,isFilled:c});break}default:sn(t.props.geo)}const u=Hd(this.editor,t),d=Math.min(100,r/2),f=Math.min(r,Math.max(u.w,Math.min(d,Math.max(1,r-8)))),p=Math.min(Ko[t.props.size]*Wt.lineHeight+Dr*2,o/2),y=Math.min(o,Math.max(u.h,Math.min(p,Math.max(1,r-8)))),m=_v(t.props,a),w=m?m.map(S=>new Ec({points:S})):[];return new Hr({children:[l,new Qo({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}),...w]})}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:sn(t.props.geo)}}component(t){const{id:r,type:o,props:s}=t,{fill:i,font:a,align:c,verticalAlign:l,size:u,text:d}=s,f=t.id===this.editor.getOnlySelectedShapeId(),p=_r(),m=this.editor.getEditingShapeId()!==null||t.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(Ks,{id:r,children:h.jsx(KC,{shape:t})}),m&&h.jsx(Li,{style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:h.jsx(ig,{id:r,type:o,font:a,fontSize:Ko[u],lineHeight:Wt.lineHeight,fill:i,align:c,verticalAlign:l,text:d,isSelected:f,labelColor:p[s.labelColor].solid,wrap:!0})}),t.props.url&&h.jsx(gc,{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,c=At[i],l=this.editor.getShapeGeometry(t);switch(o.geo){case"ellipse":return o.dash==="draw"?h.jsx("path",{d:uY(r,s,a,c)}):h.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return h.jsx("path",{d:Q$(s,a)});case"oval":return h.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return h.jsx("path",{d:Ev(s,a,r,i)});default:{const u=this.editor.getShapeGeometry(t),d=u instanceof Hr?u.children[0].vertices:u.vertices;let f;if(o.dash==="draw"){const y=Iv(r,d,0,c*2,1);f=Cv(y)}else f="M"+d[0]+"L"+d.slice(1)+"Z";const p=_v(t.props,c);if(p)for(const[y,m]of p)f+=`M${y.x},${y.y}L${m.x},${m.y}`;return h.jsx("path",{d:f})}}}toSvg(t,r){const{props:o}=t;r.addExportDef(tw(t.props.fill));let s;if(o.text){r.addExportDef(pc(t.props.font));const i=ts(r),a=this.editor.getShapeGeometry(t).bounds;s=h.jsx(sg,{fontSize:Ko[o.size],font:o.font,align:o.align,verticalAlign:o.verticalAlign,text:o.text,labelColor:i[o.labelColor].solid,bounds:a})}return h.jsxs(h.Fragment,{children:[h.jsx(KC,{shape:t}),s]})}getCanvasSvgDefs(){return[nw()]}}g(Vh,"type","geo"),g(Vh,"props",XE),g(Vh,"migrations",qE);function Hd(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Wt,fontFamily:fo[n.props.font],fontSize:Ko[n.props.size],maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(t,{...Wt,fontFamily:fo[n.props.font],fontSize:Ko[n.props.size],minWidth:r.w,maxWidth:Math.max(0,Math.ceil(r.w+o[n.props.size]),Math.ceil(n.props.w-Dr*2))});return{w:s.w+Dr*2,h:s.h+Dr*2}}function vY(){const[e,n]=x.useState(!1);return x.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)},[]),W(Pt.forceSrgb)||!e?"srgb":"p3"}const WC=.35,GC=.82;class Yh extends Br{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>Wd(t));g(this,"hideRotateHandle",t=>Wd(t));g(this,"hideSelectionBoundsFg",t=>Wd(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:c,y:l,z:u})=>({x:o*c,y:s*l,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1}}getGeometry(t){const r=ua(t);if(Wd(t))return new Tx({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=J$(t,r,!0),i=bv({strokeWidth:s,showAsComplete:!0});return og(o,i),new bt({points:Qx(o,i),isFilled:!0})}component(t){return h.jsx(Ks,{id:t.id,style:{opacity:WC},children:h.jsx(Kd,{strokeWidth:ua(t),shape:t})})}backgroundComponent(t){return h.jsx(Ks,{id:t.id,style:{opacity:GC},children:h.jsx(Kd,{strokeWidth:ua(t),shape:t})})}indicator(t){var d;const r=du(),o=ua(t),s=hu(t.props.segments);let i=o;!r&&!t.props.isPen&&s.length===1&&(i+=Gr(t.id)()*(o/6));const a=t.props.isComplete||((d=Nt(t.props.segments))==null?void 0:d.type)==="straight",c=bv({strokeWidth:o,showAsComplete:a}),l=mo(s,c);let u;return l.length<2?u=wY(s[0],i):u=Fi(l,!1),h.jsx("path",{d:u})}toSvg(t){return h.jsx(Kd,{strokeWidth:ua(t),shape:t,opacity:WC})}toBackgroundSvg(t){return h.jsx(Kd,{strokeWidth:ua(t),shape:t,opacity:GC})}}g(Yh,"type","highlight"),g(Yh,"props",JE),g(Yh,"migrations",e_);function xY(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 wY(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 J$(e,n,t){var c;const r=hu(e.props.segments),o=e.props.isComplete||((c=Nt(e.props.segments))==null?void 0:c.type)==="straight";let s=n;!t&&!e.props.isPen&&r.length===1&&(s+=Gr(e.id)()*(n/6));const i=bv({strokeWidth:s,showAsComplete:o});return{strokePoints:mo(r,i),sw:s}}function bY(e,n,t){const{strokePoints:r,sw:o}=J$(e,n,t);return{solidStrokePath:r.length>1?Fi(r,!1):xY(e.props.segments[0].points[0]),sw:o}}function Kd({strokeWidth:e,shape:n,opacity:t}){const r=_r(),o=du(),{solidStrokePath:s,sw:i}=bY(n,e,o),a=vY(),c=r[n.props.color].highlight[a];return h.jsx("path",{d:s,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:c,strokeWidth:i,opacity:t})}function ua(e){return hc[e.props.size]*1.12}function Wd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function eM(){return h.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),h.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),h.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function tM(){const[e,n]=x.useState(!1);return x.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 PY(e){const t=await(await fetch(e)).blob();return Ua.blobToDataUrl(t)}class Xh extends _c{constructor(){super(...arguments);g(this,"isAspectRatioLocked",()=>!0);g(this,"canCrop",()=>!0);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=xt(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 b(o.topLeft.x*s,o.topLeft.y*i).rot(t.rotation),c={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([c])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}isAnimated(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;return r?"mimeType"in r.props&&Xn.isAnimatedImageType(r==null?void 0:r.props.mimeType)||"isAnimated"in r.props&&r.props.isAnimated:!1}component(t){var f;const r=this.editor.getCroppingShapeId()===t.id,o=tM(),[s,i]=x.useState(""),a=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0,c=t.id===this.editor.getOnlySelectedShapeId();if(x.useEffect(()=>{if(a!=null&&a.props.src&&this.isAnimated(t)){let p=!1;const y=a.props.src;if(!y)return;const m=new Image;return m.onload=()=>{if(p)return;const w=document.createElement("canvas");w.width=m.width,w.height=m.height;const S=w.getContext("2d");S&&(S.drawImage(m,0,0),i(w.toDataURL()))},m.crossOrigin="anonymous",m.src=y,()=>{p=!0}}},[o,a==null?void 0:a.props,t]),(a==null?void 0:a.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const l=c&&r&&this.editor.isInAny("select.crop","select.cropping","select.pointing_crop_handle"),u=o&&(((f=a==null?void 0:a.props.mimeType)==null?void 0:f.includes("video"))||this.isAnimated(t)),d=VC(t);return a!=null&&a.props.src?h.jsxs(h.Fragment,{children:[l&&h.jsx("div",{style:d,children:h.jsx("div",{className:"tl-image",style:{opacity:.1,backgroundImage:`url(${!t.props.playing||u?s:a.props.src})`},draggable:!1})}),h.jsxs(Li,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h},children:[h.jsxs("div",{className:"tl-image-container",style:d,children:[h.jsx("div",{className:"tl-image",style:{backgroundImage:`url(${!t.props.playing||u?s:a.props.src})`},draggable:!1}),this.isAnimated(t)&&!t.props.playing&&h.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),")",t.props.url&&h.jsx(gc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):h.jsxs(Li,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h,color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:[h.jsx("div",{className:"tl-image-container",style:d,children:a?null:h.jsx(eM,{})}),")","url"in t.props&&t.props.url&&h.jsx(gc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return this.editor.getCroppingShapeId()===t.id?null:h.jsx("rect",{width:F(t.props.w),height:F(t.props.h)})}async toSvg(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null;if(!r)return null;let o=(r==null?void 0:r.props.src)||"";(o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await PY(o)||"");const s=VC(t),i=t.props.crop;if(s.transform&&i){const{transform:a,width:c,height:l}=s,u=(i.bottomRight.x-i.topLeft.x)*c,d=(i.bottomRight.y-i.topLeft.y)*l,f=[new b(0,0),new b(u,0),new b(u,d),new b(0,d)],p=`cropClipPath_${t.id.replace(":","_")}`;return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsx("clipPath",{id:p,children:h.jsx("polygon",{points:f.map(y=>`${y.x},${y.y}`).join(" ")})})}),h.jsx("g",{clipPath:"url(#{cropClipId})",children:h.jsx("image",{href:o,width:c,height:l,style:{transform:a}})})]})}else return h.jsx("image",{href:o,width:t.props.w,height:t.props.h})}}g(Xh,"type","image"),g(Xh,"props",t_),g(Xh,"migrations",n_);function VC(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 nM(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function rM(e,n,t){const r=n.vertices,o=nM(t);return mo(r,o)}function CY(e,n,t){const r=nM(t);return Qx(og(rM(e,n,t),r),r)}function IY(e,n,t){const r=CY(e,n,t);return E0(r)}function EY(e,n,t){if(e.props.dash==="draw"){const r=rM(e,n,t);return Fi(r)}return n.getSvgPathData()}function oM(e,n,t){let r=`M ${Ee(n[0])}L`,o=`M ${Ee(n[0])}L`;const s=t/3,i=t*2,a=Gr(e);let c=n[0],l,u=n[0],d;const f=n.length;for(let p=0,y=f-1;p<y;p++){l=n[p+1],d=b.AddXY(n[p+1],a()*s,a()*s);const m=b.Sub(l,c),w=b.Len(m),S=b.Div(m,w).mul(Math.min(w/4,i)),v=b.Add(c,S),P=b.Add(l,S.neg()),E=b.Sub(d,u),C=b.Len(E),I=b.Div(E,C).mul(Math.min(C/4,i)),_=b.Add(u,I),k=b.Add(d,I.neg());p===y-1?(r+=`${Ee(v)}L ${Ee(l)}`,o+=`${Ee(_)}L ${Ee(d)}`):(r+=`${Ee(v)}L ${Ee(P)}Q ${Ee(l)}`,o+=`${Ee(_)}L ${Ee(k)}Q ${Ee(d)}`,c=l,u=d)}return[r,r+o]}const _Y=new _i;class qh extends Br{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:Iu(t.props.points,(i,{id:a,index:c,x:l,y:u})=>({id:a,index:c,x:l*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]=Bl(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}}}}getGeometry(t){return wl(t)}getHandles(t){return _Y.get(t.props,()=>{const r=wl(t),o=kv(t),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=zl(o[i].index,o[i+1].index),l=r.segments[i].midPoint();s.push({id:a,type:"create",index:a,x:l.x,y:l.y,canSnap:!0})}return s.sort(nn)})}component(t){return h.jsx(Ks,{id:t.id,children:h.jsx(YC,{shape:t})})}indicator(t){const r=At[t.props.size],o=wl(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[c]=oM(t.id,a,r);i=c}}else i=EY(t,o,r);return h.jsx("path",{d:i})}toSvg(t){return h.jsx(YC,{shape:t})}getHandleSnapGeometry(t){const r=kv(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(b.From)},getSelfSnapOutline:o=>{const s=this.getHandles(t).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),i=wl(t).segments.filter((a,c)=>c!==s-1&&c!==s);return i.length?new Hr({children:i}):null}}}}g(qh,"type","line"),g(qh,"props",r_),g(qh,"migrations",o_);function kv(e){return Object.values(e.props.points).sort(nn)}function wl(e){const n=kv(e).map(b.From);switch(e.props.spline){case"cubic":return new c7({points:n});case"line":return new Ec({points:n})}}function YC({shape:e}){const n=_r(),t=wl(e),r=At[e.props.size],{dash:o,color:s}=e.props;if(e.props.spline==="line"){if(o==="solid"){const i=t.points,a="M"+i[0]+"L"+i.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:a,fill:"none",color:s,theme:n}),h.jsx("path",{d:a,stroke:n[s].solid,strokeWidth:r,fill:"none"})]})}if(o==="dashed"||o==="dotted"){const i=t.points,a="M"+i[0]+"L"+i.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:a,fill:"none",color:s,theme:n}),h.jsx("g",{stroke:n[s].solid,strokeWidth:r,children:t.segments.map((c,l)=>{const{strokeDasharray:u,strokeDashoffset:d}=eo(c.length,r,{style:o,start:l>0?"outset":"none",end:l<t.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:u,strokeDashoffset:d,d:c.getSvgPathData(!0),fill:"none"},l)})})]})}if(o==="draw"){const i=t.points,[a,c]=oM(e.id,i,r);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:a,fill:"none",color:s,theme:n}),h.jsx("path",{d:c,stroke:n[s].solid,strokeWidth:r,fill:"none"})]})}}if(e.props.spline==="cubic"){const i=t.getSvgPathData();if(o==="solid")return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:i,fill:"none",color:s,theme:n}),h.jsx("path",{strokeWidth:r,stroke:n[s].solid,fill:"none",d:i})]});if(o==="dashed"||o==="dotted")return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:i,fill:"none",color:s,theme:n}),h.jsx("g",{stroke:n[s].solid,strokeWidth:r,children:t.segments.map((a,c)=>{const{strokeDasharray:l,strokeDashoffset:u}=eo(a.length,r,{style:o,start:c>0?"outset":"none",end:c<t.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:l,strokeDashoffset:u,d:a.getSvgPathData(),fill:"none"},c)})})]});if(o==="draw")return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:i,fill:"none",color:s,theme:n}),h.jsx("path",{d:IY(e,t,r),strokeWidth:1,stroke:n[s].solid,fill:n[s].solid})]})}}const sM=x.createContext(null);function kY({assetUrls:e,children:n}){return x.useEffect(()=>{for(const t of Object.values(e.icons)){const r=new Image;r.src=t,r.decode()}for(const t of Object.values(e.embedIcons)){const r=new Image;r.src=t,r.decode()}},[e]),h.jsx(sM.Provider,{value:e,children:n})}function iw(){const e=x.useContext(sM);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const Tv={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","menu.title":"Menu","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy share link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy read-only link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to 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.","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..."},TY=new Set(["ar","fa","he","ur","ku"]),da={locale:"en",label:"English",messages:Tv,dir:"ltr"};async function $Y(e,n){if(!(await fetch(n.translations.en)).ok)return console.warn("No main translations found."),da;if(e==="en")return da;const r=Hl.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),da;const s=await(await fetch(n.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),da;const i=[];for(const a in da.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:TY.has(r.locale)?"rtl":"ltr",messages:{...da.messages,...s}}}const iM=x.createContext(null);function aM(){const e=x.useContext(iM);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const MY=ir(function({overrides:n,children:t}){const o=B().user.getLocale(),s=iw(),[i,a]=x.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...Tv,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:Tv});return x.useEffect(()=>{let c=!1;async function l(){const u=await $Y(o,s);u&&!c&&(n&&n[o]?a({...u,messages:{...u.messages,...n[o]}}):a(u))}return l(),()=>{c=!0}},[s,o,n]),h.jsx(iM.Provider,{value:i,children:t})});function Me(){const e=aM();return x.useCallback(function(t){return e.messages[t]??t},[e])}const cy=[0,390,428,468,580,640,840,1023];var wt=(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))(wt||{});const cM=20;class Zh extends Br{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"hideResizeHandles",()=>!0);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"onBeforeCreate",t=>XC(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 XC(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:""}}getGeometry(t){const r=Gd(t),{labelHeight:o,labelWidth:s}=lM(this.editor,t);return new Hr({children:[new Qo({width:$e,height:r,isFilled:!0}),new Qo({x:t.props.align==="start"?0:t.props.align==="end"?$e-s:($e-s)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?r-o:(r-o)/2,width:s,height:o,isFilled:!0,isLabel:!0})]})}getHandles(t){const r=this.editor.getZoomLevel(),o=cV/r,s=Gd(t),i=this.editor.getInstanceState().isCoarsePointer;return r<.25||i?[]:r<.5?[{id:"bottom",index:"a3",type:"clone",x:$e/2,y:s+o}]:[{id:"top",index:"a1",type:"clone",x:$e/2,y:-o},{id:"right",index:"a2",type:"clone",x:$e+o,y:s/2},{id:"bottom",index:"a3",type:"clone",x:$e/2,y:s+o},{id:"left",index:"a4",type:"clone",x:-o,y:s/2}]}component(t){const{id:r,type:o,props:{color:s,font:i,size:a,align:c,text:l,verticalAlign:u,fontSizeAdjustment:d}}=t,f=OY(r),p=_r(),y=Gd(t),m=W("shape rotation",()=>{var v;return((v=this.editor.getShapePageTransform(r))==null?void 0:v.rotation())??0},[this.editor]),w=du(),S=t.id===this.editor.getOnlySelectedShapeId();return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:r,className:"tl-note__container",style:{width:$e,height:y,backgroundColor:p[s].note.fill,borderBottom:w?"3px solid rgb(15, 23, 31, .2)":"none",boxShadow:w?"none":DY(t.id,m)},children:h.jsx(ig,{id:r,type:o,font:i,fontSize:d||Ko[a],lineHeight:Wt.lineHeight,align:c,verticalAlign:u,text:l,isNote:!0,isSelected:S,labelColor:p[s].note.text,wrap:!0,onKeyDown:f})}),"url"in t.props&&t.props.url&&h.jsx(gc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return h.jsx("rect",{rx:"1",width:F($e),height:F(Gd(t))})}toSvg(t,r){r.addExportDef(pc(t.props.font)),t.props.text&&r.addExportDef(pc(t.props.font));const o=ts({isDarkMode:r.isDarkMode}),s=this.editor.getShapeGeometry(t).bounds;return h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:5,y:5,rx:1,width:$e-10,height:s.h,fill:"rgba(0,0,0,.1)"}),h.jsx("rect",{rx:1,width:$e,height:s.h,fill:o[t.props.color].note.fill}),h.jsx(sg,{fontSize:t.props.fontSizeAdjustment||Ko[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(Zh,"type","note"),g(Zh,"props",s_),g(Zh,"migrations",i_);function XC(e,n){const{labelHeight:t,fontSizeAdjustment:r}=lM(e,n),o=Math.max(0,t-$e);if(o!==n.props.growY||r!==n.props.fontSizeAdjustment)return{...n,props:{...n.props,growY:o,fontSizeAdjustment:r}}}function AY(e,n){const t=n.props.text;if(!t)return{labelHeight:Ko[n.props.size]*Wt.lineHeight+Dr*2,labelWidth:100,fontSizeAdjustment:0};const r=Ko[n.props.size];let o=0,s=0,i=$e,a=$e;const c=1;do{o=Math.min(r,r-s);const l=e.textMeasure.measureText(t,{...Wt,fontFamily:fo[n.props.font],fontSize:o,maxWidth:$e-Dr*2-c,disableOverflowWrapBreaking:!0});if(i=l.h+Dr*2,a=l.w+Dr*2,o<=14){const u=e.textMeasure.measureText(t,{...Wt,fontFamily:fo[n.props.font],fontSize:o,maxWidth:$e-Dr*2-c});i=u.h+Dr*2,a=u.w+Dr*2;break}if(l.scrollWidth.toFixed(0)===l.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const jY=new _i;function lM(e,n){return jY.get(n,()=>AY(e,n))}function OY(e){const n=B(),t=aM();return x.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),c=a.rotation(),l=!!(t.dir==="rtl"||O$(o.props.text)),u=$e+cM+(i&&!r.shiftKey?o.props.growY:0),d=new b(s?r.shiftKey!=l?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(ew).rot(c).add(a.point()),f=U$(n,o,d,c);f&&(n.mark("editing adjacent shape"),hp(n,f,!0))}},[e,n,t.dir])}function Gd(e){return $e+e.props.growY}function DY(e,n){const t=Gr(e),r=Math.abs(t())+.5,o=Math.cos(n);return`0px ${5-r}px 5px -5px rgba(15, 23, 31, .6),
166
- 0px ${(4+r*7)*Math.max(0,o)}px ${6+r*7}px -${4+r*6}px rgba(15, 23, 31, ${(.3+r*.1).toFixed(2)}),
167
- 0px 48px 10px -10px inset rgba(15, 23, 44, ${((.022+t()*.005)*((1+o)/2)).toFixed(2)})`}function RY(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),i=new b(0,0);t<0&&(i.x=-(n.width*s)),r<0&&(i.y=-(n.height*s));const{x:a,y:c}=b.Add(o,i.rot(e.rotation));return{x:a,y:c,props:{scale:s*e.props.scale}}}const LY=new _i;class Qh extends Br{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:c}=r;if(r.mode==="scale_shape"||c!=="right"&&c!=="left")return{id:t.id,type:t.type,...RY(t,r)};{const l=Math.max(1,Math.abs(s.width*a)),{x:u,y:d}=a<0?b.Sub(o,b.FromAngle(t.rotation).mul(l)):o;return{id:t.id,type:t.type,x:u,y:d,props:{w:l/i.props.scale,autoSize:!1}}}});g(this,"onBeforeCreate",t=>{if(!t.props.autoSize||t.props.text.trim())return;const r=this.getMinDimensions(t);return{...t,x:t.x-r.width/2,y:t.y-r.height/2}});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=qC(this.editor,r.props),c=i.width*t.props.scale,l=i.height*t.props.scale,u=a.width*r.props.scale,d=a.height*r.props.scale;let f;switch(r.props.textAlign){case"middle":{f=new b((u-c)/2,s?0:(d-l)/2);break}case"end":{f=new b(u-c,s?0:(d-l)/2);break}default:{if(s)break;f=new b(0,(d-l)/2);break}}if(f){f.rot(r.rotation);const{x:p,y}=r;return{...r,x:p-f.x,y:y-f.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}});g(this,"onDoubleClickEdge",t=>{if(!t.props.autoSize)return{id:t.id,type:t.type,props:{autoSize:!0}};if(t.props.scale!==1)return{id:t.id,type:t.type,props:{scale:1}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(t){return LY.get(t.props,r=>qC(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:s}=this.getMinDimensions(t);return new Qo({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:c,textAlign:l}}=t,{width:u,height:d}=this.getMinDimensions(t),f=t.id===this.editor.getOnlySelectedShapeId(),p=_r(),y=FY(r);return h.jsx(ig,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:hc[s],lineHeight:Wt.lineHeight,align:l,verticalAlign:"middle",text:i,labelColor:p[a].solid,isSelected:f,textWidth:u,textHeight:d,style:{transform:`scale(${c})`,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:h.jsx("rect",{width:F(r.width),height:F(r.height)})}toSvg(t,r){r.addExportDef(pc(t.props.font)),t.props.text&&r.addExportDef(pc(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=ts(r);return h.jsx(sg,{fontSize:hc[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 J(0,0,s,i),padding:0})}}g(Qh,"type","text"),g(Qh,"props",a_),g(Qh,"migrations",c_);function qC(e,n){const{font:t,text:r,autoSize:o,size:s,w:i}=n,a=o?16:Math.max(16,i),c=hc[s],l=o?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...Wt,fontFamily:fo[t],fontSize:c,maxWidth:l});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(c,u.h)}}function FY(e){const n=B();return x.useCallback(t=>{if(n.getEditingShapeId()===e)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&n.complete();break}case"Tab":{_e(t),t.shiftKey?fc.unindent(t.currentTarget):fc.indent(t.currentTarget);break}}},[n,e])}class Jh extends _c{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,s=t.props.assetId?r.getAsset(t.props.assetId):null,{time:i,playing:a}=t.props,c=Zp(t.id),l=tM(),u=x.useRef(null),d=x.useCallback(S=>{const v=S.currentTarget;v&&r.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:v.currentTime}}])},[t.id,r]),f=x.useCallback(S=>{const v=S.currentTarget;v&&r.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:v.currentTime}}])},[t.id,r]),p=x.useCallback(S=>{const v=S.currentTarget;v&&c&&r.updateShapes([{type:"video",id:t.id,props:{time:v.currentTime}}])},[c,t.id,r]),[y,m]=x.useState(!1),w=x.useCallback(S=>{const v=S.currentTarget;v&&(i!==v.currentTime&&(v.currentTime=i),a||v.pause(),m(!0))},[a,i]);return x.useEffect(()=>{const S=u.current;S&&(y&&!c&&i!==S.currentTime&&(S.currentTime=i),c&&document.activeElement!==S&&S.focus())},[c,y,i]),x.useEffect(()=>{if(l){const S=u.current;if(!S)return;S.pause(),S.currentTime=0}},[u,l]),h.jsxs(h.Fragment,{children:[h.jsx(Li,{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:h.jsx("div",{className:"tl-counter-scaled",children:h.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?h.jsx("video",{ref:u,style:c?{pointerEvents:"all"}:void 0,className:`tl-video tl-video-shape-${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:d,onPause:f,onTimeUpdate:p,onLoadedData:w,hidden:!y,children:h.jsx("source",{src:s.props.src})}):h.jsx(eM,{})})})}),"url"in t.props&&t.props.url&&h.jsx(gc,{url:t.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(t){return h.jsx("rect",{width:F(t.props.w),height:F(t.props.h)})}toSvg(t){return h.jsx("image",{href:NY(t.id),width:t.props.w,height:t.props.h})}}g(Jh,"type","video"),g(Jh,"props",l_),g(Jh,"migrations",u_);function NY(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 uM=[Qh,Hh,Kh,Vh,Zh,qh,Gh,Uh,Yh,Wh,Xh,Jh];function zY(e){return[e.sideEffects.registerAfterChangeHandler("instance_page_state",(n,t)=>{if(n.croppingShapeId!==t.croppingShapeId){const r=e.isInAny("select.crop","select.pointing_crop_handle","select.cropping");!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 dM 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:c}}=t;this.pushPointToScribble();const l=new Set(o),u=Vo/s;for(const d of i){if(t.isShapeOfType(d,"group"))continue;const f=t.getShapeMask(d.id);if(f&&!er(a,f))continue;const p=t.getShapeGeometry(d),y=t.getShapePageTransform(d);if(!p||!y)continue;const m=y.clone().invert(),w=m.applyToPoint(c),S=m.applyToPoint(a),{bounds:v}=p;v.minX-u>Math.max(w.x,S.x)||v.minY-u>Math.max(w.y,S.y)||v.maxX+u<Math.min(w.x,S.x)||v.maxY+u<Math.min(w.y,S.y)||p.hitTestLineSegment(w,S,u)&&l.add(t.getOutermostSelectableShape(d).id)}this.editor.setErasingShapes([...l].filter(d=>!r.has(d)))}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(dM,"id","erasing");var Ny;let BY=(Ny=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Ny,"id","idle"),Ny);var zy;let UY=(zy=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,c=a-1;c>=0;c--){const l=r[c];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,o,{hitInside:!1,margin:Vo/t})){const u=this.editor.getOutermostSelectableShape(l);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(zy,"id","pointing"),zy);class ef extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(ef,"id","eraser"),g(ef,"initial","idle"),g(ef,"children",()=>[BY,UY,dM]);class hM extends se{constructor(){super(...arguments);g(this,"initialCamera",new b);g(this,"onEnter",()=>{this.initialCamera=b.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=b.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,friction:y_}),this.parent.transition("idle")}}g(hM,"id","dragging");var By;let HY=(By=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(By,"id","idle"),By);var Uy;let KY=(Uy=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(Uy,"id","pointing"),Uy);class tf 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:an.easeOutQuint}})}});g(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:an.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:an.easeOutQuint}}):this.editor.resetZoom(o,{animation:{duration:320,easing:an.easeOutQuint}})}})}}g(tf,"id","hand"),g(tf,"initial","idle"),g(tf,"children",()=>[HY,KY,hM]);var Hy;let WY=(Hy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},g(Hy,"id","idle"),Hy);class fM 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(fM,"id","lasering");class nf extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(nf,"id","laser"),g(nf,"initial","idle"),g(nf,"children",()=>[WY,fM]);class pM 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",()=>{$x(this.editor)});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:c}}=t,l=new Set(a?this.initialSelectedShapeIds:[]),u=o?!c:c,d=J.FromPoints([s,i]),{corners:f}=d;let p,y,m,w,S,v;const P=t.getCurrentPageShapes(),E=t.getCurrentPageId();e:for(let _=0,k=P.length;_<k;_++){if(m=P[_],r.has(m.id)||l.has(m.id)||(w=t.getShapePageBounds(m),!w))continue e;if(d.contains(w)){this.handleHit(m,i,E,l,f);continue e}if(u||t.isShapeOfType(m,"frame"))continue e;if(d.collides(w)){if(S=t.getShapePageTransform(m),!S)continue e;v=S.clone().invert().applyToPoints(f);const $=t.getShapeGeometry(m);t:for(let T=0;T<4;T++)if(p=v[T],y=v[(T+1)%4],$.hitTestLineSegment(p,y,0)){this.handleHit(m,i,E,l,f);break t}}}t.getInstanceState().isCoarsePointer;const C=t.getInstanceState().brush;(!C||!d.equals(C))&&t.updateInstanceState({brush:{...d.toJson()}});const I=t.getSelectedShapeIds();(I.length!==l.size||I.some(_=>!l.has(_)))&&t.setSelectedShapes(Array.from(l))}handleHit(t,r,o,s,i){if(t.parentId===o){s.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),c=this.editor.getShapeMask(a.id);c&&!s2(c,i)&&!er(r,c)||s.add(a.id)}}g(pM,"id","brushing");function aw(e,n=!1){const t=e.getZoomLevel(),{inputs:{currentPagePoint:r}}=e;return e.getShapeAtPoint(r,{hitInside:!1,hitLabels:n,margin:Vo/t,renderingOnly:!0})??e.getSelectedShapeAtPoint(r)}function gM(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,c=r.bottomRight.x-r.topLeft.x,l=xt(r);return l.topLeft.x=Math.min(1-c,Math.max(0,l.topLeft.x-t.x/s)),l.topLeft.y=Math.min(1-a,Math.max(0,l.topLeft.y-t.y/i)),l.bottomRight.x=l.topLeft.x+c,l.bottomRight.y=l.topLeft.y+a,{id:n.id,type:n.type,props:{crop:l}}}var Ky;let GY=(Ky=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const t=this.editor.getOnlySelectedShape();this.editor.on("tick",this.cleanupCroppingState),t&&(this.editor.mark("crop"),this.editor.setCroppingShape(t.id))});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.editor.off("tick",this.cleanupCroppingState)});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=aw(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"});break}case"top":case"right":case"bottom":case"left":{this.editor.setCurrentTool("select.pointing_crop_handle",{...t,onInteractionEnd:"select.crop"});break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.pointing_crop_handle",{...t,onInteractionEnd:"select.crop"});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}}});g(this,"cleanupCroppingState",()=>{this.editor.getCroppingShapeId()||this.editor.setCurrentTool("select.idle",{})})}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 b(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 b(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=gM(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},g(Ky,"id","idle"),Ky);class mM 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(mM,"id","pointing_crop");class yM 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=gM(this.editor,t,s);i&&this.editor.updateShapes([i])}}g(yM,"id","translating_crop");class rf extends se{}g(rf,"id","crop"),g(rf,"initial","idle"),g(rf,"children",()=>[GY,yM,mM]);const pr=8,mc={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 SM 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=mc[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(SM,"id","pointing_resize_handle");class vM 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=mc[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),c=i.clone().sub(a).rot(-t.rotation),l=s.crop??this.getDefaultCrop(),u=xt(l),d=new b(t.x,t.y),f=new b(0,0),p=1/(l.bottomRight.x-l.topLeft.x)*s.w,y=1/(l.bottomRight.y-l.topLeft.y)*s.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(y<pr)break;m=!0,u.topLeft.y=u.topLeft.y+c.y/y,y*(u.bottomRight.y-u.topLeft.y)<pr?(u.topLeft.y=u.bottomRight.y-pr/y,f.y=(u.topLeft.y-l.topLeft.y)*y):u.topLeft.y<=0?(u.topLeft.y=0,f.y=(u.topLeft.y-l.topLeft.y)*y):f.y=c.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(y<pr)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+c.y/y),y*(u.bottomRight.y-u.topLeft.y)<pr&&(u.bottomRight.y=u.topLeft.y+pr/y);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<pr)break;m=!0,u.topLeft.x=u.topLeft.x+c.x/p,p*(u.bottomRight.x-u.topLeft.x)<pr?(u.topLeft.x=u.bottomRight.x-pr/p,f.x=(u.topLeft.x-l.topLeft.x)*p):u.topLeft.x<=0?(u.topLeft.x=0,f.x=(u.topLeft.x-l.topLeft.x)*p):f.x=c.x;break}case"right":case"top_right":case"bottom_right":{if(p<pr)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+c.x/p),p*(u.bottomRight.x-u.topLeft.x)<pr&&(u.bottomRight.x=u.topLeft.x+pr/p);break}}if(!m)return;d.add(f.rot(t.rotation));const w={id:t.id,type:t.type,x:d.x,y:d.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*p,h:(u.bottomRight.y-u.topLeft.y)*y}};this.editor.updateShapes([w]),this.updateCursor()}complete(){this.updateShapes(),We(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}createSnapshot(){const t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(s.getHandlePoint(this.info.handle),s.point,t),a=b.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}g(vM,"id","cropping");class xM 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=xt(s),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[s.index]:{id:s.index,index:s.index,x:s.x,y:s.y}}}});const l=this.editor.getShapeHandles(r).find(u=>u.index===s.index);this.initialHandle=xt(l)}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(nn),a=i.findIndex(c=>c.id===t.handle.id);this.initialAdjacentHandle=null;for(let c=a+1;c<i.length;c++){const l=i[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==t.handle.id){this.initialAdjacentHandle=l;break}}if(!this.initialAdjacentHandle)for(let c=i.length-1;c>=0;c--){const l=i[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==t.handle.id){this.initialAdjacentHandle=l;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=_n(this.editor,r)[t.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)});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=setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),We(this.editor,[this.shapeId]);const{onInteractionEnd: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 _;const{editor:t,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,c=this.editor.getHintingShapeIds(),l=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:d,shiftKey:f,ctrlKey:p,altKey:y,pointerVelocity:m}}=t,w=this.info.shape,S=t.getShape(r);if(!S)return;const v=t.getShapeUtil(S);let P=d.clone().sub(o).rot(-i).add(s);if(f&&a&&s.id!=="middle"){const k=b.Angle(a,P),T=kf(k,24)-k;P=b.RotWith(P,a,T)}t.snaps.clearIndicators();let E={...s,x:P.x,y:P.y};if(s.canSnap&&(l?!p:p)){if(!t.getShapePageTransform(S.id))throw Error("Expected a page transform");const $=u.handles.snapHandle({currentShapeId:r,handle:E});$&&($.nudge.rot(-t.getShapeParentTransform(S).rotation()),P.add($.nudge),E={...s,x:P.x,y:P.y})}const C=(_=v.onHandleDrag)==null?void 0:_.call(v,S,{handle:E,isPrecise:this.isPrecise||y,initial:w}),I={id:S.id,type:S.type,...C};if(s.type==="vertex"&&this.editor.isShapeOfType(S,"arrow")){const k=_n(t,S)[s.id];k?c[0]!==k.toId&&(t.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=m.len()<.5||y,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):c.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&t.updateShapes([I])}}g(xM,"id","dragging_handle");function wM(e){return e.isLabel?[e]:e instanceof Hr?e.children.filter(n=>n.isLabel):[]}class bM 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,Ja(this.editor),this.editor.select(t)});g(this,"onExit",()=>{var s;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null);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)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",t),this.hitShapeForPointerUp=null;return}switch(t.target){case"shape":case"canvas":{Ja(this.editor);return}}});g(this,"onPointerDown",t=>{switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=aw(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=wM(s),a=i.length===1?i[0]:void 0,c=this.editor.isShapeOfType(o,"text")&&o.props.text.trim()==="";if(a&&!c){const l=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(l,0)&&a.hitTestPoint(l)){if(r.id===o.id)return;this.hitShapeForPointerUp=r,this.editor.mark("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===o.id)this.editor.isShapeOfType(r,"frame")&&this.editor.setEditingShape(null);else{this.parent.transition("pointing_shape",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(this.editor.getInstanceState().isReadonly&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",t);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),Ja(this.editor)});g(this,"onComplete",t=>{this.parent.transition("idle",t)});g(this,"onCancel",t=>{this.parent.transition("idle",t)})}}g(bM,"id","editing_shape");function ZC(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function gp(e){const n=e.getSelectedShapeIds(),{shiftKey:t,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin:Vo/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(mr(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const VY=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Wy;let YY=(Wy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Ja(this.editor),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{Ja(this.editor)});g(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&ZC(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=aw(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))&&QC(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":{r?this.parent.transition("pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("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(),c=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:Vo/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(c){if(this.editor.isShapeOfType(c,"group")){gp(this.editor);return}else{const u=this.editor.getShape(c.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(l&&u.id===l)){gp(this.editor);return}}this.onDoubleClick({...t,shape:c,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 c=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(t.handle==="right"||t.handle==="left"||t.handle==="top"||t.handle==="bottom"){const l=(r=c.onDoubleClickEdge)==null?void 0:r.call(c,a);if(l){this.editor.mark("double click edge"),this.editor.updateShapes([l]),We(this.editor,[a.id]);return}}if(c.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",t);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}break}case"shape":{const{shape:a}=t,c=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(c.onDoubleClick){const l=(o=c.onDoubleClick)==null?void 0:o.call(c,a);if(l){this.editor.updateShapes([l]);return}else if(c.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((s=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:c}=t,l=this.editor.getShapeUtil(a),u=(i=l.onDoubleClickHandle)==null?void 0:i.call(l,a,c);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,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:Vo/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))&&QC(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=t,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));r.includes(s.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});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(Pt.editOnType.get()&&!VY.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}ZC(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"),hp(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&&er(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(t){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=Be(),{x:o,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:o,y:s,props:{text:"",autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",t))}nudgeSelectedShapes(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new b(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 b(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*ZY:i:o?XY:qY,c=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(c,s.mul(a)),We(this.editor,c)}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},g(Wy,"id","idle"),Wy);const XY=10,qY=1,ZY=5;function QC(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?er(n,t.corners.map(o=>b.RotWith(o,t.point,r))):t.containsPoint(n)}class PM 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=b.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 b(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=so(this.editor,r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),c=i.nearestPoint(b.Add(a,this._labelDragOffset));let l;if(o.isStraight){const u=b.Dist(o.start.point,o.end.point);l=1-b.Dist(o.end.point,c)/u}else{const{_center:u,measure:d,angleEnd:f,angleStart:p}=s.children[0];l=oS(d,p,f,u.angle(c))}isNaN(l)&&(l=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:l}})});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(PM,"id","pointing_arrow_label");class CM 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",()=>{gp(this.editor),this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}g(CM,"id","pointing_canvas");class IM 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=mc[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.parent.transition("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.parent.transition("idle"))}}g(IM,"id","pointing_crop_handle");class EM 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=_n(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=JC(o,t,r,!1);if(s){hp(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=JC(t,r,o,!0);if(s){const i=t.getPointInParentSpace(s,t.inputs.originPagePoint).sub(b.Rot(ew,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:()=>{hp(t,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}g(EM,"id","pointing_handle");function JC(e,n,t,r){const o=e.getShapePageTransform(n.id),s=o.point(),i=o.rotation(),c=z$(s,i,n.props.growY,0)[t.index];if(c)return U$(e,n,c,i,r)}class _M 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:mc[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(_M,"id","pointing_rotate_handle");class kM extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerUp",t=>{gp(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(kM,"id","pointing_selection");class TM 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:c}}=this.editor;this.hitShape=t.shape,this.isDoubleClick=!1;const l=this.editor.getOutermostSelectableShape(t.shape),u=this.editor.findShapeAncestor(l,d=>r.includes(d.id));if(this.editor.getShapeUtil(t.shape).onClick||l.id===s||r.includes(l.id)||u||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=l;return}this.didSelectOnEnter=!0,a&&!c?(this.editor.cancelDoubleClick(),r.includes(l.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,l.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([l.id]))});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,c=this.editor.getShapeAtPoint(i,{margin:Vo/s,hitInside:!0,renderingOnly:!0})??this.hitShape,l=c?this.editor.getOutermostSelectableShape(c):this.hitShapeForPointerUp;if(l){const d=this.editor.getShapeUtil(l);if(d.onClick){const f=(u=d.onClick)==null?void 0:u.call(d,l);if(f){this.editor.mark("shape on click"),this.editor.updateShapes([f]),this.parent.transition("idle",t);return}}if(l.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 d=this.editor.getOutermostSelectableShape(c,f=>!r.includes(f.id));if(r.includes(d.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(l);else if(r.includes(l.id)){if(r.length===1){const f=this.editor.getShapeUtil(l).getGeometry(l),p=wM(f),y=p.length===1?p[0]:void 0;if(y){const m=this.editor.getPointInShapeSpace(l,i);if(y.bounds.containsPoint(m,0)&&y.hitTestPoint(m)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(l.id);const w=this.editor.getShapeUtil(l);this.editor.getInstanceState().isReadonly&&!w.canEditInReadOnly(l)||(this.editor.setEditingShape(l.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:l.id}))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(l.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(l);else if(a){const f=this.editor.getShapeAncestors(d);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(p=>!f.find(y=>y.id===p)),d.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([d.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(TM,"id","pointing_shape");class $M 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",()=>{$x(this.editor)});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=b.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=b.Sub(o,i),c=new Map,l=[];t.forEach(d=>{const f=this.editor.getShape(d);if(f){if(f.type==="frame"&&l.push({id:d,children:ye(this.editor.getSortedChildIdsForParent(f).map(p=>this.editor.getShape(p)))}),c.set(f.id,this._createShapeSnapshot(f)),this.editor.isShapeOfType(f,"frame")&&t.length===1)return;this.editor.visitDescendants(f.id,p=>{const y=this.editor.getShape(p);if(y&&(c.set(y.id,this._createShapeSnapshot(y)),this.editor.isShapeOfType(y,"frame")))return!1})}});const u=![...c.values()].some(d=>!g_(d.pageRotation,r)||d.isAspectRatioLocked);return{shapeSnapshots:c,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:l}});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(We(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 c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onResizeEnd)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:c,selectionRotation:l,canShapesDeform:u}=this.snapshot;let d=r||!u;if(s.size===1){const k=[...s.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(d=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:f}=this.editor.inputs,p=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),y=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!f){const{gridSize:k}=this.editor.getDocumentSettings();p.snapToGrid(k)}const m=this.info.handle,w=eI(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!f:f)&&l%Ve===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:b.Sub(p,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:eI(m,l),isAspectRatioLocked:d,isResizingFromCenter:t});p.add(k)}const v=b.RotWith(t?i.center:i.getHandlePoint(w),i.point,l),P=b.Sub(p,v).rot(-l),E=b.Sub(y,v).rot(-l),C=b.DivV(P,E);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const I=m==="top"||m==="bottom",_=m==="left"||m==="right";d?_?C.y=Math.abs(C.x):I?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(I&&(C.x=1),_&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:l});for(const k of s.keys()){const $=s.get(k);this.editor.resizeShape(k,C,{initialShape:$.shape,initialBounds:$.bounds,initialPageTransform:$.pageTransform,dragHandle:m,mode:c.length===1&&k===c[0]?"resize_bounds":"scale_shape",scaleOrigin:v,isAspectRatioLocked:d,scaleAxisRotation:l,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:$}of o){if(!$.length)continue;const T=s.get(k).shape,O=this.editor.getShape(k);if(!(T&&O))continue;const N=O.x-T.x,A=O.y-T.y,j=new b(N,A).rot(-T.rotation);if(j.x!==0||j.y!==0)for(const L of $)this.editor.updateShape({id:L.id,type:L.type,x:L.x-j.x,y:L.y-j.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of o)if(k.length)for(const $ of k)this.editor.updateShape({id:$.id,type:$.type,x:$.x,y:$.y})}}updateCursor({dragHandle: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($M,"id","resizing");const ly=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function eI(e,n){n=n%Re;const t=Math.round(n/(ke/4)),r=ly.indexOf(e);return ly[(r+t)%ly.length]}const tI=Math.PI/180;class MM 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=c2({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Ih({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:mc[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});Ih({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:mc[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",()=>{Ih({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),We(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:c}=this.snapshot;if(!o)return c;const u=o.center.clone().rotWith(o.point,r).angle(i)-a;let d=c+u;if(s)d=kf(d,24);else if(t&&(d=Math.round(d/tI)*tI,this.editor.getInstanceState().isCoarsePointer)){const f=kf(d,4),p=hh(d,f);Math.abs(p)<aL(5)&&(d=f)}return d-c}}g(MM,"id","rotating");class AM 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:c}}=this.editor,{newlySelectedShapeIds:l,initialSelectedShapeIds:u}=this;t&&this.pushPointToScribble();const d=o;let f,p,y,m;const w=0;for(let P=0,E=d.length;P<E;P++){if(f=d[P],r.isShapeOfType(f,"group")||l.has(f.id)||r.isShapeOrAncestorLocked(f)||(p=r.getShapeGeometry(f),r.isShapeOfType(f,"frame")&&p.bounds.containsPoint(r.getPointInShapeSpace(f,i))))continue;const C=r.getShapePageTransform(f);if(!p||!C)continue;const I=C.clone().invert();y=I.applyToPoint(a),m=I.applyToPoint(c);const{bounds:_}=p;if(!(_.minX-w>Math.max(y.x,m.x)||_.minY-w>Math.max(y.y,m.y)||_.maxX+w<Math.min(y.x,m.x)||_.maxY+w<Math.min(y.y,m.y))&&p.hitTestLineSegment(y,m,w)){const k=this.editor.getOutermostSelectableShape(f),$=this.editor.getShapeMask(k.id);if($&&wx(a,c,$)!==null&&!er(c,$))continue;l.add(k.id)}}const S=r.getSelectedShapeIds(),v=new Set(s?[...l,...u]:[...l]);(S.length!==v.size||S.some(P=>!v.has(P)))&&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(AM,"id","scribble_brushing");const QY=20,JY=100;class eX{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,QY,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearInterval(this.droppingNodeTimer),this.setDragTimer(n,JY,t))}setDragTimer(n,t,r){this.droppingNodeTimer=setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,n,r)}),this.droppingNodeTimer=null},t)}handleDrag(n,t,r){var c,l,u,d,f;t=ye(t.map(p=>this.editor.getShape(p.id)));const o=((c=this.editor.getDroppingOverShape(n,t))==null?void 0:c.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=(l=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(l,i,t)),a&&((f=(d=this.editor.getShapeUtil(a)).onDragShapesOver)==null||f.call(d,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&&L$(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&&clearInterval(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class jM 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 eX(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=nI(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",()=>{this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),$x(this.editor)});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=Pn(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=nI(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),We(this.editor,this.snapshot.movingShapes.map(r=>r.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(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=b.Average(t.map(i=>this.editor.getShapePageTransform(i.id).point())),s=b.Sub(o,this.selectionSnapshot.averagePagePoint);b.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 c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onTranslateEnd)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:t}=this;this.dragAndDropManager.updateDroppingNode(t.movingShapes,this.updateParentTransforms),tX({editor:this.editor,snapshot:t});const{movingShapes:r}=t,o=[];r.forEach(s=>{var l;const i=this.editor.getShape(s.id),a=this.editor.getShapeUtil(s),c=(l=a.onTranslate)==null?void 0:l.call(a,s,i);c&&o.push(c)}),o.length>0&&this.editor.updateShapes(o)}}g(jM,"id","translating");function nI(e){var d;const n=[],t=[],r=e.getSelectedShapeIds(),o=ye(r.map(f=>{const p=e.getShape(f);if(!p)return null;n.push(p);const y=e.getShapePageTransform(f),m=y.point(),w=y.rotation();t.push(m);const S=Go.isId(p.parentId)?null:oe.Inverse(e.getShapePageTransform(p.parentId));return{shape:p,pagePoint:m,pageRotation:w,parentTransform:S}})),s=e.getOnlySelectedShape();let i=[];if(s)i=e.snaps.shapeBounds.getSnapPoints(s.id);else{const f=e.getSelectionPageBounds();f&&(i=f.cornersAndCenter.map((p,y)=>({id:"selection:"+y,x:p.x,y:p.y})))}let a,c;const{originPagePoint:l}=e.inputs,u=o.filter(f=>e.isShapeOfType(f.shape,"note")&&e.isPointInShape(f.shape,l));if(u.length!==0)if(u.length===1)c=u[0];else{const f=e.getCurrentPageShapesSorted();c=(d=u.map(p=>({snapshot:p,index:f.findIndex(y=>y.id===p.shape.id)})).sort((p,y)=>y.index-p.index)[0])==null?void 0:d.snapshot}return c&&(a=B$(e,c.pageRotation,c.shape.props.growY??0)),{averagePagePoint:b.Average(t),movingShapes:n,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:c}}function tX({editor:e,snapshot:n}){const{inputs:t}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:c}=n,l=e.getInstanceState().isGridMode,u=e.getDocumentSettings().gridSize,d=b.Sub(t.currentPagePoint,t.originPagePoint),f=e.inputs.shiftKey?Math.abs(d.x)<Math.abs(d.y)?"x":"y":null;if(f==="x"?d.x=0:f==="y"&&(d.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:w}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:d,initialSelectionPageBounds:s,lockedAxis:f,initialSelectionSnapPoints:i});d.add(w)}else if(r&&o){let w=N$/e.getZoomLevel(),S=new b(0,0);const v=b.Add(b.Add(r.pagePoint,d),new b($e/2,$e/2).rot(r.pageRotation));for(const P of o){const E=b.Sub(v,P),C=E.len();C<w&&(w=C,S=E)}d.sub(S)}const y=b.Add(c,d);l&&!t.ctrlKey&&y.snapToGrid(u);const m=b.Sub(y,c);e.updateShapes(ye(a.map(({shape:w,pagePoint:S,parentTransform:v})=>{const P=b.Add(S,m),E=v?oe.applyToPoint(v,P):P;return{id:w.id,type:w.type,x:E.x,y:E.y}})))}class of 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=Wi("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(of,"id","select"),g(of,"initial","idle"),g(of,"children",()=>[rf,vM,YY,CM,TM,jM,pM,AM,IM,kM,SM,bM,$M,MM,_M,PM,EM,xM]);class OM 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(OM,"id","idle");class DM 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(DM,"id","pointing");class RM extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"zoomBrush",new J);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(J.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(RM,"id","zoom_brushing");class sf 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(sf,"id","zoom"),g(sf,"initial","idle"),g(sf,"children",()=>[OM,RM,DM]);const nX=[ef,tf,nf,sf,of];function Q(){return Q=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},Q.apply(null,arguments)}function ie(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 rX(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function cg(...e){return n=>e.forEach(t=>rX(t,n))}function Xe(...e){return x.useCallback(cg(...e),e)}function Co(e,n=[]){let t=[];function r(s,i){const a=x.createContext(i),c=t.length;t=[...t,i];function l(d){const{scope:f,children:p,...y}=d,m=(f==null?void 0:f[e][c])||a,w=x.useMemo(()=>y,Object.values(y));return x.createElement(m.Provider,{value:w},p)}function u(d,f){const p=(f==null?void 0:f[e][c])||a,y=x.useContext(p);if(y)return y;if(i!==void 0)return i;throw new Error(`\`${d}\` must be used within \`${s}\``)}return l.displayName=s+"Provider",[l,u]}const o=()=>{const s=t.map(i=>x.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,oX(o,...n)]}function oX(...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:c,scopeName:l})=>{const d=c(s)[`__scope${l}`];return{...a,...d}},{});return x.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return t.scopeName=n.scopeName,t}const Ni=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{},sX=TD.useId||(()=>{});let iX=0;function Wo(e){const[n,t]=x.useState(sX());return Ni(()=>{e||t(r=>r??String(iX++))},[e]),e||(n?`radix-${n}`:"")}function un(e){const n=x.useRef(e);return x.useEffect(()=>{n.current=e}),x.useMemo(()=>(...t)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...t)},[])}function ni({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=aX({defaultProp:n,onChange:t}),s=e!==void 0,i=s?e:r,a=un(t),c=x.useCallback(l=>{if(s){const d=typeof l=="function"?l(e):l;d!==e&&a(d)}else o(l)},[s,e,o,a]);return[i,c]}function aX({defaultProp:e,onChange:n}){const t=x.useState(e),[r]=t,o=x.useRef(r),s=un(n);return x.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),t}const zi=x.forwardRef((e,n)=>{const{children:t,...r}=e,o=x.Children.toArray(t),s=o.find(lX);if(s){const i=s.props.children,a=o.map(c=>c===s?x.Children.count(i)>1?x.Children.only(null):x.isValidElement(i)?i.props.children:null:c);return x.createElement($v,Q({},r,{ref:n}),x.isValidElement(i)?x.cloneElement(i,void 0,a):null)}return x.createElement($v,Q({},r,{ref:n}),t)});zi.displayName="Slot";const $v=x.forwardRef((e,n)=>{const{children:t,...r}=e;return x.isValidElement(t)?x.cloneElement(t,{...uX(r,t.props),ref:n?cg(n,t.ref):t.ref}):x.Children.count(t)>1?x.Children.only(null):null});$v.displayName="SlotClone";const cX=({children:e})=>x.createElement(x.Fragment,null,e);function lX(e){return x.isValidElement(e)&&e.type===cX}function uX(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}}const dX=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],He=dX.reduce((e,n)=>{const t=x.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?zi:n;return x.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),x.createElement(a,Q({},i,{ref:o}))});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function cw(e,n){e&&Yi.flushSync(()=>e.dispatchEvent(n))}function hX(e,n=globalThis==null?void 0:globalThis.document){const t=un(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r),()=>n.removeEventListener("keydown",r)},[t,n])}const Mv="dismissableLayer.update",fX="dismissableLayer.pointerDownOutside",pX="dismissableLayer.focusOutside";let rI;const LM=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),lg=x.forwardRef((e,n)=>{var t;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:a,onDismiss:c,...l}=e,u=x.useContext(LM),[d,f]=x.useState(null),p=(t=d==null?void 0:d.ownerDocument)!==null&&t!==void 0?t:globalThis==null?void 0:globalThis.document,[,y]=x.useState({}),m=Xe(n,k=>f(k)),w=Array.from(u.layers),[S]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=w.indexOf(S),P=d?w.indexOf(d):-1,E=u.layersWithOutsidePointerEventsDisabled.size>0,C=P>=v,I=mX(k=>{const $=k.target,T=[...u.branches].some(O=>O.contains($));!C||T||(s==null||s(k),a==null||a(k),k.defaultPrevented||c==null||c())},p),_=yX(k=>{const $=k.target;[...u.branches].some(O=>O.contains($))||(i==null||i(k),a==null||a(k),k.defaultPrevented||c==null||c())},p);return hX(k=>{P===u.layers.size-1&&(o==null||o(k),!k.defaultPrevented&&c&&(k.preventDefault(),c()))},p),x.useEffect(()=>{if(d)return r&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(rI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),oI(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=rI)}},[d,p,r,u]),x.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),oI())},[d,u]),x.useEffect(()=>{const k=()=>y({});return document.addEventListener(Mv,k),()=>document.removeEventListener(Mv,k)},[]),x.createElement(He.div,Q({},l,{ref:m,style:{pointerEvents:E?C?"auto":"none":void 0,...e.style},onFocusCapture:ie(e.onFocusCapture,_.onFocusCapture),onBlurCapture:ie(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:ie(e.onPointerDownCapture,I.onPointerDownCapture)}))}),gX=x.forwardRef((e,n)=>{const t=x.useContext(LM),r=x.useRef(null),o=Xe(n,r);return x.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),x.createElement(He.div,Q({},e,{ref:o}))});function mX(e,n=globalThis==null?void 0:globalThis.document){const t=un(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let u=function(){FM(fX,t,l,{discrete:!0})};var c=u;const l={originalEvent:a};a.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=u,n.addEventListener("click",o.current,{once:!0})):u()}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 yX(e,n=globalThis==null?void 0:globalThis.document){const t=un(e),r=x.useRef(!1);return x.useEffect(()=>{const o=s=>{s.target&&!r.current&&FM(pX,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 oI(){const e=new CustomEvent(Mv);document.dispatchEvent(e)}function FM(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?cw(o,s):o.dispatchEvent(s)}const SX=lg,vX=gX,uy="focusScope.autoFocusOnMount",dy="focusScope.autoFocusOnUnmount",sI={bubbles:!1,cancelable:!0},lw=x.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=x.useState(null),l=un(o),u=un(s),d=x.useRef(null),f=Xe(n,m=>c(m)),p=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let v=function(I){if(p.paused||!a)return;const _=I.target;a.contains(_)?d.current=_:Ss(d.current,{select:!0})},P=function(I){if(p.paused||!a)return;const _=I.relatedTarget;_!==null&&(a.contains(_)||Ss(d.current,{select:!0}))},E=function(I){if(document.activeElement===document.body)for(const k of I)k.removedNodes.length>0&&Ss(a)};var m=v,w=P,S=E;document.addEventListener("focusin",v),document.addEventListener("focusout",P);const C=new MutationObserver(E);return a&&C.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",P),C.disconnect()}}},[r,a,p.paused]),x.useEffect(()=>{if(a){aI.add(p);const m=document.activeElement;if(!a.contains(m)){const S=new CustomEvent(uy,sI);a.addEventListener(uy,l),a.dispatchEvent(S),S.defaultPrevented||(xX(IX(NM(a)),{select:!0}),document.activeElement===m&&Ss(a))}return()=>{a.removeEventListener(uy,l),setTimeout(()=>{const S=new CustomEvent(dy,sI);a.addEventListener(dy,u),a.dispatchEvent(S),S.defaultPrevented||Ss(m??document.body,{select:!0}),a.removeEventListener(dy,u),aI.remove(p)},0)}}},[a,l,u,p]);const y=x.useCallback(m=>{if(!t&&!r||p.paused)return;const w=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,S=document.activeElement;if(w&&S){const v=m.currentTarget,[P,E]=wX(v);P&&E?!m.shiftKey&&S===E?(m.preventDefault(),t&&Ss(P,{select:!0})):m.shiftKey&&S===P&&(m.preventDefault(),t&&Ss(E,{select:!0})):S===v&&m.preventDefault()}},[t,r,p.paused]);return x.createElement(He.div,Q({tabIndex:-1},i,{ref:f,onKeyDown:y}))});function xX(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(Ss(r,{select:n}),document.activeElement!==t)return}function wX(e){const n=NM(e),t=iI(n,e),r=iI(n.reverse(),e);return[t,r]}function NM(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 iI(e,n){for(const t of e)if(!bX(t,{upTo:n}))return t}function bX(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 PX(e){return e instanceof HTMLInputElement&&"select"in e}function Ss(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&PX(e)&&n&&e.select()}}const aI=CX();function CX(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=cI(e,n),e.unshift(n)},remove(n){var t;e=cI(e,n),(t=e[0])===null||t===void 0||t.resume()}}}function cI(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function IX(e){return e.filter(n=>n.tagName!=="A")}const ug=x.forwardRef((e,n)=>{var t;const{container:r=globalThis==null||(t=globalThis.document)===null||t===void 0?void 0:t.body,...o}=e;return r?fz.createPortal(x.createElement(He.div,Q({},o,{ref:n})),r):null});function EX(e,n){return x.useReducer((t,r)=>{const o=n[t][r];return o??t},e)}const Io=e=>{const{present:n,children:t}=e,r=_X(n),o=typeof t=="function"?t({present:r.isPresent}):x.Children.only(t),s=Xe(r.ref,o.ref);return typeof t=="function"||r.isPresent?x.cloneElement(o,{ref:s}):null};Io.displayName="Presence";function _X(e){const[n,t]=x.useState(),r=x.useRef({}),o=x.useRef(e),s=x.useRef("none"),i=e?"mounted":"unmounted",[a,c]=EX(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const l=Vd(r.current);s.current=a==="mounted"?l:"none"},[a]),Ni(()=>{const l=r.current,u=o.current;if(u!==e){const f=s.current,p=Vd(l);e?c("MOUNT"):p==="none"||(l==null?void 0:l.display)==="none"?c("UNMOUNT"):c(u&&f!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),Ni(()=>{if(n){const l=d=>{const p=Vd(r.current).includes(d.animationName);d.target===n&&p&&Yi.flushSync(()=>c("ANIMATION_END"))},u=d=>{d.target===n&&(s.current=Vd(r.current))};return n.addEventListener("animationstart",u),n.addEventListener("animationcancel",l),n.addEventListener("animationend",l),()=>{n.removeEventListener("animationstart",u),n.removeEventListener("animationcancel",l),n.removeEventListener("animationend",l)}}else c("ANIMATION_END")},[n,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:x.useCallback(l=>{l&&(r.current=getComputedStyle(l)),t(l)},[])}}function Vd(e){return(e==null?void 0:e.animationName)||"none"}let hy=0;function uw(){x.useEffect(()=>{var e,n;const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",(e=t[0])!==null&&e!==void 0?e:lI()),document.body.insertAdjacentElement("beforeend",(n=t[1])!==null&&n!==void 0?n:lI()),hy++,()=>{hy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),hy--}},[])}function lI(){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 oo=function(){return oo=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},oo.apply(this,arguments)};function zM(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 kX(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 af="right-scroll-bar-position",cf="width-before-scroll-bar",TX="with-scroll-bars-hidden",$X="--removed-body-scroll-bar-size";function fy(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function MX(e,n){var t=x.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 AX=typeof window<"u"?x.useLayoutEffect:x.useEffect,uI=new WeakMap;function jX(e,n){var t=MX(null,function(r){return e.forEach(function(o){return fy(o,r)})});return AX(function(){var r=uI.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||fy(a,null)}),s.forEach(function(a){o.has(a)||fy(a,i)})}uI.set(t,e)},[e]),t}function OX(e){return e}function DX(e,n){n===void 0&&(n=OX);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 c=function(){var u=i;i=[],u.forEach(s)},l=function(){return Promise.resolve().then(c)};l(),t={push:function(u){i.push(u),l()},filter:function(u){return i=i.filter(u),t}}}};return o}function RX(e){e===void 0&&(e={});var n=DX(null);return n.options=oo({async:!0,ssr:!1},e),n}var BM=function(e){var n=e.sideCar,t=zM(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 x.createElement(r,oo({},t))};BM.isSideCarExport=!0;function LX(e,n){return e.useMedium(n),BM}var UM=RX(),py=function(){},dg=x.forwardRef(function(e,n){var t=x.useRef(null),r=x.useState({onScrollCapture:py,onWheelCapture:py,onTouchMoveCapture:py}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,f=e.sideCar,p=e.noIsolation,y=e.inert,m=e.allowPinchZoom,w=e.as,S=w===void 0?"div":w,v=zM(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),P=f,E=jX([t,n]),C=oo(oo({},v),o);return x.createElement(x.Fragment,null,u&&x.createElement(P,{sideCar:UM,removeScrollBar:l,shards:d,noIsolation:p,inert:y,setCallbacks:s,allowPinchZoom:!!m,lockRef:t}),i?x.cloneElement(x.Children.only(a),oo(oo({},C),{ref:E})):x.createElement(S,oo({},C,{className:c,ref:E}),a))});dg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};dg.classNames={fullWidth:cf,zeroRight:af};var FX=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function NX(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=FX();return n&&e.setAttribute("nonce",n),e}function zX(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function BX(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var UX=function(){var e=0,n=null;return{add:function(t){e==0&&(n=NX())&&(zX(n,t),BX(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},HX=function(){var e=UX();return function(n,t){x.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},HM=function(){var e=HX(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},KX={left:0,top:0,right:0,gap:0},gy=function(e){return parseInt(e||"",10)||0},WX=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[gy(t),gy(r),gy(o)]},GX=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return KX;var n=WX(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])}},VX=HM(),ec="data-scroll-locked",YX=function(e,n,t,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return t===void 0&&(t="margin"),`
168
- .`.concat(TX,` {
169
- overflow: hidden `).concat(r,`;
170
- padding-right: `).concat(a,"px ").concat(r,`;
171
- }
172
- body[`).concat(ec,`] {
173
- overflow: hidden `).concat(r,`;
174
- overscroll-behavior: contain;
175
- `).concat([n&&"position: relative ".concat(r,";"),t==="margin"&&`
176
- padding-left: `.concat(o,`px;
177
- padding-top: `).concat(s,`px;
178
- padding-right: `).concat(i,`px;
179
- margin-left:0;
180
- margin-top:0;
181
- margin-right: `).concat(a,"px ").concat(r,`;
182
- `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
183
- }
184
-
185
- .`).concat(af,` {
186
- right: `).concat(a,"px ").concat(r,`;
187
- }
188
-
189
- .`).concat(cf,` {
190
- margin-right: `).concat(a,"px ").concat(r,`;
191
- }
192
-
193
- .`).concat(af," .").concat(af,` {
194
- right: 0 `).concat(r,`;
195
- }
196
-
197
- .`).concat(cf," .").concat(cf,` {
198
- margin-right: 0 `).concat(r,`;
199
- }
200
-
201
- body[`).concat(ec,`] {
202
- `).concat($X,": ").concat(a,`px;
203
- }
204
- `)},dI=function(){var e=parseInt(document.body.getAttribute(ec)||"0",10);return isFinite(e)?e:0},XX=function(){x.useEffect(function(){return document.body.setAttribute(ec,(dI()+1).toString()),function(){var e=dI()-1;e<=0?document.body.removeAttribute(ec):document.body.setAttribute(ec,e.toString())}},[])},qX=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;XX();var s=x.useMemo(function(){return GX(o)},[o]);return x.createElement(VX,{styles:YX(s,!n,o,t?"":"!important")})},Av=!1;if(typeof window<"u")try{var Yd=Object.defineProperty({},"passive",{get:function(){return Av=!0,!0}});window.addEventListener("test",Yd,Yd),window.removeEventListener("test",Yd,Yd)}catch{Av=!1}var ha=Av?{passive:!1}:!1,ZX=function(e){return e.tagName==="TEXTAREA"},KM=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!ZX(e)&&t[n]==="visible")},QX=function(e){return KM(e,"overflowY")},JX=function(e){return KM(e,"overflowX")},hI=function(e,n){var t=n;do{typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&(t=t.host);var r=WM(e,t);if(r){var o=GM(e,t),s=o[1],i=o[2];if(s>i)return!0}t=t.parentNode}while(t&&t!==document.body);return!1},eq=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},tq=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},WM=function(e,n){return e==="v"?QX(n):JX(n)},GM=function(e,n){return e==="v"?eq(n):tq(n)},nq=function(e,n){return e==="h"&&n==="rtl"?-1:1},rq=function(e,n,t,r,o){var s=nq(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,c=n.contains(a),l=!1,u=i>0,d=0,f=0;do{var p=GM(e,a),y=p[0],m=p[1],w=p[2],S=m-w-s*y;(y||S)&&WM(e,a)&&(d+=S,f+=y),a=a.parentNode}while(!c&&a!==document.body||c&&(n.contains(a)||n===a));return(u&&(d===0||!o)||!u&&(f===0||!o))&&(l=!0),l},Xd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},fI=function(e){return[e.deltaX,e.deltaY]},pI=function(e){return e&&"current"in e?e.current:e},oq=function(e,n){return e[0]===n[0]&&e[1]===n[1]},sq=function(e){return`
205
- .block-interactivity-`.concat(e,` {pointer-events: none;}
206
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
207
- `)},iq=0,fa=[];function aq(e){var n=x.useRef([]),t=x.useRef([0,0]),r=x.useRef(),o=x.useState(iq++)[0],s=x.useState(function(){return HM()})[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=kX([e.lockRef.current],(e.shards||[]).map(pI),!0).filter(Boolean);return m.forEach(function(w){return w.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(m,w){if("touches"in m&&m.touches.length===2)return!i.current.allowPinchZoom;var S=Xd(m),v=t.current,P="deltaX"in m?m.deltaX:v[0]-S[0],E="deltaY"in m?m.deltaY:v[1]-S[1],C,I=m.target,_=Math.abs(P)>Math.abs(E)?"h":"v";if("touches"in m&&_==="h"&&I.type==="range")return!1;var k=hI(_,I);if(!k)return!0;if(k?C=_:(C=_==="v"?"h":"v",k=hI(_,I)),!k)return!1;if(!r.current&&"changedTouches"in m&&(P||E)&&(r.current=C),!C)return!0;var $=r.current||C;return rq($,w,m,$==="h"?P:E,!0)},[]),c=x.useCallback(function(m){var w=m;if(!(!fa.length||fa[fa.length-1]!==s)){var S="deltaY"in w?fI(w):Xd(w),v=n.current.filter(function(C){return C.name===w.type&&C.target===w.target&&oq(C.delta,S)})[0];if(v&&v.should){w.cancelable&&w.preventDefault();return}if(!v){var P=(i.current.shards||[]).map(pI).filter(Boolean).filter(function(C){return C.contains(w.target)}),E=P.length>0?a(w,P[0]):!i.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),l=x.useCallback(function(m,w,S,v){var P={name:m,delta:w,target:S,should:v};n.current.push(P),setTimeout(function(){n.current=n.current.filter(function(E){return E!==P})},1)},[]),u=x.useCallback(function(m){t.current=Xd(m),r.current=void 0},[]),d=x.useCallback(function(m){l(m.type,fI(m),m.target,a(m,e.lockRef.current))},[]),f=x.useCallback(function(m){l(m.type,Xd(m),m.target,a(m,e.lockRef.current))},[]);x.useEffect(function(){return fa.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",c,ha),document.addEventListener("touchmove",c,ha),document.addEventListener("touchstart",u,ha),function(){fa=fa.filter(function(m){return m!==s}),document.removeEventListener("wheel",c,ha),document.removeEventListener("touchmove",c,ha),document.removeEventListener("touchstart",u,ha)}},[]);var p=e.removeScrollBar,y=e.inert;return x.createElement(x.Fragment,null,y?x.createElement(s,{styles:sq(o)}):null,p?x.createElement(qX,{gapMode:"margin"}):null)}const cq=LX(UM,aq);var hg=x.forwardRef(function(e,n){return x.createElement(dg,oo({},e,{ref:n,sideCar:cq}))});hg.classNames=dg.classNames;var lq=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},pa=new WeakMap,qd=new WeakMap,Zd={},my=0,VM=function(e){return e&&(e.host||VM(e.parentNode))},uq=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=VM(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})},dq=function(e,n,t,r){var o=uq(n,Array.isArray(e)?e:[e]);Zd[t]||(Zd[t]=new WeakMap);var s=Zd[t],i=[],a=new Set,c=new Set(o),l=function(d){!d||a.has(d)||(a.add(d),l(d.parentNode))};o.forEach(l);var u=function(d){!d||c.has(d)||Array.prototype.forEach.call(d.children,function(f){if(a.has(f))u(f);else try{var p=f.getAttribute(r),y=p!==null&&p!=="false",m=(pa.get(f)||0)+1,w=(s.get(f)||0)+1;pa.set(f,m),s.set(f,w),i.push(f),m===1&&y&&qd.set(f,!0),w===1&&f.setAttribute(t,"true"),y||f.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",f,S)}})};return u(n),a.clear(),my++,function(){i.forEach(function(d){var f=pa.get(d)-1,p=s.get(d)-1;pa.set(d,f),s.set(d,p),f||(qd.has(d)||d.removeAttribute(r),qd.delete(d)),p||d.removeAttribute(t)}),my--,my||(pa=new WeakMap,pa=new WeakMap,qd=new WeakMap,Zd={})}},dw=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=lq(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),dq(r,o,t,"aria-hidden")):function(){return null}};const YM="Dialog",[XM,ose]=Co(YM),[hq,is]=XM(YM),fq=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),c=x.useRef(null),[l=!1,u]=ni({prop:r,defaultProp:o,onChange:s});return x.createElement(hq,{scope:n,triggerRef:a,contentRef:c,contentId:Wo(),titleId:Wo(),descriptionId:Wo(),open:l,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(d=>!d),[u]),modal:i},t)},qM="DialogPortal",[pq,ZM]=XM(qM,{forceMount:void 0}),gq=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=is(qM,n);return x.createElement(pq,{scope:n,forceMount:t},x.Children.map(r,i=>x.createElement(Io,{present:t||s.open},x.createElement(ug,{asChild:!0,container:o},i))))},jv="DialogOverlay",mq=x.forwardRef((e,n)=>{const t=ZM(jv,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=is(jv,e.__scopeDialog);return s.modal?x.createElement(Io,{present:r||s.open},x.createElement(yq,Q({},o,{ref:n}))):null}),yq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=is(jv,t);return x.createElement(hg,{as:zi,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(He.div,Q({"data-state":JM(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),fu="DialogContent",Sq=x.forwardRef((e,n)=>{const t=ZM(fu,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=is(fu,e.__scopeDialog);return x.createElement(Io,{present:r||s.open},s.modal?x.createElement(vq,Q({},o,{ref:n})):x.createElement(xq,Q({},o,{ref:n})))}),vq=x.forwardRef((e,n)=>{const t=is(fu,e.__scopeDialog),r=x.useRef(null),o=Xe(n,t.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return dw(s)},[]),x.createElement(QM,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ie(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:ie(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault())}))}),xq=x.forwardRef((e,n)=>{const t=is(fu,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(QM,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),QM=x.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=is(fu,t),c=x.useRef(null),l=Xe(n,c);return uw(),x.createElement(x.Fragment,null,x.createElement(lw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(lg,Q({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":JM(a.open)},i,{ref:l,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),wq="DialogTitle",bq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=is(wq,t);return x.createElement(He.h2,Q({id:o.titleId},r,{ref:n}))});const Pq="DialogClose",Cq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=is(Pq,t);return x.createElement(He.button,Q({type:"button"},r,{ref:n,onClick:ie(e.onClick,()=>o.onOpenChange(!1))}))});function JM(e){return e?"open":"closed"}const Iq=fq,Eq=gq,_q=mq,kq=Sq,eA=()=>{},tA=x.createContext(null);function Tq({onEvent:e,children:n}){return h.jsx(tA.Provider,{value:e??eA,children:n})}function Eo(){return x.useContext(tA)??eA}const nA=x.createContext(null);function $q({children:e}){const n=B(),t=Eo(),[r,o]=x.useState([]),s=x.useCallback(l=>{const u=l.id??ot();return o(d=>[...d.filter(f=>f.id!==l.id),{...l,id:u}]),t("open-menu",{source:"dialog",id:u}),n.addOpenMenu(u),u},[n,t]),i=x.useCallback((l,u)=>(o(d=>d.map(f=>f.id===l?{...f,...u}:f)),t("open-menu",{source:"dialog",id:l}),n.addOpenMenu(l),l),[n,t]),a=x.useCallback(l=>(o(u=>u.filter(d=>{var f;return d.id===l?((f=d.onClose)==null||f.call(d),!1):!0})),t("close-menu",{source:"dialog",id:l}),n.deleteOpenMenu(l),l),[n,t]),c=x.useCallback(()=>{o(l=>(l.forEach(u=>{var d;(d=u.onClose)==null||d.call(u),t("close-menu",{source:"dialog",id:u.id}),n.deleteOpenMenu(u.id)}),[]))},[n,t]);return h.jsx(nA.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:c,updateDialog:i},children:e})}function Qi(){const e=x.useContext(nA);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}=Qi(),o=dn(),s=x.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return h.jsx(Iq,{onOpenChange:s,defaultOpen:!0,children:h.jsx(Eq,{container:o,children:h.jsx(_q,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:h.jsx(kq,{dir:"ltr",className:"tlui-dialog__content",children:h.jsx(n,{onClose:()=>s(!1)})})})})})};function Aq(){const{dialogs:e}=Qi();return h.jsx(h.Fragment,{children:e.map(n=>h.jsx(Mq,{...n},n.id))})}const jq=Se.memo(Aq);function Oq(){const e=B(),n=W("follow",()=>e.getInstanceState().followingUserId,[e]);return n?h.jsx(Dq,{userId:n}):null}function Dq({userId:e}){const n=B_(e);return n?h.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function fg(e){const n=e+"CollectionProvider",[t,r]=Co(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:y,children:m}=p,w=Se.useRef(null),S=Se.useRef(new Map).current;return Se.createElement(o,{scope:y,itemMap:S,collectionRef:w},m)},a=e+"CollectionSlot",c=Se.forwardRef((p,y)=>{const{scope:m,children:w}=p,S=s(a,m),v=Xe(y,S.collectionRef);return Se.createElement(zi,{ref:v},w)}),l=e+"CollectionItemSlot",u="data-radix-collection-item",d=Se.forwardRef((p,y)=>{const{scope:m,children:w,...S}=p,v=Se.useRef(null),P=Xe(y,v),E=s(l,m);return Se.useEffect(()=>(E.itemMap.set(v,{ref:v,...S}),()=>void E.itemMap.delete(v))),Se.createElement(zi,{[u]:"",ref:P},w)});function f(p){const y=s(e+"CollectionConsumer",p);return Se.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${u}]`));return Array.from(y.itemMap.values()).sort((E,C)=>S.indexOf(E.ref.current)-S.indexOf(C.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:c,ItemSlot:d},f,r]}const rA=x.forwardRef((e,n)=>x.createElement(He.span,Q({},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}}))),oA="ToastProvider",[hw,Rq,Lq]=fg("Toast"),[sA,sse]=Co("Toast",[Lq]),[Fq,pg]=sA(oA),iA=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,c]=x.useState(null),[l,u]=x.useState(0),d=x.useRef(!1),f=x.useRef(!1);return x.createElement(hw.Provider,{scope:n},x.createElement(Fq,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:l,viewport:a,onViewportChange:c,onToastAdd:x.useCallback(()=>u(p=>p+1),[]),onToastRemove:x.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:d,isClosePausedRef:f},i))};iA.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const n=`Invalid prop \`label\` supplied to \`${oA}\`. Expected non-empty \`string\`.`;return new Error(n)}return null}};const Nq="ToastViewport",zq=["F8"],Ov="toast.viewportPause",Dv="toast.viewportResume",Bq=x.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=zq,label:o="Notifications ({hotkey})",...s}=e,i=pg(Nq,t),a=Rq(t),c=x.useRef(null),l=x.useRef(null),u=x.useRef(null),d=x.useRef(null),f=Xe(n,d,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=i.toastCount>0;x.useEffect(()=>{const w=S=>{var v;r.every(E=>S[E]||S.code===E)&&((v=d.current)===null||v===void 0||v.focus())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[r]),x.useEffect(()=>{const w=c.current,S=d.current;if(y&&w&&S){const v=()=>{if(!i.isClosePausedRef.current){const I=new CustomEvent(Ov);S.dispatchEvent(I),i.isClosePausedRef.current=!0}},P=()=>{if(i.isClosePausedRef.current){const I=new CustomEvent(Dv);S.dispatchEvent(I),i.isClosePausedRef.current=!1}},E=I=>{!w.contains(I.relatedTarget)&&P()},C=()=>{w.contains(document.activeElement)||P()};return w.addEventListener("focusin",v),w.addEventListener("focusout",E),w.addEventListener("pointermove",v),w.addEventListener("pointerleave",C),window.addEventListener("blur",v),window.addEventListener("focus",P),()=>{w.removeEventListener("focusin",v),w.removeEventListener("focusout",E),w.removeEventListener("pointermove",v),w.removeEventListener("pointerleave",C),window.removeEventListener("blur",v),window.removeEventListener("focus",P)}}},[y,i.isClosePausedRef]);const m=x.useCallback(({tabbingDirection:w})=>{const v=a().map(P=>{const E=P.ref.current,C=[E,...rZ(E)];return w==="forwards"?C:C.reverse()});return(w==="forwards"?v.reverse():v).flat()},[a]);return x.useEffect(()=>{const w=d.current;if(w){const S=v=>{const P=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!P){const k=document.activeElement,$=v.shiftKey;if(v.target===w&&$){var C;(C=l.current)===null||C===void 0||C.focus();return}const N=m({tabbingDirection:$?"backwards":"forwards"}),A=N.findIndex(j=>j===k);if(yy(N.slice(A+1)))v.preventDefault();else{var I,_;$?(I=l.current)===null||I===void 0||I.focus():(_=u.current)===null||_===void 0||_.focus()}}};return w.addEventListener("keydown",S),()=>w.removeEventListener("keydown",S)}},[a,m]),x.createElement(vX,{ref:c,role:"region","aria-label":o.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:y?void 0:"none"}},y&&x.createElement(gI,{ref:l,onFocusFromOutsideViewport:()=>{const w=m({tabbingDirection:"forwards"});yy(w)}}),x.createElement(hw.Slot,{scope:t},x.createElement(He.ol,Q({tabIndex:-1},s,{ref:f}))),y&&x.createElement(gI,{ref:u,onFocusFromOutsideViewport:()=>{const w=m({tabbingDirection:"backwards"});yy(w)}}))}),Uq="ToastFocusProxy",gI=x.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=pg(Uq,t);return x.createElement(rA,Q({"aria-hidden":!0,tabIndex:0},o,{ref:n,style:{position:"fixed"},onFocus:i=>{var a;const c=i.relatedTarget;!((a=s.viewport)!==null&&a!==void 0&&a.contains(c))&&r()}}))}),gg="Toast",Hq="toast.swipeStart",Kq="toast.swipeMove",Wq="toast.swipeCancel",Gq="toast.swipeEnd",Vq=x.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,c]=ni({prop:r,defaultProp:o,onChange:s});return x.createElement(Io,{present:t||a},x.createElement(aA,Q({open:a},i,{ref:n,onClose:()=>c(!1),onPause:un(e.onPause),onResume:un(e.onResume),onSwipeStart:ie(e.onSwipeStart,l=>{l.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ie(e.onSwipeMove,l=>{const{x:u,y:d}=l.detail.delta;l.currentTarget.setAttribute("data-swipe","move"),l.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),l.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${d}px`)}),onSwipeCancel:ie(e.onSwipeCancel,l=>{l.currentTarget.setAttribute("data-swipe","cancel"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),l.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:ie(e.onSwipeEnd,l=>{const{x:u,y:d}=l.detail.delta;l.currentTarget.setAttribute("data-swipe","end"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),l.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),l.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${d}px`),c(!1)})})))}),[Yq,Xq]=sA(gg,{onClose(){}}),aA=x.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:c,onResume:l,onSwipeStart:u,onSwipeMove:d,onSwipeCancel:f,onSwipeEnd:p,...y}=e,m=pg(gg,t),[w,S]=x.useState(null),v=Xe(n,j=>S(j)),P=x.useRef(null),E=x.useRef(null),C=o||m.duration,I=x.useRef(0),_=x.useRef(C),k=x.useRef(0),{onToastAdd:$,onToastRemove:T}=m,O=un(()=>{var j;(w==null?void 0:w.contains(document.activeElement))&&((j=m.viewport)===null||j===void 0||j.focus()),i()}),N=x.useCallback(j=>{!j||j===1/0||(window.clearTimeout(k.current),I.current=new Date().getTime(),k.current=window.setTimeout(O,j))},[O]);x.useEffect(()=>{const j=m.viewport;if(j){const L=()=>{N(_.current),l==null||l()},X=()=>{const V=new Date().getTime()-I.current;_.current=_.current-V,window.clearTimeout(k.current),c==null||c()};return j.addEventListener(Ov,X),j.addEventListener(Dv,L),()=>{j.removeEventListener(Ov,X),j.removeEventListener(Dv,L)}}},[m.viewport,C,c,l,N]),x.useEffect(()=>{s&&!m.isClosePausedRef.current&&N(C)},[s,C,m.isClosePausedRef,N]),x.useEffect(()=>($(),()=>T()),[$,T]);const A=x.useMemo(()=>w?dA(w):null,[w]);return m.viewport?x.createElement(x.Fragment,null,A&&x.createElement(qq,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},A),x.createElement(Yq,{scope:t,onClose:O},Yi.createPortal(x.createElement(hw.ItemSlot,{scope:t},x.createElement(SX,{asChild:!0,onEscapeKeyDown:ie(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||O(),m.isFocusedToastEscapeKeyDownRef.current=!1})},x.createElement(He.li,Q({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:ie(e.onKeyDown,j=>{j.key==="Escape"&&(a==null||a(j.nativeEvent),j.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,O()))}),onPointerDown:ie(e.onPointerDown,j=>{j.button===0&&(P.current={x:j.clientX,y:j.clientY})}),onPointerMove:ie(e.onPointerMove,j=>{if(!P.current)return;const L=j.clientX-P.current.x,X=j.clientY-P.current.y,V=!!E.current,H=["left","right"].includes(m.swipeDirection),U=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,K=H?U(0,L):0,Z=H?0:U(0,X),le=j.pointerType==="touch"?10:2,be={x:K,y:Z},Ae={originalEvent:j,delta:be};V?(E.current=be,Qd(Kq,d,Ae,{discrete:!1})):mI(be,m.swipeDirection,le)?(E.current=be,Qd(Hq,u,Ae,{discrete:!1}),j.target.setPointerCapture(j.pointerId)):(Math.abs(L)>le||Math.abs(X)>le)&&(P.current=null)}),onPointerUp:ie(e.onPointerUp,j=>{const L=E.current,X=j.target;if(X.hasPointerCapture(j.pointerId)&&X.releasePointerCapture(j.pointerId),E.current=null,P.current=null,L){const V=j.currentTarget,H={originalEvent:j,delta:L};mI(L,m.swipeDirection,m.swipeThreshold)?Qd(Gq,p,H,{discrete:!0}):Qd(Wq,f,H,{discrete:!0}),V.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})))),m.viewport))):null});aA.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const n=`Invalid prop \`type\` supplied to \`${gg}\`. Expected \`foreground | background\`.`;return new Error(n)}return null}};const qq=e=>{const{__scopeToast:n,children:t,...r}=e,o=pg(gg,n),[s,i]=x.useState(!1),[a,c]=x.useState(!1);return tZ(()=>i(!0)),x.useEffect(()=>{const l=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(l)},[]),a?null:x.createElement(ug,{asChild:!0},x.createElement(rA,r,s&&x.createElement(x.Fragment,null,o.label," ",t)))},Zq=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return x.createElement(He.div,Q({},r,{ref:n}))}),Qq=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return x.createElement(He.div,Q({},r,{ref:n}))}),Jq="ToastAction",cA=x.forwardRef((e,n)=>{const{altText:t,...r}=e;return t?x.createElement(uA,{altText:t,asChild:!0},x.createElement(lA,Q({},r,{ref:n}))):null});cA.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${Jq}\``)}};const eZ="ToastClose",lA=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=Xq(eZ,t);return x.createElement(uA,{asChild:!0},x.createElement(He.button,Q({type:"button"},r,{ref:n,onClick:ie(e.onClick,o.onClose)})))}),uA=x.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return x.createElement(He.div,Q({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0},o,{ref:n}))});function dA(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),nZ(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(...dA(r))}}),n}function Qd(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?cw(o,s):o.dispatchEvent(s)}const mI=(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 tZ(e=()=>{}){const n=un(e);Ni(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function nZ(e){return e.nodeType===e.ELEMENT_NODE}function rZ(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 yy(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}const oZ=Vq,sZ=Zq,iZ=Qq,aZ=cA,yI=lA,hA=x.createContext(null);function cZ({children:e}){const[n,t]=x.useState([]),r=x.useCallback(i=>{const a=i.id??ot();return t(c=>[...c.filter(l=>l.id!==i.id),{...i,id:a}]),a},[]),o=x.useCallback(i=>(t(a=>a.filter(c=>c.id!==i)),i),[]),s=x.useCallback(()=>{t(()=>[])},[]);return h.jsx(iA,{children:h.jsx(hA.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})})}function Yr(){const e=x.useContext(hA);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const he=x.forwardRef(function({children:n,disabled:t,type:r,...o},s){return h.jsx("button",{ref:s,type:"button",draggable:!1,disabled:t,...o,className:ue("tlui-button",`tlui-button__${r}`,o.className),children:n})});function It({children:e}){return h.jsx("span",{className:"tlui-button__label",children:e})}const Ws=x.memo(function({small:n,invertIcon:t,icon:r,color:o,className:s,...i}){const a=iw(),c=a.icons[r]??a.icons["question-mark-circle"],l=x.useRef(null);return x.useLayoutEffect(()=>{c||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),l!=null&&l.current&&(l.current.style.webkitMask=`url(${c}) center 100% / 100% no-repeat`)},[l,c,r]),r==="none"?h.jsx("div",{className:ue("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":n},s)}):h.jsx("div",{...i,ref:l,className:ue("tlui-icon",{"tlui-icon__small":n},s),style:{color:o,mask:`url(${c}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})}),lZ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function uZ({toast:e}){const{removeToast:n}=Yr(),t=Me(),r=i=>{i||n(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&lZ[e.severity];return h.jsxs(oZ,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&h.jsx("div",{className:"tlui-toast__icon",children:h.jsx(Ws,{icon:s})}),h.jsxs("div",{className:"tlui-toast__main",children:[h.jsxs("div",{className:"tlui-toast__content",children:[e.title&&h.jsx(sZ,{className:"tlui-toast__title",children:e.title}),e.description&&h.jsx(iZ,{className:"tlui-toast__description",children:e.description})]}),e.actions&&h.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>h.jsx(aZ,{altText:i.label,asChild:!0,onClick:i.onClick,children:h.jsx(he,{type:i.type,children:h.jsx(It,{children:i.label})})},a)),h.jsx(yI,{asChild:!0,children:h.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:h.jsx(It,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&h.jsx(yI,{asChild:!0,children:h.jsx(he,{type:"normal",className:"tlui-toast__close",children:h.jsx(It,{children:e.closeLabel??t("toast.close")})})})]})}function dZ(){const{toasts:e}=Yr();return h.jsx(h.Fragment,{children:e.map(n=>h.jsx(uZ,{toast:n},n.id))})}const hZ=x.memo(dZ);function fZ(){const{toasts:e}=Yr(),[n,t]=x.useState(!1);return x.useEffect(()=>{let r=!1;return e.length?t(!0):setTimeout(()=>{r||t(!1)},1e3),()=>{r=!0}},[e.length,t]),n?h.jsx(Bq,{className:"tlui-toast__viewport"}):null}function Pe({icon:e,small:n,invertIcon:t}){return h.jsx(Ws,{className:"tlui-button__icon",icon:e,small:n,invertIcon:t})}const wi="2.2.0-canary.e474f51745ec";let Rv={fonts:{draw:`https://unpkg.com/@tldraw/assets@${wi}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${wi}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${wi}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${wi}/fonts/IBMPlexMono-Medium.woff2`}};function fA(e){return x.useMemo(()=>e?{fonts:{...Rv.fonts,...e==null?void 0:e.fonts}}:Rv,[e])}const pZ=["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-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 il={...Rv,icons:Object.fromEntries(pZ.map(e=>[e,`https://unpkg.com/@tldraw/assets@${wi}/icons/icon/${e}.svg`])),translations:Object.fromEntries(Hl.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${wi}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(_u.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${wi}/embed-icons/${e.type}.png`]))};function gZ(e){return e?{fonts:Object.assign({...il.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...il.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...il.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...il.translations},{...e==null?void 0:e.translations})}:il}function mg({className:e,children:n}){return h.jsx("div",{className:ue("tlui-dialog__header",e),children:n})}function yg({className:e,children:n}){return h.jsx(bq,{dir:"ltr",className:ue("tlui-dialog__header__title",e),children:n})}function Sg(){return h.jsx("div",{className:"tlui-dialog__header__close",children:h.jsx(Cq,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:h.jsx(he,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:h.jsx(Pe,{small:!0,icon:"cross-2"})})})})}function pu({className:e,children:n,style:t}){return h.jsx("div",{className:ue("tlui-dialog__body",e),style:t,children:n})}function fw({className:e,children:n}){return h.jsx("div",{className:ue("tlui-dialog__footer",e),children:n})}const pw=x.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:c,onComplete:l,onValueChange:u,onCancel:d,onFocus:f,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:y=!1,children:m,value:w},S){const v=B(),P=x.useRef(null);x.useImperativeHandle(S,()=>P.current);const E=Me(),C=x.useRef(a??""),I=x.useRef(a??""),[_,k]=x.useState(!1),$=x.useCallback(A=>{k(!0);const j=A.currentTarget;I.current=j.value,requestAnimationFrame(()=>{s&&j.select()}),f==null||f()},[s,f]),T=x.useCallback(A=>{const j=A.currentTarget.value;I.current=j,u==null||u(j)},[u]),O=x.useCallback(A=>{switch(A.key){case"Enter":{A.currentTarget.blur(),Ht(A),l==null||l(A.currentTarget.value);break}case"Escape":{A.currentTarget.value=C.current,A.currentTarget.blur(),Ht(A),d==null||d(A.currentTarget.value);break}}},[l,d]),N=x.useCallback(A=>{k(!1);const j=A.currentTarget.value;p==null||p(j)},[p]);return x.useEffect(()=>{if(!v.environment.isIos)return;const A=window.visualViewport;if(_&&y&&A){const j=()=>{var L;(L=P.current)==null||L.scrollIntoView({block:"center"})};return A.addEventListener("resize",j),A.addEventListener("scroll",j),requestAnimationFrame(()=>{var L;(L=P.current)==null||L.scrollIntoView({block:"center"})}),()=>{A.removeEventListener("resize",j),A.removeEventListener("scroll",j)}}},[v,_,y]),h.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,t&&h.jsx("label",{children:E(t)}),o&&h.jsx(Ws,{icon:o,className:"tlui-icon-left",small:!0}),h.jsx("input",{ref:P,className:ue("tlui-input",n),type:"text",defaultValue:a,onKeyUp:O,onChange:T,onFocus:$,onBlur:N,autoFocus:i,placeholder:c,value:w}),r&&h.jsx(Ws,{icon:r,small:!!t})]})}),pA=ir(function({onClose:n}){const t=B(),r=Me(),o=iw(),[s,i]=x.useState(null),[a,c]=x.useState(""),[l,u]=x.useState(null),[d,f]=x.useState(!1),p=x.useRef(-1);return h.jsxs(h.Fragment,{children:[h.jsxs(mg,{children:[h.jsx(yg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),h.jsx(Sg,{})]}),s?h.jsxs(h.Fragment,{children:[h.jsxs(pu,{className:"tlui-embed-dialog__enter",children:[h.jsx(pw,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:y=>{c(y);const m=ks(y);u(m&&m.definition.type===s.type?m:null),f(!1),clearTimeout(p.current),p.current=setTimeout(()=>f(!m),320)}}),a===""?h.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[h.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&h.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",h.jsx(Ws,{icon:"external-link",small:!0})]})]}):h.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),h.jsxs(fw,{className:"tlui-dialog__footer__actions",children:[h.jsx(he,{type:"normal",onClick:()=>{i(null),u(null),c("")},children:h.jsx(It,{children:r("embed-dialog.back")})}),h.jsx("div",{className:"tlui-embed__spacer"}),h.jsx(he,{type:"normal",onClick:n,children:h.jsx(It,{children:r("embed-dialog.cancel")})}),h.jsx(he,{type:"primary",disabled:!l,onClick:()=>{l&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:l.definition}),n())},children:h.jsx(It,{children:r("embed-dialog.create")})})]})]}):h.jsx(h.Fragment,{children:h.jsx(pu,{className:"tlui-embed-dialog__list",children:_u.map(y=>h.jsxs(he,{type:"menu",onClick:()=>i(y),children:[h.jsx(It,{children:y.title}),h.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})]},y.type))})})]})});function gA(){const e=B(),n=x.useRef();return x.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept=SR,t.multiple=!0,n.current=t;async function r(o){const s=o.target.files;!s||s.length===0||(await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),t.value="")}return t.addEventListener("change",r),()=>{n.current=void 0,t.removeEventListener("change",r)}},[e]),x.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}const mA=x.createContext(null);function mZ({overrides:e,children:n}){const t=B(),r=Eo(),{addDialog:o}=Qi(),s=gA(),i=x.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(l){t.setCurrentTool("select"),r("select-tool",{source:l,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(l){t.setCurrentTool("hand"),r("select-tool",{source:l,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(l){t.setCurrentTool("eraser"),r("select-tool",{source:l,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(l){t.setCurrentTool("draw"),r("select-tool",{source:l,id:"draw"})}},...[...co.values].map(l=>({id:l,label:`tool.${l}`,meta:{geo:l},kbd:l==="rectangle"?"r":l==="ellipse"?"o":void 0,icon:"geo-"+l,onSelect(u){t.batch(()=>{t.setStyleForNextShapes(co,l),t.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${l}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(l){t.setCurrentTool("arrow"),r("select-tool",{source:l,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(l){t.setCurrentTool("line"),r("select-tool",{source:l,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(l){t.setCurrentTool("frame"),r("select-tool",{source:l,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(l){t.setCurrentTool("text"),r("select-tool",{source:l,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(l){s(),r("select-tool",{source:l,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(l){t.setCurrentTool("note"),r("select-tool",{source:l,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(l){t.setCurrentTool("laser"),r("select-tool",{source:l,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(l){o({component:pA}),r("select-tool",{source:l,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(l){t.setCurrentTool("highlight"),r("select-tool",{source:l,id:"highlight"})}}];a.push();const c=Object.fromEntries(a.map(l=>[l.id,l]));return e?e(t,c,{insertMedia:s}):c},[e,t,r,s,o]);return h.jsx(mA.Provider,{value:i,children:n})}function vg(){const e=x.useContext(mA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const yA=Se.createContext(null);function yZ({forceMobile:e=!1,children:n}){const t=B(),r=W("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?wt.MOBILE_SM:cy.length-1;for(let i=0;i<s;i++)if(o>cy[i]&&o<=cy[i+1])return i;return s},[t]);return h.jsx(yA.Provider,{value:r,children:n})}function zn(){const e=x.useContext(yA);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function SZ(){const{addToast:e,removeToast:n,clearToasts:t}=Yr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=Qi(),c=zn()<wt.TABLET_SM,l=Me();return x.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:l,isMobile:c}),[r,e,o,t,l,s,n,i,c])}function vZ(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of An(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 SA(e){return x.useMemo(()=>e,e)}function xZ(e){const n=SA(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of An(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function wZ(e){const n=SZ(),t=SA(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>vZ(t,n),[t,n])}function bZ(e,n){const t=ye(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 PZ=50;function CZ(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=ye(o.map(p=>e.getShape(p)));if(!s.length)return;const i=J.FromPoints(s.flatMap(p=>{const y=e.getShapeGeometry(p.id);return e.getShapeLocalTransform(p).applyToPoints(y.vertices)})),{padding:a=PZ}=t,c=i.w+2*a,l=i.h+2*a,u=a-i.minX,d=a-i.minY;if(u===0&&d===0&&r.props.w===c&&r.props.h===l)return;const f=new b(u,d).rot(r.rotation);e.batch(()=>{const p=o.map(y=>{const m=e.getShape(y);return{id:m.id,type:m.type,x:m.x+u,y:m.y+d}});p.push({id:r.id,type:r.type,x:r.x-f.x,y:r.y-f.y,props:{w:c,h:l}}),e.updateShapes(p)})}function SI(e){return rr.isValid(e)?{isValid:!0,hasProtocol:!0}:rr.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const IZ=ir(function({onClose:n}){const r=B().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?h.jsx(EZ,{onClose:n,selectedShape:r}):null}),EZ=ir(function({onClose:n,selectedShape:t}){const r=B(),o=Me(),s=x.useRef(null);x.useEffect(()=>{requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[]);const i=x.useRef(t.props.url),[a,c]=x.useState(()=>{const y=SI(t.props.url),m=y.isValid===!0?y.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:m,safe:m,valid:!0}}),l=x.useCallback(y=>{const m=y.replace(/https?:\/\/(https?:\/\/)/,(v,P)=>P),w=SI(m),S=w.isValid===!0?w.hasProtocol?m:"https://"+m:"https://";c({actual:m,safe:S,valid:w.isValid})},[]),u=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),n())},[r,n]),d=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),n())},[r,n,a]),f=x.useCallback(()=>{n()},[n]);if(!t)return n(),null;const p=i.current&&!a.valid;return h.jsxs(h.Fragment,{children:[h.jsxs(mg,{children:[h.jsx(yg,{children:o("edit-link-dialog.title")}),h.jsx(Sg,{})]}),h.jsx(pu,{children:h.jsxs("div",{className:"tlui-edit-link-dialog",children:[h.jsx(pw,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:l,onComplete:d,onCancel:f}),h.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),h.jsxs(fw,{className:"tlui-dialog__footer__actions",children:[h.jsx(he,{type:"normal",onClick:f,onTouchEnd:f,children:h.jsx(It,{children:o("edit-link-dialog.cancel")})}),p?h.jsx(he,{type:"danger",onTouchEnd:u,onClick:u,children:h.jsx(It,{children:o("edit-link-dialog.clear")})}):h.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:h.jsx(It,{children:o("edit-link-dialog.save")})})]})]})});var gw={exports:{}};gw.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(c,l){if(!s[c]){s[c]={};for(var u=0;u<c.length;u++)s[c][c.charAt(u)]=u}return s[c][l]}var a={compressToBase64:function(c){if(c==null)return"";var l=a._compress(c,6,function(u){return r.charAt(u)});switch(l.length%4){default:case 0:return l;case 1:return l+"===";case 2:return l+"==";case 3:return l+"="}},decompressFromBase64:function(c){return c==null?"":c==""?null:a._decompress(c.length,32,function(l){return i(r,c.charAt(l))})},compressToUTF16:function(c){return c==null?"":a._compress(c,15,function(l){return t(l+32)})+" "},decompressFromUTF16:function(c){return c==null?"":c==""?null:a._decompress(c.length,16384,function(l){return c.charCodeAt(l)-32})},compressToUint8Array:function(c){for(var l=a.compress(c),u=new Uint8Array(l.length*2),d=0,f=l.length;d<f;d++){var p=l.charCodeAt(d);u[d*2]=p>>>8,u[d*2+1]=p%256}return u},decompressFromUint8Array:function(c){if(c==null)return a.decompress(c);for(var l=new Array(c.length/2),u=0,d=l.length;u<d;u++)l[u]=c[u*2]*256+c[u*2+1];var f=[];return l.forEach(function(p){f.push(t(p))}),a.decompress(f.join(""))},compressToEncodedURIComponent:function(c){return c==null?"":a._compress(c,6,function(l){return o.charAt(l)})},decompressFromEncodedURIComponent:function(c){return c==null?"":c==""?null:(c=c.replace(/ /g,"+"),a._decompress(c.length,32,function(l){return i(o,c.charAt(l))}))},compress:function(c){return a._compress(c,16,function(l){return t(l)})},_compress:function(c,l,u){if(c==null)return"";var d,f,p={},y={},m="",w="",S="",v=2,P=3,E=2,C=[],I=0,_=0,k;for(k=0;k<c.length;k+=1)if(m=c.charAt(k),Object.prototype.hasOwnProperty.call(p,m)||(p[m]=P++,y[m]=!0),w=S+m,Object.prototype.hasOwnProperty.call(p,w))S=w;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<E;d++)I=I<<1,_==l-1?(_=0,C.push(u(I)),I=0):_++;for(f=S.charCodeAt(0),d=0;d<8;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1}else{for(f=1,d=0;d<E;d++)I=I<<1|f,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=0;for(f=S.charCodeAt(0),d=0;d<16;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete y[S]}else for(f=p[S],d=0;d<E;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1;v--,v==0&&(v=Math.pow(2,E),E++),p[w]=P++,S=String(m)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<E;d++)I=I<<1,_==l-1?(_=0,C.push(u(I)),I=0):_++;for(f=S.charCodeAt(0),d=0;d<8;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1}else{for(f=1,d=0;d<E;d++)I=I<<1|f,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=0;for(f=S.charCodeAt(0),d=0;d<16;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete y[S]}else for(f=p[S],d=0;d<E;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1;v--,v==0&&(v=Math.pow(2,E),E++)}for(f=2,d=0;d<E;d++)I=I<<1|f&1,_==l-1?(_=0,C.push(u(I)),I=0):_++,f=f>>1;for(;;)if(I=I<<1,_==l-1){C.push(u(I));break}else _++;return C.join("")},decompress:function(c){return c==null?"":c==""?null:a._decompress(c.length,32768,function(l){return c.charCodeAt(l)})},_decompress:function(c,l,u){var d=[],f=4,p=4,y=3,m="",w=[],S,v,P,E,C,I,_,k={val:u(0),position:l,index:1};for(S=0;S<3;S+=1)d[S]=S;for(P=0,C=Math.pow(2,2),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),P|=(E>0?1:0)*I,I<<=1;switch(P){case 0:for(P=0,C=Math.pow(2,8),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),P|=(E>0?1:0)*I,I<<=1;_=t(P);break;case 1:for(P=0,C=Math.pow(2,16),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),P|=(E>0?1:0)*I,I<<=1;_=t(P);break;case 2:return""}for(d[3]=_,v=_,w.push(_);;){if(k.index>c)return"";for(P=0,C=Math.pow(2,y),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),P|=(E>0?1:0)*I,I<<=1;switch(_=P){case 0:for(P=0,C=Math.pow(2,8),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),P|=(E>0?1:0)*I,I<<=1;d[p++]=t(P),_=p-1,f--;break;case 1:for(P=0,C=Math.pow(2,16),I=1;I!=C;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=u(k.index++)),P|=(E>0?1:0)*I,I<<=1;d[p++]=t(P),_=p-1,f--;break;case 2:return w.join("")}if(f==0&&(f=Math.pow(2,y),y++),d[_])m=d[_];else if(_===p)m=v+v.charAt(0);else return null;w.push(m),d[p++]=v+m.charAt(0),f--,v=m,f==0&&(f=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})})(gw);var _Z=gw.exports;const vA=Ys(_Z);async function kZ(e,n,t){var S,v,P;const{elements:r,files:o}=n,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,c=e.getCurrentPageId(),l=new Map,u=[],d=new Set;r.forEach(E=>{if(l.set(E.id,Be()),E.boundElements!==null)for(const C of E.boundElements)C.type==="text"&&d.add(C.id)});let f=xR;for(const E of r){if(d.has(E.id))continue;const C=l.get(E.id),I={id:C,typeName:"shape",parentId:c,index:f,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:TZ(E.opacity),meta:{}};switch(E.angle!==0&&a.set(C,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(S=i.get(E.groupIds[0]))==null||S.push(C):i.set(E.groupIds[0],[C]):u.push(C),E.type){case"rectangle":case"ellipse":case"diamond":{let _="",k="middle";if(E.boundElements!==null){for(const T of E.boundElements)if(T.type==="text"){const O=r.find(N=>N.id===T.id);O&&(_=O.text,k=DZ[O.textAlign])}}const $=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;s.shapes.push({...I,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:Jd[E.strokeWidth]??"draw",color:al[$]??"black",text:_,align:k,dash:eh(E),fill:FZ(E)}});break}case"freedraw":{s.shapes.push({...I,type:"draw",props:{dash:eh(E),size:Jd[E.strokeWidth],color:al[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([_,k,$=.5])=>({x:_,y:k,z:$}))}]}});break}case"line":{if(E.points.slice().length<2)break;const k=Bl(E.points.length);s.shapes.push({...I,type:"line",props:{dash:eh(E),size:Jd[E.strokeWidth],color:al[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([$,T],O)=>{const N=k[O];return[N,{id:N,index:N,x:$,y:T}]}))}}});break}case"arrow":{let _="";if(E.boundElements!==null){for(const N of E.boundElements)if(N.type==="text"){const A=r.find(j=>j.id===N.id);A&&(_=A.text)}}const k=E.points[0],$=E.points[E.points.length-1],T=l.get((v=E.startBinding)==null?void 0:v.elementId),O=l.get((P=E.endBinding)==null?void 0:P.elementId);s.shapes.push({...I,type:"arrow",props:{text:_,bend:LZ(E,k,$),dash:eh(E),size:Jd[E.strokeWidth]??"m",color:al[E.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:$[0],y:$[1]},arrowheadEnd:vI[E.endArrowhead]??"none",arrowheadStart:vI[E.startArrowhead]??"none"}}),T&&s.bindings.push({id:Ci(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),O&&s.bindings.push({id:Ci(),typeName:"binding",type:"arrow",fromId:C,toId:O,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:_,scale:k}=MZ(E.fontSize);s.shapes.push({...I,type:"text",props:{size:_,scale:k,font:AZ[E.fontFamily]??"draw",color:al[E.strokeColor]??"black",text:E.text,textAlign:RZ[E.textAlign]}});break}case"image":{const _=o[E.fileId];if(!_)break;const k=yi.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:E.width,h:E.height,name:E.id??"Untitled",isAnimated:!1,mimeType:_.mimeType,src:_.dataURL},meta:{}}),s.shapes.push({...I,type:"image",props:{w:E.width,h:E.height,assetId:k}})}}f=Lo(f)}const p=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:p,select:!1,preserveIds:!0});for(const E of i.values())if(E.length>1){e.groupShapes(E);const C=e.getShape(E[0]);C!=null&&C.parentId&&mr(C.parentId)&&u.push(C.parentId)}for(const[E,C]of a)e.select(E),e.rotateShapesBy([E],C);const y=ye(u.map(E=>e.getShape(E))),m=J.Common(y.map(E=>e.getShapePageBounds(E))),w=e.getViewportPageBounds().center;e.updateShapes(y.map(E=>{const C={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:w.x+C.x,y:w.y+C.y}})),e.setSelectedShapes(u)}const TZ=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},Jd={1:"s",2:"m",3:"l",4:"xl"},$Z={16:"s",20:"m",28:"l",36:"xl"};function MZ(e){const n=$Z[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 AZ={1:"draw",2:"sans",3:"mono"},al={"#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"},jZ={solid:"draw",dashed:"dashed",dotted:"dotted"},OZ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},DZ={left:"start",center:"middle",right:"end"},RZ={left:"start",center:"middle",right:"end"},vI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function LZ(e,n,t){let r=0;if(e.points.length>2){const o=new b(n[0],n[1]),s=new b(t[0],t[1]),i=new b(e.points[1][0],e.points[1][1]),a=b.Sub(s,o),c=b.Per(a),l=b.Med(s,o),u=b.Sub(l,c),d=b.Add(l,c),f=b.NearestPointOnLineSegment(u,d,i,!1);r=b.Dist(f,l),b.Clockwise(f,s,l)&&(r*=-1)}return r}const eh=e=>{let n=jZ[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},FZ=e=>e.backgroundColor==="transparent"?"none":OZ[e.fillStyle]??"solid";async function xA(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await fetch(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r}),n.forEach(i=>URL.revokeObjectURL(i))}function NZ(e,n,t){const r=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(n,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0}),setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))}async function Lv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await fetch(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),xA(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 zZ(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const BZ=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},UZ=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 z_(n)},HZ=e=>/^<svg/.test(e),KZ=["input","select","textarea"];function Sy(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||KZ.indexOf(n.tagName.toLowerCase())>-1)}const WZ=e=>e.types.find(n=>n.match(/^image\//)),vy=(e,n,t,r)=>{const o=UZ(n);if(o)for(const s of o)Lv(e,s,t);else BZ(n)?Lv(e,n,t):HZ(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}))},GZ=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}}bA(e,r,t)},wA=async(e,n,t)=>{const r=[];for(const o of n){if(WZ(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 Ua.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Ua.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Ua.blobToText(s)})()})}return await bA(e,r,t)};async function bA(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 xA(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(c=>{var u;const l=(u=c.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:u[1];if(l)try{const d=vA.decompressFromBase64(l);if(d===null){i({type:"error",data:d,reason:"found tldraw data comment but could not parse base64"});return}else{const f=JSON.parse(d);if(f.type!=="application/tldraw"&&i({type:"error",data:f,reason:`found tldraw data comment but JSON was of a different type: ${f.type}`}),typeof f.data=="string"){i({type:"error",data:f,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:f.data});return}}catch{i({type:"error",data:l,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:c,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:c,subtype:"url"});return}try{const d=JSON.parse(c);if(d.type==="excalidraw/clipboard"){i({type:"excalidraw",data:d});return}else{i({type:"text",data:c,subtype:"json"});return}}catch{i({type:"text",data:c,subtype:"text"});return}}i({type:"error",data:c,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){NZ(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){kZ(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(l=>l.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const l=a.firstElementChild.getAttribute("href");vy(e,l,t,o);return}if(!o.some(l=>l.type==="text"&&l.subtype!=="html")&&s.data.trim()){vy(e,zZ(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Lv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){vy(e,s.data,t,o);return}}const mp=e=>{var r;const n=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=vA.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(TR);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<tldraw>${t}</tldraw>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${t}</tldraw>`)}};function VZ(){const e=B(),n=Eo(),t=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(mp(e),n("copy",{source:i}))},[e,n]),r=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(mp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=x.useCallback(async function(i,a,c){e.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(wA(e,i,c),n("paste",{source:"menu"})):navigator.clipboard.read().then(l=>{o(l,a,c)}))},[e,n]);return{copy:t,cut:r,paste:o}}function YZ(){const e=B(),n=Eo(),t=W("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!t)return;const r=c=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Sy(e)||(_e(c),mp(e),n("copy",{source:"kbd"}))};function o(c){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Sy(e)||(_e(c),mp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=c=>{c.button===1&&(s=!0,requestAnimationFrame(()=>{s=!1}))},a=c=>{if(s){Ht(c);return}e.getEditingShapeId()!==null||Sy(e)||(c.clipboardData&&!e.inputs.shiftKey?GZ(e,c.clipboardData):navigator.clipboard.read().then(l=>{Array.isArray(l)&&l[0]instanceof ClipboardItem&&wA(e,l,e.inputs.currentPagePoint)}),_e(c),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 PA(e,n,t){const{type:r,quality:o,scale:s,width:i,height:a}=t;let[c,l]=await M$(i*s,a*s);c=Math.floor(c),l=Math.floor(l);const u=c/i,d=URL.createObjectURL(new Blob([e],{type:"image/svg+xml"})),f=await new Promise(y=>{const m=new Image;m.crossOrigin="anonymous",m.onload=async()=>{n&&await new Promise(v=>setTimeout(v,250));const w=document.createElement("canvas"),S=w.getContext("2d");w.width=c,w.height=l,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(m,0,0,c,l),URL.revokeObjectURL(d),y(w)},m.onerror=()=>{y(null)},m.src=d});if(!f)return null;const p=await new Promise(y=>f.toBlob(m=>{(!m||Pt.throwToBlob.get())&&y(null),y(m)},"image/"+r,o));if(!p)return null;if(r==="png"){const y=new DataView(await p.arrayBuffer());return to.setPhysChunk(y,u,{type:"image/"+r})}else return p}async function CA(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 Fv(e,n,t,r={}){var o;switch(t){case"svg":return(o=await CA(e,n,r))==null?void 0:o.svg;case"json":{const s=e.getContentFromCurrentPage(n);return JSON.stringify(s)}default:sn(t)}}async function IA({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await Fv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Fv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await CA(e,n,r);if(!o)throw new Error("Could not construct image.");const s=await PA(o.svg,e.environment.isSafari,{type:t,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:sn(t)}}const XZ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function qZ(e,n,t,r={}){return{blobPromise:IA({editor:e,ids:n,format:t,opts:r}),mimeType:XZ[t]}}function ZZ(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}=qZ(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 QZ(async()=>Fv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:sn(t)}}async function QZ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}function JZ(){const e=B(),{addToast:n}=Yr(),t=Me();return x.useCallback((r,o="svg")=>{ZZ(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 eQ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${xI()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${xI()}`}r+=`.${t}`;const s=await IA({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});tQ(i)}function xI(){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 tQ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function nQ(){const e=B(),{addToast:n}=Yr(),t=Me();return x.useCallback((r,o="png",s)=>{eQ(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])}function rQ(){const e=B(),n=x.useRef(null),t=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,v)=>{S&&(S.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),S&&document.body.contains(S)&&document.body.removeChild(S)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${ot()}`;o.className=a,s.innerHTML=`
208
- .${a} {
209
- display: none;
210
- }
211
-
212
- .${a} svg {
213
- max-width: 100%;
214
- height: 100%;
215
- display: block;
216
- }
217
-
218
- @media print {
219
- html, body {
220
- min-height: 100%;
221
- height: 100%;
222
- margin: 0;
223
- }
224
-
225
- body {
226
- position: relative;
227
- }
228
-
229
- body > * {
230
- display: none;
231
- }
232
-
233
- .tldraw__editor {
234
- display: none;
235
- }
236
-
237
- .${a} {
238
- display: block !important;
239
- background: white;
240
- min-height: 100%;
241
- height: 100%;
242
- max-width: 100%;
243
- }
244
-
245
- .${a}__item {
246
- padding: 10mm;
247
- display: flex;
248
- min-height: 100%;
249
- flex-direction: column;
250
- page-break-after: always;
251
- position: relative;
252
- overflow: hidden;
253
- height: 100%;
254
- }
255
-
256
- .${a}__item__main {
257
- flex: 1;
258
- display: flex;
259
- align-items: center;
260
- justify-content: center;
261
- max-height: 100%;
262
- }
263
-
264
- .${a}__item__header {
265
- display: none;
266
- }
267
-
268
- .${a}__item__footer {
269
- display: none;
270
- text-align: right;
271
- }
272
-
273
- .${a}__item__footer__hide {
274
- display: none;
275
- }
276
-
277
-
278
- }
279
-
280
- `;const c=()=>{document.head.appendChild(s),document.body.appendChild(o)},l=()=>{e.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",c),window.addEventListener("afterprint",l);function u(S,v,P){try{o.innerHTML+=`<div class="${a}__item">
281
- <div class="${a}__item__header">
282
- ${S.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
283
- </div>
284
- <div class="${a}__item__main">
285
- ${P}
286
- </div>
287
- <div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
288
- ${v??""}
289
- </div>
290
- </div>`}catch(E){console.error(E)}}function d(){e.environment.isChromeForIos?(c(),window.print()):e.environment.isSafari?(c(),document.execCommand("print",!1)):window.print()}const f=e.getSelectedShapeIds(),p=e.getCurrentPageId(),y=e.getPages(),w={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvgString(f,w);if(S){const v=y.find(P=>P.id===p);u(`tldraw — ${v==null?void 0:v.name}`,null,S.svg),d()}}else{const S=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(S.id),w);v&&(u(`tldraw — ${S.name}`,null,v.svg),d())}window.removeEventListener("beforeprint",c),window.removeEventListener("afterprint",l)},[e])}const EA=x.createContext(null);function oQ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function ga(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function sQ({overrides:e,children:n}){const t=B(),{addDialog:r,clearDialogs:o}=Qi(),{clearToasts:s}=Yr(),i=Me(),a=gA(),c=rQ(),{cut:l,copy:u,paste:d}=VZ(),f=JZ(),p=nQ(),y=i("document.default-name"),m=Eo(),w=x.useMemo(()=>{function S(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function v(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const E=oQ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(C){v()&&(S()||(m("edit-link",{source:C}),t.mark("edit-link"),r({component:IZ})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(C){m("insert-embed",{source:C}),r({component:pA})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(C){m("insert-media",{source:C}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(C){m("undo",{source:C}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(C){m("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&&(m("export-as",{format:"svg",source:C}),p(I,"svg",ga(t,y)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(m("export-as",{format:"png",source:C}),p(I,"png",ga(t,y)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(m("export-as",{format:"json",source:C}),p(I,"json",ga(t,y)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(m("export-all-as",{format:"svg",source:C}),p(Array.from(t.getCurrentPageShapeIds()),"svg",ga(t,y)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(C){const I=Array.from(t.getCurrentPageShapeIds().values());I.length!==0&&(m("export-all-as",{format:"png",source:C}),p(I,"png",ga(t,y)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(C){const I=Array.from(t.getCurrentPageShapeIds().values());I.length!==0&&(m("export-all-as",{format:"json",source:C}),p(I,"json",ga(t,y)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(C){let I=t.getSelectedShapeIds();I.length===0&&(I=Array.from(t.getCurrentPageShapeIds().values())),I.length!==0&&(m("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&&(m("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&&(m("copy-as",{format:"json",source:C}),f(I,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(C){if(!v()||S())return;m("toggle-auto-size",{source:C}),t.mark("toggling auto size");const I=t.getSelectedShapes().filter(_=>t.isShapeOfType(_,"text")&&_.props.autoSize===!1);t.updateShapes(I.map(_=>({id:_.id,type:_.type,props:{..._.props,w:8,autoSize:!0}}))),We(t,I.map(_=>_.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(C){m("open-embed-link",{source:C});const I=t.getSelectedShapeIds(),_="No embed shapes selected";if(I.length!==1){console.error(_);return}const k=t.getShape(I[0]);if(!k||!t.isShapeOfType(k,"embed")){console.error(_);return}h7(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(C){var I,_;if(((I=t.root.getCurrent())==null?void 0:I.id)!=="zoom"&&(m("zoom-tool",{source:C}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const k=t.root.getCurrent();k&&((_=k.getCurrent())==null?void 0:_.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(C){v()&&(S()||t.batch(()=>{m("convert-to-bookmark",{source:C});const I=t.getSelectedShapes(),_=[],k=[];for(const $ of I){if(!$||!t.isShapeOfType($,"embed")||!$.props.url)continue;const T=new b($.x,$.y);T.rot(-$.rotation),T.add(new b($.props.w/2-300/2,$.props.h/2-320/2)),T.rot($.rotation);const O={id:Be(),type:"bookmark",rotation:$.rotation,x:T.x,y:T.y,opacity:1,props:{url:$.props.url}};_.push(O),k.push($.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(k),t.createShapes(_)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(C){v()&&(S()||(m("convert-to-embed",{source:C}),t.batch(()=>{const I=t.getSelectedShapeIds(),_=ye(I.map(T=>t.getShape(T))),k=[],$=[];for(const T of _){if(!t.isShapeOfType(T,"bookmark"))continue;const{url:O}=T.props,N=ks(T.props.url);if(!N||!N.definition)continue;const{width:A,height:j}=N.definition,L=new b(T.x,T.y);L.rot(-T.rotation),L.add(new b(T.props.w/2-A/2,T.props.h/2-j/2)),L.rot(T.rotation);const X={id:Be(),type:"embed",x:L.x,y:L.y,rotation:T.rotation,props:{url:O,w:A,h:j}};k.push(X),$.push(T.id)}t.mark("convert shapes to embed"),t.deleteShapes($),t.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(C){if(!v()||S())return;m("duplicate-shapes",{source:C});const I=t.getInstanceState();let _,k;if(I.duplicateProps)_=I.duplicateProps.shapeIds,k=I.duplicateProps.offset;else{_=t.getSelectedShapeIds();const $=J.Common(ye(_.map(T=>t.getShapePageBounds(T))));k=t.getCameraOptions().isLocked?{x:20,y:20}:{x:$.width+20,y:0}}t.mark("duplicate shapes"),t.duplicateShapes(_,k),I.duplicateProps&&t.updateInstanceState({duplicateProps:{...I.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(C){v()&&(S()||(m("ungroup-shapes",{source:C}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(C){if(!v()||S())return;m("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(!v())return;m("remove-frame",{source:C});const I=t.getSelectedShapes();I.length>0&&I.every(_=>t.isShapeOfType(_,"frame"))&&(t.mark("remove-frame"),bZ(t,I.map(_=>_.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(C){if(!v())return;m("fit-frame-to-content",{source:C});const I=t.getOnlySelectedShape();I&&t.isShapeOfType(I,"frame")&&(t.mark("fit-frame-to-content"),CZ(t,I.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(C){if(!v()||S())return;m("align-shapes",{operation:"left",source:C}),t.mark("align left");const I=t.getSelectedShapeIds();t.alignShapes(I,"left"),We(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(!v()||S())return;m("align-shapes",{operation:"center-horizontal",source:C}),t.mark("align center horizontal");const I=t.getSelectedShapeIds();t.alignShapes(I,"center-horizontal"),We(t,I)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(C){if(!v()||S())return;m("align-shapes",{operation:"right",source:C}),t.mark("align right");const I=t.getSelectedShapeIds();t.alignShapes(I,"right"),We(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(!v()||S())return;m("align-shapes",{operation:"center-vertical",source:C}),t.mark("align center vertical");const I=t.getSelectedShapeIds();t.alignShapes(I,"center-vertical"),We(t,I)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(C){if(!v()||S())return;m("align-shapes",{operation:"top",source:C}),t.mark("align top");const I=t.getSelectedShapeIds();t.alignShapes(I,"top"),We(t,I)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(C){if(!v()||S())return;m("align-shapes",{operation:"bottom",source:C}),t.mark("align bottom");const I=t.getSelectedShapeIds();t.alignShapes(I,"bottom"),We(t,I)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(C){if(!v()||S())return;m("distribute-shapes",{operation:"horizontal",source:C}),t.mark("distribute horizontal");const I=t.getSelectedShapeIds();t.distributeShapes(I,"horizontal"),We(t,I)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(C){if(!v()||S())return;m("distribute-shapes",{operation:"vertical",source:C}),t.mark("distribute vertical");const I=t.getSelectedShapeIds();t.distributeShapes(I,"vertical"),We(t,I)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(C){if(!v()||S())return;m("stretch-shapes",{operation:"horizontal",source:C}),t.mark("stretch horizontal");const I=t.getSelectedShapeIds();t.stretchShapes(I,"horizontal"),We(t,I)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(C){if(!v()||S())return;m("stretch-shapes",{operation:"vertical",source:C}),t.mark("stretch vertical");const I=t.getSelectedShapeIds();t.stretchShapes(I,"vertical"),We(t,I)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(C){if(!v()||S())return;m("flip-shapes",{operation:"horizontal",source:C}),t.mark("flip horizontal");const I=t.getSelectedShapeIds();t.flipShapes(I,"horizontal"),We(t,I)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(C){if(!v()||S())return;m("flip-shapes",{operation:"vertical",source:C}),t.mark("flip vertical");const I=t.getSelectedShapeIds();t.flipShapes(I,"vertical"),We(t,I)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(C){if(!v()||S())return;m("pack-shapes",{source:C}),t.mark("pack");const I=t.getSelectedShapeIds();t.packShapes(I,cM),We(t,I)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(C){if(!v()||S())return;m("stack-shapes",{operation:"vertical",source:C}),t.mark("stack-vertical");const I=t.getSelectedShapeIds();t.stackShapes(I,"vertical",16),We(t,I)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(C){if(!v()||S())return;m("stack-shapes",{operation:"horizontal",source:C}),t.mark("stack-horizontal");const I=t.getSelectedShapeIds();t.stackShapes(I,"horizontal",16),We(t,I)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(C){v()&&(S()||(m("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){v()&&(S()||(m("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){v()&&(S()||(m("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){v()&&(S()||(m("reorder-shapes",{operation:"toBack",source:C}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(C){v()&&(S()||(t.mark("cut"),l(C)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(C){v()&&(S()||u(C))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(C){var I;(I=navigator.clipboard)==null||I.read().then(_=>{d(_,C,C==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(C){t.batch(()=>{S()||(m("select-all-shapes",{source:C}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(C){v()&&(S()||(m("select-none-shapes",{source:C}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(C){v()&&(S()||(m("delete-shapes",{source:C}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(C){if(!v()||S())return;m("rotate-cw",{source:C}),t.mark("rotate-cw");const I=t.getSelectionRotation()%(Ve/2),_=Cl(I,0)||Cl(I,Ve/2),k=t.getSelectedShapeIds();t.rotateShapesBy(k,Ve/2-(_?0:I)),We(t,k)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(C){if(!v()||S())return;m("rotate-ccw",{source:C}),t.mark("rotate-ccw");const I=t.getSelectionRotation()%(Ve/2),_=Cl(I,0),k=t.getSelectedShapeIds();t.rotateShapesBy(k,_?-(Ve/2):-I),We(t,k)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(C){m("zoom-in",{source:C}),t.zoomIn(void 0,{animation:{duration:no}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(C){m("zoom-out",{source:C}),t.zoomOut(void 0,{animation:{duration:no}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(C){m("reset-zoom",{source:C}),t.resetZoom(void 0,{animation:{duration:no}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(C){m("zoom-to-fit",{source:C}),t.zoomToFit({animation:{duration:no}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(C){v()&&(S()||(m("zoom-to-selection",{source:C}),t.zoomToSelection({animation:{duration:no}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(C){m("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){m("toggle-dark-mode",{source:C}),t.user.updateUserPreferences({isDarkMode:!t.user.getIsDarkMode()})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(C){m("toggle-wrap-mode",{source:C}),t.user.updateUserPreferences({isWrapMode:!t.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(C){m("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){m("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){m("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){m("toggle-tool-lock",{source:C}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(C){m("unlock-all",{source:C});const I=[];for(const _ of t.getCurrentPageShapes())_.isLocked&&I.push({id:_.id,type:_.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){requestAnimationFrame(()=>{t.batch(()=>{m("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){m("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){m("toggle-debug-mode",{source:C}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(C){m("print",{source:C}),c()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(C){m("exit-pen-mode",{source:C}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(C){m("stop-following",{source:C}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(C){m("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"),m("toggle-lock",{source:C}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(C){const I=Go.createId(),_=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:i("page-menu.new-page-initial-name"),id:I}),t.moveShapesToPage(_,I)}),m("new-page",{source:C})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(C){const I=or;t.batch(()=>{t.mark("change-color"),t.isIn("select")&&t.setStyleForSelectedShapes(I,"white"),t.setStyleForNextShapes(I,"white"),t.updateInstanceState({isChangingStyle:!0})}),m("set-style",{source:C,id:I.id,value:"white"})}}]);return e?e(t,E,void 0):E},[t,m,e,r,a,p,f,l,u,d,o,s,c,i,y]);return h.jsx(EA.Provider,{value:w,children:n})}function ce(){const e=x.useContext(EA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function gu(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const iQ=["top","right","bottom","left"],io=Math.min,Yn=Math.max,yp=Math.round,th=Math.floor,Gs=e=>({x:e,y:e}),aQ={left:"right",right:"left",bottom:"top",top:"bottom"},cQ={start:"end",end:"start"};function Nv(e,n,t){return Yn(e,io(n,t))}function Jo(e,n){return typeof e=="function"?e(n):e}function es(e){return e.split("-")[0]}function Ac(e){return e.split("-")[1]}function mw(e){return e==="x"?"y":"x"}function yw(e){return e==="y"?"height":"width"}function jc(e){return["top","bottom"].includes(es(e))?"y":"x"}function Sw(e){return mw(jc(e))}function lQ(e,n,t){t===void 0&&(t=!1);const r=Ac(e),o=Sw(e),s=yw(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=Sp(i)),[i,Sp(i)]}function uQ(e){const n=Sp(e);return[zv(e),n,zv(n)]}function zv(e){return e.replace(/start|end/g,n=>cQ[n])}function dQ(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 hQ(e,n,t,r){const o=Ac(e);let s=dQ(es(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(zv)))),s}function Sp(e){return e.replace(/left|right|bottom|top/g,n=>aQ[n])}function fQ(e){return{top:0,right:0,bottom:0,left:0,...e}}function _A(e){return typeof e!="number"?fQ(e):{top:e,right:e,bottom:e,left:e}}function vp(e){const{x:n,y:t,width:r,height:o}=e;return{width:r,height:o,top:t,left:n,right:n+r,bottom:t+o,x:n,y:t}}function wI(e,n,t){let{reference:r,floating:o}=e;const s=jc(n),i=Sw(n),a=yw(i),c=es(n),l=s==="y",u=r.x+r.width/2-o.width/2,d=r.y+r.height/2-o.height/2,f=r[a]/2-o[a]/2;let p;switch(c){case"top":p={x:u,y:r.y-o.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:d};break;case"left":p={x:r.x-o.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Ac(n)){case"start":p[i]-=f*(t&&l?-1:1);break;case"end":p[i]+=f*(t&&l?-1:1);break}return p}const pQ=async(e,n,t)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=t,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(n));let l=await i.getElementRects({reference:e,floating:n,strategy:o}),{x:u,y:d}=wI(l,r,c),f=r,p={},y=0;for(let m=0;m<a.length;m++){const{name:w,fn:S}=a[m],{x:v,y:P,data:E,reset:C}=await S({x:u,y:d,initialPlacement:r,placement:f,strategy:o,middlewareData:p,rects:l,platform:i,elements:{reference:e,floating:n}});u=v??u,d=P??d,p={...p,[w]:{...p[w],...E}},C&&y<=50&&(y++,typeof C=="object"&&(C.placement&&(f=C.placement),C.rects&&(l=C.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):C.rects),{x:u,y:d}=wI(l,f,c)),m=-1)}return{x:u,y:d,placement:f,strategy:o,middlewareData:p}};async function mu(e,n){var t;n===void 0&&(n={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:f=!1,padding:p=0}=Jo(n,e),y=_A(p),w=a[f?d==="floating"?"reference":"floating":d],S=vp(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(w)))==null||t?w:w.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:l,rootBoundary:u,strategy:c})),v=d==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,P=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(P))?await(s.getScale==null?void 0:s.getScale(P))||{x:1,y:1}:{x:1,y:1},C=vp(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:P,strategy:c}):v);return{top:(S.top-C.top+y.top)/E.y,bottom:(C.bottom-S.bottom+y.bottom)/E.y,left:(S.left-C.left+y.left)/E.x,right:(C.right-S.right+y.right)/E.x}}const gQ=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=n,{element:l,padding:u=0}=Jo(e,n)||{};if(l==null)return{};const d=_A(u),f={x:t,y:r},p=Sw(o),y=yw(p),m=await i.getDimensions(l),w=p==="y",S=w?"top":"left",v=w?"bottom":"right",P=w?"clientHeight":"clientWidth",E=s.reference[y]+s.reference[p]-f[p]-s.floating[y],C=f[p]-s.reference[p],I=await(i.getOffsetParent==null?void 0:i.getOffsetParent(l));let _=I?I[P]:0;(!_||!await(i.isElement==null?void 0:i.isElement(I)))&&(_=a.floating[P]||s.floating[y]);const k=E/2-C/2,$=_/2-m[y]/2-1,T=io(d[S],$),O=io(d[v],$),N=T,A=_-m[y]-O,j=_/2-m[y]/2+k,L=Nv(N,j,A),X=!c.arrow&&Ac(o)!=null&&j!==L&&s.reference[y]/2-(j<N?T:O)-m[y]/2<0,V=X?j<N?j-N:j-A:0;return{[p]:f[p]+V,data:{[p]:L,centerOffset:j-L-V,...X&&{alignmentOffset:V}},reset:X}}}),mQ=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:c,elements:l}=n,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:m=!0,...w}=Jo(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const S=es(o),v=es(a)===a,P=await(c.isRTL==null?void 0:c.isRTL(l.floating)),E=f||(v||!m?[Sp(a)]:uQ(a));!f&&y!=="none"&&E.push(...hQ(a,m,y,P));const C=[a,...E],I=await mu(n,w),_=[];let k=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&_.push(I[S]),d){const N=lQ(o,i,P);_.push(I[N[0]],I[N[1]])}if(k=[...k,{placement:o,overflows:_}],!_.every(N=>N<=0)){var $,T;const N=((($=s.flip)==null?void 0:$.index)||0)+1,A=C[N];if(A)return{data:{index:N,overflows:k},reset:{placement:A}};let j=(T=k.filter(L=>L.overflows[0]<=0).sort((L,X)=>L.overflows[1]-X.overflows[1])[0])==null?void 0:T.placement;if(!j)switch(p){case"bestFit":{var O;const L=(O=k.map(X=>[X.placement,X.overflows.filter(V=>V>0).reduce((V,H)=>V+H,0)]).sort((X,V)=>X[1]-V[1])[0])==null?void 0:O[0];L&&(j=L);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function bI(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function PI(e){return iQ.some(n=>e[n]>=0)}const yQ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=Jo(e,n);switch(r){case"referenceHidden":{const s=await mu(n,{...o,elementContext:"reference"}),i=bI(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:PI(i)}}}case"escaped":{const s=await mu(n,{...o,altBoundary:!0}),i=bI(s,t.floating);return{data:{escapedOffsets:i,escaped:PI(i)}}}default:return{}}}}};async function SQ(e,n){const{placement:t,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=es(t),a=Ac(t),c=jc(t)==="y",l=["left","top"].includes(i)?-1:1,u=s&&c?-1:1,d=Jo(n,e);let{mainAxis:f,crossAxis:p,alignmentAxis:y}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...d};return a&&typeof y=="number"&&(p=a==="end"?y*-1:y),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const vQ=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,c=await SQ(n,e);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},xQ=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:w=>{let{x:S,y:v}=w;return{x:S,y:v}}},...c}=Jo(e,n),l={x:t,y:r},u=await mu(n,c),d=jc(es(o)),f=mw(d);let p=l[f],y=l[d];if(s){const w=f==="y"?"top":"left",S=f==="y"?"bottom":"right",v=p+u[w],P=p-u[S];p=Nv(v,p,P)}if(i){const w=d==="y"?"top":"left",S=d==="y"?"bottom":"right",v=y+u[w],P=y-u[S];y=Nv(v,y,P)}const m=a.fn({...n,[f]:p,[d]:y});return{...m,data:{x:m.x-t,y:m.y-r}}}}},wQ=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:c=!0,crossAxis:l=!0}=Jo(e,n),u={x:t,y:r},d=jc(o),f=mw(d);let p=u[f],y=u[d];const m=Jo(a,n),w=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(c){const P=f==="y"?"height":"width",E=s.reference[f]-s.floating[P]+w.mainAxis,C=s.reference[f]+s.reference[P]-w.mainAxis;p<E?p=E:p>C&&(p=C)}if(l){var S,v;const P=f==="y"?"width":"height",E=["top","left"].includes(es(o)),C=s.reference[d]-s.floating[P]+(E&&((S=i.offset)==null?void 0:S[d])||0)+(E?0:w.crossAxis),I=s.reference[d]+s.reference[P]+(E?0:((v=i.offset)==null?void 0:v[d])||0)-(E?w.crossAxis:0);y<C?y=C:y>I&&(y=I)}return{[f]:p,[d]:y}}}},bQ=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}=Jo(e,n),c=await mu(n,a),l=es(t),u=Ac(t),d=jc(t)==="y",{width:f,height:p}=r.floating;let y,m;l==="top"||l==="bottom"?(y=l,m=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(m=l,y=u==="end"?"top":"bottom");const w=p-c.top-c.bottom,S=f-c.left-c.right,v=io(p-c[y],w),P=io(f-c[m],S),E=!n.middlewareData.shift;let C=v,I=P;if(d?I=u||E?io(P,S):S:C=u||E?io(v,w):w,E&&!u){const k=Yn(c.left,0),$=Yn(c.right,0),T=Yn(c.top,0),O=Yn(c.bottom,0);d?I=f-2*(k!==0||$!==0?k+$:Yn(c.left,c.right)):C=p-2*(T!==0||O!==0?T+O:Yn(c.top,c.bottom))}await i({...n,availableWidth:I,availableHeight:C});const _=await o.getDimensions(s.floating);return f!==_.width||p!==_.height?{reset:{rects:!0}}:{}}}};function Oc(e){return kA(e)?(e.nodeName||"").toLowerCase():"#document"}function nr(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function as(e){var n;return(n=(kA(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function kA(e){return e instanceof Node||e instanceof nr(e).Node}function yo(e){return e instanceof Element||e instanceof nr(e).Element}function So(e){return e instanceof HTMLElement||e instanceof nr(e).HTMLElement}function CI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof nr(e).ShadowRoot}function Wu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=Wr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function PQ(e){return["table","td","th"].includes(Oc(e))}function vw(e){const n=xw(),t=Wr(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 CQ(e){let n=Vs(e);for(;So(n)&&!yc(n);){if(vw(n))return n;n=Vs(n)}return null}function xw(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function yc(e){return["html","body","#document"].includes(Oc(e))}function Wr(e){return nr(e).getComputedStyle(e)}function xg(e){return yo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Vs(e){if(Oc(e)==="html")return e;const n=e.assignedSlot||e.parentNode||CI(e)&&e.host||as(e);return CI(n)?n.host:n}function TA(e){const n=Vs(e);return yc(n)?e.ownerDocument?e.ownerDocument.body:e.body:So(n)&&Wu(n)?n:TA(n)}function yu(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=TA(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=nr(o);return s?n.concat(i,i.visualViewport||[],Wu(o)?o:[],i.frameElement&&t?yu(i.frameElement):[]):n.concat(o,yu(o,[],t))}function $A(e){const n=Wr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=So(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=yp(t)!==s||yp(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function ww(e){return yo(e)?e:e.contextElement}function tc(e){const n=ww(e);if(!So(n))return Gs(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=$A(n);let i=(s?yp(t.width):t.width)/r,a=(s?yp(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const IQ=Gs(0);function MA(e){const n=nr(e);return!xw()||!n.visualViewport?IQ:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function EQ(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==nr(e)?!1:n}function Bi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=ww(e);let i=Gs(1);n&&(r?yo(r)&&(i=tc(r)):i=tc(e));const a=EQ(s,t,r)?MA(s):Gs(0);let c=(o.left+a.x)/i.x,l=(o.top+a.y)/i.y,u=o.width/i.x,d=o.height/i.y;if(s){const f=nr(s),p=r&&yo(r)?nr(r):r;let y=f,m=y.frameElement;for(;m&&r&&p!==y;){const w=tc(m),S=m.getBoundingClientRect(),v=Wr(m),P=S.left+(m.clientLeft+parseFloat(v.paddingLeft))*w.x,E=S.top+(m.clientTop+parseFloat(v.paddingTop))*w.y;c*=w.x,l*=w.y,u*=w.x,d*=w.y,c+=P,l+=E,y=nr(m),m=y.frameElement}}return vp({width:u,height:d,x:c,y:l})}const _Q=[":popover-open",":modal"];function bw(e){return _Q.some(n=>{try{return e.matches(n)}catch{return!1}})}function kQ(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=as(r),a=n?bw(n.floating):!1;if(r===i||a&&s)return t;let c={scrollLeft:0,scrollTop:0},l=Gs(1);const u=Gs(0),d=So(r);if((d||!d&&!s)&&((Oc(r)!=="body"||Wu(i))&&(c=xg(r)),So(r))){const f=Bi(r);l=tc(r),u.x=f.x+r.clientLeft,u.y=f.y+r.clientTop}return{width:t.width*l.x,height:t.height*l.y,x:t.x*l.x-c.scrollLeft*l.x+u.x,y:t.y*l.y-c.scrollTop*l.y+u.y}}function TQ(e){return Array.from(e.getClientRects())}function AA(e){return Bi(as(e)).left+xg(e).scrollLeft}function $Q(e){const n=as(e),t=xg(e),r=e.ownerDocument.body,o=Yn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=Yn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+AA(e);const a=-t.scrollTop;return Wr(r).direction==="rtl"&&(i+=Yn(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function MQ(e,n){const t=nr(e),r=as(e),o=t.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const l=xw();(!l||l&&n==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}function AQ(e,n){const t=Bi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=So(e)?tc(e):Gs(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,l=r*s.y;return{width:i,height:a,x:c,y:l}}function II(e,n,t){let r;if(n==="viewport")r=MQ(e,t);else if(n==="document")r=$Q(as(e));else if(yo(n))r=AQ(n,t);else{const o=MA(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return vp(r)}function jA(e,n){const t=Vs(e);return t===n||!yo(t)||yc(t)?!1:Wr(t).position==="fixed"||jA(t,n)}function jQ(e,n){const t=n.get(e);if(t)return t;let r=yu(e,[],!1).filter(a=>yo(a)&&Oc(a)!=="body"),o=null;const s=Wr(e).position==="fixed";let i=s?Vs(e):e;for(;yo(i)&&!yc(i);){const a=Wr(i),c=vw(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Wu(i)&&!c&&jA(e,i))?r=r.filter(u=>u!==i):o=a,i=Vs(i)}return n.set(e,r),r}function OQ(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?bw(n)?[]:jQ(n,this._c):[].concat(t),r],a=i[0],c=i.reduce((l,u)=>{const d=II(n,u,o);return l.top=Yn(d.top,l.top),l.right=io(d.right,l.right),l.bottom=io(d.bottom,l.bottom),l.left=Yn(d.left,l.left),l},II(n,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function DQ(e){const{width:n,height:t}=$A(e);return{width:n,height:t}}function RQ(e,n,t){const r=So(n),o=as(n),s=t==="fixed",i=Bi(e,!0,s,n);let a={scrollLeft:0,scrollTop:0};const c=Gs(0);if(r||!r&&!s)if((Oc(n)!=="body"||Wu(o))&&(a=xg(n)),r){const d=Bi(n,!0,s,n);c.x=d.x+n.clientLeft,c.y=d.y+n.clientTop}else o&&(c.x=AA(o));const l=i.left+a.scrollLeft-c.x,u=i.top+a.scrollTop-c.y;return{x:l,y:u,width:i.width,height:i.height}}function xy(e){return Wr(e).position==="static"}function EI(e,n){return!So(e)||Wr(e).position==="fixed"?null:n?n(e):e.offsetParent}function OA(e,n){const t=nr(e);if(bw(e))return t;if(!So(e)){let o=Vs(e);for(;o&&!yc(o);){if(yo(o)&&!xy(o))return o;o=Vs(o)}return t}let r=EI(e,n);for(;r&&PQ(r)&&xy(r);)r=EI(r,n);return r&&yc(r)&&xy(r)&&!vw(r)?t:r||CQ(e)||t}const LQ=async function(e){const n=this.getOffsetParent||OA,t=this.getDimensions,r=await t(e.floating);return{reference:RQ(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function FQ(e){return Wr(e).direction==="rtl"}const NQ={convertOffsetParentRelativeRectToViewportRelativeRect:kQ,getDocumentElement:as,getClippingRect:OQ,getOffsetParent:OA,getElementRects:LQ,getClientRects:TQ,getDimensions:DQ,getScale:tc,isElement:yo,isRTL:FQ};function zQ(e,n){let t=null,r;const o=as(e);function s(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const{left:l,top:u,width:d,height:f}=e.getBoundingClientRect();if(a||n(),!d||!f)return;const p=th(u),y=th(o.clientWidth-(l+d)),m=th(o.clientHeight-(u+f)),w=th(l),v={rootMargin:-p+"px "+-y+"px "+-m+"px "+-w+"px",threshold:Yn(0,io(1,c))||1};let P=!0;function E(C){const I=C[0].intersectionRatio;if(I!==c){if(!P)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}P=!1}try{t=new IntersectionObserver(E,{...v,root:o.ownerDocument})}catch{t=new IntersectionObserver(E,v)}t.observe(e)}return i(!0),s}function BQ(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:c=!1}=r,l=ww(e),u=o||s?[...l?yu(l):[],...yu(n)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",t,{passive:!0}),s&&S.addEventListener("resize",t)});const d=l&&a?zQ(l,t):null;let f=-1,p=null;i&&(p=new ResizeObserver(S=>{let[v]=S;v&&v.target===l&&p&&(p.unobserve(n),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var P;(P=p)==null||P.observe(n)})),t()}),l&&!c&&p.observe(l),p.observe(n));let y,m=c?Bi(e):null;c&&w();function w(){const S=Bi(e);m&&(S.x!==m.x||S.y!==m.y||S.width!==m.width||S.height!==m.height)&&t(),m=S,y=requestAnimationFrame(w)}return t(),()=>{var S;u.forEach(v=>{o&&v.removeEventListener("scroll",t),s&&v.removeEventListener("resize",t)}),d==null||d(),(S=p)==null||S.disconnect(),p=null,c&&cancelAnimationFrame(y)}}const UQ=vQ,HQ=xQ,KQ=mQ,WQ=bQ,GQ=yQ,_I=gQ,VQ=wQ,YQ=(e,n,t)=>{const r=new Map,o={platform:NQ,...t},s={...o.platform,_c:r};return pQ(e,n,{...o,platform:s})};var lf=typeof document<"u"?x.useLayoutEffect:x.useEffect;function xp(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(!xp(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)&&!xp(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function DA(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kI(e,n){const t=DA(e);return Math.round(n*t)/t}function TI(e){const n=x.useRef(e);return lf(()=>{n.current=e}),n}function XQ(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:c,open:l}=e,[u,d]=x.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[f,p]=x.useState(r);xp(f,r)||p(r);const[y,m]=x.useState(null),[w,S]=x.useState(null),v=x.useCallback(V=>{V!==I.current&&(I.current=V,m(V))},[]),P=x.useCallback(V=>{V!==_.current&&(_.current=V,S(V))},[]),E=s||y,C=i||w,I=x.useRef(null),_=x.useRef(null),k=x.useRef(u),$=c!=null,T=TI(c),O=TI(o),N=x.useCallback(()=>{if(!I.current||!_.current)return;const V={placement:n,strategy:t,middleware:f};O.current&&(V.platform=O.current),YQ(I.current,_.current,V).then(H=>{const U={...H,isPositioned:!0};A.current&&!xp(k.current,U)&&(k.current=U,Yi.flushSync(()=>{d(U)}))})},[f,n,t,O]);lf(()=>{l===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,d(V=>({...V,isPositioned:!1})))},[l]);const A=x.useRef(!1);lf(()=>(A.current=!0,()=>{A.current=!1}),[]),lf(()=>{if(E&&(I.current=E),C&&(_.current=C),E&&C){if(T.current)return T.current(E,C,N);N()}},[E,C,N,T,$]);const j=x.useMemo(()=>({reference:I,floating:_,setReference:v,setFloating:P}),[v,P]),L=x.useMemo(()=>({reference:E,floating:C}),[E,C]),X=x.useMemo(()=>{const V={position:t,left:0,top:0};if(!L.floating)return V;const H=kI(L.floating,u.x),U=kI(L.floating,u.y);return a?{...V,transform:"translate("+H+"px, "+U+"px)",...DA(L.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:H,top:U}},[t,a,L.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:N,refs:j,elements:L,floatingStyles:X}),[u,N,j,L,X])}const qQ=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?_I({element:r.current,padding:o}).fn(t):{}:r?_I({element:r,padding:o}).fn(t):{}}}},ZQ=(e,n)=>({...UQ(e),options:[e,n]}),QQ=(e,n)=>({...HQ(e),options:[e,n]}),JQ=(e,n)=>({...VQ(e),options:[e,n]}),eJ=(e,n)=>({...KQ(e),options:[e,n]}),tJ=(e,n)=>({...WQ(e),options:[e,n]}),nJ=(e,n)=>({...GQ(e),options:[e,n]}),rJ=(e,n)=>({...qQ(e),options:[e,n]});function RA(e){const[n,t]=x.useState(void 0);return Ni(()=>{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 c=s.borderBoxSize,l=Array.isArray(c)?c[0]:c;i=l.inlineSize,a=l.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}const LA="Popper",[FA,wg]=Co(LA),[oJ,NA]=FA(LA),sJ=e=>{const{__scopePopper:n,children:t}=e,[r,o]=x.useState(null);return x.createElement(oJ,{scope:n,anchor:r,onAnchorChange:o},t)},iJ="PopperAnchor",aJ=x.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=NA(iJ,t),i=x.useRef(null),a=Xe(n,i);return x.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:x.createElement(He.div,Q({},o,{ref:a}))}),zA="PopperContent",[cJ,ise]=FA(zA),lJ=x.forwardRef((e,n)=>{var t,r,o,s,i,a,c,l;const{__scopePopper:u,side:d="bottom",sideOffset:f=0,align:p="center",alignOffset:y=0,arrowPadding:m=0,avoidCollisions:w=!0,collisionBoundary:S=[],collisionPadding:v=0,sticky:P="partial",hideWhenDetached:E=!1,updatePositionStrategy:C="optimized",onPlaced:I,..._}=e,k=NA(zA,u),[$,T]=x.useState(null),O=Xe(n,qe=>T(qe)),[N,A]=x.useState(null),j=RA(N),L=(t=j==null?void 0:j.width)!==null&&t!==void 0?t:0,X=(r=j==null?void 0:j.height)!==null&&r!==void 0?r:0,V=d+(p!=="center"?"-"+p:""),H=typeof v=="number"?v:{top:0,right:0,bottom:0,left:0,...v},U=Array.isArray(S)?S:[S],K=U.length>0,Z={padding:H,boundary:U.filter(uJ),altBoundary:K},{refs:le,floatingStyles:be,placement:Ae,isPositioned:ae,middlewareData:je}=XQ({strategy:"fixed",placement:V,whileElementsMounted:(...qe)=>BQ(...qe,{animationFrame:C==="always"}),elements:{reference:k.anchor},middleware:[ZQ({mainAxis:f+X,alignmentAxis:y}),w&&QQ({mainAxis:!0,crossAxis:!1,limiter:P==="partial"?JQ():void 0,...Z}),w&&eJ({...Z}),tJ({...Z,apply:({elements:qe,rects:Dt,availableWidth:To,availableHeight:Rc})=>{const{width:Lc,height:kg}=Dt.reference,ea=qe.floating.style;ea.setProperty("--radix-popper-available-width",`${To}px`),ea.setProperty("--radix-popper-available-height",`${Rc}px`),ea.setProperty("--radix-popper-anchor-width",`${Lc}px`),ea.setProperty("--radix-popper-anchor-height",`${kg}px`)}}),N&&rJ({element:N,padding:m}),dJ({arrowWidth:L,arrowHeight:X}),E&&nJ({strategy:"referenceHidden",...Z})]}),[Le,it]=BA(Ae),Ie=un(I);Ni(()=>{ae&&(Ie==null||Ie())},[ae,Ie]);const pt=(o=je.arrow)===null||o===void 0?void 0:o.x,Ue=(s=je.arrow)===null||s===void 0?void 0:s.y,ur=((i=je.arrow)===null||i===void 0?void 0:i.centerOffset)!==0,[Bn,Un]=x.useState();return Ni(()=>{$&&Un(window.getComputedStyle($).zIndex)},[$]),x.createElement("div",{ref:le.setFloating,"data-radix-popper-content-wrapper":"",style:{...be,transform:ae?be.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Bn,"--radix-popper-transform-origin":[(a=je.transformOrigin)===null||a===void 0?void 0:a.x,(c=je.transformOrigin)===null||c===void 0?void 0:c.y].join(" ")},dir:e.dir},x.createElement(cJ,{scope:u,placedSide:Le,onArrowChange:A,arrowX:pt,arrowY:Ue,shouldHideArrow:ur},x.createElement(He.div,Q({"data-side":Le,"data-align":it},_,{ref:O,style:{..._.style,animation:ae?void 0:"none",opacity:(l=je.hide)!==null&&l!==void 0&&l.referenceHidden?0:void 0}}))))});function uJ(e){return e!==null}const dJ=e=>({name:"transformOrigin",options:e,fn(n){var t,r,o,s,i;const{placement:a,rects:c,middlewareData:l}=n,d=((t=l.arrow)===null||t===void 0?void 0:t.centerOffset)!==0,f=d?0:e.arrowWidth,p=d?0:e.arrowHeight,[y,m]=BA(a),w={start:"0%",center:"50%",end:"100%"}[m],S=((r=(o=l.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+f/2,v=((s=(i=l.arrow)===null||i===void 0?void 0:i.y)!==null&&s!==void 0?s:0)+p/2;let P="",E="";return y==="bottom"?(P=d?w:`${S}px`,E=`${-p}px`):y==="top"?(P=d?w:`${S}px`,E=`${c.floating.height+p}px`):y==="right"?(P=`${-p}px`,E=d?w:`${v}px`):y==="left"&&(P=`${c.floating.width+p}px`,E=d?w:`${v}px`),{data:{x:P,y:E}}}});function BA(e){const[n,t="center"]=e.split("-");return[n,t]}const Pw=sJ,UA=aJ,HA=lJ,KA="Popover",[WA,ase]=Co(KA,[wg]),Cw=wg(),[hJ,Dc]=WA(KA),fJ=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Cw(n),c=x.useRef(null),[l,u]=x.useState(!1),[d=!1,f]=ni({prop:r,defaultProp:o,onChange:s});return x.createElement(Pw,a,x.createElement(hJ,{scope:n,contentId:Wo(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:x.useCallback(()=>f(p=>!p),[f]),hasCustomAnchor:l,onCustomAnchorAdd:x.useCallback(()=>u(!0),[]),onCustomAnchorRemove:x.useCallback(()=>u(!1),[]),modal:i},t))},pJ="PopoverTrigger",gJ=x.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Dc(pJ,t),s=Cw(t),i=Xe(n,o.triggerRef),a=x.createElement(He.button,Q({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":YA(o.open)},r,{ref:i,onClick:ie(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(UA,Q({asChild:!0},s),a)}),GA="PopoverPortal",[mJ,yJ]=WA(GA,{forceMount:void 0}),SJ=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=Dc(GA,n);return x.createElement(mJ,{scope:n,forceMount:t},x.createElement(Io,{present:t||s.open},x.createElement(ug,{asChild:!0,container:o},r)))},Su="PopoverContent",vJ=x.forwardRef((e,n)=>{const t=yJ(Su,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=Dc(Su,e.__scopePopover);return x.createElement(Io,{present:r||s.open},s.modal?x.createElement(xJ,Q({},o,{ref:n})):x.createElement(wJ,Q({},o,{ref:n})))}),xJ=x.forwardRef((e,n)=>{const t=Dc(Su,e.__scopePopover),r=x.useRef(null),o=Xe(n,r),s=x.useRef(!1);return x.useEffect(()=>{const i=r.current;if(i)return dw(i)},[]),x.createElement(hg,{as:zi,allowPinchZoom:!0},x.createElement(VA,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ie(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:ie(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,l=a.button===2||c;s.current=l},{checkForDefaultPrevented:!1}),onFocusOutside:ie(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),wJ=x.forwardRef((e,n)=>{const t=Dc(Su,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(VA,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),VA=x.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=Dc(Su,t),p=Cw(t);return uw(),x.createElement(lw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(lg,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1)},x.createElement(HA,Q({"data-state":YA(f.open),role:"dialog",id:f.contentId},p,d,{ref:n,style:{...d.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}}))))});function YA(e){return e?"open":"closed"}const bJ=fJ,PJ=gJ,CJ=SJ,IJ=vJ;function ri(e,n){const t=B(),r=x.useRef(!1),o=Eo(),s=x.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(c=>!c.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=W("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return x.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 Iw({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=ri(e,t);return h.jsx(bJ,{onOpenChange:s,open:r||o,children:h.jsx("div",{className:"tlui-popover",children:n})})}function Ew({children:e}){return h.jsx(PJ,{asChild:!0,dir:"ltr",children:e})}function _w({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=dn();return h.jsx(CJ,{container:s,children:h.jsx(IJ,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const XA=x.createContext(null);function bg(){const e=x.useContext(XA);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function Er({type:e,sourceId:n,children:t}){return h.jsx(XA.Provider,{value:{type:e,sourceId:n},children:t})}const EJ=x.createContext(void 0);function kw(e){const n=x.useContext(EJ);return e||n||"ltr"}const wy="rovingFocusGroup.onEntryFocus",_J={bubbles:!1,cancelable:!0},Tw="RovingFocusGroup",[Bv,qA,kJ]=fg(Tw),[TJ,ZA]=Co(Tw,[kJ]),[$J,MJ]=TJ(Tw),AJ=x.forwardRef((e,n)=>x.createElement(Bv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(Bv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(jJ,Q({},e,{ref:n}))))),jJ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:l,...u}=e,d=x.useRef(null),f=Xe(n,d),p=kw(s),[y=null,m]=ni({prop:i,defaultProp:a,onChange:c}),[w,S]=x.useState(!1),v=un(l),P=qA(t),E=x.useRef(!1),[C,I]=x.useState(0);return x.useEffect(()=>{const _=d.current;if(_)return _.addEventListener(wy,v),()=>_.removeEventListener(wy,v)},[v]),x.createElement($J,{scope:t,orientation:r,dir:p,loop:o,currentTabStopId:y,onItemFocus:x.useCallback(_=>m(_),[m]),onItemShiftTab:x.useCallback(()=>S(!0),[]),onFocusableItemAdd:x.useCallback(()=>I(_=>_+1),[]),onFocusableItemRemove:x.useCallback(()=>I(_=>_-1),[])},x.createElement(He.div,Q({tabIndex:w||C===0?-1:0,"data-orientation":r},u,{ref:f,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{E.current=!0}),onFocus:ie(e.onFocus,_=>{const k=!E.current;if(_.target===_.currentTarget&&k&&!w){const $=new CustomEvent(wy,_J);if(_.currentTarget.dispatchEvent($),!$.defaultPrevented){const T=P().filter(L=>L.focusable),O=T.find(L=>L.active),N=T.find(L=>L.id===y),j=[O,N,...T].filter(Boolean).map(L=>L.ref.current);QA(j)}}E.current=!1}),onBlur:ie(e.onBlur,()=>S(!1))})))}),OJ="RovingFocusGroupItem",DJ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Wo(),c=s||a,l=MJ(OJ,t),u=l.currentTabStopId===c,d=qA(t),{onFocusableItemAdd:f,onFocusableItemRemove:p}=l;return x.useEffect(()=>{if(r)return f(),()=>p()},[r,f,p]),x.createElement(Bv.ItemSlot,{scope:t,id:c,focusable:r,active:o},x.createElement(He.span,Q({tabIndex:u?0:-1,"data-orientation":l.orientation},i,{ref:n,onMouseDown:ie(e.onMouseDown,y=>{r?l.onItemFocus(c):y.preventDefault()}),onFocus:ie(e.onFocus,()=>l.onItemFocus(c)),onKeyDown:ie(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){l.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const m=FJ(y,l.orientation,l.dir);if(m!==void 0){y.preventDefault();let S=d().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=l.loop?NJ(S,v+1):S.slice(v+1)}setTimeout(()=>QA(S))}})})))}),RJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function LJ(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function FJ(e,n,t){const r=LJ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return RJ[r]}function QA(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function NJ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const zJ=AJ,BJ=DJ,Uv=["Enter"," "],UJ=["ArrowDown","PageUp","Home"],JA=["ArrowUp","PageDown","End"],HJ=[...UJ,...JA],KJ={ltr:[...Uv,"ArrowRight"],rtl:[...Uv,"ArrowLeft"]},WJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Pg="Menu",[vu,GJ,VJ]=fg(Pg),[Ji,Cg]=Co(Pg,[VJ,wg,ZA]),Ig=wg(),ej=ZA(),[tj,oi]=Ji(Pg),[YJ,Gu]=Ji(Pg),XJ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Ig(n),[c,l]=x.useState(null),u=x.useRef(!1),d=un(s),f=kw(o);return x.useEffect(()=>{const p=()=>{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",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),x.createElement(Pw,a,x.createElement(tj,{scope:n,open:t,onOpenChange:d,content:c,onContentChange:l},x.createElement(YJ,{scope:n,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:i},r)))},nj=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=Ig(t);return x.createElement(UA,Q({},o,r,{ref:n}))}),rj="MenuPortal",[qJ,oj]=Ji(rj,{forceMount:void 0}),ZJ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=oi(rj,n);return x.createElement(qJ,{scope:n,forceMount:t},x.createElement(Io,{present:t||s.open},x.createElement(ug,{asChild:!0,container:o},r)))},Ur="MenuContent",[QJ,$w]=Ji(Ur),JJ=x.forwardRef((e,n)=>{const t=oj(Ur,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=oi(Ur,e.__scopeMenu),i=Gu(Ur,e.__scopeMenu);return x.createElement(vu.Provider,{scope:e.__scopeMenu},x.createElement(Io,{present:r||s.open},x.createElement(vu.Slot,{scope:e.__scopeMenu},i.modal?x.createElement(eee,Q({},o,{ref:n})):x.createElement(tee,Q({},o,{ref:n})))))}),eee=x.forwardRef((e,n)=>{const t=oi(Ur,e.__scopeMenu),r=x.useRef(null),o=Xe(n,r);return x.useEffect(()=>{const s=r.current;if(s)return dw(s)},[]),x.createElement(Mw,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)}))}),tee=x.forwardRef((e,n)=>{const t=oi(Ur,e.__scopeMenu);return x.createElement(Mw,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),Mw=x.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:y,...m}=e,w=oi(Ur,t),S=Gu(Ur,t),v=Ig(t),P=ej(t),E=GJ(t),[C,I]=x.useState(null),_=x.useRef(null),k=Xe(n,_,w.onContentChange),$=x.useRef(0),T=x.useRef(""),O=x.useRef(0),N=x.useRef(null),A=x.useRef("right"),j=x.useRef(0),L=y?hg:x.Fragment,X=y?{as:zi,allowPinchZoom:!0}:void 0,V=U=>{var K,Z;const le=T.current+U,be=E().filter(Ie=>!Ie.disabled),Ae=document.activeElement,ae=(K=be.find(Ie=>Ie.ref.current===Ae))===null||K===void 0?void 0:K.textValue,je=be.map(Ie=>Ie.textValue),Le=gee(je,le,ae),it=(Z=be.find(Ie=>Ie.textValue===Le))===null||Z===void 0?void 0:Z.ref.current;(function Ie(pt){T.current=pt,window.clearTimeout($.current),pt!==""&&($.current=window.setTimeout(()=>Ie(""),1e3))})(le),it&&setTimeout(()=>it.focus())};x.useEffect(()=>()=>window.clearTimeout($.current),[]),uw();const H=x.useCallback(U=>{var K,Z;return A.current===((K=N.current)===null||K===void 0?void 0:K.side)&&yee(U,(Z=N.current)===null||Z===void 0?void 0:Z.area)},[]);return x.createElement(QJ,{scope:t,searchRef:T,onItemEnter:x.useCallback(U=>{H(U)&&U.preventDefault()},[H]),onItemLeave:x.useCallback(U=>{var K;H(U)||((K=_.current)===null||K===void 0||K.focus(),I(null))},[H]),onTriggerLeave:x.useCallback(U=>{H(U)&&U.preventDefault()},[H]),pointerGraceTimerRef:O,onPointerGraceIntentChange:x.useCallback(U=>{N.current=U},[])},x.createElement(L,X,x.createElement(lw,{asChild:!0,trapped:o,onMountAutoFocus:ie(s,U=>{var K;U.preventDefault(),(K=_.current)===null||K===void 0||K.focus()}),onUnmountAutoFocus:i},x.createElement(lg,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p},x.createElement(zJ,Q({asChild:!0},P,{dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:I,onEntryFocus:ie(c,U=>{S.isUsingKeyboardRef.current||U.preventDefault()})}),x.createElement(HA,Q({role:"menu","aria-orientation":"vertical","data-state":lj(w.open),"data-radix-menu-content":"",dir:S.dir},v,m,{ref:k,style:{outline:"none",...m.style},onKeyDown:ie(m.onKeyDown,U=>{const Z=U.target.closest("[data-radix-menu-content]")===U.currentTarget,le=U.ctrlKey||U.altKey||U.metaKey,be=U.key.length===1;Z&&(U.key==="Tab"&&U.preventDefault(),!le&&be&&V(U.key));const Ae=_.current;if(U.target!==Ae||!HJ.includes(U.key))return;U.preventDefault();const je=E().filter(Le=>!Le.disabled).map(Le=>Le.ref.current);JA.includes(U.key)&&je.reverse(),fee(je)}),onBlur:ie(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout($.current),T.current="")}),onPointerMove:ie(e.onPointerMove,xu(U=>{const K=U.target,Z=j.current!==U.clientX;if(U.currentTarget.contains(K)&&Z){const le=U.clientX>j.current?"right":"left";A.current=le,j.current=U.clientX}}))})))))))}),nee=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return x.createElement(He.div,Q({role:"group"},r,{ref:n}))}),Hv="MenuItem",$I="menu.itemSelect",sj=x.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=x.useRef(null),i=Gu(Hv,e.__scopeMenu),a=$w(Hv,e.__scopeMenu),c=Xe(n,s),l=x.useRef(!1),u=()=>{const d=s.current;if(!t&&d){const f=new CustomEvent($I,{bubbles:!0,cancelable:!0});d.addEventListener($I,p=>r==null?void 0:r(p),{once:!0}),cw(d,f),f.defaultPrevented?l.current=!1:i.onClose()}};return x.createElement(ij,Q({},o,{ref:c,disabled:t,onClick:ie(e.onClick,u),onPointerDown:d=>{var f;(f=e.onPointerDown)===null||f===void 0||f.call(e,d),l.current=!0},onPointerUp:ie(e.onPointerUp,d=>{var f;l.current||(f=d.currentTarget)===null||f===void 0||f.click()}),onKeyDown:ie(e.onKeyDown,d=>{const f=a.searchRef.current!=="";t||f&&d.key===" "||Uv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),ij=x.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=$w(Hv,t),a=ej(t),c=x.useRef(null),l=Xe(n,c),[u,d]=x.useState(!1),[f,p]=x.useState("");return x.useEffect(()=>{const y=c.current;if(y){var m;p(((m=y.textContent)!==null&&m!==void 0?m:"").trim())}},[s.children]),x.createElement(vu.ItemSlot,{scope:t,disabled:r,textValue:o??f},x.createElement(BJ,Q({asChild:!0},a,{focusable:!r}),x.createElement(He.div,Q({role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:l,onPointerMove:ie(e.onPointerMove,xu(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus())})),onPointerLeave:ie(e.onPointerLeave,xu(y=>i.onItemLeave(y))),onFocus:ie(e.onFocus,()=>d(!0)),onBlur:ie(e.onBlur,()=>d(!1))}))))}),ree=x.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return x.createElement(iee,{scope:e.__scopeMenu,checked:t},x.createElement(sj,Q({role:"menuitemcheckbox","aria-checked":Kv(t)?"mixed":t},o,{ref:n,"data-state":hee(t),onSelect:ie(o.onSelect,()=>r==null?void 0:r(Kv(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),oee="MenuRadioGroup";Ji(oee,{value:void 0,onValueChange:()=>{}});const see="MenuItemIndicator",[iee,cse]=Ji(see,{checked:!1}),aj="MenuSub",[aee,cj]=Ji(aj),cee=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=oi(aj,n),i=Ig(n),[a,c]=x.useState(null),[l,u]=x.useState(null),d=un(o);return x.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),x.createElement(Pw,i,x.createElement(tj,{scope:n,open:r,onOpenChange:d,content:l,onContentChange:u},x.createElement(aee,{scope:n,contentId:Wo(),triggerId:Wo(),trigger:a,onTriggerChange:c},t)))},nh="MenuSubTrigger",lee=x.forwardRef((e,n)=>{const t=oi(nh,e.__scopeMenu),r=Gu(nh,e.__scopeMenu),o=cj(nh,e.__scopeMenu),s=$w(nh,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,l={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),c(null)}},[a,c]),x.createElement(nj,Q({asChild:!0},l),x.createElement(ij,Q({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":lj(t.open)},e,{ref:cg(n,o.onTriggerChange),onClick:d=>{var f;(f=e.onClick)===null||f===void 0||f.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:ie(e.onPointerMove,xu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:ie(e.onPointerLeave,xu(d=>{var f;u();const p=(f=t.content)===null||f===void 0?void 0:f.getBoundingClientRect();if(p){var y;const m=(y=t.content)===null||y===void 0?void 0:y.dataset.side,w=m==="right",S=w?-5:5,v=p[w?"left":"right"],P=p[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+S,y:d.clientY},{x:v,y:p.top},{x:P,y:p.top},{x:P,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(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ie(e.onKeyDown,d=>{const f=s.searchRef.current!=="";if(!(e.disabled||f&&d.key===" ")&&KJ[r.dir].includes(d.key)){var p;t.onOpenChange(!0),(p=t.content)===null||p===void 0||p.focus(),d.preventDefault()}})})))}),uee="MenuSubContent",dee=x.forwardRef((e,n)=>{const t=oj(Ur,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=oi(Ur,e.__scopeMenu),i=Gu(Ur,e.__scopeMenu),a=cj(uee,e.__scopeMenu),c=x.useRef(null),l=Xe(n,c);return x.createElement(vu.Provider,{scope:e.__scopeMenu},x.createElement(Io,{present:r||s.open},x.createElement(vu.Slot,{scope:e.__scopeMenu},x.createElement(Mw,Q({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:l,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;i.isUsingKeyboardRef.current&&((d=c.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ie(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ie(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ie(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),f=WJ[i.dir].includes(u.key);if(d&&f){var p;s.onOpenChange(!1),(p=a.trigger)===null||p===void 0||p.focus(),u.preventDefault()}})})))))});function lj(e){return e?"open":"closed"}function Kv(e){return e==="indeterminate"}function hee(e){return Kv(e)?"indeterminate":e?"checked":"unchecked"}function fee(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function pee(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function gee(e,n,t){const o=n.length>1&&Array.from(n).every(l=>l===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=pee(e,Math.max(s,0));o.length===1&&(i=i.filter(l=>l!==t));const c=i.find(l=>l.toLowerCase().startsWith(o.toLowerCase()));return c!==t?c:void 0}function mee(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,c=n[s].y,l=n[i].x,u=n[i].y;c>r!=u>r&&t<(l-a)*(r-c)/(u-c)+a&&(o=!o)}return o}function yee(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return mee(t,n)}function xu(e){return n=>n.pointerType==="mouse"?e(n):void 0}const uj=XJ,dj=nj,hj=ZJ,fj=JJ,pj=nee,gj=sj,mj=ree,yj=cee,Sj=lee,vj=dee,xj="ContextMenu",[See,lse]=Co(xj,[Cg]),_o=Cg(),[vee,wj]=See(xj),xee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=x.useState(!1),c=_o(n),l=un(r),u=x.useCallback(d=>{a(d),l(d)},[l]);return x.createElement(vee,{scope:n,open:i,onOpenChange:u,modal:s},x.createElement(uj,Q({},c,{dir:o,open:i,onOpenChange:u,modal:s}),t))},wee="ContextMenuTrigger",bee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=wj(wee,t),i=_o(t),a=x.useRef({x:0,y:0}),c=x.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),l=x.useRef(0),u=x.useCallback(()=>window.clearTimeout(l.current),[]),d=f=>{a.current={x:f.clientX,y:f.clientY},s.onOpenChange(!0)};return x.useEffect(()=>u,[u]),x.useEffect(()=>void(r&&u()),[r,u]),x.createElement(x.Fragment,null,x.createElement(dj,Q({},i,{virtualRef:c})),x.createElement(He.span,Q({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:ie(e.onContextMenu,f=>{u(),d(f),f.preventDefault()}),onPointerDown:r?e.onPointerDown:ie(e.onPointerDown,rh(f=>{u(),l.current=window.setTimeout(()=>d(f),700)})),onPointerMove:r?e.onPointerMove:ie(e.onPointerMove,rh(u)),onPointerCancel:r?e.onPointerCancel:ie(e.onPointerCancel,rh(u)),onPointerUp:r?e.onPointerUp:ie(e.onPointerUp,rh(u))})))}),bj=e=>{const{__scopeContextMenu:n,...t}=e,r=_o(n);return x.createElement(hj,Q({},r,t))},Pee="ContextMenuContent",Cee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=wj(Pee,t),s=_o(t),i=x.useRef(!1);return x.createElement(fj,Q({},s,r,{ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var c;(c=e.onCloseAutoFocus)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var c;(c=e.onInteractOutside)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),Iee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=_o(t);return x.createElement(pj,Q({},o,r,{ref:n}))}),Eee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=_o(t);return x.createElement(gj,Q({},o,r,{ref:n}))}),_ee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=_o(t);return x.createElement(mj,Q({},o,r,{ref:n}))}),kee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=_o(n),[a,c]=ni({prop:o,defaultProp:s,onChange:r});return x.createElement(yj,Q({},i,{open:a,onOpenChange:c}),t)},Tee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=_o(t);return x.createElement(Sj,Q({},o,r,{ref:n}))}),$ee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=_o(t);return x.createElement(vj,Q({},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)"}}))});function rh(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const Mee=xee,Aee=bee,jee=bj,Oee=Cee,Dee=_ee,Pj=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Ree=Pj?"⌘":"Ctrl",Lee=Pj?"⌥":"Alt";function Cj(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,Ree).replace(/\?/g,Lee).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Wv(e){return"— "+Cj(e).join(" ")}function Fee(e){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const Ij="DropdownMenu",[Nee,use]=Co(Ij,[Cg]),ko=Cg(),[zee,Ej]=Nee(Ij),Bee=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=ko(n),l=x.useRef(null),[u=!1,d]=ni({prop:o,defaultProp:s,onChange:i});return x.createElement(zee,{scope:n,triggerId:Wo(),triggerRef:l,contentId:Wo(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(f=>!f),[d]),modal:a},x.createElement(uj,Q({},c,{open:u,onOpenChange:d,dir:r,modal:a}),t))},Uee="DropdownMenuTrigger",Hee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=Ej(Uee,t),i=ko(t);return x.createElement(dj,Q({asChild:!0},i),x.createElement(He.button,Q({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:cg(n,s.triggerRef),onPointerDown:ie(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ie(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),Kee=e=>{const{__scopeDropdownMenu:n,...t}=e,r=ko(n);return x.createElement(hj,Q({},r,t))},Wee="DropdownMenuContent",Gee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Ej(Wee,t),s=ko(t),i=x.useRef(!1);return x.createElement(fj,Q({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:n,onCloseAutoFocus:ie(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)===null||c===void 0||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ie(e.onInteractOutside,a=>{const c=a.detail.originalEvent,l=c.button===0&&c.ctrlKey===!0,u=c.button===2||l;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),Vee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=ko(t);return x.createElement(pj,Q({},o,r,{ref:n}))}),Yee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=ko(t);return x.createElement(gj,Q({},o,r,{ref:n}))}),Xee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=ko(t);return x.createElement(mj,Q({},o,r,{ref:n}))}),qee=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=ko(n),[a=!1,c]=ni({prop:r,defaultProp:s,onChange:o});return x.createElement(yj,Q({},i,{open:a,onOpenChange:c}),t)},Zee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=ko(t);return x.createElement(Sj,Q({},o,r,{ref:n}))}),Qee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=ko(t);return x.createElement(vj,Q({},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)"}}))}),Aw=Bee,jw=Hee,Eg=Kee,Ow=Gee,Jee=Vee,ete=Yee,tte=Xee,nte=qee,rte=Zee,ote=Qee;function Ui({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=ri(e);return h.jsx(Aw,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function Hi({children:e,...n}){return h.jsx(jw,{dir:"ltr",asChild:!0,onTouchEnd:t=>_e(t),...n,children:e})}function Ki({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=dn();return h.jsx(Eg,{container:s,children:h.jsx(Ow,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function ste({id:e,children:n}){const[t,r]=ri(e);return h.jsx(nte,{open:t,onOpenChange:r,children:n})}function ite({id:e,label:n,title:t,disabled:r}){return h.jsx(rte,{dir:"ltr",asChild:!0,disabled:r,children:h.jsxs(he,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[h.jsx(It,{children:n}),h.jsx(Pe,{icon:"chevron-right",small:!0})]})})}function ate({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=dn();return h.jsx(Eg,{container:s,children:h.jsx(ote,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function cte({children:e}){return h.jsx(Jee,{dir:"ltr",className:"tlui-menu__group",children:e})}function wu({noClose:e,children:n}){return h.jsx(ete,{dir:"ltr",asChild:!0,onClick:e?_e:void 0,children:n})}function Fl({children:e,visibleOnMobileLayout:n=!1}){const t=zn();return!n&&t<wt.MOBILE?null:h.jsx("kbd",{className:"tlui-kbd",children:Cj(e).map((r,o)=>h.jsx("span",{children:r},o))})}function z({disabled:e=!1,spinner:n=!1,readonlyOk:t=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:c,isSelected:l}){const{type:u,sourceId:d}=bg(),f=Me(),[p,y]=x.useState(!1);if(ss()&&!t)return null;const w=gu(s,u),S=o?Wv(o):void 0,v=w?f(w):void 0,P=v&&S?`${v} ${S}`:v;switch(u){case"menu":return h.jsx(wu,{children:h.jsxs(he,{type:"menu","data-testid":`${d}.${r}`,disabled:e,title:P,onClick:E=>{c&&_e(E),p?y(!1):a(d)},children:[h.jsx(It,{children:v}),o&&h.jsx(Fl,{children:o})]})});case"context-menu":return e?null:h.jsxs(Eee,{dir:"ltr",title:P,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${d}.${r}`,onSelect:E=>{c&&_e(E),p?y(!1):a(d)},children:[h.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&h.jsx(Fl,{children:o}),n&&h.jsx(Fee,{})]});case"panel":return h.jsxs(he,{"data-testid":`${d}.${r}`,type:"menu",title:P,disabled:e,onClick:()=>a(d),children:[h.jsx(It,{children:v}),i&&h.jsx(Pe,{icon:i})]});case"small-icons":case"icons":return h.jsx(he,{"data-testid":`${d}.${r}`,type:"icon",title:P,disabled:e,onClick:()=>a(d),children:h.jsx(Pe,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return o?h.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${d}.${r}`,children:[h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:h.jsx(Fl,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return h.jsxs(he,{type:"low",onClick:()=>a(d),children:[h.jsx(Pe,{icon:i}),h.jsx(It,{children:v})]});case"toolbar":return h.jsx(he,{type:"tool","data-testid":`tools.${r}`,"aria-label":w,"data-value":r,onClick:()=>a("toolbar"),title:P,onTouchStart:E=>{_e(E),a("toolbar")},role:"radio","aria-checked":l?"true":"false",children:h.jsx(Pe,{icon:i})});case"toolbar-overflow":return h.jsx(wu,{"aria-label":s,children:h.jsx(he,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:P,role:"radio","aria-checked":l?"true":"false","data-value":r,children:h.jsx(Pe,{icon:i})})});default:throw sn(u)}}function lte(){return h.jsxs(h.Fragment,{children:[h.jsx(ute,{}),h.jsx(dte,{}),h.jsx(hte,{}),h.jsx(fte,{}),h.jsx(pte,{}),h.jsx(yte,{}),h.jsx(Ste,{}),h.jsx(vte,{})]})}function ute(){const e=ce(),n=wn(2);return h.jsxs(h.Fragment,{children:[h.jsx(z,{...e["align-left"],disabled:!n}),h.jsx(z,{...e["align-center-horizontal"],disabled:!n}),h.jsx(z,{...e["align-right"],disabled:!n}),h.jsx(z,{...e["stretch-horizontal"],disabled:!n}),h.jsx(z,{...e["align-top"],disabled:!n}),h.jsx(z,{...e["align-center-vertical"],disabled:!n}),h.jsx(z,{...e["align-bottom"],disabled:!n}),h.jsx(z,{...e["stretch-vertical"],disabled:!n})]})}function dte(){const e=ce(),n=wn(3);return h.jsxs(h.Fragment,{children:[h.jsx(z,{...e["distribute-horizontal"],disabled:!n}),h.jsx(z,{...e["distribute-vertical"],disabled:!n})]})}function hte(){const e=ce(),n=x$();return h.jsxs(h.Fragment,{children:[h.jsx(z,{...e["stack-horizontal"],disabled:!n}),h.jsx(z,{...e["stack-vertical"],disabled:!n})]})}function fte(){const e=ce(),n=wn(1);return h.jsxs(h.Fragment,{children:[h.jsx(z,{...e["send-to-back"],disabled:!n}),h.jsx(z,{...e["send-backward"],disabled:!n}),h.jsx(z,{...e["bring-forward"],disabled:!n}),h.jsx(z,{...e["bring-to-front"],disabled:!n})]})}function pte(){return zn()<wt.TABLET_SM?h.jsx(gte,{}):h.jsx(mte,{})}function gte(){const e=ce(),n=B(),t=W("zoom is 1",()=>n.getZoomLevel()===1,[n]);return h.jsx(z,{...e["zoom-to-100"],disabled:t})}function mte(){const e=ce(),n=wn(1);return h.jsx(z,{...e["rotate-ccw"],disabled:!n})}function yte(){const e=ce(),n=wn(1);return h.jsx(z,{...e["rotate-cw"],disabled:!n})}function Ste(){const e=ce(),n=P$();return h.jsx(z,{...e["edit-link"],disabled:!n})}function vte(){const e=w$(),n=b$();return e?h.jsx(MI,{}):n?h.jsx(xte,{}):h.jsx(MI,{})}function MI(){const e=ce(),n=wn(2);return h.jsx(z,{...e.group,disabled:!n})}function xte(){const e=ce();return h.jsx(z,{...e.ungroup})}const wte=x.memo(function({children:n}){const t=Me(),r=zn(),o=ss(),s=B(),i=W("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??h.jsx(lte,{});if(!(o&&!i))return h.jsxs(Iw,{id:"actions-menu",children:[h.jsx(Ew,{children:h.jsx(he,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:h.jsx(Pe,{icon:"dots-vertical",small:!0})})}),h.jsx(_w,{side:r>=wt.TABLET?"bottom":"top",sideOffset:6,children:h.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:h.jsx(Er,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function kr({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:c,sourceId:l}=bg(),u=ss(),d=Me();if(u&&!r)return null;const f=gu(t,c),p=f?d(f):void 0;switch(c){case"menu":return h.jsxs(tte,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:p,onSelect:y=>{o==null||o(l),_e(y)},disabled:i,checked:a,children:[h.jsx(Ws,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),n&&h.jsx(Fl,{children:n})]});case"context-menu":return h.jsxs(Dee,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:p,onSelect:y=>{o(l),_e(y)},disabled:i,checked:a,children:[h.jsx(Ws,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),n&&h.jsx(Fl,{children:n})]},e);default:return null}}function me({id:e,label:n,children:t}){const{type:r,sourceId:o}=bg(),s=Me(),i=gu(n,r),a=i?s(i):void 0;switch(r){case"panel":return h.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return h.jsx(cte,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return h.jsx(Iee,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return h.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[h.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),h.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function Tr({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=bg(),a=dn(),c=Me(),l=t?typeof t=="string"?t:t[s]??t.default:void 0,u=l?c(l):void 0;switch(s){case"menu":return h.jsxs(ste,{id:`${i}-sub.${e}`,children:[h.jsx(ite,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:n,label:u,title:u}),h.jsx(ate,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:h.jsxs(bte,{id:`${i}-sub.${e}`,children:[h.jsx(Tee,{dir:"ltr",disabled:n,asChild:!0,children:h.jsxs(he,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[h.jsx(It,{children:u}),h.jsx(Pe,{icon:"chevron-right",small:!0})]})}),h.jsx(bj,{container:a,children:h.jsx($ee,{"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 bte({id:e,children:n}){const[t,r]=ri(e);return h.jsx(kee,{open:t,onOpenChange:r,children:n})}function _j(){const e=ce();return dG()?h.jsx(z,{...e["toggle-auto-size"]}):null}function kj(){const e=ce();return P$()?h.jsx(z,{...e["edit-link"]}):null}function Pte(){const e=ce();return wn(1)?h.jsx(z,{...e.duplicate}):null}function Tj(){const e=ce();return w$()?h.jsx(z,{...e.group}):null}function $j(){const e=ce();return b$()?h.jsx(z,{...e.ungroup}):null}function Mj(){const e=B(),n=ce();return W("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?h.jsx(z,{...n["remove-frame"]}):null}function Aj(){const e=B(),n=ce();return W("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?h.jsx(z,{...n["fit-frame-to-content"]}):null}function jj(){const e=B(),n=ce();return W("selected shapes",()=>e.getSelectedShapes().length>0,[e])?h.jsx(z,{...n["toggle-lock"]}):null}function Dw(){const e=ce(),n=B(),t=W("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return h.jsx(kr,{...e["toggle-transparent"],checked:t,toggle:!0})}function Cte(){const e=B(),n=ce(),t=W("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsx(z,{...n["unlock-all"],disabled:!t})}function Oj(){const e=B(),n=W("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=ce();return h.jsx(z,{...t["zoom-to-100"],noClose:!0,disabled:n})}function Dj(){const e=B(),n=W("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=ce();return h.jsx(z,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function Rj(){const e=B(),n=W("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=ce();return h.jsx(z,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function Lj(){return h.jsxs(me,{id:"clipboard",children:[h.jsx(Ete,{}),h.jsx(_te,{}),h.jsx(kte,{}),h.jsx(Pte,{}),h.jsx(Tte,{})]})}function Ite(){var r;const e=B(),n=ce(),t=W("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsxs(Tr,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[h.jsxs(me,{id:"copy-as-group",children:[h.jsx(z,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&h.jsx(z,{...n["copy-as-png"]}),h.jsx(z,{...n["copy-as-json"]})]}),h.jsx(me,{id:"copy-as-bg",children:h.jsx(Dw,{})})]})}function Ete(){const e=ce(),n=wn(1);return h.jsx(z,{...e.cut,disabled:!n})}function _te(){const e=ce(),n=uG(1);return h.jsx(z,{...e.copy,disabled:!n})}function kte(){const e=ce(),n=lG;return h.jsx(z,{...e.paste,disabled:!n})}function Fj(){const e=B(),n=ce();return W("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?h.jsxs(me,{id:"conversions",children:[h.jsx(Ite,{}),h.jsxs(Tr,{id:"export-as",label:"context-menu.export-as",size:"small",children:[h.jsxs(me,{id:"export-as-group",children:[h.jsx(z,{...n["export-as-svg"]}),h.jsx(z,{...n["export-as-png"]}),h.jsx(z,{...n["export-as-json"]})]}),h.jsx(me,{id:"export-as-bg",children:h.jsx(Dw,{})})]})]}):null}function Nj(){const e=ce(),n=B(),t=W("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return h.jsx(z,{...e["select-all"],disabled:!t})}function Tte(){const e=ce(),n=wn(1);return h.jsx(z,{...e.delete,disabled:!n})}function $te(){const e=wn(2),n=hG(),t=ce();return e||n?h.jsxs(Tr,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&h.jsxs(me,{id:"align",children:[h.jsx(z,{...t["align-left"]}),h.jsx(z,{...t["align-center-horizontal"]}),h.jsx(z,{...t["align-right"]}),h.jsx(z,{...t["align-top"]}),h.jsx(z,{...t["align-center-vertical"]}),h.jsx(z,{...t["align-bottom"]})]}),h.jsx(Mte,{}),e&&h.jsxs(me,{id:"stretch",children:[h.jsx(z,{...t["stretch-horizontal"]}),h.jsx(z,{...t["stretch-vertical"]})]}),(e||n)&&h.jsxs(me,{id:"flip",children:[h.jsx(z,{...t["flip-horizontal"]}),h.jsx(z,{...t["flip-vertical"]})]}),h.jsx(Ate,{})]}):null}function Mte(){const e=ce();return wn(3)?h.jsxs(me,{id:"distribute",children:[h.jsx(z,{...e["distribute-horizontal"]}),h.jsx(z,{...e["distribute-vertical"]})]}):null}function Ate(){const e=ce(),n=wn(2),t=x$();return n?h.jsxs(me,{id:"order",children:[h.jsx(z,{...e.pack}),t&&h.jsx(z,{...e["stack-horizontal"]}),t&&h.jsx(z,{...e["stack-vertical"]})]}):null}function jte(){const e=ce();return wn(1)?h.jsx(Tr,{id:"reorder",label:"context-menu.reorder",size:"small",children:h.jsxs(me,{id:"reorder",children:[h.jsx(z,{...e["bring-to-front"]}),h.jsx(z,{...e["bring-forward"]}),h.jsx(z,{...e["send-backward"]}),h.jsx(z,{...e["send-to-back"]})]})}):null}function Ote(){const e=B(),n=W("pages",()=>e.getPages(),[e]),t=W("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Yr(),o=ce(),s=Eo();return wn(1)?h.jsxs(Tr,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[h.jsx(me,{id:"pages",children:n.map(a=>h.jsx(z,{id:a.id,disabled:t===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const c=e.getPage(a.id);c&&r({title:"Changed Page",description:`Moved to ${c.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),h.jsx(me,{id:"new-page",children:h.jsx(z,{...o["new-page"]})})]}):null}function zj(){const e=B(),n=ce();return W("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(z,{...n["convert-to-bookmark"]}):null}function Bj(){const e=B(),n=ce();return W("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&ks(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(z,{...n["convert-to-embed"]}):null}function Dte(){const e=ce(),n=B(),t=W("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return h.jsx(kr,{...e["toggle-snap-mode"],checked:t})}function Rte(){const e=ce(),n=B(),t=W("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return h.jsx(kr,{...e["toggle-tool-lock"],checked:t})}function Lte(){const e=ce(),n=B(),t=W("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return h.jsx(kr,{...e["toggle-grid"],checked:t})}function Fte(){const e=ce(),n=B(),t=W("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return h.jsx(kr,{...e["toggle-wrap-mode"],checked:t})}function Nte(){const e=ce(),n=B(),t=W("isDarkMode",()=>n.user.getIsDarkMode(),[n]);return h.jsx(kr,{...e["toggle-dark-mode"],checked:t})}function zte(){const e=ce(),n=B(),t=W("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return h.jsx(kr,{...e["toggle-focus-mode"],checked:t})}function Bte(){const e=ce(),n=B(),t=W("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return h.jsx(kr,{...e["toggle-edge-scrolling"],checked:t===1})}function Ute(){const e=ce(),n=B(),t=W("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return h.jsx(kr,{...e["toggle-reduce-motion"],checked:t===0})}function Hte(){const e=ce(),n=B(),t=W("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return h.jsx(kr,{...e["toggle-debug-mode"],checked:t})}function Kte(){const e=B();return W("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?h.jsxs(h.Fragment,{children:[h.jsxs(me,{id:"misc",children:[h.jsx(Tj,{}),h.jsx($j,{}),h.jsx(kj,{}),h.jsx(_j,{}),h.jsx(Mj,{}),h.jsx(Aj,{}),h.jsx(Bj,{}),h.jsx(zj,{}),h.jsx(jj,{})]}),h.jsxs(me,{id:"modify",children:[h.jsx($te,{}),h.jsx(jte,{}),h.jsx(Ote,{})]}),h.jsx(Lj,{}),h.jsx(Fj,{}),h.jsx(me,{id:"select-all",children:h.jsx(Nj,{})})]}):null}const Wte=x.memo(function({children:n}){const t=B(),{Canvas:r}=ht(),o=x.useCallback(l=>{if(l){if(t.getInstanceState().isCoarsePointer){const u=t.getSelectedShapes(),{inputs:{currentPagePoint:d}}=t,f=t.getShapesAtPoint(d);if(!t.getSelectedShapes().length||!f.some(p=>u.includes(p))){const p=f.filter(y=>t.isShapeOrAncestorLocked(y));p.length&&t.select(...p.map(y=>y.id))}}}else{const u=t.getOnlySelectedShape();u&&t.isShapeOrAncestorLocked(u)&&t.setSelectedShapes([])}},[t]),s=dn(),[i,a]=ri("context menu",o),c=n??h.jsx(Kte,{});return h.jsxs(Mee,{dir:"ltr",onOpenChange:a,modal:!1,children:[h.jsx(Aee,{onContextMenu:void 0,dir:"ltr",children:r?h.jsx(r,{}):null}),i&&h.jsx(jee,{container:s,children:h.jsx(Oee,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:_e,children:h.jsx(Er,{type:"context-menu",sourceId:"context-menu",children:c})})})]})});function Gv({checked:e}){return h.jsx(Ws,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function Gte(){const e=B(),{addToast:n}=Yr(),{addDialog:t}=Qi(),[r,o]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(me,{id:"items",children:[h.jsx(z,{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"}),h.jsx(z,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>h.jsx(Xte,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),h.jsx(z,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>qte(e,100)}),h.jsx(z,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const s=e.getSelectedShapes(),i=s.length===0?e.getRenderingShapes():s;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),h.jsx(z,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),h.jsx(z,{id:"hard-reset",onSelect:G_,label:"Hard reset"})]}),h.jsxs(me,{id:"flags",children:[h.jsx(Vte,{}),h.jsx(Yte,{})]})]})}function Vte(){const e=Object.values(Pt);return e.length?h.jsx(Tr,{id:"debug flags",label:"Debug Flags",children:h.jsx(me,{id:"debug flags",children:e.map(n=>h.jsx(Uj,{flag:n},n.name))})}):null}function Yte(){const e=Object.values(PL);return e.length?h.jsx(Tr,{id:"feature flags",label:"Feature Flags",children:h.jsx(me,{id:"feature flags",children:e.map(n=>h.jsx(Uj,{flag:n},n.name))})}):null}function Xte({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,c]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(mg,{children:[h.jsx(yg,{children:e}),h.jsx(Sg,{})]}),h.jsx(pu,{style:{maxWidth:350},children:n}),h.jsxs(fw,{className:"tlui-dialog__footer__actions",children:[o&&h.jsxs(he,{type:"normal",onClick:()=>c(!a),style:{marginRight:"auto"},children:[h.jsx(Gv,{checked:a}),h.jsx(It,{children:"Don't show again"})]}),h.jsx(he,{type:"normal",onClick:s,children:h.jsx(It,{children:t})}),h.jsx(he,{type:"primary",onClick:async()=>i(),children:h.jsx(It,{children:r})})]})]})}const Uj=ir(function({flag:n,onChange:t}){const r=n.get();return h.jsx(kr,{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 AI=0;function qte(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)AI++,t[o]={id:Be("box"+AI),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function Zte({children:e}){const n=e??h.jsx(Gte,{});return h.jsxs(Ui,{id:"debug",children:[h.jsx(Hi,{children:h.jsx(he,{type:"icon",title:"Debug menu",children:h.jsx(Pe,{icon:"dots-horizontal"})})}),h.jsx(Ki,{side:"top",align:"end",alignOffset:0,children:h.jsx(Er,{type:"menu",sourceId:"debug-panel",children:n})})]})}const Qte=x.memo(function(){const{DebugMenu:n}=ii();return h.jsxs("div",{className:"tlui-debug-panel",children:[h.jsx(ene,{}),h.jsx(tne,{}),n&&h.jsx(n,{})]})});function Jte(e=!0){const[n,t]=x.useState(0),r=B();x.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const ene=ir(function(){Jte();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:""} / [${b.ToInt(n.getPointInShapeSpace(s,n.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${b.ToInt(n.inputs.originPagePoint)}] → [${b.ToInt(n.inputs.currentPagePoint)}] = ${b.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return h.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function tne(){const e=W("show_fps",()=>Pt.showFps.get(),[Pt]),n=x.useRef(null);return x.useEffect(()=>{if(!e)return;const t=250;let r=0,o=!1,s=performance.now(),i=0,a=0,c=!1;function l(){if(!o){if(a++,i=performance.now()-s,i>t){const u=Math.round(a*(t/i)*(1e3/t));u>r&&(r=u);const d=r*.75;(u<d&&!c||u>=d&&c)&&(c=!c),n.current.innerHTML=`FPS ${u.toString()}`,n.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),i-=t,a=0,s=performance.now()}requestAnimationFrame(l)}}return l(),()=>{o=!0}},[e]),e?h.jsx("div",{ref:n}):null}function Hj(){const e=B(),n=Eo(),t=W("locale",()=>e.user.getLocale(),[e]);return h.jsx(Tr,{id:"help menu language",label:"menu.language",children:h.jsx(me,{id:"languages",children:Hl.map(({locale:r,label:o})=>h.jsx(kr,{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 nne(){return h.jsxs(h.Fragment,{children:[h.jsx(Hj,{}),h.jsx(rne,{})]})}function rne(){const{KeyboardShortcutsDialog:e}=ii(),{addDialog:n}=Qi();return e?h.jsx(z,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const one=x.memo(function({children:n}){const t=Me(),r=zn(),o=n??h.jsx(nne,{});return r<wt.MOBILE?null:h.jsx("div",{className:"tlui-help-menu",children:h.jsxs(Ui,{id:"help menu",children:[h.jsx(Hi,{children:h.jsx(he,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:h.jsx(Pe,{icon:"question-mark",small:!0})})}),h.jsx(Ki,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:h.jsx(Er,{type:"menu",sourceId:"help-menu",children:o})})]})})});function sne(){const e=B(),n=ce(),[t,r]=x.useState(!1),o=x.useRef(!1);return $s("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?h.jsx(z,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function ine(){const e=B(),n=ce();return W("is pen mode",()=>e.getInstanceState().isPenMode,[e])?h.jsx(z,{...n["exit-pen-mode"]}):null}function ane(){const e=B(),n=ce();return W("is following user",()=>!!e.getInstanceState().followingUserId,[e])?h.jsx(z,{...n["stop-following"]}):null}function cne(){return h.jsxs(h.Fragment,{children:[h.jsx(ine,{}),h.jsx(sne,{}),h.jsx(ane,{})]})}function lne({children:e}){const n=e??h.jsx(cne,{});return h.jsx("div",{className:"tlui-helper-buttons",children:h.jsx(Er,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}function une(){const e=ce(),n=vg();return h.jsxs(h.Fragment,{children:[h.jsxs(me,{label:"shortcuts-dialog.tools",id:"tools",children:[h.jsx(z,{...e["toggle-tool-lock"]}),h.jsx(z,{...e["insert-media"]}),h.jsx(z,{...n.select}),h.jsx(z,{...n.draw}),h.jsx(z,{...n.eraser}),h.jsx(z,{...n.hand}),h.jsx(z,{...n.rectangle}),h.jsx(z,{...n.ellipse}),h.jsx(z,{...n.arrow}),h.jsx(z,{...n.line}),h.jsx(z,{...n.text}),h.jsx(z,{...n.frame}),h.jsx(z,{...n.note}),h.jsx(z,{...n.laser})]}),h.jsxs(me,{label:"shortcuts-dialog.preferences",id:"preferences",children:[h.jsx(z,{...e["toggle-dark-mode"]}),h.jsx(z,{...e["toggle-focus-mode"]}),h.jsx(z,{...e["toggle-grid"]})]}),h.jsxs(me,{label:"shortcuts-dialog.edit",id:"edit",children:[h.jsx(z,{...e.undo}),h.jsx(z,{...e.redo}),h.jsx(z,{...e.cut}),h.jsx(z,{...e.copy}),h.jsx(z,{...e.paste}),h.jsx(z,{...e["select-all"]}),h.jsx(z,{...e.delete}),h.jsx(z,{...e.duplicate})]}),h.jsxs(me,{label:"shortcuts-dialog.view",id:"view",children:[h.jsx(z,{...e["zoom-in"]}),h.jsx(z,{...e["zoom-out"]}),h.jsx(z,{...e["zoom-to-100"]}),h.jsx(z,{...e["zoom-to-fit"]}),h.jsx(z,{...e["zoom-to-selection"]})]}),h.jsxs(me,{label:"shortcuts-dialog.transform",id:"transform",children:[h.jsx(z,{...e["bring-to-front"]}),h.jsx(z,{...e["bring-forward"]}),h.jsx(z,{...e["send-backward"]}),h.jsx(z,{...e["send-to-back"]}),h.jsx(z,{...e.group}),h.jsx(z,{...e.ungroup}),h.jsx(z,{...e["flip-horizontal"]}),h.jsx(z,{...e["flip-vertical"]}),h.jsx(z,{...e["align-top"]}),h.jsx(z,{...e["align-center-vertical"]}),h.jsx(z,{...e["align-bottom"]}),h.jsx(z,{...e["align-left"]}),h.jsx(z,{...e["align-center-horizontal"]}),h.jsx(z,{...e["align-right"]})]})]})}const dne=x.memo(function({children:n}){const t=Me(),r=zn(),o=n??h.jsx(une,{});return h.jsxs(h.Fragment,{children:[h.jsxs(mg,{className:"tlui-shortcuts-dialog__header",children:[h.jsx(yg,{children:t("shortcuts-dialog.title")}),h.jsx(Sg,{})]}),h.jsx(pu,{className:ue("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=wt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=wt.TABLET}),children:h.jsx(Er,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),h.jsx("div",{className:"tlui-dialog__scrim"})]})});function hne(){return h.jsxs(h.Fragment,{children:[h.jsx(pne,{}),h.jsx(Sne,{}),h.jsx(fne,{}),h.jsx(vne,{}),h.jsx(xne,{})]})}function fne(){const e=ce();return h.jsxs(Tr,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[h.jsxs(me,{id:"export-all-as-group",children:[h.jsx(z,{...e["export-all-as-svg"]}),h.jsx(z,{...e["export-all-as-png"]}),h.jsx(z,{...e["export-all-as-json"]})]}),h.jsx(me,{id:"export-all-as-bg",children:h.jsx(Dw,{})})]})}function pne(){const e=B(),n=W("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return h.jsxs(Tr,{id:"edit",label:"menu.edit",disabled:!n,children:[h.jsx(yne,{}),h.jsx(Lj,{}),h.jsx(Fj,{}),h.jsx(gne,{}),h.jsx(mne,{}),h.jsx(me,{id:"select-all",children:h.jsx(Nj,{})})]})}function gne(){return h.jsxs(me,{id:"misc",children:[h.jsx(Tj,{}),h.jsx($j,{}),h.jsx(kj,{}),h.jsx(_j,{}),h.jsx(Mj,{}),h.jsx(Aj,{}),h.jsx(Bj,{}),h.jsx(zj,{})]})}function mne(){return h.jsxs(me,{id:"lock",children:[h.jsx(jj,{}),h.jsx(Cte,{})]})}function yne(){const e=ce(),n=I$(),t=C$();return h.jsxs(me,{id:"undo-redo",children:[h.jsx(z,{...e.undo,disabled:!n}),h.jsx(z,{...e.redo,disabled:!t})]})}function Sne(){const e=ce();return h.jsx(Tr,{id:"view",label:"menu.view",children:h.jsxs(me,{id:"view-actions",children:[h.jsx(z,{...e["zoom-in"]}),h.jsx(z,{...e["zoom-out"]}),h.jsx(Oj,{}),h.jsx(Dj,{}),h.jsx(Rj,{})]})})}function vne(){const e=ce();return h.jsxs(me,{id:"extras",children:[h.jsx(z,{...e["insert-embed"]}),h.jsx(z,{...e["insert-media"]})]})}function xne(){return h.jsx(me,{id:"preferences",children:h.jsxs(Tr,{id:"preferences",label:"menu.preferences",children:[h.jsxs(me,{id:"preferences-actions",children:[h.jsx(Dte,{}),h.jsx(Rte,{}),h.jsx(Lte,{}),h.jsx(Fte,{}),h.jsx(Nte,{}),h.jsx(zte,{}),h.jsx(Bte,{}),h.jsx(Ute,{}),h.jsx(Hte,{})]}),h.jsx(me,{id:"language",children:h.jsx(Hj,{})})]})})}const wne=x.memo(function({children:n}){const t=dn(),[r,o]=ri("main menu"),s=Me(),i=n??h.jsx(hne,{});return h.jsxs(Aw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(jw,{asChild:!0,dir:"ltr",children:h.jsx(he,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:h.jsx(Pe,{icon:"menu",small:!0})})}),h.jsx(Eg,{container:t,children:h.jsx(Ow,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:h.jsx(Er,{type:"menu",sourceId:"main-menu",children:i})})})]})}),bne=x.memo(function(){const n=zn(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=ii();return!t&&!s&&n<6?null:h.jsx("div",{className:"tlui-menu-zone",children:h.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&h.jsx(t,{}),s&&h.jsx(s,{}),n<6?null:h.jsxs(h.Fragment,{children:[r&&h.jsx(r,{}),o&&h.jsx(o,{})]})]})})}),by={};function cl(e){if(by[e])return by[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 by[e]=a,a}const uf=10,Kj=4*6*uf+12+4*12;function ya(e,{center:n,radius:t,numArcSegments:r=20,startAngle:o=0,endAngle:s=Re,offset:i=0}){const a=(s-o)/r;let c=i;for(let l=o;l<s;l+=a)e[c++]=n.x,e[c++]=n.y,e[c++]=n.x+Math.cos(l)*t,e[c++]=n.y+Math.sin(l)*t,e[c++]=n.x+Math.cos(l+a)*t,e[c++]=n.y+Math.sin(l+a)*t;return e}function Sa(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 Pne(e,n,t){const r=uf;t=Math.min(t,Math.min(n.w,n.h)/2);const o=J.ExpandBy(n,-t);if(o.w<=0||o.h<=0)return ya(e,{center:n.center,radius:t,numArcSegments:uf*4}),uf*4*6;let s=0;return Sa(e,s,o.minX,o.minY,o.w,o.h),s+=12,Sa(e,s,o.minX,n.minY,o.w,t),s+=12,Sa(e,s,o.maxX,o.minY,t,o.h),s+=12,Sa(e,s,o.minX,o.maxY,o.w,t),s+=12,Sa(e,s,n.minX,o.minY,t,o.h),s+=12,ya(e,{numArcSegments:r,offset:s,center:o.point,radius:t,startAngle:ke,endAngle:ke*1.5}),s+=r*6,ya(e,{numArcSegments:r,offset:s,center:b.Add(o.point,new b(o.w,0)),radius:t,startAngle:ke*1.5,endAngle:Re}),s+=r*6,ya(e,{numArcSegments:r,offset:s,center:b.Add(o.point,o.size),radius:t,startAngle:0,endAngle:Ve}),s+=r*6,ya(e,{numArcSegments:r,offset:s,center:b.Add(o.point,new b(0,o.h)),radius:t,startAngle:Ve,endAngle:ke}),Kj}function Cne(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
291
- precision mediump float;
292
-
293
- in vec2 shapeVertexPosition;
294
-
295
- uniform vec4 canvasPageBounds;
296
-
297
- // taken (with thanks) from
298
- // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
299
- void main() {
300
- // convert the position from pixels to 0.0 to 1.0
301
- vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
302
-
303
- // convert from 0->1 to 0->2
304
- vec2 zeroToTwo = zeroToOne * 2.0;
305
-
306
- // convert from 0->2 to -1->+1 (clipspace)
307
- vec2 clipSpace = zeroToTwo - 1.0;
308
-
309
- gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
310
- }`,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
311
- precision mediump float;
312
-
313
- uniform vec4 fillColor;
314
- out vec4 outputColor;
315
-
316
- void main() {
317
- outputColor = fillColor;
318
- }`,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 c=n.getUniformLocation(i,"canvasPageBounds"),l=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:oh(n,1024),unselectedShapes:oh(n,4096),viewport:oh(n,Kj),collaborators:oh(n,1024),prepareTriangles(f,p){n.bindBuffer(n.ARRAY_BUFFER,f.buffer),n.bufferData(n.ARRAY_BUFFER,f.vertices,n.STATIC_DRAW,0,p),n.enableVertexAttribArray(a),n.vertexAttribPointer(a,2,n.FLOAT,!1,0,0)},drawTrianglesTransparently(f){n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.drawArrays(n.TRIANGLES,0,f/2),n.disable(n.BLEND)},drawTriangles(f){n.drawArrays(n.TRIANGLES,0,f/2)},setFillColor(f){n.uniform4fv(l,f)},setCanvasPageBounds(f){n.uniform4fv(c,f)}}}function oh(e,n){const t=e.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(n)}}function jI(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 Ine=Object.defineProperty,Ene=Object.getOwnPropertyDescriptor,si=(e,n,t,r)=>{for(var o=Ene(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&Ine(n,t,o),o};class cs{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",on("canvasBoundingClientRect",new J));g(this,"originPagePoint",new b);g(this,"originPageCenter",new b);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 b(s,i,1)});g(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:c}=this.getMinimapPagePoint(n,t);if(o){const l=this.editor.getCurrentPageBounds()??new J,u=l.minX-i.width/2,d=l.maxX+i.width/2,f=l.minY-i.height/2,p=l.maxY+i.height/2,y=Math.max(0,u+i.width-a),m=Math.max(0,-(d-i.width-a)),w=Math.max(0,f+i.height-c),S=Math.max(0,-(p-i.height-c));a+=(y-m)/2,c+=(w-S)/2,a=$t(a,u,d),c=$t(c,f,p)}if(r){const{originPagePoint:l}=this,u=Math.abs(a-l.x),d=Math.abs(c-l.y);u>d?c=l.y:a=l.x}return new b(a,c)});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 c=0,l=a.length;c<l;c++){const u=a[c],d=this.shapeGeometryCache.get(u);if(!d)continue;const f=d.length;r.has(u)?(jI(this.gl.selectedShapes,s,d),s+=f):(jI(this.gl.unselectedShapes,i,d),i+=f)}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=Cne(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 Sa(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),Wi("minimap render",this.render))}_getColors(){const n=getComputedStyle(this.editor.getContainer());return{shapeFill:cl(n.getPropertyValue("--color-text-3").trim()),selectFill:cl(n.getPropertyValue("--color-selected").trim()),viewportFill:cl(n.getPropertyValue("--color-muted-1").trim()),background:cl(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?J.Expand(t,n):n}getContentScreenBounds(){const n=this.getContentPageBounds(),t=this.editor.pageToScreen(n.point),r=this.editor.pageToScreen(new b(n.maxX,n.maxY));return new J(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 J(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 b(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 J(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=Pne(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:c}of n)ya(s,{center:b.From(c),radius:3*a,offset:i,numArcSegments:t}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,o),i=0;for(const{color:c}of n)this.gl.setFillColor(cl(c)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}si([G],cs.prototype,"getDpr");si([G],cs.prototype,"getContentPageBounds");si([G],cs.prototype,"getContentScreenBounds");si([G],cs.prototype,"getCanvasSize");si([G],cs.prototype,"getCanvasClientPosition");si([G],cs.prototype,"getCanvasPageBounds");si([G],cs.prototype,"getZoom");si([G],cs.prototype,"getCanvasPageBoundsArray");function _ne(){const e=B(),n=dn(),t=x.useRef(null),r=x.useRef(!1),o=x.useRef();x.useEffect(()=>{try{const u=new cs(e,t.current,n);return o.current=u,o.current.close}catch(u){e.annotateError(u,{origin:"minimap",willCrashApp:!1}),setTimeout(()=>{throw u})}},[e,n]);const s=x.useCallback(u=>{if(!e.getCurrentPageShapeIds().size||!o.current)return;const d=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.originPagePoint.setTo(f),o.current.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(d,{animation:{duration:no}})},[e]),i=x.useCallback(u=>{if(!o.current)return;const d=u.currentTarget;if(Tu(d,u),!e.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const f=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=e.getViewportPageBounds(),y=o.current.getContentPageBounds();if(new J(y.x-p.width/2,y.y-p.height/2,y.width+p.width,y.height+p.height).containsPoint(f)&&!p.containsPoint(f)){o.current.isInViewport=p.containsPoint(f);const S=b.Sub(p.center,p.point),v=b.Add(f,S);o.current.originPagePoint.setTo(v),o.current.originPageCenter.setTo(f),e.centerOnPoint(f,{animation:{duration:no}})}else{const S=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=p.containsPoint(S),o.current.originPagePoint.setTo(S),o.current.originPageCenter.setTo(p.center)}function w(S){d&&$u(d,S),r.current=!1,document.body.removeEventListener("pointerup",w)}document.body.addEventListener("pointerup",w)},[e]),a=x.useCallback(u=>{if(!o.current)return;const d=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(b.Sub(d,m));return}e.centerOnPoint(d)}const f=o.current.getMinimapPagePoint(u.clientX,u.clientY),p=e.pageToScreen(f),y={type:"pointer",target:"canvas",name:"pointer_move",...Tn(u),point:p,isPen:e.getInstanceState().isPenMode};e.dispatch(y)},[e]),c=x.useCallback(u=>{const d=M_(u);e.dispatch({type:"wheel",name:"wheel",delta:d,point:new b(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey})},[e]),l=Nu();return x.useEffect(()=>{setTimeout(()=>{var u,d;(u=o.current)==null||u.updateColors(),(d=o.current)==null||d.render()})},[l]),h.jsx("div",{className:"tlui-minimap",children:h.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:s,onPointerMove:a,onPointerDown:i,onWheel:c})})}function kne(e,n){const[t,r]=Se.useState(n);Se.useLayoutEffect(()=>{const s=a0(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=Se.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return c0(e,JSON.stringify(a)),a})},[e]);return[t,o]}const Tne=x.memo(function(){const n=ce(),t=Me(),r=zn(),[o,s]=kne("minimap",!0),i=x.useCallback(()=>{s(l=>!l)},[s]),{ZoomMenu:a,Minimap:c}=ii();return r<wt.MOBILE?null:h.jsxs("div",{className:"tlui-navigation-panel",children:[h.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<wt.TABLET?h.jsx(a,{}):o?h.jsxs(h.Fragment,{children:[a&&h.jsx(a,{}),c&&h.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):h.jsxs(h.Fragment,{children:[h.jsx(he,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(gu(n["zoom-out"].label))} ${Wv(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:h.jsx(Pe,{icon:"minus"})}),a&&h.jsx(a,{}),h.jsx(he,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(gu(n["zoom-in"].label))} ${Wv(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:h.jsx(Pe,{icon:"plus"})}),c&&h.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=wt.TABLET&&!o&&h.jsx(c,{})]})}),$ne=function({name:n,id:t,isCurrentPage:r}){const o=B(),s=x.useRef(null),i=x.useCallback(()=>{o.mark("rename page")},[o]),a=x.useCallback(c=>{o.renamePage(t,c||"New Page")},[o,t]);return h.jsx(pw,{className:"tlui-page-menu__item__input",ref:c=>s.current=c,defaultValue:n,onValueChange:a,onFocus:i,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},Vv=(e,n,t,r)=>{let o;const s=e.getPages(),i=t>r?s[r-1]:s[r],a=t>r?s[r]:s[r+1];i&&!a?o=Lo(i.index):!i&&a?o=bR(s[0].index):o=zl(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},OI=ir(function({index:n,listSize:t,item:r,onRename:o}){const s=B(),i=Me(),a=s.getPages(),c=x.useCallback(()=>{s.mark("creating page");const f=Go.createId();s.duplicatePage(r.id,f)},[s,r]),l=x.useCallback(()=>{Vv(s,r.id,n,n-1)},[s,r,n]),u=x.useCallback(()=>{Vv(s,r.id,n,n+1)},[s,r,n]),d=x.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return h.jsxs(Ui,{id:`page item submenu ${n}`,children:[h.jsx(Hi,{children:h.jsx(he,{type:"icon",title:i("page-menu.submenu.title"),children:h.jsx(Pe,{icon:"dots-vertical"})})}),h.jsx(Ki,{alignOffset:0,side:"right",sideOffset:-4,children:h.jsxs(Er,{type:"menu",sourceId:"page-menu",children:[h.jsxs(me,{id:"modify",children:[o&&h.jsx(z,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),h.jsx(z,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=Tf}),n>0&&h.jsx(z,{id:"move-up",onSelect:l,label:"page-menu.submenu.move-up"}),n<t-1&&h.jsx(z,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),t>1&&h.jsx(me,{id:"delete",children:h.jsx(z,{id:"delete",onSelect:d,label:"page-menu.submenu.delete"})})]})})]})}),Mne=x.memo(function(){const n=B(),t=Me(),r=zn(),o=x.useCallback(()=>w(!1),[]),[s,i]=ri("page-menu",o),a=36,c=x.useRef(null),l=W("pages",()=>n.getPages(),[n]),u=W("currentPage",()=>n.getCurrentPage(),[n]),d=W("currentPageId",()=>n.getCurrentPageId(),[n]),f=ss(),p=W("maxPageCountReached",()=>n.getPages().length>=Tf,[n]),y=W("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[m,w]=x.useState(!1),S=x.useCallback(()=>{f||w(T=>!T)},[f]),v=x.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,E]=x.useState(Object.fromEntries(l.map((T,O)=>[T.id,{y:O*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{E(Object.fromEntries(l.map((T,O)=>[T.id,{y:O*a,offsetY:0,isSelected:!1}])))},[a,l]),x.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const O=c.current;if(!O)return;const N=T.offsetTop,A=O.scrollTop;N<A&&O.scrollTo({top:N});const j=N+a,L=O.scrollTop+O.offsetHeight;j>L&&O.scrollTo({top:j-O.offsetHeight})}})},[a,d,s]);const C=x.useCallback(T=>{const{clientY:O,currentTarget:N}=T,{dataset:{id:A,index:j}}=N;if(!A||!j)return;const L=v.current;Tu(T.currentTarget,T),L.status="pointing",L.pointing={id:A,index:+j};const V=P[A].y;L.startY=O,L.startIndex=Math.max(0,Math.min(Math.round(V/a),l.length-1))},[a,l.length,P]),I=x.useCallback(T=>{const O=v.current;if(O.status==="pointing"){const{clientY:N}=T,A=N-O.startY;Math.abs(A)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:N}=T,A=N-O.startY,j=P[O.pointing.id],{startIndex:L,pointing:X}=O,V=j.y+A,H=Math.max(0,Math.min(Math.round(V/a),l.length-1)),U={...P};if(U[X.id]={y:j.y,offsetY:A,isSelected:!0},H!==O.dragIndex){O.dragIndex=H;for(let K=0;K<l.length;K++){const Z=l[K];if(Z.id===O.pointing.id)continue;let{y:le}=U[Z.id];H===L?le=K*a:H<L?H<=K&&K<L?le=(K+1)*a:le=K*a:H>L&&(H>=K&&K>L?le=(K-1)*a:le=K*a),le!==U[Z.id].y&&(U[Z.id]={y:le,offsetY:0,isSelected:!0})}}E(U)}},[a,l,P]),_=x.useCallback(T=>{const O=v.current;if(O.status==="dragging"){const{id:N,index:A}=O.pointing;Vv(n,N,A,O.dragIndex)}$u(T.currentTarget,T),O.status="idle"},[n]),k=x.useCallback(T=>{const O=v.current;T.key==="Escape"&&(O.status==="dragging"&&E(Object.fromEntries(l.map((N,A)=>[N.id,{y:A*a,offsetY:0,isSelected:!1}]))),O.status="idle")},[a,l]),$=x.useCallback(()=>{f||n.batch(()=>{n.mark("creating page");const T=Go.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),w(!0)})},[n,t,f]);return h.jsxs(Iw,{id:"pages",onOpenChange:i,open:s,children:[h.jsx(Ew,{"data-testid":"main.page-menu",children:h.jsxs(he,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[h.jsx("div",{className:"tlui-page-menu__name",children:u.name}),h.jsx(Pe,{icon:"chevron-down",small:!0})]})}),h.jsx(_w,{side:"bottom",align:"start",sideOffset:6,children:h.jsxs("div",{className:"tlui-page-menu__wrapper",children:[h.jsxs("div",{className:"tlui-page-menu__header",children:[h.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!f&&h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsx(he,{type:"icon","data-testid":"page-menu.edit",title:t(m?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:h.jsx(Pe,{icon:m?"check":"edit"})}),h.jsx(he,{type:"icon","data-testid":"page-menu.create",title:t(p?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:p,onClick:$,children:h.jsx(Pe,{icon:"plus"})})]})]}),h.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*l.length+4},ref:c,children:l.map((T,O)=>{const N=P[T.id]??{position:O*40,offsetY:0};return m?h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===u.id?888:O,transform:`translate(0px, ${N.y+N.offsetY}px)`},children:[h.jsx(he,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:C,onPointerUp:_,onPointerMove:I,onKeyDown:k,"data-id":T.id,"data-index":O,children:h.jsx(Pe,{icon:"drag-handle-dots"})}),r<wt.TABLET_SM&&y?h.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const A=window.prompt("Rename page",T.name);A&&A!==T.name&&n.renamePage(T.id,A)},onDoubleClick:S,children:[h.jsx(Gv,{checked:T.id===u.id}),h.jsx(It,{children:T.name})]}):h.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:h.jsx($ne,{id:T.id,name:T.name,isCurrentPage:T.id===u.id})}),!f&&h.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":m,children:h.jsx(OI,{index:O,item:T,listSize:l.length})})]},T.id+"_editing"):h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[h.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(T.id),onDoubleClick:S,title:t("page-menu.go-to-page"),children:[h.jsx(Gv,{checked:T.id===u.id}),h.jsx(It,{children:T.name})]}),!f&&h.jsx("div",{className:"tlui-page_menu__item__submenu",children:h.jsx(OI,{index:O,item:T,listSize:l.length,onRename:()=>{if(n.environment.isIos){const A=window.prompt("Rename page",T.name);A&&A!==T.name&&n.renamePage(T.id,A)}else n.batch(()=>{w(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function Ane(){const e=ce(),n=B(),t=I$(),r=C$(),o=wn(1),s=ss(),i=W("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(s&&!i))return h.jsxs(h.Fragment,{children:[h.jsx(z,{...e.undo,disabled:!t}),h.jsx(z,{...e.redo,disabled:!r}),h.jsx(z,{...e.delete,disabled:!o}),h.jsx(z,{...e.duplicate,disabled:!o})]})}const jne=x.memo(function({children:n}){const t=n??h.jsx(Ane,{});return h.jsx(Er,{type:"small-icons",sourceId:"quick-actions",children:t})}),One=Object.freeze([or,Ti,rc,go]);function Wj(e=One){const n=B();return W("getRelevantStyles",()=>{var s;const t=new tv(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 br={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"}]};function Dne(e){const{uiType:n,items:t,title:r,style:o,value:s,onValueChange:i,theme:a}=e,c=B(),l=Me(),u=x.useRef(!1),d=x.useRef(null),{handleButtonClick:f,handleButtonPointerDown:p,handleButtonPointerEnter:y,handleButtonPointerUp:m}=x.useMemo(()=>{const w=()=>{u.current=!1,window.removeEventListener("pointerup",w);const C=d.current;C&&["TEXTAREA","INPUT"].includes(C.nodeName)&&C.focus(),d.current=null};return{handleButtonClick:C=>{const{id:I}=C.currentTarget.dataset;s.type==="shared"&&s.value===I||(c.mark("point picker item"),i(o,I))},handleButtonPointerDown:C=>{const{id:I}=C.currentTarget.dataset;c.mark("point picker item"),i(o,I),u.current=!0,d.current=document.activeElement,window.addEventListener("pointerup",w)},handleButtonPointerEnter:C=>{if(!u.current)return;const{id:I}=C.currentTarget.dataset;i(o,I)},handleButtonPointerUp:C=>{const{id:I}=C.currentTarget.dataset;s.type==="shared"&&s.value===I||i(o,I)}}},[s,c,i,o]);return h.jsx("div",{"data-testid":`style.${n}`,className:ue("tlui-buttons__grid"),children:t.map(w=>h.jsx(he,{type:"icon","data-id":w.value,"data-testid":`style.${n}.${w.value}`,"aria-label":w.value,"data-state":s.type==="shared"&&s.value===w.value?"hinted":void 0,title:r+" — "+l(`${n}-style.${w.value}`),className:ue("tlui-button-grid__button"),style:o===or?{color:a[w.value].solid}:void 0,onPointerEnter:y,onPointerDown:p,onPointerUp:m,onClick:f,children:h.jsx(Pe,{icon:w.icon})},w.value))})}const bi=x.memo(Dne);function Gj(e,[n,t]){return Math.min(t,Math.max(n,e))}function Rne(e){const n=x.useRef({value:e,previous:e});return x.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}const Vj=["PageUp","PageDown"],Yj=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Xj={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Vu="Slider",[Yv,Lne,Fne]=fg(Vu),[qj,dse]=Co(Vu,[Fne]),[Nne,_g]=qj(Vu),zne=x.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:l=[r],value:u,onValueChange:d=()=>{},onValueCommit:f=()=>{},inverted:p=!1,...y}=e,[m,w]=x.useState(null),S=Xe(n,j=>w(j)),v=x.useRef(new Set),P=x.useRef(0),E=i==="horizontal",C=m?!!m.closest("form"):!0,I=E?Bne:Une,[_=[],k]=ni({prop:u,defaultProp:l,onChange:j=>{var L;(L=[...v.current][P.current])===null||L===void 0||L.focus(),d(j)}}),$=x.useRef(_);function T(j){const L=Zne(_,j);A(j,L)}function O(j){A(j,P.current)}function N(){const j=$.current[P.current];_[P.current]!==j&&f(_)}function A(j,L,{commit:X}={commit:!1}){const V=tre(s),H=nre(Math.round((j-r)/s)*s+r,V),U=Gj(H,[r,o]);k((K=[])=>{const Z=Xne(K,U,L);if(ere(Z,c*s)){P.current=Z.indexOf(U);const le=String(Z)!==String(K);return le&&X&&f(Z),le?Z:K}else return K})}return x.createElement(Nne,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:P,thumbs:v.current,values:_,orientation:i},x.createElement(Yv.Provider,{scope:e.__scopeSlider},x.createElement(Yv.Slot,{scope:e.__scopeSlider},x.createElement(I,Q({"aria-disabled":a,"data-disabled":a?"":void 0},y,{ref:S,onPointerDown:ie(y.onPointerDown,()=>{a||($.current=_)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:T,onSlideMove:a?void 0:O,onSlideEnd:a?void 0:N,onHomeKeyDown:()=>!a&&A(r,0,{commit:!0}),onEndKeyDown:()=>!a&&A(o,_.length-1,{commit:!0}),onStepKeyDown:({event:j,direction:L})=>{if(!a){const H=Vj.includes(j.key)||j.shiftKey&&Yj.includes(j.key)?10:1,U=P.current,K=_[U],Z=s*H*L;A(K+Z,U,{commit:!0})}}})))),C&&_.map((j,L)=>x.createElement(Yne,{key:L,name:t?t+(_.length>1?"[]":""):void 0,value:j})))}),[Zj,Qj]=qj(Vu,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Bne=x.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:c,onStepKeyDown:l,...u}=e,[d,f]=x.useState(null),p=Xe(n,P=>f(P)),y=x.useRef(),m=kw(o),w=m==="ltr",S=w&&!s||!w&&s;function v(P){const E=y.current||d.getBoundingClientRect(),C=[0,E.width],_=Rw(C,S?[t,r]:[r,t]);return y.current=E,_(P-E.left)}return x.createElement(Zj,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width"},x.createElement(Jj,Q({dir:m,"data-orientation":"horizontal"},u,{ref:p,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:P=>{const E=v(P.clientX);i==null||i(E)},onSlideMove:P=>{const E=v(P.clientX);a==null||a(E)},onSlideEnd:()=>{y.current=void 0,c==null||c()},onStepKeyDown:P=>{const C=Xj[S?"from-left":"from-right"].includes(P.key);l==null||l({event:P,direction:C?-1:1})}})))}),Une=x.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:c,...l}=e,u=x.useRef(null),d=Xe(n,u),f=x.useRef(),p=!o;function y(m){const w=f.current||u.current.getBoundingClientRect(),S=[0,w.height],P=Rw(S,p?[r,t]:[t,r]);return f.current=w,P(m-w.top)}return x.createElement(Zj,{scope:e.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1},x.createElement(Jj,Q({"data-orientation":"vertical"},l,{ref:d,style:{...l.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const w=y(m.clientY);s==null||s(w)},onSlideMove:m=>{const w=y(m.clientY);i==null||i(w)},onSlideEnd:()=>{f.current=void 0,a==null||a()},onStepKeyDown:m=>{const S=Xj[p?"from-bottom":"from-top"].includes(m.key);c==null||c({event:m,direction:S?-1:1})}})))}),Jj=x.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:c,...l}=e,u=_g(Vu,t);return x.createElement(He.span,Q({},l,{ref:n,onKeyDown:ie(e.onKeyDown,d=>{d.key==="Home"?(i(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):Vj.concat(Yj).includes(d.key)&&(c(d),d.preventDefault())}),onPointerDown:ie(e.onPointerDown,d=>{const f=d.target;f.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(f)?f.focus():r(d)}),onPointerMove:ie(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:ie(e.onPointerUp,d=>{const f=d.target;f.hasPointerCapture(d.pointerId)&&(f.releasePointerCapture(d.pointerId),s(d))})}))}),Hne="SliderTrack",Kne=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=_g(Hne,t);return x.createElement(He.span,Q({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),DI="SliderRange",Wne=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=_g(DI,t),s=Qj(DI,t),i=x.useRef(null),a=Xe(n,i),c=o.values.length,l=o.values.map(f=>eO(f,o.min,o.max)),u=c>1?Math.min(...l):0,d=100-Math.max(...l);return x.createElement(He.span,Q({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:d+"%"}}))}),RI="SliderThumb",Gne=x.forwardRef((e,n)=>{const t=Lne(e.__scopeSlider),[r,o]=x.useState(null),s=Xe(n,a=>o(a)),i=x.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return x.createElement(Vne,Q({},e,{ref:s,index:i}))}),Vne=x.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,s=_g(RI,t),i=Qj(RI,t),[a,c]=x.useState(null),l=Xe(n,w=>c(w)),u=RA(a),d=s.values[r],f=d===void 0?0:eO(d,s.min,s.max),p=qne(r,s.values.length),y=u==null?void 0:u[i.size],m=y?Qne(y,f,i.direction):0;return x.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${f}% + ${m}px)`}},x.createElement(Yv.ItemSlot,{scope:e.__scopeSlider},x.createElement(He.span,Q({role:"slider","aria-label":e["aria-label"]||p,"aria-valuemin":s.min,"aria-valuenow":d,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:l,style:d===void 0?{display:"none"}:e.style,onFocus:ie(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),Yne=e=>{const{value:n,...t}=e,r=x.useRef(null),o=Rne(n);return x.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&c){const l=new Event("input",{bubbles:!0});c.call(s,n),s.dispatchEvent(l)}},[o,n]),x.createElement("input",Q({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function Xne(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function eO(e,n,t){const s=100/(t-n)*(e-n);return Gj(s,[0,100])}function qne(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function Zne(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 Qne(e,n,t){const r=e/2,s=Rw([0,50],[0,r]);return(r-s(n)*t)*t}function Jne(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function ere(e,n){if(n>0){const t=Jne(e);return Math.min(...t)>=n}return!0}function Rw(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 tre(e){return(String(e).split(".")[1]||"").length}function nre(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const rre=zne,ore=Kne,sre=Wne,ire=Gne,are=x.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=B(),c=Me(),l=x.useCallback(f=>{i(f[0])},[i]),u=x.useCallback(()=>{a.mark("click slider")},[a]),d=x.useCallback(()=>{o&&i(o)},[o,i]);return h.jsx("div",{className:"tlui-slider__container",children:h.jsxs(rre,{"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:l,onPointerUp:d,title:t+" — "+c(s),children:[h.jsx(ore,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&h.jsx(sre,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&h.jsx(ire,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function cre({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:c,valueA:l,valueB:u,onValueChange:d}){const f=Me(),p=x.useMemo(()=>{var m;return((m=s.find(w=>l.type==="shared"&&l.value===w.value))==null?void 0:m.icon)??"mixed"},[s,l]),y=x.useMemo(()=>{var m;return((m=i.find(w=>u.type==="shared"&&u.value===w.value))==null?void 0:m.icon)??"mixed"},[i,u]);return l===void 0&&u===void 0?null:h.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[h.jsx("div",{title:f(e),className:"tlui-style-panel__double-select-picker-label",children:f(e)}),h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsxs(Ui,{id:`style panel ${n} A`,children:[h.jsx(Hi,{children:h.jsx(he,{type:"icon","data-testid":`style.${n}`,title:f(r)+" — "+(l===null||l.type==="mixed"?f("style-panel.mixed"):f(`${n}-style.${l.value}`)),children:h.jsx(Pe,{icon:p,small:!0,invertIcon:!0})})}),h.jsx(Ki,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:s.map((m,w)=>h.jsx(wu,{"data-testid":`style.${n}.${m.value}`,children:h.jsx(he,{type:"icon",onClick:()=>d(a,m.value),title:`${f(r)} — ${f(`${n}-style.${m.value}`)}`,children:h.jsx(Pe,{icon:m.icon,invertIcon:!0})},m.value)},w))})})]}),h.jsxs(Ui,{id:`style panel ${t}`,children:[h.jsx(Hi,{children:h.jsx(he,{type:"icon","data-testid":`style.${t}`,title:f(o)+" — "+(u===null||u.type==="mixed"?f("style-panel.mixed"):f(`${t}-style.${u.value}`)),children:h.jsx(Pe,{icon:y,small:!0})})}),h.jsx(Ki,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>h.jsx(wu,{children:h.jsx(he,{type:"icon",title:`${f(o)} — ${f(`${t}-style.${m.value}`)}`,"data-testid":`style.${t}.${m.value}`,onClick:()=>d(c,m.value),children:h.jsx(Pe,{icon:m.icon})})},m.value))})})]})]})]})}const lre=x.memo(cre);function ure({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const c=Me(),l=B(),u=x.useMemo(()=>{var p;return(p=o.find(y=>i.type==="shared"&&y.value===i.value))==null?void 0:p.icon},[o,i]),d=i.type==="mixed"?c("style-panel.mixed"):c(`${t}-style.${i.value}`),f=n?c(n):"";return h.jsxs(Ui,{id:`style panel ${e}`,children:[h.jsx(Hi,{children:h.jsxs(he,{type:s,"data-testid":`style.${t}`,title:d,children:[h.jsx(It,{children:f}),h.jsx(Pe,{icon:u??"mixed"})]})}),h.jsx(Ki,{side:"left",align:"center",alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:o.map(p=>h.jsx(wu,{children:h.jsx(he,{type:"icon","data-testid":`style.${t}.${p.value}`,title:c(`${t}-style.${p.value}`),onClick:()=>{l.mark("select style dropdown item"),a(r,p.value)},children:h.jsx(Pe,{icon:p.icon})})},p.value))})})]})}const Lw=x.memo(ure);function dre({styles:e}){const n=Nu();if(!e)return null;const t=e.get(co),r=e.get(Pf),o=e.get(bf),s=e.get(_f),i=e.get(po),a=t===void 0,c=r===void 0&&o===void 0,l=s===void 0,u=i===void 0,d=ts({isDarkMode:n});return h.jsxs(h.Fragment,{children:[h.jsx(hre,{theme:d,styles:e}),!u&&h.jsx(fre,{theme:d,styles:e}),!(a&&c&&l)&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[h.jsx(pre,{styles:e}),h.jsx(mre,{styles:e}),h.jsx(gre,{styles:e})]})]})}function Yu(){const e=B(),n=Eo();return Se.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 hre({styles:e,theme:n}){const t=Me(),r=B(),o=Yu(),s=e.get(or),i=e.get(rc),a=e.get(Ti),c=e.get(go),l=i!==void 0||a!==void 0||c!==void 0;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:h.jsx(bi,{title:t("style-panel.color"),uiType:"color",style:or,items:br.color,value:s,onValueChange:o,theme:n}),h.jsx(yre,{})]}),l&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:h.jsx(bi,{title:t("style-panel.fill"),uiType:"fill",style:rc,items:br.fill,value:i,onValueChange:o,theme:n}),a===void 0?null:h.jsx(bi,{title:t("style-panel.dash"),uiType:"dash",style:Ti,items:br.dash,value:a,onValueChange:o,theme:n}),c===void 0?null:h.jsx(bi,{title:t("style-panel.size"),uiType:"size",style:go,items:br.size,value:c,onValueChange:(u,d)=>{o(u,d);const f=r.getSelectedShapeIds();f.length>0&&We(r,f)},theme:n})]})]})}function fre({theme:e,styles:n}){const t=Me(),r=Yu(),o=n.get(po),s=n.get(nS),i=n.get(If),a=n.get(Ef);return o===void 0&&i===void 0?null:h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:h.jsx(bi,{title:t("style-panel.font"),uiType:"font",style:po,items:br.font,value:o,onValueChange:r,theme:e}),s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(bi,{title:t("style-panel.align"),uiType:"align",style:nS,items:br.textAlign,value:s,onValueChange:r,theme:e}),h.jsx("div",{className:"tlui-style-panel__row__extra-button",children:h.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:h.jsx(Pe,{icon:"vertical-align-middle"})})})]}),i===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(bi,{title:t("style-panel.align"),uiType:"align",style:If,items:br.horizontalAlign,value:i,onValueChange:r,theme:e}),h.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?h.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:h.jsx(Pe,{icon:"vertical-align-middle"})}):h.jsx(Lw,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:Ef,items:br.verticalAlign,value:a,onValueChange:r})})]})]})}function pre({styles:e}){const n=Yu(),t=e.get(co);return t===void 0?null:h.jsx(Lw,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:co,items:br.geo,value:t,onValueChange:n})}function gre({styles:e}){const n=Yu(),t=e.get(_f);return t===void 0?null:h.jsx(Lw,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:_f,items:br.spline,value:t,onValueChange:n})}function mre({styles:e}){const n=Yu(),t=e.get(Pf),r=e.get(bf);return!t||!r?null:h.jsx(lre,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:bf,itemsA:br.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Pf,itemsB:br.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const ll=[.1,.25,.5,.75,1];function yre(){const e=B(),n=W("opacity",()=>e.getSharedOpacity(),[e]),t=Eo(),r=Me(),o=Se.useCallback(i=>{const a=ll[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:ll.indexOf(sR(ll,i=>Math.abs(i-n.value)));return h.jsx(are,{"data-testid":"style.opacity",value:s>=0?s:ll.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:ll.length-1,title:r("style-panel.opacity")})}const Sre=x.memo(function({isMobile:n,children:t}){const r=B(),o=Wj(),s=x.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1})},[r,n]),i=t??h.jsx(dre,{styles:o});return h.jsx("div",{className:ue("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})});function vre(){const e=B(),n=Me(),t=Wj(),r=t==null?void 0:t.get(or),o=ts({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=W("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(l=>{l||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:c}=ii();return c?h.jsxs(Iw,{id:"mobile style menu",onOpenChange:a,children:[h.jsx(Ew,{children:h.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:h.jsx(Pe,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),h.jsx(_w,{side:"top",align:"end",children:c&&h.jsx(c,{isMobile:!0})})]}):null}function xre(){return h.jsxs(h.Fragment,{children:[h.jsx(bre,{}),h.jsx(Pre,{}),h.jsx(Cre,{}),h.jsx(Ire,{}),h.jsx(Ere,{}),h.jsx(_re,{}),h.jsx(kre,{}),h.jsx(Tre,{}),h.jsx($re,{}),h.jsx(Mre,{}),h.jsx(jre,{}),h.jsx(Are,{}),h.jsx(Rre,{}),h.jsx(Nre,{}),h.jsx(Ore,{}),h.jsx(Fre,{}),h.jsx(Lre,{}),h.jsx(Dre,{}),h.jsx(zre,{}),h.jsx(Bre,{}),h.jsx(Ure,{}),h.jsx(Hre,{}),h.jsx(Kre,{}),h.jsx(Wre,{}),h.jsx(Gre,{}),h.jsx(Vre,{}),h.jsx(Xre,{}),h.jsx(Yre,{})]})}function wre(e){var r;const n=B(),t=(r=e.meta)==null?void 0:r.geo;return W("is tool selected",()=>{const o=n.getCurrentToolId(),s=n.getSharedStyles().getAsKnownValue(co);return t?o==="geo"&&s===t:o===e.id},[n,e.id,t])}function Ke({tool:e}){const n=vg(),t=wre(n[e]);return h.jsx(z,{...n[e],isSelected:t})}function bre(){return h.jsx(Ke,{tool:"select"})}function Pre(){return h.jsx(Ke,{tool:"hand"})}function Cre(){return h.jsx(Ke,{tool:"draw"})}function Ire(){return h.jsx(Ke,{tool:"eraser"})}function Ere(){return h.jsx(Ke,{tool:"arrow"})}function _re(){return h.jsx(Ke,{tool:"text"})}function kre(){return h.jsx(Ke,{tool:"note"})}function Tre(){const e=vg();return h.jsx(z,{...e.asset})}function $re(){return h.jsx(Ke,{tool:"rectangle"})}function Mre(){return h.jsx(Ke,{tool:"ellipse"})}function Are(){return h.jsx(Ke,{tool:"diamond"})}function jre(){return h.jsx(Ke,{tool:"triangle"})}function Ore(){return h.jsx(Ke,{tool:"rhombus"})}function Dre(){return h.jsx(Ke,{tool:"heart"})}function Rre(){return h.jsx(Ke,{tool:"hexagon"})}function Lre(){return h.jsx(Ke,{tool:"cloud"})}function Fre(){return h.jsx(Ke,{tool:"star"})}function Nre(){return h.jsx(Ke,{tool:"oval"})}function zre(){return h.jsx(Ke,{tool:"x-box"})}function Bre(){return h.jsx(Ke,{tool:"check-box"})}function Ure(){return h.jsx(Ke,{tool:"arrow-left"})}function Hre(){return h.jsx(Ke,{tool:"arrow-up"})}function Kre(){return h.jsx(Ke,{tool:"arrow-down"})}function Wre(){return h.jsx(Ke,{tool:"arrow-right"})}function Gre(){return h.jsx(Ke,{tool:"line"})}function Vre(){return h.jsx(Ke,{tool:"highlight"})}function Yre(){return h.jsx(Ke,{tool:"frame"})}function Xre(){return h.jsx(Ke,{tool:"laser"})}const Py=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Cy(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function ul(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function tO(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 nO(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 qre(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,"-":Py?173:189,"=":Py?61:187,";":Py?59:186,"'":222,"[":219,"]":221,"\\":220},vo={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Xv={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},ut={};for(let e=1;e<20;e++)bu["f".concat(e)]=111+e;let Ge=[],Nl=null,rO="all";const Do=new Map,Xu=e=>bu[e.toLowerCase()]||vo[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Zre=e=>Object.keys(bu).find(n=>bu[n]===e),Qre=e=>Object.keys(vo).find(n=>vo[n]===e);function oO(e){rO=e||"all"}function Pu(){return rO||"all"}function Jre(){return Ge.slice(0)}function eoe(){return Ge.map(e=>Zre(e)||Qre(e)||String.fromCharCode(e))}function toe(){const e=[];return Object.keys(ut).forEach(n=>{ut[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=>Xu(a))})})}),e}function noe(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 roe(e){return typeof e=="string"&&(e=Xu(e)),Ge.indexOf(e)!==-1}function ooe(e,n){let t,r;e||(e=Pu());for(const o in ut)if(Object.prototype.hasOwnProperty.call(ut,o))for(t=ut[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return Fw(a)}):r++;Pu()===e&&oO(n||"all")}function soe(e){let n=e.keyCode||e.which||e.charCode;const t=Ge.indexOf(n);if(t>=0&&Ge.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&Ge.splice(0,Ge.length),(n===93||n===224)&&(n=91),n in Ft){Ft[n]=!1;for(const r in vo)vo[r]===n&&(Mn[r]=!1)}}function sO(e){if(typeof e>"u")Object.keys(ut).forEach(o=>{Array.isArray(ut[o])&&ut[o].forEach(s=>sh(s)),delete ut[o]}),Fw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&sh(o)});else if(typeof e=="object")e.key&&sh(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=""),sh({key:e,scope:o,method:s,splitKey:"+"})}}const sh=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;nO(n).forEach(i=>{const a=i.split(o),c=a.length,l=a[c-1],u=l==="*"?"*":Xu(l);if(!ut[u])return;t||(t=Pu());const d=c>1?tO(vo,a):[],f=[];ut[u]=ut[u].filter(p=>{const m=(r?p.method===r:!0)&&p.scope===t&&qre(p.mods,d);return m&&f.push(p.element),!m}),f.forEach(p=>Fw(p))})};function LI(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(Ge),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function FI(e,n){const t=ut["*"];let r=e.keyCode||e.which||e.charCode;if(!Mn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),Ge.indexOf(r)===-1&&r!==229&&Ge.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const c=Xv[a];e[a]&&Ge.indexOf(c)===-1?Ge.push(c):!e[a]&&Ge.indexOf(c)>-1?Ge.splice(Ge.indexOf(c),1):a==="metaKey"&&e[a]&&Ge.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(Ge=Ge.slice(Ge.indexOf(c))))}),r in Ft){Ft[r]=!0;for(const a in vo)vo[a]===r&&(Mn[a]=!0);if(!t)return}for(const a in Ft)Object.prototype.hasOwnProperty.call(Ft,a)&&(Ft[a]=e[Xv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Ge.indexOf(17)===-1&&Ge.push(17),Ge.indexOf(18)===-1&&Ge.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)&&LI(e,t[a],o,n);if(!(r in ut))return;const s=ut[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const c=s[a],{splitKey:l}=c,u=c.key.split(l),d=[];for(let f=0;f<u.length;f++)d.push(Xu(u[f]));d.sort().join("")===Ge.sort().join("")&&LI(e,c,o,n)}}function Mn(e,n,t){Ge=[];const r=nO(e);let o=[],s="all",i=document,a=0,c=!1,l=!0,u="+",d=!1,f=!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&&(c=n.keyup),n.keydown!==void 0&&(l=n.keydown),n.capture!==void 0&&(d=n.capture),typeof n.splitKey=="string"&&(u=n.splitKey),n.single===!0&&(f=!0)),typeof n=="string"&&(s=n),f&&sO(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=tO(vo,e)),e=e[e.length-1],e=e==="*"?"*":Xu(e),e in ut||(ut[e]=[]),ut[e].push({keyup:c,keydown:l,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!Do.has(i)){const p=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return FI(m,i)},y=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;FI(m,i),soe(m)};Do.set(i,{keydownListener:p,keyupListenr:y,capture:d}),Cy(i,"keydown",p,d),Cy(i,"keyup",y,d)}if(!Nl){const p=()=>{Ge=[]};Nl={listener:p,capture:d},Cy(window,"focus",p,d)}}}function ioe(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ut).forEach(t=>{ut[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function Fw(e){const n=Object.values(ut).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=Do.get(e)||{};r&&o&&(ul(e,"keyup",o,s),ul(e,"keydown",r,s),Do.delete(e))}if((n.length<=0||Do.size<=0)&&(Object.keys(Do).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=Do.get(o)||{};s&&i&&(ul(o,"keyup",i,a),ul(o,"keydown",s,a),Do.delete(o))}),Do.clear(),Object.keys(ut).forEach(o=>delete ut[o]),Nl)){const{listener:o,capture:s}=Nl;ul(window,"focus",o,s),Nl=null}}const Iy={getPressedKeyString:eoe,setScope:oO,getScope:Pu,deleteScope:ooe,getPressedKeyCodes:Jre,getAllKeyCodes:toe,isPressed:roe,filter:noe,trigger:ioe,unbind:sO,keyMap:bu,modifier:vo,modifierMap:Xv};for(const e in Iy)Object.prototype.hasOwnProperty.call(Iy,e)&&(Mn[e]=Iy[e]);if(typeof window<"u"){const e=window.hotkeys;Mn.noConflict=n=>(n&&window.hotkeys===Mn&&(window.hotkeys=e),Mn),window.hotkeys=Mn}const NI=["copy","cut","paste","asset"];function aoe(){const e=B(),n=ss(),t=ce(),r=vg(),o=W("is focused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!o)return;Mn.setScope(e.store.id);const s=(a,c)=>{Mn(a,{element:document.body,scope:e.store.id},c)},i=(a,c)=>{Mn(a,{element:document.body,keyup:!0,keydown:!1,scope:e.store.id},c)};for(const a of Object.values(t))a.kbd&&(n&&!a.readonlyOk||NI.includes(a.id)||s(zI(a.kbd),c=>{bl(e)||(_e(c),a.onSelect("kbd"))}));for(const a of Object.values(r))!a.kbd||!a.readonlyOk&&e.getInstanceState().isReadonly||NI.includes(a.id)||s(zI(a.kbd),c=>{bl(e)||(_e(c),a.onSelect("kbd"))});return s(",",a=>{if(bl(e)||e.inputs.keys.has("Comma"))return;_e(a),e.focus(),e.inputs.keys.add("Comma");const{x:c,y:l,z:u}=e.inputs.currentScreenPoint,d={type:"pointer",name:"pointer_down",point:{x:c,y:l,z:u},shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(d)}),i(",",a=>{if(bl(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:c,y:l,z:u}=e.inputs.currentScreenPoint,d={type:"pointer",name:"pointer_up",point:{x:c,y:l,z:u},shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(d)}),()=>{Mn.deleteScope(e.store.id)}},[t,r,n,e,o])}function zI(e){return coe(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 coe(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 bl(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const loe=x.createContext(!1);function uoe({children:e}){const n=B(),t=s7(),r=zn(),o=Me(),s=Math.min(8,5+r),[i,a]=x.useState(0),c=x.useRef(null),[l,u]=x.useState(null),d=x.useMemo(()=>{const p=l?`:not([data-value="${l}"])`:"";return`
319
- #${t}_main > *:nth-child(n + ${s+(l?1:2)})${p} {
320
- display: none;
321
- }
322
- #${t}_more > *:nth-child(-n + ${s}) {
323
- display: none;
324
- }
325
- `},[l,t,s]),f=Ix(()=>{if(!c.current)return;const p=Array.from(c.current.children);a(p.length),p.findIndex(w=>w.getAttribute("data-value")===l)<=s&&u(null);const m=Array.from(c.current.children).findIndex(w=>w.getAttribute("aria-checked")==="true");m!==-1&&m>=s&&u(p[m].getAttribute("data-value"))});return x.useLayoutEffect(()=>{f()}),x.useLayoutEffect(()=>{if(!c.current)return;const p=new MutationObserver(f);return p.observe(c.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{p.disconnect()}},[f]),x.useEffect(()=>{const p=[["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 p)Mn(y,w=>{var P;if(bl(n))return;_e(w);const v=Array.from(((P=c.current)==null?void 0:P.children)??[]).filter(E=>!(E instanceof HTMLElement)||E.tagName.toLowerCase()!=="button"?!1:!!(E.offsetWidth||E.offsetHeight))[m];v&&v.click()});return()=>{Mn.unbind("1,2,3,4,5,6,7,8,9,0")}},[n]),h.jsxs(h.Fragment,{children:[h.jsx("style",{children:d}),h.jsxs("div",{className:ue("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<wt.TABLET_SM}),role:"radiogroup",children:[h.jsx("div",{id:`${t}_main`,ref:c,className:"tlui-toolbar__tools__list",children:h.jsx(Er,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s+1&&h.jsx(loe.Provider,{value:!0,children:h.jsxs(Ui,{id:"toolbar overflow",modal:!1,children:[h.jsx(Hi,{children:h.jsx(he,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:h.jsx(Pe,{icon:"chevron-up"})})}),h.jsx(Ki,{side:"top",align:"center",children:h.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:h.jsx(Er,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const doe=["select","hand","draw","eraser","text","zoom","laser","highlight"];function hoe({activeToolId:e}){const n=B(),t=zn(),r=Me(),o=W("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||doe.includes(e)?null:h.jsx(he,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ue("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<wt.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:h.jsx(Pe,{icon:o?"lock":"unlock",small:!0})})}const foe=x.memo(function({children:n}){const t=B(),r=zn(),o=ss(),s=W("current tool id",()=>t.getCurrentToolId(),[t]),{ActionsMenu:i,QuickActions:a}=ii();return h.jsx("div",{className:"tlui-toolbar",children:h.jsxs("div",{className:"tlui-toolbar__inner",children:[h.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&h.jsxs("div",{className:"tlui-toolbar__extras",children:[r<wt.TABLET&&h.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&h.jsx(a,{}),i&&h.jsx(i,{})]}),h.jsx(hoe,{activeToolId:s})]}),h.jsx(uoe,{children:n??h.jsx(xre,{})})]}),r<wt.TABLET_SM&&!o&&h.jsx("div",{className:"tlui-toolbar__tools",children:h.jsx(vre,{})})]})})});function poe(){const e=ce();return h.jsxs(h.Fragment,{children:[h.jsx(z,{...e["zoom-in"],noClose:!0}),h.jsx(z,{...e["zoom-out"],noClose:!0}),h.jsx(Oj,{}),h.jsx(Dj,{}),h.jsx(Rj,{})]})}const goe=x.memo(function({children:n}){const t=dn(),[r,o]=ri("zoom menu"),s=n??h.jsx(poe,{});return h.jsxs(Aw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(jw,{asChild:!0,dir:"ltr",children:h.jsx(moe,{})}),h.jsx(Eg,{container:t,children:h.jsx(Ow,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:h.jsx(Er,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),moe=x.forwardRef(function(n,t){const r=B(),o=zn(),s=W("zoom",()=>r.getZoomLevel(),[r]),i=Me(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:no}})},[r]);return h.jsx(he,{ref:t,...n,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<wt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<wt.MOBILE?"zoom-in":void 0,children:o<wt.MOBILE?null:h.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),iO=x.createContext(null);function yoe({overrides:e={},children:n}){const t=_0(e);return h.jsx(iO.Provider,{value:x.useMemo(()=>({ContextMenu:Wte,ActionsMenu:wte,HelpMenu:one,ZoomMenu:goe,MainMenu:wne,Minimap:_ne,StylePanel:Sre,PageMenu:Mne,NavigationPanel:Tne,Toolbar:foe,KeyboardShortcutsDialog:dne,QuickActions:jne,HelperButtons:lne,DebugPanel:Qte,DebugMenu:Zte,MenuPanel:bne,...t}),[t]),children:n})}function ii(){const e=x.useContext(iO);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function Soe({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return h.jsx(kY,{assetUrls:gZ(t),children:h.jsx(MY,{overrides:xZ(e),children:h.jsx(Tq,{onEvent:r,children:h.jsx(cZ,{children:h.jsx($q,{children:h.jsx(yZ,{forceMobile:o,children:h.jsx(yoe,{overrides:n,children:h.jsx(voe,{overrides:e,children:s})})})})})})})})}function voe({overrides:e,children:n}){const t=wZ(e);return h.jsx(sQ,{overrides:t.actions,children:h.jsx(mZ,{overrides:t.tools,children:n})})}function xoe(){const e=B(),{addToast:n}=Yr();x.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 woe=Se.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return h.jsx(Soe,{...s,components:o,children:h.jsx(boe,{hideUi:r,renderDebugMenuItems:n,children:t})})}),boe=Se.memo(function({children:n,hideUi:t,...r}){return h.jsxs(h.Fragment,{children:[n,t?null:h.jsx(Coe,{...r}),h.jsx(Poe,{})]})});function Poe(){const{InFrontOfTheCanvas:e}=ht();return e?h.jsx("div",{className:"tl-front",children:h.jsx(e,{})}):null}const Coe=Se.memo(function(){const n=B(),t=Me(),r=zn(),o=ss(),s=W("focus",()=>n.getInstanceState().isFocusMode,[n]),i=W("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:c,MenuPanel:l,StylePanel:u,Toolbar:d,HelpMenu:f,NavigationPanel:p,HelperButtons:y,DebugPanel:m}=ii();aoe(),YZ(),xoe();const{"toggle-focus-mode":w}=ce();return h.jsxs("div",{className:ue("tlui-layout",{"tlui-layout__mobile":r<wt.TABLET_SM}),"data-breakpoint":r,children:[s?h.jsx("div",{className:"tlui-layout__top",children:h.jsx(he,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>w.onSelect("menu"),children:h.jsx(Pe,{icon:"dot"})})}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"tlui-layout__top",children:[h.jsxs("div",{className:"tlui-layout__top__left",children:[l&&h.jsx(l,{}),y&&h.jsx(y,{})]}),h.jsx("div",{className:"tlui-layout__top__center",children:c&&h.jsx(c,{})}),h.jsxs("div",{className:"tlui-layout__top__right",children:[a&&h.jsx(a,{}),u&&r>=wt.TABLET_SM&&!o&&h.jsx(u,{})]})]}),h.jsxs("div",{className:"tlui-layout__bottom",children:[h.jsxs("div",{className:"tlui-layout__bottom__main",children:[p&&h.jsx(p,{}),d&&h.jsx(d,{}),f&&h.jsx(f,{})]}),i&&m&&h.jsx(m,{})]})]}),h.jsx(hZ,{}),h.jsx(jq,{}),h.jsx(fZ,{}),h.jsx(Oq,{})]})}),ih=(e,n)=>{const[t,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),LD(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function Ioe(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 aO(e){const n=x.useMemo(()=>Ioe(e),[e]),t=[ih("tldraw_draw",n.draw),ih("tldraw_serif",n.serif),ih("tldraw_sans",n.sansSerif),ih("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Eoe(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:c=[],bindingUtils:l=[],tools:u=[],...d}=e,f=_0(a),p=x.useMemo(()=>({Scribble:PC,CollaboratorScribble:PC,SelectionForeground:xG,SelectionBackground:SG,Handles:fG,...f}),[f]),y=Il(c),m=x.useMemo(()=>[...uM,...y],[y]),w=Il(l),S=x.useMemo(()=>[...T$,...w],[w]),v=Il(u),P=x.useMemo(()=>[...nX,...pV,...v],[v]),E=fA(d.assetUrls),{done:C,error:I}=aO(E);return I?h.jsx(P2,{children:"Could not load assets. Please refresh the page."}):C?h.jsx(Q8,{initialState:"select",...d,components:p,shapeUtils:m,bindingUtils:S,tools:P,children:h.jsxs(woe,{...d,components:p,children:[h.jsx(_oe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),n]})}):h.jsx(b2,{children:"Loading assets..."})}function _oe({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=s0,acceptedVideoMimeTypes:r=dE,onMount:o}){const s=B(),i=Yr(),a=Me(),c=Ix(d=>{const f=[];return f.push(...zY(d)),ZG(d,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),f.push(o==null?void 0:o(d)),()=>{f.forEach(p=>p==null?void 0:p())}});x.useLayoutEffect(()=>{if(s)return c==null?void 0:c(s)},[s,c]);const{Canvas:l}=ht(),{ContextMenu:u}=ii();return u?h.jsx(u,{}):l?h.jsx(l,{}):null}x.memo(function(n){const[t,r]=x.useState(null),[o,s]=x.useState(null),i=Il(n.shapeUtils??[]),a=x.useMemo(()=>[...uM,...i],[i]),c=Il(n.bindingUtils??[]),l=x.useMemo(()=>[...T$,...c],[c]),u=v2({snapshot:n.snapshot,shapeUtils:a}),d=fA(),{done:f,error:p}=aO(d),{pageId:y,bounds:m,scale:w,background:S,padding:v,darkMode:P,preserveAspectRatio:E,format:C="svg"}=n;return x.useLayoutEffect(()=>{if(!o||!u||!f)return;let I=!1;const _=document.createElement("div");o.appendChild(_),o.classList.add("tl-container","tl-theme__light");const k=new ee({store:u,shapeUtils:a,bindingUtils:l,tools:[],getContainer:()=>_});y&&k.setCurrentPage(y);const $=k.getCurrentPageShapeIds();async function T(){const O=await k.getSvgString([...$],{bounds:m,scale:w,background:S,padding:v,darkMode:P,preserveAspectRatio:E});if(O&&!I){if(C==="svg"){if(!I){const N=new Blob([O.svg],{type:"image/svg+xml"}),A=URL.createObjectURL(N);r(A)}}else if(C==="png"){const N=await PA(O.svg,k.environment.isSafari,{type:C,quality:1,scale:2,width:O.width,height:O.height});if(N&&!I){const A=URL.createObjectURL(N);r(A)}}}k.dispose()}return T(),()=>{I=!0}},[C,o,u,a,l,y,m,w,S,v,P,E,f,p]),p?h.jsx(P2,{children:"Could not load assets."}):f?h.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&h.jsx("img",{src:t,style:{width:"100%",height:"100%"}})}):h.jsx(b2,{children:"Loading assets..."})});const koe=1,Toe=ve({schemaVersion:cn(1),storeVersion:dh,recordVersions:xf(pe,ve({version:dh,subTypeVersions:xf(pe,dh).optional(),subTypeKey:pe.optional()}))}),$oe=ve({schemaVersion:cn(2),sequences:xf(pe,dh)}),Moe=ve({tldrawFileFormatVersion:YR,schema:XR("schemaVersion",{1:Toe,2:$oe}),records:zt(ve({id:pe,typeName:pe}).allowUnknownProperties())});function Aoe(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function joe({json:e,schema:n}){let t;try{t=Moe.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),Aoe(t))return pn.err({type:"v1File",data:t})}catch{}return pn.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>koe)return pn.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=Ooe(t.records),s=Object.fromEntries(o.map(i=>[i.id,i]));r=n.migrateStoreSnapshot({store:s,schema:t.schema})}catch(o){return pn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return pn.err({type:"migrationFailed",reason:r.reason});try{return pn.ok(S2({initialData:r.value,schema:n}))}catch(o){return pn.err({type:"invalidRecords",cause:o})}}function Ooe(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 Doe(){const[e,n]=x.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=joe({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 h.jsx("div",{style:{inset:0,position:"fixed"},children:h.jsx(Eoe,{assetUrls:RD(),onMount:t,store:e})})}JS.createRoot(document.querySelector("#root")).render(h.jsx(Se.StrictMode,{children:h.jsx(Doe,{})}));